Package ca.cgjennings.graphics.filters
Class CompoundPixelwiseFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
-
- ca.cgjennings.graphics.filters.CompoundPixelwiseFilter
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
public final class CompoundPixelwiseFilter extends AbstractPixelwiseFilter
A filter that can apply multipleAbstractPixelwiseFilter
s in sequence. Using this filter to combine multiple filters is faster than applying each filter in sequence because it avoids the overhead of unpacking and repacking the image data multiple times.In-place filtering: This class supports in-place filtering (the source and destination images may be the same).
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description CompoundPixelwiseFilter()
Creates a new compound filter with an empty filter list.CompoundPixelwiseFilter(AbstractPixelwiseFilter... filters)
Creates a new compound filter with the specified filter list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendFilter(AbstractPixelwiseFilter filter)
Appends a new filter to the current filter list, replacing the existing list.void
filterPixels(int[] argb, int start, int end)
This method is called with a block of ARGB values to be filtered.AbstractPixelwiseFilter
getFilter(int index)
Returns the filter at the specified index in the list of filters.AbstractPixelwiseFilter[]
getFilters()
Returns a copy of the filter list as an array.int
getSize()
Returns the number of filters that will be applied by this compound filter.void
setFilters(AbstractPixelwiseFilter... filters)
Sets the filters to be applied by this compound filter.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.AbstractPixelwiseFilter
filter, filter, filterPixel
-
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
-
-
-
-
Constructor Detail
-
CompoundPixelwiseFilter
public CompoundPixelwiseFilter()
Creates a new compound filter with an empty filter list. If the list is not changed, this filter will have the same effect as aCloneFilter
.
-
CompoundPixelwiseFilter
public CompoundPixelwiseFilter(AbstractPixelwiseFilter... filters)
Creates a new compound filter with the specified filter list.- Parameters:
filters
- an array of filters to apply in sequence
-
-
Method Detail
-
getFilters
public AbstractPixelwiseFilter[] getFilters()
Returns a copy of the filter list as an array.- Returns:
- the filters applied by this compound filter
-
setFilters
public void setFilters(AbstractPixelwiseFilter... filters)
Sets the filters to be applied by this compound filter.- Parameters:
filters
- an array of filters to apply in sequence
-
appendFilter
public void appendFilter(AbstractPixelwiseFilter filter)
Appends a new filter to the current filter list, replacing the existing list.- Parameters:
filter
- the new filter to append
-
getFilter
public AbstractPixelwiseFilter getFilter(int index)
Returns the filter at the specified index in the list of filters.- Parameters:
index
- the index in the filter list, from 0 togetSize()
-1.- Returns:
- the filter at the specified index
-
getSize
public int getSize()
Returns the number of filters that will be applied by this compound filter.- Returns:
- the number of filters in the list
-
filterPixels
public void filterPixels(int[] argb, int start, int end)
Description copied from class:AbstractPixelwiseFilter
This method is called with a block of ARGB values to be filtered. Subclasses must override this method to implement the actual filtering algorithm by replacing each pixel value in the rangeargb[start] ... argb[end-1]
with the filtered value.- Specified by:
filterPixels
in classAbstractPixelwiseFilter
- Parameters:
argb
- an array of pixel data to filterstart
- the index of the first pixel to filterend
- the index of the last pixel to filter, plus one
-
workFactor
protected float workFactor()
Description copied from class:AbstractPixelwiseFilter
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.
- Overrides:
workFactor
in classAbstractPixelwiseFilter
- Returns:
- the approximate amount of work per pixel, relative to simply copying the pixel values
-
-