0
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            float redS = .393 * (float) image[i][j].rgbtRed + .769 * (float) image[i][j].rgbtGreen + .189 * (float) image[i][j].rgbtBlue;
            float greenS = .349 * (float) image[i][j].rgbtRed + .686 * (float) image[i][j].rgbtGreen + .168 * (float) image[i][j].rgbtBlue;
            float blueS = .272 * (float) image[i][j].rgbtRed + .534 * (float) image[i][j].rgbtGreen + .131 * (float) image[i][j].rgbtBlue;

            int r = round(redS);
            int g = round(greenS);
            int b = round(blueS);

            image[i][j].rgbtRed = r;
            image[i][j].rgbtGreen = g;
            image[i][j].rgbtBlue = b;

        }
    }
    return;
}

this is the code i wrote, but what check50 says:

:( sepia correctly filters more complex 3x3 image expected "25 22 17\n66 5...", not "25 22 17\n66 5..."

:( sepia correctly filters 4x4 image expected "25 22 17\n66 5...", not "25 22 17\n66 5..."

1
  • What is the output that you get when you go to the link provided by check50?
    – Luke
    Jan 2, 2021 at 12:45

1 Answer 1

0

The issue you are likely running into is that the formula for each color can return a value that is greater than 255, which is not value for an 8-bit color value. You can look to add a ternary statement to check whether the value is larger than 255 and to adjust the image accordingly.

image[i][j].rgbtRed = r > 255 ? 255 : r;
image[i][j].rgbtGreen = g > 255 ? 255 : g;
image[i][j].rgbtBlue = b > 255 ? 255 : b;

You must log in to answer this question.

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