Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
BMP file format
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== 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 2 bytes of the BMP file format are the character "B" then the character "M" in [[ASCII]] encoding. All of the integer values are stored in [[little-endian]] format (i.e. least-significant byte first). {| class="wikitable" |- ! Offset hex ! Offset dec ! Size ! Purpose |- | 00||0 | 2 bytes | The [[File format#Magic number|header field]] used to identify the BMP and DIB file is <code>0x42 0x4D</code> in [[hexadecimal]], same as <code>BM</code> in ASCII. The following entries are possible: ;BM: Windows 3.1x, 95, NT, ... etc. ;BA: OS/2 struct bitmap array ;CI: OS/2 struct color icon ;CP: OS/2 const color pointer ;IC: OS/2 struct icon ;PT: OS/2 pointer |- | 02||2 | 4 bytes | The size of the BMP file in bytes |- | 06||6 | 2 bytes | Reserved; actual value depends on the application that creates the image, if created manually can be 0 |- | 08||8 | 2 bytes | Reserved; actual value depends on the application that creates the image, if created manually can be 0 |- | 0A||10 | 4 bytes | The offset, i.e. starting address, of the byte where the bitmap image data (pixel array) can be found. |} ==== 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. {| class="wikitable" |+ Windows and OS/2 bitmap headers |- ! Size ! Header name ! OS support ! Features ! Written by |- | align="right"| 12 | {{mono|BITMAPCOREHEADER}}<br />{{mono|OS21XBITMAPHEADER}} | [[Windows 2.0]] or later<br />[[OS/2]] 1.x<ref name="os2bmp" /> | | |- | align="right"| 64 | {{mono|OS22XBITMAPHEADER}} | [[OS/2]] {{mono|BITMAPCOREHEADER}}2 | Adds [[halftoning]]. Adds [[Run-length encoding|RLE]] and [[Huffman coding|Huffman]] 1D compression. | |- | align="right"| 16 | {{mono|OS22XBITMAPHEADER}} | This variant of the previous header contains only the first 16 bytes and the remaining bytes are assumed to be zero values.<ref name="os2bmp" /> An example of such a case is the graphic [http://entropymine.com/jason/bmpsuite/bmpsuite/q/pal8os2v2-16.bmp pal8os2v2-16.bmp]<ref name="pal8os2v2-16.bmp">{{cite web| title=pal8os2v2-16.bmp|date=2015-10-30|access-date=2016-07-06|first=Jason|last=Summers| url=http://entropymine.com/jason/bmpsuite/bmpsuite/q/pal8os2v2-16.bmp}}</ref> of the BMP Suite.<ref name="bmpsuite">{{cite web|title=BMP Suite| date=2015-10-30|access-date=2016-07-06|first=Jason|last=Summers| url=http://entropymine.com/jason/bmpsuite/}}</ref> | | |- | align="right"| 40 | {{mono|BITMAPINFOHEADER}} | [[Windows NT]], [[Windows 3.1x|3.1x]] or later<ref name="bmp" /> | Extends bitmap width and height to 4 bytes. Adds 16 bpp and 32 bpp formats. Adds RLE compression. | |- | align="right"| 52 | {{mono|BITMAPV2INFOHEADER}} | Undocumented | Adds RGB bit masks. | Adobe Photoshop |- | align="right"| 56 | {{mono|BITMAPV3INFOHEADER}} | Not officially documented, but this documentation was posted on Adobe's forums, by an employee of Adobe with a statement that the standard was at one point in the past included in official MS documentation<ref>{{cite web|url=https://forums.adobe.com/message/3272950#3272950|title=Invalid BMP Format with Alpha channel|work=[[Adobe Photoshop|Photoshop Windows]] forum|date=2010-11-15|publisher=[[Adobe Systems|Adobe]]|first=Chris|last=Cox|archive-url=https://web.archive.org/web/20150127132443/https://forums.adobe.com/message/3272950|url-status = live|archive-date=2015-01-27|access-date=2016-05-22}}</ref> | Adds [[alpha channel]] bit mask. | Adobe Photoshop |- | align="right"| 108 | {{mono|BITMAPV4HEADER}} | [[Windows NT 4.0]], [[Windows 95|95]] or later | Adds color space type and [[gamma correction]] | |- | align="right"| 124 | {{mono|BITMAPV5HEADER}} | [[Windows 2000|Windows NT 5.0]], [[Windows 98|98]] or later | Adds [[ICC profile|ICC color profiles]] | The GIMP |} {| class="wikitable" ! Offset (hex)|| Offset (dec) ! Size (bytes) ! OS/2 1.x {{mono|BITMAPCOREHEADER}}<ref name="os2bmp">{{cite book|title=Encyclopedia of Graphics File Formats|edition=Second|date=April 1996|author=James D. Murray|author2=William vanRyper|isbn=1-56592-161-5|publisher=[[O'Reilly Media|O'Reilly]]|at=[https://archive.org/details/mac_Graphics_File_Formats_Second_Edition_1996/page/ os2bmp]|url=https://archive.org/details/mac_Graphics_File_Formats_Second_Edition_1996/page/|access-date=2014-03-07}}</ref> |- | 0E||14 | 4 | The size of this header (12 bytes) |- | 12||18 | 2 | The bitmap width in pixels (unsigned 16-bit) |- | 14||20 | 2 | The bitmap height in pixels (unsigned 16-bit) |- | 16||22 | 2 | The number of color planes, must be 1 |- | 18||24 | 2 | The number of bits per pixel |+ align="bottom" style="caption-side: bottom" | {{nobold|OS/2 1.x bitmaps are uncompressed and cannot be 16 or 32 bpp.}} |} The Windows 2.x BITMAPCOREHEADER differs from the OS/2 1.x BITMAPCOREHEADER (shown in the table above) in the one detail that the image width and height fields are signed integers, not unsigned.<ref>{{Cite web|url=https://www.fileformat.info/format/bmp/egff.htm|title = Microsoft Windows Bitmap: Summary from the Encyclopedia of Graphics File Formats}}</ref> Versions after {{mono|BITMAPINFOHEADER}} only add fields to the end of the header of the previous version. For example: {{mono|BITMAPV2INFOHEADER}} adds fields to {{mono|BITMAPINFOHEADER}}, and {{mono|BITMAPV3INFOHEADER}} adds fields to {{mono|BITMAPV2INFOHEADER}}. An integrated alpha channel has been introduced with the undocumented {{mono|BITMAPV3INFOHEADER}} and with the documented {{mono|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]], [[Microsoft PowerPoint]] and [[Microsoft Word]]. For compatibility reasons, most applications use the older DIB headers for saving files. '''With OS/2 no longer supported after Windows 2000, for now the common Windows format is the {{mono|BITMAPINFOHEADER}} header.''' See next table for its description. All values are stored as unsigned integers, unless explicitly noted.{{Clear}} {| class="wikitable" ! Offset (hex)|| Offset (dec) ! Size (bytes) ! Windows {{mono|BITMAPINFOHEADER}}<ref name="bmp" /> |- | 0E||14 | 4 | the size of this header, in bytes (40) |- | 12|| 18 | 4 | the bitmap width in pixels (signed integer) |- | 16|| 22 | 4 | the bitmap height in pixels (signed integer) |- | 1A||26 | 2 | the number of color planes (must be 1) |- | 1C||28 | 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. |- | 1E||30 | 4 | the compression method being used. See the next table for a list of possible values |- | 22||34 | 4 | the image size. This is the size of the raw bitmap data; a dummy 0 can be given for BI_RGB bitmaps. |- | 26||38 | 4 | the horizontal resolution of the image. (pixel per metre, signed integer) |- | 2A||42 | 4 | the vertical resolution of the image. (pixel per metre, signed integer) |- | 2E||46 | 4 | the number of colors in the color palette, or 0 to default to 2<sup>''n''</sup> |- | 32||50 | 4 | the number of important colors used, or 0 when every color is important; generally ignored |} The compression method (offset 30) can be: {| class="wikitable" |- ! Value ! Identified by ! Compression method ! Comments |- | 0 | {{mono|BI_RGB}} | {{CNone|none}} | Most common |- | 1 | {{mono|BI_RLE8}} | [[Run-length encoding|RLE]] 8-bit/pixel | Can be used only with 8-bit/pixel bitmaps |- | 2 | {{mono|BI_RLE4}} | RLE 4-bit/pixel | Can be used only with 4-bit/pixel bitmaps |- | 3 | valign="top" | {{mono|BI_BITFIELDS}} | valign="bottom" | <abbr title="Only OS/2 2.x or later">{{mono|OS22XBITMAPHEADER}}</abbr>: Huffman 1D | {{mono|BITMAPV2INFOHEADER}}: RGB bit field masks, <br /><abbr title="V3 or later">{{mono|BITMAPV3INFOHEADER}}+</abbr>: RGBA |- | 4 | {{mono|BI_JPEG}} | <abbr title="Only OS/2 2.x or later">{{mono|OS22XBITMAPHEADER}}</abbr>: RLE-24 | <abbr title="Windows NT 4.0 & 95 or later">{{mono|BITMAPV4INFOHEADER}}+</abbr>: [[JPEG]] image for printing<ref name="onlyprint"> {{cite web | url = http://msdn.microsoft.com/en-us/library/dd145023(VS.85).aspx | title = JPEG and PNG Extensions for Specific Bitmap Functions and Structures}}</ref> |- | 5 | {{mono|BI_PNG}} | | <abbr title="Windows NT 4.0 & 95 or later">{{mono|BITMAPV4INFOHEADER}}+</abbr>: [[Portable Network Graphics|PNG]] image for printing<ref name="onlyprint" /> |- | 6 | {{mono|BI_ALPHABITFIELDS}} | RGBA bit field masks | only [[Windows CE]] 5.0 with .NET 4.0 or later |- | 11 | {{mono|BI_CMYK}} | {{CNone|none}} | only [[Windows Metafile]] [[CMYK color model|CMYK]]<ref name="v11" /> |- | 12 | {{mono|BI_CMYKRLE8}} | RLE-8 | only [[Windows Metafile]] CMYK |- | 13 | {{mono|BI_CMYKRLE4}} | RLE-4 | only [[Windows Metafile]] CMYK |} An OS/2 2.x {{mono|OS22XBITMAPHEADER}} ({{mono|BITMAPINFOHEADER2}} in IBM's documentation) contains 24 additional bytes:<ref name="os2bmp" /> {| class="wikitable" ! Offset (hex)|| Offset (dec) ! Size (bytes) ! OS/2 {{mono|OS22XBITMAPHEADER}} ({{mono|BITMAPINFOHEADER2}})<ref name="os2bmp" /> |- | 36||54 | 2 | An enumerated value specifying the units for the horizontal and vertical resolutions (offsets 38 and 42). The only defined value is 0, meaning pixels per metre |- | 38||56 | 2 | Padding. Ignored and should be zero |- | 3A||58 | 2 | An enumerated value indicating the direction in which the bits fill the bitmap. The only defined value is 0, meaning the origin is the lower-left corner. Bits fill from left-to-right, then bottom-to-top. Note that Windows bitmaps (which don't include this field) can also specify an upper-left origin (bits fill from left-to-right, then top-to-bottom) by using a negative value for the image height |- | 3C||60 | 2 | An enumerated value indicating a halftoning algorithm that should be used when rendering the image. |- | 3E||62 | 4 | Halftoning parameter 1 (see below) |- | 42||66 | 4 | Halftoning parameter 2 (see below) |- | 46||70 | 4 | An enumerated value indicating the color encoding for each entry in the color table. The only defined value is 0, indicating RGB. |- | 4A||74 | 4 | An application-defined identifier. Not used for image rendering |} The halftoning algorithm (offset 60) can be: {| class="wikitable" |- ! Value ! Halftoning algorithm ! Comments |- | 0 | {{CNone|none}} | Most common |- | 1 | [[Error diffusion]] | Halftoning parameter 1 (offset 64) is the percentage of error damping. 100 indicates no damping. 0 indicates that errors are not diffused |- | 2 | PANDA: Processing Algorithm for Noncoded Document Acquisition | Halftoning parameters 1 and 2 (offsets 64 and 68, respectively) represent the X and Y dimensions, in pixels, respectively, of the halftoning pattern used |- | 3 | Super-circle | Halftoning parameters 1 and 2 (offsets 64 and 68, respectively) represent the X and Y dimensions, in pixels, respectively, of the halftoning pattern used |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)