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