tracker r2949 - in trunk: . src/tracker-extract



Author: mottela
Date: Fri Feb 20 15:03:16 2009
New Revision: 2949
URL: http://svn.gnome.org/viewvc/tracker?rev=2949&view=rev

Log:
Added iptc support for jpeg and tiff

Added:
   trunk/src/tracker-extract/tracker-iptc.c
   trunk/src/tracker-extract/tracker-iptc.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/tracker-extract/Makefile.am
   trunk/src/tracker-extract/tracker-extract-jpeg.c
   trunk/src/tracker-extract/tracker-extract-tiff.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Fri Feb 20 15:03:16 2009
@@ -894,6 +894,39 @@
 AM_CONDITIONAL(HAVE_EXIF, test "x$have_libexif" = "xyes")
 
 ##################################################################
+# Check for libiptcdata
+##################################################################
+
+AC_ARG_ENABLE(libiptcdata, 
+              AS_HELP_STRING([--disable-libiptcdata],
+		             [disable extractor for iptc data]),,
+	      [enable_libiptcdata=auto])
+
+if test "x$enable_libiptcdata" != "xno" ; then
+   PKG_CHECK_MODULES(LIBIPTCDATA, 
+	             [libiptcdata],
+		     [have_libiptcdata=yes],
+		     [have_libiptcdata=no])
+
+   AC_SUBST(LIBIPTCDATA_CFLAGS)
+   AC_SUBST(LIBIPTCDATA_LIBS)
+
+   if test "x$have_libiptcdata" = "xyes"; then
+      AC_DEFINE(HAVE_LIBIPTCDATA, [], [Define if we have libiptcdata])
+   fi
+else
+   have_libiptcdata="no  (disabled)"
+fi
+
+if test "x$enable_libiptcdata" = "xyes"; then
+   if test "x$have_libiptcdata" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find libiptcdata.])
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_IPTC, test "x$have_libiptcdata" = "xyes")
+
+##################################################################
 # Check for libgsf
 ##################################################################
 
@@ -1329,8 +1362,8 @@
 
 	Support PNG:				yes
 	Support PDF:				$have_poppler_glib
-	Support JPEG:				$have_libjpeg (xmp: $have_exempi, exif: $have_libexif)
-	Support TIFF:				$have_libtiff (xmp: $have_exempi, exif: yes)
+	Support JPEG:				$have_libjpeg (xmp: $have_exempi, exif: $have_libexif, iptc: $have_libiptcdata)
+	Support TIFF:				$have_libtiff (xmp: $have_exempi, exif: yes, iptc: $have_libiptcdata)
 	Support MS & Open Office (gsf):	        $have_libgsf
 	Support XML / HTML formats:		$have_libxml2
 	Support embedded / sidecar XMP:		$have_exempi

Modified: trunk/src/tracker-extract/Makefile.am
==============================================================================
--- trunk/src/tracker-extract/Makefile.am	(original)
+++ trunk/src/tracker-extract/Makefile.am	Fri Feb 20 15:03:16 2009
@@ -18,6 +18,7 @@
 	$(LIBJPEG_CFLAGS) 						\
 	$(LIBTIFF_CFLAGS) 						\
 	$(LIBEXIF_CFLAGS) 						\
+	$(LIBIPTCDATA_CFLAGS)						\
 	$(LIBGSF_CFLAGS) 						\
 	$(LIBXML2_CFLAGS) 						\
 	$(LIBPNG_CFLAGS) 						\
@@ -26,6 +27,7 @@
 	$(XINE_CFLAGS) 							\
 	$(TOTEM_PL_PARSER_CFLAGS)
 
+
 modules_LTLIBRARIES = 							\
 	libextract-abw.la 						\
 	libextract-mp3.la				 		\
@@ -92,6 +94,11 @@
 	tracker-xmp.c							\
 	tracker-xmp.h
 
+# Common iptc Sources
+iptc_sources =								\
+	tracker-iptc.c							\
+	tracker-iptc.h
+
 # Common AlbumArt sources
 
 albumart_libs = 
@@ -193,14 +200,14 @@
 libextract_xine_la_LIBADD = $(GLIB2_LIBS) $(XINE_LIBS)
 
 # JPEG
