Skip to content

Commit

Permalink
Reimplement get_rect_tx_ratio as TxSize::rect_ratio_log2
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezyLemon committed Apr 16, 2024
1 parent 8651a0e commit aa8e88b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/transform/inverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 7 additions & 10 deletions src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit aa8e88b

Please sign in to comment.