anti-aliased lines
Posted: Wed Nov 24, 2004 2:32 am
Hi guys
Here is a bit of code I ported from Blitz a while ago. It draws anti-aliased lines. It's FAR slower than the built-in PB lineXY() command.
I was hoping someone had a faster or better way to do this?
Here is a bit of code I ported from Blitz a while ago. It draws anti-aliased lines. It's FAR slower than the built-in PB lineXY() command.
I was hoping someone had a faster or better way to do this?
Code: Select all
; combine two pixels at specified w=weight=0-255
Procedure MergePixel(x,y,r,g,b,w)
col = Point(x,y) : r2 = Red(col)
g2 = Green(col) : b2 = Blue(col)
rnew = ((r * w) >> 8) + ((r2 * (255 - w)) >> 8)
gnew = ((g * w) >> 8) + ((g2 * (255 - w)) >> 8)
bnew = ((b * w) >> 8) + ((b2 * (255 - w)) >> 8)
Plot(x,y,RGB(rnew,gnew,bnew))
EndProcedure
; draw anti aliased line on current drawing surface
Procedure AntiLineXY(x1,y1,x2,y2,col)
r = Red(col)
g = Green(col)
b = Blue(col)
FrontColor(r,g,b)
Plot(x1,y1,col)
Plot(x2,y2,col)
xd = x2 - x1
yd = y2 - y1
If (xd = 0 Or yd = 0)
LineXY(x1,y1,x2,y2)
ProcedureReturn
EndIf
If Abs(xd) > Abs(yd)
If (x1>x2)
tmp = x1: x1 = x2: x2 = tmp
tmp = y1: y1 = y2: y2 = tmp
xd = x2-x1
yd = y2-y1
EndIf
grad = yd * 65536 / xd
yf = y1 * 65536
For x = x1 + 1 To x2 - 1
yf = yf + grad
w = (yf >> 8) & $FF
y = yf >> 16
MergePixel(x,y,r,g,b,255-w)
MergePixel(x,y+1,r,g,b,w)
Next
Else
If (y1 > y2)
tmp = x1: x1 = x2: x2 = tmp
tmp = y1: y1 = y2: y2 = tmp
xd = x2 - x1
yd = y2 - y1
EndIf
grad = xd * 65536 / yd
xf = x1 * 65536
For y = y1 + 1 To y2 - 1
xf = xf + grad
w = (xf >> 8) & $FF
x = xf >> 16
MergePixel(x,y,r,g,b,255-w)
MergePixel(x+1,y,r,g,b,w)
Next
EndIf
EndProcedure