From 210cc61ee4191465805a770881235c677041f929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 8 Mar 2026 11:11:07 +0100 Subject: New upstream version 0.32.15 --- src/util/image.vala | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/util/image.vala') diff --git a/src/util/image.vala b/src/util/image.vala index 5b78a50..e46233d 100644 --- a/src/util/image.vala +++ b/src/util/image.vala @@ -185,8 +185,39 @@ public Gdk.Point subtract_points(Gdk.Point p1, Gdk.Point p2) { return result; } +Gdk.Pixbuf apply_alpha_channel(Gdk.Pixbuf source, bool strip = false) { + var dest = new Gdk.Pixbuf (source.colorspace, false, source.bits_per_sample, source.width, source.height); + uchar *sp = source.pixels; + uchar *dp = dest.pixels; + + for (int j = 0; j < source.height; j++) { + uchar *s = sp; + uchar *d = dp; + uchar *end = s + 4 * source.width; + while (s < end) { + if (strip) { + d[0] = s[0]; + d[1] = s[1]; + d[2] = s[2]; + } else { + double alpha = s[3] / 255.0; + d[0] = (uchar)Math.round((255.0 * (1.0 - alpha)) + (s[0] * alpha)); + d[1] = (uchar)Math.round((255.0 * (1.0 - alpha)) + (s[1] * alpha)); + d[2] = (uchar)Math.round((255.0 * (1.0 - alpha)) + (s[2] * alpha)); + } + s += 4; + d += 3; + } + + sp += source.rowstride; + dp += dest.rowstride; + } + + return dest; +} + // Converts XRGB/ARGB (Cairo)-formatted pixels to RGBA (GDK). -void fix_cairo_pixbuf(Gdk.Pixbuf pixbuf) { +void argb2rgba(Gdk.Pixbuf pixbuf) { uchar *gdk_pixels = pixbuf.pixels; for (int j = 0 ; j < pixbuf.height; ++j) { uchar *p = gdk_pixels; @@ -274,9 +305,8 @@ Gdk.Pixbuf rotate_arb(Gdk.Pixbuf source_pixbuf, double angle) { // prepare the newly-drawn image for use by // the rest of the pipeline. - fix_cairo_pixbuf(dest_pixbuf); - - return dest_pixbuf; + argb2rgba(dest_pixbuf); + return apply_alpha_channel(dest_pixbuf, true); } /** -- cgit v1.2.3