final class PNGConverter
extends java.lang.Object
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 |
---|---|
(package private) static class |
PNGConverter.Chunk
Holds the information about a chunks
|
private static class |
PNGConverter.MultipleInputStream |
(package private) static class |
PNGConverter.PNGConverterState
Holds all relevant chunks of the PNG
|
Modifier and Type | Field and Description |
---|---|
private static int |
CHUNK_CHRM |
private static int |
CHUNK_GAMA |
private static int |
CHUNK_HIST |
private static int |
CHUNK_ICCP |
private static int |
CHUNK_IDAT |
private static int |
CHUNK_IEND |
private static int |
CHUNK_IHDR |
private static int |
CHUNK_ITXT |
private static int |
CHUNK_KBKG |
private static int |
CHUNK_PHYS |
private static int |
CHUNK_PLTE |
private static int |
CHUNK_SBIT |
private static int |
CHUNK_SPLT |
private static int |
CHUNK_SRGB |
private static int |
CHUNK_TEXT |
private static int |
CHUNK_TIME |
private static int |
CHUNK_TRNS |
private static int |
CHUNK_ZTXT |
private static int[] |
CRC_TABLE |
private static org.apache.commons.logging.Log |
LOG |
Modifier | Constructor and Description |
---|---|
private |
PNGConverter() |
Modifier and Type | Method and Description |
---|---|
private static COSDictionary |
buildDecodeParams(PNGConverter.PNGConverterState state,
PDColorSpace colorSpace) |
private static PDImageXObject |
buildImageObject(PDDocument document,
PNGConverter.PNGConverterState state)
Build the base image object from the IDATs and profile information
|
private static PDImageXObject |
buildIndexImage(PDDocument doc,
PNGConverter.PNGConverterState state)
Build a indexed image
|
private static PDImageXObject |
buildTransparencyMaskFromIndexedData(PDDocument doc,
PDImageXObject image,
PNGConverter.PNGConverterState state) |
(package private) static boolean |
checkChunkSane(PNGConverter.Chunk chunk)
Check if the chunk is sane, i.e.
|
(package private) static boolean |
checkConverterState(PNGConverter.PNGConverterState state)
Check if the converter state is sane.
|
private static PDImageXObject |
convertPng(PDDocument doc,
PNGConverter.PNGConverterState state)
Convert the image using the state.
|
(package private) static PDImageXObject |
convertPNGImage(PDDocument doc,
byte[] imageData)
Try to convert a PNG into a PDImageXObject.
|
(package private) static int |
crc(byte[] buf,
int offset,
int len) |
private static java.io.InputStream |
getIDATInputStream(PNGConverter.PNGConverterState state)
Build an input stream for the IDAT data.
|
private static void |
makeCrcTable() |
(package private) static COSName |
mapPNGRenderIntent(int renderIntent)
Map the renderIntent int to a PDF render intent.
|
private static PNGConverter.PNGConverterState |
parsePNGChunks(byte[] imageData)
Parse the PNG structure into the PNGConverterState.
|
private static int |
readInt(byte[] data,
int offset) |
private static float |
readPNGFloat(byte[] bytes,
int offset) |
private static void |
setupIndexedColorSpace(PDDocument doc,
PNGConverter.Chunk lookupTable,
PDImageXObject image,
int highVal) |
private static int |
updateCrc(byte[] buf,
int offset,
int len) |
private static final org.apache.commons.logging.Log LOG
private static final int CHUNK_IHDR
private static final int CHUNK_IDAT
private static final int CHUNK_PLTE
private static final int CHUNK_IEND
private static final int CHUNK_TRNS
private static final int CHUNK_CHRM
private static final int CHUNK_GAMA
private static final int CHUNK_ICCP
private static final int CHUNK_SBIT
private static final int CHUNK_SRGB
private static final int CHUNK_TEXT
private static final int CHUNK_ZTXT
private static final int CHUNK_ITXT
private static final int CHUNK_KBKG
private static final int CHUNK_HIST
private static final int CHUNK_PHYS
private static final int CHUNK_SPLT
private static final int CHUNK_TIME
private static final int[] CRC_TABLE
static PDImageXObject convertPNGImage(PDDocument doc, byte[] imageData) throws java.io.IOException
This usually means the PNG structure is damaged (CRC error, etc.) or it uses some features which can not be mapped to PDF.
doc
- the document to put the image inimageData
- the byte data of the PNGjava.io.IOException
private static PDImageXObject convertPng(PDDocument doc, PNGConverter.PNGConverterState state) throws java.io.IOException
doc
- the document to put the image instate
- the parser state containing the PNG chunks.java.io.IOException
private static PDImageXObject buildIndexImage(PDDocument doc, PNGConverter.PNGConverterState state) throws java.io.IOException
java.io.IOException
private static PDImageXObject buildTransparencyMaskFromIndexedData(PDDocument doc, PDImageXObject image, PNGConverter.PNGConverterState state) throws java.io.IOException
java.io.IOException
private static void setupIndexedColorSpace(PDDocument doc, PNGConverter.Chunk lookupTable, PDImageXObject image, int highVal) throws java.io.IOException
java.io.IOException
private static PDImageXObject buildImageObject(PDDocument document, PNGConverter.PNGConverterState state) throws java.io.IOException
java.io.IOException
private static COSDictionary buildDecodeParams(PNGConverter.PNGConverterState state, PDColorSpace colorSpace)
private static java.io.InputStream getIDATInputStream(PNGConverter.PNGConverterState state)
state
- the converter state.static COSName mapPNGRenderIntent(int renderIntent)
renderIntent
- the PNG render intentstatic boolean checkConverterState(PNGConverter.PNGConverterState state)
state
- the parsed converter statestatic boolean checkChunkSane(PNGConverter.Chunk chunk)
private static int readInt(byte[] data, int offset)
private static float readPNGFloat(byte[] bytes, int offset)
private static PNGConverter.PNGConverterState parsePNGChunks(byte[] imageData)
imageData
- the byte array with the PNG dataprivate static void makeCrcTable()
private static int updateCrc(byte[] buf, int offset, int len)
static int crc(byte[] buf, int offset, int len)