0
4.7kviews
Write short note BMP image file format
1 Answer
0
32views

BMP image format

BMP is an outdated image file format for computers running the Windows operating system. The format was developed by Microsoft for storing bitmap files in a device-independent bitmap (DIB) format that would allow Windows to display the bitmap on any type of display device. The term ‘device independent’ means that the bitmap specifies pixel color in a form independent of the method used by a display to represent color.

Since BMP is a fairly simple file format, its structure is pretty straightforward. Each bitmap file contains:

a bitmap-file header: this contains information about the type, size, and layout of a device-independent bitmap file.

a bitmap-information header which specifies the dimensions, compression type, and color format for the bitmap.

a color table, defined as an array of RGBQUAD structures, contains as many elements as there are colors in the bitmap. The color table is not present for bitmaps with 24 color bits because each pixel is represented by 24-bit red-green-blue (RGB) values in the actual bitmap data area.

an array of bytes that defines the bitmap bits: These are the actual image data, represented by consecutive rows or ‘scan lines’ of the bitmap. Each scan line consists of consecutive bytes representing the pixels in the scan line, in left-to-right order.

Structure

A BMP file consists of either 3 or 4 parts as shown in the Fig 1 below. The first part is a header, this is followed by a information section, if the image is indexed color then the palette follows, and last of all is the pixel data. The position of the image data with respect to the start of the file is contained in the header. Information such as the image width and height, the type of compression, the number of colors is contained in the information header.

enter image description here

Information

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 */

} INFOHEADER;

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

24 bit Image Data

The simplest data to read is 24 bit true colour images. In this case the image data follows immediately after the information header, that is, there is no colour palette. It consists of three bytes per pixel in b,g,r order. Each byte gives the saturation for that colour component, 0 for black and 1 for white (fully saturated).

Indexed Colour Data

If the image is indexed colour then immediately after the information header there will be a table of infoheader.ncolours colours, each of 4 bytes. The first three bytes correspond to b,g,r components, the last byte is reserved/unused but could obviously represent the alpha channel. For 8 bit greyscale images this colour index will generally just be a greyscale ramp. If you do the sums....then the length of the header plus the length of the information block plus 4 times the number of palette colours should equal the image data offset. In other words

14 + 40 + 4 * infoheader.ncolours = header.offset

Please log in to add an answer.