[Lazarus] Fast drawing to canvas

Graeme Geldenhuys graemeg.lists at gmail.com
Fri Feb 10 11:31:20 CET 2012


2012/2/9 Darius Blaszyk :
> I've put up the test app on the CCR. All three methods draw at roughly 10fps
> on windows and 6fps on mac.

Using your project as-is, I get 9fps under Linux. Also I have a 10-20
seconds delay just for the program to start up - I didn't investigate
this.

I then went and modified your TImage code to look as shown below...
Basically this is so I can do a direct comparison to my fpGUI test
project. It now loads 1.5Mbyte BMP versions of your images. This gives
me a 7fps animation. Yuck!  Oh, and I had to enable double buffering,
otherwise I would have gone into shock. ;-)


----------------------------
procedure TForm1.mnuTImageClick(Sender: TObject);
var
  s: TDateTime;
  i: integer;
  j: integer;
  f: boolean;
begin
  PageControl1.ActivePage := ImageTabSheet;

  s := Now;
    for i := 1 to 23 do
    begin
        Image1.Picture.LoadFromFile(Format('./images_50/%.4d.bmp', [i]));
        Application.ProcessMessages;
    end;

  AddTestToListBox('TImage', 23 / ((Now - s) * 24 * 3600));
end;
----------------------------


So this got me thinking. We already know that fcl-image really really
sucks at loading images from disk. fpGUI proves with it's own JPG and
BMP loading code, that it could be done in a fraction of the time it
takes fcl-image.

So to prove this point further, I quickly implement PNG support in
fpGUI, by using the fcl-image loading code, and populating a TfpgImage
instead. Now my fpGUI based animation test can use BMP, JPG and PNG
images.

The result....using 50% HD images.

   BMP (native) in fpGUI.... 100fps
   JPG (native) in fpGUI... 37fps
   PNG (via fcl-image) in fpGUI.... 8fps


So this clearly shows one huge bottleneck... Loading via fcl-image is
very bad!  The FPC team really needs to investigate this further.

Unfortunately I haven't implemented native PNG loading in fpGUI yet,
but you are welcome to port the BMP or JPG code to your LCL
application. This shouldn't be hard, because the code doesn't have
much to do with GUI toolkits. Though that means your images need to be
converted too - which I gather you would rather not want to do.

My fpGUI animation test project and the image samples can be
downloaded from the following URL. If your ISP bans DynamicDNS sites,
email me in private and I'll send it to you directly.

  http://opensoft.homeip.net:8080/~graemeg/animation_test.tar.gz         (2Mb)



-- 
Regards,
  - Graeme -


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




More information about the Lazarus mailing list