metadata: fixed bug in setting shutter speed in output jpgs

(cherry picked from commit b6a1a15a76c2091f6f940ae7d16d45caa93dbb99)
This commit is contained in:
Alberto Griggio 2021-06-22 23:59:47 -07:00 committed by Lawrence Lee
parent 77d1bc2cb1
commit a73e74f9cc
No known key found for this signature in database
GPG Key ID: 048FF2B76A63895F

View File

@ -695,11 +695,12 @@ std::string FramesMetaData::apertureToString(double aperture)
std::string FramesMetaData::shutterToString(double shutter)
{
char buffer[256];
if (shutter > 0.0 && shutter <= 0.5) {
snprintf(buffer, sizeof(buffer), "1/%0.0f", 1.0 / shutter);
} else if (int(shutter) == shutter) {
snprintf(buffer, sizeof(buffer), "%d", int(shutter));
} else {
snprintf(buffer, sizeof(buffer), "%0.1f", shutter);
}
@ -755,6 +756,9 @@ void set_exif(Exiv2::ExifData &exif, const std::string &key, T val)
try {
exif[key] = val;
} catch (std::exception &exc) {
if (settings->verbose) {
std::cout << "Exif -- error setting " << key << " to " << val << ": " << exc.what() << std::endl;
}
}
}
@ -768,7 +772,11 @@ void FramesData::fillBasicTags(Exiv2::ExifData &exif) const
set_exif(exif, "Exif.Photo.ISOSpeedRatings", getISOSpeed());
set_exif(exif, "Exif.Photo.FNumber", Exiv2::URationalValue(Exiv2::URational(round(getFNumber() * 10), 10)));
auto s = shutterToString(getShutterSpeed());
if (s.find('/') == std::string::npos) {
auto p = s.find('.');
if (p != std::string::npos) {
assert(p == s.length()-2);
s = s.substr(0, p) + s.substr(p+1) + "/10";
} else if (s.find('/') == std::string::npos) {
s += "/1";
}
set_exif(exif, "Exif.Photo.ExposureTime", s);