Overview
- Device independent bitmap
- Can be moved from device to device (hence device independent)
- Normally transported in
- metafiles
- bmp files
- clipboard (CF_DIB data format)
- Contains
- bits
- header
- describes the format of the bits
- color format (color table)
- size of the bitmap
- describes the format of the bits
- Supports
- 1-bit, 4-bit, 8-bit
- pixels are defined by indexes into color table
- 24-bit
- 1 byte each for red, green, and blue
- 1-bit, 4-bit, 8-bit
- DIB functions
- GetDIBits
- SetDIBits
- CreateDIBBitmap
- SetDIBitsToDevice
- StretchDIBits
- CreateDIBPatternBrush
DIB Header
- Consists two adjoioning parts
- header
- color table
- Combined into the BITMAPINFO structure
- biSize
- biWidth
- biHeight
- biPlanes
- Should always be 1
- biBitCount
- Color resolution in bits per pixel.
- Allowed are 1, 4, 8, and 24
- biCompression
- Type of compression
- Can be
- BI_RGB
- BI_RLE4
- BI_RLE8
- biSizeImage
- Size of the bitmap proper in bytes
- biXPelsPerMeter
- biYPelsPerMeter
- biClrUsed
- biClrImportant
OS2 Style DIB
- A DIB file has
- A file header
// 14 bytes since each WORD is 2 bytes and DWORD is 4
typedef struct tagBITMAPFILEHEADER // bmfh
{
WORD bfType ; // signature word "BM" or 0x4D42
DWORD bfSize ; // entire size of file
WORD bfReserved1 ; // must be zero
WORD bfReserved2 ; // must be zero
DWORD bfOffsetBits ; // offset in file of DIB pixel bits
}
BITMAPFILEHEADER, * PBITMAPFILEHEADER ;
- An information header
typedef struct tagBITMAPCOREHEADER // bmch
{
DWORD bcSize ; // size of the structure = 12
WORD bcWidth ; // width of image in pixels
WORD bcHeight ; // height of image in pixels
WORD bcPlanes ; // = 1
WORD bcBitCount ; // bits per pixel (1, 4, 8, or 24)
}
BITMAPCOREHEADER, * PBITMAPCOREHEADER ;// Also defined in WINGDI.H
typedef struct tagBITMAPCOREINFO // bmci
{
BITMAPCOREHEADER bmciHeader ; // core-header structure
RGBTRIPLE bmciColors[1] ; // color table array
// Always 2, 16, or 256 RGBTRIPLE structures depending on bits per pixel
// Allocate PBITMAPCOREINFO for an 8-bit DIB
// pbmci = malloc (sizeof (BITMAPCOREINFO) + 255 * sizeof (RGBTRIPLE)) ;
}
BITMAPCOREINFO, * PBITMAPCOREINFO ; - An RGB color table (but not always. not with 24 bit/pixel DIB)
- An array of 3 byte RGBTRIPLE structures
typedef struct tagRGBTRIPLE // rgbt
{
BYTE rgbtBlue ; // blue level
BYTE rgbtGreen ; // green level
BYTE rgbtRed ; // red level
}
RGBTRIPLE ;
- An array of 3 byte RGBTRIPLE structures
- The bitmap pixel bits
- A file header
- A in memory DIB has exactly as DIB file minus file header