jpeg2000: Improve reduced resolution decoding

Correctly scale down the component coordinates and
clean up some redundant code.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
pull/26/merge
Michael Niedermayer 12 years ago committed by Luca Barbato
parent 952f7ed3c0
commit f9581f1414
  1. 18
      libavcodec/jpeg2000dec.c

@ -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 },
};

Loading…
Cancel
Save