mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #8527: fix(atn): export Black & White adjustment layers with Photoshop's BanW class (#8481)
This commit is contained in:
commit
ee85da2ffd
2 files changed
+48
-3
No files matched your search
@@ -892,14 +892,23 @@ 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")];
|
||||
|
||||
/// The adjustment with Photoshop class `c`, or the one an old PhotoCraft class stands for.
|
||||
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)];
|
||||
@@ -3356,7 +3365,7 @@ const EVENTS: &[Event] = &[
|
||||
adjustment_event!("Exps", "Exps", "exposure", "Exposure"),
|
||||
// Photoshop runs Photo Filter by name only: `PhtF` is the class, not an event (#8301).
|
||||
adjustment_event!("", "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"),
|
||||
|
||||
@@ -1805,6 +1805,42 @@ fn photo_filter_saves_under_the_name_photoshop_runs() {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 an old PhotoCraft Make with a setting both load,
|
||||
// the setting kept; near misses stay Photoshop steps.
|
||||
let make = |class: &str| {
|
||||
let kind = if class == "BlnW" { desc(class).with("Rd ", long(17.0)) } else { desc(class) };
|
||||
let using = desc("AdjL").with("Type", D::Descriptor(kind));
|
||||
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}");
|
||||
assert_eq!(t.actions.list[0].steps[1].1["reds"], 17, "{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]
|
||||
|
||||
Reference in new issue
Block a user