Animated GIFs

Started by Thomas., September 10, 2010, 10:43:57 PM

Previous topic - Next topic

Thomas.

Is some way to use GIF for textures? I found this http://www.jpct.net/forum2/index.php/topic,1406.0.html but is not working on android... :(

EgonOlsen

I've no idea if processing animated gifs on Android is supported by default. If it is, it should be possible to modify Paulscode's stuff to work on Android. My gut feeling says, that this will be too slow though. Maybe it's a better idea to just use some frames of the gif as individual textures.

paulscode

Reading and processing the GIF information from the file should work fine on Android without modification, because it's based on my own GIF loading code that I wrote some time ago in C++ (so it isn't Java-specific).  The part that won't work on Android is the drawing stuff (the part where I take the loaded information and use it to generate instances of java.awt.image.BufferedImage for each frame of the GIF).  What you need to be able to do is create 2D images with transparency on Android.  With that knowledge, you should be able to work with Egon to figure out how to use those images to create Texture instances in jPCT.  From there, it should be pretty easy to port the code over (in fact, I'll do the port for you if you do the initial research).

An alternative method would be to download the sourcecode for a JRE, such as OpenJDK, and pull out just the .java files you need to make my GIFImage class work as-is without modification (this would probably be more tedious than the first option, I'm guessing).

As for speed, I'm not sure how it would perform on Android.  It switches frames by changing the u/v coordinates on a "mosaic texture" containing all the frames in tiles.  This works quite fast in normal jPCT (much better than using a texture effect), but I have no idea how fast u/v changes are on AE version.  Changing it to use texture effects instead would be fairly easy (I've already written such a version of GIF loading for normal jPCT on this thread).  Obviously this method would also require the changes I mentioned above before it would work on Android.

paulscode

#3
While looking though the jPCT-AE javadoc, I saw that Textures can be made from Bitmap instances, which basically have all the functions needed to easily port my GIF loader to jPCT-AE.  It only took about 30 minutes once I figured out how to use the Android SDK (this was my first real Android project).  It seems to run quite well - no serious performance issues that I can detect (although my example is very simple)

Example App  (source code)

EgonOlsen

Nice work. It runs fine on my good old Galaxy. I'm always thinking that changing u/v coordinates will make performance suffer, because for compiled objects, the process is quite complex. But i guess i have to accept that this doesn't matter for simple geometry like quads... ;)