From b621e2d72efe6e164264359e0e330123afeae835 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Wed, 31 Jul 2013 16:11:03 -0700 Subject: [PATCH] Nice looking motion vector clamping functions. Removing assign_and_clamp_mv function, making implementation of clamp_mv and clamp_mv2 more clear and consistent. Change-Id: Iecd08e1c1bf0379f8314ebe01811f8253f4ade58 --- vp9/common/vp9_findnearmv.c | 2 +- vp9/common/vp9_findnearmv.h | 25 +++++++------------ vp9/decoder/vp9_decodemv.c | 49 +++++++++++-------------------------- vp9/encoder/vp9_mcomp.c | 9 ++++--- vp9/encoder/vp9_rdopt.c | 8 +++--- 5 files changed, 33 insertions(+), 60 deletions(-) diff --git a/vp9/common/vp9_findnearmv.c b/vp9/common/vp9_findnearmv.c index cea06b4bd..d056dffc9 100644 --- a/vp9/common/vp9_findnearmv.c +++ b/vp9/common/vp9_findnearmv.c @@ -32,7 +32,7 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, // Make sure all the candidates are properly clamped etc for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) { lower_mv_precision(&mvlist[i], xd->allow_high_precision_mv); - clamp_mv2(&mvlist[i], xd); + clamp_mv2(&mvlist[i].as_mv, xd); } *nearest = mvlist[0]; *near = mvlist[1]; diff --git a/vp9/common/vp9_findnearmv.h b/vp9/common/vp9_findnearmv.h index 907e580cd..543351df3 100644 --- a/vp9/common/vp9_findnearmv.h +++ b/vp9/common/vp9_findnearmv.h @@ -29,24 +29,17 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int_mv *near); // TODO(jingning): this mv clamping function should be block size dependent. -static void clamp_mv(int_mv *mv, - int mb_to_left_edge, - int mb_to_right_edge, - int mb_to_top_edge, - int mb_to_bottom_edge) { - mv->as_mv.col = clamp(mv->as_mv.col, mb_to_left_edge, mb_to_right_edge); - mv->as_mv.row = clamp(mv->as_mv.row, mb_to_top_edge, mb_to_bottom_edge); +static void clamp_mv(MV *mv, int min_col, int max_col, + int min_row, int max_row) { + mv->col = clamp(mv->col, min_col, max_col); + mv->row = clamp(mv->row, min_row, max_row); } -static int clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) { - int_mv tmp_mv; - tmp_mv.as_int = mv->as_int; - clamp_mv(mv, - xd->mb_to_left_edge - LEFT_TOP_MARGIN, - xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN, - xd->mb_to_top_edge - LEFT_TOP_MARGIN, - xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN); - return tmp_mv.as_int != mv->as_int; +static void clamp_mv2(MV *mv, const MACROBLOCKD *xd) { + clamp_mv(mv, xd->mb_to_left_edge - LEFT_TOP_MARGIN, + xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN, + xd->mb_to_top_edge - LEFT_TOP_MARGIN, + xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN); } void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *pc, diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index 6282f944b..aa1ebc53e 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -366,16 +366,6 @@ static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) { return mode; } -static INLINE void assign_and_clamp_mv(int_mv *dst, const int_mv *src, - int mb_to_left_edge, - int mb_to_right_edge, - int mb_to_top_edge, - int mb_to_bottom_edge) { - dst->as_int = src->as_int; - clamp_mv(dst, mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, - mb_to_bottom_edge); -} - static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type( VP9D_COMP *pbi, vp9_reader *r) { VP9_COMMON *const cm = &pbi->common; @@ -558,36 +548,25 @@ static void read_inter_block_mode_info(VP9D_COMP *pbi, MODE_INFO *mi, mv0->as_int = mi->bmi[3].as_mv[0].as_int; mv1->as_int = mi->bmi[3].as_mv[1].as_int; } else { - const int mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN; - const int mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; - const int mb_to_left_edge = xd->mb_to_left_edge - LEFT_TOP_MARGIN; - const int mb_to_right_edge = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN; - switch (mbmi->mode) { case NEARMV: - // Clip "next_nearest" so that it does not extend to far out of image - assign_and_clamp_mv(mv0, &nearby, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); - if (ref1 > 0) - assign_and_clamp_mv(mv1, &nearby_second, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); + mv0->as_int = nearby.as_int; + clamp_mv2(&mv0->as_mv, xd); + + if (ref1 > 0) { + mv1->as_int = nearby_second.as_int; + clamp_mv2(&mv1->as_mv, xd); + } break; case NEARESTMV: - // Clip "next_nearest" so that it does not extend to far out of image - assign_and_clamp_mv(mv0, &nearest, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); - if (ref1 > 0) - assign_and_clamp_mv(mv1, &nearest_second, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); + mv0->as_int = nearest.as_int; + clamp_mv2(&mv0->as_mv, xd); + + if (ref1 > 0) { + mv1->as_int = nearest_second.as_int; + clamp_mv2(&mv1->as_mv, xd); + } break; case ZEROMV: diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index b2814d93e..e3c002b1f 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -1319,7 +1319,8 @@ int vp9_hex_search fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; // adjust ref_mv to make sure it is within MV range - clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); + clamp_mv(&ref_mv->as_mv, + x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); br = ref_mv->as_mv.row; bc = ref_mv->as_mv.col; @@ -1475,7 +1476,8 @@ int vp9_diamond_search_sad_c(MACROBLOCK *x, fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; - clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); + clamp_mv(&ref_mv->as_mv, + x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); ref_row = ref_mv->as_mv.row; ref_col = ref_mv->as_mv.col; *num00 = 0; @@ -1615,7 +1617,8 @@ int vp9_diamond_search_sadx4(MACROBLOCK *x, fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; - clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); + clamp_mv(&ref_mv->as_mv, + x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); ref_row = ref_mv->as_mv.row; ref_col = ref_mv->as_mv.col; *num00 = 0; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 1303948dd..29bfd23ab 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -1973,7 +1973,7 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, // Should we do a full search (best quality only) if (cpi->compressor_speed == 0) { /* Check if mvp_full is within the range. */ - clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, + clamp_mv(&mvp_full.as_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); thissme = cpi->full_search_sad(x, &mvp_full, @@ -2833,10 +2833,8 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, for (i = 0; i < num_refs; ++i) { cur_mv[i] = frame_mv[refs[i]]; // Clip "next_nearest" so that it does not extend to far out of image - if (this_mode == NEWMV) - assert(!clamp_mv2(&cur_mv[i], xd)); - else - clamp_mv2(&cur_mv[i], xd); + if (this_mode != NEWMV) + clamp_mv2(&cur_mv[i].as_mv, xd); if (mv_check_bounds(x, &cur_mv[i])) return INT64_MAX; -- 2.40.0