--------------------WINDOWS BITMAP (.bmp/.dib) IMAGE FORMAT--------------------- -------------------------------------------------------------------------------- OVERVIEW - word: a 2-byte little-endian integer - dword: a 4-byte little-endian integer - The four parts of a bitmap file are the bitmap header, the bitmap information, the color palette, & the bitmap data. - Unused fields are set to 0. BITMAP HEADER CONTENTS - "BM" - size of file as a dword - 4 reserved bytes whose value depends on the creator application; 0 seems to be the default - offset of the start of the bitmap data as a dword BITMAP INFORMATION CONTENTS The V3 header, the most common format: - size of this header (40 bytes) as a dword - bitmap width in pixels as a dword - bitmap height in pixels as a dword - number of color planes being used; stored as a word; not often used, so is usually set to 0 (Note: Recent versions of Preview.app seem to require this to be set to 1, or at least something non-zero.) - number of bits per pixel as a word (usually 1, 4, 8, 16, 24, or 32) - dword specifying the compression method used (0 for none) - bitmap data size as a dword; if not compressed, it may be set to 0 - horizontal resolution (pixels per meter) as a dword, usually set to 0 - vertical resolution (pixels per meter) as a dword, usually set to 0 - number of colors used as a dword; if 0, it is assumed to be 2 to the power of the number of bits per pixel - number of important colors used as a dword; can be 0 when all are important Alternatively, the OS/2 V1 header, which is also popular: - size of this header (12 bytes) as a dword - bitmap width in pixels as a word - bitmap height in pixels as a word - number of color planes used as a word - number of bits per pixel as a word COLOR PALETTE This is a list of all of the colors used by the image; it is omitted when the image uses 16 or more bits per pixel. Each entry in the palette consists of four bytes: the blue value, the green value, the red value, and 0. The image data indexes into this array in order to specify the color of each pixel. BITMAP DATA This section gives the color of each pixel in the image. The rows of pixels are listed from bottom to top, and the pixels in each row are listed from left to right. The number of bits used for each pixel (1, 4, 8, 16, 24, or 32) is defined in the bitmap information; when this number is less than 16, each pixel is represented by a number specifying a zero-based index into the color palette. When fewer than 8 bits are used, each index is stored using only that many bits, and consecutive indices are packed into bytes in descending bit order (e.g., two consecutive four-bit indices 5 and 11 are packed together as 0b01011011). When 16 or more bits are used per pixel, each pixel is represented as its color directly; for 24-bit images, each pixel is encoded as three bytes which give its red value, green value, and blue value, in that order. It is unclear how colors are represented in 16-bit and 32-bit images. NOTE: Each row of the image MUST be represented by a number of bytes equal to a multiple of 4; if a row uses a non-multiple of 4 bytes, it must be padded with NULs. SOURCES http://en.wikipedia.org/wiki/Bitmaps http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html