michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include "vp9/common/vp9_findnearmv.h" michael@0: #include "vp9/common/vp9_mvref_common.h" michael@0: michael@0: static void lower_mv_precision(MV *mv, int allow_hp) { michael@0: const int use_hp = allow_hp && vp9_use_mv_hp(mv); michael@0: if (!use_hp) { michael@0: if (mv->row & 1) michael@0: mv->row += (mv->row > 0 ? -1 : 1); michael@0: if (mv->col & 1) michael@0: mv->col += (mv->col > 0 ? -1 : 1); michael@0: } michael@0: } michael@0: michael@0: michael@0: void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp, michael@0: int_mv *mvlist, int_mv *nearest, int_mv *near) { michael@0: int i; michael@0: // Make sure all the candidates are properly clamped etc michael@0: for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) { michael@0: lower_mv_precision(&mvlist[i].as_mv, allow_hp); michael@0: clamp_mv2(&mvlist[i].as_mv, xd); michael@0: } michael@0: *nearest = mvlist[0]; michael@0: *near = mvlist[1]; michael@0: } michael@0: michael@0: void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, michael@0: const TileInfo *const tile, michael@0: int_mv *dst_nearest, michael@0: int_mv *dst_near, michael@0: int block_idx, int ref_idx, michael@0: int mi_row, int mi_col) { michael@0: int_mv dst_list[MAX_MV_REF_CANDIDATES]; michael@0: int_mv mv_list[MAX_MV_REF_CANDIDATES]; michael@0: MODE_INFO *const mi = xd->mi_8x8[0]; michael@0: michael@0: assert(ref_idx == 0 || ref_idx == 1); michael@0: assert(MAX_MV_REF_CANDIDATES == 2); // makes code here slightly easier michael@0: michael@0: vp9_find_mv_refs_idx(cm, xd, tile, mi, xd->last_mi, michael@0: mi->mbmi.ref_frame[ref_idx], michael@0: mv_list, block_idx, mi_row, mi_col); michael@0: michael@0: dst_list[1].as_int = 0; michael@0: if (block_idx == 0) { michael@0: vpx_memcpy(dst_list, mv_list, MAX_MV_REF_CANDIDATES * sizeof(int_mv)); michael@0: } else if (block_idx == 1 || block_idx == 2) { michael@0: int dst = 0, n; michael@0: b_mode_info *bmi = mi->bmi; michael@0: michael@0: dst_list[dst++].as_int = bmi[0].as_mv[ref_idx].as_int; michael@0: for (n = 0; dst < MAX_MV_REF_CANDIDATES && michael@0: n < MAX_MV_REF_CANDIDATES; n++) michael@0: if (mv_list[n].as_int != dst_list[0].as_int) michael@0: dst_list[dst++].as_int = mv_list[n].as_int; michael@0: } else { michael@0: int dst = 0, n; michael@0: b_mode_info *bmi = mi->bmi; michael@0: michael@0: assert(block_idx == 3); michael@0: dst_list[dst++].as_int = bmi[2].as_mv[ref_idx].as_int; michael@0: if (dst_list[0].as_int != bmi[1].as_mv[ref_idx].as_int) michael@0: dst_list[dst++].as_int = bmi[1].as_mv[ref_idx].as_int; michael@0: if (dst < MAX_MV_REF_CANDIDATES && michael@0: dst_list[0].as_int != bmi[0].as_mv[ref_idx].as_int) michael@0: dst_list[dst++].as_int = bmi[0].as_mv[ref_idx].as_int; michael@0: for (n = 0; dst < MAX_MV_REF_CANDIDATES && michael@0: n < MAX_MV_REF_CANDIDATES; n++) michael@0: if (mv_list[n].as_int != dst_list[0].as_int) michael@0: dst_list[dst++].as_int = mv_list[n].as_int; michael@0: } michael@0: michael@0: dst_nearest->as_int = dst_list[0].as_int; michael@0: dst_near->as_int = dst_list[1].as_int; michael@0: }