summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Muller <drnlmuller@gmail.com>2024-06-03 17:21:15 +0200
committerSimon Ser <contact@emersion.fr>2024-06-14 22:41:03 +0200
commitb70d85ec145520ba3ebaa4c51921a2761bc0c7f0 (patch)
treebf240131f0b6d5b0d54f4abb94ff16ebba8bc463
parentf9ce3f193bc2f035790372b550547686075f4923 (diff)
Correct for image orientation when loading image
PEG and other image formats may include an EXIF orientation tag which indicates in what orientation (rotation and mirroring) the image should be displayed. libgdk-pixbuf does not correct for this when loading an image, but provides a function to apply the transform after the fact, which this commit uses. Pulled from https://github.com/swaywm/swaybg/pull/68
-rw-r--r--background-image.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/background-image.c b/background-image.c
index fc2ca0d..572aceb 100644
--- a/background-image.c
+++ b/background-image.c
@@ -31,8 +31,12 @@ cairo_surface_t *load_background_image(const char *path) {
err->message);
return NULL;
}
- image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf);
+ // Correct for embedded image orientation; typical images are not
+ // rotated and will be handled efficiently
+ GdkPixbuf *oriented = gdk_pixbuf_apply_embedded_orientation(pixbuf);
g_object_unref(pixbuf);
+ image = gdk_cairo_image_surface_create_from_pixbuf(oriented);
+ g_object_unref(oriented);
#else
image = cairo_image_surface_create_from_png(path);
#endif // HAVE_GDK_PIXBUF