Package ca.cgjennings.graphics.filters
Class AbstractFunctionFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
-
- ca.cgjennings.graphics.filters.AbstractFunctionFilter
-
- All Implemented Interfaces:
Fn
,java.awt.image.BufferedImageOp
- Direct Known Subclasses:
BrightnessContrastFilter
public abstract class AbstractFunctionFilter extends AbstractPixelwiseFilter implements Fn
An abstract base class for filters that apply a transfer function to the red, green, and blue channels to produce a result. The alpha channel is not affected.Subclasses must implement
f(double)
to compute the specific function to be applied to the channels, and must callfunctionChanged()
whenever the filter settings change in a way that affects the output off
.The transfer function
f
is passed values between 0 and 1 inclusive, representing the brightness of the red, green, or blue channels for a given sample (pixel). The transfer function then returns new values representing how the input value should change as a result of applying the filter. As a simple example, the following transfer function would brighten images by 10 percent:public float f( float x ) { return x * 1.10f; }
In-place filtering: This class supports in-place filtering (the source and destination images may be the same).
- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description AbstractFunctionFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract double
f(double x)
Subclasses must implement this method to define the transfer function used by the filter.void
filterPixels(int[] pixels, int start, int end)
This method is called with a block of ARGB values to be filtered.protected void
functionChanged()
Subclasses must call this function if a change to the filter instance would cause the transfer function to return different values.-
Methods inherited from class ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
filter, filter, filterPixel, workFactor
-
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
-
f
public abstract double f(double x)
Subclasses must implement this method to define the transfer function used by the filter. The function must return a valid result for any input between 0 and 1, inclusive. The value returned is normally also in this range, but this is not required. (Out of range values will be clamped to the nearest in-range value.)
-
functionChanged
protected void functionChanged()
Subclasses must call this function if a change to the filter instance would cause the transfer function to return different values. For example, if the filter function defines parameters used by the transfer function, this function must be called if one of those parameters changes.
-
filterPixels
public void filterPixels(int[] pixels, 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:
pixels
- 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
-
-