From 436d5864e9b86cd0ec17255e1617a9355f89495f Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Tue, 20 Feb 2024 22:42:44 +0100 Subject: [PATCH] Reimplement get_rect_tx_ratio as TxSize::rect_ratio_log2 --- src/transform/inverse.rs | 3 +-- src/transform/mod.rs | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/transform/inverse.rs b/src/transform/inverse.rs index 737edf3d4f..0a5a56062d 100644 --- a/src/transform/inverse.rs +++ b/src/transform/inverse.rs @@ -25,7 +25,6 @@ use crate::util::*; use super::clamp_value; use super::consts::*; use super::get_1d_tx_types; -use super::get_rect_tx_log_ratio; use super::half_btf; use super::TxSize; use super::TxType; @@ -1644,7 +1643,7 @@ pub(crate) mod rust { // For 64 point transforms, rely on the last 32 columns being initialized // to zero for filling out missing input coeffs. let mut buffer = vec![0i32; width * height].into_boxed_slice(); - let rect_type = get_rect_tx_log_ratio(width, height); + let rect_type = tx_size.rect_ratio_log2(); let tx_types_1d = get_1d_tx_types(tx_type); let lossless = tx_type == TxType::WHT_WHT; diff --git a/src/transform/mod.rs b/src/transform/mod.rs index 0ebfa43cd5..649e6f55bd 100644 --- a/src/transform/mod.rs +++ b/src/transform/mod.rs @@ -268,6 +268,12 @@ impl TxSize { pub const fn is_rect(self) -> bool { self.width_log2() != self.height_log2() } + + /// Returns log2(width / height), e.g. `TX_16x4` -> log2(16 / 4) = 2 + #[inline] + pub const fn rect_ratio_log2(self) -> i8 { + self.width_log2() as i8 - self.height_log2() as i8 + } } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd)] @@ -286,13 +292,6 @@ pub enum TxSet { TX_SET_INTER_1, // TX_SET_ALL16 } -/// Utility function that returns the log of the ratio of the col and row sizes. -#[inline] -pub fn get_rect_tx_log_ratio(col: usize, row: usize) -> i8 { - debug_assert!(col > 0 && row > 0); - ILog::ilog(col) as i8 - ILog::ilog(row) as i8 -} - // performs half a butterfly #[inline] const fn half_btf(w0: i32, in0: i32, w1: i32, in1: i32, bit: usize) -> i32 { @@ -548,9 +547,7 @@ mod test { tx_size.width(), tx_size.height() ); - assert!( - get_rect_tx_log_ratio(tx_size.width(), tx_size.height()) == expected - ); + assert!(tx_size.rect_ratio_log2() == expected); } }