Top Description Fields Constructors Methods
java.awt.image

public abstract Class RGBImageFilter

extends ImageFilter
Class Inheritance
Known Direct Subclasses
javax.swing.DebugGraphicsFilter, javax.swing.GrayFilter, javax.swing.plaf.metal.MetalUtils.OceanDisabledButtonImageFilter, javax.swing.plaf.metal.MetalUtils.OceanToolBarImageFilter, com.sun.java.swing.plaf.gtk.Metacity.ColorizeImageFilter
Imports
java.awt.image.ImageConsumer, .ColorModel

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 usable 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));
         }
     }

Author
Jim Graham
See Also
FilteredImageSource, ImageFilter, ColorModel#getRGBdefault

Field Summary

Modifier and TypeField and Description
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.

protected ColorModel
newmodel

The ColorModel with which to replace origmodel when the user calls substituteColorModel.

protected ColorModel
origmodel

The ColorModel to be replaced by newmodel when the user calls substituteColorModel.

Inherited from java.awt.image.ImageFilter:
consumer

Constructor Summary

AccessConstructor and Description
protected
RGBImageFilter()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
public IndexColorModel

Returns:

a new IndexColorModel representing the filtered colors
filterIndexColorModel
(IndexColorModel
the IndexColorModel object to be filtered
icm
)

Filters an IndexColorModel object by running each entry in its color tables through the filterRGB function that RGBImageFilter subclasses must provide.

public abstract int

Returns:

a filtered pixel in the default RGB color model.
filterRGB
(int
the X coordinate of the pixel
x
,
int
the Y coordinate of the pixel
y
,
int
the integer pixel representation in the default RGB color model
rgb
)

Subclasses must specify a method to convert a single input pixel in the default RGB ColorModel to a single output pixel.

public void
filterRGBPixels(int
the X coordinate of the upper-left corner of the region of pixels
x
,
int
the Y coordinate of the upper-left corner of the region of pixels
y
,
int
the width of the region of pixels
w
,
int
the height of the region of pixels
h
,
int[]
the array of pixels
pixels
,
int
the offset into the pixels array
off
,
int
the distance from one row of pixels to the next in the array
scansize
)

Filters a buffer of pixels in the default RGB ColorModel by passing them one by one through the filterRGB method.

public void
setColorModel(ColorModel
the specified ColorModel
model
)

Overrides java.awt.image.ImageFilter.setColorModel.

Implements java.awt.image.ImageConsumer.setColorModel.

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.

public void
setPixels(int
the X coordinate of the upper-left corner of the area of pixels to be set
x
,
int
the Y coordinate of the upper-left corner of the area of pixels to be set
y
,
int
the width of the area of pixels
w
,
int
the height of the area of pixels
h
,
ColorModel
the specified ColorModel
model
,
byte[]
the array of pixels
pixels
,
int
the offset into the pixels array
off
,
int
the distance from one row of pixels to the next in the pixels array
scansize
)

Overrides java.awt.image.ImageFilter.setPixels.

Implements java.awt.image.ImageConsumer.setPixels.

If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel.

public void
setPixels(int
the X coordinate of the upper-left corner of the area of pixels to be set
x
,
int
the Y coordinate of the upper-left corner of the area of pixels to be set
y
,
int
the width of the area of pixels
w
,
int
the height of the area of pixels
h
,
ColorModel
the specified ColorModel
model
,
int[]
the array of pixels
pixels
,
int
the offset into the pixels array
off
,
int
the distance from one row of pixels to the next in the pixels array
scansize
)

Overrides java.awt.image.ImageFilter.setPixels.

Implements java.awt.image.ImageConsumer.setPixels.

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.

public void
substituteColorModel(ColorModel
the ColorModel object to be replaced on the fly
oldcm
,
ColorModel
the ColorModel object to replace oldcm on the fly
newcm
)

Registers two ColorModel objects for substitution.

Inherited from java.awt.image.ImageFilter:
clonegetFilterInstanceimageCompleteresendTopDownLeftRightsetDimensionssetHintssetProperties

Field Detail

canFilterIndexColorModelback to summary
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.

See Also
substituteColorModel, filterRGB, IndexColorModel
newmodelback to summary
protected ColorModel newmodel

The ColorModel with which to replace origmodel when the user calls substituteColorModel.

origmodelback to summary
protected ColorModel origmodel

The ColorModel to be replaced by newmodel when the user calls substituteColorModel.

