[trunk] realloc is misused and may leak memory (Issue#168)
This commit is contained in:
parent
7bfdb31c77
commit
4e81ea2a8a
|
@ -475,10 +475,17 @@ int main(int argc, char *argv[]) {
|
||||||
// Ending loop
|
// Ending loop
|
||||||
fclose(j2kfile);
|
fclose(j2kfile);
|
||||||
snum++;
|
snum++;
|
||||||
movie->tk[0].sample = (mj2_sample_t*)
|
mj2_sample_t * new_sample = (mj2_sample_t*)
|
||||||
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
|
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
|
||||||
movie->tk[0].chunk = (mj2_chunk_t*)
|
mj2_chunk_t * new_chunk = (mj2_chunk_t*)
|
||||||
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
|
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
|
||||||
|
if (new_sample && new_chunk) {
|
||||||
|
movie->tk[0].sample = new_sample;
|
||||||
|
movie->tk[0].chunk = new_chunk;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
free(frame_codestream);
|
free(frame_codestream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,8 @@ opj_bool opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_
|
||||||
opj_free(p_validation_list->m_procedures);
|
opj_free(p_validation_list->m_procedures);
|
||||||
p_validation_list->m_nb_max_procedures = 0;
|
p_validation_list->m_nb_max_procedures = 0;
|
||||||
p_validation_list->m_nb_procedures = 0;
|
p_validation_list->m_nb_procedures = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); */
|
||||||
|
fprintf(stderr, "Not enough memory to add a new validation procedure\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -884,7 +884,7 @@ Add main header marker information
|
||||||
@param pos byte offset of marker segment
|
@param pos byte offset of marker segment
|
||||||
@param len length of marker segment
|
@param len length of marker segment
|
||||||
*/
|
*/
|
||||||
static void opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len) ;
|
static opj_bool opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len) ;
|
||||||
/**
|
/**
|
||||||
Add tile header marker information
|
Add tile header marker information
|
||||||
@param tileno tile index number
|
@param tileno tile index number
|
||||||
|
@ -893,7 +893,7 @@ Add tile header marker information
|
||||||
@param pos byte offset of marker segment
|
@param pos byte offset of marker segment
|
||||||
@param len length of marker segment
|
@param len length of marker segment
|
||||||
*/
|
*/
|
||||||
static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len);
|
static opj_bool opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an unknown marker
|
* Reads an unknown marker
|
||||||
|
@ -1800,8 +1800,10 @@ static opj_bool opj_j2k_read_soc( opj_j2k_v2_t *p_j2k,
|
||||||
opj_event_msg_v2(p_manager, EVT_INFO, "Start to read j2k main header (%d).\n", p_j2k->cstr_index->main_head_start);
|
opj_event_msg_v2(p_manager, EVT_INFO, "Start to read j2k main header (%d).\n", p_j2k->cstr_index->main_head_start);
|
||||||
|
|
||||||
/* Add the marker to the codestream index*/
|
/* Add the marker to the codestream index*/
|
||||||
opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_SOC, p_j2k->cstr_index->main_head_start, 2);
|
if (OPJ_FALSE == opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_SOC, p_j2k->cstr_index->main_head_start, 2)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1836,14 +1838,15 @@ opj_bool opj_j2k_write_siz( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
if (l_size_len > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_size_len > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
|
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_size_len);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_size_len);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory for the SIZ marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_size_len;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_size_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2250,14 +2253,15 @@ opj_bool opj_j2k_write_com( opj_j2k_v2_t *p_j2k,
|
||||||
l_total_com_size = l_comment_size + 6;
|
l_total_com_size = l_comment_size + 6;
|
||||||
|
|
||||||
if (l_total_com_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_total_com_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_total_com_size);
|
||||||
= (OPJ_BYTE*)opj_realloc( p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
if (! new_header_tile_data) {
|
||||||
l_total_com_size);
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
if(! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write the COM marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_total_com_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_total_com_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2330,15 +2334,15 @@ opj_bool opj_j2k_write_cod( opj_j2k_v2_t *p_j2k,
|
||||||
l_remaining_size = l_code_size;
|
l_remaining_size = l_code_size;
|
||||||
|
|
||||||
if (l_code_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_code_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_code_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_code_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write COD marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_code_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_code_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2504,10 +2508,16 @@ opj_bool opj_j2k_write_coc( opj_j2k_v2_t *p_j2k,
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
= (OPJ_BYTE*)opj_realloc(
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
||||||
l_coc_size);
|
l_coc_size);
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
|
||||||
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_coc_size);
|
||||||
|
if (! new_header_tile_data) {
|
||||||
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write COC marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_coc_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_coc_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2690,15 +2700,15 @@ opj_bool opj_j2k_write_qcd( opj_j2k_v2_t *p_j2k,
|
||||||
l_remaining_size = l_qcd_size;
|
l_remaining_size = l_qcd_size;
|
||||||
|
|
||||||
if (l_qcd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_qcd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_qcd_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_qcd_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write QCD marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_qcd_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_qcd_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2788,14 +2798,15 @@ opj_bool opj_j2k_write_qcc( opj_j2k_v2_t *p_j2k,
|
||||||
l_remaining_size = l_qcc_size;
|
l_remaining_size = l_qcc_size;
|
||||||
|
|
||||||
if (l_qcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_qcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_qcc_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_qcc_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write QCC marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_qcc_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_qcc_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2992,15 +3003,15 @@ opj_bool opj_j2k_write_poc( opj_j2k_v2_t *p_j2k,
|
||||||
l_poc_size = 4 + (5 + 2 * l_poc_room) * l_nb_poc;
|
l_poc_size = 4 + (5 + 2 * l_poc_room) * l_nb_poc;
|
||||||
|
|
||||||
if (l_poc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_poc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_poc_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_poc_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write POC marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_poc_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_poc_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3545,13 +3556,17 @@ opj_bool j2k_read_ppm_v2 (
|
||||||
p_header_size-=4;
|
p_header_size-=4;
|
||||||
l_cp->ppm_len += l_N_ppm ;
|
l_cp->ppm_len += l_N_ppm ;
|
||||||
|
|
||||||
l_cp->ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
|
OPJ_BYTE *new_ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
|
||||||
if (l_cp->ppm_buffer == 00) {
|
if (! new_ppm_buffer) {
|
||||||
|
opj_free(l_cp->ppm_buffer);
|
||||||
|
l_cp->ppm_buffer = NULL;
|
||||||
|
l_cp->ppm_len = 0;
|
||||||
|
l_cp->ppm_data = NULL;
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading ppm marker\n");
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading ppm marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_cp->ppm_buffer = new_ppm_buffer;
|
||||||
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
|
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
|
||||||
|
|
||||||
l_cp->ppm_data = l_cp->ppm_buffer;
|
l_cp->ppm_data = l_cp->ppm_buffer;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3664,7 +3679,15 @@ opj_bool j2k_read_ppm_v3 (
|
||||||
p_header_size-=4;
|
p_header_size-=4;
|
||||||
|
|
||||||
/* Increase the size of ppm_data to add the new Ippm series*/
|
/* Increase the size of ppm_data to add the new Ippm series*/
|
||||||
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
OPJ_BYTE *new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
||||||
|
if (! new_ppm_data) {
|
||||||
|
opj_free(l_cp->ppm_data);
|
||||||
|
l_cp->ppm_data = NULL;
|
||||||
|
l_cp->ppm_len = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new Ippm series\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
l_cp->ppm_data = new_ppm_data;
|
||||||
|
|
||||||
/* Keep the position of the place where concatenate the new series*/
|
/* Keep the position of the place where concatenate the new series*/
|
||||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
||||||
|
@ -3699,7 +3722,15 @@ opj_bool j2k_read_ppm_v3 (
|
||||||
/* Next Ippm series is a complete series ?*/
|
/* Next Ippm series is a complete series ?*/
|
||||||
if (l_remaining_data > l_N_ppm) {
|
if (l_remaining_data > l_N_ppm) {
|
||||||
/* Increase the size of ppm_data to add the new Ippm series*/
|
/* Increase the size of ppm_data to add the new Ippm series*/
|
||||||
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
OPJ_BYTE *new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
||||||
|
if (! new_ppm_data) {
|
||||||
|
opj_free(l_cp->ppm_data);
|
||||||
|
l_cp->ppm_data = NULL;
|
||||||
|
l_cp->ppm_len = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new (complete) Ippm series\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
l_cp->ppm_data = new_ppm_data;
|
||||||
|
|
||||||
/* Keep the position of the place where concatenate the new series */
|
/* Keep the position of the place where concatenate the new series */
|
||||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
||||||
|
@ -3710,7 +3741,15 @@ opj_bool j2k_read_ppm_v3 (
|
||||||
|
|
||||||
/* Need to read an incomplete Ippm series*/
|
/* Need to read an incomplete Ippm series*/
|
||||||
if (l_remaining_data) {
|
if (l_remaining_data) {
|
||||||
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
OPJ_BYTE *new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
||||||
|
if (! new_ppm_data) {
|
||||||
|
opj_free(l_cp->ppm_data);
|
||||||
|
l_cp->ppm_data = NULL;
|
||||||
|
l_cp->ppm_len = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new (incomplete) Ippm series\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
l_cp->ppm_data = new_ppm_data;
|
||||||
|
|
||||||
/* Keep the position of the place where concatenate the new series*/
|
/* Keep the position of the place where concatenate the new series*/
|
||||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
||||||
|
@ -3734,11 +3773,15 @@ opj_bool j2k_read_ppm_v3 (
|
||||||
p_header_size-=4;
|
p_header_size-=4;
|
||||||
l_cp->ppm_len += l_N_ppm ;
|
l_cp->ppm_len += l_N_ppm ;
|
||||||
|
|
||||||
l_cp->ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
|
OPJ_BYTE *new_ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
|
||||||
if (l_cp->ppm_buffer == 00) {
|
if (! new_ppm_buffer) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading ppm marker\n");
|
opj_free(l_cp->ppm_buffer);
|
||||||
|
l_cp->ppm_buffer = NULL;
|
||||||
|
l_cp->ppm_len = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_cp->ppm_buffer = new_ppm_buffer;
|
||||||
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
|
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
|
||||||
|
|
||||||
l_cp->ppm_data = l_cp->ppm_buffer;
|
l_cp->ppm_data = l_cp->ppm_buffer;
|
||||||
|
@ -3819,7 +3862,7 @@ static opj_bool opj_j2k_read_ppt ( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
l_tcp->ppt_buffer = (OPJ_BYTE *) opj_calloc(l_tcp->ppt_len, sizeof(OPJ_BYTE) );
|
l_tcp->ppt_buffer = (OPJ_BYTE *) opj_calloc(l_tcp->ppt_len, sizeof(OPJ_BYTE) );
|
||||||
if (l_tcp->ppt_buffer == 00) {
|
if (l_tcp->ppt_buffer == 00) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading PPT marker\n");
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
l_tcp->ppt_data = l_tcp->ppt_buffer;
|
l_tcp->ppt_data = l_tcp->ppt_buffer;
|
||||||
|
@ -3829,11 +3872,15 @@ static opj_bool opj_j2k_read_ppt ( opj_j2k_v2_t *p_j2k,
|
||||||
else {
|
else {
|
||||||
l_tcp->ppt_len += p_header_size;
|
l_tcp->ppt_len += p_header_size;
|
||||||
|
|
||||||
l_tcp->ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer,l_tcp->ppt_len);
|
OPJ_BYTE *new_ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer, l_tcp->ppt_len);
|
||||||
if (l_tcp->ppt_buffer == 00) {
|
if (! new_ppt_buffer) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading PPT marker\n");
|
opj_free(l_tcp->ppt_buffer);
|
||||||
|
l_tcp->ppt_buffer = NULL;
|
||||||
|
l_tcp->ppt_len = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_tcp->ppt_buffer = new_ppt_buffer;
|
||||||
l_tcp->ppt_data = l_tcp->ppt_buffer;
|
l_tcp->ppt_data = l_tcp->ppt_buffer;
|
||||||
|
|
||||||
memset(l_tcp->ppt_buffer+l_tcp->ppt_data_size,0,p_header_size);
|
memset(l_tcp->ppt_buffer+l_tcp->ppt_data_size,0,p_header_size);
|
||||||
|
@ -3870,15 +3917,15 @@ opj_bool opj_j2k_write_tlm( opj_j2k_v2_t *p_j2k,
|
||||||
l_tlm_size = 6 + (5*p_j2k->m_specific_param.m_encoder.m_total_tile_parts);
|
l_tlm_size = 6 + (5*p_j2k->m_specific_param.m_encoder.m_total_tile_parts);
|
||||||
|
|
||||||
if (l_tlm_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_tlm_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_tlm_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_tlm_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write TLM marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_tlm_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_tlm_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4134,14 +4181,21 @@ opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = l_num_parts;
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = l_num_parts;
|
||||||
|
|
||||||
|
|
||||||
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)
|
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
|
||||||
(opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t));
|
(opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t));
|
||||||
else
|
}
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
|
else {
|
||||||
(opj_tp_index_t*)opj_realloc(
|
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index,
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index, l_num_parts* sizeof(opj_tp_index_t));
|
||||||
l_num_parts* sizeof(opj_tp_index_t));
|
if (! new_tp_index) {
|
||||||
|
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
|
||||||
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/*if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)*/ {
|
/*if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)*/ {
|
||||||
|
@ -4155,10 +4209,17 @@ opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
|
if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps += 10;
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps += 10;
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
|
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
|
||||||
(opj_tp_index_t*)opj_realloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index,
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index,
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps * sizeof(opj_tp_index_t));
|
||||||
* sizeof(opj_tp_index_t));
|
if (! new_tp_index) {
|
||||||
|
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
|
||||||
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
|
||||||
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4195,7 +4256,7 @@ opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
|
||||||
p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
|
p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
|
||||||
}*/
|
}*/
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the SOD marker (Start of data)
|
* Writes the SOD marker (Start of data)
|
||||||
|
@ -4331,14 +4392,25 @@ opj_bool opj_j2k_read_sod (opj_j2k_v2_t *p_j2k,
|
||||||
l_tile_len = &l_tcp->m_data_size;
|
l_tile_len = &l_tcp->m_data_size;
|
||||||
|
|
||||||
if (! *l_current_data) {
|
if (! *l_current_data) {
|
||||||
|
/* LH: oddly enough, in this path, l_tile_len!=0.
|
||||||
|
* TODO: If this was consistant, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...).
|
||||||
|
*/
|
||||||
*l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param.m_decoder.m_sot_length);
|
*l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param.m_decoder.m_sot_length);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*l_current_data = (OPJ_BYTE*) opj_realloc(*l_current_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length);
|
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_current_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length);
|
||||||
|
if (! l_new_current_data) {
|
||||||
|
opj_free(*l_current_data);
|
||||||
|
// nothing more is done as l_current_data will be set to null, and just
|
||||||
|
// afterward we enter in the error path
|
||||||
|
// and the actual tile_len is updated (committed) at the end of the
|
||||||
|
// function.
|
||||||
|
}
|
||||||
|
*l_current_data = l_new_current_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*l_current_data == 00) {
|
if (*l_current_data == 00) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Cannot decode tile\n");
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tile\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4354,16 +4426,20 @@ opj_bool opj_j2k_read_sod (opj_j2k_v2_t *p_j2k,
|
||||||
l_cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index[l_current_tile_part].end_pos =
|
l_cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index[l_current_tile_part].end_pos =
|
||||||
l_current_pos + p_j2k->m_specific_param.m_decoder.m_sot_length + 2;
|
l_current_pos + p_j2k->m_specific_param.m_decoder.m_sot_length + 2;
|
||||||
|
|
||||||
opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
|
if (OPJ_FALSE == opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
|
||||||
l_cstr_index,
|
l_cstr_index,
|
||||||
J2K_MS_SOD,
|
J2K_MS_SOD,
|
||||||
l_current_pos,
|
l_current_pos,
|
||||||
p_j2k->m_specific_param.m_decoder.m_sot_length + 2);
|
p_j2k->m_specific_param.m_decoder.m_sot_length + 2)) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add tl marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/*l_cstr_index->packno = 0;*/
|
/*l_cstr_index->packno = 0;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
l_current_read_size = opj_stream_read_data( p_stream,
|
l_current_read_size = opj_stream_read_data(
|
||||||
|
p_stream,
|
||||||
*l_current_data + *l_tile_len,
|
*l_current_data + *l_tile_len,
|
||||||
p_j2k->m_specific_param.m_decoder.m_sot_length,
|
p_j2k->m_specific_param.m_decoder.m_sot_length,
|
||||||
p_manager);
|
p_manager);
|
||||||
|
@ -5040,9 +5116,15 @@ opj_bool opj_j2k_read_unk ( opj_j2k_v2_t *p_j2k,
|
||||||
if (l_marker_handler->id != J2K_MS_UNK) {
|
if (l_marker_handler->id != J2K_MS_UNK) {
|
||||||
/* Add the marker to the codestream index*/
|
/* Add the marker to the codestream index*/
|
||||||
if (l_marker_handler->id != J2K_MS_SOT)
|
if (l_marker_handler->id != J2K_MS_SOT)
|
||||||
opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_UNK,
|
{
|
||||||
|
opj_bool res = opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_UNK,
|
||||||
(OPJ_UINT32) opj_stream_tell(p_stream) - l_size_unk,
|
(OPJ_UINT32) opj_stream_tell(p_stream) - l_size_unk,
|
||||||
l_size_unk);
|
l_size_unk);
|
||||||
|
if (res == OPJ_FALSE) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
break; /* next marker is known and well located */
|
break; /* next marker is known and well located */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -5080,15 +5162,15 @@ opj_bool opj_j2k_write_mct_record( opj_j2k_v2_t *p_j2k,
|
||||||
l_mct_size = 10 + p_mct_record->m_data_size;
|
l_mct_size = 10 + p_mct_record->m_data_size;
|
||||||
|
|
||||||
if (l_mct_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_mct_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mct_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_mct_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write MCT marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mct_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mct_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5186,12 +5268,16 @@ static opj_bool opj_j2k_read_mct ( opj_j2k_v2_t *p_j2k,
|
||||||
if (l_tcp->m_nb_mct_records == l_tcp->m_nb_max_mct_records) {
|
if (l_tcp->m_nb_mct_records == l_tcp->m_nb_max_mct_records) {
|
||||||
l_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
l_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
||||||
|
|
||||||
l_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(l_tcp->m_mct_records,l_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
|
opj_mct_data_t *new_mct_records = (opj_mct_data_t *) opj_realloc(l_tcp->m_mct_records, l_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
|
||||||
if(! l_tcp->m_mct_records) {
|
if (! new_mct_records) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading MCT marker\n");
|
opj_free(l_tcp->m_mct_records);
|
||||||
|
l_tcp->m_mct_records = NULL;
|
||||||
|
l_tcp->m_nb_max_mct_records = 0;
|
||||||
|
l_tcp->m_nb_mct_records = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read MCT marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_tcp->m_mct_records = new_mct_records;
|
||||||
l_mct_data = l_tcp->m_mct_records + l_tcp->m_nb_mct_records;
|
l_mct_data = l_tcp->m_mct_records + l_tcp->m_nb_mct_records;
|
||||||
memset(l_mct_data ,0,(l_tcp->m_nb_max_mct_records - l_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
|
memset(l_mct_data ,0,(l_tcp->m_nb_max_mct_records - l_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
|
||||||
}
|
}
|
||||||
|
@ -5266,14 +5352,15 @@ opj_bool opj_j2k_write_mcc_record( opj_j2k_v2_t *p_j2k,
|
||||||
l_mcc_size = p_mcc_record->m_nb_comps * 2 * l_nb_bytes_for_comp + 19;
|
l_mcc_size = p_mcc_record->m_nb_comps * 2 * l_nb_bytes_for_comp + 19;
|
||||||
if (l_mcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size)
|
if (l_mcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size)
|
||||||
{
|
{
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mcc_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_mcc_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write MCC marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mcc_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mcc_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5407,12 +5494,17 @@ opj_bool opj_j2k_read_mcc ( opj_j2k_v2_t *p_j2k,
|
||||||
if (l_tcp->m_nb_mcc_records == l_tcp->m_nb_max_mcc_records) {
|
if (l_tcp->m_nb_mcc_records == l_tcp->m_nb_max_mcc_records) {
|
||||||
l_tcp->m_nb_max_mcc_records += J2K_MCC_DEFAULT_NB_RECORDS;
|
l_tcp->m_nb_max_mcc_records += J2K_MCC_DEFAULT_NB_RECORDS;
|
||||||
|
|
||||||
l_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*)
|
opj_simple_mcc_decorrelation_data_t *new_mcc_records = (opj_simple_mcc_decorrelation_data_t *) opj_realloc(
|
||||||
opj_realloc(l_tcp->m_mcc_records,l_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
|
l_tcp->m_mcc_records, l_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
|
||||||
if (! l_tcp->m_mcc_records) {
|
if (! new_mcc_records) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading MCC marker\n");
|
opj_free(l_tcp->m_mcc_records);
|
||||||
|
l_tcp->m_mcc_records = NULL;
|
||||||
|
l_tcp->m_nb_max_mcc_records = 0;
|
||||||
|
l_tcp->m_nb_mcc_records = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read MCC marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_tcp->m_mcc_records = new_mcc_records;
|
||||||
l_mcc_record = l_tcp->m_mcc_records + l_tcp->m_nb_mcc_records;
|
l_mcc_record = l_tcp->m_mcc_records + l_tcp->m_nb_mcc_records;
|
||||||
memset(l_mcc_record,0,(l_tcp->m_nb_max_mcc_records-l_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
|
memset(l_mcc_record,0,(l_tcp->m_nb_max_mcc_records-l_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
|
||||||
}
|
}
|
||||||
|
@ -5587,15 +5679,15 @@ opj_bool opj_j2k_write_mco( opj_j2k_v2_t *p_j2k,
|
||||||
l_mco_size = 5 + l_tcp->m_nb_mcc_records;
|
l_mco_size = 5 + l_tcp->m_nb_mcc_records;
|
||||||
if (l_mco_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_mco_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
|
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mco_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_mco_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data)
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
{
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write MCO marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mco_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mco_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5610,7 +5702,7 @@ opj_bool opj_j2k_write_mco( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
l_mcc_record = l_tcp->m_mcc_records;
|
l_mcc_record = l_tcp->m_mcc_records;
|
||||||
for (i=0;i<l_tcp->m_nb_mcc_records;++i) {
|
for (i=0;i<l_tcp->m_nb_mcc_records;++i) {
|
||||||
opj_write_bytes(l_current_data,l_mcc_record->m_index,1); /* Imco -> use the mcc indicated by 1*/
|
opj_write_bytes(l_current_data,l_mcc_record->m_index,1);/* Imco -> use the mcc indicated by 1*/
|
||||||
++l_current_data;
|
++l_current_data;
|
||||||
|
|
||||||
++l_mcc_record;
|
++l_mcc_record;
|
||||||
|
@ -5805,15 +5897,15 @@ opj_bool opj_j2k_write_cbd( opj_j2k_v2_t *p_j2k,
|
||||||
l_cbd_size = 6 + p_j2k->m_private_image->numcomps;
|
l_cbd_size = 6 + p_j2k->m_private_image->numcomps;
|
||||||
|
|
||||||
if (l_cbd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
if (l_cbd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data
|
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_cbd_size);
|
||||||
= (OPJ_BYTE*)opj_realloc(
|
if (! new_header_tile_data) {
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
|
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
|
||||||
l_cbd_size);
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
|
||||||
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write CBD marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
|
||||||
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_cbd_size;
|
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_cbd_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6273,14 +6365,23 @@ void opj_j2k_setup_encoder( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
|
static opj_bool opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
|
||||||
{
|
{
|
||||||
assert(cstr_index != 00);
|
assert(cstr_index != 00);
|
||||||
|
|
||||||
/* expand the list? */
|
/* expand the list? */
|
||||||
if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) {
|
if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) {
|
||||||
cstr_index->maxmarknum = 100 + (int) ((float) cstr_index->maxmarknum * 1.0F);
|
cstr_index->maxmarknum = 100 + (int) ((float) cstr_index->maxmarknum * 1.0F);
|
||||||
cstr_index->marker = (opj_marker_info_t*)opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t));
|
opj_marker_info_t *new_marker = (opj_marker_info_t *) opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t));
|
||||||
|
if (! new_marker) {
|
||||||
|
opj_free(cstr_index->marker);
|
||||||
|
cstr_index->marker = NULL;
|
||||||
|
cstr_index->maxmarknum = 0;
|
||||||
|
cstr_index->marknum = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n"); */
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
cstr_index->marker = new_marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the marker */
|
/* add the marker */
|
||||||
|
@ -6288,10 +6389,10 @@ static void opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32
|
||||||
cstr_index->marker[cstr_index->marknum].pos = (OPJ_INT32)pos;
|
cstr_index->marker[cstr_index->marknum].pos = (OPJ_INT32)pos;
|
||||||
cstr_index->marker[cstr_index->marknum].len = (OPJ_INT32)len;
|
cstr_index->marker[cstr_index->marknum].len = (OPJ_INT32)len;
|
||||||
cstr_index->marknum++;
|
cstr_index->marknum++;
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
|
static opj_bool opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
|
||||||
{
|
{
|
||||||
assert(cstr_index != 00);
|
assert(cstr_index != 00);
|
||||||
assert(cstr_index->tile_index != 00);
|
assert(cstr_index->tile_index != 00);
|
||||||
|
@ -6299,9 +6400,18 @@ static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr
|
||||||
/* expand the list? */
|
/* expand the list? */
|
||||||
if ((cstr_index->tile_index[tileno].marknum + 1) > cstr_index->tile_index[tileno].maxmarknum) {
|
if ((cstr_index->tile_index[tileno].marknum + 1) > cstr_index->tile_index[tileno].maxmarknum) {
|
||||||
cstr_index->tile_index[tileno].maxmarknum = 100 + (int) ((float) cstr_index->tile_index[tileno].maxmarknum * 1.0F);
|
cstr_index->tile_index[tileno].maxmarknum = 100 + (int) ((float) cstr_index->tile_index[tileno].maxmarknum * 1.0F);
|
||||||
cstr_index->tile_index[tileno].marker =
|
opj_marker_info_t *new_marker = (opj_marker_info_t *) opj_realloc(
|
||||||
(opj_marker_info_t*)opj_realloc(cstr_index->tile_index[tileno].marker,
|
cstr_index->tile_index[tileno].marker,
|
||||||
cstr_index->tile_index[tileno].maxmarknum *sizeof(opj_marker_info_t));
|
cstr_index->tile_index[tileno].maxmarknum *sizeof(opj_marker_info_t));
|
||||||
|
if (! new_marker) {
|
||||||
|
opj_free(cstr_index->tile_index[tileno].marker);
|
||||||
|
cstr_index->tile_index[tileno].marker = NULL;
|
||||||
|
cstr_index->tile_index[tileno].maxmarknum = 0;
|
||||||
|
cstr_index->tile_index[tileno].marknum = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add tl marker\n"); */
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
cstr_index->tile_index[tileno].marker = new_marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the marker */
|
/* add the marker */
|
||||||
|
@ -6317,6 +6427,7 @@ static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr
|
||||||
cstr_index->tile_index[tileno].tp_index[l_current_tile_part].start_pos = pos;
|
cstr_index->tile_index[tileno].tp_index[l_current_tile_part].start_pos = pos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6497,10 +6608,16 @@ opj_bool opj_j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
|
||||||
if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
|
if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
|
||||||
p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
||||||
|
|
||||||
p_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(p_tcp->m_mct_records,p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
|
opj_mct_data_t *new_mct_records = (opj_mct_data_t *) opj_realloc(p_tcp->m_mct_records, p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
|
||||||
if (! p_tcp->m_mct_records) {
|
if (! new_mct_records) {
|
||||||
|
opj_free(p_tcp->m_mct_records);
|
||||||
|
p_tcp->m_mct_records = NULL;
|
||||||
|
p_tcp->m_nb_max_mct_records = 0;
|
||||||
|
p_tcp->m_nb_mct_records = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to setup mct encoding\n"); */
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_tcp->m_mct_records = new_mct_records;
|
||||||
l_mct_deco_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
|
l_mct_deco_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
|
||||||
|
|
||||||
memset(l_mct_deco_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
|
memset(l_mct_deco_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
|
||||||
|
@ -6531,13 +6648,18 @@ opj_bool opj_j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
|
||||||
|
|
||||||
if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
|
if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
|
||||||
p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
||||||
p_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(p_tcp->m_mct_records,p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
|
opj_mct_data_t *new_mct_records = (opj_mct_data_t *) opj_realloc(p_tcp->m_mct_records, p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
|
||||||
|
if (! new_mct_records) {
|
||||||
if (! p_tcp->m_mct_records) {
|
opj_free(p_tcp->m_mct_records);
|
||||||
|
p_tcp->m_mct_records = NULL;
|
||||||
|
p_tcp->m_nb_max_mct_records = 0;
|
||||||
|
p_tcp->m_nb_mct_records = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to setup mct encoding\n"); */
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_tcp->m_mct_records = new_mct_records;
|
||||||
l_mct_offset_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
|
l_mct_offset_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
|
||||||
|
|
||||||
memset(l_mct_offset_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
|
memset(l_mct_offset_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
|
||||||
|
|
||||||
if (l_mct_deco_data) {
|
if (l_mct_deco_data) {
|
||||||
|
@ -6588,12 +6710,17 @@ opj_bool opj_j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
|
||||||
|
|
||||||
if (p_tcp->m_nb_mcc_records == p_tcp->m_nb_max_mcc_records) {
|
if (p_tcp->m_nb_mcc_records == p_tcp->m_nb_max_mcc_records) {
|
||||||
p_tcp->m_nb_max_mcc_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
p_tcp->m_nb_max_mcc_records += J2K_MCT_DEFAULT_NB_RECORDS;
|
||||||
p_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*)
|
opj_simple_mcc_decorrelation_data_t *new_mcc_records = (opj_simple_mcc_decorrelation_data_t *) opj_realloc(
|
||||||
opj_realloc(p_tcp->m_mcc_records,p_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
|
p_tcp->m_mcc_records, p_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
|
||||||
|
if (! new_mcc_records) {
|
||||||
if (! p_tcp->m_mcc_records) {
|
opj_free(p_tcp->m_mcc_records);
|
||||||
|
p_tcp->m_mcc_records = NULL;
|
||||||
|
p_tcp->m_nb_max_mcc_records = 0;
|
||||||
|
p_tcp->m_nb_mcc_records = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to setup mct encoding\n"); */
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_tcp->m_mcc_records = new_mcc_records;
|
||||||
l_mcc_data = p_tcp->m_mcc_records + p_tcp->m_nb_mcc_records;
|
l_mcc_data = p_tcp->m_mcc_records + p_tcp->m_nb_mcc_records;
|
||||||
memset(l_mcc_data ,0,(p_tcp->m_nb_max_mcc_records - p_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
|
memset(l_mcc_data ,0,(p_tcp->m_nb_max_mcc_records - p_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
|
||||||
|
|
||||||
|
@ -6798,11 +6925,15 @@ opj_bool opj_j2k_read_header_procedure( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
/* Check if the marker size is compatible with the header data size */
|
/* Check if the marker size is compatible with the header data size */
|
||||||
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
|
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
|
||||||
p_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE*)
|
OPJ_BYTE *new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
|
||||||
opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size);
|
if (! new_header_data) {
|
||||||
if (p_j2k->m_specific_param.m_decoder.m_header_data == 00) {
|
opj_free(p_j2k->m_specific_param.m_decoder.m_header_data);
|
||||||
|
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_decoder.m_header_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read header\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_decoder.m_header_data = new_header_data;
|
||||||
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
|
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6819,10 +6950,14 @@ opj_bool opj_j2k_read_header_procedure( opj_j2k_v2_t *p_j2k,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the marker to the codestream index*/
|
/* Add the marker to the codestream index*/
|
||||||
opj_j2k_add_mhmarker(p_j2k->cstr_index,
|
if (OPJ_FALSE == opj_j2k_add_mhmarker(
|
||||||
|
p_j2k->cstr_index,
|
||||||
l_marker_handler->id,
|
l_marker_handler->id,
|
||||||
(OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4,
|
(OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4,
|
||||||
l_marker_size + 4 );
|
l_marker_size + 4 )) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
|
/* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
|
||||||
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
|
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
|
||||||
|
@ -7346,11 +7481,15 @@ opj_bool opj_j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
|
||||||
|
|
||||||
/* Check if the marker size is compatible with the header data size */
|
/* Check if the marker size is compatible with the header data size */
|
||||||
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
|
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
|
||||||
p_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE*)
|
OPJ_BYTE *new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
|
||||||
opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size);
|
if (! new_header_data) {
|
||||||
if (p_j2k->m_specific_param.m_decoder.m_header_data == 00) {
|
opj_free(p_j2k->m_specific_param.m_decoder.m_header_data);
|
||||||
|
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
|
||||||
|
p_j2k->m_specific_param.m_decoder.m_header_data_size = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read header\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
p_j2k->m_specific_param.m_decoder.m_header_data = new_header_data;
|
||||||
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
|
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7367,11 +7506,14 @@ opj_bool opj_j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the marker to the codestream index*/
|
/* Add the marker to the codestream index*/
|
||||||
opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
|
if (OPJ_FALSE == opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
|
||||||
p_j2k->cstr_index,
|
p_j2k->cstr_index,
|
||||||
l_marker_handler->id,
|
l_marker_handler->id,
|
||||||
(OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4,
|
(OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4,
|
||||||
l_marker_size + 4 );
|
l_marker_size + 4 )) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add tl marker\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Keep the position of the last SOT marker read */
|
/* Keep the position of the last SOT marker read */
|
||||||
if ( l_marker_handler->id == J2K_MS_SOT ) {
|
if ( l_marker_handler->id == J2K_MS_SOT ) {
|
||||||
|
@ -9106,6 +9248,7 @@ opj_bool opj_j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
|
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
|
||||||
if (! l_current_data) {
|
if (! l_current_data) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tiles\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
l_max_data_size = 1000;
|
l_max_data_size = 1000;
|
||||||
|
@ -9131,12 +9274,13 @@ opj_bool opj_j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l_data_size > l_max_data_size) {
|
if (l_data_size > l_max_data_size) {
|
||||||
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_data_size);
|
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_data_size);
|
||||||
if (! l_current_data) {
|
if (! l_new_current_data) {
|
||||||
opj_free(l_current_data);
|
opj_free(l_current_data);
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tile %d/%d\n", l_current_tile_no +1, p_j2k->m_cp.th * p_j2k->m_cp.tw);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_current_data = l_new_current_data;
|
||||||
l_max_data_size = l_data_size;
|
l_max_data_size = l_data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9189,6 +9333,7 @@ static opj_bool opj_j2k_decode_one_tile ( opj_j2k_v2_t *p_j2k,
|
||||||
|
|
||||||
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
|
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
|
||||||
if (! l_current_data) {
|
if (! l_current_data) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode one tile\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
l_max_data_size = 1000;
|
l_max_data_size = 1000;
|
||||||
|
@ -9245,12 +9390,16 @@ static opj_bool opj_j2k_decode_one_tile ( opj_j2k_v2_t *p_j2k,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l_data_size > l_max_data_size) {
|
if (l_data_size > l_max_data_size) {
|
||||||
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_data_size);
|
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_data_size);
|
||||||
if (! l_current_data) {
|
if (! l_new_current_data) {
|
||||||
opj_free(l_current_data);
|
opj_free(l_current_data);
|
||||||
|
l_current_data = NULL;
|
||||||
|
// TODO: LH: why tile numbering policy used in messages differs from
|
||||||
|
// the one used in opj_j2k_decode_tiles() ?
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tile %d/%d\n", l_current_tile_no, (p_j2k->m_cp.th * p_j2k->m_cp.tw) - 1);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_current_data = l_new_current_data;
|
||||||
l_max_data_size = l_data_size;
|
l_max_data_size = l_data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9497,6 +9646,7 @@ opj_bool opj_j2k_encode_v2( opj_j2k_v2_t * p_j2k,
|
||||||
|
|
||||||
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
|
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
|
||||||
if (! l_current_data) {
|
if (! l_current_data) {
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to encode all tiles\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
l_max_tile_size = 1000;
|
l_max_tile_size = 1000;
|
||||||
|
@ -9510,10 +9660,13 @@ opj_bool opj_j2k_encode_v2( opj_j2k_v2_t * p_j2k,
|
||||||
|
|
||||||
l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd);
|
l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd);
|
||||||
if (l_current_tile_size > l_max_tile_size) {
|
if (l_current_tile_size > l_max_tile_size) {
|
||||||
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_tile_size);
|
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_current_tile_size);
|
||||||
if (! l_current_data) {
|
if (! l_new_current_data) {
|
||||||
|
opj_free(l_current_data);
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to encode all tiles\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_current_data = l_new_current_data;
|
||||||
l_max_tile_size = l_current_tile_size;
|
l_max_tile_size = l_current_tile_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1785,17 +1785,22 @@ static opj_bool opj_jp2_read_header_procedure( opj_jp2_v2_t *jp2,
|
||||||
|
|
||||||
if (l_current_handler != 00) {
|
if (l_current_handler != 00) {
|
||||||
if (l_current_data_size > l_last_data_size) {
|
if (l_current_data_size > l_last_data_size) {
|
||||||
l_current_data = (unsigned char*)opj_realloc(l_current_data,l_current_data_size);
|
unsigned char* new_current_data = (unsigned char*)opj_realloc(l_current_data,l_current_data_size);
|
||||||
if (!l_current_data){
|
if (!l_current_data){
|
||||||
opj_free(l_current_data);
|
opj_free(l_current_data);
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 box\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
l_current_data = new_current_data;
|
||||||
l_last_data_size = l_current_data_size;
|
l_last_data_size = l_current_data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
l_nb_bytes_read = opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager);
|
l_nb_bytes_read = opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager);
|
||||||
if (l_nb_bytes_read != l_current_data_size) {
|
if (l_nb_bytes_read != l_current_data_size) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n");
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n");
|
||||||
|
// TODO: LH: why nothing is freed here (as
|
||||||
|
// all other returns imply a free, even
|
||||||
|
// in the nominal case)?
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,15 +161,27 @@ void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
|
opj_bool j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
|
||||||
|
|
||||||
if (!cstr_info)
|
if (!cstr_info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* expand the list? */
|
/* expand the list? */
|
||||||
if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) {
|
if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) {
|
||||||
|
opj_marker_info_t* new_marker;
|
||||||
cstr_info->maxmarknum += 100;
|
cstr_info->maxmarknum += 100;
|
||||||
cstr_info->marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum * sizeof(opj_marker_info_t));
|
new_marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum * sizeof(opj_marker_info_t));
|
||||||
|
if (! new_marker)
|
||||||
|
{
|
||||||
|
opj_free(cstr_info->marker);
|
||||||
|
cstr_info->marker = 0;
|
||||||
|
cstr_info->marknum = 0;
|
||||||
|
cstr_info->maxmarknum = 0;
|
||||||
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add a marker\n"); // TODO: find a better error message
|
||||||
|
TODO_test_add_marker_result;
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
cstr_info->marker = new_marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the marker */
|
/* add the marker */
|
||||||
|
@ -177,6 +189,7 @@ void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, i
|
||||||
cstr_info->marker[cstr_info->marknum].pos = pos;
|
cstr_info->marker[cstr_info->marknum].pos = pos;
|
||||||
cstr_info->marker[cstr_info->marknum].len = len;
|
cstr_info->marker[cstr_info->marknum].len = len;
|
||||||
cstr_info->marknum++;
|
cstr_info->marknum++;
|
||||||
|
return OPJ_TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -363,7 +363,7 @@ opj_mqc_t* mqc_create(void) {
|
||||||
void mqc_destroy(opj_mqc_t *mqc) {
|
void mqc_destroy(opj_mqc_t *mqc) {
|
||||||
if(mqc) {
|
if(mqc) {
|
||||||
#ifdef MQC_PERF_OPT
|
#ifdef MQC_PERF_OPT
|
||||||
if (mqc->buffer) {
|
if (mqc->buffer) { // TODO: LH: this test is pointless as free() is a no-op on 0
|
||||||
opj_free(mqc->buffer);
|
opj_free(mqc->buffer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -508,7 +508,7 @@ void mqc_segmark_enc(opj_mqc_t *mqc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
opj_bool mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
||||||
mqc_setcurctx(mqc, 0);
|
mqc_setcurctx(mqc, 0);
|
||||||
mqc->start = bp;
|
mqc->start = bp;
|
||||||
mqc->end = bp + len;
|
mqc->end = bp + len;
|
||||||
|
@ -521,7 +521,13 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
unsigned int *ip;
|
unsigned int *ip;
|
||||||
unsigned char *end = mqc->end - 1;
|
unsigned char *end = mqc->end - 1;
|
||||||
mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
|
void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
|
||||||
|
if (! new_buffer) {
|
||||||
|
opj_free(mqc->buffer);
|
||||||
|
mqc->buffer = NULL;
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
mqc->buffer = new_buffer;
|
||||||
ip = (unsigned int *) mqc->buffer;
|
ip = (unsigned int *) mqc->buffer;
|
||||||
|
|
||||||
while (bp < end) {
|
while (bp < end) {
|
||||||
|
@ -557,6 +563,7 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
||||||
mqc->c <<= 7;
|
mqc->c <<= 7;
|
||||||
mqc->ct -= 7;
|
mqc->ct -= 7;
|
||||||
mqc->a = 0x8000;
|
mqc->a = 0x8000;
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mqc_decode(opj_mqc_t *const mqc) {
|
int mqc_decode(opj_mqc_t *const mqc) {
|
||||||
|
|
|
@ -185,7 +185,7 @@ Initialize the decoder
|
||||||
@param bp Pointer to the start of the buffer from which the bytes will be read
|
@param bp Pointer to the start of the buffer from which the bytes will be read
|
||||||
@param len Length of the input buffer
|
@param len Length of the input buffer
|
||||||
*/
|
*/
|
||||||
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
|
opj_bool mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
|
||||||
/**
|
/**
|
||||||
Decode a symbol
|
Decode a symbol
|
||||||
@param mqc MQC handle
|
@param mqc MQC handle
|
||||||
|
|
|
@ -330,8 +330,9 @@ Decode 1 code-block
|
||||||
@param orient
|
@param orient
|
||||||
@param roishift Region of interest shifting value
|
@param roishift Region of interest shifting value
|
||||||
@param cblksty Code-block style
|
@param cblksty Code-block style
|
||||||
|
@deprecated ?
|
||||||
*/
|
*/
|
||||||
static void t1_decode_cblk(
|
static opj_bool t1_decode_cblk(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
opj_tcd_cblk_dec_t* cblk,
|
opj_tcd_cblk_dec_t* cblk,
|
||||||
int orient,
|
int orient,
|
||||||
|
@ -346,7 +347,7 @@ Decode 1 code-block
|
||||||
@param roishift Region of interest shifting value
|
@param roishift Region of interest shifting value
|
||||||
@param cblksty Code-block style
|
@param cblksty Code-block style
|
||||||
*/
|
*/
|
||||||
static void t1_decode_cblk_v2(
|
static opj_bool t1_decode_cblk_v2(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
opj_tcd_cblk_dec_v2_t* cblk,
|
opj_tcd_cblk_dec_v2_t* cblk,
|
||||||
OPJ_UINT32 orient,
|
OPJ_UINT32 orient,
|
||||||
|
@ -1393,7 +1394,7 @@ static void t1_encode_cblk(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void t1_decode_cblk(
|
static opj_bool t1_decode_cblk(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
opj_tcd_cblk_dec_t* cblk,
|
opj_tcd_cblk_dec_t* cblk,
|
||||||
int orient,
|
int orient,
|
||||||
|
@ -1435,7 +1436,9 @@ static void t1_decode_cblk(
|
||||||
if (type == T1_TYPE_RAW) {
|
if (type == T1_TYPE_RAW) {
|
||||||
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
|
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
|
||||||
} else {
|
} else {
|
||||||
mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
|
if (OPJ_FALSE == mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (passno = 0; passno < seg->numpasses; ++passno) {
|
for (passno = 0; passno < seg->numpasses; ++passno) {
|
||||||
|
@ -1479,6 +1482,7 @@ static void t1_decode_cblk(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
@ -1644,7 +1648,7 @@ void opj_t1_destroy(opj_t1_t *p_t1)
|
||||||
opj_free(p_t1);
|
opj_free(p_t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void opj_t1_decode_cblks( opj_t1_t* t1,
|
opj_bool opj_t1_decode_cblks( opj_t1_t* t1,
|
||||||
opj_tcd_tilecomp_v2_t* tilec,
|
opj_tcd_tilecomp_v2_t* tilec,
|
||||||
opj_tccp_t* tccp
|
opj_tccp_t* tccp
|
||||||
)
|
)
|
||||||
|
@ -1669,12 +1673,14 @@ void opj_t1_decode_cblks( opj_t1_t* t1,
|
||||||
OPJ_INT32 x, y;
|
OPJ_INT32 x, y;
|
||||||
OPJ_UINT32 i, j;
|
OPJ_UINT32 i, j;
|
||||||
|
|
||||||
t1_decode_cblk_v2(
|
if (OPJ_FALSE == t1_decode_cblk_v2(
|
||||||
t1,
|
t1,
|
||||||
cblk,
|
cblk,
|
||||||
band->bandno,
|
band->bandno,
|
||||||
tccp->roishift,
|
tccp->roishift,
|
||||||
tccp->cblksty);
|
tccp->cblksty)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
x = cblk->x0 - band->x0;
|
x = cblk->x0 - band->x0;
|
||||||
y = cblk->y0 - band->y0;
|
y = cblk->y0 - band->y0;
|
||||||
|
@ -1727,10 +1733,11 @@ void opj_t1_decode_cblks( opj_t1_t* t1,
|
||||||
} /* precno */
|
} /* precno */
|
||||||
} /* bandno */
|
} /* bandno */
|
||||||
} /* resno */
|
} /* resno */
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void t1_decode_cblk_v2(
|
static opj_bool t1_decode_cblk_v2(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
opj_tcd_cblk_dec_v2_t* cblk,
|
opj_tcd_cblk_dec_v2_t* cblk,
|
||||||
OPJ_UINT32 orient,
|
OPJ_UINT32 orient,
|
||||||
|
@ -1773,7 +1780,9 @@ static void t1_decode_cblk_v2(
|
||||||
if (type == T1_TYPE_RAW) {
|
if (type == T1_TYPE_RAW) {
|
||||||
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
|
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
|
||||||
} else {
|
} else {
|
||||||
mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
|
if (OPJ_FALSE == mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (passno = 0; passno < seg->real_num_passes; ++passno) {
|
for (passno = 0; passno < seg->real_num_passes; ++passno) {
|
||||||
|
@ -1801,6 +1810,7 @@ static void t1_decode_cblk_v2(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
opj_bool opj_t1_encode_cblks( opj_t1_t *t1,
|
opj_bool opj_t1_encode_cblks( opj_t1_t *t1,
|
||||||
|
|
|
@ -131,7 +131,7 @@ Decode the code-blocks of a tile
|
||||||
@param tilec The tile to decode
|
@param tilec The tile to decode
|
||||||
@param tccp Tile coding parameters
|
@param tccp Tile coding parameters
|
||||||
*/
|
*/
|
||||||
void opj_t1_decode_cblks( opj_t1_t* t1,
|
opj_bool opj_t1_decode_cblks( opj_t1_t* t1,
|
||||||
opj_tcd_tilecomp_v2_t* tilec,
|
opj_tcd_tilecomp_v2_t* tilec,
|
||||||
opj_tccp_t* tccp);
|
opj_tccp_t* tccp);
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ static opj_bool t2_encode_packet_v2(
|
||||||
@param cblksty
|
@param cblksty
|
||||||
@param first
|
@param first
|
||||||
*/
|
*/
|
||||||
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
|
static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
|
||||||
/**
|
/**
|
||||||
Decode a packet of a tile from a source buffer
|
Decode a packet of a tile from a source buffer
|
||||||
@param t2 T2 handle
|
@param t2 T2 handle
|
||||||
|
@ -389,9 +389,16 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
|
||||||
return (c - dest);
|
return (c - dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
|
static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
|
||||||
opj_tcd_seg_t* seg;
|
opj_tcd_seg_t* seg;
|
||||||
cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
|
opj_tcd_seg_t* new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
|
||||||
|
if (!new_segs) {
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to init segment #%d\n", index); */
|
||||||
|
// TODO: tell cblk has no segment (in order to update the range of valid indices)
|
||||||
|
cblk->segs = NULL;
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
cblk->segs = new_segs;
|
||||||
seg = &cblk->segs[index];
|
seg = &cblk->segs[index];
|
||||||
seg->data = NULL;
|
seg->data = NULL;
|
||||||
seg->dataindex = 0;
|
seg->dataindex = 0;
|
||||||
|
@ -409,6 +416,7 @@ static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int fi
|
||||||
} else {
|
} else {
|
||||||
seg->maxpasses = 109;
|
seg->maxpasses = 109;
|
||||||
}
|
}
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
||||||
|
@ -555,12 +563,20 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
||||||
cblk->numlenbits += increment;
|
cblk->numlenbits += increment;
|
||||||
segno = 0;
|
segno = 0;
|
||||||
if (!cblk->numsegs) {
|
if (!cblk->numsegs) {
|
||||||
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1);
|
if (OPJ_FALSE == t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1)) {
|
||||||
|
// TODO: LH: shall we destroy bio here ?
|
||||||
|
opj_event_msg(t2->cinfo, EVT_WARNING, "Not enough memory to init segment #%d\n", segno);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
segno = cblk->numsegs - 1;
|
segno = cblk->numsegs - 1;
|
||||||
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
|
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
|
||||||
++segno;
|
++segno;
|
||||||
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
|
if (OPJ_FALSE == t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) {
|
||||||
|
// TODO: LH: shall we destroy bio here ?
|
||||||
|
opj_event_msg(t2->cinfo, EVT_WARNING, "Not enough memory to init segment #%d\n", segno);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = cblk->numnewpasses;
|
n = cblk->numnewpasses;
|
||||||
|
@ -571,7 +587,11 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
||||||
n -= cblk->segs[segno].numnewpasses;
|
n -= cblk->segs[segno].numnewpasses;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
++segno;
|
++segno;
|
||||||
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
|
if (OPJ_FALSE == t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) {
|
||||||
|
// TODO: LH: shall we destroy bio here ?
|
||||||
|
opj_event_msg(t2->cinfo, EVT_WARNING, "Not enough memory to init segment #%d\n", segno);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (n > 0);
|
} while (n > 0);
|
||||||
}
|
}
|
||||||
|
@ -661,7 +681,16 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
||||||
|
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char));
|
unsigned char * new_data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char));
|
||||||
|
if (! new_data) {
|
||||||
|
opj_event_msg(t2->cinfo, EVT_ERROR, "JPWL: Not enough memory for codeblock data %d (p=%d, b=%d, r=%d, c=%d)\n",
|
||||||
|
seg->newlen, cblkno, precno, bandno, resno, compno);
|
||||||
|
cblk->data = 0;
|
||||||
|
cblk->len = 0; // TODO: LH: other things to reset ?
|
||||||
|
opj_free(cblk->data);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
|
cblk->data = new_data;
|
||||||
memcpy(cblk->data + cblk->len, c, seg->newlen);
|
memcpy(cblk->data + cblk->len, c, seg->newlen);
|
||||||
if (seg->numpasses == 0) {
|
if (seg->numpasses == 0) {
|
||||||
seg->data = &cblk->data;
|
seg->data = &cblk->data;
|
||||||
|
@ -1930,10 +1959,15 @@ static opj_bool t2_init_seg_v2(opj_tcd_cblk_dec_v2_t* cblk, OPJ_UINT32 index, OP
|
||||||
if (l_nb_segs > cblk->m_current_max_segs) {
|
if (l_nb_segs > cblk->m_current_max_segs) {
|
||||||
cblk->m_current_max_segs += J2K_DEFAULT_NB_SEGS;
|
cblk->m_current_max_segs += J2K_DEFAULT_NB_SEGS;
|
||||||
|
|
||||||
cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
|
opj_tcd_seg_t* new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
|
||||||
if(! cblk->segs) {
|
if(! new_segs) {
|
||||||
|
opj_free(cblk->segs);
|
||||||
|
cblk->segs = NULL;
|
||||||
|
cblk->m_current_max_segs = 0;
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to initialize segment %d\n", l_nb_segs); */
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
cblk->segs = new_segs;
|
||||||
}
|
}
|
||||||
|
|
||||||
seg = &cblk->segs[index];
|
seg = &cblk->segs[index];
|
||||||
|
|
|
@ -615,7 +615,7 @@ void opj_tcd_destroy(opj_tcd_v2_t *tcd) {
|
||||||
* @return true if the encoding values could be set (false otherwise).
|
* @return true if the encoding values could be set (false otherwise).
|
||||||
*/
|
*/
|
||||||
#define MACRO_TCD_ALLOCATE(FUNCTION,TYPE,FRACTION,ELEMENT,FUNCTION_ELEMENT) \
|
#define MACRO_TCD_ALLOCATE(FUNCTION,TYPE,FRACTION,ELEMENT,FUNCTION_ELEMENT) \
|
||||||
opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
OPJ_UINT32 p_tile_no \
|
OPJ_UINT32 p_tile_no \
|
||||||
) \
|
) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -668,7 +668,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
l_tile->y0 = int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \
|
l_tile->y0 = int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \
|
||||||
l_tile->x1 = int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \
|
l_tile->x1 = int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \
|
||||||
l_tile->y1 = int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \
|
l_tile->y1 = int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \
|
||||||
/*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,l_tile->x1,l_tile->y1);*/\
|
/*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,l_tile->x1,l_tile->y1);*/ \
|
||||||
\
|
\
|
||||||
/*tile->numcomps = image->numcomps; */ \
|
/*tile->numcomps = image->numcomps; */ \
|
||||||
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
|
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
|
||||||
|
@ -679,7 +679,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
l_tilec->y0 = int_ceildiv(l_tile->y0, l_image_comp->dy); \
|
l_tilec->y0 = int_ceildiv(l_tile->y0, l_image_comp->dy); \
|
||||||
l_tilec->x1 = int_ceildiv(l_tile->x1, l_image_comp->dx); \
|
l_tilec->x1 = int_ceildiv(l_tile->x1, l_image_comp->dx); \
|
||||||
l_tilec->y1 = int_ceildiv(l_tile->y1, l_image_comp->dy); \
|
l_tilec->y1 = int_ceildiv(l_tile->y1, l_image_comp->dy); \
|
||||||
/*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/\
|
/*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/ \
|
||||||
\
|
\
|
||||||
l_data_size = (l_tilec->x1 - l_tilec->x0) \
|
l_data_size = (l_tilec->x1 - l_tilec->x0) \
|
||||||
* (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 ); \
|
* (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 ); \
|
||||||
|
@ -702,10 +702,16 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
l_tilec->data_size = l_data_size; \
|
l_tilec->data_size = l_data_size; \
|
||||||
} \
|
} \
|
||||||
else if (l_data_size > l_tilec->data_size) { \
|
else if (l_data_size > l_tilec->data_size) { \
|
||||||
l_tilec->data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_data_size); \
|
OPJ_INT32 * new_data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_data_size); \
|
||||||
if (! l_tilec->data) { \
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle tile data\n"); */ \
|
||||||
|
fprintf(stderr, "Not enough memory to handle tile data\n"); \
|
||||||
|
if (! new_data) { \
|
||||||
|
opj_free(l_tilec->data); \
|
||||||
|
l_tilec->data = NULL; \
|
||||||
|
l_tilec->data_size = 0; \
|
||||||
return OPJ_FALSE; \
|
return OPJ_FALSE; \
|
||||||
} \
|
} \
|
||||||
|
l_tilec->data = new_data; \
|
||||||
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->data_size, l_data_size);*/ \
|
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->data_size, l_data_size);*/ \
|
||||||
l_tilec->data_size = l_data_size; \
|
l_tilec->data_size = l_data_size; \
|
||||||
} \
|
} \
|
||||||
|
@ -722,10 +728,16 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
memset(l_tilec->resolutions,0,l_data_size); \
|
memset(l_tilec->resolutions,0,l_data_size); \
|
||||||
} \
|
} \
|
||||||
else if (l_data_size > l_tilec->resolutions_size) { \
|
else if (l_data_size > l_tilec->resolutions_size) { \
|
||||||
l_tilec->resolutions = (opj_tcd_resolution_v2_t *) opj_realloc(l_tilec->resolutions, l_data_size); \
|
opj_tcd_resolution_v2_t* new_resolutions = (opj_tcd_resolution_v2_t *) opj_realloc(l_tilec->resolutions, l_data_size); \
|
||||||
if (! l_tilec->resolutions) { \
|
if (! new_resolutions) { \
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to tile resolutions\n"); */ \
|
||||||
|
fprintf(stderr, "Not enough memory to tile resolutions\n"); \
|
||||||
|
opj_free(l_tilec->resolutions); \
|
||||||
|
l_tilec->resolutions = NULL; \
|
||||||
|
l_tilec->resolutions_size = 0; \
|
||||||
return OPJ_FALSE; \
|
return OPJ_FALSE; \
|
||||||
} \
|
} \
|
||||||
|
l_tilec->resolutions = new_resolutions; \
|
||||||
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ \
|
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ \
|
||||||
memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resolutions_size,0,l_data_size - l_tilec->resolutions_size); \
|
memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resolutions_size,0,l_data_size - l_tilec->resolutions_size); \
|
||||||
l_tilec->resolutions_size = l_data_size; \
|
l_tilec->resolutions_size = l_data_size; \
|
||||||
|
@ -795,7 +807,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
l_band = l_res->bands; \
|
l_band = l_res->bands; \
|
||||||
\
|
\
|
||||||
for (bandno = 0; bandno < l_res->numbands; ++bandno) { \
|
for (bandno = 0; bandno < l_res->numbands; ++bandno) { \
|
||||||
OPJ_INT32 numbps;\
|
OPJ_INT32 numbps; \
|
||||||
/*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandno, l_res->numbands );*/ \
|
/*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandno, l_res->numbands );*/ \
|
||||||
\
|
\
|
||||||
if (resno == 0) { \
|
if (resno == 0) { \
|
||||||
|
@ -821,11 +833,11 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
/** avoid an if with storing function pointer */ \
|
/** avoid an if with storing function pointer */ \
|
||||||
l_gain = (*l_gain_ptr) (l_band->bandno); \
|
l_gain = (*l_gain_ptr) (l_band->bandno); \
|
||||||
numbps = l_image_comp->prec + l_gain; \
|
numbps = l_image_comp->prec + l_gain; \
|
||||||
l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * FRACTION;\
|
l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * FRACTION; \
|
||||||
l_band->numbps = l_step_size->expn + l_tccp->numgbits - 1; /* WHY -1 ? */\
|
l_band->numbps = l_step_size->expn + l_tccp->numgbits - 1; /* WHY -1 ? */ \
|
||||||
\
|
\
|
||||||
if (! l_band->precincts) { \
|
if (! l_band->precincts) { \
|
||||||
l_band->precincts = (opj_tcd_precinct_v2_t *) opj_malloc( /*3 * */ l_nb_precinct_size);\
|
l_band->precincts = (opj_tcd_precinct_v2_t *) opj_malloc( /*3 * */ l_nb_precinct_size); \
|
||||||
if (! l_band->precincts) { \
|
if (! l_band->precincts) { \
|
||||||
return OPJ_FALSE; \
|
return OPJ_FALSE; \
|
||||||
} \
|
} \
|
||||||
|
@ -835,12 +847,18 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
} \
|
} \
|
||||||
else if (l_band->precincts_data_size < l_nb_precinct_size) { \
|
else if (l_band->precincts_data_size < l_nb_precinct_size) { \
|
||||||
\
|
\
|
||||||
l_band->precincts = (opj_tcd_precinct_v2_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);\
|
opj_tcd_precinct_v2_t * new_precincts = (opj_tcd_precinct_v2_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size); \
|
||||||
if (! l_band->precincts) { \
|
if (! new_precincts) { \
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle band precints\n"); */ \
|
||||||
|
fprintf(stderr, "Not enough memory to handle band precints\n"); \
|
||||||
|
opj_free(l_band->precincts); \
|
||||||
|
l_band->precincts = NULL; \
|
||||||
|
l_band->precincts_data_size = 0; \
|
||||||
return OPJ_FALSE; \
|
return OPJ_FALSE; \
|
||||||
} \
|
} \
|
||||||
/*fprintf(stderr, "\t\t\t\tReallocate precincts of a band (opj_tcd_precinct_v2_t): from %d to %d\n",l_band->precincts_data_size, l_nb_precinct_size);*/\
|
l_band->precincts = new_precincts; \
|
||||||
memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size);\
|
/*fprintf(stderr, "\t\t\t\tReallocate precincts of a band (opj_tcd_precinct_v2_t): from %d to %d\n",l_band->precincts_data_size, l_nb_precinct_size);*/ \
|
||||||
|
memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size); \
|
||||||
l_band->precincts_data_size = l_nb_precinct_size; \
|
l_band->precincts_data_size = l_nb_precinct_size; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -851,8 +869,8 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn); \
|
OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn); \
|
||||||
OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \
|
OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \
|
||||||
OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \
|
OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \
|
||||||
/*fprintf(stderr, "\t precno=%d; bandno=%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/\
|
/*fprintf(stderr, "\t precno=%d; bandno=%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/ \
|
||||||
/*fprintf(stderr, "\t tlcbgxstart(=%d) + (precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,precno,l_res->pw,cbgwidthexpn);*/\
|
/*fprintf(stderr, "\t tlcbgxstart(=%d) + (precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,precno,l_res->pw,cbgwidthexpn);*/ \
|
||||||
\
|
\
|
||||||
/* precinct size (global) */ \
|
/* precinct size (global) */ \
|
||||||
/*fprintf(stderr, "\t cbgxstart=%d, l_band->x0 = %d \n",cbgxstart, l_band->x0);*/ \
|
/*fprintf(stderr, "\t cbgxstart=%d, l_band->x0 = %d \n",cbgxstart, l_band->x0);*/ \
|
||||||
|
@ -879,23 +897,28 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE); \
|
l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE); \
|
||||||
\
|
\
|
||||||
if (! l_current_precinct->cblks.ELEMENT) { \
|
if (! l_current_precinct->cblks.ELEMENT) { \
|
||||||
l_current_precinct->cblks.ELEMENT = (TYPE*) opj_malloc(l_nb_code_blocks_size);\
|
l_current_precinct->cblks.ELEMENT = (TYPE*) opj_malloc(l_nb_code_blocks_size); \
|
||||||
if (! l_current_precinct->cblks.ELEMENT ) { \
|
if (! l_current_precinct->cblks.ELEMENT ) { \
|
||||||
return OPJ_FALSE; \
|
return OPJ_FALSE; \
|
||||||
} \
|
} \
|
||||||
/*fprintf(stderr, "\t\t\t\tAllocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): %d\n",l_nb_code_blocks_size);*/ \
|
/*fprintf(stderr, "\t\t\t\tAllocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): %d\n",l_nb_code_blocks_size);*/ \
|
||||||
\
|
\
|
||||||
memset(l_current_precinct->cblks.ELEMENT,0,l_nb_code_blocks_size);\
|
memset(l_current_precinct->cblks.ELEMENT,0,l_nb_code_blocks_size); \
|
||||||
\
|
\
|
||||||
l_current_precinct->block_size = l_nb_code_blocks_size; \
|
l_current_precinct->block_size = l_nb_code_blocks_size; \
|
||||||
} \
|
} \
|
||||||
else if (l_nb_code_blocks_size > l_current_precinct->block_size) { \
|
else if (l_nb_code_blocks_size > l_current_precinct->block_size) { \
|
||||||
l_current_precinct->cblks.ELEMENT = (TYPE*) \
|
TYPE *new_ELEMENT = (TYPE*) opj_realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size); \
|
||||||
opj_realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size); \
|
if (! new_ELEMENT) { \
|
||||||
if (! l_current_precinct->cblks.ELEMENT ) { \
|
opj_free(l_current_precinct->cblks.ELEMENT); \
|
||||||
|
l_current_precinct->cblks.ELEMENT = NULL; \
|
||||||
|
l_current_precinct->block_size = 0; \
|
||||||
|
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory for current precinct codeblock element\n"); */ \
|
||||||
|
fprintf(stderr, "Not enough memory for current precinct codeblock element\n"); \
|
||||||
return OPJ_FALSE; \
|
return OPJ_FALSE; \
|
||||||
} \
|
} \
|
||||||
/*fprintf(stderr, "\t\t\t\tReallocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): from %d to %d\n",l_current_precinct->block_size, l_nb_code_blocks_size); */ \
|
l_current_precinct->cblks.ELEMENT = new_ELEMENT; \
|
||||||
|
/*fprintf(stderr, "\t\t\t\tReallocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): from %d to %d\n",l_current_precinct->block_size, l_nb_code_blocks_size); */\
|
||||||
\
|
\
|
||||||
memset(((OPJ_BYTE *) l_current_precinct->cblks.ELEMENT) + l_current_precinct->block_size \
|
memset(((OPJ_BYTE *) l_current_precinct->cblks.ELEMENT) + l_current_precinct->block_size \
|
||||||
,0 \
|
,0 \
|
||||||
|
@ -915,14 +938,14 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if (! l_current_precinct->incltree) { \
|
if (! l_current_precinct->incltree) { \
|
||||||
fprintf(stderr, "WARNING: No incltree created.\n");\
|
fprintf(stderr, "WARNING: No incltree created.\n"); \
|
||||||
/*return OPJ_FALSE;*/ \
|
/*return OPJ_FALSE;*/ \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if (! l_current_precinct->imsbtree) { \
|
if (! l_current_precinct->imsbtree) { \
|
||||||
l_current_precinct->imsbtree = tgt_create_v2( \
|
l_current_precinct->imsbtree = tgt_create_v2( \
|
||||||
l_current_precinct->cw, \
|
l_current_precinct->cw, \
|
||||||
l_current_precinct->ch);\
|
l_current_precinct->ch); \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
l_current_precinct->imsbtree = tgt_init( \
|
l_current_precinct->imsbtree = tgt_init( \
|
||||||
|
@ -932,7 +955,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if (! l_current_precinct->imsbtree) { \
|
if (! l_current_precinct->imsbtree) { \
|
||||||
fprintf(stderr, "WARNING: No imsbtree created.\n");\
|
fprintf(stderr, "WARNING: No imsbtree created.\n"); \
|
||||||
/*return OPJ_FALSE;*/ \
|
/*return OPJ_FALSE;*/ \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -942,7 +965,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
|
||||||
OPJ_INT32 cblkxstart = tlcblkxstart + (cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \
|
OPJ_INT32 cblkxstart = tlcblkxstart + (cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \
|
||||||
OPJ_INT32 cblkystart = tlcblkystart + (cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \
|
OPJ_INT32 cblkystart = tlcblkystart + (cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \
|
||||||
OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
|
OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
|
||||||
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn);\
|
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
|
||||||
\
|
\
|
||||||
/* code-block size (global) */ \
|
/* code-block size (global) */ \
|
||||||
l_code_block->x0 = int_max(cblkxstart, l_current_precinct->x0); \
|
l_code_block->x0 = int_max(cblkxstart, l_current_precinct->x0); \
|
||||||
|
@ -1487,7 +1510,10 @@ opj_bool opj_tcd_t1_decode ( opj_tcd_v2_t *p_tcd )
|
||||||
|
|
||||||
for (compno = 0; compno < l_tile->numcomps; ++compno) {
|
for (compno = 0; compno < l_tile->numcomps; ++compno) {
|
||||||
/* The +3 is headroom required by the vectorized DWT */
|
/* The +3 is headroom required by the vectorized DWT */
|
||||||
opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp);
|
if (OPJ_FALSE == opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp)) {
|
||||||
|
opj_t1_destroy(l_t1);
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
++l_tile_comp;
|
++l_tile_comp;
|
||||||
++l_tccp;
|
++l_tccp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,13 +244,15 @@ opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_U
|
||||||
if
|
if
|
||||||
(l_node_size > p_tree->nodes_size)
|
(l_node_size > p_tree->nodes_size)
|
||||||
{
|
{
|
||||||
p_tree->nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
|
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
|
||||||
if
|
if
|
||||||
(! p_tree->nodes)
|
(! p_tree->nodes)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "Not enough memory to reinitialize the tag tree\n");
|
||||||
tgt_destroy(p_tree);
|
tgt_destroy(p_tree);
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
|
p_tree->nodes = new_nodes;
|
||||||
memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
|
memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
|
||||||
p_tree->nodes_size = l_node_size;
|
p_tree->nodes_size = l_node_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,36 +137,36 @@ static int infile_format(const char *fname)
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
sample error callback expecting a FILE* client object
|
sample error callback expecting a FILE* client object
|
||||||
*/
|
*/
|
||||||
void error_callback_file(const char *msg, void *client_data) {
|
void error_callback_file(const char *msg, void *client_data) {
|
||||||
FILE *stream = (FILE*)client_data;
|
FILE *stream = (FILE*)client_data;
|
||||||
fprintf(stream, "[ERROR] %s", msg);
|
fprintf(stream, "[ERROR] %s", msg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
sample warning callback expecting a FILE* client object
|
sample warning callback expecting a FILE* client object
|
||||||
*/
|
*/
|
||||||
void warning_callback_file(const char *msg, void *client_data) {
|
void warning_callback_file(const char *msg, void *client_data) {
|
||||||
FILE *stream = (FILE*)client_data;
|
FILE *stream = (FILE*)client_data;
|
||||||
fprintf(stream, "[WARNING] %s", msg);
|
fprintf(stream, "[WARNING] %s", msg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
sample error debug callback expecting no client object
|
sample error debug callback expecting no client object
|
||||||
*/
|
*/
|
||||||
void error_callback(const char *msg, void *client_data) {
|
void error_callback(const char *msg, void *client_data) {
|
||||||
(void)client_data;
|
(void)client_data;
|
||||||
fprintf(stdout, "[ERROR] %s", msg);
|
fprintf(stdout, "[ERROR] %s", msg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
sample warning debug callback expecting no client object
|
sample warning debug callback expecting no client object
|
||||||
*/
|
*/
|
||||||
void warning_callback(const char *msg, void *client_data) {
|
void warning_callback(const char *msg, void *client_data) {
|
||||||
(void)client_data;
|
(void)client_data;
|
||||||
fprintf(stdout, "[WARNING] %s", msg);
|
fprintf(stdout, "[WARNING] %s", msg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
sample debug callback expecting no client object
|
sample debug callback expecting no client object
|
||||||
*/
|
*/
|
||||||
void info_callback(const char *msg, void *client_data) {
|
void info_callback(const char *msg, void *client_data) {
|
||||||
(void)client_data;
|
(void)client_data;
|
||||||
fprintf(stdout, "[INFO] %s", msg);
|
fprintf(stdout, "[INFO] %s", msg);
|
||||||
|
@ -338,15 +338,17 @@ int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (l_data_size > l_max_data_size)
|
if (l_data_size > l_max_data_size)
|
||||||
{
|
{
|
||||||
l_data = (OPJ_BYTE *) realloc(l_data,l_data_size);
|
OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size);
|
||||||
if (! l_data)
|
if (! l_new_data)
|
||||||
{
|
{
|
||||||
fclose(l_file);
|
fclose(l_file);
|
||||||
|
free(l_new_data);
|
||||||
opj_stream_destroy(l_stream);
|
opj_stream_destroy(l_stream);
|
||||||
opj_destroy_codec(l_codec);
|
opj_destroy_codec(l_codec);
|
||||||
opj_image_destroy(l_image);
|
opj_image_destroy(l_image);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
l_data = l_new_data;
|
||||||
l_max_data_size = l_data_size;
|
l_max_data_size = l_data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,3 +387,4 @@ int main (int argc, char *argv[])
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue