istereo

annotate libs/libpng/pngerror.c @ 28:c0ae8e668447

added vmath library
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 08:30:42 +0300
parents
children
rev   line source
nuclear@26 1
nuclear@26 2 /* pngerror.c - stub functions for i/o and memory allocation
nuclear@26 3 *
nuclear@26 4 * Last changed in libpng 1.2.30 [August 15, 2008]
nuclear@26 5 * For conditions of distribution and use, see copyright notice in png.h
nuclear@26 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
nuclear@26 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
nuclear@26 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
nuclear@26 9 *
nuclear@26 10 * This file provides a location for all error handling. Users who
nuclear@26 11 * need special error handling are expected to write replacement functions
nuclear@26 12 * and use png_set_error_fn() to use those functions. See the instructions
nuclear@26 13 * at each function.
nuclear@26 14 */
nuclear@26 15
nuclear@26 16 #define PNG_INTERNAL
nuclear@26 17 #include "png.h"
nuclear@26 18 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
nuclear@26 19
nuclear@26 20 static void /* PRIVATE */
nuclear@26 21 png_default_error PNGARG((png_structp png_ptr,
nuclear@26 22 png_const_charp error_message));
nuclear@26 23 #ifndef PNG_NO_WARNINGS
nuclear@26 24 static void /* PRIVATE */
nuclear@26 25 png_default_warning PNGARG((png_structp png_ptr,
nuclear@26 26 png_const_charp warning_message));
nuclear@26 27 #endif /* PNG_NO_WARNINGS */
nuclear@26 28
nuclear@26 29 /* This function is called whenever there is a fatal error. This function
nuclear@26 30 * should not be changed. If there is a need to handle errors differently,
nuclear@26 31 * you should supply a replacement error function and use png_set_error_fn()
nuclear@26 32 * to replace the error function at run-time.
nuclear@26 33 */
nuclear@26 34 #ifndef PNG_NO_ERROR_TEXT
nuclear@26 35 void PNGAPI
nuclear@26 36 png_error(png_structp png_ptr, png_const_charp error_message)
nuclear@26 37 {
nuclear@26 38 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@26 39 char msg[16];
nuclear@26 40 if (png_ptr != NULL)
nuclear@26 41 {
nuclear@26 42 if (png_ptr->flags&
nuclear@26 43 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
nuclear@26 44 {
nuclear@26 45 if (*error_message == '#')
nuclear@26 46 {
nuclear@26 47 /* Strip "#nnnn " from beginning of error message. */
nuclear@26 48 int offset;
nuclear@26 49 for (offset = 1; offset<15; offset++)
nuclear@26 50 if (error_message[offset] == ' ')
nuclear@26 51 break;
nuclear@26 52 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
nuclear@26 53 {
nuclear@26 54 int i;
nuclear@26 55 for (i = 0; i < offset - 1; i++)
nuclear@26 56 msg[i] = error_message[i + 1];
nuclear@26 57 msg[i - 1] = '\0';
nuclear@26 58 error_message = msg;
nuclear@26 59 }
nuclear@26 60 else
nuclear@26 61 error_message += offset;
nuclear@26 62 }
nuclear@26 63 else
nuclear@26 64 {
nuclear@26 65 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
nuclear@26 66 {
nuclear@26 67 msg[0] = '0';
nuclear@26 68 msg[1] = '\0';
nuclear@26 69 error_message = msg;
nuclear@26 70 }
nuclear@26 71 }
nuclear@26 72 }
nuclear@26 73 }
nuclear@26 74 #endif
nuclear@26 75 if (png_ptr != NULL && png_ptr->error_fn != NULL)
nuclear@26 76 (*(png_ptr->error_fn))(png_ptr, error_message);
nuclear@26 77
nuclear@26 78 /* If the custom handler doesn't exist, or if it returns,
nuclear@26 79 use the default handler, which will not return. */
nuclear@26 80 png_default_error(png_ptr, error_message);
nuclear@26 81 }
nuclear@26 82 #else
nuclear@26 83 void PNGAPI
nuclear@26 84 png_err(png_structp png_ptr)
nuclear@26 85 {
nuclear@26 86 if (png_ptr != NULL && png_ptr->error_fn != NULL)
nuclear@26 87 (*(png_ptr->error_fn))(png_ptr, '\0');
nuclear@26 88
nuclear@26 89 /* If the custom handler doesn't exist, or if it returns,
nuclear@26 90 use the default handler, which will not return. */
nuclear@26 91 png_default_error(png_ptr, '\0');
nuclear@26 92 }
nuclear@26 93 #endif /* PNG_NO_ERROR_TEXT */
nuclear@26 94
nuclear@26 95 #ifndef PNG_NO_WARNINGS
nuclear@26 96 /* This function is called whenever there is a non-fatal error. This function
nuclear@26 97 * should not be changed. If there is a need to handle warnings differently,
nuclear@26 98 * you should supply a replacement warning function and use
nuclear@26 99 * png_set_error_fn() to replace the warning function at run-time.
nuclear@26 100 */
nuclear@26 101 void PNGAPI
nuclear@26 102 png_warning(png_structp png_ptr, png_const_charp warning_message)
nuclear@26 103 {
nuclear@26 104 int offset = 0;
nuclear@26 105 if (png_ptr != NULL)
nuclear@26 106 {
nuclear@26 107 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@26 108 if (png_ptr->flags&
nuclear@26 109 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
nuclear@26 110 #endif
nuclear@26 111 {
nuclear@26 112 if (*warning_message == '#')
nuclear@26 113 {
nuclear@26 114 for (offset = 1; offset < 15; offset++)
nuclear@26 115 if (warning_message[offset] == ' ')
nuclear@26 116 break;
nuclear@26 117 }
nuclear@26 118 }
nuclear@26 119 if (png_ptr != NULL && png_ptr->warning_fn != NULL)
nuclear@26 120 (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
nuclear@26 121 }
nuclear@26 122 else
nuclear@26 123 png_default_warning(png_ptr, warning_message + offset);
nuclear@26 124 }
nuclear@26 125 #endif /* PNG_NO_WARNINGS */
nuclear@26 126
nuclear@26 127
nuclear@26 128 /* These utilities are used internally to build an error message that relates
nuclear@26 129 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
nuclear@26 130 * this is used to prefix the message. The message is limited in length
nuclear@26 131 * to 63 bytes, the name characters are output as hex digits wrapped in []
nuclear@26 132 * if the character is invalid.
nuclear@26 133 */
nuclear@26 134 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
nuclear@26 135 static PNG_CONST char png_digit[16] = {
nuclear@26 136 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
nuclear@26 137 'A', 'B', 'C', 'D', 'E', 'F'
nuclear@26 138 };
nuclear@26 139
nuclear@26 140 #define PNG_MAX_ERROR_TEXT 64
nuclear@26 141
nuclear@26 142 #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
nuclear@26 143 static void /* PRIVATE */
nuclear@26 144 png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
nuclear@26 145 error_message)
nuclear@26 146 {
nuclear@26 147 int iout = 0, iin = 0;
nuclear@26 148
nuclear@26 149 while (iin < 4)
nuclear@26 150 {
nuclear@26 151 int c = png_ptr->chunk_name[iin++];
nuclear@26 152 if (isnonalpha(c))
nuclear@26 153 {
nuclear@26 154 buffer[iout++] = '[';
nuclear@26 155 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
nuclear@26 156 buffer[iout++] = png_digit[c & 0x0f];
nuclear@26 157 buffer[iout++] = ']';
nuclear@26 158 }
nuclear@26 159 else
nuclear@26 160 {
nuclear@26 161 buffer[iout++] = (png_byte)c;
nuclear@26 162 }
nuclear@26 163 }
nuclear@26 164
nuclear@26 165 if (error_message == NULL)
nuclear@26 166 buffer[iout] = '\0';
nuclear@26 167 else
nuclear@26 168 {
nuclear@26 169 buffer[iout++] = ':';
nuclear@26 170 buffer[iout++] = ' ';
nuclear@26 171 png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
nuclear@26 172 buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
nuclear@26 173 }
nuclear@26 174 }
nuclear@26 175
nuclear@26 176 #ifdef PNG_READ_SUPPORTED
nuclear@26 177 void PNGAPI
nuclear@26 178 png_chunk_error(png_structp png_ptr, png_const_charp error_message)
nuclear@26 179 {
nuclear@26 180 char msg[18+PNG_MAX_ERROR_TEXT];
nuclear@26 181 if (png_ptr == NULL)
nuclear@26 182 png_error(png_ptr, error_message);
nuclear@26 183 else
nuclear@26 184 {
nuclear@26 185 png_format_buffer(png_ptr, msg, error_message);
nuclear@26 186 png_error(png_ptr, msg);
nuclear@26 187 }
nuclear@26 188 }
nuclear@26 189 #endif /* PNG_READ_SUPPORTED */
nuclear@26 190 #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
nuclear@26 191
nuclear@26 192 #ifndef PNG_NO_WARNINGS
nuclear@26 193 void PNGAPI
nuclear@26 194 png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
nuclear@26 195 {
nuclear@26 196 char msg[18+PNG_MAX_ERROR_TEXT];
nuclear@26 197 if (png_ptr == NULL)
nuclear@26 198 png_warning(png_ptr, warning_message);
nuclear@26 199 else
nuclear@26 200 {
nuclear@26 201 png_format_buffer(png_ptr, msg, warning_message);
nuclear@26 202 png_warning(png_ptr, msg);
nuclear@26 203 }
nuclear@26 204 }
nuclear@26 205 #endif /* PNG_NO_WARNINGS */
nuclear@26 206
nuclear@26 207
nuclear@26 208 /* This is the default error handling function. Note that replacements for
nuclear@26 209 * this function MUST NOT RETURN, or the program will likely crash. This
nuclear@26 210 * function is used by default, or if the program supplies NULL for the
nuclear@26 211 * error function pointer in png_set_error_fn().
nuclear@26 212 */
nuclear@26 213 static void /* PRIVATE */
nuclear@26 214 png_default_error(png_structp png_ptr, png_const_charp error_message)
nuclear@26 215 {
nuclear@26 216 #ifndef PNG_NO_CONSOLE_IO
nuclear@26 217 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@26 218 if (*error_message == '#')
nuclear@26 219 {
nuclear@26 220 /* Strip "#nnnn " from beginning of warning message. */
nuclear@26 221 int offset;
nuclear@26 222 char error_number[16];
nuclear@26 223 for (offset = 0; offset<15; offset++)
nuclear@26 224 {
nuclear@26 225 error_number[offset] = error_message[offset + 1];
nuclear@26 226 if (error_message[offset] == ' ')
nuclear@26 227 break;
nuclear@26 228 }
nuclear@26 229 if ((offset > 1) && (offset < 15))
nuclear@26 230 {
nuclear@26 231 error_number[offset - 1] = '\0';
nuclear@26 232 fprintf(stderr, "libpng error no. %s: %s\n", error_number,
nuclear@26 233 error_message + offset + 1);
nuclear@26 234 }
nuclear@26 235 else
nuclear@26 236 fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);
nuclear@26 237 }
nuclear@26 238 else
nuclear@26 239 #endif
nuclear@26 240 fprintf(stderr, "libpng error: %s\n", error_message);
nuclear@26 241 #endif
nuclear@26 242
nuclear@26 243 #ifdef PNG_SETJMP_SUPPORTED
nuclear@26 244 if (png_ptr)
nuclear@26 245 {
nuclear@26 246 # ifdef USE_FAR_KEYWORD
nuclear@26 247 {
nuclear@26 248 jmp_buf jmpbuf;
nuclear@26 249 png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
nuclear@26 250 longjmp(jmpbuf, 1);
nuclear@26 251 }
nuclear@26 252 # else
nuclear@26 253 longjmp(png_ptr->jmpbuf, 1);
nuclear@26 254 # endif
nuclear@26 255 }
nuclear@26 256 #else
nuclear@26 257 PNG_ABORT();
nuclear@26 258 #endif
nuclear@26 259 #ifdef PNG_NO_CONSOLE_IO
nuclear@26 260 error_message = error_message; /* make compiler happy */
nuclear@26 261 #endif
nuclear@26 262 }
nuclear@26 263
nuclear@26 264 #ifndef PNG_NO_WARNINGS
nuclear@26 265 /* This function is called when there is a warning, but the library thinks
nuclear@26 266 * it can continue anyway. Replacement functions don't have to do anything
nuclear@26 267 * here if you don't want them to. In the default configuration, png_ptr is
nuclear@26 268 * not used, but it is passed in case it may be useful.
nuclear@26 269 */
nuclear@26 270 static void /* PRIVATE */
nuclear@26 271 png_default_warning(png_structp png_ptr, png_const_charp warning_message)
nuclear@26 272 {
nuclear@26 273 #ifndef PNG_NO_CONSOLE_IO
nuclear@26 274 # ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@26 275 if (*warning_message == '#')
nuclear@26 276 {
nuclear@26 277 int offset;
nuclear@26 278 char warning_number[16];
nuclear@26 279 for (offset = 0; offset < 15; offset++)
nuclear@26 280 {
nuclear@26 281 warning_number[offset] = warning_message[offset + 1];
nuclear@26 282 if (warning_message[offset] == ' ')
nuclear@26 283 break;
nuclear@26 284 }
nuclear@26 285 if ((offset > 1) && (offset < 15))
nuclear@26 286 {
nuclear@26 287 warning_number[offset + 1] = '\0';
nuclear@26 288 fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
nuclear@26 289 warning_message + offset);
nuclear@26 290 }
nuclear@26 291 else
nuclear@26 292 fprintf(stderr, "libpng warning: %s\n", warning_message);
nuclear@26 293 }
nuclear@26 294 else
nuclear@26 295 # endif
nuclear@26 296 fprintf(stderr, "libpng warning: %s\n", warning_message);
nuclear@26 297 #else
nuclear@26 298 warning_message = warning_message; /* make compiler happy */
nuclear@26 299 #endif
nuclear@26 300 png_ptr = png_ptr; /* make compiler happy */
nuclear@26 301 }
nuclear@26 302 #endif /* PNG_NO_WARNINGS */
nuclear@26 303
nuclear@26 304 /* This function is called when the application wants to use another method
nuclear@26 305 * of handling errors and warnings. Note that the error function MUST NOT
nuclear@26 306 * return to the calling routine or serious problems will occur. The return
nuclear@26 307 * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
nuclear@26 308 */
nuclear@26 309 void PNGAPI
nuclear@26 310 png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
nuclear@26 311 png_error_ptr error_fn, png_error_ptr warning_fn)
nuclear@26 312 {
nuclear@26 313 if (png_ptr == NULL)
nuclear@26 314 return;
nuclear@26 315 png_ptr->error_ptr = error_ptr;
nuclear@26 316 png_ptr->error_fn = error_fn;
nuclear@26 317 png_ptr->warning_fn = warning_fn;
nuclear@26 318 }
nuclear@26 319
nuclear@26 320
nuclear@26 321 /* This function returns a pointer to the error_ptr associated with the user
nuclear@26 322 * functions. The application should free any memory associated with this
nuclear@26 323 * pointer before png_write_destroy and png_read_destroy are called.
nuclear@26 324 */
nuclear@26 325 png_voidp PNGAPI
nuclear@26 326 png_get_error_ptr(png_structp png_ptr)
nuclear@26 327 {
nuclear@26 328 if (png_ptr == NULL)
nuclear@26 329 return NULL;
nuclear@26 330 return ((png_voidp)png_ptr->error_ptr);
nuclear@26 331 }
nuclear@26 332
nuclear@26 333
nuclear@26 334 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
nuclear@26 335 void PNGAPI
nuclear@26 336 png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
nuclear@26 337 {
nuclear@26 338 if (png_ptr != NULL)
nuclear@26 339 {
nuclear@26 340 png_ptr->flags &=
nuclear@26 341 ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
nuclear@26 342 }
nuclear@26 343 }
nuclear@26 344 #endif
nuclear@26 345 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */