Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/jerror.c@0:791a779d6220, 2017-07-31 (annotated)
- Committer:
- shoaib_ahmed
- Date:
- Mon Jul 31 09:16:35 2017 +0000
- Revision:
- 0:791a779d6220
final project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shoaib_ahmed | 0:791a779d6220 | 1 | /* |
shoaib_ahmed | 0:791a779d6220 | 2 | * jerror.c |
shoaib_ahmed | 0:791a779d6220 | 3 | * |
shoaib_ahmed | 0:791a779d6220 | 4 | * Copyright (C) 1991-1998, Thomas G. Lane. |
shoaib_ahmed | 0:791a779d6220 | 5 | * Modified 2012-2015 by Guido Vollbeding. |
shoaib_ahmed | 0:791a779d6220 | 6 | * This file is part of the Independent JPEG Group's software. |
shoaib_ahmed | 0:791a779d6220 | 7 | * For conditions of distribution and use, see the accompanying README file. |
shoaib_ahmed | 0:791a779d6220 | 8 | * |
shoaib_ahmed | 0:791a779d6220 | 9 | * This file contains simple error-reporting and trace-message routines. |
shoaib_ahmed | 0:791a779d6220 | 10 | * These are suitable for Unix-like systems and others where writing to |
shoaib_ahmed | 0:791a779d6220 | 11 | * stderr is the right thing to do. Many applications will want to replace |
shoaib_ahmed | 0:791a779d6220 | 12 | * some or all of these routines. |
shoaib_ahmed | 0:791a779d6220 | 13 | * |
shoaib_ahmed | 0:791a779d6220 | 14 | * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, |
shoaib_ahmed | 0:791a779d6220 | 15 | * you get a Windows-specific hack to display error messages in a dialog box. |
shoaib_ahmed | 0:791a779d6220 | 16 | * It ain't much, but it beats dropping error messages into the bit bucket, |
shoaib_ahmed | 0:791a779d6220 | 17 | * which is what happens to output to stderr under most Windows C compilers. |
shoaib_ahmed | 0:791a779d6220 | 18 | * |
shoaib_ahmed | 0:791a779d6220 | 19 | * These routines are used by both the compression and decompression code. |
shoaib_ahmed | 0:791a779d6220 | 20 | */ |
shoaib_ahmed | 0:791a779d6220 | 21 | |
shoaib_ahmed | 0:791a779d6220 | 22 | #ifdef USE_WINDOWS_MESSAGEBOX |
shoaib_ahmed | 0:791a779d6220 | 23 | #include <windows.h> |
shoaib_ahmed | 0:791a779d6220 | 24 | #endif |
shoaib_ahmed | 0:791a779d6220 | 25 | |
shoaib_ahmed | 0:791a779d6220 | 26 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ |
shoaib_ahmed | 0:791a779d6220 | 27 | #include "jinclude.h" |
shoaib_ahmed | 0:791a779d6220 | 28 | #include "jpeglib.h" |
shoaib_ahmed | 0:791a779d6220 | 29 | #include "jversion.h" |
shoaib_ahmed | 0:791a779d6220 | 30 | #include "jerror.h" |
shoaib_ahmed | 0:791a779d6220 | 31 | |
shoaib_ahmed | 0:791a779d6220 | 32 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ |
shoaib_ahmed | 0:791a779d6220 | 33 | #define EXIT_FAILURE 1 |
shoaib_ahmed | 0:791a779d6220 | 34 | #endif |
shoaib_ahmed | 0:791a779d6220 | 35 | |
shoaib_ahmed | 0:791a779d6220 | 36 | |
shoaib_ahmed | 0:791a779d6220 | 37 | /* |
shoaib_ahmed | 0:791a779d6220 | 38 | * Create the message string table. |
shoaib_ahmed | 0:791a779d6220 | 39 | * We do this from the master message list in jerror.h by re-reading |
shoaib_ahmed | 0:791a779d6220 | 40 | * jerror.h with a suitable definition for macro JMESSAGE. |
shoaib_ahmed | 0:791a779d6220 | 41 | * The message table is made an external symbol just in case any applications |
shoaib_ahmed | 0:791a779d6220 | 42 | * want to refer to it directly. |
shoaib_ahmed | 0:791a779d6220 | 43 | */ |
shoaib_ahmed | 0:791a779d6220 | 44 | |
shoaib_ahmed | 0:791a779d6220 | 45 | #ifdef NEED_SHORT_EXTERNAL_NAMES |
shoaib_ahmed | 0:791a779d6220 | 46 | #define jpeg_std_message_table jMsgTable |
shoaib_ahmed | 0:791a779d6220 | 47 | #endif |
shoaib_ahmed | 0:791a779d6220 | 48 | |
shoaib_ahmed | 0:791a779d6220 | 49 | #define JMESSAGE(code,string) string , |
shoaib_ahmed | 0:791a779d6220 | 50 | |
shoaib_ahmed | 0:791a779d6220 | 51 | const char * const jpeg_std_message_table[] = { |
shoaib_ahmed | 0:791a779d6220 | 52 | #include "jerror.h" |
shoaib_ahmed | 0:791a779d6220 | 53 | NULL |
shoaib_ahmed | 0:791a779d6220 | 54 | }; |
shoaib_ahmed | 0:791a779d6220 | 55 | |
shoaib_ahmed | 0:791a779d6220 | 56 | |
shoaib_ahmed | 0:791a779d6220 | 57 | /* |
shoaib_ahmed | 0:791a779d6220 | 58 | * Error exit handler: must not return to caller. |
shoaib_ahmed | 0:791a779d6220 | 59 | * |
shoaib_ahmed | 0:791a779d6220 | 60 | * Applications may override this if they want to get control back after |
shoaib_ahmed | 0:791a779d6220 | 61 | * an error. Typically one would longjmp somewhere instead of exiting. |
shoaib_ahmed | 0:791a779d6220 | 62 | * The setjmp buffer can be made a private field within an expanded error |
shoaib_ahmed | 0:791a779d6220 | 63 | * handler object. Note that the info needed to generate an error message |
shoaib_ahmed | 0:791a779d6220 | 64 | * is stored in the error object, so you can generate the message now or |
shoaib_ahmed | 0:791a779d6220 | 65 | * later, at your convenience. |
shoaib_ahmed | 0:791a779d6220 | 66 | * You should make sure that the JPEG object is cleaned up (with jpeg_abort |
shoaib_ahmed | 0:791a779d6220 | 67 | * or jpeg_destroy) at some point. |
shoaib_ahmed | 0:791a779d6220 | 68 | */ |
shoaib_ahmed | 0:791a779d6220 | 69 | |
shoaib_ahmed | 0:791a779d6220 | 70 | METHODDEF(noreturn_t) |
shoaib_ahmed | 0:791a779d6220 | 71 | error_exit (j_common_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 72 | { |
shoaib_ahmed | 0:791a779d6220 | 73 | /* Always display the message */ |
shoaib_ahmed | 0:791a779d6220 | 74 | (*cinfo->err->output_message) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 75 | |
shoaib_ahmed | 0:791a779d6220 | 76 | /* Let the memory manager delete any temp files before we die */ |
shoaib_ahmed | 0:791a779d6220 | 77 | jpeg_destroy(cinfo); |
shoaib_ahmed | 0:791a779d6220 | 78 | |
shoaib_ahmed | 0:791a779d6220 | 79 | exit(EXIT_FAILURE); |
shoaib_ahmed | 0:791a779d6220 | 80 | } |
shoaib_ahmed | 0:791a779d6220 | 81 | |
shoaib_ahmed | 0:791a779d6220 | 82 | |
shoaib_ahmed | 0:791a779d6220 | 83 | /* |
shoaib_ahmed | 0:791a779d6220 | 84 | * Actual output of an error or trace message. |
shoaib_ahmed | 0:791a779d6220 | 85 | * Applications may override this method to send JPEG messages somewhere |
shoaib_ahmed | 0:791a779d6220 | 86 | * other than stderr. |
shoaib_ahmed | 0:791a779d6220 | 87 | * |
shoaib_ahmed | 0:791a779d6220 | 88 | * On Windows, printing to stderr is generally completely useless, |
shoaib_ahmed | 0:791a779d6220 | 89 | * so we provide optional code to produce an error-dialog popup. |
shoaib_ahmed | 0:791a779d6220 | 90 | * Most Windows applications will still prefer to override this routine, |
shoaib_ahmed | 0:791a779d6220 | 91 | * but if they don't, it'll do something at least marginally useful. |
shoaib_ahmed | 0:791a779d6220 | 92 | * |
shoaib_ahmed | 0:791a779d6220 | 93 | * NOTE: to use the library in an environment that doesn't support the |
shoaib_ahmed | 0:791a779d6220 | 94 | * C stdio library, you may have to delete the call to fprintf() entirely, |
shoaib_ahmed | 0:791a779d6220 | 95 | * not just not use this routine. |
shoaib_ahmed | 0:791a779d6220 | 96 | */ |
shoaib_ahmed | 0:791a779d6220 | 97 | |
shoaib_ahmed | 0:791a779d6220 | 98 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 99 | output_message (j_common_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 100 | { |
shoaib_ahmed | 0:791a779d6220 | 101 | char buffer[JMSG_LENGTH_MAX]; |
shoaib_ahmed | 0:791a779d6220 | 102 | |
shoaib_ahmed | 0:791a779d6220 | 103 | /* Create the message */ |
shoaib_ahmed | 0:791a779d6220 | 104 | (*cinfo->err->format_message) (cinfo, buffer); |
shoaib_ahmed | 0:791a779d6220 | 105 | |
shoaib_ahmed | 0:791a779d6220 | 106 | #ifdef USE_WINDOWS_MESSAGEBOX |
shoaib_ahmed | 0:791a779d6220 | 107 | /* Display it in a message dialog box */ |
shoaib_ahmed | 0:791a779d6220 | 108 | MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", |
shoaib_ahmed | 0:791a779d6220 | 109 | MB_OK | MB_ICONERROR); |
shoaib_ahmed | 0:791a779d6220 | 110 | #else |
shoaib_ahmed | 0:791a779d6220 | 111 | /* Send it to stderr, adding a newline */ |
shoaib_ahmed | 0:791a779d6220 | 112 | fprintf(stderr, "%s\n", buffer); |
shoaib_ahmed | 0:791a779d6220 | 113 | #endif |
shoaib_ahmed | 0:791a779d6220 | 114 | } |
shoaib_ahmed | 0:791a779d6220 | 115 | |
shoaib_ahmed | 0:791a779d6220 | 116 | |
shoaib_ahmed | 0:791a779d6220 | 117 | /* |
shoaib_ahmed | 0:791a779d6220 | 118 | * Decide whether to emit a trace or warning message. |
shoaib_ahmed | 0:791a779d6220 | 119 | * msg_level is one of: |
shoaib_ahmed | 0:791a779d6220 | 120 | * -1: recoverable corrupt-data warning, may want to abort. |
shoaib_ahmed | 0:791a779d6220 | 121 | * 0: important advisory messages (always display to user). |
shoaib_ahmed | 0:791a779d6220 | 122 | * 1: first level of tracing detail. |
shoaib_ahmed | 0:791a779d6220 | 123 | * 2,3,...: successively more detailed tracing messages. |
shoaib_ahmed | 0:791a779d6220 | 124 | * An application might override this method if it wanted to abort on warnings |
shoaib_ahmed | 0:791a779d6220 | 125 | * or change the policy about which messages to display. |
shoaib_ahmed | 0:791a779d6220 | 126 | */ |
shoaib_ahmed | 0:791a779d6220 | 127 | |
shoaib_ahmed | 0:791a779d6220 | 128 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 129 | emit_message (j_common_ptr cinfo, int msg_level) |
shoaib_ahmed | 0:791a779d6220 | 130 | { |
shoaib_ahmed | 0:791a779d6220 | 131 | struct jpeg_error_mgr * err = cinfo->err; |
shoaib_ahmed | 0:791a779d6220 | 132 | |
shoaib_ahmed | 0:791a779d6220 | 133 | if (msg_level < 0) { |
shoaib_ahmed | 0:791a779d6220 | 134 | /* It's a warning message. Since corrupt files may generate many warnings, |
shoaib_ahmed | 0:791a779d6220 | 135 | * the policy implemented here is to show only the first warning, |
shoaib_ahmed | 0:791a779d6220 | 136 | * unless trace_level >= 3. |
shoaib_ahmed | 0:791a779d6220 | 137 | */ |
shoaib_ahmed | 0:791a779d6220 | 138 | if (err->num_warnings == 0 || err->trace_level >= 3) |
shoaib_ahmed | 0:791a779d6220 | 139 | (*err->output_message) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 140 | /* Always count warnings in num_warnings. */ |
shoaib_ahmed | 0:791a779d6220 | 141 | err->num_warnings++; |
shoaib_ahmed | 0:791a779d6220 | 142 | } else { |
shoaib_ahmed | 0:791a779d6220 | 143 | /* It's a trace message. Show it if trace_level >= msg_level. */ |
shoaib_ahmed | 0:791a779d6220 | 144 | if (err->trace_level >= msg_level) |
shoaib_ahmed | 0:791a779d6220 | 145 | (*err->output_message) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 146 | } |
shoaib_ahmed | 0:791a779d6220 | 147 | } |
shoaib_ahmed | 0:791a779d6220 | 148 | |
shoaib_ahmed | 0:791a779d6220 | 149 | |
shoaib_ahmed | 0:791a779d6220 | 150 | /* |
shoaib_ahmed | 0:791a779d6220 | 151 | * Format a message string for the most recent JPEG error or message. |
shoaib_ahmed | 0:791a779d6220 | 152 | * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX |
shoaib_ahmed | 0:791a779d6220 | 153 | * characters. Note that no '\n' character is added to the string. |
shoaib_ahmed | 0:791a779d6220 | 154 | * Few applications should need to override this method. |
shoaib_ahmed | 0:791a779d6220 | 155 | */ |
shoaib_ahmed | 0:791a779d6220 | 156 | |
shoaib_ahmed | 0:791a779d6220 | 157 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 158 | format_message (j_common_ptr cinfo, char * buffer) |
shoaib_ahmed | 0:791a779d6220 | 159 | { |
shoaib_ahmed | 0:791a779d6220 | 160 | struct jpeg_error_mgr * err = cinfo->err; |
shoaib_ahmed | 0:791a779d6220 | 161 | int msg_code = err->msg_code; |
shoaib_ahmed | 0:791a779d6220 | 162 | const char * msgtext = NULL; |
shoaib_ahmed | 0:791a779d6220 | 163 | const char * msgptr; |
shoaib_ahmed | 0:791a779d6220 | 164 | char ch; |
shoaib_ahmed | 0:791a779d6220 | 165 | boolean isstring; |
shoaib_ahmed | 0:791a779d6220 | 166 | |
shoaib_ahmed | 0:791a779d6220 | 167 | /* Look up message string in proper table */ |
shoaib_ahmed | 0:791a779d6220 | 168 | if (msg_code > 0 && msg_code <= err->last_jpeg_message) { |
shoaib_ahmed | 0:791a779d6220 | 169 | msgtext = err->jpeg_message_table[msg_code]; |
shoaib_ahmed | 0:791a779d6220 | 170 | } else if (err->addon_message_table != NULL && |
shoaib_ahmed | 0:791a779d6220 | 171 | msg_code >= err->first_addon_message && |
shoaib_ahmed | 0:791a779d6220 | 172 | msg_code <= err->last_addon_message) { |
shoaib_ahmed | 0:791a779d6220 | 173 | msgtext = err->addon_message_table[msg_code - err->first_addon_message]; |
shoaib_ahmed | 0:791a779d6220 | 174 | } |
shoaib_ahmed | 0:791a779d6220 | 175 | |
shoaib_ahmed | 0:791a779d6220 | 176 | /* Defend against bogus message number */ |
shoaib_ahmed | 0:791a779d6220 | 177 | if (msgtext == NULL) { |
shoaib_ahmed | 0:791a779d6220 | 178 | err->msg_parm.i[0] = msg_code; |
shoaib_ahmed | 0:791a779d6220 | 179 | msgtext = err->jpeg_message_table[0]; |
shoaib_ahmed | 0:791a779d6220 | 180 | } |
shoaib_ahmed | 0:791a779d6220 | 181 | |
shoaib_ahmed | 0:791a779d6220 | 182 | /* Check for string parameter, as indicated by %s in the message text */ |
shoaib_ahmed | 0:791a779d6220 | 183 | isstring = FALSE; |
shoaib_ahmed | 0:791a779d6220 | 184 | msgptr = msgtext; |
shoaib_ahmed | 0:791a779d6220 | 185 | while ((ch = *msgptr++) != '\0') { |
shoaib_ahmed | 0:791a779d6220 | 186 | if (ch == '%') { |
shoaib_ahmed | 0:791a779d6220 | 187 | if (*msgptr == 's') isstring = TRUE; |
shoaib_ahmed | 0:791a779d6220 | 188 | break; |
shoaib_ahmed | 0:791a779d6220 | 189 | } |
shoaib_ahmed | 0:791a779d6220 | 190 | } |
shoaib_ahmed | 0:791a779d6220 | 191 | |
shoaib_ahmed | 0:791a779d6220 | 192 | /* Format the message into the passed buffer */ |
shoaib_ahmed | 0:791a779d6220 | 193 | if (isstring) |
shoaib_ahmed | 0:791a779d6220 | 194 | sprintf(buffer, msgtext, err->msg_parm.s); |
shoaib_ahmed | 0:791a779d6220 | 195 | else |
shoaib_ahmed | 0:791a779d6220 | 196 | sprintf(buffer, msgtext, |
shoaib_ahmed | 0:791a779d6220 | 197 | err->msg_parm.i[0], err->msg_parm.i[1], |
shoaib_ahmed | 0:791a779d6220 | 198 | err->msg_parm.i[2], err->msg_parm.i[3], |
shoaib_ahmed | 0:791a779d6220 | 199 | err->msg_parm.i[4], err->msg_parm.i[5], |
shoaib_ahmed | 0:791a779d6220 | 200 | err->msg_parm.i[6], err->msg_parm.i[7]); |
shoaib_ahmed | 0:791a779d6220 | 201 | } |
shoaib_ahmed | 0:791a779d6220 | 202 | |
shoaib_ahmed | 0:791a779d6220 | 203 | |
shoaib_ahmed | 0:791a779d6220 | 204 | /* |
shoaib_ahmed | 0:791a779d6220 | 205 | * Reset error state variables at start of a new image. |
shoaib_ahmed | 0:791a779d6220 | 206 | * This is called during compression startup to reset trace/error |
shoaib_ahmed | 0:791a779d6220 | 207 | * processing to default state, without losing any application-specific |
shoaib_ahmed | 0:791a779d6220 | 208 | * method pointers. An application might possibly want to override |
shoaib_ahmed | 0:791a779d6220 | 209 | * this method if it has additional error processing state. |
shoaib_ahmed | 0:791a779d6220 | 210 | */ |
shoaib_ahmed | 0:791a779d6220 | 211 | |
shoaib_ahmed | 0:791a779d6220 | 212 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 213 | reset_error_mgr (j_common_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 214 | { |
shoaib_ahmed | 0:791a779d6220 | 215 | cinfo->err->num_warnings = 0; |
shoaib_ahmed | 0:791a779d6220 | 216 | /* trace_level is not reset since it is an application-supplied parameter */ |
shoaib_ahmed | 0:791a779d6220 | 217 | cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ |
shoaib_ahmed | 0:791a779d6220 | 218 | } |
shoaib_ahmed | 0:791a779d6220 | 219 | |
shoaib_ahmed | 0:791a779d6220 | 220 | |
shoaib_ahmed | 0:791a779d6220 | 221 | /* |
shoaib_ahmed | 0:791a779d6220 | 222 | * Fill in the standard error-handling methods in a jpeg_error_mgr object. |
shoaib_ahmed | 0:791a779d6220 | 223 | * Typical call is: |
shoaib_ahmed | 0:791a779d6220 | 224 | * struct jpeg_compress_struct cinfo; |
shoaib_ahmed | 0:791a779d6220 | 225 | * struct jpeg_error_mgr err; |
shoaib_ahmed | 0:791a779d6220 | 226 | * |
shoaib_ahmed | 0:791a779d6220 | 227 | * cinfo.err = jpeg_std_error(&err); |
shoaib_ahmed | 0:791a779d6220 | 228 | * after which the application may override some of the methods. |
shoaib_ahmed | 0:791a779d6220 | 229 | */ |
shoaib_ahmed | 0:791a779d6220 | 230 | |
shoaib_ahmed | 0:791a779d6220 | 231 | GLOBAL(struct jpeg_error_mgr *) |
shoaib_ahmed | 0:791a779d6220 | 232 | jpeg_std_error (struct jpeg_error_mgr * err) |
shoaib_ahmed | 0:791a779d6220 | 233 | { |
shoaib_ahmed | 0:791a779d6220 | 234 | err->error_exit = error_exit; |
shoaib_ahmed | 0:791a779d6220 | 235 | err->emit_message = emit_message; |
shoaib_ahmed | 0:791a779d6220 | 236 | err->output_message = output_message; |
shoaib_ahmed | 0:791a779d6220 | 237 | err->format_message = format_message; |
shoaib_ahmed | 0:791a779d6220 | 238 | err->reset_error_mgr = reset_error_mgr; |
shoaib_ahmed | 0:791a779d6220 | 239 | |
shoaib_ahmed | 0:791a779d6220 | 240 | err->trace_level = 0; /* default = no tracing */ |
shoaib_ahmed | 0:791a779d6220 | 241 | err->num_warnings = 0; /* no warnings emitted yet */ |
shoaib_ahmed | 0:791a779d6220 | 242 | err->msg_code = 0; /* may be useful as a flag for "no error" */ |
shoaib_ahmed | 0:791a779d6220 | 243 | |
shoaib_ahmed | 0:791a779d6220 | 244 | /* Initialize message table pointers */ |
shoaib_ahmed | 0:791a779d6220 | 245 | err->jpeg_message_table = jpeg_std_message_table; |
shoaib_ahmed | 0:791a779d6220 | 246 | err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; |
shoaib_ahmed | 0:791a779d6220 | 247 | |
shoaib_ahmed | 0:791a779d6220 | 248 | err->addon_message_table = NULL; |
shoaib_ahmed | 0:791a779d6220 | 249 | err->first_addon_message = 0; /* for safety */ |
shoaib_ahmed | 0:791a779d6220 | 250 | err->last_addon_message = 0; |
shoaib_ahmed | 0:791a779d6220 | 251 | |
shoaib_ahmed | 0:791a779d6220 | 252 | return err; |
shoaib_ahmed | 0:791a779d6220 | 253 | } |