static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)

{

    int layno, reslevelno, compno, precno, ok_reslevel, ret;

    uint8_t prog_order = tile->codsty[0].prog_order;

    uint16_t x;

    uint16_t y;



    s->bit_index = 8;

    switch (prog_order) {

    case JPEG2000_PGOD_LRCP:

        for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {

            ok_reslevel = 1;

            for (reslevelno = 0; ok_reslevel; reslevelno++) {

                ok_reslevel = 0;

                for (compno = 0; compno < s->ncomponents; compno++) {

                    Jpeg2000CodingStyle *codsty = tile->codsty + compno;

                    Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

                    if (reslevelno < codsty->nreslevels) {

                        Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel +

                                                   reslevelno;

                        ok_reslevel = 1;

                        for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++)

                            if ((ret = jpeg2000_decode_packet(s,

                                                              codsty, rlevel,

                                                              precno, layno,

                                                              qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_CPRL:

        for (compno = 0; compno < s->ncomponents; compno++) {

            Jpeg2000CodingStyle *codsty = tile->codsty + compno;

            Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;



            /* Set bit stream buffer address according to tile-part.

             * For DCinema one tile-part per component, so can be

             * indexed by component. */

            s->buf = tile->tile_part[compno].tp_start_bstrm;



            /* Position loop (y axis)

             * TODO: Automate computing of step 256.

             * Fixed here, but to be computed before entering here. */

            for (y = 0; y < s->height; y += 256) {

                /* Position loop (y axis)

                 * TODO: automate computing of step 256.

                 * Fixed here, but to be computed before entering here. */

                for (x = 0; x < s->width; x += 256) {

                    for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {

                        uint16_t prcx, prcy;

                        uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno; //  ==> N_L - r

                        Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;



                        if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||

                              (y == 0))) // TODO: 2nd condition simplified as try0 always =0 for dcinema

                            continue;



                        if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||

                              (x == 0))) // TODO: 2nd condition simplified as try0 always =0 for dcinema

                            continue;



                        // check if a precinct exists

                        prcx   = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;

                        prcy   = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;

                        precno = prcx + rlevel->num_precincts_x * prcy;

                        for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {

                            if ((ret = jpeg2000_decode_packet(s, codsty, rlevel,

                                                              precno, layno,

                                                              qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                        }

                    }

                }

            }

        }

        break;



    default:

        break;

    }



    /* EOC marker reached */

    s->buf += 2;



    return 0;

}

static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)

{

    int layno, reslevelno, compno, precno, ok_reslevel, ret;

    uint8_t prog_order = tile->codsty[0].prog_order;

    uint16_t x;

    uint16_t y;



    s->bit_index = 8;

    switch (prog_order) {

    case JPEG2000_PGOD_LRCP:

        for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {

            ok_reslevel = 1;

            for (reslevelno = 0; ok_reslevel; reslevelno++) {

                ok_reslevel = 0;

                for (compno = 0; compno < s->ncomponents; compno++) {

                    Jpeg2000CodingStyle *codsty = tile->codsty + compno;

                    Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

                    if (reslevelno < codsty->nreslevels) {

                        Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel +

                                                   reslevelno;

                        ok_reslevel = 1;

                        for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++)

                            if ((ret = jpeg2000_decode_packet(s,

                                                              codsty, rlevel,

                                                              precno, layno,

                                                              qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_CPRL:

        for (compno = 0; compno < s->ncomponents; compno++) {

            Jpeg2000CodingStyle *codsty = tile->codsty + compno;

            Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;



            





            s->buf = tile->tile_part[compno].tp_start_bstrm;



            





            for (y = 0; y < s->height; y += 256) {

                





                for (x = 0; x < s->width; x += 256) {

                    for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {

                        uint16_t prcx, prcy;

                        uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno; 

                        Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;



                        if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||

                              (y == 0))) 

                            continue;



                        if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||

                              (x == 0))) 

                            continue;



                        

                        prcx   = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;

                        prcy   = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;

                        precno = prcx + rlevel->num_precincts_x * prcy;

                        for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {

                            if ((ret = jpeg2000_decode_packet(s, codsty, rlevel,

                                                              precno, layno,

                                                              qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                        }

                    }

                }

            }

        }

        break;



    default:

        break;

    }



    

    s->buf += 2;



    return 0;

}

            s->buf = tile->tile_part[compno].tp_start_bstrm;     s->buf += 2;
static int FUNC_0(Jpeg2000DecoderContext *VAR_0, Jpeg2000Tile *VAR_1)

{

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;

    uint8_t prog_order = VAR_1->codsty[0].prog_order;

    uint16_t x;

    uint16_t y;



    VAR_0->bit_index = 8;

    switch (prog_order) {

    case JPEG2000_PGOD_LRCP:

        for (VAR_2 = 0; VAR_2 < VAR_1->codsty[0].nlayers; VAR_2++) {

            VAR_6 = 1;

            for (VAR_3 = 0; VAR_6; VAR_3++) {

                VAR_6 = 0;

                for (VAR_4 = 0; VAR_4 < VAR_0->ncomponents; VAR_4++) {

                    Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_4;

                    Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_4;

                    if (VAR_3 < codsty->nreslevels) {

                        Jpeg2000ResLevel *rlevel = VAR_1->comp[VAR_4].reslevel +

                                                   VAR_3;

                        VAR_6 = 1;

                        for (VAR_5 = 0; VAR_5 < rlevel->num_precincts_x * rlevel->num_precincts_y; VAR_5++)

                            if ((VAR_7 = jpeg2000_decode_packet(VAR_0,

                                                              codsty, rlevel,

                                                              VAR_5, VAR_2,

                                                              qntsty->expn + (VAR_3 ? 3 * (VAR_3 - 1) + 1 : 0),

                                                              qntsty->nguardbits)) < 0)

                                return VAR_7;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_CPRL:

        for (VAR_4 = 0; VAR_4 < VAR_0->ncomponents; VAR_4++) {

            Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_4;

            Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_4;



            





            VAR_0->buf = VAR_1->tile_part[VAR_4].tp_start_bstrm;



            





            for (y = 0; y < VAR_0->height; y += 256) {

                





                for (x = 0; x < VAR_0->width; x += 256) {

                    for (VAR_3 = 0; VAR_3 < codsty->nreslevels; VAR_3++) {

                        uint16_t prcx, prcy;

                        uint8_t reducedresno = codsty->nreslevels - 1 -VAR_3; 

                        Jpeg2000ResLevel *rlevel = VAR_1->comp[VAR_4].reslevel + VAR_3;



                        if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||

                              (y == 0))) 

                            continue;



                        if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||

                              (x == 0))) 

                            continue;



                        

                        prcx   = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;

                        prcy   = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;

                        VAR_5 = prcx + rlevel->num_precincts_x * prcy;

                        for (VAR_2 = 0; VAR_2 < VAR_1->codsty[0].nlayers; VAR_2++) {

                            if ((VAR_7 = jpeg2000_decode_packet(VAR_0, codsty, rlevel,

                                                              VAR_5, VAR_2,

                                                              qntsty->expn + (VAR_3 ? 3 * (VAR_3 - 1) + 1 : 0),

                                                              qntsty->nguardbits)) < 0)

                                return VAR_7;

                        }

                    }

                }

            }

        }

        break;



    default:

        break;

    }



    

    VAR_0->buf += 2;



    return 0;

}

static int FUNC_0(Jpeg2000DecoderContext *VAR_0, Jpeg2000Tile *VAR_1)
{ int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; uint8_t prog_order = VAR_1->codsty[0].prog_order; uint16_t x; uint16_t y; VAR_0->bit_index = 8; switch (prog_order) { case JPEG2000_PGOD_LRCP:
for (VAR_2 = 0; VAR_2 < VAR_1->codsty[0].nlayers; VAR_2++) { VAR_6 = 1; for (VAR_3 = 0; VAR_6; VAR_3++) { VAR_6 = 0; for (VAR_4 = 0; VAR_4 < VAR_0->ncomponents; VAR_4++) { Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_4; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_4; if (VAR_3 < codsty->nreslevels) { Jpeg2000ResLevel *rlevel = VAR_1->comp[VAR_4].reslevel +
VAR_3; VAR_6 = 1; for (VAR_5 = 0; VAR_5 < rlevel->num_precincts_x * rlevel->num_precincts_y; VAR_5++) if ((VAR_7 = jpeg2000_decode_packet(VAR_0,
codsty, rlevel,
VAR_5, VAR_2,
qntsty->expn + (VAR_3 ? 3 * (VAR_3 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_7; } } } } break; case JPEG2000_PGOD_CPRL:
for (VAR_4 = 0; VAR_4 < VAR_0->ncomponents; VAR_4++) { Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_4; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_4; VAR_0->buf = VAR_1->tile_part[VAR_4].tp_start_bstrm; for (y = 0; y < VAR_0->height; y += 256) { for (x = 0; x < VAR_0->width; x += 256) { for (VAR_3 = 0; VAR_3 < codsty->nreslevels; VAR_3++) { uint16_t prcx, prcy; uint8_t reducedresno = codsty->nreslevels - 1 -VAR_3; Jpeg2000ResLevel *rlevel = VAR_1->comp[VAR_4].reslevel + VAR_3; if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||
(y == 0)))
continue; if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||
(x == 0)))
continue; prcx   = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width; prcy   = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height; VAR_5 = prcx + rlevel->num_precincts_x * prcy; for (VAR_2 = 0; VAR_2 < VAR_1->codsty[0].nlayers; VAR_2++) { if ((VAR_7 = jpeg2000_decode_packet(VAR_0, codsty, rlevel,
VAR_5, VAR_2,
qntsty->expn + (VAR_3 ? 3 * (VAR_3 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_7; } } } } } break; default:
break; } VAR_0->buf += 2; return 0; }