mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Actions: keep a Distort step whose enumeration has another type (CodeRabbit review on steps_distort.rs:71)
Import read an enumeration's value and ignored its type, so `Cnvr` recorded as `Ordn`/`RctP` loaded as Polar Coordinates and saved back as `Cnvr`/`RctP`. Each enumeration (and Wave's `UndA`) now loads only with the type Photoshop records and the step saves back; another type keeps the Photoshop step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13f6e07678
commit
427c59d32a
2 files changed
+31
-4
No files matched your search
@@ -1,7 +1,7 @@
|
||||
//! Photoshop's Distort filter steps (#10605): Pinch, Polar Coordinates, Spherize, Twirl, Wave and
|
||||
//! ZigZag, each key in recorded order with the limits and defaults Photoshop measures.
|
||||
|
||||
use super::descriptors::{desc, enm, enumerated, num, trimmed};
|
||||
use super::descriptors::{desc, enm, num, trimmed};
|
||||
use super::events::pixel_target;
|
||||
use super::fields::{Mapped, step};
|
||||
use super::tables::{lookup, lookup_back};
|
||||
@@ -30,13 +30,22 @@ fn sets_only(p: &Value, allowed: &[&str]) -> bool {
|
||||
p.as_object().is_none_or(|m| m.iter().all(|(k, v)| v.is_null() || allowed.contains(&k.as_str())))
|
||||
}
|
||||
|
||||
/// An enumeration's value when its type is `ty`, the type Photoshop records it with and the
|
||||
/// step saves back: one of another type isn't that setting.
|
||||
fn enum_of(ty: &str) -> impl Fn(&D) -> Option<String> + '_ {
|
||||
move |v| match v {
|
||||
D::Enumerated { type_id, value } if trimmed(type_id) == ty.trim_end() => Some(trimmed(value)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// One key of a Distort filter's step, in recorded order.
|
||||
pub(super) enum Key {
|
||||
/// An integer clamped to `min..=max` on import, as Photoshop clamps it; `default` when the
|
||||
/// step leaves it out.
|
||||
Int { key: &'static str, param: &'static str, min: i32, max: i32, default: i32 },
|
||||
/// An enumeration (`ty`, Photoshop ↔ PhotoCraft values); `default` is Photoshop's value when
|
||||
/// the step leaves it out. An unknown value keeps the step.
|
||||
/// the step leaves it out. An unknown value, or one of another type, keeps the step.
|
||||
Enum { key: &'static str, param: &'static str, ty: &'static str, table: &'static [(&'static str, &'static str)], default: &'static str },
|
||||
}
|
||||
|
||||
@@ -71,7 +80,7 @@ fn keys_map(d: &Descriptor, keys: &[Key], extra: &[&'static str]) -> Option<Map<
|
||||
Key::Int { key, min, max, default, .. } => {
|
||||
Value::from(setting(d, key, |v| num(v).map(|n| n.round().clamp(f64::from(*min), f64::from(*max)) as i32), *default)?)
|
||||
}
|
||||
Key::Enum { key, table, default, .. } => Value::from(lookup(table, &setting(d, key, enumerated, (*default).to_string())?)?),
|
||||
Key::Enum { key, ty, table, default, .. } => Value::from(lookup(table, &setting(d, key, enum_of(ty), (*default).to_string())?)?),
|
||||
};
|
||||
m.insert(k.param().into(), v);
|
||||
}
|
||||
@@ -152,7 +161,7 @@ pub(super) fn wave_from(d: &Descriptor) -> Mapped {
|
||||
if ["SclH", "SclV"].iter().any(|k| setting(d, k, num, 100.0).is_none_or(|n| n.round().clamp(1.0, 100.0) != 100.0)) {
|
||||
return unsupported;
|
||||
}
|
||||
let Some(undefined) = setting(d, "UndA", enumerated, "RptE".into()).and_then(|e| lookup(WAVE_UNDEFINED, &e)) else { return unsupported };
|
||||
let Some(undefined) = setting(d, "UndA", enum_of("UndA"), "RptE".into()).and_then(|e| lookup(WAVE_UNDEFINED, &e)) else { return unsupported };
|
||||
m.insert("undefinedAreas".into(), undefined.into());
|
||||
match setting(d, "RndS", |v| seed_bits(v).map(Some), None) {
|
||||
Some(Some(seed)) => {
|
||||
|
||||
@@ -3374,3 +3374,21 @@ fn distort_filter_steps_with_a_repeated_key_are_kept() {
|
||||
assert!(kept(distort(code, desc("null").with(key, a.clone()).with(key, b.clone()))), "{code} with {key} twice was mapped");
|
||||
}
|
||||
}
|
||||
|
||||
/// An enumeration of another type isn't the setting Photoshop records, so the step stays a
|
||||
/// Photoshop step instead of loading its value and saving back the expected type (#10605).
|
||||
#[test]
|
||||
fn distort_filter_steps_with_an_enumeration_of_another_type_are_kept() {
|
||||
let kept = |m: Mapped| matches!(m, Mapped::Unsupported { harmless: false });
|
||||
for (code, key, v) in [
|
||||
("Plr ", "Cnvr", enm("Ordn", "RctP")),
|
||||
("Sphr", "SphM", enm("Cnvr", "Nrml")),
|
||||
("ZgZg", "ZZTy", enm("Ordn", "PndR")),
|
||||
("Wave", "Wvtp", enm("WvSn", "WvSn")),
|
||||
("Wave", "UndA", enm("Ordn", "WrpA")),
|
||||
] {
|
||||
assert!(kept(distort(code, desc("null").with(key, v.clone()))), "{code} with {key} = {v:?} was mapped");
|
||||
}
|
||||
assert!(!kept(distort("Plr ", desc("null").with("Cnvr", enm("Cnvr", "PlrR")))));
|
||||
assert!(!kept(distort("Wave", desc("null").with("UndA", enm("UndA", "WrpA")))));
|
||||
}
|
||||
Reference in new issue
Block a user