-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExivInfo.cpp
140 lines (120 loc) · 2.9 KB
/
ExivInfo.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
#include "ExivInfo.h"
#include <QDateTime>
ExivInfo::ExivInfo(std::string RawFilePath)
{
Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);
m_Image = Exiv2::ImageFactory::open(RawFilePath);
if (m_Image.get() == nullptr){
m_Valid = false;
return;
}
m_Valid = true;
m_Image->readMetadata();
Exiv2::ExifData &exifData = m_Image->exifData();
m_ExivInfo = &exifData;
if (exifData.empty() == true){
m_Empty = true;
}else{
m_Empty = false;
}
}
bool ExivInfo::IsValid()
{
return m_Valid;
}
bool ExivInfo::IsEmpty()
{
return m_Empty;
}
std::string ExivInfo::GetMIMEType()
{
std::string Str = "";
GetExifKey("Exif.Image.Make", Str);
return Str;
}
bool ExivInfo::GetSize(int &width, int &Height)
{
std::string Value;
if (GetExifKey("Exif.Photo.PixelXDimension", Value) == false){
width = std::stoi(Value);
return false;
}
if (GetExifKey("Exif.Photo.PixelYDimension", Value) == false){
Height = std::stoi(Value);
return false;
}
return true;
}
std::string ExivInfo::GetCameraMake()
{
std::string Value;
GetExifKey("Exif.Image.Make", Value);
return Value;
}
std::string ExivInfo::GetCameraModel()
{
std::string Value;
GetExifKey("Exif.Image.Model", Value);
return Value;
}
long int ExivInfo::GetTimestamp()
{
std::string Value;
long int TimeStmap = 0;
if (GetExifKey("Exif.Image.DateTime", Value) == true){
TimeStmap = QDateTime::fromString(QString(Value.c_str()), "yyyy:MM:dd hh:mm:ss").toTime_t();
}
return TimeStmap;
}
int ExivInfo::GetExposure()
{
std::string Value;
long int TimeStmap = 0;
if (GetExifKey("Exif.Photo.ExposureTime", Value) == true){
TimeStmap = std::stoi(Value);
}
return TimeStmap;
}
float ExivInfo::GetAperture()
{
std::string Value;
float Aperture = 0.0;
if (GetExifKey("Exif.Photo.FNumber", Value) == true){
Aperture = std::stof(Value);
}
return Aperture;
}
int ExivInfo::GetISOSpeed()
{
std::string Value;
int ISOSpeed = 0;
if (GetExifKey("Exif.Photo.ISOSpeedRatings", Value) == true){
ISOSpeed = std::stoi(Value);
}
return ISOSpeed;
}
std::string ExivInfo::GetCopyright()
{
std::string Str = "";
GetExifKey("Exif.Image.Copyright", Str);
return Str;
}
int ExivInfo::GetAllInfo(std::map<std::string, std::string> &Map)
{
Map.clear();
for (Exiv2::ExifData::iterator tmp = m_ExivInfo->begin(); tmp != m_ExivInfo->end(); tmp++) {
Map[tmp->key()] = tmp->value().toString();
}
return Map.size();
}
bool ExivInfo::GetExifKey(std::string key, std::string &String)
{
Exiv2::ExifKey tmp = Exiv2::ExifKey(key);
Exiv2::ExifData::iterator pos = m_ExivInfo->findKey(tmp);
if (pos == m_ExivInfo->end()) {
return false;
}
String = pos->value().toString();
return true;
}