[trunk] fixed a bug preventing palette image with cdef to decode properly (fixes...
authorAntonin Descampe <antonin@gmail.com>
Thu, 30 Oct 2014 18:26:10 +0000 (18:26 +0000)
committerAntonin Descampe <antonin@gmail.com>
Thu, 30 Oct 2014 18:26:10 +0000 (18:26 +0000)
src/lib/openjp2/jp2.c

index 7d15e36851bc548ae1e8461b255592f1ab811a30..bce8813ced4611ded050ba3ee5e457ae7f83a272 100644 (file)
@@ -772,12 +772,12 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
                }
 
                for (i = 0; i < n; i++) {
-                       if (info[i].cn >= image->numcomps) {
-                               opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, image->numcomps);
+                       if (info[i].cn >= nr_channels) {
+                               opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, nr_channels);
                                return OPJ_FALSE;
                        }
-                       if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= image->numcomps) {
-                               opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, image->numcomps);
+                       if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= nr_channels) {
+                               opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, nr_channels);
                                return OPJ_FALSE;
                        }
                }
@@ -1357,11 +1357,6 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
            else
                    p_image->color_space = OPJ_CLRSPC_UNKNOWN;
 
-           /* Apply the color space if needed */
-           if(jp2->color.jp2_cdef) {
-                   opj_jp2_apply_cdef(p_image, &(jp2->color));
-           }
-
            if(jp2->color.jp2_pclr) {
                    /* Part 1, I.5.3.4: Either both or none : */
                    if( !jp2->color.jp2_pclr->cmap)
@@ -1370,6 +1365,11 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
                            opj_jp2_apply_pclr(p_image, &(jp2->color));
            }
 
+           /* Apply the color space if needed */
+           if(jp2->color.jp2_cdef) {
+                   opj_jp2_apply_cdef(p_image, &(jp2->color));
+           }
+
            if(jp2->color.icc_profile_buf) {
                    p_image->icc_profile_buf = jp2->color.icc_profile_buf;
                    p_image->icc_profile_len = jp2->color.icc_profile_len;