java.awt.image

Class ColorConvertOp

Implemented Interfaces:
BufferedImageOp, RasterOp

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(RenderingHints hints)
Convert from source color space to destination color space.
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.

Method Summary

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.
WritableRaster
createCompatibleDestRaster(Raster src)
Creates a new WritableRaster with the size equal to the source and the correct number of bands.
BufferedImage
filter(BufferedImage src, BufferedImage dst)
Converts the source image using the conversion path specified in the constructor.
WritableRaster
filter(Raster src, WritableRaster dest)
Converts the source raster using the conversion path specified in the constructor.
Rectangle2D
getBounds2D(BufferedImage src)
Returns the corresponding destination boundary of a source boundary.
Rectangle2D
getBounds2D(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.
Point2D
getPoint2D(Point2D src, Point2D dst)
Returns the corresponding destination point for a source point.
RenderingHints
getRenderingHints()
Returns the rendering hints for this op.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

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).

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.

Method Details

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.
Specified by:
createCompatibleDestImage in interface BufferedImageOp
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.
Specified by:
createCompatibleDestRaster in interface RasterOp
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.
Specified by:
filter in interface BufferedImageOp
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.
Specified by:
filter in interface RasterOp
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.
Specified by:
getBounds2D in interface BufferedImageOp
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.
Specified by:
getBounds2D in interface RasterOp
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.
Specified by:
getPoint2D in interface BufferedImageOp
getPoint2D in interface RasterOp
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.
Specified by:
getRenderingHints in interface BufferedImageOp
getRenderingHints in interface RasterOp
Returns:
The rendering hints for this Op, or null.

ColorConvertOp.java -- Copyright (C) 2004, 2006 Free Software Foundation This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.