}
w = raw_cp->rawWidth;
h = raw_cp->rawHeight;
- cmptparm = (opj_image_cmptparm_t*) malloc((size_t)numcomps * sizeof(opj_image_cmptparm_t));
-
+ cmptparm = (opj_image_cmptparm_t*) calloc(numcomps,sizeof(opj_image_cmptparm_t));
+ if (!cmptparm) {
+ fprintf(stderr, "Failed to allocate image components parameters !!\n");
+ fprintf(stderr,"Aborting\n");
+ return NULL;
+ }
/* initialize image components */
- memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++) {
cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth;
cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth;
if( bSuccess && bUseTiles ) {
OPJ_BYTE *l_data;
OPJ_UINT32 l_data_size = 512*512*3;
- l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE));
- memset(l_data, 0, l_data_size );
+ l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
assert( l_data );
for (i=0;i<l_nb_tiles;++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input)
{
opj_stream_private_t * l_stream = 00;
- l_stream = (opj_stream_private_t*) opj_malloc(sizeof(opj_stream_private_t));
+ l_stream = (opj_stream_private_t*) opj_calloc(1,sizeof(opj_stream_private_t));
if (! l_stream) {
return 00;
}
- memset(l_stream,0,sizeof(opj_stream_private_t));
l_stream->m_buffer_size = p_buffer_size;
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
if (! l_stream->m_stored_data) {
opj_procedure_list_t * opj_procedure_list_create()
{
/* memory allocation */
- opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_malloc(sizeof(opj_procedure_list_t));
+ opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation)
{
return 00;
}
/* initialization */
- memset(l_validation,0,sizeof(opj_procedure_list_t));
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
- l_validation->m_procedures = (opj_procedure*)opj_malloc(
- OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
+ l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures)
{
opj_free(l_validation);
return 00;
}
- memset(l_validation->m_procedures,0,OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
return l_validation;
}
OPJ_UINT32 compno;
opj_image_t *image = 00;
- image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
+ image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image)
{
- memset(image,0,sizeof(opj_image_t));
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
- image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
+ image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
- memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_event_msg(p_manager , EVT_ERROR, "Not enough memory for checking the poc values.\n");
return OPJ_FALSE;
}
- memset(packet_array,0,step_l * p_num_layers* sizeof(OPJ_UINT32));
if (p_nb_pocs == 0) {
opj_free(packet_array);
return OPJ_FALSE;
}
- memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_t));
l_img_comp = l_image->comps;
/* Read the component information */
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
- memset(l_cp->tcps,0,l_nb_tiles*sizeof(opj_tcp_t));
#ifdef USE_JPWL
if (l_cp->correct) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
- memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->tccps ,0,l_image->numcomps*sizeof(opj_tccp_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records =
- (opj_mct_data_t*)opj_malloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS * sizeof(opj_mct_data_t));
+ (opj_mct_data_t*)opj_calloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS ,sizeof(opj_mct_data_t));
if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
- memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records,0,OPJ_J2K_MCT_DEFAULT_NB_RECORDS * sizeof(opj_mct_data_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_nb_max_mct_records = OPJ_J2K_MCT_DEFAULT_NB_RECORDS;
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records =
(opj_simple_mcc_decorrelation_data_t*)
- opj_malloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS * sizeof(opj_simple_mcc_decorrelation_data_t));
+ opj_calloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS, sizeof(opj_simple_mcc_decorrelation_data_t));
if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
- memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records,0,OPJ_J2K_MCC_DEFAULT_NB_RECORDS * sizeof(opj_simple_mcc_decorrelation_data_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_nb_max_mcc_records = OPJ_J2K_MCC_DEFAULT_NB_RECORDS;
/* set up default dc level shift */
l_current_tile_param = l_cp->tcps;
for (i = 0; i < l_nb_tiles; ++i) {
- l_current_tile_param->tccps = (opj_tccp_t*) opj_malloc(l_image->numcomps * sizeof(opj_tccp_t));
+ l_current_tile_param->tccps = (opj_tccp_t*) opj_calloc(l_image->numcomps, sizeof(opj_tccp_t));
if (l_current_tile_param->tccps == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
- memset(l_current_tile_param->tccps,0,l_image->numcomps * sizeof(opj_tccp_t));
++l_current_tile_param;
}
l_cp->ppm_len = l_N_ppm;
l_cp->ppm_data_read = 0;
- l_cp->ppm_data = (OPJ_BYTE *) opj_malloc(l_cp->ppm_len);
+ l_cp->ppm_data = (OPJ_BYTE *) opj_calloc(1,l_cp->ppm_len);
l_cp->ppm_buffer = l_cp->ppm_data;
if (l_cp->ppm_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
return OPJ_FALSE;
}
- memset(l_cp->ppm_data,0,l_cp->ppm_len);
l_cp->ppm_data_current = l_cp->ppm_data;
opj_j2k_t* opj_j2k_create_compress(void)
{
- opj_j2k_t *l_j2k = (opj_j2k_t*) opj_malloc(sizeof(opj_j2k_t));
+ opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
if (!l_j2k) {
return NULL;
}
- memset(l_j2k,0,sizeof(opj_j2k_t));
l_j2k->m_is_decoder = 0;
l_j2k->m_cp.m_is_decoder = 0;
opj_j2k_t* opj_j2k_create_decompress(void)
{
- opj_j2k_t *l_j2k = (opj_j2k_t*) opj_malloc(sizeof(opj_j2k_t));
+ opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
if (!l_j2k) {
return 00;
}
- memset(l_j2k,0,sizeof(opj_j2k_t));
l_j2k->m_is_decoder = 1;
l_j2k->m_cp.m_is_decoder = 1;
- l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_malloc(sizeof(opj_tcp_t));
+ l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_calloc(1,sizeof(opj_tcp_t));
if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) {
opj_j2k_destroy(l_j2k);
return 00;
}
- memset(l_j2k->m_specific_param.m_decoder.m_default_tcp,0,sizeof(opj_tcp_t));
- l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_malloc(OPJ_J2K_DEFAULT_HEADER_SIZE);
+ l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_calloc(1,OPJ_J2K_DEFAULT_HEADER_SIZE);
if (! l_j2k->m_specific_param.m_decoder.m_header_data) {
opj_j2k_destroy(l_j2k);
return 00;
p_image_header_data += 2;
/* allocate memory for components */
- jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
+ jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t));
if (jp2->comps == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
return OPJ_FALSE;
}
- memset(jp2->comps,0,jp2->numcomps * sizeof(opj_jp2_comps_t));
opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */
++ p_image_header_data;
assert(p_nb_bytes_written != 00);
/* default image header is 22 bytes wide */
- l_ihdr_data = (OPJ_BYTE *) opj_malloc(22);
+ l_ihdr_data = (OPJ_BYTE *) opj_calloc(1,22);
if (l_ihdr_data == 00) {
return 00;
}
- memset(l_ihdr_data,0,22);
l_current_ihdr_ptr = l_ihdr_data;
assert(jp2 != 00);
assert(p_nb_bytes_written != 00);
- l_bpcc_data = (OPJ_BYTE *) opj_malloc(l_bpcc_size);
+ l_bpcc_data = (OPJ_BYTE *) opj_calloc(1,l_bpcc_size);
if (l_bpcc_data == 00) {
return 00;
}
- memset(l_bpcc_data,0,l_bpcc_size);
l_current_bpcc_ptr = l_bpcc_data;
return 00;
}
- l_colr_data = (OPJ_BYTE *) opj_malloc(l_colr_size);
+ l_colr_data = (OPJ_BYTE *) opj_calloc(1,l_colr_size);
if (l_colr_data == 00) {
return 00;
}
- memset(l_colr_data,0,l_colr_size);
l_current_colr_ptr = l_colr_data;
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
- jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc((size_t)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;
}
- memset(jp2->color.icc_profile_buf, 0, (size_t)icc_len * sizeof(OPJ_BYTE));
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
{
assert(jp2 != 00);
assert(p_manager != 00);
- l_ftyp_data = (OPJ_BYTE *) opj_malloc(l_ftyp_size);
+ l_ftyp_data = (OPJ_BYTE *) opj_calloc(1,l_ftyp_size);
if (l_ftyp_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
return OPJ_FALSE;
}
- memset(l_ftyp_data,0,l_ftyp_size);
-
l_current_data_ptr = l_ftyp_data;
opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
assert(jp2 != 00);
assert(p_manager != 00);
- l_current_data = (OPJ_BYTE*)opj_malloc(l_last_data_size);
+ l_current_data = (OPJ_BYTE*)opj_calloc(1,l_last_data_size);
if (l_current_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 file header\n");
return OPJ_FALSE;
}
- memset(l_current_data, 0 , l_last_data_size);
while (opj_jp2_read_boxhdr(&box,&l_nb_bytes_read,stream,p_manager)) {
/* is it the codestream box ? */
/* div by 4 */
jp2->numcl = l_remaining_bytes >> 2;
if (jp2->numcl) {
- jp2->cl = (OPJ_UINT32 *) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
+ jp2->cl = (OPJ_UINT32 *) opj_calloc(jp2->numcl, sizeof(OPJ_UINT32));
if (jp2->cl == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory with FTYP Box\n");
return OPJ_FALSE;
}
- memset(jp2->cl,0,jp2->numcl * sizeof(OPJ_UINT32));
}
for (i = 0; i < jp2->numcl; ++i)
opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder)
{
- opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
+ opj_jp2_t *jp2 = (opj_jp2_t*)opj_calloc(1,sizeof(opj_jp2_t));
if (jp2) {
- memset(jp2,0,sizeof(opj_jp2_t));
/* create the J2K codec */
if (! p_is_decoder) {
if (!l_codec){
return 00;
}
- memset(l_codec, 0, sizeof(opj_codec_private_t));
l_codec->is_decompressor = 1;
if (!l_codec) {
return 00;
}
- memset(l_codec, 0, sizeof(opj_codec_private_t));
l_codec->is_decompressor = 0;
if (!l_pi) {
return NULL;
}
- memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t));
l_current_pi = l_pi;
for (pino = 0; pino < l_poc_bound ; ++pino) {
}
l_current_pi->numcomps = image->numcomps;
- memset(l_current_pi->comps,0,image->numcomps * sizeof(opj_pi_comp_t));
for (compno = 0; compno < image->numcomps; ++compno) {
opj_pi_comp_t *comp = &l_current_pi->comps[compno];
tccp = &tcp->tccps[compno];
- comp->resolutions = (opj_pi_resolution_t*) opj_malloc(tccp->numresolutions * sizeof(opj_pi_resolution_t));
+ comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions, sizeof(opj_pi_resolution_t));
if (!comp->resolutions) {
opj_pi_destroy(l_pi, l_poc_bound);
return 00;
}
comp->numresolutions = tccp->numresolutions;
- memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
}
++l_current_pi;
}
opj_pi_destroy(l_pi, l_bound);
return 00;
}
- memset(l_current_pi->include,0, (l_tcp->numlayers + 1) * l_step_l* sizeof(OPJ_INT16));
/* special treatment for the first packet iterator */
l_current_comp = l_current_pi->comps;
opj_pi_destroy(l_pi, l_bound);
return 00;
}
- memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16));
/* special treatment for the first packet iterator*/
l_current_comp = l_current_pi->comps;
{
opj_t1_t *l_t1 = 00;
- l_t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t));
+ l_t1 = (opj_t1_t*) opj_calloc(1,sizeof(opj_t1_t));
if (!l_t1) {
return 00;
}
- memset(l_t1,0,sizeof(opj_t1_t));
/* create MQC and RAW handles */
l_t1->mqc = opj_mqc_create();
opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
{
/* create the t2 structure */
- opj_t2_t *l_t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t));
+ opj_t2_t *l_t2 = (opj_t2_t*)opj_calloc(1,sizeof(opj_t2_t));
if (!l_t2) {
return NULL;
}
- memset(l_t2,0,sizeof(opj_t2_t));
l_t2->image = p_image;
l_t2->cp = p_cp;
opj_tcd_t *l_tcd = 00;
/* create the tcd structure */
- l_tcd = (opj_tcd_t*) opj_malloc(sizeof(opj_tcd_t));
+ l_tcd = (opj_tcd_t*) opj_calloc(1,sizeof(opj_tcd_t));
if (!l_tcd) {
return 00;
}
- memset(l_tcd,0,sizeof(opj_tcd_t));
l_tcd->m_is_decoder = p_is_decoder ? 1 : 0;
- l_tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t));
+ l_tcd->tcd_image = (opj_tcd_image_t*)opj_calloc(1,sizeof(opj_tcd_image_t));
if (!l_tcd->tcd_image) {
opj_free(l_tcd);
return 00;
}
- memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_t));
return l_tcd;
}
opj_image_t * p_image,
opj_cp_t * p_cp )
{
- OPJ_UINT32 l_tile_comp_size;
-
p_tcd->image = p_image;
p_tcd->cp = p_cp;
- p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t));
+ p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(1,sizeof(opj_tcd_tile_t));
if (! p_tcd->tcd_image->tiles) {
return OPJ_FALSE;
}
- memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t));
- l_tile_comp_size = p_image->numcomps * (OPJ_UINT32)sizeof(opj_tcd_tilecomp_t);
- p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
+ p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_calloc(p_image->numcomps,sizeof(opj_tcd_tilecomp_t));
if (! p_tcd->tcd_image->tiles->comps ) {
return OPJ_FALSE;
}
- memset( p_tcd->tcd_image->tiles->comps , 0 , l_tile_comp_size);
p_tcd->tcd_image->tiles->numcomps = p_image->numcomps;
p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
p_code_block->data+=1;
/* no memset since data */
- p_code_block->layers = (opj_tcd_layer_t*) opj_malloc(100 * sizeof(opj_tcd_layer_t));
+ p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
if (! p_code_block->layers) {
return OPJ_FALSE;
}
- p_code_block->passes = (opj_tcd_pass_t*) opj_malloc(100 * sizeof(opj_tcd_pass_t));
+ p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
if (! p_code_block->passes) {
return OPJ_FALSE;
}
}
- memset(p_code_block->layers,0,100 * sizeof(opj_tcd_layer_t));
- memset(p_code_block->passes,0,100 * sizeof(opj_tcd_pass_t));
-
return OPJ_TRUE;
}
*/
OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
{
- OPJ_UINT32 l_seg_size;
-
if (! p_code_block->data) {
p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE);
p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE;
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
- l_seg_size = OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t);
- p_code_block->segs = (opj_tcd_seg_t *) opj_malloc(l_seg_size);
+ p_code_block->segs = (opj_tcd_seg_t *) opj_calloc(OPJ_J2K_DEFAULT_NB_SEGS,sizeof(opj_tcd_seg_t));
if (! p_code_block->segs) {
return OPJ_FALSE;
}
- memset(p_code_block->segs,0,l_seg_size);
/*fprintf(stderr, "Allocate %d elements of code_block->data\n", OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t));*/
p_code_block->m_current_max_segs = OPJ_J2K_DEFAULT_NB_SEGS;
OPJ_UINT32 numlvls;
OPJ_UINT32 n;
- tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
+ tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) {
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
return 00;
}
- memset(tree,0,sizeof(opj_tgt_tree_t));
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
opj_free(tree);
return 00;
}
- memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
node = tree->nodes;