home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / gfx / edit / amigaxv / docs / bmp.doc < prev    next >
Text File  |  1993-04-23  |  39KB  |  1,040 lines

  1. Note: the constants BI_RGB, BI_RLE8, and BI_RLE4 have the values 0, 1, and 2,
  2.     respectively.
  3.  
  4. =============================================================================
  5. Graphics File Formats
  6.  
  7. This topic describes the graphics-file formats used by the Microsoft Windows
  8. operating system. Graphics files include bitmap files, icon-resource files,
  9. and cursor-resource files.
  10.  
  11. Bitmap-File Formats
  12.  
  13. Windows bitmap files are stored in a device-independent bitmap (DIB) format
  14. that allows Windows to display the bitmap on any type of display device. The
  15. term "device independent" means that the bitmap specifies pixel color in a
  16. form independent of the method used by a display to represent color. The
  17. default filename extension of a Windows DIB file is .BMP.
  18.  
  19. Bitmap-File Structures
  20.  
  21. Each bitmap file contains a bitmap-file header, a bitmap-information header,
  22. a color table, and an array of bytes that defines the bitmap bits. The file
  23. has the following form:
  24.  
  25. BITMAPFILEHEADER bmfh;
  26. BITMAPINFOHEADER bmih;
  27. RGBQUAD          aColors[];
  28. BYTE             aBitmapBits[];
  29.  
  30. The bitmap-file header contains information about the type, size, and layout
  31. of a device-independent bitmap file. The header is defined as a
  32. BITMAPFILEHEADER structure.
  33.  
  34. The bitmap-information header, defined as a BITMAPINFOHEADER structure,
  35. specifies the dimensions, compression type, and color format for the bitmap.
  36.  
  37. The color table, defined as an array of RGBQUAD structures, contains as many
  38. elements as there are colors in the bitmap. The color table is not present
  39. for bitmaps with 24 color bits because each pixel is represented by 24-bit
  40. red-green-blue (RGB) values in the actual bitmap data area. The colors in the
  41. table should appear in order of importance. This helps a display driver
  42. render a bitmap on a device that cannot display as many colors as there are
  43. in the bitmap. If the DIB is in Windows version 3.0 or later format, the
  44. driver can use the biClrImportant member of the BITMAPINFOHEADER structure to
  45. determine which colors are important.
  46.  
  47. The BITMAPINFO structure can be used to represent a combined
  48. bitmap-information header and color table.  The bitmap bits, immediately
  49. following the color table, consist of an array of BYTE values representing
  50. consecutive rows, or "scan lines," of the bitmap. Each scan line consists of
  51. consecutive bytes representing the pixels in the scan line, in left-to-right
  52. order. The number of bytes representing a scan line depends on the color
  53. format and the width, in pixels, of the bitmap. If necessary, a scan line
  54. must be zero-padded to end on a 32-bit boundary. However, segment boundaries
  55. can appear anywhere in the bitmap. The scan lines in the bitmap are stored
  56. from bottom up. This means that the first byte in the array represents the
  57. pixels in the lower-left corner of the bitmap and the last byte represents
  58. the pixels in the upper-right corner.
  59.  
  60. The biBitCount member of the BITMAPINFOHEADER structure determines the number
  61. of bits that define each pixel and the maximum number of colors in the
  62. bitmap. These members can have any of the following values:
  63.  
  64. Value    Meaning
  65.  
  66. 1    Bitmap is monochrome and the color table contains two entries. Each
  67. bit in the bitmap array represents a pixel. If the bit is clear, the pixel is
  68. displayed with the color of the first entry in the color table. If the bit is
  69. set, the pixel has the color of the second entry in the table.
  70.  
  71. 4    Bitmap has a maximum of 16 colors. Each pixel in the bitmap is
  72. represented by a 4-bit index into the color table. For example, if the first
  73. byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel
  74. contains the color in the second table entry, and the second pixel contains
  75. the color in the sixteenth table entry.
  76.  
  77. 8    Bitmap has a maximum of 256 colors. Each pixel in the bitmap is
  78. represented by a 1-byte index into the color table. For example, if the first
  79. byte in the bitmap is 0x1F, the first pixel has the color of the
  80. thirty-second table entry.
  81.  
  82. 24    Bitmap has a maximum of 2^24 colors. The bmiColors (or bmciColors)
  83. member is NULL, and each 3-byte sequence in the bitmap array represents the
  84. relative intensities of red, green, and blue, respectively, for a pixel.
  85.  
  86. The biClrUsed member of the BITMAPINFOHEADER structure specifies the number
  87. of color indexes in the color table actually used by the bitmap. If the
  88. biClrUsed member is set to zero, the bitmap uses the maximum number of colors
  89. corresponding to the value of the biBitCount member.  An alternative form of
  90. bitmap file uses the BITMAPCOREINFO, BITMAPCOREHEADER, and RGBTRIPLE
  91. structures.
  92.  
  93. Bitmap Compression
  94.  
  95. Windows versions 3.0 and later support run-length encoded (RLE) formats for
  96. compressing bitmaps that use 4 bits per pixel and 8 bits per pixel.
  97. Compression reduces the disk and memory storage required for a bitmap.
  98.  
  99. Compression of 8-Bits-per-Pixel Bitmaps
  100.  
  101. When the biCompression member of the BITMAPINFOHEADER structure is set to
  102. BI_RLE8, the DIB is compressed using a run-length encoded format for a
  103. 256-color bitmap. This format uses two modes: encoded mode and absolute mode.
  104. Both modes can occur anywhere throughout a single bitmap.
  105.  
  106. Encoded Mode
  107.  
  108. A unit of information in encoded mode consists of two bytes. The first byte
  109. specifies the number of consecutive pixels to be drawn using the color index
  110. contained in the second byte.  The first byte of the pair can be set to zero
  111. to indicate an escape that denotes the end of a line, the end of the bitmap,
  112. or a delta. The interpretation of the escape depends on the value of the
  113. second byte of the pair, which must be in the range 0x00 through 0x02.
  114. Following are the meanings of the escape values that can be used in the
  115. second byte:
  116.  
  117. Second byte    Meaning
  118.  
  119. 0    End of line. 
  120. 1    End of bitmap. 
  121. 2    Delta. The two bytes following the escape contain unsigned values
  122. indicating the horizontal and vertical offsets of the next pixel from the
  123. current position.
  124.  
  125. Absolute Mode
  126.  
  127. Absolute mode is signaled by the first byte in the pair being set to zero and
  128. the second byte to a value between 0x03 and 0xFF. The second byte represents
  129. the number of bytes that follow, each of which contains the color index of a
  130. single pixel. Each run must be aligned on a word boundary.  Following is an
  131. example of an 8-bit RLE bitmap (the two-digit hexadecimal values in the
  132. second column represent a color index for a single pixel):
  133.  
  134. Compressed data        Expanded data
  135.  
  136. 03 04            04 04 04 
  137. 05 06            06 06 06 06 06 
  138. 00 03 45 56 67 00    45 56 67 
  139. 02 78            78 78 
  140. 00 02 05 01        Move 5 right and 1 down 
  141. 02 78            78 78 
  142. 00 00            End of line 
  143. 09 1E            1E 1E 1E 1E 1E 1E 1E 1E 1E 
  144. 00 01            End of RLE bitmap 
  145.  
  146. Compression of 4-Bits-per-Pixel Bitmaps
  147.  
  148. When the biCompression member of the BITMAPINFOHEADER structure is set to
  149. BI_RLE4, the DIB is compressed using a run-length encoded format for a
  150. 16-color bitmap. This format uses two modes: encoded mode and absolute mode.
  151.  
  152. Encoded Mode
  153.  
  154. A unit of information in encoded mode consists of two bytes. The first byte
  155. of the pair contains the number of pixels to be drawn using the color indexes
  156. in the second byte.
  157.  
  158. The second byte contains two color indexes, one in its high-order nibble
  159. (that is, its low-order 4 bits) and one in its low-order nibble.
  160.  
  161. The first pixel is drawn using the color specified by the high-order nibble,
  162. the second is drawn using the color in the low-order nibble, the third is
  163. drawn with the color in the high-order nibble, and so on, until all the
  164. pixels specified by the first byte have been drawn.
  165.  
  166. The first byte of the pair can be set to zero to indicate an escape that
  167. denotes the end of a line, the end of the bitmap, or a delta. The
  168. interpretation of the escape depends on the value of the second byte of the
  169. pair. In encoded mode, the second byte has a value in the range 0x00 through
  170. 0x02. The meaning of these values is the same as for a DIB with 8 bits per
  171. pixel.
  172.  
  173. Absolute Mode
  174.  
  175. In absolute mode, the first byte contains zero, the second byte contains the
  176. number of color indexes that follow, and subsequent bytes contain color
  177. indexes in their high- and low-order nibbles, one color index for each pixel.
  178. Each run must be aligned on a word boundary.
  179.  
  180. Following is an example of a 4-bit RLE bitmap (the on