Package ca.cgjennings.graphics.filters
Class ColorOverlayFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
-
- ca.cgjennings.graphics.filters.ColorOverlayFilter
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
public class ColorOverlayFilter extends AbstractPixelwiseFilter
Sets every pixel to a common RGB value without modifying the alpha channel. Where the alpha channel uses transparency to define a shape, the effect of this filter is to overlay the shape with a solid colour. To simply set every pixel to a single value, overwriting the alpha value, use aClearFilter
instead. For more complex channel mixing and swapping of channels, seeChannelSwapFilter
.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 ColorOverlayFilter()
ColorOverlayFilter(int rgb)
ColorOverlayFilter(int rgb, boolean invert)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
filterPixel(int argb)
Returns the result of applying the filter to a single ARGB pixel value.void
filterPixels(int[] argb, int start, int end)
This method is called with a block of ARGB values to be filtered.java.awt.Color
getColor()
Returns the colour to overlay as aColor
object.int
getColorRGB()
Returns the colour to overlay as a packed RGB value.boolean
isAlphaInverted()
Returnstrue
if the alpha channel values will be inverted, changing the shape from the exterior to the interior of the original shape.void
setAlphaInverted(boolean invert)
Sets whether the alpha channel will be inverted.void
setColor(java.awt.Color c)
Sets the colour to overlay from aColor
object.void
setColorRGB(int rgb)
Sets the colour to overlay as a packed integer RGB value.-
Methods inherited from class ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
filter, filter, 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
-
setColorRGB
public void setColorRGB(int rgb)
Sets the colour to overlay as a packed integer RGB value.- Parameters:
rgb
- the colour value to apply
-
getColorRGB
public int getColorRGB()
Returns the colour to overlay as a packed RGB value.- Returns:
- the colour value to be applied
-
setColor
public void setColor(java.awt.Color c)
Sets the colour to overlay from aColor
object.- Parameters:
c
- the colour value to apply
-
getColor
public java.awt.Color getColor()
Returns the colour to overlay as aColor
object. If the colour was set from a colour object, this is not guaranteed to be the same instance.- Returns:
- the colour value to be applied
-
setAlphaInverted
public void setAlphaInverted(boolean invert)
Sets whether the alpha channel will be inverted. The default isfalse
, so that the overlay is applied to the interior of the shape(s) defined by the alpha channel. If set totrue
, the effect is to apply the overlay to the exterior of that shape.- Parameters:
invert
- iftrue
, alpha values are inverted
-
isAlphaInverted
public boolean isAlphaInverted()
Returnstrue
if the alpha channel values will be inverted, changing the shape from the exterior to the interior of the original shape.- Returns:
true
if alpha values are inverted
-
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
-
filterPixel
public int filterPixel(int argb)
Description copied from class:AbstractPixelwiseFilter
Returns the result of applying the filter to a single ARGB pixel value.The base class implementation creates a singleton array containing the pixel value and passes this to
AbstractPixelwiseFilter.filterPixels(int[], int, int)
, returning the result. Subclasses may wish override this to provide a more efficient implementation.- Overrides:
filterPixel
in classAbstractPixelwiseFilter
- Parameters:
argb
- the pixel value to filter- Returns:
- the filtered pixel value
-
-