PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Integration: #7611 smart brush export refuses steps with refine strokes
aiongg87d930997bf4
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rsindex ba2ad90fb..a1958b1a7 100644--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@ -3037,14 +3037,16 @@ macro_rules! adjustment_event {const RIPPLE_SIZE: &[(&str, &str)] = &[("Sml", "small"), ("Mdm", "medium"), ("Lrg", "large")];+/// Whether a Select and Mask step carries Refine Edge Brush strokes, which no descriptor holds.+fn has_refine_strokes(p: &Value) -> bool {+ p.get("refineStrokes").is_some_and(|v| !v.is_null() && v.as_array().is_none_or(|a| !a.is_empty()))+}+/// Select and Mask to Photoshop. The descriptor has no field for the Refine Edge Brush, so a/// step with `refineStrokes` can't be exported faithfully. One with `sampleAllLayers` is not/// exported here either: it exports as `smartBrushWorkspace`.fn refine_edge_to(_: &str, p: &Value) -> Option<Descriptor> {- if !pixel_target(p)- || p.get("sampleAllLayers").is_some()- || p.get("refineStrokes").is_some_and(|v| !v.is_null() && v.as_array().is_none_or(|a| !a.is_empty()))- {+ if !pixel_target(p) || p.get("sampleAllLayers").is_some() || has_refine_strokes(p) {return None;}fields_to(p, REFINE_EDGE, desc("null"))@@ -3614,7 +3616,7 @@ const EVENTS: &[Event] = &[},to: refine_edge_to,},- ev!("", "smartBrushWorkspace", "Select and Mask", "select.refineEdge", SMART_BRUSH),+ ev!("", "smartBrushWorkspace", "Select and Mask", "select.refineEdge", SMART_BRUSH, unless has_refine_strokes),ev!("", "autoCutout", "Select Subject", "select.subject", &[F("sampleAllLayers", "sampleAllLayers", Kind::Bool)]),Event { code: "ClrR", name: "colorRange", label: "Color Range", ids: &["select.colorRange"], from: color_range_from, to: color_range_to },// Edit.diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rsindex a50e4ceeb..c8e2dab39 100644--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@ -2410,6 +2410,27 @@ fn image_size_round_trip(params: &Value) -> Option<Value> {}}+/// A step with brush strokes and Sample All Layers is refused by `refineSelectionEdge`; it must+/// not fall through to `smartBrushWorkspace`, which has no field for the strokes either.+#[test]+fn refine_edge_with_strokes_and_sample_all_layers_is_not_exported_without_the_strokes() {+ let stroke = json!({"points": [[5, 4]], "size": 4, "mode": "add"});+ let brushed = Action {+ name: "Probe".into(),+ steps: vec![("select.refineEdge".into(), json!({"radius": 1, "sampleAllLayers": true, "refineStrokes": [stroke]}))],+ ..Default::default()+ };+ assert!(export("Audit", &[&brushed], &[], false).is_err());+ let (_, skipped) = export("Audit", &[&brushed], &[], true).unwrap();+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "select.refineEdge".into() }]);+ let plain = Action {+ name: "Plain".into(),+ steps: vec![("select.refineEdge".into(), json!({"radius": 1, "sampleAllLayers": true, "refineStrokes": []}))],+ ..Default::default()+ };+ assert!(export("Audit", &[&plain], &[], false).is_ok());+}+/// Photoshop's Select and Mask descriptor as mapped has no field for the Refine Edge Brush,/// so a step with brush strokes must not export as a plain Select and Mask without them.#[test]