4 * @author Mathis Rosenhauer, Deutsches Klimarechenzentrum
5 * @author Moritz Hanke, Deutsches Klimarechenzentrum
6 * @author Joerg Behrens, Deutsches Klimarechenzentrum
7 * @author Luis Kornblueh, Max-Planck-Institut fuer Meteorologie
12 * Mathis Rosenhauer, Luis Kornblueh
16 * Deutsches Klimarechenzentrum GmbH Max-Planck-Institut fuer Meteorologie
17 * Bundesstr. 45a Bundesstr. 53
18 * 20146 Hamburg 20146 Hamburg
21 * All rights reserved.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above
30 * copyright notice, this list of conditions and the following
31 * disclaimer in the documentation and/or other materials provided
32 * with the distribution.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
37 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
38 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
39 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
45 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * @section DESCRIPTION
49 * Adaptive Entropy Decoder
50 * Based on CCSDS documents 121.0-B-2 and 120.0-G-2
68 #define MIN(a, b) (((a) < (b))? (a): (b))
70 struct internal_state {
71 int (*mode)(struct aec_stream *);
72 int id; /* option ID */
73 int id_len; /* bit length of code option identification key */
74 int (**id_table)(struct aec_stream *); /* table maps IDs to states */
75 void (*flush_output)(struct aec_stream *);
76 int64_t last_out; /* previous output for post-processing */
77 int64_t xmin; /* minimum integer for post-processing */
78 int64_t xmax; /* maximum integer for post-processing */
79 int in_blklen; /* length of uncompressed input block
80 should be the longest possible block */
81 int out_blklen; /* length of output block in bytes */
82 int n, i; /* counter for samples */
83 uint64_t acc; /* accumulator for currently used bit sequence */
84 int bitp; /* bit pointer to the next unused bit in
86 int fs; /* last fundamental sequence in accumulator */
87 int ref; /* 1 if current block has reference sample */
88 int pp; /* 1 if postprocessor has to be used */
89 int bytes_per_sample; /* storage size of samples in bytes */
90 int *se_table; /* table for decoding second extension option */
91 uint32_t *rsi_buffer; /* output buffer holding one reference
93 uint32_t *rsip; /* current position of output in rsi_buffer */
94 size_t rsi_size; /* rsi in bytes */
95 uint32_t *flush_start; /* first not yet flushed byte in rsi_buffer */