Class GifTexImage2D

java.lang.Object
pl.droidsonroids.gif.GifTexImage2D

public class GifTexImage2D
extends Object
Provides support for animated GIFs in OpenGL. There are 2 possible usages:
  1. Automatic animation according to timing defined in GIF file - startDecoderThread() and stopDecoderThread().
  2. Manual frame advancing - seekToFrame(int).
Note that call seekToFrame(int) while decoder thread is running will cause frame change but it can be immediately changed again by decoder thread.
Current frame can be copied to 2D texture when needed. See glTexImage2D(int, int) and glTexSubImage2D(int, int).
  • Constructor Details

    • GifTexImage2D

      public GifTexImage2D​(InputSource inputSource, @Nullable GifOptions options) throws IOException
      Constructs new GifTexImage2D. Decoder thread is initially stopped, use startDecoderThread() to start it.
      Parameters:
      inputSource - source
      options - null-ok; options controlling parameters like subsampling and opacity
      Throws:
      IOException - when creation fails
  • Method Details

    • getFrameDuration

      public int getFrameDuration​(@IntRange(from=0L) int index)
      Parameters:
      index - index of the frame
      Returns:
      duration of the given frame in milliseconds
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >= <number of frames>
    • seekToFrame

      public void seekToFrame​(@IntRange(from=0L) int index)
      Seeks to given frame
      Parameters:
      index - index of the frame
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >= <number of frames>
    • getNumberOfFrames

      public int getNumberOfFrames()
      Returns:
      number of frames in GIF, at least one
    • getCurrentFrameIndex

      public int getCurrentFrameIndex()
      Returns:
      index of recently rendered frame or -1 if this object is recycled
    • setSpeed

      public void setSpeed​(@FloatRange(from=0.0,fromInclusive=false) float factor)
      Sets new animation speed factor. See GifDrawable.setSpeed(float).
      Parameters:
      factor - new speed factor, eg. 0.5f means half speed, 1.0f - normal, 2.0f - double speed
      Throws:
      IllegalArgumentException - if factor<=0
    • glTexImage2D

      public void glTexImage2D​(int target, int level)
      Equivalent of GLES20.glTexImage2D(int, int, int, int, int, int, int, int, Buffer). Where Buffer contains pixels of the current frame.
      Parameters:
      level - level-of-detail number
      target - target texture
    • glTexSubImage2D

      public void glTexSubImage2D​(int target, int level)
      Equivalent of GLES20.glTexSubImage2D(int, int, int, int, int, int, int, int, Buffer). Where Buffer contains pixels of the current frame.
      Parameters:
      level - level-of-detail number
      target - target texture
    • startDecoderThread

      public void startDecoderThread()
      Creates frame buffer and starts decoding thread. Does nothing if already started.
    • stopDecoderThread

      public void stopDecoderThread()
      Stops decoder thread and releases frame buffer. Does nothing if already stopped.
    • recycle

      public void recycle()
      See GifDrawable.recycle(). Decoder thread is stopped automatically.
    • getWidth

      public int getWidth()
      Returns:
      width of the GIF canvas, 0 if recycled
    • getHeight

      public int getHeight()
      Returns:
      height of the GIF canvas, 0 if recycled
    • getDuration

      public int getDuration()
      Returns:
      duration of of one loop the animation in milliseconds. Result is always multiple of 10.
    • finalize

      protected final void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable