I'm working on Sepia (2020 problem set 4- filter). The command window printed out the following error message:
helpers.c:33:29: runtime error: 260 is outside the range of representable values of type 'unsigned char'
helpers.c:34:31: runtime error: 263 is outside the range of representable values of type 'unsigned char'
But I did assign 255 to all values above 255. The command window also did not print out the printf("color\n") I used to debug. Please help. Thank you.
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
// loop thorough rows
for (int i = 0; i < height; i++)
{
// loop through columns
for (int j = 0; j < width; j++)
{
// store original values
BYTE originalRed = image[i][j].rgbtRed;
BYTE originalGreen = image[i][j].rgbtGreen;
BYTE originalBlue = image[i][j].rgbtBlue;
// calculate sepia effect
BYTE sepiaRed = round(.393 * originalRed + .769 * originalGreen + .189 * originalBlue);
BYTE sepiaGreen = round(.349 * originalRed + .686 * originalGreen + .168 * originalBlue);
BYTE sepiaBlue = round(.272 * originalRed + .534 * originalGreen + .131 * originalBlue);
// cap valus over 255
if (sepiaRed > 255)
{
printf("red\n");
sepiaRed = 255;
}
if (sepiaGreen > 255)
{
printf("green\n");
sepiaGreen = 255;
}
if (sepiaBlue > 255)
{
printf("blue\n");
sepiaBlue = 255;
}
// assign the new sepia values
image[i][j].rgbtBlue = sepiaBlue;
image[i][j].rgbtGreen = sepiaGreen;
image[i][j].rgbtRed = sepiaRed;
}
}
return;
}