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