Class PSImageUtils


  • public class PSImageUtils
    extends Object
    Utility code for rendering images in PostScript.
    • Constructor Detail

      • PSImageUtils

        public PSImageUtils()
    • Method Detail

      • writeImage

        public static void writeImage​(byte[] img,
                                      Dimension imgDim,
                                      String imgDescription,
                                      Rectangle2D targetRect,
                                      boolean isJPEG,
                                      ColorSpace colorSpace,
                                      PSGenerator gen)
                               throws IOException
        Deprecated.
        Please use the variant with the more versatile ImageEncoder as parameter
        Writes a bitmap image to the PostScript stream.
        Parameters:
        img - the bitmap image as a byte array
        imgDim - the dimensions of the image
        imgDescription - the name of the image
        targetRect - the target rectangle to place the image in
        isJPEG - true if "img" contains a DCT-encoded images, false if "img" contains the decoded bitmap
        colorSpace - the color space of the image
        gen - the PostScript generator
        Throws:
        IOException - In case of an I/O exception
      • writeImage

        public static void writeImage​(ImageEncoder encoder,
                                      Dimension imgDim,
                                      String imgDescription,
                                      Rectangle2D targetRect,
                                      ColorSpace colorSpace,
                                      int bitsPerComponent,
                                      boolean invertImage,
                                      PSGenerator gen)
                               throws IOException
        Writes a bitmap image to the PostScript stream.
        Parameters:
        encoder - the image encoder
        imgDim - the dimensions of the image
        imgDescription - the name of the image
        targetRect - the target rectangle to place the image in
        colorSpace - the color space of the image
        bitsPerComponent - the number of bits per component
        invertImage - true if the image shall be inverted
        gen - the PostScript generator
        Throws:
        IOException - In case of an I/O exception
      • writeImage

        public static void writeImage​(ImageEncoder encoder,
                                      Dimension imgDim,
                                      String imgDescription,
                                      Rectangle2D targetRect,
                                      ColorModel colorModel,
                                      PSGenerator gen,
                                      RenderedImage ri)
                               throws IOException
        Writes a bitmap image to the PostScript stream.
        Parameters:
        encoder - the image encoder
        imgDim - the dimensions of the image
        imgDescription - the name of the image
        targetRect - the target rectangle to place the image in
        colorModel - the color model of the image
        gen - the PostScript generator
        Throws:
        IOException - In case of an I/O exception
      • writeImage

        public static void writeImage​(ImageEncoder encoder,
                                      Dimension imgDim,
                                      String imgDescription,
                                      Rectangle2D targetRect,
                                      ColorModel colorModel,
                                      PSGenerator gen,
                                      RenderedImage ri,
                                      Color maskColor)
                               throws IOException
        Writes a bitmap image to the PostScript stream.
        Parameters:
        encoder - the image encoder
        imgDim - the dimensions of the image
        imgDescription - the name of the image
        targetRect - the target rectangle to place the image in
        colorModel - the color model of the image
        gen - the PostScript generator
        Throws:
        IOException - In case of an I/O exception
      • renderBitmapImage

        public static void renderBitmapImage​(RenderedImage img,
                                             float x,
                                             float y,
                                             float w,
                                             float h,
                                             PSGenerator gen,
                                             Color mask)
                                      throws IOException
        Renders a bitmap image to PostScript.
        Parameters:
        img - image to render
        x - x position
        y - y position
        w - width
        h - height
        gen - PS generator
        Throws:
        IOException - In case of an I/O problem while rendering the image
      • writeReusableImage

        public static PSResource writeReusableImage​(byte[] img,
                                                    Dimension imgDim,
                                                    String formName,
                                                    String imageDescription,
                                                    boolean isJPEG,
                                                    ColorSpace colorSpace,
                                                    PSGenerator gen)
                                             throws IOException
        Deprecated.
        Please use FormGenerator
        Writes a bitmap image as a PostScript form enclosed by DSC resource wrappers to the PostScript file.
        Parameters:
        img - the raw bitmap data
        imgDim - the dimensions of the image
        formName - the name of the PostScript form to use
        imageDescription - a description of the image added as a DSC Title comment
        isJPEG - true if "img" contains a DCT-encoded images, false if "img" contains the decoded bitmap
        colorSpace - the color space of the image
        gen - the PostScript generator
        Returns:
        a PSResource representing the form for resource tracking
        Throws:
        IOException - In case of an I/O exception
      • writeReusableImage

        protected static PSResource writeReusableImage​(ImageEncoder encoder,
                                                       Dimension imgDim,
                                                       String formName,
                                                       String imageDescription,
                                                       ColorSpace colorSpace,
                                                       boolean invertImage,
                                                       PSGenerator gen)
                                                throws IOException
        Deprecated.
        Please use FormGenerator
        Writes a bitmap image as a PostScript form enclosed by DSC resource wrappers to the PostScript file.
        Parameters:
        encoder - the ImageEncoder that will provide the raw bitmap data
        imgDim - the dimensions of the image
        formName - the name of the PostScript form to use
        imageDescription - a description of the image added as a DSC Title comment
        colorSpace - the color space of the image
        invertImage - true if the image shall be inverted
        gen - the PostScript generator
        Returns:
        a PSResource representing the form for resource tracking
        Throws:
        IOException - In case of an I/O exception
      • paintForm

        public static void paintForm​(PSResource form,
                                     Dimension2D formDimensions,
                                     Rectangle2D targetRect,
                                     PSGenerator gen)
                              throws IOException
        Paints a reusable image (previously added as a PostScript form).
        Parameters:
        form - the PostScript form resource implementing the image
        formDimensions - the original dimensions of the form
        targetRect - the target rectangle to place the image in
        gen - the PostScript generator
        Throws:
        IOException - In case of an I/O exception
      • translateAndScale

        public static void translateAndScale​(PSGenerator gen,
                                             Dimension2D imageDimensions,
                                             Rectangle2D targetRect)
                                      throws IOException
        Generates commands to modify the current transformation matrix so an image fits into a given rectangle.
        Parameters:
        gen - the PostScript generator
        imageDimensions - the image's dimensions
        targetRect - the target rectangle
        Throws:
        IOException - if an I/O error occurs
      • getRGB

        public static int[] getRGB​(RenderedImage img,
                                   int startX,
                                   int startY,
                                   int w,
                                   int h,
                                   int[] rgbArray,
                                   int offset,
                                   int scansize)
        Extracts a packed RGB integer array of a RenderedImage.
        Parameters:
        img - the image
        startX - the starting X coordinate
        startY - the starting Y coordinate
        w - the width of the cropped image
        h - the height of the cropped image
        rgbArray - the prepared integer array to write to
        offset - offset in the target array
        scansize - width of a row in the target array
        Returns:
        the populated integer array previously passed in as rgbArray parameter
      • renderEPS

        public static void renderEPS​(byte[] rawEPS,
                                     String name,
                                     float x,
                                     float y,
                                     float w,
                                     float h,
                                     float bboxx,
                                     float bboxy,
                                     float bboxw,
                                     float bboxh,
                                     PSGenerator gen)
                              throws IOException
        Deprecated.
        Please use the variant with the InputStream as parameter
        Places an EPS file in the PostScript stream.
        Parameters:
        rawEPS - byte array containing the raw EPS data
        name - name for the EPS document
        x - x-coordinate of viewport in points
        y - y-coordinate of viewport in points
        w - width of viewport in points
        h - height of viewport in points
        bboxx - x-coordinate of EPS bounding box in points
        bboxy - y-coordinate of EPS bounding box in points
        bboxw - width of EPS bounding box in points
        bboxh - height of EPS bounding box in points
        gen - the PS generator
        Throws:
        IOException - in case an I/O error happens during output
      • renderEPS

        public static void renderEPS​(InputStream in,
                                     String name,
                                     Rectangle2D viewport,
                                     Rectangle2D bbox,
                                     PSGenerator gen)
                              throws IOException
        Places an EPS file in the PostScript stream.
        Parameters:
        in - the InputStream that contains the EPS stream
        name - name for the EPS document
        viewport - the viewport in points in which to place the EPS
        bbox - the EPS bounding box in points
        gen - the PS generator
        Throws:
        IOException - in case an I/O error happens during output