[trunk] Enhance support of events like the v2 branch. Use right name of variables.
This commit is contained in:
@@ -158,10 +158,9 @@ int main(int argc, char **argv)
|
||||
FILE *fsrc = NULL;
|
||||
|
||||
opj_dparameters_t parameters; /* decompression parameters */
|
||||
opj_event_mgr_t event_mgr; /* event manager */
|
||||
opj_image_t* image = NULL;
|
||||
opj_stream_t *cio = NULL; /* Stream */
|
||||
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
|
||||
opj_stream_t *l_stream = NULL; /* Stream */
|
||||
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
|
||||
opj_codestream_info_v2_t* cstr_info = NULL;
|
||||
|
||||
/* Index of corner tiles */
|
||||
@@ -175,12 +174,6 @@ int main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Set event mgr */
|
||||
event_mgr.error_handler = error_callback;
|
||||
event_mgr.warning_handler = warning_callback;
|
||||
event_mgr.info_handler = info_callback;
|
||||
opj_initialize_default_event_handler(&event_mgr, 1);
|
||||
|
||||
/* Set decoding parameters to default values */
|
||||
opj_set_default_decoder_parameters(¶meters);
|
||||
|
||||
@@ -202,19 +195,19 @@ int main(int argc, char **argv)
|
||||
case J2K_CFMT: /* JPEG-2000 codestream */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
dinfo = opj_create_decompress_v2(CODEC_J2K);
|
||||
l_codec = opj_create_decompress_v2(CODEC_J2K);
|
||||
break;
|
||||
}
|
||||
case JP2_CFMT: /* JPEG 2000 compressed image data */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
dinfo = opj_create_decompress_v2(CODEC_JP2);
|
||||
l_codec = opj_create_decompress_v2(CODEC_JP2);
|
||||
break;
|
||||
}
|
||||
case JPT_CFMT: /* JPEG 2000, JPIP */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
dinfo = opj_create_decompress_v2(CODEC_JPT);
|
||||
l_codec = opj_create_decompress_v2(CODEC_JPT);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -224,34 +217,39 @@ int main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cio = opj_stream_create_default_file_stream(fsrc,1);
|
||||
if (!cio){
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_info_handler(l_codec, info_callback,00);
|
||||
opj_set_warning_handler(l_codec, warning_callback,00);
|
||||
opj_set_error_handler(l_codec, error_callback,00);
|
||||
|
||||
l_stream = opj_stream_create_default_file_stream(fsrc,1);
|
||||
if (!l_stream){
|
||||
fclose(fsrc);
|
||||
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Setup the decoder decoding parameters using user parameters */
|
||||
if ( !opj_setup_decoder_v2(dinfo, ¶meters, &event_mgr) ){
|
||||
if ( !opj_setup_decoder_v2(l_codec, ¶meters) ){
|
||||
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
|
||||
opj_stream_destroy(cio);
|
||||
opj_stream_destroy(l_stream);
|
||||
fclose(fsrc);
|
||||
opj_destroy_codec(dinfo);
|
||||
opj_destroy_codec(l_codec);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Read the main header of the codestream and if necessary the JP2 boxes*/
|
||||
if(! opj_read_header(cio, dinfo, &image)){
|
||||
if(! opj_read_header(l_stream, l_codec, &image)){
|
||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
|
||||
opj_stream_destroy(cio);
|
||||
opj_stream_destroy(l_stream);
|
||||
fclose(fsrc);
|
||||
opj_destroy_codec(dinfo);
|
||||
opj_destroy_codec(l_codec);
|
||||
opj_image_destroy(image);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Extract some info from the code stream */
|
||||
cstr_info = opj_get_cstr_info(dinfo);
|
||||
cstr_info = opj_get_cstr_info(l_codec);
|
||||
|
||||
fprintf(stdout, "The file contains %dx%d tiles\n", cstr_info->tw, cstr_info->th);
|
||||
|
||||
@@ -262,11 +260,11 @@ int main(int argc, char **argv)
|
||||
|
||||
#define TEST_TILE( tile_index ) \
|
||||
fprintf(stdout, "Decoding tile %d ...\n", tile_index); \
|
||||
if(!opj_get_decoded_tile(dinfo, cio, image, tile_index )){ \
|
||||
if(!opj_get_decoded_tile(l_codec, l_stream, image, tile_index )){ \
|
||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode tile %d\n", tile_index); \
|
||||
opj_stream_destroy(cio); \
|
||||
opj_stream_destroy(l_stream); \
|
||||
opj_destroy_cstr_info_v2(&cstr_info); \
|
||||
opj_destroy_codec(dinfo); \
|
||||
opj_destroy_codec(l_codec); \
|
||||
opj_image_destroy(image); \
|
||||
fclose(fsrc); \
|
||||
return EXIT_FAILURE; \
|
||||
@@ -281,13 +279,13 @@ int main(int argc, char **argv)
|
||||
TEST_TILE(tile_lr)
|
||||
|
||||
/* Close the byte stream */
|
||||
opj_stream_destroy(cio);
|
||||
opj_stream_destroy(l_stream);
|
||||
|
||||
/* Destroy code stream info */
|
||||
opj_destroy_cstr_info_v2(&cstr_info);
|
||||
|
||||
/* Free remaining structures */
|
||||
opj_destroy_codec(dinfo);
|
||||
opj_destroy_codec(l_codec);
|
||||
|
||||
/* Free image data structure */
|
||||
opj_image_destroy(image);
|
||||
|
Reference in New Issue
Block a user