Top Description Fields Constructors Methods
java.awt.image

public Class ColorConvertOp

extends Object
implements BufferedImageOp, RasterOp
Class Inheritance
All Implemented Interfaces
java.awt.image.RasterOp, java.awt.image.BufferedImageOp
Imports
java.awt.Graphics2D, .Point, .RenderingHints, java.awt.color.ColorSpace, .ICC_ColorSpace, .ICC_Profile, java.awt.geom.Point2D, .Rectangle2D, sun.java2d.cmm.CMSManager, .ColorTransform, .PCMM

This class performs a pixel-by-pixel color conversion of the data in the source image. The resulting color values are scaled to the precision of the destination image. Color conversion can be specified via an array of ColorSpace objects or an array of ICC_Profile objects.

If the source is a BufferedImage with premultiplied alpha, the color components are divided by the alpha component before color conversion. If the destination is a BufferedImage with premultiplied alpha, the color components are multiplied by the alpha component after conversion. Rasters are treated as having no alpha channel, i.e. all bands are color bands.

If a RenderingHints object is specified in the constructor, the color rendering hint and the dithering hint may be used to control color conversion.

Note that Source and Destination may be the same object.

See Also
java.awt.RenderingHints#KEY_COLOR_RENDERING, java.awt.RenderingHints#KEY_DITHERING

Field Summary

Modifier and TypeField and Description
pack-priv ColorSpace[]
pack-priv float[]
pack-priv float[]
pack-priv boolean
pack-priv RenderingHints
pack-priv ICC_Profile[]
pack-priv float[]
pack-priv float[]
pack-priv ICC_Profile
pack-priv ColorTransform
pack-priv ICC_Profile
pack-priv ColorTransform

Constructor Summary

AccessConstructor and Description
public
ColorConvertOp(RenderingHints
the RenderingHints object used to control the color conversion, or null
hints
)

Constructs a new ColorConvertOp which will convert from a source color space to a destination color space.

public
ColorConvertOp(ColorSpace
defines the destination ColorSpace or an intermediate ColorSpace
cspace
,
RenderingHints
the RenderingHints object used to control the color conversion, or null
hints
)

Constructs a new ColorConvertOp from a ColorSpace object.

public
ColorConvertOp(ColorSpace
the source ColorSpace
srcCspace
,
ColorSpace
the destination ColorSpace
dstCspace
,
RenderingHints
the RenderingHints object used to control the color conversion, or null
hints
)

Constructs a new ColorConvertOp from two ColorSpace objects.

public
ColorConvertOp(ICC_Profile[]
the array of ICC_Profile objects
profiles
,
RenderingHints
the RenderingHints object used to control the color conversion, or null
hints
)

Constructs a new ColorConvertOp from an array of ICC_Profiles.

Method Summary

Modifier and TypeMethod and Description
private static ColorSpace
public BufferedImage

Returns:

a BufferedImage with the correct size and number of bands from the specified src.
createCompatibleDestImage
(BufferedImage
Source image for the filter operation.
src
,
ColorModel
ColorModel of the destination. If null, an appropriate ColorModel will be used.
destCM
)

Implements java.awt.image.BufferedImageOp.createCompatibleDestImage.

Creates a zeroed destination image with the correct size and number of bands, given this source.
private BufferedImage
public WritableRaster

Returns:

a WritableRaster with the correct size and number of bands from the specified src
createCompatibleDestRaster
(Raster
the specified Raster
src
)

Implements java.awt.image.RasterOp.createCompatibleDestRaster.

Creates a zeroed destination Raster with the correct size and number of bands, given this source.
public final BufferedImage

Returns:

dest color converted from src or a new, converted BufferedImage if dest is null
filter
(BufferedImage
the source BufferedImage to be converted
src
,
BufferedImage
the destination BufferedImage, or null
dest
)

Implements java.awt.image.BufferedImageOp.filter.

ColorConverts the source BufferedImage.
public final WritableRaster

Returns:

