[英]CS50 pset 4 // sepia filter
Hello I am having an issue with the sepia filter for my cs50 course this is the error it gives me.I am really not sure what the issue is.您好,我的 cs50 课程的棕褐色过滤器有问题,这是它给我的错误。我真的不确定问题是什么。 If anyone could help me that would be great
如果有人可以帮助我,那就太好了
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;
} }
In the cases where you clamp one component to 255
you have not updated the other components.在您将一个组件限制为
255
的情况下,您尚未更新其他组件。 I suggest changing the faulty logic in this section of the code我建议更改这部分代码中的错误逻辑
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);
}
to this, which clamps each component and then writes them all为此,它会钳住每个组件,然后将它们全部写入
if(sepiaRed > 255) {
sepiaRed = 255;
}
if(sepiaGreen > 255) {
sepiaGreen = 255;
}
if(sepiaBlue > 255) {
sepiaBlue = 255;
}
image[i][j].rgbtRed = round(sepiaRed);
image[i][j].rgbtGreen = round(sepiaGreen);
image[i][j].rgbtBlue = round(sepiaBlue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.