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.
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.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
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.
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.
40 @brief Implementation of an MQ-Coder (MQC)
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.
46 /** @defgroup MQC MQC - Implementation of an MQ-Coder */
50 This struct defines the state of a context.
52 typedef struct opj_mqc_state {
53 /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
55 /** the Most Probable Symbol (0 or 1) */
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;
63 #define MQC_NUMCTXS 32
68 typedef struct opj_mqc {
75 opj_mqc_state_t *ctxs[MQC_NUMCTXS];
76 opj_mqc_state_t **curctx;
79 /** @name Exported functions */
81 /* ----------------------------------------------------------------------- */
83 Create a new MQC handle
84 @return Returns a new MQC handle if successful, returns NULL otherwise
86 opj_mqc_t* mqc_create(void);
88 Destroy a previously created MQC handle
89 @param mqc MQC handle to destroy
91 void mqc_destroy(opj_mqc_t *mqc);
93 Return the number of bytes written/read since initialisation
95 @return Returns the number of bytes already encoded
97 int mqc_numbytes(opj_mqc_t *mqc);
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
103 void mqc_resetstates(opj_mqc_t *mqc);
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
111 void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
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
117 void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
119 Set the current context used for coding/decoding
120 @param mqc MQC handle
121 @param ctxno Number that identifies the context
123 void mqc_setcurctx(opj_mqc_t *mqc, int ctxno);
125 Encode a symbol using the MQ-coder
126 @param mqc MQC handle
127 @param d The symbol to be encoded (0 or 1)
129 void mqc_encode(opj_mqc_t *mqc, int d);
131 Flush the encoder, so that all remaining data is written
132 @param mqc MQC handle
134 void mqc_flush(opj_mqc_t *mqc);
136 BYPASS mode switch, initialization operation.
138 <h2>Not fully implemented and tested !!</h2>
139 @param mqc MQC handle
141 void mqc_bypass_init_enc(opj_mqc_t *mqc);
143 BYPASS mode switch, coding operation.
145 <h2>Not fully implemented and tested !!</h2>
146 @param mqc MQC handle
147 @param d The symbol to be encoded (0 or 1)
149 void mqc_bypass_enc(opj_mqc_t *mqc, int d);
151 BYPASS mode switch, flush operation
152 <h2>Not fully implemented and tested !!</h2>
153 @param mqc MQC handle
154 @return Returns 1 (always)
156 int mqc_bypass_flush_enc(opj_mqc_t *mqc);
159 @param mqc MQC handle
161 void mqc_reset_enc(opj_mqc_t *mqc);
164 @param mqc MQC handle
166 void mqc_reset_enc_3(opj_mqc_t *mqc);
168 RESTART mode switch (TERMALL)
169 @param mqc MQC handle
170 @return Returns 1 (always)
172 int mqc_restart_enc(opj_mqc_t *mqc);
174 RESTART mode switch (TERMALL) reinitialisation
175 @param mqc MQC handle
177 void mqc_restart_init_enc(opj_mqc_t *mqc);
179 ERTERM mode switch (PTERM)
180 @param mqc MQC handle
182 void mqc_erterm_enc(opj_mqc_t *mqc);
184 SEGMARK mode switch (SEGSYM)
185 @param mqc MQC handle
187 void mqc_segmark_enc(opj_mqc_t *mqc);
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
194 void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
197 @param mqc MQC handle
198 @return Returns the decoded symbol (0 or 1)
200 int mqc_decode(opj_mqc_t *mqc);
201 /* ----------------------------------------------------------------------- */