Framework Serveur J2EE ACube V3.1.0
CLASSE PRECEDANTE CLASSE SUIVANTE
SOMMAIRE: ATTR CONSTR METH DETAIL: ATTR CONSTR METH

acube.framework.clavierVirtuel
Classe PngEncoder
java.lang.Object
  acube.framework.clavierVirtuel.PngEncoder

public class PngEncoder
hérite de Object
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

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA A copy of the GNU LGPL may be found at http://www.gnu.org/copyleft/lesser.html

Author:
J. David Eisenberg
Version:
1.5, 19 Oct 2003 CHANGES: -------- 19-Nov-2002 : CODING STYLE CHANGES ONLY (by David Gilbert for Object Refinery Limited); 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

Sommaire des Attributs
private int
bytePos
The byte position.
private int
bytesPerPixel
The bytes-per-pixel.
private int
compressionLevel
The compression level.
private CRC32
crc
CRC.
private long
crcValue
The CRC value.
static final boolean
ENCODE_ALPHA
Constant specifying that alpha channel should be encoded.
private boolean
encodeAlpha
Encode alpha?
private int
filter
The filter type.
static final int
FILTER_LAST
Constants for filter (LAST)
static final int
FILTER_NONE
Constants for filter (NONE)
static final int
FILTER_SUB
Constants for filter (SUB)
static final int
FILTER_UP
Constants for filter (UP)
private int
height
The width.
protected static final byte[]
IDAT
IDAT tag.
protected static final byte[]
IEND
IEND tag.
protected static final byte[]
IHDR
IHDR tag.
private Image
image
The image.
private byte[]
leftBytes
The left bytes.
static final int
MAX_COMPRESS_LEVEL
MAX_COMPRESS_LEVEL the MAX_COMPRESS_LEVEL
private int
maxPos
The byte position.
static final boolean
NO_ALPHA
Constant specifying that alpha channel should not be encoded.
private byte[]
pngBytes
The png bytes.
private byte[]
priorRow
The prior row.
private int
width
The width.
Sommaire des Constructeurs
PngEncoder()
Class constructor
PngEncoder(Image image)
Class constructor specifying Image to encode, with no alpha channel encoding.
PngEncoder(Image image, boolean encodeAlpha)
Class constructor specifying Image to encode, and whether to encode alpha.
PngEncoder(Image image, boolean encodeAlpha, int whichFilter)
Class constructor specifying Image to encode, whether to encode alpha, and filter to use.
PngEncoder(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.
Sommaire des Méthodes
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.
int
getCompressionLevel()
Retrieve compression level
boolean
getEncodeAlpha()
Retrieve alpha encoding status.
int
getFilter()
Retrieve filtering scheme
byte[]
pngEncode()
Creates an array of bytes that is the PNG equivalent of the current image.
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(Image image)
Set the image to be encoded
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.
Méthodes héritées de la classe java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Détail des Attributs
MAX_COMPRESS_LEVEL
public static final int MAX_COMPRESS_LEVEL
MAX_COMPRESS_LEVEL the MAX_COMPRESS_LEVEL

ENCODE_ALPHA
public static final boolean ENCODE_ALPHA
Constant specifying that alpha channel should be encoded.

NO_ALPHA
public static final boolean NO_ALPHA
Constant specifying that alpha channel should not be encoded.

FILTER_NONE
public static final int FILTER_NONE
Constants for filter (NONE)

FILTER_SUB
public static final int FILTER_SUB
Constants for filter (SUB)

FILTER_UP
public static final int FILTER_UP
Constants for filter (UP)

FILTER_LAST
public static final int FILTER_LAST
Constants for filter (LAST)

IHDR
protected static final byte[] IHDR
IHDR tag.

IDAT
protected static final byte[] IDAT
IDAT tag.

IEND
protected static final byte[] IEND
IEND tag.

pngBytes
private byte[] pngBytes
The png bytes.

priorRow
private byte[] priorRow
The prior row.

leftBytes
private byte[] leftBytes
The left bytes.

image
private Image image
The image.

width
private int width
The width.

height
private int height
The width.

bytePos
private int bytePos
The byte position.

maxPos
private int maxPos
The byte position.

crc
private CRC32 crc
CRC.

crcValue
private long crcValue
The CRC value.

encodeAlpha
private boolean encodeAlpha
Encode alpha?

filter
private int filter
The filter type.

bytesPerPixel
private int bytesPerPixel
The bytes-per-pixel.

compressionLevel
private int compressionLevel
The compression level.
Détail des Constructeurs
PngEncoder
public PngEncoder()
Class constructor

PngEncoder
public PngEncoder(Image image)
Class constructor specifying Image to encode, with no alpha channel encoding.
Voir Aussi:
Image

PngEncoder
public PngEncoder(Image image,
                  boolean encodeAlpha)
Class constructor specifying Image to encode, and whether to encode alpha.
Voir Aussi:
Image

PngEncoder
public PngEncoder(Image image,
                  boolean encodeAlpha,
                  int whichFilter)
Class constructor specifying Image to encode, whether to encode alpha, and filter to use.
Voir Aussi:
Image

PngEncoder
public PngEncoder(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.
Voir Aussi:
Image
Détail des méthodes
setImage
public void setImage(Image image)
Set the image to be encoded
Paramètres:
image - A Java Image object which uses the DirectColorModel
Voir Aussi:
Image, DirectColorModel

pngEncode
public 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.
Paramètres:
encodeAlpha - boolean false=no alpha, true=encode alpha
Retours:
an array of bytes, or null if there was a problem

pngEncode
public byte[] pngEncode()
Creates an array of bytes that is the PNG equivalent of the current image. Alpha encoding is determined by its setting in the constructor.
Retours:
an array of bytes, or null if there was a problem

setEncodeAlpha
public void setEncodeAlpha(boolean encodeAlpha)
Set the alpha encoding on or off.
Paramètres:
encodeAlpha - false=no, true=yes

getEncodeAlpha
public boolean getEncodeAlpha()
Retrieve alpha encoding status.
Retours:
boolean false=no, true=yes

setFilter
public void setFilter(int whichFilter)
Set the filter to use
Paramètres:
whichFilter - from constant list

getFilter
public int getFilter()
Retrieve filtering scheme
Retours:
int (see constant list)

setCompressionLevel
public void setCompressionLevel(int level)
Set the compression level to use
Paramètres:
level - 0 through 9

getCompressionLevel
public int getCompressionLevel()
Retrieve compression level
Retours:
int in range 0-9

resizeByteArray
protected byte[] resizeByteArray(byte[] array,
                                 int newLength)
Increase or decrease the length of a byte array.
Paramètres:
array - The original array.
newLength - The length you wish the new array to have.
Retours:
Array of newly desired length. If shorter than the original, the trailing elements are truncated.

writeBytes
protected int writeBytes(byte[] data,
                         int offset)
Write an array of bytes into the pngBytes array. Note: This routine has the side effect of updating maxPos, the largest element written in the array. The array is resized by 1000 bytes or the length of the data to be written, whichever is larger.
Paramètres:
data - The data to be written into pngBytes.
offset - The starting point to write to.
Retours:
The next place to be written to in the pngBytes array.

writeBytes
protected int writeBytes(byte[] data,
                         int nBytes,
                         int offset)
Write an array of bytes into the pngBytes array, specifying number of bytes to write. Note: This routine has the side effect of updating maxPos, the largest element written in the array. The array is resized by 1000 bytes or the length of the data to be written, whichever is larger.
Paramètres:
data - The data to be written into pngBytes.
nBytes - The number of bytes to be written.
offset - The starting point to write to.
Retours:
The next place to be written to in the pngBytes array.

writeInt2
protected int writeInt2(int n,
                        int offset)
Write a two-byte integer into the pngBytes array at a given position.
Paramètres:
n - The integer to be written into pngBytes.
offset - The starting point to write to.
Retours:
The next place to be written to in the pngBytes array.

writeInt4
protected int writeInt4(int n,
                        int offset)
Write a four-byte integer into the pngBytes array at a given position.
Paramètres:
n - The integer to be written into pngBytes.
offset - The starting point to write to.
Retours:
The next place to be written to in the pngBytes array.

writeByte
protected int writeByte(int b,
                        int offset)
Write a single byte into the pngBytes array at a given position.
Paramètres:
b - The integer to be written into pngBytes.
offset - The starting point to write to.
Retours:
The next place to be written to in the pngBytes array.

writeHeader
protected void writeHeader()
Write a PNG "IHDR" chunk into the pngBytes array.

filterSub
protected void filterSub(byte[] pixels,
                         int startPos,
                         int width)
Perform "sub" filtering on the given row. Uses temporary array leftBytes to store the original values of the previous pixels. The array is 16 bytes long, which will easily hold two-byte samples plus two-byte alpha.
Paramètres:
pixels - The array holding the scan lines being built
startPos - Starting position within pixels of bytes to be filtered.
width - Width of a scanline in pixels.

filterUp
protected void filterUp(byte[] pixels,
                        int startPos,
                        int width)
Perform "up" filtering on the given row. Side effect: refills the prior row with current row
Paramètres:
pixels - The array holding the scan lines being built
startPos - Starting position within pixels of bytes to be filtered.
width - Width of a scanline in pixels.

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.
Retours:
true if no errors; false if error grabbing pixels

writeEnd
protected void writeEnd()
Write a PNG "IEND" chunk into the pngBytes array.

Framework Serveur J2EE ACube V3.1.0
CLASSE PRECEDANTE CLASSE SUIVANTE
SOMMAIRE: ATTR CONSTR METH DETAIL: ATTR CONSTR METH

Version 3.1.0 du 06/11/2009 / Etat : Validé
Cette création est mise à disposition selon le Contrat Paternité - Pas d'Utilisation Commerciale - Partage des Conditions Initiales à l'Identique disponible en ligne http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ ou par courrier postal à Creative Commons, 559 Nathan Abbott Way, Stanford,California 94305, USA.
Documentation generated by DocFlex