Commit 75bc91f8 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[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.
parent 76bfb1a7
......@@ -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;
}
......@@ -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
......
......@@ -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]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment