forked from mayanklahiri/easyexif
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.cpp
225 lines (177 loc) · 6.5 KB
/
demo.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <cstdio>
#include "exif.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: demo <JPEG file>\n");
return -1;
}
// Read the JPEG file into a buffer
FILE *fp = fopen(argv[1], "rb");
if (!fp) {
printf("Can't open file.\n");
return -1;
}
fseek(fp, 0, SEEK_END);
unsigned long fsize = ftell(fp);
rewind(fp);
unsigned char *buf = new unsigned char[fsize];
if (fread(buf, 1, fsize, fp) != fsize) {
printf("Can't read file.\n");
fclose(fp);
delete[] buf;
return -2;
}
fclose(fp);
// Parse EXIF
easyexif::EXIFInfo result;
easyexif::ParseError code = result.parseFrom(buf, fsize);
delete[] buf;
if (code != easyexif::ParseError::None) {
printf("Error parsing EXIF: code %d\n", static_cast<int>(code));
return -3;
}
// Dump EXIF information
if (result.isValid(result.Make)) {
printf("Camera make : %s\n", result.Make.c_str());
}
if (result.isValid(result.Model)) {
printf("Camera model : %s\n", result.Model.c_str());
}
if (result.isValid(result.Software)) {
printf("Software : %s\n", result.Software.c_str());
}
if (result.isValid(result.BitsPerSample)) {
printf("Bits per sample : %d\n", result.BitsPerSample);
}
if (result.isValid(result.XResolution)) {
printf("XResolution : %.1f\n", result.XResolution);
}
if (result.isValid(result.YResolution)) {
printf("YResolution : %.1f\n", result.YResolution);
}
if (result.isValid(result.ResolutionUnit)) {
printf("ResolutionUnit : %u\n", result.ResolutionUnit);
}
if (result.isValid(result.ColorSpace)) {
printf("Color space : %u\n", result.ColorSpace);
}
if (result.isValid(result.WhiteBalance)) {
printf("White balance : %u\n", result.WhiteBalance);
}
if (result.isValid(result.ImageWidth)) {
printf("Image width : %u\n", result.ImageWidth);
}
if (result.isValid(result.ImageHeight)) {
printf("Image height : %u\n", result.ImageHeight);
}
if (result.isValid(result.ImageDescription)) {
printf("Image description : %s\n", result.ImageDescription.c_str());
}
if (result.isValid(result.Orientation)) {
printf("Image orientation : %d\n", result.Orientation);
}
if (result.isValid(result.Copyright)) {
printf("Image copyright : %s\n", result.Copyright.c_str());
}
if (result.isValid(result.DateTime)) {
printf("Image date/time : %s\n", result.DateTime.c_str());
}
if (result.isValid(result.DateTimeOriginal)) {
printf("Original date/time : %s\n", result.DateTimeOriginal.c_str());
}
if (result.isValid(result.DateTimeDigitized)) {
printf("Digitize date/time : %s\n", result.DateTimeDigitized.c_str());
}
if (result.isValid(result.SubSecTimeOriginal)) {
printf("Subsecond time : %s\n", result.SubSecTimeOriginal.c_str());
}
if (result.isValid(result.ExposureTime)) {
printf("Exposure time : 1/%u s\n",
static_cast<unsigned int>(1.0 / result.ExposureTime));
}
if (result.isValid(result.FNumber)) {
printf("F-stop : f/%.1f\n", result.FNumber);
}
if (result.isValid(result.ExposureProgram)) {
printf("Exposure program : %d\n", result.ExposureProgram);
}
if (result.isValid(result.ExposureMode)) {
printf("Exposure mode : %d\n", result.ExposureMode);
}
if (result.isValid(result.ISOSpeedRatings)) {
printf("ISO speed : %d\n", result.ISOSpeedRatings);
}
if (result.isValid(result.SubjectDistance)) {
printf("Subject distance : %f m\n", result.SubjectDistance);
}
if (result.isValid(result.ExposureBiasValue)) {
printf("Exposure bias : %f EV\n", result.ExposureBiasValue);
}
if (result.isValid(result.Flash)) {
printf("Flash used? : %d\n", result.Flash);
}
if (result.isValid(result.FlashReturnedLight)) {
printf("Flash returned light : %d\n", result.FlashReturnedLight);
}
if (result.isValid(result.FlashMode)) {
printf("Flash mode : %d\n", result.FlashMode);
}
if (result.isValid(result.MeteringMode)) {
printf("Metering mode : %d\n", result.MeteringMode);
}
if (result.isValid(result.FocalLength)) {
printf("Lens focal length : %f mm\n", result.FocalLength);
}
if (result.isValid(result.FocalLengthIn35mm)) {
printf("35mm focal length : %u mm\n", result.FocalLengthIn35mm);
}
if (result.isValid(result.GeoLocation.Latitude)) {
printf("GPS Latitude : %f deg (%f deg, %f min, %f sec %c)\n",
result.GeoLocation.Latitude,
result.GeoLocation.LatComponents.degrees,
result.GeoLocation.LatComponents.minutes,
result.GeoLocation.LatComponents.seconds,
result.GeoLocation.LatComponents.direction);
}
if (result.isValid(result.GeoLocation.Longitude)) {
printf("GPS Longitude : %f deg (%f deg, %f min, %f sec %c)\n",
result.GeoLocation.Longitude,
result.GeoLocation.LonComponents.degrees,
result.GeoLocation.LonComponents.minutes,
result.GeoLocation.LonComponents.seconds,
result.GeoLocation.LonComponents.direction);
}
if (result.isValid(result.GeoLocation.Altitude)) {
printf("GPS Altitude : %f m\n", result.GeoLocation.Altitude);
}
if (result.isValid(result.GeoLocation.DOP)) {
printf("GPS Precision (DOP) : %f\n", result.GeoLocation.DOP);
}
if (result.isValid(result.LensInfo.FocalLengthMin)) {
printf("Lens min focal length: %f mm\n", result.LensInfo.FocalLengthMin);
}
if (result.isValid(result.LensInfo.FocalLengthMax)) {
printf("Lens max focal length: %f mm\n", result.LensInfo.FocalLengthMax);
}
if (result.isValid(result.LensInfo.FStopMin)) {
printf("Lens f-stop min : f/%.1f\n", result.LensInfo.FStopMin);
}
if (result.isValid(result.LensInfo.FStopMax)) {
printf("Lens f-stop max : f/%.1f\n", result.LensInfo.FStopMax);
}
if (result.isValid(result.LensInfo.Make)) {
printf("Lens make : %s\n", result.LensInfo.Make.c_str());
}
if (result.isValid(result.LensInfo.Model)) {
printf("Lens model : %s\n", result.LensInfo.Model.c_str());
}
if (result.isValid(result.LensInfo.FocalPlaneXResolution)) {
printf("Focal plane XRes : %f\n",
result.LensInfo.FocalPlaneXResolution);
}
if (result.isValid(result.LensInfo.FocalPlaneYResolution)) {
printf("Focal plane YRes : %f\n",
result.LensInfo.FocalPlaneYResolution);
}
return 0;
}