From e1d950d6b2c91b146b87d3ee4eeb3d74fedf6db3 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 14:04:27 +0100 Subject: [PATCH] Smart Filter Lens Blur: setParams refuses an alpha channel depth Applying Lens Blur to a Smart Object already refuses an alpha channel as the depth map: a smart filter re-renders from its params alone, without the document's channels (#7400). layer.smartFilter.setParams did not, so since the Lens Blur dialog sends a chosen channel as `depthMap: "channel"` (#15883), OK in a Smart Filter's Lens Blur dialog could record a source the re-render cannot read. setParams now refuses it with the same message, merged or replaced, and the filter and history stay as they were. Follow-up to the review of integration batch #16092. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/smart_cmds/filters.rs | 4 +++ crates/engine/src/cmd/smart_cmds/tests.rs | 28 +++++++++++++++++++++ crates/engine/src/filters.rs | 7 +++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/smart_cmds/filters.rs b/crates/engine/src/cmd/smart_cmds/filters.rs index 46a5ccba39..70486a8451 100644 --- a/crates/engine/src/cmd/smart_cmds/filters.rs +++ b/crates/engine/src/cmd/smart_cmds/filters.rs @@ -229,6 +229,10 @@ pub(super) fn set_filter_params(s: &mut Session, p: &Value) -> Result { f.params = photocraft_io::smart_map::displace_without_map(&f.params); } } + // As applying it does: the re-render can't read the document's alpha channels. + if f.command == "filter.blur.lensBlur" && f.params.get("depthMap").and_then(Value::as_str) == Some("channel") { + return Err(EngineError::Other(crate::filters::LENS_BLUR_CHANNEL_ON_SMART.into())); + } // Authorize the underlying command with the complete merged params, including paths // already stored in the document, before committing the edit or starting a worker. if let Some(gate) = authorize { diff --git a/crates/engine/src/cmd/smart_cmds/tests.rs b/crates/engine/src/cmd/smart_cmds/tests.rs index 34cb323dae..8465f33719 100644 --- a/crates/engine/src/cmd/smart_cmds/tests.rs +++ b/crates/engine/src/cmd/smart_cmds/tests.rs @@ -1667,3 +1667,31 @@ fn set_params_replace_drops_a_shape_blur_radius_it_leaves_out() { s.execute("layer.smartFilter.setParams", json!({"params": {"shape": "circle"}, "replace": true})).unwrap(); assert!(params(&s).get("radius").is_none(), "replaced: {}", params(&s)); } + +/// A smart filter re-renders from its params alone, without the document's alpha channels (#7400): Lens Blur refuses an +/// alpha channel as its depth on a Smart Object, both when it is applied and when a recorded filter's params are edited +/// (merged or replaced), and the refused edit changes neither the filter nor the history. +#[test] +fn lens_blur_smart_filter_refuses_an_alpha_channel_depth_on_edit() { + let mut s = session(8); + paint(&mut s); + s.execute("select.all", json!({})).unwrap(); + s.execute("select.saveSelection", json!({"name": "Depth"})).unwrap(); + s.execute("select.deselect", json!({})).unwrap(); + s.execute("filter.convertForSmartFilters", json!({})).unwrap(); + let channel = json!({"radius": 4, "depthMap": "channel", "depthChannel": 0}); + let applied = s.execute("filter.blur.lensBlur", channel.clone()).unwrap_err().to_string(); + assert!(applied.contains("rasterize the layer first"), "{applied}"); + s.execute("filter.blur.lensBlur", json!({"radius": 4, "depthMap": "transparency"})).unwrap(); + let recorded = active_smart(&s).smart_filters[0].params.clone(); + let steps = s.active().unwrap().history.past_len(); + for replace in [false, true] { + let e = s.execute("layer.smartFilter.setParams", json!({"index": 0, "params": channel, "replace": replace})).unwrap_err().to_string(); + assert!(e.contains("rasterize the layer first"), "replace={replace}: {e}"); + assert_eq!(active_smart(&s).smart_filters[0].params, recorded, "replace={replace}"); + assert_eq!(s.active().unwrap().history.past_len(), steps, "replace={replace}"); + } + // Sources that need no channel stay editable. + s.execute("layer.smartFilter.setParams", json!({"index": 0, "params": {"depthMap": "none"}})).unwrap(); + assert_eq!(active_smart(&s).smart_filters[0].params["depthMap"], json!("none")); +} diff --git a/crates/engine/src/filters.rs b/crates/engine/src/filters.rs index dd263e335a..9a48debb9b 100644 --- a/crates/engine/src/filters.rs +++ b/crates/engine/src/filters.rs @@ -76,6 +76,11 @@ fn preset(id: &str) -> Option<(&'static str, FilterParams)> { }) } +/// Why Lens Blur refuses an alpha channel as its depth on a Smart Object: a smart filter re-renders from its params +/// alone, without the document's channels, so the depth would be lost (#7400). Applying it and editing a recorded +/// filter's params both refuse it. +pub(crate) const LENS_BLUR_CHANNEL_ON_SMART: &str = "Lens Blur can't read an alpha channel as depth on a Smart Object: rasterize the layer first"; + /// Builds the algorithm parameters for a filter command id from JSON params /// (Photoshop dialog units). Stored smart filters and previews retain their tolerant decoding; /// new command invocations pass through `validate_params` before any document changes. @@ -339,7 +344,7 @@ pub(crate) fn run_filter(s: &mut Session, id: &str, p: &Value) -> Result // A smart filter re-renders from its params alone, without the document's // channels, so Lens Blur's alpha-channel depth would be lost (#7400). if matches!(fp, FilterParams::LensBlur { depth: algo::DepthSource::Channel, .. }) { - return Err(EngineError::Other("Lens Blur can't read an alpha channel as depth on a Smart Object: rasterize the layer first".into())); + return Err(EngineError::Other(LENS_BLUR_CHANNEL_ON_SMART.into())); } // A smart filter re-renders from its params alone: a Displace map read from an // open document, which the re-render can't read again, is kept in them, as