Class PNGFileFormat


public final class PNGFileFormat extends FileFormat.StaticImageFileFormat
  • Field Details

    • SIGNATURE_LENGTH

      static final int SIGNATURE_LENGTH
      See Also:
    • PRIME

      static final int PRIME
      See Also:
    • headerChunk

      PngIhdrChunk headerChunk
    • paletteChunk

      PngPlteChunk paletteChunk
    • imageData

      ImageData imageData
    • data

      byte[] data
    • alphaPalette

      byte[] alphaPalette
    • headerByte1

      byte headerByte1
    • headerByte2

      byte headerByte2
    • adler

      int adler
  • Constructor Details

    • PNGFileFormat

      public PNGFileFormat()
  • Method Details

    • readSignature

      void readSignature() throws IOException
      Skip over signature data. This has already been verified in isFileFormat().
      Throws:
      IOException
    • loadFromByteStream

      ImageData[] loadFromByteStream()
      Load the PNG image from the byte stream.
      Specified by:
      loadFromByteStream in class FileFormat.StaticImageFileFormat
    • readNextChunk

      void readNextChunk(PngChunkReader chunkReader) throws IOException
      Read and handle the next chunk of data from the PNG file.
      Throws:
      IOException
    • unloadIntoByteStream

      void unloadIntoByteStream(ImageLoader loader)
      Specified by:
      unloadIntoByteStream in class FileFormat
    • isFileFormat

      boolean isFileFormat(LEDataInputStream stream) throws IOException
      Description copied from class: FileFormat
      Return whether or not the specified input stream represents a supported file format.
      Specified by:
      isFileFormat in class FileFormat
      Throws:
      IOException
    • validateBitDepth

      byte[] validateBitDepth(byte[] data)
      SWT does not support 16-bit depths. If this image uses 16-bit depths, convert the data to an 8-bit depth.
    • setPixelData

      void setPixelData(byte[] data, ImageData imageData)
      SWT does not support greyscale as a color type. For plain grayscale, we create a palette. For Grayscale with Alpha, however, we need to convert the pixels to use RGB values. Note: This method assumes that the bit depth of the data has already been restricted to 8 or less.
    • setImageDataValues

      void setImageDataValues(byte[] data, ImageData imageData)
      PNG supports some color types and bit depths that are unsupported by SWT. If the image uses an unsupported color type (either of the gray scale types) or bit depth (16), convert the data to an SWT-supported format. Then assign the data into the ImageData given.
    • readPixelData

      void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) throws IOException
      Read the image data from the data stream. This must handle decoding the data, filtering, and interlacing.
      Throws:
      IOException
    • getAlignedBytesPerRow

      int getAlignedBytesPerRow()
      Answer the number of bytes in a word-aligned row of pixel data.
    • getBytesPerRow

      int getBytesPerRow()
      Answer the number of bytes in each row of the image data. Each PNG row is byte-aligned, so images with bit depths less than a byte may have unused bits at the end of each row. The value of these bits is undefined.
    • getBytesPerPixel

      int getBytesPerPixel()
      Answer the number of bytes needed to represent a pixel. This value depends on the image's color type and bit depth. Note that this method rounds up if an image's pixel size isn't byte-aligned.
    • getBytesPerRow

      int getBytesPerRow(int rowWidthInPixels)
      Answer the number of bytes in a row of the given pixel width. Each row is byte-aligned, so images with bit depths less than a byte may have unused bits at the end of each row. The value of these bits is undefined.
    • readInterlaceFrame

      void readInterlaceFrame(InputStream inputStream, int rowInterval, int columnInterval, int startRow, int startColumn, int frameCount) throws IOException
      1. Read one of the seven frames of interlaced data. 2. Update the imageData. 3. Notify the image loader's listeners of the frame load.
      Throws:
      IOException
    • readInterlacedImage

      void readInterlacedImage(InputStream inputStream) throws IOException
      Read the pixel data for an interlaced image from the data stream.
      Throws:
      IOException
    • fireInterlacedFrameEvent

      void fireInterlacedFrameEvent(int frameCount)
      Fire an event to let listeners know that an interlaced frame has been loaded. finalFrame should be true if the image has finished loading, false if there are more frames to come.
    • readNonInterlacedImage

      void readNonInterlacedImage(InputStream inputStream) throws IOException
      Read the pixel data for a non-interlaced image from the data stream. Update the imageData to reflect the new data.
      Throws:
      IOException
    • compress16BitDepthTo8BitDepth

      static void compress16BitDepthTo8BitDepth(byte[] source, int sourceOffset, byte[] destination, int destinationOffset, int numberOfValues)
      SWT does not support 16-bit depth color formats. Convert the 16-bit data to 8-bit data. The correct way to do this is to multiply each 16 bit value by the value: (2^8 - 1) / (2^16 - 1). The fast way to do this is just to drop the low byte of the 16-bit value.
    • compress16BitDepthTo8BitDepth

      static int compress16BitDepthTo8BitDepth(int value)
      SWT does not support 16-bit depth color formats. Convert the 16-bit data to 8-bit data. The correct way to do this is to multiply each 16 bit value by the value: (2^8 - 1) / (2^16 - 1). The fast way to do this is just to drop the low byte of the 16-bit value.
    • filterRow

      void filterRow(byte[] row, byte[] previousRow, int filterType)
      PNG supports four filtering types. These types are applied per row of image data. This method unfilters the given row based on the filterType.