Recent

Author Topic: BGRABitmap is slow  (Read 380 times)

pcurtis

  • Full Member
  • ***
  • Posts: 218
BGRABitmap is slow
« on: July 08, 2020, 08:55:57 am »
Hi All,

I am trying to make an image viewer using BGRABitmap. The problem is it takes a long time to load certain images.

My code look like this :

Code: Pascal  [Select][+][-]
  1. Var
  2.   myimage : TBGRABitmap;
  3. Begin
  4.   myimage := TBGRABitmap.Create;
  5.  
  6.   // https://chandra.si.edu/photo/2012/n1929/n1929_lg.jpg
  7.   // 3600 x 2768
  8.  
  9.   myimage.LoadFromFile('c:\work\n1929_lg.jpg');  // Approx 2.1 seconds
  10.  
  11.   Image1.Picture.Assign(myimage);  // Approx 3.8 seconds - 1.7 seconds just to display??
  12.  
  13.   myimage.Free;
  14.  

I use BGRABitmap because I open different image types - TIF, WEBP, .....

If I open the same file in, for example, Google Picasa it is instant

What am I doing wrong?

Just displaying the image takes 2.5 seconds. Is there a better way?

Thanks for all comments.

BTW I am using Win 10
« Last Edit: July 08, 2020, 09:11:06 am by pcurtis »
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: BGRABitmap is slow
« Reply #1 on: July 08, 2020, 12:23:52 pm »
I modified the demo that I posted for https://forum.lazarus.freepascal.org/index.php/topic,50444.msg368175.html#msg368175 such that the Graphics32 library is not needed. It does not use BGRABitmap either, just the regular LCL routines in one case, and in the other case the high-speed Intel Jpeg Library (IJL) which, however, is only for Windows and for 32 bit applications.

Your image loads within 1.2s with the standard LCL jpeg reader, but within 0.2 s using the IJL dll.

If you cannot use IJL you could try the Vampyre Imaging Library (available in OPM) or FreeImage (google for it). Both of them are cross-platform, and, as I remember from an old Delphi project, faster than the Delphi jpeg reader, although not as fast as IJL. And both of them can read a variety of formats.

Another reason why picasa appears to be fast could be that it pre-loads the next image from the image directory in the background while the previously loaded image is viewed.
« Last Edit: July 08, 2020, 12:26:41 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

winni

  • Hero Member
  • *****
  • Posts: 1815
Re: BGRABitmap is slow
« Reply #2 on: July 08, 2020, 12:38:49 pm »
@pcurtis

You are handling the BGRABitmap too complicated.
This is easier:

Code: Pascal  [Select][+][-]
  1. Var
  2.   myimage : TBGRABitmap;
  3. Begin
  4.  myimage := TBGRABitmap.Create('c:\work\n1929_lg.jpg');
  5.  myImage.Draw(Image1.canvas,0,0,true)
  6.  
  7.   myimage.Free;
  8.  end;
  9.  
  10.  
  11.  
Winni

pcurtis

  • Full Member
  • ***
  • Posts: 218
Re: BGRABitmap is slow
« Reply #3 on: July 08, 2020, 01:59:58 pm »
Code: Pascal  [Select][+][-]
  1. myimage := TBGRABitmap.Create('c:\work\n1929_lg.jpg');
  2.  

Still takes 2.2 seconds.

Code: Pascal  [Select][+][-]
  1. myImage.Draw(Image1.canvas,0,0,true);
  2.  

Is faster.

I have chosen to use FreeImage. The same image loads in under 0.5 seconds.
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

circular

  • Hero Member
  • *****
  • Posts: 3448
    • Personal webpage
Re: BGRABitmap is slow
« Reply #4 on: July 08, 2020, 11:16:25 pm »
Basically BGRABitmap uses the LCL image reader for JPEG.

Note that BGRABitmap uses the high quality loading by default, which gives better results especially if the compression quality was low. You can specify loJpegQuick option in parameters to get a faster loading speed.

if FreeImage is faster, this could be an inspiration on optimizing the LCL JPEG reader.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018