gthumb r2178 - in trunk: . libgthumb src



Author: mjc
Date: Fri Jan 11 14:03:01 2008
New Revision: 2178
URL: http://svn.gnome.org/viewvc/gthumb?rev=2178&view=rev

Log:
2008-01-11  Michael J. Chudobiak  <mjc svn gnome org>

        * configure.in:
        * libgthumb/Makefile.am:
        * libgthumb/gth-exif-utils.c: (gth_read_exiv2):
        * libgthumb/gth-exif-utils.h:
        * libgthumb/gth-exiv2-utils.cpp:
        * libgthumb/gth-exiv2-utils.hpp:
        * src/gth-exif-data-viewer.c: (update_metadata):
        Added XMP sidecar support to the exiv2 code. Removed exempi library,
        as exiv2 provides everything we need now.



Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/libgthumb/Makefile.am
   trunk/libgthumb/gth-exif-utils.c
   trunk/libgthumb/gth-exif-utils.h
   trunk/libgthumb/gth-exiv2-utils.cpp
   trunk/libgthumb/gth-exiv2-utils.hpp
   trunk/src/gth-exif-data-viewer.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Jan 11 14:03:01 2008
@@ -35,7 +35,6 @@
 LIBGPHOTO_REQUIRED=2.1.3
 BONOBO_REQUIRED=2.6.0
 LIBOPENRAW_REQUIRED=0.0.2
-EXEMPI_REQUIRED=1.99.2
 EXIV2_REQUIRED=0.16
 GSTREAMER_REQUIRED=0.10.0
 
@@ -52,7 +51,6 @@
 AC_SUBST(LIBGPHOTO_REQUIRED)
 AC_SUBST(BONOBO_REQUIRED)
 AC_SUBST(LIBOPENRAW_REQUIRED)
-AC_SUBST(EXEMPI_REQUIRED)
 AC_SUBST(EXIV2_REQUIRED)
 AC_SUBST(GSTREAMER_REQUIRED)
 
@@ -249,21 +247,6 @@
 
 
 #
-# check for exempi
-#
-AC_ARG_ENABLE([xmp],
-              [AC_HELP_STRING([--disable-xmp], [Disable XMP extraction])],,
-              [enable_xmp=yes])
-HAVE_EXEMPI=no
-if test "x$enable_xmp" = "xyes"; then
-   PKG_CHECK_MODULES(EXEMPI, exempi-2.0 >= $EXEMPI_REQUIRED,
-                     [AC_DEFINE(HAVE_EXEMPI, 1, [Define to 1 to enable XMP support])
-                      HAVE_EXEMPI=yes],
-                     [HAVE_EXEMPI=no])
-fi
-
-
-#
 # check for exiv2
 #
 AC_ARG_ENABLE([exiv2],
@@ -416,7 +399,6 @@
 	Have libtiff:             ${HAVE_TIFF}
 	Have libgphoto:           ${HAVE_GPHOTO2}
 	Have libopenraw:          ${HAVE_LIBOPENRAW}
-	Have exempi:              ${HAVE_EXEMPI}
 	Have exiv2:               ${HAVE_EXIV2}
 	Have gstreamer:           ${HAVE_GSTREAMER}
 

Modified: trunk/libgthumb/Makefile.am
==============================================================================
--- trunk/libgthumb/Makefile.am	(original)
+++ trunk/libgthumb/Makefile.am	Fri Jan 11 14:03:01 2008
@@ -15,8 +15,7 @@
 	-DGTHUMB_MODULEDIR=\""$(libdir)/gthumb/modules"\"	\
 	-DGTHUMB_GLADEDIR=\""$(gladedir)"\"			\
 	$(LIBOPENRAW_CFLAGS)                                    \
-	$(EXEMPI_CFLAGS)					\
-	$(EXIV2_CFLAGS)					\
+	$(EXIV2_CFLAGS)						\
 	$(GSTREAMER_CFLAGS)					\
 	$(DISABLE_DEPRECATED)
 
@@ -147,7 +146,6 @@
 	$(GTHUMB_LIBS)		\
 	$(IPTCDATA_LIBS)	\
 	$(LIBOPENRAW_LIBS)      \
-	$(EXEMPI_LIBS)		\
 	$(EXIV2_LIBS)		\
 	$(GSTREAMER_LIBS)
 

Modified: trunk/libgthumb/gth-exif-utils.c
==============================================================================
--- trunk/libgthumb/gth-exif-utils.c	(original)
+++ trunk/libgthumb/gth-exif-utils.c	Fri Jan 11 14:03:01 2008
@@ -32,11 +32,6 @@
 #include "gth-exif-utils.h"
 #include "glib-utils.h"
 
-#ifdef HAVE_EXEMPI
-#include <exempi/xmp.h>
-#include <exempi/xmpconsts.h>
-#endif
-
 
 ExifData *
 gth_exif_data_new_from_uri (const char *uri)
@@ -775,227 +770,18 @@
 	g_list_free (metadata);
 }
 
-#ifdef HAVE_EXEMPI
-
-static GList *
-xmp_iter_simple (GList *metadata, const gchar *schema, const gchar *path, const gchar *value, GthMetadataCategory category);
-static GList *
-xmp_iter (XmpPtr xmp, XmpIteratorPtr iter, GList *metadata, GthMetadataCategory category);
-
-
-/* We have an array, now recursively iterate over it's children. */
-static GList *
-xmp_iter_array (XmpPtr xmp, 
-		GList *metadata, 
-		const gchar *schema, 
-		const gchar *path, 
-		GthMetadataCategory category)
-{
-		XmpIteratorPtr iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN);
-		metadata = xmp_iter (xmp, iter, metadata, category);
-		xmp_iterator_free (iter);
-
-		return metadata;
-}
-
-
-/* We have a simple element, but need to iterate over the qualifiers */
-static GList *
-xmp_iter_simple_qual (XmpPtr xmp, 
-		      GList *metadata,
-                      const gchar *schema, 
-		      const gchar *path, 
-		      const gchar *value, 
-		      GthMetadataCategory category)
-{
-	XmpIteratorPtr iter = xmp_iterator_new(xmp, schema, path, XMP_ITER_JUSTCHILDREN | XMP_ITER_JUSTLEAFNAME);
-
-	XmpStringPtr the_path = xmp_string_new ();
-	XmpStringPtr the_prop = xmp_string_new ();
-
-	gchar *locale = setlocale (LC_ALL, NULL);
-	gchar *sep = strchr (locale,'.');
-	if (sep) {
-		locale[sep - locale] = '\0';
-	}
-	sep = strchr (locale, '_');
-	if (sep) {
-		locale[sep - locale] = '-';
-	}
-
-	gboolean ignore_element = FALSE;
-
-	while (xmp_iterator_next (iter, NULL, the_path, the_prop, NULL)) {
-		const gchar *qual_path = xmp_string_cstr (the_path);
-		const gchar *qual_value = xmp_string_cstr (the_prop);
-
-		if (strcmp (qual_path, "xml:lang") == 0) {
-			/* is this a language we should ignore? */
-			if (strcmp (qual_value, "x-default") != 0 && strcmp (qual_value, "x-repair") != 0 && strcmp (qual_value, locale) != 0) {
-				ignore_element = TRUE;
-				break;
-			}
-		}
-	}
-
-	if (!ignore_element) {
-		metadata = xmp_iter_simple (metadata, schema, path, value, category);
-	}
-
-	xmp_string_free (the_prop);
-	xmp_string_free (the_path);
-
-	xmp_iterator_free (iter);
-
-	return metadata;
-}
-
-
-/* We have a simple element. Add any metadata we know about to the hash table  */
-static GList *
-xmp_iter_simple (GList *metadata,
-		 const gchar *schema, 
-		 const gchar *path, 
-		 const gchar *value, 
-		 GthMetadataCategory category)
-{
-	GthMetadata *new_entry;
-
-	new_entry = g_new (GthMetadata, 1);
-	new_entry->category = category;
-	new_entry->name = g_strdup (path);
-	new_entry->value = g_strdup (value);
-	new_entry->position = 0;
-	metadata = g_list_prepend (metadata, new_entry);
-
-	return metadata;
-}
-
-
-/* Iterate over the XMP, dispatching to the appropriate element type 
-   simple, simple w/qualifiers, or an array) handler */
-
-static GList *
-xmp_iter (XmpPtr xmp, XmpIteratorPtr iter, GList *metadata, GthMetadataCategory category)
-{
-	XmpStringPtr the_schema = xmp_string_new ();
-	XmpStringPtr the_path = xmp_string_new ();
-	XmpStringPtr the_prop = xmp_string_new ();
-
-	uint32_t opt;
-	while (xmp_iterator_next (iter, the_schema, the_path, the_prop, &opt)) {
-		const gchar *schema = xmp_string_cstr (the_schema);
-		const gchar *path = xmp_string_cstr (the_path);
-		const gchar *value = xmp_string_cstr (the_prop);
-
-		if (XMP_IS_PROP_SIMPLE (opt)) {
-			if (strcmp (path,"") != 0) {
-				if (XMP_HAS_PROP_QUALIFIERS (opt)) {
-					metadata = xmp_iter_simple_qual (xmp, metadata, schema, path, value, category);
-				} else {
-					metadata = xmp_iter_simple (metadata, schema, path, value, category);
-				}
-			}	
-		}
-		else if (XMP_IS_PROP_ARRAY (opt)) {
-			metadata = xmp_iter_array (xmp, metadata, schema, path, category);
-			xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE);
-		}
-	}
-
-	xmp_string_free (the_prop);
-	xmp_string_free (the_path);
-	xmp_string_free (the_schema);
-
-	return metadata;
-}
-
-static GList *
-read_xmp_file (const char *uri, GList *metadata, GthMetadataCategory category)
-{
-	char       *local_file;
-	XmpFilePtr  fp;
-        XmpPtr      xmp;
-
-        local_file = get_cache_filename_from_uri (uri);
-        if (local_file == NULL)
-                return metadata;
-
-	/* sidecar may not exist */
-	if (!path_exists (local_file))
-		return metadata;
-
-        fp = xmp_files_open_new (local_file, XMP_OPEN_READ);
-        if (fp == NULL) {
-                g_free (local_file);
-                return metadata;
-        }
-
-        xmp = xmp_files_get_new_xmp (fp);
-        if (xmp != NULL) {
-                XmpIteratorPtr iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_PROPERTIES);
-                metadata = xmp_iter (xmp, iter, metadata, category);
-                xmp_iterator_free (iter);
-
-                xmp_free (xmp);
-        }
-
-        xmp_files_free (fp);
-        g_free (local_file);
-
-	return metadata;
-}
-#endif
-
-
-GList *
-gth_read_xmp (const char *uri, GList *metadata)
-{
-#ifdef HAVE_EXEMPI
-	XmpFilePtr          fp;
-	XmpPtr              xmp;
-	char               *local_file;
-	char		   *uri_wo_ext;
-	char               *sidecar_uri;
-	GthMetadataCategory category;
-
-	/* Because prepending is faster than appending */
-	metadata = g_list_reverse (metadata);
-
-	xmp_init ();
-
-#ifndef HAVE_EXIV2	
-	/* embedded xmp data */	
-	metadata = read_xmp_file (uri, 
-				  metadata, 
-				  GTH_METADATA_CATEGORY_XMP_EMBEDDED);
-#endif
-
-	/* Check for sidecar (foo.jpg <-> foo.xmp) */
-	uri_wo_ext = remove_extension_from_path (uri);
-	sidecar_uri = g_strconcat (uri_wo_ext, ".xmp", NULL);
-	metadata = read_xmp_file (sidecar_uri, 
-				  metadata, 
-				  GTH_METADATA_CATEGORY_XMP_SIDECAR);
-	g_free (sidecar_uri);
-        g_free (uri_wo_ext);
-
-	xmp_terminate ();
-
-	/* Undo the initial reverse */
-	metadata = g_list_reverse (metadata);
-#endif
-
-	return metadata;
-}
 
 GList * read_exiv2_file (const char *uri, GList *metadata);
