Package java.awt.image Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class RGBImageFilter

Fields , Constructors , Methods

public  abstract  class  java.awt.image.RGBImageFilter
    extends  java.awt.image.ImageFilter  
{
        // Fields
    protected boolean canFilterIndexColorModel;	
    protected ColorModel newmodel;	
    protected ColorModel origmodel;	

        // Constructors
    public RGBImageFilter();	

        // Methods
    public IndexColorModel 	
        filterIndexColorModel(IndexColorModel  icm);
    public abstract int filterRGB(int  x, int  y, int  rgb);	
    public void filterRGBPixels(int  x, int  y, int  w,	
          int  h, int  pixels[], int  off, int  scansize);
    public void setColorModel(ColorModel  model);	
    public void setPixels(int  x, int  y, int  w, int  h,	
            ColorModel  model, byte  pixels[], ;int  off, int  scansize);
    public void setPixels(int  x, int  y, int  w, int  h	
            ColorModel  model, int  pixels[], int  off, int  scansize);
    public void tituteColorModel(ColorModel  oldcm, 	
            ColorModel  newcm);
}

This class provides an easy way to create an image filter which modifies the pixels of the original image by converting them one at a time in the default RGB color model .

Objects of this class are meant to be used in conjunction with a filtered image source object to produce filtered versions of existing images.

This class is an abstract class. It provides the calls needed to channel all the pixel data through a single method which converts pixels, one at a time, into the default RGB color model, regardless of the color model being used by the image producer. The only method which needs to be defined to create a useable image filter is the filterRGB method.

Here is an example 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  &amp;  0xff)  <<  16)); 
                }
}



Fields


canFilterIndexColorModel

protected boolean canFilterIndexColorModel 

Setting this value to true indicates that the the value returned by the filterRGB method is independent of the x and y arguments, and depends only on the rgb argument.

Subclasses of RGBImageFilter should set this field to true in their constructor if their filterRGB method does not depend on the coordinate of the pixel being filtered. Filtering the colormap entries of an indexed color map can be much faster than filtering every pixel.

The default value is false.

See Also: substituteColorModel IndexColorModel .


newmodel

protected ColorModel newmodel 

This field is used to remember the newcm argument passed to the substituteColorModel method.


origmodel

protected ColorModel origmodel 

This field is used to remember the oldcm argument passed to the substituteColorModel method.


Constructors


RGBImageFilter

public RGBImageFilter() 

The default constructor.


Methods


filterIndexColorModel

public IndexColorModel
filterIndexColorModel(IndexColorModel  icm) 

Filters an index color model object by running each entry in its color table through the filterRGB method . The call to filterRGB has the x and y arguments set to -1 as a flag to indicate that a color table entry is being filtered rather than an actual pixel value.

Return Value:

Returns a new index color model with the filtered colors.

ParameterDescription
icm the index color model object to be filtered


filterRGB

public abstract int filterRGB(int  x, int  y, int  rgb) 

Specifies a method to convert a single input pixel, whose value is specified in the default RGB color model , to a new pixel value also in the default RGB color model. Subclasses of RGBImageFilter must provide a definition for this method.

If the value of the field canFilterIndexColorModel is true, then the value returned by this method must not depend on the x and y coordinates.

If the x and y arguments are both -1, this method is being called by the filterIndexColorModel method .

Return Value:

Returns the new value of the pixel, in the default RGB color model.

ParameterDescription
x the x coordinate of the pixel
y the y coordinate of the pixel
rgb the value of the pixel, in the default RGB color model

See Also: filterRGBPixels .


filterRGBPixels

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 color model by passing them one by one through the filterRGB method .

The setPixels method of the filter's consumer is then called with the resulting buffer and the color model argument set to the default RGB color model.

Only pixels that fall within the specified rectangle are modified. The value of the pixel at coordinate (i,j) is stored in the pixel array at index j ´ scan + i + offset

ParameterDescription
x left coordinate of rectangle
y top coordinte of rectangle
w width of rectangle
h height of rectangle
model color model for bits
pixels array of bits
off offset for first element
scansize number of elements per row


setColorModel

public void setColorModel(ColorModel  model) 

The image producer calls the setColorModel method to specify the color model for the majority of the subsequent setPixels method calls. For more information on this method and its model argument, see setColorModel

The setColorModel method of RGBImageFilter determines if the color model argument is an index color model and if the canFilterIndexColorModel field is true.

If both conditions are true, the method creates a new color model by calling the filterIndexColorModel method on the model argument. The original color model and the newly created color model are then passed as arguments to the substituteColorModel method. In addition, the setColorModel method of the filter's consumer is called with the newly created color model.

If either condition is false, the method calls the the setColorModel method of its consumer with the default RGB color map .

ParameterDescription
model a color map used in subsequent setPixel calls

Overrides:

setColorModel in class ImageFilter .


setPixels

public void
setPixels(int  x, int  y, int  w, int  h, ColorModel model, 
                    byte  pixels[], int  off,  int  scansize) 

The image producer calls the setPixels method of the image consumer one or more times to deliver the pixels of the image. For more information on this method and its arguments, see setPixels.

The setPixels method of RGBImageFilter looks to see if the color model is the same one that has already been converted and remembered for substitution by a previous call to the substituteColorModel method.

If so, it calls the setPixels method of its consumer , changing the color model argument to be the alternative color model.

Otherwise, the method converts the buffer of byte pixels to the default RGB color model and passes the converted buffer to the filterRGBPixels method to be converted one by one.

ParameterDescription
x left coordinate of rectangle
y top coordinte of rectangle
w width of rectangle
h height of rectangle
model color model for bits
pixels array of bits
off offset for first element
scansize number of elements per row

Overrides:

setPixels in class ImageFilter .


setPixels

public void
setPixels(int  x, int  y, int  w, int  h, ColorModel model, 
                    int  pixels[], int  off, int  scansize) 

The image producer calls the setPixels method of the image consumer one or more times to deliver the pixels of the image. For more information on this method and its arguments, see setPixels.

The setPixels method of RGBImageFilter looks to see if the color model is the same one that has already been converted and remembered for substitution by a previous call to the substituteColorModel method.

If so, it calls the setPixels method of the filter's consumer , changing the color model argument to be the alternative color model.

Otherwise, the method converts the buffer of byte pixels to the default RGB color model and passes the converted buffer to the filterRGBPixels method to be converted one by one.

ParameterDescription
x left coordinate of rectangle
y top coordinte of rectangle
w width of rectangle
h height of rectangle
model color model for bits
pixels array of bits
off offset for first element
scansize number of elements per row

Overrides:

setPixels in class ImageFilter .


substituteColorModel

public void substituteColorModel(ColorModel  oldcm, ColorModel  newcm) 

Registers two color model objects for substitution: If the oldcm is the color model during any subsequent call to either of the setPixels methods , the newcm argument is substituted and the pixels passed through unmodifed.

ParameterDescription
oldcm the ColorModel object to be replaced on the fly
newcm the ColorModel object to replace oldcm on the fly



Top© 1996 Sun Microsystems, Inc. All rights reserved.