From 3b7dced8e66418ab90c1f7398fc36453e834f4dc Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 30 Oct 2014 18:26:10 +0000 Subject: [PATCH] [trunk] fixed a bug preventing palette image with cdef to decode properly (fixes issue 412) --- src/lib/openjp2/jp2.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 7d15e368..bce8813c 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -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; -- 2.50.1