7a9f8ea6d597ac2a76c275189ab400910d4d1c00
[platform/upstream/libaec.git] / src / encode.h
1 /**
2  * @file encode.h
3  *
4  * @section LICENSE
5  * Copyright 2012 - 2016
6  *
7  * Mathis Rosenhauer, Moritz Hanke, Joerg Behrens
8  * Deutsches Klimarechenzentrum GmbH
9  * Bundesstr. 45a
10  * 20146 Hamburg Germany
11  *
12  * Luis Kornblueh
13  * Max-Planck-Institut fuer Meteorologie
14  * Bundesstr. 53
15  * 20146 Hamburg
16  * Germany
17  *
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  *
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above
27  *    copyright notice, this list of conditions and the following
28  *    disclaimer in the documentation and/or other materials provided
29  *    with the distribution.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
34  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
35  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
36  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
42  * OF THE POSSIBILITY OF SUCH DAMAGE.
43  *
44  * @section DESCRIPTION
45  *
46  * Adaptive Entropy Encoder
47  * Based on CCSDS documents 121.0-B-2 and 120.0-G-3
48  *
49  */
50
51 #ifndef ENCODE_H
52 #define ENCODE_H 1
53
54 #include <config.h>
55
56 #if HAVE_STDINT_H
57 #  include <stdint.h>
58 #endif
59
60 #define M_CONTINUE 1
61 #define M_EXIT 0
62 #define MIN(a, b) (((a) < (b))? (a): (b))
63
64 /* Maximum CDS length in bytes: 5 bits ID, 64 * 32 bits samples, 7
65  * bits carry from previous CDS */
66 #define CDSLEN ((5 + 64 * 32 + 7 + 7) / 8)
67
68 /* Marker for Remainder Of Segment condition in zero block encoding */
69 #define ROS -1
70
71 struct internal_state {
72     int (*mode)(struct aec_stream *);
73     uint32_t (*get_sample)(struct aec_stream *);
74     void (*get_rsi)(struct aec_stream *);
75     void (*preprocess)(struct aec_stream *);
76
77     /* bit length of code option identification key */
78     int id_len;
79
80     /* minimum integer for preprocessing */
81     uint32_t xmin;
82
83     /* maximum integer for preprocessing */
84     uint32_t xmax;
85
86     uint32_t i;
87
88     /* RSI blocks of preprocessed input */
89     uint32_t *data_pp;
90
91     /* RSI blocks of input */
92     uint32_t *data_raw;
93
94     /* remaining blocks in buffer */
95     int blocks_avail;
96
97     /* current (preprocessed) input block */
98     uint32_t *block;
99
100     /* reference sample interval in byte */
101     uint32_t rsi_len;
102
103     /* current Coded Data Set output */
104     uint8_t *cds;
105
106     /* buffer for one CDS (only used if strm->next_out cannot hold
107      * full CDS) */
108     uint8_t cds_buf[CDSLEN];
109
110     /* cds points to strm->next_out (1) or cds_buf (0) */
111     int direct_out;
112
113     /* Free bits (LSB) in output buffer or accumulator */
114     int bits;
115
116     /* length of reference sample in current block i.e. 0 or 1
117      * depending on whether the block has a reference sample or not */
118     int ref;
119
120     /* reference sample stored here for performance reasons */
121     uint32_t ref_sample;
122
123     /* current zero block has a reference sample */
124     int zero_ref;
125
126     /* reference sample of zero block */
127     uint32_t zero_ref_sample;
128
129     /* storage size of samples in bytes */
130     uint32_t bytes_per_sample;
131
132     /* number of contiguous zero blocks */
133     int zero_blocks;
134
135     /* 1 if this is the first non-zero block after one or more zero
136      * blocks */
137     int block_nonzero;
138
139     /* splitting position */
140     int k;
141
142     /* maximum number for k depending on id_len */
143     int kmax;
144
145     /* flush option copied from argument */
146     int flush;
147
148     /* 1 if flushing was successful */
149     int flushed;
150
151     /* length of uncompressed CDS */
152     uint32_t uncomp_len;
153 };
154
155 #endif /* ENCODE_H */