I wrote some quick code that is supposed to invert colors of a BMP image. I test with a 40x40 dimensional BMP image, created by paint. However the function seem to fill it entirelly with white pixels instead.
void
negate
(char *FILE_NAME)
{
FILE* fp = fopen(FILE_NAME, "r+b");
uint_64 raw_data, i;
fseek(fp, 35, SEEK_SET);
//raw_data = fgetc(fp) + fgetc(fp)*256;
raw_data = 4800; // calculated
fseek(fp, 54, SEEK_SET);
for(i = 54; i != 54 + raw_data; i++) // <=
{
int old = fgetc(fp);
fseek(fp, i, SEEK_SET);
fputc(255 - old, fp);
}
fclose(fp);
}
Where am I mistaken?