public class StandardGifDecoder extends Object implements GifDecoder
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
GifDecoder.BitmapProvider, GifDecoder.GifDecodeStatusSTATUS_FORMAT_ERROR, STATUS_OK, STATUS_OPEN_ERROR, STATUS_PARTIAL_DECODE, TOTAL_ITERATION_COUNT_FOREVER| Constructor and Description |
|---|
StandardGifDecoder(GifDecoder.BitmapProvider provider) |
StandardGifDecoder(GifDecoder.BitmapProvider provider,
GifHeader gifHeader,
ByteBuffer rawData) |
StandardGifDecoder(GifDecoder.BitmapProvider provider,
GifHeader gifHeader,
ByteBuffer rawData,
int sampleSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
advance()
Move the animation frame counter forward.
|
void |
clear() |
int |
getByteSize()
Returns an estimated byte size for this decoder based on the data provided to
GifDecoder.setData(GifHeader, byte[]), as well as internal buffers. |
int |
getCurrentFrameIndex()
Gets the current index of the animation frame, or -1 if animation hasn't not yet started.
|
ByteBuffer |
getData() |
int |
getDelay(int n)
Gets display duration for specified frame.
|
int |
getFrameCount()
Gets the number of frames read from file.
|
int |
getHeight() |
int |
getLoopCount()
Deprecated.
|
int |
getNetscapeLoopCount()
Gets the "Netscape" loop count, if any.
|
int |
getNextDelay()
Gets display duration for the upcoming frame in ms.
|
Bitmap |
getNextFrame()
Get the next frame in the animation sequence.
|
int |
getStatus()
Returns the current status of the decoder.
|
int |
getTotalIterationCount()
Gets the total count
which represents how many times the animation sequence should be displayed.
|
int |
getWidth() |
int |
read(byte[] data)
Reads GIF image from byte array.
|
int |
read(InputStream is,
int contentLength)
Reads GIF image from stream.
|
void |
resetFrameIndex()
Resets the frame pointer to before the 0th frame, as if we'd never used this decoder to
decode any frames.
|
void |
setData(GifHeader header,
byte[] data) |
void |
setData(GifHeader header,
ByteBuffer buffer) |
void |
setData(GifHeader header,
ByteBuffer buffer,
int sampleSize) |
public StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData)
public StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData, int sampleSize)
public StandardGifDecoder(GifDecoder.BitmapProvider provider)
public int getWidth()
getWidth in interface GifDecoderpublic int getHeight()
getHeight in interface GifDecoderpublic ByteBuffer getData()
getData in interface GifDecoderpublic int getStatus()
GifDecoderStatus will update per frame to allow the caller to tell whether or not the current frame was decoded successfully and/or completely. Format and open failures persist across frames.
getStatus in interface GifDecoderpublic void advance()
GifDecoderadvance in interface GifDecoderpublic int getDelay(int n)
GifDecodergetDelay in interface GifDecodern - int index of frame.public int getNextDelay()
GifDecodergetNextDelay in interface GifDecoderpublic int getFrameCount()
GifDecodergetFrameCount in interface GifDecoderpublic int getCurrentFrameIndex()
GifDecodergetCurrentFrameIndex in interface GifDecoderpublic void resetFrameIndex()
GifDecoderresetFrameIndex in interface GifDecoder@Deprecated public int getLoopCount()
GifDecodergetLoopCount in interface GifDecoderpublic int getNetscapeLoopCount()
GifDecoderGifHeader.NETSCAPE_LOOP_COUNT_FOREVER) means repeat indefinitely.
It must not be a negative value.
GifDecoder.getTotalIterationCount()
to know how many times the animation sequence should be displayed.getNetscapeLoopCount in interface GifDecoderGifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST).public int getTotalIterationCount()
GifDecoderGifDecoder.TOTAL_ITERATION_COUNT_FOREVER) means repeat indefinitely.
It must not be a negative value.
The total count is calculated as follows by using GifDecoder.getNetscapeLoopCount().
This behavior is the same as most web browsers.
getNetscapeLoopCount() |
The total count |
|---|---|
GifHeader.NETSCAPE_LOOP_COUNT_FOREVER |
GifDecoder.TOTAL_ITERATION_COUNT_FOREVER |
GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST |
1 |
n (n > 0) |
n + 1 |
getTotalIterationCount in interface GifDecoderpublic int getByteSize()
GifDecoderGifDecoder.setData(GifHeader, byte[]), as well as internal buffers.getByteSize in interface GifDecoderpublic Bitmap getNextFrame()
GifDecodergetNextFrame in interface GifDecoderpublic int read(InputStream is, int contentLength)
GifDecoderread in interface GifDecoderis - containing GIF file.public void clear()
clear in interface GifDecoderpublic void setData(GifHeader header, byte[] data)
setData in interface GifDecoderpublic void setData(GifHeader header, ByteBuffer buffer)
setData in interface GifDecoderpublic void setData(GifHeader header, ByteBuffer buffer, int sampleSize)
setData in interface GifDecoderpublic int read(byte[] data)
GifDecoderread in interface GifDecoderdata - containing GIF file.