| OLD | NEW |
| 1 | 1 |
| 2 /* pngset.c - storage of image information into info struct | 2 /* pngset.c - storage of image information into info struct |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.43 [February 25, 2010] | 4 * Last changed in libpng 1.2.51 [February 6, 2014] |
| 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2014 Glenn Randers-Pehrson |
| 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 8 * | 8 * |
| 9 * This code is released under the libpng license. | 9 * This code is released under the libpng license. |
| 10 * For conditions of distribution and use, see the disclaimer | 10 * For conditions of distribution and use, see the disclaimer |
| 11 * and license in png.h | 11 * and license in png.h |
| 12 * | 12 * |
| 13 * The functions here are used during reads to store data from the file | 13 * The functions here are used during reads to store data from the file |
| 14 * into the info struct, and during writes to store application data | 14 * into the info struct, and during writes to store application data |
| 15 * into the info struct for writing into the file. This abstracts the | 15 * into the info struct for writing into the file. This abstracts the |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 float file_gamma; | 526 float file_gamma; |
| 527 #endif | 527 #endif |
| 528 #ifdef PNG_FIXED_POINT_SUPPORTED | 528 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 529 png_fixed_point int_file_gamma; | 529 png_fixed_point int_file_gamma; |
| 530 #endif | 530 #endif |
| 531 #endif | 531 #endif |
| 532 #ifdef PNG_cHRM_SUPPORTED | 532 #ifdef PNG_cHRM_SUPPORTED |
| 533 #ifdef PNG_FLOATING_POINT_SUPPORTED | 533 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 534 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; | 534 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; |
| 535 #endif | 535 #endif |
| 536 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 536 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, | 537 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, |
| 537 int_green_y, int_blue_x, int_blue_y; | 538 int_green_y, int_blue_x, int_blue_y; |
| 538 #endif | 539 #endif |
| 540 #endif |
| 539 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); | 541 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); |
| 540 | 542 |
| 541 if (png_ptr == NULL || info_ptr == NULL) | 543 if (png_ptr == NULL || info_ptr == NULL) |
| 542 return; | 544 return; |
| 543 | 545 |
| 544 png_set_sRGB(png_ptr, info_ptr, intent); | 546 png_set_sRGB(png_ptr, info_ptr, intent); |
| 545 | 547 |
| 546 #ifdef PNG_gAMA_SUPPORTED | 548 #ifdef PNG_gAMA_SUPPORTED |
| 547 #ifdef PNG_FLOATING_POINT_SUPPORTED | 549 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 548 file_gamma = (float).45455; | 550 file_gamma = (float).45455; |
| 549 png_set_gAMA(png_ptr, info_ptr, file_gamma); | 551 png_set_gAMA(png_ptr, info_ptr, file_gamma); |
| 550 #endif | 552 #endif |
| 551 #ifdef PNG_FIXED_POINT_SUPPORTED | 553 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 552 int_file_gamma = 45455L; | 554 int_file_gamma = 45455L; |
| 553 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); | 555 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); |
| 554 #endif | 556 #endif |
| 555 #endif | 557 #endif |
| 556 | 558 |
| 557 #ifdef PNG_cHRM_SUPPORTED | 559 #ifdef PNG_cHRM_SUPPORTED |
| 560 # ifdef PNG_FIXED_POINT_SUPPORTED |
| 558 int_white_x = 31270L; | 561 int_white_x = 31270L; |
| 559 int_white_y = 32900L; | 562 int_white_y = 32900L; |
| 560 int_red_x = 64000L; | 563 int_red_x = 64000L; |
| 561 int_red_y = 33000L; | 564 int_red_y = 33000L; |
| 562 int_green_x = 30000L; | 565 int_green_x = 30000L; |
| 563 int_green_y = 60000L; | 566 int_green_y = 60000L; |
| 564 int_blue_x = 15000L; | 567 int_blue_x = 15000L; |
| 565 int_blue_y = 6000L; | 568 int_blue_y = 6000L; |
| 569 png_set_cHRM_fixed(png_ptr, info_ptr, |
| 570 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, |
| 571 int_green_y, int_blue_x, int_blue_y); |
| 572 # endif |
| 566 | 573 |
| 567 #ifdef PNG_FLOATING_POINT_SUPPORTED | 574 # ifdef PNG_FLOATING_POINT_SUPPORTED |
| 568 white_x = (float).3127; | 575 white_x = (float).3127; |
| 569 white_y = (float).3290; | 576 white_y = (float).3290; |
| 570 red_x = (float).64; | 577 red_x = (float).64; |
| 571 red_y = (float).33; | 578 red_y = (float).33; |
| 572 green_x = (float).30; | 579 green_x = (float).30; |
| 573 green_y = (float).60; | 580 green_y = (float).60; |
| 574 blue_x = (float).15; | 581 blue_x = (float).15; |
| 575 blue_y = (float).06; | 582 blue_y = (float).06; |
| 576 #endif | |
| 577 | |
| 578 #ifdef PNG_FIXED_POINT_SUPPORTED | |
| 579 png_set_cHRM_fixed(png_ptr, info_ptr, | |
| 580 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, | |
| 581 int_green_y, int_blue_x, int_blue_y); | |
| 582 #endif | |
| 583 #ifdef PNG_FLOATING_POINT_SUPPORTED | |
| 584 png_set_cHRM(png_ptr, info_ptr, | 583 png_set_cHRM(png_ptr, info_ptr, |
| 585 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); | 584 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); |
| 586 #endif | 585 # endif |
| 587 #endif /* cHRM */ | 586 #endif /* cHRM */ |
| 588 } | 587 } |
| 589 #endif /* sRGB */ | 588 #endif /* sRGB */ |
| 590 | 589 |
| 591 | 590 |
| 592 #ifdef PNG_iCCP_SUPPORTED | 591 #ifdef PNG_iCCP_SUPPORTED |
| 593 void PNGAPI | 592 void PNGAPI |
| 594 png_set_iCCP(png_structp png_ptr, png_infop info_ptr, | 593 png_set_iCCP(png_structp png_ptr, png_infop info_ptr, |
| 595 png_charp name, int compression_type, | 594 png_charp name, int compression_type, |
| 596 png_charp profile, png_uint_32 proflen) | 595 png_charp profile, png_uint_32 proflen) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 "text" : (png_const_charp)png_ptr->chunk_name)); | 659 "text" : (png_const_charp)png_ptr->chunk_name)); |
| 661 | 660 |
| 662 if (png_ptr == NULL || info_ptr == NULL || num_text == 0) | 661 if (png_ptr == NULL || info_ptr == NULL || num_text == 0) |
| 663 return(0); | 662 return(0); |
| 664 | 663 |
| 665 /* Make sure we have enough space in the "text" array in info_struct | 664 /* Make sure we have enough space in the "text" array in info_struct |
| 666 * to hold all of the incoming text_ptr objects. | 665 * to hold all of the incoming text_ptr objects. |
| 667 */ | 666 */ |
| 668 if (info_ptr->num_text + num_text > info_ptr->max_text) | 667 if (info_ptr->num_text + num_text > info_ptr->max_text) |
| 669 { | 668 { |
| 669 int old_max_text = info_ptr->max_text; |
| 670 int old_num_text = info_ptr->num_text; |
| 671 |
| 670 if (info_ptr->text != NULL) | 672 if (info_ptr->text != NULL) |
| 671 { | 673 { |
| 672 png_textp old_text; | 674 png_textp old_text; |
| 673 int old_max; | |
| 674 | 675 |
| 675 old_max = info_ptr->max_text; | |
| 676 info_ptr->max_text = info_ptr->num_text + num_text + 8; | 676 info_ptr->max_text = info_ptr->num_text + num_text + 8; |
| 677 old_text = info_ptr->text; | 677 old_text = info_ptr->text; |
| 678 |
| 678 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, | 679 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, |
| 679 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); | 680 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); |
| 680 if (info_ptr->text == NULL) | 681 if (info_ptr->text == NULL) |
| 681 { | 682 { |
| 682 png_free(png_ptr, old_text); | 683 /* Restore to previous condition */ |
| 684 info_ptr->max_text = old_max_text; |
| 685 info_ptr->text = old_text; |
| 683 return(1); | 686 return(1); |
| 684 } | 687 } |
| 685 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * | 688 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max_text * |
| 686 png_sizeof(png_text))); | 689 png_sizeof(png_text))); |
| 687 png_free(png_ptr, old_text); | 690 png_free(png_ptr, old_text); |
| 688 } | 691 } |
| 689 else | 692 else |
| 690 { | 693 { |
| 691 info_ptr->max_text = num_text + 8; | 694 info_ptr->max_text = num_text + 8; |
| 692 info_ptr->num_text = 0; | 695 info_ptr->num_text = 0; |
| 693 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, | 696 info_ptr->text = (png_textp)png_malloc_warn(png_ptr, |
| 694 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); | 697 (png_uint_32)(info_ptr->max_text * png_sizeof(png_text))); |
| 695 if (info_ptr->text == NULL) | 698 if (info_ptr->text == NULL) |
| 699 { |
| 700 /* Restore to previous condition */ |
| 701 info_ptr->num_text = old_num_text; |
| 702 info_ptr->max_text = old_max_text; |
| 696 return(1); | 703 return(1); |
| 704 } |
| 697 #ifdef PNG_FREE_ME_SUPPORTED | 705 #ifdef PNG_FREE_ME_SUPPORTED |
| 698 info_ptr->free_me |= PNG_FREE_TEXT; | 706 info_ptr->free_me |= PNG_FREE_TEXT; |
| 699 #endif | 707 #endif |
| 700 } | 708 } |
| 701 png_debug1(3, "allocated %d entries for info_ptr->text", | 709 png_debug1(3, "allocated %d entries for info_ptr->text", |
| 702 info_ptr->max_text); | 710 info_ptr->max_text); |
| 703 } | 711 } |
| 712 |
| 704 for (i = 0; i < num_text; i++) | 713 for (i = 0; i < num_text; i++) |
| 705 { | 714 { |
| 706 png_size_t text_length, key_len; | 715 png_size_t text_length, key_len; |
| 707 png_size_t lang_len, lang_key_len; | 716 png_size_t lang_len, lang_key_len; |
| 708 png_textp textp = &(info_ptr->text[info_ptr->num_text]); | 717 png_textp textp = &(info_ptr->text[info_ptr->num_text]); |
| 709 | 718 |
| 710 if (text_ptr[i].key == NULL) | 719 if (text_ptr[i].key == NULL) |
| 711 continue; | 720 continue; |
| 712 | 721 |
| 713 key_len = png_strlen(text_ptr[i].key); | 722 key_len = png_strlen(text_ptr[i].key); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 #ifdef PNG_tRNS_SUPPORTED | 842 #ifdef PNG_tRNS_SUPPORTED |
| 834 void PNGAPI | 843 void PNGAPI |
| 835 png_set_tRNS(png_structp png_ptr, png_infop info_ptr, | 844 png_set_tRNS(png_structp png_ptr, png_infop info_ptr, |
| 836 png_bytep trans, int num_trans, png_color_16p trans_values) | 845 png_bytep trans, int num_trans, png_color_16p trans_values) |
| 837 { | 846 { |
| 838 png_debug1(1, "in %s storage function", "tRNS"); | 847 png_debug1(1, "in %s storage function", "tRNS"); |
| 839 | 848 |
| 840 if (png_ptr == NULL || info_ptr == NULL) | 849 if (png_ptr == NULL || info_ptr == NULL) |
| 841 return; | 850 return; |
| 842 | 851 |
| 852 if (num_trans < 0 || num_trans > PNG_MAX_PALETTE_LENGTH) |
| 853 { |
| 854 png_warning(png_ptr, "Ignoring invalid num_trans value"); |
| 855 return; |
| 856 } |
| 857 |
| 843 if (trans != NULL) | 858 if (trans != NULL) |
| 844 { | 859 { |
| 845 /* It may not actually be necessary to set png_ptr->trans here; | 860 /* It may not actually be necessary to set png_ptr->trans here; |
| 846 * we do it for backward compatibility with the way the png_handle_tRNS | 861 * we do it for backward compatibility with the way the png_handle_tRNS |
| 847 * function used to do the allocation. | 862 * function used to do the allocation. |
| 848 */ | 863 */ |
| 849 | 864 |
| 850 #ifdef PNG_FREE_ME_SUPPORTED | 865 #ifdef PNG_FREE_ME_SUPPORTED |
| 851 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); | 866 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); |
| 852 #endif | 867 #endif |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 | 1182 |
| 1168 #ifndef PNG_1_0_X | 1183 #ifndef PNG_1_0_X |
| 1169 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED | 1184 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED |
| 1170 /* Function was added to libpng 1.2.0 and should always exist by default */ | 1185 /* Function was added to libpng 1.2.0 and should always exist by default */ |
| 1171 void PNGAPI | 1186 void PNGAPI |
| 1172 png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) | 1187 png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags) |
| 1173 { | 1188 { |
| 1174 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ | 1189 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ |
| 1175 if (png_ptr != NULL) | 1190 if (png_ptr != NULL) |
| 1176 png_ptr->asm_flags = 0; | 1191 png_ptr->asm_flags = 0; |
| 1177 asm_flags = asm_flags; /* Quiet the compiler */ | 1192 PNG_UNUSED(asm_flags) /* Quiet the compiler */ |
| 1178 } | 1193 } |
| 1179 | 1194 |
| 1180 /* This function was added to libpng 1.2.0 */ | 1195 /* This function was added to libpng 1.2.0 */ |
| 1181 void PNGAPI | 1196 void PNGAPI |
| 1182 png_set_mmx_thresholds (png_structp png_ptr, | 1197 png_set_mmx_thresholds (png_structp png_ptr, |
| 1183 png_byte mmx_bitdepth_threshold, | 1198 png_byte mmx_bitdepth_threshold, |
| 1184 png_uint_32 mmx_rowbytes_threshold) | 1199 png_uint_32 mmx_rowbytes_threshold) |
| 1185 { | 1200 { |
| 1186 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ | 1201 /* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */ |
| 1187 if (png_ptr == NULL) | 1202 if (png_ptr == NULL) |
| 1188 return; | 1203 return; |
| 1189 /* Quiet the compiler */ | 1204 /* Quiet the compiler */ |
| 1190 mmx_bitdepth_threshold = mmx_bitdepth_threshold; | 1205 PNG_UNUSED(mmx_bitdepth_threshold) |
| 1191 mmx_rowbytes_threshold = mmx_rowbytes_threshold; | 1206 PNG_UNUSED(mmx_rowbytes_threshold) |
| 1192 } | 1207 } |
| 1193 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ | 1208 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ |
| 1194 | 1209 |
| 1195 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | 1210 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 1196 /* This function was added to libpng 1.2.6 */ | 1211 /* This function was added to libpng 1.2.6 */ |
| 1197 void PNGAPI | 1212 void PNGAPI |
| 1198 png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, | 1213 png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, |
| 1199 png_uint_32 user_height_max) | 1214 png_uint_32 user_height_max) |
| 1200 { | 1215 { |
| 1201 /* Images with dimensions larger than these limits will be | 1216 /* Images with dimensions larger than these limits will be |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1217 png_debug(1, "in png_set_benign_errors"); | 1232 png_debug(1, "in png_set_benign_errors"); |
| 1218 | 1233 |
| 1219 if (allowed) | 1234 if (allowed) |
| 1220 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; | 1235 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; |
| 1221 else | 1236 else |
| 1222 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; | 1237 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; |
| 1223 } | 1238 } |
| 1224 #endif /* PNG_BENIGN_ERRORS_SUPPORTED */ | 1239 #endif /* PNG_BENIGN_ERRORS_SUPPORTED */ |
| 1225 #endif /* ?PNG_1_0_X */ | 1240 #endif /* ?PNG_1_0_X */ |
| 1226 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 1241 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ |
| OLD | NEW |