GifAnimation and UnzipIt: read gif from zip
in
Share your Work
•
3 years ago
I started to use GifAnimation because i needed to load .gif and display them in my games. Then i wanted to zip all sprites files to make them faster to load. However GifAnimation request a filename to load .gif with InputStream and this is the only constructor. So I think, if you put a .gif file in a zip you can't load it with GifAnimation, and if you open this zip archive with UnzipIt, you can't load the gif after. So I added it to these libraries:
- public Gif(PApplet parent, InputStream stream) {
- super(1, 1, ARGB);
- this.parent = parent;
- GifDecoder gifDecoder = createDecoder(parent, stream);
- frames = extractFrames(gifDecoder);
- delays = extractDelays(gifDecoder);
- repeatSetting = gifDecoder.getLoopCount();
- super.init(frames[0].width, frames[0].height, ARGB);
- jump(0);
- parent.registerDispose(this);
- runner = new Thread(this);
- runner.start();
- }
- private static GifDecoder createDecoder(PApplet parent, InputStream stream) {
- GifDecoder gifDecoder = new GifDecoder();
- gifDecoder.read(stream);
- return gifDecoder;
- }
- public InputStream getInputStream(PApplet p, String fname) {
- try {
ZipInputStream in = new ZipInputStream(new FileInputStream(zip.getAbsolutePath()));
ZipEntry entry = in.getNextEntry();
while(entry != null && !entry.getName().toLowerCase().equals(fname.toLowerCase())){
in.closeEntry();
entry = in.getNextEntry();
}
return in;
} catch(Exception e) {}
return null; - }