Skip to content

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

Integration: merge main (#8180)

David Mannaa87afc88692
diff --cc crates/engine/src/atn_cmds.rs
index 811d1dbc5,f166c239b..1a0fa60ad
--- a/crates/engine/src/atn_cmds.rs
+++ b/crates/engine/src/atn_cmds.rs
@@@ -1736,13 -2048,16 +2048,22 @@@ fn apply_image_from(d: &Descriptor) ->
}
fn apply_image_to(_: &str, p: &Value) -> Option<Descriptor> {
+ // The optional blending mask has no descriptor mapping: refuse it rather than drop it,
+ // which would widen the edit to the whole layer.
+ let mask_channel = match p.get("mask") {
+ Some(m) => m.get("channel"),
+ None => p.get("maskChannel"),
+ };
+ if mask_channel.is_some_and(|c| !(c.is_null() || c == "none" || c == "")) {
+ return None;
+ }
- let source = p.get("source").cloned().unwrap_or(json!({}));
+ // The Apply Image dialog sends flat `sourceLayer`/`sourceChannel`/`sourceInvert` fields; read
+ // them as the command does, or the export would quietly reset them to the merged composite.
+ let source = crate::channel_cmds::source_spec(p, "source", "source").unwrap_or(json!({}));
+ // A source from another open document has no event form here: skip the step, don't rewrite it.
+ if source.get("document").is_some_and(|d| !d.is_null()) {
+ return None;
+ }
let channel = jstr(&source, "channel").unwrap_or("composite");
let chan = lookup_back(SOURCE_CHANNELS, channel).or_else(|| lookup_back(CHANNELS, channel))?;
let mut items = vec![ReferenceItem::Enumerated { class: class("Chnl"), type_id: code("Chnl"), value: code(chan) }];
diff --cc crates/engine/src/atn_cmds/tests.rs
index bbcef0ad5,d83d69e62..d7d8e87f8
--- a/crates/engine/src/atn_cmds/tests.rs
+++ b/crates/engine/src/atn_cmds/tests.rs
@@@ -1388,22 -2316,372 +2316,392 @@@ fn function_keys_keep_shift_and_command
assert_eq!(super::function_key_name(7, false, false), "F7");
}
+/// The Apply Image dialog's flat source fields keep their meaning through a strict `.atn` export
+/// (#7197): they used to come back as the merged composite.
+#[test]
+fn apply_image_flat_source_fields_survive_a_strict_export() {
+ let flat = json!({"sourceLayer": "Pixels", "sourceChannel": "green", "sourceInvert": true, "blending": "normal", "opacity": 75});
+ let item = export_item("image.applyImage", &flat, "S").expect("the flat form exports");
+ let event = event_for(&item.event).expect("a known event");
+ let Mapped::Steps(steps) = (event.from)(item.descriptor.as_ref().unwrap()) else { panic!("does not import back") };
+ assert_eq!(steps.len(), 1);
+ assert_eq!(steps[0].1["source"], json!({"layer": "Pixels", "channel": "green", "invert": true}));
+ // The nested form is unchanged, and the "merged" layer of a flat form stays merged.
+ let merged = json!({"sourceLayer": "merged", "sourceChannel": "red"});
+ let item = export_item("image.applyImage", &merged, "S").expect("exports");
+ let Mapped::Steps(steps) = (event.from)(item.descriptor.as_ref().unwrap()) else { panic!("does not import back") };
+ assert_eq!(steps[0].1["source"], json!({"layer": "merged", "channel": "red"}));
+ // A source in another document cannot be written: the step is skipped, not rewritten.
+ assert!(export_item("image.applyImage", &json!({"source": {"document": "Other", "channel": "red"}}), "S").is_none());
+ assert!(export_item("image.applyImage", &json!({"sourceDocument": "Other"}), "S").is_none());
+}
++
+ /// A param a PhotoCraft step leaves out exports as PhotoCraft's default wherever Photoshop plays
+ /// the missing key differently (checked against Photoshop): Canvas Size anchors top left,
+ /// Apply Image blends Normal, Color Balance turns preserve luminosity off, and a Paint Bucket
+ /// step without a tolerance doesn't play at all.
+ #[test]
+ fn defaults_photoshop_plays_differently_are_written() {
+ let exported = |id: &str, p: Value| export_item(id, &p, "S").and_then(|i| i.descriptor).unwrap_or_else(|| panic!("{id} does not export"));
+ let bucket = exported("paint.bucket", json!({"x": 1, "y": 2}));
+ assert_eq!((get_num(&bucket, "Tlrn"), get_bool(&bucket, "AntA")), (Some(32.0), Some(true)));
+ let canvas = exported("image.canvasSize", json!({"width": 10, "height": 10}));
+ assert_eq!((get_enum(&canvas, "Hrzn").as_deref(), get_enum(&canvas, "Vrtc").as_deref()), (Some("Cntr"), Some("Cntr")));
+ let apply = exported("image.applyImage", json!({}));
+ assert_eq!(get_obj(&apply, "With").and_then(|w| get_enum(w, "Clcl")).as_deref(), Some("Mltp"));
+ let balance = exported("image.adjustments.colorBalance", json!({"midtones": [10, 0, 0]}));
+ assert_eq!(get_bool(&balance, "PrsL"), Some(true));
+ assert_eq!(get_list(&balance, "ShdL").map(<[D]>::len), Some(3));
+ }
+
+ /// Photoshop sets one colour per step: a step that sets both doesn't export rather than drop one.
+ #[test]
+ fn set_colors_exports_only_a_single_colour() {
+ assert!(export_item("tools.setColors", &json!({"foreground": "#ff0000", "background": "#0000ff"}), "S").is_none());
+ assert!(export_item("tools.setColors", &json!({"foregroundCmyk": [0, 0, 0, 100], "background": "#0000ff"}), "S").is_none());
+ assert!(export_item("tools.setColors", &json!({"background": "#0000ff"}), "S").is_some());
+ }
+
+ /// Photoshop's reset of an adjustment layer (`set` with an empty `T`) stays a reset: `kind`
+ /// only joins params that edit something, as any key makes `layer.setAdjustment` merge.
+ #[test]
+ fn adjustment_layer_reset_still_resets() {
+ let set = |t: Descriptor| desc("null").with("null", target_ref("AdjL")).with("T ", D::Descriptor(t));
+ let reset = set(desc("HStr").with("presetKind", enm("presetKindType", "presetKindDefault")));
+ let edit = set(desc("ClrB").with("MdtL", D::List(vec![long(10.0), long(0.0), long(0.0)])));
+ let file = AtnFile {
+ name: UnicodeString::new_nul("Reset"),
+ expanded: false,
+ actions: vec![AtnAction {
+ name: UnicodeString::new_nul("A"),
+ items: vec![item("setd", "Set", Some(reset)), item("setd", "Set", Some(edit))],
+ ..Default::default()
+ }],
+ warnings: vec![],
+ };
+ let steps = import(&atn::write(&file).unwrap()).unwrap().actions.remove(0).steps;
+ assert_eq!(steps[0], ("layer.setAdjustment".to_string(), json!({})));
+ assert_eq!(steps[1].1, json!({"midtones": [10, 0, 0], "kind": "colorBalance"}));
+ }
+
+ /// A Free Transform recorded against an unlinked mask or an alpha channel must not export as a
+ /// layer transform that moves the layer's pixels on replay (#7195).
+ #[test]
+ fn transform_with_mask_or_channel_target_is_not_exported_as_layer_transform() {
+ for target in [json!("mask"), json!({"channel": 0}), json!("quickMask")] {
+ let a = Action {
+ name: "Probe".into(),
+ steps: vec![("edit.transform".into(), json!({"target": target, "dx": 3, "dy": 2, "scaleX": 100, "interpolation": "nearest"}))],
+ ..Default::default()
+ };
+ assert!(export("Targets", &[&a], &[], false).is_err(), "{target} exported");
+ let (_, skipped) = export("Targets", &[&a], &[], true).unwrap();
+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "edit.transform".into() }]);
+ }
+ for params in [
+ json!({"dx": 3, "dy": 2, "scaleX": 50, "interpolation": "nearest"}),
+ json!({"target": "pixels", "dx": 3, "dy": 2, "scaleX": 50, "interpolation": "nearest"}),
+ ] {
+ let plain = Action { name: "Plain".into(), steps: vec![("edit.transform".into(), params)], ..Default::default() };
+ let (bytes, skipped) = export("Targets", &[&plain], &[], false).unwrap();
+ assert!(skipped.is_empty());
+ let imported = import(&bytes).unwrap();
+ assert_eq!(imported.actions[0].steps, vec![("edit.transform".to_string(), json!({"dx": 3, "dy": 2, "scaleX": 50, "interpolation": "nearest"}))]);
+ }
+ for form in [json!({"quad": [[0, 0], [1, 0], [1, 1], [0, 1]]}), json!({"matrix": [1, 0, 0, 1, 0, 0]}), json!({"rect": [0, 0, 1, 1]})] {
+ assert!(transform_to("edit.transform", &form).is_none());
+ }
+ }
+
+ /// Apply Image's optional blending mask has no `.atn` mapping: a strict export must refuse the
+ /// step rather than drop the mask and widen the edit to the whole layer.
+ #[test]
+ fn apply_image_with_blending_mask_is_not_exported_without_its_mask() {
+ let source = json!({"layer": "Pixels", "channel": "green", "invert": true});
+ for params in [json!({"source": source, "blending": "normal", "mask": {"channel": 0}}), json!({"source": source, "blending": "normal", "maskChannel": 0})] {
+ let masked = Action { name: "Masked".into(), steps: vec![("image.applyImage".into(), params.clone())], ..Default::default() };
+ assert!(export("Audit5", &[&masked], &[], false).is_err(), "{params}");
+ let (_, skipped) = export("Audit5", &[&masked], &[], true).unwrap();
+ assert_eq!(skipped, vec![Skipped { action: "Masked".into(), step: 0, id: "image.applyImage".into() }]);
+ }
+ for params in [json!({"source": source, "blending": "normal"}), json!({"source": source, "blending": "normal", "mask": {"channel": "none"}})] {
+ let plain = Action { name: "Plain".into(), steps: vec![("image.applyImage".into(), params.clone())], ..Default::default() };
+ let (bytes, skipped) = export("Audit5", &[&plain], &[], false).unwrap();
+ assert!(skipped.is_empty());
+ let imported = import(&bytes).unwrap();
+ assert_eq!(imported.actions[0].steps, vec![("image.applyImage".to_string(), json!({"source": source, "blending": "normal"}))]);
+ }
+ }
+
+ fn image_size_round_trip(params: &Value) -> Option<Value> {
+ let item = export_item("image.imageSize", params, "S")?;
+ let e = event_for(&item.event).unwrap();
+ match (e.from)(item.descriptor.as_ref().unwrap()) {
+ Mapped::Steps(steps) => Some(steps[0].1.clone()),
+ _ => panic!("image size descriptor did not import as steps"),
+ }
+ }
+
+ /// 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]
+ fn refine_edge_with_brush_strokes_is_not_exported_without_them() {
+ for mode in ["add", "subtract"] {
+ let brushed = Action {
+ name: "Probe".into(),
+ steps: vec![("select.refineEdge".into(), json!({"radius": 1, "refineStrokes": [{"points": [[5, 4]], "size": 4, "mode": mode}]}))],
+ ..Default::default()
+ };
+ assert!(export("Audit", &[&brushed], &[], false).is_err(), "{mode}");
+ let (_, skipped) = export("Audit", &[&brushed], &[], true).unwrap();
+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "select.refineEdge".into() }]);
+ }
+ for params in [json!({"radius": 1}), json!({"radius": 1, "refineStrokes": []}), json!({"radius": 1, "refineStrokes": null})] {
+ let plain = Action { name: "Plain".into(), steps: vec![("select.refineEdge".into(), params)], ..Default::default() };
+ let (bytes, skipped) = export("Audit", &[&plain], &[], false).unwrap();
+ assert!(skipped.is_empty());
+ let imported = import(&bytes).unwrap();
+ assert_eq!(imported.actions[0].steps, vec![("select.refineEdge".to_string(), json!({"radius": 1}))]);
+ }
+ }
+
+ #[test]
+ fn image_size_resolution_only_does_not_gain_keep_print_size() {
+ // The .atn cannot tell resolution-only from keepPrintSize:true, so the former must not
+ // export as a descriptor that imports back as keep-print-size.
+ let params = json!({"resolution": 144, "resample": "nearest"});
+ assert_eq!(image_size_round_trip(&params), None);
+ }
+
+ #[test]
+ fn image_size_intentional_controls_still_round_trip() {
+ for params in [
+ json!({"resolution": 144.0, "resample": "nearest", "keepPrintSize": true}),
+ json!({"width": 12.0, "height": 10.0, "resolution": 144.0, "resample": "nearest"}),
+ ] {
+ assert_eq!(image_size_round_trip(&params), Some(params.clone()));
+ }
+ }
+
+ #[test]
+ fn recorded_layer_select_exports_to_atn() {
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
+ let l = s.execute("layer.new.layer", json!({"name": "Wanted"})).unwrap();
+ let wanted_id = l["layer"].as_u64().unwrap();
+ s.execute("actions.record", json!({"name": "SelectWanted"})).unwrap();
+ s.execute("layer.select", json!({"layer": wanted_id})).unwrap();
+ s.execute("actions.stop", json!({})).unwrap();
+
+ let action = s.execute("actions.get", json!({"action": "SelectWanted"})).unwrap();
+ assert_eq!(action["steps"][0], json!(["layer.select", {"name": "Wanted"}]));
+
+ // Strict export should succeed and produce bytes without skipUnsupported
+ let saved = s.execute("actions.save", json!({"action": "SelectWanted"})).unwrap();
+ assert_eq!(saved["steps"], 1);
+ assert_eq!(saved["skipped"], json!([]));
+
+ // When exported with skipUnsupported: true, it shouldn't skip the step either
+ let saved_skip = s.execute("actions.save", json!({"action": "SelectWanted", "skipUnsupported": true})).unwrap();
+ assert_eq!(saved_skip["steps"], 1);
+ assert_eq!(saved_skip["skipped"], json!([]));
+
+ // If an action has an occurrence target (duplicate names), it cannot be represented unambiguously in .atn
+ let bad_action = Action::new("Dup", vec![("layer.select".into(), json!({"name": "Wanted", "occurrence": 1}))]);
+ let err = export("Set", &[&bad_action], &[], false);
+ assert!(err.is_err(), "occurrence without representation must fail strict export");
+ }
+
+ #[test]
+ fn select_rect_mode_strict_export_rejects_unrepresentable_modes() {
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
+
+ // Default or "replace" mode succeeds
+ s.actions.list.push(Action::new("ReplaceAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "replace"}))]));
+ let saved = s.execute("actions.save", json!({"action": "ReplaceAct"})).unwrap();
+ assert_eq!(saved["steps"], 1);
+
+ // "add" mode cannot be silently converted to replace (set) in strict export
+ s.actions.list.push(Action::new("AddAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "add"}))]));
+ let before_actions = s.actions.list.clone();
+ let err = s.execute("actions.save", json!({"action": "AddAct"}));
+ assert!(err.is_err(), "strict export must reject select.rect with add mode rather than converting to replace");
+ assert_eq!(s.actions.list, before_actions, "actions list must remain unchanged after rejected save");
+
+ // "subtract" mode cannot be silently converted to replace either
+ s.actions.list.push(Action::new("SubtractAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "subtract"}))]));
+ let before_actions_sub = s.actions.list.clone();
+ let err_subtract = s.execute("actions.save", json!({"action": "SubtractAct"}));
+ assert!(err_subtract.is_err(), "strict export must reject select.rect with subtract mode rather than converting to replace");
+ assert_eq!(s.actions.list, before_actions_sub, "actions list must remain unchanged after rejected save");
+
+ // With skipUnsupported: true, unrepresentable modes are reported in skipped
+ let skipped = s.execute("actions.save", json!({"action": "AddAct", "skipUnsupported": true})).unwrap();
+ assert_eq!(skipped["steps"], 0);
+ assert_eq!(skipped["skipped"][0]["id"], "select.rect");
+ }
+
+ #[test]
+ fn radial_blur_off_center_strict_export_refuses_silent_recentering() {
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 16, "height": 16})).unwrap();
+
+ // Default center (omitted) exports successfully
+ s.actions.list.push(Action::new("DefaultCenter", vec![("filter.blur.radialBlur".into(), json!({"amount": 50, "method": "spin", "quality": "good"}))]));
+ let saved = s.execute("actions.save", json!({"action": "DefaultCenter"})).unwrap();
+ assert_eq!(saved["steps"], 1);
+
+ // Explicit (0.5, 0.5) center also exports successfully
+ s.actions.list.push(Action::new(
+ "ExplicitDefaultCenter",
+ vec![("filter.blur.radialBlur".into(), json!({"amount": 50, "method": "spin", "quality": "good", "centerX": 0.5, "centerY": 0.5}))],
+ ));
+ let saved_exp = s.execute("actions.save", json!({"action": "ExplicitDefaultCenter"})).unwrap();
+ assert_eq!(saved_exp["steps"], 1);
+
+ // Off-center radial blur cannot be silently recentered in strict export
+ s.actions.list.push(Action::new(
+ "OffCenter",
+ vec![("filter.blur.radialBlur".into(), json!({"amount": 50, "method": "spin", "quality": "good", "centerX": 0.1, "centerY": 0.2}))],
+ ));
+ let before_actions = s.actions.list.clone();
+ let err = s.execute("actions.save", json!({"action": "OffCenter"}));
+ assert!(err.is_err(), "strict export must reject off-center radial blur rather than silently recentering it");
+ assert_eq!(s.actions.list, before_actions, "actions list must remain unchanged after rejected save");
+
+ // With skipUnsupported: true, off-center radial blur is skipped
+ let skipped = s.execute("actions.save", json!({"action": "OffCenter", "skipUnsupported": true})).unwrap();
+ assert_eq!(skipped["steps"], 0);
+ assert_eq!(skipped["skipped"][0]["id"], "filter.blur.radialBlur");
+
+ // Radial blur targeting a mask must not export as a plain filter that edits pixels
+ s.actions
+ .list
+ .push(Action::new("MaskTarget", vec![("filter.blur.radialBlur".into(), json!({"amount": 50, "method": "spin", "quality": "good", "target": "mask"}))]));
+ let before_actions = s.actions.list.clone();
+ let err_mask = s.execute("actions.save", json!({"action": "MaskTarget"}));
+ assert!(err_mask.is_err(), "strict export must reject radial blur with non-pixel target");
+ assert_eq!(s.actions.list, before_actions, "actions list must remain unchanged after rejected save");
+
+ let skipped_mask = s.execute("actions.save", json!({"action": "MaskTarget", "skipUnsupported": true})).unwrap();
+ assert_eq!(skipped_mask["steps"], 0);
+ assert_eq!(skipped_mask["skipped"][0]["id"], "filter.blur.radialBlur");
+
+ // Explicit pixels target exports successfully
+ s.actions.list.push(Action::new(
+ "PixelsTarget",
+ vec![("filter.blur.radialBlur".into(), json!({"amount": 50, "method": "spin", "quality": "good", "target": "pixels"}))],
+ ));
+ let saved_pixels = s.execute("actions.save", json!({"action": "PixelsTarget"})).unwrap();
+ assert_eq!(saved_pixels["steps"], 1);
+ }
+
+ /// A crop with W x H x Resolution output options must not export as a plain rectangle crop
+ /// that keeps the old size and resolution on replay: the mapper has no field for them.
+ #[test]
+ fn crop_with_output_size_or_resolution_is_not_exported_as_plain_crop() {
+ for params in [
+ json!({"x": 1, "y": 1, "width": 4, "height": 3, "targetWidth": 8, "targetHeight": 6, "resolution": 144, "resample": "nearest"}),
+ json!({"x": 1, "y": 1, "width": 4, "height": 3, "resolution": 144}),
+ json!({"x": 1, "y": 1, "width": 4, "height": 3, "targetWidth": 8, "targetHeight": 6}),
+ ] {
+ let sized = Action { name: "Probe".into(), steps: vec![("image.crop".into(), params)], ..Default::default() };
+ assert!(export("Audit", &[&sized], &[], false).is_err());
+ let (_, skipped) = export("Audit", &[&sized], &[], true).unwrap();
+ assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "image.crop".into() }]);
+ }
+ let plain = Action { name: "Plain".into(), steps: vec![("image.crop".into(), json!({"x": 1, "y": 1, "width": 4, "height": 3}))], ..Default::default() };
+ let (bytes, skipped) = export("Audit", &[&plain], &[], false).unwrap();
+ assert!(skipped.is_empty());
+ let imported = import(&bytes).unwrap();
+ assert_eq!(imported.actions[0].steps, vec![("image.crop".to_string(), json!({"x": 1, "y": 1, "width": 4, "height": 3}))]);
+ }
+
+ /// `image.imageSize` with `resample: "none"` ignores width, height and percent; the `.atn`
+ /// round trip must not turn them into a pixel resize (#7189).
+ #[test]
+ fn image_size_resample_none_keeps_ignoring_its_size_through_atn_export() {
+ let event = event_for(&export_item("image.imageSize", &json!({"resolution": 72}), "S").expect("exports").event).expect("a known event");
+ let back = |p: Value| {
+ let item = export_item("image.imageSize", &p, "S")?;
+ let Mapped::Steps(steps) = (event.from)(item.descriptor.as_ref().unwrap()) else { panic!("does not import back") };
+ let mut back = steps[0].1.clone();
+ normalise(&mut back);
+ Some(back)
+ };
+ for sized in [json!({"width": 12, "height": 10}), json!({"width": 12}), json!({"percent": 200}), json!({"width": 12, "percent": 50, "height": 3})] {
+ let mut p = sized.clone();
+ p["resolution"] = json!(144);
+ p["resample"] = json!("none");
+ assert_eq!(back(p.clone()), Some(json!({"resolution": 144, "resample": "none"})), "{p}");
+ }
+ // A step with nothing left to record is refused rather than exported as an empty (unsupported) event.
+ assert_eq!(back(json!({"width": 12, "height": 10, "resample": "none"})), None);
+ // Real resizes are untouched.
+ assert_eq!(back(json!({"width": 12, "height": 10, "resample": "bicubic"})), Some(json!({"width": 12, "height": 10, "resample": "bicubic"})));
+ }
+
+ /// #8302, #8308: Hue/Saturation's hue is `H ` in Photoshop's `Hst2`, both ways. It was written
+ /// and read as `Hue `: exported actions failed in Photoshop, and Photoshop-recorded ones lost
+ /// their hue on import with no warning. PhotoCraft's own older files (`Hue `) still read.
+ #[test]
+ fn hue_saturation_uses_photoshops_hue_key() {
+ let params = json!({"colorize": false, "hue": 30, "saturation": 20, "lightness": -7, "greens": {"hue": -12, "saturation": 0, "lightness": 0, "range": [75, 105, 135, 165]}});
+ let a = Action::new("H", vec![("image.adjustments.hueSaturation".into(), params.clone())]);
+ let (bytes, skipped) = export("S", &[&a], &[], false).unwrap();
+ assert!(skipped.is_empty());
+ let file = atn::parse(&bytes).unwrap();
+ let d = file.actions[0].items[0].descriptor.clone().expect("a descriptor");
+ let entries: Vec<Descriptor> =
+ get_list(&d, "Adjs").expect("Adjs").iter().filter_map(|e| if let D::Descriptor(e) = e { Some(e.clone()) } else { None }).collect();
+ assert_eq!(entries.len(), 2);
+ assert_eq!(get_num(&entries[0], "H "), Some(30.0), "the master hue under H");
+ assert_eq!(get_num(&entries[1], "H "), Some(-12.0), "a range's hue under H");
+ assert!(entries.iter().all(|e| get_num(e, "Hue ").is_none()), "no Hue key");
+
+ // A Photoshop-recorded step (H) and an older PhotoCraft one (Hue ) both import with the hue.
+ let step = |key: &str| {
+ desc("null")
+ .with("presetKind", enm("presetKindType", "presetKindCustom"))
+ .with("Clrz", D::Boolean(false))
+ .with("Adjs", D::List(vec![D::Descriptor(desc("Hst2").with(key, long(30.0)).with("Strt", long(20.0)).with("Lght", long(-7.0)))]))
+ };
+ for key in ["H ", "Hue "] {
+ let e = event_for(&item("HStr", "", None).event).expect("HStr imports");
+ match (e.from)(&step(key)) {
+ Mapped::Steps(steps) => {
+ assert_eq!(steps[0].0, "image.adjustments.hueSaturation");
+ assert_eq!(steps[0].1["hue"], json!(30.0), "{key:?}: {}", steps[0].1);
+ assert_eq!(steps[0].1["saturation"], json!(20.0));
+ }
+ Mapped::Unsupported { .. } => panic!("{key:?} is unsupported"),
+ }
+ }
+ // Through a whole file, saved and loaded back: the hue survives.
+ let back = import(&bytes).unwrap();
+ let mut p = back.actions[0].steps[0].1.clone();
+ normalise(&mut p);
+ assert_eq!(p["hue"], json!(30), "{p}");
+ }