import java.awt.*;

/**
 * This mirrors the image horizontally (across the
 * vertical axis).
 * 
 * @author Michael Kolling and David J Barnes
 * @updates and changes by Michael Rivers
 * @version 1.0 May 16th, 2006
 */
public class MirrorFilter extends Filter
{
    /**
     * Constructor for objects of class GrayscaleFilter
     */
    public MirrorFilter(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();
        int w = Math.round((width-1)/2);
        for(int y = 0; y < height; y++) {
            for(int x = 0; x < w; x++) {
                int d = w - x;
                    Color pixelOne = image.getPixel(x,y);
                    Color pixelTwo = image.getPixel(w+d,y);
                    image.setPixel(x,y,pixelTwo);
                    image.setPixel(w+d,y,pixelOne);
            }
        }
    }
}
