If in the below snippet of code (at the bottom of this post) I need to write a function that will turn a BMP into grayscale, how would I go about? Note that the main
of the program is already written, and has all the open/close file features etc. written - this just needs the function itself.
My assignment requires that for each pixel the values of red, green, and blue are converted into an average value of the three so as to become somewhat grayscale, but am at a loss of how to even begin.
The following libraries are included - again, note that this is in a separate file:
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
Here's the snippet of code I have to fill out:
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
return;
}
I have played around with the below potential solution, but my use of image[height][width]
doesn't seem to work. And then of course I need to replace the 0x00
with a calculation that provides the average of the three. But not quite sure how to go about improving this.
{
if(( image[height][width].rgbtRed==0xff && image[height][width].rgbtBlue==0x00 && image[height][width].rgbtGreen==0x00)||(image[height][width].rgbtRed==0xff && image[height][width].rgbtBlue==0xff && image[height][width].rgbtGreen==0xff))
{
image[height][width].rgbtRed=0x00;
image[height][width].rgbtBlue=0x00;
image[height][width].rgbtGreen=0x00;
}
return;
}
(I apologize if my lingo is mistaken - I'm a very novice learner.)