Class StandardGifDecoder
- All Implemented Interfaces:
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
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.bumptech.glide.gifdecoder.GifDecoder
GifDecoder.BitmapProvider, GifDecoder.GifDecodeStatus -
Field Summary
Fields inherited from interface com.bumptech.glide.gifdecoder.GifDecoder
STATUS_FORMAT_ERROR, STATUS_OK, STATUS_OPEN_ERROR, STATUS_PARTIAL_DECODE, TOTAL_ITERATION_COUNT_FOREVER -
Constructor Summary
ConstructorsConstructorDescriptionStandardGifDecoder(GifDecoder.BitmapProvider provider) StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData) StandardGifDecoder(GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData, int sampleSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance()Move the animation frame counter forward.voidclear()intReturns an estimated byte size for this decoder based on the data provided toGifDecoder.setData(GifHeader, byte[]), as well as internal buffers.intGets the current index of the animation frame, or -1 if animation hasn't not yet started.getData()intgetDelay(int n) Gets display duration for specified frame.intGets the number of frames read from file.intintDeprecated.intGets the "Netscape" loop count, if any.intGets display duration for the upcoming frame in ms.Get the next frame in the animation sequence.intReturns the current status of the decoder.intGets the total count which represents how many times the animation sequence should be displayed.intgetWidth()intread(byte[] data) Reads GIF image from byte array.intread(InputStream is, int contentLength) Reads GIF image from stream.voidResets the frame pointer to before the 0th frame, as if we'd never used this decoder to decode any frames.voidvoidsetData(GifHeader header, ByteBuffer buffer) voidsetData(GifHeader header, ByteBuffer buffer, int sampleSize) voidsetDefaultBitmapConfig(Bitmap.Config config) Sets the defaultBitmap.Configto use when decoding frames of a GIF.
-
Constructor Details
-
StandardGifDecoder
public StandardGifDecoder(@NonNull GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData) -
StandardGifDecoder
public StandardGifDecoder(@NonNull GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData, int sampleSize) -
StandardGifDecoder
-
-
Method Details
-
getWidth
public int getWidth()- Specified by:
getWidthin interfaceGifDecoder
-
getHeight
public int getHeight()- Specified by:
getHeightin interfaceGifDecoder
-
getData
- Specified by:
getDatain interfaceGifDecoder
-
getStatus
public int getStatus()Description copied from interface:GifDecoderReturns the current status of the decoder.Status 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.
- Specified by:
getStatusin interfaceGifDecoder
-
advance
public void advance()Description copied from interface:GifDecoderMove the animation frame counter forward.- Specified by:
advancein interfaceGifDecoder
-
getDelay
public int getDelay(int n) Description copied from interface:GifDecoderGets display duration for specified frame.- Specified by:
getDelayin interfaceGifDecoder- Parameters:
n- int index of frame.- Returns:
- delay in milliseconds.
-
getNextDelay
public int getNextDelay()Description copied from interface:GifDecoderGets display duration for the upcoming frame in ms.- Specified by:
getNextDelayin interfaceGifDecoder
-
getFrameCount
public int getFrameCount()Description copied from interface:GifDecoderGets the number of frames read from file.- Specified by:
getFrameCountin interfaceGifDecoder- Returns:
- frame count.
-
getCurrentFrameIndex
public int getCurrentFrameIndex()Description copied from interface:GifDecoderGets the current index of the animation frame, or -1 if animation hasn't not yet started.- Specified by:
getCurrentFrameIndexin interfaceGifDecoder- Returns:
- frame index.
-
resetFrameIndex
public void resetFrameIndex()Description copied from interface:GifDecoderResets the frame pointer to before the 0th frame, as if we'd never used this decoder to decode any frames.- Specified by:
resetFrameIndexin interfaceGifDecoder
-
getLoopCount
Deprecated.Description copied from interface:GifDecoderGets the "Netscape" loop count, if any. A count of 0 means repeat indefinitely.- Specified by:
getLoopCountin interfaceGifDecoder- Returns:
- loop count if one was specified, else 1.
-
getNetscapeLoopCount
public int getNetscapeLoopCount()Description copied from interface:GifDecoderGets the "Netscape" loop count, if any. A count of 0 (GifHeader.NETSCAPE_LOOP_COUNT_FOREVER) means repeat indefinitely. It must not be a negative value.
UseGifDecoder.getTotalIterationCount()to know how many times the animation sequence should be displayed.- Specified by:
getNetscapeLoopCountin interfaceGifDecoder- Returns:
- loop count if one was specified,
else -1 (
GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST).
-
getTotalIterationCount
public int getTotalIterationCount()Description copied from interface:GifDecoderGets the total count which represents how many times the animation sequence should be displayed. A count of 0 (GifDecoder.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_FOREVERGifDecoder.TOTAL_ITERATION_COUNT_FOREVERGifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST1n (n > 0)n + 1- Specified by:
getTotalIterationCountin interfaceGifDecoder- Returns:
- total iteration count calculated from "Netscape" loop count.
- See Also:
-
getByteSize
public int getByteSize()Description copied from interface:GifDecoderReturns an estimated byte size for this decoder based on the data provided toGifDecoder.setData(GifHeader, byte[]), as well as internal buffers.- Specified by:
getByteSizein interfaceGifDecoder
-
getNextFrame
Description copied from interface:GifDecoderGet the next frame in the animation sequence.- Specified by:
getNextFramein interfaceGifDecoder- Returns:
- Bitmap representation of frame.
-
read
Description copied from interface:GifDecoderReads GIF image from stream.- Specified by:
readin interfaceGifDecoder- Parameters:
is- containing GIF file.- Returns:
- read status code (0 = no errors).
-
clear
public void clear()- Specified by:
clearin interfaceGifDecoder
-
setData
- Specified by:
setDatain interfaceGifDecoder
-
setData
- Specified by:
setDatain interfaceGifDecoder
-
setData
- Specified by:
setDatain interfaceGifDecoder
-
read
public int read(@Nullable byte[] data) Description copied from interface:GifDecoderReads GIF image from byte array.- Specified by:
readin interfaceGifDecoder- Parameters:
data- containing GIF file.- Returns:
- read status code (0 = no errors).
-
setDefaultBitmapConfig
Description copied from interface:GifDecoderSets the defaultBitmap.Configto use when decoding frames of a GIF.Valid options are
Bitmap.Config.ARGB_8888andBitmap.Config.RGB_565.Bitmap.Config.ARGB_8888will produce higher quality frames, but will also use 2x the memory ofBitmap.Config.RGB_565.Defaults to
Bitmap.Config.ARGB_8888This value is not a guarantee. For example if set to
Bitmap.Config.RGB_565and the GIF contains transparent pixels,Bitmap.Config.ARGB_8888will be used anyway to support the transparency.- Specified by:
setDefaultBitmapConfigin interfaceGifDecoder
-