Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1 | |
| 2 | /* pngpread.c - read a png file in push mode |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | eb657ae | 2014-02-22 21:59:40 -0600 | [diff] [blame] | 4 | * Last changed in libpng 1.6.10 [(PENDING RELEASE)] |
| 5 | * Copyright (c) 1998-2014 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 | 3e61d79 | 2009-06-24 09:31:28 -0500 | [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 | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 12 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 13 | |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 14 | #include "pngpriv.h" |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 15 | |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 16 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
| 17 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 18 | /* Push model modes */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 19 | #define PNG_READ_SIG_MODE 0 |
| 20 | #define PNG_READ_CHUNK_MODE 1 |
| 21 | #define PNG_READ_IDAT_MODE 2 |
| 22 | #define PNG_SKIP_MODE 3 |
| 23 | #define PNG_READ_tEXt_MODE 4 |
| 24 | #define PNG_READ_zTXt_MODE 5 |
| 25 | #define PNG_READ_DONE_MODE 6 |
| 26 | #define PNG_READ_iTXt_MODE 7 |
| 27 | #define PNG_ERROR_MODE 8 |
| 28 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 29 | void PNGAPI |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 30 | png_process_data(png_structrp png_ptr, png_inforp info_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 31 | png_bytep buffer, png_size_t buffer_size) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 32 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 33 | if (png_ptr == NULL || info_ptr == NULL) |
| 34 | return; |
| 35 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 36 | png_push_restore_buffer(png_ptr, buffer, buffer_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 37 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 38 | while (png_ptr->buffer_size) |
| 39 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 40 | png_process_some_data(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 41 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 42 | } |
| 43 | |
John Bowler | 0a5c9c0 | 2011-01-22 17:36:34 -0600 | [diff] [blame] | 44 | png_size_t PNGAPI |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 45 | png_process_data_pause(png_structrp png_ptr, int save) |
John Bowler | 0a5c9c0 | 2011-01-22 17:36:34 -0600 | [diff] [blame] | 46 | { |
| 47 | if (png_ptr != NULL) |
| 48 | { |
| 49 | /* It's easiest for the caller if we do the save, then the caller doesn't |
| 50 | * have to supply the same data again: |
| 51 | */ |
| 52 | if (save) |
| 53 | png_push_save_buffer(png_ptr); |
| 54 | else |
| 55 | { |
| 56 | /* This includes any pending saved bytes: */ |
| 57 | png_size_t remaining = png_ptr->buffer_size; |
| 58 | png_ptr->buffer_size = 0; |
| 59 | |
| 60 | /* So subtract the saved buffer size, unless all the data |
| 61 | * is actually 'saved', in which case we just return 0 |
| 62 | */ |
| 63 | if (png_ptr->save_buffer_size < remaining) |
| 64 | return remaining - png_ptr->save_buffer_size; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | png_uint_32 PNGAPI |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 72 | png_process_data_skip(png_structrp png_ptr) |
John Bowler | 0a5c9c0 | 2011-01-22 17:36:34 -0600 | [diff] [blame] | 73 | { |
John Bowler | fca50df | 2011-01-28 06:34:02 -0600 | [diff] [blame] | 74 | png_uint_32 remaining = 0; |
John Bowler | 0a5c9c0 | 2011-01-22 17:36:34 -0600 | [diff] [blame] | 75 | |
| 76 | if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE && |
| 77 | png_ptr->skip_length > 0) |
| 78 | { |
| 79 | /* At the end of png_process_data the buffer size must be 0 (see the loop |
| 80 | * above) so we can detect a broken call here: |
| 81 | */ |
| 82 | if (png_ptr->buffer_size != 0) |
| 83 | png_error(png_ptr, |
| 84 | "png_process_data_skip called inside png_process_data"); |
| 85 | |
| 86 | /* If is impossible for there to be a saved buffer at this point - |
| 87 | * otherwise we could not be in SKIP mode. This will also happen if |
| 88 | * png_process_skip is called inside png_process_data (but only very |
| 89 | * rarely.) |
| 90 | */ |
| 91 | if (png_ptr->save_buffer_size != 0) |
| 92 | png_error(png_ptr, "png_process_data_skip called with saved data"); |
| 93 | |
| 94 | remaining = png_ptr->skip_length; |
| 95 | png_ptr->skip_length = 0; |
| 96 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
| 97 | } |
| 98 | |
| 99 | return remaining; |
| 100 | } |
| 101 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 102 | /* What we do with the incoming data depends on what we were previously |
| 103 | * doing before we ran out of data... |
| 104 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 105 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 106 | png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 107 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 108 | if (png_ptr == NULL) |
| 109 | return; |
| 110 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 111 | switch (png_ptr->process_mode) |
| 112 | { |
| 113 | case PNG_READ_SIG_MODE: |
| 114 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 115 | png_push_read_sig(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 116 | break; |
| 117 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 118 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 119 | case PNG_READ_CHUNK_MODE: |
| 120 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 121 | png_push_read_chunk(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 122 | break; |
| 123 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 124 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 125 | case PNG_READ_IDAT_MODE: |
| 126 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 127 | png_push_read_IDAT(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 128 | break; |
| 129 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 130 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 131 | case PNG_SKIP_MODE: |
| 132 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 133 | png_push_crc_finish(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 134 | break; |
| 135 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 136 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 137 | default: |
| 138 | { |
| 139 | png_ptr->buffer_size = 0; |
| 140 | break; |
| 141 | } |
| 142 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 143 | } |
| 144 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 145 | /* Read any remaining signature bytes from the stream and compare them with |
| 146 | * the correct PNG signature. It is possible that this routine is called |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 147 | * with bytes already read from the signature, either because they have been |
| 148 | * checked by the calling application, or because of multiple calls to this |
| 149 | * routine. |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 150 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 151 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 152 | png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 153 | { |
Glenn Randers-Pehrson | bc8e40d | 2013-07-15 08:44:53 -0500 | [diff] [blame] | 154 | png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 155 | num_to_check = 8 - num_checked; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 156 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 157 | if (png_ptr->buffer_size < num_to_check) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 158 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 159 | num_to_check = png_ptr->buffer_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 160 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 161 | |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 162 | png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 163 | num_to_check); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 164 | png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 165 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 166 | if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 167 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 168 | if (num_checked < 4 && |
| 169 | png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) |
| 170 | png_error(png_ptr, "Not a PNG file"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 171 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 172 | else |
| 173 | png_error(png_ptr, "PNG file corrupted by ASCII conversion"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 174 | } |
| 175 | else |
| 176 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 177 | if (png_ptr->sig_bytes >= 8) |
| 178 | { |
| 179 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
| 180 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 181 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 182 | } |
| 183 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 184 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 185 | png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 186 | { |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 187 | png_uint_32 chunk_name; |
Glenn Randers-Pehrson | bd757ac | 2013-11-18 18:40:39 -0600 | [diff] [blame] | 188 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 189 | int keep; /* unknown handling method */ |
| 190 | #endif |
Glenn Randers-Pehrson | a2567be | 2009-10-19 20:31:31 -0500 | [diff] [blame] | 191 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 192 | /* First we make sure we have enough data for the 4 byte chunk name |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 193 | * and the 4 byte chunk length before proceeding with decoding the |
| 194 | * chunk data. To fully decode each of these chunks, we also make |
| 195 | * sure we have enough data in the buffer for the 4 byte CRC at the |
| 196 | * end of every chunk (except IDAT, which is handled separately). |
| 197 | */ |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 198 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 199 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 200 | png_byte chunk_length[4]; |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 201 | png_byte chunk_tag[4]; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 202 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 203 | if (png_ptr->buffer_size < 8) |
| 204 | { |
| 205 | png_push_save_buffer(png_ptr); |
| 206 | return; |
| 207 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 208 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 209 | png_push_fill_buffer(png_ptr, chunk_length, 4); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 210 | png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 211 | png_reset_crc(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 212 | png_crc_read(png_ptr, chunk_tag, 4); |
| 213 | png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); |
Glenn Randers-Pehrson | eb58091 | 2008-07-30 14:47:09 -0500 | [diff] [blame] | 214 | png_check_chunk_name(png_ptr, png_ptr->chunk_name); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 215 | png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 216 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 217 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 218 | chunk_name = png_ptr->chunk_name; |
| 219 | |
| 220 | if (chunk_name == png_IDAT) |
Glenn Randers-Pehrson | 4daae30 | 2011-10-06 21:37:47 -0500 | [diff] [blame] | 221 | { |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 222 | if (png_ptr->mode & PNG_AFTER_IDAT) |
| 223 | png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 224 | |
| 225 | /* If we reach an IDAT chunk, this means we have read all of the |
| 226 | * header chunks, and we can start reading the image (or if this |
| 227 | * is called after the image has been read - we have an error). |
| 228 | */ |
| 229 | if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 230 | png_error(png_ptr, "Missing IHDR before IDAT"); |
| 231 | |
| 232 | else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
| 233 | !(png_ptr->mode & PNG_HAVE_PLTE)) |
| 234 | png_error(png_ptr, "Missing PLTE before IDAT"); |
| 235 | |
| 236 | png_ptr->mode |= PNG_HAVE_IDAT; |
Glenn Randers-Pehrson | eb657ae | 2014-02-22 21:59:40 -0600 | [diff] [blame] | 237 | png_ptr->process_mode = PNG_READ_IDAT_MODE; |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 238 | |
| 239 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
| 240 | if (png_ptr->push_length == 0) |
| 241 | return; |
| 242 | |
| 243 | if (png_ptr->mode & PNG_AFTER_IDAT) |
| 244 | png_benign_error(png_ptr, "Too many IDATs found"); |
Glenn Randers-Pehrson | 4daae30 | 2011-10-06 21:37:47 -0500 | [diff] [blame] | 245 | } |
Glenn Randers-Pehrson | 6bc53be | 2006-06-16 07:52:03 -0500 | [diff] [blame] | 246 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 247 | if (chunk_name == png_IHDR) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 248 | { |
Glenn Randers-Pehrson | eb58091 | 2008-07-30 14:47:09 -0500 | [diff] [blame] | 249 | if (png_ptr->push_length != 13) |
| 250 | png_error(png_ptr, "Invalid IHDR length"); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 251 | |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 252 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 253 | { |
| 254 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 255 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 256 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 257 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 258 | png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 259 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 260 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 261 | else if (chunk_name == png_IEND) |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 262 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 263 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 264 | { |
| 265 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 266 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 267 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 268 | |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 269 | png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); |
| 270 | |
| 271 | png_ptr->process_mode = PNG_READ_DONE_MODE; |
| 272 | png_push_have_end(png_ptr, info_ptr); |
| 273 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 274 | |
Glenn Randers-Pehrson | bd757ac | 2013-11-18 18:40:39 -0600 | [diff] [blame] | 275 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 276 | else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 277 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 278 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 279 | { |
| 280 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 281 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 282 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 283 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 284 | png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 285 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 286 | if (chunk_name == png_PLTE) |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 287 | png_ptr->mode |= PNG_HAVE_PLTE; |
Glenn Randers-Pehrson | d029a75 | 2004-08-09 21:50:32 -0500 | [diff] [blame] | 288 | } |
| 289 | #endif |
Glenn Randers-Pehrson | 012d36f | 2013-11-17 19:42:48 -0600 | [diff] [blame] | 290 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 291 | else if (chunk_name == png_PLTE) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 292 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 293 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 294 | { |
| 295 | png_push_save_buffer(png_ptr); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 296 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 297 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 298 | png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 299 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 300 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 301 | else if (chunk_name == png_IDAT) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 302 | { |
| 303 | png_ptr->idat_size = png_ptr->push_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 304 | png_ptr->process_mode = PNG_READ_IDAT_MODE; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 305 | png_push_have_info(png_ptr, info_ptr); |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 306 | png_ptr->zstream.avail_out = |
| 307 | (uInt) PNG_ROWBYTES(png_ptr->pixel_depth, |
| 308 | png_ptr->iwidth) + 1; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 309 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 310 | return; |
| 311 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 312 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 313 | #ifdef PNG_READ_gAMA_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 314 | else if (png_ptr->chunk_name == png_gAMA) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 315 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 316 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 317 | { |
| 318 | png_push_save_buffer(png_ptr); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 319 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 320 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 321 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 322 | png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 323 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 324 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 325 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 326 | #ifdef PNG_READ_sBIT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 327 | else if (png_ptr->chunk_name == png_sBIT) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 328 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 329 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 330 | { |
| 331 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 332 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 333 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 334 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 335 | png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 336 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 337 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 338 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 339 | #ifdef PNG_READ_cHRM_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 340 | else if (png_ptr->chunk_name == png_cHRM) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 341 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 342 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 343 | { |
| 344 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 345 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 346 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 347 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 348 | png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 349 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 350 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 351 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 352 | #ifdef PNG_READ_sRGB_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 353 | else if (chunk_name == png_sRGB) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 354 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 355 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 356 | { |
| 357 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 358 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 359 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 360 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 361 | png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); |
| 362 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 363 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 364 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 365 | #ifdef PNG_READ_iCCP_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 366 | else if (png_ptr->chunk_name == png_iCCP) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 367 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 368 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 369 | { |
| 370 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 371 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 372 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 373 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 374 | png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); |
| 375 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 376 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 377 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 378 | #ifdef PNG_READ_sPLT_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 379 | else if (chunk_name == png_sPLT) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 380 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 381 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 382 | { |
| 383 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 384 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 385 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 386 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 387 | png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); |
| 388 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 389 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 390 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 391 | #ifdef PNG_READ_tRNS_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 392 | else if (chunk_name == png_tRNS) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 393 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 394 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 395 | { |
| 396 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 397 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 398 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 399 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 400 | png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 401 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 402 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 403 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 404 | #ifdef PNG_READ_bKGD_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 405 | else if (chunk_name == png_bKGD) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 406 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 407 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 408 | { |
| 409 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 410 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 411 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 412 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 413 | png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 414 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 415 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 416 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 417 | #ifdef PNG_READ_hIST_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 418 | else if (chunk_name == png_hIST) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 419 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 420 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 421 | { |
| 422 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 423 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 424 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 425 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 426 | png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 427 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 428 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 429 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 430 | #ifdef PNG_READ_pHYs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 431 | else if (chunk_name == png_pHYs) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 432 | { |
| 433 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 434 | { |
| 435 | png_push_save_buffer(png_ptr); |
| 436 | return; |
| 437 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 438 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 439 | png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 440 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 441 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 442 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 443 | #ifdef PNG_READ_oFFs_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 444 | else if (chunk_name == png_oFFs) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 445 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 446 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 447 | { |
| 448 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 449 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 450 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 451 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 452 | png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 453 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 454 | #endif |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 455 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 456 | #ifdef PNG_READ_pCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 457 | else if (chunk_name == png_pCAL) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 458 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 459 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 460 | { |
| 461 | png_push_save_buffer(png_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 462 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 463 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 464 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 465 | png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 466 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 467 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 468 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 469 | #ifdef PNG_READ_sCAL_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 470 | else if (chunk_name == png_sCAL) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 471 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 472 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 473 | { |
| 474 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 475 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 476 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 477 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 478 | png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 479 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 480 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 481 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 482 | #ifdef PNG_READ_tIME_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 483 | else if (chunk_name == png_tIME) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 484 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 485 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 486 | { |
| 487 | png_push_save_buffer(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 488 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 489 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 490 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 491 | png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 492 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 493 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 494 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 495 | #ifdef PNG_READ_tEXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 496 | else if (chunk_name == png_tEXt) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 497 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 498 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 499 | { |
| 500 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 501 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 502 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 503 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 504 | png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 505 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 506 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 507 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 508 | #ifdef PNG_READ_zTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 509 | else if (chunk_name == png_zTXt) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 510 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 511 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 512 | { |
| 513 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 514 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 515 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 516 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 517 | png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 518 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 519 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 520 | #endif |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 521 | #ifdef PNG_READ_iTXt_SUPPORTED |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 522 | else if (chunk_name == png_iTXt) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 523 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 524 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 525 | { |
| 526 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 527 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 528 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 529 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 530 | png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 531 | } |
| 532 | #endif |
Glenn Randers-Pehrson | 416bb93 | 2013-11-17 11:01:31 -0600 | [diff] [blame] | 533 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 534 | else |
| 535 | { |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 536 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 537 | { |
| 538 | png_push_save_buffer(png_ptr); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 539 | return; |
Glenn Randers-Pehrson | 7908421 | 2008-08-04 13:31:41 -0500 | [diff] [blame] | 540 | } |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 541 | png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, |
| 542 | PNG_HANDLE_CHUNK_AS_DEFAULT); |
Glenn Randers-Pehrson | 68dfa9e | 2013-11-17 19:26:40 -0600 | [diff] [blame] | 543 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 544 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 545 | png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 548 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 549 | png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 550 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 551 | png_ptr->process_mode = PNG_SKIP_MODE; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 552 | png_ptr->skip_length = skip; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 553 | } |
| 554 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 555 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 556 | png_push_crc_finish(png_structrp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 557 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 558 | if (png_ptr->skip_length && png_ptr->save_buffer_size) |
| 559 | { |
Glenn Randers-Pehrson | 1408c2a | 2011-01-16 14:16:28 -0600 | [diff] [blame] | 560 | png_size_t save_size = png_ptr->save_buffer_size; |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 561 | png_uint_32 skip_length = png_ptr->skip_length; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 562 | |
John Bowler | 168a433 | 2011-01-16 19:32:22 -0600 | [diff] [blame] | 563 | /* We want the smaller of 'skip_length' and 'save_buffer_size', but |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 564 | * they are of different types and we don't know which variable has the |
| 565 | * fewest bits. Carefully select the smaller and cast it to the type of |
| 566 | * the larger - this cannot overflow. Do not cast in the following test |
| 567 | * - it will break on either 16 or 64 bit platforms. |
| 568 | */ |
| 569 | if (skip_length < save_size) |
| 570 | save_size = (png_size_t)skip_length; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 571 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 572 | else |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 573 | skip_length = (png_uint_32)save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 574 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 575 | png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 576 | |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 577 | png_ptr->skip_length -= skip_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 578 | png_ptr->buffer_size -= save_size; |
| 579 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 580 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 581 | } |
| 582 | if (png_ptr->skip_length && png_ptr->current_buffer_size) |
| 583 | { |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 584 | png_size_t save_size = png_ptr->current_buffer_size; |
| 585 | png_uint_32 skip_length = png_ptr->skip_length; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 586 | |
John Bowler | 168a433 | 2011-01-16 19:32:22 -0600 | [diff] [blame] | 587 | /* We want the smaller of 'skip_length' and 'current_buffer_size', here, |
| 588 | * the same problem exists as above and the same solution. |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 589 | */ |
| 590 | if (skip_length < save_size) |
| 591 | save_size = (png_size_t)skip_length; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 592 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 593 | else |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 594 | skip_length = (png_uint_32)save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 595 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 596 | png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 597 | |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 598 | png_ptr->skip_length -= skip_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 599 | png_ptr->buffer_size -= save_size; |
| 600 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 601 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 602 | } |
| 603 | if (!png_ptr->skip_length) |
| 604 | { |
| 605 | if (png_ptr->buffer_size < 4) |
| 606 | { |
| 607 | png_push_save_buffer(png_ptr); |
| 608 | return; |
| 609 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 610 | |
| 611 | png_crc_finish(png_ptr, 0); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 612 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 613 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 614 | } |
| 615 | |
Glenn Randers-Pehrson | eae8e36 | 2010-03-12 17:36:53 -0600 | [diff] [blame] | 616 | void PNGCBAPI |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 617 | png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 618 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 619 | png_bytep ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 620 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 621 | if (png_ptr == NULL) |
| 622 | return; |
| 623 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 624 | ptr = buffer; |
| 625 | if (png_ptr->save_buffer_size) |
| 626 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 627 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 628 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 629 | if (length < png_ptr->save_buffer_size) |
| 630 | save_size = length; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 631 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 632 | else |
| 633 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 634 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 635 | memcpy(ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 636 | length -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 637 | ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 638 | png_ptr->buffer_size -= save_size; |
| 639 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 640 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 641 | } |
| 642 | if (length && png_ptr->current_buffer_size) |
| 643 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 644 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 645 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 646 | if (length < png_ptr->current_buffer_size) |
| 647 | save_size = length; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 648 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 649 | else |
| 650 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 651 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 652 | memcpy(ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 653 | png_ptr->buffer_size -= save_size; |
| 654 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 655 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 656 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 657 | } |
| 658 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 659 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 660 | png_push_save_buffer(png_structrp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 661 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 662 | if (png_ptr->save_buffer_size) |
| 663 | { |
| 664 | if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) |
| 665 | { |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 666 | png_size_t i, istop; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 667 | png_bytep sp; |
| 668 | png_bytep dp; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 669 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 670 | istop = png_ptr->save_buffer_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 671 | for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 672 | i < istop; i++, sp++, dp++) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 673 | { |
| 674 | *dp = *sp; |
| 675 | } |
| 676 | } |
| 677 | } |
Glenn Randers-Pehrson | e00ed36 | 2010-02-07 22:42:58 -0600 | [diff] [blame] | 678 | if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 679 | png_ptr->save_buffer_max) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 680 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 681 | png_size_t new_max; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 682 | png_bytep old_buffer; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 683 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 684 | if (png_ptr->save_buffer_size > PNG_SIZE_MAX - |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 685 | (png_ptr->current_buffer_size + 256)) |
Glenn Randers-Pehrson | e00ed36 | 2010-02-07 22:42:58 -0600 | [diff] [blame] | 686 | { |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 687 | png_error(png_ptr, "Potential overflow of save_buffer"); |
Glenn Randers-Pehrson | e00ed36 | 2010-02-07 22:42:58 -0600 | [diff] [blame] | 688 | } |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 689 | |
Glenn Randers-Pehrson | e00ed36 | 2010-02-07 22:42:58 -0600 | [diff] [blame] | 690 | new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 691 | old_buffer = png_ptr->save_buffer; |
Glenn Randers-Pehrson | f1eb918 | 2010-02-08 15:36:41 -0600 | [diff] [blame] | 692 | png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 693 | (png_size_t)new_max); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 694 | |
Glenn Randers-Pehrson | f1eb918 | 2010-02-08 15:36:41 -0600 | [diff] [blame] | 695 | if (png_ptr->save_buffer == NULL) |
| 696 | { |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 697 | png_free(png_ptr, old_buffer); |
| 698 | png_error(png_ptr, "Insufficient memory for save_buffer"); |
Glenn Randers-Pehrson | f1eb918 | 2010-02-08 15:36:41 -0600 | [diff] [blame] | 699 | } |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 700 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 701 | memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 702 | png_free(png_ptr, old_buffer); |
| 703 | png_ptr->save_buffer_max = new_max; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 704 | } |
| 705 | if (png_ptr->current_buffer_size) |
| 706 | { |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 707 | memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 708 | png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 709 | png_ptr->save_buffer_size += png_ptr->current_buffer_size; |
| 710 | png_ptr->current_buffer_size = 0; |
| 711 | } |
| 712 | png_ptr->save_buffer_ptr = png_ptr->save_buffer; |
| 713 | png_ptr->buffer_size = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 714 | } |
| 715 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 716 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 717 | png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 718 | png_size_t buffer_length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 719 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 720 | png_ptr->current_buffer = buffer; |
| 721 | png_ptr->current_buffer_size = buffer_length; |
| 722 | png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; |
| 723 | png_ptr->current_buffer_ptr = png_ptr->current_buffer; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 724 | } |
| 725 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 726 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 727 | png_push_read_IDAT(png_structrp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 728 | { |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 729 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 730 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 731 | png_byte chunk_length[4]; |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 732 | png_byte chunk_tag[4]; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 733 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 734 | /* TODO: this code can be commoned up with the same code in push_read */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 735 | if (png_ptr->buffer_size < 8) |
| 736 | { |
| 737 | png_push_save_buffer(png_ptr); |
| 738 | return; |
| 739 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 740 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 741 | png_push_fill_buffer(png_ptr, chunk_length, 4); |
Glenn Randers-Pehrson | 145f5c8 | 2008-07-10 09:13:13 -0500 | [diff] [blame] | 742 | png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 743 | png_reset_crc(png_ptr); |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 744 | png_crc_read(png_ptr, chunk_tag, 4); |
| 745 | png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 746 | png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 747 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 748 | if (png_ptr->chunk_name != png_IDAT) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 749 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 750 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 751 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 752 | if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 753 | png_error(png_ptr, "Not enough compressed data"); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 754 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 755 | return; |
| 756 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 757 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 758 | png_ptr->idat_size = png_ptr->push_length; |
| 759 | } |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 760 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 761 | if (png_ptr->idat_size && png_ptr->save_buffer_size) |
| 762 | { |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 763 | png_size_t save_size = png_ptr->save_buffer_size; |
| 764 | png_uint_32 idat_size = png_ptr->idat_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 765 | |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 766 | /* We want the smaller of 'idat_size' and 'current_buffer_size', but they |
| 767 | * are of different types and we don't know which variable has the fewest |
| 768 | * bits. Carefully select the smaller and cast it to the type of the |
| 769 | * larger - this cannot overflow. Do not cast in the following test - it |
| 770 | * will break on either 16 or 64 bit platforms. |
| 771 | */ |
| 772 | if (idat_size < save_size) |
| 773 | save_size = (png_size_t)idat_size; |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 774 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 775 | else |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 776 | idat_size = (png_uint_32)save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 777 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 778 | png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 779 | |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 780 | png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 781 | |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 782 | png_ptr->idat_size -= idat_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 783 | png_ptr->buffer_size -= save_size; |
| 784 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 785 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 786 | } |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 787 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 788 | if (png_ptr->idat_size && png_ptr->current_buffer_size) |
| 789 | { |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 790 | png_size_t save_size = png_ptr->current_buffer_size; |
| 791 | png_uint_32 idat_size = png_ptr->idat_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 792 | |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 793 | /* We want the smaller of 'idat_size' and 'current_buffer_size', but they |
| 794 | * are of different types and we don't know which variable has the fewest |
| 795 | * bits. Carefully select the smaller and cast it to the type of the |
| 796 | * larger - this cannot overflow. |
| 797 | */ |
| 798 | if (idat_size < save_size) |
| 799 | save_size = (png_size_t)idat_size; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 800 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 801 | else |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 802 | idat_size = (png_uint_32)save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 803 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 804 | png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 805 | |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 806 | png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 807 | |
Glenn Randers-Pehrson | bcb3aac | 2010-09-10 22:05:27 -0500 | [diff] [blame] | 808 | png_ptr->idat_size -= idat_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 809 | png_ptr->buffer_size -= save_size; |
| 810 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 811 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 812 | } |
| 813 | if (!png_ptr->idat_size) |
| 814 | { |
| 815 | if (png_ptr->buffer_size < 4) |
| 816 | { |
| 817 | png_push_save_buffer(png_ptr); |
| 818 | return; |
| 819 | } |
| 820 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 821 | png_crc_finish(png_ptr, 0); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 822 | png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 823 | png_ptr->mode |= PNG_AFTER_IDAT; |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 824 | png_ptr->zowner = 0; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 825 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 826 | } |
| 827 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 828 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 829 | png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 830 | png_size_t buffer_length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 831 | { |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 832 | /* The caller checks for a non-zero buffer length. */ |
Glenn Randers-Pehrson | ef3831a | 2010-06-22 13:03:32 -0500 | [diff] [blame] | 833 | if (!(buffer_length > 0) || buffer == NULL) |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 834 | png_error(png_ptr, "No IDAT data (internal error)"); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 835 | |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 836 | /* This routine must process all the data it has been given |
| 837 | * before returning, calling the row callback as required to |
Glenn Randers-Pehrson | 5feb87c | 2010-06-21 12:28:05 -0500 | [diff] [blame] | 838 | * handle the uncompressed results. |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 839 | */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 840 | png_ptr->zstream.next_in = buffer; |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 841 | /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 842 | png_ptr->zstream.avail_in = (uInt)buffer_length; |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 843 | |
| 844 | /* Keep going until the decompressed data is all processed |
| 845 | * or the stream marked as finished. |
| 846 | */ |
| 847 | while (png_ptr->zstream.avail_in > 0 && |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 848 | !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 849 | { |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 850 | int ret; |
| 851 | |
| 852 | /* We have data for zlib, but we must check that zlib |
Glenn Randers-Pehrson | ef3831a | 2010-06-22 13:03:32 -0500 | [diff] [blame] | 853 | * has someplace to put the results. It doesn't matter |
Glenn Randers-Pehrson | 5feb87c | 2010-06-21 12:28:05 -0500 | [diff] [blame] | 854 | * if we don't expect any results -- it may be the input |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 855 | * data is just the LZ end code. |
| 856 | */ |
| 857 | if (!(png_ptr->zstream.avail_out > 0)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 858 | { |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 859 | /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ |
| 860 | png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, |
| 861 | png_ptr->iwidth) + 1); |
Glenn Randers-Pehrson | 5feb87c | 2010-06-21 12:28:05 -0500 | [diff] [blame] | 862 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 863 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 864 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 865 | |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 866 | /* Using Z_SYNC_FLUSH here means that an unterminated |
Glenn Randers-Pehrson | ef3831a | 2010-06-22 13:03:32 -0500 | [diff] [blame] | 867 | * LZ stream (a stream with a missing end code) can still |
| 868 | * be handled, otherwise (Z_NO_FLUSH) a future zlib |
| 869 | * implementation might defer output and therefore |
| 870 | * change the current behavior (see comments in inflate.c |
| 871 | * for why this doesn't happen at present with zlib 1.2.5). |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 872 | */ |
| 873 | ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); |
| 874 | |
| 875 | /* Check for any failure before proceeding. */ |
| 876 | if (ret != Z_OK && ret != Z_STREAM_END) |
| 877 | { |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 878 | /* Terminate the decompression. */ |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 879 | png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; |
| 880 | png_ptr->zowner = 0; |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 881 | |
| 882 | /* This may be a truncated stream (missing or |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 883 | * damaged end code). Treat that as a warning. |
| 884 | */ |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 885 | if (png_ptr->row_number >= png_ptr->num_rows || |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 886 | png_ptr->pass > 6) |
| 887 | png_warning(png_ptr, "Truncated compressed data in IDAT"); |
Glenn Randers-Pehrson | 5feb87c | 2010-06-21 12:28:05 -0500 | [diff] [blame] | 888 | |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 889 | else |
| 890 | png_error(png_ptr, "Decompression error in IDAT"); |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 891 | |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 892 | /* Skip the check on unprocessed input */ |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 893 | return; |
| 894 | } |
| 895 | |
| 896 | /* Did inflate output any data? */ |
| 897 | if (png_ptr->zstream.next_out != png_ptr->row_buf) |
| 898 | { |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 899 | /* Is this unexpected data after the last row? |
| 900 | * If it is, artificially terminate the LZ output |
| 901 | * here. |
| 902 | */ |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 903 | if (png_ptr->row_number >= png_ptr->num_rows || |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 904 | png_ptr->pass > 6) |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 905 | { |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 906 | /* Extra data. */ |
| 907 | png_warning(png_ptr, "Extra compressed data in IDAT"); |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 908 | png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; |
| 909 | png_ptr->zowner = 0; |
Glenn Randers-Pehrson | 5feb87c | 2010-06-21 12:28:05 -0500 | [diff] [blame] | 910 | |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 911 | /* Do no more processing; skip the unprocessed |
| 912 | * input check below. |
| 913 | */ |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 914 | return; |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 915 | } |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 916 | |
Glenn Randers-Pehrson | d9d4cec | 2010-07-12 07:12:09 -0500 | [diff] [blame] | 917 | /* Do we have a complete row? */ |
| 918 | if (png_ptr->zstream.avail_out == 0) |
| 919 | png_push_process_row(png_ptr); |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 920 | } |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 921 | |
| 922 | /* And check for the end of the stream. */ |
| 923 | if (ret == Z_STREAM_END) |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 924 | png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 925 | } |
Glenn Randers-Pehrson | 57d9617 | 2010-06-19 19:25:17 -0500 | [diff] [blame] | 926 | |
| 927 | /* All the data should have been processed, if anything |
| 928 | * is left at this point we have bytes of IDAT data |
| 929 | * after the zlib end code. |
| 930 | */ |
| 931 | if (png_ptr->zstream.avail_in > 0) |
Glenn Randers-Pehrson | 5feb87c | 2010-06-21 12:28:05 -0500 | [diff] [blame] | 932 | png_warning(png_ptr, "Extra compression data in IDAT"); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 933 | } |
| 934 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 935 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 936 | png_push_process_row(png_structrp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 937 | { |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 938 | /* 1.5.6: row_info moved out of png_struct to a local here. */ |
| 939 | png_row_info row_info; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 940 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 941 | row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ |
| 942 | row_info.color_type = png_ptr->color_type; |
| 943 | row_info.bit_depth = png_ptr->bit_depth; |
| 944 | row_info.channels = png_ptr->channels; |
| 945 | row_info.pixel_depth = png_ptr->pixel_depth; |
| 946 | row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 947 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 948 | if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) |
| 949 | { |
| 950 | if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) |
Mans Rullgard | d3a9480 | 2011-11-03 00:47:55 -0500 | [diff] [blame] | 951 | 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] | 952 | png_ptr->prev_row + 1, png_ptr->row_buf[0]); |
| 953 | else |
| 954 | png_error(png_ptr, "bad adaptive filter value"); |
| 955 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 956 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 957 | /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before |
| 958 | * 1.5.6, while the buffer really is this big in current versions of libpng |
| 959 | * it may not be in the future, so this was changed just to copy the |
| 960 | * interlaced row count: |
| 961 | */ |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 962 | memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 963 | |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 964 | #ifdef PNG_READ_TRANSFORMS_SUPPORTED |
John Bowler | 9b872f4 | 2011-02-12 09:00:16 -0600 | [diff] [blame] | 965 | if (png_ptr->transformations) |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 966 | png_do_read_transformations(png_ptr, &row_info); |
John Bowler | 4a12f4a | 2011-04-17 18:34:22 -0500 | [diff] [blame] | 967 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 968 | |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 969 | /* The transformed pixel depth should match the depth now in row_info. */ |
| 970 | if (png_ptr->transformed_pixel_depth == 0) |
| 971 | { |
| 972 | png_ptr->transformed_pixel_depth = row_info.pixel_depth; |
| 973 | if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) |
| 974 | png_error(png_ptr, "progressive row overflow"); |
| 975 | } |
| 976 | |
| 977 | else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) |
| 978 | png_error(png_ptr, "internal progressive row size calculation error"); |
| 979 | |
| 980 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 981 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 982 | /* Blow up interlaced rows to full size */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 983 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 984 | { |
| 985 | if (png_ptr->pass < 6) |
Glenn Randers-Pehrson | bb5cb14 | 2011-09-22 12:41:58 -0500 | [diff] [blame] | 986 | png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, |
| 987 | png_ptr->transformations); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 988 | |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 989 | switch (png_ptr->pass) |
| 990 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 991 | case 0: |
| 992 | { |
| 993 | int i; |
| 994 | for (i = 0; i < 8 && png_ptr->pass == 0; i++) |
| 995 | { |
| 996 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 997 | png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 998 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 999 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 1000 | if (png_ptr->pass == 2) /* Pass 1 might be empty */ |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1001 | { |
| 1002 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 1003 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1004 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1005 | png_read_push_finish_row(png_ptr); |
| 1006 | } |
| 1007 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1008 | |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1009 | if (png_ptr->pass == 4 && png_ptr->height <= 4) |
| 1010 | { |
| 1011 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1012 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1013 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 1014 | png_read_push_finish_row(png_ptr); |
| 1015 | } |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1016 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1017 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1018 | if (png_ptr->pass == 6 && png_ptr->height <= 4) |
| 1019 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1020 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1021 | png_read_push_finish_row(png_ptr); |
| 1022 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1023 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1024 | break; |
| 1025 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1026 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1027 | case 1: |
| 1028 | { |
| 1029 | int i; |
| 1030 | for (i = 0; i < 8 && png_ptr->pass == 1; i++) |
| 1031 | { |
| 1032 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1033 | png_read_push_finish_row(png_ptr); |
| 1034 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1035 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 1036 | if (png_ptr->pass == 2) /* Skip top 4 generated rows */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1037 | { |
| 1038 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 1039 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1040 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1041 | png_read_push_finish_row(png_ptr); |
| 1042 | } |
| 1043 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1044 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1045 | break; |
| 1046 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1047 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1048 | case 2: |
| 1049 | { |
| 1050 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1051 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1052 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 1053 | { |
| 1054 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1055 | png_read_push_finish_row(png_ptr); |
| 1056 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1057 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1058 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 1059 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1060 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1061 | png_read_push_finish_row(png_ptr); |
| 1062 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1063 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 1064 | if (png_ptr->pass == 4) /* Pass 3 might be empty */ |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1065 | { |
| 1066 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1067 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1068 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1069 | png_read_push_finish_row(png_ptr); |
| 1070 | } |
| 1071 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1072 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1073 | break; |
| 1074 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1075 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1076 | case 3: |
| 1077 | { |
| 1078 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1079 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1080 | for (i = 0; i < 4 && png_ptr->pass == 3; i++) |
| 1081 | { |
| 1082 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1083 | png_read_push_finish_row(png_ptr); |
| 1084 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1085 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 1086 | if (png_ptr->pass == 4) /* Skip top two generated rows */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1087 | { |
| 1088 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1089 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1090 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1091 | png_read_push_finish_row(png_ptr); |
| 1092 | } |
| 1093 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1094 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1095 | break; |
| 1096 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1097 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1098 | case 4: |
| 1099 | { |
| 1100 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1101 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1102 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1103 | { |
| 1104 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1105 | png_read_push_finish_row(png_ptr); |
| 1106 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1107 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1108 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 1109 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1110 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1111 | png_read_push_finish_row(png_ptr); |
| 1112 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1113 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 1114 | if (png_ptr->pass == 6) /* Pass 5 might be empty */ |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1115 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1116 | png_push_have_row(png_ptr, NULL); |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1117 | png_read_push_finish_row(png_ptr); |
| 1118 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1119 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1120 | break; |
| 1121 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1122 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1123 | case 5: |
| 1124 | { |
| 1125 | int i; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1126 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1127 | for (i = 0; i < 2 && png_ptr->pass == 5; i++) |
| 1128 | { |
| 1129 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1130 | png_read_push_finish_row(png_ptr); |
| 1131 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1132 | |
Glenn Randers-Pehrson | 4bb4d01 | 2009-05-20 12:45:29 -0500 | [diff] [blame] | 1133 | if (png_ptr->pass == 6) /* Skip top generated row */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1134 | { |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1135 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1136 | png_read_push_finish_row(png_ptr); |
| 1137 | } |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1138 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1139 | break; |
| 1140 | } |
Glenn Randers-Pehrson | 67439c4 | 2010-08-19 07:01:09 -0500 | [diff] [blame] | 1141 | |
Glenn Randers-Pehrson | b3edc73 | 2010-11-21 14:06:41 -0600 | [diff] [blame] | 1142 | default: |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1143 | case 6: |
| 1144 | { |
| 1145 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1146 | png_read_push_finish_row(png_ptr); |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1147 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1148 | if (png_ptr->pass != 6) |
| 1149 | break; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1150 | |
Glenn Randers-Pehrson | beb572e | 2006-08-19 13:59:24 -0500 | [diff] [blame] | 1151 | png_push_have_row(png_ptr, NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1152 | png_read_push_finish_row(png_ptr); |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | else |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1157 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1158 | { |
| 1159 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 1160 | png_read_push_finish_row(png_ptr); |
| 1161 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1162 | } |
| 1163 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1164 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1165 | png_read_push_finish_row(png_structrp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1166 | { |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 1167 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1168 | /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1169 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1170 | /* Start of interlace block */ |
John Bowler | baeb6d1 | 2011-11-26 18:21:02 -0600 | [diff] [blame] | 1171 | static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1172 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1173 | /* Offset to next interlace block */ |
John Bowler | baeb6d1 | 2011-11-26 18:21:02 -0600 | [diff] [blame] | 1174 | static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1175 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1176 | /* Start of interlace block in the y direction */ |
John Bowler | baeb6d1 | 2011-11-26 18:21:02 -0600 | [diff] [blame] | 1177 | static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1178 | |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1179 | /* Offset to next interlace block in the y direction */ |
John Bowler | baeb6d1 | 2011-11-26 18:21:02 -0600 | [diff] [blame] | 1180 | static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1181 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1182 | /* Height of interlace block. This is not currently used - if you need |
| 1183 | * it, uncomment it here and in png.h |
John Bowler | baeb6d1 | 2011-11-26 18:21:02 -0600 | [diff] [blame] | 1184 | static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1185 | */ |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 1186 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1187 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1188 | png_ptr->row_number++; |
| 1189 | if (png_ptr->row_number < png_ptr->num_rows) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1190 | return; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1191 | |
Glenn Randers-Pehrson | e26c095 | 2009-09-23 11:22:08 -0500 | [diff] [blame] | 1192 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1193 | if (png_ptr->interlaced) |
| 1194 | { |
| 1195 | png_ptr->row_number = 0; |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 1196 | memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1197 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1198 | do |
| 1199 | { |
| 1200 | png_ptr->pass++; |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1201 | if ((png_ptr->pass == 1 && png_ptr->width < 5) || |
| 1202 | (png_ptr->pass == 3 && png_ptr->width < 3) || |
| 1203 | (png_ptr->pass == 5 && png_ptr->width < 2)) |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1204 | png_ptr->pass++; |
Glenn Randers-Pehrson | cdf140b | 2001-01-15 12:22:32 -0600 | [diff] [blame] | 1205 | |
Glenn Randers-Pehrson | 859665d | 2002-08-06 18:06:11 -0500 | [diff] [blame] | 1206 | if (png_ptr->pass > 7) |
| 1207 | png_ptr->pass--; |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1208 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1209 | if (png_ptr->pass >= 7) |
| 1210 | break; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1211 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1212 | png_ptr->iwidth = (png_ptr->width + |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1213 | png_pass_inc[png_ptr->pass] - 1 - |
| 1214 | png_pass_start[png_ptr->pass]) / |
| 1215 | png_pass_inc[png_ptr->pass]; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1216 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1217 | if (png_ptr->transformations & PNG_INTERLACE) |
| 1218 | break; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1219 | |
| 1220 | png_ptr->num_rows = (png_ptr->height + |
Glenn Randers-Pehrson | f24daf2 | 2010-05-06 09:44:04 -0500 | [diff] [blame] | 1221 | png_pass_yinc[png_ptr->pass] - 1 - |
| 1222 | png_pass_ystart[png_ptr->pass]) / |
| 1223 | png_pass_yinc[png_ptr->pass]; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1224 | |
| 1225 | } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1226 | } |
Glenn Randers-Pehrson | a31c74f | 2009-05-18 15:52:01 -0500 | [diff] [blame] | 1227 | #endif /* PNG_READ_INTERLACING_SUPPORTED */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1228 | } |
| 1229 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1230 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1231 | png_push_have_info(png_structrp png_ptr, png_inforp info_ptr) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1232 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1233 | if (png_ptr->info_fn != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1234 | (*(png_ptr->info_fn))(png_ptr, info_ptr); |
| 1235 | } |
| 1236 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1237 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1238 | png_push_have_end(png_structrp png_ptr, png_inforp info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1239 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1240 | if (png_ptr->end_fn != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1241 | (*(png_ptr->end_fn))(png_ptr, info_ptr); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1242 | } |
| 1243 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1244 | void /* PRIVATE */ |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1245 | png_push_have_row(png_structrp png_ptr, png_bytep row) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1246 | { |
Glenn Randers-Pehrson | 78d5545 | 2010-06-19 07:03:50 -0500 | [diff] [blame] | 1247 | if (png_ptr->row_fn != NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1248 | (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, |
| 1249 | (int)png_ptr->pass); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1250 | } |
| 1251 | |
Glenn Randers-Pehrson | 4daae30 | 2011-10-06 21:37:47 -0500 | [diff] [blame] | 1252 | #ifdef PNG_READ_INTERLACING_SUPPORTED |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1253 | void PNGAPI |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1254 | png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row, |
Glenn Randers-Pehrson | e600c51 | 2010-08-18 07:25:46 -0500 | [diff] [blame] | 1255 | png_const_bytep new_row) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1256 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1257 | if (png_ptr == NULL) |
| 1258 | return; |
| 1259 | |
Glenn Randers-Pehrson | 4daae30 | 2011-10-06 21:37:47 -0500 | [diff] [blame] | 1260 | /* new_row is a flag here - if it is NULL then the app callback was called |
| 1261 | * from an empty row (see the calls to png_struct::row_fn below), otherwise |
| 1262 | * it must be png_ptr->row_buf+1 |
| 1263 | */ |
| 1264 | if (new_row != NULL) |
| 1265 | png_combine_row(png_ptr, old_row, 1/*display*/); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1266 | } |
Glenn Randers-Pehrson | 4daae30 | 2011-10-06 21:37:47 -0500 | [diff] [blame] | 1267 | #endif /* PNG_READ_INTERLACING_SUPPORTED */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1268 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1269 | void PNGAPI |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1270 | png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr, |
Glenn Randers-Pehrson | 262d0ff | 2010-03-03 07:06:54 -0600 | [diff] [blame] | 1271 | png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, |
| 1272 | png_progressive_end_ptr end_fn) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1273 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1274 | if (png_ptr == NULL) |
| 1275 | return; |
| 1276 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1277 | png_ptr->info_fn = info_fn; |
| 1278 | png_ptr->row_fn = row_fn; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1279 | png_ptr->end_fn = end_fn; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1280 | |
Glenn Randers-Pehrson | 25d8224 | 2002-05-01 11:51:26 -0500 | [diff] [blame] | 1281 | png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1282 | } |
| 1283 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1284 | png_voidp PNGAPI |
John Bowler | 5d56786 | 2011-12-24 09:12:00 -0600 | [diff] [blame] | 1285 | png_get_progressive_ptr(png_const_structrp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1286 | { |
Glenn Randers-Pehrson glennrp@comcast.net | b1c0d33 | 2009-05-15 20:39:34 -0500 | [diff] [blame] | 1287 | if (png_ptr == NULL) |
| 1288 | return (NULL); |
| 1289 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1290 | return png_ptr->io_ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1291 | } |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 1292 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |