[Lazarus] Fast drawing to canvas

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Feb 9 12:02:18 CET 2012


On 9 February 2012 02:52, Darius Blaszyk  wrote:
> Despite all the advices, none of the suggestions of drawing on a TPaintBox or creating a TCustomControl actually speed up the painting significantly. Therefore I did some profiling. It appears that loading a 40kb png file (50% HD) from a stream takes about 60msec another 30msec is used to paint the bitmap to screen. It all results in approx. 11fps which is actually pretty poor when you imagine a full HD loop will make the rate drop 2.5fps.
>

A quick test on my system, using my own "animation" images.

  * using the fpGUI toolkit
  * Each BMP image is 140kb (fpGUI doesn't have PNG support yet)
  * each image is loaded one-by-one. No images are cached.
  * just before a new image is loaded, the old image is freed.
  * Partition has the ReiserFS filesystem under Linux 64-bit
  * hard drive is an avg Seagate 250GB sata drive.

Initial framerate was 1500 fps.  I couldn't actually see any animation
at that speed, and had to add writeln(i) statements to make sure I am
loading all images - which it did. :-)

I then added a sleep (10) between each image load/paint job. Animation
was now visible to the eye and running at 92fps. Having a sleep(1)
gives me 577fps.

I don't know what resolution your images are, so I simply used the
40kb file size you mentioned as the bare minimum. I took a screenshot
of my desktop and resized the image and saved it to PNG until I got +-
a 40kb file. I then created a 26 frame animation using that image an
the background. I then converted those images to BMP, so fpGUI could
read them. PNG to BMP made the images go from 40kb to 140kb in size.


I'll wait for your sample images before I take another look. But from
my initial testing, there is something seriously screwy in your case
to get only 11fps. I can't imagine loading a 40kb PNG vs a 140kb BMP
can make up that a huge difference in framerate.

-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net




More information about the Lazarus mailing list