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