diff --git a/README.md b/README.md index f26298e..e757e03 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed | Name | MIME | Path | Description | |------|------|------|-------------| +| BMP | `image/bmp` | `patterns/bmp.hexpat` | OS2/Windows Bitmap files | | ELF | `application/x-executable` | `patterns/elf.hexpat` | ELF header in elf binaries | | PE | `application/x-dosexec` | `patterns/pe.hexpat` | PE header, COFF header, Standard COFF fields and Windows Specific fields | | MIDI | `audio/midi` | `patterns/midi.hexpat` | MIDI header, event fields provided | diff --git a/patterns/bmp.hexpat b/patterns/bmp.hexpat new file mode 100644 index 0000000..98972e2 --- /dev/null +++ b/patterns/bmp.hexpat @@ -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;