static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile,

                        int width, int height, int bandpos, int lev)

{

    int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;

    int64_t wmsedec = 0;



    memset(t1->flags, 0, t1->stride * (height + 2) * sizeof(*t1->flags));



    for (y = 0; y < height; y++){

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

            if (t1->data[(y) * t1->stride + x] < 0){

                t1->flags[(y+1) * t1->stride + x+1] |= JPEG2000_T1_SGN;

                t1->data[(y) * t1->stride + x] = -t1->data[(y) * t1->stride + x];

            }

            max = FFMAX(max, t1->data[(y) * t1->stride + x]);

        }

    }



    if (max == 0){

        cblk->nonzerobits = 0;

        bpno = 0;

    } else{

        cblk->nonzerobits = av_log2(max) + 1 - NMSEDEC_FRACBITS;

        bpno = cblk->nonzerobits - 1;

    }



    ff_mqc_initenc(&t1->mqc, cblk->data);



    for (passno = 0; bpno >= 0; passno++){

        nmsedec=0;



        switch(pass_t){

            case 0: encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);

                    break;

            case 1: encode_refpass(t1, width, height, &nmsedec, bpno);

                    break;

            case 2: encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);

                    break;

        }



        cblk->passes[passno].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno].flushed, &cblk->passes[passno].flushed_len);

        wmsedec += (int64_t)nmsedec << (2*bpno);

        cblk->passes[passno].disto = wmsedec;



        if (++pass_t == 3){

            pass_t = 0;

            bpno--;

        }

    }

    cblk->npasses = passno;

    cblk->ninclpasses = passno;



    cblk->passes[passno-1].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno-1].flushed, &cblk->passes[passno-1].flushed_len);

}

static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile,

                        int width, int height, int bandpos, int lev)

{

    int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;

    int64_t wmsedec = 0;



    memset(t1->flags, 0, t1->stride * (height + 2) * sizeof(*t1->flags));



    for (y = 0; y < height; y++){

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

            if (t1->data[(y) * t1->stride + x] < 0){

                t1->flags[(y+1) * t1->stride + x+1] |= JPEG2000_T1_SGN;

                t1->data[(y) * t1->stride + x] = -t1->data[(y) * t1->stride + x];

            }

            max = FFMAX(max, t1->data[(y) * t1->stride + x]);

        }

    }



    if (max == 0){

        cblk->nonzerobits = 0;

        bpno = 0;

    } else{

        cblk->nonzerobits = av_log2(max) + 1 - NMSEDEC_FRACBITS;

        bpno = cblk->nonzerobits - 1;

    }



    ff_mqc_initenc(&t1->mqc, cblk->data);



    for (passno = 0; bpno >= 0; passno++){

        nmsedec=0;



        switch(pass_t){

            case 0: encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);

                    break;

            case 1: encode_refpass(t1, width, height, &nmsedec, bpno);

                    break;

            case 2: encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);

                    break;

        }



        cblk->passes[passno].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno].flushed, &cblk->passes[passno].flushed_len);

        wmsedec += (int64_t)nmsedec << (2*bpno);

        cblk->passes[passno].disto = wmsedec;



        if (++pass_t == 3){

            pass_t = 0;

            bpno--;

        }

    }

    cblk->npasses = passno;

    cblk->ninclpasses = passno;



    cblk->passes[passno-1].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno-1].flushed, &cblk->passes[passno-1].flushed_len);

}

    ff_mqc_initenc(&t1->mqc, cblk->data);
static void FUNC_0(Jpeg2000EncoderContext *VAR_0, Jpeg2000T1Context *VAR_1, Jpeg2000Cblk *VAR_2, Jpeg2000Tile *VAR_3,

                        int VAR_4, int VAR_5, int VAR_6, int VAR_7)

