check_szcomp.c 1.74 KB
Newer Older
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
1 2 3
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
4
#include <string.h>
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
5 6
#include "szlib.h"

7 8 9
#define OPTIONS_MASK        (SZ_RAW_OPTION_MASK     \
                             | SZ_MSB_OPTION_MASK   \
                             | SZ_NN_OPTION_MASK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
10 11 12 13 14
#define PIXELS_PER_BLOCK    (8)
#define PIXELS_PER_SCANLINE (PIXELS_PER_BLOCK*128)

int main(int argc, char *argv[])
{
15
    int status;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
16
    SZ_com_t sz_param;
17 18 19
    unsigned char *source, *dest, *dest1;
    size_t destLen, dest1Len, sourceLen;
    FILE *fp;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
20

21
    if (argc < 3)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
22
    {
23
        fprintf(stderr, "Usage: %s buffer_size file\n", argv[0]);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
24 25 26
        return 1;
    }
    sz_param.options_mask = OPTIONS_MASK;
27
    sz_param.bits_per_pixel = 64;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
28 29 30 31 32
    sz_param.pixels_per_block = PIXELS_PER_BLOCK;
    sz_param.pixels_per_scanline = PIXELS_PER_SCANLINE;

    sourceLen = destLen = atoi(argv[1]);

33
    source = (unsigned char *)malloc(sourceLen);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
34
    dest = (unsigned char *)malloc(destLen);
35
    dest1 = (unsigned char *)malloc(destLen);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
36

37
    if (source == NULL || dest == NULL || dest1 == NULL)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
38 39
        return 1;

40
    if ((fp = fopen(argv[2], "r")) == NULL)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
41
    {
42 43
        fprintf(stderr, "Can't open %s\n", argv[2]);
        exit(-1);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
44 45
    }

46
    sourceLen = fread(source, 1, sourceLen, fp);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
47

48 49
    status = SZ_BufftoBuffCompress(dest, &destLen,
                                   source, sourceLen, &sz_param);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
50 51 52
    if (status != SZ_OK)
        return status;

53
    dest1Len = sourceLen;
54 55
    status = SZ_BufftoBuffDecompress(dest1, &dest1Len,
                                     dest, destLen, &sz_param);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
56 57 58
    if (status != SZ_OK)
        return status;

59 60
    if (memcmp(source, dest1, sourceLen) != 0)
        fprintf(stderr, "File %s Buffers differ\n", argv[2]);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
61 62 63

    free(source);
    free(dest);
64
    free(dest1);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
65 66
    return 0;
}