]> 4ch.mooo.com Git - 16.git/blob - 16/PCGPE10/BMP.TXT
modified: 16/DOS_GFX.EXE
[16.git] / 16 / PCGPE10 / BMP.TXT
1 Graphics File Formats\r
2 \r
3 This topic describes the graphics-file formats used by the Microsoft Windows\r
4 operating system. Graphics files include bitmap files, icon-resource files,\r
5 and cursor-resource files.\r
6 \r
7 Bitmap-File Formats\r
8 \r
9 Windows bitmap files are stored in a device-independent bitmap (DIB) format\r
10 that allows Windows to display the bitmap on any type of display device. The\r
11 term "device independent" means that the bitmap specifies pixel color in a\r
12 form independent of the method used by a display to represent color. The\r
13 default filename extension of a Windows DIB file is .BMP.\r
14 \r
15 Bitmap-File Structures\r
16 \r
17 Each bitmap file contains a bitmap-file header, a bitmap-information header,\r
18 a color table, and an array of bytes that defines the bitmap bits. The file\r
19 has the following form:\r
20 \r
21 BITMAPFILEHEADER bmfh;\r
22 BITMAPINFOHEADER bmih;\r
23 RGBQUAD          aColors[];\r
24 BYTE             aBitmapBits[];\r
25 \r
26 The bitmap-file header contains information about the type, size, and layout\r
27 of a device-independent bitmap file. The header is defined as a\r
28 BITMAPFILEHEADER structure.\r
29 \r
30 The bitmap-information header, defined as a BITMAPINFOHEADER structure,\r
31 specifies the dimensions, compression type, and color format for the bitmap.\r
32 \r
33 The color table, defined as an array of RGBQUAD structures, contains as many\r
34 elements as there are colors in the bitmap. The color table is not present\r
35 for bitmaps with 24 color bits because each pixel is represented by 24-bit\r
36 red-green-blue (RGB) values in the actual bitmap data area. The colors in the\r
37 table should appear in order of importance. This helps a display driver\r
38 render a bitmap on a device that cannot display as many colors as there are\r
39 in the bitmap. If the DIB is in Windows version 3.0 or later format, the\r
40 driver can use the biClrImportant member of the BITMAPINFOHEADER structure to\r
41 determine which colors are important.\r
42 \r
43 The BITMAPINFO structure can be used to represent a combined\r
44 bitmap-information header and color table.  The bitmap bits, immediately\r
45 following the color table, consist of an array of BYTE values representing\r
46 consecutive rows, or "scan lines," of the bitmap. Each scan line consists of\r
47 consecutive bytes representing the pixels in the scan line, in left-to-right\r
48 order. The number of bytes representing a scan line depends on the color\r
49 format and the width, in pixels, of the bitmap. If necessary, a scan line\r
50 must be zero-padded to end on a 32-bit boundary. However, segment boundaries\r
51 can appear anywhere in the bitmap. The scan lines in the bitmap are stored\r
52 from bottom up. This means that the first byte in the array represents the\r
53 pixels in the lower-left corner of the bitmap and the last byte represents\r
54 the pixels in the upper-right corner.\r
55 \r
56 The biBitCount member of the BITMAPINFOHEADER structure determines the number\r
57 of bits that define each pixel and the maximum number of colors in the\r
58 bitmap. These members can have any of the following values:\r
59 \r
60 Value   Meaning\r
61 \r
62 1       Bitmap is monochrome and the color table contains two entries. Each\r
63 bit in the bitmap array represents a pixel. If the bit is clear, the pixel is\r
64 displayed with the color of the first entry in the color table. If the bit is\r
65 set, the pixel has the color of the second entry in the table.\r
66 \r
67 4       Bitmap has a maximum of 16 colors. Each pixel in the bitmap is\r
68 represented by a 4-bit index into the color table. For example, if the first\r
69 byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel\r
70 contains the color in the second table entry, and the second pixel contains\r
71 the color in the sixteenth table entry.\r
72 \r
73 8       Bitmap has a maximum of 256 colors. Each pixel in the bitmap is\r
74 represented by a 1-byte index into the color table. For example, if the first\r
75 byte in the bitmap is 0x1F, the first pixel has the color of the\r
76 thirty-second table entry.\r
77 \r
78 24      Bitmap has a maximum of 2^24 colors. The bmiColors (or bmciColors)\r
79 member is NULL, and each 3-byte sequence in the bitmap array represents the\r
80 relative intensities of red, green, and blue, respectively, for a pixel.\r
81 \r
82 The biClrUsed member of the BITMAPINFOHEADER structure specifies the number\r
83 of color indexes in the color table actually used by the bitmap. If the\r
84 biClrUsed member is set to zero, the bitmap uses the maximum number of colors\r
85 corresponding to the value of the biBitCount member.  An alternative form of\r
86 bitmap file uses the BITMAPCOREINFO, BITMAPCOREHEADER, and RGBTRIPLE\r
87 structures.\r
88 \r
89 Bitmap Compression\r
90 \r
91 Windows versions 3.0 and later support run-length encoded (RLE) formats for\r
92 compressing bitmaps that use 4 bits per pixel and 8 bits per pixel.\r
93 Compression reduces the disk and memory storage required for a bitmap.\r
94 \r
95 Compression of 8-Bits-per-Pixel Bitmaps\r
96 \r
97 When the biCompression member of the BITMAPINFOHEADER structure is set to\r
98 BI_RLE8, the DIB is compressed using a run-length encoded format for a\r
99 256-color bitmap. This format uses two modes: encoded mode and absolute mode.\r
100 Both modes can occur anywhere throughout a single bitmap.\r
101 \r
102 Encoded Mode\r
103 \r
104 A unit of information in encoded mode consists of two bytes. The first byte\r
105 specifies the number of consecutive pixels to be drawn using the color index\r
106 contained in the second byte.  The first byte of the pair can be set to zero\r
107 to indicate an escape that denotes the end of a line, the end of the bitmap,\r
108 or a delta. The interpretation of the escape depends on the value of the\r
109 second byte of the pair, which must be in the range 0x00 through 0x02.\r
110 Following are the meanings of the escape values that can be used in the\r
111 second byte:\r
112 \r
113 Second byte     Meaning\r
114 \r
115 0       End of line. \r
116 1       End of bitmap. \r
117 2       Delta. The two bytes following the escape contain unsigned values\r
118 indicating the horizontal and vertical offsets of the next pixel from the\r
119 current position.\r
120 \r
121 Absolute Mode\r
122 \r
123 Absolute mode is signaled by the first byte in the pair being set to zero and\r
124 the second byte to a value between 0x03 and 0xFF. The second byte represents\r
125 the number of bytes that follow, each of which contains the color index of a\r
126 single pixel. Each run must be aligned on a word boundary.  Following is an\r
127 example of an 8-bit RLE bitmap (the two-digit hexadecimal values in the\r
128 second column represent a color index for a single pixel):\r
129 \r
130 Compressed data         Expanded data\r
131 \r
132 03 04                   04 04 04 \r
133 05 06                   06 06 06 06 06 \r
134 00 03 45 56 67 00       45 56 67 \r
135 02 78                   78 78 \r
136 00 02 05 01             Move 5 right and 1 down \r
137 02 78                   78 78 \r
138 00 00                   End of line \r
139 09 1E                   1E 1E 1E 1E 1E 1E 1E 1E 1E \r
140 00 01                   End of RLE bitmap \r
141 \r
142 Compression of 4-Bits-per-Pixel Bitmaps\r
143 \r
144 When the biCompression member of the BITMAPINFOHEADER structure is set to\r
145 BI_RLE4, the DIB is compressed using a run-length encoded format for a\r
146 16-color bitmap. This format uses two modes: encoded mode and absolute mode.\r
147 \r
148 Encoded Mode\r
149 \r
150 A unit of information in encoded mode consists of two bytes. The first byte\r
151 of the pair contains the number of pixels to be drawn using the color indexes\r
152 in the second byte.\r
153 \r
154 The second byte contains two color indexes, one in its high-order nibble\r
155 (that is, its low-order 4 bits) and one in its low-order nibble.\r
156 \r
157 The first pixel is drawn using the color specified by the high-order nibble,\r
158 the second is drawn using the color in the low-order nibble, the third is\r
159 drawn with the color in the high-order nibble, and so on, until all the\r
160 pixels specified by the first byte have been drawn.\r
161 \r
162 The first byte of the pair can be set to zero to indicate an escape that\r
163 denotes the end of a line, the end of the bitmap, or a delta. The\r
164 interpretation of the escape depends on the value of the second byte of the\r
165 pair. In encoded mode, the second byte has a value in the range 0x00 through\r
166 0x02. The meaning of these values is the same as for a DIB with 8 bits per\r
167 pixel.\r
168 \r
169 Absolute Mode\r
170 \r
171 In absolute mode, the first byte contains zero, the second byte contains the\r
172 number of color indexes that follow, and subsequent bytes contain color\r
173 indexes in their high- and low-order nibbles, one color index for each pixel.\r
174 Each run must be aligned on a word boundary.\r
175 \r
176 Following is an example of a 4-bit RLE bitmap (the one-digit hexadecimal\r
177 values in the second column represent a color index for a single pixel):\r
178 \r
179 Compressed data         Expanded data\r
180 \r
181 03 04                   0 4 0\r
182 05 06                   0 6 0 6 0 \r
183 00 06 45 56 67 00       4 5 5 6 6 7 \r
184 04 78                   7 8 7 8 \r
185 00 02 05 01             Move 5 right and 1 down \r
186 04 78                   7 8 7 8 \r
187 00 00                   End of line \r
188 09 1E                   1 E 1 E 1 E 1 E 1 \r
189 00 01                   End of RLE bitmap \r
190 \r
191 Bitmap Example\r
192 \r
193 The following example is a text dump of a 16-color bitmap (4 bits per pixel):\r
194 \r
195 Win3DIBFile\r
196               BitmapFileHeader\r
197                   Type       19778\r
198                   Size       3118\r
199                   Reserved1  0\r
200                   Reserved2  0\r
201                   OffsetBits 118\r
202               BitmapInfoHeader\r
203                   Size            40\r
204                   Width           80\r
205                   Height          75\r
206                   Planes          1\r
207                   BitCount        4\r
208                   Compression     0\r
209                   SizeImage       3000\r
210 \r
211                   XPelsPerMeter   0\r
212                   YPelsPerMeter   0\r
213                   ColorsUsed      16\r
214                   ColorsImportant 16\r
215               Win3ColorTable\r
216                   Blue  Green  Red  Unused\r
217 [00000000]        84    252    84   0\r
218 [00000001]        252   252    84   0\r
219 [00000002]        84    84     252  0\r
220 [00000003]        252   84     252  0\r
221 [00000004]        84    252    252  0\r
222 [00000005]        252   252    252  0\r
223 [00000006]        0     0      0    0\r
224 [00000007]        168   0      0    0\r
225 [00000008]        0     168    0    0\r
226 [00000009]        168   168    0    0\r
227 [0000000A]        0     0      168  0\r
228 [0000000B]        168   0      168  0\r
229 [0000000C]        0     168    168  0\r
230 [0000000D]        168   168    168  0\r
231 [0000000E]        84    84     84   0\r
232 [0000000F]        252   84     84   0\r
233               Image\r
234     .\r
235     .                                           Bitmap data\r
236     .\r
237 \r
238 Icon-Resource File Format\r
239 \r
240 An icon-resource file contains image data for icons used by Windows\r
241 applications. The file consists of an icon directory identifying the number\r
242 and types of icon images in the file, plus one or more icon images. The\r
243 default filename extension for an icon-resource file is .ICO.\r
244 \r
245 Icon Directory\r
246 \r
247 Each icon-resource file starts with an icon directory. The icon directory,\r
248 defined as an ICONDIR structure, specifies the number of icons in the\r
249 resource and the dimensions and color format of each icon image. The ICONDIR\r
250 structure has the following form:\r
251 \r
252 \r
253 \r
254 typedef struct ICONDIR {\r
255     WORD          idReserved;\r
256     WORD          idType;\r
257     WORD          idCount;\r
258     ICONDIRENTRY  idEntries[1];\r
259 } ICONHEADER;\r
260 \r
261 Following are the members in the ICONDIR structure:\r
262 \r
263 idReserved      Reserved; must be zero. \r
264 idType          Specifies the resource type. This member is set to 1. \r
265 idCount         Specifies the number of entries in the directory. \r
266 idEntries       Specifies an array of ICONDIRENTRY structures containing\r
267 information about individual icons. The idCount member specifies the number\r
268 of structures in the array.\r
269 \r
270 The ICONDIRENTRY structure specifies the dimensions and color format for an\r
271 icon. The structure has the following form:\r
272 \r
273 \r
274 \r
275 struct IconDirectoryEntry {\r
276     BYTE  bWidth;\r
277     BYTE  bHeight;\r
278     BYTE  bColorCount;\r
279     BYTE  bReserved;\r
280     WORD  wPlanes;\r
281     WORD  wBitCount;\r
282     DWORD dwBytesInRes;\r
283     DWORD dwImageOffset;\r
284 };\r
285 \r
286 Following are the members in the ICONDIRENTRY structure: \r
287 \r
288 bWidth          Specifies the width of the icon, in pixels. Acceptable values\r
289 are 16, 32, and 64.\r
290 \r
291 bHeight         Specifies the height of the icon, in pixels. Acceptable\r
292 values are 16, 32, and 64.\r
293 \r
294 bColorCount     Specifies the number of colors in the icon. Acceptable values\r
295 are 2, 8, and 16.\r
296 \r
297 bReserved       Reserved; must be zero. \r
298 wPlanes         Specifies the number of color planes in the icon bitmap. \r
299 wBitCount       Specifies the number of bits in the icon bitmap. \r
300 dwBytesInRes    Specifies the size of the resource, in bytes. \r
301 dwImageOffset   Specifies the offset, in bytes, from the beginning of the\r
302 file to the icon image.\r
303 \r
304 Icon Image\r
305 \r
306 Each icon-resource file contains one icon image for each image identified in\r
307 the icon directory. An icon image consists of an icon-image header, a color\r
308 table, an XOR mask, and an AND mask. The icon image has the following form:\r
309 \r
310 \r
311 \r
312 BITMAPINFOHEADER    icHeader;\r
313 RGBQUAD             icColors[];\r
314 BYTE                icXOR[];\r
315 BYTE                icAND[];\r
316 \r
317 The icon-image header, defined as a BITMAPINFOHEADER structure, specifies the\r
318 dimensions and color format of the icon bitmap. Only the biSize through\r
319 biBitCount members and the biSizeImage member are used. All other members\r
320 (such as biCompression and biClrImportant) must be set to zero.\r
321 \r
322 The color table, defined as an array of RGBQUAD structures, specifies the\r
323 colors used in the XOR mask. As with the color table in a bitmap file, the\r
324 biBitCount member in the icon-image header determines the number of elements\r
325 in the array. For more information about the color table, see Section 1.1,\r
326 "Bitmap-File Formats."\r
327 \r
328 The XOR mask, immediately following the color table, is an array of BYTE\r
329 values representing consecutive rows of a bitmap. The bitmap defines the\r
330 basic shape and color of the icon image. As with the bitmap bits in a bitmap\r
331 file, the bitmap data in an icon-resource file is organized in scan lines,\r
332 with each byte representing one or more pixels, as defined by the color\r
333 format. For more information about these bitmap bits, see Section 1.1,\r
334 "Bitmap-File Formats."\r
335 \r
336 The AND mask, immediately following the XOR mask, is an array of BYTE values,\r
337 representing a monochrome bitmap with the same width and height as the XOR\r
338 mask. The array is organized in scan lines, with each byte representing 8\r
339 pixels.\r
340 \r
341 When Windows draws an icon, it uses the AND and XOR masks to combine the icon\r
342 image with the pixels already on the display surface. Windows first applies\r
343 the AND mask by using a bitwise AND operation; this preserves or removes\r
344 existing pixel color.  Windows then applies the XOR mask by using a bitwise\r
345 XOR operation. This sets the final color for each pixel.\r
346 \r
347 The following illustration shows the XOR and AND masks that create a\r
348 monochrome icon (measuring 8 pixels by 8 pixels) in the form of an uppercase\r
349 K:\r
350 \r
351 Windows Icon Selection\r
352 \r
353 Windows detects the resolution of the current display and matches it against\r
354 the width and height specified for each version of the icon image. If Windows\r
355 determines that there is an exact match between an icon image and the current\r
356 device, it uses the matching image. Otherwise, it selects the closest match\r
357 and stretches the image to the proper size.\r
358 \r
359 If an icon-resource file contains more than one image for a particular\r
360 resolution, Windows uses the icon image that most closely matches the color\r
361 capabilities of the current display. If no image matches the device\r
362 capabilities exactly, Windows selects the image that has the greatest number\r
363 of colors without exceeding the number of display colors. If all images\r
364 exceed the color capabilities of the current display, Windows uses the icon\r
365 image with the least number of colors.\r
366 \r
367 \r
368 \r
369 Cursor-Resource File Format\r
370 \r
371 A cursor-resource file contains image data for cursors used by Windows\r
372 applications. The file consists of a cursor directory identifying the number\r
373 and types of cursor images in the file, plus one or more cursor images. The\r
374 default filename extension for a cursor-resource file is .CUR.\r
375 \r
376 Cursor Directory\r
377 \r
378 Each cursor-resource file starts with a cursor directory. The cursor\r
379 directory, defined as a CURSORDIR structure, specifies the number of cursors\r
380 in the file and the dimensions and color format of each cursor image. The\r
381 CURSORDIR structure has the following form:\r
382 \r
383 \r
384 typedef struct _CURSORDIR {\r
385     WORD           cdReserved;\r
386     WORD           cdType;\r
387     WORD           cdCount;\r
388     CURSORDIRENTRY cdEntries[];\r
389 } CURSORDIR;\r
390 \r
391 Following are the members in the CURSORDIR structure: \r
392 \r
393 cdReserved      Reserved; must be zero. \r
394 cdType          Specifies the resource type. This member must be set to 2. \r
395 cdCount         Specifies the number of cursors in the file. \r
396 cdEntries       Specifies an array of CURSORDIRENTRY structures containing\r
397 information about individual cursors. The cdCount member specifies the number\r
398 of structures in the array.\r
399 \r
400 A CURSORDIRENTRY structure specifies the dimensions and color format of a\r
401 cursor image. The structure has the following form:\r
402 \r
403 \r
404 \r
405 typedef struct _CURSORDIRENTRY {\r
406     BYTE  bWidth;\r
407     BYTE  bHeight;\r
408     BYTE  bColorCount;\r
409     BYTE  bReserved;\r
410     WORD  wXHotspot;\r
411     WORD  wYHotspot;\r
412     DWORD lBytesInRes;\r
413     DWORD dwImageOffset;\r
414 } CURSORDIRENTRY;\r
415 \r
416 Following are the members in the CURSORDIRENTRY structure: \r
417 \r
418 bWidth          Specifies the width of the cursor, in pixels. \r
419 bHeight         Specifies the height of the cursor, in pixels. \r
420 bColorCount     Reserved; must be zero. \r
421 bReserved       Reserved; must be zero.\r
422 wXHotspot       Specifies the x-coordinate, in pixels, of the hot spot. \r
423 wYHotspot       Specifies the y-coordinate, in pixels, of the hot spot. \r
424 lBytesInRes     Specifies the size of the resource, in bytes. \r
425 dwImageOffset   Specifies the offset, in bytes, from the start of the file to\r
426 the cursor image.\r
427 \r
428 Cursor Image\r
429 \r
430 Each cursor-resource file contains one cursor image for each image identified\r
431 in the cursor directory. A cursor image consists of a cursor-image header, a\r
432 color table, an XOR mask, and an AND mask. The cursor image has the following\r
433 form:\r
434 \r
435 \r
436 \r
437 BITMAPINFOHEADER    crHeader;\r
438 RGBQUAD             crColors[];\r
439 BYTE                crXOR[];\r
440 BYTE                crAND[];\r
441 \r
442 The cursor hot spot is a single pixel in the cursor bitmap that Windows uses\r
443 to track the cursor. The crXHotspot and crYHotspot members specify the x- and\r
444 y-coordinates of the cursor hot spot. These coordinates are 16-bit integers.\r
445 \r
446 The cursor-image header, defined as a BITMAPINFOHEADER structure, specifies\r
447 the dimensions and color format of the cursor bitmap. Only the biSize through\r
448 biBitCount members and the biSizeImage member are used. The biHeight member\r
449 specifies the combined height of the XOR and AND masks for the cursor. This\r
450 value is twice the height of the XOR mask. The biPlanes and biBitCount\r
451 members must be 1. All other members (such as biCompression and\r
452 biClrImportant) must be set to zero.\r
453 \r
454 The color table, defined as an array of RGBQUAD structures, specifies the\r
455 colors used in the XOR mask. For a cursor image, the table contains exactly\r
456 two structures, since the biBitCount member in the cursor-image header is\r
457 always 1.\r
458 \r
459 The XOR mask, immediately following the color table, is an array of BYTE\r
460 values representing consecutive rows of a bitmap. The bitmap defines the\r
461 basic shape and color of the cursor image. As with the bitmap bits in a\r
462 bitmap file, the bitmap data in a cursor-resource file is organized in scan\r
463 lines, with each byte representing one or more pixels, as defined by the\r
464 color format. For more information about these bitmap bits, see Section 1.1,\r
465 "Bitmap-File Formats."\r
466 \r
467 The AND mask, immediately following the XOR mask, is an array of BYTE values\r
468 representing a monochrome bitmap with the same width and height as the XOR\r
469 mask. The array is organized in scan lines, with each byte representing 8\r
470 pixels.\r
471 \r
472 When Windows draws a cursor, it uses the AND and XOR masks to combine the\r
473 cursor image with the pixels already on the display surface. Windows first\r
474 applies the AND mask by using a bitwise AND operation; this preserves or\r
475 removes existing pixel color.  Window then applies the XOR mask by using a\r
476 bitwise XOR operation. This sets the final color for each pixel.\r
477 \r
478 The following illustration shows the XOR and the AND masks that create a\r
479 cursor (measuring 8 pixels by 8 pixels) in the form of an arrow:\r
480 \r
481 Following are the bit-mask values necessary to produce black, white,\r
482 inverted, and transparent results:\r
483 \r
484 Pixel result    AND maskXOR mask\r
485 \r
486 Black           0               0 \r
487 White           0               1 \r
488 Transparent     1               0 \r
489 Inverted1               1 \r
490 \r
491 Windows Cursor Selection\r
492 \r
493 If a cursor-resource file contains more than one cursor image, Windows\r
494 determines the best match for a particular display by examining the width and\r
495 height of the cursor images.\r
496 \r
497 \r
498 ==============================================================================\r
499 \r
500 \r
501 BITMAPFILEHEADER (3.0)\r
502 \r
503 \r
504 \r
505 typedef struct tagBITMAPFILEHEADER {    /* bmfh */\r
506     UINT    bfType;\r
507     DWORD   bfSize;\r
508     UINT    bfReserved1;\r
509     UINT    bfReserved2;\r
510     DWORD   bfOffBits;\r
511 } BITMAPFILEHEADER;\r
512 \r
513 The BITMAPFILEHEADER structure contains information about the type, size, and\r
514 layout of a device-independent bitmap (DIB) file.\r
515 \r
516 Member          Description\r
517 \r
518 bfType          Specifies the type of file. This member must be BM. \r
519 bfSize          Specifies the size of the file, in bytes. \r
520 bfReserved1     Reserved; must be set to zero. \r
521 bfReserved2     Reserved; must be set to zero.\r
522 bfOffBits       Specifies the byte offset from the BITMAPFILEHEADER structure\r
523 to the actual bitmap data in the file.\r
524 \r
525 Comments\r
526 \r
527 A BITMAPINFO or BITMAPCOREINFO structure immediately follows the\r
528 BITMAPFILEHEADER structure in the DIB file.\r
529 \r
530 See Also\r
531 \r
532 BITMAPCOREINFO, BITMAPINFO \r
533 \r
534 \r
535 ==============================================================================\r
536 BITMAPINFO (3.0)\r
537 \r
538 \r
539 \r
540 typedef struct tagBITMAPINFO {  /* bmi */\r
541     BITMAPINFOHEADER    bmiHeader;\r
542     RGBQUAD             bmiColors[1];\r
543 } BITMAPINFO;\r
544 \r
545 The BITMAPINFO structure fully defines the dimensions and color information\r
546 for a Windows 3.0 or later device-independent bitmap (DIB).\r
547 \r
548 Member          Description\r
549 \r
550 bmiHeader       Specifies a BITMAPINFOHEADER structure that contains\r
551 information about the dimensions and color format of a DIB.\r
552 \r
553 bmiColors       Specifies an array of RGBQUAD structures that define the\r
554 colors in the bitmap.\r
555 \r
556 Comments\r
557 \r
558 A Windows 3.0 or later DIB consists of two distinct parts: a BITMAPINFO\r
559 structure, which describes the dimensions and colors of the bitmap, and an\r
560 array of bytes defining the pixels of the bitmap. The bits in the array are\r
561 packed together, but each scan line must be zero-padded to end on a LONG\r
562 boundary. Segment boundaries, however, can appear anywhere in the bitmap. The\r
563 origin of the bitmap is the lower-left corner.\r
564 \r
565 The biBitCount member of the BITMAPINFOHEADER structure determines the number\r
566 of bits which define each pixel and the maximum number of colors in the\r
567 bitmap. This member may be set to any of the following values:\r
568 \r
569 Value   Meaning\r
570 \r
571 1       The bitmap is monochrome, and the bmciColors member must contain two\r
572 entries. Each bit in the bitmap array represents a pixel. If the bit is\r
573 clear, the pixel is displayed with the color of the first entry in the\r
574 bmciColors table. If the bit is set, the pixel has the color of the second\r
575 entry in the table.\r
576 \r
577 4       The bitmap has a maximum of 16 colors, and the bmciColors member\r
578 contains 16 entries. Each pixel in the bitmap is represented by a four-bit\r
579 index into the color table.\r
580 \r
581 For example, if the first byte in the bitmap is 0x1F, the byte represents two\r
582 pixels. The first pixel contains the color in the second table entry, and the\r
583 second pixel contains the color in the sixteenth table entry.\r
584 \r
585 8       The bitmap has a maximum of 256 colors, and the bmciColors member\r
586 contains 256 entries. In this case, each byte in the array represents a\r
587 single pixel.\r
588 \r
589 24      The bitmap has a maximum of 2^24 colors. The bmciColors member is\r
590 NULL, and each 3-byte sequence in the bitmap array represents the relative\r
591 intensities of red, green, and blue, respectively, of a pixel.\r
592 \r
593 The biClrUsed member of the BITMAPINFOHEADER structure specifies the number\r
594 of color indexes in the color table actually used by the bitmap. If the\r
595 biClrUsed member is set to zero, the bitmap uses the maximum number of colors\r
596 corresponding to the value of the biBitCount member.\r
597 \r
598 The colors in the bmiColors table should appear in order of importance.\r
599 Alternatively, for functions that use DIBs, the bmiColors member can be an\r
600 array of 16-bit unsigned integers that specify an index into the currently\r
601 realized logical palette instead of explicit RGB values. In this case, an\r
602 application using the bitmap must call DIB functions with the wUsage\r
603 parameter set to DIB_PAL_COLORS.\r
604 \r
605 Note:   The bmiColors member should not contain palette indexes if the bitmap\r
606 is to be stored in a file or transferred to another application. Unless the\r
607 application uses the bitmap exclusively and under its complete control, the\r
608 bitmap color table should contain explicit RGB values.\r
609 \r
610 See Also\r
611 \r
612 BITMAPINFOHEADER, RGBQUAD \r
613 \r
614 ==============================================================================\r
615 BITMAPINFOHEADER (3.0)\r
616 \r
617 \r
618 \r
619 typedef struct tagBITMAPINFOHEADER {    /* bmih */\r
620     DWORD   biSize;\r
621     LONG    biWidth;\r
622     LONG    biHeight;\r
623     WORD    biPlanes;\r
624     WORD    biBitCount;\r
625     DWORD   biCompression;\r
626     DWORD   biSizeImage;\r
627     LONG    biXPelsPerMeter;\r
628     LONG    biYPelsPerMeter;\r
629     DWORD   biClrUsed;\r
630     DWORD   biClrImportant;\r
631 } BITMAPINFOHEADER;\r
632 \r
633 The BITMAPINFOHEADER structure contains information about the dimensions and\r
634 color format of a Windows 3.0 or later device-independent bitmap (DIB).\r
635 \r
636 Member          Description\r
637 \r
638 biSize          Specifies the number of bytes required by the\r
639 BITMAPINFOHEADER structure.\r
640 \r
641 biWidth         Specifies the width of the bitmap, in pixels. \r
642 biHeightSpecifies the height of the bitmap, in pixels. \r
643 \r
644 biPlanesSpecifies the number of planes for the target device. This\r
645 member must be set to 1.\r
646 \r
647 biBitCount      Specifies the number of bits per pixel. This value must be 1,\r
648 4, 8, or 24.\r
649 \r
650 biCompression   Specifies the type of compression for a compressed bitmap. It\r
651 can be one of the following values:\r
652 \r
653 Value           Meaning\r
654 \r
655 BI_RGB          Specifies that the bitmap is not compressed. \r
656 \r
657 BI_RLE8         Specifies a run-length encoded format for bitmaps with 8 bits\r
658 per pixel. The compression format is a 2-byte format consisting of a count\r
659 byte followed by a byte containing a color index.  For more information, see\r
660 the following Comments section.\r
661 \r
662 BI_RLE4         Specifies a run-length encoded format for bitmaps with 4 bits\r
663 per pixel. The compression format is a 2-byte format consisting of a count\r
664 byte followed by two word-length color indexes.  For more information, see\r
665 the following Comments section.\r
666 \r
667 biSizeImage     Specifies the size, in bytes, of the image. It is valid to\r
668 set this member to zero if the bitmap is in the BI_RGB format.\r
669 \r
670 biXPelsPerMeter Specifies the horizontal resolution, in pixels per meter, of\r
671 the target device for the bitmap. An application can use this value to select\r
672 a bitmap from a resource group that best matches the characteristics of the\r
673 current device.\r
674 \r
675 biYPelsPerMeter Specifies the vertical resolution, in pixels per meter, of\r
676 the target device for the bitmap.\r
677 \r
678 biClrUsed       Specifies the number of color indexes in the color table\r
679 actually used by the bitmap. If this value is zero, the bitmap uses the\r
680 maximum number of colors corresponding to the value of the biBitCount member.\r
681 For more information on the maximum sizes of the color table, see the\r
682 description of the BITMAPINFO structure earlier in this topic.\r
683 \r
684 If the biClrUsed member is nonzero, it specifies the actual number of colors\r
685 that the graphics engine or device driver will access if the biBitCount\r
686 member is less than 24. If biBitCount is set to 24, biClrUsed specifies the\r
687 size of the reference color table used to optimize performance of Windows\r
688 color palettes.  If the bitmap is a packed bitmap (that is, a bitmap in which\r
689 the bitmap array immediately follows the BITMAPINFO header and which is\r
690 referenced by a single pointer), the biClrUsed member must be set to zero or\r
691 to the actual size of the color table.\r
692 \r
693 biClrImportant  Specifies the number of color indexes that are considered\r
694 important for displaying the bitmap. If this value is zero, all colors are\r
695 important.\r
696 \r
697 Comments\r
698 \r
699 The BITMAPINFO structure combines the BITMAPINFOHEADER structure and a color\r
700 table to provide a complete definition of the dimensions and colors of a\r
701 Windows 3.0 or later DIB. For more information about specifying a Windows 3.0\r
702 DIB, see the description of the BITMAPINFO structure.\r
703 \r
704 An application should use the information stored in the biSize member to\r
705 locate the color table in a BITMAPINFO structure as follows:\r
706 \r
707 pColor = ((LPSTR) pBitmapInfo + (WORD) (pBitmapInfo->bmiHeader.biSize))\r
708 \r
709 Windows supports formats for compressing bitmaps that define their colors\r
710 with 8 bits per pixel and with 4 bits per pixel. Compression reduces the disk\r
711 and memory storage required for the bitmap. The following paragraphs describe\r
712 these formats.\r
713 \r
714 BI_RLE8\r
715 \r
716 When the biCompression member is set to BI_RLE8, the bitmap is compressed\r
717 using a run-length encoding format for an 8-bit bitmap. This format may be\r
718 compressed in either of two modes: encoded and absolute. Both modes can occur\r
719 anywhere throughout a single bitmap.\r
720 \r
721 Encoded mode consists of two bytes: the first byte specifies the number of\r
722 consecutive pixels to be drawn using the color index contained in the second\r
723 byte. In addition, the first byte of the pair can be set to zero to indicate\r
724 an escape that denotes an end of line, end of bitmap, or a delta. The\r
725 interpretation of the escape depends on the value of the second byte of the\r
726 pair. The following list shows the meaning of the second byte:\r
727 \r
728 Value   Meaning\r
729 \r
730 0       End of line. \r
731 1       End of bitmap. \r
732 2       Delta. The two bytes following the escape contain unsigned values\r
733 indicating the horizontal and vertical offset of the next pixel from the\r
734 current position.\r
735 \r
736 Absolute mode is signaled by the first byte set to zero and the second byte\r
737 set to a value between 0x03 and 0xFF. In absolute mode, the second byte\r
738 represents the number of bytes that follow, each of which contains the color\r
739 index of a single pixel. When the second byte is set to 2 or less, the escape\r
740 has the same meaning as in encoded mode. In absolute mode, each run must be\r
741 aligned on a word boundary.  The following example shows the hexadecimal\r
742 values of an 8-bit compressed bitmap:\r
743 \r
744 \r
745 \r
746 03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01\r
747 02 78 00 00 09 1E 00 01\r
748 \r
749 This bitmap would expand as follows (two-digit values represent a color index\r
750 for a single pixel):\r
751 \r
752 \r
753 \r
754 04 04 04\r
755 06 06 06 06 06\r
756 45 56 67\r
757 78 78\r
758 move current position 5 right and 1 down\r
759 78 78\r
760 end of line\r
761 1E 1E 1E 1E 1E 1E 1E 1E 1E\r
762 end of RLE bitmap\r
763 \r
764 BI_RLE4\r
765 \r
766 When the biCompression member is set to BI_RLE4, the bitmap is compressed\r
767 using a run-length encoding (RLE) format for a 4-bit bitmap, which also uses\r
768 encoded and absolute modes. In encoded mode, the first byte of the pair\r
769 contains the number of pixels to be drawn using the color indexes in the\r
770 second byte. The second byte contains two color indexes, one in its\r
771 high-order nibble (that is, its low-order four bits) and one in its low-order\r
772 nibble. The first of the pixels is drawn using the color specified by the\r
773 high-order nibble, the second is drawn using the color in the low-order\r
774 nibble, the third is drawn with the color in the high-order nibble, and so\r
775 on, until all the pixels specified by the first byte have been drawn.  In\r
776 absolute mode, the first byte contains zero, the second byte contains the\r
777 number of color indexes that follow, and subsequent bytes contain color\r
778 indexes in their high- and low-order nibbles, one color index for each pixel.\r
779 In absolute mode, each run must be aligned on a word boundary. The\r
780 end-of-line, end-of-bitmap, and delta escapes also apply to BI_RLE4.\r
781 \r
782 The following example shows the hexadecimal values of a 4-bit compressed\r
783 bitmap:\r
784 \r
785 \r
786 \r
787 03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01\r
788 04 78 00 00 09 1E 00 01\r
789 \r
790 This bitmap would expand as follows (single-digit values represent a color\r
791 index for a single pixel):\r
792 \r
793 \r
794 \r
795 0 4 0\r
796 0 6 0 6 0\r
797 4 5 5 6 6 7\r
798 7 8 7 8\r
799 move current position 5 right and 1 down\r
800 7 8 7 8\r
801 end of line\r
802 1 E 1 E 1 E 1 E 1\r
803 end of RLE bitmap\r
804 \r
805 See Also\r
806 \r
807 BITMAPINFO \r
808 \r
809 ==============================================================================\r
810 RGBQUAD (3.0)\r
811 \r
812 \r
813 \r
814 typedef struct tagRGBQUAD {     /* rgbq */\r
815     BYTE    rgbBlue;\r
816     BYTE    rgbGreen;\r
817     BYTE    rgbRed;\r
818     BYTE    rgbReserved;\r
819 } RGBQUAD;\r
820 \r
821 The RGBQUAD structure describes a color consisting of relative intensities of\r
822 red, green, and blue. The bmiColors member of the BITMAPINFO structure\r
823 consists of an array of RGBQUAD structures.\r
824 \r
825 Member          Description\r
826 \r
827 rgbBlue         Specifies the intensity of blue in the color. \r
828 rgbGreenSpecifies the intensity of green in the color. \r
829 rgbRed          Specifies the intensity of red in the color. \r
830 rgbReserved     Not used; must be set to zero. \r
831 \r
832 See Also\r
833 \r
834 BITMAPINFO \r
835 \r
836 ==============================================================================\r
837 RGB (2.x)\r
838 \r
839 COLORREF RGB(cRed, cGreen, cBlue)\r
840 \r
841 BYTE cRed;      /* red component of color       */\r
842 BYTE cGreen;    /* green component of color     */\r
843 BYTE cBlue;     /* blue component of color      */\r
844 \r
845 \r
846 The RGB macro selects an RGB color based on the parameters supplied and the\r
847 color capabilities of the output device.\r
848 \r
849 Parameter       Description\r
850 \r
851 cRed    Specifies the intensity of the red color field. \r
852 cGreen  Specifies the intensity of the green color field. \r
853 cBlue   Specifies the intensity of the blue color field. \r
854 \r
855 Returns\r
856 \r
857 The return value specifies the resultant RGB color. \r
858 \r
859 Comments\r
860 \r
861 The intensity for each argument can range from 0 through 255. If all three\r
862 intensities are specified as zero, the result is black. If all three\r
863 intensities are specified as 255, the result is white.\r
864 \r
865 Comments\r
866 \r
867 The RGB macro is defined in WINDOWS.H as follows: \r
868 \r
869 \r
870 \r
871 #define RGB(r,g,b)   ((COLORREF)(((BYTE)(r)|((WORD)(g)<<8))| \\r
872     (((DWORD)(BYTE)(b))<<16)))\r
873 \r
874 See Also\r
875 \r
876 GetBValue, GetGValue, GetRValue, PALETTEINDEX, PALETTERGB\r
877 \r
878 ==============================================================================\r
879 BITMAPCOREINFO (3.0)\r
880 \r
881 \r
882 \r
883 typedef struct tagBITMAPCOREINFO {  /* bmci */\r
884     BITMAPCOREHEADER bmciHeader;\r
885     RGBTRIPLE        bmciColors[1];\r
886 } BITMAPCOREINFO;\r
887 \r
888 The BITMAPCOREINFO structure fully defines the dimensions and color\r
889 information for a device-independent bitmap (DIB).  Windows applications\r
890 should use the BITMAPINFO structure instead of BITMAPCOREINFO whenever\r
891 possible.\r
892 \r
893 Member          Description\r
894 \r
895 bmciHeader      Specifies a BITMAPCOREHEADER structure that contains\r
896 information about the dimensions and color format of a DIB.\r
897 \r
898 bmciColors      Specifies an array of RGBTRIPLE structures that define the\r
899 colors in the bitmap.\r
900 \r
901 Comments\r
902 \r
903 The BITMAPCOREINFO structure describes the dimensions and colors of a bitmap.\r
904 It is followed immediately in memory by an array of bytes which define the\r
905 pixels of the bitmap. The bits in the array are packed together, but each\r
906 scan line must be zero-padded to end on a LONG boundary. Segment boundaries,\r
907 however, can appear anywhere in the bitmap. The origin of the bitmap is the\r
908 lower-left corner.\r
909 \r
910 The bcBitCount member of the BITMAPCOREHEADER structure determines the number\r
911 of bits that define each pixel and the maximum number of colors in the\r
912 bitmap. This member may be set to any of the following values:\r
913 \r
914 Value   Meaning\r
915 \r
916 1       The bitmap is monochrome, and the bmciColors member must contain two\r
917 entries. Each bit in the bitmap array represents a pixel. If the bit is\r
918 clear, the pixel is displayed with the color of the first entry in the\r
919 bmciColors table. If the bit is set, the pixel has the color of the second\r
920 entry in the table.\r
921 \r
922 4       The bitmap has a maximum of 16 colors, and the bmciColors member\r
923 contains 16 entries. Each pixel in the bitmap is represented by a four-bit\r
924 index into the color table.\r
925 \r
926 For example, if the first byte in the bitmap is 0x1F, the byte represents two\r
927 pixels. The first pixel contains the color in the second table entry, and the\r
928 second pixel contains the color in the sixteenth table entry.\r
929 \r
930 8       The bitmap has a maximum of 256 colors, and the bmciColors member\r
931 contains 256 entries. In this case, each byte in the array represents a\r
932 single pixel.\r
933 \r
934 24      The bitmap has a maximum of 2^24 colors. The bmciColors member is\r
935 NULL, and each 3-byte sequence in the bitmap array represents the relative\r
936 intensities of red, green, and blue, respectively, of a pixel.\r
937 \r
938 The colors in the bmciColors table should appear in order of importance.\r
939 Alternatively, for functions that use DIBs, the bmciColors member can be an\r
940 array of 16-bit unsigned integers that specify an index into the currently\r
941 realized logical palette instead of explicit RGB values. In this case, an\r
942 application using the bitmap must call DIB functions with the wUsage\r
943 parameter set to DIB_PAL_COLORS.\r
944 \r
945 Note:   The bmciColors member should not contain palette indexes if the\r
946 bitmap is to be stored in a file or transferred to another application.\r
947 Unless the application uses the bitmap exclusively and under its complete\r
948 control, the bitmap color table should contain explicit RGB values.\r
949 \r
950 See Also\r
951 \r
952 BITMAPINFO, BITMAPCOREHEADER, RGBTRIPLE \r
953 \r
954 \r
955 ==============================================================================\r
956 BITMAPCOREHEADER (3.0)\r
957 \r
958 \r
959 \r
960 typedef struct tagBITMAPCOREHEADER {    /* bmch */\r
961     DWORD   bcSize;\r
962     short   bcWidth;\r
963     short   bcHeight;\r
964     WORD    bcPlanes;\r
965     WORD    bcBitCount;\r
966 } BITMAPCOREHEADER;\r
967 \r
968 The BITMAPCOREHEADER structure contains information about the dimensions and\r
969 color format of a device-independent bitmap (DIB). Windows applications\r
970 should use the BITMAPINFOHEADER structure instead of BITMAPCOREHEADER\r
971 whenever possible.\r
972 \r
973 Member          Description\r
974 \r
975 bcSize          Specifies the number of bytes required by the\r
976 BITMAPCOREHEADER structure.\r
977 \r
978 bcWidth         Specifies the width of the bitmap, in pixels. \r
979 bcHeightSpecifies the height of the bitmap, in pixels. \r
980 \r
981 bcPlanesSpecifies the number of planes for the target device. This\r
982 member must be set to 1.\r
983 \r
984 bcBitCount      Specifies the number of bits per pixel. This value must be 1,\r
985 4, 8, or 24.\r
986 \r
987 Comments\r
988 \r
989 The BITMAPCOREINFO structure combines the BITMAPCOREHEADER structure and a\r
990 color table to provide a complete definition of the dimensions and colors of\r
991 a DIB. See the description of the BITMAPCOREINFO structure for more\r
992 information about specifying a DIB.\r
993 \r
994 An application should use the information stored in the bcSize member to\r
995 locate the color table in a BITMAPCOREINFO structure with a method such as\r
996 the following:\r
997 \r
998 \r
999 \r
1000 lpColor = ((LPSTR) pBitmapCoreInfo + (UINT) (pBitmapCoreInfo->bcSize))\r
1001 \r
1002 See Also\r
1003 \r
1004 BITMAPCOREINFO, BITMAPINFOHEADER, BITMAPINFOHEADER \r
1005 \r
1006 =============================================================================\r
1007 RGBTRIPLE (3.0)\r
1008 \r
1009 \r
1010 \r
1011 typedef struct tagRGBTRIPLE {   /* rgbt */\r
1012     BYTE    rgbtBlue;\r
1013     BYTE    rgbtGreen;\r
1014     BYTE    rgbtRed;\r
1015 } RGBTRIPLE;\r
1016 \r
1017 The RGBTRIPLE structure describes a color consisting of relative intensities\r
1018 of red, green, and blue. The bmciColors member of the BITMAPCOREINFO\r
1019 structure consists of an array of RGBTRIPLE structures.  Windows applications\r
1020 should use the BITMAPINFO structure instead of BITMAPCOREINFO whenever\r
1021 possible. The BITMAPINFO structure uses an RGBQUAD structure instead of the\r
1022 RGBTRIPLE structure.\r
1023 \r
1024 Member  Description\r
1025 \r
1026 rgbtBlueSpecifies the intensity of blue in the color. \r
1027 rgbtGreen       Specifies the intensity of green in the color. \r
1028 rgbtRed         Specifies the intensity of red in the color.\r
1029 \r
1030 See Also\r
1031 \r
1032 BITMAPCOREINFO, BITMAPINFO, RGBQUAD\r
1033 \r
1034 ==============================================================================\r