[librsvg] surface_utils: pass down opacity as a UnitInterval
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] surface_utils: pass down opacity as a UnitInterval
- Date: Mon, 6 Jan 2020 11:27:59 +0000 (UTC)
commit d1cc13a2688a08d7b8542293f32fece0309a4a6a
Author: Paolo Borelli <pborelli gnome org>
Date: Mon Jan 6 12:10:33 2020 +0100
surface_utils: pass down opacity as a UnitInterval
The u8 representation is an internal detail of cairo.
rsvg_internals/src/drawing_ctx.rs | 2 +-
rsvg_internals/src/surface_utils/shared_surface.rs | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index c3528646..a90af76a 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -478,7 +478,7 @@ impl DrawingCtx {
let Opacity(opacity) = values.opacity;
let mask = SharedImageSurface::new(mask_content_surface, SurfaceType::SRgb)?
- .to_mask(u8::from(opacity))?
+ .to_mask(opacity)?
.into_image_surface()?;
Ok(Some(mask))
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index 069b07df..f96c5fcf 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -10,6 +10,7 @@ use nalgebra::{storage::Storage, Dim, Matrix};
use crate::rect::IRect;
use crate::srgb;
+use crate::unit_interval::UnitInterval;
use crate::util::clamp;
use super::{
@@ -413,7 +414,7 @@ impl SharedImageSurface {
/// useful luminance data.
///
/// This is to get a mask suitable for use with cairo_mask_surface().
- pub fn to_mask(&self, opacity: u8) -> Result<SharedImageSurface, cairo::Status> {
+ pub fn to_mask(&self, opacity: UnitInterval) -> Result<SharedImageSurface, cairo::Status> {
let bounds = IRect::from_size(self.width, self.height);
let mut output_surface =
@@ -422,6 +423,7 @@ impl SharedImageSurface {
let stride = output_surface.get_stride() as usize;
{
let mut data = output_surface.get_data().unwrap();
+ let opacity = u8::from(opacity);
for (x, y, pixel) in Pixels::new(self, bounds) {
data.set_pixel(stride, pixel.to_mask(opacity), x, y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]