Lines Matching refs:mqc
52 static void opj_mqc_byteout(opj_mqc_t *mqc);
57 static void opj_mqc_renorme(opj_mqc_t *mqc);
62 static void opj_mqc_codemps(opj_mqc_t *mqc);
67 static void opj_mqc_codelps(opj_mqc_t *mqc);
72 static void opj_mqc_setbits(opj_mqc_t *mqc);
78 static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc);
84 static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc);
89 static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc);
94 static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc);
205 static void opj_mqc_byteout(opj_mqc_t *mqc) { in opj_mqc_byteout() argument
206 if (*mqc->bp == 0xff) { in opj_mqc_byteout()
207 mqc->bp++; in opj_mqc_byteout()
208 *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); in opj_mqc_byteout()
209 mqc->c &= 0xfffff; in opj_mqc_byteout()
210 mqc->ct = 7; in opj_mqc_byteout()
212 if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ in opj_mqc_byteout()
213 mqc->bp++; in opj_mqc_byteout()
214 *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); in opj_mqc_byteout()
215 mqc->c &= 0x7ffff; in opj_mqc_byteout()
216 mqc->ct = 8; in opj_mqc_byteout()
218 (*mqc->bp)++; in opj_mqc_byteout()
219 if (*mqc->bp == 0xff) { in opj_mqc_byteout()
220 mqc->c &= 0x7ffffff; in opj_mqc_byteout()
221 mqc->bp++; in opj_mqc_byteout()
222 *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); in opj_mqc_byteout()
223 mqc->c &= 0xfffff; in opj_mqc_byteout()
224 mqc->ct = 7; in opj_mqc_byteout()
226 mqc->bp++; in opj_mqc_byteout()
227 *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); in opj_mqc_byteout()
228 mqc->c &= 0x7ffff; in opj_mqc_byteout()
229 mqc->ct = 8; in opj_mqc_byteout()
235 static void opj_mqc_renorme(opj_mqc_t *mqc) { in opj_mqc_renorme() argument
237 mqc->a <<= 1; in opj_mqc_renorme()
238 mqc->c <<= 1; in opj_mqc_renorme()
239 mqc->ct--; in opj_mqc_renorme()
240 if (mqc->ct == 0) { in opj_mqc_renorme()
241 opj_mqc_byteout(mqc); in opj_mqc_renorme()
243 } while ((mqc->a & 0x8000) == 0); in opj_mqc_renorme()
246 static void opj_mqc_codemps(opj_mqc_t *mqc) { in opj_mqc_codemps() argument
247 mqc->a -= (*mqc->curctx)->qeval; in opj_mqc_codemps()
248 if ((mqc->a & 0x8000) == 0) { in opj_mqc_codemps()
249 if (mqc->a < (*mqc->curctx)->qeval) { in opj_mqc_codemps()
250 mqc->a = (*mqc->curctx)->qeval; in opj_mqc_codemps()
252 mqc->c += (*mqc->curctx)->qeval; in opj_mqc_codemps()
254 *mqc->curctx = (*mqc->curctx)->nmps; in opj_mqc_codemps()
255 opj_mqc_renorme(mqc); in opj_mqc_codemps()
257 mqc->c += (*mqc->curctx)->qeval; in opj_mqc_codemps()
261 static void opj_mqc_codelps(opj_mqc_t *mqc) { in opj_mqc_codelps() argument
262 mqc->a -= (*mqc->curctx)->qeval; in opj_mqc_codelps()
263 if (mqc->a < (*mqc->curctx)->qeval) { in opj_mqc_codelps()
264 mqc->c += (*mqc->curctx)->qeval; in opj_mqc_codelps()
266 mqc->a = (*mqc->curctx)->qeval; in opj_mqc_codelps()
268 *mqc->curctx = (*mqc->curctx)->nlps; in opj_mqc_codelps()
269 opj_mqc_renorme(mqc); in opj_mqc_codelps()
272 static void opj_mqc_setbits(opj_mqc_t *mqc) { in opj_mqc_setbits() argument
273 OPJ_UINT32 tempc = mqc->c + mqc->a; in opj_mqc_setbits()
274 mqc->c |= 0xffff; in opj_mqc_setbits()
275 if (mqc->c >= tempc) { in opj_mqc_setbits()
276 mqc->c -= 0x8000; in opj_mqc_setbits()
280 static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) { in opj_mqc_mpsexchange() argument
282 if (mqc->a < (*mqc->curctx)->qeval) { in opj_mqc_mpsexchange()
283 d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); in opj_mqc_mpsexchange()
284 *mqc->curctx = (*mqc->curctx)->nlps; in opj_mqc_mpsexchange()
286 d = (OPJ_INT32)(*mqc->curctx)->mps; in opj_mqc_mpsexchange()
287 *mqc->curctx = (*mqc->curctx)->nmps; in opj_mqc_mpsexchange()
293 static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) { in opj_mqc_lpsexchange() argument
295 if (mqc->a < (*mqc->curctx)->qeval) { in opj_mqc_lpsexchange()
296 mqc->a = (*mqc->curctx)->qeval; in opj_mqc_lpsexchange()
297 d = (OPJ_INT32)(*mqc->curctx)->mps; in opj_mqc_lpsexchange()
298 *mqc->curctx = (*mqc->curctx)->nmps; in opj_mqc_lpsexchange()
300 mqc->a = (*mqc->curctx)->qeval; in opj_mqc_lpsexchange()
301 d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); in opj_mqc_lpsexchange()
302 *mqc->curctx = (*mqc->curctx)->nlps; in opj_mqc_lpsexchange()
309 static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) { in opj_mqc_bytein() argument
310 unsigned int i = *((unsigned int *) mqc->bp); in opj_mqc_bytein()
311 mqc->c += i & 0xffff00; in opj_mqc_bytein()
312 mqc->ct = i & 0x0f; in opj_mqc_bytein()
313 mqc->bp += (i >> 2) & 0x04; in opj_mqc_bytein()
316 static void opj_mqc_bytein(opj_mqc_t *const mqc) { in opj_mqc_bytein() argument
317 if (mqc->bp != mqc->end) { in opj_mqc_bytein()
319 if (mqc->bp + 1 != mqc->end) { in opj_mqc_bytein()
320 c = *(mqc->bp + 1); in opj_mqc_bytein()
324 if (*mqc->bp == 0xff) { in opj_mqc_bytein()
326 mqc->c += 0xff00; in opj_mqc_bytein()
327 mqc->ct = 8; in opj_mqc_bytein()
329 mqc->bp++; in opj_mqc_bytein()
330 mqc->c += c << 9; in opj_mqc_bytein()
331 mqc->ct = 7; in opj_mqc_bytein()
334 mqc->bp++; in opj_mqc_bytein()
335 mqc->c += c << 8; in opj_mqc_bytein()
336 mqc->ct = 8; in opj_mqc_bytein()
339 mqc->c += 0xff00; in opj_mqc_bytein()
340 mqc->ct = 8; in opj_mqc_bytein()
345 static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) { in opj_mqc_renormd() argument
347 if (mqc->ct == 0) { in opj_mqc_renormd()
348 opj_mqc_bytein(mqc); in opj_mqc_renormd()
350 mqc->a <<= 1; in opj_mqc_renormd()
351 mqc->c <<= 1; in opj_mqc_renormd()
352 mqc->ct--; in opj_mqc_renormd()
353 } while (mqc->a < 0x8000); in opj_mqc_renormd()
363 opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); in opj_mqc_create() local
365 if (mqc) { in opj_mqc_create()
366 mqc->buffer = NULL; in opj_mqc_create()
369 return mqc; in opj_mqc_create()
372 void opj_mqc_destroy(opj_mqc_t *mqc) { in opj_mqc_destroy() argument
373 if(mqc) { in opj_mqc_destroy()
375 if (mqc->buffer) { in opj_mqc_destroy()
376 opj_free(mqc->buffer); in opj_mqc_destroy()
379 opj_free(mqc); in opj_mqc_destroy()
383 OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { in opj_mqc_numbytes() argument
384 const ptrdiff_t diff = mqc->bp - mqc->start; in opj_mqc_numbytes()
391 void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { in opj_mqc_init_enc() argument
393 opj_mqc_setcurctx(mqc, 0); in opj_mqc_init_enc()
394 mqc->a = 0x8000; in opj_mqc_init_enc()
395 mqc->c = 0; in opj_mqc_init_enc()
396 mqc->bp = bp - 1; in opj_mqc_init_enc()
397 mqc->ct = 12; in opj_mqc_init_enc()
398 if (*mqc->bp == 0xff) { in opj_mqc_init_enc()
399 mqc->ct = 13; in opj_mqc_init_enc()
401 mqc->start = bp; in opj_mqc_init_enc()
404 void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) { in opj_mqc_encode() argument
405 if ((*mqc->curctx)->mps == d) { in opj_mqc_encode()
406 opj_mqc_codemps(mqc); in opj_mqc_encode()
408 opj_mqc_codelps(mqc); in opj_mqc_encode()
412 void opj_mqc_flush(opj_mqc_t *mqc) { in opj_mqc_flush() argument
413 opj_mqc_setbits(mqc); in opj_mqc_flush()
414 mqc->c <<= mqc->ct; in opj_mqc_flush()
415 opj_mqc_byteout(mqc); in opj_mqc_flush()
416 mqc->c <<= mqc->ct; in opj_mqc_flush()
417 opj_mqc_byteout(mqc); in opj_mqc_flush()
419 if (*mqc->bp != 0xff) { in opj_mqc_flush()
420 mqc->bp++; in opj_mqc_flush()
424 void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { in opj_mqc_bypass_init_enc() argument
425 mqc->c = 0; in opj_mqc_bypass_init_enc()
426 mqc->ct = 8; in opj_mqc_bypass_init_enc()
432 void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) { in opj_mqc_bypass_enc() argument
433 mqc->ct--; in opj_mqc_bypass_enc()
434 mqc->c = mqc->c + (d << mqc->ct); in opj_mqc_bypass_enc()
435 if (mqc->ct == 0) { in opj_mqc_bypass_enc()
436 mqc->bp++; in opj_mqc_bypass_enc()
437 *mqc->bp = (OPJ_BYTE)mqc->c; in opj_mqc_bypass_enc()
438 mqc->ct = 8; in opj_mqc_bypass_enc()
439 if (*mqc->bp == 0xff) { in opj_mqc_bypass_enc()
440 mqc->ct = 7; in opj_mqc_bypass_enc()
442 mqc->c = 0; in opj_mqc_bypass_enc()
446 OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { in opj_mqc_bypass_flush_enc() argument
451 if (mqc->ct != 0) { in opj_mqc_bypass_flush_enc()
452 while (mqc->ct > 0) { in opj_mqc_bypass_flush_enc()
453 mqc->ct--; in opj_mqc_bypass_flush_enc()
454 mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct); in opj_mqc_bypass_flush_enc()
457 mqc->bp++; in opj_mqc_bypass_flush_enc()
458 *mqc->bp = (OPJ_BYTE)mqc->c; in opj_mqc_bypass_flush_enc()
459 mqc->ct = 8; in opj_mqc_bypass_flush_enc()
460 mqc->c = 0; in opj_mqc_bypass_flush_enc()
466 void opj_mqc_reset_enc(opj_mqc_t *mqc) { in opj_mqc_reset_enc() argument
467 opj_mqc_resetstates(mqc); in opj_mqc_reset_enc()
468 opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); in opj_mqc_reset_enc()
469 opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); in opj_mqc_reset_enc()
470 opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); in opj_mqc_reset_enc()
473 OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) { in opj_mqc_restart_enc() argument
477 OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct); in opj_mqc_restart_enc()
478 mqc->c <<= mqc->ct; in opj_mqc_restart_enc()
480 opj_mqc_byteout(mqc); in opj_mqc_restart_enc()
481 n -= (OPJ_INT32)mqc->ct; in opj_mqc_restart_enc()
482 mqc->c <<= mqc->ct; in opj_mqc_restart_enc()
484 opj_mqc_byteout(mqc); in opj_mqc_restart_enc()
489 void opj_mqc_restart_init_enc(opj_mqc_t *mqc) { in opj_mqc_restart_init_enc() argument
491 opj_mqc_setcurctx(mqc, 0); in opj_mqc_restart_init_enc()
492 mqc->a = 0x8000; in opj_mqc_restart_init_enc()
493 mqc->c = 0; in opj_mqc_restart_init_enc()
494 mqc->ct = 12; in opj_mqc_restart_init_enc()
495 mqc->bp--; in opj_mqc_restart_init_enc()
496 if (*mqc->bp == 0xff) { in opj_mqc_restart_init_enc()
497 mqc->ct = 13; in opj_mqc_restart_init_enc()
501 void opj_mqc_erterm_enc(opj_mqc_t *mqc) { in opj_mqc_erterm_enc() argument
502 OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); in opj_mqc_erterm_enc()
505 mqc->c <<= mqc->ct; in opj_mqc_erterm_enc()
506 mqc->ct = 0; in opj_mqc_erterm_enc()
507 opj_mqc_byteout(mqc); in opj_mqc_erterm_enc()
508 k -= (OPJ_INT32)mqc->ct; in opj_mqc_erterm_enc()
511 if (*mqc->bp != 0xff) { in opj_mqc_erterm_enc()
512 opj_mqc_byteout(mqc); in opj_mqc_erterm_enc()
516 void opj_mqc_segmark_enc(opj_mqc_t *mqc) { in opj_mqc_segmark_enc() argument
518 opj_mqc_setcurctx(mqc, 18); in opj_mqc_segmark_enc()
521 opj_mqc_encode(mqc, i % 2); in opj_mqc_segmark_enc()
525 OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) { in opj_mqc_init_dec() argument
526 opj_mqc_setcurctx(mqc, 0); in opj_mqc_init_dec()
527 mqc->start = bp; in opj_mqc_init_dec()
528 mqc->end = bp + len; in opj_mqc_init_dec()
529 mqc->bp = bp; in opj_mqc_init_dec()
530 if (len==0) mqc->c = 0xff << 16; in opj_mqc_init_dec()
531 else mqc->c = (OPJ_UINT32)(*mqc->bp << 16); in opj_mqc_init_dec()
537 OPJ_BYTE *end = mqc->end - 1; in opj_mqc_init_dec()
538 void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32)); in opj_mqc_init_dec()
540 opj_free(mqc->buffer); in opj_mqc_init_dec()
541 mqc->buffer = NULL; in opj_mqc_init_dec()
544 mqc->buffer = new_buffer; in opj_mqc_init_dec()
546 ip = (OPJ_UINT32 *) mqc->buffer; in opj_mqc_init_dec()
574 mqc->bp = mqc->buffer; in opj_mqc_init_dec()
577 opj_mqc_bytein(mqc); in opj_mqc_init_dec()
578 mqc->c <<= 7; in opj_mqc_init_dec()
579 mqc->ct -= 7; in opj_mqc_init_dec()
580 mqc->a = 0x8000; in opj_mqc_init_dec()
584 OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) { in opj_mqc_decode() argument
586 mqc->a -= (*mqc->curctx)->qeval; in opj_mqc_decode()
587 if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { in opj_mqc_decode()
588 d = opj_mqc_lpsexchange(mqc); in opj_mqc_decode()
589 opj_mqc_renormd(mqc); in opj_mqc_decode()
591 mqc->c -= (*mqc->curctx)->qeval << 16; in opj_mqc_decode()
592 if ((mqc->a & 0x8000) == 0) { in opj_mqc_decode()
593 d = opj_mqc_mpsexchange(mqc); in opj_mqc_decode()
594 opj_mqc_renormd(mqc); in opj_mqc_decode()
596 d = (OPJ_INT32)(*mqc->curctx)->mps; in opj_mqc_decode()
603 void opj_mqc_resetstates(opj_mqc_t *mqc) { in opj_mqc_resetstates() argument
606 mqc->ctxs[i] = mqc_states; in opj_mqc_resetstates()
610 void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) { in opj_mqc_setstate() argument
611 mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; in opj_mqc_setstate()