import java.awt.*;

/**
 * This is my modification of the threshold filter.
 * It takes more thresholds, and sets pixels within
 * the brightness boundaries to rainbow colors
 * instead of gray, black, and white.
 * 
 * @author Michael Kolling and David J Barnes
 * @updates and changes by Michael Rivers
 * @version 1.0 May 16th, 2006
 */
public class MikesFilter extends Filter
{
	/**
	 * Constructor for objects of class MikesFilter
	 */
	public MikesFilter(String name)
    {
        super(name);
	}

    /**
     * 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);
                int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
                if(brightness <= 31)
                    image.setPixel(x, y, Color.RED);
                else if(brightness <= 63)
                    image.setPixel(x, y, Color.ORANGE);
                else if(brightness <= 95)
                    image.setPixel(x, y, Color.YELLOW);
                else if(brightness <= 127)
                    image.setPixel(x, y, Color.GREEN);
                else if(brightness <= 159)
                    image.setPixel(x, y, Color.CYAN);
                else if(brightness <= 191)
                    image.setPixel(x, y, Color.BLUE);
                else if(brightness <= 223)
                    image.setPixel(x, y, Color.MAGENTA);
                else
                    image.setPixel(x, y, Color.PINK);
            }
        }
    }
}
