diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index 7119c3a5..58577951 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -324,10 +324,12 @@ void opj_mqc_flush(opj_mqc_t *mqc) { if (*mqc->bp != 0xff) { mqc->bp++; + *mqc->bp = 0; } } void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { + opj_mqc_byteout(mqc); mqc->c = 0; mqc->ct = 8; /*if (*mqc->bp == 0xff) { @@ -362,6 +364,8 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { } mqc->bp++; *mqc->bp = (OPJ_BYTE)mqc->c; + mqc->bp++; + *mqc->bp = 0; mqc->ct = 8; mqc->c = 0; } diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 453d2908..18e841b6 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -2102,7 +2102,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, /* Code switch "RESTART" (i.e. TERMALL) */ if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { if (type == T1_TYPE_RAW) { - opj_mqc_flush(mqc); + opj_mqc_bypass_flush_enc(mqc); correction = 1; /* correction = mqc_bypass_flush_enc(); */ } else { /* correction = mqc_restart_enc(); */ @@ -2114,7 +2114,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, if (((bpno < ((OPJ_INT32) (cblk->numbps) - 4) && (passtype > 0)) || ((bpno == ((OPJ_INT32)cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) { if (type == T1_TYPE_RAW) { - opj_mqc_flush(mqc); + opj_mqc_bypass_flush_enc(mqc); correction = 1; /* correction = mqc_bypass_flush_enc(); */ } else { /* correction = mqc_restart_enc(); */