aboutsummaryrefslogtreecommitdiff
path: root/src/imageview.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2013-09-10 07:22:32 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2013-09-10 07:22:32 +0000
commit7869d8aad54068c3378eb0dc88a71df382393858 (patch)
tree3a9c86c2018d2677133121a464da466c7cacac17 /src/imageview.c
parent2e7d504d5191b25b5d53c3da4a43ec7bd8856c7b (diff)
rotate attached images based on Exif orientation tag.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3277 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src/imageview.c')
-rw-r--r--src/imageview.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/imageview.c b/src/imageview.c
index 77f33006..19b1b131 100644
--- a/src/imageview.c
+++ b/src/imageview.c
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto
*
* 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
@@ -26,6 +26,7 @@
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtkimage.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <stdlib.h>
#include "mainwindow.h"
#include "prefs_common.h"
@@ -86,6 +87,7 @@ void imageview_show_image(ImageView *imageview, MimeInfo *mimeinfo,
const gchar *file, gboolean resize)
{
GdkPixbuf *pixbuf;
+ GdkPixbuf *rotated;
GError *error = NULL;
g_return_if_fail(imageview != NULL);
@@ -112,12 +114,16 @@ void imageview_show_image(ImageView *imageview, MimeInfo *mimeinfo,
imageview->resize = resize;
+ pixbuf = rotated = imageview_get_rotated_pixbuf(pixbuf);
+
if (resize) {
pixbuf = imageview_get_resized_pixbuf
(pixbuf, imageview->scrolledwin->parent, 8);
} else
g_object_ref(pixbuf);
+ g_object_unref(rotated);
+
if (!imageview->image) {
imageview->image = gtk_image_new_from_pixbuf(pixbuf);
@@ -222,6 +228,60 @@ static gboolean get_resized_size(gint w, gint h, gint aw, gint ah,
return TRUE;
}
+GdkPixbuf *imageview_get_rotated_pixbuf(GdkPixbuf *pixbuf)
+{
+#if GTK_CHECK_VERSION(2, 12, 0)
+ return gdk_pixbuf_apply_embedded_orientation(pixbuf);
+#else
+ const gchar *orientation_str;
+ gint orientation;
+ GdkPixbuf *rotated;
+ GdkPixbuf *new_pixbuf;
+
+ orientation_str = gdk_pixbuf_get_option(pixbuf, "orientation");
+ if (!orientation_str)
+ return g_object_ref(pixbuf);
+
+ orientation = strtol(orientation_str, NULL, 10);
+
+ switch (orientation) {
+ case 1:
+ new_pixbuf = g_object_ref(pixbuf);
+ break;
+ case 2:
+ new_pixbuf = gdk_pixbuf_flip(pixbuf, TRUE);
+ break;
+ case 3:
+ new_pixbuf = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
+ break;
+ case 4:
+ new_pixbuf = gdk_pixbuf_flip(pixbuf, FALSE);
+ break;
+ case 5:
+ rotated = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
+ new_pixbuf = gdk_pixbuf_flip(rotated, TRUE);
+ g_object_unref(rotated);
+ break;
+ case 6:
+ new_pixbuf = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
+ break;
+ case 7:
+ rotated = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
+ new_pixbuf = gdk_pixbuf_flip(rotated, FALSE);
+ g_object_unref(rotated);
+ break;
+ case 8:
+ new_pixbuf = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
+ break;
+ default:
+ new_pixbuf = g_object_ref(pixbuf);
+ break;
+ }
+
+ return new_pixbuf;
+#endif
+}
+
static gint button_press_cb(GtkWidget *widget, GdkEventButton *event,
gpointer data)
{