-
Notifications
You must be signed in to change notification settings - Fork 64
/
BitBltPlugin.c
8161 lines (7358 loc) · 229 KB
/
BitBltPlugin.c
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
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.2493 uuid: d7437cc5-75c7-4a43-af6b-0f85bf0cebe6
from
BitBltSimulation VMMaker.oscog-eem.2493 uuid: d7437cc5-75c7-4a43-af6b-0f85bf0cebe6
*/
static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.2493 uuid: d7437cc5-75c7-4a43-af6b-0f85bf0cebe6 " __DATE__ ;
#include "config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Default EXPORT macro that does nothing (see comment in sq.h): */
#define EXPORT(returnType) returnType
/* Do not include the entire sq.h file but just those parts needed. */
#include "sqConfig.h" /* Configuration options */
#include "sqVirtualMachine.h" /* The virtual machine proxy definition */
#include "sqPlatformSpecific.h" /* Platform specific definitions */
#define true 1
#define false 0
#define null 0 /* using 'null' because nil is predefined in Think C */
#ifdef SQUEAK_BUILTIN_PLUGIN
# undef EXPORT
# define EXPORT(returnType) static returnType
#endif
#include "sqAssert.h"
#ifdef ENABLE_FAST_BLT
#include "BitBltDispatch.h"
#else
// to handle the unavoidable decl in the spec of copyBitsFallback();
#define operation_t void
#endif
#include "sqMemoryAccess.h"
/*** Constants ***/
#define AllOnes 0xFFFFFFFFU
#define AlphaIndex 3
#define BBClipHeightIndex 13
#define BBClipWidthIndex 12
#define BBClipXIndex 10
#define BBClipYIndex 11
#define BBColorMapIndex 14
#define BBDestFormIndex 0
#define BBDestXIndex 4
#define BBDestYIndex 5
#define BBHalftoneFormIndex 2
#define BBHeightIndex 7
#define BBRuleIndex 3
#define BBSourceFormIndex 1
#define BBSourceXIndex 8
#define BBSourceYIndex 9
#define BBWarpBase 15
#define BBWidthIndex 6
#define BEBitBltIndex 2
#define BinaryPoint 14
#define BlueIndex 2
#define ColorMapFixedPart 2
#define ColorMapIndexedPart 4
#define ColorMapNewStyle 8
#define ColorMapPresent 1
#define FixedPt1 0x4000
#define FormBitsIndex 0
#define FormDepthIndex 3
#define FormHeightIndex 2
#define FormWidthIndex 1
#define GreenIndex 1
#define OpTableSize 43
#define PrimErrBadArgument 3
#define PrimErrCallbackError 20
#define PrimErrObjectMoved 18
#define RedIndex 0
/*** Function Prototypes ***/
static unsigned int addWordwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt affectedBottom(void);
static sqInt affectedLeft(void);
static sqInt affectedRight(void);
static sqInt affectedTop(void);
static unsigned int alphaBlendConstwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int alphaBlendConstwithpaintMode(unsigned int sourceWord, unsigned int destinationWord, sqInt paintMode);
static unsigned int alphaBlendScaledwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int alphaBlendwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int alphaPaintConstwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt alphaSourceBlendBits16(void);
static sqInt alphaSourceBlendBits32(void);
static sqInt alphaSourceBlendBits8(void);
static unsigned int bitAndInvertwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitAndwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertAndInvertwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertAndwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertDestinationwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertOrInvertwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertOrwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertSourcewith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitInvertXorwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitOrInvertwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitOrwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int bitXorwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt checkSourceOverlap(void);
static unsigned int clearWordwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt clipRange(void);
EXPORT(sqInt) copyBits(void);
static sqInt copyBitsFastPathSpecialised(void);
EXPORT(sqInt) copyBitsFromtoat(sqInt startX, sqInt stopX, sqInt yValue);
static sqInt copyBitsLockedAndClipped(void);
static sqInt copyBitsRule41Test(void);
extern void copyBitsFallback(operation_t *op, unsigned int flags);
static sqInt copyLoop(void);
static sqInt copyLoopNoSource(void);
static sqInt copyLoopPixMap(void);
static unsigned int * default8To32Table(void);
static sqInt deltaFromtonSteps(sqInt x1, sqInt x2, sqInt n);
static unsigned int destinationWordwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt destMaskAndPointerInit(void);
static unsigned int dither32To16threshold(unsigned int srcWord, sqInt ditherValue);
static sqInt drawLoopXY(sqInt xDelta, sqInt yDelta);
static unsigned int expensiveDither32To16threshold(unsigned int srcWord, sqInt ditherValue);
static sqInt fetchIntOrFloatofObject(sqInt fieldIndex, sqInt objectPointer);
static sqInt fetchIntOrFloatofObjectifNil(sqInt fieldIndex, sqInt objectPointer, sqInt defaultValue);
static unsigned int fixAlphawith(unsigned int sourceWord, unsigned int destinationWord);
EXPORT(const char*) getModuleName(void);
static sqInt ignoreSourceOrHalftone(sqInt formPointer);
static sqInt initBBOpTable(void);
static sqInt initDither8Lookup(void);
EXPORT(sqInt) initialiseModule(void);
static sqInt isIdentityMapwith(int *shifts, unsigned int *masks);
static sqInt loadBitBltDestForm(void);
EXPORT(sqInt) loadBitBltFrom(sqInt bbObj);
static sqInt loadBitBltFromwarping(sqInt bbObj, sqInt aBool);
static sqInt loadBitBltSourceForm(void);
static sqInt loadColorMap(void);
static void * loadColorMapShiftOrMaskFrom(sqInt mapOop);
static sqInt loadHalftoneForm(void);
static sqInt loadSurfacePlugin(void);
static sqInt loadWarpBltFrom(sqInt bbObj);
static sqInt lockSurfaces(void);
static sqInt mapPixelflags(sqInt sourcePixel, sqInt mapperFlags);
static unsigned int mergewith(unsigned int sourceWord, unsigned int destinationWord);
EXPORT(sqInt) moduleUnloaded(char *aModuleName);
static sqInt OLDrgbDiffwith(sqInt sourceWord, sqInt destinationWord);
static sqInt OLDtallyIntoMapwith(sqInt sourceWord, sqInt destinationWord);
static unsigned int partitionedAddtonBitscomponentMaskcarryOverflowMask(unsigned int word1, unsigned int word2, sqInt nBits, unsigned int componentMask, unsigned int carryOverflowMask);
static unsigned int partitionedANDtonBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
static unsigned int partitionedMaxwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
static unsigned int partitionedMinwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
static unsigned int partitionedMulwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
static unsigned int partitionedRgbComponentAlphadestnBitsnPartitions(unsigned int sourceWord, unsigned int destWord, sqInt nBits, sqInt nParts);
static unsigned int partitionedSubfromnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
static sqInt performCopyLoop(void);
static unsigned int pickSourcePixelsflagssrcMaskdestMasksrcShiftIncdstShiftInc(sqInt nPixels, sqInt mapperFlags, sqInt srcMask, sqInt dstMask, sqInt srcShiftInc, sqInt dstShiftInc);
static unsigned int pickWarpPixelAtXy(sqInt xx, sqInt yy);
static unsigned int pixClearwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int pixMaskwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int pixPaintwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int pixSwapwith(unsigned int sourceWord, unsigned int destWord);
EXPORT(sqInt) primitiveCompareColors(void);
EXPORT(sqInt) primitiveCopyBits(void);
EXPORT(sqInt) primitiveDisplayString(void);
EXPORT(sqInt) primitiveDrawLoop(void);
EXPORT(sqInt) primitivePixelValueAt(void);
EXPORT(sqInt) primitiveWarpBits(void);
static sqInt reloadDestAndSourceForms(void);
static unsigned int rgbAddwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt rgbComponentAlpha16(void);
static sqInt rgbComponentAlpha32(void);
static sqInt rgbComponentAlpha32with(sqInt sourceWord, sqInt destinationWord);
static sqInt rgbComponentAlpha8(void);
static sqInt rgbComponentAlphawith(sqInt sourceWord, sqInt destinationWord);
static unsigned int rgbDiffwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt rgbMap16To32(sqInt sourcePixel);
static sqInt rgbMap32To32(sqInt sourcePixel);
static sqInt rgbMapPixelflags(sqInt sourcePixel, sqInt mapperFlags);
static sqInt rgbMapfromto(sqInt sourcePixel, sqInt nBitsIn, sqInt nBitsOut);
static unsigned int rgbMaxwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int rgbMinInvertwith(unsigned int wordToInvert, unsigned int destinationWord);
static unsigned int rgbMinwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int rgbMulwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int rgbSubwith(unsigned int sourceWord, unsigned int destinationWord);
EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter);
static sqInt setupColorMasks(void);
static sqInt setupColorMasksFromto(sqInt srcBits, sqInt targetBits);
static sqInt showDisplayBits(void);
static sqInt sourceSkewAndPointerInit(void);
static unsigned int sourceWordwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt sqAssert(sqInt aBool);
static unsigned int subWordwith(unsigned int sourceWord, unsigned int destinationWord);
static unsigned int tallyIntoMapwith(unsigned int sourceWord, unsigned int destinationWord);
static sqInt tryCopyingBitsQuickly(void);
static sqInt unlockSurfaces(void);
static sqInt warpBits(void);
static sqInt warpLoop(void);
static sqInt warpLoopSetup(void);
static sqInt warpPickSmoothPixelsxDeltahyDeltahxDeltavyDeltavsourceMapsmoothingdstShiftInc(sqInt nPixels, sqInt xDeltah, sqInt yDeltah, sqInt xDeltav, sqInt yDeltav, sqInt sourceMap, sqInt n, sqInt dstShiftInc);
static sqInt warpPickSourcePixelsxDeltahyDeltahxDeltavyDeltavdstShiftIncflags(sqInt nPixels, sqInt xDeltah, sqInt yDeltah, sqInt xDeltav, sqInt yDeltav, sqInt dstShiftInc, sqInt mapperFlags);
/*** Variables ***/
static sqInt affectedB;
static sqInt affectedL;
static sqInt affectedR;
static sqInt affectedT;
static int bbH;
static int bbW;
static sqInt bitBltIsReceiver;
static sqInt bitBltOop;
static sqInt bitCount;
static sqInt clipHeight;
static sqInt clipWidth;
static sqInt clipX;
static sqInt clipY;
static sqInt cmBitsPerColor;
static sqInt cmFlags;
static unsigned int * cmLookupTable;
static sqInt cmMask;
static unsigned int * cmMaskTable;
static int * cmShiftTable;
static sqInt combinationRule;
static sqInt componentAlphaModeAlpha;
static sqInt componentAlphaModeColor;
static sqInt destBits;
static sqInt destDelta;
static int destDepth;
static sqInt destForm;
static int destHeight;
static usqInt destIndex;
static sqInt destMask;
static int destMSB;
static int destPitch;
static sqInt destPPW;
static int destWidth;
static sqInt destX;
static sqInt destY;
static unsigned char dither8Lookup[4096];
static const int ditherMatrix4x4[16] = {
0, 8, 2, 10,
12, 4, 14, 6,
3, 11, 1, 9,
15, 7, 13, 5
};
static const int ditherThresholds16[8] = { 0, 2, 4, 6, 8, 12, 14, 16 };
static const int ditherValues16[32] = {
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
};
static sqInt dstBitShift;
static int dx;
static int dy;
static usqInt endOfDestination;
static usqInt endOfSource;
static unsigned char * gammaLookupTable;
static sqInt halftoneBase;
static sqInt halftoneForm;
static sqInt halftoneHeight;
static sqInt hasSurfaceLock;
static sqInt hDir;
static sqInt height;
#if !defined(SQUEAK_BUILTIN_PLUGIN)
static sqInt (*byteSizeOf)(sqInt oop);
static sqInt (*failed)(void);
static sqInt (*fetchIntegerofObject)(sqInt fieldIndex, sqInt objectPointer);
static sqInt (*fetchLong32ofObject)(sqInt fieldIndex, sqInt oop);
static sqInt (*fetchPointerofObject)(sqInt index, sqInt oop);
static void * (*firstIndexableField)(sqInt oop);
static double (*floatValueOf)(sqInt oop);
static sqInt (*integerObjectOf)(sqInt value);
static sqInt (*integerValueOf)(sqInt oop);
static void * (*ioLoadFunctionFrom)(char *functionName, char *moduleName);
static sqInt (*isArray)(sqInt oop);
static sqInt (*isBytes)(sqInt oop);
static sqInt (*isIntegerObject)(sqInt objectPointer);
static sqInt (*isPointers)(sqInt oop);
static sqInt (*isPositiveMachineIntegerObject)(sqInt oop);
static sqInt (*isWords)(sqInt oop);
static sqInt (*isWordsOrBytes)(sqInt oop);
static sqInt (*methodArgumentCount)(void);
static sqInt (*methodReturnInteger)(sqInt integer);
static sqInt (*methodReturnReceiver)(void);
static sqInt (*nilObject)(void);
static sqInt (*pop)(sqInt nItems);
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
static sqInt (*positive32BitIntegerFor)(unsigned int integerValue);
static usqInt (*positive32BitValueOf)(sqInt oop);
static usqLong (*positive64BitValueOf)(sqInt oop);
static sqInt (*primitiveFail)(void);
static sqInt (*primitiveFailFor)(sqInt reasonCode);
static sqInt (*showDisplayBitsLeftTopRightBottom)(sqInt aForm, sqInt l, sqInt t, sqInt r, sqInt b);
static sqInt (*slotSizeOf)(sqInt oop);
static sqInt (*stackIntegerValue)(sqInt offset);
static sqInt (*stackObjectValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
static sqInt (*statNumGCs)(void);
static sqInt (*storeIntegerofObjectwithValue)(sqInt index, sqInt oop, sqInt integer);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern sqInt byteSizeOf(sqInt oop);
extern sqInt failed(void);
extern sqInt fetchIntegerofObject(sqInt fieldIndex, sqInt objectPointer);
extern sqInt fetchLong32ofObject(sqInt fieldIndex, sqInt oop);
extern sqInt fetchPointerofObject(sqInt index, sqInt oop);
extern void * firstIndexableField(sqInt oop);
extern double floatValueOf(sqInt oop);
extern sqInt integerObjectOf(sqInt value);
extern sqInt integerValueOf(sqInt oop);
extern void * ioLoadFunctionFrom(char *functionName, char *moduleName);
extern sqInt isArray(sqInt oop);
extern sqInt isBytes(sqInt oop);
#if !defined(isIntegerObject)
extern sqInt isIntegerObject(sqInt objectPointer);
#endif
extern sqInt isPointers(sqInt oop);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 15)
extern sqInt isPositiveMachineIntegerObject(sqInt oop);
#else
# define isPositiveMachineIntegerObject(oop) 0
#endif
extern sqInt isWords(sqInt oop);
extern sqInt isWordsOrBytes(sqInt oop);
extern sqInt methodArgumentCount(void);
extern sqInt methodReturnInteger(sqInt integer);
extern sqInt methodReturnReceiver(void);
extern sqInt nilObject(void);
extern sqInt pop(sqInt nItems);
extern sqInt popthenPush(sqInt nItems, sqInt oop);
extern sqInt positive32BitIntegerFor(unsigned int integerValue);
extern usqInt positive32BitValueOf(sqInt oop);
extern usqLong positive64BitValueOf(sqInt oop);
extern sqInt primitiveFail(void);
extern sqInt primitiveFailFor(sqInt reasonCode);
extern sqInt showDisplayBitsLeftTopRightBottom(sqInt aForm, sqInt l, sqInt t, sqInt r, sqInt b);
extern sqInt slotSizeOf(sqInt oop);
extern sqInt stackIntegerValue(sqInt offset);
extern sqInt stackObjectValue(sqInt offset);
extern sqInt stackValue(sqInt offset);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 14)
extern sqInt statNumGCs(void);
#else
# define statNumGCs() 0
#endif
extern sqInt storeIntegerofObjectwithValue(sqInt index, sqInt oop, sqInt integer);
extern
#endif
struct VirtualMachine* interpreterProxy;
static sqInt isWarping;
static sqIntptr_t (*lockSurfaceFn)(sqIntptr_t, int*, int, int, int, int);
static sqInt mask1;
static sqInt mask2;
static int maskTable[33] = {
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
};
static const char *moduleName =
#ifdef SQUEAK_BUILTIN_PLUGIN
"BitBltPlugin VMMaker.oscog-eem.2493 (i)"
#else
"BitBltPlugin VMMaker.oscog-eem.2493 (e)"
#endif
;
static sqInt noHalftone;
static sqInt noSource;
static sqInt numGCsOnInvocation;
static sqInt nWords;
static void *opTable[43];
static sqInt preload;
static int (*querySurfaceFn)(sqIntptr_t, int*, int*, int*, int*);
static sqInt skew;
static sqInt sourceAlpha;
static sqInt sourceBits;
static sqInt sourceDelta;
static int sourceDepth;
static sqInt sourceForm;
static int sourceHeight;
static usqInt sourceIndex;
static int sourceMSB;
static int sourcePitch;
static sqInt sourcePPW;
static int sourceWidth;
static sqInt sourceX;
static sqInt sourceY;
static sqInt srcBitShift;
static int sx;
static int sy;
static unsigned char * ungammaLookupTable;
static int (*unlockSurfaceFn)(sqIntptr_t, int, int, int, int);
static sqInt vDir;
static sqInt warpAlignMask;
static sqInt warpAlignShift;
static int warpBitShiftTable[32];
static sqInt warpSrcMask;
static sqInt warpSrcShift;
static sqInt width;
/* BitBltSimulation>>#addWord:with: */
static unsigned int
addWordwith(unsigned int sourceWord, unsigned int destinationWord)
{
return sourceWord + destinationWord;
}
/* BitBltSimulation>>#affectedBottom */
static sqInt
affectedBottom(void)
{
return affectedB;
}
/* BitBltSimulation>>#affectedLeft */
static sqInt
affectedLeft(void)
{
return affectedL;
}
/* BitBltSimulation>>#affectedRight */
static sqInt
affectedRight(void)
{
return affectedR;
}
/* BitBltSimulation>>#affectedTop */
static sqInt
affectedTop(void)
{
return affectedT;
}
/* BitBltSimulation>>#alphaBlendConst:with: */
static unsigned int
alphaBlendConstwith(unsigned int sourceWord, unsigned int destinationWord)
{
return alphaBlendConstwithpaintMode(sourceWord, destinationWord, 0);
}
/* 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.
*/
/* BitBltSimulation>>#alphaBlendConst:with:paintMode: */
static unsigned int
alphaBlendConstwithpaintMode(unsigned int sourceWord, unsigned int destinationWord, sqInt paintMode)
{
sqInt bitsPerColor;
unsigned int blend;
unsigned int blendAG;
unsigned int blendRB;
unsigned int destPixVal;
unsigned int destShifted;
sqInt i;
sqInt j;
unsigned int maskShifted;
unsigned int pixBlend;
unsigned int pixMask;
unsigned int result;
unsigned int rgbMask;
sqInt shift;
unsigned int sourcePixVal;
unsigned int sourceShifted;
unsigned int unAlpha;
if (destDepth < 16) {
return destinationWord;
}
unAlpha = 0xFF - 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 = ((((((usqInt) sourceWord) >> 8) & 16711935) * sourceAlpha) + (((((usqInt) destinationWord) >> 8) & 16711935) * unAlpha)) + 16711935;
/* divide by 255 */
blendRB = (((usqInt) (blendRB + ((((usqInt) (blendRB - 65537)) >> 8) & 16711935))) >> 8) & 16711935;
blendAG = (((usqInt) (blendAG + ((((usqInt) (blendAG - 65537)) >> 8) & 16711935))) >> 8) & 16711935;
result = blendRB | (((usqInt)(blendAG) << 8));
}
}
else {
pixMask = maskTable[destDepth];
bitsPerColor = 5;
rgbMask = 0x1F;
maskShifted = destMask;
destShifted = destinationWord;
sourceShifted = sourceWord;
for (j = 1; j <= destPPW; j += 1) {
sourcePixVal = sourceShifted & pixMask;
if (!(((maskShifted & pixMask) == 0)
|| (paintMode && (sourcePixVal == 0)))) {
destPixVal = destShifted & pixMask;
pixBlend = 0;
for (i = 1; i <= 3; i += 1) {
shift = (i - 1) * bitsPerColor;
blend = ((((((((usqInt) sourcePixVal) >> shift) & rgbMask) * sourceAlpha) + (((((usqInt) destPixVal) >> shift) & rgbMask) * unAlpha)) + 0xFE) / 0xFF) & rgbMask;
pixBlend = pixBlend | (((usqInt)(blend) << shift));
}
result = (result & ((unsigned int)~(((usqInt)(pixMask) << ((j - 1) * 16))))) | (((usqInt)(pixBlend) << ((j - 1) * 16)));
}
maskShifted = ((usqInt) maskShifted) >> destDepth;
sourceShifted = ((usqInt) sourceShifted) >> destDepth;
destShifted = ((usqInt) 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.
*/
/* BitBltSimulation>>#alphaBlendScaled:with: */
static unsigned int
alphaBlendScaledwith(unsigned int sourceWord, unsigned int destinationWord)
{
unsigned int ag;
unsigned int rb;
unsigned int unAlpha;
/* Do NOT inline this into optimized loops */
/* High 8 bits of source pixel is source opacity (ARGB format) */
unAlpha = 0xFF - (((usqInt) sourceWord) >> 24);
/* blend red and blue components */
rb = ((((usqInt) ((destinationWord & 16711935) * unAlpha)) >> 8) & 16711935) + (sourceWord & 16711935);
/* blend alpha and green components */
ag = ((((usqInt) (((((usqInt) destinationWord) >> 8) & 16711935) * unAlpha)) >> 8) & 16711935) + ((((usqInt) sourceWord) >> 8) & 16711935);
/* saturate red and blue components if there is a carry */
rb = (rb & 16711935) | (((usqInt) ((rb & 16777472) * 0xFF)) >> 8);
/* saturate alpha and green components if there is a carry */
ag = (((usqInt)((ag & 16711935)) << 8)) | ((ag & 16777472) * 0xFF);
return ag | rb;
}
/* 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. */
/* BitBltSimulation>>#alphaBlend:with: */
static unsigned int
alphaBlendwith(unsigned int sourceWord, unsigned int destinationWord)
{
unsigned int alpha;
unsigned int blendAG;
unsigned int blendRB;
unsigned int result;
unsigned int unAlpha;
/* High 8 bits of source pixel */
alpha = ((usqInt) sourceWord) >> 24;
if (alpha == 0) {
return destinationWord;
}
if (alpha == 0xFF) {
return sourceWord;
}
unAlpha = 0xFF - alpha;
/* blend red and blue */
blendRB = (((sourceWord & 16711935) * alpha) + ((destinationWord & 16711935) * unAlpha)) + 16711935;
/* blend alpha and green */
blendAG = (((((((usqInt) sourceWord) >> 8) | 0xFF0000) & 16711935) * alpha) + (((((usqInt) destinationWord) >> 8) & 16711935) * unAlpha)) + 16711935;
/* divide by 255 */
blendRB = (((usqInt) (blendRB + ((((usqInt) (blendRB - 65537)) >> 8) & 16711935))) >> 8) & 16711935;
blendAG = (((usqInt) (blendAG + ((((usqInt) (blendAG - 65537)) >> 8) & 16711935))) >> 8) & 16711935;
result = blendRB | (((usqInt)(blendAG) << 8));
return result;
}
/* BitBltSimulation>>#alphaPaintConst:with: */
static unsigned int
alphaPaintConstwith(unsigned int sourceWord, unsigned int destinationWord)
{
if (sourceWord == 0) {
return destinationWord;
}
return alphaBlendConstwithpaintMode(sourceWord, destinationWord, 1);
}
/* This version assumes
combinationRule = 34
sourcePixSize = 32
destPixSize = 16
sourceForm ~= destForm.
*/
/* BitBltSimulation>>#alphaSourceBlendBits16 */
static sqInt
alphaSourceBlendBits16(void)
{
sqInt addThreshold;
sqInt addThreshold1;
int deltaX;
int deltaY;
unsigned int destWord;
int ditherBase;
int ditherIndex;
int ditherThreshold;
sqInt dstIndex;
unsigned int dstMask;
sqInt dstValue;
sqInt dstValue1;
int dstY;
unsigned int sourceWord;
unsigned int srcAlpha;
sqInt srcIndex;
int srcShift;
int srcY;
/* 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 = 0xFFFFU << (16 - srcShift);
while (((deltaY -= 1)) != 0) {
srcIndex = (sourceBits + (srcY * sourcePitch)) + (sx * 4);
dstIndex = (destBits + (dstY * destPitch)) + ((dx / 2) * 4);
ditherBase = (dstY & 3) * 4;
/* For pre-increment */
ditherIndex = (sx & 3) - 1;
/* So we can pre-decrement */
deltaX = bbW + 1;
dstMask = mask1;
if (dstMask == 0xFFFF) {
srcShift = 16;
}
else {
srcShift = 0;
}
while (((deltaX -= 1)) != 0) {
ditherThreshold = ditherMatrix4x4[ditherBase + ((ditherIndex = (ditherIndex + 1) & 3))];
assert((((usqInt)srcIndex)) < endOfSource);
sourceWord = long32At(srcIndex);
srcAlpha = ((usqInt) sourceWord) >> 24;
if (srcAlpha == 0xFF) {
/* Dither from 32 to 16 bit */
/* begin dither32To16:threshold: */
addThreshold = ((usqInt) ditherThreshold << 8);
sourceWord = ((((usqInt) (dither8Lookup[addThreshold + ((((usqInt) sourceWord >> 16)) & 0xFF)]) << 10)) + (((usqInt) (dither8Lookup[addThreshold + ((((usqInt) sourceWord >> 8)) & 0xFF)]) << 5))) + (dither8Lookup[addThreshold + (sourceWord & 0xFF)]);
if (sourceWord == 0) {
sourceWord = 1U << srcShift;
}
else {
sourceWord = ((usqInt)(sourceWord) << srcShift);
}
/* begin dstLongAt:put:mask: */
assert((((usqInt)dstIndex)) < endOfDestination);
dstValue = long32At(dstIndex);
dstValue = dstValue & dstMask;
dstValue = dstValue | sourceWord;
/* begin dstLongAt:put: */
long32Atput(dstIndex, dstValue);
}
else {
/* srcAlpha ~= 255 */
if (!(srcAlpha == 0)) {
/* 0 < srcAlpha < 255 */
/* If we have to mix colors then just copy a single word */
assert((((usqInt)dstIndex)) < endOfDestination);
destWord = long32At(dstIndex);
destWord = destWord & ((unsigned int)~dstMask);
/* Expand from 16 to 32 bit by adding zero bits */
destWord = ((usqInt) destWord) >> srcShift;
/* Mix colors */
destWord = ((((usqInt) (destWord & 0x7C00) << 9)) | (((usqInt) (destWord & 0x3E0) << 6))) | ((((usqInt) (destWord & 0x1F) << 3)) | 0xFF000000U);
/* And dither */
sourceWord = alphaBlendScaledwith(sourceWord, destWord);
/* begin dither32To16:threshold: */
addThreshold1 = ((usqInt) ditherThreshold << 8);
sourceWord = ((((usqInt) (dither8Lookup[addThreshold1 + ((((usqInt) sourceWord >> 16)) & 0xFF)]) << 10)) + (((usqInt) (dither8Lookup[addThreshold1 + ((((usqInt) sourceWord >> 8)) & 0xFF)]) << 5))) + (dither8Lookup[addThreshold1 + (sourceWord & 0xFF)]);
if (sourceWord == 0) {
sourceWord = 1U << srcShift;
}
else {
sourceWord = ((usqInt)(sourceWord) << srcShift);
}
/* begin dstLongAt:put:mask: */
assert((((usqInt)dstIndex)) < endOfDestination);
dstValue1 = long32At(dstIndex);
dstValue1 = dstValue1 & dstMask;
dstValue1 = dstValue1 | sourceWord;
/* begin dstLongAt:put: */
long32Atput(dstIndex, dstValue1);
}
}
srcIndex += 4;
if (destMSB) {
if (srcShift == 0) {
dstIndex += 4;
}
}
else {
if (!(srcShift == 0)) {
dstIndex += 4;
}
}
/* Toggle between 0 and 16 */
srcShift = srcShift ^ 16;
dstMask = (unsigned int)~dstMask;
}
srcY += 1;
dstY += 1;
}
return 0;
}
/* 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
*/
/* BitBltSimulation>>#alphaSourceBlendBits32 */
static sqInt
alphaSourceBlendBits32(void)
{
int deltaX;
int deltaY;
unsigned int destWord;
sqInt dstIndex;
int dstY;
unsigned int sourceWord;
unsigned int srcAlpha;
sqInt srcIndex;
int srcY;
/* 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 -= 1)) != 0) {
srcIndex = (sourceBits + (srcY * sourcePitch)) + (sx * 4);
dstIndex = (destBits + (dstY * destPitch)) + (dx * 4);
/* So we can pre-decrement */
/* This is the inner loop */
deltaX = bbW + 1;
while (((deltaX -= 1)) != 0) {
assert((((usqInt)srcIndex)) < endOfSource);
sourceWord = long32At(srcIndex);
srcAlpha = ((usqInt) sourceWord) >> 24;
if (srcAlpha == 0xFF) {
long32Atput(dstIndex, sourceWord);
srcIndex += 4;
/* Now copy as many words as possible with alpha = 255 */
dstIndex += 4;
while ((((deltaX -= 1)) != 0)
&& ((((usqInt) ((assert((((usqInt)srcIndex)) < endOfSource),
(sourceWord = long32At(srcIndex))))) >> 24) == 0xFF)) {
long32Atput(dstIndex, sourceWord);
srcIndex += 4;
dstIndex += 4;
}
deltaX += 1;
}
else {
/* srcAlpha ~= 255 */
if (srcAlpha == 0) {
srcIndex += 4;
/* Now skip as many words as possible, */
dstIndex += 4;
while ((((deltaX -= 1)) != 0)
&& ((((usqInt) ((assert((((usqInt)srcIndex)) < endOfSource),
(sourceWord = long32At(srcIndex))))) >> 24) == 0)) {
srcIndex += 4;
dstIndex += 4;
}
deltaX += 1;
}
else {
/* 0 < srcAlpha < 255 */
/* If we have to mix colors then just copy a single word */
assert((((usqInt)dstIndex)) < endOfDestination);
destWord = long32At(dstIndex);
destWord = alphaBlendScaledwith(sourceWord, destWord);
long32Atput(dstIndex, destWord);
srcIndex += 4;
dstIndex += 4;
}
}
}
srcY += 1;
dstY += 1;
}
return 0;
}
/* 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. */
/* BitBltSimulation>>#alphaSourceBlendBits8 */
static sqInt
alphaSourceBlendBits8(void)
{
sqInt adjust;
int deltaX;
int deltaY;
unsigned int destWord;
sqInt dstIndex;
unsigned int dstMask;
sqInt dstValue;
int dstY;
sqInt mapperFlags;
unsigned int *mappingTable;
sqInt pv;
unsigned int sourceWord;
unsigned int srcAlpha;
sqInt srcIndex;
sqInt srcShift;
int srcY;
static unsigned int theTable[256] = {
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};;
sqInt val;
mappingTable = theTable;
mapperFlags = cmFlags & ((unsigned int)~ColorMapNewStyle);
/* So we can pre-decrement */
deltaY = bbH + 1;
srcY = sy;
dstY = dy;
mask1 = (dx & 3) * 8;
if (destMSB) {
mask1 = 24 - mask1;
}
mask2 = AllOnes ^ (0xFFU << mask1);
if ((dx & 1) == 0) {
adjust = 0;
}
else {
adjust = 522133279;
}
if ((dy & 1) == 0) {
adjust = adjust ^ 522133279;
}
while (((deltaY -= 1)) != 0) {
adjust = adjust ^ 522133279;
srcIndex = (sourceBits + (srcY * sourcePitch)) + (sx * 4);
dstIndex = (destBits + (dstY * destPitch)) + ((dx / 4) * 4);
/* So we can pre-decrement */
deltaX = bbW + 1;
srcShift = mask1;
/* This is the inner loop */
dstMask = mask2;
while (((deltaX -= 1)) != 0) {
sourceWord = (((assert((((usqInt)srcIndex)) < endOfSource),
long32At(srcIndex))) & ((unsigned int)~adjust)) + adjust;
srcAlpha = ((usqInt) sourceWord) >> 24;
if (srcAlpha > 0x1F) {
/* Everything below 31 is transparent */
if (srcAlpha < 224) {
/* Everything above 224 is opaque */
assert((((usqInt)dstIndex)) < endOfDestination);
destWord = long32At(dstIndex);
destWord = destWord & ((unsigned int)~dstMask);
destWord = ((usqInt) destWord) >> srcShift;
destWord = mappingTable[destWord];
sourceWord = alphaBlendScaledwith(sourceWord, destWord);
}
/* begin mapPixel:flags: */
pv = sourceWord;
if ((mapperFlags & ColorMapPresent) != 0) {
if ((mapperFlags & ColorMapFixedPart) != 0) {
/* begin rgbMapPixel:flags: */
val = (((((int) (cmShiftTable[0]))) < 0) ? ((usqInt) (sourceWord & (cmMaskTable[0])) >> -(((int) (cmShiftTable[0])))) : ((usqInt) (sourceWord & (cmMaskTable[0])) << (((int) (cmShiftTable[0])))));
val = val | ((((((int) (cmShiftTable[1]))) < 0) ? ((usqInt) (sourceWord & (cmMaskTable[1])) >> -(((int) (cmShiftTable[1])))) : ((usqInt) (sourceWord & (cmMaskTable[1])) << (((int) (cmShiftTable[1]))))));
val = val | ((((((int) (cmShiftTable[2]))) < 0) ? ((usqInt) (sourceWord & (cmMaskTable[2])) >> -(((int) (cmShiftTable[2])))) : ((usqInt) (sourceWord & (cmMaskTable[2])) << (((int) (cmShiftTable[2]))))));
pv = val | ((((((int) (cmShiftTable[3]))) < 0) ? ((usqInt) (sourceWord & (cmMaskTable[3])) >> -(((int) (cmShiftTable[3])))) : ((usqInt) (sourceWord & (cmMaskTable[3])) << (((int) (cmShiftTable[3]))))));
if ((pv == 0)
&& (sourceWord != 0)) {
pv = 1;
}
}
if ((mapperFlags & ColorMapIndexedPart) != 0) {
pv = cmLookupTable[pv & cmMask];
}
}
sourceWord = pv;