我已经为反射编写了这段代码,当我使用check50时,得到了以下内容:
:( reflect correctly filters 1x2 image
expected "0 0 255\n255 0...", not "0 0 255\n0 0 2..."
:( reflect correctly filters 1x3 image
expected "0 0 255\n0 255...", not "0 0 255\n0 255..."
:) reflect correctly filters image that is its own mirror image
:( reflect correctly filters 3x3 image
expected "70 80 90\n40 5...", not "70 80 90\n40 5..."
:( reflect correctly filters 4x4 image
expected "100 110 120\n7...", not "100 110 120\n7..."
但是这些数字似乎是相同的...
这是我的反射功能:
/ Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
//Cycle through rows
for (int i = 0; i < height; i++)
{ //Cycle through columns
for (int j = 0; j < width; j++)
{ //Swap the current cell with oppsite cell.
image[i][j].rgbtRed = image[i][width - j - 1].rgbtRed;
image[i][j].rgbtBlue = image[i][width - j - 1].rgbtBlue;
image[i][j].rgbtGreen = image[i][width - j - 1].rgbtGreen;
}
}
return;
}
答案 0 :(得分:0)
首先,我想指出一下check50仅显示了很小的像素子集;仅仅因为您正确反射了前2-3个像素,并不意味着所有像素都是正确的。
也就是说,这是改善代码的三个建议:
j < round(width / 2.0)
来实现此目的。image[i][j]
而不是image[i][j].rgbtRed
和其他所有颜色。在涉及颜色失真的其他部分,您需要处理颜色。