老年斑是什么原因引起的| 鲫鱼吃什么| 鸟飞到头上什么预兆| 匆匆那年是什么意思| 产后42天复查都检查什么| 空腹c肽偏高说明什么| 花心大萝卜是什么意思| 维生素c什么时候吃最好| 纳尼是什么意思| 正三角形是什么| 月经有血块是什么原因| 璨字五行属什么| 1940年出生属什么生肖| 金克木是什么意思| 橄榄油的好处和坏处是什么| 为什么叫夺命大乌苏| 薤白是什么东西| 流觞是什么意思| 私募是什么意思| 脸上出油是什么原因| 破财免灾什么意思| 吃什么补维生素| tommyhilfiger什么牌子| 斐乐手表属于什么档次| 成龙真名叫什么名字| 33数字代表什么意思| 内膜厚吃什么掉内膜| 1959年属什么| 回族信奉什么教| 脱头发严重是什么原因引起的| 钟乳石是什么| 大鱼际发青是什么原因| 佝偻是什么意思| 一戴套就软是什么原因| 齐天大圣是什么级别| 聚酰胺纤维是什么面料| 真菌阴性是什么意思| 隐翅虫咬了用什么药| 肝内胆管轻度扩张是什么意思| 死水是什么| 耳鸣吃什么药效果好| 反复感冒是什么原因引起的| 尿素高什么原因| 海参不能和什么一起吃| 胰腺炎是什么病严重吗| 花裙子配什么上衣好看| 喝酸奶有什么好处| 什么叫肾阴虚和肾阳虚| 什么样属于轻度地包天| 例假来的是黑色的是什么原因| 枸杞有什么作用和功效| 属猴与什么属相最配| 9.23什么星座| 食铁兽是什么动物| 一直打哈欠是什么原因| 父母是o型血孩子是什么血型| 百合与什么搭配最好| 丙肝病毒抗体阴性是什么意思| 梦见老公出轨预示什么| 乳核是什么| 大利月小利月什么意思| 簋是什么| 心梗什么症状| 可尔必思是什么饮料| 照影是什么意思| 吃饭肚子疼是什么原因| 急性胰腺炎吃什么药| 做什么生意挣钱| 学考成绩什么时候公布| 茹什么饮什么| 什么叫比例| 23数字代表什么意思| 尿路感染吃什么药效果好| 23333是什么意思| 康宽杀虫剂能杀什么虫| loho是什么牌子| 双侧卵巢多卵泡是什么意思| 医学是什么| 洁身自好什么意思| 紫苏有什么功效与作用| 小孩肠套叠什么症状| 乳腺钼靶是什么意思| olayks是什么牌子| 屁股长痘是什么原因| 腋下皮肤发黑是什么原因引起的| 开背是什么意思| p是什么医学| 牛奶不能和什么一起吃| 吞拿鱼是什么鱼| 什么叫血沉| 胭脂是什么东西| 尿常规能检查出什么| 吃什么食物治便秘| 心衰做什么检查能确诊| 尿毒症的尿是什么颜色| 脸上长藓用什么药| 疝气是什么病| 三白眼是什么意思| 前兆是什么意思| 恶露是什么样子的图片| 蔡徐坤粉丝名叫什么| 吃什么增强免疫力| 手突然抽搐是什么原因| 梦见烙饼是什么意思| 鸡和什么属相最配对| 接骨草长什么样| 桂花什么时候开| c罗全名叫什么| 争奇斗艳是什么意思| 巧克力是什么材料做的| 肝病晚期什么症状| 1946年属什么生肖| 女大四岁有什么说法| 月经一直不干净吃什么药| 贲门炎是什么意思| 含漱是什么意思| 什么是梅毒| 龙阳之好是什么意思| 为什么来姨妈会拉肚子| 属鸡适合佩戴什么饰品| 黑眼圈重是什么原因| 正厅级是什么级别| 立字五行属什么| uvb是什么意思| 天丝是什么材料| 性生活什么意思| 琥珀是什么颜色| 未病是什么意思| 张伦硕为什么娶钟丽缇| 什么东西进去是硬的出来是软的| 稳是什么意思| 梦见迁祖坟有什么预兆| 脚脖子疼是什么原因| 甲状腺什么原因引起的| 清创手术是什么意思| 铜镯子对人有什么好处| 中国人在印度属于什么种姓| 吐司是什么| 制动什么意思| 屁眼火辣辣的疼是什么原因| 汪字五行属什么| 植物光合作用产生什么| 打喷嚏流鼻涕吃什么药| 4月7号是什么星座| 物以类聚形容什么动物| 人体缺钾是什么原因引起的| 女人排卵是什么时候| 三伏天从什么时候开始| 567是什么意思| 中央型肺ca是什么意思| 92年出生属什么| 为什么拉绿色的屎| 血压高什么原因| 一阴一阳是什么数字| 舒五行属性是什么| 什么是匝道图片| 铁皮石斛花有什么作用| 油烟机没有吸力是什么原因| 口是心非什么意思| 甜蜜素是什么| 什么能增强免疫力| 一什么树| 膝关节痛挂什么科| normal是什么意思| 小别胜新婚是什么意思| 手链断了是什么预兆| 小孩黄疸是什么原因引起的| 睾丸扭转有什么症状| 什么样的孕妇容易翻盘| 代谢慢吃什么效果最快| 什么洗发水去屑效果好| 咽拭子是检查什么的| 69岁属什么| 小肠是干什么的| 嘴唇发黑是什么原因| 嗑药是什么意思| 健康证明需要检查什么| 肠道功能紊乱吃什么药效果好| 男生的蛋蛋长什么样| 脚踝后面的筋疼因为什么| 来月经吃什么排得最干净| 肇庆有什么大学| 健身后应该吃什么| 姐姐的老公叫什么| 前壁后壁有什么区别| 助听器什么品牌最好| 口嫌体正直什么意思| 主动脉增宽是什么意思| 红豆与赤小豆有什么区别| 麻叶是什么植物| 散光跟近视有什么区别| 慰安妇是什么意思| 姑息是什么意思| 邓紫棋为什么叫gem| 碧螺春属于什么茶类| 什么是热辐射| 大云是什么| 检查肺部应该挂什么科| 2月29号是什么星座| 什么叫宿根太阳花| 什么工作赚钱最快| 关羽的刀叫什么名字| hpv阳性是什么意思| 纾是什么意思| 1976年五行属什么| 大红色配什么颜色好看| 多喝酸奶有什么好处| 男性生殖器官叫什么| 缺钾吃什么食物补得最快| 柒牌男装什么档次| 咳嗽干呕是什么原因| 梦见蛇吃人代表什么预兆| 伪骨科是什么意思| 捣碎东西的器皿叫什么| 嬴政姓什么| 脑门疼是什么原因| 孕妇低血压什么补最快| 蛇用什么呼吸| 联系是什么意思| 初秋的天冰冷的夜是什么歌| infp是什么意思| 毕业礼物送什么| 四大美女是什么生肖| 酱油和生抽有什么区别| 圈名什么意思| 过房养是什么意思| 肝硬化吃什么好| 球虫病有什么症状| 6月30日什么星座| 中国最毒的蛇是什么蛇| 懂事是什么意思| 鸡生肖配什么生肖最好| 肺癌早期有什么症状| 屁股长痘痘是什么原因| 叶绿素主要吸收什么光| 声音的传播需要什么| 青蒿素是什么| 办护照带什么资料| 九浅一深是什么意思| 哦吼是什么意思| 血燥是什么意思| 四叶草代表什么意思| 什么的东西| 大便遇水就散什么原因| 在野是什么意思| lancome是什么品牌| 什么药可以降尿酸| 心脏支架是什么材料做的| 凌晨两点半是什么时辰| 纯天然无公害什么意思| 斜率是什么| pg是什么意思| 精子是什么| 病机是什么意思| 什么食物含磷高| ca125高是什么原因| 柠檬水有什么好处| 泥鳅吃什么食物| 96166是什么电话| 为什么延迟退休| 病毒性疣是什么病| 蚧壳虫用什么药| 腰间盘突出有什么好的治疗方法| 为什么不| 百度Jump to content

曹妃甸也有共享单车了!这周投放曹妃甸大学城!

From Wikipedia, the free encyclopedia
Windows Bitmap
Filename extension
.bmp, .dib
Internet media typeimage/bmp[1]
image/x-bmp
Type code'BMP '
'BMPf'
'BMPp'
Uniform Type Identifier (UTI)com.microsoft.bmp
Developed byMicrosoft Corporation
Type of formatRaster graphics
Open format?OSP for WMF
百度 要充分发挥江苏的特色优势,进一步深化苏台经贸交流与合作,促进两地产业融合发展。

The BMP file format, or bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device (such as a graphics adapter), especially on Microsoft Windows[2] and OS/2[3] operating systems.

The BMP file format is capable of storing two-dimensional digital images in various color depths, and optionally with data compression, alpha channels, and color profiles. The Windows Metafile (WMF) specification covers the BMP file format.[4]

Device-independent bitmaps and the BMP file format

[edit]
Diagram 1 – The structure of the bitmap image file
Diagram 1 – The structure of the bitmap image file

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:[5]

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 detail. This is the standard BMP file format.[5] Some applications create bitmap image files which are not compliant with the Microsoft documentation. Also, not all fields are used; a value of 0 will be found in these unused fields.

File structure

[edit]

The bitmap image file consists of fixed-size structures (headers) as well as variable-sized 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 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
(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[6]
(12 or 16 bytes)
To define the pixel format Present only in case the DIB header is the BITMAPINFOHEADER and the Compression Method member is set to either BI_BITFIELDS or BI_ALPHABITFIELDS
Color table Semi-optional Variable size To define colors used by the bitmap image data (Pixel array) Mandatory for color depths ≤ 8 bits
Gap1 Yes Variable size Structure alignment An artifact of the File offset to Pixel array 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 for color management 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.[7]

DIBs in memory

[edit]

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[8] (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[7] (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.[8] 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).[7]
"Packed DIBs" are required by Windows clipboard API functions as well as by some Windows patterned brush and resource functions.[9]

Bitmap file header

[edit]

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).

Offset hex Offset dec Size Purpose
00 0 2 bytes The header field used to identify the BMP and DIB file is 0x42 0x4D in hexadecimal, same as BM 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)

[edit]

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.

Windows and OS/2 bitmap headers
Size Header name OS support Features Written by
12 BITMAPCOREHEADER
OS21XBITMAPHEADER
Windows 2.0 or later
OS/2 1.x[3]
64 OS22XBITMAPHEADER OS/2 BITMAPCOREHEADER2 Adds halftoning. Adds RLE and Huffman 1D compression.
16 OS22XBITMAPHEADER This variant of the previous header contains only the first 16 bytes and the remaining bytes are assumed to be zero values.[3]

An example of such a case is the graphic pal8os2v2-16.bmp[10] of the BMP Suite.[11]

40 BITMAPINFOHEADER Windows NT, 3.1x or later[2] Extends bitmap width and height to 4 bytes. Adds 16 bpp and 32 bpp formats. Adds RLE compression.
52 BITMAPV2INFOHEADER Undocumented Adds RGB bit masks. Adobe Photoshop
56 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[12] Adds alpha channel bit mask. Adobe Photoshop
108 BITMAPV4HEADER Windows NT 4.0, 95 or later Adds color space type and gamma correction
124 BITMAPV5HEADER Windows NT 5.0, 98 or later Adds ICC color profiles The GIMP
Offset (hex) Offset (dec) Size (bytes) OS/2 1.x BITMAPCOREHEADER[3]
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
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.[13]

Versions after BITMAPINFOHEADER 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.

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, 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 BITMAPINFOHEADER header. See next table for its description. All values are stored as unsigned integers, unless explicitly noted.

Offset (hex) Offset (dec) Size (bytes) Windows BITMAPINFOHEADER[2]
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 2n
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:

Value Identified by Compression method Comments
0 BI_RGB none Most common
1 BI_RLE8 RLE 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 OS22XBITMAPHEADER: Huffman 1D BITMAPV2INFOHEADER: RGB bit field masks,
BITMAPV3INFOHEADER+: RGBA
4 BI_JPEG OS22XBITMAPHEADER: RLE-24 BITMAPV4INFOHEADER+: JPEG image for printing[14]
5 BI_PNG BITMAPV4INFOHEADER+: PNG image for printing[14]
6 BI_ALPHABITFIELDS RGBA bit field masks only Windows CE 5.0 with .NET 4.0 or later
11 BI_CMYK none only Windows Metafile CMYK[4]
12 BI_CMYKRLE8 RLE-8 only Windows Metafile CMYK
13 BI_CMYKRLE4 RLE-4 only Windows Metafile CMYK

