[tracker/albumart-quill] Allowing different image libraries to deal with albumart image formats
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/albumart-quill] Allowing different image libraries to deal with albumart image formats
- Date: Mon, 2 Nov 2009 15:52:42 +0000 (UTC)
commit 2528d9be6cd10f05d215907052a309b34fdc8948
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Nov 2 16:50:59 2009 +0100
Allowing different image libraries to deal with albumart image formats
Split the code that uses pixbuf out of tracker-albumart.c into four files:
- tracker-albumart-quill.cpp : C++ code that uses libquill for this
- tracker-albumart-pixbuf.c : C code that uses GdkPixbuf forthis
- tracker-albumart-dummy.c : C code that does nothing but return FALSE,
elected in case both are absent
- tracker-albumart-generic.h : Generic API for above
configure.ac | 11 ++-
src/tracker-extract/Makefile.am | 12 +++-
src/tracker-extract/tracker-albumart-dummy.c | 40 +++++++++
src/tracker-extract/tracker-albumart-generic.h | 37 ++++++++
src/tracker-extract/tracker-albumart-pixbuf.c | 111 ++++++++++++++++++++++++
src/tracker-extract/tracker-albumart-quill.cpp | 40 +++++++++
src/tracker-extract/tracker-albumart.c | 103 +++-------------------
7 files changed, 262 insertions(+), 92 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 441b4b8..935ff61 100644
--- a/configure.ac
+++ b/configure.ac
@@ -139,6 +139,7 @@ LIBNOTIFY_REQUIRED=0.4.3
HAL_REQUIRED=0.5
DEVKIT_POWER_REQUIRED=007
GDKPIXBUF_REQUIRED=2.12.0
+QUILL_REQUIRED=1.0.0
UNAC_REQUIRED=1.0.0
POPPLER_GLIB_REQUIRED=0.4.5
CAIRO_REQUIRED=1.0
@@ -447,7 +448,7 @@ fi
AM_CONDITIONAL(HAVE_LIBXML2, test "x$have_libxml2" = "xyes")
##################################################################
-# Check for GdkPixbuf, needed for the MP3 album art extractor
+# Check for GdkPixbuf or QUILL, needed for the MP3 album art extractor
##################################################################
AC_ARG_ENABLE(gdkpixbuf,
@@ -466,7 +467,13 @@ if test "x$enable_gdkpixbuf" != "xno"; then
if test "x$have_gdkpixbuf" = "xyes"; then
AC_DEFINE(HAVE_GDKPIXBUF, [], [Define if we have GdkPixbuf])
fi
+
+ have_quill="no"
else
+ PKG_CHECK_MODULES(QUILL,
+ [quill >= $QUILL_REQUIRED],
+ [have_quill=yes],
+ [have_quill=no])
have_gdkpixbuf="no (disabled)"
fi
@@ -477,6 +484,8 @@ if test "x$enable_gdkpixbuf" = "xyes"; then
fi
AM_CONDITIONAL(HAVE_GDKPIXBUF, test "x$have_gdkpixbuf" = "xyes")
+AM_CONDITIONAL(HAVE_QUILL, test "x$have_quill" = "xyes")
+
####################################################################
# Check for GStreamer or Xine. Otherwise, call an external video
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index b098bd8..f4f16f1 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -256,7 +256,8 @@ tracker_extract_SOURCES = \
tracker-fts-config.c \
tracker-fts-config.h \
tracker-main.c \
- tracker-main.h
+ tracker-main.h \
+ tracker-albumart-generic.h
tracker_extract_LDADD = \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
@@ -273,6 +274,15 @@ endif
if HAVE_GDKPIXBUF
tracker_extract_LDADD += $(GDKPIXBUF_LIBS)
+tracker_extract_SOURCES += tracker-albumart-pixbuf.c
+else
+if HAVE_QUILL
+INCLUDES += $(QUILL_CFLAGS)
+tracker_extract_SOURCES += tracker-albumart-quill.c
+tracker_extract_LDADD += $(QUILL_LIBS)
+else
+tracker_extract_SOURCES += tracker-albumart-dummy.c
+endif
endif
marshal_sources = \
diff --git a/src/tracker-extract/tracker-albumart-dummy.c b/src/tracker-extract/tracker-albumart-dummy.c
new file mode 100644
index 0000000..440c47d
--- /dev/null
+++ b/src/tracker-extract/tracker-albumart-dummy.c
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * 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.
+ *
+ * Authors:
+ * Philip Van Hoof <philip codeminded be>
+ */
+
+#include "tracker-albumart-generic.h"
+
+gboolean
+tracker_albumart_file_to_jpeg (const gchar *filename,
+ const gchar *target)
+{
+ return FALSE;
+}
+
+gboolean
+tracker_albumart_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target)
+{
+ return FALSE;
+}
diff --git a/src/tracker-extract/tracker-albumart-generic.h b/src/tracker-extract/tracker-albumart-generic.h
new file mode 100644
index 0000000..a6bb974
--- /dev/null
+++ b/src/tracker-extract/tracker-albumart-generic.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * 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.
+ *
+ * Authors:
+ * Philip Van Hoof <philip codeminded be>
+ */
+
+#ifndef __TRACKER_ALBUMART_GENERIC_H__
+#define __TRACKER_ALBUMART_GENERIC_H__
+
+#include <glib.h>
+
+gboolean tracker_albumart_file_to_jpeg (const gchar *filename,
+ const gchar *target);
+gboolean tracker_albumart_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target);
+
+
+#endif /* __TRACKER_ALBUMART_GENERIC_H__ */
diff --git a/src/tracker-extract/tracker-albumart-pixbuf.c b/src/tracker-extract/tracker-albumart-pixbuf.c
new file mode 100644
index 0000000..cbda326
--- /dev/null
+++ b/src/tracker-extract/tracker-albumart-pixbuf.c
@@ -0,0 +1,111 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * 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.
+ *
+ * Authors:
+ * Philip Van Hoof <philip codeminded be>
+ */
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "tracker-albumart-generic.h"
+
+gboolean
+tracker_albumart_file_to_jpeg (const gchar *filename,
+ const gchar *target)
+{
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+
+ pixbuf = gdk_pixbuf_new_from_file (filename, &error);
+
+ if (error) {
+ g_clear_error (&error);
+
+ return FALSE;
+ } else {
+ gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL);
+ g_object_unref (pixbuf);
+
+ if (error) {
+ g_clear_error (&error);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+gboolean
+tracker_albumart_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target)
+{
+ if (g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
+ g_strcmp0 (buffer_mime, "JPG") == 0) {
+
+ g_debug ("Saving album art using raw data as uri:'%s'",
+ target);
+
+ g_file_set_contents (target, buffer, (gssize) len, NULL);
+ } else {
+ GdkPixbuf *pixbuf;
+ GdkPixbufLoader *loader;
+ GError *error = NULL;
+
+ g_debug ("Saving album art using GdkPixbufLoader for uri:'%s'",
+ target);
+
+ loader = gdk_pixbuf_loader_new ();
+
+ if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
+ g_warning ("Could not write with GdkPixbufLoader when setting album art, %s",
+ error ? error->message : "no error given");
+
+ g_clear_error (&error);
+ gdk_pixbuf_loader_close (loader, NULL);
+
+ return FALSE;
+ }
+
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+
+ if (!gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL)) {
+ g_warning ("Could not save GdkPixbuf when setting album art, %s",
+ error ? error->message : "no error given");
+
+ g_clear_error (&error);
+ g_object_unref (pixbuf);
+ gdk_pixbuf_loader_close (loader, NULL);
+
+ return FALSE;
+ }
+
+ g_object_unref (pixbuf);
+
+ if (!gdk_pixbuf_loader_close (loader, &error)) {
+ g_warning ("Could not close GdkPixbufLoader when setting album art, %s",
+ error ? error->message : "no error given");
+ g_clear_error (&error);
+ }
+ }
+
+ return TRUE;
+}
diff --git a/src/tracker-extract/tracker-albumart-quill.cpp b/src/tracker-extract/tracker-albumart-quill.cpp
new file mode 100644
index 0000000..440c47d
--- /dev/null
+++ b/src/tracker-extract/tracker-albumart-quill.cpp
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * 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.
+ *
+ * Authors:
+ * Philip Van Hoof <philip codeminded be>
+ */
+
+#include "tracker-albumart-generic.h"
+
+gboolean
+tracker_albumart_file_to_jpeg (const gchar *filename,
+ const gchar *target)
+{
+ return FALSE;
+}
+
+gboolean
+tracker_albumart_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target)
+{
+ return FALSE;
+}
diff --git a/src/tracker-extract/tracker-albumart.c b/src/tracker-extract/tracker-albumart.c
index aabb5b7..0cc61e7 100644
--- a/src/tracker-extract/tracker-albumart.c
+++ b/src/tracker-extract/tracker-albumart.c
@@ -32,10 +32,6 @@
#include <glib/gstdio.h>
#include <gio/gio.h>
-#ifdef HAVE_GDKPIXBUF
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#endif /* HAVE_GDKPIXBUF */
-
#include <dbus/dbus-glib-bindings.h>
#include <libtracker-common/tracker-storage.h>
@@ -44,15 +40,12 @@
#include "tracker-dbus.h"
#include "tracker-extract.h"
#include "tracker-marshal.h"
+#include "tracker-albumart-generic.h"
#define ALBUMARTER_SERVICE "com.nokia.albumart"
#define ALBUMARTER_PATH "/com/nokia/albumart/Requester"
#define ALBUMARTER_INTERFACE "com.nokia.albumart.Requester"
-#define THUMBNAILER_SERVICE "org.freedesktop.thumbnailer"
-#define THUMBNAILER_PATH "/org/freedesktop/thumbnailer/Generic"
-#define THUMBNAILER_INTERFACE "org.freedesktop.thumbnailer.Generic"
-
typedef struct {
TrackerStorage *hal;
gchar *art_path;
@@ -549,38 +542,23 @@ albumart_heuristic (const gchar *artist,
retval = error != NULL;
g_clear_error (&error);
}
-#ifdef HAVE_GDKPIXBUF
} else if (g_str_has_suffix (name, "png")) {
- GdkPixbuf *pixbuf;
gchar *found;
+ if (!target) {
+ albumart_get_path (artist_stripped,
+ album_stripped,
+ "album",
+ NULL,
+ &target,
+ NULL);
+ }
+
found = g_build_filename (dirname, name, NULL);
g_debug ("Album art (PNG) found in same directory being used:'%s'", found);
-
- pixbuf = gdk_pixbuf_new_from_file (found, &error);
+ retval = tracker_albumart_file_to_jpeg (found, target);
g_free (found);
-
- if (error) {
- g_clear_error (&error);
- retval = FALSE;
- } else {
- if (!target) {
- albumart_get_path (artist_stripped,
- album_stripped,
- "album",
- NULL,
- &target,
- NULL);
- }
-
- gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL);
- g_object_unref (pixbuf);
-
- retval = error != NULL;
- g_clear_error (&error);
- }
}
-#endif /* HAVE_GDKPIXBUF */
}
}
@@ -624,8 +602,6 @@ albumart_signal_queue_thumbnail (const gchar *file,
g_signal_emit_by_name (object, "queue-thumbnail", file, mime);
}
-#ifdef HAVE_GDKPIXBUF
-
static gboolean
albumart_set (const unsigned char *buffer,
size_t len,
@@ -635,6 +611,7 @@ albumart_set (const unsigned char *buffer,
const gchar *uri)
{
gchar *local_path;
+ gboolean retval;
if (!artist && !album) {
g_warning ("Could not save embedded album art, no artist or album supplied");
@@ -643,55 +620,7 @@ albumart_set (const unsigned char *buffer,
albumart_get_path (artist, album, "album", NULL, &local_path, NULL);
- if (g_strcmp0 (mime, "image/jpeg") == 0 ||
- g_strcmp0 (mime, "JPG") == 0) {
- g_debug ("Saving album art using raw data as uri:'%s'",
- local_path);
-
- g_file_set_contents (local_path, buffer, (gssize) len, NULL);
- } else {
- GdkPixbuf *pixbuf;
- GdkPixbufLoader *loader;
- GError *error = NULL;
-
- g_debug ("Saving album art using GdkPixbufLoader for uri:'%s'",
- local_path);
-
- loader = gdk_pixbuf_loader_new ();
-
- if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
- g_warning ("Could not write with GdkPixbufLoader when setting album art, %s",
- error ? error->message : "no error given");
-
- g_clear_error (&error);
- gdk_pixbuf_loader_close (loader, NULL);
- g_free (local_path);
-
- return FALSE;
- }
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-
- if (!gdk_pixbuf_save (pixbuf, local_path, "jpeg", &error, NULL)) {
- g_warning ("Could not save GdkPixbuf when setting album art, %s",
- error ? error->message : "no error given");
-
- g_clear_error (&error);
- g_free (local_path);
- g_object_unref (pixbuf);
- gdk_pixbuf_loader_close (loader, NULL);
-
- return FALSE;
- }
-
- g_object_unref (pixbuf);
-
- if (!gdk_pixbuf_loader_close (loader, &error)) {
- g_warning ("Could not close GdkPixbufLoader when setting album art, %s",
- error ? error->message : "no error given");
- g_clear_error (&error);
- }
- }
+ retval = tracker_albumart_buffer_to_jpeg (buffer, len, mime, local_path);
albumart_signal_queue_thumbnail (local_path, mime);
g_free (local_path);
@@ -699,8 +628,6 @@ albumart_set (const unsigned char *buffer,
return TRUE;
}
-#endif /* HAVE_GDKPIXBUF */
-
static void
albumart_request_download (TrackerStorage *hal,
const gchar *album,
@@ -984,7 +911,6 @@ tracker_albumart_process (const unsigned char *buffer,
}
if (!g_file_test (art_path, G_FILE_TEST_EXISTS)) {
-#ifdef HAVE_GDKPIXBUF
/* If we have embedded album art */
if (buffer && len > 0) {
processed = albumart_set (buffer,
@@ -994,7 +920,6 @@ tracker_albumart_process (const unsigned char *buffer,
album,
filename_uri);
} else {
-#endif /* HAVE_GDK_PIXBUF */
/* If not, we perform a heuristic on the dir */
gchar *key;
gchar *dirname;
@@ -1037,9 +962,7 @@ tracker_albumart_process (const unsigned char *buffer,
} else {
g_free (key);
}
-#ifdef HAVE_GDKPIXBUF
}
-#endif /* HAVE_GDKPIXBUF */
if (processed) {
albumart_signal_queue_thumbnail (filename_uri, "image/jpeg");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]