Changeset 43 for vendor/libpng/pngrtran.c
- Timestamp:
- 02/15/10 11:37:15 (2 years ago)
- Files:
-
- 1 modified
-
vendor/libpng/pngrtran.c (modified) (106 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/libpng/pngrtran.c
r11 r43 2 2 /* pngrtran.c - transforms the data in a row for PNG readers 3 3 * 4 * Last changed in libpng 1.2. 38 [July 16, 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 #if defined(PNG_READ_SUPPORTED)22 #ifdef PNG_READ_SUPPORTED 22 23 23 24 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ … … 26 27 { 27 28 png_debug(1, "in png_set_crc_action"); 28 /* Tell libpng how we react to CRC errors in critical chunks */29 29 30 if (png_ptr == NULL) 30 31 return; 32 33 /* Tell libpng how we react to CRC errors in critical chunks */ 31 34 switch (crit_action) 32 35 { … … 56 59 } 57 60 61 /* Tell libpng how we react to CRC errors in ancillary chunks */ 58 62 switch (ancil_action) 59 63 { … … 95 99 { 96 100 png_debug(1, "in png_set_background"); 101 97 102 if (png_ptr == NULL) 98 103 return; … … 112 117 #endif 113 118 114 #if defined(PNG_READ_16_TO_8_SUPPORTED)119 #ifdef PNG_READ_16_TO_8_SUPPORTED 115 120 /* Strip 16 bit depth files to 8 bit depth */ 116 121 void PNGAPI … … 118 123 { 119 124 png_debug(1, "in png_set_strip_16"); 125 120 126 if (png_ptr == NULL) 121 127 return; … … 124 130 #endif 125 131 126 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)132 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED 127 133 void PNGAPI 128 134 png_set_strip_alpha(png_structp png_ptr) 129 135 { 130 136 png_debug(1, "in png_set_strip_alpha"); 137 131 138 if (png_ptr == NULL) 132 139 return; … … 135 142 #endif 136 143 137 #if defined(PNG_READ_DITHER_SUPPORTED)144 #ifdef PNG_READ_DITHER_SUPPORTED 138 145 /* Dither file to 8 bit. Supply a palette, the current number 139 146 * of elements in the palette, the maximum number of elements … … 160 167 { 161 168 png_debug(1, "in png_set_dither"); 169 162 170 if (png_ptr == NULL) 163 171 return; … … 329 337 } 330 338 331 hash = (png_dsortpp)png_ malloc(png_ptr, (png_uint_32)(769 *339 hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * 332 340 png_sizeof(png_dsortp))); 333 png_memset(hash, 0, 769 * png_sizeof(png_dsortp));334 341 335 342 num_new_palette = num_palette; … … 477 484 int num_blue = (1 << PNG_DITHER_BLUE_BITS); 478 485 png_size_t num_entries = ((png_size_t)1 << total_bits); 479 png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr, 486 487 png_ptr->palette_lookup = (png_bytep )png_calloc(png_ptr, 480 488 (png_uint_32)(num_entries * png_sizeof(png_byte))); 481 png_memset(png_ptr->palette_lookup, 0, num_entries *482 png_sizeof(png_byte));483 489 484 490 distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * 485 491 png_sizeof(png_byte))); 486 487 492 png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); 488 493 … … 545 550 { 546 551 png_debug(1, "in png_set_gamma"); 552 547 553 if (png_ptr == NULL) 548 554 return; 555 549 556 if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || 550 557 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || … … 556 563 #endif 557 564 558 #if defined(PNG_READ_EXPAND_SUPPORTED)565 #ifdef PNG_READ_EXPAND_SUPPORTED 559 566 /* Expand paletted images to RGB, expand grayscale images of 560 567 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks … … 565 572 { 566 573 png_debug(1, "in png_set_expand"); 574 567 575 if (png_ptr == NULL) 568 576 return; 577 569 578 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 570 579 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; … … 584 593 * doing, whereas "expand" can (and does) mean any number of things. 585 594 * 586 * GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified 587 * to expand only the sample depth but not to expand the tRNS to alpha. 595 * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified 596 * to expand only the sample depth but not to expand the tRNS to alpha 597 * and its name was changed to png_set_expand_gray_1_2_4_to_8(). 588 598 */ 589 599 … … 593 603 { 594 604 png_debug(1, "in png_set_palette_to_rgb"); 605 595 606 if (png_ptr == NULL) 596 607 return; 608 597 609 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 598 610 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; 599 611 } 600 612 601 #if !defined(PNG_1_0_X)613 #ifndef PNG_1_0_X 602 614 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ 603 615 void PNGAPI … … 605 617 { 606 618 png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); 619 607 620 if (png_ptr == NULL) 608 621 return; 622 609 623 png_ptr->transformations |= PNG_EXPAND; 610 624 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; … … 619 633 { 620 634 png_debug(1, "in png_set_gray_1_2_4_to_8"); 635 621 636 if (png_ptr == NULL) 622 637 return; 638 623 639 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 624 640 } … … 631 647 { 632 648 png_debug(1, "in png_set_tRNS_to_alpha"); 649 633 650 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 634 651 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; … … 636 653 #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ 637 654 638 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)655 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 639 656 void PNGAPI 640 657 png_set_gray_to_rgb(png_structp png_ptr) 641 658 { 642 659 png_debug(1, "in png_set_gray_to_rgb"); 660 643 661 png_ptr->transformations |= PNG_GRAY_TO_RGB; 644 662 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; … … 646 664 #endif 647 665 648 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)649 #if defined(PNG_FLOATING_POINT_SUPPORTED)666 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED 667 #ifdef PNG_FLOATING_POINT_SUPPORTED 650 668 /* Convert a RGB image to a grayscale of the same width. This allows us, 651 669 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. … … 669 687 { 670 688 png_debug(1, "in png_set_rgb_to_gray"); 689 671 690 if (png_ptr == NULL) 672 691 return; 692 673 693 switch(error_action) 674 694 { … … 682 702 } 683 703 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 684 #if defined(PNG_READ_EXPAND_SUPPORTED)704 #ifdef PNG_READ_EXPAND_SUPPORTED 685 705 png_ptr->transformations |= PNG_EXPAND; 686 706 #else … … 725 745 { 726 746 png_debug(1, "in png_set_read_user_transform_fn"); 747 727 748 if (png_ptr == NULL) 728 749 return; 729 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 750 751 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED 730 752 png_ptr->transformations |= PNG_USER_TRANSFORM; 731 753 png_ptr->read_user_transform_fn = read_user_transform_fn; … … 746 768 { 747 769 png_debug(1, "in png_init_read_transformations"); 748 #if defined(PNG_USELESS_TESTS_SUPPORTED) 749 if (png_ptr != NULL) 770 771 #ifdef PNG_USELESS_TESTS_SUPPORTED 772 if (png_ptr != NULL) 750 773 #endif 751 774 { … … 757 780 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) 758 781 759 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)782 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 760 783 /* Detect gray background and attempt to enable optimization 761 784 * for gray --> RGB case … … 844 867 png_ptr->palette[png_ptr->background.index].blue; 845 868 846 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)869 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED 847 870 if (png_ptr->transformations & PNG_INVERT_ALPHA) 848 871 { 849 #if defined(PNG_READ_EXPAND_SUPPORTED)872 #ifdef PNG_READ_EXPAND_SUPPORTED 850 873 if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) 851 874 #endif … … 890 913 { 891 914 png_build_gamma_table(png_ptr); 892 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 915 916 #ifdef PNG_READ_BACKGROUND_SUPPORTED 893 917 if (png_ptr->transformations & PNG_BACKGROUND) 894 918 { … … 991 1015 } 992 1016 } 993 /* Prevent the transformations being done again, and make sure994 * that the now spurious alpha channel is stripped - the code995 * has just reduced background composition and gamma correction996 * to a simple alpha channel strip.997 */998 png_ptr->transformations &= ~PNG_BACKGROUND;999 png_ptr->transformations &= ~PNG_GAMMA;1000 png_ptr->transformations |= PNG_STRIP_ALPHA;1017 /* Prevent the transformations being done again, and make sure 1018 * that the now spurious alpha channel is stripped - the code 1019 * has just reduced background composition and gamma correction 1020 * to a simple alpha channel strip. 1021 */ 1022 png_ptr->transformations &= ~PNG_BACKGROUND; 1023 png_ptr->transformations &= ~PNG_GAMMA; 1024 png_ptr->transformations |= PNG_STRIP_ALPHA; 1001 1025 } 1002 1026 /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ … … 1076 1100 } 1077 1101 1078 /* Done the gamma correction. */1079 png_ptr->transformations &= ~PNG_GAMMA;1102 /* Done the gamma correction. */ 1103 png_ptr->transformations &= ~PNG_GAMMA; 1080 1104 } 1081 1105 } 1082 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1106 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1083 1107 else 1084 1108 #endif 1085 1109 #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */ 1086 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1110 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1087 1111 /* No GAMMA transformation */ 1088 1112 if ((png_ptr->transformations & PNG_BACKGROUND) && … … 1122 1146 #endif /* PNG_READ_BACKGROUND_SUPPORTED */ 1123 1147 1124 #if defined(PNG_READ_SHIFT_SUPPORTED)1148 #ifdef PNG_READ_SHIFT_SUPPORTED 1125 1149 if ((png_ptr->transformations & PNG_SHIFT) && 1126 1150 (color_type == PNG_COLOR_TYPE_PALETTE)) … … 1162 1186 { 1163 1187 png_debug(1, "in png_read_transform_info"); 1164 #if defined(PNG_READ_EXPAND_SUPPORTED) 1188 1189 #ifdef PNG_READ_EXPAND_SUPPORTED 1165 1190 if (png_ptr->transformations & PNG_EXPAND) 1166 1191 { … … 1189 1214 #endif 1190 1215 1191 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1216 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1192 1217 if (png_ptr->transformations & PNG_BACKGROUND) 1193 1218 { … … 1198 1223 #endif 1199 1224 1200 #if defined(PNG_READ_GAMMA_SUPPORTED)1225 #ifdef PNG_READ_GAMMA_SUPPORTED 1201 1226 if (png_ptr->transformations & PNG_GAMMA) 1202 1227 { … … 1210 1235 #endif 1211 1236 1212 #if defined(PNG_READ_16_TO_8_SUPPORTED)1237 #ifdef PNG_READ_16_TO_8_SUPPORTED 1213 1238 if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) 1214 1239 info_ptr->bit_depth = 8; 1215 1240 #endif 1216 1241 1217 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)1242 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 1218 1243 if (png_ptr->transformations & PNG_GRAY_TO_RGB) 1219 1244 info_ptr->color_type |= PNG_COLOR_MASK_COLOR; 1220 1245 #endif 1221 1246 1222 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)1247 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED 1223 1248 if (png_ptr->transformations & PNG_RGB_TO_GRAY) 1224 1249 info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR; 1225 1250 #endif 1226 1251 1227 #if defined(PNG_READ_DITHER_SUPPORTED)1252 #ifdef PNG_READ_DITHER_SUPPORTED 1228 1253 if (png_ptr->transformations & PNG_DITHER) 1229 1254 { … … 1237 1262 #endif 1238 1263 1239 #if defined(PNG_READ_PACK_SUPPORTED)1264 #ifdef PNG_READ_PACK_SUPPORTED 1240 1265 if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) 1241 1266 info_ptr->bit_depth = 8; … … 1249 1274 info_ptr->channels = 1; 1250 1275 1251 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)1276 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED 1252 1277 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) 1253 1278 info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; … … 1257 1282 info_ptr->channels++; 1258 1283 1259 #if defined(PNG_READ_FILLER_SUPPORTED)1284 #ifdef PNG_READ_FILLER_SUPPORTED 1260 1285 /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ 1261 1286 if ((png_ptr->transformations & PNG_FILLER) && … … 1265 1290 info_ptr->channels++; 1266 1291 /* If adding a true alpha channel not just filler */ 1267 #if !defined(PNG_1_0_X)1292 #ifndef PNG_1_0_X 1268 1293 if (png_ptr->transformations & PNG_ADD_ALPHA) 1269 1294 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; … … 1288 1313 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); 1289 1314 1290 #if !defined(PNG_READ_EXPAND_SUPPORTED)1315 #ifndef PNG_READ_EXPAND_SUPPORTED 1291 1316 if (png_ptr) 1292 1317 return; … … 1302 1327 { 1303 1328 png_debug(1, "in png_do_read_transformations"); 1329 1304 1330 if (png_ptr->row_buf == NULL) 1305 1331 { 1306 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)1332 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) 1307 1333 char msg[50]; 1308 1334 … … 1328 1354 #endif 1329 1355 1330 #if defined(PNG_READ_EXPAND_SUPPORTED)1356 #ifdef PNG_READ_EXPAND_SUPPORTED 1331 1357 if (png_ptr->transformations & PNG_EXPAND) 1332 1358 { … … 1349 1375 #endif 1350 1376 1351 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)1377 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED 1352 1378 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) 1353 1379 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, … … 1355 1381 #endif 1356 1382 1357 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)1383 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED 1358 1384 if (png_ptr->transformations & PNG_RGB_TO_GRAY) 1359 1385 { … … 1404 1430 */ 1405 1431 1406 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)1432 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 1407 1433 /* If gray -> RGB, do so now only if background is non-gray; else do later 1408 1434 * for performance reasons … … 1413 1439 #endif 1414 1440 1415 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1441 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1416 1442 if ((png_ptr->transformations & PNG_BACKGROUND) && 1417 1443 ((png_ptr->num_trans != 0 ) || … … 1419 1445 png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, 1420 1446 &(png_ptr->trans_values), &(png_ptr->background) 1421 #if defined(PNG_READ_GAMMA_SUPPORTED)1447 #ifdef PNG_READ_GAMMA_SUPPORTED 1422 1448 , &(png_ptr->background_1), 1423 1449 png_ptr->gamma_table, png_ptr->gamma_from_1, … … 1429 1455 #endif 1430 1456 1431 #if defined(PNG_READ_GAMMA_SUPPORTED)1457 #ifdef PNG_READ_GAMMA_SUPPORTED 1432 1458 if ((png_ptr->transformations & PNG_GAMMA) && 1433 #if defined(PNG_READ_BACKGROUND_SUPPORTED)1459 #ifdef PNG_READ_BACKGROUND_SUPPORTED 1434 1460 !((png_ptr->transformations & PNG_BACKGROUND) && 1435 1461 ((png_ptr->num_trans != 0) || … … 1442 1468 #endif 1443 1469 1444 #if defined(PNG_READ_16_TO_8_SUPPORTED)1470 #ifdef PNG_READ_16_TO_8_SUPPORTED 1445 1471 if (png_ptr->transformations & PNG_16_TO_8) 1446 1472 png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); 1447 1473 #endif 1448 1474 1449 #if defined(PNG_READ_DITHER_SUPPORTED)1475 #ifdef PNG_READ_DITHER_SUPPORTED 1450 1476 if (png_ptr->transformations & PNG_DITHER) 1451 1477 { … … 1457 1483 #endif 1458 1484 1459 #if defined(PNG_READ_INVERT_SUPPORTED)1485 #ifdef PNG_READ_INVERT_SUPPORTED 1460 1486 if (png_ptr->transformations & PNG_INVERT_MONO) 1461 1487 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); 1462 1488 #endif 1463 1489 1464 #if defined(PNG_READ_SHIFT_SUPPORTED)1490 #ifdef PNG_READ_SHIFT_SUPPORTED 1465 1491 if (png_ptr->transformations & PNG_SHIFT) 1466 1492 png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1, … … 1468 1494 #endif 1469 1495 1470 #if defined(PNG_READ_PACK_SUPPORTED)1496 #ifdef PNG_READ_PACK_SUPPORTED 1471 1497 if (png_ptr->transformations & PNG_PACK) 1472 1498 png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1); 1473 1499 #endif 1474 1500 1475 #if defined(PNG_READ_BGR_SUPPORTED)1501 #ifdef PNG_READ_BGR_SUPPORTED 1476 1502 if (png_ptr->transformations & PNG_BGR) 1477 1503 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); 1478 1504 #endif 1479 1505 1480 #if defined(PNG_READ_PACKSWAP_SUPPORTED)1506 #ifdef PNG_READ_PACKSWAP_SUPPORTED 1481 1507 if (png_ptr->transformations & PNG_PACKSWAP) 1482 1508 png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); 1483 1509 #endif 1484 1510 1485 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)1511 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 1486 1512 /* If gray -> RGB, do so now only if we did not do so above */ 1487 1513 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && … … 1490 1516 #endif 1491 1517 1492 #if defined(PNG_READ_FILLER_SUPPORTED)1518 #ifdef PNG_READ_FILLER_SUPPORTED 1493 1519 if (png_ptr->transformations & PNG_FILLER) 1494 1520 png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, … … 1496 1522 #endif 1497 1523 1498 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)1524 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED 1499 1525 if (png_ptr->transformations & PNG_INVERT_ALPHA) 1500 1526 png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); 1501 1527 #endif 1502 1528 1503 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)1529 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED 1504 1530 if (png_ptr->transformations & PNG_SWAP_ALPHA) 1505 1531 png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); 1506 1532 #endif 1507 1533 1508 #if defined(PNG_READ_SWAP_SUPPORTED)1534 #ifdef PNG_READ_SWAP_SUPPORTED 1509 1535 if (png_ptr->transformations & PNG_SWAP_BYTES) 1510 1536 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); 1511 1537 #endif 1512 1538 1513 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)1539 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED 1514 1540 if (png_ptr->transformations & PNG_USER_TRANSFORM) 1515 1541 { … … 1525 1551 /* png_byte pixel_depth; bits per pixel (depth*channels) */ 1526 1552 png_ptr->row_buf + 1); /* start of pixel data for row */ 1527 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)1553 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED 1528 1554 if (png_ptr->user_transform_depth) 1529 1555 png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; … … 1540 1566 } 1541 1567 1542 #if defined(PNG_READ_PACK_SUPPORTED)1568 #ifdef PNG_READ_PACK_SUPPORTED 1543 1569 /* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, 1544 1570 * without changing the actual values. Thus, if you had a row with … … 1551 1577 { 1552 1578 png_debug(1, "in png_do_unpack"); 1553 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1579 1580 #ifdef PNG_USELESS_TESTS_SUPPORTED 1554 1581 if (row != NULL && row_info != NULL && row_info->bit_depth < 8) 1555 1582 #else … … 1633 1660 #endif 1634 1661 1635 #if defined(PNG_READ_SHIFT_SUPPORTED)1662 #ifdef PNG_READ_SHIFT_SUPPORTED 1636 1663 /* Reverse the effects of png_do_shift. This routine merely shifts the 1637 1664 * pixels back to their significant bits values. Thus, if you have … … 1643 1670 { 1644 1671 png_debug(1, "in png_do_unshift"); 1672 1645 1673 if ( 1646 #if defined(PNG_USELESS_TESTS_SUPPORTED)1674 #ifdef PNG_USELESS_TESTS_SUPPORTED 1647 1675 row != NULL && row_info != NULL && sig_bits != NULL && 1648 1676 #endif … … 1746 1774 #endif 1747 1775 1748 #if defined(PNG_READ_16_TO_8_SUPPORTED)1776 #ifdef PNG_READ_16_TO_8_SUPPORTED 1749 1777 /* Chop rows of bit depth 16 down to 8 */ 1750 1778 void /* PRIVATE */ … … 1752 1780 { 1753 1781 png_debug(1, "in png_do_chop"); 1754 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1782 1783 #ifdef PNG_USELESS_TESTS_SUPPORTED 1755 1784 if (row != NULL && row_info != NULL && row_info->bit_depth == 16) 1756 1785 #else … … 1765 1794 for (i = 0; i<istop; i++, sp += 2, dp++) 1766 1795 { 1767 #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)1796 #ifdef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED 1768 1797 /* This does a more accurate scaling of the 16-bit color 1769 1798 * value, rather than a simple low-byte truncation. … … 1804 1833 #endif 1805 1834 1806 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)1835 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED 1807 1836 void /* PRIVATE */ 1808 1837 png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) 1809 1838 { 1810 1839 png_debug(1, "in png_do_read_swap_alpha"); 1811 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1840 1841 #ifdef PNG_USELESS_TESTS_SUPPORTED 1812 1842 if (row != NULL && row_info != NULL) 1813 1843 #endif … … 1896 1926 #endif 1897 1927 1898 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)1928 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED 1899 1929 void /* PRIVATE */ 1900 1930 png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) 1901 1931 { 1902 1932 png_debug(1, "in png_do_read_invert_alpha"); 1903 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1933 1934 #ifdef PNG_USELESS_TESTS_SUPPORTED 1904 1935 if (row != NULL && row_info != NULL) 1905 1936 #endif … … 1994 2025 #endif 1995 2026 1996 #if defined(PNG_READ_FILLER_SUPPORTED)2027 #ifdef PNG_READ_FILLER_SUPPORTED 1997 2028 /* Add filler channel if we have RGB color */ 1998 2029 void /* PRIVATE */ … … 2007 2038 2008 2039 png_debug(1, "in png_do_read_filler"); 2040 2009 2041 if ( 2010 #if defined(PNG_USELESS_TESTS_SUPPORTED)2042 #ifdef PNG_USELESS_TESTS_SUPPORTED 2011 2043 row != NULL && row_info != NULL && 2012 2044 #endif … … 2170 2202 #endif 2171 2203 2172 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)2204 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED 2173 2205 /* Expand grayscale files to RGB, with or without alpha */ 2174 2206 void /* PRIVATE */ … … 2179 2211 2180 2212 png_debug(1, "in png_do_gray_to_rgb"); 2213 2181 2214 if (row_info->bit_depth >= 8 && 2182 #if defined(PNG_USELESS_TESTS_SUPPORTED)2215 #ifdef PNG_USELESS_TESTS_SUPPORTED 2183 2216 row != NULL && row_info != NULL && 2184 2217 #endif … … 2253 2286 #endif 2254 2287 2255 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)2288 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED 2256 2289 /* Reduce RGB files to grayscale, with or without alpha 2257 2290 * using the equation given in Poynton's ColorFAQ at … … 2285 2318 2286 2319 png_debug(1, "in png_do_rgb_to_gray"); 2320 2287 2321 if ( 2288 #if defined(PNG_USELESS_TESTS_SUPPORTED)2322 #ifdef PNG_USELESS_TESTS_SUPPORTED 2289 2323 row != NULL && row_info != NULL && 2290 2324 #endif … … 2523 2557 2524 2558 png_debug(1, "in png_do_build_grayscale_palette"); 2559 2525 2560 if (palette == NULL) 2526 2561 return; … … 2569 2604 { 2570 2605 png_debug(1, "in png_correct_palette"); 2606 2571 2607 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ 2572 2608 defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) … … 2679 2715 else 2680 2716 #endif 2681 #if defined(PNG_READ_GAMMA_SUPPORTED)2717 #ifdef PNG_READ_GAMMA_SUPPORTED 2682 2718 if (png_ptr->transformations & PNG_GAMMA) 2683 2719 { … … 2691 2727 } 2692 2728 } 2693 #if defined(PNG_READ_BACKGROUND_SUPPORTED)2729 #ifdef PNG_READ_BACKGROUND_SUPPORTED 2694 2730 else 2695 2731 #endif 2696 2732 #endif 2697 #if defined(PNG_READ_BACKGROUND_SUPPORTED)2733 #ifdef PNG_READ_BACKGROUND_SUPPORTED 2698 2734 if (png_ptr->transformations & PNG_BACKGROUND) 2699 2735 { … … 2744 2780 #endif 2745 2781 2746 #if defined(PNG_READ_BACKGROUND_SUPPORTED)2782 #ifdef PNG_READ_BACKGROUND_SUPPORTED 2747 2783 /* Replace any alpha or transparency with the supplied background color. 2748 2784 * "background" is already in the screen gamma, while "background_1" is … … 2752 2788 png_do_background(png_row_infop row_info, png_bytep row, 2753 2789 png_color_16p trans_values, png_color_16p background 2754 #if defined(PNG_READ_GAMMA_SUPPORTED)2790 #ifdef PNG_READ_GAMMA_SUPPORTED 2755 2791 , png_color_16p background_1, 2756 2792 png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, … … 2766 2802 2767 2803 png_debug(1, "in png_do_background"); 2804 2768 2805 if (background != NULL && 2769 #if defined(PNG_USELESS_TESTS_SUPPORTED)2806 #ifdef PNG_USELESS_TESTS_SUPPORTED 2770 2807 row != NULL && row_info != NULL && 2771 2808 #endif … … 2804 2841 case 2: 2805 2842 { 2806 #if defined(PNG_READ_GAMMA_SUPPORTED)2843 #ifdef PNG_READ_GAMMA_SUPPORTED 2807 2844 if (gamma_table != NULL) 2808 2845 { … … 2861 2898 case 4: 2862 2899 { 2863 #if defined(PNG_READ_GAMMA_SUPPORTED)2900 #ifdef PNG_READ_GAMMA_SUPPORTED 2864 2901 if (gamma_table != NULL) 2865 2902 { … … 2918 2955 case 8: 2919 2956 { 2920 #if defined(PNG_READ_GAMMA_SUPPORTED)2957 #ifdef PNG_READ_GAMMA_SUPPORTED 2921 2958 if (gamma_table != NULL) 2922 2959 { … … 2951 2988 case 16: 2952 2989 { 2953 #if defined(PNG_READ_GAMMA_SUPPORTED)2990 #ifdef PNG_READ_GAMMA_SUPPORTED 2954 2991 if (gamma_16 != NULL) 2955 2992 { … … 3000 3037 if (row_info->bit_depth == 8) 3001 3038 { 3002 #if defined(PNG_READ_GAMMA_SUPPORTED)3039 #ifdef PNG_READ_GAMMA_SUPPORTED 3003 3040 if (gamma_table != NULL) 3004 3041 { … … 3041 3078 else /* if (row_info->bit_depth == 16) */ 3042 3079 { 3043 #if defined(PNG_READ_GAMMA_SUPPORTED)3080 #ifdef PNG_READ_GAMMA_SUPPORTED 3044 3081 if (gamma_16 != NULL) 3045 3082 { … … 3105 3142 if (row_info->bit_depth == 8) 3106 3143 { 3107 #if defined(PNG_READ_GAMMA_SUPPORTED)3144 #ifdef PNG_READ_GAMMA_SUPPORTED 3108 3145 if (gamma_to_1 != NULL && gamma_from_1 != NULL && 3109 3146 gamma_table != NULL) … … 3147 3184 *dp = *sp; 3148 3185 } 3149 #if defined(PNG_READ_GAMMA_SUPPORTED)3186 #ifdef PNG_READ_GAMMA_SUPPORTED 3150 3187 else if (a == 0) 3151 3188 { … … 3164 3201 else /* if (png_ptr->bit_depth == 16) */ 3165 3202 { 3166 #if defined(PNG_READ_GAMMA_SUPPORTED)3203 #ifdef PNG_READ_GAMMA_SUPPORTED 3167 3204 if (gamma_16 != NULL && gamma_16_from_1 != NULL && 3168 3205 gamma_16_to_1 != NULL) … … 3182 3219 *(dp + 1) = (png_byte)(v & 0xff); 3183 3220 } 3184 #if defined(PNG_READ_GAMMA_SUPPORTED)3221 #ifdef PNG_READ_GAMMA_SUPPORTED 3185 3222 else if (a == 0) 3186 3223 #else … … 3192 3229 *(dp + 1) = (png_byte)(background->gray & 0xff); 3193 3230 } 3194 #if defined(PNG_READ_GAMMA_SUPPORTED)3231 #ifdef PNG_READ_GAMMA_SUPPORTED 3195 3232 else 3196 3233 { … … 3218 3255 png_memcpy(dp, sp, 2); 3219 3256 } 3220 #if defined(PNG_READ_GAMMA_SUPPORTED)3257 #ifdef PNG_READ_GAMMA_SUPPORTED 3221 3258 else if (a == 0) 3222 3259 #else … … 3227 3264 *(dp + 1) = (png_byte)(background->gray & 0xff); 3228 3265 } 3229 #if defined(PNG_READ_GAMMA_SUPPORTED)3266 #ifdef PNG_READ_GAMMA_SUPPORTED 3230 3267 else 3231 3268 { … … 3248 3285 if (row_info->bit_depth == 8) 3249 3286 { 3250 #if defined(PNG_READ_GAMMA_SUPPORTED)3287 #ifdef PNG_READ_GAMMA_SUPPORTED 3251 3288 if (gamma_to_1 != NULL && gamma_from_1 != NULL && 3252 3289 gamma_table != NULL) … … 3321 3358 else /* if (row_info->bit_depth == 16) */ 3322 3359 { 3323 #if defined(PNG_READ_GAMMA_SUPPORTED)3360 #ifdef PNG_READ_GAMMA_SUPPORTED 3324 3361 if (gamma_16 != NULL && gamma_16_from_1 != NULL && 3325 3362 gamma_16_to_1 != NULL) … … 3438 3475 #endif 3439 3476 3440 #if defined(PNG_READ_GAMMA_SUPPORTED)3477 #ifdef PNG_READ_GAMMA_SUPPORTED 3441 3478 /* Gamma correct the image, avoiding the alpha channel. Make sure 3442 3479 * you do this after you deal with the transparency issue on grayscale … … 3455 3492 3456 3493 png_debug(1, "in png_do_gamma"); 3494 3457 3495 if ( 3458 #if defined(PNG_USELESS_TESTS_SUPPORTED)3496 #ifdef PNG_USELESS_TESTS_SUPPORTED 3459 3497 row != NULL && row_info != NULL && 3460 3498 #endif … … 3629 3667 #endif 3630 3668 3631 #if defined(PNG_READ_EXPAND_SUPPORTED)3669 #ifdef PNG_READ_EXPAND_SUPPORTED 3632 3670 /* Expands a palette row to an RGB or RGBA row depending 3633 3671 * upon whether you supply trans and num_trans. … … 3643 3681 3644 3682 png_debug(1, "in png_do_expand_palette"); 3683 3645 3684 if ( 3646 #if defined(PNG_USELESS_TESTS_SUPPORTED)3685 #ifdef PNG_USELESS_TESTS_SUPPORTED 3647 3686 row != NULL && row_info != NULL && 3648 3687 #endif … … 3789 3828 3790 3829 png_debug(1, "in png_do_expand"); 3791 #if defined(PNG_USELESS_TESTS_SUPPORTED) 3830 3831 #ifdef PNG_USELESS_TESTS_SUPPORTED 3792 3832 if (row != NULL && row_info != NULL) 3793 3833 #endif … … 3990 4030 #endif 3991 4031 3992 #if defined(PNG_READ_DITHER_SUPPORTED)4032 #ifdef PNG_READ_DITHER_SUPPORTED 3993 4033 void /* PRIVATE */ 3994 4034 png_do_dither(png_row_infop row_info, png_bytep row, … … 4000 4040 4001 4041 png_debug(1, "in png_do_dither"); 4002 #if defined(PNG_USELESS_TESTS_SUPPORTED) 4042 4043 #ifdef PNG_USELESS_TESTS_SUPPORTED 4003 4044 if (row != NULL && row_info != NULL) 4004 4045 #endif … … 4082 4123 4083 4124 #ifdef PNG_FLOATING_POINT_SUPPORTED 4084 #if defined(PNG_READ_GAMMA_SUPPORTED)4125 #ifdef PNG_READ_GAMMA_SUPPORTED 4085 4126 static PNG_CONST int png_gamma_shift[] = 4086 4127 {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00}; … … 4090 4131 * the future. Note also how the gamma_16 tables are segmented so that 4091 4132 * we don't need to allocate > 64K chunks for a full 16-bit table. 4133 * 4134 * See the PNG extensions document for an integer algorithm for creating 4135 * the gamma tables. Maybe we will implement that here someday. 4136 * 4137 * We should only reach this point if 4138 * 4139 * the file_gamma is known (i.e., the gAMA or sRGB chunk is present, 4140 * or the application has provided a file_gamma) 4141 * 4142 * AND 4143 * { 4144 * the screen_gamma is known 4145 * OR 4146 * 4147 * RGB_to_gray transformation is being performed 4148 * } 4149 * 4150 * AND 4151 * { 4152 * the screen_gamma is different from the reciprocal of the 4153 * file_gamma by more than the specified threshold 4154 * 4155 * OR 4156 * 4157 * a background color has been specified and the file_gamma 4158 * and screen_gamma are not 1.0, within the specified threshold. 4159 * } 4092 4160 */ 4161 4093 4162 void /* PRIVATE */ 4094 4163 png_build_gamma_table(png_structp png_ptr) … … 4200 4269 g = 1.0; 4201 4270 4202 png_ptr->gamma_16_table = (png_uint_16pp)png_ malloc(png_ptr,4271 png_ptr->gamma_16_table = (png_uint_16pp)png_calloc(png_ptr, 4203 4272 (png_uint_32)(num * png_sizeof(png_uint_16p))); 4204 png_memset(png_ptr->gamma_16_table, 0, num * png_sizeof(png_uint_16p));4205 4273 4206 4274 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) … … 4262 4330 g = 1.0 / (png_ptr->gamma); 4263 4331 4264 png_ptr->gamma_16_to_1 = (png_uint_16pp)png_ malloc(png_ptr,4332 png_ptr->gamma_16_to_1 = (png_uint_16pp)png_calloc(png_ptr, 4265 4333 (png_uint_32)(num * png_sizeof(png_uint_16p ))); 4266 png_memset(png_ptr->gamma_16_to_1, 0, num * png_sizeof(png_uint_16p));4267 4334 4268 4335 for (i = 0; i < num; i++) … … 4287 4354 g = png_ptr->gamma; /* Probably doing rgb_to_gray */ 4288 4355 4289 png_ptr->gamma_16_from_1 = (png_uint_16pp)png_ malloc(png_ptr,4356 png_ptr->gamma_16_from_1 = (png_uint_16pp)png_calloc(png_ptr, 4290 4357 (png_uint_32)(num * png_sizeof(png_uint_16p))); 4291 png_memset(png_ptr->gamma_16_from_1, 0,4292 num * png_sizeof(png_uint_16p));4293 4358 4294 4359 for (i = 0; i < num; i++) … … 4315 4380 #endif 4316 4381 4317 #if defined(PNG_MNG_FEATURES_SUPPORTED)4382 #ifdef PNG_MNG_FEATURES_SUPPORTED 4318 4383 /* Undoes intrapixel differencing */ 4319 4384 void /* PRIVATE */ … … 4321 4386 { 4322 4387 png_debug(1, "in png_do_read_intrapixel"); 4388 4323 4389 if ( 4324 #if defined(PNG_USELESS_TESTS_SUPPORTED)4390 #ifdef PNG_USELESS_TESTS_SUPPORTED 4325 4391 row != NULL && row_info != NULL && 4326 4392 #endif
