[FFmpeg-devel] [PATCH V2] jpeg2000: use of lowres parameter from avcodec.h

Nicolas Bertrand nicoinattendu at gmail.com
Tue Apr 30 15:28:20 CEST 2013


An error message is set on case of inconsistent lowres parameter.
---
 libavcodec/jpeg2000dec.c |   31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 20e5c9c..ef7afdb 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -86,9 +86,6 @@ typedef struct Jpeg2000DecoderContext {
     int16_t         curtileno;
     Jpeg2000Tile    *tile;
 
-    /*options parameters*/
-    int16_t         lowres;
-    int16_t         reduction_factor;
 } Jpeg2000DecoderContext;
 
 /* get_bits functions for JPEG2000 packet bitstream
@@ -205,9 +202,9 @@ static int get_siz(Jpeg2000DecoderContext *s)
 
     /* compute image size with reduction factor */
     s->avctx->width  = ff_jpeg2000_ceildivpow2(s->width  - s->image_offset_x,
-                                               s->reduction_factor);
+                                               s->avctx->lowres);
     s->avctx->height = ff_jpeg2000_ceildivpow2(s->height - s->image_offset_y,
-                                               s->reduction_factor);
+                                               s->avctx->lowres);
 
     switch (s->avctx->profile) {
     case FF_PROFILE_JPEG2000_DCINEMA_2K:
@@ -251,13 +248,15 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
 
     if (s->buf_end - s->buf < 5)
         return AVERROR(EINVAL);
-    c->nreslevels = bytestream_get_byte(&s->buf) + 1; // num of resolution levels - 1
-
+    c->nreslevels = bytestream_get_byte(&s->buf) + 1; // num of resolution levels
     /* compute number of resolution levels to decode */
-    if (c->nreslevels < s->reduction_factor)
-        c->nreslevels2decode = 1;
-    else
-        c->nreslevels2decode = c->nreslevels - s->reduction_factor;
+    if (c->nreslevels <= s->avctx->lowres) {
+        av_log(s->avctx, AV_LOG_ERROR,
+            "Cannot set lowres to %d, maximum lowres for this file is %d.\n",
+             s->avctx->lowres, c->nreslevels - 1);
+        return EINVAL;
+    } else
+        c->nreslevels2decode = c->nreslevels - s->avctx->lowres;
 
     c->log2_cblk_width  = bytestream_get_byte(&s->buf) + 2; // cblk width
     c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height
@@ -1252,8 +1251,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
     s->buf_end   = s->buf_start + 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;
 
     ff_jpeg2000_init_tier1_luts();
 
@@ -1301,12 +1298,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
 #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
-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 },
-    { NULL },
-};
-
 static const AVProfile profiles[] = {
     { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0,  "JPEG 2000 codestream restriction 0"   },
     { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1,  "JPEG 2000 codestream restriction 1"   },
@@ -1319,7 +1310,6 @@ static const AVProfile profiles[] = {
 static const AVClass class = {
     .class_name = "jpeg2000",
     .item_name  = av_default_item_name,
-    .option     = options,
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
@@ -1330,6 +1320,7 @@ AVCodec ff_jpeg2000_decoder = {
     .id             = AV_CODEC_ID_JPEG2000,
     .capabilities   = CODEC_CAP_FRAME_THREADS,
     .priv_data_size = sizeof(Jpeg2000DecoderContext),
+    .max_lowres     = 31,
     .decode         = jpeg2000_decode_frame,
     .priv_class     = &class,
     .pix_fmts       = (enum PixelFormat[]) { AV_PIX_FMT_XYZ12,
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list