[tracker/custom-dlna: 2/3] tracker-extract: Make PNG module handle DLNA profiles



commit 4293ba9e86f6abec3c57722083044a99aba4639f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 27 17:52:07 2011 +0200

    tracker-extract: Make PNG module handle DLNA profiles
    
    In this extractor makes little sense to perform calls to any
    dlna library as we have all the necessary data right there.

 src/tracker-extract/tracker-extract-png.c |   48 +++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 7bd5073..3d1f418 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -509,6 +509,48 @@ read_metadata (TrackerSparqlBuilder *preupdate,
 	g_free (pd.creation_time);
 }
 
+static gboolean
+guess_dlna_profile (gint          depth,
+                    gint          width,
+                    gint          height,
+                    const gchar **dlna_profile,
+                    const gchar **dlna_mimetype)
+{
+	gchar *profile = NULL;
+
+	if (dlna_profile) {
+		*dlna_profile = NULL;
+	}
+
+	if (dlna_mimetype) {
+		*dlna_mimetype = NULL;
+	}
+
+	if (width == 120 && height == 120) {
+		profile = "PNG_LRG_ICO";
+	} else if (width == 48 && height == 48) {
+		profile = "PNG_SM_ICO";
+	} else if (width <= 160 && height <= 160) {
+		profile = "PNG_TN";
+	} else if (depth <= 32 && width <= 4096 && height <= 4096) {
+		profile = "PNG_LRG";
+	}
+
+	if (profile) {
+		if (dlna_profile) {
+			*dlna_profile = profile;
+		}
+
+		if (dlna_mimetype) {
+			*dlna_mimetype = "image/png";
+		}
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 G_MODULE_EXPORT gboolean
 tracker_extract_get_metadata (const gchar          *uri,
                               const gchar          *mimetype,
@@ -526,6 +568,7 @@ tracker_extract_get_metadata (const gchar          *uri,
 	png_uint_32 width, height;
 	gint bit_depth, color_type;
 	gint interlace_type, compression_type, filter_type;
+	const gchar *dlna_profile;
 	gchar *filename;
 
 	filename = g_filename_from_uri (uri, NULL, NULL);
@@ -620,6 +663,11 @@ tracker_extract_get_metadata (const gchar          *uri,
 	tracker_sparql_builder_predicate (metadata, "nfo:height");
 	tracker_sparql_builder_object_int64 (metadata, height);
 
+	if (guess_dlna_profile (bit_depth, width, height, &dlna_profile, NULL)) {
+		tracker_sparql_builder_predicate (metadata, "nmm:dlnaProfile");
+		tracker_sparql_builder_object_string (metadata, dlna_profile);
+	}
+
 	png_destroy_read_struct (&png_ptr, &info_ptr, &end_ptr);
 	tracker_file_close (f, FALSE);
 



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