at last, fixed the bug, and re-enabled 5-gray levels support for backwards compatibility..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 3a75330..45e2cd0 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -140,16 +140,34 @@
/*************************************************************************/
/* */
+ /* DLL Export Compilation */
+ /* */
/* When compiling FreeType as a DLL, some systems/compilers need a */
- /* special keyword in front of each function definition instead of */
- /* `extern'. */
+ /* special keyword in front OR after the return type of function */
+ /* declarations. */
+ /* */
+ /* Two macros are used within the FreeType source code to define */
+ /* exported library functions: EXPORT_DEF and EXPORT_FUNC */
+ /* */
+ /* EXPORT_DEF(return_type) is used in a function declaration, as in: */
+ /* */
+ /* EXPORT_DEF(FT_Error) FT_Init_FreeType( FT_Library *alibrary ); */
+ /* */
+ /* */
/* */
- /* The macros EXPORT_DEF and EXPORT_FUNC are thus used to define */
- /* exported library function interfaces and exported library functions */
- /* implementations respectively. */
+ /* EXPORT_FUNC(return_type) is used in a function definition, as in: */
/* */
- /* If not defined here, they automatically default to `extern' and void */
- /* later in this header file. */
+ /* EXPORT_FUNC(FT_Error) FT_Init_FreeType( FT_Library *alibrary ) */
+ /* { */
+ /* ... some code ... */
+ /* return FT_Err_Ok; */
+ /* } */
+ /* */
+ /* */
+ /* You can provide your own implementation of EXPORT_DEF and EXPORT_FUNC */
+ /* here if you want. If you leave them undefined, they'll later be */
+ /* automatically defined as "extern return_type" to allow normal */
+ /* compilation.. */
/* */
#undef EXPORT_DEF
#undef EXPORT_FUNC
@@ -157,6 +175,25 @@
/*************************************************************************/
/* */
+ /* 5-levels Anti Aliasing support: */
+ /* */
+ /* FreeType 2 provides a new "smooth" renderer that is capable of */
+ /* producing anti-aliased glyph bitmaps with up to 256 gray-levels. */
+ /* */
+ /* However, for compatibility purposes with FreeType 1.x, the standard */
+ /* raster is still capable of generating anti-aliased bitmaps with 5 */
+ /* gray levels. */
+ /* */
+ /* If you do not need this capability (i.e. if you always use the */
+ /* "smooth" renderer for anti-aliased glyphs), we suggest you to */
+ /* undefine this configuration macro, as it will save both code and */
+ /* memory.. */
+ /* */
+#define FT_CONFIG_OPTION_5_GRAY_LEVELS
+
+
+ /*************************************************************************/
+ /* */
/* Debug level */
/* */
/* FreeType can be compiled in debug or trace mode. In debug mode, */
@@ -175,17 +212,6 @@
/*************************************************************************/
/* */
- /* Anti-aliasing support */
- /* */
- /* Undefine this macro only if you want to disable the anti-aliasing */
- /* support in FreeType. This will save you about 5 Kb of code. It */
- /* may be important for some embedded systems. */
- /* */
-#define FT_CONFIG_OPTION_ANTI_ALIAS
-
-
- /*************************************************************************/
- /* */
/* Endianess performance improvement */
/* */
/* FreeType is completely endian-independent, and can thus be compiled */
@@ -212,6 +238,7 @@
/* */
#define FT_CONFIG_OPTION_OLD_CALCS
+
/*************************************************************************/
/* */
/* The size in bytes of the render pool used by the scan-line */
diff --git a/src/base/ftraster.c b/src/base/ftraster.c
index d68edfc..93c25af 100644
--- a/src/base/ftraster.c
+++ b/src/base/ftraster.c
@@ -1,234 +1,159 @@
-/***************************************************************************/
-/* */
-/* ftraster.c */
-/* */
-/* The FreeType glyph rasterizer (body). */
-/* */
-/* Copyright 1996-2000 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used */
-/* modified and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
-
-
- /*************************************************************************/
- /* */
- /* The `raster' component implements FreeType's scan-line converter, the */
- /* one used to generate bitmaps and pixmaps from vectorial outline */
- /* descriptions. */
- /* */
- /* It has been rewritten entirely for FreeType 2.0, in order to become */
- /* completely independent of the rest of the library. It should now be */
- /* possible to include it more easily in all kinds of libraries and */
- /* applications, which do not necessarily need the font engines and API. */
- /* */
- /* This version contains the following features: */
- /* */
- /* - Support for third-order Bezier arcs. */
- /* */
- /* - Improved performance of the 5-levels anti-aliasing algorithm. */
- /* */
- /* - 17-levels anti-aliasing for smoother curves, though the difference */
- /* isn't always noticeable, depending on your palette. */
- /* */
- /* - An API to decompose a raster outline into a path (i.e., into a */
- /* a series of segments and arcs). */
- /* */
- /* Planned additions: */
- /* */
- /* - Getting rid of the second pass for horizontal drop-out detection. */
- /* I've got a few ideas, but I'll have to experiment in Pascal with */
- /* them. to avoid damaging of the rendering of glyphs at small sizes. */
- /* */
- /* - Adding a `composition' callback, which should be invoked during */
- /* anti-aliased rendering. In short, it will allow line-by-line */
- /* composition (i.e., transparencies, etc.) of the output in a fairly */
- /* portable way. Of course, a single sweep is required there. */
- /* */
- /*************************************************************************/
-
-#define OLD
-
-
-#define xxxDEBUG_RAS
-#ifdef DEBUG_RAS
-#include <stdio.h>
-#endif
-
+/*******************************************************************
+ *
+ * ftraster.c 1.5
+ *
+ * The FreeType glyph rasterizer (body).
+ *
+ * Copyright 1996-2000 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used
+ * modified and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ *
+ * This is a rewrite of the FreeType 1.x scan-line converter
+ *
+ *
+ *
+ ******************************************************************/
#include <freetype/ftraster.h>
-#ifndef _STANDALONE_
-#include <freetype/internal/ftdebug.h>
-#endif
-
-#ifndef UNUSED
-#define UNUSED( arg ) ( (arg)=(arg) )
-#endif
-
-#undef FT_COMPONENT
-#define FT_COMPONENT trace_raster
-
-#ifdef _STANDALONE_
+#include <freetype/internal/ftcalc.h> /* for FT_MulDiv only */
/*************************************************************************/
/* */
- /* The following defines are used when the raster is compiled as a */
- /* stand-alone object. Each of them is commented, and you're free to */
- /* toggle them to suit your needs. */
- /* */
- /*************************************************************************/
-
- /*************************************************************************/
- /* */
- /* FT_RASTER_INT_IS_32 */
- /* */
- /* Set this configuration macro to the unsigned type which has 32 */
- /* bits. */
- /* */
-#define FT_RASTER_INT_IS_32
-
-
- /*************************************************************************/
+ /* A simple technical note on how the raster works: */
/* */
- /* FT_RASTER_OPTION_ANTI_ALIAS */
+ /* Converting an outline into a bitmap is achieved in several steps */
+ /* which are: */
/* */
- /* Define this configuration macro if you want to support */
- /* anti-aliasing. */
+ /* 1 - Decomposing the outline into successive `profiles'. Each */
+ /* profile is simply an array of scanline intersections on a given */
+ /* dimension. A profile's main attributes are */
/* */
-#undef FT_RASTER_OPTION_ANTI_ALIAS
-
-
- /*************************************************************************/
+ /* o its scanline position boundaries, i.e. `Ymin' and `Ymax'. */
/* */
- /* FT_RASTER_OPTION_CONIC_BEZIERS */
+ /* o an array of intersection coordinates for each scanline */
+ /* between `Ymin' and `Ymax'. */
/* */
- /* Define this configuration macro if your source outlines contain */
- /* second-order Bezier arcs. Typically, these are TrueType outlines. */
+ /* o a direction, indicating wether is was built going `up' or */
+ /* `down', as this is very important for filling rules. */
/* */
-#define FT_RASTER_CONIC_BEZIERS
-
-
- /*************************************************************************/
+ /* 2 - Sweeping the target map's scanlines in order to compute segment */
+ /* `spans' which are then filled. Additionaly, this pass performs */
+ /* drop-out control. */
/* */
- /* FT_RASTER_OPTION_CUBIC_BEZIERS */
+ /* The outline data is parsed during step 1 only. The profiles are */
+ /* built from the bottom of the render pool, used as a stack. The */
+ /* following graphics shows the profile list under construction: */
/* */
- /* Define this configuration macro if your source outlines contain */
- /* third-order Bezier arcs. Typically, these are Type1 outlines. */
+ /* ____________________________________________________________ _ _ */
+ /* | | | | | */
+ /* | profile | coordinates for | profile | coordinates for |--> */
+ /* | 1 | profile 1 | 2 | profile 2 |--> */
+ /* |_________|___________________|_________|_________________|__ _ _ */
/* */
-#define FT_RASTER_CUBIC_BEZIERS
-
-
- /*************************************************************************/
+ /* ^ ^ */
+ /* | | */
+ /* start of render pool top */
/* */
- /* FT_RASTER_CONSTANT_PRECISION */
+ /* The top of the profile stack is kept in the `top' variable. */
/* */
- /* Define this configuration macro if you want to use a constant */
- /* precision for the internal sub-pixel coordinates. Otherwise, the */
- /* precision is either 64 or 1024 units per pixel, depending on the */
- /* outline's "high_precision" flag.. */
+ /* As you can see, a profile record is pushed on top of the render */
+ /* pool, which is then followed by its coordinates/intersections. If */
+ /* a change of direction is detected in the outline, a new profile is */
+ /* generated until the end of the outline. */
/* */
- /* This results in a speed boost, but the macro can be undefined if */
- /* it results in rendering errors (mainly changed drop-outs).. */
+ /* Note that when all profiles have been generated, the function */
+ /* Finalize_Profile_Table() is used to record, for each profile, its */
+ /* bottom-most scanline as well as the scanline above its upmost */
+ /* boundary. These positions are called `y-turns' because they (sort */
+ /* of) correspond to local extrema. They are stored in a sorted list */
+ /* built from the top of the render pool as a downwards stack: */
/* */
-#undef FT_RASTER_CONSTANT_PRECISION
-
-
- /*************************************************************************/
+ /* _ _ _______________________________________ */
+ /* | | */
+ /* <--| sorted list of | */
+ /* <--| extrema scanlines | */
+ /* _ _ __________________|____________________| */
/* */
- /* FT_PRECISION_BITS */
+ /* ^ ^ */
+ /* | | */
+ /* maxBuff sizeBuff = end of pool */
/* */
- /* When the macro FT_RASTER_CONSTANT_PRECISION is defined, this */
- /* constant holds the number of bits used for the internal sub-pixels */
+ /* This list is later used during the sweep phase in order to */
+ /* optimize performance (see technical note on the sweep below). */
/* */
- /* This number should be at least 6, but use at least 8 if you */
- /* intend to generate small glyph images (use 6 for a printer, for */
- /* example..) */
+ /* Of course, the raster detects whether the two stacks collide and */
+ /* handles the situation propertly. */
/* */
-#define FT_PRECISION_BITS 8
-
-
/*************************************************************************/
- /* */
- /* FT_DYNAMIC_BEZIER_STEPS */
- /* */
- /* Set this macro to enable the bezier decomposition to be */
- /* dynamically computed. This is interesting when the precision is */
- /* constant, as it speeds things a bit while keeping a very good */
- /* accuracy on the bezier intersections.. */
- /* */
-#undef FT_DYNAMIC_BEZIER_STEPS
+ /****************************************************************/
+ /****************************************************************/
+ /** **/
+ /** CONFIGURATION MACROS **/
+ /** **/
+ /****************************************************************/
+ /****************************************************************/
-#else /* _STANDALONE_ */
+/* define DEBUG_RASTER if you want to compile a debugging version */
+#define xxxDEBUG_RASTER
-#include <freetype/freetype.h>
-#include <freetype/config/ftconfig.h>
+/* The default render pool size in bytes */
+#define RASTER_RENDER_POOL 8192
- /*************************************************************************/
- /* */
- /* The following defines are used when the raster is compiled within the */
- /* FreeType base layer. Don't change these unless you really know what */
- /* you're doing. */
- /* */
- /*************************************************************************/
-
-
-#ifdef FT_CONFIG_OPTION_ANTI_ALIAS
-#define FT_RASTER_OPTION_ANTI_ALIAS
+/* undefine FT_RASTER_OPTION_ANTI_ALIASING if you do not want to support */
+/* 5-levels anti-aliasing */
+#ifdef FT_CONFIG_OPTION_5_GRAY_LEVELS
+#define FT_RASTER_OPTION_ANTI_ALIASING
#endif
-#define FT_RASTER_CONIC_BEZIERS
-#define FT_RASTER_CUBIC_BEZIERS
+/* The size of the two-lines intermediate bitmap used */
+/* for anti-aliasing, in bytes.. */
+#define RASTER_GRAY_LINES 2048
-#define FT_RASTER_ANTI_ALIAS_5
-/* #define FT_RASTER_ANTI_ALIAS_17 */
-#ifdef FT_CONFIG_OPTION_LITTLE_ENDIAN
-#define FT_RASTER_LITTLE_ENDIAN
-#endif
+ /****************************************************************/
+ /****************************************************************/
+ /** **/
+ /** OTHER MACROS (do not change) **/
+ /** **/
+ /****************************************************************/
+ /****************************************************************/
-#ifdef FT_CONFIG_OPTION_BIG_ENDIAN
-#define FT_RASTER_BIG_ENDIAN
-#endif
+/* required by the tracing mode */
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_raster
-#undef FT_RASTER_CONSTANT_PRECISION
-#undef FT_DYNAMIC_BEZIER_STEPS
-#define FT_PRECISION_BITS 8
+#include <freetype/internal/ftdebug.h>
-#endif /* _STANDALONE_ */
+#define Raster_Err_None 0
+#define Raster_Err_Not_Ini -1
+#define Raster_Err_Overflow -2
+#define Raster_Err_Neg_Height -3
+#define Raster_Err_Invalid -4
+#define Raster_Err_Gray_Unsupported -5
+#define Raster_Err_Unsupported -6
+/* FMulDiv means "Fast MulDiv", it is used in case where 'b' is typically */
+/* a small value and the result of (a*b) is known to fit in 32 bits. */
+#define FMulDiv( a, b, c ) ( (a) * (b) / (c) )
-/* to keep the compiler happy */
-#ifndef FT_TRACE2
-#define FT_TRACE2(x) /*void*/
-#endif
+/* On the other hand, SMulDiv is for "Slow MulDiv", and is used typically */
+/* for clipping computations. It simply uses the FT_MulDiv() function */
+/* defined in "ftcalc.h" */
+/* */
+#define SMulDiv FT_MulDiv
-#ifndef FT_TRACE4
-#define FT_TRACE4(x) /* void */
-#endif
-
- /*************************************************************************/
- /* */
- /* FT_RASTER_ANY_ENDIAN indicates that no endianess was defined by one */
- /* of the configuration macros. */
- /* */
-#if !defined( FT_RASTER_LITTLE_ENDIAN ) && !defined( FT_RASTER_BIG_ENDIAN )
-#define FT_RASTER_ANY_ENDIAN
-#endif
- /*************************************************************************/
- /* */
- /* The rasterizer is a very general purpose component. Please leave the */
- /* following redefinitions here (you never know your target */
- /* environment). */
- /* */
- /*************************************************************************/
+/* The rasterizer is a very general purpose component, please leave */
+/* the following redefinitions there (you never know your target */
+/* environment). */
#ifndef TRUE
#define TRUE 1
@@ -242,499 +167,296 @@
#define NULL (void*)0
#endif
-
-#ifndef UNUSED
-#define UNUSED( arg ) ( (void)(arg) )
-#endif
-
-
-#undef FAILURE
-#define FAILURE TRUE
-
-#undef SUCCESS
-#define SUCCESS FALSE
-
-#ifndef ABS
-#define ABS(x) ( (x) < 0 ? -(x) : (x) )
+#ifndef SUCCESS
+#define SUCCESS 0
#endif
- /*************************************************************************/
- /* */
- /* Please don't touch the following macros. Their importance is */
- /* historical to FreeType, but they have some nice effects, like getting */
- /* rid of all `->' symbols when accessing the raster object (replacing */
- /* them with a simple `.'). */
- /* */
- /*************************************************************************/
-
- /* used in function signatures to define the _first_ argument */
-#define RAS_ARG_ FT_Raster raster,
-#define RAS_ARG FT_Raster raster
-
- /* used to call a function within this component, first parameter */
-#define RAS_VAR_ raster,
-#define RAS_VAR raster
-
- /* used to access the current raster object, with a `.' instead of a */
- /* `->' */
-#define ras (*raster)
-
-#define UNUSED_RASTER (raster=raster);
-
- /*************************************************************************/
- /* */
- /* Error codes returned by the scan-line converter/raster. */
- /* */
-#define ErrRaster_Ok 0
-#define ErrRaster_Uninitialized_Object 1
-#define ErrRaster_Overflow 2
-#define ErrRaster_Negative_Height 3
-#define ErrRaster_Invalid_Outline 4
-#define ErrRaster_Invalid_Map 5
-#define ErrRaster_AntiAlias_Unsupported 6
-#define ErrRaster_Invalid_Pool 7
-#define ErrRaster_Unimplemented 8
-#define ErrRaster_Bad_Palette_Count 9
-
-
-#define Flow_Up 1
-#define Flow_Down -1
-
-#define SET_High_Precision( p ) Set_High_Precision( RAS_VAR_ p )
-
-
- /*************************************************************************/
- /* */
- /* Fast MulDiv, as `b' is always < 64. Don't use intermediate */
- /* precision. */
- /* */
-#define FMulDiv( a, b, c ) ( (a) * (b) / (c) )
-
-
- /*************************************************************************/
- /* */
- /* Define DEBUG_RASTER if you want to generate a debug version of the */
- /* rasterizer. This will progressively draw the glyphs while all the */
- /* computation are done directly on the graphics screen (the glyphs will */
- /* will be shown inverted). */
- /* */
- /* Note that DEBUG_RASTER should only be used for debugging with b/w */
- /* rendering, not with gray levels. */
- /* */
- /* The definition of DEBUG_RASTER should appear in the file */
- /* `ftconfig.h'. */
- /* */
-#ifdef DEBUG_RASTER
- extern char* vio; /* A pointer to VRAM or display buffer */
+#ifndef FAILURE
+#define FAILURE 1
#endif
- /*************************************************************************/
- /* */
- /* The maximum number of stacked Bezier curves. Setting this constant */
- /* to more than 32 is a pure waste of space. */
- /* */
-#define MaxBezier 32
-
-
- /*************************************************************************/
- /* */
- /* The number fractional bits of *input* coordinates. We always use the */
- /* 26.6 format (i.e, 6 bits for the fractional part), but hackers are */
- /* free to experiment with different values. */
- /* */
-#define INPUT_BITS 6
-
-
- /*************************************************************************/
- /* */
- /* An unsigned type that is exactly 32 bits on your platform. This */
- /* means `unsigned long' on 16-bit machines, and `unsigned int' on */
- /* others. */
- /* */
-#ifdef _STANDALONE_
-#if defined( FT_RASTER_INT_IS_32 )
- typedef unsigned int FT_Word32;
-#elif defined( FT_RASTER_LONG_IS_32 )
- typedef unsigned long FT_Word32;
-#else
-#error "no 32bit type found - please check your configuration"
-#endif
-#endif
-
+#define MaxBezier 32 /* The maximum number of stacked Bezier curves. */
+ /* Setting this constant to more than 32 is a */
+ /* pure waste of space. */
- /*************************************************************************/
- /* */
- /* A pointer to an unsigned char. */
- /* */
- typedef unsigned char Byte, *PByte;
- typedef int TResult;
+#define Pixel_Bits 6 /* fractional bits of *input* coordinates */
+ /****************************************************************/
+ /****************************************************************/
+ /** **/
+ /** SIMPLE TYPE DECLARATIONS **/
+ /** **/
+ /****************************************************************/
+ /****************************************************************/
+
+ typedef int Int;
+ typedef unsigned int UInt;
+ typedef short Short;
+ typedef unsigned short UShort, *PUShort;
+ typedef long Long, *PLong;
+ typedef unsigned long ULong;
+
+ typedef unsigned char Byte, *PByte;
+ typedef char Bool;
- /*************************************************************************/
- /* */
- /* The type of the pixel coordinates used within the render pool during */
- /* scan-line conversion. We use longs to store either 26.6 or 22.10 */
- /* fixed float values, depending on the `precision' we want to use */
- /* (i.e., low resp. high precision). These are ideals in order to */
- /* subdivise Bezier arcs in halves by simple additions and shifts. */
- /* */
- /* Note that this is an 8-bytes integer on 64 bits systems. */
- /* */
- typedef long TPos, *PPos;
+ typedef struct TPoint_
+ {
+ Long x;
+ Long y;
+
+ } TPoint;
- /*************************************************************************/
- /* */
- /* The type of a scanline position/coordinate within a map. */
- /* */
- typedef int TScan, *PScan;
+ typedef enum TFlow_
+ {
+ Flow_None = 0,
+ Flow_Up = 1,
+ Flow_Down = -1
+
+ } TFlow;
- /*************************************************************************/
- /* */
- /* States and directions of each line, arc, and profile. */
- /* */
- typedef enum _TDirection
+ /* States of each line, arc and profile */
+ typedef enum TStates_
{
Unknown,
Ascending,
Descending,
Flat
-
- } TDirection;
+
+ } TStates;
- struct _TProfile;
- typedef struct _TProfile TProfile;
+ typedef struct TProfile_ TProfile;
typedef TProfile* PProfile;
-
- /*************************************************************************/
- /* */
- /* The `master' structure used for decomposing outlines. */
- /* */
- struct _TProfile
+ struct TProfile_
{
- TPos X; /* current coordinate during sweep */
- PProfile link; /* link to next profile - various purpose */
- PPos offset; /* start of profile's data in render pool */
- int flow; /* Profile orientation: Asc/Descending */
- TScan height; /* profile's height in scanlines */
- TScan start; /* profile's starting scanline */
-
- TScan countL; /* number of lines to step before this */
- /* profile becomes drawable */
-
- PProfile next; /* next profile in same contour, used */
- /* during drop-out control */
+ FT_F26Dot6 X; /* current coordinate during sweep */
+ PProfile link; /* link to next profile - various purpose */
+ PLong offset; /* start of profile's data in render pool */
+ Int flow; /* Profile orientation: Asc/Descending */
+ Long height; /* profile's height in scanlines */
+ Long start; /* profile's starting scanline */
+
+ UShort countL; /* number of lines to step before this */
+ /* profile becomes drawable */
+
+ PProfile next; /* next profile in same contour, used */
+ /* during drop-out control */
};
typedef PProfile TProfileList;
typedef PProfile* PProfileList;
- /*************************************************************************/
- /* */
- /* A simple record used to implement a stack of bands, required by the */
- /* sub-banding mechanism. */
- /* */
- typedef struct _TBand
+ /* Simple record used to implement a stack of bands, required */
+ /* by the sub-banding mechanism */
+ typedef struct TBand_
{
- TScan y_min; /* band's minimum */
- TScan y_max; /* band's maximum */
-
+ Short y_min; /* band's minimum */
+ Short y_max; /* band's maximum */
+
} TBand;
- /*************************************************************************/
- /* */
- /* The size in _TPos_ of a profile record in the render pool. */
- /* */
-#define AlignProfileSize \
- ( (sizeof ( TProfile ) + sizeof ( TPos ) - 1) / sizeof ( TPos ) )
-
-
- /*************************************************************************/
- /* */
- /* Prototypes used for sweep function dispatch. */
- /* */
- typedef void (*Function_Sweep_Init)( RAS_ARG_ int* min,
- int* max );
-
- typedef void (*Function_Sweep_Span)( RAS_ARG_ TScan y,
- TPos x1,
- TPos x2 );
- typedef int (*Function_Test_Pixel)( RAS_ARG_ TScan y,
- int x );
+#define AlignProfileSize \
+ (( sizeof(TProfile)+sizeof(long)-1 ) / sizeof(long))
- typedef void (*Function_Set_Pixel)( RAS_ARG_ TScan y,
- int x,
- int color );
-
- typedef void (*Function_Sweep_Step)( RAS_ARG );
-
- typedef struct Raster_Render_
- {
- Function_Sweep_Init init;
- Function_Sweep_Span span;
- Function_Sweep_Step step;
- Function_Test_Pixel test_pixel;
- Function_Set_Pixel set_pixel;
- } Raster_Render;
+#ifdef TT_STATIC_RASTER
-#ifdef FT_RASTER_CONSTANT_PRECISION
+#define RAS_ARGS /* void */
+#define RAS_ARG /* void */
- #define PRECISION_BITS FT_PRECISION_BITS
- #define PRECISION (1 << PRECISION_BITS)
- #define PRECISION_MASK (-1L << PRECISION_BITS)
- #define PRECISION_HALF (PRECISION >> 1)
- #define PRECISION_JITTER (PRECISION >> 5)
- #define PRECISION_STEP PRECISION_HALF
+#define RAS_VARS /* void */
+#define RAS_VAR /* void */
#else
- #define PRECISION_BITS ras.precision_bits
- #define PRECISION ras.precision
- #define PRECISION_MASK ras.precision_mask
- #define PRECISION_HALF ras.precision_half
- #define PRECISION_JITTER ras.precision_jitter
- #define PRECISION_STEP ras.precision_step
-
-#endif
-
- /*************************************************************************/
- /* */
- /* Compute lowest integer coordinate below a given value. */
- /* */
-#define FLOOR( x ) ( (x) & PRECISION_MASK )
-
+#define RAS_ARGS TRaster_Instance* raster,
+#define RAS_ARG TRaster_Instance* raster
- /*************************************************************************/
- /* */
- /* Compute highest integer coordinate above a given value. */
- /* */
-#define CEILING( x ) ( ((x) + PRECISION - 1) & PRECISION_MASK )
+#define RAS_VARS raster,
+#define RAS_VAR raster
+#endif
- /*************************************************************************/
- /* */
- /* Get integer coordinate of a given 26.6 or 22.10 `x' coordinate -- no */
- /* rounding. */
- /* */
-#define TRUNC( x ) ( (signed long)(x) >> PRECISION_BITS )
+ typedef struct TRaster_Instance_ TRaster_Instance;
- /*************************************************************************/
- /* */
- /* Get the fractional part of a given coordinate. */
- /* */
-#define FRAC( x ) ( (x) & (PRECISION-1) )
+ /* prototypes used for sweep function dispatch */
+ typedef void Function_Sweep_Init( RAS_ARGS Short* min,
+ Short* max );
- /*************************************************************************/
- /* */
- /* Scale an `input coordinate' (as found in FT_Outline structures) into */
- /* a `work coordinate' which depends on current resolution and render */
- /* mode. */
- /* */
-#define SCALED( x ) ( ((x) << ras.scale_shift) - ras.scale_delta )
+ typedef void Function_Sweep_Span( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right );
-
- /*************************************************************************/
- /* */
- /* DEBUG_PSET is used to plot a single pixel in VRam during debug mode. */
- /* */
-#ifdef DEBUG_RASTER
-#define DEBUG_PSET Pset()
-#else
-#define DEBUG_PSET
-#endif
+ typedef void Function_Sweep_Step( RAS_ARG );
- /*************************************************************************/
- /* */
- /* This structure defines a point in a plane. */
- /* */
- typedef struct _TPoint
- {
- TPos x, y;
+/* NOTE: These operations are only valid on 2's complement processors */
- } TPoint;
+#define FLOOR( x ) ( (x) & -ras.precision )
+#define CEILING( x ) ( ((x) + ras.precision - 1) & -ras.precision )
+#define TRUNC( x ) ( (signed long)(x) >> ras.precision_bits )
+#define FRAC( x ) ( (x) & (ras.precision - 1) )
+#define SCALED( x ) ( ((x) << ras.scale_shift) - ras.precision_half )
+ /* Note that I have moved the location of some fields in the */
+ /* structure to ensure that the most used variables are used */
+ /* at the top. Thus, their offset can be coded with less */
+ /* opcodes, and it results in a smaller executable. */
- /*************************************************************************/
- /* */
- /* The most used variables are at the beginning of the structure. Thus, */
- /* their offset can be coded with less opcodes which results in a */
- /* smaller executable. */
- /* */
- struct FT_RasterRec_
+ struct TRaster_Instance_
{
- PPos cursor; /* Current cursor in render pool */
+ Int precision_bits; /* precision related variables */
+ Int precision;
+ Int precision_half;
+ Long precision_mask;
+ Int precision_shift;
+ Int precision_step;
+ Int precision_jitter;
- PPos pool; /* The render pool base address */
- PPos pool_size; /* The render pool's size */
- PPos pool_limit; /* Limit of profiles zone in pool */
+ Int scale_shift; /* == precision_shift for bitmaps */
+ /* == precision_shift+1 for pixmaps */
- int bit_width; /* target bitmap width */
- PByte bit_buffer; /* target bitmap buffer */
- PByte pix_buffer; /* target pixmap buffer */
+ PLong buff; /* The profiles buffer */
+ PLong sizeBuff; /* Render pool size */
+ PLong maxBuff; /* Profiles buffer size */
+ PLong top; /* Current cursor in buffer */
- TPoint last;
- long minY, maxY;
+ FT_Error error;
- int error;
+ Int numTurns; /* number of Y-turns in outline */
-#ifndef FT_RASTER_CONSTANT_PRECISION
- int precision_bits; /* precision related variables */
- int precision;
- int precision_half;
- long precision_mask;
- int precision_shift;
- int precision_step;
- int precision_jitter;
-#endif
-
- FT_Outline* outline;
+ TPoint* arc; /* current Bezier arc pointer */
- int n_points; /* number of points in current glyph */
- int n_contours; /* number of contours in current glyph */
- int n_extrema; /* number of `extrema' scanlines */
+ UShort bWidth; /* target bitmap width */
+ PByte bTarget; /* target bitmap buffer */
+ PByte gTarget; /* target pixmap buffer */
- TPoint* arc; /* current Bezier arc pointer */
+ Long lastX, lastY, minY, maxY;
- int num_profs; /* current number of profiles */
+ UShort num_Profs; /* current number of profiles */
- char fresh; /* signals a fresh new profile which */
- /* `start' field must be completed */
- char joint; /* signals that the last arc ended */
+ Bool fresh; /* signals a fresh new profile which */
+ /* 'start' field must be completed */
+ Bool joint; /* signals that the last arc ended */
/* exactly on a scanline. Allows */
/* removal of doublets */
- PProfile cur_prof; /* current profile */
- PProfile start_prof; /* head of linked list of profiles */
- PProfile first_prof; /* contour's first profile in case */
+ PProfile cProfile; /* current profile */
+ PProfile fProfile; /* head of linked list of profiles */
+ PProfile gProfile; /* contour's first profile in case */
/* of impact */
- TDirection state; /* rendering state */
+ TStates state; /* rendering state */
- FT_Bitmap target; /* description of target bit/pixmap */
- void* memory;
+ FT_Bitmap target; /* description of target bit/pixmap */
+ FT_Outline outline;
- int trace_bit; /* current offset in target bitmap */
- int trace_pix; /* current offset in target pixmap */
- int trace_incr; /* sweep's increment in target bitmap */
+ Long traceOfs; /* current offset in target bitmap */
+ Long traceG; /* current offset in target pixmap */
- /* dispatch variables */
+ Short traceIncr; /* sweep's increment in target bitmap */
- Raster_Render render;
+ Short gray_min_x; /* current min x during gray rendering */
+ Short gray_max_x; /* current max x during gray rendering */
- int scale_shift; /* == 0 for bitmaps */
- /* == 1 for 5-levels pixmaps */
- /* == 2 for 17-levels pixmaps */
+ /* dispatch variables */
- int scale_delta; /* ras.precision_half for bitmaps */
- /* 0 for pixmaps */
+ Function_Sweep_Init* Proc_Sweep_Init;
+ Function_Sweep_Span* Proc_Sweep_Span;
+ Function_Sweep_Span* Proc_Sweep_Drop;
+ Function_Sweep_Step* Proc_Sweep_Step;
- char dropout_mode; /* current drop_out control method */
+ Byte dropOutControl; /* current drop_out control method */
- char second_pass; /* indicates whether a horizontal pass */
+ Bool second_pass; /* indicates wether a horizontal pass */
/* should be performed to control drop-out */
/* accurately when calling Render_Glyph. */
/* Note that there is no horizontal pass */
/* during gray rendering. */
+ TPoint arcs[2 * MaxBezier + 1]; /* The Bezier stack */
- char flipped; /* this flag is set during the rendering to */
- /* indicate the second pass. */
+ TBand band_stack[16]; /* band stack used for sub-banding */
+ Int band_top; /* band stack top */
- TBand band_stack[16]; /* band stack used for sub-banding */
- int band_top; /* band stack top */
+ Int count_table[256]; /* Look-up table used to quickly count */
+ /* set bits in a gray 2x2 cell */
- TPoint arcs[2 * MaxBezier + 1]; /* The Bezier stack */
- };
+ void* memory;
+#ifdef FT_RASTER_OPTION_ANTI_ALIASING
+ Byte grays[5]; /* Palette of gray levels used for render */
-#ifdef DEBUG_RASTER
+ Byte gray_lines[RASTER_GRAY_LINES];
+ /* Intermediate table used to render the */
+ /* graylevels pixmaps. */
+ /* gray_lines is a buffer holding two */
+ /* monochrome scanlines */
+ Short gray_width; /* width in bytes of one monochrome */
+ /* intermediate scanline of gray_lines. */
+ /* Each gray pixel takes 2 bits long there */
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Pset */
- /* */
- /* <Description> */
- /* Used for debugging only. Plots a point in VRAM during rendering */
- /* (not afterwards). */
- /* */
- /* <Note> */
- /* This procedure relies on the value of cProfile->start, which may */
- /* not be set when Pset() is called sometimes. This will usually */
- /* result in a dot plotted on the first screen scanline (far away */
- /* from its original position). */
- /* */
- /* This `feature' reflects nothing wrong in the current */
- /* implementation, and the bitmap is rendered correctly, so don't */
- /* panic if you see `flying' dots in debugging mode. */
- /* */
- static
- void Pset( RAS_ARG )
- {
- long o;
- long x;
+ /* The gray_lines must hold 2 lines, thus with size */
+ /* in bytes of at least 'gray_width*2' */
- x = ras.cursor[-1];
+#endif /* FT_RASTER_ANTI_ALIASING */
+
+#if 0
+ PByte flags; /* current flags table */
+ PUShort outs; /* current outlines table */
+ FT_Vector* coords;
- switch ( ras.cur_prof->flow )
- {
- case FT_Flow_Up:
- o = Vio_ScanLineWidth *
- ( ras.cursor - ras.cur_prof->offset + ras.cur_prof->start ) +
- ( x / (PRECISION * 8) );
- break;
+ UShort nPoints; /* number of points in current glyph */
+ Short nContours; /* number of contours in current glyph */
+#endif
- case FT_Flow_Down:
- o = Vio_ScanLineWidth *
- ( ras.cur_prof->start - ras.cursor + ras.cur_prof->offset ) +
- ( x / (PRECISION * 8) );
- break;
- }
- if ( o > 0 )
- Vio[o] |= (unsigned)0x80 >> ( (x/PRECISION) & 7 );
- }
+ };
- static
- void Clear_Band( RAS_ARG_ TScan y1,
- TScan y2 )
- {
- MEM_Set( Vio + y1*Vio_ScanLineWidth, (y2-y1+1)*Vio_ScanLineWidth, 0 );
- }
+#ifdef FT_CONFIG_OPTION_STATIC_RASTER
-#endif /* DEBUG_RASTER */
+ static TRaster_Instance cur_ras;
+ #define ras cur_ras
+
+#else
+ #define ras (*raster)
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Set_High_Precision */
- /* */
- /* <Description> */
- /* Sets precision variables according to the parameter flag. */
- /* */
- /* <Input> */
- /* High :: Set to True for high precision (typically for ppem < 18), */
- /* false otherwise. */
- /* */
- static
- void Set_High_Precision( RAS_ARG_ char High )
+#endif /* FT_STATIC_RASTER */
+
+ /****************************************************************/
+ /****************************************************************/
+ /** **/
+ /** PROFILES COMPUTATION **/
+ /** **/
+ /****************************************************************/
+ /****************************************************************/
+
+
+/************************************************************************/
+/* */
+/* Function: Set_High_Precision */
+/* */
+/* Description: Sets precision variables according to param flag. */
+/* */
+/* Input: High set to True for high precision (typically for */
+/* ppem < 18), false otherwise. */
+/* */
+/************************************************************************/
+
+ static void Set_High_Precision( RAS_ARGS Int High )
{
-#ifdef FT_RASTER_CONSTANT_PRECISION
- (void)High;
- (void)&ras;
-#else
if ( High )
{
ras.precision_bits = 10;
@@ -748,206 +470,127 @@
ras.precision_jitter = 2;
}
+ FT_TRACE7(( "Set_High_Precision(%s)\n", High ? "true" : "false" ));
+
ras.precision = 1L << ras.precision_bits;
ras.precision_half = ras.precision / 2;
- ras.precision_shift = ras.precision_bits - INPUT_BITS;
+ ras.precision_shift = ras.precision_bits - Pixel_Bits;
ras.precision_mask = -ras.precision;
-#endif
}
- /*************************************************************************/
- /* */
- /* A simple technical note on how the raster works: */
- /* */
- /* Converting an outline into a bitmap is achieved in several steps */
- /* which are: */
- /* */
- /* 1 - Decomposing the outline into successive `profiles'. Each */
- /* profile is simply an array of scanline intersections on a given */
- /* dimension. A profile's main attributes are */
- /* */
- /* o its scanline position boundaries, i.e. `Ymin' and `Ymax'. */
- /* */
- /* o an array of intersection coordinates for each scanline */
- /* between `Ymin' and `Ymax'. */
- /* */
- /* o a direction, indicating wether is was built going `up' or */
- /* `down', as this is very important for filling rules. */
- /* */
- /* 2 - Sweeping the target map's scanlines in order to compute segment */
- /* `spans' which are then filled. Additionaly, this pass performs */
- /* drop-out control. */
- /* */
- /* The outline data is parsed during step 1 only. The profiles are */
- /* built from the bottom of the render pool, used as a stack. The */
- /* following graphics shows the profile list under construction: */
- /* */
- /* ____________________________________________________________ _ _ */
- /* | | | | | */
- /* | profile | coordinates for | profile | coordinates for |--> */
- /* | 1 | profile 1 | 2 | profile 2 |--> */
- /* |_________|___________________|_________|_________________|__ _ _ */
- /* */
- /* ^ ^ */
- /* | | */
- /* start of render pool cursor */
- /* */
- /* The top of the profile stack is kept in the `cursor' variable. */
- /* */
- /* As you can see, a profile record is pushed on top of the render */
- /* pool, which is then followed by its coordinates/intersections. If */
- /* a change of direction is detected in the outline, a new profile is */
- /* generated until the end of the outline. */
- /* */
- /* Note that when all profiles have been generated, the function */
- /* Finalize_Profile_Table() is used to record, for each profile, its */
- /* bottom-most scanline as well as the scanline above its upmost */
- /* boundary. These positions are called `extrema' because they (sort */
- /* of) correspond to local extrema. They are stored in a sorted list */
- /* built from the top of the render pool as a downwards stack: */
- /* */
- /* _ _ _______________________________________ */
- /* | | */
- /* <--| sorted list of | */
- /* <--| extrema scanlines | */
- /* _ _ __________________|____________________| */
- /* */
- /* ^ ^ */
- /* | | */
- /* pool_limit end of render pool */
- /* */
- /* This list is later used during the sweep phase in order to */
- /* optimize performance (see technical note on the sweep below). */
- /* */
- /* Of course, the raster detects whether the two stacks collide and */
- /* handles the situation propertly. */
- /* */
- /*************************************************************************/
+/****************************************************************************/
+/* */
+/* Function: New_Profile */
+/* */
+/* Description: Creates a new Profile in the render pool. */
+/* */
+/* Input: aState state/orientation of the new Profile */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE in case of overflow or of incoherent Profile. */
+/* */
+/****************************************************************************/
- /*************************************************************************/
- /* */
- /* <Function> */
- /* New_Profile */
- /* */
- /* <Description> */
- /* Creates a new Profile in the render pool. */
- /* */
- /* <Input> */
- /* aState :: The state/orientation of the new profile. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult New_Profile( RAS_ARG_ TDirection direction )
+ static Bool New_Profile( RAS_ARGS TStates aState )
{
- if ( ras.start_prof == NULL )
+ if ( !ras.fProfile )
{
- ras.cur_prof = (PProfile)ras.cursor; /* current profile */
- ras.start_prof = ras.cur_prof; /* first profile in pool */
- ras.cursor += AlignProfileSize; /* record profile in buffer */
+ ras.cProfile = (PProfile)ras.top;
+ ras.fProfile = ras.cProfile;
+ ras.top += AlignProfileSize;
}
- /* check for overflow */
- if ( ras.cursor >= ras.pool_limit )
+ if ( ras.top >= ras.maxBuff )
{
- ras.error = ErrRaster_Overflow;
+ ras.error = Raster_Err_Overflow;
return FAILURE;
}
- /* record profile direction */
- switch ( direction )
+ switch ( aState )
{
case Ascending:
- ras.cur_prof->flow = Flow_Up;
+ ras.cProfile->flow = Flow_Up;
+ FT_TRACE7(( "New ascending profile = %lx\n", (long)ras.cProfile ));
break;
case Descending:
- ras.cur_prof->flow = Flow_Down;
+ ras.cProfile->flow = Flow_Down;
+ FT_TRACE7(( "New descending profile = %lx\n", (long)ras.cProfile ));
break;
default:
- ras.error = ErrRaster_Invalid_Map;
+ FT_ERROR(( "Invalid profile direction in Raster:New_Profile !!\n" ));
+ ras.error = Raster_Err_Invalid;
return FAILURE;
}
- /* initialize a few fields */
- {
- PProfile cur = ras.cur_prof;
-
-
- cur->start = 0; /* current start scanline */
- cur->height = 0; /* current height */
- cur->offset = ras.cursor; /* address of first coordinate */
- cur->link = (PProfile)0; /* link to next profile in pool */
- cur->next = (PProfile)0; /* link to next profile in contour */
- }
+ ras.cProfile->start = 0;
+ ras.cProfile->height = 0;
+ ras.cProfile->offset = ras.top;
+ ras.cProfile->link = (PProfile)0;
+ ras.cProfile->next = (PProfile)0;
- /* record the first profile in a contour */
- if ( ras.first_prof == NULL )
- ras.first_prof = ras.cur_prof;
+ if ( !ras.gProfile )
+ ras.gProfile = ras.cProfile;
- ras.state = direction;
- ras.fresh = TRUE; /* this profile has no coordinates yet */
- ras.joint = FALSE;
+ ras.state = aState;
+ ras.fresh = TRUE;
+ ras.joint = FALSE;
return SUCCESS;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* End_Profile */
- /* */
- /* <Description> */
- /* Finalizes the current Profile and computes its height. If it is */
- /* not 0, the profile's fields are updated and a new profile is */
- /* pushed on top of its coordinates. Otherwise the current profile */
- /* is kept and the recording of intersections is restarted. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult End_Profile( RAS_ARG )
+/****************************************************************************/
+/* */
+/* Function: End_Profile */
+/* */
+/* Description: Finalizes the current Profile. */
+/* */
+/* Input: None */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE in case of overflow or incoherency. */
+/* */
+/****************************************************************************/
+
+ static Bool End_Profile( RAS_ARG )
{
- int h;
+ Long h;
+ PProfile oldProfile;
- h = ras.cursor - ras.cur_prof->offset;
+ h = ras.top - ras.cProfile->offset;
if ( h < 0 )
{
- /* This error should _never_ occur unless the raster is buggy */
- ras.error = ErrRaster_Negative_Height;
+ FT_ERROR(( "Negative height encountered in End_Profile!\n" ));
+ ras.error = Raster_Err_Neg_Height;
return FAILURE;
}
if ( h > 0 )
{
- PProfile old, new;
-
- /* record scanline height in current profile, create a new one */
- /* and set a link from the old one to it */
- old = ras.cur_prof;
- old->height = h;
- ras.cur_prof = new = (PProfile)ras.cursor;
+ FT_TRACE1(( "Ending profile %lx, start = %ld, height = %ld\n",
+ (long)ras.cProfile, ras.cProfile->start, h ));
- ras.cursor += AlignProfileSize;
+ oldProfile = ras.cProfile;
+ ras.cProfile->height = h;
+ ras.cProfile = (PProfile)ras.top;
- new->height = 0;
- new->offset = ras.cursor;
- old->next = new;
+ ras.top += AlignProfileSize;
- ras.num_profs++;
+ ras.cProfile->height = 0;
+ ras.cProfile->offset = ras.top;
+ oldProfile->next = ras.cProfile;
+ ras.num_Profs++;
}
- /* check for overflow */
- if ( ras.cursor >= ras.pool_limit )
+ if ( ras.top >= ras.maxBuff )
{
- ras.error = ErrRaster_Overflow;
+ FT_TRACE1(( "overflow in End_Profile\n" ));
+ ras.error = Raster_Err_Overflow;
return FAILURE;
}
@@ -957,85 +600,81 @@
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Insert_Extrema */
- /* */
- /* <Description> */
- /* Records that a given scanline contains at least one local */
- /* extremum. The table of extrema is placed at the end of the render */
- /* pool and grows downwards. It is used during the sweep phase. */
- /* */
- /* <Input> */
- /* y :: The coordinate of the scanline containing an extremum. */
- /* */
+/****************************************************************************/
+/* */
+/* Function: Insert_Y_Turn */
+/* */
+/* Description: Insert a salient into the sorted list placed on top */
+/* of the render pool */
+/* */
+/* Input: New y scanline position */
+/* */
+/****************************************************************************/
+
static
- TResult Insert_Extrema( RAS_ARG_ TScan y )
+ Bool Insert_Y_Turn( RAS_ARGS Int y )
{
- PPos extrema;
- TScan y2;
- int n;
-
+ PLong y_turns;
+ Int y2, n;
- FT_TRACE2(( "EXTREMA += %d", y ));
- n = ras.n_extrema - 1;
- extrema = ras.pool_size - ras.n_extrema;
+ n = ras.numTurns-1;
+ y_turns = ras.sizeBuff - ras.numTurns;
- /* look for first y extremum that is <= */
- while ( n >= 0 && y < extrema[n] )
+ /* look for first y value that is <= */
+ while ( n >= 0 && y < y_turns[n] )
n--;
/* if it is <, simply insert it, ignore if == */
- if ( n >= 0 && y > extrema[n] )
+ if ( n >= 0 && y > y_turns[n] )
while ( n >= 0 )
{
- y2 = extrema[n];
- extrema[n] = y;
+ y2 = y_turns[n];
+ y_turns[n] = y;
y = y2;
n--;
}
if ( n < 0 )
{
- ras.pool_limit--;
- ras.n_extrema++;
- ras.pool_size[-ras.n_extrema] = y;
-
- if ( ras.pool_limit <= ras.cursor )
+ if (ras.maxBuff <= ras.top)
{
- ras.error = ErrRaster_Overflow;
+ ras.error = Raster_Err_Overflow;
return FAILURE;
}
+ ras.maxBuff--;
+ ras.numTurns++;
+ ras.sizeBuff[-ras.numTurns] = y;
}
+
return SUCCESS;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Finalize_Profile_Table */
- /* */
- /* <Description> */
- /* Adjusts all links in the profiles list. Called when the outline */
- /* parsing is done. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
+/****************************************************************************/
+/* */
+/* Function: Finalize_Profile_Table */
+/* */
+/* Description: Adjusts all links in the Profiles list. */
+/* */
+/* Input: None */
+/* */
+/* Returns: None. */
+/* */
+/****************************************************************************/
+
static
- TResult Finalize_Profile_Table( RAS_ARG )
+ Bool Finalize_Profile_Table( RAS_ARG )
{
- int n, bottom, top;
+ Int bottom, top;
+ UShort n;
PProfile p;
- n = ras.num_profs;
+ n = ras.num_Profs;
if ( n > 1 )
{
- p = ras.start_prof;
+ p = ras.fProfile;
while ( n > 0 )
{
if ( n > 1 )
@@ -1045,25 +684,21 @@
switch ( p->flow )
{
- case Flow_Down:
- FT_TRACE2(( "FLOW DOWN (start = %d, height = %d)",
- p->start, p->height ));
- bottom = p->start - p->height+1;
- top = p->start;
- p->start = bottom;
- p->offset += p->height-1;
- break;
-
- case Flow_Up:
- default:
- FT_TRACE2(( "FLOW UP (start = %d, height = %d)",
- p->start, p->height ));
- bottom = p->start;
- top = p->start + p->height-1;
+ case Flow_Down:
+ bottom = p->start - p->height+1;
+ top = p->start;
+ p->start = bottom;
+ p->offset += p->height-1;
+ break;
+
+ case Flow_Up:
+ default:
+ bottom = p->start;
+ top = p->start + p->height-1;
}
- if ( Insert_Extrema( RAS_VAR_ bottom ) ||
- Insert_Extrema( RAS_VAR_ top+1 ) )
+ if ( Insert_Y_Turn( RAS_VARS bottom ) ||
+ Insert_Y_Turn( RAS_VARS top+1 ) )
return FAILURE;
p = p->link;
@@ -1071,55 +706,117 @@
}
}
else
- ras.start_prof = NULL;
+ ras.fProfile = NULL;
return SUCCESS;
}
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /**** ****/
- /**** ****/
- /**** COMPUTE SCAN-LINE INTERSECTIONS FROM SEGMENTS ****/
- /**** ****/
- /**** ****/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
+
+/****************************************************************************/
+/* */
+/* Function: Split_Conic */
+/* */
+/* Description: Subdivides one conic bezier into two joint */
+/* sub-arcs in the Bezier stack. */
+/* */
+/* Input: None (subdivided bezier is taken from the top of the */
+/* stack). */
+/* */
+/* Returns: None. */
+/* */
+/* */
+/* Note: This routine is the 'beef' of this component. It is _the_ */
+/* inner loop that should be optimized to hell to get the */
+/* best performance. */
+/* */
+/****************************************************************************/
+
+ static void Split_Conic( TPoint* base )
+ {
+ Long a, b;
+
+
+ base[4].x = base[2].x;
+ b = base[1].x;
+ a = base[3].x = ( base[2].x + b ) / 2;
+ b = base[1].x = ( base[0].x + b ) / 2;
+ base[2].x = ( a + b ) / 2;
+
+ base[4].y = base[2].y;
+ b = base[1].y;
+ a = base[3].y = ( base[2].y + b ) / 2;
+ b = base[1].y = ( base[0].y + b ) / 2;
+ base[2].y = ( a + b ) / 2;
+
+ /* hand optimized. gcc doesn't seem too good at common expression */
+ /* substitution and instruction scheduling ;-) */
+ }
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> Split_Cubic */
+ /* */
+ /* <Description> */
+ /* Subdivides a third-order Bezier arc into two joint sub-arcs in */
+ /* the Bezier stack. */
+ /* */
+ /* <Note> */
+ /* This routine is the `beef' of the component. It is one of _the_ */
+ /* inner loops that should be optimized like hell to get the best */
+ /* performance. */
+ /* */
+ static
+ void Split_Cubic( TPoint* base )
+ {
+ Long a, b, c, d;
+
+ base[6].x = base[3].x;
+ c = base[1].x;
+ d = base[2].x;
+ base[1].x = a = ( base[0].x + c + 1 ) >> 1;
+ base[5].x = b = ( base[3].x + d + 1 ) >> 1;
+ c = ( c + d + 1 ) >> 1;
+ base[2].x = a = ( a + c + 1 ) >> 1;
+ base[4].x = b = ( b + c + 1 ) >> 1;
+ base[3].x = ( a + b + 1 ) >> 1;
+
+ base[6].y = base[3].y;
+ c = base[1].y;
+ d = base[2].y;
+ base[1].y = a = ( base[0].y + c + 1 ) >> 1;
+ base[5].y = b = ( base[3].y + d + 1 ) >> 1;
+ c = ( c + d + 1 ) >> 1;
+ base[2].y = a = ( a + c + 1 ) >> 1;
+ base[4].y = b = ( b + c + 1 ) >> 1;
+ base[3].y = ( a + b + 1 ) >> 1;
+ }
+
+/****************************************************************************/
+/* */
+/* Function: Line_Up */
+/* */
+/* Description: Computes the x-coordinates of an ascending line segment */
+/* and stores them in the render pool. */
+/* */
+/* Input: x1,y1,x2,y2 Segment start (x1,y1) and end (x2,y2) points */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE on Render Pool overflow. */
+/* */
+/****************************************************************************/
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Line_Up */
- /* */
- /* <Description> */
- /* Computes the scan-line intersections of an ascending line segment */
- /* and stores them in the render pool. */
- /* */
- /* <Input> */
- /* x1 :: The start x coordinate. */
- /* y1 :: The start y coordinate. */
- /* x2 :: The end x coordinate. */
- /* y2 :: The end y coordinate. */
- /* miny :: The minimum vertical grid coordinate. */
- /* maxy :: The maximum vertical grid coordinate. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult Line_Up( RAS_ARG_ TPos x1, TPos y1,
- TPos x2, TPos y2,
- TPos miny, TPos maxy )
+ static Bool Line_Up( RAS_ARGS Long x1, Long y1,
+ Long x2, Long y2,
+ Long miny, Long maxy )
{
- TPos Dx, Dy;
- int e1, e2, f1, f2, size;
- TPos Ix, Rx, Ax;
+ Long Dx, Dy;
+ Int e1, e2, f1, f2, size; /* XXX: is `Short' sufficient? */
+ Long Ix, Rx, Ax;
- PPos top;
+ PLong top;
Dx = x2 - x1;
@@ -1128,335 +825,165 @@
if ( Dy <= 0 || y2 < miny || y1 > maxy )
return SUCCESS;
- /* clip to higher scanline when necessary */
- if ( y2 > maxy )
+ if ( y1 < miny )
{
- /* x2 += FMulDiv( Dx, maxy-y2, Dy ); UNNECESSARY */
- e2 = TRUNC( maxy );
- f2 = 0;
+ /* Take care : miny-y1 can be a very large value, we use */
+ /* a slow MulDiv function to avoid clipping bugs */
+ x1 += SMulDiv( Dx, miny - y1, Dy );
+ e1 = TRUNC( miny );
+ f1 = 0;
}
else
{
- e2 = TRUNC( y2 );
- f2 = FRAC( y2 );
+ e1 = TRUNC( y1 );
+ f1 = FRAC( y1 );
}
- /* clip to lower scanline when necessary */
- if ( y1 < miny )
+ if ( y2 > maxy )
{
-#ifdef OLD
- x1 += FT_MulDiv( Dx, miny-y1, Dy );
- e1 = TRUNC( miny );
- f1 = 0;
-#else
- TPos x, y;
-
- /* we use a binary search to compute the lower
- // clipping intersection. That's because we don't
- // want to use an external function like FT_MulDiv
- // to compute it directly.
- */
- if ( y2 == miny ) goto Exit;
- do
- {
- x = (x1 + x2) >> 1;
- y = (y1 + y2) >> 1;
-
- if (y <= miny)
- {
- x1 = x;
- y1 = y;
- }
- else
- {
- x2 = x;
- y2 = y;
- }
- }
- while ( y1 < miny );
-
- e1 = TRUNC( miny );
- f1 = 0;
-#endif
+ /* x2 += FMulDiv( Dx, maxy - y2, Dy ); UNNECESSARY */
+ e2 = TRUNC( maxy );
+ f2 = 0;
}
else
{
- e1 = TRUNC( y1 );
- f1 = FRAC( y1 );
+ e2 = TRUNC( y2 );
+ f2 = FRAC( y2 );
}
- /* adjust start point so that we begin on an integer scanline position */
if ( f1 > 0 )
{
- if ( e1 == e2 ) goto Exit;
+ if ( e1 == e2 ) return SUCCESS;
else
{
- x1 += FMulDiv( Dx, PRECISION - f1, Dy );
+ x1 += FMulDiv( Dx, ras.precision - f1, Dy );
e1 += 1;
}
}
else
if ( ras.joint )
{
- ras.cursor--;
+ ras.top--;
ras.joint = FALSE;
}
ras.joint = ( f2 == 0 );
- /* if this is a `fresh' profile, record its starting scanline */
if ( ras.fresh )
{
- ras.cur_prof->start = e1;
+ ras.cProfile->start = e1;
ras.fresh = FALSE;
}
- /* check for overflow */
size = e2 - e1 + 1;
- if ( ras.cursor + size >= ras.pool_limit )
+ if ( ras.top + size >= ras.maxBuff )
{
- ras.error = ErrRaster_Overflow;
+ ras.error = Raster_Err_Overflow;
return FAILURE;
}
-#ifdef OLD
if ( Dx > 0 )
{
- Ix = ( PRECISION*Dx ) / Dy;
- Rx = ( PRECISION*Dx ) % Dy;
+ Ix = (ras.precision*Dx) / Dy;
+ Rx = (ras.precision*Dx) % Dy;
Dx = 1;
}
else
{
- Ix = -( (PRECISION*-Dx) / Dy );
- Rx = (PRECISION*-Dx) % Dy;
+ Ix = -( (ras.precision*-Dx) / Dy );
+ Rx = (ras.precision*-Dx) % Dy;
Dx = -1;
}
-
- Ax = -Dy;
-#else
- /* compute decision variables and push the intersections on top */
- /* of the render pool */
- Dx <<= PRECISION_BITS;
- Ix = Dx / Dy;
- Rx = Dx % Dy;
- if (Rx < 0)
- {
- Ix --;
- Rx += Dy;
- }
-
- Ax = -Dy;
- Rx <<= 1;
- Dy <<= 1;
-#endif
- top = ras.cursor;
+ Ax = -Dy;
+ top = ras.top;
while ( size > 0 )
{
*top++ = x1;
- DEBUG_PSET;
-
x1 += Ix;
Ax += Rx;
if ( Ax >= 0 )
{
Ax -= Dy;
-#ifdef OLD
x1 += Dx;
-#else
- x1 ++;
-#endif
}
size--;
}
- ras.cursor = top;
- Exit:
+ ras.top = top;
return SUCCESS;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Line_Down */
- /* */
- /* <Description> */
- /* Computes the scan-line intersections of a descending line segment */
- /* and stores them in the render pool. */
- /* */
- /* <Input> */
- /* x1 :: The start x coordinate. */
- /* y1 :: The start y coordinate. */
- /* x2 :: The end x coordinate. */
- /* y2 :: The end y coordinate. */
- /* miny :: The minimum vertical grid coordinate. */
- /* maxy :: The maximum vertical grid coordinate. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult Line_Down( RAS_ARG_ TPos x1, TPos y1,
- TPos x2, TPos y2,
- TPos miny, TPos maxy )
+ static Bool Line_Down( RAS_ARGS Long x1, Long y1,
+ Long x2, Long y2,
+ Long miny, Long maxy )
{
- TResult result, fresh;
+ Bool result, fresh;
- /* simply invert the coordinates and call Line_Up */
fresh = ras.fresh;
- result = Line_Up( RAS_VAR_ x1, -y1, x2, -y2, -maxy, -miny );
- /* if this was a fresh profile, invert the recorded start position */
+ result = Line_Up( RAS_VARS x1, -y1, x2, -y2, -maxy, -miny );
+
if ( fresh && !ras.fresh )
- ras.cur_prof->start = -ras.cur_prof->start;
+ ras.cProfile->start = -ras.cProfile->start;
return result;
}
-
+/****************************************************************************/
+/* */
+/* Function: Bezier_Up */
+/* */
+/* Description: Computes thes x-coordinates of an ascending bezier arc */
+/* and stores them in the render pool. */
+/* */
/* A function type describing the functions used to split bezier arcs */
typedef void (*TSplitter)( TPoint* base );
-#ifdef FT_DYNAMIC_BEZIER_STEPS
- static
- TPos Dynamic_Bezier_Threshold( RAS_ARG_ int degree, TPoint* arc )
- {
- TPos min_x, max_x, min_y, max_y, A, B;
- TPos wide_x, wide_y, threshold;
- TPoint* cur = arc;
- TPoint* limit = cur + degree;
-
- /* first of all, set the threshold to the maximum x or y extent */
- min_x = max_x = arc[0].x;
- min_y = max_y = arc[0].y;
- cur++;
- for ( ; cur < limit; cur++ )
- {
- TPos x = cur->x;
- TPos y = cur->y;
-
- if ( x < min_x ) min_x = x;
- if ( x > max_x ) max_x = x;
-
- if ( y < min_y ) min_y = y;
- if ( y > max_y ) max_y = y;
- }
- wide_x = (max_x - min_x) << 4;
- wide_y = (max_y - min_y) << 4;
-
- threshold = wide_x;
- if (threshold < wide_y) threshold = wide_y;
-
- /* now compute the second and third order error values */
-
- wide_x = arc[0].x + arc[1].x - arc[2].x*2;
- wide_y = arc[0].y + arc[1].y - arc[2].y*2;
-
- if (wide_x < 0) wide_x = -wide_x;
- if (wide_y < 0) wide_y = -wide_y;
-
- A = wide_x; if ( A < wide_y ) A = wide_y;
-
- if (degree >= 3)
- {
- wide_x = arc[3].x - arc[0].x + 3*(arc[2].x - arc[3].x);
- wide_y = arc[3].y - arc[0].y + 3*(arc[2].y - arc[3].y);
-
- if (wide_x < 0) wide_x = -wide_x;
- if (wide_y < 0) wide_y = -wide_y;
-
- B = wide_x; if ( B < wide_y ) B = wide_y;
- }
- else
- B = 0;
-
- while ( A > 0 || B > 0 )
- {
- threshold >>= 1;
- A >>= 2;
- B >>= 3;
- }
-
- if (threshold < PRECISION_STEP)
- threshold = PRECISION_STEP;
-
- return threshold;
- }
-#endif
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Bezier_Up */
- /* */
- /* <Description> */
- /* Computes the scan-line intersections of an ascending second-order */
- /* Bezier arc and stores them in the render pool. The arc is taken */
- /* from the top of the stack. */
- /* */
- /* <Input> */
- /* miny :: The minimum vertical grid coordinate. */
- /* maxy :: The maximum vertical grid coordinate. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult Bezier_Up( RAS_ARG_ int degree,
- TSplitter splitter,
- TPos miny,
- TPos maxy )
+ static Bool Bezier_Up( RAS_ARGS Int degree,
+ TSplitter splitter,
+ Long miny,
+ Long maxy )
{
- TPos y1, y2, e, e2, e0, threshold;
- int f1;
+ Long y1, y2, e, e2, e0;
+ Short f1;
TPoint* arc;
TPoint* start_arc;
- PPos top;
+ PLong top;
arc = ras.arc;
y1 = arc[degree].y;
y2 = arc[0].y;
- top = ras.cursor;
+ top = ras.top;
if ( y2 < miny || y1 > maxy )
goto Fin;
- e2 = FLOOR( y2 ); /* integer end y */
+ e2 = FLOOR( y2 );
-#ifdef OLD
if ( e2 > maxy )
e2 = maxy;
-
- e0 = miny;
-#else
- if ( e2 > maxy )
- e2 = FLOOR(maxy);
-
- e0 = CEILING(miny);
-#endif
+ e0 = miny;
if ( y1 < miny )
- {
- e = e0; /* integer start y == current scanline */
- }
+ e = miny;
else
{
- e = CEILING( y1 ); /* integer start y == current scanline */
- f1 = FRAC( y1 ); /* fractional shift of start y */
- e0 = e; /* first integer scanline to be pushed */
+ e = CEILING( y1 );
+ f1 = FRAC( y1 );
+ e0 = e;
- if ( f1 == 0 ) /* do we start on an integer scanline? */
+ if ( f1 == 0 )
{
if ( ras.joint )
{
@@ -1464,517 +991,206 @@
ras.joint = FALSE;
}
- *top++ = arc[degree].x; /* write directly start position */
+ *top++ = arc[degree].x;
- DEBUG_PSET;
-
- e += PRECISION; /* go to next scanline */
+ e += ras.precision;
}
}
- /* record start position if necessary */
if ( ras.fresh )
{
- ras.cur_prof->start = TRUNC( e0 );
+ ras.cProfile->start = TRUNC( e0 );
ras.fresh = FALSE;
}
- /* exit if the current scanline is already above the max scanline */
if ( e2 < e )
goto Fin;
- /* check for overflow */
- if ( ( top + TRUNC( e2 - e ) + 1 ) >= ras.pool_limit )
+ if ( ( top + TRUNC( e2 - e ) + 1 ) >= ras.maxBuff )
{
- ras.cursor = top;
- ras.error = ErrRaster_Overflow;
+ ras.top = top;
+ ras.error = Raster_Err_Overflow;
return FAILURE;
}
-
-#ifdef FT_DYNAMIC_BEZIER_STEPS
- /* compute dynamic bezier step threshold */
- threshold = Dynamic_Bezier_Threshold( RAS_VAR_ degree, arc );
-#else
- threshold = PRECISION_STEP;
-#endif
-
start_arc = arc;
- /* loop while there is still an arc on the bezier stack */
- /* and the current scan line is below y max == e2 */
while ( arc >= start_arc && e <= e2 )
{
ras.joint = FALSE;
- y2 = arc[0].y; /* final y of the top-most arc */
+ y2 = arc[0].y;
- if ( y2 > e ) /* the arc intercepts the current scanline */
+ if ( y2 > e )
{
- y1 = arc[degree].y; /* start y of top-most arc */
-
-#ifdef OLD
- if ( y2-y1 >= PRECISION_STEP )
-#else
- if ( y2 >= e + PRECISION || y2 - y1 >= threshold )
-#endif
+ y1 = arc[degree].y;
+ if ( y2 - y1 >= ras.precision_step )
{
- /* if the arc's height is too great, split it */
splitter( arc );
arc += degree;
}
else
{
- /* otherwise, approximate it as a segment and compute */
- /* its intersection with the current scanline */
- *top++ = arc[degree].x +
- FMulDiv( arc[0].x-arc[degree].x,
- e - y1,
- y2 - y1 );
-
- DEBUG_PSET;
-
- arc -= degree; /* pop the arc */
- e += PRECISION; /* go to next scanline */
+ *top++ = arc[degree].x + FMulDiv( arc[0].x-arc[degree].x,
+ e - y1, y2 - y1 );
+ arc -= degree;
+ e += ras.precision;
}
}
else
{
- if ( y2 == e ) /* if the arc falls on the scanline */
- { /* record its _joint_ intersection */
- ras.joint = TRUE;
- *top++ = arc[0].x;
-
- DEBUG_PSET;
-
- e += PRECISION; /* go to next scanline */
- }
- arc -= degree; /* pop the arc */
- }
- }
-
- Fin:
- ras.cursor = top;
- ras.arc -= degree;
- return SUCCESS;
- }
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Bezier_Down */
- /* */
- /* <Description> */
- /* Computes the scan-line intersections of a descending second-order */
- /* Bezier arc and stores them in the render pool. The arc is taken */
- /* from the top of the stack. */
- /* */
- /* <Input> */
- /* miny :: The minimum vertical grid coordinate. */
- /* maxy :: The maximum vertical grid coordinate. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult Bezier_Down( RAS_ARG_ int degree,
- TSplitter splitter,
- TPos miny,
- TPos maxy )
- {
- TPoint* arc = ras.arc;
- TResult result, fresh;
-
- arc[0].y = -arc[0].y;
- arc[1].y = -arc[1].y;
- arc[2].y = -arc[2].y;
- if (degree > 2)
- arc[3].y = -arc[3].y;
-
- fresh = ras.fresh;
-
- result = Bezier_Up( RAS_VAR_ degree, splitter, -maxy, -miny );
-
- if ( fresh && !ras.fresh )
- ras.cur_prof->start = -ras.cur_prof->start;
-
- arc[0].y = -arc[0].y;
- return result;
- }
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /**** ****/
- /**** ****/
- /**** SPLITTING CONIC AND CUBIC BEZIERS IN HALF ****/
- /**** ****/
- /**** ****/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
-#ifdef FT_RASTER_CONIC_BEZIERS
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Split_Conic */
- /* */
- /* <Description> */
- /* Subdivides one second-order Bezier arc into two joint sub-arcs in */
- /* the Bezier stack. */
- /* */
- /* <Note> */
- /* This routine is the `beef' of the component. It is one of _the_ */
- /* inner loops that should be optimized like hell to get the best */
- /* performance. */
- /* */
- static
- void Split_Conic( TPoint* base )
- {
- TPos a, b;
-
-
- base[4].x = base[2].x;
- b = base[1].x;
- a = base[3].x = ( base[2].x + b + 1 ) >> 1;
- b = base[1].x = ( base[0].x + b + 1 ) >> 1;
- base[2].x = ( a + b + 1 ) >> 1;
-
- base[4].y = base[2].y;
- b = base[1].y;
- a = base[3].y = ( base[2].y + b + 1 ) >> 1;
- b = base[1].y = ( base[0].y + b + 1 ) >> 1;
- base[2].y = ( a + b ) / 2;
- }
-
-#endif
-
-#ifdef FT_RASTER_CUBIC_BEZIERS
-
- /*************************************************************************/
- /* */
- /* <Function> Split_Cubic */
- /* */
- /* <Description> */
- /* Subdivides a third-order Bezier arc into two joint sub-arcs in */
- /* the Bezier stack. */
- /* */
- /* <Note> */
- /* This routine is the `beef' of the component. It is one of _the_ */
- /* inner loops that should be optimized like hell to get the best */
- /* performance. */
- /* */
- static
- void Split_Cubic( TPoint* base )
- {
- TPos a, b, c, d;
-
-
- base[6].x = base[3].x;
- c = base[1].x;
- d = base[2].x;
- base[1].x = a = ( base[0].x + c + 1 ) >> 1;
- base[5].x = b = ( base[3].x + d + 1 ) >> 1;
- c = ( c + d + 1 ) >> 1;
- base[2].x = a = ( a + c + 1 ) >> 1;
- base[4].x = b = ( b + c + 1 ) >> 1;
- base[3].x = ( a + b + 1 ) >> 1;
-
- base[6].y = base[3].y;
- c = base[1].y;
- d = base[2].y;
- base[1].y = a = ( base[0].y + c + 1 ) >> 1;
- base[5].y = b = ( base[3].y + d + 1 ) >> 1;
- c = ( c + d + 1 ) >> 1;
- base[2].y = a = ( a + c + 1 ) >> 1;
- base[4].y = b = ( b + c + 1 ) >> 1;
- base[3].y = ( a + b + 1 ) >> 1;
- }
-
-#endif /* FT_RASTER_CUBIC_BEZIERS */
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /**** ****/
- /**** ****/
- /**** PROCESSING OUTLINE SEGMENTS ****/
- /**** ****/
- /**** ****/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Check_Contour */
- /* */
- /* <Description> */
- /* Performs some checks at contour closure. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult Check_Contour( RAS_ARG )
- {
- PProfile lastProfile;
-
- /* Sometimes, the first and last profile in a contour join on */
- /* an integer scan-line; we must then remove the last intersection */
- /* from the last profile to get rid of doublets */
- if ( ( FRAC( ras.last.y ) == 0 &&
- ras.last.y >= ras.minY &&
- ras.last.y <= ras.maxY ) )
- {
- if ( ras.first_prof && ras.first_prof->flow == ras.cur_prof->flow )
- ras.cursor--;
- }
-
- lastProfile = ras.cur_prof;
- if ( End_Profile( RAS_VAR ) )
- return FAILURE;
+ if ( y2 == e )
+ {
+ ras.joint = TRUE;
+ *top++ = arc[0].x;
- /* close the `next profile in contour' linked list */
- lastProfile->next = ras.first_prof;
+ e += ras.precision;
+ }
+ arc -= degree;
+ }
+ }
+ Fin:
+ ras.top = top;
+ ras.arc -= degree;
return SUCCESS;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Move_To */
- /* */
- /* <Description> */
- /* This function injects a new contour in the render pool. */
- /* */
- /* <Input> */
- /* to :: A pointer to the contour's first point. */
- /* raster :: A pointer to the current raster object. */
- /* */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function is used as a `FTRasterMoveTo_Func' by the outline */
- /* decomposer. */
- /* */
- static
- int Move_To( FT_Vector* to,
- FT_Raster raster )
+/****************************************************************************/
+/* */
+/* Function: Bezier_Down */
+/* */
+/* Description: Computes the x-coordinates of a descending bezier arc */
+/* and stores them in the render pool. */
+/* */
+
+ static Bool Bezier_Down( RAS_ARGS Int degree,
+ TSplitter splitter,
+ Long miny,
+ Long maxy )
{
- TPos scaled_x, scaled_y;
+ TPoint* arc = ras.arc;
+ Bool result, fresh;
- /* if there was already a contour being built, perform some checks */
- if ( ras.start_prof )
- if ( Check_Contour( RAS_VAR ) )
- return FAILURE;
+ arc[0].y = -arc[0].y;
+ arc[1].y = -arc[1].y;
+ arc[2].y = -arc[2].y;
+ if (degree > 2)
+ arc[3].y = -arc[3].y;
- /* set the `current last point' */
- scaled_x = SCALED( to->x );
- scaled_y = SCALED( to->y );
+ fresh = ras.fresh;
- if ( ras.flipped )
- {
- ras.last.x = scaled_y;
- ras.last.y = scaled_x;
- }
- else
- {
- ras.last.x = scaled_x;
- ras.last.y = scaled_y;
- }
+ result = Bezier_Up( RAS_VARS degree, splitter, -maxy, -miny );
- ras.state = Unknown;
- ras.first_prof = NULL;
+ if ( fresh && !ras.fresh )
+ ras.cProfile->start = -ras.cProfile->start;
- return SUCCESS;
+ arc[0].y = -arc[0].y;
+ return result;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Line_To */
- /* */
- /* <Description> */
- /* This function injects a new line segment in the render pool and */
- /* adjusts the profiles list accordingly. */
- /* */
- /* <Input> */
- /* to :: A pointer to the target position. */
- /* raster :: A pointer to the current raster object. */
- /* */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function is used as a `FTRasterLineTo_Func' by the outline */
- /* decomposer. */
- /* */
- static
- int Line_To( FT_Vector* to,
- FT_Raster raster )
- {
- TPos x, scaled_x;
- TPos y, scaled_y;
-
-
- scaled_x = SCALED( to->x );
- scaled_y = SCALED( to->y );
-
- if ( ras.flipped )
- {
- x = scaled_y;
- y = scaled_x;
- }
- else
- {
- x = scaled_x;
- y = scaled_y;
- }
+/****************************************************************************/
+/* */
+/* Function: Line_To */
+/* */
+/* Description: Injects a new line segment and adjusts Profiles list. */
+/* */
+/* Input: x, y : segment endpoint (start point in LastX,LastY) */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE on Render Pool overflow or Incorrect Profile. */
+/* */
+/****************************************************************************/
+ static Bool Line_To( RAS_ARGS Long x, Long y )
+ {
/* First, detect a change of direction */
- if ( y != ras.last.y )
- {
- TDirection new_state = ( (y > ras.last.y) ? Ascending : Descending );
+ switch ( ras.state )
+ {
+ case Unknown:
+ if ( y > ras.lastY )
+ {
+ if ( New_Profile( RAS_VARS Ascending ) ) return FAILURE;
+ }
+ else
+ {
+ if ( y < ras.lastY )
+ if ( New_Profile( RAS_VARS Descending ) ) return FAILURE;
+ }
+ break;
- if ( ras.state != new_state )
+ case Ascending:
+ if ( y < ras.lastY )
{
- if ( ras.state != Unknown &&
- End_Profile( RAS_VAR ) )
- goto Fail;
+ if ( End_Profile( RAS_VAR ) ||
+ New_Profile( RAS_VARS Descending ) ) return FAILURE;
+ }
+ break;
- if ( New_Profile( RAS_VAR_ new_state ) )
- goto Fail;
+ case Descending:
+ if ( y > ras.lastY )
+ {
+ if ( End_Profile( RAS_VAR ) ||
+ New_Profile( RAS_VARS Ascending ) ) return FAILURE;
}
+ break;
+
+ default:
+ ;
}
/* Then compute the lines */
+
switch ( ras.state )
{
case Ascending:
- if ( Line_Up ( RAS_VAR_ ras.last.x, ras.last.y,
- x, y, ras.minY, ras.maxY ) )
- goto Fail;
+ if ( Line_Up ( RAS_VARS ras.lastX, ras.lastY,
+ x, y, ras.minY, ras.maxY ) )
+ return FAILURE;
break;
case Descending:
- if ( Line_Down( RAS_VAR_ ras.last.x, ras.last.y,
- x, y, ras.minY, ras.maxY ) )
- goto Fail;
+ if ( Line_Down( RAS_VARS ras.lastX, ras.lastY,
+ x, y, ras.minY, ras.maxY ) )
+ return FAILURE;
break;
default:
;
}
- ras.last.x = x;
- ras.last.y = y;
+ ras.lastX = x;
+ ras.lastY = y;
return SUCCESS;
-
- Fail:
- return FAILURE;
}
-#ifdef FT_RASTER_CONIC_BEZIERS
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Push_Conic */
- /* */
- /* <Description> */
- /* Clears the Bezier stack and pushes a new arc on top of it. */
- /* */
- /* <Input> */
- /* p2 :: A pointer to the second (control) point. */
- /* p3 :: A pointer to the third (end) point. */
- /* */
- /* <Note> */
- /* The first point is taken as `raster->last', so it doesn't appear */
- /* in the signature. */
- /* */
- static
- void Push_Conic( RAS_ARG_ FT_Vector* p2,
- FT_Vector* p3 )
- {
-#undef STORE
-#define STORE( _arc, point ) \
- { \
- TPos x = SCALED( point->x ); \
- TPos y = SCALED( point->y ); \
- \
- \
- if ( ras.flipped ) \
- { \
- _arc.x = y; \
- _arc.y = x; \
- } \
- else \
- { \
- _arc.x = x; \
- _arc.y = y; \
- } \
- }
-
- TPoint* arc;
-
-
- ras.arc = arc = ras.arcs;
-
- arc[2] = ras.last;
- STORE( arc[1], p2 );
- STORE( arc[0], p3 );
-#undef STORE
- }
-
+/****************************************************************************/
+/* */
+/* Function: Conic_To */
+/* */
+/* Description: Injects a new conic arc and adjusts the profile list. */
+/* */
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Conic_To */
- /* */
- /* <Description> */
- /* Injects a new conic Bezier arc and adjusts the profile list */
- /* accordingly. */
- /* */
- /* <Input> */
- /* control :: A pointer to an intermediate control point. */
- /* to :: A pointer to the end point. */
- /* raster :: A handle to the current raster object. */
- /* */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function is used as a `FTRasterConicTo_Func' by the outline */
- /* decomposer. */
- /* */
- static
- int Conic_To( FT_Vector* control,
- FT_Vector* to,
- FT_Raster raster )
+ static Bool Conic_To( RAS_ARGS Long cx,
+ Long cy,
+ Long x,
+ Long y )
{
- TPos y1, y2, y3, x3, ymin, ymax;
- TDirection state_bez;
+ Long y1, y2, y3, x3, ymin, ymax;
+ TStates state_bez;
- Push_Conic( RAS_VAR_ control, to );
+ ras.arc = ras.arcs;
+ ras.arc[2].x = ras.lastX;
+ ras.arc[2].y = ras.lastY;
+ ras.arc[1].x = cx; ras.arc[1].y = cy;
+ ras.arc[0].x = x; ras.arc[0].y = y;
do
{
@@ -2020,141 +1236,55 @@
goto Fail;
/* create a new profile */
- if ( New_Profile( RAS_VAR_ state_bez ) )
+ if ( New_Profile( RAS_VARS state_bez ) )
goto Fail;
}
/* now call the appropriate routine */
if ( state_bez == Ascending )
{
- if ( Bezier_Up( RAS_VAR_ 2, Split_Conic, ras.minY, ras.maxY ) )
+ if ( Bezier_Up( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) )
goto Fail;
}
else
- if ( Bezier_Down( RAS_VAR_ 2, Split_Conic, ras.minY, ras.maxY ) )
+ if ( Bezier_Down( RAS_VARS 2, Split_Conic, ras.minY, ras.maxY ) )
goto Fail;
}
} while ( ras.arc >= ras.arcs );
- ras.last.x = x3;
- ras.last.y = y3;
+ ras.lastX = x3;
+ ras.lastY = y3;
return SUCCESS;
-
Fail:
return FAILURE;
}
-#else /* FT_RASTER_CONIC_BEZIERS */
-
-
- static
- int Conic_To( FT_Vector* control,
- FT_Vector* to,
- FT_Raster raster )
- {
- UNUSED( control );
- UNUSED( to );
- UNUSED( raster );
-
- return ErrRaster_Invalid_Outline;
- }
-
-#endif /* FT_RASTER_CONIC_BEZIERS */
-
-
-#ifdef FT_RASTER_CUBIC_BEZIERS
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Push_Cubic */
- /* */
- /* <Description> */
- /* Clears the Bezier stack and pushes a new third-order Bezier arc on */
- /* top of it. */
- /* */
- /* <Input> */
- /* p2 :: A pointer to the second (control) point. */
- /* p3 :: A pointer to the third (control) point. */
- /* p4 :: A pointer to the fourth (end) point. */
- /* */
- /* <Note> */
- /* The first point is taken as `raster->last', so it doesn't appear */
- /* in the signature. */
- /* */
- /* This is the same as Push_Conic(), except that it deals with */
- /* third-order Beziers. */
- /* */
- static
- void Push_Cubic( RAS_ARG_ FT_Vector* p2,
- FT_Vector* p3,
- FT_Vector* p4 )
- {
-#undef STORE
-#define STORE( _arc, point ) \
- { \
- TPos x = SCALED( point->x ); \
- TPos y = SCALED( point->y ); \
- \
- if ( ras.flipped ) \
- { \
- _arc.x = y; \
- _arc.y = x; \
- } \
- else \
- { \
- _arc.x = x; \
- _arc.y = y; \
- } \
- }
-
- TPoint* arc;
- ras.arc = arc = ras.arcs;
-
- arc[3] = ras.last;
- STORE( arc[2], p2 );
- STORE( arc[1], p3 );
- STORE( arc[0], p4 );
-
-#undef STORE
- }
-
+/****************************************************************************/
+/* */
+/* Function: Cubic_To */
+/* */
+/* Description: Injects a new cubic arc and adjusts the profile list. */
+/* */
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Cubic_To */
- /* */
- /* <Description> */
- /* Injects a new cubic Bezier arc and adjusts the profile list */
- /* accordingly. */
- /* */
- /* <Input> */
- /* control1 :: A pointer to the first control point. */
- /* control2 :: A pointer to the second control point. */
- /* to :: A pointer to the end point. */
- /* raster :: A handle to the current raster object. */
- /* */
- /* <Return> */
- /* Error code. 0 means success. */
- /* */
- /* <Note> */
- /* This function is used as a `FTRasterCubicTo_Func' by the outline */
- /* decomposer. */
- /* */
- static
- int Cubic_To( FT_Vector* control1,
- FT_Vector* control2,
- FT_Vector* to,
- FT_Raster raster )
+ static Bool Cubic_To( RAS_ARGS Long cx1,
+ Long cy1,
+ Long cx2,
+ Long cy2,
+ Long x,
+ Long y )
{
- TPos y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2;
- TDirection state_bez;
+ Long y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2;
+ TStates state_bez;
- Push_Cubic( RAS_VAR_ control1, control2, to );
+ ras.arc = ras.arcs;
+ ras.arc[3].x = ras.lastX;
+ ras.arc[3].y = ras.lastY;
+ ras.arc[2].x = cx1; ras.arc[2].y = cy1;
+ ras.arc[1].x = cx2; ras.arc[1].y = cy2;
+ ras.arc[0].x = x; ras.arc[0].y = y;
do
{
@@ -2210,135 +1340,345 @@
End_Profile( RAS_VAR ) )
goto Fail;
- if ( New_Profile( RAS_VAR_ state_bez ) )
+ if ( New_Profile( RAS_VARS state_bez ) )
goto Fail;
}
/* compute intersections */
if ( state_bez == Ascending )
{
- if ( Bezier_Up ( RAS_VAR_ 3, Split_Cubic, ras.minY, ras.maxY ) )
+ if ( Bezier_Up ( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) )
goto Fail;
}
else
- if ( Bezier_Down ( RAS_VAR_ 3, Split_Cubic, ras.minY, ras.maxY ) )
+ if ( Bezier_Down ( RAS_VARS 3, Split_Cubic, ras.minY, ras.maxY ) )
goto Fail;
}
} while ( ras.arc >= ras.arcs );
- ras.last.x = x4;
- ras.last.y = y4;
+ ras.lastX = x4;
+ ras.lastY = y4;
return SUCCESS;
-
Fail:
return FAILURE;
}
-#else /* FT_RASTER_CUBIC_BEZIERS */
+/****************************************************************************/
+/* */
+/* Function: Decompose_Curve */
+/* */
+/* Description: Scans the outline arays in order to emit individual */
+/* segments and beziers by calling Line_To() and Bezier_To(). */
+/* It handles all weird cases, like when the first point */
+/* is off the curve, or when there are simply no 'on' */
+/* points in the contour! */
+/* */
+/* Input: first, last : indexes of first and last point in */
+/* contour. */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE on error. */
+/* */
+/****************************************************************************/
+
+#undef SWAP_
+#define SWAP_(x,y) { Long swap = x; x = y; y = swap; }
+
+
+ static Bool Decompose_Curve( RAS_ARGS UShort first,
+ UShort last,
+ int flipped )
+ {
+ FT_Vector v_last;
+ FT_Vector v_control;
+ FT_Vector v_start;
+
+ FT_Vector* points;
+ FT_Vector* point;
+ FT_Vector* limit;
+ char* tags;
+
+ char tag; /* current point's state */
+
+ points = ras.outline.points;
+ limit = points + last;
+
+ v_start.x = SCALED(points[first].x);
+ v_start.y = SCALED(points[first].y);
+ v_last.x = SCALED(points[last].x);
+ v_last.y = SCALED(points[last].y);
+ if (flipped)
+ {
+ SWAP_(v_start.x,v_start.y);
+ SWAP_(v_last.x,v_last.y);
+ }
+
+ v_control = v_start;
+
+ point = points + first;
+ tags = ras.outline.tags + first;
+ tag = FT_CURVE_TAG( tags[0] );
+ /* A contour cannot start with a cubic control point! */
+ if ( tag == FT_Curve_Tag_Cubic )
+ goto Invalid_Outline;
- int Cubic_To( FT_Vector* control1,
- FT_Vector* control2,
- FT_Vector* to,
- FT_Raster raster )
- {
- UNUSED( control1 );
- UNUSED( control2 );
- UNUSED( to );
- UNUSED( raster );
+ /* check first point to determine origin */
+ if ( tag == FT_Curve_Tag_Conic )
+ {
+ /* first point is conic control. Yes, this happens. */
+ if ( FT_CURVE_TAG( ras.outline.tags[last] ) == FT_Curve_Tag_On )
+ {
+ /* start at last point if it is on the curve */
+ v_start = v_last;
+ limit--;
+ }
+ else
+ {
+ /* if both first and last points are conic, */
+ /* start at their middle and record its position */
+ /* for closure */
+ v_start.x = ( v_start.x + v_last.x ) / 2;
+ v_start.y = ( v_start.y + v_last.y ) / 2;
+
+ v_last = v_start;
+ }
+ point--;
+ tags--;
+ }
- return ErrRaster_Invalid_Outline;
+ ras.lastX = v_start.x;
+ ras.lastY = v_start.y;
+
+ while (point < limit)
+ {
+ point++;
+ tags++;
+
+ tag = FT_CURVE_TAG( tags[0] );
+ switch (tag)
+ {
+ case FT_Curve_Tag_On: /* emit a single line_to */
+ {
+ Long x, y;
+
+ x = SCALED(point->x);
+ y = SCALED(point->y);
+ if (flipped) SWAP_(x,y);
+
+ if (Line_To( RAS_VARS x, y )) goto Fail;
+ continue;
+ }
+
+
+ case FT_Curve_Tag_Conic: /* consume conic arcs */
+ {
+ v_control.x = SCALED(point[0].x);
+ v_control.y = SCALED(point[0].y);
+ if (flipped) SWAP_(v_control.x,v_control.y);
+
+ Do_Conic:
+ if (point < limit)
+ {
+ FT_Vector v_middle;
+ Long x, y;
+
+ point++;
+ tags++;
+ tag = FT_CURVE_TAG( tags[0] );
+
+ x = SCALED(point[0].x);
+ y = SCALED(point[0].y);
+ if (flipped) SWAP_(x,y);
+
+ if (tag == FT_Curve_Tag_On)
+ {
+ if (Conic_To( RAS_VARS v_control.x, v_control.y, x, y ))
+ goto Fail;
+ continue;
+ }
+
+ if (tag != FT_Curve_Tag_Conic)
+ goto Invalid_Outline;
+
+ v_middle.x = (v_control.x + x)/2;
+ v_middle.y = (v_control.y + y)/2;
+
+ if (Conic_To( RAS_VARS v_control.x, v_control.y,
+ v_middle.x, v_middle.y )) goto Fail;
+
+ v_control.x = x;
+ v_control.y = y;
+ goto Do_Conic;
+ }
+
+ if (Conic_To( RAS_VARS v_control.x, v_control.y,
+ v_start.x, v_start.y )) goto Fail;
+ goto Close;
+ }
+
+ default: /* FT_Curve_Tag_Cubic */
+ {
+ Long x1, y1, x2, y2, x3, y3;
+
+ if ( point+1 > limit ||
+ FT_CURVE_TAG( tags[1] ) != FT_Curve_Tag_Cubic )
+ goto Invalid_Outline;
+
+ point += 2;
+ tags += 2;
+
+ x1 = SCALED(point[-2].x);
+ y1 = SCALED(point[-2].y);
+ x2 = SCALED(point[-1].x);
+ y2 = SCALED(point[-1].y);
+ x3 = SCALED(point[ 0].x);
+ y3 = SCALED(point[ 0].y);
+ if (flipped)
+ {
+ SWAP_(x1,y1);
+ SWAP_(x2,y2);
+ SWAP_(x3,y3);
+ }
+ if (point <= limit)
+ {
+ if (Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ))
+ goto Fail;
+ continue;
+ }
+
+ if (Cubic_To( RAS_VARS x1, y1, x2, y2, v_start.x, v_start.y ))
+ goto Fail;
+ goto Close;
+ }
+ }
+ }
+
+ /* close the contour with a line segment */
+ if (Line_To( RAS_VARS v_start.x, v_start.y ))
+ goto Fail;
+
+ Close:
+ return SUCCESS;
+
+ Invalid_Outline:
+ ras.error = Raster_Err_Invalid;
+
+ Fail:
+ return FAILURE;
}
+
+/****************************************************************************/
+/* */
+/* Function: Convert_Glyph */
+/* */
+/* Description: Converts a glyph into a series of segments and arcs */
+/* and makes a Profiles list with them. */
+/* */
+/* Input: _xCoord, _yCoord : coordinates tables. */
+/* */
+/* Uses the 'Flag' table too. */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE if any error was encountered during rendering. */
+/* */
+/****************************************************************************/
+
+ static Bool Convert_Glyph( RAS_ARGS int flipped )
+ {
+ Short i;
+ UShort start;
+ PProfile lastProfile;
-#endif /* FT_RASTER_CUBIC_BEZIERS */
+ ras.fProfile = NULL;
+ ras.joint = FALSE;
+ ras.fresh = FALSE;
+ ras.maxBuff = ras.sizeBuff - AlignProfileSize;
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Convert_Glyph */
- /* */
- /* <Description> */
- /* Converts a glyph into a series of segments and arcs and makes a */
- /* profiles list with them. */
- /* */
- /* <InOut> */
- /* outline :: The glyph outline. */
- /* */
- /* <Return> */
- /* SUCCESS or FAILURE. */
- /* */
- static
- TResult Convert_Glyph( RAS_ARG_ FT_Outline* outline )
- {
- static
- FT_Outline_Funcs interface =
+ ras.numTurns = 0;
+
+ ras.cProfile = (PProfile)ras.top;
+ ras.cProfile->offset = ras.top;
+ ras.num_Profs = 0;
+
+ start = 0;
+
+ for ( i = 0; i < ras.outline.n_contours; i++ )
{
- (FT_Outline_MoveTo_Func)Move_To,
- (FT_Outline_LineTo_Func)Line_To,
- (FT_Outline_ConicTo_Func)Conic_To,
- (FT_Outline_CubicTo_Func)Cubic_To,
- 0,
- 0
- };
+ ras.state = Unknown;
+ ras.gProfile = NULL;
- /* Set up state in the raster object */
- ras.start_prof = NULL;
- ras.joint = FALSE;
- ras.fresh = FALSE;
+ if ( Decompose_Curve( RAS_VARS start, ras.outline.contours[i], flipped ) )
+ return FAILURE;
- ras.pool_limit = ras.pool_size - AlignProfileSize;
+ start = ras.outline.contours[i] + 1;
- ras.n_extrema = 0;
+ /* We must now see if the extreme arcs join or not */
+ if ( ( FRAC( ras.lastY ) == 0 &&
+ ras.lastY >= ras.minY &&
+ ras.lastY <= ras.maxY ) )
+ if ( ras.gProfile && ras.gProfile->flow == ras.cProfile->flow )
+ ras.top--;
+ /* Note that ras.gProfile can be nil if the contour was too small */
+ /* to be drawn. */
- ras.cur_prof = (PProfile)ras.cursor;
- ras.cur_prof->offset = ras.cursor;
- ras.num_profs = 0;
+ lastProfile = ras.cProfile;
+ if ( End_Profile( RAS_VAR ) ) return FAILURE;
- /* Now decompose curve */
- if ( FT_Outline_Decompose( outline, &interface, &ras ) )
- return FAILURE;
- /* XXX: the error condition is in ras.error */
+ /* close the 'next profile in contour' linked list */
+ if ( ras.gProfile )
+ lastProfile->next = ras.gProfile;
+ }
- /* Check the last contour if needed */
- if ( Check_Contour( RAS_VAR ) )
+ if (Finalize_Profile_Table( RAS_VAR ))
return FAILURE;
- /* Finalize profiles list */
- return Finalize_Profile_Table( RAS_VAR );
+ return (ras.top < ras.maxBuff ? SUCCESS : FAILURE );
}
- /*************************************************************************/
- /* */
- /* Init_Linked */
- /* */
- /* Inits an empty linked list. */
- /* */
- static
- void Init_Linked( TProfileList* l )
+ /****************************************************************/
+ /****************************************************************/
+ /** **/
+ /** SCAN-LINE SWEEPS AND DRAWING **/
+ /** **/
+ /****************************************************************/
+ /****************************************************************/
+
+
+/************************************************/
+/* */
+/* Init_Linked */
+/* */
+/* Inits an empty linked list. */
+/* */
+/************************************************/
+
+ static void Init_Linked( TProfileList* l )
{
*l = NULL;
}
- /*************************************************************************/
- /* */
- /* InsNew */
- /* */
- /* Inserts a new Profile in a linked list. */
- /* */
- static
- void InsNew( PProfileList list,
- PProfile profile )
+/************************************************/
+/* */
+/* InsNew : */
+/* */
+/* Inserts a new Profile in a linked list. */
+/* */
+/************************************************/
+
+ static void InsNew( PProfileList list,
+ PProfile profile )
{
PProfile *old, current;
- TPos x;
+ Long x;
old = list;
@@ -2358,15 +1698,16 @@
}
- /*************************************************************************/
- /* */
- /* DelOld */
- /* */
- /* Removes an old Profile from a linked list. */
- /* */
- static
- void DelOld( PProfileList list,
- PProfile profile )
+/*************************************************/
+/* */
+/* DelOld : */
+/* */
+/* Removes an old Profile from a linked list. */
+/* */
+/*************************************************/
+
+ static void DelOld( PProfileList list,
+ PProfile profile )
{
PProfile *old, current;
@@ -2386,19 +1727,20 @@
current = *old;
}
- /* We should never reach this place, unless the Profile was not */
- /* part of the list. */
+ /* we should never get there, unless the Profile was not part of */
+ /* the list. */
}
- /*************************************************************************/
- /* */
- /* Update */
- /* */
- /* Updates all X offsets of a drawing list. */
- /* */
- static
- void Update( PProfile first )
+/************************************************/
+/* */
+/* Update : */
+/* */
+/* Update all X offsets of a drawing list */
+/* */
+/************************************************/
+
+ static void Update( PProfile first )
{
PProfile current = first;
@@ -2413,16 +1755,18 @@
}
- /*************************************************************************/
- /* */
- /* Sort */
- /* */
- /* Sorts a trace list. In 95%, the list is already sorted. We need */
- /* an algorithm which is fast in this case. Bubble sort is enough */
- /* and simple to implement. */
- /* */
- static
- void Sort( PProfileList list )
+/************************************************/
+/* */
+/* Sort : */
+/* */
+/* Sorts a trace list. In 95%, the list */
+/* is already sorted. We need an algorithm */
+/* which is fast in this case. Bubble sort */
+/* is enough and simple. */
+/* */
+/************************************************/
+
+ static void Sort( PProfileList list )
{
PProfile *old, current, next;
@@ -2452,110 +1796,82 @@
else
{
*old = next;
- current->link = next->link;
- next->link = current;
-
- old = list;
- current = *old;
- }
-
- next = current->link;
- }
- }
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /******** ********/
- /******** Vertical Bitmap Sweep Routines ********/
- /******** ********/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
+ current->link = next->link;
+ next->link = current;
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Sweep_Init */
- /* */
- /* <Description> */
- /* Initializes the vertical bitmap sweep. Called by the generic */
- /* sweep/draw routine before its loop. */
- /* */
- /* <Input> */
- /* min :: The address of the current minimum scanline. */
- /* max :: The address of the current maximum scanline. */
- /* */
- static
- void Vertical_Sweep_Init( RAS_ARG_ int* min, int* max )
- {
- long pitch;
+ old = list;
+ current = *old;
+ }
- UNUSED( max );
+ next = current->link;
+ }
+ }
- pitch = ras.target.pitch;
- /* start from the bottom line, going up !! */
- ras.trace_bit = - *min * pitch;
- ras.trace_incr = -pitch;
+/***********************************************************************/
+/* */
+/* Vertical Sweep Procedure Set : */
+/* */
+/* These three routines are used during the vertical black/white */
+/* sweep phase by the generic Draw_Sweep() function. */
+/* */
+/***********************************************************************/
+ static void Vertical_Sweep_Init( RAS_ARGS Short* min, Short* max )
+ {
+ Long pitch = ras.target.pitch;
+
+ UNUSED(max);
+
+ ras.traceIncr = (Short)- pitch;
+ ras.traceOfs = - *min * pitch;
if (pitch > 0)
- ras.trace_bit += pitch*(ras.target.rows-1);
+ ras.traceOfs += (ras.target.rows-1)*pitch;
+
+ ras.gray_min_x = 0;
+ ras.gray_max_x = 0;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Sweep_Span */
- /* */
- /* <Description> */
- /* Draws a single horizontal bitmap span during the vertical bitmap */
- /* sweep. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x1 :: The left span edge. */
- /* x2 :: The right span edge. */
- /* */
- static
- void Vertical_Sweep_Span( RAS_ARG_ TScan y,
- TPos x1,
- TPos x2 )
+ static void Vertical_Sweep_Span( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right )
{
- TPos e1, e2;
- int c1, c2;
+ Long e1, e2;
+ Short c1, c2;
Byte f1, f2;
- PByte target;
+ Byte* target;
- UNUSED( y );
+ UNUSED(y);
+ UNUSED(left);
+ UNUSED(right);
/* Drop-out control */
+
e1 = TRUNC( CEILING( x1 ) );
-
- if ( x2 - x1 - PRECISION <= PRECISION_JITTER )
+
+ if ( x2-x1-ras.precision <= ras.precision_jitter )
e2 = e1;
else
e2 = TRUNC( FLOOR( x2 ) );
-#ifdef OLD
- if ( e2 >= 0 && e1 < ras.bit_width )
-#else
- if ( e1 <= e2 && e2 >= 0 && e1 < ras.bit_width )
-#endif
+ if ( e2 >= 0 && e1 < ras.bWidth )
{
- if ( e1 < 0 ) e1 = 0;
- if ( e2 >= ras.bit_width ) e2 = ras.bit_width - 1;
+ if ( e1 < 0 ) e1 = 0;
+ if ( e2 >= ras.bWidth ) e2 = ras.bWidth-1;
- c1 = e1 >> 3;
- c2 = e2 >> 3;
+ c1 = (Short)(e1 >> 3);
+ c2 = (Short)(e2 >> 3);
f1 = ((unsigned char)0xFF >> (e1 & 7));
f2 = ~((unsigned char)0x7F >> (e2 & 7));
- target = ras.bit_buffer + ras.trace_bit + c1;
+ if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1;
+ if ( ras.gray_max_x < c2 ) ras.gray_max_x = c2;
+
+ target = ras.bTarget + ras.traceOfs + c1;
c2 -= c1;
if ( c2 > 0 )
@@ -2579,828 +1895,543 @@
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Test_Pixel */
- /* */
- /* <Description> */
- /* Tests a pixel `light' during the vertical bitmap sweep. Used */
- /* during drop-out control only. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x :: The current x coordinate. */
- /* */
- static
- int Vertical_Test_Pixel( RAS_ARG_ TScan y,
- int x )
+ static void Vertical_Sweep_Drop( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right )
{
- int c1 = x >> 3;
+ Long e1, e2;
+ Short c1, f1;
- UNUSED( y );
+ /* Drop-out control */
- return ( x >= 0 && x < ras.bit_width &&
- ras.bit_buffer[ras.trace_bit + c1] & (0x80 >> (x & 7)) );
- }
+ e1 = CEILING( x1 );
+ e2 = FLOOR ( x2 );
+ if ( e1 > e2 )
+ {
+ if ( e1 == e2 + ras.precision )
+ {
+ switch ( ras.dropOutControl )
+ {
+ case 1:
+ e1 = e2;
+ break;
+
+ case 4:
+ e1 = CEILING( (x1 + x2 + 1) / 2 );
+ break;
+
+ case 2:
+ case 5:
+ /* Drop-out Control Rule #4 */
+
+ /* The spec is not very clear regarding rule #4. It */
+ /* presents a method that is way too costly to implement */
+ /* while the general idea seems to get rid of 'stubs'. */
+ /* */
+ /* Here, we only get rid of stubs recognized when: */
+ /* */
+ /* upper stub: */
+ /* */
+ /* - P_Left and P_Right are in the same contour */
+ /* - P_Right is the successor of P_Left in that contour */
+ /* - y is the top of P_Left and P_Right */
+ /* */
+ /* lower stub: */
+ /* */
+ /* - P_Left and P_Right are in the same contour */
+ /* - P_Left is the successor of P_Right in that contour */
+ /* - y is the bottom of P_Left */
+ /* */
+
+ /* FIXXXME : uncommenting this line solves the disappearing */
+ /* bit problem in the '7' of verdana 10pts, but */
+ /* makes a new one in the 'C' of arial 14pts */
+
+ /* if ( x2-x1 < ras.precision_half ) */
+ {
+ /* upper stub test */
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Set_Pixel */
- /* */
- /* <Description> */
- /* Sets a single pixel in a bitmap during the vertical sweep. Used */
- /* during drop-out control. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x :: The current x coordinate. */
- /* color :: Ignored by this function. */
- /* */
- static
- void Vertical_Set_Pixel( RAS_ARG_ int y,
- int x,
- int color )
- {
- UNUSED( color );
- UNUSED( y );
+ if ( left->next == right && left->height <= 0 ) return;
- if ( x >= 0 && x < ras.bit_width )
- ras.bit_buffer[ras.trace_bit+(x >> 3)] |= (char)(0x80 >> (x & 7));
- }
+ /* lower stub test */
+ if ( right->next == left && left->start == y ) return;
+ }
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Sweep_Step */
- /* */
- /* <Description> */
- /* Called whenever the sweep jumps to another scanline. Only updates */
- /* the pointers in the vertical bitmap sweep. */
- /* */
- static
- void Vertical_Sweep_Step( RAS_ARG )
- {
- ras.trace_bit += ras.trace_incr;
+ /* check that the rightmost pixel isn't set */
+
+ e1 = TRUNC( e1 );
+
+ c1 = (Short)(e1 >> 3);
+ f1 = e1 & 7;
+
+ if ( e1 >= 0 && e1 < ras.bWidth &&
+ ras.bTarget[ras.traceOfs + c1] & (0x80 >> f1) )
+ return;
+
+ if ( ras.dropOutControl == 2 )
+ e1 = e2;
+ else
+ e1 = CEILING( (x1 + x2 + 1) / 2 );
+
+ break;
+
+ default:
+ return; /* unsupported mode */
+ }
+ }
+ else
+ return;
+ }
+
+ e1 = TRUNC( e1 );
+
+ if ( e1 >= 0 && e1 < ras.bWidth )
+ {
+ c1 = (Short)(e1 >> 3);
+ f1 = e1 & 7;
+
+ if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1;
+ if ( ras.gray_max_x < c1 ) ras.gray_max_x = c1;
+
+ ras.bTarget[ras.traceOfs + c1] |= (char)(0x80 >> f1);
+ }
}
- static
- const Raster_Render vertical_render_mono =
+ static void Vertical_Sweep_Step( RAS_ARG )
{
- &Vertical_Sweep_Init,
- &Vertical_Sweep_Span,
- &Vertical_Sweep_Step,
- &Vertical_Test_Pixel,
- &Vertical_Set_Pixel
- };
+ ras.traceOfs += ras.traceIncr;
+ }
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /******** ********/
- /******** Horizontal Bitmap Sweep Routines ********/
- /******** ********/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
+/***********************************************************************/
+/* */
+/* Horizontal Sweep Procedure Set : */
+/* */
+/* These three routines are used during the horizontal black/white */
+/* sweep phase by the generic Draw_Sweep() function. */
+/* */
+/***********************************************************************/
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Sweep_Init */
- /* */
- /* <Description> */
- /* Initializes the horizontal bitmap sweep. Called by the generic */
- /* sweep/draw routine before its loop. */
- /* */
- /* <Input> */
- /* min :: The address of the current minimum pixel column. */
- /* max :: The address of the current maximum pixel column. */
- /* */
- static
- void Horizontal_Sweep_Init( RAS_ARG_ int* min,
- int* max )
+ static void Horizontal_Sweep_Init( RAS_ARGS Short* min, Short* max )
{
- UNUSED( ras );
- UNUSED( min );
- UNUSED( max );
-
/* nothing, really */
+ UNUSED(raster);
+ UNUSED(min);
+ UNUSED(max);
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Sweep_Span */
- /* */
- /* <Description> */
- /* Draws a single vertical bitmap span during the horizontal bitmap */
- /* sweep. Actually, this function is only used to check for weird */
- /* drop-out cases. */
- /* */
- /* <Input> */
- /* y :: The current pixel column. */
- /* x1 :: The top span edge. */
- /* x2 :: The bottom span edge. */
- /* */
- static
- void Horizontal_Sweep_Span( RAS_ARG_ TScan y,
- TPos x1,
- TPos x2 )
+ static void Horizontal_Sweep_Span( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right )
{
- TPos e1, e2;
- PByte bits;
- Byte f1;
+ Long e1, e2;
+ PByte bits;
+ Byte f1;
- UNUSED( y );
-
- /* During the horizontal sweep, we only take care of drop-outs */
- if ( x2 - x1 < PRECISION )
+ UNUSED(left);
+ UNUSED(right);
+
+ if ( x2-x1 < ras.precision )
{
e1 = CEILING( x1 );
- e2 = FLOOR( x2 );
+ e2 = FLOOR ( x2 );
if ( e1 == e2 )
{
- bits = ras.bit_buffer + (y >> 3);
- f1 = (Byte)(0x80 >> (y & 7));
+ bits = ras.bTarget + (y >> 3);
+ f1 = (Byte)(0x80 >> (y & 7));
e1 = TRUNC( e1 );
if ( e1 >= 0 && e1 < ras.target.rows )
{
- long pitch = ras.target.pitch;
- long offset = - pitch * e1;
+ PByte p;
- if (pitch > 0)
- offset += (ras.target.rows-1)*pitch;
-
- bits[offset] |= f1;
+ p = bits - e1*ras.target.pitch;
+ if (ras.target.pitch > 0)
+ p += (ras.target.rows-1)*ras.target.pitch;
+
+ p[0] |= f1;
}
}
}
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Test_Pixel */
- /* */
- /* <Description> */
- /* Tests a pixel `light' during the horizontal bitmap sweep. Used */
- /* during drop-out control only. */
- /* */
- /* <Input> */
- /* y :: The current pixel column. */
- /* x :: The current row/scanline. */
- /* */
- static
- int Horizontal_Test_Pixel( RAS_ARG_ int y,
- int x )
+ static void Horizontal_Sweep_Drop( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right )
{
- char* bits = (char*)ras.bit_buffer + (y >> 3);
- int f1 = (Byte)(0x80 >> (y & 7));
- long pitch = ras.target.pitch;
- long offset = - pitch * x;
+ Long e1, e2;
+ PByte bits;
+ Byte f1;
- if (pitch > 0)
- offset += (ras.target.rows-1)*pitch;
-
- return ( x >= 0 && x < ras.target.rows && (bits[0] & f1) );
- }
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Set_Pixel */
- /* */
- /* <Description> */
- /* Sets a single pixel in a bitmap during the horizontal sweep. Used */
- /* during drop-out control. */
- /* */
- /* <Input> */
- /* y :: The current pixel column. */
- /* x :: The current row/scanline. */
- /* color :: Ignored by this function. */
- /* */
- static
- void Horizontal_Set_Pixel( RAS_ARG_ int y,
- int x,
- int color )
- {
- char* bits = (char*)ras.bit_buffer + (y >> 3);
- int f1 = (Byte)(0x80 >> (y & 7));
+ /* During the horizontal sweep, we only take care of drop-outs */
- UNUSED( color );
+ e1 = CEILING( x1 );
+ e2 = FLOOR ( x2 );
- if ( x >= 0 && x < ras.target.rows )
+ if ( e1 > e2 )
{
- long pitch = ras.target.pitch;
- long offset = - x*pitch;
-
- if (pitch > 0)
- offset += (ras.target.rows-1)*pitch;
-
- bits[offset] |= f1;
- }
- }
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Sweep_Step */
- /* */
- /* <Description> */
- /* Called whenever the sweep jumps to another pixel column. */
- /* */
- static
- void Horizontal_Sweep_Step( RAS_ARG )
- {
- UNUSED( ras.target );
-
- /* Nothing, really */
- }
-
-
- static
- const Raster_Render horizontal_render_mono =
- {
- &Horizontal_Sweep_Init,
- &Horizontal_Sweep_Span,
- &Horizontal_Sweep_Step,
- &Horizontal_Test_Pixel,
- &Horizontal_Set_Pixel
- };
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /******** ********/
- /******** Anti-Aliased Vertical Bitmap Sweep Routines ********/
- /******** ********/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
+ if ( e1 == e2 + ras.precision )
+ {
+ switch ( ras.dropOutControl )
+ {
+ case 1:
+ e1 = e2;
+ break;
-#ifdef FT_RASTER_OPTION_ANTI_ALIAS
+ case 4:
+ e1 = CEILING( (x1 + x2 + 1) / 2 );
+ break;
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Gray_Sweep_Init */
- /* */
- /* <Description> */
- /* Initializes the vertical bitmap sweep. Called by the generic */
- /* sweep/draw routine before its loop. */
- /* */
- /* <Input> */
- /* min :: The address of the current minimum scanline. */
- /* max :: The address of the current maximum scanline. */
- /* */
- static
- void Vertical_Gray_Sweep_Init( RAS_ARG_ int* min, int* max )
- {
- long pitch;
+ case 2:
+ case 5:
- UNUSED( max );
+ /* Drop-out Control Rule #4 */
- pitch = ras.target.pitch;
+ /* The spec is not very clear regarding rule #4. It */
+ /* presents a method that is way too costly to implement */
+ /* while the general idea seems to get rid of 'stubs'. */
+ /* */
- /* start from the bottom line, going up */
- ras.trace_incr = -pitch;
- ras.trace_bit = - *min * pitch;
+ /* rightmost stub test */
- if (pitch > 0)
- ras.trace_bit += (ras.target.rows-1)*pitch;
- }
+ if ( left->next == right && left->height <= 0 ) return;
+ /* leftmost stub test */
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Gray_Sweep_Span */
- /* */
- /* <Description> */
- /* Draws a single horizontal bitmap span during the vertical bitmap */
- /* sweep. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x1 :: The left span edge. */
- /* x2 :: The right span edge. */
- /* */
- static
- void Vertical_Gray_Sweep_Span( RAS_ARG_ TScan y,
- TPos x1,
- TPos x2 )
- {
- TPos e1, e2;
- int shift = PRECISION_BITS - 6;
- PByte target;
+ if ( right->next == left && left->start == y ) return;
- UNUSED( y );
+ /* check that the rightmost pixel isn't set */
- x1 += PRECISION_HALF;
- x2 += PRECISION_HALF;
+ e1 = TRUNC( e1 );
- e1 = TRUNC( x1 );
- e2 = TRUNC( x2 );
+ bits = ras.bTarget + (y >> 3);
+ f1 = (Byte)(0x80 >> (y & 7));
- if ( e1 <= e2 && e2 >= 0 && e1 < ras.bit_width )
- {
- x1 = FRAC(x1) >> shift;
- x2 = FRAC(x2) >> shift;
+ bits -= e1*ras.target.pitch;
+ if (ras.target.pitch > 0)
+ bits += (ras.target.rows-1)*ras.target.pitch;
- if ( e1 < 0 )
- {
- e1 = 0;
- x1 = 0;
- }
+ if ( e1 >= 0 &&
+ e1 < ras.target.rows &&
+ *bits & f1 )
+ return;
- if ( e2 > ras.bit_width )
- {
- e2 = ras.bit_width-1;
- x2 = 0;
- }
+ if ( ras.dropOutControl == 2 )
+ e1 = e2;
+ else
+ e1 = CEILING( (x1 + x2 + 1) / 2 );
- target = ras.bit_buffer + ras.trace_bit + e1;
- e2 -= e1;
+ break;
- if ( e2 > 0 )
- {
- if (x1 > 0) target[0] += (Byte)(64-x1) << 1;
- else target[0] = 127;
- e2--;
- while (e2 > 0)
- {
- *(++target) = 127;
- e2--;
+ default:
+ return; /* unsupported mode */
}
- if (x2)
- target[1] += (Byte)x2 << 1;
}
else
- {
- target[0] += (Byte)(x2-x1) << 1;
- }
+ return;
}
- }
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Gray_Test_Pixel */
- /* */
- /* <Description> */
- /* Tests a pixel `light' during the vertical bitmap sweep. Used */
- /* during drop-out control only. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x :: The current x coordinate. */
- /* */
- static
- int Vertical_Gray_Test_Pixel( RAS_ARG_ TScan y,
- int x )
- {
- UNUSED_RASTER
- UNUSED( y );
-
-#if 0
- /* as a rule of thumb, do not add a drop-out if the current */
- /* gray level is over 0.5 */
-
- return ( x >= 0 && x < ras.bit_width &&
- ras.bit_buffer[ras.trace_bit + x] >= 64 );
-#else
- UNUSED(x);
- return 0;
-#endif
- }
+ bits = ras.bTarget + (y >> 3);
+ f1 = (Byte)(0x80 >> (y & 7));
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Gray_Set_Pixel */
- /* */
- /* <Description> */
- /* Sets a single pixel in a bitmap during the vertical sweep. Used */
- /* during drop-out control. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x :: The current x coordinate. */
- /* color :: Ignored by this function. */
- /* */
- static
- void Vertical_Gray_Set_Pixel( RAS_ARG_ int y,
- int x,
- int color )
- {
- UNUSED( y );
+ e1 = TRUNC( e1 );
- if ( x >= 0 && x < ras.bit_width )
+ if ( e1 >= 0 && e1 < ras.target.rows )
{
- unsigned char* pixel;
+ bits -= e1*ras.target.pitch;
+ if (ras.target.pitch > 0)
+ bits += (ras.target.rows-1)*ras.target.pitch;
- pixel = ras.bit_buffer + ras.trace_bit + x;
-
- /* do not add too much to the pixel gray level */
- color += *pixel;
- if (color < 64)
- color = 64;
-
- *pixel = ( color >= 127 ? 127 : (unsigned char)color );
+ bits[0] |= f1;
}
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Vertical_Sweep_Step */
- /* */
- /* <Description> */
- /* Called whenever the sweep jumps to another scanline. Only updates */
- /* the pointers in the vertical bitmap sweep. */
- /* */
- static
- void Vertical_Gray_Sweep_Step( RAS_ARG )
+ static void Horizontal_Sweep_Step( RAS_ARG )
{
- ras.trace_bit += ras.trace_incr;
+ /* Nothing, really */
+ UNUSED(raster);
}
+#ifdef FT_RASTER_OPTION_ANTI_ALIASING
+
+/***********************************************************************/
+/* */
+/* Vertical Gray Sweep Procedure Set: */
+/* */
+/* These two routines are used during the vertical gray-levels */
+/* sweep phase by the generic Draw_Sweep() function. */
+/* */
+/* */
+/* NOTES: */
+/* */
+/* - The target pixmap's width *must* be a multiple of 4. */
+/* */
+/* - you have to use the function Vertical_Sweep_Span() for */
+/* the gray span call. */
+/* */
+/***********************************************************************/
+
+ static void Vertical_Gray_Sweep_Init( RAS_ARGS Short* min, Short* max )
+ {
+ Long pitch, byte_len;
+
+ *min = *min & -2;
+ *max = ( *max + 3 ) & -2;
+
+ ras.traceOfs = 0;
+ pitch = ras.target.pitch;
+ byte_len = -pitch;
+ ras.traceIncr = (Short)byte_len;
+ ras.traceG = (*min/2)*byte_len;
+ if (pitch > 0)
+ {
+ ras.traceG += (ras.target.rows-1)*pitch;
+ byte_len = -byte_len;
+ }
- static
- const Raster_Render vertical_render_gray =
- {
- &Vertical_Gray_Sweep_Init,
- &Vertical_Gray_Sweep_Span,
- &Vertical_Gray_Sweep_Step,
- &Vertical_Gray_Test_Pixel,
- &Vertical_Gray_Set_Pixel
- };
-
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /******** ********/
- /******** Horizontal Bitmap Sweep Routines ********/
- /******** ********/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Sweep_Init */
- /* */
- /* <Description> */
- /* Initializes the horizontal bitmap sweep. Called by the generic */
- /* sweep/draw routine before its loop. */
- /* */
- /* <Input> */
- /* min :: The address of the current minimum pixel column. */
- /* max :: The address of the current maximum pixel column. */
- /* */
- static
- void Horizontal_Gray_Sweep_Init( RAS_ARG_ int* min,
- int* max )
- {
- UNUSED( ras );
- UNUSED( min );
- UNUSED( max );
-
- /* nothing, really */
+ ras.gray_min_x = (Short)byte_len;
+ ras.gray_max_x = -(Short)byte_len;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Gray_Sweep_Span */
- /* */
- /* <Description> */
- /* Draws a single vertical bitmap span during the horizontal bitmap */
- /* sweep. */
- /* */
- /* <Input> */
- /* y :: The current scanline. */
- /* x1 :: The left span edge. */
- /* x2 :: The right span edge. */
- /* */
- static
- void Horizontal_Gray_Sweep_Span( RAS_ARG_ TScan y,
- TPos x1,
- TPos x2 )
+ static void Vertical_Gray_Sweep_Step( RAS_ARG )
{
- TPos e1, e2;
- int shift = PRECISION_BITS - 6;
- int incr;
- PByte bits;
- Byte b;
+ Int c1, c2;
+ PByte pix, bit, bit2;
+ Int* count = ras.count_table;
+ Byte* grays;
- UNUSED( y );
- x1 += PRECISION_HALF;
- x2 += PRECISION_HALF;
+ ras.traceOfs += ras.gray_width;
- e1 = TRUNC( x1 );
- e2 = TRUNC( x2 );
-
- if ( e1 <= e2 && e2 >= 0 && e1 < ras.bit_width )
+ if ( ras.traceOfs > ras.gray_width )
{
- x1 = FRAC(x1) >> shift;
- x2 = FRAC(x2) >> shift;
-
- if ( e1 < 0 )
- {
- e1 = 0;
- x1 = 0;
- }
+ pix = ras.gTarget + ras.traceG + ras.gray_min_x * 4;
+ grays = ras.grays;
- if ( e2 >= ras.bit_width )
+ if ( ras.gray_max_x >= 0 )
{
- e2 = ras.bit_width;
- x2 = 0;
- }
+ Long last_pixel = ras.target.width-1;
+ Int last_cell = last_pixel >> 2;
+ Int last_bit = last_pixel & 3;
+ Bool over = 0;
+
+ if (ras.gray_max_x >= last_cell && last_bit != 3)
+ {
+ ras.gray_max_x = last_cell-1;
+ over = 1;
+ }
- incr = -ras.target.pitch;
- bits = ras.bit_buffer + y;
- bits += incr * e1;
- if (incr < 0)
- bits -= incr*(ras.target.rows-1);
+ if ( ras.gray_min_x < 0 )
+ ras.gray_min_x = 0;
- e2 -= e1;
+ bit = ras.bTarget + ras.gray_min_x;
+ bit2 = bit + ras.gray_width;
- if ( e2 > 0 )
- {
- b = bits[0];
- if (b < 127) b++;
- b = (Byte)((64-x1) + (b >> 1));
- bits[0] = b;
+ c1 = ras.gray_max_x - ras.gray_min_x;
- if ( e2 < 24 )
+ while ( c1 >= 0 )
{
- e2--;
- while (e2 > 0)
- {
- bits += incr;
- b = bits[0];
+ c2 = count[*bit] + count[*bit2];
- if (b < 127)
- bits[0] = (Byte)(63+((b+1) >> 1));
+ if ( c2 )
+ {
+ pix[0] = grays[(c2 >> 12) & 0x000F];
+ pix[1] = grays[(c2 >> 8 ) & 0x000F];
+ pix[2] = grays[(c2 >> 4 ) & 0x000F];
+ pix[3] = grays[ c2 & 0x000F];
- e2--;
+ *bit = 0;
+ *bit2 = 0;
}
- }
- else
- bits += incr*(e2-1);
- if (x2)
+ bit ++;
+ bit2++;
+ pix += 4;
+ c1 --;
+ }
+
+ if (over)
{
- bits += incr;
- b = bits[0];
- if (b < 127) b++;
- b = (Byte)(x2 + (b >> 1));
- bits[0] = b;
+ c2 = count[*bit] + count[*bit2];
+ if (c2)
+ {
+ switch (last_bit)
+ {
+ case 2: pix[2] = grays[(c2 >> 4 ) & 0x000F];
+ case 1: pix[1] = grays[(c2 >> 8 ) & 0x000F];
+ default: pix[0] = grays[(c2 >> 12) & 0x000F];
+ }
+
+ *bit = 0;
+ *bit2 = 0;
+ }
}
}
- else
- {
- b = bits[0];
- if (b < 127) b++;
- b = (Byte)((b >> 1)+(x2-x1));
- bits[0] = b;
- }
+
+ ras.traceOfs = 0;
+ ras.traceG += ras.traceIncr;
+
+ ras.gray_min_x = 32000;
+ ras.gray_max_x = -32000;
}
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Gray_Test_Pixel */
- /* */
- /* <Description> */
- /* Tests a pixel `light' during the horizontal bitmap sweep. Used */
- /* during drop-out control only. */
- /* */
- /* <Input> */
- /* y :: The current pixel column. */
- /* x :: The current row/scanline. */
- /* */
- static
- int Horizontal_Gray_Test_Pixel( RAS_ARG_ int y,
- int x )
+ static void Horizontal_Gray_Sweep_Span( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right )
{
-#if 0
- unsigned char* pixel = (unsigned char*)ras.bit_buffer + y;
-
- if ( ras.target.flow == Flow_Down )
- pixel += (ras.target.rows-1 - x) * ras.target.cols;
- else
- pixel += x * ras.target.cols;
-
- return ( x >= 0 && x < ras.target.rows &&
- *pixel >= 64 );
-#else
- UNUSED_RASTER
+ /* nothing, really */
+ UNUSED(raster);
UNUSED(y);
- UNUSED(x);
- return 0;
-#endif
+ UNUSED(x1);
+ UNUSED(x2);
+ UNUSED(left);
+ UNUSED(right);
}
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Horizontal_Set_Pixel */
- /* */
- /* <Description> */
- /* Sets a single pixel in a bitmap during the horizontal sweep. Used */
- /* during drop-out control. */
- /* */
- /* <Input> */
- /* y :: The current pixel column. */
- /* x :: The current row/scanline. */
- /* color :: Ignored by this function. */
- /* */
- static
- void Horizontal_Gray_Set_Pixel( RAS_ARG_ int y,
- int x,
- int color )
+ static void Horizontal_Gray_Sweep_Drop( RAS_ARGS Short y,
+ FT_F26Dot6 x1,
+ FT_F26Dot6 x2,
+ PProfile left,
+ PProfile right )
{
- unsigned char* pixel = (unsigned char*)ras.bit_buffer + y;
+ Long e1, e2;
+ PByte pixel;
+ Byte color;
+
- if ( x >= 0 && x < ras.target.rows )
+ /* During the horizontal sweep, we only take care of drop-outs */
+ e1 = CEILING( x1 );
+ e2 = FLOOR ( x2 );
+
+ if ( e1 > e2 )
{
- long pitch = ras.target.pitch;
+ if ( e1 == e2 + ras.precision )
+ {
+ switch ( ras.dropOutControl )
+ {
+ case 1:
+ e1 = e2;
+ break;
- pixel -= pitch*x;
- if (pitch > 0)
- pixel += pitch*(ras.target.rows-1);
+ case 4:
+ e1 = CEILING( (x1 + x2 + 1) / 2 );
+ break;
- color += *pixel;
- if (color < 64)
- color = 64;
+ case 2:
+ case 5:
- *pixel = (color >= 127 ? 127 : (unsigned char)color );
- }
- }
+ /* Drop-out Control Rule #4 */
+ /* The spec is not very clear regarding rule #4. It */
+ /* presents a method that is way too costly to implement */
+ /* while the general idea seems to get rid of 'stubs'. */
+ /* */
- static
- void Gray_Ignore( void )
- {
- ;
- }
+ /* rightmost stub test */
+ if ( left->next == right && left->height <= 0 ) return;
+ /* leftmost stub test */
+ if ( right->next == left && left->start == y ) return;
- static
- const Raster_Render horizontal_render_gray =
- {
- &Horizontal_Gray_Sweep_Init,
- &Horizontal_Gray_Sweep_Span,
+ if ( ras.dropOutControl == 2 )
+ e1 = e2;
+ else
+ e1 = CEILING( (x1 + x2 + 1) / 2 );
- (Function_Sweep_Step) &Gray_Ignore,
- &Horizontal_Gray_Test_Pixel,
- &Horizontal_Gray_Set_Pixel,
- };
+ break;
-#endif /* FT_RASTER_OPTION_ANTI_ALIAS */
+ default:
+ return; /* unsupported mode */
+ }
+ }
+ else
+ return;
+ }
+ if ( e1 >= 0 )
+ {
+ if ( x2 - x1 >= ras.precision_half )
+ color = ras.grays[2];
+ else
+ color = ras.grays[1];
- /*************************************************************************/
- /* */
- /* A technical note to explain how the scanline sweep is performed: */
- /* */
- /* The function Draw_Sweep() is used to sweep the scanlines of the */
- /* target bitmap or pixmap. For each scanline, it must do the */
- /* following: */
- /* */
- /* - Get the set of all outline intersections for the current */
- /* scanline. */
- /* */
- /* - Sort these intersections (in increasing order). */
- /* */
- /* - Pair intersections to create spans (horizontal pixel segments) */
- /* that are then `drawn' by calling a `sweep_span' function. */
- /* */
- /* - Check for dropouts: If a span is too small to be drawn, it must */
- /* be re-adjusted in order to make it visible again. */
- /* */
- /* The sweep starts from the bottom of the outline (ymin) and goes */
- /* upwards (to ymax). Thus, the function manages the following: */
- /* */
- /* - A linked list of the profiles which are above the current */
- /* scanline. It is called the `wait' list as it contains all the */
- /* profiles waiting to be `activated' during the sweep. It contains */
- /* all profiles initially. */
- /* */
- /* - A linked list of the profiles covering the current scanline, */
- /* i.e., all the profiles that contain an intersection for the */
- /* current scanline. It is called the `draw' list. */
- /* */
- /* A profile travels from the wait list to the draw list if the */
- /* current scanline reaches its bottom border (its ymin). It is also */
- /* removed from the draw list (and becomes unlisted) when the current */
- /* scanline reaches the scanline above its upper border (its ymax). */
- /* */
- /* These positions correspond to the `extrema' table built by */
- /* Finalize_Profile_Table(). */
- /* */
- /* The draw list is always sorted in increasing order of the X */
- /* coordinates. We use a bubble sort because it is easy to implement */
- /* on a linked list, and because in 95% cases, the list is already */
- /* correctly sorted when going from one scanline to the other. */
- /* */
- /* The extrema table gives the scanline coordinates at which at least */
- /* one profile must be removed from the `draw' list, or another one */
- /* must be moved from the `wait' to `draw' lists. */
- /* */
- /* Note that when a dropout is detected, the corresponding span is not */
- /* drawn immediately but kept on a temporary list. All dropout spans */
- /* are drawn after the regular spans on a given scanline. This is a */
- /* requirement of the TrueType specification to properly implement */
- /* some drop-out control modes -- yes, it's weird! */
- /* */
- /* Finally, the parser contains four function pointers that are called */
- /* by Draw_Sweep(). Each rendering mode (monochrome, anti-aliased-5, */
- /* and anti-aliased-17) provide its own set of such functions. These */
- /* are: */
- /* */
- /* sweep_init: Called only when the sweep starts. Used to set */
- /* up some variables. */
- /* */
- /* sweep_span: Used to draw a horizontal span on the current */
- /* scanline. */
- /* */
- /* sweep_test_pixel: Used to test a pixel's intensity, as it is */
- /* required for drop-out control. */
- /* */
- /* sweep_put_pixel: Used to write a single pixel when a drop-out */
- /* needs to be lighted/drawn. */
- /* */
- /*************************************************************************/
+ e1 = TRUNC( e1 ) / 2;
+ if ( e1 < ras.target.rows )
+ {
+ pixel = ras.gTarget - e1*ras.target.pitch + y/2;
+ if (ras.target.pitch > 0)
+ pixel += (ras.target.rows-1)*ras.target.pitch;
+ if (pixel[0] == ras.grays[0])
+ pixel[0] = color;
+ }
+ }
+ }
- /*************************************************************************/
- /* */
- /* Generic Sweep Drawing routine */
- /* */
- static
- TResult Draw_Sweep( RAS_ARG )
+#endif /* FT_RASTER_OPTION_ANTI_ALIASING */
+
+
+/********************************************************************/
+/* */
+/* Generic Sweep Drawing routine */
+/* */
+/********************************************************************/
+
+ static Bool Draw_Sweep( RAS_ARG )
{
- TScan y, y_change, y_height;
+ Short y, y_change, y_height;
PProfile P, Q, P_Left, P_Right;
- TScan min_Y, max_Y, top, bottom, dropouts;
+ Short min_Y, max_Y, top, bottom, dropouts;
- TPos x1, x2, e1, e2;
+ Long x1, x2, xs, e1, e2;
TProfileList wait;
- TProfileList draw;
+ TProfileList draw_left, draw_right;
- #ifdef DEBUG_RAS
- int y_set = 0;
- #endif
/* Init empty linked lists */
+
Init_Linked( &wait );
- Init_Linked( &draw );
- /* first, compute min and max Y -- and add profiles to the wait list */
- P = ras.start_prof;
- max_Y = TRUNC( ras.minY );
- min_Y = TRUNC( ras.maxY );
+ Init_Linked( &draw_left );
+ Init_Linked( &draw_right );
+
+ /* first, compute min and max Y */
+
+ P = ras.fProfile;
+ max_Y = (short)TRUNC( ras.minY );
+ min_Y = (short)TRUNC( ras.maxY );
while ( P )
{
Q = P->link;
- bottom = P->start;
- top = P->start + P->height-1;
+ bottom = (Short)P->start;
+ top = (Short)P->start + P->height-1;
if ( min_Y > bottom ) min_Y = bottom;
if ( max_Y < top ) max_Y = top;
@@ -3411,20 +2442,21 @@
P = Q;
}
- /* Check the extrema table */
- if ( ras.n_extrema == 0 )
+ /* Check the Y-turns */
+ if ( ras.numTurns == 0 )
{
- ras.error = ErrRaster_Invalid_Outline;
+ ras.error = Raster_Err_Invalid;
return FAILURE;
}
/* Now inits the sweep */
- FT_TRACE2(( "draw_sweep: initialize sweep\n" ));
- ras.render.init( RAS_VAR_ &min_Y, &max_Y );
- FT_TRACE2(( " init min_y = %d, max_y = %d\n", min_Y, max_Y ));
+
+ ras.Proc_Sweep_Init( RAS_VARS &min_Y, &max_Y );
/* Then compute the distance of each profile from min_Y */
+
P = wait;
+
while ( P )
{
P->countL = P->start - min_Y;
@@ -3432,490 +2464,429 @@
}
/* Let's go */
+
y = min_Y;
y_height = 0;
- if ( ras.n_extrema > 0 &&
- ras.pool_size[-ras.n_extrema] == min_Y )
- ras.n_extrema--;
+ if ( ras.numTurns > 0 &&
+ ras.sizeBuff[-ras.numTurns] == min_Y )
+ ras.numTurns--;
- FT_TRACE2(( "starting loop with n_extrema = %d", ras.n_extrema ));
- while ( ras.n_extrema > 0 )
+ while ( ras.numTurns > 0 )
{
- PProfile prof = wait;
+ /* look in the wait list for new activations */
+ P = wait;
- /* look in the wait list for new activations */
- while ( prof )
+ while ( P )
{
- PProfile next = prof->link;
-
- prof->countL -= y_height;
- if ( prof->countL == 0 )
+ Q = P->link;
+ P->countL -= y_height;
+ if ( P->countL == 0 )
{
- /* move the profile from the wait list to the draw list */
- DelOld( &wait, prof );
- InsNew( &draw, prof );
+ DelOld( &wait, P );
+
+ switch ( P->flow )
+ {
+ case Flow_Up: InsNew( &draw_left, P ); break;
+ case Flow_Down: InsNew( &draw_right, P ); break;
+ }
}
- prof = next;
+
+ P = Q;
}
- /* Sort the draw list */
- Sort( &draw );
+ /* Sort the drawing lists */
- /* compute next y extremum scanline; we won't change the */
- /* elements of the wait and draw lists until there */
- y_change = ras.pool_size[-ras.n_extrema--];
- y_height = y_change - y;
+ Sort( &draw_left );
+ Sort( &draw_right );
- FT_TRACE2(( ">>> y = %d, y_change = %d, y_height = %d",
- y, y_change, y_height ));
+ y_change = (Short)ras.sizeBuff[-ras.numTurns--];
+ y_height = y_change - y;
while ( y < y_change )
{
- int window;
- PProfile left;
-
/* Let's trace */
- dropouts = 0;
- /* skip to next line if there is no active profile there */
- if ( !draw ) goto Next_Line;
-
- left = draw;
- window = left->flow;
- prof = left->link;
+ dropouts = 0;
- FT_TRACE2(( ">>> line y = %d", y ));
+ P_Left = draw_left;
+ P_Right = draw_right;
- while ( prof )
+ while ( P_Left )
{
- PProfile next = prof->link;
+ x1 = P_Left ->X;
+ x2 = P_Right->X;
- window += prof->flow;
+ if ( x1 > x2 )
+ {
+ xs = x1;
+ x1 = x2;
+ x2 = xs;
+ }
- if ( window == 0 )
+ if ( x2-x1 <= ras.precision )
{
- x1 = left->X;
- x2 = prof->X;
+ e1 = FLOOR( x1 );
+ e2 = CEILING( x2 );
- if ( x1 > x2 )
+ if ( ras.dropOutControl != 0 &&
+ (e1 > e2 || e2 == e1 + ras.precision) )
{
- TPos xs = x1;
+ /* a drop out was detected */
- x1 = x2;
- x2 = xs;
- }
+ P_Left ->X = x1;
+ P_Right->X = x2;
- if ( x2 - x1 <= PRECISION && ras.dropout_mode )
- {
- e1 = CEILING( x1 );
- e2 = FLOOR( x2 );
+ /* mark profile for drop-out processing */
+ P_Left->countL = 1;
+ dropouts++;
- if ( e1 > e2 || e2 == e1 + PRECISION )
- {
- /* a drop out was detected */
- left->X = x1;
- prof->X = x2;
-
- /* mark profiles for drop-out processing */
- left->countL = 1;
- prof->countL = 2;
- dropouts++;
- goto Skip_To_Next;
- }
+ goto Skip_To_Next;
}
+ }
- FT_TRACE2(( "drawing span ( y=%d, x1=%d, x2=%d )", y, x1, x2 ));
- #ifdef DEBUG_RAS
- if (!y_set)
- {
- y_set = 1;
- fprintf( stderr, "%3d", y );
- }
- fprintf( stderr, " [%.2f-%.2f]", x1*1.0/PRECISION, x2*1.0/PRECISION );
- #endif
- ras.render.span( RAS_VAR_ y, x1, x2 );
+ ras.Proc_Sweep_Span( RAS_VARS y, x1, x2, P_Left, P_Right );
Skip_To_Next:
- left = next;
- }
- prof = next;
+
+ P_Left = P_Left->link;
+ P_Right = P_Right->link;
}
/* now perform the dropouts _after_ the span drawing */
/* drop-outs processing has been moved out of the loop */
/* for performance tuning */
- if ( dropouts > 0 )
+ if (dropouts > 0)
goto Scan_DropOuts;
Next_Line:
- ras.render.step( RAS_VAR );
+
+ ras.Proc_Sweep_Step( RAS_VAR );
y++;
- #ifdef DEBUG_RAS
- if (y_set)
- {
- fprintf( stderr, "\n" );
- y_set = 0;
- }
- #endif
if ( y < y_change )
- Sort( &draw );
+ {
+ Sort( &draw_left );
+ Sort( &draw_right );
+ }
- FT_TRACE4(( "line sorted for next operation" ));
}
/* Now finalize the profiles that needs it */
- FT_TRACE2(( "finalizing profiles..." ));
{
- PProfile prof, next;
-
- prof = draw;
- while ( prof )
+ PProfile Q, P;
+ P = draw_left;
+ while ( P )
{
- next = prof->link;
- if (prof->height == 0)
- DelOld( &draw, prof );
- prof = next;
+ Q = P->link;
+ if ( P->height == 0 )
+ DelOld( &draw_left, P );
+ P = Q;
}
}
- FT_TRACE2(( "profiles finalized for this run" ));
+ {
+ PProfile Q, P = draw_right;
+ while ( P )
+ {
+ Q = P->link;
+ if ( P->height == 0 )
+ DelOld( &draw_right, P );
+ P = Q;
+ }
+ }
}
/* for gray-scaling, flushes the bitmap scanline cache */
while ( y <= max_Y )
{
- ras.render.step( RAS_VAR );
+ ras.Proc_Sweep_Step( RAS_VAR );
y++;
}
return SUCCESS;
-
Scan_DropOuts :
- P_Left = draw;
+ P_Left = draw_left;
+ P_Right = draw_right;
- while ( dropouts > 0 )
+ while ( P_Left )
{
- TPos e1, e2;
- PProfile left, right;
-
- while ( P_Left->countL != 1 )
- P_Left = P_Left->link;
- P_Right = P_Left->link;
- while ( P_Right->countL != 2 )
- P_Right = P_Right->link;
-
- P_Left->countL = 0;
- P_Right->countL = 0;
-
- /* Now perform the dropout control */
- x1 = P_Left->X;
- x2 = P_Right->X;
-
- left = ( ras.flipped ? P_Right : P_Left );
- right = ( ras.flipped ? P_Left : P_Right );
-
- FT_TRACE2(( "performing drop-out control ( x1= %d, x2 = %d )",
- x1, x2 ));
-
- #ifdef DEBUG_RAS
- if (!y_set)
- {
- y_set = 1;
- fprintf( stderr, "%3d", y );
- }
- fprintf( stderr, " <%.2f-%.2f>", P_Left->X*1.0/PRECISION, P_Right->X*1.0/PRECISION );
- #endif
-
- e1 = CEILING( x1 );
- e2 = FLOOR ( x2 );
-
- if ( e1 > e2 )
+ if ( P_Left->countL )
{
- if ( e1 == e2 + PRECISION )
- {
- switch ( ras.dropout_mode )
- {
- case 1:
- e1 = e2;
- break;
-
- case 4:
- e1 = CEILING( (x1 + x2 + 1) / 2 );
- break;
-
- case 2:
- case 5:
- /* Drop-out Control Rule #4 */
-
- /* The spec is not very clear regarding rule #4. It */
- /* presents a method that is way too costly to implement */
- /* while the general idea seems to get rid of `stubs'. */
- /* */
- /* Here, we only get rid of stubs recognized when: */
- /* */
- /* upper stub: */
- /* */
- /* - P_Left and P_Right are in the same contour */
- /* - P_Right is the successor of P_Left in that contour */
- /* - y is the top of P_Left and P_Right */
- /* */
- /* lower stub: */
- /* */
- /* - P_Left and P_Right are in the same contour */
- /* - P_Left is the successor of P_Right in that contour */
- /* - y is the bottom of P_Left */
- /* */
-
- /* upper stub test */
- if ( ( left->next == right && left->height <= 0 ) ||
-
- /* lower stub test */
- ( right->next == left && left->start == y ) ||
-
- /* check that the rightmost pixel isn't set */
- ras.render.test_pixel( RAS_VAR_ y, TRUNC(e1)) )
- goto Next_Dropout;
-
- if ( ras.dropout_mode == 2 )
- e1 = e2;
- else
- e1 = CEILING( (x1 + x2 + 1)/2 );
-
- break;
-
- default:
- goto Next_Dropout; /* Unsupported mode */
- }
- }
- else
- goto Next_Dropout;
+ P_Left->countL = 0;
+ /* dropouts--; -- this is useful when debugging only */
+ ras.Proc_Sweep_Drop( RAS_VARS y,
+ P_Left->X,
+ P_Right->X,
+ P_Left,
+ P_Right );
}
- FT_TRACE2(( " -> setting pixel" ));
- ras.render.set_pixel( RAS_VAR_ y,
- TRUNC( e1 ),
- (x2 - x1) >> ras.scale_shift );
- Next_Dropout:
-
- dropouts--;
+ P_Left = P_Left->link;
+ P_Right = P_Right->link;
}
+
goto Next_Line;
}
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Render_Single_Pass */
- /* */
- /* <Description> */
- /* Performs one sweep with sub-banding. */
- /* */
- /* <Input> */
- /* flipped :: whether or not we have to flip. */
- /* */
- /* <Returns> */
- /* Error code. 0 means success. */
- /* */
- static
- int Render_Single_Pass( RAS_ARG_ int flipped )
- {
- TBand* band;
-
-
- ras.flipped = flipped;
+/****************************************************************************/
+/* */
+/* Function: Render_Single_Pass */
+/* */
+/* Description: Performs one sweep with sub-banding. */
+/* */
+/* Input: _XCoord, _YCoord : x and y coordinates arrays */
+/* */
+/* Returns: SUCCESS on success */
+/* FAILURE if any error was encountered during render. */
+/* */
+/****************************************************************************/
- band = ras.band_stack;
+ static FT_Error Render_Single_Pass( RAS_ARGS Bool flipped )
+ {
+ Short i, j, k;
- FT_TRACE2(( "raster: entering render_single_pass (flipped = %d)\n",
- flipped ));
- while ( band >= ras.band_stack )
+ while ( ras.band_top >= 0 )
{
- ras.maxY = ((long)band[0].y_max << PRECISION_BITS) - 1;
- ras.minY = (long)band[0].y_min << PRECISION_BITS;
+ ras.maxY = (Long)ras.band_stack[ras.band_top].y_max * ras.precision;
+ ras.minY = (Long)ras.band_stack[ras.band_top].y_min * ras.precision;
- ras.cursor = ras.pool;
- ras.error = 0;
+ ras.top = ras.buff;
- FT_TRACE2(( "raster: band = [ %d, %d ]\n",
- band[0].y_min,
- band[0].y_max ));
+ ras.error = Raster_Err_None;
- if ( Convert_Glyph( RAS_VAR_ ras.outline ) )
+ if ( Convert_Glyph( RAS_VARS flipped ) )
{
- int bottom, top, half;
-
+ if ( ras.error != Raster_Err_Overflow ) return FAILURE;
- if ( ras.error != ErrRaster_Overflow )
- return FAILURE;
- ras.error = ErrRaster_Ok;
-
- FT_TRACE2(( "conversion failure, performing sub-banding\n" ));
+ ras.error = Raster_Err_None;
/* sub-banding */
-#ifdef DEBUG_RASTER
- ClearBand( RAS_VAR_ TRUNC( ras.minY ), TRUNC( ras.maxY ) );
-#endif
+ #ifdef DEBUG_RASTER
+ ClearBand( RAS_VARS TRUNC( ras.minY ), TRUNC( ras.maxY ) );
+ #endif
- bottom = band[0].y_min;
- top = band[0].y_max;
- half = ( top - bottom ) >> 1;
+ i = ras.band_stack[ras.band_top].y_min;
+ j = ras.band_stack[ras.band_top].y_max;
- if ( band >= ras.band_stack + 7 || half == 0 )
+ k = ( i + j ) / 2;
+
+ if ( ras.band_top >= 7 || k < i )
{
- ras.band_top = 0;
- ras.error = ErrRaster_Invalid_Outline;
+ ras.band_top = 0;
+ ras.error = Raster_Err_Invalid;
return ras.error;
}
- band[1].y_min = bottom + half;
- band[1].y_max = top;
- band[0].y_max = bottom + half;
+ ras.band_stack[ras.band_top+1].y_min = k;
+ ras.band_stack[ras.band_top+1].y_max = j;
+
+ ras.band_stack[ras.band_top].y_max = k - 1;
- band ++;
+ ras.band_top++;
}
else
{
- FT_TRACE2(( "conversion succeeded, span drawing sweep\n" ));
-#if 1 /* for debugging */
- if ( ras.start_prof )
- if ( Draw_Sweep( RAS_VAR ) )
- return ras.error;
-#endif
- band --;
+ if ( ras.fProfile )
+ if ( Draw_Sweep( RAS_VAR ) ) return ras.error;
+ ras.band_top--;
}
}
- FT_TRACE2(( "raster: exiting render_single_pass\n" ));
-
- return SUCCESS; /* success */
+ return FT_Err_Ok;
}
- static
- int Raster_Render1( FT_Raster raster )
- {
- int error;
+/****************************************************************************/
+/* */
+/* Function: Render_Glyph */
+/* */
+/* Description: Renders a glyph in a bitmap. Sub-banding if needed. */
+/* */
+/* Input: AGlyph Glyph record */
+/* */
+/* Returns: SUCCESS on success. */
+/* FAILURE if any error was encountered during rendering. */
+/* */
+/****************************************************************************/
+ LOCAL_FUNC
+ FT_Error Render_Glyph( RAS_ARG )
+ {
+ FT_Error error;
- if ( ras.target.width > ABS(ras.target.pitch)*8 )
- return ErrRaster_Invalid_Map;
+ Set_High_Precision( RAS_VARS ras.outline.flags & ft_outline_high_precision );
+ ras.scale_shift = ras.precision_shift;
+ ras.dropOutControl = 2;
+ ras.second_pass = !(ras.outline.flags & ft_outline_single_pass);
- ras.scale_shift = PRECISION_BITS - INPUT_BITS;
- ras.scale_delta = PRECISION_HALF;
/* Vertical Sweep */
+ ras.Proc_Sweep_Init = Vertical_Sweep_Init;
+ ras.Proc_Sweep_Span = Vertical_Sweep_Span;
+ ras.Proc_Sweep_Drop = Vertical_Sweep_Drop;
+ ras.Proc_Sweep_Step = Vertical_Sweep_Step;
+
ras.band_top = 0;
ras.band_stack[0].y_min = 0;
- ras.band_stack[0].y_max = ras.target.rows;
+ ras.band_stack[0].y_max = ras.target.rows - 1;
- ras.render = vertical_render_mono;
- ras.bit_width = ras.target.width;
- ras.bit_buffer = (unsigned char*)ras.target.buffer;
+ ras.bWidth = ras.target.width;
+ ras.bTarget = (Byte*)ras.target.buffer;
- if ( (error = Render_Single_Pass( RAS_VAR_ 0 )) != 0 )
+ if ( (error = Render_Single_Pass( RAS_VARS 0 )) != 0 )
return error;
/* Horizontal Sweep */
-
- if ( ras.second_pass && ras.dropout_mode != 0 )
+ if ( ras.second_pass && ras.dropOutControl != 0 )
{
- ras.render = horizontal_render_mono;
+ ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+ ras.Proc_Sweep_Span = Horizontal_Sweep_Span;
+ ras.Proc_Sweep_Drop = Horizontal_Sweep_Drop;
+ ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
+
ras.band_top = 0;
ras.band_stack[0].y_min = 0;
- ras.band_stack[0].y_max = ras.target.width;
+ ras.band_stack[0].y_max = ras.target.width - 1;
- if ( (error = Render_Single_Pass( RAS_VAR_ 1 )) != 0 )
+ if ( (error = Render_Single_Pass( RAS_VARS 1 )) != 0 )
return error;
}
- return ErrRaster_Ok;
+ return FT_Err_Ok;
}
-#ifdef FT_RASTER_OPTION_ANTI_ALIAS
-
+/****************************************************************************/
+/* */
+/* Function: Render_Gray_Glyph */
+/* */
+/* Description: Renders a glyph with grayscaling. Sub-banding if needed. */
+/* */
+/* Input: AGlyph Glyph record */
+/* */
+/* Returns: SUCCESS on success */
+/* FAILURE if any error was encountered during rendering. */
+/* */
+/****************************************************************************/
+
+#ifdef FT_RASTER_OPTION_ANTI_ALIASING
+ LOCAL_FUNC
+ FT_Error Render_Gray_Glyph( RAS_ARG )
+ {
+ Long pixel_width;
+ FT_Error error;
- static
- int Raster_Render8( FT_Raster raster )
- {
- int error;
+ Set_High_Precision( RAS_VARS ras.outline.flags & ft_outline_high_precision );
+ ras.scale_shift = ras.precision_shift+1;
+ ras.dropOutControl = 2;
+ ras.second_pass = !(ras.outline.flags & ft_outline_single_pass);
- if ( ras.target.width > ABS(ras.target.pitch) )
- return ErrRaster_Invalid_Map;
/* Vertical Sweep */
+
ras.band_top = 0;
ras.band_stack[0].y_min = 0;
- ras.band_stack[0].y_max = ras.target.rows;
+ ras.band_stack[0].y_max = 2 * ras.target.rows - 1;
- ras.scale_shift = PRECISION_BITS - INPUT_BITS;
- ras.scale_delta = PRECISION_HALF;
- ras.dropout_mode = 2;
+ ras.bWidth = ras.gray_width;
+ pixel_width = 2*((ras.target.width + 3) >> 2);
+
+ if ( ras.bWidth > pixel_width )
+ ras.bWidth = pixel_width;
+
+ ras.bWidth = ras.bWidth * 8;
+ ras.bTarget = (Byte*)ras.gray_lines;
+ ras.gTarget = (Byte*)ras.target.buffer;
- ras.render = vertical_render_gray;
- ras.bit_width = ras.target.width;
- ras.bit_buffer = (unsigned char*)ras.target.buffer;
- ras.pix_buffer = (unsigned char*)ras.target.buffer;
+ ras.Proc_Sweep_Init = Vertical_Gray_Sweep_Init;
+ ras.Proc_Sweep_Span = Vertical_Sweep_Span;
+ ras.Proc_Sweep_Drop = Vertical_Sweep_Drop;
+ ras.Proc_Sweep_Step = Vertical_Gray_Sweep_Step;
- error = Render_Single_Pass( RAS_VAR_ 0 );
- if ( error )
+ error = Render_Single_Pass( RAS_VARS 0 );
+ if (error)
return error;
-#if 1
/* Horizontal Sweep */
- ras.render = horizontal_render_gray;
- ras.band_top = 0;
- ras.bit_width = ras.target.rows;
- ras.band_stack[0].y_min = 0;
- ras.band_stack[0].y_max = ras.target.width;
-
- return Render_Single_Pass( RAS_VAR_ 1 );
-#else
- return 0;
-#endif
- }
-
+ if ( ras.second_pass && ras.dropOutControl != 0 )
+ {
+ ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+ ras.Proc_Sweep_Span = Horizontal_Gray_Sweep_Span;
+ ras.Proc_Sweep_Drop = Horizontal_Gray_Sweep_Drop;
+ ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
-#else /* FT_RASTER_OPTION_ANTI_ALIAS */
+ ras.band_top = 0;
+ ras.band_stack[0].y_min = 0;
+ ras.band_stack[0].y_max = ras.target.width * 2 - 1;
+ error = Render_Single_Pass( RAS_VARS 1 );
+ if (error)
+ return error;
+ }
- static
- int Raster_Render8( FT_Raster raster )
+ return FT_Err_Ok;
+ }
+#else
+ LOCAL_FUNC
+ FT_Error Render_Gray_Glyph( RAS_ARG )
{
- return ErrRaster_Unimplemented;
+ UNUSED_RASTER
+ return Raster_Err_Unsupported;
}
+#endif
-#endif /* FT_RASTER_OPTION_ANTI_ALIAS */
-
-
+ static void ft_black_init( TRaster_Instance* raster )
+ {
+ FT_UInt n;
+ FT_ULong c;
+
+ /* setup count table */
+ for ( n = 0; n < 256; n++ )
+ {
+ c = (n & 0x55) + ((n & 0xAA) >> 1);
+
+ c = ((c << 6) & 0x3000) |
+ ((c << 4) & 0x0300) |
+ ((c << 2) & 0x0030) |
+ (c & 0x0003);
+
+ raster->count_table[n] = c;
+ }
+
+ /* set default 5-levels gray palette */
+ for ( n = 0; n < 5; n++ )
+ raster->grays[n] = (n*127/4);
+
+ raster->gray_width = RASTER_GRAY_LINES/2;
+ }
/**** RASTER OBJECT CREATION : in standalone mode, we simply use *****/
/**** a static object .. *****/
#ifdef _STANDALONE_
static
- int ft_raster_new( void* memory, FT_Raster *araster )
+ int ft_black_new( void* memory, FT_Raster *araster )
{
static FT_RasterRec_ the_raster;
*araster = &the_raster;
memset( &the_raster, sizeof(the_raster), 0 );
+ ft_black_init( &the_raster );
return 0;
}
static
- void ft_raster_done( FT_Raster raster )
+ void ft_black_done( FT_Raster raster )
{
/* nothing */
raster->init = 0;
@@ -3926,15 +2897,17 @@ Scan_DropOuts :
#include <freetype/internal/ftobjs.h>
static
- int ft_raster_new( FT_Memory memory, FT_Raster* araster )
+ int ft_black_new( FT_Memory memory, TRaster_Instance* *araster )
{
- FT_Error error;
- FT_Raster raster;
+ FT_Error error;
+ TRaster_Instance* raster;
*araster = 0;
if ( !ALLOC( raster, sizeof(*raster) ))
{
raster->memory = memory;
+ ft_black_init( raster );
+
*araster = raster;
}
@@ -3942,7 +2915,7 @@ Scan_DropOuts :
}
static
- void ft_raster_done( FT_Raster raster )
+ void ft_black_done( TRaster_Instance* raster )
{
FT_Memory memory = (FT_Memory)raster->memory;
FREE( raster );
@@ -3951,71 +2924,78 @@ Scan_DropOuts :
#endif
- static void ft_raster_reset( FT_Raster raster,
- const char* pool_base,
- long pool_size )
+ static void ft_black_reset( TRaster_Instance* raster,
+ const char* pool_base,
+ long pool_size )
{
if ( raster && pool_base && pool_size >= 4096 )
{
/* save the pool */
- raster->pool = (PPos)pool_base;
- raster->pool_size = raster->pool + pool_size / sizeof ( TPos );
+ raster->buff = (PLong)pool_base;
+ raster->sizeBuff = raster->buff + pool_size / sizeof (Long);
}
}
+ static void ft_black_set_mode( TRaster_Instance* raster,
+ unsigned long mode,
+ const char* palette )
+ {
+ if (mode==FT_MAKE_TAG('p','a','l','5'))
+ {
+ /* set 5-levels gray palette */
+ raster->grays[0] = palette[0];
+ raster->grays[1] = palette[1];
+ raster->grays[2] = palette[2];
+ raster->grays[3] = palette[3];
+ raster->grays[4] = palette[4];
+ }
+ }
+
static
- int ft_raster_render( FT_Raster raster,
- FT_Raster_Params* params )
+ int ft_black_render( TRaster_Instance* raster,
+ FT_Raster_Params* params )
{
FT_Outline* outline = (FT_Outline*)params->source;
FT_Bitmap* target_map = params->target;
- if ( !raster || !raster->pool || !raster->pool_size )
- return ErrRaster_Uninitialized_Object;
+ if ( !raster || !raster->buff || !raster->sizeBuff )
+ return Raster_Err_Not_Ini;
if ( !outline || !outline->contours || !outline->points )
- return ErrRaster_Invalid_Outline;
+ return Raster_Err_Invalid;
/* return immediately if the outline is empty */
if ( outline->n_points == 0 || outline->n_contours <= 0 )
- return ErrRaster_Ok;
+ return Raster_Err_None;
if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 )
- return ErrRaster_Invalid_Outline;
+ return Raster_Err_Invalid;
if ( !target_map || !target_map->buffer )
- return ErrRaster_Invalid_Map;
-
- ras.outline = outline;
- ras.target = *target_map;
-
- /* Note that we always use drop-out mode 2, because it seems that */
- /* it's the only way to do to get results consistent with Windows */
- /* rendering.. */
- ras.dropout_mode = 2;
-
- ras.second_pass = (outline->flags & ft_outline_single_pass) == 0;
- SET_High_Precision( (char)((outline->flags & ft_outline_high_precision)!= 0) );
+ return Raster_Err_Invalid;
/* this version of the raster does not support direct rendering, sorry */
if ( params->flags & ft_raster_flag_direct )
- return ErrRaster_Unimplemented;
+ return Raster_Err_Unsupported;
- return ( params->flags & ft_raster_flag_aa
- ? Raster_Render8( raster )
- : Raster_Render1( raster ) );
+ ras.outline = *outline;
+ ras.target = *target_map;
+
+ return ( params->flags & ft_raster_flag_aa
+ ? Render_Gray_Glyph( raster )
+ : Render_Glyph( raster ) );
}
FT_Raster_Funcs ft_default_raster =
{
ft_glyph_format_outline,
- (FT_Raster_New_Func) ft_raster_new,
- (FT_Raster_Reset_Func) ft_raster_reset,
- (FT_Raster_Set_Mode_Func) 0,
- (FT_Raster_Render_Func) ft_raster_render,
- (FT_Raster_Done_Func) ft_raster_done
+ (FT_Raster_New_Func) ft_black_new,
+ (FT_Raster_Reset_Func) ft_black_reset,
+ (FT_Raster_Set_Mode_Func) ft_black_set_mode,
+ (FT_Raster_Render_Func) ft_black_render,
+ (FT_Raster_Done_Func) ft_black_done
};