Class 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 call functionChanged() whenever the filter settings change in a way that affects the output of f.

    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 Detail

      • AbstractFunctionFilter

        public AbstractFunctionFilter()
    • 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.)
        Specified by:
        f in interface Fn
        Parameters:
        x - the input value to the function, between 0 and 1 inclusive
        Returns:
        the output value of the function
      • 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 range argb[start] ... argb[end-1] with the filtered value.
        Specified by:
        filterPixels in class AbstractPixelwiseFilter
        Parameters:
        pixels - an array of pixel data to filter
        start - the index of the first pixel to filter
        end - the index of the last pixel to filter, plus one