+GList * read_exiv2_sidecar (const char *uri, GList *metadata);
+
 
 GList *
 gth_read_exiv2 (const char *uri, GList *metadata)
 {
 #ifdef HAVE_EXIV2
 	char *local_file;
+	char *uri_wo_ext;
+        char *sidecar_uri;
 
         local_file = get_cache_filename_from_uri (uri);
         if (local_file == NULL)
@@ -1004,12 +790,25 @@
 	/* Because prepending is faster than appending */
 	metadata = g_list_reverse (metadata);
 
+	/* Read image file */
 	metadata = read_exiv2_file (local_file, metadata);
+	g_free (local_file);
 
-	/* Undo the initial reverse */
-	metadata = g_list_reverse (metadata);
+	/* Read sidecar, if present */
+	/* FIXME: add remote cache support (use copy_remote_file_to_cache) */
+	uri_wo_ext = remove_extension_from_path (uri);
+	sidecar_uri = g_strconcat (uri_wo_ext, ".xmp", NULL);
+	local_file = get_cache_filename_from_uri (sidecar_uri);
+
+	if ((local_file != NULL) && path_exists (local_file))
+	       	metadata = read_exiv2_sidecar (local_file, metadata);
 
 	g_free (local_file);
+       	g_free (uri_wo_ext);
+        g_free (sidecar_uri);
+
+	/* Undo the initial reverse */
+	metadata = g_list_reverse (metadata);
 #endif
 
 	return metadata;

Modified: trunk/libgthumb/gth-exif-utils.h
==============================================================================
--- trunk/libgthumb/gth-exif-utils.h	(original)
+++ trunk/libgthumb/gth-exif-utils.h	Fri Jan 11 14:03:01 2008
@@ -97,8 +97,6 @@
 GthTransform  read_orientation_field      (const char   *path);
 void	      write_orientation_field     (const char   *filename, 
 				  	   GthTransform  transform);
-GList *       gth_read_xmp		  (const char   *filename,
-					   GList        *metadata);
 GList *       gth_read_exiv2		  (const char   *filename,
 					   GList        *metadata);
 void          free_metadata               (GList        *metadata);

Modified: trunk/libgthumb/gth-exiv2-utils.cpp
==============================================================================
--- trunk/libgthumb/gth-exiv2-utils.cpp	(original)
+++ trunk/libgthumb/gth-exiv2-utils.cpp	Fri Jan 11 14:03:01 2008
@@ -22,13 +22,17 @@
 
 #include "gth-exiv2-utils.hpp"
 
+#include <exiv2/basicio.hpp>
+#include <exiv2/xmp.hpp>
+#include <exiv2/error.hpp>
 #include <exiv2/image.hpp>
 #include <exiv2/exif.hpp>
 #include <iostream>
-
 #include <string>
 #include <sstream>
 #include <vector>
+#include <iomanip>
+
 
 using namespace std;
 
@@ -151,7 +155,7 @@
 		Exiv2::XmpData &xmpData = image->xmpData();
 		if (!xmpData.empty()) {
 
-			//add iptc-metadata to glist
+			//add xmp-metadata to glist
 			GthMetadata *new_entry;
 			Exiv2::XmpData::iterator end = xmpData.end();
 			for (Exiv2::XmpData::iterator md = xmpData.begin(); md != end; ++md) {
@@ -178,3 +182,45 @@
 	}
 }
 
+
+extern "C"
+GList *
+read_exiv2_sidecar (const char *uri, GList *metadata)
+{
+	try {
+	        Exiv2::DataBuf buf = Exiv2::readFile(uri);
+        	std::string xmpPacket;
+	        xmpPacket.assign(reinterpret_cast<char*>(buf.pData_), buf.size_);
+	        Exiv2::XmpData xmpData;
+
+	        if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket))
+			return metadata;
+
+	        if (!xmpData.empty()) {
+
+                        //add xmp-metadata to glist
+                        GthMetadata *new_entry;
+                        Exiv2::XmpData::iterator end = xmpData.end();
+                        for (Exiv2::XmpData::iterator md = xmpData.begin(); md != end; ++md) {
+
+                                //determine metadata category
+                                GthMetadataCategory cat = GTH_METADATA_CATEGORY_XMP_SIDECAR;
+
+                                //fill entry
+                                stringstream value;
+                                value << *md;
+
+                                stringstream name;
+                                name << md->groupName() << "." << md->tagName();
+
+                                metadata = add (metadata, name.str().c_str(), value.str().c_str(), cat);
+			}
+		}
+	        Exiv2::XmpParser::terminate();
+	        return metadata;
+	} 
+	catch (Exiv2::AnyError& e) {
+	        std::cout << "Caught Exiv2 exception '" << e << "'\n";
+	        return metadata;
+	}
+}

Modified: trunk/libgthumb/gth-exiv2-utils.hpp
==============================================================================
--- trunk/libgthumb/gth-exiv2-utils.hpp	(original)
+++ trunk/libgthumb/gth-exiv2-utils.hpp	Fri Jan 11 14:03:01 2008
@@ -28,5 +28,8 @@
 extern "C" GList *
 read_exiv2_file (const char *uri, GList *metadata);
 
+extern "C" GList *
+read_exiv2_sidecar (const char *uri, GList *metadata);
+
 #endif
 

Modified: trunk/src/gth-exif-data-viewer.c
==============================================================================
--- trunk/src/gth-exif-data-viewer.c	(original)
+++ trunk/src/gth-exif-data-viewer.c	Fri Jan 11 14:03:01 2008
@@ -805,8 +805,6 @@
 	if ( mime_type_is (mime_type, "image/jpeg"))
 		metadata = gth_read_exif (uri, metadata, existing_edata);
 
-	metadata = gth_read_xmp (uri, metadata);
-
 	if ( mime_type_is_audio (mime_type) || mime_type_is_video (mime_type))
 		metadata = gth_read_gstreamer (uri, metadata);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]