Package ca.cgjennings.graphics.filters
Class SubstitutionFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
-
- ca.cgjennings.graphics.filters.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 Summary
Constructors Constructor Description SubstitutionFilter()
Creates a new filter that substitutes pixels with value 0xffff00ff with the value 0x00000000.SubstitutionFilter(int target, int replacement)
Creates a new filter that substitutes pixels as specified.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
filterPixels(int[] argb, int start, int end)
This method is called with a block of ARGB values to be filtered.float
getErrorTolerance()
Returns the amount of error tolerance allowed when matching pixels.int
getReplacement()
Returns the replacement value.int
getTarget()
Returns the target value.boolean
isBlendedWithOriginal()
Returnstrue
if the substitute colour is blended with the original colour according to the distance from the target colour.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.void
setErrorTolerance(float tolerance)
Sets the amount of error tolerance allowed when matching pixels.void
setReplacement(int replacement)
Sets the replacement value.void
setTarget(int target)
Sets the target pixel value to match.-
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
-
-
-
-
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 forreplacement
- 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()
Returnstrue
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
- iftrue
, 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 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
-
-