blob: 0d446c61b997863a9b990df47bb9f9b0f2debaa4 [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-Pehrsone26c0952009-09-23 11:22:08 -05004 * Last changed in libpng 1.4.0 [September 23, 2009]
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -06005 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06008 *
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05009 * This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -050010 * For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -050011 * and license in png.h
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -050012 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060013 * This file contains routines that an application calls directly to
14 * read a PNG file or stream.
15 */
Guy Schalnat0d580581995-07-20 02:43:20 -050016
Guy Schalnat0d580581995-07-20 02:43:20 -050017#include "png.h"
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -050018#ifdef PNG_READ_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050019#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060020
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -050021
Andreas Dilger47a0c421997-05-16 02:46:07 -050022/* Create a PNG structure for reading, and allocate any memory needed. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050023png_structp PNGAPI
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -050024png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060025 png_error_ptr error_fn, png_error_ptr warn_fn)
Guy Schalnat0d580581995-07-20 02:43:20 -050026{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050027
28#ifdef PNG_USER_MEM_SUPPORTED
29 return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050030 warn_fn, NULL, NULL, NULL));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050031}
32
33/* Alternate create PNG structure for reading, and allocate any memory needed. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050034png_structp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050035png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
36 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
37 png_malloc_ptr malloc_fn, png_free_ptr free_fn)
38{
39#endif /* PNG_USER_MEM_SUPPORTED */
40
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -060041#ifdef PNG_SETJMP_SUPPORTED
42 volatile
43#endif
44 png_structp png_ptr;
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -050045 int png_cleanup_needed = 0;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060046
47#ifdef PNG_SETJMP_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060048#ifdef USE_FAR_KEYWORD
49 jmp_buf jmpbuf;
50#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060051#endif
52
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050053 int i;
54
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -050055 png_debug(1, "in png_create_read_struct");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -050056
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050057#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060058 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050059 malloc_fn, mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050060#else
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060061 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050062#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -060063 if (png_ptr == NULL)
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050064 return (NULL);
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050065
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -050066 /* Added at libpng-1.2.6 */
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -050067#ifdef PNG_SET_USER_LIMITS_SUPPORTED
68 png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
69 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
70#endif
71
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -050072#ifdef PNG_SETJMP_SUPPORTED
73/* Applications that neglect to set up their own setjmp() and then
74 encounter a png_error() will longjmp here. Since the jmpbuf is
75 then meaningless we abort instead of returning. */
76#ifdef USE_FAR_KEYWORD
77 if (setjmp(jmpbuf))
78#else
79 if (setjmp(png_ptr->jmpbuf))
80#endif
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050081 PNG_ABORT();
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -050082#endif
83
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050084#ifdef PNG_USER_MEM_SUPPORTED
85 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060086#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050087
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060088 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
Guy Schalnat6d764711995-12-19 03:22:19 -060089
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050090 if (user_png_ver)
Guy Schalnate5a37791996-06-05 15:50:50 -050091 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050092 i = 0;
93 do
94 {
95 if (user_png_ver[i] != png_libpng_ver[i])
96 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
97 } while (png_libpng_ver[i++]);
98 }
99 else
100 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
Glenn Randers-Pehrsond60c8862009-06-15 21:56:14 -0500101
Guy Schalnate5a37791996-06-05 15:50:50 -0500102
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500103 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
104 {
105 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
106 * we must recompile any applications that use any older library version.
107 * For versions after libpng 1.0, we will be compatible, so we need
108 * only check the first digit.
109 */
110 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
111 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
112 (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
113 {
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500114#if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500115 char msg[80];
116 if (user_png_ver)
117 {
118 png_snprintf(msg, 80,
119 "Application was compiled with png.h from libpng-%.20s",
120 user_png_ver);
121 png_warning(png_ptr, msg);
122 }
123 png_snprintf(msg, 80,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500124 "Application is running with png.c from libpng-%.20s",
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500125 png_libpng_ver);
126 png_warning(png_ptr, msg);
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -0500127#endif
128#ifdef PNG_ERROR_NUMBERS_SUPPORTED
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500129 png_ptr->flags = 0;
Glenn Randers-Pehrsonb1828932001-06-23 08:03:17 -0500130#endif
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500131 png_warning(png_ptr,
132 "Incompatible libpng version in application and library");
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500133
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500134 png_cleanup_needed = 1;
135 }
Glenn Randers-Pehrson98c9d732000-05-03 21:06:11 -0500136 }
137
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500138 if (!png_cleanup_needed)
139 {
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500140 /* Initialize zbuf - compression buffer */
Guy Schalnat0d580581995-07-20 02:43:20 -0500141 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500142 png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500143 png_ptr->zbuf_size);
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500144 if (png_ptr->zbuf == NULL)
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -0500145 png_cleanup_needed = 1;
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500146 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600147 png_ptr->zstream.zalloc = png_zalloc;
148 png_ptr->zstream.zfree = png_zfree;
149 png_ptr->zstream.opaque = (voidpf)png_ptr;
Guy Schalnate5a37791996-06-05 15:50:50 -0500150
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500151 if (!png_cleanup_needed)
152 {
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500153 switch (inflateInit(&png_ptr->zstream))
154 {
155 case Z_OK: /* Do nothing */ break;
156 case Z_MEM_ERROR:
157 case Z_STREAM_ERROR: png_warning(png_ptr, "zlib memory error");
158 png_cleanup_needed = 1; break;
159 case Z_VERSION_ERROR: png_warning(png_ptr, "zlib version error");
160 png_cleanup_needed = 1; break;
161 default: png_warning(png_ptr, "Unknown zlib error");
162 png_cleanup_needed = 1;
163 }
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500164 }
165
166 if (png_cleanup_needed)
167 {
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -0500168 /* Clean up PNG structure and deallocate any memory. */
169 png_free(png_ptr, png_ptr->zbuf);
170 png_ptr->zbuf = NULL;
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500171#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -0500172 png_destroy_struct_2((png_voidp)png_ptr,
173 (png_free_ptr)free_fn, (png_voidp)mem_ptr);
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500174#else
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -0500175 png_destroy_struct((png_voidp)png_ptr);
Glenn Randers-Pehrsona93c9422009-04-13 11:41:33 -0500176#endif
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -0500177 return (NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500178 }
179
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600180 png_ptr->zstream.next_out = png_ptr->zbuf;
181 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
Guy Schalnate5a37791996-06-05 15:50:50 -0500182
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500183 png_set_read_fn(png_ptr, NULL, NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500184
Glenn Randers-Pehrsonf0a8fe02009-04-14 08:28:15 -0500185
Guy Schalnate5a37791996-06-05 15:50:50 -0500186 return (png_ptr);
187}
188
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500189
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500190#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600191/* Read the information before the actual image data. This has been
Glenn Randers-Pehrsonf9f2fe01998-03-15 18:20:23 -0600192 * changed in v0.90 to allow reading a file that already has the magic
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600193 * bytes read from the stream. You can tell libpng how many bytes have
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500194 * been read from the beginning of the stream (up to the maximum of 8)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600195 * via png_set_sig_bytes(), and we will only check the remaining bytes
196 * here. The application can then have access to the signature bytes we
197 * read if it is determined that this isn't a valid PNG file.
198 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500199void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600200png_read_info(png_structp png_ptr, png_infop info_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500201{
Glenn Randers-Pehrsonc81bb8a2009-08-15 22:02:26 -0500202 png_debug(1, "in png_read_info");
203
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500204 if (png_ptr == NULL || info_ptr == NULL)
205 return;
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500206
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600207 /* If we haven't checked all of the PNG signature bytes, do so now. */
208 if (png_ptr->sig_bytes < 8)
Guy Schalnate5a37791996-06-05 15:50:50 -0500209 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500210 png_size_t num_checked = png_ptr->sig_bytes,
211 num_to_check = 8 - num_checked;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600212
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500213#ifdef PNG_IO_STATE_SUPPORTED
214 png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
215#endif
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500216
Andreas Dilger47a0c421997-05-16 02:46:07 -0500217 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600218 png_ptr->sig_bytes = 8;
219
220 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
221 {
222 if (num_checked < 4 &&
223 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
224 png_error(png_ptr, "Not a PNG file");
225 else
226 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
227 }
Glenn Randers-Pehrson408b4212000-12-18 09:33:57 -0600228 if (num_checked < 3)
229 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
Guy Schalnate5a37791996-06-05 15:50:50 -0500230 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500231
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500232 for (;;)
Guy Schalnat0d580581995-07-20 02:43:20 -0500233 {
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500234 PNG_IHDR;
235 PNG_IDAT;
236 PNG_IEND;
237 PNG_PLTE;
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500238#ifdef PNG_READ_bKGD_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500239 PNG_bKGD;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600240#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500241#ifdef PNG_READ_cHRM_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500242 PNG_cHRM;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600243#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500244#ifdef PNG_READ_gAMA_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500245 PNG_gAMA;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600246#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500247#ifdef PNG_READ_hIST_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500248 PNG_hIST;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600249#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500250#ifdef PNG_READ_iCCP_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500251 PNG_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600252#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500253#ifdef PNG_READ_iTXt_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500254 PNG_iTXt;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600255#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500256#ifdef PNG_READ_oFFs_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500257 PNG_oFFs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600258#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500259#ifdef PNG_READ_pCAL_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500260 PNG_pCAL;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600261#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500262#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500263 PNG_pHYs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600264#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500265#ifdef PNG_READ_sBIT_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500266 PNG_sBIT;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600267#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500268#ifdef PNG_READ_sCAL_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500269 PNG_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600270#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500271#ifdef PNG_READ_sPLT_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500272 PNG_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600273#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500274#ifdef PNG_READ_sRGB_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500275 PNG_sRGB;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600276#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500277#ifdef PNG_READ_tEXt_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500278 PNG_tEXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600279#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500280#ifdef PNG_READ_tIME_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500281 PNG_tIME;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600282#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500283#ifdef PNG_READ_tRNS_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500284 PNG_tRNS;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600285#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500286#ifdef PNG_READ_zTXt_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500287 PNG_zTXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600288#endif
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500289 png_uint_32 length = png_read_chunk_header(png_ptr);
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500290 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500291
292 /* This should be a binary subdivision search or a hash for
293 * matching the chunk name rather than a linear search.
294 */
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500295 if (!png_memcmp(chunk_name, png_IDAT, 4))
296 if (png_ptr->mode & PNG_AFTER_IDAT)
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500297 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
298
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500299 if (!png_memcmp(chunk_name, png_IHDR, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600300 png_handle_IHDR(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500301 else if (!png_memcmp(chunk_name, png_IEND, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600302 png_handle_IEND(png_ptr, info_ptr, length);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600303#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500304 else if (png_handle_as_unknown(png_ptr, chunk_name))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600305 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500306 if (!png_memcmp(chunk_name, png_IDAT, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600307 png_ptr->mode |= PNG_HAVE_IDAT;
308 png_handle_unknown(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500309 if (!png_memcmp(chunk_name, png_PLTE, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600310 png_ptr->mode |= PNG_HAVE_PLTE;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500311 else if (!png_memcmp(chunk_name, png_IDAT, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600312 {
313 if (!(png_ptr->mode & PNG_HAVE_IHDR))
314 png_error(png_ptr, "Missing IHDR before IDAT");
315 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
316 !(png_ptr->mode & PNG_HAVE_PLTE))
317 png_error(png_ptr, "Missing PLTE before IDAT");
318 break;
319 }
320 }
321#endif
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500322 else if (!png_memcmp(chunk_name, png_PLTE, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600323 png_handle_PLTE(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500324 else if (!png_memcmp(chunk_name, png_IDAT, 4))
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500325 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500326 if (!(png_ptr->mode & PNG_HAVE_IHDR))
327 png_error(png_ptr, "Missing IHDR before IDAT");
328 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
329 !(png_ptr->mode & PNG_HAVE_PLTE))
330 png_error(png_ptr, "Missing PLTE before IDAT");
331
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500332 png_ptr->idat_size = length;
Guy Schalnate5a37791996-06-05 15:50:50 -0500333 png_ptr->mode |= PNG_HAVE_IDAT;
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500334 break;
335 }
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500336#ifdef PNG_READ_bKGD_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500337 else if (!png_memcmp(chunk_name, png_bKGD, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500338 png_handle_bKGD(png_ptr, info_ptr, length);
339#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500340#ifdef PNG_READ_cHRM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500341 else if (!png_memcmp(chunk_name, png_cHRM, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500342 png_handle_cHRM(png_ptr, info_ptr, length);
343#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500344#ifdef PNG_READ_gAMA_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500345 else if (!png_memcmp(chunk_name, png_gAMA, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500346 png_handle_gAMA(png_ptr, info_ptr, length);
347#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500348#ifdef PNG_READ_hIST_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500349 else if (!png_memcmp(chunk_name, png_hIST, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500350 png_handle_hIST(png_ptr, info_ptr, length);
351#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500352#ifdef PNG_READ_oFFs_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500353 else if (!png_memcmp(chunk_name, png_oFFs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500354 png_handle_oFFs(png_ptr, info_ptr, length);
355#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500356#ifdef PNG_READ_pCAL_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500357 else if (!png_memcmp(chunk_name, png_pCAL, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500358 png_handle_pCAL(png_ptr, info_ptr, length);
359#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500360#ifdef PNG_READ_sCAL_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500361 else if (!png_memcmp(chunk_name, png_sCAL, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600362 png_handle_sCAL(png_ptr, info_ptr, length);
363#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500364#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500365 else if (!png_memcmp(chunk_name, png_pHYs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500366 png_handle_pHYs(png_ptr, info_ptr, length);
367#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500368#ifdef PNG_READ_sBIT_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500369 else if (!png_memcmp(chunk_name, png_sBIT, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500370 png_handle_sBIT(png_ptr, info_ptr, length);
371#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500372#ifdef PNG_READ_sRGB_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500373 else if (!png_memcmp(chunk_name, png_sRGB, 4))
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600374 png_handle_sRGB(png_ptr, info_ptr, length);
375#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500376#ifdef PNG_READ_iCCP_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500377 else if (!png_memcmp(chunk_name, png_iCCP, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600378 png_handle_iCCP(png_ptr, info_ptr, length);
379#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500380#ifdef PNG_READ_sPLT_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500381 else if (!png_memcmp(chunk_name, png_sPLT, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600382 png_handle_sPLT(png_ptr, info_ptr, length);
383#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500384#ifdef PNG_READ_tEXt_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500385 else if (!png_memcmp(chunk_name, png_tEXt, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500386 png_handle_tEXt(png_ptr, info_ptr, length);
387#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500388#ifdef PNG_READ_tIME_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500389 else if (!png_memcmp(chunk_name, png_tIME, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500390 png_handle_tIME(png_ptr, info_ptr, length);
391#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500392#ifdef PNG_READ_tRNS_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500393 else if (!png_memcmp(chunk_name, png_tRNS, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500394 png_handle_tRNS(png_ptr, info_ptr, length);
395#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500396#ifdef PNG_READ_zTXt_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500397 else if (!png_memcmp(chunk_name, png_zTXt, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500398 png_handle_zTXt(png_ptr, info_ptr, length);
399#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500400#ifdef PNG_READ_iTXt_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500401 else if (!png_memcmp(chunk_name, png_iTXt, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600402 png_handle_iTXt(png_ptr, info_ptr, length);
403#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500404 else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600405 png_handle_unknown(png_ptr, info_ptr, length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500406 }
407}
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500408#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500409
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500410/* Optional call to update the users info_ptr structure */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500411void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600412png_read_update_info(png_structp png_ptr, png_infop info_ptr)
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500413{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500414 png_debug(1, "in png_read_update_info");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500415
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500416 if (png_ptr == NULL)
417 return;
Guy Schalnate5a37791996-06-05 15:50:50 -0500418 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500419 png_read_start_row(png_ptr);
Glenn Randers-Pehrson5e5c1e12000-11-10 12:26:19 -0600420 else
421 png_warning(png_ptr,
422 "Ignoring extra png_read_update_info() call; row buffer not reallocated");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600423 png_read_transform_info(png_ptr, info_ptr);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500424}
425
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500426#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600427/* Initialize palette, background, etc, after transformations
428 * are set, but before any reading takes place. This allows
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500429 * the user to obtain a gamma-corrected palette, for example.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600430 * If the user doesn't call this, we will do it ourselves.
431 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500432void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600433png_start_read_image(png_structp png_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500434{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500435 png_debug(1, "in png_start_read_image");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500436
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500437 if (png_ptr == NULL)
438 return;
Guy Schalnate5a37791996-06-05 15:50:50 -0500439 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500440 png_read_start_row(png_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500441}
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500442#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500443
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500444#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500445void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600446png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
Guy Schalnat0d580581995-07-20 02:43:20 -0500447{
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500448 PNG_IDAT;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500449 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
450 0xff};
451 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
Guy Schalnat0d580581995-07-20 02:43:20 -0500452 int ret;
Glenn Randers-Pehrsonc81bb8a2009-08-15 22:02:26 -0500453
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500454 if (png_ptr == NULL)
455 return;
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500456
Glenn Randers-Pehrson6d75d0c2009-08-22 08:45:09 -0500457 png_debug2(1, "in png_read_row (row %lu, pass %d)",
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500458 (unsigned long) png_ptr->row_number, png_ptr->pass);
Glenn Randers-Pehrson6d75d0c2009-08-22 08:45:09 -0500459
Guy Schalnate5a37791996-06-05 15:50:50 -0500460 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
Guy Schalnat0d580581995-07-20 02:43:20 -0500461 png_read_start_row(png_ptr);
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500462 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
463 {
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500464 /* Check for transforms that have been set but were defined out */
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500465#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
466 if (png_ptr->transformations & PNG_INVERT_MONO)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500467 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500468#endif
469#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
470 if (png_ptr->transformations & PNG_FILLER)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500471 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500472#endif
473#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
474 if (png_ptr->transformations & PNG_PACKSWAP)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500475 png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500476#endif
477#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
478 if (png_ptr->transformations & PNG_PACK)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500479 png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500480#endif
481#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
482 if (png_ptr->transformations & PNG_SHIFT)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500483 png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500484#endif
485#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
486 if (png_ptr->transformations & PNG_BGR)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500487 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500488#endif
489#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
490 if (png_ptr->transformations & PNG_SWAP_BYTES)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500491 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined");
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500492#endif
493 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500494
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500495#ifdef PNG_READ_INTERLACING_SUPPORTED
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500496 /* If interlaced and we do not need a new row, combine row and return */
Guy Schalnat0d580581995-07-20 02:43:20 -0500497 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
498 {
499 switch (png_ptr->pass)
500 {
501 case 0:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600502 if (png_ptr->row_number & 0x07)
Guy Schalnat0d580581995-07-20 02:43:20 -0500503 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500504 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500505 png_combine_row(png_ptr, dsp_row,
506 png_pass_dsp_mask[png_ptr->pass]);
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600507 png_read_finish_row(png_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500508 return;
509 }
510 break;
511 case 1:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600512 if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
Guy Schalnat0d580581995-07-20 02:43:20 -0500513 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500514 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500515 png_combine_row(png_ptr, dsp_row,
516 png_pass_dsp_mask[png_ptr->pass]);
517 png_read_finish_row(png_ptr);
518 return;
519 }
520 break;
521 case 2:
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600522 if ((png_ptr->row_number & 0x07) != 4)
Guy Schalnat0d580581995-07-20 02:43:20 -0500523 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500524 if (dsp_row != NULL && (png_ptr->row_number & 4))
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600525 png_combine_row(png_ptr, dsp_row,
Guy Schalnat0d580581995-07-20 02:43:20 -0500526 png_pass_dsp_mask[png_ptr->pass]);
527 png_read_finish_row(png_ptr);
528 return;
529 }
530 break;
531 case 3:
532 if ((png_ptr->row_number & 3) || png_ptr->width < 3)
533 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500534 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500535 png_combine_row(png_ptr, dsp_row,
536 png_pass_dsp_mask[png_ptr->pass]);
537 png_read_finish_row(png_ptr);
538 return;
539 }
540 break;
541 case 4:
542 if ((png_ptr->row_number & 3) != 2)
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600543 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500544 if (dsp_row != NULL && (png_ptr->row_number & 2))
Guy Schalnat0d580581995-07-20 02:43:20 -0500545 png_combine_row(png_ptr, dsp_row,
546 png_pass_dsp_mask[png_ptr->pass]);
547 png_read_finish_row(png_ptr);
548 return;
549 }
550 break;
551 case 5:
552 if ((png_ptr->row_number & 1) || png_ptr->width < 2)
553 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500554 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500555 png_combine_row(png_ptr, dsp_row,
556 png_pass_dsp_mask[png_ptr->pass]);
557 png_read_finish_row(png_ptr);
558 return;
559 }
560 break;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600561 case 6:
Guy Schalnat0d580581995-07-20 02:43:20 -0500562 if (!(png_ptr->row_number & 1))
563 {
564 png_read_finish_row(png_ptr);
565 return;
566 }
567 break;
568 }
569 }
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500570#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500571
Guy Schalnate5a37791996-06-05 15:50:50 -0500572 if (!(png_ptr->mode & PNG_HAVE_IDAT))
573 png_error(png_ptr, "Invalid attempt to read row data");
Guy Schalnat0d580581995-07-20 02:43:20 -0500574
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600575 png_ptr->zstream.next_out = png_ptr->row_buf;
576 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
Guy Schalnat0d580581995-07-20 02:43:20 -0500577 do
578 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600579 if (!(png_ptr->zstream.avail_in))
Guy Schalnat0d580581995-07-20 02:43:20 -0500580 {
581 while (!png_ptr->idat_size)
582 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600583 png_crc_finish(png_ptr, 0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500584
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500585 png_ptr->idat_size = png_read_chunk_header(png_ptr);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600586 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
587 png_error(png_ptr, "Not enough image data");
Guy Schalnat0d580581995-07-20 02:43:20 -0500588 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600589 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
590 png_ptr->zstream.next_in = png_ptr->zbuf;
Guy Schalnat0d580581995-07-20 02:43:20 -0500591 if (png_ptr->zbuf_size > png_ptr->idat_size)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600592 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500593 png_crc_read(png_ptr, png_ptr->zbuf,
594 (png_size_t)png_ptr->zstream.avail_in);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600595 png_ptr->idat_size -= png_ptr->zstream.avail_in;
Guy Schalnat0d580581995-07-20 02:43:20 -0500596 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600597 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
Guy Schalnat0d580581995-07-20 02:43:20 -0500598 if (ret == Z_STREAM_END)
599 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600600 if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
Guy Schalnat0d580581995-07-20 02:43:20 -0500601 png_ptr->idat_size)
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500602 png_benign_error(png_ptr, "Extra compressed data");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600603 png_ptr->mode |= PNG_AFTER_IDAT;
Guy Schalnate5a37791996-06-05 15:50:50 -0500604 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600605 break;
Guy Schalnat0d580581995-07-20 02:43:20 -0500606 }
607 if (ret != Z_OK)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600608 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
Guy Schalnate5a37791996-06-05 15:50:50 -0500609 "Decompression error");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600610
611 } while (png_ptr->zstream.avail_out);
Guy Schalnat0d580581995-07-20 02:43:20 -0500612
Guy Schalnat0d580581995-07-20 02:43:20 -0500613 png_ptr->row_info.color_type = png_ptr->color_type;
614 png_ptr->row_info.width = png_ptr->iwidth;
615 png_ptr->row_info.channels = png_ptr->channels;
616 png_ptr->row_info.bit_depth = png_ptr->bit_depth;
617 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500618 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
619 png_ptr->row_info.width);
Guy Schalnat0d580581995-07-20 02:43:20 -0500620
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500621 if (png_ptr->row_buf[0])
Guy Schalnate5a37791996-06-05 15:50:50 -0500622 png_read_filter_row(png_ptr, &(png_ptr->row_info),
623 png_ptr->row_buf + 1, png_ptr->prev_row + 1,
624 (int)(png_ptr->row_buf[0]));
Guy Schalnat0d580581995-07-20 02:43:20 -0500625
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500626 png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600627
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500628#ifdef PNG_MNG_FEATURES_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500629 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
Glenn Randers-Pehrson2ad31ae2000-12-15 08:54:42 -0600630 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
631 {
632 /* Intrapixel differencing */
633 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
634 }
635#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500636
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500637
Glenn Randers-Pehrson73b029f2004-11-26 17:28:09 -0600638 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
Guy Schalnat0d580581995-07-20 02:43:20 -0500639 png_do_read_transformations(png_ptr);
640
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500641#ifdef PNG_READ_INTERLACING_SUPPORTED
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500642 /* Blow up interlaced rows to full size */
Guy Schalnat0d580581995-07-20 02:43:20 -0500643 if (png_ptr->interlaced &&
644 (png_ptr->transformations & PNG_INTERLACE))
645 {
646 if (png_ptr->pass < 6)
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500647 /* Old interface (pre-1.0.9):
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500648 * png_do_read_interlace(&(png_ptr->row_info),
649 * png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
650 */
Glenn Randers-Pehrson231e6872001-01-12 15:13:06 -0600651 png_do_read_interlace(png_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500652
Andreas Dilger47a0c421997-05-16 02:46:07 -0500653 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500654 png_combine_row(png_ptr, dsp_row,
655 png_pass_dsp_mask[png_ptr->pass]);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500656 if (row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500657 png_combine_row(png_ptr, row,
658 png_pass_mask[png_ptr->pass]);
659 }
660 else
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500661#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500662 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500663 if (row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500664 png_combine_row(png_ptr, row, 0xff);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500665 if (dsp_row != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500666 png_combine_row(png_ptr, dsp_row, 0xff);
667 }
668 png_read_finish_row(png_ptr);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600669
670 if (png_ptr->read_row_fn != NULL)
671 (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
Guy Schalnat0d580581995-07-20 02:43:20 -0500672}
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500673#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500674
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500675#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500676/* Read one or more rows of image data. If the image is interlaced,
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600677 * and png_set_interlace_handling() has been called, the rows need to
678 * contain the contents of the rows from the previous pass. If the
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500679 * image has alpha or transparency, and png_handle_alpha()[*] has been
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600680 * called, the rows contents must be initialized to the contents of the
681 * screen.
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600682 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600683 * "row" holds the actual image, and pixels are placed in it
684 * as they arrive. If the image is displayed after each pass, it will
685 * appear to "sparkle" in. "display_row" can be used to display a
686 * "chunky" progressive image, with finer detail added as it becomes
687 * available. If you do not want this "chunky" display, you may pass
688 * NULL for display_row. If you do not want the sparkle display, and
689 * you have not called png_handle_alpha(), you may pass NULL for rows.
690 * If you have called png_handle_alpha(), and the image has either an
691 * alpha channel or a transparency chunk, you must provide a buffer for
692 * rows. In this case, you do not have to provide a display_row buffer
693 * also, but you may. If the image is not interlaced, or if you have
694 * not called png_set_interlace_handling(), the display_row buffer will
695 * be ignored, so pass NULL to it.
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500696 *
Glenn Randers-Pehrsonc3d51c12006-03-02 07:23:18 -0600697 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600698 */
Guy Schalnat6d764711995-12-19 03:22:19 -0600699
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500700void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600701png_read_rows(png_structp png_ptr, png_bytepp row,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600702 png_bytepp display_row, png_uint_32 num_rows)
Guy Schalnat0d580581995-07-20 02:43:20 -0500703{
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600704 png_uint_32 i;
705 png_bytepp rp;
706 png_bytepp dp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500707
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500708 png_debug(1, "in png_read_rows");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500709
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500710 if (png_ptr == NULL)
711 return;
Guy Schalnat0f716451995-11-28 11:22:13 -0600712 rp = row;
713 dp = display_row;
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500714 if (rp != NULL && dp != NULL)
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500715 for (i = 0; i < num_rows; i++)
716 {
717 png_bytep rptr = *rp++;
718 png_bytep dptr = *dp++;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600719
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500720 png_read_row(png_ptr, rptr, dptr);
721 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500722 else if (rp != NULL)
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500723 for (i = 0; i < num_rows; i++)
724 {
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500725 png_bytep rptr = *rp;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500726 png_read_row(png_ptr, rptr, NULL);
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500727 rp++;
728 }
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500729 else if (dp != NULL)
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500730 for (i = 0; i < num_rows; i++)
731 {
732 png_bytep dptr = *dp;
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500733 png_read_row(png_ptr, NULL, dptr);
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500734 dp++;
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -0500735 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500736}
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500737#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500738
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500739#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500740/* Read the entire image. If the image has an alpha channel or a tRNS
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500741 * chunk, and you have called png_handle_alpha()[*], you will need to
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600742 * initialize the image to the current image that PNG will be overlaying.
743 * We set the num_rows again here, in case it was incorrectly set in
744 * png_read_start_row() by a call to png_read_update_info() or
745 * png_start_read_image() if png_set_interlace_handling() wasn't called
746 * prior to either of these functions like it should have been. You can
747 * only call this function once. If you desire to have an image for
748 * each pass of a interlaced image, use png_read_rows() instead.
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -0500749 *
Glenn Randers-Pehrsonc3d51c12006-03-02 07:23:18 -0600750 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600751 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500752void PNGAPI
Guy Schalnat6d764711995-12-19 03:22:19 -0600753png_read_image(png_structp png_ptr, png_bytepp image)
Guy Schalnat0d580581995-07-20 02:43:20 -0500754{
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500755 png_uint_32 i, image_height;
Guy Schalnat0d580581995-07-20 02:43:20 -0500756 int pass, j;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600757 png_bytepp rp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500758
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500759 png_debug(1, "in png_read_image");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500760
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500761 if (png_ptr == NULL)
762 return;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500763
764#ifdef PNG_READ_INTERLACING_SUPPORTED
Guy Schalnat0d580581995-07-20 02:43:20 -0500765 pass = png_set_interlace_handling(png_ptr);
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500766#else
767 if (png_ptr->interlaced)
768 png_error(png_ptr,
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500769 "Cannot read interlaced image -- interlace handler disabled");
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500770 pass = 1;
771#endif
772
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500773
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500774 image_height=png_ptr->height;
775 png_ptr->num_rows = image_height; /* Make sure this is set correctly */
Guy Schalnate5a37791996-06-05 15:50:50 -0500776
Guy Schalnat0d580581995-07-20 02:43:20 -0500777 for (j = 0; j < pass; j++)
778 {
779 rp = image;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500780 for (i = 0; i < image_height; i++)
Guy Schalnat0d580581995-07-20 02:43:20 -0500781 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500782 png_read_row(png_ptr, *rp, NULL);
Guy Schalnat0d580581995-07-20 02:43:20 -0500783 rp++;
784 }
785 }
786}
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500787#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500788
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500789#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500790/* Read the end of the PNG file. Will not read past the end of the
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600791 * file, will verify the end is accurate, and will read any comments
792 * or time information at the end of the file, if info is not NULL.
793 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500794void PNGAPI
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600795png_read_end(png_structp png_ptr, png_infop info_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500796{
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500797 png_debug(1, "in png_read_end");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500798
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500799 if (png_ptr == NULL)
800 return;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500801 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
Guy Schalnat0d580581995-07-20 02:43:20 -0500802
803 do
804 {
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500805 PNG_IHDR;
806 PNG_IDAT;
807 PNG_IEND;
808 PNG_PLTE;
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500809#ifdef PNG_READ_bKGD_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500810 PNG_bKGD;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600811#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500812#ifdef PNG_READ_cHRM_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500813 PNG_cHRM;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600814#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500815#ifdef PNG_READ_gAMA_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500816 PNG_gAMA;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600817#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500818#ifdef PNG_READ_hIST_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500819 PNG_hIST;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600820#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500821#ifdef PNG_READ_iCCP_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500822 PNG_iCCP;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600823#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500824#ifdef PNG_READ_iTXt_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500825 PNG_iTXt;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600826#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500827#ifdef PNG_READ_oFFs_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500828 PNG_oFFs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600829#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500830#ifdef PNG_READ_pCAL_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500831 PNG_pCAL;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600832#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500833#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500834 PNG_pHYs;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600835#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500836#ifdef PNG_READ_sBIT_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500837 PNG_sBIT;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600838#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500839#ifdef PNG_READ_sCAL_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500840 PNG_sCAL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600841#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500842#ifdef PNG_READ_sPLT_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500843 PNG_sPLT;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600844#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500845#ifdef PNG_READ_sRGB_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500846 PNG_sRGB;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600847#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500848#ifdef PNG_READ_tEXt_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500849 PNG_tEXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600850#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500851#ifdef PNG_READ_tIME_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500852 PNG_tIME;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600853#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500854#ifdef PNG_READ_tRNS_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500855 PNG_tRNS;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600856#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500857#ifdef PNG_READ_zTXt_SUPPORTED
Glenn Randers-Pehrson9bf60832009-09-20 13:37:50 -0500858 PNG_zTXt;
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -0600859#endif
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500860 png_uint_32 length = png_read_chunk_header(png_ptr);
861 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
Guy Schalnat0d580581995-07-20 02:43:20 -0500862
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500863 if (!png_memcmp(chunk_name, png_IHDR, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600864 png_handle_IHDR(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500865 else if (!png_memcmp(chunk_name, png_IEND, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600866 png_handle_IEND(png_ptr, info_ptr, length);
867#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500868 else if (png_handle_as_unknown(png_ptr, chunk_name))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600869 {
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500870 if (!png_memcmp(chunk_name, png_IDAT, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600871 {
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500872 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500873 png_benign_error(png_ptr, "Too many IDATs found");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600874 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600875 png_handle_unknown(png_ptr, info_ptr, length);
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500876 if (!png_memcmp(chunk_name, png_PLTE, 4))
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600877 png_ptr->mode |= PNG_HAVE_PLTE;
878 }
879#endif
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500880 else if (!png_memcmp(chunk_name, png_IDAT, 4))
Guy Schalnat0d580581995-07-20 02:43:20 -0500881 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500882 /* Zero length IDATs are legal after the last IDAT has been
883 * read, but not after other chunks have been read.
884 */
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500885 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500886 png_benign_error(png_ptr, "Too many IDATs found");
Glenn Randers-Pehrson4accabb2000-04-14 14:20:47 -0500887 png_crc_finish(png_ptr, length);
Guy Schalnat0d580581995-07-20 02:43:20 -0500888 }
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500889 else if (!png_memcmp(chunk_name, png_PLTE, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500890 png_handle_PLTE(png_ptr, info_ptr, length);
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500891#ifdef PNG_READ_bKGD_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500892 else if (!png_memcmp(chunk_name, png_bKGD, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500893 png_handle_bKGD(png_ptr, info_ptr, length);
894#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500895#ifdef PNG_READ_cHRM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500896 else if (!png_memcmp(chunk_name, png_cHRM, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500897 png_handle_cHRM(png_ptr, info_ptr, length);
898#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500899#ifdef PNG_READ_gAMA_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500900 else if (!png_memcmp(chunk_name, png_gAMA, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500901 png_handle_gAMA(png_ptr, info_ptr, length);
902#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500903#ifdef PNG_READ_hIST_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500904 else if (!png_memcmp(chunk_name, png_hIST, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500905 png_handle_hIST(png_ptr, info_ptr, length);
906#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500907#ifdef PNG_READ_oFFs_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500908 else if (!png_memcmp(chunk_name, png_oFFs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500909 png_handle_oFFs(png_ptr, info_ptr, length);
910#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500911#ifdef PNG_READ_pCAL_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500912 else if (!png_memcmp(chunk_name, png_pCAL, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500913 png_handle_pCAL(png_ptr, info_ptr, length);
914#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500915#ifdef PNG_READ_sCAL_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500916 else if (!png_memcmp(chunk_name, png_sCAL, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600917 png_handle_sCAL(png_ptr, info_ptr, length);
918#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500919#ifdef PNG_READ_pHYs_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500920 else if (!png_memcmp(chunk_name, png_pHYs, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500921 png_handle_pHYs(png_ptr, info_ptr, length);
922#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500923#ifdef PNG_READ_sBIT_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500924 else if (!png_memcmp(chunk_name, png_sBIT, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500925 png_handle_sBIT(png_ptr, info_ptr, length);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500926#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500927#ifdef PNG_READ_sRGB_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500928 else if (!png_memcmp(chunk_name, png_sRGB, 4))
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600929 png_handle_sRGB(png_ptr, info_ptr, length);
930#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500931#ifdef PNG_READ_iCCP_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500932 else if (!png_memcmp(chunk_name, png_iCCP, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600933 png_handle_iCCP(png_ptr, info_ptr, length);
934#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500935#ifdef PNG_READ_sPLT_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500936 else if (!png_memcmp(chunk_name, png_sPLT, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600937 png_handle_sPLT(png_ptr, info_ptr, length);
938#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500939#ifdef PNG_READ_tEXt_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500940 else if (!png_memcmp(chunk_name, png_tEXt, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600941 png_handle_tEXt(png_ptr, info_ptr, length);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500942#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500943#ifdef PNG_READ_tIME_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500944 else if (!png_memcmp(chunk_name, png_tIME, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500945 png_handle_tIME(png_ptr, info_ptr, length);
946#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500947#ifdef PNG_READ_tRNS_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500948 else if (!png_memcmp(chunk_name, png_tRNS, 4))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500949 png_handle_tRNS(png_ptr, info_ptr, length);
950#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500951#ifdef PNG_READ_zTXt_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500952 else if (!png_memcmp(chunk_name, png_zTXt, 4))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600953 png_handle_zTXt(png_ptr, info_ptr, length);
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500954#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500955#ifdef PNG_READ_iTXt_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500956 else if (!png_memcmp(chunk_name, png_iTXt, 4))
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600957 png_handle_iTXt(png_ptr, info_ptr, length);
958#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500959 else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600960 png_handle_unknown(png_ptr, info_ptr, length);
961 } while (!(png_ptr->mode & PNG_HAVE_IEND));
Guy Schalnat0d580581995-07-20 02:43:20 -0500962}
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -0500963#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500964
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -0500965/* Free all memory used by the read */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500966void PNGAPI
Guy Schalnate5a37791996-06-05 15:50:50 -0500967png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600968 png_infopp end_info_ptr_ptr)
Guy Schalnate5a37791996-06-05 15:50:50 -0500969{
970 png_structp png_ptr = NULL;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600971 png_infop info_ptr = NULL, end_info_ptr = NULL;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500972#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500973 png_free_ptr free_fn = NULL;
974 png_voidp mem_ptr = NULL;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600975#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500976
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -0500977 png_debug(1, "in png_destroy_read_struct");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -0500978
Andreas Dilger47a0c421997-05-16 02:46:07 -0500979 if (png_ptr_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -0500980 png_ptr = *png_ptr_ptr;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500981 if (png_ptr == NULL)
982 return;
983
984#ifdef PNG_USER_MEM_SUPPORTED
985 free_fn = png_ptr->free_fn;
986 mem_ptr = png_ptr->mem_ptr;
987#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500988
Andreas Dilger47a0c421997-05-16 02:46:07 -0500989 if (info_ptr_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -0500990 info_ptr = *info_ptr_ptr;
991
Andreas Dilger47a0c421997-05-16 02:46:07 -0500992 if (end_info_ptr_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600993 end_info_ptr = *end_info_ptr_ptr;
Guy Schalnate5a37791996-06-05 15:50:50 -0500994
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600995 png_read_destroy(png_ptr, info_ptr, end_info_ptr);
Guy Schalnate5a37791996-06-05 15:50:50 -0500996
Andreas Dilger47a0c421997-05-16 02:46:07 -0500997 if (info_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -0500998 {
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -0500999#ifdef PNG_TEXT_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001000 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001001#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001002
1003#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05001004 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
1005 (png_voidp)mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001006#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001007 png_destroy_struct((png_voidp)info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001008#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -05001009 *info_ptr_ptr = NULL;
Guy Schalnate5a37791996-06-05 15:50:50 -05001010 }
1011
Andreas Dilger47a0c421997-05-16 02:46:07 -05001012 if (end_info_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001013 {
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001014#ifdef PNG_READ_TEXT_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001015 png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001016#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001017#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05001018 png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
1019 (png_voidp)mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001020#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001021 png_destroy_struct((png_voidp)end_info_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001022#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -05001023 *end_info_ptr_ptr = NULL;
Guy Schalnate5a37791996-06-05 15:50:50 -05001024 }
1025
Andreas Dilger47a0c421997-05-16 02:46:07 -05001026 if (png_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -05001027 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001028#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -05001029 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
1030 (png_voidp)mem_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001031#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001032 png_destroy_struct((png_voidp)png_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001033#endif
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -05001034 *png_ptr_ptr = NULL;
Guy Schalnate5a37791996-06-05 15:50:50 -05001035 }
1036}
1037
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -05001038/* Free all memory used by the read (old method) */
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001039void /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001040png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -05001041{
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001042#ifdef PNG_SETJMP_SUPPORTED
Guy Schalnat0d580581995-07-20 02:43:20 -05001043 jmp_buf tmp_jmp;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001044#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001045 png_error_ptr error_fn;
1046 png_error_ptr warning_fn;
1047 png_voidp error_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001048#ifdef PNG_USER_MEM_SUPPORTED
1049 png_free_ptr free_fn;
1050#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001051
Glenn Randers-Pehrson51650b82008-08-05 07:44:42 -05001052 png_debug(1, "in png_read_destroy");
Glenn Randers-Pehrsonda009802009-08-15 13:25:47 -05001053
Andreas Dilger47a0c421997-05-16 02:46:07 -05001054 if (info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001055 png_info_destroy(png_ptr, info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -05001056
Andreas Dilger47a0c421997-05-16 02:46:07 -05001057 if (end_info_ptr != NULL)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001058 png_info_destroy(png_ptr, end_info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -05001059
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001060 png_free(png_ptr, png_ptr->zbuf);
Glenn Randers-Pehrson1b8e5672001-08-25 06:46:06 -05001061 png_free(png_ptr, png_ptr->big_row_buf);
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001062 png_free(png_ptr, png_ptr->prev_row);
Glenn Randers-Pehrsonb3ff9682008-07-21 08:05:57 -05001063 png_free(png_ptr, png_ptr->chunkdata);
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001064#ifdef PNG_READ_DITHER_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001065 png_free(png_ptr, png_ptr->palette_lookup);
1066 png_free(png_ptr, png_ptr->dither_index);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001067#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001068#ifdef PNG_READ_GAMMA_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001069 png_free(png_ptr, png_ptr->gamma_table);
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001070#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001071#ifdef PNG_READ_BACKGROUND_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001072 png_free(png_ptr, png_ptr->gamma_from_1);
1073 png_free(png_ptr, png_ptr->gamma_to_1);
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001074#endif
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001075 if (png_ptr->free_me & PNG_FREE_PLTE)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001076 png_zfree(png_ptr, png_ptr->palette);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001077 png_ptr->free_me &= ~PNG_FREE_PLTE;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001078#if defined(PNG_tRNS_SUPPORTED) || \
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001079 defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001080 if (png_ptr->free_me & PNG_FREE_TRNS)
Glenn Randers-Pehrson6abea752009-08-08 16:52:06 -05001081 png_free(png_ptr, png_ptr->trans_alpha);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001082 png_ptr->free_me &= ~PNG_FREE_TRNS;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001083#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001084#ifdef PNG_READ_hIST_SUPPORTED
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001085 if (png_ptr->free_me & PNG_FREE_HIST)
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001086 png_free(png_ptr, png_ptr->hist);
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001087 png_ptr->free_me &= ~PNG_FREE_HIST;
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001088#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001089#ifdef PNG_READ_GAMMA_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -05001090 if (png_ptr->gamma_16_table != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -05001091 {
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001092 int i;
1093 int istop = (1 << (8 - png_ptr->gamma_shift));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001094 for (i = 0; i < istop; i++)
Guy Schalnat0d580581995-07-20 02:43:20 -05001095 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001096 png_free(png_ptr, png_ptr->gamma_16_table[i]);
Guy Schalnat0d580581995-07-20 02:43:20 -05001097 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001098 png_free(png_ptr, png_ptr->gamma_16_table);
Guy Schalnat0d580581995-07-20 02:43:20 -05001099 }
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001100#ifdef PNG_READ_BACKGROUND_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -05001101 if (png_ptr->gamma_16_from_1 != NULL)
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001102 {
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001103 int i;
1104 int istop = (1 << (8 - png_ptr->gamma_shift));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001105 for (i = 0; i < istop; i++)
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001106 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001107 png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001108 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001109 png_free(png_ptr, png_ptr->gamma_16_from_1);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001110 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001111 if (png_ptr->gamma_16_to_1 != NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -05001112 {
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001113 int i;
1114 int istop = (1 << (8 - png_ptr->gamma_shift));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001115 for (i = 0; i < istop; i++)
Guy Schalnat0d580581995-07-20 02:43:20 -05001116 {
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001117 png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
Guy Schalnat0d580581995-07-20 02:43:20 -05001118 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001119 png_free(png_ptr, png_ptr->gamma_16_to_1);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001120 }
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001121#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001122#endif
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001123#ifdef PNG_TIME_RFC1123_SUPPORTED
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001124 png_free(png_ptr, png_ptr->time_buffer);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001125#endif
Guy Schalnat0f716451995-11-28 11:22:13 -06001126
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001127 inflateEnd(&png_ptr->zstream);
Guy Schalnat6d764711995-12-19 03:22:19 -06001128#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001129 png_free(png_ptr, png_ptr->save_buffer);
Guy Schalnat6d764711995-12-19 03:22:19 -06001130#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001131
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -05001132#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1133#ifdef PNG_TEXT_SUPPORTED
1134 png_free(png_ptr, png_ptr->current_text);
1135#endif /* PNG_TEXT_SUPPORTED */
1136#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1137
Guy Schalnate5a37791996-06-05 15:50:50 -05001138 /* Save the important info out of the png_struct, in case it is
1139 * being used again.
1140 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001141#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001142 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001143#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001144
1145 error_fn = png_ptr->error_fn;
1146 warning_fn = png_ptr->warning_fn;
1147 error_ptr = png_ptr->error_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001148#ifdef PNG_USER_MEM_SUPPORTED
1149 free_fn = png_ptr->free_fn;
1150#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001151
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001152 png_memset(png_ptr, 0, png_sizeof(png_struct));
Guy Schalnate5a37791996-06-05 15:50:50 -05001153
1154 png_ptr->error_fn = error_fn;
1155 png_ptr->warning_fn = warning_fn;
1156 png_ptr->error_ptr = error_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001157#ifdef PNG_USER_MEM_SUPPORTED
1158 png_ptr->free_fn = free_fn;
1159#endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001160
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001161#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001162 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001163#endif
1164
Guy Schalnat0d580581995-07-20 02:43:20 -05001165}
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001166
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001167void PNGAPI
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001168png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
1169{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001170 if (png_ptr == NULL)
1171 return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001172 png_ptr->read_row_fn = read_row_fn;
1173}
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001174
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -05001175
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -05001176#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001177#ifdef PNG_INFO_IMAGE_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -05001178void PNGAPI
1179png_read_png(png_structp png_ptr, png_infop info_ptr,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001180 int transforms,
1181 voidp params)
1182{
1183 int row;
1184
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001185 if (png_ptr == NULL)
1186 return;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001187
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001188 /* png_read_info() gives us all of the information from the
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001189 * PNG file before the first IDAT (image data chunk).
1190 */
1191 png_read_info(png_ptr, info_ptr);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001192 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
1193 png_error(png_ptr, "Image is too high to process with png_read_png()");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001194
1195 /* -------------- image transformations start here ------------------- */
1196
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001197#ifdef PNG_READ_16_TO_8_SUPPORTED
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001198 /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001199 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001200 if (transforms & PNG_TRANSFORM_STRIP_16)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001201 png_set_strip_16(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001202#endif
1203
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001204#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001205 /* Strip alpha bytes from the input data without combining with
1206 * the background (not recommended).
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001207 */
1208 if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001209 png_set_strip_alpha(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001210#endif
1211
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001212#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001213 /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001214 * byte into separate bytes (useful for paletted and grayscale images).
1215 */
1216 if (transforms & PNG_TRANSFORM_PACKING)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001217 png_set_packing(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001218#endif
1219
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001220#ifdef PNG_READ_PACKSWAP_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001221 /* Change the order of packed pixels to least significant bit first
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001222 * (not useful if you are using png_set_packing).
1223 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001224 if (transforms & PNG_TRANSFORM_PACKSWAP)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001225 png_set_packswap(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001226#endif
1227
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001228#ifdef PNG_READ_EXPAND_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001229 /* Expand paletted colors into true RGB triplets
1230 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
1231 * Expand paletted or RGB images with transparency to full alpha
1232 * channels so the data will be available as RGBA quartets.
1233 */
1234 if (transforms & PNG_TRANSFORM_EXPAND)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001235 if ((png_ptr->bit_depth < 8) ||
1236 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
1237 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001238 png_set_expand(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001239#endif
1240
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001241 /* We don't handle background color or gamma transformation or dithering.
1242 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001243
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001244#ifdef PNG_READ_INVERT_SUPPORTED
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -05001245 /* Invert monochrome files to have 0 as white and 1 as black
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001246 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001247 if (transforms & PNG_TRANSFORM_INVERT_MONO)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001248 png_set_invert_mono(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001249#endif
1250
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001251#ifdef PNG_READ_SHIFT_SUPPORTED
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001252 /* If you want to shift the pixel values from the range [0,255] or
1253 * [0,65535] to the original [0,7] or [0,31], or whatever range the
1254 * colors were originally in:
1255 */
1256 if ((transforms & PNG_TRANSFORM_SHIFT)
1257 && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
1258 {
1259 png_color_8p sig_bit;
1260
1261 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1262 png_set_shift(png_ptr, sig_bit);
1263 }
1264#endif
1265
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001266#ifdef PNG_READ_BGR_SUPPORTED
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -05001267 /* Flip the RGB pixels to BGR (or RGBA to BGRA)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001268 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001269 if (transforms & PNG_TRANSFORM_BGR)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001270 png_set_bgr(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001271#endif
1272
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001273#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -05001274 /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001275 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001276 if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1277 png_set_swap_alpha(png_ptr);
1278#endif
1279
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001280#ifdef PNG_READ_SWAP_SUPPORTED
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -05001281 /* Swap bytes of 16 bit files to least significant byte first
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -05001282 */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001283 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001284 png_set_swap(png_ptr);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001285#endif
1286
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001287#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
Glenn Randers-Pehrson6878eb62009-06-29 16:45:53 -05001288 /* Invert the alpha channel from opacity to transparency
1289 */
1290 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1291 png_set_invert_alpha(png_ptr);
1292#endif
1293
Glenn Randers-Pehrsone26c0952009-09-23 11:22:08 -05001294#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05001295 /* Expand grayscale image to RGB
1296 */
1297 if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
Glenn Randers-Pehrson8cb69f02009-07-19 19:24:58 -05001298 png_set_gray_to_rgb(png_ptr);
Glenn Randers-Pehrson99708d52009-06-29 17:30:00 -05001299#endif
1300
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001301 /* We don't handle adding filler bytes */
1302
1303 /* Optional call to gamma correct and add the background to the palette
1304 * and update info structure. REQUIRED if you are expecting libpng to
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001305 * update the palette for you (i.e., you selected such a transform above).
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001306 */
1307 png_read_update_info(png_ptr, info_ptr);
1308
1309 /* -------------- image transformations end here ------------------- */
1310
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001311 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001312 if (info_ptr->row_pointers == NULL)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001313 {
Glenn Randers-Pehrsond9f21ee2009-08-31 10:52:38 -05001314 png_uint_32 iptr;
1315
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -06001316 info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
1317 info_ptr->height * png_sizeof(png_bytep));
Glenn Randers-Pehrsond9f21ee2009-08-31 10:52:38 -05001318 for (iptr=0; iptr<info_ptr->height; iptr++)
1319 info_ptr->row_pointers[iptr] = NULL;
1320
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001321 info_ptr->free_me |= PNG_FREE_ROWS;
Glenn Randers-Pehrsond9f21ee2009-08-31 10:52:38 -05001322
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001323 for (row = 0; row < (int)info_ptr->height; row++)
Glenn Randers-Pehrson3097f612001-05-07 14:52:45 -05001324 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001325 png_get_rowbytes(png_ptr, info_ptr));
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001326 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001327
1328 png_read_image(png_ptr, info_ptr->row_pointers);
1329 info_ptr->valid |= PNG_INFO_IDAT;
1330
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -05001331 /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001332 png_read_end(png_ptr, info_ptr);
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001333
Glenn Randers-Pehrsond8eb62f2009-05-30 20:19:20 -05001334 transforms = transforms; /* Quiet compiler warnings */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -05001335 params = params;
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -06001336
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001337}
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001338#endif /* PNG_INFO_IMAGE_SUPPORTED */
Glenn Randers-Pehrsondbd40142009-08-31 08:42:02 -05001339#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -06001340#endif /* PNG_READ_SUPPORTED */