static int init_tile(Jpeg2000DecoderContext *s, int tileno)

{

    int compno;

    int tilex = tileno % s->numXtiles;

    int tiley = tileno / s->numXtiles;

    Jpeg2000Tile *tile = s->tile + tileno;



    if (!tile->comp)

        return AVERROR(ENOMEM);



    tile->coord[0][0] = FFMAX(tilex       * s->tile_width  + s->tile_offset_x, s->image_offset_x);

    tile->coord[0][1] = FFMIN((tilex + 1) * s->tile_width  + s->tile_offset_x, s->width);

    tile->coord[1][0] = FFMAX(tiley       * s->tile_height + s->tile_offset_y, s->image_offset_y);

    tile->coord[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height);



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

        Jpeg2000Component *comp = tile->comp + compno;

        Jpeg2000CodingStyle *codsty = tile->codsty + compno;

        Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;

        int ret; // global bandno



        comp->coord_o[0][0] = tile->coord[0][0];

        comp->coord_o[0][1] = tile->coord[0][1];

        comp->coord_o[1][0] = tile->coord[1][0];

        comp->coord_o[1][1] = tile->coord[1][1];

        if (compno) {

            comp->coord_o[0][0] /= s->cdx[compno];

            comp->coord_o[0][1] /= s->cdx[compno];

            comp->coord_o[1][0] /= s->cdy[compno];

            comp->coord_o[1][1] /= s->cdy[compno];

        }



        comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor);

        comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor);

        comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], s->reduction_factor);

        comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], s->reduction_factor);



        if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,

                                             s->cbps[compno], s->cdx[compno],

                                             s->cdy[compno], s->avctx))

            return ret;

    }

    return 0;

}

static int init_tile(Jpeg2000DecoderContext *s, int tileno)

{

    int compno;

    int tilex = tileno % s->numXtiles;

    int tiley = tileno / s->numXtiles;

    Jpeg2000Tile *tile = s->tile + tileno;



    if (!tile->comp)

        return AVERROR(ENOMEM);



    tile->coord[0][0] = FFMAX(tilex       * s->tile_width  + s->tile_offset_x, s->image_offset_x);

    tile->coord[0][1] = FFMIN((tilex + 1) * s->tile_width  + s->tile_offset_x, s->width);

    tile->coord[1][0] = FFMAX(tiley       * s->tile_height + s->tile_offset_y, s->image_offset_y);

    tile->coord[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height);



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

        Jpeg2000Component *comp = tile->comp + compno;

        Jpeg2000CodingStyle *codsty = tile->codsty + compno;

        Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;

        int ret; 



        comp->coord_o[0][0] = tile->coord[0][0];

        comp->coord_o[0][1] = tile->coord[0][1];

        comp->coord_o[1][0] = tile->coord[1][0];

        comp->coord_o[1][1] = tile->coord[1][1];

        if (compno) {

            comp->coord_o[0][0] /= s->cdx[compno];

            comp->coord_o[0][1] /= s->cdx[compno];

            comp->coord_o[1][0] /= s->cdy[compno];

            comp->coord_o[1][1] /= s->cdy[compno];

        }



        comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor);

        comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor);

        comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], s->reduction_factor);

        comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], s->reduction_factor);



        if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,

                                             s->cbps[compno], s->cdx[compno],

                                             s->cdy[compno], s->avctx))

            return ret;

    }

    return 0;

}

static int FUNC_0(Jpeg2000DecoderContext *VAR_0, int VAR_1)

