[librsvg: 6/10] Rename to_mask -> to_luminance mask




commit 18c502ddc6bd26c46178cde6a7ee0257ebabe611
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Oct 15 17:22:23 2021 -0500

    Rename to_mask -> to_luminance mask
    
    We will support alpha masks too, so clarify that name.
    
    Also, remove the opacity argument to that function.  The spec says:
    
    https://www.w3.org/TR/css-masking-1/#MaskElement
    > The opacity, filter and display properties do not apply to the mask element
    
    So we were composing opacity into masks unnecessarily.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/609>

 benches/pixel_ops.rs                | 5 ++---
 src/drawing_ctx.rs                  | 4 +---
 src/surface_utils/mod.rs            | 7 +++----
 src/surface_utils/shared_surface.rs | 6 ++----
 4 files changed, 8 insertions(+), 14 deletions(-)
---
diff --git a/benches/pixel_ops.rs b/benches/pixel_ops.rs
index bbd2e334..dfe19dc0 100644
--- a/benches/pixel_ops.rs
+++ b/benches/pixel_ops.rs
@@ -36,10 +36,9 @@ fn bench_pixel_ops(c: &mut Criterion) {
         b.iter(|| bench_op(&pixels, |pixel| pixel.diff(&other)))
     });
 
-    c.bench_function("pixel_to_mask", |b| {
+    c.bench_function("pixel_to_luminance_mask", |b| {
         let pixels = black_box(make_pixels(N));
-        let opacity = black_box(0x70);
-        b.iter(|| bench_op(&pixels, |pixel| pixel.to_mask(opacity)))
+        b.iter(|| bench_op(&pixels, |pixel| pixel.to_luminance_mask()))
     });
 
     c.bench_function("pixel_premultiply", |b| {
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 92ba431b..f3948113 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -645,10 +645,8 @@ impl DrawingCtx {
             res?;
         }
 
-        let Opacity(opacity) = values.opacity();
-
         let mask = SharedImageSurface::wrap(mask_content_surface, SurfaceType::SRgb)?
-            .to_mask(opacity)?
+            .to_luminance_mask()?
             .into_image_surface()?;
 
         Ok(Some(mask))
diff --git a/src/surface_utils/mod.rs b/src/surface_utils/mod.rs
index 4f751ece..e95e5dce 100644
--- a/src/surface_utils/mod.rs
+++ b/src/surface_utils/mod.rs
@@ -163,7 +163,7 @@ pub trait PixelOps {
     fn premultiply(self) -> Self;
     fn unpremultiply(self) -> Self;
     fn diff(&self, other: &Self) -> Self;
-    fn to_mask(&self, opacity: u8) -> Self;
+    fn to_luminance_mask(&self) -> Self;
     fn to_u32(&self) -> u32;
     fn from_u32(x: u32) -> Self;
 }
@@ -223,17 +223,16 @@ impl PixelOps for Pixel {
 
     /// if pixel = 0x00000000, pixel' = 0x00......
     #[inline]
-    fn to_mask(&self, opacity: u8) -> Self {
+    fn to_luminance_mask(&self) -> Self {
         let r = u32::from(self.r);
         let g = u32::from(self.g);
         let b = u32::from(self.b);
-        let o = u32::from(opacity);
 
         Self {
             r: 0,
             g: 0,
             b: 0,
-            a: (((r * 14042 + g * 47240 + b * 4769) * o) >> 24) as u8,
+            a: (((r * 14042 + g * 47240 + b * 4769) * 255) >> 24) as u8,
         }
     }
 
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index 20cd0f40..fa095806 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -10,7 +10,6 @@ use rgb::FromSlice;
 
 use crate::rect::{IRect, Rect};
 use crate::surface_utils::srgb;
-use crate::unit_interval::UnitInterval;
 use crate::util::clamp;
 
 use super::{
@@ -493,7 +492,7 @@ impl ImageSurface<Shared> {
     /// useful luminance data.
     ///
     /// This is to get a mask suitable for use with cairo_mask_surface().
-    pub fn to_mask(&self, opacity: UnitInterval) -> Result<SharedImageSurface, cairo::Error> {
+    pub fn to_luminance_mask(&self) -> Result<SharedImageSurface, cairo::Error> {
         let bounds = IRect::from_size(self.width, self.height);
 
         let mut output_surface =
@@ -502,10 +501,9 @@ impl ImageSurface<Shared> {
         let stride = output_surface.stride() as usize;
         {
             let mut data = output_surface.data().unwrap();
-            let opacity = u8::from(opacity);
 
             for (x, y, pixel) in Pixels::within(self, bounds) {
-                data.set_pixel(stride, pixel.to_mask(opacity), x, y);
+                data.set_pixel(stride, pixel.to_luminance_mask(), x, y);
             }
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]