static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)

{

    int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);

    for (y0 = 0; y0 < height; y0 += 4)

        for (x = 0; x < width; x++){

            if (y0 + 3 < height && !(

            (t1->flags[y0+1][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (t1->flags[y0+2][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (t1->flags[y0+3][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (t1->flags[y0+4][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG))))

            {

                // aggregation mode

                int rlen;

                for (rlen = 0; rlen < 4; rlen++)

                    if (t1->data[y0+rlen][x] & mask)

                        break;

                ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL, rlen != 4);

                if (rlen == 4)

                    continue;

                ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen >> 1);

                ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen & 1);

                for (y = y0 + rlen; y < y0 + 4; y++){

                    if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){

                        int ctxno = ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1], bandno);

                        if (y > y0 + rlen)

                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);

                        if (t1->data[y][x] & mask){ // newly significant

                            int xorbit;

                            int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);

                            *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);

                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);

                            ff_jpeg2000_set_significance(t1, x, y, t1->flags[y+1][x+1] >> 15);

                        }

                    }

                    t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;

                }

            } else{

                for (y = y0; y < y0 + 4 && y < height; y++){

                    if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){

                        int ctxno = ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1], bandno);

                        ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);

                        if (t1->data[y][x] & mask){ // newly significant

                            int xorbit;

                            int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);

                            *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);

                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);

                            ff_jpeg2000_set_significance(t1, x, y, t1->flags[y+1][x+1] >> 15);

                        }

                    }

                    t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;

                }

            }

        }

}

static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)

{

    int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS);

    for (y0 = 0; y0 < height; y0 += 4)

        for (x = 0; x < width; x++){

            if (y0 + 3 < height && !(

            (t1->flags[y0+1][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (t1->flags[y0+2][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (t1->flags[y0+3][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (t1->flags[y0+4][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG))))

            {

                

                int rlen;

                for (rlen = 0; rlen < 4; rlen++)

                    if (t1->data[y0+rlen][x] & mask)

                        break;

                ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL, rlen != 4);

                if (rlen == 4)

                    continue;

                ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen >> 1);

                ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen & 1);

                for (y = y0 + rlen; y < y0 + 4; y++){

                    if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){

                        int ctxno = ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1], bandno);

                        if (y > y0 + rlen)

                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);

                        if (t1->data[y][x] & mask){ 

                            int xorbit;

                            int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);

                            *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);

                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);

                            ff_jpeg2000_set_significance(t1, x, y, t1->flags[y+1][x+1] >> 15);

                        }

                    }

                    t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;

                }

            } else{

                for (y = y0; y < y0 + 4 && y < height; y++){

                    if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){

                        int ctxno = ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1], bandno);

                        ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);

                        if (t1->data[y][x] & mask){ 

                            int xorbit;

                            int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);

                            *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);

                            ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit);

                            ff_jpeg2000_set_significance(t1, x, y, t1->flags[y+1][x+1] >> 15);

                        }

                    }

                    t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;

                }

            }

        }

}

static void FUNC_0(Jpeg2000T1Context *VAR_0, int VAR_1, int VAR_2, int VAR_3, int *VAR_4, int VAR_5)

