From 37a37e91ca0276e5dbb2864ede644d71e5687a7e Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 7 Apr 2009 17:45:18 +0200 Subject: factor out gpsSetCoordinate() --- src/ImageMetaData.cxx | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx index 19d9e27..902425a 100644 --- a/src/ImageMetaData.cxx +++ b/src/ImageMetaData.cxx @@ -72,6 +72,21 @@ ImageMetaData::save_image(char *in_img, char *out_img) { return save_image_jpgcom(in_img, out_img); } +static void +gpsSetCoordinate(double *destVal, Exiv2::ExifData *exifData, const char *name) { + Exiv2::ExifKey key(name); + Exiv2::ExifData::iterator pos = exifData->findKey(key); + + if (pos != exifData->end()) { + if (pos->toFloat() >= 0) + *destVal = pos->toFloat(); + if (pos->toFloat(1) >= 0) + *destVal += pos->toFloat(1) / 60; + if (pos->toFloat(2) >= 0) + *destVal += pos->toFloat(2) / 3600; + } +} + int ImageMetaData::load_image_exif(char *name) { Exiv2::Image::AutoPtr image; @@ -120,31 +135,11 @@ ImageMetaData::load_image_exif(char *name) { _focal_length_35mm = pos->toFloat(); } - if (isnan(_longitude)) { - Exiv2::ExifKey key("Exif.GPSInfo.GPSLongitude"); - pos = exifData.findKey(key); - if (pos != exifData.end()) { - if ( pos->toFloat() >= 0) - _longitude = pos->toFloat(); - if ( pos->toFloat(1) >= 0) - _longitude += pos->toFloat(1) / 60; - if ( pos->toFloat(2) >= 0) - _longitude += pos->toFloat(2) / 3600; - } - } + if (isnan(_longitude)) + gpsSetCoordinate(&_longitude, &exifData, "Exif.GPSInfo.GPSLongitude"); - if (isnan(_latitude)) { - Exiv2::ExifKey key("Exif.GPSInfo.GPSLatitude"); - pos = exifData.findKey(key); - if (pos != exifData.end()) { - if ( pos->toFloat() >= 0) - _latitude = pos->toFloat(); - if ( pos->toFloat(1) >= 0) - _latitude += pos->toFloat(1) / 60; - if ( pos->toFloat(2) >= 0) - _latitude += pos->toFloat(2) / 3600; - } - } + if (isnan(_latitude)) + gpsSetCoordinate(&_longitude, &exifData, "Exif.GPSInfo.GPSLatitude"); if (isnan(_height)) { Exiv2::ExifKey key("Exif.GPSInfo.GPSAltitude"); -- cgit v1.2.3