-
Notifications
You must be signed in to change notification settings - Fork 5
/
BitmapInfoHeader.cs
49 lines (44 loc) · 1.58 KB
/
BitmapInfoHeader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SL3Reader;
[StructLayout(LayoutKind.Sequential, Size = Size), SkipLocalsInit]
internal struct BitmapInfoHeader
{
internal const int Size = 40;
private uint StructureSize;
private int Width;
private int Height;
private ushort Planes;
private ushort BitCount;
private BitmapCompressionMode Compression;
private uint ImageSize;
private int XPixelsPerMeter;
private int YPixelsPerMeter;
private uint NumberOfUsedColors;
private uint NumberOfImportantColors;
internal BitmapInfoHeader(int width,
int height,
ushort bitCount = 8,
int xPixelsPerMeter = 0,
int yPixelsPerMeter = 0) =>
Update(width, height, bitCount, xPixelsPerMeter, yPixelsPerMeter);
internal void Update(int width,
int height,
ushort bitCount = 8,
int xPixelsPerMeter = 0,
int yPixelsPerMeter = 0)
{
const ushort ByteSize = 8;
StructureSize = Size;
Width = width;
Height = height;
Planes = 1;
BitCount = bitCount;
Compression = BitmapCompressionMode.BI_RGB;
ImageSize = (uint)(bitCount / ByteSize * height * width); // (width + (4 - width % 4))
XPixelsPerMeter = xPixelsPerMeter;
YPixelsPerMeter = yPixelsPerMeter;
NumberOfUsedColors = 256;
NumberOfImportantColors = 256;
}
}