mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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 <[email protected]>
This commit is contained in:
1 parent
fbd84f2d88
commit
e1d950d6b2
3 files changed
+38
-1
No files matched your search
@@ -229,6 +229,10 @@ pub(super) fn set_filter_params(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
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 {
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
@@ -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<Value>
|
||||
// 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
|
||||
|
||||
Reference in new issue
Block a user