Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 2 | /* pngread.c - read a PNG file |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | bc6726b | 2011-11-02 22:43:00 -0500 | [diff] [blame^] | 4 | * Last changed in libpng 1.5.6 [November 3, 2011] |
Glenn Randers-Pehrson | 64b863c | 2011-01-04 09:57:06 -0600 | [diff] [blame] | 5 | * Copyright (c) 1998-2011 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | d436672 | 2000-06-04 14:29:29 -0500 | [diff] [blame] | 6 | * (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-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 8 | * |
Glenn Randers-Pehrson | bfbf865 | 2009-06-26 21:46:52 -0500 | [diff] [blame] | 9 | * This code is released under the libpng license. |
Glenn Randers-Pehrson | c332bbc | 2009-06-25 13:43:50 -0500 | [diff] [blame] | 10 | * For conditions of distribution and use, see the disclaimer |
Glenn Randers-Pehrson | 037023b | 2009-06-24 10:27:36 -0500 | [diff] [blame] | 11 | * and license in png.h |
Glenn Randers-Pehrson | 3e61d79 | 2009-06-24 09:31:28 -0500 | [diff] [blame] | 12 | * |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 13 | * This file contains routines that an application calls directly to |
| 14 | * read a PNG file or stream. |
| 15 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 16 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 17 | #include "pngpriv.h" |
Glenn Randers-Pehrson | 9c3ab68 | 2006-02-20 22:09:05 -0600 | [diff] [blame] | 18 | |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 19 | #ifdef PNG_READ_SUPPORTED |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 20 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 21 | /* Create a PNG structure for reading, and allocate any memory needed. */ |
Glenn Randers-Pehrson | 77396b6 | 2010-08-02 08:00:10 -0500 | [diff] [blame] | 22 | PNG_FUNCTION(png_structp,PNGAPI |
| 23 | png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, |
| 24 | png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 25 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 26 | |
| 27 | #ifdef PNG_USER_MEM_SUPPORTED |
| 28 | return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 29 | warn_fn, NULL, NULL, NULL)); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 32 | /* Alternate create PNG structure for reading, and allocate any memory |
| 33 | * needed. |
| 34 | */ |
Glenn Randers-Pehrson | 77396b6 | 2010-08-02 08:00:10 -0500 | [diff] [blame] | 35 | PNG_FUNCTION(png_structp,PNGAPI |
| 36 | png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 37 | png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
Glenn Randers-Pehrson | 77396b6 | 2010-08-02 08:00:10 -0500 | [diff] [blame] | 38 | png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 39 | { |
| 40 | #endif /* PNG_USER_MEM_SUPPORTED */ |
| 41 | |
Glenn Randers-Pehrson | 79134c6 | 2009-02-14 10:32:18 -0600 | [diff] [blame] | 42 | #ifdef PNG_SETJMP_SUPPORTED |
| 43 | volatile |
| 44 | #endif |
| 45 | png_structp png_ptr; |
Glenn Randers-Pehrson | 62ca98e | 2009-12-20 15:14:57 -0600 | [diff] [blame] | 46 | volatile int png_cleanup_needed = 0; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 47 | |
| 48 | #ifdef PNG_SETJMP_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 49 | #ifdef USE_FAR_KEYWORD |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 50 | jmp_buf tmp_jmpbuf; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 51 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 52 | #endif |
| 53 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 54 | png_debug(1, "in png_create_read_struct"); |
Glenn Randers-Pehrson | da00980 | 2009-08-15 13:25:47 -0500 | [diff] [blame] | 55 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 56 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 57 | png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 58 | malloc_fn, mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 59 | #else |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 60 | png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 61 | #endif |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 62 | if (png_ptr == NULL) |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 63 | return (NULL); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 64 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 65 | /* Added at libpng-1.2.6 */ |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 66 | #ifdef PNG_USER_LIMITS_SUPPORTED |
Glenn Randers-Pehrson | ef29a5e | 2009-10-31 19:37:05 -0500 | [diff] [blame] | 67 | png_ptr->user_width_max = PNG_USER_WIDTH_MAX; |
| 68 | png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 69 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 70 | # ifdef PNG_USER_CHUNK_CACHE_MAX |
| 71 | /* Added at libpng-1.2.43 and 1.4.0 */ |
Glenn Randers-Pehrson | ef29a5e | 2009-10-31 19:37:05 -0500 | [diff] [blame] | 72 | png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 73 | # endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 74 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 75 | # ifdef PNG_SET_USER_CHUNK_MALLOC_MAX |
| 76 | /* Added at libpng-1.2.43 and 1.4.1 */ |
| 77 | png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; |
| 78 | # endif |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 79 | #endif |
| 80 | |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 81 | #ifdef PNG_SETJMP_SUPPORTED |
| 82 | /* Applications that neglect to set up their own setjmp() and then |
| 83 | encounter a png_error() will longjmp here. Since the jmpbuf is |
| 84 | then meaningless we abort instead of returning. */ |
| 85 | #ifdef USE_FAR_KEYWORD |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 86 | if (setjmp(tmp_jmpbuf)) |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 87 | #else |
Glenn Randers-Pehrson | f4ea224 | 2009-11-20 21:38:24 -0600 | [diff] [blame] | 88 | if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 89 | #endif |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 90 | PNG_ABORT(); |
Glenn Randers-Pehrson | f4ea224 | 2009-11-20 21:38:24 -0600 | [diff] [blame] | 91 | #ifdef USE_FAR_KEYWORD |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 92 | png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf)); |
Glenn Randers-Pehrson | f4ea224 | 2009-11-20 21:38:24 -0600 | [diff] [blame] | 93 | #endif |
Glenn Randers-Pehrson | a2567be | 2009-10-19 20:31:31 -0500 | [diff] [blame] | 94 | #endif /* PNG_SETJMP_SUPPORTED */ |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 95 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 96 | #ifdef PNG_USER_MEM_SUPPORTED |
| 97 | png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 98 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 99 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 100 | png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 101 | |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 102 | /* Call the general version checker (shared with read and write code): */ |
| 103 | if (!png_user_version_check(png_ptr, user_png_ver)) |
| 104 | png_cleanup_needed = 1; |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 105 | |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 106 | if (!png_cleanup_needed) |
| 107 | { |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 108 | /* Initialize zbuf - compression buffer */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 109 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 110 | png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size); |
| 111 | |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 112 | if (png_ptr->zbuf == NULL) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 113 | png_cleanup_needed = 1; |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 114 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 115 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 116 | png_ptr->zstream.zalloc = png_zalloc; |
| 117 | png_ptr->zstream.zfree = png_zfree; |
| 118 | png_ptr->zstream.opaque = (voidpf)png_ptr; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 119 | |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 120 | if (!png_cleanup_needed) |
| 121 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 122 | switch (inflateInit(&png_ptr->zstream)) |
| 123 | { |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 124 | case Z_OK: |
| 125 | break; /* Do nothing */ |
| 126 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 127 | case Z_MEM_ERROR: |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 128 | png_warning(png_ptr, "zlib memory error"); |
| 129 | png_cleanup_needed = 1; |
| 130 | break; |
| 131 | |
| 132 | case Z_STREAM_ERROR: |
| 133 | png_warning(png_ptr, "zlib stream error"); |
| 134 | png_cleanup_needed = 1; |
| 135 | break; |
| 136 | |
| 137 | case Z_VERSION_ERROR: |
| 138 | png_warning(png_ptr, "zlib version error"); |
| 139 | png_cleanup_needed = 1; |
| 140 | break; |
| 141 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 142 | default: png_warning(png_ptr, "Unknown zlib error"); |
| 143 | png_cleanup_needed = 1; |
| 144 | } |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | if (png_cleanup_needed) |
| 148 | { |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 149 | /* Clean up PNG structure and deallocate any memory. */ |
| 150 | png_free(png_ptr, png_ptr->zbuf); |
| 151 | png_ptr->zbuf = NULL; |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 152 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 153 | png_destroy_struct_2((png_voidp)png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 154 | (png_free_ptr)free_fn, (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 155 | #else |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 156 | png_destroy_struct((png_voidp)png_ptr); |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 157 | #endif |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 158 | return (NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 159 | } |
| 160 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 161 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 162 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 163 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 164 | png_set_read_fn(png_ptr, NULL, NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 165 | |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 166 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 167 | return (png_ptr); |
| 168 | } |
| 169 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 170 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 171 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 172 | /* Read the information before the actual image data. This has been |
Glenn Randers-Pehrson | f9f2fe0 | 1998-03-15 18:20:23 -0600 | [diff] [blame] | 173 | * changed in v0.90 to allow reading a file that already has the magic |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 174 | * bytes read from the stream. You can tell libpng how many bytes have |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 175 | * been read from the beginning of the stream (up to the maximum of 8) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 176 | * via png_set_sig_bytes(), and we will only check the remaining bytes |
| 177 | * here. The application can then have access to the signature bytes we |
| 178 | * read if it is determined that this isn't a valid PNG file. |
| 179 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 180 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 181 | png_read_info(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 182 | { |
Glenn Randers-Pehrson | c81bb8a | 2009-08-15 22:02:26 -0500 | [diff] [blame] | 183 | png_debug(1, "in png_read_info"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 184 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 185 | if (png_ptr == NULL || info_ptr == NULL) |
| 186 | return; |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 187 | |
Glenn Randers-Pehrson | a581556 | 2010-11-20 21:48:29 -0600 | [diff] [blame] | 188 | /* Read and check the PNG file signature. */ |
| 189 | png_read_sig(png_ptr, info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 190 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 191 | for (;;) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 192 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 193 | png_uint_32 length = png_read_chunk_header(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 194 | png_uint_32 chunk_name = png_ptr->chunk_name; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 195 | |
| 196 | /* This should be a binary subdivision search or a hash for |
| 197 | * matching the chunk name rather than a linear search. |
| 198 | */ |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 199 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 200 | if (png_ptr->mode & PNG_AFTER_IDAT) |
| 201 | png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 202 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 203 | if (chunk_name == png_IHDR) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 204 | png_handle_IHDR(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 205 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 206 | else if (chunk_name == png_IEND) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 207 | png_handle_IEND(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 208 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 209 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 210 | else if (png_chunk_unknown_handling(png_ptr, chunk_name) != |
| 211 | PNG_HANDLE_CHUNK_AS_DEFAULT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 212 | { |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 213 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 214 | png_ptr->mode |= PNG_HAVE_IDAT; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 215 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 216 | png_handle_unknown(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 217 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 218 | if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 219 | png_ptr->mode |= PNG_HAVE_PLTE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 220 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 221 | else if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 222 | { |
| 223 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 224 | png_error(png_ptr, "Missing IHDR before IDAT"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 225 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 226 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 227 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 228 | png_error(png_ptr, "Missing PLTE before IDAT"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 229 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | } |
| 233 | #endif |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 234 | else if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 235 | png_handle_PLTE(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 236 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 237 | else if (chunk_name == png_IDAT) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 238 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 239 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 240 | png_error(png_ptr, "Missing IHDR before IDAT"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 241 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 242 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 243 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 244 | png_error(png_ptr, "Missing PLTE before IDAT"); |
| 245 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 246 | png_ptr->idat_size = length; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 247 | png_ptr->mode |= PNG_HAVE_IDAT; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 248 | break; |
| 249 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 250 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 251 | #ifdef PNG_READ_bKGD_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 252 | else if (chunk_name == png_bKGD) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 253 | png_handle_bKGD(png_ptr, info_ptr, length); |
| 254 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 255 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 256 | #ifdef PNG_READ_cHRM_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 257 | else if (chunk_name == png_cHRM) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 258 | png_handle_cHRM(png_ptr, info_ptr, length); |
| 259 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 260 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 261 | #ifdef PNG_READ_gAMA_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 262 | else if (chunk_name == png_gAMA) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 263 | png_handle_gAMA(png_ptr, info_ptr, length); |
| 264 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 265 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 266 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 267 | else if (chunk_name == png_hIST) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 268 | png_handle_hIST(png_ptr, info_ptr, length); |
| 269 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 270 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 271 | #ifdef PNG_READ_oFFs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 272 | else if (chunk_name == png_oFFs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 273 | png_handle_oFFs(png_ptr, info_ptr, length); |
| 274 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 275 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 276 | #ifdef PNG_READ_pCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 277 | else if (chunk_name == png_pCAL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 278 | png_handle_pCAL(png_ptr, info_ptr, length); |
| 279 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 280 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 281 | #ifdef PNG_READ_sCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 282 | else if (chunk_name == png_sCAL) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 283 | png_handle_sCAL(png_ptr, info_ptr, length); |
| 284 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 285 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 286 | #ifdef PNG_READ_pHYs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 287 | else if (chunk_name == png_pHYs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 288 | png_handle_pHYs(png_ptr, info_ptr, length); |
| 289 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 290 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 291 | #ifdef PNG_READ_sBIT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 292 | else if (chunk_name == png_sBIT) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 293 | png_handle_sBIT(png_ptr, info_ptr, length); |
| 294 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 295 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 296 | #ifdef PNG_READ_sRGB_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 297 | else if (chunk_name == png_sRGB) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 298 | png_handle_sRGB(png_ptr, info_ptr, length); |
| 299 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 300 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 301 | #ifdef PNG_READ_iCCP_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 302 | else if (chunk_name == png_iCCP) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 303 | png_handle_iCCP(png_ptr, info_ptr, length); |
| 304 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 305 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 306 | #ifdef PNG_READ_sPLT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 307 | else if (chunk_name == png_sPLT) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 308 | png_handle_sPLT(png_ptr, info_ptr, length); |
| 309 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 310 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 311 | #ifdef PNG_READ_tEXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 312 | else if (chunk_name == png_tEXt) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 313 | png_handle_tEXt(png_ptr, info_ptr, length); |
| 314 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 315 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 316 | #ifdef PNG_READ_tIME_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 317 | else if (chunk_name == png_tIME) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 318 | png_handle_tIME(png_ptr, info_ptr, length); |
| 319 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 320 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 321 | #ifdef PNG_READ_tRNS_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 322 | else if (chunk_name == png_tRNS) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 323 | png_handle_tRNS(png_ptr, info_ptr, length); |
| 324 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 325 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 326 | #ifdef PNG_READ_zTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 327 | else if (chunk_name == png_zTXt) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 328 | png_handle_zTXt(png_ptr, info_ptr, length); |
| 329 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 330 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 331 | #ifdef PNG_READ_iTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 332 | else if (chunk_name == png_iTXt) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 333 | png_handle_iTXt(png_ptr, info_ptr, length); |
| 334 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 335 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 336 | else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 337 | png_handle_unknown(png_ptr, info_ptr, length); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 338 | } |
| 339 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 340 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 341 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 342 | /* Optional call to update the users info_ptr structure */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 343 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 344 | png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 345 | { |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 346 | png_debug(1, "in png_read_update_info"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 347 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 348 | if (png_ptr == NULL) |
| 349 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 350 | |
Glenn Randers-Pehrson | 3dbfd30 | 2011-10-13 17:24:36 -0500 | [diff] [blame] | 351 | png_read_start_row(png_ptr); |
Glenn Randers-Pehrson | 4cfdb3c | 2009-11-26 11:49:37 -0600 | [diff] [blame] | 352 | |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 353 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 354 | png_read_transform_info(png_ptr, info_ptr); |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 355 | #else |
| 356 | PNG_UNUSED(info_ptr) |
| 357 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 358 | } |
| 359 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 360 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 361 | /* Initialize palette, background, etc, after transformations |
| 362 | * are set, but before any reading takes place. This allows |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 363 | * the user to obtain a gamma-corrected palette, for example. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 364 | * If the user doesn't call this, we will do it ourselves. |
| 365 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 366 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 367 | png_start_read_image(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 368 | { |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 369 | png_debug(1, "in png_start_read_image"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 370 | |
Glenn Randers-Pehrson | 3dbfd30 | 2011-10-13 17:24:36 -0500 | [diff] [blame] | 371 | if (png_ptr != NULL) |
| 372 | png_read_start_row(png_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 373 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 374 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 375 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 376 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 377 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 378 | png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 379 | { |
| 380 | int ret; |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 381 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 382 | png_row_info row_info; |
| 383 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 384 | if (png_ptr == NULL) |
| 385 | return; |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 386 | |
Glenn Randers-Pehrson | 6d75d0c | 2009-08-22 08:45:09 -0500 | [diff] [blame] | 387 | png_debug2(1, "in png_read_row (row %lu, pass %d)", |
Glenn Randers-Pehrson | d233287 | 2010-10-12 19:19:28 -0500 | [diff] [blame] | 388 | (unsigned long)png_ptr->row_number, png_ptr->pass); |
Glenn Randers-Pehrson | 6d75d0c | 2009-08-22 08:45:09 -0500 | [diff] [blame] | 389 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 390 | /* png_read_start_row sets the information (in particular iwidth) for this |
| 391 | * interlace pass. |
| 392 | */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 393 | if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 394 | png_read_start_row(png_ptr); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 395 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 396 | /* 1.5.6: row_info moved out of png_struct to a local here. */ |
| 397 | row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ |
| 398 | row_info.color_type = png_ptr->color_type; |
| 399 | row_info.bit_depth = png_ptr->bit_depth; |
| 400 | row_info.channels = png_ptr->channels; |
| 401 | row_info.pixel_depth = png_ptr->pixel_depth; |
| 402 | row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); |
| 403 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 404 | if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
| 405 | { |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 406 | /* Check for transforms that have been set but were defined out */ |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 407 | #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
| 408 | if (png_ptr->transformations & PNG_INVERT_MONO) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 409 | png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 410 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 411 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 412 | #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) |
| 413 | if (png_ptr->transformations & PNG_FILLER) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 414 | png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 415 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 416 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 417 | #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ |
| 418 | !defined(PNG_READ_PACKSWAP_SUPPORTED) |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 419 | if (png_ptr->transformations & PNG_PACKSWAP) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 420 | png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 421 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 422 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 423 | #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) |
| 424 | if (png_ptr->transformations & PNG_PACK) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 425 | png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 426 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 427 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 428 | #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) |
| 429 | if (png_ptr->transformations & PNG_SHIFT) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 430 | png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 431 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 432 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 433 | #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) |
| 434 | if (png_ptr->transformations & PNG_BGR) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 435 | png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 436 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 437 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 438 | #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) |
| 439 | if (png_ptr->transformations & PNG_SWAP_BYTES) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 440 | png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 441 | #endif |
| 442 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 443 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 444 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 445 | /* If interlaced and we do not need a new row, combine row and return. |
| 446 | * Notice that the pixels we have from previous rows have been transformed |
| 447 | * already; we can only combine like with like (transformed or |
| 448 | * untransformed) and, because of the libpng API for interlaced images, this |
| 449 | * means we must transform before de-interlacing. |
| 450 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 451 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 452 | { |
| 453 | switch (png_ptr->pass) |
| 454 | { |
| 455 | case 0: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 456 | if (png_ptr->row_number & 0x07) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 457 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 458 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 459 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 460 | png_read_finish_row(png_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 461 | return; |
| 462 | } |
| 463 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 464 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 465 | case 1: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 466 | if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 467 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 468 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 469 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 470 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 471 | png_read_finish_row(png_ptr); |
| 472 | return; |
| 473 | } |
| 474 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 475 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 476 | case 2: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 477 | if ((png_ptr->row_number & 0x07) != 4) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 478 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 479 | if (dsp_row != NULL && (png_ptr->row_number & 4)) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 480 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 481 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 482 | png_read_finish_row(png_ptr); |
| 483 | return; |
| 484 | } |
| 485 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 486 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 487 | case 3: |
| 488 | if ((png_ptr->row_number & 3) || png_ptr->width < 3) |
| 489 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 490 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 491 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 492 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 493 | png_read_finish_row(png_ptr); |
| 494 | return; |
| 495 | } |
| 496 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 497 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 498 | case 4: |
| 499 | if ((png_ptr->row_number & 3) != 2) |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 500 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 501 | if (dsp_row != NULL && (png_ptr->row_number & 2)) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 502 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 503 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 504 | png_read_finish_row(png_ptr); |
| 505 | return; |
| 506 | } |
| 507 | break; |
| 508 | case 5: |
| 509 | if ((png_ptr->row_number & 1) || png_ptr->width < 2) |
| 510 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 511 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 512 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 513 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 514 | png_read_finish_row(png_ptr); |
| 515 | return; |
| 516 | } |
| 517 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 518 | |
Glenn Randers-Pehrson | b3edc73 | 2010-11-21 14:06:41 -0600 | [diff] [blame] | 519 | default: |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 520 | case 6: |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 521 | if (!(png_ptr->row_number & 1)) |
| 522 | { |
| 523 | png_read_finish_row(png_ptr); |
| 524 | return; |
| 525 | } |
| 526 | break; |
| 527 | } |
| 528 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 529 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 530 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 531 | if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
| 532 | png_error(png_ptr, "Invalid attempt to read row data"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 533 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 534 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 535 | png_ptr->zstream.avail_out = |
| 536 | (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, |
| 537 | png_ptr->iwidth) + 1); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 538 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 539 | do |
| 540 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 541 | if (!(png_ptr->zstream.avail_in)) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 542 | { |
| 543 | while (!png_ptr->idat_size) |
| 544 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 545 | png_crc_finish(png_ptr, 0); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 546 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 547 | png_ptr->idat_size = png_read_chunk_header(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 548 | if (png_ptr->chunk_name != png_IDAT) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 549 | png_error(png_ptr, "Not enough image data"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 550 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 551 | png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; |
| 552 | png_ptr->zstream.next_in = png_ptr->zbuf; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 553 | if (png_ptr->zbuf_size > png_ptr->idat_size) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 554 | png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 555 | png_crc_read(png_ptr, png_ptr->zbuf, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 556 | (png_size_t)png_ptr->zstream.avail_in); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 557 | png_ptr->idat_size -= png_ptr->zstream.avail_in; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 558 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 559 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 560 | ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 561 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 562 | if (ret == Z_STREAM_END) |
| 563 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 564 | if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 565 | png_ptr->idat_size) |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 566 | png_benign_error(png_ptr, "Extra compressed data"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 567 | png_ptr->mode |= PNG_AFTER_IDAT; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 568 | png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 569 | break; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 570 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 571 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 572 | if (ret != Z_OK) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 573 | png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 574 | "Decompression error"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 575 | |
| 576 | } while (png_ptr->zstream.avail_out); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 577 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 578 | if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) |
| 579 | { |
| 580 | if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) |
| 581 | png_read_filter_row(&row_info, png_ptr->row_buf + 1, |
| 582 | png_ptr->prev_row + 1, png_ptr->row_buf[0]); |
| 583 | else |
| 584 | png_error(png_ptr, "bad adaptive filter value"); |
| 585 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 586 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 587 | /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before |
| 588 | * 1.5.6, while the buffer really is this big in current versions of libpng |
| 589 | * it may not be in the future, so this was changed just to copy the |
| 590 | * interlaced count: |
| 591 | */ |
| 592 | png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); |
Glenn Randers-Pehrson | e647462 | 2006-03-04 16:50:47 -0600 | [diff] [blame] | 593 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 594 | #ifdef PNG_MNG_FEATURES_SUPPORTED |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 595 | if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 596 | (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
Glenn Randers-Pehrson | 2ad31ae | 2000-12-15 08:54:42 -0600 | [diff] [blame] | 597 | { |
| 598 | /* Intrapixel differencing */ |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 599 | png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1); |
Glenn Randers-Pehrson | 2ad31ae | 2000-12-15 08:54:42 -0600 | [diff] [blame] | 600 | } |
| 601 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 602 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 603 | |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 604 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED |
John Bowler | 9b872f4 | 2011-02-12 09:00:16 -0600 | [diff] [blame] | 605 | if (png_ptr->transformations) |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 606 | png_do_read_transformations(png_ptr, &row_info); |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 607 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 608 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 609 | /* The transformed pixel depth should match the depth now in row_info. */ |
| 610 | if (png_ptr->transformed_pixel_depth == 0) |
| 611 | { |
| 612 | png_ptr->transformed_pixel_depth = row_info.pixel_depth; |
| 613 | if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) |
| 614 | png_error(png_ptr, "sequential row overflow"); |
| 615 | } |
| 616 | |
| 617 | else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) |
| 618 | png_error(png_ptr, "internal sequential row size calculation error"); |
| 619 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 620 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 621 | /* Blow up interlaced rows to full size */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 622 | if (png_ptr->interlaced && |
| 623 | (png_ptr->transformations & PNG_INTERLACE)) |
| 624 | { |
| 625 | if (png_ptr->pass < 6) |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 626 | png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, |
| 627 | png_ptr->transformations); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 628 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 629 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 630 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 631 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 632 | if (row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 633 | png_combine_row(png_ptr, row, 0/*row*/); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 634 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 635 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 636 | else |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 637 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 638 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 639 | if (row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 640 | png_combine_row(png_ptr, row, -1/*ignored*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 641 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 642 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 643 | png_combine_row(png_ptr, dsp_row, -1/*ignored*/); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 644 | } |
| 645 | png_read_finish_row(png_ptr); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 646 | |
| 647 | if (png_ptr->read_row_fn != NULL) |
| 648 | (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 649 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 650 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 651 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 652 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 653 | /* Read one or more rows of image data. If the image is interlaced, |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 654 | * and png_set_interlace_handling() has been called, the rows need to |
| 655 | * contain the contents of the rows from the previous pass. If the |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 656 | * image has alpha or transparency, and png_handle_alpha()[*] has been |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 657 | * called, the rows contents must be initialized to the contents of the |
| 658 | * screen. |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 659 | * |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 660 | * "row" holds the actual image, and pixels are placed in it |
| 661 | * as they arrive. If the image is displayed after each pass, it will |
| 662 | * appear to "sparkle" in. "display_row" can be used to display a |
| 663 | * "chunky" progressive image, with finer detail added as it becomes |
| 664 | * available. If you do not want this "chunky" display, you may pass |
| 665 | * NULL for display_row. If you do not want the sparkle display, and |
| 666 | * you have not called png_handle_alpha(), you may pass NULL for rows. |
| 667 | * If you have called png_handle_alpha(), and the image has either an |
| 668 | * alpha channel or a transparency chunk, you must provide a buffer for |
| 669 | * rows. In this case, you do not have to provide a display_row buffer |
| 670 | * also, but you may. If the image is not interlaced, or if you have |
| 671 | * not called png_set_interlace_handling(), the display_row buffer will |
| 672 | * be ignored, so pass NULL to it. |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 673 | * |
Glenn Randers-Pehrson | c3d51c1 | 2006-03-02 07:23:18 -0600 | [diff] [blame] | 674 | * [*] png_handle_alpha() does not exist yet, as of this version of libpng |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 675 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 676 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 677 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 678 | png_read_rows(png_structp png_ptr, png_bytepp row, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 679 | png_bytepp display_row, png_uint_32 num_rows) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 680 | { |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 681 | png_uint_32 i; |
| 682 | png_bytepp rp; |
| 683 | png_bytepp dp; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 684 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 685 | png_debug(1, "in png_read_rows"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 686 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 687 | if (png_ptr == NULL) |
| 688 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 689 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 690 | rp = row; |
| 691 | dp = display_row; |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 692 | if (rp != NULL && dp != NULL) |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 693 | for (i = 0; i < num_rows; i++) |
| 694 | { |
| 695 | png_bytep rptr = *rp++; |
| 696 | png_bytep dptr = *dp++; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 697 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 698 | png_read_row(png_ptr, rptr, dptr); |
| 699 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 700 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 701 | else if (rp != NULL) |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 702 | for (i = 0; i < num_rows; i++) |
| 703 | { |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 704 | png_bytep rptr = *rp; |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 705 | png_read_row(png_ptr, rptr, NULL); |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 706 | rp++; |
| 707 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 708 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 709 | else if (dp != NULL) |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 710 | for (i = 0; i < num_rows; i++) |
| 711 | { |
| 712 | png_bytep dptr = *dp; |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 713 | png_read_row(png_ptr, NULL, dptr); |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 714 | dp++; |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 715 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 716 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 717 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 718 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 719 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 720 | /* Read the entire image. If the image has an alpha channel or a tRNS |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 721 | * chunk, and you have called png_handle_alpha()[*], you will need to |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 722 | * initialize the image to the current image that PNG will be overlaying. |
| 723 | * We set the num_rows again here, in case it was incorrectly set in |
| 724 | * png_read_start_row() by a call to png_read_update_info() or |
| 725 | * png_start_read_image() if png_set_interlace_handling() wasn't called |
| 726 | * prior to either of these functions like it should have been. You can |
| 727 | * only call this function once. If you desire to have an image for |
| 728 | * each pass of a interlaced image, use png_read_rows() instead. |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 729 | * |
Glenn Randers-Pehrson | c3d51c1 | 2006-03-02 07:23:18 -0600 | [diff] [blame] | 730 | * [*] png_handle_alpha() does not exist yet, as of this version of libpng |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 731 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 732 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 733 | png_read_image(png_structp png_ptr, png_bytepp image) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 734 | { |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 735 | png_uint_32 i, image_height; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 736 | int pass, j; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 737 | png_bytepp rp; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 738 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 739 | png_debug(1, "in png_read_image"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 740 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 741 | if (png_ptr == NULL) |
| 742 | return; |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 743 | |
| 744 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | 31aee0d | 2010-07-29 17:39:14 -0500 | [diff] [blame] | 745 | if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 746 | { |
| 747 | pass = png_set_interlace_handling(png_ptr); |
| 748 | /* And make sure transforms are initialized. */ |
| 749 | png_start_read_image(png_ptr); |
| 750 | } |
| 751 | else |
| 752 | { |
Glenn Randers-Pehrson | e15a96b | 2011-01-14 15:47:37 -0600 | [diff] [blame] | 753 | if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) |
Glenn Randers-Pehrson | 31aee0d | 2010-07-29 17:39:14 -0500 | [diff] [blame] | 754 | { |
Glenn Randers-Pehrson | 29034c5 | 2010-07-29 17:58:49 -0500 | [diff] [blame] | 755 | /* Caller called png_start_read_image or png_read_update_info without |
| 756 | * first turning on the PNG_INTERLACE transform. We can fix this here, |
| 757 | * but the caller should do it! |
| 758 | */ |
| 759 | png_warning(png_ptr, "Interlace handling should be turned on when " |
| 760 | "using png_read_image"); |
| 761 | /* Make sure this is set correctly */ |
| 762 | png_ptr->num_rows = png_ptr->height; |
Glenn Randers-Pehrson | 31aee0d | 2010-07-29 17:39:14 -0500 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in |
| 766 | * the above error case. |
| 767 | */ |
| 768 | pass = png_set_interlace_handling(png_ptr); |
| 769 | } |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 770 | #else |
| 771 | if (png_ptr->interlaced) |
| 772 | png_error(png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 773 | "Cannot read interlaced image -- interlace handler disabled"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 774 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 775 | pass = 1; |
| 776 | #endif |
| 777 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 778 | image_height=png_ptr->height; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 779 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 780 | for (j = 0; j < pass; j++) |
| 781 | { |
| 782 | rp = image; |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 783 | for (i = 0; i < image_height; i++) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 784 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 785 | png_read_row(png_ptr, *rp, NULL); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 786 | rp++; |
| 787 | } |
| 788 | } |
| 789 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 790 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 791 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 792 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 793 | /* Read the end of the PNG file. Will not read past the end of the |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 794 | * file, will verify the end is accurate, and will read any comments |
| 795 | * or time information at the end of the file, if info is not NULL. |
| 796 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 797 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 798 | png_read_end(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 799 | { |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 800 | png_debug(1, "in png_read_end"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 801 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 802 | if (png_ptr == NULL) |
| 803 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 804 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 805 | png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 806 | |
| 807 | do |
| 808 | { |
Glenn Randers-Pehrson | 895a9c9 | 2008-07-25 08:51:18 -0500 | [diff] [blame] | 809 | png_uint_32 length = png_read_chunk_header(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 810 | png_uint_32 chunk_name = png_ptr->chunk_name; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 811 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 812 | if (chunk_name == png_IHDR) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 813 | png_handle_IHDR(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 814 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 815 | else if (chunk_name == png_IEND) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 816 | png_handle_IEND(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 817 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 818 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 819 | else if (png_chunk_unknown_handling(png_ptr, chunk_name) != |
| 820 | PNG_HANDLE_CHUNK_AS_DEFAULT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 821 | { |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 822 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 823 | { |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 824 | if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 825 | png_benign_error(png_ptr, "Too many IDATs found"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 826 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 827 | png_handle_unknown(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 828 | if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 829 | png_ptr->mode |= PNG_HAVE_PLTE; |
| 830 | } |
| 831 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 832 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 833 | else if (chunk_name == png_IDAT) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 834 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 835 | /* Zero length IDATs are legal after the last IDAT has been |
| 836 | * read, but not after other chunks have been read. |
| 837 | */ |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 838 | if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 839 | png_benign_error(png_ptr, "Too many IDATs found"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 840 | |
Glenn Randers-Pehrson | 4accabb | 2000-04-14 14:20:47 -0500 | [diff] [blame] | 841 | png_crc_finish(png_ptr, length); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 842 | } |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 843 | else if (chunk_name == png_PLTE) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 844 | png_handle_PLTE(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 845 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 846 | #ifdef PNG_READ_bKGD_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 847 | else if (chunk_name == png_bKGD) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 848 | png_handle_bKGD(png_ptr, info_ptr, length); |
| 849 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 850 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 851 | #ifdef PNG_READ_cHRM_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 852 | else if (chunk_name == png_cHRM) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 853 | png_handle_cHRM(png_ptr, info_ptr, length); |
| 854 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 855 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 856 | #ifdef PNG_READ_gAMA_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 857 | else if (chunk_name == png_gAMA) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 858 | png_handle_gAMA(png_ptr, info_ptr, length); |
| 859 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 860 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 861 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 862 | else if (chunk_name == png_hIST) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 863 | png_handle_hIST(png_ptr, info_ptr, length); |
| 864 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 865 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 866 | #ifdef PNG_READ_oFFs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 867 | else if (chunk_name == png_oFFs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 868 | png_handle_oFFs(png_ptr, info_ptr, length); |
| 869 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 870 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 871 | #ifdef PNG_READ_pCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 872 | else if (chunk_name == png_pCAL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 873 | png_handle_pCAL(png_ptr, info_ptr, length); |
| 874 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 875 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 876 | #ifdef PNG_READ_sCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 877 | else if (chunk_name == png_sCAL) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 878 | png_handle_sCAL(png_ptr, info_ptr, length); |
| 879 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 880 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 881 | #ifdef PNG_READ_pHYs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 882 | else if (chunk_name == png_pHYs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 883 | png_handle_pHYs(png_ptr, info_ptr, length); |
| 884 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 885 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 886 | #ifdef PNG_READ_sBIT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 887 | else if (chunk_name == png_sBIT) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 888 | png_handle_sBIT(png_ptr, info_ptr, length); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 889 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 890 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 891 | #ifdef PNG_READ_sRGB_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 892 | else if (chunk_name == png_sRGB) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 893 | png_handle_sRGB(png_ptr, info_ptr, length); |
| 894 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 895 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 896 | #ifdef PNG_READ_iCCP_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 897 | else if (chunk_name == png_iCCP) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 898 | png_handle_iCCP(png_ptr, info_ptr, length); |
| 899 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 900 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 901 | #ifdef PNG_READ_sPLT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 902 | else if (chunk_name == png_sPLT) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 903 | png_handle_sPLT(png_ptr, info_ptr, length); |
| 904 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 905 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 906 | #ifdef PNG_READ_tEXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 907 | else if (chunk_name == png_tEXt) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 908 | png_handle_tEXt(png_ptr, info_ptr, length); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 909 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 910 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 911 | #ifdef PNG_READ_tIME_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 912 | else if (chunk_name == png_tIME) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 913 | png_handle_tIME(png_ptr, info_ptr, length); |
| 914 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 915 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 916 | #ifdef PNG_READ_tRNS_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 917 | else if (chunk_name == png_tRNS) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 918 | png_handle_tRNS(png_ptr, info_ptr, length); |
| 919 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 920 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 921 | #ifdef PNG_READ_zTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 922 | else if (chunk_name == png_zTXt) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 923 | png_handle_zTXt(png_ptr, info_ptr, length); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 924 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 925 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 926 | #ifdef PNG_READ_iTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 927 | else if (chunk_name == png_iTXt) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 928 | png_handle_iTXt(png_ptr, info_ptr, length); |
| 929 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 930 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 931 | else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 932 | png_handle_unknown(png_ptr, info_ptr, length); |
| 933 | } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 934 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 935 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 936 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 937 | /* Free all memory used by the read */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 938 | void PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 939 | png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 940 | png_infopp end_info_ptr_ptr) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 941 | { |
| 942 | png_structp png_ptr = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 943 | png_infop info_ptr = NULL, end_info_ptr = NULL; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 944 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 945 | png_free_ptr free_fn = NULL; |
| 946 | png_voidp mem_ptr = NULL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 947 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 948 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 949 | png_debug(1, "in png_destroy_read_struct"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 950 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 951 | if (png_ptr_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 952 | png_ptr = *png_ptr_ptr; |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 953 | if (png_ptr == NULL) |
| 954 | return; |
| 955 | |
| 956 | #ifdef PNG_USER_MEM_SUPPORTED |
| 957 | free_fn = png_ptr->free_fn; |
| 958 | mem_ptr = png_ptr->mem_ptr; |
| 959 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 960 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 961 | if (info_ptr_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 962 | info_ptr = *info_ptr_ptr; |
| 963 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 964 | if (end_info_ptr_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 965 | end_info_ptr = *end_info_ptr_ptr; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 966 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 967 | png_read_destroy(png_ptr, info_ptr, end_info_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 968 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 969 | if (info_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 970 | { |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 971 | #ifdef PNG_TEXT_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 972 | png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 973 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 974 | |
| 975 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 976 | png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
| 977 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 978 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 979 | png_destroy_struct((png_voidp)info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 980 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 981 | *info_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 982 | } |
| 983 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 984 | if (end_info_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 985 | { |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 986 | #ifdef PNG_READ_TEXT_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 987 | png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 988 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 989 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 990 | png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 991 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 992 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 993 | png_destroy_struct((png_voidp)end_info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 994 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 995 | *end_info_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 996 | } |
| 997 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 998 | if (png_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 999 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1000 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 1001 | png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
| 1002 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1003 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1004 | png_destroy_struct((png_voidp)png_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1005 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 1006 | *png_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 1010 | /* Free all memory used by the read (old method) */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1011 | void /* PRIVATE */ |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 1012 | png_read_destroy(png_structp png_ptr, png_infop info_ptr, |
| 1013 | png_infop end_info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1014 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1015 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1016 | jmp_buf tmp_jmp; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1017 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1018 | png_error_ptr error_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1019 | #ifdef PNG_WARNINGS_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1020 | png_error_ptr warning_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1021 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1022 | png_voidp error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1023 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1024 | png_free_ptr free_fn; |
| 1025 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1026 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 1027 | png_debug(1, "in png_read_destroy"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 1028 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1029 | if (info_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1030 | png_info_destroy(png_ptr, info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1031 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1032 | if (end_info_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1033 | png_info_destroy(png_ptr, end_info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1034 | |
John Bowler | 07772cb | 2011-10-14 18:19:47 -0500 | [diff] [blame] | 1035 | #ifdef PNG_READ_GAMMA_SUPPORTED |
| 1036 | png_destroy_gamma_table(png_ptr); |
| 1037 | #endif |
| 1038 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1039 | png_free(png_ptr, png_ptr->zbuf); |
Glenn Randers-Pehrson | 1b8e567 | 2001-08-25 06:46:06 -0500 | [diff] [blame] | 1040 | png_free(png_ptr, png_ptr->big_row_buf); |
Mans Rullgard | 1c42276 | 2011-10-17 16:52:19 -0500 | [diff] [blame] | 1041 | png_free(png_ptr, png_ptr->big_prev_row); |
Glenn Randers-Pehrson | b3ff968 | 2008-07-21 08:05:57 -0500 | [diff] [blame] | 1042 | png_free(png_ptr, png_ptr->chunkdata); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1043 | |
Glenn Randers-Pehrson | 3cd7cff | 2010-04-16 19:27:08 -0500 | [diff] [blame] | 1044 | #ifdef PNG_READ_QUANTIZE_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1045 | png_free(png_ptr, png_ptr->palette_lookup); |
Glenn Randers-Pehrson | 3cd7cff | 2010-04-16 19:27:08 -0500 | [diff] [blame] | 1046 | png_free(png_ptr, png_ptr->quantize_index); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1047 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1048 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1049 | if (png_ptr->free_me & PNG_FREE_PLTE) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1050 | png_zfree(png_ptr, png_ptr->palette); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1051 | png_ptr->free_me &= ~PNG_FREE_PLTE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1052 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1053 | #if defined(PNG_tRNS_SUPPORTED) || \ |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1054 | defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1055 | if (png_ptr->free_me & PNG_FREE_TRNS) |
Glenn Randers-Pehrson | 6abea75 | 2009-08-08 16:52:06 -0500 | [diff] [blame] | 1056 | png_free(png_ptr, png_ptr->trans_alpha); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1057 | png_ptr->free_me &= ~PNG_FREE_TRNS; |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1058 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1059 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1060 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1061 | if (png_ptr->free_me & PNG_FREE_HIST) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1062 | png_free(png_ptr, png_ptr->hist); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1063 | png_ptr->free_me &= ~PNG_FREE_HIST; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1064 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1065 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1066 | inflateEnd(&png_ptr->zstream); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1067 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1068 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1069 | png_free(png_ptr, png_ptr->save_buffer); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1070 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1071 | |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1072 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
| 1073 | #ifdef PNG_TEXT_SUPPORTED |
| 1074 | png_free(png_ptr, png_ptr->current_text); |
| 1075 | #endif /* PNG_TEXT_SUPPORTED */ |
| 1076 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
| 1077 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1078 | /* Save the important info out of the png_struct, in case it is |
| 1079 | * being used again. |
| 1080 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1081 | #ifdef PNG_SETJMP_SUPPORTED |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 1082 | png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf)); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1083 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1084 | |
| 1085 | error_fn = png_ptr->error_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1086 | #ifdef PNG_WARNINGS_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1087 | warning_fn = png_ptr->warning_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1088 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1089 | error_ptr = png_ptr->error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1090 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1091 | free_fn = png_ptr->free_fn; |
| 1092 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1093 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1094 | png_memset(png_ptr, 0, png_sizeof(png_struct)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1095 | |
| 1096 | png_ptr->error_fn = error_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1097 | #ifdef PNG_WARNINGS_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1098 | png_ptr->warning_fn = warning_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1099 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1100 | png_ptr->error_ptr = error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1101 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1102 | png_ptr->free_fn = free_fn; |
| 1103 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1104 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1105 | #ifdef PNG_SETJMP_SUPPORTED |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 1106 | png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf)); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1107 | #endif |
| 1108 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1109 | } |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1110 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1111 | void PNGAPI |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1112 | png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) |
| 1113 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1114 | if (png_ptr == NULL) |
| 1115 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1116 | |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1117 | png_ptr->read_row_fn = read_row_fn; |
| 1118 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1119 | |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame] | 1120 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 1121 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1122 | #ifdef PNG_INFO_IMAGE_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1123 | void PNGAPI |
| 1124 | png_read_png(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1125 | int transforms, |
| 1126 | voidp params) |
| 1127 | { |
| 1128 | int row; |
| 1129 | |
John Bowler | 6a6d79f | 2011-02-12 08:56:40 -0600 | [diff] [blame] | 1130 | if (png_ptr == NULL || info_ptr == NULL) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1131 | return; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1132 | |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1133 | /* png_read_info() gives us all of the information from the |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1134 | * PNG file before the first IDAT (image data chunk). |
| 1135 | */ |
| 1136 | png_read_info(png_ptr, info_ptr); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1137 | if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) |
| 1138 | png_error(png_ptr, "Image is too high to process with png_read_png()"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1139 | |
| 1140 | /* -------------- image transformations start here ------------------- */ |
| 1141 | |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1142 | #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED |
Glenn Randers-Pehrson | 55fbff3 | 2011-05-17 06:49:32 -0500 | [diff] [blame] | 1143 | /* Tell libpng to strip 16-bit/color files down to 8 bits per color. |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1144 | */ |
Glenn Randers-Pehrson | ab63dd0 | 2011-06-17 20:04:17 -0500 | [diff] [blame] | 1145 | if (transforms & PNG_TRANSFORM_SCALE_16) |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1146 | { |
Glenn Randers-Pehrson | 6da2f2d | 2011-06-17 23:07:16 -0500 | [diff] [blame] | 1147 | /* Added at libpng-1.5.4. "strip_16" produces the same result that it |
| 1148 | * did in earlier versions, while "scale_16" is now more accurate. |
| 1149 | */ |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1150 | png_set_scale_16(png_ptr); |
| 1151 | } |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1152 | #endif |
| 1153 | |
| 1154 | #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED |
John Bowler | 8d26126 | 2011-06-18 13:37:11 -0500 | [diff] [blame] | 1155 | /* If both SCALE and STRIP are required pngrtran will effectively cancel the |
| 1156 | * latter by doing SCALE first. This is ok and allows apps not to check for |
| 1157 | * which is supported to get the right answer. |
| 1158 | */ |
| 1159 | if (transforms & PNG_TRANSFORM_STRIP_16) |
| 1160 | png_set_strip_16(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1161 | #endif |
| 1162 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1163 | #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1164 | /* Strip alpha bytes from the input data without combining with |
| 1165 | * the background (not recommended). |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1166 | */ |
| 1167 | if (transforms & PNG_TRANSFORM_STRIP_ALPHA) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1168 | png_set_strip_alpha(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1169 | #endif |
| 1170 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1171 | #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1172 | /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1173 | * byte into separate bytes (useful for paletted and grayscale images). |
| 1174 | */ |
| 1175 | if (transforms & PNG_TRANSFORM_PACKING) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1176 | png_set_packing(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1177 | #endif |
| 1178 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1179 | #ifdef PNG_READ_PACKSWAP_SUPPORTED |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1180 | /* Change the order of packed pixels to least significant bit first |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1181 | * (not useful if you are using png_set_packing). |
| 1182 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1183 | if (transforms & PNG_TRANSFORM_PACKSWAP) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1184 | png_set_packswap(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1185 | #endif |
| 1186 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1187 | #ifdef PNG_READ_EXPAND_SUPPORTED |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1188 | /* Expand paletted colors into true RGB triplets |
| 1189 | * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel |
| 1190 | * Expand paletted or RGB images with transparency to full alpha |
| 1191 | * channels so the data will be available as RGBA quartets. |
| 1192 | */ |
| 1193 | if (transforms & PNG_TRANSFORM_EXPAND) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1194 | if ((png_ptr->bit_depth < 8) || |
| 1195 | (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || |
| 1196 | (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1197 | png_set_expand(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1198 | #endif |
| 1199 | |
Glenn Randers-Pehrson | 3cd7cff | 2010-04-16 19:27:08 -0500 | [diff] [blame] | 1200 | /* We don't handle background color or gamma transformation or quantizing. |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1201 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1202 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1203 | #ifdef PNG_READ_INVERT_SUPPORTED |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 1204 | /* Invert monochrome files to have 0 as white and 1 as black |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1205 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1206 | if (transforms & PNG_TRANSFORM_INVERT_MONO) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1207 | png_set_invert_mono(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1208 | #endif |
| 1209 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1210 | #ifdef PNG_READ_SHIFT_SUPPORTED |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1211 | /* If you want to shift the pixel values from the range [0,255] or |
| 1212 | * [0,65535] to the original [0,7] or [0,31], or whatever range the |
| 1213 | * colors were originally in: |
| 1214 | */ |
| 1215 | if ((transforms & PNG_TRANSFORM_SHIFT) |
| 1216 | && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) |
| 1217 | { |
| 1218 | png_color_8p sig_bit; |
| 1219 | |
| 1220 | png_get_sBIT(png_ptr, info_ptr, &sig_bit); |
| 1221 | png_set_shift(png_ptr, sig_bit); |
| 1222 | } |
| 1223 | #endif |
| 1224 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1225 | #ifdef PNG_READ_BGR_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1226 | /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1227 | if (transforms & PNG_TRANSFORM_BGR) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1228 | png_set_bgr(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1229 | #endif |
| 1230 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1231 | #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1232 | /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1233 | if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1234 | png_set_swap_alpha(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1235 | #endif |
| 1236 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1237 | #ifdef PNG_READ_SWAP_SUPPORTED |
Glenn Randers-Pehrson | 55fbff3 | 2011-05-17 06:49:32 -0500 | [diff] [blame] | 1238 | /* Swap bytes of 16-bit files to least significant byte first */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1239 | if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1240 | png_set_swap(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1241 | #endif |
| 1242 | |
Glenn Randers-Pehrson | c1a4d64 | 2009-10-29 23:29:24 -0500 | [diff] [blame] | 1243 | /* Added at libpng-1.2.41 */ |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1244 | #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1245 | /* Invert the alpha channel from opacity to transparency */ |
Glenn Randers-Pehrson | 6878eb6 | 2009-06-29 16:45:53 -0500 | [diff] [blame] | 1246 | if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1247 | png_set_invert_alpha(png_ptr); |
Glenn Randers-Pehrson | 6878eb6 | 2009-06-29 16:45:53 -0500 | [diff] [blame] | 1248 | #endif |
| 1249 | |
Glenn Randers-Pehrson | c1a4d64 | 2009-10-29 23:29:24 -0500 | [diff] [blame] | 1250 | /* Added at libpng-1.2.41 */ |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1251 | #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1252 | /* Expand grayscale image to RGB */ |
Glenn Randers-Pehrson | 99708d5 | 2009-06-29 17:30:00 -0500 | [diff] [blame] | 1253 | if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1254 | png_set_gray_to_rgb(png_ptr); |
Glenn Randers-Pehrson | 99708d5 | 2009-06-29 17:30:00 -0500 | [diff] [blame] | 1255 | #endif |
| 1256 | |
Glenn Randers-Pehrson | ef217b7 | 2011-06-15 12:58:27 -0500 | [diff] [blame] | 1257 | /* Added at libpng-1.5.4 */ |
John Bowler | 96cec0e | 2011-05-08 22:48:12 -0500 | [diff] [blame] | 1258 | #ifdef PNG_READ_EXPAND_16_SUPPORTED |
| 1259 | if (transforms & PNG_TRANSFORM_EXPAND_16) |
| 1260 | png_set_expand_16(png_ptr); |
| 1261 | #endif |
| 1262 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1263 | /* We don't handle adding filler bytes */ |
| 1264 | |
John Bowler | 6a6d79f | 2011-02-12 08:56:40 -0600 | [diff] [blame] | 1265 | /* We use png_read_image and rely on that for interlace handling, but we also |
| 1266 | * call png_read_update_info therefore must turn on interlace handling now: |
| 1267 | */ |
| 1268 | (void)png_set_interlace_handling(png_ptr); |
| 1269 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1270 | /* Optional call to gamma correct and add the background to the palette |
| 1271 | * and update info structure. REQUIRED if you are expecting libpng to |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1272 | * update the palette for you (i.e., you selected such a transform above). |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1273 | */ |
| 1274 | png_read_update_info(png_ptr, info_ptr); |
| 1275 | |
| 1276 | /* -------------- image transformations end here ------------------- */ |
| 1277 | |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 1278 | png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1279 | if (info_ptr->row_pointers == NULL) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1280 | { |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1281 | png_uint_32 iptr; |
Glenn Randers-Pehrson | d9f21ee | 2009-08-31 10:52:38 -0500 | [diff] [blame] | 1282 | |
Glenn Randers-Pehrson | 0ffb71a | 2009-02-28 06:08:20 -0600 | [diff] [blame] | 1283 | info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1284 | info_ptr->height * png_sizeof(png_bytep)); |
Glenn Randers-Pehrson | d9f21ee | 2009-08-31 10:52:38 -0500 | [diff] [blame] | 1285 | for (iptr=0; iptr<info_ptr->height; iptr++) |
| 1286 | info_ptr->row_pointers[iptr] = NULL; |
| 1287 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1288 | info_ptr->free_me |= PNG_FREE_ROWS; |
Glenn Randers-Pehrson | d9f21ee | 2009-08-31 10:52:38 -0500 | [diff] [blame] | 1289 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1290 | for (row = 0; row < (int)info_ptr->height; row++) |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1291 | info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1292 | png_get_rowbytes(png_ptr, info_ptr)); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1293 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1294 | |
| 1295 | png_read_image(png_ptr, info_ptr->row_pointers); |
| 1296 | info_ptr->valid |= PNG_INFO_IDAT; |
| 1297 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1298 | /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1299 | png_read_end(png_ptr, info_ptr); |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1300 | |
Glenn Randers-Pehrson | d546f43 | 2010-12-04 20:41:36 -0600 | [diff] [blame] | 1301 | PNG_UNUSED(transforms) /* Quiet compiler warnings */ |
| 1302 | PNG_UNUSED(params) |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1303 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1304 | } |
Glenn Randers-Pehrson | 9c3ab68 | 2006-02-20 22:09:05 -0600 | [diff] [blame] | 1305 | #endif /* PNG_INFO_IMAGE_SUPPORTED */ |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 1306 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Glenn Randers-Pehrson | 9c3ab68 | 2006-02-20 22:09:05 -0600 | [diff] [blame] | 1307 | #endif /* PNG_READ_SUPPORTED */ |