Sample usage of high-level XMP classes.
#include <exiv2/exiv2.hpp>
#include <cassert>
#include <cmath>
#include <iostream>
bool isEqual(float a, float b) {
double d = std::fabs(a - b);
return d < 0.00001;
}
int main() try {
#ifdef EXV_ENABLE_BMFF
Exiv2::enableBMFF();
#endif
xmpData["Xmp.dc.source"] = "xmpsample.cpp";
xmpData["Xmp.dc.subject"] = "Palmtree";
xmpData["Xmp.dc.subject"] = "Rubbertree";
xmpData["Xmp.dc.title"] = "lang=de-DE Sonnenuntergang am Strand";
xmpData["Xmp.dc.title"] = "lang=en-US Sunset on the beach";
xmpData["Xmp.dc.one"] = -1;
xmpData["Xmp.dc.two"] = 3.1415;
xmpData["Xmp.dc.four"] = static_cast<uint16_t>(255);
xmpData["Xmp.dc.five"] = 256;
xmpData["Xmp.dc.six"] = false;
xmpData["Xmp.dc.seven"] = val;
xmpData["Xmp.dc.eight"] = true;
assert(xmpData["Xmp.dc.one"].toInt64() == -1);
assert(xmpData["Xmp.dc.one"].value().ok());
[[maybe_unused]]
const Exiv2::Value& getv1 = xmpData[
"Xmp.dc.one"].value();
assert(isEqual(getv1.
toFloat(), -1));
[[maybe_unused]]
const Exiv2::Value& getv2 = xmpData[
"Xmp.dc.two"].value();
assert(isEqual(getv2.
toFloat(), 3.1415f));
assert(isEqual(static_cast<float>(R.first) / R.second, 3.1415f));
[[maybe_unused]]
const Exiv2::Value& getv3 = xmpData[
"Xmp.dc.three"].value();
assert(isEqual(getv3.
toFloat(), 5.0f / 7.0f));
[[maybe_unused]]
const Exiv2::Value& getv6 = xmpData[
"Xmp.dc.six"].value();
const Exiv2::Value& getv7 = xmpData[
"Xmp.dc.seven"].value();
[[maybe_unused]]
const Exiv2::Value& getv8 = xmpData[
"Xmp.dc.eight"].value();
if (pos == xmpData.
end())
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Key not found");
v->read("image/jpeg");
v->read("1) The first creator");
v->read("2) The second creator");
v->read("3) And another one");
v->read("lang=de-DE Hallo, Welt");
v->read("Hello, World");
xmpData["Xmp.tiff.ImageDescription"] = "TIFF image description";
xmpData["Xmp.tiff.ImageDescription"] = "lang=de-DE TIFF Bildbeschreibung";
xmpData["Xmp.ns.myProperty"] = "myValue";
tv.read("9");
tv.read("inch");
xmpData["Xmp.dc.publisher"] = "James Bond";
xmpData["Xmp.dc.publisher[1]/?ns:role"] = "secret agent";
tv.read("programmer");
tv.read("");
tv.setXmpArrayType(Exiv2::XmpValue::xaBag);
tv.setXmpArrayType(Exiv2::XmpValue::xaNone);
tv.read("Birthday party");
tv.read("Photographer");
tv.read("Wedding ceremony");
tv.read("Best man");
xmpData["Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiAdrCity"] = "Kuala Lumpur";
xmpData["Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiAdrCtry"] = "Malaysia";
xmpData["Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiUrlWork"] = "http://www.exiv2.org";
for (auto&& md : xmpData) {
std::cout << std::setfill(' ') << std::left << std::setw(44) << md.key() << " " << std::setw(9) << std::setfill(' ')
<< std::left << md.typeName() << " " << std::dec << std::setw(3) << std::setfill(' ') << std::right
<< md.
count() <<
" " << std::dec << md.value() << std::endl;
}
std::string xmpPacket;
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
"Failed to serialize XMP data");
}
std::cout << xmpPacket << "\n";
return EXIT_SUCCESS;
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return EXIT_FAILURE;
}