imitate szlib for gribex
[platform/upstream/libaec.git] / src / sz_compat.c
1 #include <stddef.h>
2 #include "szlib.h"
3
4 int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, SZ_com_t *param)
5 {
6     int status;
7     ae_stream strm;
8
9     strm.bit_per_sample = param->bits_per_pixel;
10     strm.block_size = param->pixels_per_block;
11     strm.segment_size = param->pixels_per_scanline / param->pixels_per_block;
12     strm.flags = param->options_mask;
13     strm.avail_in = sourceLen;
14     strm.avail_out = *destLen;
15     strm.next_out = dest;
16     strm.next_in = source;
17
18     if ((status = ae_encode_init(&strm)) != AE_OK)
19         return status;
20
21     if ((status = ae_encode(&strm, AE_FLUSH)) != AE_OK)
22         return status;
23
24     *destLen = strm.total_out;
25     return SZ_OK;
26 }
27
28 int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, SZ_com_t *param)
29 {
30     int status;
31     ae_stream strm;
32
33     strm.bit_per_sample = param->bits_per_pixel;
34     strm.block_size = param->pixels_per_block;
35     strm.segment_size = param->pixels_per_scanline / param->pixels_per_block;
36     strm.flags = param->options_mask;
37     strm.avail_in = sourceLen;
38     strm.avail_out = *destLen;
39     strm.next_out = dest;
40     strm.next_in = source;
41
42     if ((status = ae_decode_init(&strm)) != AE_OK)
43         return status;
44
45     if ((status = ae_decode(&strm, AE_FLUSH)) != AE_OK)
46         return status;
47
48     *destLen = strm.total_out;
49     return SZ_OK;
50 }