dest color converted from src or a new, converted WritableRaster if dest is null
filter
(Raster
the source Raster to be converted
src
,
WritableRaster
the destination WritableRaster, or null
dest
)

Implements java.awt.image.RasterOp.filter.

ColorConverts the image data in the source Raster.
public final Rectangle2D

Returns:

a Rectangle2D that is the bounding box of the destination, given the specified src
getBounds2D
(BufferedImage
the source BufferedImage
src
)

Implements java.awt.image.BufferedImageOp.getBounds2D.

Returns the bounding box of the destination, given this source.
public final Rectangle2D

Returns:

a Rectangle2D that is the bounding box of the destination, given the specified src
getBounds2D
(Raster
the source Raster
src
)

Implements java.awt.image.RasterOp.getBounds2D.

Returns the bounding box of the destination, given this source.
public final ICC_Profile[]

Returns:

the array of ICC_Profile objects of this ColorConvertOp, or null if this ColorConvertOp was not constructed with an array of ICC_Profile objects.
getICC_Profiles
()

Returns the array of ICC_Profiles used to construct this ColorConvertOp.

private void
private void
public final Point2D

Returns:

dstPt after setting its location to be the same as srcPt
getPoint2D
(Point2D
the specified source Point2D
srcPt
,
Point2D
the destination Point2D
dstPt
)

Implements java.awt.image.BufferedImageOp.getPoint2D, java.awt.image.RasterOp.getPoint2D.

Returns the location of the destination point given a point in the source.
public final RenderingHints

Returns:

the RenderingHints object of this ColorConvertOp
getRenderingHints
()

Implements java.awt.image.BufferedImageOp.getRenderingHints, java.awt.image.RasterOp.getRenderingHints.

Returns the rendering hints used by this op.
private int
getRenderingIntent(ICC_Profile profile)

Returns the RenderingIntent from the specified ICC Profile.

private BufferedImage
ICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dest, ColorSpace destColorSpace)

private BufferedImage
nonICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dst, ColorSpace dstColorSpace)

private WritableRaster
private void
setMinMax(int type, int nc, float[] minVals, float[] maxVals)

private void
updateBITransform(ICC_Profile srcProfile, ICC_Profile destProfile)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CSListback to summary
pack-priv ColorSpace[] CSList
dstMaxValsback to summary
pack-priv float[] dstMaxVals
dstMinValsback to summary
pack-priv float[] dstMinVals
gotProfilesback to summary
pack-priv boolean gotProfiles
hintsback to summary
pack-priv RenderingHints hints
profileListback to summary
pack-priv ICC_Profile[] profileList
srcMaxValsback to summary
pack-priv float[] srcMaxVals
srcMinValsback to summary
pack-priv float[] srcMinVals
thisDestProfileback to summary
pack-priv ICC_Profile thisDestProfile
thisRasterTransformback to summary
pack-priv ColorTransform thisRasterTransform
thisSrcProfileback to summary
pack-priv ICC_Profile thisSrcProfile
thisTransformback to summary
pack-priv ColorTransform thisTransform

Constructor Detail

ColorConvertOpback to summary
public ColorConvertOp(RenderingHints hints)

Constructs a new ColorConvertOp which will convert from a source color space to a destination color space. The RenderingHints argument may be null. This Op can be used only with BufferedImages, and will convert directly from the ColorSpace of the source image to that of the destination. The destination argument of the filter method cannot be specified as null.

Parameters
hints:RenderingHints

the RenderingHints object used to control the color conversion, or null

ColorConvertOpback to summary
public ColorConvertOp(ColorSpace cspace, RenderingHints hints)

Constructs a new ColorConvertOp from a ColorSpace object. The RenderingHints argument may be null. This Op can be used only with BufferedImages, and is primarily useful when the filter method is invoked with a destination argument of null. In that case, the ColorSpace defines the destination color space for the destination created by the filter method. Otherwise, the ColorSpace defines an intermediate space to which the source is converted before being converted to the destination space.

Parameters
cspace:ColorSpace

