mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Actions: keep an Oil Paint step whose setting has a unit or another number type (CodeRabbit review on steps_image.rs:548)
Import read Oil Paint's settings with `num`, which takes any number and drops a unit, so a recorded `#Prc` stylization or an integer bristle detail loaded and saved back as a plain double, and a fractional light direction loaded and then couldn't be saved. Import now takes the types Photoshop records and the step writes back (doubles, and an integer `LghD`), and keeps anything else as a Photoshop step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1eb8f7d4da
commit
527dfaa591
2 files changed
+41
-4
No files matched your search
@@ -513,6 +513,23 @@ pub(super) fn select_sky_to(_: &str, p: &Value) -> Option<Descriptor> {
|
||||
Some(desc("null").with("sampleAllLayers", D::Boolean(all)))
|
||||
}
|
||||
|
||||
/// A plain double, as Photoshop records Oil Paint's settings and the step saves them back: a
|
||||
/// value with a unit, or an integer, would save back as another value.
|
||||
fn double(v: &D) -> Option<f64> {
|
||||
match v {
|
||||
D::Double(n) if n.is_finite() => Some(*n),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// An integer, as Photoshop records Oil Paint's light direction and the step saves it back.
|
||||
fn integer(v: &D) -> Option<i32> {
|
||||
match v {
|
||||
D::Integer(n) => Some(*n),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Oil Paint's keys in recorded order: (key, param, Photoshop's default, the command's default).
|
||||
const OIL_PAINT: &[(&str, &str, f64, f64)] = &[
|
||||
("stylization", "stylization", 4.0, 4.0),
|
||||
@@ -522,7 +539,8 @@ const OIL_PAINT: &[(&str, &str, f64, f64)] = &[
|
||||
];
|
||||
|
||||
/// Oil Paint (`oilPaint`). Missing keys take Photoshop's defaults, which differ from the
|
||||
/// command's for cleanliness, scale, bristle detail and shine, so they are written out.
|
||||
/// command's for cleanliness, scale, bristle detail and shine, so they are written out. A
|
||||
/// setting of another number type, or with a unit, keeps the Photoshop step.
|
||||
pub(super) fn oil_paint_from(d: &Descriptor) -> Mapped {
|
||||
match oil_paint_params(d) {
|
||||
Some(p) => step("filter.stylize.oilPaint", Value::Object(p)),
|
||||
@@ -538,10 +556,10 @@ fn oil_paint_params(d: &Descriptor) -> Option<Map<String, Value>> {
|
||||
let mut p = Map::new();
|
||||
p.insert("lighting".into(), setting(d, "lightingOn", boolean, true)?.into());
|
||||
for (key, param, ps, _) in OIL_PAINT {
|
||||
p.insert((*param).into(), setting(d, key, num, *ps)?.into());
|
||||
p.insert((*param).into(), setting(d, key, double, *ps)?.into());
|
||||
}
|
||||
p.insert("angle".into(), setting(d, "LghD", num, -60.0)?.into());
|
||||
p.insert("shine".into(), setting(d, "specularity", num, 1.299_999_952_316_28)?.into());
|
||||
p.insert("angle".into(), setting(d, "LghD", |v| integer(v).map(f64::from), -60.0)?.into());
|
||||
p.insert("shine".into(), setting(d, "specularity", double, 1.299_999_952_316_28)?.into());
|
||||
Some(p)
|
||||
}
|
||||
|
||||
|
||||
@@ -3332,3 +3332,22 @@ fn smart_sharpen_reads_an_unpadded_radius() {
|
||||
let d = desc("null").with("Amnt", pct(150.0)).with("Rds", px(2.5));
|
||||
assert_eq!(mapped(newer("smartSharpen", d)), ("filter.sharpen.smartSharpen".into(), json!({"amount": 150.0, "radius": 2.5, "reduceNoise": 0})));
|
||||
}
|
||||
|
||||
/// Oil Paint records its settings as plain doubles and the light direction as an integer, and
|
||||
/// saves them back so: a value with a unit, or of the other number type, would load as a bare
|
||||
/// number and save back changed, so the step stays a Photoshop step (#10610).
|
||||
#[test]
|
||||
fn oil_paint_setting_with_a_unit_or_another_number_type_is_kept() {
|
||||
kept_when_wrong_typed(
|
||||
"oilPaint",
|
||||
&[
|
||||
("stylization", pct(4.0)),
|
||||
("cleanliness", px(2.0)),
|
||||
("brushScale", D::UnitFloat { unit: *b"#Rlt", value: 0.8 }),
|
||||
("microBrush", D::Integer(10)),
|
||||
("LghD", ang(-60.0)),
|
||||
("LghD", D::Double(-60.5)),
|
||||
("specularity", D::UnitFloat { unit: *b"#Prc", value: 1.3 }),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user