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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "findnearmv.h"
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
const unsigned char vp8_mbsplit_offset[4][16] = {
|
|
|
|
{ 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
{ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
{ 0, 2, 8, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
|
|
|
|
};
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
/* Predict motion vectors using those from already-decoded nearby blocks.
|
|
|
|
Note that we only consider one 4x4 subblock from each candidate 16x16
|
|
|
|
macroblock. */
|
2011-11-16 01:16:30 +01:00
|
|
|
#if CONFIG_NEWNEAR
|
2010-05-18 17:58:33 +02:00
|
|
|
void vp8_find_near_mvs
|
|
|
|
(
|
|
|
|
MACROBLOCKD *xd,
|
|
|
|
const MODE_INFO *here,
|
2011-11-16 01:16:30 +01:00
|
|
|
const MODE_INFO *lf_here,
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv *nearest,
|
|
|
|
int_mv *nearby,
|
|
|
|
int_mv *best_mv,
|
2010-05-18 17:58:33 +02:00
|
|
|
int cnt[4],
|
|
|
|
int refframe,
|
|
|
|
int *ref_frame_sign_bias
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const MODE_INFO *above = here - xd->mode_info_stride;
|
|
|
|
const MODE_INFO *left = here - 1;
|
|
|
|
const MODE_INFO *aboveleft = above - 1;
|
2011-11-16 01:16:30 +01:00
|
|
|
const MODE_INFO *third = NULL;
|
2010-05-18 17:58:33 +02:00
|
|
|
int_mv near_mvs[4];
|
|
|
|
int_mv *mv = near_mvs;
|
|
|
|
int *cntx = cnt;
|
|
|
|
enum {CNT_INTRA, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
|
|
|
|
|
|
|
|
/* Zero accumulators */
|
|
|
|
mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
|
|
|
|
cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
|
|
|
|
|
|
|
|
/* Process above */
|
|
|
|
if (above->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if (above->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
(++mv)->as_int = above->mbmi.mv.as_int;
|
2011-08-05 01:30:27 +02:00
|
|
|
mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame],
|
|
|
|
refframe, mv, ref_frame_sign_bias);
|
2010-05-18 17:58:33 +02:00
|
|
|
++cntx;
|
|
|
|
}
|
2011-11-16 01:16:30 +01:00
|
|
|
*cntx += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process left */
|
|
|
|
if (left->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if (left->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
int_mv this_mv;
|
|
|
|
this_mv.as_int = left->mbmi.mv.as_int;
|
|
|
|
mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame],
|
|
|
|
refframe, &this_mv, ref_frame_sign_bias);
|
|
|
|
|
|
|
|
if (this_mv.as_int != mv->as_int)
|
|
|
|
{
|
|
|
|
(++mv)->as_int = this_mv.as_int;
|
|
|
|
++cntx;
|
|
|
|
}
|
|
|
|
*cntx += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cnt[CNT_INTRA] += 2;
|
|
|
|
}
|
|
|
|
/* Process above left or the one frome last frame */
|
|
|
|
if ( aboveleft->mbmi.ref_frame != INTRA_FRAME||
|
|
|
|
(lf_here->mbmi.ref_frame==LAST_FRAME && refframe == LAST_FRAME))
|
|
|
|
{
|
|
|
|
if (aboveleft->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
third = aboveleft;
|
|
|
|
}
|
|
|
|
else if(lf_here->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
third = lf_here;
|
|
|
|
}
|
|
|
|
if(third)
|
|
|
|
{
|
|
|
|
int_mv this_mv;
|
|
|
|
this_mv.as_int = third->mbmi.mv.as_int;
|
|
|
|
mv_bias(ref_frame_sign_bias[third->mbmi.ref_frame],
|
|
|
|
refframe, &this_mv, ref_frame_sign_bias);
|
|
|
|
|
|
|
|
if (this_mv.as_int != mv->as_int)
|
|
|
|
{
|
|
|
|
(++mv)->as_int = this_mv.as_int;
|
|
|
|
++cntx;
|
|
|
|
}
|
|
|
|
*cntx += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cnt[CNT_INTRA] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have three distinct MV's ... */
|
|
|
|
if (cnt[CNT_SPLITMV])
|
|
|
|
{
|
|
|
|
/* See if the third MV can be merged with NEAREST */
|
|
|
|
if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
|
|
|
|
cnt[CNT_NEAREST] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
|
|
|
|
+ (left->mbmi.mode == SPLITMV)) * 2
|
|
|
|
+ (
|
|
|
|
#if CONFIG_NEWNEAR
|
|
|
|
lf_here->mbmi.mode == SPLITMV ||
|
|
|
|
#endif
|
|
|
|
aboveleft->mbmi.mode == SPLITMV);
|
|
|
|
|
|
|
|
/* Swap near and nearest if necessary */
|
|
|
|
if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
tmp = cnt[CNT_NEAREST];
|
|
|
|
cnt[CNT_NEAREST] = cnt[CNT_NEAR];
|
|
|
|
cnt[CNT_NEAR] = tmp;
|
|
|
|
tmp = near_mvs[CNT_NEAREST].as_int;
|
|
|
|
near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
|
|
|
|
near_mvs[CNT_NEAR].as_int = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use near_mvs[0] to store the "best" MV */
|
|
|
|
if (cnt[CNT_NEAREST] >= cnt[CNT_INTRA])
|
|
|
|
near_mvs[CNT_INTRA] = near_mvs[CNT_NEAREST];
|
|
|
|
|
|
|
|
/* Set up return values */
|
|
|
|
best_mv->as_int = near_mvs[0].as_int;
|
|
|
|
nearest->as_int = near_mvs[CNT_NEAREST].as_int;
|
|
|
|
nearby->as_int = near_mvs[CNT_NEAR].as_int;
|
|
|
|
|
|
|
|
//TODO: move clamp outside findnearmv
|
|
|
|
vp8_clamp_mv2(nearest, xd);
|
|
|
|
vp8_clamp_mv2(nearby, xd);
|
|
|
|
vp8_clamp_mv2(best_mv, xd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
void vp8_find_near_mvs
|
|
|
|
(
|
|
|
|
MACROBLOCKD *xd,
|
|
|
|
const MODE_INFO *here,
|
|
|
|
int_mv *nearest,
|
|
|
|
int_mv *nearby,
|
|
|
|
int_mv *best_mv,
|
|
|
|
int cnt[4],
|
|
|
|
int refframe,
|
|
|
|
int *ref_frame_sign_bias
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const MODE_INFO *above = here - xd->mode_info_stride;
|
|
|
|
const MODE_INFO *left = here - 1;
|
|
|
|
const MODE_INFO *aboveleft = above - 1;
|
|
|
|
int_mv near_mvs[4];
|
|
|
|
int_mv *mv = near_mvs;
|
|
|
|
int *cntx = cnt;
|
2011-12-06 16:09:08 +01:00
|
|
|
enum {CNT_ZEROMV, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
/* Zero accumulators */
|
|
|
|
mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
|
|
|
|
cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
|
|
|
|
|
|
|
|
/* Process above */
|
|
|
|
if (above->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if (above->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
(++mv)->as_int = above->mbmi.mv.as_int;
|
|
|
|
mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame],
|
|
|
|
refframe, mv, ref_frame_sign_bias);
|
|
|
|
++cntx;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
*cntx += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process left */
|
|
|
|
if (left->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if (left->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
int_mv this_mv;
|
|
|
|
|
|
|
|
this_mv.as_int = left->mbmi.mv.as_int;
|
2011-08-05 01:30:27 +02:00
|
|
|
mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame],
|
|
|
|
refframe, &this_mv, ref_frame_sign_bias);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (this_mv.as_int != mv->as_int)
|
|
|
|
{
|
|
|
|
(++mv)->as_int = this_mv.as_int;
|
|
|
|
++cntx;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cntx += 2;
|
|
|
|
}
|
|
|
|
else
|
2011-12-06 16:09:08 +01:00
|
|
|
cnt[CNT_ZEROMV] += 2;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
/* Process above left */
|
|
|
|
if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if (aboveleft->mbmi.mv.as_int)
|
|
|
|
{
|
|
|
|
int_mv this_mv;
|
|
|
|
|
|
|
|
this_mv.as_int = aboveleft->mbmi.mv.as_int;
|
2011-08-05 01:30:27 +02:00
|
|
|
mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame],
|
|
|
|
refframe, &this_mv, ref_frame_sign_bias);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (this_mv.as_int != mv->as_int)
|
|
|
|
{
|
|
|
|
(++mv)->as_int = this_mv.as_int;
|
|
|
|
++cntx;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cntx += 1;
|
|
|
|
}
|
|
|
|
else
|
2011-12-06 16:09:08 +01:00
|
|
|
cnt[CNT_ZEROMV] += 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have three distinct MV's ... */
|
|
|
|
if (cnt[CNT_SPLITMV])
|
|
|
|
{
|
|
|
|
/* See if above-left MV can be merged with NEAREST */
|
|
|
|
if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
|
|
|
|
cnt[CNT_NEAREST] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
|
|
|
|
+ (left->mbmi.mode == SPLITMV)) * 2
|
|
|
|
+ (aboveleft->mbmi.mode == SPLITMV);
|
|
|
|
|
|
|
|
/* Swap near and nearest if necessary */
|
|
|
|
if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
tmp = cnt[CNT_NEAREST];
|
|
|
|
cnt[CNT_NEAREST] = cnt[CNT_NEAR];
|
|
|
|
cnt[CNT_NEAR] = tmp;
|
|
|
|
tmp = near_mvs[CNT_NEAREST].as_int;
|
|
|
|
near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
|
|
|
|
near_mvs[CNT_NEAR].as_int = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use near_mvs[0] to store the "best" MV */
|
2011-12-06 16:09:08 +01:00
|
|
|
if (cnt[CNT_NEAREST] >= cnt[CNT_ZEROMV])
|
|
|
|
near_mvs[CNT_ZEROMV] = near_mvs[CNT_NEAREST];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
/* Set up return values */
|
2011-05-12 16:50:16 +02:00
|
|
|
best_mv->as_int = near_mvs[0].as_int;
|
|
|
|
nearest->as_int = near_mvs[CNT_NEAREST].as_int;
|
|
|
|
nearby->as_int = near_mvs[CNT_NEAR].as_int;
|
|
|
|
|
|
|
|
//TODO: move clamp outside findnearmv
|
|
|
|
vp8_clamp_mv2(nearest, xd);
|
|
|
|
vp8_clamp_mv2(nearby, xd);
|
|
|
|
vp8_clamp_mv2(best_mv, xd);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-11-16 01:16:30 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
vp8_prob *vp8_mv_ref_probs(
|
|
|
|
vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
|
|
|
|
)
|
|
|
|
{
|
|
|
|
p[0] = vp8_mode_contexts [near_mv_ref_ct[0]] [0];
|
|
|
|
p[1] = vp8_mode_contexts [near_mv_ref_ct[1]] [1];
|
|
|
|
p[2] = vp8_mode_contexts [near_mv_ref_ct[2]] [2];
|
|
|
|
p[3] = vp8_mode_contexts [near_mv_ref_ct[3]] [3];
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|