Author Topic: Animated GIFs  (Read 3808 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Animated GIFs
« on: September 10, 2010, 10:43:57 pm »
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... :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animated GIFs
« Reply #1 on: September 10, 2010, 10:50:08 pm »
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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Animated GIFs
« Reply #2 on: September 10, 2010, 11:53:41 pm »
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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Animated GIFs
« Reply #3 on: September 12, 2010, 06:11:50 am »
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)
« Last Edit: September 12, 2010, 04:27:44 pm by paulscode »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animated GIFs
« Reply #4 on: September 12, 2010, 09:44:53 am »
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... ;)