为什么我们不在helpers.c 中使用指针?我注意到下面的代码已经通过了 check50,但是它如何转换 filter.c 中的变量“image”?
#include "helpers.h"
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
float tmp;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
tmp = (image[i][j].rgbtBlue + image[i][j].rgbtRed + image[i][j].rgbtGreen)/3.0;
image[i][j].rgbtBlue = (int)(tmp + 0.5);
image[i][j].rgbtRed = (int)(tmp + 0.5);
image[i][j].rgbtGreen = (int)(tmp + 0.5);
}
}
return;
}
这是因为当你设置
image[i][j].rgbtBlue, image[i][j].rgbtGreen, image[i][j].rgbtRed.
的值时,你正在写入文件
双循环内的以下代码行在做什么?
image[i][j].rgbtBlue = (int)(tmp + 0.5);
image[i][j].rgbtRed = (int)(tmp + 0.5);
image[i][j].rgbtGreen = (int)(tmp + 0.5);
他们正在逐像素地更改位图图像文件。该文件位于辅助存储器中。它与变量的指针或其在主内存中的地址无关。