[recipes/image-import] wip image rotation stuff
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/image-import] wip image rotation stuff
- Date: Sun, 7 May 2017 19:24:35 +0000 (UTC)
commit 6935ff8d3d0d76c95cdfe0b198a283e4ce6aae8f
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 18 13:13:52 2017 -0500
wip image rotation stuff
src/gr-utils.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/src/gr-utils.c b/src/gr-utils.c
index 0d96c9d..78719cd 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -38,6 +38,47 @@
#include "gr-utils.h"
#include "gr-app.h"
+static GdkPixbuf *
+load_oriented_at_size (const char *path, int width, int height)
+{
+ g_autoptr(GdkPixbuf) src = NULL;
+ int transform = 0;
+ const char *orientation;
+
+ src = gdk_pixbuf_new_from_file_at_size (path, width, height, NULL);
+ if (!src)
+ return NULL;
+
+ orientation = gdk_pixbuf_get_option (src, "orientation");
+ if (orientation)
+ transform = (int) g_ascii_strtoll (orientation, NULL, 10);
+
+ if (transform > 4)
+ g_set_object (&src, gdk_pixbuf_new_from_file_at_size (path, height, width, NULL));
+
+ return gdk_pixbuf_apply_embedded_orientation (src);
+}
+
+static GdkPixbuf *
+load_oriented_at_scale (const char *path, int width, int height, gboolean preserve_aspect)
+{
+ g_autoptr(GdkPixbuf) src = NULL;
+ int transform = 0;
+ const char *orientation;
+
+ src = gdk_pixbuf_new_from_file_at_scale (path, width, height, preserve_aspect, NULL);
+ if (!src)
+ return NULL;
+
+ orientation = gdk_pixbuf_get_option (src, "orientation");
+ if (orientation)
+ transform = (int) g_ascii_strtoll (orientation, NULL, 10);
+
+ if (transform > 4)
+ g_set_object (&src, gdk_pixbuf_new_from_file_at_scale (path, height, width, preserve_aspect,
NULL));
+
+ return gdk_pixbuf_apply_embedded_orientation (src);
+}
/* load image rotated by angle to fit in width x height while preserving
* aspect ratio, filling seams with transparency
*/
@@ -66,11 +107,12 @@ load_pixbuf_fit_size (const char *path,
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
gdk_pixbuf_fill (pixbuf, 0x00000000);
- original = gdk_pixbuf_new_from_file_at_size (path, load_width, load_height, NULL);
+ original = load_oriented_at_size (path, load_width, load_height);
if (!original) {
g_warning ("Failed to load image %s", path);
return pixbuf;
}
+
if (angle != 0) {
g_autoptr(GdkPixbuf) pb = NULL;
pb = gdk_pixbuf_rotate_simple (original, angle);
@@ -116,7 +158,7 @@ load_pixbuf_fill_size (const char *path,
load_height = height;
}
- original = gdk_pixbuf_new_from_file_at_scale (path, -1, load_height, TRUE, NULL);
+ original = load_oriented_at_scale (path, -1, load_height, TRUE);
if (!original) {
GdkPixbuf *pixbuf;
g_warning ("Failed to load image %s", path);
@@ -125,6 +167,7 @@ load_pixbuf_fill_size (const char *path,
return pixbuf;
}
+
if (angle != 0) {
g_autoptr(GdkPixbuf) pb = NULL;
pb = gdk_pixbuf_rotate_simple (original, angle);
@@ -133,7 +176,7 @@ load_pixbuf_fill_size (const char *path,
if (gdk_pixbuf_get_width (original) < width) {
g_autoptr(GdkPixbuf) pb1 = NULL;
- pb1 = gdk_pixbuf_new_from_file_at_scale (path, load_width, -1, TRUE, NULL);
+ pb1 = load_oriented_at_scale (path, load_width, -1, TRUE);
g_set_object (&original, pb1);
if (angle != 0) {
g_autoptr(GdkPixbuf) pb = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]