0

I just ran my code through check50 and it's throwing the following errors:

:( sepia correctly filters more complex 3x3 image

:( sepia correctly filters 4x4 image

But I looked further into the issue and all the values my code produces are correct? screenshot of check50 showing above errors, but no difference between expected output and actual output

I looked into other people's questions for this, but I think I'm rounding correctly and checking for the upper limit, so why is it flagging incorrect?

    void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    int sepiaRed = 0;
    int sepiaGreen = 0;
    int sepiaBlue = 0;

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            float originalRed = image[i][j].rgbtRed;
            float originalGreen = image[i][j].rgbtGreen;
            float originalBlue = image[i][j].rgbtBlue;

            sepiaRed = round(0.393 * originalRed + 0.769 * originalGreen + 0.189 * originalBlue);
            sepiaGreen = round(0.349 * originalRed + 0.686 * originalGreen + 0.1688 * originalBlue);
            sepiaBlue = round(0.272 * originalRed + 0.534 * originalGreen + 0.131 * originalBlue);

            if (sepiaRed > 255)
            {
                sepiaRed = 255;
            }
            if (sepiaGreen > 255)
            {
                sepiaGreen = 255;
            }
            if (sepiaBlue > 255)
            {
                sepiaBlue = 255;
            }

            image[i][j].rgbtRed = sepiaRed;
            image[i][j].rgbtGreen = sepiaGreen;
            image[i][j].rgbtBlue = sepiaBlue;
        }
    }
    return;
}

1 Answer 1

0

This is why it's important to look really, really carefully at everything. ;-)

First of all, your program's output is not correct. In both cases, exactly one color value in only one pixel is wrong, and it happens to be the same pixel with the same error! Go figure!

BTW, it's a good thing that you weren't entirely sure if the output was correct. Tells me that you had an idea that something really was wrong and you thought that maybe you missed it. that's a good thing. ;-)

Look at the middle value of the third pixel in each result. Your code is producing 106 95 74. The correct values are 106 94 74. You have an off-by-1 error. These are usually produced by a bug in a counter (often a loop counter) for int values or an issue with a calculation.

Now, all you need to do is track down the error. Hint: are the formulas absolutely correct? ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thank you!! I wasn't looking closely enough! All is fixed now :-)
    – scarmonies
    Commented Feb 20, 2023 at 1:59

You must log in to answer this question.

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