Changeset 43 for vendor/libpng/pngget.c
- Timestamp:
- 02/15/10 11:37:15 (2 years ago)
- Files:
-
- 1 modified
-
vendor/libpng/pngget.c (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/libpng/pngget.c
r11 r43 2 2 /* pngget.c - retrieval of values from info struct 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) … … 14 14 15 15 #define PNG_INTERNAL 16 #define PNG_NO_PEDANTIC_WARNINGS 16 17 #include "png.h" 17 18 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) … … 37 38 } 38 39 39 #if defined(PNG_INFO_IMAGE_SUPPORTED)40 #ifdef PNG_INFO_IMAGE_SUPPORTED 40 41 png_bytepp PNGAPI 41 42 png_get_rows(png_structp png_ptr, png_infop info_ptr) … … 118 119 { 119 120 if (png_ptr != NULL && info_ptr != NULL) 120 #if defined(PNG_pHYs_SUPPORTED)121 #ifdef PNG_pHYs_SUPPORTED 121 122 if (info_ptr->valid & PNG_INFO_pHYs) 122 123 { … … 139 140 { 140 141 if (png_ptr != NULL && info_ptr != NULL) 141 #if defined(PNG_pHYs_SUPPORTED)142 #ifdef PNG_pHYs_SUPPORTED 142 143 if (info_ptr->valid & PNG_INFO_pHYs) 143 144 { … … 160 161 { 161 162 if (png_ptr != NULL && info_ptr != NULL) 162 #if defined(PNG_pHYs_SUPPORTED)163 #ifdef PNG_pHYs_SUPPORTED 163 164 if (info_ptr->valid & PNG_INFO_pHYs) 164 165 { … … 183 184 { 184 185 if (png_ptr != NULL && info_ptr != NULL) 185 #if defined(PNG_pHYs_SUPPORTED)186 #ifdef PNG_pHYs_SUPPORTED 186 187 187 188 if (info_ptr->valid & PNG_INFO_pHYs) 188 189 { 189 190 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio"); 191 190 192 if (info_ptr->x_pixels_per_unit == 0) 191 193 return ((float)0.0); 194 192 195 else 193 196 return ((float)((float)info_ptr->y_pixels_per_unit … … 205 208 { 206 209 if (png_ptr != NULL && info_ptr != NULL) 207 #if defined(PNG_oFFs_SUPPORTED)210 #ifdef PNG_oFFs_SUPPORTED 208 211 209 212 if (info_ptr->valid & PNG_INFO_oFFs) … … 228 231 if (png_ptr != NULL && info_ptr != NULL) 229 232 230 #if defined(PNG_oFFs_SUPPORTED)233 #ifdef PNG_oFFs_SUPPORTED 231 234 if (info_ptr->valid & PNG_INFO_oFFs) 232 235 { … … 250 253 if (png_ptr != NULL && info_ptr != NULL) 251 254 252 #if defined(PNG_oFFs_SUPPORTED)255 #ifdef PNG_oFFs_SUPPORTED 253 256 if (info_ptr->valid & PNG_INFO_oFFs) 254 257 { … … 272 275 if (png_ptr != NULL && info_ptr != NULL) 273 276 274 #if defined(PNG_oFFs_SUPPORTED)277 #ifdef PNG_oFFs_SUPPORTED 275 278 if (info_ptr->valid & PNG_INFO_oFFs) 276 279 { … … 325 328 } 326 329 327 #if defined(PNG_pHYs_SUPPORTED)330 #ifdef PNG_pHYs_SUPPORTED 328 331 png_uint_32 PNGAPI 329 332 png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, … … 335 338 { 336 339 png_debug1(1, "in %s retrieval function", "pHYs"); 340 337 341 if (res_x != NULL) 338 342 { … … 383 387 } 384 388 385 #if defined(PNG_bKGD_SUPPORTED)389 #ifdef PNG_bKGD_SUPPORTED 386 390 png_uint_32 PNGAPI 387 391 png_get_bKGD(png_structp png_ptr, png_infop info_ptr, … … 392 396 { 393 397 png_debug1(1, "in %s retrieval function", "bKGD"); 398 394 399 *background = &(info_ptr->background); 395 400 return (PNG_INFO_bKGD); … … 399 404 #endif 400 405 401 #if defined(PNG_cHRM_SUPPORTED)406 #ifdef PNG_cHRM_SUPPORTED 402 407 #ifdef PNG_FLOATING_POINT_SUPPORTED 403 408 png_uint_32 PNGAPI … … 409 414 { 410 415 png_debug1(1, "in %s retrieval function", "cHRM"); 416 411 417 if (white_x != NULL) 412 418 *white_x = (double)info_ptr->x_white; … … 437 443 png_fixed_point *blue_x, png_fixed_point *blue_y) 438 444 { 445 png_debug1(1, "in %s retrieval function", "cHRM"); 446 439 447 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)) 440 448 { 441 png_debug1(1, "in %s retrieval function", "cHRM");442 449 if (white_x != NULL) 443 450 *white_x = info_ptr->int_x_white; … … 463 470 #endif 464 471 465 #if defined(PNG_gAMA_SUPPORTED)472 #ifdef PNG_gAMA_SUPPORTED 466 473 #ifdef PNG_FLOATING_POINT_SUPPORTED 467 474 png_uint_32 PNGAPI 468 475 png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) 469 476 { 477 png_debug1(1, "in %s retrieval function", "gAMA"); 478 470 479 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) 471 480 && file_gamma != NULL) 472 481 { 473 png_debug1(1, "in %s retrieval function", "gAMA");474 482 *file_gamma = (double)info_ptr->gamma; 475 483 return (PNG_INFO_gAMA); … … 483 491 png_fixed_point *int_file_gamma) 484 492 { 493 png_debug1(1, "in %s retrieval function", "gAMA"); 494 485 495 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) 486 496 && int_file_gamma != NULL) 487 497 { 488 png_debug1(1, "in %s retrieval function", "gAMA");489 498 *int_file_gamma = info_ptr->int_gamma; 490 499 return (PNG_INFO_gAMA); … … 495 504 #endif 496 505 497 #if defined(PNG_sRGB_SUPPORTED)506 #ifdef PNG_sRGB_SUPPORTED 498 507 png_uint_32 PNGAPI 499 508 png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) 500 509 { 510 png_debug1(1, "in %s retrieval function", "sRGB"); 511 501 512 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) 502 513 && file_srgb_intent != NULL) 503 514 { 504 png_debug1(1, "in %s retrieval function", "sRGB");505 515 *file_srgb_intent = (int)info_ptr->srgb_intent; 506 516 return (PNG_INFO_sRGB); … … 510 520 #endif 511 521 512 #if defined(PNG_iCCP_SUPPORTED)522 #ifdef PNG_iCCP_SUPPORTED 513 523 png_uint_32 PNGAPI 514 524 png_get_iCCP(png_structp png_ptr, png_infop info_ptr, … … 516 526 png_charpp profile, png_uint_32 *proflen) 517 527 { 528 png_debug1(1, "in %s retrieval function", "iCCP"); 529 518 530 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP) 519 531 && name != NULL && profile != NULL && proflen != NULL) 520 532 { 521 png_debug1(1, "in %s retrieval function", "iCCP");522 533 *name = info_ptr->iccp_name; 523 534 *profile = info_ptr->iccp_profile; … … 533 544 #endif 534 545 535 #if defined(PNG_sPLT_SUPPORTED)546 #ifdef PNG_sPLT_SUPPORTED 536 547 png_uint_32 PNGAPI 537 548 png_get_sPLT(png_structp png_ptr, png_infop info_ptr, … … 547 558 #endif 548 559 549 #if defined(PNG_hIST_SUPPORTED)560 #ifdef PNG_hIST_SUPPORTED 550 561 png_uint_32 PNGAPI 551 562 png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) 552 563 { 564 png_debug1(1, "in %s retrieval function", "hIST"); 565 553 566 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) 554 567 && hist != NULL) 555 568 { 556 png_debug1(1, "in %s retrieval function", "hIST");557 569 *hist = info_ptr->hist; 558 570 return (PNG_INFO_hIST); … … 569 581 570 582 { 571 if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL && 572 bit_depth != NULL && color_type != NULL) 573 { 574 png_debug1(1, "in %s retrieval function", "IHDR"); 575 *width = info_ptr->width; 576 *height = info_ptr->height; 577 *bit_depth = info_ptr->bit_depth; 578 if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16) 579 png_error(png_ptr, "Invalid bit depth"); 580 581 *color_type = info_ptr->color_type; 582 583 if (info_ptr->color_type > 6) 584 png_error(png_ptr, "Invalid color type"); 585 586 if (compression_type != NULL) 587 *compression_type = info_ptr->compression_type; 588 589 if (filter_type != NULL) 590 *filter_type = info_ptr->filter_type; 591 592 if (interlace_type != NULL) 593 *interlace_type = info_ptr->interlace_type; 594 595 /* Check for potential overflow of rowbytes */ 596 if (*width == 0 || *width > PNG_UINT_31_MAX) 597 png_error(png_ptr, "Invalid image width"); 598 599 if (*height == 0 || *height > PNG_UINT_31_MAX) 600 png_error(png_ptr, "Invalid image height"); 601 602 if (info_ptr->width > (PNG_UINT_32_MAX 603 >> 3) /* 8-byte RGBA pixels */ 604 - 64 /* bigrowbuf hack */ 605 - 1 /* filter byte */ 606 - 7*8 /* rounding of width to multiple of 8 pixels */ 607 - 8) /* extra max_pixel_depth pad */ 608 { 609 png_warning(png_ptr, 610 "Width too large for libpng to process image data."); 611 } 612 613 return (1); 614 } 615 return (0); 616 } 617 618 #if defined(PNG_oFFs_SUPPORTED) 583 png_debug1(1, "in %s retrieval function", "IHDR"); 584 585 if (png_ptr == NULL || info_ptr == NULL || width == NULL || 586 height == NULL || bit_depth == NULL || color_type == NULL) 587 return (0); 588 589 *width = info_ptr->width; 590 *height = info_ptr->height; 591 *bit_depth = info_ptr->bit_depth; 592 *color_type = info_ptr->color_type; 593 594 if (compression_type != NULL) 595 *compression_type = info_ptr->compression_type; 596 597 if (filter_type != NULL) 598 *filter_type = info_ptr->filter_type; 599 600 if (interlace_type != NULL) 601 *interlace_type = info_ptr->interlace_type; 602 603 /* This is redundant if we can be sure that the info_ptr values were all 604 * assigned in png_set_IHDR(). We do the check anyhow in case an 605 * application has ignored our advice not to mess with the members 606 * of info_ptr directly. 607 */ 608 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, 609 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, 610 info_ptr->compression_type, info_ptr->filter_type); 611 612 return (1); 613 } 614 615 #ifdef PNG_oFFs_SUPPORTED 619 616 png_uint_32 PNGAPI 620 617 png_get_oFFs(png_structp png_ptr, png_infop info_ptr, 621 618 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) 622 619 { 620 png_debug1(1, "in %s retrieval function", "oFFs"); 621 623 622 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) 624 623 && offset_x != NULL && offset_y != NULL && unit_type != NULL) 625 624 { 626 png_debug1(1, "in %s retrieval function", "oFFs");627 625 *offset_x = info_ptr->x_offset; 628 626 *offset_y = info_ptr->y_offset; … … 634 632 #endif 635 633 636 #if defined(PNG_pCAL_SUPPORTED)634 #ifdef PNG_pCAL_SUPPORTED 637 635 png_uint_32 PNGAPI 638 636 png_get_pCAL(png_structp png_ptr, png_infop info_ptr, … … 640 638 png_charp *units, png_charpp *params) 641 639 { 640 png_debug1(1, "in %s retrieval function", "pCAL"); 641 642 642 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) 643 643 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL && 644 644 nparams != NULL && units != NULL && params != NULL) 645 645 { 646 png_debug1(1, "in %s retrieval function", "pCAL");647 646 *purpose = info_ptr->pcal_purpose; 648 647 *X0 = info_ptr->pcal_X0; … … 658 657 #endif 659 658 660 #if defined(PNG_sCAL_SUPPORTED)659 #ifdef PNG_sCAL_SUPPORTED 661 660 #ifdef PNG_FLOATING_POINT_SUPPORTED 662 661 png_uint_32 PNGAPI … … 694 693 #endif 695 694 696 #if defined(PNG_pHYs_SUPPORTED)695 #ifdef PNG_pHYs_SUPPORTED 697 696 png_uint_32 PNGAPI 698 697 png_get_pHYs(png_structp png_ptr, png_infop info_ptr, … … 701 700 png_uint_32 retval = 0; 702 701 702 png_debug1(1, "in %s retrieval function", "pHYs"); 703 703 704 if (png_ptr != NULL && info_ptr != NULL && 704 705 (info_ptr->valid & PNG_INFO_pHYs)) 705 706 { 706 png_debug1(1, "in %s retrieval function", "pHYs");707 708 707 if (res_x != NULL) 709 708 { … … 732 731 int *num_palette) 733 732 { 733 png_debug1(1, "in %s retrieval function", "PLTE"); 734 734 735 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE) 735 736 && palette != NULL) 736 737 { 737 png_debug1(1, "in %s retrieval function", "PLTE");738 738 *palette = info_ptr->palette; 739 739 *num_palette = info_ptr->num_palette; … … 744 744 } 745 745 746 #if defined(PNG_sBIT_SUPPORTED)746 #ifdef PNG_sBIT_SUPPORTED 747 747 png_uint_32 PNGAPI 748 748 png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) 749 749 { 750 png_debug1(1, "in %s retrieval function", "sBIT"); 751 750 752 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) 751 753 && sig_bit != NULL) 752 754 { 753 png_debug1(1, "in %s retrieval function", "sBIT");754 755 *sig_bit = &(info_ptr->sig_bit); 755 756 return (PNG_INFO_sBIT); … … 759 760 #endif 760 761 761 #if defined(PNG_TEXT_SUPPORTED)762 #ifdef PNG_TEXT_SUPPORTED 762 763 png_uint_32 PNGAPI 763 764 png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, … … 784 785 #endif 785 786 786 #if defined(PNG_tIME_SUPPORTED)787 #ifdef PNG_tIME_SUPPORTED 787 788 png_uint_32 PNGAPI 788 789 png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) 789 790 { 791 png_debug1(1, "in %s retrieval function", "tIME"); 792 790 793 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) 791 794 && mod_time != NULL) 792 795 { 793 png_debug1(1, "in %s retrieval function", "tIME");794 796 *mod_time = &(info_ptr->mod_time); 795 797 return (PNG_INFO_tIME); … … 799 801 #endif 800 802 801 #if defined(PNG_tRNS_SUPPORTED)803 #ifdef PNG_tRNS_SUPPORTED 802 804 png_uint_32 PNGAPI 803 805 png_get_tRNS(png_structp png_ptr, png_infop info_ptr, … … 808 810 { 809 811 png_debug1(1, "in %s retrieval function", "tRNS"); 812 810 813 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 811 814 { … … 840 843 #endif 841 844 842 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)845 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 843 846 png_uint_32 PNGAPI 844 847 png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, … … 854 857 #endif 855 858 856 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)859 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED 857 860 png_byte PNGAPI 858 861 png_get_rgb_to_gray_status (png_structp png_ptr) … … 862 865 #endif 863 866 864 #if defined(PNG_USER_CHUNKS_SUPPORTED)867 #ifdef PNG_USER_CHUNKS_SUPPORTED 865 868 png_voidp PNGAPI 866 869 png_get_user_chunk_ptr(png_structp png_ptr) … … 940 943 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 941 944 942 943 945 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
