[tracker/rss-enclosures] tracker-extract: Fixes NB#161047: X/Y resolution of images



commit ffe9b8829c1e00a244c5fa451f134782e8100d6e
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Apr 13 17:36:09 2010 +0200

    tracker-extract: Fixes NB#161047: X/Y resolution of images

 src/libtracker-extract/tracker-exif.c      |   21 ++++++++++++++++
 src/libtracker-extract/tracker-exif.h      |    1 +
 src/tracker-extract/tracker-extract-jpeg.c |   36 +++++++++++++++++++++++----
 src/tracker-extract/tracker-extract-png.c  |   18 ++++++++++++++
 src/tracker-extract/tracker-extract-tiff.c |   18 ++++++++++++++
 5 files changed, 88 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-exif.c b/src/libtracker-extract/tracker-exif.c
index f9ea24b..32c4f8e 100644
--- a/src/libtracker-extract/tracker-exif.c
+++ b/src/libtracker-extract/tracker-exif.c
@@ -278,6 +278,24 @@ get_white_balance (ExifData *exif,
 	return NULL;
 }
 
+
+static gint
+get_int (ExifData *exif, 
+         ExifTag   tag)
+{
+	ExifEntry *entry = exif_data_get_entry (exif, tag);
+
+	if (entry) {
+		ExifByteOrder order;
+
+		order = exif_data_get_byte_order (exif);
+		return (gint) exif_get_short (entry->data, order);
+	}
+
+	return -1;
+}
+
+
 static gchar *
 get_value (ExifData *exif, 
            ExifTag   tag)
