Skip to main content
1 of 2

Filter - Structures & Headers

The problem statement states that BMP files have a particular header with: (1) BITMAPFILEHEADER 14 bytes long and (2) BITMAPINFOHEADER 40 bytes long.

bmp.h (provided) includes the definitions of the structures such as for BITMAPINFOHEADER. I am thinking in terms of memory storage/allocation and trying to understand the following:

If BITMAPINFOHEADER is 40 bytes and the first 4 bytes correspond to the size, the following 4 bytes correspond to the Width, ... how do the fields point to the subset of bytes? How does the dot notation access memory addresses?

typedef uint8_t  BYTE;
typedef uint32_t DWORD;
typedef int32_t  LONG;
typedef uint16_t WORD;

typedef struct
{
DWORD  biSize;
LONG   biWidth;
LONG   biHeight;
WORD   biPlanes;
WORD   biBitCount;
DWORD  biCompression;
DWORD  biSizeImage;
LONG   biXPelsPerMeter;
LONG   biYPelsPerMeter;
DWORD  biClrUsed;
DWORD  biClrImportant;
} __attribute__((__packed__))
BITMAPINFOHEADER;