Page 1 of 1

DrawAlphaImage: Speed much improved

Posted: Sat Sep 19, 2009 4:59 pm
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!

Re: DrawAlphaImage: Speed much improved

Posted: Sat Sep 19, 2009 7:23 pm
by srod
Aye, that does look quite impressive.

Cute picture! :)

Re: DrawAlphaImage: Speed much improved

Posted: Sun Sep 20, 2009 11:45 pm
by Rescator
well, your drawing a 24bit image, try with a 32bit image.
CreateImage(1, ImageWidth(0), ImageHeight(0),32)

Re: DrawAlphaImage: Speed much improved

Posted: Mon Sep 21, 2009 12:05 am
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.

Re: DrawAlphaImage: Speed much improved

Posted: Mon Sep 21, 2009 6:25 pm
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.