defines the destination ColorSpace or an intermediate ColorSpace

hints:RenderingHints

the RenderingHints object used to control the color conversion, or null

Exceptions
NullPointerException:
if cspace is null
ColorConvertOpback to summary
public ColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, RenderingHints hints)

Constructs a new ColorConvertOp from two ColorSpace objects. The RenderingHints argument may be null. This Op is primarily useful for calling the filter method on Rasters, in which case the two ColorSpaces define the operation to be performed on the Rasters. In that case, the number of bands in the source Raster must match the number of components in srcCspace, and the number of bands in the destination Raster must match the number of components in dstCspace. For BufferedImages, the two ColorSpaces define intermediate spaces through which the source is converted before being converted to the destination space.

Parameters
srcCspace:ColorSpace

the source ColorSpace

dstCspace:ColorSpace

the destination ColorSpace

hints:RenderingHints

the RenderingHints object used to control the color conversion, or null

Exceptions
NullPointerException:
if either srcCspace or dstCspace is null
ColorConvertOpback to summary
public ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints)

Constructs a new ColorConvertOp from an array of ICC_Profiles. The RenderingHints argument may be null. The sequence of profiles may include profiles that represent color spaces, profiles that represent effects, etc. If the whole sequence does not represent a well-defined color conversion, an exception is thrown.

For BufferedImages, if the ColorSpace of the source BufferedImage does not match the requirements of the first profile in the array, the first conversion is to an appropriate ColorSpace. If the requirements of the last profile in the array are not met by the ColorSpace of the destination BufferedImage, the last conversion is to the destination's ColorSpace.

For Rasters, the number of bands in the source Raster must match the requirements of the first profile in the array, and the number of bands in the destination Raster must match the requirements of the last profile in the array. The array must have at least two elements or calling the filter method for Rasters will throw an IllegalArgumentException.

Parameters
profiles:ICC_Profile[]

the array of ICC_Profile objects

hints:RenderingHints

the RenderingHints object used to control the color conversion, or null

Exceptions
IllegalArgumentException:
when the profile sequence does not specify a well-defined color conversion
NullPointerException:
if profiles is null

Method Detail

createCompatibleColorSpaceback to summary
private static ColorSpace createCompatibleColorSpace(ICC_Profile profile)
createCompatibleDestImageback to summary
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM)

Implements java.awt.image.BufferedImageOp.createCompatibleDestImage.

Creates a zeroed destination image with the correct size and number of bands, given this source.

Parameters
src:BufferedImage

Source image for the filter operation.

destCM:ColorModel

ColorModel of the destination. If null, an appropriate ColorModel will be used.

Returns:BufferedImage

a BufferedImage with the correct size and number of bands from the specified src.

Exceptions
IllegalArgumentException:
if destCM is null and this ColorConvertOp was created without any ICC_Profile or ColorSpace defined for the destination
createCompatibleDestImageback to summary
private BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM, ColorSpace destCS)
createCompatibleDestRasterback to summary
public WritableRaster createCompatibleDestRaster(Raster src)

Implements java.awt.image.RasterOp.createCompatibleDestRaster.

Creates a zeroed destination Raster with the correct size and number of bands, given this source.

Parameters
src:Raster

the specified Raster

Returns:WritableRaster

a WritableRaster with the correct size and number of bands from the specified src

Exceptions
IllegalArgumentException:
if this ColorConvertOp was created without sufficient information to define the dst and src color spaces
filterback to summary
public final BufferedImage filter(BufferedImage src, BufferedImage dest)

Implements java.awt.image.BufferedImageOp.filter.

ColorConverts the source BufferedImage. If the destination image is null, a BufferedImage will be created with an appropriate ColorModel.

Parameters
src:BufferedImage

the source BufferedImage to be converted

dest:BufferedImage

the destination BufferedImage, or null

Returns:BufferedImage

dest color converted from src or a new, converted BufferedImage if dest is null

