Skip to content

Commit

Permalink
Make apply_ssim_boost a const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezyLemon authored and shssoichiro committed Feb 20, 2024
1 parent 1412bed commit 0504761
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ struct RsqrtOutput {
}

/// Fixed point `rsqrt` for `ssim_boost`
fn ssim_boost_rsqrt(x: u64) -> RsqrtOutput {
const fn ssim_boost_rsqrt(x: u64) -> RsqrtOutput {
const INSHIFT: u8 = 16;
const OUTSHIFT: u8 = 14;

let k = ((ILog::ilog(x) - 1) >> 1) as i16;
let k = (x.ilog2() >> 1) as i16;
/*t is x in the range [0.25, 1) in QINSHIFT, or x*2^(-s).
Shift by log2(x) - log2(0.25*(1 << INSHIFT)) to ensure 0.25 lower bound.*/
let s: i16 = 2 * k - (INSHIFT as i16 - 2);
Expand Down Expand Up @@ -140,7 +140,7 @@ fn ssim_boost_rsqrt(x: u64) -> RsqrtOutput {
Coefficients here, and the final result r, are Q14. */
let rsqrt: i32 = 23557 + mult16_16_q15(n, -13490 + mult16_16_q15(n, 6711));

debug_assert!((16384..32768).contains(&rsqrt));
debug_assert!(16384 <= rsqrt && rsqrt < 32768);
RsqrtOutput { norm: rsqrt as u16, shift: rsqrt_shift }
}

Expand All @@ -156,7 +156,7 @@ pub fn ssim_boost(svar: u32, dvar: u32, bit_depth: usize) -> DistortionScale {

/// Apply ssim boost to a given input
#[inline(always)]
pub fn apply_ssim_boost(
pub const fn apply_ssim_boost(
input: u32, svar: u32, dvar: u32, bit_depth: usize,
) -> u32 {
let coeff_shift = bit_depth - 8;
Expand Down

0 comments on commit 0504761

Please sign in to comment.