Commit f9581f14 authored by Michael Niedermayer's avatar Michael Niedermayer Committed by Luca Barbato

jpeg2000: Improve reduced resolution decoding

Correctly scale down the component coordinates and
clean up some redundant code.
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent 952f7ed3
......@@ -84,8 +84,7 @@ typedef struct Jpeg2000DecoderContext {
Jpeg2000Tile *tile;
/*options parameters*/
int16_t lowres;
int16_t reduction_factor;
int reduction_factor;
} Jpeg2000DecoderContext;
/* get_bits functions for JPEG2000 packet bitstream
......@@ -599,12 +598,10 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno)
comp->coord_o[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y);
comp->coord_o[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height);
// FIXME: add a dcinema profile check ?
// value is guaranteed by profile (orig=0, 1 tile)
comp->coord[0][0] = 0;
comp->coord[0][1] = s->avctx->width;
comp->coord[1][0] = 0;
comp->coord[1][1] = s->avctx->height;
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],
......@@ -1351,9 +1348,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
bytestream2_init(&s->g, avpkt->data, avpkt->size);
s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for more tiles
// reduction factor, i.e number of resolution levels to skip
s->reduction_factor = s->lowres;
if (bytestream2_get_bytes_left(&s->g) < 2)
return AVERROR_INVALIDDATA;
......@@ -1413,7 +1407,7 @@ static void jpeg2000_init_static_data(AVCodec *codec)
static const AVOption options[] = {
{ "lowres", "Lower the decoding resolution by a power of two",
OFFSET(lowres), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, JPEG2000_MAX_RESLEVELS - 1, VD },
OFFSET(reduction_factor), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, JPEG2000_MAX_RESLEVELS - 1, VD },
{ NULL },
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment