Class LosslessFactory.PredictorEncoder
java.lang.Object
org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory.PredictorEncoder
- Enclosing class:
- LosslessFactory
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final byte[]
(package private) final byte[]
(package private) final byte[]
private final int
private final int
private final int
(package private) final byte[]
private final byte[]
private final byte[]
private final byte[]
private final byte[]
private final byte[]
private final PDDocument
(package private) final boolean
private final int
private final BufferedImage
(package private) final int
(package private) final byte[]
private final int
private final int
(package private) final byte[]
-
Constructor Summary
ConstructorsConstructorDescriptionPredictorEncoder
(PDDocument document, BufferedImage image) Initialize the encoder and set all final fields -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
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
(ByteArrayOutputStream stream, int bitsPerComponent)
-
Field Details
-
document
-
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 Details
-
PredictorEncoder
PredictorEncoder(PDDocument document, BufferedImage image) Initialize the encoder and set all final fields
-
-
Method Details
-
encode
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:
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(ByteArrayOutputStream stream, int bitsPerComponent) throws IOException - Throws:
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)
-