public static BufferedImage magnifyX2(BufferedImage input) {

        BufferedImage result = new BufferedImage(input.getWidth() * 2, input.getHeight() * 2, input.getType());


        for (int i = 0; i < result.getWidth(); i++) {
            for (int j = 0; j < result.getHeight(); j += 2) {

                if (i % 2 == 0) {
                    result.setRGB(i, j, input.getRGB(i / 2, j / 2));
                } else {
                    Color left = new Color(input.getRGB((i - 1)/2, j / 2));
                    Color right = new Color(input.getRGB((i + 1) % result.getWidth() / 2, j / 2));
                    result.setRGB(i, j, new Color(
                                    (left.getRed() + right.getRed()) / 2,
                                    (left.getGreen() + right.getGreen()) / 2,
                                    (left.getBlue() + right.getBlue()) / 2).getRGB()
                    );
                }
            }
        }

        for (int i = 0; i < result.getWidth(); i++) {
            for (int j = 1; j < result.getHeight(); j += 2) {

                Color up = new Color(result.getRGB(i, j - 1));
                Color down = new Color(result.getRGB(i, (j + 1)%result.getHeight()));
                result.setRGB(i, j, new Color(
                                (up.getRed() + down.getRed()) / 2,
                                (up.getGreen() + down.getGreen()) / 2,
                                (up.getBlue() + down.getBlue()) / 2).getRGB()
                );
            }
        }

        return result;
    }