Package com.aowagie.text.pdf.codec
Class PngImage
- java.lang.Object
-
- com.aowagie.text.pdf.codec.PngImage
-
public class PngImage extends java.lang.ObjectReads a PNG image. All types of PNG can be read.It is based in part in the JAI codec.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPngImage.NewByteArrayOutputStream
-
Field Summary
Fields Modifier and Type Field Description private PdfDictionaryadditionalprivate intbitDepthprivate intbytesPerPixelprivate static java.lang.StringcHRMA PNG marker.private byte[]colorTableprivate intcolorTypeprivate intcompressionMethodprivate java.io.DataInputStreamdataStreamprivate intdpiXprivate intdpiYprivate intfilterMethodprivate static java.lang.StringgAMAA PNG marker.private floatgammaprivate booleangenBWMaskprivate booleanhasCHRMprivate intheightprivate java.awt.color.ICC_Profileicc_profileprivate static java.lang.StringiCCPA PNG marker.private PngImage.NewByteArrayOutputStreamidatprivate static java.lang.StringIDATA PNG marker.private static java.lang.StringIENDA PNG marker.private static java.lang.StringIHDRA PNG marker.private byte[]imageprivate intinputBandsprivate PdfNameintentprivate static PdfName[]intentsprivate intinterlaceMethodprivate java.io.InputStreamisprivate booleanpalShadesprivate static java.lang.StringpHYsA PNG marker.private static java.lang.StringPLTEA PNG marker.private static intPNG_FILTER_AVERAGEprivate static intPNG_FILTER_NONEprivate static intPNG_FILTER_PAETHprivate static intPNG_FILTER_SUBprivate static intPNG_FILTER_UPstatic int[]PNGIDSome PNG specific values.private byte[]smaskprivate static java.lang.StringsRGBA PNG marker.private byte[]transprivate inttransBlueprivate static intTRANSFERSIZEprivate inttransGreenprivate inttransRedGrayprivate static java.lang.StringtRNSA PNG marker.private intwidthprivate floatxBprivate floatxGprivate floatxRprivate floatxWprivate floatXYRatioprivate floatyBprivate floatyGprivate floatyRprivate floatyW
-
Constructor Summary
Constructors Modifier Constructor Description privatePngImage(java.io.InputStream is)Creates a new instance of PngImage
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancheckMarker(java.lang.String s)private static voiddecodeAverageFilter(byte[] curr, byte[] prev, int count, int bpp)private voiddecodeIdat()private static voiddecodePaethFilter(byte[] curr, byte[] prev, int count, int bpp)private voiddecodePass(int xOffset, int yOffset, int xStep, int yStep, int passWidth, int passHeight)private static voiddecodeSubFilter(byte[] curr, int count, int bpp)private static voiddecodeUpFilter(byte[] curr, byte[] prev, int count)private PdfObjectgetColorspace()private ImagegetImage()static ImagegetImage(byte[] data)Reads a PNG from a byte array.private static ImagegetImage(java.io.InputStream is)Reads a PNG from a stream.static ImagegetImage(java.net.URL url)Reads a PNG from an url.private static intgetInt(java.io.InputStream is)Gets anintfrom anInputStream.private int[]getPixel(byte[] curr)private static java.lang.StringgetString(java.io.InputStream is)Gets aStringfrom anInputStream.private static intgetWord(java.io.InputStream is)Gets awordfrom anInputStream.private static intpaethPredictor(int a, int b, int c)private voidprocessPixels(byte[] curr, int xOffset, int step, int y, int width)private voidreadPng()private static voidsetPixel(byte[] image, int[] data, int offset, int size, int x, int y, int bitDepth, int bytesPerRow)
-
-
-
Field Detail
-
PNGID
public static final int[] PNGID
Some PNG specific values.
-
IHDR
private static final java.lang.String IHDR
A PNG marker.- See Also:
- Constant Field Values
-
PLTE
private static final java.lang.String PLTE
A PNG marker.- See Also:
- Constant Field Values
-
IDAT
private static final java.lang.String IDAT
A PNG marker.- See Also:
- Constant Field Values
-
IEND
private static final java.lang.String IEND
A PNG marker.- See Also:
- Constant Field Values
-
tRNS
private static final java.lang.String tRNS
A PNG marker.- See Also:
- Constant Field Values
-
pHYs
private static final java.lang.String pHYs
A PNG marker.- See Also:
- Constant Field Values
-
gAMA
private static final java.lang.String gAMA
A PNG marker.- See Also:
- Constant Field Values
-
cHRM
private static final java.lang.String cHRM
A PNG marker.- See Also:
- Constant Field Values
-
sRGB
private static final java.lang.String sRGB
A PNG marker.- See Also:
- Constant Field Values
-
iCCP
private static final java.lang.String iCCP
A PNG marker.- See Also:
- Constant Field Values
-
TRANSFERSIZE
private static final int TRANSFERSIZE
- See Also:
- Constant Field Values
-
PNG_FILTER_NONE
private static final int PNG_FILTER_NONE
- See Also:
- Constant Field Values
-
PNG_FILTER_SUB
private static final int PNG_FILTER_SUB
- See Also:
- Constant Field Values
-
PNG_FILTER_UP
private static final int PNG_FILTER_UP
- See Also:
- Constant Field Values
-
PNG_FILTER_AVERAGE
private static final int PNG_FILTER_AVERAGE
- See Also:
- Constant Field Values
-
PNG_FILTER_PAETH
private static final int PNG_FILTER_PAETH
- See Also:
- Constant Field Values
-
intents
private static final PdfName[] intents
-
is
private final java.io.InputStream is
-
dataStream
private java.io.DataInputStream dataStream
-
width
private int width
-
height
private int height
-
bitDepth
private int bitDepth
-
colorType
private int colorType
-
compressionMethod
private int compressionMethod
-
filterMethod
private int filterMethod
-
interlaceMethod
private int interlaceMethod
-
additional
private final PdfDictionary additional
-
image
private byte[] image
-
smask
private byte[] smask
-
trans
private byte[] trans
-
idat
private final PngImage.NewByteArrayOutputStream idat
-
dpiX
private int dpiX
-
dpiY
private int dpiY
-
XYRatio
private float XYRatio
-
genBWMask
private boolean genBWMask
-
palShades
private boolean palShades
-
transRedGray
private int transRedGray
-
transGreen
private int transGreen
-
transBlue
private int transBlue
-
inputBands
private int inputBands
-
bytesPerPixel
private int bytesPerPixel
-
colorTable
private byte[] colorTable
-
gamma
private float gamma
-
hasCHRM
private boolean hasCHRM
-
xW
private float xW
-
yW
private float yW
-
xR
private float xR
-
yR
private float yR
-
xG
private float xG
-
yG
private float yG
-
xB
private float xB
-
yB
private float yB
-
intent
private PdfName intent
-
icc_profile
private java.awt.color.ICC_Profile icc_profile
-
-
Method Detail
-
getImage
public static Image getImage(java.net.URL url) throws java.io.IOException
Reads a PNG from an url.- Parameters:
url- the url- Returns:
- the image
- Throws:
java.io.IOException- on error
-
getImage
private static Image getImage(java.io.InputStream is) throws java.io.IOException
Reads a PNG from a stream.- Parameters:
is- the stream- Returns:
- the image
- Throws:
java.io.IOException- on error
-
getImage
public static Image getImage(byte[] data) throws java.io.IOException
Reads a PNG from a byte array.- Parameters:
data- the byte array- Returns:
- the image
- Throws:
java.io.IOException- on error
-
checkMarker
private boolean checkMarker(java.lang.String s)
-
readPng
private void readPng() throws java.io.IOException- Throws:
java.io.IOException
-
getColorspace
private PdfObject getColorspace()
-
getImage
private Image getImage() throws java.io.IOException
- Throws:
java.io.IOException
-
decodeIdat
private void decodeIdat()
-
decodePass
private void decodePass(int xOffset, int yOffset, int xStep, int yStep, int passWidth, int passHeight)
-
processPixels
private void processPixels(byte[] curr, int xOffset, int step, int y, int width)
-
setPixel
private static void setPixel(byte[] image, int[] data, int offset, int size, int x, int y, int bitDepth, int bytesPerRow)
-
getPixel
private int[] getPixel(byte[] curr)
-
decodeSubFilter
private static void decodeSubFilter(byte[] curr, int count, int bpp)
-
decodeUpFilter
private static void decodeUpFilter(byte[] curr, byte[] prev, int count)
-
decodeAverageFilter
private static void decodeAverageFilter(byte[] curr, byte[] prev, int count, int bpp)
-
paethPredictor
private static int paethPredictor(int a, int b, int c)
-
decodePaethFilter
private static void decodePaethFilter(byte[] curr, byte[] prev, int count, int bpp)
-
getInt
private static final int getInt(java.io.InputStream is) throws java.io.IOExceptionGets anintfrom anInputStream.- Parameters:
is- anInputStream- Returns:
- the value of an
int - Throws:
java.io.IOException
-
getWord
private static final int getWord(java.io.InputStream is) throws java.io.IOExceptionGets awordfrom anInputStream.- Parameters:
is- anInputStream- Returns:
- the value of an
int - Throws:
java.io.IOException
-
getString
private static final java.lang.String getString(java.io.InputStream is) throws java.io.IOExceptionGets aStringfrom anInputStream.- Parameters:
is- anInputStream- Returns:
- the value of an
int - Throws:
java.io.IOException
-
-