sz_compat.c 1.78 KB
Newer Older
1
#include <stdio.h>
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
2
3
#include <stddef.h>
#include "szlib.h"
4
#include "libaec.h"
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define NOPTS 129

static int convert_options(int sz_opts)
{
    int co[NOPTS];
    int i;
    int opts = 0;

    memset(co, 0, sizeof(int) * NOPTS);
    co[SZ_MSB_OPTION_MASK] = AEC_DATA_MSB;
    co[SZ_NN_OPTION_MASK] = AEC_DATA_PREPROCESS;

    for (i = 1; i < NOPTS; i <<= 1)
        opts |= co[i];

    return opts;
}

24
25
26
int SZ_BufftoBuffCompress(void *dest, size_t *destLen,
                          const void *source, size_t sourceLen,
                          SZ_com_t *param)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
27
28
{
    int status;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
29
    struct aec_stream strm;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
30
31
32

    strm.bit_per_sample = param->bits_per_pixel;
    strm.block_size = param->pixels_per_block;
33
    strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
34
    strm.flags = convert_options(param->options_mask);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
35
36
37
38
39
    strm.avail_in = sourceLen;
    strm.avail_out = *destLen;
    strm.next_out = dest;
    strm.next_in = source;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
40
    status = aec_buffer_encode(&strm);
41
    if (status != AEC_OK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
42
43
        return status;

44
    *destLen = strm.total_out;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
45
46
47
    return SZ_OK;
}

48
49
50
int SZ_BufftoBuffDecompress(void *dest, size_t *destLen,
                            const void *source, size_t sourceLen,
                            SZ_com_t *param)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
51
52
{
    int status;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
53
    struct aec_stream strm;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
54
55
56

    strm.bit_per_sample = param->bits_per_pixel;
    strm.block_size = param->pixels_per_block;
57
    strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
58
    strm.flags = convert_options(param->options_mask);
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
59
60
61
62
63
    strm.avail_in = sourceLen;
    strm.avail_out = *destLen;
    strm.next_out = dest;
    strm.next_in = source;

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
64
    status = aec_buffer_decode(&strm);
65
    if (status != AEC_OK)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
66
67
        return status;

68
    *destLen = strm.total_out;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
69
70
    return SZ_OK;
}
71
72
73
74
75

int SZ_encoder_enabled(void)
{
    return 1;
}