2 * Copyright (c) 2005, Herve Drolon, FreeImage Team
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
27 #include "opj_includes.h"
29 /* ==========================================================
31 ==========================================================*/
33 #ifdef OPJ_CODE_NOT_USED
36 i2a(unsigned i, char *a, unsigned r) {
37 if (i/r > 0) a = i2a(i/r,a,r);
38 *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
43 Transforms integer i into an ascii string and stores the result in a;
44 string is encoded in the base indicated by r.
45 @param i Number to be converted
46 @param a String result
47 @param r Base of value; must be in the range 2 - 36
51 _itoa(int i, char *a, int r) {
52 r = ((r < 2) || (r > 36)) ? 10 : r;
57 else *i2a(i, a, r) = 0;
63 /* ----------------------------------------------------------------------- */
65 opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
67 opj_event_mgr_t *previous = cinfo->event_mgr;
68 cinfo->event_mgr = event_mgr;
69 cinfo->client_data = context;
76 opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
77 #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
78 opj_msg_callback msg_handler = NULL;
80 opj_event_mgr_t *event_mgr = cinfo->event_mgr;
81 if(event_mgr != NULL) {
84 msg_handler = event_mgr->error_handler;
87 msg_handler = event_mgr->warning_handler;
90 msg_handler = event_mgr->info_handler;
95 if(msg_handler == NULL) {
102 if ((fmt != NULL) && (event_mgr != NULL)) {
104 int str_length/*, i, j*/; /* UniPG */
105 char message[MSG_SIZE];
106 memset(message, 0, MSG_SIZE);
107 /* initialize the optional parameter list */
109 /* check the length of the format string */
110 str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
111 /* parse the format string and put the result in 'message' */
112 vsprintf(message, fmt, arg); /* UniPG */
113 /* deinitialize the optional parameter list */
116 /* output the message to the user program */
117 msg_handler(message, cinfo->client_data);
123 opj_bool opj_event_msg_v2(opj_event_mgr_t* event_mgr, int event_type, const char *fmt, ...) {
124 #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
125 opj_msg_callback msg_handler = NULL;
127 if(event_mgr != NULL) {
130 msg_handler = event_mgr->error_handler;
133 msg_handler = event_mgr->warning_handler;
136 msg_handler = event_mgr->info_handler;
141 if(msg_handler == NULL) {
148 if ((fmt != NULL) && (event_mgr != NULL)) {
150 int str_length/*, i, j*/; /* UniPG */
151 char message[MSG_SIZE];
152 memset(message, 0, MSG_SIZE);
153 /* initialize the optional parameter list */
155 /* check the length of the format string */
156 str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
157 /* parse the format string and put the result in 'message' */
158 vsprintf(message, fmt, arg); /* UniPG */
159 /* deinitialize the optional parameter list */
162 /* output the message to the user program */
163 msg_handler(message, event_mgr->client_data);