[tracker/roi-png-fix: 14/14] Fix the Imagemagick png raw profile magic.
- From: Mikael Ottela <mottela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/roi-png-fix: 14/14] Fix the Imagemagick png raw profile magic.
- Date: Fri, 9 Sep 2011 14:06:03 +0000 (UTC)
commit 59e1ca87bc333578418a0f7be7ce33e0b04ba847
Author: Mikael Ottela <mikael ottela ixonos com>
Date: Thu Sep 8 15:21:27 2011 +0300
Fix the Imagemagick png raw profile magic.
src/libtracker-extract/tracker-xmp.c | 4 +-
src/tracker-extract/tracker-extract-png.c | 144 ++++++++++++++++++++++++++---
2 files changed, 133 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-xmp.c b/src/libtracker-extract/tracker-xmp.c
index 905c881..c8438ea 100644
--- a/src/libtracker-extract/tracker-xmp.c
+++ b/src/libtracker-extract/tracker-xmp.c
@@ -287,8 +287,6 @@ iterate_simple_qual (XmpPtr xmp,
static const gchar *
fix_orientation (const gchar *orientation)
{
- g_debug ("Checking orientation");
-
if (orientation && g_ascii_strcasecmp (orientation, "1") == 0) {
return "nfo:orientation-top";
} else if (orientation && g_ascii_strcasecmp (orientation, "2") == 0) {
@@ -742,6 +740,8 @@ tracker_xmp_new (const gchar *buffer,
data = g_new0 (TrackerXmpData, 1);
+ g_debug ("Found XMP");
+
if (!parse_xmp (buffer, len, uri, data)) {
tracker_xmp_free (data);
return NULL;
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index e64c9e3..bec4550 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -79,6 +79,100 @@ rfc1123_to_iso8601_date (const gchar *date)
return tracker_date_format_to_iso8601 (date, RFC1123_DATE_FORMAT);
}
+/* Handle raw profiles by Imagemagick (at least). Hex encoded with line-changes
+ * and other (undocumented/unofficial) twists.
+ */
+static gchar *
+raw_profile_new (const gchar *input,
+ const guint input_length,
+ guint *output_length)
+{
+ static const gchar* const lut = "0123456789abcdef";
+
+ gchar *output;
+ const gchar *ptr;
+ const gchar *length_ptr;
+ gsize size;
+ gchar *length_str;
+ guint length;
+
+ size_t len;
+ size_t i;
+ size_t o;
+ char *p;
+ char *q;
+
+ ptr = input;
+
+ if (*ptr != '\n')
+ return NULL;
+ ptr++;
+ if (!g_ascii_isalpha(*ptr))
+ return NULL;
+
+ // Skip the type string
+ do {
+ ptr++;
+ } while (g_ascii_isalpha(*ptr));
+
+ if (*ptr != '\n')
+ return NULL;
+
+ // Hop over whitespaces
+ do {
+ ptr++;
+ } while (*ptr == ' ');
+
+ if (!g_ascii_isdigit(*ptr))
+ return NULL;
+
+ // Get the length string
+ length_ptr = ptr;
+ size = 1;
+ do {
+ ptr++;
+ size++;
+ } while (g_ascii_isdigit(*ptr));
+
+ length_str = g_strndup (length_ptr, size-1);
+
+ if (*ptr != '\n')
+ return NULL;
+ ptr++;
+
+ length = atoi (length_str);
+ g_free (length_str);
+
+ len = length;
+ i = 0;
+ o = 0;
+
+ output = malloc (length+1); // A bit less with non-valid
+
+ o = 0;
+ while (o < len) {
+ do {
+ gchar a = ptr[i];
+ p = strchr (lut, a);
+ i++;
+ } while (p == 0);
+ do {
+ gchar b = ptr[i];
+ q = strchr (lut, b);
+ i++;
+ } while (q == 0);
+
+ output[o] = (((p - lut) << 4) | (q - lut));
+ o++;
+ }
+
+ output[o] = '\0';
+ *output_length = o;
+
+ return output;
+}
+
+
static void
read_metadata (TrackerSparqlBuilder *preupdate,
TrackerSparqlBuilder *metadata,
@@ -119,24 +213,45 @@ read_metadata (TrackerSparqlBuilder *preupdate,
/* ATM tracker_extract_xmp_read supports setting xd
* multiple times, keep it that way as here it's
* theoretically possible that the function gets
- * called multiple times
+ * called multiple times
*/
xd = tracker_xmp_new (text_ptr[i].text,
- text_ptr[i].itxt_length,
- uri);
+ text_ptr[i].itxt_length,
+ uri);
+ continue;
+ }
+
+ if (g_strcmp0 ("Raw profile type xmp", text_ptr[i].key) == 0) {
+ gchar *xmp_buffer;
+ guint xmp_buffer_length = 0;
+
+ xmp_buffer = raw_profile_new (text_ptr[i].text, text_ptr[i].text_length,
+ &xmp_buffer_length);
+
+ if (xmp_buffer) {
+ xd = tracker_xmp_new (xmp_buffer,
+ xmp_buffer_length,
+ uri);
+ }
+ g_free (xmp_buffer);
continue;
}
#endif
- #if defined(HAVE_LIBEXIF) && defined(PNG_iTXt_SUPPORTED)
- /* I'm not certain this is the key for EXIF. Using key according to
- * this document about exiftool:
- * http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html#TextualData
- */
+#if defined(HAVE_LIBEXIF) && defined(PNG_iTXt_SUPPORTED)
if (g_strcmp0 ("Raw profile type exif", text_ptr[i].key) == 0) {
- ed = tracker_exif_new (text_ptr[i].text,
- text_ptr[i].itxt_length,
- uri);
+ gchar *exif_buffer;
+ guint exif_buffer_length = 0;
+
+ exif_buffer = raw_profile_new (text_ptr[i].text, text_ptr[i].text_length,
+ &exif_buffer_length);
+
+ if (exif_buffer) {
+ ed = tracker_exif_new (exif_buffer,
+ exif_buffer_length,
+ uri);
+ }
+ g_free (exif_buffer);
continue;
}
#endif /* HAVE_LIBEXIF */
@@ -426,8 +541,7 @@ read_metadata (TrackerSparqlBuilder *preupdate,
addruri = tracker_sparql_get_uuid_urn ();
tracker_sparql_builder_predicate (metadata, "slo:postalAddress");
- tracker_sparql_builder_object_iri (metadata, addruri);
-
+ tracker_sparql_builder_object_iri (metadata, addruri);
tracker_sparql_builder_insert_open (preupdate, NULL);
tracker_sparql_builder_subject_iri (preupdate, addruri);
@@ -498,6 +612,10 @@ read_metadata (TrackerSparqlBuilder *preupdate,
tracker_sparql_builder_object_double (metadata, value);
}
+ if (xd->regions) {
+ tracker_xmp_apply_regions (preupdate, metadata, where, uri, xd);
+ }
+
for (i = 0; i < keywords->len; i++) {
gchar *p, *escaped, *var;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]