typos
[platform/upstream/libaec.git] / src / encode.h
1 /**
2  * @file encode.h
3  *
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
8  *
9  * @section LICENSE
10  * Copyright 2012 - 2014
11  *
12  * Mathis Rosenhauer,                 Luis Kornblueh
13  * Moritz Hanke,
14  * Joerg Behrens
15  *
16  * Deutsches Klimarechenzentrum GmbH  Max-Planck-Institut fuer Meteorologie
17  * Bundesstr. 45a                     Bundesstr. 53
18  * 20146 Hamburg                      20146 Hamburg
19  * Germany                            Germany
20  *
21  * All rights reserved.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  *
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.
33  *
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.
46  *
47  * @section DESCRIPTION
48  *
49  * Adaptive Entropy Encoder
50  * Based on CCSDS documents 121.0-B-2 and 120.0-G-2
51  *
52  */
53
54 #ifndef ENCODE_H
55 #define ENCODE_H
56
57 #include <config.h>
58
59 #if HAVE_STDINT_H
60 # include <stdint.h>
61 #endif
62
63 #include "libaec.h"
64
65 #define M_CONTINUE 1
66 #define M_EXIT 0
67 #define MIN(a, b) (((a) < (b))? (a): (b))
68
69 /* Maximum CDS length in bytes: 5 bits ID, 64 * 32 bits samples, 7
70  * bits carry from previous CDS */
71 #define CDSLEN ((5 + 64 * 32 + 7 + 7) / 8)
72
73 /* Marker for Remainder Of Segment condition in zero block encoding */
74 #define ROS -1
75
76 struct internal_state {
77     int (*mode)(struct aec_stream *);
78     uint32_t (*get_sample)(struct aec_stream *);
79     void (*get_rsi)(struct aec_stream *);
80     void (*preprocess)(struct aec_stream *);
81
82     int id_len;             /* bit length of code option identification key */
83     int64_t xmin;           /* minimum integer for preprocessing */
84     int64_t xmax;           /* maximum integer for preprocessing */
85     int i;                  /* counter */
86     uint32_t *data_pp;      /* RSI blocks of preprocessed input */
87     uint32_t *data_raw;     /* RSI blocks of input */
88     int blocks_avail;       /* remaining blocks in buffer */
89     uint32_t *block;        /* current (preprocessed) input block */
90     int rsi_len;            /* reference sample interval in byte */
91     uint8_t *cds;           /* current Coded Data Set output */
92     uint8_t cds_buf[CDSLEN];/* buffer for one CDS (only used if
93                              * strm->next_out cannot hold full CDS) */
94     int direct_out;         /* cds points to strm->next_out (1)
95                              * or cds_buf (0) */
96     int bits;               /* Free bits (LSB) in output buffer or
97                              * accumulator */
98     int ref;                /* length of reference sample in current
99                              * block i.e. 0 or 1 depending on whether
100                              * the block has a reference sample or
101                              * not */
102     int zero_ref;           /* current zero block has a reference sample */
103     uint32_t zero_ref_sample;/* reference sample of zero block */
104     int bytes_per_sample;   /* storage size of samples in bytes */
105     int zero_blocks;        /* number of contiguous zero blocks */
106     int block_nonzero;      /* 1 if this is the first non-zero block
107                              * after one or more zero blocks */
108     int k;                  /* splitting position */
109     int kmax;               /* maximum number for k depending on id_len */
110     int flush;              /* flush option copied from argument */
111     uint32_t uncomp_len;    /* length of uncompressed CDS */
112 };
113
114 #endif /* ENCODE_H */