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
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include "opj_includes.h"
34 /* ==========================================================
36 ==========================================================*/
38 #ifdef OPJ_CODE_NOT_USED
41 i2a(unsigned i, char *a, unsigned r) {
42 if (i/r > 0) a = i2a(i/r,a,r);
43 *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
48 Transforms integer i into an ascii string and stores the result in a;
49 string is encoded in the base indicated by r.
50 @param i Number to be converted
51 @param a String result
52 @param r Base of value; must be in the range 2 - 36
56 _itoa(int i, char *a, int r) {
57 r = ((r < 2) || (r > 36)) ? 10 : r;
62 else *i2a(i, a, r) = 0;
68 /* ----------------------------------------------------------------------- */
70 opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
72 opj_event_mgr_t *previous = cinfo->event_mgr;
73 cinfo->event_mgr = event_mgr;
74 cinfo->client_data = context;
81 opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
82 #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
83 opj_msg_callback msg_handler = NULL;
85 opj_event_mgr_t *event_mgr = cinfo->event_mgr;
86 if(event_mgr != NULL) {
89 msg_handler = event_mgr->error_handler;
92 msg_handler = event_mgr->warning_handler;
95 msg_handler = event_mgr->info_handler;
100 if(msg_handler == NULL) {
107 if ((fmt != NULL) && (event_mgr != NULL)) {
109 int str_length/*, i, j*/; /* UniPG */
110 char message[MSG_SIZE];
111 /* initialize the optional parameter list */
113 /* parse the format string and put the result in 'message' */
114 str_length = vsnprintf(message, MSG_SIZE, fmt, arg); /* UniPG */
115 /* deinitialize the optional parameter list */
118 /* output the message to the user program */
119 if( str_length > -1 && str_length < MSG_SIZE )
120 msg_handler(message, cinfo->client_data);
121 else return OPJ_FALSE;