An OS/2 2.x OS22XBITMAPHEADER (BITMAPINFOHEADER2 in IBM's documentation) contains 24 additional bytes:[3]

Offset (hex) Offset (dec) Size (bytes) OS/2 OS22XBITMAPHEADER (BITMAPINFOHEADER2)[3]
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:

Value Halftoning algorithm Comments
0 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

Color table

[edit]

The color table (palette) occurs in the BMP image file directly after the BMP file header, the DIB header, and after the optional three or four bitmasks if the BITMAPINFOHEADER header with BI_BITFIELDS (12 bytes) or BI_ALPHABITFIELDS (16 bytes) option is used. Therefore, its offset is the size of the BITMAPFILEHEADER plus the size of the DIB header (plus optional 12-16 bytes for the three or four bit masks).
Note: On Windows CE the BITMAPINFOHEADER header can be used with the BI_ALPHABITFIELDS[6] option in the biCompression member.

The number of entries in the palette is either 2n (where n is the number of bits per pixel) or a smaller number specified in the header (in the OS/2 BITMAPCOREHEADER header format, only the full-size palette is supported).[3][5] In most cases, each entry in the color table occupies 4 bytes, in the order blue, green, red, 0x00 (see below for exceptions). This is indexed in the BITMAPINFOHEADER in the structure member biBitCount.

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 palettization.

The colors in the color table are usually specified in the 4-byte per entry ARGB32 format. The color table used with the OS/2 BITMAPCOREHEADER uses the 3-byte per entry RGB24 format.[3][5] For DIBs loaded in memory, the color table can optionally consist of 2-byte entries – these entries constitute indexes to the currently realized palette[8] instead of explicit RGB color definitions.

Microsoft does not disallow the presence of a valid alpha channel bit mask[15] 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[16] 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[17]) 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

[edit]

The bits representing the bitmap pixels are packed in rows (also known as strides or scan lines). The size of each row is rounded up to a multiple of 4 bytes (a 32-bit DWORD) by padding.[18]

For images with height above 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 equation above uses the floor and ceiling functions.

The total number 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 4 bytes, as follows:

ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight is expressed as a negative number for top-down images.

Pixel array (bitmap data)

[edit]

The pixel array is a block of 32-bit DWORDs, that describes the image pixel by pixel. Usually pixels are stored "bottom-up", 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.[5] Unless BITMAPCOREHEADER is used, 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).[5] Contemporary DIB Headers allow pixel formats with 1, 2, 4, 8, 16, 24 and 32 bits per pixel (bpp).[19] GDI+ also permits 64 bits per pixel.[20]

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 Arrays 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.[5] 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 6 bytes of data and 2 bytes of padding, Width=3 would have 9 bytes of data and 3 bytes of padding, and Width=4 would have 12 bytes of data and no padding.

Compression

[edit]
  • Indexed 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 depths can be stored without compression if so desired.

Pixel format

[edit]
  • The 1-bit per pixel (1bpp) format supports 2 distinct colors, (for example: black and white). The pixel values are stored in each bit, with the first (left-most) pixel in the most-significant bit of the first byte.[5] Each bit is an index into a table of 2 colors. 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 CE only:[21]). Each pixel value is a 2-bit index into a table of up to 4 colors.
  • 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 nibble.[5] Each pixel value is a 4-bit index into a table of up to 16 colors.
  • 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.
  • 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 samples of the pixel.
  • The 24-bit per 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 samples of the pixel (8.8.8.0.0 in RGBAX notation). Specifically, in the order: blue, green and red (8 bits per each sample).[5]
  • 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 samples of the pixel.

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
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, but the order of the sample fields is arbitrary. The most ubiquitous field order is: Alpha, Blue, Green, Red (MSB to LSB). 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[6] (Windows CE only).

Diag. 3 – The pixel format with an alpha channel for a 16-bit pixel (in RGBAX sample Length notation) actually generated by Adobe Photoshop[22]
Diag. 3 – The pixel format with an alpha channel for a 16-bit pixel (in RGBAX sample Length notation) actually generated by Adobe Photoshop[22]
All of the possible pixel formats in a DIB
All of the possible pixel formats in a DIB

RGB video subtypes

[edit]

The BITFIELD mechanism described above allows for the definition of tens of thousands of different pixel formats, however only several of them are used in practice,[22] all palettized formats RGB8, RGB4, and RGB1 (marked in yellow in the table above, defined in dshow.h.MEDIASUBTYPE names):

