Class AbstractConvolver
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractImagewiseFilter
-
- ca.cgjennings.graphics.filters.AbstractConvolver
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
- Direct Known Subclasses:
ConvolveFilter,GaussianBlurFilter,SharpenFilter
public abstract class AbstractConvolver extends AbstractImagewiseFilter
An abstract base class for filters that perform convolutions. Concrete subclasses are responsible for supplying the convolution kernel(s) by implementinggetKernels(). (Separable convolutions can be implemented by returning a pair of kernels.)Additional methods modify the behaviour of the convolution. They have default implementations that return the following values:
getEdgeHandling()determines how input pixels that fall off the edge of the source image are handled. The base class returnsEdgeHandling.REPEAT.isAlphaPremultiplied()determines whether the alpha channel is premultiplied. The default istrue. Subclasses may choose to override this if they are calling the integer array filtering method with pixel data that is already premultiplied.isAlphaFiltered()determines whether the alpha channel is retained after filtering. The default istrue. Iffalse, the alpha channel will be completely opaque after filtering.In-place filtering: Unless otherwise noted, filters based on this class support in-place filtering (the source and destination images can be the same).
- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description AbstractConvolver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int[]filter(int[] source, int[] destination, int width, int height)Applies the filter to ARGB pixel data stored in an array.protected voidfilterPixels(int[] srcPixels, int[] dstPixels, int width, int height, int y0, int rowsToFilter)Filters a block of rows in the source image, placing the result in the corresponding rows in the destination image.EdgeHandlinggetEdgeHandling()Returns the edge handling mode used by the convolution.protected abstract java.awt.image.Kernel[]getKernels()Returns the convolution kernel(s) that should be applied to execute this filter.booleanisAlphaFiltered()Returnstrueif the alpha channel is filtered.booleanisAlphaPremultiplied()Returnstrueif images with an alpha channel will automatically be converted to a premultiplied format during the convolution, and converted back afterward.protected floatworkFactor()Returns a factor representing the amount of work performed by this filter relative to a filter that simply copies the source image by reading and writing each pixel.-
Methods inherited from class ca.cgjennings.graphics.filters.AbstractImagewiseFilter
filter
-
Methods inherited from class ca.cgjennings.graphics.filters.AbstractImageFilter
clamp, clamp, clamp, clampBoth, createCompatibleDestImage, fA, fB, fG, fR, getARGB, getARGB, getARGBSynch, getBounds2D, getPoint2D, getRenderingHints, iA, iB, iG, iR, setARGB, setARGB, setARGBSynch
-
-
-
-
Method Detail
-
getEdgeHandling
public EdgeHandling getEdgeHandling()
Returns the edge handling mode used by the convolution.- Returns:
- how the filter handles pixels that fall of the image edge
-
isAlphaPremultiplied
public boolean isAlphaPremultiplied()
Returnstrueif images with an alpha channel will automatically be converted to a premultiplied format during the convolution, and converted back afterward.- Returns:
trueif images are premultiplied automatically
-
isAlphaFiltered
public boolean isAlphaFiltered()
Returnstrueif the alpha channel is filtered. If this returnsfalse, the alpha channel is set to 255. For more complex channel value manipulation, seeChannelSwapFilter.- Returns:
trueif the alpha channel is processed by the filter
-
getKernels
protected abstract java.awt.image.Kernel[] getKernels()
Returns the convolution kernel(s) that should be applied to execute this filter. Typically, array is either length one (non-separable) or length two (separable).- Returns:
- an array of non-
nullconvolution kernels
-
filter
public int[] filter(int[] source, int[] destination, int width, int height)Description copied from class:AbstractImagewiseFilterApplies the filter to ARGB pixel data stored in an array. This method can be used during the internal processing of other filters.- Overrides:
filterin classAbstractImagewiseFilter- Parameters:
source- the source pixel data in ARGB formatdestination- the destination in which the filtered should be stored, may benullwidth- the width of the source imageheight- the height of the source image- Returns:
- the array that holds the destination pixels
-
filterPixels
protected void filterPixels(int[] srcPixels, int[] dstPixels, int width, int height, int y0, int rowsToFilter)Description copied from class:AbstractImagewiseFilterFilters a block of rows in the source image, placing the result in the corresponding rows in the destination image. The block of rows to be filtered runs from y0 to y0 + rows-1 (inclusive).- Specified by:
filterPixelsin classAbstractImagewiseFilter- Parameters:
srcPixels- the pixel data for the source imagedstPixels- the destination for output pixelswidth- the width of the imageheight- the height of the imagey0- the index of the first row to filterrowsToFilter- the number of rows to filter
-
workFactor
protected float workFactor()
Description copied from class:AbstractImagewiseFilterReturns a factor representing the amount of work performed by this filter relative to a filter that simply copies the source image by reading and writing each pixel. For example, a filter that implemented a 3x3 convolution might return the value 9. The work factor value helps determine when an image should be processed in parallel. (There is significant overhead involved in running a filter in parallel, so it is only worth doing if the image is relatively large or the amount of processing per pixel is relatively high.)Note: The work factor may vary depending on the current filter settings.
- Overrides:
workFactorin classAbstractImagewiseFilter- Returns:
- the approximate amount of work per pixel, relative to simply copying the pixel values
-
-