diff options
Diffstat (limited to 'meta/recipes-gnome/librsvg/librsvg/0003-New-ToCairoARGB-trait.patch')
-rw-r--r-- | meta/recipes-gnome/librsvg/librsvg/0003-New-ToCairoARGB-trait.patch | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/meta/recipes-gnome/librsvg/librsvg/0003-New-ToCairoARGB-trait.patch b/meta/recipes-gnome/librsvg/librsvg/0003-New-ToCairoARGB-trait.patch new file mode 100644 index 0000000000..8dd45ef0a2 --- /dev/null +++ b/meta/recipes-gnome/librsvg/librsvg/0003-New-ToCairoARGB-trait.patch | |||
@@ -0,0 +1,81 @@ | |||
1 | From f5768df65cf6277e8ab687a84fdc5d9addaa373d Mon Sep 17 00:00:00 2001 | ||
2 | From: Federico Mena Quintero <federico@gnome.org> | ||
3 | Date: Tue, 21 Sep 2021 12:49:53 -0500 | ||
4 | Subject: [PATCH] New ToCairoARGB trait | ||
5 | |||
6 | Use it in the pixbuf-to-cairo-surface function. | ||
7 | |||
8 | Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/592> | ||
9 | Upstream-Status: Backport | ||
10 | Signed-off-by: Alexander Kanavin <alex@linutronix.de> | ||
11 | --- | ||
12 | src/surface_utils/mod.rs | 17 +++++++++++++++++ | ||
13 | src/surface_utils/shared_surface.rs | 8 ++++---- | ||
14 | 2 files changed, 21 insertions(+), 4 deletions(-) | ||
15 | |||
16 | diff --git a/src/surface_utils/mod.rs b/src/surface_utils/mod.rs | ||
17 | index 58953e6a0..3f915cd01 100644 | ||
18 | --- a/src/surface_utils/mod.rs | ||
19 | +++ b/src/surface_utils/mod.rs | ||
20 | @@ -76,6 +76,11 @@ pub trait ToPixel { | ||
21 | fn to_pixel(&self) -> Pixel; | ||
22 | } | ||
23 | |||
24 | +/// Trait to convert pixels in various formats to Cairo's endian-dependent 0xaarrggbb. | ||
25 | +pub trait ToCairoARGB { | ||
26 | + fn to_cairo_argb(&self) -> CairoARGB; | ||
27 | +} | ||
28 | + | ||
29 | impl ToGdkPixbufRGBA for Pixel { | ||
30 | #[inline] | ||
31 | fn to_pixbuf_rgba(&self) -> GdkPixbufRGBA { | ||
32 | @@ -112,6 +117,18 @@ impl ToPixel for GdkPixbufRGB { | ||
33 | } | ||
34 | } | ||
35 | |||
36 | +impl ToCairoARGB for Pixel { | ||
37 | + #[inline] | ||
38 | + fn to_cairo_argb(&self) -> CairoARGB { | ||
39 | + CairoARGB { | ||
40 | + r: self.r, | ||
41 | + g: self.g, | ||
42 | + b: self.b, | ||
43 | + a: self.a, | ||
44 | + } | ||
45 | + } | ||
46 | +} | ||
47 | + | ||
48 | /// Extension methods for `cairo::ImageSurfaceData`. | ||
49 | pub trait ImageSurfaceDataExt: DerefMut<Target = [u8]> { | ||
50 | /// Sets the pixel at the given coordinates. Assumes the `ARgb32` format. | ||
51 | diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs | ||
52 | index 9fa9a2e15..34dfc992e 100644 | ||
53 | --- a/src/surface_utils/shared_surface.rs | ||
54 | +++ b/src/surface_utils/shared_surface.rs | ||
55 | @@ -15,8 +15,8 @@ use crate::util::clamp; | ||
56 | |||
57 | use super::{ | ||
58 | iterators::{PixelRectangle, Pixels}, | ||
59 | - AsCairoARGB, CairoARGB, EdgeMode, ImageSurfaceDataExt, Pixel, PixelOps, ToGdkPixbufRGBA, | ||
60 | - ToPixel, | ||
61 | + AsCairoARGB, CairoARGB, EdgeMode, ImageSurfaceDataExt, Pixel, PixelOps, ToCairoARGB, | ||
62 | + ToGdkPixbufRGBA, ToPixel, | ||
63 | }; | ||
64 | |||
65 | /// Types of pixel data in a `ImageSurface`. | ||
66 | @@ -305,13 +305,13 @@ impl ImageSurface<Shared> { | ||
67 | .map(|row| row.as_rgba()) | ||
68 | .zip(surf.rows_mut()) | ||
69 | .flat_map(|(src_row, dest_row)| src_row.iter().zip(dest_row.iter_mut())) | ||
70 | - .for_each(|(src, dest)| *dest = src.to_pixel().premultiply().into()); | ||
71 | + .for_each(|(src, dest)| *dest = src.to_pixel().premultiply().to_cairo_argb()); | ||
72 | } else { | ||
73 | pixbuf_rows | ||
74 | .map(|row| row.as_rgb()) | ||
75 | .zip(surf.rows_mut()) | ||
76 | .flat_map(|(src_row, dest_row)| src_row.iter().zip(dest_row.iter_mut())) | ||
77 | - .for_each(|(src, dest)| *dest = src.to_pixel().into()); | ||
78 | + .for_each(|(src, dest)| *dest = src.to_pixel().to_cairo_argb()); | ||
79 | } | ||
80 | |||
81 | if let (Some(content_type), Some(bytes)) = (content_type, mime_data) { | ||