diff options
| author | Jörg Frings-Fürst <debian@jff.email> | 2026-03-08 11:11:23 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff.email> | 2026-03-08 11:11:23 +0100 |
| commit | 1ef9b86df1cca6dde71529f03b66407953d000c9 (patch) | |
| tree | b3d41d58cbb1d52e3871e40258539ac760cd265e /src/util/image.vala | |
| parent | fa4d70ea3101f5a70b33977ba9b7673ddfb36762 (diff) | |
| parent | 210cc61ee4191465805a770881235c677041f929 (diff) | |
Update upstream source from tag 'upstream/0.32.15'
Update to upstream version '0.32.15'
with Debian dir ab0b4536d524ccbb338db4641523f7abd3f9a2fd
Diffstat (limited to 'src/util/image.vala')
| -rw-r--r-- | src/util/image.vala | 38 |
1 files changed, 34 insertions, 4 deletions
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); } /** |
