0

i am missing something here...but not sure what... it doesn't work on normal images... check50 passes for 1X2 and 1X3 images but fails for 3x3 and 4x4 images (so i guess it is an issue of iterating through the rows ..but that`s what the first for loop does ...i m confused.. :(

void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    //loop through the rows
    for (int i = 0; i < height; i++)
    {
        int hwidth = round(width / 2);
        
        //swap the first half of pixels with last half
        for (int j = 0; j < hwidth; j++, width--)
        {
            RGBTRIPLE temp = image[i][j];
            image[i][j] = image[i][width - 1 - j];
            image[i][width - 1 - j] = temp;
        }
    }
    return;
}
0

I think the issue is "int hwidth = round(width / 2);" When you are rounding it then if say width/2 == 3.5, it would become 4. and that would mess up the filter as in this case 4 would be middle pixel which shouldn't change.

| improve this answer | |
0

oh well ...i am an idiot indeed....the 'width--' should not have been there...if j is increasing and width is decreasing it s like adding 1 and then subtracting 1...nothing changes...

| improve this answer | |

You must log in to answer this question.

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