assert(jp2 != 00);
assert(p_manager != 00);
+ if (jp2->comps != NULL) {
+ opj_event_msg(p_manager, EVT_WARNING, "Ignoring ihdr box. First ihdr box already read\n");
+ return OPJ_TRUE;
+ }
+
if (p_image_header_size != 14) {
opj_event_msg(p_manager, EVT_ERROR, "Bad image header box (bad size)\n");
return OPJ_FALSE;
p_image_header_data += 4;
opj_read_bytes(p_image_header_data,&(jp2->numcomps),2); /* NC */
p_image_header_data += 2;
+
+ if ((jp2->numcomps - 1U) >= 16384U) { /* unsigned underflow is well defined: 1U <= jp2->numcomps <= 16384U */
+ opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components (ihdr)\n");
+ return OPJ_FALSE;
+ }
/* allocate memory for components */
jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t));
{
OPJ_UINT32 i;
/* room for 8 bytes for box and 1 byte for each component */
- OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps;
+ OPJ_UINT32 l_bpcc_size;
OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr;
/* preconditions */
assert(jp2 != 00);
assert(p_nb_bytes_written != 00);
+ l_bpcc_size = 8 + jp2->numcomps;
l_bpcc_data = (OPJ_BYTE *) opj_calloc(1,l_bpcc_size);
if (l_bpcc_data == 00) {
OPJ_UINT32 rl, ol, ra, oa, rb, ob, il;
cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32));
+ if(cielab == NULL){
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory for cielab\n");
+ return OPJ_FALSE;
+ }
cielab[0] = 14; /* enumcs */
/* default values */
opj_event_mgr_t * p_manager )
{
OPJ_UINT32 i;
- OPJ_UINT32 l_ftyp_size = 16 + 4 * jp2->numcl;
+ OPJ_UINT32 l_ftyp_size;
OPJ_BYTE * l_ftyp_data, * l_current_data_ptr;
OPJ_BOOL l_result;
assert(cio != 00);
assert(jp2 != 00);
assert(p_manager != 00);
+ l_ftyp_size = 16 + 4 * jp2->numcl;
l_ftyp_data = (OPJ_BYTE *) opj_calloc(1,l_ftyp_size);
/* further JP2 initializations go here */
jp2->color.jp2_has_colr = 0;
- jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
+ jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
+}
+
+OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads)
+{
+ return opj_j2k_set_threads(jp2->j2k, num_threads);
}
/* ----------------------------------------------------------------------- */
jp2->numcl = 1;
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
if (!jp2->cl){
- jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return OPJ_FALSE;
}
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
if (!jp2->comps) {
- jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
/* Memory of jp2->cl will be freed by opj_jp2_destroy */
return OPJ_FALSE;