]> granicus.if.org Git - openjpeg/commitdiff
[trunk] merge rev 1330/1331 from branch 1.5 onto trunk
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Fri, 2 Mar 2012 14:24:39 +0000 (14:24 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Fri, 2 Mar 2012 14:24:39 +0000 (14:24 +0000)
libopenjpeg/jp2.c

index f60e9e49b41dd3aa0559cd3c59c8faaf6005c45d..8aeda3733283975d88a0149e293941d457d76894 100644 (file)
@@ -191,7 +191,7 @@ Apply collected palette data
 @param color Collector for profile, cdef and pclr data
 @param image 
 */
-static void jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color);
+static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image, opj_common_ptr cinfo);
 /**
 Collect palette data
 @param jp2 JP2 handle
@@ -761,8 +761,7 @@ static void free_color_data(opj_jp2_color_t *color)
        if(color->icc_profile_buf) opj_free(color->icc_profile_buf);
 }
 
-
-static void jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
+static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image, opj_common_ptr cinfo)
 {
        opj_image_comp_t *old_comps, *new_comps;
        OPJ_BYTE *channel_size, *channel_sign;
@@ -786,7 +785,13 @@ static void jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
        for(i = 0; i < nr_channels; ++i) {
                pcol = cmap[i].pcol; cmp = cmap[i].cmp;
 
-               new_comps[pcol] = old_comps[cmp];
+  if( pcol < nr_channels )
+    new_comps[pcol] = old_comps[cmp];
+  else
+    {
+    opj_event_msg(cinfo, EVT_ERROR, "Error with pcol value %d (max: %d). skipping\n", pcol, nr_channels);
+    continue;
+    }
 
                /* Direct use */
                if(cmap[i].mtyp == 0){
@@ -1471,7 +1476,7 @@ opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
        if( !color.jp2_pclr->cmap) 
         jp2_free_pclr(&color);
        else
-        jp2_apply_pclr(image, &color);
+        jp2_apply_pclr(&color, image, cinfo);
    }
        if(color.icc_profile_buf)
    {