Cleaning up vp9_diamond_search_sad_c() function.

Change-Id: I0816ec12ec0a6f21d0f25f10c214b5fd327afc6c
This commit is contained in:
Dmitry Kovalev 2014-04-07 16:28:35 -07:00
parent 8eec5cad50
commit 9243edc737

View File

@ -981,66 +981,49 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x,
const vp9_variance_fn_ptr_t *fn_ptr, const vp9_variance_fn_ptr_t *fn_ptr,
int *mvjcost, int *mvcost[2], int *mvjcost, int *mvcost[2],
const MV *center_mv) { const MV *center_mv) {
int i, j, step;
const MACROBLOCKD *const xd = &x->e_mbd; const MACROBLOCKD *const xd = &x->e_mbd;
const uint8_t *what = x->plane[0].src.buf; const struct buf_2d *const what = &x->plane[0].src;
const int what_stride = x->plane[0].src.stride; const struct buf_2d *const in_what = &xd->plane[0].pre[0];
const uint8_t *in_what;
const int in_what_stride = xd->plane[0].pre[0].stride;
const uint8_t *best_address;
int bestsad = INT_MAX;
int best_site = 0;
int last_site = 0;
int ref_row, ref_col;
// search_param determines the length of the initial step and hence the number // search_param determines the length of the initial step and hence the number
// of iterations // of iterations
// 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 =
// (MAX_FIRST_STEP/4) pel... etc. // (MAX_FIRST_STEP/4) pel... etc.
const search_site *const ss = &x->ss[search_param * x->searches_per_step]; const search_site *const ss = &x->ss[search_param * x->searches_per_step];
const int tot_steps = (x->ss_count / x->searches_per_step) - search_param; const int tot_steps = (x->ss_count / x->searches_per_step) - search_param;
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
const int *mvjsadcost = x->nmvjointsadcost; const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
const uint8_t *best_address;
int best_sad = INT_MAX;
int best_site = 0;
int last_site = 0;
int i, j, step;
clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); 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; best_address = get_buf_from_mv(in_what, ref_mv);
ref_col = ref_mv->col;
*num00 = 0; *num00 = 0;
best_mv->row = ref_row; *best_mv = *ref_mv;
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;
best_address = in_what;
// Check the starting position // Check the starting position
bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) best_sad = fn_ptr->sdf(what->buf, what->stride,
+ mvsad_err_cost(best_mv, &fcenter_mv, in_what->buf, in_what->stride, 0x7fffffff) +
mvjsadcost, mvsadcost, sad_per_bit); mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, sad_per_bit);
i = 1; i = 1;
for (step = 0; step < tot_steps; step++) { for (step = 0; step < tot_steps; step++) {
for (j = 0; j < x->searches_per_step; j++) { for (j = 0; j < x->searches_per_step; j++) {
const MV this_mv = {best_mv->row + ss[i].mv.row, const MV mv = {best_mv->row + ss[i].mv.row,
best_mv->col + ss[i].mv.col}; best_mv->col + ss[i].mv.col};
if (is_mv_in(x, &this_mv)) { if (is_mv_in(x, &mv)) {
const uint8_t *const check_here = ss[i].offset + best_address; int sad = fn_ptr->sdf(what->buf, what->stride,
int thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, best_address + ss[i].offset, in_what->stride,
bestsad); best_sad);
if (sad < best_sad) {
if (thissad < bestsad) { sad += mvsad_err_cost(&mv, &fcenter_mv, mvjsadcost, mvsadcost,
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, sad_per_bit);
mvjsadcost, mvsadcost, sad_per_bit); if (sad < best_sad) {
best_sad = sad;
if (thissad < bestsad) {
bestsad = thissad;
best_site = i; best_site = i;
} }
} }
@ -1059,14 +1042,14 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x,
const MV this_mv = {best_mv->row + ss[best_site].mv.row, const MV this_mv = {best_mv->row + ss[best_site].mv.row,
best_mv->col + ss[best_site].mv.col}; best_mv->col + ss[best_site].mv.col};
if (is_mv_in(x, &this_mv)) { if (is_mv_in(x, &this_mv)) {
const uint8_t *const check_here = ss[best_site].offset + best_address; int sad = fn_ptr->sdf(what->buf, what->stride,
int thissad = fn_ptr->sdf(what, what_stride, check_here, best_address + ss[best_site].offset,
in_what_stride, bestsad); in_what->stride, best_sad);
if (thissad < bestsad) { if (sad < best_sad) {
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, sad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit); mvjsadcost, mvsadcost, sad_per_bit);
if (thissad < bestsad) { if (sad < best_sad) {
bestsad = thissad; best_sad = sad;
best_mv->row += ss[best_site].mv.row; best_mv->row += ss[best_site].mv.row;
best_mv->col += ss[best_site].mv.col; best_mv->col += ss[best_site].mv.col;
best_address += ss[best_site].offset; best_address += ss[best_site].offset;
@ -1077,11 +1060,11 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x,
break; break;
}; };
#endif #endif
} else if (best_address == in_what) { } else if (best_address == in_what->buf) {
(*num00)++; (*num00)++;
} }
} }
return bestsad; return best_sad;
} }
int vp9_diamond_search_sadx4(const MACROBLOCK *x, int vp9_diamond_search_sadx4(const MACROBLOCK *x,