diff options
Diffstat (limited to 'extern/libopenjpeg/event.c')
-rw-r--r-- | extern/libopenjpeg/event.c | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/extern/libopenjpeg/event.c b/extern/libopenjpeg/event.c index 38db33a9432..b6034b42d0a 100644 --- a/extern/libopenjpeg/event.c +++ b/extern/libopenjpeg/event.c @@ -1,5 +1,12 @@ /* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR + * Copyright (c) 2012, CS Systemes d'Information, France * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -60,62 +67,80 @@ _itoa(int i, char *a, int r) { #endif /* !_WIN32 */ #endif + /* ----------------------------------------------------------------------- */ +/** + * Default callback function. + * Do nothing. + */ +static void opj_default_callback (const char *msg, void *client_data) +{ + OPJ_ARG_NOT_USED(msg); + OPJ_ARG_NOT_USED(client_data); +} -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; - cinfo->event_mgr = event_mgr; - cinfo->client_data = context; - return previous; - } +/* ----------------------------------------------------------------------- */ - 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; +/* ----------------------------------------------------------------------- */ +OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) { +#define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ + opj_msg_callback msg_handler = 00; + void * l_data = 00; - opj_event_mgr_t *event_mgr = cinfo->event_mgr; - if(event_mgr != NULL) { + if(p_event_mgr != 00) { switch(event_type) { case EVT_ERROR: - msg_handler = event_mgr->error_handler; + msg_handler = p_event_mgr->error_handler; + l_data = p_event_mgr->m_error_data; break; case EVT_WARNING: - msg_handler = event_mgr->warning_handler; + msg_handler = p_event_mgr->warning_handler; + l_data = p_event_mgr->m_warning_data; break; case EVT_INFO: - msg_handler = event_mgr->info_handler; + msg_handler = p_event_mgr->info_handler; + l_data = p_event_mgr->m_info_data; break; default: break; } - if(msg_handler == NULL) { + if(msg_handler == 00) { return OPJ_FALSE; } } else { return OPJ_FALSE; } - if ((fmt != NULL) && (event_mgr != NULL)) { + if ((fmt != 00) && (p_event_mgr != 00)) { va_list arg; - int str_length/*, i, j*/; /* UniPG */ - char message[MSG_SIZE]; + size_t str_length/*, i, j*/; /* UniPG */ + char message[OPJ_MSG_SIZE]; + memset(message, 0, OPJ_MSG_SIZE); /* initialize the optional parameter list */ va_start(arg, fmt); + /* check the length of the format string */ + str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt); + (void)str_length; /* parse the format string and put the result in 'message' */ - str_length = vsnprintf(message, MSG_SIZE, fmt, arg); /* UniPG */ + vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */ /* deinitialize the optional parameter list */ va_end(arg); /* output the message to the user program */ - if( str_length > -1 && str_length < MSG_SIZE ) - msg_handler(message, cinfo->client_data); - else return OPJ_FALSE; + msg_handler(message, l_data); } return OPJ_TRUE; } +void opj_set_default_event_handler(opj_event_mgr_t * p_manager) +{ + 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; +} + |