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
9 * Redistribution and use in source and binary forms, with or without
\r
10 * modification, are permitted provided that the following conditions
\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
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
35 @brief Implementation of an MQ-Coder (MQC)
\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
41 /** @defgroup MQC MQC - Implementation of an MQ-Coder */
\r
45 This struct defines the state of a context.
\r
47 typedef struct opj_mqc_state {
\r
48 /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
\r
50 /** the Most Probable Symbol (0 or 1) */
\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
58 #define MQC_NUMCTXS 32
\r
63 typedef struct opj_mqc {
\r
68 unsigned char *start;
\r
70 opj_mqc_state_t *ctxs[MQC_NUMCTXS];
\r
71 opj_mqc_state_t **curctx;
\r
74 /** @name Exported functions */
\r
76 /* ----------------------------------------------------------------------- */
\r
78 Create a new MQC handle
\r
79 @return Returns a new MQC handle if successful, returns NULL otherwise
\r
81 opj_mqc_t* mqc_create();
\r
83 Destroy a previously created MQC handle
\r
84 @param mqc MQC handle to destroy
\r
86 void mqc_destroy(opj_mqc_t *mqc);
\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
92 int mqc_numbytes(opj_mqc_t *mqc);
\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
98 void mqc_resetstates(opj_mqc_t *mqc);
\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
106 void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
\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
112 void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
\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
118 void mqc_setcurctx(opj_mqc_t *mqc, int ctxno);
\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
124 void mqc_encode(opj_mqc_t *mqc, int d);
\r
126 Flush the encoder, so that all remaining data is written
\r
127 @param mqc MQC handle
\r
129 void mqc_flush(opj_mqc_t *mqc);
\r
131 BYPASS mode switch, initialization operation.
\r
133 <h2>Not fully implemented and tested !!</h2>
\r
134 @param mqc MQC handle
\r
136 void mqc_bypass_init_enc(opj_mqc_t *mqc);
\r
138 BYPASS mode switch, coding operation.
\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
144 void mqc_bypass_enc(opj_mqc_t *mqc, int d);
\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
151 int mqc_bypass_flush_enc(opj_mqc_t *mqc);
\r
154 @param mqc MQC handle
\r
156 void mqc_reset_enc(opj_mqc_t *mqc);
\r
159 @param mqc MQC handle
\r
161 void mqc_reset_enc_3(opj_mqc_t *mqc);
\r
163 RESTART mode switch (TERMALL)
\r
164 @param mqc MQC handle
\r
165 @return Returns 1 (always)
\r
167 int mqc_restart_enc(opj_mqc_t *mqc);
\r
169 RESTART mode switch (TERMALL) reinitialisation
\r
170 @param mqc MQC handle
\r
172 void mqc_restart_init_enc(opj_mqc_t *mqc);
\r
174 ERTERM mode switch (PTERM)
\r
175 @param mqc MQC handle
\r
177 void mqc_erterm_enc(opj_mqc_t *mqc);
\r
179 SEGMARK mode switch (SEGSYM)
\r
180 @param mqc MQC handle
\r
182 void mqc_segmark_enc(opj_mqc_t *mqc);
\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
189 void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
\r
192 @param mqc MQC handle
\r
193 @return Returns the decoded symbol (0 or 1)
\r
195 int mqc_decode(opj_mqc_t *mqc);
\r
196 /* ----------------------------------------------------------------------- */
\r
201 #endif /* __MQC_H */
\r