Package bdsup2sub.tools
Class EnhancedPngEncoder
java.lang.Object
bdsup2sub.tools.PngEncoder
bdsup2sub.tools.EnhancedPngEncoder
- Version:
- 1.5, 19 Oct 2003 (modified by 0xdeadbeef in 2009 and mjuhasz in 2012)
CHANGES:
--------
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
Added modifications for unsigned short images
(contributed by Christian at xpogen.com)
10-Nov-2012 : Removed unused constants and useless method override. (mjuhasz)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BufferedImage
private static final byte[]
PLTE tag.private static final byte[]
tRNS tag.private int
private WritableRaster
Fields inherited from class bdsup2sub.tools.PngEncoder
bytePos, bytesPerPixel, compressionLevel, crc, crcValue, encodeAlpha, filter, FILTER_LAST, FILTER_NONE, FILTER_SUB, FILTER_UP, height, IDAT, IEND, IHDR, leftBytes, maxPos, pngBytes, priorRow, width
-
Constructor Summary
ConstructorsModifierConstructorDescriptionEnhancedPngEncoder
(BufferedImage image) Class constructor specifying BufferedImage to encode, with no alpha channel encoding.EnhancedPngEncoder
(BufferedImage image, boolean encodeAlpha) Class constructor specifying BufferedImage to encode, and whether to encode alpha.EnhancedPngEncoder
(BufferedImage image, boolean encodeAlpha, int whichFilter) Class constructor specifying BufferedImage to encode, whether to encode alpha, and filter to use.private
EnhancedPngEncoder
(BufferedImage image, boolean encodeAlpha, int whichFilter, int compLevel) Class constructor specifying BufferedImage source to encode, whether to encode alpha, filter to use, and compression level. -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
Get and set variables that determine how picture is stored.byte[]
Creates an array of bytes that is the PNG equivalent of the current image.void
setImage
(BufferedImage image) Set the BufferedImage to be encoded.(package private) void
protected void
Write a PNG "IHDR" chunk into the pngBytes array.protected boolean
Write the image data into the pngBytes array.(package private) void
Methods inherited from class bdsup2sub.tools.PngEncoder
filterSub, filterUp, getCompressionLevel, getEncodeAlpha, getFilter, resizeByteArray, setCompressionLevel, setEncodeAlpha, setFilter, setImage, writeByte, writeBytes, writeBytes, writeEnd, writeInt2, writeInt4
-
Field Details
-
PLTE
private static final byte[] PLTEPLTE tag. -
TRNS
private static final byte[] TRNStRNS tag. -
image
-
wRaster
-
tType
private int tType
-
-
Constructor Details
-
EnhancedPngEncoder
public EnhancedPngEncoder() -
EnhancedPngEncoder
Class constructor specifying BufferedImage to encode, with no alpha channel encoding.- Parameters:
image
- A Java BufferedImage object
-
EnhancedPngEncoder
Class constructor specifying BufferedImage to encode, and whether to encode alpha.- Parameters:
image
- A Java BufferedImage objectencodeAlpha
- Encode the alpha channel? false=no; true=yes
-
EnhancedPngEncoder
Class constructor specifying BufferedImage to encode, whether to encode alpha, and filter to use.- Parameters:
image
- A Java BufferedImage objectencodeAlpha
- Encode the alpha channel? false=no; true=yeswhichFilter
- 0=none, 1=sub, 2=up
-
EnhancedPngEncoder
private EnhancedPngEncoder(BufferedImage image, boolean encodeAlpha, int whichFilter, int compLevel) Class constructor specifying BufferedImage source to encode, whether to encode alpha, filter to use, and compression level.- Parameters:
image
- A Java BufferedImage objectencodeAlpha
- Encode the alpha channel? false=no; true=yeswhichFilter
- 0=none, 1=sub, 2=upcompLevel
- 0..9
-
-
Method Details
-
setImage
Set the BufferedImage to be encoded.- Parameters:
image
- A Java BufferedImage object
-
pngEncode
public byte[] pngEncode()Creates an array of bytes that is the PNG equivalent of the current image.- Overrides:
pngEncode
in classPngEncoder
- Returns:
- an array of bytes, or null if there was a problem
-
establishStorageInfo
boolean establishStorageInfo()Get and set variables that determine how picture is stored. Retrieves the writable raster of the buffered image, as well its transfer type. Sets number of output bytes per pixel, and, if only eight-bit bytes, turns off alpha encoding.- Returns:
- true if 1-byte or 4-byte data, false otherwise
-
writeHeader
protected void writeHeader()Write a PNG "IHDR" chunk into the pngBytes array.- Overrides:
writeHeader
in classPngEncoder
-
writePalette
-
writeAlpha
-
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.- Overrides:
writeImageData
in classPngEncoder
- Returns:
- true if no errors; false if error grabbing pixels
-