Recent

Author Topic: Fast way to load image preview ?  (Read 3024 times)

TomTom

  • Full Member
  • ***
  • Posts: 170
Fast way to load image preview ?
« on: February 23, 2019, 09:20:36 pm »
Hi, now Im writing quite complitacted file renamer for scanned document files (mainly big tif/tiff,  300/600 DPI, 30 - 400MB each). I had to add option for user so he could add few different suffixes to file name depending on what's on the image (i.e. _metryczka for image file that contains information about who scanned image, number and name of collection, or _okladka to point that it's scanned cover of book, etc etc.)
I need to give user option to preview this image. That is easy. But with that big files it can be real pain in the ... :)
I've figured  out that I can create smaller JPG files and then load them in TImage. So when user selects file on list my program checks if there is preview file, if there is then it's loading it if not.. then program creates for future use, and loads it. It works, quite ok... But what I'm really wondering of is that :
How to start creating this previews for all  files on list,  in background, when user clicks a button/checkbox for example. I want it to be in background so main form is responsive.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Fast way to load image preview ?
« Reply #1 on: February 23, 2019, 10:19:39 pm »
I would suggest it's time to start learning how the Thread class works.  :D

 or

You can create function that does your code but have it call "application.ProcessMessages" between each time
you load an image. This will allow the GUI to become responsive.. You should place some sort of
checkpoint on the code incase you try to re-enter it again, if its already operating, then exit.

 In ether case, you should be testing for some sort of external event to have it quit what it's dong and
exit early. The threat approach can test for the Termination property, the ProcessMessages can test for
some external variable for a state, Boolean, etc..

The only true wisdom is knowing you know nothing

TomTom

  • Full Member
  • ***
  • Posts: 170
Re: Fast way to load image preview ?
« Reply #2 on: February 23, 2019, 10:31:05 pm »
Yeah, I thought so, that TThread is what I need. I have been postponing this for a long time now.
Already tried ProcessMessages but it's not very efficient in my case.
and... I made quick attempt to use TThread, but I bumped out from it even quicker :P
Guess I have no choice :P

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Fast way to load image preview ?
« Reply #3 on: February 23, 2019, 11:45:25 pm »
Guess I have no choice :P

If you really dislike threads you could always use TProcess to launch a "thumbnailer" program in the background and use SimpleIPC to communicate between them.

It's not much easier than threads, though :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Fast way to load image preview ?
« Reply #4 on: February 24, 2019, 12:01:21 am »
Not a general solution, but many image files already contain a preview image. You can use fpexif to extract it from tiff and jpeg: https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fpexif/

TomTom

  • Full Member
  • ***
  • Posts: 170
Re: Fast way to load image preview ?
« Reply #5 on: February 24, 2019, 12:13:46 am »
It's not like that I dislike threads, I just that never used them and I don't understand how to use TThread right now.  ;) :-[
After some thinking I've decided to leave this function of my program as it is. When user selects file on the list if there is thumbnail then its loaded, if there's no thumbnail program generates it and loads it. It's useful but not main function of my program anyway.
But I have to ask. How apps like irfanview manage to load those big files so quickly?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Fast way to load image preview ?
« Reply #6 on: February 24, 2019, 01:06:15 am »
But I have to ask. How apps like irfanview manage to load those big files so quickly?

By decoding them on-the-fly while they are still being read. That's why sometimes you get large images rendered piece-by-piece with small intervals betweeen pieces.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Fast way to load image preview ?
« Reply #7 on: February 24, 2019, 04:27:40 pm »
I haven't looked but could it be that some image readers provide a OnScanLine process or OnProgress so that
a icon image could be built on the fly if one wants it instead of actually declaring all that memory ?

 Not sure if readers would obey looking at preset set Width and Height properties and condense the image
into that while reading the image in, if they did it would speed up things a lot..

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018