diff options
| author | Mickael Savinaud <savmickael@users.noreply.github.com> | 2012-05-02 07:01:13 +0000 |
|---|---|---|
| committer | Mickael Savinaud <savmickael@users.noreply.github.com> | 2012-05-02 07:01:13 +0000 |
| commit | 055d429ae11ad98dfd3dc68d188ec538588d805c (patch) | |
| tree | 4f8b62cb33a66264cf9faa6346994f01e5d5df54 /applications/codec | |
| parent | 8231897b26096be299ef6f33ff7d5f42b45106d5 (diff) | |
[trunk] Enhance support of events like the v2 branch. Use right name of variables.
Diffstat (limited to 'applications/codec')
| -rw-r--r-- | applications/codec/image_to_j2k.c | 83 | ||||
| -rw-r--r-- | applications/codec/j2k_dump.c | 73 | ||||
| -rw-r--r-- | applications/codec/j2k_to_image.c | 73 |
3 files changed, 133 insertions, 96 deletions
diff --git a/applications/codec/image_to_j2k.c b/applications/codec/image_to_j2k.c index 7d2bba0d..ed9a9a37 100644 --- a/applications/codec/image_to_j2k.c +++ b/applications/codec/image_to_j2k.c @@ -1536,38 +1536,59 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, /** sample error callback expecting a FILE* client object */ -void error_callback(const char *msg, void *client_data) { +void error_file_callback(const char *msg, void *client_data) { FILE *stream = (FILE*)client_data; fprintf(stream, "[ERROR] %s", msg); } /** sample warning callback expecting a FILE* client object */ -void warning_callback(const char *msg, void *client_data) { +void warning_file_callback(const char *msg, void *client_data) { FILE *stream = (FILE*)client_data; fprintf(stream, "[WARNING] %s", msg); } /** sample debug callback expecting a FILE* client object */ -void info_callback(const char *msg, void *client_data) { +void info_file_callback(const char *msg, void *client_data) { FILE *stream = (FILE*)client_data; fprintf(stream, "[INFO] %s", msg); } +/** +sample error debug callback expecting no client object +*/ +void error_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); +} +/** +sample warning debug callback expecting no client object +*/ +void warning_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); +} +/** +sample debug callback expecting no client object +*/ +void info_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); +} + /* -------------------------------------------------------------------------- */ /** * IMAGE_TO_J2K MAIN */ /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - FILE *f = NULL; + FILE *fout = NULL; opj_cparameters_t parameters; /* compression parameters */ - opj_event_mgr_t event_mgr; /* event manager */ - opj_stream_t *cio = 00; - opj_codec_t* cinfo = 00; + opj_stream_t *l_stream = 00; + opj_codec_t* l_codec = 00; opj_image_t *image = NULL; raw_cparameters_t raw_cp; opj_codestream_info_t cstr_info; /* Codestream information structure */ @@ -1580,15 +1601,6 @@ int main(int argc, char **argv) { opj_bool bSuccess; - /* - configure the event callbacks (not required) - setting of each callback is optionnal - */ - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = error_callback; - event_mgr.warning_handler = warning_callback; - event_mgr.info_handler = info_callback; - /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); @@ -1768,56 +1780,61 @@ int main(int argc, char **argv) { case J2K_CFMT: /* JPEG-2000 codestream */ { /* Get a decoder handle */ - cinfo = opj_create_compress_v2(CODEC_J2K); + l_codec = opj_create_compress_v2(CODEC_J2K); break; } case JP2_CFMT: /* JPEG 2000 compressed image data */ { /* Get a decoder handle */ - cinfo = opj_create_compress_v2(CODEC_JP2); + l_codec = opj_create_compress_v2(CODEC_JP2); break; } default: fprintf(stderr, "skipping file..\n"); - opj_stream_destroy(cio); + opj_stream_destroy(l_stream); continue; } + + /* 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); - opj_setup_encoder_v2(cinfo, ¶meters, image); + opj_setup_encoder_v2(l_codec, ¶meters, image); /* Open the output file*/ - f = fopen(parameters.outfile, "wb"); - if (! f) { + fout = fopen(parameters.outfile, "wb"); + if (! fout) { fprintf(stderr, "Not enable to create output file!\n"); - opj_stream_destroy(cio); + opj_stream_destroy(l_stream); return 1; } /* open a byte stream for writing and allocate memory for all tiles */ - cio = opj_stream_create_default_file_stream(f,OPJ_FALSE); - if (! cio){ + l_stream = opj_stream_create_default_file_stream(fout,OPJ_FALSE); + if (! l_stream){ return 1; } /* encode the image */ - bSuccess = opj_start_compress(cinfo,image,cio); - bSuccess = bSuccess && opj_encode_v2(cinfo, cio); - bSuccess = bSuccess && opj_end_compress(cinfo, cio); + bSuccess = opj_start_compress(l_codec,image,l_stream); + bSuccess = bSuccess && opj_encode_v2(l_codec, l_stream); + bSuccess = bSuccess && opj_end_compress(l_codec, l_stream); if (!bSuccess) { - opj_stream_destroy(cio); - fclose(f); + opj_stream_destroy(l_stream); + fclose(fout); fprintf(stderr, "failed to encode image\n"); return 1; } fprintf(stderr,"Generated outfile %s\n",parameters.outfile); /* close and free the byte stream */ - opj_stream_destroy(cio); - fclose(f); + opj_stream_destroy(l_stream); + fclose(fout); /* free remaining compression structures */ - opj_destroy_codec(cinfo); + opj_destroy_codec(l_codec); /* free image data */ opj_image_destroy(image); diff --git a/applications/codec/j2k_dump.c b/applications/codec/j2k_dump.c index 0ac05499..c41becd3 100644 --- a/applications/codec/j2k_dump.c +++ b/applications/codec/j2k_dump.c @@ -370,6 +370,30 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i } /* -------------------------------------------------------------------------- */ + +/** +sample error debug callback expecting no client object +*/ +void error_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); +} +/** +sample warning debug callback expecting no client object +*/ +void warning_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); +} +/** +sample debug callback expecting no client object +*/ +void info_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); +} + +/* -------------------------------------------------------------------------- */ /** * J2K_DUMP MAIN */ @@ -379,10 +403,9 @@ int main(int argc, char *argv[]) FILE *fsrc = NULL, *fout = NULL; opj_dparameters_t parameters; /* Decompression parameters */ - opj_event_mgr_t event_mgr; /* Event manager */ opj_image_t* image = NULL; /* Image structure */ - opj_codec_t* dinfo = NULL; /* Handle to a decompressor */ - opj_stream_t *cio = NULL; /* Stream */ + opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ + opj_stream_t *l_stream = NULL; /* Stream */ opj_codestream_info_v2_t* cstr_info = NULL; opj_codestream_index_t* cstr_index = NULL; @@ -407,9 +430,6 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - /* Set default event mgr */ - opj_initialize_default_event_handler(&event_mgr, parameters.m_verbose); - /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ int it_image; @@ -471,8 +491,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - cio = opj_stream_create_default_file_stream(fsrc,1); - if (!cio){ + 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; @@ -485,61 +505,66 @@ 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: fprintf(stderr, "skipping file..\n"); - opj_stream_destroy(cio); + opj_stream_destroy(l_stream); continue; } + /* 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); + /* 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); fclose(fout); 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_dump: 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); fclose(fout); return EXIT_FAILURE; } - opj_dump_codec(dinfo, OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND, fout ); + opj_dump_codec(l_codec, OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND, fout ); - cstr_info = opj_get_cstr_info(dinfo); + cstr_info = opj_get_cstr_info(l_codec); - cstr_index = opj_get_cstr_index(dinfo); + cstr_index = opj_get_cstr_index(l_codec); /* close the byte stream */ - opj_stream_destroy(cio); + opj_stream_destroy(l_stream); fclose(fsrc); /* free remaining structures */ - if (dinfo) { - opj_destroy_codec(dinfo); + if (l_codec) { + opj_destroy_codec(l_codec); } /* destroy the image header */ diff --git a/applications/codec/j2k_to_image.c b/applications/codec/j2k_to_image.c index 30d80862..762763ab 100644 --- a/applications/codec/j2k_to_image.c +++ b/applications/codec/j2k_to_image.c @@ -667,10 +667,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_index_t* cstr_index = NULL; char indexfilename[OPJ_PATH_LEN]; /* index file name */ @@ -679,12 +678,6 @@ int main(int argc, char **argv) img_fol_t img_fol; dircnt_t *dirptr = NULL; - /* configure the event callbacks (not required) */ - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = error_callback; - event_mgr.warning_handler = warning_callback; - event_mgr.info_handler = info_callback; - /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); @@ -699,9 +692,6 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - /* Set default event mgr */ - opj_initialize_default_event_handler(&event_mgr, 1); - /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ int it_image; @@ -750,8 +740,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - cio = opj_stream_create_default_file_stream(fsrc,1); - if (!cio){ + 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; @@ -764,64 +754,69 @@ 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: fprintf(stderr, "skipping file..\n"); - opj_stream_destroy(cio); + opj_stream_destroy(l_stream); continue; } + /* 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); + /* 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; } if (!parameters.nb_tile_to_decode) { // Optional if you want decode the entire image - if (!opj_set_decode_area(dinfo, image, parameters.DA_x0, + if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){ fprintf(stderr, "ERROR -> j2k_to_image: failed to set the decoded area\n"); - opj_stream_destroy(cio); - opj_destroy_codec(dinfo); + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; } /* Get the decoded image */ - if (!(opj_decode_v2(dinfo, cio, image) && opj_end_decompress(dinfo, cio))) { + if (!(opj_decode_v2(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) { fprintf(stderr,"ERROR -> j2k_to_image: failed to decode image!\n"); - opj_destroy_codec(dinfo); - opj_stream_destroy(cio); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; @@ -830,19 +825,19 @@ int main(int argc, char **argv) else { // It is just here to illustrate how to use the resolution after set parameters - /*if (!opj_set_decoded_resolution_factor(dinfo, 5)) { + /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) { fprintf(stderr, "ERROR -> j2k_to_image: failed to set the resolution factor tile!\n"); - opj_destroy_codec(dinfo); - opj_stream_destroy(cio); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; }*/ - if (!opj_get_decoded_tile(dinfo, cio, image, parameters.tile_index)) { + if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode tile!\n"); - opj_destroy_codec(dinfo); - opj_stream_destroy(cio); + opj_destroy_codec(l_codec); + opj_stream_destroy(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; @@ -851,7 +846,7 @@ int main(int argc, char **argv) } /* Close the byte stream */ - opj_stream_destroy(cio); + opj_stream_destroy(l_stream); fclose(fsrc); if(image->color_space == CLRSPC_SYCC){ @@ -940,8 +935,8 @@ int main(int argc, char **argv) } /* free remaining structures */ - if (dinfo) { - opj_destroy_codec(dinfo); + if (l_codec) { + opj_destroy_codec(l_codec); } |
