Commit 9243edc7 authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Cleaning up vp9_diamond_search_sad_c() function.

Change-Id: I0816ec12ec0a6f21d0f25f10c214b5fd327afc6c
parent 8eec5cad
......@@ -981,66 +981,49 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x,
const vp9_variance_fn_ptr_t *fn_ptr,
int *mvjcost, int *mvcost[2],
const MV *center_mv) {
int i, j, step;
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;
const uint8_t *best_address;
int bestsad = INT_MAX;
int best_site = 0;
int last_site = 0;
int ref_row, ref_col;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
// search_param determines the length of the initial step and hence the number
// of iterations
// 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 =
// (MAX_FIRST_STEP/4) pel... etc.
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 MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
const int *mvjsadcost = x->nmvjointsadcost;
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);
ref_row = ref_mv->row;
ref_col = ref_mv->col;
best_address = get_buf_from_mv(in_what, ref_mv);
*num00 = 0;
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;
best_address = in_what;
*best_mv = *ref_mv;
// Check the starting position
bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff)
+ mvsad_err_cost(best_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
best_sad = fn_ptr->sdf(what->buf, what->stride,
in_what->buf, in_what->stride, 0x7fffffff) +
mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, sad_per_bit);
i = 1;
for (step = 0; step < tot_steps; step++) {
for (j = 0; j < x->searches_per_step; j++) {
const MV this_mv = {best_mv->row + ss[i].mv.row,
best_mv->col + ss[i].mv.col};
if (is_mv_in(x, &this_mv)) {
const uint8_t *const check_here = ss[i].offset + best_address;
int thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
bestsad);
if (thissad < bestsad) {
thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
if (thissad < bestsad) {
bestsad = thissad;
const MV mv = {best_mv->row + ss[i].mv.row,
best_mv->col + ss[i].mv.col};
if (is_mv_in(x, &mv)) {
int sad = fn_ptr->sdf(what->buf, what->stride,
best_address + ss[i].offset, in_what->stride,
best_sad);
if (sad < best_sad) {
sad += mvsad_err_cost(&mv, &fcenter_mv, mvjsadcost, mvsadcost,
sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
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,
best_mv->col + ss[best_site].mv.col};
if (is_mv_in(x, &this_mv)) {
const uint8_t *const check_here = ss[best_site].offset + best_address;
int thissad = fn_ptr->sdf(what, what_stride, check_here,
in_what_stride, bestsad);
if (thissad < bestsad) {
thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
if (thissad < bestsad) {
bestsad = thissad;
int sad = fn_ptr->sdf(what->buf, what->stride,
best_address + ss[best_site].offset,
in_what->stride, best_sad);
if (sad < best_sad) {
sad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
best_mv->row += ss[best_site].mv.row;
best_mv->col += ss[best_site].mv.col;
best_address += ss[best_site].offset;
......@@ -1077,11 +1060,11 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x,
break;
};
#endif
} else if (best_address == in_what) {
} else if (best_address == in_what->buf) {
(*num00)++;
}
}
return bestsad;
return best_sad;
}
int vp9_diamond_search_sadx4(const MACROBLOCK *x,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment