1/* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 12#ifndef VP8_COMMON_FINDNEARMV_H_ 13#define VP8_COMMON_FINDNEARMV_H_ 14 15#include "./vpx_config.h" 16#include "mv.h" 17#include "blockd.h" 18#include "modecont.h" 19#include "treecoder.h" 20 21#ifdef __cplusplus 22extern "C" { 23#endif 24 25 26static INLINE void mv_bias(int refmb_ref_frame_sign_bias, int refframe, 27 int_mv *mvp, const int *ref_frame_sign_bias) 28{ 29 if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe]) 30 { 31 mvp->as_mv.row *= -1; 32 mvp->as_mv.col *= -1; 33 } 34} 35 36#define LEFT_TOP_MARGIN (16 << 3) 37#define RIGHT_BOTTOM_MARGIN (16 << 3) 38static INLINE void vp8_clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) 39{ 40 if (mv->as_mv.col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN)) 41 mv->as_mv.col = xd->mb_to_left_edge - LEFT_TOP_MARGIN; 42 else if (mv->as_mv.col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN) 43 mv->as_mv.col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN; 44 45 if (mv->as_mv.row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN)) 46 mv->as_mv.row = xd->mb_to_top_edge - LEFT_TOP_MARGIN; 47 else if (mv->as_mv.row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN) 48 mv->as_mv.row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; 49} 50 51static INLINE void vp8_clamp_mv(int_mv *mv, int mb_to_left_edge, 52 int mb_to_right_edge, int mb_to_top_edge, 53 int mb_to_bottom_edge) 54{ 55 mv->as_mv.col = (mv->as_mv.col < mb_to_left_edge) ? 56 mb_to_left_edge : mv->as_mv.col; 57 mv->as_mv.col = (mv->as_mv.col > mb_to_right_edge) ? 58 mb_to_right_edge : mv->as_mv.col; 59 mv->as_mv.row = (mv->as_mv.row < mb_to_top_edge) ? 60 mb_to_top_edge : mv->as_mv.row; 61 mv->as_mv.row = (mv->as_mv.row > mb_to_bottom_edge) ? 62 mb_to_bottom_edge : mv->as_mv.row; 63} 64static INLINE unsigned int vp8_check_mv_bounds(int_mv *mv, int mb_to_left_edge, 65 int mb_to_right_edge, 66 int mb_to_top_edge, 67 int mb_to_bottom_edge) 68{ 69 unsigned int need_to_clamp; 70 need_to_clamp = (mv->as_mv.col < mb_to_left_edge); 71 need_to_clamp |= (mv->as_mv.col > mb_to_right_edge); 72 need_to_clamp |= (mv->as_mv.row < mb_to_top_edge); 73 need_to_clamp |= (mv->as_mv.row > mb_to_bottom_edge); 74 return need_to_clamp; 75} 76 77void vp8_find_near_mvs 78( 79 MACROBLOCKD *xd, 80 const MODE_INFO *here, 81 int_mv *nearest, int_mv *nearby, int_mv *best, 82 int near_mv_ref_cts[4], 83 int refframe, 84 int *ref_frame_sign_bias 85); 86 87 88int vp8_find_near_mvs_bias 89( 90 MACROBLOCKD *xd, 91 const MODE_INFO *here, 92 int_mv mode_mv_sb[2][MB_MODE_COUNT], 93 int_mv best_mv_sb[2], 94 int cnt[4], 95 int refframe, 96 int *ref_frame_sign_bias 97); 98 99 100vp8_prob *vp8_mv_ref_probs( 101 vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4] 102); 103 104extern const unsigned char vp8_mbsplit_offset[4][16]; 105 106 107static INLINE int left_block_mv(const MODE_INFO *cur_mb, int b) 108{ 109 if (!(b & 3)) 110 { 111 /* On L edge, get from MB to left of us */ 112 --cur_mb; 113 114 if(cur_mb->mbmi.mode != SPLITMV) 115 return cur_mb->mbmi.mv.as_int; 116 b += 4; 117 } 118 119 return (cur_mb->bmi + b - 1)->mv.as_int; 120} 121 122static INLINE int above_block_mv(const MODE_INFO *cur_mb, int b, int mi_stride) 123{ 124 if (!(b >> 2)) 125 { 126 /* On top edge, get from MB above us */ 127 cur_mb -= mi_stride; 128 129 if(cur_mb->mbmi.mode != SPLITMV) 130 return cur_mb->mbmi.mv.as_int; 131 b += 16; 132 } 133 134 return (cur_mb->bmi + (b - 4))->mv.as_int; 135} 136static INLINE B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b) 137{ 138 if (!(b & 3)) 139 { 140 /* On L edge, get from MB to left of us */ 141 --cur_mb; 142 switch (cur_mb->mbmi.mode) 143 { 144 case B_PRED: 145 return (cur_mb->bmi + b + 3)->as_mode; 146 case DC_PRED: 147 return B_DC_PRED; 148 case V_PRED: 149 return B_VE_PRED; 150 case H_PRED: 151 return B_HE_PRED; 152 case TM_PRED: 153 return B_TM_PRED; 154 default: 155 return B_DC_PRED; 156 } 157 } 158 159 return (cur_mb->bmi + b - 1)->as_mode; 160} 161 162static INLINE B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b, 163 int mi_stride) 164{ 165 if (!(b >> 2)) 166 { 167 /* On top edge, get from MB above us */ 168 cur_mb -= mi_stride; 169 170 switch (cur_mb->mbmi.mode) 171 { 172 case B_PRED: 173 return (cur_mb->bmi + b + 12)->as_mode; 174 case DC_PRED: 175 return B_DC_PRED; 176 case V_PRED: 177 return B_VE_PRED; 178 case H_PRED: 179 return B_HE_PRED; 180 case TM_PRED: 181 return B_TM_PRED; 182 default: 183 return B_DC_PRED; 184 } 185 } 186 187 return (cur_mb->bmi + b - 4)->as_mode; 188} 189 190#ifdef __cplusplus 191} // extern "C" 192#endif 193 194#endif // VP8_COMMON_FINDNEARMV_H_ 195