PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(atn): export Black & White adjustment layers with Photoshop's BanW class (#8481)
Arian10000d5a71313ab
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rsindex 3be9ee217..6b2c37df8 100644--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@ -874,14 +874,22 @@ const ADJUSTMENTS: &[Adjustment] = &[adj_fields!("Vbrn", "vibrance", &[F("vibrance", "vibrance", Kind::Long), F("Strt", "saturation", Kind::Long)]),adj_fields!("Exps", "exposure", &[F("Exps", "exposure", Kind::Dbl), F("Ofst", "offset", Kind::Dbl), F("gammaCorrection", "gamma", Kind::Dbl)]),Adjustment { class: "PhtF", suffix: "photoFilter", from: |d| fields_from(d, PHOTO_FILTER_FIELDS).map(Value::Object), to: photo_filter_to },- adj_fields!("BlnW", "blackWhite", BW),+ adj_fields!("BanW", "blackWhite", BW),Adjustment { class: "ChnM", suffix: "channelMixer", from: channel_mixer_from, to: channel_mixer_to },Adjustment { class: "SlcC", suffix: "selectiveColor", from: selective_from, to: selective_to },Adjustment { class: "GdMp", suffix: "gradientMap", from: gradient_map_from, to: gradient_map_to },];+/// Adjustment classes PhotoCraft once exported, with the class Photoshop uses. Measured in+/// Photoshop (#8481): a Make whose Black & White type is `BlnW` fails ("the command Make is not+/// currently available"), `BanW` runs. Import keeps accepting them so actions saved before still+/// load; export never writes them.+const LEGACY_CLASSES: &[(&str, &str)] = &[("BlnW", "BanW")];+fn adjustment_by_class(c: &str) -> Option<&'static Adjustment> {- ADJUSTMENTS.iter().find(|a| a.class.trim_end() == c.trim_end())+ let c = c.trim_end();+ let c = LEGACY_CLASSES.iter().find(|(old, _)| *old == c).map_or(c, |(_, class)| class);+ ADJUSTMENTS.iter().find(|a| a.class.trim_end() == c)}const PHOTO_FILTER_FIELDS: &[F] = &[F("Clr ", "color", Kind::Color), F("Dnst", "density", Kind::Long), F("PrsL", "preserveLuminosity", Kind::Bool)];@@ -3105,7 +3113,7 @@ const EVENTS: &[Event] = &[adjustment_event!("Vbrn", "Vbrn", "vibrance", "Vibrance"),adjustment_event!("Exps", "Exps", "exposure", "Exposure"),adjustment_event!("PhtF", "PhtF", "photoFilter", "Photo Filter"),- adjustment_event!("", "BlnW", "blackAndWhite", "Black & White", "image.adjustments.blackWhite"),+ adjustment_event!("", "BanW", "blackAndWhite", "Black & White", "image.adjustments.blackWhite"),adjustment_event!("ChnM", "ChnM", "channelMixer", "Channel Mixer"),adjustment_event!("GdMp", "GdMp", "gradientMapEvent", "Gradient Map", "image.adjustments.gradientMap"),adjustment_event!("SlcC", "SlcC", "selectiveColor", "Selective Color"),diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rsindex e8595086a..e5d258317 100644--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@ -1444,6 +1444,40 @@ fn events_photoshop_only_runs_by_name_export_by_name_and_old_codes_still_import(}}+/// A Black & White adjustment layer saves with Photoshop's `BanW` class (#8481): measured in+/// Photoshop, a Make whose type is `BlnW` is refused. Photoshop's own `BanW` Make loads, and so+/// does the `BlnW` one PhotoCraft wrote before.+#[test]+fn black_white_adjustment_layer_saves_as_photoshops_class_and_old_class_still_imports() {+ let id = "layer.newAdjustmentLayer.blackWhite";+ let params = json!({"reds": 17, "yellows": 83, "greens": -12, "cyans": 107, "blues": 51, "magentas": 133, "tint": true, "tintColor": "#c08040"});+ let mut s = Session::new();+ s.actions.list.push(Action::new("BW", vec![(id.into(), params.clone())]));+ let r = s.execute("actions.save", json!({"action": "BW"})).unwrap();+ assert_eq!(r["skipped"], json!([]));+ let saved = photocraft_paint::tile::b64_decode(r["data"].as_str().unwrap()).unwrap();+ let file = atn::parse(&saved).unwrap();+ let make = file.actions[0].items[0].descriptor.as_ref().unwrap();+ let kind = get_obj(make, "Usng").and_then(|u| get_obj(u, "Type")).unwrap();+ assert_eq!(trimmed(&kind.class_id), "BanW");+ let mut t = Session::new();+ let r = t.execute("actions.load", json!({"data": b64(&saved)})).unwrap();+ assert_eq!(r["unsupported"], json!([]), "{r}");+ assert_eq!(t.actions.list[0].steps, vec![(id.to_string(), params)]);++ // Photoshop's minimal Make (no settings) and the old PhotoCraft class both load; near misses+ // stay Photoshop steps.+ let make = |class: &str| {+ let using = desc("AdjL").with("Type", D::Descriptor(desc(class)));+ item("Mk ", "Make", Some(desc("null").with("null", class_ref("AdjL")).with("Usng", D::Descriptor(using))))+ };+ let data = set_of("S", vec![("A", ["BanW", "BlnW", "BANW", "BlnWx"].into_iter().map(make).collect())]);+ let mut t = Session::new();+ let r = t.execute("actions.load", json!({"data": data})).unwrap();+ let steps: Vec<&str> = t.actions.list[0].steps.iter().map(|(id, _)| id.as_str()).collect();+ assert_eq!(steps, [id, id, PHOTOSHOP_STEP, PHOTOSHOP_STEP], "{r}");+}+/// Smart Blur's quality uses Photoshop's `SmBQ` codes (`SBQL`/`SBQM`/`SBQH`): measured in/// Photoshop, the old `Hgh `/`Mdm `/`Low ` play back as its fallback quality. Old codes still read.#[test]