summaryrefslogtreecommitdiffstats
path: root/meta/recipes-gnome/librsvg/librsvg/0002-New-ToPixel-trait.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-gnome/librsvg/librsvg/0002-New-ToPixel-trait.patch')
-rw-r--r--meta/recipes-gnome/librsvg/librsvg/0002-New-ToPixel-trait.patch100
1 files changed, 100 insertions, 0 deletions
diff --git a/meta/recipes-gnome/librsvg/librsvg/0002-New-ToPixel-trait.patch b/meta/recipes-gnome/librsvg/librsvg/0002-New-ToPixel-trait.patch
new file mode 100644
index 0000000000..c71c93e1a1
--- /dev/null
+++ b/meta/recipes-gnome/librsvg/librsvg/0002-New-ToPixel-trait.patch
@@ -0,0 +1,100 @@
1From 47478d5a8a4b7a05b44f024404137c4c68b62b7e Mon Sep 17 00:00:00 2001
2From: Federico Mena Quintero <federico@gnome.org>
3Date: Tue, 21 Sep 2021 12:22:15 -0500
4Subject: [PATCH] New ToPixel trait
5
6Use it where we convert GdkPixbuf pixels to our own Pixel for premultiplication.
7
8Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/592>
9Upstream-Status: Backport
10Signed-off-by: Alexander Kanavin <alex@linutronix.de>
11---
12 src/surface_utils/mod.rs | 32 +++++++++++++++++++++++++++++
13 src/surface_utils/shared_surface.rs | 5 +++--
14 2 files changed, 35 insertions(+), 2 deletions(-)
15
16diff --git a/src/surface_utils/mod.rs b/src/surface_utils/mod.rs
17index 93d3b4f79..58953e6a0 100644
18--- a/src/surface_utils/mod.rs
19+++ b/src/surface_utils/mod.rs
20@@ -25,6 +25,9 @@ pub type CairoARGB = ARGB8;
21 /// GdkPixbuf's endian-independent RGBA8 pixel layout.
22 pub type GdkPixbufRGBA = rgb::RGBA8;
23
24+/// GdkPixbuf's packed RGB pixel layout.
25+pub type GdkPixbufRGB = rgb::RGB8;
26+
27 /// Analogous to `rgb::FromSlice`, to convert from `[T]` to `[CairoARGB]`
28 #[allow(clippy::upper_case_acronyms)]
29 pub trait AsCairoARGB<T: Copy> {
30@@ -68,6 +71,11 @@ pub trait ToGdkPixbufRGBA {
31 fn to_pixbuf_rgba(&self) -> GdkPixbufRGBA;
32 }
33
34+/// Trait to convert pixels in various formats to our own Pixel layout.
35+pub trait ToPixel {
36+ fn to_pixel(&self) -> Pixel;
37+}
38+
39 impl ToGdkPixbufRGBA for Pixel {
40 #[inline]
41 fn to_pixbuf_rgba(&self) -> GdkPixbufRGBA {
42@@ -80,6 +88,30 @@ impl ToGdkPixbufRGBA for Pixel {
43 }
44 }
45
46+impl ToPixel for GdkPixbufRGBA {
47+ #[inline]
48+ fn to_pixel(&self) -> Pixel {
49+ Pixel {
50+ r: self.r,
51+ g: self.g,
52+ b: self.b,
53+ a: self.a,
54+ }
55+ }
56+}
57+
58+impl ToPixel for GdkPixbufRGB {
59+ #[inline]
60+ fn to_pixel(&self) -> Pixel {
61+ Pixel {
62+ r: self.r,
63+ g: self.g,
64+ b: self.b,
65+ a: 255,
66+ }
67+ }
68+}
69+
70 /// Extension methods for `cairo::ImageSurfaceData`.
71 pub trait ImageSurfaceDataExt: DerefMut<Target = [u8]> {
72 /// Sets the pixel at the given coordinates. Assumes the `ARgb32` format.
73diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
74index 476a6f776..9fa9a2e15 100644
75--- a/src/surface_utils/shared_surface.rs
76+++ b/src/surface_utils/shared_surface.rs
77@@ -16,6 +16,7 @@ use crate::util::clamp;
78 use super::{
79 iterators::{PixelRectangle, Pixels},
80 AsCairoARGB, CairoARGB, EdgeMode, ImageSurfaceDataExt, Pixel, PixelOps, ToGdkPixbufRGBA,
81+ ToPixel,
82 };
83
84 /// Types of pixel data in a `ImageSurface`.
85@@ -304,13 +305,13 @@ impl ImageSurface<Shared> {
86 .map(|row| row.as_rgba())
87 .zip(surf.rows_mut())
88 .flat_map(|(src_row, dest_row)| src_row.iter().zip(dest_row.iter_mut()))
89- .for_each(|(src, dest)| *dest = src.premultiply().into());
90+ .for_each(|(src, dest)| *dest = src.to_pixel().premultiply().into());
91 } else {
92 pixbuf_rows
93 .map(|row| row.as_rgb())
94 .zip(surf.rows_mut())
95 .flat_map(|(src_row, dest_row)| src_row.iter().zip(dest_row.iter_mut()))
96- .for_each(|(src, dest)| *dest = src.alpha(0xff).into());
97+ .for_each(|(src, dest)| *dest = src.to_pixel().into());
98 }
99
100 if let (Some(content_type), Some(bytes)) = (content_type, mime_data) {