2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_findnearmv.h"
|
2013-05-26 23:40:49 +02:00
|
|
|
#include "vp9/common/vp9_mvref_common.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-08-06 01:27:51 +02:00
|
|
|
static void lower_mv_precision(MV *mv, int allow_hp) {
|
|
|
|
const int use_hp = allow_hp && vp9_use_mv_hp(mv);
|
2013-08-02 20:21:16 +02:00
|
|
|
if (!use_hp) {
|
2013-08-06 01:27:51 +02:00
|
|
|
if (mv->row & 1)
|
|
|
|
mv->row += (mv->row > 0 ? -1 : 1);
|
|
|
|
if (mv->col & 1)
|
|
|
|
mv->col += (mv->col > 0 ? -1 : 1);
|
2012-09-06 18:07:42 +02:00
|
|
|
}
|
2012-08-06 19:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 00:49:15 +01:00
|
|
|
void vp9_find_best_ref_mvs(MACROBLOCKD *xd,
|
|
|
|
int_mv *mvlist,
|
|
|
|
int_mv *nearest,
|
|
|
|
int_mv *near) {
|
|
|
|
int i;
|
|
|
|
// Make sure all the candidates are properly clamped etc
|
|
|
|
for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
|
2013-08-06 01:27:51 +02:00
|
|
|
lower_mv_precision(&mvlist[i].as_mv, xd->allow_high_precision_mv);
|
2013-08-01 01:11:03 +02:00
|
|
|
clamp_mv2(&mvlist[i].as_mv, xd);
|
2013-03-13 00:49:15 +01:00
|
|
|
}
|
|
|
|
*nearest = mvlist[0];
|
|
|
|
*near = mvlist[1];
|
|
|
|
}
|
2013-05-26 23:40:49 +02:00
|
|
|
|
|
|
|
void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
|
|
|
|
int_mv *dst_nearest,
|
|
|
|
int_mv *dst_near,
|
2013-07-31 20:58:00 +02:00
|
|
|
int block_idx, int ref_idx,
|
|
|
|
int mi_row, int mi_col) {
|
2013-05-26 23:40:49 +02:00
|
|
|
int_mv dst_list[MAX_MV_REF_CANDIDATES];
|
|
|
|
int_mv mv_list[MAX_MV_REF_CANDIDATES];
|
2013-10-10 21:11:44 +02:00
|
|
|
MODE_INFO *const mi = xd->mi_8x8[0];
|
2013-05-26 23:40:49 +02:00
|
|
|
|
|
|
|
assert(ref_idx == 0 || ref_idx == 1);
|
|
|
|
assert(MAX_MV_REF_CANDIDATES == 2); // makes code here slightly easier
|
|
|
|
|
2013-09-11 19:45:44 +02:00
|
|
|
vp9_find_mv_refs_idx(cm, xd, mi, xd->last_mi,
|
2013-08-23 21:00:14 +02:00
|
|
|
mi->mbmi.ref_frame[ref_idx],
|
|
|
|
mv_list, block_idx, mi_row, mi_col);
|
2013-05-26 23:40:49 +02:00
|
|
|
|
|
|
|
dst_list[1].as_int = 0;
|
|
|
|
if (block_idx == 0) {
|
2013-09-24 18:07:08 +02:00
|
|
|
vpx_memcpy(dst_list, mv_list, MAX_MV_REF_CANDIDATES * sizeof(int_mv));
|
2013-05-26 23:40:49 +02:00
|
|
|
} else if (block_idx == 1 || block_idx == 2) {
|
|
|
|
int dst = 0, n;
|
2013-10-03 02:05:31 +02:00
|
|
|
b_mode_info *bmi = mi->bmi;
|
2013-05-26 23:40:49 +02:00
|
|
|
|
|
|
|
dst_list[dst++].as_int = bmi[0].as_mv[ref_idx].as_int;
|
|
|
|
for (n = 0; dst < MAX_MV_REF_CANDIDATES &&
|
|
|
|
n < MAX_MV_REF_CANDIDATES; n++)
|
|
|
|
if (mv_list[n].as_int != dst_list[0].as_int)
|
|
|
|
dst_list[dst++].as_int = mv_list[n].as_int;
|
|
|
|
} else {
|
|
|
|
int dst = 0, n;
|
2013-10-03 02:05:31 +02:00
|
|
|
b_mode_info *bmi = mi->bmi;
|
2013-05-26 23:40:49 +02:00
|
|
|
|
|
|
|
assert(block_idx == 3);
|
|
|
|
dst_list[dst++].as_int = bmi[2].as_mv[ref_idx].as_int;
|
|
|
|
if (dst_list[0].as_int != bmi[1].as_mv[ref_idx].as_int)
|
|
|
|
dst_list[dst++].as_int = bmi[1].as_mv[ref_idx].as_int;
|
|
|
|
if (dst < MAX_MV_REF_CANDIDATES &&
|
|
|
|
dst_list[0].as_int != bmi[0].as_mv[ref_idx].as_int)
|
|
|
|
dst_list[dst++].as_int = bmi[0].as_mv[ref_idx].as_int;
|
|
|
|
for (n = 0; dst < MAX_MV_REF_CANDIDATES &&
|
|
|
|
n < MAX_MV_REF_CANDIDATES; n++)
|
|
|
|
if (mv_list[n].as_int != dst_list[0].as_int)
|
|
|
|
dst_list[dst++].as_int = mv_list[n].as_int;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_nearest->as_int = dst_list[0].as_int;
|
|
|
|
dst_near->as_int = dst_list[1].as_int;
|
|
|
|
}
|