Use file color interpretation for newly bound images

This commit is contained in:
chasse20 committed 2026-11-27 06:52:10 -05:00
1 parent d30917484c
commit fc5ad59e02
5 files changed
+24 -12

No files matched your search

+10 -6
View File
@@ -44,7 +44,7 @@ pub(crate) fn specs() -> Vec<CommandSpec> {
"Set input preview image",
[],
None,
"{identifier, resource? | path?, linear?} shows a bitmap resource (or an image file, embedded) on the graph's input node `identifier`, e.g. a mesh map baked in TextureCraft",
"{identifier, resource? | path?, linear?} shows a bitmap on the graph's input node using its file color interpretation. Set linear to true for data or false for sRGB",
has_graph,
bind
),
@@ -233,14 +233,18 @@ fn bind(s: &mut Session, p: &J) -> Result<J> {
Some((name, bytes)) => crate::file_cmds::push_resource(&mut s.pkg, &name, bytes, Some(&id)),
None => strp(p, "resource").unwrap_or_default().to_string(),
};
let linear = p.get("linear").and_then(J::as_bool).unwrap_or(false);
let g = s.graph_mut()?;
g.input_images.insert(id.clone(), res.clone());
g.input_images_linear.remove(&id);
g.input_images_from_file.remove(&id);
if linear {
g.input_images_linear.insert(id.clone());
} else {
g.input_images_linear.remove(&id);
match p.get("linear") {
None => {
g.input_images_from_file.insert(id.clone());
}
Some(J::Bool(true)) => {
g.input_images_linear.insert(id.clone());
}
_ => {}
}
Ok(json!({"identifier": id, "resource": res}))
})
+10 -4
View File
@@ -56,10 +56,16 @@ fn bitmap_nodes_read_default_colors_from_the_file_and_keep_explicit_data_reads()
assert_eq!(pixel(bitmap), expected);
assert_eq!(pixel(data), [64, 128, 192, 97]);
assert_eq!(pixel(input), expected);
crate::execute(&mut session, "graph.input.bind", &serde_json::json!({"identifier":"input", "resource":"field", "linear":true})).unwrap();
assert!(!session.graph().unwrap().input_images_from_file.contains("input"));
let rebound = session.cook().image(input, 0).unwrap().get(0, 0, false).map(|v| (v * 255.0).round() as u8);
assert_eq!(rebound, [64, 128, 192, 97]);
for (linear, levels) in [(Some(true), [64, 128, 192, 97]), (None, expected), (Some(false), [13, 55, 134, 97]), (None, expected)] {
let mut params = serde_json::json!({"identifier": "input", "resource": "field"});
if let Some(value) = linear {
params["linear"] = value.into();
}
crate::execute(&mut session, "graph.input.bind", &params).unwrap();
assert_eq!(session.graph().unwrap().input_images_from_file.contains("input"), linear.is_none());
let rebound = session.cook().image(input, 0).unwrap().get(0, 0, false).map(|v| (v * 255.0).round() as u8);
assert_eq!(rebound, levels);
}
}
}
+1 -1
View File
@@ -416,7 +416,7 @@ still coalesce until release. `material_export` uses the headless write-root cap
expose unrestricted engine file paths.
SBS image inputs store the package resource URL in the input bridge's `bitmapresourcepath`.
On import, an image bound by this field uses the resource file's color interpretation.
Both imported bindings and newly bound images use the resource file's color interpretation by default.
`graph.input.bind` accepts `linear: true` to keep the original levels of normal, height and other
data maps, or `linear: false` for sRGB color. MaterialCraft preserves its explicit preview
interpretations in graph options and reads bindings from older files that use those options.
+2
View File
@@ -65,6 +65,8 @@ Bind generated gray and color images to graph inputs and use an ordinary **Save
MaterialCraft now reads and writes this bridge parameter with the package resource path and dependency UID. To test a file-authored binding, connect an image input directly to an output at 16² U8. Use `u(x,y) = x + 16y` for gray and `(u(x,y), u(y,x), 255−u(x,y), u((x−3) mod 16,y))` for RGBA. Write PNGs with no transfer tag, an sRGB tag and gAMA values 100000, 45455 and 220000. Open the ten SBS files directly, save them normally and reopen them in both applications. The previous reader matched 5/2,560 pixels with a maximum error of 255 byte levels. The corrected reader matches 2,560/2,560 on one processor, eight and on ordinary reopen, maximum zero. At gray level 128 the three gamma-tagged files read back as 186, 128 and 221 respectively. Alpha retains its original levels. The 549 tracked SBS files contain 2,495 input bridges and zero authored `bitmapresourcepath` bindings on those bridges.
For the editor binding path, use the same 16² gray and RGBA fields, each with no transfer tag and with gAMA 100000. Bind the image through `graph.input.bind` with the color setting omitted, save and reopen. The previous default matched 262/1,024 U8 pixels in the four reopened files. The largest error was 135 byte levels in the gamma-tagged RGBA image. The editor now uses the file's color interpretation by default. Open the four saved files directly and read the output before editing any property. All **1,024/1,024 pixels** match on one and eight reference processors, maximum zero. Repeating the four bindings with each explicit color setting preserved the previous MaterialCraft output across 2,048 pixels. The regression also switches modes on the same input and checks its alpha.
Run the [145 grayscale and 76 color settings](#integer-assignments-read-by-pattern-seeds) with a separate path to the same original procedural bitmap for each connected input in each setting. Read the whole output on one reference processor, on eight and after opening an ordinary MaterialCraft save and reapplying those inputs. Every setting matches on all three routes. Each cell gives exact pixels per route. Maximum error is zero throughout.
| Root | U8 | U16 | F16 | F32 | Total |
+1 -1
View File
@@ -41,7 +41,7 @@ Writable quadrant tints now match 16,896/16,896 pixels in 44 settings across fou
Six upstream filters now match 27,648/27,648 original and 27,648/27,648 reopened pixels across four output formats, up from 24,192 on each side. Both directions of an image connection through a graph instance also match 4,608/4,608 F32 pixels on each side. [Published filter properties, fixed controls and raw errors](parity-fixes.md#published-filter-properties-upstream-of-a-quadrant-draw)
The two roots in `tile_random.sbs` match all 484,864 pixels across 221 freshly bound settings. All 32 configured files reopened directly with 106,496/106,496 pixels exact on one and eight reference processors. Keeping the pattern connected while changing the background still gives a different result in one setting per root. [Per-format counts, filter controls and exact edit sequence](parity-fixes.md#saved-image-inputs-and-automatic-filtering-in-tile-random)
The two roots in `tile_random.sbs` match all 484,864 pixels across 221 freshly bound settings. All 32 configured files reopened directly with 106,496/106,496 pixels exact on one and eight reference processors. Four editor-bound gray and color inputs also survive a file handoff with 1,024/1,024 U8 pixels exact. Keeping the pattern connected while changing the background still gives a different result in one setting per root. [Per-format counts, filter controls and exact edit sequence](parity-fixes.md#saved-image-inputs-and-automatic-filtering-in-tile-random)
The two roots in `pattern_tile_random.sbs` match all 425,216 grayscale pixels in 104 settings and all 728,832 color pixels in 179 settings. Each output format matched on one processor, eight processors and ordinary reopen. [Whole-root settings and the shared pattern property correction](parity-fixes.md#returned-vectors-in-pattern-properties)