added fColorProfile pseudo-tag with detailed information
authorVladimir Nadvornik <nadvornik@suse.cz>
Sun, 20 Apr 2008 09:29:46 +0000 (09:29 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sun, 20 Apr 2008 09:29:46 +0000 (09:29 +0000)
src/bar_exif.c
src/exif-common.c

index 8636449..1c0f875 100644 (file)
@@ -41,7 +41,7 @@ ExifUI ExifUIList[]={
        { 0, 0, EXIF_UI_IFSET,  "Exif.Photo.ExposureProgram"},
        { 0, 0, EXIF_UI_IFSET,  "Exif.Photo.MeteringMode"},
        { 0, 0, EXIF_UI_IFSET,  "Exif.Photo.LightSource"},
-       { 0, 0, EXIF_UI_IFSET,  "Exif.Photo.ColorSpace"},
+       { 0, 0, EXIF_UI_IFSET,  "fColorProfile"},
        { 0, 0, EXIF_UI_IFSET,  "fSubjectDistance"},
        { 0, 0, EXIF_UI_IFSET,  "fResolution"},
        { 0, 0, EXIF_UI_IFSET,  "Exif.Image.Orientation"},
index 2293945..78c1987 100644 (file)
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <math.h>
+
+#ifdef HAVE_LCMS
+/*** color support enabled ***/
+
+#ifdef HAVE_LCMS_LCMS_H
+  #include <lcms/lcms.h>
+#else
+  #include <lcms.h>
+#endif
+#endif
+
 #include <glib.h>
 
 #include "intl.h"
@@ -43,6 +53,7 @@ ExifFormattedText ExifFormattedList[] = {
        { "fSubjectDistance",   N_("Subject distance") },
        { "fFlash",             N_("Flash") },
        { "fResolution",        N_("Resolution") },
+       { "fColorProfile",      N_("Color profile") },
        { NULL, NULL }
 };
 
@@ -372,6 +383,61 @@ do {                                    \
                g_free(units);
                return text;
                }
+       if (strcmp(key, "fColorProfile") == 0)
+               {
+               const gchar *name = "";
+               const gchar *source = "";
+               ExifItem *prof_item = exif_get_item(exif, "Exif.Image.InterColorProfile");
+               if (!prof_item)
+                       {
+                       gint cs;
+                       gchar *interop_index;
+
+                       /* ColorSpace == 1 specifies sRGB per EXIF 2.2 */
+                       if (!exif_get_integer(exif, "Exif.Photo.ColorSpace", &cs)) cs = 0;
+                       interop_index = exif_get_data_as_text(exif, "Exif.Iop.InteroperabilityIndex");                  
+                       
+                       if (cs == 1)
+                               {
+                               name = _("sRGB");
+                               source = "ColorSpace";
+                               }
+                       else if (cs == 2 || (interop_index && !strcmp(interop_index, "R03")))
+                               {
+                               name = _("AdobeRGB");
+                               source = (cs == 2) ? "ColorSpace" : "Iop";
+                               }
+                               
+                       g_free(interop_index);
+                       }
+
+               if (prof_item && exif_item_get_format_id(prof_item) == EXIF_FORMAT_UNDEFINED)
+                       {
+                       source = _("embedded");
+#ifdef HAVE_LCMS
+       
+                               {
+                               unsigned char *data;
+                               guint data_len;
+                               cmsHPROFILE profile;
+               
+                               data = (unsigned char *) exif_item_get_data(prof_item, &data_len);
+                               if (data)
+                                       {
+                                       profile = cmsOpenProfileFromMem(data, data_len);
+                                       if (profile)
+                                               {
+                                               name = cmsTakeProductName(profile);
+                                               cmsCloseProfile(profile);
+                                               }
+                                       g_free(data);
+                                       }
+                               }
+#endif
+                       }
+               if (name[0] == 0 && source[0] == 0) return NULL;
+               return g_strdup_printf("%s (%s)", name, source);
+               }
 
        if (key_valid) *key_valid = FALSE;
        return NULL;