Class SubstitutionFilter

  • All Implemented Interfaces:
    java.awt.image.BufferedImageOp

    public class SubstitutionFilter
    extends AbstractPixelwiseFilter
    An image filter that replaces one ARGB value with another. The substitution only occurs when the input value is an exact match. Typically, this is used to replace a "magic" or "key" value, for example, when a source image uses a special value to indicate pixels that should be transparent.

    In-place filtering: This filter supports in-place filtering (the source and destination may be the same).

    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Detail

      • SubstitutionFilter

        public SubstitutionFilter()
        Creates a new filter that substitutes pixels with value 0xffff00ff with the value 0x00000000.
      • SubstitutionFilter

        public SubstitutionFilter​(int target,
                                  int replacement)
        Creates a new filter that substitutes pixels as specified.
        Parameters:
        target - the value to search for
        replacement - the value to replace the target with
    • Method Detail

      • getTarget

        public int getTarget()
        Returns the target value.
        Returns:
        the pixel value to match
      • setTarget

        public void setTarget​(int target)
        Sets the target pixel value to match.
        Parameters:
        target - the pixel value to match
      • getReplacement

        public int getReplacement()
        Returns the replacement value.
        Returns:
        the pixel value to replace the target with
      • setReplacement

        public void setReplacement​(int replacement)
        Sets the replacement value.
        Parameters:
        replacement - the pixel value to replace target pixels with
      • setErrorTolerance

        public void setErrorTolerance​(float tolerance)
        Sets the amount of error tolerance allowed when matching pixels. The error value of any pixel is the distance between the tuples formed by the channel values of the target value and the pixel being considered. The default tolerance is 0, meaning that the pixel values must match exactly.
        Parameters:
        tolerance - the error tolerance to allow when matching the target pixel
        See Also:
        getErrorTolerance()
      • getErrorTolerance

        public float getErrorTolerance()
        Returns the amount of error tolerance allowed when matching pixels.
        Returns:
        the error tolerance to allow when matching the target pixel
        See Also:
        setErrorTolerance(float)
      • isBlendedWithOriginal

        public boolean isBlendedWithOriginal()
        Returns true if the substitute colour is blended with the original colour according to the distance from the target colour. This has no effect if the error tolerance is 0.
        Returns:
        true if the substitute colour is blended with the target colour in proportion to the target's error
      • setBlendedWithOriginal

        public void setBlendedWithOriginal​(boolean blend)
        Sets whether the substitute colour is blended with the target colour in proportion to a pixel's distance from the colour to match. This has no effect if the error tolerance is 0.
        Parameters:
        blend - if true, blending is performed relative to the amount of error
      • 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 range argb[start] ... argb[end-1] with the filtered value.
        Specified by:
        filterPixels in class AbstractPixelwiseFilter
        Parameters:
        argb - 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