Class PngDecoder

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

public class PngDecoder extends Object implements StbDecoder
PNG decoder with zlib decompression. Supports 1/2/4/8/16-bit depths, all color types (grayscale, RGB, RGBA, palette).
  • Constructor Details

    • PngDecoder

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

    • isPng

      public static boolean isPng(ByteBuffer buffer)
      Tests whether the buffer starts with a PNG signature.
      Parameters:
      buffer - source bytes
      Returns:
      true if signature matches PNG
    • setConvertIphonePngToRgb

      public void setConvertIphonePngToRgb(boolean convertIphonePngToRgb)
      Enables/disables iPhone CgBI BGR(A)-to-RGB(A) conversion.
      Parameters:
      convertIphonePngToRgb - true to convert channels
    • setUnpremultiplyOnLoad

      public void setUnpremultiplyOnLoad(boolean unpremultiplyOnLoad)
      Enables/disables iPhone PNG unpremultiply by alpha.
      Parameters:
      unpremultiplyOnLoad - true to unpremultiply on decode
    • getAllocator

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

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

      public StbImageResult load(int desiredChannels)
      Decodes image pixels.
      Specified by:
      load in interface StbDecoder
      Parameters:
      desiredChannels - requested output channels (0 keeps source/default behavior)
      Returns:
      decoded image result