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