ImageConsumer
, Cloneable
GrayFilter
This class provides an easy way to create an ImageFilter which modifies the pixels of an image in the default RGB ColorModel. It is meant to be used in conjunction with a FilteredImageSource object to produce filtered versions of existing images. It is an abstract class that provides the calls needed to channel all of the pixel data through a single method which converts pixels one at a time in the default RGB ColorModel regardless of the ColorModel being used by the ImageProducer. The only method which needs to be defined to create a useable image filter is the filterRGB method. Here is an example of a definition of a filter which swaps the red and blue components of an image:
class RedBlueSwapFilter extends RGBImageFilter {
public RedBlueSwapFilter() {
// The filter's operation does not depend on the
// pixel's location, so IndexColorModels can be
// filtered directly.
canFilterIndexColorModel = true;
}
public int filterRGB(int x, int y, int rgb) {
return ((rgb & 0xff00ff00)
| ((rgb & 0xff0000) >> 16)
| ((rgb & 0xff) << 16));
}
}
Fields
protected boolean
This boolean indicates whether or not it is acceptable to apply the color filtering of the filterRGB method to the color table entries of an IndexColorModel object in lieu of pixel by pixel filtering.
The ColorModel
with which to replace origmodel
when the user calls substituteColorModel
.
Constructors
protected
Constructor for subclasses to call.
Filters an IndexColorModel object by running each entry in its color tables through the filterRGB function that RGBImageFilter subclasses must provide.
abstract int
Subclasses must specify a method to convert a single input pixel in the default RGB ColorModel to a single output pixel.
void
filterRGBPixels(int x, int y, int w, int h, int[] pixels, int off, int scansize)
Filters a buffer of pixels in the default RGB ColorModel by passing them one by one through the filterRGB method.
void
If the ColorModel is an IndexColorModel and the subclass has set the canFilterIndexColorModel flag to true, we substitute a filtered version of the color model here and wherever that original ColorModel object appears in the setPixels methods.
void
If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel.
void
If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel, otherwise converts the buffer of integer pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method to be converted one by one.
void
Registers two ColorModel objects for substitution.
The ColorModel
with which to replace origmodel
when the user calls substituteColorModel
.
protected boolean canFilterIndexColorModel
This boolean indicates whether or not it is acceptable to apply the color filtering of the filterRGB method to the color table entries of an IndexColorModel object in lieu of pixel by pixel filtering. Subclasses should set this variable to true in their constructor if their filterRGB method does not depend on the coordinate of the pixel being filtered.
protected RGBImageFilter()
Constructor for subclasses to call.
Note: This method is intended to be called by the ImageProducer
of the Image
whose pixels are being filtered. Developers using this class to filter pixels from an image should avoid calling this method directly since that operation could interfere with the filtering operation.
setColorModel
in interface ImageConsumer
setColorModel
in class ImageFilter
model
- the specified ColorModel
Registers two ColorModel objects for substitution. If the oldcm is encountered during any of the setPixels methods, the newcm is substituted and the pixels passed through untouched (but with the new ColorModel object).
oldcm
- the ColorModel object to be replaced on the fly
newcm
- the ColorModel object to replace oldcm on the fly
Filters an IndexColorModel object by running each entry in its color tables through the filterRGB function that RGBImageFilter subclasses must provide. Uses coordinates of -1 to indicate that a color table entry is being filtered rather than an actual pixel value.
icm
- the IndexColorModel object to be filtered
NullPointerException
- if icm
is null
public void filterRGBPixels(int x, int y, int w, int h, int[] pixels, int off, int scansize)
Filters a buffer of pixels in the default RGB ColorModel by passing them one by one through the filterRGB method.
x
- the X coordinate of the upper-left corner of the region of pixels
y
- the Y coordinate of the upper-left corner of the region of pixels
w
- the width of the region of pixels
h
- the height of the region of pixels
pixels
- the array of pixels
off
- the offset into the pixels
array
scansize
- the distance from one row of pixels to the next in the array
Note: This method is intended to be called by the ImageProducer
of the Image
whose pixels are being filtered. Developers using this class to filter pixels from an image should avoid calling this method directly since that operation could interfere with the filtering operation.
setPixels
in interface ImageConsumer
setPixels
in class ImageFilter
x
- the X coordinate of the upper-left corner of the area of pixels to be set
y
- the Y coordinate of the upper-left corner of the area of pixels to be set
w
- the width of the area of pixels
h
- the height of the area of pixels
model
- the specified ColorModel
pixels
- the array of pixels
off
- the offset into the pixels
array
scansize
- the distance from one row of pixels to the next in the pixels
array
Note: This method is intended to be called by the ImageProducer
of the Image
whose pixels are being filtered. Developers using this class to filter pixels from an image should avoid calling this method directly since that operation could interfere with the filtering operation.
setPixels
in interface ImageConsumer
setPixels
in class ImageFilter
x
- the X coordinate of the upper-left corner of the area of pixels to be set
y
- the Y coordinate of the upper-left corner of the area of pixels to be set
w
- the width of the area of pixels
h
- the height of the area of pixels
model
- the specified ColorModel
pixels
- the array of pixels
off
- the offset into the pixels
array
scansize
- the distance from one row of pixels to the next in the pixels
array
public abstract int filterRGB(int x, int y, int rgb)
Subclasses must specify a method to convert a single input pixel in the default RGB ColorModel to a single output pixel.
x
- the X coordinate of the pixel
y
- the Y coordinate of the pixel
rgb
- the integer pixel representation in the default RGB color model
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4