import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.applet.*;

// This example demonstrates the use of Java 1.1 image filters,
// including built-in filters for image scaling and homemade
// filters for color manipulation.

public class Filters extends Applet {

  Image smileImage,       // the original image
        scaledSmileImage, // shrunk and smoothed
        shadowSmileImage; // shadow effect added

  public void init() {

    // Get the original image
    smileImage = getImage(getDocumentBase(), "smile.jpg");

    // Create a smooted image half the size of the original image
    // by applying the getScaledInstance method. This takes the
    // height and width of the new image as parameters, as well as
    // the type of filtering to be done (smoothing the image by
    // averaging adjacent pixels instead of destroying them).

    scaledSmileImage = smileImage.getScaledInstance(50, 50, Image.SCALE_SMOOTH);

    // Here we apply the homemade filter "ShadowFilter" to the image.
    // We first create a ShadowFilter (passing it the width of the image,
    // which it will use to darken the image from left to right).

    ImageFilter filter = new ShadowFilter(100);

    // We then create an "Image producer" object from the image
    // and the filter (which is like a "pipeline" of pixels that
    // we can read), and then create a new image from that producer.

    ImageProducer producer =
        new FilteredImageSource(smileImage.getSource(), filter);
    shadowSmileImage = createImage(producer);
    }

  public void paint(Graphics g) {

    // Draw the original image at half its size (will be very choppy)
    g.drawImage(smileImage, 0, 0, 50, 50, this);

    // Draw the smoothed image for comparison
    g.drawImage(scaledSmileImage, 0, 50, this);

    // Draw the shadowed image
    g.drawImage(shadowSmileImage, 50, 0, this);
    }

  }

