Package ca.cgjennings.graphics.filters
Class ChannelSwapFilter
- java.lang.Object
-
- ca.cgjennings.graphics.filters.AbstractImageFilter
-
- ca.cgjennings.graphics.filters.AbstractPixelwiseFilter
-
- ca.cgjennings.graphics.filters.ChannelSwapFilter
-
- All Implemented Interfaces:
java.awt.image.BufferedImageOp
public class ChannelSwapFilter extends AbstractPixelwiseFilter
A filter that allows channels in the source image to be swapped around, inverted, or filled with constant values. A source is set for each channel in the destination image. If the source value is between 0 and 255 (inclusive), then that channel is filled with that constant value. Otherwise, the source can be a special value that indicates any channel in the source image, and the value of that channel in the source image will be copied to the destination channel.As an example, the following filter would set the alpha value of every destination pixel to 255, and copy the red channel to all of the other channels:
ChannelSwapFilter csf = new ChannelSwapFilter( 255, RED, RED, RED );
In-place filtering: This class supports in-place filtering (the source and destination images may be the same).
- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALPHA
The target channel's value will be copied from the alpha channel of the source.static int
ALPHA_INVERTED
The target channel's value will be copied from the alpha channel of the source and inverted.static int
BLUE
The target channel's value will be copied from the blue channel of the source.static int
BLUE_INVERTED
The target channel's value will be copied from the blue channel of the source and inverted.static int
FILL
The value 255, which indicates that the channel should set to its maximum value.static int
GREEN
The target channel's value will be copied from the green channel of the source.static int
GREEN_INVERTED
The target channel's value will be copied from the green channel of the source and inverted.static int
GREY
The target channel's value will be set to the brightness of the source pixel as if it were converted to greyscale.static int
GREY_INVERTED
The target channel's value will be set to the inverse of the brightness of the source pixel (255-GREY
).static int
RED
The target channel's value will be copied from the red channel of the source.static int
RED_INVERTED
The target channel's value will be copied from the red channel of the source and inverted.static int
ZERO
The value 0, which indicates that the channel should be zeroed out.
-
Constructor Summary
Constructors Constructor Description ChannelSwapFilter()
Creates aChannelSwapFilter
that copies each channel from the the same channel in the source image, reproducing the original image.ChannelSwapFilter(int alphaSource, int redSource, int greenSource, int blueSource)
Creates aChannelSwapFilter
that copies channels from the indicated source channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
filterPixels(int[] pixels, int start, int end)
This method is called with a block of ARGB values to be filtered.int
getAlphaSource()
Returns the alpha source channel.int
getBlueSource()
Returns the blue source channel.int
getGreenSource()
Returns the green source channel.int
getRedSource()
Returns the red source channel.int[]
getSources()
Returns a new array containing the current channel sources for all channels in the order alpha, red, green, blue.void
setAlphaSource(int alphaSource)
Sets the alpha source channel.void
setBlueSource(int blueSource)
Sets the blue source channel.void
setGreenSource(int greenSource)
Sets the green source channel.void
setRedSource(int redSource)
Sets the red source channel.void
setSources(int alphaSource, int redSource, int greenSource, int blueSource)
Sets the channel source for all channels with a single call.-
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
-
-
-
-
Field Detail
-
ZERO
public static final int ZERO
The value 0, which indicates that the channel should be zeroed out.- See Also:
- Constant Field Values
-
FILL
public static final int FILL
The value 255, which indicates that the channel should set to its maximum value.- See Also:
- Constant Field Values
-
ALPHA
public static final int ALPHA
The target channel's value will be copied from the alpha channel of the source.- See Also:
- Constant Field Values
-
RED
public static final int RED
The target channel's value will be copied from the red channel of the source.- See Also:
- Constant Field Values
-
GREEN
public static final int GREEN
The target channel's value will be copied from the green channel of the source.- See Also:
- Constant Field Values
-
BLUE
public static final int BLUE
The target channel's value will be copied from the blue channel of the source.- See Also:
- Constant Field Values
-
ALPHA_INVERTED
public static final int ALPHA_INVERTED
The target channel's value will be copied from the alpha channel of the source and inverted.- See Also:
- Constant Field Values
-
RED_INVERTED
public static final int RED_INVERTED
The target channel's value will be copied from the red channel of the source and inverted.- See Also:
- Constant Field Values
-
GREEN_INVERTED
public static final int GREEN_INVERTED
The target channel's value will be copied from the green channel of the source and inverted.- See Also:
- Constant Field Values
-
BLUE_INVERTED
public static final int BLUE_INVERTED
The target channel's value will be copied from the blue channel of the source and inverted.- See Also:
- Constant Field Values
-
GREY
public static final int GREY
The target channel's value will be set to the brightness of the source pixel as if it were converted to greyscale.- See Also:
- Constant Field Values
-
GREY_INVERTED
public static final int GREY_INVERTED
The target channel's value will be set to the inverse of the brightness of the source pixel (255-GREY
).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ChannelSwapFilter
public ChannelSwapFilter()
Creates aChannelSwapFilter
that copies each channel from the the same channel in the source image, reproducing the original image.
-
ChannelSwapFilter
public ChannelSwapFilter(int alphaSource, int redSource, int greenSource, int blueSource)
Creates aChannelSwapFilter
that copies channels from the indicated source channel.- Parameters:
alphaSource
- the source channel to use for the destination's alpha channelredSource
- the source channel to use for the destination's red channelgreenSource
- the source channel to use for the destination's green channelblueSource
- the source channel to use for the destination's blue channel
-
-
Method Detail
-
setSources
public final void setSources(int alphaSource, int redSource, int greenSource, int blueSource)
Sets the channel source for all channels with a single call.- Parameters:
alphaSource
- the source channel to use for the destination's alpha channelredSource
- the source channel to use for the destination's red channelgreenSource
- the source channel to use for the destination's green channelblueSource
- the source channel to use for the destination's blue channel
-
getSources
public final int[] getSources()
Returns a new array containing the current channel sources for all channels in the order alpha, red, green, blue.- Returns:
- the current channel sources, as an array
- See Also:
setSources(int, int, int, int)
-
setAlphaSource
public final void setAlphaSource(int alphaSource)
Sets the alpha source channel.- Parameters:
alphaSource
- the source channel to use for the destination's alpha channel
-
setRedSource
public final void setRedSource(int redSource)
Sets the red source channel.- Parameters:
redSource
- the source channel to use for the destination's red channel
-
setGreenSource
public final void setGreenSource(int greenSource)
Sets the green source channel.- Parameters:
greenSource
- the source channel to use for the destination's green channel
-
setBlueSource
public final void setBlueSource(int blueSource)
Sets the blue source channel.- Parameters:
blueSource
- the source channel to use for the destination's blue channel
-
getAlphaSource
public final int getAlphaSource()
Returns the alpha source channel.- Returns:
- the source channel to use for the destination's alpha channel
-
getRedSource
public final int getRedSource()
Returns the red source channel.- Returns:
- the source channel to use for the destination's red channel
-
getGreenSource
public final int getGreenSource()
Returns the green source channel.- Returns:
- the source channel to use for the destination's green channel
-
getBlueSource
public final int getBlueSource()
Returns the blue source channel.- Returns:
- the source channel to use for the destination's blue channel
-
filterPixels
public void filterPixels(int[] pixels, 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:
pixels
- 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
-
-