BMP Basics

BMP Basics

Acronyms Technology

Short for Bitmap according to ABBREVIATIONFINDER.ORG, BMP is an image file format, it is one of the simplest. It was developed jointly by Microsoft and IBM, which explains its particularly wide use on Windows and OS / 2 platforms.

The BMP format supports RGB, Indexed Color, Grayscale, and Bitmap color modes. You can specify the Windows or OS / 2® format and a bit depth of up to 32 bits per channel in the image. For 4-bit and 8-bit images using Windows format, you can also specify RLE compression.

BMP file

A BMP file is a bitmap file, that is, a graphics image file, with pixels stored in the form of a point table that manages colors as real colors or using an indexed palette. The BMP format has been studied in such a way that it allows to obtain a bitmap independent of the peripheral display device (DIB, Device Independent Bitmap).

The structure of a bitmap is as follows:

  • File header
  • The bitmap information header (also called the information header).
  • Palette (optional)
  • Image body

File header

The file header provides information about the file type (bitmap) and its size, as well as where the image information actually begins.

The header comprises four fields:

  • The signature (in 2 bytes), indicating that it is a BMP file with two characters

o BM, 424D in hexadecimal, which indicates that it is a Windows bitmap o BA that indicates that it is an OS / 2 bitmap or CI that indicates that it is an OS / 2 color icon o CP indicates that it is an OS / 2 color pointer o IC indicates that it is an OS / 2 icon o PT indicates that it is an OS / 2 pointer

  • A reserved field (in 4 bytes)
  • The image mismatch (in 4 bytes), that is, the location of the beginning of the image information relative to the beginning of the file

Information header

The bitmap information header provides information about the image, especially its dimensions and colors.

  • The size of the bitmap information header in bytes (encoded in 4 bytes)
  • The width of the image (in 4 bytes), that is, the number of pixels counted horizontally
  • The height of the image (in 4 bytes), that is, the number of pixels counted vertically
  • The number of planes (in 2 bytes). This value is always 1
  • The depth of the color model (in 2 bytes), that is, the number of bits used to encode the color. This value can be equivalent to 1, 4, 8, 16, 24 or 32
  • The compression method (in 4 bytes). This value is 0 when the image is not compressed or 1, 2 or 3 depending on the type of compression used:

o 1 for RLE 8 bits per pixel encoding o 2 for RLE 4 bits per pixel encoding o 3 for bitfield encoding, which means that the color was encoded by a triple mask represented by the palette

  • The total size of the image in bytes (in 4 bytes).
  • The horizontal resolution (in 4 bytes), that is, the number of pixels per meter counted horizontally
  • The vertical resolution (in 4 bytes), that is, the number of pixels per meter counted vertically
  • The number of colors in the palette (in 4 bytes)
  • The number of important colors in the palette (in 4 bytes). This field can equal 0 when all colors are important.

Image palette

The paddle is optional. When the palette is defined, it contains 4 bytes in succession for each of the inputs, which represent:

  • The blue component (in one byte)
  • The green component (in one byte)
  • The red component (in one byte)
  • A reserved field (in one byte)

Image encoding

Image encoding is done by successively writing the bits that correspond to each pixel, line by line, starting with the bottom left pixel.

  • 2-color images use 1 bit per pixel, which means that one byte encodes 8 pixels
  • 16-color images use 4 bits per pixel, which means that one byte allows 2 pixels to be encoded
  • 256-color images use 8 bits per pixel, which means that one byte is needed to encode each pixel
  • True color images use 24 bits per pixel, which means that 3 bytes are needed to encode each pixel, respecting the alternating color order for blue, green, and red.

Each line in the image must contain a total number of bytes that is a multiple of 4; If this scheme is not met, the line must be completed with all the 0’s necessary to meet the criteria.

BMP Basics