All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.awt.image.ImageFilter | +----Acme.JPM.Filters.ImageFilterPlus | +----Acme.JPM.Filters.RGBAllFilter
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.
public RGBAllFilter(ImageProducer producer)
public abstract void filterRGBAll(int width, int height, int rgbPixels[][])
public void setPixels(int newWidth, int newHeight, int newPixels[][])
public void setColorModel(ColorModel model)
public void setDimensions(int width, int height)
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 imageComplete(int status)
All Packages Class Hierarchy This Package Previous Next Index
ACME Java ACME Labs