-
Notifications
You must be signed in to change notification settings - Fork 74
/
UCommands.inc1.p
1671 lines (1155 loc) · 29.7 KB
/
UCommands.inc1.p
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
{Photoshop version 1.0.1, file: UCommands.inc1.p
Computer History Museum, www.computerhistory.org
This material is (C)Copyright 1990 Adobe Systems Inc.
It may not be distributed to third parties.
It is licensed for non-commercial use according to
www.computerhistory.org/softwarelicense/photoshop/ }
{$I UAssembly.a.inc}
{$I UFloat.a.inc}
{$I UDither.a.inc}
{*****************************************************************************}
{$S AInit}
PROCEDURE ScanPouchFiles (theType: OSType;
PROCEDURE TestIt (fileName: TFileName));
LABEL
1;
CONST
kGeneralType = '8BPI';
VAR
fi: FailInfo;
name: Str255;
index: INTEGER;
refNum: INTEGER;
pb: ParamBlockRec;
PROCEDURE CleanUp (error: INTEGER; message: LONGINT);
BEGIN
GOTO 1
END;
BEGIN
FOR index := 1 TO 32767 DO
BEGIN
WITH pb DO
BEGIN
ioNamePtr := @name;
ioVRefNum := gPouchRefNum;
ioFVersNum := 0;
ioFDirIndex := index
END;
IF PBGetFInfo (@pb, FALSE) <> noErr THEN LEAVE;
IF (pb.ioFlFndrInfo.fdType = theType) OR
(pb.ioFlFndrInfo.fdType = kGeneralType) THEN
IF LENGTH (name) <= kFileNameLength THEN
BEGIN
refNum := OpenResFile (name);
IF refNum <> -1 THEN
BEGIN
CatchFailures (fi, CleanUp);
TestIt (name);
Success (fi);
1: CloseResFile (refNum)
END
END
END
END;
{*****************************************************************************}
{$S AInit}
PROCEDURE AddNameToMenu (command: INTEGER; name: Str255);
VAR
mark: CHAR;
item: INTEGER;
count: INTEGER;
oldName: Str255;
menu: MenuHandle;
compare: INTEGER;
cmdMenu: INTEGER;
cmdItem: INTEGER;
BEGIN
CmdToMenuItem (command, cmdMenu, cmdItem);
GetItemMark (GetResMenu (cmdMenu), cmdItem, mark);
menu := GetResMenu (ORD (mark));
count := CountMItems (menu);
item := 1;
WHILE item <= count DO
BEGIN
GetItem (menu, item, oldName);
compare := RelString (name, oldName, TRUE, TRUE);
IF compare <= 0 THEN LEAVE;
item := item + 1
END;
IF item > count THEN
BEGIN
AppendMenu (menu, 'Dummy');
SetItem (menu, item, name)
END
ELSE IF compare <> 0 THEN
BEGIN
InsMenuItem (menu, 'Dummy', item - 1);
SetItem (menu, item, name)
END
END;
{*****************************************************************************}
{$S AInit}
PROCEDURE InitPlugInList (kind: ResType;
loVersion, hiVersion: INTEGER;
VAR first: HPlugInInfo;
command: INTEGER);
PROCEDURE AddPlugIn (name: Str255;
fileName: TFileName;
resourceID: INTEGER;
version: INTEGER);
VAR
aPlugInInfo: HPlugInInfo;
BEGIN
aPlugInInfo := HPlugInInfo (NewHandle (SIZEOF (TPlugInInfo)));
FailMemError;
WITH aPlugInInfo^^ DO
BEGIN
fName := name;
fFileName := fileName;
fKind := kind;
fResourceID := resourceID;
fVersion := version;
fData := 0;
fParameters := NIL;
fNext := first
END;
first := aPlugInInfo;
AddNameToMenu (command, name)
END;
PROCEDURE TestIt (fileName: TFileName);
TYPE
IntegerPtr = ^INTEGER;
VAR
h: Handle;
name: Str255;
index: INTEGER;
count: INTEGER;
version: INTEGER;
resourceID: INTEGER;
ignoreType: ResType;
BEGIN
count := Count1Resources (kind);
FOR index := 1 TO count DO
BEGIN
SetResLoad (FALSE);
h := Get1IndResource (kind, index);
SetResLoad (TRUE);
IF h <> NIL THEN
BEGIN
GetResInfo (h, resourceID, ignoreType, name);
FailResError;
IF LENGTH (name) <> 0 THEN
BEGIN
h := Get1Resource ('PiMI', resourceID);
IF h <> NIL THEN
BEGIN
version := IntegerPtr (h^)^;
IF (version >= loVersion) AND
(version <= hiVersion) THEN
AddPlugIn (name, fileName, resourceID, version)
END
END
END
END
END;
BEGIN
first := NIL;
IF NOT gFinderPrinting THEN
BEGIN
TestIt ('');
ScanPouchFiles (kind, TestIt)
END
END;
{*****************************************************************************}
{$S AInit}
PROCEDURE CheckForNoPlugIns (command: INTEGER);
VAR
mark: CHAR;
name: Str255;
count: INTEGER;
cmdMenu: INTEGER;
cmdItem: INTEGER;
subMenu: MenuHandle;
mainMenu: MenuHandle;
BEGIN
CmdToMenuItem (command, cmdMenu, cmdItem);
mainMenu := GetResMenu (cmdMenu);
GetItemMark (mainMenu, cmdItem, mark);
subMenu := GetResMenu (ORD (mark));
count := CountMItems (subMenu);
IF count = 0 THEN
BEGIN
SetItemCmd (mainMenu, cmdItem, CHR (noMark));
SetItemMark (mainMenu, cmdItem, CHR (noMark))
END
END;
{*****************************************************************************}
{$S ASelCommand}
FUNCTION IsPlugIn (name: Str255;
first: HPlugInInfo;
VAR info: HPlugInInfo): BOOLEAN;
BEGIN
info := first;
WHILE info <> NIL DO
BEGIN
IF EqualString (name, info^^.fName, TRUE, TRUE) THEN
BEGIN
IsPlugIn := TRUE;
EXIT (IsPlugIn)
END;
info := info^^.fNext
END;
IsPlugIn := FALSE
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE GetCenterPoint (view: TImageView; VAR center: Point);
VAR
r: Rect;
BEGIN
view.fFrame.GetViewedRect (r);
center.h := BSR (ORD4 (r.right) + r.left, 1);
center.v := BSR (ORD4 (r.bottom) + r.top, 1);
view.CvtView2Image (center)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE SetTopLeft (view: TImageView; top, left: INTEGER);
BEGIN
SetCtlValue (view.fFrame.fScrollBars [h], left);
SetCtlValue (view.fFrame.fScrollBars [v], top);
view.fFrame.ScrlToSBars (TRUE)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE SetCenterPoint (view: TImageView; center: Point);
VAR
r: Rect;
tl: Point;
BEGIN
tl := center;
view.CvtImage2View (tl, kRoundDown);
r := view.fFrame.fContentRect;
tl.h := tl.h - BSR (r.right - r.left, 1);
tl.v := tl.v - BSR (r.bottom - r.top, 1);
SetTopLeft (view, tl.v, tl.h)
END;
{*****************************************************************************}
{$S ADoCommand}
FUNCTION MakeMonochromeArray (rArray, gArray, bArray: TVMArray): TVMArray;
VAR
rPtr: Ptr;
gPtr: Ptr;
bPtr: Ptr;
mPtr: Ptr;
fi: FailInfo;
row: INTEGER;
mArray: TVMArray;
PROCEDURE CleanUp (error: INTEGER; message: LONGINT);
BEGIN
IF rPtr <> NIL THEN rArray.DoneWithPtr;
IF gPtr <> NIL THEN gArray.DoneWithPtr;
IF bPtr <> NIL THEN bArray.DoneWithPtr;
rArray.Flush;
gArray.Flush;
bArray.Flush;
mArray.Free
END;
BEGIN
mArray := NewVMArray (rArray.fBlockCount, rArray.fLogicalSize, 1);
CatchFailures (fi, CleanUp);
FOR row := 0 TO mArray.fBlockCount - 1 DO
BEGIN
UpdateProgress (row, mArray.fBlockCount);
rPtr := NIL;
gPtr := NIL;
bPtr := NIL;
rPtr := rArray.NeedPtr (row, row, FALSE);
gPtr := gArray.NeedPtr (row, row, FALSE);
bPtr := bArray.NeedPtr (row, row, FALSE);
mPtr := mArray.NeedPtr (row, row, TRUE);
DoMakeMonochrome (rPtr, gGrayLUT.R,
gPtr, gGrayLUT.G,
bPtr, gGrayLUT.B,
mPtr, mArray.fLogicalSize);
rArray.DoneWithPtr;
gArray.DoneWithPtr;
bArray.DoneWithPtr;
mArray.DoneWithPtr
END;
UpdateProgress (1, 1);
Success (fi);
rArray.Flush;
gArray.Flush;
bArray.Flush;
mArray.Flush;
MakeMonochromeArray := mArray;
END;
{*****************************************************************************}
{$S ADoCommand}
FUNCTION CopyHalftoneRect (srcBuffer: TVMArray;
r: Rect;
depth: INTEGER): TVMArray;
VAR
dr: Rect;
srcPtr: Ptr;
dstPtr: Ptr;
fi: FailInfo;
row: INTEGER;
map: TLookUpTable;
rowBytes: INTEGER;
dstBuffer: TVMArray;
PROCEDURE CleanUp (error: INTEGER; message: LONGINT);
BEGIN
IF srcPtr <> NIL THEN srcBuffer.DoneWithPtr;
srcBuffer.Flush;
dstBuffer.Free
END;
BEGIN
{$IFC qDebug}
IF (depth <> 1) AND (depth <> 8) THEN
ProgramBreak ('Bad depth passed to CopyHalftoneRect');
{$ENDC}
IF depth = 8 THEN
rowBytes := r.right - r.left
ELSE
rowBytes := BSL (BSR (r.right - r.left + 15, 4), 1);
dstBuffer := NewVMArray (r.bottom - r.top, rowBytes, 1);
CatchFailures (fi, CleanUp);
dr := r;
dr.top := 0;
dr.bottom := 1;
FOR row := r.top TO r.bottom - 1 DO
BEGIN
srcPtr := NIL;
srcPtr := srcBuffer.NeedPtr (row, row, FALSE);
dstPtr := dstBuffer.NeedPtr (row - r.top, row - r.top, TRUE);
DoHalftone (srcPtr, 0, dstPtr, rowBytes, depth, dr, 1);
srcBuffer.DoneWithPtr;
dstBuffer.DoneWithPtr
END;
srcPtr := NIL;
srcBuffer.Flush;
dstBuffer.Flush;
IF depth = 8 THEN
BEGIN
map [0] := CHR (255);
map [1] := CHR ( 0);
dstBuffer.MapBytes (map)
END;
Success (fi);
CopyHalftoneRect := dstBuffer
END;
{*****************************************************************************}
{$S ASelCommand}
PROCEDURE TBufferCommand.IBufferCommand (itsCommand: INTEGER;
view: TImageView);
VAR
channel: INTEGER;
BEGIN
fView := view;
fDoc := TImageDocument (view.fDocument);
FOR channel := 0 TO kMaxChannels - 1 DO
fBuffer [channel] := NIL;
ICommand (itsCommand)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TBufferCommand.Free; OVERRIDE;
VAR
channel: INTEGER;
BEGIN
FOR channel := 0 TO kMaxChannels - 1 DO
FreeObject (fBuffer [channel]);
INHERITED Free
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TBufferCommand.SwapAllChannels;
VAR
save: TVMArray;
channel: INTEGER;
BEGIN
FOR channel := 0 TO fDoc.fChannels - 1 DO
BEGIN
save := fBuffer [channel];
fBuffer [channel] := fDoc.fData [channel];
fDoc.fData [channel] := save
END
END;
{*****************************************************************************}
{$S ASelCommand}
PROCEDURE TFloatCommand.IFloatCommand (itsCommand: INTEGER;
view: TImageView);
VAR
channel: INTEGER;
BEGIN
fSwapMask := FALSE;
fFloatMask := NIL;
FOR channel := 0 TO 2 DO
BEGIN
fFloatData [channel] := NIL;
fFloatBelow [channel] := NIL
END;
IBufferCommand (itsCommand, view);
fWasFloating := fDoc.fSelectionFloating AND
NOT fDoc.fExactFloat AND
(fDoc.fFloatChannel = view.fChannel);
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.Free; OVERRIDE;
VAR
channel: INTEGER;
BEGIN
FreeObject (fFloatMask);
FOR channel := 0 TO 2 DO
BEGIN
FreeObject (fFloatData [channel]);
FreeObject (fFloatBelow [channel])
END;
IF fDoc.fFloatCommand = SELF THEN
BEGIN
fDoc.fFloatCommand := NIL;
IF NOT fDoc.fSelectionFloating OR fDoc.fExactFloat THEN
fDoc.FreeFloat
END;
INHERITED Free
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.SwapFloat;
VAR
saveRect: Rect;
channel: INTEGER;
saveExact: BOOLEAN;
saveArray: TVMArray;
BEGIN
saveExact := fDoc.fExactFloat;
fDoc.fExactFloat := fExactFloat;
fExactFloat := saveExact;
saveRect := fDoc.fFloatRect;
fDoc.fFloatRect := fFloatRect;
fFloatRect := saveRect;
IF (fFloatMask <> NIL) OR fSwapMask THEN
BEGIN
saveArray := fDoc.fFloatMask;
fDoc.fFloatMask := fFloatMask;
fFloatMask := saveArray
END;
FOR channel := 0 TO 2 DO
BEGIN
IF fFloatData [channel] <> NIL THEN
BEGIN
saveArray := fDoc.fFloatData [channel];
fDoc.fFloatData [channel] := fFloatData [channel];
fFloatData [channel] := saveArray
END;
IF fFloatBelow [channel] <> NIL THEN
BEGIN
saveArray := fDoc.fFloatBelow [channel];
fDoc.fFloatBelow [channel] := fFloatBelow [channel];
fFloatBelow [channel] := saveArray
END
END
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.MakeMapLegal (VAR map: TLookUpTable);
VAR
gray: INTEGER;
BEGIN
IF fDoc.fMode = IndexedColorMode THEN
FOR gray := 0 TO 255 DO
IF ORD (map [gray]) >= 128 THEN
map [gray] := CHR (255)
ELSE
map [gray] := CHR (0)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.FloatSelection (duplicate: BOOLEAN);
VAR
r: Rect;
fi: FailInfo;
row: INTEGER;
page: INTEGER;
width: INTEGER;
height: INTEGER;
channel: INTEGER;
map: TLookUpTable;
channels: INTEGER;
aVMArray: TVMArray;
bVMArray: TVMArray;
cVMArray: TVMArray;
PROCEDURE CleanUp (error: INTEGER; message: LONGINT);
BEGIN
fDoc.FreeFloat
END;
BEGIN
IF fWasFloating THEN
BEGIN
fDoc.fFloatCommand := SELF;
EXIT (FloatSelection)
END;
fDoc.FreeFloat;
CatchFailures (fi, CleanUp);
r := fDoc.fSelectionRect;
width := r.right - r.left;
height := r.bottom - r.top;
fDoc.fSelectionFloating := TRUE;
fDoc.fExactFloat := NOT duplicate;
fDoc.fFloatCommand := SELF;
fDoc.fFloatChannel := fView.fChannel;
fDoc.fFloatRect := r;
IF fDoc.fSelectionMask <> NIL THEN
BEGIN
aVMArray := fDoc.fSelectionMask.CopyArray (1);
fDoc.fFloatMask := aVMArray
END;
IF fDoc.fFloatChannel = kRGBChannels THEN
channels := 3
ELSE
channels := 1;
FOR channel := 0 TO channels - 1 DO
BEGIN
aVMArray := NewVMArray (height, width, 1);
fDoc.fFloatBelow [channel] := aVMArray
END;
FOR channel := 0 TO channels - 1 DO
BEGIN
IF channels = 3 THEN
aVMArray := fDoc.fData [channel] .
CopyRect (r, channels - channel)
ELSE
aVMArray := fDoc.fData [fDoc.fFloatChannel] .
CopyRect (r, channels - channel);
fDoc.fFloatData [channel] := aVMArray;
bVMArray := fDoc.fFloatBelow [channel];
IF duplicate THEN
aVMArray.MoveArray (bVMArray)
ELSE
BEGIN
bVMArray.SetBytes (fView.BackgroundByte (channel));
cVMArray := fDoc.fFloatMask;
IF cVMArray <> NIL THEN
BEGIN
map := gInvertLUT;
MakeMapLegal (map);
FOR row := 0 TO height - 1 DO
BEGIN
BlockMove (cVMArray.NeedPtr (row, row, FALSE),
gBuffer,
width);
DoMapBytes (gBuffer, width, map);
DoBlendBelow (gBuffer,
aVMArray.NeedPtr (row, row, FALSE),
bVMArray.NeedPtr (row, row, TRUE),
width,
0,
-1);
aVMArray.DoneWithPtr;
bVMArray.DoneWithPtr;
cVMArray.DoneWithPtr
END;
aVMArray.Flush;
bVMArray.Flush;
cVMArray.Flush
END
END
END;
Success (fi)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.ComputeOverlap (VAR r: Rect);
BEGIN
r := fDoc.fFloatRect;
fDoc.SectBoundsRect (r)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.CopyOverlapArea (into: BOOLEAN;
buffer: TVMArray;
image: TVMArray);
VAR
r1: Rect;
r2: Rect;
BEGIN
IF into THEN
buffer.Undefine
ELSE
buffer.Preload (2);
ComputeOverlap (r1);
r2 := r1;
OffsetRect (r2, -fDoc.fFloatRect.left, -fDoc.fFloatRect.top);
IF into THEN
image.MoveRect (buffer, r1, r2)
ELSE
buffer.MoveRect (image, r2, r1)
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.CopyOverlapAreas (into: BOOLEAN;
buffer0: TVMArray;
buffer1: TVMArray;
buffer2: TVMArray);
BEGIN
IF fDoc.fFloatChannel = kRGBChannels THEN
BEGIN
CopyOverlapArea (into, buffer0, fDoc.fData [0]);
CopyOverlapArea (into, buffer1, fDoc.fData [1]);
CopyOverlapArea (into, buffer2, fDoc.fData [2])
END
ELSE
CopyOverlapArea (into, buffer0, fDoc.fData [fDoc.fFloatChannel])
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE TFloatCommand.CopyBelow (into: BOOLEAN);
BEGIN
CopyOverlapAreas (into, fDoc.fFloatBelow [0],
fDoc.fFloatBelow [1],
fDoc.fFloatBelow [2])
END;
{*****************************************************************************}
{$S ADoCommand}
PROCEDURE GetPasteControls (doc: TImageDocument;
VAR controls: TPasteControls);
VAR
band: INTEGER;
BEGIN
IF doc.fPasteControls <> NIL THEN
controls := HPasteControls (doc.fPasteControls)^^
ELSE
WITH controls DO
BEGIN
FOR band := 0 TO 3 DO
BEGIN
fSrcMin [band] := 0;
fSrcMax [band] := 255;
fDstMin [band] := 0;
fDstMax [band] := 255
END;
fMode := PasteNormal;
fBlend := 100;
fFuzz := 0;
fMat := -1
END
END;
{*****************************************************************************}
{$S ADoCommand}
FUNCTION BuildMaskLUT (VAR map: TLookUpTable;
lower: INTEGER;
upper: INTEGER;
fuzz: INTEGER): BOOLEAN;
VAR
g1: INTEGER;
g2: INTEGER;
g3: INTEGER;
gap: INTEGER;
gray: INTEGER;
ignore: BOOLEAN;
BEGIN
IF upper >= lower THEN
BEGIN
DoSetBytes (@map, 256, 255);
gap := fuzz + 1;
IF lower <> 0 THEN
BEGIN
g1 := lower - BSR (gap + 1, 1);
g2 := lower + BSR (gap , 1);
FOR gray := 0 TO g2 - 1 DO
IF gray <= g1 THEN
map [gray] := CHR (0)