istereo2

annotate libs/libpng/pngpread.c @ 32:622f61160016

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