Class DCTDecode

java.lang.Object
com.sun.pdfview.decode.DCTDecode

public class DCTDecode extends Object
decode a DCT encoded array into a byte array. This class uses Java's built-in JPEG image class to do the decoding.
  • Constructor Details

    • DCTDecode

      public DCTDecode()
  • Method Details

    • decode

      protected static ByteBuffer decode(PDFObject dict, ByteBuffer buf, PDFObject params) throws PDFParseException
      decode an array of bytes in DCT format.

      DCT is the format used by JPEG images, so this class simply loads the DCT-format bytes as an image, then reads the bytes out of the image to create the array. If this were to be used against image objects we'd end up wasting a lot of work, because we'd be generating a buffered image here, writing out the bytes, and then generating a buffered image again from those bytes in the PDFImage class.

      Luckily, the image processing has been optimised to detect DCT decodes at the end of filters, in which case it avoids running the stream through this filter, and just directly generates a BufferedImage from the DCT encoded byte stream. As such, this decode will be invoked only if there's been some very unusual employment of filters in the PDF - e.g., DCTDecode applied to non-image data, or if DCTDecode is not at the end of a Filter dictionary entry. This is permissible but unlikely to occur in practice.

      The DCT-encoded stream may have 1, 3 or 4 samples per pixel, depending on the colorspace of the image. In decoding, we look for the colorspace in the stream object's dictionary to decide how to decode this image. If no colorspace is present, we guess 3 samples per pixel.

      Parameters:
      dict - the stream dictionary
      buf - the DCT-encoded buffer
      params - the parameters to the decoder (ignored)
      Returns:
      the decoded buffer
      Throws:
      PDFParseException