read also iptc and xmp
authorVladimir Nadvornik <nadvornik@suse.cz>
Fri, 15 Feb 2008 10:48:09 +0000 (10:48 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Fri, 15 Feb 2008 10:48:09 +0000 (10:48 +0000)
src/bar_exif.c
src/exif.c
src/exif.h
src/exiv2.cc

index 19bc921..e02579a 100644 (file)
@@ -240,7 +240,6 @@ static void bar_exif_update(ExifBar *eb)
                {
                GtkListStore *store;
                GtkTreeIter iter;
-               GList *work;
                ExifItem *item;
                
                store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(eb->listview)));
@@ -250,11 +249,11 @@ static void bar_exif_update(ExifBar *eb)
                while (item)
                        {
                        gchar *tag;
-                       const gchar *tag_name;
+                       gchar *tag_name;
                        gchar *text;
                        const gchar *format;
                        gchar *elements;
-                       const gchar *description;
+                       gchar *description;
 
                        tag = g_strdup_printf("0x%04x", exif_item_get_tag_id(item));
                        tag_name = exif_item_get_tag_name(item);
@@ -277,6 +276,7 @@ static void bar_exif_update(ExifBar *eb)
                        g_free(text);
                        g_free(elements);
                        g_free(description);
+                       g_free(tag_name);
                        item = exif_get_next_item(exif);
                        }
                }
index b03d9ff..53e647f 100644 (file)
@@ -494,7 +494,7 @@ static void exif_item_free(ExifItem *item)
 const char *exif_item_get_tag_name(ExifItem *item)
 {
        if (!item || !item->marker) return NULL;
-       return item->marker->key;
+       return g_strdup(item->marker->key);
 }
 
 guint exif_item_get_tag_id(ExifItem *item)
@@ -694,7 +694,9 @@ void exif_item_copy_data(ExifItem *item, void *src, guint len,
        if (!dest ||
            ExifFormatList[src_format].size * ne > len)
                {
-               printf("exif tag %s data size mismatch\n", exif_item_get_tag_name(item));
+               gchar *tag = exif_item_get_tag_name(item);
+               printf("exif tag %s data size mismatch\n", tag);
+               g_free(tag);
                return;
                }
 
@@ -1556,8 +1558,10 @@ static void exif_write_item(FILE *f, ExifItem *item)
        text = exif_item_get_data_as_text(item);
        if (text)
                {
+               gchar *tag = exif_item_get_tag_name(item);
                fprintf(f, "%4x %9s %30s %s\n", item->tag, ExifFormatList[item->format].short_name,
-                       exif_item_get_tag_name(item), text);
+                       tag, text);
+               g_free(tag);
                }
        g_free(text);
 }
index bca15d1..8e6ca1b 100644 (file)
@@ -118,7 +118,7 @@ ExifItem *exif_get_item(ExifData *exif, const gchar *key);
 ExifItem *exif_get_first_item(ExifData *exif);
 ExifItem *exif_get_next_item(ExifData *exif);
 
-const char *exif_item_get_tag_name(ExifItem *item);
+char *exif_item_get_tag_name(ExifItem *item);
 guint exif_item_get_tag_id(ExifItem *item);
 guint exif_item_get_elements(ExifItem *item);
 char *exif_item_get_data(ExifItem *item, guint *data_len);
