sz_compat.c 1.55 KB
Newer Older
1
#include <stdio.h>
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
2 3 4 5 6 7
#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;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
8
    struct aec_stream strm;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
9 10 11

    strm.bit_per_sample = param->bits_per_pixel;
    strm.block_size = param->pixels_per_block;
12
    strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
13
    strm.flags = param->options_mask;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
14 15 16 17 18
    strm.avail_in = sourceLen;
    strm.avail_out = *destLen;
    strm.next_out = dest;
    strm.next_in = source;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
19
    if ((status = aec_encode_init(&strm)) != AEC_OK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
20 21
        return status;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
22
    if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
23 24
        return status;

25 26
    *destLen = strm.total_out;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
27
    if ((status = aec_encode_end(&strm)) != AEC_OK)
28 29
        return status;

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

int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, size_t sourceLen, SZ_com_t *param)
{
    int status;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
36
    struct aec_stream strm;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
37 38 39

    strm.bit_per_sample = param->bits_per_pixel;
    strm.block_size = param->pixels_per_block;
40
    strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
41 42 43 44 45 46
    strm.flags = param->options_mask;
    strm.avail_in = sourceLen;
    strm.avail_out = *destLen;
    strm.next_out = dest;
    strm.next_in = source;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
47
    if ((status = aec_decode_init(&strm)) != AEC_OK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
48 49
        return status;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
50
    if ((status = aec_decode(&strm, AEC_FLUSH)) != AEC_OK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
51 52
        return status;

53 54
    *destLen = strm.total_out;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
55
    if ((status = aec_decode_end(&strm)) != AEC_OK)
56 57
        return status;

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