{

    int VAR_6, VAR_7, VAR_8, VAR_9 = 1 << (VAR_5 + NMSEDEC_FRACBITS);

    for (VAR_6 = 0; VAR_6 < VAR_2; VAR_6 += 4)

        for (VAR_7 = 0; VAR_7 < VAR_1; VAR_7++){

            if (VAR_6 + 3 < VAR_2 && !(

            (VAR_0->flags[VAR_6+1][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (VAR_0->flags[VAR_6+2][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (VAR_0->flags[VAR_6+3][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||

            (VAR_0->flags[VAR_6+4][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG))))

            {

                

                int VAR_10;

                for (VAR_10 = 0; VAR_10 < 4; VAR_10++)

                    if (VAR_0->data[VAR_6+VAR_10][VAR_7] & VAR_9)

                        break;

                ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + MQC_CX_RL, VAR_10 != 4);

                if (VAR_10 == 4)

                    continue;

                ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + MQC_CX_UNI, VAR_10 >> 1);

                ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + MQC_CX_UNI, VAR_10 & 1);

                for (VAR_8 = VAR_6 + VAR_10; VAR_8 < VAR_6 + 4; VAR_8++){

                    if (!(VAR_0->flags[VAR_8+1][VAR_7+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){

                        int VAR_13 = ff_jpeg2000_getsigctxno(VAR_0->flags[VAR_8+1][VAR_7+1], VAR_3);

                        if (VAR_8 > VAR_6 + VAR_10)

                            ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, VAR_0->data[VAR_8][VAR_7] & VAR_9 ? 1:0);

                        if (VAR_0->data[VAR_8][VAR_7] & VAR_9){ 

                            int VAR_13;

                            int VAR_13 = ff_jpeg2000_getsgnctxno(VAR_0->flags[VAR_8+1][VAR_7+1], &VAR_13);

                            *VAR_4 += getnmsedec_sig(VAR_0->data[VAR_8][VAR_7], VAR_5 + NMSEDEC_FRACBITS);

                            ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, (VAR_0->flags[VAR_8+1][VAR_7+1] >> 15) ^ VAR_13);

                            ff_jpeg2000_set_significance(VAR_0, VAR_7, VAR_8, VAR_0->flags[VAR_8+1][VAR_7+1] >> 15);

                        }

                    }

                    VAR_0->flags[VAR_8+1][VAR_7+1] &= ~JPEG2000_T1_VIS;

                }

            } else{

                for (VAR_8 = VAR_6; VAR_8 < VAR_6 + 4 && VAR_8 < VAR_2; VAR_8++){

                    if (!(VAR_0->flags[VAR_8+1][VAR_7+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){

                        int VAR_13 = ff_jpeg2000_getsigctxno(VAR_0->flags[VAR_8+1][VAR_7+1], VAR_3);

                        ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, VAR_0->data[VAR_8][VAR_7] & VAR_9 ? 1:0);

                        if (VAR_0->data[VAR_8][VAR_7] & VAR_9){ 

                            int VAR_13;

                            int VAR_13 = ff_jpeg2000_getsgnctxno(VAR_0->flags[VAR_8+1][VAR_7+1], &VAR_13);

                            *VAR_4 += getnmsedec_sig(VAR_0->data[VAR_8][VAR_7], VAR_5 + NMSEDEC_FRACBITS);

                            ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, (VAR_0->flags[VAR_8+1][VAR_7+1] >> 15) ^ VAR_13);

                            ff_jpeg2000_set_significance(VAR_0, VAR_7, VAR_8, VAR_0->flags[VAR_8+1][VAR_7+1] >> 15);

                        }

                    }

                    VAR_0->flags[VAR_8+1][VAR_7+1] &= ~JPEG2000_T1_VIS;

                }

            }

        }

}

static void FUNC_0(Jpeg2000T1Context *VAR_0, int VAR_1, int VAR_2, int VAR_3, int *VAR_4, int VAR_5)
{ int VAR_6, VAR_7, VAR_8, VAR_9 = 1 << (VAR_5 + NMSEDEC_FRACBITS); for (VAR_6 = 0; VAR_6 < VAR_2; VAR_6 += 4) for (VAR_7 = 0; VAR_7 < VAR_1; VAR_7++){ if (VAR_6 + 3 < VAR_2 && !(
(VAR_0->flags[VAR_6+1][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(VAR_0->flags[VAR_6+2][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(VAR_0->flags[VAR_6+3][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(VAR_0->flags[VAR_6+4][VAR_7+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG))))
{ int VAR_10; for (VAR_10 = 0; VAR_10 < 4; VAR_10++) if (VAR_0->data[VAR_6+VAR_10][VAR_7] & VAR_9)
break; ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + MQC_CX_RL, VAR_10 != 4); if (VAR_10 == 4)
continue; ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + MQC_CX_UNI, VAR_10 >> 1); ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + MQC_CX_UNI, VAR_10 & 1); for (VAR_8 = VAR_6 + VAR_10; VAR_8 < VAR_6 + 4; VAR_8++){ if (!(VAR_0->flags[VAR_8+1][VAR_7+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){ int VAR_13 = ff_jpeg2000_getsigctxno(VAR_0->flags[VAR_8+1][VAR_7+1], VAR_3); if (VAR_8 > VAR_6 + VAR_10)
ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, VAR_0->data[VAR_8][VAR_7] & VAR_9 ? 1:0); if (VAR_0->data[VAR_8][VAR_7] & VAR_9){ int VAR_13; int VAR_13 = ff_jpeg2000_getsgnctxno(VAR_0->flags[VAR_8+1][VAR_7+1], &VAR_13); *VAR_4 += getnmsedec_sig(VAR_0->data[VAR_8][VAR_7], VAR_5 + NMSEDEC_FRACBITS); ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, (VAR_0->flags[VAR_8+1][VAR_7+1] >> 15) ^ VAR_13); ff_jpeg2000_set_significance(VAR_0, VAR_7, VAR_8, VAR_0->flags[VAR_8+1][VAR_7+1] >> 15); } } VAR_0->flags[VAR_8+1][VAR_7+1] &= ~JPEG2000_T1_VIS; } } else{ for (VAR_8 = VAR_6; VAR_8 < VAR_6 + 4 && VAR_8 < VAR_2; VAR_8++){ if (!(VAR_0->flags[VAR_8+1][VAR_7+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){ int VAR_13 = ff_jpeg2000_getsigctxno(VAR_0->flags[VAR_8+1][VAR_7+1], VAR_3); ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, VAR_0->data[VAR_8][VAR_7] & VAR_9 ? 1:0); if (VAR_0->data[VAR_8][VAR_7] & VAR_9){ int VAR_13; int VAR_13 = ff_jpeg2000_getsgnctxno(VAR_0->flags[VAR_8+1][VAR_7+1], &VAR_13); *VAR_4 += getnmsedec_sig(VAR_0->data[VAR_8][VAR_7], VAR_5 + NMSEDEC_FRACBITS); ff_mqc_encode(&VAR_0->mqc, VAR_0->mqc.cx_states + VAR_13, (VAR_0->flags[VAR_8+1][VAR_7+1] >> 15) ^ VAR_13); ff_jpeg2000_set_significance(VAR_0, VAR_7, VAR_8, VAR_0->flags[VAR_8+1][VAR_7+1] >> 15); } } VAR_0->flags[VAR_8+1][VAR_7+1] &= ~JPEG2000_T1_VIS; } } } }