index 273f8fc..6b82819 100644 (file)
@@ -19,7 +19,11 @@ extern "C" {
 struct _ExifData
 {
        Exiv2::ExifData exifData;
-       Exiv2::ExifData::const_iterator iter;
+       Exiv2::ExifData::const_iterator exifIter; /* for exif_get_next_item */
+       Exiv2::IptcData iptcData;
+       Exiv2::IptcData::const_iterator iptcIter; /* for exif_get_next_item */
+       Exiv2::XmpData xmpData;
+       Exiv2::XmpData::const_iterator xmpIter; /* for exif_get_next_item */
 
        _ExifData(gchar *path, gint parse_color_profile)
        {
@@ -27,6 +31,8 @@ struct _ExifData
                g_assert (image.get() != 0);
                image->readMetadata();
                exifData = image->exifData();
+               iptcData = image->iptcData();
+               xmpData = image->xmpData();
        }
 
 };
@@ -55,10 +61,27 @@ void exif_free(ExifData *exif)
 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
 {
        try {
-               Exiv2::ExifKey ekey(key);
-               Exiv2::ExifData::iterator pos = exif->exifData.findKey(ekey);
-               if (pos == exif->exifData.end()) return NULL;
-               Exiv2::Exifdatum *item = &*pos;
+               Exiv2::Metadatum *item;
+               try {
+                       Exiv2::ExifKey ekey(key);
+                       Exiv2::ExifData::iterator pos = exif->exifData.findKey(ekey);
+                       if (pos == exif->exifData.end()) return NULL;
+                       item = &*pos;
+               }
+               catch (Exiv2::AnyError& e) {
+                       try {
+                               Exiv2::IptcKey ekey(key);
+                               Exiv2::IptcData::iterator pos = exif->iptcData.findKey(ekey);
+                               if (pos == exif->iptcData.end()) return NULL;
+                               item = &*pos;
+                       }
+                       catch (Exiv2::AnyError& e) {
+                               Exiv2::XmpKey ekey(key);
+                               Exiv2::XmpData::iterator pos = exif->xmpData.findKey(ekey);
+                               if (pos == exif->xmpData.end()) return NULL;
+                               item = &*pos;
+                       }
+               }
                return (ExifItem *)item;
        }
        catch (Exiv2::AnyError& e) {
@@ -71,10 +94,29 @@ ExifItem *exif_get_item(ExifData *exif, const gchar *key)
 ExifItem *exif_get_first_item(ExifData *exif)
 {
        try {
-               exif->iter = exif->exifData.begin();
-               if (exif->iter == exif->exifData.end()) return NULL;
-               const Exiv2::Exifdatum *item = &*exif->iter;
-               return (ExifItem *)item;
+               exif->exifIter = exif->exifData.begin();
+               exif->iptcIter = exif->iptcData.begin();
+               exif->xmpIter = exif->xmpData.begin();
+               if (exif->exifIter != exif->exifData.end()) 
+                       {
+                       const Exiv2::Metadatum *item = &*exif->exifIter;
+                       exif->exifIter++;
+                       return (ExifItem *)item;
+                       }
+               if (exif->iptcIter != exif->iptcData.end()) 
+                       {
+                       const Exiv2::Metadatum *item = &*exif->iptcIter;
+                       exif->iptcIter++;
+                       return (ExifItem *)item;
+                       }
+               if (exif->xmpIter != exif->xmpData.end()) 
+                       {
+                       const Exiv2::Metadatum *item = &*exif->xmpIter;
+                       exif->xmpIter++;
+                       return (ExifItem *)item;
+                       }
+               return NULL;
+                       
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -85,10 +127,25 @@ ExifItem *exif_get_first_item(ExifData *exif)
 ExifItem *exif_get_next_item(ExifData *exif)
 {
        try {
-               exif->iter++;
-               if (exif->iter == exif->exifData.end()) return NULL;
-               const Exiv2::Exifdatum *item = &*exif->iter;
-               return (ExifItem *)item;
+               if (exif->exifIter != exif->exifData.end())
+                       {
+                       const Exiv2::Metadatum *item = &*exif->exifIter;
+                       exif->exifIter++;
+                       return (ExifItem *)item;
+               }
+               if (exif->iptcIter != exif->iptcData.end())
+                       {
+                       const Exiv2::Metadatum *item = &*exif->iptcIter;
+                       exif->iptcIter++;
+                       return (ExifItem *)item;
+               }
+               if (exif->xmpIter != exif->xmpData.end())
+                       {
+                       const Exiv2::Metadatum *item = &*exif->xmpIter;
+                       exif->xmpIter++;
+                       return (ExifItem *)item;
+               }
+               return NULL;
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -96,11 +153,11 @@ ExifItem *exif_get_next_item(ExifData *exif)
        }
 }
 
-const char *exif_item_get_tag_name(ExifItem *item)
+char *exif_item_get_tag_name(ExifItem *item)
 {
        try {
                if (!item) return NULL;
-               return ((Exiv2::Exifdatum *)item)->key().c_str();
+               return g_strdup(((Exiv2::Metadatum *)item)->key().c_str());
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -112,7 +169,7 @@ guint exif_item_get_tag_id(ExifItem *item)
 {
        try {
                if (!item) return 0;
-               return ((Exiv2::Exifdatum *)item)->tag();
+               return ((Exiv2::Metadatum *)item)->tag();
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -124,11 +181,11 @@ guint exif_item_get_elements(ExifItem *item)
 {
        try {
                if (!item) return 0;
-               return ((Exiv2::Exifdatum *)item)->count();
+               return ((Exiv2::Metadatum *)item)->count();
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
-               return NULL;
+               return 0;
        }
 }
 
@@ -140,10 +197,10 @@ char *exif_item_get_description(ExifItem *item)
 {
        try {
                if (!item) return NULL;
-               return g_strdup(((Exiv2::Exifdatum *)item)->tagLabel().c_str());
+               return g_strdup(((Exiv2::Metadatum *)item)->tagLabel().c_str());
        }
-       catch (Exiv2::AnyError& e) {
-               std::cout << "Caught Exiv2 exception '" << e << "'\n";
+       catch (std::exception& e) {
+//             std::cout << "Caught Exiv2 exception '" << e << "'\n";
                return NULL;
        }
 }
@@ -185,7 +242,7 @@ guint exif_item_get_format_id(ExifItem *item)
 {
        try {
                if (!item) return EXIF_FORMAT_UNKNOWN;
-               guint id = ((Exiv2::Exifdatum *)item)->typeId();
+               guint id = ((Exiv2::Metadatum *)item)->typeId();
                if (id >= (sizeof(format_id_trans_tbl) / sizeof(format_id_trans_tbl[0])) ) return EXIF_FORMAT_UNKNOWN;
                return format_id_trans_tbl[id];
        }
@@ -199,7 +256,7 @@ const char *exif_item_get_format_name(ExifItem *item, gint brief)
 {
        try {
                if (!item) return NULL;
-               return ((Exiv2::Exifdatum *)item)->typeName();
+               return ((Exiv2::Metadatum *)item)->typeName();
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -212,9 +269,10 @@ gchar *exif_item_get_data_as_text(ExifItem *item)
 {
        try {
                if (!item) return NULL;
-               std::stringstream str;
-               str << *((Exiv2::Exifdatum *)item);
-               return g_strdup(str.str().c_str());
+//             std::stringstream str;  // does not work with Exiv2::Metadatum because operator<< is not virtual
+//             str << *((Exiv2::Metadatum *)item);
+//             return g_strdup(str.str().c_str());
+               return g_strdup(((Exiv2::Metadatum *)item)->toString().c_str());
        }
        catch (Exiv2::AnyError& e) {
                return NULL;
@@ -226,7 +284,7 @@ gint exif_item_get_integer(ExifItem *item, gint *value)
 {
        try {
                if (!item) return 0;
-               return ((Exiv2::Exifdatum *)item)->toLong();
+               return ((Exiv2::Metadatum *)item)->toLong();
        }
        catch (Exiv2::AnyError& e) {
                std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -238,7 +296,7 @@ ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
 {
        try {
                if (!item) return NULL;
-               Exiv2::Rational v = ((Exiv2::Exifdatum *)item)->toRational();
+               Exiv2::Rational v = ((Exiv2::Metadatum *)item)->toRational();
                static ExifRational ret;
                ret.num = v.first;
                ret.den = v.second;