Package org.apache.xmlgraphics.ps
Class ImageEncodingHelper
java.lang.Object
org.apache.xmlgraphics.ps.ImageEncodingHelper
Helper class for encoding bitmap images.
-
Constructor Summary
ConstructorsConstructorDescriptionImageEncodingHelper
(RenderedImage image) Main constructorImageEncodingHelper
(RenderedImage image, boolean enableCMYK) Main constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageEncoder
Create an ImageEncoder for the given RenderImage instance.protected void
Determines the color model used for encoding the image.void
encode
(OutputStream out) Encodes the image and writes everything to the given OutputStream.void
encodeAlpha
(OutputStream out) Encodes the image's alpha channel.static void
encodePackedColorComponents
(RenderedImage image, OutputStream out) Writes all pixels (color components only) of a RenderedImage to an OutputStream.static void
encodeRenderedImageAsRGB
(RenderedImage image, OutputStream out) static void
encodeRenderedImageAsRGB
(RenderedImage image, OutputStream out, boolean outputbw, boolean bwinvert) Writes a RenderedImage to an OutputStream by converting it to RGB.static boolean
Writes a RenderedImage to an OutputStream.static void
encodeRGBAsGrayScale
(byte[] raw, int width, int height, int bitsPerPixel, OutputStream out) Converts a byte array containing 24 bit RGB image data to a grayscale image.Returns the effectiveColorModel
used to encode the image.getImage()
Returns the associated image.Returns the nativeColorModel
used by the image.boolean
hasAlpha()
Indicates whether the image has an alpha channel.boolean
Indicates whether the image is converted during encodation.protected boolean
Indicates whether the image consists of multiple tiles.void
setBWInvert
(boolean v)
-
Constructor Details
-
ImageEncodingHelper
Main constructor- Parameters:
image
- the image
-
ImageEncodingHelper
Main constructor- Parameters:
image
- the imageenableCMYK
- true to enable CMYK, false to disable
-
-
Method Details
-
getImage
Returns the associated image.- Returns:
- the image
-
getNativeColorModel
Returns the nativeColorModel
used by the image.- Returns:
- the native color model
-
getEncodedColorModel
Returns the effectiveColorModel
used to encode the image. If this is different from the value returned bygetNativeColorModel()
this means that the image is converted in order to encode it because no native encoding is currently possible.- Returns:
- the effective color model
-
hasAlpha
public boolean hasAlpha()Indicates whether the image has an alpha channel.- Returns:
- true if the image has an alpha channel
-
isConverted
public boolean isConverted()Indicates whether the image is converted during encodation.- Returns:
- true if the image cannot be encoded in its native format
-
encodeRenderedImageAsRGB
public static void encodeRenderedImageAsRGB(RenderedImage image, OutputStream out) throws IOException - Throws:
IOException
-
encodeRenderedImageAsRGB
public static void encodeRenderedImageAsRGB(RenderedImage image, OutputStream out, boolean outputbw, boolean bwinvert) throws IOException Writes a RenderedImage to an OutputStream by converting it to RGB.- Parameters:
image
- the imageout
- the OutputStream to write the pixels to- Throws:
IOException
- if an I/O error occurs
-
encodeRenderedImageWithDirectColorModelAsRGB
public static boolean encodeRenderedImageWithDirectColorModelAsRGB(RenderedImage image, OutputStream out) throws IOException Writes a RenderedImage to an OutputStream. This method optimizes the encoding of theDirectColorModel
as it is returned byColorModel.getRGBdefault()
.- Parameters:
image
- the imageout
- the OutputStream to write the pixels to- Returns:
- true if this method encoded this image, false if the image is incompatible
- Throws:
IOException
- if an I/O error occurs
-
encodeRGBAsGrayScale
public static void encodeRGBAsGrayScale(byte[] raw, int width, int height, int bitsPerPixel, OutputStream out) throws IOException Converts a byte array containing 24 bit RGB image data to a grayscale image.- Parameters:
raw
- the buffer containing the RGB image datawidth
- the width of the image in pixelsheight
- the height of the image in pixelsbitsPerPixel
- the number of bits to use per pixelout
- the OutputStream to write the pixels to- Throws:
IOException
- if an I/O error occurs
-
isMultiTile
protected boolean isMultiTile()Indicates whether the image consists of multiple tiles.- Returns:
- true if there are multiple tiles
-
determineEncodedColorModel
protected void determineEncodedColorModel()Determines the color model used for encoding the image. -
encode
Encodes the image and writes everything to the given OutputStream.- Parameters:
out
- the OutputStream- Throws:
IOException
- if an I/O error occurs
-
encodeAlpha
Encodes the image's alpha channel. If it doesn't have an alpha channel, anIllegalStateException
is thrown.- Parameters:
out
- the OutputStream- Throws:
IOException
- if an I/O error occurs
-
encodePackedColorComponents
public static void encodePackedColorComponents(RenderedImage image, OutputStream out) throws IOException Writes all pixels (color components only) of a RenderedImage to an OutputStream.- Parameters:
image
- the image to be encodedout
- the OutputStream to write to- Throws:
IOException
- if an I/O error occurs
-
createRenderedImageEncoder
Create an ImageEncoder for the given RenderImage instance.- Parameters:
img
- the image- Returns:
- the requested ImageEncoder
-
setBWInvert
public void setBWInvert(boolean v)
-