Commit 49ef5314 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Apply orientation from EXIF data to images

If GTK fails to apply any orientation data from the image file,
then fallback to applying orientation data from the exif
metadata block
parent f2d8f062
......@@ -80,28 +80,21 @@ static void entangle_image_loader_set_property(GObject *object,
static GdkPixbuf *entangle_image_loader_pixbuf_load(EntanglePixbufLoader *loader G_GNUC_UNUSED,
EntangleImage *image)
EntangleImage *image,
GExiv2Metadata **metadata)
{
EntangleImageLoaderPrivate *priv = (ENTANGLE_IMAGE_LOADER(loader))->priv;
g_printerr("Preview %d\n", priv->embeddedPreview);
if (priv->embeddedPreview)
return entangle_pixbuf_open_image(image,
ENTANGLE_PIXBUF_IMAGE_SLOT_PREVIEW);
ENTANGLE_PIXBUF_IMAGE_SLOT_PREVIEW,
TRUE,
metadata);
else
return entangle_pixbuf_open_image(image,
ENTANGLE_PIXBUF_IMAGE_SLOT_MASTER);
}
static GExiv2Metadata *entangle_image_loader_metadata_load(EntanglePixbufLoader *loader G_GNUC_UNUSED,
EntangleImage *image)
{
GExiv2Metadata *metadata = gexiv2_metadata_new();
if (!gexiv2_metadata_open_path(metadata, entangle_image_get_filename(image), NULL)) {
g_object_unref(metadata);
metadata = NULL;
}
return metadata;
ENTANGLE_PIXBUF_IMAGE_SLOT_MASTER,
TRUE,
metadata);
}
......@@ -126,7 +119,6 @@ static void entangle_image_loader_class_init(EntangleImageLoaderClass *klass)
G_PARAM_STATIC_BLURB));
loader_class->pixbuf_load = entangle_image_loader_pixbuf_load;
loader_class->metadata_load = entangle_image_loader_metadata_load;
g_type_class_add_private(klass, sizeof(EntangleImageLoaderPrivate));
}
......@@ -159,6 +151,7 @@ gboolean entangle_image_loader_get_embedded_preview(EntangleImageLoader *loader)
void entangle_image_loader_set_embedded_preview(EntangleImageLoader *loader, gboolean enable)
{
EntangleImageLoaderPrivate *priv = loader->priv;
g_printerr("Set preview %d\n", enable);
priv->embeddedPreview = enable;
entangle_pixbuf_loader_trigger_reload(ENTANGLE_PIXBUF_LOADER(loader));
}
......
......@@ -228,15 +228,12 @@ static gboolean entangle_pixbuf_loader_result(gpointer data)
}
static GdkPixbuf *entangle_pixbuf_load(EntanglePixbufLoader *loader, EntangleImage *image)
static GdkPixbuf *entangle_pixbuf_load(EntanglePixbufLoader *loader, EntangleImage *image,
GExiv2Metadata **metadata)
{
return ENTANGLE_PIXBUF_LOADER_GET_CLASS(loader)->pixbuf_load(loader, image);
return ENTANGLE_PIXBUF_LOADER_GET_CLASS(loader)->pixbuf_load(loader, image, metadata);
}
static GExiv2Metadata *entangle_metadata_load(EntanglePixbufLoader *loader, EntangleImage *image)
{
return ENTANGLE_PIXBUF_LOADER_GET_CLASS(loader)->metadata_load(loader, image);
}
static void entangle_pixbuf_loader_worker(gpointer data,
gpointer opaque)
......@@ -267,7 +264,9 @@ static void entangle_pixbuf_loader_worker(gpointer data,
g_object_ref(transform);
g_mutex_unlock(priv->lock);
pixbuf = entangle_pixbuf_load(loader, image);
pixbuf = entangle_pixbuf_load(loader, image,
priv->withMetadata ?
&result->metadata : NULL);
if (pixbuf) {
if (transform) {
result->pixbuf = entangle_colour_profile_transform_apply(transform,
......@@ -277,9 +276,6 @@ static void entangle_pixbuf_loader_worker(gpointer data,
result->pixbuf = pixbuf;
}
}
if (priv->withMetadata) {
result->metadata = entangle_metadata_load(loader, image);
}
result->loader = loader;
result->image = image;
......
......@@ -58,8 +58,8 @@ struct _EntanglePixbufLoaderClass
void (*pixbuf_unloaded)(EntanglePixbufLoader *loader, EntangleImage *image);
void (*metadata_unloaded)(EntanglePixbufLoader *loader, EntangleImage *image);
GdkPixbuf *(*pixbuf_load)(EntanglePixbufLoader *loader, EntangleImage *image);
GExiv2Metadata *(*metadata_load)(EntanglePixbufLoader *loader, EntangleImage *image);
GdkPixbuf *(*pixbuf_load)(EntanglePixbufLoader *loader, EntangleImage *image,
GExiv2Metadata **metadata);
};
......
This diff is collapsed.
......@@ -22,11 +22,13 @@
#define __ENTANGLE_PIXBUF_H__
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gexiv2.h>
#include "entangle-image.h"
G_BEGIN_DECLS
GdkPixbuf *entangle_pixbuf_auto_rotate(GdkPixbuf *src);
GdkPixbuf *entangle_pixbuf_auto_rotate(GdkPixbuf *src,
GExiv2Metadata *metadata);
typedef enum {
ENTANGLE_PIXBUF_IMAGE_SLOT_MASTER,
......@@ -35,7 +37,9 @@ typedef enum {
} EntanglePixbufImageSlot;
GdkPixbuf *entangle_pixbuf_open_image(EntangleImage *image,
EntanglePixbufImageSlot slot);
EntanglePixbufImageSlot slot,
gboolean applyOrientation,
GExiv2Metadata **metadata);
#endif /* __ENTANGLE_PIXBUF_H__ */
......
......@@ -133,7 +133,8 @@ static GdkPixbuf *entangle_thumbnail_loader_generate(EntanglePixbufLoader *loade
EntangleImage *image,
const char *uri,
const char *thumbname,
time_t mtime)
time_t mtime,
GExiv2Metadata **metadata)
{
GdkPixbuf *master;
GdkPixbuf *thumb = NULL;
......@@ -149,7 +150,9 @@ static GdkPixbuf *entangle_thumbnail_loader_generate(EntanglePixbufLoader *loade
const char *orientationstr;
master = entangle_pixbuf_open_image(image,
ENTANGLE_PIXBUF_IMAGE_SLOT_THUMBNAIL);
ENTANGLE_PIXBUF_IMAGE_SLOT_THUMBNAIL,
FALSE,
metadata);
if (!master)
return NULL;
......@@ -209,7 +212,8 @@ static GdkPixbuf *entangle_thumbnail_loader_generate(EntanglePixbufLoader *loade
static GdkPixbuf *entangle_thumbnail_loader_pixbuf_load(EntanglePixbufLoader *loader,
EntangleImage *image)
EntangleImage *image,
GExiv2Metadata **metadata G_GNUC_UNUSED)
{
EntangleThumbnailLoader *tloader = ENTANGLE_THUMBNAIL_LOADER(loader);
EntangleThumbnailLoaderPrivate *priv = tloader->priv;
......@@ -218,6 +222,7 @@ static GdkPixbuf *entangle_thumbnail_loader_pixbuf_load(EntanglePixbufLoader *lo
GdkPixbuf *result = NULL;
GdkPixbuf *thumb = NULL;
struct stat sb;
GExiv2Metadata *themetadata = NULL;
/* Sanity check that the base image still exists */
if (stat(entangle_image_get_filename(image), &sb) < 0) {
......@@ -257,12 +262,13 @@ static GdkPixbuf *entangle_thumbnail_loader_pixbuf_load(EntanglePixbufLoader *lo
thumb = entangle_thumbnail_loader_generate(loader,
image,
uri, thumbname,
sb.st_mtime);
sb.st_mtime,
&themetadata);
}
/* Apply any rotation hints so it is "normal" for the viewer */
if (thumb) {
GdkPixbuf *tmp = entangle_pixbuf_auto_rotate(thumb);
GdkPixbuf *tmp = entangle_pixbuf_auto_rotate(thumb, themetadata);
g_object_unref(thumb);
thumb = tmp;
}
......@@ -316,6 +322,8 @@ static GdkPixbuf *entangle_thumbnail_loader_pixbuf_load(EntanglePixbufLoader *lo
}
cleanup:
if (themetadata)
g_object_unref(themetadata);
g_free(uri);
g_free(thumbname);
......
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