From f23dc54b9c7a4248e7aa1d77dbce4674bb9ab3dc Mon Sep 17 00:00:00 2001 From: draekko Date: Mon, 29 May 2017 12:13:04 -0400 Subject: [PATCH] Adding xmpprint sample --- samples/CMakeLists.txt | 1 + samples/Makefile | 1 + samples/xmpprint.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 samples/xmpprint.cpp diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 9690aa0e..bc88be9e 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -36,6 +36,7 @@ SET( SAMPLES addmoddel.cpp write2-test.cpp xmpparse.cpp xmpparser-test.cpp + xmpprint.cpp xmpsample.cpp ) diff --git a/samples/Makefile b/samples/Makefile index 8c4c17c8..1ad6364d 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -80,6 +80,7 @@ BINSRC = addmoddel.cpp \ write2-test.cpp \ xmpparse.cpp \ xmpparser-test.cpp \ + xmpprint.cpp \ xmpsample.cpp # Samples that need special treatment during compilation or linking diff --git a/samples/xmpprint.cpp b/samples/xmpprint.cpp new file mode 100644 index 00000000..e321ef42 --- /dev/null +++ b/samples/xmpprint.cpp @@ -0,0 +1,69 @@ +// ***************************************************************** -*- C++ -*- +// xmpprint.cpp, $Rev$ +// Read an XMP from a video or graphic file, parse it and print +// all (known) properties. +// ======================================================================== +// Linux standalone compilation : +// g++ -o xmprint xmprint.cpp `pkg-config --cflags --libs exiv2` +// ======================================================================== + +#include + +#include +#include +#include +#include + +int main(int argc, char** argv) +{ +try + { + if (argc != 2) + { + std::cout << "Usage: " << argv[0] << " file\n"; + return 1; + } + + Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); + assert (image.get() != 0); + image->readMetadata(); + + Exiv2::XmpData &xmpData = image->xmpData(); + if (xmpData.empty()) { + std::string error(argv[1]); + error += ": No XMP data found in the file"; + throw Exiv2::Error(1, error); + } + if (xmpData.empty()) + { + std::string error(argv[1]); + error += ": No XMP properties found in the XMP packet"; + throw Exiv2::Error(1, error); + } + + for (Exiv2::XmpData::const_iterator md = xmpData.begin(); + md != xmpData.end(); ++md) + { + 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; + } + + Exiv2::XmpParser::terminate(); + + return 0; + } +catch (Exiv2::AnyError& e) + { + std::cout << "Caught Exiv2 exception '" << e << "'\n"; + return -1; + } +} +