0b56162940d656651a144f176ad87d0b33a12dbb
[openjpeg.git] / src / lib / openmj2 / mqc.c
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) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8  * Copyright (c) 2002-2014, Professor Benoit Macq
9  * Copyright (c) 2001-2003, David Janssens
10  * Copyright (c) 2002-2003, Yannick Verschueren
11  * Copyright (c) 2003-2007, Francois-Olivier Devaux 
12  * Copyright (c) 2003-2014, Antonin Descampe
13  * Copyright (c) 2005, Herve Drolon, FreeImage Team
14  * All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37
38 #include "opj_includes.h"
39
40 /** @defgroup MQC MQC - Implementation of an MQ-Coder */
41 /*@{*/
42
43 /** @name Local static functions */
44 /*@{*/
45
46 /**
47 Output a byte, doing bit-stuffing if necessary.
48 After a 0xff byte, the next byte must be smaller than 0x90.
49 @param mqc MQC handle
50 */
51 static void mqc_byteout(opj_mqc_t *mqc);
52 /**
53 Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000
54 @param mqc MQC handle
55 */
56 static void mqc_renorme(opj_mqc_t *mqc);
57 /**
58 Encode the most probable symbol
59 @param mqc MQC handle
60 */
61 static void mqc_codemps(opj_mqc_t *mqc);
62 /**
63 Encode the most least symbol
64 @param mqc MQC handle
65 */
66 static void mqc_codelps(opj_mqc_t *mqc);
67 /**
68 Fill mqc->c with 1's for flushing
69 @param mqc MQC handle
70 */
71 static void mqc_setbits(opj_mqc_t *mqc);
72 /**
73 FIXME: documentation ???
74 @param mqc MQC handle
75 @return 
76 */
77 static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc);
78 /**
79 FIXME: documentation ???
80 @param mqc MQC handle
81 @return 
82 */
83 static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc);
84 /**
85 Input a byte
86 @param mqc MQC handle
87 */
88 static INLINE void mqc_bytein(opj_mqc_t *const mqc);
89 /**
90 Renormalize mqc->a and mqc->c while decoding
91 @param mqc MQC handle
92 */
93 static INLINE void mqc_renormd(opj_mqc_t *const mqc);
94 /*@}*/
95
96 /*@}*/
97
98 /* <summary> */
99 /* This array defines all the possible states for a context. */
100 /* </summary> */
101 static opj_mqc_state_t mqc_states[47 * 2] = {
102         {0x5601, 0, &mqc_states[2], &mqc_states[3]},
103         {0x5601, 1, &mqc_states[3], &mqc_states[2]},
104         {0x3401, 0, &mqc_states[4], &mqc_states[12]},
105         {0x3401, 1, &mqc_states[5], &mqc_states[13]},
106         {0x1801, 0, &mqc_states[6], &mqc_states[18]},
107         {0x1801, 1, &mqc_states[7], &mqc_states[19]},
108         {0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
109         {0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
110         {0x0521, 0, &mqc_states[10], &mqc_states[58]},
111         {0x0521, 1, &mqc_states[11], &mqc_states[59]},
112         {0x0221, 0, &mqc_states[76], &mqc_states[66]},
113         {0x0221, 1, &mqc_states[77], &mqc_states[67]},
114         {0x5601, 0, &mqc_states[14], &mqc_states[13]},
115         {0x5601, 1, &mqc_states[15], &mqc_states[12]},
116         {0x5401, 0, &mqc_states[16], &mqc_states[28]},
117         {0x5401, 1, &mqc_states[17], &mqc_states[29]},
118         {0x4801, 0, &mqc_states[18], &mqc_states[28]},
119         {0x4801, 1, &mqc_states[19], &mqc_states[29]},
120         {0x3801, 0, &mqc_states[20], &mqc_states[28]},
121         {0x3801, 1, &mqc_states[21], &mqc_states[29]},
122         {0x3001, 0, &mqc_states[22], &mqc_states[34]},
123         {0x3001, 1, &mqc_states[23], &mqc_states[35]},
124         {0x2401, 0, &mqc_states[24], &mqc_states[36]},
125         {0x2401, 1, &mqc_states[25], &mqc_states[37]},
126         {0x1c01, 0, &mqc_states[26], &mqc_states[40]},
127         {0x1c01, 1, &mqc_states[27], &mqc_states[41]},
128         {0x1601, 0, &mqc_states[58], &mqc_states[42]},
129         {0x1601, 1, &mqc_states[59], &mqc_states[43]},
130         {0x5601, 0, &mqc_states[30], &mqc_states[29]},
131         {0x5601, 1, &mqc_states[31], &mqc_states[28]},
132         {0x5401, 0, &mqc_states[32], &mqc_states[28]},
133         {0x5401, 1, &mqc_states[33], &mqc_states[29]},
134         {0x5101, 0, &mqc_states[34], &mqc_states[30]},
135         {0x5101, 1, &mqc_states[35], &mqc_states[31]},
136         {0x4801, 0, &mqc_states[36], &mqc_states[32]},
137         {0x4801, 1, &mqc_states[37], &mqc_states[33]},
138         {0x3801, 0, &mqc_states[38], &mqc_states[34]},
139         {0x3801, 1, &mqc_states[39], &mqc_states[35]},
140         {0x3401, 0, &mqc_states[40], &mqc_states[36]},
141         {0x3401, 1, &mqc_states[41], &mqc_states[37]},
142         {0x3001, 0, &mqc_states[42], &mqc_states[38]},
143         {0x3001, 1, &mqc_states[43], &mqc_states[39]},
144         {0x2801, 0, &mqc_states[44], &mqc_states[38]},
145         {0x2801, 1, &mqc_states[45], &mqc_states[39]},
146         {0x2401, 0, &mqc_states[46], &mqc_states[40]},
147         {0x2401, 1, &mqc_states[47], &mqc_states[41]},
148         {0x2201, 0, &mqc_states[48], &mqc_states[42]},
149         {0x2201, 1, &mqc_states[49], &mqc_states[43]},
150         {0x1c01, 0, &mqc_states[50], &mqc_states[44]},
151         {0x1c01, 1, &mqc_states[51], &mqc_states[45]},
152         {0x1801, 0, &mqc_states[52], &mqc_states[46]},
153         {0x1801, 1, &mqc_states[53], &mqc_states[47]},
154         {0x1601, 0, &mqc_states[54], &mqc_states[48]},
155         {0x1601, 1, &mqc_states[55], &mqc_states[49]},
156         {0x1401, 0, &mqc_states[56], &mqc_states[50]},
157         {0x1401, 1, &mqc_states[57], &mqc_states[51]},
158         {0x1201, 0, &mqc_states[58], &mqc_states[52]},
159         {0x1201, 1, &mqc_states[59], &mqc_states[53]},
160         {0x1101, 0, &mqc_states[60], &mqc_states[54]},
161         {0x1101, 1, &mqc_states[61], &mqc_states[55]},
162         {0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
163         {0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
164         {0x09c1, 0, &mqc_states[64], &mqc_states[58]},
165         {0x09c1, 1, &mqc_states[65], &mqc_states[59]},
166         {0x08a1, 0, &mqc_states[66], &mqc_states[60]},
167         {0x08a1, 1, &mqc_states[67], &mqc_states[61]},
168         {0x0521, 0, &mqc_states[68], &mqc_states[62]},
169         {0x0521, 1, &mqc_states[69], &mqc_states[63]},
170         {0x0441, 0, &mqc_states[70], &mqc_states[64]},
171         {0x0441, 1, &mqc_states[71], &mqc_states[65]},
172         {0x02a1, 0, &mqc_states[72], &mqc_states[66]},
173         {0x02a1, 1, &mqc_states[73], &mqc_states[67]},
174         {0x0221, 0, &mqc_states[74], &mqc_states[68]},
175         {0x0221, 1, &mqc_states[75], &mqc_states[69]},
176         {0x0141, 0, &mqc_states[76], &mqc_states[70]},
177         {0x0141, 1, &mqc_states[77], &mqc_states[71]},
178         {0x0111, 0, &mqc_states[78], &mqc_states[72]},
179         {0x0111, 1, &mqc_states[79], &mqc_states[73]},
180         {0x0085, 0, &mqc_states[80], &mqc_states[74]},
181         {0x0085, 1, &mqc_states[81], &mqc_states[75]},
182         {0x0049, 0, &mqc_states[82], &mqc_states[76]},
183         {0x0049, 1, &mqc_states[83], &mqc_states[77]},
184         {0x0025, 0, &mqc_states[84], &mqc_states[78]},
185         {0x0025, 1, &mqc_states[85], &mqc_states[79]},
186         {0x0015, 0, &mqc_states[86], &mqc_states[80]},
187         {0x0015, 1, &mqc_states[87], &mqc_states[81]},
188         {0x0009, 0, &mqc_states[88], &mqc_states[82]},
189         {0x0009, 1, &mqc_states[89], &mqc_states[83]},
190         {0x0005, 0, &mqc_states[90], &mqc_states[84]},
191         {0x0005, 1, &mqc_states[91], &mqc_states[85]},
192         {0x0001, 0, &mqc_states[90], &mqc_states[86]},
193         {0x0001, 1, &mqc_states[91], &mqc_states[87]},
194         {0x5601, 0, &mqc_states[92], &mqc_states[92]},
195         {0x5601, 1, &mqc_states[93], &mqc_states[93]},
196 };
197
198 /* 
199 ==========================================================
200    local functions
201 ==========================================================
202 */
203
204 static void mqc_byteout(opj_mqc_t *mqc) {
205         if (*mqc->bp == 0xff) {
206                 mqc->bp++;
207                 *mqc->bp = mqc->c >> 20;
208                 mqc->c &= 0xfffff;
209                 mqc->ct = 7;
210         } else {
211                 if ((mqc->c & 0x8000000) == 0) {        /* ((mqc->c&0x8000000)==0) CHANGE */
212                         mqc->bp++;
213                         *mqc->bp = mqc->c >> 19;
214                         mqc->c &= 0x7ffff;
215                         mqc->ct = 8;
216                 } else {
217                         (*mqc->bp)++;
218                         if (*mqc->bp == 0xff) {
219                                 mqc->c &= 0x7ffffff;
220                                 mqc->bp++;
221                                 *mqc->bp = mqc->c >> 20;
222                                 mqc->c &= 0xfffff;
223                                 mqc->ct = 7;
224                         } else {
225                                 mqc->bp++;
226                                 *mqc->bp = mqc->c >> 19;
227                                 mqc->c &= 0x7ffff;
228                                 mqc->ct = 8;
229                         }
230                 }
231         }
232 }
233
234 static void mqc_renorme(opj_mqc_t *mqc) {
235         do {
236                 mqc->a <<= 1;
237                 mqc->c <<= 1;
238                 mqc->ct--;
239                 if (mqc->ct == 0) {
240                         mqc_byteout(mqc);
241                 }
242         } while ((mqc->a & 0x8000) == 0);
243 }
244
245 static void mqc_codemps(opj_mqc_t *mqc) {
246         mqc->a -= (*mqc->curctx)->qeval;
247         if ((mqc->a & 0x8000) == 0) {
248                 if (mqc->a < (*mqc->curctx)->qeval) {
249                         mqc->a = (*mqc->curctx)->qeval;
250                 } else {
251                         mqc->c += (*mqc->curctx)->qeval;
252                 }
253                 *mqc->curctx = (*mqc->curctx)->nmps;
254                 mqc_renorme(mqc);
255         } else {
256                 mqc->c += (*mqc->curctx)->qeval;
257         }
258 }
259
260 static void mqc_codelps(opj_mqc_t *mqc) {
261         mqc->a -= (*mqc->curctx)->qeval;
262         if (mqc->a < (*mqc->curctx)->qeval) {
263                 mqc->c += (*mqc->curctx)->qeval;
264         } else {
265                 mqc->a = (*mqc->curctx)->qeval;
266         }
267         *mqc->curctx = (*mqc->curctx)->nlps;
268         mqc_renorme(mqc);
269 }
270
271 static void mqc_setbits(opj_mqc_t *mqc) {
272         unsigned int tempc = mqc->c + mqc->a;
273         mqc->c |= 0xffff;
274         if (mqc->c >= tempc) {
275                 mqc->c -= 0x8000;
276         }
277 }
278
279 static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc) {
280         int d;
281         if (mqc->a < (*mqc->curctx)->qeval) {
282                 d = 1 - (*mqc->curctx)->mps;
283                 *mqc->curctx = (*mqc->curctx)->nlps;
284         } else {
285                 d = (*mqc->curctx)->mps;
286                 *mqc->curctx = (*mqc->curctx)->nmps;
287         }
288         
289         return d;
290 }
291
292 static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc) {
293         int d;
294         if (mqc->a < (*mqc->curctx)->qeval) {
295                 mqc->a = (*mqc->curctx)->qeval;
296                 d = (*mqc->curctx)->mps;
297                 *mqc->curctx = (*mqc->curctx)->nmps;
298         } else {
299                 mqc->a = (*mqc->curctx)->qeval;
300                 d = 1 - (*mqc->curctx)->mps;
301                 *mqc->curctx = (*mqc->curctx)->nlps;
302         }
303         
304         return d;
305 }
306
307 #ifdef MQC_PERF_OPT
308 static INLINE void mqc_bytein(opj_mqc_t *const mqc) {
309         unsigned int i = *((unsigned int *) mqc->bp);
310         mqc->c += i & 0xffff00;
311         mqc->ct = i & 0x0f;
312         mqc->bp += (i >> 2) & 0x04;
313 }
314 #else
315 static void mqc_bytein(opj_mqc_t *const mqc) {
316         if (mqc->bp != mqc->end) {
317                 unsigned int c;
318                 if (mqc->bp + 1 != mqc->end) {
319                         c = *(mqc->bp + 1);
320                 } else {
321                         c = 0xff;
322                 }
323                 if (*mqc->bp == 0xff) {
324                         if (c > 0x8f) {
325                                 mqc->c += 0xff00;
326                                 mqc->ct = 8;
327                         } else {
328                                 mqc->bp++;
329                                 mqc->c += c << 9;
330                                 mqc->ct = 7;
331                         }
332                 } else {
333                         mqc->bp++;
334                         mqc->c += c << 8;
335                         mqc->ct = 8;
336                 }
337         } else {
338                 mqc->c += 0xff00;
339                 mqc->ct = 8;
340         }
341 }
342 #endif
343
344 static INLINE void mqc_renormd(opj_mqc_t *const mqc) {
345         do {
346                 if (mqc->ct == 0) {
347                         mqc_bytein(mqc);
348                 }
349                 mqc->a <<= 1;
350                 mqc->c <<= 1;
351                 mqc->ct--;
352         } while (mqc->a < 0x8000);
353 }
354
355 /* 
356 ==========================================================
357    MQ-Coder interface
358 ==========================================================
359 */
360
361 opj_mqc_t* mqc_create(void) {
362         opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
363 #ifdef MQC_PERF_OPT
364         mqc->buffer = NULL;
365 #endif
366         return mqc;
367 }
368
369 void mqc_destroy(opj_mqc_t *mqc) {
370         if(mqc) {
371 #ifdef MQC_PERF_OPT
372                 if (mqc->buffer) {
373                         opj_free(mqc->buffer);
374                 }
375 #endif
376                 opj_free(mqc);
377         }
378 }
379
380 int mqc_numbytes(opj_mqc_t *mqc) {
381         return mqc->bp - mqc->start;
382 }
383
384 void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) {
385         mqc_setcurctx(mqc, 0);
386         mqc->a = 0x8000;
387         mqc->c = 0;
388         mqc->bp = bp - 1;
389         mqc->ct = 12;
390         if (*mqc->bp == 0xff) {
391                 mqc->ct = 13;
392         }
393         mqc->start = bp;
394 }
395
396 void mqc_encode(opj_mqc_t *mqc, int d) {
397         if ((*mqc->curctx)->mps == d) {
398                 mqc_codemps(mqc);
399         } else {
400                 mqc_codelps(mqc);
401         }
402 }
403
404 void mqc_flush(opj_mqc_t *mqc) {
405         mqc_setbits(mqc);
406         mqc->c <<= mqc->ct;
407         mqc_byteout(mqc);
408         mqc->c <<= mqc->ct;
409         mqc_byteout(mqc);
410         
411         if (*mqc->bp != 0xff) {
412                 mqc->bp++;
413         }
414 }
415
416 void mqc_bypass_init_enc(opj_mqc_t *mqc) {
417         mqc->c = 0;
418         mqc->ct = 8;
419         /*if (*mqc->bp == 0xff) {
420         mqc->ct = 7;
421      } */
422 }
423
424 void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
425         mqc->ct--;
426         mqc->c = mqc->c + (d << mqc->ct);
427         if (mqc->ct == 0) {
428                 mqc->bp++;
429                 *mqc->bp = mqc->c;
430                 mqc->ct = 8;
431                 if (*mqc->bp == 0xff) {
432                         mqc->ct = 7;
433                 }
434                 mqc->c = 0;
435         }
436 }
437
438 int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
439         unsigned char bit_padding;
440         
441         bit_padding = 0;
442         
443         if (mqc->ct != 0) {
444                 while (mqc->ct > 0) {
445                         mqc->ct--;
446                         mqc->c += bit_padding << mqc->ct;
447                         bit_padding = (bit_padding + 1) & 0x01;
448                 }
449                 mqc->bp++;
450                 *mqc->bp = mqc->c;
451                 mqc->ct = 8;
452                 mqc->c = 0;
453         }
454         
455         return 1;
456 }
457
458 void mqc_reset_enc(opj_mqc_t *mqc) {
459         mqc_resetstates(mqc);
460         mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
461         mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
462         mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
463 }
464
465 int mqc_restart_enc(opj_mqc_t *mqc) {
466         int correction = 1;
467         
468         /* <flush part> */
469         int n = 27 - 15 - mqc->ct;
470         mqc->c <<= mqc->ct;
471         while (n > 0) {
472                 mqc_byteout(mqc);
473                 n -= mqc->ct;
474                 mqc->c <<= mqc->ct;
475         }
476         mqc_byteout(mqc);
477         
478         return correction;
479 }
480
481 void mqc_restart_init_enc(opj_mqc_t *mqc) {
482         /* <Re-init part> */
483         mqc_setcurctx(mqc, 0);
484         mqc->a = 0x8000;
485         mqc->c = 0;
486         mqc->ct = 12;
487         mqc->bp--;
488         if (*mqc->bp == 0xff) {
489                 mqc->ct = 13;
490         }
491 }
492
493 void mqc_erterm_enc(opj_mqc_t *mqc) {
494         int k = 11 - mqc->ct + 1;
495         
496         while (k > 0) {
497                 mqc->c <<= mqc->ct;
498                 mqc->ct = 0;
499                 mqc_byteout(mqc);
500                 k -= mqc->ct;
501         }
502         
503         if (*mqc->bp != 0xff) {
504                 mqc_byteout(mqc);
505         }
506 }
507
508 void mqc_segmark_enc(opj_mqc_t *mqc) {
509         int i;
510         mqc_setcurctx(mqc, 18);
511         
512         for (i = 1; i < 5; i++) {
513                 mqc_encode(mqc, i % 2);
514         }
515 }
516
517 void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
518         mqc_setcurctx(mqc, 0);
519         mqc->start = bp;
520         mqc->end = bp + len;
521         mqc->bp = bp;
522         if (len==0) mqc->c = 0xff << 16;
523         else mqc->c = *mqc->bp << 16;
524
525 #ifdef MQC_PERF_OPT
526         {
527                 unsigned int c;
528                 unsigned int *ip;
529                 unsigned char *end = mqc->end - 1;
530                 mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
531                 ip = (unsigned int *) mqc->buffer;
532
533                 while (bp < end) {
534                         c = *(bp + 1);
535                         if (*bp == 0xff) {
536                                 if (c > 0x8f) {
537                                         break;
538                                 } else {
539                                         *ip = 0x00000017 | (c << 9);
540                                 }
541                         } else {
542                                 *ip = 0x00000018 | (c << 8);
543                         }
544                         bp++;
545                         ip++;
546                 }
547
548                 /* Handle last byte of data */
549                 c = 0xff;
550                 if (*bp == 0xff) {
551                         *ip = 0x0000ff18;
552                 } else {
553                         bp++;
554                         *ip = 0x00000018 | (c << 8);
555                 }
556                 ip++;
557
558                 *ip = 0x0000ff08;
559                 mqc->bp = mqc->buffer;
560         }
561 #endif
562         mqc_bytein(mqc);
563         mqc->c <<= 7;
564         mqc->ct -= 7;
565         mqc->a = 0x8000;
566 }
567
568 int mqc_decode(opj_mqc_t *const mqc) {
569         int d;
570         mqc->a -= (*mqc->curctx)->qeval;
571         if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
572                 d = mqc_lpsexchange(mqc);
573                 mqc_renormd(mqc);
574         } else {
575                 mqc->c -= (*mqc->curctx)->qeval << 16;
576                 if ((mqc->a & 0x8000) == 0) {
577                         d = mqc_mpsexchange(mqc);
578                         mqc_renormd(mqc);
579                 } else {
580                         d = (*mqc->curctx)->mps;
581                 }
582         }
583
584         return d;
585 }
586
587 void mqc_resetstates(opj_mqc_t *mqc) {
588         int i;
589         for (i = 0; i < MQC_NUMCTXS; i++) {
590                 mqc->ctxs[i] = mqc_states;
591         }
592 }
593
594 void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) {
595         mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
596 }
597
598