APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.image

public Class ConvolveOp

extends Object
implements BufferedImageOp, RasterOp
Class Inheritance
All Implemented Interfaces
java.awt.image.RasterOp, java.awt.image.BufferedImageOp
Imports
java.awt.color.ICC_Profile, java.awt.geom.Rectangle2D, .Point2D, java.awt.Rectangle, .RenderingHints, java.lang.annotation.Native, sun.awt.image.ImagingLib

This class implements a convolution from the source to the destination. Convolution using a convolution kernel is a spatial operation that computes the output pixel from an input pixel by multiplying the kernel with the surround of the input pixel. This allows the output pixel to be affected by the immediate neighborhood in a way that can be mathematically specified with a kernel.

This class operates with BufferedImage data in which color components are premultiplied with the alpha component. If the Source BufferedImage has an alpha component, and the color components are not premultiplied with the alpha component, then the data are premultiplied before being convolved. If the Destination has color components which are not premultiplied, then alpha is divided out before storing into the Destination (if alpha is 0, the color components are set to 0). If the Destination has no alpha component, then the resulting alpha is discarded after first dividing it out of the color components.

Rasters are treated as having no alpha channel. If the above treatment of the alpha channel in BufferedImages is not desired, it may be avoided by getting the Raster of a source BufferedImage and using the filter method of this class which works with Rasters.

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

Note that the Source and the Destination may not be the same object.

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

Field Summary

Modifier and TypeField and Description
public static final int
EDGE_NO_OP

Pixels at the edge of the source image are copied to the corresponding pixels in the destination without modification.

public static final int
EDGE_ZERO_FILL

Pixels at the edge of the destination image are set to zero.

pack-priv int
pack-priv RenderingHints
pack-priv Kernel

Constructor Summary

AccessConstructor and Description
public
ConvolveOp(Kernel
the specified Kernel
kernel
,
int
the specified edge condition
edgeCondition
,
RenderingHints
the specified RenderingHints object
hints
)

Constructs a ConvolveOp given a Kernel, an edge condition, and a RenderingHints object (which may be null).

public
ConvolveOp(Kernel
the specified Kernel
kernel
)

Constructs a ConvolveOp given a Kernel.

Method Summary

Modifier and TypeMethod and Description
public BufferedImage

Returns:

a destination BufferedImage with the correct size and number of bands.
createCompatibleDestImage
(BufferedImage
Source image for the filter operation.
src
,
ColorModel
ColorModel of the destination. Can be null.
destCM
)

Implements java.awt.image.BufferedImageOp.createCompatibleDestImage.

Creates a zeroed destination image with the correct size and number of bands.

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.

public final BufferedImage

Returns:

the filtered BufferedImage
filter
(BufferedImage
the source BufferedImage to filter
src
,
BufferedImage
the destination BufferedImage for the filtered src
dst
)

Implements java.awt.image.BufferedImageOp.filter.

Performs a convolution on BufferedImages.

public final WritableRaster

Returns:

the filtered WritableRaster
filter
(Raster
the source Raster to filter
src
,
WritableRaster
the destination WritableRaster for the filtered src
dst
)

Implements java.awt.image.RasterOp.filter.

Performs a convolution on Rasters.

public final Rectangle2D
getBounds2D(BufferedImage src)

Implements java.awt.image.BufferedImageOp.getBounds2D.

Returns the bounding box of the filtered destination image.

public final Rectangle2D
getBounds2D(Raster src)

Implements java.awt.image.RasterOp.getBounds2D.

Returns the bounding box of the filtered destination Raster.

public int

Returns:

the edge condition of this ConvolveOp.
getEdgeCondition
()

Returns the edge condition.

public final Kernel

Returns:

the Kernel of this ConvolveOp.
getKernel
()

Returns the Kernel.

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.

public final RenderingHints
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EDGE_NO_OPback to summary
public static final int EDGE_NO_OP

Pixels at the edge of the source image are copied to the corresponding pixels in the destination without modification.