Constructor Detail

RGBImageFilterback to summary
protected RGBImageFilter()

Constructor for subclasses to call.

Method Detail

filterIndexColorModelback to summary
public IndexColorModel filterIndexColorModel(IndexColorModel icm)

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.

Parameters
icm:IndexColorModel

the IndexColorModel object to be filtered

Returns:IndexColorModel

a new IndexColorModel representing the filtered colors

Exceptions
NullPointerException:
if icm is null
filterRGBback to summary
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.

Parameters
x:int

the X coordinate of the pixel

y:int

the Y coordinate of the pixel

rgb:int

the integer pixel representation in the default RGB color model

Returns:int

a filtered pixel in the default RGB color model.

See Also
ColorModel#getRGBdefault, filterRGBPixels
filterRGBPixelsback to summary
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.

Parameters
x:int

the X coordinate of the upper-left corner of the region of pixels

y:int

the Y coordinate of the upper-left corner of the region of pixels

w:int

the width of the region of pixels

h:int

the height of the region of pixels

pixels:int[]

the array of pixels

off:int

the offset into the pixels array

scansize:int

the distance from one row of pixels to the next in the array

See Also
ColorModel#getRGBdefault, filterRGB
setColorModelback to summary
public void setColorModel(ColorModel model)

Overrides java.awt.image.ImageFilter.setColorModel.

Implements java.awt.image.ImageConsumer.setColorModel.

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. If the ColorModel is not an IndexColorModel or is null, this method overrides the default ColorModel used by the ImageProducer and specifies the default RGB ColorModel instead.

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.

Parameters
model:ColorModel

Doc from java.awt.image.ImageConsumer.setColorModel.

the specified ColorModel

See Also
ImageConsumer, ColorModel#getRGBdefault
setPixelsback to summary
public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize)

Overrides java.awt.image.ImageFilter.setPixels.

Implements java.awt.image.ImageConsumer.setPixels.

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 byte pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method to be converted one by one.

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.

Parameters
x:int

Doc from java.awt.image.ImageConsumer.setPixels.

the X coordinate of the upper-left corner of the area of pixels to be set

y:int

Doc from java.awt.image.ImageConsumer.setPixels.

the Y coordinate of the upper-left corner of the area of pixels to be set

w:int

Doc from java.awt.image.ImageConsumer.setPixels.

the width of the area of pixels

h:int

Doc from java.awt.image.ImageConsumer.setPixels.

the height of the area of pixels

model:ColorModel

Doc from java.awt.image.ImageConsumer.setPixels.

the specified ColorModel

pixels:byte[]

Doc from java.awt.image.ImageConsumer.setPixels.

the array of pixels

off:int

Doc from java.awt.image.ImageConsumer.setPixels.

the offset into the pixels array

scansize:int

Doc from java.awt.image.ImageConsumer.setPixels.

the distance from one row of pixels to the next in the pixels array

See Also
ColorModel#getRGBdefault, filterRGBPixels
setPixelsback to summary
public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize)

Overrides java.awt.image.ImageFilter.setPixels.

Implements java.awt.image.ImageConsumer.setPixels.

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. Converts a buffer of integer pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method.

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.

Parameters
x:int

Doc from java.awt.image.ImageConsumer.setPixels.

the X coordinate of the upper-left corner of the area of pixels to be set

y:int

Doc from java.awt.image.ImageConsumer.setPixels.

the Y coordinate of the upper-left corner of the area of pixels to be set

w:int

Doc from java.awt.image.ImageConsumer.setPixels.

the width of the area of pixels

h:int

Doc from java.awt.image.ImageConsumer.setPixels.

the height of the area of pixels

model:ColorModel

Doc from java.awt.image.ImageConsumer.setPixels.

the specified ColorModel

pixels:int[]

Doc from java.awt.image.ImageConsumer.setPixels.

the array of pixels

off:int

Doc from java.awt.image.ImageConsumer.setPixels.

the offset into the pixels array

scansize:int

Doc from java.awt.image.ImageConsumer.setPixels.

the distance from one row of pixels to the next in the pixels array

See Also
ColorModel#getRGBdefault, filterRGBPixels
substituteColorModelback to summary
public void substituteColorModel(ColorModel oldcm, ColorModel newcm)

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).

Parameters
oldcm:ColorModel

the ColorModel object to be replaced on the fly

newcm:ColorModel

the ColorModel object to replace oldcm on the fly