public class PngEncoder
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected int |
bytePos |
protected int |
bytesPerPixel |
protected int |
compressionLevel |
protected java.util.zip.CRC32 |
crc |
protected long |
crcValue |
protected int |
dataPos |
static boolean |
ENCODE_ALPHA
Constant specifying that alpha channel should be encoded.
|
protected boolean |
encodeAlpha |
protected int |
endPos |
protected int |
filter |
static int |
FILTER_LAST |
static int |
FILTER_NONE
Constants for filters
|
static int |
FILTER_SUB |
static int |
FILTER_UP |
protected int |
hdrPos |
protected int |
height |
protected java.awt.Image |
image |
(package private) byte[] |
int2 |
(package private) byte[] |
int4 |
protected byte[] |
leftBytes |
protected int |
maxPos |
static boolean |
NO_ALPHA
Constant specifying that alpha channel should not be encoded.
|
protected byte[] |
pngBytes |
protected byte[] |
priorRow |
private static int |
ptJmolByteText |
private java.lang.Integer |
transparentColor |
private java.lang.String |
type |
protected int |
width |
Constructor and Description |
---|
PngEncoder()
Class constructor
|
PngEncoder(java.awt.Image image)
Class constructor specifying Image to encode, with no alpha channel encoding.
|
PngEncoder(java.awt.Image image,
boolean encodeAlpha)
Class constructor specifying Image to encode, and whether to encode alpha.
|
PngEncoder(java.awt.Image image,
boolean encodeAlpha,
int whichFilter)
Class constructor specifying Image to encode, whether to encode alpha, and filter to use.
|
PngEncoder(java.awt.Image image,
boolean encodeAlpha,
int whichFilter,
int compLevel)
Class constructor specifying Image source to encode, whether to encode alpha, filter to use, and compression level.
|
Modifier and Type | Method and Description |
---|---|
protected void |
filterSub(byte[] pixels,
int startPos,
int width)
Perform "sub" filtering on the given row.
|
protected void |
filterUp(byte[] pixels,
int startPos,
int width)
Perform "up" filtering on the given row.
|
static byte[] |
getBytes(java.awt.Image image,
int quality) |
static byte[] |
getBytes(java.awt.Image image,
int quality,
int bgcolor,
java.lang.String type) |
int |
getCompressionLevel()
Retrieve compression level
|
boolean |
getEncodeAlpha()
Retrieve alpha encoding status.
|
int |
getFilter()
Retrieve filtering scheme
|
private static void |
getInt4(int n,
byte[] int4) |
private static java.lang.String |
getJmolTypeText(java.lang.String type,
int nPNG,
int nState) |
byte[] |
pngEncode()
Creates an array of bytes that is the PNG equivalent of the current image.
|
(package private) byte[] |
pngEncode(boolean encodeAlpha)
Creates an array of bytes that is the PNG equivalent of the current image, specifying whether to encode alpha or not.
|
protected byte[] |
resizeByteArray(byte[] array,
int newLength)
Increase or decrease the length of a byte array.
|
void |
setCompressionLevel(int level)
Set the compression level to use
|
void |
setEncodeAlpha(boolean encodeAlpha)
Set the alpha encoding on or off.
|
void |
setFilter(int whichFilter)
Set the filter to use
|
void |
setImage(java.awt.Image image)
Set the image to be encoded
|
static void |
setJmolTypeText(byte[] b,
int nPNG,
int nState,
java.lang.String type)
Fill in the Jmol type text area with number of bytes of PNG data
and number of bytes of Jmol state data and fix checksum.
|
private void |
setTransparentColor(int bgcolor) |
static void |
write(java.awt.Image image,
int quality,
java.io.OutputStream os)
not used in Jmol
|
static int |
write(java.awt.Image image,
int quality,
java.io.OutputStream os,
int bgcolor,
java.lang.String type) |
protected int |
writeByte(int b,
int offset)
Write a single byte into the pngBytes array at a given position.
|
protected int |
writeBytes(byte[] data,
int offset)
Write an array of bytes into the pngBytes array.
|
protected int |
writeBytes(byte[] data,
int nBytes,
int offset)
Write an array of bytes into the pngBytes array, specifying number of bytes to write.
|
protected void |
writeEnd()
Write a PNG "IEND" chunk into the pngBytes array.
|
protected void |
writeHeader()
Write a PNG "IHDR" chunk into the pngBytes array.
|
protected boolean |
writeImageData()
Write the image data into the pngBytes array.
|
protected int |
writeInt2(int n,
int offset)
Write a two-byte integer into the pngBytes array at a given position.
|
protected int |
writeInt4(int n,
int offset)
Write a four-byte integer into the pngBytes array at a given position.
|
protected int |
writeString(java.lang.String s,
int offset)
Write a string into the pngBytes array at a given position.
|
private void |
writeText(java.lang.String msg) |
private void |
writeTransparentColor(int icolor)
Write a PNG "tRNS" chunk into the pngBytes array.
|
public static final boolean ENCODE_ALPHA
public static final boolean NO_ALPHA
public static final int FILTER_NONE
public static final int FILTER_SUB
public static final int FILTER_UP
public static final int FILTER_LAST
protected byte[] pngBytes
protected byte[] priorRow
protected byte[] leftBytes
protected java.awt.Image image
protected int width
protected int height
protected int bytePos
protected int maxPos
protected int hdrPos
protected int dataPos
protected int endPos
protected java.util.zip.CRC32 crc
protected long crcValue
protected boolean encodeAlpha
protected int filter
protected int bytesPerPixel
protected int compressionLevel
private java.lang.String type
private java.lang.Integer transparentColor
private static int ptJmolByteText
byte[] int2
byte[] int4
public PngEncoder()
public PngEncoder(java.awt.Image image)
image
- A Java Image object which uses the DirectColorModelImage
public PngEncoder(java.awt.Image image, boolean encodeAlpha)
image
- A Java Image object which uses the DirectColorModelencodeAlpha
- Encode the alpha channel? false=no; true=yesImage
public PngEncoder(java.awt.Image image, boolean encodeAlpha, int whichFilter)
image
- A Java Image object which uses the DirectColorModelencodeAlpha
- Encode the alpha channel? false=no; true=yeswhichFilter
- 0=none, 1=sub, 2=upImage
public PngEncoder(java.awt.Image image, boolean encodeAlpha, int whichFilter, int compLevel)
image
- A Java Image objectencodeAlpha
- Encode the alpha channel? false=no; true=yeswhichFilter
- 0=none, 1=sub, 2=upcompLevel
- 0..9Image
public static void write(java.awt.Image image, int quality, java.io.OutputStream os) throws java.io.IOException
image
- quality
- os
- java.io.IOException
public static int write(java.awt.Image image, int quality, java.io.OutputStream os, int bgcolor, java.lang.String type) throws java.io.IOException
java.io.IOException
public static byte[] getBytes(java.awt.Image image, int quality)
public static byte[] getBytes(java.awt.Image image, int quality, int bgcolor, java.lang.String type)
private void setTransparentColor(int bgcolor)
public void setImage(java.awt.Image image)
image
- A Java Image object which uses the DirectColorModelImage
,
DirectColorModel
byte[] pngEncode(boolean encodeAlpha)
encodeAlpha
- boolean false=no alpha, true=encode alphaprivate static java.lang.String getJmolTypeText(java.lang.String type, int nPNG, int nState)
public byte[] pngEncode()
public void setEncodeAlpha(boolean encodeAlpha)
encodeAlpha
- false=no, true=yespublic boolean getEncodeAlpha()
public void setFilter(int whichFilter)
whichFilter
- from constant listpublic int getFilter()
public void setCompressionLevel(int level)
level
- 0 through 9public int getCompressionLevel()
protected byte[] resizeByteArray(byte[] array, int newLength)
array
- The original array.newLength
- The length you wish the array to have.protected int writeBytes(byte[] data, int offset)
data
- The data to be written into pngBytes.offset
- The starting point to write to.protected int writeBytes(byte[] data, int nBytes, int offset)
data
- The data to be written into pngBytes.nBytes
- The number of bytes to be written.offset
- The starting point to write to.protected int writeInt2(int n, int offset)
n
- The integer to be written into pngBytes.offset
- The starting point to write to.protected int writeInt4(int n, int offset)
n
- The integer to be written into pngBytes.offset
- The starting point to write to.private static void getInt4(int n, byte[] int4)
protected int writeByte(int b, int offset)
b
- The byte to be written into pngBytes.offset
- The starting point to write to.protected int writeString(java.lang.String s, int offset)
s
- The string to be written into pngBytes.offset
- The starting point to write to.String.getBytes()
protected void writeHeader()
private void writeText(java.lang.String msg)
private void writeTransparentColor(int icolor)
icolor
- protected void filterSub(byte[] pixels, int startPos, int width)
pixels
- The array holding the scan lines being builtstartPos
- Starting position within pixels of bytes to be filtered.width
- Width of a scanline in pixels.protected void filterUp(byte[] pixels, int startPos, int width)
pixels
- The array holding the scan lines being builtstartPos
- Starting position within pixels of bytes to be filtered.width
- Width of a scanline in pixels.protected boolean writeImageData()
protected void writeEnd()
public static void setJmolTypeText(byte[] b, int nPNG, int nState, java.lang.String type)
b
- nPNG
- nState
- type
-