sz_compat.c 1.58 KB
Newer Older
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
1
2
3
4
5
6
7
8
9
10
#include <stddef.h>
#include "szlib.h"

int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, SZ_com_t *param)
{
    int status;
    ae_stream strm;

    strm.bit_per_sample = param->bits_per_pixel;
    strm.block_size = param->pixels_per_block;
11
12
//    strm.segment_size = param->pixels_per_scanline / param->pixels_per_block;
    strm.segment_size = 8;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
13
14
15
16
17
18
19
20
21
22
23
24
    strm.flags = param->options_mask;
    strm.avail_in = sourceLen;
    strm.avail_out = *destLen;
    strm.next_out = dest;
    strm.next_in = source;

    if ((status = ae_encode_init(&strm)) != AE_OK)
        return status;

    if ((status = ae_encode(&strm, AE_FLUSH)) != AE_OK)
        return status;

25
26
    *destLen = strm.total_out;

27
28
29
    if ((status = ae_encode_end(&strm)) != AE_OK)
        return status;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
30
31
32
33
34
35
36
37
38
39
    return SZ_OK;
}

int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, SZ_com_t *param)
{
    int status;
    ae_stream strm;

    strm.bit_per_sample = param->bits_per_pixel;
    strm.block_size = param->pixels_per_block;
40
41
//    strm.segment_size = param->pixels_per_scanline / param->pixels_per_block;
    strm.segment_size = 8;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
42
43
44
45
46
47
48
49
50
51
52
53
    strm.flags = param->options_mask;
    strm.avail_in = sourceLen;
    strm.avail_out = *destLen;
    strm.next_out = dest;
    strm.next_in = source;

    if ((status = ae_decode_init(&strm)) != AE_OK)
        return status;

    if ((status = ae_decode(&strm, AE_FLUSH)) != AE_OK)
        return status;

54
55
    *destLen = strm.total_out;

56
57
58
    if ((status = ae_decode_end(&strm)) != AE_OK)
        return status;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
59
60
    return SZ_OK;
}