-
- All Implemented Interfaces:
-
com.batch.android.messaging.gif.GifDecoder
public class StandardGifDecoder implements GifDecoder
Reads frame data from a GIF image source and decodes it into individual frames for animation purposes. Image data can be read from either and InputStream source or a byte[].
This class is optimized for running animations with the frames, there are no methods to get individual frame images, only to decode the next frame in the animation sequence. Instead, it lowers its memory footprint by only housing the minimum data necessary to decode the next frame in the animation sequence.
The animation must be manually moved forward using advance before requesting the next frame. This method must also be called before you request the first frame or an error will occur.
Implementation adapted from sample code published in Lyons. (2004). Java for Programmers, republished under the MIT Open Source License
-
-
Field Summary
Fields Modifier and Type Field Description private intstatus
-
Constructor Summary
Constructors Constructor Description StandardGifDecoder(GifDecoder.BitmapProvider provider, ByteBuffer rawData)StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData)StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData, int sampleSize)StandardGifDecoder(GifDecoder.BitmapProvider provider)
-
Method Summary
Modifier and Type Method Description intgetStatus()Returns the current status of the decoder. intgetWidth()intgetHeight()ByteBuffergetData()voidadvance()Move the animation frame counter forward. intgetDelay(int n)Gets display duration for specified frame. intgetNextDelay()Gets display duration for the upcoming frame in ms. intgetFrameCount()Gets the number of frames read from file. intgetCurrentFrameIndex()Gets the current index of the animation frame, or -1 if animation hasn't not yet started. voidresetFrameIndex()Resets the frame pointer to before the 0th frame, as if we'd never used this decoder todecode any frames. intgetLoopCount()Gets the "Netscape" loop count, if any. intgetNetscapeLoopCount()Gets the "Netscape" loop count, if any. intgetTotalIterationCount()Gets the total countwhich represents how many times the animation sequence should be displayed. intgetByteSize()Returns an estimated byte size for this decoder based on the data provided to , as well as internal buffers. synchronized BitmapgetNextFrame()Get the next frame in the animation sequence. intread(@Nullable() InputStream is, int contentLength)Reads GIF image from stream. voidclear()synchronized voidsetData(@NonNull() GifHeader header, @NonNull() Array<byte> data)synchronized voidsetData(@NonNull() GifHeader header, @NonNull() ByteBuffer buffer)synchronized voidsetData(@NonNull() GifHeader header, @NonNull() ByteBuffer buffer, int sampleSize)synchronized intread(@Nullable() Array<byte> data)Reads GIF image from byte array. voidsetDefaultBitmapConfig(@NonNull() Bitmap.Config config)Sets the default Bitmap.Config to use when decoding frames of a GIF. -
-
Constructor Detail
-
StandardGifDecoder
StandardGifDecoder(GifDecoder.BitmapProvider provider, ByteBuffer rawData)
-
StandardGifDecoder
StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData)
-
StandardGifDecoder
StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData, int sampleSize)
-
StandardGifDecoder
StandardGifDecoder(GifDecoder.BitmapProvider provider)
-
-
Method Detail
-
getStatus
int getStatus()
Returns the current status of the decoder.
Status will update per frame to allow the caller to tell whether or not the current framewas decoded successfully and/or completely. Format and open failures persist across frames.
-
getWidth
int getWidth()
-
getHeight
int getHeight()
-
getData
@NonNull() ByteBuffer getData()
-
advance
void advance()
Move the animation frame counter forward.
-
getDelay
int getDelay(int n)
Gets display duration for specified frame.
- Parameters:
n- int index of frame.
-
getNextDelay
int getNextDelay()
Gets display duration for the upcoming frame in ms.
-
getFrameCount
int getFrameCount()
Gets the number of frames read from file.
-
getCurrentFrameIndex
int getCurrentFrameIndex()
Gets the current index of the animation frame, or -1 if animation hasn't not yet started.
-
resetFrameIndex
void resetFrameIndex()
Resets the frame pointer to before the 0th frame, as if we'd never used this decoder todecode any frames.
-
getLoopCount
@Deprecated() int getLoopCount()
Gets the "Netscape" loop count, if any. A count of 0 means repeat indefinitely.
-
getNetscapeLoopCount
int getNetscapeLoopCount()
Gets the "Netscape" loop count, if any.A count of 0 (NETSCAPE_LOOP_COUNT_FOREVER) means repeat indefinitely.It must not be a negative value.Use getTotalIterationCount to know how many times the animation sequence should be displayed.
-
getTotalIterationCount
int getTotalIterationCount()
Gets the total countwhich represents how many times the animation sequence should be displayed.A count of 0 (TOTAL_ITERATION_COUNT_FOREVER) means repeat indefinitely.It must not be a negative value.
The total count is calculated as follows by using getNetscapeLoopCount.This behavior is the same as most web browsers.
-
getByteSize
int getByteSize()
-
getNextFrame
@Nullable() synchronized Bitmap getNextFrame()
Get the next frame in the animation sequence.
-
read
int read(@Nullable() InputStream is, int contentLength)
Reads GIF image from stream.
- Parameters:
is- containing GIF file.
-
clear
void clear()
-
setData
synchronized void setData(@NonNull() GifHeader header, @NonNull() ByteBuffer buffer)
-
setData
synchronized void setData(@NonNull() GifHeader header, @NonNull() ByteBuffer buffer, int sampleSize)
-
read
synchronized int read(@Nullable() Array<byte> data)
Reads GIF image from byte array.
- Parameters:
data- containing GIF file.
-
setDefaultBitmapConfig
void setDefaultBitmapConfig(@NonNull() Bitmap.Config config)
Sets the default Bitmap.Config to use when decoding frames of a GIF.
Valid options are ARGB_8888 and RGB_565. ARGB_8888 will produce higher quality frames, but willalso use 2x the memory of RGB_565.
Defaults to ARGB_8888
This value is not a guarantee. For example if set to RGB_565 and the GIF contains transparent pixels, ARGB_8888 will be used anyway to support thetransparency.
-
-
-
-