-
Notifications
You must be signed in to change notification settings - Fork 0
/
dibHeader.cpp
176 lines (110 loc) · 3.6 KB
/
dibHeader.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
enum DIB_HEADER_TYPE
{
UNDEFINED,
BITMAPCOREHEADER,
OS22XBITMAPHEADER,
BITMAPINFOHEADER,
BITMAPV2INFOHEADER,
BITMAPV3INFOHEADER,
BITMAPV4INFOHEADER,
BITMAPV5INFOHEADER
};
class dibHeader{
private:
///////////////////////////////////////////
// Header All formats
///////////////////////////////////////
DIB_HEADER_TYPE type;
uint32_t headerSize;
int width;
int height;
void loadBitmapCoreHeader(std::ifstream& file){
uint16_t width16;
uint16_t height16;
uint16_t numColorPlanes16;
uint16_t bitsPerPixel16;
file.read((char*)&width16, sizeof(uint16_t));
file.read((char*)&height16, sizeof(uint16_t));
file.read((char*)&numColorPlanes16, sizeof(uint16_t));
file.read((char*)&bitsPerPixel16, sizeof(uint16_t));
width = (int)width16;
height = (int)height16;
}
void loadBitmapInfoHeader(std::ifstream& file){
uint32_t width32;
uint32_t height32;
uint16_t numColorPlanes16;
uint16_t bitsPerPixel16;
uint32_t compressionMethod16; //default 0
uint32_t imageSize32;
uint32_t horizontalRes32;
uint32_t verticalRes32;
uint32_t numColors32; // default 0
uint32_t numImportantColors; // default 0
file.read((char*)&width32, sizeof(uint32_t));
file.read((char*)&height32, sizeof(uint32_t));
file.read((char*)&numColorPlanes16, sizeof(uint16_t));
file.read((char*)&bitsPerPixel16, sizeof(uint16_t));
file.read((char*)&compressionMethod16, sizeof(uint16_t)); //default 0
file.read((char*)&imageSize32, sizeof(uint32_t));
file.read((char*)&horizontalRes32, sizeof(uint32_t));
file.read((char*)&verticalRes32, sizeof(uint32_t));
file.read((char*)&numColors32, sizeof(uint32_t)); // default 0
file.read((char*)&numImportantColors, sizeof(uint32_t)); // default 0
width = (int)width32;
height = (int)height32;
}
public:
///////////////////////////////////////////
// Header All formats
///////////////////////////////////////
dibHeader(){
}
dibHeader(std::ifstream& file) {
assert(file.is_open());
file.read((char*)&headerSize, sizeof(uint32_t));
switch(headerSize){
case 12:
type = BITMAPCOREHEADER;
loadBitmapCoreHeader(file);
break;
case 64:
type = OS22XBITMAPHEADER;
break;
case 16:
type = OS22XBITMAPHEADER;
break;
case 40:
type = BITMAPINFOHEADER;
loadBitmapInfoHeader(file);
break;
case 52:
type = BITMAPV2INFOHEADER;
break;
case 56:
type = BITMAPV3INFOHEADER;
break;
case 108:
type = BITMAPV4INFOHEADER;
break;
case 124:
type = BITMAPV5INFOHEADER;
break;
default:
type = UNDEFINED;
break;
}
std::cout << "size is:" << (headerSize) << "\n";
std::cout << "width is: " << width << "\n";
std::cout << "height is: " << height << "\n";
}
int getWidth(){
return width;
}
int getHeight(){
return height;
}
int getDibSize(){
return headerSize;
}
};