; ; PROJECT: ppt ; MODULE : render2.a ; ; $Id: render2.a,v 1.7 1997-10-06 21:49:50 jj Exp $ ; ; Support functions for renderer. Mainly to fasten things up a bit ;) ; ; XDEF @RGBDistance XDEF @BestMatchPen4 XDEF @BestMatchPen8 XDEF @Plane2Chunk XDEF @QuickMapRow XDEF _BestMatchPen8 XDEF _Plane2Chunk XDEF _QuickMapRow XDEF @QuickMapARGBDeepRow XDEF _QuickMapARGBDeepRow ; ; INPUTS: d0.h = r1, d0.l = g1, ; d1.h = b1, d1.l = g2, ; d2.h = r2, d2.l = b2. ; ; OUTPUTS: D0 = distance^2 ; TRASHED: D1,D2 ; ; This function returns the square of the distance of two rgb vectors ; (r1,g1,b1) and (r2,g2,b2) ; ; This code is rather time-critical, so that is why it is written in assembler. section code,code @RGBDistance: move.l D7,-(A7) ; our scratch register ; First calculate green. sub.w D1,D0 move.w D0,D7 muls.w D7,D7 ; D7 = (g1-g2)^2 ; Then blue swap D1 sub.w D2,D1 muls.w D1,D1 ; D1 = (b1-b2)^2 add.l D1,D7 ; And finally red. swap D0 swap D2 sub.w D0,D2 muls.w D2,D2 ; D2 = (r1-r2)^2 add.l D2,D7 move.l D7,D0 move.l (A7)+,D7 rts ; ; BestMatchPen8() calculates the closest pen for 8bit color values. ; ; Input : A0 = pointer to colortable (ARGBPixel_T *) ; D4.w = ncolors ; D0.b = r ; D1.b = g ; D2.b = b ; ; Output: ; D0 = pen number ; ; used: D6 holds offset ; D7 holds minimum ; D3 is trash (holds mask value); ; D5 is counter _BestMatchPen8: @BestMatchPen8: movem.l D2-D7,-(A7) move.w #$00FF,D3 ; mask ; adjust registers for RGBDistance and.w D3,D0 ; D0 = ????00RR swap D0 ; D0 = 00RR???? move.w D1,D0 ; D0 = ??RR??GG and.w D3,D0 ; D0 = 00RR00GG move.w D2,D1 ; D1 = ??????BB and.w D3,D1 ; D1 = ????00BB swap D1 ; D1 = 00BB???? moveq.l #-1,D7 ; D7 holds minimum value, D7 = 0xFFFFFFFF moveq.l #0,D5 ; D5 is counter ; Fetch the color values from the colortable ; We'll have to set D2.h to R, D1.l to G and D2.l to B __bmp8_loop: add.l #1,A0 ; Skip alpha ; Get red move.b (A0)+,D2 ; D2 = ??????rr and.w D3,D2 ; D2 = ????00rr swap D2 ; D2 = 00rr???? ; Get green move.b (A0)+,D1 ; D1 = 00BB??gg and.w D3,D1 ; D1 = 00BB00gg ; Get blue move.b (A0)+,D2 ; D2 = 00rr??bb and.w D3,D2 ; D2 = 00rr00bb ; Color registers are done, so calculate the distance! movem.l D0-D1,-(A7) bsr.w @RGBDistance ; D0 = distance tst.l D0 ; if D0 = 0, a perfect match was found beq.w __bmp8_quickend ; thus, skip to end cmp.l D7,D0 ; res = D0-D7. if res < 0 ts D0-D7 < 0 <=> D0 D0