Windows bitmap
Encyclopedia
The BMP File Format, also known as Bitmap Image File or Device Independent Bitmap (DIB) file format or simply a Bitmap, is a Raster graphics
image file format used to store bitmap
digital image
s, independently of the display device
(such as a graphics adapter
), especially on Microsoft Windows
and OS/2
operating systems.
The BMP File Format is capable of storing 2D digital image
s of arbitrary width, height, and resolution, both monochrome
and color, in various color depth
s, and optionally with data compression
, alpha channel
s, and color profiles
.
The following sections discuss the data stored in the BMP file or DIB in details. This is the standard BMP file format. Some applications create bitmap image files which are not compliant with the current Microsoft documentation. Also, not all fields are used; a value of 0 will be found in these unused fields.
Referring to the Diagram 1, the Bitmap Image File is composed of structures in the following order:
When the size of Gap1 and Gap2 is zero, the in-memory DIB data structure is customarily referred to as "packed DIB" and can be referred to by a single pointer pointing to the beginning of the DIB Header. In all cases, the Pixel Array must begin at a memory address that is a multiple of 4 bytes. In some cases it may be necessary to adjust the number of entries in the Color Table in order to force the memory address of the Pixel Array to a multiple of 4 bytes. For "packed DIBs" loaded in memory, the optional Color Profile data should immediately follow the Pixel Array, as depicted in Diag.1 (with Gap1=0 and Gap2=0).
"Packed DIBs" are required by Windows
clipboard API functions as well as by some Windows patterned brush and resource functions.
encoding. All of the integer values are stored in little-endian format (i.e. least-significant byte first).
Equivalent header in C language
/* Note: the magic number has been removed from the bmpfile_header structure
since it causes alignment problems
struct bmpfile_magic should be written/read first
followed by the
struct bmpfile_header
[this avoids compiler-specific alignment pragmas etc.]
struct bmpfile_magic {
unsigned char magic[2];
};
struct bmpfile_header {
uint32_t filesz;
uint16_t creator1;
uint16_t creator2;
uint32_t bmp_offset;
};
Versions after BITMAPCOREHEADER only add fields to the end of the header of the previous version.
For example: BITMAPV2INFOHEADER adds fields to BITMAPINFOHEADER and BITMAPV3INFOHEADER adds fields to BITMAPV2INFOHEADER (or, BITMAPINFOHEADER is a stripped version of BITMAPV2INFOHEADER)
For compatibility reasons, most applications use the older DIB headers for saving files. With OS/2 being obsolete, for now the common format is the BITMAPINFOHEADER header.
See next table for its description. All values are stored as unsigned integers
, unless explicitly noted.
Note: The image size field can be 0 for BI_RGB bitmaps.
Equivalent header in C language
typedef struct {
uint32_t header_sz;
int32_t width;
int32_t height;
uint16_t nplanes;
uint16_t bitspp;
uint32_t compress_type;
uint32_t bmp_bytesz;
int32_t hres;
int32_t vres;
uint32_t ncolors;
uint32_t nimpcolors;
} BITMAPINFOHEADER;
The compression method field (bytes #30-33) can have the following values:
Note: BI_JPEG and BI_PNG are for printer drivers and are not supported when rendering to the screen.
Equivalent header in C language (compression methods)
typedef enum {
BI_RGB = 0,
BI_RLE8,
BI_RLE4,
BI_BITFIELDS, //Also Huffman 1D compression for BITMAPCOREHEADER2
BI_JPEG, //Also RLE-24 compression for BITMAPCOREHEADER2
BI_PNG,
} bmp_compression_method_t;
The OS/2 BITMAPCOREHEADER header is also popular:
Note: OS/2 BITMAPCOREHEADER bitmaps cannot be compressed and cannot be 16 or 32 bits/pixel. All values in the OS/2 BITMAPCOREHEADER header are unsigned integers.
A 16-bit and 32-bit version of DIB with an integrated alpha channel has been introduced with the undocumented BITMAPV3INFOHEADER and with the documented BITMAPV4HEADER (since Windows 95
) and is used within Windows XP
logon and theme system as well as Microsoft Office (since v2000); it is supported by some image editing
software, such as Adobe Photoshop
since version 7 and Adobe Flash
since version MX 2004 (then known as Macromedia Flash). It is also supported by GIMP
, Google Chrome
, MS-PowerPoint
and MS-Word.
Note: On Windows CE
the BITMAPINFOHEADER Header can be used with the BI_ALPHABITFIELDS option in the biCompression member. In such case, four optional bitmasks follow the BITMAPINFOHEADER Header instead of the two bitmask mentioned above, thus the Color Table's offset is the size of the BITMAPFILEHEADER plus the size of the BITMAPINFOHEADER Header plus the 16 bytes of the four bitmasks (Red, Green, Blue and Alpha).
The number of entries in the palette is either 2n or a smaller number specified in the header (in the OS/2 BITMAPCOREHEADER header format, only the full-size palette is supported). In most cases, each entry in the color table occupies 4 bytes, in the order Blue, Green, Red, 0x00 (see below for exceptions).
The Color Table is a block of bytes (a table) listing the colors used by the image. Each pixel in an indexed color image is described by a number of bits (1, 4, or 8) which is an index of a single color described by this table. The purpose of the color palette in indexed color bitmaps is to inform the application about the actual color that each of these index values corresponds to. The purpose of the Color Table in non-indexed (non-palettized) bitmaps is to list the colors used by the bitmap for the purposes of optimization on devices with limited color display capability and to facilitate future conversion to different pixel formats and paletization.
The colors in the Color Table are usually specified in the 4-byte per entry 8.8.8.0.8 format (in RGBAX notation). The Color Table used with the OS/2 BITMAPCOREHEADER uses the 3-byte per entry 8.8.8.0.0 format. For DIBs loaded in memory, the Color Table can optionally consist of 2-byte entries - these entries constitute indexes to the currently realized palette instead of explicit RGB color definitions.
Microsoft does not disallow the presence of a valid Alpha channel bit mask in BITMAPV4HEADER and BITMAPV5HEADER for 1bpp, 4bpp and 8bpp indexed color images, which indicates that the Color Table entries can also specify an Alpha component using the 8.8.8.[0-8].[0-8] format via the RGBQUAD.rgbReserved member. However, some versions of Microsoft's documentation disallow this feature by stating that the RGBQUAD.rgbReserved member "must be zero".
As mentioned above, the Color Table is normally not used when the pixels are in the 16-bit per pixel (16bpp) format (and higher); there are normally no Color Table entries in those bitmap image files. However, the Microsoft documentation (on the MSDN web site as of Nov. 16, 2010) specifies that for 16bpp (and higher), the Color Table can be present to store a list of colors intended for optimization on devices with limited color display capability, while it also specifies, that in such cases, no indexed palette entries are present in this Color Table. This may seem like a contradiction if no distinction is made between the mandatory palette entries and the optional color list.
For images with Height > 1, multiple padded rows are stored consecutively, forming a Pixel Array.
The total number of bytes necessary to store one row of pixels can be calculated as:
The total amount of bytes
necessary to store an array of pixels in an n Bits per Pixel (bpp) image, with 2n
colors, can be calculated by accounting for the effect of rounding up the size of each row to a multiple of a 4 bytes, as follows:
The total Bitmap Image File size can be approximated as:,
Only images with 8 or fewer Bits per Pixel must account for the palette
. 16bpp images (or higher), may omit the palette
part from the size calculation, as follows:
,
In the formulas above, the number 54 is the combined size of the 14 byte Bitmap File Header and the 40 byte popular Windows DIB Header
- the BITMAPINFOHEADER (some other DIB Header versions will be larger or smaller than that as described by the table above) and the expression is the size of the color palette
in bytes
.
This total file size formula is only an approximation, since the size of the color palette
will be bytes for the OS/2 DIB Header version BITMAPCOREHEADER, and some files may define only the number of colors needed by the image, potentially fewer than .
An additional size uncertainty is introduced by the optional presence of the 12 or 16 bytes needed for the extra bit masks stored immediately after the BITMAPINFOHEADER DIB Header and the variable-size GAP depiced in Diag.1
order, starting in the lower left corner, going from left to right, and then row by row from the bottom to the top of the image.
Uncompressed Windows
bitmaps also can be stored from the top to bottom, when the Image Height value is negative.
In the original OS/2 DIB, the only four legal values of color depth
were 1, 4, 8, and 24 bits per pixel (bpp).
Contemporary DIB Headers allow pixel formats with 1, 2, 4, 8, 16, 24 and 32 bits per pixel (bpp).
Padding bytes (not necessarily 0) must be appended to the end of the rows in order to bring up the length of the rows to a multiple of four bytes. When the Pixel Array is loaded into memory, each row must begin at a memory address that is a multiple of 4. This address/offset restriction is mandatory only for Pixel Array's loaded in memory. For file storage purposes, only the size of each row must be a multiple of 4 bytes while the file offset can be arbitrary.
A 24-bit bitmap with Width=1, would have 3 bytes of data per row (blue, green, red) and 1 byte of padding, while Width=2 would have 2 bytes of padding, Width=3 would have 3 bytes of padding, and Width=4 would not have any padding at all.
Bitmap Image Files are typically much larger than image file formats compressed with other algorithms, for the same image. For example, the 1058×1058 Wikipedia logo, which occupies about 271 KB
in the lossless PNG format, takes about 3358 KB
as a 24bpp BMP Image File. Uncompressed formats are generally unsuitable for transferring images on the Internet
or other slow or capacity-limited media
.
color images may be compressed
with 4-bit or 8-bit RLE
or Huffman
1D algorithm.
OS/2
BITMAPCOREHEADER2 24bpp
images may be compressed
with the 24-bit RLE
algorithm.
The 16bpp
and 32bpp
images are always stored uncompressed.
Note that images in all color depth
s can be stored without compression
if so desired.
In order to resolve the ambiguity of which bits define which samples
, the DIB Headers provide certain defaults as well as specific BITFIELDS which are bit masks that define the membership of particular group of bits in a pixel to a particular channel
.
The following diagram defines this mechanism:
Diag.2 - The BITFIELDS mechanism for a 32 bit pixel depicted in RGBAX Sample
Length notation
The sample
fields defined by the BITFIELDS bit masks have to be contiguous and non-overlapping.
The Red, Green and Blue bit masks are valid only when the Compression member of the DIB Header is set to BI_BITFIELDS.
The Alpha bit mask is valid whenever it is present in the DIB Header or when the Compression member of the DIB Header is set to BI_ALPHABITFIELDS (Windows CE
only).
Diag.3 - The pixel format with an Alpha channel in a 16 bit pixel (in RGBAX Sample
Length notation) actually generated by Adobe Photohop
The BITFIELD mechanism described above allows for the definition of tens of thousands different pixel formats, however only several of them are used in practice, such as:
[The list above is in the RGBAX notation]
Note that the bitmap data starts with the lower left hand corner of the image.
and free of patent
s, makes it a very common format that image processing programs from many operating systems can read and write.
Many older graphical user interface
s used bitmaps in their built-in graphics subsystems; for example, the Microsoft Windows and OS/2 platforms' GDI
subsystem, where the specific format used is the Windows and OS/2 bitmap file format, usually named with the file extension of
While most BMP files have a relatively large file size due to lack of any compression (or generally low-ratio RLE
on palletized images), many BMP files can be considerably compressed with lossless data compression
algorithms such as ZIP
(in extreme cases of non-photographic data, up to 0.1% of original size) because they contain redundant data. Some formats, such as RAR, even include routines specifically targeted at efficient compression of such data.
uses a similar XBM format for black-and-white
images, and XPM (pixelmap) for color
images. There are also a variety of "raw" formats, which saves raw data
with no other information
. The Portable Pixmap
(PPM) and Truevision TGA
formats also exist, but are less often used – or only for special purposes; for example, TGA can contain transparency information.
Numerous other bitmap file formats are in existence, though most are not widely used.
Raster graphics
In computer graphics, a raster graphics image, or bitmap, is a data structure representing a generally rectangular grid of pixels, or points of color, viewable via a monitor, paper, or other display medium...
image file format used to store bitmap
Bitmap
In computer graphics, a bitmap or pixmap is a type of memory organization or image file format used to store digital images. The term bitmap comes from the computer programming terminology, meaning just a map of bits, a spatially mapped array of bits. Now, along with pixmap, it commonly refers to...
digital image
Digital image
A digital image is a numeric representation of a two-dimensional image. Depending on whether or not the image resolution is fixed, it may be of vector or raster type...
s, independently of the display device
Display device
A display device is an output device for presentation of information in visual or tactile form...
(such as a graphics adapter
Video card
A video card, Graphics Card, or Graphics adapter is an expansion card which generates output images to a display. Most video cards offer various functions such as accelerated rendering of 3D scenes and 2D graphics, MPEG-2/MPEG-4 decoding, TV output, or the ability to connect multiple monitors...
), especially on Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
and OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
operating systems.
The BMP File Format is capable of storing 2D digital image
Digital image
A digital image is a numeric representation of a two-dimensional image. Depending on whether or not the image resolution is fixed, it may be of vector or raster type...
s of arbitrary width, height, and resolution, both monochrome
Monochrome
Monochrome describes paintings, drawings, design, or photographs in one color or shades of one color. A monochromatic object or image has colors in shades of limited colors or hues. Images using only shades of grey are called grayscale or black-and-white...
and color, in various color depth
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
s, and optionally with data compression
Data compression
In computer science and information theory, data compression, source coding or bit-rate reduction is the process of encoding information using fewer bits than the original representation would use....
, alpha channel
Alpha compositing
In computer graphics, alpha compositing is the process of combining an image with a background to create the appearance of partial or full transparency. It is often useful to render image elements in separate passes, and then combine the resulting multiple 2D images into a single, final image in a...
s, and color profiles
Color management
In digital imaging systems, color management is the controlled conversion between the color representations of various devices, such as image scanners, digital cameras, monitors, TV screens, film printers, computer printers, offset presses, and corresponding media.The primary goal of color...
.
Device-independent bitmaps and BMP file format
Microsoft has defined a particular representation of color bitmaps of different color depths, as an aid to exchanging bitmaps between devices and applications with a variety of internal representations. They called these device-independent bitmaps or DIBs, and the file format for them is called DIB file format or BMP image file format. According to Microsoft support:
A device-independent bitmap (DIB) is a format used to define device-independent bitmaps in various color resolutions. The main purpose of DIBs is to allow bitmaps to be moved from one device to another (hence, the device-independent part of the name). A DIB is an external format, in contrast to a device-dependent bitmap, which appears in the system as a bitmap object (created by an application...). A DIB is normally transported in metafiles (usually using the StretchDIBits function), BMP files, and the Clipboard (CF_DIB data format).
The following sections discuss the data stored in the BMP file or DIB in details. This is the standard BMP file format. Some applications create bitmap image files which are not compliant with the current Microsoft documentation. Also, not all fields are used; a value of 0 will be found in these unused fields.
File structure
The Bitmap Image File consists of fixed-size structures (headers) as well as variable-size structures appearing in a predetermined sequence. Many different versions of some of these structures can appear in the file, due to the long evolution of this file format.Referring to the Diagram 1, the Bitmap Image File is composed of structures in the following order:
Structure Name | Optional | Size | Purpose | Comments |
---|---|---|---|---|
Bitmap File Header | No | 14 Bytes | To store general information about the Bitmap Image File | Not needed after the file is loaded in memory |
DIB Header | No | Fixed-size (however 7 different versions exist) |
To store detailed information about the bitmap image and define the pixel format | Immediately follows the Bitmap File Header |
Extra bit masks | Yes | 3 or 4 DWORDs (12 or 16 Bytes) |
To define the pixel format | Present only in case the DIB Header is the BITMAPINFOHEADER |
Color Table | Semi-optional | Variable-size | To define colors used by the bitmap image data (Pixel Array) | Mandatory for color depth Color depth In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used... s <= 8 |
Gap1 | Yes | Variable-size | Structure alignment | An artifact of the File Offset to PixelArray in the Bitmap File Header |
Pixel Array | No | Variable-size | To define the actual values of the pixels | The pixel format is defined by the DIB Header or Extra bit masks. Each row in the Pixel Array is padded to a multiple of 4 bytes in size |
Gap2 | Yes | Variable-size | Structure alignment | An artifact of the ICC Profile Data offset field in the DIB Header |
ICC Color Profile | Yes | Variable-size | To define the color profile Color management In digital imaging systems, color management is the controlled conversion between the color representations of various devices, such as image scanners, digital cameras, monitors, TV screens, film printers, computer printers, offset presses, and corresponding media.The primary goal of color... for Color management Color management In digital imaging systems, color management is the controlled conversion between the color representations of various devices, such as image scanners, digital cameras, monitors, TV screens, film printers, computer printers, offset presses, and corresponding media.The primary goal of color... |
Can also contain a path to an external file containing the Color Profile. When loaded in memory as "non-packed DIB", it is located between the Color Table and Gap1. |
DIBs in memory
A Bitmap Image File loaded into memory becomes a DIB data structure - an important component of the Windows GDI API. The in-memory DIB data structure is almost the same as the BMP file format, but it does not contain the 14-byte Bitmap File Header and begins with the DIB Header. For DIBs loaded in memory, the Color Table can also consist of 16 bit entries, that constitute indexes to the currently realized palette (an additional level of indirection), instead of explicit RGB color definitions. In all cases, the Pixel Array must begin at a memory address that is a multiple of 4 bytes. In non-packed DIBs loaded in memory, the optional Color Profile data should be located immediately after the Color Table and before the Gap1 and Pixel Array (unlike in Diag.1).When the size of Gap1 and Gap2 is zero, the in-memory DIB data structure is customarily referred to as "packed DIB" and can be referred to by a single pointer pointing to the beginning of the DIB Header. In all cases, the Pixel Array must begin at a memory address that is a multiple of 4 bytes. In some cases it may be necessary to adjust the number of entries in the Color Table in order to force the memory address of the Pixel Array to a multiple of 4 bytes. For "packed DIBs" loaded in memory, the optional Color Profile data should immediately follow the Pixel Array, as depicted in Diag.1 (with Gap1=0 and Gap2=0).
"Packed DIBs" are required by Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
clipboard API functions as well as by some Windows patterned brush and resource functions.
Bitmap file header
This block of bytes is at the start of the file and is used to identify the file. A typical application reads this block first to ensure that the file is actually a BMP file and that it is not damaged. The first two bytes of the BMP file format are the character 'B' then the character 'M' in 1-byte ASCIIASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...
encoding. All of the integer values are stored in little-endian format (i.e. least-significant byte first).
Offset# | Size | Purpose |
---|---|---|
0000h | 2 bytes | the Header field Magic number (programming) In computer programming, the term magic number has multiple meanings. It could refer to one or more of the following:* A constant numerical or text value used to identify a file format or protocol; for files, see List of file signatures... used to identify the BMP & DIB file is 0x42 0x4D in Hexadecimal Hexadecimal In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen... , same as BM in ASCII. The following entries are possible:
|
0002h | 4 bytes | the size of the BMP file in bytes |
0006h | 2 bytes | reserved; actual value depends on the application that creates the image |
0008h | 2 bytes | reserved; actual value depends on the application that creates the image |
000Ah | 4 bytes | the offset, i.e. starting address, of the byte where the bitmap image data (Pixel Array) can be found. |
Equivalent header in C language
- include
/* Note: the magic number has been removed from the bmpfile_header structure
since it causes alignment problems
struct bmpfile_magic should be written/read first
followed by the
struct bmpfile_header
[this avoids compiler-specific alignment pragmas etc.]
struct bmpfile_magic {
unsigned char magic[2];
};
struct bmpfile_header {
uint32_t filesz;
uint16_t creator1;
uint16_t creator2;
uint32_t bmp_offset;
};
DIB Header (Bitmap Information Header)
This block of bytes tells the application detailed information about the image, which will be used to display the image on the screen. The block also matches the header used internally by Windows and OS/2 and has several different variants. All of them contain a dword (32 bit) field, specifying their size, so that an application can easily determine which header is used in the image. The reason that there are different headers is that Microsoft extended the DIB format several times. The new extended headers can be used with some GDI functions instead of the older ones, providing more functionality. Since the GDI supports a function for loading bitmap files, typical Windows applications use that functionality. One consequence of this is that for such applications, the BMP formats that they support match the formats supported by the Windows version being run. See the table below for more information.Size | Header Name | OS support | Features Added (incremental) | in Bitmap Files Written by |
---|---|---|---|---|
12 | BITMAPCOREHEADER OS21XBITMAPHEADER |
OS/2 OS/2 OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal... and also all Windows versions since Windows 3.0 Windows 3.0 Windows 3.0, a graphical environment, is the third major release of Microsoft Windows, and was released on 22 May 1990. It became the first widely successful version of Windows and a rival to Apple Macintosh and the Commodore Amiga on the GUI front... |
||
64 | BITMAPCOREHEADER2 OS22XBITMAPHEADER |
OS/2 OS/2 OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal... |
Adds Halftoning. Adds RLE and Huffman 1D compression. | |
40 | BITMAPINFOHEADER | all Windows versions since Windows 3.0 Windows 3.0 Windows 3.0, a graphical environment, is the third major release of Microsoft Windows, and was released on 22 May 1990. It became the first widely successful version of Windows and a rival to Apple Macintosh and the Commodore Amiga on the GUI front... |
Removes RLE-24 and Huffman 1D compression. Adds 16bpp and 32bpp pixel formats. Adds optional RGB bit masks. | Adobe Photoshop |
52 | BITMAPV2INFOHEADER | Undocumented. | Removes optional RGB bit masks. Adds mandatory RGB bit masks. | |
56 | BITMAPV3INFOHEADER | Undocumented. | Adds mandatory Alpha channel bit mask. | Adobe Photoshop |
108 | BITMAPV4HEADER | all Windows versions since Windows 95 Windows 95 Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Windows products... /NT4 Windows NT 4.0 Windows NT 4.0 is a preemptive, graphical and business-oriented operating system designed to work with either uniprocessor or symmetric multi-processor computers. It was the next release of Microsoft's Windows NT line of operating systems and was released to manufacturing on 31 July 1996... |
Adds Color Space Color space A color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers, typically as three or four values or color components... type and Gamma correction Gamma correction Gamma correction, gamma nonlinearity, gamma encoding, or often simply gamma, is the name of a nonlinear operation used to code and decode luminance or tristimulus values in video or still image systems... |
|
124 | BITMAPV5HEADER | Windows 98 Windows 98 Windows 98 is a graphical operating system by Microsoft. It is the second major release in the Windows 9x line of operating systems. It was released to manufacturing on 15 May 1998 and to retail on 25 June 1998. Windows 98 is the successor to Windows 95. Like its predecessor, it is a hybrid... /2000 Windows 2000 Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the... and newer |
Adds ICC Color Profiles ICC profile In color management, an ICC profile is a set of data that characterizes a color input or output device, or a color space, according to standards promulgated by the International Color Consortium... |
Versions after BITMAPCOREHEADER only add fields to the end of the header of the previous version.
For example: BITMAPV2INFOHEADER adds fields to BITMAPINFOHEADER and BITMAPV3INFOHEADER adds fields to BITMAPV2INFOHEADER (or, BITMAPINFOHEADER is a stripped version of BITMAPV2INFOHEADER)
For compatibility reasons, most applications use the older DIB headers for saving files. With OS/2 being obsolete, for now the common format is the BITMAPINFOHEADER header.
See next table for its description. All values are stored as unsigned integers
Signedness
In computing, signedness is a property of data types representing numbers in computer programs. A numeric variable is signed if it can represent both positive and negative numbers, and unsigned if it can only represent non-negative numbers .As signed numbers can represent negative numbers, they...
, unless explicitly noted.
Offset # | Size | Purpose |
---|---|---|
0Eh | 4 | the size of this header (40 bytes) |
12h | 4 | the bitmap width in pixels (signed integer). |
16h | 4 | the bitmap height in pixels (signed integer). |
1Ah | 2 | the number of color planes being used. Must be set to 1. |
1Ch | 2 | the number of bits per pixel, which is the color depth of the image. Typical values are 1, 4, 8, 16, 24 and 32. |
1Eh | 4 | the compression method being used. See the next table for a list of possible values. |
22h | 4 | the image size. This is the size of the raw bitmap data (see below), and should not be confused with the file size. |
26h | 4 | the horizontal resolution of the image. (pixel per meter, signed integer) |
2Ah | 4 | the vertical resolution of the image. (pixel per meter, signed integer) |
2Eh | 4 | the number of colors in the color palette, or 0 to default to 2n. |
32h | 4 | the number of important colors used, or 0 when every color is important; generally ignored. |
Note: The image size field can be 0 for BI_RGB bitmaps.
Equivalent header in C language
typedef struct {
uint32_t header_sz;
int32_t width;
int32_t height;
uint16_t nplanes;
uint16_t bitspp;
uint32_t compress_type;
uint32_t bmp_bytesz;
int32_t hres;
int32_t vres;
uint32_t ncolors;
uint32_t nimpcolors;
} BITMAPINFOHEADER;
The compression method field (bytes #30-33) can have the following values:
Value | Identified by | Compression method | Comments |
---|---|---|---|
0 | BI_RGB | none | Most common |
1 | BI_RLE8 | RLE Run-length encoding Run-length encoding is a very simple form of data compression in which runs of data are stored as a single data value and count, rather than as the original run... 8-bit/pixel |
Can be used only with 8-bit/pixel bitmaps |
2 | BI_RLE4 | RLE 4-bit/pixel | Can be used only with 4-bit/pixel bitmaps |
3 | BI_BITFIELDS | Bit field Bit field A bit field is a common idiom used in computer programming to compactly store multiple logical values as a short series of bits where each of the single bits can be addressed separately. A bit field is most commonly used to represent integral types of known, fixed bit-width. A well-known usage of... or Huffman 1D compression for BITMAPCOREHEADER2 |
Pixel format defined by bit masks or Huffman 1D compressed bitmap for BITMAPCOREHEADER2 |
4 | BI_JPEG | JPEG or RLE-24 compression for BITMAPCOREHEADER2 | The bitmap contains a JPEG JPEG In computing, JPEG . The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality.... image or RLE-24 compressed bitmap for BITMAPCOREHEADER2 |
5 | BI_PNG | PNG | The bitmap contains a PNG image |
6 | BI_ALPHABITFIELDS | Bit field Bit field A bit field is a common idiom used in computer programming to compactly store multiple logical values as a short series of bits where each of the single bits can be addressed separately. A bit field is most commonly used to represent integral types of known, fixed bit-width. A well-known usage of... |
This value is valid in Windows CE .NET 4.0 and later. |
Note: BI_JPEG and BI_PNG are for printer drivers and are not supported when rendering to the screen.
Equivalent header in C language (compression methods)
typedef enum {
BI_RGB = 0,
BI_RLE8,
BI_RLE4,
BI_BITFIELDS, //Also Huffman 1D compression for BITMAPCOREHEADER2
BI_JPEG, //Also RLE-24 compression for BITMAPCOREHEADER2
BI_PNG,
} bmp_compression_method_t;
The OS/2 BITMAPCOREHEADER header is also popular:
Offset | Size | Purpose |
---|---|---|
Eh | 4 | the size of this header (12 bytes) |
12h | 2 | the bitmap width in pixels. |
14h | 2 | the bitmap height in pixels. |
16h | 2 | the number of color planes; 1 is the only legal value |
18h | 2 | the number of bits per pixel. Typical values are 1, 4, 8 and 24. |
Note: OS/2 BITMAPCOREHEADER bitmaps cannot be compressed and cannot be 16 or 32 bits/pixel. All values in the OS/2 BITMAPCOREHEADER header are unsigned integers.
A 16-bit and 32-bit version of DIB with an integrated alpha channel has been introduced with the undocumented BITMAPV3INFOHEADER and with the documented BITMAPV4HEADER (since Windows 95
Windows 95
Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Windows products...
) and is used within Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...
logon and theme system as well as Microsoft Office (since v2000); it is supported by some image editing
Image editing
Image editing encompasses the processes of altering images, whether they be digital photographs, traditional analog photographs, or illustrations. Traditional analog image editing is known as photo retouching, using tools such as an airbrush to modify photographs, or editing illustrations with any...
software, such as Adobe Photoshop
Adobe Photoshop
Adobe Photoshop is a graphics editing program developed and published by Adobe Systems Incorporated.Adobe's 2003 "Creative Suite" rebranding led to Adobe Photoshop 8's renaming to Adobe Photoshop CS. Thus, Adobe Photoshop CS5 is the 12th major release of Adobe Photoshop...
since version 7 and Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...
since version MX 2004 (then known as Macromedia Flash). It is also supported by GIMP
GIMP
GIMP is a free software raster graphics editor. It is primarily employed as an image retouching and editing tool and is freely available in versions tailored for most popular operating systems including Microsoft Windows, Apple Mac OS X, and Linux.In addition to detailed image retouching and...
, Google Chrome
Google Chrome
Google Chrome is a web browser developed by Google that uses the WebKit layout engine. It was first released as a beta version for Microsoft Windows on September 2, 2008, and the public stable release was on December 11, 2008. The name is derived from the graphical user interface frame, or...
, MS-PowerPoint
Microsoft PowerPoint
Microsoft PowerPoint, usually just called PowerPoint, is a non-free commercial presentation program developed by Microsoft. It is part of the Microsoft Office suite, and runs on Microsoft Windows and Apple's Mac OS X operating system...
and MS-Word.
Color Table
The Color Table (a.k.a. Palette) occurs in the BMP image file directly after the BMP file header, the DIB header (and after optional three Red, Green and Blue bitmasks if the BITMAPINFOHEADER Header with BI_BITFIELDS option is used). Therefore, its offset is the size of the BITMAPFILEHEADER plus the size of the DIB header (plus optional 12 bytes for the three bit masks).Note: On Windows CE
Windows CE
Microsoft Windows CE is an operating system developed by Microsoft for embedded systems. Windows CE is a distinct operating system and kernel, rather than a trimmed-down version of desktop Windows...
the BITMAPINFOHEADER Header can be used with the BI_ALPHABITFIELDS option in the biCompression member. In such case, four optional bitmasks follow the BITMAPINFOHEADER Header instead of the two bitmask mentioned above, thus the Color Table's offset is the size of the BITMAPFILEHEADER plus the size of the BITMAPINFOHEADER Header plus the 16 bytes of the four bitmasks (Red, Green, Blue and Alpha).
The number of entries in the palette is either 2n or a smaller number specified in the header (in the OS/2 BITMAPCOREHEADER header format, only the full-size palette is supported). In most cases, each entry in the color table occupies 4 bytes, in the order Blue, Green, Red, 0x00 (see below for exceptions).
The Color Table is a block of bytes (a table) listing the colors used by the image. Each pixel in an indexed color image is described by a number of bits (1, 4, or 8) which is an index of a single color described by this table. The purpose of the color palette in indexed color bitmaps is to inform the application about the actual color that each of these index values corresponds to. The purpose of the Color Table in non-indexed (non-palettized) bitmaps is to list the colors used by the bitmap for the purposes of optimization on devices with limited color display capability and to facilitate future conversion to different pixel formats and paletization.
The colors in the Color Table are usually specified in the 4-byte per entry 8.8.8.0.8 format (in RGBAX notation). The Color Table used with the OS/2 BITMAPCOREHEADER uses the 3-byte per entry 8.8.8.0.0 format. For DIBs loaded in memory, the Color Table can optionally consist of 2-byte entries - these entries constitute indexes to the currently realized palette instead of explicit RGB color definitions.
Microsoft does not disallow the presence of a valid Alpha channel bit mask in BITMAPV4HEADER and BITMAPV5HEADER for 1bpp, 4bpp and 8bpp indexed color images, which indicates that the Color Table entries can also specify an Alpha component using the 8.8.8.[0-8].[0-8] format via the RGBQUAD.rgbReserved member. However, some versions of Microsoft's documentation disallow this feature by stating that the RGBQUAD.rgbReserved member "must be zero".
As mentioned above, the Color Table is normally not used when the pixels are in the 16-bit per pixel (16bpp) format (and higher); there are normally no Color Table entries in those bitmap image files. However, the Microsoft documentation (on the MSDN web site as of Nov. 16, 2010) specifies that for 16bpp (and higher), the Color Table can be present to store a list of colors intended for optimization on devices with limited color display capability, while it also specifies, that in such cases, no indexed palette entries are present in this Color Table. This may seem like a contradiction if no distinction is made between the mandatory palette entries and the optional color list.
Pixel storage
The bits representing the bitmap pixels are packed in rows. The size of each row is rounded up to a multiple of 4 bytes (a 32-bit DWORD) by padding.For images with Height > 1, multiple padded rows are stored consecutively, forming a Pixel Array.
The total number of bytes necessary to store one row of pixels can be calculated as:
- ImageWidth is expressed in pixels.
The total amount of bytes
Octet (computing)
An octet is a unit of digital information in computing and telecommunications that consists of eight bits. The term is often used when the term byte might be ambiguous, as there is no standard for the size of the byte.-Overview:...
necessary to store an array of pixels in an n Bits per Pixel (bpp) image, with 2n
Power of two
In mathematics, a power of two means a number of the form 2n where n is an integer, i.e. the result of exponentiation with as base the number two and as exponent the integer n....
colors, can be calculated by accounting for the effect of rounding up the size of each row to a multiple of a 4 bytes, as follows:
- ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative
The total Bitmap Image File size can be approximated as:,
- for BPP ≤ 8 ( because for pixels larger than 8 bits, the palettePalette (computing)In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
is not mandatory )
Only images with 8 or fewer Bits per Pixel must account for the palette
Palette (computing)
In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
. 16bpp images (or higher), may omit the palette
Palette (computing)
In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
part from the size calculation, as follows:
,
- for Bits per Pixel > 8.
In the formulas above, the number 54 is the combined size of the 14 byte Bitmap File Header and the 40 byte popular Windows DIB Header
Header (information technology)
In information technology, header refers to supplemental data placed at the beginning of a block of data being stored or transmitted. In data transmission, the data following the header are sometimes called the payload or body....
- the BITMAPINFOHEADER (some other DIB Header versions will be larger or smaller than that as described by the table above) and the expression is the size of the color palette
Palette (computing)
In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
in bytes
Octet (computing)
An octet is a unit of digital information in computing and telecommunications that consists of eight bits. The term is often used when the term byte might be ambiguous, as there is no standard for the size of the byte.-Overview:...
.
This total file size formula is only an approximation, since the size of the color palette
Palette (computing)
In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
will be bytes for the OS/2 DIB Header version BITMAPCOREHEADER, and some files may define only the number of colors needed by the image, potentially fewer than .
An additional size uncertainty is introduced by the optional presence of the 12 or 16 bytes needed for the extra bit masks stored immediately after the BITMAPINFOHEADER DIB Header and the variable-size GAP depiced in Diag.1
Pixel Array (bitmap data)
The Pixel Array is a block of 32-bit DWORDs, that describes the image pixel by pixel. Normally pixels are stored "upside-down" with respect to normal image raster scanRaster scan
A raster scan, or raster scanning, is the rectangular pattern of image capture and reconstruction in television. By analogy, the term is used for raster graphics, the pattern of image storage and transmission used in most computer bitmap image systems...
order, starting in the lower left corner, going from left to right, and then row by row from the bottom to the top of the image.
Uncompressed Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
bitmaps also can be stored from the top to bottom, when the Image Height value is negative.
In the original OS/2 DIB, the only four legal values of color depth
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
were 1, 4, 8, and 24 bits per pixel (bpp).
Contemporary DIB Headers allow pixel formats with 1, 2, 4, 8, 16, 24 and 32 bits per pixel (bpp).
Padding bytes (not necessarily 0) must be appended to the end of the rows in order to bring up the length of the rows to a multiple of four bytes. When the Pixel Array is loaded into memory, each row must begin at a memory address that is a multiple of 4. This address/offset restriction is mandatory only for Pixel Array's loaded in memory. For file storage purposes, only the size of each row must be a multiple of 4 bytes while the file offset can be arbitrary.
A 24-bit bitmap with Width=1, would have 3 bytes of data per row (blue, green, red) and 1 byte of padding, while Width=2 would have 2 bytes of padding, Width=3 would have 3 bytes of padding, and Width=4 would not have any padding at all.
Bitmap Image Files are typically much larger than image file formats compressed with other algorithms, for the same image. For example, the 1058×1058 Wikipedia logo, which occupies about 271 KB
Kilobyte
The kilobyte is a multiple of the unit byte for digital information. Although the prefix kilo- means 1000, the term kilobyte and symbol KB have historically been used to refer to either 1024 bytes or 1000 bytes, dependent upon context, in the fields of computer science and information...
in the lossless PNG format, takes about 3358 KB
Kilobyte
The kilobyte is a multiple of the unit byte for digital information. Although the prefix kilo- means 1000, the term kilobyte and symbol KB have historically been used to refer to either 1024 bytes or 1000 bytes, dependent upon context, in the fields of computer science and information...
as a 24bpp BMP Image File. Uncompressed formats are generally unsuitable for transferring images on the Internet
Internet
The Internet is a global system of interconnected computer networks that use the standard Internet protocol suite to serve billions of users worldwide...
or other slow or capacity-limited media
Digital media
Digital media is a form of electronic media where data is stored in digital form. It can refer to the technical aspect of storage and transmission Digital media is a form of electronic media where data is stored in digital (as opposed to analog) form. It can refer to the technical aspect of...
.
Compression
IndexedPalette (computing)
In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
color images may be compressed
Image compression
The objective of image compression is to reduce irrelevance and redundancy of the image data in order to be able to store or transmit data in an efficient form.- Lossy and lossless compression :...
with 4-bit or 8-bit RLE
Run-length encoding
Run-length encoding is a very simple form of data compression in which runs of data are stored as a single data value and count, rather than as the original run...
or Huffman
Huffman coding
In computer science and information theory, Huffman coding is an entropy encoding algorithm used for lossless data compression. The term refers to the use of a variable-length code table for encoding a source symbol where the variable-length code table has been derived in a particular way based on...
1D algorithm.
OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
BITMAPCOREHEADER2 24bpp
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
images may be compressed
Image compression
The objective of image compression is to reduce irrelevance and redundancy of the image data in order to be able to store or transmit data in an efficient form.- Lossy and lossless compression :...
with the 24-bit RLE
Run-length encoding
Run-length encoding is a very simple form of data compression in which runs of data are stored as a single data value and count, rather than as the original run...
algorithm.
The 16bpp
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
and 32bpp
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
images are always stored uncompressed.
Note that images in all color depth
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
s can be stored without compression
Image compression
The objective of image compression is to reduce irrelevance and redundancy of the image data in order to be able to store or transmit data in an efficient form.- Lossy and lossless compression :...
if so desired.
Pixel Format
In bitmap image file on a disk or bitmap image in memory, the pixels can be defined by varying number of bits.- The 1-bit per pixel (1bpp) format supports 2 distinct colors, (for example: black and white, ...or yellow and pink). The pixel values are stored in each bit, with the first (left-most) pixel in the most-significant bit of the first byte. Each bit is an index into a table of 2 colors. This Color Table is in 32bpp 8.8.8.0.8 RGBAX format. An unset bit will refer to the first color table entry, and a set bit will refer to the last (second) color table entry.
- The 2-bit per pixel (2bpp) format supports 4 distinct colors and stores 4 pixels per 1 byte, the left-most pixel being in the two most significant bits (Windows CEWindows CEMicrosoft Windows CE is an operating system developed by Microsoft for embedded systems. Windows CE is a distinct operating system and kernel, rather than a trimmed-down version of desktop Windows...
only). Each pixel value is a 2-bit index into a table of up to 4 colors. This Color Table is in 32bpp 8.8.8.0.8 RGBAX format.
- The 4-bit per pixel (4bpp) format supports 16 distinct colors and stores 2 pixels per 1 byte, the left-most pixel being in the more significant nibbleNibbleIn computing, a nibble is a four-bit aggregation, or half an octet...
. Each pixel value is a 4-bit index into a table of up to 16 colors. This Color Table is in 32bpp 8.8.8.0.8 RGBAX format.
- The 8-bit per pixel (8bpp) format supports 256 distinct colors and stores 1 pixel per 1 byte. Each byte is an index into a table of up to 256 colors. This Color Table is in 32bpp 8.8.8.0.8 RGBAX format.
- The 16-bit per pixel (16bpp) format supports 65536 distinct colors and stores 1 pixel per 2 byte WORD. Each WORD can define the Alpha, Red, Green and Blue samplesSample (graphics)In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
of the pixel.
- The 24-bit pixel (24bpp) format supports 16,777,216 distinct colors and stores 1 pixel value per 3 bytes. Each pixel value defines the Red, Green and Blue samplesSample (graphics)In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
of the pixel (8.8.8.0.0 in RGBAX notation). Specifically in the order (Blue, Green and Red, 8-bits per each sampleSample (graphics)In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
).
- The 32-bit per pixel (32bpp) format supports 4,294,967,296 distinct colors and stores 1 pixel per 4 byte DWORD. Each DWORD can define the Alpha, Red, Green and Blue samplesSample (graphics)In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
of the pixel.
In order to resolve the ambiguity of which bits define which samples
Sample (graphics)
In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
, the DIB Headers provide certain defaults as well as specific BITFIELDS which are bit masks that define the membership of particular group of bits in a pixel to a particular channel
Channel (digital image)
Color digital images are made of pixels, and pixels are made of combinations of primary colors. A channel in this context is the grayscale image of the same size as a color image, made of just one of these primary colors. For instance, an image from a standard digital camera will have a red, green...
.
The following diagram defines this mechanism:
Diag.2 - The BITFIELDS mechanism for a 32 bit pixel depicted in RGBAX Sample
Sample (graphics)
In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
Length notation
The sample
Sample (graphics)
In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
fields defined by the BITFIELDS bit masks have to be contiguous and non-overlapping.
The Red, Green and Blue bit masks are valid only when the Compression member of the DIB Header is set to BI_BITFIELDS.
The Alpha bit mask is valid whenever it is present in the DIB Header or when the Compression member of the DIB Header is set to BI_ALPHABITFIELDS (Windows CE
Windows CE
Microsoft Windows CE is an operating system developed by Microsoft for embedded systems. Windows CE is a distinct operating system and kernel, rather than a trimmed-down version of desktop Windows...
only).
Diag.3 - The pixel format with an Alpha channel in a 16 bit pixel (in RGBAX Sample
Sample (graphics)
In computer graphics, a sample is an intersection of channel and a pixel.The diagram below depicts a 24-bit pixel, consisting of 3 samples for Red, Green, and Blue....
Length notation) actually generated by Adobe Photohop
-
-
-
- The table below lists all of the possible pixel formats of a DIB (in RGBAX notation).
-
-
The BITFIELD mechanism described above allows for the definition of tens of thousands different pixel formats, however only several of them are used in practice, such as:
- 8.8.8.0.0
- 8.8.8.0.8
- 8.8.8.8.0
- 5.5.5.0.1
- 5.5.5.1.0
- 5.6.5.0.0
- 4.4.4.0.4
- 4.4.4.4.0
- All palettized formats (marked in yellow in the table above)
[The list above is in the RGBAX notation]
Example 1
Following is an example of a 2×2 pixel, 24-bit bitmap (Windows DIB Header BITMAPINFOHEADER) with pixel format 8.8.8.0.0 (in RGBAX notation).Offset | Size | Hex Value | Value | Description |
---|---|---|---|---|
BMP Header | ||||
0h | 2 | 42 4D |
"BM" | Magic number (unsigned integer 66, 77) |
2h | 4 | 46 00 00 00 |
70 Bytes | Size of the BMP file |
6h | 2 | 00 00 |
Unused | Application specific |
8h | 2 | 00 00 |
Unused | Application specific |
Ah | 4 | 36 00 00 00 |
54 bytes | Offset where the Pixel Array (bitmap data) can be found |
DIB Header | ||||
Eh | 4 | 28 00 00 00 |
40 bytes | Number of bytes in the DIB header (from this point) |
12h | 4 | 02 00 00 00 |
2 pixels | Width of the bitmap in pixels |
16h | 4 | 02 00 00 00 |
2 pixels | Height of the bitmap in pixels |
1Ah | 2 | 01 00 |
1 plane | Number of color planes being used |
1Ch | 2 | 18 00 |
24 bits | Number of bits per pixel |
1Eh | 4 | 00 00 00 00 |
0 | BI_RGB, no Pixel Array compression used |
22h | 4 | 10 00 00 00 |
16 bytes | Size of the raw data in the Pixel Array (including padding) |
26h | 4 | 13 0B 00 00 |
2,835 pixels/meter | Horizontal resolution of the image |
2Ah | 4 | 13 0B 00 00 |
2,835 pixels/meter | Vertical resolution of the image |
2Eh | 4 | 00 00 00 00 |
0 colors | Number of colors in the palette |
32h | 4 | 00 00 00 00 |
0 important colors | 0 means all colors are important |
Start of Pixel Array (bitmap data) | ||||
36h | 3 | 00 00 FF |
0 0 255 | Red, Pixel (0,1) |
39h | 3 | FF FF FF |
255 255 255 | White, Pixel (1,1) |
3Ch | 2 | 00 00 |
0 0 | Padding for 4 byte alignment (could be a value other than zero) |
3Eh | 3 | FF 00 00 |
255 0 0 | Blue, Pixel (0,0) |
41h | 3 | 00 FF 00 |
0 255 0 | Green, Pixel (1,0) |
44h | 2 | 00 00 |
0 0 | Padding for 4 byte alignment (could be a value other than zero) |
Example 2
Following is an example of a 4×2 pixel, 32-bit bitmap with opacity values in the alpha channel (Windows DIB Header BITMAPV4HEADER) with pixel format 8.8.8.8.0 (in RGBAX notation).Offset | Size | Hex Value | Value | Description |
---|---|---|---|---|
BMP Header | ||||
0h | 2 | 42 4D |
"BM" | Magic number (unsigned integer 66, 77) |
2h | 4 | 9A 00 00 00 |
154 Bytes | Size of the BMP file |
6h | 2 | 00 00 |
Unused | Application specific |
8h | 2 | 00 00 |
Unused | Application specific |
Ah | 4 | 7A 00 00 00 |
122 bytes from the start of the file | Offset where the Pixel Array (bitmap data) can be found |
DIB Header | ||||
Eh | 4 | 6C 00 00 00 |
108 bytes | Number of bytes in the DIB header (from this point) |
12h | 4 | 04 00 00 00 |
4 pixels | Width of the bitmap in pixels |
16h | 4 | 02 00 00 00 |
2 pixels | Height of the bitmap in pixels |
1Ah | 2 | 01 00 |
1 plane | Number of color planes being used |
1Ch | 2 | 20 00 |
32 bits | Number of bits per pixel |
1Eh | 4 | 03 00 00 00 |
3 | BI_BITFIELDS, no Pixel Array compression used |
22h | 4 | 20 00 00 00 |
32 bytes | Size of the raw data in the Pixel Array (including padding) |
26h | 4 | 13 0B 00 00 |
2,835 pixels/meter | Horizontal physical resolution of the image |
2Ah | 4 | 13 0B 00 00 |
2,835 pixels/meter | Vertical physical resolution of the image |
2Eh | 4 | 00 00 00 00 |
0 colors | Number of colors in the palette |
32h | 4 | 00 00 00 00 |
0 important colors | 0 means all colors are important |
36h | 4 | 00 00 FF 00 |
00FF0000 in big-endian | Red channel bit mask (valid because BI_BITFIELDS is specified) |
3Ah | 4 | 00 FF 00 00 |
0000FF00 in big-endian | Green channel bit mask (valid because BI_BITFIELDS is specified) |
3Eh | 4 | FF 00 00 00 |
000000FF in big-endian | Blue channel bit mask (valid because BI_BITFIELDS is specified) |
42h | 4 | 00 00 00 FF |
FF000000 in big-endian | Alpha channel bit mask |
46h | 4 | 20 6E 69 57 |
LCS_WINDOWS_COLOR_SPACE | Type of Color Space |
4Ah | 24h | 24* 00...00 |
CIEXYZTRIPLE Color Space endpoints | Unused when LCS_WINDOWS_COLOR_SPACE is specified |
6Eh | 4 | 00 00 00 00 |
0 Red Gamma | Unused when LCS_WINDOWS_COLOR_SPACE is specified |
72h | 4 | 00 00 00 00 |
0 Green Gamma | Unused when LCS_WINDOWS_COLOR_SPACE is specified |
76h | 4 | 00 00 00 00 |
0 Blue Gamma | Unused when LCS_WINDOWS_COLOR_SPACE is specified |
Start of the Pixel Array (the bitmap Data) | ||||
7Ah | 4 | FF 00 00 7F |
255 0 0 127 | Blue (Alpha: 127), Pixel (0,1) |
7Eh | 4 | 00 FF 00 7F |
0 255 0 127 | Green (Alpha: 127), Pixel (1,1) |
82h | 4 | 00 00 FF 7F |
0 0 255 127 | Red (Alpha: 127), Pixel (2,1) |
86h | 4 | FF FF FF 7F |
255 255 255 127 | White (Alpha: 127), Pixel (3,1) |
8Ah | 4 | FF 00 00 FF |
255 0 0 255 | Blue (Alpha: 255), Pixel (0,0) |
8Eh | 4 | 00 FF 00 FF |
0 255 0 255 | Green (Alpha: 255), Pixel (1,0) |
92h | 4 | 00 00 FF FF |
0 0 255 255 | Red (Alpha: 255), Pixel (2,0) |
96h | 4 | FF FF FF FF |
255 255 255 255 | White (Alpha: 255), Pixel (3,0) |
Note that the bitmap data starts with the lower left hand corner of the image.
Usage of BMP format
The simplicity of the BMP file format, and its widespread familiarity in Windows and elsewhere, as well as the fact that this format is relatively well documentedDocumentation
Documentation is a term used in several different ways. Generally, documentation refers to the process of providing evidence.Modules of Documentation are Helpful...
and free of patent
Patent
A patent is a form of intellectual property. It consists of a set of exclusive rights granted by a sovereign state to an inventor or their assignee for a limited period of time in exchange for the public disclosure of an invention....
s, makes it a very common format that image processing programs from many operating systems can read and write.
Many older graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...
s used bitmaps in their built-in graphics subsystems; for example, the Microsoft Windows and OS/2 platforms' GDI
Graphics Device Interface
The Graphics Device Interface is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers....
subsystem, where the specific format used is the Windows and OS/2 bitmap file format, usually named with the file extension of
.BMP
or .DIB
.While most BMP files have a relatively large file size due to lack of any compression (or generally low-ratio RLE
Run-length encoding
Run-length encoding is a very simple form of data compression in which runs of data are stored as a single data value and count, rather than as the original run...
on palletized images), many BMP files can be considerably compressed with lossless data compression
Lossless data compression
Lossless data compression is a class of data compression algorithms that allows the exact original data to be reconstructed from the compressed data. The term lossless is in contrast to lossy data compression, which only allows an approximation of the original data to be reconstructed, in exchange...
algorithms such as ZIP
ZIP (file format)
Zip is a file format used for data compression and archiving. A zip file contains one or more files that have been compressed, to reduce file size, or stored as is...
(in extreme cases of non-photographic data, up to 0.1% of original size) because they contain redundant data. Some formats, such as RAR, even include routines specifically targeted at efficient compression of such data.
Related formats
The X Window SystemX Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...
uses a similar XBM format for black-and-white
Black-and-white
Black-and-white, often abbreviated B/W or B&W, is a term referring to a number of monochrome forms in visual arts.Black-and-white as a description is also something of a misnomer, for in addition to black and white, most of these media included varying shades of gray...
images, and XPM (pixelmap) for color
Color
Color or colour is the visual perceptual property corresponding in humans to the categories called red, green, blue and others. Color derives from the spectrum of light interacting in the eye with the spectral sensitivities of the light receptors...
images. There are also a variety of "raw" formats, which saves raw data
Data
The term data refers to qualitative or quantitative attributes of a variable or set of variables. Data are typically the results of measurements and can be the basis of graphs, images, or observations of a set of variables. Data are often viewed as the lowest level of abstraction from which...
with no other information
Information
Information in its most restricted technical sense is a message or collection of messages that consists of an ordered sequence of symbols, or it is the meaning that can be interpreted from such a message or collection of messages. Information can be recorded or transmitted. It can be recorded as...
. The Portable Pixmap
Portable pixmap
The phrase Netpbm format commonly refers to any or all of the members of a set of closely related graphics formats used and defined by the Netpbm project....
(PPM) and Truevision TGA
Truevision TGA
Truevision TGA, often referred to as TARGA, is a raster graphics file format created by Truevision Inc. . It was the native format of TARGA and VISTA boards, which were the first graphic cards for IBM-compatible PCs to support Highcolor/truecolor display...
formats also exist, but are less often used – or only for special purposes; for example, TGA can contain transparency information.
Numerous other bitmap file formats are in existence, though most are not widely used.