Faster image loading?

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Faster image loading?

Post by Dude »

Is there a way to fast load images to a much better speed than what LoadImage() currently does? I have a bunch of image names in a ListIconGadget, and when I click an item in the list, it loads the image to show in an ImageGadget. But if I scroll through the ListIconGadget (holding the down arrow key), each image is loaded but it's not very fast, and the scrolling is slow. :( My images are all PNG format and around 800 KB in size. I'd love to be able to just hold down the arrow key and scroll the ListIconGadget with the images flicking through the ImageGadget a lot faster.

Or maybe it's SetGadgetState() to the ImageGadget() that's slow? I don't know. Any tips?
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Faster image loading?

Post by walbus »

Hi Dude,
make a try with the Image Plugin from Wilbert :wink:

http://www.purebasic.fr/english/viewtop ... 12&t=66497
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Faster image loading?

Post by nco2k »

for the scrolling issue, you could load the images in separate background threads.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Faster image loading?

Post by Dude »

I'll check out Wilbert's loader, as I can see some assembly code in there which may be the speed increase I need.

nco2k, what do you mean by threads? I can only load one image at a time, to show when it's selected by the user. Loading them all first is not an option (there's over 2000 of them, at 800 KB each).
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Faster image loading?

Post by nco2k »

who said anything about loading them all? currently you use the same thread for the event loop and the loading of the image. you click on a gadget item, and the event loop blocks until the image is loaded and displayed. if you put the loading of the image in a separate thread, your event loop wont block. like the windows explorer does it. you can scroll through them all without blocking, and the image itself will be displayed when its ready.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Faster image loading?

Post by RASHAD »

I suggest to look at :
1- Create an ImageList with icons for all your images and when the user pick one it will be loaded at once
2- Try GDI+ it should be faster than PB
3- Try OLE solution to load the images

Search the forum :P
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Faster image loading?

Post by Dude »

nco2k wrote:who said anything about loading them all?
I thought that's what you meant when you said "load the images" as opposed to "image" singular.

But loading in a background thread won't work, because I won't see the images as I scroll (just like Windows Explorer doesn't show until you stop scrolling). I need to see what I'm scrolling through because I'm looking for a specific image, so background threads won't do the job.

Currently it all works the way I like, but the image loading could be faster.

[Edit] Actually, I ended up doing Rashad's icon idea: when building the ListIconGadget, I loaded the image and resized it to 16x16 and used that as each item's listicon image. So I get to see a (tiny) thumbnail which makes it easier to preview what I want without loading the full image first. I can still scroll through the list and load each full image while scrolling, but the speed is of no concern now that I have a backup smaller thumbnail for reference.

As I always seem to say: thanks Rashad! :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Faster image loading?

Post by RASHAD »

Hi Dude
thumbnail 16x16 is tiny as you mentioned but this is a limit of the ListIcon()
Try bigger size with ImageList() and do not use column 0
Search the forum :P
Egypt my love
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Faster image loading?

Post by wilbert »

Loading PNG just is slow compared to JPEG (especially with a library like libjpeg-turbo).
Using a thumbnail might indeed be the best option.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply