istereo2

annotate libs/libpng/pngerror.c @ 20:2b85d05df3f2

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