static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno,

                         int layno, uint8_t *expn, int numgbits)

{

    int bandno, cblkny, cblknx, cblkno, ret;



    if (!(ret = get_bits(s, 1))){

        j2k_flush(s);

        return 0;

    } else if (ret < 0)

        return ret;



    for (bandno = 0; bandno < rlevel->nbands; bandno++){

        J2kBand *band = rlevel->band + bandno;

        J2kPrec *prec = band->prec + precno;

        int pos = 0;



        if (band->coord[0][0] == band->coord[0][1]

        ||  band->coord[1][0] == band->coord[1][1])

            continue;



        for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)

            for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){

                J2kCblk *cblk = band->cblk + cblkno;

                int incl, newpasses, llen;



                if (cblk->npasses)

                    incl = get_bits(s, 1);

                else

                    incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno;

                if (!incl)

                    continue;

                else if (incl < 0)

                    return incl;



                if (!cblk->npasses)

                    cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100);

                if ((newpasses = getnpasses(s)) < 0)

                    return newpasses;

                if ((llen = getlblockinc(s)) < 0)

                    return llen;

                cblk->lblock += llen;

                if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0)

                    return ret;

                cblk->lengthinc = ret;

                cblk->npasses += newpasses;

            }

    }

    j2k_flush(s);



    if (codsty->csty & J2K_CSTY_EPH) {

        if (AV_RB16(s->buf) == J2K_EPH) {

            s->buf += 2;

        } else {

            av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n");

        }

    }



    for (bandno = 0; bandno < rlevel->nbands; bandno++){

        J2kBand *band = rlevel->band + bandno;

        int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;

        for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){

            int xi;

            for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){

                J2kCblk *cblk = band->cblk + yi * cblknw + xi;

                if (s->buf_end - s->buf < cblk->lengthinc)

                    return AVERROR(EINVAL);

                bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);

                cblk->length += cblk->lengthinc;

                cblk->lengthinc = 0;

            }

        }

    }

    return 0;

}

static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno,

                         int layno, uint8_t *expn, int numgbits)

{

    int bandno, cblkny, cblknx, cblkno, ret;



    if (!(ret = get_bits(s, 1))){

        j2k_flush(s);

        return 0;

    } else if (ret < 0)

        return ret;



    for (bandno = 0; bandno < rlevel->nbands; bandno++){

        J2kBand *band = rlevel->band + bandno;

        J2kPrec *prec = band->prec + precno;

        int pos = 0;



        if (band->coord[0][0] == band->coord[0][1]

        ||  band->coord[1][0] == band->coord[1][1])

            continue;



        for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)

            for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){

                J2kCblk *cblk = band->cblk + cblkno;

                int incl, newpasses, llen;



                if (cblk->npasses)

                    incl = get_bits(s, 1);

                else

                    incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno;

                if (!incl)

                    continue;

                else if (incl < 0)

                    return incl;



                if (!cblk->npasses)

                    cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100);

                if ((newpasses = getnpasses(s)) < 0)

                    return newpasses;

                if ((llen = getlblockinc(s)) < 0)

                    return llen;

                cblk->lblock += llen;

                if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0)

                    return ret;

                cblk->lengthinc = ret;

                cblk->npasses += newpasses;

            }

    }

    j2k_flush(s);



    if (codsty->csty & J2K_CSTY_EPH) {

        if (AV_RB16(s->buf) == J2K_EPH) {

            s->buf += 2;

        } else {

            av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n");

        }

    }



    for (bandno = 0; bandno < rlevel->nbands; bandno++){

        J2kBand *band = rlevel->band + bandno;

        int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;

        for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){

            int xi;

            for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){

                J2kCblk *cblk = band->cblk + yi * cblknw + xi;

                if (s->buf_end - s->buf < cblk->lengthinc)

                    return AVERROR(EINVAL);

                bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);

                cblk->length += cblk->lengthinc;

                cblk->lengthinc = 0;

            }

        }

    }

    return 0;

}

        if (AV_RB16(s->buf) == J2K_EPH) {             s->buf += 2;                 if (s->buf_end - s->buf < cblk->lengthinc)                 bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
static int FUNC_0(J2kDecoderContext *VAR_0, J2kCodingStyle *VAR_1, J2kResLevel *VAR_2, int VAR_3,

                         int VAR_4, uint8_t *VAR_5, int VAR_6)

{

    int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;



    if (!(VAR_11 = get_bits(VAR_0, 1))){

        j2k_flush(VAR_0);

        return 0;

    } else if (VAR_11 < 0)

        return VAR_11;



    for (VAR_7 = 0; VAR_7 < VAR_2->nbands; VAR_7++){

        J2kBand *band = VAR_2->band + VAR_7;

        J2kPrec *prec = band->prec + VAR_3;

        int pos = 0;



        if (band->coord[0][0] == band->coord[0][1]

        ||  band->coord[1][0] == band->coord[1][1])

            continue;



        for (VAR_8 = prec->yi0; VAR_8 < prec->yi1; VAR_8++)

            for(VAR_9 = prec->xi0, VAR_10 = VAR_8 * band->VAR_9 + VAR_9; VAR_9 < prec->xi1; VAR_9++, VAR_10++, pos++){

                J2kCblk *cblk = band->cblk + VAR_10;

                int incl, newpasses, llen;



                if (cblk->npasses)

                    incl = get_bits(VAR_0, 1);

                else

                    incl = tag_tree_decode(VAR_0, prec->cblkincl + pos, VAR_4+1) == VAR_4;

                if (!incl)

                    continue;

                else if (incl < 0)

                    return incl;



                if (!cblk->npasses)

                    cblk->nonzerobits = VAR_5[VAR_7] + VAR_6 - 1 - tag_tree_decode(VAR_0, prec->zerobits + pos, 100);

                if ((newpasses = getnpasses(VAR_0)) < 0)

                    return newpasses;

                if ((llen = getlblockinc(VAR_0)) < 0)

                    return llen;

                cblk->lblock += llen;

                if ((VAR_11 = get_bits(VAR_0, av_log2(newpasses) + cblk->lblock)) < 0)

                    return VAR_11;

                cblk->lengthinc = VAR_11;

                cblk->npasses += newpasses;

            }

    }

    j2k_flush(VAR_0);



    if (VAR_1->csty & J2K_CSTY_EPH) {

        if (AV_RB16(VAR_0->buf) == J2K_EPH) {

            VAR_0->buf += 2;

        } else {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "EPH marker not found.\n");

        }

    }



    for (VAR_7 = 0; VAR_7 < VAR_2->nbands; VAR_7++){

        J2kBand *band = VAR_2->band + VAR_7;

        int yi, cblknw = band->prec[VAR_3].xi1 - band->prec[VAR_3].xi0;

        for (yi = band->prec[VAR_3].yi0; yi < band->prec[VAR_3].yi1; yi++){

            int xi;

            for (xi = band->prec[VAR_3].xi0; xi < band->prec[VAR_3].xi1; xi++){

                J2kCblk *cblk = band->cblk + yi * cblknw + xi;

                if (VAR_0->buf_end - VAR_0->buf < cblk->lengthinc)

                    return AVERROR(EINVAL);

                bytestream_get_buffer(&VAR_0->buf, cblk->data, cblk->lengthinc);

                cblk->length += cblk->lengthinc;

                cblk->lengthinc = 0;

            }

        }

    }

    return 0;

}