Uncompressed RGB Video Subtypes[23]
R.G.B.A.X RGB subtype R.G.B.A.X ARGB subtype
8.8.8.0.8 RGB32 8.8.8.8.0 ARGB32
10.10.10.2.0 A2R10G10B10
8.8.8.0.0 RGB24 10.10.10.2.0 A2B10G10R10
5.6.5.0.0 RGB565 4.4.4.4.0 ARGB4444
5.5.5.0.1 RGB555 5.5.5.1.0 ARGB1555
Bit fields for ten RGB bits[23]
Bit field Offset

(hex)

Bits A2R10G10B10 Bits A2B10G10R10
Red 36 00 00 F0 3F LE: 3FF00000 20...29 FF 03 00 00 LE: 000003FF  0... 9
Green 3A 00 FC 0F 00 LE: 000FFC00 10...19 00 FC 0F 00 LE: 000FFC00 10...19
Blue 3E FF 03 00 00 LE: 000003FF  0... 9 00 00 F0 3F LE: 3FF00000 20...29
Alpha 42 00 00 00 C0 LE: C0000000 30...31 00 00 00 C0 LE: C0000000 30...31

In version 2.1.4 FFmpeg supported (in its own terminology) the BMP pixel formats bgra, bgr24, rgb565le, rgb555le, rgb444le, rgb8, bgr8, rgb4_byte, bgr4_byte, gray, pal8, and monob; i.e., bgra was the only supported pixel format with transparency.[24]

Example 1 of a 2×2 pixel bitmap, with 24 bits/pixel encoding

Example 1

[edit]

Following is an example of a 2×2 pixel, 24-bit bitmap (Windows DIB header BITMAPINFOHEADER) with pixel format RGB24.

Offset

(hex)

Size

(bytes)

Hex value Value Description
BMP Header
00 2 42 4D "BM" ID field (42h, 4Dh)
02 4 46 00 00 00 70 bytes (54+16) Size of the BMP file (54 bytes header + 16 bytes data)
06 2 00 00 Unused Application specific
08 2 00 00 Unused Application specific
0A 4 36 00 00 00 54 bytes (14+40) Offset where the pixel array (bitmap data) can be found
DIB Header
0E 4 28 00 00 00 40 bytes Number of bytes in the DIB header (from this point)
12 4 02 00 00 00 2 pixels (left to right order) Width of the bitmap in pixels
16 4 02 00 00 00 2 pixels (bottom to top order) Height of the bitmap in pixels. Positive for bottom to top pixel order.
1A 2 01 00 1 plane Number of color planes being used
1C 2 18 00 24 bits Number of bits per pixel
1E 4 00 00 00 00 0 BI_RGB, no pixel array compression used
22 4 10 00 00 00 16 bytes Size of the raw bitmap data (including padding)
26 4 13 0B 00 00 2835 pixels/metre horizontal Print resolution of the image,
72 DPI × 39.3701 inches per metre yields 2834.6472
2A 4 13 0B 00 00 2835 pixels/metre vertical
2E 4 00 00 00 00 0 colors Number of colors in the palette
32 4 00 00 00 00 0 important colors 0 means all colors are important
Start of pixel array (bitmap data)
36 3 00 00 FF 0 0 255 Red, Pixel (x=0, y=1)
39 3 FF FF FF 255 255 255 White, Pixel (x=1, y=1)
3C 2 00 00 0 0 Padding for 4 byte alignment (could be a value other than zero)
3E 3 FF 00 00 255 0 0 Blue, Pixel (x=0, y=0)
41 3 00 FF 00 0 255 0 Green, Pixel (x=1, y=0)
44 2 00 00 0 0 Padding for 4 byte alignment (could be a value other than zero)
0,0: blue 0000FF FF0,1: green 00FF00 FF0,2: red FF00000 FF0,3: white FFFFFF FF1,0: blue 0000FF 7F, half transparent1,1: green 00FF00 7F, half transparent1,2: red FF0000 7F, half transparent1,3: white FFFFFF 7F, half transparent
Example 2 of a 4×2 pixel bitmap, with 32 bits/pixel encoding

Example 2

[edit]

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 ARGB32.

Offset

(hex)

Size

(bytes)

