| 1 | /* |
|---|
| 2 | * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/pngerror.c#1 $ |
|---|
| 3 | * $Revision: #1 $ |
|---|
| 4 | * $DateTime: 2006/02/24 17:51:46 $ |
|---|
| 5 | * $Change: 42566 $ |
|---|
| 6 | * $Author: pryush.sharma $ |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | /* pngerror.c - stub functions for i/o and memory allocation |
|---|
| 11 | * |
|---|
| 12 | * libpng 1.0.2 - June 14, 1998 |
|---|
| 13 | * For conditions of distribution and use, see copyright notice in png.h |
|---|
| 14 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
|---|
| 15 | * Copyright (c) 1996, 1997 Andreas Dilger |
|---|
| 16 | * Copyright (c) 1998, Glenn Randers-Pehrson |
|---|
| 17 | * |
|---|
| 18 | * This file provides a location for all error handling. Users who |
|---|
| 19 | * need special error handling are expected to write replacement functions |
|---|
| 20 | * and use png_set_error_fn() to use those functions. See the instructions |
|---|
| 21 | * at each function. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | #define PNG_INTERNAL |
|---|
| 25 | #include "png.h" |
|---|
| 26 | //#include "user_dbg.h" |
|---|
| 27 | |
|---|
| 28 | #include "ministd.h"//BKTEMP |
|---|
| 29 | |
|---|
| 30 | static void png_default_error PNGARG((png_structp png_ptr, |
|---|
| 31 | png_const_charp message)); |
|---|
| 32 | static void png_default_warning PNGARG((png_structp png_ptr, |
|---|
| 33 | png_const_charp message)); |
|---|
| 34 | |
|---|
| 35 | /* This function is called whenever there is a fatal error. This function |
|---|
| 36 | * should not be changed. If there is a need to handle errors differently, |
|---|
| 37 | * you should supply a replacement error function and use png_set_error_fn() |
|---|
| 38 | * to replace the error function at run-time. |
|---|
| 39 | */ |
|---|
| 40 | void |
|---|
| 41 | png_error(png_structp png_ptr, png_const_charp message) |
|---|
| 42 | { |
|---|
| 43 | if (png_ptr->error_fn != NULL) |
|---|
| 44 | (*(png_ptr->error_fn))(png_ptr, message); |
|---|
| 45 | |
|---|
| 46 | /* if the following returns or doesn't exist, use the default function, |
|---|
| 47 | which will not return */ |
|---|
| 48 | png_default_error(png_ptr, message); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /* This function is called whenever there is a non-fatal error. This function |
|---|
| 52 | * should not be changed. If there is a need to handle warnings differently, |
|---|
| 53 | * you should supply a replacement warning function and use |
|---|
| 54 | * png_set_error_fn() to replace the warning function at run-time. |
|---|
| 55 | */ |
|---|
| 56 | void |
|---|
| 57 | png_warning(png_structp png_ptr, png_const_charp message) |
|---|
| 58 | { |
|---|
| 59 | if (png_ptr->warning_fn != NULL) |
|---|
| 60 | (*(png_ptr->warning_fn))(png_ptr, message); |
|---|
| 61 | else |
|---|
| 62 | png_default_warning(png_ptr, message); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /* These utilities are used internally to build an error message that relates |
|---|
| 66 | * to the current chunk. The chunk name comes from png_ptr->chunk_name, |
|---|
| 67 | * this is used to prefix the message. The message is limited in length |
|---|
| 68 | * to 63 bytes, the name characters are output as hex digits wrapped in [] |
|---|
| 69 | * if the character is invalid. |
|---|
| 70 | */ |
|---|
| 71 | #define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97)) |
|---|
| 72 | static PNG_CONST char png_digit[16] = { |
|---|
| 73 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | static void |
|---|
| 77 | png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message) |
|---|
| 78 | { |
|---|
| 79 | int iout = 0, iin = 0; |
|---|
| 80 | |
|---|
| 81 | while (iin < 4) { |
|---|
| 82 | int c = png_ptr->chunk_name[iin++]; |
|---|
| 83 | if (isnonalpha(c)) { |
|---|
| 84 | buffer[iout++] = '['; |
|---|
| 85 | buffer[iout++] = png_digit[(c & 0xf0) >> 4]; |
|---|
| 86 | buffer[iout++] = png_digit[c & 0xf]; |
|---|
| 87 | buffer[iout++] = ']'; |
|---|
| 88 | } else { |
|---|
| 89 | buffer[iout++] = c; |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | if (message == NULL) |
|---|
| 94 | buffer[iout] = 0; |
|---|
| 95 | else { |
|---|
| 96 | buffer[iout++] = ':'; |
|---|
| 97 | buffer[iout++] = ' '; |
|---|
| 98 | png_memcpy(buffer+iout, message, 64); |
|---|
| 99 | buffer[iout+63] = 0; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void |
|---|
| 104 | png_chunk_error(png_structp png_ptr, png_const_charp message) |
|---|
| 105 | { |
|---|
| 106 | char msg[16+64]; |
|---|
| 107 | png_format_buffer(png_ptr, msg, message); |
|---|
| 108 | png_error(png_ptr, msg); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | void |
|---|
| 112 | png_chunk_warning(png_structp png_ptr, png_const_charp message) |
|---|
| 113 | { |
|---|
| 114 | char msg[16+64]; |
|---|
| 115 | png_format_buffer(png_ptr, msg, message); |
|---|
| 116 | png_warning(png_ptr, msg); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /* This is the default error handling function. Note that replacements for |
|---|
| 120 | * this function MUST NOT RETURN, or the program will likely crash. This |
|---|
| 121 | * function is used by default, or if the program supplies NULL for the |
|---|
| 122 | * error function pointer in png_set_error_fn(). |
|---|
| 123 | */ |
|---|
| 124 | static void |
|---|
| 125 | png_default_error(png_structp png_ptr, png_const_charp message) |
|---|
| 126 | { |
|---|
| 127 | #ifndef PNG_NO_STDIO |
|---|
| 128 | printf("libpng error: %s\n", message); |
|---|
| 129 | #endif |
|---|
| 130 | |
|---|
| 131 | #ifdef USE_FAR_KEYWORD |
|---|
| 132 | { |
|---|
| 133 | jmp_buf jmpbuf; |
|---|
| 134 | png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf)); |
|---|
| 135 | longjmp(jmpbuf, 1); |
|---|
| 136 | } |
|---|
| 137 | #else |
|---|
| 138 | longjmp(&png_ptr->jmpbuf, 1); |
|---|
| 139 | #endif |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | /* This function is called when there is a warning, but the library thinks |
|---|
| 143 | * it can continue anyway. Replacement functions don't have to do anything |
|---|
| 144 | * here if you don't want them to. In the default configuration, png_ptr is |
|---|
| 145 | * not used, but it is passed in case it may be useful. |
|---|
| 146 | */ |
|---|
| 147 | static void |
|---|
| 148 | png_default_warning(png_structp png_ptr, png_const_charp message) |
|---|
| 149 | { |
|---|
| 150 | if (png_ptr == NULL) |
|---|
| 151 | return; |
|---|
| 152 | |
|---|
| 153 | printf("libpng warning: %s\n", message); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | /* This function is called when the application wants to use another method |
|---|
| 157 | * of handling errors and warnings. Note that the error function MUST NOT |
|---|
| 158 | * return to the calling routine or serious problems will occur. The return |
|---|
| 159 | * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) |
|---|
| 160 | */ |
|---|
| 161 | void |
|---|
| 162 | png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, |
|---|
| 163 | png_error_ptr error_fn, png_error_ptr warning_fn) |
|---|
| 164 | { |
|---|
| 165 | png_ptr->error_ptr = error_ptr; |
|---|
| 166 | png_ptr->error_fn = error_fn; |
|---|
| 167 | png_ptr->warning_fn = warning_fn; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | /* This function returns a pointer to the error_ptr associated with the user |
|---|
| 172 | * functions. The application should free any memory associated with this |
|---|
| 173 | * pointer before png_write_destroy and png_read_destroy are called. |
|---|
| 174 | */ |
|---|
| 175 | png_voidp |
|---|
| 176 | png_get_error_ptr(png_structp png_ptr) |
|---|
| 177 | { |
|---|
| 178 | return ((png_voidp)png_ptr->error_ptr); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|