I'm currently trying to program a function that allows a user to read in an image and they can either flip the image horizontally or vertically, or convert the image to grayscale. I'm having trouble getting the grayscale function to work.
An error says no match for 'operand[]' (operand types are 'Image' and 'int'). Another error says no match for 'operator=' (operand types are 'Image" and 'unsigned char').
How can I get it so the code can run correctly?
void toGrayScale(Image image, Pixel pixel, int width, int height)
{
Image newImage[width][height];
for (int i = 0; i < width; i++){
for (int j = 0; j < height; j++) {
unsigned char color[] = image[width][height];
color[0] = i % 256;
unsigned char red = color[0];
color[1] = j % 256;
unsigned char green = color[1];
color[2] = (i * j) % 256;
unsigned char blue = color[2];
unsigned char gray = round(0.299*red + 0.587*green + 0.114*blue);
newImage[i][j] = gray;
}
}
}
Here's the header file I'm using:
struct Pixel {
int numRows;
int numCols;
char color[];
int red;
int green;
int blue;
};
struct Image {
int width;
int height;
int size;
Pixel pixel;
};
// loads a "P3" PPM formatted image from a file
void loadImage();
// saves an image to a text file as a "P3" PPM formatted image
void saveImage();
// filters an image by converting it to grayscale
void toGrayscale(struct Image);
// manipulates an image by flipping it either vertically or horizontally
void flipImage(struct Image, bool horizontal);