Played a little bit around and found no speed increase when using Line instead of LineXY - I'll get also nearly same times for Windows API Lineto...
Code: Select all
; Simple Line
Procedure FastlineInit(Window,Width,Color)
Global FastLineDC=GetDC_(WindowID(Window))
Global FastLinePen=CreatePen_(#PS_SOLID,Width,Color)
Global FastLineOld=SelectObject_(FastLineDC,FastLinePen)
EndProcedure
Procedure FastLine(x,y,x1,y1)
MoveToEx_(FastLineDC,x,y,0)
LineTo_(FastLineDC,x1,y1)
EndProcedure
Procedure FastlineStop()
DeleteObject_(FastLinePen)
DeleteObject_(FastLineOld)
EndProcedure
; Antialiased Line
Procedure.l Limit(x)
If x<0
ProcedureReturn 0
ElseIf x>255
ProcedureReturn 255
Else
ProcedureReturn x
EndIf
EndProcedure
Procedure AntiLineInit(Window)
Structure DxStructure
StructureUnion
l.l
w.w
EndStructureUnion
EndStructure
Global DxMem,DxMul,DxPix; Plot-Beschleunigung...
Global *DX.DxStructure
windc=StartDrawing(ScreenOutput())
DxMem=DrawingBuffer()
DxMul=DrawingBufferPitch()
DxPix=DrawingBufferPixelFormat()
Global Dim AntiA(255)
Global Dim AntiB(255)
#AntiStrength=5
Dummy=(#AntiStrength-5)<<4
For k=0 To 255
AntiA(k)=Limit(255-k+Dummy)
AntiB(k)=Limit(k+Dummy)
Next k
EndProcedure
Macro ColRed(col)
(col&$ff)
EndMacro
Macro ColGreen(col)
(col>>8&$ff)
EndMacro
Macro ColBlue(col)
(col>>16&$ff)
EndMacro
Macro ColMix(c,r,g,b,w)
; (c) Michael Vogel
; 24/32 Bit-Pixel: bbbbbbbb|gggggggg|rrrrrrrr
( (r*w+ColRed(c)*(255-w))>>8 + (g*w+ColGreen(c)*(255-w))&$ff00 + (b*w+ColBlue(c)*(255-w))<<8&$ff0000 )
EndMacro
Procedure MergePixel(x,y,r,g,b,w)
If x>=0 And x<screenx And y>=0 And y<ScreenY
If DxPix>=#PB_PixelFormat_32Bits_RGB
*DX=DxMem+x<<2+y*DxMul
*DX\l=ColMix(*DX\l,b,g,r,w)
ElseIf DxPix>=#PB_PixelFormat_24Bits_RGB
*DX=DxMem+x*3+y*DxMul
*DX\l=ColMix(*DX\l,b,g,r,w)|(*DX\l&$FF000000)
ElseIf DxPix>=#PB_PixelFormat_16Bits
*DX=DxMem+x<<1+y*DxMul
*DX\w=ColMurx(*DX\w,r,g,b,w)
;Plot(x,y,ColMix(Point(x,y),r,g,b,w))
;SetPixel_(hdc,x,y,col)
EndIf
EndIf
EndProcedure
Procedure AntiLineXY(x1,y1,x2,y2,col)
Protected r = ColRed(col)
Protected g = ColGreen(col)
Protected b = ColBlue(col)
Protected xd=x2-x1
Protected yd=y2-y1
Protected x,y,xf,yf
Protected grad,w
MergePixel(x1,y1,r,g,b,255)
MergePixel(x2,y2,r,g,b,255)
If xd=0 Or yd=0
LineXY(x1,y1,x2,y2,col)
ProcedureReturn
EndIf
If Abs(xd)>Abs(yd)
If (x1>x2)
Swap x1,x2
Swap y1,y2
xd=-xd
yd=-yd
EndIf
grad=yd<<16/xd
yf=y1<<16
For x=x1+1 To x2-1
yf+grad
w=(yf>>8)&$FF
y=yf>>16
MergePixel(x,y,r,g,b,AntiA(w))
MergePixel(x,y+1,r,g,b,AntiB(w))
Next
Else
If (y1>y2)
Swap x1,x2
Swap y1,y2
xd=-xd
yd=-yd
EndIf
grad=xd<<16/yd
xf=x1<<16
For y=y1+1 To y2-1
xf+grad
w=(xf>>8)&$FF
x=xf>>16
MergePixel(x,y,r,g,b,AntiA(w))
MergePixel(x+1,y,r,g,b,AntiB(w))
Next
EndIf
EndProcedure
_X=GetSystemMetrics_(#SM_CXSCREEN)-8
_Y=GetSystemMetrics_(#SM_CYSCREEN)-68
InitSprite()
OpenWindow(0,0,0,_X,_Y,"")
;OpenWindowedScreen(WindowID(Window),0,0,_X,_Y,0,0,0)
StartDrawing(WindowOutput(0))
;FastlineInit(0,1,#Blue)
;AntiLineInit(0)
Zeit=GetTickCount_()
For i=0 To _X Step 8
For j=0 To _X Step 8
LineXY(i,0,j,_Y)
;Line(i,0,j-i,_Y+1)
;FastLine(i,0,j,_Y)
;AntiLineXY(i,0,j,_Y,#Red)
Next j
Next i
Zeit-GetTickCount_()
FastLineStop()
StopDrawing()
MessageRequester("Fertig","Zeit: "+Str(-Zeit)+"ms",0)