Lines Matching refs:mqc
54 static void opj_mqc_byteout(opj_mqc_t *mqc);
59 static void opj_mqc_renorme(opj_mqc_t *mqc);
64 static void opj_mqc_codemps(opj_mqc_t *mqc);
69 static void opj_mqc_codelps(opj_mqc_t *mqc);
74 static void opj_mqc_setbits(opj_mqc_t *mqc);
185 static void opj_mqc_byteout(opj_mqc_t *mqc) in opj_mqc_byteout() argument
189 assert(mqc->bp >= mqc->start - 1); in opj_mqc_byteout()
190 if (*mqc->bp == 0xff) { in opj_mqc_byteout()
191 mqc->bp++; in opj_mqc_byteout()
192 *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); in opj_mqc_byteout()
193 mqc->c &= 0xfffff; in opj_mqc_byteout()
194 mqc->ct = 7; in opj_mqc_byteout()
196 if ((mqc->c & 0x8000000) == 0) { in opj_mqc_byteout()
197 mqc->bp++; in opj_mqc_byteout()
198 *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); in opj_mqc_byteout()
199 mqc->c &= 0x7ffff; in opj_mqc_byteout()
200 mqc->ct = 8; in opj_mqc_byteout()
202 (*mqc->bp)++; in opj_mqc_byteout()
203 if (*mqc->bp == 0xff) { in opj_mqc_byteout()
204 mqc->c &= 0x7ffffff; in opj_mqc_byteout()
205 mqc->bp++; in opj_mqc_byteout()
206 *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); in opj_mqc_byteout()
207 mqc->c &= 0xfffff; in opj_mqc_byteout()
208 mqc->ct = 7; in opj_mqc_byteout()
210 mqc->bp++; in opj_mqc_byteout()
211 *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); in opj_mqc_byteout()
212 mqc->c &= 0x7ffff; in opj_mqc_byteout()
213 mqc->ct = 8; in opj_mqc_byteout()
219 static void opj_mqc_renorme(opj_mqc_t *mqc) in opj_mqc_renorme() argument
222 mqc->a <<= 1; in opj_mqc_renorme()
223 mqc->c <<= 1; in opj_mqc_renorme()
224 mqc->ct--; in opj_mqc_renorme()
225 if (mqc->ct == 0) { in opj_mqc_renorme()
226 opj_mqc_byteout(mqc); in opj_mqc_renorme()
228 } while ((mqc->a & 0x8000) == 0); in opj_mqc_renorme()
231 static void opj_mqc_codemps(opj_mqc_t *mqc) in opj_mqc_codemps() argument
233 mqc->a -= (*mqc->curctx)->qeval; in opj_mqc_codemps()
234 if ((mqc->a & 0x8000) == 0) { in opj_mqc_codemps()
235 if (mqc->a < (*mqc->curctx)->qeval) { in opj_mqc_codemps()
236 mqc->a = (*mqc->curctx)->qeval; in opj_mqc_codemps()
238 mqc->c += (*mqc->curctx)->qeval; in opj_mqc_codemps()
240 *mqc->curctx = (*mqc->curctx)->nmps; in opj_mqc_codemps()
241 opj_mqc_renorme(mqc); in opj_mqc_codemps()
243 mqc->c += (*mqc->curctx)->qeval; in opj_mqc_codemps()
247 static void opj_mqc_codelps(opj_mqc_t *mqc) in opj_mqc_codelps() argument
249 mqc->a -= (*mqc->curctx)->qeval; in opj_mqc_codelps()
250 if (mqc->a < (*mqc->curctx)->qeval) { in opj_mqc_codelps()
251 mqc->c += (*mqc->curctx)->qeval; in opj_mqc_codelps()
253 mqc->a = (*mqc->curctx)->qeval; in opj_mqc_codelps()
255 *mqc->curctx = (*mqc->curctx)->nlps; in opj_mqc_codelps()
256 opj_mqc_renorme(mqc); in opj_mqc_codelps()
259 static void opj_mqc_setbits(opj_mqc_t *mqc) in opj_mqc_setbits() argument
261 OPJ_UINT32 tempc = mqc->c + mqc->a; in opj_mqc_setbits()
262 mqc->c |= 0xffff; in opj_mqc_setbits()
263 if (mqc->c >= tempc) { in opj_mqc_setbits()
264 mqc->c -= 0x8000; in opj_mqc_setbits()
274 OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) in opj_mqc_numbytes() argument
276 const ptrdiff_t diff = mqc->bp - mqc->start; in opj_mqc_numbytes()
283 void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) in opj_mqc_init_enc() argument
287 opj_mqc_setcurctx(mqc, 0); in opj_mqc_init_enc()
291 mqc->a = 0x8000; in opj_mqc_init_enc()
292 mqc->c = 0; in opj_mqc_init_enc()
295 mqc->bp = bp - 1; in opj_mqc_init_enc()
296 mqc->ct = 12; in opj_mqc_init_enc()
300 assert(*(mqc->bp) != 0xff); in opj_mqc_init_enc()
302 mqc->start = bp; in opj_mqc_init_enc()
303 mqc->end_of_byte_stream_counter = 0; in opj_mqc_init_enc()
306 void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) in opj_mqc_encode() argument
308 if ((*mqc->curctx)->mps == d) { in opj_mqc_encode()
309 opj_mqc_codemps(mqc); in opj_mqc_encode()
311 opj_mqc_codelps(mqc); in opj_mqc_encode()
315 void opj_mqc_flush(opj_mqc_t *mqc) in opj_mqc_flush() argument
319 opj_mqc_setbits(mqc); in opj_mqc_flush()
320 mqc->c <<= mqc->ct; in opj_mqc_flush()
321 opj_mqc_byteout(mqc); in opj_mqc_flush()
322 mqc->c <<= mqc->ct; in opj_mqc_flush()
323 opj_mqc_byteout(mqc); in opj_mqc_flush()
326 if (*mqc->bp != 0xff) { in opj_mqc_flush()
328 mqc->bp++; in opj_mqc_flush()
334 void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) in opj_mqc_bypass_init_enc() argument
339 assert(mqc->bp >= mqc->start); in opj_mqc_bypass_init_enc()
340 mqc->c = 0; in opj_mqc_bypass_init_enc()
346 mqc->ct = BYPASS_CT_INIT; in opj_mqc_bypass_init_enc()
349 assert(mqc->bp[-1] != 0xff); in opj_mqc_bypass_init_enc()
352 void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) in opj_mqc_bypass_enc() argument
354 if (mqc->ct == BYPASS_CT_INIT) { in opj_mqc_bypass_enc()
355 mqc->ct = 8; in opj_mqc_bypass_enc()
357 mqc->ct--; in opj_mqc_bypass_enc()
358 mqc->c = mqc->c + (d << mqc->ct); in opj_mqc_bypass_enc()
359 if (mqc->ct == 0) { in opj_mqc_bypass_enc()
360 *mqc->bp = (OPJ_BYTE)mqc->c; in opj_mqc_bypass_enc()
361 mqc->ct = 8; in opj_mqc_bypass_enc()
363 if (*mqc->bp == 0xff) { in opj_mqc_bypass_enc()
364 mqc->ct = 7; in opj_mqc_bypass_enc()
366 mqc->bp++; in opj_mqc_bypass_enc()
367 mqc->c = 0; in opj_mqc_bypass_enc()
371 OPJ_UINT32 opj_mqc_bypass_get_extra_bytes(opj_mqc_t *mqc, OPJ_BOOL erterm) in opj_mqc_bypass_get_extra_bytes() argument
373 return (mqc->ct < 7 || in opj_mqc_bypass_get_extra_bytes()
374 (mqc->ct == 7 && (erterm || mqc->bp[-1] != 0xff))) ? 1 : 0; in opj_mqc_bypass_get_extra_bytes()
377 void opj_mqc_bypass_flush_enc(opj_mqc_t *mqc, OPJ_BOOL erterm) in opj_mqc_bypass_flush_enc() argument
385 if (mqc->ct < 7 || (mqc->ct == 7 && (erterm || mqc->bp[-1] != 0xff))) { in opj_mqc_bypass_flush_enc()
391 while (mqc->ct > 0) { in opj_mqc_bypass_flush_enc()
392 mqc->ct--; in opj_mqc_bypass_flush_enc()
393 mqc->c += (OPJ_UINT32)(bit_value << mqc->ct); in opj_mqc_bypass_flush_enc()
396 *mqc->bp = (OPJ_BYTE)mqc->c; in opj_mqc_bypass_flush_enc()
398 mqc->bp++; in opj_mqc_bypass_flush_enc()
399 } else if (mqc->ct == 7 && mqc->bp[-1] == 0xff) { in opj_mqc_bypass_flush_enc()
402 mqc->bp --; in opj_mqc_bypass_flush_enc()
403 } else if (mqc->ct == 8 && !erterm && in opj_mqc_bypass_flush_enc()
404 mqc->bp[-1] == 0x7f && mqc->bp[-2] == 0xff) { in opj_mqc_bypass_flush_enc()
409 mqc->bp -= 2; in opj_mqc_bypass_flush_enc()
412 assert(mqc->bp[-1] != 0xff); in opj_mqc_bypass_flush_enc()
415 void opj_mqc_reset_enc(opj_mqc_t *mqc) in opj_mqc_reset_enc() argument
417 opj_mqc_resetstates(mqc); in opj_mqc_reset_enc()
418 opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); in opj_mqc_reset_enc()
419 opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); in opj_mqc_reset_enc()
420 opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); in opj_mqc_reset_enc()
424 OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) in opj_mqc_restart_enc() argument
429 OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct); in opj_mqc_restart_enc()
430 mqc->c <<= mqc->ct; in opj_mqc_restart_enc()
432 opj_mqc_byteout(mqc); in opj_mqc_restart_enc()
433 n -= (OPJ_INT32)mqc->ct; in opj_mqc_restart_enc()
434 mqc->c <<= mqc->ct; in opj_mqc_restart_enc()
436 opj_mqc_byteout(mqc); in opj_mqc_restart_enc()
442 void opj_mqc_restart_init_enc(opj_mqc_t *mqc) in opj_mqc_restart_init_enc() argument
448 mqc->a = 0x8000; in opj_mqc_restart_init_enc()
449 mqc->c = 0; in opj_mqc_restart_init_enc()
450 mqc->ct = 12; in opj_mqc_restart_init_enc()
454 mqc->bp --; in opj_mqc_restart_init_enc()
455 assert(mqc->bp >= mqc->start - 1); in opj_mqc_restart_init_enc()
456 assert(*mqc->bp != 0xff); in opj_mqc_restart_init_enc()
457 if (*mqc->bp == 0xff) { in opj_mqc_restart_init_enc()
458 mqc->ct = 13; in opj_mqc_restart_init_enc()
462 void opj_mqc_erterm_enc(opj_mqc_t *mqc) in opj_mqc_erterm_enc() argument
464 OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); in opj_mqc_erterm_enc()
467 mqc->c <<= mqc->ct; in opj_mqc_erterm_enc()
468 mqc->ct = 0; in opj_mqc_erterm_enc()
469 opj_mqc_byteout(mqc); in opj_mqc_erterm_enc()
470 k -= (OPJ_INT32)mqc->ct; in opj_mqc_erterm_enc()
473 if (*mqc->bp != 0xff) { in opj_mqc_erterm_enc()
474 opj_mqc_byteout(mqc); in opj_mqc_erterm_enc()
478 void opj_mqc_segmark_enc(opj_mqc_t *mqc) in opj_mqc_segmark_enc() argument
481 opj_mqc_setcurctx(mqc, 18); in opj_mqc_segmark_enc()
484 opj_mqc_encode(mqc, i % 2); in opj_mqc_segmark_enc()
488 static void opj_mqc_init_dec_common(opj_mqc_t *mqc, in opj_mqc_init_dec_common() argument
496 mqc->start = bp; in opj_mqc_init_dec_common()
497 mqc->end = bp + len; in opj_mqc_init_dec_common()
502 memcpy(mqc->backup, mqc->end, OPJ_COMMON_CBLK_DATA_EXTRA); in opj_mqc_init_dec_common()
503 mqc->end[0] = 0xFF; in opj_mqc_init_dec_common()
504 mqc->end[1] = 0xFF; in opj_mqc_init_dec_common()
505 mqc->bp = bp; in opj_mqc_init_dec_common()
507 void opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, in opj_mqc_init_dec() argument
515 opj_mqc_init_dec_common(mqc, bp, len, extra_writable_bytes); in opj_mqc_init_dec()
516 opj_mqc_setcurctx(mqc, 0); in opj_mqc_init_dec()
517 mqc->end_of_byte_stream_counter = 0; in opj_mqc_init_dec()
519 mqc->c = 0xff << 16; in opj_mqc_init_dec()
521 mqc->c = (OPJ_UINT32)(*mqc->bp << 16); in opj_mqc_init_dec()
524 opj_mqc_bytein(mqc); in opj_mqc_init_dec()
525 mqc->c <<= 7; in opj_mqc_init_dec()
526 mqc->ct -= 7; in opj_mqc_init_dec()
527 mqc->a = 0x8000; in opj_mqc_init_dec()
531 void opj_mqc_raw_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, in opj_mqc_raw_init_dec() argument
534 opj_mqc_init_dec_common(mqc, bp, len, extra_writable_bytes); in opj_mqc_raw_init_dec()
535 mqc->c = 0; in opj_mqc_raw_init_dec()
536 mqc->ct = 0; in opj_mqc_raw_init_dec()
540 void opq_mqc_finish_dec(opj_mqc_t *mqc) in opq_mqc_finish_dec() argument
543 memcpy(mqc->end, mqc->backup, OPJ_COMMON_CBLK_DATA_EXTRA); in opq_mqc_finish_dec()
546 void opj_mqc_resetstates(opj_mqc_t *mqc) in opj_mqc_resetstates() argument
550 mqc->ctxs[i] = mqc_states; in opj_mqc_resetstates()
554 void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, in opj_mqc_setstate() argument
557 mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; in opj_mqc_setstate()