f2359fde43bb8552152b5288e34455a9eabb0729
[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
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 struct internal_state {
70     int (*mode)(struct aec_stream *);
71     uint32_t (*get_sample)(struct aec_stream *);
72     void (*get_rsi)(struct aec_stream *);
73     void (*preprocess)(struct aec_stream *);
74
75     int id_len;             /* bit length of code option identification key */
76     int64_t xmin;           /* minimum integer for preprocessing */
77     int64_t xmax;           /* maximum integer for preprocessing */
78     int i;                  /* counter */
79     uint32_t *data_pp;      /* RSI blocks of preprocessed input */
80     uint32_t *data_raw;     /* RSI blocks of input */
81     int blocks_avail;       /* remaining blocks in buffer */
82     uint32_t *block;        /* current (preprocessed) input block */
83     int rsi_len;            /* reference sample interval in byte */
84     uint8_t *cds;           /* current Coded Data Set output */
85     uint8_t *cds_buf;       /* buffer for one CDS (only used if
86                              * strm->next_out cannot hold full CDS) */
87     int cds_len;            /* max cds length in byte */
88     int direct_out;         /* cds points to strm->next_out (1)
89                              * or cds_buf (0) */
90     int bits;               /* Free bits (LSB) in output buffer or
91                              * accumulator */
92     int ref;                /* length of reference sample in current
93                              * block i.e. 0 or 1 depending on whether
94                              * the block has a reference sample or
95                              * not */
96     int zero_ref;           /* current zero block has a reference sample */
97     uint32_t zero_ref_sample;/* reference sample of zero block */
98     int zero_blocks;        /* number of contiguous zero blocks */
99     int block_nonzero;      /* 1 if this is the first non-zero block
100                              * after one or more zero blocks */
101     int k;                  /* splitting position */
102     int kmax;               /* maximum number for k depending on id_len */
103     int flush;              /* flush option copied from argument */
104     uint32_t uncomp_len;    /* length of uncompressed CDS */
105 };
106
107 #endif /* ENCODE_H */