{

    int VAR_8 = 2, VAR_9, VAR_10, VAR_11, VAR_12=0, VAR_13, VAR_14;

    int64_t wmsedec = 0;



    memset(VAR_1->flags, 0, VAR_1->stride * (VAR_5 + 2) * sizeof(*VAR_1->flags));



    for (VAR_11 = 0; VAR_11 < VAR_5; VAR_11++){

        for (VAR_10 = 0; VAR_10 < VAR_4; VAR_10++){

            if (VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10] < 0){

                VAR_1->flags[(VAR_11+1) * VAR_1->stride + VAR_10+1] |= JPEG2000_T1_SGN;

                VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10] = -VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10];

            }

            VAR_12 = FFMAX(VAR_12, VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10]);

        }

    }



    if (VAR_12 == 0){

        VAR_2->nonzerobits = 0;

        VAR_14 = 0;

    } else{

        VAR_2->nonzerobits = av_log2(VAR_12) + 1 - NMSEDEC_FRACBITS;

        VAR_14 = VAR_2->nonzerobits - 1;

    }



    ff_mqc_initenc(&VAR_1->mqc, VAR_2->data);



    for (VAR_9 = 0; VAR_14 >= 0; VAR_9++){

        VAR_13=0;



        switch(VAR_8){

            case 0: encode_sigpass(VAR_1, VAR_4, VAR_5, VAR_6, &VAR_13, VAR_14);

                    break;

            case 1: encode_refpass(VAR_1, VAR_4, VAR_5, &VAR_13, VAR_14);

                    break;

            case 2: encode_clnpass(VAR_1, VAR_4, VAR_5, VAR_6, &VAR_13, VAR_14);

                    break;

        }



        VAR_2->passes[VAR_9].rate = ff_mqc_flush_to(&VAR_1->mqc, VAR_2->passes[VAR_9].flushed, &VAR_2->passes[VAR_9].flushed_len);

        wmsedec += (int64_t)VAR_13 << (2*VAR_14);

        VAR_2->passes[VAR_9].disto = wmsedec;



        if (++VAR_8 == 3){

            VAR_8 = 0;

            VAR_14--;

        }

    }

    VAR_2->npasses = VAR_9;

    VAR_2->ninclpasses = VAR_9;



    VAR_2->passes[VAR_9-1].rate = ff_mqc_flush_to(&VAR_1->mqc, VAR_2->passes[VAR_9-1].flushed, &VAR_2->passes[VAR_9-1].flushed_len);

}

static void FUNC_0(Jpeg2000EncoderContext *VAR_0, Jpeg2000T1Context *VAR_1, Jpeg2000Cblk *VAR_2, Jpeg2000Tile *VAR_3,
int VAR_4, int VAR_5, int VAR_6, int VAR_7)
{ int VAR_8 = 2, VAR_9, VAR_10, VAR_11, VAR_12=0, VAR_13, VAR_14; int64_t wmsedec = 0; memset(VAR_1->flags, 0, VAR_1->stride * (VAR_5 + 2) * sizeof(*VAR_1->flags)); for (VAR_11 = 0; VAR_11 < VAR_5; VAR_11++){ for (VAR_10 = 0; VAR_10 < VAR_4; VAR_10++){ if (VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10] < 0){ VAR_1->flags[(VAR_11+1) * VAR_1->stride + VAR_10+1] |= JPEG2000_T1_SGN; VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10] = -VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10]; } VAR_12 = FFMAX(VAR_12, VAR_1->data[(VAR_11) * VAR_1->stride + VAR_10]); } } if (VAR_12 == 0){ VAR_2->nonzerobits = 0; VAR_14 = 0; } else{ VAR_2->nonzerobits = av_log2(VAR_12) + 1 - NMSEDEC_FRACBITS; VAR_14 = VAR_2->nonzerobits - 1; } ff_mqc_initenc(&VAR_1->mqc, VAR_2->data); for (VAR_9 = 0; VAR_14 >= 0; VAR_9++){ VAR_13=0; switch(VAR_8){ case 0: encode_sigpass(VAR_1, VAR_4, VAR_5, VAR_6, &VAR_13, VAR_14); break; case 1: encode_refpass(VAR_1, VAR_4, VAR_5, &VAR_13, VAR_14); break; case 2: encode_clnpass(VAR_1, VAR_4, VAR_5, VAR_6, &VAR_13, VAR_14); break; } VAR_2->passes[VAR_9].rate = ff_mqc_flush_to(&VAR_1->mqc, VAR_2->passes[VAR_9].flushed, &VAR_2->passes[VAR_9].flushed_len); wmsedec += (int64_t)VAR_13 << (2*VAR_14); VAR_2->passes[VAR_9].disto = wmsedec; if (++VAR_8 == 3){ VAR_8 = 0; VAR_14--; } } VAR_2->npasses = VAR_9; VAR_2->ninclpasses = VAR_9; VAR_2->passes[VAR_9-1].rate = ff_mqc_flush_to(&VAR_1->mqc, VAR_2->passes[VAR_9-1].flushed, &VAR_2->passes[VAR_9-1].flushed_len); }