From 2a41b2475e0a00ef6878f5f91c4b2c1109c4bad8 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Sat, 30 Sep 2006 07:55:12 +0000 Subject: [PATCH] Added pretty-print function for GPSTimeStamp --- src/tags.cpp | 31 ++++++++++++++++++++++++++++++- src/tags.hpp | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/tags.cpp b/src/tags.cpp index 3a070a8b..1ad2aaa2 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -528,7 +528,7 @@ namespace Exiv2 { TagInfo(0x0004, "GPSLongitude", "GPSLongitude", "Longitude", gpsIfdId, gpsTags, unsignedRational, printDegrees), TagInfo(0x0005, "GPSAltitudeRef", "GPSAltitudeRef", "Altitude reference", gpsIfdId, gpsTags, unsignedByte, EXV_PRINT_TAG(exifGPSAltitudeRef)), TagInfo(0x0006, "GPSAltitude", "GPSAltitude", "Altitude", gpsIfdId, gpsTags, unsignedRational, print0x0006), - TagInfo(0x0007, "GPSTimeStamp", "GPSTimeStamp", "GPS time (atomic clock)", gpsIfdId, gpsTags, unsignedRational, printValue), + TagInfo(0x0007, "GPSTimeStamp", "GPSTimeStamp", "GPS time (atomic clock)", gpsIfdId, gpsTags, unsignedRational, print0x0007), TagInfo(0x0008, "GPSSatellites", "GPSSatellites", "GPS satellites used for measurement", gpsIfdId, gpsTags, asciiString, printValue), TagInfo(0x0009, "GPSStatus", "GPSStatus", "GPS receiver status", gpsIfdId, gpsTags, asciiString, printValue), TagInfo(0x000a, "GPSMeasureMode", "GPSMeasureMode", "GPS measurement mode", gpsIfdId, gpsTags, asciiString, printValue), @@ -1087,6 +1087,35 @@ namespace Exiv2 { return os; } + std::ostream& print0x0007(std::ostream& os, const Value& value) + { + if (value.count() == 3) { + std::ostringstream oss; + oss.copyfmt(os); + const float sec = 3600 * value.toFloat(0) + + 60 * value.toFloat(1) + + value.toFloat(2); + int p = 0; + if (sec != static_cast(sec)) p = 1; + + const int hh = static_cast(sec / 3600); + const int mm = static_cast((sec - 3600 * hh) / 60); + const float ss = sec - 3600 * hh - 60 * mm; + + os << std::setw(2) << std::setfill('0') << std::right << hh << ":" + << std::setw(2) << std::setfill('0') << std::right << mm << ":" + << std::setw(2 + p * 2) << std::setfill('0') << std::right + << std::fixed << std::setprecision(p) << ss; + + os.copyfmt(oss); + } + else { + os << value; + } + + return os; + } + std::ostream& print0x8298(std::ostream& os, const Value& value) { // Print the copyright information in the format Photographer, Editor diff --git a/src/tags.hpp b/src/tags.hpp index cdf90a8d..3ac89118 100644 --- a/src/tags.hpp +++ b/src/tags.hpp @@ -437,6 +437,8 @@ namespace Exiv2 { //! Print GPS altitude std::ostream& print0x0006(std::ostream& os, const Value& value); + //! Print GPS timestamp + std::ostream& print0x0007(std::ostream& os, const Value& value); //! Print the copyright std::ostream& print0x8298(std::ostream& os, const Value& value); //! Print the exposure time