Add a simple BMP parser. (#11)

This commit is contained in:
Matthias Mailänder
2021-03-30 20:55:14 +02:00
committed by GitHub
parent 2f41f6e233
commit 92d0abc57d
2 changed files with 52 additions and 0 deletions

51
patterns/bmp.hexpat Normal file
View File

@@ -0,0 +1,51 @@
#pragma MIME image/bmp
#pragma endian little
struct BitmapFileHeader {
u8 bfType[2];
u32 bfSize;
u16 bfReserved1;
u16 bfReserved2;
u32 bfOffBits;
};
struct BitmapInfoHeader {
u32 biSize;
s32 biWidth;
s32 biHeight;
u16 biPlanes;
u16 biBitCount;
u32 biCompression;
u32 biSizeImage;
s32 biXPelsPerMeter;
s32 biYPelsPerMeter;
u32 biClrUsed;
u32 biClrImportant;
};
struct Colors {
u8 blue;
u8 green;
u8 red;
u8 reserved;
};
struct Bitmap {
BitmapFileHeader bmfh;
BitmapInfoHeader bmih;
if ((bmih.biBitCount != 24) && (bmih.biBitCount != 32))
{
if (bmih.biClrUsed > 0 )
Colors rgbq[bmih.biClrUsed];
else
Colors rgbq[1 << bmih.biBitCount];
}
if (bmih.biSizeImage > 0 )
u8 lineData[bmih.biSizeImage];
else
u8 lineData[bmfh.bfSize - $];
};
Bitmap bitmap @ 0x00;