Package ca.cgjennings.graphics.filters
Class StencilFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractRowwiseFilter
-
- ca.cgjennings.graphics.filters.StencilFilter
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
public class StencilFilter extends AbstractRowwiseFilter
Set the alpha channel of an image using the pixels of another image as a stencil. The same effect can be achieved with a composite, but the filter is optimized for the case where the stencil image will be reused multiple times.In-place filtering: This class supports in-place filtering (the source and destination images may be the same).
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description StencilFilter()Creates a new filter with a transparent empty 1 pixel by 1 pixel image as the stencil.StencilFilter(java.awt.image.BufferedImage stencil)Creates a new stencil filter with the specified stencil image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.image.BufferedImagefilter(java.awt.image.BufferedImage source, java.awt.image.BufferedImage dest)voidfilterPixels(int y, int[] argb)This method is called with a block of ARGB values to be filtered.booleanisAlphaReplaceMode()Returns whether the stencil's alpha values are copied over (true), or blended with the source image (false).voidsetAlphaReplaceMode(boolean replaceMode)Sets whether the stencil is applied in alpha replace mode, in which the output image's alpha channel is copied unmodified from the stencil image.voidsetStencil(java.awt.image.BufferedImage stencil)Sets the stencil to the specified image.-
Methods inherited from class ca.cgjennings.graphics.filters.AbstractRowwiseFilter
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
-
StencilFilter
public StencilFilter()
Creates a new filter with a transparent empty 1 pixel by 1 pixel image as the stencil.
-
StencilFilter
public StencilFilter(java.awt.image.BufferedImage stencil)
Creates a new stencil filter with the specified stencil image.- Parameters:
stencil- the stencil image whose alpha channel will mask the source image
-
-
Method Detail
-
setStencil
public void setStencil(java.awt.image.BufferedImage stencil)
Sets the stencil to the specified image. The image's alpha channel data is copied, so modifications made to the source image after this method returns will not affect the behaviour of the stencil.- Parameters:
stencil- the stencil image whose alpha channel will mask the source image
-
setAlphaReplaceMode
public void setAlphaReplaceMode(boolean replaceMode)
Sets whether the stencil is applied in alpha replace mode, in which the output image's alpha channel is copied unmodified from the stencil image. This is the default. The alternative, when this is set tofalse, is that the alpha values from the source and stencil image are blended by multiplying them together.- Parameters:
replaceMode-trueif the stencil's alpha values should simply replace the alpha values in the source;falseif the alpha values should be multiplied- See Also:
isAlphaReplaceMode()
-
isAlphaReplaceMode
public boolean isAlphaReplaceMode()
Returns whether the stencil's alpha values are copied over (true), or blended with the source image (false).- Returns:
trueif the stencil's alpha values should simply replace the alpha values in the source;falseif the alpha values should be multiplied- See Also:
setAlphaReplaceMode(boolean)
-
filter
public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage source, java.awt.image.BufferedImage dest)- Specified by:
filterin interfacejava.awt.image.BufferedImageOp- Overrides:
filterin classAbstractRowwiseFilter
-
filterPixels
public void filterPixels(int y, int[] argb)Description copied from class:AbstractRowwiseFilterThis method is called with a block of ARGB values to be filtered. Subclasses should override this method to implement the actual filtering algorithm, replacing each pixel in the supplied array with its filtered value.- Specified by:
filterPixelsin classAbstractRowwiseFilter
-
-