[gthumb] raw: added a metadata provider to read the image size
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] raw: added a metadata provider to read the image size
- Date: Sun, 30 Jun 2013 08:39:38 +0000 (UTC)
commit eb22c115c77dfe8c6da15f073d91d85a8e4eb6e6
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Jun 24 10:09:03 2013 +0200
raw: added a metadata provider to read the image size
extensions/raw_files/Makefile.am | 11 ++-
extensions/raw_files/gth-metadata-provider-raw.c | 145 ++++++++++++++++++++++
extensions/raw_files/gth-metadata-provider-raw.h | 51 ++++++++
extensions/raw_files/main.c | 50 +++++---
extensions/raw_files/main.h | 30 +++++
gthumb/gth-main.c | 34 +++++-
gthumb/gth-main.h | 3 +
7 files changed, 298 insertions(+), 26 deletions(-)
---
diff --git a/extensions/raw_files/Makefile.am b/extensions/raw_files/Makefile.am
index 3f941b5..d455d26 100644
--- a/extensions/raw_files/Makefile.am
+++ b/extensions/raw_files/Makefile.am
@@ -1,8 +1,15 @@
extensiondir = $(pkglibdir)/extensions
extension_LTLIBRARIES = libraw_files.la
-libraw_files_la_SOURCES = \
- main.c
+libraw_files_la_SOURCES = \
+ main.c \
+ main.h
+
+if ENABLE_LIBRAW
+libraw_files_la_SOURCES += \
+ gth-metadata-provider-raw.c \
+ gth-metadata-provider-raw.h
+endif
libraw_files_la_CFLAGS = $(GTHUMB_CFLAGS) $(LIBRAW_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
libraw_files_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
diff --git a/extensions/raw_files/gth-metadata-provider-raw.c
b/extensions/raw_files/gth-metadata-provider-raw.c
new file mode 100644
index 0000000..675f0f9
--- /dev/null
+++ b/extensions/raw_files/gth-metadata-provider-raw.c
@@ -0,0 +1,145 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <gthumb.h>
+#include <libraw.h>
+#include "gth-metadata-provider-raw.h"
+#include "main.h"
+
+
+G_DEFINE_TYPE (GthMetadataProviderRaw, gth_metadata_provider_raw, GTH_TYPE_METADATA_PROVIDER)
+
+
+static gboolean
+gth_metadata_provider_raw_can_read (GthMetadataProvider *self,
+ const char *mime_type,
+ char **attribute_v)
+{
+ return _g_file_attributes_matches_any_v ("general::format,"
+ "general::dimensions,"
+ "image::width,"
+ "image::height,"
+ "frame::width,"
+ "frame::height",
+ attribute_v);
+}
+
+
+static gboolean
+supported_mime_type (GthFileData *file_data)
+{
+ const char *mime_type;
+ int i;
+
+ mime_type = gth_file_data_get_mime_type (file_data);
+ for (i = 0; raw_mime_types[i] != NULL; i++) {
+ if (g_strcmp0 (raw_mime_types[i], mime_type) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+static void
+gth_metadata_provider_raw_read (GthMetadataProvider *self,
+ GthFileData *file_data,
+ const char *attributes,
+ GCancellable *cancellable)
+{
+ libraw_data_t *raw_data;
+ GInputStream *istream = NULL;
+ int result;
+ void *buffer;
+ size_t buffer_size;
+ char *size;
+ guint width, height;
+
+ if (! supported_mime_type (file_data))
+ return;
+
+ raw_data = libraw_init (LIBRAW_OPIONS_NO_MEMERR_CALLBACK | LIBRAW_OPIONS_NO_DATAERR_CALLBACK);
+ if (raw_data == NULL)
+ goto fatal_error;
+
+ istream = (GInputStream *) g_file_read (file_data->file, cancellable, NULL);
+ if (istream == NULL)
+ goto fatal_error;
+
+ if (! _g_input_stream_read_all (istream, &buffer, &buffer_size, cancellable, NULL))
+ goto fatal_error;
+
+ result = libraw_open_buffer (raw_data, buffer, buffer_size);
+ if (LIBRAW_FATAL_ERROR (result))
+ goto fatal_error;
+
+ width = raw_data->sizes.iwidth;
+ height = raw_data->sizes.iheight;
+
+ switch (raw_data->sizes.flip) {
+ case 5: /* 270 degrees */
+ case 6: /* 90 degrees */
+ {
+ int tmp = width;
+ width = height;
+ height = tmp;
+ break;
+ }
+ default:
+ break;
+ }
+
+ g_file_info_set_attribute_string (file_data->info, "general::format", _("RAW Format"));
+ g_file_info_set_attribute_int32 (file_data->info, "image::width", width);
+ g_file_info_set_attribute_int32 (file_data->info, "image::height", height);
+ g_file_info_set_attribute_int32 (file_data->info, "frame::width", width);
+ g_file_info_set_attribute_int32 (file_data->info, "frame::height", height);
+
+ size = g_strdup_printf (_("%d × %d"), width, height);
+ g_file_info_set_attribute_string (file_data->info, "general::dimensions", size);
+ g_free (size);
+
+ fatal_error:
+
+ if (raw_data != NULL)
+ libraw_close (raw_data);
+ g_free (buffer);
+ _g_object_unref (istream);
+}
+
+
+static void
+gth_metadata_provider_raw_class_init (GthMetadataProviderRawClass *klass)
+{
+ GthMetadataProviderClass *metadata_provider_class;
+
+ metadata_provider_class = GTH_METADATA_PROVIDER_CLASS (klass);
+ metadata_provider_class->can_read = gth_metadata_provider_raw_can_read;
+ metadata_provider_class->read = gth_metadata_provider_raw_read;
+}
+
+
+static void
+gth_metadata_provider_raw_init (GthMetadataProviderRaw *self)
+{
+ /* void */
+}
diff --git a/extensions/raw_files/gth-metadata-provider-raw.h
b/extensions/raw_files/gth-metadata-provider-raw.h
new file mode 100644
index 0000000..6406c68
--- /dev/null
+++ b/extensions/raw_files/gth-metadata-provider-raw.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_METADATA_PROVIDER_RAW_H
+#define GTH_METADATA_PROVIDER_RAW_H
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gthumb.h>
+
+#define GTH_TYPE_METADATA_PROVIDER_RAW (gth_metadata_provider_raw_get_type ())
+#define GTH_METADATA_PROVIDER_RAW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GTH_TYPE_METADATA_PROVIDER_RAW, GthMetadataProviderRaw))
+#define GTH_METADATA_PROVIDER_RAW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),
GTH_TYPE_METADATA_PROVIDER_RAW, GthMetadataProviderRawClass))
+#define GTH_IS_METADATA_PROVIDER_RAW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GTH_TYPE_METADATA_PROVIDER_RAW))
+#define GTH_IS_METADATA_PROVIDER_RAW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),
GTH_TYPE_METADATA_PROVIDER_RAW))
+#define GTH_METADATA_PROVIDER_RAW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o),
GTH_TYPE_METADATA_PROVIDER_RAW, GthMetadataProviderRawClass))
+
+typedef struct _GthMetadataProviderRaw GthMetadataProviderRaw;
+typedef struct _GthMetadataProviderRawClass GthMetadataProviderRawClass;
+
+struct _GthMetadataProviderRaw
+{
+ GthMetadataProvider __parent;
+};
+
+struct _GthMetadataProviderRawClass
+{
+ GthMetadataProviderClass __parent_class;
+};
+
+GType gth_metadata_provider_raw_get_type (void) G_GNUC_CONST;
+
+#endif /* GTH_METADATA_PROVIDER_RAW_H */
diff --git a/extensions/raw_files/main.c b/extensions/raw_files/main.c
index b190218..e402027 100644
--- a/extensions/raw_files/main.c
+++ b/extensions/raw_files/main.c
@@ -21,13 +21,31 @@
#include <config.h>
+#include <glib.h>
+#include "main.h"
-#ifdef ENABLE_LIBRAW
+const char *raw_mime_types[] = {
+ "image/x-adobe-dng",
+ "image/x-canon-cr2",
+ "image/x-canon-crw",
+ "image/x-epson-erf",
+ "image/x-minolta-mrw",
+ "image/x-nikon-nef",
+ "image/x-olympus-orf",
+ "image/x-pentax-pef",
+ "image/x-sony-arw",
+ NULL };
+#ifdef HAVE_LIBRAW
+
+#include <cairo.h>
#include <gtk/gtk.h>
#include <gthumb.h>
+#include <libraw.h>
+#include "gth-metadata-provider-raw.h"
+
static GthImage *
@@ -39,12 +57,15 @@ openraw_pixbuf_animation_new_from_file (GInputStream *istream,
gpointer user_data,
GCancellable *cancellable,
GError **error)
+
+G_MODULE_EXPORT void
+gthumb_extension_activate (void)
{
- return NULL;
+ gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_RAW);
}
-#else /* ! ENABLE_LIBRAW */
+#else /* ! HAVE_LIBRAW */
#define GDK_PIXBUF_ENABLE_BACKEND
@@ -110,7 +131,7 @@ get_file_mtime (const char *path)
static GthImage *
-openraw_pixbuf_animation_new_from_file (GInputStream *istream,
+dcraw_pixbuf_animation_new_from_file (GInputStream *istream,
GthFileData *file_data,
int requested_size,
int *original_width,
@@ -285,27 +306,18 @@ openraw_pixbuf_animation_new_from_file (GInputStream *istream,
}
-#endif
-
-
G_MODULE_EXPORT void
gthumb_extension_activate (void)
{
- gth_main_register_image_loader_func (openraw_pixbuf_animation_new_from_file,
- GTH_IMAGE_FORMAT_GDK_PIXBUF,
- "image/x-adobe-dng",
- "image/x-canon-cr2",
- "image/x-canon-crw",
- "image/x-epson-erf",
- "image/x-minolta-mrw",
- "image/x-nikon-nef",
- "image/x-olympus-orf",
- "image/x-pentax-pef",
- "image/x-sony-arw",
- NULL);
+ gth_main_register_image_loader_func_v (dcraw_pixbuf_animation_new_from_file,
+ GTH_IMAGE_FORMAT_GDK_PIXBUF,
+ raw_mime_types);
}
+#endif
+
+
G_MODULE_EXPORT void
gthumb_extension_deactivate (void)
{
diff --git a/extensions/raw_files/main.h b/extensions/raw_files/main.h
new file mode 100644
index 0000000..a2a39a7
--- /dev/null
+++ b/extensions/raw_files/main.h
@@ -0,0 +1,30 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef GTH_RAW_FILES_MAIN_H
+#define GTH_RAW_FILES_MAIN_H
+
+#include <config.h>
+
+extern const char *raw_mime_types[];
+
+#endif /* GTH_RAW_FILES_MAIN_H */
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index 45406cd..3e7f4f5 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -661,6 +661,18 @@ _gth_main_create_type_spec (GType object_type,
}
+static void
+_register_image_loader_func (GthImageLoaderFunc loader,
+ GthImageFormat native_format,
+ const char *mime_type)
+{
+ char *key;
+
+ key = g_strdup_printf ("%s-%d", mime_type, native_format);
+ g_hash_table_insert (Main->priv->image_loaders, (gpointer) key, loader);
+}
+
+
void
gth_main_register_image_loader_func (GthImageLoaderFunc loader,
GthImageFormat native_format,
@@ -675,11 +687,7 @@ gth_main_register_image_loader_func (GthImageLoaderFunc loader,
va_start (var_args, first_mime_type);
mime_type = first_mime_type;
while (mime_type != NULL) {
- char *key;
-
- key = g_strdup_printf ("%s-%d", mime_type, native_format);
- g_hash_table_insert (Main->priv->image_loaders, (gpointer) key, loader);
-
+ _register_image_loader_func (loader, native_format, mime_type);
mime_type = va_arg (var_args, const char *);
}
va_end (var_args);
@@ -688,6 +696,22 @@ gth_main_register_image_loader_func (GthImageLoaderFunc loader,
}
+void
+gth_main_register_image_loader_func_v (GthImageLoaderFunc loader,
+ GthImageFormat native_format,
+ const char **mime_types)
+{
+ int i;
+
+ g_static_mutex_lock (®ister_mutex);
+
+ for (i = 0; mime_types[i] != NULL; i++)
+ _register_image_loader_func (loader, native_format, mime_types[i]);
+
+ g_static_mutex_unlock (®ister_mutex);
+}
+
+
GthImageLoaderFunc
gth_main_get_image_loader_func (const char *mime_type,
GthImageFormat preferred_format)
diff --git a/gthumb/gth-main.h b/gthumb/gth-main.h
index 90ec628..9e9fe3c 100644
--- a/gthumb/gth-main.h
+++ b/gthumb/gth-main.h
@@ -90,6 +90,9 @@ void gth_main_register_image_loader_func (GthImageLoaderFun
GthImageFormat native_format,
const char *first_mime_type,
...);
+void gth_main_register_image_loader_func_v (GthImageLoaderFunc loader,
+ GthImageFormat native_format,
+ const char **mime_types);
GthImageLoaderFunc gth_main_get_image_loader_func (const char *mime_type,
GthImageFormat preferred_format);
GthImageSaver * gth_main_get_image_saver (const char *mime_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]