From: Francesco Cuzzocrea <france...@bltitalia.com>

---
 libavcodec/j2kenc.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 1bd4fbd..20dda87 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -1121,8 +1121,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
     memset(codsty->log2_prec_heights, 15, sizeof(codsty->log2_prec_heights));
     codsty->nreslevels2decode=
     codsty->nreslevels       = 7;
-    codsty->log2_cblk_width  = 4;
-    codsty->log2_cblk_height = 4;
     codsty->transform        = s->pred ? FF_DWT53 : FF_DWT97_INT;
 
     qntsty->nguardbits       = 1;
@@ -1131,6 +1129,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
         (s->tile_height & (s->tile_height-1))) {
         av_log(avctx, AV_LOG_WARNING, "Tile dimension not a power of 2\n");
     }
+    i = codsty->log2_cblk_width + codsty->log2_cblk_height -4;
+    if ( i > 12 )
+    {
+      av_log(avctx, AV_LOG_ERROR, "Invalid values for codeblocks size\n");
+      return -1;
+    }
+
 
     if (codsty->transform == FF_DWT53)
         qntsty->quantsty = JPEG2000_QSTY_NONE;
@@ -1178,21 +1183,20 @@ static int j2kenc_destroy(AVCodecContext *avctx)
 // taken from the libopenjpeg wraper so it matches
 
 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
-#define OFFSET1(x) offsetof(Jpeg2000CodingStyle, x)
 
 
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    { "format",           "Codec Format",       OFFSET(format),                
               AV_OPT_TYPE_INT,   { .i64 = CODEC_JP2   }, CODEC_J2K, CODEC_JP2, 
  VE, "format"      },
-    { "j2k",               NULL,                0,                             
               AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0,         0,         
  VE, "format"      },
-    { "jp2",               NULL,                0,                             
               AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0,         0,         
  VE, "format"      },
-    { "tile_width",        "Tile Width",        OFFSET(tile_width),            
               AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,         
  VE, },
-    { "tile_height",       "Tile Height",       OFFSET(tile_height),           
               AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,         
  VE, },
-    { "pred",              "DWT Type",          OFFSET(pred),                  
               AV_OPT_TYPE_INT,   { .i64 = 0           }, 0,         1,         
  VE, "pred"        },
-    { "dwt97int",          NULL,                0,                             
               AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,     
  VE, "pred"        },
-    { "dwt53",             NULL,                0,                             
               AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,     
  VE, "pred"        },
-    { "log2_cblk_width",   "Codeblock Width",   
(OFFSET(codsty)+OFFSET1(log2_cblk_width)),    AV_OPT_TYPE_INT,   { .i64 = 4     
      }, 1,     1<<30,           VE, },
-    { "log2_cblk_height",  "Codeblock Height",  
(OFFSET(codsty)+OFFSET1(log2_cblk_height)),   AV_OPT_TYPE_INT,   { .i64 = 4     
      }, 1,     1<<30,           VE, },
+    { "format",           "Codec Format",       OFFSET(format),                
    AV_OPT_TYPE_INT,   { .i64 = CODEC_JP2   }, CODEC_J2K, CODEC_JP2,   VE, 
"format"      },
+    { "j2k",               NULL,                0,                             
    AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K   }, 0,         0,           VE, 
"format"      },
+    { "jp2",               NULL,                0,                             
    AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2   }, 0,         0,           VE, 
"format"      },
+    { "tile_width",        "Tile Width",        OFFSET(tile_width),            
    AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,           VE, },
+    { "tile_height",       "Tile Height",       OFFSET(tile_height),           
    AV_OPT_TYPE_INT,   { .i64 = 256         }, 1,     1<<30,           VE, },
+    { "pred",              "DWT Type",          OFFSET(pred),                  
    AV_OPT_TYPE_INT,   { .i64 = 0           }, 0,         1,           VE, 
"pred"        },
+    { "dwt97int",          NULL,                0,                             
    AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,       VE, 
"pred"        },
+    { "dwt53",             NULL,                0,                             
    AV_OPT_TYPE_CONST, { .i64 = 0           }, INT_MIN, INT_MAX,       VE, 
"pred"        },
+    { "log2_cblk_width",   "Codeblock Width",   
OFFSET(codsty.log2_cblk_width),    AV_OPT_TYPE_INT,   { .i64 = 4           }, 
0,     1<<10,           VE, },
+    { "log2_cblk_height",  "Codeblock Height",  
OFFSET(codsty.log2_cblk_height),   AV_OPT_TYPE_INT,   { .i64 = 4           }, 
0,     1<<10,           VE, },
     { NULL }
 };
 
-- 
2.1.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to