Monday, June 28, 2010

What is in the bitmap header

from -


The header consists of the following fields. Note that we are assuming
short int of 2 bytes, int of 4 bytes, and long int of 8 bytes. Further
we are assuming byte ordering as for typical (Intel) machines. The
header is 14 bytes in length.

typedef struct {
unsigned short int type; /* Magic identifier */
unsigned int size; /* File size in bytes */
unsigned short int reserved1, reserved2;
unsigned int offset; /* Offset to image data, bytes */

The useful fields in this structure are the type field (should be
'BM') which is a simple check that this is likely to be a legitimate
BMP file, and the offset field which gives the number of bytes before
the actual pixel data (this is relative to the start of the file).
Note that this struct is not a multiple of 4 bytes for those
machines/compilers that might assume this, these machines will
generally pad this struct by 2 bytes to 16 which will unalign the
future fread() calls - be warned.

The image info data that follows is 40 bytes in length, it is
described in the struct given below. The fields of most interest below
are the image width and height, the number of bits per pixel (should
be 1, 4, 8 or 24), the number of planes (assumed to be 1 here), and
the compression type (assumed to be 0 here).

typedef struct {
unsigned int size; /* Header size in bytes */
int width,height; /* Width and height of image */
unsigned short int planes; /* Number of colour planes */
unsigned short int bits; /* Bits per pixel */
unsigned int compression; /* Compression type */
unsigned int imagesize; /* Image size in bytes */
int xresolution,yresolution; /* Pixels per meter */
unsigned int ncolours; /* Number of colours */
unsigned int importantcolours; /* Important colours */

The compression types supported by BMP are listed below :

* 0 - no compression
* 1 - 8 bit run length encoding
* 2 - 4 bit run length encoding
* 3 - RGB bitmap with mask

Only type 0 (no compression will be discussed here.

No comments: