[tracker] tracker-extract: New windows icon extractor (image/vnd.microsoft.icon)



commit 62237e6d47dd2c0364a16738337d1d8e96a5c302
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Dec 9 13:17:37 2010 +0100

    tracker-extract: New windows icon extractor (image/vnd.microsoft.icon)
    
     Fixes NB#207918
    
     [NEWS]

 src/tracker-extract/Makefile.am            |  208 ++++++++++++++-------------
 src/tracker-extract/tracker-extract-icon.c |  167 ++++++++++++++++++++++
 2 files changed, 275 insertions(+), 100 deletions(-)
---
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index 7afe879..37ed716 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -3,23 +3,24 @@ include $(top_srcdir)/Makefile.decl
 module_flags = -module -avoid-version -no-undefined
 modulesdir = $(libdir)/tracker-$(TRACKER_API_VERSION)/extract-modules
 
-AM_CPPFLAGS =                                          \
-	$(BUILD_CFLAGS)                                \
-	-I$(top_srcdir)/src                            \
-	-I$(top_builddir)/src                          \
-	-DLOCALEDIR=\""$(localedir)"\"                 \
-	-DTRACKER_EXTRACTORS_DIR=\"$(modulesdir)\"     \
+AM_CPPFLAGS = \
+	$(BUILD_CFLAGS) \
+	-I$(top_srcdir)/src \
+	-I$(top_builddir)/src \
+	-DLOCALEDIR=\""$(localedir)"\" \
+	-DTRACKER_EXTRACTORS_DIR=\"$(modulesdir)\" \
 	$(TRACKER_EXTRACT_CFLAGS)
 
 # NOTE:
 # We don't always link with libtracker-common, we only link
 # against it if we directly use functions in the .so
-modules_LTLIBRARIES =                                  \
-	libextract-abw.la                              \
-	libextract-mp3.la                              \
-	libextract-png.la                              \
-	libextract-ps.la                               \
-	libextract-text.la
+modules_LTLIBRARIES = \
+	libextract-abw.la \
+	libextract-mp3.la \
+	libextract-png.la \
+	libextract-ps.la \
+	libextract-text.la \
+	libextract-icon.la
 
 if HAVE_LIBVORBIS
 modules_LTLIBRARIES += libextract-vorbis.la
@@ -50,9 +51,9 @@ modules_LTLIBRARIES += libextract-html.la
 endif
 
 if HAVE_LIBGSF
-modules_LTLIBRARIES +=                                 \
-	libextract-msoffice.la                         \
-	libextract-msoffice-xml.la                     \
+modules_LTLIBRARIES += \
+	libextract-msoffice.la \
+	libextract-msoffice-xml.la \
 	libextract-oasis.la
 endif
 
@@ -77,7 +78,7 @@ modules_LTLIBRARIES += libextract-xine.la
 endif
 
 if USING_EXTERNAL_VIDEO_PLAYER
-modules_LTLIBRARIES +=	libextract-mplayer.la           \
+modules_LTLIBRARIES +=	libextract-mplayer.la \
 			libextract-totem.la
 endif
 
@@ -88,19 +89,19 @@ endif
 # ABW
 libextract_abw_la_SOURCES = tracker-extract-abw.c
 libextract_abw_la_LDFLAGS = $(module_flags)
-libextract_abw_la_LIBADD =                             \
+libextract_abw_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 # MP3
 libextract_mp3_la_SOURCES = tracker-extract-mp3.c
 libextract_mp3_la_LDFLAGS = $(module_flags)
-libextract_mp3_la_LIBADD =                             \
+libextract_mp3_la_LIBADD =  \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 if HAVE_ENCA
@@ -111,212 +112,220 @@ endif
 # Vorbis (OGG)
 libextract_vorbis_la_SOURCES = tracker-extract-vorbis.c $(escape_sources)
 libextract_vorbis_la_LDFLAGS = $(module_flags)
-libextract_vorbis_la_LIBADD =                          \
+libextract_vorbis_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBVORBIS_LIBS)
 
 # Flac
 libextract_flac_la_SOURCES = tracker-extract-flac.c $(escape_sources)
 libextract_flac_la_LDFLAGS = $(module_flags)
-libextract_flac_la_LIBADD =                            \
+libextract_flac_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBFLAC_LIBS)
 
 # MPlayer
 libextract_mplayer_la_SOURCES = tracker-extract-mplayer.c
 libextract_mplayer_la_LDFLAGS = $(module_flags)
-libextract_mplayer_la_LIBADD =                         \
+libextract_mplayer_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 # Oasis
 libextract_oasis_la_SOURCES = tracker-extract-oasis.c
 libextract_oasis_la_CFLAGS = $(LIBGSF_CFLAGS)
 libextract_oasis_la_LDFLAGS = $(module_flags)
