Skip to main content

pito_codecs/vp9/enc/tx/
tables.rs

1pub use crate::vp9::spec_tables::{COEFBAND_4X4, COEFBAND_8X8PLUS, ENERGY_CLASS};
2pub use crate::vp9::tables::{CAT_PROBS, scan};
3
4pub fn bands(tx_size: u8) -> &'static [u8] {
5    if tx_size == 0 {
6        &COEFBAND_4X4
7    } else {
8        &COEFBAND_8X8PLUS
9    }
10}
11
12pub struct ScanSet {
13    pub neighbors: Vec<(u16, u16)>,
14    pub iscan_t: Vec<u16>,
15}
16
17fn build(tx: u8, ty: u8) -> ScanSet {
18    let sc = scan(tx, ty);
19    let log2n = 2 + tx as usize;
20    let n = 1usize << log2n;
21    let mut neighbors = vec![(0u16, 0u16); sc.len()];
22    let mut iscan_t = vec![0u16; sc.len()];
23    for (c, &pos) in sc.iter().enumerate() {
24        let pos = pos as usize;
25        let (i, j) = (pos >> log2n, pos & (n - 1));
26        iscan_t[(j << log2n) | i] = c as u16;
27        if c == 0 {
28            continue;
29        }
30        neighbors[c] = if i > 0 && j > 0 {
31            let a = ((i - 1) * n + j) as u16;
32            let l = (i * n + j - 1) as u16;
33            match if tx == 3 { 0 } else { ty } {
34                2 => (a, a),
35                1 => (l, l),
36                _ => (a, l),
37            }
38        } else if i > 0 {
39            let a = ((i - 1) * n + j) as u16;
40            (a, a)
41        } else {
42            let l = (i * n + j - 1) as u16;
43            (l, l)
44        };
45    }
46    ScanSet { neighbors, iscan_t }
47}
48
49pub fn scan_set(tx_size: u8, tx_type: u8) -> &'static ScanSet {
50    use std::sync::LazyLock;
51    static ALL: LazyLock<Vec<ScanSet>> =
52        LazyLock::new(|| (0..16u8).map(|k| build(k >> 2, k & 3)).collect());
53    &ALL[((tx_size.min(3) << 2) | if tx_size >= 3 { 0 } else { tx_type & 3 }) as usize]
54}
55
56pub fn neighbors(tx_size: u8, tx_type: u8) -> &'static [(u16, u16)] {
57    &scan_set(tx_size, tx_type).neighbors
58}