import java.awt.*;

/**
 * This exchanges via translation each quadrant
 * kitty-corner to the quadrant across from it.
 * 
 * @author Michael Kolling and David J Barnes
 * @updates and changes by Michael Rivers
 * @version 1.0 May 14th, 2006
 */
public class QuadrantFilter extends Filter
{
    /**
     * Constructor for objects of class GrayscaleFilter
     */
    public QuadrantFilter(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 h = Math.round(height/2);
        int w = Math.round(width/2);
        for(int y = 0; y < h; y++) {
            for(int x = 0; x < w; x++) {
                Color pixelOne = image.getPixel(x,y);
                Color pixelTwo = image.getPixel(x+w,y+h);
                image.setPixel(x,y,pixelTwo);
                image.setPixel(x+w,y+h,pixelOne);
            }
            for(int x = w; x < 2*w; x++) {
                Color pixelOne = image.getPixel(x,y);
                Color pixelTwo = image.getPixel(x-w,y+h);
                image.setPixel(x,y,pixelTwo);
                image.setPixel(x-w,y+h,pixelOne);
            }
        }
    }
}
