Interface GifDecoder

  • All Known Implementing Classes:
    StandardGifDecoder

    public interface GifDecoder
    Shared interface for GIF decoders.
    • Field Detail

      • STATUS_FORMAT_ERROR

        static final int STATUS_FORMAT_ERROR
        File read status: Error decoding file (may be partially decoded).
        See Also:
        Constant Field Values
      • STATUS_OPEN_ERROR

        static final int STATUS_OPEN_ERROR
        File read status: Unable to open source.
        See Also:
        Constant Field Values
      • STATUS_PARTIAL_DECODE

        static final int STATUS_PARTIAL_DECODE
        Unable to fully decode the current frame.
        See Also:
        Constant Field Values
      • TOTAL_ITERATION_COUNT_FOREVER

        static final int TOTAL_ITERATION_COUNT_FOREVER
        The total iteration count which means repeat forever.
        See Also:
        Constant Field Values
    • Method Detail

      • getWidth

        int getWidth()
      • getHeight

        int getHeight()
      • getData

        @NonNull
        java.nio.ByteBuffer getData()
      • 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 frame was decoded successfully and/or completely. Format and open failures persist across frames.

      • 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.
        Returns:
        delay in milliseconds.
      • getNextDelay

        int getNextDelay()
        Gets display duration for the upcoming frame in ms.
      • getFrameCount

        int getFrameCount()
        Gets the number of frames read from file.
        Returns:
        frame count.
      • getCurrentFrameIndex

        int getCurrentFrameIndex()
        Gets the current index of the animation frame, or -1 if animation hasn't not yet started.
        Returns:
        frame index.
      • resetFrameIndex

        void resetFrameIndex()
        Resets the frame pointer to before the 0th frame, as if we'd never used this decoder to decode any frames.
      • getLoopCount

        @Deprecated
        int getLoopCount()
        Deprecated.
        Use getNetscapeLoopCount() instead. This method cannot distinguish whether the loop count is 1 or doesn't exist.
        Gets the "Netscape" loop count, if any. A count of 0 means repeat indefinitely.
        Returns:
        loop count if one was specified, else 1.
      • getByteSize

        int getByteSize()
        Returns an estimated byte size for this decoder based on the data provided to setData(GifHeader, byte[]), as well as internal buffers.
      • getNextFrame

        @Nullable
        android.graphics.Bitmap getNextFrame()
        Get the next frame in the animation sequence.
        Returns:
        Bitmap representation of frame.
      • read

        int read​(@Nullable
                 java.io.InputStream is,
                 int contentLength)
        Reads GIF image from stream.
        Parameters:
        is - containing GIF file.
        Returns:
        read status code (0 = no errors).
      • clear

        void clear()
      • setData

        void setData​(@NonNull
                     GifHeader header,
                     @NonNull
                     byte[] data)
      • setData

        void setData​(@NonNull
                     GifHeader header,
                     @NonNull
                     java.nio.ByteBuffer buffer)
      • setData

        void setData​(@NonNull
                     GifHeader header,
                     @NonNull
                     java.nio.ByteBuffer buffer,
                     int sampleSize)
      • read

        int read​(@Nullable
                 byte[] data)
        Reads GIF image from byte array.
        Parameters:
        data - containing GIF file.
        Returns:
        read status code (0 = no errors).
      • setDefaultBitmapConfig

        void setDefaultBitmapConfig​(@NonNull
                                    android.graphics.Bitmap.Config format)
        Sets the default Bitmap.Config to use when decoding frames of a GIF.

        Valid options are Bitmap.Config.ARGB_8888 and Bitmap.Config.RGB_565. Bitmap.Config.ARGB_8888 will produce higher quality frames, but will also use 2x the memory of Bitmap.Config.RGB_565.

        Defaults to Bitmap.Config.ARGB_8888

        This value is not a guarantee. For example if set to Bitmap.Config.RGB_565 and the GIF contains transparent pixels, Bitmap.Config.ARGB_8888 will be used anyway to support the transparency.