info: adjustment layers are reported with the params their command takes (#4871)

document.inspect dumped an adjustment's internal model (enum name as
key, snake_case fields, 0..1 values), which no adjustment command takes.
It is now {"kind": "levels", "params": ...}: the kind and parameters
from adjust_params::to_params, which from_params reads back.

Fixes #4865
This commit is contained in:
Gert Pellin - GPE authored and GitHub committed 2026-10-13 12:46:03 -04:00
1 parent 207d05a0e2
commit f389d4ee64
1 file changed
+22 -1
+22 -1
View File
@@ -98,7 +98,9 @@ fn layer_sel(l: &Layer, selected: &[photocraft_doc::LayerId]) -> Value {
}
}
LayerContent::Adjustment(a) => {
v["adjustment"] = serde_json::to_value(a).unwrap_or(Value::Null);
// The same kind and parameters the adjustment commands take (`inBlack` 0..255, …),
// not the internal model.
v["adjustment"] = json!({"kind": crate::commands::adjustment_kind(a), "params": crate::adjust_params::to_params(a)});
}
LayerContent::Smart(sm) => {
v["smartFilters"] = Value::Array(
@@ -165,6 +167,25 @@ mod tests {
use photocraft_color::PixelFormat;
use photocraft_doc::{LayerMask, Path, VectorMask};
#[test]
fn an_adjustment_layer_is_reported_with_the_params_its_command_takes() {
let mut s = Session::new();
s.execute("file.new", json!({"width": 4, "height": 4})).unwrap();
s.execute("layer.newAdjustmentLayer.levels", json!({"inBlack": 10, "inWhite": 240, "gamma": 1.2})).unwrap();
let info = s.execute("document.inspect", json!({})).unwrap();
let adj = &info["layers"][0]["adjustment"];
assert_eq!(adj["kind"], "levels");
assert_eq!((adj["params"]["inBlack"].as_f64(), adj["params"]["inWhite"].as_f64()), (Some(10.0), Some(240.0)), "{adj}");
// Fed back to the command, the params give the same adjustment; no internal field names.
let model = match &s.active().unwrap().doc.layers[1].content {
LayerContent::Adjustment(a) => a.clone(),
c => panic!("{c:?}"),
};
let back = crate::adjust_params::from_params("levels", &adj["params"], None, photocraft_color::ColorMode::Rgb).unwrap();
assert_eq!(crate::adjust_params::to_params(&back), crate::adjust_params::to_params(&model));
assert!(!adj.to_string().contains('_'), "{adj}");
}
#[test]
fn document_inspect_reports_raster_and_vector_masks_when_nested() {
let cases = [(false, None), (true, None), (false, Some(true)), (false, Some(false)), (true, Some(true))];