Class PngEncoder
java.lang.Object
javajs.img.ImageEncoder
javajs.img.PngEncoder
- All Implemented Interfaces:
GenericImageEncoder
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 Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intstatic final intstatic final intConstants for filtersstatic final intstatic final intprotected byte[]protected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidgenerate()protected byte[]getBytes()protected static voidgetInt4(int n, byte[] int4) protected voidsetData(byte[] b, int pt) protected voidprotected voidwriteByte(int b) Write a single byte into the pngBytes array at a given position.protected voidwriteBytes(byte[] data) Write an array of bytes into the pngBytes array.protected voidwriteCRC()protected voidwriteInt2(int n) Write a two-byte integer into the pngBytes array at a given position.protected voidwriteInt4(int n) Write a four-byte integer into the pngBytes array at a given position.protected voidWrite a string into the pngBytes array at a given position.Methods inherited from class ImageEncoder
close, createImage, putByte, putString
-
Field Details
-
FILTER_NONE
public static final int FILTER_NONEConstants 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
- Specified by:
setParamsin classImageEncoder
-
generate
- Specified by:
generatein classImageEncoder- 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
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.
-