mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
This commit is contained in:
commit
53aa1a4a2c
3 files changed
+56
-2
No files matched your search
@@ -66,6 +66,16 @@ fn levels_entry(chan: Option<&str>, p: &Value) -> Descriptor {
|
||||
e
|
||||
}
|
||||
|
||||
/// Whether the Levels settings in `p` (the master curve and every channel object) name both ends
|
||||
/// of each range they touch, or neither. `levels_entry` writes a whole `Inpt` or `Otpt` pair and
|
||||
/// fills the end a partial edit left out with 0 or 255, so replaying `inBlack: 31` alone would
|
||||
/// also reset a retained Input White (#8530).
|
||||
pub(super) fn levels_complete(p: &Value) -> bool {
|
||||
let pairs_whole =
|
||||
|v: &Value| [("inBlack", "inWhite"), ("outBlack", "outWhite")].iter().all(|(low, high)| jnum(v, low).is_some() == jnum(v, high).is_some());
|
||||
pairs_whole(p) && CHANNELS.iter().filter_map(|(_, k)| p.get(*k).filter(|v| v.is_object())).all(pairs_whole)
|
||||
}
|
||||
|
||||
pub(super) fn levels_to(p: &Value) -> Option<Descriptor> {
|
||||
let mut entries = vec![D::Descriptor(levels_entry(None, p))];
|
||||
for (_, k) in CHANNELS {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::adjustments::{HUE_RANGES, adjustment_by_class, adjustment_by_suffix, adjustment_steps};
|
||||
use super::adjustments::{HUE_RANGES, adjustment_by_class, adjustment_by_suffix, adjustment_steps, levels_complete};
|
||||
use super::descriptors::{
|
||||
PX, Target, ang, class, class_ref, code, color_desc, color_hex, desc, enm, get_bool, get_enum, get_list, get_num, get_obj, get_ref, get_text, jbool, jnum,
|
||||
jstr, layer_ref, layer_target, long, name_ref, pct, px, ref_class, target, target_ref, text, trimmed,
|
||||
@@ -762,7 +762,8 @@ pub(super) fn set_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
let kind = jstr(p, "kind")?;
|
||||
// `layer.setAdjustment` changes only the settings it names. Color Balance and
|
||||
// Hue/Saturation descriptors carry every setting, filling absent ones with defaults,
|
||||
// so a partial edit would replay as one that also resets the rest (#8531).
|
||||
// so a partial edit would replay as one that also resets the rest (#8531). Levels writes
|
||||
// each range whole, so one end alone resets the other (#8530).
|
||||
// Present and of the shape the writer reads: anything else it would write as 0.
|
||||
let number = |p: &Value, k: &str| p.get(k).and_then(Value::as_f64).is_some_and(f64::is_finite);
|
||||
let numbers = |p: &Value, keys: &[&str]| keys.iter().all(|k| number(p, k));
|
||||
@@ -784,6 +785,8 @@ pub(super) fn set_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
r.is_object() && numbers(r, &["hue", "saturation", "lightness"]) && bounds
|
||||
})
|
||||
}
|
||||
// Both ends of each range it names (#8530).
|
||||
"levels" => levels_complete(p),
|
||||
_ => true,
|
||||
};
|
||||
if !complete {
|
||||
|
||||
@@ -2280,6 +2280,47 @@ fn partial_color_balance_and_hue_saturation_edits_refuse_strict_export() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Levels, like Color Balance and Hue/Saturation: the descriptor writes both ends of the Input and
|
||||
/// of the Output range, filling the end an edit did not name with 0 or 255, so replaying
|
||||
/// `inBlack: 31` alone would also reset a retained Input White (#8530). Strict export refuses it;
|
||||
/// a pair given whole, or none of it, still exports and round-trips.
|
||||
#[test]
|
||||
fn partial_levels_edits_refuse_strict_export() {
|
||||
let one = |p: Value| Action { name: "Probe".into(), steps: vec![("layer.setAdjustment".into(), p)], ..Default::default() };
|
||||
for p in [
|
||||
json!({"kind": "levels", "inBlack": 31}),
|
||||
json!({"kind": "levels", "inWhite": 239}),
|
||||
json!({"kind": "levels", "outBlack": 10}),
|
||||
json!({"kind": "levels", "outWhite": 240}),
|
||||
json!({"kind": "levels", "inBlack": 31, "inWhite": 239, "outWhite": 240}),
|
||||
json!({"kind": "levels", "red": {"inBlack": 2}}),
|
||||
json!({"kind": "levels", "inBlack": 1, "inWhite": 250, "blue": {"outBlack": 3}}),
|
||||
// A value of the wrong shape is no value: the other end is then alone.
|
||||
json!({"kind": "levels", "inBlack": 31, "inWhite": "239"}),
|
||||
] {
|
||||
let err = export("Audit8", &[&one(p.clone())], &[], false).unwrap_err();
|
||||
assert!(err.contains("`layer.setAdjustment`"), "{p}: {err}");
|
||||
let (_, skipped) = export("Audit8", &[&one(p.clone())], &[], true).unwrap();
|
||||
assert_eq!(skipped, vec![Skipped { action: "Probe".into(), step: 0, id: "layer.setAdjustment".into() }], "{p}");
|
||||
}
|
||||
for p in [
|
||||
json!({"kind": "levels", "inBlack": 31, "inWhite": 239}),
|
||||
json!({"kind": "levels", "outBlack": 10, "outWhite": 240}),
|
||||
json!({"kind": "levels", "inBlack": 31, "inWhite": 239, "outBlack": 10, "outWhite": 240, "gamma": 1.2}),
|
||||
json!({"kind": "levels", "gamma": 0.8}),
|
||||
json!({"kind": "levels", "inBlack": 1, "inWhite": 250, "red": {"inBlack": 2, "inWhite": 200}}),
|
||||
] {
|
||||
let (bytes, skipped) = export("Audit8", &[&one(p.clone())], &[], false).unwrap_or_else(|e| panic!("{p}: {e}"));
|
||||
assert!(skipped.is_empty(), "{p}");
|
||||
let steps = import(&bytes).unwrap().actions[0].steps.clone();
|
||||
let (id, back) = steps.first().unwrap();
|
||||
assert_eq!(id, "layer.setAdjustment");
|
||||
for k in ["inBlack", "inWhite", "outBlack", "outWhite"] {
|
||||
assert_eq!(back.get(k), p.get(k), "{p}: {k} in {back}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Photoshop's Close has no document target: a Close of a specific document must not be
|
||||
/// exported as a plain Close, which would close the active document on playback.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user