0

I am coding the sepia filter, it is already working, but it does not pass the check50. I think of according to the check50 report, that there is some problem of precision in the calculations, but I can't find the error. What can it be ?

float sepiaRed   = round(0.393 * image[h][w].rgbtRed + 0.769 * image[h][w].rgbtGreen + 0.189 * image[h][w].rgbtBlue);
float sepiaGreen = round(0.349 * image[h][w].rgbtRed + 0.686 * image[h][w].rgbtGreen + 0.168 * image[h][w].rgbtBlue);
float sepiaBlue  = round(0.272 * image[h][w].rgbtRed + 0.534 * image[h][w].rgbtGreen + 0.131 * image[h][w].rgbtBlue);

Thank You

0
int sepiaRed = round((0.393 * image[h][w].rgbtRed) + (0.769 * image[h][w].rgbtGreen) + (0.189 * image[h][w].rgbtBlue));
int sepiaGreen = round((0.349 * image[h][w].rgbtRed) + (0.686 * image[h][w].rgbtGreen) + (0.168 * image[h][w].rgbtBlue));
int sepiaBlue = round((0.272 * image[h][w].rgbtRed) + (0.534 * image[h][w].rgbtGreen) + (0.131 * image[h][w].rgbtBlue));

From the problem description page,

Be sure to round any floating-point numbers to the nearest integer when assigning them to a pixel value

Also beneficial to know about operator precedence in C

3
  • I change my code, but i can't success the check50. Look it. :)
    – Code Maker
    Apr 24 at 17:10
  • @CodeMaker Hmm.. looks like this part is fine, perhaps problem with loops
    – C--
    Apr 24 at 17:45
  • Yes, Thank You for help.
    – Code Maker
    Apr 24 at 17:59

You must log in to answer this question.

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