DrawAlphaImage: Speed much improved

Everything else that doesn't fall into one of the other PB categories.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

DrawAlphaImage: Speed much improved

Post by netmaestro »

I used the included code with PB v4.31 and with PB v4.40b3 and compared the results. The image is not small, 442*518. Your mileage may vary, but here's mine:

4.31 - 6000 ms or 15ms/draw
4.40 - 2798 ms or 7ms/draw

cutting the draw time by more than half.

Code: Select all

InitNetwork()
If Not ReceiveHTTPFile("http://www.lloydsplace.com/babytuxalpha.png", GetTemporaryDirectory()+"babytuxalpha.png")
  MessageRequester("oops...", "Can't download the image",#MB_ICONERROR)
EndIf

UsePNGImageDecoder()
LoadImage(0,GetTemporaryDirectory()+"babytuxalpha.png")

CreateImage(1, ImageWidth(0), ImageHeight(0))

t=ElapsedMilliseconds()
For i=1 To 400
  StartDrawing(ImageOutput(1))
    DrawAlphaImage(ImageID(0),0,0)
  StopDrawing()
Next
MessageRequester("",Str(ElapsedMilliseconds()-t),$80)
I mainly constructed this test because while b3 was in development Freak said somewhere that Fred had optimized it. Imho - he's right!
Last edited by netmaestro on Mon Sep 21, 2009 12:07 am, edited 1 time in total.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: DrawAlphaImage: Speed much improved

Post by srod »

Aye, that does look quite impressive.

Cute picture! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: DrawAlphaImage: Speed much improved

Post by Rescator »

well, your drawing a 24bit image, try with a 32bit image.
CreateImage(1, ImageWidth(0), ImageHeight(0),32)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: DrawAlphaImage: Speed much improved

Post by netmaestro »

rescator wrote:well, your drawing a 24bit image, try with a 32bit image.
Nope. I'm drawing a 32bit source on to a 24bit target. The presence or absence of an alpha channel in the target has no bearing on what happens with AlphaBlend_ which, btw DrawAlphaImage still uses.
BERESHEIT
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: DrawAlphaImage: Speed much improved

Post by freak »

> The presence or absence of an alpha channel in the target has no bearing on what happens with AlphaBlend_ which, btw DrawAlphaImage still uses.

Only for non-image outputs. For ImageOutput() we use a customized routine to support the new drawing modes. This is where the big difference comes from. Also there is a slight difference between a 24bit or 32bit target image because there is an additional alphachannel to multiply, but the difference is not that significant.

Fred optimized our support library for alphablending to a DC which still uses the AlphaBlend API. What benefits from that is the ImageGadget, the ButtonImageGadget and DrawAlphaImage for non-image outputs.
quidquid Latine dictum sit altum videtur
Post Reply