*
* @param p_tile_no the tile to output
* @param p_comp_no the component to output
- * @param p_stream the stream to write data to.
- * @param p_j2k J2K codec.
+ * @param nb_comps the number of components
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
* @param p_manager the user event manager.
*/
-static opj_bool opj_j2k_write_rgn( opj_j2k_t *p_j2k,
- OPJ_UINT32 p_tile_no,
- OPJ_UINT32 p_comp_no,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool opj_j2k_write_rgn( opj_j2k_t *p_j2k,
+ OPJ_UINT32 p_tile_no,
+ OPJ_UINT32 p_comp_no,
+ OPJ_UINT32 nb_comps,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Reads a RGN marker (Region Of Interest)
}
opj_bool opj_j2k_write_rgn(opj_j2k_t *p_j2k,
- OPJ_UINT32 p_tile_no,
- OPJ_UINT32 p_comp_no,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager
+ OPJ_UINT32 p_tile_no,
+ OPJ_UINT32 p_comp_no,
+ OPJ_UINT32 nb_comps,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager
)
{
OPJ_BYTE * l_current_data = 00;
- OPJ_UINT32 l_nb_comp;
OPJ_UINT32 l_rgn_size;
- opj_image_t *l_image = 00;
opj_cp_t *l_cp = 00;
opj_tcp_t *l_tcp = 00;
opj_tccp_t *l_tccp = 00;
l_tcp = &l_cp->tcps[p_tile_no];
l_tccp = &l_tcp->tccps[p_comp_no];
- l_nb_comp = l_image->numcomps;
-
- if (l_nb_comp <= 256) {
+ if (nb_comps <= 256) {
l_comp_room = 1;
}
else {
opj_write_bytes(l_current_data,l_rgn_size-2,2); /* Lrgn */
l_current_data += 2;
- opj_write_bytes(l_current_data,p_comp_no,l_comp_room); /* Crgn */
+ opj_write_bytes(l_current_data,p_comp_no,l_comp_room); /* Crgn */
l_current_data+=l_comp_room;
- opj_write_bytes(l_current_data, 0,1); /* Srgn */
+ opj_write_bytes(l_current_data, 0,1); /* Srgn */
++l_current_data;
- opj_write_bytes(l_current_data, l_tccp->roishift,1); /* SPrgn */
+ opj_write_bytes(l_current_data, l_tccp->roishift,1); /* SPrgn */
++l_current_data;
if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_header_tile_data,l_rgn_size,p_manager) != l_rgn_size) {
for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno) {
if (l_tccp->roishift) {
- if (! opj_j2k_write_rgn(p_j2k,0,compno,p_stream,p_manager)) {
+ if (! opj_j2k_write_rgn(p_j2k,0,compno,p_j2k->m_private_image->numcomps,p_stream,p_manager)) {
return OPJ_FALSE;
}
}
OPJ_UINT32 numcomps = p_j2k->m_private_image->numcomps;
opj_tcp_t *l_default_tile;
opj_codestream_info_v2_t* cstr_info = (opj_codestream_info_v2_t*) opj_calloc(1,sizeof(opj_codestream_info_v2_t));
+ if (!cstr_info)
+ return NULL;
cstr_info->nbcomps = p_j2k->m_private_image->numcomps;
cstr_info->m_default_tile_info.mct = l_default_tile->mct;
cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc(cstr_info->nbcomps, sizeof(opj_tccp_info_t));
+ if (!cstr_info->m_default_tile_info.tccp_info)
+ {
+ opj_destroy_cstr_info(&cstr_info);
+ return NULL;
+ }
for (compno = 0; compno < numcomps; compno++) {
opj_tccp_t *l_tccp = &(l_default_tile->tccps[compno]);
nr_channels = (OPJ_UINT16) l_value;
entries = (OPJ_UINT32*) opj_malloc(nr_channels * nr_entries * sizeof(OPJ_UINT32));
+ if (!entries)
+ return OPJ_FALSE;
channel_size = (OPJ_BYTE*) opj_malloc(nr_channels);
+ if (!channel_size)
+ {
+ opj_free(entries);
+ return OPJ_FALSE;
+ }
channel_sign = (OPJ_BYTE*) opj_malloc(nr_channels);
+ if (!channel_sign)
+ {
+ opj_free(entries);
+ opj_free(channel_size);
+ return OPJ_FALSE;
+ }
jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t));
+ if (!jp2_pclr)
+ {
+ opj_free(entries);
+ opj_free(channel_size);
+ opj_free(channel_sign);
+ return OPJ_FALSE;
+ }
+
jp2_pclr->channel_sign = channel_sign;
jp2_pclr->channel_size = channel_size;
jp2_pclr->entries = entries;
assert(jp2 != 00);
assert(p_cmap_header_data != 00);
assert(p_manager != 00);
- (void)p_cmap_header_size;
+ (void)p_cmap_header_size;
/* Need nr_channels: */
if(jp2->color.jp2_pclr == NULL) {
nr_channels = jp2->color.jp2_pclr->nr_channels;
cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t));
+ if (!cmap)
+ return OPJ_FALSE;
+
for(i = 0; i < nr_channels; ++i) {
opj_read_bytes(p_cmap_header_data, &l_value, 2); /* CMP^i */
}
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_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;
jp2->color.icc_profile_len = icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc(icc_len);
-
+ if (!jp2->color.icc_profile_buf)
+ {
+ jp2->color.icc_profile_len = 0;
+ return OPJ_FALSE;
+ }
memset(jp2->color.icc_profile_buf, 0, icc_len * sizeof(OPJ_BYTE));
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
jp2->minversion = 0; /* MinV */
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;
+ }
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
/* Image Header box */
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");
+ return;
+ }
+
jp2->h = image->y1 - image->y0; /* HEIGHT */
jp2->w = image->x1 - image->x0; /* WIDTH */
/* BPC */