We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Loading Images (again!) but in the background
Page Index Toggle Pages: 1
Loading Images (again!) but in the background (Read 1035 times)
Loading Images (again!) but in the background
Sep 6th, 2007, 6:40pm
 
Hi.
I'm making a king of photo presentation app, and I've run into serious problems because of the image loading.

In trying to mitigate the problem, I've tried putting image loading code in a separate thread, but to my surprise loading times have grown exponentially! I only made things worse.
Any idea why this could be happening?

There's no chance this has to do with my code since I'm measuring the exact time and image takes to load, something like:

time = System.currentTimeMillis();
img = loadImage(blah);
System.out.println(System.currentTimeMillis() - time);

I've read a couple of previous posts on this subject and it seems nobody has a good answer. What beats me is that loading times grow **an order of magnitude** when loading in another thread. How can this be possible?

Somebody pointed this could be related to .jpg decoding. I think something has to be seriously wrong in the loading function if a 1.5Mb jpg takes around 1.5 seconds to decode, not to mention that this same jpg takes more than 30 secs if done in a separate thread!

Sorry for the long post, but this is crucial to the success of my app. I really need to find an answer.
Thanks.

Re: Loading Images (again!) but in the background
Reply #1 - Sep 6th, 2007, 8:38pm
 
just guessing here: if you're loading on the main drawing thread it will halt everything until loading is finished. if you're in a seperate thread the main drawing loop (which is pretty tight) will continue and use some resources. so, maybe you should try to set framerate to something very low while you're loading ... that way you can still have feedback for the user and loading might speed up (a little).

F
Re: Loading Images (again!) but in the background
Reply #2 - Sep 7th, 2007, 10:26am
 
Well, it turns out you were right! Frankly, I don't know how I didn't think about it before. I even tried messing with priorities but that didn't make much difference. However, lowering frame rates gives me some better times.

BUT, It's still so slow!! I think users will not want to wait about 10 seconds just for the application to start. The point of doing this with Processing is that I want my application to flow smoothly.

I now know this has little to do with Processing itself, since I tried loading images directly from the Toolkit and I've gotten the same poor times. STILL, there has to be some alternative. Anybody has any ideas?

Googling around right now... I'll let you know if I find something.
Re: Loading Images (again!) but in the background
Reply #3 - Sep 7th, 2007, 12:13pm
 
what kind of images are that?
where do the images come from? disk or web?
is this a specific (given) set, or something people can choose?

try comparing loading times of different formats like tif/tga, png gif, jpg .. maybe use something like imagemagick or ghostscript to convert / downsize files before loading them.

another idea: less disk-access is better, maybe try to combine the images into one file.

more general, people are used to waiting a little. the question is how to make them stay long enough. if you app is not almost instantly loaded, make it have a loading-bar or idle-sign (rotating dots). give information about what's happening (loading images, loading database, ..).

F
Re: Loading Images (again!) but in the background
Reply #4 - Sep 7th, 2007, 1:06pm
 
Well I'm loading image from a directory structure on disk and showing them as thumbnails for the user to select. For now, they have to be JPEG images, and I'd like to make the thumbnails myself so I don't need to have two separate set of images. I will prepare the thumbs beforehand if there is no other solution, but I would prefer not to.

Btw, I already show a progress dialog, but I simply want more speed.

I'm currently investigating the possibility of loading thumbnails directly from the EXIF data. I didn't know this could be done, but as it seems most cameras store a thumb inside this metadata so they can show the image fast on their screens. This would be perfect for my purposes.
I'll try and see if I can get some library which does this job for me.

Cheers.
Re: Loading Images (again!) but in the background
Reply #5 - Sep 7th, 2007, 1:54pm
 
Finally! I did it. Only this is just for thumbnails, so it doesn't do any good for those who want to load the whole images.
I used a library from Drew Noakes (http://www.drewnoakes.com/code/exif/), to extract the thumbs and the times are _very_ small, around 60ms per image.

Well, let's see what's next Smiley
Cheers.
Page Index Toggle Pages: 1