-libextract_jpeg_la_SOURCES = tracker-extract-jpeg.c $(xmp_sources) $(escape_sources)
+libextract_jpeg_la_SOURCES = tracker-extract-jpeg.c $(xmp_sources) $(iptc_sources) $(escape_sources)
 libextract_jpeg_la_LDFLAGS = $(module_flags)
-libextract_jpeg_la_LIBADD = $(GLIB2_LIBS) $(LIBJPEG_LIBS) $(LIBEXIF_LIBS) $(EXEMPI_LIBS)
+libextract_jpeg_la_LIBADD = $(GLIB2_LIBS) $(LIBJPEG_LIBS) $(LIBEXIF_LIBS) $(LIBIPTCDATA_LIBS) $(EXEMPI_LIBS)
 
 # TIFF
-libextract_tiff_la_SOURCES = tracker-extract-tiff.c $(xmp_sources) $(escape_sources)
+libextract_tiff_la_SOURCES = tracker-extract-tiff.c $(xmp_sources) $(iptc_sources) $(escape_sources)
 libextract_tiff_la_LDFLAGS = $(module_flags)
-libextract_tiff_la_LIBADD = $(GLIB2_LIBS) $(LIBTIFF_LIBS) $(EXEMPI_LIBS)
+libextract_tiff_la_LIBADD = $(GLIB2_LIBS) $(LIBTIFF_LIBS) $(LIBIPTCDATA_LIBS) $(EXEMPI_LIBS)
 
 # Playlists using totem-pl-parser
 libextract_playlist_la_SOURCES = tracker-extract-playlist.c  $(escape_sources)

Modified: trunk/src/tracker-extract/tracker-extract-jpeg.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-jpeg.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-jpeg.c	Fri Feb 20 15:03:16 2009
@@ -44,6 +44,7 @@
 
 #include "tracker-main.h"
 #include "tracker-xmp.h"
+#include "tracker-iptc.h"
 
 #ifdef HAVE_EXEMPI
 #define XMP_NAMESPACE	     "http://ns.adobe.com/xap/1.0/\x00";
@@ -55,6 +56,12 @@
 #define EXIF_DATE_FORMAT "%Y:%m:%d %H:%M:%S"
 #endif /* HAVE_LIBEXIF */
 
+#ifdef HAVE_LIBIPTCDATA
+#define PS3_NAMESPACE	     "Photoshop 3.0\0"
+#define PS3_NAMESPACE_LENGTH 14
+#include <libiptcdata/iptc-jpeg.h>
+#endif /* HAVE_LIBIPTCDATA */
+
 static void extract_jpeg (const gchar *filename,
 			  GHashTable  *metadata);
 
@@ -63,6 +70,19 @@
 	{ NULL, NULL }
 };
 
+struct tej_error_mgr 
+{
+	struct jpeg_error_mgr jpeg;
+	jmp_buf setjmp_buffer;
+};
+
+static void tracker_extract_jpeg_error_exit (j_common_ptr cinfo)
+{
+    struct tej_error_mgr *h = (struct tej_error_mgr *)cinfo->err;
+    (*cinfo->err->output_message)(cinfo);
+    longjmp(h->setjmp_buffer, 1);
+}
+
 #ifdef HAVE_LIBEXIF
 
 typedef gchar * (*PostProcessor) (const gchar*);
@@ -108,18 +128,9 @@
 	{ -1, NULL, NULL }
 };
 
-struct tej_error_mgr 
-{
-	struct jpeg_error_mgr jpeg;
-	jmp_buf setjmp_buffer;
-};
+#endif /* HAVE_EXIF */
 
-static void tracker_extract_jpeg_error_exit (j_common_ptr cinfo)
-{
-    struct tej_error_mgr *h = (struct tej_error_mgr *)cinfo->err;
-    (*cinfo->err->output_message)(cinfo);
-    longjmp(h->setjmp_buffer, 1);
-}
+#ifdef HAVE_LIBEXIF
 
 static gchar *
 date_to_iso8601 (const gchar *date)
@@ -258,6 +269,7 @@
 
 #endif /* HAVE_LIBEXIF */
 
+
 static void
 extract_jpeg (const gchar *filename,
 	      GHashTable  *metadata)
