From c9dfa3f72e7b1d9abcca08c2fb2acd695d78c0cd Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Wed, 30 Apr 2014 15:40:24 -0700 Subject: Cleaning up vp9_full_range_search_c() function. Change-Id: Ifc9114aeacd493cfa04d4cb3d071bf1de80e0568 --- vp9/encoder/vp9_mcomp.c | 110 +++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 66 deletions(-) (limited to 'vp9') diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index bbec4da76..15afa1ab5 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -878,89 +878,67 @@ int vp9_full_range_search_c(const MACROBLOCK *x, const vp9_variance_fn_ptr_t *fn_ptr, const MV *center_mv) { const MACROBLOCKD *const xd = &x->e_mbd; - const uint8_t *what = x->plane[0].src.buf; - const int what_stride = x->plane[0].src.stride; - const uint8_t *in_what; - const int in_what_stride = xd->plane[0].pre[0].stride; - - unsigned int bestsad = INT_MAX; - int ref_row, ref_col; - - unsigned int thissad; + const struct buf_2d *const what = &x->plane[0].src; + const struct buf_2d *const in_what = &xd->plane[0].pre[0]; + const int range = 64; const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; - int tr, tc; - int best_tr = 0; - int best_tc = 0; - int range = 64; - - int start_col, end_col; - int start_row, end_row; - int i; + unsigned int best_sad = INT_MAX; + int r, c, i; + int start_col, end_col, start_row, end_row; clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); - ref_row = ref_mv->row; - ref_col = ref_mv->col; + *best_mv = *ref_mv; *num00 = 11; - best_mv->row = ref_row; - best_mv->col = ref_col; - - // Work out the start point for the search - in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; - - // Check the starting position - bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) - + mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); - - start_row = MAX(-range, x->mv_row_min - ref_row); - start_col = MAX(-range, x->mv_col_min - ref_col); - end_row = MIN(range, x->mv_row_max - ref_row); - end_col = MIN(range, x->mv_col_max - ref_col); - - for (tr = start_row; tr <= end_row; ++tr) { - for (tc = start_col; tc <= end_col; tc += 4) { - if ((tc + 3) <= end_col) { - unsigned int sad_array[4]; - unsigned char const *addr_ref[4]; - for (i = 0; i < 4; ++i) - addr_ref[i] = in_what + tr * in_what_stride + tc + i; + best_sad = fn_ptr->sdf(what->buf, what->stride, + get_buf_from_mv(in_what, ref_mv), in_what->stride, + 0x7fffffff) + + 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); + + for (r = start_row; r <= end_row; ++r) { + for (c = start_col; c <= end_col; c += 4) { + if (c + 3 <= end_col) { + unsigned int sads[4]; + const uint8_t *addrs[4]; + for (i = 0; i < 4; ++i) { + const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; + addrs[i] = get_buf_from_mv(in_what, &mv); + } - fn_ptr->sdx4df(what, what_stride, addr_ref, in_what_stride, sad_array); + fn_ptr->sdx4df(what->buf, what->stride, addrs, in_what->stride, sads); for (i = 0; i < 4; ++i) { - if (sad_array[i] < bestsad) { - const MV this_mv = {ref_row + tr, ref_col + tc + i}; - thissad = sad_array[i] + - mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); - if (thissad < bestsad) { - bestsad = thissad; - best_tr = tr; - best_tc = tc + i; + if (sads[i] < best_sad) { + const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; + const unsigned int sad = sads[i] + + mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); + if (sad < best_sad) { + best_sad = sad; + *best_mv = mv; } } } } else { - for (i = 0; i < end_col - tc; ++i) { - const uint8_t *check_here = in_what + tr * in_what_stride + tc + i; - thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, - bestsad); - - if (thissad < bestsad) { - const MV this_mv = {ref_row + tr, ref_col + tc + i}; - thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); - - if (thissad < bestsad) { - bestsad = thissad; - best_tr = tr; - best_tc = tc + i; + for (i = 0; i < end_col - c; ++i) { + const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; + unsigned int sad = fn_ptr->sdf(what->buf, what->stride, + get_buf_from_mv(in_what, &mv), in_what->stride, best_sad); + if (sad < best_sad) { + sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); + if (sad < best_sad) { + best_sad = sad; + *best_mv = mv; } } } } } } - best_mv->row += best_tr; - best_mv->col += best_tc; - return bestsad; + + return best_sad; } int vp9_diamond_search_sad_c(const MACROBLOCK *x, -- cgit v1.2.3