Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / exif-common.c
index 1479909..155898e 100644 (file)
@@ -1,9 +1,21 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
-*/
+ * 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.
+ */
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
 #ifdef HAVE_LCMS
 /*** color support enabled ***/
 
-#ifdef HAVE_LCMS_LCMS_H
-  #include <lcms/lcms.h>
+#ifdef HAVE_LCMS2
+#include <lcms2.h>
 #else
-  #include <lcms.h>
+#include <lcms.h>
 #endif
 #endif
 
@@ -125,13 +137,13 @@ static gdouble get_crop_factor(ExifData *exif)
 static gboolean remove_suffix(gchar *str, const gchar *suffix, gint suffix_len)
 {
        gint str_len = strlen(str);
-       
+
        if (suffix_len < 0) suffix_len = strlen(suffix);
        if (str_len < suffix_len) return FALSE;
-       
+
        if (strcmp(str + str_len - suffix_len, suffix) != 0) return FALSE;
        str[str_len - suffix_len] = '\0';
-       
+
        return TRUE;
 }
 
@@ -161,7 +173,7 @@ static gchar *exif_build_formatted_Camera(ExifData *exif)
                gint i, j;
 
                g_strstrip(software);
-               
+
                /* remove superfluous spaces (pentax K100D) */
                for (i = 0, j = 0; software[i]; i++, j++)
                        {
@@ -413,6 +425,9 @@ static gchar *exif_build_formatted_Resolution(ExifData *exif)
 
 static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
 {
+#ifdef HAVE_LCMS2
+       cmsUInt8Number profileID[17];
+#endif
        const gchar *name = "";
        const gchar *source = "";
        guchar *profile_data;
@@ -452,7 +467,13 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
                        profile = cmsOpenProfileFromMem(profile_data, profile_len);
                        if (profile)
                                {
-                               name = cmsTakeProductName(profile);
+#ifdef HAVE_LCMS2
+                               profileID[16] = '\0';
+                               cmsGetHeaderProfileID(profile, profileID);
+                               name = (gchar *) profileID;
+#else
+                               name = (gchar *) cmsTakeProductName(profile);
+#endif
                                cmsCloseProfile(profile);
                                }
                        g_free(profile_data);
@@ -639,21 +660,21 @@ void exif_release_cb(FileData *fd)
 
 void exif_init_cache(void)
 {
-       assert(!exif_cache);
+       g_assert(!exif_cache);
        exif_cache = file_cache_new(exif_release_cb, 4);
 }
 
 ExifData *exif_read_fd(FileData *fd)
 {
        gchar *sidecar_path;
-       
+
        if (!exif_cache) exif_init_cache();
 
-       if (!fd || !is_readable_file(fd->path)) return NULL;
-       
+       if (!fd) return NULL;
+
        if (file_cache_get(exif_cache, fd)) return fd->exif;
        g_assert(fd->exif == NULL);
-       
+
        /* CACHE_TYPE_XMP_METADATA file should exist only if the metadata are
         * not writable directly, thus it should contain the most up-to-date version */
        sidecar_path = NULL;
@@ -668,6 +689,7 @@ ExifData *exif_read_fd(FileData *fd)
        fd->exif = exif_read(fd->path, sidecar_path, fd->modified_xmp);
 
        g_free(sidecar_path);
+       file_cache_put(exif_cache, fd, 1);
        return fd->exif;
 }
 
@@ -676,8 +698,6 @@ void exif_free_fd(FileData *fd, ExifData *exif)
 {
        if (!fd) return;
        g_assert(fd->exif == exif);
-       
-       file_cache_put(exif_cache, fd, 1);
 }
 
 /* embedded icc in jpeg */