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