diff options
| author | Mickael Savinaud <savmickael@users.noreply.github.com> | 2011-09-21 16:37:45 +0000 |
|---|---|---|
| committer | Mickael Savinaud <savmickael@users.noreply.github.com> | 2011-09-21 16:37:45 +0000 |
| commit | 5d0b813cecee07f2bf69e94e826385b38b5dfb4c (patch) | |
| tree | 4d71e0d1902a93f4e8636326ab57e54164a02d22 /libopenjpeg | |
| parent | ba0c271774f56259874dffbe15f44313f9d6e954 (diff) | |
[trunk] WIP: clean the j2k_dump application and the lib regards to the event management
Diffstat (limited to 'libopenjpeg')
| -rw-r--r-- | libopenjpeg/event.c | 63 | ||||
| -rw-r--r-- | libopenjpeg/event.h | 42 | ||||
| -rw-r--r-- | libopenjpeg/j2k.c | 11 | ||||
| -rw-r--r-- | libopenjpeg/jp2.c | 5 | ||||
| -rw-r--r-- | libopenjpeg/openjpeg.c | 106 | ||||
| -rw-r--r-- | libopenjpeg/openjpeg.h | 41 |
6 files changed, 197 insertions, 71 deletions
diff --git a/libopenjpeg/event.c b/libopenjpeg/event.c index 77cec893..6346e39d 100644 --- a/libopenjpeg/event.c +++ b/libopenjpeg/event.c @@ -60,8 +60,8 @@ _itoa(int i, char *a, int r) { #endif /* !_WIN32 */ #endif -/* ----------------------------------------------------------------------- */ +/* ----------------------------------------------------------------------- */ opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { if(cinfo) { opj_event_mgr_t *previous = cinfo->event_mgr; @@ -73,6 +73,7 @@ opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_ return NULL; } +/* ----------------------------------------------------------------------- */ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ opj_msg_callback msg_handler = NULL; @@ -120,6 +121,7 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, .. return OPJ_TRUE; } +/* ----------------------------------------------------------------------- */ opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...) { #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ opj_msg_callback msg_handler = NULL; @@ -165,3 +167,62 @@ opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char return OPJ_TRUE; } + +/* ----------------------------------------------------------------------- */ +void opj_set_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose) +{ + p_manager->client_data = NULL; + p_manager->error_handler = opj_error_default_callback; + + if (verbose) { + p_manager->info_handler = opj_info_default_callback; + p_manager->warning_handler = opj_warning_default_callback; + } + else { + /* FIXME (MSD) This message should be remove when the documentation will be updated */ + fprintf(stdout, "[INFO] Verbose mode = OFF => no other info/warning output.\n"); + p_manager->info_handler = opj_default_callback ; + p_manager->warning_handler = opj_default_callback ; + } +} + +/* ---------------------------------------------------------------------- */ +/* Default callback functions */ + +/** + * Default callback function. + * Do nothing. + */ +void opj_default_callback (const char *msg, void *client_data) +{ +} + +/** + * Default info callback function. + * Output = stdout. + */ +void opj_info_default_callback (const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); +} + +/** + * Default warning callback function. + * Output = stderr. + */ +void opj_warning_default_callback (const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stderr, "[WARNING] %s", msg); +} + +/** + * Default error callback function. + * Output = stderr. + */ +void opj_error_default_callback (const char *msg, void *client_data) +{ + (void)client_data; + fprintf(stderr, "[ERROR] %s", msg); +} diff --git a/libopenjpeg/event.h b/libopenjpeg/event.h index c8cb85e4..2c80276e 100644 --- a/libopenjpeg/event.h +++ b/libopenjpeg/event.h @@ -48,14 +48,54 @@ Write formatted data to a string and send the string to a user callback. @param event_type Event type or callback to use to send the message @param fmt Format-control string (plus optional arguments) @return Returns true if successful, returns false otherwise +* FIXME Change by its v2 version this function after ended the merge (perhaps remove to the exported function) */ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...); +/** + * Set the default event handler. This function set the output of message event to be stderr for warning and error output + * and stdout for info output. It is optional, you can set your own event handler or provide a null structure to the + * opj_setup_decoder function. In this last case no output will be displayed. + * + * @param p_manager a opj_event_mgr structure which will be pass to the codec. + */ +void opj_set_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose); -opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...); /* ----------------------------------------------------------------------- */ /*@}*/ +/** + * Write formatted data to a string and send the string to a user callback. + * + * @param event_mgr Event handler + * @param event_type Event type or callback to use to send the message + * @param fmt Format-control string (plus optional arguments) + * + * @return Returns true if successful, returns false otherwise + */ +opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...); + +/** + * Default callback function. No message sent to output. + */ +void opj_default_callback (const char *msg, void *client_data); + +/** + * Default info callback function, message is sent to the stdout output. + */ +void opj_info_default_callback (const char *msg, void *client_data); + +/** + * Default warning callback function, message is sent to stderr output. + */ +void opj_warning_default_callback (const char *msg, void *client_data); + +/** + * Default error callback function, message is sent to stderr output. + */ +void opj_error_default_callback (const char *msg, void *client_data); + + /*@}*/ #endif /* __EVENT_H */ diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c index dd124ca6..11189d04 100644 --- a/libopenjpeg/j2k.c +++ b/libopenjpeg/j2k.c @@ -4097,24 +4097,17 @@ void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) { } } -void j2k_setup_decoder_v2(opj_j2k_v2_t *j2k, opj_dparameters_t *parameters) { +void j2k_setup_decoder_v2(opj_j2k_v2_t *j2k, opj_dparameters_t *parameters) +{ if(j2k && parameters) { - /* create and initialize the coding parameters structure */ - //opj_cp_v2_t *cp = (opj_cp_v2_t*) opj_calloc(1, sizeof(opj_cp_v2_t)); j2k->m_cp.m_specific_param.m_dec.m_layer = parameters->cp_layer; j2k->m_cp.m_specific_param.m_dec.m_reduce = parameters->cp_reduce; - /*cp->reduce = parameters->cp_reduce; - cp->layer = parameters->cp_layer; - cp->limit_decoding = parameters->cp_limit_decoding;*/ - - // TODO MS #ifdef USE_JPWL j2k->m_cp.correct = parameters->jpwl_correct; j2k->m_cp.exp_comps = parameters->jpwl_exp_comps; j2k->m_cp.max_tiles = parameters->jpwl_max_tiles; #endif /* USE_JPWL */ - } } diff --git a/libopenjpeg/jp2.c b/libopenjpeg/jp2.c index bfdf2cc8..43766b14 100644 --- a/libopenjpeg/jp2.c +++ b/libopenjpeg/jp2.c @@ -1750,11 +1750,12 @@ void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) { /* further JP2 initializations go here */ } -void jp2_setup_decoder_v2(opj_jp2_v2_t *jp2, opj_dparameters_t *parameters) { +void jp2_setup_decoder_v2(opj_jp2_v2_t *jp2, opj_dparameters_t *parameters) +{ /* setup the J2K codec */ j2k_setup_decoder_v2(jp2->j2k, parameters); - /* further JP2 initializations go here */ + /* further JP2 initializations go here */ jp2->color.jp2_has_colr = 0; } diff --git a/libopenjpeg/openjpeg.c b/libopenjpeg/openjpeg.c index c03d6602..f9a39258 100644 --- a/libopenjpeg/openjpeg.c +++ b/libopenjpeg/openjpeg.c @@ -31,17 +31,22 @@ #include "opj_config.h" #include "opj_includes.h" + +/** + * Decompression handler. + */ typedef struct opj_decompression { + /** Main header reading function handler*/ opj_bool (* opj_read_header) ( struct opj_stream_private * cio, void * p_codec, opj_file_info_t * file_info, struct opj_event_mgr * p_manager); - + /** FIXME DOC */ opj_image_t* (* opj_decode) ( void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager); - + /** FIXME DOC */ opj_bool (*opj_read_tile_header)( void * p_codec, OPJ_UINT32 * p_tile_index, OPJ_UINT32* p_data_size, @@ -51,28 +56,31 @@ typedef struct opj_decompression opj_bool * p_should_go_on, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager); - + /** FIXME DOC */ opj_bool (*opj_decode_tile_data)( void * p_codec, OPJ_UINT32 p_tile_index, OPJ_BYTE * p_data, OPJ_UINT32 p_data_size, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager); - + /** FIXME DOC */ opj_bool (* opj_end_decompress) ( void *p_codec, struct opj_stream_private *cio, struct opj_event_mgr * p_manager); - + /** Codec destroy function handler*/ void (* opj_destroy) (void * p_codec); - + /** Setup decoder function handler */ void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param); - + /** Set decode area function handler */ opj_bool (*opj_set_decode_area) ( void * p_codec, OPJ_INT32 p_start_x, OPJ_INT32 p_end_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_y, struct opj_event_mgr * p_manager); }opj_decompression_t; +/** + * Compression handler. FIXME DOC + */ typedef struct opj_compression { opj_bool (* opj_start_compress) (void *p_codec,struct opj_stream_private *cio,struct opj_image * p_image, struct opj_event_mgr * p_manager); @@ -84,38 +92,29 @@ typedef struct opj_compression }opj_compression_t; +/** + * Main codec handler used for compression or decompression. + */ typedef struct opj_codec_private { - /* code-blocks informations */ + /** FIXME DOC */ union { opj_decompression_t m_decompression; opj_compression_t m_compression; } m_codec_data; + /** FIXME DOC*/ void * m_codec; + /** Event handler */ opj_event_mgr_t* m_event_mgr; - unsigned is_decompressor : 1; + /** Flag to indicate if the codec is used to decode or encode*/ + opj_bool is_decompressor; } opj_codec_private_t; -/** - * Default callback function. - * Do nothing. - */ -void opj_default_callback (const char *msg, void *client_data) -{ - //FIXME V2 -> V1 cf below -} -void set_default_event_handler(opj_event_mgr_t * p_manager) -{ - //FIXME V2 -> V1 - //p_manager->m_error_data = 00; - //p_manager->m_warning_data = 00; - //p_manager->m_info_data = 00; - p_manager->error_handler = opj_default_callback; - p_manager->info_handler = opj_default_callback; - p_manager->warning_handler = opj_default_callback; -} + +/* ---------------------------------------------------------------------- */ + OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file) { @@ -177,6 +176,8 @@ const char* OPJ_CALLCONV opj_version(void) { return PACKAGE_VERSION; } + + opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t)); if(!dinfo) return NULL; @@ -378,27 +379,28 @@ void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *param opj_bool OPJ_CALLCONV opj_setup_decoder_v2(opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr) { - if (p_info && parameters) { - opj_codec_private_t * l_info = (opj_codec_private_t *) p_info; + opj_codec_private_t * l_info = (opj_codec_private_t *) p_info; - if (! l_info->is_decompressor) { - return OPJ_FALSE; - } + if ( !p_info || !parameters || !event_mgr ){ + fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n"); + return OPJ_FALSE; + } - l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec,parameters); + if ( !event_mgr->error_handler || !event_mgr->warning_handler || !event_mgr->error_handler){ + fprintf(stderr, "[ERROR] Event handler provided to the setup_decoder function is not valid.\n"); + return OPJ_FALSE; + } - if (event_mgr == NULL) - { - l_info->m_event_mgr->error_handler = opj_default_callback ; - l_info->m_event_mgr->warning_handler = opj_default_callback ; - l_info->m_event_mgr->info_handler = opj_default_callback ; - l_info->m_event_mgr->client_data = stderr; - } - else - l_info->m_event_mgr = event_mgr; - return OPJ_TRUE; + if (! l_info->is_decompressor) { + opj_event_msg_v2(event_mgr, EVT_ERROR, "Codec provided to the setup_decoder function is not a decompressor handler.\n"); + return OPJ_FALSE; } - return OPJ_FALSE; + + l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec, parameters); + + l_info->m_event_mgr = event_mgr; + + return OPJ_TRUE; } opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { @@ -675,6 +677,7 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio, opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio; if(! l_info->is_decompressor) { + opj_event_msg_v2(l_info->m_event_mgr, EVT_ERROR, "Codec provided to the read_header function is not a decompressor handler.\n"); return OPJ_FALSE; } @@ -684,25 +687,24 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio, p_file_info, l_info->m_event_mgr); } + + fprintf(stderr, "[ERROR] Input parameters of the read_header function are incorrect.\n"); return OPJ_FALSE; } void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info) { - if - (p_info) - { + if (p_info) { opj_codec_private_t * l_info = (opj_codec_private_t *) p_info; - if - (l_info->is_decompressor) - { + + if (l_info->is_decompressor) { l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec); } - else - { + else { l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec); } + l_info->m_codec = 00; opj_free(l_info); } diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h index 4eabb399..55b8c83a 100644 --- a/libopenjpeg/openjpeg.h +++ b/libopenjpeg/openjpeg.h @@ -192,7 +192,7 @@ typedef enum LIMIT_DECODING { /** Callback function prototype for events @param msg Event message -@param client_data +@param client_data FIXME DOC */ typedef void (*opj_msg_callback) (const char *msg, void *client_data); @@ -206,6 +206,7 @@ used for </ul> */ typedef struct opj_event_mgr { + /** FIXME DOC */ void* client_data; /** Error message callback if available, NULL otherwise */ opj_msg_callback error_handler; @@ -434,11 +435,16 @@ typedef struct opj_dparameters { OPJ_LIMIT_DECODING cp_limit_decoding; - /* V2 */ - OPJ_UINT32 ROI_x0; - OPJ_UINT32 ROI_x1; - OPJ_UINT32 ROI_y0; - OPJ_UINT32 ROI_y1; + /** Decoding area left boundary */ + OPJ_UINT32 DA_x0; + /** Decoding area right boundary */ + OPJ_UINT32 DA_x1; + /** Decoding area up boundary */ + OPJ_UINT32 DA_y0; + /** Decoding area bottom boundary */ + OPJ_UINT32 DA_y1; + /** Verbose mode */ + opj_bool m_verbose; } opj_dparameters_t; @@ -1175,6 +1181,17 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context); +/** + * Set the default event handler. This function set the output of message event to be stderr for warning and error output + * and stdout for info output. It is optional, you can set your own event handler or provide a null structure to the + * opj_setup_decoder function. In this last case no output will be displayed. + * + * @param p_manager a opj_event_mgr structure which will be pass to the codec. + * + */ +OPJ_API void OPJ_CALLCONV opj_set_default_event_handler(opj_event_mgr_t * p_manager, opj_bool verbose); + + /* ========================================================== codec functions definitions @@ -1212,6 +1229,17 @@ Decoding parameters are returned in j2k->cp. */ OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters); + +/** + * Setup the decoder with decompression parameters provided by the user and with the message handler + * provided by the user. + * + * @param dinfo decompressor handlers + * @param parameters decompression parameters + * @param vent_mgr message handler + * + * @return true if the decoder is correctly set + */ OPJ_API opj_bool OPJ_CALLCONV opj_setup_decoder_v2( opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr); @@ -1384,6 +1412,7 @@ OPJ_API opj_bool OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec, OPJ_UINT32 p_data_size, opj_stream_t *p_stream ); + #ifdef __cplusplus } #endif |
