Main MRPT website > C++ reference for MRPT 1.5.6
jerror.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
11 #include "jinclude.h"
12 #include "mrpt_jpeglib.h"
13 #include "jversion.h"
14 #include "jerror.h"
15 
16 #ifdef USE_WINDOWS_MESSAGEBOX
17 #include <windows.h>
18 #endif
19 
20 #ifndef EXIT_FAILURE /* define exit() codes if not provided */
21 #define EXIT_FAILURE 1
22 #endif
23 
24 
25 /*
26  * Create the message string table.
27  * We do this from the master message list in jerror.h by re-reading
28  * jerror.h with a suitable definition for macro JMESSAGE.
29  * The message table is made an external symbol just in case any applications
30  * want to refer to it directly.
31  */
32 
33 #ifdef NEED_SHORT_EXTERNAL_NAMES
34 #define jpeg_std_message_table jMsgTable
35 #endif
36 
37 #define JMESSAGE(code,string) string ,
38 
39 const char * const jpeg_std_message_table[] = {
40 #include "jerror.h"
41  NULL
42 };
43 
44 
45 /*
46  * Error exit handler: must not return to caller.
47  *
48  * Applications may override this if they want to get control back after
49  * an error. Typically one would longjmp somewhere instead of exiting.
50  * The setjmp buffer can be made a private field within an expanded error
51  * handler object. Note that the info needed to generate an error message
52  * is stored in the error object, so you can generate the message now or
53  * later, at your convenience.
54  * You should make sure that the JPEG object is cleaned up (with jpeg_abort
55  * or jpeg_destroy) at some point.
56  */
57 
58 METHODDEF(void)
60 {
61  /* Always display the message */
62  (*cinfo->err->output_message) (cinfo);
63 
64  /* Let the memory manager delete any temp files before we die */
65  jpeg_destroy(cinfo);
66 
67  fprintf(stderr,"[jpeg::error_exit] critical error\n");
68  //exit(EXIT_FAILURE);
69 }
70 
71 
72 /*
73  * Actual output of an error or trace message.
74  * Applications may override this method to send JPEG messages somewhere
75  * other than stderr.
76  *
77  * On Windows, printing to stderr is generally completely useless,
78  * so we provide optional code to produce an error-dialog popup.
79  * Most Windows applications will still prefer to override this routine,
80  * but if they don't, it'll do something at least marginally useful.
81  *
82  * NOTE: to use the library in an environment that doesn't support the
83  * C stdio library, you may have to delete the call to fprintf() entirely,
84  * not just not use this routine.
85  */
86 
87 METHODDEF(void)
89 {
90  char buffer[JMSG_LENGTH_MAX];
91 
92  /* Create the message */
93  (*cinfo->err->format_message) (cinfo, buffer);
94 
95 #ifdef USE_WINDOWS_MESSAGEBOX
96  /* Display it in a message dialog box */
97  MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
98  MB_OK | MB_ICONERROR);
99 #else
100  /* Send it to stderr, adding a newline */
101  fprintf(stderr, "%s\n", buffer);
102 #endif
103 }
104 
105 
106 /*
107  * Decide whether to emit a trace or warning message.
108  * msg_level is one of:
109  * -1: recoverable corrupt-data warning, may want to abort.
110  * 0: important advisory messages (always display to user).
111  * 1: first level of tracing detail.
112  * 2,3,...: successively more detailed tracing messages.
113  * An application might override this method if it wanted to abort on warnings
114  * or change the policy about which messages to display.
115  */
116 
117 METHODDEF(void)
118 emit_message (j_common_ptr cinfo, int msg_level)
119 {
120  struct jpeg_error_mgr * err = cinfo->err;
121 
122  if (msg_level < 0) {
123  /* It's a warning message. Since corrupt files may generate many warnings,
124  * the policy implemented here is to show only the first warning,
125  * unless trace_level >= 3.
126  */
127  if (err->num_warnings == 0 || err->trace_level >= 3)
128  (*err->output_message) (cinfo);
129  /* Always count warnings in num_warnings. */
130  err->num_warnings++;
131  } else {
132  /* It's a trace message. Show it if trace_level >= msg_level. */
133  if (err->trace_level >= msg_level)
134  (*err->output_message) (cinfo);
135  }
136 }
137 
138 
139 /*
140  * Format a message string for the most recent JPEG error or message.
141  * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
142  * characters. Note that no '\n' character is added to the string.
143  * Few applications should need to override this method.
144  */
145 
146 METHODDEF(void)
148 {
149  struct jpeg_error_mgr * err = cinfo->err;
150  int msg_code = err->msg_code;
151  const char * msgtext = NULL;
152  const char * msgptr;
153  char ch;
154  boolean isstring;
155 
156  /* Look up message string in proper table */
157  if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
158  msgtext = err->jpeg_message_table[msg_code];
159  } else if (err->addon_message_table != NULL &&
160  msg_code >= err->first_addon_message &&
161  msg_code <= err->last_addon_message) {
162  msgtext = err->addon_message_table[msg_code - err->first_addon_message];
163  }
164 
165  /* Defend against bogus message number */
166  if (msgtext == NULL) {
167  err->msg_parm.i[0] = msg_code;
168  msgtext = err->jpeg_message_table[0];
169  }
170 
171  /* Check for string parameter, as indicated by %s in the message text */
172  isstring = FALSE;
173  msgptr = msgtext;
174  while ((ch = *msgptr++) != '\0') {
175  if (ch == '%') {
176  if (*msgptr == 's') isstring = TRUE;
177  break;
178  }
179  }
180 
181  /* Format the message into the passed buffer */
182  if (isstring)
183  sprintf(buffer, msgtext, err->msg_parm.s);
184  else
185  sprintf(buffer, msgtext,
186  err->msg_parm.i[0], err->msg_parm.i[1],
187  err->msg_parm.i[2], err->msg_parm.i[3],
188  err->msg_parm.i[4], err->msg_parm.i[5],
189  err->msg_parm.i[6], err->msg_parm.i[7]);
190 }
191 
192 
193 /*
194  * Reset error state variables at start of a new image.
195  * This is called during compression startup to reset trace/error
196  * processing to default state, without losing any application-specific
197  * method pointers. An application might possibly want to override
198  * this method if it has additional error processing state.
199  */
200 
201 METHODDEF(void)
203 {
204  cinfo->err->num_warnings = 0;
205  /* trace_level is not reset since it is an application-supplied parameter */
206  cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
207 }
208 
209 
210 /*
211  * Fill in the standard error-handling methods in a jpeg_error_mgr object.
212  * Typical call is:
213  * struct jpeg_compress_struct cinfo;
214  * struct jpeg_error_mgr err;
215  *
216  * cinfo.err = jpeg_std_error(&err);
217  * after which the application may override some of the methods.
218  */
219 
220 GLOBAL(struct jpeg_error_mgr *)
222 {
223  err->error_exit = error_exit;
224  err->emit_message = emit_message;
225  err->output_message = output_message;
226  err->format_message = format_message;
227  err->reset_error_mgr = reset_error_mgr;
228 
229  err->trace_level = 0; /* default = no tracing */
230  err->num_warnings = 0; /* no warnings emitted yet */
231  err->msg_code = 0; /* may be useful as a flag for "no error" */
232 
233  /* Initialize message table pointers */
234  err->jpeg_message_table = jpeg_std_message_table;
235  err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
236 
237  err->addon_message_table = NULL;
238  err->first_addon_message = 0; /* for safety */
239  err->last_addon_message = 0;
240 
241  return err;
242 }
reset_error_mgr(j_common_ptr cinfo)
Definition: jerror.cpp:202
output_message(j_common_ptr cinfo)
Definition: jerror.cpp:88
char s[JMSG_STR_PARM_MAX]
Definition: mrpt_jpeglib.h:660
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.cpp:147
jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.cpp:67
const char *const * addon_message_table
Definition: mrpt_jpeglib.h:690
const char *const jpeg_std_message_table[]
Definition: jerror.cpp:39
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:412
#define FALSE
Definition: jmorecfg.h:227
GLuint buffer
Definition: glew.h:1585
union jpeg_error_mgr::@79 msg_parm
error_exit(j_common_ptr cinfo)
Definition: jerror.cpp:59
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
#define TRUE
Definition: jmorecfg.h:230
#define GLOBAL(type)
Definition: jmorecfg.h:185
#define METHODDEF(type)
Definition: jmorecfg.h:181
const char *const * jpeg_message_table
Definition: mrpt_jpeglib.h:685
jpeg_std_error(struct jpeg_error_mgr *err)
Definition: jerror.cpp:221
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:191
#define JMSG_LENGTH_MAX
Definition: mrpt_jpeglib.h:649
emit_message(j_common_ptr cinfo, int msg_level)
Definition: jerror.cpp:118



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018