If this is for any reason not possible, the factory will return null. You must then encode the image by loading it and using the LosslessFactory.
The W3C PNG spec was used to implement this class: https://www.w3.org/TR/2003/REC-PNG-20031110
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | PNGConverter.
Holds the information about a chunks |
| private static class | |
| pack-priv static class | PNGConverter.
Holds all relevant chunks of the PNG |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int[] | |
| private static final Log |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static COSDictionary | |
| private static PDImageXObject | buildImageObject(PDDocument document, PNGConverter.
Build the base image object from the IDATs and profile information |
| private static PDImageXObject | |
| private static PDImageXObject | buildTransparencyMaskFromIndexedData(PDDocument doc, PDImageXObject image, PNGConverter.
|
| pack-priv static boolean | checkChunkSane(PNGConverter.
Check if the chunk is sane, i.e. CRC matches and offsets and lengths in the byte array |
| pack-priv static boolean | Returns: true if the state seems plausiblethe parsed converter state stateCheck if the converter state is sane. |
| private static PDImageXObject | Returns: null or the converted imagethe document to put the image in doc, PNGConverter.the parser state containing the PNG chunks. stateConvert the image using the state. |
| pack-priv static PDImageXObject | Returns: null or the PDImageXObject built from the pngthe document to put the image in doc, byte[] the byte data of the PNG imageData)Try to convert a PNG into a PDImageXObject. |
| pack-priv static int | |
| private static COSStream | createCOSStreamwithIccProfile(PDDocument document, PDColorSpace colorSpace, PNGConverter.
|
| private static InputStream | Returns: a input stream with the IDAT data.the converter state. stateBuild an input stream for the IDAT data. |
| private static void | |
| pack-priv static COSName | Returns: the matching PDF Render Intent or nullthe PNG render intent renderIntent)Map the renderIntent int to a PDF render intent. |
| private static PNGConverter. | Returns: null or the converter state with all relevant chunksthe byte array with the PNG data imageData)Parse the PNG structure into the PNGConverterState. |
| private static int | |
| private static float | |
| private static void | setupIndexedColorSpace(PDDocument doc, PNGConverter.
|
| private static int |
| CHUNK_CHRM | back to summary |
|---|---|
| private static final int CHUNK_CHRM | |
| CHUNK_GAMA | back to summary |
|---|---|
| private static final int CHUNK_GAMA | |
| CHUNK_HIST | back to summary |
|---|---|
| private static final int CHUNK_HIST | |
| CHUNK_ICCP | back to summary |
|---|---|
| private static final int CHUNK_ICCP | |
| CHUNK_IDAT | back to summary |
|---|---|
| private static final int CHUNK_IDAT | |
| CHUNK_IEND | back to summary |
|---|---|
| private static final int CHUNK_IEND | |
| CHUNK_IHDR | back to summary |
|---|---|
| private static final int CHUNK_IHDR | |
| CHUNK_ITXT | back to summary |
|---|---|
| private static final int CHUNK_ITXT | |
| CHUNK_KBKG | back to summary |
|---|---|
| private static final int CHUNK_KBKG | |
| CHUNK_PHYS | back to summary |
|---|---|
| private static final int CHUNK_PHYS | |
| CHUNK_PLTE | back to summary |
|---|---|
| private static final int CHUNK_PLTE | |
| CHUNK_SBIT | back to summary |
|---|---|
| private static final int CHUNK_SBIT | |
| CHUNK_SPLT | back to summary |
|---|---|
| private static final int CHUNK_SPLT | |
| CHUNK_SRGB | back to summary |
|---|---|
| private static final int CHUNK_SRGB | |
| CHUNK_TEXT | back to summary |
|---|---|
| private static final int CHUNK_TEXT | |
| CHUNK_TIME | back to summary |
|---|---|
| private static final int CHUNK_TIME | |
| CHUNK_TRNS | back to summary |
|---|---|
| private static final int CHUNK_TRNS | |
| CHUNK_ZTXT | back to summary |
|---|---|
| private static final int CHUNK_ZTXT | |
| CRC_TABLE | back to summary |
|---|---|
| private static final int[] CRC_TABLE | |
| LOG | back to summary |
|---|---|
| private static final Log LOG | |
| PNGConverter | back to summary |
|---|---|
| private PNGConverter() | |
| buildDecodeParams | back to summary |
|---|---|
| private static COSDictionary buildDecodeParams(PNGConverter. | |
| buildImageObject | back to summary |
|---|---|
| private static PDImageXObject buildImageObject(PDDocument document, PNGConverter. Build the base image object from the IDATs and profile information | |
| buildIndexImage | back to summary |
|---|---|
| private static PDImageXObject buildIndexImage(PDDocument doc, PNGConverter. Build a indexed image | |
| buildTransparencyMaskFromIndexedData | back to summary |
|---|---|
| private static PDImageXObject buildTransparencyMaskFromIndexedData(PDDocument doc, PDImageXObject image, PNGConverter. | |
| checkChunkSane | back to summary |
|---|---|
| pack-priv static boolean checkChunkSane(PNGConverter. Check if the chunk is sane, i.e. CRC matches and offsets and lengths in the byte array | |
| checkConverterState | back to summary |
|---|---|
| pack-priv static boolean checkConverterState(PNGConverter. Check if the converter state is sane.
| |
| convertPng | back to summary |
|---|---|
| private static PDImageXObject convertPng(PDDocument doc, PNGConverter. Convert the image using the state.
| |
| convertPNGImage | back to summary |
|---|---|
| pack-priv static PDImageXObject convertPNGImage(PDDocument doc, byte[] imageData) throws IOException Try to convert a PNG into a PDImageXObject. If for any reason the PNG can not be converted, null is returned. This usually means the PNG structure is damaged (CRC error, etc.) or it uses some features which can not be mapped to PDF.
| |
| crc | back to summary |
|---|---|
| pack-priv static int crc(byte[] buf, int offset, int len) | |
| createCOSStreamwithIccProfile | back to summary |
|---|---|
| private static COSStream createCOSStreamwithIccProfile(PDDocument document, PDColorSpace colorSpace, PNGConverter. | |
| getIDATInputStream | back to summary |
|---|---|
| private static InputStream getIDATInputStream(PNGConverter. Build an input stream for the IDAT data. May need to concat multiple IDAT chunks.
| |
| makeCrcTable | back to summary |
|---|---|
| private static void makeCrcTable() | |
| mapPNGRenderIntent | back to summary |
|---|---|
| pack-priv static COSName mapPNGRenderIntent(int renderIntent) Map the renderIntent int to a PDF render intent. See also https://www.w3.org/TR/2003/REC-PNG-20031110/#11sRGB
| |
| parsePNGChunks | back to summary |
|---|---|
| private static PNGConverter. Parse the PNG structure into the PNGConverterState. If we can't handle something, this method will return null.
| |
| readInt | back to summary |
|---|---|
| private static int readInt(byte[] data, int offset) | |
| readPNGFloat | back to summary |
|---|---|
| private static float readPNGFloat(byte[] bytes, int offset) | |
| setupIndexedColorSpace | back to summary |
|---|---|
| private static void setupIndexedColorSpace(PDDocument doc, PNGConverter. | |
| updateCrc | back to summary |
|---|---|
| private static int updateCrc(byte[] buf, int offset, int len) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv byte[] | bytes
This field holds the whole byte array; In that it's redundant, as all chunks will have the same byte array. |
| pack-priv int | chunkType
The chunk type, see the CHUNK_??? |
| pack-priv int | crc
The crc of the chunk data, as stored in the PNG stream. |
| pack-priv int | length
The length of the data within the byte array. |
| pack-priv int | start
The start index of the chunk data within bytes. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv byte[] | Returns: a byte-array with only the data of the chunkGet the data of this chunk as a byte array |
| bytes | back to summary |
|---|---|
| pack-priv byte[] bytes This field holds the whole byte array; In that it's redundant, as all chunks will have the same byte array. But have this byte array per chunk makes it easier to validate and pass around. And we won't have that many chunks, so those 8 bytes for the pointer (on 64-bit systems) don't matter. | |
| chunkType | back to summary |
|---|---|
| pack-priv int chunkType The chunk type, see the CHUNK_??? constants. | |
| crc | back to summary |
|---|---|
| pack-priv int crc The crc of the chunk data, as stored in the PNG stream. | |
| length | back to summary |
|---|---|
| pack-priv int length The length of the data within the byte array. | |
| start | back to summary |
|---|---|
| pack-priv int start The start index of the chunk data within bytes. | |
| Chunk | back to summary |
|---|---|
| pack-priv Chunk() | |
| getData | back to summary |
|---|---|
| pack-priv byte[] getData() Get the data of this chunk as a byte array
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv InputStream | |
| pack-priv int | |
| pack-priv final List |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. |
| private boolean | |
| public int | read()
Implements abstract java. Reads the next byte of data from the input stream. |
| public int | read(byte[]
the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
| currentStream | back to summary |
|---|---|
| pack-priv InputStream currentStream | |
| currentStreamIdx | back to summary |
|---|---|
| pack-priv int currentStreamIdx | |
| inputStreams | back to summary |
|---|---|
| pack-priv final List<InputStream> inputStreams | |
| MultipleInputStream | back to summary |
|---|---|
| private MultipleInputStream() | |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of A subclass's implementation of this method may choose to throw an
| |
| ensureStream | back to summary |
|---|---|
| private boolean ensureStream() | |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| pack-priv PNGConverter. | |
| pack-priv PNGConverter. | |
| pack-priv int | |
| pack-priv PNGConverter. | |
| pack-priv List | |
| pack-priv PNGConverter. | |
| pack-priv PNGConverter. | |
| pack-priv PNGConverter. | |
| pack-priv PNGConverter. | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| bitsPerComponent | back to summary |
|---|---|
| pack-priv int bitsPerComponent | |
| cHRM | back to summary |
|---|---|
| pack-priv PNGConverter. | |
| gAMA | back to summary |
|---|---|
| pack-priv PNGConverter. | |
| height | back to summary |
|---|---|
| pack-priv int height | |
| iCCP | back to summary |
|---|---|
| pack-priv PNGConverter. | |
| IDATs | back to summary |
|---|---|
| pack-priv List<PNGConverter. | |
| IHDR | back to summary |
|---|---|
pack-priv PNGConverter.
| |
| PLTE | back to summary |
|---|---|
pack-priv PNGConverter.
| |
| sRGB | back to summary |
|---|---|
| pack-priv PNGConverter. | |
| tRNS | back to summary |
|---|---|
| pack-priv PNGConverter. | |
| width | back to summary |
|---|---|
| pack-priv int width | |
| PNGConverterState | back to summary |
|---|---|
| pack-priv PNGConverterState() | |