Use exiv2 for metadata handling
This commit is contained in:
@@ -295,7 +295,36 @@ bool saveToKeyfile(
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const std::map<Glib::ustring, Glib::ustring> exif_keys = {
|
||||
{"Copyright", "Exif.Image.Copyright"},
|
||||
{"Artist", "Exif.Image.Artist"},
|
||||
{"ImageDescription", "Exif.Image.ImageDescription"},
|
||||
{"Exif.UserComment", "Exif.Photo.UserComment"}
|
||||
};
|
||||
|
||||
const std::map<Glib::ustring, Glib::ustring> iptc_keys = {
|
||||
{"Title", "Iptc.Application2.ObjectName"},
|
||||
{"Category", "Iptc.Application2.Category"},
|
||||
{"SupplementalCategories", "Iptc.Application2.SuppCategory"},
|
||||
{"Keywords", "Iptc.Application2.Keywords"},
|
||||
{"Instructions", "Iptc.Application2.SpecialInstructions"},
|
||||
{"DateCreated", "Iptc.Application2.DateCreated"},
|
||||
{"Creator", "Iptc.Application2.Byline"},
|
||||
{"CreatorJobTitle", "Iptc.Application2.BylineTitle"},
|
||||
{"City", "Iptc.Application2.City"},
|
||||
{"Province", "Iptc.Application2.ProvinceState"},
|
||||
{"Country", "Iptc.Application2.CountryName"},
|
||||
{"TransReference", "Iptc.Application2.TransmissionReference"},
|
||||
{"Headline", "Iptc.Application2.Headline"},
|
||||
{"Credit", "Iptc.Application2.Credit"},
|
||||
{"Source", "Iptc.Application2.Source"},
|
||||
{"Copyright", "Iptc.Application2.Copyright"},
|
||||
{"Caption", "Iptc.Application2.Caption"},
|
||||
{"CaptionWriter", "Iptc.Application2.Writer"}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace rtengine
|
||||
{
|
||||
@@ -3568,16 +3597,30 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo
|
||||
|
||||
// EXIF change list
|
||||
if (!pedited || pedited->exif) {
|
||||
std::map<Glib::ustring, Glib::ustring> m;
|
||||
for (auto &p : exif_keys) {
|
||||
m[p.second] = p.first;
|
||||
}
|
||||
for (ExifPairs::const_iterator i = exif.begin(); i != exif.end(); ++i) {
|
||||
keyFile.set_string("Exif", i->first, i->second);
|
||||
auto it = m.find(i->first);
|
||||
if (it != m.end()) {
|
||||
keyFile.set_string("Exif", it->second, i->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IPTC change list
|
||||
if (!pedited || pedited->iptc) {
|
||||
std::map<Glib::ustring, Glib::ustring> m;
|
||||
for (auto &p : iptc_keys) {
|
||||
m[p.second] = p.first;
|
||||
}
|
||||
for (IPTCPairs::const_iterator i = iptc.begin(); i != iptc.end(); ++i) {
|
||||
Glib::ArrayHandle<Glib::ustring> values = i->second;
|
||||
keyFile.set_string_list("IPTC", i->first, values);
|
||||
auto it = m.find(i->first);
|
||||
if (it != m.end()) {
|
||||
Glib::ArrayHandle<Glib::ustring> values = i->second;
|
||||
keyFile.set_string_list("IPTC", it->second, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5120,10 +5163,13 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited)
|
||||
|
||||
if (keyFile.has_group("Exif")) {
|
||||
for (const auto& key : keyFile.get_keys("Exif")) {
|
||||
exif[key] = keyFile.get_string("Exif", key);
|
||||
auto it = exif_keys.find(key);
|
||||
if (it != exif_keys.end()) {
|
||||
exif[it->second] = keyFile.get_string("Exif", key);
|
||||
|
||||
if (pedited) {
|
||||
pedited->exif = true;
|
||||
if (pedited) {
|
||||
pedited->exif = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5143,7 +5189,12 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited)
|
||||
if (keyFile.has_group("IPTC")) {
|
||||
for (const auto& key : keyFile.get_keys("IPTC")) {
|
||||
// does this key already exist?
|
||||
const IPTCPairs::iterator element = iptc.find(key);
|
||||
auto it = iptc_keys.find(key);
|
||||
if (it == iptc_keys.end()) {
|
||||
continue;
|
||||
}
|
||||
auto kk = it->second;
|
||||
const IPTCPairs::iterator element = iptc.find(kk);
|
||||
|
||||
if (element != iptc.end()) {
|
||||
// it already exist so we cleanup the values
|
||||
@@ -5152,7 +5203,7 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited)
|
||||
|
||||
// TODO: look out if merging Keywords and SupplementalCategories from the procparams chain would be interesting
|
||||
for (const auto& currLoadedTagValue : keyFile.get_string_list("IPTC", key)) {
|
||||
iptc[key].push_back(currLoadedTagValue);
|
||||
iptc[kk].push_back(currLoadedTagValue);
|
||||
}
|
||||
|
||||
if (pedited) {
|
||||
|
Reference in New Issue
Block a user