Class 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 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 to false, is that the alpha values from the source and stencil image are blended by multiplying them together.
        Parameters:
        replaceMode - true if the stencil's alpha values should simply replace the alpha values in the source; false if 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:
        true if the stencil's alpha values should simply replace the alpha values in the source; false if 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:
        filter in interface java.awt.image.BufferedImageOp
        Overrides:
        filter in class AbstractRowwiseFilter
      • filterPixels

        public void filterPixels​(int y,
                                 int[] argb)
        Description copied from class: AbstractRowwiseFilter
        This 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:
        filterPixels in class AbstractRowwiseFilter