blob: 87c2b47d0bdb792530199e04fd0c95fc82c1083b [file] [log] [blame]
Guy Schalnat0d580581995-07-20 02:43:20 -05001
Andreas Dilger47a0c421997-05-16 02:46:07 -05002/* pngread.c - read a PNG file
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05004 * Last changed in libpng 1.4.0 [July 10, 2008]
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05006 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05007 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 *
10 * This file contains routines that an application calls directly to
11 * read a PNG file or stream.
12 */
Guy Schalnat0d580581995-07-20 02:43:20 -050013
Guy Schalnat0d580581995-07-20 02:43:20 -050014#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060015#if defined(PNG_READ_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050016#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060017
Andreas Dilger47a0c421997-05-16 02:46:07 -050018/* Create a PNG structure for reading, and allocate any memory needed. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050019png_structp PNGAPI
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -050020png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060021 png_error_ptr error_fn, png_error_ptr warn_fn)
Guy Schalnat0d580581995-07-20 02:43:20 -050022{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050023
24#ifdef PNG_USER_MEM_SUPPORTED
25 return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050026 warn_fn, NULL, NULL, NULL));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050027}
28
29/* Alternate create PNG structure for reading, and allocate any memory needed. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050030png_structp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050031png_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,
33 png_malloc_ptr malloc_fn, png_free_ptr free_fn)
34{
35#endif /* PNG_USER_MEM_SUPPORTED */
36
Guy Schalnate5a37791996-06-05 15:50:50 -050037 png_structp png_ptr;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060038
39#ifdef PNG_SETJMP_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060040#ifdef USE_FAR_KEYWORD
41 jmp_buf jmpbuf;
42#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060043#endif
44
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050045 int i;
46
Andreas Dilger47a0c421997-05-16 02:46:07 -050047 png_debug(1, "in png_create_read_struct\n");
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050048#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060049 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050050 malloc_fn, mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050051#else
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060052 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050053#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060054 if (png_ptr == NULL)
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050055 return (NULL);
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050056
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -050057 /* added at libpng-1.2.6 */
58#ifdef PNG_SET_USER_LIMITS_SUPPORTED
59 png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
60 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
61#endif
62
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060063#ifdef PNG_SETJMP_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060064#ifdef USE_FAR_KEYWORD
65 if (setjmp(jmpbuf))
66#else
Guy Schalnate5a37791996-06-05 15:50:50 -050067 if (setjmp(png_ptr->jmpbuf))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060068#endif
Guy Schalnate5a37791996-06-05 15:50:50 -050069 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060070 png_free(png_ptr, png_ptr->zbuf);
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -050071 png_ptr->zbuf=NULL;
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -060072#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060073 png_destroy_struct_2((png_voidp)png_ptr,
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -050074 (png_free_ptr)free_fn, (png_voidp)mem_ptr);
Glenn Randers-Pehrson25228ab2002-03-31 07:33:55 -060075#else
76 png_destroy_struct((png_voidp)png_ptr);
77#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050078 return (NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -050079 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060080#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050081 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060082#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060083#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050084
85#ifdef PNG_USER_MEM_SUPPORTED
86 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060087#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050088
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060089 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
Guy Schalnat6d764711995-12-19 03:22:19 -060090
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050091 if (user_png_ver)
Guy Schalnate5a37791996-06-05 15:50:50 -050092 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050093 i=0;
94 do
95 {
96 if (user_png_ver[i] != png_libpng_ver[i])
97 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
98 } while (png_libpng_ver[i++]);
99 }
100 else
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500101 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500102
Guy Schalnate5a37791996-06-05 15:50:50 -0500103
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500104 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500105 {
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500106 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
107 * we must recompile any applications that use any older library version.
108 * For versions after libpng 1.0, we will be compatible, so we need
109 * only check the first digit.
110 */
111 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500112 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500113 (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
114 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500115#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -0500116 char msg[80];
117 if (user_png_ver)
118 {
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500119 png_snprintf(msg, 80,
120 "Application was compiled with png.h from libpng-%.20s",
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -0500121 user_png_ver);
122 png_warning(png_ptr, msg);
123 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500124 png_snprintf(msg, 80,
125 "Application is running with png.c from libpng-%.20s",
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -0500126 png_libpng_ver);
127 png_warning(png_ptr, msg);
128#endif
129#ifdef PNG_ERROR_NUMBERS_SUPPORTED
130 png_ptr->flags=0;
131#endif
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500132 png_error(png_ptr,
133 "Incompatible libpng version in application and library");
134 }
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500135 }
136
Guy Schalnate5a37791996-06-05 15:50:50 -0500137 /* initialize zbuf - compression buffer */
Guy Schalnat0d580581995-07-20 02:43:20 -0500138 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500139 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
140 png_ptr->zbuf_size);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600141 png_ptr->zstream.zalloc = png_zalloc;
142 png_ptr->zstream.zfree = png_zfree;
143 png_ptr->zstream.opaque = (voidpf)png_ptr;
Guy Schalnate5a37791996-06-05 15:50:50 -0500144
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600145 switch (inflateInit(&png_ptr->zstream))
Guy Schalnate5a37791996-06-05 15:50:50 -0500146 {
147 case Z_OK: /* Do nothing */ break;
148 case Z_MEM_ERROR:
149 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
150 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
151 default: png_error(png_ptr, "Unknown zlib error");
152 }
153
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600154 png_ptr->zstream.next_out = png_ptr->zbuf;
155 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
Guy Schalnate5a37791996-06-05 15:50:50 -0500156
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500157 png_set_read_fn(png_ptr, NULL, NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500158
Glenn Randers-Pehrson03008a02002-04-27 10:11:25 -0500159#ifdef PNG_SETJMP_SUPPORTED
160/* Applications that neglect to set up their own setjmp() and then encounter
161 a png_error() will longjmp here. Since the jmpbuf is then meaningless we
162 abort instead of returning. */
163#ifdef USE_FAR_KEYWORD
164 if (setjmp(jmpbuf))
165 PNG_ABORT();
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500166 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
Glenn Randers-Pehrson03008a02002-04-27 10:11:25 -0500167#else
168 if (setjmp(png_ptr->jmpbuf))
169 PNG_ABORT();
170#endif
171#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500172 return (png_ptr);
173}
174
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500175
176void PNGAPI
177png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
178 png_size_t png_struct_size)
179{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600180#ifdef PNG_SETJMP_SUPPORTED
Guy Schalnate5a37791996-06-05 15:50:50 -0500181 jmp_buf tmp_jmp; /* to save current jump buffer */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600182#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500183
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500184 int i=0;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500185
186 png_structp png_ptr=*ptr_ptr;
187
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500188 if (png_ptr == NULL) return;
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600189
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500190 do
191 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500192 if (user_png_ver[i] != png_libpng_ver[i])
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500193 {
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500194#ifdef PNG_LEGACY_SUPPORTED
195 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
196#else
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500197 png_ptr->warning_fn=NULL;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500198 png_warning(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500199 "Application uses deprecated png_read_init() and should be recompiled");
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500200 break;
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500201#endif
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500202 }
203 } while (png_libpng_ver[i++]);
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500204
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500205 png_debug(1, "in png_read_init_3\n");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600206
207#ifdef PNG_SETJMP_SUPPORTED
Guy Schalnate5a37791996-06-05 15:50:50 -0500208 /* save jump buffer and error functions */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500209 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600210#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500211
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500212 if (png_sizeof(png_struct) > png_struct_size)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500213 {
214 png_destroy_struct(png_ptr);
215 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
216 png_ptr = *ptr_ptr;
217 }
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500218
Guy Schalnate5a37791996-06-05 15:50:50 -0500219 /* reset all variables to 0 */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500220 png_memset(png_ptr, 0, png_sizeof(png_struct));
Guy Schalnate5a37791996-06-05 15:50:50 -0500221
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600222#ifdef PNG_SETJMP_SUPPORTED
Guy Schalnate5a37791996-06-05 15:50:50 -0500223 /* restore jump buffer */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500224 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600225#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500226
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500227 /* added at libpng-1.2.6 */
228#ifdef PNG_SET_USER_LIMITS_SUPPORTED
229 png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
230 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
231#endif
232
Guy Schalnate5a37791996-06-05 15:50:50 -0500233 /* initialize zbuf - compression buffer */
234 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500235 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
236 png_ptr->zbuf_size);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600237 png_ptr->zstream.zalloc = png_zalloc;
238 png_ptr->zstream.zfree = png_zfree;
239 png_ptr->zstream.opaque = (voidpf)png_ptr;
Guy Schalnate5a37791996-06-05 15:50:50 -0500240
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600241 switch (inflateInit(&png_ptr->zstream))
Guy Schalnate5a37791996-06-05 15:50:50 -0500242 {
243 case Z_OK: /* Do nothing */ break;
244 case Z_MEM_ERROR:
245 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
246 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
247 default: png_error(png_ptr, "Unknown zlib error");
248 }
249
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600250 png_ptr->zstream.next_out = png_ptr->zbuf;
251 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
Guy Schalnate5a37791996-06-05 15:50:50 -0500252
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500253 png_set_read_fn(png_ptr, NULL, NULL);
Guy Schalnat0d580581995-07-20 02:43:20 -0500254}
255
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500256#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600257/* Read the information before the actual image data. This has been
Glenn Randers-Pehrsonf9f2fe01998-03-15 18:20:23 -0600258 * changed in v0.90 to allow reading a file that already has the magic
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600259 * bytes read from the stream. You can tell libpng how many bytes have
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500260 * been read from the beginning of the stream (up to the maximum of 8)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600261 * via png_set_sig_bytes(), and we will only check the remaining bytes
262 * here. The application can then have access to the signature bytes we
263 * read if it is determined that this isn't a valid PNG file.
264 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500265void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600266png_read_info(png_structp png_ptr, png_infop info_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500267{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500268 if (png_ptr == NULL || info_ptr == NULL) return;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500269 png_debug(1, "in png_read_info\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600270 /* If we haven't checked all of the PNG signature bytes, do so now. */
271 if (png_ptr->sig_bytes < 8)
Guy Schalnate5a37791996-06-05 15:50:50 -0500272 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500273 png_size_t num_checked = png_ptr->sig_bytes,
274 num_to_check = 8 - num_checked;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600275
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500276#ifdef PNG_IO_STATE_SUPPORTED
277 png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
278#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500279
Andreas Dilger47a0c421997-05-16 02:46:07 -0500280 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600281 png_ptr->sig_bytes = 8;
282
283 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
284 {
285 if (num_checked < 4 &&
286 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
287 png_error(png_ptr, "Not a PNG file");
288 else
289 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
290 }
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -0600291 if (num_checked < 3)
292 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
Guy Schalnate5a37791996-06-05 15:50:50 -0500293 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500294
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500295 for (;;)
Guy Schalnat0d580581995-07-20 02:43:20 -0500296 {
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600297#ifdef PNG_USE_LOCAL_ARRAYS
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500298 PNG_CONST PNG_IHDR;
299 PNG_CONST PNG_IDAT;
300 PNG_CONST PNG_IEND;
301 PNG_CONST PNG_PLTE;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600302#if defined(PNG_READ_bKGD_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500303 PNG_CONST PNG_bKGD;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600304#endif
305#if defined(PNG_READ_cHRM_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500306 PNG_CONST PNG_cHRM;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600307#endif
308#if defined(PNG_READ_gAMA_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500309 PNG_CONST PNG_gAMA;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600310#endif
311#if defined(PNG_READ_hIST_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500312 PNG_CONST PNG_hIST;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600313#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600314#if defined(PNG_READ_iCCP_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500315 PNG_CONST PNG_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600316#endif
317#if defined(PNG_READ_iTXt_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500318 PNG_CONST PNG_iTXt;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600319#endif
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600320#if defined(PNG_READ_oFFs_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500321 PNG_CONST PNG_oFFs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600322#endif
323#if defined(PNG_READ_pCAL_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500324 PNG_CONST PNG_pCAL;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600325#endif
326#if defined(PNG_READ_pHYs_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500327 PNG_CONST PNG_pHYs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600328#endif
329#if defined(PNG_READ_sBIT_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500330 PNG_CONST PNG_sBIT;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600331#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600332#if defined(PNG_READ_sCAL_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500333 PNG_CONST PNG_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600334#endif
335#if defined(PNG_READ_sPLT_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500336 PNG_CONST PNG_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600337#endif
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600338#if defined(PNG_READ_sRGB_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500339 PNG_CONST PNG_sRGB;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600340#endif
341#if defined(PNG_READ_tEXt_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500342 PNG_CONST PNG_tEXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600343#endif
344#if defined(PNG_READ_tIME_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500345 PNG_CONST PNG_tIME;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600346#endif
347#if defined(PNG_READ_tRNS_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500348 PNG_CONST PNG_tRNS;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600349#endif
350#if defined(PNG_READ_zTXt_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500351 PNG_CONST PNG_zTXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600352#endif
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -0600353#endif /* PNG_USE_LOCAL_ARRAYS */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500354 png_uint_32 length = png_read_chunk_header(png_ptr);
355 png_bytep chunk_name = png_ptr->chunk_name;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500356
357 /* This should be a binary subdivision search or a hash for
358 * matching the chunk name rather than a linear search.
359 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500360 if (!png_memcmp(chunk_name, png_IDAT, 4))
361 if (png_ptr->mode & PNG_AFTER_IDAT)
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500362 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
363
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500364 if (!png_memcmp(chunk_name, png_IHDR, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600365 png_handle_IHDR(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500366 else if (!png_memcmp(chunk_name, png_IEND, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600367 png_handle_IEND(png_ptr, info_ptr, length);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600368#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500369 else if (png_handle_as_unknown(png_ptr, chunk_name))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600370 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500371 if (!png_memcmp(chunk_name, png_IDAT, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600372 png_ptr->mode |= PNG_HAVE_IDAT;
373 png_handle_unknown(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500374 if (!png_memcmp(chunk_name, png_PLTE, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600375 png_ptr->mode |= PNG_HAVE_PLTE;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500376 else if (!png_memcmp(chunk_name, png_IDAT, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600377 {
378 if (!(png_ptr->mode & PNG_HAVE_IHDR))
379 png_error(png_ptr, "Missing IHDR before IDAT");
380 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
381 !(png_ptr->mode & PNG_HAVE_PLTE))
382 png_error(png_ptr, "Missing PLTE before IDAT");
383 break;
384 }
385 }
386#endif
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500387 else if (!png_memcmp(chunk_name, png_PLTE, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600388 png_handle_PLTE(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500389 else if (!png_memcmp(chunk_name, png_IDAT, 4))
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500390 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500391 if (!(png_ptr->mode & PNG_HAVE_IHDR))
392 png_error(png_ptr, "Missing IHDR before IDAT");
393 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
394 !(png_ptr->mode & PNG_HAVE_PLTE))
395 png_error(png_ptr, "Missing PLTE before IDAT");
396
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500397 png_ptr->idat_size = length;
Guy Schalnate5a37791996-06-05 15:50:50 -0500398 png_ptr->mode |= PNG_HAVE_IDAT;
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500399 break;
400 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500401#if defined(PNG_READ_bKGD_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500402 else if (!png_memcmp(chunk_name, png_bKGD, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500403 png_handle_bKGD(png_ptr, info_ptr, length);
404#endif
405#if defined(PNG_READ_cHRM_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500406 else if (!png_memcmp(chunk_name, png_cHRM, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500407 png_handle_cHRM(png_ptr, info_ptr, length);
408#endif
409#if defined(PNG_READ_gAMA_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500410 else if (!png_memcmp(chunk_name, png_gAMA, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500411 png_handle_gAMA(png_ptr, info_ptr, length);
412#endif
413#if defined(PNG_READ_hIST_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500414 else if (!png_memcmp(chunk_name, png_hIST, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500415 png_handle_hIST(png_ptr, info_ptr, length);
416#endif
417#if defined(PNG_READ_oFFs_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500418 else if (!png_memcmp(chunk_name, png_oFFs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500419 png_handle_oFFs(png_ptr, info_ptr, length);
420#endif
421#if defined(PNG_READ_pCAL_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500422 else if (!png_memcmp(chunk_name, png_pCAL, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500423 png_handle_pCAL(png_ptr, info_ptr, length);
424#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600425#if defined(PNG_READ_sCAL_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500426 else if (!png_memcmp(chunk_name, png_sCAL, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600427 png_handle_sCAL(png_ptr, info_ptr, length);
428#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500429#if defined(PNG_READ_pHYs_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500430 else if (!png_memcmp(chunk_name, png_pHYs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500431 png_handle_pHYs(png_ptr, info_ptr, length);
432#endif
433#if defined(PNG_READ_sBIT_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500434 else if (!png_memcmp(chunk_name, png_sBIT, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500435 png_handle_sBIT(png_ptr, info_ptr, length);
436#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600437#if defined(PNG_READ_sRGB_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500438 else if (!png_memcmp(chunk_name, png_sRGB, 4))
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600439 png_handle_sRGB(png_ptr, info_ptr, length);
440#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600441#if defined(PNG_READ_iCCP_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500442 else if (!png_memcmp(chunk_name, png_iCCP, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600443 png_handle_iCCP(png_ptr, info_ptr, length);
444#endif
445#if defined(PNG_READ_sPLT_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500446 else if (!png_memcmp(chunk_name, png_sPLT, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600447 png_handle_sPLT(png_ptr, info_ptr, length);
448#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500449#if defined(PNG_READ_tEXt_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500450 else if (!png_memcmp(chunk_name, png_tEXt, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500451 png_handle_tEXt(png_ptr, info_ptr, length);
452#endif
453#if defined(PNG_READ_tIME_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500454 else if (!png_memcmp(chunk_name, png_tIME, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500455 png_handle_tIME(png_ptr, info_ptr, length);
456#endif
457#if defined(PNG_READ_tRNS_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500458 else if (!png_memcmp(chunk_name, png_tRNS, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500459 png_handle_tRNS(png_ptr, info_ptr, length);
460#endif
461#if defined(PNG_READ_zTXt_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500462 else if (!png_memcmp(chunk_name, png_zTXt, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500463 png_handle_zTXt(png_ptr, info_ptr, length);
464#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600465#if defined(PNG_READ_iTXt_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500466 else if (!png_memcmp(chunk_name, png_iTXt, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600467 png_handle_iTXt(png_ptr, info_ptr, length);
468#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500469 else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600470 png_handle_unknown(png_ptr, info_ptr, length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500471 }
472}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500473#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500474
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600475/* optional call to update the users info_ptr structure */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500476void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600477png_read_update_info(png_structp png_ptr, png_infop info_ptr)
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500478{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500479 png_debug(1, "in png_read_update_info\n");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500480 if (png_ptr == NULL) return;
Guy Schalnate5a37791996-06-05 15:50:50 -0500481 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500482 png_read_start_row(png_ptr);
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600483 else
484 png_warning(png_ptr,
485 "Ignoring extra png_read_update_info() call; row buffer not reallocated");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600486 png_read_transform_info(png_ptr, info_ptr);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500487}
488
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500489#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600490/* Initialize palette, background, etc, after transformations
491 * are set, but before any reading takes place. This allows
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500492 * the user to obtain a gamma-corrected palette, for example.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600493 * If the user doesn't call this, we will do it ourselves.
494 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500495void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600496png_start_read_image(png_structp png_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500497{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500498 png_debug(1, "in png_start_read_image\n");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500499 if (png_ptr == NULL) return;
Guy Schalnate5a37791996-06-05 15:50:50 -0500500 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500501 png_read_start_row(png_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500502}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500503#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500504
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500505#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500506void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600507png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
Guy Schalnat0d580581995-07-20 02:43:20 -0500508{
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600509#ifdef PNG_USE_LOCAL_ARRAYS
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500510 PNG_CONST PNG_IDAT;
511 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
512 0xff};
513 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600514#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500515 int ret;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500516 if (png_ptr == NULL) return;
Glenn Randers-Pehrson4766a242000-07-17 06:17:09 -0500517 png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500518 (unsigned long) png_ptr->row_number, png_ptr->pass);
Guy Schalnate5a37791996-06-05 15:50:50 -0500519 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
Guy Schalnat0d580581995-07-20 02:43:20 -0500520 png_read_start_row(png_ptr);
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500521 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
522 {
523 /* check for transforms that have been set but were defined out */
524#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
525 if (png_ptr->transformations & PNG_INVERT_MONO)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500526 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500527#endif
528#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
529 if (png_ptr->transformations & PNG_FILLER)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500530 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500531#endif
532#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
533 if (png_ptr->transformations & PNG_PACKSWAP)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500534 png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500535#endif
536#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
537 if (png_ptr->transformations & PNG_PACK)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500538 png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500539#endif
540#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
541 if (png_ptr->transformations & PNG_SHIFT)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500542 png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500543#endif
544#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
545 if (png_ptr->transformations & PNG_BGR)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500546 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500547#endif
548#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
549 if (png_ptr->transformations & PNG_SWAP_BYTES)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500550 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500551#endif
552 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500553
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500554#if defined(PNG_READ_INTERLACING_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500555 /* if interlaced and we do not need a new row, combine row and return */
556 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
557 {
558 switch (png_ptr->pass)
559 {
560 case 0:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600561 if (png_ptr->row_number & 0x07)
Guy Schalnat0d580581995-07-20 02:43:20 -0500562 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500563 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500564 png_combine_row(png_ptr, dsp_row,
565 png_pass_dsp_mask[png_ptr->pass]);
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600566 png_read_finish_row(png_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500567 return;
568 }
569 break;
570 case 1:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600571 if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
Guy Schalnat0d580581995-07-20 02:43:20 -0500572 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500573 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500574 png_combine_row(png_ptr, dsp_row,
575 png_pass_dsp_mask[png_ptr->pass]);
576 png_read_finish_row(png_ptr);
577 return;
578 }
579 break;
580 case 2:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600581 if ((png_ptr->row_number & 0x07) != 4)
Guy Schalnat0d580581995-07-20 02:43:20 -0500582 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500583 if (dsp_row != NULL && (png_ptr->row_number & 4))
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600584 png_combine_row(png_ptr, dsp_row,
Guy Schalnat0d580581995-07-20 02:43:20 -0500585 png_pass_dsp_mask[png_ptr->pass]);
586 png_read_finish_row(png_ptr);
587 return;
588 }
589 break;
590 case 3:
591 if ((png_ptr->row_number & 3) || png_ptr->width < 3)
592 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500593 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500594 png_combine_row(png_ptr, dsp_row,
595 png_pass_dsp_mask[png_ptr->pass]);
596 png_read_finish_row(png_ptr);
597 return;
598 }
599 break;
600 case 4:
601 if ((png_ptr->row_number & 3) != 2)
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600602 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500603 if (dsp_row != NULL && (png_ptr->row_number & 2))
Guy Schalnat0d580581995-07-20 02:43:20 -0500604 png_combine_row(png_ptr, dsp_row,
605 png_pass_dsp_mask[png_ptr->pass]);
606 png_read_finish_row(png_ptr);
607 return;
608 }
609 break;
610 case 5:
611 if ((png_ptr->row_number & 1) || png_ptr->width < 2)
612 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500613 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500614 png_combine_row(png_ptr, dsp_row,
615 png_pass_dsp_mask[png_ptr->pass]);
616 png_read_finish_row(png_ptr);
617 return;
618 }
619 break;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600620 case 6:
Guy Schalnat0d580581995-07-20 02:43:20 -0500621 if (!(png_ptr->row_number & 1))
622 {
623 png_read_finish_row(png_ptr);
624 return;
625 }
626 break;
627 }
628 }
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500629#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500630
Guy Schalnate5a37791996-06-05 15:50:50 -0500631 if (!(png_ptr->mode & PNG_HAVE_IDAT))
632 png_error(png_ptr, "Invalid attempt to read row data");
Guy Schalnat0d580581995-07-20 02:43:20 -0500633
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600634 png_ptr->zstream.next_out = png_ptr->row_buf;
635 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
Guy Schalnat0d580581995-07-20 02:43:20 -0500636 do
637 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600638 if (!(png_ptr->zstream.avail_in))
Guy Schalnat0d580581995-07-20 02:43:20 -0500639 {
640 while (!png_ptr->idat_size)
641 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600642 png_crc_finish(png_ptr, 0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500643
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500644 png_ptr->idat_size = png_read_chunk_header(png_ptr);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600645 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
646 png_error(png_ptr, "Not enough image data");
Guy Schalnat0d580581995-07-20 02:43:20 -0500647 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600648 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
649 png_ptr->zstream.next_in = png_ptr->zbuf;
Guy Schalnat0d580581995-07-20 02:43:20 -0500650 if (png_ptr->zbuf_size > png_ptr->idat_size)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600651 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500652 png_crc_read(png_ptr, png_ptr->zbuf,
653 (png_size_t)png_ptr->zstream.avail_in);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600654 png_ptr->idat_size -= png_ptr->zstream.avail_in;
Guy Schalnat0d580581995-07-20 02:43:20 -0500655 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600656 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
Guy Schalnat0d580581995-07-20 02:43:20 -0500657 if (ret == Z_STREAM_END)
658 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600659 if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
Guy Schalnat0d580581995-07-20 02:43:20 -0500660 png_ptr->idat_size)
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500661 png_benign_error(png_ptr, "Extra compressed data");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600662 png_ptr->mode |= PNG_AFTER_IDAT;
Guy Schalnate5a37791996-06-05 15:50:50 -0500663 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600664 break;
Guy Schalnat0d580581995-07-20 02:43:20 -0500665 }
666 if (ret != Z_OK)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600667 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
Guy Schalnate5a37791996-06-05 15:50:50 -0500668 "Decompression error");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600669
670 } while (png_ptr->zstream.avail_out);
Guy Schalnat0d580581995-07-20 02:43:20 -0500671
Guy Schalnat0d580581995-07-20 02:43:20 -0500672 png_ptr->row_info.color_type = png_ptr->color_type;
673 png_ptr->row_info.width = png_ptr->iwidth;
674 png_ptr->row_info.channels = png_ptr->channels;
675 png_ptr->row_info.bit_depth = png_ptr->bit_depth;
676 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500677 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
678 png_ptr->row_info.width);
Guy Schalnat0d580581995-07-20 02:43:20 -0500679
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500680 if (png_ptr->row_buf[0])
Guy Schalnate5a37791996-06-05 15:50:50 -0500681 png_read_filter_row(png_ptr, &(png_ptr->row_info),
682 png_ptr->row_buf + 1, png_ptr->prev_row + 1,
683 (int)(png_ptr->row_buf[0]));
Guy Schalnat0d580581995-07-20 02:43:20 -0500684
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500685 png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600686
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -0600687#if defined(PNG_MNG_FEATURES_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500688 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -0600689 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
690 {
691 /* Intrapixel differencing */
692 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
693 }
694#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500695
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500696
Glenn Randers-Pehrson73b029f2004-11-26 17:28:09 -0600697 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
Guy Schalnat0d580581995-07-20 02:43:20 -0500698 png_do_read_transformations(png_ptr);
699
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500700#if defined(PNG_READ_INTERLACING_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500701 /* blow up interlaced rows to full size */
702 if (png_ptr->interlaced &&
703 (png_ptr->transformations & PNG_INTERLACE))
704 {
705 if (png_ptr->pass < 6)
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600706/* old interface (pre-1.0.9):
Guy Schalnat0d580581995-07-20 02:43:20 -0500707 png_do_read_interlace(&(png_ptr->row_info),
Andreas Dilger47a0c421997-05-16 02:46:07 -0500708 png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600709 */
710 png_do_read_interlace(png_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500711
Andreas Dilger47a0c421997-05-16 02:46:07 -0500712 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500713 png_combine_row(png_ptr, dsp_row,
714 png_pass_dsp_mask[png_ptr->pass]);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500715 if (row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500716 png_combine_row(png_ptr, row,
717 png_pass_mask[png_ptr->pass]);
718 }
719 else
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500720#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500721 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500722 if (row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500723 png_combine_row(png_ptr, row, 0xff);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500724 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500725 png_combine_row(png_ptr, dsp_row, 0xff);
726 }
727 png_read_finish_row(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600728
729 if (png_ptr->read_row_fn != NULL)
730 (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
Guy Schalnat0d580581995-07-20 02:43:20 -0500731}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500732#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500733
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500734#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500735/* Read one or more rows of image data. If the image is interlaced,
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600736 * and png_set_interlace_handling() has been called, the rows need to
737 * contain the contents of the rows from the previous pass. If the
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500738 * image has alpha or transparency, and png_handle_alpha()[*] has been
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600739 * called, the rows contents must be initialized to the contents of the
740 * screen.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600741 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600742 * "row" holds the actual image, and pixels are placed in it
743 * as they arrive. If the image is displayed after each pass, it will
744 * appear to "sparkle" in. "display_row" can be used to display a
745 * "chunky" progressive image, with finer detail added as it becomes
746 * available. If you do not want this "chunky" display, you may pass
747 * NULL for display_row. If you do not want the sparkle display, and
748 * you have not called png_handle_alpha(), you may pass NULL for rows.
749 * If you have called png_handle_alpha(), and the image has either an
750 * alpha channel or a transparency chunk, you must provide a buffer for
751 * rows. In this case, you do not have to provide a display_row buffer
752 * also, but you may. If the image is not interlaced, or if you have
753 * not called png_set_interlace_handling(), the display_row buffer will
754 * be ignored, so pass NULL to it.
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500755 *
Glenn Randers-Pehrsonc3d51c12006-03-02 07:23:18 -0600756 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600757 */
Guy Schalnat6d764711995-12-19 03:22:19 -0600758
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500759void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600760png_read_rows(png_structp png_ptr, png_bytepp row,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600761 png_bytepp display_row, png_uint_32 num_rows)
Guy Schalnat0d580581995-07-20 02:43:20 -0500762{
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600763 png_uint_32 i;
764 png_bytepp rp;
765 png_bytepp dp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500766
Andreas Dilger47a0c421997-05-16 02:46:07 -0500767 png_debug(1, "in png_read_rows\n");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500768 if (png_ptr == NULL) return;
Guy Schalnat0f716451995-11-28 11:22:13 -0600769 rp = row;
770 dp = display_row;
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500771 if (rp != NULL && dp != NULL)
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500772 for (i = 0; i < num_rows; i++)
773 {
774 png_bytep rptr = *rp++;
775 png_bytep dptr = *dp++;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600776
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500777 png_read_row(png_ptr, rptr, dptr);
778 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500779 else if (rp != NULL)
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500780 for (i = 0; i < num_rows; i++)
781 {
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500782 png_bytep rptr = *rp;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500783 png_read_row(png_ptr, rptr, NULL);
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500784 rp++;
785 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500786 else if (dp != NULL)
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500787 for (i = 0; i < num_rows; i++)
788 {
789 png_bytep dptr = *dp;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500790 png_read_row(png_ptr, NULL, dptr);
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500791 dp++;
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500792 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500793}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500794#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500795
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500796#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500797/* Read the entire image. If the image has an alpha channel or a tRNS
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500798 * chunk, and you have called png_handle_alpha()[*], you will need to
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600799 * initialize the image to the current image that PNG will be overlaying.
800 * We set the num_rows again here, in case it was incorrectly set in
801 * png_read_start_row() by a call to png_read_update_info() or
802 * png_start_read_image() if png_set_interlace_handling() wasn't called
803 * prior to either of these functions like it should have been. You can
804 * only call this function once. If you desire to have an image for
805 * each pass of a interlaced image, use png_read_rows() instead.
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500806 *
Glenn Randers-Pehrsonc3d51c12006-03-02 07:23:18 -0600807 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600808 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500809void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600810png_read_image(png_structp png_ptr, png_bytepp image)
Guy Schalnat0d580581995-07-20 02:43:20 -0500811{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500812 png_uint_32 i, image_height;
Guy Schalnat0d580581995-07-20 02:43:20 -0500813 int pass, j;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600814 png_bytepp rp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500815
Andreas Dilger47a0c421997-05-16 02:46:07 -0500816 png_debug(1, "in png_read_image\n");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500817 if (png_ptr == NULL) return;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500818
819#ifdef PNG_READ_INTERLACING_SUPPORTED
Guy Schalnat0d580581995-07-20 02:43:20 -0500820 pass = png_set_interlace_handling(png_ptr);
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500821#else
822 if (png_ptr->interlaced)
823 png_error(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500824 "Cannot read interlaced image -- interlace handler disabled");
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500825 pass = 1;
826#endif
827
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500828
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500829 image_height=png_ptr->height;
830 png_ptr->num_rows = image_height; /* Make sure this is set correctly */
Guy Schalnate5a37791996-06-05 15:50:50 -0500831
Guy Schalnat0d580581995-07-20 02:43:20 -0500832 for (j = 0; j < pass; j++)
833 {
834 rp = image;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500835 for (i = 0; i < image_height; i++)
Guy Schalnat0d580581995-07-20 02:43:20 -0500836 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500837 png_read_row(png_ptr, *rp, NULL);
Guy Schalnat0d580581995-07-20 02:43:20 -0500838 rp++;
839 }
840 }
841}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500842#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500843
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500844#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500845/* Read the end of the PNG file. Will not read past the end of the
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600846 * file, will verify the end is accurate, and will read any comments
847 * or time information at the end of the file, if info is not NULL.
848 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500849void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600850png_read_end(png_structp png_ptr, png_infop info_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500851{
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500852 png_bytep chunk_name;
Guy Schalnat0d580581995-07-20 02:43:20 -0500853 png_uint_32 length;
Guy Schalnat0d580581995-07-20 02:43:20 -0500854
Andreas Dilger47a0c421997-05-16 02:46:07 -0500855 png_debug(1, "in png_read_end\n");
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500856 if (png_ptr == NULL) return;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500857 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
Guy Schalnat0d580581995-07-20 02:43:20 -0500858
859 do
860 {
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600861#ifdef PNG_USE_LOCAL_ARRAYS
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500862 PNG_CONST PNG_IHDR;
863 PNG_CONST PNG_IDAT;
864 PNG_CONST PNG_IEND;
865 PNG_CONST PNG_PLTE;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600866#if defined(PNG_READ_bKGD_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500867 PNG_CONST PNG_bKGD;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600868#endif
869#if defined(PNG_READ_cHRM_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500870 PNG_CONST PNG_cHRM;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600871#endif
872#if defined(PNG_READ_gAMA_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500873 PNG_CONST PNG_gAMA;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600874#endif
875#if defined(PNG_READ_hIST_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500876 PNG_CONST PNG_hIST;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600877#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600878#if defined(PNG_READ_iCCP_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500879 PNG_CONST PNG_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600880#endif
881#if defined(PNG_READ_iTXt_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500882 PNG_CONST PNG_iTXt;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600883#endif
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600884#if defined(PNG_READ_oFFs_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500885 PNG_CONST PNG_oFFs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600886#endif
887#if defined(PNG_READ_pCAL_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500888 PNG_CONST PNG_pCAL;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600889#endif
890#if defined(PNG_READ_pHYs_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500891 PNG_CONST PNG_pHYs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600892#endif
893#if defined(PNG_READ_sBIT_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500894 PNG_CONST PNG_sBIT;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600895#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600896#if defined(PNG_READ_sCAL_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500897 PNG_CONST PNG_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600898#endif
899#if defined(PNG_READ_sPLT_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500900 PNG_CONST PNG_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600901#endif
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600902#if defined(PNG_READ_sRGB_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500903 PNG_CONST PNG_sRGB;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600904#endif
905#if defined(PNG_READ_tEXt_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500906 PNG_CONST PNG_tEXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600907#endif
908#if defined(PNG_READ_tIME_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500909 PNG_CONST PNG_tIME;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600910#endif
911#if defined(PNG_READ_tRNS_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500912 PNG_CONST PNG_tRNS;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600913#endif
914#if defined(PNG_READ_zTXt_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500915 PNG_CONST PNG_zTXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600916#endif
Glenn Randers-Pehrson16e11662004-11-01 14:13:40 -0600917#endif /* PNG_USE_LOCAL_ARRAYS */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500918 length = png_read_chunk_header(png_ptr);
919 chunk_name = png_ptr->chunk_name;
Guy Schalnat0d580581995-07-20 02:43:20 -0500920
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500921 if (!png_memcmp(chunk_name, png_IHDR, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600922 png_handle_IHDR(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500923 else if (!png_memcmp(chunk_name, png_IEND, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600924 png_handle_IEND(png_ptr, info_ptr, length);
925#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500926 else if (png_handle_as_unknown(png_ptr, chunk_name))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600927 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500928 if (!png_memcmp(chunk_name, png_IDAT, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600929 {
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500930 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500931 png_benign_error(png_ptr, "Too many IDATs found");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600932 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600933 png_handle_unknown(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500934 if (!png_memcmp(chunk_name, png_PLTE, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600935 png_ptr->mode |= PNG_HAVE_PLTE;
936 }
937#endif
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500938 else if (!png_memcmp(chunk_name, png_IDAT, 4))
Guy Schalnat0d580581995-07-20 02:43:20 -0500939 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500940 /* Zero length IDATs are legal after the last IDAT has been
941 * read, but not after other chunks have been read.
942 */
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500943 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500944 png_benign_error(png_ptr, "Too many IDATs found");
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500945 png_crc_finish(png_ptr, length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500946 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500947 else if (!png_memcmp(chunk_name, png_PLTE, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500948 png_handle_PLTE(png_ptr, info_ptr, length);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500949#if defined(PNG_READ_bKGD_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500950 else if (!png_memcmp(chunk_name, png_bKGD, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500951 png_handle_bKGD(png_ptr, info_ptr, length);
952#endif
953#if defined(PNG_READ_cHRM_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500954 else if (!png_memcmp(chunk_name, png_cHRM, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500955 png_handle_cHRM(png_ptr, info_ptr, length);
956#endif
957#if defined(PNG_READ_gAMA_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500958 else if (!png_memcmp(chunk_name, png_gAMA, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500959 png_handle_gAMA(png_ptr, info_ptr, length);
960#endif
961#if defined(PNG_READ_hIST_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500962 else if (!png_memcmp(chunk_name, png_hIST, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500963 png_handle_hIST(png_ptr, info_ptr, length);
964#endif
965#if defined(PNG_READ_oFFs_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500966 else if (!png_memcmp(chunk_name, png_oFFs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500967 png_handle_oFFs(png_ptr, info_ptr, length);
968#endif
969#if defined(PNG_READ_pCAL_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500970 else if (!png_memcmp(chunk_name, png_pCAL, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500971 png_handle_pCAL(png_ptr, info_ptr, length);
972#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600973#if defined(PNG_READ_sCAL_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500974 else if (!png_memcmp(chunk_name, png_sCAL, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600975 png_handle_sCAL(png_ptr, info_ptr, length);
976#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500977#if defined(PNG_READ_pHYs_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500978 else if (!png_memcmp(chunk_name, png_pHYs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500979 png_handle_pHYs(png_ptr, info_ptr, length);
980#endif
981#if defined(PNG_READ_sBIT_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500982 else if (!png_memcmp(chunk_name, png_sBIT, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500983 png_handle_sBIT(png_ptr, info_ptr, length);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500984#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600985#if defined(PNG_READ_sRGB_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500986 else if (!png_memcmp(chunk_name, png_sRGB, 4))
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600987 png_handle_sRGB(png_ptr, info_ptr, length);
988#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600989#if defined(PNG_READ_iCCP_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500990 else if (!png_memcmp(chunk_name, png_iCCP, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600991 png_handle_iCCP(png_ptr, info_ptr, length);
992#endif
993#if defined(PNG_READ_sPLT_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500994 else if (!png_memcmp(chunk_name, png_sPLT, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600995 png_handle_sPLT(png_ptr, info_ptr, length);
996#endif
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500997#if defined(PNG_READ_tEXt_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500998 else if (!png_memcmp(chunk_name, png_tEXt, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600999 png_handle_tEXt(png_ptr, info_ptr, length);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001000#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -05001001#if defined(PNG_READ_tIME_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001002 else if (!png_memcmp(chunk_name, png_tIME, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -05001003 png_handle_tIME(png_ptr, info_ptr, length);
1004#endif
1005#if defined(PNG_READ_tRNS_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001006 else if (!png_memcmp(chunk_name, png_tRNS, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -05001007 png_handle_tRNS(png_ptr, info_ptr, length);
1008#endif
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001009#if defined(PNG_READ_zTXt_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001010 else if (!png_memcmp(chunk_name, png_zTXt, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001011 png_handle_zTXt(png_ptr, info_ptr, length);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001012#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001013#if defined(PNG_READ_iTXt_SUPPORTED)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -05001014 else if (!png_memcmp(chunk_name, png_iTXt, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001015 png_handle_iTXt(png_ptr, info_ptr, length);
1016#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001017 else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001018 png_handle_unknown(png_ptr, info_ptr, length);
1019 } while (!(png_ptr->mode & PNG_HAVE_IEND));
Guy Schalnat0d580581995-07-20 02:43:20 -05001020}
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001021#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -05001022
1023/* free all memory used by the read */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001024void PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -05001025png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001026 png_infopp end_info_ptr_ptr)
Guy Schalnate5a37791996-06-05 15:50:50 -05001027{
1028 png_structp png_ptr = NULL;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001029 png_infop info_ptr = NULL, end_info_ptr = NULL;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001030#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001031 png_free_ptr free_fn = NULL;
1032 png_voidp mem_ptr = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001033#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001034
Andreas Dilger47a0c421997-05-16 02:46:07 -05001035 png_debug(1, "in png_destroy_read_struct\n");
Andreas Dilger47a0c421997-05-16 02:46:07 -05001036 if (png_ptr_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001037 png_ptr = *png_ptr_ptr;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001038 if (png_ptr == NULL)
1039 return;
1040
1041#ifdef PNG_USER_MEM_SUPPORTED
1042 free_fn = png_ptr->free_fn;
1043 mem_ptr = png_ptr->mem_ptr;
1044#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001045
Andreas Dilger47a0c421997-05-16 02:46:07 -05001046 if (info_ptr_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001047 info_ptr = *info_ptr_ptr;
1048
Andreas Dilger47a0c421997-05-16 02:46:07 -05001049 if (end_info_ptr_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001050 end_info_ptr = *end_info_ptr_ptr;
Guy Schalnate5a37791996-06-05 15:50:50 -05001051
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001052 png_read_destroy(png_ptr, info_ptr, end_info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -05001053
Andreas Dilger47a0c421997-05-16 02:46:07 -05001054 if (info_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001055 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001056#if defined(PNG_TEXT_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001057 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001058#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001059
1060#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05001061 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
1062 (png_voidp)mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001063#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001064 png_destroy_struct((png_voidp)info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001065#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -05001066 *info_ptr_ptr = NULL;
Guy Schalnate5a37791996-06-05 15:50:50 -05001067 }
1068
Andreas Dilger47a0c421997-05-16 02:46:07 -05001069 if (end_info_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001070 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001071#if defined(PNG_READ_TEXT_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001072 png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001073#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001074#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05001075 png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
1076 (png_voidp)mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001077#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001078 png_destroy_struct((png_voidp)end_info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001079#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -05001080 *end_info_ptr_ptr = NULL;
Guy Schalnate5a37791996-06-05 15:50:50 -05001081 }
1082
Andreas Dilger47a0c421997-05-16 02:46:07 -05001083 if (png_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001084 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001085#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05001086 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
1087 (png_voidp)mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001088#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001089 png_destroy_struct((png_voidp)png_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001090#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -05001091 *png_ptr_ptr = NULL;
Guy Schalnate5a37791996-06-05 15:50:50 -05001092 }
1093}
1094
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001095/* free all memory used by the read (old method) */
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001096void /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001097png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -05001098{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001099#ifdef PNG_SETJMP_SUPPORTED
Guy Schalnat0d580581995-07-20 02:43:20 -05001100 jmp_buf tmp_jmp;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001101#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001102 png_error_ptr error_fn;
1103 png_error_ptr warning_fn;
1104 png_voidp error_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001105#ifdef PNG_USER_MEM_SUPPORTED
1106 png_free_ptr free_fn;
1107#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001108
Andreas Dilger47a0c421997-05-16 02:46:07 -05001109 png_debug(1, "in png_read_destroy\n");
Andreas Dilger47a0c421997-05-16 02:46:07 -05001110 if (info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001111 png_info_destroy(png_ptr, info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -05001112
Andreas Dilger47a0c421997-05-16 02:46:07 -05001113 if (end_info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001114 png_info_destroy(png_ptr, end_info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -05001115
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001116 png_free(png_ptr, png_ptr->zbuf);
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001117 png_free(png_ptr, png_ptr->big_row_buf);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001118 png_free(png_ptr, png_ptr->prev_row);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001119#if defined(PNG_READ_DITHER_SUPPORTED)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001120 png_free(png_ptr, png_ptr->palette_lookup);
1121 png_free(png_ptr, png_ptr->dither_index);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001122#endif
1123#if defined(PNG_READ_GAMMA_SUPPORTED)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001124 png_free(png_ptr, png_ptr->gamma_table);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001125#endif
1126#if defined(PNG_READ_BACKGROUND_SUPPORTED)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001127 png_free(png_ptr, png_ptr->gamma_from_1);
1128 png_free(png_ptr, png_ptr->gamma_to_1);
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001129#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001130#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001131 if (png_ptr->free_me & PNG_FREE_PLTE)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001132 png_zfree(png_ptr, png_ptr->palette);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001133 png_ptr->free_me &= ~PNG_FREE_PLTE;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001134#else
1135 if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
1136 png_zfree(png_ptr, png_ptr->palette);
1137 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
1138#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001139#if defined(PNG_tRNS_SUPPORTED) || \
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001140 defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001141#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001142 if (png_ptr->free_me & PNG_FREE_TRNS)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001143 png_free(png_ptr, png_ptr->trans);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001144 png_ptr->free_me &= ~PNG_FREE_TRNS;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001145#else
1146 if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
1147 png_free(png_ptr, png_ptr->trans);
1148 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
1149#endif
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001150#endif
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001151#if defined(PNG_READ_hIST_SUPPORTED)
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001152#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001153 if (png_ptr->free_me & PNG_FREE_HIST)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001154 png_free(png_ptr, png_ptr->hist);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001155 png_ptr->free_me &= ~PNG_FREE_HIST;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001156#else
1157 if (png_ptr->flags & PNG_FLAG_FREE_HIST)
1158 png_free(png_ptr, png_ptr->hist);
1159 png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
1160#endif
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001161#endif
1162#if defined(PNG_READ_GAMMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001163 if (png_ptr->gamma_16_table != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -05001164 {
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001165 int i;
1166 int istop = (1 << (8 - png_ptr->gamma_shift));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001167 for (i = 0; i < istop; i++)
Guy Schalnat0d580581995-07-20 02:43:20 -05001168 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001169 png_free(png_ptr, png_ptr->gamma_16_table[i]);
Guy Schalnat0d580581995-07-20 02:43:20 -05001170 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001171 png_free(png_ptr, png_ptr->gamma_16_table);
Guy Schalnat0d580581995-07-20 02:43:20 -05001172 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001173#if defined(PNG_READ_BACKGROUND_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001174 if (png_ptr->gamma_16_from_1 != NULL)
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001175 {
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001176 int i;
1177 int istop = (1 << (8 - png_ptr->gamma_shift));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001178 for (i = 0; i < istop; i++)
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001179 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001180 png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001181 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001182 png_free(png_ptr, png_ptr->gamma_16_from_1);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001183 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001184 if (png_ptr->gamma_16_to_1 != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -05001185 {
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001186 int i;
1187 int istop = (1 << (8 - png_ptr->gamma_shift));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001188 for (i = 0; i < istop; i++)
Guy Schalnat0d580581995-07-20 02:43:20 -05001189 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001190 png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
Guy Schalnat0d580581995-07-20 02:43:20 -05001191 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001192 png_free(png_ptr, png_ptr->gamma_16_to_1);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001193 }
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001194#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001195#endif
1196#if defined(PNG_TIME_RFC1123_SUPPORTED)
1197 png_free(png_ptr, png_ptr->time_buffer);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001198#endif
Guy Schalnat0f716451995-11-28 11:22:13 -06001199
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001200 inflateEnd(&png_ptr->zstream);
Guy Schalnat6d764711995-12-19 03:22:19 -06001201#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001202 png_free(png_ptr, png_ptr->save_buffer);
Guy Schalnat6d764711995-12-19 03:22:19 -06001203#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001204
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -05001205#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1206#ifdef PNG_TEXT_SUPPORTED
1207 png_free(png_ptr, png_ptr->current_text);
1208#endif /* PNG_TEXT_SUPPORTED */
1209#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1210
Guy Schalnate5a37791996-06-05 15:50:50 -05001211 /* Save the important info out of the png_struct, in case it is
1212 * being used again.
1213 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001214#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001215 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001216#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001217
1218 error_fn = png_ptr->error_fn;
1219 warning_fn = png_ptr->warning_fn;
1220 error_ptr = png_ptr->error_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001221#ifdef PNG_USER_MEM_SUPPORTED
1222 free_fn = png_ptr->free_fn;
1223#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001224
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001225 png_memset(png_ptr, 0, png_sizeof(png_struct));
Guy Schalnate5a37791996-06-05 15:50:50 -05001226
1227 png_ptr->error_fn = error_fn;
1228 png_ptr->warning_fn = warning_fn;
1229 png_ptr->error_ptr = error_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001230#ifdef PNG_USER_MEM_SUPPORTED
1231 png_ptr->free_fn = free_fn;
1232#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001233
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001234#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001235 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001236#endif
1237
Guy Schalnat0d580581995-07-20 02:43:20 -05001238}
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001239
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001240void PNGAPI
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001241png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
1242{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001243 if (png_ptr == NULL) return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001244 png_ptr->read_row_fn = read_row_fn;
1245}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001246
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001247
1248#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001249#if defined(PNG_INFO_IMAGE_SUPPORTED)
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001250void PNGAPI
1251png_read_png(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001252 int transforms,
1253 voidp params)
1254{
1255 int row;
1256
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001257 if (png_ptr == NULL) return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001258#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001259 /* invert the alpha channel from opacity to transparency
1260 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001261 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1262 png_set_invert_alpha(png_ptr);
1263#endif
1264
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001265 /* png_read_info() gives us all of the information from the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001266 * PNG file before the first IDAT (image data chunk).
1267 */
1268 png_read_info(png_ptr, info_ptr);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001269 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
1270 png_error(png_ptr, "Image is too high to process with png_read_png()");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001271
1272 /* -------------- image transformations start here ------------------- */
1273
1274#if defined(PNG_READ_16_TO_8_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001275 /* tell libpng to strip 16 bit/color files down to 8 bits per color
1276 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001277 if (transforms & PNG_TRANSFORM_STRIP_16)
1278 png_set_strip_16(png_ptr);
1279#endif
1280
1281#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001282 /* Strip alpha bytes from the input data without combining with
1283 * the background (not recommended).
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001284 */
1285 if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
1286 png_set_strip_alpha(png_ptr);
1287#endif
1288
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001289#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001290 /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001291 * byte into separate bytes (useful for paletted and grayscale images).
1292 */
1293 if (transforms & PNG_TRANSFORM_PACKING)
1294 png_set_packing(png_ptr);
1295#endif
1296
1297#if defined(PNG_READ_PACKSWAP_SUPPORTED)
1298 /* Change the order of packed pixels to least significant bit first
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001299 * (not useful if you are using png_set_packing).
1300 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001301 if (transforms & PNG_TRANSFORM_PACKSWAP)
1302 png_set_packswap(png_ptr);
1303#endif
1304
1305#if defined(PNG_READ_EXPAND_SUPPORTED)
1306 /* Expand paletted colors into true RGB triplets
1307 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
1308 * Expand paletted or RGB images with transparency to full alpha
1309 * channels so the data will be available as RGBA quartets.
1310 */
1311 if (transforms & PNG_TRANSFORM_EXPAND)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001312 if ((png_ptr->bit_depth < 8) ||
1313 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
1314 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
1315 png_set_expand(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001316#endif
1317
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001318 /* We don't handle background color or gamma transformation or dithering.
1319 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001320
1321#if defined(PNG_READ_INVERT_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001322 /* invert monochrome files to have 0 as white and 1 as black
1323 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001324 if (transforms & PNG_TRANSFORM_INVERT_MONO)
1325 png_set_invert_mono(png_ptr);
1326#endif
1327
1328#if defined(PNG_READ_SHIFT_SUPPORTED)
1329 /* If you want to shift the pixel values from the range [0,255] or
1330 * [0,65535] to the original [0,7] or [0,31], or whatever range the
1331 * colors were originally in:
1332 */
1333 if ((transforms & PNG_TRANSFORM_SHIFT)
1334 && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
1335 {
1336 png_color_8p sig_bit;
1337
1338 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1339 png_set_shift(png_ptr, sig_bit);
1340 }
1341#endif
1342
1343#if defined(PNG_READ_BGR_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001344 /* flip the RGB pixels to BGR (or RGBA to BGRA)
1345 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001346 if (transforms & PNG_TRANSFORM_BGR)
1347 png_set_bgr(png_ptr);
1348#endif
1349
1350#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001351 /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
1352 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001353 if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1354 png_set_swap_alpha(png_ptr);
1355#endif
1356
1357#if defined(PNG_READ_SWAP_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001358 /* swap bytes of 16 bit files to least significant byte first
1359 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001360 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1361 png_set_swap(png_ptr);
1362#endif
1363
1364 /* We don't handle adding filler bytes */
1365
1366 /* Optional call to gamma correct and add the background to the palette
1367 * and update info structure. REQUIRED if you are expecting libpng to
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001368 * update the palette for you (i.e., you selected such a transform above).
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001369 */
1370 png_read_update_info(png_ptr, info_ptr);
1371
1372 /* -------------- image transformations end here ------------------- */
1373
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001374#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001375 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001376#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001377 if (info_ptr->row_pointers == NULL)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001378 {
1379 info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001380 info_ptr->height * png_sizeof(png_bytep));
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001381#ifdef PNG_FREE_ME_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001382 info_ptr->free_me |= PNG_FREE_ROWS;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001383#endif
1384 for (row = 0; row < (int)info_ptr->height; row++)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001385 {
1386 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001387 png_get_rowbytes(png_ptr, info_ptr));
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001388 }
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001389 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001390
1391 png_read_image(png_ptr, info_ptr->row_pointers);
1392 info_ptr->valid |= PNG_INFO_IDAT;
1393
1394 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
1395 png_read_end(png_ptr, info_ptr);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001396
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001397 transforms = transforms; /* quiet compiler warnings */
1398 params = params;
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001399
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001400}
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001401#endif /* PNG_INFO_IMAGE_SUPPORTED */
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001402#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001403#endif /* PNG_READ_SUPPORTED */