4 * Copyright (C) 1991-1994, Thomas G. Lane.
\r
5 * This file is part of the Independent JPEG Group's software.
\r
6 * For conditions of distribution and use, see the accompanying README file.
\r
8 * This file contains simple error-reporting and trace-message routines.
\r
9 * These are suitable for Unix-like systems and others where writing to
\r
10 * stderr is the right thing to do. Many applications will want to replace
\r
11 * some or all of these routines.
\r
13 * These routines are used by both the compression and decompression code.
\r
16 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
\r
17 #include "jinclude.h"
\r
18 #include "radiant_jpeglib.h"
\r
19 #include "jversion.h"
\r
22 #ifndef EXIT_FAILURE /* define exit() codes if not provided */
\r
23 #define EXIT_FAILURE 1
\r
28 * Create the message string table.
\r
29 * We do this from the master message list in jerror.h by re-reading
\r
30 * jerror.h with a suitable definition for macro JMESSAGE.
\r
31 * The message table is made an external symbol just in case any applications
\r
32 * want to refer to it directly.
\r
35 #ifdef NEED_SHORT_EXTERNAL_NAMES
\r
36 #define jpeg_std_message_table jMsgTable
\r
39 #define JMESSAGE(code,string) string ,
\r
41 const char * const jpeg_std_message_table[] = {
\r
46 // Rad additions, longjmp out of the LoadJPGBuff
\r
47 GLOBAL jmp_buf rad_loadfailed;
\r
48 GLOBAL char rad_errormsg[JMSG_LENGTH_MAX];
\r
51 * Error exit handler: must not return to caller.
\r
53 * Applications may override this if they want to get control back after
\r
54 * an error. Typically one would longjmp somewhere instead of exiting.
\r
55 * The setjmp buffer can be made a private field within an expanded error
\r
56 * handler object. Note that the info needed to generate an error message
\r
57 * is stored in the error object, so you can generate the message now or
\r
58 * later, at your convenience.
\r
59 * You should make sure that the JPEG object is cleaned up (with jpeg_abort
\r
60 * or jpeg_destroy) at some point.
\r
64 error_exit (j_common_ptr cinfo)
\r
66 // char buffer[JMSG_LENGTH_MAX];
\r
68 /* Create the message */
\r
69 (*cinfo->err->format_message) (cinfo,rad_errormsg);
\r
71 /* Let the memory manager delete any temp files before we die */
\r
72 jpeg_destroy(cinfo);
\r
74 longjmp( rad_loadfailed, -1 );
\r
79 * Actual output of an error or trace message.
\r
80 * Applications may override this method to send JPEG messages somewhere
\r
81 * other than stderr.
\r
85 output_message (j_common_ptr cinfo)
\r
87 char buffer[JMSG_LENGTH_MAX];
\r
89 /* Create the message */
\r
90 (*cinfo->err->format_message) (cinfo, buffer);
\r
92 /* Send it to stderr, adding a newline */
\r
93 printf("%s\n", buffer);
\r
98 * Decide whether to emit a trace or warning message.
\r
99 * msg_level is one of:
\r
100 * -1: recoverable corrupt-data warning, may want to abort.
\r
101 * 0: important advisory messages (always display to user).
\r
102 * 1: first level of tracing detail.
\r
103 * 2,3,...: successively more detailed tracing messages.
\r
104 * An application might override this method if it wanted to abort on warnings
\r
105 * or change the policy about which messages to display.
\r
109 emit_message (j_common_ptr cinfo, int msg_level)
\r
111 struct jpeg_error_mgr * err = cinfo->err;
\r
113 if (msg_level < 0) {
\r
114 /* It's a warning message. Since corrupt files may generate many warnings,
\r
115 * the policy implemented here is to show only the first warning,
\r
116 * unless trace_level >= 3.
\r
118 if (err->num_warnings == 0 || err->trace_level >= 3)
\r
119 (*err->output_message) (cinfo);
\r
120 /* Always count warnings in num_warnings. */
\r
121 err->num_warnings++;
\r
123 /* It's a trace message. Show it if trace_level >= msg_level. */
\r
124 if (err->trace_level >= msg_level)
\r
125 (*err->output_message) (cinfo);
\r
131 * Format a message string for the most recent JPEG error or message.
\r
132 * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
\r
133 * characters. Note that no '\n' character is added to the string.
\r
134 * Few applications should need to override this method.
\r
138 format_message (j_common_ptr cinfo, char * buffer)
\r
140 struct jpeg_error_mgr * err = cinfo->err;
\r
141 int msg_code = err->msg_code;
\r
142 const char * msgtext = NULL;
\r
143 const char * msgptr;
\r
147 /* Look up message string in proper table */
\r
148 if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
\r
149 msgtext = err->jpeg_message_table[msg_code];
\r
150 } else if (err->addon_message_table != NULL &&
\r
151 msg_code >= err->first_addon_message &&
\r
152 msg_code <= err->last_addon_message) {
\r
153 msgtext = err->addon_message_table[msg_code - err->first_addon_message];
\r
156 /* Defend against bogus message number */
\r
157 if (msgtext == NULL) {
\r
158 err->msg_parm.i[0] = msg_code;
\r
159 msgtext = err->jpeg_message_table[0];
\r
162 /* Check for string parameter, as indicated by %s in the message text */
\r
165 while ((ch = *msgptr++) != '\0') {
\r
167 if (*msgptr == 's') isstring = TRUE;
\r
172 /* Format the message into the passed buffer */
\r
174 sprintf(buffer, msgtext, err->msg_parm.s);
\r
176 sprintf(buffer, msgtext,
\r
177 err->msg_parm.i[0], err->msg_parm.i[1],
\r
178 err->msg_parm.i[2], err->msg_parm.i[3],
\r
179 err->msg_parm.i[4], err->msg_parm.i[5],
\r
180 err->msg_parm.i[6], err->msg_parm.i[7]);
\r
185 * Reset error state variables at start of a new image.
\r
186 * This is called during compression startup to reset trace/error
\r
187 * processing to default state, without losing any application-specific
\r
188 * method pointers. An application might possibly want to override
\r
189 * this method if it has additional error processing state.
\r
193 reset_error_mgr (j_common_ptr cinfo)
\r
195 cinfo->err->num_warnings = 0;
\r
196 /* trace_level is not reset since it is an application-supplied parameter */
\r
197 cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
\r
202 * Fill in the standard error-handling methods in a jpeg_error_mgr object.
\r
204 * struct jpeg_compress_struct cinfo;
\r
205 * struct jpeg_error_mgr err;
\r
207 * cinfo.err = jpeg_std_error(&err);
\r
208 * after which the application may override some of the methods.
\r
211 GLOBAL struct jpeg_error_mgr *
\r
212 jpeg_std_error (struct jpeg_error_mgr * err)
\r
214 err->error_exit = error_exit;
\r
215 err->emit_message = emit_message;
\r
216 err->output_message = output_message;
\r
217 err->format_message = format_message;
\r
218 err->reset_error_mgr = reset_error_mgr;
\r
220 err->trace_level = 0; /* default = no tracing */
\r
221 err->num_warnings = 0; /* no warnings emitted yet */
\r
222 err->msg_code = 0; /* may be useful as a flag for "no error" */
\r
224 /* Initialize message table pointers */
\r
225 err->jpeg_message_table = jpeg_std_message_table;
\r
226 err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
\r
228 err->addon_message_table = NULL;
\r
229 err->first_addon_message = 0; /* for safety */
\r
230 err->last_addon_message = 0;
\r