Changeset View
Changeset View
Standalone View
Standalone View
src/extractors/exiv2extractor.cpp
Show All 13 Lines | 1 | /* | |||
---|---|---|---|---|---|
14 | 14 | | |||
15 | You should have received a copy of the GNU Lesser General Public | 15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | 16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | 20 | | |||
21 | #include "exiv2extractor.h" | 21 | #include "exiv2extractor.h" | ||
22 | #include <cmath> | ||||
22 | #include <QDebug> | 23 | #include <QDebug> | ||
23 | 24 | | |||
24 | using namespace KFileMetaData; | 25 | using namespace KFileMetaData; | ||
25 | 26 | | |||
26 | 27 | | |||
27 | Exiv2Extractor::Exiv2Extractor(QObject* parent) | 28 | Exiv2Extractor::Exiv2Extractor(QObject* parent) | ||
28 | : ExtractorPlugin(parent) | 29 | : ExtractorPlugin(parent) | ||
29 | { | 30 | { | ||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | 142 | { | |||
205 | QByteArray latRef = fetchByteArray(data, "Exif.GPSInfo.GPSLatitudeRef"); | 206 | QByteArray latRef = fetchByteArray(data, "Exif.GPSInfo.GPSLatitudeRef"); | ||
206 | if (!latRef.isEmpty() && latRef[0] == 'S') | 207 | if (!latRef.isEmpty() && latRef[0] == 'S') | ||
207 | latitude *= -1; | 208 | latitude *= -1; | ||
208 | 209 | | |||
209 | QByteArray longRef = fetchByteArray(data, "Exif.GPSInfo.GPSLongitudeRef"); | 210 | QByteArray longRef = fetchByteArray(data, "Exif.GPSInfo.GPSLongitudeRef"); | ||
210 | if (!longRef.isEmpty() && longRef[0] == 'W') | 211 | if (!longRef.isEmpty() && longRef[0] == 'W') | ||
211 | longitude *= -1; | 212 | longitude *= -1; | ||
212 | 213 | | |||
213 | if (latitude != 0.0) { | 214 | if (!std::isnan(latitude)) { | ||
214 | result->add(Property::PhotoGpsLatitude, latitude); | 215 | result->add(Property::PhotoGpsLatitude, latitude); | ||
215 | } | 216 | } | ||
216 | 217 | | |||
217 | if (longitude != 0.0) { | 218 | if (!std::isnan(longitude)) { | ||
218 | result->add(Property::PhotoGpsLongitude, longitude); | 219 | result->add(Property::PhotoGpsLongitude, longitude); | ||
219 | } | 220 | } | ||
220 | 221 | | |||
221 | if (altitude != 0.0) { | 222 | if (!std::isnan(altitude)) { | ||
222 | result->add(Property::PhotoGpsAltitude, altitude); | 223 | result->add(Property::PhotoGpsAltitude, altitude); | ||
223 | } | 224 | } | ||
224 | } | 225 | } | ||
225 | 226 | | |||
226 | void Exiv2Extractor::add(ExtractionResult* result, const Exiv2::ExifData& data, | 227 | void Exiv2Extractor::add(ExtractionResult* result, const Exiv2::ExifData& data, | ||
227 | Property::Property prop, const char* name, | 228 | Property::Property prop, const char* name, | ||
228 | QVariant::Type type) | 229 | QVariant::Type type) | ||
229 | { | 230 | { | ||
Show All 11 Lines | 240 | { | |||
241 | if (it != data.end() && it->count() == 3) { | 242 | if (it != data.end() && it->count() == 3) { | ||
242 | double n = 0.0; | 243 | double n = 0.0; | ||
243 | double d = 0.0; | 244 | double d = 0.0; | ||
244 | 245 | | |||
245 | n = (*it).toRational(0).first; | 246 | n = (*it).toRational(0).first; | ||
246 | d = (*it).toRational(0).second; | 247 | d = (*it).toRational(0).second; | ||
247 | 248 | | |||
248 | if (d == 0.0) { | 249 | if (d == 0.0) { | ||
249 | return 0.0; | 250 | return std::numeric_limits<double>::quiet_NaN(); | ||
250 | } | 251 | } | ||
251 | 252 | | |||
252 | double deg = n / d; | 253 | double deg = n / d; | ||
253 | 254 | | |||
254 | n = (*it).toRational(1).first; | 255 | n = (*it).toRational(1).first; | ||
255 | d = (*it).toRational(1).second; | 256 | d = (*it).toRational(1).second; | ||
256 | 257 | | |||
257 | if (d == 0.0) { | 258 | if (d == 0.0) { | ||
Show All 15 Lines | |||||
273 | double sec = n / d; | 274 | double sec = n / d; | ||
274 | if (sec != -1.0) { | 275 | if (sec != -1.0) { | ||
275 | deg += sec / 3600.0; | 276 | deg += sec / 3600.0; | ||
276 | } | 277 | } | ||
277 | 278 | | |||
278 | return deg; | 279 | return deg; | ||
279 | } | 280 | } | ||
280 | 281 | | |||
281 | return 0.0; | 282 | return std::numeric_limits<double>::quiet_NaN(); | ||
282 | } | 283 | } | ||
283 | 284 | | |||
284 | double Exiv2Extractor::fetchGpsAltitude(const Exiv2::ExifData& data) | 285 | double Exiv2Extractor::fetchGpsAltitude(const Exiv2::ExifData& data) | ||
285 | { | 286 | { | ||
286 | double alt = 0.0; | 287 | double alt = std::numeric_limits<double>::quiet_NaN(); | ||
287 | Exiv2::ExifData::const_iterator it = data.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSAltitude")); | 288 | Exiv2::ExifData::const_iterator it = data.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSAltitude")); | ||
288 | if (it != data.end()) { | 289 | if (it != data.end()) { | ||
289 | alt = it->value().toFloat(); | 290 | auto ratio = it->value().toRational(); | ||
290 | it = data.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSAltitudeRef")); | 291 | it = data.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSAltitudeRef")); | ||
291 | if (it != data.end()) { | 292 | if ((ratio.second != 0) && (it != data.end())) { | ||
292 | auto altRef = it->value().toLong(); | 293 | auto altRef = it->value().toLong(); | ||
293 | if (altRef) { | 294 | if (altRef) { | ||
294 | alt = alt * -1; | 295 | alt = -1.0 * ratio.first / ratio.second; | ||
296 | } else { | ||||
297 | alt = 1.0 * ratio.first / ratio.second; | ||||
295 | } | 298 | } | ||
296 | } | 299 | } | ||
297 | } | 300 | } | ||
bruns: when you rewrite this as
```
if (it != data.end()) {
auto ratio = it->value(). | |||||
astippich: Yes, it does | |||||
298 | return alt; | 301 | return alt; | ||
299 | } | 302 | } | ||
300 | 303 | | |||
301 | QByteArray Exiv2Extractor::fetchByteArray(const Exiv2::ExifData& data, const char* name) | 304 | QByteArray Exiv2Extractor::fetchByteArray(const Exiv2::ExifData& data, const char* name) | ||
302 | { | 305 | { | ||
303 | Exiv2::ExifData::const_iterator it = data.findKey(Exiv2::ExifKey(name)); | 306 | Exiv2::ExifData::const_iterator it = data.findKey(Exiv2::ExifKey(name)); | ||
304 | if (it != data.end()) { | 307 | if (it != data.end()) { | ||
305 | std::string str = it->value().toString(); | 308 | std::string str = it->value().toString(); | ||
306 | return QByteArray(str.c_str(), str.size()); | 309 | return QByteArray(str.c_str(), str.size()); | ||
307 | } | 310 | } | ||
308 | 311 | | |||
309 | return QByteArray(); | 312 | return QByteArray(); | ||
310 | } | 313 | } |
when you rewrite this as
does the unit test pass without special handling of the altitude fuzz?