Mistři v programování na #hovnokod

Java #723

public class ImageRotator {

    public static BufferedImage rotate(BufferedImage originalImage, int angle) {
        BufferedImage image = null;
        switch (angle) {
            case 90:
            case -270:
                image = ImageRotator.rotate90Right(originalImage);
                break;
            case 270:
            case -90:
                image = ImageRotator.rotate90Left(originalImage);
                break;
            case 180:
            case -180:
                image = ImageRotator.rotate180(originalImage);
                break;
            default:
                image = originalImage;
                break;
        }
        return image;
    }

    private static BufferedImage rotate90Left(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                biFlip.setRGB(height - 1 - j, width - 1 - i, bi.getRGB(i, j));
            }
        }
        return biFlip;
    }

    private static BufferedImage rotate90Right(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                biFlip.setRGB(j, i, bi.getRGB(i, j));
            }
        }
        return biFlip;
    }

    private static BufferedImage rotate180(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                biFlip.setRGB(i, j, bi.getRGB(width - 1 - i, height - 1 - j));
            }
        }
        return biFlip;
    }
}

HovnoKod,