{

    int VAR_2;

    int VAR_3 = VAR_1 % VAR_0->numXtiles;

    int VAR_4 = VAR_1 / VAR_0->numXtiles;

    Jpeg2000Tile *tile = VAR_0->tile + VAR_1;



    if (!tile->comp)

        return AVERROR(ENOMEM);



    tile->coord[0][0] = FFMAX(VAR_3       * VAR_0->tile_width  + VAR_0->tile_offset_x, VAR_0->image_offset_x);

    tile->coord[0][1] = FFMIN((VAR_3 + 1) * VAR_0->tile_width  + VAR_0->tile_offset_x, VAR_0->width);

    tile->coord[1][0] = FFMAX(VAR_4       * VAR_0->tile_height + VAR_0->tile_offset_y, VAR_0->image_offset_y);

    tile->coord[1][1] = FFMIN((VAR_4 + 1) * VAR_0->tile_height + VAR_0->tile_offset_y, VAR_0->height);



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

        Jpeg2000Component *comp = tile->comp + VAR_2;

        Jpeg2000CodingStyle *codsty = tile->codsty + VAR_2;

        Jpeg2000QuantStyle  *qntsty = tile->qntsty + VAR_2;

        int ret; 



        comp->coord_o[0][0] = tile->coord[0][0];

        comp->coord_o[0][1] = tile->coord[0][1];

        comp->coord_o[1][0] = tile->coord[1][0];

        comp->coord_o[1][1] = tile->coord[1][1];

        if (VAR_2) {

            comp->coord_o[0][0] /= VAR_0->cdx[VAR_2];

            comp->coord_o[0][1] /= VAR_0->cdx[VAR_2];

            comp->coord_o[1][0] /= VAR_0->cdy[VAR_2];

            comp->coord_o[1][1] /= VAR_0->cdy[VAR_2];

        }



        comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], VAR_0->reduction_factor);

        comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], VAR_0->reduction_factor);

        comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], VAR_0->reduction_factor);

        comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], VAR_0->reduction_factor);



        if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,

                                             VAR_0->cbps[VAR_2], VAR_0->cdx[VAR_2],

                                             VAR_0->cdy[VAR_2], VAR_0->avctx))

            return ret;

    }

    return 0;

}

static int FUNC_0(Jpeg2000DecoderContext *VAR_0, int VAR_1)
{ int VAR_2; int VAR_3 = VAR_1 % VAR_0->numXtiles; int VAR_4 = VAR_1 / VAR_0->numXtiles; Jpeg2000Tile *tile = VAR_0->tile + VAR_1; if (!tile->comp)
return AVERROR(ENOMEM); tile->coord[0][0] = FFMAX(VAR_3       * VAR_0->tile_width  + VAR_0->tile_offset_x, VAR_0->image_offset_x); tile->coord[0][1] = FFMIN((VAR_3 + 1) * VAR_0->tile_width  + VAR_0->tile_offset_x, VAR_0->width); tile->coord[1][0] = FFMAX(VAR_4       * VAR_0->tile_height + VAR_0->tile_offset_y, VAR_0->image_offset_y); tile->coord[1][1] = FFMIN((VAR_4 + 1) * VAR_0->tile_height + VAR_0->tile_offset_y, VAR_0->height); for (VAR_2 = 0; VAR_2 < VAR_0->ncomponents; VAR_2++) { Jpeg2000Component *comp = tile->comp + VAR_2; Jpeg2000CodingStyle *codsty = tile->codsty + VAR_2; Jpeg2000QuantStyle  *qntsty = tile->qntsty + VAR_2; int ret; comp->coord_o[0][0] = tile->coord[0][0]; comp->coord_o[0][1] = tile->coord[0][1]; comp->coord_o[1][0] = tile->coord[1][0]; comp->coord_o[1][1] = tile->coord[1][1]; if (VAR_2) { comp->coord_o[0][0] /= VAR_0->cdx[VAR_2]; comp->coord_o[0][1] /= VAR_0->cdx[VAR_2]; comp->coord_o[1][0] /= VAR_0->cdy[VAR_2]; comp->coord_o[1][1] /= VAR_0->cdy[VAR_2]; } comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], VAR_0->reduction_factor); comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], VAR_0->reduction_factor); comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], VAR_0->reduction_factor); comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], VAR_0->reduction_factor); if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,
VAR_0->cbps[VAR_2], VAR_0->cdx[VAR_2],
VAR_0->cdy[VAR_2], VAR_0->avctx))
return ret; } return 0; }