java.awt.image

Class ColorConvertOp

public class ColorConvertOp extends Object implements BufferedImageOp, RasterOp

ColorConvertOp is a filter for converting images or rasters between colorspaces, either through a sequence of colorspaces or just from source to destination. Color conversion is done on the color components without alpha. Thus if a BufferedImage has alpha premultiplied, this is divided out before color conversion, and premultiplication applied if the destination requires it. Color rendering and dithering hints may be applied if specified. This is likely platform-dependent.
Constructor Summary
ColorConvertOp(ColorSpace cspace, RenderingHints hints)
Convert a BufferedImage through a ColorSpace.
ColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, RenderingHints hints)
Convert from a source colorspace to a destination colorspace.
ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints)
Convert from a source colorspace to a destinatino colorspace.
ColorConvertOp(RenderingHints hints)
Convert from source color space to destination color space.
Method Summary
BufferedImagecreateCompatibleDestImage(BufferedImage src, ColorModel dstCM)
Creates an empty BufferedImage with the size equal to the source and the correct number of bands for the conversion defined in this Op.
WritableRastercreateCompatibleDestRaster(Raster src)
Creates a new WritableRaster with the size equal to the source and the correct number of bands.
BufferedImagefilter(BufferedImage src, BufferedImage dst)
Converts the source image using the conversion path specified in the constructor.
WritableRasterfilter(Raster src, WritableRaster dest)
Converts the source raster using the conversion path specified in the constructor.
Rectangle2DgetBounds2D(BufferedImage src)
Returns the corresponding destination boundary of a source boundary.
Rectangle2DgetBounds2D(Raster src)
Returns the corresponding destination boundary of a source boundary.
ICC_Profile[]getICC_Profiles()
Returns the array of ICC_Profiles used to create this Op, or null if the Op was created using ColorSpace arguments.
Point2DgetPoint2D(Point2D src, Point2D dst)
Returns the corresponding destination point for a source point.
RenderingHintsgetRenderingHints()
Returns the rendering hints for this op.

Constructor Detail

ColorConvertOp

public ColorConvertOp(ColorSpace cspace, RenderingHints hints)
Convert a BufferedImage through a ColorSpace. Objects created with this constructor can be used to convert BufferedImage's to a destination ColorSpace. Attempts to convert Rasters with this constructor will result in an IllegalArgumentException when the filter(Raster, WritableRaster) method is called.

Parameters: cspace The target color space. hints Rendering hints to use in conversion, if any (may be null)

Throws: NullPointerException if the ColorSpace is null.

ColorConvertOp

public ColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, RenderingHints hints)
Convert from a source colorspace to a destination colorspace. This constructor takes two ColorSpace arguments as the source and destination color spaces. It is usually used with the filter(Raster, WritableRaster) method, in which case the source colorspace is assumed to correspond to the source Raster, and the destination colorspace with the destination Raster. If used with BufferedImages that do not match the source or destination colorspaces specified here, there is an implicit conversion from the source image to the source ColorSpace, or the destination ColorSpace to the destination image.

Parameters: srcCspace The source ColorSpace. dstCspace The destination ColorSpace. hints Rendering hints to use in conversion, if any (may be null).

Throws: NullPointerException if any ColorSpace is null.

ColorConvertOp

public ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints)
Convert from a source colorspace to a destinatino colorspace. This constructor builds a ColorConvertOp from an array of ICC_Profiles. The source will be converted through the sequence of color spaces defined by the profiles. If the sequence of profiles doesn't give a well-defined conversion, an IllegalArgumentException is thrown. If used with BufferedImages that do not match the source or destination colorspaces specified here, there is an implicit conversion from the source image to the source ColorSpace, or the destination ColorSpace to the destination image. For Rasters, the first and last profiles must have the same number of bands as the source and destination Rasters, respectively. If this is not the case, or there fewer than 2 profiles, an IllegalArgumentException will be thrown.

Parameters: profiles An array of ICC_Profile's to convert through. hints Rendering hints to use in conversion, if any (may be null).

Throws: NullPointerException if the profile array is null. IllegalArgumentException if the array is not a well-defined conversion.

ColorConvertOp

public ColorConvertOp(RenderingHints hints)
Convert from source color space to destination color space. Only valid for BufferedImage objects, this Op converts from the source image's color space to the destination image's color space. The destination in the filter(BufferedImage, BufferedImage) method cannot be null for this operation, and it also cannot be used with the filter(Raster, WritableRaster) method.

Parameters: hints Rendering hints to use in conversion, if any (may be null).

Method Detail

createCompatibleDestImage

public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM)
Creates an empty BufferedImage with the size equal to the source and the correct number of bands for the conversion defined in this Op. The newly created image is created with the specified ColorModel, or if no ColorModel is supplied, an appropriate one is chosen.

Parameters: src The source image. dstCM A color model for the destination image (may be null).

Returns: The new compatible destination image.

Throws: IllegalArgumentException if an appropriate colormodel cannot be chosen with the information given.

createCompatibleDestRaster

public WritableRaster createCompatibleDestRaster(Raster src)
Creates a new WritableRaster with the size equal to the source and the correct number of bands. Note, the new Raster will always use a BYTE storage size, regardless of the color model or defined destination; this is for compatibility with the reference implementation.

Parameters: src The source Raster.

Returns: The new compatible destination raster.

Throws: IllegalArgumentException if there isn't enough colorspace information to create a compatible Raster.

filter

public final BufferedImage filter(BufferedImage src, BufferedImage dst)
Converts the source image using the conversion path specified in the constructor. The resulting image is stored in the destination image if one is provided; otherwise a new BufferedImage is created and returned. The source and destination BufferedImage (if one is supplied) must have the same dimensions.

Parameters: src The source image. dst The destination image.

Returns: The transformed image.

Throws: IllegalArgumentException if the rasters and/or color spaces are incompatible.

filter

public final WritableRaster filter(Raster src, WritableRaster dest)
Converts the source raster using the conversion path specified in the constructor. The resulting raster is stored in the destination raster if one is provided; otherwise a new WritableRaster is created and returned. This operation is not valid with every constructor of this class; see the constructors for details. Further, the source raster must have the same number of bands as the source ColorSpace, and the destination raster must have the same number of bands as the destination ColorSpace. The source and destination raster (if one is supplied) must also have the same dimensions.

Parameters: src The source raster. dest The destination raster.

Returns: The transformed raster.

Throws: IllegalArgumentException if the rasters and/or color spaces are incompatible.

getBounds2D

public final Rectangle2D getBounds2D(BufferedImage src)
Returns the corresponding destination boundary of a source boundary. Because this is not a geometric operation, the destination and source boundaries will be identical.

Parameters: src The source boundary.

Returns: The boundaries of the destination.

getBounds2D

public final Rectangle2D getBounds2D(Raster src)
Returns the corresponding destination boundary of a source boundary. Because this is not a geometric operation, the destination and source boundaries will be identical.

Parameters: src The source boundary.

Returns: The boundaries of the destination.

getICC_Profiles

public final ICC_Profile[] getICC_Profiles()
Returns the array of ICC_Profiles used to create this Op, or null if the Op was created using ColorSpace arguments.

Returns: The array of ICC_Profiles, or null.

getPoint2D

public final Point2D getPoint2D(Point2D src, Point2D dst)
Returns the corresponding destination point for a source point. Because this is not a geometric operation, the destination and source points will be identical.

Parameters: src The source point. dst The transformed destination point.

Returns: The transformed destination point.

getRenderingHints

public final RenderingHints getRenderingHints()
Returns the rendering hints for this op.

Returns: The rendering hints for this Op, or null.