From 81f18ad7f4c2b1db895ca2191edb9f641653cb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Tue, 29 Apr 2025 15:10:05 +0200 Subject: [PATCH] :recycle: Normalize opacity in fills to u8 --- render-wasm/src/shapes/fills.rs | 8 ++++---- render-wasm/src/wasm/fills.rs | 16 ++++------------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/render-wasm/src/shapes/fills.rs b/render-wasm/src/shapes/fills.rs index 9497a1f90..fd87f0804 100644 --- a/render-wasm/src/shapes/fills.rs +++ b/render-wasm/src/shapes/fills.rs @@ -7,7 +7,7 @@ use crate::uuid::Uuid; pub struct Gradient { start: (f32, f32), end: (f32, f32), - opacity: f32, + opacity: u8, width: f32, colors: Vec, offsets: Vec, @@ -17,7 +17,7 @@ impl Gradient { pub fn new( start: (f32, f32), end: (f32, f32), - opacity: f32, + opacity: u8, width: f32, stops: &[(Color, f32)], ) -> Self { @@ -143,7 +143,7 @@ impl Fill { Self::LinearGradient(gradient) => { let mut p = skia::Paint::default(); p.set_shader(gradient.to_linear_shader(rect)); - p.set_alpha((gradient.opacity * 255.) as u8); + p.set_alpha(gradient.opacity); p.set_style(skia::PaintStyle::Fill); p.set_anti_alias(anti_alias); p.set_blend_mode(skia::BlendMode::SrcOver); @@ -152,7 +152,7 @@ impl Fill { Self::RadialGradient(gradient) => { let mut p = skia::Paint::default(); p.set_shader(gradient.to_radial_shader(rect)); - p.set_alpha((gradient.opacity * 255.) as u8); + p.set_alpha(gradient.opacity); p.set_style(skia::PaintStyle::Fill); p.set_anti_alias(anti_alias); p.set_blend_mode(skia::BlendMode::SrcOver); diff --git a/render-wasm/src/wasm/fills.rs b/render-wasm/src/wasm/fills.rs index 663941fdd..a2642bfc1 100644 --- a/render-wasm/src/wasm/fills.rs +++ b/render-wasm/src/wasm/fills.rs @@ -67,7 +67,7 @@ const RAW_GRADIENT_DATA_SIZE: usize = #[derive(Debug)] #[repr(C)] -pub struct RawGradientData { +struct RawGradientData { start_x: f32, start_y: f32, end_x: f32, @@ -111,21 +111,13 @@ impl RawGradientData { pub fn end(&self) -> (f32, f32) { (self.end_x, self.end_y) } - - pub fn opacity(&self) -> f32 { - self.opacity - } - - pub fn width(&self) -> f32 { - self.width - } } pub const RAW_STOP_DATA_SIZE: usize = 8; #[derive(Debug)] #[repr(C)] -pub struct RawStopData { +struct RawStopData { color: u32, offset: f32, } @@ -173,8 +165,8 @@ impl From for Gradient { Gradient::new( raw_gradient.start(), raw_gradient.end(), - raw_gradient.opacity(), - raw_gradient.width(), + (raw_gradient.opacity * 255.) as u8, + raw_gradient.width, &stops, ) }