2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
8 * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
9 * Copyright (c) 2012, CS Systemes d'Information, France
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #include "opj_includes.h"
36 /* ==========================================================
38 ==========================================================*/
40 #ifdef OPJ_CODE_NOT_USED
43 i2a(unsigned i, char *a, unsigned r) {
44 if (i/r > 0) a = i2a(i/r,a,r);
45 *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
50 Transforms integer i into an ascii string and stores the result in a;
51 string is encoded in the base indicated by r.
52 @param i Number to be converted
53 @param a String result
54 @param r Base of value; must be in the range 2 - 36
58 _itoa(int i, char *a, int r) {
59 r = ((r < 2) || (r > 36)) ? 10 : r;
64 else *i2a(i, a, r) = 0;
71 /* ----------------------------------------------------------------------- */
73 * Default callback function.
76 static void opj_default_callback (const char *msg, void *client_data)
78 OPJ_ARG_NOT_USED(msg);
79 OPJ_ARG_NOT_USED(client_data);
82 /* ----------------------------------------------------------------------- */
85 /* ----------------------------------------------------------------------- */
86 OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) {
87 #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
88 opj_msg_callback msg_handler = 00;
91 if(p_event_mgr != 00) {
94 msg_handler = p_event_mgr->error_handler;
95 l_data = p_event_mgr->m_error_data;
98 msg_handler = p_event_mgr->warning_handler;
99 l_data = p_event_mgr->m_warning_data;
102 msg_handler = p_event_mgr->info_handler;
103 l_data = p_event_mgr->m_info_data;
108 if(msg_handler == 00) {
115 if ((fmt != 00) && (p_event_mgr != 00)) {
117 size_t str_length/*, i, j*/; /* UniPG */
118 char message[OPJ_MSG_SIZE];
119 memset(message, 0, OPJ_MSG_SIZE);
120 /* initialize the optional parameter list */
122 /* check the length of the format string */
123 str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
125 /* parse the format string and put the result in 'message' */
126 vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
127 /* deinitialize the optional parameter list */
130 /* output the message to the user program */
131 msg_handler(message, l_data);
137 void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
139 p_manager->m_error_data = 00;
140 p_manager->m_warning_data = 00;
141 p_manager->m_info_data = 00;
142 p_manager->error_handler = opj_default_callback;
143 p_manager->info_handler = opj_default_callback;
144 p_manager->warning_handler = opj_default_callback;