From 86f431d1771b7e8ac641afff0ba705adb04e96cf Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:02:19 +0100 Subject: [PATCH 1/2] fix(compose): scatter Inner Glow noise at the measured strength Fixes #14926. The shared effect-noise law (#15188, #15197) leaves 244 of the issue's 1620 band pixels without glow at Noise 50; the reference application shows 343. Inner glows now feed the law the square root of Noise, which keeps Noise 0 and Noise 100 unchanged and gives 342 px at Noise 50. Outer Glow and both shadows keep the shared law. --- crates/compose/src/effects.rs | 3 + .../src/effects/inner_glow_noise_tests.rs | 141 ++++++++++++++++++ crates/compose/src/effects/paint.rs | 6 +- 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 crates/compose/src/effects/inner_glow_noise_tests.rs diff --git a/crates/compose/src/effects.rs b/crates/compose/src/effects.rs index 4164e43cdf..43a0d4b382 100644 --- a/crates/compose/src/effects.rs +++ b/crates/compose/src/effects.rs @@ -270,5 +270,8 @@ mod satin_size_one_tests; #[cfg(test)] mod inner_glow_size_one_tests; + +#[cfg(test)] +mod inner_glow_noise_tests; #[cfg(test)] mod stroke_partial_alpha_tests; diff --git a/crates/compose/src/effects/inner_glow_noise_tests.rs b/crates/compose/src/effects/inner_glow_noise_tests.rs new file mode 100644 index 0000000000..9931915d15 --- /dev/null +++ b/crates/compose/src/effects/inner_glow_noise_tests.rs @@ -0,0 +1,141 @@ +//! #14926 - BUG-LAYER-STYLE-INNER-GLOW-NOISE-TOO-WEAK. +//! +//! Measured on the issue's test document: 400 x 300 px, RGB 8 bit, white Background, an orange +//! (255, 128, 0) pixel layer covering x 100..299, y 75..224. Inner Glow black, Normal, 100 %, +//! Softer, Source Edge, Choke 0, Size 10, Contour Linear, Range 50 %. The issue counts the G +//! channel of the flattened top band y 75..83, x 110..289 (1620 px): G 128 is the layer's own +//! orange (no glow), G 0 is full black glow. The shared `noise` law (#14936, #14952) leaves 244 +//! band pixels without glow at Noise 50, while the reference application shows 343. + +use super::*; + +const DOC_W: usize = 400; +const DOC_H: usize = 300; + +/// The layer's alpha over the whole document: solid over x 100..=299, y 75..=224. +fn document_shape() -> Map { + let mut m = Map::new(DOC_W, DOC_H, 0.0); + for y in 75..=224 { + for x in 100..=299 { + m.v[y * DOC_W + x] = 1.0; + } + } + m +} + +/// The issue's Inner Glow settings: black, Normal, 100 %, Softer, Source Edge, Choke 0, Size 10, +/// Contour Linear, Range 50 %, Jitter 0, Anti-aliased off, Noise `noise`. +fn glow(noise: f32) -> Glow { + Glow { + common: photocraft_doc::FxCommon::new(BlendMode::Normal, 1.0), + paint: FxPaint::Color(photocraft_color::Color::BLACK), + technique: GlowTechnique::Softer, + spread: 0.0, + size: 10.0, + contour: Contour::Linear, + anti_alias: false, + range: 0.5, + jitter: 0.0, + noise, + source: GlowSource::Edge, + } +} + +fn map(noise: f32) -> Map { + glow_map(&document_shape(), &glow(noise), true, (0, 0)) +} + +/// The G channel of the orange layer under a black Normal inner glow of coverage `c`. +fn g_u8(c: f32) -> u8 { + (128.0 * (1.0 - c)).round().clamp(0.0, 128.0) as u8 +} + +/// The issue's band, y 75..=83 and x 110..=289 (1620 px), as G channel values. +fn band(m: &Map) -> Vec { + let mut out = Vec::with_capacity(180 * 9); + for y in 75..=83 { + for x in 110..=289 { + out.push(g_u8(m.get(x, y))); + } + } + out +} + +/// Done when: Noise 50 on that band leaves 260..430 pixels at G 128 (no glow at all), at most +/// 30 pixels equal to the noiseless result, and reaches G 0. The shared law alone leaves 244. +#[test] +fn noise_fifty_scatters_the_glow_across_the_band() { + let plain = band(&map(0.0)); + let noisy = band(&map(0.5)); + let gone = noisy.iter().filter(|v| **v == 128).count(); + let equal = noisy.iter().zip(&plain).filter(|(a, b)| a == b).count(); + let min = noisy.iter().copied().min().unwrap_or(128); + assert!((260..=430).contains(&gone), "Noise 50: {gone} pixels without glow, want 260..430 (reference: 343)"); + assert!(equal <= 30, "Noise 50: {equal} pixels equal to the noiseless result, want at most 30 (reference: 8)"); + assert_eq!(min, 0, "Noise 50: minimum G {min}, want 0"); +} + +/// Done when: Noise 100 leaves 400..580 pixels at G 128 (reference: 490). +#[test] +fn noise_hundred_thins_the_glow_further() { + let noisy = band(&map(1.0)); + let gone = noisy.iter().filter(|v| **v == 128).count(); + assert!((400..=580).contains(&gone), "Noise 100: {gone} pixels without glow, want 400..580 (reference: 490)"); +} + +/// Done when: the interior beyond the glow's reach stays G 128 at every Noise. +#[test] +fn noise_keeps_the_interior_beyond_the_glow_clean() { + let plain = map(0.0); + for noise in [0.25f32, 0.5, 1.0] { + let noisy = map(noise); + for y in (100..=200).step_by(5) { + for x in (130..=270).step_by(7) { + assert_eq!(plain.get(x, y), 0.0, "noiseless coverage at ({x},{y}) is not empty"); + assert_eq!(noisy.get(x, y), 0.0, "noise {noise} lit up ({x},{y}): {}", noisy.get(x, y)); + assert_eq!(g_u8(noisy.get(x, y)), 128, "noise {noise} moved the interior at ({x},{y}) off 128"); + } + } + } +} + +/// Done when: the same settings give the identical image twice. +#[test] +fn the_same_noise_renders_identically_twice() { + for noise in [0.5f32, 1.0] { + let a = map(noise); + let b = map(noise); + assert_eq!(a.v, b.v, "noise {noise} is not deterministic"); + } +} + +/// Noise that is not a positive number leaves the glow exactly as Noise 0 does, and the inner +/// strength does not reach the Outer Glow, whose band was measured on the shared law (#14952). +#[test] +fn odd_noise_values_and_outer_glows_keep_the_shared_law() { + let plain = map(0.0); + for odd in [-0.5f32, f32::NAN, f32::INFINITY] { + assert_eq!(map(odd).v, plain.v, "noise {odd} changed the inner glow"); + } + let shape = document_shape(); + let outer = glow_map(&shape, &glow(0.0), false, (0, 0)); + let mut by_law = outer.clone(); + noise(&mut by_law, 0.5, 0, 0); + assert_eq!(glow_map(&shape, &glow(0.5), false, (0, 0)).v, by_law.v, "the outer glow left the shared law"); +} + +/// A hash over every coverage value of a map: the map is bit-for-bit unchanged iff this is. +fn bit_hash(m: &Map) -> u64 { + let mut h: u64 = 0xcbf2_9ce4_8422_2325; + for v in &m.v { + h = (h ^ u64::from(v.to_bits())).wrapping_mul(0x0000_0100_0000_01b3); + } + h +} + +/// Noise 0 stays bit-identical: the whole-map FNV hash `glow_map` gives for the issue's +/// document with Noise 0 on origin/main. +#[test] +fn noise_zero_maps_stay_bit_identical() { + assert_eq!(bit_hash(&map(0.0)), 0xefad_fffb_8195_d0b9, "the Noise 0 inner glow map moved"); +} diff --git a/crates/compose/src/effects/paint.rs b/crates/compose/src/effects/paint.rs index b079fea59d..726217b8cc 100644 --- a/crates/compose/src/effects/paint.rs +++ b/crates/compose/src/effects/paint.rs @@ -569,7 +569,11 @@ pub(super) fn glow_map(shape: &Map, g: &Glow, inner: bool, origin: (i32, i32)) - if inner && g.source == GlowSource::Center { m = m.map(|v| 1.0 - v); } - noise(&mut m, g.noise, origin.0, origin.1); + // #14926: an Inner Glow scatters harder at mid Noise than the shared law gives (measured + // band: Noise 50 leaves 343 of 1620 px without glow, Noise 100 490). The square root keeps + // Noise 0 and Noise 100 where they are and lifts Noise 50 to the law's 0.71 (about 340 px). + let amount = if inner && g.noise > 0.0 { g.noise.sqrt() } else { g.noise }; + noise(&mut m, amount, origin.0, origin.1); if inner { for (v, a) in m.v.iter_mut().zip(&shape.v) { *v *= a; From eef4dadc22bf41b9dec81f7c96f3751db9488da0 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 28 Nov 2026 23:35:22 +0100 Subject: [PATCH 2/2] Inner Glow noise: keep the shared law for Source Center and Precise (#14926) Only Softer with Source Edge was measured. The issue's rules keep today's behaviour for unmeasured cases, so the square root now applies to that case alone. --- .../src/effects/inner_glow_noise_tests.rs | 17 +++++++++++++++++ crates/compose/src/effects/paint.rs | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/compose/src/effects/inner_glow_noise_tests.rs b/crates/compose/src/effects/inner_glow_noise_tests.rs index 9931915d15..ab316449c1 100644 --- a/crates/compose/src/effects/inner_glow_noise_tests.rs +++ b/crates/compose/src/effects/inner_glow_noise_tests.rs @@ -139,3 +139,20 @@ fn bit_hash(m: &Map) -> u64 { fn noise_zero_maps_stay_bit_identical() { assert_eq!(bit_hash(&map(0.0)), 0xefad_fffb_8195_d0b9, "the Noise 0 inner glow map moved"); } + +/// The Centre source and the Precise technique were not measured, so they keep the shared law at every Noise: only +/// the measured Softer, Edge-sourced Inner Glow gets the stronger mid-Noise scatter. +#[test] +fn unmeasured_centre_and_precise_inner_glows_keep_the_shared_law() { + let shape = document_shape(); + let centre = |noise| Glow { source: GlowSource::Center, ..glow(noise) }; + let precise = |noise| Glow { technique: GlowTechnique::Precise, ..glow(noise) }; + let precise_centre = |noise| Glow { technique: GlowTechnique::Precise, source: GlowSource::Center, ..glow(noise) }; + for (name, make) in [("Centre", ¢re as &dyn Fn(f32) -> Glow), ("Precise", &precise), ("Precise Centre", &precise_centre)] { + for amount in [0.25f32, 0.5] { + let mut by_law = glow_map(&shape, &make(0.0), true, (0, 0)); + noise(&mut by_law, amount, 0, 0); + assert_eq!(glow_map(&shape, &make(amount), true, (0, 0)).v, by_law.v, "{name}, Noise {amount}: left the shared law"); + } + } +} diff --git a/crates/compose/src/effects/paint.rs b/crates/compose/src/effects/paint.rs index 726217b8cc..77b90c03ab 100644 --- a/crates/compose/src/effects/paint.rs +++ b/crates/compose/src/effects/paint.rs @@ -572,7 +572,9 @@ pub(super) fn glow_map(shape: &Map, g: &Glow, inner: bool, origin: (i32, i32)) - // #14926: an Inner Glow scatters harder at mid Noise than the shared law gives (measured // band: Noise 50 leaves 343 of 1620 px without glow, Noise 100 490). The square root keeps // Noise 0 and Noise 100 where they are and lifts Noise 50 to the law's 0.71 (about 340 px). - let amount = if inner && g.noise > 0.0 { g.noise.sqrt() } else { g.noise }; + // Only the measured Softer, Edge-sourced case; Centre and Precise keep the shared law. + let measured = inner && g.technique == GlowTechnique::Softer && g.source == GlowSource::Edge; + let amount = if measured && g.noise > 0.0 { g.noise.sqrt() } else { g.noise }; noise(&mut m, amount, origin.0, origin.1); if inner { for (v, a) in m.v.iter_mut().zip(&shape.v) {