Package com.jhlabs.image
Class ConvolveFilter
- java.lang.Object
-
- com.jhlabs.image.AbstractBufferedImageOp
-
- com.jhlabs.image.ConvolveFilter
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
,java.lang.Cloneable
- Direct Known Subclasses:
AverageFilter
,BlurFilter
,BumpFilter
,GaussianFilter
,SharpenFilter
public class ConvolveFilter extends AbstractBufferedImageOp
A filter which applies a convolution kernel to an image.- Author:
- Jerry Huxtable
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
alpha
Whether to convolve alpha.static int
CLAMP_EDGES
Clamp pixels off the edge to the nearest edge.protected java.awt.image.Kernel
kernel
The convolution kernel.protected boolean
premultiplyAlpha
Whether to promultiply the alpha before convolving.static int
WRAP_EDGES
Wrap pixels off the edge to the opposite edge.static int
ZERO_EDGES
Treat pixels off the edge as zero.
-
Constructor Summary
Constructors Constructor Description ConvolveFilter()
Construct a filter with a null kernel.ConvolveFilter(float[] matrix)
Construct a filter with the given 3x3 kernel.ConvolveFilter(int rows, int cols, float[] matrix)
Construct a filter with the given kernel.ConvolveFilter(java.awt.image.Kernel kernel)
Construct a filter with the given 3x3 kernel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
convolve(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve a block of pixels.static void
convolve(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, int edgeAction)
Convolve a block of pixels.static void
convolveH(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a kernel consisting of one row.static void
convolveHV(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a 2D kernel.static void
convolveV(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a kernel consisting of one column.java.awt.image.BufferedImage
createCompatibleDestImage(java.awt.image.BufferedImage src, java.awt.image.ColorModel dstCM)
java.awt.image.BufferedImage
filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
java.awt.geom.Rectangle2D
getBounds2D(java.awt.image.BufferedImage src)
int
getEdgeAction()
Get the action to perfomr for pixels off the image edges.java.awt.image.Kernel
getKernel()
Get the convolution kernel.java.awt.geom.Point2D
getPoint2D(java.awt.geom.Point2D srcPt, java.awt.geom.Point2D dstPt)
boolean
getPremultiplyAlpha()
Get whether to premultiply the alpha channel.java.awt.RenderingHints
getRenderingHints()
boolean
getUseAlpha()
Get whether to convolve the alpha channel.void
setEdgeAction(int edgeAction)
Set the action to perfomr for pixels off the image edges.void
setKernel(java.awt.image.Kernel kernel)
Set the convolution kernel.void
setPremultiplyAlpha(boolean premultiplyAlpha)
Set whether to premultiply the alpha channel.void
setUseAlpha(boolean useAlpha)
Set whether to convolve the alpha channel.java.lang.String
toString()
-
Methods inherited from class com.jhlabs.image.AbstractBufferedImageOp
clone, getRGB, setRGB, stringToColor
-
-
-
-
Field Detail
-
ZERO_EDGES
public static int ZERO_EDGES
Treat pixels off the edge as zero.
-
CLAMP_EDGES
public static int CLAMP_EDGES
Clamp pixels off the edge to the nearest edge.
-
WRAP_EDGES
public static int WRAP_EDGES
Wrap pixels off the edge to the opposite edge.
-
kernel
protected java.awt.image.Kernel kernel
The convolution kernel.
-
alpha
protected boolean alpha
Whether to convolve alpha.
-
premultiplyAlpha
protected boolean premultiplyAlpha
Whether to promultiply the alpha before convolving.
-
-
Constructor Detail
-
ConvolveFilter
public ConvolveFilter()
Construct a filter with a null kernel. This is only useful if you're going to change the kernel later on.
-
ConvolveFilter
public ConvolveFilter(float[] matrix)
Construct a filter with the given 3x3 kernel.- Parameters:
matrix
- an array of 9 floats containing the kernel
-
ConvolveFilter
public ConvolveFilter(int rows, int cols, float[] matrix)
Construct a filter with the given kernel.- Parameters:
rows
- the number of rows in the kernelcols
- the number of columns in the kernelmatrix
- an array of rows*cols floats containing the kernel
-
ConvolveFilter
public ConvolveFilter(java.awt.image.Kernel kernel)
Construct a filter with the given 3x3 kernel.- Parameters:
kernel
- the convolution kernel
-
-
Method Detail
-
setKernel
public void setKernel(java.awt.image.Kernel kernel)
Set the convolution kernel.- Parameters:
kernel
- the kernel- See Also:
getKernel()
-
getKernel
public java.awt.image.Kernel getKernel()
Get the convolution kernel.- Returns:
- the kernel
- See Also:
setKernel(java.awt.image.Kernel)
-
setEdgeAction
public void setEdgeAction(int edgeAction)
Set the action to perfomr for pixels off the image edges.- Parameters:
edgeAction
- the action- See Also:
getEdgeAction()
-
getEdgeAction
public int getEdgeAction()
Get the action to perfomr for pixels off the image edges.- Returns:
- the action
- See Also:
setEdgeAction(int)
-
setUseAlpha
public void setUseAlpha(boolean useAlpha)
Set whether to convolve the alpha channel.- Parameters:
useAlpha
- true to convolve the alpha- See Also:
getUseAlpha()
-
getUseAlpha
public boolean getUseAlpha()
Get whether to convolve the alpha channel.- Returns:
- true to convolve the alpha
- See Also:
setUseAlpha(boolean)
-
setPremultiplyAlpha
public void setPremultiplyAlpha(boolean premultiplyAlpha)
Set whether to premultiply the alpha channel.- Parameters:
premultiplyAlpha
- true to premultiply the alpha- See Also:
getPremultiplyAlpha()
-
getPremultiplyAlpha
public boolean getPremultiplyAlpha()
Get whether to premultiply the alpha channel.- Returns:
- true to premultiply the alpha
- See Also:
setPremultiplyAlpha(boolean)
-
filter
public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dst)
-
createCompatibleDestImage
public java.awt.image.BufferedImage createCompatibleDestImage(java.awt.image.BufferedImage src, java.awt.image.ColorModel dstCM)
- Specified by:
createCompatibleDestImage
in interfacejava.awt.image.BufferedImageOp
- Overrides:
createCompatibleDestImage
in classAbstractBufferedImageOp
-
getBounds2D
public java.awt.geom.Rectangle2D getBounds2D(java.awt.image.BufferedImage src)
- Specified by:
getBounds2D
in interfacejava.awt.image.BufferedImageOp
- Overrides:
getBounds2D
in classAbstractBufferedImageOp
-
getPoint2D
public java.awt.geom.Point2D getPoint2D(java.awt.geom.Point2D srcPt, java.awt.geom.Point2D dstPt)
- Specified by:
getPoint2D
in interfacejava.awt.image.BufferedImageOp
- Overrides:
getPoint2D
in classAbstractBufferedImageOp
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
- Specified by:
getRenderingHints
in interfacejava.awt.image.BufferedImageOp
- Overrides:
getRenderingHints
in classAbstractBufferedImageOp
-
convolve
public static void convolve(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, int edgeAction)
Convolve a block of pixels.- Parameters:
kernel
- the kernelinPixels
- the input pixelsoutPixels
- the output pixelswidth
- the widthheight
- the heightedgeAction
- what to do at the edges
-
convolve
public static void convolve(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve a block of pixels.- Parameters:
kernel
- the kernelinPixels
- the input pixelsoutPixels
- the output pixelswidth
- the widthheight
- the heightalpha
- include alpha channeledgeAction
- what to do at the edges
-
convolveHV
public static void convolveHV(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a 2D kernel.- Parameters:
kernel
- the kernelinPixels
- the input pixelsoutPixels
- the output pixelswidth
- the widthheight
- the heightalpha
- include alpha channeledgeAction
- what to do at the edges
-
convolveH
public static void convolveH(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a kernel consisting of one row.- Parameters:
kernel
- the kernelinPixels
- the input pixelsoutPixels
- the output pixelswidth
- the widthheight
- the heightalpha
- include alpha channeledgeAction
- what to do at the edges
-
convolveV
public static void convolveV(java.awt.image.Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a kernel consisting of one column.- Parameters:
kernel
- the kernelinPixels
- the input pixelsoutPixels
- the output pixelswidth
- the widthheight
- the heightalpha
- include alpha channeledgeAction
- what to do at the edges
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-