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 | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 4 | * libpng 1.0.5h - December 10, 1999 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * For conditions of distribution and use, see copyright notice in png.h |
| 6 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
| 7 | * Copyright (c) 1996, 1997 Andreas Dilger |
Glenn Randers-Pehrson | c944229 | 1999-01-06 21:50:16 -0600 | [diff] [blame] | 8 | * Copyright (c) 1998, 1999 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 10 | |
| 11 | #define PNG_INTERNAL |
| 12 | #include "png.h" |
| 13 | |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 14 | #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
| 15 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 16 | /* push model modes */ |
| 17 | #define PNG_READ_SIG_MODE 0 |
| 18 | #define PNG_READ_CHUNK_MODE 1 |
| 19 | #define PNG_READ_IDAT_MODE 2 |
| 20 | #define PNG_SKIP_MODE 3 |
| 21 | #define PNG_READ_tEXt_MODE 4 |
| 22 | #define PNG_READ_zTXt_MODE 5 |
| 23 | #define PNG_READ_DONE_MODE 6 |
| 24 | #define PNG_READ_iTXt_MODE 7 |
| 25 | #define PNG_ERROR_MODE 8 |
| 26 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 27 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 28 | png_process_data(png_structp png_ptr, png_infop info_ptr, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 29 | png_bytep buffer, png_size_t buffer_size) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 30 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 31 | png_push_restore_buffer(png_ptr, buffer, buffer_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 32 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 33 | while (png_ptr->buffer_size) |
| 34 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 35 | png_process_some_data(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 36 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 37 | } |
| 38 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 39 | /* What we do with the incoming data depends on what we were previously |
| 40 | * doing before we ran out of data... |
| 41 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 42 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 43 | png_process_some_data(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 44 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 45 | switch (png_ptr->process_mode) |
| 46 | { |
| 47 | case PNG_READ_SIG_MODE: |
| 48 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 49 | png_push_read_sig(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 50 | break; |
| 51 | } |
| 52 | case PNG_READ_CHUNK_MODE: |
| 53 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 54 | png_push_read_chunk(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | case PNG_READ_IDAT_MODE: |
| 58 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 59 | png_push_read_IDAT(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 60 | break; |
| 61 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 62 | #if defined(PNG_READ_tEXt_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 63 | case PNG_READ_tEXt_MODE: |
| 64 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 65 | png_push_read_tEXt(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 66 | break; |
| 67 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 68 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 69 | #if defined(PNG_READ_zTXt_SUPPORTED) |
| 70 | case PNG_READ_zTXt_MODE: |
| 71 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 72 | png_push_read_zTXt(png_ptr, info_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 73 | break; |
| 74 | } |
| 75 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 76 | #if defined(PNG_READ_iTXt_SUPPORTED) |
| 77 | case PNG_READ_iTXt_MODE: |
| 78 | { |
| 79 | png_push_read_iTXt(png_ptr, info_ptr); |
| 80 | break; |
| 81 | } |
| 82 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 83 | case PNG_SKIP_MODE: |
| 84 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 85 | png_push_crc_finish(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 86 | break; |
| 87 | } |
| 88 | default: |
| 89 | { |
| 90 | png_ptr->buffer_size = 0; |
| 91 | break; |
| 92 | } |
| 93 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 94 | } |
| 95 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 96 | /* Read any remaining signature bytes from the stream and compare them with |
| 97 | * 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] | 98 | * with bytes already read from the signature, either because they have been |
| 99 | * checked by the calling application, or because of multiple calls to this |
| 100 | * routine. |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 101 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 102 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 103 | png_push_read_sig(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 104 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 105 | png_size_t num_checked = png_ptr->sig_bytes, |
| 106 | num_to_check = 8 - num_checked; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 107 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 108 | if (png_ptr->buffer_size < num_to_check) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 109 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 110 | num_to_check = png_ptr->buffer_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 111 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 112 | |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 113 | png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 114 | num_to_check); |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 115 | 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] | 116 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 117 | if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 118 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 119 | if (num_checked < 4 && |
| 120 | png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) |
| 121 | png_error(png_ptr, "Not a PNG file"); |
| 122 | else |
| 123 | png_error(png_ptr, "PNG file corrupted by ASCII conversion"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 124 | } |
| 125 | else |
| 126 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 127 | if (png_ptr->sig_bytes >= 8) |
| 128 | { |
| 129 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
| 130 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 131 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 135 | png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 136 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 137 | #ifdef PNG_USE_LOCAL_ARRAYS |
| 138 | PNG_IHDR; |
| 139 | PNG_IDAT; |
| 140 | PNG_IEND; |
| 141 | PNG_PLTE; |
| 142 | #if defined(PNG_READ_bKGD_SUPPORTED) |
| 143 | PNG_bKGD; |
| 144 | #endif |
| 145 | #if defined(PNG_READ_cHRM_SUPPORTED) |
| 146 | PNG_cHRM; |
| 147 | #endif |
| 148 | #if defined(PNG_READ_gAMA_SUPPORTED) |
| 149 | PNG_gAMA; |
| 150 | #endif |
| 151 | #if defined(PNG_READ_hIST_SUPPORTED) |
| 152 | PNG_hIST; |
| 153 | #endif |
| 154 | #if defined(PNG_READ_oFFs_SUPPORTED) |
| 155 | PNG_oFFs; |
| 156 | #endif |
| 157 | #if defined(PNG_READ_pCAL_SUPPORTED) |
| 158 | PNG_pCAL; |
| 159 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 160 | #if defined(PNG_READ_sCAL_SUPPORTED) |
| 161 | PNG_sCAL; |
| 162 | #endif |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 163 | #if defined(PNG_READ_pHYs_SUPPORTED) |
| 164 | PNG_pHYs; |
| 165 | #endif |
| 166 | #if defined(PNG_READ_sBIT_SUPPORTED) |
| 167 | PNG_sBIT; |
| 168 | #endif |
| 169 | #if defined(PNG_READ_sRGB_SUPPORTED) |
| 170 | PNG_sRGB; |
| 171 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 172 | #if defined(PNG_READ_iCCP_SUPPORTED) |
| 173 | PNG_iCCP; |
| 174 | #endif |
| 175 | #if defined(PNG_READ_sPLT_SUPPORTED) |
| 176 | PNG_sPLT; |
| 177 | #endif |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 178 | #if defined(PNG_READ_tEXt_SUPPORTED) |
| 179 | PNG_tEXt; |
| 180 | #endif |
| 181 | #if defined(PNG_READ_tIME_SUPPORTED) |
| 182 | PNG_tIME; |
| 183 | #endif |
| 184 | #if defined(PNG_READ_tRNS_SUPPORTED) |
| 185 | PNG_tRNS; |
| 186 | #endif |
| 187 | #if defined(PNG_READ_zTXt_SUPPORTED) |
| 188 | PNG_zTXt; |
| 189 | #endif |
| 190 | #endif /* PNG_USE_LOCAL_ARRAYS */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 191 | /* 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] | 192 | * and the 4 byte chunk length before proceeding with decoding the |
| 193 | * chunk data. To fully decode each of these chunks, we also make |
| 194 | * sure we have enough data in the buffer for the 4 byte CRC at the |
| 195 | * end of every chunk (except IDAT, which is handled separately). |
| 196 | */ |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 197 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 198 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 199 | png_byte chunk_length[4]; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 200 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 201 | if (png_ptr->buffer_size < 8) |
| 202 | { |
| 203 | png_push_save_buffer(png_ptr); |
| 204 | return; |
| 205 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 206 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 207 | png_push_fill_buffer(png_ptr, chunk_length, 4); |
| 208 | png_ptr->push_length = png_get_uint_32(chunk_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 209 | png_reset_crc(png_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 210 | png_crc_read(png_ptr, png_ptr->chunk_name, 4); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 211 | png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 212 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 213 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 214 | if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 215 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 216 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 217 | { |
| 218 | png_push_save_buffer(png_ptr); |
| 219 | return; |
| 220 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 221 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 222 | png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 223 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 224 | else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 225 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 226 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 227 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 228 | png_push_save_buffer(png_ptr); |
| 229 | return; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 230 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 231 | |
| 232 | png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 233 | } |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 234 | else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 235 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 236 | /* If we reach an IDAT chunk, this means we have read all of the |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 237 | * header chunks, and we can start reading the image (or if this |
| 238 | * is called after the image has been read - we have an error). |
| 239 | */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 240 | if (png_ptr->mode & PNG_HAVE_IDAT) |
| 241 | { |
| 242 | if (png_ptr->push_length == 0) |
| 243 | return; |
| 244 | |
| 245 | if (png_ptr->mode & PNG_AFTER_IDAT) |
| 246 | png_error(png_ptr, "Too many IDAT's found"); |
| 247 | } |
| 248 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 249 | png_ptr->idat_size = png_ptr->push_length; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 250 | png_ptr->mode |= PNG_HAVE_IDAT; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 251 | png_ptr->process_mode = PNG_READ_IDAT_MODE; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 252 | png_push_have_info(png_ptr, info_ptr); |
| 253 | png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; |
| 254 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 255 | return; |
| 256 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 257 | else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 258 | { |
| 259 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 260 | { |
| 261 | png_push_save_buffer(png_ptr); |
| 262 | return; |
| 263 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 264 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 265 | png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); |
| 266 | png_ptr->process_mode = PNG_READ_DONE_MODE; |
| 267 | png_push_have_end(png_ptr, info_ptr); |
| 268 | } |
| 269 | #if defined(PNG_READ_gAMA_SUPPORTED) |
| 270 | else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) |
| 271 | { |
| 272 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 273 | { |
| 274 | png_push_save_buffer(png_ptr); |
| 275 | return; |
| 276 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 277 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 278 | png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 279 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 280 | #endif |
| 281 | #if defined(PNG_READ_sBIT_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 282 | else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 283 | { |
| 284 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 285 | { |
| 286 | png_push_save_buffer(png_ptr); |
| 287 | return; |
| 288 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 289 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 290 | png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 291 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 292 | #endif |
| 293 | #if defined(PNG_READ_cHRM_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 294 | else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 295 | { |
| 296 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 297 | { |
| 298 | png_push_save_buffer(png_ptr); |
| 299 | return; |
| 300 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 301 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 302 | png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 303 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 304 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 305 | #if defined(PNG_READ_sRGB_SUPPORTED) |
| 306 | else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) |
| 307 | { |
| 308 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 309 | { |
| 310 | png_push_save_buffer(png_ptr); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); |
| 315 | } |
| 316 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 317 | #if defined(PNG_READ_iCCP_SUPPORTED) |
| 318 | else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) |
| 319 | { |
| 320 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 321 | { |
| 322 | png_push_save_buffer(png_ptr); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); |
| 327 | } |
| 328 | #endif |
| 329 | #if defined(PNG_READ_sPLT_SUPPORTED) |
| 330 | else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) |
| 331 | { |
| 332 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 333 | { |
| 334 | png_push_save_buffer(png_ptr); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); |
| 339 | } |
| 340 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 341 | #if defined(PNG_READ_tRNS_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 342 | else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 343 | { |
| 344 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 345 | { |
| 346 | png_push_save_buffer(png_ptr); |
| 347 | return; |
| 348 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 349 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 350 | png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 351 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 352 | #endif |
| 353 | #if defined(PNG_READ_bKGD_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 354 | else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 355 | { |
| 356 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 357 | { |
| 358 | png_push_save_buffer(png_ptr); |
| 359 | return; |
| 360 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 361 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 362 | png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 363 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 364 | #endif |
| 365 | #if defined(PNG_READ_hIST_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 366 | else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 367 | { |
| 368 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 369 | { |
| 370 | png_push_save_buffer(png_ptr); |
| 371 | return; |
| 372 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 373 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 374 | png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 375 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 376 | #endif |
| 377 | #if defined(PNG_READ_pHYs_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 378 | else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 379 | { |
| 380 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 381 | { |
| 382 | png_push_save_buffer(png_ptr); |
| 383 | return; |
| 384 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 385 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 386 | png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 387 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 388 | #endif |
| 389 | #if defined(PNG_READ_oFFs_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 390 | else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 391 | { |
| 392 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 393 | { |
| 394 | png_push_save_buffer(png_ptr); |
| 395 | return; |
| 396 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 397 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 398 | png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 399 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 400 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 401 | #if defined(PNG_READ_pCAL_SUPPORTED) |
| 402 | else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) |
| 403 | { |
| 404 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 405 | { |
| 406 | png_push_save_buffer(png_ptr); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 411 | } |
| 412 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 413 | #if defined(PNG_READ_sCAL_SUPPORTED) |
| 414 | else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) |
| 415 | { |
| 416 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 417 | { |
| 418 | png_push_save_buffer(png_ptr); |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); |
| 423 | } |
| 424 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 425 | #if defined(PNG_READ_tIME_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 426 | else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 427 | { |
| 428 | if (png_ptr->push_length + 4 > png_ptr->buffer_size) |
| 429 | { |
| 430 | png_push_save_buffer(png_ptr); |
| 431 | return; |
| 432 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 433 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 434 | png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 435 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 436 | #endif |
| 437 | #if defined(PNG_READ_tEXt_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 438 | else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 439 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 440 | png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 441 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 442 | #endif |
| 443 | #if defined(PNG_READ_zTXt_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 444 | else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 445 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 446 | png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 447 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 448 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 449 | #if defined(PNG_READ_iTXt_SUPPORTED) |
| 450 | else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) |
| 451 | { |
| 452 | png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); |
| 453 | } |
| 454 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 455 | else |
| 456 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 457 | png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 458 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 459 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 460 | png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 464 | png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 465 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 466 | png_ptr->process_mode = PNG_SKIP_MODE; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 467 | png_ptr->skip_length = skip; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 471 | png_push_crc_finish(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 472 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 473 | if (png_ptr->skip_length && png_ptr->save_buffer_size) |
| 474 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 475 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 476 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 477 | if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size) |
| 478 | save_size = (png_size_t)png_ptr->skip_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 479 | else |
| 480 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 481 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 482 | png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 483 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 484 | png_ptr->skip_length -= save_size; |
| 485 | png_ptr->buffer_size -= save_size; |
| 486 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 487 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 488 | } |
| 489 | if (png_ptr->skip_length && png_ptr->current_buffer_size) |
| 490 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 491 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 492 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 493 | if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size) |
| 494 | save_size = (png_size_t)png_ptr->skip_length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 495 | else |
| 496 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 497 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 498 | png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 499 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 500 | png_ptr->skip_length -= save_size; |
| 501 | png_ptr->buffer_size -= save_size; |
| 502 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 503 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 504 | } |
| 505 | if (!png_ptr->skip_length) |
| 506 | { |
| 507 | if (png_ptr->buffer_size < 4) |
| 508 | { |
| 509 | png_push_save_buffer(png_ptr); |
| 510 | return; |
| 511 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 512 | |
| 513 | png_crc_finish(png_ptr, 0); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 514 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 515 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 519 | 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] | 520 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 521 | png_bytep ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 522 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 523 | ptr = buffer; |
| 524 | if (png_ptr->save_buffer_size) |
| 525 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 526 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 527 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 528 | if (length < png_ptr->save_buffer_size) |
| 529 | save_size = length; |
| 530 | else |
| 531 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 532 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 533 | png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 534 | length -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 535 | ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 536 | png_ptr->buffer_size -= save_size; |
| 537 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 538 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 539 | } |
| 540 | if (length && png_ptr->current_buffer_size) |
| 541 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 542 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 543 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 544 | if (length < png_ptr->current_buffer_size) |
| 545 | save_size = length; |
| 546 | else |
| 547 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 548 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 549 | png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 550 | png_ptr->buffer_size -= save_size; |
| 551 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 552 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 553 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void |
| 557 | png_push_save_buffer(png_structp png_ptr) |
| 558 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 559 | if (png_ptr->save_buffer_size) |
| 560 | { |
| 561 | if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) |
| 562 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 563 | png_size_t i,istop; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 564 | png_bytep sp; |
| 565 | png_bytep dp; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 566 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 567 | istop = png_ptr->save_buffer_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 568 | for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 569 | i < istop; i++, sp++, dp++) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 570 | { |
| 571 | *dp = *sp; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > |
| 576 | png_ptr->save_buffer_max) |
| 577 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 578 | png_size_t new_max; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 579 | png_bytep old_buffer; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 580 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 581 | 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] | 582 | old_buffer = png_ptr->save_buffer; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 583 | png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 584 | (png_uint_32)new_max); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 585 | png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 586 | png_free(png_ptr, old_buffer); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 587 | png_ptr->save_buffer_max = new_max; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 588 | } |
| 589 | if (png_ptr->current_buffer_size) |
| 590 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 591 | png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, |
| 592 | png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 593 | png_ptr->save_buffer_size += png_ptr->current_buffer_size; |
| 594 | png_ptr->current_buffer_size = 0; |
| 595 | } |
| 596 | png_ptr->save_buffer_ptr = png_ptr->save_buffer; |
| 597 | png_ptr->buffer_size = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | void |
| 601 | png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 602 | png_size_t buffer_length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 603 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 604 | png_ptr->current_buffer = buffer; |
| 605 | png_ptr->current_buffer_size = buffer_length; |
| 606 | png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; |
| 607 | png_ptr->current_buffer_ptr = png_ptr->current_buffer; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | void |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 611 | png_push_read_IDAT(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 612 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 613 | #ifdef PNG_USE_LOCAL_ARRAYS |
| 614 | PNG_IDAT; |
| 615 | #endif |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 616 | if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 617 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 618 | png_byte chunk_length[4]; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 619 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 620 | if (png_ptr->buffer_size < 8) |
| 621 | { |
| 622 | png_push_save_buffer(png_ptr); |
| 623 | return; |
| 624 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 625 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 626 | png_push_fill_buffer(png_ptr, chunk_length, 4); |
| 627 | png_ptr->push_length = png_get_uint_32(chunk_length); |
| 628 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 629 | png_reset_crc(png_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 630 | png_crc_read(png_ptr, png_ptr->chunk_name, 4); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 631 | png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 632 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 633 | if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 634 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 635 | png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 636 | if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 637 | png_error(png_ptr, "Not enough compressed data"); |
| 638 | return; |
| 639 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 640 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 641 | png_ptr->idat_size = png_ptr->push_length; |
| 642 | } |
| 643 | if (png_ptr->idat_size && png_ptr->save_buffer_size) |
| 644 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 645 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 646 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 647 | if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 648 | { |
| 649 | save_size = (png_size_t)png_ptr->idat_size; |
| 650 | /* check for overflow */ |
| 651 | if((png_uint_32)save_size != png_ptr->idat_size) |
| 652 | png_error(png_ptr, "save_size overflowed in pngpread"); |
| 653 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 654 | else |
| 655 | save_size = png_ptr->save_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 656 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 657 | png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
| 658 | png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 659 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 660 | png_ptr->idat_size -= save_size; |
| 661 | png_ptr->buffer_size -= save_size; |
| 662 | png_ptr->save_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 663 | png_ptr->save_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 664 | } |
| 665 | if (png_ptr->idat_size && png_ptr->current_buffer_size) |
| 666 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 667 | png_size_t save_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 668 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 669 | if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size) |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 670 | { |
| 671 | save_size = (png_size_t)png_ptr->idat_size; |
| 672 | /* check for overflow */ |
| 673 | if((png_uint_32)save_size != png_ptr->idat_size) |
| 674 | png_error(png_ptr, "save_size overflowed in pngpread"); |
| 675 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 676 | else |
| 677 | save_size = png_ptr->current_buffer_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 678 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 679 | png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
| 680 | 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] | 681 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 682 | png_ptr->idat_size -= save_size; |
| 683 | png_ptr->buffer_size -= save_size; |
| 684 | png_ptr->current_buffer_size -= save_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 685 | png_ptr->current_buffer_ptr += save_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 686 | } |
| 687 | if (!png_ptr->idat_size) |
| 688 | { |
| 689 | if (png_ptr->buffer_size < 4) |
| 690 | { |
| 691 | png_push_save_buffer(png_ptr); |
| 692 | return; |
| 693 | } |
| 694 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 695 | png_crc_finish(png_ptr, 0); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 696 | png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 697 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | void |
| 701 | png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 702 | png_size_t buffer_length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 703 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 704 | int ret; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 705 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 706 | if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 707 | png_error(png_ptr, "Extra compression data"); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 708 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 709 | png_ptr->zstream.next_in = buffer; |
| 710 | png_ptr->zstream.avail_in = (uInt)buffer_length; |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 711 | for(;;) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 712 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 713 | ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 714 | if (ret == Z_STREAM_END) |
| 715 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 716 | if (png_ptr->zstream.avail_in) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 717 | png_error(png_ptr, "Extra compressed data"); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 718 | if (!(png_ptr->zstream.avail_out)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 719 | { |
| 720 | png_push_process_row(png_ptr); |
| 721 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 722 | |
| 723 | png_ptr->mode |= PNG_AFTER_IDAT; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 724 | png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 725 | break; |
| 726 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 727 | else if (ret == Z_BUF_ERROR) |
| 728 | break; |
| 729 | else if (ret != Z_OK) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 730 | png_error(png_ptr, "Decompression Error"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 731 | if (!(png_ptr->zstream.avail_out)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 732 | { |
| 733 | png_push_process_row(png_ptr); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 734 | png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; |
| 735 | png_ptr->zstream.next_out = png_ptr->row_buf; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 736 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 737 | else |
| 738 | break; |
| 739 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void |
| 743 | png_push_process_row(png_structp png_ptr) |
| 744 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 745 | png_ptr->row_info.color_type = png_ptr->color_type; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 746 | png_ptr->row_info.width = png_ptr->iwidth; |
| 747 | png_ptr->row_info.channels = png_ptr->channels; |
| 748 | png_ptr->row_info.bit_depth = png_ptr->bit_depth; |
| 749 | png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 750 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 751 | png_ptr->row_info.rowbytes = ((png_ptr->row_info.width * |
| 752 | (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); |
| 753 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 754 | png_read_filter_row(png_ptr, &(png_ptr->row_info), |
| 755 | png_ptr->row_buf + 1, png_ptr->prev_row + 1, |
| 756 | (int)(png_ptr->row_buf[0])); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 757 | |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 758 | png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 759 | png_ptr->rowbytes + 1); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 760 | |
| 761 | if (png_ptr->transformations) |
| 762 | png_do_read_transformations(png_ptr); |
| 763 | |
| 764 | #if defined(PNG_READ_INTERLACING_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 765 | /* blow up interlaced rows to full size */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 766 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 767 | { |
| 768 | if (png_ptr->pass < 6) |
| 769 | png_do_read_interlace(&(png_ptr->row_info), |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 770 | png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 771 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 772 | switch (png_ptr->pass) |
| 773 | { |
| 774 | case 0: |
| 775 | { |
| 776 | int i; |
| 777 | for (i = 0; i < 8 && png_ptr->pass == 0; i++) |
| 778 | { |
| 779 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 780 | png_read_push_finish_row(png_ptr); |
| 781 | } |
| 782 | break; |
| 783 | } |
| 784 | case 1: |
| 785 | { |
| 786 | int i; |
| 787 | for (i = 0; i < 8 && png_ptr->pass == 1; i++) |
| 788 | { |
| 789 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 790 | png_read_push_finish_row(png_ptr); |
| 791 | } |
| 792 | if (png_ptr->pass == 2) |
| 793 | { |
| 794 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 795 | { |
| 796 | png_push_have_row(png_ptr, NULL); |
| 797 | png_read_push_finish_row(png_ptr); |
| 798 | } |
| 799 | } |
| 800 | break; |
| 801 | } |
| 802 | case 2: |
| 803 | { |
| 804 | int i; |
| 805 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 806 | { |
| 807 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 808 | png_read_push_finish_row(png_ptr); |
| 809 | } |
| 810 | for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
| 811 | { |
| 812 | png_push_have_row(png_ptr, NULL); |
| 813 | png_read_push_finish_row(png_ptr); |
| 814 | } |
| 815 | break; |
| 816 | } |
| 817 | case 3: |
| 818 | { |
| 819 | int i; |
| 820 | for (i = 0; i < 4 && png_ptr->pass == 3; i++) |
| 821 | { |
| 822 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 823 | png_read_push_finish_row(png_ptr); |
| 824 | } |
| 825 | if (png_ptr->pass == 4) |
| 826 | { |
| 827 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 828 | { |
| 829 | png_push_have_row(png_ptr, NULL); |
| 830 | png_read_push_finish_row(png_ptr); |
| 831 | } |
| 832 | } |
| 833 | break; |
| 834 | } |
| 835 | case 4: |
| 836 | { |
| 837 | int i; |
| 838 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 839 | { |
| 840 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 841 | png_read_push_finish_row(png_ptr); |
| 842 | } |
| 843 | for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
| 844 | { |
| 845 | png_push_have_row(png_ptr, NULL); |
| 846 | png_read_push_finish_row(png_ptr); |
| 847 | } |
| 848 | break; |
| 849 | } |
| 850 | case 5: |
| 851 | { |
| 852 | int i; |
| 853 | for (i = 0; i < 2 && png_ptr->pass == 5; i++) |
| 854 | { |
| 855 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 856 | png_read_push_finish_row(png_ptr); |
| 857 | } |
| 858 | if (png_ptr->pass == 6) |
| 859 | { |
| 860 | png_push_have_row(png_ptr, NULL); |
| 861 | png_read_push_finish_row(png_ptr); |
| 862 | } |
| 863 | break; |
| 864 | } |
| 865 | case 6: |
| 866 | { |
| 867 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 868 | png_read_push_finish_row(png_ptr); |
| 869 | if (png_ptr->pass != 6) |
| 870 | break; |
| 871 | png_push_have_row(png_ptr, NULL); |
| 872 | png_read_push_finish_row(png_ptr); |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | else |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 877 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 878 | { |
| 879 | png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
| 880 | png_read_push_finish_row(png_ptr); |
| 881 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | void |
| 885 | png_read_push_finish_row(png_structp png_ptr) |
| 886 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 887 | #ifdef PNG_USE_LOCAL_ARRAYS |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 888 | /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 889 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 890 | /* start of interlace block */ |
| 891 | const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 892 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 893 | /* offset to next interlace block */ |
| 894 | const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 895 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 896 | /* start of interlace block in the y direction */ |
| 897 | const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 898 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 899 | /* offset to next interlace block in the y direction */ |
| 900 | const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 901 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 902 | /* Width of interlace block. This is not currently used - if you need |
| 903 | * it, uncomment it here and in png.h |
| 904 | const int png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; |
| 905 | */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 906 | |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 907 | /* Height of interlace block. This is not currently used - if you need |
| 908 | * it, uncomment it here and in png.h |
| 909 | const int png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
| 910 | */ |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 911 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 912 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 913 | png_ptr->row_number++; |
| 914 | if (png_ptr->row_number < png_ptr->num_rows) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 915 | return; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 916 | |
| 917 | if (png_ptr->interlaced) |
| 918 | { |
| 919 | png_ptr->row_number = 0; |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 920 | png_memset_check(png_ptr, png_ptr->prev_row, 0, |
| 921 | png_ptr->rowbytes + 1); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 922 | do |
| 923 | { |
| 924 | png_ptr->pass++; |
| 925 | if (png_ptr->pass >= 7) |
| 926 | break; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 927 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 928 | png_ptr->iwidth = (png_ptr->width + |
| 929 | png_pass_inc[png_ptr->pass] - 1 - |
| 930 | png_pass_start[png_ptr->pass]) / |
| 931 | png_pass_inc[png_ptr->pass]; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 932 | |
| 933 | png_ptr->irowbytes = ((png_ptr->iwidth * |
| 934 | png_ptr->pixel_depth + 7) >> 3) + 1; |
| 935 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 936 | if (png_ptr->transformations & PNG_INTERLACE) |
| 937 | break; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 938 | |
| 939 | png_ptr->num_rows = (png_ptr->height + |
| 940 | png_pass_yinc[png_ptr->pass] - 1 - |
| 941 | png_pass_ystart[png_ptr->pass]) / |
| 942 | png_pass_yinc[png_ptr->pass]; |
| 943 | |
| 944 | } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 948 | #if defined(PNG_READ_tEXt_SUPPORTED) |
| 949 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 950 | png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 951 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 952 | if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND) |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 953 | { |
| 954 | png_error(png_ptr, "Out of place tEXt"); |
| 955 | /* to quiet some compiler warnings */ |
| 956 | if(info_ptr == NULL) return; |
| 957 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 958 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 959 | #ifdef PNG_MAX_MALLOC_64K |
| 960 | png_ptr->skip_length = 0; /* This may not be necessary */ |
| 961 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 962 | if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 963 | { |
| 964 | png_warning(png_ptr, "tEXt chunk too large to fit in memory"); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 965 | png_ptr->skip_length = length - (png_uint_32)65535L; |
| 966 | length = (png_uint_32)65535L; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 967 | } |
| 968 | #endif |
| 969 | |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 970 | png_ptr->current_text = (png_charp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 971 | (png_uint_32)(length+1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 972 | png_ptr->current_text[length] = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 973 | png_ptr->current_text_ptr = png_ptr->current_text; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 974 | png_ptr->current_text_size = (png_size_t)length; |
| 975 | png_ptr->current_text_left = (png_size_t)length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 976 | png_ptr->process_mode = PNG_READ_tEXt_MODE; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 980 | png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 981 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 982 | if (png_ptr->buffer_size && png_ptr->current_text_left) |
| 983 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 984 | png_size_t text_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 985 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 986 | if (png_ptr->buffer_size < png_ptr->current_text_left) |
| 987 | text_size = png_ptr->buffer_size; |
| 988 | else |
| 989 | text_size = png_ptr->current_text_left; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 990 | png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 991 | png_ptr->current_text_left -= text_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 992 | png_ptr->current_text_ptr += text_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 993 | } |
| 994 | if (!(png_ptr->current_text_left)) |
| 995 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 996 | png_textp text_ptr; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 997 | png_charp text; |
| 998 | png_charp key; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 999 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1000 | if (png_ptr->buffer_size < 4) |
| 1001 | { |
| 1002 | png_push_save_buffer(png_ptr); |
| 1003 | return; |
| 1004 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1005 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1006 | png_push_crc_finish(png_ptr); |
| 1007 | |
| 1008 | #if defined(PNG_MAX_MALLOC_64K) |
| 1009 | if (png_ptr->skip_length) |
| 1010 | return; |
| 1011 | #endif |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1012 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1013 | key = png_ptr->current_text; |
| 1014 | png_ptr->current_text = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1015 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1016 | for (text = key; *text; text++) |
| 1017 | /* empty loop */ ; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1018 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1019 | if (text != key + png_ptr->current_text_size) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1020 | text++; |
| 1021 | |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1022 | text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1023 | text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 1024 | text_ptr->lang = (char *)NULL; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1025 | text_ptr->key = key; |
| 1026 | text_ptr->text = text; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1027 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1028 | png_set_text(png_ptr, info_ptr, text_ptr, 1); |
| 1029 | |
| 1030 | png_free(png_ptr, text_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1031 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1032 | } |
| 1033 | #endif |
| 1034 | |
| 1035 | #if defined(PNG_READ_zTXt_SUPPORTED) |
| 1036 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1037 | png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1038 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1039 | if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND) |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 1040 | { |
| 1041 | png_error(png_ptr, "Out of place zTXt"); |
| 1042 | /* to quiet some compiler warnings */ |
| 1043 | if(info_ptr == NULL) return; |
| 1044 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1045 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1046 | #ifdef PNG_MAX_MALLOC_64K |
| 1047 | /* We can't handle zTXt chunks > 64K, since we don't have enough space |
| 1048 | * to be able to store the uncompressed data. Actually, the threshold |
| 1049 | * is probably around 32K, but it isn't as definite as 64K is. |
| 1050 | */ |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1051 | if (length > (png_uint_32)65535L) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1052 | { |
| 1053 | png_warning(png_ptr, "zTXt chunk too large to fit in memory"); |
| 1054 | png_push_crc_skip(png_ptr, length); |
| 1055 | return; |
| 1056 | } |
| 1057 | #endif |
| 1058 | |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1059 | png_ptr->current_text = (png_charp)png_malloc(png_ptr, |
| 1060 | (png_uint_32)(length+1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1061 | png_ptr->current_text[length] = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1062 | png_ptr->current_text_ptr = png_ptr->current_text; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1063 | png_ptr->current_text_size = (png_size_t)length; |
| 1064 | png_ptr->current_text_left = (png_size_t)length; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1065 | png_ptr->process_mode = PNG_READ_zTXt_MODE; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1069 | png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1070 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1071 | if (png_ptr->buffer_size && png_ptr->current_text_left) |
| 1072 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1073 | png_size_t text_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1074 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1075 | if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1076 | text_size = png_ptr->buffer_size; |
| 1077 | else |
| 1078 | text_size = png_ptr->current_text_left; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1079 | png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1080 | png_ptr->current_text_left -= text_size; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1081 | png_ptr->current_text_ptr += text_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1082 | } |
| 1083 | if (!(png_ptr->current_text_left)) |
| 1084 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1085 | png_textp text_ptr; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1086 | png_charp text; |
| 1087 | png_charp key; |
| 1088 | int ret; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1089 | png_size_t text_size, key_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1090 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1091 | if (png_ptr->buffer_size < 4) |
| 1092 | { |
| 1093 | png_push_save_buffer(png_ptr); |
| 1094 | return; |
| 1095 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1096 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1097 | png_push_crc_finish(png_ptr); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1098 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1099 | key = png_ptr->current_text; |
| 1100 | png_ptr->current_text = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1101 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1102 | for (text = key; *text; text++) |
| 1103 | /* empty loop */ ; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1104 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1105 | /* zTXt can't have zero text */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1106 | if (text == key + png_ptr->current_text_size) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1107 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1108 | png_free(png_ptr, key); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1109 | return; |
| 1110 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1111 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1112 | text++; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1113 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1114 | if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1115 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1116 | png_free(png_ptr, key); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1117 | return; |
| 1118 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1119 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1120 | text++; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1121 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1122 | png_ptr->zstream.next_in = (png_bytep )text; |
| 1123 | png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size - |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1124 | (text - key)); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1125 | png_ptr->zstream.next_out = png_ptr->zbuf; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1126 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1127 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1128 | key_size = text - key; |
| 1129 | text_size = 0; |
| 1130 | text = NULL; |
| 1131 | ret = Z_STREAM_END; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1132 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1133 | while (png_ptr->zstream.avail_in) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1134 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1135 | ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1136 | if (ret != Z_OK && ret != Z_STREAM_END) |
| 1137 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1138 | inflateReset(&png_ptr->zstream); |
| 1139 | png_ptr->zstream.avail_in = 0; |
| 1140 | png_free(png_ptr, key); |
| 1141 | png_free(png_ptr, text); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1142 | return; |
| 1143 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1144 | if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1145 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1146 | if (text == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1147 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1148 | text = (png_charp)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1149 | (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + |
| 1150 | key_size + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1151 | png_memcpy(text + key_size, png_ptr->zbuf, |
| 1152 | png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
| 1153 | png_memcpy(text, key, key_size); |
| 1154 | text_size = key_size + png_ptr->zbuf_size - |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1155 | png_ptr->zstream.avail_out; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1156 | *(text + text_size) = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1157 | } |
| 1158 | else |
| 1159 | { |
| 1160 | png_charp tmp; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1161 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1162 | tmp = text; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1163 | text = (png_charp)png_malloc(png_ptr, text_size + |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1164 | (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out |
| 1165 | + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1166 | png_memcpy(text, tmp, text_size); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1167 | png_free(png_ptr, tmp); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1168 | png_memcpy(text + text_size, png_ptr->zbuf, |
| 1169 | png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1170 | text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1171 | *(text + text_size) = '\0'; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1172 | } |
| 1173 | if (ret != Z_STREAM_END) |
| 1174 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1175 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 1176 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | else |
| 1180 | { |
| 1181 | break; |
| 1182 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1183 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1184 | if (ret == Z_STREAM_END) |
| 1185 | break; |
| 1186 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1187 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1188 | inflateReset(&png_ptr->zstream); |
| 1189 | png_ptr->zstream.avail_in = 0; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1190 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1191 | if (ret != Z_STREAM_END) |
| 1192 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1193 | png_free(png_ptr, key); |
| 1194 | png_free(png_ptr, text); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1195 | return; |
| 1196 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1197 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1198 | png_free(png_ptr, key); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1199 | key = text; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1200 | text += key_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1201 | |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1202 | text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1203 | text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame^] | 1204 | text_ptr->lang = (char *)NULL; |
| 1205 | text_ptr->key = key; |
| 1206 | text_ptr->text = text; |
| 1207 | |
| 1208 | png_set_text(png_ptr, info_ptr, text_ptr, 1); |
| 1209 | |
| 1210 | png_free(png_ptr, text_ptr); |
| 1211 | } |
| 1212 | } |
| 1213 | #endif |
| 1214 | |
| 1215 | #if defined(PNG_READ_iTXt_SUPPORTED) |
| 1216 | void |
| 1217 | png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) |
| 1218 | { |
| 1219 | if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND) |
| 1220 | { |
| 1221 | png_error(png_ptr, "Out of place iTXt"); |
| 1222 | /* to quiet some compiler warnings */ |
| 1223 | if(info_ptr == NULL) return; |
| 1224 | } |
| 1225 | |
| 1226 | #ifdef PNG_MAX_MALLOC_64K |
| 1227 | png_ptr->skip_length = 0; /* This may not be necessary */ |
| 1228 | |
| 1229 | if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */ |
| 1230 | { |
| 1231 | png_warning(png_ptr, "iTXt chunk too large to fit in memory"); |
| 1232 | png_ptr->skip_length = length - (png_uint_32)65535L; |
| 1233 | length = (png_uint_32)65535L; |
| 1234 | } |
| 1235 | #endif |
| 1236 | |
| 1237 | png_ptr->current_text = (png_charp)png_malloc(png_ptr, |
| 1238 | (png_uint_32)(length+1)); |
| 1239 | png_ptr->current_text[length] = '\0'; |
| 1240 | png_ptr->current_text_ptr = png_ptr->current_text; |
| 1241 | png_ptr->current_text_size = (png_size_t)length; |
| 1242 | png_ptr->current_text_left = (png_size_t)length; |
| 1243 | png_ptr->process_mode = PNG_READ_iTXt_MODE; |
| 1244 | } |
| 1245 | |
| 1246 | void |
| 1247 | png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) |
| 1248 | { |
| 1249 | if (png_ptr->buffer_size && png_ptr->current_text_left) |
| 1250 | { |
| 1251 | png_size_t text_size; |
| 1252 | |
| 1253 | if (png_ptr->buffer_size < png_ptr->current_text_left) |
| 1254 | text_size = png_ptr->buffer_size; |
| 1255 | else |
| 1256 | text_size = png_ptr->current_text_left; |
| 1257 | png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); |
| 1258 | png_ptr->current_text_left -= text_size; |
| 1259 | png_ptr->current_text_ptr += text_size; |
| 1260 | } |
| 1261 | if (!(png_ptr->current_text_left)) |
| 1262 | { |
| 1263 | png_textp text_ptr; |
| 1264 | png_charp text; |
| 1265 | png_charp lang; |
| 1266 | png_charp key; |
| 1267 | |
| 1268 | if (png_ptr->buffer_size < 4) |
| 1269 | { |
| 1270 | png_push_save_buffer(png_ptr); |
| 1271 | return; |
| 1272 | } |
| 1273 | |
| 1274 | png_push_crc_finish(png_ptr); |
| 1275 | |
| 1276 | #if defined(PNG_MAX_MALLOC_64K) |
| 1277 | if (png_ptr->skip_length) |
| 1278 | return; |
| 1279 | #endif |
| 1280 | |
| 1281 | lang = png_ptr->current_text; |
| 1282 | png_ptr->current_text = 0; |
| 1283 | |
| 1284 | for (key = lang; *key; key++) |
| 1285 | /* empty loop */ ; |
| 1286 | |
| 1287 | if (key != lang + png_ptr->current_text_size) |
| 1288 | key++; |
| 1289 | |
| 1290 | for (text = key; *text; text++) |
| 1291 | /* empty loop */ ; |
| 1292 | |
| 1293 | if (text != key + png_ptr->current_text_size) |
| 1294 | text++; |
| 1295 | |
| 1296 | text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text)); |
| 1297 | text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; |
| 1298 | text_ptr->lang = lang; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1299 | text_ptr->key = key; |
| 1300 | text_ptr->text = text; |
| 1301 | |
| 1302 | png_set_text(png_ptr, info_ptr, text_ptr, 1); |
| 1303 | |
| 1304 | png_free(png_ptr, text_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1305 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1306 | } |
| 1307 | #endif |
| 1308 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1309 | /* This function is called when we haven't found a handler for this |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 1310 | * chunk. In the future we will have code here that can handle |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1311 | * user-defined callback functions for unknown chunks before they are |
| 1312 | * ignored or cause an error. If there isn't a problem with the |
| 1313 | * chunk itself (ie a bad chunk name or a critical chunk), the chunk |
| 1314 | * is (currently) silently ignored. |
| 1315 | */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1316 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1317 | png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1318 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1319 | png_check_chunk_name(png_ptr, png_ptr->chunk_name); |
| 1320 | |
| 1321 | if (!(png_ptr->chunk_name[0] & 0x20)) |
| 1322 | { |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1323 | png_chunk_error(png_ptr, "unknown critical chunk"); |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 1324 | /* to quiet some compiler warnings */ |
| 1325 | if(info_ptr == NULL) return; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | png_push_crc_skip(png_ptr, length); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1332 | png_push_have_info(png_structp png_ptr, png_infop info_ptr) |
| 1333 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1334 | if (png_ptr->info_fn != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1335 | (*(png_ptr->info_fn))(png_ptr, info_ptr); |
| 1336 | } |
| 1337 | |
| 1338 | void |
| 1339 | png_push_have_end(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1340 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1341 | if (png_ptr->end_fn != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1342 | (*(png_ptr->end_fn))(png_ptr, info_ptr); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | void |
| 1346 | png_push_have_row(png_structp png_ptr, png_bytep row) |
| 1347 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1348 | if (png_ptr->row_fn != NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1349 | (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, |
| 1350 | (int)png_ptr->pass); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1351 | } |
| 1352 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1353 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1354 | png_progressive_combine_row (png_structp png_ptr, |
| 1355 | png_bytep old_row, png_bytep new_row) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1356 | { |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 1357 | #ifdef PNG_USE_LOCAL_ARRAYS |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1358 | const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; |
Glenn Randers-Pehrson | 074af5e | 1999-11-28 23:32:18 -0600 | [diff] [blame] | 1359 | #endif |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 1360 | if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1361 | png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | void |
| 1365 | png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1366 | png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, |
| 1367 | png_progressive_end_ptr end_fn) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1368 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1369 | png_ptr->info_fn = info_fn; |
| 1370 | png_ptr->row_fn = row_fn; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1371 | png_ptr->end_fn = end_fn; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1372 | |
| 1373 | png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1374 | } |
| 1375 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1376 | png_voidp |
| 1377 | png_get_progressive_ptr(png_structp png_ptr) |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1378 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1379 | return png_ptr->io_ptr; |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1380 | } |
| 1381 | |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 1382 | #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
| 1383 | |