Class LosslessFactory.PredictorEncoder

java.lang.Object
org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory.PredictorEncoder
Enclosing class:
LosslessFactory

private static class LosslessFactory.PredictorEncoder extends Object
  • Field Details

    • document

      private final PDDocument document
    • image

      private final 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 Details

    • PredictorEncoder

      PredictorEncoder(PDDocument document, BufferedImage image)
      Initialize the encoder and set all final fields
  • Method Details

    • encode

      PDImageXObject encode() throws 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:
      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)