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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
/* Smalltalk from Squeak4.5 with VMMaker 4.13.6 translated as JS source on 3 November 2014 1:52:20 pm */
/* Automatically generated by
	JSSmartSyntaxPluginCodeGenerator VMMakerJS-bf.15 uuid: fd4e10f2-3773-4e80-8bb5-c4b471a014e5
   from
	BitBltSimulation VMMaker-bf.353 uuid: 8ae25e7e-8d2c-451e-8277-598b30e9c002
 */

(function BitBltPlugin() {
"use strict";

var VM_PROXY_MAJOR = 1;
var VM_PROXY_MINOR = 11;

/*** Functions ***/
function CLASSOF(obj) { return typeof obj === "number" ? interpreterProxy.classSmallInteger() : obj.sqClass }
function SIZEOF(obj) { return obj.pointers ? obj.pointers.length : obj.words ? obj.words.length : obj.bytes ? obj.bytes.length : 0 }
function BYTESIZEOF(obj) { return obj.bytes ? obj.bytes.length : obj.words ? obj.words.length * 4 : 0 }
function DIV(a, b) { return Math.floor(a / b) | 0; }   // integer division
function MOD(a, b) { return a - DIV(a, b) * b | 0; }   // signed modulus
function SHL(a, b) { return b > 31 ? 0 : a << b; }     // fix JS shift
function SHR(a, b) { return b > 31 ? 0 : a >>> b; }    // fix JS shift
function SHIFT(a, b) { return b < 0 ? (b < -31 ? 0 : a >>> (0-b) ) : (b > 31 ? 0 : a << b); }

/*** Constants ***/
var AllOnes = 4294967295;
var AlphaIndex = 3;
var BBClipHeightIndex = 13;
var BBClipWidthIndex = 12;
var BBClipXIndex = 10;
var BBClipYIndex = 11;
var BBColorMapIndex = 14;
var BBDestFormIndex = 0;
var BBDestXIndex = 4;
var BBDestYIndex = 5;
var BBHalftoneFormIndex = 2;
var BBHeightIndex = 7;
var BBRuleIndex = 3;
var BBSourceFormIndex = 1;
var BBSourceXIndex = 8;
var BBSourceYIndex = 9;
var BBWarpBase = 15;
var BBWidthIndex = 6;
var BinaryPoint = 14;
var BlueIndex = 2;
var ColorMapFixedPart = 2;
var ColorMapIndexedPart = 4;
var ColorMapNewStyle = 8;
var ColorMapPresent = 1;
var FixedPt1 = 16384;
var FormBitsIndex = 0;
var FormDepthIndex = 3;
var FormHeightIndex = 2;
var FormWidthIndex = 1;
var GreenIndex = 1;
var OpTableSize = 43;
var RedIndex = 0;

/*** Variables ***/
var affectedB = 0;
var affectedL = 0;
var affectedR = 0;
var affectedT = 0;
var bbH = 0;
var bbW = 0;
var bitBltOop = 0;
var bitCount = 0;
var clipHeight = 0;
var clipWidth = 0;
var clipX = 0;
var clipY = 0;
var cmBitsPerColor = 0;
var cmFlags = 0;
var cmLookupTable = null;
var cmMask = 0;
var cmMaskTable = null;
var cmShiftTable = null;
var combinationRule = 0;
var componentAlphaModeAlpha = 0;
var componentAlphaModeColor = 0;
var destBits = 0;
var destDelta = 0;
var destDepth = 0;
var destForm = 0;
var destHeight = 0;
var destIndex = 0;
var destMSB = 0;
var destMask = 0;
var destPPW = 0;
var destPitch = 0;
var destWidth = 0;
var destX = 0;
var destY = 0;
var dither8Lookup = new Array(4096);
var ditherMatrix4x4 = [
0,	8,	2,	10,
12,	4,	14,	6,
3,	11,	1,	9,
15,	7,	13,	5
];
var ditherThresholds16 = [ 0, 2, 4, 6, 8, 12, 14, 16 ];
var ditherValues16 = [
0, 0, 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
];
var dstBitShift = 0;
var dx = 0;
var dy = 0;
var gammaLookupTable = null;
var hDir = 0;
var halftoneBase = 0;
var halftoneForm = 0;
var halftoneHeight = 0;
var hasSurfaceLock = 0;
var height = 0;
var interpreterProxy = null;
var isWarping = 0;
var lockSurfaceFn = null;
var mask1 = 0;
var mask2 = 0;
var maskTable = [
0, 1, 3, 0, 15, 31, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 65535,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1
];
var moduleName = "BitBltPlugin 3 November 2014 (e)";
var nWords = 0;
var noHalftone = 0;
var noSource = 0;
var opTable = new Array(43);
var preload = 0;
var querySurfaceFn = null;
var skew = 0;
var sourceAlpha = 0;
var sourceBits = 0;
var sourceDelta = 0;
var sourceDepth = 0;
var sourceForm = 0;
var sourceHeight = 0;
var sourceIndex = 0;
var sourceMSB = 0;
var sourcePPW = 0;
var sourcePitch = 0;
var sourceWidth = 0;
var sourceX = 0;
var sourceY = 0;
var srcBitShift = 0;
var sx = 0;
var sy = 0;
var ungammaLookupTable = null;
var unlockSurfaceFn = null;
var vDir = 0;
var warpAlignMask = 0;
var warpAlignShift = 0;
var warpBitShiftTable = new Array(32);
var warpSrcMask = 0;
var warpSrcShift = 0;
var width = 0;



/*	Subract the pixels in the source and destination, color by color,
	and return the sum of the absolute value of all the differences.
	For non-rgb, XOR the two and return the number of differing pixels.
	Note that the region is not clipped to bit boundaries, but only to the
	nearest (enclosing) word.  This is because copyLoop does not do
	pre-merge masking.  For accurate results, you must subtract the
	values obtained from the left and right fringes. */

function OLDrgbDiffwith(sourceWord, destinationWord) {
	var diff;
	var pixMask;

	if (destDepth < 16) {

		/* Just xor and count differing bits if not RGB */

		diff = sourceWord ^ destinationWord;
		pixMask = maskTable[destDepth];
		while (!(diff === 0)) {
			if ((diff & pixMask) !== 0) {
				++bitCount;
			}
			diff = SHR(diff, destDepth);
		}
		return destinationWord;
	}
	if (destDepth === 16) {
		diff = partitionedSubfromnBitsnPartitions(sourceWord, destinationWord, 5, 3);
		bitCount = ((bitCount + (diff & 31)) + ((diff >>> 5) & 31)) + ((diff >>> 10) & 31);
		diff = partitionedSubfromnBitsnPartitions(sourceWord >>> 16, destinationWord >>> 16, 5, 3);
		bitCount = ((bitCount + (diff & 31)) + ((diff >>> 5) & 31)) + ((diff >>> 10) & 31);
	} else {
		diff = partitionedSubfromnBitsnPartitions(sourceWord, destinationWord, 8, 3);
		bitCount = ((bitCount + (diff & 255)) + ((diff >>> 8) & 255)) + ((diff >>> 16) & 255);
	}
	return destinationWord;
}


/*	Tally pixels into the color map.  Note that the source should be 
	specified = destination, in order for the proper color map checks 
	to be performed at setup.
	Note that the region is not clipped to bit boundaries, but only to the
	nearest (enclosing) word.  This is because copyLoop does not do
	pre-merge masking.  For accurate results, you must subtract the
	values obtained from the left and right fringes. */

function OLDtallyIntoMapwith(sourceWord, destinationWord) {
	var pixMask;
	var mapIndex;
	var i;
	var shiftWord;

	if ((cmFlags & (ColorMapPresent | ColorMapIndexedPart)) !== (ColorMapPresent | ColorMapIndexedPart)) {
		return destinationWord;
	}
	if (destDepth < 16) {

		/* loop through all packed pixels. */

		pixMask = maskTable[destDepth] & cmMask;
		shiftWord = destinationWord;
		for (i = 1; i <= destPPW; i++) {
			mapIndex = shiftWord & pixMask;
			tallyMapAtput(mapIndex, tallyMapAt(mapIndex) + 1);
			shiftWord = SHR(shiftWord, destDepth);
		}
		return destinationWord;
	}
	if (destDepth === 16) {

		/* Two pixels  Tally the right half... */

		mapIndex = rgbMapfromto(destinationWord & 65535, 5, cmBitsPerColor);
		tallyMapAtput(mapIndex, tallyMapAt(mapIndex) + 1);
		mapIndex = rgbMapfromto(destinationWord >>> 16, 5, cmBitsPerColor);
		tallyMapAtput(mapIndex, tallyMapAt(mapIndex) + 1);
	} else {

		/* Just one pixel. */

		mapIndex = rgbMapfromto(destinationWord, 8, cmBitsPerColor);
		tallyMapAtput(mapIndex, tallyMapAt(mapIndex) + 1);
	}
	return destinationWord;
}

function addWordwith(sourceWord, destinationWord) {
	return sourceWord + destinationWord;
}


/*	Blend sourceWord with destinationWord, assuming both are 32-bit pixels.
	The source is assumed to have 255*alpha in the high 8 bits of each pixel,
	while the high 8 bits of the destinationWord will be ignored.
	The blend produced is alpha*source + (1-alpha)*dest, with
	the computation being performed independently on each color
	component.  The high byte of the result will be 0. */

function alphaBlendwith(sourceWord, destinationWord) {
	var unAlpha;
	var blendRB;
	var blendAG;
	var result;
	var alpha;


	/* High 8 bits of source pixel */

	alpha = sourceWord >>> 24;
	if (alpha === 0) {
		return destinationWord;
	}
	if (alpha === 255) {
		return sourceWord;
	}
	unAlpha = 255 - alpha;

	/* blend red and blue */

	blendRB = (((sourceWord & 16711935) * alpha) + ((destinationWord & 16711935) * unAlpha)) + 16711935;

	/* blend alpha and green */

	blendAG = (((((sourceWord >>> 8) | 16711680) & 16711935) * alpha) + (((destinationWord >>> 8) & 16711935) * unAlpha)) + 16711935;

	/* divide by 255 */

	blendRB = ((blendRB + (((blendRB - 65537) >>> 8) & 16711935)) >>> 8) & 16711935;
	blendAG = ((blendAG + (((blendAG - 65537) >>> 8) & 16711935)) >>> 8) & 16711935;
	result = blendRB | (blendAG << 8);
	return result;
}

function alphaBlendConstwith(sourceWord, destinationWord) {
	return alphaBlendConstwithpaintMode(sourceWord, destinationWord, false);
}


/*	Blend sourceWord with destinationWord using a constant alpha.
	Alpha is encoded as 0 meaning 0.0, and 255 meaning 1.0.
	The blend produced is alpha*source + (1.0-alpha)*dest, with the
	computation being performed independently on each color component.
	This function could eventually blend into any depth destination,
	using the same color averaging and mapping as warpBlt.
	paintMode = true means do nothing if the source pixel value is zero. */
/*	This first implementation works with dest depths of 16 and 32 bits only.
	Normal color mapping will allow sources of lower depths in this case,
	and results can be mapped directly by truncation, so no extra color maps are needed.
	To allow storing into any depth will require subsequent addition of two other
	colormaps, as is the case with WarpBlt. */

function alphaBlendConstwithpaintMode(sourceWord, destinationWord, paintMode) {
	var rgbMask;
	var pixMask;
	var pixBlend;
	var j;
	var sourceShifted;
	var result;
	var shift;
	var sourcePixVal;
	var i;
	var unAlpha;
	var destPixVal;
	var blendRB;
	var blendAG;
	var bitsPerColor;
	var blend;
	var destShifted;
	var maskShifted;

	if (destDepth < 16) {
		return destinationWord;
	}
	unAlpha = 255 - sourceAlpha;
	result = destinationWord;
	if (destPPW === 1) {

		/* 32bpp blends include alpha */

		if (!(paintMode && (sourceWord === 0))) {

			/* painting a transparent pixel */


			/* blendRB red and blue */

			blendRB = (((sourceWord & 16711935) * sourceAlpha) + ((destinationWord & 16711935) * unAlpha)) + 16711935;

			/* blendRB alpha and green */

			blendAG = ((((sourceWord >>> 8) & 16711935) * sourceAlpha) + (((destinationWord >>> 8) & 16711935) * unAlpha)) + 16711935;

			/* divide by 255 */

			blendRB = ((blendRB + (((blendRB - 65537) >>> 8) & 16711935)) >>> 8) & 16711935;
			blendAG = ((blendAG + (((blendAG - 65537) >>> 8) & 16711935)) >>> 8) & 16711935;
			result = blendRB | (blendAG << 8);
		}
	} else {
		pixMask = maskTable[destDepth];
		bitsPerColor = 5;
		rgbMask = 31;
		maskShifted = destMask;
		destShifted = destinationWord;
		sourceShifted = sourceWord;
		for (j = 1; j <= destPPW; j++) {
			sourcePixVal = sourceShifted & pixMask;
			if (!(((maskShifted & pixMask) === 0) || (paintMode && (sourcePixVal === 0)))) {
				destPixVal = destShifted & pixMask;
				pixBlend = 0;
				for (i = 1; i <= 3; i++) {
					shift = (i - 1) * bitsPerColor;
					blend = (DIV((((((SHR(sourcePixVal, shift)) & rgbMask) * sourceAlpha) + (((SHR(destPixVal, shift)) & rgbMask) * unAlpha)) + 254), 255)) & rgbMask;
					pixBlend = pixBlend | (SHL(blend, shift));
				}
				result = (result & ~(SHL(pixMask, ((j - 1) * 16)))) | (SHL(pixBlend, ((j - 1) * 16)));
			}
			maskShifted = SHR(maskShifted, destDepth);
			sourceShifted = SHR(sourceShifted, destDepth);
			destShifted = SHR(destShifted, destDepth);
		}
	}
	return result;
}


/*	Blend sourceWord with destinationWord using the alpha value from sourceWord.
	Alpha is encoded as 0 meaning 0.0, and 255 meaning 1.0.
	In contrast to alphaBlend:with: the color produced is

		srcColor + (1-srcAlpha) * dstColor

	e.g., it is assumed that the source color is already scaled. */

function alphaBlendScaledwith(sourceWord, destinationWord) {
	var unAlpha;
	var rb;
	var ag;


	/* Do NOT inline this into optimized loops */


	/* High 8 bits of source pixel is source opacity (ARGB format) */

	unAlpha = 255 - (sourceWord >>> 24);

	/* blend red and blue components */

	rb = ((((destinationWord & 16711935) * unAlpha) >>> 8) & 16711935) + (sourceWord & 16711935);

	/* blend alpha and green components */

	ag = (((((destinationWord >>> 8) & 16711935) * unAlpha) >>> 8) & 16711935) + ((sourceWord >>> 8) & 16711935);

	/* saturate red and blue components if there is a carry */

	rb = (rb & 16711935) | (((rb & 16777472) * 255) >>> 8);

	/* saturate alpha and green components if there is a carry */

	ag = ((ag & 16711935) << 8) | ((ag & 16777472) * 255);
	return ag | rb;
}

function alphaPaintConstwith(sourceWord, destinationWord) {
	if (sourceWord === 0) {
		return destinationWord;
	}
	return alphaBlendConstwithpaintMode(sourceWord, destinationWord, true);
}


/*	This version assumes 
		combinationRule = 34
		sourcePixSize = 32
		destPixSize = 16
		sourceForm ~= destForm.
	 */

function alphaSourceBlendBits16() {
	var ditherBase;
	var ditherThreshold;
	var srcShift;
	var sourceWord;
	var srcIndex;
	var deltaX;
	var dstIndex;
	var srcAlpha;
	var dstMask;
	var deltaY;
	var srcY;
	var destWord;
	var dstY;
	var ditherIndex;


	/* This particular method should be optimized in itself */


	/* So we can pre-decrement */

	deltaY = bbH + 1;
	srcY = sy;
	dstY = dy;
	srcShift = (dx & 1) * 16;
	if (destMSB) {
		srcShift = 16 - srcShift;
	}

	/* This is the outer loop */

	mask1 = SHL(65535, (16 - srcShift));
	while (((--deltaY)) !== 0) {
		srcIndex = ((srcY * sourcePitch)) + (sx * 4);
		dstIndex = ((dstY * destPitch)) + ((dx >> 1) * 4);
		ditherBase = (dstY & 3) * 4;

		/* For pre-increment */

		ditherIndex = (sx & 3) - 1;

		/* So we can pre-decrement */

		deltaX = bbW + 1;
		dstMask = mask1;
		if (dstMask === 65535) {
			srcShift = 16;
		} else {
			srcShift = 0;
		}
		while (((--deltaX)) !== 0) {
			ditherThreshold = ditherMatrix4x4[ditherBase + ((ditherIndex = (ditherIndex + 1) & 3))];
			sourceWord = sourceBits[srcIndex >>> 2];
			srcAlpha = sourceWord >>> 24;
			if (srcAlpha === 255) {

				/* Dither from 32 to 16 bit */

				sourceWord = dither32To16threshold(sourceWord, ditherThreshold);
				if (sourceWord === 0) {
					sourceWord = SHL(1, srcShift);
				} else {
					sourceWord = SHL(sourceWord, srcShift);
				}
				dstLongAtputmask(dstIndex, sourceWord, dstMask);
			} else {

				/* srcAlpha ~= 255 */

				if (srcAlpha !== 0) {

					/* 0 < srcAlpha < 255 */
					/* If we have to mix colors then just copy a single word */

					destWord = destBits[dstIndex >>> 2];
					destWord = destWord & ~dstMask;

					/* Expand from 16 to 32 bit by adding zero bits */

					destWord = SHR(destWord, srcShift);

					/* Mix colors */

					destWord = (((destWord & 31744) << 9) | ((destWord & 992) << 6)) | (((destWord & 31) << 3) | 4278190080);

					/* And dither */

					sourceWord = alphaBlendScaledwith(sourceWord, destWord);
					sourceWord = dither32To16threshold(sourceWord, ditherThreshold);
					if (sourceWord === 0) {
						sourceWord = SHL(1, srcShift);
					} else {
						sourceWord = SHL(sourceWord, srcShift);
					}
					dstLongAtputmask(dstIndex, sourceWord, dstMask);
				}
			}
			srcIndex += 4;
			if (destMSB) {
				if (srcShift === 0) {
					dstIndex += 4;
				}
			} else {
				if (srcShift !== 0) {
					dstIndex += 4;
				}
			}

			/* Toggle between 0 and 16 */

			srcShift = srcShift ^ 16;
			dstMask = ~dstMask;
		}
		++srcY;
		++dstY;
	}
}


/*	This version assumes 
		combinationRule = 34
		sourcePixSize = destPixSize = 32
		sourceForm ~= destForm.
	Note: The inner loop has been optimized for dealing
		with the special cases of srcAlpha = 0.0 and srcAlpha = 1.0 
	 */

function alphaSourceBlendBits32() {
	var sourceWord;
	var srcIndex;
	var deltaX;
	var dstIndex;
	var srcAlpha;
	var deltaY;
	var srcY;
	var destWord;
	var dstY;


	/* This particular method should be optimized in itself */
	/* Give the compile a couple of hints */
	/* The following should be declared as pointers so the compiler will
	notice that they're used for accessing memory locations 
	(good to know on an Intel architecture) but then the increments
	would be different between ST code and C code so must hope the
	compiler notices what happens (MS Visual C does) */


	/* So we can pre-decrement */

	deltaY = bbH + 1;
	srcY = sy;

	/* This is the outer loop */

	dstY = dy;
	while (((--deltaY)) !== 0) {
		srcIndex = ((srcY * sourcePitch)) + (sx * 4);
		dstIndex = ((dstY * destPitch)) + (dx * 4);

		/* So we can pre-decrement */
		/* This is the inner loop */

		deltaX = bbW + 1;
		while (((--deltaX)) !== 0) {
			sourceWord = sourceBits[srcIndex >>> 2];
			srcAlpha = sourceWord >>> 24;
			if (srcAlpha === 255) {
				destBits[dstIndex >>> 2] = sourceWord;
				srcIndex += 4;

				/* Now copy as many words as possible with alpha = 255 */

				dstIndex += 4;
				while ((((--deltaX)) !== 0) && ((((sourceWord = sourceBits[srcIndex >>> 2])) >>> 24) === 255)) {
					destBits[dstIndex >>> 2] = sourceWord;
					srcIndex += 4;
					dstIndex += 4;
				}
				++deltaX;
			} else {

				/* srcAlpha ~= 255 */

				if (srcAlpha === 0) {
					srcIndex += 4;

					/* Now skip as many words as possible, */

					dstIndex += 4;
					while ((((--deltaX)) !== 0) && ((((sourceWord = sourceBits[srcIndex >>> 2])) >>> 24) === 0)) {
						srcIndex += 4;
						dstIndex += 4;
					}
					++deltaX;
				} else {

					/* 0 < srcAlpha < 255 */
					/* If we have to mix colors then just copy a single word */

					destWord = destBits[dstIndex >>> 2];
					destWord = alphaBlendScaledwith(sourceWord, destWord);
					destBits[dstIndex >>> 2] = destWord;
					srcIndex += 4;
					dstIndex += 4;
				}
			}
		}
		++srcY;
		++dstY;
	}
}


/*	This version assumes 
		combinationRule = 34
		sourcePixSize = 32
		destPixSize = 8
		sourceForm ~= destForm.
	Note: This is not real blending since we don't have the source colors available.
	 */

function alphaSourceBlendBits8() {
	var srcShift;
	var sourceWord;
	var srcIndex;
	var deltaX;
	var mappingTable;
	var dstIndex;
	var adjust;
	var mapperFlags;
	var srcAlpha;
	var dstMask;
	var deltaY;
	var srcY;
	var destWord;
	var dstY;

	mappingTable = default8To32Table();
	mapperFlags = cmFlags & ~ColorMapNewStyle;

	/* So we can pre-decrement */

	deltaY = bbH + 1;
	srcY = sy;
	dstY = dy;
	mask1 = (dx & 3) * 8;
	if (destMSB) {
		mask1 = 24 - mask1;
	}
	mask2 = AllOnes ^ (SHL(255, mask1));
	if ((dx & 1) === 0) {
		adjust = 0;
	} else {
		adjust = 522133279;
	}
	if ((dy & 1) === 0) {
		adjust = adjust ^ 522133279;
	}
	while (((--deltaY)) !== 0) {
		adjust = adjust ^ 522133279;
		srcIndex = ((srcY * sourcePitch)) + (sx * 4);
		dstIndex = ((dstY * destPitch)) + ((dx >> 2) * 4);

		/* So we can pre-decrement */

		deltaX = bbW + 1;
		srcShift = mask1;

		/* This is the inner loop */

		dstMask = mask2;
		while (((--deltaX)) !== 0) {
			sourceWord = (sourceBits[srcIndex >>> 2] & ~adjust) + adjust;
			srcAlpha = sourceWord >>> 24;
			if (srcAlpha > 31) {

				/* Everything below 31 is transparent */

				if (srcAlpha < 224) {

					/* Everything above 224 is opaque */

					destWord = destBits[dstIndex >>> 2];
					destWord = destWord & ~dstMask;
					destWord = SHR(destWord, srcShift);
					destWord = mappingTable[destWord];
					sourceWord = alphaBlendScaledwith(sourceWord, destWord);
				}
				sourceWord = mapPixelflags(sourceWord, mapperFlags);

				/* Store back */

				sourceWord = SHL(sourceWord, srcShift);
				dstLongAtputmask(dstIndex, sourceWord, dstMask);
			}
			srcIndex += 4;
			if (destMSB) {
				if (srcShift === 0) {
					dstIndex += 4;
					srcShift = 24;
					dstMask = 16777215;
				} else {
					srcShift -= 8;
					dstMask = (dstMask >>> 8) | 4278190080;
				}
			} else {
				if (srcShift === 24) {
					dstIndex += 4;
					srcShift = 0;
					dstMask = 4294967040;
				} else {
					srcShift += 8;
					dstMask = (dstMask << 8) | 255;
				}
			}
			adjust = adjust ^ 522133279;
		}
		++srcY;
		++dstY;
	}
}

function bitAndwith(sourceWord, destinationWord) {
	return sourceWord & destinationWord;
}

function bitAndInvertwith(sourceWord, destinationWord) {
	return sourceWord & ~destinationWord;
}

function bitInvertAndwith(sourceWord, destinationWord) {
	return ~sourceWord & destinationWord;
}

function bitInvertAndInvertwith(sourceWord, destinationWord) {
	return ~sourceWord & ~destinationWord;
}

function bitInvertDestinationwith(sourceWord, destinationWord) {
	return ~destinationWord;
}

function bitInvertOrwith(sourceWord, destinationWord) {
	return ~sourceWord | destinationWord;
}

function bitInvertOrInvertwith(sourceWord, destinationWord) {
	return ~sourceWord | ~destinationWord;
}

function bitInvertSourcewith(sourceWord, destinationWord) {
	return ~sourceWord;
}

function bitInvertXorwith(sourceWord, destinationWord) {
	return ~sourceWord ^ destinationWord;
}

function bitOrwith(sourceWord, destinationWord) {
	return sourceWord | destinationWord;
}

function bitOrInvertwith(sourceWord, destinationWord) {
	return sourceWord | ~destinationWord;
}

function bitXorwith(sourceWord, destinationWord) {
	return sourceWord ^ destinationWord;
}


/*	check for possible overlap of source and destination */
/*	ar 10/19/1999: This method requires surfaces to be locked. */

function checkSourceOverlap() {
	var t;

	if ((sourceForm === destForm) && (dy >= sy)) {
		if (dy > sy) {

			/* have to start at bottom */

			vDir = -1;
			sy = (sy + bbH) - 1;
			dy = (dy + bbH) - 1;
		} else {
			if ((dy === sy) && (dx > sx)) {

				/* y's are equal, but x's are backward */

				hDir = -1;

				/* start at right */

				sx = (sx + bbW) - 1;

				/* and fix up masks */

				dx = (dx + bbW) - 1;
				if (nWords > 1) {
					t = mask1;
					mask1 = mask2;
					mask2 = t;
				}
			}
		}
		destIndex = ((dy * destPitch)) + ((DIV(dx, destPPW)) * 4);
		destDelta = (destPitch * vDir) - (4 * (nWords * hDir));
	}
}

function clearWordwith(source, destination) {
	return 0;
}


/*	clip and adjust source origin and extent appropriately */
/*	first in x */

function clipRange() {
	if (destX >= clipX) {
		sx = sourceX;
		dx = destX;
		bbW = width;
	} else {
		sx = sourceX + (clipX - destX);
		bbW = width - (clipX - destX);
		dx = clipX;
	}
	if ((dx + bbW) > (clipX + clipWidth)) {
		bbW -= (dx + bbW) - (clipX + clipWidth);
	}
	if (destY >= clipY) {
		sy = sourceY;
		dy = destY;
		bbH = height;
	} else {
		sy = (sourceY + clipY) - destY;
		bbH = height - (clipY - destY);
		dy = clipY;
	}
	if ((dy + bbH) > (clipY + clipHeight)) {
		bbH -= (dy + bbH) - (clipY + clipHeight);
	}
	if (noSource) {
		return null;
	}
	if (sx < 0) {
		dx -= sx;
		bbW += sx;
		sx = 0;
	}
	if ((sx + bbW) > sourceWidth) {
		bbW -= (sx + bbW) - sourceWidth;
	}
	if (sy < 0) {
		dy -= sy;
		bbH += sy;
		sy = 0;
	}
	if ((sy + bbH) > sourceHeight) {
		bbH -= (sy + bbH) - sourceHeight;
	}
}


/*	This function is exported for the Balloon engine */

function copyBits() {
	clipRange();
	if ((bbW <= 0) || (bbH <= 0)) {

		/* zero width or height; noop */

		affectedL = (affectedR = (affectedT = (affectedB = 0)));
		return null;
	}
	if (!lockSurfaces()) {
		return interpreterProxy.primitiveFail();
	}
	// skipping ifdef ENABLE_FAST_BLT
	copyBitsLockedAndClipped();

	unlockSurfaces();
}


/*	Recover from the fast path specialised code saying Help-I-cant-cope */

function copyBitsFallback(op, flags) {
	var done;

	// skipping ifdef ENABLE_FAST_BLT
}


/*	Perform the actual copyBits operation using the fast path specialised code; fail some cases by falling back to normal code.
	Assume: Surfaces have been locked and clipping was performed. */

function copyBitsFastPathSpecialised() {
	// skipping ifdef ENABLE_FAST_BLT
}


/*	Support for the balloon engine. */

function copyBitsFromtoat(startX, stopX, yValue) {
	destX = startX;
	destY = yValue;
	sourceX = startX;
	width = stopX - startX;
	copyBits();
	showDisplayBits();
}


/*	Perform the actual copyBits operation.
	Assume: Surfaces have been locked and clipping was performed. */

function copyBitsLockedAndClipped() {
	var done;

	copyBitsRule41Test();
	if (interpreterProxy.failed()) {
		return interpreterProxy.primitiveFail();
	}
	done = tryCopyingBitsQuickly();
	if (done) {
		return null;
	}
	if ((combinationRule === 30) || (combinationRule === 31)) {

		/* Check and fetch source alpha parameter for alpha blend */

		if (interpreterProxy.methodArgumentCount() === 1) {
			sourceAlpha = interpreterProxy.stackIntegerValue(0);
			if (!(!interpreterProxy.failed() && ((sourceAlpha >= 0) && (sourceAlpha <= 255)))) {
				return interpreterProxy.primitiveFail();
			}
		} else {
			return interpreterProxy.primitiveFail();
		}
	}

	/* Choose and perform the actual copy loop. */

	bitCount = 0;
	performCopyLoop();
	if ((combinationRule === 22) || (combinationRule === 32)) {

		/* zero width and height; return the count */

		affectedL = (affectedR = (affectedT = (affectedB = 0)));
	}
	if (hDir > 0) {
		affectedL = dx;
		affectedR = dx + bbW;
	} else {
		affectedL = (dx - bbW) + 1;
		affectedR = dx + 1;
	}
	if (vDir > 0) {
		affectedT = dy;
		affectedB = dy + bbH;
	} else {
		affectedT = (dy - bbH) + 1;
		affectedB = dy + 1;
	}
}


/*	Test possible use of rule 41, rgbComponentAlpha:with: Nothing to return, just set up some variables */

function copyBitsRule41Test() {
	var ungammaLookupTableOop;
	var gammaLookupTableOop;

	if (combinationRule === 41) {

		/* fetch the forecolor into componentAlphaModeColor. */

		componentAlphaModeAlpha = 255;
		componentAlphaModeColor = 16777215;
		gammaLookupTable = null;
		ungammaLookupTable = null;
		if (interpreterProxy.methodArgumentCount() >= 2) {
			componentAlphaModeAlpha = interpreterProxy.stackIntegerValue(interpreterProxy.methodArgumentCount() - 2);
			if (interpreterProxy.failed()) {
				return interpreterProxy.primitiveFail();
			}
			componentAlphaModeColor = interpreterProxy.stackIntegerValue(interpreterProxy.methodArgumentCount() - 1);
			if (interpreterProxy.failed()) {
				return interpreterProxy.primitiveFail();
			}
			if (interpreterProxy.methodArgumentCount() === 4) {
				gammaLookupTableOop = interpreterProxy.stackObjectValue(1);
				if (interpreterProxy.isBytes(gammaLookupTableOop)) {
					gammaLookupTable = gammaLookupTableOop.bytes;
				}
				ungammaLookupTableOop = interpreterProxy.stackObjectValue(0);
				if (interpreterProxy.isBytes(ungammaLookupTableOop)) {
					ungammaLookupTable = ungammaLookupTableOop.bytes;
				}
			}
		} else {
			if (interpreterProxy.methodArgumentCount() === 1) {
				componentAlphaModeColor = interpreterProxy.stackIntegerValue(0);
				if (interpreterProxy.failed()) {
					return interpreterProxy.primitiveFail();
				}
			} else {
				return interpreterProxy.primitiveFail();
			}
		}
	}
}


/*	This version of the inner loop assumes noSource = false. */

function copyLoop() {
	var mergeWord;
	var skewWord;
	var skewMask;
	var halftoneWord;
	var unskew;
	var mergeFnwith;
	var hInc;
	var destWord;
	var word;
	var prevWord;
	var y;
	var i;
	var thisWord;
	var notSkewMask;

	mergeFnwith = opTable[combinationRule + 1];
	mergeFnwith;

	/* Byte delta */
	/* degenerate skew fixed for Sparc. 10/20/96 ikp */

	hInc = hDir * 4;
	if (skew === -32) {
		skew = (unskew = (skewMask = 0));
	} else {
		if (skew < 0) {
			unskew = skew + 32;
			skewMask = SHL(AllOnes, (0 - skew));
		} else {
			if (skew === 0) {
				unskew = 0;
				skewMask = AllOnes;
			} else {
				unskew = skew - 32;
				skewMask = SHR(AllOnes, skew);
			}
		}
	}
	notSkewMask = ~skewMask;
	if (noHalftone) {
		halftoneWord = AllOnes;
		halftoneHeight = 0;
	} else {
		halftoneWord = halftoneAt(0);
	}
	y = dy;
	for (i = 1; i <= bbH; i++) {

		/* here is the vertical loop */

		if (halftoneHeight > 1) {

			/* Otherwise, its always the same */

			halftoneWord = halftoneAt(y);
			y += vDir;
		}
		if (preload) {

			/* load the 64-bit shifter */

			prevWord = sourceBits[sourceIndex >>> 2];
			sourceIndex += hInc;
		} else {
			prevWord = 0;
		}
		destMask = mask1;

		/* pick up next word */

		thisWord = sourceBits[sourceIndex >>> 2];
		sourceIndex += hInc;

		/* 32-bit rotate */

		skewWord = (SHIFT((prevWord & notSkewMask), unskew)) | (SHIFT((thisWord & skewMask), skew));
		prevWord = thisWord;
		destWord = destBits[destIndex >>> 2];
		mergeWord = mergeFnwith(skewWord & halftoneWord, destWord);
		destWord = (destMask & mergeWord) | (destWord & ~destMask);
		destBits[destIndex >>> 2] = destWord;

		/* This central horizontal loop requires no store masking */

		destIndex += hInc;
		destMask = AllOnes;
		if (combinationRule === 3) {
			if ((skew === 0) && (halftoneWord === AllOnes)) {

				/* Very special inner loop for STORE mode with no skew -- just move words */

				if (hDir === -1) {

					/* Woeful patch: revert to older code for hDir = -1 */

					for (word = 2; word <= (nWords - 1); word++) {
						thisWord = sourceBits[sourceIndex >>> 2];
						sourceIndex += hInc;
						destBits[destIndex >>> 2] = thisWord;
						destIndex += hInc;
					}
				} else {
					for (word = 2; word <= (nWords - 1); word++) {

						/* Note loop starts with prevWord loaded (due to preload) */

						destBits[destIndex >>> 2] = prevWord;
						destIndex += hInc;
						prevWord = sourceBits[sourceIndex >>> 2];
						sourceIndex += hInc;
					}
				}
			} else {

				/* Special inner loop for STORE mode -- no need to call merge */

				for (word = 2; word <= (nWords - 1); word++) {
					thisWord = sourceBits[sourceIndex >>> 2];
					sourceIndex += hInc;

					/* 32-bit rotate */

					skewWord = (SHIFT((prevWord & notSkewMask), unskew)) | (SHIFT((thisWord & skewMask), skew));
					prevWord = thisWord;
					destBits[destIndex >>> 2] = skewWord & halftoneWord;
					destIndex += hInc;
				}
			}
		} else {
			for (word = 2; word <= (nWords - 1); word++) {

				/* Normal inner loop does merge: */


				/* pick up next word */

				thisWord = sourceBits[sourceIndex >>> 2];
				sourceIndex += hInc;

				/* 32-bit rotate */

				skewWord = (SHIFT((prevWord & notSkewMask), unskew)) | (SHIFT((thisWord & skewMask), skew));
				prevWord = thisWord;
				mergeWord = mergeFnwith(skewWord & halftoneWord, destBits[destIndex >>> 2]);
				destBits[destIndex >>> 2] = mergeWord;
				destIndex += hInc;
			}
		}
		if (nWords > 1) {
			destMask = mask2;

			/* pick up next word */

			thisWord = sourceBits[sourceIndex >>> 2];
			sourceIndex += hInc;

			/* 32-bit rotate */

			skewWord = (SHIFT((prevWord & notSkewMask), unskew)) | (SHIFT((thisWord & skewMask), skew));
			destWord = destBits[destIndex >>> 2];
			mergeWord = mergeFnwith(skewWord & halftoneWord, destWord);
			destWord = (destMask & mergeWord) | (destWord & ~destMask);
			destBits[destIndex >>> 2] = destWord;
			destIndex += hInc;
		}
		sourceIndex += sourceDelta;
		destIndex += destDelta;
	}
}


/*	Faster copyLoop when source not used.  hDir and vDir are both
	positive, and perload and skew are unused */

function copyLoopNoSource() {
	var mergeWord;
	var halftoneWord;
	var mergeFnwith;
	var destWord;
	var word;
	var i;

	mergeFnwith = opTable[combinationRule + 1];
	mergeFnwith;
	for (i = 1; i <= bbH; i++) {

		/* here is the vertical loop */

		if (noHalftone) {
			halftoneWord = AllOnes;
		} else {
			halftoneWord = halftoneAt((dy + i) - 1);
		}
		destMask = mask1;
		destWord = destBits[destIndex >>> 2];
		mergeWord = mergeFnwith(halftoneWord, destWord);
		destWord = (destMask & mergeWord) | (destWord & ~destMask);
		destBits[destIndex >>> 2] = destWord;

		/* This central horizontal loop requires no store masking */

		destIndex += 4;
		destMask = AllOnes;
		if (combinationRule === 3) {

			/* Special inner loop for STORE */

			destWord = halftoneWord;
			for (word = 2; word <= (nWords - 1); word++) {
				destBits[destIndex >>> 2] = destWord;
				destIndex += 4;
			}
		} else {

			/* Normal inner loop does merge */

			for (word = 2; word <= (nWords - 1); word++) {

				/* Normal inner loop does merge */

				destWord = destBits[destIndex >>> 2];
				mergeWord = mergeFnwith(halftoneWord, destWord);
				destBits[destIndex >>> 2] = mergeWord;
				destIndex += 4;
			}
		}
		if (nWords > 1) {
			destMask = mask2;
			destWord = destBits[destIndex >>> 2];
			mergeWord = mergeFnwith(halftoneWord, destWord);
			destWord = (destMask & mergeWord) | (destWord & ~destMask);
			destBits[destIndex >>> 2] = destWord;
			destIndex += 4;
		}
		destIndex += destDelta;
	}
}


/*	This version of the inner loop maps source pixels
	to a destination form with different depth.  Because it is already
	unweildy, the loop is not unrolled as in the other versions.
	Preload, skew and skewMask are all overlooked, since pickSourcePixels
	delivers its destination word already properly aligned.
	Note that pickSourcePixels could be copied in-line at the top of
	the horizontal loop, and some of its inits moved out of the loop. */
/*	ar 12/7/1999:
	The loop has been rewritten to use only one pickSourcePixels call.
	The idea is that the call itself could be inlined. If we decide not
	to inline pickSourcePixels we could optimize the loop instead. */

function copyLoopPixMap() {
	var mapperFlags;
	var srcShiftInc;
	var dstShiftLeft;
	var sourcePixMask;
	var nSourceIncs;
	var skewWord;
	var words;
	var destWord;
	var startBits;
	var mergeFnwith;
	var dstShift;
	var i;
	var halftoneWord;
	var mergeWord;
	var destPixMask;
	var dstShiftInc;
	var srcShift;
	var endBits;
	var nPix;
	var scrStartBits;

	mergeFnwith = opTable[combinationRule + 1];
	mergeFnwith;
	sourcePPW = DIV(32, sourceDepth);
	sourcePixMask = maskTable[sourceDepth];
	destPixMask = maskTable[destDepth];
	mapperFlags = cmFlags & ~ColorMapNewStyle;
	sourceIndex = ((sy * sourcePitch)) + ((DIV(sx, sourcePPW)) * 4);
	scrStartBits = sourcePPW - (sx & (sourcePPW - 1));
	if (bbW < scrStartBits) {
		nSourceIncs = 0;
	} else {
		nSourceIncs = (DIV((bbW - scrStartBits), sourcePPW)) + 1;
	}

	/* Note following two items were already calculated in destmask setup! */

	sourceDelta = sourcePitch - (nSourceIncs * 4);
	startBits = destPPW - (dx & (destPPW - 1));
	endBits = (((dx + bbW) - 1) & (destPPW - 1)) + 1;
	if (bbW < startBits) {
		startBits = bbW;
	}
	srcShift = (sx & (sourcePPW - 1)) * sourceDepth;
	dstShift = (dx & (destPPW - 1)) * destDepth;
	srcShiftInc = sourceDepth;
	dstShiftInc = destDepth;
	dstShiftLeft = 0;
	if (sourceMSB) {
		srcShift = (32 - sourceDepth) - srcShift;
		srcShiftInc = 0 - srcShiftInc;
	}
	if (destMSB) {
		dstShift = (32 - destDepth) - dstShift;
		dstShiftInc = 0 - dstShiftInc;
		dstShiftLeft = 32 - destDepth;
	}
	for (i = 1; i <= bbH; i++) {

		/* here is the vertical loop */
		/* *** is it possible at all that noHalftone == false? *** */

		if (noHalftone) {
			halftoneWord = AllOnes;
		} else {
			halftoneWord = halftoneAt((dy + i) - 1);
		}
		srcBitShift = srcShift;
		dstBitShift = dstShift;
		destMask = mask1;

		/* Here is the horizontal loop... */

		nPix = startBits;
		words = nWords;
		do {

			/* pick up the word */


			/* align next word to leftmost pixel */

			skewWord = pickSourcePixelsflagssrcMaskdestMasksrcShiftIncdstShiftInc(nPix, mapperFlags, sourcePixMask, destPixMask, srcShiftInc, dstShiftInc);
			dstBitShift = dstShiftLeft;
			if (destMask === AllOnes) {

				/* avoid read-modify-write */

				mergeWord = mergeFnwith(skewWord & halftoneWord, destBits[destIndex >>> 2]);
				destBits[destIndex >>> 2] = destMask & mergeWord;
			} else {

				/* General version using dest masking */

				destWord = destBits[destIndex >>> 2];
				mergeWord = mergeFnwith(skewWord & halftoneWord, destWord & destMask);
				destWord = (destMask & mergeWord) | (destWord & ~destMask);
				destBits[destIndex >>> 2] = destWord;
			}
			destIndex += 4;
			if (words === 2) {

				/* e.g., is the next word the last word? */
				/* set mask for last word in this row */

				destMask = mask2;
				nPix = endBits;
			} else {

				/* use fullword mask for inner loop */

				destMask = AllOnes;
				nPix = destPPW;
			}
		} while(!(((--words)) === 0));
		sourceIndex += sourceDelta;
		destIndex += destDelta;
	}
}


/*	Return the default translation table from 1..8 bit indexed colors to 32bit */
/*	The table has been generated by the following statements */
/*	| pvs hex |
	String streamContents:[:s|
		s nextPutAll:'static unsigned int theTable[256] = { '.
		pvs := (Color colorMapIfNeededFrom: 8 to: 32) asArray.
		1 to: pvs size do:[:i|
			i > 1 ifTrue:[s nextPutAll:', '].
			(i-1 \\ 8) = 0 ifTrue:[s cr].
			s nextPutAll:'0x'.
			hex := (pvs at: i) printStringBase: 16.
			s nextPutAll: (hex copyFrom: 4 to: hex size).
		].
		s nextPutAll:'};'.
	]. */

function default8To32Table() {
	var theTable = [ 
0x0, 0xFF000001, 0xFFFFFFFF, 0xFF808080, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFF00FFFF, 
0xFFFFFF00, 0xFFFF00FF, 0xFF202020, 0xFF404040, 0xFF606060, 0xFF9F9F9F, 0xFFBFBFBF, 0xFFDFDFDF, 
0xFF080808, 0xFF101010, 0xFF181818, 0xFF282828, 0xFF303030, 0xFF383838, 0xFF484848, 0xFF505050, 
0xFF585858, 0xFF686868, 0xFF707070, 0xFF787878, 0xFF878787, 0xFF8F8F8F, 0xFF979797, 0xFFA7A7A7, 
0xFFAFAFAF, 0xFFB7B7B7, 0xFFC7C7C7, 0xFFCFCFCF, 0xFFD7D7D7, 0xFFE7E7E7, 0xFFEFEFEF, 0xFFF7F7F7, 
0xFF000001, 0xFF003300, 0xFF006600, 0xFF009900, 0xFF00CC00, 0xFF00FF00, 0xFF000033, 0xFF003333, 
0xFF006633, 0xFF009933, 0xFF00CC33, 0xFF00FF33, 0xFF000066, 0xFF003366, 0xFF006666, 0xFF009966, 
0xFF00CC66, 0xFF00FF66, 0xFF000099, 0xFF003399, 0xFF006699, 0xFF009999, 0xFF00CC99, 0xFF00FF99, 
0xFF0000CC, 0xFF0033CC, 0xFF0066CC, 0xFF0099CC, 0xFF00CCCC, 0xFF00FFCC, 0xFF0000FF, 0xFF0033FF, 
0xFF0066FF, 0xFF0099FF, 0xFF00CCFF, 0xFF00FFFF, 0xFF330000, 0xFF333300, 0xFF336600, 0xFF339900, 
0xFF33CC00, 0xFF33FF00, 0xFF330033, 0xFF333333, 0xFF336633, 0xFF339933, 0xFF33CC33, 0xFF33FF33, 
0xFF330066, 0xFF333366, 0xFF336666, 0xFF339966, 0xFF33CC66, 0xFF33FF66, 0xFF330099, 0xFF333399, 
0xFF336699, 0xFF339999, 0xFF33CC99, 0xFF33FF99, 0xFF3300CC, 0xFF3333CC, 0xFF3366CC, 0xFF3399CC, 
0xFF33CCCC, 0xFF33FFCC, 0xFF3300FF, 0xFF3333FF, 0xFF3366FF, 0xFF3399FF, 0xFF33CCFF, 0xFF33FFFF, 
0xFF660000, 0xFF663300, 0xFF666600, 0xFF669900, 0xFF66CC00, 0xFF66FF00, 0xFF660033, 0xFF663333, 
0xFF666633, 0xFF669933, 0xFF66CC33, 0xFF66FF33, 0xFF660066, 0xFF663366, 0xFF666666, 0xFF669966, 
0xFF66CC66, 0xFF66FF66, 0xFF660099, 0xFF663399, 0xFF666699, 0xFF669999, 0xFF66CC99, 0xFF66FF99, 
0xFF6600CC, 0xFF6633CC, 0xFF6666CC, 0xFF6699CC, 0xFF66CCCC, 0xFF66FFCC, 0xFF6600FF, 0xFF6633FF, 
0xFF6666FF, 0xFF6699FF, 0xFF66CCFF, 0xFF66FFFF, 0xFF990000, 0xFF993300, 0xFF996600, 0xFF999900, 
0xFF99CC00, 0xFF99FF00, 0xFF990033, 0xFF993333, 0xFF996633, 0xFF999933, 0xFF99CC33, 0xFF99FF33, 
0xFF990066, 0xFF993366, 0xFF996666, 0xFF999966, 0xFF99CC66, 0xFF99FF66, 0xFF990099, 0xFF993399, 
0xFF996699, 0xFF999999, 0xFF99CC99, 0xFF99FF99, 0xFF9900CC, 0xFF9933CC, 0xFF9966CC, 0xFF9999CC, 
0xFF99CCCC, 0xFF99FFCC, 0xFF9900FF, 0xFF9933FF, 0xFF9966FF, 0xFF9999FF, 0xFF99CCFF, 0xFF99FFFF, 
0xFFCC0000, 0xFFCC3300, 0xFFCC6600, 0xFFCC9900, 0xFFCCCC00, 0xFFCCFF00, 0xFFCC0033, 0xFFCC3333, 
0xFFCC6633, 0xFFCC9933, 0xFFCCCC33, 0xFFCCFF33, 0xFFCC0066, 0xFFCC3366, 0xFFCC6666, 0xFFCC9966, 
0xFFCCCC66, 0xFFCCFF66, 0xFFCC0099, 0xFFCC3399, 0xFFCC6699, 0xFFCC9999, 0xFFCCCC99, 0xFFCCFF99, 
0xFFCC00CC, 0xFFCC33CC, 0xFFCC66CC, 0xFFCC99CC, 0xFFCCCCCC, 0xFFCCFFCC, 0xFFCC00FF, 0xFFCC33FF, 
0xFFCC66FF, 0xFFCC99FF, 0xFFCCCCFF, 0xFFCCFFFF, 0xFFFF0000, 0xFFFF3300, 0xFFFF6600, 0xFFFF9900, 
0xFFFFCC00, 0xFFFFFF00, 0xFFFF0033, 0xFFFF3333, 0xFFFF6633, 0xFFFF9933, 0xFFFFCC33, 0xFFFFFF33, 
0xFFFF0066, 0xFFFF3366, 0xFFFF6666, 0xFFFF9966, 0xFFFFCC66, 0xFFFFFF66, 0xFFFF0099, 0xFFFF3399, 
0xFFFF6699, 0xFFFF9999, 0xFFFFCC99, 0xFFFFFF99, 0xFFFF00CC, 0xFFFF33CC, 0xFFFF66CC, 0xFFFF99CC, 
0xFFFFCCCC, 0xFFFFFFCC, 0xFFFF00FF, 0xFFFF33FF, 0xFFFF66FF, 0xFFFF99FF, 0xFFFFCCFF, 0xFFFFFFFF];;

	return theTable;
}


/*	Utility routine for computing Warp increments. */

function deltaFromtonSteps(x1, x2, n) {
	if (x2 > x1) {
		return (DIV(((x2 - x1) + FixedPt1), (n + 1))) + 1;
	} else {
		if (x2 === x1) {
			return 0;
		}
		return 0 - ((DIV(((x1 - x2) + FixedPt1), (n + 1))) + 1);
	}
}


/*	Compute masks for left and right destination words */

function destMaskAndPointerInit() {
	var endBits;
	var startBits;
	var pixPerM1;


	/* A mask, assuming power of two */
	/* how many pixels in first word */

	pixPerM1 = destPPW - 1;
	startBits = destPPW - (dx & pixPerM1);
	if (destMSB) {
		mask1 = SHR(AllOnes, (32 - (startBits * destDepth)));
	} else {
		mask1 = SHL(AllOnes, (32 - (startBits * destDepth)));
	}
	endBits = (((dx + bbW) - 1) & pixPerM1) + 1;
	if (destMSB) {
		mask2 = SHL(AllOnes, (32 - (endBits * destDepth)));
	} else {
		mask2 = SHR(AllOnes, (32 - (endBits * destDepth)));
	}
	if (bbW < startBits) {
		mask1 = mask1 & mask2;
		mask2 = 0;
		nWords = 1;
	} else {
		nWords = (DIV(((bbW - startBits) + pixPerM1), destPPW)) + 1;
	}

	/* defaults for no overlap with source */
	/* calculate byte addr and delta, based on first word of data */
	/* Note pitch is bytes and nWords is longs, not bytes */

	hDir = (vDir = 1);
	destIndex = ((dy * destPitch)) + ((DIV(dx, destPPW)) * 4);
	destDelta = (destPitch * vDir) - (4 * (nWords * hDir));
}

function destinationWordwith(sourceWord, destinationWord) {
	return destinationWord;
}


/*	Dither the given 32bit word to 16 bit. Ignore alpha. */

function dither32To16threshold(srcWord, ditherValue) {
	var addThreshold;


	/* You bet */

	addThreshold = ditherValue << 8;
	return ((dither8Lookup[addThreshold + ((srcWord >>> 16) & 255)] << 10) + (dither8Lookup[addThreshold + ((srcWord >>> 8) & 255)] << 5)) + dither8Lookup[addThreshold + (srcWord & 255)];
}


/*	This is the primitive implementation of the line-drawing loop.
	See the comments in BitBlt>>drawLoopX:Y: */

function drawLoopXY(xDelta, yDelta) {
	var P;
	var affT;
	var dx1;
	var px;
	var affR;
	var affL;
	var py;
	var i;
	var affB;
	var dy1;

	if (xDelta > 0) {
		dx1 = 1;
	} else {
		if (xDelta === 0) {
			dx1 = 0;
		} else {
			dx1 = -1;
		}
	}
	if (yDelta > 0) {
		dy1 = 1;
	} else {
		if (yDelta === 0) {
			dy1 = 0;
		} else {
			dy1 = -1;
		}
	}
	px = Math.abs(yDelta);
	py = Math.abs(xDelta);

	/* init null rectangle */

	affL = (affT = 9999);
	affR = (affB = -9999);
	if (py > px) {

		/* more horizontal */

		P = py >> 1;
		for (i = 1; i <= py; i++) {
			destX += dx1;
			if (((P -= px)) < 0) {
				destY += dy1;
				P += py;
			}
			if (i < py) {
				copyBits();
				if (interpreterProxy.failed()) {
					return null;
				}
				if ((affectedL < affectedR) && (affectedT < affectedB)) {

					/* Affected rectangle grows along the line */

					affL = Math.min(affL, affectedL);
					affR = Math.max(affR, affectedR);
					affT = Math.min(affT, affectedT);
					affB = Math.max(affB, affectedB);
					if (((affR - affL) * (affB - affT)) > 4000) {

						/* If affected rectangle gets large, update it in chunks */

						affectedL = affL;
						affectedR = affR;
						affectedT = affT;
						affectedB = affB;
						showDisplayBits();

						/* init null rectangle */

						affL = (affT = 9999);
						affR = (affB = -9999);
					}
				}
			}
		}
	} else {

		/* more vertical */

		P = px >> 1;
		for (i = 1; i <= px; i++) {
			destY += dy1;
			if (((P -= py)) < 0) {
				destX += dx1;
				P += px;
			}
			if (i < px) {
				copyBits();
				if (interpreterProxy.failed()) {
					return null;
				}
				if ((affectedL < affectedR) && (affectedT < affectedB)) {

					/* Affected rectangle grows along the line */

					affL = Math.min(affL, affectedL);
					affR = Math.max(affR, affectedR);
					affT = Math.min(affT, affectedT);
					affB = Math.max(affB, affectedB);
					if (((affR - affL) * (affB - affT)) > 4000) {

						/* If affected rectangle gets large, update it in chunks */

						affectedL = affL;
						affectedR = affR;
						affectedT = affT;
						affectedB = affB;
						showDisplayBits();

						/* init null rectangle */

						affL = (affT = 9999);
						affR = (affB = -9999);
					}
				}
			}
		}
	}
	affectedL = affL;
	affectedR = affR;
	affectedT = affT;

	/* store destX, Y back */

	affectedB = affB;
	interpreterProxy.storeIntegerofObjectwithValue(BBDestXIndex, bitBltOop, destX);
	interpreterProxy.storeIntegerofObjectwithValue(BBDestYIndex, bitBltOop, destY);
}


/*	Store the given value back into destination form, using dstMask
	to mask out the bits to be modified. This is an essiantial
	read-modify-write operation on the destination form. */

function dstLongAtputmask(idx, srcValue, dstMask) {
	var dstValue;

	dstValue = destBits[idx >>> 2];
	dstValue = dstValue & dstMask;
	dstValue = dstValue | srcValue;
	destBits[idx >>> 2] = dstValue;
}


/*	Dither the given 32bit word to 16 bit. Ignore alpha. */

function expensiveDither32To16threshold(srcWord, ditherValue) {
	var pv;
	var threshold;
	var value;
	var out;


	/* You bet */

	pv = srcWord & 255;
	threshold = ditherThresholds16[pv & 7];
	value = ditherValues16[pv >>> 3];
	if (ditherValue < threshold) {
		out = value + 1;
	} else {
		out = value;
	}
	pv = (srcWord >>> 8) & 255;
	threshold = ditherThresholds16[pv & 7];
	value = ditherValues16[pv >>> 3];
	if (ditherValue < threshold) {
		out = out | ((value + 1) << 5);
	} else {
		out = out | (value << 5);
	}
	pv = (srcWord >>> 16) & 255;
	threshold = ditherThresholds16[pv & 7];
	value = ditherValues16[pv >>> 3];
	if (ditherValue < threshold) {
		out = out | ((value + 1) << 10);
	} else {
		out = out | (value << 10);
	}
	return out;
}


/*	Return the integer value of the given field of the given object. If the field contains a Float, truncate it and return its integral part. Fail if the given field does not contain a small integer or Float, or if the truncated Float is out of the range of small integers. */

function fetchIntOrFloatofObject(fieldIndex, objectPointer) {
	var floatValue;
	var fieldOop;

	fieldOop = interpreterProxy.fetchPointerofObject(fieldIndex, objectPointer);
	if (typeof fieldOop === "number") {
		return fieldOop;
	}
	floatValue = interpreterProxy.floatValueOf(fieldOop);
	if (!((-2.147483648e9 <= floatValue) && (floatValue <= 2.147483647e9))) {
		interpreterProxy.primitiveFail();
		return 0;
	}
	return (floatValue|0);
}


/*	Return the integer value of the given field of the given object. If the field contains a Float, truncate it and return its integral part. Fail if the given field does not contain a small integer or Float, or if the truncated Float is out of the range of small integers. */

function fetchIntOrFloatofObjectifNil(fieldIndex, objectPointer, defaultValue) {
	var floatValue;
	var fieldOop;

	fieldOop = interpreterProxy.fetchPointerofObject(fieldIndex, objectPointer);
	if (typeof fieldOop === "number") {
		return fieldOop;
	}
	if (fieldOop.isNil) {
		return defaultValue;
	}
	floatValue = interpreterProxy.floatValueOf(fieldOop);
	if (!((-2.147483648e9 <= floatValue) && (floatValue <= 2.147483647e9))) {
		interpreterProxy.primitiveFail();
		return 0;
	}
	return (floatValue|0);
}


/*	For any non-zero pixel value in destinationWord with zero alpha channel take the alpha from sourceWord and fill it in. Intended for fixing alpha channels left at zero during 16->32 bpp conversions. */

function fixAlphawith(sourceWord, destinationWord) {
	if (destDepth !== 32) {
		return destinationWord;
	}
	if (destinationWord === 0) {
		return 0;
	}
	if ((destinationWord & 4278190080) !== 0) {
		return destinationWord;
	}
	return destinationWord | (sourceWord & 4278190080);
}


/*	Note: This is hardcoded so it can be run from Squeak.
	The module name is used for validating a module *after*
	it is loaded to check if it does really contain the module
	we're thinking it contains. This is important! */

function getModuleName() {
	return moduleName;
}


/*	Return a value from the halftone pattern. */

function halftoneAt(idx) {
	return halftoneBase[MOD(idx, halftoneHeight)];
}

function halt() {
	;
}

function ignoreSourceOrHalftone(formPointer) {
	if (formPointer.isNil) {
		return true;
	}
	if (combinationRule === 0) {
		return true;
	}
	if (combinationRule === 5) {
		return true;
	}
	if (combinationRule === 10) {
		return true;
	}
	if (combinationRule === 15) {
		return true;
	}
	return false;
}

function initBBOpTable() {
	opTable[0+1] = clearWordwith;
	opTable[1+1] = bitAndwith;
	opTable[2+1] = bitAndInvertwith;
	opTable[3+1] = sourceWordwith;
	opTable[4+1] = bitInvertAndwith;
	opTable[5+1] = destinationWordwith;
	opTable[6+1] = bitXorwith;
	opTable[7+1] = bitOrwith;
	opTable[8+1] = bitInvertAndInvertwith;
	opTable[9+1] = bitInvertXorwith;
	opTable[10+1] = bitInvertDestinationwith;
	opTable[11+1] = bitOrInvertwith;
	opTable[12+1] = bitInvertSourcewith;
	opTable[13+1] = bitInvertOrwith;
	opTable[14+1] = bitInvertOrInvertwith;
	opTable[15+1] = destinationWordwith;
	opTable[16+1] = destinationWordwith;
	opTable[17+1] = destinationWordwith;
	opTable[18+1] = addWordwith;
	opTable[19+1] = subWordwith;
	opTable[20+1] = rgbAddwith;
	opTable[21+1] = rgbSubwith;
	opTable[22+1] = OLDrgbDiffwith;
	opTable[23+1] = OLDtallyIntoMapwith;
	opTable[24+1] = alphaBlendwith;
	opTable[25+1] = pixPaintwith;
	opTable[26+1] = pixMaskwith;
	opTable[27+1] = rgbMaxwith;
	opTable[28+1] = rgbMinwith;
	opTable[29+1] = rgbMinInvertwith;
	opTable[30+1] = alphaBlendConstwith;
	opTable[31+1] = alphaPaintConstwith;
	opTable[32+1] = rgbDiffwith;
	opTable[33+1] = tallyIntoMapwith;
	opTable[34+1] = alphaBlendScaledwith;
	opTable[35+1] = alphaBlendScaledwith;
	opTable[36+1] = alphaBlendScaledwith;
	opTable[37+1] = rgbMulwith;
	opTable[38+1] = pixSwapwith;
	opTable[39+1] = pixClearwith;
	opTable[40+1] = fixAlphawith;
	opTable[41+1] = rgbComponentAlphawith;
}

function initDither8Lookup() {
	var t;
	var b;
	var value;

	for (b = 0; b <= 255; b++) {
		for (t = 0; t <= 15; t++) {
			value = expensiveDither32To16threshold(b, t);
			dither8Lookup[(t << 8) + b] = value;
		}
	}
}

function initialiseModule() {
	initBBOpTable();
	initDither8Lookup();
	// skipping ifdef ENABLE_FAST_BLT
	return true;
}


/*	Return true if shiftTable/maskTable define an identity mapping. */

function isIdentityMapwith(shifts, masks) {
	if ((!shifts) || (!masks)) {
		return true;
	}
	if ((shifts[RedIndex] === 0) && ((shifts[GreenIndex] === 0) && ((shifts[BlueIndex] === 0) && ((shifts[AlphaIndex] === 0) && ((masks[RedIndex] === 16711680) && ((masks[GreenIndex] === 65280) && ((masks[BlueIndex] === 255) && (masks[AlphaIndex] === 4278190080)))))))) {
		return true;
	}
	return false;
}


/*	Load the dest form for BitBlt. Return false if anything is wrong, true otherwise. */

function loadBitBltDestForm() {
	var destBitsSize;

	destBits = interpreterProxy.fetchPointerofObject(FormBitsIndex, destForm);
	destWidth = interpreterProxy.fetchIntegerofObject(FormWidthIndex, destForm);
	destHeight = interpreterProxy.fetchIntegerofObject(FormHeightIndex, destForm);
	if (!((destWidth >= 0) && (destHeight >= 0))) {
		return false;
	}
	destDepth = interpreterProxy.fetchIntegerofObject(FormDepthIndex, destForm);
	destMSB = destDepth > 0;
	if (destDepth < 0) {
		destDepth = 0 - destDepth;
	}
	if (typeof destBits === "number") {

		/* Query for actual surface dimensions */

		if (!queryDestSurface(destBits)) {
			return false;
		}
		destPPW = DIV(32, destDepth);
		destBits = (destPitch = 0);
	} else {
		destPPW = DIV(32, destDepth);
		destPitch = (DIV((destWidth + (destPPW - 1)), destPPW)) * 4;
		destBitsSize = BYTESIZEOF(destBits);
		if (!(interpreterProxy.isWordsOrBytes(destBits) && (destBitsSize === (destPitch * destHeight)))) {
			if (interpreterProxy.isWordsOrBytes(destBits) && (destBitsSize > (destPitch * destHeight))) {
				interpreterProxy.vm.warnOnce("BitBlt>>loadBitBltDestForm: destBitsSize != destPitch * destHeight, expected " +
					destPitch + "*" + destHeight + "=" + (destPitch * destHeight) + ", got " + destBitsSize);
			} else {
				return false;
			}
		}
		destBits = destBits.wordsOrBytes();
	}
	return true;
}


/*	Load BitBlt from the oop.
	This function is exported for the Balloon engine. */

function loadBitBltFrom(bbObj) {
	return loadBitBltFromwarping(bbObj, false);
}


/*	Load context from BitBlt instance.  Return false if anything is amiss */
/*	NOTE this should all be changed to minX/maxX coordinates for simpler clipping
		-- once it works! */

function loadBitBltFromwarping(bbObj, aBool) {
	var ok;

	bitBltOop = bbObj;
	isWarping = aBool;
	combinationRule = interpreterProxy.fetchIntegerofObject(BBRuleIndex, bitBltOop);
	if (interpreterProxy.failed() || ((combinationRule < 0) || (combinationRule > (OpTableSize - 2)))) {
		return false;
	}
	if ((combinationRule >= 16) && (combinationRule <= 17)) {
		return false;
	}
	sourceForm = interpreterProxy.fetchPointerofObject(BBSourceFormIndex, bitBltOop);
	noSource = ignoreSourceOrHalftone(sourceForm);
	halftoneForm = interpreterProxy.fetchPointerofObject(BBHalftoneFormIndex, bitBltOop);
	noHalftone = ignoreSourceOrHalftone(halftoneForm);
	destForm = interpreterProxy.fetchPointerofObject(BBDestFormIndex, bbObj);
	if (!(interpreterProxy.isPointers(destForm) && (SIZEOF(destForm) >= 4))) {
		return false;
	}
	ok = loadBitBltDestForm();
	if (!ok) {
		return false;
	}
	destX = fetchIntOrFloatofObjectifNil(BBDestXIndex, bitBltOop, 0);
	destY = fetchIntOrFloatofObjectifNil(BBDestYIndex, bitBltOop, 0);
	width = fetchIntOrFloatofObjectifNil(BBWidthIndex, bitBltOop, destWidth);
	height = fetchIntOrFloatofObjectifNil(BBHeightIndex, bitBltOop, destHeight);
	if (interpreterProxy.failed()) {
		return false;
	}
	if (noSource) {
		sourceX = (sourceY = 0);
	} else {
		if (!(interpreterProxy.isPointers(sourceForm) && (SIZEOF(sourceForm) >= 4))) {
			return false;
		}
		ok = loadBitBltSourceForm();
		if (!ok) {
			return false;
		}
		ok = loadColorMap();
		if (!ok) {
			return false;
		}
		if ((cmFlags & ColorMapNewStyle) === 0) {
			setupColorMasks();
		}
		sourceX = fetchIntOrFloatofObjectifNil(BBSourceXIndex, bitBltOop, 0);
		sourceY = fetchIntOrFloatofObjectifNil(BBSourceYIndex, bitBltOop, 0);
	}
	ok = loadHalftoneForm();
	if (!ok) {
		return false;
	}
	clipX = fetchIntOrFloatofObjectifNil(BBClipXIndex, bitBltOop, 0);
	clipY = fetchIntOrFloatofObjectifNil(BBClipYIndex, bitBltOop, 0);
	clipWidth = fetchIntOrFloatofObjectifNil(BBClipWidthIndex, bitBltOop, destWidth);
	clipHeight = fetchIntOrFloatofObjectifNil(BBClipHeightIndex, bitBltOop, destHeight);
	if (interpreterProxy.failed()) {
		return false;
	}
	if (clipX < 0) {
		clipWidth += clipX;
		clipX = 0;
	}
	if (clipY < 0) {
		clipHeight += clipY;
		clipY = 0;
	}
	if ((clipX + clipWidth) > destWidth) {
		clipWidth = destWidth - clipX;
	}
	if ((clipY + clipHeight) > destHeight) {
		clipHeight = destHeight - clipY;
	}
	return true;
}


/*	Load the source form for BitBlt. Return false if anything is wrong, true otherwise. */

function loadBitBltSourceForm() {
	var sourceBitsSize;

	sourceBits = interpreterProxy.fetchPointerofObject(FormBitsIndex, sourceForm);
	sourceWidth = fetchIntOrFloatofObject(FormWidthIndex, sourceForm);
	sourceHeight = fetchIntOrFloatofObject(FormHeightIndex, sourceForm);
	if (!((sourceWidth >= 0) && (sourceHeight >= 0))) {
		return false;
	}
	sourceDepth = interpreterProxy.fetchIntegerofObject(FormDepthIndex, sourceForm);
	sourceMSB = sourceDepth > 0;
	if (sourceDepth < 0) {
		sourceDepth = 0 - sourceDepth;
	}
	if (typeof sourceBits === "number") {

		/* Query for actual surface dimensions */

		if (!querySourceSurface(sourceBits)) {
			return false;
		}
		sourcePPW = DIV(32, sourceDepth);
		sourceBits = (sourcePitch = 0);
	} else {
		sourcePPW = DIV(32, sourceDepth);
		sourcePitch = (DIV((sourceWidth + (sourcePPW - 1)), sourcePPW)) * 4;
		sourceBitsSize = BYTESIZEOF(sourceBits);
		if (!(interpreterProxy.isWordsOrBytes(sourceBits) && (sourceBitsSize === (sourcePitch * sourceHeight)))) {
			if (interpreterProxy.isWordsOrBytes(sourceBits) && (sourceBitsSize > (sourcePitch * sourceHeight))) {
				interpreterProxy.vm.warnOnce("BitBlt>>loadBitBltSourceForm: sourceBitsSize != sourcePitch * sourceHeight, expected " +
					sourcePitch + "*" + sourceHeight + "=" + (sourcePitch * sourceHeight) + ", got " + sourceBitsSize);
			} else {
				return false;
			}
		}
		sourceBits = sourceBits.wordsOrBytes();
	}
	return true;
}


/*	ColorMap, if not nil, must be longWords, and 
	2^N long, where N = sourceDepth for 1, 2, 4, 8 bits, 
	or N = 9, 12, or 15 (3, 4, 5 bits per color) for 16 or 32 bits. */

function loadColorMap() {
	var oop;
	var cmOop;
	var cmSize;
	var oldStyle;

	cmFlags = (cmMask = (cmBitsPerColor = 0));
	cmShiftTable = null;
	cmMaskTable = null;
	cmLookupTable = null;
	cmOop = interpreterProxy.fetchPointerofObject(BBColorMapIndex, bitBltOop);
	if (cmOop.isNil) {
		return true;
	}

	/* even if identity or somesuch - may be cleared later */

	cmFlags = ColorMapPresent;
	oldStyle = false;
	if (interpreterProxy.isWords(cmOop)) {

		/* This is an old-style color map (indexed only, with implicit RGBA conversion) */

		cmSize = SIZEOF(cmOop);
		cmLookupTable = cmOop.words;
		oldStyle = true;
		;
	} else {

		/* A new-style color map (fully qualified) */

		if (!(interpreterProxy.isPointers(cmOop) && (SIZEOF(cmOop) >= 3))) {
			return false;
		}
		cmShiftTable = loadColorMapShiftOrMaskFrom(interpreterProxy.fetchPointerofObject(0, cmOop));
		cmMaskTable = loadColorMapShiftOrMaskFrom(interpreterProxy.fetchPointerofObject(1, cmOop));
		oop = interpreterProxy.fetchPointerofObject(2, cmOop);
		if (oop.isNil) {
			cmSize = 0;
		} else {
			if (!interpreterProxy.isWords(oop)) {
				return false;
			}
			cmSize = SIZEOF(oop);
			cmLookupTable = oop.words;
		}
		cmFlags = cmFlags | ColorMapNewStyle;
		;
	}
	if ((cmSize & (cmSize - 1)) !== 0) {
		return false;
	}
	cmMask = cmSize - 1;
	cmBitsPerColor = 0;
	if (cmSize === 512) {
		cmBitsPerColor = 3;
	}
	if (cmSize === 4096) {
		cmBitsPerColor = 4;
	}
	if (cmSize === 32768) {
		cmBitsPerColor = 5;
	}
	if (cmSize === 0) {
		cmLookupTable = null;
		cmMask = 0;
	} else {
		cmFlags = cmFlags | ColorMapIndexedPart;
	}
	if (oldStyle) {

		/* needs implicit conversion */

		setupColorMasks();
	}
	if (isIdentityMapwith(cmShiftTable, cmMaskTable)) {
		cmMaskTable = null;
		cmShiftTable = null;
	} else {
		cmFlags = cmFlags | ColorMapFixedPart;
	}
	return true;
}

function loadColorMapShiftOrMaskFrom(mapOop) {
	if (mapOop.isNil) {
		return null;
	}
	if (typeof mapOop === "number") {
		interpreterProxy.primitiveFail();
		return null;
	}
	if (!(interpreterProxy.isWords(mapOop) && (SIZEOF(mapOop) === 4))) {
		interpreterProxy.primitiveFail();
		return null;
	}
	// hand-edited generated code: shifts needs to be signed!
	return mapOop.wordsAsInt32Array();
}


/*	Load the halftone form */

function loadHalftoneForm() {
	var halftoneBits;

	if (noHalftone) {
		halftoneBase = null;
		return true;
	}
	if (interpreterProxy.isPointers(halftoneForm) && (SIZEOF(halftoneForm) >= 4)) {

		/* Old-style 32xN monochrome halftone Forms */

		halftoneBits = interpreterProxy.fetchPointerofObject(FormBitsIndex, halftoneForm);
		halftoneHeight = interpreterProxy.fetchIntegerofObject(FormHeightIndex, halftoneForm);
		if (!interpreterProxy.isWords(halftoneBits)) {
			noHalftone = true;
		}
	} else {

		/* New spec accepts, basically, a word array */

		if (!(!interpreterProxy.isPointers(halftoneForm) && (interpreterProxy.isWords(halftoneForm)))) {
			return false;
		}
		halftoneBits = halftoneForm;
		halftoneHeight = SIZEOF(halftoneBits);
	}
	halftoneBase = halftoneBits.wordsOrBytes();
	return true;
}


/*	Load the surface support plugin */

function loadSurfacePlugin() {
	querySurfaceFn = interpreterProxy.ioLoadFunctionFrom("ioGetSurfaceFormat", "SurfacePlugin");
	lockSurfaceFn = interpreterProxy.ioLoadFunctionFrom("ioLockSurface", "SurfacePlugin");
	unlockSurfaceFn = interpreterProxy.ioLoadFunctionFrom("ioUnlockSurface", "SurfacePlugin");
	return (!!querySurfaceFn) && ((!!lockSurfaceFn) && (!!unlockSurfaceFn));
}

function loadWarpBltFrom(bbObj) {
	return loadBitBltFromwarping(bbObj, true);
}


/*	Get a pointer to the bits of any OS surfaces. */
/*	Notes: 
	* For equal source/dest handles only one locking operation is performed.
	This is to prevent locking of overlapping areas which does not work with
	certain APIs (as an example, DirectDraw prevents locking of overlapping areas). 
	A special case for non-overlapping but equal source/dest handle would 
	be possible but we would have to transfer this information over to 
	unlockSurfaces somehow (currently, only one unlock operation is 
	performed for equal source and dest handles). Also, this would require
	a change in the notion of ioLockSurface() which is right now interpreted
	as a hint and not as a requirement to lock only the specific portion of
	the surface.

	* The arguments in ioLockSurface() provide the implementation with
	an explicit hint what area is affected. It can be very useful to
	know the max. affected area beforehand if getting the bits requires expensive
	copy operations (e.g., like a roundtrip to the X server or a glReadPixel op).
	However, the returned pointer *MUST* point to the virtual origin of the surface
	and not to the beginning of the rectangle. The promise made by BitBlt
	is to never access data outside the given rectangle (aligned to 4byte boundaries!)
	so it is okay to return a pointer to the virtual origin that is actually outside
	the valid memory area.

	* The area provided in ioLockSurface() is already clipped (e.g., it will always
	be inside the source and dest boundingBox) but it is not aligned to word boundaries
	yet. It is up to the support code to compute accurate alignment if necessary.

	* Warping always requires the entire source surface to be locked because
	there is no beforehand knowledge about what area will actually be traversed.

	 */

function lockSurfaces() {
	var destHandle;
	var sourceHandle;
	var t;
	var fn;
	var r;
	var b;
	var l;

	hasSurfaceLock = false;
	if (destBits === 0) {

		/* Blitting *to* OS surface */

		if (!lockSurfaceFn) {
			if (!loadSurfacePlugin()) {
				return null;
			}
		}
		fn = lockSurfaceFn;
		destHandle = interpreterProxy.fetchIntegerofObject(FormBitsIndex, destForm);
		if ((sourceBits === 0) && (!noSource)) {

			/* Handle the special case of equal source and dest handles */

			sourceHandle = interpreterProxy.fetchIntegerofObject(FormBitsIndex, sourceForm);
			if (sourceHandle === destHandle) {

				/* If we have overlapping source/dest we lock the entire area
				so that there is only one area transmitted */

				if (isWarping) {

					/* Otherwise use overlapping area */

					l = Math.min(sx, dx);
					r = Math.max(sx, dx) + bbW;
					t = Math.min(sy, dy);
					b = Math.max(sy, dy) + bbH;
					sourceBits = fn(sourceHandle, function(p){sourcePitch = p}, l, t, r-l, b-t);
				} else {

					/* When warping we always need the entire surface for the source */

					sourceBits = fn(sourceHandle, function(p){sourcePitch = p}, 0,0, sourceWidth, sourceHeight);
				}
				destBits = sourceBits;
				destPitch = sourcePitch;
				hasSurfaceLock = true;
				return destBits !== 0;
			}
		}
		destBits = fn(destHandle, function(p){destPitch = p}, dx, dy, bbW, bbH);
		hasSurfaceLock = true;
	}
	if ((sourceBits === 0) && (!noSource)) {

		/* Blitting *from* OS surface */

		sourceHandle = interpreterProxy.fetchIntegerofObject(FormBitsIndex, sourceForm);
		if (!lockSurfaceFn) {
			if (!loadSurfacePlugin()) {
				return null;
			}
		}

		/* Warping requiring the entire surface */

		fn = lockSurfaceFn;
		if (isWarping) {
			sourceBits = fn(sourceHandle, function(p){sourcePitch = p}, 0, 0, sourceWidth, sourceHeight);
		} else {
			sourceBits = fn(sourceHandle, function(p){sourcePitch = p}, sx, sy, bbW, bbH);
		}
		hasSurfaceLock = true;
	}
	return (destBits !== 0) && ((sourceBits !== 0) || (noSource));
}


/*	Color map the given source pixel. */

function mapPixelflags(sourcePixel, mapperFlags) {
	var pv;

	pv = sourcePixel;
	if ((mapperFlags & ColorMapPresent) !== 0) {
		if ((mapperFlags & ColorMapFixedPart) !== 0) {

			/* avoid introducing transparency by color reduction */

			pv = rgbMapPixelflags(sourcePixel, mapperFlags);
			if ((pv === 0) && (sourcePixel !== 0)) {
				pv = 1;
			}
		}
		if ((mapperFlags & ColorMapIndexedPart) !== 0) {
			pv = cmLookupTable[pv & cmMask];
		}
	}
	return pv;
}


/*	The module with the given name was just unloaded.
	Make sure we have no dangling references. */

function moduleUnloaded(aModuleName) {
	if (strcmp(aModuleName, "SurfacePlugin") === 0) {

		/* The surface plugin just shut down. How nasty. */

		querySurfaceFn = (lockSurfaceFn = (unlockSurfaceFn = 0));
	}
}


/*	AND word1 to word2 as nParts partitions of nBits each.
	Any field of word1 not all-ones is treated as all-zeroes.
	Used for erasing, eg, brush shapes prior to ORing in a color */

function partitionedANDtonBitsnPartitions(word1, word2, nBits, nParts) {
	var result;
	var i;
	var mask;


	/* partition mask starts at the right */

	mask = maskTable[nBits];
	result = 0;
	for (i = 1; i <= nParts; i++) {
		if ((word1 & mask) === mask) {
			result = result | (word2 & mask);
		}

		/* slide left to next partition */

		mask = SHL(mask, nBits);
	}
	return result;
}


/*	Add word1 to word2 as nParts partitions of nBits each.
	This is useful for packed pixels, or packed colors */
/*	Use unsigned int everywhere because it has a well known arithmetic model without undefined behavior w.r.t. overflow and shifts */

function partitionedAddtonBitscomponentMaskcarryOverflowMask(word1, word2, nBits, componentMask, carryOverflowMask) {
	var w2;
	var carryOverflow;
	var sum;
	var w1;


	/* mask to remove high bit of each component */

	w1 = word1 & carryOverflowMask;
	w2 = word2 & carryOverflowMask;

	/* sum without high bit to avoid overflowing over next component */

	sum = (word1 ^ w1) + (word2 ^ w2);

	/* detect overflow condition for saturating */

	carryOverflow = (w1 & w2) | ((w1 | w2) & sum);
	return ((sum ^ w1) ^ w2) | ((SHR(carryOverflow, (nBits - 1))) * componentMask);
}


/*	Max word1 to word2 as nParts partitions of nBits each */
/*	In C, most arithmetic operations answer the same bit pattern regardless of the operands being signed or unsigned ints
	(this is due to the way 2's complement numbers work). However, comparisions might fail. Add the proper declaration of
	words as unsigned int in those cases where comparisions are done (jmv) */

function partitionedMaxwithnBitsnPartitions(word1, word2, nBits, nParts) {
	var result;
	var i;
	var mask;


	/* partition mask starts at the right */

	mask = maskTable[nBits];
	result = 0;
	for (i = 1; i <= nParts; i++) {
		result = result | Math.max((word2 & mask), (word1 & mask));

		/* slide left to next partition */

		mask = SHL(mask, nBits);
	}
	return result;
}


/*	Min word1 to word2 as nParts partitions of nBits each */
/*	In C, most arithmetic operations answer the same bit pattern regardless of the operands being signed or unsigned ints
	(this is due to the way 2's complement numbers work). However, comparisions might fail. Add the proper declaration of
	words as unsigned int in those cases where comparisions are done (jmv) */

function partitionedMinwithnBitsnPartitions(word1, word2, nBits, nParts) {
	var result;
	var i;
	var mask;


	/* partition mask starts at the right */

	mask = maskTable[nBits];
	result = 0;
	for (i = 1; i <= nParts; i++) {
		result = result | Math.min((word2 & mask), (word1 & mask));

		/* slide left to next partition */

		mask = SHL(mask, nBits);
	}
	return result;
}


/*	Multiply word1 with word2 as nParts partitions of nBits each.
	This is useful for packed pixels, or packed colors.
	Bug in loop version when non-white background */
/*	In C, integer multiplication might answer a wrong value if the unsigned values are declared as signed.
	This problem does not affect this method, because the most significant bit (i.e. the sign bit) will
	always be zero (jmv) */

function partitionedMulwithnBitsnPartitions(word1, word2, nBits, nParts) {
	var dMask;
	var result;
	var product;
	var sMask;


	/* partition mask starts at the right */

	sMask = maskTable[nBits];
	dMask = SHL(sMask, nBits);

	/* optimized first step */

	result = SHR((((((word1 & sMask) + 1) * ((word2 & sMask) + 1)) - 1) & dMask), nBits);
	if (nParts === 1) {
		return result;
	}
	product = (((((SHR(word1, nBits)) & sMask) + 1) * (((SHR(word2, nBits)) & sMask) + 1)) - 1) & dMask;
	result = result | product;
	if (nParts === 2) {
		return result;
	}
	product = (((((SHR(word1, (2 * nBits))) & sMask) + 1) * (((SHR(word2, (2 * nBits))) & sMask) + 1)) - 1) & dMask;
	result = result | (SHL(product, nBits));
	if (nParts === 3) {
		return result;
	}
	product = (((((SHR(word1, (3 * nBits))) & sMask) + 1) * (((SHR(word2, (3 * nBits))) & sMask) + 1)) - 1) & dMask;
	result = result | (SHL(product, (2 * nBits)));
	return result;
}

function partitionedRgbComponentAlphadestnBitsnPartitions(sourceWord, destWord, nBits, nParts) {
	var p2;
	var result;
	var p1;
	var i;
	var v;
	var mask;


	/* partition mask starts at the right */

	mask = maskTable[nBits];
	result = 0;
	for (i = 1; i <= nParts; i++) {
		p1 = SHR((sourceWord & mask), ((i - 1) * nBits));
		p2 = SHR((destWord & mask), ((i - 1) * nBits));
		if (nBits !== 32) {
			if (nBits === 16) {
				p1 = rgbMap16To32(p1) | 4278190080;
				p2 = rgbMap16To32(p2) | 4278190080;
			} else {
				p1 = rgbMapfromto(p1, nBits, 32) | 4278190080;
				p2 = rgbMapfromto(p2, nBits, 32) | 4278190080;
			}
		}
		v = rgbComponentAlpha32with(p1, p2);
		if (nBits !== 32) {
			v = rgbMapfromto(v, 32, nBits);
		}
		result = result | (SHL(v, ((i - 1) * nBits)));

		/* slide left to next partition */

		mask = SHL(mask, nBits);
	}
	return result;
}


/*	Subtract word1 from word2 as nParts partitions of nBits each.
	This is useful for packed pixels, or packed colors */
/*	In C, most arithmetic operations answer the same bit pattern regardless of the operands being signed or unsigned ints
	(this is due to the way 2's complement numbers work). However, comparisions might fail. Add the proper declaration of
	words as unsigned int in those cases where comparisions are done (jmv) */

function partitionedSubfromnBitsnPartitions(word1, word2, nBits, nParts) {
	var p2;
	var result;
	var p1;
	var i;
	var mask;


	/* partition mask starts at the right */

	mask = maskTable[nBits];
	result = 0;
	for (i = 1; i <= nParts; i++) {
		p1 = word1 & mask;
		p2 = word2 & mask;
		if (p1 < p2) {

			/* result is really abs value of thedifference */

			result = result | (p2 - p1);
		} else {
			result = result | (p1 - p2);
		}

		/* slide left to next partition */

		mask = SHL(mask, nBits);
	}
	return result;
}


/*	Based on the values provided during setup choose and
	perform the appropriate inner loop function. */
/*	Should be inlined into caller for speed */

function performCopyLoop() {
	destMaskAndPointerInit();
	if (noSource) {

		/* Simple fill loop */

		copyLoopNoSource();
	} else {

		/* Loop using source and dest */

		checkSourceOverlap();
		if ((sourceDepth !== destDepth) || ((cmFlags !== 0) || (sourceMSB !== destMSB))) {

			/* If we must convert between pixel depths or use
			color lookups or swap pixels use the general version */

			copyLoopPixMap();
		} else {

			/* Otherwise we simple copy pixels and can use a faster version */

			sourceSkewAndPointerInit();
			copyLoop();
		}
	}
}


/*	Pick nPix pixels starting at srcBitIndex from the source, map by the
	color map, and justify them according to dstBitIndex in the resulting destWord. */

function pickSourcePixelsflagssrcMaskdestMasksrcShiftIncdstShiftInc(nPixels, mapperFlags, srcMask, dstMask, srcShiftInc, dstShiftInc) {
	var sourcePix;
	var srcShift;
	var sourceWord;
	var dstShift;
	var destPix;
	var nPix;
	var destWord;


	/* oh please */

	sourceWord = sourceBits[sourceIndex >>> 2];
	destWord = 0;

	/* Hint: Keep in register */

	srcShift = srcBitShift;

	/* Hint: Keep in register */

	dstShift = dstBitShift;

	/* always > 0 so we can use do { } while(--nPix); */

	nPix = nPixels;
	if (mapperFlags === (ColorMapPresent | ColorMapIndexedPart)) {

		/* a little optimization for (pretty crucial) blits using indexed lookups only */
		/* grab, colormap and mix in pixel */

		do {
			sourcePix = (SHR(sourceWord, srcShift)) & srcMask;
			destPix = cmLookupTable[sourcePix & cmMask];

			/* adjust dest pix index */

			destWord = destWord | (SHL((destPix & dstMask), dstShift));

			/* adjust source pix index */

			dstShift += dstShiftInc;
			if ((((srcShift += srcShiftInc)) & 4294967264) !== 0) {
				if (sourceMSB) {
					srcShift += 32;
				} else {
					srcShift -= 32;
				}
				sourceWord = sourceBits[(sourceIndex += 4) >>> 2];
			}
		} while(!(((--nPix)) === 0));
	} else {

		/* grab, colormap and mix in pixel */

		do {
			sourcePix = (SHR(sourceWord, srcShift)) & srcMask;
			destPix = mapPixelflags(sourcePix, mapperFlags);

			/* adjust dest pix index */

			destWord = destWord | (SHL((destPix & dstMask), dstShift));

			/* adjust source pix index */

			dstShift += dstShiftInc;
			if ((((srcShift += srcShiftInc)) & 4294967264) !== 0) {
				if (sourceMSB) {
					srcShift += 32;
				} else {
					srcShift -= 32;
				}
				sourceWord = sourceBits[(sourceIndex += 4) >>> 2];
			}
		} while(!(((--nPix)) === 0));
	}

	/* Store back */

	srcBitShift = srcShift;
	return destWord;
}


/*	Pick a single pixel from the source for WarpBlt.
	Note: This method is crucial for WarpBlt speed w/o smoothing
	and still relatively important when smoothing is used. */

function pickWarpPixelAtXy(xx, yy) {
	var sourcePix;
	var sourceWord;
	var srcIndex;
	var x;
	var y;


	/* *please* */
	/* note: it would be much faster if we could just
	avoid these stupid tests for being inside sourceForm. */

	if ((xx < 0) || ((yy < 0) || ((((x = xx >>> 14)) >= sourceWidth) || (((y = yy >>> 14)) >= sourceHeight)))) {
		return 0;
	}
	srcIndex = ((y * sourcePitch)) + ((SHR(x, warpAlignShift)) * 4);

	/* Extract pixel from word */

	sourceWord = sourceBits[srcIndex >>> 2];
	srcBitShift = warpBitShiftTable[x & warpAlignMask];
	sourcePix = (SHR(sourceWord, srcBitShift)) & warpSrcMask;
	return sourcePix;
}


/*	Clear all pixels in destinationWord for which the pixels of sourceWord have the same values. Used to clear areas of some constant color to zero. */

function pixClearwith(sourceWord, destinationWord) {
	var pv;
	var nBits;
	var result;
	var i;
	var mask;

	if (destDepth === 32) {
		if (sourceWord === destinationWord) {
			return 0;
		} else {
			return destinationWord;
		}
	}
	nBits = destDepth;

	/* partition mask starts at the right */

	mask = maskTable[nBits];
	result = 0;
	for (i = 1; i <= destPPW; i++) {
		pv = destinationWord & mask;
		if ((sourceWord & mask) === pv) {
			pv = 0;
		}
		result = result | pv;

		/* slide left to next partition */

		mask = SHL(mask, nBits);
	}
	return result;
}

function pixMaskwith(sourceWord, destinationWord) {
	return partitionedANDtonBitsnPartitions(~sourceWord, destinationWord, destDepth, destPPW);
}

function pixPaintwith(sourceWord, destinationWord) {
	if (sourceWord === 0) {
		return destinationWord;
	}
	return sourceWord | partitionedANDtonBitsnPartitions(~sourceWord, destinationWord, destDepth, destPPW);
}


/*	Swap the pixels in destWord */

function pixSwapwith(sourceWord, destWord) {
	var result;
	var shift;
	var lowMask;
	var highMask;
	var i;

	if (destPPW === 1) {
		return destWord;
	}
	result = 0;

	/* mask low pixel */

	lowMask = (SHL(1, destDepth)) - 1;

	/* mask high pixel */

	highMask = SHL(lowMask, ((destPPW - 1) * destDepth));
	shift = 32 - destDepth;
	result = result | ((SHL((destWord & lowMask), shift)) | (SHR((destWord & highMask), shift)));
	if (destPPW <= 2) {
		return result;
	}
	for (i = 2; i <= (destPPW >> 1); i++) {
		lowMask = SHL(lowMask, destDepth);
		highMask = SHR(highMask, destDepth);
		shift -= destDepth * 2;
		result = result | ((SHL((destWord & lowMask), shift)) | (SHR((destWord & highMask), shift)));
	}
	return result;
}


/*	Invoke the copyBits primitive. If the destination is the display, then copy it to the screen. */

function primitiveCopyBits() {
	var rcvr;

	rcvr = interpreterProxy.stackValue(interpreterProxy.methodArgumentCount());
	if (!loadBitBltFrom(rcvr)) {
		return interpreterProxy.primitiveFail();
	}
	copyBits();
	if (interpreterProxy.failed()) {
		return null;
	}
	showDisplayBits();
	if (interpreterProxy.failed()) {
		return null;
	}
	interpreterProxy.pop(interpreterProxy.methodArgumentCount());
	if ((combinationRule === 22) || (combinationRule === 32)) {
		interpreterProxy.pop(1);
		return interpreterProxy.pushInteger(bitCount);
	}
}

function primitiveDisplayString() {
	var charIndex;
	var sourcePtr;
	var stopIndex;
	var bbObj;
	var xTable;
	var maxGlyph;
	var quickBlt;
	var glyphIndex;
	var glyphMap;
	var left;
	var kernDelta;
	var startIndex;
	var ascii;
	var sourceString;

	if (interpreterProxy.methodArgumentCount() !== 6) {
		return interpreterProxy.primitiveFail();
	}
	kernDelta = interpreterProxy.stackIntegerValue(0);
	xTable = interpreterProxy.stackObjectValue(1);
	glyphMap = interpreterProxy.stackObjectValue(2);
	if (!((CLASSOF(xTable) === interpreterProxy.classArray()) && (CLASSOF(glyphMap) === interpreterProxy.classArray()))) {
		return interpreterProxy.primitiveFail();
	}
	if (SIZEOF(glyphMap) !== 256) {
		return interpreterProxy.primitiveFail();
	}
	if (interpreterProxy.failed()) {
		return null;
	}
	maxGlyph = SIZEOF(xTable) - 2;
	stopIndex = interpreterProxy.stackIntegerValue(3);
	startIndex = interpreterProxy.stackIntegerValue(4);
	sourceString = interpreterProxy.stackObjectValue(5);
	if (!interpreterProxy.isBytes(sourceString)) {
		return interpreterProxy.primitiveFail();
	}
	if (!((startIndex > 0) && ((stopIndex > 0) && (stopIndex <= BYTESIZEOF(sourceString))))) {
		return interpreterProxy.primitiveFail();
	}
	bbObj = interpreterProxy.stackObjectValue(6);
	if (!loadBitBltFrom(bbObj)) {
		return interpreterProxy.primitiveFail();
	}
	if ((combinationRule === 30) || (combinationRule === 31)) {

		/* needs extra source alpha */

		return interpreterProxy.primitiveFail();
	}
	quickBlt = (destBits !== 0) && ((sourceBits !== 0) && ((noSource === false) && ((sourceForm !== destForm) && ((cmFlags !== 0) || ((sourceMSB !== destMSB) || (sourceDepth !== destDepth))))));
	left = destX;
	sourcePtr = sourceString.bytes;
	for (charIndex = startIndex; charIndex <= stopIndex; charIndex++) {
		ascii = sourcePtr[charIndex - 1];
		glyphIndex = interpreterProxy.fetchIntegerofObject(ascii, glyphMap);
		if ((glyphIndex < 0) || (glyphIndex > maxGlyph)) {
			return interpreterProxy.primitiveFail();
		}
		sourceX = interpreterProxy.fetchIntegerofObject(glyphIndex, xTable);
		width = interpreterProxy.fetchIntegerofObject(glyphIndex + 1, xTable) - sourceX;
		if (interpreterProxy.failed()) {
			return null;
		}
		clipRange();
		if ((bbW > 0) && (bbH > 0)) {
			if (quickBlt) {
				destMaskAndPointerInit();
				copyLoopPixMap();
				affectedL = dx;
				affectedR = dx + bbW;
				affectedT = dy;
				affectedB = dy + bbH;
			} else {
				copyBits();
			}
		}
		if (interpreterProxy.failed()) {
			return null;
		}
		destX = (destX + width) + kernDelta;
	}
	affectedL = left;
	showDisplayBits();
	interpreterProxy.storeIntegerofObjectwithValue(BBDestXIndex, bbObj, destX);
	interpreterProxy.pop(6);
}


/*	Invoke the line drawing primitive. */

function primitiveDrawLoop() {
	var yDelta;
	var rcvr;
	var xDelta;

	rcvr = interpreterProxy.stackValue(2);
	xDelta = interpreterProxy.stackIntegerValue(1);
	yDelta = interpreterProxy.stackIntegerValue(0);
	if (!loadBitBltFrom(rcvr)) {
		return interpreterProxy.primitiveFail();
	}
	if (!interpreterProxy.failed()) {
		drawLoopXY(xDelta, yDelta);
		showDisplayBits();
	}
	if (!interpreterProxy.failed()) {
		interpreterProxy.pop(2);
	}
}


/*	returns the single pixel at x@y.
	It does not handle LSB bitmaps right now.
	If x or y are < 0, return 0 to indicate transparent (cf BitBlt>bitPeekerFromForm: usage).
	Likewise if x>width or y>depth.
	Fail if the rcvr doesn't seem to be a Form, or x|y seem wrong */

function primitivePixelValueAt() {
	var pixel;
	var rcvr;
	var shift;
	var depth;
	var bitmap;
	var ppW;
	var word;
	var stride;
	var bitsSize;
	var mask;
	var xVal;
	var yVal;
	var _return_value;

	xVal = interpreterProxy.stackIntegerValue(1);
	yVal = interpreterProxy.stackIntegerValue(0);
	rcvr = interpreterProxy.stackValue(2);
	if (interpreterProxy.failed()) {
		return null;
	}
	if ((xVal < 0) || (yVal < 0)) {
		_return_value = 0;
		if (interpreterProxy.failed()) {
			return null;
		}
		interpreterProxy.popthenPush(3, _return_value);
		return null;
	}
	rcvr = interpreterProxy.stackValue(interpreterProxy.methodArgumentCount());
	if (!(interpreterProxy.isPointers(rcvr) && (SIZEOF(rcvr) >= 4))) {
		interpreterProxy.primitiveFail();
		return null;
	}
	bitmap = interpreterProxy.fetchPointerofObject(FormBitsIndex, rcvr);
	if (!interpreterProxy.isWordsOrBytes(bitmap)) {
		interpreterProxy.primitiveFail();
		return null;
	}
	width = interpreterProxy.fetchIntegerofObject(FormWidthIndex, rcvr);
	height = interpreterProxy.fetchIntegerofObject(FormHeightIndex, rcvr);

	/* if width/height/depth are not integer, fail */

	depth = interpreterProxy.fetchIntegerofObject(FormDepthIndex, rcvr);
	if (interpreterProxy.failed()) {
		return null;
	}
	if ((xVal >= width) || (yVal >= height)) {
		_return_value = 0;
		if (interpreterProxy.failed()) {
			return null;
		}
		interpreterProxy.popthenPush(3, _return_value);
		return null;
	}
	if (depth < 0) {
		interpreterProxy.primitiveFail();
		return null;
	}

	/* pixels in each word */

	ppW = DIV(32, depth);

	/* how many words per row of pixels */

	stride = DIV((width + (ppW - 1)), ppW);
	bitsSize = BYTESIZEOF(bitmap);
	if (bitsSize !== ((stride * height) * 4)) {

		/* bytes per word */

		interpreterProxy.primitiveFail();
		return null;
	}

	/* load the word that contains our target */

	word = interpreterProxy.fetchLong32ofObject((yVal * stride) + (DIV(xVal, ppW)), bitmap);

	/* make a mask to isolate the pixel within that word */

	mask = SHR(4294967295, (32 - depth));

	/* this is the tricky MSB part - we mask the xVal to find how far into the word we need, then add 1 for the pixel we're looking for, then * depth to get the bit shift */

	shift = 32 - (((xVal & (ppW - 1)) + 1) * depth);

	/* shift, mask and dim the lights */

	pixel = (SHR(word, shift)) & mask;
	_return_value = interpreterProxy.positive32BitIntegerFor(pixel);
	if (interpreterProxy.failed()) {
		return null;
	}
	interpreterProxy.popthenPush(3, _return_value);
	return null;
}


/*	Invoke the warpBits primitive. If the destination is the display, then copy it to the screen. */

function primitiveWarpBits() {
	var rcvr;

	rcvr = interpreterProxy.stackValue(interpreterProxy.methodArgumentCount());
	if (!loadWarpBltFrom(rcvr)) {
		return interpreterProxy.primitiveFail();
	}
	warpBits();
	if (interpreterProxy.failed()) {
		return null;
	}
	showDisplayBits();
	if (interpreterProxy.failed()) {
		return null;
	}
	interpreterProxy.pop(interpreterProxy.methodArgumentCount());
}


/*	Query the dimension of an OS surface.
	This method is provided so that in case the inst vars of the
	source form are broken, *actual* values of the OS surface
	can be obtained. This might, for instance, happen if the user
	resizes the main window.
	Note: Moved to a separate function for better inlining of the caller. */

function queryDestSurface(handle) {
	if (!querySurfaceFn) {
		if (!loadSurfacePlugin()) {
			return false;
		}
	}
	return querySurfaceFn(handle, function(w, h, d, m){destWidth = w; destHeight = h; destDepth = d; destMSB = m; });
}


/*	Query the dimension of an OS surface.
	This method is provided so that in case the inst vars of the
	source form are broken, *actual* values of the OS surface
	can be obtained. This might, for instance, happen if the user
	resizes the main window.
	Note: Moved to a separate function for better inlining of the caller. */

function querySourceSurface(handle) {
	if (!querySurfaceFn) {
		if (!loadSurfacePlugin()) {
			return false;
		}
	}
	return querySurfaceFn(handle, function(w, h, d, m){sourceWidth = w; sourceHeight = h; sourceDepth = d; sourceMSB = m; });
}

function rgbAddwith(sourceWord, destinationWord) {
	var carryOverflowMask;
	var componentMask;

	if (destDepth < 16) {

		/* Add each pixel separately */

		componentMask = (SHL(1, destDepth)) - 1;
		carryOverflowMask = SHL((DIV(4294967295, componentMask)), (destDepth - 1));
		return partitionedAddtonBitscomponentMaskcarryOverflowMask(sourceWord, destinationWord, destDepth, componentMask, carryOverflowMask);
	}
	if (destDepth === 16) {

		/* Add RGB components of each pixel separately */

		componentMask = 31;
		carryOverflowMask = 1108361744;
		return partitionedAddtonBitscomponentMaskcarryOverflowMask(sourceWord & 2147450879, destinationWord & 2147450879, 5, componentMask, carryOverflowMask);
	} else {

		/* Add RGBA components of the pixel separately */

		componentMask = 255;
		carryOverflowMask = 2155905152;
		return partitionedAddtonBitscomponentMaskcarryOverflowMask(sourceWord, destinationWord, 8, componentMask, carryOverflowMask);
	}
}


/*	This version assumes 
		combinationRule = 41
		sourcePixSize = 32
		destPixSize = 16
		sourceForm ~= destForm.
	 */
/*	This particular method should be optimized in itself */

function rgbComponentAlpha16() {
	var ditherBase;
	var ditherThreshold;
	var srcShift;
	var sourceWord;
	var srcIndex;
	var deltaX;
	var dstIndex;
	var srcAlpha;
	var dstMask;
	var deltaY;
	var srcY;
	var destWord;
	var dstY;
	var ditherIndex;


	/* So we can pre-decrement */

	deltaY = bbH + 1;
	srcY = sy;
	dstY = dy;
	srcShift = (dx & 1) * 16;
	if (destMSB) {
		srcShift = 16 - srcShift;
	}

	/* This is the outer loop */

	mask1 = SHL(65535, (16 - srcShift));
	while (((--deltaY)) !== 0) {
		srcIndex = ((srcY * sourcePitch)) + (sx * 4);
		dstIndex = ((dstY * destPitch)) + ((dx >> 1) * 4);
		ditherBase = (dstY & 3) * 4;

		/* For pre-increment */

		ditherIndex = (sx & 3) - 1;

		/* So we can pre-decrement */

		deltaX = bbW + 1;
		dstMask = mask1;
		if (dstMask === 65535) {
			srcShift = 16;
		} else {
			srcShift = 0;
		}
		while (((--deltaX)) !== 0) {
			ditherThreshold = ditherMatrix4x4[ditherBase + ((ditherIndex = (ditherIndex + 1) & 3))];
			sourceWord = sourceBits[srcIndex >>> 2];
			srcAlpha = sourceWord & 16777215;
			if (srcAlpha !== 0) {

				/* 0 < srcAlpha */
				/* If we have to mix colors then just copy a single word */

				destWord = destBits[dstIndex >>> 2];
				destWord = destWord & ~dstMask;

				/* Expand from 16 to 32 bit by adding zero bits */

				destWord = SHR(destWord, srcShift);

				/* Mix colors */

				destWord = (((destWord & 31744) << 9) | ((destWord & 992) << 6)) | (((destWord & 31) << 3) | 4278190080);

				/* And dither */

				sourceWord = rgbComponentAlpha32with(sourceWord, destWord);
				sourceWord = dither32To16threshold(sourceWord, ditherThreshold);
				if (sourceWord === 0) {
					sourceWord = SHL(1, srcShift);
				} else {
					sourceWord = SHL(sourceWord, srcShift);
				}
				dstLongAtputmask(dstIndex, sourceWord, dstMask);
			}
			srcIndex += 4;
			if (destMSB) {
				if (srcShift === 0) {
					dstIndex += 4;
				}
			} else {
				if (srcShift !== 0) {
					dstIndex += 4;
				}
			}

			/* Toggle between 0 and 16 */

			srcShift = srcShift ^ 16;
			dstMask = ~dstMask;
		}
		++srcY;
		++dstY;
	}
}


/*	This version assumes 
		combinationRule = 41
		sourcePixSize = destPixSize = 32
		sourceForm ~= destForm.
	Note: The inner loop has been optimized for dealing
		with the special case of aR = aG = aB = 0 
	 */

function rgbComponentAlpha32() {
	var sourceWord;
	var srcIndex;
	var deltaX;
	var dstIndex;
	var srcAlpha;
	var deltaY;
	var srcY;
	var destWord;
	var dstY;


	/* This particular method should be optimized in itself */
	/* Give the compile a couple of hints */
	/* The following should be declared as pointers so the compiler will
	notice that they're used for accessing memory locations 
	(good to know on an Intel architecture) but then the increments
	would be different between ST code and C code so must hope the
	compiler notices what happens (MS Visual C does) */


	/* So we can pre-decrement */

	deltaY = bbH + 1;
	srcY = sy;

	/* This is the outer loop */

	dstY = dy;
	while (((--deltaY)) !== 0) {
		srcIndex = ((srcY * sourcePitch)) + (sx * 4);
		dstIndex = ((dstY * destPitch)) + (dx * 4);

		/* So we can pre-decrement */
		/* This is the inner loop */

		deltaX = bbW + 1;
		while (((--deltaX)) !== 0) {
			sourceWord = sourceBits[srcIndex >>> 2];
			srcAlpha = sourceWord & 16777215;
			if (srcAlpha === 0) {
				srcIndex += 4;

				/* Now skip as many words as possible, */

				dstIndex += 4;
				while ((((--deltaX)) !== 0) && ((((sourceWord = sourceBits[srcIndex >>> 2])) & 16777215) === 0)) {
					srcIndex += 4;
					dstIndex += 4;
				}
				++deltaX;
			} else {

				/* 0 < srcAlpha */
				/* If we have to mix colors then just copy a single word */

				destWord = destBits[dstIndex >>> 2];
				destWord = rgbComponentAlpha32with(sourceWord, destWord);
				destBits[dstIndex >>> 2] = destWord;
				srcIndex += 4;
				dstIndex += 4;
			}
		}
		++srcY;
		++dstY;
	}
}


/*	
	componentAlphaModeColor is the color,
	sourceWord contains an alpha value for each component of RGB
	each of which is encoded as0 meaning 0.0 and 255 meaning 1.0 .
	the rule is...
	
	color = componentAlphaModeColor.
	colorAlpha = componentAlphaModeAlpha.
	mask = sourceWord.
	dst.A =  colorAlpha + (1 - colorAlpha) * dst.A
      dst.R = color.R * mask.R * colorAlpha + (1 - (mask.R * colorAlpha)) * dst.R
      dst.G = color.G * mask.G * colorAlpha + (1 - (mask.G* colorAlpha)) * dst.G
      dst.B = color.B * mask.B * colorAlpha + (1 - (mask.B* colorAlpha)) * dst.B
	 */
/*	Do NOT inline this into optimized loops */

function rgbComponentAlpha32with(sourceWord, destinationWord) {
	var g;
	var srcColor;
	var aG;
	var d;
	var a;
	var aA;
	var aR;
	var dstMask;
	var srcAlpha;
	var r;
	var b;
	var aB;
	var alpha;
	var answer;
	var s;

	alpha = sourceWord;
	if (alpha === 0) {
		return destinationWord;
	}
	srcColor = componentAlphaModeColor;
	srcAlpha = componentAlphaModeAlpha & 255;
	aB = alpha & 255;
	alpha = alpha >>> 8;
	aG = alpha & 255;
	alpha = alpha >>> 8;
	aR = alpha & 255;
	alpha = alpha >>> 8;
	aA = alpha & 255;
	if (srcAlpha !== 255) {
		aA = (aA * srcAlpha) >>> 8;
		aR = (aR * srcAlpha) >>> 8;
		aG = (aG * srcAlpha) >>> 8;
		aB = (aB * srcAlpha) >>> 8;
	}
	dstMask = destinationWord;
	d = dstMask & 255;
	s = srcColor & 255;
	if (!!ungammaLookupTable) {
		d = ungammaLookupTable[d];
		s = ungammaLookupTable[s];
	}
	b = ((d * (255 - aB)) >>> 8) + ((s * aB) >>> 8);
	if (b > 255) {
		b = 255;
	}
	if (!!gammaLookupTable) {
		b = gammaLookupTable[b];
	}
	dstMask = dstMask >>> 8;
	srcColor = srcColor >>> 8;
	d = dstMask & 255;
	s = srcColor & 255;
	if (!!ungammaLookupTable) {
		d = ungammaLookupTable[d];
		s = ungammaLookupTable[s];
	}
	g = ((d * (255 - aG)) >>> 8) + ((s * aG) >>> 8);
	if (g > 255) {
		g = 255;
	}
	if (!!gammaLookupTable) {
		g = gammaLookupTable[g];
	}
	dstMask = dstMask >>> 8;
	srcColor = srcColor >>> 8;
	d = dstMask & 255;
	s = srcColor & 255;
	if (!!ungammaLookupTable) {
		d = ungammaLookupTable[d];
		s = ungammaLookupTable[s];
	}
	r = ((d * (255 - aR)) >>> 8) + ((s * aR) >>> 8);
	if (r > 255) {
		r = 255;
	}
	if (!!gammaLookupTable) {
		r = gammaLookupTable[r];
	}
	dstMask = dstMask >>> 8;
	srcColor = srcColor >>> 8;

	/* no need to gamma correct alpha value ? */

	a = (((dstMask & 255) * (255 - aA)) >>> 8) + aA;
	if (a > 255) {
		a = 255;
	}
	answer = (((((a << 8) + r) << 8) + g) << 8) + b;
	return answer;
}


/*	This version assumes 
		combinationRule = 41
		sourcePixSize = 32
		destPixSize = 8
		sourceForm ~= destForm.
	Note: This is not real blending since we don't have the source colors available.
	 */

function rgbComponentAlpha8() {
	var srcShift;
	var sourceWord;
	var srcIndex;
	var deltaX;
	var mappingTable;
	var dstIndex;
	var adjust;
	var mapperFlags;
	var srcAlpha;
	var dstMask;
	var deltaY;
	var srcY;
	var destWord;
	var dstY;


	/* This particular method should be optimized in itself */

	mappingTable = default8To32Table();
	mapperFlags = cmFlags & ~ColorMapNewStyle;

	/* So we can pre-decrement */

	deltaY = bbH + 1;
	srcY = sy;
	dstY = dy;
	mask1 = (dx & 3) * 8;
	if (destMSB) {
		mask1 = 24 - mask1;
	}
	mask2 = AllOnes ^ (SHL(255, mask1));
	if ((dx & 1) === 0) {
		adjust = 0;
	} else {
		adjust = 522133279;
	}
	if ((dy & 1) === 0) {
		adjust = adjust ^ 522133279;
	}
	while (((--deltaY)) !== 0) {
		adjust = adjust ^ 522133279;
		srcIndex = ((srcY * sourcePitch)) + (sx * 4);
		dstIndex = ((dstY * destPitch)) + ((dx >> 2) * 4);

		/* So we can pre-decrement */

		deltaX = bbW + 1;
		srcShift = mask1;

		/* This is the inner loop */

		dstMask = mask2;
		while (((--deltaX)) !== 0) {
			sourceWord = (sourceBits[srcIndex >>> 2] & ~adjust) + adjust;

			/* set srcAlpha to the average of the 3 separate aR,Ag,AB values */

			srcAlpha = sourceWord & 16777215;
			srcAlpha = DIV((((srcAlpha >>> 16) + ((srcAlpha >>> 8) & 255)) + (srcAlpha & 255)), 3);
			if (srcAlpha > 31) {

				/* Everything below 31 is transparent */

				if (srcAlpha > 224) {

					/* treat everything above 224 as opaque */

					sourceWord = 4294967295;
				}
				destWord = destBits[dstIndex >>> 2];
				destWord = destWord & ~dstMask;
				destWord = SHR(destWord, srcShift);
				destWord = mappingTable[destWord];
				sourceWord = rgbComponentAlpha32with(sourceWord, destWord);
				sourceWord = mapPixelflags(sourceWord, mapperFlags);

				/* Store back */

				sourceWord = SHL(sourceWord, srcShift);
				dstLongAtputmask(dstIndex, sourceWord, dstMask);
			}
			srcIndex += 4;
			if (destMSB) {
				if (srcShift === 0) {
					dstIndex += 4;
					srcShift = 24;
					dstMask = 16777215;
				} else {
					srcShift -= 8;
					dstMask = (dstMask >>> 8) | 4278190080;
				}
			} else {
				if (srcShift === 32) {
					dstIndex += 4;
					srcShift = 0;
					dstMask = 4294967040;
				} else {
					srcShift += 8;
					dstMask = (dstMask << 8) | 255;
				}
			}
			adjust = adjust ^ 522133279;
		}
		++srcY;
		++dstY;
	}
}


/*	
	componentAlphaModeColor is the color,
	sourceWord contains an alpha value for each component of RGB
	each of which is encoded as0 meaning 0.0 and 255 meaning 1.0 .
	the rule is...
	
	color = componentAlphaModeColor.
	colorAlpha = componentAlphaModeAlpha.
	mask = sourceWord.
	dst.A =  colorAlpha + (1 - colorAlpha) * dst.A
      dst.R = color.R * mask.R * colorAlpha + (1 - (mask.R * colorAlpha)) * dst.R
      dst.G = color.G * mask.G * colorAlpha + (1 - (mask.G* colorAlpha)) * dst.G
      dst.B = color.B * mask.B * colorAlpha + (1 - (mask.B* colorAlpha)) * dst.B
	 */
/*	Do NOT inline this into optimized loops */

function rgbComponentAlphawith(sourceWord, destinationWord) {
	var alpha;

	alpha = sourceWord;
	if (alpha === 0) {
		return destinationWord;
	}
	return partitionedRgbComponentAlphadestnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
}


/*	Subract the pixels in the source and destination, color by color,
	and return the sum of the absolute value of all the differences.
	For non-rgb, return the number of differing pixels. */

function rgbDiffwith(sourceWord, destinationWord) {
	var sourcePixVal;
	var bitsPerColor;
	var diff;
	var sourceShifted;
	var pixMask;
	var rgbMask;
	var destShifted;
	var i;
	var maskShifted;
	var destPixVal;

	pixMask = maskTable[destDepth];
	if (destDepth === 16) {
		bitsPerColor = 5;
		rgbMask = 31;
	} else {
		bitsPerColor = 8;
		rgbMask = 255;
	}
	maskShifted = destMask;
	destShifted = destinationWord;
	sourceShifted = sourceWord;
	for (i = 1; i <= destPPW; i++) {
		if ((maskShifted & pixMask) > 0) {

			/* Only tally pixels within the destination rectangle */

			destPixVal = destShifted & pixMask;
			sourcePixVal = sourceShifted & pixMask;
			if (destDepth < 16) {
				if (sourcePixVal === destPixVal) {
					diff = 0;
				} else {
					diff = 1;
				}
			} else {
				diff = partitionedSubfromnBitsnPartitions(sourcePixVal, destPixVal, bitsPerColor, 3);
				diff = ((diff & rgbMask) + ((SHR(diff, bitsPerColor)) & rgbMask)) + ((SHR((SHR(diff, bitsPerColor)), bitsPerColor)) & rgbMask);
			}
			bitCount += diff;
		}
		maskShifted = SHR(maskShifted, destDepth);
		sourceShifted = SHR(sourceShifted, destDepth);
		destShifted = SHR(destShifted, destDepth);
	}
	return destinationWord;
}


/*	Convert the given 16bit pixel value to a 32bit RGBA value.
 	Note: This method is intended to deal with different source formats. */

function rgbMap16To32(sourcePixel) {
	return (((sourcePixel & 31) << 3) | ((sourcePixel & 992) << 6)) | ((sourcePixel & 31744) << 9);
}


/*	Convert the given 32bit pixel value to a 32bit RGBA value.
 	Note: This method is intended to deal with different source formats. */

function rgbMap32To32(sourcePixel) {
	return sourcePixel;
}


/*	Convert the given pixel value with nBitsIn bits for each color component to a pixel value with nBitsOut bits for each color component. Typical values for nBitsIn/nBitsOut are 3, 5, or 8. */

function rgbMapfromto(sourcePixel, nBitsIn, nBitsOut) {
	var d;
	var destPix;
	var srcPix;
	var mask;

	if (((d = nBitsOut - nBitsIn)) > 0) {

		/* Expand to more bits by zero-fill */


		/* Transfer mask */

		mask = (SHL(1, nBitsIn)) - 1;
		srcPix = SHL(sourcePixel, d);
		mask = SHL(mask, d);
		destPix = srcPix & mask;
		mask = SHL(mask, nBitsOut);
		srcPix = SHL(srcPix, d);
		return (destPix + (srcPix & mask)) + ((SHL(srcPix, d)) & (SHL(mask, nBitsOut)));
	} else {

		/* Compress to fewer bits by truncation */

		if (d === 0) {
			if (nBitsIn === 5) {

				/* Sometimes called with 16 bits, though pixel is 15,
					but we must never return more than 15. */

				return sourcePixel & 32767;
			}
			if (nBitsIn === 8) {

				/* Sometimes called with 32 bits, though pixel is 24,
					but we must never return more than 24. */

				return sourcePixel & 16777215;
			}
			return sourcePixel;
		}
		if (sourcePixel === 0) {
			return sourcePixel;
		}
		d = nBitsIn - nBitsOut;

		/* Transfer mask */

		mask = (SHL(1, nBitsOut)) - 1;
		srcPix = SHR(sourcePixel, d);
		destPix = srcPix & mask;
		mask = SHL(mask, nBitsOut);
		srcPix = SHR(srcPix, d);
		destPix = (destPix + (srcPix & mask)) + ((SHR(srcPix, d)) & (SHL(mask, nBitsOut)));
		if (destPix === 0) {
			return 1;
		}
		return destPix;
	}
}


/*	Perform the RGBA conversion for the given source pixel */

function rgbMapPixelflags(sourcePixel, mapperFlags) {
	var val;

	val = SHIFT((sourcePixel & cmMaskTable[0]), cmShiftTable[0]);
	val = val | (SHIFT((sourcePixel & cmMaskTable[1]), cmShiftTable[1]));
	val = val | (SHIFT((sourcePixel & cmMaskTable[2]), cmShiftTable[2]));
	return val | (SHIFT((sourcePixel & cmMaskTable[3]), cmShiftTable[3]));
}

function rgbMaxwith(sourceWord, destinationWord) {
	if (destDepth < 16) {

		/* Max each pixel separately */

		return partitionedMaxwithnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
	}
	if (destDepth === 16) {

		/* Max RGB components of each pixel separately */

		return partitionedMaxwithnBitsnPartitions(sourceWord, destinationWord, 5, 3) + (partitionedMaxwithnBitsnPartitions(sourceWord >>> 16, destinationWord >>> 16, 5, 3) << 16);
	} else {

		/* Max RGBA components of the pixel separately */

		return partitionedMaxwithnBitsnPartitions(sourceWord, destinationWord, 8, 4);
	}
}

function rgbMinwith(sourceWord, destinationWord) {
	if (destDepth < 16) {

		/* Min each pixel separately */

		return partitionedMinwithnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
	}
	if (destDepth === 16) {

		/* Min RGB components of each pixel separately */

		return partitionedMinwithnBitsnPartitions(sourceWord, destinationWord, 5, 3) + (partitionedMinwithnBitsnPartitions(sourceWord >>> 16, destinationWord >>> 16, 5, 3) << 16);
	} else {

		/* Min RGBA components of the pixel separately */

		return partitionedMinwithnBitsnPartitions(sourceWord, destinationWord, 8, 4);
	}
}

function rgbMinInvertwith(wordToInvert, destinationWord) {
	var sourceWord;

	sourceWord = ~wordToInvert;
	if (destDepth < 16) {

		/* Min each pixel separately */

		return partitionedMinwithnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
	}
	if (destDepth === 16) {

		/* Min RGB components of each pixel separately */

		return partitionedMinwithnBitsnPartitions(sourceWord, destinationWord, 5, 3) + (partitionedMinwithnBitsnPartitions(sourceWord >>> 16, destinationWord >>> 16, 5, 3) << 16);
	} else {

		/* Min RGBA components of the pixel separately */

		return partitionedMinwithnBitsnPartitions(sourceWord, destinationWord, 8, 4);
	}
}

function rgbMulwith(sourceWord, destinationWord) {
	if (destDepth < 16) {

		/* Mul each pixel separately */

		return partitionedMulwithnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
	}
	if (destDepth === 16) {

		/* Mul RGB components of each pixel separately */

		return partitionedMulwithnBitsnPartitions(sourceWord, destinationWord, 5, 3) + (partitionedMulwithnBitsnPartitions(sourceWord >>> 16, destinationWord >>> 16, 5, 3) << 16);
	} else {

		/* Mul RGBA components of the pixel separately */

		return partitionedMulwithnBitsnPartitions(sourceWord, destinationWord, 8, 4);
	}
}

function rgbSubwith(sourceWord, destinationWord) {
	if (destDepth < 16) {

		/* Sub each pixel separately */

		return partitionedSubfromnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
	}
	if (destDepth === 16) {

		/* Sub RGB components of each pixel separately */

		return partitionedSubfromnBitsnPartitions(sourceWord, destinationWord, 5, 3) + (partitionedSubfromnBitsnPartitions(sourceWord >>> 16, destinationWord >>> 16, 5, 3) << 16);
	} else {

		/* Sub RGBA components of the pixel separately */

		return partitionedSubfromnBitsnPartitions(sourceWord, destinationWord, 8, 4);
	}
}


/*	Note: This is coded so that is can be run from Squeak. */

function setInterpreter(anInterpreter) {
	var ok;

	interpreterProxy = anInterpreter;
	ok = interpreterProxy.majorVersion() == VM_PROXY_MAJOR;
	if (ok === false) {
		return false;
	}
	ok = interpreterProxy.minorVersion() >= VM_PROXY_MINOR;
	return ok;
}


/*	WARNING: For WarpBlt w/ smoothing the source depth is wrong here! */

function setupColorMasks() {
	var bits;
	var targetBits;

	bits = (targetBits = 0);
	if (sourceDepth <= 8) {
		return null;
	}
	if (sourceDepth === 16) {
		bits = 5;
	}
	if (sourceDepth === 32) {
		bits = 8;
	}
	if (cmBitsPerColor === 0) {

		/* Convert to destDepth */

		if (destDepth <= 8) {
			return null;
		}
		if (destDepth === 16) {
			targetBits = 5;
		}
		if (destDepth === 32) {
			targetBits = 8;
		}
	} else {
		targetBits = cmBitsPerColor;
	}
	setupColorMasksFromto(bits, targetBits);
}


/*	Setup color masks for converting an incoming RGB pixel value from srcBits to targetBits. */

function setupColorMasksFromto(srcBits, targetBits) {
	var shifts = [0, 0, 0, 0];
	var masks = [0, 0, 0, 0];
	var deltaBits;
	var mask;

	;
	deltaBits = targetBits - srcBits;
	if (deltaBits === 0) {
		return 0;
	}
	if (deltaBits <= 0) {

		/* Mask for extracting a color part of the source */

		mask = (SHL(1, targetBits)) - 1;
		masks[RedIndex] = (SHL(mask, ((srcBits * 2) - deltaBits)));
		masks[GreenIndex] = (SHL(mask, (srcBits - deltaBits)));
		masks[BlueIndex] = (SHL(mask, (0 - deltaBits)));
		masks[AlphaIndex] = 0;
	} else {

		/* Mask for extracting a color part of the source */

		mask = (SHL(1, srcBits)) - 1;
		masks[RedIndex] = (SHL(mask, (srcBits * 2)));
		masks[GreenIndex] = (SHL(mask, srcBits));
		masks[BlueIndex] = mask;
	}
	shifts[RedIndex] = (deltaBits * 3);
	shifts[GreenIndex] = (deltaBits * 2);
	shifts[BlueIndex] = deltaBits;
	shifts[AlphaIndex] = 0;
	cmShiftTable = shifts;
	cmMaskTable = masks;
	cmFlags = cmFlags | (ColorMapPresent | ColorMapFixedPart);
}

function showDisplayBits() {
	interpreterProxy.showDisplayBitsLeftTopRightBottom(destForm, affectedL, affectedT, affectedR, affectedB);
}


/*	This is only used when source and dest are same depth,
	ie, when the barrel-shift copy loop is used. */

function sourceSkewAndPointerInit() {
	var dxLowBits;
	var sxLowBits;
	var dWid;
	var pixPerM1;


	/* A mask, assuming power of two */

	pixPerM1 = destPPW - 1;
	sxLowBits = sx & pixPerM1;

	/* check if need to preload buffer
	(i.e., two words of source needed for first word of destination) */

	dxLowBits = dx & pixPerM1;
	if (hDir > 0) {

		/* n Bits stored in 1st word of dest */

		dWid = Math.min(bbW, (destPPW - dxLowBits));
		preload = (sxLowBits + dWid) > pixPerM1;
	} else {
		dWid = Math.min(bbW, (dxLowBits + 1));
		preload = ((sxLowBits - dWid) + 1) < 0;
	}
	if (sourceMSB) {
		skew = (sxLowBits - dxLowBits) * destDepth;
	} else {
		skew = (dxLowBits - sxLowBits) * destDepth;
	}
	if (preload) {
		if (skew < 0) {
			skew += 32;
		} else {
			skew -= 32;
		}
	}

	/* calculate increments from end of 1 line to start of next */

	sourceIndex = ((sy * sourcePitch)) + ((DIV(sx, (DIV(32, sourceDepth)))) * 4);
	sourceDelta = (sourcePitch * vDir) - (4 * (nWords * hDir));
	if (preload) {

		/* Compensate for extra source word fetched */

		sourceDelta -= 4 * hDir;
	}
}

function sourceWordwith(sourceWord, destinationWord) {
	return sourceWord;
}

function subWordwith(sourceWord, destinationWord) {
	return sourceWord - destinationWord;
}


/*	Tally pixels into the color map.  Those tallied are exactly those
	in the destination rectangle.  Note that the source should be 
	specified == destination, in order for the proper color map checks 
	to be performed at setup. */

function tallyIntoMapwith(sourceWord, destinationWord) {
	var pixMask;
	var mapIndex;
	var destShifted;
	var i;
	var maskShifted;
	var pixVal;

	if ((cmFlags & (ColorMapPresent | ColorMapIndexedPart)) !== (ColorMapPresent | ColorMapIndexedPart)) {
		return destinationWord;
	}
	pixMask = maskTable[destDepth];
	destShifted = destinationWord;
	maskShifted = destMask;
	for (i = 1; i <= destPPW; i++) {
		if ((maskShifted & pixMask) !== 0) {

			/* Only tally pixels within the destination rectangle */

			pixVal = destShifted & pixMask;
			if (destDepth < 16) {
				mapIndex = pixVal;
			} else {
				if (destDepth === 16) {
					mapIndex = rgbMapfromto(pixVal, 5, cmBitsPerColor);
				} else {
					mapIndex = rgbMapfromto(pixVal, 8, cmBitsPerColor);
				}
			}
			tallyMapAtput(mapIndex, tallyMapAt(mapIndex) + 1);
		}
		maskShifted = SHR(maskShifted, destDepth);
		destShifted = SHR(destShifted, destDepth);
	}
	return destinationWord;
}


/*	Return the word at position idx from the colorMap */

function tallyMapAt(idx) {
	return cmLookupTable[idx & cmMask];
}


/*	Store the word at position idx in the colorMap */

function tallyMapAtput(idx, value) {
	return cmLookupTable[idx & cmMask] = value;
}


/*	Shortcut for stuff that's being run from the balloon engine.
	Since we do this at each scan line we should avoid the expensive 
	setup for source and destination. */
/*	We need a source. */

function tryCopyingBitsQuickly() {
	if (noSource) {
		return false;
	}
	if (!((combinationRule === 34) || (combinationRule === 41))) {
		return false;
	}
	if (sourceDepth !== 32) {
		return false;
	}
	if (sourceForm === destForm) {
		return false;
	}
	if (combinationRule === 41) {
		if (destDepth === 32) {
			rgbComponentAlpha32();
			affectedL = dx;
			affectedR = dx + bbW;
			affectedT = dy;
			affectedB = dy + bbH;
			return true;
		}
		if (destDepth === 16) {
			rgbComponentAlpha16();
			affectedL = dx;
			affectedR = dx + bbW;
			affectedT = dy;
			affectedB = dy + bbH;
			return true;
		}
		if (destDepth === 8) {
			rgbComponentAlpha8();
			affectedL = dx;
			affectedR = dx + bbW;
			affectedT = dy;
			affectedB = dy + bbH;
			return true;
		}
		return false;
	}
	if (destDepth < 8) {
		return false;
	}
	if ((destDepth === 8) && ((cmFlags & ColorMapPresent) === 0)) {
		return false;
	}
	if (destDepth === 32) {
		alphaSourceBlendBits32();
	}
	if (destDepth === 16) {
		alphaSourceBlendBits16();
	}
	if (destDepth === 8) {
		alphaSourceBlendBits8();
	}
	affectedL = dx;
	affectedR = dx + bbW;
	affectedT = dy;
	affectedB = dy + bbH;
	return true;
}


/*	Unlock the bits of any OS surfaces. */
/*	See the comment in lockSurfaces. Similar rules apply. That is, the area provided in ioUnlockSurface can be used to determine the dirty region after drawing. If a source is unlocked, then the area will be (0,0,0,0) to indicate that no portion is dirty. */

function unlockSurfaces() {
	var destHandle;
	var sourceHandle;
	var fn;
	var destLocked;

	if (hasSurfaceLock) {
		if (!unlockSurfaceFn) {
			if (!loadSurfacePlugin()) {
				return null;
			}
		}
		fn = unlockSurfaceFn;
		destLocked = false;
		destHandle = interpreterProxy.fetchPointerofObject(FormBitsIndex, destForm);
		if (typeof destHandle === "number") {

			/* The destBits are always assumed to be dirty */

			destHandle = destHandle;
			fn(destHandle, affectedL, affectedT, affectedR-affectedL, affectedB-affectedT);
			destBits = (destPitch = 0);
			destLocked = true;
		}
		if (!noSource) {
			sourceHandle = interpreterProxy.fetchPointerofObject(FormBitsIndex, sourceForm);
			if (typeof sourceHandle === "number") {

				/* Only unlock sourceHandle if different from destHandle */

				sourceHandle = sourceHandle;
				if (!(destLocked && (sourceHandle === destHandle))) {
					fn(sourceHandle, 0, 0, 0, 0);
				}
				sourceBits = (sourcePitch = 0);
			}
		}
		hasSurfaceLock = false;
	}
}

function warpBits() {
	var ns;

	ns = noSource;
	noSource = true;
	clipRange();
	noSource = ns;
	if (noSource || ((bbW <= 0) || (bbH <= 0))) {

		/* zero width or height; noop */

		affectedL = (affectedR = (affectedT = (affectedB = 0)));
		return null;
	}
	if (!lockSurfaces()) {
		return interpreterProxy.primitiveFail();
	}
	destMaskAndPointerInit();
	warpLoop();
	if (hDir > 0) {
		affectedL = dx;
		affectedR = dx + bbW;
	} else {
		affectedL = (dx - bbW) + 1;
		affectedR = dx + 1;
	}
	if (vDir > 0) {
		affectedT = dy;
		affectedB = dy + bbH;
	} else {
		affectedT = (dy - bbH) + 1;
		affectedB = dy + 1;
	}
	unlockSurfaces();
}


/*	This version of the inner loop traverses an arbirary quadrilateral
	source, thus producing a general affine transformation. */

function warpLoop() {
	var mapperFlags;
	var dstShiftLeft;
	var words;
	var skewWord;
	var nSteps;
	var deltaP43y;
	var destWord;
	var startBits;
	var mergeFnwith;
	var deltaP43x;
	var pBy;
	var i;
	var yDelta;
	var halftoneWord;
	var mergeWord;
	var pAy;
	var dstShiftInc;
	var pBx;
	var sourceMapOop;
	var xDelta;
	var pAx;
	var deltaP12y;
	var endBits;
	var nPix;
	var deltaP12x;
	var smoothingCount;

	mergeFnwith = opTable[combinationRule + 1];
	mergeFnwith;
	if (!(SIZEOF(bitBltOop) >= (BBWarpBase + 12))) {
		return interpreterProxy.primitiveFail();
	}
	nSteps = height - 1;
	if (nSteps <= 0) {
		nSteps = 1;
	}
	pAx = fetchIntOrFloatofObject(BBWarpBase, bitBltOop);
	words = fetchIntOrFloatofObject(BBWarpBase + 3, bitBltOop);
	deltaP12x = deltaFromtonSteps(pAx, words, nSteps);
	if (deltaP12x < 0) {
		pAx = words - (nSteps * deltaP12x);
	}
	pAy = fetchIntOrFloatofObject(BBWarpBase + 1, bitBltOop);
	words = fetchIntOrFloatofObject(BBWarpBase + 4, bitBltOop);
	deltaP12y = deltaFromtonSteps(pAy, words, nSteps);
	if (deltaP12y < 0) {
		pAy = words - (nSteps * deltaP12y);
	}
	pBx = fetchIntOrFloatofObject(BBWarpBase + 9, bitBltOop);
	words = fetchIntOrFloatofObject(BBWarpBase + 6, bitBltOop);
	deltaP43x = deltaFromtonSteps(pBx, words, nSteps);
	if (deltaP43x < 0) {
		pBx = words - (nSteps * deltaP43x);
	}
	pBy = fetchIntOrFloatofObject(BBWarpBase + 10, bitBltOop);
	words = fetchIntOrFloatofObject(BBWarpBase + 7, bitBltOop);
	deltaP43y = deltaFromtonSteps(pBy, words, nSteps);
	if (deltaP43y < 0) {
		pBy = words - (nSteps * deltaP43y);
	}
	if (interpreterProxy.failed()) {
		return false;
	}
	if (interpreterProxy.methodArgumentCount() === 2) {
		smoothingCount = interpreterProxy.stackIntegerValue(1);
		sourceMapOop = interpreterProxy.stackValue(0);
		if (sourceMapOop.isNil) {
			if (sourceDepth < 16) {

				/* color map is required to smooth non-RGB dest */

				return interpreterProxy.primitiveFail();
			}
		} else {
			if (SIZEOF(sourceMapOop) < (SHL(1, sourceDepth))) {

				/* sourceMap must be long enough for sourceDepth */

				return interpreterProxy.primitiveFail();
			}
			sourceMapOop = sourceMapOop.wordsOrBytes();
		}
	} else {
		smoothingCount = 1;
		sourceMapOop = interpreterProxy.nilObject();
	}
	nSteps = width - 1;
	if (nSteps <= 0) {
		nSteps = 1;
	}
	startBits = destPPW - (dx & (destPPW - 1));
	endBits = (((dx + bbW) - 1) & (destPPW - 1)) + 1;
	if (bbW < startBits) {
		startBits = bbW;
	}
	if (destY < clipY) {

		/* Advance increments if there was clipping in y */

		pAx += (clipY - destY) * deltaP12x;
		pAy += (clipY - destY) * deltaP12y;
		pBx += (clipY - destY) * deltaP43x;
		pBy += (clipY - destY) * deltaP43y;
	}
	warpLoopSetup();
	if ((smoothingCount > 1) && ((cmFlags & ColorMapNewStyle) === 0)) {
		if (!cmLookupTable) {
			if (destDepth === 16) {
				setupColorMasksFromto(8, 5);
			}
		} else {
			setupColorMasksFromto(8, cmBitsPerColor);
		}
	}
	mapperFlags = cmFlags & ~ColorMapNewStyle;
	if (destMSB) {
		dstShiftInc = 0 - destDepth;
		dstShiftLeft = 32 - destDepth;
	} else {
		dstShiftInc = destDepth;
		dstShiftLeft = 0;
	}
	for (i = 1; i <= bbH; i++) {

		/* here is the vertical loop... */

		xDelta = deltaFromtonSteps(pAx, pBx, nSteps);
		if (xDelta >= 0) {
			sx = pAx;
		} else {
			sx = pBx - (nSteps * xDelta);
		}
		yDelta = deltaFromtonSteps(pAy, pBy, nSteps);
		if (yDelta >= 0) {
			sy = pAy;
		} else {
			sy = pBy - (nSteps * yDelta);
		}
		if (destMSB) {
			dstBitShift = 32 - (((dx & (destPPW - 1)) + 1) * destDepth);
		} else {
			dstBitShift = (dx & (destPPW - 1)) * destDepth;
		}
		if (destX < clipX) {

			/* Advance increments if there was clipping in x */

			sx += (clipX - destX) * xDelta;
			sy += (clipX - destX) * yDelta;
		}
		if (noHalftone) {
			halftoneWord = AllOnes;
		} else {
			halftoneWord = halftoneAt((dy + i) - 1);
		}
		destMask = mask1;

		/* Here is the inner loop... */

		nPix = startBits;
		words = nWords;
		do {

			/* pick up word */

			if (smoothingCount === 1) {

				/* Faster if not smoothing */

				skewWord = warpPickSourcePixelsxDeltahyDeltahxDeltavyDeltavdstShiftIncflags(nPix, xDelta, yDelta, deltaP12x, deltaP12y, dstShiftInc, mapperFlags);
			} else {

				/* more difficult with smoothing */

				skewWord = warpPickSmoothPixelsxDeltahyDeltahxDeltavyDeltavsourceMapsmoothingdstShiftInc(nPix, xDelta, yDelta, deltaP12x, deltaP12y, sourceMapOop, smoothingCount, dstShiftInc);
			}
			dstBitShift = dstShiftLeft;
			if (destMask === AllOnes) {

				/* avoid read-modify-write */

				mergeWord = mergeFnwith(skewWord & halftoneWord, destBits[destIndex >>> 2]);
				destBits[destIndex >>> 2] = destMask & mergeWord;
			} else {

				/* General version using dest masking */

				destWord = destBits[destIndex >>> 2];
				mergeWord = mergeFnwith(skewWord & halftoneWord, destWord & destMask);
				destWord = (destMask & mergeWord) | (destWord & ~destMask);
				destBits[destIndex >>> 2] = destWord;
			}
			destIndex += 4;
			if (words === 2) {

				/* e.g., is the next word the last word? */
				/* set mask for last word in this row */

				destMask = mask2;
				nPix = endBits;
			} else {

				/* use fullword mask for inner loop */

				destMask = AllOnes;
				nPix = destPPW;
			}
		} while(!(((--words)) === 0));
		pAx += deltaP12x;
		pAy += deltaP12y;
		pBx += deltaP43x;
		pBy += deltaP43y;
		destIndex += destDelta;
	}
}


/*	Setup values for faster pixel fetching. */

function warpLoopSetup() {
	var i;
	var words;


	/* warpSrcShift = log2(sourceDepth) */

	warpSrcShift = 0;

	/* recycle temp */

	words = sourceDepth;
	while (!(words === 1)) {
		++warpSrcShift;
		words = words >>> 1;
	}

	/* warpAlignShift: Shift for aligning x position to word boundary */

	warpSrcMask = maskTable[sourceDepth];

	/* warpAlignMask: Mask for extracting the pixel position from an x position */

	warpAlignShift = 5 - warpSrcShift;

	/* Setup the lookup table for source bit shifts */
	/* warpBitShiftTable: given an sub-word x value what's the bit shift? */

	warpAlignMask = (SHL(1, warpAlignShift)) - 1;
	for (i = 0; i <= warpAlignMask; i++) {
		if (sourceMSB) {
			warpBitShiftTable[i] = (32 - (SHL((i + 1), warpSrcShift)));
		} else {
			warpBitShiftTable[i] = (SHL(i, warpSrcShift));
		}
	}
}


/*	Pick n (sub-) pixels from the source form, mapped by sourceMap,
	average the RGB values, map by colorMap and return the new word.
	This version is only called from WarpBlt with smoothingCount > 1 */

function warpPickSmoothPixelsxDeltahyDeltahxDeltavyDeltavsourceMapsmoothingdstShiftInc(nPixels, xDeltah, yDeltah, xDeltav, yDeltav, sourceMap, n, dstShiftInc) {
	var k;
	var destWord;
	var xdh;
	var j;
	var ydh;
	var i;
	var xdv;
	var dstMask;
	var ydv;
	var rgb;
	var y;
	var b;
	var yy;
	var g;
	var x;
	var a;
	var r;
	var nPix;
	var xx;


	/* nope - too much stuff in here */

	dstMask = maskTable[destDepth];
	destWord = 0;
	if (n === 2) {

		/* Try avoiding divides for most common n (divide by 2 is generated as shift) */

		xdh = xDeltah >> 1;
		ydh = yDeltah >> 1;
		xdv = xDeltav >> 1;
		ydv = yDeltav >> 1;
	} else {
		xdh = DIV(xDeltah, n);
		ydh = DIV(yDeltah, n);
		xdv = DIV(xDeltav, n);
		ydv = DIV(yDeltav, n);
	}
	i = nPixels;
	do {
		x = sx;
		y = sy;

		/* Pick and average n*n subpixels */

		a = (r = (g = (b = 0)));

		/* actual number of pixels (not clipped and not transparent) */

		nPix = 0;
		j = n;
		do {
			xx = x;
			yy = y;
			k = n;
			do {

				/* get a single subpixel */

				rgb = pickWarpPixelAtXy(xx, yy);
				if (!((combinationRule === 25) && (rgb === 0))) {

					/* If not clipped and not transparent, then tally rgb values */

					++nPix;
					if (sourceDepth < 16) {

						/* Get RGBA values from sourcemap table */

						rgb = sourceMap[rgb];
					} else {

						/* Already in RGB format */

						if (sourceDepth === 16) {
							rgb = rgbMap16To32(rgb);
						} else {
							rgb = rgbMap32To32(rgb);
						}
					}
					b += rgb & 255;
					g += (rgb >>> 8) & 255;
					r += (rgb >>> 16) & 255;
					a += rgb >>> 24;
				}
				xx += xdh;
				yy += ydh;
			} while(!(((--k)) === 0));
			x += xdv;
			y += ydv;
		} while(!(((--j)) === 0));
		if ((nPix === 0) || ((combinationRule === 25) && (nPix < ((n * n) >> 1)))) {

			/* All pixels were 0, or most were transparent */

			rgb = 0;
		} else {

			/* normalize rgba sums */

			if (nPix === 4) {

				/* Try to avoid divides for most common n */

				r = r >>> 2;
				g = g >>> 2;
				b = b >>> 2;
				a = a >>> 2;
			} else {
				r = DIV(r, nPix);
				g = DIV(g, nPix);
				b = DIV(b, nPix);
				a = DIV(a, nPix);
			}

			/* map the pixel */

			rgb = (((a << 24) + (r << 16)) + (g << 8)) + b;
			if (rgb === 0) {

				/* only generate zero if pixel is really transparent */

				if ((((r + g) + b) + a) > 0) {
					rgb = 1;
				}
			}
			rgb = mapPixelflags(rgb, cmFlags);
		}
		destWord = destWord | (SHL((rgb & dstMask), dstBitShift));
		dstBitShift += dstShiftInc;
		sx += xDeltah;
		sy += yDeltah;
	} while(!(((--i)) === 0));
	return destWord;
}


/*	Pick n pixels from the source form,
	map by colorMap and return aligned by dstBitShift.
	This version is only called from WarpBlt with smoothingCount = 1 */

function warpPickSourcePixelsxDeltahyDeltahxDeltavyDeltavdstShiftIncflags(nPixels, xDeltah, yDeltah, xDeltav, yDeltav, dstShiftInc, mapperFlags) {
	var sourcePix;
	var nPix;
	var destPix;
	var dstMask;
	var destWord;


	/* Yepp - this should go into warpLoop */

	dstMask = maskTable[destDepth];
	destWord = 0;
	nPix = nPixels;
	if (mapperFlags === (ColorMapPresent | ColorMapIndexedPart)) {

		/* a little optimization for (pretty crucial) blits using indexed lookups only */
		/* grab, colormap and mix in pixel */

		do {
			sourcePix = pickWarpPixelAtXy(sx, sy);
			destPix = cmLookupTable[sourcePix & cmMask];
			destWord = destWord | (SHL((destPix & dstMask), dstBitShift));
			dstBitShift += dstShiftInc;
			sx += xDeltah;
			sy += yDeltah;
		} while(!(((--nPix)) === 0));
	} else {

		/* grab, colormap and mix in pixel */

		do {
			sourcePix = pickWarpPixelAtXy(sx, sy);
			destPix = mapPixelflags(sourcePix, mapperFlags);
			destWord = destWord | (SHL((destPix & dstMask), dstBitShift));
			dstBitShift += dstShiftInc;
			sx += xDeltah;
			sy += yDeltah;
		} while(!(((--nPix)) === 0));
	}
	return destWord;
}


function registerPlugin() {
	if (typeof Squeak === "object" && Squeak.registerExternalModule) {
		Squeak.registerExternalModule("BitBltPlugin", {
			primitiveCopyBits: primitiveCopyBits,
			copyBits: copyBits,
			moduleUnloaded: moduleUnloaded,
			primitiveDrawLoop: primitiveDrawLoop,
			primitiveDisplayString: primitiveDisplayString,
			initialiseModule: initialiseModule,
			loadBitBltFrom: loadBitBltFrom,
			setInterpreter: setInterpreter,
			primitiveWarpBits: primitiveWarpBits,
			getModuleName: getModuleName,
			primitivePixelValueAt: primitivePixelValueAt,
			copyBitsFromtoat: copyBitsFromtoat,
		});
	} else self.setTimeout(registerPlugin, 100);
}

registerPlugin();

})(); // Register module/plugin