Package org.apache.xmlgraphics.ps
Class PSImageUtils
java.lang.Object
org.apache.xmlgraphics.ps.PSImageUtils
Utility code for rendering images in PostScript.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static void
compressAndWriteBitmap
(ImageEncoder encoder, PSGenerator gen) private static String
getColorSpaceName
(ColorSpace colorSpace) private static String
getDecodeArray
(int numComponents, boolean invertColors) 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.static void
paintForm
(PSResource form, Dimension2D formDimensions, Rectangle2D targetRect, PSGenerator gen) Paints a reusable image (previously added as a PostScript form).static void
paintForm
(PSResource form, Rectangle2D targetRect, PSGenerator gen) Deprecated.static void
paintReusableImage
(String formName, Rectangle2D targetRect, PSGenerator gen) Deprecated.Please usepaintForm(PSResource, Dimension2D, Rectangle2D, PSGenerator)
instead.private static ColorModel
populateImageDictionary
(Dimension imgDim, ColorModel colorModel, PSDictionary imageDict) private static ColorModel
populateImageDictionary
(Dimension imgDim, ColorModel colorModel, PSDictionary imageDict, Color maskColor) private static void
prepareColorspace
(PSGenerator gen, ColorSpace colorSpace) private static void
prepareColorSpace
(PSGenerator gen, ColorModel cm) static void
renderBitmapImage
(RenderedImage img, float x, float y, float w, float h, PSGenerator gen, Color mask, boolean maskBitmap) Renders a bitmap image to PostScript.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) Deprecated.Please use the variant with the InputStream as parameterstatic void
renderEPS
(InputStream in, String name, Rectangle2D viewport, Rectangle2D bbox, PSGenerator gen) Places an EPS file in the PostScript stream.private static String
rgb2Hex
(int rgb) (package private) static String
toHexString
(byte[] color) static void
translateAndScale
(PSGenerator gen, Dimension2D imageDimensions, Rectangle2D targetRect) Generates commands to modify the current transformation matrix so an image fits into a given rectangle.static void
writeImage
(byte[] img, Dimension imgDim, String imgDescription, Rectangle2D targetRect, boolean isJPEG, ColorSpace colorSpace, PSGenerator gen) Deprecated.Please use the variant with the more versatile ImageEncoder as parameterstatic void
writeImage
(ImageEncoder encoder, Dimension imgDim, String imgDescription, Rectangle2D targetRect, ColorSpace colorSpace, int bitsPerComponent, boolean invertImage, PSGenerator gen) Writes a bitmap image to the PostScript stream.static void
writeImage
(ImageEncoder encoder, Dimension imgDim, String imgDescription, Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen) static void
writeImage
(ImageEncoder encoder, Dimension imgDim, String imgDescription, Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen, RenderedImage ri, boolean maskBitmap) Writes a bitmap image to the PostScript stream.static void
writeImage
(ImageEncoder encoder, Dimension imgDim, String imgDescription, Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen, RenderedImage ri, Color maskColor) Writes a bitmap image to the PostScript stream.(package private) static void
writeImageCommand
(RenderedImage img, PSDictionary imageDict, PSGenerator gen) (package private) static void
writeImageCommand
(PSDictionary imageDict, Dimension imgDim, ColorSpace colorSpace, boolean invertImage, PSGenerator gen) (package private) static void
writeImageCommand
(PSDictionary imageDict, ColorModel cm, PSGenerator gen, boolean maskBitmap) private static ColorModel
writeImageDictionary
(Dimension imgDim, PSDictionary imageDict, ColorModel colorModel) static PSResource
writeReusableImage
(byte[] img, Dimension imgDim, String formName, String imageDescription, boolean isJPEG, ColorSpace colorSpace, PSGenerator gen) Deprecated.Please useFormGenerator
protected static PSResource
writeReusableImage
(ImageEncoder encoder, Dimension imgDim, String formName, String imageDescription, ColorSpace colorSpace, boolean invertImage, PSGenerator gen) Deprecated.Please useFormGenerator
-
Field Details
-
HEX
private static final char[] HEX
-
-
Constructor Details
-
PSImageUtils
public PSImageUtils()
-
-
Method Details
-
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 parameterWrites a bitmap image to the PostScript stream.- Parameters:
img
- the bitmap image as a byte arrayimgDim
- the dimensions of the imageimgDescription
- the name of the imagetargetRect
- the target rectangle to place the image inisJPEG
- true if "img" contains a DCT-encoded images, false if "img" contains the decoded bitmapcolorSpace
- the color space of the imagegen
- 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 encoderimgDim
- the dimensions of the imageimgDescription
- the name of the imagetargetRect
- the target rectangle to place the image incolorSpace
- the color space of the imagebitsPerComponent
- the number of bits per componentinvertImage
- true if the image shall be invertedgen
- 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) throws IOException - Throws:
IOException
-
writeImage
public static void writeImage(ImageEncoder encoder, Dimension imgDim, String imgDescription, Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen, RenderedImage ri, boolean maskBitmap) throws IOException Writes a bitmap image to the PostScript stream.- Parameters:
encoder
- the image encoderimgDim
- the dimensions of the imageimgDescription
- the name of the imagetargetRect
- the target rectangle to place the image incolorModel
- the color model of the imagegen
- 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 encoderimgDim
- the dimensions of the imageimgDescription
- the name of the imagetargetRect
- the target rectangle to place the image incolorModel
- the color model of the imagegen
- the PostScript generator- Throws:
IOException
- In case of an I/O exception
-
populateImageDictionary
private static ColorModel populateImageDictionary(Dimension imgDim, ColorModel colorModel, PSDictionary imageDict) -
populateImageDictionary
private static ColorModel populateImageDictionary(Dimension imgDim, ColorModel colorModel, PSDictionary imageDict, Color maskColor) -
writeImageDictionary
private static ColorModel writeImageDictionary(Dimension imgDim, PSDictionary imageDict, ColorModel colorModel) -
getDecodeArray
-
prepareColorspace
- Throws:
IOException
-
prepareColorSpace
- Throws:
IOException
-
toHexString
-
writeImageCommand
static void writeImageCommand(RenderedImage img, PSDictionary imageDict, PSGenerator gen) throws IOException - Throws:
IOException
-
writeImageCommand
static void writeImageCommand(PSDictionary imageDict, ColorModel cm, PSGenerator gen, boolean maskBitmap) throws IOException - Throws:
IOException
-
writeImageCommand
static void writeImageCommand(PSDictionary imageDict, Dimension imgDim, ColorSpace colorSpace, boolean invertImage, PSGenerator gen) throws IOException - Throws:
IOException
-
rgb2Hex
-
renderBitmapImage
public static void renderBitmapImage(RenderedImage img, float x, float y, float w, float h, PSGenerator gen, Color mask, boolean maskBitmap) throws IOException Renders a bitmap image to PostScript.- Parameters:
img
- image to renderx
- x positiony
- y positionw
- widthh
- heightgen
- 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 useFormGenerator
Writes a bitmap image as a PostScript form enclosed by DSC resource wrappers to the PostScript file.- Parameters:
img
- the raw bitmap dataimgDim
- the dimensions of the imageformName
- the name of the PostScript form to useimageDescription
- a description of the image added as a DSC Title commentisJPEG
- true if "img" contains a DCT-encoded images, false if "img" contains the decoded bitmapcolorSpace
- the color space of the imagegen
- 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 useFormGenerator
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 dataimgDim
- the dimensions of the imageformName
- the name of the PostScript form to useimageDescription
- a description of the image added as a DSC Title commentcolorSpace
- the color space of the imageinvertImage
- true if the image shall be invertedgen
- the PostScript generator- Returns:
- a PSResource representing the form for resource tracking
- Throws:
IOException
- In case of an I/O exception
-
paintReusableImage
public static void paintReusableImage(String formName, Rectangle2D targetRect, PSGenerator gen) throws IOException Deprecated.Please usepaintForm(PSResource, Dimension2D, Rectangle2D, PSGenerator)
instead.Paints a reusable image (previously added as a PostScript form).- Parameters:
formName
- the name of the PostScript form implementing the imagetargetRect
- the target rectangle to place the image ingen
- the PostScript generator- Throws:
IOException
- In case of an I/O exception
-
paintForm
public static void paintForm(PSResource form, Rectangle2D targetRect, PSGenerator gen) throws IOException Deprecated.Please usepaintForm(PSResource, Dimension2D, Rectangle2D, PSGenerator)
instead.Paints a reusable image (previously added as a PostScript form).- Parameters:
form
- the PostScript form resource implementing the imagetargetRect
- the target rectangle to place the image ingen
- the PostScript generator- 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 imageformDimensions
- the original dimensions of the formtargetRect
- the target rectangle to place the image ingen
- the PostScript generator- Throws:
IOException
- In case of an I/O exception
-
getColorSpaceName
-
compressAndWriteBitmap
- Throws:
IOException
-
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 generatorimageDimensions
- the image's dimensionstargetRect
- 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 imagestartX
- the starting X coordinatestartY
- the starting Y coordinatew
- the width of the cropped imageh
- the height of the cropped imagergbArray
- the prepared integer array to write tooffset
- offset in the target arrayscansize
- 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 parameterPlaces an EPS file in the PostScript stream.- Parameters:
rawEPS
- byte array containing the raw EPS dataname
- name for the EPS documentx
- x-coordinate of viewport in pointsy
- y-coordinate of viewport in pointsw
- width of viewport in pointsh
- height of viewport in pointsbboxx
- x-coordinate of EPS bounding box in pointsbboxy
- y-coordinate of EPS bounding box in pointsbboxw
- width of EPS bounding box in pointsbboxh
- height of EPS bounding box in pointsgen
- 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 streamname
- name for the EPS documentviewport
- the viewport in points in which to place the EPSbbox
- the EPS bounding box in pointsgen
- the PS generator- Throws:
IOException
- in case an I/O error happens during output
-
paintForm(PSResource, Dimension2D, Rectangle2D, PSGenerator)
instead.