test_szcomp.c 1.61 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 7 8 9 10 11 12
#include "szlib.h"

#define OPTIONS_MASK        (SZ_RAW_OPTION_MASK | SZ_MSB_OPTION_MASK | SZ_NN_OPTION_MASK)
#define PIXELS_PER_BLOCK    (8)
#define PIXELS_PER_SCANLINE (PIXELS_PER_BLOCK*128)

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

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

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

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

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

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

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

    status = SZ_BufftoBuffCompress(dest, &destLen, source, sourceLen, &sz_param);
    if (status != SZ_OK)
        return status;

50 51
    dest1Len = sourceLen;
    status = SZ_BufftoBuffDecompress(dest1, &dest1Len, dest, destLen, &sz_param);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
52 53 54
    if (status != SZ_OK)
        return status;

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

    free(source);
    free(dest);
60
    free(dest1);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
61 62
    return 0;
}