Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Image > Adjustments: locked smart objects refuse new smart filters (#5655)

David Mannafd735ba96fb
diff --git a/crates/engine/src/adjust_cmds.rs b/crates/engine/src/adjust_cmds.rs
index c1393bb94..b24272734 100644
--- a/crates/engine/src/adjust_cmds.rs
+++ b/crates/engine/src/adjust_cmds.rs
@@ -270,6 +270,8 @@ pub(crate) fn adjust_as_smart_filter(s: &mut Session, kind: &str, label: &str, p
if !smart {
return Ok(false);
}
+ // A pixel or full lock refuses the smart filter, as for `filter.*` on a smart object.
+ crate::commands::check_pixels_unlocked(&s.active().ok_or(EngineError::NoDocument)?.doc, id)?;
// The recorded params are the command's own, minus the engine's private `__kind` key.
let mut params = p.clone();
if let Value::Object(m) = &mut params {
diff --git a/crates/engine/src/adjust_cmds/tests.rs b/crates/engine/src/adjust_cmds/tests.rs
index 9f614732d..249b88e4b 100644
--- a/crates/engine/src/adjust_cmds/tests.rs
+++ b/crates/engine/src/adjust_cmds/tests.rs
@@ -479,6 +479,26 @@ fn adjustment_smart_filters_take_a_selection_as_their_mask() {
assert_eq!(at(&now, 40, 16), at(&original, 40, 16), "outside the mask the composite is unchanged");
}
+/// #5655: as for `filter.*` smart filters, a pixel or full lock refuses an adjustment smart
+/// filter, leaving the layer and the history as they were.
+#[test]
+fn locked_smart_objects_refuse_adjustment_smart_filters() {
+ let adjustments =
+ [("image.adjustments.invert", json!({})), ("image.adjustments.shadowsHighlights", json!({"shadowAmount": 100, "blackClip": 0, "whiteClip": 0}))];
+ for lock in [json!({"all": true}), json!({"pixels": true})] {
+ for (cmd, p) in &adjustments {
+ let mut s = smart_session();
+ s.execute("layer.lockLayers", lock.clone()).unwrap();
+ let (steps, flat) = (s.active().unwrap().history.past_len(), flatten(&s));
+ let r = s.execute(cmd, p.clone());
+ assert!(r.is_err(), "{cmd} added a smart filter to a smart object locked with {lock}: {r:?}");
+ assert!(smart_filters_of(&s).is_empty(), "{cmd} {lock}: nothing recorded");
+ assert_eq!(s.active().unwrap().history.past_len(), steps, "{cmd} {lock}: no history step");
+ assert_eq!(flatten(&s), flat, "{cmd} {lock}: pixels untouched");
+ }
+ }
+}
+
/// A wrong-typed value errors before anything is recorded (never a panic), and the adjustments
/// that can't re-render from a source (Replace Color, Match Color) stay off a smart object.
#[test]