0
void reflect (int height, int width, RGBTRIPLE image[height][width])
{
    
    RGBTRIPLE invert[height][width];
    
    for (int i=0; i<height; i++)
    {
        for (int j=width,s=0; j>=0; j--,s++)
        { 
            invert[i][s]=image[i][j];  
        }
    }
   
    for (int l=0; l<height; l++)
    {
        for (int k=0; k<width; k++)
        { 
            image[l][k]=invert[l][k];
        }
    }
    return;
}
1
  • Please give more details.
    – an4s911
    Oct 31, 2021 at 10:51

1 Answer 1

0

Sorry, it only looks correctly reflected. In fact, every pixel has been moved one positon away from where it should be. I'll let you figure out what's wrong with the first and last pixel in each row.

If you want to test it, create a 3x3 image and see what happens. (Aren't there some of those available from recent psets?)

It's a simple mistake, really an oversight. Take a very close look at the for loop setup:

    for (int j=width,s=0; j>=0; j--,s++)
    { 
        invert[i][s]=image[i][j];  
    }

Notice that at the start, j=width. Isn't width the size of the array? What's the last element in the row? Is it j or j-1? width or width - 1????

This is an excellent demonstration of why it's necessary to examine raw output data, rather than just looking at a produced image. There could easily be errors in the data that aren't visually obvious. (Of course, a quick check of an image can show if there's a major issue.)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • yeah i just figured it out after posting this Nov 3, 2021 at 15:44

You must log in to answer this question.

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