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 › AniSprite and Animated GIFs
Page Index Toggle Pages: 1
AniSprite and Animated GIFs (Read 1134 times)
AniSprite and Animated GIFs
Dec 10th, 2007, 7:07pm
 
So http://processing.org/learning/topics/animatedsprite.html seems to reference an AniSprite class, where do i get that, and where can I learn more about it?

I'm looking for a library that can:
A. rip an animated GIF into different frames
B. generate an animated GIF from a series of frames

(I know that the latter is non-trivial, what with the palette issues etc)

I'd be 2/3 as happy with decent command line tools to handle those issues, but it would be awesome if I could do that stuff in Processing...
Re: AniSprite and Animated GIFs
Reply #1 - Dec 10th, 2007, 7:29pm
 
google 'AniSprite.pde' and you will find the original class; but it doesn't load an animated gif : it loads separate files with the loadImage() method, store them in an array, and return the next frame at each call of the display() method.
Re: AniSprite and Animated GIFs
Reply #2 - Dec 10th, 2007, 7:38pm
 
Ah.

I hate this comment:
"It would be easy to write a program to display animated GIFs, but would not allow as much control over the display sequence and rate of display."

I know it was fairly easy to at least display a basic animated GIF using old Java Servlets, and I see a few possibly commercial libraries to mess around with this stuff, just wondering if someone else has tacked the issue in a more processing-friendly way.
Re: AniSprite and Animated GIFs
Reply #3 - Dec 11th, 2007, 6:08am
 
I found something interesting about ripping an animated GIF into a PImage array :
http://www.velocityreviews.com/forums/t147024-accessing-animated-gifs-with-imageio.html

So I went up with this code which works well :

(edit: I updated the source code so specifying an absolute file path is not needed anymore)

Code:
PImage[] animation;

int i = 0;

void setup() {
String gifPath = "animated.gif";
animation = AniGifLoader.getFramesFrom(openStream(gifPath));
}

void draw() {
background(255);
image(animation[i], 0, 0);
i = (i + 1) % animation.length;
}


Code:
public static class AniGifLoader {

public static PImage[] getFramesFrom(java.io.InputStream s) {

try {

javax.imageio.stream.ImageInputStream stream = javax.imageio.ImageIO.createImageInputStream(s);
java.util.Iterator readers = javax.imageio.ImageIO.getImageReaders(stream);
if (!readers.hasNext()) throw new RuntimeException("no image reader found");
javax.imageio.ImageReader reader = (javax.imageio.ImageReader) readers.next();
reader.setInput(stream);

int n = reader.getNumImages(true);
PImage[] frames = new PImage[n];

for (int i = 0; i < n; i++) {
java.awt.image.BufferedImage image = reader.read(i);
frames[i] = new PImage(image);
}

stream.close();
return frames;

} catch (Exception e) {
e.printStackTrace();
return null;
}

}

}
Re: AniSprite and Animated GIFs
Reply #4 - Dec 11th, 2007, 5:08pm
 
Cool! I will have to try that out!
Re: AniSprite and Animated GIFs
Reply #5 - Jan 3rd, 2008, 3:50pm
 
antiplastik, the problem with your solution is that it does not support optimized animations, the 'progressive' GIF type. And seems not to be able to handle transparent GIFs.
e.g., try kirkjerk's atari animation:
http://kisrael.com/journal.aux/atariparty.gif

solution: use GifAnimation library Wink
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=LibraryProblems;action=display;num=1199371244;start=0#0
Re: AniSprite and Animated GIFs
Reply #6 - Jan 3rd, 2008, 4:15pm
 
Oh, I haven't figured this out. That's great work!
Page Index Toggle Pages: 1