All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.JPM.Filters.RGBAllFilter

java.lang.Object
   |
   +----java.awt.image.ImageFilter
           |
           +----Acme.JPM.Filters.ImageFilterPlus
                   |
                   +----Acme.JPM.Filters.RGBAllFilter

public abstract class RGBAllFilter
extends ImageFilterPlus
An ImageFilter that grabs the whole image.

Many image filters need to work on the whole image at once. This class collects up the image and hands it to a single routine for processing.

Also, because Java's image classes allow each setPixels() call to use a different color model, we have to convert all pixels into the default RGB model.

Here's a sample RGBAllFilter that smooths an image by averaging nine adjacent pixels.

 class SmoothFilter extends RGBAllFilter
     {
     public void filterRGBAll( int width, int height, int[][] rgbPixels )
         {
         int[][] newPixels = new int[height][width];
         for ( int row = 0; row < height; ++row )
             for ( int col = 0; col < width; ++col )
                 {
                 int a = 0, r = 0, g = 0, b = 0, c = 0;
                 for ( int subrow = row - 1; subrow <= row + 1; ++subrow )
                     if ( subrow >= 0 && subrow < height )
                         for ( int subcol = col - 1; subcol <= col + 1; ++subcol )
                             if ( subcol >= 0 && subcol < width )
                                 {
                                 int pixel = rgbPixels[subrow][subcol];
                                 a += rgbModel.getAlpha( pixel );
                                 r += rgbModel.getRed( pixel );
                                 g += rgbModel.getGreen( pixel );
                                 b += rgbModel.getBlue( pixel );
                                 ++c;
                                 }
                 a /= c;
                 r /= c;
                 g /= c;
                 b /= c;
                 newPixels[row][col] =
                     ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b;
                 }
         setPixels( width, height, newPixels );
         }
     }
 

Fetch the software.
Fetch the entire Acme package.


Constructor Index

 o RGBAllFilter(ImageProducer)

Method Index

 o filterRGBAll(int, int, int[][])
This is the routine that subclasses must implement.
 o imageComplete(int)
This routine fixes a bug in java.awt.image.ImageFilter.
 o setColorModel(ColorModel)
 o setDimensions(int, int)
 o setPixels(int, int, int, int, ColorModel, byte[], int, int)
 o setPixels(int, int, int, int, ColorModel, int[], int, int)
 o setPixels(int, int, int[][])
The version of setPixels() that gets called by the subclass.

Constructors

 o RGBAllFilter
 public RGBAllFilter(ImageProducer producer)

Methods

 o filterRGBAll
 public abstract void filterRGBAll(int width,
                                   int height,
                                   int rgbPixels[][])
This is the routine that subclasses must implement. It gets the entire image as an int[height][width] in the default RGB color model. It should call setPixels() with a filtered array, same color model.

 o setPixels
 public void setPixels(int newWidth,
                       int newHeight,
                       int newPixels[][])
The version of setPixels() that gets called by the subclass.

 o setColorModel
 public void setColorModel(ColorModel model)
Overrides:
setColorModel in class ImageFilter
 o setDimensions
 public void setDimensions(int width,
                           int height)
Overrides:
setDimensions in class ImageFilter
 o setPixels
 public void setPixels(int x,
                       int y,
                       int w,
                       int h,
                       ColorModel model,
                       byte pixels[],
                       int off,
                       int scansize)
Overrides:
setPixels in class ImageFilter
 o setPixels
 public void setPixels(int x,
                       int y,
                       int w,
                       int h,
                       ColorModel model,
                       int pixels[],
                       int off,
                       int scansize)
Overrides:
setPixels in class ImageFilter
 o imageComplete
 public void imageComplete(int status)
This routine fixes a bug in java.awt.image.ImageFilter.

Overrides:
imageComplete in class ImageFilterPlus

All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs