#include <exiv2/exif.hpp>
#include <iostream>
+// EXIV2_TEST_VERSION is defined in Exiv2 0.15 and newer.
+#ifndef EXIV2_TEST_VERSION
+# define EXIV2_TEST_VERSION(major,minor,patch) \
+ ( EXIV2_VERSION >= EXIV2_MAKE_VERSION(major,minor,patch) )
+#endif
+
+
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <exiv2/tiffimage.hpp>
#include <exiv2/cr2image.hpp>
#include <exiv2/crwimage.hpp>
+#if EXIV2_TEST_VERSION(0,16,0)
#include <exiv2/orfimage.hpp>
+#endif
+#if EXIV2_TEST_VERSION(0,13,0)
#include <exiv2/rafimage.hpp>
+#endif
#include <exiv2/futils.hpp>
Exiv2::Image::AutoPtr sidecar;
Exiv2::ExifData::const_iterator exifIter; /* for exif_get_next_item */
Exiv2::IptcData::const_iterator iptcIter; /* for exif_get_next_item */
+#if EXIV2_TEST_VERSION(0,16,0)
Exiv2::XmpData::const_iterator xmpIter; /* for exif_get_next_item */
+#endif
bool have_sidecar;
image = Exiv2::ImageFactory::open(path);
// g_assert (image.get() != 0);
image->readMetadata();
-
+
+#if EXIV2_TEST_VERSION(0,16,0)
printf("xmp count %d\n", image->xmpData().count());
if (sidecar_path && image->xmpData().empty())
{
printf("sidecar xmp count %d\n", sidecar->xmpData().count());
}
+#endif
}
void writeMetadata()
return image->iptcData();
}
+#if EXIV2_TEST_VERSION(0,16,0)
Exiv2::XmpData &xmpData ()
{
return have_sidecar ? sidecar->xmpData() : image->xmpData();
}
-
+#endif
};
item = &*pos;
}
catch (Exiv2::AnyError& e) {
+#if EXIV2_TEST_VERSION(0,16,0)
Exiv2::XmpKey ekey(key);
Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey);
if (pos == exif->xmpData().end()) return NULL;
item = &*pos;
+#endif
}
}
return (ExifItem *)item;
item = &*pos;
}
catch (Exiv2::AnyError& e) {
+#if EXIV2_TEST_VERSION(0,16,0)
Exiv2::XmpKey ekey(key);
exif->xmpData().add(ekey, NULL);
Exiv2::XmpData::iterator pos = exif->xmpData().end();
pos--;
item = &*pos;
+#endif
}
}
return (ExifItem *)item;
try {
exif->exifIter = exif->exifData().begin();
exif->iptcIter = exif->iptcData().begin();
+#if EXIV2_TEST_VERSION(0,16,0)
exif->xmpIter = exif->xmpData().begin();
+#endif
if (exif->exifIter != exif->exifData().end())
{
const Exiv2::Metadatum *item = &*exif->exifIter;
exif->iptcIter++;
return (ExifItem *)item;
}
+#if EXIV2_TEST_VERSION(0,16,0)
if (exif->xmpIter != exif->xmpData().end())
{
const Exiv2::Metadatum *item = &*exif->xmpIter;
exif->xmpIter++;
return (ExifItem *)item;
}
+#endif
return NULL;
}
exif->iptcIter++;
return (ExifItem *)item;
}
+#if EXIV2_TEST_VERSION(0,16,0)
if (exif->xmpIter != exif->xmpData().end())
{
const Exiv2::Metadatum *item = &*exif->xmpIter;
exif->xmpIter++;
return (ExifItem *)item;
}
+#endif
return NULL;
}
catch (Exiv2::AnyError& e) {
try {
if (!item) return NULL;
Exiv2::Metadatum *em = (Exiv2::Metadatum *)item;
+#if EXIV2_TEST_VERSION(0,16,0)
std::string str = em->toString(idx);
+#else
+ std::string str = em->toString(); // FIXME
+#endif
if (idx == 0 && str == "") str = em->toString();
if (str.length() > 5 && str.substr(0, 5) == "lang=")
{
return 1;
}
}
+#if EXIV2_TEST_VERSION(0,16,0)
for (Exiv2::XmpData::iterator i = exif->xmpData().begin(); i != exif->xmpData().end(); ++i) {
if (((Exiv2::Metadatum *)item) == &*i) {
i = exif->xmpData().erase(i);
return 1;
}
}
-
+#endif
return 0;
}
catch (Exiv2::AnyError& e) {
}
type = Exiv2::ImageFactory::getType(map_data, map_len);
+#if EXIV2_TEST_VERSION(0,16,0)
TiffHeaderBase *tiffHeader;
+#else
+ TiffHeade2 *tiffHeader;
+#endif
switch (type) {
case Exiv2::ImageType::tiff:
tiffHeader = new TiffHeade2();
break;
+#if EXIV2_TEST_VERSION(0,16,0)
+
case Exiv2::ImageType::cr2:
tiffHeader = new Cr2Header();
break;
case Exiv2::ImageType::orf:
tiffHeader = new OrfHeader();
break;
+#endif
+#if EXIV2_TEST_VERSION(0,13,0)
case Exiv2::ImageType::raf:
if (map_len < 84 + 4) throw Error(14);
offset = getULong(map_data + 84, bigEndian);
return;
+#endif
case Exiv2::ImageType::crw:
{
// Parse the image, starting with a CIFF header component
if (0 == rootDir.get()) {
throw Error(1, "No root element defined in TIFF structure");
}
+#if EXIV2_TEST_VERSION(0,16,0)
rootDir->setStart(map_data + tiffHeader->offset());
-
+#else
+ rootDir->setStart(map_data + tiffHeader->ifdOffset());
+#endif
TiffRwState::AutoPtr state(
new TiffRwState(tiffHeader->byteOrder(), 0, createFct));