[gthumb] [exiv2_tools] generate the thumbnail from the embedded data
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] [exiv2_tools] generate the thumbnail from the embedded data
- Date: Fri, 26 Mar 2010 16:52:06 +0000 (UTC)
commit 75bc91f879bc78dd4afdfe5c836fb4a6abaf0a11
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Mar 26 16:30:24 2010 +0100
[exiv2_tools] generate the thumbnail from the embedded data
implemented a "generate-thumbnail" hook that read the thumbnail
from the exif metadata to speed-up the thumbnail generation process
for jpeg and tiff images with embedded thumbnails.
extensions/exiv2_tools/exiv2-utils.cpp | 64 ++++++++++++++++++++++++++++++++
extensions/exiv2_tools/exiv2-utils.h | 35 +++++++++--------
extensions/exiv2_tools/main.c | 1 +
3 files changed, 84 insertions(+), 16 deletions(-)
---
diff --git a/extensions/exiv2_tools/exiv2-utils.cpp b/extensions/exiv2_tools/exiv2-utils.cpp
index 74df98a..858d851 100644
--- a/extensions/exiv2_tools/exiv2-utils.cpp
+++ b/extensions/exiv2_tools/exiv2-utils.cpp
@@ -22,6 +22,8 @@
#include <config.h>
#include <glib.h>
+#define GDK_PIXBUF_ENABLE_BACKEND
+#include <gdk-pixbuf/gdk-pixbuf-io.h>
#include <exiv2/basicio.hpp>
#include <exiv2/error.hpp>
#include <exiv2/image.hpp>
@@ -825,3 +827,65 @@ exiv2_write_metadata_to_buffer (void **buffer,
return TRUE;
}
+
+
+GdkPixbuf *
+exiv2_generate_thumbnail (const char *uri,
+ const char *mime_type,
+ int size)
+{
+ GdkPixbuf *pixbuf = NULL;
+
+ if (! _g_content_type_is_a (mime_type, "image/jpeg")
+ && ! _g_content_type_is_a (mime_type, "image/tiff"))
+ {
+ return NULL;
+ }
+
+ try {
+ char *path;
+
+ path = g_filename_from_uri (uri, NULL, NULL);
+ if (path != NULL) {
+ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (path);
+ image->readMetadata ();
+ Exiv2::ExifThumbC exifThumb (image->exifData ());
+ Exiv2::DataBuf thumb = exifThumb.copy ();
+
+ if (thumb.pData_ != NULL) {
+ GInputStream *stream = g_memory_input_stream_new_from_data (thumb.pData_, thumb.size_, NULL);
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+
+ Exiv2::ExifData &ed = image->exifData();
+ long w = ed["Exif.Photo.PixelXDimension"].toLong();
+ if (w > 0) {
+ char *s;
+
+ s = g_strdup_printf ("%ld", w);
+ gdk_pixbuf_set_option (pixbuf, "tEXt::Thumb::Image::Width", s);
+ g_object_set_data (G_OBJECT (pixbuf), "gnome-original-width", GINT_TO_POINTER ((int) w));
+
+ g_free (s);
+ }
+ long h = ed["Exif.Photo.PixelYDimension"].toLong();
+ if (h > 0) {
+ char *s;
+
+ s = g_strdup_printf ("%ld", w);
+ gdk_pixbuf_set_option (pixbuf, "tEXt::Thumb::Image::Height", s);
+ g_object_set_data (G_OBJECT (pixbuf), "gnome-original-height", GINT_TO_POINTER ((int) h));
+
+ g_free (s);
+ }
+
+ g_object_unref (stream);
+ }
+
+ g_free (path);
+ }
+ }
+ catch (Exiv2::AnyError& e) {
+ }
+
+ return pixbuf;
+}
diff --git a/extensions/exiv2_tools/exiv2-utils.h b/extensions/exiv2_tools/exiv2-utils.h
index 083e739..29771de 100644
--- a/extensions/exiv2_tools/exiv2-utils.h
+++ b/extensions/exiv2_tools/exiv2-utils.h
@@ -29,22 +29,25 @@
G_BEGIN_DECLS
-gboolean exiv2_read_metadata_from_file (GFile *file,
- GFileInfo *info,
- GError **error);
-gboolean exiv2_read_metadata_from_buffer (void *buffer,
- gsize buffer_size,
- GFileInfo *info,
- GError **error);
-gboolean exiv2_read_sidecar (GFile *file,
- GFileInfo *info);
-gboolean exiv2_write_metadata (SavePixbufData *data);
-gboolean exiv2_write_metadata_to_buffer (void **buffer,
- gsize *buffer_size,
- GFileInfo *info,
- GdkPixbuf *pixbuf, /* optional */
- GError **error);
-gboolean exiv2_supports_writes (const char *mime_type);
+gboolean exiv2_read_metadata_from_file (GFile *file,
+ GFileInfo *info,
+ GError **error);
+gboolean exiv2_read_metadata_from_buffer (void *buffer,
+ gsize buffer_size,
+ GFileInfo *info,
+ GError **error);
+gboolean exiv2_read_sidecar (GFile *file,
+ GFileInfo *info);
+gboolean exiv2_supports_writes (const char *mime_type);
+gboolean exiv2_write_metadata (SavePixbufData *data);
+gboolean exiv2_write_metadata_to_buffer (void **buffer,
+ gsize *buffer_size,
+ GFileInfo *info,
+ GdkPixbuf *pixbuf, /* optional */
+ GError **error);
+GdkPixbuf *exiv2_generate_thumbnail (const char *uri,
+ const char *mime_type,
+ int size);
G_END_DECLS
diff --git a/extensions/exiv2_tools/main.c b/extensions/exiv2_tools/main.c
index a9c55b9..00fd67a 100644
--- a/extensions/exiv2_tools/main.c
+++ b/extensions/exiv2_tools/main.c
@@ -230,6 +230,7 @@ gthumb_extension_activate (void)
gth_hook_add_callback ("save-pixbuf", 10, G_CALLBACK (exiv2_write_metadata), NULL);
if (gth_hook_present ("jpegtran-after"))
gth_hook_add_callback ("jpegtran-after", 10, G_CALLBACK (exiv2_jpeg_tran_cb), NULL);
+ gth_hook_add_callback ("generate-thumbnail", 10, G_CALLBACK (exiv2_generate_thumbnail), NULL);
for (i = 0; i < G_N_ELEMENTS (exiv2_sort_types); i++)
gth_main_register_sort_type (&exiv2_sort_types[i]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]