fix build against exiv2-0.27.x
[geeqie.git] / src / exiv2.cc
index 1dbe118..2992740 100644 (file)
 
 #ifdef HAVE_EXIV2
 
-#include <exiv2/image.hpp>
-#include <exiv2/exif.hpp>
+// Don't include the <exiv2/version.hpp> file directly
+// Early Exiv2 versions didn't have version.hpp and the macros.
+#include <exiv2/exiv2.hpp>
 #include <iostream>
+#include <string>
 
 // EXIV2_TEST_VERSION is defined in Exiv2 0.15 and newer.
+#ifdef EXIV2_VERSION
 #ifndef EXIV2_TEST_VERSION
-# define EXIV2_TEST_VERSION(major,minor,patch) \
+#define EXIV2_TEST_VERSION(major,minor,patch) \
        ( EXIV2_VERSION >= EXIV2_MAKE_VERSION(major,minor,patch) )
 #endif
+#else
+#define EXIV2_TEST_VERSION(major,minor,patch) (false)
+#endif
 
+#if EXIV2_TEST_VERSION(0,27,0)
+#define HAVE_EXIV2_ERROR_CODE
+#endif
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 
-#if !EXIV2_TEST_VERSION(0,17,90)
-#include <exiv2/tiffparser.hpp>
-#include <exiv2/tiffcomposite.hpp>
-#include <exiv2/tiffvisitor.hpp>
-#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>
-#else
-#include <exiv2/preview.hpp>
-#endif
-
-#if EXIV2_TEST_VERSION(0,17,0)
-#include <exiv2/convert.hpp>
-#include <exiv2/xmpsidecar.hpp>
+#if EXIV2_TEST_VERSION(0,27,0)
+#define EXV_PACKAGE "exiv2"
 #endif
 
 extern "C" {
@@ -157,6 +147,10 @@ struct _ExifData
        virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) = 0;
 
        virtual guchar *get_jpeg_color_profile(guint *data_len) = 0;
+
+       virtual std::string image_comment() const = 0;
+
+       virtual void set_image_comment(const std::string& comment) = 0;
 };
 
 // This allows read-only access to the original metadata
@@ -279,6 +273,17 @@ public:
                }
                return NULL;
        }
+
+       virtual std::string image_comment() const
+       {
+               return image_.get() ? image_->comment() : "";
+       }
+
+       virtual void set_image_comment(const std::string& comment)
+       {
+               if (image_.get())
+                       image_->setComment(comment);
+       }
 };
 
 extern "C" {
@@ -358,7 +363,11 @@ public:
 #endif
                        Exiv2::Image *image = imageData_->image();
 
-                       if (!image) Exiv2::Error(21);
+#ifdef HAVE_EXIV2_ERROR_CODE
+                       if (!image) throw Exiv2::Error(Exiv2::ErrorCode::kerInputDataReadFailed);
+#else
+                       if (!image) throw Exiv2::Error(21);
+#endif
                        image->setExifData(exifData_);
                        image->setIptcData(iptcData_);
 #if EXIV2_TEST_VERSION(0,16,0)
@@ -377,8 +386,12 @@ public:
 
                        sidecar->setXmpData(xmpData_);
                        sidecar->writeMetadata();
+#else
+#ifdef HAVE_EXIV2_ERROR_CODE
+                       throw Exiv2::Error(Exiv2::ErrorCode::kerNotAnImage, "xmp");
 #else
                        throw Exiv2::Error(3, "xmp");
+#endif
 #endif
                        }
        }
@@ -414,6 +427,16 @@ public:
        {
                return imageData_->get_jpeg_color_profile(data_len);
        }
+
+       virtual std::string image_comment() const
+       {
+               return imageData_->image_comment();
+       }
+
+       virtual void set_image_comment(const std::string& comment)
+       {
+               imageData_->set_image_comment(comment);
+       }
 };
 
 
@@ -1132,6 +1155,23 @@ guchar *exif_get_color_profile(ExifData *exif, guint *data_len)
        return ret;
 }
 
+gchar* exif_get_image_comment(FileData* fd)
+{
+       if (!fd || !fd->exif)
+               return g_strdup("");
+
+       return g_strdup(fd->exif->image_comment().c_str());
+}
+
+void exif_set_image_comment(FileData* fd, const gchar* comment)
+{
+       if (!fd || !fd->exif)
+               return;
+
+       fd->exif->set_image_comment(comment ? comment : "");
+}
+
+
 #if EXIV2_TEST_VERSION(0,17,90)
 
 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height)
@@ -1140,8 +1180,9 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 
        if (!exif->image()) return NULL;
 
+       std::string const path = exif->image()->io().path();
        /* given image pathname, first do simple (and fast) file extension test */
-       gboolean is_raw = filter_file_class(exif->image()->io().path().c_str(), FORMAT_CLASS_RAWIMAGE);
+       gboolean is_raw = filter_file_class(path.c_str(), FORMAT_CLASS_RAWIMAGE);
 
        if (!is_raw && requested_width == 0) return NULL;
 
@@ -1241,10 +1282,10 @@ extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint reques
        if (!exif) return NULL;
        if (!exif->image()) return NULL;
 
-       const char* path = exif->image()->io().path().c_str();
+       std::string const path = exif->image()->io().path();
 
        /* given image pathname, first do simple (and fast) file extension test */
-       if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL;
+       if (!filter_file_class(path.c_str(), FORMAT_CLASS_RAWIMAGE)) return NULL;
 
        try {
                struct stat st;
@@ -1255,9 +1296,9 @@ extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint reques
 
                RawFile rf(exif->image()->io());
                offset = rf.preview_offset();
-               DEBUG_1("%s: offset %lu", path, offset);
+               DEBUG_1("%s: offset %lu", path.c_str(), offset);
 
-               fd = open(path, O_RDONLY);
+               fd = open(path.c_str(), O_RDONLY);
                if (fd == -1)
                        {
                        return NULL;