<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p>Hi Alex,</p>
<p> </p>
<p>I will add memory buffering as well of course, but on longer sequences, this will help little. The memory buffer will run empty before a second thread will fill it with new images.</p>
<p> </p>
<p>Darius</p>
<p> </p>
<p>On 9 feb '12, Alejandro Pérez wrote:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<pre>My 2 cents.
Try to load in memory some png first and descompress them, when the
buffer is full, launch other thread that only get data from the buffer
and paint it while the first thread fills the buffer with more files,
your bottleneck is always loading and decoding png files from disk.
Plase let us know your improvements,
Alex
El 09/02/2012 3:33, Brett Hunter escribió:</pre>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">I seem to remember some code that was in the NativeJPG examples that loaded the file into a TMemoryStream first, then did a LoadfromSteam instead of a LoadfromFile. It might be that the loadfromfile (or in your case LoadFromRawImage) is slower than a TMemorysteam.loadfromfile+Image.LoadfromStream. I admit I have never tried as I have never needed it, but it might help. Please let us know if there is a speed improvement. Ciao brett -----Original Message----- From: Darius Blaszyk [mailto:<a href="mailto:dhkblaszyk@zeelandnet.nl">dhkblaszyk@zeelandnet.nl</a>] Sent: Thursday, 9 February 2012 11:52 AM To: Lazarus mailing list Subject: Re: [Lazarus] Fast drawing to canvas 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. As I see it now, I will need to lower the access time to the png's from disk. I will do a test with storing only raw pixel data instead. This means that there will be no conversion (or decompression in the case of PNG) when streaming from disk. However, although the minor part of the total loop, I was hoping to improve the painting speed significantly as well. Hopefully someone else has an idea that works. Is there a way to access even lower level functions from LCL? Like GDI and GTK2 functions to copy the pixel data as fast as possible? Appreciate the help from everybody so far. Regards, Darius On Feb 8, 2012, at 5:12 PM, Sven Barth wrote:
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">Am 08.02.2012 16:02, schrieb <a href="mailto:dhkblaszyk@zeelandnet.nl:">dhkblaszyk@zeelandnet.nl:</a>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">I have played with Image.Update, .Invalidate and .Repaint, but none of them seem to work for me. Only when I put Application.ProcessMessages the painted images show on screen. See below for the testloop code. The images are streamed from a file cache. For 24 frames this seems overkill, but running at 24fps the memeory requirements quickly get very large! Image.Transparent is also set to false btw, which is default. Otherwise the drawing on the canvas is even messed up. Regards, Darius procedure TForm1.Button1Click(Sender: TObject); var s: TDateTime; i: Integer; begin s := now; for i := 1 to 24 do begin if filecache_get_from_cache(i, png) then begin Image1.Picture.Bitmap.LoadFromRawImage(png.RawImage, False); Application.ProcessMessages; end; end; ShowMessage(FloatToStr(24 / ((now - s) * 24 * 3600))) end;</blockquote>
Here it is clear that you need to use Application.ProcessMessages, because</blockquote>
"LoadFromRawImage" will only tell the control that it needs to repaint itself, but does not execute this repainting (this is done in Application.ProcessMessages). In the example you posted in the beginning the call to Application.ProcessMessages is located inside the OnPaint handler of the Image which is - in my opinion - not good. Maybe also the loading of the image inside the OnPaint handler is not good...
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">Maybe you should try - like Felipe suggested - something else than TImage.</blockquote>
Try for example TPaintBox in combination with the Application.OnIdle event:
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">procedure TForm1.ApplicationOnIdle(aSender: TObject; var aDone: Boolean); begin LoadNextImageFromCache; // this will load the next image into some private variable of the form (let's call it fImage). [this is based on your filecache_get_from_cache any you'll need to write it of course ;) ] PaintBox1.Invalidate; aDone := False; //</blockquote>
important!
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">end; procedure TForm1.PaintBox1Paint(aSender: TObject); begin PaintBox1.Canvas.Draw(fImage); // or however you'll get the content of the fImage onto the canvas of the PaintBox end; Note: Don't forget to assign your ApplicationOnIdle to Application.OnIdle</blockquote>
or use the ApplicationProperties component located in the Additional tab.
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">Regards, Sven -- _______________________________________________ Lazarus mailing list <a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a> <a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a></blockquote>
-- _______________________________________________ Lazarus mailing list <a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a> <a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a> __________ Information from ESET NOD32 Antivirus, version of virus signature database 6869 (20120208) __________ The message was checked by ESET NOD32 Antivirus. <a href="http://www.eset.com">http://www.eset.com</a> __________ Information from ESET NOD32 Antivirus, version of virus signature database 6869 (20120208) __________ The message was checked by ESET NOD32 Antivirus. <a href="http://www.eset.com">http://www.eset.com</a> -- _______________________________________________ Lazarus mailing list <a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a> <a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a></blockquote>
<pre>
--
_______________________________________________
Lazarus mailing list
<a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a>
</pre>
</blockquote>
<p> </p>
<p> </p>
<div> </div>
</body></html>