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.
IndexProcessing DevelopmentLibraries,  Tool Development › ImageLoader (checking percent of completion)
Page Index Toggle Pages: 1
ImageLoader (checking percent of completion) (Read 1965 times)
ImageLoader (checking percent of completion)
Jan 31st, 2008, 8:51pm
 
I have written this library, which helps loading images in another thread and checking the loading completion, so when you're loading a very large image, you can show a progress bar or something like that.

If any of you find it useful, I may try to debug it a little more and/or submit it to the external libraries collection.

It should work well with (and only with, though I haven't tried) JPG, GIF and PNG.

Here it is:
http://n.clavaud.free.fr/processing/imageloader/
Re: ImageLoader (checking percent of completion)
Reply #1 - Feb 1st, 2008, 3:16am
 
great lib,is this can be loading the images from the local folder? anyway,i'll try it

thank you!
Re: ImageLoader (checking percent of completion)
Reply #2 - Feb 1st, 2008, 2:13pm
 
Wow, thank you, this is really nice! Whats up with memory? Arent you copying pictures by:

void imageLoadingComplete(ImageLoader il) {
 pro01 = il.getImage(0);
 pro02 = il.getImage(1);
}

greeting sascorbin
Re: ImageLoader (checking percent of completion)
Reply #3 - Feb 4th, 2008, 2:29pm
 
Mmm... The images themselves are not copied by this statement. The pointers to the images are, instead. So I guess there shouldn't be any memory issue.

Quote:
is this can be loading the images from the local folder?
not sure! but i'll check this as soon as I have some free time.
Re: ImageLoader (checking percent of completion)
Reply #4 - Feb 16th, 2008, 9:47pm
 
wow, really great work! This works very fine! Two more questions:
If I build my own classes which preloads images by themself I cannot use ' this ' in new ImageLoader(this, String[]). So, whats the name of my PApplet? something like paren? super? Second, When I work in OPENGL the images are copied as a OPENGL texture by the first images()-call which cost some time, can this be managed by the preloader?

greetings ascorbin
Re: ImageLoader (checking percent of completion)
Reply #5 - Feb 17th, 2008, 9:42pm
 
Quote:
So, whats the name of my PApplet?
yourImageLoader.parent returns the PApplet it is associated to.

Quote:
When I work in OPENGL the images are copied as a OPENGL texture by the first images()-call which cost some time, can this be managed by the preloader?

I don't get it (sorry, my understanding of english isn't very high). Can you give me more explanations?
Re: ImageLoader (checking percent of completion)
Reply #6 - Feb 17th, 2008, 9:52pm
 
I have a project in OPENGL with some very large pictures. There are 8 buttons which show eight pictures when clicked. At the beginning each picture waits half  a second before opening. Later everything is very fluid and fast. So, obviously the pictures are copied into a faster OPENGL graphic buffer or something.
Re: ImageLoader (checking percent of completion)
Reply #7 - Feb 17th, 2008, 10:11pm
 
oh ok. I think the ImageLoader can't help in this case, since it only informs when a PImage is ready to be used... :-/
Re: ImageLoader (checking percent of completion)
Reply #8 - Aug 6th, 2008, 7:08am
 
thanks for this, very simple and does the trick.  

question: according to doc, imageLoadingComplete() is supposed to be called "when downloads are complete", and the example program suggests this happens once, when ALL images are finished loading.  however, it actually gets called EVERY time each image is loaded.  a) is this a mistake, b) if not, is there a method that is called when all images are done besides checking constantly for the boolean flag isAlive?  

thanks

eric

@liquid: yes, local files work fine

@ascorbin: just pointers as nicolas said, you can also omit that whole function and refer directly to images with loader.getImage(i)
Re: ImageLoader (checking percent of completion)
Reply #9 - Aug 6th, 2008, 7:14am
 
also, a feature request - can you specify path separately so you don't have to waste memory by stuffing array of image location strings with redundant data?

what are your thoughts on fry's imageLoader?  
http://benfry.com/writing/acquire/ImageLoader.java

note that it has some small bugs as specified in this thread:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=WebsiteBugs;action=display;num=1206736963;start=0#0
Re: ImageLoader (checking percent of completion)
Reply #10 - Aug 6th, 2008, 8:52pm
 
Thank you for reporting the imageComplete() bug - that was a mistake indeed.

I fixed it and released another version. I've also added the requested feature : you can now add more urls with the addImage(String url) method.

http://n.clavaud.free.fr/processing/imageloader/

Fry's imageLoader is nice, but I wanted to know how much bytes were loaded for each image. Try the example with a huge image, and you'll see that the progress bar will keep you inform of the overall progression.
Re: ImageLoader (checking percent of completion)
Reply #11 - Aug 6th, 2008, 9:21pm
 
wow that was fast.  cool.  i'm not clear on the use of addImage, if you have to use it before you start loading images, it seems you would always be able to take care of that by adding to the String urls parameter *before* you call ImageLoader.  i don't see what advantage addImage gives you.  

the feature i meant to request is specifying a path, which would then not need to be repeated for every String in urls array.  e.g. imageLoader could have an optional 3rd parameter which is a path string that gets prepended to each filename.  if you leave it out, it works exactly as in all previous versions.

Code:

// new way
String path = "http://processing.org/images/";
String[] files = { "alpha.gif", "beta.gif", "gamma.gif", "delta.gif" };
loader = new ImageLoader(this, files, path};

// old way still works
String[] files = { "http://processing.org/images/alpha.gif", "http://processing.org/images/beta.gif", "http://processing.org/images/gamma.gif", "http://processing.org/images/delta.gif" };
loader = new ImageLoader(this, files};



while we're at it, a function for loading image sequences would be really useful.  e.g. image001.jpg, image002.jpg, without needing to write your own loop and string constructor.  sorry, i'm being greedy now.  Smiley

thanks again for your quick response and public code,

eric
Page Index Toggle Pages: 1