Unverified Commit 8ecca039 authored by Thomas Daede's avatar Thomas Daede Committed by GitHub

Merge pull request #33 from luctrudeau/v_pred

Perform RDO over DC_PRED, H_PRED and V_PRED
parents 0eaa36f0 03b69822
......@@ -289,7 +289,7 @@ fn write_b(cw: &mut ContextWriter, fi: &FrameInvariants, fs: &mut FrameState, p:
PredictionMode::H_PRED =>
pred_h(&mut fs.rec.planes[p].data[y*stride+x..], stride, &left, 4),
PredictionMode::V_PRED =>
pred_v_4x4(&mut fs.rec.planes[p].data[y*stride+x..], stride, &above, &left),
pred_v(&mut fs.rec.planes[p].data[y*stride+x..], stride, &above, 4),
_ =>
panic!("Unimplemented prediction mode: {:?}", mode),
}
......@@ -370,7 +370,7 @@ fn encode_tile(fi: &FrameInvariants, fs: &mut FrameState) -> Vec<u8> {
let mut best_mode = PredictionMode::DC_PRED;
let mut best_rd = std::f64::MAX;
for &mode in &[PredictionMode::DC_PRED, PredictionMode::V_PRED] {
for &mode in &[PredictionMode::DC_PRED, PredictionMode::H_PRED, PredictionMode::V_PRED] {
let checkpoint = cw.checkpoint();
write_sb(&mut cw, fi, fs, sbx, sby, mode);
......
......@@ -16,6 +16,7 @@ extern {
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
#[cfg(test)]
fn highbd_v_predictor(dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int,
bh: libc::c_int, above: *const u16,
left: *const u16, bd: libc::c_int);
......@@ -64,10 +65,11 @@ pub fn pred_h(output: &mut [u16], stride: usize, left: &[u16], bw: usize) {
}
}
pub fn pred_v_4x4(output: &mut [u16], stride: usize, above: &[u16], left: &[u16]) {
unsafe {
highbd_v_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
pub fn pred_v(output: &mut [u16], stride: usize, above: &[u16], bh: usize) {
let bw = above.len();
for line in output.chunks_mut(stride).take(bh) {
line[..bw].clone_from_slice(above)
}
}
#[cfg(test)]
......@@ -95,9 +97,15 @@ mod test {
}
pub fn pred_h_4x4(output: &mut [u16], stride: usize, above: &[u16], left: &[u16]) {
unsafe {
highbd_h_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
unsafe {
highbd_h_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
}
pub fn pred_v_4x4(output: &mut [u16], stride: usize, above: &[u16], left: &[u16]) {
unsafe {
highbd_v_predictor(output.as_mut_ptr(), stride as libc::ptrdiff_t, 4, 4, above.as_ptr(), left.as_ptr(), 8);
}
}
fn do_dc_pred(ra: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>) {
......@@ -118,12 +126,21 @@ mod test {
(o1, o2)
}
fn do_v_pred(ra: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>) {
let (above, left, mut o1, mut o2) = setup_pred(ra);
pred_v_4x4(&mut o1, 32, &above[..4], &left[..4]);
pred_v(&mut o2, 32, &above[..4], 4);
(o1, o2)
}
fn assert_same(o2: Vec<u16>) {
for l in o2.chunks(32).take(4) {
for v in l[..4].windows(2) {
assert_eq!(v[0], v[1]);
for l in o2.chunks(32).take(4) {
for v in l[..4].windows(2) {
assert_eq!(v[0], v[1]);
}
}
}
}
#[test]
......@@ -135,6 +152,9 @@ mod test {
let (o1, o2) = do_h_pred(&mut ra);
assert_eq!(o1, o2);
let (o1, o2) = do_v_pred(&mut ra);
assert_eq!(o1, o2);
}
}
......@@ -171,5 +191,13 @@ mod test {
assert_eq!(*v, max12bit);
}
}
pred_v(&mut o, 32, &above[..4], 4);
for l in o.chunks(32).take(4) {
for v in l[..4].iter() {
assert_eq!(*v, max12bit);
}
}
}
}
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