Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

778 Part II: The Java Library


The two concrete subclasses, shown in the next section, simply implement theconvolve( )
method, usingimgpixelsfor source data andnewimgpixelsto storethe result.

import java.applet.*;
import java.awt.*;
import java.awt.image.*;

abstract class Convolver implements ImageConsumer, PlugInFilter {
int width, height;
int imgpixels[], newimgpixels[];
boolean imageReady = false;

abstract void convolve(); // filter goes here...

public Image filter(Applet a, Image in) {
in.getSource().startProduction(this);
imageReady = false;
waitForImage();
newimgpixels = new int[width*height];

try {
convolve();
} catch (Exception e) {
System.out.println("Convolver failed: " + e);
e.printStackTrace();
}

FIGURE 25-9

Using theContrast
filter with
ImageFilterDemo
Free download pdf