import java.awt.*;

/**
 * This filter strips all but one (RGB) color.
 * 
 * @author Michael Kolling and David J Barnes
 * @updates and changes by Michael Rivers
 * @version 1.0 May 14th, 2006
 */
public class StripFilter extends Filter
{
    private int rgb;
    public static final int RED = 1;
    public static final int GREEN = 2;
    public static final int BLUE = 3;
    /**
     * Constructor for objects of class MikesFilter
     */
    public StripFilter(String name, int rgb)
    {
        super(name);
        this.rgb = rgb;
    }

    /**
     * Apply this filter to an image.
     * 
     * @param  image  The image to be changed by this filter.
     */
    public void apply(OFImage image)
    {
        int height = image.getHeight();
        int width = image.getWidth();
        for(int y = 0; y < height; y++) {
            for(int x = 0; x < width; x++) {
                Color pixel = image.getPixel(x, y);
                if (rgb == RED) {
                    int r = pixel.getRed();
                    image.setPixel(x, y, new Color(r,0,0));
                } else if (rgb == GREEN) {
                    int g = pixel.getGreen();
                    image.setPixel(x, y, new Color(0,g,0));
                } else if (rgb == BLUE) {
                    int b = pixel.getGreen();
                    image.setPixel(x, y, new Color(0,0,b));
                } else {
                    System.out.println("Error: Strip color undefined");
                }
            }
        }
    }
}