Exceptions
IllegalArgumentException:
if dest is null and this op was constructed using the constructor which takes only a RenderingHints argument, since the operation is ill defined.
filterback to summary
public final WritableRaster filter(Raster src, WritableRaster dest)

Implements java.awt.image.RasterOp.filter.

ColorConverts the image data in the source Raster. If the destination Raster is null, a new Raster will be created. The number of bands in the source and destination Rasters must meet the requirements explained above. The constructor used to create this ColorConvertOp must have provided enough information to define both source and destination color spaces. See above. Otherwise, an exception is thrown.

Parameters
src:Raster

the source Raster to be converted

dest:WritableRaster

the destination WritableRaster, or null

Returns:WritableRaster

dest color converted from src or a new, converted WritableRaster if dest is null

Exceptions
IllegalArgumentException:
if the number of source or destination bands is incorrect, the source or destination color spaces are undefined, or this op was constructed with one of the constructors that applies only to operations on BufferedImages.
getBounds2Dback to summary
public final Rectangle2D getBounds2D(BufferedImage src)

Implements java.awt.image.BufferedImageOp.getBounds2D.

Returns the bounding box of the destination, given this source. Note that this will be the same as the bounding box of the source.

Parameters
src:BufferedImage

the source BufferedImage

Returns:Rectangle2D

a Rectangle2D that is the bounding box of the destination, given the specified src

getBounds2Dback to summary
public final Rectangle2D getBounds2D(Raster src)

Implements java.awt.image.RasterOp.getBounds2D.

Returns the bounding box of the destination, given this source. Note that this will be the same as the bounding box of the source.

Parameters
src:Raster

the source Raster

Returns:Rectangle2D

a Rectangle2D that is the bounding box of the destination, given the specified src

getICC_Profilesback to summary
public final ICC_Profile[] getICC_Profiles()

Returns the array of ICC_Profiles used to construct this ColorConvertOp. Returns null if the ColorConvertOp was not constructed from such an array.

Returns:ICC_Profile[]

the array of ICC_Profile objects of this ColorConvertOp, or null if this ColorConvertOp was not constructed with an array of ICC_Profile objects.

getMinMaxValsFromColorSpacesback to summary
private void getMinMaxValsFromColorSpaces(ColorSpace srcCspace, ColorSpace dstCspace)
getMinMaxValsFromProfilesback to summary
private void getMinMaxValsFromProfiles(ICC_Profile srcProfile, ICC_Profile dstProfile)
getPoint2Dback to summary
public final Point2D getPoint2D(Point2D srcPt, Point2D dstPt)

Implements java.awt.image.BufferedImageOp.getPoint2D, java.awt.image.RasterOp.getPoint2D.

Returns the location of the destination point given a point in the source. If dstPt is non-null, it will be used to hold the return value. Note that for this class, the destination point will be the same as the source point.

Parameters
srcPt:Point2D

the specified source Point2D

dstPt:Point2D

the destination Point2D

Returns:Point2D

dstPt after setting its location to be the same as srcPt

getRenderingHintsback to summary
public final RenderingHints getRenderingHints()

Implements java.awt.image.BufferedImageOp.getRenderingHints, java.awt.image.RasterOp.getRenderingHints.

Returns the rendering hints used by this op.

Returns:RenderingHints

the RenderingHints object of this ColorConvertOp

getRenderingIntentback to summary
private int getRenderingIntent(ICC_Profile profile)

Returns the RenderingIntent from the specified ICC Profile.

ICCBIFilterback to summary
private BufferedImage ICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dest, ColorSpace destColorSpace)
nonICCBIFilterback to summary
private BufferedImage nonICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dst, ColorSpace dstColorSpace)
nonICCRasterFilterback to summary
private WritableRaster nonICCRasterFilter(Raster src, WritableRaster dst)
setMinMaxback to summary
private void setMinMax(int type, int nc, float[] minVals, float[] maxVals)
updateBITransformback to summary
private void updateBITransform(ICC_Profile srcProfile, ICC_Profile destProfile)