public Channel rotate(int degrees) {
Channel channel = null;
int tmp = width;
switch (degrees) {
case 90:
channel = new Channel(height, width);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
channel.putPixel(y, width - x - 1, getPixel(x, y));
}
}
width = height;
height = tmp;
break;
case 180:
channel = new Channel(width, height);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
channel.putPixel(width - x - 1, height - y - 1, getPixel(x, y));
}
}
break;
case 270:
channel = new Channel(height, width);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
channel.putPixel(height - y - 1, x, getPixel(x, y));
}
}
width = height;
height = tmp;
break;
default:
throw new Exception("Rotation degrees not a multiple of 90");
}
pixels = channel.getPixels();
return this;
}