1 **********************************************************************
2 libaec - Adaptive Entropy Coding library
3 **********************************************************************
5 libaec provides fast lossless compression of 1 up to 32 bit wide
6 signed or unsigned integers. The library achieves best results for low
7 entropy data as often encountered in space imaging instrument data or
8 numerical model output from weather or climate simulations. While
9 floating point representations are not directly supported, they can
10 also be efficiently coded by grouping exponents and mantissa.
12 libaec implements a Space Data System Standard [1], [2].
15 **********************************************************************
17 **********************************************************************
19 In doc/license.txt a clarification on potentially applying
20 intellectual property rights is given.
23 **********************************************************************
25 **********************************************************************
27 See INSTALL for details.
30 **********************************************************************
32 **********************************************************************
34 In this context efficiency refers to the size of the encoded
35 data. Performance refers to the time it takes to encode data.
37 Suppose you have an array of 32 bit signed integers you want to
38 compress. The pointer pointing to the data shall be called *source,
39 output goes into *dest.
44 struct aec_stream strm;
48 /* input data ist 32 bits wide */
49 strm.bits_per_sample = 32;
51 /* define a block size of 16 */
54 /* the reference sample interval is set to 128 blocks */
57 /* input data is signed and needs to be preprocessed */
58 strm.flags = AEC_DATA_SIGNED | AEC_DATA_PREPROCESS;
60 /* pointer to input */
61 strm.next_in = (unsigned char *)source;
63 /* length of input in bytes */
64 strm.avail_in = source_length * 4;
66 /* pointer to output buffer */
67 strm.avail_out = dest;
69 /* length of output buffer in bytes */
70 strm.next_out = dest_lenth;
72 /* initialize encoding */
73 if (aec_encode_init(&strm) != AEC_OK)
76 /* Perform encoding in one call and flush output. */
77 /* In this example you must be sure that the output */
78 /* buffer is large enough for all compressed output */
79 if (aec_encode(&strm, AEC_FLUSH) != AEC_OK)
82 /* free all resources used by encoder */
83 aec_encode_end(&strm);
86 block_size can vary from 8 to 64. Smaller blocks allow the compression
87 to adapt to rapid changes in entropy. Larger blocks create less
88 overhead but can be less efficient.
90 rsi sets the reference sample interval. A large RSI will improve
91 performance and efficiency. It will also increase memory requiremens
92 since internal buffering is based on RSI size. Smaller RSI may be
93 desirable in situations where each RSI will be packetized and possible
94 error propagation has to be minimized (e.g. on board a spacecraft[2]).
98 AEC_DATA_SIGNED: input data are signed integers. Specifying this
99 correctly increases compression efficiency. Default is unsigned.
101 AEC_DATA_PREPROCESS: preprocessing input will almost always improve
102 compression efficiency. It may only cost performance for no gain in
103 efficiency if the data is already uncorrelated.
105 AEC_DATA_MSB: input data is stored most significant byte first
106 i.e. big endian. You have to specify AEC_DATA_MSB even if your host
107 architecture is big endian. Default is little endian on all
110 AEC_DATA_3BYTE: the 24 bit input data is stored in three bytes.
114 Except for the AEC_DATA_3BYTE case for 24 bit data, the following
117 data size storage size
120 17 - 32 bit 4 bytes (also for 24bit if AEC_DATA_3BYTE is not set)
124 aec_encode can be used in a streaming fashion by chunking input and
125 output and specifying AEC_NO_FLUSH. The function will return if either
126 the input runs empty or the output buffer is full. The calling
127 function can check avail_in and avail_out to see what occcurred. aec.c
128 is an example of streaming usage of encoding and decoding.
131 **********************************************************************
133 **********************************************************************
135 Usage for decoding is very similar to encoding, only the meaning of
136 input and output is reversed.
141 struct aec_stream strm;
142 /* this is now the compressed data */
143 unsigned char *source;
144 /* here goes the uncompressed result */
147 strm.bits_per_sample = 32;
148 strm.block_size = 16;
150 strm.flags = AEC_DATA_SIGNED | AEC_DATA_PREPROCESS;
151 strm.next_in = source;
152 strm.avail_in = source_length;
153 strm.next_out = (unsigned char *)dest;
154 strm.avail_out = dest_lenth * 4;
155 if (aec_decode_init(&strm) != AEC_OK)
157 if (aec_decode(&strm, AEC_FLUSH) != AEC_OK)
159 aec_decode_end(&strm);
162 It is essential for decoding that parameters like bits_per_sample,
163 block_size, rsi, and flags are exactly the same as they were for
164 encoding. libaec does not store these parameters in the coded stream
165 so it is up to the calling program to keep the correct parameters
166 between encoding and decoding.
169 **********************************************************************
171 **********************************************************************
173 [1] Consultative Committee for Space Data Systems. Lossless Data
174 Compression. Recommendation for Space Data System Standards, CCSDS
175 121.0-B-2. Blue Book. Issue 2. Washington, D.C.: CCSDS, May 2012.
176 http://public.ccsds.org/publications/archive/121x0b2.pdf
178 [2] Consultative Committee for Space Data Systems. Lossless Data
179 Compression. Recommendation for Space Data System Standards, CCSDS
180 120.0-G-2. Green Book. Issue 2. Washington, D.C.: CCSDS, December
182 http://public.ccsds.org/publications/archive/120x0g2.pdf