Fix #381: Feature-Request: Make JPEG comment available for overlays
[geeqie.git] / src / exif.c
index fd7ac93..872b9cc 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- *  Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2003, 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
- *  Authors:
- *    Support for Exif file format, originally written by Eric Swalens.
- *    Modified by Quy Tonthat
+ * Authors: Eric Swalens, Quy Tonthat
  *
- *    Reimplemented with generic data storage by John Ellis (Nov 2003)
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  *  The tags were added with information from the FREE document:
  *     http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
  *        ComponentsConfiguration
  *        UserComment (convert this to UTF-8?)
  *     Add support for marker tag 0x0000
- *
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
@@ -73,6 +67,7 @@
 
 #include "main.h"
 #include "exif-int.h"
+#include "jpeg_parser.h"
 
 #include "format_raw.h"
 #include "ui_fileops.h"
@@ -1086,7 +1081,7 @@ static gint exif_jpeg_parse(ExifData *exif,
                return -2;
                }
 
-       if (exif_jpeg_segment_find(data, size, JPEG_MARKER_APP1,
+       if (jpeg_segment_find(data, size, JPEG_MARKER_APP1,
                                   "Exif\x00\x00", 6,
                                   &seg_offset, &seg_length))
                {
@@ -1110,6 +1105,18 @@ guchar *exif_get_color_profile(ExifData *exif, guint *data_len)
 }
 
 
+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
@@ -1280,11 +1287,6 @@ ExifData *exif_read(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp)
 
        if (exif) exif->items = g_list_reverse(exif->items);
 
-#if 0
-       exif_write_data_list(exif, stdout, TRUE);
-       exif_write_data_list(exif, stdout, FALSE);
-#endif
-
        return exif;
 }
 
@@ -1458,6 +1460,7 @@ gchar *exif_item_get_data_as_text(ExifItem *item)
 gint exif_item_get_integer(ExifItem *item, gint *value)
 {
        if (!item) return FALSE;
+       if (!item->elements) return FALSE;
 
        switch (item->format)
                {
@@ -1602,12 +1605,12 @@ GList *exif_get_metadata(ExifData *exif, const gchar *key, MetadataFormat format
 {
        gchar *str;
        ExifItem *item;
-       
+
        if (!key) return NULL;
-       
+
        /* convert xmp key to exif key */
        if (strcmp(key, "Xmp.tiff.Orientation") == 0) key = "Exif.Image.Orientation";
-       
+
        if (format == METADATA_FORMATTED)
                {
                gchar *text;
@@ -1618,11 +1621,11 @@ GList *exif_get_metadata(ExifData *exif, const gchar *key, MetadataFormat format
 
        item = exif_get_item(exif, key);
        if (!item) return NULL;
-       
+
        str = exif_item_get_data_as_text_full(item, format);
-       
+
        if (!str) return NULL;
-       
+
        return g_list_append(NULL, str);
 }
 
@@ -1644,13 +1647,13 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
        guchar *map_data;
        size_t map_len;
        int fd;
-       
+
        if (!exif) return NULL;
        path = exif->path;
 
        fd = open(path, O_RDONLY);
-               
-               
+
+
        if (fd == -1)
                {
                return 0;
@@ -1681,7 +1684,7 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
                ud->ptr = map_data + offset;
                ud->map_data = map_data;
                ud->map_len = map_len;
-               
+
                exif_unmap_list = g_list_prepend(exif_unmap_list, ud);
                return ud->ptr;
                }
@@ -1694,7 +1697,7 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 void exif_free_preview(guchar *buf)
 {
        GList *work = exif_unmap_list;
-       
+
        while (work)
                {
                UnmapData *ud = (UnmapData *)work->data;