summaryrefslogtreecommitdiff
path: root/src/sz_compat.c
blob: ed4e4d6435b3a0a6dbb72e1271ce10870207f0ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#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;
    strm.segment_size = param->pixels_per_scanline / param->pixels_per_block;
    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;

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

    *destLen = strm.total_out;
    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;
    strm.segment_size = param->pixels_per_scanline / param->pixels_per_block;
    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;

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

    *destLen = strm.total_out;
    return SZ_OK;
}