【发布时间】:2021-01-03 17:57:03
【问题描述】:
您好,我的 cs50 课程的棕褐色过滤器有问题,这是它给我的错误。我真的不确定问题是什么。如果有人可以帮助我,那就太好了
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
double sepiaRed;
double sepiaGreen;
double sepiaBlue;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
sepiaRed = (0.393 * image[i][j].rgbtRed) + (0.769 * image[i][j].rgbtGreen) + (0.189 * image[i][j].rgbtBlue);
sepiaGreen = (0.349 * image[i][j].rgbtRed) + (0.686 * image[i][j].rgbtGreen) + (0.168 * image[i][j].rgbtBlue);
sepiaBlue = (0.272 * image[i][j].rgbtRed) + (0.534 * image[i][j].rgbtGreen) + (0.131 * image[i][j].rgbtBlue);
if( sepiaRed > 255)
{
image[i][j].rgbtRed = 255;
}
else if(sepiaGreen > 255)
{
image[i][j].rgbtGreen = 255;
}
else if(sepiaBlue > 255){
image[i][j].rgbtBlue = 255;
}
else{
image[i][j].rgbtRed = round(sepiaRed);
image[i][j].rgbtGreen = round(sepiaGreen);
image[i][j].rgbtBlue = round(sepiaBlue);
}
}
}
return;
}
【问题讨论】:
-
您应该在专门的 CS50 StackExchange 站点 cs50.stackexchange.com 中提出这个问题
-
浮点运算几乎总是会导致复合舍入错误,可能会导致错误的结果。尝试找出一种不使用浮点运算的方法来进行计算。
-
谢谢大家,这也有助于我的知识谢谢