Changeset 44 for cafu/trunk/ExtLibs/libpng/pngread.c
- Timestamp:
- 02/15/10 11:56:43 (2 years ago)
- Files:
-
- 1 modified
-
cafu/trunk/ExtLibs/libpng/pngread.c (modified) (57 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/ExtLibs/libpng/pngread.c
r11 r44 2 2 /* pngread.c - read a PNG file 3 3 * 4 * Last changed in libpng 1.2. 37 [June 4, 2009]4 * Last changed in libpng 1.2.41 [December 3, 2009] 5 5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 6 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) … … 16 16 17 17 #define PNG_INTERNAL 18 #define PNG_NO_PEDANTIC_WARNINGS 18 19 #include "png.h" 19 #if defined(PNG_READ_SUPPORTED) 20 #ifdef PNG_READ_SUPPORTED 21 20 22 21 23 /* Create a PNG structure for reading, and allocate any memory needed. */ … … 52 54 53 55 png_debug(1, "in png_create_read_struct"); 56 54 57 #ifdef PNG_USER_MEM_SUPPORTED 55 58 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, … … 63 66 /* Added at libpng-1.2.6 */ 64 67 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 65 png_ptr->user_width_max =PNG_USER_WIDTH_MAX;66 png_ptr->user_height_max =PNG_USER_HEIGHT_MAX;68 png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 69 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 67 70 #endif 68 71 … … 87 90 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); 88 91 #endif 89 #endif 92 #endif /* PNG_SETJMP_SUPPORTED */ 90 93 91 94 #ifdef PNG_USER_MEM_SUPPORTED … … 97 100 if (user_png_ver) 98 101 { 99 i = 0;100 do101 {102 if (user_png_ver[i] != png_libpng_ver[i])103 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;104 } while (png_libpng_ver[i++]);105 }106 else107 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;108 109 110 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)111 {112 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so113 * we must recompile any applications that use any older library version.114 * For versions after libpng 1.0, we will be compatible, so we need115 * only check the first digit.116 */117 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||118 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||119 (user_png_ver[0] == '0' && user_png_ver[2] < '9'))120 {121 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)122 char msg[80];123 if (user_png_ver)124 {125 png_snprintf(msg, 80,126 "Application was compiled with png.h from libpng-%.20s",127 user_png_ver);128 png_warning(png_ptr, msg);129 }130 png_snprintf(msg, 80,102 i = 0; 103 do 104 { 105 if (user_png_ver[i] != png_libpng_ver[i]) 106 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 107 } while (png_libpng_ver[i++]); 108 } 109 else 110 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 111 112 113 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) 114 { 115 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so 116 * we must recompile any applications that use any older library version. 117 * For versions after libpng 1.0, we will be compatible, so we need 118 * only check the first digit. 119 */ 120 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || 121 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || 122 (user_png_ver[0] == '0' && user_png_ver[2] < '9')) 123 { 124 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 125 char msg[80]; 126 if (user_png_ver) 127 { 128 png_snprintf(msg, 80, 129 "Application was compiled with png.h from libpng-%.20s", 130 user_png_ver); 131 png_warning(png_ptr, msg); 132 } 133 png_snprintf(msg, 80, 131 134 "Application is running with png.c from libpng-%.20s", 132 png_libpng_ver);133 png_warning(png_ptr, msg);135 png_libpng_ver); 136 png_warning(png_ptr, msg); 134 137 #endif 135 138 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 136 png_ptr->flags = 0;137 #endif 138 png_error(png_ptr,139 "Incompatible libpng version in application and library");140 }139 png_ptr->flags = 0; 140 #endif 141 png_error(png_ptr, 142 "Incompatible libpng version in application and library"); 143 } 141 144 } 142 145 … … 149 152 png_ptr->zstream.opaque = (voidpf)png_ptr; 150 153 151 switch (inflateInit(&png_ptr->zstream)) 152 { 153 case Z_OK: /* Do nothing */ break; 154 case Z_MEM_ERROR: 155 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; 156 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break; 157 default: png_error(png_ptr, "Unknown zlib error"); 158 } 154 switch (inflateInit(&png_ptr->zstream)) 155 { 156 case Z_OK: /* Do nothing */ break; 157 case Z_MEM_ERROR: 158 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); 159 break; 160 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); 161 break; 162 default: png_error(png_ptr, "Unknown zlib error"); 163 } 164 159 165 160 166 png_ptr->zstream.next_out = png_ptr->zbuf; … … 164 170 165 171 #ifdef PNG_SETJMP_SUPPORTED 166 /* Applications that neglect to set up their own setjmp() and then encounter167 a png_error() will longjmp here. Since the jmpbuf is then meaningless we168 abort instead of returning. */172 /* Applications that neglect to set up their own setjmp() and then 173 encounter a png_error() will longjmp here. Since the jmpbuf is 174 then meaningless we abort instead of returning. */ 169 175 #ifdef USE_FAR_KEYWORD 170 176 if (setjmp(jmpbuf)) 171 PNG_ABORT();177 PNG_ABORT(); 172 178 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); 173 179 #else 174 180 if (setjmp(png_ptr->jmpbuf)) 175 PNG_ABORT(); 176 #endif 177 #endif 181 PNG_ABORT(); 182 #endif 183 #endif /* PNG_SETJMP_SUPPORTED */ 184 178 185 return (png_ptr); 179 186 } … … 181 188 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) 182 189 /* Initialize PNG structure for reading, and allocate any memory needed. 183 This interface is deprecated in favour of the png_create_read_struct(), 184 and it will disappear as of libpng-1.3.0. */ 190 * This interface is deprecated in favour of the png_create_read_struct(), 191 * and it will disappear as of libpng-1.3.0. 192 */ 185 193 #undef png_read_init 186 194 void PNGAPI … … 198 206 if (png_ptr == NULL) 199 207 return; 200 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)208 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 201 209 if (png_sizeof(png_struct) > png_struct_size || 202 210 png_sizeof(png_info) > png_info_size) … … 218 226 #endif 219 227 if (png_sizeof(png_struct) > png_struct_size) 220 {221 png_ptr->error_fn = NULL;228 { 229 png_ptr->error_fn = NULL; 222 230 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 223 png_ptr->flags = 0;224 #endif 225 png_error(png_ptr,226 "The png struct allocated by the application for reading is too small.");227 }231 png_ptr->flags = 0; 232 #endif 233 png_error(png_ptr, 234 "The png struct allocated by the application for reading is too small."); 235 } 228 236 if (png_sizeof(png_info) > png_info_size) 229 {230 png_ptr->error_fn = NULL;237 { 238 png_ptr->error_fn = NULL; 231 239 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 232 png_ptr->flags = 0;233 #endif 234 png_error(png_ptr,235 "The info struct allocated by application for reading is too small.");236 }240 png_ptr->flags = 0; 241 #endif 242 png_error(png_ptr, 243 "The info struct allocated by application for reading is too small."); 244 } 237 245 png_read_init_3(&png_ptr, user_png_ver, png_struct_size); 238 246 } … … 256 264 do 257 265 { 258 if (user_png_ver[i] != png_libpng_ver[i])259 {266 if (user_png_ver[i] != png_libpng_ver[i]) 267 { 260 268 #ifdef PNG_LEGACY_SUPPORTED 261 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;269 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 262 270 #else 263 png_ptr->warning_fn = NULL;264 png_warning(png_ptr,265 "Application uses deprecated png_read_init() and should be recompiled.");266 break;267 #endif 268 }271 png_ptr->warning_fn = NULL; 272 png_warning(png_ptr, 273 "Application uses deprecated png_read_init() and should be recompiled."); 274 break; 275 #endif 276 } 269 277 } while (png_libpng_ver[i++]); 270 278 … … 293 301 /* Added at libpng-1.2.6 */ 294 302 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 295 png_ptr->user_width_max =PNG_USER_WIDTH_MAX;296 png_ptr->user_height_max =PNG_USER_HEIGHT_MAX;303 png_ptr->user_width_max = PNG_USER_WIDTH_MAX; 304 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; 297 305 #endif 298 306 299 307 /* Initialize zbuf - compression buffer */ 300 308 png_ptr->zbuf_size = PNG_ZBUF_SIZE; 309 png_ptr->zstream.zalloc = png_zalloc; 301 310 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 302 311 (png_uint_32)png_ptr->zbuf_size); … … 307 316 switch (inflateInit(&png_ptr->zstream)) 308 317 { 309 case Z_OK: /* Do nothing */ break; 310 case Z_MEM_ERROR: 311 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break; 312 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break; 313 default: png_error(png_ptr, "Unknown zlib error"); 318 case Z_OK: /* Do nothing */ break; 319 case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break; 320 case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break; 321 default: png_error(png_ptr, "Unknown zlib error"); 314 322 } 315 323 … … 320 328 } 321 329 322 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED330 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 323 331 /* Read the information before the actual image data. This has been 324 332 * changed in v0.90 to allow reading a file that already has the magic … … 332 340 png_read_info(png_structp png_ptr, png_infop info_ptr) 333 341 { 342 png_debug(1, "in png_read_info"); 343 334 344 if (png_ptr == NULL || info_ptr == NULL) 335 345 return; 336 png_debug(1, "in png_read_info");346 337 347 /* If we haven't checked all of the PNG signature bytes, do so now. */ 338 348 if (png_ptr->sig_bytes < 8) … … 363 373 PNG_CONST PNG_IEND; 364 374 PNG_CONST PNG_PLTE; 365 #if defined(PNG_READ_bKGD_SUPPORTED)375 #ifdef PNG_READ_bKGD_SUPPORTED 366 376 PNG_CONST PNG_bKGD; 367 377 #endif 368 #if defined(PNG_READ_cHRM_SUPPORTED)378 #ifdef PNG_READ_cHRM_SUPPORTED 369 379 PNG_CONST PNG_cHRM; 370 380 #endif 371 #if defined(PNG_READ_gAMA_SUPPORTED)381 #ifdef PNG_READ_gAMA_SUPPORTED 372 382 PNG_CONST PNG_gAMA; 373 383 #endif 374 #if defined(PNG_READ_hIST_SUPPORTED)384 #ifdef PNG_READ_hIST_SUPPORTED 375 385 PNG_CONST PNG_hIST; 376 386 #endif 377 #if defined(PNG_READ_iCCP_SUPPORTED)387 #ifdef PNG_READ_iCCP_SUPPORTED 378 388 PNG_CONST PNG_iCCP; 379 389 #endif 380 #if defined(PNG_READ_iTXt_SUPPORTED)390 #ifdef PNG_READ_iTXt_SUPPORTED 381 391 PNG_CONST PNG_iTXt; 382 392 #endif 383 #if defined(PNG_READ_oFFs_SUPPORTED)393 #ifdef PNG_READ_oFFs_SUPPORTED 384 394 PNG_CONST PNG_oFFs; 385 395 #endif 386 #if defined(PNG_READ_pCAL_SUPPORTED)396 #ifdef PNG_READ_pCAL_SUPPORTED 387 397 PNG_CONST PNG_pCAL; 388 398 #endif 389 #if defined(PNG_READ_pHYs_SUPPORTED)399 #ifdef PNG_READ_pHYs_SUPPORTED 390 400 PNG_CONST PNG_pHYs; 391 401 #endif 392 #if defined(PNG_READ_sBIT_SUPPORTED)402 #ifdef PNG_READ_sBIT_SUPPORTED 393 403 PNG_CONST PNG_sBIT; 394 404 #endif 395 #if defined(PNG_READ_sCAL_SUPPORTED)405 #ifdef PNG_READ_sCAL_SUPPORTED 396 406 PNG_CONST PNG_sCAL; 397 407 #endif 398 #if defined(PNG_READ_sPLT_SUPPORTED)408 #ifdef PNG_READ_sPLT_SUPPORTED 399 409 PNG_CONST PNG_sPLT; 400 410 #endif 401 #if defined(PNG_READ_sRGB_SUPPORTED)411 #ifdef PNG_READ_sRGB_SUPPORTED 402 412 PNG_CONST PNG_sRGB; 403 413 #endif 404 #if defined(PNG_READ_tEXt_SUPPORTED)414 #ifdef PNG_READ_tEXt_SUPPORTED 405 415 PNG_CONST PNG_tEXt; 406 416 #endif 407 #if defined(PNG_READ_tIME_SUPPORTED)417 #ifdef PNG_READ_tIME_SUPPORTED 408 418 PNG_CONST PNG_tIME; 409 419 #endif 410 #if defined(PNG_READ_tRNS_SUPPORTED)420 #ifdef PNG_READ_tRNS_SUPPORTED 411 421 PNG_CONST PNG_tRNS; 412 422 #endif 413 #if defined(PNG_READ_zTXt_SUPPORTED)423 #ifdef PNG_READ_zTXt_SUPPORTED 414 424 PNG_CONST PNG_zTXt; 415 425 #endif … … 462 472 break; 463 473 } 464 #if defined(PNG_READ_bKGD_SUPPORTED)474 #ifdef PNG_READ_bKGD_SUPPORTED 465 475 else if (!png_memcmp(chunk_name, png_bKGD, 4)) 466 476 png_handle_bKGD(png_ptr, info_ptr, length); 467 477 #endif 468 #if defined(PNG_READ_cHRM_SUPPORTED)478 #ifdef PNG_READ_cHRM_SUPPORTED 469 479 else if (!png_memcmp(chunk_name, png_cHRM, 4)) 470 480 png_handle_cHRM(png_ptr, info_ptr, length); 471 481 #endif 472 #if defined(PNG_READ_gAMA_SUPPORTED)482 #ifdef PNG_READ_gAMA_SUPPORTED 473 483 else if (!png_memcmp(chunk_name, png_gAMA, 4)) 474 484 png_handle_gAMA(png_ptr, info_ptr, length); 475 485 #endif 476 #if defined(PNG_READ_hIST_SUPPORTED)486 #ifdef PNG_READ_hIST_SUPPORTED 477 487 else if (!png_memcmp(chunk_name, png_hIST, 4)) 478 488 png_handle_hIST(png_ptr, info_ptr, length); 479 489 #endif 480 #if defined(PNG_READ_oFFs_SUPPORTED)490 #ifdef PNG_READ_oFFs_SUPPORTED 481 491 else if (!png_memcmp(chunk_name, png_oFFs, 4)) 482 492 png_handle_oFFs(png_ptr, info_ptr, length); 483 493 #endif 484 #if defined(PNG_READ_pCAL_SUPPORTED)494 #ifdef PNG_READ_pCAL_SUPPORTED 485 495 else if (!png_memcmp(chunk_name, png_pCAL, 4)) 486 496 png_handle_pCAL(png_ptr, info_ptr, length); 487 497 #endif 488 #if defined(PNG_READ_sCAL_SUPPORTED)498 #ifdef PNG_READ_sCAL_SUPPORTED 489 499 else if (!png_memcmp(chunk_name, png_sCAL, 4)) 490 500 png_handle_sCAL(png_ptr, info_ptr, length); 491 501 #endif 492 #if defined(PNG_READ_pHYs_SUPPORTED)502 #ifdef PNG_READ_pHYs_SUPPORTED 493 503 else if (!png_memcmp(chunk_name, png_pHYs, 4)) 494 504 png_handle_pHYs(png_ptr, info_ptr, length); 495 505 #endif 496 #if defined(PNG_READ_sBIT_SUPPORTED)506 #ifdef PNG_READ_sBIT_SUPPORTED 497 507 else if (!png_memcmp(chunk_name, png_sBIT, 4)) 498 508 png_handle_sBIT(png_ptr, info_ptr, length); 499 509 #endif 500 #if defined(PNG_READ_sRGB_SUPPORTED)510 #ifdef PNG_READ_sRGB_SUPPORTED 501 511 else if (!png_memcmp(chunk_name, png_sRGB, 4)) 502 512 png_handle_sRGB(png_ptr, info_ptr, length); 503 513 #endif 504 #if defined(PNG_READ_iCCP_SUPPORTED)514 #ifdef PNG_READ_iCCP_SUPPORTED 505 515 else if (!png_memcmp(chunk_name, png_iCCP, 4)) 506 516 png_handle_iCCP(png_ptr, info_ptr, length); 507 517 #endif 508 #if defined(PNG_READ_sPLT_SUPPORTED)518 #ifdef PNG_READ_sPLT_SUPPORTED 509 519 else if (!png_memcmp(chunk_name, png_sPLT, 4)) 510 520 png_handle_sPLT(png_ptr, info_ptr, length); 511 521 #endif 512 #if defined(PNG_READ_tEXt_SUPPORTED)522 #ifdef PNG_READ_tEXt_SUPPORTED 513 523 else if (!png_memcmp(chunk_name, png_tEXt, 4)) 514 524 png_handle_tEXt(png_ptr, info_ptr, length); 515 525 #endif 516 #if defined(PNG_READ_tIME_SUPPORTED)526 #ifdef PNG_READ_tIME_SUPPORTED 517 527 else if (!png_memcmp(chunk_name, png_tIME, 4)) 518 528 png_handle_tIME(png_ptr, info_ptr, length); 519 529 #endif 520 #if defined(PNG_READ_tRNS_SUPPORTED)530 #ifdef PNG_READ_tRNS_SUPPORTED 521 531 else if (!png_memcmp(chunk_name, png_tRNS, 4)) 522 532 png_handle_tRNS(png_ptr, info_ptr, length); 523 533 #endif 524 #if defined(PNG_READ_zTXt_SUPPORTED)534 #ifdef PNG_READ_zTXt_SUPPORTED 525 535 else if (!png_memcmp(chunk_name, png_zTXt, 4)) 526 536 png_handle_zTXt(png_ptr, info_ptr, length); 527 537 #endif 528 #if defined(PNG_READ_iTXt_SUPPORTED)538 #ifdef PNG_READ_iTXt_SUPPORTED 529 539 else if (!png_memcmp(chunk_name, png_iTXt, 4)) 530 540 png_handle_iTXt(png_ptr, info_ptr, length); … … 534 544 } 535 545 } 536 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */546 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 537 547 538 548 /* Optional call to update the users info_ptr structure */ … … 541 551 { 542 552 png_debug(1, "in png_read_update_info"); 553 543 554 if (png_ptr == NULL) 544 555 return; … … 548 559 png_warning(png_ptr, 549 560 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); 561 550 562 png_read_transform_info(png_ptr, info_ptr); 551 563 } 552 564 553 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED565 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 554 566 /* Initialize palette, background, etc, after transformations 555 567 * are set, but before any reading takes place. This allows … … 561 573 { 562 574 png_debug(1, "in png_start_read_image"); 575 563 576 if (png_ptr == NULL) 564 577 return; … … 566 579 png_read_start_row(png_ptr); 567 580 } 568 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */569 570 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED581 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 582 583 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 571 584 void PNGAPI 572 585 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) 573 586 { 574 #ifdef PNG_USE_LOCAL_ARRAYS575 587 PNG_CONST PNG_IDAT; 576 588 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 577 589 0xff}; 578 590 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; 579 #endif580 591 int ret; 592 581 593 if (png_ptr == NULL) 582 594 return; 595 583 596 png_debug2(1, "in png_read_row (row %lu, pass %d)", 584 597 png_ptr->row_number, png_ptr->pass); 598 585 599 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) 586 600 png_read_start_row(png_ptr); … … 618 632 } 619 633 620 #if defined(PNG_READ_INTERLACING_SUPPORTED)634 #ifdef PNG_READ_INTERLACING_SUPPORTED 621 635 /* If interlaced and we do not need a new row, combine row and return */ 622 636 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) … … 752 766 png_ptr->rowbytes + 1); 753 767 754 #if defined(PNG_MNG_FEATURES_SUPPORTED)768 #ifdef PNG_MNG_FEATURES_SUPPORTED 755 769 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 756 770 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) … … 765 779 png_do_read_transformations(png_ptr); 766 780 767 #if defined(PNG_READ_INTERLACING_SUPPORTED)781 #ifdef PNG_READ_INTERLACING_SUPPORTED 768 782 /* Blow up interlaced rows to full size */ 769 783 if (png_ptr->interlaced && … … 797 811 (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); 798 812 } 799 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */800 801 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED813 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 814 815 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 802 816 /* Read one or more rows of image data. If the image is interlaced, 803 817 * and png_set_interlace_handling() has been called, the rows need to … … 833 847 834 848 png_debug(1, "in png_read_rows"); 849 835 850 if (png_ptr == NULL) 836 851 return; … … 860 875 } 861 876 } 862 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */863 864 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED877 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 878 879 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 865 880 /* Read the entire image. If the image has an alpha channel or a tRNS 866 881 * chunk, and you have called png_handle_alpha()[*], you will need to … … 883 898 884 899 png_debug(1, "in png_read_image"); 900 885 901 if (png_ptr == NULL) 886 902 return; … … 909 925 } 910 926 } 911 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */912 913 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED927 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 928 929 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 914 930 /* Read the end of the PNG file. Will not read past the end of the 915 931 * file, will verify the end is accurate, and will read any comments … … 920 936 { 921 937 png_debug(1, "in png_read_end"); 938 922 939 if (png_ptr == NULL) 923 940 return; … … 931 948 PNG_CONST PNG_IEND; 932 949 PNG_CONST PNG_PLTE; 933 #if defined(PNG_READ_bKGD_SUPPORTED)950 #ifdef PNG_READ_bKGD_SUPPORTED 934 951 PNG_CONST PNG_bKGD; 935 952 #endif 936 #if defined(PNG_READ_cHRM_SUPPORTED)953 #ifdef PNG_READ_cHRM_SUPPORTED 937 954 PNG_CONST PNG_cHRM; 938 955 #endif 939 #if defined(PNG_READ_gAMA_SUPPORTED)956 #ifdef PNG_READ_gAMA_SUPPORTED 940 957 PNG_CONST PNG_gAMA; 941 958 #endif 942 #if defined(PNG_READ_hIST_SUPPORTED)959 #ifdef PNG_READ_hIST_SUPPORTED 943 960 PNG_CONST PNG_hIST; 944 961 #endif 945 #if defined(PNG_READ_iCCP_SUPPORTED)962 #ifdef PNG_READ_iCCP_SUPPORTED 946 963 PNG_CONST PNG_iCCP; 947 964 #endif 948 #if defined(PNG_READ_iTXt_SUPPORTED)965 #ifdef PNG_READ_iTXt_SUPPORTED 949 966 PNG_CONST PNG_iTXt; 950 967 #endif 951 #if defined(PNG_READ_oFFs_SUPPORTED)968 #ifdef PNG_READ_oFFs_SUPPORTED 952 969 PNG_CONST PNG_oFFs; 953 970 #endif 954 #if defined(PNG_READ_pCAL_SUPPORTED)971 #ifdef PNG_READ_pCAL_SUPPORTED 955 972 PNG_CONST PNG_pCAL; 956 973 #endif 957 #if defined(PNG_READ_pHYs_SUPPORTED)974 #ifdef PNG_READ_pHYs_SUPPORTED 958 975 PNG_CONST PNG_pHYs; 959 976 #endif 960 #if defined(PNG_READ_sBIT_SUPPORTED)977 #ifdef PNG_READ_sBIT_SUPPORTED 961 978 PNG_CONST PNG_sBIT; 962 979 #endif 963 #if defined(PNG_READ_sCAL_SUPPORTED)980 #ifdef PNG_READ_sCAL_SUPPORTED 964 981 PNG_CONST PNG_sCAL; 965 982 #endif 966 #if defined(PNG_READ_sPLT_SUPPORTED)983 #ifdef PNG_READ_sPLT_SUPPORTED 967 984 PNG_CONST PNG_sPLT; 968 985 #endif 969 #if defined(PNG_READ_sRGB_SUPPORTED)986 #ifdef PNG_READ_sRGB_SUPPORTED 970 987 PNG_CONST PNG_sRGB; 971 988 #endif 972 #if defined(PNG_READ_tEXt_SUPPORTED)989 #ifdef PNG_READ_tEXt_SUPPORTED 973 990 PNG_CONST PNG_tEXt; 974 991 #endif 975 #if defined(PNG_READ_tIME_SUPPORTED)992 #ifdef PNG_READ_tIME_SUPPORTED 976 993 PNG_CONST PNG_tIME; 977 994 #endif 978 #if defined(PNG_READ_tRNS_SUPPORTED)995 #ifdef PNG_READ_tRNS_SUPPORTED 979 996 PNG_CONST PNG_tRNS; 980 997 #endif 981 #if defined(PNG_READ_zTXt_SUPPORTED)998 #ifdef PNG_READ_zTXt_SUPPORTED 982 999 PNG_CONST PNG_zTXt; 983 1000 #endif … … 1014 1031 else if (!png_memcmp(chunk_name, png_PLTE, 4)) 1015 1032 png_handle_PLTE(png_ptr, info_ptr, length); 1016 #if defined(PNG_READ_bKGD_SUPPORTED)1033 #ifdef PNG_READ_bKGD_SUPPORTED 1017 1034 else if (!png_memcmp(chunk_name, png_bKGD, 4)) 1018 1035 png_handle_bKGD(png_ptr, info_ptr, length); 1019 1036 #endif 1020 #if defined(PNG_READ_cHRM_SUPPORTED)1037 #ifdef PNG_READ_cHRM_SUPPORTED 1021 1038 else if (!png_memcmp(chunk_name, png_cHRM, 4)) 1022 1039 png_handle_cHRM(png_ptr, info_ptr, length); 1023 1040 #endif 1024 #if defined(PNG_READ_gAMA_SUPPORTED)1041 #ifdef PNG_READ_gAMA_SUPPORTED 1025 1042 else if (!png_memcmp(chunk_name, png_gAMA, 4)) 1026 1043 png_handle_gAMA(png_ptr, info_ptr, length); 1027 1044 #endif 1028 #if defined(PNG_READ_hIST_SUPPORTED)1045 #ifdef PNG_READ_hIST_SUPPORTED 1029 1046 else if (!png_memcmp(chunk_name, png_hIST, 4)) 1030 1047 png_handle_hIST(png_ptr, info_ptr, length); 1031 1048 #endif 1032 #if defined(PNG_READ_oFFs_SUPPORTED)1049 #ifdef PNG_READ_oFFs_SUPPORTED 1033 1050 else if (!png_memcmp(chunk_name, png_oFFs, 4)) 1034 1051 png_handle_oFFs(png_ptr, info_ptr, length); 1035 1052 #endif 1036 #if defined(PNG_READ_pCAL_SUPPORTED)1053 #ifdef PNG_READ_pCAL_SUPPORTED 1037 1054 else if (!png_memcmp(chunk_name, png_pCAL, 4)) 1038 1055 png_handle_pCAL(png_ptr, info_ptr, length); 1039 1056 #endif 1040 #if defined(PNG_READ_sCAL_SUPPORTED)1057 #ifdef PNG_READ_sCAL_SUPPORTED 1041 1058 else if (!png_memcmp(chunk_name, png_sCAL, 4)) 1042 1059 png_handle_sCAL(png_ptr, info_ptr, length); 1043 1060 #endif 1044 #if defined(PNG_READ_pHYs_SUPPORTED)1061 #ifdef PNG_READ_pHYs_SUPPORTED 1045 1062 else if (!png_memcmp(chunk_name, png_pHYs, 4)) 1046 1063 png_handle_pHYs(png_ptr, info_ptr, length); 1047 1064 #endif 1048 #if defined(PNG_READ_sBIT_SUPPORTED)1065 #ifdef PNG_READ_sBIT_SUPPORTED 1049 1066 else if (!png_memcmp(chunk_name, png_sBIT, 4)) 1050 1067 png_handle_sBIT(png_ptr, info_ptr, length); 1051 1068 #endif 1052 #if defined(PNG_READ_sRGB_SUPPORTED)1069 #ifdef PNG_READ_sRGB_SUPPORTED 1053 1070 else if (!png_memcmp(chunk_name, png_sRGB, 4)) 1054 1071 png_handle_sRGB(png_ptr, info_ptr, length); 1055 1072 #endif 1056 #if defined(PNG_READ_iCCP_SUPPORTED)1073 #ifdef PNG_READ_iCCP_SUPPORTED 1057 1074 else if (!png_memcmp(chunk_name, png_iCCP, 4)) 1058 1075 png_handle_iCCP(png_ptr, info_ptr, length); 1059 1076 #endif 1060 #if defined(PNG_READ_sPLT_SUPPORTED)1077 #ifdef PNG_READ_sPLT_SUPPORTED 1061 1078 else if (!png_memcmp(chunk_name, png_sPLT, 4)) 1062 1079 png_handle_sPLT(png_ptr, info_ptr, length); 1063 1080 #endif 1064 #if defined(PNG_READ_tEXt_SUPPORTED)1081 #ifdef PNG_READ_tEXt_SUPPORTED 1065 1082 else if (!png_memcmp(chunk_name, png_tEXt, 4)) 1066 1083 png_handle_tEXt(png_ptr, info_ptr, length); 1067 1084 #endif 1068 #if defined(PNG_READ_tIME_SUPPORTED)1085 #ifdef PNG_READ_tIME_SUPPORTED 1069 1086 else if (!png_memcmp(chunk_name, png_tIME, 4)) 1070 1087 png_handle_tIME(png_ptr, info_ptr, length); 1071 1088 #endif 1072 #if defined(PNG_READ_tRNS_SUPPORTED)1089 #ifdef PNG_READ_tRNS_SUPPORTED 1073 1090 else if (!png_memcmp(chunk_name, png_tRNS, 4)) 1074 1091 png_handle_tRNS(png_ptr, info_ptr, length); 1075 1092 #endif 1076 #if defined(PNG_READ_zTXt_SUPPORTED)1093 #ifdef PNG_READ_zTXt_SUPPORTED 1077 1094 else if (!png_memcmp(chunk_name, png_zTXt, 4)) 1078 1095 png_handle_zTXt(png_ptr, info_ptr, length); 1079 1096 #endif 1080 #if defined(PNG_READ_iTXt_SUPPORTED)1097 #ifdef PNG_READ_iTXt_SUPPORTED 1081 1098 else if (!png_memcmp(chunk_name, png_iTXt, 4)) 1082 1099 png_handle_iTXt(png_ptr, info_ptr, length); … … 1086 1103 } while (!(png_ptr->mode & PNG_HAVE_IEND)); 1087 1104 } 1088 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */1105 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 1089 1106 1090 1107 /* Free all memory used by the read */ … … 1101 1118 1102 1119 png_debug(1, "in png_destroy_read_struct"); 1120 1103 1121 if (png_ptr_ptr != NULL) 1104 1122 png_ptr = *png_ptr_ptr; … … 1121 1139 if (info_ptr != NULL) 1122 1140 { 1123 #if defined(PNG_TEXT_SUPPORTED)1141 #ifdef PNG_TEXT_SUPPORTED 1124 1142 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); 1125 1143 #endif … … 1136 1154 if (end_info_ptr != NULL) 1137 1155 { 1138 #if defined(PNG_READ_TEXT_SUPPORTED)1156 #ifdef PNG_READ_TEXT_SUPPORTED 1139 1157 png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); 1140 1158 #endif … … 1175 1193 1176 1194 png_debug(1, "in png_read_destroy"); 1195 1177 1196 if (info_ptr != NULL) 1178 1197 png_info_destroy(png_ptr, info_ptr); … … 1185 1204 png_free(png_ptr, png_ptr->prev_row); 1186 1205 png_free(png_ptr, png_ptr->chunkdata); 1187 #if defined(PNG_READ_DITHER_SUPPORTED)1206 #ifdef PNG_READ_DITHER_SUPPORTED 1188 1207 png_free(png_ptr, png_ptr->palette_lookup); 1189 1208 png_free(png_ptr, png_ptr->dither_index); 1190 1209 #endif 1191 #if defined(PNG_READ_GAMMA_SUPPORTED)1210 #ifdef PNG_READ_GAMMA_SUPPORTED 1192 1211 png_free(png_ptr, png_ptr->gamma_table); 1193 1212 #endif 1194 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1213 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1195 1214 png_free(png_ptr, png_ptr->gamma_from_1); 1196 1215 png_free(png_ptr, png_ptr->gamma_to_1); … … 1217 1236 #endif 1218 1237 #endif 1219 #if defined(PNG_READ_hIST_SUPPORTED)1238 #ifdef PNG_READ_hIST_SUPPORTED 1220 1239 #ifdef PNG_FREE_ME_SUPPORTED 1221 1240 if (png_ptr->free_me & PNG_FREE_HIST) … … 1228 1247 #endif 1229 1248 #endif 1230 #if defined(PNG_READ_GAMMA_SUPPORTED)1249 #ifdef PNG_READ_GAMMA_SUPPORTED 1231 1250 if (png_ptr->gamma_16_table != NULL) 1232 1251 { … … 1239 1258 png_free(png_ptr, png_ptr->gamma_16_table); 1240 1259 } 1241 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1260 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1242 1261 if (png_ptr->gamma_16_from_1 != NULL) 1243 1262 { … … 1262 1281 #endif 1263 1282 #endif 1264 #if defined(PNG_TIME_RFC1123_SUPPORTED)1283 #ifdef PNG_TIME_RFC1123_SUPPORTED 1265 1284 png_free(png_ptr, png_ptr->time_buffer); 1266 1285 #endif … … 1315 1334 1316 1335 1317 #if ndef PNG_NO_SEQUENTIAL_READ_SUPPORTED1318 #if defined(PNG_INFO_IMAGE_SUPPORTED)1336 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 1337 #ifdef PNG_INFO_IMAGE_SUPPORTED 1319 1338 void PNGAPI 1320 1339 png_read_png(png_structp png_ptr, png_infop info_ptr, … … 1326 1345 if (png_ptr == NULL) 1327 1346 return; 1328 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)1347 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED 1329 1348 /* Invert the alpha channel from opacity to transparency 1330 1349 */ … … 1342 1361 /* -------------- image transformations start here ------------------- */ 1343 1362 1344 #if defined(PNG_READ_16_TO_8_SUPPORTED)1363 #ifdef PNG_READ_16_TO_8_SUPPORTED 1345 1364 /* Tell libpng to strip 16 bit/color files down to 8 bits per color. 1346 1365 */ … … 1349 1368 #endif 1350 1369 1351 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)1370 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED 1352 1371 /* Strip alpha bytes from the input data without combining with 1353 1372 * the background (not recommended). … … 1365 1384 #endif 1366 1385 1367 #if defined(PNG_READ_PACKSWAP_SUPPORTED)1386 #ifdef PNG_READ_PACKSWAP_SUPPORTED 1368 1387 /* Change the order of packed pixels to least significant bit first 1369 1388 * (not useful if you are using png_set_packing). … … 1373 1392 #endif 1374 1393 1375 #if defined(PNG_READ_EXPAND_SUPPORTED)1394 #ifdef PNG_READ_EXPAND_SUPPORTED 1376 1395 /* Expand paletted colors into true RGB triplets 1377 1396 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel … … 1389 1408 */ 1390 1409 1391 #if defined(PNG_READ_INVERT_SUPPORTED)1410 #ifdef PNG_READ_INVERT_SUPPORTED 1392 1411 /* Invert monochrome files to have 0 as white and 1 as black 1393 1412 */ … … 1396 1415 #endif 1397 1416 1398 #if defined(PNG_READ_SHIFT_SUPPORTED)1417 #ifdef PNG_READ_SHIFT_SUPPORTED 1399 1418 /* If you want to shift the pixel values from the range [0,255] or 1400 1419 * [0,65535] to the original [0,7] or [0,31], or whatever range the … … 1411 1430 #endif 1412 1431 1413 #if defined(PNG_READ_BGR_SUPPORTED)1432 #ifdef PNG_READ_BGR_SUPPORTED 1414 1433 /* Flip the RGB pixels to BGR (or RGBA to BGRA) 1415 1434 */ … … 1418 1437 #endif 1419 1438 1420 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)1439 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED 1421 1440 /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) 1422 1441 */ … … 1425 1444 #endif 1426 1445 1427 #if defined(PNG_READ_SWAP_SUPPORTED)1446 #ifdef PNG_READ_SWAP_SUPPORTED 1428 1447 /* Swap bytes of 16 bit files to least significant byte first 1429 1448 */ 1430 1449 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) 1431 1450 png_set_swap(png_ptr); 1451 #endif 1452 1453 /* Added at libpng-1.2.41 */ 1454 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED 1455 /* Invert the alpha channel from opacity to transparency 1456 */ 1457 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) 1458 png_set_invert_alpha(png_ptr); 1459 #endif 1460 1461 /* Added at libpng-1.2.41 */ 1462 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 1463 /* Expand grayscale image to RGB 1464 */ 1465 if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) 1466 png_set_gray_to_rgb(png_ptr); 1432 1467 #endif 1433 1468 … … 1451 1486 png_memset(info_ptr->row_pointers, 0, info_ptr->height 1452 1487 * png_sizeof(png_bytep)); 1488 1453 1489 #ifdef PNG_FREE_ME_SUPPORTED 1454 1490 info_ptr->free_me |= PNG_FREE_ROWS; 1455 1491 #endif 1492 1456 1493 for (row = 0; row < (int)info_ptr->height; row++) 1457 1494 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, … … 1470 1507 } 1471 1508 #endif /* PNG_INFO_IMAGE_SUPPORTED */ 1472 #endif /* PNG_ NO_SEQUENTIAL_READ_SUPPORTED */1509 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ 1473 1510 #endif /* PNG_READ_SUPPORTED */