Hex value Value Description
BMP Header
00 2 42 4D "BM" ID field (42h, 4Dh)
02 4 9A 00 00 00 154 bytes (122+32) Size of the BMP file
06 2 00 00 Unused Application specific
08 2 00 00 Unused Application specific
0A 4 7A 00 00 00 122 bytes (14+108) Offset where the pixel array (bitmap data) can be found
DIB Header
0E 4 6C 00 00 00 108 bytes Number of bytes in the DIB header (from this point)
12 4 04 00 00 00 4 pixels (left to right order) Width of the bitmap in pixels
16 4 02 00 00 00 2 pixels (bottom to top order) Height of the bitmap in pixels
1A 2 01 00 1 plane Number of color planes being used
1C 2 20 00 32 bits Number of bits per pixel
1E 4 03 00 00 00 3 BI_BITFIELDS, no pixel array compression used
22 4 20 00 00 00 32 bytes Size of the raw bitmap data (including padding)
26 4 13 0B 00 00 2835 pixels/metre horizontal Print resolution of the image,
72 DPI × 39.3701 inches per metre yields 2834.6472
2A 4 13 0B 00 00 2835 pixels/metre vertical
2E 4 00 00 00 00 0 colors Number of colors in the palette
32 4 00 00 00 00 0 important colors 0 means all colors are important
36 4 00 00 FF 00 00FF0000 in big-endian Red channel bit mask (valid because BI_BITFIELDS is specified)
3A 4 00 FF 00 00 0000FF00 in big-endian Green channel bit mask (valid because BI_BITFIELDS is specified)
3E 4 FF 00 00 00 000000FF in big-endian Blue channel bit mask (valid because BI_BITFIELDS is specified)
42 4 00 00 00 FF FF000000 in big-endian Alpha channel bit mask
46 4 20 6E 69 57 little-endian "Win " LCS_WINDOWS_COLOR_SPACE
4A 36 00...00 CIEXYZTRIPLE Color Space endpoints Unused for LCS "Win " or "sRGB"
6E 4 00 00 00 00 0 Red Gamma Unused for LCS "Win " or "sRGB"
72 4 00 00 00 00 0 Green Gamma Unused for LCS "Win " or "sRGB"
76 4 00 00 00 00 0 Blue Gamma Unused for LCS "Win " or "sRGB"
Start of the Pixel Array (the bitmap Data)
7A 4 FF 00 00 7F 255 0 0 127 Blue (Alpha: 127), Pixel (x=0, y=1)
7E 4 00 FF 00 7F 0 255 0 127 Green (Alpha: 127), Pixel (x=1, y=1)
82 4 00 00 FF 7F 0 0 255 127 Red (Alpha: 127), Pixel (x=2, y=1)
86 4 FF FF FF 7F 255 255 255 127 White (Alpha: 127), Pixel (x=3, y=1)
8A 4 FF 00 00 FF 255 0 0 255 Blue (Alpha: 255), Pixel (x=0, y=0)
8E 4 00 FF 00 FF 0 255 0 255 Green (Alpha: 255), Pixel (x=1, y=0)
92 4 00 00 FF FF 0 0 255 255 Red (Alpha: 255), Pixel (x=2, y=0)
96 4 FF FF FF FF 255 255 255 255 White (Alpha: 255), Pixel (x=3, y=0)

Note that the bitmap data starts with the lower left hand corner of the image.

Usage of BMP format

[edit]

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 documented and has an open format, makes BMP a very common format that image processing programs from many operating systems can read and write. ICO and CUR files contain bitmaps starting with a BITMAPINFOHEADER.

Many older graphical user interfaces used bitmaps in their built-in graphics subsystems;[25] 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 .BMP.[26]

While most BMP files have a relatively large file size due to lack of any compression (or generally low-ratio run-length encoding on palletized images), many BMP files can be considerably compressed with lossless data compression algorithms such as ZIP because they contain redundant data. Some formats, such as RAR, even include routines specifically targeted at efficient compression of such data.

[edit]

The X Window System 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 save 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.

References

