What is DIB in Bitmap

Structure of DIB files * .bmp, bitmap

Description of the structure of .bmp files from the beginning of the file

First comes the BITMAPFILEHEADER, then the BITMAPINFOHEADER and then one Color tableif the number of colors is less than or equal to 256. Then the image data. struct BITMAPFILEHEADER {WORD bfType; // type for * .bmp in hex = 424D = BM DWORD bfSize; // File size in bytes WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; // offset to the first data byte of the image}; struct BITMAPINFOHEADER {DWORD biSize; // Length of the info header (this record) = 40 bytes in hex 28 LONG biWidth; // width of the image LONG biHeight; // Height of the picture WORD biPlanes; // Number of color levels usually 1 and 0 WORD biBitCount; // Number of bits per pixel (number of colors) // 1 = black and white, 4 = 16 colors = 64 bytes, // 8 = 256 colors = 1024 bytes, 24 = 16 million colors DWORD biCompression; // Compression type, 0 = uncompressed, 1 = 8-bit // run-length encoding method, // 2 = 4-bit run-coding method DWORD biSizeImage; // Image size in bytes. LONG biXPelsPerMeter; // Horizontal resolution LONG biYPelsPerMeter; // Vertical resolution DWORD biClrUsed; // The number of colors in the picture DWORD biClrImportant; // the number of important colors}; According to the size of the biBitCount, here is one Color table, with biBitCount = 18 Hex = 24 not. If the biBitCount = 1 then this is Color table 8 bytes large. 2 colors, four bytes for black and 4 bytes for white If the biBitCount = 4 then the Color table 64 bytes in size. 16 colors * Four bytes for each color. If the biBitCount = 8 then this is Color table 1024 bytes in size. 256 colors * Four bytes for each color. If the biBitCount is larger, there is none Color table more available. The color values ​​are saved individually for each pixel in the data block of the file, 3 bytes for one color. If biBitCount = 1, 1 bit is used as a reference to the index in the Color table used, zero and one = 2 colors. For example, the image data of a 32 * 32 pixel image is 128 bytes, 32 * 32 = 1024/8 = 128. With biBitCount = 4, 4 bits are used for the reference to the Color table used, 4 bits = 0-15. The sample image is then 512 bytes in size. With biBitCount = 8, 1 byte becomes 8 bits for the reference to the Color table used, 8 bit = 0-255. The sample image is then 1024 bytes. In biSizeImage the value 400 should then be in hex = 1024 bytes. Of the 4 bytes for a color, only 3 bytes are used, 1 byte each for red, green and blue (RGB). Examples: 00 00 00 00 = black, 00 FF FF FF = white, 00 FF 00 00 = red, etc. Important note: With biBitCount = 4, 16 the 16 colors are in the Color table specified, it must be exactly these 16 colors (system colors). This is not the case with 256 colors. So 4 bytes for colors in the Color table and 3 bytes for the colors if none Color table is available.