From 33e665a6abf1bfe45bc2d9484f1dd2dcdfb2324a Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 1 Jul 2013 10:01:25 +0200 Subject: [PATCH 1/3] jpeg2000: Update pixel format support Signed-off-by: Luca Barbato --- libavcodec/jpeg2000dec.c | 50 ++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 07ccbe5c8e..802180f65b 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -235,37 +235,35 @@ static int get_siz(Jpeg2000DecoderContext *s) s->avctx->height = ff_jpeg2000_ceildivpow2(s->height - s->image_offset_y, s->reduction_factor); - switch (s->avctx->profile) { - case FF_PROFILE_JPEG2000_DCINEMA_2K: - case FF_PROFILE_JPEG2000_DCINEMA_4K: - /* XYZ color-space for digital cinema profiles */ - s->avctx->pix_fmt = AV_PIX_FMT_XYZ12; + switch (s->ncomponents) { + case 1: + if (s->precision > 8) + s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; + else + s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; break; - default: - /* For other profiles selects color-space according number of - * components and bit depth precision. */ - switch (s->ncomponents) { - case 1: - if (s->precision > 8) - s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; - else - s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; + case 3: + switch (s->avctx->profile) { + case FF_PROFILE_JPEG2000_DCINEMA_2K: + case FF_PROFILE_JPEG2000_DCINEMA_4K: + /* XYZ color-space for digital cinema profiles */ + s->avctx->pix_fmt = AV_PIX_FMT_XYZ12; break; - case 3: + default: if (s->precision > 8) s->avctx->pix_fmt = AV_PIX_FMT_RGB48; else s->avctx->pix_fmt = AV_PIX_FMT_RGB24; break; - case 4: - s->avctx->pix_fmt = AV_PIX_FMT_BGRA; - break; - default: - /* pixel format can not be identified */ - s->avctx->pix_fmt = AV_PIX_FMT_NONE; - break; } break; + case 4: + s->avctx->pix_fmt = AV_PIX_FMT_RGBA; + break; + default: + /* pixel format can not be identified */ + s->avctx->pix_fmt = AV_PIX_FMT_NONE; + break; } return 0; } @@ -1135,11 +1133,6 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, if (tile->codsty[0].mct) mct_decode(s, tile); - if (s->avctx->pix_fmt == AV_PIX_FMT_BGRA) { // RGBA -> BGRA - FFSWAP(float *, tile->comp[0].f_data, tile->comp[2].f_data); - FFSWAP(int *, tile->comp[0].i_data, tile->comp[2].i_data); - } - if (s->precision <= 8) { for (compno = 0; compno < s->ncomponents; compno++) { Jpeg2000Component *comp = tile->comp + compno; @@ -1443,8 +1436,5 @@ AVCodec ff_jpeg2000_decoder = { .init_static_data = jpeg2000_init_static_data, .decode = jpeg2000_decode_frame, .priv_class = &class, - .pix_fmts = (enum AVPixelFormat[]) { AV_PIX_FMT_XYZ12, - AV_PIX_FMT_GRAY8, - -1 }, .profiles = NULL_IF_CONFIG_SMALL(profiles) }; From 5b73916d34527ce9a615f7934e02558ad1d77713 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 1 Jul 2013 10:01:26 +0200 Subject: [PATCH 2/3] jpeg2000: Simplify init_tile() Signed-off-by: Luca Barbato --- libavcodec/jpeg2000dec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 802180f65b..0fa8ccaa16 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -573,8 +573,6 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) int tilex = tileno % s->numXtiles; int tiley = tileno / s->numXtiles; Jpeg2000Tile *tile = s->tile + tileno; - Jpeg2000CodingStyle *codsty; - Jpeg2000QuantStyle *qntsty; if (!tile->comp) return AVERROR(ENOMEM); @@ -582,14 +580,14 @@ static int init_tile(Jpeg2000DecoderContext *s, int tileno) /* copy codsty, qnsty to tile. TODO: Is it the best way? * codsty, qnsty is an array of 4 structs Jpeg2000CodingStyle * and Jpeg2000QuantStyle */ - memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(*codsty)); - memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(*qntsty)); + memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(*tile->codsty)); + memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(*tile->qntsty)); 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 - codsty = tile->codsty + compno; - qntsty = tile->qntsty + compno; comp->coord_o[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x); comp->coord_o[0][1] = FFMIN((tilex + 1) * s->tile_width + s->tile_offset_x, s->width); From 589e5b52f634f6b2d307a167a19eef7e7328cb08 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 1 Jul 2013 10:01:27 +0200 Subject: [PATCH 3/3] jpeg2000: Use the correct sizeof in memset for T1 data Signed-off-by: Luca Barbato --- libavcodec/jpeg2000dec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 0fa8ccaa16..346a5c6867 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -940,12 +940,13 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y; for (y = 0; y < height; y++) - memset(t1->data[y], 0, width * sizeof(width)); + memset(t1->data[y], 0, width * sizeof(**t1->data)); + /* If code-block contains no compressed data: nothing to do. */ if (!cblk->length) return 0; for (y = 0; y < height + 2; y++) - memset(t1->flags[y], 0, (width + 2) * sizeof(width)); + memset(t1->flags[y], 0, (width + 2) * sizeof(**t1->flags)); ff_mqc_initdec(&t1->mqc, cblk->data); cblk->data[cblk->length] = 0xff;