Commit a554adca authored by Romain Vimont's avatar Romain Vimont Committed by Thomas Daede

Compute predictors from tiled motion vectors

To prepare for tiling, compute subset predictors from TileMotionVectors
instead of FrameMotionVectors.
parent 6681b602
......@@ -323,7 +323,7 @@ fn get_mv_range(
pub fn get_subset_predictors<T: Pixel>(
bo: BlockOffset, cmv: MotionVector,
frame_mvs: &FrameMotionVectors, frame_ref_opt: Option<&ReferenceFrame<T>>,
tile_mvs: &TileMotionVectors<'_>, frame_ref_opt: Option<&ReferenceFrame<T>>,
ref_frame_id: usize
) -> (Vec<MotionVector>) {
let mut predictors = Vec::new();
......@@ -338,17 +338,17 @@ pub fn get_subset_predictors<T: Pixel>(
let mut median_preds = Vec::new();
if bo.x > 0 {
let left = frame_mvs[bo.y][bo.x - 1];
let left = tile_mvs[bo.y][bo.x - 1];
median_preds.push(left);
if !left.is_zero() { predictors.push(left); }
}
if bo.y > 0 {
let top = frame_mvs[bo.y - 1][bo.x];
let top = tile_mvs[bo.y - 1][bo.x];
median_preds.push(top);
if !top.is_zero() { predictors.push(top); }
if bo.x < frame_mvs.cols - 1 {
let top_right = frame_mvs[bo.y - 1][bo.x + 1];
if bo.x < tile_mvs.cols() - 1 {
let top_right = tile_mvs[bo.y - 1][bo.x + 1];
median_preds.push(top_right);
if !top_right.is_zero() { predictors.push(top_right); }
}
......@@ -369,24 +369,28 @@ pub fn get_subset_predictors<T: Pixel>(
if let Some(ref frame_ref) = frame_ref_opt {
let prev_frame_mvs = &frame_ref.frame_mvs[ref_frame_id];
if bo.x > 0 {
let left = prev_frame_mvs[bo.y][bo.x - 1];
let frame_bo = BlockOffset {
x: tile_mvs.x() + bo.x,
y: tile_mvs.y() + bo.y,
};
if frame_bo.x > 0 {
let left = prev_frame_mvs[frame_bo.y][frame_bo.x - 1];
if !left.is_zero() { predictors.push(left); }
}
if bo.y > 0 {
let top = prev_frame_mvs[bo.y - 1][bo.x];
if frame_bo.y > 0 {
let top = prev_frame_mvs[frame_bo.y - 1][frame_bo.x];
if !top.is_zero() { predictors.push(top); }
}
if bo.x < frame_mvs.cols - 1 {
let right = prev_frame_mvs[bo.y][bo.x + 1];
if frame_bo.x < prev_frame_mvs.cols - 1 {
let right = prev_frame_mvs[frame_bo.y][frame_bo.x + 1];
if !right.is_zero() { predictors.push(right); }
}
if bo.y < frame_mvs.rows - 1 {
let bottom = prev_frame_mvs[bo.y + 1][bo.x];
if frame_bo.y < prev_frame_mvs.rows - 1 {
let bottom = prev_frame_mvs[frame_bo.y + 1][frame_bo.x];
if !bottom.is_zero() { predictors.push(bottom); }
}
let previous = prev_frame_mvs[bo.y][bo.x];
let previous = prev_frame_mvs[frame_bo.y][frame_bo.x];
if !previous.is_zero() { predictors.push(previous); }
}
......@@ -459,6 +463,7 @@ pub trait MotionEstimation {
let global_mv = [MotionVector{row: 0, col: 0}; 2];
let frame_mvs = &fs.frame_mvs[ref_frame];
let tile_mvs = frame_mvs.as_tile_motion_vectors();
let frame_ref_opt = fi.rec_buffer.frames[fi.ref_frames[0] as usize].as_ref().map(Arc::as_ref);
let mut lowest_cost = std::u64::MAX;
......@@ -469,7 +474,7 @@ pub trait MotionEstimation {
Self::me_ss2(
fi, fs, pmvs, bo_adj,
frame_mvs, frame_ref_opt, rec, global_mv, lambda,
&tile_mvs, frame_ref_opt, rec, global_mv, lambda,
mvx_min, mvx_max, mvy_min, mvy_max, blk_w, blk_h,
&mut best_mv, &mut lowest_cost
);
......@@ -482,8 +487,8 @@ pub trait MotionEstimation {
fn me_ss2<T: Pixel>(
fi: &FrameInvariants<T>, fs: &FrameState<T>,
pmvs: &[Option<MotionVector>; 3], bo_adj_h: BlockOffset,
frame_mvs: &FrameMotionVectors, frame_ref_opt: Option<&ReferenceFrame<T>>,
pmvs: &[Option<MotionVector>; 3], bo_adj: BlockOffset,
tile_mvs: &TileMotionVectors<'_>, frame_ref_opt: Option<&ReferenceFrame<T>>,
rec: &ReferenceFrame<T>, global_mv: [MotionVector; 2], lambda: u32,
mvx_min: isize, mvx_max: isize, mvy_min: isize, mvy_max: isize,
blk_w: usize, blk_h: usize,
......@@ -503,9 +508,10 @@ impl MotionEstimation for DiamondSearch {
best_mv: &mut MotionVector, lowest_cost: &mut u64, ref_frame: RefType
) {
let frame_mvs = &fs.frame_mvs[ref_frame.to_index()];
let tile_mvs = frame_mvs.as_tile_motion_vectors();
let frame_ref = fi.rec_buffer.frames[fi.ref_frames[0] as usize].as_ref().map(Arc::as_ref);
let predictors =
get_subset_predictors(bo, cmv, frame_mvs, frame_ref, ref_frame.to_index());
get_subset_predictors(bo, cmv, &tile_mvs, frame_ref, ref_frame.to_index());
diamond_me_search(
fi,
......@@ -563,7 +569,7 @@ impl MotionEstimation for DiamondSearch {
fn me_ss2<T: Pixel>(
fi: &FrameInvariants<T>, fs: &FrameState<T>,
pmvs: &[Option<MotionVector>; 3], bo_adj: BlockOffset,
frame_mvs: &FrameMotionVectors, frame_ref_opt: Option<&ReferenceFrame<T>>,
tile_mvs: &TileMotionVectors<'_>, frame_ref_opt: Option<&ReferenceFrame<T>>,
rec: &ReferenceFrame<T>, global_mv: [MotionVector; 2], lambda: u32,
mvx_min: isize, mvx_max: isize, mvy_min: isize, mvy_max: isize,
blk_w: usize, blk_h: usize,
......@@ -578,7 +584,7 @@ impl MotionEstimation for DiamondSearch {
let mut predictors = get_subset_predictors::<T>(
bo_adj,
MotionVector{row: pmv.row, col: pmv.col},
&frame_mvs, frame_ref_opt, 0
&tile_mvs, frame_ref_opt, 0
);
for predictor in &mut predictors {
......@@ -669,7 +675,7 @@ impl MotionEstimation for FullSearch {
fn me_ss2<T: Pixel>(
fi: &FrameInvariants<T>, fs: &FrameState<T>,
pmvs: &[Option<MotionVector>; 3], bo_adj: BlockOffset,
_frame_mvs: &FrameMotionVectors, _frame_ref_opt: Option<&ReferenceFrame<T>>,
_tile_mvs: &TileMotionVectors<'_>, _frame_ref_opt: Option<&ReferenceFrame<T>>,
rec: &ReferenceFrame<T>, _global_mv: [MotionVector; 2], lambda: u32,
mvx_min: isize, mvx_max: isize, mvy_min: isize, mvy_max: isize,
blk_w: usize, blk_h: usize,
......
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