[trunk] Import patch from issue 218. No dataset to check, so blindly applied it.
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Thu, 27 Feb 2014 17:21:00 +0000 (17:21 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Thu, 27 Feb 2014 17:21:00 +0000 (17:21 +0000)
Fixes issue 218

src/lib/openjp2/jp2.c

index 544ce91b916ff22d346c66bc75fee455df426ae8..d59ec43403f1f9dd46d81b7e13901b17361aa9b5 100644 (file)
@@ -823,6 +823,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
        return OPJ_TRUE;
 }
 
+// file9.jp2
 void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
 {
        opj_image_comp_t *old_comps, *new_comps;
@@ -1076,7 +1077,8 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
        for(i = 0; i < n; ++i)
        {
                /* WATCH: acn = asoc - 1 ! */
-               if((asoc = info[i].asoc) == 0)
+    asoc = info[i].asoc;
+               if(asoc == 0 || asoc == 65535)
                 {
                     if (i < image->numcomps)
                         image->comps[i].alpha = info[i].typ;
@@ -1085,6 +1087,11 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
 
                cn = info[i].cn; 
         acn = asoc - 1;
+        if( cn >= image->numcomps || acn >= image->numcomps )
+        {
+            fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps);
+            continue;
+        }
 
                if(cn != acn)
                {