0

I have the following code below. The code compiles correctly, but the resulting images is exactly the same as the one that was used as the input file. I have gone through each line multiple times and logic seems to checkout just fine but its clearly not. Wondering if anyone here can guide me as to where the flaw is in this logic.

Thank you.

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

    int mid_width = floor(width/2.0);

    for (int i = 0; i < height; i++)

    if(width % 2 != 0)
    {
        for (int j = 0, diff = mid_width - j; j <= mid_width; j++)
        {

        //purpose of the following code is to copy the integer BGR values of the pixel in column j row i to a temp int variable.
        RGBTRIPLE temp = image[i][j];

        //purpose of the following code is to copy the integer BGR values of the pixel in column (mid_width + diff) row i to the pixel in column j row i.
         image[i][j] = image[i][mid_width + diff];

         //purpose of the following code is to the copy the integer BGR values of the pixel in the temp int varable created in the stack above, into the integer BGR values of the pixel in column (mid_width + diff) row i
         image[i][mid_width + diff] = temp;
        }

    }

    else
    {
        for (int j = 0, diff = mid_width - j; j < mid_width; j++)
        {

            //purpose of the following code is to copy the integer BGR values of the pixel in column j row i to a temp int variable.
        RGBTRIPLE temp = image[i][j];

        //purpose of the following code is to copy the integer BGR values of the pixel in column (mid_width + diff - 1) row i to the pixel in column j row i.

         image[i][j] = image[i][mid_width + diff - 1];

         //purpose of the following code is to the copy the integer BGR values of the pixel in the temp int varable created in the stack above, into the integer BGR values of the pixel in column (mid_width + diff - 1) row i
         image[i][mid_width + diff - 1] = temp;

        }
    }

    return;
}
1
  • I don't understand your code image[i][mid_width + diff - 1]; why not just say image[i][width - 1 -i], width - 1 is equal to the edge of the image in the right side.
    – Ojou Nii
    Apr 11 '20 at 8:36
0

You have a for loop and then an if/ else loop with for loops nested inside each of them. The first for loop is for the height, and the second(2) loops for the width. What if you were to have the two for loops nested inside of each other; height, then width, then the if/ else loops dividing the even/ odd widths. This might might it a little more streamlines and even affect the outcome, especially because the second 2 for loops are identical. Good luck!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .