Recent

Author Topic: Performance Issue Loading JPEG  (Read 13526 times)

MaartenJB

  • Jr. Member
  • **
  • Posts: 73
Performance Issue Loading JPEG
« on: June 09, 2011, 02:00:30 pm »
Hi,

I've got a performance issue with loading large(r) jpeg foto's. I want to show a preview of a JPEG image, but the way I'm using now is very slow. In Delphi I can use the "TJpegImage.Scale" option, this is very fast, but I can't find a similar function in Lazarus.

In lazarus 4mb jpg takes +/- 2.5 sec
Code: [Select]
var
  myImage: TBGRABitmap;
begin
  myImage := TBGRABitmap.Create;
  try
    myImage.LoadFromFile('C:\temp\test.jpg');  // 4mb jpg, 2.5sec
    myImage.Draw(Image1.Canvas,Rect(0,0,Image1.Width,Image1.Height),False);
  finally
    myImage.Free;
  end;
end;


In Delphi same image takes 140 MilliSec. (almost 20 times faster)
Code: [Select]
var
  AJpg: TJpegImage;
begin
  AJpg := TJpegImage.Create;
  try
    AJpg.LoadFromFile('C:\temp\test.jpg'); //4mb,140millisec
    AJpg.Scale := jsEighth;
    Image1.Picture.Bitmap.Assign(AJpg);
  finally
    AJpg.Free;
  end;

I've tried a lot of things, browsed almost every web page, but can't find a solution, I hope somebody else does....

Thanks in advance

eny

  • Hero Member
  • *****
  • Posts: 1613
Re: Performance Issue Loading JPEG
« Reply #1 on: June 09, 2011, 05:08:46 pm »
Code: Delphi  [Select][+][-]
  1.   myImage.LoadFromFile('C:\temp\test.jpg');  // 4mb jpg, 2.5sec
0,9s on my config.
Maybe Delphi cheats by initially just loading the raw data and not doing any processing.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

MaartenJB

  • Jr. Member
  • **
  • Posts: 73
Re: Performance Issue Loading JPEG
« Reply #2 on: June 09, 2011, 05:33:09 pm »
delphi needs to decompress the whole jpg first, before it's able to draw the whole picture right?


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Performance Issue Loading JPEG
« Reply #3 on: June 09, 2011, 05:48:56 pm »
There was a fix in Free Pascal recently which could speed up image loading. In this case you would need to try a snapshot containing the latest fpc 2.5.1

eny

  • Hero Member
  • *****
  • Posts: 1613
Re: Performance Issue Loading JPEG
« Reply #4 on: June 09, 2011, 07:49:53 pm »
delphi needs to decompress the whole jpg first, before it's able to draw the whole picture right?
Sure, but is this done during the load process (which apparently takes only 140ms) or just in time before the image is drawn?
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

MaartenJB

  • Jr. Member
  • **
  • Posts: 73
Re: Performance Issue Loading JPEG
« Reply #5 on: June 09, 2011, 07:59:15 pm »
within the 140ms the jpg is loaded from file and drawn on the canvas.

eny

  • Hero Member
  • *****
  • Posts: 1613
Re: Performance Issue Loading JPEG
« Reply #6 on: June 09, 2011, 09:52:42 pm »
within the 140ms the jpg is loaded from file and drawn on the canvas.

Did you verify this in the Delphi source code?
Did a small test myself: indeed Delphi is pretty fast!
« Last Edit: June 09, 2011, 10:02:01 pm by eny »
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8281
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Performance Issue Loading JPEG
« Reply #7 on: June 10, 2011, 01:13:29 am »
I remember a posting in FPC forum / mailing list regarding palette that's created by default. The svn fix disables this by default.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Performance Issue Loading JPEG
« Reply #8 on: June 10, 2011, 10:33:59 am »
« Last Edit: June 10, 2011, 10:35:43 am by theo »

MaartenJB

  • Jr. Member
  • **
  • Posts: 73
Re: Performance Issue Loading JPEG
« Reply #9 on: June 11, 2011, 01:08:46 pm »
@Theo;  Great stuff!  Thanks Theo, it works like a charm!

It took a while since I never worked with svn, and never compiled fpc/lazarus before.

@All;  Thanks for the reply's!

Code: [Select]
var
  myImage : TFPMemoryImage;
  myImgReader: TFPReaderJpeg;
begin
  myImage  :=  TFPMemoryImage.create(0, 0);
  myImgReader := TFPReaderJPEG.Create;
  try
    myImage.UsePalette := False;
    myImgReader.Scale:= jsEighth;

    myImage.LoadFromFile('C:\Documents and Settings\Administrator\My Documents\Lazarus\foto\dsc_9537.jpg', myImgReader);
    Image1.Picture.Assign(myImage);
  finally
    myImage.Free;
    myImgReader.Free;
  end;
end;

 

TinyPortal © 2005-2018