diff options
Diffstat (limited to 'vp8/common/findnearmv.c')
-rw-r--r-- | vp8/common/findnearmv.c | 159 |
1 files changed, 98 insertions, 61 deletions
diff --git a/vp8/common/findnearmv.c b/vp8/common/findnearmv.c index 6f7361dd0..235ca46ce 100644 --- a/vp8/common/findnearmv.c +++ b/vp8/common/findnearmv.c @@ -20,15 +20,20 @@ const unsigned char vp8_mbsplit_offset[4][16] = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} }; -static void lower_mv_precision(int_mv *mv) +static void lower_mv_precision(int_mv *mv, int usehp) { - if (mv->as_mv.row & 1) - mv->as_mv.row += (mv->as_mv.row > 0 ? -1 : 1); - if (mv->as_mv.col & 1) - mv->as_mv.col += (mv->as_mv.col > 0 ? -1 : 1); +#if CONFIG_NEWMVENTROPY + if (!usehp || !vp8_use_nmv_hp(&mv->as_mv)) { +#else + if (!usehp) { +#endif + if (mv->as_mv.row & 1) + mv->as_mv.row += (mv->as_mv.row > 0 ? -1 : 1); + if (mv->as_mv.col & 1) + mv->as_mv.col += (mv->as_mv.col > 0 ? -1 : 1); + } } - /* Predict motion vectors using those from already-decoded nearby blocks. Note that we only consider one 4x4 subblock from each candidate 16x16 macroblock. */ @@ -173,11 +178,9 @@ void vp8_find_near_mvs /* Make sure that the 1/8th bits of the Mvs are zero if high_precision * is not being used, by truncating the last bit towards 0 */ - if (!xd->allow_high_precision_mv) { - lower_mv_precision(best_mv); - lower_mv_precision(nearest); - lower_mv_precision(nearby); - } + lower_mv_precision(best_mv, xd->allow_high_precision_mv); + lower_mv_precision(nearest, xd->allow_high_precision_mv); + lower_mv_precision(nearby, xd->allow_high_precision_mv); // TODO: move clamp outside findnearmv vp8_clamp_mv2(nearest, xd); @@ -200,75 +203,109 @@ vp8_prob *vp8_mv_ref_probs(VP8_COMMON *pc, * above and a number cols of pixels in the left to select the one with best * score to use as ref motion vector */ + void vp8_find_best_ref_mvs(MACROBLOCKD *xd, unsigned char *ref_y_buffer, int ref_y_stride, + int_mv *mvlist, int_mv *best_mv, int_mv *nearest, int_mv *near) { - int_mv *ref_mv = xd->ref_mv; - int bestsad = INT_MAX; - int i; + int i, j; unsigned char *above_src; unsigned char *left_src; unsigned char *above_ref; unsigned char *left_ref; int sad; + int sad_scores[MAX_MV_REFS]; + int_mv sorted_mvs[MAX_MV_REFS]; + int zero_seen = FALSE; - above_src = xd->dst.y_buffer - xd->dst.y_stride * 2; - left_src = xd->dst.y_buffer - 2; - above_ref = ref_y_buffer - ref_y_stride * 2; - left_ref = ref_y_buffer - 2; + // Default all to 0,0 if nothing else available + best_mv->as_int = nearest->as_int = near->as_int = 0; + vpx_memset(sorted_mvs, 0, sizeof(sorted_mvs)); - bestsad = vp8_sad16x2_c(above_src, xd->dst.y_stride, - above_ref, ref_y_stride, - INT_MAX); - bestsad += vp8_sad2x16_c(left_src, xd->dst.y_stride, - left_ref, ref_y_stride, - INT_MAX); - best_mv->as_int = 0; + above_src = xd->dst.y_buffer - xd->dst.y_stride * 3; + left_src = xd->dst.y_buffer - 3; + above_ref = ref_y_buffer - ref_y_stride * 3; + left_ref = ref_y_buffer - 3; + //for(i = 0; i < MAX_MV_REFS; ++i) { + // Limit search to the predicted best 4 for(i = 0; i < 4; ++i) { - if (ref_mv[i].as_int) { - int_mv this_mv; - int offset=0; - int row_offset, col_offset; - this_mv.as_int = ref_mv[i].as_int; - vp8_clamp_mv(&this_mv, - xd->mb_to_left_edge - LEFT_TOP_MARGIN + 16, - xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN, - xd->mb_to_top_edge - LEFT_TOP_MARGIN + 16, - xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN); - - row_offset = (this_mv.as_mv.row > 0) ? - ((this_mv.as_mv.row + 3) >> 3):((this_mv.as_mv.row + 4) >> 3); - col_offset = (this_mv.as_mv.col > 0) ? - ((this_mv.as_mv.col + 3) >> 3):((this_mv.as_mv.col + 4) >> 3); - offset = ref_y_stride * row_offset + col_offset; - - sad = vp8_sad16x2_c(above_src, xd->dst.y_stride, - above_ref + offset, ref_y_stride, INT_MAX); - - sad += vp8_sad2x16_c(left_src, xd->dst.y_stride, - left_ref + offset, ref_y_stride, INT_MAX); - - if (sad < bestsad) { - bestsad = sad; - best_mv->as_int = this_mv.as_int; - } + int_mv this_mv; + int offset=0; + int row_offset, col_offset; + + this_mv.as_int = mvlist[i].as_int; + + // If we see a 0,0 vector for a second time we have reached the end of + // the list of valid candidate vectors. + if (!this_mv.as_int) + if (zero_seen) + break; + else + zero_seen = TRUE; + + vp8_clamp_mv(&this_mv, + xd->mb_to_left_edge - LEFT_TOP_MARGIN + 16, + xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN, + xd->mb_to_top_edge - LEFT_TOP_MARGIN + 16, + xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN); + + row_offset = (this_mv.as_mv.row > 0) ? + ((this_mv.as_mv.row + 3) >> 3):((this_mv.as_mv.row + 4) >> 3); + col_offset = (this_mv.as_mv.col > 0) ? + ((this_mv.as_mv.col + 3) >> 3):((this_mv.as_mv.col + 4) >> 3); + offset = ref_y_stride * row_offset + col_offset; + + sad = vp8_sad16x3_c(above_src, xd->dst.y_stride, + above_ref + offset, ref_y_stride, INT_MAX); + + sad += vp8_sad3x16_c(left_src, xd->dst.y_stride, + left_ref + offset, ref_y_stride, INT_MAX); + + // Add the entry to our list and then resort the list on score. + sad_scores[i] = sad; + sorted_mvs[i].as_int = this_mv.as_int; + j = i; + while (j > 0) { + if (sad_scores[j] < sad_scores[j-1]) { + sad_scores[j] = sad_scores[j-1]; + sorted_mvs[j].as_int = sorted_mvs[j-1].as_int; + sad_scores[j-1] = sad; + sorted_mvs[j-1].as_int = this_mv.as_int; + j--; + } else + break; } } - if (!xd->allow_high_precision_mv) - lower_mv_precision(best_mv); - vp8_clamp_mv2(best_mv, xd); + // Set the best mv to the first entry in the sorted list + best_mv->as_int = sorted_mvs[0].as_int; - if (best_mv->as_int != 0 && - (best_mv->as_mv.row >> 3) != (nearest->as_mv.row >>3 ) && - (best_mv->as_mv.col >> 3) != (nearest->as_mv.col >>3 )) { - near->as_int = nearest->as_int; - nearest->as_int = best_mv->as_int; + // Provided that there are non zero vectors available there will not + // be more than one 0,0 entry in the sorted list. + // The best ref mv is always set to the first entry (which gave the best + // results. The nearest is set to the first non zero vector if available and + // near to the second non zero vector if avaialable. + // We do not use 0,0 as a nearest or near as 0,0 has its own mode. + if ( sorted_mvs[0].as_int ) { + nearest->as_int = sorted_mvs[0].as_int; + if ( sorted_mvs[1].as_int ) + near->as_int = sorted_mvs[1].as_int; + else + near->as_int = sorted_mvs[2].as_int; + } else { + nearest->as_int = sorted_mvs[1].as_int; + near->as_int = sorted_mvs[2].as_int; } + + // Copy back the re-ordered mv list + vpx_memcpy(mvlist, sorted_mvs, sizeof(sorted_mvs)); + lower_mv_precision(best_mv, xd->allow_high_precision_mv); + + vp8_clamp_mv2(best_mv, xd); } -#endif +#endif // CONFIG_NEWBESTREFMV |