
I've been playing with PBv4a9 and using the 2D drawing commands and noticed that the 'DrawAlphaImage()' command is veeeeeeerrry slow.
I loaded a WinXP icon with an eight bit alpha channel and then drawn 10,000 of these on another image created with 'CreateImage()' using the 'DrawImage()' command, this takes about 200ms
Then i converted this icon into a 32 bit PNG with an alpha channel, then loaded this and drawn 10,000 using the 'DrawAlphaImage()' command. This takes 9800ms!!!
These are with the debugger OFF. Are these time what is expected or does the 'DrawAlphaImage()' command need a bit of love?
Code: Select all
Enumeration
#WINDOW_MAIN
#IMAGE_GADGET
#IMAGE_SMALL
#IMAGE_MAIN
#FONT_MAIN
EndEnumeration
Global ImageWidth = 400
Global ImageHeight = 200
Global XPos.l, YPos.l, LoadedImageWidth.l, LoadedImageHeight.l
Global File.s
Global RequesterText.s = "Choose an image"
Global DefaultFile.s = ""
Global Pattern.s = "Icon (*.ico)|*.ico|Png (*.png)|*.png"
UsePNGImageDecoder()
File = OpenFileRequester(RequesterText, DefaultFile, Pattern, 0)
If File
StartTime.l = ElapsedMilliseconds()
LoadImage(#IMAGE_SMALL, File)
LoadedImageWidth = ImageWidth(#IMAGE_SMALL)
LoadedImageHeight = ImageHeight(#IMAGE_SMALL)
If CreateImage(#IMAGE_MAIN, ImageWidth,ImageHeight)
If StartDrawing(ImageOutput(#IMAGE_MAIN))
Box(0, 0,ImageWidth, ImageHeight, RGB(255, 255, 255))
For x.l = 0 To 10000
XPos = Random(ImageWidth) - (ImageWidth(#IMAGE_SMALL) / 2)
YPos = Random(ImageHeight) - (ImageHeight(#IMAGE_SMALL) / 2)
If SelectedFilePattern() = 1
DrawAlphaImage(ImageID(#IMAGE_SMALL), XPos, YPos)
Else
DrawImage(ImageID(#IMAGE_SMALL), XPos, YPos)
EndIf
Next x
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, ImageWidth, ImageHeight, RGB(0, 0, 0))
StopDrawing()
EndTime.l = ElapsedMilliseconds()
EndIf
EndIf
#TEXT = "Drawing Using Images"
#FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(#WINDOW_MAIN,0,0,ImageWidth+20,ImageHeight+20,#TEXT,#FLAGS)
If CreateGadgetList(WindowID(#WINDOW_MAIN))
ImageGadget(#IMAGE_GADGET,10,10,ImageWidth,ImageHeight,ImageID(#IMAGE_MAIN))
EndIf
MessageRequester("Timings", "The amount of time taken to complete all drawing actions was:" + #LF$ + #LF$ + Str(EndTime - StartTime) + "ms")
Repeat
Event.l = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
End
EndIf