-libextract_oasis_la_LIBADD =                           \
+libextract_oasis_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBGSF_LIBS)
 
 # PNG
 libextract_png_la_SOURCES = tracker-extract-png.c
 libextract_png_la_CFLAGS = $(LIBPNG_CFLAGS)
 libextract_png_la_LDFLAGS = $(module_flags)
-libextract_png_la_LIBADD =                             \
+libextract_png_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBPNG_LIBS)
 
 # PS
 libextract_ps_la_SOURCES = tracker-extract-ps.c
 libextract_ps_la_LDFLAGS = $(module_flags)
-libextract_ps_la_LIBADD =                              \
+libextract_ps_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 # Totem
 libextract_totem_la_SOURCES = tracker-extract-totem.c
 libextract_totem_la_LDFLAGS = $(module_flags)
-libextract_totem_la_LIBADD =                           \
+libextract_totem_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 # XMP
 libextract_xmp_la_SOURCES = tracker-extract-xmp.c
 libextract_xmp_la_LDFLAGS = $(module_flags)
-libextract_xmp_la_LIBADD =                             \
+libextract_xmp_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 # HTML
 libextract_html_la_SOURCES = tracker-extract-html.c
 libextract_html_la_CFLAGS = $(LIBXML2_CFLAGS)
 libextract_html_la_LDFLAGS = $(module_flags)
-libextract_html_la_LIBADD =                            \
+libextract_html_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBXML2_LIBS)
 
 # MS Office
 libextract_msoffice_la_SOURCES = tracker-extract-msoffice.c
 libextract_msoffice_la_CFLAGS = $(LIBGSF_CFLAGS)
 libextract_msoffice_la_LDFLAGS = $(module_flags)
-libextract_msoffice_la_LIBADD =                        \
+libextract_msoffice_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBGSF_LIBS)
 
 # MS Office XML
 libextract_msoffice_xml_la_SOURCES = tracker-extract-msoffice-xml.c
 libextract_msoffice_xml_la_CFLAGS = $(LIBGSF_CFLAGS)
 libextract_msoffice_xml_la_LDFLAGS = $(module_flags)
-libextract_msoffice_xml_la_LIBADD =                    \
+libextract_msoffice_xml_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBGSF_LIBS)
 
 # PDF
 libextract_pdf_la_SOURCES = tracker-extract-pdf.cpp
 libextract_pdf_la_CXXFLAGS = $(POPPLER_CFLAGS)
 libextract_pdf_la_LDFLAGS = $(module_flags)
-libextract_pdf_la_LIBADD =                             \
+libextract_pdf_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(POPPLER_LIBS)
 
 # GStreamer
 libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c
 libextract_gstreamer_la_CFLAGS = $(GSTREAMER_CFLAGS)
 libextract_gstreamer_la_LDFLAGS = $(module_flags)
-libextract_gstreamer_la_LIBADD =                       \
+libextract_gstreamer_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(GSTREAMER_LIBS)
 
 # GStreamer helix
 libextract_gstreamer_helix_la_SOURCES = tracker-extract-gstreamer-helix.c
 libextract_gstreamer_helix_la_CFLAGS = $(GSTREAMER_CFLAGS)
 libextract_gstreamer_helix_la_LDFLAGS = $(module_flags) $(albumart_flags)
-libextract_gstreamer_helix_la_LIBADD =                 \
+libextract_gstreamer_helix_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(GSTREAMER_LIBS)
 
 # GUPnP DLNA
 libextract_gupnp_dlna_la_SOURCES = tracker-extract-gupnp-dlna.c
 libextract_gupnp_dlna_la_CFLAGS = $(GSTREAMER_CFLAGS) $(GUPNP_DLNA_CFLAGS)
 libextract_gupnp_dlna_la_LDFLAGS = $(module_flags) $(albumart_flags)
-libextract_gupnp_dlna_la_LIBADD =                      \
+libextract_gupnp_dlna_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(GUPNP_DLNA_LIBS)
 
 # Xine
 libextract_xine_la_SOURCES = tracker-extract-libxine.c
 libextract_xine_la_CFLAGS = $(XINE_CFLAGS)
 libextract_xine_la_LDFLAGS = $(module_flags)
-libextract_xine_la_LIBADD =                            \
+libextract_xine_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(XINE_LIBS)
 
 # GIF
 libextract_gif_la_SOURCES = tracker-extract-gif.c
 libextract_gif_la_CFLAGS = $(LIBGIF_CFLAGS)
 libextract_gif_la_LDFLAGS = $(module_flags)
