From 3403a4de4d1b8914eb8a4dff5d8a76c1b7e78f7b Mon Sep 17 00:00:00 2001 From: chasse20 Date: Sat, 21 Nov 2026 05:49:20 -0500 Subject: [PATCH] Preserve finite HDR channels in pattern backgrounds --- crates/nodes/src/parameter.rs | 4 +++- crates/nodes/tests/atomic_filter_parity.rs | 19 ++++++++++++++++++- docs/parity-fixes.md | 19 +++++++++++++++++++ docs/sbs-root-nodes.md | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/crates/nodes/src/parameter.rs b/crates/nodes/src/parameter.rs index 2933d1d7..0e993ea2 100644 --- a/crates/nodes/src/parameter.rs +++ b/crates/nodes/src/parameter.rs @@ -42,8 +42,10 @@ pub fn clamp_params(definition: &NodeDefinition, params: &mut BTreeMap], values: &[(&str, Value)], siz (definition.cook)(&context).unwrap().remove(0) } +#[test] +fn empty_pattern_uses_the_finite_background_before_grayscale_conversion() { + let mut pattern = PatternGraph::with_root(PatternNodeKind::Quadrant); + pattern.nodes[0].parameters.insert("patterntype".into(), Value::Int(0)); + let render = |background, color| { + let values = + [("background", Value::Color(background)), ("color_mode", Value::Bool(color)), ("pattern", Value::PatternGraph(Box::new(pattern.clone())))]; + cook("fx_map", &[], &values, [8, 8], true) + }; + + let background = [-64.0, 192.0, -32.0, 40.0]; + assert_eq!(render(background, true).get(0, 0, false), background); + assert_eq!(render(background, false).get_gray(0, 0, false), 32.0); + let large = f32::from_bits(0x7f00_0000); + assert_eq!(render([large, large, large, 1.0], false).get_gray(0, 0, false), f32::INFINITY); +} + #[test] fn min_blend_accumulates_the_background_weight_on_the_foreground_product() { let foreground = Image::gray(1, 1, |_, _| 46.0 / 255.0); diff --git a/docs/parity-fixes.md b/docs/parity-fixes.md index b8d59f23..ce973e70 100644 --- a/docs/parity-fixes.md +++ b/docs/parity-fixes.md @@ -564,6 +564,25 @@ For file gamma g and channel maximum M, the observed transfer rounds 1/(2.2g) to Bitmap file-default and explicit data reads matched all 570,112 pixels across 329 renders. Reopening 24 saved packages matched another 203,520/203,520 pixels and reproduced each original buffer in both applications. One of the original packages was saved by the reference editor before the five direct renders. These measurements cover the generated files and the listed metadata. Other ICC profiles, palette transparency and file-default DDS remain unmeasured. All 790 release tests across the engine, evaluator, format and node crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. +### Finite HDR backgrounds in empty pattern graphs + +The literal background of an FX-Map supplies image samples. The previous parameter clamp limited all four channels to −16 through 17, before the renderer could store color or take the grayscale mean. With an empty quadrant and background (−64,192,−32,40), both apps now return those four F32 values in color mode and 32 in grayscale. Non-finite parameter components retain the usual parameter fallback. + +Set the quadrant pattern type to zero, omit the background image, and use a 16² output. Test the following backgrounds in both color modes, numbered from zero. For rows with one RGB level, repeat it on all three channels. The rows are (−128,−128,−128,1), (128,128,128,128), (−64,192,−32,40), (32768,−16384,8192,−4096), (−2²⁸,−2²⁸,−2²⁸,1), (2⁸⁰,2⁸⁰,2⁸⁰,1), (2¹²⁶,2¹²⁶,2¹²⁶,1), (2¹²⁷,2¹²⁷,2¹²⁷,1), (−2¹²⁷,2¹²⁷,−2¹²⁷,2¹²⁰) and (17,−16,16.5,−15.5). Use seed 570829 + 13 × row + color switch. Render each at U8, U16 and F32 and include F16 where every channel fits its finite range. For the all-positive 2¹²⁷ row, both applications store F32 word `7f800000` after the grayscale sum overflows, and 255 and 65535 in the two normalized formats. + +| Stored output | Original renders | Exact / total | Reopened renders | Exact / total | Maximum error | +|---|---:|---:|---:|---:|---:| +| LUM16 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| LUM16F | 5 | 1,280/1,280 | 5 | 1,280/1,280 | 0 | +| LUM32F | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| LUM8 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| RGBA16 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| RGBA16F | 5 | 1,280/1,280 | 5 | 1,280/1,280 | 0 | +| RGBA32F | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | +| RGBA8 | 10 | 2,560/2,560 | 10 | 2,560/2,560 | 0 | + +Across the 67 entirely finite earlier renders, 10,240/17,152 pixels had matched with a maximum F32 error of 1.70141183e+38. All 70 renders now match **17,920/17,920** pixels, including the infinity word. All 20 saved packages match **17,920/17,920** on reopening and regenerate the originals in both applications. The [wide grayscale bitmap stamp](#stored-coverage-before-grayscale-bitmap-stamp-opacity) improved from 1,536/1,792 to **1,792/1,792** across its seven settings, also exact on reopening. Its maximum is zero. The empty-background regression failed at the old parameter clamp. All 666 release tests in the node, evaluator and engine crates passed, along with formatting, strict workspace Clippy, dependency layers and WebAssembly. The [signed-zero empty-background comparisons](#stored-coverage-before-grayscale-bitmap-stamp-opacity) remain separate. + ## 2026-11-20 root comparisons ### Hue, saturation, lightness and Replace Color diff --git a/docs/sbs-root-nodes.md b/docs/sbs-root-nodes.md index 1ce491d7..47186933 100644 --- a/docs/sbs-root-nodes.md +++ b/docs/sbs-root-nodes.md @@ -49,6 +49,8 @@ Odd-sized grayscale bitmap resources match 116,736/116,736 pixels directly and 9 Linear RGBA bitmap resources match 108,544/108,544 pixels on two procedural fields. [Exact counts by format and saved-package results](parity-fixes.md#stored-levels-of-linear-color-bitmap-resources) +Wide literal pattern backgrounds matched 17,920/17,920 pixels directly and again after saving. The seven wide bitmap stamp renders now match 1,792/1,792 pixels. [Measurements and saved packages](parity-fixes.md#finite-hdr-backgrounds-in-empty-pattern-graphs) + Bitmap file-default and explicit data reads matched all 570,112 pixels across 329 renders. Reopening 24 saved packages matched another 203,520/203,520 pixels and reproduced each original buffer in both applications. [Measurements and saved packages](parity-fixes.md#bitmap-file-transfer-and-stored-channel-precision) Grayscale bitmap stamps matched every stored F32 word across the 120 composites, 312 individual-stamp renders and 60 reopened renders. The wider background controls have separate measured differences. [Measurements and saved packages](parity-fixes.md#stored-coverage-before-grayscale-bitmap-stamp-opacity)