Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: third_party/libpng/pngread.c

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

Powered by Google App Engine
This is Rietveld 408576698