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