Changeset 43 for vendor/libpng/pngwutil.c
- Timestamp:
- 02/15/10 11:37:15 (2 years ago)
- Files:
-
- 1 modified
-
vendor/libpng/pngwutil.c (modified) (59 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/libpng/pngwutil.c
r11 r43 2 2 /* pngwutil.c - utilities to write a PNG file 3 3 * 4 * Last changed in libpng 1.2.4 0 [September 10, 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) … … 13 13 14 14 #define PNG_INTERNAL 15 #define PNG_NO_PEDANTIC_WARNINGS 15 16 #include "png.h" 16 17 #ifdef PNG_WRITE_SUPPORTED … … 59 60 * bytes have already been written. 60 61 */ 61 void /* PRIVATE */62 void PNGAPI 62 63 png_write_sig(png_structp png_ptr) 63 64 { … … 107 108 return; 108 109 110 109 111 /* Write the length and the chunk name */ 110 112 png_save_uint_32(buf, length); … … 193 195 if (compression >= PNG_TEXT_COMPRESSION_LAST) 194 196 { 195 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)197 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 196 198 char msg[50]; 197 199 png_snprintf(msg, 50, "Unknown compression type %d", compression); … … 460 462 */ 461 463 if ( 462 #if defined(PNG_MNG_FEATURES_SUPPORTED)464 #ifdef PNG_MNG_FEATURES_SUPPORTED 463 465 !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 464 466 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && … … 488 490 png_ptr->color_type = (png_byte)color_type; 489 491 png_ptr->interlaced = (png_byte)interlace_type; 490 #if defined(PNG_MNG_FEATURES_SUPPORTED)492 #ifdef PNG_MNG_FEATURES_SUPPORTED 491 493 png_ptr->filter_type = (png_byte)filter_type; 492 494 #endif … … 580 582 581 583 if (( 582 #if defined(PNG_MNG_FEATURES_SUPPORTED)584 #ifdef PNG_MNG_FEATURES_SUPPORTED 583 585 !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && 584 586 #endif … … 608 610 png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, 609 611 (png_uint_32)(num_pal * 3)); 610 #if ndef PNG_NO_POINTER_INDEXING612 #ifdef PNG_POINTER_INDEXING_SUPPORTED 611 613 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) 612 614 { … … 701 703 } 702 704 703 #if defined(PNG_WRITE_gAMA_SUPPORTED)705 #ifdef PNG_WRITE_gAMA_SUPPORTED 704 706 /* Write a gAMA chunk */ 705 707 #ifdef PNG_FLOATING_POINT_SUPPORTED … … 739 741 #endif 740 742 741 #if defined(PNG_WRITE_sRGB_SUPPORTED)743 #ifdef PNG_WRITE_sRGB_SUPPORTED 742 744 /* Write a sRGB chunk */ 743 745 void /* PRIVATE */ … … 759 761 #endif 760 762 761 #if defined(PNG_WRITE_iCCP_SUPPORTED)763 #ifdef PNG_WRITE_iCCP_SUPPORTED 762 764 /* Write an iCCP chunk */ 763 765 void /* PRIVATE */ … … 840 842 #endif 841 843 842 #if defined(PNG_WRITE_sPLT_SUPPORTED)844 #ifdef PNG_WRITE_sPLT_SUPPORTED 843 845 /* Write a sPLT chunk */ 844 846 void /* PRIVATE */ … … 854 856 int palette_size = entry_size * spalette->nentries; 855 857 png_sPLT_entryp ep; 856 #if def PNG_NO_POINTER_INDEXING858 #ifndef PNG_POINTER_INDEXING_SUPPORTED 857 859 int i; 858 860 #endif … … 871 873 872 874 /* Loop through each palette entry, writing appropriately */ 873 #if ndef PNG_NO_POINTER_INDEXING875 #ifdef PNG_POINTER_INDEXING_SUPPORTED 874 876 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++) 875 877 { … … 921 923 #endif 922 924 923 #if defined(PNG_WRITE_sBIT_SUPPORTED)925 #ifdef PNG_WRITE_sBIT_SUPPORTED 924 926 /* Write the sBIT chunk */ 925 927 void /* PRIVATE */ … … 978 980 #endif 979 981 980 #if defined(PNG_WRITE_cHRM_SUPPORTED)982 #ifdef PNG_WRITE_cHRM_SUPPORTED 981 983 /* Write the cHRM chunk */ 982 984 #ifdef PNG_FLOATING_POINT_SUPPORTED … … 1005 1007 int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5); 1006 1008 1007 #if !defined(PNG_NO_CHECK_cHRM)1009 #ifdef PNG_CHECK_cHRM_SUPPORTED 1008 1010 if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, 1009 1011 int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) … … 1043 1045 1044 1046 /* Each value is saved in 1/100,000ths */ 1045 #if !defined(PNG_NO_CHECK_cHRM)1047 #ifdef PNG_CHECK_cHRM_SUPPORTED 1046 1048 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, 1047 1049 green_x, green_y, blue_x, blue_y)) … … 1066 1068 #endif 1067 1069 1068 #if defined(PNG_WRITE_tRNS_SUPPORTED)1070 #ifdef PNG_WRITE_tRNS_SUPPORTED 1069 1071 /* Write the tRNS chunk */ 1070 1072 void /* PRIVATE */ … … 1123 1125 #endif 1124 1126 1125 #if defined(PNG_WRITE_bKGD_SUPPORTED)1127 #ifdef PNG_WRITE_bKGD_SUPPORTED 1126 1128 /* Write the background chunk */ 1127 1129 void /* PRIVATE */ … … 1138 1140 { 1139 1141 if ( 1140 #if defined(PNG_MNG_FEATURES_SUPPORTED)1142 #ifdef PNG_MNG_FEATURES_SUPPORTED 1141 1143 (png_ptr->num_palette || 1142 1144 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && … … 1177 1179 #endif 1178 1180 1179 #if defined(PNG_WRITE_hIST_SUPPORTED)1181 #ifdef PNG_WRITE_hIST_SUPPORTED 1180 1182 /* Write the histogram */ 1181 1183 void /* PRIVATE */ … … 1254 1256 ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1)) 1255 1257 { 1256 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)1258 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 1257 1259 char msg[40]; 1258 1260 … … 1341 1343 #endif 1342 1344 1343 #if defined(PNG_WRITE_tEXt_SUPPORTED)1345 #ifdef PNG_WRITE_tEXt_SUPPORTED 1344 1346 /* Write a tEXt chunk */ 1345 1347 void /* PRIVATE */ … … 1382 1384 #endif 1383 1385 1384 #if defined(PNG_WRITE_zTXt_SUPPORTED)1386 #ifdef PNG_WRITE_zTXt_SUPPORTED 1385 1387 /* Write a compressed text chunk */ 1386 1388 void /* PRIVATE */ … … 1442 1444 #endif 1443 1445 1444 #if defined(PNG_WRITE_iTXt_SUPPORTED)1446 #ifdef PNG_WRITE_iTXt_SUPPORTED 1445 1447 /* Write an iTXt chunk */ 1446 1448 void /* PRIVATE */ … … 1531 1533 #endif 1532 1534 1533 #if defined(PNG_WRITE_oFFs_SUPPORTED)1535 #ifdef PNG_WRITE_oFFs_SUPPORTED 1534 1536 /* Write the oFFs chunk */ 1535 1537 void /* PRIVATE */ … … 1554 1556 } 1555 1557 #endif 1556 #if defined(PNG_WRITE_pCAL_SUPPORTED)1558 #ifdef PNG_WRITE_pCAL_SUPPORTED 1557 1559 /* Write the pCAL chunk (described in the PNG extensions document) */ 1558 1560 void /* PRIVATE */ … … 1617 1619 #endif 1618 1620 1619 #if defined(PNG_WRITE_sCAL_SUPPORTED)1621 #ifdef PNG_WRITE_sCAL_SUPPORTED 1620 1622 /* Write the sCAL chunk */ 1621 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)1623 #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) 1622 1624 void /* PRIVATE */ 1623 1625 png_write_sCAL(png_structp png_ptr, int unit, double width, double height) … … 1632 1634 1633 1635 buf[0] = (char)unit; 1634 #if defined(_WIN32_WCE)1636 #ifdef _WIN32_WCE 1635 1637 /* sprintf() function is not supported on WindowsCE */ 1636 1638 { … … 1691 1693 #endif 1692 1694 1693 #if defined(PNG_WRITE_pHYs_SUPPORTED)1695 #ifdef PNG_WRITE_pHYs_SUPPORTED 1694 1696 /* Write the pHYs chunk */ 1695 1697 void /* PRIVATE */ … … 1716 1718 #endif 1717 1719 1718 #if defined(PNG_WRITE_tIME_SUPPORTED)1720 #ifdef PNG_WRITE_tIME_SUPPORTED 1719 1721 /* Write the tIME chunk. Use either png_convert_from_struct_tm() 1720 1722 * or png_convert_from_time_t(), or fill in the structure yourself. … … 1754 1756 { 1755 1757 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1756 #ifdef PNG_USE_LOCAL_ARRAYS1757 1758 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1758 1759 … … 1768 1769 /* Offset to next interlace block in the y direction */ 1769 1770 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1770 #endif1771 1771 #endif 1772 1772 … … 1783 1783 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; 1784 1784 1785 #if ndef PNG_NO_WRITE_FILTER1785 #ifdef PNG_WRITE_FILTER_SUPPORTED 1786 1786 /* Set up filtering buffer, if using this filter */ 1787 1787 if (png_ptr->do_filter & PNG_FILTER_SUB) … … 1795 1795 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) 1796 1796 { 1797 /* Set up previous row buffer */ 1798 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, 1799 (png_uint_32)buf_size); 1800 png_memset(png_ptr->prev_row, 0, buf_size); 1797 /* Set up previous row buffer */ 1798 png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, 1799 (png_uint_32)buf_size); 1801 1800 1802 1801 if (png_ptr->do_filter & PNG_FILTER_UP) 1803 1802 { 1804 1803 png_ptr->up_row = (png_bytep)png_malloc(png_ptr, 1805 (png_uint_32)(png_ptr->rowbytes + 1));1804 (png_uint_32)(png_ptr->rowbytes + 1)); 1806 1805 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; 1807 1806 } … … 1810 1809 { 1811 1810 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, 1812 (png_uint_32)(png_ptr->rowbytes + 1));1811 (png_uint_32)(png_ptr->rowbytes + 1)); 1813 1812 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; 1814 1813 } … … 1817 1816 { 1818 1817 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 1819 (png_uint_32)(png_ptr->rowbytes + 1));1818 (png_uint_32)(png_ptr->rowbytes + 1)); 1820 1819 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 1821 1820 } 1822 1821 } 1823 #endif /* PNG_ NO_WRITE_FILTER*/1822 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1824 1823 1825 1824 #ifdef PNG_WRITE_INTERLACING_SUPPORTED … … 1855 1854 { 1856 1855 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1857 #ifdef PNG_USE_LOCAL_ARRAYS1858 1856 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1859 1857 … … 1869 1867 /* Offset to next interlace block in the y direction */ 1870 1868 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1871 #endif1872 1869 #endif 1873 1870 … … 1963 1960 } 1964 1961 1965 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)1962 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1966 1963 /* Pick out the correct pixels for the interlace pass. 1967 1964 * The basic idea here is to go through the row with a source … … 1974 1971 png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) 1975 1972 { 1976 #ifdef PNG_USE_LOCAL_ARRAYS1977 1973 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1978 1974 … … 1982 1978 /* Offset to next interlace block */ 1983 1979 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1984 #endif1985 1980 1986 1981 png_debug(1, "in png_do_write_interlace"); 1987 1982 1988 1983 /* We don't have to do anything on the last pass (6) */ 1989 #if defined(PNG_USELESS_TESTS_SUPPORTED)1984 #ifdef PNG_USELESS_TESTS_SUPPORTED 1990 1985 if (row != NULL && row_info != NULL && pass < 6) 1991 1986 #else … … 2147 2142 { 2148 2143 png_bytep best_row; 2149 #if ndef PNG_NO_WRITE_FILTER2144 #ifdef PNG_WRITE_FILTER_SUPPORTED 2150 2145 png_bytep prev_row, row_buf; 2151 2146 png_uint_32 mins, bpp; … … 2158 2153 png_debug(1, "in png_write_find_filter"); 2159 2154 2155 #ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2156 if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) 2157 { 2158 /* These will never be selected so we need not test them. */ 2159 filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); 2160 } 2161 #endif 2162 2160 2163 /* Find out how many bytes offset each pixel is */ 2161 2164 bpp = (row_info->pixel_depth + 7) >> 3; … … 2164 2167 #endif 2165 2168 best_row = png_ptr->row_buf; 2166 #if ndef PNG_NO_WRITE_FILTER2169 #ifdef PNG_WRITE_FILTER_SUPPORTED 2167 2170 row_buf = best_row; 2168 2171 mins = PNG_MAXSUM; … … 2207 2210 } 2208 2211 2209 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2212 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2210 2213 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2211 2214 { … … 2271 2274 int v; 2272 2275 2273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2276 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2274 2277 /* We temporarily increase the "minimum sum" by the factor we 2275 2278 * would reduce the sum of this filter, so that we can do the … … 2324 2327 } 2325 2328 2326 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2329 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2327 2330 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2328 2331 { … … 2385 2388 2386 2389 2387 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2390 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2388 2391 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2389 2392 { … … 2427 2430 } 2428 2431 2429 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2432 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2430 2433 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2431 2434 { … … 2490 2493 int v; 2491 2494 2492 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2495 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2493 2496 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2494 2497 { … … 2539 2542 } 2540 2543 2541 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2544 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2542 2545 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2543 2546 { … … 2623 2626 int v; 2624 2627 2625 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2628 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2626 2629 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2627 2630 { … … 2704 2707 } 2705 2708 2706 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2709 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2707 2710 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2708 2711 { … … 2740 2743 } 2741 2744 } 2742 #endif /* PNG_ NO_WRITE_FILTER*/2745 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 2743 2746 /* Do the actual writing of the filtered row data from the chosen filter. */ 2744 2747 2745 2748 png_write_filtered_row(png_ptr, best_row); 2746 2749 2747 #if ndef PNG_NO_WRITE_FILTER2748 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2750 #ifdef PNG_WRITE_FILTER_SUPPORTED 2751 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2749 2752 /* Save the type of filter we picked this time for future calculations */ 2750 2753 if (png_ptr->num_prev_filters > 0) … … 2758 2761 } 2759 2762 #endif 2760 #endif /* PNG_ NO_WRITE_FILTER*/2763 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 2761 2764 } 2762 2765 … … 2813 2816 png_write_finish_row(png_ptr); 2814 2817 2815 #if defined(PNG_WRITE_FLUSH_SUPPORTED)2818 #ifdef PNG_WRITE_FLUSH_SUPPORTED 2816 2819 png_ptr->flush_rows++; 2817 2820
