0

I can't find why it doesn't work. That's the error message: index 600 out of bounds for type 'RGBTRIPLE [width] And I think it makes half reflection and half stays the same...

That's my code:

// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{       RGBTRIPLE copy[height][width];

    //Temporary copy of the array
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            copy[i][j].rgbtRed = image[i][j].rgbtRed;
            copy[i][j].rgbtGreen = image[i][j].rgbtGreen;
            copy[i][j].rgbtBlue = image[i][j].rgbtBlue;
        }
    }
    //Reflect
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j].rgbtRed = copy[i][width - 1 - j].rgbtRed;
            image[i][j].rgbtGreen = copy[i][width - 1 - j].rgbtGreen;
            image[i][j].rgbtBlue = copy[i][width - 1 - j].rgbtBlue;
        }
    }


    return;
}

2 Answers 2

0

I've tried your code and it works just fine. It flips the image correctly. I can´t see anything wrong. What line did you get in the error message?

0

Your code works but I made it a bit shorter:

// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width]) 
{
RGBTRIPLE temp[height][width];

//Temporary copy of the array
for (int i = 0; i < height; i++)
{
    for (int j = 0; j < width; j++)
    {
        temp[i][j] = image[i][j];
    }
}

// Reflect
   for (int i = 0; i < height; i++)
    {   
    int position = 0;
    for (int j = width -1; j >= 0; j--, position++)
    {
        image[i][position] = temp[i][j];
    }
 }
 return; 
}

You must log in to answer this question.

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