import java.awt.*;

/**
 * This filter makes the threshold filter break
 * the image up into more sections by brightness,
 * and then instead of setting each level of brightness
 * to a gray value, it sets each one to a rainbow
 * color predefined in the java libraries.
 * 
 * @author Michael Kolling and David J Barnes
 * @updates and changes by Michael Rivers
 * @version 1.0 May 14th, 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);
            }
        }
    }
}
