<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.awt.image.BufferedImage;

public class ImageConverter {

    private int[][] imageData = Comp202ImageIO.loadImage("rangers.jpg"); // you probably will want to change this line later.....
    private int height;
    private int width;

    public int getHeight() {
	return this.height;
    }
 
    public int getWidth() {
	return this.width;
    }

    public ImageConverter(String filename, String[] args) {
	//FILL IN THE CONSTRUCTOR TO LOAD FROM filename instead of rangers.jpg
	this.imageData = Comp202ImageIO.loadImage(filename);
	this.height = Comp202ImageIO.getImageHeight(filename);
	this.width = Comp202ImageIO.getImageWidth(filename);
    }

    public void rotate90DegreesClockwise() {
	//first expand the arrays
	int[][] alpha = unflattenArray(imageData[0], this.width);
	int[][] red = unflattenArray(imageData[1], this.width);
	int[][] green = unflattenArray(imageData[2], this.width);
	int[][] blue = unflattenArray(imageData[3], this.width);

	//now perform the rotations
	int[][] newAlpha = MatrixUtilities.rotateRight(alpha);
	int[][] newRed = MatrixUtilities.rotateRight(red);
	int[][] newGreen = MatrixUtilities.rotateRight(green);
	int[][] newBlue = MatrixUtilities.rotateRight(blue);

	//switch the width and heights:
	int temp = this.width;
	this.width = this.height;
	this.height = temp;

	//now fill imageData with the new arrays
	imageData[0] = flattenArray(newAlpha);
	imageData[1] = flattenArray(newRed);
	imageData[2] = flattenArray(newGreen);
	imageData[3] = flattenArray(newBlue);
    }

    public void rotate90DegreesCounterClockwise() {
	this.rotate90DegreesClockwise();
	this.rotate90DegreesClockwise();
	this.rotate90DegreesClockwise();
    }

    public void flipHorizontal() {
	//first expand the arrays
	int[][] alpha = unflattenArray(imageData[0], this.width);
	int[][] red = unflattenArray(imageData[1], this.width);
	int[][] green = unflattenArray(imageData[2], this.width);
	int[][] blue = unflattenArray(imageData[3], this.width);

	//now perform the rotations
	int[][] newAlpha = MatrixUtilities.horizontalMirror(alpha);
	int[][] newRed = MatrixUtilities.horizontalMirror(red);
	int[][] newGreen = MatrixUtilities.horizontalMirror(green);
	int[][] newBlue = MatrixUtilities.horizontalMirror(blue);

	//now fill imageData with the new arrays
	imageData[0] = flattenArray(newAlpha);
	imageData[1] = flattenArray(newRed);
	imageData[2] = flattenArray(newGreen);
	imageData[3] = flattenArray(newBlue);
    }

    public void flipVertical() {
	//first expand the arrays
	int[][] alpha = unflattenArray(imageData[0], this.width);
	int[][] red = unflattenArray(imageData[1], this.width);
	int[][] green = unflattenArray(imageData[2], this.width);
	int[][] blue = unflattenArray(imageData[3], this.width);

	//now perform the rotations
	int[][] newAlpha = MatrixUtilities.verticalMirror(alpha);
	int[][] newRed = MatrixUtilities.verticalMirror(red);
	int[][] newGreen = MatrixUtilities.verticalMirror(green);
	int[][] newBlue = MatrixUtilities.verticalMirror(blue);

	//now fill imageData with the new arrays
	imageData[0] = flattenArray(newAlpha);
	imageData[1] = flattenArray(newRed);
	imageData[2] = flattenArray(newGreen);
	imageData[3] = flattenArray(newBlue);
    }

    private int[] flattenArray(int[][] originalArray) {
	int[] flattenedArray = new int[originalArray.length * originalArray[0].length];
	for (int i=0; i &lt; originalArray.length; i++) {
		for (int j=0; j &lt; originalArray[0].length; j++) {
			flattenedArray[i * originalArray[0].length + j] = originalArray[i][j];
		}
	}

	return flattenedArray;
    }

    private int[][] unflattenArray(int[] originalArray, int width) {
	int height = originalArray.length / width;
	int[][] unflattenedArray = new int[height][width];

	for (int i=0; i &lt; height; i++) {
		for (int j=0; j &lt; width; j++) {
			unflattenedArray[i][j] = originalArray[i * width + j];
		}
	}

	return unflattenedArray;
    }

    /*don't modify the below method! */
    public BufferedImage getBufferedImage() {
	return Comp202ImageIO.getBufferedImage(imageData, this.getHeight(), this.getWidth());
    }
}
</pre></body></html>