Changeset 43 for vendor/libpng/pngset.c
- Timestamp:
- 02/15/10 11:37:15 (2 years ago)
- Files:
-
- 1 modified
-
vendor/libpng/pngset.c (modified) (47 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/libpng/pngset.c
r11 r43 2 2 /* pngset.c - storage of image information into info struct 3 3 * 4 * Last changed in libpng 1.2.4 0 [September 10, 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.) … … 18 18 19 19 #define PNG_INTERNAL 20 #define PNG_NO_PEDANTIC_WARNINGS 20 21 #include "png.h" 21 22 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 22 23 23 #if defined(PNG_bKGD_SUPPORTED)24 #ifdef PNG_bKGD_SUPPORTED 24 25 void PNGAPI 25 26 png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) … … 35 36 #endif 36 37 37 #if defined(PNG_cHRM_SUPPORTED)38 #ifdef PNG_cHRM_SUPPORTED 38 39 #ifdef PNG_FLOATING_POINT_SUPPORTED 39 40 void PNGAPI … … 81 82 return; 82 83 83 #if !defined(PNG_NO_CHECK_cHRM)84 #ifdef PNG_CHECK_cHRM_SUPPORTED 84 85 if (png_check_cHRM_fixed(png_ptr, 85 86 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) … … 110 111 #endif /* PNG_cHRM_SUPPORTED */ 111 112 112 #if defined(PNG_gAMA_SUPPORTED)113 #ifdef PNG_gAMA_SUPPORTED 113 114 #ifdef PNG_FLOATING_POINT_SUPPORTED 114 115 void PNGAPI … … 177 178 #endif 178 179 179 #if defined(PNG_hIST_SUPPORTED)180 #ifdef PNG_hIST_SUPPORTED 180 181 void PNGAPI 181 182 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) … … 234 235 return; 235 236 236 /* Check for width and height valid values */237 if (width == 0 || height == 0)238 png_error(png_ptr, "Image width or height is zero in IHDR");239 #ifdef PNG_SET_USER_LIMITS_SUPPORTED240 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)241 png_error(png_ptr, "image size exceeds user limits in IHDR");242 #else243 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)244 png_error(png_ptr, "image size exceeds user limits in IHDR");245 #endif246 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)247 png_error(png_ptr, "Invalid image size in IHDR");248 if ( width > (PNG_UINT_32_MAX249 >> 3) /* 8-byte RGBA pixels */250 - 64 /* bigrowbuf hack */251 - 1 /* filter byte */252 - 7*8 /* rounding of width to multiple of 8 pixels */253 - 8) /* extra max_pixel_depth pad */254 png_warning(png_ptr, "Width is too large for libpng to process pixels");255 256 /* Check other values */257 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&258 bit_depth != 8 && bit_depth != 16)259 png_error(png_ptr, "Invalid bit depth in IHDR");260 261 if (color_type < 0 || color_type == 1 ||262 color_type == 5 || color_type > 6)263 png_error(png_ptr, "Invalid color type in IHDR");264 265 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||266 ((color_type == PNG_COLOR_TYPE_RGB ||267 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||268 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))269 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");270 271 if (interlace_type >= PNG_INTERLACE_LAST)272 png_error(png_ptr, "Unknown interlace method in IHDR");273 274 if (compression_type != PNG_COMPRESSION_TYPE_BASE)275 png_error(png_ptr, "Unknown compression method in IHDR");276 277 #if defined(PNG_MNG_FEATURES_SUPPORTED)278 /* Accept filter_method 64 (intrapixel differencing) only if279 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and280 * 2. Libpng did not read a PNG signature (this filter_method is only281 * used in PNG datastreams that are embedded in MNG datastreams) and282 * 3. The application called png_permit_mng_features with a mask that283 * included PNG_FLAG_MNG_FILTER_64 and284 * 4. The filter_method is 64 and285 * 5. The color_type is RGB or RGBA286 */287 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)288 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");289 if (filter_type != PNG_FILTER_TYPE_BASE)290 {291 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&292 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&293 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&294 (color_type == PNG_COLOR_TYPE_RGB ||295 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))296 png_error(png_ptr, "Unknown filter method in IHDR");297 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)298 png_warning(png_ptr, "Invalid filter method in IHDR");299 }300 #else301 if (filter_type != PNG_FILTER_TYPE_BASE)302 png_error(png_ptr, "Unknown filter method in IHDR");303 #endif304 305 237 info_ptr->width = width; 306 238 info_ptr->height = height; 307 239 info_ptr->bit_depth = (png_byte)bit_depth; 308 info_ptr->color_type = (png_byte)color_type;240 info_ptr->color_type = (png_byte)color_type; 309 241 info_ptr->compression_type = (png_byte)compression_type; 310 242 info_ptr->filter_type = (png_byte)filter_type; 311 243 info_ptr->interlace_type = (png_byte)interlace_type; 244 245 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, 246 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, 247 info_ptr->compression_type, info_ptr->filter_type); 248 312 249 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 313 250 info_ptr->channels = 1; … … 332 269 } 333 270 334 #if defined(PNG_oFFs_SUPPORTED)271 #ifdef PNG_oFFs_SUPPORTED 335 272 void PNGAPI 336 273 png_set_oFFs(png_structp png_ptr, png_infop info_ptr, … … 349 286 #endif 350 287 351 #if defined(PNG_pCAL_SUPPORTED)288 #ifdef PNG_pCAL_SUPPORTED 352 289 void PNGAPI 353 290 png_set_pCAL(png_structp png_ptr, png_infop info_ptr, … … 461 398 { 462 399 png_warning(png_ptr, 463 "Memory allocation failed while processing sCAL.");400 "Memory allocation failed while processing sCAL."); 464 401 return; 465 402 } … … 475 412 info_ptr->scal_s_width = NULL; 476 413 png_warning(png_ptr, 477 "Memory allocation failed while processing sCAL.");414 "Memory allocation failed while processing sCAL."); 478 415 return; 479 416 } … … 488 425 #endif 489 426 490 #if defined(PNG_pHYs_SUPPORTED)427 #ifdef PNG_pHYs_SUPPORTED 491 428 void PNGAPI 492 429 png_set_pHYs(png_structp png_ptr, png_infop info_ptr, … … 526 463 } 527 464 528 /* 529 * It may not actually be necessary to set png_ptr->palette here; 465 /* It may not actually be necessary to set png_ptr->palette here; 530 466 * we do it for backward compatibility with the way the png_handle_tRNS 531 467 * function used to do the allocation. … … 539 475 * too-large sample values. 540 476 */ 541 png_ptr->palette = (png_colorp)png_ malloc(png_ptr,477 png_ptr->palette = (png_colorp)png_calloc(png_ptr, 542 478 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); 543 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *544 png_sizeof(png_color));545 479 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); 546 480 info_ptr->palette = png_ptr->palette; … … 556 490 } 557 491 558 #if defined(PNG_sBIT_SUPPORTED)492 #ifdef PNG_sBIT_SUPPORTED 559 493 void PNGAPI 560 494 png_set_sBIT(png_structp png_ptr, png_infop info_ptr, … … 571 505 #endif 572 506 573 #if defined(PNG_sRGB_SUPPORTED)507 #ifdef PNG_sRGB_SUPPORTED 574 508 void PNGAPI 575 509 png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) … … 588 522 int intent) 589 523 { 590 #if defined(PNG_gAMA_SUPPORTED)524 #ifdef PNG_gAMA_SUPPORTED 591 525 #ifdef PNG_FLOATING_POINT_SUPPORTED 592 526 float file_gamma; … … 596 530 #endif 597 531 #endif 598 #if defined(PNG_cHRM_SUPPORTED)532 #ifdef PNG_cHRM_SUPPORTED 599 533 #ifdef PNG_FLOATING_POINT_SUPPORTED 600 534 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; … … 610 544 png_set_sRGB(png_ptr, info_ptr, intent); 611 545 612 #if defined(PNG_gAMA_SUPPORTED)546 #ifdef PNG_gAMA_SUPPORTED 613 547 #ifdef PNG_FLOATING_POINT_SUPPORTED 614 548 file_gamma = (float).45455; … … 621 555 #endif 622 556 623 #if defined(PNG_cHRM_SUPPORTED)557 #ifdef PNG_cHRM_SUPPORTED 624 558 int_white_x = 31270L; 625 559 int_white_y = 32900L; … … 642 576 #endif 643 577 644 #if !defined(PNG_NO_CHECK_cHRM)645 if (png_check_cHRM_fixed(png_ptr,578 #ifdef PNG_FIXED_POINT_SUPPORTED 579 png_set_cHRM_fixed(png_ptr, info_ptr, 646 580 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 647 int_green_y, int_blue_x, int_blue_y)) 648 #endif 649 { 650 #ifdef PNG_FIXED_POINT_SUPPORTED 651 png_set_cHRM_fixed(png_ptr, info_ptr, 652 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, 653 int_green_y, int_blue_x, int_blue_y); 581 int_green_y, int_blue_x, int_blue_y); 654 582 #endif 655 583 #ifdef PNG_FLOATING_POINT_SUPPORTED 656 png_set_cHRM(png_ptr, info_ptr, 657 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 658 #endif 659 } 584 png_set_cHRM(png_ptr, info_ptr, 585 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); 586 #endif 660 587 #endif /* cHRM */ 661 588 } … … 663 590 664 591 665 #if defined(PNG_iCCP_SUPPORTED)592 #ifdef PNG_iCCP_SUPPORTED 666 593 void PNGAPI 667 594 png_set_iCCP(png_structp png_ptr, png_infop info_ptr, … … 682 609 if (new_iccp_name == NULL) 683 610 { 684 png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");611 png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); 685 612 return; 686 613 } … … 691 618 png_free (png_ptr, new_iccp_name); 692 619 png_warning(png_ptr, 693 "Insufficient memory to process iCCP profile.");620 "Insufficient memory to process iCCP profile."); 694 621 return; 695 622 } … … 702 629 info_ptr->iccp_profile = new_iccp_profile; 703 630 /* Compression is always zero but is here so the API and info structure 704 * does not have to change if we introduce multiple compression types */ 631 * does not have to change if we introduce multiple compression types 632 */ 705 633 info_ptr->iccp_compression = (png_byte)compression_type; 706 634 #ifdef PNG_FREE_ME_SUPPORTED … … 711 639 #endif 712 640 713 #if defined(PNG_TEXT_SUPPORTED)641 #ifdef PNG_TEXT_SUPPORTED 714 642 void PNGAPI 715 643 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, … … 790 718 lang_key_len = 0; 791 719 } 720 792 721 else 793 722 #ifdef PNG_iTXt_SUPPORTED 794 723 { 795 724 /* Set iTXt data */ 725 796 726 if (text_ptr[i].lang != NULL) 797 727 lang_len = png_strlen(text_ptr[i].lang); … … 803 733 lang_key_len = 0; 804 734 } 805 #else 735 #else /* PNG_iTXt_SUPPORTED */ 806 736 { 807 737 png_warning(png_ptr, "iTXt chunk not supported."); … … 820 750 textp->compression = PNG_TEXT_COMPRESSION_NONE; 821 751 } 752 822 753 else 823 754 { … … 871 802 else 872 803 #endif 804 873 805 { 874 806 textp->text_length = text_length; … … 884 816 #endif 885 817 886 #if defined(PNG_tIME_SUPPORTED)818 #ifdef PNG_tIME_SUPPORTED 887 819 void PNGAPI 888 820 png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) … … 899 831 #endif 900 832 901 #if defined(PNG_tRNS_SUPPORTED)833 #ifdef PNG_tRNS_SUPPORTED 902 834 void PNGAPI 903 835 png_set_tRNS(png_structp png_ptr, png_infop info_ptr, … … 911 843 if (trans != NULL) 912 844 { 913 /* 914 * It may not actually be necessary to set png_ptr->trans here; 845 /* It may not actually be necessary to set png_ptr->trans here; 915 846 * we do it for backward compatibility with the way the png_handle_tRNS 916 847 * function used to do the allocation. … … 958 889 #endif 959 890 960 #if defined(PNG_sPLT_SUPPORTED)891 #ifdef PNG_sPLT_SUPPORTED 961 892 void PNGAPI 962 893 png_set_sPLT(png_structp png_ptr, … … 982 913 { 983 914 png_warning(png_ptr, "No memory for sPLT palettes."); 984 return;915 return; 985 916 } 986 917 987 918 png_memcpy(np, info_ptr->splt_palettes, 988 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));919 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); 989 920 png_free(png_ptr, info_ptr->splt_palettes); 990 921 info_ptr->splt_palettes=NULL; … … 997 928 998 929 length = png_strlen(from->name) + 1; 999 to->name = (png_charp)png_malloc_warn(png_ptr, length);930 to->name = (png_charp)png_malloc_warn(png_ptr, length); 1000 931 if (to->name == NULL) 1001 932 { … … 1006 937 png_memcpy(to->name, from->name, length); 1007 938 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, 1008 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));939 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); 1009 940 if (to->entries == NULL) 1010 941 { … … 1030 961 #endif /* PNG_sPLT_SUPPORTED */ 1031 962 1032 #ifdef PNG_ HANDLE_AS_UNKNOWN_SUPPORTED963 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED 1033 964 void PNGAPI 1034 965 png_set_unknown_chunks(png_structp png_ptr, … … 1047 978 { 1048 979 png_warning(png_ptr, 1049 "Out of memory while processing unknown chunk.");980 "Out of memory while processing unknown chunk."); 1050 981 return; 1051 982 } 1052 983 1053 984 png_memcpy(np, info_ptr->unknown_chunks, 1054 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));985 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); 1055 986 png_free(png_ptr, info_ptr->unknown_chunks); 1056 info_ptr->unknown_chunks =NULL;987 info_ptr->unknown_chunks = NULL; 1057 988 1058 989 for (i = 0; i < num_unknowns; i++) … … 1061 992 png_unknown_chunkp from = unknowns + i; 1062 993 1063 png_memcpy((png_charp)to->name, 1064 (png_charp)from->name, 1065 png_sizeof(from->name)); 994 png_memcpy((png_charp)to->name, (png_charp)from->name, 995 png_sizeof(from->name)); 1066 996 to->name[png_sizeof(to->name)-1] = '\0'; 1067 997 to->size = from->size; … … 1097 1027 { 1098 1028 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < 1099 (int)info_ptr->unknown_chunks_num)1029 (int)info_ptr->unknown_chunks_num) 1100 1030 info_ptr->unknown_chunks[chunk].location = (png_byte)location; 1101 1031 } … … 1122 1052 #endif 1123 1053 1124 #if defined(PNG_MNG_FEATURES_SUPPORTED)1054 #ifdef PNG_MNG_FEATURES_SUPPORTED 1125 1055 png_uint_32 PNGAPI 1126 1056 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) … … 1136 1066 #endif 1137 1067 1138 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)1068 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED 1139 1069 void PNGAPI 1140 1070 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep … … 1163 1093 new_list=(png_bytep)png_malloc(png_ptr, 1164 1094 (png_uint_32) 1165 (5*(num_chunks + old_num_chunks)));1095 (5*(num_chunks + old_num_chunks))); 1166 1096 if (png_ptr->chunk_list != NULL) 1167 1097 { 1168 1098 png_memcpy(new_list, png_ptr->chunk_list, 1169 (png_size_t)(5*old_num_chunks));1099 (png_size_t)(5*old_num_chunks)); 1170 1100 png_free(png_ptr, png_ptr->chunk_list); 1171 1101 png_ptr->chunk_list=NULL; 1172 1102 } 1173 1103 png_memcpy(new_list + 5*old_num_chunks, chunk_list, 1174 (png_size_t)(5*num_chunks));1104 (png_size_t)(5*num_chunks)); 1175 1105 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5) 1176 1106 *p=(png_byte)keep; … … 1183 1113 #endif 1184 1114 1185 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)1115 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED 1186 1116 void PNGAPI 1187 1117 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, … … 1198 1128 #endif 1199 1129 1200 #if defined(PNG_INFO_IMAGE_SUPPORTED)1130 #ifdef PNG_INFO_IMAGE_SUPPORTED 1201 1131 void PNGAPI 1202 1132 png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) … … 1282 1212 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ 1283 1213 1214 1215 #ifdef PNG_BENIGN_ERRORS_SUPPORTED 1216 void PNGAPI 1217 png_set_benign_errors(png_structp png_ptr, int allowed) 1218 { 1219 png_debug(1, "in png_set_benign_errors"); 1220 1221 if (allowed) 1222 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; 1223 else 1224 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; 1225 } 1226 #endif /* PNG_BENIGN_ERRORS_SUPPORTED */ 1284 1227 #endif /* ?PNG_1_0_X */ 1285 1228 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
