Commit 678afd62 authored by David Michael Barr's avatar David Michael Barr

Embed DC prediction in CFL prediction as per dav1d

parent f1333229
......@@ -182,11 +182,20 @@ pub fn intra_bench(c: &mut Criterion) {
pub fn intra_cfl_4x4_aom(b: &mut Bencher) {
let mut rng = ChaChaRng::from_seed([0; 32]);
let (mut block, _above_context, _left_context) = generate_block(&mut rng);
let (mut block, above_context, left_context) = generate_block(&mut rng);
let ac: Vec<i16> = (0..(32 * 32)).map(|_| rng.gen()).collect();
let alpha = -1 as i16;
b.iter(|| unsafe {
highbd_dc_predictor(
block.as_mut_ptr(),
BLOCK_SIZE.width() as libc::ptrdiff_t,
4,
4,
above_context.as_ptr(),
left_context.as_ptr(),
8
);
cfl_predict_hbd_c(
ac.as_ptr(),
block.as_mut_ptr(),
......
......@@ -191,12 +191,20 @@ pub fn intra_smooth_v_4x4(b: &mut Bencher) {
pub fn intra_cfl_4x4(b: &mut Bencher) {
let mut rng = ChaChaRng::from_seed([0; 32]);
let (mut block, _above, _left) = generate_block(&mut rng);
let (mut block, above, left) = generate_block(&mut rng);
let ac: Vec<i16> = (0..(32 * 32)).map(|_| rng.gen()).collect();
let alpha = -1 as i16;
b.iter(|| {
Block4x4::pred_cfl(&mut block, BLOCK_SIZE.width(), &ac, alpha, 8);
Block4x4::pred_cfl(
&mut block,
BLOCK_SIZE.width(),
&ac,
alpha,
8,
&above,
&left
);
})
}
......
......@@ -895,14 +895,20 @@ impl PredictionMode {
(0, _) => PredictionMode::V_PRED,
_ => PredictionMode::PAETH_PRED
},
PredictionMode::UV_CFL_PRED => PredictionMode::DC_PRED,
PredictionMode::UV_CFL_PRED =>
if alpha == 0 {
PredictionMode::DC_PRED
} else {
self
},
_ => self
};
let dc_or_cfl =
mode == PredictionMode::DC_PRED || mode == PredictionMode::UV_CFL_PRED;
// Needs left
if mode != PredictionMode::V_PRED
&& (mode != PredictionMode::DC_PRED || x != 0)
{
if mode != PredictionMode::V_PRED && (!dc_or_cfl || x != 0) {
if x != 0 {
let left_slice = dst.go_left(1);
for i in 0..B::H {
......@@ -927,9 +933,7 @@ impl PredictionMode {
}
// Needs top
if mode != PredictionMode::H_PRED
&& (mode != PredictionMode::DC_PRED || y != 0)
{
if mode != PredictionMode::H_PRED && (!dc_or_cfl || y != 0) {
if y != 0 {
above[..B::W].copy_from_slice(&dst.go_up(1).as_slice()[..B::W]);
} else {
......@@ -951,6 +955,36 @@ impl PredictionMode {
(0, _) => B::pred_dc_top(slice, stride, above_slice, left_slice),
_ => B::pred_dc(slice, stride, above_slice, left_slice)
},
PredictionMode::UV_CFL_PRED => match (x, y) {
(0, 0) => B::pred_cfl_128(slice, stride, &ac, alpha, bit_depth),
(_, 0) => B::pred_cfl_left(
slice,
stride,
&ac,
alpha,
bit_depth,
above_slice,
left_slice
),
(0, _) => B::pred_cfl_top(
slice,
stride,
&ac,
alpha,
bit_depth,
above_slice,
left_slice
),
_ => B::pred_cfl(
slice,
stride,
&ac,
alpha,
bit_depth,
above_slice,
left_slice
)
},
PredictionMode::H_PRED => B::pred_h(slice, stride, left_slice),
PredictionMode::V_PRED => B::pred_v(slice, stride, above_slice),
PredictionMode::PAETH_PRED =>
......@@ -963,9 +997,6 @@ impl PredictionMode {
B::pred_smooth_v(slice, stride, above_slice, left_slice),
_ => unimplemented!()
}
if self == PredictionMode::UV_CFL_PRED {
B::pred_cfl(slice, stride, &ac, alpha, bit_depth);
}
}
pub fn is_intra(self) -> bool {
......
......@@ -609,10 +609,8 @@ where
}
}
#[cfg_attr(feature = "comparative_bench", inline(never))]
fn pred_cfl(
output: &mut [T], stride: usize, ac: &[i16], alpha: i16,
bit_depth: usize
fn pred_cfl_inner(
output: &mut [T], stride: usize, ac: &[i16], alpha: i16, bit_depth: usize
) {
if alpha == 0 {
return;
......@@ -642,6 +640,38 @@ where
}
}
}
#[cfg_attr(feature = "comparative_bench", inline(never))]
fn pred_cfl(
output: &mut [T], stride: usize, ac: &[i16], alpha: i16, bit_depth: usize,
above: &[T], left: &[T]
) {
Self::pred_dc(output, stride, above, left);
Self::pred_cfl_inner(output, stride, &ac, alpha, bit_depth);
}
fn pred_cfl_128(
output: &mut [T], stride: usize, ac: &[i16], alpha: i16, bit_depth: usize
) {
Self::pred_dc_128(output, stride, bit_depth);
Self::pred_cfl_inner(output, stride, &ac, alpha, bit_depth);
}
fn pred_cfl_left(
output: &mut [T], stride: usize, ac: &[i16], alpha: i16, bit_depth: usize,
above: &[T], left: &[T]
) {
Self::pred_dc_left(output, stride, above, left);
Self::pred_cfl_inner(output, stride, &ac, alpha, bit_depth);
}
fn pred_cfl_top(
output: &mut [T], stride: usize, ac: &[i16], alpha: i16, bit_depth: usize,
above: &[T], left: &[T]
) {
Self::pred_dc_top(output, stride, above, left);
Self::pred_cfl_inner(output, stride, &ac, alpha, bit_depth);
}
}
pub trait Inter: Dim {}
......@@ -840,10 +870,9 @@ pub mod test {
let (above, left, ac, alpha, mut o1, mut o2) = setup_cfl_pred(ra, 8);
pred_dc_4x4(&mut o1, 32, &above[..4], &left[..4]);
Block4x4::pred_dc(&mut o2, 32, &above[..4], &left[..4]);
pred_cfl_4x4(&mut o1, 32, &ac, alpha, 8);
Block4x4::pred_cfl(&mut o2, 32, &ac, alpha, 8);
Block4x4::pred_cfl(&mut o2, 32, &ac, alpha, 8, &above[..4], &left[..4]);
(o1, o2)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment