Changeset 846 for trunk/src/3rdparty/libpng/pngwutil.c
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/3rdparty/libpng/pngwutil.c
r561 r846 2 2 /* pngwutil.c - utilities to write a PNG file 3 3 * 4 * Last changed in libpng 1. 2.40 [September 10, 2009]5 * Copyright (c) 1998-20 09Glenn Randers-Pehrson4 * Last changed in libpng 1.4.0 [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.) … … 12 12 */ 13 13 14 #define PNG_ INTERNAL14 #define PNG_NO_PEDANTIC_WARNINGS 15 15 #include "png.h" 16 16 #ifdef PNG_WRITE_SUPPORTED 17 #include "pngpriv.h" 17 18 18 19 /* Place a 32-bit number into a buffer in PNG byte order. We work … … 29 30 } 30 31 32 #ifdef PNG_SAVE_INT_32_SUPPORTED 31 33 /* The png_save_int_32 function assumes integers are stored in two's 32 34 * complement format. If this isn't the case, then this routine needs to … … 41 43 buf[3] = (png_byte)(i & 0xff); 42 44 } 45 #endif 43 46 44 47 /* Place a 16-bit number into a buffer in PNG byte order. … … 59 62 * bytes have already been written. 60 63 */ 61 void /* PRIVATE */64 void PNGAPI 62 65 png_write_sig(png_structp png_ptr) 63 66 { 64 67 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; 68 69 #ifdef PNG_IO_STATE_SUPPORTED 70 /* Inform the I/O callback that the signature is being written */ 71 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE; 72 #endif 65 73 66 74 /* Write the rest of the 8 byte signature */ … … 107 115 return; 108 116 117 #ifdef PNG_IO_STATE_SUPPORTED 118 /* Inform the I/O callback that the chunk header is being written. 119 * PNG_IO_CHUNK_HDR requires a single I/O call. 120 */ 121 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR; 122 #endif 123 109 124 /* Write the length and the chunk name */ 110 125 png_save_uint_32(buf, length); … … 115 130 /* Reset the crc and run it over the chunk name */ 116 131 png_reset_crc(png_ptr); 117 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); 132 png_calculate_crc(png_ptr, chunk_name, 4); 133 134 #ifdef PNG_IO_STATE_SUPPORTED 135 /* Inform the I/O callback that chunk data will (possibly) be written. 136 * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls. 137 */ 138 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA; 139 #endif 118 140 } 119 141 … … 147 169 if (png_ptr == NULL) return; 148 170 171 #ifdef PNG_IO_STATE_SUPPORTED 172 /* Inform the I/O callback that the chunk CRC is being written. 173 * PNG_IO_CHUNK_CRC requires a single I/O function call. 174 */ 175 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC; 176 #endif 177 149 178 /* Write the crc in a single operation */ 150 179 png_save_uint_32(buf, png_ptr->crc); … … 193 222 if (compression >= PNG_TEXT_COMPRESSION_LAST) 194 223 { 195 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)224 #ifdef PNG_STDIO_SUPPORTED 196 225 char msg[50]; 197 226 png_snprintf(msg, 50, "Unknown compression type %d", compression); … … 252 281 old_ptr = comp->output_ptr; 253 282 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 254 (png_ uint_32)283 (png_alloc_size_t) 255 284 (comp->max_output_ptr * png_sizeof(png_charpp))); 256 285 png_memcpy(comp->output_ptr, old_ptr, old_max … … 260 289 else 261 290 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 262 (png_ uint_32)291 (png_alloc_size_t) 263 292 (comp->max_output_ptr * png_sizeof(png_charp))); 264 293 } … … 267 296 comp->output_ptr[comp->num_output_ptr] = 268 297 (png_charp)png_malloc(png_ptr, 269 (png_ uint_32)png_ptr->zbuf_size);298 (png_alloc_size_t)png_ptr->zbuf_size); 270 299 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 271 300 png_ptr->zbuf_size); … … 304 333 /* This could be optimized to realloc() */ 305 334 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 306 (png_ uint_32)(comp->max_output_ptr *335 (png_alloc_size_t)(comp->max_output_ptr * 307 336 png_sizeof(png_charp))); 308 337 png_memcpy(comp->output_ptr, old_ptr, … … 312 341 else 313 342 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 314 (png_ uint_32)(comp->max_output_ptr *343 (png_alloc_size_t)(comp->max_output_ptr * 315 344 png_sizeof(png_charp))); 316 345 } … … 319 348 comp->output_ptr[comp->num_output_ptr] = 320 349 (png_charp)png_malloc(png_ptr, 321 (png_ uint_32)png_ptr->zbuf_size);350 (png_alloc_size_t)png_ptr->zbuf_size); 322 351 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 323 352 png_ptr->zbuf_size); … … 367 396 (png_size_t)png_ptr->zbuf_size); 368 397 png_free(png_ptr, comp->output_ptr[i]); 369 comp->output_ptr[i]=NULL;370 398 } 371 399 if (comp->max_output_ptr != 0) 372 400 png_free(png_ptr, comp->output_ptr); 373 comp->output_ptr=NULL;374 401 /* Write anything left in zbuf */ 375 402 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) … … 392 419 int interlace_type) 393 420 { 394 #ifdef PNG_USE_LOCAL_ARRAYS395 421 PNG_IHDR; 396 #endif397 422 int ret; 398 423 … … 460 485 */ 461 486 if ( 462 #if defined(PNG_MNG_FEATURES_SUPPORTED)487 #ifdef PNG_MNG_FEATURES_SUPPORTED 463 488 !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 464 489 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && … … 488 513 png_ptr->color_type = (png_byte)color_type; 489 514 png_ptr->interlaced = (png_byte)interlace_type; 490 #if defined(PNG_MNG_FEATURES_SUPPORTED)515 #ifdef PNG_MNG_FEATURES_SUPPORTED 491 516 png_ptr->filter_type = (png_byte)filter_type; 492 517 #endif … … 570 595 png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) 571 596 { 572 #ifdef PNG_USE_LOCAL_ARRAYS573 597 PNG_PLTE; 574 #endif575 598 png_uint_32 i; 576 599 png_colorp pal_ptr; … … 580 603 581 604 if (( 582 #if defined(PNG_MNG_FEATURES_SUPPORTED)605 #ifdef PNG_MNG_FEATURES_SUPPORTED 583 606 !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && 584 607 #endif … … 608 631 png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, 609 632 (png_uint_32)(num_pal * 3)); 610 #if ndef PNG_NO_POINTER_INDEXING633 #ifdef PNG_POINTER_INDEXING_SUPPORTED 611 634 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) 612 635 { … … 635 658 png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) 636 659 { 637 #ifdef PNG_USE_LOCAL_ARRAYS638 660 PNG_IDAT; 639 #endif640 661 641 662 png_debug(1, "in png_write_IDAT"); … … 690 711 png_write_IEND(png_structp png_ptr) 691 712 { 692 #ifdef PNG_USE_LOCAL_ARRAYS693 713 PNG_IEND; 694 #endif695 714 696 715 png_debug(1, "in png_write_IEND"); 697 716 698 png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,717 png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL, 699 718 (png_size_t)0); 700 719 png_ptr->mode |= PNG_HAVE_IEND; 701 720 } 702 721 703 #if defined(PNG_WRITE_gAMA_SUPPORTED)722 #ifdef PNG_WRITE_gAMA_SUPPORTED 704 723 /* Write a gAMA chunk */ 705 724 #ifdef PNG_FLOATING_POINT_SUPPORTED … … 707 726 png_write_gAMA(png_structp png_ptr, double file_gamma) 708 727 { 709 #ifdef PNG_USE_LOCAL_ARRAYS710 728 PNG_gAMA; 711 #endif712 729 png_uint_32 igamma; 713 730 png_byte buf[4]; … … 725 742 png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) 726 743 { 727 #ifdef PNG_USE_LOCAL_ARRAYS728 744 PNG_gAMA; 729 #endif730 745 png_byte buf[4]; 731 746 … … 739 754 #endif 740 755 741 #if defined(PNG_WRITE_sRGB_SUPPORTED)756 #ifdef PNG_WRITE_sRGB_SUPPORTED 742 757 /* Write a sRGB chunk */ 743 758 void /* PRIVATE */ 744 759 png_write_sRGB(png_structp png_ptr, int srgb_intent) 745 760 { 746 #ifdef PNG_USE_LOCAL_ARRAYS747 761 PNG_sRGB; 748 #endif749 762 png_byte buf[1]; 750 763 … … 759 772 #endif 760 773 761 #if defined(PNG_WRITE_iCCP_SUPPORTED)774 #ifdef PNG_WRITE_iCCP_SUPPORTED 762 775 /* Write an iCCP chunk */ 763 776 void /* PRIVATE */ … … 765 778 png_charp profile, int profile_len) 766 779 { 767 #ifdef PNG_USE_LOCAL_ARRAYS768 780 PNG_iCCP; 769 #endif770 781 png_size_t name_len; 771 782 png_charp new_name; … … 840 851 #endif 841 852 842 #if defined(PNG_WRITE_sPLT_SUPPORTED)853 #ifdef PNG_WRITE_sPLT_SUPPORTED 843 854 /* Write a sPLT chunk */ 844 855 void /* PRIVATE */ 845 856 png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) 846 857 { 847 #ifdef PNG_USE_LOCAL_ARRAYS848 858 PNG_sPLT; 849 #endif850 859 png_size_t name_len; 851 860 png_charp new_name; 852 861 png_byte entrybuf[10]; 853 int entry_size = (spalette->depth == 8 ? 6 : 10);854 int palette_size = entry_size * spalette->nentries;862 png_size_t entry_size = (spalette->depth == 8 ? 6 : 10); 863 png_size_t palette_size = entry_size * spalette->nentries; 855 864 png_sPLT_entryp ep; 856 #if def PNG_NO_POINTER_INDEXING865 #ifndef PNG_POINTER_INDEXING_SUPPORTED 857 866 int i; 858 867 #endif … … 871 880 872 881 /* Loop through each palette entry, writing appropriately */ 873 #if ndef PNG_NO_POINTER_INDEXING882 #ifdef PNG_POINTER_INDEXING_SUPPORTED 874 883 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++) 875 884 { … … 921 930 #endif 922 931 923 #if defined(PNG_WRITE_sBIT_SUPPORTED)932 #ifdef PNG_WRITE_sBIT_SUPPORTED 924 933 /* Write the sBIT chunk */ 925 934 void /* PRIVATE */ 926 935 png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) 927 936 { 928 #ifdef PNG_USE_LOCAL_ARRAYS929 937 PNG_sBIT; 930 #endif931 938 png_byte buf[4]; 932 939 png_size_t size; … … 978 985 #endif 979 986 980 #if defined(PNG_WRITE_cHRM_SUPPORTED)987 #ifdef PNG_WRITE_cHRM_SUPPORTED 981 988 /* Write the cHRM chunk */ 982 989 #ifdef PNG_FLOATING_POINT_SUPPORTED … … 986 993 double blue_x, double blue_y) 987 994 { 988 #ifdef PNG_USE_LOCAL_ARRAYS989 995 PNG_cHRM; 990 #endif991 996 png_byte buf[32]; 992 997 … … 1005 1010 int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5); 1006 1011 1007 #if !defined(PNG_NO_CHECK_cHRM)1012 #ifdef PNG_CHECK_cHRM_SUPPORTED 1008 1013 if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, 1009 1014 int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) … … 1035 1040 png_fixed_point blue_y) 1036 1041 { 1037 #ifdef PNG_USE_LOCAL_ARRAYS1038 1042 PNG_cHRM; 1039 #endif1040 1043 png_byte buf[32]; 1041 1044 … … 1043 1046 1044 1047 /* Each value is saved in 1/100,000ths */ 1045 #if !defined(PNG_NO_CHECK_cHRM)1048 #ifdef PNG_CHECK_cHRM_SUPPORTED 1046 1049 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, 1047 1050 green_x, green_y, blue_x, blue_y)) … … 1066 1069 #endif 1067 1070 1068 #if defined(PNG_WRITE_tRNS_SUPPORTED)1071 #ifdef PNG_WRITE_tRNS_SUPPORTED 1069 1072 /* Write the tRNS chunk */ 1070 1073 void /* PRIVATE */ 1071 png_write_tRNS(png_structp png_ptr, png_bytep trans , png_color_16p tran,1074 png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran, 1072 1075 int num_trans, int color_type) 1073 1076 { 1074 #ifdef PNG_USE_LOCAL_ARRAYS1075 1077 PNG_tRNS; 1076 #endif1077 1078 png_byte buf[6]; 1078 1079 … … 1087 1088 } 1088 1089 /* Write the chunk out as it is */ 1089 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans ,1090 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans_alpha, 1090 1091 (png_size_t)num_trans); 1091 1092 } … … 1123 1124 #endif 1124 1125 1125 #if defined(PNG_WRITE_bKGD_SUPPORTED)1126 #ifdef PNG_WRITE_bKGD_SUPPORTED 1126 1127 /* Write the background chunk */ 1127 1128 void /* PRIVATE */ 1128 1129 png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) 1129 1130 { 1130 #ifdef PNG_USE_LOCAL_ARRAYS1131 1131 PNG_bKGD; 1132 #endif1133 1132 png_byte buf[6]; 1134 1133 … … 1138 1137 { 1139 1138 if ( 1140 #if defined(PNG_MNG_FEATURES_SUPPORTED)1139 #ifdef PNG_MNG_FEATURES_SUPPORTED 1141 1140 (png_ptr->num_palette || 1142 1141 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && … … 1177 1176 #endif 1178 1177 1179 #if defined(PNG_WRITE_hIST_SUPPORTED)1178 #ifdef PNG_WRITE_hIST_SUPPORTED 1180 1179 /* Write the histogram */ 1181 1180 void /* PRIVATE */ 1182 1181 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) 1183 1182 { 1184 #ifdef PNG_USE_LOCAL_ARRAYS1185 1183 PNG_hIST; 1186 #endif1187 1184 int i; 1188 1185 png_byte buf[3]; … … 1254 1251 ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1)) 1255 1252 { 1256 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)1253 #ifdef PNG_STDIO_SUPPORTED 1257 1254 char msg[40]; 1258 1255 … … 1326 1323 { 1327 1324 png_free(png_ptr, *new_key); 1328 *new_key=NULL;1329 1325 png_warning(png_ptr, "Zero length keyword"); 1330 1326 } … … 1341 1337 #endif 1342 1338 1343 #if defined(PNG_WRITE_tEXt_SUPPORTED)1339 #ifdef PNG_WRITE_tEXt_SUPPORTED 1344 1340 /* Write a tEXt chunk */ 1345 1341 void /* PRIVATE */ … … 1347 1343 png_size_t text_len) 1348 1344 { 1349 #ifdef PNG_USE_LOCAL_ARRAYS1350 1345 PNG_tEXt; 1351 #endif1352 1346 png_size_t key_len; 1353 1347 png_charp new_key; … … 1382 1376 #endif 1383 1377 1384 #if defined(PNG_WRITE_zTXt_SUPPORTED)1378 #ifdef PNG_WRITE_zTXt_SUPPORTED 1385 1379 /* Write a compressed text chunk */ 1386 1380 void /* PRIVATE */ … … 1388 1382 png_size_t text_len, int compression) 1389 1383 { 1390 #ifdef PNG_USE_LOCAL_ARRAYS1391 1384 PNG_zTXt; 1392 #endif1393 1385 png_size_t key_len; 1394 1386 char buf[1]; … … 1442 1434 #endif 1443 1435 1444 #if defined(PNG_WRITE_iTXt_SUPPORTED)1436 #ifdef PNG_WRITE_iTXt_SUPPORTED 1445 1437 /* Write an iTXt chunk */ 1446 1438 void /* PRIVATE */ … … 1448 1440 png_charp lang, png_charp lang_key, png_charp text) 1449 1441 { 1450 #ifdef PNG_USE_LOCAL_ARRAYS1451 1442 PNG_iTXt; 1452 #endif1453 1443 png_size_t lang_len, key_len, lang_key_len, text_len; 1454 1444 png_charp new_lang; … … 1531 1521 #endif 1532 1522 1533 #if defined(PNG_WRITE_oFFs_SUPPORTED)1523 #ifdef PNG_WRITE_oFFs_SUPPORTED 1534 1524 /* Write the oFFs chunk */ 1535 1525 void /* PRIVATE */ … … 1537 1527 int unit_type) 1538 1528 { 1539 #ifdef PNG_USE_LOCAL_ARRAYS1540 1529 PNG_oFFs; 1541 #endif1542 1530 png_byte buf[9]; 1543 1531 … … 1554 1542 } 1555 1543 #endif 1556 #if defined(PNG_WRITE_pCAL_SUPPORTED)1544 #ifdef PNG_WRITE_pCAL_SUPPORTED 1557 1545 /* Write the pCAL chunk (described in the PNG extensions document) */ 1558 1546 void /* PRIVATE */ … … 1560 1548 png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) 1561 1549 { 1562 #ifdef PNG_USE_LOCAL_ARRAYS1563 1550 PNG_pCAL; 1564 #endif1565 1551 png_size_t purpose_len, units_len, total_len; 1566 1552 png_uint_32p params_len; … … 1581 1567 1582 1568 params_len = (png_uint_32p)png_malloc(png_ptr, 1583 (png_ uint_32)(nparams * png_sizeof(png_uint_32)));1569 (png_alloc_size_t)(nparams * png_sizeof(png_uint_32))); 1584 1570 1585 1571 /* Find the length of each parameter, making sure we don't count the … … 1617 1603 #endif 1618 1604 1619 #if defined(PNG_WRITE_sCAL_SUPPORTED)1605 #ifdef PNG_WRITE_sCAL_SUPPORTED 1620 1606 /* Write the sCAL chunk */ 1621 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)1607 #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) 1622 1608 void /* PRIVATE */ 1623 1609 png_write_sCAL(png_structp png_ptr, int unit, double width, double height) 1624 1610 { 1625 #ifdef PNG_USE_LOCAL_ARRAYS1626 1611 PNG_sCAL; 1627 #endif1628 1612 char buf[64]; 1629 1613 png_size_t total_len; … … 1632 1616 1633 1617 buf[0] = (char)unit; 1634 #if defined(_WIN32_WCE)1635 /* sprintf() function is not supported on WindowsCE */1636 {1637 wchar_t wc_buf[32];1638 size_t wc_len;1639 swprintf(wc_buf, TEXT("%12.12e"), width);1640 wc_len = wcslen(wc_buf);1641 WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);1642 total_len = wc_len + 2;1643 swprintf(wc_buf, TEXT("%12.12e"), height);1644 wc_len = wcslen(wc_buf);1645 WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,1646 NULL, NULL);1647 total_len += wc_len;1648 }1649 #else1650 1618 png_snprintf(buf + 1, 63, "%12.12e", width); 1651 1619 total_len = 1 + png_strlen(buf + 1) + 1; 1652 1620 png_snprintf(buf + total_len, 64-total_len, "%12.12e", height); 1653 1621 total_len += png_strlen(buf + total_len); 1654 #endif1655 1622 1656 1623 png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); … … 1663 1630 png_charp height) 1664 1631 { 1665 #ifdef PNG_USE_LOCAL_ARRAYS1666 1632 PNG_sCAL; 1667 #endif1668 1633 png_byte buf[64]; 1669 1634 png_size_t wlen, hlen, total_len; … … 1691 1656 #endif 1692 1657 1693 #if defined(PNG_WRITE_pHYs_SUPPORTED)1658 #ifdef PNG_WRITE_pHYs_SUPPORTED 1694 1659 /* Write the pHYs chunk */ 1695 1660 void /* PRIVATE */ … … 1698 1663 int unit_type) 1699 1664 { 1700 #ifdef PNG_USE_LOCAL_ARRAYS1701 1665 PNG_pHYs; 1702 #endif1703 1666 png_byte buf[9]; 1704 1667 … … 1716 1679 #endif 1717 1680 1718 #if defined(PNG_WRITE_tIME_SUPPORTED)1681 #ifdef PNG_WRITE_tIME_SUPPORTED 1719 1682 /* Write the tIME chunk. Use either png_convert_from_struct_tm() 1720 1683 * or png_convert_from_time_t(), or fill in the structure yourself. … … 1723 1686 png_write_tIME(png_structp png_ptr, png_timep mod_time) 1724 1687 { 1725 #ifdef PNG_USE_LOCAL_ARRAYS1726 1688 PNG_tIME; 1727 #endif1728 1689 png_byte buf[7]; 1729 1690 … … 1754 1715 { 1755 1716 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1756 #ifdef PNG_USE_LOCAL_ARRAYS1757 1717 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1758 1718 … … 1769 1729 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1770 1730 #endif 1771 #endif1772 1731 1773 1732 png_size_t buf_size; … … 1780 1739 /* Set up row buffer */ 1781 1740 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, 1782 (png_ uint_32)buf_size);1741 (png_alloc_size_t)buf_size); 1783 1742 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; 1784 1743 1785 #if ndef PNG_NO_WRITE_FILTER1744 #ifdef PNG_WRITE_FILTER_SUPPORTED 1786 1745 /* Set up filtering buffer, if using this filter */ 1787 1746 if (png_ptr->do_filter & PNG_FILTER_SUB) 1788 1747 { 1789 1748 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, 1790 (png_ uint_32)(png_ptr->rowbytes + 1));1749 (png_alloc_size_t)(png_ptr->rowbytes + 1)); 1791 1750 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; 1792 1751 } … … 1795 1754 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) 1796 1755 { 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); 1756 /* Set up previous row buffer */ 1757 png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, 1758 (png_alloc_size_t)buf_size); 1801 1759 1802 1760 if (png_ptr->do_filter & PNG_FILTER_UP) 1803 1761 { 1804 1762 png_ptr->up_row = (png_bytep)png_malloc(png_ptr, 1805 (png_uint_32)(png_ptr->rowbytes + 1));1763 (png_size_t)(png_ptr->rowbytes + 1)); 1806 1764 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; 1807 1765 } … … 1810 1768 { 1811 1769 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, 1812 (png_uint_32)(png_ptr->rowbytes + 1));1770 (png_alloc_size_t)(png_ptr->rowbytes + 1)); 1813 1771 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; 1814 1772 } … … 1817 1775 { 1818 1776 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 1819 (png_uint_32)(png_ptr->rowbytes + 1));1777 (png_size_t)(png_ptr->rowbytes + 1)); 1820 1778 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 1821 1779 } 1822 1780 } 1823 #endif /* PNG_ NO_WRITE_FILTER*/1781 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 1824 1782 1825 1783 #ifdef PNG_WRITE_INTERLACING_SUPPORTED … … 1855 1813 { 1856 1814 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1857 #ifdef PNG_USE_LOCAL_ARRAYS1858 1815 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1859 1816 … … 1869 1826 /* Offset to next interlace block in the y direction */ 1870 1827 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1871 #endif1872 1828 #endif 1873 1829 … … 1963 1919 } 1964 1920 1965 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)1921 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1966 1922 /* Pick out the correct pixels for the interlace pass. 1967 1923 * The basic idea here is to go through the row with a source … … 1974 1930 png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) 1975 1931 { 1976 #ifdef PNG_USE_LOCAL_ARRAYS1977 1932 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1978 1933 … … 1982 1937 /* Offset to next interlace block */ 1983 1938 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1984 #endif1985 1939 1986 1940 png_debug(1, "in png_do_write_interlace"); 1987 1941 1988 1942 /* We don't have to do anything on the last pass (6) */ 1989 #if defined(PNG_USELESS_TESTS_SUPPORTED)1990 if (row != NULL && row_info != NULL && pass < 6)1991 #else1992 1943 if (pass < 6) 1993 #endif1994 1944 { 1995 1945 /* Each pixel depth is handled separately */ … … 2147 2097 { 2148 2098 png_bytep best_row; 2149 #if ndef PNG_NO_WRITE_FILTER2099 #ifdef PNG_WRITE_FILTER_SUPPORTED 2150 2100 png_bytep prev_row, row_buf; 2151 2101 png_uint_32 mins, bpp; … … 2158 2108 png_debug(1, "in png_write_find_filter"); 2159 2109 2110 #ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2111 if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) 2112 { 2113 /* These will never be selected so we need not test them. */ 2114 filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); 2115 } 2116 #endif 2117 2160 2118 /* Find out how many bytes offset each pixel is */ 2161 2119 bpp = (row_info->pixel_depth + 7) >> 3; … … 2164 2122 #endif 2165 2123 best_row = png_ptr->row_buf; 2166 #if ndef PNG_NO_WRITE_FILTER2124 #ifdef PNG_WRITE_FILTER_SUPPORTED 2167 2125 row_buf = best_row; 2168 2126 mins = PNG_MAXSUM; … … 2207 2165 } 2208 2166 2209 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2167 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2210 2168 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2211 2169 { … … 2271 2229 int v; 2272 2230 2273 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2231 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2274 2232 /* We temporarily increase the "minimum sum" by the factor we 2275 2233 * would reduce the sum of this filter, so that we can do the … … 2324 2282 } 2325 2283 2326 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2284 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2327 2285 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2328 2286 { … … 2385 2343 2386 2344 2387 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2345 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2388 2346 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2389 2347 { … … 2427 2385 } 2428 2386 2429 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2387 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2430 2388 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2431 2389 { … … 2490 2448 int v; 2491 2449 2492 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2450 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2493 2451 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2494 2452 { … … 2539 2497 } 2540 2498 2541 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2499 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2542 2500 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2543 2501 { … … 2623 2581 int v; 2624 2582 2625 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2583 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2626 2584 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2627 2585 { … … 2704 2662 } 2705 2663 2706 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2664 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2707 2665 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) 2708 2666 { … … 2740 2698 } 2741 2699 } 2742 #endif /* PNG_ NO_WRITE_FILTER*/2700 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 2743 2701 /* Do the actual writing of the filtered row data from the chosen filter. */ 2744 2702 2745 2703 png_write_filtered_row(png_ptr, best_row); 2746 2704 2747 #if ndef PNG_NO_WRITE_FILTER2748 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)2705 #ifdef PNG_WRITE_FILTER_SUPPORTED 2706 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED 2749 2707 /* Save the type of filter we picked this time for future calculations */ 2750 2708 if (png_ptr->num_prev_filters > 0) … … 2758 2716 } 2759 2717 #endif 2760 #endif /* PNG_ NO_WRITE_FILTER*/2718 #endif /* PNG_WRITE_FILTER_SUPPORTED */ 2761 2719 } 2762 2720 … … 2813 2771 png_write_finish_row(png_ptr); 2814 2772 2815 #if defined(PNG_WRITE_FLUSH_SUPPORTED)2773 #ifdef PNG_WRITE_FLUSH_SUPPORTED 2816 2774 png_ptr->flush_rows++; 2817 2775
Note:
See TracChangeset
for help on using the changeset viewer.