Merge #16661 into the merge queue batch

Outer Glow: one Range/Size rule for Softer Edge glows (#15871)
This commit is contained in:
David Mann committed 2026-11-25 13:28:26 +01:00
commit b30a4b0bae
5 files changed
+90 -39

No files matched your search

+9
View File
@@ -109,6 +109,15 @@ pub fn tent_kernel(w: f32) -> (i32, Vec<f32>) {
((n as i32 - 1) / 2, t)
}
/// The end tap of the box of width `w` that [`tent_kernel`] squares, and the tap next to it
/// (`None` for a single-tap box): the tent's last tap is `end²`, without building the tent.
pub(super) fn box_end_taps(w: f32) -> Option<(f32, f32)> {
match box_weights(w).as_slice() {
[.., next, end] => Some((*end, *next)),
_ => None,
}
}
/// Box geometry for a (fractional) width: (`r`, end-tap weight `f`, 1 / width) — the
/// [`box_weights`] taps are `r - 1` full ones each side of the centre plus the two end taps at `f`.
fn box_geom(bw: f32) -> (i64, f64, f64) {
@@ -124,8 +124,9 @@ fn bit_hash(m: &Map) -> u64 {
}
/// Noise 0 stays bit-identical: this is the whole-map FNV hash `glow_map` gives for the
/// issue's document with Noise 0 on upstream/main, so the new law must not touch it.
/// issue's document with Noise 0 on upstream/main, so the new law must not touch it. Re-pinned
/// for #15871, whose Range rule moves this Range 50 % map towards the measured #14958 profile.
#[test]
fn noise_zero_maps_stay_bit_identical() {
assert_eq!(bit_hash(&map(0.0)), 0x340b_6ce5_05c9_a71d, "the Noise 0 outer glow map moved");
assert_eq!(bit_hash(&map(0.0)), 0x49c1_01e2_0b3d_c395, "the Noise 0 outer glow map moved");
}
@@ -5,11 +5,12 @@
//! Spread 0, Size 10, Contour Linear, Anti-aliased off, Noise 0. Profiles list the R channel of
//! the flattened image from the layer edge outwards (255 = no glow, 0 = full black glow); the
//! reference application gives `0 x8, 39, 255` at Range 1 % on all four edges (within 3 levels).
//! Range 25/50/100 keep today's profiles (the measured values, within 4 levels). The cases the
//! issue marks *not measured* (Range 2, other Sizes at Range 1, Precise at Range 1, Range 1 with
//! Spread, a custom contour at Range 1, the Inner Glow Center source at Range 1) pin today's
//! output. The last inner test mirrors #14929's measured Inner Glow Range-1 profile `0 x8, 19,
//! 128` through the shared table as a cross-check; it does not claim that issue's item.
//! Range 25/50/100 keep today's profiles (the measured values, within 4 levels). #15871 measured
//! Range 2 and Sizes 20 and 5 at Range 1 on the same document (within 3 levels). The cases still
//! *not measured* (Precise at Range 1, Range 1 with Spread, a custom contour at Range 1, the
//! Inner Glow Center source at Range 1) pin today's output. The inner test mirrors #14929's
//! measured Inner Glow Range-1 profile `0 x8, 19, 128` as a cross-check; it does not claim that
//! issue's item.
use super::{Contour, Effect, FxPaint, Glow, GlowSource, GlowTechnique, Rect};
use photocraft_color::{BlendMode, Color, ColorMode, PixelFormat, SampleType};
@@ -147,19 +148,26 @@ fn outer_glow_range_one_with_spread_keeps_todays_profile() {
assert_all_edges(&measured_doc(g, false), 0, false, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 255, 255], 1, "spread 20 % at Range 1 %");
}
/// Not measured, keeps today's behaviour: another Size at Range 1 % (Size 20: solid through 17
/// px, then 48, 175, 239, then no glow).
/// #15871 Done when 1: Size 20 at Range 1 % gives seventeen solid pixels, then 93, 201, then no
/// glow, within 3 levels. Before, the glow reached one pixel further: 48, 175, 239.
#[test]
fn outer_glow_range_one_other_sizes_keep_todays_profile() {
fn outer_glow_range_one_at_size_20_gives_the_measured_profile() {
let g = Glow { size: 20.0, ..glow(0.01) };
assert_all_edges(&measured_doc(g, false), 0, false, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 175, 239, 255], 1, "size 20 at Range 1 %");
assert_all_edges(&measured_doc(g, false), 0, false, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93, 201, 255, 255], 3, "size 20 at Range 1 %");
}
/// Not measured, keeps today's behaviour: a whole-number Range next to 1 (2 %: solid through 8
/// px, then 96, 223, then no glow).
/// #15871 Done when 1: Size 5 at Range 1 % gives four solid pixels, then no glow.
#[test]
fn outer_glow_range_two_keeps_todays_profile() {
assert_all_edges(&measured_doc(glow(0.02), false), 0, false, &[0, 0, 0, 0, 0, 0, 0, 0, 96, 223, 255, 255], 1, "Range 2 %");
fn outer_glow_range_one_at_size_5_gives_the_measured_profile() {
let g = Glow { size: 5.0, ..glow(0.01) };
assert_all_edges(&measured_doc(g, false), 0, false, &[0, 0, 0, 0, 255, 255], 3, "size 5 at Range 1 %");
}
/// #15871 Done when 1: Range 2 % at Size 10 gives eight solid pixels, then 125, then no glow,
/// within 3 levels. Before, it gave 96, 223.
#[test]
fn outer_glow_range_two_gives_the_measured_profile() {
assert_all_edges(&measured_doc(glow(0.02), false), 0, false, &[0, 0, 0, 0, 0, 0, 0, 0, 125, 255, 255, 255], 3, "Range 2 %");
}
/// Not measured, keeps today's behaviour: a custom (flat) contour at Range 1 % keeps the
+51 -19
View File
@@ -34,24 +34,24 @@ pub(super) fn lut_at(l: &[f32], v: f32) -> f32 {
/// coverage `v` through `contour(min(v / range, 1))`, so the default 50 % doubles a blurred
/// edge's 0.5 to full strength). `None` = identity.
///
/// One measured exception (#14958, and #14929 through this same table): at the Range-1 % test
/// document (Softer, Size 10, Spread 0, Linear contour, Edge source) the reference application
/// hardens the glow instead of amplifying the blur's tail to one pixel further: the coverage at
/// the tent's last tap (its reach's outermost pixel, 0.0025 at Size 10) paints nothing, and the
/// coverage one pixel inside it (0.0125) paints 0.85 - measured as 39 of 255 outside the layer
/// and 19 of 128 inside. A linear ramp from that last tap to `range` plus 3/4 of it reproduces
/// all four measured pixels within 1 level (outer 40, inner 20, both reaches exact); today's
/// `min(v / range, 1)` there paints solid one pixel wider and leaves 191 (outer) / 96 (inner)
/// at the pixel the reference stops at. Every other configuration - all other Ranges, Sizes
/// and Spreads, Precise, the Center source, and custom contours - keeps `ranged_lut` exactly.
pub fn glow_lut(g: &Glow) -> Option<Vec<f32>> {
if matches!(g.contour, Contour::Linear)
&& matches!(g.technique, GlowTechnique::Softer)
&& g.source == GlowSource::Edge
&& g.spread == 0.0
&& g.size == 10.0
&& (g.range - 0.01).abs() < 1e-6
{
/// An outer Softer glow from the Edge with Spread 0 and the Linear contour follows
/// [`softer_edge_lut`] instead, at every Size and Range (#14958, #15871). Precise, Spread, the
/// Center source and custom contours keep `ranged_lut` exactly.
///
/// Inner glows (`inner`) keep one measured exception (#14929, the mirror image of #14958's first
/// measurement): at the Range-1 % test document (Softer, Size 10, Spread 0, Linear contour, Edge
/// source) the coverage at the tent's last tap (its reach's outermost pixel, 0.0025 at Size 10)
/// paints nothing, and the coverage one pixel inside it (0.0125) paints 0.85, measured as 19 of
/// 128. A linear ramp from that last tap to `range` plus 3/4 of it gives 20; `min(v / range, 1)`
/// there paints solid one pixel wider and leaves 96 at the pixel the reference stops at. Every
/// other inner glow keeps `ranged_lut`: their other Sizes and Ranges are measured against it
/// (`inner_glow_size_one_tests`).
pub fn glow_lut(g: &Glow, inner: bool) -> Option<Vec<f32>> {
let softer_edge = matches!(g.contour, Contour::Linear) && matches!(g.technique, GlowTechnique::Softer) && g.source == GlowSource::Edge && g.spread == 0.0;
if softer_edge && !inner {
return Some(softer_edge_lut(g.size, g.range));
}
if softer_edge && g.size == 10.0 && (g.range - 0.01).abs() < 1e-6 {
// `tent_kernel` stores its weights from -r to r and never an empty list, so its last
// entry is the tap at the reach's end (for Size 10: 1/400): the straight edge's
// coverage at the reach's outermost pixel. `end` 0 (unreachable) leaves today's ramp.
@@ -62,6 +62,38 @@ pub fn glow_lut(g: &Glow) -> Option<Vec<f32>> {
ranged_lut(&g.contour, g.range)
}
/// The Linear transfer of an outer Softer Edge glow with Spread 0:
/// `(v - floor) / (levels · (1 - floor))`, clamped to 0..=1. `levels` is the Range rounded to a
/// whole 8-bit level, and `floor` is [`softer_edge_floor`]: the coverage a straight edge gives
/// the reach's outermost pixel at an even Size, which paints nothing. The `1 - floor` keeps full
/// coverage at full strength.
///
/// Measured on the #14958 document (black, Normal 100 %), with the flattened R channel from the
/// layer edge outwards. Size 10 at Range 1 % (3 levels) gives `0 x8, 39`; at Range 2 % (5 levels)
/// `0 x8, 125`; Size 20 at Range 1 % gives `0 x17, 93, 201`; Size 5 at Range 1 % gives `0 x4`. Each
/// is followed by no glow. Size 10 at Range 25, 50 and 100 % keeps the measured profiles. This
/// rule gives every one of those pixels within 1 level. The plain `min(v / range, 1)` reaches one
/// pixel further at small Ranges (`0 x8, 96, 223` at Range 2 %) and leaves 252 for 255 at the
/// end of the Range 100 % profile.
fn softer_edge_lut(size: f32, range: f32) -> Vec<f32> {
let range = if range.is_finite() { range.clamp(0.01, 1.0) } else { 1.0 };
let levels = (range * 255.0).round() / 255.0;
let floor = softer_edge_floor(size);
let full = levels * (1.0 - floor);
(0..GLOW_LUT_LEN).map(|k| ((k as f32 / (GLOW_LUT_LEN - 1) as f32 - floor) / full).clamp(0.0, 1.0)).collect()
}
/// The tent's outermost tap (the box's end tap squared) when the box `blur` runs for `size` ends
/// in partial taps, else 0. Even Sizes end in half taps (1/400 at Size 10, 1/1600 at Size 20).
/// Odd Sizes end in whole taps (Size 5's outermost pixel paints in full at Range 1 %), and a
/// Size of one pixel or less has no falloff.
fn softer_edge_floor(size: f32) -> f32 {
match super::blur::box_end_taps(size) {
Some((end, next)) if end < 0.999 * next => end * end,
_ => 0.0,
}
}
/// The coverage transfer a glow paints through (CPU `glow_map` and the GPU's `MFinish` stage
/// alike): [`glow_lut`], and for an outer glow with a custom contour, capped by the glow's
/// anti-aliased reach (#11361).
@@ -99,7 +131,7 @@ pub fn glow_lut(g: &Glow) -> Option<Vec<f32>> {
/// Inner glows keep `glow_lut` (`inner`): their unreached pixels are the shape's interior, where
/// Photoshop's behaviour with a high contour is unmeasured. `None` = identity.
pub fn glow_paint_lut(g: &Glow, inner: bool) -> Option<Vec<f32>> {
let lut = glow_lut(g);
let lut = glow_lut(g, inner);
if inner || matches!(g.contour, Contour::Linear) {
return lut;
}
+6 -5
View File
@@ -855,6 +855,7 @@ fn bevel_contour_and_texture_shape_the_height() {
assert!(mid > flat + 0.5, "{mid} vs {flat}");
}
/// Through an inner glow's table: an outer Softer Edge glow takes `softer_edge_lut` (#15871).
#[test]
fn glow_range_stretches_the_contour() {
let mut g = Glow {
@@ -870,10 +871,10 @@ fn glow_range_stretches_the_contour() {
noise: 0.0,
source: GlowSource::Edge,
};
let l = glow_lut(&g).unwrap();
let l = glow_lut(&g, true).unwrap();
assert!((lut_at(&l, 0.25) - 0.5).abs() < 1e-3 && (lut_at(&l, 0.75) - 1.0).abs() < 1e-6);
g.range = 1.0;
assert!(glow_lut(&g).is_none());
assert!(glow_lut(&g, true).is_none());
}
/// Photoshop 27.11, measured on a 128 px square (Normal, black, 100 %, Range 50 %): a precise
@@ -1109,14 +1110,14 @@ fn glow_paint_lut_leaves_linear_and_inner_glows_alone() {
for size in [1.0f32, 4.0, 10.0, 60.0] {
for range in [0.5f32, 1.0] {
let linear = Glow { contour: Contour::Linear, range, ..contour_glow(t, size, &FLAT) };
assert_eq!(glow_paint_lut(&linear, false), glow_lut(&linear), "{t:?} {size} {range}");
assert_eq!(glow_paint_lut(&linear, false), glow_lut(&linear, false), "{t:?} {size} {range}");
let straight = Glow { range, ..contour_glow(t, size, &[(0.0, 0.0), (1.0, 1.0)]) };
let (Some(a), Some(b)) = (glow_paint_lut(&straight, false), glow_lut(&straight)) else { panic!("custom contours have a table") };
let (Some(a), Some(b)) = (glow_paint_lut(&straight, false), glow_lut(&straight, false)) else { panic!("custom contours have a table") };
assert_eq!(a.len(), 4096);
let worst = a.iter().zip(&b).map(|(x, y)| (x - y).abs()).fold(0.0f32, f32::max);
assert!(worst < 1e-5, "{t:?} size {size} range {range}: a straight contour moved by {worst}");
let flat = Glow { range, ..contour_glow(t, size, &FLAT) };
assert_eq!(glow_paint_lut(&flat, true), glow_lut(&flat), "inner glows keep their transfer");
assert_eq!(glow_paint_lut(&flat, true), glow_lut(&flat, true), "inner glows keep their transfer");
let Some(f) = glow_paint_lut(&flat, false) else { panic!("a flat contour has a table") };
assert_eq!(f[0], 0.0, "coverage 0 paints nothing");
assert!((f[4095] - 1.0).abs() < 1e-6);