Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: scasparz on October 26, 2021, 09:33:31 pm

Title: converting graphics in the background (Solved)
Post by: scasparz on October 26, 2021, 09:33:31 pm
Am Linux Mint with Laz v2.0.12.
Need to build a jpeg browser for my camera’s very large jpegs that take ages to just load and display. What about working in the background?

Is there a way to load, resize and convert a jpeg into to a tbitmap from within a thread in a thread-safe manner?



regards
s
Title: Re: converting graphics in the background
Post by: trev on October 26, 2021, 11:07:14 pm
How about using ImageMagick's convert utility.
Title: Re: converting graphics in the background
Post by: scasparz on October 26, 2021, 11:31:58 pm
Thanks for the reply, however I would rather to follow a conventional Pascal way.
Title: Re: converting graphics in the background
Post by: lainz on October 27, 2021, 01:14:50 am
Am Linux Mint with Laz v2.0.12.
Need to build a jpeg browser for my camera’s very large jpegs that take ages to just load and display. What about working in the background?

Is there a way to load, resize and convert a jpeg into to a tbitmap from within a thread in a thread-safe manner?



regards
s

check LazPaint file open dialog, it has thumbnails for images of all kinds.
github.com/bgrabitmap/lazpaint

check the sources
Title: Re: converting graphics in the background
Post by: MarkMLl on October 27, 2021, 08:55:35 am
I've been holding off commenting in the hope that somebody who knows more- i.e. something- about JPEG handling comes along, but feel that it's worth throwing in my 2d-worth at this point to keep the thread alive.

Since JPEG compression can be handled by an FPGA etc., I presume that it can be parallelized onto one or more background threads.

A background thread must not interact with the GUI in any way, but once an image had been built in memory I see no reason why it could not be handed off to some component of the GUI via TThread.Synchronize().

Usual comments about it being difficult to get this sort of thing right, but you can minimise the potential for problems by having as few points of contact between threads (including the main/foreground/GUI thread) as possible.

MarkMLl
Title: Re: converting graphics in the background
Post by: winni on October 27, 2021, 10:52:09 am
Hi!

Use the BGRAbitmap.
It is threadsave.

You can load nearly any kind of graphic file into a BGRAbitmap.
Resizing is simple.

Finaly you draw the BGRAbitmap on any kind of canvas.

The BGRAbitmap can be installed via the Online Package Manager.

Winni
Title: Re: converting graphics in the background
Post by: scasparz on October 27, 2021, 05:20:06 pm
Many thanks everyone for their suggestions. Will try to use BGRABitMap winni.


EDIT: Still have a few trillion of things to learn in regard to tBGRABitMap, have tried it and found it works well and suits my purpose.
Thank you winni.
Title: Re: converting graphics in the background (Solved)
Post by: winni on October 28, 2021, 09:53:38 am
Hi!

Just made a little test:

Reading a directory with jpg photos and resizing them to thumbs.
The result:

91%  of the used time is needed for loading the files in a BGRAbitmap.

I think a thread based solution will not speed up the process.
The bootleneck is the harddisk.

Winni

Title: Re: converting graphics in the background (Solved)
Post by: wp on October 28, 2021, 11:56:15 am
Read the full image only if there is no other option. TJpegImage has the property Scale which allows to scale down the image internally - this is done by optimized decoding of the smaller image and is faster than full reading. Beyond that, there is even an embedded thumbnail image in most jpeg images. You must read the EXIF section of the file which contains information where to find this thumbnail. Use fpexif for this purpose (get it through online-package-manager, or download it directly from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fpexif/), or use the specialized routine in the attached demo which extracts only the thumbnail image; when a thumbnail is not available it uses the Scale property to get a reduced size; and only when the image is not a jpeg at all it reads the full image.

Further optimization can be achieved by switching to an alternate image loading library. In Windows, particularly, there is an Intel dll, ijl15.dll, which is much faster than what FPC provides. And IIRC, nativejpeg (https://github.com/acbarbosa1964/simdesign/tree/master/simlib/nativejpg) is also faster then FPC.
Title: Re: converting graphics in the background (Solved)
Post by: scasparz on October 30, 2021, 02:04:41 am
Guys perhaps I failed to clarify sufficiently what I want to do.

The idea has been to conduct the loading/resizing for multiple JPEGS at the background ending in an large array of tBitMaps that are ready to be displayed instantly. On that the tJPEGImage/tBitMap were giving me problems as I manipulated them into multiple threads.

On that the tBGRABitMap has been exactly what I wanted in that it has the functionality I want while being thread safe.

Have not finished this app yet, still have made enough progress though, looks that the loading/resizing at the background works well.


regards
s
TinyPortal © 2005-2018