Index: source/libvpx/vp9/encoder/vp9_mcomp.c |
diff --git a/source/libvpx/vp9/encoder/vp9_mcomp.c b/source/libvpx/vp9/encoder/vp9_mcomp.c |
index 081b99f9f1f211a70926ee82911d78707a2d6fb6..6a02481fa5aa9618d064045c74fcd5e8d249a4fe 100644 |
--- a/source/libvpx/vp9/encoder/vp9_mcomp.c |
+++ b/source/libvpx/vp9/encoder/vp9_mcomp.c |
@@ -37,10 +37,10 @@ void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv) { |
int col_max = (mv->col >> 3) + MAX_FULL_PEL_VAL; |
int row_max = (mv->row >> 3) + MAX_FULL_PEL_VAL; |
- col_min = MAX(col_min, (MV_LOW >> 3) + 1); |
- row_min = MAX(row_min, (MV_LOW >> 3) + 1); |
- col_max = MIN(col_max, (MV_UPP >> 3) - 1); |
- row_max = MIN(row_max, (MV_UPP >> 3) - 1); |
+ col_min = VPXMAX(col_min, (MV_LOW >> 3) + 1); |
+ row_min = VPXMAX(row_min, (MV_LOW >> 3) + 1); |
+ col_max = VPXMIN(col_max, (MV_UPP >> 3) - 1); |
+ row_max = VPXMIN(row_max, (MV_UPP >> 3) - 1); |
// Get intersection of UMV window and valid MV window to reduce # of checks |
// in diamond search. |
@@ -57,12 +57,12 @@ void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv) { |
int vp9_init_search_range(int size) { |
int sr = 0; |
// Minimum search size no matter what the passed in value. |
- size = MAX(16, size); |
+ size = VPXMAX(16, size); |
while ((size << sr) < MAX_FULL_PEL_VAL) |
sr++; |
- sr = MIN(sr, MAX_MVSEARCH_STEPS - 2); |
+ sr = VPXMIN(sr, MAX_MVSEARCH_STEPS - 2); |
return sr; |
} |
@@ -256,6 +256,27 @@ static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { |
} \ |
} |
+// TODO(yunqingwang): SECOND_LEVEL_CHECKS_BEST was a rewrote of |
+// SECOND_LEVEL_CHECKS, and SECOND_LEVEL_CHECKS should be rewritten |
+// later in the same way. |
+#define SECOND_LEVEL_CHECKS_BEST \ |
+ { \ |
+ unsigned int second; \ |
+ int br0 = br; \ |
+ int bc0 = bc; \ |
+ assert(tr == br || tc == bc); \ |
+ if (tr == br && tc != bc) { \ |
+ kc = bc - tc; \ |
+ } else if (tr != br && tc == bc) { \ |
+ kr = br - tr; \ |
+ } \ |
+ CHECK_BETTER(second, br0 + kr, bc0); \ |
+ CHECK_BETTER(second, br0, bc0 + kc); \ |
+ if (br0 != br || bc0 != bc) { \ |
+ CHECK_BETTER(second, br0 + kr, bc0 + kc); \ |
+ } \ |
+ } |
+ |
#define SETUP_SUBPEL_SEARCH \ |
const uint8_t *const z = x->plane[0].src.buf; \ |
const int src_stride = x->plane[0].src.stride; \ |
@@ -276,10 +297,10 @@ static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { |
int br = bestmv->row * 8; \ |
int bc = bestmv->col * 8; \ |
int hstep = 4; \ |
- const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \ |
- const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); \ |
- const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); \ |
- const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \ |
+ const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \ |
+ const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); \ |
+ const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); \ |
+ const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \ |
int tr = br; \ |
int tc = bc; \ |
\ |
@@ -636,7 +657,6 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
const MACROBLOCKD *xd = &x->e_mbd; |
unsigned int besterr = INT_MAX; |
unsigned int sse; |
- unsigned int whichdir = 0; |
int thismse; |
const int y_stride = xd->plane[0].pre[0].stride; |
const int offset = bestmv->row * y_stride + bestmv->col; |
@@ -648,15 +668,16 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
int bc = bestmv->col * 8; |
int hstep = 4; |
int iter, round = 3 - forced_stop; |
- const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); |
- const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); |
- const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); |
- const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); |
+ const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); |
+ const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); |
+ const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); |
+ const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); |
int tr = br; |
int tc = bc; |
const MV *search_step = search_step_table; |
int idx, best_idx = -1; |
unsigned int cost_array[5]; |
+ int kr, kc; |
if (!(allow_hp && vp9_use_mv_hp(ref_mv))) |
if (round == 3) |
@@ -703,8 +724,11 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
} |
// Check diagonal sub-pixel position |
- tc = bc + (cost_array[0] < cost_array[1] ? -hstep : hstep); |
- tr = br + (cost_array[2] < cost_array[3] ? -hstep : hstep); |
+ kc = (cost_array[0] <= cost_array[1] ? -hstep : hstep); |
+ kr = (cost_array[2] <= cost_array[3] ? -hstep : hstep); |
+ |
+ tc = bc + kc; |
+ tr = br + kr; |
if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) { |
const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3); |
MV this_mv = {tr, tc}; |
@@ -735,8 +759,8 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
bc = tc; |
} |
- if (iters_per_step > 1) |
- SECOND_LEVEL_CHECKS; |
+ if (iters_per_step > 1 && best_idx != -1) |
+ SECOND_LEVEL_CHECKS_BEST; |
tr = br; |
tc = bc; |
@@ -1476,7 +1500,7 @@ int vp9_fast_hex_search(const MACROBLOCK *x, |
int use_mvcost, |
const MV *center_mv, |
MV *best_mv) { |
- return vp9_hex_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), |
+ return vp9_hex_search(x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param), |
sad_per_bit, do_init_search, cost_list, vfp, use_mvcost, |
center_mv, best_mv); |
} |
@@ -1491,9 +1515,9 @@ int vp9_fast_dia_search(const MACROBLOCK *x, |
int use_mvcost, |
const MV *center_mv, |
MV *best_mv) { |
- return vp9_bigdia_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), |
- sad_per_bit, do_init_search, cost_list, vfp, |
- use_mvcost, center_mv, best_mv); |
+ return vp9_bigdia_search( |
+ x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param), sad_per_bit, |
+ do_init_search, cost_list, vfp, use_mvcost, center_mv, best_mv); |
} |
#undef CHECK_BETTER |
@@ -1523,10 +1547,10 @@ int vp9_full_range_search_c(const MACROBLOCK *x, |
best_sad = fn_ptr->sdf(what->buf, what->stride, |
get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
- start_row = MAX(-range, x->mv_row_min - ref_mv->row); |
- start_col = MAX(-range, x->mv_col_min - ref_mv->col); |
- end_row = MIN(range, x->mv_row_max - ref_mv->row); |
- end_col = MIN(range, x->mv_col_max - ref_mv->col); |
+ start_row = VPXMAX(-range, x->mv_row_min - ref_mv->row); |
+ start_col = VPXMAX(-range, x->mv_col_min - ref_mv->col); |
+ end_row = VPXMIN(range, x->mv_row_max - ref_mv->row); |
+ end_col = VPXMIN(range, x->mv_col_max - ref_mv->col); |
for (r = start_row; r <= end_row; ++r) { |
for (c = start_col; c <= end_col; c += 4) { |
@@ -1704,7 +1728,7 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, |
} |
} |
break; |
- }; |
+ } |
#endif |
} else if (best_address == in_what) { |
(*num00)++; |
@@ -1997,10 +2021,10 @@ int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv, |
const MACROBLOCKD *const xd = &x->e_mbd; |
const struct buf_2d *const what = &x->plane[0].src; |
const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
- const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
- const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
- const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
- const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min); |
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max); |
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min); |
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max); |
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
int best_sad = fn_ptr->sdf(what->buf, what->stride, |
get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
@@ -2030,10 +2054,10 @@ int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, |
const MACROBLOCKD *const xd = &x->e_mbd; |
const struct buf_2d *const what = &x->plane[0].src; |
const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
- const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
- const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
- const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
- const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min); |
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max); |
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min); |
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max); |
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
@@ -2095,10 +2119,10 @@ int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv, |
const MACROBLOCKD *const xd = &x->e_mbd; |
const struct buf_2d *const what = &x->plane[0].src; |
const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
- const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
- const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
- const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
- const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min); |
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max); |
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min); |
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max); |
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
get_buf_from_mv(in_what, ref_mv), in_what->stride) + |