Class LosslessFactory.PredictorEncoder
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory.PredictorEncoder
-
- Enclosing class:
- LosslessFactory
private static class LosslessFactory.PredictorEncoder extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) byte[]
alphaImageData
(package private) byte[]
aValues
(package private) byte[]
bValues
private int
bytesPerComponent
private int
bytesPerPixel
private int
componentsPerPixel
(package private) byte[]
cValues
private byte[]
dataRawRowAverage
private byte[]
dataRawRowNone
private byte[]
dataRawRowPaeth
private byte[]
dataRawRowSub
private byte[]
dataRawRowUp
private PDDocument
document
(package private) boolean
hasAlpha
private int
height
private java.awt.image.BufferedImage
image
(package private) int
imageType
(package private) byte[]
tmpResultValues
private int
transferType
private int
width
(package private) byte[]
xValues
-
Constructor Summary
Constructors Constructor Description PredictorEncoder(PDDocument document, java.awt.image.BufferedImage image)
Initialize the encoder and set all final fields
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[]
chooseDataRowToWrite()
We look which row encoding is the "best" one, ie.private void
copyImageBytes(byte[] transferRow, int indexInTranferRow, byte[] targetValues, byte[] alphaImageData, int alphaPtr)
private void
copyIntToBytes(int[] transferRow, int indexInTranferRow, byte[] targetValues, byte[] alphaImageData, int alphaPtr)
private static void
copyShortsToBytes(short[] transferRow, int indexInTranferRow, byte[] targetValues, byte[] alphaImageData, int alphaPtr)
(package private) PDImageXObject
encode()
Tries to compress the image using a predictor.private static long
estCompressSum(byte[] dataRawRowSub)
private static byte
pngFilterAverage(int x, int a, int b)
private static byte
pngFilterPaeth(int x, int a, int b, int c)
private static byte
pngFilterSub(int x, int a)
private static byte
pngFilterUp(int x, int b)
private PDImageXObject
preparePredictorPDImage(java.io.ByteArrayOutputStream stream, int bitsPerComponent)
-
-
-
Field Detail
-
document
private final PDDocument document
-
image
private final java.awt.image.BufferedImage image
-
componentsPerPixel
private final int componentsPerPixel
-
transferType
private final int transferType
-
bytesPerComponent
private final int bytesPerComponent
-
bytesPerPixel
private final int bytesPerPixel
-
height
private final int height
-
width
private final int width
-
dataRawRowNone
private final byte[] dataRawRowNone
-
dataRawRowSub
private final byte[] dataRawRowSub
-
dataRawRowUp
private final byte[] dataRawRowUp
-
dataRawRowAverage
private final byte[] dataRawRowAverage
-
dataRawRowPaeth
private final byte[] dataRawRowPaeth
-
imageType
final int imageType
-
hasAlpha
final boolean hasAlpha
-
alphaImageData
final byte[] alphaImageData
-
aValues
final byte[] aValues
-
cValues
final byte[] cValues
-
bValues
final byte[] bValues
-
xValues
final byte[] xValues
-
tmpResultValues
final byte[] tmpResultValues
-
-
Constructor Detail
-
PredictorEncoder
PredictorEncoder(PDDocument document, java.awt.image.BufferedImage image)
Initialize the encoder and set all final fields
-
-
Method Detail
-
encode
PDImageXObject encode() throws java.io.IOException
Tries to compress the image using a predictor.- Returns:
- the image or null if it is not possible to encoded the image (e.g. not supported raster format etc.)
- Throws:
java.io.IOException
-
copyIntToBytes
private void copyIntToBytes(int[] transferRow, int indexInTranferRow, byte[] targetValues, byte[] alphaImageData, int alphaPtr)
-
copyImageBytes
private void copyImageBytes(byte[] transferRow, int indexInTranferRow, byte[] targetValues, byte[] alphaImageData, int alphaPtr)
-
copyShortsToBytes
private static void copyShortsToBytes(short[] transferRow, int indexInTranferRow, byte[] targetValues, byte[] alphaImageData, int alphaPtr)
-
preparePredictorPDImage
private PDImageXObject preparePredictorPDImage(java.io.ByteArrayOutputStream stream, int bitsPerComponent) throws java.io.IOException
- Throws:
java.io.IOException
-
chooseDataRowToWrite
private byte[] chooseDataRowToWrite()
We look which row encoding is the "best" one, ie. has the lowest sum. We don't implement anything fancier to choose the right row encoding. This is just the recommend algorithm in the spec. The get the perfect encoding you would need to do a brute force check how all the different encoded rows compress in the zip stream together. You have would have to check 5*image-height permutations...- Returns:
- the "best" row encoding of the row encodings
-
pngFilterSub
private static byte pngFilterSub(int x, int a)
-
pngFilterUp
private static byte pngFilterUp(int x, int b)
-
pngFilterAverage
private static byte pngFilterAverage(int x, int a, int b)
-
pngFilterPaeth
private static byte pngFilterPaeth(int x, int a, int b, int c)
-
estCompressSum
private static long estCompressSum(byte[] dataRawRowSub)
-
-