[edit]
  1. ^ "IANA Considerations". Windows Image Media Types. sec. 5. doi:10.17487/RFC7903. RFC 7903.
  2. ^ a b c James D. Murray; William vanRyper (April 1996). Encyclopedia of Graphics File Formats (Second ed.). O'Reilly. bmp. ISBN 1-56592-161-5. Retrieved 2025-08-06.
  3. ^ a b c d e f g h James D. Murray; William vanRyper (April 1996). Encyclopedia of Graphics File Formats (Second ed.). O'Reilly. os2bmp. ISBN 1-56592-161-5. Retrieved 2025-08-06.
  4. ^ a b "[MS-WMF]: Windows Metafile Format". MSDN. 2025-08-06. Retrieved 2025-08-06.
  5. ^ a b c d e f g h i j "DIBs and Their Uses". Microsoft Help and Support. Retrieved 2025-08-06.
  6. ^ a b c MSDN - BITMAPINFOHEADER (Windows CE 5.0): BI_ALPHABITFIELDS in biCompression member
  7. ^ a b c MSDN Bitmap Header Types
  8. ^ a b c MSDN BITMAPINFO Structure
  9. ^ Feng Yuan - Windows graphics programming: Win32 GDI and DirectDraw: Packed Device-Independent Bitmap (CreateDIBPatternBrush, CreateDIBPatternBrushPt, FindResource, LoadResource, LockResource)
  10. ^ Summers, Jason (2025-08-06). "pal8os2v2-16.bmp". Retrieved 2025-08-06.
  11. ^ Summers, Jason (2025-08-06). "BMP Suite". Retrieved 2025-08-06.
  12. ^ Cox, Chris (2025-08-06). "Invalid BMP Format with Alpha channel". Photoshop Windows forum. Adobe. Archived from the original on 2025-08-06. Retrieved 2025-08-06.
  13. ^ "Microsoft Windows Bitmap: Summary from the Encyclopedia of Graphics File Formats".
  14. ^ a b "JPEG and PNG Extensions for Specific Bitmap Functions and Structures".
  15. ^ MSDN – BITMAPV4HEADER: The member bV4AlphaMask
  16. ^ MSDN – RGBQUAD: rgbReserved member
  17. ^ see note under biClrUsed MSDN BITMAPINFOHEADER
  18. ^ "Image Stride - Win32 apps". learn.microsoft.com.
  19. ^ MSDN - BITMAPINFOHEADER: The member biBitCount
  20. ^ "Types of Bitmaps". MSDN. 2025-08-06. Retrieved 2025-08-06.
  21. ^ MSDN: Windows CE - BITMAPINFOHEADER Structure
  22. ^ a b Adobe Photoshop: BMP Format Archived 2025-08-06 at the Wayback Machine
  23. ^ a b "Uncompressed RGB Video Subtypes". dshow.h. MSDN. Retrieved 2025-08-06.
  24. ^ "Image Formats". FFmpeg General Documentation. 2014. Retrieved 2025-08-06.
  25. ^ Julian Smart; Stefan Csomor & Kevin Hock (2006). Cross-Platform GUI Programming with Wxwidgets. Prentice Hall. ISBN 0-13-147381-6.
  26. ^ "Bitmap Image File (BMP), Version 5". Digital Preservation. Library of Congress. 2025-08-06. Retrieved 2025-08-06.
[edit]
月经一直不干净吃什么药 演宋江的演员叫什么 主胰管不扩张是什么意思 什么人不能吃皮蛋 安徽什么阳
手串断了寓意什么 蛇生肖和什么生肖相配 梦见下雨是什么征兆 老是干咳嗽是什么原因 喝水多尿多是什么原因
艾滋病有什么症状图片 胃胀不舒服吃什么药 什么牌子的风扇好 高脂血症是什么病 翳什么意思
受戒是什么意思 溶豆是什么 什么是挂科 三文鱼是什么鱼 四肢百骸是什么意思
陶和瓷有什么区别hcv9jop6ns2r.cn 松鼠尾巴有什么作用hcv8jop3ns5r.cn 停车坐爱枫林晚的坐是什么意思hcv7jop6ns8r.cn 什么牌子的山地车好骑又不贵hcv9jop1ns6r.cn 小便绿色是什么原因zhongyiyatai.com
消化不良吃什么中药hcv9jop2ns7r.cn 血离子是检查什么的hcv8jop2ns7r.cn 太后是皇上的什么人hcv7jop6ns9r.cn 丝瓜不能和什么食物一起吃hcv8jop3ns3r.cn 什么耳什么聋hcv8jop4ns9r.cn
lgbtq是什么意思hcv9jop2ns7r.cn 摩羯座女生和什么星座男生最配hcv8jop7ns2r.cn 财大气粗是什么意思hcv9jop3ns9r.cn ih医学上是什么意思hcv9jop0ns6r.cn 爱出汗是什么原因女人mmeoe.com
生长激素分泌的高峰期是什么时候hcv9jop3ns0r.cn 一直想大便是什么原因hcv8jop9ns7r.cn 高锰酸钾用什么能洗掉hcv8jop8ns3r.cn 漂洋过海是什么生肖wzqsfys.com z是什么火车xinjiangjialails.com
百度