Interface GifDecoder

All Known Implementing Classes:
StandardGifDecoder

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

    • STATUS_OK

      static final int STATUS_OK
      File read status: No errors.
      See Also:
    • STATUS_FORMAT_ERROR

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

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

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

      static final int TOTAL_ITERATION_COUNT_FOREVER
      The total iteration count which means repeat forever.
      See Also:
  • Method Details

    • getWidth

      int getWidth()
    • getHeight

      int getHeight()
    • getData

      @NonNull 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.
    • getNetscapeLoopCount

      int getNetscapeLoopCount()
      Gets 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.
      Use getTotalIterationCount() to know how many times the animation sequence should be displayed.
      Returns:
      loop count if one was specified, else -1 (GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST).
    • getTotalIterationCount

      int getTotalIterationCount()
      Gets the total count which 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.

      getNetscapeLoopCount() The total count
      GifHeader.NETSCAPE_LOOP_COUNT_FOREVER TOTAL_ITERATION_COUNT_FOREVER
      GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST 1
      n (n > 0) n + 1

      Returns:
      total iteration count calculated from "Netscape" loop count.
      See Also:
    • 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 Bitmap getNextFrame()
      Get the next frame in the animation sequence.
      Returns:
      Bitmap representation of frame.
    • read

      int read(@Nullable 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 ByteBuffer buffer)
    • setData

      void setData(@NonNull GifHeader header, @NonNull 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 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.