summaryrefslogtreecommitdiffstats
path: root/meta/recipes-gnome/librsvg/librsvg/0003-New-ToCairoARGB-trait.patch
blob: 8dd45ef0a286fdee325e80316b337ec90aa3b3bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From f5768df65cf6277e8ab687a84fdc5d9addaa373d Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Tue, 21 Sep 2021 12:49:53 -0500
Subject: [PATCH] New ToCairoARGB trait

Use it in the pixbuf-to-cairo-surface function.

Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/592>
Upstream-Status: Backport
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 src/surface_utils/mod.rs            | 17 +++++++++++++++++
 src/surface_utils/shared_surface.rs |  8 ++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/surface_utils/mod.rs b/src/surface_utils/mod.rs
index 58953e6a0..3f915cd01 100644
--- a/src/surface_utils/mod.rs
+++ b/src/surface_utils/mod.rs
@@ -76,6 +76,11 @@ pub trait ToPixel {
     fn to_pixel(&self) -> Pixel;
 }
 
+/// Trait to convert pixels in various formats to Cairo's endian-dependent 0xaarrggbb.
+pub trait ToCairoARGB {
+    fn to_cairo_argb(&self) -> CairoARGB;
+}
+
 impl ToGdkPixbufRGBA for Pixel {
     #[inline]
     fn to_pixbuf_rgba(&self) -> GdkPixbufRGBA {
@@ -112,6 +117,18 @@ impl ToPixel for GdkPixbufRGB {
     }
 }
 
+impl ToCairoARGB for Pixel {
+    #[inline]
+    fn to_cairo_argb(&self) -> CairoARGB {
+        CairoARGB {
+            r: self.r,
+            g: self.g,
+            b: self.b,
+            a: self.a,
+        }
+    }
+}
+
 /// Extension methods for `cairo::ImageSurfaceData`.
 pub trait ImageSurfaceDataExt: DerefMut<Target = [u8]> {
     /// Sets the pixel at the given coordinates. Assumes the `ARgb32` format.
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index 9fa9a2e15..34dfc992e 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -15,8 +15,8 @@ use crate::util::clamp;
 
 use super::{
     iterators::{PixelRectangle, Pixels},
-    AsCairoARGB, CairoARGB, EdgeMode, ImageSurfaceDataExt, Pixel, PixelOps, ToGdkPixbufRGBA,
-    ToPixel,
+    AsCairoARGB, CairoARGB, EdgeMode, ImageSurfaceDataExt, Pixel, PixelOps, ToCairoARGB,
+    ToGdkPixbufRGBA, ToPixel,
 };
 
 /// Types of pixel data in a `ImageSurface`.
@@ -305,13 +305,13 @@ impl ImageSurface<Shared> {
                 .map(|row| row.as_rgba())
                 .zip(surf.rows_mut())
                 .flat_map(|(src_row, dest_row)| src_row.iter().zip(dest_row.iter_mut()))
-                .for_each(|(src, dest)| *dest = src.to_pixel().premultiply().into());
+                .for_each(|(src, dest)| *dest = src.to_pixel().premultiply().to_cairo_argb());
         } else {
             pixbuf_rows
                 .map(|row| row.as_rgb())
                 .zip(surf.rows_mut())
                 .flat_map(|(src_row, dest_row)| src_row.iter().zip(dest_row.iter_mut()))
-                .for_each(|(src, dest)| *dest = src.to_pixel().into());
+                .for_each(|(src, dest)| *dest = src.to_pixel().to_cairo_argb());
         }
 
         if let (Some(content_type), Some(bytes)) = (content_type, mime_data) {