[trunk] WIP: correct some memory leaks in applications functions
This commit is contained in:
parent
195190b612
commit
27e255fa75
1
CHANGES
1
CHANGES
|
@ -6,6 +6,7 @@ What's New for OpenJPEG
|
||||||
+ : added
|
+ : added
|
||||||
|
|
||||||
October 12, 2011
|
October 12, 2011
|
||||||
|
* [mickael] WIP: correct some memory leaks in applications functions
|
||||||
+ [mickael] WIP: add a read CBD marker function (JPEG2000 part 2)
|
+ [mickael] WIP: add a read CBD marker function (JPEG2000 part 2)
|
||||||
+ [mickael] WIP: add a read MCO marker function (JPEG2000 part 2)
|
+ [mickael] WIP: add a read MCO marker function (JPEG2000 part 2)
|
||||||
+ [mickael] WIP: add a read MCC marker function (JPEG2000 part 2)
|
+ [mickael] WIP: add a read MCC marker function (JPEG2000 part 2)
|
||||||
|
|
|
@ -372,19 +372,21 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
opj_dparameters_t parameters; /* Decompression parameters */
|
opj_dparameters_t parameters; /* Decompression parameters */
|
||||||
opj_event_mgr_t event_mgr; /* Event manager */
|
opj_event_mgr_t event_mgr; /* Event manager */
|
||||||
opj_image_t image; /* Image structure */
|
opj_image_t* image = NULL; /* Image structure */
|
||||||
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
|
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
|
||||||
opj_stream_t *cio = NULL; /* Stream */
|
opj_stream_t *cio = NULL; /* Stream */
|
||||||
opj_codestream_info_v2_t* cstr_info;
|
opj_codestream_info_v2_t* cstr_info = NULL;
|
||||||
opj_codestream_index_t* cstr_index;
|
opj_codestream_index_t* cstr_index = NULL;
|
||||||
|
|
||||||
OPJ_INT32 num_images, imageno;
|
OPJ_INT32 num_images, imageno;
|
||||||
img_fol_t img_fol;
|
img_fol_t img_fol;
|
||||||
dircnt_t *dirptr = NULL;
|
dircnt_t *dirptr = NULL;
|
||||||
|
|
||||||
|
#ifdef MSD
|
||||||
opj_bool l_go_on = OPJ_TRUE;
|
opj_bool l_go_on = OPJ_TRUE;
|
||||||
OPJ_UINT32 l_max_data_size = 1000;
|
OPJ_UINT32 l_max_data_size = 1000;
|
||||||
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
|
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Set decoding parameters to default values */
|
/* Set decoding parameters to default values */
|
||||||
opj_set_default_decoder_parameters(¶meters);
|
opj_set_default_decoder_parameters(¶meters);
|
||||||
|
@ -512,6 +514,7 @@ int main(int argc, char *argv[])
|
||||||
opj_stream_destroy(cio);
|
opj_stream_destroy(cio);
|
||||||
fclose(fsrc);
|
fclose(fsrc);
|
||||||
opj_destroy_codec(dinfo);
|
opj_destroy_codec(dinfo);
|
||||||
|
opj_image_destroy(image);
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -603,7 +606,13 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* destroy the image header */
|
/* destroy the image header */
|
||||||
opj_image_destroy(&image);
|
opj_image_destroy(image);
|
||||||
|
|
||||||
|
/* destroy the codestream index */
|
||||||
|
opj_destroy_cstr_index(&cstr_index);
|
||||||
|
|
||||||
|
/* destroy the codestream info */
|
||||||
|
opj_destroy_cstr_info_v2(&cstr_info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -576,7 +576,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
opj_dparameters_t parameters; /* decompression parameters */
|
opj_dparameters_t parameters; /* decompression parameters */
|
||||||
opj_event_mgr_t event_mgr; /* event manager */
|
opj_event_mgr_t event_mgr; /* event manager */
|
||||||
opj_image_t image;
|
opj_image_t* image = NULL;
|
||||||
opj_stream_t *cio = NULL; /* Stream */
|
opj_stream_t *cio = NULL; /* Stream */
|
||||||
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
|
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
|
||||||
|
|
||||||
|
@ -712,7 +712,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the decoded image */
|
/* Get the decoded image */
|
||||||
if ( !( opj_decode_v2(dinfo, cio, &image) && opj_end_decompress(dinfo,cio) ) ) {
|
if ( !( opj_decode_v2(dinfo, cio, image) && opj_end_decompress(dinfo,cio) ) ) {
|
||||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||||
opj_destroy_codec(dinfo);
|
opj_destroy_codec(dinfo);
|
||||||
opj_stream_destroy(cio);
|
opj_stream_destroy(cio);
|
||||||
|
@ -725,23 +725,23 @@ int main(int argc, char **argv)
|
||||||
fclose(fsrc);
|
fclose(fsrc);
|
||||||
|
|
||||||
|
|
||||||
if(image.color_space == CLRSPC_SYCC){
|
if(image->color_space == CLRSPC_SYCC){
|
||||||
color_sycc_to_rgb(&image); /* FIXME */
|
color_sycc_to_rgb(image); /* FIXME */
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image.icc_profile_buf) {
|
if(image->icc_profile_buf) {
|
||||||
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
|
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
|
||||||
color_apply_icc_profile(&image); /* FIXME */
|
color_apply_icc_profile(image); /* FIXME */
|
||||||
#endif
|
#endif
|
||||||
free(image.icc_profile_buf);
|
free(image->icc_profile_buf);
|
||||||
image.icc_profile_buf = NULL; image.icc_profile_len = 0;
|
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create output image */
|
/* create output image */
|
||||||
/* ------------------- */
|
/* ------------------- */
|
||||||
switch (parameters.cod_format) {
|
switch (parameters.cod_format) {
|
||||||
case PXM_DFMT: /* PNM PGM PPM */
|
case PXM_DFMT: /* PNM PGM PPM */
|
||||||
if (imagetopnm(&image, parameters.outfile)) {
|
if (imagetopnm(image, parameters.outfile)) {
|
||||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -750,7 +750,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PGX_DFMT: /* PGX */
|
case PGX_DFMT: /* PGX */
|
||||||
if(imagetopgx(&image, parameters.outfile)){
|
if(imagetopgx(image, parameters.outfile)){
|
||||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -759,7 +759,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BMP_DFMT: /* BMP */
|
case BMP_DFMT: /* BMP */
|
||||||
if(imagetobmp(&image, parameters.outfile)){
|
if(imagetobmp(image, parameters.outfile)){
|
||||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -768,7 +768,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_LIBTIFF
|
#ifdef HAVE_LIBTIFF
|
||||||
case TIF_DFMT: /* TIFF */
|
case TIF_DFMT: /* TIFF */
|
||||||
if(imagetotif(&image, parameters.outfile)){
|
if(imagetotif(image, parameters.outfile)){
|
||||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -777,7 +777,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
#endif /* HAVE_LIBTIFF */
|
#endif /* HAVE_LIBTIFF */
|
||||||
case RAW_DFMT: /* RAW */
|
case RAW_DFMT: /* RAW */
|
||||||
if(imagetoraw(&image, parameters.outfile)){
|
if(imagetoraw(image, parameters.outfile)){
|
||||||
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -786,7 +786,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TGA_DFMT: /* TGA */
|
case TGA_DFMT: /* TGA */
|
||||||
if(imagetotga(&image, parameters.outfile)){
|
if(imagetotga(image, parameters.outfile)){
|
||||||
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -795,7 +795,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_LIBPNG
|
#ifdef HAVE_LIBPNG
|
||||||
case PNG_DFMT: /* PNG */
|
case PNG_DFMT: /* PNG */
|
||||||
if(imagetopng(&image, parameters.outfile)){
|
if(imagetopng(image, parameters.outfile)){
|
||||||
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
|
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -817,10 +817,10 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
/* free image data structure */
|
/* free image data structure */
|
||||||
opj_image_destroy(&image);
|
opj_image_destroy(image);
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
//end main
|
//end main
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
|
||||||
if(image) {
|
if(image) {
|
||||||
if(image->comps) {
|
if(image->comps) {
|
||||||
OPJ_UINT32 compno;
|
OPJ_UINT32 compno;
|
||||||
|
|
||||||
/* image components */
|
/* image components */
|
||||||
for(compno = 0; compno < image->numcomps; compno++) {
|
for(compno = 0; compno < image->numcomps; compno++) {
|
||||||
opj_image_comp_t *image_comp = &(image->comps[compno]);
|
opj_image_comp_t *image_comp = &(image->comps[compno]);
|
||||||
|
@ -87,7 +88,8 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
|
||||||
if(image->icc_profile_buf) {
|
if(image->icc_profile_buf) {
|
||||||
opj_free(image->icc_profile_buf);
|
opj_free(image->icc_profile_buf);
|
||||||
}
|
}
|
||||||
//FIXME opj_free(image);
|
|
||||||
|
opj_free(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -776,7 +776,7 @@ static opj_bool j2k_read_cbd ( opj_j2k_v2_t *p_j2k,
|
||||||
*
|
*
|
||||||
* @return true if the image header is correctly copy.
|
* @return true if the image header is correctly copy.
|
||||||
*/
|
*/
|
||||||
static opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_t* p_image);
|
static opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_t** p_image);
|
||||||
|
|
||||||
|
|
||||||
static void j2k_dump_MH_info(opj_j2k_v2_t* p_j2k, FILE* out_stream);
|
static void j2k_dump_MH_info(opj_j2k_v2_t* p_j2k, FILE* out_stream);
|
||||||
|
@ -5796,13 +5796,12 @@ opj_bool j2k_end_decompress(
|
||||||
*/
|
*/
|
||||||
opj_bool j2k_read_header( struct opj_stream_private *p_stream,
|
opj_bool j2k_read_header( struct opj_stream_private *p_stream,
|
||||||
opj_j2k_v2_t* p_j2k,
|
opj_j2k_v2_t* p_j2k,
|
||||||
opj_image_t* p_image,
|
opj_image_t** p_image,
|
||||||
struct opj_event_mgr* p_manager )
|
struct opj_event_mgr* p_manager )
|
||||||
{
|
{
|
||||||
/* preconditions */
|
/* preconditions */
|
||||||
assert(p_j2k != 00);
|
assert(p_j2k != 00);
|
||||||
assert(p_stream != 00);
|
assert(p_stream != 00);
|
||||||
assert(p_image != 00);
|
|
||||||
assert(p_manager != 00);
|
assert(p_manager != 00);
|
||||||
|
|
||||||
/* create an empty image header */
|
/* create an empty image header */
|
||||||
|
@ -5831,6 +5830,11 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream,
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*p_image = opj_image_create0();
|
||||||
|
if (! (*p_image)) {
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (! j2k_copy_img_header(p_j2k, p_image)){
|
if (! j2k_copy_img_header(p_j2k, p_image)){
|
||||||
opj_image_destroy(p_j2k->m_image);
|
opj_image_destroy(p_j2k->m_image);
|
||||||
p_j2k->m_image = NULL;
|
p_j2k->m_image = NULL;
|
||||||
|
@ -5841,42 +5845,41 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream,
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_t* p_image)
|
opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_t** p_image)
|
||||||
{
|
{
|
||||||
OPJ_UINT16 compno;
|
OPJ_UINT16 compno;
|
||||||
|
|
||||||
/* preconditions */
|
/* preconditions */
|
||||||
assert(p_j2k != 00);
|
assert(p_j2k != 00);
|
||||||
assert(p_image != 00);
|
|
||||||
|
|
||||||
p_image->x0 = p_j2k->m_image->x0;
|
(*p_image)->x0 = p_j2k->m_image->x0;
|
||||||
p_image->y0 = p_j2k->m_image->y0;
|
(*p_image)->y0 = p_j2k->m_image->y0;
|
||||||
p_image->x1 = p_j2k->m_image->x1;
|
(*p_image)->x1 = p_j2k->m_image->x1;
|
||||||
p_image->y1 = p_j2k->m_image->y1;
|
(*p_image)->y1 = p_j2k->m_image->y1;
|
||||||
|
|
||||||
p_image->numcomps = p_j2k->m_image->numcomps;
|
(*p_image)->numcomps = p_j2k->m_image->numcomps;
|
||||||
p_image->comps = (opj_image_comp_t*)opj_malloc(p_image->numcomps * sizeof(opj_image_comp_t));
|
(*p_image)->comps = (opj_image_comp_t*)opj_malloc((*p_image)->numcomps * sizeof(opj_image_comp_t));
|
||||||
if (!p_image->comps)
|
if (!(*p_image)->comps)
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
for (compno=0; compno < p_image->numcomps; compno++){
|
for (compno=0; compno < (*p_image)->numcomps; compno++){
|
||||||
memcpy( &(p_image->comps[compno]),
|
memcpy( &((*p_image)->comps[compno]),
|
||||||
&(p_j2k->m_image->comps[compno]),
|
&(p_j2k->m_image->comps[compno]),
|
||||||
sizeof(opj_image_comp_t));
|
sizeof(opj_image_comp_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
p_image->color_space = p_j2k->m_image->color_space;
|
(*p_image)->color_space = p_j2k->m_image->color_space;
|
||||||
p_image->icc_profile_len = p_j2k->m_image->icc_profile_len;
|
(*p_image)->icc_profile_len = p_j2k->m_image->icc_profile_len;
|
||||||
if (!p_image->icc_profile_len) {
|
if (!(*p_image)->icc_profile_len) {
|
||||||
|
|
||||||
p_image->icc_profile_buf = (unsigned char*)opj_malloc(p_image->icc_profile_len);
|
(*p_image)->icc_profile_buf = (unsigned char*)opj_malloc((*p_image)->icc_profile_len);
|
||||||
if (!p_image->icc_profile_buf)
|
if (!(*p_image)->icc_profile_buf)
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
memcpy( p_image->icc_profile_buf,
|
memcpy( (*p_image)->icc_profile_buf,
|
||||||
p_j2k->m_image->icc_profile_buf,
|
p_j2k->m_image->icc_profile_buf,
|
||||||
p_j2k->m_image->icc_profile_len);
|
p_j2k->m_image->icc_profile_len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
p_image->icc_profile_buf = NULL;
|
(*p_image)->icc_profile_buf = NULL;
|
||||||
|
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -6327,7 +6330,7 @@ void j2k_destroy (opj_j2k_v2_t *p_j2k)
|
||||||
tcd_destroy_v2(p_j2k->m_tcd);
|
tcd_destroy_v2(p_j2k->m_tcd);
|
||||||
|
|
||||||
j2k_cp_destroy(&(p_j2k->m_cp));
|
j2k_cp_destroy(&(p_j2k->m_cp));
|
||||||
memset(&(p_j2k->m_cp),0,sizeof(opj_cp_t));
|
memset(&(p_j2k->m_cp),0,sizeof(opj_cp_v2_t));
|
||||||
|
|
||||||
opj_procedure_list_destroy(p_j2k->m_procedure_list);
|
opj_procedure_list_destroy(p_j2k->m_procedure_list);
|
||||||
p_j2k->m_procedure_list = 00;
|
p_j2k->m_procedure_list = 00;
|
||||||
|
@ -6338,22 +6341,26 @@ void j2k_destroy (opj_j2k_v2_t *p_j2k)
|
||||||
j2k_destroy_cstr_index(p_j2k->cstr_index);
|
j2k_destroy_cstr_index(p_j2k->cstr_index);
|
||||||
p_j2k->cstr_index = NULL;
|
p_j2k->cstr_index = NULL;
|
||||||
|
|
||||||
|
opj_image_destroy(p_j2k->m_image);
|
||||||
|
p_j2k->m_image = NULL;
|
||||||
|
|
||||||
opj_free(p_j2k);
|
opj_free(p_j2k);
|
||||||
}
|
}
|
||||||
|
|
||||||
void j2k_destroy_cstr_index (opj_codestream_index_t *p_cstr_ind)
|
void j2k_destroy_cstr_index (opj_codestream_index_t *p_cstr_ind)
|
||||||
{
|
{
|
||||||
if (!p_cstr_ind) {
|
if (p_cstr_ind) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_cstr_ind->marker) {
|
if (p_cstr_ind->marker) {
|
||||||
opj_free(p_cstr_ind->marker);
|
opj_free(p_cstr_ind->marker);
|
||||||
p_cstr_ind->marker = NULL;
|
p_cstr_ind->marker = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_cstr_ind->tile_index) {
|
if (p_cstr_ind->tile_index) {
|
||||||
// FIXME
|
// FIXME not used for the moment
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(p_cstr_ind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7597,6 +7604,8 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_v2_t* p_j2k)
|
||||||
cstr_info->tw = p_j2k->m_cp.tw;
|
cstr_info->tw = p_j2k->m_cp.tw;
|
||||||
cstr_info->th = p_j2k->m_cp.th;
|
cstr_info->th = p_j2k->m_cp.th;
|
||||||
|
|
||||||
|
cstr_info->tile_info = NULL; /* Not fill from the main header*/
|
||||||
|
|
||||||
l_default_tile = p_j2k->m_specific_param.m_decoder.m_default_tcp;
|
l_default_tile = p_j2k->m_specific_param.m_decoder.m_default_tcp;
|
||||||
|
|
||||||
cstr_info->m_default_tile_info.csty = l_default_tile->csty;
|
cstr_info->m_default_tile_info.csty = l_default_tile->csty;
|
||||||
|
@ -7670,6 +7679,7 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_v2_t* p_j2k)
|
||||||
|
|
||||||
memcpy(l_cstr_index->marker, p_j2k->cstr_index->marker, l_cstr_index->marknum * sizeof(opj_marker_info_t) );
|
memcpy(l_cstr_index->marker, p_j2k->cstr_index->marker, l_cstr_index->marknum * sizeof(opj_marker_info_t) );
|
||||||
|
|
||||||
|
l_cstr_index->tile_index = NULL; /* FIXME not used for the moment*/
|
||||||
|
|
||||||
return l_cstr_index;
|
return l_cstr_index;
|
||||||
}
|
}
|
||||||
|
@ -7765,20 +7775,24 @@ opj_bool j2k_decode_v2( opj_j2k_v2_t * p_j2k,
|
||||||
{
|
{
|
||||||
OPJ_UINT32 compno;
|
OPJ_UINT32 compno;
|
||||||
|
|
||||||
|
if (!p_image)
|
||||||
|
return OPJ_FALSE;
|
||||||
|
|
||||||
/* customization of the decoding */
|
/* customization of the decoding */
|
||||||
j2k_setup_decoding(p_j2k);
|
j2k_setup_decoding(p_j2k);
|
||||||
|
|
||||||
/* write header */
|
/* Decode the codestream */
|
||||||
if (! j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
|
if (! j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
|
||||||
opj_image_destroy(p_j2k->m_image);
|
opj_image_destroy(p_j2k->m_image);
|
||||||
p_j2k->m_image = NULL;
|
p_j2k->m_image = NULL;
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy data from codec to output image*/
|
||||||
for (compno = 0; compno < p_image->numcomps; compno++) {
|
for (compno = 0; compno < p_image->numcomps; compno++) {
|
||||||
p_image->comps[compno].data = p_j2k->m_image->comps[compno].data;
|
p_image->comps[compno].data = p_j2k->m_image->comps[compno].data;
|
||||||
p_j2k->m_image->comps[compno].data = NULL;
|
p_j2k->m_image->comps[compno].data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OPJ_TRUE /*p_j2k->m_image*/;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -899,7 +899,7 @@ opj_bool j2k_end_decompress(opj_j2k_v2_t *j2k, struct opj_stream_private *cio, s
|
||||||
*/
|
*/
|
||||||
opj_bool j2k_read_header( struct opj_stream_private *p_stream,
|
opj_bool j2k_read_header( struct opj_stream_private *p_stream,
|
||||||
opj_j2k_v2_t* p_j2k,
|
opj_j2k_v2_t* p_j2k,
|
||||||
opj_image_t* p_image,
|
opj_image_t** p_image,
|
||||||
struct opj_event_mgr* p_manager );
|
struct opj_event_mgr* p_manager );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1484,11 +1484,14 @@ opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
|
||||||
|
|
||||||
}/* opj_jp2_decode() */
|
}/* opj_jp2_decode() */
|
||||||
|
|
||||||
opj_bool opj_jp2_decode_v2( opj_jp2_v2_t *jp2,
|
opj_bool jp2_decode_v2( opj_jp2_v2_t *jp2,
|
||||||
struct opj_stream_private *cio,
|
struct opj_stream_private *cio,
|
||||||
opj_image_t* p_image,
|
opj_image_t* p_image,
|
||||||
struct opj_event_mgr * p_manager)
|
struct opj_event_mgr * p_manager)
|
||||||
{
|
{
|
||||||
|
if (!p_image)
|
||||||
|
return OPJ_FALSE;
|
||||||
|
|
||||||
/* J2K decoding */
|
/* J2K decoding */
|
||||||
if( ! j2k_decode_v2(jp2->j2k, cio, p_image, p_manager) ) {
|
if( ! j2k_decode_v2(jp2->j2k, cio, p_image, p_manager) ) {
|
||||||
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\n");
|
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\n");
|
||||||
|
@ -2438,7 +2441,7 @@ static opj_bool jp2_read_boxhdr_char(
|
||||||
*/
|
*/
|
||||||
opj_bool jp2_read_header( struct opj_stream_private *p_stream,
|
opj_bool jp2_read_header( struct opj_stream_private *p_stream,
|
||||||
opj_jp2_v2_t *jp2,
|
opj_jp2_v2_t *jp2,
|
||||||
opj_image_t* p_image,
|
opj_image_t** p_image,
|
||||||
struct opj_event_mgr * p_manager
|
struct opj_event_mgr * p_manager
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -2527,7 +2530,7 @@ opj_bool jp2_read_tile_header( opj_jp2_v2_t * p_jp2,
|
||||||
* @param p_stream the stream to write data to.
|
* @param p_stream the stream to write data to.
|
||||||
* @param p_manager the user event manager.
|
* @param p_manager the user event manager.
|
||||||
*/
|
*/
|
||||||
opj_bool opj_jp2_decode_tile (
|
opj_bool jp2_decode_tile (
|
||||||
opj_jp2_v2_t * p_jp2,
|
opj_jp2_v2_t * p_jp2,
|
||||||
OPJ_UINT32 p_tile_index,
|
OPJ_UINT32 p_tile_index,
|
||||||
OPJ_BYTE * p_data,
|
OPJ_BYTE * p_data,
|
||||||
|
|
|
@ -293,10 +293,10 @@ opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_
|
||||||
* @param cstr_info Codestream information structure if required, NULL otherwise
|
* @param cstr_info Codestream information structure if required, NULL otherwise
|
||||||
* @return Returns a decoded image if successful, returns NULL otherwise
|
* @return Returns a decoded image if successful, returns NULL otherwise
|
||||||
*/
|
*/
|
||||||
opj_bool opj_jp2_decode_v2( opj_jp2_v2_t *jp2,
|
opj_bool jp2_decode_v2( opj_jp2_v2_t *jp2,
|
||||||
struct opj_stream_private *cio,
|
struct opj_stream_private *cio,
|
||||||
opj_image_t* p_image,
|
opj_image_t* p_image,
|
||||||
struct opj_event_mgr * p_manager);
|
struct opj_event_mgr * p_manager);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -348,7 +348,7 @@ opj_bool jp2_end_decompress(opj_jp2_v2_t *jp2, struct opj_stream_private *cio, s
|
||||||
*/
|
*/
|
||||||
opj_bool jp2_read_header( struct opj_stream_private *p_stream,
|
opj_bool jp2_read_header( struct opj_stream_private *p_stream,
|
||||||
opj_jp2_v2_t *jp2,
|
opj_jp2_v2_t *jp2,
|
||||||
opj_image_t * p_img_header,
|
opj_image_t ** p_img_header,
|
||||||
struct opj_event_mgr * p_manager
|
struct opj_event_mgr * p_manager
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ opj_bool jp2_read_tile_header (
|
||||||
* @param p_stream the stream to write data to.
|
* @param p_stream the stream to write data to.
|
||||||
* @param p_manager the user event manager.
|
* @param p_manager the user event manager.
|
||||||
*/
|
*/
|
||||||
opj_bool opj_jp2_decode_tile (
|
opj_bool jp2_decode_tile (
|
||||||
opj_jp2_v2_t * p_jp2,
|
opj_jp2_v2_t * p_jp2,
|
||||||
OPJ_UINT32 p_tile_index,
|
OPJ_UINT32 p_tile_index,
|
||||||
OPJ_BYTE * p_data,
|
OPJ_BYTE * p_data,
|
||||||
|
|
|
@ -40,7 +40,7 @@ typedef struct opj_decompression
|
||||||
/** Main header reading function handler*/
|
/** Main header reading function handler*/
|
||||||
opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
|
opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
|
||||||
void * p_codec,
|
void * p_codec,
|
||||||
opj_image_t *p_image,
|
opj_image_t **p_image,
|
||||||
struct opj_event_mgr * p_manager);
|
struct opj_event_mgr * p_manager);
|
||||||
/** FIXME DOC */
|
/** FIXME DOC */
|
||||||
opj_bool (* opj_decode) ( void * p_codec,
|
opj_bool (* opj_decode) ( void * p_codec,
|
||||||
|
@ -259,7 +259,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
|
||||||
l_info->m_codec_data.m_decompression.opj_read_header =
|
l_info->m_codec_data.m_decompression.opj_read_header =
|
||||||
(opj_bool (*) ( struct opj_stream_private *,
|
(opj_bool (*) ( struct opj_stream_private *,
|
||||||
void *,
|
void *,
|
||||||
opj_image_t *,
|
opj_image_t **,
|
||||||
struct opj_event_mgr * )) j2k_read_header;
|
struct opj_event_mgr * )) j2k_read_header;
|
||||||
|
|
||||||
l_info->m_codec_data.m_decompression.opj_destroy =
|
l_info->m_codec_data.m_decompression.opj_destroy =
|
||||||
|
@ -306,14 +306,14 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
|
||||||
(opj_bool (*) ( void *,
|
(opj_bool (*) ( void *,
|
||||||
struct opj_stream_private *,
|
struct opj_stream_private *,
|
||||||
opj_image_t*,
|
opj_image_t*,
|
||||||
struct opj_event_mgr * )) opj_jp2_decode_v2;
|
struct opj_event_mgr * )) jp2_decode_v2;
|
||||||
|
|
||||||
l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
|
l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
|
||||||
|
|
||||||
l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
|
l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
|
||||||
struct opj_stream_private *,
|
struct opj_stream_private *,
|
||||||
void *,
|
void *,
|
||||||
opj_image_t *,
|
opj_image_t **,
|
||||||
struct opj_event_mgr * )) jp2_read_header;
|
struct opj_event_mgr * )) jp2_read_header;
|
||||||
|
|
||||||
l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
|
l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
|
||||||
|
@ -329,7 +329,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
|
||||||
struct opj_stream_private *,
|
struct opj_stream_private *,
|
||||||
struct opj_event_mgr * )) jp2_read_tile_header;
|
struct opj_event_mgr * )) jp2_read_tile_header;
|
||||||
|
|
||||||
l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) opj_jp2_decode_tile;
|
l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) jp2_decode_tile;
|
||||||
|
|
||||||
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
|
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
|
||||||
|
|
||||||
|
@ -663,27 +663,6 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OPJ_CALLCONV opj_destroy_cstr_info_v2(opj_codestream_info_v2_t *cstr_info) {
|
|
||||||
if (cstr_info) {
|
|
||||||
int tileno, compno;
|
|
||||||
|
|
||||||
if (cstr_info->tile_info){
|
|
||||||
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
|
|
||||||
for (compno = 0; compno < cstr_info->nbcomps; compno++){
|
|
||||||
opj_free(cstr_info->tile_info[tileno].tccp_info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
opj_free(cstr_info->tile_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cstr_info->m_default_tile_info.tccp_info){
|
|
||||||
opj_free(cstr_info->m_default_tile_info.tccp_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
opj_free(cstr_info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef OLD_WAY_MS
|
#ifdef OLD_WAY_MS
|
||||||
|
@ -724,7 +703,7 @@ opj_bool OPJ_CALLCONV opj_read_header (
|
||||||
|
|
||||||
opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
|
opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
|
||||||
opj_codec_t *p_codec,
|
opj_codec_t *p_codec,
|
||||||
opj_image_t *p_image )
|
opj_image_t **p_image )
|
||||||
{
|
{
|
||||||
if (p_codec && p_cio) {
|
if (p_codec && p_cio) {
|
||||||
opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
|
opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
|
||||||
|
@ -923,6 +902,26 @@ opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void OPJ_CALLCONV opj_destroy_cstr_info_v2(opj_codestream_info_v2_t **cstr_info) {
|
||||||
|
if (cstr_info) {
|
||||||
|
|
||||||
|
if ((*cstr_info)->m_default_tile_info.tccp_info){
|
||||||
|
opj_free((*cstr_info)->m_default_tile_info.tccp_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*cstr_info)->tile_info){
|
||||||
|
/* FIXME not used for the moment*/
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free((*cstr_info));
|
||||||
|
(*cstr_info) = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -938,6 +937,30 @@ opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
|
||||||
|
{
|
||||||
|
if (*p_cstr_index){
|
||||||
|
|
||||||
|
if((*p_cstr_index)->marker){
|
||||||
|
opj_free((*p_cstr_index)->marker);
|
||||||
|
(*p_cstr_index)->marker = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((*p_cstr_index)->tile_index) {
|
||||||
|
/* FIXME not used for the moment*/
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free((*p_cstr_index));
|
||||||
|
(*p_cstr_index) = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
opj_bool OPJ_CALLCONV opj_decode_v2(opj_codec_t *p_info,
|
opj_bool OPJ_CALLCONV opj_decode_v2(opj_codec_t *p_info,
|
||||||
opj_stream_t *cio,
|
opj_stream_t *cio,
|
||||||
opj_image_t* p_image)
|
opj_image_t* p_image)
|
||||||
|
|
|
@ -1262,6 +1262,7 @@ Destroy Codestream information after compression or decompression
|
||||||
*/
|
*/
|
||||||
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
|
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
|
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info_v2(opj_codestream_info_v2_t **cstr_info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes an image header.
|
* Decodes an image header.
|
||||||
|
@ -1274,7 +1275,7 @@ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info
|
||||||
*/
|
*/
|
||||||
OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
|
OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
|
||||||
opj_codec_t *p_codec,
|
opj_codec_t *p_codec,
|
||||||
opj_image_t *p_image);
|
opj_image_t **p_image);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a decompressor handle
|
* Destroy a decompressor handle
|
||||||
|
@ -1386,6 +1387,9 @@ OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_
|
||||||
*/
|
*/
|
||||||
OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
|
OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
|
||||||
|
|
||||||
|
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JP2 file information from the codec FIXME
|
* Get the JP2 file information from the codec FIXME
|
||||||
*
|
*
|
||||||
|
|
|
@ -970,7 +970,7 @@ opj_t2_v2_t* t2_create_v2( opj_image_t *p_image,
|
||||||
if (!l_t2) {
|
if (!l_t2) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(l_t2,0,sizeof(opj_t2_t));
|
memset(l_t2,0,sizeof(opj_t2_v2_t));
|
||||||
|
|
||||||
l_t2->image = p_image;
|
l_t2->image = p_image;
|
||||||
l_t2->cp = p_cp;
|
l_t2->cp = p_cp;
|
||||||
|
|
Loading…
Reference in New Issue