0

Hi can i ask why the if statements does not execute in this code? I tried running the program and saw that the if statements were not executed.

void sepia(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE original;
for (int i = 0; i < height; i++)
{
    for (int n = 0; n < width; n++)
    {
         original.rgbtRed = image[i][n].rgbtRed;
         original.rgbtGreen = image[i][n].rgbtGreen;
         original.rgbtBlue = image[i][n].rgbtBlue;
         image[i][n].rgbtRed = round(.393 * original.rgbtRed + .769 * original.rgbtGreen + .189 * original.rgbtBlue);
         if (image[i][n].rgbtRed > 255)
         {
             image[i][n].rgbtRed = 255;
         }
         image[i][n].rgbtGreen = round(.349 * original.rgbtRed + .686 * original.rgbtGreen + .168 * original.rgbtBlue);
         if (image[i][n].rgbtGreen > 255)
         {
             image[i][n].rgbtGreen = 255;
         }
         image[i][n].rgbtBlue = round(.272 * original.rgbtRed + .534 * original.rgbtGreen + .131 * original.rgbtBlue);
         if (image[i][n].rgbtBlue > 255)
         {
             image[i][n].rgbtBlue = 255;
         }
    }
}
return;

}

0

RGBTRIPLE only can store 3 values from 0 to 255. You have to check if the result is greater than 255 before assigning the values to the image.

| improve this answer | |

You must log in to answer this question.

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