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