STYLE: Add a lot of comments for the CMake build system
[openjpeg.git] / libopenjpeg / mqc.h
1 /*
2  * Copyright (c) 2001-2003, David Janssens
3  * Copyright (c) 2002-2003, Yannick Verschueren
4  * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
5  * Copyright (c) 2005, Herv� Drolon, FreeImage Team
6  * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef __MQC_H
32 #define __MQC_H
33 /**
34 @file mqc.h
35 @brief Implementation of an MQ-Coder (MQC)
36
37 The functions in MQC.C have for goal to realize the MQ-coder operations. The functions
38 in MQC.C are used by some function in T1.C.
39 */
40
41 /** @defgroup MQC MQC - Implementation of an MQ-Coder */
42 /*@{*/
43
44 /**
45 This struct defines the state of a context.
46 */
47 typedef struct opj_mqc_state {
48         /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
49         unsigned int qeval;
50         /** the Most Probable Symbol (0 or 1) */
51         int mps;
52         /** next state if the next encoded symbol is the MPS */
53         struct opj_mqc_state *nmps;
54         /** next state if the next encoded symbol is the LPS */
55         struct opj_mqc_state *nlps;
56 } opj_mqc_state_t;
57
58 #define MQC_NUMCTXS 32
59
60 /**
61 MQ coder
62 */
63 typedef struct opj_mqc {
64         unsigned int c;
65         unsigned int a;
66         unsigned int ct;
67         unsigned char *bp;
68         unsigned char *start;
69         unsigned char *end;
70         opj_mqc_state_t *ctxs[MQC_NUMCTXS];
71         opj_mqc_state_t **curctx;
72 } opj_mqc_t;
73
74 /** @name Exported functions */
75 /*@{*/
76 /* ----------------------------------------------------------------------- */
77 /**
78 Create a new MQC handle 
79 @return Returns a new MQC handle if successful, returns NULL otherwise
80 */
81 opj_mqc_t* mqc_create();
82 /**
83 Destroy a previously created MQC handle
84 @param mqc MQC handle to destroy
85 */
86 void mqc_destroy(opj_mqc_t *mqc);
87 /**
88 Return the number of bytes written/read since initialisation
89 @param mqc MQC handle
90 @return Returns the number of bytes already encoded
91 */
92 int mqc_numbytes(opj_mqc_t *mqc);
93 /**
94 Reset the states of all the context of the coder/decoder 
95 (each context is set to a state where 0 and 1 are more or less equiprobable)
96 @param mqc MQC handle
97 */
98 void mqc_resetstates(opj_mqc_t *mqc);
99 /**
100 Set the state of a particular context
101 @param mqc MQC handle
102 @param ctxno Number that identifies the context
103 @param msb The MSB of the new state of the context
104 @param prob Number that identifies the probability of the symbols for the new state of the context
105 */
106 void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
107 /**
108 Initialize the encoder
109 @param mqc MQC handle
110 @param bp Pointer to the start of the buffer where the bytes will be written
111 */
112 void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
113 /**
114 Set the current context used for coding/decoding
115 @param mqc MQC handle
116 @param ctxno Number that identifies the context
117 */
118 void mqc_setcurctx(opj_mqc_t *mqc, int ctxno);
119 /**
120 Encode a symbol using the MQ-coder
121 @param mqc MQC handle
122 @param d The symbol to be encoded (0 or 1)
123 */
124 void mqc_encode(opj_mqc_t *mqc, int d);
125 /**
126 Flush the encoder, so that all remaining data is written
127 @param mqc MQC handle
128 */
129 void mqc_flush(opj_mqc_t *mqc);
130 /**
131 BYPASS mode switch, initialization operation. 
132 JPEG 2000 p 505. 
133 <h2>Not fully implemented and tested !!</h2>
134 @param mqc MQC handle
135 */
136 void mqc_bypass_init_enc(opj_mqc_t *mqc);
137 /**
138 BYPASS mode switch, coding operation. 
139 JPEG 2000 p 505. 
140 <h2>Not fully implemented and tested !!</h2>
141 @param mqc MQC handle
142 @param d The symbol to be encoded (0 or 1)
143 */
144 void mqc_bypass_enc(opj_mqc_t *mqc, int d);
145 /**
146 BYPASS mode switch, flush operation
147 <h2>Not fully implemented and tested !!</h2>
148 @param mqc MQC handle
149 @return Returns 1 (always)
150 */
151 int mqc_bypass_flush_enc(opj_mqc_t *mqc);
152 /**
153 RESET mode switch
154 @param mqc MQC handle
155 */
156 void mqc_reset_enc(opj_mqc_t *mqc);
157 /**
158 RESTART mode switch (TERMALL)
159 @param mqc MQC handle
160 @return Returns 1 (always)
161 */
162 int mqc_restart_enc(opj_mqc_t *mqc);
163 /**
164 RESTART mode switch (TERMALL) reinitialisation
165 @param mqc MQC handle
166 */
167 void mqc_restart_init_enc(opj_mqc_t *mqc);
168 /**
169 ERTERM mode switch (PTERM)
170 @param mqc MQC handle
171 */
172 void mqc_erterm_enc(opj_mqc_t *mqc);
173 /**
174 SEGMARK mode switch (SEGSYM)
175 @param mqc MQC handle
176 */
177 void mqc_segmark_enc(opj_mqc_t *mqc);
178 /**
179 Initialize the decoder
180 @param mqc MQC handle
181 @param bp Pointer to the start of the buffer from which the bytes will be read
182 @param len Length of the input buffer
183 */
184 void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
185 /**
186 Decode a symbol
187 @param mqc MQC handle
188 @return Returns the decoded symbol (0 or 1)
189 */
190 int mqc_decode(opj_mqc_t *mqc);
191 /* ----------------------------------------------------------------------- */
192 /*@}*/
193
194 /*@}*/
195
196 #endif /* __MQC_H */