Toucouch | Tiré de la doc de Win32:
Code :
- Bitmaps should be saved in a file that uses the established Windows format and assigned a name with the three-character .BMP extension. The established Windows format consists of a BITMAPFILEHEADER structure followed by a BITMAPINFOHEADER structure. An array of RGBQUAD structures (also called a color table) follows the BITMAPINFOHEADER structure. The color table is followed by a second array of indexes into the color table (the actual bitmap data).
- The Windows format is shown in the following illustration.
- The members of the BITMAPFILEHEADER structure identify the file; specify the size of the file, in bytes; and specify the offset from the first byte in the header to the first byte of bitmap data. The members of the BITMAPINFOHEADER structure specify the bitmap's width and height, in pixels; the color format (count of color planes and color bits per pixel) of the display device on which the bitmap was created; whether the bitmap data was compressed before storage and the type of compression used; the number of bytes of bitmap data; the resolution of the display device on which the bitmap was created; and the number of colors represented in the data. The RGBQUAD structures specify the RGB intensity values for each of the colors in the device's palette. The color-index array maps indices values from the RGBQUAD array to pixels in a rectangular region on the display.
- The following hexadecimal output shows the contents of the file REDBRICK.BMP.
- 0000 42 4d 76 02 00 00 00 00 00 00 76 00 00 00 28 00
- 0010 00 00 20 00 00 00 20 00 00 00 01 00 04 00 00 00
- 0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- 0030 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80
- 0040 00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80
- 0050 00 00 80 80 80 00 c0 c0 c0 00 00 00 ff 00 00 ff
- 0060 00 00 00 ff ff 00 ff 00 00 00 ff 00 ff 00 ff ff
- 0070 00 00 ff ff ff 00 00 00 00 00 00 00 00 00 00 00
- 0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00
- 0090 00 00 00 00 00 00 11 11 01 19 11 01 10 10 09 09
- 00a0 01 09 11 11 01 90 11 01 19 09 09 91 11 10 09 11
- 00b0 09 11 19 10 90 11 19 01 19 19 10 10 11 10 09 01
- 00c0 91 10 91 09 10 10 90 99 11 11 11 11 19 00 09 01
- 00d0 91 01 01 19 00 99 11 10 11 91 99 11 09 90 09 91
- 00e0 01 11 11 11 91 10 09 19 01 00 11 90 91 10 09 01
- 00f0 11 99 10 01 11 11 91 11 11 19 10 11 99 10 09 10
- 0100 01 11 11 11 19 10 11 09 09 10 19 10 10 10 09 01
- 0110 11 19 00 01 10 19 10 11 11 01 99 01 11 90 09 19
- 0120 11 91 11 91 01 11 19 10 99 00 01 19 09 10 09 19
- 0130 10 91 11 01 11 11 91 01 91 19 11 00 99 90 09 01
- 0140 01 99 19 01 91 10 19 91 91 09 11 99 11 10 09 91
- 0150 11 10 11 91 99 10 90 11 01 11 11 19 11 90 09 11
- 0160 00 19 10 11 01 11 99 99 99 99 99 99 99 99 09 99
- 0170 99 99 99 99 99 99 00 00 00 00 00 00 00 00 00 00
- 0180 00 00 00 00 00 00 90 00 00 00 00 00 00 00 00 00
- 0190 00 00 00 00 00 00 99 11 11 11 19 10 19 19 11 09
- 01a0 10 90 91 90 91 00 91 19 19 09 01 10 09 01 11 11
- 01b0 91 11 11 11 10 00 91 11 01 19 10 11 10 01 01 11
- 01c0 90 11 11 11 91 00 99 09 19 10 11 90 09 90 91 01
- 01d0 19 09 91 11 01 00 90 10 19 11 00 11 11 00 10 11
- 01e0 01 10 11 19 11 00 90 19 10 91 01 90 19 99 00 11
- 01f0 91 01 11 01 91 00 99 09 09 01 10 11 91 01 10 91
- 0200 99 11 10 90 91 00 91 11 00 10 11 01 10 19 19 09
- 0210 10 00 99 01 01 00 91 01 19 91 19 91 11 09 10 11
- 0220 00 91 00 10 90 00 99 01 11 10 09 10 10 19 09 01
- 0230 91 90 11 09 11 00 90 99 11 11 11 90 19 01 19 01
- 0240 91 01 01 19 09 00 91 10 11 91 99 09 09 90 11 91
- 0250 01 19 11 11 91 00 91 19 01 00 11 00 91 10 11 01
- 0260 11 11 10 01 11 00 99 99 99 99 99 99 99 99 99 99
- 0270 99 99 99 99 99 90
- The following table shows the data bytes associated with the structures in a bitmap file.
- Structure Corresponding bytes
- BITMAPFILEHEADER 0x00 - 0x0D
- BITMAPINFOHEADER 0x0E - 0x31
- RGBQUAD array 0x32 - 0x75
- Color-index array 0x76 - 0x275
|
Code :
- typedef struct tagBITMAPFILEHEADER { // bmfh
- WORD bfType;
- DWORD bfSize;
- WORD bfReserved1;
- WORD bfReserved2;
- DWORD bfOffBits;
- } BITMAPFILEHEADER;
- The BITMAPFILEHEADER structure contains information about the type, size, and layout of a file that contains a device-independent bitmap (DIB).
- Members
- bfType
- Specifies the file type. It must be BM.
- bfSize
- Specifies the size, in bytes, of the bitmap file.
- bfReserved1
- Reserved; must be zero.
- bfReserved2
- Reserved; must be zero.
- bfOffBits
- Specifies the offset, in bytes, from the BITMAPFILEHEADER structure to the bitmap bits.
- Remarks
- A BITMAPINFO or BITMAPCOREINFO structure immediately follows the BITMAPFILEHEADER structure in the DIB file.
|
Code :
- typedef struct tagBITMAPINFOHEADER{ // bmih
- DWORD biSize;
- LONG biWidth;
- LONG biHeight;
- WORD biPlanes;
- WORD biBitCount
- DWORD biCompression;
- DWORD biSizeImage;
- LONG biXPelsPerMeter;
- LONG biYPelsPerMeter;
- DWORD biClrUsed;
- DWORD biClrImportant;
- } BITMAPINFOHEADER;
- The BITMAPINFOHEADER structure contains information about the dimensions and color format of a device-independent bitmap (DIB).
- Members
- biSize
- Specifies the number of bytes required by the structure.
- biWidth
- Specifies the width of the bitmap, in pixels.
- biHeight
- Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper left corner.
- biPlanes
- Specifies the number of planes for the target device. This value must be set to 1.
- biBitCount
- Specifies the number of bits per pixel. This value must be 1, 4, 8, 16, 24, or 32.
- biCompression
- Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be compressed). It can be one of the following values:
- Value Description
- BI_RGB An uncompressed format.
- BI_RLE8 A run-length encoded (RLE) format for bitmaps with 8 bits per pixel. The compression format is a two-byte format consisting of a count byte followed by a byte containing a color index. For more information, see the following Remarks section.
- BI_RLE4 An RLE format for bitmaps with 4 bits per pixel. The compression format is a two-byte format consisting of a count byte followed by two word-length color indices. For more information, see the following Remarks section.
- BI_BITFIELDS Specifies that the bitmap is not compressed and that the color table consists of three doubleword color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bits-per-pixel bitmaps.
- biSizeImage
- Specifies the size, in bytes, of the image. This may be set to 0 for BI_RGB bitmaps.
- biXPelsPerMeter
- Specifies the horizontal resolution, in pixels per meter, of the target device for the bitmap. An application can use this value to select a bitmap from a resource group that best matches the characteristics of the current device.
- biYPelsPerMeter
- Specifies the vertical resolution, in pixels per meter, of the target device for the bitmap.
- biClrUsed
- Specifies the number of color indices in the color table that are actually used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression.
- If biClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed member specifies the actual number of colors the graphics engine or device driver accesses. If biBitCount is 16 or greater, then biClrUsed member specifies the size of the color table used to optimize performance of Windows color palettes. If biBitCount equals 16 or 32, the optimal color palette starts immediately following the three doubleword masks.
- If the bitmap is a packed bitmap (a bitmap in which the bitmap array immediately follows the BITMAPINFO header and which is referenced by a single pointer), the biClrUsed member must be either 0 or the actual size of the color table.
- biClrImportant
- Specifies the number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important.
- Remarks
- The BITMAPINFO structure combines the BITMAPINFOHEADER structure and a color table to provide a complete definition of the dimensions and colors of a DIB. For more information about DIBs, see the description of the BITMAPINFO data structure.
- An application should use the information stored in the biSize member to locate the color table in a BITMAPINFO structure, as follows:
- pColor = ((LPSTR)pBitmapInfo +
- (WORD)(pBitmapInfo->bmiHeader.biSize));
- Windows supports formats for compressing bitmaps that define their colors with eight or four bits per pixel. Compression reduces the disk and memory storage required for the bitmap. The following paragraphs describe these formats.
- When the biCompression member is BI_RLE8, the bitmap is compressed by using a run-length encoding (RLE) format for an 8-bit bitmap. This format can be compressed in encoded or absolute modes. Both modes can occur anywhere in the same bitmap.
- · Encoded mode consists of two bytes: the first byte specifies the number of consecutive pixels to be drawn using the color index contained in the second byte. In addition, the first byte of the pair can be set to zero to indicate an escape that denotes an end of line, end of bitmap, or delta. The interpretation of the escape depends on the value of the second byte of the pair, which can be one of the following:
- Value Meaning
- 0 End of line.
- 1 End of bitmap.
- 2 Delta. The two bytes following the escape contain unsigned values indicating the horizontal and vertical offsets of the next pixel from the current position.
- · In absolute mode, the first byte is zero and the second byte is a value in the range 03H through FFH. The second byte represents the number of bytes that follow, each of which contains the color index of a single pixel. When the second byte is 2 or less, the escape has the same meaning as in encoded mode. In absolute mode, each run must be aligned on a word boundary.
- The following example shows the hexadecimal values of an 8-bit compressed bitmap.
- 03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01
- 02 78 00 00 09 1E 00 01
- This bitmap would expand as follows (two-digit values represent a color index for a single pixel):
- 04 04 04
- 06 06 06 06 06
- 45 56 67
- 78 78
- move current position 5 right and 1 down
- 78 78
- end of line
- 1E 1E 1E 1E 1E 1E 1E 1E 1E
- end of RLE bitmap
- When the biCompression member is BI_RLE4, the bitmap is compressed by using a run-length encoding format for a 4-bit bitmap, which also uses encoded and absolute modes:
- · In encoded mode, the first byte of the pair contains the number of pixels to be drawn using the color indices in the second byte. The second byte contains two color indices, one in its high-order four bits and one in its low-order four bits. The first of the pixels is drawn using the color specified by the high-order four bits, the second is drawn using the color in the low-order four bits, the third is drawn using the color in the high-order four bits, and so on, until all the pixels specified by the first byte have been drawn.
- · In absolute mode, the first byte is zero, the second byte contains the number of color indices that follow, and subsequent bytes contain color indices in their high- and low-order four bits, one color index for each pixel. In absolute mode, each run must be aligned on a word boundary. The end-of-line, end-of-bitmap, and delta escapes described for BI_RLE8 also apply to BI_RLE4 compression.
- The following example shows the hexadecimal values of a 4-bit compressed bitmap.
- 03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01
- 04 78 00 00 09 1E 00 01
- This bitmap would expand as follows (single-digit values represent a color index for a single pixel):
- 0 4 0
- 0 6 0 6 0
- 4 5 5 6 6 7
- 7 8 7 8
- move current position 5 right and 1 down
- 7 8 7 8
- end of line
- 1 E 1 E 1 E 1 E 1
- end of RLE bitmap
- If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
|
Code :
- typedef struct tagRGBQUAD { // rgbq
- BYTE rgbBlue;
- BYTE rgbGreen;
- BYTE rgbRed;
- BYTE rgbReserved;
- } RGBQUAD;
- The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue.
- Members
- rgbBlue
- Specifies the intensity of blue in the color.
- rgbGreen
- Specifies the intensity of green in the color.
- rgbRed
- Specifies the intensity of red in the color.
- rgbReserved
- Reserved; must be zero.
- Remarks
- The bmiColors member of the BITMAPINFO structure consists of an array of RGBQUAD structures.
|
Bonne lecture! |