diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2013-09-10 07:22:32 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2013-09-10 07:22:32 +0000 |
commit | 7869d8aad54068c3378eb0dc88a71df382393858 (patch) | |
tree | 3a9c86c2018d2677133121a464da466c7cacac17 /src | |
parent | 2e7d504d5191b25b5d53c3da4a43ec7bd8856c7b (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')
-rw-r--r-- | src/imageview.c | 62 | ||||
-rw-r--r-- | src/imageview.h | 4 | ||||
-rw-r--r-- | src/textview.c | 7 |
3 files changed, 71 insertions, 2 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) { diff --git a/src/imageview.h b/src/imageview.h index 19146e7d..48686b7f 100644 --- a/src/imageview.h +++ b/src/imageview.h @@ -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 @@ -54,4 +54,6 @@ GdkPixbuf *imageview_get_resized_pixbuf (GdkPixbuf *pixbuf, GtkWidget *parent, gint margin); +GdkPixbuf *imageview_get_rotated_pixbuf (GdkPixbuf *pixbuf); + #endif /* __IMAGEVIEW_H__ */ diff --git a/src/textview.c b/src/textview.c index 8f2449a1..3d597d86 100644 --- a/src/textview.c +++ b/src/textview.c @@ -1025,6 +1025,13 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp) return; } + { + GdkPixbuf *rotated; + + rotated = imageview_get_rotated_pixbuf(pixbuf); + g_object_unref(pixbuf); + pixbuf = rotated; + } if (prefs_common.resize_image) { GdkPixbuf *scaled; |