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