# HG changeset patch # User nadvornik # Date 1206367426 0 # Node ID 1a38eef1129a8b4118e01898320f54db37777079 # Parent 80d0701de0f9f29b89fffd715dd24f051e04e510 exiv2 version checks diff -r 80d0701de0f9 -r 1a38eef1129a src/exiv2.cc --- a/src/exiv2.cc Mon Mar 24 12:04:31 2008 +0000 +++ b/src/exiv2.cc Mon Mar 24 14:03:46 2008 +0000 @@ -9,6 +9,13 @@ #include #include +// 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 #include #include @@ -21,8 +28,12 @@ #include #include #include +#if EXIV2_TEST_VERSION(0,16,0) #include +#endif +#if EXIV2_TEST_VERSION(0,13,0) #include +#endif #include @@ -40,7 +51,9 @@ 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; @@ -50,7 +63,8 @@ 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()) { @@ -60,6 +74,7 @@ printf("sidecar xmp count %d\n", sidecar->xmpData().count()); } +#endif } void writeMetadata() @@ -78,11 +93,12 @@ return image->iptcData(); } +#if EXIV2_TEST_VERSION(0,16,0) Exiv2::XmpData &xmpData () { return have_sidecar ? sidecar->xmpData() : image->xmpData(); } - +#endif }; @@ -139,10 +155,12 @@ 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; @@ -173,11 +191,13 @@ 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; @@ -194,7 +214,9 @@ 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; @@ -207,12 +229,14 @@ 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; } @@ -237,12 +261,14 @@ 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) { @@ -382,7 +408,11 @@ 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=") { @@ -467,13 +497,14 @@ 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) { @@ -523,21 +554,30 @@ } 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 @@ -561,8 +601,11 @@ 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));