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_mv.as_mv.row = br;
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
//j=0
@ -1062,7 +1064,9 @@ int vp8_diamond_search_sad
(ref_row > x->mv_row_min) && (ref_row < x->mv_row_max))
{
// 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
@ -1091,7 +1095,8 @@ int vp8_diamond_search_sad
{
this_mv.as_mv.row = this_row_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)
{
@ -1182,7 +1187,9 @@ int vp8_diamond_search_sadx4
(ref_row > x->mv_row_min) && (ref_row < x->mv_row_max))
{
// 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
@ -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.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)
{
@ -1251,7 +1259,8 @@ int vp8_diamond_search_sadx4
{
this_mv.as_mv.row = this_row_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)
{
@ -1331,7 +1340,9 @@ int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
// 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->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
@ -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);
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)
{
@ -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))
{
// 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
@ -1462,7 +1476,8 @@ int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad)
{
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)
{
@ -1485,7 +1500,8 @@ int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad)
{
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)
{
@ -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))
{
// 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
@ -1594,7 +1612,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad)
{
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)
{
@ -1623,7 +1642,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad)
{
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)
{
@ -1646,7 +1666,8 @@ int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv,
if (thissad < bestsad)
{
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)
{

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

@ -713,7 +713,7 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
int step_param;
int further_steps;
int n = 0;
int sadpb = x->sadperbit16;
int sadpb = x->sadperbit16/2;
int col_min;
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)
{
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;
}
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;
// 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,
&d->bmi.mv,
step_param + n,
sadpb / 4, &num00,
sadpb, &num00,
&cpi->fn_ptr[BLOCK_16X16],
x->mvcost, &best_ref_mv);
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;
{
int sadpb = x->sadperbit4;
int sadpb = x->sadperbit4/2;
// find first label
n = vp8_mbsplit_offset[segmentation][i];
@ -1141,8 +1141,9 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
{
bestsme = cpi->diamond_search_sad(x, c, e, &bsi->mvp,
&mode_mv[NEW4X4], step_param,
sadpb / 2, &num00, v_fn_ptr, x->mvcost, bsi->ref_mv);
&mode_mv[NEW4X4], step_param,
sadpb, &num00, v_fn_ptr,
x->mvcost, bsi->ref_mv);
n = num00;
num00 = 0;
@ -1155,9 +1156,11 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
num00--;
else
{
thissme = cpi->diamond_search_sad(x, c, e, &bsi->mvp,
&temp_mv, step_param + n,
sadpb / 2, &num00, v_fn_ptr, x->mvcost, bsi->ref_mv);
thissme = cpi->diamond_search_sad(x, c, e,
&bsi->mvp, &temp_mv,
step_param + n, sadpb,
&num00, v_fn_ptr,
x->mvcost, bsi->ref_mv);
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;
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)
{
@ -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,
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_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
{
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;
// 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--;
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. */
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;
//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)
{