Compose: tone and hue-range lookups truncate instead of calling floor

Baseline x86-64 has no SSE4.1 roundss, so f32::floor is an out-of-line libm call there. lut, which every Levels, Curves, Hue/Saturation range and modern Brightness/Contrast sample goes through, floored its non-negative table position. Truncating is the same there (NaN casts to 0 either way) and inlines. Bit-identical.
This commit is contained in:
xsvm committed 2026-10-21 11:46:27 +08:00
1 parent b097800e78
commit d278a85696
1 file changed
+3 -1
+3 -1
View File
@@ -898,7 +898,9 @@ fn map_rgb(buf: &mut Buffer, f: impl Fn([f32; 3]) -> [f32; 3]) {
#[inline]
fn lut(table: &[f32], v: f32) -> f32 {
let x = v.clamp(0.0, 1.0) * (table.len() - 1) as f32;
let i = x.floor() as usize;
// Never negative (NaN casts to 0, as its floor did), so truncating is `floor`, without the
// libm call baseline x86-64 (no SSE4.1) makes for it.
let i = x as usize;
let j = (i + 1).min(table.len() - 1);
let f = x - i as f32;
table[i] * (1.0 - f) + table[j] * f