I am trying to modify a bitmap file and in order to do this, I need its size.
I am pretty sure I read the headers properly, I used these structs(btw, using C) :
#pragma pack(1)
struct bmp_fileheader
{
unsigned char fileMarker1; /* 'B' */
unsigned char fileMarker2; /* 'M' */
unsigned int bfSize; /* File's size */
unsigned short unused1;
unsigned short unused2;
unsigned int imageDataOffset; /* Offset to the start of image data */
};
struct bmp_infoheader
{
unsigned int biSize; /* Size of the info header - 40 bytes */
signed int width; /* Width of the image */
signed int height; /* Height of the image */
unsigned short planes;
unsigned short bitPix;
unsigned int biCompression;
unsigned int biSizeImage; /* Size of the image data */
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
};
#pragma pack()
At the end of the day I am getting a buggy result, and I think it's because the bfSize doesn't match the properties of the file. (right click properties differs from printf bfSize.
From what I understand from this link (https://en.wikipedia.org/wiki/BMP_file_format#Example_1 ), the bfSize should contain the whole size, including the padding.
Is it okay if the bfSize differs from properties?
I just got an idea, do you think that my buggy result is because I read the structs using pragma pack, then I continue reading from the file, as if I read from where the pixels' array starts?
I am using something like
FILE *pf
I read those structs.
I calculate the number of octets stored inside the pixels' array.
Then I read those octets continuing from pf's location, which should be, according to my logic, exactly where the array starts.
Thanks for reading.
edit: ps: those differences are something like: bfSize says 3645 and on the properties it displays 3702, which is a pretty big difference. The bfSize number is always less than the properties number, when it differs.