1 module daffodil.bmp.headers; 2 3 import daffodil.bmp; 4 import daffodil.util.headers; 5 6 const BMP_FILE_HEADER = [0x42, 0x4D]; 7 8 struct BmpHeader { 9 @(Endianess.little): 10 uint size; 11 ushort reserved1; 12 ushort reserved2; 13 uint contentOffset; 14 } 15 16 enum DibVersion { 17 CORE = 12, 18 INFO = 40, 19 V2INFO = 52, 20 V3INFO = 56, 21 V4 = 108, 22 V5 = 124, 23 } 24 25 enum CompressionMethod { 26 RGB = 0, 27 RLE8 = 1, 28 RLE4 = 2, 29 BITFIELDS = 3, 30 JPEG = 4, 31 PNG = 5, 32 ALPHABITFIELDS = 6, 33 CMYK = 11, 34 CMYKRLE8 = 12, 35 CMYKRLE4 = 13, 36 } 37 38 /// Matches the typedefs found here: https://forums.adobe.com/servlet/JiveServlet/showImage/2-3273299-47801/BMP_Headers.png 39 struct DibHeader(DibVersion version_ = DibVersion.V5) { 40 @(Endianess.little): 41 // All versions 42 static if (version_ <= DibVersion.CORE) { 43 ushort width; 44 ushort height; 45 } else { 46 int width; 47 int height; 48 } 49 ushort planes; 50 ushort bitCount; 51 52 static if (version_ >= DibVersion.INFO) { 53 uint compression; 54 uint dataSize; 55 int xPixelsPerMeter; 56 int yPixelsPerMeter; 57 uint colorsUsed; 58 uint colorsImportant; 59 } 60 61 static if (version_ >= DibVersion.V2INFO) { 62 uint redMask; 63 uint greenMask; 64 uint blueMask; 65 } 66 67 static if (version_ >= DibVersion.V3INFO) { 68 uint alphaMask; 69 } 70 71 static if (version_ >= DibVersion.V4) { 72 uint csType; 73 // No idea what this is, but its 32 bits long 74 static struct Endpoints { long a; long b; long c; long d; int e; }; 75 Endpoints endpoints; 76 uint gammaRed; 77 uint gammaGreen; 78 uint gammaBlue; 79 } 80 81 static if (version_ >= DibVersion.V5) { 82 uint intent; 83 uint profileData; 84 uint profileSize; 85 uint reserved; 86 } 87 88 mixin Upcast; 89 } 90 91 struct DibColorMask(bool alpha = true) { 92 @(Endianess.little): 93 uint redMask; 94 uint greenMask; 95 uint blueMask; 96 97 static if (alpha) { 98 uint alphaMask; 99 } 100 }