3dphotoshoot
diff libs/libjpeg/jerror.c @ 14:06dc8b9b4f89
added libimago, libjpeg and libpng
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 07 Jun 2015 17:25:49 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/libjpeg/jerror.c Sun Jun 07 17:25:49 2015 +0300 1.3 @@ -0,0 +1,252 @@ 1.4 +/* 1.5 + * jerror.c 1.6 + * 1.7 + * Copyright (C) 1991-1998, Thomas G. Lane. 1.8 + * This file is part of the Independent JPEG Group's software. 1.9 + * For conditions of distribution and use, see the accompanying README file. 1.10 + * 1.11 + * This file contains simple error-reporting and trace-message routines. 1.12 + * These are suitable for Unix-like systems and others where writing to 1.13 + * stderr is the right thing to do. Many applications will want to replace 1.14 + * some or all of these routines. 1.15 + * 1.16 + * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, 1.17 + * you get a Windows-specific hack to display error messages in a dialog box. 1.18 + * It ain't much, but it beats dropping error messages into the bit bucket, 1.19 + * which is what happens to output to stderr under most Windows C compilers. 1.20 + * 1.21 + * These routines are used by both the compression and decompression code. 1.22 + */ 1.23 + 1.24 +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ 1.25 +#include "jinclude.h" 1.26 +#include "jpeglib.h" 1.27 +#include "jversion.h" 1.28 +#include "jerror.h" 1.29 + 1.30 +#ifdef USE_WINDOWS_MESSAGEBOX 1.31 +#include <windows.h> 1.32 +#endif 1.33 + 1.34 +#ifndef EXIT_FAILURE /* define exit() codes if not provided */ 1.35 +#define EXIT_FAILURE 1 1.36 +#endif 1.37 + 1.38 + 1.39 +/* 1.40 + * Create the message string table. 1.41 + * We do this from the master message list in jerror.h by re-reading 1.42 + * jerror.h with a suitable definition for macro JMESSAGE. 1.43 + * The message table is made an external symbol just in case any applications 1.44 + * want to refer to it directly. 1.45 + */ 1.46 + 1.47 +#ifdef NEED_SHORT_EXTERNAL_NAMES 1.48 +#define jpeg_std_message_table jMsgTable 1.49 +#endif 1.50 + 1.51 +#define JMESSAGE(code,string) string , 1.52 + 1.53 +const char * const jpeg_std_message_table[] = { 1.54 +#include "jerror.h" 1.55 + NULL 1.56 +}; 1.57 + 1.58 + 1.59 +/* 1.60 + * Error exit handler: must not return to caller. 1.61 + * 1.62 + * Applications may override this if they want to get control back after 1.63 + * an error. Typically one would longjmp somewhere instead of exiting. 1.64 + * The setjmp buffer can be made a private field within an expanded error 1.65 + * handler object. Note that the info needed to generate an error message 1.66 + * is stored in the error object, so you can generate the message now or 1.67 + * later, at your convenience. 1.68 + * You should make sure that the JPEG object is cleaned up (with jpeg_abort 1.69 + * or jpeg_destroy) at some point. 1.70 + */ 1.71 + 1.72 +METHODDEF(void) 1.73 +error_exit (j_common_ptr cinfo) 1.74 +{ 1.75 + /* Always display the message */ 1.76 + (*cinfo->err->output_message) (cinfo); 1.77 + 1.78 + /* Let the memory manager delete any temp files before we die */ 1.79 + jpeg_destroy(cinfo); 1.80 + 1.81 + exit(EXIT_FAILURE); 1.82 +} 1.83 + 1.84 + 1.85 +/* 1.86 + * Actual output of an error or trace message. 1.87 + * Applications may override this method to send JPEG messages somewhere 1.88 + * other than stderr. 1.89 + * 1.90 + * On Windows, printing to stderr is generally completely useless, 1.91 + * so we provide optional code to produce an error-dialog popup. 1.92 + * Most Windows applications will still prefer to override this routine, 1.93 + * but if they don't, it'll do something at least marginally useful. 1.94 + * 1.95 + * NOTE: to use the library in an environment that doesn't support the 1.96 + * C stdio library, you may have to delete the call to fprintf() entirely, 1.97 + * not just not use this routine. 1.98 + */ 1.99 + 1.100 +METHODDEF(void) 1.101 +output_message (j_common_ptr cinfo) 1.102 +{ 1.103 + char buffer[JMSG_LENGTH_MAX]; 1.104 + 1.105 + /* Create the message */ 1.106 + (*cinfo->err->format_message) (cinfo, buffer); 1.107 + 1.108 +#ifdef USE_WINDOWS_MESSAGEBOX 1.109 + /* Display it in a message dialog box */ 1.110 + MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", 1.111 + MB_OK | MB_ICONERROR); 1.112 +#else 1.113 + /* Send it to stderr, adding a newline */ 1.114 + fprintf(stderr, "%s\n", buffer); 1.115 +#endif 1.116 +} 1.117 + 1.118 + 1.119 +/* 1.120 + * Decide whether to emit a trace or warning message. 1.121 + * msg_level is one of: 1.122 + * -1: recoverable corrupt-data warning, may want to abort. 1.123 + * 0: important advisory messages (always display to user). 1.124 + * 1: first level of tracing detail. 1.125 + * 2,3,...: successively more detailed tracing messages. 1.126 + * An application might override this method if it wanted to abort on warnings 1.127 + * or change the policy about which messages to display. 1.128 + */ 1.129 + 1.130 +METHODDEF(void) 1.131 +emit_message (j_common_ptr cinfo, int msg_level) 1.132 +{ 1.133 + struct jpeg_error_mgr * err = cinfo->err; 1.134 + 1.135 + if (msg_level < 0) { 1.136 + /* It's a warning message. Since corrupt files may generate many warnings, 1.137 + * the policy implemented here is to show only the first warning, 1.138 + * unless trace_level >= 3. 1.139 + */ 1.140 + if (err->num_warnings == 0 || err->trace_level >= 3) 1.141 + (*err->output_message) (cinfo); 1.142 + /* Always count warnings in num_warnings. */ 1.143 + err->num_warnings++; 1.144 + } else { 1.145 + /* It's a trace message. Show it if trace_level >= msg_level. */ 1.146 + if (err->trace_level >= msg_level) 1.147 + (*err->output_message) (cinfo); 1.148 + } 1.149 +} 1.150 + 1.151 + 1.152 +/* 1.153 + * Format a message string for the most recent JPEG error or message. 1.154 + * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX 1.155 + * characters. Note that no '\n' character is added to the string. 1.156 + * Few applications should need to override this method. 1.157 + */ 1.158 + 1.159 +METHODDEF(void) 1.160 +format_message (j_common_ptr cinfo, char * buffer) 1.161 +{ 1.162 + struct jpeg_error_mgr * err = cinfo->err; 1.163 + int msg_code = err->msg_code; 1.164 + const char * msgtext = NULL; 1.165 + const char * msgptr; 1.166 + char ch; 1.167 + boolean isstring; 1.168 + 1.169 + /* Look up message string in proper table */ 1.170 + if (msg_code > 0 && msg_code <= err->last_jpeg_message) { 1.171 + msgtext = err->jpeg_message_table[msg_code]; 1.172 + } else if (err->addon_message_table != NULL && 1.173 + msg_code >= err->first_addon_message && 1.174 + msg_code <= err->last_addon_message) { 1.175 + msgtext = err->addon_message_table[msg_code - err->first_addon_message]; 1.176 + } 1.177 + 1.178 + /* Defend against bogus message number */ 1.179 + if (msgtext == NULL) { 1.180 + err->msg_parm.i[0] = msg_code; 1.181 + msgtext = err->jpeg_message_table[0]; 1.182 + } 1.183 + 1.184 + /* Check for string parameter, as indicated by %s in the message text */ 1.185 + isstring = FALSE; 1.186 + msgptr = msgtext; 1.187 + while ((ch = *msgptr++) != '\0') { 1.188 + if (ch == '%') { 1.189 + if (*msgptr == 's') isstring = TRUE; 1.190 + break; 1.191 + } 1.192 + } 1.193 + 1.194 + /* Format the message into the passed buffer */ 1.195 + if (isstring) 1.196 + sprintf(buffer, msgtext, err->msg_parm.s); 1.197 + else 1.198 + sprintf(buffer, msgtext, 1.199 + err->msg_parm.i[0], err->msg_parm.i[1], 1.200 + err->msg_parm.i[2], err->msg_parm.i[3], 1.201 + err->msg_parm.i[4], err->msg_parm.i[5], 1.202 + err->msg_parm.i[6], err->msg_parm.i[7]); 1.203 +} 1.204 + 1.205 + 1.206 +/* 1.207 + * Reset error state variables at start of a new image. 1.208 + * This is called during compression startup to reset trace/error 1.209 + * processing to default state, without losing any application-specific 1.210 + * method pointers. An application might possibly want to override 1.211 + * this method if it has additional error processing state. 1.212 + */ 1.213 + 1.214 +METHODDEF(void) 1.215 +reset_error_mgr (j_common_ptr cinfo) 1.216 +{ 1.217 + cinfo->err->num_warnings = 0; 1.218 + /* trace_level is not reset since it is an application-supplied parameter */ 1.219 + cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ 1.220 +} 1.221 + 1.222 + 1.223 +/* 1.224 + * Fill in the standard error-handling methods in a jpeg_error_mgr object. 1.225 + * Typical call is: 1.226 + * struct jpeg_compress_struct cinfo; 1.227 + * struct jpeg_error_mgr err; 1.228 + * 1.229 + * cinfo.err = jpeg_std_error(&err); 1.230 + * after which the application may override some of the methods. 1.231 + */ 1.232 + 1.233 +GLOBAL(struct jpeg_error_mgr *) 1.234 +jpeg_std_error (struct jpeg_error_mgr * err) 1.235 +{ 1.236 + err->error_exit = error_exit; 1.237 + err->emit_message = emit_message; 1.238 + err->output_message = output_message; 1.239 + err->format_message = format_message; 1.240 + err->reset_error_mgr = reset_error_mgr; 1.241 + 1.242 + err->trace_level = 0; /* default = no tracing */ 1.243 + err->num_warnings = 0; /* no warnings emitted yet */ 1.244 + err->msg_code = 0; /* may be useful as a flag for "no error" */ 1.245 + 1.246 + /* Initialize message table pointers */ 1.247 + err->jpeg_message_table = jpeg_std_message_table; 1.248 + err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; 1.249 + 1.250 + err->addon_message_table = NULL; 1.251 + err->first_addon_message = 0; /* for safety */ 1.252 + err->last_addon_message = 0; 1.253 + 1.254 + return err; 1.255 +}