-/*\r
- * jerror.c\r
- *\r
- * Copyright (C) 1991-1994, Thomas G. Lane.\r
- * This file is part of the Independent JPEG Group's software.\r
- * For conditions of distribution and use, see the accompanying README file.\r
- *\r
- * This file contains simple error-reporting and trace-message routines.\r
- * These are suitable for Unix-like systems and others where writing to\r
- * stderr is the right thing to do. Many applications will want to replace\r
- * some or all of these routines.\r
- *\r
- * These routines are used by both the compression and decompression code.\r
- */\r
-\r
-/* this is not a core library module, so it doesn't define JPEG_INTERNALS */\r
-#include "jinclude.h"\r
-#include "radiant_jpeglib.h"\r
-#include "jversion.h"\r
-#include "jerror.h"\r
-\r
-#ifndef EXIT_FAILURE /* define exit() codes if not provided */\r
-#define EXIT_FAILURE 1\r
-#endif\r
-\r
-\r
-/*\r
- * Create the message string table.\r
- * We do this from the master message list in jerror.h by re-reading\r
- * jerror.h with a suitable definition for macro JMESSAGE.\r
- * The message table is made an external symbol just in case any applications\r
- * want to refer to it directly.\r
- */\r
-\r
-#ifdef NEED_SHORT_EXTERNAL_NAMES\r
-#define jpeg_std_message_table jMsgTable\r
-#endif\r
-\r
-#define JMESSAGE(code,string) string ,\r
-\r
-const char * const jpeg_std_message_table[] = {\r
-#include "jerror.h"\r
- NULL\r
-};\r
-\r
-// Rad additions, longjmp out of the LoadJPGBuff\r
-GLOBAL jmp_buf rad_loadfailed;\r
-GLOBAL char rad_errormsg[JMSG_LENGTH_MAX];\r
-\r
-/*\r
- * Error exit handler: must not return to caller.\r
- *\r
- * Applications may override this if they want to get control back after\r
- * an error. Typically one would longjmp somewhere instead of exiting.\r
- * The setjmp buffer can be made a private field within an expanded error\r
- * handler object. Note that the info needed to generate an error message\r
- * is stored in the error object, so you can generate the message now or\r
- * later, at your convenience.\r
- * You should make sure that the JPEG object is cleaned up (with jpeg_abort\r
- * or jpeg_destroy) at some point.\r
- */\r
-\r
-METHODDEF void\r
-error_exit (j_common_ptr cinfo)\r
-{\r
-// char buffer[JMSG_LENGTH_MAX];\r
-\r
- /* Create the message */\r
- (*cinfo->err->format_message) (cinfo,rad_errormsg);\r
-\r
- /* Let the memory manager delete any temp files before we die */\r
- jpeg_destroy(cinfo);\r
-\r
- longjmp( rad_loadfailed, -1 );\r
-}\r
-\r
-\r
-/*\r
- * Actual output of an error or trace message.\r
- * Applications may override this method to send JPEG messages somewhere\r
- * other than stderr.\r
- */\r
-\r
-METHODDEF void\r
-output_message (j_common_ptr cinfo)\r
-{\r
- char buffer[JMSG_LENGTH_MAX];\r
-\r
- /* Create the message */\r
- (*cinfo->err->format_message) (cinfo, buffer);\r
-\r
- /* Send it to stderr, adding a newline */\r
- printf("%s\n", buffer);\r
-}\r
-\r
-\r
-/*\r
- * Decide whether to emit a trace or warning message.\r
- * msg_level is one of:\r
- * -1: recoverable corrupt-data warning, may want to abort.\r
- * 0: important advisory messages (always display to user).\r
- * 1: first level of tracing detail.\r
- * 2,3,...: successively more detailed tracing messages.\r
- * An application might override this method if it wanted to abort on warnings\r
- * or change the policy about which messages to display.\r
- */\r
-\r
-METHODDEF void\r
-emit_message (j_common_ptr cinfo, int msg_level)\r
-{\r
- struct jpeg_error_mgr * err = cinfo->err;\r
-\r
- if (msg_level < 0) {\r
- /* It's a warning message. Since corrupt files may generate many warnings,\r
- * the policy implemented here is to show only the first warning,\r
- * unless trace_level >= 3.\r
- */\r
- if (err->num_warnings == 0 || err->trace_level >= 3)\r
- (*err->output_message) (cinfo);\r
- /* Always count warnings in num_warnings. */\r
- err->num_warnings++;\r
- } else {\r
- /* It's a trace message. Show it if trace_level >= msg_level. */\r
- if (err->trace_level >= msg_level)\r
- (*err->output_message) (cinfo);\r
- }\r
-}\r
-\r
-\r
-/*\r
- * Format a message string for the most recent JPEG error or message.\r
- * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX\r
- * characters. Note that no '\n' character is added to the string.\r
- * Few applications should need to override this method.\r
- */\r
-\r
-METHODDEF void\r
-format_message (j_common_ptr cinfo, char * buffer)\r
-{\r
- struct jpeg_error_mgr * err = cinfo->err;\r
- int msg_code = err->msg_code;\r
- const char * msgtext = NULL;\r
- const char * msgptr;\r
- char ch;\r
- boolean isstring;\r
-\r
- /* Look up message string in proper table */\r
- if (msg_code > 0 && msg_code <= err->last_jpeg_message) {\r
- msgtext = err->jpeg_message_table[msg_code];\r
- } else if (err->addon_message_table != NULL &&\r
- msg_code >= err->first_addon_message &&\r
- msg_code <= err->last_addon_message) {\r
- msgtext = err->addon_message_table[msg_code - err->first_addon_message];\r
- }\r
-\r
- /* Defend against bogus message number */\r
- if (msgtext == NULL) {\r
- err->msg_parm.i[0] = msg_code;\r
- msgtext = err->jpeg_message_table[0];\r
- }\r
-\r
- /* Check for string parameter, as indicated by %s in the message text */\r
- isstring = FALSE;\r
- msgptr = msgtext;\r
- while ((ch = *msgptr++) != '\0') {\r
- if (ch == '%') {\r
- if (*msgptr == 's') isstring = TRUE;\r
- break;\r
- }\r
- }\r
-\r
- /* Format the message into the passed buffer */\r
- if (isstring)\r
- sprintf(buffer, msgtext, err->msg_parm.s);\r
- else\r
- sprintf(buffer, msgtext,\r
- err->msg_parm.i[0], err->msg_parm.i[1],\r
- err->msg_parm.i[2], err->msg_parm.i[3],\r
- err->msg_parm.i[4], err->msg_parm.i[5],\r
- err->msg_parm.i[6], err->msg_parm.i[7]);\r
-}\r
-\r
-\r
-/*\r
- * Reset error state variables at start of a new image.\r
- * This is called during compression startup to reset trace/error\r
- * processing to default state, without losing any application-specific\r
- * method pointers. An application might possibly want to override\r
- * this method if it has additional error processing state.\r
- */\r
-\r
-METHODDEF void\r
-reset_error_mgr (j_common_ptr cinfo)\r
-{\r
- cinfo->err->num_warnings = 0;\r
- /* trace_level is not reset since it is an application-supplied parameter */\r
- cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */\r
-}\r
-\r
-\r
-/*\r
- * Fill in the standard error-handling methods in a jpeg_error_mgr object.\r
- * Typical call is:\r
- * struct jpeg_compress_struct cinfo;\r
- * struct jpeg_error_mgr err;\r
- *\r
- * cinfo.err = jpeg_std_error(&err);\r
- * after which the application may override some of the methods.\r
- */\r
-\r
-GLOBAL struct jpeg_error_mgr *\r
-jpeg_std_error (struct jpeg_error_mgr * err)\r
-{\r
- err->error_exit = error_exit;\r
- err->emit_message = emit_message;\r
- err->output_message = output_message;\r
- err->format_message = format_message;\r
- err->reset_error_mgr = reset_error_mgr;\r
-\r
- err->trace_level = 0; /* default = no tracing */\r
- err->num_warnings = 0; /* no warnings emitted yet */\r
- err->msg_code = 0; /* may be useful as a flag for "no error" */\r
-\r
- /* Initialize message table pointers */\r
- err->jpeg_message_table = jpeg_std_message_table;\r
- err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;\r
-\r
- err->addon_message_table = NULL;\r
- err->first_addon_message = 0; /* for safety */\r
- err->last_addon_message = 0;\r
-\r
- return err;\r
-}\r
+/*
+ * jerror.c
+ *
+ * Copyright (C) 1991-1994, 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.
+ *
+ * These routines are used by both the compression and decompression code.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+#include "jinclude.h"
+#include "radiant_jpeglib.h"
+#include "jversion.h"
+#include "jerror.h"
+
+#ifndef EXIT_FAILURE /* define exit() codes if not provided */
+#define EXIT_FAILURE 1
+#endif
+
+
+/*
+ * 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.
+ */
+
+#ifdef NEED_SHORT_EXTERNAL_NAMES
+#define jpeg_std_message_table jMsgTable
+#endif
+
+#define JMESSAGE(code,string) string ,
+
+const char * const jpeg_std_message_table[] = {
+#include "jerror.h"
+ NULL
+};
+
+// Rad additions, longjmp out of the LoadJPGBuff
+GLOBAL jmp_buf rad_loadfailed;
+GLOBAL char rad_errormsg[JMSG_LENGTH_MAX];
+
+/*
+ * 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.
+ */
+
+METHODDEF void
+error_exit (j_common_ptr cinfo)
+{
+// char buffer[JMSG_LENGTH_MAX];
+
+ /* Create the message */
+ (*cinfo->err->format_message) (cinfo,rad_errormsg);
+
+ /* Let the memory manager delete any temp files before we die */
+ jpeg_destroy(cinfo);
+
+ longjmp( rad_loadfailed, -1 );
+}
+
+
+/*
+ * Actual output of an error or trace message.
+ * Applications may override this method to send JPEG messages somewhere
+ * other than stderr.
+ */
+
+METHODDEF void
+output_message (j_common_ptr cinfo)
+{
+ char buffer[JMSG_LENGTH_MAX];
+
+ /* Create the message */
+ (*cinfo->err->format_message) (cinfo, buffer);
+
+ /* Send it to stderr, adding a newline */
+ printf("%s\n", buffer);
+}
+
+
+/*
+ * 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.
+ */
+
+METHODDEF void
+emit_message (j_common_ptr cinfo, int msg_level)
+{
+ struct jpeg_error_mgr * err = cinfo->err;
+
+ if (msg_level < 0) {
+ /* 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.
+ */
+ if (err->num_warnings == 0 || err->trace_level >= 3)
+ (*err->output_message) (cinfo);
+ /* Always count warnings in num_warnings. */
+ err->num_warnings++;
+ } else {
+ /* It's a trace message. Show it if trace_level >= msg_level. */
+ if (err->trace_level >= msg_level)
+ (*err->output_message) (cinfo);
+ }
+}
+
+
+/*
+ * 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.
+ */
+
+METHODDEF void
+format_message (j_common_ptr cinfo, char * buffer)
+{
+ struct jpeg_error_mgr * err = cinfo->err;
+ int msg_code = err->msg_code;
+ const char * msgtext = NULL;
+ const char * msgptr;
+ char ch;
+ boolean isstring;
+
+ /* Look up message string in proper table */
+ if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
+ msgtext = err->jpeg_message_table[msg_code];
+ } else if (err->addon_message_table != NULL &&
+ msg_code >= err->first_addon_message &&
+ msg_code <= err->last_addon_message) {
+ msgtext = err->addon_message_table[msg_code - err->first_addon_message];
+ }
+
+ /* Defend against bogus message number */
+ if (msgtext == NULL) {
+ err->msg_parm.i[0] = msg_code;
+ msgtext = err->jpeg_message_table[0];
+ }
+
+ /* Check for string parameter, as indicated by %s in the message text */
+ isstring = FALSE;
+ msgptr = msgtext;
+ while ((ch = *msgptr++) != '\0') {
+ if (ch == '%') {
+ if (*msgptr == 's') isstring = TRUE;
+ break;
+ }
+ }
+
+ /* Format the message into the passed buffer */
+ if (isstring)
+ sprintf(buffer, msgtext, err->msg_parm.s);
+ else
+ sprintf(buffer, msgtext,
+ err->msg_parm.i[0], err->msg_parm.i[1],
+ err->msg_parm.i[2], err->msg_parm.i[3],
+ err->msg_parm.i[4], err->msg_parm.i[5],
+ err->msg_parm.i[6], err->msg_parm.i[7]);
+}
+
+
+/*
+ * 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.
+ */
+
+METHODDEF void
+reset_error_mgr (j_common_ptr cinfo)
+{
+ cinfo->err->num_warnings = 0;
+ /* trace_level is not reset since it is an application-supplied parameter */
+ cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
+}
+
+
+/*
+ * 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.
+ */
+
+GLOBAL struct jpeg_error_mgr *
+jpeg_std_error (struct jpeg_error_mgr * err)
+{
+ err->error_exit = error_exit;
+ err->emit_message = emit_message;
+ err->output_message = output_message;
+ err->format_message = format_message;
+ err->reset_error_mgr = reset_error_mgr;
+
+ err->trace_level = 0; /* default = no tracing */
+ err->num_warnings = 0; /* no warnings emitted yet */
+ err->msg_code = 0; /* may be useful as a flag for "no error" */
+
+ /* Initialize message table pointers */
+ err->jpeg_message_table = jpeg_std_message_table;
+ err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
+
+ err->addon_message_table = NULL;
+ err->first_addon_message = 0; /* for safety */
+ err->last_addon_message = 0;
+
+ return err;
+}