remove some magic weights associated with sad_per_bit

sad_per_bit has been used for a number of motion vector search routines
with different magic weights: 1, 1/2 and 1/4. This commit remove these
magic numbers and use 1/2 for all motion search routines, also reformat
a number of source code lines to within 80 column limit.

Test on cif set shows overall effect is neutral on all metrics. <=0.01%

Change-Id: I8a382821fa4cffc9c0acf8e8431435a03df74885
This commit is contained in:
Yaowu Xu 2010-06-30 18:58:54 -07:00
Родитель 9e4f76c154
Коммит 50916c6a7d
3 изменённых файлов: 68 добавлений и 30 удалений

Просмотреть файл

@ -875,7 +875,9 @@ int vp8_hex_search
this_offset = base_offset + (br * (d->pre_stride)) + bc; this_offset = base_offset + (br * (d->pre_stride)) + bc;
this_mv.as_mv.row = br; this_mv.as_mv.row = br;
this_mv.as_mv.col = bc; this_mv.as_mv.col = bc;
bestsad = vfp->sdf( what, what_stride, this_offset, in_what_stride, 0x7fffffff) + mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); bestsad = vfp->sdf( what, what_stride, this_offset,
in_what_stride, 0x7fffffff)
+ mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit);
// hex search // hex search
//j=0 //j=0
@ -1062,7 +1064,9 @@ int vp8_diamond_search_sad
(ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max))
{ {
// Check the starting position // Check the starting position
bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); bestsad = fn_ptr->sdf(what, what_stride, in_what,
in_what_stride, 0x7fffffff)
+ mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
} }
// search_param determines the length of the initial step and hence the number of iterations // search_param determines the length of the initial step and hence the number of iterations
@ -1091,7 +1095,8 @@ int vp8_diamond_search_sad
{ {
this_mv.as_mv.row = this_row_offset; this_mv.as_mv.row = this_row_offset;
this_mv.as_mv.col = this_col_offset; this_mv.as_mv.col = this_col_offset;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1182,7 +1187,9 @@ int vp8_diamond_search_sadx4
(ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max))
{ {
// Check the starting position // Check the starting position
bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); bestsad = fn_ptr->sdf(what, what_stride,
in_what, in_what_stride, 0x7fffffff)
+ mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
} }
// search_param determines the length of the initial step and hence the number of iterations // search_param determines the length of the initial step and hence the number of iterations
@ -1222,7 +1229,8 @@ int vp8_diamond_search_sadx4
{ {
this_mv.as_mv.row = best_mv->as_mv.row + ss[i].mv.row; this_mv.as_mv.row = best_mv->as_mv.row + ss[i].mv.row;
this_mv.as_mv.col = best_mv->as_mv.col + ss[i].mv.col; this_mv.as_mv.col = best_mv->as_mv.col + ss[i].mv.col;
sad_array[t] += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); sad_array[t] += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (sad_array[t] < bestsad) if (sad_array[t] < bestsad)
{ {
@ -1251,7 +1259,8 @@ int vp8_diamond_search_sadx4
{ {
this_mv.as_mv.row = this_row_offset; this_mv.as_mv.row = this_row_offset;
this_mv.as_mv.col = this_col_offset; this_mv.as_mv.col = this_col_offset;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1331,7 +1340,9 @@ int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
// Baseline value at the centre // Baseline value at the centre
//bestsad = fn_ptr->sf( what,what_stride,bestaddress,in_what_stride) + (int)sqrt(mv_err_cost(ref_mv,ref_mv, mvcost,error_per_bit*14)); //bestsad = fn_ptr->sf( what,what_stride,bestaddress,in_what_stride) + (int)sqrt(mv_err_cost(ref_mv,ref_mv, mvcost,error_per_bit*14));
bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x7fffffff) + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); bestsad = fn_ptr->sdf(what, what_stride, bestaddress,
in_what_stride, 0x7fffffff)
+ mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
} }
// Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border // Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border
@ -1357,7 +1368,8 @@ int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride, bestsad); thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride, bestsad);
this_mv.as_mv.col = c; this_mv.as_mv.col = c;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1427,7 +1439,9 @@ int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
(ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max))
{ {
// Baseline value at the centre // Baseline value at the centre
bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x7fffffff) + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); bestsad = fn_ptr->sdf(what, what_stride,
bestaddress, in_what_stride, 0x7fffffff)
+ mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
} }
// Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border // Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border
@ -1462,7 +1476,8 @@ int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad) if (thissad < bestsad)
{ {
this_mv.as_mv.col = c; this_mv.as_mv.col = c;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1485,7 +1500,8 @@ int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad) if (thissad < bestsad)
{ {
this_mv.as_mv.col = c; this_mv.as_mv.col = c;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1559,7 +1575,9 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
(ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max))
{ {
// Baseline value at the centre // Baseline value at the centre
bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x7fffffff) + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); bestsad = fn_ptr->sdf(what, what_stride,
bestaddress, in_what_stride, 0x7fffffff)
+ mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit);
} }
// Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border // Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border
@ -1594,7 +1612,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad) if (thissad < bestsad)
{ {
this_mv.as_mv.col = c; this_mv.as_mv.col = c;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1623,7 +1642,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad) if (thissad < bestsad)
{ {
this_mv.as_mv.col = c; this_mv.as_mv.col = c;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {
@ -1646,7 +1666,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad) if (thissad < bestsad)
{ {
this_mv.as_mv.col = c; this_mv.as_mv.col = c;
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); thissad += mvsad_err_cost(&this_mv, &fcenter_mv,
mvsadcost, sad_per_bit);
if (thissad < bestsad) if (thissad < bestsad)
{ {

Просмотреть файл

@ -713,7 +713,7 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
int step_param; int step_param;
int further_steps; int further_steps;
int n = 0; int n = 0;
int sadpb = x->sadperbit16; int sadpb = x->sadperbit16/2;
int col_min; int col_min;
int col_max; int col_max;
@ -760,12 +760,17 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
if (cpi->sf.search_method == HEX) if (cpi->sf.search_method == HEX)
{ {
bestsme = vp8_hex_search(x, b, d, &mvp, &d->bmi.mv, step_param, sadpb/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost, &best_ref_mv); bestsme = vp8_hex_search(x, b, d, &mvp, &d->bmi.mv, step_param,
sadpb, &num00, &cpi->fn_ptr[BLOCK_16X16],
x->mvsadcost, x->mvcost, &best_ref_mv);
mode_mv[NEWMV].as_int = d->bmi.mv.as_int; mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
} }
else else
{ {
bestsme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv, step_param, sadpb / 2/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv); //sadpb < 9 bestsme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv,
step_param, sadpb, &num00,
&cpi->fn_ptr[BLOCK_16X16],
x->mvcost, &best_ref_mv);
mode_mv[NEWMV].as_int = d->bmi.mv.as_int; mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
// Further step/diamond searches as necessary // Further step/diamond searches as necessary
@ -787,7 +792,7 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
cpi->diamond_search_sad(x, b, d, &mvp, cpi->diamond_search_sad(x, b, d, &mvp,
&d->bmi.mv, &d->bmi.mv,
step_param + n, step_param + n,
sadpb / 4, &num00, sadpb, &num00,
&cpi->fn_ptr[BLOCK_16X16], &cpi->fn_ptr[BLOCK_16X16],
x->mvcost, &best_ref_mv); x->mvcost, &best_ref_mv);
if (thissme < bestsme) if (thissme < bestsme)

Просмотреть файл

@ -1131,7 +1131,7 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
{ {
int sadpb = x->sadperbit4; int sadpb = x->sadperbit4/2;
// find first label // find first label
n = vp8_mbsplit_offset[segmentation][i]; n = vp8_mbsplit_offset[segmentation][i];
@ -1142,7 +1142,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
{ {
bestsme = cpi->diamond_search_sad(x, c, e, &bsi->mvp, bestsme = cpi->diamond_search_sad(x, c, e, &bsi->mvp,
&mode_mv[NEW4X4], step_param, &mode_mv[NEW4X4], step_param,
sadpb / 2, &num00, v_fn_ptr, x->mvcost, bsi->ref_mv); sadpb, &num00, v_fn_ptr,
x->mvcost, bsi->ref_mv);
n = num00; n = num00;
num00 = 0; num00 = 0;
@ -1155,9 +1156,11 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
num00--; num00--;
else else
{ {
thissme = cpi->diamond_search_sad(x, c, e, &bsi->mvp, thissme = cpi->diamond_search_sad(x, c, e,
&temp_mv, step_param + n, &bsi->mvp, &temp_mv,
sadpb / 2, &num00, v_fn_ptr, x->mvcost, bsi->ref_mv); step_param + n, sadpb,
&num00, v_fn_ptr,
x->mvcost, bsi->ref_mv);
if (thissme < bestsme) if (thissme < bestsme)
{ {
@ -1179,7 +1182,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
full_mvp.as_mv.col = bsi->mvp.as_mv.col >>3; full_mvp.as_mv.col = bsi->mvp.as_mv.col >>3;
thissme = cpi->full_search_sad(x, c, e, &full_mvp, thissme = cpi->full_search_sad(x, c, e, &full_mvp,
sadpb / 4, 16, v_fn_ptr, x->mvcost, bsi->ref_mv); sadpb, 16, v_fn_ptr,
x->mvcost, bsi->ref_mv);
if (thissme < bestsme) if (thissme < bestsme)
{ {
@ -2034,7 +2038,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int do_refine=1; /* If last step (1-away) of n-step search doesn't pick the center point as the best match, int do_refine=1; /* If last step (1-away) of n-step search doesn't pick the center point as the best match,
we will do a final 1-away diamond refining search */ we will do a final 1-away diamond refining search */
int sadpb = x->sadperbit16; int sadpb = x->sadperbit16/2;
int col_min = (best_ref_mv.as_mv.col - MAX_FULL_PEL_VAL) >>3; int col_min = (best_ref_mv.as_mv.col - MAX_FULL_PEL_VAL) >>3;
int col_max = (best_ref_mv.as_mv.col + MAX_FULL_PEL_VAL) >>3; int col_max = (best_ref_mv.as_mv.col + MAX_FULL_PEL_VAL) >>3;
@ -2062,7 +2066,10 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
// Initial step/diamond search // Initial step/diamond search
{ {
bestsme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv, step_param, sadpb / 2/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv); //sadpb < 9 bestsme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv,
step_param, sadpb, &num00,
&cpi->fn_ptr[BLOCK_16X16],
x->mvcost, &best_ref_mv);
mode_mv[NEWMV].as_int = d->bmi.mv.as_int; mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
// Further step/diamond searches as necessary // Further step/diamond searches as necessary
@ -2084,7 +2091,10 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
num00--; num00--;
else else
{ {
thissme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv, step_param + n, sadpb / 4/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv); //sadpb = 9 thissme = cpi->diamond_search_sad(x, b, d, &mvp,
&d->bmi.mv, step_param + n, sadpb, &num00,
&cpi->fn_ptr[BLOCK_16X16], x->mvcost,
&best_ref_mv);
/* check to see if refining search is needed. */ /* check to see if refining search is needed. */
if (num00 > (further_steps-n)) if (num00 > (further_steps-n))
@ -2113,7 +2123,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
search_range = 8; search_range = 8;
//thissme = cpi->full_search_sad(x, b, d, &d->bmi.mv.as_mv, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv); //thissme = cpi->full_search_sad(x, b, d, &d->bmi.mv.as_mv, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv);
thissme = cpi->refining_search_sad(x, b, d, &d->bmi.mv, sadpb/4, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv); thissme = cpi->refining_search_sad(x, b, d, &d->bmi.mv, sadpb,
search_range, &cpi->fn_ptr[BLOCK_16X16],
x->mvcost, &best_ref_mv);
if (thissme < bestsme) if (thissme < bestsme)
{ {