Class GifDecoder

java.lang.Object
org.ngengine.stbimage.GifDecoder
All Implemented Interfaces:
StbDecoder

public class GifDecoder extends Object implements StbDecoder
GIF decoder. Supports regular stbi_load-like first-frame decode through load(int), streaming frame-by-frame decode through loadNextFrame(int), and full materialization through loadAllFrames(int).
  • Constructor Details

    • GifDecoder

      public GifDecoder(ByteBuffer buffer, IntFunction<ByteBuffer> allocator, boolean flipVertically)
      Creates a GIF decoder instance.
      Parameters:
      buffer - source data
      allocator - output allocator
      flipVertically - true to flip decoded rows
  • Method Details

    • isGif

      public static boolean isGif(ByteBuffer buffer)
      Tests whether the source starts with a GIF87a/GIF89a signature.
      Parameters:
      buffer - source bytes
      Returns:
      true if the signature indicates GIF
    • getAllocator

      public IntFunction<ByteBuffer> getAllocator()
      Description copied from interface: StbDecoder
      Returns the allocator used by this decoder for output buffers.
      Specified by:
      getAllocator in interface StbDecoder
      Returns:
      allocator function
    • info

      public StbImageInfo info()
      Description copied from interface: StbDecoder
      Reads image metadata without fully decoding pixel data.
      Specified by:
      info in interface StbDecoder
      Returns:
      image information
    • load

      public StbImageResult load(int desiredChannels)
      Decodes and returns the first frame (stb-style load behavior).
      Specified by:
      load in interface StbDecoder
      Parameters:
      desiredChannels - requested output channels (0 keeps source/default behavior)
      Returns:
      decoded image result
    • loadNextFrame

      public StbImageResult loadNextFrame(int desiredChannels)
      Loads the next GIF frame in streaming mode. Once the trailer is reached, already decoded frames are replayed in a loop.
      Specified by:
      loadNextFrame in interface StbDecoder
      Parameters:
      desiredChannels -
      Returns:
    • loadAllFrames

      public List<StbImageResult> loadAllFrames(int desiredChannels)
      Decodes all frames and returns them.
      Specified by:
      loadAllFrames in interface StbDecoder
      Parameters:
      desiredChannels - requested channel count
      Returns:
      all frames in playback order
    • getFrameCount

      public int getFrameCount()
      Returns the number of frames in the GIF stream.
    • isAnimated

      public boolean isAnimated()
      Indicates whether the GIF contains more than one frame.
    • getLastFrameDelayMs

      public int getLastFrameDelayMs()
      Returns delay in milliseconds for the last frame returned by load(int) or loadNextFrame(int).
    • setFillFirstFrameBackground

      public void setFillFirstFrameBackground(boolean fillFirstFrameBackground)
      Controls whether first-frame untouched pixels are filled using GIF logical screen background color.

      Enabled matches stb behavior. Disabling is useful for UI preview flows that prefer transparent untouched pixels.