39 |
41 |
40 #ifdef PNG_SETJMP_SUPPORTED |
42 #ifdef PNG_SETJMP_SUPPORTED |
41 volatile |
43 volatile |
42 #endif |
44 #endif |
43 png_structp png_ptr; |
45 png_structp png_ptr; |
|
46 volatile int png_cleanup_needed = 0; |
44 |
47 |
45 #ifdef PNG_SETJMP_SUPPORTED |
48 #ifdef PNG_SETJMP_SUPPORTED |
46 #ifdef USE_FAR_KEYWORD |
49 #ifdef USE_FAR_KEYWORD |
47 jmp_buf jmpbuf; |
50 jmp_buf jmpbuf; |
48 #endif |
51 #endif |
49 #endif |
52 #endif |
50 |
53 |
51 int i; |
54 int i; |
52 |
55 |
53 png_debug(1, "in png_create_read_struct"); |
56 png_debug(1, "in png_create_read_struct"); |
|
57 |
54 #ifdef PNG_USER_MEM_SUPPORTED |
58 #ifdef PNG_USER_MEM_SUPPORTED |
55 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
59 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
56 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); |
60 malloc_fn, mem_ptr); |
57 #else |
61 #else |
58 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
62 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
59 #endif |
63 #endif |
60 if (png_ptr == NULL) |
64 if (png_ptr == NULL) |
61 return (NULL); |
65 return (NULL); |
62 |
66 |
63 /* Added at libpng-1.2.6 */ |
67 /* Added at libpng-1.2.6 */ |
64 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
68 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
65 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
69 png_ptr->user_width_max = PNG_USER_WIDTH_MAX; |
66 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
70 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; |
|
71 /* Added at libpng-1.4.0 */ |
|
72 png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; |
67 #endif |
73 #endif |
68 |
74 |
69 #ifdef PNG_SETJMP_SUPPORTED |
75 #ifdef PNG_SETJMP_SUPPORTED |
|
76 /* Applications that neglect to set up their own setjmp() and then |
|
77 encounter a png_error() will longjmp here. Since the jmpbuf is |
|
78 then meaningless we abort instead of returning. */ |
70 #ifdef USE_FAR_KEYWORD |
79 #ifdef USE_FAR_KEYWORD |
71 if (setjmp(jmpbuf)) |
80 if (setjmp(jmpbuf)) |
72 #else |
81 #else |
73 if (setjmp(png_ptr->jmpbuf)) |
82 if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ |
74 #endif |
83 #endif |
75 { |
84 PNG_ABORT(); |
|
85 #ifdef USE_FAR_KEYWORD |
|
86 png_memcpy(png_jmpbuf(png_ptr), jmpbuf, png_sizeof(jmp_buf)); |
|
87 #endif |
|
88 #endif /* PNG_SETJMP_SUPPORTED */ |
|
89 |
|
90 #ifdef PNG_USER_MEM_SUPPORTED |
|
91 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
|
92 #endif |
|
93 |
|
94 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
|
95 |
|
96 if (user_png_ver) |
|
97 { |
|
98 i = 0; |
|
99 do |
|
100 { |
|
101 if (user_png_ver[i] != png_libpng_ver[i]) |
|
102 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
|
103 } while (png_libpng_ver[i++]); |
|
104 } |
|
105 else |
|
106 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
|
107 |
|
108 |
|
109 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
|
110 { |
|
111 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
|
112 * we must recompile any applications that use any older library version. |
|
113 * For versions after libpng 1.0, we will be compatible, so we need |
|
114 * only check the first digit. |
|
115 */ |
|
116 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
|
117 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || |
|
118 (user_png_ver[0] == '0' && user_png_ver[2] < '9')) |
|
119 { |
|
120 #ifdef PNG_STDIO_SUPPORTED |
|
121 char msg[80]; |
|
122 if (user_png_ver) |
|
123 { |
|
124 png_snprintf(msg, 80, |
|
125 "Application was compiled with png.h from libpng-%.20s", |
|
126 user_png_ver); |
|
127 png_warning(png_ptr, msg); |
|
128 } |
|
129 png_snprintf(msg, 80, |
|
130 "Application is running with png.c from libpng-%.20s", |
|
131 png_libpng_ver); |
|
132 png_warning(png_ptr, msg); |
|
133 #endif |
|
134 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
|
135 png_ptr->flags = 0; |
|
136 #endif |
|
137 png_warning(png_ptr, |
|
138 "Incompatible libpng version in application and library"); |
|
139 |
|
140 png_cleanup_needed = 1; |
|
141 } |
|
142 } |
|
143 |
|
144 if (!png_cleanup_needed) |
|
145 { |
|
146 /* Initialize zbuf - compression buffer */ |
|
147 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
|
148 png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, |
|
149 png_ptr->zbuf_size); |
|
150 if (png_ptr->zbuf == NULL) |
|
151 png_cleanup_needed = 1; |
|
152 } |
|
153 png_ptr->zstream.zalloc = png_zalloc; |
|
154 png_ptr->zstream.zfree = png_zfree; |
|
155 png_ptr->zstream.opaque = (voidpf)png_ptr; |
|
156 |
|
157 if (!png_cleanup_needed) |
|
158 { |
|
159 switch (inflateInit(&png_ptr->zstream)) |
|
160 { |
|
161 case Z_OK: /* Do nothing */ break; |
|
162 case Z_MEM_ERROR: |
|
163 case Z_STREAM_ERROR: png_warning(png_ptr, "zlib memory error"); |
|
164 png_cleanup_needed = 1; break; |
|
165 case Z_VERSION_ERROR: png_warning(png_ptr, "zlib version error"); |
|
166 png_cleanup_needed = 1; break; |
|
167 default: png_warning(png_ptr, "Unknown zlib error"); |
|
168 png_cleanup_needed = 1; |
|
169 } |
|
170 } |
|
171 |
|
172 if (png_cleanup_needed) |
|
173 { |
|
174 /* Clean up PNG structure and deallocate any memory. */ |
76 png_free(png_ptr, png_ptr->zbuf); |
175 png_free(png_ptr, png_ptr->zbuf); |
77 png_ptr->zbuf = NULL; |
176 png_ptr->zbuf = NULL; |
78 #ifdef PNG_USER_MEM_SUPPORTED |
177 #ifdef PNG_USER_MEM_SUPPORTED |
79 png_destroy_struct_2((png_voidp)png_ptr, |
178 png_destroy_struct_2((png_voidp)png_ptr, |
80 (png_free_ptr)free_fn, (png_voidp)mem_ptr); |
179 (png_free_ptr)free_fn, (png_voidp)mem_ptr); |
81 #else |
180 #else |
82 png_destroy_struct((png_voidp)png_ptr); |
181 png_destroy_struct((png_voidp)png_ptr); |
83 #endif |
182 #endif |
84 return (NULL); |
183 return (NULL); |
85 } |
184 } |
86 #ifdef USE_FAR_KEYWORD |
|
87 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); |
|
88 #endif |
|
89 #endif |
|
90 |
|
91 #ifdef PNG_USER_MEM_SUPPORTED |
|
92 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
|
93 #endif |
|
94 |
|
95 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
|
96 |
|
97 if (user_png_ver) |
|
98 { |
|
99 i = 0; |
|
100 do |
|
101 { |
|
102 if (user_png_ver[i] != png_libpng_ver[i]) |
|
103 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
|
104 } while (png_libpng_ver[i++]); |
|
105 } |
|
106 else |
|
107 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
|
108 |
|
109 |
|
110 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
|
111 { |
|
112 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
|
113 * we must recompile any applications that use any older library version. |
|
114 * For versions after libpng 1.0, we will be compatible, so we need |
|
115 * only check the first digit. |
|
116 */ |
|
117 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
|
118 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || |
|
119 (user_png_ver[0] == '0' && user_png_ver[2] < '9')) |
|
120 { |
|
121 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
|
122 char msg[80]; |
|
123 if (user_png_ver) |
|
124 { |
|
125 png_snprintf(msg, 80, |
|
126 "Application was compiled with png.h from libpng-%.20s", |
|
127 user_png_ver); |
|
128 png_warning(png_ptr, msg); |
|
129 } |
|
130 png_snprintf(msg, 80, |
|
131 "Application is running with png.c from libpng-%.20s", |
|
132 png_libpng_ver); |
|
133 png_warning(png_ptr, msg); |
|
134 #endif |
|
135 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
|
136 png_ptr->flags = 0; |
|
137 #endif |
|
138 png_error(png_ptr, |
|
139 "Incompatible libpng version in application and library"); |
|
140 } |
|
141 } |
|
142 |
|
143 /* Initialize zbuf - compression buffer */ |
|
144 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
|
145 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
|
146 (png_uint_32)png_ptr->zbuf_size); |
|
147 png_ptr->zstream.zalloc = png_zalloc; |
|
148 png_ptr->zstream.zfree = png_zfree; |
|
149 png_ptr->zstream.opaque = (voidpf)png_ptr; |
|
150 |
|
151 switch (inflateInit(&png_ptr->zstream)) |
|
152 { |
|
153 case Z_OK: /* Do nothing */ break; |
|
154 case Z_MEM_ERROR: |
|
155 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; |
|
156 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break; |
|
157 default: png_error(png_ptr, "Unknown zlib error"); |
|
158 } |
|
159 |
185 |
160 png_ptr->zstream.next_out = png_ptr->zbuf; |
186 png_ptr->zstream.next_out = png_ptr->zbuf; |
161 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
187 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
162 |
188 |
163 png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); |
189 png_set_read_fn(png_ptr, NULL, NULL); |
164 |
190 |
165 #ifdef PNG_SETJMP_SUPPORTED |
191 |
166 /* Applications that neglect to set up their own setjmp() and then encounter |
|
167 a png_error() will longjmp here. Since the jmpbuf is then meaningless we |
|
168 abort instead of returning. */ |
|
169 #ifdef USE_FAR_KEYWORD |
|
170 if (setjmp(jmpbuf)) |
|
171 PNG_ABORT(); |
|
172 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); |
|
173 #else |
|
174 if (setjmp(png_ptr->jmpbuf)) |
|
175 PNG_ABORT(); |
|
176 #endif |
|
177 #endif |
|
178 return (png_ptr); |
192 return (png_ptr); |
179 } |
193 } |
180 |
194 |
181 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) |
195 |
182 /* Initialize PNG structure for reading, and allocate any memory needed. |
196 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
183 This interface is deprecated in favour of the png_create_read_struct(), |
|
184 and it will disappear as of libpng-1.3.0. */ |
|
185 #undef png_read_init |
|
186 void PNGAPI |
|
187 png_read_init(png_structp png_ptr) |
|
188 { |
|
189 /* We only come here via pre-1.0.7-compiled applications */ |
|
190 png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); |
|
191 } |
|
192 |
|
193 void PNGAPI |
|
194 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, |
|
195 png_size_t png_struct_size, png_size_t png_info_size) |
|
196 { |
|
197 /* We only come here via pre-1.0.12-compiled applications */ |
|
198 if (png_ptr == NULL) |
|
199 return; |
|
200 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
|
201 if (png_sizeof(png_struct) > png_struct_size || |
|
202 png_sizeof(png_info) > png_info_size) |
|
203 { |
|
204 char msg[80]; |
|
205 png_ptr->warning_fn = NULL; |
|
206 if (user_png_ver) |
|
207 { |
|
208 png_snprintf(msg, 80, |
|
209 "Application was compiled with png.h from libpng-%.20s", |
|
210 user_png_ver); |
|
211 png_warning(png_ptr, msg); |
|
212 } |
|
213 png_snprintf(msg, 80, |
|
214 "Application is running with png.c from libpng-%.20s", |
|
215 png_libpng_ver); |
|
216 png_warning(png_ptr, msg); |
|
217 } |
|
218 #endif |
|
219 if (png_sizeof(png_struct) > png_struct_size) |
|
220 { |
|
221 png_ptr->error_fn = NULL; |
|
222 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
|
223 png_ptr->flags = 0; |
|
224 #endif |
|
225 png_error(png_ptr, |
|
226 "The png struct allocated by the application for reading is too small."); |
|
227 } |
|
228 if (png_sizeof(png_info) > png_info_size) |
|
229 { |
|
230 png_ptr->error_fn = NULL; |
|
231 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
|
232 png_ptr->flags = 0; |
|
233 #endif |
|
234 png_error(png_ptr, |
|
235 "The info struct allocated by application for reading is too small."); |
|
236 } |
|
237 png_read_init_3(&png_ptr, user_png_ver, png_struct_size); |
|
238 } |
|
239 #endif /* PNG_1_0_X || PNG_1_2_X */ |
|
240 |
|
241 void PNGAPI |
|
242 png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, |
|
243 png_size_t png_struct_size) |
|
244 { |
|
245 #ifdef PNG_SETJMP_SUPPORTED |
|
246 jmp_buf tmp_jmp; /* to save current jump buffer */ |
|
247 #endif |
|
248 |
|
249 int i = 0; |
|
250 |
|
251 png_structp png_ptr=*ptr_ptr; |
|
252 |
|
253 if (png_ptr == NULL) |
|
254 return; |
|
255 |
|
256 do |
|
257 { |
|
258 if (user_png_ver[i] != png_libpng_ver[i]) |
|
259 { |
|
260 #ifdef PNG_LEGACY_SUPPORTED |
|
261 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
|
262 #else |
|
263 png_ptr->warning_fn = NULL; |
|
264 png_warning(png_ptr, |
|
265 "Application uses deprecated png_read_init() and should be recompiled."); |
|
266 break; |
|
267 #endif |
|
268 } |
|
269 } while (png_libpng_ver[i++]); |
|
270 |
|
271 png_debug(1, "in png_read_init_3"); |
|
272 |
|
273 #ifdef PNG_SETJMP_SUPPORTED |
|
274 /* Save jump buffer and error functions */ |
|
275 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
|
276 #endif |
|
277 |
|
278 if (png_sizeof(png_struct) > png_struct_size) |
|
279 { |
|
280 png_destroy_struct(png_ptr); |
|
281 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
|
282 png_ptr = *ptr_ptr; |
|
283 } |
|
284 |
|
285 /* Reset all variables to 0 */ |
|
286 png_memset(png_ptr, 0, png_sizeof(png_struct)); |
|
287 |
|
288 #ifdef PNG_SETJMP_SUPPORTED |
|
289 /* Restore jump buffer */ |
|
290 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
|
291 #endif |
|
292 |
|
293 /* Added at libpng-1.2.6 */ |
|
294 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
|
295 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
|
296 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
|
297 #endif |
|
298 |
|
299 /* Initialize zbuf - compression buffer */ |
|
300 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
|
301 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
|
302 (png_uint_32)png_ptr->zbuf_size); |
|
303 png_ptr->zstream.zalloc = png_zalloc; |
|
304 png_ptr->zstream.zfree = png_zfree; |
|
305 png_ptr->zstream.opaque = (voidpf)png_ptr; |
|
306 |
|
307 switch (inflateInit(&png_ptr->zstream)) |
|
308 { |
|
309 case Z_OK: /* Do nothing */ break; |
|
310 case Z_MEM_ERROR: |
|
311 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break; |
|
312 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break; |
|
313 default: png_error(png_ptr, "Unknown zlib error"); |
|
314 } |
|
315 |
|
316 png_ptr->zstream.next_out = png_ptr->zbuf; |
|
317 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
|
318 |
|
319 png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); |
|
320 } |
|
321 |
|
322 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
|
323 /* Read the information before the actual image data. This has been |
197 /* Read the information before the actual image data. This has been |
324 * changed in v0.90 to allow reading a file that already has the magic |
198 * changed in v0.90 to allow reading a file that already has the magic |
325 * bytes read from the stream. You can tell libpng how many bytes have |
199 * bytes read from the stream. You can tell libpng how many bytes have |
326 * been read from the beginning of the stream (up to the maximum of 8) |
200 * been read from the beginning of the stream (up to the maximum of 8) |
327 * via png_set_sig_bytes(), and we will only check the remaining bytes |
201 * via png_set_sig_bytes(), and we will only check the remaining bytes |
459 |
337 |
460 png_ptr->idat_size = length; |
338 png_ptr->idat_size = length; |
461 png_ptr->mode |= PNG_HAVE_IDAT; |
339 png_ptr->mode |= PNG_HAVE_IDAT; |
462 break; |
340 break; |
463 } |
341 } |
464 #if defined(PNG_READ_bKGD_SUPPORTED) |
342 #ifdef PNG_READ_bKGD_SUPPORTED |
465 else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
343 else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
466 png_handle_bKGD(png_ptr, info_ptr, length); |
344 png_handle_bKGD(png_ptr, info_ptr, length); |
467 #endif |
345 #endif |
468 #if defined(PNG_READ_cHRM_SUPPORTED) |
346 #ifdef PNG_READ_cHRM_SUPPORTED |
469 else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
347 else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
470 png_handle_cHRM(png_ptr, info_ptr, length); |
348 png_handle_cHRM(png_ptr, info_ptr, length); |
471 #endif |
349 #endif |
472 #if defined(PNG_READ_gAMA_SUPPORTED) |
350 #ifdef PNG_READ_gAMA_SUPPORTED |
473 else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
351 else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
474 png_handle_gAMA(png_ptr, info_ptr, length); |
352 png_handle_gAMA(png_ptr, info_ptr, length); |
475 #endif |
353 #endif |
476 #if defined(PNG_READ_hIST_SUPPORTED) |
354 #ifdef PNG_READ_hIST_SUPPORTED |
477 else if (!png_memcmp(chunk_name, png_hIST, 4)) |
355 else if (!png_memcmp(chunk_name, png_hIST, 4)) |
478 png_handle_hIST(png_ptr, info_ptr, length); |
356 png_handle_hIST(png_ptr, info_ptr, length); |
479 #endif |
357 #endif |
480 #if defined(PNG_READ_oFFs_SUPPORTED) |
358 #ifdef PNG_READ_oFFs_SUPPORTED |
481 else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
359 else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
482 png_handle_oFFs(png_ptr, info_ptr, length); |
360 png_handle_oFFs(png_ptr, info_ptr, length); |
483 #endif |
361 #endif |
484 #if defined(PNG_READ_pCAL_SUPPORTED) |
362 #ifdef PNG_READ_pCAL_SUPPORTED |
485 else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
363 else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
486 png_handle_pCAL(png_ptr, info_ptr, length); |
364 png_handle_pCAL(png_ptr, info_ptr, length); |
487 #endif |
365 #endif |
488 #if defined(PNG_READ_sCAL_SUPPORTED) |
366 #ifdef PNG_READ_sCAL_SUPPORTED |
489 else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
367 else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
490 png_handle_sCAL(png_ptr, info_ptr, length); |
368 png_handle_sCAL(png_ptr, info_ptr, length); |
491 #endif |
369 #endif |
492 #if defined(PNG_READ_pHYs_SUPPORTED) |
370 #ifdef PNG_READ_pHYs_SUPPORTED |
493 else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
371 else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
494 png_handle_pHYs(png_ptr, info_ptr, length); |
372 png_handle_pHYs(png_ptr, info_ptr, length); |
495 #endif |
373 #endif |
496 #if defined(PNG_READ_sBIT_SUPPORTED) |
374 #ifdef PNG_READ_sBIT_SUPPORTED |
497 else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
375 else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
498 png_handle_sBIT(png_ptr, info_ptr, length); |
376 png_handle_sBIT(png_ptr, info_ptr, length); |
499 #endif |
377 #endif |
500 #if defined(PNG_READ_sRGB_SUPPORTED) |
378 #ifdef PNG_READ_sRGB_SUPPORTED |
501 else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
379 else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
502 png_handle_sRGB(png_ptr, info_ptr, length); |
380 png_handle_sRGB(png_ptr, info_ptr, length); |
503 #endif |
381 #endif |
504 #if defined(PNG_READ_iCCP_SUPPORTED) |
382 #ifdef PNG_READ_iCCP_SUPPORTED |
505 else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
383 else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
506 png_handle_iCCP(png_ptr, info_ptr, length); |
384 png_handle_iCCP(png_ptr, info_ptr, length); |
507 #endif |
385 #endif |
508 #if defined(PNG_READ_sPLT_SUPPORTED) |
386 #ifdef PNG_READ_sPLT_SUPPORTED |
509 else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
387 else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
510 png_handle_sPLT(png_ptr, info_ptr, length); |
388 png_handle_sPLT(png_ptr, info_ptr, length); |
511 #endif |
389 #endif |
512 #if defined(PNG_READ_tEXt_SUPPORTED) |
390 #ifdef PNG_READ_tEXt_SUPPORTED |
513 else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
391 else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
514 png_handle_tEXt(png_ptr, info_ptr, length); |
392 png_handle_tEXt(png_ptr, info_ptr, length); |
515 #endif |
393 #endif |
516 #if defined(PNG_READ_tIME_SUPPORTED) |
394 #ifdef PNG_READ_tIME_SUPPORTED |
517 else if (!png_memcmp(chunk_name, png_tIME, 4)) |
395 else if (!png_memcmp(chunk_name, png_tIME, 4)) |
518 png_handle_tIME(png_ptr, info_ptr, length); |
396 png_handle_tIME(png_ptr, info_ptr, length); |
519 #endif |
397 #endif |
520 #if defined(PNG_READ_tRNS_SUPPORTED) |
398 #ifdef PNG_READ_tRNS_SUPPORTED |
521 else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
399 else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
522 png_handle_tRNS(png_ptr, info_ptr, length); |
400 png_handle_tRNS(png_ptr, info_ptr, length); |
523 #endif |
401 #endif |
524 #if defined(PNG_READ_zTXt_SUPPORTED) |
402 #ifdef PNG_READ_zTXt_SUPPORTED |
525 else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
403 else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
526 png_handle_zTXt(png_ptr, info_ptr, length); |
404 png_handle_zTXt(png_ptr, info_ptr, length); |
527 #endif |
405 #endif |
528 #if defined(PNG_READ_iTXt_SUPPORTED) |
406 #ifdef PNG_READ_iTXt_SUPPORTED |
529 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
407 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
530 png_handle_iTXt(png_ptr, info_ptr, length); |
408 png_handle_iTXt(png_ptr, info_ptr, length); |
531 #endif |
409 #endif |
532 else |
410 else |
533 png_handle_unknown(png_ptr, info_ptr, length); |
411 png_handle_unknown(png_ptr, info_ptr, length); |
534 } |
412 } |
535 } |
413 } |
536 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
414 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
537 |
415 |
538 /* Optional call to update the users info_ptr structure */ |
416 /* Optional call to update the users info_ptr structure */ |
539 void PNGAPI |
417 void PNGAPI |
540 png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
418 png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
541 { |
419 { |
542 png_debug(1, "in png_read_update_info"); |
420 png_debug(1, "in png_read_update_info"); |
|
421 |
543 if (png_ptr == NULL) |
422 if (png_ptr == NULL) |
544 return; |
423 return; |
545 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
424 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
546 png_read_start_row(png_ptr); |
425 png_read_start_row(png_ptr); |
547 else |
426 else |
548 png_warning(png_ptr, |
427 png_warning(png_ptr, |
549 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); |
428 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); |
|
429 |
550 png_read_transform_info(png_ptr, info_ptr); |
430 png_read_transform_info(png_ptr, info_ptr); |
551 } |
431 } |
552 |
432 |
553 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
433 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
554 /* Initialize palette, background, etc, after transformations |
434 /* Initialize palette, background, etc, after transformations |
555 * are set, but before any reading takes place. This allows |
435 * are set, but before any reading takes place. This allows |
556 * the user to obtain a gamma-corrected palette, for example. |
436 * the user to obtain a gamma-corrected palette, for example. |
557 * If the user doesn't call this, we will do it ourselves. |
437 * If the user doesn't call this, we will do it ourselves. |
558 */ |
438 */ |
559 void PNGAPI |
439 void PNGAPI |
560 png_start_read_image(png_structp png_ptr) |
440 png_start_read_image(png_structp png_ptr) |
561 { |
441 { |
562 png_debug(1, "in png_start_read_image"); |
442 png_debug(1, "in png_start_read_image"); |
|
443 |
563 if (png_ptr == NULL) |
444 if (png_ptr == NULL) |
564 return; |
445 return; |
565 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
446 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
566 png_read_start_row(png_ptr); |
447 png_read_start_row(png_ptr); |
567 } |
448 } |
568 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
449 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
569 |
450 |
570 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
451 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
571 void PNGAPI |
452 void PNGAPI |
572 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
453 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
573 { |
454 { |
574 #ifdef PNG_USE_LOCAL_ARRAYS |
455 PNG_IDAT; |
575 PNG_CONST PNG_IDAT; |
|
576 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, |
456 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, |
577 0xff}; |
457 0xff}; |
578 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
458 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
579 #endif |
|
580 int ret; |
459 int ret; |
|
460 |
581 if (png_ptr == NULL) |
461 if (png_ptr == NULL) |
582 return; |
462 return; |
|
463 |
583 png_debug2(1, "in png_read_row (row %lu, pass %d)", |
464 png_debug2(1, "in png_read_row (row %lu, pass %d)", |
584 png_ptr->row_number, png_ptr->pass); |
465 (unsigned long) png_ptr->row_number, png_ptr->pass); |
|
466 |
585 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
467 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
586 png_read_start_row(png_ptr); |
468 png_read_start_row(png_ptr); |
587 if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
469 if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
588 { |
470 { |
589 /* Check for transforms that have been set but were defined out */ |
471 /* Check for transforms that have been set but were defined out */ |
590 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
472 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
591 if (png_ptr->transformations & PNG_INVERT_MONO) |
473 if (png_ptr->transformations & PNG_INVERT_MONO) |
592 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); |
474 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); |
593 #endif |
475 #endif |
594 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) |
476 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) |
595 if (png_ptr->transformations & PNG_FILLER) |
477 if (png_ptr->transformations & PNG_FILLER) |
596 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined."); |
478 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); |
597 #endif |
479 #endif |
598 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED) |
480 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED) |
599 if (png_ptr->transformations & PNG_PACKSWAP) |
481 if (png_ptr->transformations & PNG_PACKSWAP) |
600 png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined."); |
482 png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); |
601 #endif |
483 #endif |
602 #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) |
484 #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) |
603 if (png_ptr->transformations & PNG_PACK) |
485 if (png_ptr->transformations & PNG_PACK) |
604 png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined."); |
486 png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); |
605 #endif |
487 #endif |
606 #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) |
488 #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) |
607 if (png_ptr->transformations & PNG_SHIFT) |
489 if (png_ptr->transformations & PNG_SHIFT) |
608 png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined."); |
490 png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); |
609 #endif |
491 #endif |
610 #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) |
492 #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) |
611 if (png_ptr->transformations & PNG_BGR) |
493 if (png_ptr->transformations & PNG_BGR) |
612 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined."); |
494 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); |
613 #endif |
495 #endif |
614 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) |
496 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) |
615 if (png_ptr->transformations & PNG_SWAP_BYTES) |
497 if (png_ptr->transformations & PNG_SWAP_BYTES) |
616 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined."); |
498 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); |
617 #endif |
499 #endif |
618 } |
500 } |
619 |
501 |
620 #if defined(PNG_READ_INTERLACING_SUPPORTED) |
502 #ifdef PNG_READ_INTERLACING_SUPPORTED |
621 /* If interlaced and we do not need a new row, combine row and return */ |
503 /* If interlaced and we do not need a new row, combine row and return */ |
622 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
504 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
623 { |
505 { |
624 switch (png_ptr->pass) |
506 switch (png_ptr->pass) |
625 { |
507 { |
901 for (j = 0; j < pass; j++) |
784 for (j = 0; j < pass; j++) |
902 { |
785 { |
903 rp = image; |
786 rp = image; |
904 for (i = 0; i < image_height; i++) |
787 for (i = 0; i < image_height; i++) |
905 { |
788 { |
906 png_read_row(png_ptr, *rp, png_bytep_NULL); |
789 png_read_row(png_ptr, *rp, NULL); |
907 rp++; |
790 rp++; |
908 } |
791 } |
909 } |
792 } |
910 } |
793 } |
911 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
794 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
912 |
795 |
913 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
796 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
914 /* Read the end of the PNG file. Will not read past the end of the |
797 /* Read the end of the PNG file. Will not read past the end of the |
915 * file, will verify the end is accurate, and will read any comments |
798 * file, will verify the end is accurate, and will read any comments |
916 * or time information at the end of the file, if info is not NULL. |
799 * or time information at the end of the file, if info is not NULL. |
917 */ |
800 */ |
918 void PNGAPI |
801 void PNGAPI |
919 png_read_end(png_structp png_ptr, png_infop info_ptr) |
802 png_read_end(png_structp png_ptr, png_infop info_ptr) |
920 { |
803 { |
921 png_debug(1, "in png_read_end"); |
804 png_debug(1, "in png_read_end"); |
|
805 |
922 if (png_ptr == NULL) |
806 if (png_ptr == NULL) |
923 return; |
807 return; |
924 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ |
808 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ |
925 |
809 |
926 do |
810 do |
927 { |
811 { |
928 #ifdef PNG_USE_LOCAL_ARRAYS |
812 PNG_IHDR; |
929 PNG_CONST PNG_IHDR; |
813 PNG_IDAT; |
930 PNG_CONST PNG_IDAT; |
814 PNG_IEND; |
931 PNG_CONST PNG_IEND; |
815 PNG_PLTE; |
932 PNG_CONST PNG_PLTE; |
816 #ifdef PNG_READ_bKGD_SUPPORTED |
933 #if defined(PNG_READ_bKGD_SUPPORTED) |
817 PNG_bKGD; |
934 PNG_CONST PNG_bKGD; |
818 #endif |
935 #endif |
819 #ifdef PNG_READ_cHRM_SUPPORTED |
936 #if defined(PNG_READ_cHRM_SUPPORTED) |
820 PNG_cHRM; |
937 PNG_CONST PNG_cHRM; |
821 #endif |
938 #endif |
822 #ifdef PNG_READ_gAMA_SUPPORTED |
939 #if defined(PNG_READ_gAMA_SUPPORTED) |
823 PNG_gAMA; |
940 PNG_CONST PNG_gAMA; |
824 #endif |
941 #endif |
825 #ifdef PNG_READ_hIST_SUPPORTED |
942 #if defined(PNG_READ_hIST_SUPPORTED) |
826 PNG_hIST; |
943 PNG_CONST PNG_hIST; |
827 #endif |
944 #endif |
828 #ifdef PNG_READ_iCCP_SUPPORTED |
945 #if defined(PNG_READ_iCCP_SUPPORTED) |
829 PNG_iCCP; |
946 PNG_CONST PNG_iCCP; |
830 #endif |
947 #endif |
831 #ifdef PNG_READ_iTXt_SUPPORTED |
948 #if defined(PNG_READ_iTXt_SUPPORTED) |
832 PNG_iTXt; |
949 PNG_CONST PNG_iTXt; |
833 #endif |
950 #endif |
834 #ifdef PNG_READ_oFFs_SUPPORTED |
951 #if defined(PNG_READ_oFFs_SUPPORTED) |
835 PNG_oFFs; |
952 PNG_CONST PNG_oFFs; |
836 #endif |
953 #endif |
837 #ifdef PNG_READ_pCAL_SUPPORTED |
954 #if defined(PNG_READ_pCAL_SUPPORTED) |
838 PNG_pCAL; |
955 PNG_CONST PNG_pCAL; |
839 #endif |
956 #endif |
840 #ifdef PNG_READ_pHYs_SUPPORTED |
957 #if defined(PNG_READ_pHYs_SUPPORTED) |
841 PNG_pHYs; |
958 PNG_CONST PNG_pHYs; |
842 #endif |
959 #endif |
843 #ifdef PNG_READ_sBIT_SUPPORTED |
960 #if defined(PNG_READ_sBIT_SUPPORTED) |
844 PNG_sBIT; |
961 PNG_CONST PNG_sBIT; |
845 #endif |
962 #endif |
846 #ifdef PNG_READ_sCAL_SUPPORTED |
963 #if defined(PNG_READ_sCAL_SUPPORTED) |
847 PNG_sCAL; |
964 PNG_CONST PNG_sCAL; |
848 #endif |
965 #endif |
849 #ifdef PNG_READ_sPLT_SUPPORTED |
966 #if defined(PNG_READ_sPLT_SUPPORTED) |
850 PNG_sPLT; |
967 PNG_CONST PNG_sPLT; |
851 #endif |
968 #endif |
852 #ifdef PNG_READ_sRGB_SUPPORTED |
969 #if defined(PNG_READ_sRGB_SUPPORTED) |
853 PNG_sRGB; |
970 PNG_CONST PNG_sRGB; |
854 #endif |
971 #endif |
855 #ifdef PNG_READ_tEXt_SUPPORTED |
972 #if defined(PNG_READ_tEXt_SUPPORTED) |
856 PNG_tEXt; |
973 PNG_CONST PNG_tEXt; |
857 #endif |
974 #endif |
858 #ifdef PNG_READ_tIME_SUPPORTED |
975 #if defined(PNG_READ_tIME_SUPPORTED) |
859 PNG_tIME; |
976 PNG_CONST PNG_tIME; |
860 #endif |
977 #endif |
861 #ifdef PNG_READ_tRNS_SUPPORTED |
978 #if defined(PNG_READ_tRNS_SUPPORTED) |
862 PNG_tRNS; |
979 PNG_CONST PNG_tRNS; |
863 #endif |
980 #endif |
864 #ifdef PNG_READ_zTXt_SUPPORTED |
981 #if defined(PNG_READ_zTXt_SUPPORTED) |
865 PNG_zTXt; |
982 PNG_CONST PNG_zTXt; |
866 #endif |
983 #endif |
|
984 #endif /* PNG_USE_LOCAL_ARRAYS */ |
|
985 png_uint_32 length = png_read_chunk_header(png_ptr); |
867 png_uint_32 length = png_read_chunk_header(png_ptr); |
986 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
868 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
987 |
869 |
988 if (!png_memcmp(chunk_name, png_IHDR, 4)) |
870 if (!png_memcmp(chunk_name, png_IHDR, 4)) |
989 png_handle_IHDR(png_ptr, info_ptr, length); |
871 png_handle_IHDR(png_ptr, info_ptr, length); |
1006 { |
888 { |
1007 /* Zero length IDATs are legal after the last IDAT has been |
889 /* Zero length IDATs are legal after the last IDAT has been |
1008 * read, but not after other chunks have been read. |
890 * read, but not after other chunks have been read. |
1009 */ |
891 */ |
1010 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
892 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
1011 png_error(png_ptr, "Too many IDAT's found"); |
893 png_benign_error(png_ptr, "Too many IDATs found"); |
1012 png_crc_finish(png_ptr, length); |
894 png_crc_finish(png_ptr, length); |
1013 } |
895 } |
1014 else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
896 else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
1015 png_handle_PLTE(png_ptr, info_ptr, length); |
897 png_handle_PLTE(png_ptr, info_ptr, length); |
1016 #if defined(PNG_READ_bKGD_SUPPORTED) |
898 #ifdef PNG_READ_bKGD_SUPPORTED |
1017 else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
899 else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
1018 png_handle_bKGD(png_ptr, info_ptr, length); |
900 png_handle_bKGD(png_ptr, info_ptr, length); |
1019 #endif |
901 #endif |
1020 #if defined(PNG_READ_cHRM_SUPPORTED) |
902 #ifdef PNG_READ_cHRM_SUPPORTED |
1021 else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
903 else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
1022 png_handle_cHRM(png_ptr, info_ptr, length); |
904 png_handle_cHRM(png_ptr, info_ptr, length); |
1023 #endif |
905 #endif |
1024 #if defined(PNG_READ_gAMA_SUPPORTED) |
906 #ifdef PNG_READ_gAMA_SUPPORTED |
1025 else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
907 else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
1026 png_handle_gAMA(png_ptr, info_ptr, length); |
908 png_handle_gAMA(png_ptr, info_ptr, length); |
1027 #endif |
909 #endif |
1028 #if defined(PNG_READ_hIST_SUPPORTED) |
910 #ifdef PNG_READ_hIST_SUPPORTED |
1029 else if (!png_memcmp(chunk_name, png_hIST, 4)) |
911 else if (!png_memcmp(chunk_name, png_hIST, 4)) |
1030 png_handle_hIST(png_ptr, info_ptr, length); |
912 png_handle_hIST(png_ptr, info_ptr, length); |
1031 #endif |
913 #endif |
1032 #if defined(PNG_READ_oFFs_SUPPORTED) |
914 #ifdef PNG_READ_oFFs_SUPPORTED |
1033 else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
915 else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
1034 png_handle_oFFs(png_ptr, info_ptr, length); |
916 png_handle_oFFs(png_ptr, info_ptr, length); |
1035 #endif |
917 #endif |
1036 #if defined(PNG_READ_pCAL_SUPPORTED) |
918 #ifdef PNG_READ_pCAL_SUPPORTED |
1037 else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
919 else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
1038 png_handle_pCAL(png_ptr, info_ptr, length); |
920 png_handle_pCAL(png_ptr, info_ptr, length); |
1039 #endif |
921 #endif |
1040 #if defined(PNG_READ_sCAL_SUPPORTED) |
922 #ifdef PNG_READ_sCAL_SUPPORTED |
1041 else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
923 else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
1042 png_handle_sCAL(png_ptr, info_ptr, length); |
924 png_handle_sCAL(png_ptr, info_ptr, length); |
1043 #endif |
925 #endif |
1044 #if defined(PNG_READ_pHYs_SUPPORTED) |
926 #ifdef PNG_READ_pHYs_SUPPORTED |
1045 else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
927 else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
1046 png_handle_pHYs(png_ptr, info_ptr, length); |
928 png_handle_pHYs(png_ptr, info_ptr, length); |
1047 #endif |
929 #endif |
1048 #if defined(PNG_READ_sBIT_SUPPORTED) |
930 #ifdef PNG_READ_sBIT_SUPPORTED |
1049 else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
931 else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
1050 png_handle_sBIT(png_ptr, info_ptr, length); |
932 png_handle_sBIT(png_ptr, info_ptr, length); |
1051 #endif |
933 #endif |
1052 #if defined(PNG_READ_sRGB_SUPPORTED) |
934 #ifdef PNG_READ_sRGB_SUPPORTED |
1053 else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
935 else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
1054 png_handle_sRGB(png_ptr, info_ptr, length); |
936 png_handle_sRGB(png_ptr, info_ptr, length); |
1055 #endif |
937 #endif |
1056 #if defined(PNG_READ_iCCP_SUPPORTED) |
938 #ifdef PNG_READ_iCCP_SUPPORTED |
1057 else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
939 else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
1058 png_handle_iCCP(png_ptr, info_ptr, length); |
940 png_handle_iCCP(png_ptr, info_ptr, length); |
1059 #endif |
941 #endif |
1060 #if defined(PNG_READ_sPLT_SUPPORTED) |
942 #ifdef PNG_READ_sPLT_SUPPORTED |
1061 else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
943 else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
1062 png_handle_sPLT(png_ptr, info_ptr, length); |
944 png_handle_sPLT(png_ptr, info_ptr, length); |
1063 #endif |
945 #endif |
1064 #if defined(PNG_READ_tEXt_SUPPORTED) |
946 #ifdef PNG_READ_tEXt_SUPPORTED |
1065 else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
947 else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
1066 png_handle_tEXt(png_ptr, info_ptr, length); |
948 png_handle_tEXt(png_ptr, info_ptr, length); |
1067 #endif |
949 #endif |
1068 #if defined(PNG_READ_tIME_SUPPORTED) |
950 #ifdef PNG_READ_tIME_SUPPORTED |
1069 else if (!png_memcmp(chunk_name, png_tIME, 4)) |
951 else if (!png_memcmp(chunk_name, png_tIME, 4)) |
1070 png_handle_tIME(png_ptr, info_ptr, length); |
952 png_handle_tIME(png_ptr, info_ptr, length); |
1071 #endif |
953 #endif |
1072 #if defined(PNG_READ_tRNS_SUPPORTED) |
954 #ifdef PNG_READ_tRNS_SUPPORTED |
1073 else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
955 else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
1074 png_handle_tRNS(png_ptr, info_ptr, length); |
956 png_handle_tRNS(png_ptr, info_ptr, length); |
1075 #endif |
957 #endif |
1076 #if defined(PNG_READ_zTXt_SUPPORTED) |
958 #ifdef PNG_READ_zTXt_SUPPORTED |
1077 else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
959 else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
1078 png_handle_zTXt(png_ptr, info_ptr, length); |
960 png_handle_zTXt(png_ptr, info_ptr, length); |
1079 #endif |
961 #endif |
1080 #if defined(PNG_READ_iTXt_SUPPORTED) |
962 #ifdef PNG_READ_iTXt_SUPPORTED |
1081 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
963 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
1082 png_handle_iTXt(png_ptr, info_ptr, length); |
964 png_handle_iTXt(png_ptr, info_ptr, length); |
1083 #endif |
965 #endif |
1084 else |
966 else |
1085 png_handle_unknown(png_ptr, info_ptr, length); |
967 png_handle_unknown(png_ptr, info_ptr, length); |
1086 } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
968 } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
1087 } |
969 } |
1088 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
970 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
1089 |
971 |
1090 /* Free all memory used by the read */ |
972 /* Free all memory used by the read */ |
1091 void PNGAPI |
973 void PNGAPI |
1092 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
974 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
1093 png_infopp end_info_ptr_ptr) |
975 png_infopp end_info_ptr_ptr) |
1172 #ifdef PNG_USER_MEM_SUPPORTED |
1055 #ifdef PNG_USER_MEM_SUPPORTED |
1173 png_free_ptr free_fn; |
1056 png_free_ptr free_fn; |
1174 #endif |
1057 #endif |
1175 |
1058 |
1176 png_debug(1, "in png_read_destroy"); |
1059 png_debug(1, "in png_read_destroy"); |
|
1060 |
1177 if (info_ptr != NULL) |
1061 if (info_ptr != NULL) |
1178 png_info_destroy(png_ptr, info_ptr); |
1062 png_info_destroy(png_ptr, info_ptr); |
1179 |
1063 |
1180 if (end_info_ptr != NULL) |
1064 if (end_info_ptr != NULL) |
1181 png_info_destroy(png_ptr, end_info_ptr); |
1065 png_info_destroy(png_ptr, end_info_ptr); |
1182 |
1066 |
1183 png_free(png_ptr, png_ptr->zbuf); |
1067 png_free(png_ptr, png_ptr->zbuf); |
1184 png_free(png_ptr, png_ptr->big_row_buf); |
1068 png_free(png_ptr, png_ptr->big_row_buf); |
1185 png_free(png_ptr, png_ptr->prev_row); |
1069 png_free(png_ptr, png_ptr->prev_row); |
1186 png_free(png_ptr, png_ptr->chunkdata); |
1070 png_free(png_ptr, png_ptr->chunkdata); |
1187 #if defined(PNG_READ_DITHER_SUPPORTED) |
1071 #ifdef PNG_READ_DITHER_SUPPORTED |
1188 png_free(png_ptr, png_ptr->palette_lookup); |
1072 png_free(png_ptr, png_ptr->palette_lookup); |
1189 png_free(png_ptr, png_ptr->dither_index); |
1073 png_free(png_ptr, png_ptr->dither_index); |
1190 #endif |
1074 #endif |
1191 #if defined(PNG_READ_GAMMA_SUPPORTED) |
1075 #ifdef PNG_READ_GAMMA_SUPPORTED |
1192 png_free(png_ptr, png_ptr->gamma_table); |
1076 png_free(png_ptr, png_ptr->gamma_table); |
1193 #endif |
1077 #endif |
1194 #if defined(PNG_READ_BACKGROUND_SUPPORTED) |
1078 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
1195 png_free(png_ptr, png_ptr->gamma_from_1); |
1079 png_free(png_ptr, png_ptr->gamma_from_1); |
1196 png_free(png_ptr, png_ptr->gamma_to_1); |
1080 png_free(png_ptr, png_ptr->gamma_to_1); |
1197 #endif |
1081 #endif |
1198 #ifdef PNG_FREE_ME_SUPPORTED |
|
1199 if (png_ptr->free_me & PNG_FREE_PLTE) |
1082 if (png_ptr->free_me & PNG_FREE_PLTE) |
1200 png_zfree(png_ptr, png_ptr->palette); |
1083 png_zfree(png_ptr, png_ptr->palette); |
1201 png_ptr->free_me &= ~PNG_FREE_PLTE; |
1084 png_ptr->free_me &= ~PNG_FREE_PLTE; |
1202 #else |
|
1203 if (png_ptr->flags & PNG_FLAG_FREE_PLTE) |
|
1204 png_zfree(png_ptr, png_ptr->palette); |
|
1205 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE; |
|
1206 #endif |
|
1207 #if defined(PNG_tRNS_SUPPORTED) || \ |
1085 #if defined(PNG_tRNS_SUPPORTED) || \ |
1208 defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) |
1086 defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) |
1209 #ifdef PNG_FREE_ME_SUPPORTED |
|
1210 if (png_ptr->free_me & PNG_FREE_TRNS) |
1087 if (png_ptr->free_me & PNG_FREE_TRNS) |
1211 png_free(png_ptr, png_ptr->trans); |
1088 png_free(png_ptr, png_ptr->trans_alpha); |
1212 png_ptr->free_me &= ~PNG_FREE_TRNS; |
1089 png_ptr->free_me &= ~PNG_FREE_TRNS; |
1213 #else |
1090 #endif |
1214 if (png_ptr->flags & PNG_FLAG_FREE_TRNS) |
1091 #ifdef PNG_READ_hIST_SUPPORTED |
1215 png_free(png_ptr, png_ptr->trans); |
|
1216 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS; |
|
1217 #endif |
|
1218 #endif |
|
1219 #if defined(PNG_READ_hIST_SUPPORTED) |
|
1220 #ifdef PNG_FREE_ME_SUPPORTED |
|
1221 if (png_ptr->free_me & PNG_FREE_HIST) |
1092 if (png_ptr->free_me & PNG_FREE_HIST) |
1222 png_free(png_ptr, png_ptr->hist); |
1093 png_free(png_ptr, png_ptr->hist); |
1223 png_ptr->free_me &= ~PNG_FREE_HIST; |
1094 png_ptr->free_me &= ~PNG_FREE_HIST; |
1224 #else |
1095 #endif |
1225 if (png_ptr->flags & PNG_FLAG_FREE_HIST) |
1096 #ifdef PNG_READ_GAMMA_SUPPORTED |
1226 png_free(png_ptr, png_ptr->hist); |
|
1227 png_ptr->flags &= ~PNG_FLAG_FREE_HIST; |
|
1228 #endif |
|
1229 #endif |
|
1230 #if defined(PNG_READ_GAMMA_SUPPORTED) |
|
1231 if (png_ptr->gamma_16_table != NULL) |
1097 if (png_ptr->gamma_16_table != NULL) |
1232 { |
1098 { |
1233 int i; |
1099 int i; |
1234 int istop = (1 << (8 - png_ptr->gamma_shift)); |
1100 int istop = (1 << (8 - png_ptr->gamma_shift)); |
1235 for (i = 0; i < istop; i++) |
1101 for (i = 0; i < istop; i++) |
1236 { |
1102 { |
1237 png_free(png_ptr, png_ptr->gamma_16_table[i]); |
1103 png_free(png_ptr, png_ptr->gamma_16_table[i]); |
1238 } |
1104 } |
1239 png_free(png_ptr, png_ptr->gamma_16_table); |
1105 png_free(png_ptr, png_ptr->gamma_16_table); |
1240 } |
1106 } |
1241 #if defined(PNG_READ_BACKGROUND_SUPPORTED) |
1107 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
1242 if (png_ptr->gamma_16_from_1 != NULL) |
1108 if (png_ptr->gamma_16_from_1 != NULL) |
1243 { |
1109 { |
1244 int i; |
1110 int i; |
1245 int istop = (1 << (8 - png_ptr->gamma_shift)); |
1111 int istop = (1 << (8 - png_ptr->gamma_shift)); |
1246 for (i = 0; i < istop; i++) |
1112 for (i = 0; i < istop; i++) |