Package ca.cgjennings.graphics.filters
Class AbstractImagewiseFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractImagewiseFilter
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
- Direct Known Subclasses:
AbstractConvolver
,OilPaintingFilter
public abstract class AbstractImagewiseFilter extends AbstractImageFilter
An abstract base class for image filters that require access to the entire image at once when processing. Filters of this type produce images of the same dimensions as the original.It is assumed that pixels will only be read from the source image and written to the destination image. That is, that pixel values depend only on combinations of the source pixels and not on previously computed destination pixels. This allows filtering to be accelerated automatically by generating blocks of destination pixels in parallel. A filter that does not meet these criteria may return a value of 0 from
workFactor()
to disable the automatic acceleration mechanism.- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description AbstractImagewiseFilter()
-
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.java.awt.image.BufferedImage
filter(java.awt.image.BufferedImage source, java.awt.image.BufferedImage destination)
protected abstract void
filterPixels(int[] srcPixels, int[] dstPixels, int width, int height, int y0, int rows)
Filters a block of rows in the source image, placing the result in the corresponding rows in the destination image.protected float
workFactor()
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.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
-
filter
public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage source, java.awt.image.BufferedImage destination)
This implementation will call
filterPixels(int[], int[], int, int, int, int)
to perform the actual filtering.- Parameters:
source
- the source imagedestination
- the destination image (may benull
)- Returns:
- the destination image
-
filter
public int[] filter(int[] source, int[] destination, int width, int height)
Applies the filter to ARGB pixel data stored in an array. This method can be used during the internal processing of other filters.- Parameters:
source
- the source pixel data in ARGB formatdestination
- the destination in which the filtered should be stored, may benull
width
- the width of the source imageheight
- the height of the source image- Returns:
- the array that holds the destination pixels
-
filterPixels
protected abstract void filterPixels(int[] srcPixels, int[] dstPixels, int width, int height, int y0, int rows)
Filters 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).- 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 filterrows
- the number of rows to filter
-
workFactor
protected float workFactor()
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. 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.
- Returns:
- the approximate amount of work per pixel, relative to simply copying the pixel values
-
-