refactored code for extracting image dimensions from metadata

(cherry picked from commit 0ece9c5bfad09bc9052238d83fa696ef39effaaa)
This commit is contained in:
Alberto Griggio
2020-12-02 02:03:00 -08:00
committed by Lawrence Lee
parent 0102fca563
commit 92befa7e81
13 changed files with 146 additions and 21 deletions

View File

@@ -448,6 +448,29 @@ void Exiv2Metadata::setExifKeys(const std::vector<std::string> *keys)
}
void Exiv2Metadata::getDimensions(int &w, int &h) const
{
if (image_) {
if (dynamic_cast<const Exiv2::XmpSidecar *>(image_.get())) {
auto &exif = image_->exifData();
auto itw = exif.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"));
auto ith = exif.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"));
if (itw != exif.end() && ith != exif.end()) {
w = itw->toLong();
h = ith->toLong();
} else {
w = h = -1;
}
} else {
w = image_->pixelWidth();
h = image_->pixelHeight();
}
} else {
w = h = -1;
}
}
Glib::ustring Exiv2Metadata::xmpSidecarPath(const Glib::ustring &path)
{
Glib::ustring fn = path;