Fix #381: Feature-Request: Make JPEG comment available for overlays
[geeqie.git] / src / exiv2.cc
index 1dbe118..0ad5c61 100644 (file)
@@ -25,6 +25,7 @@
 #include <exiv2/image.hpp>
 #include <exiv2/exif.hpp>
 #include <iostream>
+#include <string>
 
 // EXIV2_TEST_VERSION is defined in Exiv2 0.15 and newer.
 #ifndef EXIV2_TEST_VERSION
@@ -157,6 +158,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 +284,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" {
@@ -414,6 +430,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 +1158,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 +1183,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 +1285,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 +1299,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;