diff --git a/crates/ec-prores/src/idct.rs b/crates/ec-prores/src/idct.rs index 4890216e..4fa38a9b 100644 --- a/crates/ec-prores/src/idct.rs +++ b/crates/ec-prores/src/idct.rs @@ -13,8 +13,6 @@ use wide::{i16x8, i32x4, i32x8}; /// Scalar implementation in raster layout, a line-for-line port of ffmpeg's. pub mod reference { - #![allow(dead_code)] - pub struct K { /// `a` (even part) coefficient rows for r2, r4, r6. pub a2: [i32; 4], @@ -119,6 +117,20 @@ pub mod reference { out } + pub fn put_dc(dst: &mut [u8], stride: usize, dc: i16) { + let k = if B12 { &K12 } else { &K10 }; + let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) }; + let t = (i32::from(dc).wrapping_add(1) >> 1) as i16; + let c0 = t.wrapping_add(8192) as i32; + let bias = (1i32 << (k.col_shift - 1)) / k.w4; + let v = ((k.w4.wrapping_mul(c0.wrapping_add(bias)) >> k.col_shift) as i16).clamp(lo, hi) as u16; + for r in 0..8 { + for c in dst[r * stride * 2..r * stride * 2 + 16].as_chunks_mut::<2>().0.iter_mut() { + *c = v.to_le_bytes(); + } + } + } + /// Run the IDCT on an already dequantised `block` and store the clipped 8x8 result at /// `dst[0]`, row pitch `stride`. With `dc_only` only `block[0]` is read (the block's other /// coefficients are zero), which is exact: the shortcut rows and columns of the full @@ -128,15 +140,7 @@ pub mod reference { let k = if B12 { &K12 } else { &K10 }; let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) }; if dc_only { - let t = (i32::from(block[0]).wrapping_add(1) >> 1) as i16; - let c0 = t.wrapping_add(8192) as i32; - let bias = (1i32 << (k.col_shift - 1)) / k.w4; - let v = ((k.w4.wrapping_mul(c0.wrapping_add(bias)) >> k.col_shift) as i16).clamp(lo, hi) as u16; - for r in 0..8 { - for c in dst[r * stride * 2..r * stride * 2 + 16].as_chunks_mut::<2>().0.iter_mut() { - *c = v.to_le_bytes(); - } - } + put_dc::(dst, stride, block[0]); return; } for r in 0..8 { @@ -153,7 +157,7 @@ pub mod reference { } } -use reference::{K10, K12}; +use reference::K10; use archmage::{SimdToken, X64V1Token}; use reference::K; @@ -369,18 +373,8 @@ fn idct_put_10(dst: &mut [u8], stride: usize, block: &[i16; 64]) { #[inline(always)] pub fn idct_put(dst: &mut [u8], stride: usize, block: &mut [i16; 64]) { let dc_only = block[1..].iter().fold(0, |a, &x| a | x) == 0; - let k = if B12 { &K12 } else { &K10 }; - let (lo, hi): (i16, i16) = if B12 { (4, 4091) } else { (4, 1019) }; if dc_only { - let t = (i32::from(block[0]).wrapping_add(1) >> 1) as i16; - let c0 = t.wrapping_add(8192) as i32; - let bias = (1i32 << (k.col_shift - 1)) / k.w4; - let v = ((k.w4.wrapping_mul(c0.wrapping_add(bias)) >> k.col_shift) as i16).clamp(lo, hi) as u16; - for r in 0..8 { - for c in dst[r * stride * 2..r * stride * 2 + 16].as_chunks_mut::<2>().0.iter_mut() { - *c = v.to_le_bytes(); - } - } + reference::put_dc::(dst, stride, block[0]); return; } if B12 {