pito_codecs/vp9/enc/pred/
mod.rs1#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
2
3pub mod dist;
4pub mod halfpel;
5pub mod inter;
6pub mod intra;
7#[cfg(target_arch = "x86_64")]
8mod mc_avx2;
9pub mod mode;
10pub mod motion;
11pub mod mvcost;
12#[cfg(test)]
13mod tests;
14
15pub use crate::vp9::tables::{
16 ALTREF_FRAME, BLOCK_8X8, BLOCK_64X64, COMPANDED_MVREF_THRESH, D45_PRED, D63_PRED, D117_PRED,
17 D135_PRED, D153_PRED, D207_PRED, DC_PRED, GOLDEN_FRAME, H_PRED, INTRA_FRAME, LAST_FRAME,
18 NEARESTMV, NEARMV, NEWMV, TM_PRED, V_PRED, ZEROMV,
19};
20
21pub const NONE_FRAME: i8 = -1;
22
23pub const EIGHTTAP: u8 = 0;
24pub const EIGHTTAP_SMOOTH: u8 = 1;
25pub const EIGHTTAP_SHARP: u8 = 2;
26pub const BILINEAR: u8 = 3;
27
28pub const BLOCK_4X4: u8 = 0;
29
30pub const BLOCK_W: [usize; 13] = [4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64];
31pub const BLOCK_H: [usize; 13] = [4, 8, 4, 8, 16, 8, 16, 32, 16, 32, 64, 32, 64];
32
33#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
34pub struct Mv {
35 pub row: i16,
36 pub col: i16,
37}
38
39impl Mv {
40 pub const ZERO: Mv = Mv { row: 0, col: 0 };
41
42 pub const fn new(row: i16, col: i16) -> Self {
43 Mv { row, col }
44 }
45
46 pub fn use_hp(self) -> bool {
47 (self.row as i32).abs() >> 3 < COMPANDED_MVREF_THRESH
48 && (self.col as i32).abs() >> 3 < COMPANDED_MVREF_THRESH
49 }
50
51 pub fn lower_precision(self, allow_hp: bool) -> Mv {
52 if allow_hp && self.use_hp() {
53 return self;
54 }
55 let f = |v: i16| if v & 1 != 0 { v - v.signum() } else { v };
56 Mv::new(f(self.row), f(self.col))
57 }
58}
59
60#[derive(Clone, Copy)]
61pub struct Plane<'a> {
62 pub data: &'a [u8],
63 pub stride: usize,
64 pub origin: usize,
65 pub width: usize,
66 pub height: usize,
67 pub border: usize,
68}
69
70impl<'a> Plane<'a> {
71 #[inline(always)]
72 pub fn at(&self, x: isize, y: isize) -> usize {
73 (self.origin as isize + y * self.stride as isize + x) as usize
74 }
75
76 #[inline(always)]
77 pub fn inside(&self, x: isize, y: isize, w: usize, h: usize) -> bool {
78 let b = self.border as isize;
79 x >= -b
80 && y >= -b
81 && x + w as isize <= self.width as isize + b
82 && y + h as isize <= self.height as isize + b
83 }
84}
85
86pub fn extend_borders(
87 data: &mut [u8],
88 stride: usize,
89 origin: usize,
90 width: usize,
91 height: usize,
92 border: usize,
93) {
94 for y in 0..height {
95 let row = origin + y * stride;
96 let (l, r) = (data[row], data[row + width - 1]);
97 data[row - border..row].fill(l);
98 data[row + width..row + width + border].fill(r);
99 }
100 let first = origin - border;
101 let span = width + 2 * border;
102 for y in 1..=border {
103 data.copy_within(first..first + span, first - y * stride);
104 let last = first + (height - 1) * stride;
105 data.copy_within(last..last + span, last + y * stride);
106 }
107}