Class 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 a ClearFilter instead. For more complex channel mixing and swapping of channels, see ChannelSwapFilter.

    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 Detail

      • ColorOverlayFilter

        public ColorOverlayFilter()
      • ColorOverlayFilter

        public ColorOverlayFilter​(int rgb)
      • ColorOverlayFilter

        public ColorOverlayFilter​(int rgb,
                                  boolean invert)
    • 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 a Color object.
        Parameters:
        c - the colour value to apply
      • getColor

        public java.awt.Color getColor()
        Returns the colour to overlay as a Color 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 is false, so that the overlay is applied to the interior of the shape(s) defined by the alpha channel. If set to true, the effect is to apply the overlay to the exterior of that shape.
        Parameters:
        invert - if true, alpha values are inverted
      • isAlphaInverted

        public boolean isAlphaInverted()
        Returns true 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 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
      • 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 class AbstractPixelwiseFilter
        Parameters:
        argb - the pixel value to filter
        Returns:
        the filtered pixel value