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

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

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

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
20 21
    if (argc < 2) {
        fprintf(stderr, "Usage: %s file\n", argv[0]);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
22 23
        return 1;
    }
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
24 25 26 27 28 29 30 31 32 33

    if ((fp = fopen(argv[1], "rb")) == NULL) {
        fprintf(stderr, "Can't open %s\n", argv[1]);
        return 1;
    }
    fseek(fp, 0L, SEEK_END);
    sourceLen = ftell(fp);
    fseek(fp, 0L, SEEK_SET);
    destLen = sourceLen + sourceLen / 10;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
34
    sz_param.options_mask = OPTIONS_MASK;
35
    sz_param.bits_per_pixel = 64;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
36 37 38
    sz_param.pixels_per_block = PIXELS_PER_BLOCK;
    sz_param.pixels_per_scanline = PIXELS_PER_SCANLINE;

39
    source = (unsigned char *)malloc(sourceLen);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
40
    dest = (unsigned char *)malloc(destLen);
41
    dest1 = (unsigned char *)malloc(destLen);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
42

43
    if (source == NULL || dest == NULL || dest1 == NULL)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
44 45
        return 1;

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;
}