Class ColorConvertOp
- All Implemented Interfaces:
BufferedImageOp, RasterOp
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:
-
Constructor Summary
ConstructorsConstructorDescriptionColorConvertOp(ColorSpace srcCspace, ColorSpace dstCspace, RenderingHints hints) Constructs a new ColorConvertOp from two ColorSpace objects.ColorConvertOp(ColorSpace cspace, RenderingHints hints) Constructs a new ColorConvertOp from a ColorSpace object.ColorConvertOp(ICC_Profile[] profiles, RenderingHints hints) Constructs a new ColorConvertOp from an array of ICC_Profiles.ColorConvertOp(RenderingHints hints) Constructs a new ColorConvertOp which will convert from a source color space to a destination color space. -
Method Summary
Modifier and TypeMethodDescriptioncreateCompatibleDestImage(BufferedImage src, ColorModel destCM) Creates a zeroed destination image with the correct size and number of bands, given this source.Creates a zeroed destination Raster with the correct size and number of bands, given this source.final BufferedImagefilter(BufferedImage src, BufferedImage dest) ColorConverts the source BufferedImage.final WritableRasterfilter(Raster src, WritableRaster dest) ColorConverts the image data in the source Raster.final Rectangle2DgetBounds2D(BufferedImage src) Returns the bounding box of the destination, given this source.final Rectangle2DgetBounds2D(Raster src) Returns the bounding box of the destination, given this source.final ICC_Profile[]Returns the array of ICC_Profiles used to construct this ColorConvertOp.final Point2DgetPoint2D(Point2D srcPt, Point2D dstPt) Returns the location of the destination point given a point in the source.final RenderingHintsReturns the rendering hints used by this op.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
ColorConvertOp
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- theRenderingHintsobject used to control the color conversion, ornull
-
ColorConvertOp
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 thefiltermethod 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- defines the destinationColorSpaceor an intermediateColorSpacehints- theRenderingHintsobject used to control the color conversion, ornull- Throws:
NullPointerException- if cspace is null
-
ColorConvertOp
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- the sourceColorSpacedstCspace- the destinationColorSpacehints- theRenderingHintsobject used to control the color conversion, ornull- Throws:
NullPointerException- if either srcCspace or dstCspace is null
-
ColorConvertOp
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- the array ofICC_Profileobjectshints- theRenderingHintsobject used to control the color conversion, ornull- Throws:
IllegalArgumentException- when the profile sequence does not specify a well-defined color conversionNullPointerException- if profiles is null
-
-
Method Details
-
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:
- the array of
ICC_Profileobjects of thisColorConvertOp, ornullif thisColorConvertOpwas not constructed with an array ofICC_Profileobjects.
-
filter
ColorConverts the source BufferedImage. If the destination image is null, a BufferedImage will be created with an appropriate ColorModel.- Specified by:
filterin interfaceBufferedImageOp- Parameters:
src- the sourceBufferedImageto be converteddest- the destinationBufferedImage, ornull- Returns:
destcolor converted fromsrcor a new, convertedBufferedImageifdestisnull- Throws:
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.
-
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.- Specified by:
filterin interfaceRasterOp- Parameters:
src- the sourceRasterto be converteddest- the destinationWritableRaster, ornull- Returns:
destcolor converted fromsrcor a new, convertedWritableRasterifdestisnull- Throws:
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.
-
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.- Specified by:
getBounds2Din interfaceBufferedImageOp- Parameters:
src- the sourceBufferedImage- Returns:
- a
Rectangle2Dthat is the bounding box of the destination, given the specifiedsrc
-
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.- Specified by:
getBounds2Din interfaceRasterOp- Parameters:
src- the sourceRaster- Returns:
- a
Rectangle2Dthat is the bounding box of the destination, given the specifiedsrc
-
createCompatibleDestImage
Creates a zeroed destination image with the correct size and number of bands, given this source.- Specified by:
createCompatibleDestImagein interfaceBufferedImageOp- Parameters:
src- Source image for the filter operation.destCM- ColorModel of the destination. If null, an appropriate ColorModel will be used.- Returns:
- a
BufferedImagewith the correct size and number of bands from the specifiedsrc. - Throws:
IllegalArgumentException- ifdestCMisnulland thisColorConvertOpwas created without anyICC_ProfileorColorSpacedefined for the destination
-
createCompatibleDestRaster
Creates a zeroed destination Raster with the correct size and number of bands, given this source.- Specified by:
createCompatibleDestRasterin interfaceRasterOp- Parameters:
src- the specifiedRaster- Returns:
- a
WritableRasterwith the correct size and number of bands from the specifiedsrc - Throws:
IllegalArgumentException- if thisColorConvertOpwas created without sufficient information to define thedstandsrccolor spaces
-
getPoint2D
Returns the location of the destination point given a point in the source. IfdstPtis 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.- Specified by:
getPoint2Din interfaceBufferedImageOp- Specified by:
getPoint2Din interfaceRasterOp- Parameters:
srcPt- the specified sourcePoint2DdstPt- the destinationPoint2D- Returns:
dstPtafter setting its location to be the same assrcPt
-
getRenderingHints
Returns the rendering hints used by this op.- Specified by:
getRenderingHintsin interfaceBufferedImageOp- Specified by:
getRenderingHintsin interfaceRasterOp- Returns:
- the
RenderingHintsobject of thisColorConvertOp
-