interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / allen / look-paint.om

755 lines · 37779 bytes Raw Blame History
1note SPDX-License-Identifier: MIT
2note Allen's look, part 1: the drawing kit. Handwritten Omega port of native/kernel/ui/paint.h and
3note paint.c (aienux 4b24df65): integer sine, arctangent, exp(-x), log2, hash noise, light-weighted
4note colour blending through the sky's transfer tables, and the glow, thread, rounded-rectangle and
5note letter shapes. Every function gives the same integers as the C kit; tests/look-paint.om compares
6note them value for value against the C harness. Needs font-data.om and font.om before it (afsqrt,
7note afglyph) and pkinit once before any other call.
8note Shared memory (declared here, used by every look-* module):
9note Lg: 0 screen width, 1 height, 2 k (1/256 px per design px of a 1920x1080 design), 3 sky centre x,
10note 4 sky centre y, 5..8 the clip rectangle x,y,w,h every shape is held inside (pkclip sets it),
11note 9 the rounded rectangle's radius for pksdrrect, 10..15 PAINT scratch (unused so far).
12note Nfrm: the frame being drawn, one packed RGB word (R<<16|G<<8|B) per pixel, rows Lg[0] apart.
13note Nsky: the sky as it was made at startup, the same layout.
14note Slin: ck_sky_lin, sRGB byte -> linear light Q15. Ssrgb: ck_sky_srgb16, light>>3 -> sRGB x16.
15note Both are filled by pkinit from Plin/Psrgb, the exact values of sky_data.c.
16note Pa: the argument block for calls with more than six values. pkthread reads Pa[0] = width in
17note 16ths of a pixel, Pa[1] = a0, Pa[2] = a1 (its sixth value a01 is ignored; pass 0). pkletter's
18note face is the font's own state (afinit before use). Ps is PAINT's private scratch.
19note Signatures (same integers as the C): pksin/pkcos a (turns/65536) -> Q14; pkatan2 y x -> 0..65535;
20note pkexpneg x -> exp(-x/256)*65536; pklog2q16 v -> log2(v)*65536; pkisqrt v; pkhash x y seed;
21note pknoise x256 y256 seed; pkfbm x256 y256 seed octaves; pklenc light; pkscale c f; pkadd d c a;
22note pkmix d c a; pksmooth t; pkeaseout t; pkprog now from upto; pkclip x y w h; pkglow cx cy r color a
23note (16ths); pkthread x0 y0 x1 y1 color a01 (16ths, Pa as above); pksdrrect x y rx ry rw rh (Lg[9]);
24note pkcover d16; pkletter pen y c color a plus -> pen after (pen in 1/256 px, plus true = additive).
25const LOOKPX ulong 8294400
26global Lg long 16
27global Nfrm uint LOOKPX
28global Nsky uint LOOKPX
29global Slin ushort 256
30global Ssrgb ushort 4096
31global Pa long 8
32global Psin long 4097
33global Pexp ulong 4096
34global Plog ulong 257
35global Patan ulong 14
36note Ps: 0 glow cx, 1 cy, 2 r2, 3 inv, 4 color, 5 a, 6 x0, 7 x1-1; 8..18 thread x0 y0 x1 y1 color a0 a1
37note len grad radius steep yc, 27 a; 20..26 letter gx gy color a plus x0 x1; 28..31 pkfit x0 y0 x1 y1
38global Ps long 32
39global Pgc ulong 3
40global Pgt ulong 514
41text Plin "0 10 20 30 40 50 60 70 80 90 99 110 120 132 144 157 170 184 198 213 229 246 263 281 299 319 338 359 381 403 425 449 473 498 524 551 578 606 635 665 695 727 759 792 825 860 895 931 969 1006 1045 1085 1125 1167 1209 1252 1296 1341 1386 1433 1481 1529 1578 1629 1680 1732 1785 1839 1894 1950 2007 2065 2123 2183 2244 2306 2368 2432 2496 2562 2629 2696 2765 2834 2905 2977 3049 3123 3198 3273 3350 3428 3507 3587 3668 3750 3833 3917 4002 4089 4176 4264 4354 4444 4536 4629 4723 4818 4914 5011 5109 5209 5309 5411 5514 5618 5723 5829 5936 6045 6155 6265 6377 6490 6605 6720 6837 6954 7073 7193 7315 7437 7561 7686 7812 7939 8068 8197 8328 8460 8593 8728 8864 9001 9139 9278 9419 9561 9704 9848 9994 10141 10289 10438 10589 10741 10894 11048 11204 11361 11519 11679 11839 12001 12165 12329 12495 12663 12831 13001 13172 13344 13518 13693 13870 14047 14226 14407 14588 14771 14956 15141 15328 15517 15706 15897 16090 16284 16479 16675 16873 17072 17273 17474 17678 17882 18088 18296 18504 18715 18926 19139 19353 19569 19786 20005 20225 20446 20669 20893 21118 21345 21574 21803 22035 22267 22501 22737 22974 23212 23452 23693 23936 24180 24425 24672 24921 25171 25422 25675 25929 26185 26442 26701 26961 27223 27486 27750 28016 28284 28553 28823 29095 29369 29644 29920 30198 30478 30759 31041 31325 31611 31898 32186 32476 32768 "
42text Psrgb "0 13 26 39 51 64 77 90 103 116 129 142 154 167 180 191 203 214 224 234 244 254 263 272 281 290 298 307 315 323 331 338 346 353 360 367 374 381 388 395 401 408 414 420 427 433 439 445 451 456 462 468 474 479 485 490 495 501 506 511 516 522 527 532 537 542 546 551 556 561 566 570 575 579 584 589 593 598 602 606 611 615 619 624 628 632 636 640 645 649 653 657 661 665 669 673 677 681 684 688 692 696 700 703 707 711 715 718 722 726 729 733 736 740 744 747 751 754 758 761 764 768 771 775 778 781 785 788 791 795 798 801 805 808 811 814 817 821 824 827 830 833 836 839 843 846 849 852 855 858 861 864 867 870 873 876 879 882 885 887 890 893 896 899 902 905 908 910 913 916 919 922 924 927 930 933 936 938 941 944 946 949 952 955 957 960 963 965 968 971 973 976 978 981 984 986 989 991 994 996 999 1002 1004 1007 1009 1012 1014 1017 1019 1022 1024 1027 1029 1032 1034 1036 1039 1041 1044 1046 1049 1051 1053 1056 1058 1061 1063 1065 1068 1070 1072 1075 1077 1079 1082 1084 1086 1089 1091 1093 1096 1098 1100 1102 1105 1107 1109 1111 1114 1116 1118 1120 1123 1125 1127 1129 1132 1134 1136 1138 1140 1143 1145 1147 1149 1151 1153 1156 1158 1160 1162 1164 1166 1168 1170 1173 1175 1177 1179 1181 1183 1185 1187 1189 1191 1194 1196 1198 1200 1202 1204 1206 1208 1210 1212 1214 1216 1218 1220 1222 1224 1226 1228 1230 1232 1234 1236 1238 1240 1242 1244 1246 1248 1250 1252 1254 1256 1258 1260 1262 1264 1266 1268 1269 1271 1273 1275 1277 1279 1281 1283 1285 1287 1289 1290 1292 1294 1296 1298 1300 1302 1304 1305 1307 1309 1311 1313 1315 1317 1318 1320 1322 1324 1326 1328 1329 1331 1333 1335 1337 1339 1340 1342 1344 1346 1348 1349 1351 1353 1355 1356 1358 1360 1362 1364 1365 1367 1369 1371 1372 1374 1376 1378 1379 1381 1383 1385 1386 1388 1390 1392 1393 1395 1397 1398 1400 1402 1404 1405 1407 1409 1410 1412 1414 1415 1417 1419 1420 1422 1424 1426 1427 1429 1431 1432 1434 1436 1437 1439 1441 1442 1444 1445 1447 1449 1450 1452 1454 1455 1457 1459 1460 1462 1463 1465 1467 1468 1470 1472 1473 1475 1476 1478 1480 1481 1483 1484 1486 1488 1489 1491 1492 1494 1496 1497 1499 1500 1502 1503 1505 1507 1508 1510 1511 1513 1514 1516 1517 1519 1521 1522 1524 1525 1527 1528 1530 1531 1533 1534 1536 1538 1539 1541 1542 1544 1545 1547 1548 1550 1551 1553 1554 1556 1557 1559 1560 1562 1563 1565 1566 1568 1569 1571 1572 1574 1575 1577 1578 1580 1581 1583 1584 1586 1587 1589 1590 1591 1593 1594 1596 1597 1599 1600 1602 1603 1605 1606 1607 1609 1610 1612 1613 1615 1616 1618 1619 1620 1622 1623 1625 1626 1628 1629 1630 1632 1633 1635 1636 1638 1639 1640 1642 1643 1645 1646 1647 1649 1650 1652 1653 1654 1656 1657 1659 1660 1661 1663 1664 1666 1667 1668 1670 1671 1672 1674 1675 1677 1678 1679 1681 1682 1683 1685 1686 1688 1689 1690 1692 1693 1694 1696 1697 1698 1700 1701 1702 1704 1705 1707 1708 1709 1711 1712 1713 1715 1716 1717 1719 1720 1721 1723 1724 1725 1727 1728 1729 1731 1732 1733 1734 1736 1737 1738 1740 1741 1742 1744 1745 1746 1748 1749 1750 1752 1753 1754 1755 1757 1758 1759 1761 1762 1763 1765 1766 1767 1768 1770 1771 1772 1774 1775 1776 1777 1779 1780 1781 1782 1784 1785 1786 1788 1789 1790 1791 1793 1794 1795 1796 1798 1799 1800 1801 1803 1804 1805 1806 1808 1809 1810 1811 1813 1814 1815 1816 1818 1819 1820 1821 1823 1824 1825 1826 1828 1829 1830 1831 1833 1834 1835 1836 1837 1839 1840 1841 1842 1844 1845 1846 1847 1848 1850 1851 1852 1853 1855 1856 1857 1858 1859 1861 1862 1863 1864 1865 1867 1868 1869 1870 1871 1873 1874 1875 1876 1877 1879 1880 1881 1882 1883 1885 1886 1887 1888 1889 1891 1892 1893 1894 1895 1896 1898 1899 1900 1901 1902 1904 1905 1906 1907 1908 1909 1911 1912 1913 1914 1915 1916 1918 1919 1920 1921 1922 1923 1924 1926 1927 1928 1929 1930 1931 1933 1934 1935 1936 1937 1938 1939 1941 1942 1943 1944 1945 1946 1947 1949 1950 1951 1952 1953 1954 1955 1957 1958 1959 1960 1961 1962 1963 1965 1966 1967 1968 1969 1970 1971 1972 1974 1975 1976 1977 1978 1979 1980 1981 1982 1984 1985 1986 1987 1988 1989 1990 1991 1992 1994 1995 1996 1997 1998 1999 2000 2001 2002 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 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 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 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 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2358 2359 2360 2361 2362 2363 2364 2365 2366 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2375 2376 2377 2378 2379 2380 2381 2382 2382 2383 2384 2385 2386 2387 2388 2389 2390 2390 2391 2392 2393 2394 2395 2396 2397 2397 2398 2399 2400 2401 2402 2403 2404 2404 2405 2406 2407 2408 2409 2410 2411 2411 2412 2413 2414 2415 2416 2417 2417 2418 2419 2420 2421 2422 2423 2424 2424 2425 2426 2427 2428 2429 2430 2430 2431 2432 2433 2434 2435 2436 2436 2437 2438 2439 2440 2441 2442 2442 2443 2444 2445 2446 2447 2448 2448 2449 2450 2451 2452 2453 2454 2454 2455 2456 2457 2458 2459 2460 2460 2461 2462 2463 2464 2465 2465 2466 2467 2468 2469 2470 2471 2471 2472 2473 2474 2475 2476 2476 2477 2478 2479 2480 2481 2481 2482 2483 2484 2485 2486 2486 2487 2488 2489 2490 2491 2492 2492 2493 2494 2495 2496 2497 2497 2498 2499 2500 2501 2501 2502 2503 2504 2505 2506 2506 2507 2508 2509 2510 2511 2511 2512 2513 2514 2515 2516 2516 2517 2518 2519 2520 2520 2521 2522 2523 2524 2525 2525 2526 2527 2528 2529 2530 2530 2531 2532 2533 2534 2534 2535 2536 2537 2538 2539 2539 2540 2541 2542 2543 2543 2544 2545 2546 2547 2547 2548 2549 2550 2551 2551 2552 2553 2554 2555 2556 2556 2557 2558 2559 2560 2560 2561 2562 2563 2564 2564 2565 2566 2567 2568 2568 2569 2570 2571 2572 2572 2573 2574 2575 2576 2576 2577 2578 2579 2580 2580 2581 2582 2583 2584 2584 2585 2586 2587 2588 2588 2589 2590 2591 2592 2592 2593 2594 2595 2596 2596 2597 2598 2599 2599 2600 2601 2602 2603 2603 2604 2605 2606 2607 2607 2608 2609 2610 2611 2611 2612 2613 2614 2614 2615 2616 2617 2618 2618 2619 2620 2621 2621 2622 2623 2624 2625 2625 2626 2627 2628 2629 2629 2630 2631 2632 2632 2633 2634 2635 2636 2636 2637 2638 2639 2639 2640 2641 2642 2642 2643 2644 2645 2646 2646 2647 2648 2649 2649 2650 2651 2652 2653 2653 2654 2655 2656 2656 2657 2658 2659 2659 2660 2661 2662 2662 2663 2664 2665 2666 2666 2667 2668 2669 2669 2670 2671 2672 2672 2673 2674 2675 2675 2676 2677 2678 2679 2679 2680 2681 2682 2682 2683 2684 2685 2685 2686 2687 2688 2688 2689 2690 2691 2691 2692 2693 2694 2694 2695 2696 2697 2697 2698 2699 2700 2700 2701 2702 2703 2703 2704 2705 2706 2706 2707 2708 2709 2709 2710 2711 2712 2712 2713 2714 2715 2715 2716 2717 2718 2718 2719 2720 2721 2721 2722 2723 2724 2724 2725 2726 2727 2727 2728 2729 2730 2730 2731 2732 2733 2733 2734 2735 2736 2736 2737 2738 2738 2739 2740 2741 2741 2742 2743 2744 2744 2745 2746 2747 2747 2748 2749 2750 2750 2751 2752 2752 2753 2754 2755 2755 2756 2757 2758 2758 2759 2760 2761 2761 2762 2763 2763 2764 2765 2766 2766 2767 2768 2769 2769 2770 2771 2771 2772 2773 2774 2774 2775 2776 2777 2777 2778 2779 2779 2780 2781 2782 2782 2783 2784 2785 2785 2786 2787 2787 2788 2789 2790 2790 2791 2792 2792 2793 2794 2795 2795 2796 2797 2797 2798 2799 2800 2800 2801 2802 2803 2803 2804 2805 2805 2806 2807 2808 2808 2809 2810 2810 2811 2812 2813 2813 2814 2815 2815 2816 2817 2818 2818 2819 2820 2820 2821 2822 2823 2823 2824 2825 2825 2826 2827 2827 2828 2829 2830 2830 2831 2832 2832 2833 2834 2835 2835 2836 2837 2837 2838 2839 2839 2840 2841 2842 2842 2843 2844 2844 2845 2846 2847 2847 2848 2849 2849 2850 2851 2851 2852 2853 2854 2854 2855 2856 2856 2857 2858 2858 2859 2860 2861 2861 2862 2863 2863 2864 2865 2865 2866 2867 2868 2868 2869 2870 2870 2871 2872 2872 2873 2874 2874 2875 2876 2877 2877 2878 2879 2879 2880 2881 2881 2882 2883 2883 2884 2885 2886 2886 2887 2888 2888 2889 2890 2890 2891 2892 2892 2893 2894 2894 2895 2896 2897 2897 2898 2899 2899 2900 2901 2901 2902 2903 2903 2904 2905 2905 2906 2907 2908 2908 2909 2910 2910 2911 2912 2912 2913 2914 2914 2915 2916 2916 2917 2918 2918 2919 2920 2920 2921 2922 2922 2923 2924 2925 2925 2926 2927 2927 2928 2929 2929 2930 2931 2931 2932 2933 2933 2934 2935 2935 2936 2937 2937 2938 2939 2939 2940 2941 2941 2942 2943 2943 2944 2945 2945 2946 2947 2947 2948 2949 2949 2950 2951 2952 2952 2953 2954 2954 2955 2956 2956 2957 2958 2958 2959 2960 2960 2961 2962 2962 2963 2964 2964 2965 2966 2966 2967 2968 2968 2969 2970 2970 2971 2972 2972 2973 2974 2974 2975 2976 2976 2977 2978 2978 2979 2979 2980 2981 2981 2982 2983 2983 2984 2985 2985 2986 2987 2987 2988 2989 2989 2990 2991 2991 2992 2993 2993 2994 2995 2995 2996 2997 2997 2998 2999 2999 3000 3001 3001 3002 3003 3003 3004 3005 3005 3006 3006 3007 3008 3008 3009 3010 3010 3011 3012 3012 3013 3014 3014 3015 3016 3016 3017 3018 3018 3019 3020 3020 3021 3021 3022 3023 3023 3024 3025 3025 3026 3027 3027 3028 3029 3029 3030 3031 3031 3032 3033 3033 3034 3034 3035 3036 3036 3037 3038 3038 3039 3040 3040 3041 3042 3042 3043 3043 3044 3045 3045 3046 3047 3047 3048 3049 3049 3050 3051 3051 3052 3052 3053 3054 3054 3055 3056 3056 3057 3058 3058 3059 3060 3060 3061 3061 3062 3063 3063 3064 3065 3065 3066 3067 3067 3068 3068 3069 3070 3070 3071 3072 3072 3073 3074 3074 3075 3075 3076 3077 3077 3078 3079 3079 3080 3081 3081 3082 3082 3083 3084 3084 3085 3086 3086 3087 3088 3088 3089 3089 3090 3091 3091 3092 3093 3093 3094 3094 3095 3096 3096 3097 3098 3098 3099 3099 3100 3101 3101 3102 3103 3103 3104 3105 3105 3106 3106 3107 3108 3108 3109 3110 3110 3111 3111 3112 3113 3113 3114 3115 3115 3116 3116 3117 3118 3118 3119 3120 3120 3121 3121 3122 3123 3123 3124 3125 3125 3126 3126 3127 3128 3128 3129 3129 3130 3131 3131 3132 3133 3133 3134 3134 3135 3136 3136 3137 3138 3138 3139 3139 3140 3141 3141 3142 3143 3143 3144 3144 3145 3146 3146 3147 3147 3148 3149 3149 3150 3151 3151 3152 3152 3153 3154 3154 3155 3155 3156 3157 3157 3158 3159 3159 3160 3160 3161 3162 3162 3163 3163 3164 3165 3165 3166 3166 3167 3168 3168 3169 3170 3170 3171 3171 3172 3173 3173 3174 3174 3175 3176 3176 3177 3177 3178 3179 3179 3180 3181 3181 3182 3182 3183 3184 3184 3185 3185 3186 3187 3187 3188 3188 3189 3190 3190 3191 3191 3192 3193 3193 3194 3194 3195 3196 3196 3197 3197 3198 3199 3199 3200 3200 3201 3202 3202 3203 3204 3204 3205 3205 3206 3207 3207 3208 3208 3209 3210 3210 3211 3211 3212 3213 3213 3214 3214 3215 3216 3216 3217 3217 3218 3219 3219 3220 3220 3221 3222 3222 3223 3223 3224 3224 3225 3226 3226 3227 3227 3228 3229 3229 3230 3230 3231 3232 3232 3233 3233 3234 3235 3235 3236 3236 3237 3238 3238 3239 3239 3240 3241 3241 3242 3242 3243 3244 3244 3245 3245 3246 3246 3247 3248 3248 3249 3249 3250 3251 3251 3252 3252 3253 3254 3254 3255 3255 3256 3257 3257 3258 3258 3259 3259 3260 3261 3261 3262 3262 3263 3264 3264 3265 3265 3266 3267 3267 3268 3268 3269 3269 3270 3271 3271 3272 3272 3273 3274 3274 3275 3275 3276 3277 3277 3278 3278 3279 3279 3280 3281 3281 3282 3282 3283 3284 3284 3285 3285 3286 3286 3287 3288 3288 3289 3289 3290 3291 3291 3292 3292 3293 3293 3294 3295 3295 3296 3296 3297 3297 3298 3299 3299 3300 3300 3301 3302 3302 3303 3303 3304 3304 3305 3306 3306 3307 3307 3308 3308 3309 3310 3310 3311 3311 3312 3313 3313 3314 3314 3315 3315 3316 3317 3317 3318 3318 3319 3319 3320 3321 3321 3322 3322 3323 3323 3324 3325 3325 3326 3326 3327 3327 3328 3329 3329 3330 3330 3331 3331 3332 3333 3333 3334 3334 3335 3335 3336 3337 3337 3338 3338 3339 3339 3340 3341 3341 3342 3342 3343 3343 3344 3345 3345 3346 3346 3347 3347 3348 3349 3349 3350 3350 3351 3351 3352 3353 3353 3354 3354 3355 3355 3356 3357 3357 3358 3358 3359 3359 3360 3360 3361 3362 3362 3363 3363 3364 3364 3365 3366 3366 3367 3367 3368 3368 3369 3370 3370 3371 3371 3372 3372 3373 3373 3374 3375 3375 3376 3376 3377 3377 3378 3379 3379 3380 3380 3381 3381 3382 3382 3383 3384 3384 3385 3385 3386 3386 3387 3387 3388 3389 3389 3390 3390 3391 3391 3392 3393 3393 3394 3394 3395 3395 3396 3396 3397 3398 3398 3399 3399 3400 3400 3401 3401 3402 3403 3403 3404 3404 3405 3405 3406 3406 3407 3408 3408 3409 3409 3410 3410 3411 3411 3412 3413 3413 3414 3414 3415 3415 3416 3416 3417 3418 3418 3419 3419 3420 3420 3421 3421 3422 3423 3423 3424 3424 3425 3425 3426 3426 3427 3428 3428 3429 3429 3430 3430 3431 3431 3432 3432 3433 3434 3434 3435 3435 3436 3436 3437 3437 3438 3439 3439 3440 3440 3441 3441 3442 3442 3443 3443 3444 3445 3445 3446 3446 3447 3447 3448 3448 3449 3449 3450 3451 3451 3452 3452 3453 3453 3454 3454 3455 3455 3456 3457 3457 3458 3458 3459 3459 3460 3460 3461 3461 3462 3463 3463 3464 3464 3465 3465 3466 3466 3467 3467 3468 3469 3469 3470 3470 3471 3471 3472 3472 3473 3473 3474 3474 3475 3476 3476 3477 3477 3478 3478 3479 3479 3480 3480 3481 3482 3482 3483 3483 3484 3484 3485 3485 3486 3486 3487 3487 3488 3489 3489 3490 3490 3491 3491 3492 3492 3493 3493 3494 3494 3495 3496 3496 3497 3497 3498 3498 3499 3499 3500 3500 3501 3501 3502 3503 3503 3504 3504 3505 3505 3506 3506 3507 3507 3508 3508 3509 3509 3510 3511 3511 3512 3512 3513 3513 3514 3514 3515 3515 3516 3516 3517 3517 3518 3519 3519 3520 3520 3521 3521 3522 3522 3523 3523 3524 3524 3525 3525 3526 3527 3527 3528 3528 3529 3529 3530 3530 3531 3531 3532 3532 3533 3533 3534 3534 3535 3536 3536 3537 3537 3538 3538 3539 3539 3540 3540 3541 3541 3542 3542 3543 3543 3544 3545 3545 3546 3546 3547 3547 3548 3548 3549 3549 3550 3550 3551 3551 3552 3552 3553 3553 3554 3555 3555 3556 3556 3557 3557 3558 3558 3559 3559 3560 3560 3561 3561 3562 3562 3563 3563 3564 3564 3565 3566 3566 3567 3567 3568 3568 3569 3569 3570 3570 3571 3571 3572 3572 3573 3573 3574 3574 3575 3575 3576 3576 3577 3578 3578 3579 3579 3580 3580 3581 3581 3582 3582 3583 3583 3584 3584 3585 3585 3586 3586 3587 3587 3588 3588 3589 3589 3590 3591 3591 3592 3592 3593 3593 3594 3594 3595 3595 3596 3596 3597 3597 3598 3598 3599 3599 3600 3600 3601 3601 3602 3602 3603 3603 3604 3604 3605 3606 3606 3607 3607 3608 3608 3609 3609 3610 3610 3611 3611 3612 3612 3613 3613 3614 3614 3615 3615 3616 3616 3617 3617 3618 3618 3619 3619 3620 3620 3621 3621 3622 3622 3623 3624 3624 3625 3625 3626 3626 3627 3627 3628 3628 3629 3629 3630 3630 3631 3631 3632 3632 3633 3633 3634 3634 3635 3635 3636 3636 3637 3637 3638 3638 3639 3639 3640 3640 3641 3641 3642 3642 3643 3643 3644 3644 3645 3645 3646 3646 3647 3647 3648 3649 3649 3650 3650 3651 3651 3652 3652 3653 3653 3654 3654 3655 3655 3656 3656 3657 3657 3658 3658 3659 3659 3660 3660 3661 3661 3662 3662 3663 3663 3664 3664 3665 3665 3666 3666 3667 3667 3668 3668 3669 3669 3670 3670 3671 3671 3672 3672 3673 3673 3674 3674 3675 3675 3676 3676 3677 3677 3678 3678 3679 3679 3680 3680 3681 3681 3682 3682 3683 3683 3684 3684 3685 3685 3686 3686 3687 3687 3688 3688 3689 3689 3690 3690 3691 3691 3692 3692 3693 3693 3694 3694 3695 3695 3696 3696 3697 3697 3698 3698 3699 3699 3700 3700 3701 3701 3702 3702 3703 3703 3704 3704 3705 3705 3706 3706 3707 3707 3708 3708 3709 3709 3710 3710 3711 3711 3712 3712 3713 3713 3714 3714 3715 3715 3716 3716 3717 3717 3718 3718 3719 3719 3720 3720 3721 3721 3722 3722 3723 3723 3724 3724 3725 3725 3726 3726 3727 3727 3728 3728 3729 3729 3730 3730 3731 3731 3732 3732 3733 3733 3734 3734 3735 3735 3735 3736 3736 3737 3737 3738 3738 3739 3739 3740 3740 3741 3741 3742 3742 3743 3743 3744 3744 3745 3745 3746 3746 3747 3747 3748 3748 3749 3749 3750 3750 3751 3751 3752 3752 3753 3753 3754 3754 3755 3755 3756 3756 3757 3757 3758 3758 3759 3759 3760 3760 3760 3761 3761 3762 3762 3763 3763 3764 3764 3765 3765 3766 3766 3767 3767 3768 3768 3769 3769 3770 3770 3771 3771 3772 3772 3773 3773 3774 3774 3775 3775 3776 3776 3777 3777 3778 3778 3778 3779 3779 3780 3780 3781 3781 3782 3782 3783 3783 3784 3784 3785 3785 3786 3786 3787 3787 3788 3788 3789 3789 3790 3790 3791 3791 3792 3792 3793 3793 3793 3794 3794 3795 3795 3796 3796 3797 3797 3798 3798 3799 3799 3800 3800 3801 3801 3802 3802 3803 3803 3804 3804 3805 3805 3806 3806 3806 3807 3807 3808 3808 3809 3809 3810 3810 3811 3811 3812 3812 3813 3813 3814 3814 3815 3815 3816 3816 3817 3817 3817 3818 3818 3819 3819 3820 3820 3821 3821 3822 3822 3823 3823 3824 3824 3825 3825 3826 3826 3827 3827 3828 3828 3828 3829 3829 3830 3830 3831 3831 3832 3832 3833 3833 3834 3834 3835 3835 3836 3836 3837 3837 3838 3838 3838 3839 3839 3840 3840 3841 3841 3842 3842 3843 3843 3844 3844 3845 3845 3846 3846 3847 3847 3847 3848 3848 3849 3849 3850 3850 3851 3851 3852 3852 3853 3853 3854 3854 3855 3855 3856 3856 3856 3857 3857 3858 3858 3859 3859 3860 3860 3861 3861 3862 3862 3863 3863 3864 3864 3864 3865 3865 3866 3866 3867 3867 3868 3868 3869 3869 3870 3870 3871 3871 3872 3872 3872 3873 3873 3874 3874 3875 3875 3876 3876 3877 3877 3878 3878 3879 3879 3879 3880 3880 3881 3881 3882 3882 3883 3883 3884 3884 3885 3885 3886 3886 3886 3887 3887 3888 3888 3889 3889 3890 3890 3891 3891 3892 3892 3893 3893 3893 3894 3894 3895 3895 3896 3896 3897 3897 3898 3898 3899 3899 3900 3900 3900 3901 3901 3902 3902 3903 3903 3904 3904 3905 3905 3906 3906 3907 3907 3907 3908 3908 3909 3909 3910 3910 3911 3911 3912 3912 3913 3913 3913 3914 3914 3915 3915 3916 3916 3917 3917 3918 3918 3919 3919 3919 3920 3920 3921 3921 3922 3922 3923 3923 3924 3924 3925 3925 3925 3926 3926 3927 3927 3928 3928 3929 3929 3930 3930 3931 3931 3931 3932 3932 3933 3933 3934 3934 3935 3935 3936 3936 3937 3937 3937 3938 3938 3939 3939 3940 3940 3941 3941 3942 3942 3942 3943 3943 3944 3944 3945 3945 3946 3946 3947 3947 3948 3948 3948 3949 3949 3950 3950 3951 3951 3952 3952 3953 3953 3953 3954 3954 3955 3955 3956 3956 3957 3957 3958 3958 3958 3959 3959 3960 3960 3961 3961 3962 3962 3963 3963 3963 3964 3964 3965 3965 3966 3966 3967 3967 3968 3968 3968 3969 3969 3970 3970 3971 3971 3972 3972 3973 3973 3973 3974 3974 3975 3975 3976 3976 3977 3977 3978 3978 3978 3979 3979 3980 3980 3981 3981 3982 3982 3983 3983 3983 3984 3984 3985 3985 3986 3986 3987 3987 3988 3988 3988 3989 3989 3990 3990 3991 3991 3992 3992 3992 3993 3993 3994 3994 3995 3995 3996 3996 3997 3997 3997 3998 3998 3999 3999 4000 4000 4001 4001 4001 4002 4002 4003 4003 4004 4004 4005 4005 4006 4006 4006 4007 4007 4008 4008 4009 4009 4010 4010 4010 4011 4011 4012 4012 4013 4013 4014 4014 4014 4015 4015 4016 4016 4017 4017 4018 4018 4019 4019 4019 4020 4020 4021 4021 4022 4022 4023 4023 4023 4024 4024 4025 4025 4026 4026 4027 4027 4027 4028 4028 4029 4029 4030 4030 4031 4031 4031 4032 4032 4033 4033 4034 4034 4035 4035 4035 4036 4036 4037 4037 4038 4038 4039 4039 4039 4040 4040 4041 4041 4042 4042 4043 4043 4043 4044 4044 4045 4045 4046 4046 4047 4047 4047 4048 4048 4049 4049 4050 4050 4051 4051 4051 4052 4052 4053 4053 4054 4054 4054 4055 4055 4056 4056 4057 4057 4058 4058 4058 4059 4059 4060 4060 4061 4061 4062 4062 4062 4063 4063 4064 4064 4065 4065 4066 4066 4066 4067 4067 4068 4068 4069 4069 4069 4070 4070 4071 4071 4072 4072 4073 4073 4073 4074 4074 4075 4075 4076 4076 4076 4077 4077 4078 4078 4079 4079 4080 4080 "
43fn pkmin a long b long to long
44if lt a b
45ret a
46end
47ret b
48end
49fn pkmax a long b long to long
50if gt a b
51ret a
52end
53ret b
54end
55fn pkabs a long to long
56if lt a 0
57ret neg a
58end
59ret a
60end
61fn pkclamp v long lo long hi long to long
62if lt v lo
63ret lo
64end
65if gt v hi
66ret hi
67end
68ret v
69end
70fn pkinitsin to void
71note sine: a rotation by a 4096th of a turn, applied over and over (Q30)
72c = long 1073741824
73s = long 0
74for k ulong 1025
75v = shr add s 32768 16
76if eq k 1024
77v = 16384
78end
79put Psin k v
80put Psin sub 2048 k v
81put Psin and add 2048 k 4095 neg v
82put Psin and sub 4096 k 4095 neg v
83nc = shr sub mul c 1073740561 mul s 1647099 30
84ns = shr add mul s 1073740561 mul c 1647099 30
85c = nc
86s = ns
87end
88put Psin 4096 get Psin 0
89end
90fn pkinitexp to void
91note exp(-k/256): one factor of exp(-1/256) (Q30) per step
92e = ulong 1073741824
93for k ulong 4096
94put Pexp k shr add e 8192 14
95e = shr mul e 1069555701 30
96end
97end
98fn pkinitlog to void
99note log2(1 + k/256): square the value 16 times, taking a bit each time it passes 2
100for k ulong 257
101if eq k 256
102put Plog k 65536
103else
104y = shl add ulong 256 k 8
105r = ulong 0
106for i ulong 16
107b = sub ulong 15 i
108y = shr mul y y 16
109if ge y 131072
110y = shr y 1
111r = or r shl ulong 1 b
112end
113end
114put Plog k r
115end
116end
117end
118fn pkinitatan to void
119put Patan 0 8192
120put Patan 1 4836
121put Patan 2 2555
122put Patan 3 1297
123put Patan 4 651
124put Patan 5 326
125put Patan 6 163
126put Patan 7 81
127put Patan 8 41
128put Patan 9 20
129put Patan 10 10
130put Patan 11 5
131put Patan 12 3
132put Patan 13 1
133end
134fn pkinitlin to void
135v = ulong 0
136slot = ulong 0
137for i ulong len Plin
138c = get Plin i
139if eq c 32
140put Slin slot ushort v
141slot = add slot 1
142v = 0
143else
144v = add mul v 10 sub ulong c 48
145end
146end
147end
148fn pkinitsrgb to void
149v = ulong 0
150slot = ulong 0
151for i ulong len Psrgb
152c = get Psrgb i
153if eq c 32
154put Ssrgb slot ushort v
155slot = add slot 1
156v = 0
157else
158v = add mul v 10 sub ulong c 48
159end
160end
161end
162fn pkinit to void
163for i ulong 3
164put Pgc i 0
165end
166for i ulong 514
167put Pgt i 0
168end
169pkinitsin
170pkinitexp
171pkinitlog
172pkinitatan
173pkinitlin
174pkinitsrgb
175end
176fn pksin a ulong to long
177a = and a 65535
178i = shr a 4
179f = long and a 15
180s0 = get Psin i
181ret add s0 shr mul sub get Psin add i 1 s0 f 4
182end
183fn pkcos a ulong to long
184ret pksin add a 16384
185end
186fn pkatan2 y long x long to ulong
187if and eq x 0 eq y 0
188ret 0
189end
190xx = x
191yy = y
192ang = ulong 0
193if lt xx 0
194xx = neg xx
195yy = neg yy
196ang = 32768
197end
198m = pkmax xx pkabs yy
199while lt m 1048576
200xx = mul xx 2
201yy = mul yy 2
202m = mul m 2
203end
204while ge m 4194304
205xx = shr xx 1
206yy = shr yy 1
207m = shr m 1
208end
209z = long 0
210for i ulong 14
211st = long get Patan i
212nx = xx
213if gt yy 0
214nx = add xx shr yy i
215yy = sub yy shr xx i
216z = add z st
217else
218nx = sub xx shr yy i
219yy = add yy shr xx i
220z = sub z st
221end
222xx = nx
223end
224ret and add ang bitcast ulong z 65535
225end
226fn pkexpneg x ulong to ulong
227if lt x 4096
228ret get Pexp x
229end
230ret 0
231end
232fn pklog2q16 v ulong to ulong
233if eq v 0
234ret 0
235end
236n = ulong 0
237t = v
238while ge t 2 bound 64
239t = shr t 1
240n = add n 1
241end
242m = v
243if ge n 16
244m = shr v sub n 16
245else
246m = shl v sub 16 n
247end
248k = and shr m 8 255
249f = and m 255
250lk = get Plog k
251ret add add mul n 65536 lk shr mul sub get Plog add k 1 lk f 8
252end
253fn pkisqrt v ulong to ulong
254ret afsqrt v
255end
256fn pkbits32 v long to ulong
257ret and bitcast ulong v 4294967295
258end
259fn pkhash x long y long seed ulong to ulong
260m = ulong 4294967295
261a = and mul pkbits32 x 2376512323 m
262b = and mul pkbits32 y 3625334849 m
263c = and mul and seed m 3407524639 m
264h = xor xor a b c
265h = xor h shr h 13
266h = and mul h 1540483477 m
267h = xor h shr h 15
268h = and mul h 668265261 m
269h = xor h shr h 16
270ret h
271end
272fn pksmooth t long to ulong
273t = pkclamp t 0 256
274ret ulong shr mul mul t t sub 768 mul 2 t 16
275end
276fn pkeaseout t long to ulong
277u = sub 256 pkclamp t 0 256
278ret sub ulong 256 ulong shr mul mul u u u 16
279end
280fn pkprog now ulong from ulong upto ulong to long
281if le now from
282ret 0
283end
284if ge now upto
285ret 256
286end
287ret long div mul sub now from 256 sub upto from
288end
289fn pknrow ix long iy long seed ulong fx ulong to ulong
290a = mul shr pkhash ix iy seed 16 sub 256 fx
291ret add a mul shr pkhash add ix 1 iy seed 16 fx
292end
293fn pknoise x long y long seed ulong to ulong
294fx = pksmooth long and pkbits32 x 255
295fy = pksmooth long and pkbits32 y 255
296ix = shr x 8
297iy = shr y 8
298a = pknrow ix iy seed fx
299b = pknrow ix add iy 1 seed fx
300ret shr add mul a sub 256 fy mul b fy 16
301end
302fn pkfbm x long y long seed ulong octaves ulong to ulong
303sum = ulong 0
304total = ulong 0
305for o ulong octaves
306w = shl ulong 1 sub sub octaves 1 o
307sd = and add seed mul o 7919 4294967295
308sum = add sum mul pknoise shl x o shl y o sd w
309total = add total w
310end
311ret div sum total
312end
313fn pklenc light ulong to ulong
314i = shr light 3
315if ge light 32767
316i = 4095
317end
318ret shr add ulong get Ssrgb i 8 4
319end
320fn pkscale c ulong f ulong to ulong
321if eq f 0
322ret 0
323end
324if ge f 256
325ret c
326end
327out = ulong 0
328s = ulong 16
329for k ulong 3
330x = and shr c s 255
331x = pklenc shr mul ulong get Slin x f 8
332out = or out shl x s
333s = sub s 8
334end
335ret out
336end
337fn pkadd d ulong c ulong a ulong to ulong
338if or eq a 0 eq c 0
339ret d
340end
341if and eq d 0 eq a 256
342ret c
343end
344out = ulong 0
345s = ulong 16
346for k ulong 3
347x = and shr d s 255
348y = and shr c s 255
349v = shr mul ulong get Slin y a 8
350if ne v 0
351v = add ulong get Slin x v
352i = shr v 3
353if ge v 32767
354i = 4095
355end
356x = shr add ulong get Ssrgb i 8 4
357end
358out = or out shl x s
359s = sub s 8
360end
361ret out
362end
363fn pkmix d ulong c ulong a ulong to ulong
364if or eq a 0 eq d c
365ret d
366end
367if ge a 256
368ret c
369end
370out = ulong 0
371s = ulong 16
372for k ulong 3
373x = and shr d s 255
374y = and shr c s 255
375if ne x y
376v = mul ulong get Slin x sub 256 a
377v = shr add v mul ulong get Slin y a 8
378i = shr v 3
379if ge v 32767
380i = 4095
381end
382x = shr add ulong get Ssrgb i 8 4
383end
384out = or out shl x s
385s = sub s 8
386end
387ret out
388end
389fn pkcover d16 long to ulong
390v = sub 8 d16
391if le v 0
392ret 0
393end
394if ge v 16
395ret 256
396end
397ret ulong mul v 16
398end
399fn pkclip x long y long w long h long to void
400x0 = pkmax x 0
401y0 = pkmax y 0
402x1 = pkmin add x w get Lg 0
403y1 = pkmin add y h get Lg 1
404put Lg 5 x0
405put Lg 6 y0
406put Lg 7 pkmax sub x1 x0 0
407put Lg 8 pkmax sub y1 y0 0
408end
409fn pkfit x long y long w long h long to bool
410note Ps[28..31] = the part of (x,y,w,h) inside the clip and the screen, as x0 y0 x1 y1; false when empty
411x0 = pkmax x pkmax get Lg 5 0
412y0 = pkmax y pkmax get Lg 6 0
413x1 = add get Lg 5 get Lg 7
414x1 = pkmin x1 get Lg 0
415x1 = pkmin add x w x1
416y1 = add get Lg 6 get Lg 8
417y1 = pkmin y1 get Lg 1
418y1 = pkmin add y h y1
419put Ps 28 x0
420put Ps 29 y0
421put Ps 30 x1
422put Ps 31 y1
423if or le x1 x0 le y1 y0
424ret false
425end
426ret true
427end
428fn pkmeets x long y long w long h long to bool
429x0 = pkmax x get Lg 5
430y0 = pkmax y get Lg 6
431x1 = pkmin add x w add get Lg 5 get Lg 7
432y1 = pkmin add y h add get Lg 6 get Lg 8
433if or le x1 x0 le y1 y0
434ret false
435end
436ret true
437end
438fn pkplot x long y long color ulong a ulong to void
439if eq a 0
440ret
441end
442lx = get Lg 5
443ly = get Lg 6
444if or lt x lx lt y ly
445ret
446end
447if ge x add lx get Lg 7
448ret
449end
450if ge y add ly get Lg 8
451ret
452end
453if or lt x 0 lt y 0
454ret
455end
456if ge x get Lg 0
457ret
458end
459if ge y get Lg 1
460ret
461end
462i = ulong add mul y get Lg 0 x
463put Nfrm i uint pkadd ulong get Nfrm i color a
464end
465fn pkblend i ulong color ulong w ulong to void
466note frame pixel i gets color's light times w/256 added (no clip test: callers fit first)
467put Nfrm i uint pkadd ulong get Nfrm i color w
468end
469fn pkglowrow xa long xb long to void
470note Ps: 0 cx, 2 r2, 3 inv, 4 color, 5 a, 10 y * width, 11 dy*dy
471for i ulong ulong add sub xb xa 1
472x = add xa long i
473dx = add mul x 16 8
474dx = sub dx get Ps 0
475dx = add mul dx dx get Ps 11
476if lt dx get Ps 2
477f = shr mul dx get Ps 3 32
478f = sub 256 f
479f = shr mul shr mul f f 8 f 8
480f = shr mul f get Ps 5 8
481x = add get Ps 10 x
482if eq get Nfrm x 0
483f = add f long get Pgc 2
484put Nfrm x uint get Pgt ulong f
485else
486dx = get Ps 4
487pkblend ulong x ulong dx ulong f
488end
489end
490end
491end
492note pkglowtab: the glow's colour over one black for every weight, kept for the last two
493note colours (two alternate at the merger): most of the sky is one black, so the row's add
494note becomes a table read; the bytes are pkadd's. Pgc: colour of table 0, of table 1, current.
495fn pkglowtab color ulong to void
496if eq get Pgc 0 color
497put Pgc 2 0
498ret
499end
500if eq get Pgc 1 color
501put Pgc 2 257
502ret
503end
504k = ulong 257
505if eq get Pgc 2 257
506k = 0
507end
508put Pgc 2 k
509put Pgc div k 257 color
510for i ulong 257
511put Pgt add k i pkadd 0 color i
512end
513end
514fn pkglowy y long to void
515dy = add mul y 16 8
516dy = sub dy get Ps 1
517dy = mul dy dy
518if lt dy get Ps 2
519put Ps 11 dy
520put Ps 10 mul y get Lg 0
521dy = sub get Ps 2 dy
522half = long pkisqrt ulong dy
523xa = sub get Ps 0 half
524xa = pkmax get Ps 6 shr xa 4
525xb = add get Ps 0 half
526xb = pkmin get Ps 7 shr xb 4
527if le xa xb
528pkglowrow xa xb
529end
530end
531end
532fn pkglow cx long cy long r long color ulong a ulong to void
533if or le r 0 eq a 0
534ret
535end
536x0 = shr sub cx r 4
537y0 = shr sub cy r 4
538if not pkfit x0 y0 add sub shr add cx r 4 x0 1 add sub shr add cy r 4 y0 1
539ret
540end
541put Ps 0 cx
542put Ps 1 cy
543put Ps 2 mul r r
544put Ps 3 div 1099511627776 mul r r
545put Ps 4 long color
546put Ps 5 long a
547put Ps 6 get Ps 28
548put Ps 7 sub get Ps 30 1
549pkglowtab color
550y0 = get Ps 29
551for j ulong ulong sub get Ps 31 y0
552pkglowy add y0 long j
553end
554end
555fn pkthreadpx xc long yy long to void
556note Ps: 12 color, 17 radius, 18 steep, 19 yc (16ths), 27 a
557d = add mul yy 16 8
558d = sub d get Ps 19
559d = sub pkabs d get Ps 17
560cov = pkcover d
561cov = shr mul ulong get Ps 27 cov 8
562color = ulong get Ps 12
563if eq get Ps 18 1
564pkplot yy xc color cov
565else
566pkplot xc yy color cov
567end
568end
569fn pkthreadcol xc long to void
570note one column (row when steep) at major coordinate xc; Ps: 8 x0, 9 y0, 13 a0, 14 a1, 15 len, 16 grad
571along = add mul xc 16 8
572along = sub along get Ps 8
573yc = shr mul along get Ps 16 16
574yc = add yc get Ps 9
575put Ps 19 yc
576a = sub get Ps 14 get Ps 13
577a = div mul a along get Ps 15
578put Ps 27 add a get Ps 13
579ya = sub yc get Ps 17
580ya = shr sub ya 8 4
581yb = add yc get Ps 17
582yb = shr add yb 8 4
583for j ulong ulong add sub yb ya 1
584pkthreadpx xc add ya long j
585end
586end
587fn pkthreadgo to void
588x0 = get Ps 8
589x1 = get Ps 10
590ln = sub x1 x0
591if lt ln 1
592ln = 1
593end
594put Ps 15 ln
595grad = div mul sub get Ps 11 get Ps 9 65536 ln
596put Ps 16 grad
597note slant: the native-scaled width projected onto the minor axis (256 = flat)
598grad = long shr pkisqrt ulong add 4294967296 mul grad grad 8
599put Ps 17 shr mul get Pa 0 grad 9
600first = shr add x0 7 4
601last = shr sub x1 8 4
602x0 = get Lg 5
603x1 = get Lg 7
604if eq get Ps 18 1
605x0 = get Lg 6
606x1 = get Lg 8
607end
608first = pkmax first x0
609last = pkmin last sub add x0 x1 1
610if gt first last
611ret
612end
613for i ulong ulong add sub last first 1
614pkthreadcol add first long i
615end
616end
617fn pkthreadbox x0 long y0 long x1 long y1 long pad long to bool
618bx = sub shr pkmin x0 x1 4 pad
619by = sub shr pkmin y0 y1 4 pad
620bw = add add sub shr pkmax x0 x1 4 bx pad 1
621bh = add add sub shr pkmax y0 y1 4 by pad 1
622ret pkmeets bx by bw bh
623end
624fn pkthread x0 long y0 long x1 long y1 long color ulong a01 ulong to void
625note width, a0 and a1 ride in Pa[0..2] (Omega takes at most six values); a01 is ignored
626w = get Pa 0
627if le w 0
628ret
629end
630if and eq get Pa 1 0 eq get Pa 2 0
631ret
632end
633if not pkthreadbox x0 y0 x1 y1 add shr w 4 1
634ret
635end
636put Ps 18 0
637if gt pkabs sub y1 y0 pkabs sub x1 x0
638put Ps 18 1
639t = x0
640x0 = y0
641y0 = t
642t = x1
643x1 = y1
644y1 = t
645end
646put Ps 13 get Pa 1
647put Ps 14 get Pa 2
648if gt x0 x1
649t = x0
650x0 = x1
651x1 = t
652t = y0
653y0 = y1
654y1 = t
655put Ps 13 get Pa 2
656put Ps 14 get Pa 1
657end
658put Ps 8 x0
659put Ps 9 y0
660put Ps 10 x1
661put Ps 11 y1
662put Ps 12 long color
663pkthreadgo
664end
665fn pksdrrect x long y long rx long ry long rw long rh long to long
666note The rounded rectangle's radius rides in Lg[9] (Omega takes at most six values).
667rad = mul get Lg 9 16
668x = add mul x 16 8
669x = sub x mul rx 16
670x = sub x mul rw 8
671rw = sub mul rw 8 rad
672x = sub pkabs x rw
673y = add mul y 16 8
674y = sub y mul ry 16
675y = sub y mul rh 8
676rh = sub mul rh 8 rad
677y = sub pkabs y rh
678out = pkmax x y
679if and gt x 0 gt y 0
680x = add mul x x mul y y
681out = long pkisqrt ulong x
682end
683ret sub out rad
684end
685fn pkadvance c uchar to ulong
686note the advance of c, 1/256 px: the number after 'w' at the start of its glyph, times the scale
687if not afpick c
688ret 0
689end
690put Afpos 0 add get Afpos 0 1
691ret mul ulong afnum get Af 0
692end
693fn pkletterpx xx long to void
694note Ps: 10 alpha row offset (row*w - gx), 11 y * width, 22 color, 23 a, 24 plus
695cov = ulong get Alpha ulong add xx get Ps 10
696if ne cov 0
697cov = add cov shr cov 7
698cov = shr mul cov ulong get Ps 23 8
699i = ulong add xx get Ps 11
700color = ulong get Ps 22
701if eq get Ps 24 1
702put Nfrm i uint pkadd ulong get Nfrm i color cov
703else
704put Nfrm i uint pkmix ulong get Nfrm i color cov
705end
706end
707end
708fn pkletterrow yy long to void
709m = sub yy get Ps 21
710m = mul m long get Af 3
711put Ps 10 sub m get Ps 20
712put Ps 11 mul yy get Lg 0
713x0 = get Ps 25
714n = ulong sub get Ps 26 x0
715for i ulong n
716pkletterpx add x0 long i
717end
718end
719fn pkletterrows to void
720note every row of the fitted glyph box Ps[28..31]
721put Ps 25 get Ps 28
722put Ps 26 get Ps 30
723y0 = get Ps 29
724n = ulong sub get Ps 31 y0
725for j ulong n
726pkletterrow add y0 long j
727end
728end
729fn pkletter pen ulong y long c uchar color ulong a ulong plus bool to ulong
730note ck_letter: the glyph c of the face afinit made, its pen at pen (1/256 px) on baseline y, mixed in
731note with weight a (added light when plus); returns the pen after it
732if eq a 0
733ret add pen pkadvance c
734end
735if not afglyph c
736ret add pen pkadvance c
737end
738if eq get Af 2 0
739ret add pen get Af 5
740end
741gx = add long div add pen 128 256 get Ab 0
742gy = add y get Ab 1
743if pkfit gx gy long get Af 3 long get Af 4
744put Ps 20 gx
745put Ps 21 gy
746put Ps 22 long color
747put Ps 23 long a
748put Ps 24 0
749if plus
750put Ps 24 1
751end
752pkletterrows
753end
754ret add pen get Af 5
755end