; TMS320C6x assembly language code to perform ordered dithering ; We assume that the thresholds are periodic, and hence, will be ; circularly addressed. The two instructions that set the AMR ; register set up the modulo addressing. Remove them if the ; thresholds are in a linear array. MVK .S1 0x00ff,A8 ; white pixel #1 || MVK .S2 0x0001,AMR ; modulo block size 2^2 SHL .S1 A8,8,A9 ; white pixel #2 || MVKH .S2 0x4000,AMR ; modulo addr reg. B6 SHL .S1 A8,16,A10 ; white pixel #3 || SHL .S2 A8,24,B9 ; white pixel #4 ; initialize ; A2 number of pixels divided by 4 ; A6 pointer to pixels (will be overwritten) ; B6 pointer to thresholds dith2: LDW .D1 *A6,A4 ; read 4 pixels (bytes) LDW .D2 *B6++,B4 ; read 4 thresholds EXTU .S1 A4,24,24,A12 ; extract pixel #2 EXTU .S2 B4,24,24,B12 ; extract threshold #2 ZERO .L1 A5 ; store output in A5 CMPLTU .L2 A12,B12,B0 ; B0 = (A12 < B12) EXTU .S1 A4,16,24,A13 ; extract pixel #2 EXTU .S2 B4,16,24,B13 ; extract threshold #2 [!B0] OR .L1 A5,A8,A5 ; output of pixel 1 CMPLTU .L2 A13,B13,B1 ; B1 = (A13 < B13) EXTU .S1 A4,8,24,A14 ; extract pixel #3 EXTU .S2 B4,8,24,B14 ; extract threshold #3 [!B1] OR .L1 A5,A9,A5 ; output of pixels 1-2 CMPLTU .L2 A14,B14,B2 ; B2 = (A14 < B14) EXTU .S1 A4,0,24,A15 ; extract pixel #4 EXTU .S2 B4,0,24,B15 ; extract threshold #4 [!B2] OR .L2 A5,B9,B5 ; output of pixels 1-3 CMPLTU .L1 A15,B15,A1 ; B2 = (A15 < B15) [!A1] OR .S1 B5,A11,A5 ; output of pixels 1-4 STW .D1 A5,*A6++ ; store results [A2] SUB .L1 A2,1,A2 ; decrement loop count [A2] B .L2 dith2 ; if A2 != 0, branch