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
This commit is contained in:
Dmitry Kovalev 2013-07-31 16:11:03 -07:00
Родитель 56df76bf1b
Коммит b621e2d72e
5 изменённых файлов: 33 добавлений и 60 удалений

Просмотреть файл

@ -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];

Просмотреть файл

@ -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,

Просмотреть файл

@ -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:

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;