changeset 185:354da67a7ca2

read also iptc and xmp
author nadvornik
date Fri, 15 Feb 2008 10:48:09 +0000
parents 2507418ab7a2
children bd3fc1aa7fe9
files src/bar_exif.c src/exif.c src/exif.h src/exiv2.cc
diffstat 4 files changed, 97 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_exif.c	Thu Feb 14 14:04:43 2008 +0000
+++ b/src/bar_exif.c	Fri Feb 15 10:48:09 2008 +0000
@@ -240,7 +240,6 @@
 		{
 		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 @@
 		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 @@
 			g_free(text);
 			g_free(elements);
 			g_free(description);
+			g_free(tag_name);
 			item = exif_get_next_item(exif);
 			}
 		}
--- a/src/exif.c	Thu Feb 14 14:04:43 2008 +0000
+++ b/src/exif.c	Fri Feb 15 10:48:09 2008 +0000
@@ -494,7 +494,7 @@
 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 @@
 	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 @@
 	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);
 }
--- a/src/exif.h	Thu Feb 14 14:04:43 2008 +0000
+++ b/src/exif.h	Fri Feb 15 10:48:09 2008 +0000
@@ -118,7 +118,7 @@
 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);
--- a/src/exiv2.cc	Thu Feb 14 14:04:43 2008 +0000
+++ b/src/exiv2.cc	Fri Feb 15 10:48:09 2008 +0000
@@ -19,7 +19,11 @@
 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 @@
 		g_assert (image.get() != 0);
 		image->readMetadata();
 		exifData = image->exifData();
+		iptcData = image->iptcData();
+		xmpData = image->xmpData();
 	}
 
 };
@@ -55,10 +61,27 @@
 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_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_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 @@
 	}
 }
 
-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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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 @@
 {
 	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;