Package javajs.img
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 - <PNG0|PNGJ><0000000pt>+<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 int
protected int
static final int
static final int
Constants for filtersstatic final int
static final int
protected byte[]
protected int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
generate()
protected byte[]
getBytes()
protected static void
getInt4
(int n, byte[] int4) protected void
setData
(byte[] b, int pt) protected void
protected void
writeByte
(int b) Write a single byte into the pngBytes array at a given position.protected void
writeBytes
(byte[] data) Write an array of bytes into the pngBytes array.protected void
writeCRC()
protected void
writeInt2
(int n) Write a two-byte integer into the pngBytes array at a given position.protected void
writeInt4
(int n) Write a four-byte integer into the pngBytes array at a given position.protected void
Write a string into the pngBytes array at a given position.Methods inherited from class javajs.img.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:
setParams
in classImageEncoder
-
generate
- Specified by:
generate
in 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.
-