Skip to content
Snippets Groups Projects
Unverified Commit aaf45dd0 authored by Frank Bossen's avatar Frank Bossen Committed by GitHub
Browse files

Refactor: move SAD computation into a separate function (#517)

* Move SAD computation into a separate function

* Always inline SAD function for speed
parent 8e161adb
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,23 @@ use context::BlockOffset;
use plane::*;
use context::BLOCK_TO_PLANE_SHIFT;
#[inline(always)]
pub fn get_sad(plane_org: &mut PlaneSlice, plane_ref: &mut PlaneSlice, blk_h: usize, blk_w: usize) -> u32 {
let mut sum = 0 as u32;
for _r in 0..blk_h {
{
let slice_org = plane_org.as_slice_w_width(blk_w);
let slice_ref = plane_ref.as_slice_w_width(blk_w);
sum += slice_org.iter().zip(slice_ref).map(|(&a, &b)| (a as i32 - b as i32).abs() as u32).sum::<u32>();
}
plane_org.y += 1;
plane_ref.y += 1;
}
sum
}
pub fn motion_estimation(fi: &FrameInvariants, fs: &mut FrameState, bsize: BlockSize,
bo: &BlockOffset, ref_frame: usize) -> MotionVector {
......@@ -34,19 +51,10 @@ pub fn motion_estimation(fi: &FrameInvariants, fs: &mut FrameState, bsize: Block
for y in (y_lo..y_hi).step_by(1) {
for x in (x_lo..x_hi).step_by(1) {
let mut sad = 0 as u32;
let mut plane_org = fs.input.planes[0].slice(&po);
let mut plane_ref = rec.frame.planes[0].slice(&PlaneOffset { x: x, y: y });
for _r in 0..blk_h {
{
let slice_org = plane_org.as_slice_w_width(blk_w);
let slice_ref = plane_ref.as_slice_w_width(blk_w);
sad += slice_org.iter().zip(slice_ref).map(|(&a, &b)| (a as i32 - b as i32).abs() as u32).sum::<u32>();
}
plane_org.y += 1;
plane_ref.y += 1;
}
let sad = get_sad(&mut plane_org, &mut plane_ref, blk_h, blk_w);
if sad < lowest_sad {
lowest_sad = sad;
......@@ -80,19 +88,10 @@ pub fn motion_estimation(fi: &FrameInvariants, fs: &mut FrameState, bsize: Block
mode.predict_inter(fi, 0, &po, tmp_slice, blk_w, blk_h, ref_frame, &cand_mv, 8);
}
let mut sad = 0 as u32;
let mut plane_org = fs.input.planes[0].slice(&po);
let mut plane_ref = tmp_plane.slice(&PlaneOffset { x:0, y:0 });
for _r in 0..blk_h {
{
let slice_org = plane_org.as_slice_w_width(blk_w);
let slice_ref = plane_ref.as_slice_w_width(blk_w);
sad += slice_org.iter().zip(slice_ref).map(|(&a, &b)| (a as i32 - b as i32).abs() as u32).sum::<u32>();
}
plane_org.y += 1;
plane_ref.y += 1;
}
let sad = get_sad(&mut plane_org, &mut plane_ref, blk_h, blk_w);
if sad < lowest_sad {
lowest_sad = sad;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment