import java.awt.image.*;

/** Extends awt.image.RGBImageFilter,
 * uncolors and also fades an image.<p>
 * <IMG SRC="/cgi-bin/counter">
 *
 * @version 1.0, Apr 1 1996
 * @author  David Geary
 * @see     RGBImageFilter
 */
public class BlackAndWhiteFilter extends RGBImageFilter {

/** Constructor declares we canFilterIndexColorModel,
 * rather than each pixel location. */

    public BlackAndWhiteFilter() {
        canFilterIndexColorModel = true;
    }

    public int filterRGB(int x, int y, int rgb) {
        DirectColorModel cm = 
            (DirectColorModel)ColorModel.getRGBdefault();

        int    alpha = cm.getAlpha(rgb);
        int    red   = cm.getRed  (rgb);
        int    green = cm.getGreen(rgb);
        int    blue  = cm.getBlue (rgb);

/* Double weight to green component (somewhat like UYV model)
 * and alot of gray thrown in.  */

        int  mixed = (200 + 200 + red + green + green + blue) / 6;

	red   = blue = green = mixed;

        alpha = alpha << 24;
        red   = red   << 16;
        green = green << 8;

        return alpha | red | green | blue;
    }
}
/* <IMG SRC="/cgi-bin/counter">*/
