static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,

                                             int RSpoc, int CSpoc,

                                             int LYEpoc, int REpoc, int CEpoc,

                                             int Ppoc)

{

    int ret = 0;

    int layno, reslevelno, compno, precno, ok_reslevel;

    int x, y;

    int tp_index = 0;

    int step_x, step_y;



    switch (Ppoc) {

    case JPEG2000_PGOD_RLCP:

        av_log(s->avctx, AV_LOG_DEBUG, "Progression order RLCP\n");

        ok_reslevel = 1;

        for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {

            ok_reslevel = 0;

            for (layno = 0; layno < LYEpoc; layno++) {

                for (compno = CSpoc; compno < CEpoc; 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, tile, &tp_index,

                                                              codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_LRCP:

        av_log(s->avctx, AV_LOG_DEBUG, "Progression order LRCP\n");

        for (layno = 0; layno < LYEpoc; layno++) {

            ok_reslevel = 1;

            for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {

                ok_reslevel = 0;

                for (compno = CSpoc; compno < CEpoc; 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, tile, &tp_index,

                                                              codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_CPRL:

        av_log(s->avctx, AV_LOG_DEBUG, "Progression order CPRL\n");

        for (compno = CSpoc; compno < CEpoc; compno++) {

            Jpeg2000Component *comp     = tile->comp + compno;

            Jpeg2000CodingStyle *codsty = tile->codsty + compno;

            Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

            step_x = 32;

            step_y = 32;



            for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

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

                Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                step_x = FFMIN(step_x, rlevel->log2_prec_width  + reducedresno);

                step_y = FFMIN(step_y, rlevel->log2_prec_height + reducedresno);

            }

            step_x = 1<<step_x;

            step_y = 1<<step_y;



            for (y = tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {

                for (x = tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {

                    for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

                        unsigned prcx, prcy;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                        int xc = x / s->cdx[compno];

                        int yc = y / s->cdy[compno];



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) //FIXME this is a subset of the check

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) //FIXME this is a subset of the check

                            continue;



                        // check if a precinct exists

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        precno = prcx + rlevel->num_precincts_x * prcy;



                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(s->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



                        for (layno = 0; layno < LYEpoc; layno++) {

                            if ((ret = jpeg2000_decode_packet(s, tile, &tp_index, codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                        }

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_RPCL:

        av_log(s->avctx, AV_LOG_WARNING, "Progression order RPCL\n");

        ok_reslevel = 1;

        for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {

            ok_reslevel = 0;

            step_x = 30;

            step_y = 30;

            for (compno = CSpoc; compno < CEpoc; compno++) {

                Jpeg2000Component *comp     = tile->comp + compno;

                Jpeg2000CodingStyle *codsty = tile->codsty + compno;



                if (reslevelno < codsty->nreslevels) {

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

                    Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                    step_x = FFMIN(step_x, rlevel->log2_prec_width  + reducedresno);

                    step_y = FFMIN(step_y, rlevel->log2_prec_height + reducedresno);

                }

            }

            step_x = 1<<step_x;

            step_y = 1<<step_y;



            for (y = tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {

                for (x = tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {

                    for (compno = CSpoc; compno < CEpoc; compno++) {

                        Jpeg2000Component *comp     = tile->comp + compno;

                        Jpeg2000CodingStyle *codsty = tile->codsty + compno;

                        Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                        unsigned prcx, prcy;



                        int xc = x / s->cdx[compno];

                        int yc = y / s->cdy[compno];



                        if (reslevelno >= codsty->nreslevels)

                            continue;



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) //FIXME this is a subset of the check

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) //FIXME this is a subset of the check

                            continue;



                        // check if a precinct exists

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        precno = prcx + rlevel->num_precincts_x * prcy;



                        ok_reslevel = 1;

                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(s->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



                            for (layno = 0; layno < LYEpoc; layno++) {

                                if ((ret = jpeg2000_decode_packet(s, tile, &tp_index,

                                                                codsty, rlevel,

                                                                precno, layno,

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

                                                                qntsty->nguardbits)) < 0)

                                    return ret;

                            }

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_PCRL:

        av_log(s->avctx, AV_LOG_WARNING, "Progression order PCRL\n");

        step_x = 32;

        step_y = 32;

        for (compno = CSpoc; compno < CEpoc; compno++) {

            Jpeg2000Component *comp     = tile->comp + compno;

            Jpeg2000CodingStyle *codsty = tile->codsty + compno;

            Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;



            for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

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

                Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                step_x = FFMIN(step_x, rlevel->log2_prec_width  + reducedresno);

                step_y = FFMIN(step_y, rlevel->log2_prec_height + reducedresno);

            }

        }

        step_x = 1<<step_x;

        step_y = 1<<step_y;



        for (y = tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {

            for (x = tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {

                for (compno = CSpoc; compno < CEpoc; compno++) {

                    Jpeg2000Component *comp     = tile->comp + compno;

                    Jpeg2000CodingStyle *codsty = tile->codsty + compno;

                    Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

                    int xc = x / s->cdx[compno];

                    int yc = y / s->cdy[compno];



                    for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

                        unsigned prcx, prcy;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) //FIXME this is a subset of the check

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) //FIXME this is a subset of the check

                            continue;



                        // check if a precinct exists

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        precno = prcx + rlevel->num_precincts_x * prcy;



                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(s->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



                        for (layno = 0; layno < LYEpoc; layno++) {

                            if ((ret = jpeg2000_decode_packet(s, tile, &tp_index, codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                        }

                    }

                }

            }

        }

        break;



    default:

        break;

    }



    return ret;

}

static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,

                                             int RSpoc, int CSpoc,

                                             int LYEpoc, int REpoc, int CEpoc,

                                             int Ppoc)

{

    int ret = 0;

    int layno, reslevelno, compno, precno, ok_reslevel;

    int x, y;

    int tp_index = 0;

    int step_x, step_y;



    switch (Ppoc) {

    case JPEG2000_PGOD_RLCP:

        av_log(s->avctx, AV_LOG_DEBUG, "Progression order RLCP\n");

        ok_reslevel = 1;

        for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {

            ok_reslevel = 0;

            for (layno = 0; layno < LYEpoc; layno++) {

                for (compno = CSpoc; compno < CEpoc; 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, tile, &tp_index,

                                                              codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_LRCP:

        av_log(s->avctx, AV_LOG_DEBUG, "Progression order LRCP\n");

        for (layno = 0; layno < LYEpoc; layno++) {

            ok_reslevel = 1;

            for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {

                ok_reslevel = 0;

                for (compno = CSpoc; compno < CEpoc; 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, tile, &tp_index,

                                                              codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_CPRL:

        av_log(s->avctx, AV_LOG_DEBUG, "Progression order CPRL\n");

        for (compno = CSpoc; compno < CEpoc; compno++) {

            Jpeg2000Component *comp     = tile->comp + compno;

            Jpeg2000CodingStyle *codsty = tile->codsty + compno;

            Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

            step_x = 32;

            step_y = 32;



            for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

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

                Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                step_x = FFMIN(step_x, rlevel->log2_prec_width  + reducedresno);

                step_y = FFMIN(step_y, rlevel->log2_prec_height + reducedresno);

            }

            step_x = 1<<step_x;

            step_y = 1<<step_y;



            for (y = tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {

                for (x = tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {

                    for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

                        unsigned prcx, prcy;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                        int xc = x / s->cdx[compno];

                        int yc = y / s->cdy[compno];



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) 

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) 

                            continue;



                        

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        precno = prcx + rlevel->num_precincts_x * prcy;



                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(s->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



                        for (layno = 0; layno < LYEpoc; layno++) {

                            if ((ret = jpeg2000_decode_packet(s, tile, &tp_index, codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                        }

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_RPCL:

        av_log(s->avctx, AV_LOG_WARNING, "Progression order RPCL\n");

        ok_reslevel = 1;

        for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {

            ok_reslevel = 0;

            step_x = 30;

            step_y = 30;

            for (compno = CSpoc; compno < CEpoc; compno++) {

                Jpeg2000Component *comp     = tile->comp + compno;

                Jpeg2000CodingStyle *codsty = tile->codsty + compno;



                if (reslevelno < codsty->nreslevels) {

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

                    Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                    step_x = FFMIN(step_x, rlevel->log2_prec_width  + reducedresno);

                    step_y = FFMIN(step_y, rlevel->log2_prec_height + reducedresno);

                }

            }

            step_x = 1<<step_x;

            step_y = 1<<step_y;



            for (y = tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {

                for (x = tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {

                    for (compno = CSpoc; compno < CEpoc; compno++) {

                        Jpeg2000Component *comp     = tile->comp + compno;

                        Jpeg2000CodingStyle *codsty = tile->codsty + compno;

                        Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                        unsigned prcx, prcy;



                        int xc = x / s->cdx[compno];

                        int yc = y / s->cdy[compno];



                        if (reslevelno >= codsty->nreslevels)

                            continue;



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) 

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) 

                            continue;



                        

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        precno = prcx + rlevel->num_precincts_x * prcy;



                        ok_reslevel = 1;

                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(s->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



                            for (layno = 0; layno < LYEpoc; layno++) {

                                if ((ret = jpeg2000_decode_packet(s, tile, &tp_index,

                                                                codsty, rlevel,

                                                                precno, layno,

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

                                                                qntsty->nguardbits)) < 0)

                                    return ret;

                            }

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_PCRL:

        av_log(s->avctx, AV_LOG_WARNING, "Progression order PCRL\n");

        step_x = 32;

        step_y = 32;

        for (compno = CSpoc; compno < CEpoc; compno++) {

            Jpeg2000Component *comp     = tile->comp + compno;

            Jpeg2000CodingStyle *codsty = tile->codsty + compno;

            Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;



            for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

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

                Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;

                step_x = FFMIN(step_x, rlevel->log2_prec_width  + reducedresno);

                step_y = FFMIN(step_y, rlevel->log2_prec_height + reducedresno);

            }

        }

        step_x = 1<<step_x;

        step_y = 1<<step_y;



        for (y = tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {

            for (x = tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {

                for (compno = CSpoc; compno < CEpoc; compno++) {

                    Jpeg2000Component *comp     = tile->comp + compno;

                    Jpeg2000CodingStyle *codsty = tile->codsty + compno;

                    Jpeg2000QuantStyle *qntsty  = tile->qntsty + compno;

                    int xc = x / s->cdx[compno];

                    int yc = y / s->cdy[compno];



                    for (reslevelno = RSpoc; reslevelno < FFMIN(codsty->nreslevels, REpoc); reslevelno++) {

                        unsigned prcx, prcy;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && y != tile->coord[1][0]) 

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && x != tile->coord[0][0]) 

                            continue;



                        

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        precno = prcx + rlevel->num_precincts_x * prcy;



                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(s->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



                        for (layno = 0; layno < LYEpoc; layno++) {

                            if ((ret = jpeg2000_decode_packet(s, tile, &tp_index, codsty, rlevel,

                                                              precno, layno,

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

                                                              qntsty->nguardbits)) < 0)

                                return ret;

                        }

                    }

                }

            }

        }

        break;



    default:

        break;

    }



    return ret;

}

static int FUNC_0(Jpeg2000DecoderContext *VAR_0, Jpeg2000Tile *VAR_1,

                                             int VAR_2, int VAR_3,

                                             int VAR_4, int VAR_5, int VAR_6,

                                             int VAR_7)

{

    int VAR_8 = 0;

    int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;

    int VAR_14, VAR_15;

    int VAR_16 = 0;

    int VAR_17, VAR_18;



    switch (VAR_7) {

    case JPEG2000_PGOD_RLCP:

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "Progression order RLCP\n");

        VAR_13 = 1;

        for (VAR_10 = VAR_2; VAR_13 && VAR_10 < VAR_5; VAR_10++) {

            VAR_13 = 0;

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

                for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

                    Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;

                    Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11;

                    if (VAR_10 < codsty->nreslevels) {

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

                                                VAR_10;

                        VAR_13 = 1;

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

                            if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16,

                                                              codsty, rlevel,

                                                              VAR_12, VAR_9,

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

                                                              qntsty->nguardbits)) < 0)

                                return VAR_8;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_LRCP:

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "Progression order LRCP\n");

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

            VAR_13 = 1;

            for (VAR_10 = VAR_2; VAR_13 && VAR_10 < VAR_5; VAR_10++) {

                VAR_13 = 0;

                for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

                    Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;

                    Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11;

                    if (VAR_10 < codsty->nreslevels) {

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

                                                VAR_10;

                        VAR_13 = 1;

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

                            if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16,

                                                              codsty, rlevel,

                                                              VAR_12, VAR_9,

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

                                                              qntsty->nguardbits)) < 0)

                                return VAR_8;

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_CPRL:

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "Progression order CPRL\n");

        for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

            Jpeg2000Component *comp     = VAR_1->comp + VAR_11;

            Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;

            Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11;

            VAR_17 = 32;

            VAR_18 = 32;



            for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) {

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

                Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10;

                VAR_17 = FFMIN(VAR_17, rlevel->log2_prec_width  + reducedresno);

                VAR_18 = FFMIN(VAR_18, rlevel->log2_prec_height + reducedresno);

            }

            VAR_17 = 1<<VAR_17;

            VAR_18 = 1<<VAR_18;



            for (VAR_15 = VAR_1->coord[1][0]; VAR_15 < VAR_1->coord[1][1]; VAR_15 = (VAR_15/VAR_18 + 1)*VAR_18) {

                for (VAR_14 = VAR_1->coord[0][0]; VAR_14 < VAR_1->coord[0][1]; VAR_14 = (VAR_14/VAR_17 + 1)*VAR_17) {

                    for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) {

                        unsigned prcx, prcy;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10;

                        int xc = VAR_14 / VAR_0->cdx[VAR_11];

                        int yc = VAR_15 / VAR_0->cdy[VAR_11];



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && VAR_15 != VAR_1->coord[1][0]) 

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && VAR_14 != VAR_1->coord[0][0]) 

                            continue;



                        

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        VAR_12 = prcx + rlevel->num_precincts_x * prcy;



                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(VAR_0->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



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

                            if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16, codsty, rlevel,

                                                              VAR_12, VAR_9,

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

                                                              qntsty->nguardbits)) < 0)

                                return VAR_8;

                        }

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_RPCL:

        av_log(VAR_0->avctx, AV_LOG_WARNING, "Progression order RPCL\n");

        VAR_13 = 1;

        for (VAR_10 = VAR_2; VAR_13 && VAR_10 < VAR_5; VAR_10++) {

            VAR_13 = 0;

            VAR_17 = 30;

            VAR_18 = 30;

            for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

                Jpeg2000Component *comp     = VAR_1->comp + VAR_11;

                Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;



                if (VAR_10 < codsty->nreslevels) {

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

                    Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10;

                    VAR_17 = FFMIN(VAR_17, rlevel->log2_prec_width  + reducedresno);

                    VAR_18 = FFMIN(VAR_18, rlevel->log2_prec_height + reducedresno);

                }

            }

            VAR_17 = 1<<VAR_17;

            VAR_18 = 1<<VAR_18;



            for (VAR_15 = VAR_1->coord[1][0]; VAR_15 < VAR_1->coord[1][1]; VAR_15 = (VAR_15/VAR_18 + 1)*VAR_18) {

                for (VAR_14 = VAR_1->coord[0][0]; VAR_14 < VAR_1->coord[0][1]; VAR_14 = (VAR_14/VAR_17 + 1)*VAR_17) {

                    for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

                        Jpeg2000Component *comp     = VAR_1->comp + VAR_11;

                        Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;

                        Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10;

                        unsigned prcx, prcy;



                        int xc = VAR_14 / VAR_0->cdx[VAR_11];

                        int yc = VAR_15 / VAR_0->cdy[VAR_11];



                        if (VAR_10 >= codsty->nreslevels)

                            continue;



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && VAR_15 != VAR_1->coord[1][0]) 

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && VAR_14 != VAR_1->coord[0][0]) 

                            continue;



                        

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        VAR_12 = prcx + rlevel->num_precincts_x * prcy;



                        VAR_13 = 1;

                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(VAR_0->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



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

                                if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16,

                                                                codsty, rlevel,

                                                                VAR_12, VAR_9,

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

                                                                qntsty->nguardbits)) < 0)

                                    return VAR_8;

                            }

                    }

                }

            }

        }

        break;



    case JPEG2000_PGOD_PCRL:

        av_log(VAR_0->avctx, AV_LOG_WARNING, "Progression order PCRL\n");

        VAR_17 = 32;

        VAR_18 = 32;

        for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

            Jpeg2000Component *comp     = VAR_1->comp + VAR_11;

            Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;

            Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11;



            for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) {

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

                Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10;

                VAR_17 = FFMIN(VAR_17, rlevel->log2_prec_width  + reducedresno);

                VAR_18 = FFMIN(VAR_18, rlevel->log2_prec_height + reducedresno);

            }

        }

        VAR_17 = 1<<VAR_17;

        VAR_18 = 1<<VAR_18;



        for (VAR_15 = VAR_1->coord[1][0]; VAR_15 < VAR_1->coord[1][1]; VAR_15 = (VAR_15/VAR_18 + 1)*VAR_18) {

            for (VAR_14 = VAR_1->coord[0][0]; VAR_14 < VAR_1->coord[0][1]; VAR_14 = (VAR_14/VAR_17 + 1)*VAR_17) {

                for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) {

                    Jpeg2000Component *comp     = VAR_1->comp + VAR_11;

                    Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11;

                    Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11;

                    int xc = VAR_14 / VAR_0->cdx[VAR_11];

                    int yc = VAR_15 / VAR_0->cdy[VAR_11];



                    for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) {

                        unsigned prcx, prcy;

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

                        Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10;



                        if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && VAR_15 != VAR_1->coord[1][0]) 

                            continue;



                        if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && VAR_14 != VAR_1->coord[0][0]) 

                            continue;



                        

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

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

                        prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width;

                        prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height;



                        VAR_12 = prcx + rlevel->num_precincts_x * prcy;



                        if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) {

                            av_log(VAR_0->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",

                                   prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y);

                            continue;

                        }



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

                            if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16, codsty, rlevel,

                                                              VAR_12, VAR_9,

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

                                                              qntsty->nguardbits)) < 0)

                                return VAR_8;

                        }

                    }

                }

            }

        }

        break;



    default:

        break;

    }



    return VAR_8;

}

static int FUNC_0(Jpeg2000DecoderContext *VAR_0, Jpeg2000Tile *VAR_1,
int VAR_2, int VAR_3,
int VAR_4, int VAR_5, int VAR_6,
int VAR_7)
{ int VAR_8 = 0; int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; int VAR_14, VAR_15; int VAR_16 = 0; int VAR_17, VAR_18; switch (VAR_7) { case JPEG2000_PGOD_RLCP:
av_log(VAR_0->avctx, AV_LOG_DEBUG, "Progression order RLCP\n"); VAR_13 = 1; for (VAR_10 = VAR_2; VAR_13 && VAR_10 < VAR_5; VAR_10++) { VAR_13 = 0; for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) { for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11; if (VAR_10 < codsty->nreslevels) { Jpeg2000ResLevel *rlevel = VAR_1->comp[VAR_11].reslevel +
VAR_10; VAR_13 = 1; for (VAR_12 = 0; VAR_12 < rlevel->num_precincts_x * rlevel->num_precincts_y; VAR_12++) if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16,
codsty, rlevel,
VAR_12, VAR_9,
qntsty->expn + (VAR_10 ? 3 * (VAR_10 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_8; } } } } break; case JPEG2000_PGOD_LRCP:
av_log(VAR_0->avctx, AV_LOG_DEBUG, "Progression order LRCP\n"); for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) { VAR_13 = 1; for (VAR_10 = VAR_2; VAR_13 && VAR_10 < VAR_5; VAR_10++) { VAR_13 = 0; for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11; if (VAR_10 < codsty->nreslevels) { Jpeg2000ResLevel *rlevel = VAR_1->comp[VAR_11].reslevel +
VAR_10; VAR_13 = 1; for (VAR_12 = 0; VAR_12 < rlevel->num_precincts_x * rlevel->num_precincts_y; VAR_12++) if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16,
codsty, rlevel,
VAR_12, VAR_9,
qntsty->expn + (VAR_10 ? 3 * (VAR_10 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_8; } } } } break; case JPEG2000_PGOD_CPRL:
av_log(VAR_0->avctx, AV_LOG_DEBUG, "Progression order CPRL\n"); for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000Component *comp     = VAR_1->comp + VAR_11; Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11; VAR_17 = 32; VAR_18 = 32; for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) { uint8_t reducedresno = codsty->nreslevels - 1 -VAR_10; Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10; VAR_17 = FFMIN(VAR_17, rlevel->log2_prec_width  + reducedresno); VAR_18 = FFMIN(VAR_18, rlevel->log2_prec_height + reducedresno); } VAR_17 = 1<<VAR_17; VAR_18 = 1<<VAR_18; for (VAR_15 = VAR_1->coord[1][0]; VAR_15 < VAR_1->coord[1][1]; VAR_15 = (VAR_15/VAR_18 + 1)*VAR_18) { for (VAR_14 = VAR_1->coord[0][0]; VAR_14 < VAR_1->coord[0][1]; VAR_14 = (VAR_14/VAR_17 + 1)*VAR_17) { for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) { unsigned prcx, prcy; uint8_t reducedresno = codsty->nreslevels - 1 -VAR_10; Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10; int xc = VAR_14 / VAR_0->cdx[VAR_11]; int yc = VAR_15 / VAR_0->cdy[VAR_11]; if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && VAR_15 != VAR_1->coord[1][0])
continue; if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && VAR_14 != VAR_1->coord[0][0])
continue; prcx   = ff_jpeg2000_ceildivpow2(xc, reducedresno) >> rlevel->log2_prec_width; prcy   = ff_jpeg2000_ceildivpow2(yc, reducedresno) >> rlevel->log2_prec_height; prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width; prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height; VAR_12 = prcx + rlevel->num_precincts_x * prcy; if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) { av_log(VAR_0->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",
prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y); continue; } for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) { if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16, codsty, rlevel,
VAR_12, VAR_9,
qntsty->expn + (VAR_10 ? 3 * (VAR_10 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_8; } } } } } break; case JPEG2000_PGOD_RPCL:
av_log(VAR_0->avctx, AV_LOG_WARNING, "Progression order RPCL\n"); VAR_13 = 1; for (VAR_10 = VAR_2; VAR_13 && VAR_10 < VAR_5; VAR_10++) { VAR_13 = 0; VAR_17 = 30; VAR_18 = 30; for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000Component *comp     = VAR_1->comp + VAR_11; Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; if (VAR_10 < codsty->nreslevels) { uint8_t reducedresno = codsty->nreslevels - 1 -VAR_10; Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10; VAR_17 = FFMIN(VAR_17, rlevel->log2_prec_width  + reducedresno); VAR_18 = FFMIN(VAR_18, rlevel->log2_prec_height + reducedresno); } } VAR_17 = 1<<VAR_17; VAR_18 = 1<<VAR_18; for (VAR_15 = VAR_1->coord[1][0]; VAR_15 < VAR_1->coord[1][1]; VAR_15 = (VAR_15/VAR_18 + 1)*VAR_18) { for (VAR_14 = VAR_1->coord[0][0]; VAR_14 < VAR_1->coord[0][1]; VAR_14 = (VAR_14/VAR_17 + 1)*VAR_17) { for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000Component *comp     = VAR_1->comp + VAR_11; Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11; uint8_t reducedresno = codsty->nreslevels - 1 -VAR_10; Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10; unsigned prcx, prcy; int xc = VAR_14 / VAR_0->cdx[VAR_11]; int yc = VAR_15 / VAR_0->cdy[VAR_11]; if (VAR_10 >= codsty->nreslevels)
continue; if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && VAR_15 != VAR_1->coord[1][0])
continue; if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && VAR_14 != VAR_1->coord[0][0])
continue; prcx   = ff_jpeg2000_ceildivpow2(xc, reducedresno) >> rlevel->log2_prec_width; prcy   = ff_jpeg2000_ceildivpow2(yc, reducedresno) >> rlevel->log2_prec_height; prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width; prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height; VAR_12 = prcx + rlevel->num_precincts_x * prcy; VAR_13 = 1; if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) { av_log(VAR_0->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",
prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y); continue; } for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) { if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16,
codsty, rlevel,
VAR_12, VAR_9,
qntsty->expn + (VAR_10 ? 3 * (VAR_10 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_8; } } } } } break; case JPEG2000_PGOD_PCRL:
av_log(VAR_0->avctx, AV_LOG_WARNING, "Progression order PCRL\n"); VAR_17 = 32; VAR_18 = 32; for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000Component *comp     = VAR_1->comp + VAR_11; Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11; for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) { uint8_t reducedresno = codsty->nreslevels - 1 -VAR_10; Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10; VAR_17 = FFMIN(VAR_17, rlevel->log2_prec_width  + reducedresno); VAR_18 = FFMIN(VAR_18, rlevel->log2_prec_height + reducedresno); } } VAR_17 = 1<<VAR_17; VAR_18 = 1<<VAR_18; for (VAR_15 = VAR_1->coord[1][0]; VAR_15 < VAR_1->coord[1][1]; VAR_15 = (VAR_15/VAR_18 + 1)*VAR_18) { for (VAR_14 = VAR_1->coord[0][0]; VAR_14 < VAR_1->coord[0][1]; VAR_14 = (VAR_14/VAR_17 + 1)*VAR_17) { for (VAR_11 = VAR_3; VAR_11 < VAR_6; VAR_11++) { Jpeg2000Component *comp     = VAR_1->comp + VAR_11; Jpeg2000CodingStyle *codsty = VAR_1->codsty + VAR_11; Jpeg2000QuantStyle *qntsty  = VAR_1->qntsty + VAR_11; int xc = VAR_14 / VAR_0->cdx[VAR_11]; int yc = VAR_15 / VAR_0->cdy[VAR_11]; for (VAR_10 = VAR_2; VAR_10 < FFMIN(codsty->nreslevels, VAR_5); VAR_10++) { unsigned prcx, prcy; uint8_t reducedresno = codsty->nreslevels - 1 -VAR_10; Jpeg2000ResLevel *rlevel = comp->reslevel + VAR_10; if (yc % (1 << (rlevel->log2_prec_height + reducedresno)) && VAR_15 != VAR_1->coord[1][0])
continue; if (xc % (1 << (rlevel->log2_prec_width + reducedresno)) && VAR_14 != VAR_1->coord[0][0])
continue; prcx   = ff_jpeg2000_ceildivpow2(xc, reducedresno) >> rlevel->log2_prec_width; prcy   = ff_jpeg2000_ceildivpow2(yc, reducedresno) >> rlevel->log2_prec_height; prcx  -= ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], reducedresno) >> rlevel->log2_prec_width; prcy  -= ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], reducedresno) >> rlevel->log2_prec_height; VAR_12 = prcx + rlevel->num_precincts_x * prcy; if (prcx >= rlevel->num_precincts_x || prcy >= rlevel->num_precincts_y) { av_log(VAR_0->avctx, AV_LOG_WARNING, "prc %d %d outside limits %d %d\n",
prcx, prcy, rlevel->num_precincts_x, rlevel->num_precincts_y); continue; } for (VAR_9 = 0; VAR_9 < VAR_4; VAR_9++) { if ((VAR_8 = jpeg2000_decode_packet(VAR_0, VAR_1, &VAR_16, codsty, rlevel,
VAR_12, VAR_9,
qntsty->expn + (VAR_10 ? 3 * (VAR_10 - 1) + 1 : 0),
qntsty->nguardbits)) < 0)
return VAR_8; } } } } } break; default:
break; } return VAR_8; }