Cleaning up vp9_full_search_sadx3().

Change-Id: Ia63fee65c827fd33080119184e6cf3167421807c
This commit is contained in:
Dmitry Kovalev 2014-04-14 11:13:33 -07:00
parent 07dddfa3fd
commit 6733ad19e1

View File

@ -1290,84 +1290,65 @@ int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv,
int sad_per_bit, int distance,
const vp9_variance_fn_ptr_t *fn_ptr,
const MV *center_mv, MV *best_mv) {
int r;
const MACROBLOCKD *const xd = &x->e_mbd;
const uint8_t *const what = x->plane[0].src.buf;
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
MV this_mv;
unsigned int bestsad = INT_MAX;
int r, c;
unsigned int thissad;
int ref_row = ref_mv->row;
int ref_col = ref_mv->col;
// Apply further limits to prevent us looking using vectors that stretch
// beyond the UMV border
const int row_min = MAX(ref_row - distance, x->mv_row_min);
const int row_max = MIN(ref_row + distance, x->mv_row_max);
const int col_min = MAX(ref_col - distance, x->mv_col_min);
const int col_max = MIN(ref_col + distance, x->mv_col_max);
unsigned int sad_array[3];
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 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, 0x7fffffff) +
mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
*best_mv = *ref_mv;
// Work out the mid point for the search
const uint8_t *bestaddress = &in_what[ref_row * in_what_stride + ref_col];
for (r = row_min; r < row_max; ++r) {
int c = col_min;
const uint8_t *check_here = &in_what->buf[r * in_what->stride + c];
best_mv->row = ref_row;
best_mv->col = ref_col;
if (fn_ptr->sdx3f != NULL) {
while ((c + 2) < col_max) {
int i;
unsigned int sads[3];
// Baseline value at the centre
bestsad = fn_ptr->sdf(what, what_stride,
bestaddress, in_what_stride, 0x7fffffff)
+ mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit);
fn_ptr->sdx3f(what->buf, what->stride, check_here, in_what->stride,
sads);
for (r = row_min; r < row_max; r++) {
const uint8_t *check_here = &in_what[r * in_what_stride + col_min];
this_mv.row = r;
c = col_min;
while ((c + 2) < col_max && fn_ptr->sdx3f != NULL) {
int i;
fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array);
for (i = 0; i < 3; i++) {
thissad = sad_array[i];
if (thissad < bestsad) {
this_mv.col = c;
thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
if (thissad < bestsad) {
bestsad = thissad;
best_mv->row = r;
best_mv->col = c;
for (i = 0; i < 3; ++i) {
unsigned int sad = sads[i];
if (sad < best_sad) {
const MV mv = {r, c};
sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
*best_mv = mv;
}
}
++check_here;
++c;
}
check_here++;
c++;
}
}
while (c < col_max) {
thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
bestsad);
if (thissad < bestsad) {
this_mv.col = c;
thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
if (thissad < bestsad) {
bestsad = thissad;
best_mv->row = r;
best_mv->col = c;
unsigned int sad = fn_ptr->sdf(what->buf, what->stride,
check_here, in_what->stride, best_sad);
if (sad < best_sad) {
const MV mv = {r, c};
sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
*best_mv = mv;
}
}
check_here++;
c++;
++check_here;
++c;
}
}
return bestsad;
return best_sad;
}
int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv,