-
Notifications
You must be signed in to change notification settings - Fork 7
/
UDither.a
executable file
·2199 lines (1632 loc) · 37.5 KB
/
UDither.a
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: UDither.a
; 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/
INCLUDE 'Traps.a'
; **********************************************************************
; Macro to get pixel value
MACRO
GetPixel &mFlag
; Get a pixel value
IF &mFlag >= 0 THEN
MOVE.B (A1)+,D4
ELSE
MOVE.B (A1),D4
ENDIF
; Pass through look up table
MOVE.B (A2,D4.W),D4
; Add noise value to pixel
CLR.W D6
MOVE.B (A0,D0.W),D6
ADD.W D4,D6
; Pass pixel through threshold table
MOVE.B (A3,D6.W),D4
ENDM
; **********************************************************************
; Macro to move to next pixel
MACRO
NextPixel &LoopTop,&mFlag
; Update dither column
ADD.W #1,D0
BNE.S @1
MOVE D1,D0
@1
; Update input pointer if needed and close loop
IF &mFlag = 1 THEN
SUB.W #1,D5
BNE.S @2
MOVE.W D2,D5
DBF D3,&LoopTop
BRA.S @3
@2 SUB.W #1,A1
ELSEIF &mFlag = -1 THEN
SUB.W D2,A1
ENDIF
DBF D3,&LoopTop
@3
ENDM
; **********************************************************************
; Macro to process a row of pixels
MACRO
DoPixels &mFlag
; Case on number of bits per pixel
CMP.W #8,D7
BEQ @10
CMP.W #4,D7
IF &mFlag = 1 THEN
BEQ @7
ELSE
BEQ.S @7
ENDIF
CMP.W #2,D7
BEQ.S @4
; 1 bit pixel case
MOVE.B #$80,D7
@1 GetPixel &mFlag
BEQ.S @2
OR.B D7,(A4)
@2 ROR.B #1,D7
BCS.S @3
NextPixel @1,&mFlag
BRA @11
@3 ADD.L #1,A4
NextPixel @1,&mFlag
BRA @11
; 2 bit pixel case
@4 MOVE.W #6,D7
@5 GetPixel &mFlag
LSL.B D7,D4
ADD.B D4,(A4)
SUB.W #2,D7
BPL.S @6
MOVE.W #6,D7
ADD.L #1,A4
@6 NextPixel @5,&mFlag
IF &mFlag = 1 THEN
BRA @11
ELSE
BRA.S @11
ENDIF
; 4 bit pixel case
@7 CLR.W D7
@8 GetPixel &mFlag
NOT.B D7
BEQ.S @9
LSL.B #4,D4
ADD.B D4,(A4)
NextPixel @8,&mFlag
BRA.S @11
@9 ADD.B D4,(A4)+
NextPixel @8,&mFlag
BRA.S @11
; 8 bit pixel case
@10 GetPixel &mFlag
ADD.B D4,(A4)+
NextPixel @10,&mFlag
@11
ENDM
; **********************************************************************
SEG 'ARes3'
DoDither PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoDither (inDataPtr: Ptr;
; inRowBytes: INTEGER;
; outDataPtr: Ptr;
; outRowBytes: INTEGER;
; outPixelBits: INTEGER;
; viewRect: Rect;
; magnification: INTEGER;
; ditherSize: INTEGER;
; lookUpTable: TlookUpTable;
; noiseTable: TNoiseTable;
; thresTable: TThresTable;
; zeroFirst: BOOLEAN);
; Parameter Offsets
@inDataPtr EQU 40
@inRowBytes EQU 38
@outDataPtr EQU 34
@outRowBytes EQU 32
@outPixelBits EQU 30
@viewRect EQU 26
@magnification EQU 24
@ditherSize EQU 22
@lookUpTable EQU 18
@noiseTable EQU 14
@thresTable EQU 10
@zeroFirst EQU 8
; Size of parameters
@params EQU 36
; Local variables
@startRow EQU -2
@startCol EQU -4
@numRows EQU -6
@numCols EQU -8
@ditherRow EQU -10
@ditherCol EQU -12
@subRow EQU -14
@subCol EQU -16
; Size of local variables
@localVars EQU -16
; Save registers
LINK A6,#@localVars
MOVEM.L D3-D7/A2-A4,-(SP)
; Unload rect
MOVE.L @viewRect(A6),A0
MOVE.W (A0),@startRow(A6)
MOVE.W 2(A0),@startCol(A6)
MOVE.W 4(A0),D0
SUB.W (A0),D0
MOVE.W D0,@numRows(A6)
MOVE.W 6(A0),D0
SUB.W 2(A0),D0
MOVE.W D0,@numCols(A6)
; Zero output data if requested
TST.W @zeroFirst(A6)
BEQ.S @2
MOVE.W @numRows(A6),D0
MULU.W @outRowBytes(A6),D0
ADD.L #1,D0
ASR.L #1,D0
BEQ.S @2
MOVE.L @outDataPtr(A6),A0
@1 CLR.W (A0)+
SUB.L #1,D0
BNE.S @1
; Move input data pointer to starting row and column
@2 MOVE.W @magnification(A6),D1
BLT.S @2A
MOVE.W @startRow(A6),D0
EXT.L D0
DIVU.W D1,D0
SWAP D0
MOVE.W D0,@subRow(A6)
SWAP D0
MULU.W @inRowBytes(A6),D0
ADD.L D0,@inDataPtr(A6)
MOVE.W @startCol(A6),D0
EXT.L D0
DIVU.W D1,D0
SWAP D0
MOVE.W D0,@subCol(A6)
SWAP D0
EXT.L D0
ADD.L D0,@inDataPtr(A6)
BRA.S @2B
; Negative magnification case
@2A NEG.W D1
MOVE.W @startRow(A6),D0
MULU.W D1,D0
MULU.W @inRowBytes(A6),D0
ADD.L D0,@inDataPtr(A6)
MOVE.W @startCol(A6),D0
MULU.W D1,D0
ADD.L D0,@inDataPtr(A6)
CLR.W @subRow(A6)
CLR.W @subCol(A6)
; Compute initial value of ditherRow
@2B MOVE.W @startRow(A6),D0
EXT.L D0
DIVU.W @ditherSize(A6),D0
SWAP D0
MOVE.W D0,@ditherRow(A6)
; Compute value of ditherCol at start of each row
MOVE.W @startCol(A6),D0
EXT.L D0
DIVU.W @ditherSize(A6),D0
SWAP D0
MOVE.W D0,@ditherCol(A6)
; while (--numRows >= 0)
@3 SUB.W #1,@numRows(A6)
BMI @18
; A0 = pointer past end of dither table row
MOVE.L @noiseTable(A6),A0
MOVE.W @ditherRow(A6),D0
ASL.W #4,D0
ADD.W D0,A0
ADD.W #1,@ditherRow(A6)
MOVE.W @ditherSize(A6),D1
ADD.W D1,A0
CMP.W @ditherRow(A6),D1
BNE.S @5
CLR.W @ditherRow(A6)
; D1 = -ditherSize
@5 NEG.W D1
; D0 = ditherCol - ditherSize
MOVE.W @ditherCol(A6),D0
ADD.W D1,D0
; A1 = pointer to input data
MOVE.L @inDataPtr(A6),A1
; A2 = pointer to look up table
MOVE.L @lookUpTable(A6),A2
; A3 = pointer to threshold table
MOVE.L @thresTable(A6),A3
; A4 = pointer to output data
MOVE.L @outDataPtr(A6),A4
; D3 = numCols - 1
MOVE.W @numCols(A6),D3
SUB.W #1,D3
; D2 = magnification
MOVE.W @magnification(A6),D2
; D5 = magnification - subCol
MOVE.W D2,D5
SUB.W @subCol(A6),D5
; Prepare D4 to hold pixel value
CLR.W D4
; D7 = output depth
MOVE.W @outPixelBits(A6),D7
; Process a row of pixels
CMP.W #1,D2
BEQ @7
BLT @8
DoPixels 1
BRA @10
@7 DoPixels 0
BRA @10
@8 DoPixels -1
; Move to next output row
@10 MOVE.W @outRowBytes(A6),D0
EXT.L D0
ADD.L D0,@outDataPtr(A6)
; Move to next input row, if needed
MOVE.W @magnification(A6),D1
BLT.S @11
ADD.W #1,@subRow(A6)
MOVE.W @subRow(A6),D0
CMP.W D1,D0
BNE @3
CLR.W @subRow(A6)
MOVE.W @inRowBytes(A6),D0
EXT.L D0
ADD.L D0,@inDataPtr(A6)
BRA @3
@11 NEG.W D1
MULU.W @inRowBytes(A6),D1
ADD.L D1,@inDataPtr(A6)
BRA @3
; Clean up and exit
@18 MOVEM.L (SP)+,D3-D7/A2-A4
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes3'
DoHalftone PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoHalftone (inDataPtr: Ptr;
; inRowBytes: INTEGER;
; outDataPtr: Ptr;
; outRowBytes: INTEGER;
; outPixelBits: INTEGER;
; viewRect: Rect;
; magnification: INTEGER);
; Parameter Offsets
@inDataPtr EQU 24
@inRowBytes EQU 22
@outDataPtr EQU 18
@outRowBytes EQU 16
@outPixelBits EQU 14
@viewRect EQU 10
@magnification EQU 8
; Size of parameters
@params EQU 20
; Local variables
@startRow EQU -2
@startCol EQU -4
@startBit EQU -6
@numRows EQU -8
@numCols EQU -10
@subRow EQU -12
@subCol EQU -14
; Size of local variables
@localVars EQU -14
; Save registers
LINK A6,#@localVars
MOVEM.L D3-D7,-(SP)
; Unload rect
MOVE.L @viewRect(A6),A0
MOVE.W (A0),@startRow(A6)
MOVE.W 2(A0),@startCol(A6)
MOVE.W 4(A0),D0
SUB.W (A0),D0
MOVE.W D0,@numRows(A6)
MOVE.W 6(A0),D0
SUB.W 2(A0),D0
MOVE.W D0,@numCols(A6)
; Move input pointer to start of rectangle
TST.W @magnification(A6)
BLT.S @2
; Case 1, positive magnification
MOVE.W @startRow(A6),D0
EXT.L D0
DIVU.W @magnification(A6),D0
SWAP D0
MOVE.W D0,@subRow(A6)
SWAP D0
MULU.W @inRowBytes(A6),D0
ADD.L D0,@inDataPtr(A6)
MOVE.W @startCol(A6),D0
EXT.L D0
DIVU.W @magnification(A6),D0
SWAP D0
MOVE.W D0,@subCol(A6)
SWAP D0
MOVE.W D0,D1
LSR.W #3,D0
EXT.L D0
ADD.L D0,@inDataPtr(A6)
AND.W #7,D1
EOR.W #7,D1
MOVE.W D1,@startBit(A6)
BRA.S @3
; Case 2, negative magnification
@2 MOVE.W @magnification(A6),D1
NEG.W D1
MOVE.W @startRow(A6),D0
MULU.W D1,D0
MULU.W @inRowBytes(A6),D0
ADD.L D0,@inDataPtr(A6)
MOVE.W @startCol(A6),D0
MULU.W D1,D0
MOVE.W D0,D1
LSR.W #3,D0
EXT.L D0
ADD.L D0,@inDataPtr(A6)
AND.W #7,D1
EOR.W #7,D1
MOVE.W D1,@startBit(A6)
CLR.W @subRow(A6)
CLR.W @subCol(A6)
; Process each row
@3 MOVE.L @inDataPtr(A6),A0
MOVE.L @outDataPtr(A6),A1
; Case on magnification
MOVE.W @magnification(A6),D0
CMP.W #1,D0
BGT @magnif
BLT.S @reduct
; Full size case, test if byte aligned
MOVE.W @startBit(A6),D2
CMP.W #7,D2
BNE.S @6
; Full size case, aligned
MOVE.W @numCols(A6),D1
LSR.W #3,D1
SUB.W #1,D1
BLT.S @5
@4 MOVE.B (A0)+,(A1)+
DBF D1,@4
@5 MOVE.W @numCols(A6),D1
AND.W #7,D1
BEQ @unpack
SUB.W #8,D1
NEG.W D1
MOVE.B (A0)+,D3
LSR.B D1,D3
LSL.B D1,D3
MOVE.B D3,(A1)+
BRA @unpack
; Full size case, not aligned
@6 ADD.W #1,D2
MOVE.W @numCols(A6),D1
LSR.W #3,D1
SUB.W #1,D1
BLT.S @8
@7 MOVE.B (A0)+,D3
LSL.W #8,D3
MOVE.B (A0),D3
LSR.W D2,D3
MOVE.B D3,(A1)+
DBF D1,@7
@8 MOVE.W @numCols(A6),D1
AND.W #7,D1
BEQ.S @unpack
SUB.W #8,D1
NEG.W D1
MOVE.B (A0)+,D3
LSL.W #8,D3
MOVE.B (A0),D3
LSR.W D2,D3
LSR.B D1,D3
LSL.B D1,D3
MOVE.B D3,(A1)+
BRA.S @unpack
; Reduction case
@reduct NEG.W D0
MOVE.W @numCols(A6),D1
SUB.W #1,D1
MOVE.W @startBit(A6),D2
MOVE.W #$80,D3
MOVE.W D2,D4
EOR.W #7,D4
@10 MOVE.W D4,D5
LSR.W #3,D5
BTST D2,(A0,D5.W)
BEQ.S @11
OR.B D3,(A1)
@11 SUB.W D0,D2
ADD.W D0,D4
ROR.B #1,D3
BCS.S @12
DBF D1,@10
BRA.S @unpack
@12 ADD.W #1,A1
DBF D1,@10
BRA.S @unpack
; Magnification case
@magnif MOVE.W @numCols(A6),D1
SUB.W #1,D1
MOVE.W @startBit(A6),D2
MOVE.W #$80,D3
MOVE.W D0,D4
SUB.W @subCol(A6),D4
@14 BTST D2,(A0)
BEQ.S @15
OR.B D3,(A1)
@15 ROR.B #1,D3
BCC.S @16
ADD.W #1,A1
@16 SUB.W #1,D4
BNE.S @17
MOVE.W D0,D4
SUB.W #1,D2
BGE.S @17
ADD.W #1,A0
ADD.W #8,D2
@17 DBF D1,@14
; Unpack the data if needed
@unpack MOVE.L @outDataPtr(A6),A0
MOVE.L A0,A1
MOVE.W @outRowBytes(A6),D0
EXT.L D0
ADD.L D0,A0
MOVE.L D0,D1
LSL.L #3,D1
DIVU.W @outPixelBits(A6),D1
SUB.W #1,D1
MOVE.W D1,D2
EXT.L D1
LSR.L #3,D1
ADD.L D1,A1
MOVE.W D2,D1
AND.W #7,D1
EOR.W #7,D1
SUB.W #1,D0
MOVE.W @outPixelBits(A6),D2
CMP.W #1,D2
BEQ @nextR
CMP.W #2,D2
BEQ.S @twoBit
CMP.W #4,D2
BEQ.S @fourBit
; Unpack into 8 bit pixels
@eight1 CLR.W D2
BTST D1,(A1)
BEQ.S @eight2
ADD.W #1,D2
@eight2 MOVE.B D2,-(A0)
ADD.W #1,D1
AND.W #7,D1
BNE.S @eight3
SUB.W #1,A1
@eight3 DBF D0,@eight1
BRA.S @nextR
; Unpack into 4 bit pixels
@fourBit CLR.W D2
BTST D1,(A1)
BEQ.S @four2
ADD.W #1,D2
@four2 ADD.W #1,D1
BTST D1,(A1)
BEQ.S @four3
BSET #4,D2
@four3 MOVE.B D2,-(A0)
ADD.W #1,D1
AND.W #7,D1
BNE.S @four4
SUB.W #1,A1
@four4 DBF D0,@fourBit
BRA.S @nextR
; Unpack into 2 bit pixels
@twoBit CLR.W D2
BTST D1,(A1)
BEQ.S @two2
ADD.W #1,D2
@two2 ADD.W #1,D1
BTST D1,(A1)
BEQ.S @two3
BSET #2,D2
@two3 ADD.W #1,D1
BTST D1,(A1)
BEQ.S @two4
BSET #4,D2
@two4 ADD.W #1,D1
BTST D1,(A1)
BEQ.S @two5
BSET #6,D2
@two5 MOVE.B D2,-(A0)
ADD.W #1,D1
AND.W #7,D1
BNE.S @two6
SUB.W #1,A1
@two6 DBF D0,@twoBit
; See if all the rows have been processed
@nextR SUB.W #1,@numRows(A6)
BEQ.S @exit
; Update output pointer
MOVE.W @outRowBytes(A6),D1
EXT.L D1
ADD.L D1,@outDataPtr(A6)
; Case on magnification sign
MOVE.W @magnification(A6),D0
BLT.S @nextIn
; Update sub row counter
ADD.W #1,@subRow(A6)
CMP.W @subRow(A6),D0
BGT.S @dup
; Update input pointer
CLR.W @subRow(A6)
MOVE.W @inRowBytes(A6),D1
EXT.L D1
ADD.L D1,@inDataPtr(A6)
BRA @3
; Update input pointer for reduction case
@nextIn MOVE.W @inRowBytes(A6),D1
NEG.W D0
MULU.W D0,D1
ADD.L D1,@inDataPtr(A6)
BRA @3
; We are going to cheat and duplicate the last line
@dup MOVE.W @outRowBytes(A6),D0
LSR.W #1,D0
SUB.W #1,D0
MOVE.L @outDataPtr(A6),A0
MOVE.L A0,A1
MOVE.W @outRowBytes(A6),D1
EXT.L D1
SUB.L D1,A0
@dup1 MOVE.W (A0)+,(A1)+
DBF D0,@dup1
BRA.S @nextR
; Clean up and exit
@exit MOVEM.L (SP)+,D3-D7
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes3'
DoMonochrome PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoMonochrome (rDataPtr: Ptr;
; gDataPtr: Ptr;
; bDataPtr: Ptr;
; inRowBytes: INTEGER;
; outDataPtr: Ptr;
; viewRect: Rect;
; magnification: INTEGER;
; rLUT: TLookUpTable;
; gLUT: TLookUpTable;
; bLUT: TLookUpTable);
; Parameter Offsets
@rDataPtr EQU 40
@gDataPtr EQU 36
@bDataPtr EQU 32
@inRowBytes EQU 30
@outDataPtr EQU 26
@viewRect EQU 22
@magnification EQU 20
@rLUT EQU 16
@gLUT EQU 12
@bLUT EQU 8
; Size of parameters
@params EQU 36
; Local variables
@numRows EQU -2
@numCols EQU -4
@subRow EQU -6
@subCol EQU -8
@inDataPtr EQU -12
; Size of local variables
@localVars EQU -12
; Save registers
LINK A6,#@localVars
MOVEM.L D3-D7/A2-A5,-(SP)
; Compute size of viewed rect
MOVE.L @viewRect(A6),A0
MOVE.W 4(A0),D0
SUB.W (A0),D0
MOVE.W D0,@numRows(A6)
MOVE.W 6(A0),D0
SUB.W 2(A0),D0
MOVE.W D0,@numCols(A6)
; Move input pointer to start of rect
CLR.L @inDataPtr(A6)
MOVE.W @magnification(A6),D0
BLT.S @1
MOVE.W (A0),D1
EXT.L D1
DIVU.W D0,D1
SWAP D1
MOVE.W D1,@subRow(A6)
SWAP D1
MULU.W @inRowBytes(A6),D1
ADD.L D1,@inDataPtr(A6)
MOVE.W 2(A0),D1
EXT.L D1
DIVU.W D0,D1
SWAP D1
MOVE.W D1,@subCol(A6)
SWAP D1
EXT.L D1
ADD.L D1,@inDataPtr(A6)
BRA.S @2
@1 NEG.W D0
MOVE.W (A0),D1
MULU.W D0,D1
MULU.W @inRowBytes(A6),D1
ADD.L D1,@inDataPtr(A6)
MOVE.W 2(A0),D1
MULU.W D0,D1
ADD.L D1,@inDataPtr(A6)
CLR.W @subRow(A6)
CLR.W @subCol(A6)
; A0 is the output pointer
@2 MOVE.L @outDataPtr(A6),A0
; Loop down through rows, set up input pointers
@3 MOVE.L @inDataPtr(A6),A1
MOVE.L A1,A2
MOVE.L A1,A3
ADDA.L @rDataPtr(A6),A1
ADDA.L @gDataPtr(A6),A2
ADDA.L @bDataPtr(A6),A3
; D0 is magnification
MOVE.W @magnification(A6),D0
; D1 is subCol
MOVE.W @subCol(A6),D1
; D2 is numCols - 1
MOVE.W @numCols(A6),D2
SUB.W #1,D2
; A4-A6 are LUTs
MOVE.L A6,-(SP)
MOVE.L @rLUT(A6),A4
MOVE.L @gLUT(A6),A5
MOVE.L @bLUT(A6),A6
; D3 will hold pixel values
CLR.W D3
; Case on magnification
CMP.W #1,D0
BGT.S @5
BLT.S @8
; No magnificaiton case
@4 MOVE.B (A1)+,D3
MOVE.B (A4,D3.W),D4
MOVE.B (A2)+,D3
ADD.B (A5,D3.W),D4
MOVE.B (A3)+,D3
ADD.B (A6,D3.W),D4
MOVE.B D4,(A0)+
DBF D2,@4
BRA.S @9
; Magnification case
@5 MOVE.B (A1)+,D3
MOVE.B (A4,D3.W),D4
MOVE.B (A2)+,D3
ADD.B (A5,D3.W),D4
MOVE.B (A3)+,D3
ADD.B (A6,D3.W),D4
@6 CMP.W D0,D1
BNE.S @7
CLR.W D1
MOVE.B (A1)+,D3
MOVE.B (A4,D3.W),D4
MOVE.B (A2)+,D3
ADD.B (A5,D3.W),D4
MOVE.B (A3)+,D3
ADD.B (A6,D3.W),D4
@7 ADD.W #1,D1
MOVE.B D4,(A0)+
DBF D2,@6
BRA.S @9
; Reduction case
@8 MOVE.B (A1),D3
MOVE.B (A4,D3.W),D4
MOVE.B (A2),D3
ADD.B (A5,D3.W),D4
MOVE.B (A3),D3
ADD.B (A6,D3.W),D4
MOVE.B D4,(A0)+
SUB.W D0,A1
SUB.W D0,A2
SUB.W D0,A3
DBF D2,@8
; Move to next row
@9 MOVE.L (SP)+,A6
CMP.W #1,D0
BLT.S @10
ADD.W #1,@subRow(A6)
CMP.W @subRow(A6),D0
BNE.S @11
CLR.W @subRow(A6)
MOVE.W @inRowBytes(A6),D0
EXT.L D0
ADD.L D0,@inDataPtr(A6)
BRA.S @11
@10 NEG.W D0
MULU.W @inRowBytes(A6),D0
ADD.L D0,@inDataPtr(A6)
@11 SUB.W #1,@numRows(A6)
BGT @3
; Clean up and exit
MOVEM.L (SP)+,D3-D7/A2-A5
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes3'
DoDither24 PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoDither24 (inDataPtr: Ptr;