@@ -290,6 +302,8 @@
 	if ((jpeg = fdopen (fd_jpeg, "rb"))) {
 		gchar *str;
 		gsize  len;
+		gsize  offset;
+		gsize  sublen;
 
 		cinfo.err = jpeg_std_error (&tejerr.jpeg);
 		tejerr.jpeg.error_exit = tracker_extract_jpeg_error_exit;
@@ -301,6 +315,7 @@
 		
 		jpeg_save_markers (&cinfo, JPEG_COM, 0xFFFF);
 		jpeg_save_markers (&cinfo, JPEG_APP0 + 1, 0xFFFF);
+		jpeg_save_markers (&cinfo, JPEG_APP0 + 13, 0xFFFF);
 		
 		jpeg_stdio_src (&cinfo, jpeg);
 		
@@ -330,6 +345,9 @@
 				break;
 				
 			case JPEG_APP0+1:
+				str = (gchar*) marker->data;
+				len = marker->data_length;
+
 #ifdef HAVE_LIBEXIF
 				if (strncmp ("Exif", (gchar*) (marker->data), 5) == 0) {
 					read_exif ((unsigned char*) marker->data,
@@ -339,8 +357,6 @@
 #endif /* HAVE_LIBEXIF */
 
 #ifdef HAVE_EXEMPI
-				str = (gchar*) marker->data;
-				len = marker->data_length;
 
 				if (strncmp (XMP_NAMESPACE, str, XMP_NAMESPACE_LENGTH) == 0) {
 					tracker_read_xmp (str + XMP_NAMESPACE_LENGTH,
@@ -349,7 +365,20 @@
 				}
 #endif /* HAVE_EXEMPI */
 				break;
-
+			case JPEG_APP0+13:
+				str = (gchar*) marker->data;
+				len = marker->data_length;
+#ifdef HAVE_LIBIPTCDATA
+				if (strncmp (PS3_NAMESPACE, str, PS3_NAMESPACE_LENGTH) == 0) {
+					offset = iptc_jpeg_ps3_find_iptc (str, len, &sublen);
+					if (offset>0) {
+						tracker_read_iptc (str + offset,
+								   sublen,
+								   metadata);
+					}
+				}
+#endif /* HAVE_LIBIPTCDATA */
+				break;
 			default:
 				marker = marker->next;
 				continue;

Modified: trunk/src/tracker-extract/tracker-extract-tiff.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-tiff.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-tiff.c	Fri Feb 20 15:03:16 2009
@@ -32,8 +32,8 @@
 
 #include "tracker-main.h"
 #include "tracker-xmp.h"
+#include "tracker-iptc.h"
 
-#define XMP_NAMESPACE_LENGTH 29
 #define EXIF_DATE_FORMAT     "%Y:%m:%d %H:%M:%S"
 
 typedef gchar * (*PostProcessor) (gchar *);
@@ -123,6 +123,11 @@
 
 	gfloat vardouble;
 
+#ifdef HAVE_LIBIPTCDATA
+	gchar   *iptcOffset;
+	guint32  iptcSize;
+#endif
+
 #ifdef HAVE_EXEMPI
 	gchar *xmpOffset;
 	guint32 size;
@@ -133,9 +138,18 @@
 		return;
 	}
 
+#ifdef HAVE_LIBIPTCDATA
+	if (TIFFGetField (image, TIFFTAG_RICHTIFFIPTC, &iptcSize, &iptcOffset)) {
+		if (TIFFIsByteSwapped(image) != 0) 
+			TIFFSwabArrayOfLong((uint32 *) iptcOffset,(unsigned long) iptcSize);
+		tracker_read_iptc (iptcOffset,
+				   4*iptcSize,
+				   metadata);
+	}
+#endif /* HAVE_LIBIPTCDATA */
+
 	/* FIXME There are problems between XMP data embedded with different tools
 	   due to bugs in the original spec (type) */
-
 #ifdef HAVE_EXEMPI
 	if (TIFFGetField (image, TIFFTAG_XMLPACKET, &size, &xmpOffset)) {
 		tracker_read_xmp (xmpOffset,

Added: trunk/src/tracker-extract/tracker-iptc.c
==============================================================================
--- (empty file)
+++ trunk/src/tracker-extract/tracker-iptc.c	Fri Feb 20 15:03:16 2009
@@ -0,0 +1,119 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Tracker Iptc - Iptc helper functions
+ * Copyright (C) 2009, Nokia
+ *
+ * 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 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.
+ */
+
+#include "config.h"
+
+#include "tracker-iptc.h"
+#include "tracker-main.h"
+
+#include <glib.h>
+#include <string.h>
+
+#ifdef HAVE_LIBIPTCDATA
+
+#include <libiptcdata/iptc-data.h>
+#include <libiptcdata/iptc-dataset.h>
+
+typedef gchar * (*IptcPostProcessor) (const gchar*);
+
+typedef struct {
+	IptcRecord        record;
+	IptcTag           tag;
+	gchar	         *name;
+	IptcPostProcessor post;
+} IptcTagType;
+
+static gchar *fix_iptc_orientation (const gchar *orientation);
+
+static IptcTagType iptctags[] = {
+        { 2, IPTC_TAG_KEYWORDS, "Image:Keywords", NULL },
+	{ 2, IPTC_TAG_CONTENT_LOC_NAME, "Image:Location", NULL },
+        { 2, IPTC_TAG_DATE_CREATED, "Image:Date", NULL },
+        { 2, IPTC_TAG_ORIGINATING_PROGRAM, "Image:Software", NULL },
+        { 2, IPTC_TAG_BYLINE, "Image:Creator", NULL },
+        { 2, IPTC_TAG_CITY, "Image:City", NULL },
+        { 2, IPTC_TAG_COUNTRY_NAME, "Image:Country", NULL },
+        { 2, IPTC_TAG_CREDIT, "Image:Author", NULL },
+        { 2, IPTC_TAG_COPYRIGHT_NOTICE, "File:Copyright", NULL },
+        { 2, IPTC_TAG_IMAGE_ORIENTATION, "Image:Orientation", fix_iptc_orientation },
+	{ -1, -1, NULL, NULL }
+};
+
+static void
+metadata_append (GHashTable *metadata, gchar *key, gchar *value)
+{
+	gchar *new_value;
+	gchar *orig;
+	
+	if (g_hash_table_lookup_extended (metadata, key, NULL, (gpointer) &orig)) {
+		gchar *escaped;
+		
+		escaped = tracker_escape_metadata (value);
+		new_value = g_strconcat (orig, "|", escaped, NULL);
+		
+		g_free (escaped);
+	} else {
+		new_value = tracker_escape_metadata (value);
+	}
+	g_hash_table_insert (metadata, g_strdup (key), new_value);
+}
+
+static gchar *
+fix_iptc_orientation (const gchar *orientation)
+{
+	if (strcmp(orientation, "P")==0) {
+		return g_strdup ("3");
+	}
+	
+	return g_strdup("1"); /* We take this as default */
+}
+
+#endif
+
+
+void
+tracker_read_iptc (const unsigned char *buffer,
+		   size_t		len,
+		   GHashTable	       *metadata)
+{
+#ifdef HAVE_LIBIPTCDATA
+	IptcData     *iptc = NULL;
+	IptcTagType  *p = NULL;
+
+	iptc = iptc_data_new_from_data ((unsigned char *) buffer, len);
+
+	for (p = iptctags; p->name; ++p) {
+		IptcDataSet *dataset = NULL;
+
+		while ( (dataset = iptc_data_get_next_dataset (iptc, dataset, p->record, p->tag) ) ) {
+			gchar buffer[1024];
+			
+			iptc_dataset_get_as_str (dataset, buffer, 1024);
+			
+			if (p->post) {
+				metadata_append (metadata,p->name,(*p->post) (buffer));
+			} else {
+				metadata_append (metadata, p->name, buffer);
+			}			
+		}
+	}
+	iptc_data_unref (iptc);
+#endif
+}

Added: trunk/src/tracker-extract/tracker-iptc.h
==============================================================================
--- (empty file)
+++ trunk/src/tracker-extract/tracker-iptc.h	Fri Feb 20 15:03:16 2009
@@ -0,0 +1,11 @@
+
+#ifndef _TRACKER_IPTC_H_
+#define _TRACKER_IPTC_H_
+
+#include <glib.h>
+
+void tracker_read_iptc (const unsigned char *buffer,
+			size_t		    len,
+			GHashTable	   *metadata);
+
+#endif



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