2

Why we don't use a pointer in helpers.c? I noticed that check50 has passed for my code below, but how does it convert the variable "image" in filter.c?

`#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;
    }

`
Sakib Arifin
  • 255
  • 2
  • 13
Yang00
  • 21
  • 2

1 Answers1

1

It's because you are writing to a file when you set the values of image[i][j].rgbtBlue, image[i][j].rgbtGreen, image[i][j].rgbtRed.

What are the following lines of your code inside the double loop doing?

image[i][j].rgbtBlue = (int)(tmp + 0.5);
image[i][j].rgbtRed = (int)(tmp + 0.5);
image[i][j].rgbtGreen = (int)(tmp + 0.5);

They are changing the bitmap image file pixel by pixel. The file is in secondary memory. It doesn't relate to pointers of the variables or their addresses in main memory.

Sakib Arifin
  • 255
  • 2
  • 13