[librsvg: 3/5] New ToCairoARGB trait
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/5] New ToCairoARGB trait
- Date: Wed, 22 Sep 2021 01:11:18 +0000 (UTC)
commit 3fb10220fd948caec7e957739fcb5e1f9b2896ef
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Sep 21 12:49:53 2021 -0500
New ToCairoARGB trait
Use it in the pixbuf-to-cairo-surface function.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/592>
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 58953e6a..3f915cd0 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 9fa9a2e1..34dfc992 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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]