Opentopia Directory Encyclopedia Tools

Windows bitmap

Encyclopedia : W : WI : WIN : Windows bitmap


.BMP or .DIB (device-independent bitmap) is a bitmapped graphics format used internally by the Microsoft Windows graphics subsystem (GDI), and used commonly as a simple graphics file format on that platform.

Images are generally stored with a color depth of 2 (1-bit), 16 (4-bit), 256 (8-bit), 65,536 (16-bit), or 16.7 million (24-bit) colors (the bits represent the bits per pixel). 8-bit images can also be greyscale instead of indexed color. An alpha channel (for transparency) may be stored in a separate file, where it is similar to a greyscale image. A 32-bit version with integrated alpha channel has been introduced with Windows XP and is used within its logon and theme system; it has yet to gain wide support in image editing software.

Storage Algorithm

BMP files are usually not compressed, so they are typically much larger than compressed image file formats for the same image. For example, an 800×600 24-bit image will occupy almost 1.4 megabytes. As such they are generally unsuitable for transferring images on the Internet or other slow or capacity-limited media.

Depending on the color depth, a pixel in the picture will be stored using one or more bytes, which is determined by n/8 (n is the bit depth, since 1 byte equals 8 bits). The color of the pixel will be calculated (by the picture viewer, for example) based on the ASCII code of the bytes and the corresponding values read from the color palette. For more detailed information, see the section of bitmap file format below.

The approximate size for a n-bit (2n colors) bitmap in bytes can be calculated as:

size of BMP file [\approx 54+4 \cdot 2^n+\frac], where height and width are given in pixels.

It should be noted that 54 in the above formula is the size of the header of the bitmap file. And [4 \cdot 2^n] is the size of the color palette. Notice that this is an approximation, as for a n-bit bitmap image, although there can be maximum [2^n] colors, a specific image may not use all of these colors. Since the color palette only defines the colors that are used by the image, the actual size of the color palette will be smaller than [4 \cdot 2^n].

For detailed information on how these values are derived, see the sections on file format below.

Due to storage algorithm, the calculated size will be slightly different from the actual file size, depending on several image parameters.

Typical File Format

A typical bitmap file usually contains the following blocks of data:

The following sections discuss the data stored in the bitmap file in details. Notice that this is the standard bitmap file format. Some bitmap images may be stored using a slightly different format, depending on the application that creates it. Also, not all fields are being used, and as such, a value of 0 will be found in these unused fields.

Bitmap Header

This block of bytes is used for identification. A typical application will read this block first to ensure that the file is actually a bitmap file and that it is not damaged.

Bitmap Information

This block of bytes tells the application detailed information about the image, which will be used to display the image on the screen. It starts at byte #14 of the file.

0 - none (also identified by BI_RGB)
1 - RLE 8-bit/pixel (also identified by BI_RLE8)
2 - RLE 4-bit/pixel (also identified by BI_RLE4)
3 - Bit field (also identified by BI_BITFIELDS)
4 - a JPEG image (also identified by BI_JPEG)
5 - a PNG image (also identified by BI_PNG)
However, since most BMP images are uncompressed, the most common value is 0.

Color Palette

This block of bytes define the colors being used inside the image. As stated above, the bitmap picture will be stored pixel by pixel. Each pixel is described by a value which will be stored using one or more bytes. Therefore, the purpose of the color palette is to tell the application the actual color that each of these values corresponds to.

A typical bitmap file uses the RGB color model. In this model, a color is created by mixing different intensities (which can vary from 0 to 255) of red (R), green (G) and blue (B). Or in other words, a color will be defined using its 3 values for R, G and B.

In the bitmap file implementation, the color palette contains many entries; the number of entries is the number of colors being used in the picture. Each entry contains 4 bytes: 3 for red, green and blue and the last one is unused (which will be filled with 0 by most applications). For each byte, a value of 0 indicates that the corresponding color (either red, green, or blue) is not used to create the current image color. On the contrary, a value of 255 indicates that maximum intensity is used.

Bitmap Data

This block of bytes describes the image, pixel by pixel. Pixels are stored from the bottom to the top of the images, and then from the left to the right. Each pixel is described using one or more bytes. If the number of bytes matching a horizontal line in the image is not a quadruple, i.e. an integer divisible by 4, the line is padded with null-bytes, which usually have ASCII codes of 0.

Miscellaneous

Despite the huge file size, the simplicity of BMP and its widespread familiarity in MS Windows and elsewhere, as well as the fact that this format is well-documented and free of patents, makes it a very common format that image processing programs from many operating systems can read and write.

The X Window System uses a similar .XBM format for true single-bit black and white images, and .XPM (pixelmap) for color images. There is also a .RAW format, which saves raw data with no other information. The Portable Pixmap file format (.PPM) and Truevision TGA (.TGA) formats also exist, but are rarely used - or only for special purposes. Yet other formats store as "bitmaps" (as opposed to vector graphics), but use compression or color indexes, and thus are not strictly considered true bitmaps.

Most BMP files compress very well with lossless data compression algorithms such as ZIP because they contain redundant data.

See also

External links

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: