changeset 2490:a1b125f07ead

Fix #381: Feature-Request: Make JPEG comment available for overlays https://github.com/BestImageViewer/geeqie/issues/381 Additional tag "imagecomment" for JPEG comments
author Alexander Antimonov <>
date Mon, 29 May 2017 12:06:13 +0100
parents ab6a0d1bd821
children 5523c5ce8551
files doc/docbook/GuideOptionsWindow.xml src/exif.c src/exif.h src/exiv2.cc src/image-overlay.c
diffstat 5 files changed, 67 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/docbook/GuideOptionsWindow.xml	Sun May 28 19:30:41 2017 +0100
+++ b/doc/docbook/GuideOptionsWindow.xml	Mon May 29 12:06:13 2017 +0100
@@ -180,7 +180,11 @@
           </row>
           <row>
             <entry>comment</entry>
-            <entry>Image comment from metadata</entry>
+            <entry>Image comment from XMP metadata</entry>
+          </row>
+          <row>
+            <entry>imagecomment</entry>
+            <entry>JPEG image comment</entry>
           </row>
           <row>
             <entry>&lt;meta_tag&gt;</entry>
--- a/src/exif.c	Sun May 28 19:30:41 2017 +0100
+++ b/src/exif.c	Mon May 29 12:06:13 2017 +0100
@@ -1105,6 +1105,18 @@
 }
 
 
+gchar* exif_get_image_comment(FileData* fd)
+{
+	log_printf("%s", _("Can't get image comment: not compiled with Exiv2.\n"));
+	return g_strdup("");
+}
+
+void exif_set_image_comment(FileData* fd, const gchar* comment)
+{
+	log_printf("%s", _("Can't set image comment: not compiled with Exiv2.\n"));
+}
+
+
 /*
  *-------------------------------------------------------------------
  * misc
--- a/src/exif.h	Sun May 28 19:30:41 2017 +0100
+++ b/src/exif.h	Mon May 29 12:06:13 2017 +0100
@@ -158,6 +158,10 @@
 
 gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size);
 
+/* support for so called "jpeg comment" */
+gchar* exif_get_image_comment(FileData* fd);
+void exif_set_image_comment(FileData* fd, const gchar* comment);
+
 /*raw support */
 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height);
 void exif_free_preview(guchar *buf);
--- a/src/exiv2.cc	Sun May 28 19:30:41 2017 +0100
+++ b/src/exiv2.cc	Mon May 29 12:06:13 2017 +0100
@@ -158,6 +158,10 @@
 	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
@@ -280,6 +284,17 @@
 		}
 		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" {
@@ -415,6 +430,16 @@
 	{
 		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);
+	}
 };
 
 
@@ -1133,6 +1158,23 @@
 	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)
--- a/src/image-overlay.c	Sun May 28 19:30:41 2017 +0100
+++ b/src/image-overlay.c	Mon May 29 12:06:13 2017 +0100
@@ -336,6 +336,10 @@
 			{
 			data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
 			}
+		else if (strcmp(name, "imagecomment") == 0)
+			{
+			data = exif_get_image_comment(imd->image_fd);
+			}
 #ifdef HAVE_LUA
 		else if (strncmp(name, "lua/", 4) == 0)
 			{