Pfft. bmps are so easy you don't even need structues. You can just write the headers yourself:
All integers are unsigned and little endian (
http://en.wikipedia.org/wiki/Endianness )
Bytes 0-1: Magic word. It contains the letters 'B' and 'M'.
Bytes 2-5: Double word. File size.
Bytes 6-10: No idea. Leave this zeroed.
Bytes 11-14: Double word. Start of the bitmap.
Bytes 15-18: Double word. Size of the header. Normally set to 40. The header is considered to start at offset 15.
Bytes 19-22: Double word. Width.
Bytes 23-26: Double word. Height.
Bytes 27-28: Word. Planes. Must be 1.
Bytes 29-30: Word. Bits per pixel. You'll need this as 24.
Bytes 31-34: Double word. Compression. Leave it as zero.
Bytes 35-38: Double word. Compressed size. Since there's no compression, this value will be the same as file size.
Bytes 39-42: Double word. Horizontal resolution. See below.
Bytes 43-46: Double word. Vertical resolution. Pixels per meter, according to Wikipedia. The values seem to vary, but 2835 should do for both.
Bytes 47-50: Double word. Number of colors in the palette. Leave as zero.
Bytes 51-54: Double word. "Important colors". Leave as zero.
Bytes 55-EOF: Bitmap.
In a 24-bit bitmap, every pixel channel uses exactly 8 bits and, being a little endian file, they appear in BGR order.
Rows appear from top to bottom (in a 640x480 image, the first pixel in the file is 0;479, then the next row is 478, etc.).
If the last byte in a row isn't at file offset divisible by 4, padding pixels must be added until this condition is met. For example:
1 2 3
|
//file is an std::vector<unsigned char>
while (file.size()%4)
file.push_back(0);
| |
This pretty much covers bmps.