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.
IndexSuggestions & BugsSoftware Bugs › Loading images is so slow. Why
Page Index Toggle Pages: 1
Loading images is so slow. Why? (Read 4576 times)
Loading images is so slow. Why?
Jun 12th, 2006, 12:19am
 
Hi,

I want to make a kind of slideshow which actually overlays several pictures simultaneous. The idea is to have pictures fade-in and fade-out very slowly and smoothly over each other. After one pictures fades-in and fades-out a new picture starts fading in. I always have 10 overlaying pictures out of a pool of 350 pictures. Each picture is around 150Kb.

For some strange reason Processing takes a huge amount of time to load each picture. Over one second. And I have a dual core cpu! Why?

To bypass this problem I decided to preload images. Only to find out that Processing quicly runs out of memory. Even after tweaking with memory settings I can't load more than 30 pictures. So since I have 350 pictures this solution is impossible (besides the fact that it would take more than 5 minutes for the application to start!).

I decided to develop the same application in Flash and loading the pictures is instantaneous in Flash but unfortunately, since it doesn't harware OpenGL, I ran into performance problems when using alpha channel for handling fade-ins and fade-outs of the multiple overlaying pictures. Now I don't know what to do. I'd rather stick to Processing and discard Flash. Can you help me?

So my question is: how to load pictures quickly.

Alternatively: how to load pictures asyncronously (I just came up with this idea: I could asyncronously preload the next picture of each layer). Still... I'd rather stick to a simpler solution.

Please advise.

Thanks,
Nuno
Re: Loading images is so slow. Why?
Reply #1 - Jun 12th, 2006, 12:59am
 
What size is the applet and what size are your images? Regardless of how compressed those images are they're going to be converted into Processing's image type when they go into memory - which is a little different to the file on your hardrive (4 bytes * width * height, if I remember correctly).

I just put this together and it runs pretty fast, even with a forced delay.
Code:

PImage pimage;
int i = 0;
int timer = 0;
void setup(){
size(1024, 768);
}
void draw(){
if(millis() - timer > 100){
timer = millis();
pimage = loadImage(i+".jpg");
image(pimage, 0, 0);
i = (i + 1) % 2;
}
}

If you want speed I would suggest curbing your pixels. More pixels = more time. Using copy() as a method of a PImage (pimage1.copy(pimage2, blah, blah, etc.)) could cut down the amount of space your images are taking up in memory when you load them in. Just load them into a tempory PImage then copy() into your storage space.

It sounds like what you're doing is pretty straight forward to do. If you're still having trouble, post the code of what you're doing and we'll see what needs fixing.
Re: Loading images is so slow. Why?
Reply #2 - Jun 12th, 2006, 12:19pm
 
If you want an asynchronous image loader, check out this thread:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1141752225;start=6#6

I make no guarantees about the code, but it should do what you need.
Re: Loading images is so slow. Why?
Reply #3 - Jun 15th, 2006, 10:06am
 
Hi st33d,

Thank you for your answer.

My applet in the final version will be full screen which means 1280x800. Actually I want it to run in a plasma screen.

I understand that once loaded pictures become quite big in memory. So I'm totally decided to load them on-the-fly.

I posted my code online as you asked. Thank you so much for taking the time to look at it. I published the applet but actually it is not working so ignore it and just check the source files. I also added a link to one of the images. Please note that the picture is erotic.

I was thinking... I wonder if the loading is slow because of jpeg decoding. Maybe if I convert my 350 pictures to BMP it would be fast! Does it make sense?

Unfortunately I still didn't have opportunity to try your code with my pictures to see if it loads quickly. I am currently at the office and here I cannot do it. I'll try it as soon as I can.

Bye,
Nuno
Re: Loading images is so slow. Why?
Reply #4 - Jun 15th, 2006, 10:08am
 
Hi John,

Thanks for the code for asynchronous loading! I'll definitely try to use it.

Nuno
Re: Loading images is so slow. Why?
Reply #5 - Jun 15th, 2006, 11:16pm
 
I bring news Smiley

I used your simple loop (I removed the delay) to load a set of 10 jpegs of mine and the result was this what I expected:

i=1 t=1156
i=2 t=938
i=3 t=938
i=4 t=922
i=5 t=922
i=6 t=906
i=7 t=921
i=8 t=938
i=9 t=922
i=10 t=922

Then I decided to convert these 10 pictures to BMPs and the result was QUITE different:

i=1 t=234
i=2 t=172
i=3 t=171
i=4 t=172
i=5 t=156
i=6 t=172
i=7 t=157
i=8 t=172
i=9 t=156
i=10 t=171

Around 6x faster! So, my first interesting conclusion is that actually Processing takes an awful amount of time to decode JPEGs. Then I decided to replace my JPEGs with another set of pictures roughly the same size to see if my JPEGs were specially slow. Much to my surprise, even though these other pictures where quite bigger in size (1024x768 against 500x700) they were still much faster to load:

i=1 t=594
i=2 t=343
i=3 t=344
i=4 t=359
i=5 t=328
i=6 t=360
i=7 t=328
i=8 t=359
i=9 t=328
i=10 t=359

Well, interesting as this may be, 150ms is still too long to wait for a picture to load. So I will definitely try to use the asynchronous routine John kindly gave me.

Thank you all for your help!

Nuno
Re: Loading images is so slow. Why?
Reply #6 - Jun 20th, 2006, 3:27pm
 
hm, thanks for looking into that. i have several ideas about why that might be the case.. maybe we can speed things up.
Re: Loading images is so slow. Why?
Reply #7 - Sep 13th, 2006, 4:06am
 
now filed in the bugs db:
http://dev.processing.org/bugs/show_bug.cgi?id=392
Re: Loading images is so slow. Why?
Reply #8 - Sep 24th, 2006, 5:19pm
 
changing for 0116, so this should be fixed.
Page Index Toggle Pages: 1