Animated GIFs

Started by paulscode, June 21, 2009, 02:07:48 AM

Previous topic - Next topic

paulscode

-- This slot is reserved for the most recent working releases --



Downloads:

GIFImage Source Code  Version date:  July 7, 2009
The base class for loading information from GIF files.  Supports most versions of the GIF format, including single frame (87a), animated (89a), interleaving, transparent color, LZW compression, and "clr" non-compressed data.

GIFLoader Source Code  Version date:  July 7, 2009
Library for using animated GIFs as textures in jPCT.  Provides methods for loading GIF files into "mosaic textures", animating, checking for current animation frame, and determining the UV coordinates of the current frame.  TODO: add methods for blitting.  This download includes the above GIFImage class.


Demos:

Animated GIF inside an applet  (download the Source Code)
Demonstrates loading and animating a multi-frame GIF image via the GIFImage class.

GIF Box  (download the Source Code)
Demonstrates using animated GIFs as textures in jPCT.


Android Port, for use with jPCT-AE

Example Ap  (source code)


Documentation:

GIFImage and GIFLoader JavaDoc  Version date:  July 7, 2009

paulscode

#1
Project Overview:

This project is designed to allow developers to use animated GIFs in their jPCT projects.  It will provide simple interface methods for placing GIFs into textures, using them in overlays, or blitting them.

Be sure to let me know if you run into bugs or exceptions, or if you have any suggestions for the library.

paulscode

I worked on this project a little today.  I got the "mozaic texture" part working.  The program calculates a texture size within the parameters acceptable by jpct (width is a power of two between 8 and 8192, and height is a power of two).  It places all the animation frames into this texture, and saves info about where the frames are in the texture, their u/v coordinates, how many milliseconds they should be displayed, and the number of times to loop the whole animation.

I made an applet to demonstrate:
http://www.paulscode.com/demos/jpct/GIFLoader/

The code is pretty ugly at the moment - it definitely needs more work to make it user-friendly.  I'll post the source when I get it looking nicer.

EgonOlsen

Pretty cool. But i suggest to limit the maximum size to 4096. While jPCT supports texture sizes up to 8192*8192, most hardware doesn't.

paulscode

#4
That limitation is to both width and height, I assume?  (i.e. 8192 * 256 would not be acceptable even though it has less pixel data than 4096*4096?).  I will change the formula so that it fits all frames into a width of 4096.  It will be up to the user to decide if they need to reduce the number of frames if the height goes beyond 4096 as well.  I can just print out a warning message or something if that happens.

EgonOlsen

Yes, the limit of most hardware is 4096*4096. 8129*2048 won't work even if it consumes the same amount of memory.

JavaMan

#6
Cool! No lag at all on my machine. Probably useful to use for grass effects. ::)

I have though a question about the texture width*height limits. I would probably have run into this problem in the future, so I'll clear myself up now. You said 8192*256 won't work. It says in the docs "Supported texture sizes are 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 and 8192 pixels in width with any height." Is 8192 height and 256 the width?

EgonOlsen

No, in this example 8192 is the width and 256 the height. Anyway, thanks for pointing out this part of the docs...it's just wrong. It was true when jPCT was using software rendering only but after adding OpenGL support, the texture size (width and height) has to be a power of 2. I'll correct that part of the docs, i wasn't aware of it. Funny, that no one ever asked about it until now.

paulscode

I changed the max texture dimensions and cleaned up the code a little.  I re-uploaded the demo applets and source code.  If anyone has problems getting them to run, let me know.  In its current form, the library is useful for using animated GIFs as textures for roughly square Object3Ds (i.e. quads).  I still need to add methods for blitting, since that is probably the main thing people would use GIFs for.

AGP

Thanks a lot, paulscode. I tested it and it works great. I keep meaning to ask you: do you work with AI?

paulscode

Quote from: AGP on July 08, 2009, 10:37:09 PM
do you work with AI?
I have done a few projects with AI (not much with NPC game AI's, though).  The "big-idea" project I've been working on for a while now is a grammar-learning, contextual-speaking AI.  Currently, it is text-based (user types in inputs, and it generates string outputs).  In learn-mode, it is able to quickly learn how to produce grammatically-correct sentences based on user-input.  This allows it to speak in whatever language or grammar structure the user is using (for example I have AI "brains" that talk in Spanish, Russian, like Shakespear and Yoda, etc).  In context-mode, it takes words from the user-input and generates random sentences based on contexts derived from those words (context probability is based on the number of times each word was encounterd during "learn-mode")  Thus, it will talk in context (for example, if the user typed something about cats, it might produce a random sentence about cats or a related topic, such as pets).  Currently, I am attempting to link up this AI with speech recognition and speech synthesis interfaces (the hardest part has been speech recognition reliable enough to use in "learn mode").  My ultimate goal is to create software for a toy that would speak full sentences in-context based on whatever the people around it are saying (for example, if the child were to say something about a cat, the toy might say something about cats - allowing the child and toy to have a conversation of sorts).  I think that would be really awesome!

AGP

It would be, and I've worked on something similar which I have named Lal. Mine, I'm sure, is far behind yours, but it's the same general idea. As far as speech recognition is concerned, are they still making Dragon Naturally Speaking? Up until a few years ago it was by far the best engine around. I know they even based a MacOS program on it (it was originally Windows-only). And I'm sure you know of Cloudgarden, Jonathan Kinnersley's only full JSAPI 1.0 implementation for Windows.

paulscode

Yes, the biggest problem with speech recognition for my project is that I do not want it limited to English or any one language or grammar structure.  The open-source library I've been working with recently is called Sphinx.  The cool thing about this one is that it has functions for obtaining "raw text input" (what you get before it has been run through language-specific word-recognition).  What I am attempting to do is process this raw data myself to generate space-seperated "words" (much harder than you might think - consider the difference in sound between "an arrow fell low in the grass" and "a narrow fellow in the grass", for example - the raw data would be almost identical for both sentences).  Ultimately, this may turn out to be futile (it is truely amazing what the human brain is capable of doing with such ease).  If I can't work with the raw input, I'll be forced to limit my software to a single language (which would eliminate the cool grammar-learning "talk like you" feature that my AI has now).

AGP

Honestly, I think you should focus your project goals. Do the context stuff first. If you finish that, then worry about teaching it to extrapolate from raw text input. For kicks and giggles (really just to please myself and impress people) I would use JSAPI with a great English recognition engine (you can do that in an afternoon) and then get back to the language context.

fireside

I'm just bumping this so I can find it more easily.  ;D
click here->Fireside 7 Games<-