static int init_tiles(Jpeg2000EncoderContext *s)

{

    int tileno, tilex, tiley, compno;

    Jpeg2000CodingStyle *codsty = &s->codsty;

    Jpeg2000QuantStyle  *qntsty = &s->qntsty;



    s->numXtiles = ff_jpeg2000_ceildiv(s->width, s->tile_width);

    s->numYtiles = ff_jpeg2000_ceildiv(s->height, s->tile_height);



    s->tile = av_malloc_array(s->numXtiles, s->numYtiles * sizeof(Jpeg2000Tile));

    if (!s->tile)

        return AVERROR(ENOMEM);

    for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++)

        for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){

            Jpeg2000Tile *tile = s->tile + tileno;



            tile->comp = av_mallocz_array(s->ncomponents, sizeof(Jpeg2000Component));

            if (!tile->comp)

                return AVERROR(ENOMEM);

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

                Jpeg2000Component *comp = tile->comp + compno;

                int ret, i, j;



                comp->coord[0][0] = comp->coord_o[0][0] = tilex * s->tile_width;

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

                comp->coord[1][0] = comp->coord_o[1][0] = tiley * s->tile_height;

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

                if (compno > 0)

                    for (i = 0; i < 2; i++)

                        for (j = 0; j < 2; j++)

                            comp->coord[i][j] = comp->coord_o[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);



                if (ret = ff_jpeg2000_init_component(comp,

                                                codsty,

                                                qntsty,

                                                s->cbps[compno],

                                                compno?1<<s->chroma_shift[0]:1,

                                                compno?1<<s->chroma_shift[1]:1,

                                                s->avctx

                                               ))

                    return ret;

            }

        }

    return 0;

}

static int init_tiles(Jpeg2000EncoderContext *s)

{

    int tileno, tilex, tiley, compno;

    Jpeg2000CodingStyle *codsty = &s->codsty;

    Jpeg2000QuantStyle  *qntsty = &s->qntsty;



    s->numXtiles = ff_jpeg2000_ceildiv(s->width, s->tile_width);

    s->numYtiles = ff_jpeg2000_ceildiv(s->height, s->tile_height);



    s->tile = av_malloc_array(s->numXtiles, s->numYtiles * sizeof(Jpeg2000Tile));

    if (!s->tile)

        return AVERROR(ENOMEM);

    for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++)

        for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){

            Jpeg2000Tile *tile = s->tile + tileno;



            tile->comp = av_mallocz_array(s->ncomponents, sizeof(Jpeg2000Component));

            if (!tile->comp)

                return AVERROR(ENOMEM);

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

                Jpeg2000Component *comp = tile->comp + compno;

                int ret, i, j;



                comp->coord[0][0] = comp->coord_o[0][0] = tilex * s->tile_width;

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

                comp->coord[1][0] = comp->coord_o[1][0] = tiley * s->tile_height;

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

                if (compno > 0)

                    for (i = 0; i < 2; i++)

                        for (j = 0; j < 2; j++)

                            comp->coord[i][j] = comp->coord_o[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);



                if (ret = ff_jpeg2000_init_component(comp,

                                                codsty,

                                                qntsty,

                                                s->cbps[compno],

                                                compno?1<<s->chroma_shift[0]:1,

                                                compno?1<<s->chroma_shift[1]:1,

                                                s->avctx

                                               ))

                    return ret;

            }

        }

    return 0;

}

                if (ret = ff_jpeg2000_init_component(comp,                                                ))
