Class EnhancedPngEncoder

java.lang.Object
bdsup2sub.tools.PngEncoder
bdsup2sub.tools.EnhancedPngEncoder

public class EnhancedPngEncoder extends PngEncoder
Version:
1.5, 19 Oct 2003 (modified by 0xdeadbeef in 2009 and mjuhasz in 2012) CHANGES:
--------
19-Sep-2003 : Fix for platforms using EBCDIC (contributed by Paulo Soares);
19-Oct-2003 : Change private fields to protected fields so that
PngEncoderB can inherit them (JDE)
Fixed bug with calculation of nRows
Added modifications for unsigned short images
(contributed by Christian at xpogen.com)
10-Nov-2012 : Removed unused constants and useless method override. (mjuhasz)
  • Field Details

    • PLTE

      private static final byte[] PLTE
      PLTE tag.
    • TRNS

      private static final byte[] TRNS
      tRNS tag.
    • image

      private BufferedImage image
    • wRaster

      private WritableRaster wRaster
    • tType

      private int tType
  • Constructor Details

    • EnhancedPngEncoder

      public EnhancedPngEncoder()
    • EnhancedPngEncoder

      public EnhancedPngEncoder(BufferedImage image)
      Class constructor specifying BufferedImage to encode, with no alpha channel encoding.
      Parameters:
      image - A Java BufferedImage object
    • EnhancedPngEncoder

      public EnhancedPngEncoder(BufferedImage image, boolean encodeAlpha)
      Class constructor specifying BufferedImage to encode, and whether to encode alpha.
      Parameters:
      image - A Java BufferedImage object
      encodeAlpha - Encode the alpha channel? false=no; true=yes
    • EnhancedPngEncoder

      public EnhancedPngEncoder(BufferedImage image, boolean encodeAlpha, int whichFilter)
      Class constructor specifying BufferedImage to encode, whether to encode alpha, and filter to use.
      Parameters:
      image - A Java BufferedImage object
      encodeAlpha - Encode the alpha channel? false=no; true=yes
      whichFilter - 0=none, 1=sub, 2=up
    • EnhancedPngEncoder

      private EnhancedPngEncoder(BufferedImage image, boolean encodeAlpha, int whichFilter, int compLevel)
      Class constructor specifying BufferedImage source to encode, whether to encode alpha, filter to use, and compression level.
      Parameters:
      image - A Java BufferedImage object
      encodeAlpha - Encode the alpha channel? false=no; true=yes
      whichFilter - 0=none, 1=sub, 2=up
      compLevel - 0..9
  • Method Details

    • setImage

      public void setImage(BufferedImage image)
      Set the BufferedImage to be encoded.
      Parameters:
      image - A Java BufferedImage object
    • pngEncode

      public byte[] pngEncode()
      Creates an array of bytes that is the PNG equivalent of the current image.
      Overrides:
      pngEncode in class PngEncoder
      Returns:
      an array of bytes, or null if there was a problem
    • establishStorageInfo

      boolean establishStorageInfo()
      Get and set variables that determine how picture is stored. Retrieves the writable raster of the buffered image, as well its transfer type. Sets number of output bytes per pixel, and, if only eight-bit bytes, turns off alpha encoding.
      Returns:
      true if 1-byte or 4-byte data, false otherwise
    • writeHeader

      protected void writeHeader()
      Write a PNG "IHDR" chunk into the pngBytes array.
      Overrides:
      writeHeader in class PngEncoder
    • writePalette

      void writePalette(IndexColorModel icm)
    • writeAlpha

      void writeAlpha(IndexColorModel icm)
    • writeImageData

      protected boolean writeImageData()
      Write the image data into the pngBytes array. This will write one or more PNG "IDAT" chunks. In order to conserve memory, this method grabs as many rows as will fit into 32K bytes, or the whole image; whichever is less.
      Overrides:
      writeImageData in class PngEncoder
      Returns:
      true if no errors; false if error grabbing pixels