CS50 Filter Reflect

disclaimer

DO NOT READ THIS IF YOU HAVEN’T SOLVED THIS FILTER YET! REMEMBER ACADEMIC ETHICS!

Well this code is self explanatory, we have one loop which basically copies the whole original image to tempImage, and second loop the places these pixels backwards on to original image from tempImage. This way there’s no need to check if width is even or odd.

Although this is kinda janky and bloated.

void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE tempImage[height][width];

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            tempImage[i][j] = image[i][j];
        }
    }

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][width - j - 1] = tempImage[i][j];
        }
    }

    return;
}