| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jerror.c | 2 * jerror.c |
| 3 * | 3 * |
| 4 * This file was part of the Independent JPEG Group's software: |
| 4 * Copyright (C) 1991-1998, Thomas G. Lane. | 5 * Copyright (C) 1991-1998, Thomas G. Lane. |
| 5 * This file is part of the Independent JPEG Group's software. | 6 * It was modified by The libjpeg-turbo Project to include only code relevant |
| 6 * For conditions of distribution and use, see the accompanying README file. | 7 * to libjpeg-turbo. |
| 8 * For conditions of distribution and use, see the accompanying README.ijg |
| 9 * file. |
| 7 * | 10 * |
| 8 * This file contains simple error-reporting and trace-message routines. | 11 * This file contains simple error-reporting and trace-message routines. |
| 9 * These are suitable for Unix-like systems and others where writing to | 12 * These are suitable for Unix-like systems and others where writing to |
| 10 * stderr is the right thing to do. Many applications will want to replace | 13 * stderr is the right thing to do. Many applications will want to replace |
| 11 * some or all of these routines. | 14 * some or all of these routines. |
| 12 * | 15 * |
| 13 * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, | 16 * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, |
| 14 * you get a Windows-specific hack to display error messages in a dialog box. | 17 * you get a Windows-specific hack to display error messages in a dialog box. |
| 15 * It ain't much, but it beats dropping error messages into the bit bucket, | 18 * It ain't much, but it beats dropping error messages into the bit bucket, |
| 16 * which is what happens to output to stderr under most Windows C compilers. | 19 * which is what happens to output to stderr under most Windows C compilers. |
| 17 * | 20 * |
| 18 * These routines are used by both the compression and decompression code. | 21 * These routines are used by both the compression and decompression code. |
| 19 */ | 22 */ |
| 20 | 23 |
| 21 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ | 24 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ |
| 22 #include "jinclude.h" | 25 #include "jinclude.h" |
| 23 #include "jpeglib.h" | 26 #include "jpeglib.h" |
| 24 #include "jversion.h" | 27 #include "jversion.h" |
| 25 #include "jerror.h" | 28 #include "jerror.h" |
| 26 | 29 |
| 27 #ifdef USE_WINDOWS_MESSAGEBOX | 30 #ifdef USE_WINDOWS_MESSAGEBOX |
| 28 #include <windows.h> | 31 #include <windows.h> |
| 29 #endif | 32 #endif |
| 30 | 33 |
| 31 #ifndef EXIT_FAILURE» » /* define exit() codes if not provided */ | 34 #ifndef EXIT_FAILURE /* define exit() codes if not provided */ |
| 32 #define EXIT_FAILURE 1 | 35 #define EXIT_FAILURE 1 |
| 33 #endif | 36 #endif |
| 34 | 37 |
| 35 | 38 |
| 36 /* | 39 /* |
| 37 * Create the message string table. | 40 * Create the message string table. |
| 38 * We do this from the master message list in jerror.h by re-reading | 41 * We do this from the master message list in jerror.h by re-reading |
| 39 * jerror.h with a suitable definition for macro JMESSAGE. | 42 * jerror.h with a suitable definition for macro JMESSAGE. |
| 40 * The message table is made an external symbol just in case any applications | 43 * The message table is made an external symbol just in case any applications |
| 41 * want to refer to it directly. | 44 * want to refer to it directly. |
| 42 */ | 45 */ |
| 43 | 46 |
| 44 #ifdef NEED_SHORT_EXTERNAL_NAMES | 47 #define JMESSAGE(code,string) string , |
| 45 #define jpeg_std_message_table» jMsgTable | |
| 46 #endif | |
| 47 | |
| 48 #define JMESSAGE(code,string)» string , | |
| 49 | 48 |
| 50 const char * const jpeg_std_message_table[] = { | 49 const char * const jpeg_std_message_table[] = { |
| 51 #include "jerror.h" | 50 #include "jerror.h" |
| 52 NULL | 51 NULL |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 | 54 |
| 56 /* | 55 /* |
| 57 * Error exit handler: must not return to caller. | 56 * Error exit handler: must not return to caller. |
| 58 * | 57 * |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 output_message (j_common_ptr cinfo) | 97 output_message (j_common_ptr cinfo) |
| 99 { | 98 { |
| 100 char buffer[JMSG_LENGTH_MAX]; | 99 char buffer[JMSG_LENGTH_MAX]; |
| 101 | 100 |
| 102 /* Create the message */ | 101 /* Create the message */ |
| 103 (*cinfo->err->format_message) (cinfo, buffer); | 102 (*cinfo->err->format_message) (cinfo, buffer); |
| 104 | 103 |
| 105 #ifdef USE_WINDOWS_MESSAGEBOX | 104 #ifdef USE_WINDOWS_MESSAGEBOX |
| 106 /* Display it in a message dialog box */ | 105 /* Display it in a message dialog box */ |
| 107 MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", | 106 MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", |
| 108 » MB_OK | MB_ICONERROR); | 107 MB_OK | MB_ICONERROR); |
| 109 #else | 108 #else |
| 110 /* Send it to stderr, adding a newline */ | 109 /* Send it to stderr, adding a newline */ |
| 111 fprintf(stderr, "%s\n", buffer); | 110 fprintf(stderr, "%s\n", buffer); |
| 112 #endif | 111 #endif |
| 113 } | 112 } |
| 114 | 113 |
| 115 | 114 |
| 116 /* | 115 /* |
| 117 * Decide whether to emit a trace or warning message. | 116 * Decide whether to emit a trace or warning message. |
| 118 * msg_level is one of: | 117 * msg_level is one of: |
| 119 * -1: recoverable corrupt-data warning, may want to abort. | 118 * -1: recoverable corrupt-data warning, may want to abort. |
| 120 * 0: important advisory messages (always display to user). | 119 * 0: important advisory messages (always display to user). |
| 121 * 1: first level of tracing detail. | 120 * 1: first level of tracing detail. |
| 122 * 2,3,...: successively more detailed tracing messages. | 121 * 2,3,...: successively more detailed tracing messages. |
| 123 * An application might override this method if it wanted to abort on warnings | 122 * An application might override this method if it wanted to abort on warnings |
| 124 * or change the policy about which messages to display. | 123 * or change the policy about which messages to display. |
| 125 */ | 124 */ |
| 126 | 125 |
| 127 METHODDEF(void) | 126 METHODDEF(void) |
| 128 emit_message (j_common_ptr cinfo, int msg_level) | 127 emit_message (j_common_ptr cinfo, int msg_level) |
| 129 { | 128 { |
| 130 struct jpeg_error_mgr * err = cinfo->err; | 129 struct jpeg_error_mgr *err = cinfo->err; |
| 131 | 130 |
| 132 if (msg_level < 0) { | 131 if (msg_level < 0) { |
| 133 /* It's a warning message. Since corrupt files may generate many warnings, | 132 /* It's a warning message. Since corrupt files may generate many warnings, |
| 134 * the policy implemented here is to show only the first warning, | 133 * the policy implemented here is to show only the first warning, |
| 135 * unless trace_level >= 3. | 134 * unless trace_level >= 3. |
| 136 */ | 135 */ |
| 137 if (err->num_warnings == 0 || err->trace_level >= 3) | 136 if (err->num_warnings == 0 || err->trace_level >= 3) |
| 138 (*err->output_message) (cinfo); | 137 (*err->output_message) (cinfo); |
| 139 /* Always count warnings in num_warnings. */ | 138 /* Always count warnings in num_warnings. */ |
| 140 err->num_warnings++; | 139 err->num_warnings++; |
| 141 } else { | 140 } else { |
| 142 /* It's a trace message. Show it if trace_level >= msg_level. */ | 141 /* It's a trace message. Show it if trace_level >= msg_level. */ |
| 143 if (err->trace_level >= msg_level) | 142 if (err->trace_level >= msg_level) |
| 144 (*err->output_message) (cinfo); | 143 (*err->output_message) (cinfo); |
| 145 } | 144 } |
| 146 } | 145 } |
| 147 | 146 |
| 148 | 147 |
| 149 /* | 148 /* |
| 150 * Format a message string for the most recent JPEG error or message. | 149 * Format a message string for the most recent JPEG error or message. |
| 151 * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX | 150 * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX |
| 152 * characters. Note that no '\n' character is added to the string. | 151 * characters. Note that no '\n' character is added to the string. |
| 153 * Few applications should need to override this method. | 152 * Few applications should need to override this method. |
| 154 */ | 153 */ |
| 155 | 154 |
| 156 METHODDEF(void) | 155 METHODDEF(void) |
| 157 format_message (j_common_ptr cinfo, char * buffer) | 156 format_message (j_common_ptr cinfo, char *buffer) |
| 158 { | 157 { |
| 159 struct jpeg_error_mgr * err = cinfo->err; | 158 struct jpeg_error_mgr *err = cinfo->err; |
| 160 int msg_code = err->msg_code; | 159 int msg_code = err->msg_code; |
| 161 const char * msgtext = NULL; | 160 const char *msgtext = NULL; |
| 162 const char * msgptr; | 161 const char *msgptr; |
| 163 char ch; | 162 char ch; |
| 164 boolean isstring; | 163 boolean isstring; |
| 165 | 164 |
| 166 /* Look up message string in proper table */ | 165 /* Look up message string in proper table */ |
| 167 if (msg_code > 0 && msg_code <= err->last_jpeg_message) { | 166 if (msg_code > 0 && msg_code <= err->last_jpeg_message) { |
| 168 msgtext = err->jpeg_message_table[msg_code]; | 167 msgtext = err->jpeg_message_table[msg_code]; |
| 169 } else if (err->addon_message_table != NULL && | 168 } else if (err->addon_message_table != NULL && |
| 170 » msg_code >= err->first_addon_message && | 169 msg_code >= err->first_addon_message && |
| 171 » msg_code <= err->last_addon_message) { | 170 msg_code <= err->last_addon_message) { |
| 172 msgtext = err->addon_message_table[msg_code - err->first_addon_message]; | 171 msgtext = err->addon_message_table[msg_code - err->first_addon_message]; |
| 173 } | 172 } |
| 174 | 173 |
| 175 /* Defend against bogus message number */ | 174 /* Defend against bogus message number */ |
| 176 if (msgtext == NULL) { | 175 if (msgtext == NULL) { |
| 177 err->msg_parm.i[0] = msg_code; | 176 err->msg_parm.i[0] = msg_code; |
| 178 msgtext = err->jpeg_message_table[0]; | 177 msgtext = err->jpeg_message_table[0]; |
| 179 } | 178 } |
| 180 | 179 |
| 181 /* Check for string parameter, as indicated by %s in the message text */ | 180 /* Check for string parameter, as indicated by %s in the message text */ |
| 182 isstring = FALSE; | 181 isstring = FALSE; |
| 183 msgptr = msgtext; | 182 msgptr = msgtext; |
| 184 while ((ch = *msgptr++) != '\0') { | 183 while ((ch = *msgptr++) != '\0') { |
| 185 if (ch == '%') { | 184 if (ch == '%') { |
| 186 if (*msgptr == 's') isstring = TRUE; | 185 if (*msgptr == 's') isstring = TRUE; |
| 187 break; | 186 break; |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 191 /* Format the message into the passed buffer */ | 190 /* Format the message into the passed buffer */ |
| 192 if (isstring) | 191 if (isstring) |
| 193 sprintf(buffer, msgtext, err->msg_parm.s); | 192 sprintf(buffer, msgtext, err->msg_parm.s); |
| 194 else | 193 else |
| 195 sprintf(buffer, msgtext, | 194 sprintf(buffer, msgtext, |
| 196 » err->msg_parm.i[0], err->msg_parm.i[1], | 195 err->msg_parm.i[0], err->msg_parm.i[1], |
| 197 » err->msg_parm.i[2], err->msg_parm.i[3], | 196 err->msg_parm.i[2], err->msg_parm.i[3], |
| 198 » err->msg_parm.i[4], err->msg_parm.i[5], | 197 err->msg_parm.i[4], err->msg_parm.i[5], |
| 199 » err->msg_parm.i[6], err->msg_parm.i[7]); | 198 err->msg_parm.i[6], err->msg_parm.i[7]); |
| 200 } | 199 } |
| 201 | 200 |
| 202 | 201 |
| 203 /* | 202 /* |
| 204 * Reset error state variables at start of a new image. | 203 * Reset error state variables at start of a new image. |
| 205 * This is called during compression startup to reset trace/error | 204 * This is called during compression startup to reset trace/error |
| 206 * processing to default state, without losing any application-specific | 205 * processing to default state, without losing any application-specific |
| 207 * method pointers. An application might possibly want to override | 206 * method pointers. An application might possibly want to override |
| 208 * this method if it has additional error processing state. | 207 * this method if it has additional error processing state. |
| 209 */ | 208 */ |
| 210 | 209 |
| 211 METHODDEF(void) | 210 METHODDEF(void) |
| 212 reset_error_mgr (j_common_ptr cinfo) | 211 reset_error_mgr (j_common_ptr cinfo) |
| 213 { | 212 { |
| 214 cinfo->err->num_warnings = 0; | 213 cinfo->err->num_warnings = 0; |
| 215 /* trace_level is not reset since it is an application-supplied parameter */ | 214 /* trace_level is not reset since it is an application-supplied parameter */ |
| 216 cinfo->err->msg_code = 0;» /* may be useful as a flag for "no error" */ | 215 cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ |
| 217 } | 216 } |
| 218 | 217 |
| 219 | 218 |
| 220 /* | 219 /* |
| 221 * Fill in the standard error-handling methods in a jpeg_error_mgr object. | 220 * Fill in the standard error-handling methods in a jpeg_error_mgr object. |
| 222 * Typical call is: | 221 * Typical call is: |
| 223 *» struct jpeg_compress_struct cinfo; | 222 * struct jpeg_compress_struct cinfo; |
| 224 *» struct jpeg_error_mgr err; | 223 * struct jpeg_error_mgr err; |
| 225 * | 224 * |
| 226 *» cinfo.err = jpeg_std_error(&err); | 225 * cinfo.err = jpeg_std_error(&err); |
| 227 * after which the application may override some of the methods. | 226 * after which the application may override some of the methods. |
| 228 */ | 227 */ |
| 229 | 228 |
| 230 GLOBAL(struct jpeg_error_mgr *) | 229 GLOBAL(struct jpeg_error_mgr *) |
| 231 jpeg_std_error (struct jpeg_error_mgr * err) | 230 jpeg_std_error (struct jpeg_error_mgr *err) |
| 232 { | 231 { |
| 233 err->error_exit = error_exit; | 232 err->error_exit = error_exit; |
| 234 err->emit_message = emit_message; | 233 err->emit_message = emit_message; |
| 235 err->output_message = output_message; | 234 err->output_message = output_message; |
| 236 err->format_message = format_message; | 235 err->format_message = format_message; |
| 237 err->reset_error_mgr = reset_error_mgr; | 236 err->reset_error_mgr = reset_error_mgr; |
| 238 | 237 |
| 239 err->trace_level = 0;»» /* default = no tracing */ | 238 err->trace_level = 0; /* default = no tracing */ |
| 240 err->num_warnings = 0;» /* no warnings emitted yet */ | 239 err->num_warnings = 0; /* no warnings emitted yet */ |
| 241 err->msg_code = 0;» » /* may be useful as a flag for "no error" */ | 240 err->msg_code = 0; /* may be useful as a flag for "no error" */ |
| 242 | 241 |
| 243 /* Initialize message table pointers */ | 242 /* Initialize message table pointers */ |
| 244 err->jpeg_message_table = jpeg_std_message_table; | 243 err->jpeg_message_table = jpeg_std_message_table; |
| 245 err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; | 244 err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; |
| 246 | 245 |
| 247 err->addon_message_table = NULL; | 246 err->addon_message_table = NULL; |
| 248 err->first_addon_message = 0;»/* for safety */ | 247 err->first_addon_message = 0; /* for safety */ |
| 249 err->last_addon_message = 0; | 248 err->last_addon_message = 0; |
| 250 | 249 |
| 251 return err; | 250 return err; |
| 252 } | 251 } |
| OLD | NEW |