Class PDFImage


  • public class PDFImage
    extends java.lang.Object
    Encapsulates a PDF Image
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  PDFImage.DecodeComponentColorModel
      A wrapper for ComponentColorSpace which normalizes based on the decode array.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int bpc
      the number of bits per sample component
      private int[] colorKeyMask
      color key mask.
      private PDFColorSpace colorSpace
      the colorspace to interpret the samples in
      private float[] decode
      the decode array
      private int height
      the height of this image in pixels
      private boolean imageMask
      whether this image is a mask or not
      private PDFObject imageObj
      the actual image data
      private PDFImage sMask
      the SMask image, if any
      private int width
      the width of this image in pixels
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected PDFImage​(PDFObject imageObj)
      Create an instance of a PDFImage
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PDFImage createImage​(PDFObject obj, java.util.Map resources)
      Read a PDFImage from an image dictionary and stream
      static void dump​(PDFObject obj)  
      protected int getBitsPerComponent()
      Get the number of bits per component sample
      private java.awt.image.ColorModel getColorModel()
      get a Java ColorModel consistent with the current color space, number of bits per component and decode array
      protected PDFColorSpace getColorSpace()
      Get the colorspace associated with this image, or null if there isn't one
      protected float[] getDecode()
      Get the decode array
      int getHeight()
      Get the image's height
      java.awt.image.BufferedImage getImage()
      Get the image that this PDFImage generates.
      PDFImage getSMask()
      Return the soft mask associated with this image
      int getWidth()
      Get the image's width
      boolean isImageMask()
      Return whether or not this is an image mask
      private float[] normalize​(byte[] pixels, float[] normComponents, int normOffset)
      Normalize an array of values to match the decode array
      static void p​(java.lang.String string)  
      protected java.awt.image.BufferedImage parseData​(byte[] data)
      Parse the image stream into a buffered image.
      protected void setBitsPerComponent​(int bpc)
      Set the number of bits per component sample
      private void setColorKeyMask​(PDFObject maskArrayObject)
      set the color key mask.
      protected void setColorSpace​(PDFColorSpace colorSpace)
      Set the colorspace associated with this image
      protected void setDecode​(float[] decode)
      Set the decode array
      protected void setHeight​(int height)
      Set the image's height
      void setImageMask​(boolean imageMask)
      Set whether or not this is an image mask
      protected void setSMask​(PDFImage sMask)
      Set the soft mask image
      protected void setWidth​(int width)
      Set the image's width
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • colorKeyMask

        private int[] colorKeyMask
        color key mask. Array of start/end pairs of ranges of color components to mask out. If a component falls within any of the ranges it is clear.
      • width

        private int width
        the width of this image in pixels
      • height

        private int height
        the height of this image in pixels
      • colorSpace

        private PDFColorSpace colorSpace
        the colorspace to interpret the samples in
      • bpc

        private int bpc
        the number of bits per sample component
      • imageMask

        private boolean imageMask
        whether this image is a mask or not
      • sMask

        private PDFImage sMask
        the SMask image, if any
      • decode

        private float[] decode
        the decode array
      • imageObj

        private PDFObject imageObj
        the actual image data
    • Constructor Detail

      • PDFImage

        protected PDFImage​(PDFObject imageObj)
        Create an instance of a PDFImage
    • Method Detail

      • dump

        public static void dump​(PDFObject obj)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • p

        public static void p​(java.lang.String string)
      • createImage

        public static PDFImage createImage​(PDFObject obj,
                                           java.util.Map resources)
                                    throws java.io.IOException
        Read a PDFImage from an image dictionary and stream
        Parameters:
        obj - the PDFObject containing the image's dictionary and stream
        resources - the current resources
        Throws:
        java.io.IOException
      • getImage

        public java.awt.image.BufferedImage getImage()
        Get the image that this PDFImage generates.
        Returns:
        a buffered image containing the decoded image data
      • parseData

        protected java.awt.image.BufferedImage parseData​(byte[] data)

        Parse the image stream into a buffered image. Note that this is guaranteed to be called after all the other setXXX methods have been called.

        NOTE: the color convolving is extremely slow on large images. It would be good to see if it could be moved out into the rendering phases, where we might be able to scale the image down first.

      • getWidth

        public int getWidth()
        Get the image's width
      • setWidth

        protected void setWidth​(int width)
        Set the image's width
      • getHeight

        public int getHeight()
        Get the image's height
      • setHeight

        protected void setHeight​(int height)
        Set the image's height
      • setColorKeyMask

        private void setColorKeyMask​(PDFObject maskArrayObject)
                              throws java.io.IOException
        set the color key mask. It is an array of start/end entries to indicate ranges of color indicies that should be masked out.
        Parameters:
        maskArrayObject -
        Throws:
        java.io.IOException
      • getColorSpace

        protected PDFColorSpace getColorSpace()
        Get the colorspace associated with this image, or null if there isn't one
      • setColorSpace

        protected void setColorSpace​(PDFColorSpace colorSpace)
        Set the colorspace associated with this image
      • getBitsPerComponent

        protected int getBitsPerComponent()
        Get the number of bits per component sample
      • setBitsPerComponent

        protected void setBitsPerComponent​(int bpc)
        Set the number of bits per component sample
      • isImageMask

        public boolean isImageMask()
        Return whether or not this is an image mask
      • setImageMask

        public void setImageMask​(boolean imageMask)
        Set whether or not this is an image mask
      • getSMask

        public PDFImage getSMask()
        Return the soft mask associated with this image
      • setSMask

        protected void setSMask​(PDFImage sMask)
        Set the soft mask image
      • getDecode

        protected float[] getDecode()
        Get the decode array
      • setDecode

        protected void setDecode​(float[] decode)
        Set the decode array
      • getColorModel

        private java.awt.image.ColorModel getColorModel()
        get a Java ColorModel consistent with the current color space, number of bits per component and decode array
        Parameters:
        bpc - the number of bits per component
      • normalize

        private float[] normalize​(byte[] pixels,
                                  float[] normComponents,
                                  int normOffset)
        Normalize an array of values to match the decode array