The following code keeps on giving me bugs about something I can't figure out when checking with check50 and I'm not sure what's wrong.
here's the code:
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < width; i++)
{
for (int d = 0; d < height; d++)
{
float avg = (float)(image[d][i].rgbtRed + image[d][i].rgbtBlue + image[d][i].rgbtGreen) / (float) 3;
int average = (int) ceilf(avg);
image[d][i].rgbtRed = average;
image[d][i].rgbtBlue = average;
image[d][i].rgbtGreen = average;
}
}
return;
}
// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < width; i++)
{
for (int d = 0; d < height; d++)
{
int originalRed = image[d][i].rgbtRed;
int originalBlue = image[d][i].rgbtBlue;
int originalGreen = image[d][i].rgbtGreen;
int newRed = (int)((float)round(.393 * originalRed + .769 * originalGreen + .189 * originalBlue));
int newGreen = (int)((float)round(.349 * originalRed + .686 * originalGreen + .168 * originalBlue));
int newBlue = (int)((float)round(.272 * originalRed + .534 * originalGreen + .131 * originalBlue));
image[d][i].rgbtRed = fmin(255, newRed);
image[d][i].rgbtGreen = fmin(255, newGreen);
image[d][i].rgbtBlue = fmin(255, newBlue);
return;
}
}
}
And here are the frowny faces:
for grayscale:
:( grayscale correctly filters more complex 3x3 image
expected "20 20 20\n50 5...", not "20 20 20\n50 5..."
for sepia:
:( sepia correctly filters simple 3x3 image
expected "100 89 69\n100...", not "100 89 69\n255..."
:( sepia correctly filters more complex 3x3 image
expected "25 22 17\n66 5...", not "25 22 17\n40 5..."
:( sepia correctly filters 4x4 image
expected "25 22 17\n66 5...", not "25 22 17\n40 5..."
Any help is much appreciated. Thank you very much :)