Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 11 additions & 45 deletions sparse_strips/vello_cpu/src/filter/flood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use super::FilterEffect;
use crate::layer_manager::LayerManager;
use vello_common::color::{AlphaColor, Srgb};
use vello_common::peniko::color::PremulRgba8;
use vello_common::pixmap::Pixmap;

pub(crate) struct Flood {
Expand All @@ -22,52 +21,19 @@ impl Flood {

impl FilterEffect for Flood {
fn execute_lowp(&self, pixmap: &mut Pixmap, _layer_manager: &mut LayerManager) {
// Convert AlphaColor to u8 [0-255] range
let flood_r = (self.color.components[0] * 255.0) as u8;
let flood_g = (self.color.components[1] * 255.0) as u8;
let flood_b = (self.color.components[2] * 255.0) as u8;
let flood_a = (self.color.components[3] * 255.0) as u8;

// Premultiply RGB by alpha for PremulRgba8
let premul_r = ((flood_r as u16 * flood_a as u16) / 255) as u8;
let premul_g = ((flood_g as u16 * flood_a as u16) / 255) as u8;
let premul_b = ((flood_b as u16 * flood_a as u16) / 255) as u8;

let flood_color = PremulRgba8 {
r: premul_r,
g: premul_g,
b: premul_b,
a: flood_a,
};

// Fill ALL pixels with flood color (entire subregion)
pixmap.data_mut().fill(flood_color);
pixmap.data_mut().fill(self.color.premultiply().to_rgba8());
}

fn execute_highp(&self, pixmap: &mut Pixmap, _layer_manager: &mut LayerManager) {
let flood_r = self.color.components[0];
let flood_g = self.color.components[1];
let flood_b = self.color.components[2];
let flood_a = self.color.components[3];

// Premultiply RGB by alpha for PremulRgba8
let flood_color = PremulRgba8 {
r: (flood_r * flood_a * 255.0) as u8,
g: (flood_g * flood_a * 255.0) as u8,
b: (flood_b * flood_a * 255.0) as u8,
a: (flood_a * 255.0) as u8,
};

// Fill ALL pixels with flood color (entire subregion)
pixmap.data_mut().fill(flood_color);
pixmap.data_mut().fill(self.color.premultiply().to_rgba8());
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::layer_manager::LayerManager;
use vello_common::color::Srgb;
use vello_common::color::{PremulRgba8, Srgb};

/// Test flood with semi-transparent color - verifies correct premultiplication.
#[test]
Expand All @@ -90,10 +56,10 @@ mod tests {
assert_eq!(
pixel,
PremulRgba8 {
r: 127,
g: 127,
b: 127,
a: 127
r: 128,
g: 128,
b: 128,
a: 128
}
);
}
Expand Down Expand Up @@ -121,10 +87,10 @@ mod tests {
assert_eq!(
pixel,
PremulRgba8 {
r: 127,
g: 127,
b: 127,
a: 127
r: 128,
g: 128,
b: 128,
a: 128
}
);
}
Expand Down