Lens Blur: an alpha channel as the depth map runs again

Since the move to the craft UI framework, Lens Blur's Depth Map menu
names an alpha channel `channel:N`, and that id went to the command as
is. The engine takes `channel` with `depthChannel`, so OK failed with
"`depthMap` must be one of none|transparency|layerMask|channel" and the
preview showed nothing. command_params now sends the `channel` source
and the channel's index.

Test: a document with two alpha channels, the second chosen as the
depth map, reaches the command as `channel` and index 1 and runs (fails
before the change: `channel:1` and no depthChannel).
This commit is contained in:
Ivan Sanchez committed 2026-11-19 15:57:54 -08:00
1 parent 470324eb26
commit 5445aeec54
2 files changed
+32

No files matched your search

@@ -610,6 +610,14 @@ pub(crate) fn command_params(command: &str, fields: &DialogFields) -> Value {
map.insert("matte".into(), color);
}
}
// Lens Blur's Source menu names an alpha channel `channel:N` (by index: two channels may share a name); the command
// takes the `channel` source and the channel's index.
if command == rows::LENS_BLUR
&& let Some(index) = map.get("depthMap").and_then(Value::as_str).and_then(rows::channel_of_choice)
{
map.insert("depthMap".into(), json!("channel"));
map.insert("depthChannel".into(), json!(index));
}
if command == "filter.blur.radialBlur"
&& let Some([x, y]) = fields.point("center")
{
@@ -1835,3 +1835,27 @@ fn indexed_matte_other_shows_the_color_row_and_none_hides_it() {
assert_eq!(fields_of(harness.state(), id).text("matte"), Some("none"));
assert!(try_set(harness.state_mut(), id, "matteColor", json!([0.0, 0.0, 1.0])).is_err(), "None hides the colour row");
}
/// An alpha channel chosen as Lens Blur's depth map reaches the command as the `channel` source and its index: the
/// menu's own `channel:N` id was sent as is, and the engine refused it at OK and in the preview.
#[test]
fn lens_blur_alpha_channel_source_runs() {
let mut app = new_app();
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
for name in ["Mask", "Depth"] {
app.run("select.all", json!({})).unwrap();
app.run("select.saveSelection", json!({"name": name})).unwrap();
}
app.run("select.deselect", json!({})).unwrap();
let id = open(&mut app, LENS_BLUR).unwrap();
passes(&mut app, 2);
set(&mut app, id, "depthMap", json!("channel:1"));
passes(&mut app, 2);
let params = command_params(LENS_BLUR, &fields_of(&app, id));
assert_eq!((&params["depthMap"], &params["depthChannel"]), (&json!("channel"), &json!(1)), "{params}");
app.run(LENS_BLUR, params).expect("the command takes the channel source");
// The other sources pass through.
set(&mut app, id, "depthMap", json!("transparency"));
let params = command_params(LENS_BLUR, &fields_of(&app, id));
assert_eq!((&params["depthMap"], params.get("depthChannel")), (&json!("transparency"), None));
}