I'm trying to read an image into a 2D array and then make modifications to its RGB values and create a resize function next. The dimensions of the image aren't known until the image is loaded so it looks something like this.
I've tried passing in "pixels" into the unsigned char ** and pixels[0][0] to unsigned char* and quite a few other ways I can't remember. I've searched around the web for different methods but none of them seem to work. I've seen that if you define the size of one of the arrays like pixels[][40] it works, but I don't know the size until after the image is loaded.
void invertImg(unsigned char **img, int height, int width)
{
int h, w;
for (h = 0; h < height; h++){
for (w = 0; w < width * 3; w += 3){
//Blue
img[h][w] = ~img[h][w];
//Green
img[h][w + 1] = ~img[h][w + 1];
//Red
img[h][w + 2] = ~img[h][w + 2];
}
}
}
// Get Image name and desired dimensions
char header[54];
unsigned char pixels[height][width * 3];
FILE *in = fopen(img, "rb");
FILE *out = fopen("out.bmp", "wb");
fread(header, 1, 54, in);
fread(pixels, 1, height * width * 3, in);
//function that the 2d array needs to be passed into
invertImg(pixels, height, width);
fwrite(header, sizeof(char), HEADER_SIZE, out);
fwrite(pixels, sizeof(char), height * width * 3, out);
fclose(in);
fclose(out);
How can I get this unsigned char array into the function to be able to modify its values?