still working on that damn rasterizer bug !! ;-)
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
diff --git a/demos/Makefile b/demos/Makefile
index 5a1b905..3a69279 100644
--- a/demos/Makefile
+++ b/demos/Makefile
@@ -190,6 +190,9 @@ else
$(OBJ_)ftrast.$O: $(SRC_DIR_)ftrast.c
$(COMPILE) $T$@ $<
+ $(OBJ_)ftrast2.$O: $(SRC_DIR_)ftrast2.c
+ $(COMPILE) $T$@ $<
+
$(OBJ_)fttry.$O: $(SRC_DIR_)fttry.c
$(COMPILE) $T$@ $<
@@ -264,8 +267,8 @@ else
$(LINK)
- $(BIN_)ftview$E: $(OBJ_)ftview.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) $(OBJ_)ftrast.$O
- $(GRAPH_LINK)
+ $(BIN_)ftview$E: $(OBJ_)ftview.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) $(OBJ_)ftrast2.$O
+ $(GRAPH_LINK) $(OBJ_)ftrast2.$O
$(BIN_)ftstring$E: $(OBJ_)ftstring.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ)
$(GRAPH_LINK)
diff --git a/demos/src/ftrast.c b/demos/src/ftrast.c
index 07c8df4..6f86a72 100644
--- a/demos/src/ftrast.c
+++ b/demos/src/ftrast.c
@@ -23,6 +23,75 @@
#include "ftrast.h"
#include <ftcalc.h> /* for FT_MulDiv only */
+ /*************************************************************************/
+ /* */
+ /* 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 top */
+ /* */
+ /* The top of the profile stack is kept in the `top' 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 `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: */
+ /* */
+ /* _ _ _______________________________________ */
+ /* | | */
+ /* <--| sorted list of | */
+ /* <--| extrema scanlines | */
+ /* _ _ __________________|____________________| */
+ /* */
+ /* ^ ^ */
+ /* | | */
+ /* maxBuff sizeBuff = end of 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. */
+ /* */
+ /*************************************************************************/
+
/****************************************************************/
/****************************************************************/
/** **/
diff --git a/demos/src/ftrast2.c b/demos/src/ftrast2.c
new file mode 100644
index 0000000..7f8715c
--- /dev/null
+++ b/demos/src/ftrast2.c
@@ -0,0 +1,3971 @@
+/*******************************************************************
+ *
+ * ftraster.c 2.0
+ *
+ * The FreeType glyph rasterizer (body).
+ *
+ * Copyright 1996-1998 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 outlines
+ * 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 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 series of segments and arcs).
+ *
+ ******************************************************************/
+
+#include "ftraster.h"
+#include <freetype.h> /* for FT_Outline_Decompose */
+
+#ifndef EXPORT_FUNC
+#define EXPORT_FUNC /* nothing */
+#endif
+
+
+#ifndef _xxFREETYPE_
+
+/**************************************************************************/
+/* */
+/* 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_OPTION_ANTI_ALIAS */
+/* */
+/* Define this configuration macro if you want to support anti-aliasing */
+/* */
+#define FT_RASTER_OPTION_ANTI_ALIAS
+
+/**************************************************************************/
+/* */
+/* FT_RASTER_OPTION_CONIC_BEZIERS */
+/* */
+/* Define this configuration macro if your source outlines contain */
+/* second-order Bezier arcs. Typically, these are TrueType outlines.. */
+/* */
+#define FT_RASTER_CONIC_BEZIERS
+
+/**************************************************************************/
+/* */
+/* FT_RASTER_OPTION_CUBIC_BEZIERS */
+/* */
+/* Define this configuration macro if your source outlines contain */
+/* third-order Bezier arcs. Typically, these are Type1 outlines.. */
+/* */
+#define FT_RASTER_CUBIC_BEZIERS
+
+/**************************************************************************/
+/* */
+/* FT_RASTER_ANTI_ALIAS_5 */
+/* */
+/* Define this configuration macro if you want to enable the 5-grays */
+/* anti-aliasing mode.. Ignored if FT_RASTER_OPTION_ANTI_ALIAS isn't */
+/* defined.. */
+/* */
+#define FT_RASTER_ANTI_ALIAS_5
+
+/**************************************************************************/
+/* */
+/* FT_RASTER_ANTI_ALIAS_17 */
+/* */
+/* Define this configuration macro if you want to enable the 17-grays */
+/* anti-aliasing mode.. Ignored if FT_RASTER_OPTION_ANTI_ALIAS isn't */
+/* defined.. */
+/* */
+#define FT_RASTER_ANTI_ALIAS_17
+
+/**************************************************************************/
+/* */
+/* FT_RASTER_LITTLE_ENDIAN */
+/* FT_RASTER_BIG_ENDIAN */
+/* */
+/* The default anti-alias routines are processor-independent, but slow. */
+/* Define one of these macros to suit your own system, and enjoy */
+/* greatly improved rendering speed */
+/* */
+
+/* #define FT_RASTER_LITTLE_ENDIAN */
+/* #define FT_RASTER_BIG_ENDIAN */
+
+#else /* _FREETYPE_ */
+
+/**************************************************************************/
+/* */
+/* 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
+#endif
+
+#define FT_RASTER_CONIC_BEZIERS
+#define FT_RASTER_CUBIC_BEZIERS
+
+#define FT_RASTER_ANTI_ALIAS_5
+#undef FT_RASTER_ANTI_ALIAS_17
+
+#ifdef FT_CONFIG_OPTION_LITTLE_ENDIAN
+#define FT_RASTER_LITTLE_ENDIAN
+#endif
+
+#ifdef FT_CONFIG_OPTION_BIG_ENDIAN
+#define FT_RASTER_BIG_ENDIAN
+#endif
+
+#endif /* _FREETYPE_ */
+
+
+/* FT_RASTER_ANY_ENDIAN indicates that no endianess was defined */
+/* through 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 there (you never know your target */
+/* environment). */
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef NULL
+#define NULL (void*)0
+#endif
+
+
+#undef FAILURE
+#define FAILURE TRUE
+
+#undef SUCCESS
+#define SUCCESS FALSE
+
+
+/* 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_ARGS FT_Raster raster,
+#define RAS_ARG FT_Raster raster
+
+/* used to call a function within this component, first parameter */
+#define RAS_VARS raster,
+#define RAS_VAR raster
+
+/* used to access the current raster object, with a '.' instead of a '->' */
+#define ras (*raster)
+
+
+/* For anti-aliasing modes, we use a 2 or 4 lines intermediate bitmap which */
+/* is filtered repeatedly to render each pixmap row. The following macro */
+/* defines this buffer's size in bytes (which is part of raster objects) */
+#define ANTI_ALIAS_BUFFER_SIZE 2048
+
+
+/* Error codes returned by the scan-line converter/raster */
+
+#define ErrRaster_Ok 0
+#define ErrRaster_Uninitialised_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 SET_High_Precision(p) Set_High_Precision( RAS_VARS 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 be 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 */
+#endif
+
+
+#define MaxBezier 32 /* The maximum number of stacked Bezier curves. */
+ /* Setting this constant to more than 32 is a */
+ /* pure waste of space. */
+
+#define Pixel_Bits 6 /* fractional bits of *input* coordinates */
+ /* We always use 26.6, but hackers are free */
+ /* to experiment with different values */
+
+
+ /* 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 (resp. low */
+ /* or high). These are ideals in order to subdivise bezier arcs in halves */
+ /* though simple additions and shifts. */
+
+ typedef long TPos, *PPos;
+
+
+ /* The type of a scanline position/coordinate within a map */
+ typedef int TScan, *PScan;
+
+
+
+
+ /* boolean type */
+ typedef char TBool;
+
+ /* unsigned char type and array */
+ typedef unsigned char TByte, *PByte;
+
+ /* unsigned short type and array */
+ typedef unsigned short UShort, *PUShort;
+
+ /* flow */
+ enum _TFlow
+ {
+ FT_Flow_Error = 0,
+ FT_Flow_Down = -1,
+ FT_Flow_Up = 1
+ };
+
+
+ /* states/directions of each line, arc and profile */
+ enum _TDirection
+ {
+ Unknown,
+ Ascending,
+ Descending,
+ Flat
+ };
+ typedef enum _TDirection TDirection;
+
+
+ struct _TProfile;
+ typedef struct _TProfile TProfile;
+ typedef TProfile* PProfile;
+
+ 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 */
+ };
+
+ typedef PProfile TProfileList;
+ typedef PProfile* PProfileList;
+
+
+ /* Simple record used to implement a stack of bands, required */
+ /* by the sub-banding mechanism */
+ /* */
+ struct _TBand
+ {
+ TScan y_min; /* band's minimum */
+ TScan y_max; /* band's maximum */
+ };
+
+ typedef struct _TBand 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_ARGS int* min, int* max );
+
+ typedef void Function_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 );
+
+ typedef int Function_Test_Pixel( RAS_ARGS TScan y,
+ int x );
+
+ typedef void Function_Set_Pixel( RAS_ARGS TScan y,
+ int x,
+ int color );
+
+ typedef void Function_Sweep_Step( RAS_ARG );
+
+
+/* compute lowest integer coordinate below a given x */
+#define FLOOR( x ) ( (x) & ras.precision_mask )
+
+/* compute highest integer coordinate above a given x */
+#define CEILING( x ) ( ((x) + ras.precision - 1) & ras.precision_mask )
+
+/* get integer coordinate of a given 26.6 or 22.10 'x' coordinate - no round */
+#define TRUNC( x ) ( (signed long)(x) >> ras.precision_bits )
+
+/* get the fractional part of a given coordinate */
+#define FRAC( x ) ( (x) & (ras.precision - 1) )
+
+/* 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.precision_half )
+
+
+/* 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
+
+ struct _TPoint
+ {
+ TPos x, y;
+ };
+ typedef struct _TPoint TPoint;
+
+
+ /* 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. */
+
+ struct FT_RasterRec_
+ {
+ PPos cursor; /* Current cursor in render pool */
+
+ 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 bit_width; /* target bitmap width */
+ PByte bit_buffer; /* target bitmap buffer */
+ PByte pix_buffer; /* target pixmap buffer */
+
+ TPoint last;
+ long minY, maxY;
+
+ int error;
+
+ int precision_bits; /* precision related variables */
+ int precision;
+ int precision_half;
+ long precision_mask;
+ int precision_shift;
+ int precision_step;
+ int precision_jitter;
+
+ FT_Outline* outline;
+
+ int n_points; /* number of points in current glyph */
+ int n_contours; /* number of contours in current glyph */
+ int n_turns; /* number of Y-turns in outline */
+
+ TPoint* arc; /* current Bezier arc pointer */
+
+ int num_profs; /* current number of profiles */
+
+ TBool fresh; /* signals a fresh new profile which */
+ /* 'start' field must be completed */
+ TBool 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 */
+ /* of impact */
+ TDirection state; /* rendering state */
+
+ FT_Bitmap target; /* description of target bit/pixmap */
+
+ 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 */
+
+ int gray_min_x; /* current min x during gray rendering */
+ int gray_max_x; /* current max x during gray rendering */
+
+ /* dispatch variables */
+
+ Function_Sweep_Init* Proc_Sweep_Init;
+ Function_Sweep_Span* Proc_Sweep_Span;
+ Function_Sweep_Step* Proc_Sweep_Step;
+ Function_Test_Pixel* Proc_Test_Pixel;
+ Function_Set_Pixel* Proc_Set_Pixel;
+
+ int scale_shift; /* == 0 for bitmaps */
+ /* == 1 for 5-levels pixmaps */
+ /* == 2 for 17-levels pixmaps */
+
+ TByte dropout_mode; /* current drop_out control method */
+
+ TBool 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. */
+
+ TBool 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 */
+
+ TPoint arcs[ 2*MaxBezier+1 ]; /* The Bezier stack */
+
+ void* memory;
+
+#if defined(FT_RASTER_OPTION_ANTI_ALIAS)
+
+ long grays[20]; /* Palette of gray levels used for render */
+
+ int gray_width; /* length in bytes of the onochrome */
+ /* intermediate scanline of gray_lines. */
+ /* Each gray pixel takes 2 or 4 bits long */
+
+ /* The gray_lines must hold 2 lines, thus with size */
+ /* in bytes of at least 'gray_width*2' */
+
+ int grays_count; /* number of entries in the palette */
+
+ char gray_lines[ANTI_ALIAS_BUFFER_SIZE];
+ /* Intermediate table used to render the */
+ /* graylevels pixmaps. */
+ /* gray_lines is a buffer holding 2 or 4 */
+ /* monochrome scanlines */
+
+ int count_table[256]; /* Look-up table used to quickly count */
+ /* set bits in a gray 2x2 cell */
+#endif
+ };
+
+
+
+#ifdef DEBUG_RASTER
+
+ /************************************************/
+ /* */
+ /* Pset: */
+ /* */
+ /* 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 its original position). */
+ /* */
+ /* This "bug" 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. */
+ /* */
+ /* - David */
+ /* */
+ /************************************************/
+
+ static void Pset( RAS_ARG )
+ {
+ long o;
+ long x;
+
+ x = ras.cursor[-1];
+
+ switch ( ras.cur_prof->flow )
+ {
+ case FT_Flow_Up:
+ o = Vio_ScanLineWidth *
+ ( ras.cursor - ras.cur_prof->offset + ras.cur_prof->start ) +
+ ( x / (ras.precision*8) );
+ break;
+
+ case FT_Flow_Down:
+ o = Vio_ScanLineWidth *
+ ( ras.cur_prof->start - ras.cursor + ras.cur_prof->offset ) +
+ ( x / (ras.precision*8) );
+ break;
+ }
+
+ if ( o > 0 )
+ Vio[o] |= (unsigned)0x80 >> ( (x/ras.precision) & 7 );
+ }
+
+
+ static void Clear_Band( RAS_ARGS Int y1, Int y2 )
+ {
+ MEM_Set( Vio + y1*Vio_ScanLineWidth, (y2-y1+1)*Vio_ScanLineWidth, 0 );
+ }
+
+#endif /* DEBUG_RASTER */
+
+
+/************************************************************************/
+/* */
+/* <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 )
+ {
+ if ( High )
+ {
+ ras.precision_bits = 10;
+ ras.precision_step = 128;
+ ras.precision_jitter = 24;
+ }
+ else
+ {
+ ras.precision_bits = 6;
+ ras.precision_step = 32;
+ ras.precision_jitter = 2;
+ }
+
+ ras.precision = 1 << ras.precision_bits;
+ ras.precision_half = ras.precision / 2;
+ ras.precision_shift = ras.precision_bits - Pixel_Bits;
+ ras.precision_mask = -ras.precision;
+ }
+
+
+/**************************************************************************/
+/* */
+/* <Function> New_Profile */
+/* */
+/* <Description> Creates a new Profile in the render pool. */
+/* */
+/* <Input> */
+/* aState :: state/orientation of the new Profile */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/**************************************************************************/
+
+ static
+ TBool New_Profile( RAS_ARGS TDirection direction )
+ {
+ if ( ras.start_prof == NULL )
+ {
+ ras.cur_prof = (PProfile)ras.cursor;
+ ras.start_prof = ras.cur_prof;
+ ras.cursor += AlignProfileSize;
+ }
+
+ if ( ras.cursor >= ras.pool_limit )
+ {
+ ras.error = ErrRaster_Overflow;
+ return FAILURE;
+ }
+
+ switch ( direction )
+ {
+ case Ascending:
+ ras.cur_prof->flow = FT_Flow_Up;
+ break;
+
+ case Descending:
+ ras.cur_prof->flow = FT_Flow_Down;
+ break;
+
+ default:
+ ras.error = ErrRaster_Invalid_Map;
+ return FAILURE;
+ }
+
+ {
+ PProfile cur = ras.cur_prof;
+
+ cur->start = 0;
+ cur->height = 0;
+ cur->offset = ras.cursor;
+ cur->link = (PProfile)0;
+ cur->next = (PProfile)0;
+ }
+
+ if ( ras.first_prof == NULL )
+ ras.first_prof = ras.cur_prof;
+
+ ras.state = direction;
+ ras.fresh = TRUE;
+ ras.joint = FALSE;
+
+ return SUCCESS;
+ }
+
+
+/****************************************************************************/
+/* */
+/* <Function> End_Profile */
+/* */
+/* <Description> Finalizes the current Profile. */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+
+ static
+ TBool End_Profile( RAS_ARG )
+ {
+ int h;
+
+ h = ras.cursor - ras.cur_prof->offset;
+
+ if ( h < 0 )
+ {
+ ras.error = ErrRaster_Negative_Height;
+ return FAILURE;
+ }
+
+ if ( h > 0 )
+ {
+ PProfile old, new;
+
+ old = ras.cur_prof;
+ old->height = h;
+ ras.cur_prof = new = (PProfile)ras.cursor;
+
+ ras.cursor += AlignProfileSize;
+
+ new->height = 0;
+ new->offset = ras.cursor;
+ old->next = new;
+
+ ras.num_profs++;
+ }
+
+ if ( ras.cursor >= ras.pool_limit )
+ {
+ ras.error = ErrRaster_Overflow;
+ return FAILURE;
+ }
+
+ ras.joint = FALSE;
+
+ return SUCCESS;
+ }
+
+
+/****************************************************************************/
+/* */
+/* <Function> Insert_Y_Turn */
+/* */
+/* <Description> */
+/* Insert a salient into the sorted list placed on top */
+/* of the render pool */
+/* */
+/* <Input> */
+/* y :: new scanline position */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Insert_Y_Turn( RAS_ARGS TScan y )
+ {
+ PPos y_turns;
+ TScan y2;
+ int n;
+
+ n = ras.n_turns-1;
+ y_turns = ras.pool_size - ras.n_turns;
+
+ /* 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 > y_turns[n] )
+ while (n >= 0)
+ {
+ y2 = y_turns[n];
+ y_turns[n] = y;
+ y = y2;
+ n--;
+ }
+
+ if (n < 0)
+ {
+ ras.pool_limit--;
+ ras.n_turns++;
+ ras.pool_size[-ras.n_turns ] = y;
+
+ if ( ras.pool_limit <= ras.cursor )
+ {
+ ras.error = ErrRaster_Overflow;
+ return FAILURE;
+ }
+ }
+ return SUCCESS;
+ }
+
+
+/****************************************************************************/
+/* */
+/* <Function> Finalize_Profile_Table */
+/* */
+/* <Description> */
+/* Adjusts all links in the Profiles list. */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Finalize_Profile_Table( RAS_ARG )
+ {
+ int n, bottom, top;
+ PProfile p;
+
+
+ n = ras.num_profs;
+
+ if ( n > 1 )
+ {
+ p = ras.start_prof;
+ while ( n > 0 )
+ {
+ if (n > 1)
+ p->link = (PProfile)( p->offset + p->height );
+ else
+ p->link = NULL;
+
+ switch (p->flow)
+ {
+ case FT_Flow_Down:
+ bottom = p->start - p->height+1;
+ top = p->start;
+ p->start = bottom;
+ p->offset += p->height-1;
+ break;
+
+ case FT_Flow_Up:
+ default:
+ bottom = p->start;
+ top = p->start + p->height-1;
+ }
+
+ if ( Insert_Y_Turn( RAS_VARS bottom ) ||
+ Insert_Y_Turn( RAS_VARS top+1 ) )
+ return FAILURE;
+
+ p = p->link;
+ n--;
+ }
+ }
+ else
+ ras.start_prof = NULL;
+
+ return SUCCESS;
+ }
+
+
+
+/****************************************************************************/
+/* */
+/* <Function> Line_Up */
+/* */
+/* <Description> */
+/* Computes the scan-line intersections of an ascending line segment */
+/* and stores them in the render pool. */
+/* */
+/* <Input> */
+/* x1 :: start x coordinate */
+/* y1 :: start y coordinates */
+/* x2 :: end x coordinate */
+/* y2 :: end y coordinate */
+/* miny :: minimum vertical grid coordinate */
+/* maxy :: maximum vertical grid coordinate */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE. */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Line_Up( RAS_ARGS TPos x1, TPos y1,
+ TPos x2, TPos y2,
+ TPos miny, TPos maxy )
+ {
+ TPos Dx, Dy;
+ int e1, e2, f1, f2, size;
+ TPos Ix, Rx, Ax;
+
+ PPos top;
+
+
+ Dx = x2 - x1;
+ Dy = y2 - y1;
+
+ if ( Dy <= 0 || y2 < miny || y1 > maxy )
+ return SUCCESS;
+
+ if ( y1 < miny )
+ {
+ x1 += FMulDiv( Dx, miny - y1, Dy );
+ e1 = TRUNC( miny );
+ f1 = 0;
+ }
+ else
+ {
+ e1 = TRUNC( y1 );
+ f1 = FRAC( y1 );
+ }
+
+ if ( y2 > maxy )
+ {
+ /* x2 += FMulDiv( Dx, maxy-y2, Dy ); UNNECESSARY */
+ e2 = TRUNC( maxy );
+ f2 = 0;
+ }
+ else
+ {
+ e2 = TRUNC( y2 );
+ f2 = FRAC( y2 );
+ }
+
+ if ( f1 > 0 )
+ {
+ if ( e1 == e2 ) return SUCCESS;
+ else
+ {
+ x1 += FMulDiv( Dx, ras.precision - f1, Dy );
+ e1 += 1;
+ }
+ }
+ else
+ if ( ras.joint )
+ {
+ ras.cursor--;
+ ras.joint = FALSE;
+ }
+
+ ras.joint = ( f2 == 0 );
+
+ if ( ras.fresh )
+ {
+ ras.cur_prof->start = e1;
+ ras.fresh = FALSE;
+ }
+
+ size = e2 - e1 + 1;
+ if ( ras.cursor + size >= ras.pool_limit )
+ {
+ ras.error = ErrRaster_Overflow;
+ return FAILURE;
+ }
+
+ if ( Dx > 0 )
+ {
+ Ix = (ras.precision*Dx) / Dy;
+ Rx = (ras.precision*Dx) % Dy;
+ Dx = 1;
+ }
+ else
+ {
+ Ix = -( (ras.precision*-Dx) / Dy );
+ Rx = (ras.precision*-Dx) % Dy;
+ Dx = -1;
+ }
+
+ Ax = -Dy;
+ top = ras.cursor;
+
+ while ( size > 0 )
+ {
+ *top++ = x1;
+
+ DEBUG_PSET;
+
+ x1 += Ix;
+ Ax += Rx;
+ if ( Ax >= 0 )
+ {
+ Ax -= Dy;
+ x1 += Dx;
+ }
+ size--;
+ }
+
+ ras.cursor = 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 :: start x coordinate */
+/* y1 :: start y coordinates */
+/* x2 :: end x coordinate */
+/* y2 :: end y coordinate */
+/* miny :: minimum vertical grid coordinate */
+/* maxy :: maximum vertical grid coordinate */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE. */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Line_Down( RAS_ARGS TPos x1, TPos y1,
+ TPos x2, TPos y2,
+ TPos miny, TPos maxy )
+ {
+ TBool result, fresh;
+
+ fresh = ras.fresh;
+ result = Line_Up( RAS_VARS x1, -y1, x2, -y2, -maxy, -miny );
+
+ if ( fresh && !ras.fresh )
+ ras.cur_prof->start = -ras.cur_prof->start;
+
+ return result;
+ }
+
+
+
+
+#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 )/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;
+ }
+
+/****************************************************************************/
+/* */
+/* <Function> Push_Conic */
+/* */
+/* <Description> Clears the Bezier stack and pushes a new arc on top of it */
+/* */
+/* <Input> */
+/* p2 :: pointer to second (control) point */
+/* p3 :: pointer to 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_ARGS 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_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 :: minimum vertical grid coordinate */
+/* maxy :: maximum vertical grid coordinate */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Conic_Up( RAS_ARGS TPos miny, TPos maxy )
+ {
+ TPos y1, y2, e, e2, e0;
+ int f1;
+
+ TPoint* arc;
+ TPoint* start_arc;
+
+ PPos top;
+
+
+ arc = ras.arc;
+ y1 = arc[2].y;
+ y2 = arc[0].y;
+ top = ras.cursor;
+
+ if ( y2 < miny || y1 > maxy )
+ goto Fin;
+
+ e2 = FLOOR( y2 );
+
+ if ( e2 > maxy )
+ e2 = maxy;
+
+ e0 = miny;
+
+ if ( y1 < miny )
+ e = miny;
+ else
+ {
+ e = CEILING( y1 );
+ f1 = FRAC( y1 );
+ e0 = e;
+
+ if ( f1 == 0 )
+ {
+ if ( ras.joint )
+ {
+ top--;
+ ras.joint = FALSE;
+ }
+
+ *top++ = arc[2].x;
+
+ DEBUG_PSET;
+
+ e += ras.precision;
+ }
+ }
+
+ if ( ras.fresh )
+ {
+ ras.cur_prof->start = TRUNC( e0 );
+ ras.fresh = FALSE;
+ }
+
+ if ( e2 < e )
+ goto Fin;
+
+ if ( ( top+TRUNC(e2-e)+1 ) >= ras.pool_limit )
+ {
+ ras.cursor = top;
+ ras.error = ErrRaster_Overflow;
+ return FAILURE;
+ }
+
+ start_arc = arc;
+
+ while ( arc >= start_arc && e <= e2 )
+ {
+ ras.joint = FALSE;
+
+ y2 = arc[0].y;
+
+ if ( y2 > e )
+ {
+ y1 = arc[2].y;
+ if ( y2 - y1 >= ras.precision_step )
+ {
+ Split_Conic( arc );
+ arc += 2;
+ }
+ else
+ {
+ *top++ = arc[2].x +
+ FMulDiv( arc[0].x-arc[2].x,
+ e - y1,
+ y2 - y1 );
+ DEBUG_PSET;
+
+ arc -= 2;
+ e += ras.precision;
+ }
+ }
+ else
+ {
+ if ( y2 == e )
+ {
+ ras.joint = TRUE;
+ *top++ = arc[0].x;
+
+ DEBUG_PSET;
+
+ e += ras.precision;
+ }
+ arc -= 2;
+ }
+ }
+
+ Fin:
+ ras.cursor = top;
+ ras.arc -= 2;
+ return SUCCESS;
+ }
+
+
+/****************************************************************************/
+/* */
+/* <Function> Conic_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 :: minimum vertical grid coordinate */
+/* maxy :: maximum vertical grid coordinate */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Conic_Down( RAS_ARGS TPos miny, TPos maxy )
+ {
+ TPoint* arc = ras.arc;
+ TBool result, fresh;
+
+
+ arc[0].y = -arc[0].y;
+ arc[1].y = -arc[1].y;
+ arc[2].y = -arc[2].y;
+
+ fresh = ras.fresh;
+
+ result = Conic_Up( RAS_VARS -maxy, -miny );
+
+ if ( fresh && !ras.fresh )
+ ras.cur_prof->start = -ras.cur_prof->start;
+
+ arc[0].y = -arc[0].y;
+ return result;
+ }
+
+#endif /* FT_RASTER_CONIC_BEZIERS */
+
+
+
+#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 )/2;
+ base[5].x = b = ( base[3].x + d )/2;
+ c = (c+d)/2;
+ base[2].x = a = (a+c)/2;
+ base[4].x = b = (b+c)/2;
+ base[3].x = (a+b)/2;
+
+ base[6].y = base[3].y;
+ c = base[1].y;
+ d = base[2].y;
+ base[1].y = a = ( base[0].y + c )/2;
+ base[5].y = b = ( base[3].y + d )/2;
+ c = (c+d)/2;
+ base[2].y = a = (a+c)/2;
+ base[4].y = b = (b+c)/2;
+ base[3].y = (a+b)/2;
+ }
+
+/****************************************************************************/
+/* */
+/* <Function> Push_Cubic */
+/* */
+/* <Description> */
+/* Clears the bezier stack and pushes a new third-order bezier arc */
+/* on top of it */
+/* */
+/* <Input> */
+/* p2 :: pointer to second point (control) */
+/* p3 :: pointer to third point (control) */
+/* p4 :: pointer to last point (end) */
+/* */
+/* <Note> */
+/* The first point is taken as "raster->last", so it doesn't appear */
+/* in the signature.. */
+/* */
+/****************************************************************************/
+
+ static
+ void Push_Cubic( RAS_ARGS 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_Up */
+/* */
+/* <Description> */
+/* Computes the scan-line intersections of an ascending third-order */
+/* bezier arc and stores them in the render pool */
+/* */
+/* <Input> */
+/* miny :: minimum vertical grid coordinate */
+/* maxy :: maximum vertical grid coordinate */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+ static
+ TBool Cubic_Up( RAS_ARGS TPos miny, TPos maxy )
+ {
+ TPos y1, y2, e, e2, e0;
+ int f1;
+
+ TPoint* arc;
+ TPoint* start_arc;
+
+ TPos* top;
+
+
+ arc = ras.arc;
+ y1 = arc[3].y;
+ y2 = arc[0].y;
+ top = ras.cursor;
+
+ if ( y2 < miny || y1 > maxy )
+ goto Fin;
+
+ e2 = FLOOR( y2 );
+
+ if ( e2 > maxy )
+ e2 = maxy;
+
+ e0 = miny;
+
+ if ( y1 < miny )
+ e = miny;
+ else
+ {
+ e = CEILING( y1 );
+ f1 = FRAC( y1 );
+ e0 = e;
+
+ if ( f1 == 0 )
+ {
+ if ( ras.joint )
+ {
+ top--;
+ ras.joint = FALSE;
+ }
+
+ *top++ = arc[3].x;
+
+ DEBUG_PSET;
+
+ e += ras.precision;
+ }
+ }
+
+ if ( ras.fresh )
+ {
+ ras.cur_prof->start = TRUNC( e0 );
+ ras.fresh = FALSE;
+ }
+
+ if ( e2 < e )
+ goto Fin;
+
+ if ( ( top+TRUNC(e2-e)+1 ) >= ras.pool_limit )
+ {
+ ras.cursor = top;
+ ras.error = ErrRaster_Overflow;
+ return FAILURE;
+ }
+
+ start_arc = arc;
+
+ while ( arc >= start_arc && e <= e2 )
+ {
+ ras.joint = FALSE;
+
+ y2 = arc[0].y;
+
+ if ( y2 > e )
+ {
+ y1 = arc[3].y;
+ if ( y2 - y1 >= ras.precision_step )
+ {
+ Split_Cubic( arc );
+ arc += 3;
+ }
+ else
+ {
+ *top++ = arc[3].x +
+ FMulDiv( arc[0].x-arc[3].x,
+ e - y1,
+ y2 - y1 );
+ DEBUG_PSET;
+
+ arc -= 3;
+ e += ras.precision;
+ }
+ }
+ else
+ {
+ if ( y2 == e )
+ {
+ ras.joint = TRUE;
+ *top++ = arc[0].x;
+
+ DEBUG_PSET;
+
+ e += ras.precision;
+ }
+ arc -= 3;
+ }
+ }
+
+ Fin:
+ ras.cursor = top;
+ ras.arc -= 3;
+ return SUCCESS;
+ }
+
+
+/****************************************************************************/
+/* */
+/* <Function> Cubic_Down */
+/* */
+/* <Description> */
+/* Computes the scan-line intersections of a descending third-order */
+/* bezier arc and stores them in the render pool */
+/* */
+/* <Input> */
+/* miny :: minimum vertical grid coordinate */
+/* maxy :: maximum vertical grid coordinate */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+ static
+ TBool Cubic_Down( RAS_ARGS TPos miny, TPos maxy )
+ {
+ TPoint* arc = ras.arc;
+ TBool result, fresh;
+
+
+ arc[0].y = -arc[0].y;
+ arc[1].y = -arc[1].y;
+ arc[2].y = -arc[2].y;
+ arc[3].y = -arc[3].y;
+
+ fresh = ras.fresh;
+
+ result = Cubic_Up( RAS_VARS -maxy, -miny );
+
+ if ( fresh && !ras.fresh )
+ ras.cur_prof->start = -ras.cur_prof->start;
+
+ arc[0].y = -arc[0].y;
+ return result;
+ }
+
+#endif /* FT_RASTER_CUBIC_BEZIERS */
+
+/****************************************************************************/
+/* */
+/* <Function> Check_Contour */
+/* */
+/* <Description> */
+/* perform some check at contour closure. */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Check_Contour( RAS_ARG )
+ {
+ PProfile lastProfile;
+
+ /* We must now see if the extreme arcs join or not */
+ 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;
+
+ /* close the 'next profile in contour' linked list */
+ lastProfile->next = ras.first_prof;
+
+ return SUCCESS;
+ }
+
+/****************************************************************************/
+/* */
+/* <Function> Move_To */
+/* */
+/* <Description> */
+/* This function injects a new contour in the render pool.. */
+/* */
+/* <Input> */
+/* to :: 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 )
+ {
+ /* if there was already a contour being built, perform some checks */
+ if ( ras.start_prof )
+ if ( Check_Contour( RAS_VAR ) )
+ return FAILURE;
+
+ /* set the "current last point" */
+ if (ras.flipped)
+ {
+ ras.last.x = SCALED( to->y );
+ ras.last.y = SCALED( to->x );
+ }
+ else
+ {
+ ras.last.x = SCALED( to->x );
+ ras.last.y = SCALED( to->y );
+ }
+
+ ras.state = Unknown;
+ ras.first_prof = NULL;
+
+ return SUCCESS;
+ }
+
+/****************************************************************************/
+/* */
+/* <Function> Line_To */
+/* */
+/* <Description> */
+/* This function injects a new line segment in the render pool and */
+/* adjusts the profiles list accordingly.. */
+/* */
+/* <Input> */
+/* to :: 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;
+ TPos y;
+
+ if ( ras.flipped )
+ {
+ x = SCALED(to->y);
+ y = SCALED(to->x);
+ }
+ else
+ {
+ x = SCALED(to->x);
+ y = SCALED(to->y);
+ }
+
+ /* First, detect a change of direction */
+
+ switch ( ras.state )
+ {
+ case Unknown:
+ if ( y > ras.last.y )
+ {
+ if ( New_Profile( RAS_VARS Ascending ) ) return FAILURE;
+ }
+ else
+ {
+ if ( y < ras.last.y )
+ if ( New_Profile( RAS_VARS Descending ) ) return FAILURE;
+ }
+ break;
+
+ case Ascending:
+ if ( y < ras.last.y )
+ {
+ if ( End_Profile( RAS_VAR ) ||
+ New_Profile( RAS_VARS Descending ) ) return FAILURE;
+ }
+ break;
+
+ case Descending:
+ if ( y > ras.last.y )
+ {
+ 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_VARS ras.last.x, ras.last.y,
+ x, y, ras.minY, ras.maxY ) )
+ return FAILURE;
+ break;
+
+ case Descending:
+ if ( Line_Down( RAS_VARS ras.last.x, ras.last.y,
+ x, y, ras.minY, ras.maxY ) )
+ return FAILURE;
+ break;
+
+ default:
+ ;
+ }
+
+ ras.last.x = x;
+ ras.last.y = y;
+
+ return SUCCESS;
+ }
+
+#ifdef FT_RASTER_CONIC_BEZIERS
+/****************************************************************************/
+/* */
+/* <Function> Conic_To */
+/* */
+/* <Description> */
+/* Injects a new conic bezier arc and adjusts the profile list */
+/* accordingly. */
+/* */
+/* <Input> */
+/* control :: pointer to intermediate control point */
+/* to :: pointer to end point */
+/* raster :: handle to 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 )
+ {
+ TPos y1, y2, y3, x3;
+ TDirection state_bez;
+
+
+ Push_Conic( RAS_VARS control, to );
+
+ do
+ {
+ y1 = ras.arc[2].y;
+ y2 = ras.arc[1].y;
+ y3 = ras.arc[0].y;
+ x3 = ras.arc[0].x;
+
+ /* first, categorize the bezier arc */
+
+ if( y1 == y3 )
+ {
+ if ( y2 == y1 )
+ state_bez = Flat;
+ else
+ state_bez = Unknown;
+ }
+ else if ( y1 < y3 )
+ {
+ if ( y2 < y1 || y2 > y3 )
+ state_bez = Unknown;
+ else
+ state_bez = Ascending;
+ }
+ else
+ {
+ if ( y2 < y3 || y2 > y1 )
+ state_bez = Unknown;
+ else
+ state_bez = Descending;
+ }
+
+ /* split non-monotonic arcs, ignore flat ones, or */
+ /* computes the up and down ones */
+
+ switch ( state_bez )
+ {
+ case Flat:
+ ras.arc -= 2;
+ break;
+
+ case Unknown:
+ Split_Conic( ras.arc );
+ ras.arc += 2;
+ break;
+
+ default:
+ /* detect a change of direction */
+
+ if ( ras.state != state_bez )
+ {
+ if ( ras.state != Unknown )
+ if ( End_Profile( RAS_VAR ) ) return FAILURE;
+
+ if ( New_Profile( RAS_VARS state_bez ) ) return FAILURE;
+ }
+
+ /* compute intersections */
+ switch ( ras.state )
+ {
+ case Ascending:
+ if ( Conic_Up ( RAS_VARS ras.minY, ras.maxY ) )
+ return FAILURE;
+ break;
+
+ case Descending:
+ if ( Conic_Down( RAS_VARS ras.minY, ras.maxY ) )
+ return FAILURE;
+ break;
+
+ default:
+ ;
+ }
+ }
+ } while ( ras.arc >= ras.arcs );
+
+ ras.last.x = x3;
+ ras.last.y = y3;
+
+ return 0;
+ }
+
+#else
+ static
+ int Conic_To( FT_Vector* control,
+ FT_Vector* to,
+ FT_Raster raster )
+ {
+ (void)control;
+ (void)to;
+ (void)raster;
+
+ return ErrRaster_Invalid_Outline;
+ }
+#endif /* CONIC_BEZIERS */
+
+
+#ifdef FT_RASTER_CUBIC_BEZIERS
+/****************************************************************************/
+/* */
+/* <Function> Cubic_To */
+/* */
+/* <Description> */
+/* Injects a new cubic bezier arc and adjusts the profile list */
+/* accordingly. */
+/* */
+/* <Input> */
+/* control1 :: pointer to first control point */
+/* control2 :: pointer to second control point */
+/* to :: pointer to end point */
+/* raster :: handle to 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 )
+ {
+ TPos y1, y2, y3, y4, x4;
+ TDirection state_bez;
+
+
+ Push_Cubic( RAS_VARS control1, control2, to );
+
+ do
+ {
+ y1 = ras.arc[3].y;
+ y2 = ras.arc[2].y;
+ y3 = ras.arc[1].y;
+ y4 = ras.arc[0].y;
+ x4 = ras.arc[0].x;
+
+ /* first, categorize the bezier arc */
+ if ( y1 == y4 )
+ {
+ if ( y1 == y2 && y1 == y3 )
+ state_bez = Flat;
+ else
+ state_bez = Unknown;
+ }
+ else if ( y1 < y4 )
+ {
+ if ( y2 < y1 || y2 > y4 || y3 < y1 || y3 > y4 )
+ state_bez = Unknown;
+ else
+ state_bez = Ascending;
+ }
+ else
+ {
+ if ( y2 < y4 || y2 > y1 || y3 < y4 || y3 > y1 )
+ state_bez = Unknown;
+ else
+ state_bez = Descending;
+ }
+
+ /* split non-monotonic arcs, ignore flat ones, or */
+ /* computes the up and down ones */
+
+ switch ( state_bez )
+ {
+ case Flat:
+ ras.arc -= 3;
+ break;
+
+ case Unknown:
+ Split_Cubic( ras.arc );
+ ras.arc += 3;
+ break;
+
+ default:
+ /* detect a change of direction */
+
+ if ( ras.state != state_bez )
+ {
+ if ( ras.state != Unknown )
+ if ( End_Profile( RAS_VAR ) ) return FAILURE;
+
+ if ( New_Profile( RAS_VARS state_bez ) ) return FAILURE;
+ }
+
+ /* compute */
+
+ switch ( ras.state )
+ {
+ case Ascending:
+ if ( Cubic_Up ( RAS_VARS ras.minY, ras.maxY ) )
+ return FAILURE;
+ break;
+
+ case Descending:
+ if ( Cubic_Down( RAS_VARS ras.minY, ras.maxY ) )
+ return FAILURE;
+ break;
+
+ default:
+ ;
+ }
+ }
+ } while ( ras.arc >= ras.arcs );
+
+ ras.last.x = x4;
+ ras.last.y = y4;
+
+ return 0;
+ }
+
+#else
+ int Cubic_To( FT_Vector* control1,
+ FT_Vector* control2,
+ FT_Vector* to,
+ FT_Raster raster )
+ {
+ (void)control1;
+ (void)control2;
+ (void)to;
+ (void)raster;
+
+ return ErrRaster_Invalid_Outline;
+ }
+#endif /* CUBIC_BEZIERS */
+
+
+/****************************************************************************/
+/* */
+/* <Function> Convert_Glyph */
+/* */
+/* <Description> */
+/* Converts a glyph into a series of segments and arcs and makes */
+/* a profiles list with them.. */
+/* */
+/* <Input> */
+/* outline :: glyph outline */
+/* */
+/* <Return> */
+/* SUCCESS or FAILURE */
+/* */
+/****************************************************************************/
+
+ static
+ TBool Convert_Glyph( RAS_ARGS FT_Outline* outline )
+ {
+ static
+ FT_Outline_Funcs interface =
+ {
+ (FT_Outline_MoveTo_Func)Move_To,
+ (FT_Outline_LineTo_Func)Line_To,
+ (FT_Outline_ConicTo_Func)Conic_To,
+ (FT_Outline_CubicTo_Func)Cubic_To
+ };
+
+ /* Set up state in the raster object */
+ ras.start_prof = NULL;
+ ras.joint = FALSE;
+ ras.fresh = FALSE;
+
+ ras.pool_limit = ras.pool_size - AlignProfileSize;
+
+ ras.n_turns = 0;
+
+ ras.cur_prof = (PProfile)ras.cursor;
+ ras.cur_prof->offset = ras.cursor;
+ ras.num_profs = 0;
+
+ /* Now decompose curve */
+ if ( FT_Outline_Decompose( outline, &interface, &ras ) ) return FAILURE;
+ /* XXX : the error condition is in ras.error */
+
+ /* Check the last contour if needed */
+ if ( Check_Contour( RAS_VAR ) ) return FAILURE;
+
+ /* Finalize profiles list */
+ return Finalize_Profile_Table( RAS_VAR );
+ }
+
+
+/************************************************/
+/* */
+/* 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 )
+ {
+ PProfile *old, current;
+ TPos x;
+
+
+ old = list;
+ current = *old;
+ x = profile->X;
+
+ while ( current )
+ {
+ if ( x < current->X )
+ break;
+ old = ¤t->link;
+ current = *old;
+ }
+
+ profile->link = current;
+ *old = profile;
+ }
+
+
+/*************************************************/
+/* */
+/* DelOld : */
+/* */
+/* Removes an old Profile from a linked list. */
+/* */
+/*************************************************/
+
+ static void DelOld( PProfileList list,
+ PProfile profile )
+ {
+ PProfile *old, current;
+
+
+ old = list;
+ current = *old;
+
+ while ( current )
+ {
+ if ( current == profile )
+ {
+ *old = current->link;
+ return;
+ }
+
+ old = ¤t->link;
+ current = *old;
+ }
+
+ /* we should never get there, unless the Profile was not part of */
+ /* the list. */
+ }
+
+/************************************************/
+/* */
+/* Update : */
+/* */
+/* Update all X offsets of a drawing list */
+/* */
+/************************************************/
+
+ static void Update( PProfile first )
+ {
+ PProfile current = first;
+
+ while (current)
+ {
+ current->X = *current->offset;
+ current->offset += current->flow;
+ current->height--;
+ current = current->link;
+ }
+ }
+
+/************************************************/
+/* */
+/* 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;
+
+
+ /* First, set the new X coordinate of each profile */
+ Update( *list );
+
+ /* Then sort them */
+ old = list;
+ current = *old;
+
+ if ( !current )
+ return;
+
+ next = current->link;
+
+ while ( next )
+ {
+ if ( current->X <= next->X )
+ {
+ old = ¤t->link;
+ current = *old;
+
+ if ( !current )
+ return;
+ }
+ else
+ {
+ *old = next;
+ current->link = next->link;
+ next->link = current;
+
+ old = list;
+ current = *old;
+ }
+
+ next = current->link;
+ }
+ }
+
+
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+/******** *********/
+/******** Vertical Bitmap Sweep Routines *********/
+/******** *********/
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+
+
+/***********************************************************************/
+/* */
+/* <Function> Vertical_Sweep_Init */
+/* */
+/* <Description> */
+/* Initialise the vertical bitmap sweep. Called by the generic */
+/* sweep/draw routine before its loop.. */
+/* */
+/* <Input> */
+/* min :: address of current minimum scanline */
+/* max :: address of current maximum scanline */
+/* */
+/***********************************************************************/
+
+ static
+ void Vertical_Sweep_Init( RAS_ARGS int* min, int* max )
+ {
+ long pitch = ras.target.pitch;
+
+ ras.trace_incr = -pitch;
+ ras.trace_bit = -*min*pitch;
+ if (pitch > 0)
+ ras.trace_bit += (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 :: current scanline */
+/* x1 :: left span edge */
+/* x2 :: right span edge */
+/* */
+/***********************************************************************/
+
+ static void Vertical_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 )
+ {
+ TPos e1, e2;
+ int c1, c2;
+ TByte f1, f2;
+ TByte* target;
+
+ /* Drop-out control */
+
+ e1 = TRUNC( CEILING( x1 ) );
+ if ( x2-x1-ras.precision <= ras.precision_jitter )
+ e2 = e1;
+ else
+ e2 = TRUNC( FLOOR( x2 ) );
+
+ if ( e1 <= e2 && e2 >= 0 && e1 < ras.bit_width )
+ {
+ if ( e1 < 0 ) e1 = 0;
+ if ( e2 >= ras.bit_width ) e2 = ras.bit_width-1;
+
+ c1 = e1 >> 3;
+ c2 = e2 >> 3;
+
+ f1 = ((unsigned char)0xFF >> (e1 & 7));
+ f2 = ~((unsigned char)0x7F >> (e2 & 7));
+
+ target = ras.bit_buffer + ras.trace_bit + c1;
+ c2 -= c1;
+
+ if ( c2 > 0 )
+ {
+ target[0] |= f1;
+
+ /* memset is slower than the following code on many platforms */
+ /* this is due to the fact that, in the vast majority of cases, */
+ /* the span length in bytes is relatively small.. */
+ c2--;
+ while (c2 > 0)
+ {
+ * ++target = 0xFF;
+ c2--;
+ }
+ target[1] |= f2;
+ }
+ else
+ *target |= ( f1 & f2 );
+ }
+ }
+
+/***********************************************************************/
+/* */
+/* <Function> Vertical_Test_Pixel */
+/* */
+/* <Description> */
+/* test a pixel 'light' during the vertical bitmap sweep. Used */
+/* during drop-out control only.. */
+/* */
+/* <Input> */
+/* y :: current scanline */
+/* x :: current x coordinate */
+/* */
+/***********************************************************************/
+
+ static
+ int Vertical_Test_Pixel( RAS_ARGS TScan y,
+ int x )
+ {
+ int c1 = x >> 3;
+
+ return ( x >= 0 && x < ras.bit_width &&
+ ras.bit_buffer[ras.trace_bit + c1] & (0x80 >> (x & 7)) );
+ }
+
+/***********************************************************************/
+/* */
+/* <Function> Vertical_Set_Pixel */
+/* */
+/* <Description> */
+/* Sets a single pixel in a bitmap during the vertical sweep. */
+/* Used during drop-out control.. */
+/* */
+/* <Input> */
+/* y :: current scanline */
+/* x :: current x coordinate */
+/* color :: ignored by this function */
+/* */
+/***********************************************************************/
+
+ static
+ void Vertical_Set_Pixel( RAS_ARGS int y,
+ int x,
+ int color )
+ {
+ (void)color; /* unused here */
+
+ if ( x >= 0 && x < ras.bit_width )
+ {
+ int c1 = x >> 3;
+
+ if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1;
+ if ( ras.gray_max_x < c1 ) ras.gray_max_x = c1;
+
+ ras.bit_buffer[ras.trace_bit+c1] |= (char)(0x80 >> (x & 7));
+ }
+ }
+
+/***********************************************************************/
+/* */
+/* <Function> Vertical_Sweep_Step */
+/* */
+/* <Description> */
+/* Called whenever the sweep jumps to anothr scanline. */
+/* Only updates the pointers in the vertical bitmap sweep */
+/* */
+/***********************************************************************/
+
+ static
+ void Vertical_Sweep_Step( RAS_ARG )
+ {
+ ras.trace_bit += ras.trace_incr;
+ }
+
+
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+/******** *********/
+/******** Horizontal Bitmap Sweep Routines *********/
+/******** *********/
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+
+/***********************************************************************/
+/* */
+/* <Function> Horizontal_Sweep_Init */
+/* */
+/* <Description> */
+/* Initialise the horizontal bitmap sweep. Called by the generic */
+/* sweep/draw routine before its loop.. */
+/* */
+/* <Input> */
+/* min :: address of current minimum pixel column */
+/* max :: address of current maximum pixel column */
+/* */
+/***********************************************************************/
+
+ static void Horizontal_Sweep_Init( RAS_ARGS int* min, int* max )
+ {
+ /* nothing, really */
+ }
+
+
+/***********************************************************************/
+/* */
+/* <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 :: current pixel column */
+/* x1 :: top span edge */
+/* x2 :: bottom span edge */
+/* */
+/***********************************************************************/
+
+ static void Horizontal_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 )
+ {
+ TPos e1, e2;
+ PByte bits;
+ TByte f1;
+
+
+ /* During the horizontal sweep, we only take care of drop-outs */
+ if ( x2-x1 < ras.precision )
+ {
+ e1 = CEILING( x1 );
+ e2 = FLOOR( x2 );
+
+ if ( e1 == e2 )
+ {
+ bits = ras.bit_buffer + (y >> 3);
+ f1 = (TByte)(0x80 >> (y & 7));
+
+ e1 = TRUNC( e1 );
+
+ if ( e1 >= 0 && e1 < ras.target.rows )
+ {
+ long pitch = ras.target.pitch;
+
+ bits -= e1*pitch;
+ if (pitch > 0)
+ bits += (ras.target.rows-1)*pitch;
+
+ bits[0] |= f1;
+ }
+ }
+ }
+ }
+
+
+/***********************************************************************/
+/* */
+/* <Function> Horizontal_Test_Pixel */
+/* */
+/* <Description> */
+/* test a pixel 'light' during the horizontal bitmap sweep. Used */
+/* during drop-out control only.. */
+/* */
+/* <Input> */
+/* y :: current pixel column */
+/* x :: current row/scanline */
+/* */
+/***********************************************************************/
+
+ static
+ int Horizontal_Test_Pixel( RAS_ARGS int y,
+ int x )
+ {
+ char* bits = (char*)ras.bit_buffer + (y >> 3);
+ int f1 = (TByte)(0x80 >> (y & 7));
+ long pitch = ras.target.pitch;
+
+ bits -= x*pitch;
+ if (pitch > 0)
+ bits += (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 :: current pixel column */
+/* x :: current row/scanline */
+/* color :: ignored by this function */
+/* */
+/***********************************************************************/
+
+ static
+ void Horizontal_Set_Pixel( RAS_ARGS int y,
+ int x,
+ int color )
+ {
+ char* bits = (char*)ras.bit_buffer + (y >> 3);
+ int f1 = (TByte)(0x80 >> (y & 7));
+ long pitch = ras.target.pitch;
+
+ (void)color; /* unused here */
+
+ bits -= x*pitch;
+ if (pitch > 0)
+ bits += (ras.target.rows-1)*pitch;
+
+ if ( x >= 0 && x < ras.target.rows )
+ bits[0] |= f1;
+ }
+
+/***********************************************************************/
+/* */
+/* <Function> Horizontal_Sweep_Step */
+/* */
+/* <Description> */
+/* Called whenever the sweep jumps to another pixel column. */
+/* */
+/***********************************************************************/
+
+ static void Horizontal_Sweep_Step( RAS_ARG )
+ {
+ /* Nothing, really */
+ }
+
+
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+/******** *********/
+/******** Anti-Aliased Vertical Bitmap Sweep Routines *********/
+/******** *********/
+/**************************************************************************/
+/**************************************************************************/
+/**************************************************************************/
+
+#ifdef FT_RASTER_OPTION_ANTI_ALIAS
+
+#ifdef FT_RASTER_ANTI_ALIAS_5
+/***********************************************************************/
+/* */
+/* 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_Gray5_Sweep_Init( RAS_ARGS int* min, int* max )
+ {
+ long pitch;
+
+ *min = *min & -2;
+ *max = ( *max+3 ) & -2;
+
+ ras.trace_bit = 0;
+
+ pitch = ras.target.pitch;
+ ras.trace_incr = -pitch;
+ ras.trace_pix = - (*min/2)*pitch;
+ if (pitch > 0)
+ ras.trace_pix += (ras.target.rows-1)*pitch;
+
+ ras.gray_min_x = 32000;
+ ras.gray_max_x = -32000;
+ }
+
+
+ static void Vertical_Gray5_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 )
+ {
+ static
+ const unsigned int LMask[17] =
+#ifdef FT_RASTER_LITTLE_ENDIAN
+ { 0xF0F0F0F0, 0xF0F0F070, 0xF0F0F030, 0xF0F0F010,
+ 0xF0F0F000, 0xF0F07000, 0xF0F03000, 0xF0F01000,
+ 0xF0F00000, 0xF0700000, 0xF0300000, 0xF0100000,
+ 0xF0000000, 0x70000000, 0x30000000, 0x10000000,
+ 0x00000000 };
+#else
+ { 0xF0F0F0F0, 0x70F0F0F0, 0x30F0F0F0, 0x10F0F0F0,
+ 0x00F0F0F0, 0x0070F0F0, 0x0030F0F0, 0x0010F0F0,
+ 0x0000F0F0, 0x000070F0, 0x000030F0, 0x000010F0,
+ 0x000000F0, 0x00000070, 0x00000030, 0x00000010,
+ 0x00000000 };
+#endif
+
+ TPos e1, e2;
+ int c1, c2;
+ TByte* target;
+
+ unsigned int f1, f2;
+ unsigned int shift, fill;
+
+ /* Drop-out control */
+
+ e1 = TRUNC( CEILING( x1 ) );
+ if ( x2-x1 <= ras.precision+ras.precision_jitter )
+ e2 = e1;
+ else
+ e2 = FLOOR ( x2 );
+
+ e2 = TRUNC( e2 );
+
+ if ( e1 <= e2 && e2 >= 0 && e1 < ras.bit_width )
+ {
+ if ( e1 < 0 ) e1 = 0;
+ if ( e2 >= ras.bit_width ) e2 = ras.bit_width-1;
+
+ shift = (y & 1)*4;
+
+ c1 = e1 >> 4;
+ c2 = e2 >> 4;
+
+ fill = LMask[0];
+ f1 = LMask[ e1 & 15 ];
+ f2 = fill ^ LMask[ 1+(e2 & 15) ];
+
+ f1 >>= shift;
+ f2 >>= shift;
+ fill >>= shift;
+
+ if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1;
+ if ( ras.gray_max_x < c2 ) ras.gray_max_x = c2;
+
+ target = ras.bit_buffer + c1*4;
+ c2 -= c1;
+
+ if (c2 > 0)
+ {
+ int* slice = (int*)target;
+
+ slice[0] |= f1;
+ c2--;
+ while (c2 > 0)
+ {
+ * ++slice |= fill;
+ c2--;
+ }
+ slice[1] |= f2;
+ }
+ else
+ ((int*)target)[0] |= ( f1 & f2 );
+ }
+ }
+
+
+ static
+ int Vertical_Gray5_Test_Pixel( RAS_ARGS int y,
+ int x )
+ {
+ int c1 = x >> 2;
+ int f1 = x & 3;
+ int mask = (0x80 >> f1) >> ((y & 1)*4);
+
+ return ( x >= 0 &&
+ x < ras.bit_width &&
+ ras.bit_buffer[c1] & mask );
+ }
+
+
+ static
+ void Vertical_Gray5_Set_Pixel( RAS_ARGS int y,
+ int x,
+ int color )
+ {
+ (void)color; /* unused here */
+
+ if ( x >= 0 && x < ras.bit_width )
+ {
+ int c1 = x >> 2;
+ int f1 = x & 3;
+ int mask = (0x80 >> f1) >> ((y & 1)*4);
+
+ if ( ras.gray_min_x > c1/4 ) ras.gray_min_x = c1/4;
+ if ( ras.gray_max_x < c1/4 ) ras.gray_max_x = c1/4;
+
+ ras.bit_buffer[c1] |= mask;
+ }
+ }
+
+
+ static void Vertical_Gray5_Sweep_Step( RAS_ARG )
+ {
+ int c1;
+ PByte pix, bit;
+ int* count = ras.count_table;
+ long* grays;
+
+
+ ras.trace_bit++;
+
+ if ( ras.trace_bit > 1 )
+ {
+ pix = ras.pix_buffer + ras.trace_pix + ras.gray_min_x*8;
+ grays = ras.grays;
+
+ if ( ras.gray_max_x >= 0 )
+ {
+ if ( ras.gray_max_x*8 >= ras.target.width )
+ ras.gray_max_x = (ras.target.width+7)/8-1;
+
+ if ( ras.gray_min_x < 0 )
+ ras.gray_min_x = 0;
+
+ bit = ras.bit_buffer + ras.gray_min_x*4;
+ c1 = (ras.gray_max_x - ras.gray_min_x + 1);
+
+ while ( c1 >= 0 )
+ {
+ if ( *(short*)bit )
+ {
+#if defined( FT_RASTER_LITTLE_ENDIAN )
+ /* little endian storage */
+ *((long*)pix) = (count[bit[1]] << 16) | count[bit[0]];
+#elif defined( FT_RASTER_BIG_ENDIAN )
+ /* big-endian storage */
+ *((long*)pix) = (count[bit[0]] << 16) | count[bit[1]];
+#else
+ /* endian-independent storage */
+ int c;
+ c = count[bit[1]];
+ pix[4] = (TByte)(c >> 8);
+ pix[5] = (TByte)(c & 0xFF);
+ c = count[bit[0]];
+ pix[6] = (TByte)(c >> 8);
+ pix[7] = (TByte)(c & 0xFF);
+#endif
+ *(short*)bit = 0;
+ }
+
+ bit += 2;
+
+ if ( *(short*)bit )
+ {
+#if defined( FT_RASTER_LITTLE_ENDIAN )
+ /* little endian storage */
+ *((long*)pix + 1)= (count[bit[1]] << 16) | count[bit[0]];
+#elif defined( FT_RASTER_BIG_ENDIAN )
+ /* big-endian storage */
+ *((long*)pix + 1) = (count[bit[0]] << 16) | count[bit[1]];
+#else
+ /* endian-independent storage */
+ int c;
+ c = count[bit[1]];
+ pix[0] = (TByte)(c >> 8);
+ pix[1] = (TByte)(c & 0xFF);
+ c = count[bit[0]];
+ pix[2] = (TByte)(c >> 8);
+ pix[3] = (TByte)(c & 0xFF);
+#endif
+ *(short*)bit = 0;
+ }
+ pix += 8;
+ bit += 2;
+ c1 --;
+ }
+ }
+
+ ras.trace_bit = 0;
+ ras.trace_pix += ras.trace_incr;
+
+ ras.gray_min_x = 32000;
+ ras.gray_max_x = -32000;
+ }
+ }
+
+
+
+ static void Horizontal_Gray5_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 )
+ {
+ /* nothing, really */
+ (void)y;
+ (void)x1;
+ (void)x2;
+ }
+
+
+ static
+ int Horizontal_Gray5_Test_Pixel( RAS_ARGS TScan y,
+ int x )
+ {
+ /* don't do anything here */
+ (void)x;
+ (void)y;
+
+ return 0;
+ }
+
+
+ static
+ void Horizontal_Gray5_Set_Pixel( RAS_ARGS TScan y,
+ int x,
+ int color )
+ {
+ char* pixel;
+
+ x = x/2;
+
+ if (x < ras.target.rows)
+ {
+ long pitch;
+
+ pixel = (char*)ras.pix_buffer + (y/2);
+ pitch = ras.target.pitch;
+ pixel -= x*pitch;
+ if (pitch > 0)
+ pixel += (ras.target.rows-1)*pitch;
+
+ if (pixel[0] == ras.grays[0])
+ pixel[0] = (char)ras.grays[1+color];
+ }
+ }
+#endif /* FT_RASTER_ANTI_ALIAS_5 */
+
+#ifdef FT_RASTER_ANTI_ALIAS_17
+/***********************************************************************/
+/* */
+/* 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_Gray17_Sweep_Init( RAS_ARGS int* min, int* max )
+ {
+ long pitch = ras.target.pitch;
+
+ *min = *min & -4;
+ *max = ( *max+7 ) & -4;
+
+ ras.trace_bit = 0;
+ ras.trace_incr = -pitch;
+ ras.trace_bit = - (*min/4)*pitch;
+ if (pitch > 0)
+ ras.trace_bit += (ras.target.rows-1)*pitch;
+
+ ras.gray_min_x = 32000;
+ ras.gray_max_x = -32000;
+ }
+
+
+ static void Vertical_Gray17_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 )
+ {
+ static
+ const unsigned int LMask[9] =
+#ifdef FT_RASTER_LITTLE_ENDIAN
+ { 0xF000F000, 0xF0007000, 0xF0003000, 0xF0001000,
+ 0xF0000000, 0x70000000, 0x30000000, 0x10000000,
+ 0x00000000 };
+#else
+ { 0xF000F000, 0x7000F000, 0x3000F000, 0x1000F000,
+ 0x0000F000, 0x00007000, 0x00003000, 0x00001000,
+ 0x00000000 };
+#endif
+
+ TPos e1, e2;
+ int c1, c2;
+ TByte* target;
+
+ unsigned int f1, f2;
+ unsigned int shift, fill;
+
+ /* Drop-out control */
+
+ e1 = TRUNC( CEILING( x1 ) );
+ if ( x2-x1 <= ras.precision+ras.precision_jitter )
+ e2 = e1;
+ else
+ e2 = FLOOR ( x2 );
+ e2 = TRUNC( e2 );
+
+ if ( e1 <= e2 && e2 >= 0 && e1 < ras.bit_width )
+ {
+ if ( e1 < 0 ) e1 = 0;
+ if ( e2 >= ras.bit_width ) e2 = ras.bit_width-1;
+
+ shift = (y & 3)*4;
+
+ c1 = e1 >> 3;
+ c2 = e2 >> 3;
+
+ fill = LMask[0];
+ f1 = LMask[ e1 & 7 ];
+ f2 = fill ^ LMask[ 1+(e2 & 7) ];
+
+ f1 >>= shift;
+ f2 >>= shift;
+ fill >>= shift;
+
+ if ( ras.gray_min_x > c1/2 ) ras.gray_min_x = c1/2;
+ if ( ras.gray_max_x < c2/2 ) ras.gray_max_x = c2/2;
+
+ target = ras.bit_buffer + c1*4;
+ c2 -= c1;
+
+ if (c2 > 0)
+ {
+ int* slice = (int*)target;
+
+ slice[0] |= f1;
+ c2--;
+ while (c2 > 0)
+ {
+ * ++slice |= fill;
+ c2--;
+ }
+ slice[1] |= f2;
+ }
+ else
+ ((int*)target)[0] |= ( f1 & f2 );
+ }
+ }
+
+
+ static
+ int Vertical_Gray17_Test_Pixel( RAS_ARGS int y,
+ int x )
+ {
+ int c1 = x >> 2;
+ int f1 = x & 3;
+ int mask = (0x8000 >> f1) >> ((y & 3)*4);
+
+ return ( x >= 0 &&
+ x < ras.bit_width &&
+ ((short*)ras.bit_buffer)[c1] & mask );
+ }
+
+
+ static
+ void Vertical_Gray17_Set_Pixel( RAS_ARGS int y,
+ int x,
+ int color )
+ {
+ (void)color; /* unused here */
+
+ if ( x >= 0 && x < ras.bit_width )
+ {
+ int c1 = x >> 2;
+ int f1 = x & 3;
+ int mask = (0x8000 >> f1) >> ((y & 3)*4);
+
+ if ( ras.gray_min_x > c1/4 ) ras.gray_min_x = c1/4;
+ if ( ras.gray_max_x < c1/4 ) ras.gray_max_x = c1/4;
+
+ ((short*)ras.bit_buffer)[c1] |= mask;
+ }
+ }
+
+
+ static void Vertical_Gray17_Sweep_Step( RAS_ARG )
+ {
+ int c1;
+ PByte pix, bit;
+ long* grays;
+
+
+ ras.trace_bit++;
+
+ if ( ras.trace_bit > 3 )
+ {
+ pix = ras.pix_buffer + ras.trace_pix + ras.gray_min_x*4;
+ grays = ras.grays;
+
+ if ( ras.gray_max_x >= 0 )
+ {
+ if ( ras.gray_max_x >= ras.target.width/4 )
+ ras.gray_max_x = (ras.target.width+3)/4-1;
+
+ if ( ras.gray_min_x < 0 )
+ ras.gray_min_x = 0;
+
+ bit = ras.bit_buffer + ras.gray_min_x*8;
+ c1 = (ras.gray_max_x - ras.gray_min_x + 1);
+
+ while ( c1 >= 0 )
+ {
+ if ( *(long*)bit || *(long*)(bit+4) )
+ {
+ int* table = ras.count_table;
+
+#if defined( FT_RASTER_LITTLE_ENDIAN )
+ /* little-endian specific storage */
+ *(long*)pix = grays[ table[ bit[0] ] +
+ table[ bit[1] ] ] |
+
+ ( grays[ table[ bit[2] ] +
+ table[ bit[3] ] ] << 8 ) |
+
+ ( grays[ table[ bit[4] ] +
+ table[ bit[5] ] ] << 16 ) |
+
+ ( grays[ table[ bit[6] ] +
+ table[ bit[7] ] ] << 24 );
+
+#elif defined( FT_RASTER_BIG_ENDIAN )
+ /* big-endian specific storage */
+ *(long*)pix = ( grays[ table[ bit[0] ] +
+ table[ bit[1] ] ] << 24 |
+
+ ( grays[ table[ bit[2] ] +
+ table[ bit[3] ] ] << 16 ) |
+
+ ( grays[ table[ bit[4] ] +
+ table[ bit[5] ] ] << 8 ) |
+
+ ( grays[ table[ bit[6] ] +
+ table[ bit[7] ] ] );
+#else
+ /* endianess-independent storage */
+ pix[0] = grays[ table[bit[0]] + table[bit[1]] ];
+ pix[1] = grays[ table[bit[2]] + table[bit[3]] ];
+ pix[2] = grays[ table[bit[4]] + table[bit[5]] ];
+ pix[3] = grays[ table[bit[6]] + table[bit[7]] ];
+#endif
+ *(long*)( bit ) = 0;
+ *(long*)(bit+4) = 0;
+ }
+ pix += 4;
+ bit += 8;
+ c1 --;
+ }
+ }
+ ras.trace_bit = 0;
+ ras.trace_pix += ras.trace_incr;
+
+ ras.gray_min_x = 32000;
+ ras.gray_max_x = -32000;
+ }
+ }
+
+
+
+ static void Horizontal_Gray17_Sweep_Span( RAS_ARGS TScan y,
+ TPos x1,
+ TPos x2 )
+ {
+ /* nothing, really */
+ (void)y;
+ (void)x1;
+ (void)x2;
+ }
+
+
+ static
+ int Horizontal_Gray17_Test_Pixel( RAS_ARGS TScan y,
+ int x )
+ {
+ /* don't do anything here */
+ (void)x;
+ (void)y;
+
+ return 0;
+ }
+
+
+ static
+ void Horizontal_Gray17_Set_Pixel( RAS_ARGS TScan y,
+ int x,
+ int color )
+ {
+ char* pixel;
+
+ x = x/4;
+
+ if (x < ras.target.rows)
+ {
+ long pitch = ras.target.pitch;
+
+ pixel = (char*)ras.pix_buffer + (y/4);
+ pixel -= x*pitch;
+ if (pitch > 0)
+ pixel += (ras.target.rows-1)*pitch;
+
+ if (pixel[0] == ras.grays[0])
+ pixel[0] = ras.grays[1+color];
+ }
+ }
+#endif /* FT_RASTER_ANTI_ALIAS_17 */
+
+#endif /* FT_RASTER_OPTION_ANTI_ALIAS */
+
+/********************************************************************/
+/* */
+/* Generic Sweep Drawing routine */
+/* */
+/********************************************************************/
+
+ static TBool Draw_Sweep( RAS_ARG )
+ {
+ TScan y, y_change, y_height;
+
+ PProfile P, Q, P_Left, P_Right;
+
+ TScan min_Y, max_Y, top, bottom, dropouts;
+
+ TPos x1, x2, e1, e2;
+
+ TProfileList wait;
+ TProfileList draw;
+
+ /* Init empty linked lists */
+
+ Init_Linked( &wait );
+ Init_Linked( &draw );
+
+ /* first, compute min and max Y */
+
+ P = ras.start_prof;
+ max_Y = TRUNC( ras.minY );
+ min_Y = TRUNC( ras.maxY );
+
+ while ( P )
+ {
+ Q = P->link;
+
+ bottom = P->start;
+ top = P->start + P->height-1;
+
+ if ( min_Y > bottom ) min_Y = bottom;
+ if ( max_Y < top ) max_Y = top;
+
+ P->X = 0;
+ InsNew( &wait, P );
+
+ P = Q;
+ }
+
+ /* Check the Y-turns */
+ if ( ras.n_turns == 0 )
+ {
+ ras.error = ErrRaster_Invalid_Outline;
+ return FAILURE;
+ }
+
+ /* Now inits the sweep */
+
+ 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;
+ P = P->link;
+ }
+
+ /* Let's go */
+
+ y = min_Y;
+ y_height = 0;
+
+ if ( ras.n_turns > 0 &&
+ ras.pool_size[-ras.n_turns] == min_Y )
+ ras.n_turns--;
+
+ while (ras.n_turns > 0)
+ {
+ PProfile prof = wait;
+
+ /* look in the wait list for new activations */
+ while (prof)
+ {
+ PProfile next = prof->link;
+
+ prof->countL -= y_height;
+ if ( prof->countL == 0 )
+ {
+ DelOld( &wait, prof );
+ InsNew( &draw, prof );
+ }
+ prof = next;
+ }
+
+ /* Sort the drawing lists */
+ Sort( &draw );
+
+ y_change = ras.pool_size[-ras.n_turns--];
+ y_height = y_change - y;
+
+ while ( y < y_change )
+ {
+ int window;
+ PProfile left;
+
+ /* Let's trace */
+
+ dropouts = 0;
+
+ if (!draw)
+ goto Next_Line;
+
+ left = draw;
+ window = left->flow;
+ prof = left->link;
+
+ while (prof)
+ {
+ PProfile next = prof->link;
+
+ window += prof->flow;
+
+ if ( window == 0 )
+ {
+ x1 = left->X;
+ x2 = prof->X;
+#if 1
+ if ( x1 > x2 )
+ {
+ TPos xs = x1;
+ x1 = x2;
+ x2 = xs;
+ }
+#endif
+ if ( x2-x1 <= ras.precision && ras.dropout_mode )
+ {
+#if 1
+ e1 = CEILING( x1 );
+ e2 = FLOOR( x2 );
+#else
+ e1 = FLOOR(x1);
+ e2 = CEILING(x2);
+#endif
+ if ( e1 > e2 || e2 == e1+ ras.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;
+ }
+ }
+
+ ras.Proc_Sweep_Span( RAS_VARS y, x1, x2 );
+
+ Skip_To_Next:
+ left = next;
+ }
+ prof = next;
+ }
+
+ /* now perform the dropouts _after_ the span drawing */
+ /* drop-outs processing has been moved out of the loop */
+ /* for performance tuning */
+ if (dropouts > 0)
+ goto Scan_DropOuts;
+
+ Next_Line:
+
+ ras.Proc_Sweep_Step( RAS_VAR );
+
+ y++;
+
+ if ( y < y_change )
+ Sort( &draw );
+ }
+
+ /* Now finalize the profiles that needs it */
+
+ {
+ PProfile prof, next;
+ prof = draw;
+ while (prof)
+ {
+ next = prof->link;
+ if (prof->height == 0)
+ DelOld( &draw, prof );
+ prof = next;
+ }
+ }
+ }
+
+ /* for gray-scaling, flushes the bitmap scanline cache */
+ while (y <= max_Y)
+ {
+ ras.Proc_Sweep_Step( RAS_VAR );
+ y++;
+ }
+
+ return SUCCESS;
+
+
+Scan_DropOuts :
+ P_Left = draw;
+ while (dropouts > 0)
+ {
+ 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 );
+
+ e1 = CEILING( x1 );
+ e2 = FLOOR ( x2 );
+
+ if ( e1 > e2 )
+ {
+ if ( e1 == e2 + ras.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.Proc_Test_Pixel( RAS_VARS 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;
+ }
+
+ ras.Proc_Set_Pixel( RAS_VARS y,
+ TRUNC(e1),
+ (x2-x1 >= ras.precision_half) & 1 );
+ Next_Dropout:
+
+ dropouts--;
+ }
+ goto Next_Line;
+ }
+
+
+
+/****************************************************************************/
+/* */
+/* 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. */
+/* */
+/****************************************************************************/
+
+ static
+ int Render_Single_Pass( RAS_ARGS int flipped )
+ {
+ int i, j, k;
+
+ ras.flipped = flipped;
+
+ while ( ras.band_top >= 0 )
+ {
+ ras.maxY = ((long)ras.band_stack[ras.band_top].y_max <<
+ (ras.scale_shift+6))-1;
+
+ ras.minY = (long)ras.band_stack[ras.band_top].y_min <<
+ (ras.scale_shift+6);
+
+ ras.cursor = ras.pool;
+ ras.error = 0;
+
+ if ( Convert_Glyph( RAS_VARS ras.outline ) )
+ {
+ if ( ras.error != ErrRaster_Overflow ) return FAILURE;
+ ras.error = ErrRaster_Ok;
+
+ /* sub-banding */
+
+#ifdef DEBUG_RASTER
+ ClearBand( RAS_VARS TRUNC( ras.minY ), TRUNC( ras.maxY ) );
+#endif
+
+ i = ras.band_stack[ras.band_top].y_min;
+ j = ras.band_stack[ras.band_top].y_max;
+
+ k = ( j-i ) >> 1;
+
+ if ( ras.band_top >= 7 || k == 0 )
+ {
+ ras.band_top = 0;
+ ras.error = ErrRaster_Invalid_Outline;
+ return ras.error;
+ }
+
+ ras.band_stack[ras.band_top+1].y_min = i + k;
+ ras.band_stack[ras.band_top+1].y_max = j;
+
+ ras.band_stack[ras.band_top].y_max = i + k;
+
+ ras.band_top++;
+ }
+ else
+ {
+ if ( ras.start_prof )
+ if ( Draw_Sweep( RAS_VAR ) ) return ras.error;
+ ras.band_top--;
+ }
+ }
+
+ return 0; /* success */
+ }
+
+
+#if 0
+ void Compute_BBox( FT_Outline* outline,
+ FT_BBox* bbox )
+ {
+ int n;
+ FT_Vector* vec;
+
+ vec = outline->points;
+ bbox->xMin = bbox->xMax = vec->x;
+ bbox->yMin = bbox->yMax = vec->y;
+
+ n = outline->n_points-1;
+ while ( n > 0 )
+ {
+ FT_Pos x, y;
+
+ vec++;
+
+ x = vec->x;
+ if ( bbox->xMin > x ) bbox->xMin = x;
+ if ( bbox->xMax < x ) bbox->xMax = x;
+
+ y = vec->y;
+ if ( bbox->yMin > y ) bbox->yMin = y;
+ if ( bbox->yMax < y ) bbox->yMax = y;
+
+ n--;
+ }
+ }
+#endif
+
+ static
+ int Raster_Render1( FT_Raster raster )
+ {
+ int error;
+ long byte_len;
+
+ byte_len = ras.target.pitch;
+ if (byte_len < 0) byte_len = -byte_len;
+
+ if ( ras.target.width > byte_len*8 )
+ return ErrRaster_Invalid_Map;
+
+ ras.scale_shift = (ras.precision_bits-6);
+
+ /* Vertical Sweep */
+ ras.band_top = 0;
+ ras.band_stack[0].y_min = 0;
+ ras.band_stack[0].y_max = ras.target.rows;
+
+ ras.Proc_Sweep_Init = Vertical_Sweep_Init;
+ ras.Proc_Sweep_Span = Vertical_Sweep_Span;
+ ras.Proc_Sweep_Step = Vertical_Sweep_Step;
+ ras.Proc_Test_Pixel = Vertical_Test_Pixel;
+ ras.Proc_Set_Pixel = Vertical_Set_Pixel;
+
+ ras.bit_width = ras.target.width;
+ ras.bit_buffer = (unsigned char*)ras.target.buffer;
+
+ if ( (error = Render_Single_Pass( RAS_VARS 0 )) != 0 )
+ return error;
+
+ /* Horizontal Sweep */
+
+ if ( ras.second_pass && ras.dropout_mode != 0 )
+ {
+ ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+ ras.Proc_Sweep_Span = Horizontal_Sweep_Span;
+ ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
+ ras.Proc_Test_Pixel = Horizontal_Test_Pixel;
+ ras.Proc_Set_Pixel = Horizontal_Set_Pixel;
+
+ ras.band_top = 0;
+ ras.band_stack[0].y_min = 0;
+ ras.band_stack[0].y_max = ras.target.width - 1;
+
+ if ( (error = Render_Single_Pass( RAS_VARS 1 )) != 0 )
+ return error;
+ }
+
+ return ErrRaster_Ok;
+ }
+
+
+
+#ifdef FT_RASTER_OPTION_ANTI_ALIAS
+ static
+ int Raster_Render8( FT_Raster raster )
+ {
+ int error;
+ long byte_len;
+
+ byte_len = ras.target.pitch;
+ if (byte_len < 0) byte_len = -byte_len;
+
+ if ( ras.target.width > byte_len )
+ 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;
+
+#if !defined(FT_RASTER_ANTI_ALIAS_5) && !defined(FT_RASTER_ANTI_ALIAS_17)
+ return ErrRaster_Unimplemented;
+#endif
+
+#ifdef FT_RASTER_ANTI_ALIAS_5
+ if ( ras.grays_count == 5 )
+ {
+ ras.scale_shift = (ras.precision_bits-5);
+ ras.bit_width = ras.gray_width/2;
+ if ( ras.bit_width > (ras.target.width+3)/4 )
+ ras.bit_width = (ras.target.width+3)/4;
+
+ ras.bit_width = ras.bit_width * 8;
+ ras.bit_buffer = (unsigned char*)ras.gray_lines;
+ ras.pix_buffer = (unsigned char*)ras.target.buffer;
+
+ ras.Proc_Sweep_Init = Vertical_Gray5_Sweep_Init;
+ ras.Proc_Sweep_Span = Vertical_Gray5_Sweep_Span;
+ ras.Proc_Sweep_Step = Vertical_Gray5_Sweep_Step;
+ ras.Proc_Test_Pixel = Vertical_Gray5_Test_Pixel;
+ ras.Proc_Set_Pixel = Vertical_Gray5_Set_Pixel;
+ }
+#endif
+
+#ifdef FT_RASTER_ANTI_ALIAS_17
+ if ( ras.grays_count == 17 )
+ {
+ ras.scale_shift = (ras.precision_bits-4);
+ ras.bit_width = ras.gray_width/4;
+ if ( ras.bit_width > (ras.target.width+1)/2 )
+ ras.bit_width = (ras.target.width+1)/2;
+
+ ras.bit_width = ras.bit_width * 8;
+ ras.bit_buffer = (unsigned char*)ras.gray_lines;
+ ras.pix_buffer = (unsigned char*)ras.target.buffer;
+
+ ras.Proc_Sweep_Init = Vertical_Gray17_Sweep_Init;
+ ras.Proc_Sweep_Span = Vertical_Gray17_Sweep_Span;
+ ras.Proc_Sweep_Step = Vertical_Gray17_Sweep_Step;
+ ras.Proc_Test_Pixel = Vertical_Gray17_Test_Pixel;
+ ras.Proc_Set_Pixel = Vertical_Gray17_Set_Pixel;
+ }
+#endif
+
+ error = Render_Single_Pass( RAS_VARS 0 );
+ if (error)
+ return error;
+
+ /* Horizontal Sweep */
+
+ if ( ras.second_pass && ras.dropout_mode != 0 )
+ {
+#ifdef FT_RASTER_ANTI_ALIAS_5
+ if ( ras.grays_count == 5 )
+ {
+ ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+ ras.Proc_Sweep_Span = Horizontal_Gray5_Sweep_Span;
+ ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
+ ras.Proc_Test_Pixel = Horizontal_Gray5_Test_Pixel;
+ ras.Proc_Set_Pixel = Horizontal_Gray5_Set_Pixel;
+ }
+#endif
+
+#ifdef FT_RASTER_ANTI_ALIAS_17
+ if ( ras.grays_count == 17 )
+ {
+ ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+ ras.Proc_Sweep_Span = Horizontal_Gray17_Sweep_Span;
+ ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
+ ras.Proc_Test_Pixel = Horizontal_Gray17_Test_Pixel;
+ ras.Proc_Set_Pixel = Horizontal_Gray17_Set_Pixel;
+ }
+#endif
+ ras.band_top = 0;
+ ras.band_stack[0].y_min = 0;
+ ras.band_stack[0].y_max = ras.target.width-1;
+
+ error = Render_Single_Pass( RAS_VARS 1 );
+ if (error)
+ return error;
+ }
+
+ return ErrRaster_Ok;
+ }
+
+#else /* ANTI_ALIAS */
+
+ static
+ int Raster_Render8( FT_Raster raster )
+ {
+ return ErrRaster_Unimplemented;
+ }
+
+#endif /* FT_RASTER_OPTION_ANTI_ALIAS */
+
+
+
+#ifdef FT_RASTER_OPTION_ANTI_ALIAS
+/****************************************************************************/
+/* */
+/* <Function> Reset_Palette_5 */
+/* */
+/* <Description> Resets lookup table when the 5-gray-levels palette changes */
+/* */
+/****************************************************************************/
+
+static
+void Reset_Palette_5( RAS_ARG )
+{
+ int i;
+
+ for ( i = 0; i < 256; i++ )
+ {
+ int cnt1, cnt2;
+
+ cnt1 = ((i & 128) >> 7) +
+ ((i & 64) >> 6) +
+ ((i & 8) >> 3) +
+ ((i & 4) >> 2);
+
+ cnt2 = ((i & 32) >> 5) +
+ ((i & 16) >> 4) +
+ ((i & 2) >> 1) +
+ (i & 1);
+
+ /* */
+ /* Note that when the endianess isn't specified through one of the */
+ /* configuration, we use the big-endian storage in 'count_table' */
+ /* */
+
+#if defined( FT_RASTER_LITTLE_ENDIAN )
+ ras.count_table[i] = (ras.grays[cnt2] << 8) | ras.grays[cnt1];
+#else
+ ras.count_table[i] = (ras.grays[cnt1] << 8) | ras.grays[cnt2];
+#endif
+ }
+}
+
+/****************************************************************************/
+/* */
+/* <Function> Reset_Palette_17 */
+/* */
+/* <Description> Resets lookup table when 17-gray-levels palette changes */
+/* */
+/****************************************************************************/
+
+#ifdef FT_RASTER_ANTI_ALIAS_17
+static
+void Reset_Palette_17( RAS_ARG )
+{
+ int i;
+
+ for ( i = 0; i < 256; i++ )
+ ras.count_table[i] =
+ ((i & 128) >> 7) +
+ ((i & 64) >> 6) +
+ ((i & 8) >> 3) +
+ ((i & 4) >> 2) +
+ ((i & 32) >> 5) +
+ ((i & 16) >> 4) +
+ ((i & 2) >> 1) +
+ (i & 1);
+}
+#endif /* ANTI_ALIAS_17 */
+
+#endif /* TT_RASTER_OPTION_ANTI_ALIAS */
+
+
+
+ /**********************************************************************/
+ /* */
+ /* <Function> FT_Raster_SetPalette */
+ /* */
+ /* <Description> */
+ /* Set the pixmap rendering palette. anti-aliasing modes are */
+ /* implemented/possible, they differ from the number of */
+ /* entries in the palette. */
+ /* */
+ /* <Input> */
+ /* count :: the number of palette entries. Valid values are */
+ /* 2, 5 and 17, which are the number of intermediate */
+ /* gray levels supported */
+ /* */
+ /* palette :: an array of 'count' chars giving the 8-bit palette */
+ /* of intermediate "gray" levels for anti-aliased */
+ /* rendering. */
+ /* */
+ /* In all modes, palette[0] corresponds to the background, */
+ /* while palette[count-1] to the foreground. Hence, a count */
+ /* of 2 corresponds to no anti-aliasing; a count of 5 uses */
+ /* 3 intermediate levels between the background and */
+ /* foreground, while a count of 17 uses 15 of them.. */
+ /* */
+ /* <Return> */
+ /* An error code, used as a FT_Error by the FreeType library. */
+ /* */
+ /* <Note> */
+ /* By default, a new object uses mode 5, with a palette of */
+ /* 0,1,2,3 and 4. You don't need to set the palette if you */
+ /* don't need to render pixmaps.. */
+ /* */
+ /**********************************************************************/
+
+ EXPORT_FUNC
+ int FT_Raster_SetPalette( FT_Raster raster,
+ int count,
+ const char* palette )
+ {
+ switch (count)
+ {
+#ifdef FT_RASTER_OPTION_ANTI_ALIAS
+
+ /******************************/
+ /* The case of 17 gray levels */
+ /******************************/
+
+ case 17:
+#ifdef FT_RASTER_ANTI_ALIAS_17
+ {
+ int n;
+
+ raster->grays_count = count;
+ for ( n = 0; n < count; n++ )
+ raster->grays[n] = (unsigned char)palette[n];
+ Reset_Palette_17( RAS_VAR );
+ break;
+ }
+#else
+ return ErrRaster_Unimplemented;
+#endif
+
+ /*****************************/
+ /* The case of 5 gray levels */
+ /*****************************/
+
+ case 5:
+#ifdef FT_RASTER_ANTI_ALIAS_5
+ {
+ int n;
+
+ raster->grays_count = count;
+ for ( n = 0; n < count; n++ )
+ raster->grays[n] = (unsigned char)palette[n];
+ Reset_Palette_5( RAS_VAR );
+ break;
+ }
+#else
+ return ErrRaster_Unimplemented;
+#endif
+
+#endif /* FT_RASTER_OPTION_ANTI_ALIAS */
+ default:
+ return ErrRaster_Bad_Palette_Count;
+ }
+
+ return ErrRaster_Ok;
+ }
+
+
+ /**** RASTER OBJECT CREATION : in standalone mode, we simply use *****/
+ /**** a static object .. *****/
+#ifdef _STANDALONE_
+
+ static
+ int ft_black2_new( void* memory, FT_Raster *araster )
+ {
+ static FT_RasterRec_ the_raster;
+ *araster = &the_raster;
+ memset( &the_raster, sizeof(the_raster), 0 );
+ return 0;
+ }
+
+ static
+ void ft_black2_done( FT_Raster raster )
+ {
+ /* nothing */
+ raster->init = 0;
+ }
+
+#else
+
+#include <ftobjs.h>
+
+ static
+ int ft_black2_new( FT_Memory memory, FT_Raster *araster )
+ {
+ FT_Error error;
+ FT_Raster raster;
+
+ *araster = 0;
+ if ( !ALLOC( raster, sizeof(*raster) ))
+ {
+ raster->memory = memory;
+ *araster = raster;
+ }
+
+ return error;
+ }
+
+ static
+ void ft_black2_done( FT_Raster raster )
+ {
+ FT_Memory memory = (FT_Memory)raster->memory;
+ FREE( raster );
+ }
+
+#endif
+
+
+ static void ft_black2_reset( FT_Raster raster,
+ const char* pool_base,
+ long pool_size )
+ {
+ static const char default_palette[5] = { 0, 1, 2, 3, 4 };
+
+ /* check the object address */
+ if ( !raster )
+ return;
+
+ /* check the render pool - we won't go under 4 Kb */
+ if ( !pool_base || pool_size < 4096 )
+ return;
+
+ /* save the pool */
+ raster->pool = (PPos)pool_base;
+ raster->pool_size = (PPos)(pool_base + (pool_size & -8));
+
+#ifdef FT_RASTER_OPTION_ANTI_ALIAS
+ raster->gray_width = ANTI_ALIAS_BUFFER_SIZE/2;
+ /* clear anti-alias intermediate lines */
+ {
+ char* p = raster->gray_lines;
+ int size = ANTI_ALIAS_BUFFER_SIZE;
+ do
+ {
+ *p++ = 0;
+ size--;
+
+ } while (size > 0);
+ }
+#endif
+
+ /* set the default palette : 5 levels = 0, 1, 2, 3 and 4 */
+ FT_Raster_SetPalette( raster, 5, default_palette );
+ }
+
+
+ static
+ int ft_black2_render( FT_Raster 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_Uninitialised_Object;
+
+ if ( !outline || !outline->contours || !outline->points )
+ return ErrRaster_Invalid_Outline;
+
+ /* return immediately if the outline is empty */
+ if ( outline->n_points == 0 || outline->n_contours <= 0 )
+ return ErrRaster_Invalid_Outline;
+
+ if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 )
+ return ErrRaster_Invalid_Outline;
+
+ if ( !target_map || !target_map->buffer )
+ return ErrRaster_Invalid_Map;
+
+ /* this version of the raster does not support direct rendering, sorry */
+ if ( params->flags & ft_raster_flag_direct )
+ return ErrRaster_Unimplemented;
+
+ ras.outline = outline;
+ ras.target = *target_map;
+
+ ras.dropout_mode = 2;
+ ras.second_pass = !(outline->flags & ft_outline_single_pass);
+ SET_High_Precision( (outline->flags & ft_outline_high_precision) );
+
+ return ( params->flags & ft_raster_flag_aa
+ ? Raster_Render8(raster)
+ : Raster_Render1(raster) );
+ }
+
+
+ FT_Raster_Funcs ft_black2_raster =
+ {
+ ft_glyph_format_outline,
+ (FT_Raster_New_Func) ft_black2_new,
+ (FT_Raster_Reset_Func) ft_black2_reset,
+ (FT_Raster_Set_Mode_Func) 0,
+ (FT_Raster_Render_Func) ft_black2_render,
+ (FT_Raster_Done_Func) ft_black2_done
+ };
+
+
diff --git a/demos/src/ftrast2.h b/demos/src/ftrast2.h
new file mode 100644
index 0000000..8cd9adb
--- /dev/null
+++ b/demos/src/ftrast2.h
@@ -0,0 +1,42 @@
+/*******************************************************************
+ *
+ * ftraster.h v 2.0
+ *
+ * The FreeType glyph scan-line converter (interface)
+ *
+ * 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.
+ *
+ *
+ ******************************************************************/
+
+#ifndef FTRAST2_H
+#define FTRAST2_H
+
+#include <ftimage.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef EXPORT_DEF
+#define EXPORT_DEF /* nothing */
+#endif
+
+ EXPORT_DEF
+ FT_Raster_Funcs ft_black2_raster;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FTRAST2_H */
+
+
+/* END */
diff --git a/demos/src/ftview.c b/demos/src/ftview.c
index b0c0921..e0367b4 100644
--- a/demos/src/ftview.c
+++ b/demos/src/ftview.c
@@ -28,7 +28,7 @@
#include "grfont.h"
#include "ftgrays.h"
-#include "ftrast.h"
+#include "ftrast2.h"
#define DIM_X 500
#define DIM_Y 400
@@ -425,7 +425,7 @@ $\243^\250*\265\371%!\247:/;.,?<>";
error = 1;
if ( !antialias)
- error = FT_Set_Raster( library, &ft_black_raster );
+ error = FT_Set_Raster( library, &ft_black2_raster );
else if ( use_grays && antialias )
error = FT_Set_Raster( library, &ft_grays_raster );