Changeset 43 for vendor/libpng/png.c
- Timestamp:
- 02/15/10 11:37:15 (2 years ago)
- Files:
-
- 1 modified
-
vendor/libpng/png.c (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/libpng/png.c
r11 r43 2 2 /* png.c - location for general purpose libpng functions 3 3 * 4 * Last changed in libpng 1.2. 39 [August 13, 2009]5 * Copyright (c) 1998-20 09Glenn Randers-Pehrson4 * Last changed in libpng 1.2.42 [January 3, 2010] 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson 6 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) … … 14 14 #define PNG_INTERNAL 15 15 #define PNG_NO_EXTERN 16 #define PNG_NO_PEDANTIC_WARNINGS 16 17 #include "png.h" 17 18 18 19 /* Generate a compiler error if there is an old png.h in the search path. */ 19 typedef version_1_2_4 0 Your_png_h_is_not_version_1_2_40;20 typedef version_1_2_42 Your_png_h_is_not_version_1_2_42; 20 21 21 22 /* Version information for C files. This had better match the version 22 * string defined in png.h. */ 23 * string defined in png.h. 24 */ 23 25 24 26 #ifdef PNG_USE_GLOBAL_ARRAYS … … 96 98 png_set_sig_bytes(png_structp png_ptr, int num_bytes) 97 99 { 100 png_debug(1, "in png_set_sig_bytes"); 101 98 102 if (png_ptr == NULL) 99 103 return; 100 png_debug(1, "in png_set_sig_bytes"); 104 101 105 if (num_bytes > 8) 102 106 png_error(png_ptr, "Too many bytes for PNG signature."); … … 247 251 248 252 png_debug(1, "in png_create_info_struct"); 253 249 254 if (png_ptr == NULL) 250 255 return (NULL); 256 251 257 #ifdef PNG_USER_MEM_SUPPORTED 252 258 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, … … 270 276 { 271 277 png_infop info_ptr = NULL; 278 279 png_debug(1, "in png_destroy_info_struct"); 280 272 281 if (png_ptr == NULL) 273 282 return; 274 283 275 png_debug(1, "in png_destroy_info_struct");276 284 if (info_ptr_ptr != NULL) 277 285 info_ptr = *info_ptr_ptr; … … 310 318 png_infop info_ptr = *ptr_ptr; 311 319 320 png_debug(1, "in png_info_init_3"); 321 312 322 if (info_ptr == NULL) 313 323 return; 314 315 png_debug(1, "in png_info_init_3");316 324 317 325 if (png_sizeof(png_info) > png_info_struct_size) … … 332 340 { 333 341 png_debug(1, "in png_data_freer"); 342 334 343 if (png_ptr == NULL || info_ptr == NULL) 335 344 return; 345 336 346 if (freer == PNG_DESTROY_WILL_FREE_DATA) 337 347 info_ptr->free_me |= mask; … … 349 359 { 350 360 png_debug(1, "in png_free_data"); 361 351 362 if (png_ptr == NULL || info_ptr == NULL) 352 363 return; 353 364 354 #if defined(PNG_TEXT_SUPPORTED)365 #ifdef PNG_TEXT_SUPPORTED 355 366 /* Free text item num or (if num == -1) all text items */ 356 367 #ifdef PNG_FREE_ME_SUPPORTED … … 380 391 #endif 381 392 382 #if defined(PNG_tRNS_SUPPORTED)393 #ifdef PNG_tRNS_SUPPORTED 383 394 /* Free any tRNS entry */ 384 395 #ifdef PNG_FREE_ME_SUPPORTED … … 397 408 #endif 398 409 399 #if defined(PNG_sCAL_SUPPORTED)410 #ifdef PNG_sCAL_SUPPORTED 400 411 /* Free any sCAL entry */ 401 412 #ifdef PNG_FREE_ME_SUPPORTED … … 415 426 #endif 416 427 417 #if defined(PNG_pCAL_SUPPORTED)428 #ifdef PNG_pCAL_SUPPORTED 418 429 /* Free any pCAL entry */ 419 430 #ifdef PNG_FREE_ME_SUPPORTED … … 433 444 { 434 445 png_free(png_ptr, info_ptr->pcal_params[i]); 435 info_ptr->pcal_params[i] =NULL;446 info_ptr->pcal_params[i] = NULL; 436 447 } 437 448 png_free(png_ptr, info_ptr->pcal_params); … … 442 453 #endif 443 454 444 #if defined(PNG_iCCP_SUPPORTED)455 #ifdef PNG_iCCP_SUPPORTED 445 456 /* Free any iCCP entry */ 446 457 #ifdef PNG_FREE_ME_SUPPORTED … … 458 469 #endif 459 470 460 #if defined(PNG_sPLT_SUPPORTED)471 #ifdef PNG_sPLT_SUPPORTED 461 472 /* Free a given sPLT entry, or (if num == -1) all sPLT entries */ 462 473 #ifdef PNG_FREE_ME_SUPPORTED … … 493 504 #endif 494 505 495 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)506 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 496 507 if (png_ptr->unknown_chunk.data) 497 508 { … … 531 542 #endif 532 543 533 #if defined(PNG_hIST_SUPPORTED)544 #ifdef PNG_hIST_SUPPORTED 534 545 /* Free any hIST entry */ 535 546 #ifdef PNG_FREE_ME_SUPPORTED … … 564 575 } 565 576 566 #if defined(PNG_INFO_IMAGE_SUPPORTED)577 #ifdef PNG_INFO_IMAGE_SUPPORTED 567 578 /* Free any image bits attached to the info structure */ 568 579 #ifdef PNG_FREE_ME_SUPPORTED … … 578 589 { 579 590 png_free(png_ptr, info_ptr->row_pointers[row]); 580 info_ptr->row_pointers[row] =NULL;591 info_ptr->row_pointers[row] = NULL; 581 592 } 582 593 png_free(png_ptr, info_ptr->row_pointers); 583 info_ptr->row_pointers =NULL;594 info_ptr->row_pointers = NULL; 584 595 } 585 596 info_ptr->valid &= ~PNG_INFO_IDAT; … … 606 617 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 607 618 608 #if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)619 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 609 620 if (png_ptr->num_chunk_list) 610 621 { 611 622 png_free(png_ptr, png_ptr->chunk_list); 612 png_ptr->chunk_list =NULL;623 png_ptr->chunk_list = NULL; 613 624 png_ptr->num_chunk_list = 0; 614 625 } … … 632 643 633 644 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 634 #if !defined(PNG_NO_STDIO)645 #ifdef PNG_STDIO_SUPPORTED 635 646 /* Initialize the default input/output functions for the PNG file. If you 636 647 * use your own read or write routines, you can call either png_set_read_fn() … … 643 654 { 644 655 png_debug(1, "in png_init_io"); 656 645 657 if (png_ptr == NULL) 646 658 return; 659 647 660 png_ptr->io_ptr = (png_voidp)fp; 648 661 } 649 662 #endif 650 663 651 #if defined(PNG_TIME_RFC1123_SUPPORTED)664 #ifdef PNG_TIME_RFC1123_SUPPORTED 652 665 /* Convert the supplied time into an RFC 1123 string suitable for use in 653 666 * a "Creation Time" or other text-based time string. … … 668 681 } 669 682 670 #if defined(_WIN32_WCE)683 #ifdef _WIN32_WCE 671 684 { 672 685 wchar_t time_buf[29]; … … 706 719 { 707 720 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ 708 return ((png_charp) "\n libpng version 1.2.40 - September 10, 2009\n\ 709 Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\ 710 Copyright (c) 1996-1997 Andreas Dilger\n\ 711 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); 721 #ifdef PNG_STRING_COPYRIGHT 722 return PNG_STRING_COPYRIGHT 723 #else 724 #ifdef __STDC__ 725 return ((png_charp) PNG_STRING_NEWLINE \ 726 "libpng version 1.2.42 - January 3, 2010" PNG_STRING_NEWLINE \ 727 "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ 728 "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ 729 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ 730 PNG_STRING_NEWLINE); 731 #else 732 return ((png_charp) "libpng version 1.2.42 - January 3, 2010\ 733 Copyright (c) 1998-2010 Glenn Randers-Pehrson\ 734 Copyright (c) 1996-1997 Andreas Dilger\ 735 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); 736 #endif 737 #endif 712 738 } 713 739 … … 741 767 /* Returns longer string containing both version and date */ 742 768 png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ 769 #ifdef __STDC__ 743 770 return ((png_charp) PNG_HEADER_VERSION_STRING 744 771 #ifndef PNG_READ_SUPPORTED 745 772 " (NO READ SUPPORT)" 746 773 #endif 747 "\n"); 774 PNG_STRING_NEWLINE); 775 #else 776 return ((png_charp) PNG_HEADER_VERSION_STRING); 777 #endif 748 778 } 749 779 … … 786 816 787 817 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) 788 #if !defined(PNG_1_0_X)818 #ifndef PNG_1_0_X 789 819 /* This function was added to libpng 1.2.0 */ 790 820 int PNGAPI … … 811 841 812 842 /* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */ 813 #if defined(PNG_cHRM_SUPPORTED)814 #if !defined(PNG_NO_CHECK_cHRM)843 #ifdef PNG_cHRM_SUPPORTED 844 #ifdef PNG_CHECK_cHRM_SUPPORTED 815 845 816 846 /* … … 864 894 865 895 png_debug(1, "in function png_check_cHRM_fixed"); 896 866 897 if (png_ptr == NULL) 867 898 return 0; … … 922 953 return ret; 923 954 } 924 #endif /* NO_PNG_CHECK_cHRM*/955 #endif /* PNG_CHECK_cHRM_SUPPORTED */ 925 956 #endif /* PNG_cHRM_SUPPORTED */ 957 958 void /* PRIVATE */ 959 png_check_IHDR(png_structp png_ptr, 960 png_uint_32 width, png_uint_32 height, int bit_depth, 961 int color_type, int interlace_type, int compression_type, 962 int filter_type) 963 { 964 int error = 0; 965 966 /* Check for width and height valid values */ 967 if (width == 0) 968 { 969 png_warning(png_ptr, "Image width is zero in IHDR"); 970 error = 1; 971 } 972 973 if (height == 0) 974 { 975 png_warning(png_ptr, "Image height is zero in IHDR"); 976 error = 1; 977 } 978 979 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 980 if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX) 981 #else 982 if (width > PNG_USER_WIDTH_MAX) 983 #endif 984 { 985 png_warning(png_ptr, "Image width exceeds user limit in IHDR"); 986 error = 1; 987 } 988 989 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 990 if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX) 991 #else 992 if (height > PNG_USER_HEIGHT_MAX) 993 #endif 994 { 995 png_warning(png_ptr, "Image height exceeds user limit in IHDR"); 996 error = 1; 997 } 998 999 if (width > PNG_UINT_31_MAX) 1000 { 1001 png_warning(png_ptr, "Invalid image width in IHDR"); 1002 error = 1; 1003 } 1004 1005 if ( height > PNG_UINT_31_MAX) 1006 { 1007 png_warning(png_ptr, "Invalid image height in IHDR"); 1008 error = 1; 1009 } 1010 1011 if ( width > (PNG_UINT_32_MAX 1012 >> 3) /* 8-byte RGBA pixels */ 1013 - 64 /* bigrowbuf hack */ 1014 - 1 /* filter byte */ 1015 - 7*8 /* rounding of width to multiple of 8 pixels */ 1016 - 8) /* extra max_pixel_depth pad */ 1017 png_warning(png_ptr, "Width is too large for libpng to process pixels"); 1018 1019 /* Check other values */ 1020 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && 1021 bit_depth != 8 && bit_depth != 16) 1022 { 1023 png_warning(png_ptr, "Invalid bit depth in IHDR"); 1024 error = 1; 1025 } 1026 1027 if (color_type < 0 || color_type == 1 || 1028 color_type == 5 || color_type > 6) 1029 { 1030 png_warning(png_ptr, "Invalid color type in IHDR"); 1031 error = 1; 1032 } 1033 1034 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || 1035 ((color_type == PNG_COLOR_TYPE_RGB || 1036 color_type == PNG_COLOR_TYPE_GRAY_ALPHA || 1037 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) 1038 { 1039 png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR"); 1040 error = 1; 1041 } 1042 1043 if (interlace_type >= PNG_INTERLACE_LAST) 1044 { 1045 png_warning(png_ptr, "Unknown interlace method in IHDR"); 1046 error = 1; 1047 } 1048 1049 if (compression_type != PNG_COMPRESSION_TYPE_BASE) 1050 { 1051 png_warning(png_ptr, "Unknown compression method in IHDR"); 1052 error = 1; 1053 } 1054 1055 #ifdef PNG_MNG_FEATURES_SUPPORTED 1056 /* Accept filter_method 64 (intrapixel differencing) only if 1057 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 1058 * 2. Libpng did not read a PNG signature (this filter_method is only 1059 * used in PNG datastreams that are embedded in MNG datastreams) and 1060 * 3. The application called png_permit_mng_features with a mask that 1061 * included PNG_FLAG_MNG_FILTER_64 and 1062 * 4. The filter_method is 64 and 1063 * 5. The color_type is RGB or RGBA 1064 */ 1065 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) && 1066 png_ptr->mng_features_permitted) 1067 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 1068 1069 if (filter_type != PNG_FILTER_TYPE_BASE) 1070 { 1071 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 1072 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && 1073 ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) && 1074 (color_type == PNG_COLOR_TYPE_RGB || 1075 color_type == PNG_COLOR_TYPE_RGB_ALPHA))) 1076 { 1077 png_warning(png_ptr, "Unknown filter method in IHDR"); 1078 error = 1; 1079 } 1080 1081 if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) 1082 { 1083 png_warning(png_ptr, "Invalid filter method in IHDR"); 1084 error = 1; 1085 } 1086 } 1087 1088 #else 1089 if (filter_type != PNG_FILTER_TYPE_BASE) 1090 { 1091 png_warning(png_ptr, "Unknown filter method in IHDR"); 1092 error = 1; 1093 } 1094 #endif 1095 1096 if (error == 1) 1097 png_error(png_ptr, "Invalid IHDR data"); 1098 } 926 1099 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
