rev |
line source |
nuclear@1
|
1
|
nuclear@1
|
2 /* pngread.c - read a PNG file
|
nuclear@1
|
3 *
|
nuclear@1
|
4 * Last changed in libpng 1.2.30 [August 15, 2008]
|
nuclear@1
|
5 * For conditions of distribution and use, see copyright notice in png.h
|
nuclear@1
|
6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
|
nuclear@1
|
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
nuclear@1
|
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
nuclear@1
|
9 *
|
nuclear@1
|
10 * This file contains routines that an application calls directly to
|
nuclear@1
|
11 * read a PNG file or stream.
|
nuclear@1
|
12 */
|
nuclear@1
|
13
|
nuclear@1
|
14 #define PNG_INTERNAL
|
nuclear@1
|
15 #include "png.h"
|
nuclear@1
|
16 #if defined(PNG_READ_SUPPORTED)
|
nuclear@1
|
17
|
nuclear@1
|
18 /* Create a PNG structure for reading, and allocate any memory needed. */
|
nuclear@1
|
19 png_structp PNGAPI
|
nuclear@1
|
20 png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
|
nuclear@1
|
21 png_error_ptr error_fn, png_error_ptr warn_fn)
|
nuclear@1
|
22 {
|
nuclear@1
|
23
|
nuclear@1
|
24 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
25 return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
|
nuclear@1
|
26 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
|
nuclear@1
|
27 }
|
nuclear@1
|
28
|
nuclear@1
|
29 /* Alternate create PNG structure for reading, and allocate any memory needed. */
|
nuclear@1
|
30 png_structp PNGAPI
|
nuclear@1
|
31 png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
nuclear@1
|
32 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
nuclear@1
|
33 png_malloc_ptr malloc_fn, png_free_ptr free_fn)
|
nuclear@1
|
34 {
|
nuclear@1
|
35 #endif /* PNG_USER_MEM_SUPPORTED */
|
nuclear@1
|
36
|
nuclear@1
|
37 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
38 volatile
|
nuclear@1
|
39 #endif
|
nuclear@1
|
40 png_structp png_ptr;
|
nuclear@1
|
41
|
nuclear@1
|
42 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
43 #ifdef USE_FAR_KEYWORD
|
nuclear@1
|
44 jmp_buf jmpbuf;
|
nuclear@1
|
45 #endif
|
nuclear@1
|
46 #endif
|
nuclear@1
|
47
|
nuclear@1
|
48 int i;
|
nuclear@1
|
49
|
nuclear@1
|
50 png_debug(1, "in png_create_read_struct\n");
|
nuclear@1
|
51 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
52 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
|
nuclear@1
|
53 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
|
nuclear@1
|
54 #else
|
nuclear@1
|
55 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
|
nuclear@1
|
56 #endif
|
nuclear@1
|
57 if (png_ptr == NULL)
|
nuclear@1
|
58 return (NULL);
|
nuclear@1
|
59
|
nuclear@1
|
60 /* added at libpng-1.2.6 */
|
nuclear@1
|
61 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
nuclear@1
|
62 png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
|
nuclear@1
|
63 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
|
nuclear@1
|
64 #endif
|
nuclear@1
|
65
|
nuclear@1
|
66 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
67 #ifdef USE_FAR_KEYWORD
|
nuclear@1
|
68 if (setjmp(jmpbuf))
|
nuclear@1
|
69 #else
|
nuclear@1
|
70 if (setjmp(png_ptr->jmpbuf))
|
nuclear@1
|
71 #endif
|
nuclear@1
|
72 {
|
nuclear@1
|
73 png_free(png_ptr, png_ptr->zbuf);
|
nuclear@1
|
74 png_ptr->zbuf = NULL;
|
nuclear@1
|
75 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
76 png_destroy_struct_2((png_voidp)png_ptr,
|
nuclear@1
|
77 (png_free_ptr)free_fn, (png_voidp)mem_ptr);
|
nuclear@1
|
78 #else
|
nuclear@1
|
79 png_destroy_struct((png_voidp)png_ptr);
|
nuclear@1
|
80 #endif
|
nuclear@1
|
81 return (NULL);
|
nuclear@1
|
82 }
|
nuclear@1
|
83 #ifdef USE_FAR_KEYWORD
|
nuclear@1
|
84 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
|
nuclear@1
|
85 #endif
|
nuclear@1
|
86 #endif
|
nuclear@1
|
87
|
nuclear@1
|
88 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
89 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
|
nuclear@1
|
90 #endif
|
nuclear@1
|
91
|
nuclear@1
|
92 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
|
nuclear@1
|
93
|
nuclear@1
|
94 if (user_png_ver)
|
nuclear@1
|
95 {
|
nuclear@1
|
96 i = 0;
|
nuclear@1
|
97 do
|
nuclear@1
|
98 {
|
nuclear@1
|
99 if (user_png_ver[i] != png_libpng_ver[i])
|
nuclear@1
|
100 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
|
nuclear@1
|
101 } while (png_libpng_ver[i++]);
|
nuclear@1
|
102 }
|
nuclear@1
|
103 else
|
nuclear@1
|
104 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
|
nuclear@1
|
105
|
nuclear@1
|
106
|
nuclear@1
|
107 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
|
nuclear@1
|
108 {
|
nuclear@1
|
109 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
|
nuclear@1
|
110 * we must recompile any applications that use any older library version.
|
nuclear@1
|
111 * For versions after libpng 1.0, we will be compatible, so we need
|
nuclear@1
|
112 * only check the first digit.
|
nuclear@1
|
113 */
|
nuclear@1
|
114 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
|
nuclear@1
|
115 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
|
nuclear@1
|
116 (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
|
nuclear@1
|
117 {
|
nuclear@1
|
118 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
|
nuclear@1
|
119 char msg[80];
|
nuclear@1
|
120 if (user_png_ver)
|
nuclear@1
|
121 {
|
nuclear@1
|
122 png_snprintf(msg, 80,
|
nuclear@1
|
123 "Application was compiled with png.h from libpng-%.20s",
|
nuclear@1
|
124 user_png_ver);
|
nuclear@1
|
125 png_warning(png_ptr, msg);
|
nuclear@1
|
126 }
|
nuclear@1
|
127 png_snprintf(msg, 80,
|
nuclear@1
|
128 "Application is running with png.c from libpng-%.20s",
|
nuclear@1
|
129 png_libpng_ver);
|
nuclear@1
|
130 png_warning(png_ptr, msg);
|
nuclear@1
|
131 #endif
|
nuclear@1
|
132 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
nuclear@1
|
133 png_ptr->flags = 0;
|
nuclear@1
|
134 #endif
|
nuclear@1
|
135 png_error(png_ptr,
|
nuclear@1
|
136 "Incompatible libpng version in application and library");
|
nuclear@1
|
137 }
|
nuclear@1
|
138 }
|
nuclear@1
|
139
|
nuclear@1
|
140 /* initialize zbuf - compression buffer */
|
nuclear@1
|
141 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
nuclear@1
|
142 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
|
nuclear@1
|
143 (png_uint_32)png_ptr->zbuf_size);
|
nuclear@1
|
144 png_ptr->zstream.zalloc = png_zalloc;
|
nuclear@1
|
145 png_ptr->zstream.zfree = png_zfree;
|
nuclear@1
|
146 png_ptr->zstream.opaque = (voidpf)png_ptr;
|
nuclear@1
|
147
|
nuclear@1
|
148 switch (inflateInit(&png_ptr->zstream))
|
nuclear@1
|
149 {
|
nuclear@1
|
150 case Z_OK: /* Do nothing */ break;
|
nuclear@1
|
151 case Z_MEM_ERROR:
|
nuclear@1
|
152 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
|
nuclear@1
|
153 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
|
nuclear@1
|
154 default: png_error(png_ptr, "Unknown zlib error");
|
nuclear@1
|
155 }
|
nuclear@1
|
156
|
nuclear@1
|
157 png_ptr->zstream.next_out = png_ptr->zbuf;
|
nuclear@1
|
158 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
nuclear@1
|
159
|
nuclear@1
|
160 png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
|
nuclear@1
|
161
|
nuclear@1
|
162 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
163 /* Applications that neglect to set up their own setjmp() and then encounter
|
nuclear@1
|
164 a png_error() will longjmp here. Since the jmpbuf is then meaningless we
|
nuclear@1
|
165 abort instead of returning. */
|
nuclear@1
|
166 #ifdef USE_FAR_KEYWORD
|
nuclear@1
|
167 if (setjmp(jmpbuf))
|
nuclear@1
|
168 PNG_ABORT();
|
nuclear@1
|
169 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
|
nuclear@1
|
170 #else
|
nuclear@1
|
171 if (setjmp(png_ptr->jmpbuf))
|
nuclear@1
|
172 PNG_ABORT();
|
nuclear@1
|
173 #endif
|
nuclear@1
|
174 #endif
|
nuclear@1
|
175 return (png_ptr);
|
nuclear@1
|
176 }
|
nuclear@1
|
177
|
nuclear@1
|
178 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
|
nuclear@1
|
179 /* Initialize PNG structure for reading, and allocate any memory needed.
|
nuclear@1
|
180 This interface is deprecated in favour of the png_create_read_struct(),
|
nuclear@1
|
181 and it will disappear as of libpng-1.3.0. */
|
nuclear@1
|
182 #undef png_read_init
|
nuclear@1
|
183 void PNGAPI
|
nuclear@1
|
184 png_read_init(png_structp png_ptr)
|
nuclear@1
|
185 {
|
nuclear@1
|
186 /* We only come here via pre-1.0.7-compiled applications */
|
nuclear@1
|
187 png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
|
nuclear@1
|
188 }
|
nuclear@1
|
189
|
nuclear@1
|
190 void PNGAPI
|
nuclear@1
|
191 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
|
nuclear@1
|
192 png_size_t png_struct_size, png_size_t png_info_size)
|
nuclear@1
|
193 {
|
nuclear@1
|
194 /* We only come here via pre-1.0.12-compiled applications */
|
nuclear@1
|
195 if (png_ptr == NULL) return;
|
nuclear@1
|
196 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
|
nuclear@1
|
197 if (png_sizeof(png_struct) > png_struct_size ||
|
nuclear@1
|
198 png_sizeof(png_info) > png_info_size)
|
nuclear@1
|
199 {
|
nuclear@1
|
200 char msg[80];
|
nuclear@1
|
201 png_ptr->warning_fn = NULL;
|
nuclear@1
|
202 if (user_png_ver)
|
nuclear@1
|
203 {
|
nuclear@1
|
204 png_snprintf(msg, 80,
|
nuclear@1
|
205 "Application was compiled with png.h from libpng-%.20s",
|
nuclear@1
|
206 user_png_ver);
|
nuclear@1
|
207 png_warning(png_ptr, msg);
|
nuclear@1
|
208 }
|
nuclear@1
|
209 png_snprintf(msg, 80,
|
nuclear@1
|
210 "Application is running with png.c from libpng-%.20s",
|
nuclear@1
|
211 png_libpng_ver);
|
nuclear@1
|
212 png_warning(png_ptr, msg);
|
nuclear@1
|
213 }
|
nuclear@1
|
214 #endif
|
nuclear@1
|
215 if (png_sizeof(png_struct) > png_struct_size)
|
nuclear@1
|
216 {
|
nuclear@1
|
217 png_ptr->error_fn = NULL;
|
nuclear@1
|
218 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
nuclear@1
|
219 png_ptr->flags = 0;
|
nuclear@1
|
220 #endif
|
nuclear@1
|
221 png_error(png_ptr,
|
nuclear@1
|
222 "The png struct allocated by the application for reading is too small.");
|
nuclear@1
|
223 }
|
nuclear@1
|
224 if (png_sizeof(png_info) > png_info_size)
|
nuclear@1
|
225 {
|
nuclear@1
|
226 png_ptr->error_fn = NULL;
|
nuclear@1
|
227 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
nuclear@1
|
228 png_ptr->flags = 0;
|
nuclear@1
|
229 #endif
|
nuclear@1
|
230 png_error(png_ptr,
|
nuclear@1
|
231 "The info struct allocated by application for reading is too small.");
|
nuclear@1
|
232 }
|
nuclear@1
|
233 png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
|
nuclear@1
|
234 }
|
nuclear@1
|
235 #endif /* PNG_1_0_X || PNG_1_2_X */
|
nuclear@1
|
236
|
nuclear@1
|
237 void PNGAPI
|
nuclear@1
|
238 png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
|
nuclear@1
|
239 png_size_t png_struct_size)
|
nuclear@1
|
240 {
|
nuclear@1
|
241 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
242 jmp_buf tmp_jmp; /* to save current jump buffer */
|
nuclear@1
|
243 #endif
|
nuclear@1
|
244
|
nuclear@1
|
245 int i = 0;
|
nuclear@1
|
246
|
nuclear@1
|
247 png_structp png_ptr=*ptr_ptr;
|
nuclear@1
|
248
|
nuclear@1
|
249 if (png_ptr == NULL) return;
|
nuclear@1
|
250
|
nuclear@1
|
251 do
|
nuclear@1
|
252 {
|
nuclear@1
|
253 if (user_png_ver[i] != png_libpng_ver[i])
|
nuclear@1
|
254 {
|
nuclear@1
|
255 #ifdef PNG_LEGACY_SUPPORTED
|
nuclear@1
|
256 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
|
nuclear@1
|
257 #else
|
nuclear@1
|
258 png_ptr->warning_fn = NULL;
|
nuclear@1
|
259 png_warning(png_ptr,
|
nuclear@1
|
260 "Application uses deprecated png_read_init() and should be recompiled.");
|
nuclear@1
|
261 break;
|
nuclear@1
|
262 #endif
|
nuclear@1
|
263 }
|
nuclear@1
|
264 } while (png_libpng_ver[i++]);
|
nuclear@1
|
265
|
nuclear@1
|
266 png_debug(1, "in png_read_init_3\n");
|
nuclear@1
|
267
|
nuclear@1
|
268 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
269 /* save jump buffer and error functions */
|
nuclear@1
|
270 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
|
nuclear@1
|
271 #endif
|
nuclear@1
|
272
|
nuclear@1
|
273 if (png_sizeof(png_struct) > png_struct_size)
|
nuclear@1
|
274 {
|
nuclear@1
|
275 png_destroy_struct(png_ptr);
|
nuclear@1
|
276 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
|
nuclear@1
|
277 png_ptr = *ptr_ptr;
|
nuclear@1
|
278 }
|
nuclear@1
|
279
|
nuclear@1
|
280 /* reset all variables to 0 */
|
nuclear@1
|
281 png_memset(png_ptr, 0, png_sizeof(png_struct));
|
nuclear@1
|
282
|
nuclear@1
|
283 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
284 /* restore jump buffer */
|
nuclear@1
|
285 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
|
nuclear@1
|
286 #endif
|
nuclear@1
|
287
|
nuclear@1
|
288 /* added at libpng-1.2.6 */
|
nuclear@1
|
289 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
nuclear@1
|
290 png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
|
nuclear@1
|
291 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
|
nuclear@1
|
292 #endif
|
nuclear@1
|
293
|
nuclear@1
|
294 /* initialize zbuf - compression buffer */
|
nuclear@1
|
295 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
nuclear@1
|
296 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
|
nuclear@1
|
297 (png_uint_32)png_ptr->zbuf_size);
|
nuclear@1
|
298 png_ptr->zstream.zalloc = png_zalloc;
|
nuclear@1
|
299 png_ptr->zstream.zfree = png_zfree;
|
nuclear@1
|
300 png_ptr->zstream.opaque = (voidpf)png_ptr;
|
nuclear@1
|
301
|
nuclear@1
|
302 switch (inflateInit(&png_ptr->zstream))
|
nuclear@1
|
303 {
|
nuclear@1
|
304 case Z_OK: /* Do nothing */ break;
|
nuclear@1
|
305 case Z_MEM_ERROR:
|
nuclear@1
|
306 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
|
nuclear@1
|
307 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
|
nuclear@1
|
308 default: png_error(png_ptr, "Unknown zlib error");
|
nuclear@1
|
309 }
|
nuclear@1
|
310
|
nuclear@1
|
311 png_ptr->zstream.next_out = png_ptr->zbuf;
|
nuclear@1
|
312 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
nuclear@1
|
313
|
nuclear@1
|
314 png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
|
nuclear@1
|
315 }
|
nuclear@1
|
316
|
nuclear@1
|
317 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
318 /* Read the information before the actual image data. This has been
|
nuclear@1
|
319 * changed in v0.90 to allow reading a file that already has the magic
|
nuclear@1
|
320 * bytes read from the stream. You can tell libpng how many bytes have
|
nuclear@1
|
321 * been read from the beginning of the stream (up to the maximum of 8)
|
nuclear@1
|
322 * via png_set_sig_bytes(), and we will only check the remaining bytes
|
nuclear@1
|
323 * here. The application can then have access to the signature bytes we
|
nuclear@1
|
324 * read if it is determined that this isn't a valid PNG file.
|
nuclear@1
|
325 */
|
nuclear@1
|
326 void PNGAPI
|
nuclear@1
|
327 png_read_info(png_structp png_ptr, png_infop info_ptr)
|
nuclear@1
|
328 {
|
nuclear@1
|
329 if (png_ptr == NULL || info_ptr == NULL) return;
|
nuclear@1
|
330 png_debug(1, "in png_read_info\n");
|
nuclear@1
|
331 /* If we haven't checked all of the PNG signature bytes, do so now. */
|
nuclear@1
|
332 if (png_ptr->sig_bytes < 8)
|
nuclear@1
|
333 {
|
nuclear@1
|
334 png_size_t num_checked = png_ptr->sig_bytes,
|
nuclear@1
|
335 num_to_check = 8 - num_checked;
|
nuclear@1
|
336
|
nuclear@1
|
337 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
|
nuclear@1
|
338 png_ptr->sig_bytes = 8;
|
nuclear@1
|
339
|
nuclear@1
|
340 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
nuclear@1
|
341 {
|
nuclear@1
|
342 if (num_checked < 4 &&
|
nuclear@1
|
343 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
|
nuclear@1
|
344 png_error(png_ptr, "Not a PNG file");
|
nuclear@1
|
345 else
|
nuclear@1
|
346 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
|
nuclear@1
|
347 }
|
nuclear@1
|
348 if (num_checked < 3)
|
nuclear@1
|
349 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
|
nuclear@1
|
350 }
|
nuclear@1
|
351
|
nuclear@1
|
352 for (;;)
|
nuclear@1
|
353 {
|
nuclear@1
|
354 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@1
|
355 PNG_CONST PNG_IHDR;
|
nuclear@1
|
356 PNG_CONST PNG_IDAT;
|
nuclear@1
|
357 PNG_CONST PNG_IEND;
|
nuclear@1
|
358 PNG_CONST PNG_PLTE;
|
nuclear@1
|
359 #if defined(PNG_READ_bKGD_SUPPORTED)
|
nuclear@1
|
360 PNG_CONST PNG_bKGD;
|
nuclear@1
|
361 #endif
|
nuclear@1
|
362 #if defined(PNG_READ_cHRM_SUPPORTED)
|
nuclear@1
|
363 PNG_CONST PNG_cHRM;
|
nuclear@1
|
364 #endif
|
nuclear@1
|
365 #if defined(PNG_READ_gAMA_SUPPORTED)
|
nuclear@1
|
366 PNG_CONST PNG_gAMA;
|
nuclear@1
|
367 #endif
|
nuclear@1
|
368 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@1
|
369 PNG_CONST PNG_hIST;
|
nuclear@1
|
370 #endif
|
nuclear@1
|
371 #if defined(PNG_READ_iCCP_SUPPORTED)
|
nuclear@1
|
372 PNG_CONST PNG_iCCP;
|
nuclear@1
|
373 #endif
|
nuclear@1
|
374 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@1
|
375 PNG_CONST PNG_iTXt;
|
nuclear@1
|
376 #endif
|
nuclear@1
|
377 #if defined(PNG_READ_oFFs_SUPPORTED)
|
nuclear@1
|
378 PNG_CONST PNG_oFFs;
|
nuclear@1
|
379 #endif
|
nuclear@1
|
380 #if defined(PNG_READ_pCAL_SUPPORTED)
|
nuclear@1
|
381 PNG_CONST PNG_pCAL;
|
nuclear@1
|
382 #endif
|
nuclear@1
|
383 #if defined(PNG_READ_pHYs_SUPPORTED)
|
nuclear@1
|
384 PNG_CONST PNG_pHYs;
|
nuclear@1
|
385 #endif
|
nuclear@1
|
386 #if defined(PNG_READ_sBIT_SUPPORTED)
|
nuclear@1
|
387 PNG_CONST PNG_sBIT;
|
nuclear@1
|
388 #endif
|
nuclear@1
|
389 #if defined(PNG_READ_sCAL_SUPPORTED)
|
nuclear@1
|
390 PNG_CONST PNG_sCAL;
|
nuclear@1
|
391 #endif
|
nuclear@1
|
392 #if defined(PNG_READ_sPLT_SUPPORTED)
|
nuclear@1
|
393 PNG_CONST PNG_sPLT;
|
nuclear@1
|
394 #endif
|
nuclear@1
|
395 #if defined(PNG_READ_sRGB_SUPPORTED)
|
nuclear@1
|
396 PNG_CONST PNG_sRGB;
|
nuclear@1
|
397 #endif
|
nuclear@1
|
398 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@1
|
399 PNG_CONST PNG_tEXt;
|
nuclear@1
|
400 #endif
|
nuclear@1
|
401 #if defined(PNG_READ_tIME_SUPPORTED)
|
nuclear@1
|
402 PNG_CONST PNG_tIME;
|
nuclear@1
|
403 #endif
|
nuclear@1
|
404 #if defined(PNG_READ_tRNS_SUPPORTED)
|
nuclear@1
|
405 PNG_CONST PNG_tRNS;
|
nuclear@1
|
406 #endif
|
nuclear@1
|
407 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@1
|
408 PNG_CONST PNG_zTXt;
|
nuclear@1
|
409 #endif
|
nuclear@1
|
410 #endif /* PNG_USE_LOCAL_ARRAYS */
|
nuclear@1
|
411 png_uint_32 length = png_read_chunk_header(png_ptr);
|
nuclear@1
|
412 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
|
nuclear@1
|
413
|
nuclear@1
|
414 /* This should be a binary subdivision search or a hash for
|
nuclear@1
|
415 * matching the chunk name rather than a linear search.
|
nuclear@1
|
416 */
|
nuclear@1
|
417 if (!png_memcmp(chunk_name, png_IDAT, 4))
|
nuclear@1
|
418 if (png_ptr->mode & PNG_AFTER_IDAT)
|
nuclear@1
|
419 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
|
nuclear@1
|
420
|
nuclear@1
|
421 if (!png_memcmp(chunk_name, png_IHDR, 4))
|
nuclear@1
|
422 png_handle_IHDR(png_ptr, info_ptr, length);
|
nuclear@1
|
423 else if (!png_memcmp(chunk_name, png_IEND, 4))
|
nuclear@1
|
424 png_handle_IEND(png_ptr, info_ptr, length);
|
nuclear@1
|
425 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
nuclear@1
|
426 else if (png_handle_as_unknown(png_ptr, chunk_name))
|
nuclear@1
|
427 {
|
nuclear@1
|
428 if (!png_memcmp(chunk_name, png_IDAT, 4))
|
nuclear@1
|
429 png_ptr->mode |= PNG_HAVE_IDAT;
|
nuclear@1
|
430 png_handle_unknown(png_ptr, info_ptr, length);
|
nuclear@1
|
431 if (!png_memcmp(chunk_name, png_PLTE, 4))
|
nuclear@1
|
432 png_ptr->mode |= PNG_HAVE_PLTE;
|
nuclear@1
|
433 else if (!png_memcmp(chunk_name, png_IDAT, 4))
|
nuclear@1
|
434 {
|
nuclear@1
|
435 if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
nuclear@1
|
436 png_error(png_ptr, "Missing IHDR before IDAT");
|
nuclear@1
|
437 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
nuclear@1
|
438 !(png_ptr->mode & PNG_HAVE_PLTE))
|
nuclear@1
|
439 png_error(png_ptr, "Missing PLTE before IDAT");
|
nuclear@1
|
440 break;
|
nuclear@1
|
441 }
|
nuclear@1
|
442 }
|
nuclear@1
|
443 #endif
|
nuclear@1
|
444 else if (!png_memcmp(chunk_name, png_PLTE, 4))
|
nuclear@1
|
445 png_handle_PLTE(png_ptr, info_ptr, length);
|
nuclear@1
|
446 else if (!png_memcmp(chunk_name, png_IDAT, 4))
|
nuclear@1
|
447 {
|
nuclear@1
|
448 if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
nuclear@1
|
449 png_error(png_ptr, "Missing IHDR before IDAT");
|
nuclear@1
|
450 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
nuclear@1
|
451 !(png_ptr->mode & PNG_HAVE_PLTE))
|
nuclear@1
|
452 png_error(png_ptr, "Missing PLTE before IDAT");
|
nuclear@1
|
453
|
nuclear@1
|
454 png_ptr->idat_size = length;
|
nuclear@1
|
455 png_ptr->mode |= PNG_HAVE_IDAT;
|
nuclear@1
|
456 break;
|
nuclear@1
|
457 }
|
nuclear@1
|
458 #if defined(PNG_READ_bKGD_SUPPORTED)
|
nuclear@1
|
459 else if (!png_memcmp(chunk_name, png_bKGD, 4))
|
nuclear@1
|
460 png_handle_bKGD(png_ptr, info_ptr, length);
|
nuclear@1
|
461 #endif
|
nuclear@1
|
462 #if defined(PNG_READ_cHRM_SUPPORTED)
|
nuclear@1
|
463 else if (!png_memcmp(chunk_name, png_cHRM, 4))
|
nuclear@1
|
464 png_handle_cHRM(png_ptr, info_ptr, length);
|
nuclear@1
|
465 #endif
|
nuclear@1
|
466 #if defined(PNG_READ_gAMA_SUPPORTED)
|
nuclear@1
|
467 else if (!png_memcmp(chunk_name, png_gAMA, 4))
|
nuclear@1
|
468 png_handle_gAMA(png_ptr, info_ptr, length);
|
nuclear@1
|
469 #endif
|
nuclear@1
|
470 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@1
|
471 else if (!png_memcmp(chunk_name, png_hIST, 4))
|
nuclear@1
|
472 png_handle_hIST(png_ptr, info_ptr, length);
|
nuclear@1
|
473 #endif
|
nuclear@1
|
474 #if defined(PNG_READ_oFFs_SUPPORTED)
|
nuclear@1
|
475 else if (!png_memcmp(chunk_name, png_oFFs, 4))
|
nuclear@1
|
476 png_handle_oFFs(png_ptr, info_ptr, length);
|
nuclear@1
|
477 #endif
|
nuclear@1
|
478 #if defined(PNG_READ_pCAL_SUPPORTED)
|
nuclear@1
|
479 else if (!png_memcmp(chunk_name, png_pCAL, 4))
|
nuclear@1
|
480 png_handle_pCAL(png_ptr, info_ptr, length);
|
nuclear@1
|
481 #endif
|
nuclear@1
|
482 #if defined(PNG_READ_sCAL_SUPPORTED)
|
nuclear@1
|
483 else if (!png_memcmp(chunk_name, png_sCAL, 4))
|
nuclear@1
|
484 png_handle_sCAL(png_ptr, info_ptr, length);
|
nuclear@1
|
485 #endif
|
nuclear@1
|
486 #if defined(PNG_READ_pHYs_SUPPORTED)
|
nuclear@1
|
487 else if (!png_memcmp(chunk_name, png_pHYs, 4))
|
nuclear@1
|
488 png_handle_pHYs(png_ptr, info_ptr, length);
|
nuclear@1
|
489 #endif
|
nuclear@1
|
490 #if defined(PNG_READ_sBIT_SUPPORTED)
|
nuclear@1
|
491 else if (!png_memcmp(chunk_name, png_sBIT, 4))
|
nuclear@1
|
492 png_handle_sBIT(png_ptr, info_ptr, length);
|
nuclear@1
|
493 #endif
|
nuclear@1
|
494 #if defined(PNG_READ_sRGB_SUPPORTED)
|
nuclear@1
|
495 else if (!png_memcmp(chunk_name, png_sRGB, 4))
|
nuclear@1
|
496 png_handle_sRGB(png_ptr, info_ptr, length);
|
nuclear@1
|
497 #endif
|
nuclear@1
|
498 #if defined(PNG_READ_iCCP_SUPPORTED)
|
nuclear@1
|
499 else if (!png_memcmp(chunk_name, png_iCCP, 4))
|
nuclear@1
|
500 png_handle_iCCP(png_ptr, info_ptr, length);
|
nuclear@1
|
501 #endif
|
nuclear@1
|
502 #if defined(PNG_READ_sPLT_SUPPORTED)
|
nuclear@1
|
503 else if (!png_memcmp(chunk_name, png_sPLT, 4))
|
nuclear@1
|
504 png_handle_sPLT(png_ptr, info_ptr, length);
|
nuclear@1
|
505 #endif
|
nuclear@1
|
506 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@1
|
507 else if (!png_memcmp(chunk_name, png_tEXt, 4))
|
nuclear@1
|
508 png_handle_tEXt(png_ptr, info_ptr, length);
|
nuclear@1
|
509 #endif
|
nuclear@1
|
510 #if defined(PNG_READ_tIME_SUPPORTED)
|
nuclear@1
|
511 else if (!png_memcmp(chunk_name, png_tIME, 4))
|
nuclear@1
|
512 png_handle_tIME(png_ptr, info_ptr, length);
|
nuclear@1
|
513 #endif
|
nuclear@1
|
514 #if defined(PNG_READ_tRNS_SUPPORTED)
|
nuclear@1
|
515 else if (!png_memcmp(chunk_name, png_tRNS, 4))
|
nuclear@1
|
516 png_handle_tRNS(png_ptr, info_ptr, length);
|
nuclear@1
|
517 #endif
|
nuclear@1
|
518 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@1
|
519 else if (!png_memcmp(chunk_name, png_zTXt, 4))
|
nuclear@1
|
520 png_handle_zTXt(png_ptr, info_ptr, length);
|
nuclear@1
|
521 #endif
|
nuclear@1
|
522 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@1
|
523 else if (!png_memcmp(chunk_name, png_iTXt, 4))
|
nuclear@1
|
524 png_handle_iTXt(png_ptr, info_ptr, length);
|
nuclear@1
|
525 #endif
|
nuclear@1
|
526 else
|
nuclear@1
|
527 png_handle_unknown(png_ptr, info_ptr, length);
|
nuclear@1
|
528 }
|
nuclear@1
|
529 }
|
nuclear@1
|
530 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
531
|
nuclear@1
|
532 /* optional call to update the users info_ptr structure */
|
nuclear@1
|
533 void PNGAPI
|
nuclear@1
|
534 png_read_update_info(png_structp png_ptr, png_infop info_ptr)
|
nuclear@1
|
535 {
|
nuclear@1
|
536 png_debug(1, "in png_read_update_info\n");
|
nuclear@1
|
537 if (png_ptr == NULL) return;
|
nuclear@1
|
538 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
nuclear@1
|
539 png_read_start_row(png_ptr);
|
nuclear@1
|
540 else
|
nuclear@1
|
541 png_warning(png_ptr,
|
nuclear@1
|
542 "Ignoring extra png_read_update_info() call; row buffer not reallocated");
|
nuclear@1
|
543 png_read_transform_info(png_ptr, info_ptr);
|
nuclear@1
|
544 }
|
nuclear@1
|
545
|
nuclear@1
|
546 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
547 /* Initialize palette, background, etc, after transformations
|
nuclear@1
|
548 * are set, but before any reading takes place. This allows
|
nuclear@1
|
549 * the user to obtain a gamma-corrected palette, for example.
|
nuclear@1
|
550 * If the user doesn't call this, we will do it ourselves.
|
nuclear@1
|
551 */
|
nuclear@1
|
552 void PNGAPI
|
nuclear@1
|
553 png_start_read_image(png_structp png_ptr)
|
nuclear@1
|
554 {
|
nuclear@1
|
555 png_debug(1, "in png_start_read_image\n");
|
nuclear@1
|
556 if (png_ptr == NULL) return;
|
nuclear@1
|
557 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
nuclear@1
|
558 png_read_start_row(png_ptr);
|
nuclear@1
|
559 }
|
nuclear@1
|
560 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
561
|
nuclear@1
|
562 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
563 void PNGAPI
|
nuclear@1
|
564 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
nuclear@1
|
565 {
|
nuclear@1
|
566 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@1
|
567 PNG_CONST PNG_IDAT;
|
nuclear@1
|
568 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
|
nuclear@1
|
569 0xff};
|
nuclear@1
|
570 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
nuclear@1
|
571 #endif
|
nuclear@1
|
572 int ret;
|
nuclear@1
|
573 if (png_ptr == NULL) return;
|
nuclear@1
|
574 png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
|
nuclear@1
|
575 png_ptr->row_number, png_ptr->pass);
|
nuclear@1
|
576 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
nuclear@1
|
577 png_read_start_row(png_ptr);
|
nuclear@1
|
578 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
nuclear@1
|
579 {
|
nuclear@1
|
580 /* check for transforms that have been set but were defined out */
|
nuclear@1
|
581 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
|
nuclear@1
|
582 if (png_ptr->transformations & PNG_INVERT_MONO)
|
nuclear@1
|
583 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
|
nuclear@1
|
584 #endif
|
nuclear@1
|
585 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
|
nuclear@1
|
586 if (png_ptr->transformations & PNG_FILLER)
|
nuclear@1
|
587 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
|
nuclear@1
|
588 #endif
|
nuclear@1
|
589 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
|
nuclear@1
|
590 if (png_ptr->transformations & PNG_PACKSWAP)
|
nuclear@1
|
591 png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
|
nuclear@1
|
592 #endif
|
nuclear@1
|
593 #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
|
nuclear@1
|
594 if (png_ptr->transformations & PNG_PACK)
|
nuclear@1
|
595 png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
|
nuclear@1
|
596 #endif
|
nuclear@1
|
597 #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
|
nuclear@1
|
598 if (png_ptr->transformations & PNG_SHIFT)
|
nuclear@1
|
599 png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
|
nuclear@1
|
600 #endif
|
nuclear@1
|
601 #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
|
nuclear@1
|
602 if (png_ptr->transformations & PNG_BGR)
|
nuclear@1
|
603 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
|
nuclear@1
|
604 #endif
|
nuclear@1
|
605 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
|
nuclear@1
|
606 if (png_ptr->transformations & PNG_SWAP_BYTES)
|
nuclear@1
|
607 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
|
nuclear@1
|
608 #endif
|
nuclear@1
|
609 }
|
nuclear@1
|
610
|
nuclear@1
|
611 #if defined(PNG_READ_INTERLACING_SUPPORTED)
|
nuclear@1
|
612 /* if interlaced and we do not need a new row, combine row and return */
|
nuclear@1
|
613 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
nuclear@1
|
614 {
|
nuclear@1
|
615 switch (png_ptr->pass)
|
nuclear@1
|
616 {
|
nuclear@1
|
617 case 0:
|
nuclear@1
|
618 if (png_ptr->row_number & 0x07)
|
nuclear@1
|
619 {
|
nuclear@1
|
620 if (dsp_row != NULL)
|
nuclear@1
|
621 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
622 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
623 png_read_finish_row(png_ptr);
|
nuclear@1
|
624 return;
|
nuclear@1
|
625 }
|
nuclear@1
|
626 break;
|
nuclear@1
|
627 case 1:
|
nuclear@1
|
628 if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
|
nuclear@1
|
629 {
|
nuclear@1
|
630 if (dsp_row != NULL)
|
nuclear@1
|
631 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
632 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
633 png_read_finish_row(png_ptr);
|
nuclear@1
|
634 return;
|
nuclear@1
|
635 }
|
nuclear@1
|
636 break;
|
nuclear@1
|
637 case 2:
|
nuclear@1
|
638 if ((png_ptr->row_number & 0x07) != 4)
|
nuclear@1
|
639 {
|
nuclear@1
|
640 if (dsp_row != NULL && (png_ptr->row_number & 4))
|
nuclear@1
|
641 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
642 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
643 png_read_finish_row(png_ptr);
|
nuclear@1
|
644 return;
|
nuclear@1
|
645 }
|
nuclear@1
|
646 break;
|
nuclear@1
|
647 case 3:
|
nuclear@1
|
648 if ((png_ptr->row_number & 3) || png_ptr->width < 3)
|
nuclear@1
|
649 {
|
nuclear@1
|
650 if (dsp_row != NULL)
|
nuclear@1
|
651 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
652 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
653 png_read_finish_row(png_ptr);
|
nuclear@1
|
654 return;
|
nuclear@1
|
655 }
|
nuclear@1
|
656 break;
|
nuclear@1
|
657 case 4:
|
nuclear@1
|
658 if ((png_ptr->row_number & 3) != 2)
|
nuclear@1
|
659 {
|
nuclear@1
|
660 if (dsp_row != NULL && (png_ptr->row_number & 2))
|
nuclear@1
|
661 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
662 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
663 png_read_finish_row(png_ptr);
|
nuclear@1
|
664 return;
|
nuclear@1
|
665 }
|
nuclear@1
|
666 break;
|
nuclear@1
|
667 case 5:
|
nuclear@1
|
668 if ((png_ptr->row_number & 1) || png_ptr->width < 2)
|
nuclear@1
|
669 {
|
nuclear@1
|
670 if (dsp_row != NULL)
|
nuclear@1
|
671 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
672 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
673 png_read_finish_row(png_ptr);
|
nuclear@1
|
674 return;
|
nuclear@1
|
675 }
|
nuclear@1
|
676 break;
|
nuclear@1
|
677 case 6:
|
nuclear@1
|
678 if (!(png_ptr->row_number & 1))
|
nuclear@1
|
679 {
|
nuclear@1
|
680 png_read_finish_row(png_ptr);
|
nuclear@1
|
681 return;
|
nuclear@1
|
682 }
|
nuclear@1
|
683 break;
|
nuclear@1
|
684 }
|
nuclear@1
|
685 }
|
nuclear@1
|
686 #endif
|
nuclear@1
|
687
|
nuclear@1
|
688 if (!(png_ptr->mode & PNG_HAVE_IDAT))
|
nuclear@1
|
689 png_error(png_ptr, "Invalid attempt to read row data");
|
nuclear@1
|
690
|
nuclear@1
|
691 png_ptr->zstream.next_out = png_ptr->row_buf;
|
nuclear@1
|
692 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
|
nuclear@1
|
693 do
|
nuclear@1
|
694 {
|
nuclear@1
|
695 if (!(png_ptr->zstream.avail_in))
|
nuclear@1
|
696 {
|
nuclear@1
|
697 while (!png_ptr->idat_size)
|
nuclear@1
|
698 {
|
nuclear@1
|
699 png_crc_finish(png_ptr, 0);
|
nuclear@1
|
700
|
nuclear@1
|
701 png_ptr->idat_size = png_read_chunk_header(png_ptr);
|
nuclear@1
|
702 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
nuclear@1
|
703 png_error(png_ptr, "Not enough image data");
|
nuclear@1
|
704 }
|
nuclear@1
|
705 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
|
nuclear@1
|
706 png_ptr->zstream.next_in = png_ptr->zbuf;
|
nuclear@1
|
707 if (png_ptr->zbuf_size > png_ptr->idat_size)
|
nuclear@1
|
708 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
|
nuclear@1
|
709 png_crc_read(png_ptr, png_ptr->zbuf,
|
nuclear@1
|
710 (png_size_t)png_ptr->zstream.avail_in);
|
nuclear@1
|
711 png_ptr->idat_size -= png_ptr->zstream.avail_in;
|
nuclear@1
|
712 }
|
nuclear@1
|
713 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
|
nuclear@1
|
714 if (ret == Z_STREAM_END)
|
nuclear@1
|
715 {
|
nuclear@1
|
716 if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
|
nuclear@1
|
717 png_ptr->idat_size)
|
nuclear@1
|
718 png_error(png_ptr, "Extra compressed data");
|
nuclear@1
|
719 png_ptr->mode |= PNG_AFTER_IDAT;
|
nuclear@1
|
720 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
|
nuclear@1
|
721 break;
|
nuclear@1
|
722 }
|
nuclear@1
|
723 if (ret != Z_OK)
|
nuclear@1
|
724 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
|
nuclear@1
|
725 "Decompression error");
|
nuclear@1
|
726
|
nuclear@1
|
727 } while (png_ptr->zstream.avail_out);
|
nuclear@1
|
728
|
nuclear@1
|
729 png_ptr->row_info.color_type = png_ptr->color_type;
|
nuclear@1
|
730 png_ptr->row_info.width = png_ptr->iwidth;
|
nuclear@1
|
731 png_ptr->row_info.channels = png_ptr->channels;
|
nuclear@1
|
732 png_ptr->row_info.bit_depth = png_ptr->bit_depth;
|
nuclear@1
|
733 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
|
nuclear@1
|
734 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
|
nuclear@1
|
735 png_ptr->row_info.width);
|
nuclear@1
|
736
|
nuclear@1
|
737 if (png_ptr->row_buf[0])
|
nuclear@1
|
738 png_read_filter_row(png_ptr, &(png_ptr->row_info),
|
nuclear@1
|
739 png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
nuclear@1
|
740 (int)(png_ptr->row_buf[0]));
|
nuclear@1
|
741
|
nuclear@1
|
742 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
|
nuclear@1
|
743 png_ptr->rowbytes + 1);
|
nuclear@1
|
744
|
nuclear@1
|
745 #if defined(PNG_MNG_FEATURES_SUPPORTED)
|
nuclear@1
|
746 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
|
nuclear@1
|
747 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
|
nuclear@1
|
748 {
|
nuclear@1
|
749 /* Intrapixel differencing */
|
nuclear@1
|
750 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
nuclear@1
|
751 }
|
nuclear@1
|
752 #endif
|
nuclear@1
|
753
|
nuclear@1
|
754
|
nuclear@1
|
755 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
|
nuclear@1
|
756 png_do_read_transformations(png_ptr);
|
nuclear@1
|
757
|
nuclear@1
|
758 #if defined(PNG_READ_INTERLACING_SUPPORTED)
|
nuclear@1
|
759 /* blow up interlaced rows to full size */
|
nuclear@1
|
760 if (png_ptr->interlaced &&
|
nuclear@1
|
761 (png_ptr->transformations & PNG_INTERLACE))
|
nuclear@1
|
762 {
|
nuclear@1
|
763 if (png_ptr->pass < 6)
|
nuclear@1
|
764 /* old interface (pre-1.0.9):
|
nuclear@1
|
765 png_do_read_interlace(&(png_ptr->row_info),
|
nuclear@1
|
766 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
|
nuclear@1
|
767 */
|
nuclear@1
|
768 png_do_read_interlace(png_ptr);
|
nuclear@1
|
769
|
nuclear@1
|
770 if (dsp_row != NULL)
|
nuclear@1
|
771 png_combine_row(png_ptr, dsp_row,
|
nuclear@1
|
772 png_pass_dsp_mask[png_ptr->pass]);
|
nuclear@1
|
773 if (row != NULL)
|
nuclear@1
|
774 png_combine_row(png_ptr, row,
|
nuclear@1
|
775 png_pass_mask[png_ptr->pass]);
|
nuclear@1
|
776 }
|
nuclear@1
|
777 else
|
nuclear@1
|
778 #endif
|
nuclear@1
|
779 {
|
nuclear@1
|
780 if (row != NULL)
|
nuclear@1
|
781 png_combine_row(png_ptr, row, 0xff);
|
nuclear@1
|
782 if (dsp_row != NULL)
|
nuclear@1
|
783 png_combine_row(png_ptr, dsp_row, 0xff);
|
nuclear@1
|
784 }
|
nuclear@1
|
785 png_read_finish_row(png_ptr);
|
nuclear@1
|
786
|
nuclear@1
|
787 if (png_ptr->read_row_fn != NULL)
|
nuclear@1
|
788 (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
|
nuclear@1
|
789 }
|
nuclear@1
|
790 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
791
|
nuclear@1
|
792 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
793 /* Read one or more rows of image data. If the image is interlaced,
|
nuclear@1
|
794 * and png_set_interlace_handling() has been called, the rows need to
|
nuclear@1
|
795 * contain the contents of the rows from the previous pass. If the
|
nuclear@1
|
796 * image has alpha or transparency, and png_handle_alpha()[*] has been
|
nuclear@1
|
797 * called, the rows contents must be initialized to the contents of the
|
nuclear@1
|
798 * screen.
|
nuclear@1
|
799 *
|
nuclear@1
|
800 * "row" holds the actual image, and pixels are placed in it
|
nuclear@1
|
801 * as they arrive. If the image is displayed after each pass, it will
|
nuclear@1
|
802 * appear to "sparkle" in. "display_row" can be used to display a
|
nuclear@1
|
803 * "chunky" progressive image, with finer detail added as it becomes
|
nuclear@1
|
804 * available. If you do not want this "chunky" display, you may pass
|
nuclear@1
|
805 * NULL for display_row. If you do not want the sparkle display, and
|
nuclear@1
|
806 * you have not called png_handle_alpha(), you may pass NULL for rows.
|
nuclear@1
|
807 * If you have called png_handle_alpha(), and the image has either an
|
nuclear@1
|
808 * alpha channel or a transparency chunk, you must provide a buffer for
|
nuclear@1
|
809 * rows. In this case, you do not have to provide a display_row buffer
|
nuclear@1
|
810 * also, but you may. If the image is not interlaced, or if you have
|
nuclear@1
|
811 * not called png_set_interlace_handling(), the display_row buffer will
|
nuclear@1
|
812 * be ignored, so pass NULL to it.
|
nuclear@1
|
813 *
|
nuclear@1
|
814 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
|
nuclear@1
|
815 */
|
nuclear@1
|
816
|
nuclear@1
|
817 void PNGAPI
|
nuclear@1
|
818 png_read_rows(png_structp png_ptr, png_bytepp row,
|
nuclear@1
|
819 png_bytepp display_row, png_uint_32 num_rows)
|
nuclear@1
|
820 {
|
nuclear@1
|
821 png_uint_32 i;
|
nuclear@1
|
822 png_bytepp rp;
|
nuclear@1
|
823 png_bytepp dp;
|
nuclear@1
|
824
|
nuclear@1
|
825 png_debug(1, "in png_read_rows\n");
|
nuclear@1
|
826 if (png_ptr == NULL) return;
|
nuclear@1
|
827 rp = row;
|
nuclear@1
|
828 dp = display_row;
|
nuclear@1
|
829 if (rp != NULL && dp != NULL)
|
nuclear@1
|
830 for (i = 0; i < num_rows; i++)
|
nuclear@1
|
831 {
|
nuclear@1
|
832 png_bytep rptr = *rp++;
|
nuclear@1
|
833 png_bytep dptr = *dp++;
|
nuclear@1
|
834
|
nuclear@1
|
835 png_read_row(png_ptr, rptr, dptr);
|
nuclear@1
|
836 }
|
nuclear@1
|
837 else if (rp != NULL)
|
nuclear@1
|
838 for (i = 0; i < num_rows; i++)
|
nuclear@1
|
839 {
|
nuclear@1
|
840 png_bytep rptr = *rp;
|
nuclear@1
|
841 png_read_row(png_ptr, rptr, png_bytep_NULL);
|
nuclear@1
|
842 rp++;
|
nuclear@1
|
843 }
|
nuclear@1
|
844 else if (dp != NULL)
|
nuclear@1
|
845 for (i = 0; i < num_rows; i++)
|
nuclear@1
|
846 {
|
nuclear@1
|
847 png_bytep dptr = *dp;
|
nuclear@1
|
848 png_read_row(png_ptr, png_bytep_NULL, dptr);
|
nuclear@1
|
849 dp++;
|
nuclear@1
|
850 }
|
nuclear@1
|
851 }
|
nuclear@1
|
852 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
853
|
nuclear@1
|
854 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
855 /* Read the entire image. If the image has an alpha channel or a tRNS
|
nuclear@1
|
856 * chunk, and you have called png_handle_alpha()[*], you will need to
|
nuclear@1
|
857 * initialize the image to the current image that PNG will be overlaying.
|
nuclear@1
|
858 * We set the num_rows again here, in case it was incorrectly set in
|
nuclear@1
|
859 * png_read_start_row() by a call to png_read_update_info() or
|
nuclear@1
|
860 * png_start_read_image() if png_set_interlace_handling() wasn't called
|
nuclear@1
|
861 * prior to either of these functions like it should have been. You can
|
nuclear@1
|
862 * only call this function once. If you desire to have an image for
|
nuclear@1
|
863 * each pass of a interlaced image, use png_read_rows() instead.
|
nuclear@1
|
864 *
|
nuclear@1
|
865 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
|
nuclear@1
|
866 */
|
nuclear@1
|
867 void PNGAPI
|
nuclear@1
|
868 png_read_image(png_structp png_ptr, png_bytepp image)
|
nuclear@1
|
869 {
|
nuclear@1
|
870 png_uint_32 i, image_height;
|
nuclear@1
|
871 int pass, j;
|
nuclear@1
|
872 png_bytepp rp;
|
nuclear@1
|
873
|
nuclear@1
|
874 png_debug(1, "in png_read_image\n");
|
nuclear@1
|
875 if (png_ptr == NULL) return;
|
nuclear@1
|
876
|
nuclear@1
|
877 #ifdef PNG_READ_INTERLACING_SUPPORTED
|
nuclear@1
|
878 pass = png_set_interlace_handling(png_ptr);
|
nuclear@1
|
879 #else
|
nuclear@1
|
880 if (png_ptr->interlaced)
|
nuclear@1
|
881 png_error(png_ptr,
|
nuclear@1
|
882 "Cannot read interlaced image -- interlace handler disabled.");
|
nuclear@1
|
883 pass = 1;
|
nuclear@1
|
884 #endif
|
nuclear@1
|
885
|
nuclear@1
|
886
|
nuclear@1
|
887 image_height=png_ptr->height;
|
nuclear@1
|
888 png_ptr->num_rows = image_height; /* Make sure this is set correctly */
|
nuclear@1
|
889
|
nuclear@1
|
890 for (j = 0; j < pass; j++)
|
nuclear@1
|
891 {
|
nuclear@1
|
892 rp = image;
|
nuclear@1
|
893 for (i = 0; i < image_height; i++)
|
nuclear@1
|
894 {
|
nuclear@1
|
895 png_read_row(png_ptr, *rp, png_bytep_NULL);
|
nuclear@1
|
896 rp++;
|
nuclear@1
|
897 }
|
nuclear@1
|
898 }
|
nuclear@1
|
899 }
|
nuclear@1
|
900 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
901
|
nuclear@1
|
902 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
903 /* Read the end of the PNG file. Will not read past the end of the
|
nuclear@1
|
904 * file, will verify the end is accurate, and will read any comments
|
nuclear@1
|
905 * or time information at the end of the file, if info is not NULL.
|
nuclear@1
|
906 */
|
nuclear@1
|
907 void PNGAPI
|
nuclear@1
|
908 png_read_end(png_structp png_ptr, png_infop info_ptr)
|
nuclear@1
|
909 {
|
nuclear@1
|
910 png_debug(1, "in png_read_end\n");
|
nuclear@1
|
911 if (png_ptr == NULL) return;
|
nuclear@1
|
912 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
|
nuclear@1
|
913
|
nuclear@1
|
914 do
|
nuclear@1
|
915 {
|
nuclear@1
|
916 #ifdef PNG_USE_LOCAL_ARRAYS
|
nuclear@1
|
917 PNG_CONST PNG_IHDR;
|
nuclear@1
|
918 PNG_CONST PNG_IDAT;
|
nuclear@1
|
919 PNG_CONST PNG_IEND;
|
nuclear@1
|
920 PNG_CONST PNG_PLTE;
|
nuclear@1
|
921 #if defined(PNG_READ_bKGD_SUPPORTED)
|
nuclear@1
|
922 PNG_CONST PNG_bKGD;
|
nuclear@1
|
923 #endif
|
nuclear@1
|
924 #if defined(PNG_READ_cHRM_SUPPORTED)
|
nuclear@1
|
925 PNG_CONST PNG_cHRM;
|
nuclear@1
|
926 #endif
|
nuclear@1
|
927 #if defined(PNG_READ_gAMA_SUPPORTED)
|
nuclear@1
|
928 PNG_CONST PNG_gAMA;
|
nuclear@1
|
929 #endif
|
nuclear@1
|
930 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@1
|
931 PNG_CONST PNG_hIST;
|
nuclear@1
|
932 #endif
|
nuclear@1
|
933 #if defined(PNG_READ_iCCP_SUPPORTED)
|
nuclear@1
|
934 PNG_CONST PNG_iCCP;
|
nuclear@1
|
935 #endif
|
nuclear@1
|
936 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@1
|
937 PNG_CONST PNG_iTXt;
|
nuclear@1
|
938 #endif
|
nuclear@1
|
939 #if defined(PNG_READ_oFFs_SUPPORTED)
|
nuclear@1
|
940 PNG_CONST PNG_oFFs;
|
nuclear@1
|
941 #endif
|
nuclear@1
|
942 #if defined(PNG_READ_pCAL_SUPPORTED)
|
nuclear@1
|
943 PNG_CONST PNG_pCAL;
|
nuclear@1
|
944 #endif
|
nuclear@1
|
945 #if defined(PNG_READ_pHYs_SUPPORTED)
|
nuclear@1
|
946 PNG_CONST PNG_pHYs;
|
nuclear@1
|
947 #endif
|
nuclear@1
|
948 #if defined(PNG_READ_sBIT_SUPPORTED)
|
nuclear@1
|
949 PNG_CONST PNG_sBIT;
|
nuclear@1
|
950 #endif
|
nuclear@1
|
951 #if defined(PNG_READ_sCAL_SUPPORTED)
|
nuclear@1
|
952 PNG_CONST PNG_sCAL;
|
nuclear@1
|
953 #endif
|
nuclear@1
|
954 #if defined(PNG_READ_sPLT_SUPPORTED)
|
nuclear@1
|
955 PNG_CONST PNG_sPLT;
|
nuclear@1
|
956 #endif
|
nuclear@1
|
957 #if defined(PNG_READ_sRGB_SUPPORTED)
|
nuclear@1
|
958 PNG_CONST PNG_sRGB;
|
nuclear@1
|
959 #endif
|
nuclear@1
|
960 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@1
|
961 PNG_CONST PNG_tEXt;
|
nuclear@1
|
962 #endif
|
nuclear@1
|
963 #if defined(PNG_READ_tIME_SUPPORTED)
|
nuclear@1
|
964 PNG_CONST PNG_tIME;
|
nuclear@1
|
965 #endif
|
nuclear@1
|
966 #if defined(PNG_READ_tRNS_SUPPORTED)
|
nuclear@1
|
967 PNG_CONST PNG_tRNS;
|
nuclear@1
|
968 #endif
|
nuclear@1
|
969 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@1
|
970 PNG_CONST PNG_zTXt;
|
nuclear@1
|
971 #endif
|
nuclear@1
|
972 #endif /* PNG_USE_LOCAL_ARRAYS */
|
nuclear@1
|
973 png_uint_32 length = png_read_chunk_header(png_ptr);
|
nuclear@1
|
974 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
|
nuclear@1
|
975
|
nuclear@1
|
976 if (!png_memcmp(chunk_name, png_IHDR, 4))
|
nuclear@1
|
977 png_handle_IHDR(png_ptr, info_ptr, length);
|
nuclear@1
|
978 else if (!png_memcmp(chunk_name, png_IEND, 4))
|
nuclear@1
|
979 png_handle_IEND(png_ptr, info_ptr, length);
|
nuclear@1
|
980 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
nuclear@1
|
981 else if (png_handle_as_unknown(png_ptr, chunk_name))
|
nuclear@1
|
982 {
|
nuclear@1
|
983 if (!png_memcmp(chunk_name, png_IDAT, 4))
|
nuclear@1
|
984 {
|
nuclear@1
|
985 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
|
nuclear@1
|
986 png_error(png_ptr, "Too many IDAT's found");
|
nuclear@1
|
987 }
|
nuclear@1
|
988 png_handle_unknown(png_ptr, info_ptr, length);
|
nuclear@1
|
989 if (!png_memcmp(chunk_name, png_PLTE, 4))
|
nuclear@1
|
990 png_ptr->mode |= PNG_HAVE_PLTE;
|
nuclear@1
|
991 }
|
nuclear@1
|
992 #endif
|
nuclear@1
|
993 else if (!png_memcmp(chunk_name, png_IDAT, 4))
|
nuclear@1
|
994 {
|
nuclear@1
|
995 /* Zero length IDATs are legal after the last IDAT has been
|
nuclear@1
|
996 * read, but not after other chunks have been read.
|
nuclear@1
|
997 */
|
nuclear@1
|
998 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
|
nuclear@1
|
999 png_error(png_ptr, "Too many IDAT's found");
|
nuclear@1
|
1000 png_crc_finish(png_ptr, length);
|
nuclear@1
|
1001 }
|
nuclear@1
|
1002 else if (!png_memcmp(chunk_name, png_PLTE, 4))
|
nuclear@1
|
1003 png_handle_PLTE(png_ptr, info_ptr, length);
|
nuclear@1
|
1004 #if defined(PNG_READ_bKGD_SUPPORTED)
|
nuclear@1
|
1005 else if (!png_memcmp(chunk_name, png_bKGD, 4))
|
nuclear@1
|
1006 png_handle_bKGD(png_ptr, info_ptr, length);
|
nuclear@1
|
1007 #endif
|
nuclear@1
|
1008 #if defined(PNG_READ_cHRM_SUPPORTED)
|
nuclear@1
|
1009 else if (!png_memcmp(chunk_name, png_cHRM, 4))
|
nuclear@1
|
1010 png_handle_cHRM(png_ptr, info_ptr, length);
|
nuclear@1
|
1011 #endif
|
nuclear@1
|
1012 #if defined(PNG_READ_gAMA_SUPPORTED)
|
nuclear@1
|
1013 else if (!png_memcmp(chunk_name, png_gAMA, 4))
|
nuclear@1
|
1014 png_handle_gAMA(png_ptr, info_ptr, length);
|
nuclear@1
|
1015 #endif
|
nuclear@1
|
1016 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@1
|
1017 else if (!png_memcmp(chunk_name, png_hIST, 4))
|
nuclear@1
|
1018 png_handle_hIST(png_ptr, info_ptr, length);
|
nuclear@1
|
1019 #endif
|
nuclear@1
|
1020 #if defined(PNG_READ_oFFs_SUPPORTED)
|
nuclear@1
|
1021 else if (!png_memcmp(chunk_name, png_oFFs, 4))
|
nuclear@1
|
1022 png_handle_oFFs(png_ptr, info_ptr, length);
|
nuclear@1
|
1023 #endif
|
nuclear@1
|
1024 #if defined(PNG_READ_pCAL_SUPPORTED)
|
nuclear@1
|
1025 else if (!png_memcmp(chunk_name, png_pCAL, 4))
|
nuclear@1
|
1026 png_handle_pCAL(png_ptr, info_ptr, length);
|
nuclear@1
|
1027 #endif
|
nuclear@1
|
1028 #if defined(PNG_READ_sCAL_SUPPORTED)
|
nuclear@1
|
1029 else if (!png_memcmp(chunk_name, png_sCAL, 4))
|
nuclear@1
|
1030 png_handle_sCAL(png_ptr, info_ptr, length);
|
nuclear@1
|
1031 #endif
|
nuclear@1
|
1032 #if defined(PNG_READ_pHYs_SUPPORTED)
|
nuclear@1
|
1033 else if (!png_memcmp(chunk_name, png_pHYs, 4))
|
nuclear@1
|
1034 png_handle_pHYs(png_ptr, info_ptr, length);
|
nuclear@1
|
1035 #endif
|
nuclear@1
|
1036 #if defined(PNG_READ_sBIT_SUPPORTED)
|
nuclear@1
|
1037 else if (!png_memcmp(chunk_name, png_sBIT, 4))
|
nuclear@1
|
1038 png_handle_sBIT(png_ptr, info_ptr, length);
|
nuclear@1
|
1039 #endif
|
nuclear@1
|
1040 #if defined(PNG_READ_sRGB_SUPPORTED)
|
nuclear@1
|
1041 else if (!png_memcmp(chunk_name, png_sRGB, 4))
|
nuclear@1
|
1042 png_handle_sRGB(png_ptr, info_ptr, length);
|
nuclear@1
|
1043 #endif
|
nuclear@1
|
1044 #if defined(PNG_READ_iCCP_SUPPORTED)
|
nuclear@1
|
1045 else if (!png_memcmp(chunk_name, png_iCCP, 4))
|
nuclear@1
|
1046 png_handle_iCCP(png_ptr, info_ptr, length);
|
nuclear@1
|
1047 #endif
|
nuclear@1
|
1048 #if defined(PNG_READ_sPLT_SUPPORTED)
|
nuclear@1
|
1049 else if (!png_memcmp(chunk_name, png_sPLT, 4))
|
nuclear@1
|
1050 png_handle_sPLT(png_ptr, info_ptr, length);
|
nuclear@1
|
1051 #endif
|
nuclear@1
|
1052 #if defined(PNG_READ_tEXt_SUPPORTED)
|
nuclear@1
|
1053 else if (!png_memcmp(chunk_name, png_tEXt, 4))
|
nuclear@1
|
1054 png_handle_tEXt(png_ptr, info_ptr, length);
|
nuclear@1
|
1055 #endif
|
nuclear@1
|
1056 #if defined(PNG_READ_tIME_SUPPORTED)
|
nuclear@1
|
1057 else if (!png_memcmp(chunk_name, png_tIME, 4))
|
nuclear@1
|
1058 png_handle_tIME(png_ptr, info_ptr, length);
|
nuclear@1
|
1059 #endif
|
nuclear@1
|
1060 #if defined(PNG_READ_tRNS_SUPPORTED)
|
nuclear@1
|
1061 else if (!png_memcmp(chunk_name, png_tRNS, 4))
|
nuclear@1
|
1062 png_handle_tRNS(png_ptr, info_ptr, length);
|
nuclear@1
|
1063 #endif
|
nuclear@1
|
1064 #if defined(PNG_READ_zTXt_SUPPORTED)
|
nuclear@1
|
1065 else if (!png_memcmp(chunk_name, png_zTXt, 4))
|
nuclear@1
|
1066 png_handle_zTXt(png_ptr, info_ptr, length);
|
nuclear@1
|
1067 #endif
|
nuclear@1
|
1068 #if defined(PNG_READ_iTXt_SUPPORTED)
|
nuclear@1
|
1069 else if (!png_memcmp(chunk_name, png_iTXt, 4))
|
nuclear@1
|
1070 png_handle_iTXt(png_ptr, info_ptr, length);
|
nuclear@1
|
1071 #endif
|
nuclear@1
|
1072 else
|
nuclear@1
|
1073 png_handle_unknown(png_ptr, info_ptr, length);
|
nuclear@1
|
1074 } while (!(png_ptr->mode & PNG_HAVE_IEND));
|
nuclear@1
|
1075 }
|
nuclear@1
|
1076 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
1077
|
nuclear@1
|
1078 /* free all memory used by the read */
|
nuclear@1
|
1079 void PNGAPI
|
nuclear@1
|
1080 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
nuclear@1
|
1081 png_infopp end_info_ptr_ptr)
|
nuclear@1
|
1082 {
|
nuclear@1
|
1083 png_structp png_ptr = NULL;
|
nuclear@1
|
1084 png_infop info_ptr = NULL, end_info_ptr = NULL;
|
nuclear@1
|
1085 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1086 png_free_ptr free_fn = NULL;
|
nuclear@1
|
1087 png_voidp mem_ptr = NULL;
|
nuclear@1
|
1088 #endif
|
nuclear@1
|
1089
|
nuclear@1
|
1090 png_debug(1, "in png_destroy_read_struct\n");
|
nuclear@1
|
1091 if (png_ptr_ptr != NULL)
|
nuclear@1
|
1092 png_ptr = *png_ptr_ptr;
|
nuclear@1
|
1093 if (png_ptr == NULL)
|
nuclear@1
|
1094 return;
|
nuclear@1
|
1095
|
nuclear@1
|
1096 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1097 free_fn = png_ptr->free_fn;
|
nuclear@1
|
1098 mem_ptr = png_ptr->mem_ptr;
|
nuclear@1
|
1099 #endif
|
nuclear@1
|
1100
|
nuclear@1
|
1101 if (info_ptr_ptr != NULL)
|
nuclear@1
|
1102 info_ptr = *info_ptr_ptr;
|
nuclear@1
|
1103
|
nuclear@1
|
1104 if (end_info_ptr_ptr != NULL)
|
nuclear@1
|
1105 end_info_ptr = *end_info_ptr_ptr;
|
nuclear@1
|
1106
|
nuclear@1
|
1107 png_read_destroy(png_ptr, info_ptr, end_info_ptr);
|
nuclear@1
|
1108
|
nuclear@1
|
1109 if (info_ptr != NULL)
|
nuclear@1
|
1110 {
|
nuclear@1
|
1111 #if defined(PNG_TEXT_SUPPORTED)
|
nuclear@1
|
1112 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
|
nuclear@1
|
1113 #endif
|
nuclear@1
|
1114
|
nuclear@1
|
1115 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1116 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
|
nuclear@1
|
1117 (png_voidp)mem_ptr);
|
nuclear@1
|
1118 #else
|
nuclear@1
|
1119 png_destroy_struct((png_voidp)info_ptr);
|
nuclear@1
|
1120 #endif
|
nuclear@1
|
1121 *info_ptr_ptr = NULL;
|
nuclear@1
|
1122 }
|
nuclear@1
|
1123
|
nuclear@1
|
1124 if (end_info_ptr != NULL)
|
nuclear@1
|
1125 {
|
nuclear@1
|
1126 #if defined(PNG_READ_TEXT_SUPPORTED)
|
nuclear@1
|
1127 png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
|
nuclear@1
|
1128 #endif
|
nuclear@1
|
1129 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1130 png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
|
nuclear@1
|
1131 (png_voidp)mem_ptr);
|
nuclear@1
|
1132 #else
|
nuclear@1
|
1133 png_destroy_struct((png_voidp)end_info_ptr);
|
nuclear@1
|
1134 #endif
|
nuclear@1
|
1135 *end_info_ptr_ptr = NULL;
|
nuclear@1
|
1136 }
|
nuclear@1
|
1137
|
nuclear@1
|
1138 if (png_ptr != NULL)
|
nuclear@1
|
1139 {
|
nuclear@1
|
1140 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1141 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
|
nuclear@1
|
1142 (png_voidp)mem_ptr);
|
nuclear@1
|
1143 #else
|
nuclear@1
|
1144 png_destroy_struct((png_voidp)png_ptr);
|
nuclear@1
|
1145 #endif
|
nuclear@1
|
1146 *png_ptr_ptr = NULL;
|
nuclear@1
|
1147 }
|
nuclear@1
|
1148 }
|
nuclear@1
|
1149
|
nuclear@1
|
1150 /* free all memory used by the read (old method) */
|
nuclear@1
|
1151 void /* PRIVATE */
|
nuclear@1
|
1152 png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
|
nuclear@1
|
1153 {
|
nuclear@1
|
1154 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
1155 jmp_buf tmp_jmp;
|
nuclear@1
|
1156 #endif
|
nuclear@1
|
1157 png_error_ptr error_fn;
|
nuclear@1
|
1158 png_error_ptr warning_fn;
|
nuclear@1
|
1159 png_voidp error_ptr;
|
nuclear@1
|
1160 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1161 png_free_ptr free_fn;
|
nuclear@1
|
1162 #endif
|
nuclear@1
|
1163
|
nuclear@1
|
1164 png_debug(1, "in png_read_destroy\n");
|
nuclear@1
|
1165 if (info_ptr != NULL)
|
nuclear@1
|
1166 png_info_destroy(png_ptr, info_ptr);
|
nuclear@1
|
1167
|
nuclear@1
|
1168 if (end_info_ptr != NULL)
|
nuclear@1
|
1169 png_info_destroy(png_ptr, end_info_ptr);
|
nuclear@1
|
1170
|
nuclear@1
|
1171 png_free(png_ptr, png_ptr->zbuf);
|
nuclear@1
|
1172 png_free(png_ptr, png_ptr->big_row_buf);
|
nuclear@1
|
1173 png_free(png_ptr, png_ptr->prev_row);
|
nuclear@1
|
1174 png_free(png_ptr, png_ptr->chunkdata);
|
nuclear@1
|
1175 #if defined(PNG_READ_DITHER_SUPPORTED)
|
nuclear@1
|
1176 png_free(png_ptr, png_ptr->palette_lookup);
|
nuclear@1
|
1177 png_free(png_ptr, png_ptr->dither_index);
|
nuclear@1
|
1178 #endif
|
nuclear@1
|
1179 #if defined(PNG_READ_GAMMA_SUPPORTED)
|
nuclear@1
|
1180 png_free(png_ptr, png_ptr->gamma_table);
|
nuclear@1
|
1181 #endif
|
nuclear@1
|
1182 #if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
nuclear@1
|
1183 png_free(png_ptr, png_ptr->gamma_from_1);
|
nuclear@1
|
1184 png_free(png_ptr, png_ptr->gamma_to_1);
|
nuclear@1
|
1185 #endif
|
nuclear@1
|
1186 #ifdef PNG_FREE_ME_SUPPORTED
|
nuclear@1
|
1187 if (png_ptr->free_me & PNG_FREE_PLTE)
|
nuclear@1
|
1188 png_zfree(png_ptr, png_ptr->palette);
|
nuclear@1
|
1189 png_ptr->free_me &= ~PNG_FREE_PLTE;
|
nuclear@1
|
1190 #else
|
nuclear@1
|
1191 if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
|
nuclear@1
|
1192 png_zfree(png_ptr, png_ptr->palette);
|
nuclear@1
|
1193 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
|
nuclear@1
|
1194 #endif
|
nuclear@1
|
1195 #if defined(PNG_tRNS_SUPPORTED) || \
|
nuclear@1
|
1196 defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
nuclear@1
|
1197 #ifdef PNG_FREE_ME_SUPPORTED
|
nuclear@1
|
1198 if (png_ptr->free_me & PNG_FREE_TRNS)
|
nuclear@1
|
1199 png_free(png_ptr, png_ptr->trans);
|
nuclear@1
|
1200 png_ptr->free_me &= ~PNG_FREE_TRNS;
|
nuclear@1
|
1201 #else
|
nuclear@1
|
1202 if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
|
nuclear@1
|
1203 png_free(png_ptr, png_ptr->trans);
|
nuclear@1
|
1204 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
|
nuclear@1
|
1205 #endif
|
nuclear@1
|
1206 #endif
|
nuclear@1
|
1207 #if defined(PNG_READ_hIST_SUPPORTED)
|
nuclear@1
|
1208 #ifdef PNG_FREE_ME_SUPPORTED
|
nuclear@1
|
1209 if (png_ptr->free_me & PNG_FREE_HIST)
|
nuclear@1
|
1210 png_free(png_ptr, png_ptr->hist);
|
nuclear@1
|
1211 png_ptr->free_me &= ~PNG_FREE_HIST;
|
nuclear@1
|
1212 #else
|
nuclear@1
|
1213 if (png_ptr->flags & PNG_FLAG_FREE_HIST)
|
nuclear@1
|
1214 png_free(png_ptr, png_ptr->hist);
|
nuclear@1
|
1215 png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
|
nuclear@1
|
1216 #endif
|
nuclear@1
|
1217 #endif
|
nuclear@1
|
1218 #if defined(PNG_READ_GAMMA_SUPPORTED)
|
nuclear@1
|
1219 if (png_ptr->gamma_16_table != NULL)
|
nuclear@1
|
1220 {
|
nuclear@1
|
1221 int i;
|
nuclear@1
|
1222 int istop = (1 << (8 - png_ptr->gamma_shift));
|
nuclear@1
|
1223 for (i = 0; i < istop; i++)
|
nuclear@1
|
1224 {
|
nuclear@1
|
1225 png_free(png_ptr, png_ptr->gamma_16_table[i]);
|
nuclear@1
|
1226 }
|
nuclear@1
|
1227 png_free(png_ptr, png_ptr->gamma_16_table);
|
nuclear@1
|
1228 }
|
nuclear@1
|
1229 #if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
nuclear@1
|
1230 if (png_ptr->gamma_16_from_1 != NULL)
|
nuclear@1
|
1231 {
|
nuclear@1
|
1232 int i;
|
nuclear@1
|
1233 int istop = (1 << (8 - png_ptr->gamma_shift));
|
nuclear@1
|
1234 for (i = 0; i < istop; i++)
|
nuclear@1
|
1235 {
|
nuclear@1
|
1236 png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
|
nuclear@1
|
1237 }
|
nuclear@1
|
1238 png_free(png_ptr, png_ptr->gamma_16_from_1);
|
nuclear@1
|
1239 }
|
nuclear@1
|
1240 if (png_ptr->gamma_16_to_1 != NULL)
|
nuclear@1
|
1241 {
|
nuclear@1
|
1242 int i;
|
nuclear@1
|
1243 int istop = (1 << (8 - png_ptr->gamma_shift));
|
nuclear@1
|
1244 for (i = 0; i < istop; i++)
|
nuclear@1
|
1245 {
|
nuclear@1
|
1246 png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
|
nuclear@1
|
1247 }
|
nuclear@1
|
1248 png_free(png_ptr, png_ptr->gamma_16_to_1);
|
nuclear@1
|
1249 }
|
nuclear@1
|
1250 #endif
|
nuclear@1
|
1251 #endif
|
nuclear@1
|
1252 #if defined(PNG_TIME_RFC1123_SUPPORTED)
|
nuclear@1
|
1253 png_free(png_ptr, png_ptr->time_buffer);
|
nuclear@1
|
1254 #endif
|
nuclear@1
|
1255
|
nuclear@1
|
1256 inflateEnd(&png_ptr->zstream);
|
nuclear@1
|
1257 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
nuclear@1
|
1258 png_free(png_ptr, png_ptr->save_buffer);
|
nuclear@1
|
1259 #endif
|
nuclear@1
|
1260
|
nuclear@1
|
1261 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
nuclear@1
|
1262 #ifdef PNG_TEXT_SUPPORTED
|
nuclear@1
|
1263 png_free(png_ptr, png_ptr->current_text);
|
nuclear@1
|
1264 #endif /* PNG_TEXT_SUPPORTED */
|
nuclear@1
|
1265 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
nuclear@1
|
1266
|
nuclear@1
|
1267 /* Save the important info out of the png_struct, in case it is
|
nuclear@1
|
1268 * being used again.
|
nuclear@1
|
1269 */
|
nuclear@1
|
1270 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
1271 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
|
nuclear@1
|
1272 #endif
|
nuclear@1
|
1273
|
nuclear@1
|
1274 error_fn = png_ptr->error_fn;
|
nuclear@1
|
1275 warning_fn = png_ptr->warning_fn;
|
nuclear@1
|
1276 error_ptr = png_ptr->error_ptr;
|
nuclear@1
|
1277 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1278 free_fn = png_ptr->free_fn;
|
nuclear@1
|
1279 #endif
|
nuclear@1
|
1280
|
nuclear@1
|
1281 png_memset(png_ptr, 0, png_sizeof(png_struct));
|
nuclear@1
|
1282
|
nuclear@1
|
1283 png_ptr->error_fn = error_fn;
|
nuclear@1
|
1284 png_ptr->warning_fn = warning_fn;
|
nuclear@1
|
1285 png_ptr->error_ptr = error_ptr;
|
nuclear@1
|
1286 #ifdef PNG_USER_MEM_SUPPORTED
|
nuclear@1
|
1287 png_ptr->free_fn = free_fn;
|
nuclear@1
|
1288 #endif
|
nuclear@1
|
1289
|
nuclear@1
|
1290 #ifdef PNG_SETJMP_SUPPORTED
|
nuclear@1
|
1291 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
|
nuclear@1
|
1292 #endif
|
nuclear@1
|
1293
|
nuclear@1
|
1294 }
|
nuclear@1
|
1295
|
nuclear@1
|
1296 void PNGAPI
|
nuclear@1
|
1297 png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
|
nuclear@1
|
1298 {
|
nuclear@1
|
1299 if (png_ptr == NULL) return;
|
nuclear@1
|
1300 png_ptr->read_row_fn = read_row_fn;
|
nuclear@1
|
1301 }
|
nuclear@1
|
1302
|
nuclear@1
|
1303
|
nuclear@1
|
1304 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
nuclear@1
|
1305 #if defined(PNG_INFO_IMAGE_SUPPORTED)
|
nuclear@1
|
1306 void PNGAPI
|
nuclear@1
|
1307 png_read_png(png_structp png_ptr, png_infop info_ptr,
|
nuclear@1
|
1308 int transforms,
|
nuclear@1
|
1309 voidp params)
|
nuclear@1
|
1310 {
|
nuclear@1
|
1311 int row;
|
nuclear@1
|
1312
|
nuclear@1
|
1313 if (png_ptr == NULL) return;
|
nuclear@1
|
1314 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
nuclear@1
|
1315 /* invert the alpha channel from opacity to transparency
|
nuclear@1
|
1316 */
|
nuclear@1
|
1317 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
nuclear@1
|
1318 png_set_invert_alpha(png_ptr);
|
nuclear@1
|
1319 #endif
|
nuclear@1
|
1320
|
nuclear@1
|
1321 /* png_read_info() gives us all of the information from the
|
nuclear@1
|
1322 * PNG file before the first IDAT (image data chunk).
|
nuclear@1
|
1323 */
|
nuclear@1
|
1324 png_read_info(png_ptr, info_ptr);
|
nuclear@1
|
1325 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
|
nuclear@1
|
1326 png_error(png_ptr, "Image is too high to process with png_read_png()");
|
nuclear@1
|
1327
|
nuclear@1
|
1328 /* -------------- image transformations start here ------------------- */
|
nuclear@1
|
1329
|
nuclear@1
|
1330 #if defined(PNG_READ_16_TO_8_SUPPORTED)
|
nuclear@1
|
1331 /* tell libpng to strip 16 bit/color files down to 8 bits per color
|
nuclear@1
|
1332 */
|
nuclear@1
|
1333 if (transforms & PNG_TRANSFORM_STRIP_16)
|
nuclear@1
|
1334 png_set_strip_16(png_ptr);
|
nuclear@1
|
1335 #endif
|
nuclear@1
|
1336
|
nuclear@1
|
1337 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
nuclear@1
|
1338 /* Strip alpha bytes from the input data without combining with
|
nuclear@1
|
1339 * the background (not recommended).
|
nuclear@1
|
1340 */
|
nuclear@1
|
1341 if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
|
nuclear@1
|
1342 png_set_strip_alpha(png_ptr);
|
nuclear@1
|
1343 #endif
|
nuclear@1
|
1344
|
nuclear@1
|
1345 #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
|
nuclear@1
|
1346 /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
|
nuclear@1
|
1347 * byte into separate bytes (useful for paletted and grayscale images).
|
nuclear@1
|
1348 */
|
nuclear@1
|
1349 if (transforms & PNG_TRANSFORM_PACKING)
|
nuclear@1
|
1350 png_set_packing(png_ptr);
|
nuclear@1
|
1351 #endif
|
nuclear@1
|
1352
|
nuclear@1
|
1353 #if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
nuclear@1
|
1354 /* Change the order of packed pixels to least significant bit first
|
nuclear@1
|
1355 * (not useful if you are using png_set_packing).
|
nuclear@1
|
1356 */
|
nuclear@1
|
1357 if (transforms & PNG_TRANSFORM_PACKSWAP)
|
nuclear@1
|
1358 png_set_packswap(png_ptr);
|
nuclear@1
|
1359 #endif
|
nuclear@1
|
1360
|
nuclear@1
|
1361 #if defined(PNG_READ_EXPAND_SUPPORTED)
|
nuclear@1
|
1362 /* Expand paletted colors into true RGB triplets
|
nuclear@1
|
1363 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
|
nuclear@1
|
1364 * Expand paletted or RGB images with transparency to full alpha
|
nuclear@1
|
1365 * channels so the data will be available as RGBA quartets.
|
nuclear@1
|
1366 */
|
nuclear@1
|
1367 if (transforms & PNG_TRANSFORM_EXPAND)
|
nuclear@1
|
1368 if ((png_ptr->bit_depth < 8) ||
|
nuclear@1
|
1369 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
|
nuclear@1
|
1370 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
|
nuclear@1
|
1371 png_set_expand(png_ptr);
|
nuclear@1
|
1372 #endif
|
nuclear@1
|
1373
|
nuclear@1
|
1374 /* We don't handle background color or gamma transformation or dithering.
|
nuclear@1
|
1375 */
|
nuclear@1
|
1376
|
nuclear@1
|
1377 #if defined(PNG_READ_INVERT_SUPPORTED)
|
nuclear@1
|
1378 /* invert monochrome files to have 0 as white and 1 as black
|
nuclear@1
|
1379 */
|
nuclear@1
|
1380 if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
nuclear@1
|
1381 png_set_invert_mono(png_ptr);
|
nuclear@1
|
1382 #endif
|
nuclear@1
|
1383
|
nuclear@1
|
1384 #if defined(PNG_READ_SHIFT_SUPPORTED)
|
nuclear@1
|
1385 /* If you want to shift the pixel values from the range [0,255] or
|
nuclear@1
|
1386 * [0,65535] to the original [0,7] or [0,31], or whatever range the
|
nuclear@1
|
1387 * colors were originally in:
|
nuclear@1
|
1388 */
|
nuclear@1
|
1389 if ((transforms & PNG_TRANSFORM_SHIFT)
|
nuclear@1
|
1390 && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
nuclear@1
|
1391 {
|
nuclear@1
|
1392 png_color_8p sig_bit;
|
nuclear@1
|
1393
|
nuclear@1
|
1394 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
nuclear@1
|
1395 png_set_shift(png_ptr, sig_bit);
|
nuclear@1
|
1396 }
|
nuclear@1
|
1397 #endif
|
nuclear@1
|
1398
|
nuclear@1
|
1399 #if defined(PNG_READ_BGR_SUPPORTED)
|
nuclear@1
|
1400 /* flip the RGB pixels to BGR (or RGBA to BGRA)
|
nuclear@1
|
1401 */
|
nuclear@1
|
1402 if (transforms & PNG_TRANSFORM_BGR)
|
nuclear@1
|
1403 png_set_bgr(png_ptr);
|
nuclear@1
|
1404 #endif
|
nuclear@1
|
1405
|
nuclear@1
|
1406 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
|
nuclear@1
|
1407 /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
|
nuclear@1
|
1408 */
|
nuclear@1
|
1409 if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
nuclear@1
|
1410 png_set_swap_alpha(png_ptr);
|
nuclear@1
|
1411 #endif
|
nuclear@1
|
1412
|
nuclear@1
|
1413 #if defined(PNG_READ_SWAP_SUPPORTED)
|
nuclear@1
|
1414 /* swap bytes of 16 bit files to least significant byte first
|
nuclear@1
|
1415 */
|
nuclear@1
|
1416 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
nuclear@1
|
1417 png_set_swap(png_ptr);
|
nuclear@1
|
1418 #endif
|
nuclear@1
|
1419
|
nuclear@1
|
1420 /* We don't handle adding filler bytes */
|
nuclear@1
|
1421
|
nuclear@1
|
1422 /* Optional call to gamma correct and add the background to the palette
|
nuclear@1
|
1423 * and update info structure. REQUIRED if you are expecting libpng to
|
nuclear@1
|
1424 * update the palette for you (i.e., you selected such a transform above).
|
nuclear@1
|
1425 */
|
nuclear@1
|
1426 png_read_update_info(png_ptr, info_ptr);
|
nuclear@1
|
1427
|
nuclear@1
|
1428 /* -------------- image transformations end here ------------------- */
|
nuclear@1
|
1429
|
nuclear@1
|
1430 #ifdef PNG_FREE_ME_SUPPORTED
|
nuclear@1
|
1431 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
|
nuclear@1
|
1432 #endif
|
nuclear@1
|
1433 if (info_ptr->row_pointers == NULL)
|
nuclear@1
|
1434 {
|
nuclear@1
|
1435 info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
|
nuclear@1
|
1436 info_ptr->height * png_sizeof(png_bytep));
|
nuclear@1
|
1437 #ifdef PNG_FREE_ME_SUPPORTED
|
nuclear@1
|
1438 info_ptr->free_me |= PNG_FREE_ROWS;
|
nuclear@1
|
1439 #endif
|
nuclear@1
|
1440 for (row = 0; row < (int)info_ptr->height; row++)
|
nuclear@1
|
1441 {
|
nuclear@1
|
1442 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
|
nuclear@1
|
1443 png_get_rowbytes(png_ptr, info_ptr));
|
nuclear@1
|
1444 }
|
nuclear@1
|
1445 }
|
nuclear@1
|
1446
|
nuclear@1
|
1447 png_read_image(png_ptr, info_ptr->row_pointers);
|
nuclear@1
|
1448 info_ptr->valid |= PNG_INFO_IDAT;
|
nuclear@1
|
1449
|
nuclear@1
|
1450 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
nuclear@1
|
1451 png_read_end(png_ptr, info_ptr);
|
nuclear@1
|
1452
|
nuclear@1
|
1453 transforms = transforms; /* quiet compiler warnings */
|
nuclear@1
|
1454 params = params;
|
nuclear@1
|
1455
|
nuclear@1
|
1456 }
|
nuclear@1
|
1457 #endif /* PNG_INFO_IMAGE_SUPPORTED */
|
nuclear@1
|
1458 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
|
nuclear@1
|
1459 #endif /* PNG_READ_SUPPORTED */
|