static int FUNC_0(J2kDecoderContext *VAR_0, J2kCodingStyle *VAR_1, J2kResLevel *VAR_2, int VAR_3,
int VAR_4, uint8_t *VAR_5, int VAR_6)
{ int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; if (!(VAR_11 = get_bits(VAR_0, 1))){ j2k_flush(VAR_0); return 0; } else if (VAR_11 < 0) return VAR_11; for (VAR_7 = 0; VAR_7 < VAR_2->nbands; VAR_7++){ J2kBand *band = VAR_2->band + VAR_7; J2kPrec *prec = band->prec + VAR_3; int pos = 0; if (band->coord[0][0] == band->coord[0][1]
||  band->coord[1][0] == band->coord[1][1])
continue; for (VAR_8 = prec->yi0; VAR_8 < prec->yi1; VAR_8++) for(VAR_9 = prec->xi0, VAR_10 = VAR_8 * band->VAR_9 + VAR_9; VAR_9 < prec->xi1; VAR_9++, VAR_10++, pos++){ J2kCblk *cblk = band->cblk + VAR_10; int incl, newpasses, llen; if (cblk->npasses)
incl = get_bits(VAR_0, 1); else
incl = tag_tree_decode(VAR_0, prec->cblkincl + pos, VAR_4+1) == VAR_4; if (!incl)
continue; else if (incl < 0)
return incl; if (!cblk->npasses)
cblk->nonzerobits = VAR_5[VAR_7] + VAR_6 - 1 - tag_tree_decode(VAR_0, prec->zerobits + pos, 100); if ((newpasses = getnpasses(VAR_0)) < 0)
return newpasses; if ((llen = getlblockinc(VAR_0)) < 0)
return llen; cblk->lblock += llen; if ((VAR_11 = get_bits(VAR_0, av_log2(newpasses) + cblk->lblock)) < 0)
return VAR_11; cblk->lengthinc = VAR_11; cblk->npasses += newpasses; } } j2k_flush(VAR_0); if (VAR_1->csty & J2K_CSTY_EPH) { if (AV_RB16(VAR_0->buf) == J2K_EPH) { VAR_0->buf += 2; } else { av_log(VAR_0->avctx, AV_LOG_ERROR, "EPH marker not found.\n"); } } for (VAR_7 = 0; VAR_7 < VAR_2->nbands; VAR_7++){ J2kBand *band = VAR_2->band + VAR_7; int yi, cblknw = band->prec[VAR_3].xi1 - band->prec[VAR_3].xi0; for (yi = band->prec[VAR_3].yi0; yi < band->prec[VAR_3].yi1; yi++){ int xi; for (xi = band->prec[VAR_3].xi0; xi < band->prec[VAR_3].xi1; xi++){ J2kCblk *cblk = band->cblk + yi * cblknw + xi; if (VAR_0->buf_end - VAR_0->buf < cblk->lengthinc)
return AVERROR(EINVAL); bytestream_get_buffer(&VAR_0->buf, cblk->data, cblk->lengthinc); cblk->length += cblk->lengthinc; cblk->lengthinc = 0; } } } return 0; }