Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/omega/allen/look-paint.om # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / omega / allen / look-paint.om` 755 lines ยท 37779 bytes Raw Blame History 1 note SPDX-License-Identifier: MIT 2 note Allen's look, part 1: the drawing kit. Handwritten Omega port of native/kernel/ui/paint.h and 3 note paint.c (aienux `4b24df65`): integer sine, arctangent, exp(-x), log2, hash noise, light-weighted 4 note colour blending through the sky's transfer tables, and the glow, thread, rounded-rectangle and 5 note letter shapes. Every function gives the same integers as the C kit; tests/look-paint.om compares 6 note them value for value against the C harness. Needs font-data.om and font.om before it (afsqrt, 7 note afglyph) and pkinit once before any other call. 8 note Shared memory (declared here, used by every look-* module): 9 note Lg: 0 screen width, 1 height, 2 k (1/256 px per design px of a 1920x1080 design), 3 sky centre x, 10 note 4 sky centre y, 5..8 the clip rectangle x,y,w,h every shape is held inside (pkclip sets it), 11 note 9 the rounded rectangle's radius for pksdrrect, 10..15 PAINT scratch (unused so far). 12 note Nfrm: the frame being drawn, one packed RGB word (R<<16|G<<8|B) per pixel, rows Lg[0] apart. 13 note Nsky: the sky as it was made at startup, the same layout. 14 note Slin: ck_sky_lin, sRGB byte -> linear light Q15. Ssrgb: ck_sky_srgb16, light>>3 -> sRGB x16. 15 note Both are filled by pkinit from Plin/Psrgb, the exact values of sky_data.c. 16 note Pa: the argument block for calls with more than six values. pkthread reads Pa[0] = width in 17 note 16ths of a pixel, Pa[1] = a0, Pa[2] = a1 (its sixth value a01 is ignored; pass 0). pkletter's 18 note face is the font's own state (afinit before use). Ps is PAINT's private scratch. 19 note Signatures (same integers as the C): pksin/pkcos a (turns/65536) -> Q14; pkatan2 y x -> 0..65535; 20 note pkexpneg x -> exp(-x/256)*65536; pklog2q16 v -> log2(v)*65536; pkisqrt v; pkhash x y seed; 21 note pknoise x256 y256 seed; pkfbm x256 y256 seed octaves; pklenc light; pkscale c f; pkadd d c a; 22 note pkmix d c a; pksmooth t; pkeaseout t; pkprog now from upto; pkclip x y w h; pkglow cx cy r color a 23 note (16ths); pkthread x0 y0 x1 y1 color a01 (16ths, Pa as above); pksdrrect x y rx ry rw rh (Lg[9]); 24 note pkcover d16; pkletter pen y c color a plus -> pen after (pen in 1/256 px, plus true = additive). 25 const LOOKPX ulong `8294400` 26 global Lg long 16 27 global Nfrm uint LOOKPX 28 global Nsky uint LOOKPX 29 global Slin ushort 256 30 global Ssrgb ushort 4096 31 global Pa long 8 32 global Psin long 4097 33 global Pexp ulong 4096 34 global Plog ulong 257 35 global Patan ulong 14 36 note 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 37 note len grad radius steep yc, 27 a; 20..26 letter gx gy color a plus x0 x1; 28..31 pkfit x0 y0 x1 y1 38 global Ps long 32 39 global Pgc ulong 3 40 global Pgt ulong 514 41 text 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 " 42 text 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 " 43 fn pkmin a long b long to long 44 if lt a b 45 ret a 46 end 47 ret b 48 end 49 fn pkmax a long b long to long 50 if gt a b 51 ret a 52 end 53 ret b 54 end 55 fn pkabs a long to long 56 if lt a 0 57 ret neg a 58 end 59 ret a 60 end 61 fn pkclamp v long lo long hi long to long 62 if lt v lo 63 ret lo 64 end 65 if gt v hi 66 ret hi 67 end 68 ret v 69 end 70 fn pkinitsin to void 71 note sine: a rotation by a 4096th of a turn, applied over and over (Q30) 72 c = long `1073741824` 73 s = long 0 74 for k ulong 1025 75 v = shr add s 32768 16 76 if eq k 1024 77 v = 16384 78 end 79 put Psin k v 80 put Psin sub 2048 k v 81 put Psin and add 2048 k 4095 neg v 82 put Psin and sub 4096 k 4095 neg v 83 nc = shr sub mul c `1073740561` mul s `1647099` 30 84 ns = shr add mul s `1073740561` mul c `1647099` 30 85 c = nc 86 s = ns 87 end 88 put Psin 4096 get Psin 0 89 end 90 fn pkinitexp to void 91 note exp(-k/256): one factor of exp(-1/256) (Q30) per step 92 e = ulong `1073741824` 93 for k ulong 4096 94 put Pexp k shr add e 8192 14 95 e = shr mul e `1069555701` 30 96 end 97 end 98 fn pkinitlog to void 99 note log2(1 + k/256): square the value 16 times, taking a bit each time it passes 2 100 for k ulong 257 101 if eq k 256 102 put Plog k 65536 103 else 104 y = shl add ulong 256 k 8 105 r = ulong 0 106 for i ulong 16 107 b = sub ulong 15 i 108 y = shr mul y y 16 109 if ge y 131072 110 y = shr y 1 111 r = or r shl ulong 1 b 112 end 113 end 114 put Plog k r 115 end 116 end 117 end 118 fn pkinitatan to void 119 put Patan 0 8192 120 put Patan 1 4836 121 put Patan 2 2555 122 put Patan 3 1297 123 put Patan 4 651 124 put Patan 5 326 125 put Patan 6 163 126 put Patan 7 81 127 put Patan 8 41 128 put Patan 9 20 129 put Patan 10 10 130 put Patan 11 5 131 put Patan 12 3 132 put Patan 13 1 133 end 134 fn pkinitlin to void 135 v = ulong 0 136 slot = ulong 0 137 for i ulong len Plin 138 c = get Plin i 139 if eq c 32 140 put Slin slot ushort v 141 slot = add slot 1 142 v = 0 143 else 144 v = add mul v 10 sub ulong c 48 145 end 146 end 147 end 148 fn pkinitsrgb to void 149 v = ulong 0 150 slot = ulong 0 151 for i ulong len Psrgb 152 c = get Psrgb i 153 if eq c 32 154 put Ssrgb slot ushort v 155 slot = add slot 1 156 v = 0 157 else 158 v = add mul v 10 sub ulong c 48 159 end 160 end 161 end 162 fn pkinit to void 163 for i ulong 3 164 put Pgc i 0 165 end 166 for i ulong 514 167 put Pgt i 0 168 end 169 pkinitsin 170 pkinitexp 171 pkinitlog 172 pkinitatan 173 pkinitlin 174 pkinitsrgb 175 end 176 fn pksin a ulong to long 177 a = and a 65535 178 i = shr a 4 179 f = long and a 15 180 s0 = get Psin i 181 ret add s0 shr mul sub get Psin add i 1 s0 f 4 182 end 183 fn pkcos a ulong to long 184 ret pksin add a 16384 185 end 186 fn pkatan2 y long x long to ulong 187 if and eq x 0 eq y 0 188 ret 0 189 end 190 xx = x 191 yy = y 192 ang = ulong 0 193 if lt xx 0 194 xx = neg xx 195 yy = neg yy 196 ang = 32768 197 end 198 m = pkmax xx pkabs yy 199 while lt m `1048576` 200 xx = mul xx 2 201 yy = mul yy 2 202 m = mul m 2 203 end 204 while ge m `4194304` 205 xx = shr xx 1 206 yy = shr yy 1 207 m = shr m 1 208 end 209 z = long 0 210 for i ulong 14 211 st = long get Patan i 212 nx = xx 213 if gt yy 0 214 nx = add xx shr yy i 215 yy = sub yy shr xx i 216 z = add z st 217 else 218 nx = sub xx shr yy i 219 yy = add yy shr xx i 220 z = sub z st 221 end 222 xx = nx 223 end 224 ret and add ang bitcast ulong z 65535 225 end 226 fn pkexpneg x ulong to ulong 227 if lt x 4096 228 ret get Pexp x 229 end 230 ret 0 231 end 232 fn pklog2q16 v ulong to ulong 233 if eq v 0 234 ret 0 235 end 236 n = ulong 0 237 t = v 238 while ge t 2 bound 64 239 t = shr t 1 240 n = add n 1 241 end 242 m = v 243 if ge n 16 244 m = shr v sub n 16 245 else 246 m = shl v sub 16 n 247 end 248 k = and shr m 8 255 249 f = and m 255 250 lk = get Plog k 251 ret add add mul n 65536 lk shr mul sub get Plog add k 1 lk f 8 252 end 253 fn pkisqrt v ulong to ulong 254 ret afsqrt v 255 end 256 fn pkbits32 v long to ulong 257 ret and bitcast ulong v `4294967295` 258 end 259 fn pkhash x long y long seed ulong to ulong 260 m = ulong `4294967295` 261 a = and mul pkbits32 x `2376512323` m 262 b = and mul pkbits32 y `3625334849` m 263 c = and mul and seed m `3407524639` m 264 h = xor xor a b c 265 h = xor h shr h 13 266 h = and mul h `1540483477` m 267 h = xor h shr h 15 268 h = and mul h `668265261` m 269 h = xor h shr h 16 270 ret h 271 end 272 fn pksmooth t long to ulong 273 t = pkclamp t 0 256 274 ret ulong shr mul mul t t sub 768 mul 2 t 16 275 end 276 fn pkeaseout t long to ulong 277 u = sub 256 pkclamp t 0 256 278 ret sub ulong 256 ulong shr mul mul u u u 16 279 end 280 fn pkprog now ulong from ulong upto ulong to long 281 if le now from 282 ret 0 283 end 284 if ge now upto 285 ret 256 286 end 287 ret long div mul sub now from 256 sub upto from 288 end 289 fn pknrow ix long iy long seed ulong fx ulong to ulong 290 a = mul shr pkhash ix iy seed 16 sub 256 fx 291 ret add a mul shr pkhash add ix 1 iy seed 16 fx 292 end 293 fn pknoise x long y long seed ulong to ulong 294 fx = pksmooth long and pkbits32 x 255 295 fy = pksmooth long and pkbits32 y 255 296 ix = shr x 8 297 iy = shr y 8 298 a = pknrow ix iy seed fx 299 b = pknrow ix add iy 1 seed fx 300 ret shr add mul a sub 256 fy mul b fy 16 301 end 302 fn pkfbm x long y long seed ulong octaves ulong to ulong 303 sum = ulong 0 304 total = ulong 0 305 for o ulong octaves 306 w = shl ulong 1 sub sub octaves 1 o 307 sd = and add seed mul o 7919 `4294967295` 308 sum = add sum mul pknoise shl x o shl y o sd w 309 total = add total w 310 end 311 ret div sum total 312 end 313 fn pklenc light ulong to ulong 314 i = shr light 3 315 if ge light 32767 316 i = 4095 317 end 318 ret shr add ulong get Ssrgb i 8 4 319 end 320 fn pkscale c ulong f ulong to ulong 321 if eq f 0 322 ret 0 323 end 324 if ge f 256 325 ret c 326 end 327 out = ulong 0 328 s = ulong 16 329 for k ulong 3 330 x = and shr c s 255 331 x = pklenc shr mul ulong get Slin x f 8 332 out = or out shl x s 333 s = sub s 8 334 end 335 ret out 336 end 337 fn pkadd d ulong c ulong a ulong to ulong 338 if or eq a 0 eq c 0 339 ret d 340 end 341 if and eq d 0 eq a 256 342 ret c 343 end 344 out = ulong 0 345 s = ulong 16 346 for k ulong 3 347 x = and shr d s 255 348 y = and shr c s 255 349 v = shr mul ulong get Slin y a 8 350 if ne v 0 351 v = add ulong get Slin x v 352 i = shr v 3 353 if ge v 32767 354 i = 4095 355 end 356 x = shr add ulong get Ssrgb i 8 4 357 end 358 out = or out shl x s 359 s = sub s 8 360 end 361 ret out 362 end 363 fn pkmix d ulong c ulong a ulong to ulong 364 if or eq a 0 eq d c 365 ret d 366 end 367 if ge a 256 368 ret c 369 end 370 out = ulong 0 371 s = ulong 16 372 for k ulong 3 373 x = and shr d s 255 374 y = and shr c s 255 375 if ne x y 376 v = mul ulong get Slin x sub 256 a 377 v = shr add v mul ulong get Slin y a 8 378 i = shr v 3 379 if ge v 32767 380 i = 4095 381 end 382 x = shr add ulong get Ssrgb i 8 4 383 end 384 out = or out shl x s 385 s = sub s 8 386 end 387 ret out 388 end 389 fn pkcover d16 long to ulong 390 v = sub 8 d16 391 if le v 0 392 ret 0 393 end 394 if ge v 16 395 ret 256 396 end 397 ret ulong mul v 16 398 end 399 fn pkclip x long y long w long h long to void 400 x0 = pkmax x 0 401 y0 = pkmax y 0 402 x1 = pkmin add x w get Lg 0 403 y1 = pkmin add y h get Lg 1 404 put Lg 5 x0 405 put Lg 6 y0 406 put Lg 7 pkmax sub x1 x0 0 407 put Lg 8 pkmax sub y1 y0 0 408 end 409 fn pkfit x long y long w long h long to bool 410 note Ps[28..31] = the part of (x,y,w,h) inside the clip and the screen, as x0 y0 x1 y1; false when empty 411 x0 = pkmax x pkmax get Lg 5 0 412 y0 = pkmax y pkmax get Lg 6 0 413 x1 = add get Lg 5 get Lg 7 414 x1 = pkmin x1 get Lg 0 415 x1 = pkmin add x w x1 416 y1 = add get Lg 6 get Lg 8 417 y1 = pkmin y1 get Lg 1 418 y1 = pkmin add y h y1 419 put Ps 28 x0 420 put Ps 29 y0 421 put Ps 30 x1 422 put Ps 31 y1 423 if or le x1 x0 le y1 y0 424 ret false 425 end 426 ret true 427 end 428 fn pkmeets x long y long w long h long to bool 429 x0 = pkmax x get Lg 5 430 y0 = pkmax y get Lg 6 431 x1 = pkmin add x w add get Lg 5 get Lg 7 432 y1 = pkmin add y h add get Lg 6 get Lg 8 433 if or le x1 x0 le y1 y0 434 ret false 435 end 436 ret true 437 end 438 fn pkplot x long y long color ulong a ulong to void 439 if eq a 0 440 ret 441 end 442 lx = get Lg 5 443 ly = get Lg 6 444 if or lt x lx lt y ly 445 ret 446 end 447 if ge x add lx get Lg 7 448 ret 449 end 450 if ge y add ly get Lg 8 451 ret 452 end 453 if or lt x 0 lt y 0 454 ret 455 end 456 if ge x get Lg 0 457 ret 458 end 459 if ge y get Lg 1 460 ret 461 end 462 i = ulong add mul y get Lg 0 x 463 put Nfrm i uint pkadd ulong get Nfrm i color a 464 end 465 fn pkblend i ulong color ulong w ulong to void 466 note frame pixel i gets color's light times w/256 added (no clip test: callers fit first) 467 put Nfrm i uint pkadd ulong get Nfrm i color w 468 end 469 fn pkglowrow xa long xb long to void 470 note Ps: 0 cx, 2 r2, 3 inv, 4 color, 5 a, 10 y * width, 11 dy*dy 471 for i ulong ulong add sub xb xa 1 472 x = add xa long i 473 dx = add mul x 16 8 474 dx = sub dx get Ps 0 475 dx = add mul dx dx get Ps 11 476 if lt dx get Ps 2 477 f = shr mul dx get Ps 3 32 478 f = sub 256 f 479 f = shr mul shr mul f f 8 f 8 480 f = shr mul f get Ps 5 8 481 x = add get Ps 10 x 482 if eq get Nfrm x 0 483 f = add f long get Pgc 2 484 put Nfrm x uint get Pgt ulong f 485 else 486 dx = get Ps 4 487 pkblend ulong x ulong dx ulong f 488 end 489 end 490 end 491 end 492 note pkglowtab: the glow's colour over one black for every weight, kept for the last two 493 note colours (two alternate at the merger): most of the sky is one black, so the row's add 494 note becomes a table read; the bytes are pkadd's. Pgc: colour of table 0, of table 1, current. 495 fn pkglowtab color ulong to void 496 if eq get Pgc 0 color 497 put Pgc 2 0 498 ret 499 end 500 if eq get Pgc 1 color 501 put Pgc 2 257 502 ret 503 end 504 k = ulong 257 505 if eq get Pgc 2 257 506 k = 0 507 end 508 put Pgc 2 k 509 put Pgc div k 257 color 510 for i ulong 257 511 put Pgt add k i pkadd 0 color i 512 end 513 end 514 fn pkglowy y long to void 515 dy = add mul y 16 8 516 dy = sub dy get Ps 1 517 dy = mul dy dy 518 if lt dy get Ps 2 519 put Ps 11 dy 520 put Ps 10 mul y get Lg 0 521 dy = sub get Ps 2 dy 522 half = long pkisqrt ulong dy 523 xa = sub get Ps 0 half 524 xa = pkmax get Ps 6 shr xa 4 525 xb = add get Ps 0 half 526 xb = pkmin get Ps 7 shr xb 4 527 if le xa xb 528 pkglowrow xa xb 529 end 530 end 531 end 532 fn pkglow cx long cy long r long color ulong a ulong to void 533 if or le r 0 eq a 0 534 ret 535 end 536 x0 = shr sub cx r 4 537 y0 = shr sub cy r 4 538 if not pkfit x0 y0 add sub shr add cx r 4 x0 1 add sub shr add cy r 4 y0 1 539 ret 540 end 541 put Ps 0 cx 542 put Ps 1 cy 543 put Ps 2 mul r r 544 put Ps 3 div `1099511627776` mul r r 545 put Ps 4 long color 546 put Ps 5 long a 547 put Ps 6 get Ps 28 548 put Ps 7 sub get Ps 30 1 549 pkglowtab color 550 y0 = get Ps 29 551 for j ulong ulong sub get Ps 31 y0 552 pkglowy add y0 long j 553 end 554 end 555 fn pkthreadpx xc long yy long to void 556 note Ps: 12 color, 17 radius, 18 steep, 19 yc (16ths), 27 a 557 d = add mul yy 16 8 558 d = sub d get Ps 19 559 d = sub pkabs d get Ps 17 560 cov = pkcover d 561 cov = shr mul ulong get Ps 27 cov 8 562 color = ulong get Ps 12 563 if eq get Ps 18 1 564 pkplot yy xc color cov 565 else 566 pkplot xc yy color cov 567 end 568 end 569 fn pkthreadcol xc long to void 570 note one column (row when steep) at major coordinate xc; Ps: 8 x0, 9 y0, 13 a0, 14 a1, 15 len, 16 grad 571 along = add mul xc 16 8 572 along = sub along get Ps 8 573 yc = shr mul along get Ps 16 16 574 yc = add yc get Ps 9 575 put Ps 19 yc 576 a = sub get Ps 14 get Ps 13 577 a = div mul a along get Ps 15 578 put Ps 27 add a get Ps 13 579 ya = sub yc get Ps 17 580 ya = shr sub ya 8 4 581 yb = add yc get Ps 17 582 yb = shr add yb 8 4 583 for j ulong ulong add sub yb ya 1 584 pkthreadpx xc add ya long j 585 end 586 end 587 fn pkthreadgo to void 588 x0 = get Ps 8 589 x1 = get Ps 10 590 ln = sub x1 x0 591 if lt ln 1 592 ln = 1 593 end 594 put Ps 15 ln 595 grad = div mul sub get Ps 11 get Ps 9 65536 ln 596 put Ps 16 grad 597 note slant: the native-scaled width projected onto the minor axis (256 = flat) 598 grad = long shr pkisqrt ulong add `4294967296` mul grad grad 8 599 put Ps 17 shr mul get Pa 0 grad 9 600 first = shr add x0 7 4 601 last = shr sub x1 8 4 602 x0 = get Lg 5 603 x1 = get Lg 7 604 if eq get Ps 18 1 605 x0 = get Lg 6 606 x1 = get Lg 8 607 end 608 first = pkmax first x0 609 last = pkmin last sub add x0 x1 1 610 if gt first last 611 ret 612 end 613 for i ulong ulong add sub last first 1 614 pkthreadcol add first long i 615 end 616 end 617 fn pkthreadbox x0 long y0 long x1 long y1 long pad long to bool 618 bx = sub shr pkmin x0 x1 4 pad 619 by = sub shr pkmin y0 y1 4 pad 620 bw = add add sub shr pkmax x0 x1 4 bx pad 1 621 bh = add add sub shr pkmax y0 y1 4 by pad 1 622 ret pkmeets bx by bw bh 623 end 624 fn pkthread x0 long y0 long x1 long y1 long color ulong a01 ulong to void 625 note width, a0 and a1 ride in Pa[0..2] (Omega takes at most six values); a01 is ignored 626 w = get Pa 0 627 if le w 0 628 ret 629 end 630 if and eq get Pa 1 0 eq get Pa 2 0 631 ret 632 end 633 if not pkthreadbox x0 y0 x1 y1 add shr w 4 1 634 ret 635 end 636 put Ps 18 0 637 if gt pkabs sub y1 y0 pkabs sub x1 x0 638 put Ps 18 1 639 t = x0 640 x0 = y0 641 y0 = t 642 t = x1 643 x1 = y1 644 y1 = t 645 end 646 put Ps 13 get Pa 1 647 put Ps 14 get Pa 2 648 if gt x0 x1 649 t = x0 650 x0 = x1 651 x1 = t 652 t = y0 653 y0 = y1 654 y1 = t 655 put Ps 13 get Pa 2 656 put Ps 14 get Pa 1 657 end 658 put Ps 8 x0 659 put Ps 9 y0 660 put Ps 10 x1 661 put Ps 11 y1 662 put Ps 12 long color 663 pkthreadgo 664 end 665 fn pksdrrect x long y long rx long ry long rw long rh long to long 666 note The rounded rectangle's radius rides in Lg[9] (Omega takes at most six values). 667 rad = mul get Lg 9 16 668 x = add mul x 16 8 669 x = sub x mul rx 16 670 x = sub x mul rw 8 671 rw = sub mul rw 8 rad 672 x = sub pkabs x rw 673 y = add mul y 16 8 674 y = sub y mul ry 16 675 y = sub y mul rh 8 676 rh = sub mul rh 8 rad 677 y = sub pkabs y rh 678 out = pkmax x y 679 if and gt x 0 gt y 0 680 x = add mul x x mul y y 681 out = long pkisqrt ulong x 682 end 683 ret sub out rad 684 end 685 fn pkadvance c uchar to ulong 686 note the advance of c, 1/256 px: the number after 'w' at the start of its glyph, times the scale 687 if not afpick c 688 ret 0 689 end 690 put Afpos 0 add get Afpos 0 1 691 ret mul ulong afnum get Af 0 692 end 693 fn pkletterpx xx long to void 694 note Ps: 10 alpha row offset (row*w - gx), 11 y * width, 22 color, 23 a, 24 plus 695 cov = ulong get Alpha ulong add xx get Ps 10 696 if ne cov 0 697 cov = add cov shr cov 7 698 cov = shr mul cov ulong get Ps 23 8 699 i = ulong add xx get Ps 11 700 color = ulong get Ps 22 701 if eq get Ps 24 1 702 put Nfrm i uint pkadd ulong get Nfrm i color cov 703 else 704 put Nfrm i uint pkmix ulong get Nfrm i color cov 705 end 706 end 707 end 708 fn pkletterrow yy long to void 709 m = sub yy get Ps 21 710 m = mul m long get Af 3 711 put Ps 10 sub m get Ps 20 712 put Ps 11 mul yy get Lg 0 713 x0 = get Ps 25 714 n = ulong sub get Ps 26 x0 715 for i ulong n 716 pkletterpx add x0 long i 717 end 718 end 719 fn pkletterrows to void 720 note every row of the fitted glyph box Ps[28..31] 721 put Ps 25 get Ps 28 722 put Ps 26 get Ps 30 723 y0 = get Ps 29 724 n = ulong sub get Ps 31 y0 725 for j ulong n 726 pkletterrow add y0 long j 727 end 728 end 729 fn pkletter pen ulong y long c uchar color ulong a ulong plus bool to ulong 730 note ck_letter: the glyph c of the face afinit made, its pen at pen (1/256 px) on baseline y, mixed in 731 note with weight a (added light when plus); returns the pen after it 732 if eq a 0 733 ret add pen pkadvance c 734 end 735 if not afglyph c 736 ret add pen pkadvance c 737 end 738 if eq get Af 2 0 739 ret add pen get Af 5 740 end 741 gx = add long div add pen 128 256 get Ab 0 742 gy = add y get Ab 1 743 if pkfit gx gy long get Af 3 long get Af 4 744 put Ps 20 gx 745 put Ps 21 gy 746 put Ps 22 long color 747 put Ps 23 long a 748 put Ps 24 0 749 if plus 750 put Ps 24 1 751 end 752 pkletterrows 753 end 754 ret add pen get Af 5 755 end