Class PNGImageEncoder
- java.lang.Object
-
- org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
-
- org.apache.xmlgraphics.image.codec.png.PNGImageEncoder
-
- All Implemented Interfaces:
ImageEncoder
public class PNGImageEncoder extends ImageEncoderImpl
An ImageEncoder for the PNG file format.- Since:
- EA4
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
alphaPalette
private int
bitDepth
private int
bitShift
private byte[]
bluePalette
private int
bpp
private int
colorType
private boolean
compressGray
private byte[]
currRow
private java.io.DataOutputStream
dataOutput
private byte[][]
filteredRows
private byte[]
greenPalette
private int
height
private java.awt.image.RenderedImage
image
private boolean
interlace
private static byte[]
MAGIC
private int
numBands
private PNGEncodeParam
param
private static int
PNG_COLOR_GRAY
private static int
PNG_COLOR_GRAY_ALPHA
private static int
PNG_COLOR_PALETTE
private static int
PNG_COLOR_RGB
private static int
PNG_COLOR_RGB_ALPHA
private byte[]
prevRow
private byte[]
redPalette
private boolean
skipAlpha
private static float[]
SRGB_CHROMA
private int
width
-
Fields inherited from class org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
output
-
-
Constructor Summary
Constructors Constructor Description PNGImageEncoder(java.io.OutputStream output, PNGEncodeParam param)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
clamp(int val, int maxValue)
private PNGEncodeParam.Gray
createGrayParam(byte[] redPalette, byte[] greenPalette, byte[] bluePalette, byte[] alphaPalette)
Analyzes a set of palettes and determines if it can be expressed as a standard set of gray values, with zero or one values being fully transparent and the rest being fully opaque.void
encode(java.awt.image.RenderedImage im)
This method encodes aRenderedImage
into PNG.private void
encodePass(java.io.OutputStream os, java.awt.image.Raster ras, int xOffset, int yOffset, int xSkip, int ySkip)
private void
writeBKGD()
private void
writeCHRM()
private void
writeGAMA()
private void
writeHIST()
private void
writeICCP()
private void
writeIDAT()
private void
writeIEND()
private void
writeIHDR()
private void
writeMagic()
private void
writePHYS()
private void
writePLTE()
private void
writePrivateChunks()
private void
writeSBIT()
private void
writeSPLT()
private void
writeSRGB()
private void
writeTEXT()
private void
writeTIME()
private void
writeTRNS()
private void
writeZTXT()
-
Methods inherited from class org.apache.xmlgraphics.image.codec.util.ImageEncoderImpl
encode, getOutputStream, getParam, setParam
-
-
-
-
Field Detail
-
PNG_COLOR_GRAY
private static final int PNG_COLOR_GRAY
- See Also:
- Constant Field Values
-
PNG_COLOR_RGB
private static final int PNG_COLOR_RGB
- See Also:
- Constant Field Values
-
PNG_COLOR_PALETTE
private static final int PNG_COLOR_PALETTE
- See Also:
- Constant Field Values
-
PNG_COLOR_GRAY_ALPHA
private static final int PNG_COLOR_GRAY_ALPHA
- See Also:
- Constant Field Values
-
PNG_COLOR_RGB_ALPHA
private static final int PNG_COLOR_RGB_ALPHA
- See Also:
- Constant Field Values
-
MAGIC
private static final byte[] MAGIC
-
param
private PNGEncodeParam param
-
image
private java.awt.image.RenderedImage image
-
width
private int width
-
height
private int height
-
bitDepth
private int bitDepth
-
bitShift
private int bitShift
-
numBands
private int numBands
-
colorType
private int colorType
-
bpp
private int bpp
-
skipAlpha
private boolean skipAlpha
-
compressGray
private boolean compressGray
-
interlace
private boolean interlace
-
redPalette
private byte[] redPalette
-
greenPalette
private byte[] greenPalette
-
bluePalette
private byte[] bluePalette
-
alphaPalette
private byte[] alphaPalette
-
dataOutput
private java.io.DataOutputStream dataOutput
-
prevRow
private byte[] prevRow
-
currRow
private byte[] currRow
-
filteredRows
private byte[][] filteredRows
-
SRGB_CHROMA
private static final float[] SRGB_CHROMA
-
-
Constructor Detail
-
PNGImageEncoder
public PNGImageEncoder(java.io.OutputStream output, PNGEncodeParam param)
-
-
Method Detail
-
writeMagic
private void writeMagic() throws java.io.IOException
- Throws:
java.io.IOException
-
writeIHDR
private void writeIHDR() throws java.io.IOException
- Throws:
java.io.IOException
-
clamp
private static int clamp(int val, int maxValue)
-
encodePass
private void encodePass(java.io.OutputStream os, java.awt.image.Raster ras, int xOffset, int yOffset, int xSkip, int ySkip) throws java.io.IOException
- Throws:
java.io.IOException
-
writeIDAT
private void writeIDAT() throws java.io.IOException
- Throws:
java.io.IOException
-
writeIEND
private void writeIEND() throws java.io.IOException
- Throws:
java.io.IOException
-
writeCHRM
private void writeCHRM() throws java.io.IOException
- Throws:
java.io.IOException
-
writeGAMA
private void writeGAMA() throws java.io.IOException
- Throws:
java.io.IOException
-
writeICCP
private void writeICCP() throws java.io.IOException
- Throws:
java.io.IOException
-
writeSBIT
private void writeSBIT() throws java.io.IOException
- Throws:
java.io.IOException
-
writeSRGB
private void writeSRGB() throws java.io.IOException
- Throws:
java.io.IOException
-
writePLTE
private void writePLTE() throws java.io.IOException
- Throws:
java.io.IOException
-
writeBKGD
private void writeBKGD() throws java.io.IOException
- Throws:
java.io.IOException
-
writeHIST
private void writeHIST() throws java.io.IOException
- Throws:
java.io.IOException
-
writeTRNS
private void writeTRNS() throws java.io.IOException
- Throws:
java.io.IOException
-
writePHYS
private void writePHYS() throws java.io.IOException
- Throws:
java.io.IOException
-
writeSPLT
private void writeSPLT() throws java.io.IOException
- Throws:
java.io.IOException
-
writeTIME
private void writeTIME() throws java.io.IOException
- Throws:
java.io.IOException
-
writeTEXT
private void writeTEXT() throws java.io.IOException
- Throws:
java.io.IOException
-
writeZTXT
private void writeZTXT() throws java.io.IOException
- Throws:
java.io.IOException
-
writePrivateChunks
private void writePrivateChunks() throws java.io.IOException
- Throws:
java.io.IOException
-
createGrayParam
private PNGEncodeParam.Gray createGrayParam(byte[] redPalette, byte[] greenPalette, byte[] bluePalette, byte[] alphaPalette)
Analyzes a set of palettes and determines if it can be expressed as a standard set of gray values, with zero or one values being fully transparent and the rest being fully opaque. If it is possible to express the data thusly, the method returns a suitable instance of PNGEncodeParam.Gray; otherwise it returns null.
-
encode
public void encode(java.awt.image.RenderedImage im) throws java.io.IOException
This method encodes aRenderedImage
into PNG. The stream into which the PNG is dumped is not closed at the end of the operation, this should be done if needed by the caller of this method.- Specified by:
encode
in interfaceImageEncoder
- Specified by:
encode
in classImageEncoderImpl
- Throws:
java.io.IOException
-
-