[tracker] Improvements to the IPTC extractor



commit 72aa2fa55edc074dbf7a981e6386e5eab86a05fb
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Dec 23 16:19:33 2009 +0100

    Improvements to the IPTC extractor

 src/tracker-extract/tracker-iptc.c                 |  109 ++++++++++---------
 .../tracker-extract/data/jpeg/create_jpeg_testdata |    4 +
 tests/tracker-extract/data/jpeg/iptc_random_1.data |   16 +++
 3 files changed, 77 insertions(+), 52 deletions(-)
---
diff --git a/src/tracker-extract/tracker-iptc.c b/src/tracker-extract/tracker-iptc.c
index 2101182..cb3314e 100644
--- a/src/tracker-extract/tracker-iptc.c
+++ b/src/tracker-extract/tracker-iptc.c
@@ -37,13 +37,65 @@
 static const gchar *
 fix_iptc_orientation (const gchar *orientation)
 {
-	if (strcmp(orientation, "P")==0) {
+	if (g_strcmp0 (orientation, "P") == 0) {
 		return "nfo:orientation-left";
 	}
 
 	return "nfo:orientation-top"; /* We take this as default */
 }
 
+
+static void
+foreach_dataset (IptcDataSet *dataset, void *user_data)
+{
+	TrackerIptcData *data = user_data;
+	gchar mbuffer[1024];
+
+	switch (dataset->tag) {
+			case IPTC_TAG_KEYWORDS:
+			if (!data->keywords) {
+				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+				data->keywords = g_strdup (mbuffer);
+			}
+			break;
+			case IPTC_TAG_DATE_CREATED:
+			if (!data->date_created) {
+				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+				/* From: ex; date "2007:04:15 15:35:58"
+				 * To : ex. "2007-04-15T17:35:58+0200 where +0200 is localtime */
+				data->date_created = tracker_date_format_to_iso8601 (mbuffer, IPTC_DATE_FORMAT);
+			}
+			break;
+			case IPTC_TAG_BYLINE:
+			if (!data->byline) {
+				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+				data->byline = g_strdup (mbuffer);
+			}
+			break;
+
+			case IPTC_TAG_CREDIT:
+			if (!data->credit) {
+				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+				data->credit = g_strdup (mbuffer);
+			}
+			case IPTC_TAG_COPYRIGHT_NOTICE:
+			if (!data->copyright_notice) {
+				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+				data->copyright_notice = g_strdup (mbuffer);
+			}
+			case IPTC_TAG_IMAGE_ORIENTATION:
+			if (!data->image_orientation) {
+				iptc_dataset_get_as_str (dataset, mbuffer, 1024);
+				data->image_orientation = g_strdup (fix_iptc_orientation (mbuffer));
+			}
+			break;
+
+			default:
+			break;
+	}
+}
+
+
 #endif
 
 
@@ -54,17 +106,10 @@ tracker_read_iptc (const unsigned char *buffer,
                    TrackerIptcData     *data)
 {
 #ifdef HAVE_LIBIPTCDATA
-	guint i;
 	IptcData *iptc = NULL;
-	IptcTag   p[6] = { IPTC_TAG_KEYWORDS, 
-	                   /* 01 */  IPTC_TAG_DATE_CREATED,
-	                   /* 02 */  IPTC_TAG_BYLINE,
-	                   /* 03 */  IPTC_TAG_CREDIT,
-	                   /* 04 */  IPTC_TAG_COPYRIGHT_NOTICE,
-	                   /* 05 */  IPTC_TAG_IMAGE_ORIENTATION};
 
 	/* FIXME According to valgrind this is leaking (together with the unref).
-	 * Problem in libiptc */
+	 * Problem in libiptc (I replaced this with the _free equivalent) */
 
 	iptc = iptc_data_new ();
 
@@ -72,53 +117,13 @@ tracker_read_iptc (const unsigned char *buffer,
 		return;
 
 	if (iptc_data_load (iptc, buffer, len) < 0) {
-		iptc_data_unref (iptc);
+		iptc_data_free (iptc);
 		return;
 	}
 
-	for (i = 0; i < 6; i++) {
-		IptcDataSet *dataset = NULL;
-
-		while ((dataset = iptc_data_get_next_dataset (iptc, dataset, 2, p[i]))) {
-			gchar mbuffer[1024];
-
-			iptc_dataset_get_as_str (dataset, mbuffer, 1024);
-
-			switch (p[i]) {
-			case IPTC_TAG_KEYWORDS:
-				if (!data->keywords)
-					data->keywords = g_strdup (mbuffer);
-				break;
-			case IPTC_TAG_DATE_CREATED:
-				if (!data->date_created) {
-					/* From: ex; date "2007:04:15 15:35:58"
-					 * To : ex. "2007-04-15T17:35:58+0200 where +0200 is localtime */
-					data->date_created = tracker_date_format_to_iso8601 (mbuffer, IPTC_DATE_FORMAT);
-				}
-				break;
-			case IPTC_TAG_BYLINE:
-				if (!data->byline)
-					data->byline = g_strdup (mbuffer);
-				break;
-			case IPTC_TAG_CREDIT:
-				if (!data->credit)
-					data->credit = g_strdup (mbuffer);
-				break;
-			case IPTC_TAG_COPYRIGHT_NOTICE:
-				if (!data->copyright_notice)
-					data->copyright_notice = g_strdup (mbuffer);
-				break;
-			case IPTC_TAG_IMAGE_ORIENTATION:
-				if (!data->image_orientation)
-					data->image_orientation = g_strdup (fix_iptc_orientation (mbuffer));
-				break;
-			default:
-				break;
-			}
-		}
-	}
+	iptc_data_foreach_dataset (iptc, foreach_dataset, data);
 
-	iptc_data_unref (iptc);
+	iptc_data_free (iptc);
 
 #endif
 }
diff --git a/tests/tracker-extract/data/jpeg/create_jpeg_testdata b/tests/tracker-extract/data/jpeg/create_jpeg_testdata
index 12a08c2..111b8f3 100755
--- a/tests/tracker-extract/data/jpeg/create_jpeg_testdata
+++ b/tests/tracker-extract/data/jpeg/create_jpeg_testdata
@@ -179,6 +179,10 @@ exiftool -exif:WhiteBalance=0 -n exif_white_1.jpg
 convert -size 320x240   pattern:checkerboard exif_metering_1.jpg
 exiftool -exif:MeteringMode=5 -n exif_metering_1.jpg
 
+#random iptc
+convert -size 320x240   pattern:checkerboard iptc_random_1_tmp.jpg
+convert +profile 8BIM +comment -profile 8BIMTEXT:iptc_random_1.data iptc_random_1_tmp.jpg iptc_random_1.jpg
+
 #	{ EXIF_TAG_MAKE, "Image:CameraMake", NULL },
 #	{ EXIF_TAG_MODEL, "Image:CameraModel", NULL },
 #	{ EXIF_TAG_ORIENTATION, "Image:Orientation", NULL },
diff --git a/tests/tracker-extract/data/jpeg/iptc_random_1.data b/tests/tracker-extract/data/jpeg/iptc_random_1.data
new file mode 100644
index 0000000..f17d07b
--- /dev/null
+++ b/tests/tracker-extract/data/jpeg/iptc_random_1.data
@@ -0,0 +1,16 @@
+8BIM#1028="IPTC"
+2#0="^B"
+2#120#Caption="Some caption"
+2#122#Caption Writer="Me"
+2#105#Headline="Los Angeles premiere"
+2#40#Special Instructions="pcn"
+2#10#Priority="2"
+2#80#Byline="MMMM"
+2#85#Byline Title="asdasdasd"
+2#110#Credit="asdasd.com"
+2#115#Source="My MEDIA"
+2#5#Image Name="Test"
+2#55#Created Date="20040129"
+2#90#City="Westwood"
+2#95#Province State="CA"
+2#101#Country="United States"



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