
One wonders if PB's native Plot() function could be made faster.
Feel free to modify/improve this code.
Code: Select all
imWidth = 1024: imHeight = 768: imHeightm1 = imHeight - 1: imWidthm1 = imWidth - 1
Procedure PlotPixel(x, y)
Shared buffer, imHeightm1, pitch
hm1 = buffer + ((imHeightm1 - y) * pitch)
PokeL(hm1 + x * 4, $ff0000)
EndProcedure
LoadFont(0, "Arial", 14)
result = CreateImage(0, imWidth, imHeight, 32)
If result = 0: MessageRequester("Error", "Unable to create image."): End: EndIf
; Structure Pixel
; Pixel.l
; EndStructure
OpenWindow(0, 0, 0, imWidth, imHeight, "Fast Pixels", $CA0001)
; GetObject_(ImageID(0), SizeOf(BITMAP), @bmp.BITMAP)
; Width = bmp\bmWidth
; Height = bmp\bmHeight
; widthbytes = bmp\bmWidthbytes
; *colorbits = bmp\bmBits
; *pxout.LONG
;
; then = ElapsedMilliseconds()
; For rep = 1 To 50
; For y = 0 To imHeight - 1
; *pxout = *colorbits + (widthBytes * y)
; For x = 0 To widthbytes - 1 Step 3
; *pxout\l = RGB(33,$88,$44)
; *pxout + 3
; Next
; Next
; Next
; now = ElapsedMilliseconds()
StartDrawing(ImageOutput(0))
then2 = ElapsedMilliseconds()
For rep = 1 To 50
For y = 0 To imHeightm1
For x = 0 To imWidthm1
Plot(x, y, $448821)
Next
Next
Next
StopDrawing()
StartDrawing(WindowOutput(0))
DrawImage(ImageID(0), 0, 0)
now2 = ElapsedMilliseconds()
StopDrawing()
StartDrawing(ImageOutput(0))
buffer = DrawingBuffer() ; Get the start address of the buffer
pitch = DrawingBufferPitch()
StopDrawing()
then3 = ElapsedMilliseconds()
For rep = 1 To 50
For y = 0 To imHeightm1
For x = 0 To imWidthm1
hm1 = buffer + ((imHeightm1 - y) * pitch)
PokeL(hm1 + x * 4, $ff0000)
Next
Next
Next
StartDrawing(WindowOutput(0))
DrawImage(ImageID(0), 0, 0)
now3 = ElapsedMilliseconds()
StopDrawing()
;APPROXIMATELY 3 TIMES FASTER
StartDrawing(ImageOutput(0))
buffer = DrawingBuffer() ; Get the start address of the buffer
pitch = DrawingBufferPitch()
StopDrawing()
then4 = ElapsedMilliseconds()
For rep = 1 To 50
hm1 = buffer + (imHeightm1 * pitch)
For y = 0 To imHeightm1
; hm1 = buffer + ((imHeightm1 - y) * pitch)
For x = 0 To imWidthm1
PokeL(hm1 + x * 4, $0000ff)
Next
hm1 - pitch
Next
Next
StartDrawing(WindowOutput(0))
DrawImage(ImageID(0), 0, 0)
now4 = ElapsedMilliseconds()
DrawingFont(FontID(0))
;DrawText(100,150,StrF((now - then) / 1,0)+ " milliseconds")
DrawText(100,175,StrF((now2 - then2) / 1,0)+ " milliseconds")
DrawText(100,200,StrF((now3 - then3) / 1,0)+ " milliseconds")
DrawText(100, 225, StrF((now4 - then4) / 1,0) + " milliseconds")
StopDrawing()
Repeat
Event = WaitWindowEvent()
Until Event = #WM_CLOSE
;DeleteObject_(bmp)
FreeImage(0)
End