use std::fmt::Debug;
use super::loopfilter::{Pixels, Thresholds};
use super::recon::{self, IntraEdges, Kernel};
use crate::vp9_simd::{self, loopfilter::Taps};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FilterTaps {
Four,
Eight,
Sixteen,
}
pub trait Pixel: Copy + Default + Debug + PartialEq + Send + Sync + 'static {
fn from_i32(value: i32) -> Self;
fn to_i32(self) -> i32;
fn extend_bytes(samples: &[Self], out: &mut Vec<u8>);
#[allow(clippy::too_many_arguments)]
fn inverse_transform_add(
coefficients: &[i32],
dest: &mut [Self],
stride: usize,
tx_size: u8,
tx_type: u8,
eob: usize,
lossless: bool,
bit_depth: u8,
);
#[allow(clippy::too_many_arguments)]
fn predict_intra(
dest: &mut [Self],
stride: usize,
bs: usize,
mode: u8,
edges: &IntraEdges<Self>,
have_left: bool,
have_above: bool,
bit_depth: u8,
);
#[allow(clippy::too_many_arguments)]
fn convolve(
src: &[Self],
origin: usize,
src_stride: usize,
dest: &mut [Self],
stride: usize,
w: usize,
h: usize,
kernel: &Kernel,
x_frac: i32,
x_step: i32,
y_frac: i32,
y_step: i32,
average: bool,
temp: &mut [Self; 64 * 135],
bit_depth: u8,
);
#[allow(clippy::too_many_arguments)]
fn filter_edge_vector(
pixels: &mut Pixels<'_, Self>,
start: isize,
step: isize,
along: isize,
count: usize,
t: Thresholds,
taps: FilterTaps,
) -> bool;
}
impl Pixel for u8 {
#[inline]
fn from_i32(value: i32) -> Self {
value as u8
}
#[inline]
fn to_i32(self) -> i32 {
i32::from(self)
}
fn extend_bytes(samples: &[Self], out: &mut Vec<u8>) {
out.extend_from_slice(samples);
}
#[inline]
fn inverse_transform_add(
coefficients: &[i32],
dest: &mut [Self],
stride: usize,
tx_size: u8,
tx_type: u8,
eob: usize,
lossless: bool,
_bit_depth: u8,
) {
recon::inverse_transform_add(coefficients, dest, stride, tx_size, tx_type, eob, lossless);
}
#[inline]
fn predict_intra(
dest: &mut [Self],
stride: usize,
bs: usize,
mode: u8,
edges: &IntraEdges<Self>,
have_left: bool,
have_above: bool,
_bit_depth: u8,
) {
recon::predict_intra(dest, stride, bs, mode, edges, have_left, have_above);
}
#[inline]
fn convolve(
src: &[Self],
origin: usize,
src_stride: usize,
dest: &mut [Self],
stride: usize,
w: usize,
h: usize,
kernel: &Kernel,
x_frac: i32,
x_step: i32,
y_frac: i32,
y_step: i32,
average: bool,
temp: &mut [Self; 64 * 135],
_bit_depth: u8,
) {
recon::convolve(
src, origin, src_stride, dest, stride, w, h, kernel, x_frac, x_step, y_frac, y_step,
average, temp,
);
}
#[inline]
fn filter_edge_vector(
pixels: &mut Pixels<'_, Self>,
start: isize,
step: isize,
along: isize,
count: usize,
t: Thresholds,
taps: FilterTaps,
) -> bool {
let taps = match taps {
FilterTaps::Four => Taps::Four,
FilterTaps::Eight => Taps::Eight,
FilterTaps::Sixteen => Taps::Sixteen,
};
vp9_simd::filter_edge(pixels.isa, pixels.data, start, step, along, count, t, taps)
}
}
impl Pixel for u16 {
#[inline]
fn from_i32(value: i32) -> Self {
value as u16
}
#[inline]
fn to_i32(self) -> i32 {
i32::from(self)
}
fn extend_bytes(samples: &[Self], out: &mut Vec<u8>) {
out.reserve(samples.len() * 2);
for sample in samples {
out.extend_from_slice(&sample.to_le_bytes());
}
}
#[inline]
fn inverse_transform_add(
coefficients: &[i32],
dest: &mut [Self],
stride: usize,
tx_size: u8,
tx_type: u8,
eob: usize,
lossless: bool,
bit_depth: u8,
) {
recon::inverse_transform_add_high(
coefficients,
dest,
stride,
tx_size,
tx_type,
eob,
lossless,
bit_depth,
);
}
#[inline]
fn predict_intra(
dest: &mut [Self],
stride: usize,
bs: usize,
mode: u8,
edges: &IntraEdges<Self>,
have_left: bool,
have_above: bool,
bit_depth: u8,
) {
recon::predict_intra_generic(
dest, stride, bs, mode, edges, have_left, have_above, bit_depth,
);
}
#[inline]
fn convolve(
src: &[Self],
origin: usize,
src_stride: usize,
dest: &mut [Self],
stride: usize,
w: usize,
h: usize,
kernel: &Kernel,
x_frac: i32,
x_step: i32,
y_frac: i32,
y_step: i32,
average: bool,
temp: &mut [Self; 64 * 135],
bit_depth: u8,
) {
recon::convolve_generic(
src, origin, src_stride, dest, stride, w, h, kernel, x_frac, x_step, y_frac, y_step,
average, temp, bit_depth,
);
}
#[inline]
fn filter_edge_vector(
_pixels: &mut Pixels<'_, Self>,
_start: isize,
_step: isize,
_along: isize,
_count: usize,
_t: Thresholds,
_taps: FilterTaps,
) -> bool {
false
}
}