diff options
author | Tam Merlant <tam.ille@free.fr> | 2011-11-03 15:59:11 +0100 |
---|---|---|
committer | Nick Schermer <nick@xfce.org> | 2011-11-03 16:11:28 +0100 |
commit | 9678fcbc942ae752571438ad7723e64b982a3302 (patch) | |
tree | 040fc27d190f50cc8d3e473e00ba19c82122d90e /plugins/raw-thumbnailer | |
parent | 14bcb51730324e875478d7b7b98093bd18cf8937 (diff) | |
download | tumbler-9678fcbc942ae752571438ad7723e64b982a3302.tar.gz |
Implement a raw thumbnailer using libopenraw.
Diffstat (limited to 'plugins/raw-thumbnailer')
-rw-r--r-- | plugins/raw-thumbnailer/Makefile.am | 62 | ||||
-rw-r--r-- | plugins/raw-thumbnailer/raw-thumbnailer-plugin.c | 91 | ||||
-rw-r--r-- | plugins/raw-thumbnailer/raw-thumbnailer-provider.c | 138 | ||||
-rw-r--r-- | plugins/raw-thumbnailer/raw-thumbnailer-provider.h | 43 | ||||
-rw-r--r-- | plugins/raw-thumbnailer/raw-thumbnailer.c | 175 | ||||
-rw-r--r-- | plugins/raw-thumbnailer/raw-thumbnailer.h | 46 |
6 files changed, 555 insertions, 0 deletions
diff --git a/plugins/raw-thumbnailer/Makefile.am b/plugins/raw-thumbnailer/Makefile.am new file mode 100644 index 0000000..c7e39c0 --- /dev/null +++ b/plugins/raw-thumbnailer/Makefile.am @@ -0,0 +1,62 @@ +# vi:set ts=8 sw=8 noet ai nocindent: +# - +# Copyright (c) 2011 Nick Schermer <nick@xfce.org> +# +# 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. + +if TUMBLER_RAW_THUMBNAILER + +tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins +tumbler_plugin_LTLIBRARIES = \ + tumbler-raw-thumbnailer.la + +tumbler_raw_thumbnailer_la_SOURCES = \ + raw-thumbnailer-plugin.c \ + raw-thumbnailer-provider.c \ + raw-thumbnailer-provider.h \ + raw-thumbnailer.c \ + raw-thumbnailer.h + +tumbler_raw_thumbnailer_la_CFLAGS = \ + -I$(top_builddir) \ + -I$(top_builddir)/plugins \ + -I$(top_srcdir) \ + -I$(top_srcdir)/plugins \ + -DG_LOG_DOMAIN=\"tumbler-raw-thumbnailer\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(GDK_PIXBUF_CFLAGS) \ + $(GIO_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(LIBOPENRAW_GNOME_CFLAGS) \ + $(PLATFORM_CPPFLAGS) + +tumbler_raw_thumbnailer_la_LDFLAGS = \ + -avoid-version \ + -export-dynamic \ + -module \ + $(PLATFORM_LDFLAGS) + +tumbler_raw_thumbnailer_la_LIBADD = \ + $(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la \ + $(GDK_PIXBUF_LIBS) \ + $(GIO_LIBS) \ + $(GLIB_LIBS) \ + $(LIBOPENRAW_GNOME_LIBS) + +tumbler_raw_thumbnailer_la_DEPENDENCIES = \ + $(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la + +endif diff --git a/plugins/raw-thumbnailer/raw-thumbnailer-plugin.c b/plugins/raw-thumbnailer/raw-thumbnailer-plugin.c new file mode 100644 index 0000000..0be36ca --- /dev/null +++ b/plugins/raw-thumbnailer/raw-thumbnailer-plugin.c @@ -0,0 +1,91 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> +#include <glib/gi18n.h> +#include <glib-object.h> + +#include <tumbler/tumbler.h> + +#include "raw-thumbnailer-provider.h" +#include "raw-thumbnailer.h" + + + +G_MODULE_EXPORT void tumbler_plugin_initialize (TumblerProviderPlugin *plugin); +G_MODULE_EXPORT void tumbler_plugin_shutdown (void); +G_MODULE_EXPORT void tumbler_plugin_get_types (const GType **types, + gint *n_types); + + + +static GType type_list[1]; + + + +void +tumbler_plugin_initialize (TumblerProviderPlugin *plugin) +{ + const gchar *mismatch; + + /* verify that the tumbler versions are compatible */ + mismatch = tumbler_check_version (TUMBLER_MAJOR_VERSION, TUMBLER_MINOR_VERSION, + TUMBLER_MICRO_VERSION); + if (G_UNLIKELY (mismatch != NULL)) + { + g_warning (_("Version mismatch: %s"), mismatch); + return; + } + +#ifdef DEBUG + g_message (_("Initializing the Tumbler Raw Thumbnailer plugin")); +#endif + + /* register the types provided by this plugin */ + raw_thumbnailer_register (plugin); + raw_thumbnailer_provider_register (plugin); + + /* set up the plugin provider type list */ + type_list[0] = TYPE_RAW_THUMBNAILER_PROVIDER; +} + + + +void +tumbler_plugin_shutdown (void) +{ +#ifdef DEBUG + g_message (_("Shutting down the Tumbler Raw Thumbnailer plugin")); +#endif +} + + + +void +tumbler_plugin_get_types (const GType **types, + gint *n_types) +{ + *types = type_list; + *n_types = G_N_ELEMENTS (type_list); +} diff --git a/plugins/raw-thumbnailer/raw-thumbnailer-provider.c b/plugins/raw-thumbnailer/raw-thumbnailer-provider.c new file mode 100644 index 0000000..de1b04b --- /dev/null +++ b/plugins/raw-thumbnailer/raw-thumbnailer-provider.c @@ -0,0 +1,138 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> +#include <glib-object.h> + +/* #include <gdk-pixbuf/gdk-pixbuf.h> */ + +#include <tumbler/tumbler.h> + +#include "raw-thumbnailer-provider.h" +#include "raw-thumbnailer.h" + + + +static void raw_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface); +static GList *raw_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider); + + + +struct _RawThumbnailerProviderClass +{ + GObjectClass __parent__; +}; + +struct _RawThumbnailerProvider +{ + GObject __parent__; +}; + + + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (RawThumbnailerProvider, + raw_thumbnailer_provider, + G_TYPE_OBJECT, + 0, + TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER, + raw_thumbnailer_provider_thumbnailer_provider_init)); + + + +void +raw_thumbnailer_provider_register (TumblerProviderPlugin *plugin) +{ + raw_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin)); +} + + + +static void +raw_thumbnailer_provider_class_init (RawThumbnailerProviderClass *klass) +{ +} + + + +static void +raw_thumbnailer_provider_class_finalize (RawThumbnailerProviderClass *klass) +{ +} + + + +static void +raw_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface) +{ + iface->get_thumbnailers = raw_thumbnailer_provider_get_thumbnailers; +} + + + +static void +raw_thumbnailer_provider_init (RawThumbnailerProvider *provider) +{ +} + + + +static GList * +raw_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider) +{ + RawThumbnailer *thumbnailer; + GList *thumbnailers = NULL; + GStrv uri_schemes; + const gchar *mime_types[] = + { + "image/x-adobe-dng", + "image/x-canon-cr2", + "image/x-canon-crw", + "image/x-epson-erf", + "image/x-nikon-nef", + "image/x-nikon-nrw", + "image/x-olympus-orf", + "image/x-panasonic-raw", + "image/x-panasonic-rw2", + "image/x-pentax-pef", + "image/x-sony-arw", + "image/x-minolta-mrw", + NULL + }; + + /* determine which URI schemes are supported by GIO */ + uri_schemes = tumbler_util_get_supported_uri_schemes (); + + /* create the raw thumbnailer */ + thumbnailer = g_object_new (TYPE_RAW_THUMBNAILER, + "uri-schemes", uri_schemes, "mime-types", mime_types, + NULL); + + /* free URI schemes and MIME types */ + g_strfreev (uri_schemes); + + /* add the thumbnailer to the list */ + thumbnailers = g_list_append (thumbnailers, thumbnailer); + + return thumbnailers; +} diff --git a/plugins/raw-thumbnailer/raw-thumbnailer-provider.h b/plugins/raw-thumbnailer/raw-thumbnailer-provider.h new file mode 100644 index 0000000..019f6d5 --- /dev/null +++ b/plugins/raw-thumbnailer/raw-thumbnailer-provider.h @@ -0,0 +1,43 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __RAW_THUMBNAILER_PROVIDER_H__ +#define __RAW_THUMBNAILER_PROVIDER_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define TYPE_RAW_THUMBNAILER_PROVIDER (raw_thumbnailer_provider_get_type ()) +#define RAW_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RAW_THUMBNAILER_PROVIDER, RawThumbnailerProvider)) +#define RAW_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RAW_THUMBNAILER_PROVIDER, RawThumbnailerProviderClass)) +#define IS_RAW_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RAW_THUMBNAILER_PROVIDER)) +#define IS_RAW_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RAW_THUMBNAILER_PROVIDER) +#define RAW_THUMBNAILER_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RAW_THUMBNAILER_PROVIDER, RawThumbnailerProviderClass)) + +typedef struct _RawThumbnailerProviderClass RawThumbnailerProviderClass; +typedef struct _RawThumbnailerProvider RawThumbnailerProvider; + +GType raw_thumbnailer_provider_get_type (void) G_GNUC_CONST; +void raw_thumbnailer_provider_register (TumblerProviderPlugin *plugin); + +G_END_DECLS + +#endif /* !__RAW_THUMBNAILER_PROVIDER_H__ */ diff --git a/plugins/raw-thumbnailer/raw-thumbnailer.c b/plugins/raw-thumbnailer/raw-thumbnailer.c new file mode 100644 index 0000000..af3fd33 --- /dev/null +++ b/plugins/raw-thumbnailer/raw-thumbnailer.c @@ -0,0 +1,175 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> + * Copyright (c) 2011 Tam Merlant <tam.ille@free.fr> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <sys/types.h> +#include <fcntl.h> +#include <memory.h> +#include <setjmp.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <math.h> + +#include <glib.h> +#include <glib/gi18n.h> +#include <glib-object.h> + +#include <tumbler/tumbler.h> + +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <libopenraw-gnome/gdkpixbuf.h> + +#include "raw-thumbnailer.h" + +static void raw_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info); + + + +struct _RawThumbnailerClass +{ + TumblerAbstractThumbnailerClass __parent__; +}; + +struct _RawThumbnailer +{ + TumblerAbstractThumbnailer __parent__; +}; + + + +G_DEFINE_DYNAMIC_TYPE (RawThumbnailer, + raw_thumbnailer, + TUMBLER_TYPE_ABSTRACT_THUMBNAILER); + + + +void +raw_thumbnailer_register (TumblerProviderPlugin *plugin) +{ + raw_thumbnailer_register_type (G_TYPE_MODULE (plugin)); +} + + + +static void +raw_thumbnailer_class_init (RawThumbnailerClass *klass) +{ + TumblerAbstractThumbnailerClass *abstractthumbnailer_class; + + abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass); + abstractthumbnailer_class->create = raw_thumbnailer_create; +} + + + +static void +raw_thumbnailer_class_finalize (RawThumbnailerClass *klass) +{ +} + + + +static void +raw_thumbnailer_init (RawThumbnailer *thumbnailer) +{ +} + + + +static void +raw_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info) +{ + TumblerThumbnailFlavor *flavor; + TumblerImageData data; + TumblerThumbnail *thumbnail; + const gchar *uri; + gchar *path; + GdkPixbuf *pixbuf = NULL; + GError *error = NULL; + GFile *file; + gint height; + gint width; + + g_return_if_fail (IS_RAW_THUMBNAILER (thumbnailer)); + g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + g_return_if_fail (TUMBLER_IS_FILE_INFO (info)); + + /* do nothing if cancelled */ + if (g_cancellable_is_cancelled (cancellable)) + return; + + uri = tumbler_file_info_get_uri (info); + file = g_file_new_for_uri (uri); + + thumbnail = tumbler_file_info_get_thumbnail (info); + g_assert (thumbnail != NULL); + + /* libopenraw only handles local IO */ + path = g_file_get_path (file); + if (path != NULL && g_path_is_absolute (path)) + { + flavor = tumbler_thumbnail_get_flavor (thumbnail); + g_assert (flavor != NULL); + tumbler_thumbnail_flavor_get_size (flavor, &width, &height); + g_object_unref (flavor); + + pixbuf = or_gdkpixbuf_extract_rotated_thumbnail (path, MIN (width, height)); + } + + g_free (path); + g_object_unref (file); + + if (pixbuf != NULL) + { + data.data = gdk_pixbuf_get_pixels (pixbuf); + data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); + data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf); + data.width = gdk_pixbuf_get_width (pixbuf); + data.height = gdk_pixbuf_get_height (pixbuf); + data.rowstride = gdk_pixbuf_get_rowstride (pixbuf); + data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (pixbuf); + + tumbler_thumbnail_save_image_data (thumbnail, &data, + tumbler_file_info_get_mtime (info), + NULL, &error); + } + + if (error != NULL) + { + g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message); + g_error_free (error); + } + else + { + g_signal_emit_by_name (thumbnailer, "ready", uri); + g_object_unref (pixbuf); + } + + g_object_unref (thumbnail); +} diff --git a/plugins/raw-thumbnailer/raw-thumbnailer.h b/plugins/raw-thumbnailer/raw-thumbnailer.h new file mode 100644 index 0000000..0155d22 --- /dev/null +++ b/plugins/raw-thumbnailer/raw-thumbnailer.h @@ -0,0 +1,46 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org> + * Copyright (c) 2011 Tam Merlant <tam.ille@free.fr> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __RAW_THUMBNAILER_H__ +#define __RAW_THUMBNAILER_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define TYPE_RAW_THUMBNAILER (raw_thumbnailer_get_type ()) +#define RAW_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RAW_THUMBNAILER, RawThumbnailer)) +#define RAW_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RAW_THUMBNAILER, RawThumbnailerClass)) +#define IS_RAW_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RAW_THUMBNAILER)) +#define IS_RAW_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_RAW_THUMBNAILER) +#define RAW_THUMBNAILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_RAW_THUMBNAILER, RawThumbnailerClass)) + + + +typedef struct _RawThumbnailerClass RawThumbnailerClass; +typedef struct _RawThumbnailer RawThumbnailer; + +GType raw_thumbnailer_get_type (void) G_GNUC_CONST; +void raw_thumbnailer_register (TumblerProviderPlugin *plugin); + +G_END_DECLS + +#endif /* !__RAW_THUMBNAILER_H__ */ |