media/libvpx/vp9/common/vp9_findnearmv.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp9/common/vp9_findnearmv.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +#include "vp9/common/vp9_findnearmv.h"
    1.15 +#include "vp9/common/vp9_mvref_common.h"
    1.16 +
    1.17 +static void lower_mv_precision(MV *mv, int allow_hp) {
    1.18 +  const int use_hp = allow_hp && vp9_use_mv_hp(mv);
    1.19 +  if (!use_hp) {
    1.20 +    if (mv->row & 1)
    1.21 +      mv->row += (mv->row > 0 ? -1 : 1);
    1.22 +    if (mv->col & 1)
    1.23 +      mv->col += (mv->col > 0 ? -1 : 1);
    1.24 +  }
    1.25 +}
    1.26 +
    1.27 +
    1.28 +void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp,
    1.29 +                           int_mv *mvlist, int_mv *nearest, int_mv *near) {
    1.30 +  int i;
    1.31 +  // Make sure all the candidates are properly clamped etc
    1.32 +  for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
    1.33 +    lower_mv_precision(&mvlist[i].as_mv, allow_hp);
    1.34 +    clamp_mv2(&mvlist[i].as_mv, xd);
    1.35 +  }
    1.36 +  *nearest = mvlist[0];
    1.37 +  *near = mvlist[1];
    1.38 +}
    1.39 +
    1.40 +void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
    1.41 +                                   const TileInfo *const tile,
    1.42 +                                   int_mv *dst_nearest,
    1.43 +                                   int_mv *dst_near,
    1.44 +                                   int block_idx, int ref_idx,
    1.45 +                                   int mi_row, int mi_col) {
    1.46 +  int_mv dst_list[MAX_MV_REF_CANDIDATES];
    1.47 +  int_mv mv_list[MAX_MV_REF_CANDIDATES];
    1.48 +  MODE_INFO *const mi = xd->mi_8x8[0];
    1.49 +
    1.50 +  assert(ref_idx == 0 || ref_idx == 1);
    1.51 +  assert(MAX_MV_REF_CANDIDATES == 2);  // makes code here slightly easier
    1.52 +
    1.53 +  vp9_find_mv_refs_idx(cm, xd, tile, mi, xd->last_mi,
    1.54 +                       mi->mbmi.ref_frame[ref_idx],
    1.55 +                       mv_list, block_idx, mi_row, mi_col);
    1.56 +
    1.57 +  dst_list[1].as_int = 0;
    1.58 +  if (block_idx == 0) {
    1.59 +    vpx_memcpy(dst_list, mv_list, MAX_MV_REF_CANDIDATES * sizeof(int_mv));
    1.60 +  } else if (block_idx == 1 || block_idx == 2) {
    1.61 +    int dst = 0, n;
    1.62 +    b_mode_info *bmi = mi->bmi;
    1.63 +
    1.64 +    dst_list[dst++].as_int = bmi[0].as_mv[ref_idx].as_int;
    1.65 +    for (n = 0; dst < MAX_MV_REF_CANDIDATES &&
    1.66 +                n < MAX_MV_REF_CANDIDATES; n++)
    1.67 +      if (mv_list[n].as_int != dst_list[0].as_int)
    1.68 +        dst_list[dst++].as_int = mv_list[n].as_int;
    1.69 +  } else {
    1.70 +    int dst = 0, n;
    1.71 +    b_mode_info *bmi = mi->bmi;
    1.72 +
    1.73 +    assert(block_idx == 3);
    1.74 +    dst_list[dst++].as_int = bmi[2].as_mv[ref_idx].as_int;
    1.75 +    if (dst_list[0].as_int != bmi[1].as_mv[ref_idx].as_int)
    1.76 +      dst_list[dst++].as_int = bmi[1].as_mv[ref_idx].as_int;
    1.77 +    if (dst < MAX_MV_REF_CANDIDATES &&
    1.78 +        dst_list[0].as_int != bmi[0].as_mv[ref_idx].as_int)
    1.79 +      dst_list[dst++].as_int = bmi[0].as_mv[ref_idx].as_int;
    1.80 +    for (n = 0; dst < MAX_MV_REF_CANDIDATES &&
    1.81 +                n < MAX_MV_REF_CANDIDATES; n++)
    1.82 +      if (mv_list[n].as_int != dst_list[0].as_int)
    1.83 +        dst_list[dst++].as_int = mv_list[n].as_int;
    1.84 +  }
    1.85 +
    1.86 +  dst_nearest->as_int = dst_list[0].as_int;
    1.87 +  dst_near->as_int = dst_list[1].as_int;
    1.88 +}

mercurial