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 | 55e85c2 | 2011-11-04 13:34:48 -0500 | [diff] [blame] | 4 | * Last changed in libpng 1.5.7 [(PENDING RELEASE)] |
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" |
John Bowler | 7875d53 | 2011-11-07 22:33:49 -0600 | [diff] [blame^] | 18 | #if defined PNG_SIMPLIFIED_READ_SUPPORTED && defined PNG_STDIO_SUPPORTED |
| 19 | # include <errno.h> |
| 20 | #endif |
Glenn Randers-Pehrson | 9c3ab68 | 2006-02-20 22:09:05 -0600 | [diff] [blame] | 21 | |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 22 | #ifdef PNG_READ_SUPPORTED |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 23 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 24 | /* Create a PNG structure for reading, and allocate any memory needed. */ |
Glenn Randers-Pehrson | 77396b6 | 2010-08-02 08:00:10 -0500 | [diff] [blame] | 25 | PNG_FUNCTION(png_structp,PNGAPI |
| 26 | png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr, |
| 27 | png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 28 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 29 | |
| 30 | #ifdef PNG_USER_MEM_SUPPORTED |
| 31 | 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] | 32 | warn_fn, NULL, NULL, NULL)); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 33 | } |
| 34 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 35 | /* Alternate create PNG structure for reading, and allocate any memory |
| 36 | * needed. |
| 37 | */ |
Glenn Randers-Pehrson | 77396b6 | 2010-08-02 08:00:10 -0500 | [diff] [blame] | 38 | PNG_FUNCTION(png_structp,PNGAPI |
| 39 | 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] | 40 | 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] | 41 | 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] | 42 | { |
| 43 | #endif /* PNG_USER_MEM_SUPPORTED */ |
| 44 | |
Glenn Randers-Pehrson | 79134c6 | 2009-02-14 10:32:18 -0600 | [diff] [blame] | 45 | #ifdef PNG_SETJMP_SUPPORTED |
| 46 | volatile |
| 47 | #endif |
| 48 | png_structp png_ptr; |
Glenn Randers-Pehrson | 62ca98e | 2009-12-20 15:14:57 -0600 | [diff] [blame] | 49 | volatile int png_cleanup_needed = 0; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 50 | |
| 51 | #ifdef PNG_SETJMP_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 52 | #ifdef USE_FAR_KEYWORD |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 53 | jmp_buf tmp_jmpbuf; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 54 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 55 | #endif |
| 56 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 57 | png_debug(1, "in png_create_read_struct"); |
Glenn Randers-Pehrson | da00980 | 2009-08-15 13:25:47 -0500 | [diff] [blame] | 58 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 59 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 60 | png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 61 | malloc_fn, mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 62 | #else |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 63 | png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 64 | #endif |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 65 | if (png_ptr == NULL) |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 66 | return (NULL); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 67 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 68 | /* Added at libpng-1.2.6 */ |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 69 | #ifdef PNG_USER_LIMITS_SUPPORTED |
Glenn Randers-Pehrson | ef29a5e | 2009-10-31 19:37:05 -0500 | [diff] [blame] | 70 | png_ptr->user_width_max = PNG_USER_WIDTH_MAX; |
| 71 | png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 72 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 73 | # ifdef PNG_USER_CHUNK_CACHE_MAX |
| 74 | /* Added at libpng-1.2.43 and 1.4.0 */ |
Glenn Randers-Pehrson | ef29a5e | 2009-10-31 19:37:05 -0500 | [diff] [blame] | 75 | png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 76 | # endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 77 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 78 | # ifdef PNG_SET_USER_CHUNK_MALLOC_MAX |
| 79 | /* Added at libpng-1.2.43 and 1.4.1 */ |
| 80 | png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; |
| 81 | # endif |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 82 | #endif |
| 83 | |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 84 | #ifdef PNG_SETJMP_SUPPORTED |
| 85 | /* Applications that neglect to set up their own setjmp() and then |
| 86 | encounter a png_error() will longjmp here. Since the jmpbuf is |
| 87 | then meaningless we abort instead of returning. */ |
| 88 | #ifdef USE_FAR_KEYWORD |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 89 | if (setjmp(tmp_jmpbuf)) |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 90 | #else |
Glenn Randers-Pehrson | f4ea224 | 2009-11-20 21:38:24 -0600 | [diff] [blame] | 91 | if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 92 | #endif |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 93 | PNG_ABORT(); |
Glenn Randers-Pehrson | f4ea224 | 2009-11-20 21:38:24 -0600 | [diff] [blame] | 94 | #ifdef USE_FAR_KEYWORD |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 95 | 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] | 96 | #endif |
Glenn Randers-Pehrson | a2567be | 2009-10-19 20:31:31 -0500 | [diff] [blame] | 97 | #endif /* PNG_SETJMP_SUPPORTED */ |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 98 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 99 | #ifdef PNG_USER_MEM_SUPPORTED |
| 100 | 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] | 101 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 102 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 103 | png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 104 | |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 105 | /* Call the general version checker (shared with read and write code): */ |
| 106 | if (!png_user_version_check(png_ptr, user_png_ver)) |
| 107 | png_cleanup_needed = 1; |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 108 | |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 109 | if (!png_cleanup_needed) |
| 110 | { |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 111 | /* Initialize zbuf - compression buffer */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 112 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 113 | png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size); |
| 114 | |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 115 | if (png_ptr->zbuf == NULL) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 116 | png_cleanup_needed = 1; |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 117 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 118 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 119 | png_ptr->zstream.zalloc = png_zalloc; |
| 120 | png_ptr->zstream.zfree = png_zfree; |
| 121 | png_ptr->zstream.opaque = (voidpf)png_ptr; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 122 | |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 123 | if (!png_cleanup_needed) |
| 124 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 125 | switch (inflateInit(&png_ptr->zstream)) |
| 126 | { |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 127 | case Z_OK: |
| 128 | break; /* Do nothing */ |
| 129 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 130 | case Z_MEM_ERROR: |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 131 | png_warning(png_ptr, "zlib memory error"); |
| 132 | png_cleanup_needed = 1; |
| 133 | break; |
| 134 | |
| 135 | case Z_STREAM_ERROR: |
| 136 | png_warning(png_ptr, "zlib stream error"); |
| 137 | png_cleanup_needed = 1; |
| 138 | break; |
| 139 | |
| 140 | case Z_VERSION_ERROR: |
| 141 | png_warning(png_ptr, "zlib version error"); |
| 142 | png_cleanup_needed = 1; |
| 143 | break; |
| 144 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 145 | default: png_warning(png_ptr, "Unknown zlib error"); |
| 146 | png_cleanup_needed = 1; |
| 147 | } |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | if (png_cleanup_needed) |
| 151 | { |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 152 | /* Clean up PNG structure and deallocate any memory. */ |
| 153 | png_free(png_ptr, png_ptr->zbuf); |
| 154 | png_ptr->zbuf = NULL; |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 155 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 156 | png_destroy_struct_2((png_voidp)png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 157 | (png_free_ptr)free_fn, (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 158 | #else |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 159 | png_destroy_struct((png_voidp)png_ptr); |
Glenn Randers-Pehrson | a93c942 | 2009-04-13 11:41:33 -0500 | [diff] [blame] | 160 | #endif |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 161 | return (NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 164 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 165 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 166 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 167 | png_set_read_fn(png_ptr, NULL, NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 168 | |
Glenn Randers-Pehrson | f0a8fe0 | 2009-04-14 08:28:15 -0500 | [diff] [blame] | 169 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 170 | return (png_ptr); |
| 171 | } |
| 172 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 173 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 174 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 175 | /* Read the information before the actual image data. This has been |
Glenn Randers-Pehrson | f9f2fe0 | 1998-03-15 18:20:23 -0600 | [diff] [blame] | 176 | * 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] | 177 | * 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] | 178 | * 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] | 179 | * via png_set_sig_bytes(), and we will only check the remaining bytes |
| 180 | * here. The application can then have access to the signature bytes we |
| 181 | * read if it is determined that this isn't a valid PNG file. |
| 182 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 183 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 184 | png_read_info(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 185 | { |
Glenn Randers-Pehrson | c81bb8a | 2009-08-15 22:02:26 -0500 | [diff] [blame] | 186 | png_debug(1, "in png_read_info"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 187 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 188 | if (png_ptr == NULL || info_ptr == NULL) |
| 189 | return; |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 190 | |
Glenn Randers-Pehrson | a581556 | 2010-11-20 21:48:29 -0600 | [diff] [blame] | 191 | /* Read and check the PNG file signature. */ |
| 192 | png_read_sig(png_ptr, info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 193 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 194 | for (;;) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 195 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 196 | png_uint_32 length = png_read_chunk_header(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 197 | png_uint_32 chunk_name = png_ptr->chunk_name; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 198 | |
| 199 | /* This should be a binary subdivision search or a hash for |
| 200 | * matching the chunk name rather than a linear search. |
| 201 | */ |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 202 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 203 | if (png_ptr->mode & PNG_AFTER_IDAT) |
| 204 | png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 205 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 206 | if (chunk_name == png_IHDR) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 207 | png_handle_IHDR(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 208 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 209 | else if (chunk_name == png_IEND) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 210 | png_handle_IEND(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 211 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 212 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 213 | else if (png_chunk_unknown_handling(png_ptr, chunk_name) != |
| 214 | PNG_HANDLE_CHUNK_AS_DEFAULT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 215 | { |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 216 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 217 | png_ptr->mode |= PNG_HAVE_IDAT; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 218 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 219 | png_handle_unknown(png_ptr, info_ptr, length); |
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 | if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 222 | png_ptr->mode |= PNG_HAVE_PLTE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 223 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 224 | else if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 225 | { |
| 226 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 227 | png_error(png_ptr, "Missing IHDR before IDAT"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 228 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 229 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 230 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 231 | png_error(png_ptr, "Missing PLTE before IDAT"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 232 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 233 | break; |
| 234 | } |
| 235 | } |
| 236 | #endif |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 237 | else if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 238 | png_handle_PLTE(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 239 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 240 | else if (chunk_name == png_IDAT) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 241 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 242 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 243 | png_error(png_ptr, "Missing IHDR before IDAT"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 244 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 245 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 246 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 247 | png_error(png_ptr, "Missing PLTE before IDAT"); |
| 248 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 249 | png_ptr->idat_size = length; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 250 | png_ptr->mode |= PNG_HAVE_IDAT; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 251 | break; |
| 252 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 253 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 254 | #ifdef PNG_READ_bKGD_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 255 | else if (chunk_name == png_bKGD) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 256 | png_handle_bKGD(png_ptr, info_ptr, length); |
| 257 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 258 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 259 | #ifdef PNG_READ_cHRM_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 260 | else if (chunk_name == png_cHRM) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 261 | png_handle_cHRM(png_ptr, info_ptr, length); |
| 262 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 263 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 264 | #ifdef PNG_READ_gAMA_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 265 | else if (chunk_name == png_gAMA) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 266 | png_handle_gAMA(png_ptr, info_ptr, length); |
| 267 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 268 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 269 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 270 | else if (chunk_name == png_hIST) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 271 | png_handle_hIST(png_ptr, info_ptr, length); |
| 272 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 273 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 274 | #ifdef PNG_READ_oFFs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 275 | else if (chunk_name == png_oFFs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 276 | png_handle_oFFs(png_ptr, info_ptr, length); |
| 277 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 278 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 279 | #ifdef PNG_READ_pCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 280 | else if (chunk_name == png_pCAL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 281 | png_handle_pCAL(png_ptr, info_ptr, length); |
| 282 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 283 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 284 | #ifdef PNG_READ_sCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 285 | else if (chunk_name == png_sCAL) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 286 | png_handle_sCAL(png_ptr, info_ptr, length); |
| 287 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 288 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 289 | #ifdef PNG_READ_pHYs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 290 | else if (chunk_name == png_pHYs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 291 | png_handle_pHYs(png_ptr, info_ptr, length); |
| 292 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 293 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 294 | #ifdef PNG_READ_sBIT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 295 | else if (chunk_name == png_sBIT) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 296 | png_handle_sBIT(png_ptr, info_ptr, length); |
| 297 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 298 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 299 | #ifdef PNG_READ_sRGB_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 300 | else if (chunk_name == png_sRGB) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 301 | png_handle_sRGB(png_ptr, info_ptr, length); |
| 302 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 303 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 304 | #ifdef PNG_READ_iCCP_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 305 | else if (chunk_name == png_iCCP) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 306 | png_handle_iCCP(png_ptr, info_ptr, length); |
| 307 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 308 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 309 | #ifdef PNG_READ_sPLT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 310 | else if (chunk_name == png_sPLT) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 311 | png_handle_sPLT(png_ptr, info_ptr, length); |
| 312 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 313 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 314 | #ifdef PNG_READ_tEXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 315 | else if (chunk_name == png_tEXt) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 316 | png_handle_tEXt(png_ptr, info_ptr, length); |
| 317 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 318 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 319 | #ifdef PNG_READ_tIME_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 320 | else if (chunk_name == png_tIME) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 321 | png_handle_tIME(png_ptr, info_ptr, length); |
| 322 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 323 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 324 | #ifdef PNG_READ_tRNS_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 325 | else if (chunk_name == png_tRNS) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 326 | png_handle_tRNS(png_ptr, info_ptr, length); |
| 327 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 328 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 329 | #ifdef PNG_READ_zTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 330 | else if (chunk_name == png_zTXt) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 331 | png_handle_zTXt(png_ptr, info_ptr, length); |
| 332 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 333 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 334 | #ifdef PNG_READ_iTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 335 | else if (chunk_name == png_iTXt) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 336 | png_handle_iTXt(png_ptr, info_ptr, length); |
| 337 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 338 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 339 | else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 340 | png_handle_unknown(png_ptr, info_ptr, length); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 341 | } |
| 342 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 343 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 344 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 345 | /* Optional call to update the users info_ptr structure */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 346 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 347 | png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 348 | { |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 349 | png_debug(1, "in png_read_update_info"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 350 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 351 | if (png_ptr == NULL) |
| 352 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 353 | |
Glenn Randers-Pehrson | 3dbfd30 | 2011-10-13 17:24:36 -0500 | [diff] [blame] | 354 | png_read_start_row(png_ptr); |
Glenn Randers-Pehrson | 4cfdb3c | 2009-11-26 11:49:37 -0600 | [diff] [blame] | 355 | |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 356 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 357 | png_read_transform_info(png_ptr, info_ptr); |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 358 | #else |
| 359 | PNG_UNUSED(info_ptr) |
| 360 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 361 | } |
| 362 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 363 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 364 | /* Initialize palette, background, etc, after transformations |
| 365 | * are set, but before any reading takes place. This allows |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 366 | * the user to obtain a gamma-corrected palette, for example. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 367 | * If the user doesn't call this, we will do it ourselves. |
| 368 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 369 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 370 | png_start_read_image(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 371 | { |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 372 | png_debug(1, "in png_start_read_image"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 373 | |
Glenn Randers-Pehrson | 3dbfd30 | 2011-10-13 17:24:36 -0500 | [diff] [blame] | 374 | if (png_ptr != NULL) |
| 375 | png_read_start_row(png_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 376 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 377 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 378 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 379 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 380 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 381 | 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] | 382 | { |
| 383 | int ret; |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 384 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 385 | png_row_info row_info; |
| 386 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 387 | if (png_ptr == NULL) |
| 388 | return; |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 389 | |
Glenn Randers-Pehrson | 6d75d0c | 2009-08-22 08:45:09 -0500 | [diff] [blame] | 390 | png_debug2(1, "in png_read_row (row %lu, pass %d)", |
Glenn Randers-Pehrson | d233287 | 2010-10-12 19:19:28 -0500 | [diff] [blame] | 391 | (unsigned long)png_ptr->row_number, png_ptr->pass); |
Glenn Randers-Pehrson | 6d75d0c | 2009-08-22 08:45:09 -0500 | [diff] [blame] | 392 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 393 | /* png_read_start_row sets the information (in particular iwidth) for this |
| 394 | * interlace pass. |
| 395 | */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 396 | if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 397 | png_read_start_row(png_ptr); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 398 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 399 | /* 1.5.6: row_info moved out of png_struct to a local here. */ |
| 400 | row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ |
| 401 | row_info.color_type = png_ptr->color_type; |
| 402 | row_info.bit_depth = png_ptr->bit_depth; |
| 403 | row_info.channels = png_ptr->channels; |
| 404 | row_info.pixel_depth = png_ptr->pixel_depth; |
| 405 | row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); |
| 406 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 407 | if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
| 408 | { |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 409 | /* Check for transforms that have been set but were defined out */ |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 410 | #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
| 411 | if (png_ptr->transformations & PNG_INVERT_MONO) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 412 | png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 413 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 414 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 415 | #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) |
| 416 | if (png_ptr->transformations & PNG_FILLER) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 417 | png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 418 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 419 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 420 | #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \ |
| 421 | !defined(PNG_READ_PACKSWAP_SUPPORTED) |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 422 | if (png_ptr->transformations & PNG_PACKSWAP) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 423 | png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 424 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 425 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 426 | #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) |
| 427 | if (png_ptr->transformations & PNG_PACK) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 428 | png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 429 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 430 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 431 | #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) |
| 432 | if (png_ptr->transformations & PNG_SHIFT) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 433 | png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 434 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 435 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 436 | #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) |
| 437 | if (png_ptr->transformations & PNG_BGR) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 438 | png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 439 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 440 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 441 | #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) |
| 442 | if (png_ptr->transformations & PNG_SWAP_BYTES) |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 443 | png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 444 | #endif |
| 445 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 446 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 447 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 448 | /* If interlaced and we do not need a new row, combine row and return. |
| 449 | * Notice that the pixels we have from previous rows have been transformed |
| 450 | * already; we can only combine like with like (transformed or |
| 451 | * untransformed) and, because of the libpng API for interlaced images, this |
| 452 | * means we must transform before de-interlacing. |
| 453 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 454 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 455 | { |
| 456 | switch (png_ptr->pass) |
| 457 | { |
| 458 | case 0: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 459 | if (png_ptr->row_number & 0x07) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 460 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 461 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 462 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 463 | png_read_finish_row(png_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 467 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 468 | case 1: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 469 | if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 470 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 471 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 472 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 473 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 474 | png_read_finish_row(png_ptr); |
| 475 | return; |
| 476 | } |
| 477 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 478 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 479 | case 2: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 480 | if ((png_ptr->row_number & 0x07) != 4) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 481 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 482 | if (dsp_row != NULL && (png_ptr->row_number & 4)) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 483 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 484 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 485 | png_read_finish_row(png_ptr); |
| 486 | return; |
| 487 | } |
| 488 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 489 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 490 | case 3: |
| 491 | if ((png_ptr->row_number & 3) || png_ptr->width < 3) |
| 492 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 493 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 494 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 495 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 496 | png_read_finish_row(png_ptr); |
| 497 | return; |
| 498 | } |
| 499 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 500 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 501 | case 4: |
| 502 | if ((png_ptr->row_number & 3) != 2) |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 503 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 504 | if (dsp_row != NULL && (png_ptr->row_number & 2)) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 505 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 506 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 507 | png_read_finish_row(png_ptr); |
| 508 | return; |
| 509 | } |
| 510 | break; |
| 511 | case 5: |
| 512 | if ((png_ptr->row_number & 1) || png_ptr->width < 2) |
| 513 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 514 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 515 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 516 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 517 | png_read_finish_row(png_ptr); |
| 518 | return; |
| 519 | } |
| 520 | break; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 521 | |
Glenn Randers-Pehrson | b3edc73 | 2010-11-21 14:06:41 -0600 | [diff] [blame] | 522 | default: |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 523 | case 6: |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 524 | if (!(png_ptr->row_number & 1)) |
| 525 | { |
| 526 | png_read_finish_row(png_ptr); |
| 527 | return; |
| 528 | } |
| 529 | break; |
| 530 | } |
| 531 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 532 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 533 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 534 | if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
| 535 | png_error(png_ptr, "Invalid attempt to read row data"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 536 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 537 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 538 | png_ptr->zstream.avail_out = |
| 539 | (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, |
| 540 | png_ptr->iwidth) + 1); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 541 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 542 | do |
| 543 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 544 | if (!(png_ptr->zstream.avail_in)) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 545 | { |
| 546 | while (!png_ptr->idat_size) |
| 547 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 548 | png_crc_finish(png_ptr, 0); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 549 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 550 | png_ptr->idat_size = png_read_chunk_header(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 551 | if (png_ptr->chunk_name != png_IDAT) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 552 | png_error(png_ptr, "Not enough image data"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 553 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 554 | png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; |
| 555 | png_ptr->zstream.next_in = png_ptr->zbuf; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 556 | if (png_ptr->zbuf_size > png_ptr->idat_size) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 557 | png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 558 | png_crc_read(png_ptr, png_ptr->zbuf, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 559 | (png_size_t)png_ptr->zstream.avail_in); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 560 | png_ptr->idat_size -= png_ptr->zstream.avail_in; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 561 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 562 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 563 | ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 564 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 565 | if (ret == Z_STREAM_END) |
| 566 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 567 | if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 568 | png_ptr->idat_size) |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 569 | png_benign_error(png_ptr, "Extra compressed data"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 570 | png_ptr->mode |= PNG_AFTER_IDAT; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 571 | png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 572 | break; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 573 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 574 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 575 | if (ret != Z_OK) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 576 | 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] | 577 | "Decompression error"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 578 | |
| 579 | } while (png_ptr->zstream.avail_out); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 580 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 581 | if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) |
| 582 | { |
| 583 | if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) |
Mans Rullgard | d3a9480 | 2011-11-03 00:47:55 -0500 | [diff] [blame] | 584 | png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 585 | png_ptr->prev_row + 1, png_ptr->row_buf[0]); |
| 586 | else |
| 587 | png_error(png_ptr, "bad adaptive filter value"); |
| 588 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 589 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 590 | /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before |
| 591 | * 1.5.6, while the buffer really is this big in current versions of libpng |
| 592 | * it may not be in the future, so this was changed just to copy the |
| 593 | * interlaced count: |
| 594 | */ |
| 595 | 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] | 596 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 597 | #ifdef PNG_MNG_FEATURES_SUPPORTED |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 598 | if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 599 | (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
Glenn Randers-Pehrson | 2ad31ae | 2000-12-15 08:54:42 -0600 | [diff] [blame] | 600 | { |
| 601 | /* Intrapixel differencing */ |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 602 | png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1); |
Glenn Randers-Pehrson | 2ad31ae | 2000-12-15 08:54:42 -0600 | [diff] [blame] | 603 | } |
| 604 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 605 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 606 | |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 607 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED |
John Bowler | 9b872f4 | 2011-02-12 09:00:16 -0600 | [diff] [blame] | 608 | if (png_ptr->transformations) |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 609 | png_do_read_transformations(png_ptr, &row_info); |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 610 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 611 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 612 | /* The transformed pixel depth should match the depth now in row_info. */ |
| 613 | if (png_ptr->transformed_pixel_depth == 0) |
| 614 | { |
| 615 | png_ptr->transformed_pixel_depth = row_info.pixel_depth; |
| 616 | if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) |
| 617 | png_error(png_ptr, "sequential row overflow"); |
| 618 | } |
| 619 | |
| 620 | else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) |
| 621 | png_error(png_ptr, "internal sequential row size calculation error"); |
| 622 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 623 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 624 | /* Blow up interlaced rows to full size */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 625 | if (png_ptr->interlaced && |
| 626 | (png_ptr->transformations & PNG_INTERLACE)) |
| 627 | { |
| 628 | if (png_ptr->pass < 6) |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 629 | png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, |
| 630 | png_ptr->transformations); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 631 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 632 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 633 | png_combine_row(png_ptr, dsp_row, 1/*display*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 634 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 635 | if (row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 636 | png_combine_row(png_ptr, row, 0/*row*/); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 637 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 638 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 639 | else |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 640 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 641 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 642 | if (row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 643 | png_combine_row(png_ptr, row, -1/*ignored*/); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 644 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 645 | if (dsp_row != NULL) |
Glenn Randers-Pehrson | 65c0339 | 2011-10-06 21:54:17 -0500 | [diff] [blame] | 646 | png_combine_row(png_ptr, dsp_row, -1/*ignored*/); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 647 | } |
| 648 | png_read_finish_row(png_ptr); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 649 | |
| 650 | if (png_ptr->read_row_fn != NULL) |
| 651 | (*(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] | 652 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 653 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 654 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 655 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 656 | /* 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] | 657 | * and png_set_interlace_handling() has been called, the rows need to |
| 658 | * 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] | 659 | * image has alpha or transparency, and png_handle_alpha()[*] has been |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 660 | * called, the rows contents must be initialized to the contents of the |
| 661 | * screen. |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 662 | * |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 663 | * "row" holds the actual image, and pixels are placed in it |
| 664 | * as they arrive. If the image is displayed after each pass, it will |
| 665 | * appear to "sparkle" in. "display_row" can be used to display a |
| 666 | * "chunky" progressive image, with finer detail added as it becomes |
| 667 | * available. If you do not want this "chunky" display, you may pass |
| 668 | * NULL for display_row. If you do not want the sparkle display, and |
| 669 | * you have not called png_handle_alpha(), you may pass NULL for rows. |
| 670 | * If you have called png_handle_alpha(), and the image has either an |
| 671 | * alpha channel or a transparency chunk, you must provide a buffer for |
| 672 | * rows. In this case, you do not have to provide a display_row buffer |
| 673 | * also, but you may. If the image is not interlaced, or if you have |
| 674 | * not called png_set_interlace_handling(), the display_row buffer will |
| 675 | * be ignored, so pass NULL to it. |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 676 | * |
Glenn Randers-Pehrson | c3d51c1 | 2006-03-02 07:23:18 -0600 | [diff] [blame] | 677 | * [*] 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] | 678 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 679 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 680 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 681 | png_read_rows(png_structp png_ptr, png_bytepp row, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 682 | png_bytepp display_row, png_uint_32 num_rows) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 683 | { |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 684 | png_uint_32 i; |
| 685 | png_bytepp rp; |
| 686 | png_bytepp dp; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 687 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 688 | png_debug(1, "in png_read_rows"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 689 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 690 | if (png_ptr == NULL) |
| 691 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 692 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 693 | rp = row; |
| 694 | dp = display_row; |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 695 | if (rp != NULL && dp != NULL) |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 696 | for (i = 0; i < num_rows; i++) |
| 697 | { |
| 698 | png_bytep rptr = *rp++; |
| 699 | png_bytep dptr = *dp++; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 700 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 701 | png_read_row(png_ptr, rptr, dptr); |
| 702 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 703 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 704 | else if (rp != NULL) |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 705 | for (i = 0; i < num_rows; i++) |
| 706 | { |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 707 | png_bytep rptr = *rp; |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 708 | png_read_row(png_ptr, rptr, NULL); |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 709 | rp++; |
| 710 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 711 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 712 | else if (dp != NULL) |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 713 | for (i = 0; i < num_rows; i++) |
| 714 | { |
| 715 | png_bytep dptr = *dp; |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 716 | png_read_row(png_ptr, NULL, dptr); |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 717 | dp++; |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 718 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 719 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 720 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 721 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 722 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 723 | /* 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] | 724 | * 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] | 725 | * initialize the image to the current image that PNG will be overlaying. |
| 726 | * We set the num_rows again here, in case it was incorrectly set in |
| 727 | * png_read_start_row() by a call to png_read_update_info() or |
| 728 | * png_start_read_image() if png_set_interlace_handling() wasn't called |
| 729 | * prior to either of these functions like it should have been. You can |
| 730 | * only call this function once. If you desire to have an image for |
| 731 | * each pass of a interlaced image, use png_read_rows() instead. |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 732 | * |
Glenn Randers-Pehrson | c3d51c1 | 2006-03-02 07:23:18 -0600 | [diff] [blame] | 733 | * [*] 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] | 734 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 735 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 736 | png_read_image(png_structp png_ptr, png_bytepp image) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 737 | { |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 738 | png_uint_32 i, image_height; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 739 | int pass, j; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 740 | png_bytepp rp; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 741 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 742 | png_debug(1, "in png_read_image"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 743 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 744 | if (png_ptr == NULL) |
| 745 | return; |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 746 | |
| 747 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | 31aee0d | 2010-07-29 17:39:14 -0500 | [diff] [blame] | 748 | if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 749 | { |
| 750 | pass = png_set_interlace_handling(png_ptr); |
| 751 | /* And make sure transforms are initialized. */ |
| 752 | png_start_read_image(png_ptr); |
| 753 | } |
| 754 | else |
| 755 | { |
Glenn Randers-Pehrson | e15a96b | 2011-01-14 15:47:37 -0600 | [diff] [blame] | 756 | if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE)) |
Glenn Randers-Pehrson | 31aee0d | 2010-07-29 17:39:14 -0500 | [diff] [blame] | 757 | { |
Glenn Randers-Pehrson | 29034c5 | 2010-07-29 17:58:49 -0500 | [diff] [blame] | 758 | /* Caller called png_start_read_image or png_read_update_info without |
| 759 | * first turning on the PNG_INTERLACE transform. We can fix this here, |
| 760 | * but the caller should do it! |
| 761 | */ |
| 762 | png_warning(png_ptr, "Interlace handling should be turned on when " |
| 763 | "using png_read_image"); |
| 764 | /* Make sure this is set correctly */ |
| 765 | png_ptr->num_rows = png_ptr->height; |
Glenn Randers-Pehrson | 31aee0d | 2010-07-29 17:39:14 -0500 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in |
| 769 | * the above error case. |
| 770 | */ |
| 771 | pass = png_set_interlace_handling(png_ptr); |
| 772 | } |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 773 | #else |
| 774 | if (png_ptr->interlaced) |
| 775 | png_error(png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 776 | "Cannot read interlaced image -- interlace handler disabled"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 777 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 778 | pass = 1; |
| 779 | #endif |
| 780 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 781 | image_height=png_ptr->height; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 782 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 783 | for (j = 0; j < pass; j++) |
| 784 | { |
| 785 | rp = image; |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 786 | for (i = 0; i < image_height; i++) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 787 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 788 | png_read_row(png_ptr, *rp, NULL); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 789 | rp++; |
| 790 | } |
| 791 | } |
| 792 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 793 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 794 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 795 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 796 | /* 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] | 797 | * file, will verify the end is accurate, and will read any comments |
| 798 | * or time information at the end of the file, if info is not NULL. |
| 799 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 800 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 801 | png_read_end(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 802 | { |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 803 | png_debug(1, "in png_read_end"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 804 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 805 | if (png_ptr == NULL) |
| 806 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 807 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 808 | 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] | 809 | |
| 810 | do |
| 811 | { |
Glenn Randers-Pehrson | 895a9c9 | 2008-07-25 08:51:18 -0500 | [diff] [blame] | 812 | png_uint_32 length = png_read_chunk_header(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 813 | png_uint_32 chunk_name = png_ptr->chunk_name; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 814 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 815 | if (chunk_name == png_IHDR) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 816 | png_handle_IHDR(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 817 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 818 | else if (chunk_name == png_IEND) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 819 | png_handle_IEND(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 820 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 821 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 822 | else if (png_chunk_unknown_handling(png_ptr, chunk_name) != |
| 823 | PNG_HANDLE_CHUNK_AS_DEFAULT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 824 | { |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 825 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 826 | { |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 827 | if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 828 | png_benign_error(png_ptr, "Too many IDATs found"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 829 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 830 | png_handle_unknown(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 831 | if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 832 | png_ptr->mode |= PNG_HAVE_PLTE; |
| 833 | } |
| 834 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 835 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 836 | else if (chunk_name == png_IDAT) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 837 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 838 | /* Zero length IDATs are legal after the last IDAT has been |
| 839 | * read, but not after other chunks have been read. |
| 840 | */ |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 841 | if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 842 | png_benign_error(png_ptr, "Too many IDATs found"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 843 | |
Glenn Randers-Pehrson | 4accabb | 2000-04-14 14:20:47 -0500 | [diff] [blame] | 844 | png_crc_finish(png_ptr, length); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 845 | } |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 846 | else if (chunk_name == png_PLTE) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 847 | png_handle_PLTE(png_ptr, info_ptr, length); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 848 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 849 | #ifdef PNG_READ_bKGD_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 850 | else if (chunk_name == png_bKGD) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 851 | png_handle_bKGD(png_ptr, info_ptr, length); |
| 852 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 853 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 854 | #ifdef PNG_READ_cHRM_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 855 | else if (chunk_name == png_cHRM) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 856 | png_handle_cHRM(png_ptr, info_ptr, length); |
| 857 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 858 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 859 | #ifdef PNG_READ_gAMA_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 860 | else if (chunk_name == png_gAMA) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 861 | png_handle_gAMA(png_ptr, info_ptr, length); |
| 862 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 863 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 864 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 865 | else if (chunk_name == png_hIST) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 866 | png_handle_hIST(png_ptr, info_ptr, length); |
| 867 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 868 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 869 | #ifdef PNG_READ_oFFs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 870 | else if (chunk_name == png_oFFs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 871 | png_handle_oFFs(png_ptr, info_ptr, length); |
| 872 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 873 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 874 | #ifdef PNG_READ_pCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 875 | else if (chunk_name == png_pCAL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 876 | png_handle_pCAL(png_ptr, info_ptr, length); |
| 877 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 878 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 879 | #ifdef PNG_READ_sCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 880 | else if (chunk_name == png_sCAL) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 881 | png_handle_sCAL(png_ptr, info_ptr, length); |
| 882 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 883 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 884 | #ifdef PNG_READ_pHYs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 885 | else if (chunk_name == png_pHYs) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 886 | png_handle_pHYs(png_ptr, info_ptr, length); |
| 887 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 888 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 889 | #ifdef PNG_READ_sBIT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 890 | else if (chunk_name == png_sBIT) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 891 | png_handle_sBIT(png_ptr, info_ptr, length); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 892 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 893 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 894 | #ifdef PNG_READ_sRGB_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 895 | else if (chunk_name == png_sRGB) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 896 | png_handle_sRGB(png_ptr, info_ptr, length); |
| 897 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 898 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 899 | #ifdef PNG_READ_iCCP_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 900 | else if (chunk_name == png_iCCP) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 901 | png_handle_iCCP(png_ptr, info_ptr, length); |
| 902 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 903 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 904 | #ifdef PNG_READ_sPLT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 905 | else if (chunk_name == png_sPLT) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 906 | png_handle_sPLT(png_ptr, info_ptr, length); |
| 907 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 908 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 909 | #ifdef PNG_READ_tEXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 910 | else if (chunk_name == png_tEXt) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 911 | png_handle_tEXt(png_ptr, info_ptr, length); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 912 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 913 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 914 | #ifdef PNG_READ_tIME_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 915 | else if (chunk_name == png_tIME) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 916 | png_handle_tIME(png_ptr, info_ptr, length); |
| 917 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 918 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 919 | #ifdef PNG_READ_tRNS_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 920 | else if (chunk_name == png_tRNS) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 921 | png_handle_tRNS(png_ptr, info_ptr, length); |
| 922 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 923 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 924 | #ifdef PNG_READ_zTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 925 | else if (chunk_name == png_zTXt) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 926 | png_handle_zTXt(png_ptr, info_ptr, length); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 927 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 928 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 929 | #ifdef PNG_READ_iTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 930 | else if (chunk_name == png_iTXt) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 931 | png_handle_iTXt(png_ptr, info_ptr, length); |
| 932 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 933 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 934 | else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 935 | png_handle_unknown(png_ptr, info_ptr, length); |
| 936 | } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 937 | } |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 938 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 939 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 940 | /* Free all memory used by the read */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 941 | void PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 942 | 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] | 943 | png_infopp end_info_ptr_ptr) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 944 | { |
| 945 | png_structp png_ptr = NULL; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 946 | png_infop info_ptr = NULL, end_info_ptr = NULL; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 947 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 948 | png_free_ptr free_fn = NULL; |
| 949 | png_voidp mem_ptr = NULL; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 950 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 951 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 952 | png_debug(1, "in png_destroy_read_struct"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 953 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 954 | if (png_ptr_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 955 | png_ptr = *png_ptr_ptr; |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 956 | if (png_ptr == NULL) |
| 957 | return; |
| 958 | |
| 959 | #ifdef PNG_USER_MEM_SUPPORTED |
| 960 | free_fn = png_ptr->free_fn; |
| 961 | mem_ptr = png_ptr->mem_ptr; |
| 962 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 963 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 964 | if (info_ptr_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 965 | info_ptr = *info_ptr_ptr; |
| 966 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 967 | if (end_info_ptr_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 968 | end_info_ptr = *end_info_ptr_ptr; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 969 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 970 | png_read_destroy(png_ptr, info_ptr, end_info_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 971 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 972 | if (info_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 973 | { |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 974 | #ifdef PNG_TEXT_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 975 | png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 976 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 977 | |
| 978 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 979 | png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
| 980 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 981 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 982 | png_destroy_struct((png_voidp)info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 983 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 984 | *info_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 985 | } |
| 986 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 987 | if (end_info_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 988 | { |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 989 | #ifdef PNG_READ_TEXT_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 990 | 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] | 991 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 992 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 993 | 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] | 994 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 995 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 996 | png_destroy_struct((png_voidp)end_info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 997 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 998 | *end_info_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 999 | } |
| 1000 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1001 | if (png_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1002 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1003 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 1004 | png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
| 1005 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1006 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1007 | png_destroy_struct((png_voidp)png_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1008 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 1009 | *png_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 1013 | /* Free all memory used by the read (old method) */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1014 | void /* PRIVATE */ |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 1015 | png_read_destroy(png_structp png_ptr, png_infop info_ptr, |
| 1016 | png_infop end_info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1017 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1018 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1019 | jmp_buf tmp_jmp; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1020 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1021 | png_error_ptr error_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1022 | #ifdef PNG_WARNINGS_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1023 | png_error_ptr warning_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1024 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1025 | png_voidp error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1026 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1027 | png_free_ptr free_fn; |
| 1028 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1029 | |
Glenn Randers-Pehrson | 51650b8 | 2008-08-05 07:44:42 -0500 | [diff] [blame] | 1030 | png_debug(1, "in png_read_destroy"); |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 1031 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1032 | if (info_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1033 | png_info_destroy(png_ptr, info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1034 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1035 | if (end_info_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1036 | png_info_destroy(png_ptr, end_info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1037 | |
John Bowler | 07772cb | 2011-10-14 18:19:47 -0500 | [diff] [blame] | 1038 | #ifdef PNG_READ_GAMMA_SUPPORTED |
| 1039 | png_destroy_gamma_table(png_ptr); |
| 1040 | #endif |
| 1041 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1042 | png_free(png_ptr, png_ptr->zbuf); |
Glenn Randers-Pehrson | 1b8e567 | 2001-08-25 06:46:06 -0500 | [diff] [blame] | 1043 | png_free(png_ptr, png_ptr->big_row_buf); |
Mans Rullgard | 1c42276 | 2011-10-17 16:52:19 -0500 | [diff] [blame] | 1044 | png_free(png_ptr, png_ptr->big_prev_row); |
Glenn Randers-Pehrson | b3ff968 | 2008-07-21 08:05:57 -0500 | [diff] [blame] | 1045 | png_free(png_ptr, png_ptr->chunkdata); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1046 | |
Glenn Randers-Pehrson | 3cd7cff | 2010-04-16 19:27:08 -0500 | [diff] [blame] | 1047 | #ifdef PNG_READ_QUANTIZE_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1048 | png_free(png_ptr, png_ptr->palette_lookup); |
Glenn Randers-Pehrson | 3cd7cff | 2010-04-16 19:27:08 -0500 | [diff] [blame] | 1049 | png_free(png_ptr, png_ptr->quantize_index); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1050 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1051 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1052 | if (png_ptr->free_me & PNG_FREE_PLTE) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1053 | png_zfree(png_ptr, png_ptr->palette); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1054 | png_ptr->free_me &= ~PNG_FREE_PLTE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1055 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1056 | #if defined(PNG_tRNS_SUPPORTED) || \ |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1057 | defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1058 | if (png_ptr->free_me & PNG_FREE_TRNS) |
Glenn Randers-Pehrson | 6abea75 | 2009-08-08 16:52:06 -0500 | [diff] [blame] | 1059 | png_free(png_ptr, png_ptr->trans_alpha); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1060 | png_ptr->free_me &= ~PNG_FREE_TRNS; |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1061 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1062 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1063 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1064 | if (png_ptr->free_me & PNG_FREE_HIST) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1065 | png_free(png_ptr, png_ptr->hist); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1066 | png_ptr->free_me &= ~PNG_FREE_HIST; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1067 | #endif |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1068 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1069 | inflateEnd(&png_ptr->zstream); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1070 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1071 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1072 | png_free(png_ptr, png_ptr->save_buffer); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1073 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1074 | |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1075 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
| 1076 | #ifdef PNG_TEXT_SUPPORTED |
| 1077 | png_free(png_ptr, png_ptr->current_text); |
| 1078 | #endif /* PNG_TEXT_SUPPORTED */ |
| 1079 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
| 1080 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1081 | /* Save the important info out of the png_struct, in case it is |
| 1082 | * being used again. |
| 1083 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1084 | #ifdef PNG_SETJMP_SUPPORTED |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 1085 | 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] | 1086 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1087 | |
| 1088 | error_fn = png_ptr->error_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1089 | #ifdef PNG_WARNINGS_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1090 | warning_fn = png_ptr->warning_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1091 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1092 | error_ptr = png_ptr->error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1093 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1094 | free_fn = png_ptr->free_fn; |
| 1095 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1096 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1097 | png_memset(png_ptr, 0, png_sizeof(png_struct)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1098 | |
| 1099 | png_ptr->error_fn = error_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1100 | #ifdef PNG_WARNINGS_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1101 | png_ptr->warning_fn = warning_fn; |
John Bowler | 88b77cc | 2011-05-05 06:49:55 -0500 | [diff] [blame] | 1102 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1103 | png_ptr->error_ptr = error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1104 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1105 | png_ptr->free_fn = free_fn; |
| 1106 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1107 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1108 | #ifdef PNG_SETJMP_SUPPORTED |
John Bowler | e6dc85b | 2011-04-27 14:47:15 -0500 | [diff] [blame] | 1109 | 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] | 1110 | #endif |
| 1111 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1112 | } |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1113 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1114 | void PNGAPI |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1115 | png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) |
| 1116 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1117 | if (png_ptr == NULL) |
| 1118 | return; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1119 | |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1120 | png_ptr->read_row_fn = read_row_fn; |
| 1121 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1122 | |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame] | 1123 | |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 1124 | #ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1125 | #ifdef PNG_INFO_IMAGE_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1126 | void PNGAPI |
| 1127 | png_read_png(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1128 | int transforms, |
| 1129 | voidp params) |
| 1130 | { |
| 1131 | int row; |
| 1132 | |
John Bowler | 6a6d79f | 2011-02-12 08:56:40 -0600 | [diff] [blame] | 1133 | if (png_ptr == NULL || info_ptr == NULL) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1134 | return; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1135 | |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1136 | /* png_read_info() gives us all of the information from the |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1137 | * PNG file before the first IDAT (image data chunk). |
| 1138 | */ |
| 1139 | png_read_info(png_ptr, info_ptr); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1140 | if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) |
| 1141 | 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] | 1142 | |
| 1143 | /* -------------- image transformations start here ------------------- */ |
| 1144 | |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1145 | #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED |
Glenn Randers-Pehrson | 55fbff3 | 2011-05-17 06:49:32 -0500 | [diff] [blame] | 1146 | /* 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] | 1147 | */ |
Glenn Randers-Pehrson | ab63dd0 | 2011-06-17 20:04:17 -0500 | [diff] [blame] | 1148 | if (transforms & PNG_TRANSFORM_SCALE_16) |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1149 | { |
Glenn Randers-Pehrson | 6da2f2d | 2011-06-17 23:07:16 -0500 | [diff] [blame] | 1150 | /* Added at libpng-1.5.4. "strip_16" produces the same result that it |
| 1151 | * did in earlier versions, while "scale_16" is now more accurate. |
| 1152 | */ |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1153 | png_set_scale_16(png_ptr); |
| 1154 | } |
Glenn Randers-Pehrson | aee83b4 | 2011-06-18 00:19:54 -0500 | [diff] [blame] | 1155 | #endif |
| 1156 | |
| 1157 | #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED |
John Bowler | 8d26126 | 2011-06-18 13:37:11 -0500 | [diff] [blame] | 1158 | /* If both SCALE and STRIP are required pngrtran will effectively cancel the |
| 1159 | * latter by doing SCALE first. This is ok and allows apps not to check for |
| 1160 | * which is supported to get the right answer. |
| 1161 | */ |
| 1162 | if (transforms & PNG_TRANSFORM_STRIP_16) |
| 1163 | png_set_strip_16(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1164 | #endif |
| 1165 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1166 | #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1167 | /* Strip alpha bytes from the input data without combining with |
| 1168 | * the background (not recommended). |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1169 | */ |
| 1170 | if (transforms & PNG_TRANSFORM_STRIP_ALPHA) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1171 | png_set_strip_alpha(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1172 | #endif |
| 1173 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1174 | #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1175 | /* 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] | 1176 | * byte into separate bytes (useful for paletted and grayscale images). |
| 1177 | */ |
| 1178 | if (transforms & PNG_TRANSFORM_PACKING) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1179 | png_set_packing(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1180 | #endif |
| 1181 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1182 | #ifdef PNG_READ_PACKSWAP_SUPPORTED |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1183 | /* Change the order of packed pixels to least significant bit first |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1184 | * (not useful if you are using png_set_packing). |
| 1185 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1186 | if (transforms & PNG_TRANSFORM_PACKSWAP) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1187 | png_set_packswap(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1188 | #endif |
| 1189 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1190 | #ifdef PNG_READ_EXPAND_SUPPORTED |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1191 | /* Expand paletted colors into true RGB triplets |
| 1192 | * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel |
| 1193 | * Expand paletted or RGB images with transparency to full alpha |
| 1194 | * channels so the data will be available as RGBA quartets. |
| 1195 | */ |
| 1196 | if (transforms & PNG_TRANSFORM_EXPAND) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1197 | if ((png_ptr->bit_depth < 8) || |
| 1198 | (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || |
| 1199 | (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1200 | png_set_expand(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1201 | #endif |
| 1202 | |
Glenn Randers-Pehrson | 3cd7cff | 2010-04-16 19:27:08 -0500 | [diff] [blame] | 1203 | /* We don't handle background color or gamma transformation or quantizing. |
Glenn Randers-Pehrson | 272489d | 2004-08-04 06:34:52 -0500 | [diff] [blame] | 1204 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1205 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1206 | #ifdef PNG_READ_INVERT_SUPPORTED |
Glenn Randers-Pehrson | d8eb62f | 2009-05-30 20:19:20 -0500 | [diff] [blame] | 1207 | /* 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] | 1208 | */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1209 | if (transforms & PNG_TRANSFORM_INVERT_MONO) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1210 | png_set_invert_mono(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1211 | #endif |
| 1212 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1213 | #ifdef PNG_READ_SHIFT_SUPPORTED |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1214 | /* If you want to shift the pixel values from the range [0,255] or |
| 1215 | * [0,65535] to the original [0,7] or [0,31], or whatever range the |
| 1216 | * colors were originally in: |
| 1217 | */ |
| 1218 | if ((transforms & PNG_TRANSFORM_SHIFT) |
| 1219 | && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) |
| 1220 | { |
| 1221 | png_color_8p sig_bit; |
| 1222 | |
| 1223 | png_get_sBIT(png_ptr, info_ptr, &sig_bit); |
| 1224 | png_set_shift(png_ptr, sig_bit); |
| 1225 | } |
| 1226 | #endif |
| 1227 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1228 | #ifdef PNG_READ_BGR_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1229 | /* Flip the RGB pixels to BGR (or RGBA to BGRA) */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1230 | if (transforms & PNG_TRANSFORM_BGR) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1231 | png_set_bgr(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1232 | #endif |
| 1233 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1234 | #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1235 | /* 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] | 1236 | if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1237 | png_set_swap_alpha(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1238 | #endif |
| 1239 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1240 | #ifdef PNG_READ_SWAP_SUPPORTED |
Glenn Randers-Pehrson | 55fbff3 | 2011-05-17 06:49:32 -0500 | [diff] [blame] | 1241 | /* Swap bytes of 16-bit files to least significant byte first */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1242 | if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1243 | png_set_swap(png_ptr); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1244 | #endif |
| 1245 | |
Glenn Randers-Pehrson | c1a4d64 | 2009-10-29 23:29:24 -0500 | [diff] [blame] | 1246 | /* Added at libpng-1.2.41 */ |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1247 | #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1248 | /* Invert the alpha channel from opacity to transparency */ |
Glenn Randers-Pehrson | 6878eb6 | 2009-06-29 16:45:53 -0500 | [diff] [blame] | 1249 | if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1250 | png_set_invert_alpha(png_ptr); |
Glenn Randers-Pehrson | 6878eb6 | 2009-06-29 16:45:53 -0500 | [diff] [blame] | 1251 | #endif |
| 1252 | |
Glenn Randers-Pehrson | c1a4d64 | 2009-10-29 23:29:24 -0500 | [diff] [blame] | 1253 | /* Added at libpng-1.2.41 */ |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1254 | #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1255 | /* Expand grayscale image to RGB */ |
Glenn Randers-Pehrson | 99708d5 | 2009-06-29 17:30:00 -0500 | [diff] [blame] | 1256 | if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1257 | png_set_gray_to_rgb(png_ptr); |
Glenn Randers-Pehrson | 99708d5 | 2009-06-29 17:30:00 -0500 | [diff] [blame] | 1258 | #endif |
| 1259 | |
Glenn Randers-Pehrson | ef217b7 | 2011-06-15 12:58:27 -0500 | [diff] [blame] | 1260 | /* Added at libpng-1.5.4 */ |
John Bowler | 96cec0e | 2011-05-08 22:48:12 -0500 | [diff] [blame] | 1261 | #ifdef PNG_READ_EXPAND_16_SUPPORTED |
| 1262 | if (transforms & PNG_TRANSFORM_EXPAND_16) |
| 1263 | png_set_expand_16(png_ptr); |
| 1264 | #endif |
| 1265 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1266 | /* We don't handle adding filler bytes */ |
| 1267 | |
John Bowler | 6a6d79f | 2011-02-12 08:56:40 -0600 | [diff] [blame] | 1268 | /* We use png_read_image and rely on that for interlace handling, but we also |
| 1269 | * call png_read_update_info therefore must turn on interlace handling now: |
| 1270 | */ |
| 1271 | (void)png_set_interlace_handling(png_ptr); |
| 1272 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1273 | /* Optional call to gamma correct and add the background to the palette |
| 1274 | * and update info structure. REQUIRED if you are expecting libpng to |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1275 | * 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] | 1276 | */ |
| 1277 | png_read_update_info(png_ptr, info_ptr); |
| 1278 | |
| 1279 | /* -------------- image transformations end here ------------------- */ |
| 1280 | |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 1281 | png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 1282 | if (info_ptr->row_pointers == NULL) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1283 | { |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1284 | png_uint_32 iptr; |
Glenn Randers-Pehrson | d9f21ee | 2009-08-31 10:52:38 -0500 | [diff] [blame] | 1285 | |
Glenn Randers-Pehrson | 0ffb71a | 2009-02-28 06:08:20 -0600 | [diff] [blame] | 1286 | info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1287 | info_ptr->height * png_sizeof(png_bytep)); |
Glenn Randers-Pehrson | d9f21ee | 2009-08-31 10:52:38 -0500 | [diff] [blame] | 1288 | for (iptr=0; iptr<info_ptr->height; iptr++) |
| 1289 | info_ptr->row_pointers[iptr] = NULL; |
| 1290 | |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1291 | info_ptr->free_me |= PNG_FREE_ROWS; |
Glenn Randers-Pehrson | d9f21ee | 2009-08-31 10:52:38 -0500 | [diff] [blame] | 1292 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1293 | for (row = 0; row < (int)info_ptr->height; row++) |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1294 | info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1295 | png_get_rowbytes(png_ptr, info_ptr)); |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1296 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1297 | |
| 1298 | png_read_image(png_ptr, info_ptr->row_pointers); |
| 1299 | info_ptr->valid |= PNG_INFO_IDAT; |
| 1300 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1301 | /* 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] | 1302 | png_read_end(png_ptr, info_ptr); |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1303 | |
Glenn Randers-Pehrson | d546f43 | 2010-12-04 20:41:36 -0600 | [diff] [blame] | 1304 | PNG_UNUSED(transforms) /* Quiet compiler warnings */ |
| 1305 | PNG_UNUSED(params) |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1306 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1307 | } |
Glenn Randers-Pehrson | 9c3ab68 | 2006-02-20 22:09:05 -0600 | [diff] [blame] | 1308 | #endif /* PNG_INFO_IMAGE_SUPPORTED */ |
Glenn Randers-Pehrson | dbd4014 | 2009-08-31 08:42:02 -0500 | [diff] [blame] | 1309 | #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
John Bowler | 7875d53 | 2011-11-07 22:33:49 -0600 | [diff] [blame^] | 1310 | |
| 1311 | #ifdef PNG_SIMPLIFIED_READ_SUPPORTED |
| 1312 | /* SIMPLIFIED READ |
| 1313 | * |
| 1314 | * This code currently relies on the sequential reader, though it could easily |
| 1315 | * be made to work with the progressive one. |
| 1316 | */ |
| 1317 | /* Do all the *safe* initialization - 'safe' means that png_error won't be |
| 1318 | * called, so setting up the jmp_buf is not required. |
| 1319 | */ |
| 1320 | static int |
| 1321 | png_image_read_init(png_imagep image) |
| 1322 | { |
| 1323 | png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, image, |
| 1324 | png_safe_error, png_safe_warning); |
| 1325 | |
| 1326 | if (png_ptr != NULL) |
| 1327 | { |
| 1328 | png_infop info_ptr = png_create_info_struct(png_ptr); |
| 1329 | |
| 1330 | if (info_ptr != NULL) |
| 1331 | { |
| 1332 | png_controlp control = png_malloc_warn(png_ptr, sizeof *control); |
| 1333 | |
| 1334 | if (control != NULL) |
| 1335 | { |
| 1336 | memset(control, 0, sizeof *control); |
| 1337 | |
| 1338 | control->png_ptr = png_ptr; |
| 1339 | control->info_ptr = info_ptr; |
| 1340 | control->for_write = 0; |
| 1341 | |
| 1342 | image->opaque = control; |
| 1343 | return 1; |
| 1344 | } |
| 1345 | |
| 1346 | /* Error clean up */ |
| 1347 | png_destroy_info_struct(png_ptr, &info_ptr); |
| 1348 | } |
| 1349 | |
| 1350 | png_destroy_read_struct(&png_ptr, NULL, NULL); |
| 1351 | } |
| 1352 | |
| 1353 | return png_image_error(image, "png_image_read: out of memory"); |
| 1354 | } |
| 1355 | |
| 1356 | /* Utility to find the base format of a PNG file from a png_struct. */ |
| 1357 | static png_uint_32 |
| 1358 | png_image_format(png_structp png_ptr, png_infop info_ptr) |
| 1359 | { |
| 1360 | png_uint_32 format = 0; |
| 1361 | |
| 1362 | if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) |
| 1363 | format |= PNG_FORMAT_FLAG_COLOR; |
| 1364 | |
| 1365 | if (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
| 1366 | format |= PNG_FORMAT_FLAG_ALPHA; |
| 1367 | |
| 1368 | else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS)) |
| 1369 | format |= PNG_FORMAT_FLAG_ALPHA; |
| 1370 | |
| 1371 | if (png_ptr->bit_depth == 16) |
| 1372 | format |= PNG_FORMAT_FLAG_LINEAR; |
| 1373 | |
| 1374 | return format; |
| 1375 | } |
| 1376 | |
| 1377 | /* Do the main body of a 'png_image_begin_read' function; read the PNG file |
| 1378 | * header and fill in all the information. This is executed in a safe context, |
| 1379 | * unlike the init routine above. |
| 1380 | */ |
| 1381 | static int |
| 1382 | png_image_read_header(png_voidp argument) |
| 1383 | { |
| 1384 | png_imagep image = argument; |
| 1385 | png_structp png_ptr = image->opaque->png_ptr; |
| 1386 | png_infop info_ptr = image->opaque->info_ptr; |
| 1387 | |
| 1388 | png_read_info(png_ptr, info_ptr); |
| 1389 | |
| 1390 | /* Do this the fast way; just read directly out of png_struct. */ |
| 1391 | image->width = png_ptr->width; |
| 1392 | image->height = png_ptr->height; |
| 1393 | |
| 1394 | { |
| 1395 | png_uint_32 format = png_image_format(png_ptr, info_ptr); |
| 1396 | |
| 1397 | image->format = format; |
| 1398 | image->flags = 0; |
| 1399 | |
| 1400 | /* Now try to work out whether the color data does not match sRGB. */ |
| 1401 | if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && |
| 1402 | (info_ptr->valid & PNG_INFO_sRGB) == 0) |
| 1403 | { |
| 1404 | /* gamma is irrelevant because libpng does gamma correction, what |
| 1405 | * matters is if the cHRM chunk doesn't match or, in the absence of |
| 1406 | * cRHM, if the iCCP profile looks to have different end points. |
| 1407 | */ |
| 1408 | if (info_ptr->valid & PNG_INFO_cHRM) |
| 1409 | { |
| 1410 | /* TODO: this is a copy'n'paste from pngrutil.c, make a common |
| 1411 | * checking function. This checks for a 1% error. |
| 1412 | */ |
| 1413 | /* The cHRM chunk is used in preference to iCCP */ |
| 1414 | if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270, 1000) || |
| 1415 | PNG_OUT_OF_RANGE(info_ptr->y_white, 32900, 1000) || |
| 1416 | PNG_OUT_OF_RANGE(info_ptr->x_red, 64000, 1000) || |
| 1417 | PNG_OUT_OF_RANGE(info_ptr->y_red, 33000, 1000) || |
| 1418 | PNG_OUT_OF_RANGE(info_ptr->x_green, 30000, 1000) || |
| 1419 | PNG_OUT_OF_RANGE(info_ptr->y_green, 60000, 1000) || |
| 1420 | PNG_OUT_OF_RANGE(info_ptr->x_blue, 15000, 1000) || |
| 1421 | PNG_OUT_OF_RANGE(info_ptr->y_blue, 6000, 1000)) |
| 1422 | image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB; |
| 1423 | } |
| 1424 | |
| 1425 | else if (info_ptr->valid & PNG_INFO_iCCP) |
| 1426 | { |
| 1427 | # if 0 /* TODO: IMPLEMENT THIS! */ |
| 1428 | /* Here if we just have an iCCP chunk. */ |
| 1429 | if (!png_iCCP_is_sRGB(png_ptr, info_ptr)) |
| 1430 | # endif |
| 1431 | image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB; |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | return 1; |
| 1437 | } |
| 1438 | |
| 1439 | #ifdef PNG_STDIO_SUPPORTED |
| 1440 | int PNGAPI |
| 1441 | png_image_begin_read_from_stdio(png_imagep image, FILE* file) |
| 1442 | { |
| 1443 | if (image != NULL) |
| 1444 | { |
| 1445 | if (file != NULL) |
| 1446 | { |
| 1447 | if (png_image_read_init(image)) |
| 1448 | { |
| 1449 | /* This is slightly evil, but png_init_io doesn't do anything other |
| 1450 | * than this and we haven't changed the standard IO functions so |
| 1451 | * this saves a 'safe' function. |
| 1452 | */ |
| 1453 | image->opaque->png_ptr->io_ptr = file; |
| 1454 | return png_safe_execute(image, png_image_read_header, image); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | else |
| 1459 | return png_image_error(image, |
| 1460 | "png_image_begin_read_from_stdio: invalid argument"); |
| 1461 | } |
| 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | int PNGAPI |
| 1467 | png_image_begin_read_from_file(png_imagep image, const char *file_name) |
| 1468 | { |
| 1469 | if (image != NULL) |
| 1470 | { |
| 1471 | if (file_name != NULL) |
| 1472 | { |
| 1473 | FILE *fp = fopen(file_name, "rb"); |
| 1474 | |
| 1475 | if (fp != NULL) |
| 1476 | { |
| 1477 | if (png_image_read_init(image)) |
| 1478 | { |
| 1479 | image->opaque->png_ptr->io_ptr = fp; |
| 1480 | image->opaque->owned_file = 1; |
| 1481 | return png_safe_execute(image, png_image_read_header, image); |
| 1482 | } |
| 1483 | |
| 1484 | /* Clean up: just the opened file. */ |
| 1485 | (void)fclose(fp); |
| 1486 | } |
| 1487 | |
| 1488 | else |
| 1489 | return png_image_error(image, strerror(errno)); |
| 1490 | } |
| 1491 | |
| 1492 | else |
| 1493 | return png_image_error(image, |
| 1494 | "png_image_begin_read_from_file: invalid argument"); |
| 1495 | } |
| 1496 | |
| 1497 | return 0; |
| 1498 | } |
| 1499 | #endif /* PNG_STDIO_SUPPORTED */ |
| 1500 | |
| 1501 | static void PNGCBAPI |
| 1502 | png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need) |
| 1503 | { |
| 1504 | if (png_ptr != NULL) |
| 1505 | { |
| 1506 | png_imagep image = png_ptr->io_ptr; |
| 1507 | if (image != NULL) |
| 1508 | { |
| 1509 | png_controlp cp = image->opaque; |
| 1510 | if (cp != NULL) |
| 1511 | { |
| 1512 | png_const_bytep memory = cp->memory; |
| 1513 | png_size_t size = cp->size; |
| 1514 | |
| 1515 | if (memory != NULL && size >= need) |
| 1516 | { |
| 1517 | memcpy(out, memory, need); |
| 1518 | cp->memory = memory + need; |
| 1519 | cp->size = size - need; |
| 1520 | return; |
| 1521 | } |
| 1522 | |
| 1523 | png_error(png_ptr, "read beyond end of data"); |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | png_error(png_ptr, "invalid memory read"); |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | int PNGAPI png_image_begin_read_from_memory(png_imagep image, |
| 1532 | png_const_voidp memory, png_size_t size) |
| 1533 | { |
| 1534 | if (image != NULL) |
| 1535 | { |
| 1536 | if (memory != NULL && size > 0) |
| 1537 | { |
| 1538 | if (png_image_read_init(image)) |
| 1539 | { |
| 1540 | /* Now set the IO functions to read from the memory buffer and |
| 1541 | * store it into io_ptr. Again do this in-place to avoid calling a |
| 1542 | * libpng function that requires error handling. |
| 1543 | */ |
| 1544 | image->opaque->memory = memory; |
| 1545 | image->opaque->size = size; |
| 1546 | image->opaque->png_ptr->io_ptr = image; |
| 1547 | image->opaque->png_ptr->read_data_fn = png_image_memory_read; |
| 1548 | |
| 1549 | return png_safe_execute(image, png_image_read_header, image); |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | else |
| 1554 | return png_image_error(image, |
| 1555 | "png_image_begin_read_from_memory: invalid argument"); |
| 1556 | } |
| 1557 | |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | /* Arguments to png_image_finish_read: */ |
| 1562 | typedef struct |
| 1563 | { |
| 1564 | /* Arguments: */ |
| 1565 | png_imagep image; |
| 1566 | png_voidp buffer; |
| 1567 | png_int_32 row_stride; |
| 1568 | png_colorp background; |
| 1569 | /* Local variables: */ |
| 1570 | png_bytep local_row; |
| 1571 | png_bytep first_row; |
| 1572 | ptrdiff_t row_bytes; /* unsigned arithmetic step between rows */ |
| 1573 | } png_image_read_control; |
| 1574 | |
| 1575 | /* Just the row reading part of png_image_read. */ |
| 1576 | static int |
| 1577 | png_image_read_composite(png_voidp argument) |
| 1578 | { |
| 1579 | png_image_read_control *display = argument; |
| 1580 | png_imagep image = display->image; |
| 1581 | png_structp png_ptr = image->opaque->png_ptr; |
| 1582 | png_byte interlace_type = png_ptr->interlaced; |
| 1583 | int passes; |
| 1584 | |
| 1585 | switch (interlace_type) |
| 1586 | { |
| 1587 | case PNG_INTERLACE_NONE: |
| 1588 | passes = 1; |
| 1589 | break; |
| 1590 | |
| 1591 | case PNG_INTERLACE_ADAM7: |
| 1592 | passes = PNG_INTERLACE_ADAM7_PASSES; |
| 1593 | break; |
| 1594 | |
| 1595 | default: |
| 1596 | png_error(png_ptr, "unknown interlace type"); |
| 1597 | } |
| 1598 | |
| 1599 | { |
| 1600 | png_uint_32 height = image->height; |
| 1601 | png_uint_32 width = image->width; |
| 1602 | unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) ? 3 : 1; |
| 1603 | int pass; |
| 1604 | |
| 1605 | for (pass = 0; pass < passes; ++pass) |
| 1606 | { |
| 1607 | png_bytep row = display->first_row; |
| 1608 | unsigned int startx, stepx, stepy; |
| 1609 | png_uint_32 y; |
| 1610 | |
| 1611 | if (interlace_type == PNG_INTERLACE_ADAM7) |
| 1612 | { |
| 1613 | /* The row may be empty for a short image: */ |
| 1614 | if (PNG_PASS_COLS(width, pass) == 0) |
| 1615 | continue; |
| 1616 | |
| 1617 | startx = PNG_PASS_START_COL(pass); |
| 1618 | stepx = PNG_PASS_COL_OFFSET(pass); |
| 1619 | y = PNG_PASS_START_ROW(pass); |
| 1620 | stepy = PNG_PASS_COL_OFFSET(pass); |
| 1621 | } |
| 1622 | |
| 1623 | else |
| 1624 | { |
| 1625 | y = 0; |
| 1626 | startx = 0; |
| 1627 | stepx = stepy = 1; |
| 1628 | } |
| 1629 | |
| 1630 | for (; y<height; y += stepy) |
| 1631 | if (interlace_type == PNG_INTERLACE_NONE || |
| 1632 | PNG_ROW_IN_INTERLACE_PASS(y, pass)) |
| 1633 | { |
| 1634 | png_bytep inrow = display->local_row; |
| 1635 | png_bytep outrow = row; |
| 1636 | png_uint_32 x; |
| 1637 | |
| 1638 | /* Read the row, which is packed: */ |
| 1639 | png_read_row(png_ptr, inrow, NULL); |
| 1640 | |
| 1641 | /* Now do the composition on each pixel in this row. */ |
| 1642 | for (x = startx; x<width; x += stepx, outrow += stepx*channels) |
| 1643 | { |
| 1644 | png_byte alpha = inrow[channels]; |
| 1645 | |
| 1646 | if (alpha > 0) /* else no change to the output */ |
| 1647 | { |
| 1648 | unsigned int c; |
| 1649 | |
| 1650 | for (c=0; c<channels; ++c) |
| 1651 | { |
| 1652 | png_uint_32 component = inrow[c]; |
| 1653 | |
| 1654 | if (alpha < 255) /* else just use component */ |
| 1655 | { |
| 1656 | /* This is PNG_OPTIMIZED_ALPHA, the component value |
| 1657 | * is a linear 8-bit value. Combine this with the |
| 1658 | * current outrow[c] value which is sRGB encoded. |
| 1659 | * Arithmetic here is 16-bits to preserve the output |
| 1660 | * values correctly. |
| 1661 | */ |
| 1662 | component *= 257*255; /* =65535 */ |
| 1663 | component += (255-alpha)*png_sRGB_table[outrow[c]]; |
| 1664 | |
| 1665 | /* So 'component' is scaled by 255*65535 and is |
| 1666 | * therefore appropriate for the above tables. |
| 1667 | */ |
| 1668 | component = PNG_sRGB_FROM_LINEAR(component); |
| 1669 | } |
| 1670 | |
| 1671 | outrow[c] = (png_byte)component; |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | inrow += channels+1; /* components and alpha channel */ |
| 1676 | } |
| 1677 | |
| 1678 | row += display->row_bytes; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | return 1; |
| 1684 | } |
| 1685 | |
| 1686 | /* The guts of png_image_finish_read as a png_safe_execute callback. */ |
| 1687 | static int |
| 1688 | png_image_read_end(png_voidp argument) |
| 1689 | { |
| 1690 | png_image_read_control *display = argument; |
| 1691 | png_imagep image = display->image; |
| 1692 | png_structp png_ptr = image->opaque->png_ptr; |
| 1693 | png_infop info_ptr = image->opaque->info_ptr; |
| 1694 | |
| 1695 | png_uint_32 format = image->format; |
| 1696 | int linear = (format & PNG_FORMAT_FLAG_LINEAR) != 0; |
| 1697 | int do_local_compose = 0; |
| 1698 | int passes = 0; |
| 1699 | |
| 1700 | /* Add transforms to ensure the correct output format is produced then check |
| 1701 | * that the required implementation support is there. Always expand; always |
| 1702 | * need 8 bits minimum, no palette and expanded tRNS. |
| 1703 | */ |
| 1704 | png_set_expand(png_ptr); |
| 1705 | |
| 1706 | /* Now check the format to see if it was modified. */ |
| 1707 | { |
| 1708 | png_uint_32 base_format = png_image_format(png_ptr, info_ptr); |
| 1709 | png_uint_32 change = format ^ base_format; |
| 1710 | |
| 1711 | /* Set the gamma appropriately, linear for 16-bit input, sRGB otherwise. |
| 1712 | */ |
| 1713 | { |
| 1714 | png_fixed_point input_gamma_default, output_gamma; |
| 1715 | int mode; |
| 1716 | |
| 1717 | if (base_format & PNG_FORMAT_FLAG_LINEAR) |
| 1718 | input_gamma_default = PNG_GAMMA_LINEAR; |
| 1719 | else |
| 1720 | input_gamma_default = PNG_DEFAULT_sRGB; |
| 1721 | |
| 1722 | if (linear) |
| 1723 | { |
| 1724 | mode = PNG_ALPHA_STANDARD; |
| 1725 | output_gamma = PNG_GAMMA_LINEAR; |
| 1726 | } |
| 1727 | |
| 1728 | else |
| 1729 | { |
| 1730 | mode = PNG_ALPHA_PNG; |
| 1731 | output_gamma = PNG_DEFAULT_sRGB; |
| 1732 | } |
| 1733 | |
| 1734 | /* Set the mode, the default gamma for the file and then, if it |
| 1735 | * doesn't match the default, the output gamma. |
| 1736 | */ |
| 1737 | png_set_alpha_mode_fixed(png_ptr, mode, input_gamma_default); |
| 1738 | if (input_gamma_default != output_gamma) |
| 1739 | png_set_alpha_mode(png_ptr, mode, output_gamma); |
| 1740 | |
| 1741 | /* If the bit-depth changes then handle that here. */ |
| 1742 | if (change & PNG_FORMAT_FLAG_LINEAR) |
| 1743 | { |
| 1744 | if (linear /*16-bit output*/) |
| 1745 | png_set_expand_16(png_ptr); |
| 1746 | |
| 1747 | else /* 8-bit output */ |
| 1748 | png_set_scale_16(png_ptr); |
| 1749 | |
| 1750 | change &= ~PNG_FORMAT_FLAG_LINEAR; |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | /* Now the background/alpha channel changes. */ |
| 1755 | if (change & PNG_FORMAT_FLAG_ALPHA) |
| 1756 | { |
| 1757 | /* Removing an alpha channel requires composition for the 8-bit |
| 1758 | * formats; for the 16-bit it is already done, above, by the |
| 1759 | * pre-multiplication and the channel just needs to be stripped. |
| 1760 | */ |
| 1761 | if (base_format & PNG_FORMAT_FLAG_ALPHA) |
| 1762 | { |
| 1763 | if (linear) /* compose on black (well, pre-multiply) */ |
| 1764 | png_set_strip_alpha(png_ptr); |
| 1765 | |
| 1766 | else if (display->background != NULL) |
| 1767 | { |
| 1768 | png_color_16 c; |
| 1769 | |
| 1770 | c.index = 0; /*unused*/ |
| 1771 | c.red = display->background->red; |
| 1772 | c.green = display->background->green; |
| 1773 | c.blue = display->background->blue; |
| 1774 | c.gray = display->background->green; |
| 1775 | |
| 1776 | /* This is always an 8-bit sRGB value, using the 'green' channel |
| 1777 | * for gray is much better than calculating the luminance here; |
| 1778 | * we can get off-by-one errors in that calculation relative to |
| 1779 | * the app expectations and that will show up in transparent |
| 1780 | * pixels. |
| 1781 | */ |
| 1782 | png_set_background_fixed(png_ptr, &c, |
| 1783 | PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/, |
| 1784 | 0/*gamma: not used*/); |
| 1785 | } |
| 1786 | |
| 1787 | else /* compose on row: implemented below. */ |
| 1788 | { |
| 1789 | do_local_compose = 1; |
| 1790 | /* This leaves the alpha channel in the output, it has to be |
| 1791 | * removed by the code below. Set the encoding to the 'OPTIMIZE' |
| 1792 | * one so the code only has to hack on the pixels that require |
| 1793 | * composition. |
| 1794 | */ |
| 1795 | png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED, |
| 1796 | PNG_DEFAULT_sRGB); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | else /* output needs an alpha channel */ |
| 1801 | { |
| 1802 | /* This is tricky because it happens before the swap operation has |
| 1803 | * been accomplished, so always add the alpha channel after the |
| 1804 | * component channels. |
| 1805 | */ |
| 1806 | png_set_add_alpha(png_ptr, 255/*opaque*/, PNG_FILLER_AFTER); |
| 1807 | } |
| 1808 | |
| 1809 | change &= ~PNG_FORMAT_FLAG_ALPHA; |
| 1810 | } |
| 1811 | |
| 1812 | if (change & PNG_FORMAT_FLAG_COLOR) |
| 1813 | { |
| 1814 | /* gray<->color transformation required. */ |
| 1815 | if (format & PNG_FORMAT_FLAG_COLOR) |
| 1816 | png_set_gray_to_rgb(png_ptr); |
| 1817 | |
| 1818 | else |
| 1819 | png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, |
| 1820 | PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT); |
| 1821 | |
| 1822 | change &= ~PNG_FORMAT_FLAG_COLOR; |
| 1823 | } |
| 1824 | |
| 1825 | # ifdef PNG_FORMAT_BGR_SUPPORTED |
| 1826 | if (format & PNG_FORMAT_FLAG_BGR) |
| 1827 | { |
| 1828 | /* Check only the output format; PNG is never BGR, don't do this if |
| 1829 | * the output is gray, but fix up the 'format' value in that case. |
| 1830 | */ |
| 1831 | if (format & PNG_FORMAT_FLAG_COLOR) |
| 1832 | png_set_bgr(png_ptr); |
| 1833 | |
| 1834 | else |
| 1835 | format &= ~PNG_FORMAT_FLAG_BGR; |
| 1836 | |
| 1837 | change &= ~PNG_FORMAT_FLAG_BGR; |
| 1838 | } |
| 1839 | # endif |
| 1840 | |
| 1841 | # ifdef PNG_FORMAT_AFIRST_SUPPORTED |
| 1842 | if (format & PNG_FORMAT_FLAG_AFIRST) |
| 1843 | { |
| 1844 | /* Only relevant if there is an alpha channel - it's particularly |
| 1845 | * important to handle this correctly because do_local_compose may |
| 1846 | * be set above and then libpng will keep the alpha channel for this |
| 1847 | * code to remove. |
| 1848 | */ |
| 1849 | if (format & PNG_FORMAT_FLAG_ALPHA) |
| 1850 | png_set_swap_alpha(png_ptr); |
| 1851 | |
| 1852 | else |
| 1853 | format &= ~PNG_FORMAT_FLAG_AFIRST; |
| 1854 | |
| 1855 | change &= ~PNG_FORMAT_FLAG_AFIRST; |
| 1856 | } |
| 1857 | # endif |
| 1858 | |
| 1859 | /* If the *output* is 16-bit then we need to check for a byte-swap on this |
| 1860 | * architecture. |
| 1861 | */ |
| 1862 | if (linear) |
| 1863 | { |
| 1864 | PNG_CONST png_uint_16 le = 0x0001; |
| 1865 | |
| 1866 | if (*(png_const_bytep)&le) |
| 1867 | png_set_swap(png_ptr); |
| 1868 | } |
| 1869 | |
| 1870 | /* If change is not now 0 some transformation is missing - error out. */ |
| 1871 | if (change) |
| 1872 | png_error(png_ptr, "png_read_image: unsupported transformation"); |
| 1873 | } |
| 1874 | |
| 1875 | /* Update the 'info' structure and make sure the result is as required, first |
| 1876 | * make sure to turn on the interlace handling if it will be required |
| 1877 | * (because it can't be turned on *after* the call to png_read_update_info!) |
| 1878 | */ |
| 1879 | if (!do_local_compose) |
| 1880 | passes = png_set_interlace_handling(png_ptr); |
| 1881 | |
| 1882 | png_read_update_info(png_ptr, info_ptr); |
| 1883 | |
| 1884 | { |
| 1885 | png_uint_32 info_format = 0; |
| 1886 | |
| 1887 | if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) |
| 1888 | info_format |= PNG_FORMAT_FLAG_COLOR; |
| 1889 | |
| 1890 | if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
| 1891 | { |
| 1892 | /* This channel may be removed below. */ |
| 1893 | if (!do_local_compose) |
| 1894 | info_format |= PNG_FORMAT_FLAG_ALPHA; |
| 1895 | } |
| 1896 | |
| 1897 | else if (do_local_compose) /* internal error */ |
| 1898 | png_error(png_ptr, "png_image_read: alpha channel lost"); |
| 1899 | |
| 1900 | if (info_ptr->bit_depth == 16) |
| 1901 | info_format |= PNG_FORMAT_FLAG_LINEAR; |
| 1902 | |
| 1903 | # ifdef PNG_FORMAT_BGR_SUPPORTED |
| 1904 | if (png_ptr->transformations & PNG_BGR) |
| 1905 | info_format |= PNG_FORMAT_FLAG_BGR; |
| 1906 | # endif |
| 1907 | |
| 1908 | # ifdef PNG_FORMAT_AFIRST_SUPPORTED |
| 1909 | if (png_ptr->transformations & PNG_SWAP_ALPHA) |
| 1910 | info_format |= PNG_FORMAT_FLAG_AFIRST; |
| 1911 | # endif |
| 1912 | |
| 1913 | /* This is actually an internal error. */ |
| 1914 | if (info_format != format) |
| 1915 | png_error(png_ptr, "png_read_image: invalid transformations"); |
| 1916 | } |
| 1917 | |
| 1918 | /* Now read the rows. If do_local_compose is set then it is necessary to use |
| 1919 | * a local row buffer. The output will be GA, RGBA or BGRA and must be |
| 1920 | * converted to G, RGB or BGR as appropriate. The 'local_row' member of the |
| 1921 | * display acts as a flag. |
| 1922 | */ |
| 1923 | { |
| 1924 | png_bytep first_row = display->buffer; |
| 1925 | ptrdiff_t row_bytes = display->row_stride; |
| 1926 | |
| 1927 | if (linear) |
| 1928 | row_bytes *= sizeof (png_uint_16); |
| 1929 | |
| 1930 | /* The following expression is designed to work correctly whether it gives |
| 1931 | * a signed or an unsigned result. |
| 1932 | */ |
| 1933 | if (row_bytes < 0) |
| 1934 | first_row += (image->height-1) * (-row_bytes); |
| 1935 | |
| 1936 | display->first_row = first_row; |
| 1937 | display->row_bytes = row_bytes; |
| 1938 | } |
| 1939 | |
| 1940 | if (do_local_compose) |
| 1941 | { |
| 1942 | int result; |
| 1943 | png_bytep row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); |
| 1944 | |
| 1945 | display->local_row = row; |
| 1946 | result = png_safe_execute(image, png_image_read_composite, display); |
| 1947 | display->local_row = NULL; |
| 1948 | png_free(png_ptr, row); |
| 1949 | |
| 1950 | return result; |
| 1951 | } |
| 1952 | |
| 1953 | else |
| 1954 | { |
| 1955 | png_alloc_size_t row_bytes = display->row_bytes; |
| 1956 | |
| 1957 | while (--passes >= 0) |
| 1958 | { |
| 1959 | png_uint_32 y = image->height; |
| 1960 | png_bytep row = display->first_row; |
| 1961 | |
| 1962 | while (y-- > 0) |
| 1963 | { |
| 1964 | png_read_row(png_ptr, row, NULL); |
| 1965 | row += row_bytes; |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | return 1; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | int PNGAPI |
| 1974 | png_image_finish_read(png_imagep image, png_colorp background, void *buffer, |
| 1975 | png_int_32 row_stride) |
| 1976 | { |
| 1977 | if (image != NULL) |
| 1978 | { |
| 1979 | png_uint_32 check; |
| 1980 | |
| 1981 | if (row_stride < 0) |
| 1982 | check = -row_stride; |
| 1983 | |
| 1984 | else |
| 1985 | check = row_stride; |
| 1986 | |
| 1987 | if (buffer != NULL && check >= PNG_IMAGE_ROW_STRIDE(*image)) |
| 1988 | { |
| 1989 | int result; |
| 1990 | png_image_read_control display; |
| 1991 | |
| 1992 | memset(&display, 0, sizeof display); |
| 1993 | display.image = image; |
| 1994 | display.buffer = buffer; |
| 1995 | display.row_stride = row_stride; |
| 1996 | display.background = background; |
| 1997 | display.local_row = NULL; |
| 1998 | result = png_safe_execute(image, png_image_read_end, &display); |
| 1999 | png_image_free(image); |
| 2000 | return result; |
| 2001 | } |
| 2002 | |
| 2003 | else |
| 2004 | return png_image_error(image, |
| 2005 | "png_image_finish_read: invalid argument"); |
| 2006 | } |
| 2007 | |
| 2008 | return 0; |
| 2009 | } |
| 2010 | |
| 2011 | #endif /* PNG_SIMPLIFIED_READ_SUPPORTED */ |
Glenn Randers-Pehrson | 9c3ab68 | 2006-02-20 22:09:05 -0600 | [diff] [blame] | 2012 | #endif /* PNG_READ_SUPPORTED */ |