0

below is my code for Pset4 filter(less). the code compiles fine, but I was getting these errors from check50. really appreciate if anyone can help. thanks

:( sepia correctly filters single pixel
    expected "56 50 39\n", not "47 41 39\n"

:( sepia correctly filters simple 3x3 image
    expected "100 89 69\n100...", not "191 101 69\n19..."

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

:( sepia correctly filters 4x4 image
    expected "25 22 17\n66 5...", not "23 20 17\n67 5..."
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            int sepiaBlue = round(.272 * image[i][j].rgbtRed + .534 * image[i][j].rgbtGreen + .131 * image[i][j].rgbtBlue);
            image[i][j].rgbtBlue = sepiaBlue>255 ? 255 : sepiaBlue;

            int sepiaGreen = round(.349 * image[i][j].rgbtRed + .686 * image[i][j].rgbtGreen + .168 * image[i][j].rgbtBlue);
            image[i][j].rgbtGreen = sepiaGreen>255 ? 255 : sepiaGreen;

            int sepiaRed = round(.393 * image[i][j].rgbtRed + .769 * image[i][j].rgbtGreen + .189 * image[i][j].rgbtBlue);
            image[i][j].rgbtRed = sepiaRed>255 ? 255 : sepiaRed;
        }
    }
    return;
}

the idea of Ternary Operator came from Cliff B's answer of Cs50 Sepia properly coded

2

just fixed it. so the code was wrote in wrong order and the Ternary Operator was missing a ()

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

            image[i][j].rgbtBlue = (sepiaBlue > 255) ? 255 : sepiaBlue;
            image[i][j].rgbtGreen = (sepiaGreen > 255) ? 255 : sepiaGreen;
            image[i][j].rgbtRed = (sepiaRed > 255) ? 255 : sepiaRed;
        }
    }
    return;
}

You must log in to answer this question.

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