Performance Issue Loading JPEG lazarus / 39-Graphics ---------------------------------------------------------------------- MaartenJB · 2011-06-09 12:00 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),Fa lse);   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 · 2011-06-09 15:08 Code: Delphi  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   myImage.LoadFromFile('C:\temp\test.jpg');  // 4mb jpg, 2.5sec0,9s on my config. Maybe Delphi cheats by initially just loading the raw data and not doing any processing. ---------------------------------------------------------------------- MaartenJB · 2011-06-09 15:33 delphi needs to decompress the whole jpg first, before it's able to draw the whole picture right? ---------------------------------------------------------------------- felipemdc · 2011-06-09 15:48 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 · 2011-06-09 17:49 Quote from: MaartenJB on June 09, 2011, 05:33:09 pmdelphi 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? ---------------------------------------------------------------------- MaartenJB · 2011-06-09 17:59 within the 140ms the jpg is loaded from file and drawn on the canvas. ---------------------------------------------------------------------- eny · 2011-06-09 19:52 Quote from: MaartenJB on June 09, 2011, 07:59:15 pmwithin 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! ---------------------------------------------------------------------- Leledumbo · 2011-06-09 23:13 I remember a posting in FPC forum / mailing list regarding palette that's created by default. The svn fix disables this by default. ---------------------------------------------------------------------- theo · 2011-06-10 08:33 I've submitted a patch to enable scaling in fpreadjpeg: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl- image/src/fpreadjpeg.pas?r1=13963&r2=15855&sortby=date ---------------------------------------------------------------------- MaartenJB · 2011-06-11 11:08 @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;