-libextract_gif_la_LIBADD =                             \
+libextract_gif_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBGIF_LIBS)
 
 # JPEG
 libextract_jpeg_la_SOURCES = tracker-extract-jpeg.c
 libextract_jpeg_la_CFLAGS = $(LIBJPEG_CFLAGS)
 libextract_jpeg_la_LDFLAGS = $(module_flags)
-libextract_jpeg_la_LIBADD =                            \
+libextract_jpeg_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBJPEG_LIBS)
 
 # TIFF
 libextract_tiff_la_SOURCES = tracker-extract-tiff.c $(xmp_sources) $(iptc_sources)
 libextract_tiff_la_CFLAGS = $(LIBTIFF_CFLAGS)
 libextract_tiff_la_LDFLAGS = $(module_flags)
-libextract_tiff_la_LIBADD =                            \
+libextract_tiff_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
-	$(TRACKER_EXTRACT_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS) \
 	$(LIBTIFF_LIBS)
 
 # Playlists using totem-pl-parser
 libextract_playlist_la_SOURCES = tracker-extract-playlist.c
 libextract_playlist_la_CFLAGS = $(TOTEM_PL_PARSER_CFLAGS)
 libextract_playlist_la_LDFLAGS = $(module_flags)
-libextract_playlist_la_LIBADD =                        \
+libextract_playlist_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
-	$(TOTEM_PL_PARSER_LIBS)                        \
+	$(BUILD_LIBS) \
+	$(TOTEM_PL_PARSER_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
-# TIFF
+# TEXT
 libextract_text_la_SOURCES = tracker-extract-text.c
 libextract_text_la_LDFLAGS = $(module_flags)
-libextract_text_la_LIBADD =                            \
+libextract_text_la_LIBADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
+	$(TRACKER_EXTRACT_LIBS)
+
+# ICON
+libextract_icon_la_SOURCES = tracker-extract-icon.c
+libextract_icon_la_LDFLAGS = $(module_flags)
+libextract_icon_la_LIBADD = \
+	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 #
@@ -324,29 +333,29 @@ libextract_text_la_LIBADD =                            \
 #
 libexec_PROGRAMS = tracker-extract
 
-tracker_extract_SOURCES =                              \
-	$(marshal_sources)                             \
-	$(dbus_sources)                                \
-	tracker-albumart.c                             \
-	tracker-albumart.h                             \
-	tracker-config.c                               \
-	tracker-config.h                               \
-	tracker-dbus.c                                 \
-	tracker-dbus.h                                 \
-	tracker-extract.c                              \
-	tracker-extract.h                              \
-	tracker-read.c                                 \
-	tracker-read.h                                 \
-	tracker-main.c                                 \
-	tracker-main.h                                 \
+tracker_extract_SOURCES = \
+	$(marshal_sources) \
+	$(dbus_sources) \
+	tracker-albumart.c \
+	tracker-albumart.h \
+	tracker-config.c \
+	tracker-config.h \
+	tracker-dbus.c \
+	tracker-dbus.h \
+	tracker-extract.c \
+	tracker-extract.h \
+	tracker-read.c \
+	tracker-read.h \
+	tracker-main.c \
+	tracker-main.h \
 	tracker-albumart-generic.h
 
-tracker_extract_LDADD =                                \
+tracker_extract_LDADD = \
 	$(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(BUILD_LIBS)                                  \
+	$(BUILD_LIBS) \
 	$(TRACKER_EXTRACT_LIBS)
 
 tracker_extract_CFLAGS = $(AM_CPPFLAGS)
@@ -371,12 +380,11 @@ tracker_extract_SOURCES += tracker-albumart-dummy.c
 endif
 endif
 
-marshal_sources =                                      \
-        tracker-marshal.h                              \
+marshal_sources = \
+        tracker-marshal.h \
         tracker-marshal.c
 
-dbus_sources =                                         \
-	tracker-extract-glue.h
+dbus_sources = tracker-extract-glue.h
 
 tracker-marshal.h: tracker-marshal.list
 	$(AM_V_GEN)$(GLIB_GENMARSHAL) $< --prefix=tracker_marshal --header > $@
diff --git a/src/tracker-extract/tracker-extract-icon.c b/src/tracker-extract/tracker-extract-icon.c
new file mode 100644
index 0000000..2ab53bd
--- /dev/null
+++ b/src/tracker-extract/tracker-extract-icon.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan frade nokia com>
+ *
+ * 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 A 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 <libtracker-common/tracker-file-utils.h>
+#include <libtracker-extract/tracker-extract.h>
+
+static void extract_icon (const gchar          *filename,
+                          TrackerSparqlBuilder *preupdate,
+                          TrackerSparqlBuilder *metadata);
+
+static TrackerExtractData data[] = {
+	{ "image/vnd.microsoft.icon", extract_icon },
+	{ NULL, NULL }
+};
+
+#define ICON_HEADER_SIZE_16 3
+#define ICON_IMAGE_METADATA_SIZE_8 16
+
+static gboolean
+find_max_width_and_height (const gchar *uri,
+                           guint       *width,
+                           guint       *height)
+{
+	GError *error = NULL;
+	GFile *file;
+	GFileInputStream *stream;
+	guint n_images;
+	guint i;
+	guint16 header [ICON_HEADER_SIZE_16];
+
+	*width = 0;
+	*height = 0;
+
+	file = g_file_new_for_uri (uri);
+	stream = g_file_read (file, NULL, &error);
+	if (error) {
+		g_message ("Could not read file '%s': %s",
+		           uri,
+		           error->message);
+		g_error_free (error);
+		g_object_unref (file);
+
+		return FALSE;
+	}
+
+	/* Header consists of:
+	 *  - 2bytes, reserved, must be 0
+	 *  - 2bytes, image type (1:icon, 2:cursor, other values invalid)
+	 *  - 2bytes, number of images in the file.
+	 *
+	 * Right now we just need the number of images in the file.
+	 */
+	if (!g_input_stream_read_all (G_INPUT_STREAM (stream),
+	                              header,
+	                              ICON_HEADER_SIZE_16 * 2,
+	                              NULL,
+	                              NULL,
+	                              &error)) {
+		g_message ("Error reading icon header from stream: '%s'",
+		           error->message);
+		g_error_free (error);
+		g_object_unref (stream);
+		g_object_unref (file);
+		return FALSE;
+	}
+
+	n_images = GUINT16_FROM_LE (header[2]);
+	g_debug ("Found '%u' images in the icon file...", n_images);
+
+	/* Loop images looking for the biggest one... */
+	for (i = 0; i < n_images; i++) {
+		guint8 image_metadata [ICON_IMAGE_METADATA_SIZE_8];
+
+		/* Image metadata chunk consists of:
+		 *  - 1 byte, width in pixels, 0 means 256
+		 *  - 1 byte, height in pixels, 0 means 256
+		 *  - Plus some other stuff we don't care about...
+		 */
+		if (!g_input_stream_read_all (G_INPUT_STREAM (stream),
+		                              image_metadata,
+		                              ICON_IMAGE_METADATA_SIZE_8,
+		                              NULL,
+		                              NULL,
+		                              &error)) {
+			g_message ("Error reading icon image metadata '%u' from stream: '%s'",
+			           i,
+			           error->message);
+			g_error_free (error);
+			break;
+		}
+
+		g_debug ("  Image '%u'; width:%u height:%u",
+		         i,
+		         image_metadata[0],
+		         image_metadata[1]);
+
+		/* Width... */
+		if (image_metadata[0] == 0) {
+			*width = 256;
+		} else if (image_metadata[0] > *width) {
+			*width = image_metadata[0];
+		}
+
+		/* Height... */
+		if (image_metadata[1] == 0) {
+			*height = 256;
+		} else if (image_metadata[1] > *width) {
+			*height = image_metadata[0];
+		}
+	}
+
+	g_input_stream_close (G_INPUT_STREAM (stream), NULL, NULL);
+	g_object_unref (stream);
+	g_object_unref (file);
+	return TRUE;
+}
+
+static void
+extract_icon (const gchar          *uri,
+              TrackerSparqlBuilder *preupdate,
+              TrackerSparqlBuilder *metadata)
+{
+	guint max_width;
+	guint max_height;
+
+	/* The Windows Icon file format may contain the same icon with different
+	 * sizes inside, so there's no clear way of setting single width and
+	 * height values. Thus, we set maximum sizes found. */
+	tracker_sparql_builder_predicate (metadata, "a");
+	tracker_sparql_builder_object (metadata, "nfo:Image");
+	tracker_sparql_builder_object (metadata, "nfo:Icon");
+
+	if (find_max_width_and_height (uri, &max_width, &max_height)) {
+		if (max_width > 0) {
+			tracker_sparql_builder_predicate (metadata, "nfo:width");
+			tracker_sparql_builder_object_int64 (metadata, (gint64) max_width);
+		}
+		if (max_height > 0) {
+			tracker_sparql_builder_predicate (metadata, "nfo:height");
+			tracker_sparql_builder_object_int64 (metadata, (gint64) max_height);
+		}
+	}
+}
+
+TrackerExtractData *
+tracker_extract_get_data (void)
+{
+	return data;
+}



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