@@ -366,6 +384,9 @@ parse_exif (const unsigned char *buffer,
 		data->copyright = get_value (exif, EXIF_TAG_COPYRIGHT);
 	if (!data->software)
 		data->software = get_value (exif, EXIF_TAG_SOFTWARE);
+
+	if (!data->resolution_unit)
+		data->resolution_unit = get_int (exif, EXIF_TAG_RESOLUTION_UNIT);
 	if (!data->x_resolution)
 		data->x_resolution = get_value (exif, EXIF_TAG_X_RESOLUTION);
 	if (!data->y_resolution)
diff --git a/src/libtracker-extract/tracker-exif.h b/src/libtracker-extract/tracker-exif.h
index c50be2a..35276be 100644
--- a/src/libtracker-extract/tracker-exif.h
+++ b/src/libtracker-extract/tracker-exif.h
@@ -52,6 +52,7 @@ typedef struct {
 	gchar *software;
 	gchar *x_resolution;
 	gchar *y_resolution;
+	gint resolution_unit;
 } TrackerExifData;
 
 #ifndef TRACKER_DISABLE_DEPRECATED
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index 421d79e..15284be 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -35,6 +35,8 @@
 
 #include "tracker-main.h"
 
+#define CM_TO_INCH              0.393700787
+
 #ifdef HAVE_LIBEXIF
 #define EXIF_NAMESPACE          "Exif"
 #define EXIF_NAMESPACE_LENGTH   4
@@ -572,20 +574,42 @@ extract_jpeg (const gchar          *uri,
 		tracker_sparql_builder_object_blank_close (metadata);
 	}
 
-	if (ed->x_resolution) {
+	if (cinfo.density_unit != 0 || ed->x_resolution) {
 		gdouble value;
 
-		value = g_strtod (ed->x_resolution, NULL);
+		if (cinfo.density_unit == 0) {
+			if (ed->resolution_unit == 1)
+				value = g_strtod (ed->x_resolution, NULL);
+			else
+				value = g_strtod (ed->x_resolution, NULL) * CM_TO_INCH;
+		} else {
+			if (cinfo.density_unit == 1)
+				value = cinfo.X_density;
+			else
+				value = cinfo.X_density * CM_TO_INCH;
+		}
+
 		tracker_sparql_builder_predicate (metadata, "nfo:horizontalResolution");
-		tracker_sparql_builder_object_int64 (metadata, (gint64) value);
+		tracker_sparql_builder_object_double (metadata, value);
 	}
 
-	if (ed->y_resolution) {
+	if (cinfo.density_unit != 0 || ed->y_resolution) {
 		gdouble value;
 
-		value = g_strtod (ed->y_resolution, NULL);
+		if (cinfo.density_unit == 0) {
+			if (ed->resolution_unit == 1)
+				value = g_strtod (ed->y_resolution, NULL);
+			else
+				value = g_strtod (ed->y_resolution, NULL) * CM_TO_INCH;
+		} else {
+			if (cinfo.density_unit == 1)
+				value = cinfo.Y_density;
+			else
+				value = cinfo.Y_density * CM_TO_INCH;
+		}
+
 		tracker_sparql_builder_predicate (metadata, "nfo:verticalResolution");
-		tracker_sparql_builder_object_int64 (metadata, (gint64) value);
+		tracker_sparql_builder_object_double (metadata, value);
 	}
 
 	jpeg_destroy_decompress (&cinfo);
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index a7913e0..b79769f 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -31,6 +31,7 @@
 #include <libtracker-extract/tracker-extract.h>
 
 #define RFC1123_DATE_FORMAT "%d %B %Y %H:%M:%S %z"
+#define CM_TO_INCH          0.393700787
 
 typedef struct {
 	const gchar *title;
@@ -468,6 +469,23 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 		tracker_sparql_builder_object_blank_close (metadata);
 	}
 
+	if (ed->x_resolution) {
+		gdouble value;
+
+		value = ed->resolution_unit == 1 ? g_strtod (ed->x_resolution, NULL) : g_strtod (ed->x_resolution, NULL) * CM_TO_INCH;
+		tracker_sparql_builder_predicate (metadata, "nfo:horizontalResolution");
+		tracker_sparql_builder_object_double (metadata, value);
+	}
+
+	if (ed->y_resolution) {
+		gdouble value;
+
+		value = ed->resolution_unit == 1 ? g_strtod (ed->y_resolution, NULL) : g_strtod (ed->y_resolution, NULL) * CM_TO_INCH;
+		tracker_sparql_builder_predicate (metadata, "nfo:verticalResolution");
+		tracker_sparql_builder_object_double (metadata, value);
+	}
+
+	tracker_exif_free (ed);
 	tracker_xmp_free (xd);
 	g_free (pd.creation_time);
 	g_free (md.camera);
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index b17087e..e326c17 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -27,6 +27,8 @@
 #include <libtracker-client/tracker-client.h>
 #include <libtracker-extract/tracker-extract.h>
 
+#define CM_TO_INCH          0.393700787
+
 typedef enum {
 	TAG_TYPE_UNDEFINED = 0,
 	TAG_TYPE_STRING,
@@ -676,6 +678,22 @@ extract_tiff (const gchar          *uri,
 		g_free (uri);
 	}
 
+	if (ed->x_resolution) {
+		gdouble value;
+
+		value = ed->resolution_unit == 1 ? g_strtod (ed->x_resolution, NULL) : g_strtod (ed->x_resolution, NULL) * CM_TO_INCH;
+		tracker_sparql_builder_predicate (metadata, "nfo:horizontalResolution");
+		tracker_sparql_builder_object_double (metadata, value);
+	}
+
+	if (ed->y_resolution) {
+		gdouble value;
+
+		value = ed->resolution_unit == 1 ? g_strtod (ed->y_resolution, NULL) : g_strtod (ed->y_resolution, NULL) * CM_TO_INCH;
+		tracker_sparql_builder_predicate (metadata, "nfo:verticalResolution");
+		tracker_sparql_builder_object_double (metadata, value);
+	}
+
 	g_free (md.camera);
 	tiff_data_free (&td);
 	tracker_exif_free (ed);



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