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