2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
12 #ifndef __INC_FINDNEARMV_H
13 #define __INC_FINDNEARMV_H
18 #include "treecoder.h"
21 static void mv_bias(int refmb_ref_frame_sign_bias, int refframe, int_mv *mvp, const int *ref_frame_sign_bias)
26 if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe])
35 #define LEFT_TOP_MARGIN (16 << 3)
36 #define RIGHT_BOTTOM_MARGIN (16 << 3)
37 static void vp8_clamp_mv2(int_mv *mv, const MACROBLOCKD *xd)
39 if (mv->as_mv.col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN))
40 mv->as_mv.col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
41 else if (mv->as_mv.col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN)
42 mv->as_mv.col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
44 if (mv->as_mv.row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN))
45 mv->as_mv.row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
46 else if (mv->as_mv.row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN)
47 mv->as_mv.row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
50 static void vp8_clamp_mv(int_mv *mv, int mb_to_left_edge, int mb_to_right_edge,
51 int mb_to_top_edge, int mb_to_bottom_edge)
53 mv->as_mv.col = (mv->as_mv.col < mb_to_left_edge) ?
54 mb_to_left_edge : mv->as_mv.col;
55 mv->as_mv.col = (mv->as_mv.col > mb_to_right_edge) ?
56 mb_to_right_edge : mv->as_mv.col;
57 mv->as_mv.row = (mv->as_mv.row < mb_to_top_edge) ?
58 mb_to_top_edge : mv->as_mv.row;
59 mv->as_mv.row = (mv->as_mv.row > mb_to_bottom_edge) ?
60 mb_to_bottom_edge : mv->as_mv.row;
62 static unsigned int vp8_check_mv_bounds(int_mv *mv, int mb_to_left_edge,
63 int mb_to_right_edge, int mb_to_top_edge,
64 int mb_to_bottom_edge)
66 unsigned int need_to_clamp;
67 need_to_clamp = (mv->as_mv.col < mb_to_left_edge) ? 1 : 0;
68 need_to_clamp |= (mv->as_mv.col > mb_to_right_edge) ? 1 : 0;
69 need_to_clamp |= (mv->as_mv.row < mb_to_top_edge) ? 1 : 0;
70 need_to_clamp |= (mv->as_mv.row > mb_to_bottom_edge) ? 1 : 0;
74 void vp8_find_near_mvs
77 const MODE_INFO *here,
78 int_mv *nearest, int_mv *nearby, int_mv *best,
79 int near_mv_ref_cts[4],
81 int *ref_frame_sign_bias
84 vp8_prob *vp8_mv_ref_probs(
85 vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
88 extern const unsigned char vp8_mbsplit_offset[4][16];
91 static int left_block_mv(const MODE_INFO *cur_mb, int b)
95 /* On L edge, get from MB to left of us */
98 if(cur_mb->mbmi.mode != SPLITMV)
99 return cur_mb->mbmi.mv.as_int;
103 return (cur_mb->bmi + b - 1)->mv.as_int;
106 static int above_block_mv(const MODE_INFO *cur_mb, int b, int mi_stride)
110 /* On top edge, get from MB above us */
113 if(cur_mb->mbmi.mode != SPLITMV)
114 return cur_mb->mbmi.mv.as_int;
118 return (cur_mb->bmi + b - 4)->mv.as_int;
120 static B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b)
124 /* On L edge, get from MB to left of us */
129 return (cur_mb->bmi + b - 1)->as_mode;
132 static B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b, int mi_stride)
136 /* On top edge, get from MB above us */
141 return (cur_mb->bmi + b - 4)->as_mode;