static int FUNC_0(Jpeg2000EncoderContext *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4;

    Jpeg2000CodingStyle *codsty = &VAR_0->codsty;

    Jpeg2000QuantStyle  *qntsty = &VAR_0->qntsty;



    VAR_0->numXtiles = ff_jpeg2000_ceildiv(VAR_0->width, VAR_0->tile_width);

    VAR_0->numYtiles = ff_jpeg2000_ceildiv(VAR_0->height, VAR_0->tile_height);



    VAR_0->tile = av_malloc_array(VAR_0->numXtiles, VAR_0->numYtiles * sizeof(Jpeg2000Tile));

    if (!VAR_0->tile)

        return AVERROR(ENOMEM);

    for (VAR_1 = 0, VAR_3 = 0; VAR_3 < VAR_0->numYtiles; VAR_3++)

        for (VAR_2 = 0; VAR_2 < VAR_0->numXtiles; VAR_2++, VAR_1++){

            Jpeg2000Tile *tile = VAR_0->tile + VAR_1;



            tile->comp = av_mallocz_array(VAR_0->ncomponents, sizeof(Jpeg2000Component));

            if (!tile->comp)

                return AVERROR(ENOMEM);

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

                Jpeg2000Component *comp = tile->comp + VAR_4;

                int ret, i, j;



                comp->coord[0][0] = comp->coord_o[0][0] = VAR_2 * VAR_0->tile_width;

                comp->coord[0][1] = comp->coord_o[0][1] = FFMIN((VAR_2+1)*VAR_0->tile_width, VAR_0->width);

                comp->coord[1][0] = comp->coord_o[1][0] = VAR_3 * VAR_0->tile_height;

                comp->coord[1][1] = comp->coord_o[1][1] = FFMIN((VAR_3+1)*VAR_0->tile_height, VAR_0->height);

                if (VAR_4 > 0)

                    for (i = 0; i < 2; i++)

                        for (j = 0; j < 2; j++)

                            comp->coord[i][j] = comp->coord_o[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], VAR_0->chroma_shift[i]);



                if (ret = ff_jpeg2000_init_component(comp,

                                                codsty,

                                                qntsty,

                                                VAR_0->cbps[VAR_4],

                                                VAR_4?1<<VAR_0->chroma_shift[0]:1,

                                                VAR_4?1<<VAR_0->chroma_shift[1]:1,

                                                VAR_0->avctx

                                               ))

                    return ret;

            }

        }

    return 0;

}

static int FUNC_0(Jpeg2000EncoderContext *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4; Jpeg2000CodingStyle *codsty = &VAR_0->codsty; Jpeg2000QuantStyle  *qntsty = &VAR_0->qntsty; VAR_0->numXtiles = ff_jpeg2000_ceildiv(VAR_0->width, VAR_0->tile_width); VAR_0->numYtiles = ff_jpeg2000_ceildiv(VAR_0->height, VAR_0->tile_height); VAR_0->tile = av_malloc_array(VAR_0->numXtiles, VAR_0->numYtiles * sizeof(Jpeg2000Tile)); if (!VAR_0->tile)
return AVERROR(ENOMEM); for (VAR_1 = 0, VAR_3 = 0; VAR_3 < VAR_0->numYtiles; VAR_3++) for (VAR_2 = 0; VAR_2 < VAR_0->numXtiles; VAR_2++, VAR_1++){ Jpeg2000Tile *tile = VAR_0->tile + VAR_1; tile->comp = av_mallocz_array(VAR_0->ncomponents, sizeof(Jpeg2000Component)); if (!tile->comp)
return AVERROR(ENOMEM); for (VAR_4 = 0; VAR_4 < VAR_0->ncomponents; VAR_4++){ Jpeg2000Component *comp = tile->comp + VAR_4; int ret, i, j; comp->coord[0][0] = comp->coord_o[0][0] = VAR_2 * VAR_0->tile_width; comp->coord[0][1] = comp->coord_o[0][1] = FFMIN((VAR_2+1)*VAR_0->tile_width, VAR_0->width); comp->coord[1][0] = comp->coord_o[1][0] = VAR_3 * VAR_0->tile_height; comp->coord[1][1] = comp->coord_o[1][1] = FFMIN((VAR_3+1)*VAR_0->tile_height, VAR_0->height); if (VAR_4 > 0)
for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) comp->coord[i][j] = comp->coord_o[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], VAR_0->chroma_shift[i]); if (ret = ff_jpeg2000_init_component(comp,
codsty,
qntsty,
VAR_0->cbps[VAR_4],
VAR_4?1<<VAR_0->chroma_shift[0]:1,
VAR_4?1<<VAR_0->chroma_shift[1]:1,
VAR_0->avctx
))
return ret; } } return 0; }