Package pl.droidsonroids.gif
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:
Current frame can be copied to 2D texture when needed. See
- Automatic animation according to timing defined in GIF file -
startDecoderThread()andstopDecoderThread(). - Manual frame advancing -
seekToFrame(int).
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 Summary
Constructors Constructor Description GifTexImage2D(InputSource inputSource, GifOptions options)Constructs new GifTexImage2D. -
Method Summary
Modifier and Type Method Description protected voidfinalize()intgetCurrentFrameIndex()intgetDuration()intgetFrameDuration(int index)intgetHeight()intgetNumberOfFrames()intgetWidth()voidglTexImage2D(int target, int level)voidglTexSubImage2D(int target, int level)voidrecycle()voidseekToFrame(int index)Seeks to given framevoidsetSpeed(float factor)Sets new animation speed factor.voidstartDecoderThread()Creates frame buffer and starts decoding thread.voidstopDecoderThread()Stops decoder thread and releases frame buffer.
-
Constructor Details
-
GifTexImage2D
Constructs new GifTexImage2D. Decoder thread is initially stopped, usestartDecoderThread()to start it.- Parameters:
inputSource- sourceoptions- 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- ifindex < 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- ifindex < 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. SeeGifDrawable.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 ofGLES20.glTexImage2D(int, int, int, int, int, int, int, int, Buffer). WhereBuffercontains pixels of the current frame.- Parameters:
level- level-of-detail numbertarget- target texture
-
glTexSubImage2D
public void glTexSubImage2D(int target, int level)Equivalent ofGLES20.glTexSubImage2D(int, int, int, int, int, int, int, int, Buffer). WhereBuffercontains pixels of the current frame.- Parameters:
level- level-of-detail numbertarget- 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()SeeGifDrawable.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
-