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 > 65534) continue;
+ if (info[i].asoc == 65535U) continue;
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);
old_comps = image->comps;
new_comps = (opj_image_comp_t*)
- opj_calloc(nr_channels, sizeof(opj_image_comp_t));
+ opj_malloc(nr_channels * sizeof(opj_image_comp_t));
if (!new_comps) {
/* FIXME no error code for opj_jp2_apply_pclr */
/* FIXME event manager error callback */
return OPJ_FALSE;
}
- cdef_info = (opj_jp2_cdef_info_t*) opj_calloc(1, l_value * sizeof(opj_jp2_cdef_info_t));
- if (!cdef_info)
- return OPJ_FALSE;
+ cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_cdef_info_t));
+ if (!cdef_info)
+ return OPJ_FALSE;
- jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_calloc(1, sizeof(opj_jp2_cdef_t));
- if(!jp2->color.jp2_cdef)
- {
- opj_free(cdef_info);
- return OPJ_FALSE;
- }
+ jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
+ if(!jp2->color.jp2_cdef)
+ {
+ opj_free(cdef_info);
+ return OPJ_FALSE;
+ }
jp2->color.jp2_cdef->info = cdef_info;
jp2->color.jp2_cdef->n = (OPJ_UINT16) l_value;
opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box (bad size: %d)\n", p_colr_header_size);
return OPJ_FALSE;
}
- if (p_colr_header_size > 7) {
+ if ((p_colr_header_size > 7) && (jp2->enumcs != 14)) { /* handled below for CIELab) */
/* testcase Altona_Technical_v20_x4.pdf */
opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (bad size: %d)\n", p_colr_header_size);
}
opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */
- p_colr_header_data += 4;
-
- if(jp2->enumcs == 14)/* CIELab */
- {
- OPJ_UINT32 *cielab;
- OPJ_UINT32 rl, ol, ra, oa, rb, ob, il;
-
- cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32));
- cielab[0] = 14; /* enumcs */
-
- if(p_colr_header_size == 7)/* default values */
- {
- rl = ra = rb = ol = oa = ob = 0;
- il = 0x00443530; /* D50 */
- cielab[1] = 0x44454600;/* DEF */
- }
- else
- if(p_colr_header_size == 35)
- {
- opj_read_bytes(p_colr_header_data, &rl, 4);
- p_colr_header_data += 4;
- opj_read_bytes(p_colr_header_data, &ol, 4);
- p_colr_header_data += 4;
- opj_read_bytes(p_colr_header_data, &ra, 4);
- p_colr_header_data += 4;
- opj_read_bytes(p_colr_header_data, &oa, 4);
- p_colr_header_data += 4;
- opj_read_bytes(p_colr_header_data, &rb, 4);
- p_colr_header_data += 4;
- opj_read_bytes(p_colr_header_data, &ob, 4);
- p_colr_header_data += 4;
- opj_read_bytes(p_colr_header_data, &il, 4);
- p_colr_header_data += 4;
-
- cielab[1] = 0;
- }
- cielab[2] = rl; cielab[4] = ra; cielab[6] = rb;
- cielab[3] = ol; cielab[5] = oa; cielab[7] = ob;
- cielab[8] = il;
-
- jp2->color.icc_profile_buf = (unsigned char*)cielab;
- jp2->color.icc_profile_len = 0;
- }
+ p_colr_header_data += 4;
+
+ if(jp2->enumcs == 14)/* CIELab */
+ {
+ OPJ_UINT32 *cielab;
+ OPJ_UINT32 rl, ol, ra, oa, rb, ob, il;
- jp2->color.jp2_has_colr = 1;
+ cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32));
+ cielab[0] = 14; /* enumcs */
+
+ /* default values */
+ rl = ra = rb = ol = oa = ob = 0;
+ il = 0x00443530; /* D50 */
+ cielab[1] = 0x44454600;/* DEF */
+
+ if(p_colr_header_size == 35)
+ {
+ opj_read_bytes(p_colr_header_data, &rl, 4);
+ p_colr_header_data += 4;
+ opj_read_bytes(p_colr_header_data, &ol, 4);
+ p_colr_header_data += 4;
+ opj_read_bytes(p_colr_header_data, &ra, 4);
+ p_colr_header_data += 4;
+ opj_read_bytes(p_colr_header_data, &oa, 4);
+ p_colr_header_data += 4;
+ opj_read_bytes(p_colr_header_data, &rb, 4);
+ p_colr_header_data += 4;
+ opj_read_bytes(p_colr_header_data, &ob, 4);
+ p_colr_header_data += 4;
+ opj_read_bytes(p_colr_header_data, &il, 4);
+ p_colr_header_data += 4;
+
+ cielab[1] = 0;
+ }
+ else if(p_colr_header_size != 7)
+ {
+ opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (CIELab, bad size: %d)\n", p_colr_header_size);
+ }
+ cielab[2] = rl; cielab[4] = ra; cielab[6] = rb;
+ cielab[3] = ol; cielab[5] = oa; cielab[7] = ob;
+ cielab[8] = il;
+
+ jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab;
+ jp2->color.icc_profile_len = 0;
+ }
+ jp2->color.jp2_has_colr = 1;
}
else if (jp2->meth == 2) {
/* ICC profile */
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)icc_len);
- if (!jp2->color.icc_profile_buf)
- {
- jp2->color.icc_profile_len = 0;
- return OPJ_FALSE;
- }
+ if (!jp2->color.icc_profile_buf)
+ {
+ jp2->color.icc_profile_len = 0;
+ return OPJ_FALSE;
+ }
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
{
jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
}
- jp2->color.jp2_has_colr = 1;
+ jp2->color.jp2_has_colr = 1;
}
else if (jp2->meth > 2)
- {
- /* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values:
- conforming JP2 reader shall ignore the entire Colour Specification box.*/
- opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
- "so we will ignore the entire Colour Specification box. \n", jp2->meth);
- }
- return OPJ_TRUE;
+ {
+ /* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values:
+ conforming JP2 reader shall ignore the entire Colour Specification box.*/
+ opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
+ "so we will ignore the entire Colour Specification box. \n", jp2->meth);
+ }
+ return OPJ_TRUE;
}
OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
return OPJ_FALSE;
}
- if (!jp2->ignore_pclr_cmap_cdef){
- if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) {
- return OPJ_FALSE;
- }
+ if (!jp2->ignore_pclr_cmap_cdef){
+ if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) {
+ return OPJ_FALSE;
+ }
- /* Set Image Color Space */
- if (jp2->enumcs == 16)
- p_image->color_space = OPJ_CLRSPC_SRGB;
- else if (jp2->enumcs == 17)
- p_image->color_space = OPJ_CLRSPC_GRAY;
- else if (jp2->enumcs == 18)
- p_image->color_space = OPJ_CLRSPC_SYCC;
- else if (jp2->enumcs == 24)
- p_image->color_space = OPJ_CLRSPC_EYCC;
- else
- if (jp2->enumcs == 12)
+ /* Set Image Color Space */
+ if (jp2->enumcs == 16)
+ p_image->color_space = OPJ_CLRSPC_SRGB;
+ else if (jp2->enumcs == 17)
+ p_image->color_space = OPJ_CLRSPC_GRAY;
+ else if (jp2->enumcs == 18)
+ p_image->color_space = OPJ_CLRSPC_SYCC;
+ else if (jp2->enumcs == 24)
+ p_image->color_space = OPJ_CLRSPC_EYCC;
+ else if (jp2->enumcs == 12)
p_image->color_space = OPJ_CLRSPC_CMYK;
- else
- p_image->color_space = OPJ_CLRSPC_UNKNOWN;
-
- if(jp2->color.jp2_pclr) {
- /* Part 1, I.5.3.4: Either both or none : */
- if( !jp2->color.jp2_pclr->cmap)
- opj_jp2_free_pclr(&(jp2->color));
- else
- 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), p_manager);
- }
-
- 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;
- jp2->color.icc_profile_buf = NULL;
- }
- }
+ else
+ p_image->color_space = OPJ_CLRSPC_UNKNOWN;
+
+ if(jp2->color.jp2_pclr) {
+ /* Part 1, I.5.3.4: Either both or none : */
+ if( !jp2->color.jp2_pclr->cmap)
+ opj_jp2_free_pclr(&(jp2->color));
+ else
+ 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), p_manager);
+ }
+
+ 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;
+ jp2->color.icc_profile_buf = NULL;
+ }
+ }
return OPJ_TRUE;
}
opj_event_msg(p_manager, EVT_WARNING, "Multiple alpha channels specified. No cdef box will be created.\n");
}
if (alpha_count == 1U) { /* if here, we know what we can do */
- jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_calloc(1, sizeof(opj_jp2_cdef_t));
+ jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
if(!jp2->color.jp2_cdef) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to setup the JP2 encoder\n");
return OPJ_FALSE;
}
/* no memset needed, all values will be overwritten except if jp2->color.jp2_cdef->info allocation fails, */
/* in which case jp2->color.jp2_cdef->info will be NULL => valid for destruction */
- jp2->color.jp2_cdef->info = (opj_jp2_cdef_info_t*) opj_calloc(1, image->numcomps * sizeof(opj_jp2_cdef_info_t));
+ jp2->color.jp2_cdef->info = (opj_jp2_cdef_info_t*) opj_malloc(image->numcomps * sizeof(opj_jp2_cdef_info_t));
if (!jp2->color.jp2_cdef->info) {
/* memory will be freed by opj_jp2_destroy */
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to setup the JP2 encoder\n");
p_image->color_space = OPJ_CLRSPC_GRAY;
else if (p_jp2->enumcs == 18)
p_image->color_space = OPJ_CLRSPC_SYCC;
- else
- if (p_jp2->enumcs == 24)
+ else if (p_jp2->enumcs == 24)
p_image->color_space = OPJ_CLRSPC_EYCC;
- else
- if (p_jp2->enumcs == 12)
+ else if (p_jp2->enumcs == 12)
p_image->color_space = OPJ_CLRSPC_CMYK;
else
p_image->color_space = OPJ_CLRSPC_UNKNOWN;