Package javajs.img

Class PngEncoder

All Implemented Interfaces:
GenericImageEncoder

public class PngEncoder extends ImageEncoder
Modified by Bob Hanson hansonr@stolaf.edu to be a subclass of ImageEncoder and to use javajs.util.OutputChannel instead of just returning bytes. Also includes: -- JavaScript-compatible image processing -- transparent background option -- more efficient calculation of needs for pngBytes -- option to use pre-created PNGJ image data (3/19/14; Jmol 14.1.12) -- PNGJ format: // IHDR chunk // tEXt chunk "Jmol type - invalid input: '<'PNG0|PNGJ>invalid input: '<'0000000pt>+invalid input: '<'000000len>" // tEXt chunk "Software - Jmol " // tEXt chunk "Creation Time - " // tRNS chunk transparent color, if desired // IDAT chunk (image data) // IEND chunk // [JMOL ZIP FILE APPENDIX] Original Comment: PngEncoder takes a Java Image object and creates a byte string which can be saved as a PNG file. The Image is presumed to use the DirectColorModel. Thanks to Jay Denny at KeyPoint Software http://www.keypoint.com/ who let me develop this code on company time. You may contact me with (probably very-much-needed) improvements, comments, and bug fixes at: david@catcode.com
Version:
1.4, 31 March 2000
Author:
J. David Eisenberg, http://catcode.com/pngencoder/, Christian Ribeaud (christian.ribeaud@genedata.com), Bob Hanson (hansonr@stolaf.edu)
  • Field Details

    • FILTER_NONE

      public static final int FILTER_NONE
      Constants for filters
      See Also:
    • FILTER_SUB

      public static final int FILTER_SUB
      See Also:
    • FILTER_UP

      public static final int FILTER_UP
      See Also:
    • FILTER_LAST

      public static final int FILTER_LAST
      See Also:
    • startPos

      protected int startPos
    • bytePos

      protected int bytePos
    • pngBytes

      protected byte[] pngBytes
    • dataLen

      protected int dataLen
  • Constructor Details

    • PngEncoder

      public PngEncoder()
  • Method Details

    • setParams

      protected void setParams(Map<String,Object> params)
      Specified by:
      setParams in class ImageEncoder
    • generate

      protected void generate() throws IOException
      Specified by:
      generate in class ImageEncoder
      Throws:
      IOException
    • setData

      protected void setData(byte[] b, int pt)
    • getBytes

      protected byte[] getBytes()
    • writeCRC

      protected void writeCRC()
    • writeInt2

      protected void writeInt2(int n)
      Write a two-byte integer into the pngBytes array at a given position.
      Parameters:
      n - The integer to be written into pngBytes.
    • writeInt4

      protected void writeInt4(int n)
      Write a four-byte integer into the pngBytes array at a given position.
      Parameters:
      n - The integer to be written into pngBytes.
    • getInt4

      protected static void getInt4(int n, byte[] int4)
    • writeByte

      protected void writeByte(int b)
      Write a single byte into the pngBytes array at a given position.
      Parameters:
      b - The byte to be written into pngBytes.
    • writeString

      protected void writeString(String s)
      Write a string into the pngBytes array at a given position. This uses the getBytes method, so the encoding used will be its default.
      Parameters:
      s - The string to be written into pngBytes.
      See Also:
    • writeBytes

      protected void writeBytes(byte[] data)
      Write an array of bytes into the pngBytes array. Both dataLen and bytePos are updated. If we don't have enough room, this is certainly in image data writing, so we add just enough for CRC END CRC
      Parameters:
      data - The data to be written into pngBytes.