Annotations
@Native
EDGE_ZERO_FILLback to summary
public static final int EDGE_ZERO_FILL

Pixels at the edge of the destination image are set to zero. This is the default.

Annotations
@Native
edgeHintback to summary
pack-priv int edgeHint
hintsback to summary
pack-priv RenderingHints hints
kernelback to summary
pack-priv Kernel kernel

Constructor Detail

ConvolveOpback to summary
public ConvolveOp(Kernel kernel, int edgeCondition, RenderingHints hints)

Constructs a ConvolveOp given a Kernel, an edge condition, and a RenderingHints object (which may be null).

Parameters
kernel:Kernel

the specified Kernel

edgeCondition:int

the specified edge condition

hints:RenderingHints

the specified RenderingHints object

See Also
Kernel, EDGE_NO_OP, EDGE_ZERO_FILL, java.awt.RenderingHints
ConvolveOpback to summary
public ConvolveOp(Kernel kernel)

Constructs a ConvolveOp given a Kernel. The edge condition will be EDGE_ZERO_FILL.

Parameters
kernel:Kernel

the specified Kernel

See Also
Kernel, EDGE_ZERO_FILL

Method Detail

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. If destCM is null, an appropriate ColorModel will be used.

Parameters
src:BufferedImage

Source image for the filter operation.

destCM:ColorModel

ColorModel of the destination. Can be null.

Returns:BufferedImage

a destination BufferedImage with the correct size and number of bands.

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.

filterback to summary
public final BufferedImage filter(BufferedImage src, BufferedImage dst)

Implements java.awt.image.BufferedImageOp.filter.

Performs a convolution on BufferedImages. Each component of the source image will be convolved (including the alpha component, if present). If the color model in the source image is not the same as that in the destination image, the pixels will be converted in the destination. If the destination image is null, a BufferedImage will be created with the source ColorModel. The IllegalArgumentException may be thrown if the source is the same as the destination.

Parameters
src:BufferedImage

the source BufferedImage to filter

dst:BufferedImage

the destination BufferedImage for the filtered src

Returns:BufferedImage

the filtered BufferedImage

Exceptions
NullPointerException:
if src is null
IllegalArgumentException:
if src equals dst
ImagingOpException:
if src cannot be filtered
filterback to summary
public final WritableRaster filter(Raster src, WritableRaster dst)

Implements java.awt.image.RasterOp.filter.

Performs a convolution on Rasters. Each band of the source Raster will be convolved. The source and destination must have the same number of bands. If the destination Raster is null, a new Raster will be created. The IllegalArgumentException may be thrown if the source is the same as the destination.

Parameters
src:Raster

the source Raster to filter

dst:WritableRaster

the destination WritableRaster for the filtered src

Returns:WritableRaster

the filtered WritableRaster

Exceptions
NullPointerException:
if src is null
ImagingOpException:
  • if src and dst do not have the same number of bands
  • if src cannot be filtered
IllegalArgumentException:
if src equals dst
getBounds2Dback to summary
public final Rectangle2D getBounds2D(BufferedImage src)

Implements java.awt.image.BufferedImageOp.getBounds2D.

Returns the bounding box of the filtered destination image. Since this is not a geometric operation, the bounding box does not change.

getBounds2Dback to summary
public final Rectangle2D getBounds2D(Raster src)

Implements java.awt.image.RasterOp.getBounds2D.

Returns the bounding box of the filtered destination Raster. Since this is not a geometric operation, the bounding box does not change.

getEdgeConditionback to summary
public int getEdgeCondition()

Returns the edge condition.

Returns:int

the edge condition of this ConvolveOp.

See Also
EDGE_NO_OP, EDGE_ZERO_FILL
getKernelback to summary
public final Kernel getKernel()

Returns the Kernel.

Returns:Kernel

the Kernel of this ConvolveOp.

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. Since this is not a geometric operation, the srcPt will equal the dstPt.

getRenderingHintsback to summary
public final RenderingHints getRenderingHints()

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

Returns the rendering hints for this op.