PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge main into perf/p25-blur-cancel
David Mann37a4491c632c
diff --cc crates/engine/src/filters.rsindex 900b09c1f,221709080..cae1b7bba--- a/crates/engine/src/filters.rs+++ b/crates/engine/src/filters.rs@@@ -313,16 -313,9 +313,16 @@@ pub(crate) fn run_filter(s: &mut Sessio}/// Lock transparency: put the layer's alpha back after a filter, in the tiles it changed.-pub(crate) fn keep_alpha(old: &photocraft_raster::Surface, new: &mut photocraft_raster::Surface) {+///+/// The tiles are independent, so they are fixed in parallel, each in a scratch surface of its+/// own, and `cancelled` is asked before each one: on a 24 MP layer (a Background, whose+/// transparency is locked) a serial pass took about 400 ms that a cancelled job had to sit out+/// (#6205). `Err(Cancelled)` leaves `new` holding all its tiles, some of them not yet fixed.- fn keep_alpha(old: &photocraft_raster::Surface, new: &mut photocraft_raster::Surface, cancelled: &(dyn Fn() -> bool + Sync)) -> Result<()> {++pub(crate) fn keep_alpha(old: &photocraft_raster::Surface, new: &mut photocraft_raster::Surface, cancelled: &(dyn Fn() -> bool + Sync)) -> Result<()> {+ use photocraft_raster::Surface;+ use rayon::prelude::*;if old.format() != new.format() || !new.format().alpha {- return;+ return Ok(());}let mut coords: Vec<_> = new.tiles().filter(|(c, t)| old.tile(**c).is_none_or(|o| !std::sync::Arc::ptr_eq(o, t))).map(|(c, _)| *c).collect();coords.extend(old.tiles().filter(|(c, _)| new.tile(**c).is_none()).map(|(c, _)| *c));diff --cc crates/engine/src/plugin_cmds.rsindex 5c7d2dd71,a2044f5e8..08f868ca4--- a/crates/engine/src/plugin_cmds.rs+++ b/crates/engine/src/plugin_cmds.rs@@@ -80,7 -82,12 +82,12 @@@ fn run(s: &mut Session, p: &Value) -> Rlet l = doc.layer_mut(layer).ok_or(EngineError::NoLayer(layer))?;match &mut l.content {LayerContent::Raster(surf) => {+ // Lock Transparency: the plug-in may change colour but not alpha (as built-in filters).+ let before = keep_alpha.then(|| surf.clone());*surf = plugin.apply(surf, canvas, selection.as_ref(), &resolved).map_err(err)?;+ if let Some(before) = &before {- crate::filters::keep_alpha(before, surf);++ crate::filters::keep_alpha(before, surf, &|| false)?;+ }Ok(())}LayerContent::Smart(_) => {