OLD | NEW |
(Empty) | |
| 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 VP9_COMMON_VP9_FINDNEARMV_H_ |
| 13 #define VP9_COMMON_VP9_FINDNEARMV_H_ |
| 14 |
| 15 #include "vp9/common/vp9_mv.h" |
| 16 #include "vp9/common/vp9_blockd.h" |
| 17 #include "vp9/common/vp9_treecoder.h" |
| 18 #include "vp9/common/vp9_onyxc_int.h" |
| 19 |
| 20 /* check a list of motion vectors by sad score using a number rows of pixels |
| 21 * above and a number cols of pixels in the left to select the one with best |
| 22 * score to use as ref motion vector |
| 23 */ |
| 24 void vp9_find_best_ref_mvs(MACROBLOCKD *xd, |
| 25 unsigned char *ref_y_buffer, |
| 26 int ref_y_stride, |
| 27 int_mv *mvlist, |
| 28 int_mv *best_mv, |
| 29 int_mv *nearest, |
| 30 int_mv *near); |
| 31 |
| 32 static void mv_bias(int refmb_ref_frame_sign_bias, int refframe, int_mv *mvp, co
nst int *ref_frame_sign_bias) { |
| 33 MV xmv; |
| 34 xmv = mvp->as_mv; |
| 35 |
| 36 if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe]) { |
| 37 xmv.row *= -1; |
| 38 xmv.col *= -1; |
| 39 } |
| 40 |
| 41 mvp->as_mv = xmv; |
| 42 } |
| 43 |
| 44 #define LEFT_TOP_MARGIN (16 << 3) |
| 45 #define RIGHT_BOTTOM_MARGIN (16 << 3) |
| 46 |
| 47 static void clamp_mv(int_mv *mv, |
| 48 int mb_to_left_edge, |
| 49 int mb_to_right_edge, |
| 50 int mb_to_top_edge, |
| 51 int mb_to_bottom_edge) { |
| 52 mv->as_mv.col = (mv->as_mv.col < mb_to_left_edge) ? |
| 53 mb_to_left_edge : mv->as_mv.col; |
| 54 mv->as_mv.col = (mv->as_mv.col > mb_to_right_edge) ? |
| 55 mb_to_right_edge : mv->as_mv.col; |
| 56 mv->as_mv.row = (mv->as_mv.row < mb_to_top_edge) ? |
| 57 mb_to_top_edge : mv->as_mv.row; |
| 58 mv->as_mv.row = (mv->as_mv.row > mb_to_bottom_edge) ? |
| 59 mb_to_bottom_edge : mv->as_mv.row; |
| 60 } |
| 61 |
| 62 static void clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) { |
| 63 clamp_mv(mv, |
| 64 xd->mb_to_left_edge - LEFT_TOP_MARGIN, |
| 65 xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN, |
| 66 xd->mb_to_top_edge - LEFT_TOP_MARGIN, |
| 67 xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN); |
| 68 } |
| 69 |
| 70 static unsigned int check_mv_bounds(int_mv *mv, |
| 71 int mb_to_left_edge, |
| 72 int mb_to_right_edge, |
| 73 int mb_to_top_edge, |
| 74 int mb_to_bottom_edge) { |
| 75 return (mv->as_mv.col < mb_to_left_edge) || |
| 76 (mv->as_mv.col > mb_to_right_edge) || |
| 77 (mv->as_mv.row < mb_to_top_edge) || |
| 78 (mv->as_mv.row > mb_to_bottom_edge); |
| 79 } |
| 80 |
| 81 vp9_prob *vp9_mv_ref_probs(VP9_COMMON *pc, |
| 82 vp9_prob p[VP9_MVREFS - 1], |
| 83 const int context); |
| 84 |
| 85 extern const unsigned char vp9_mbsplit_offset[4][16]; |
| 86 |
| 87 static int left_block_mv(const MODE_INFO *cur_mb, int b) { |
| 88 if (!(b & 3)) { |
| 89 /* On L edge, get from MB to left of us */ |
| 90 --cur_mb; |
| 91 |
| 92 if (cur_mb->mbmi.mode != SPLITMV) |
| 93 return cur_mb->mbmi.mv[0].as_int; |
| 94 b += 4; |
| 95 } |
| 96 |
| 97 return (cur_mb->bmi + b - 1)->as_mv.first.as_int; |
| 98 } |
| 99 |
| 100 static int left_block_second_mv(const MODE_INFO *cur_mb, int b) { |
| 101 if (!(b & 3)) { |
| 102 /* On L edge, get from MB to left of us */ |
| 103 --cur_mb; |
| 104 |
| 105 if (cur_mb->mbmi.mode != SPLITMV) |
| 106 return cur_mb->mbmi.second_ref_frame > 0 ? |
| 107 cur_mb->mbmi.mv[1].as_int : cur_mb->mbmi.mv[0].as_int; |
| 108 b += 4; |
| 109 } |
| 110 |
| 111 return cur_mb->mbmi.second_ref_frame > 0 ? |
| 112 (cur_mb->bmi + b - 1)->as_mv.second.as_int : |
| 113 (cur_mb->bmi + b - 1)->as_mv.first.as_int; |
| 114 } |
| 115 |
| 116 static int above_block_mv(const MODE_INFO *cur_mb, int b, int mi_stride) { |
| 117 if (!(b >> 2)) { |
| 118 /* On top edge, get from MB above us */ |
| 119 cur_mb -= mi_stride; |
| 120 |
| 121 if (cur_mb->mbmi.mode != SPLITMV) |
| 122 return cur_mb->mbmi.mv[0].as_int; |
| 123 b += 16; |
| 124 } |
| 125 |
| 126 return (cur_mb->bmi + b - 4)->as_mv.first.as_int; |
| 127 } |
| 128 |
| 129 static int above_block_second_mv(const MODE_INFO *cur_mb, int b, int mi_stride)
{ |
| 130 if (!(b >> 2)) { |
| 131 /* On top edge, get from MB above us */ |
| 132 cur_mb -= mi_stride; |
| 133 |
| 134 if (cur_mb->mbmi.mode != SPLITMV) |
| 135 return cur_mb->mbmi.second_ref_frame > 0 ? |
| 136 cur_mb->mbmi.mv[1].as_int : cur_mb->mbmi.mv[0].as_int; |
| 137 b += 16; |
| 138 } |
| 139 |
| 140 return cur_mb->mbmi.second_ref_frame > 0 ? |
| 141 (cur_mb->bmi + b - 4)->as_mv.second.as_int : |
| 142 (cur_mb->bmi + b - 4)->as_mv.first.as_int; |
| 143 } |
| 144 |
| 145 static B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb, int b) { |
| 146 if (!(b & 3)) { |
| 147 /* On L edge, get from MB to left of us */ |
| 148 --cur_mb; |
| 149 |
| 150 if (cur_mb->mbmi.mode < I8X8_PRED) { |
| 151 return pred_mode_conv(cur_mb->mbmi.mode); |
| 152 } else if (cur_mb->mbmi.mode == I8X8_PRED) { |
| 153 return pred_mode_conv( |
| 154 (MB_PREDICTION_MODE)(cur_mb->bmi + 3 + b)->as_mode.first); |
| 155 } else if (cur_mb->mbmi.mode == B_PRED) { |
| 156 return ((cur_mb->bmi + 3 + b)->as_mode.first); |
| 157 } else { |
| 158 return B_DC_PRED; |
| 159 } |
| 160 } |
| 161 return (cur_mb->bmi + b - 1)->as_mode.first; |
| 162 } |
| 163 |
| 164 static B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, |
| 165 int b, int mi_stride) { |
| 166 if (!(b >> 2)) { |
| 167 /* On top edge, get from MB above us */ |
| 168 cur_mb -= mi_stride; |
| 169 |
| 170 if (cur_mb->mbmi.mode < I8X8_PRED) { |
| 171 return pred_mode_conv(cur_mb->mbmi.mode); |
| 172 } else if (cur_mb->mbmi.mode == I8X8_PRED) { |
| 173 return pred_mode_conv( |
| 174 (MB_PREDICTION_MODE)(cur_mb->bmi + 12 + b)->as_mode.first); |
| 175 } else if (cur_mb->mbmi.mode == B_PRED) { |
| 176 return ((cur_mb->bmi + 12 + b)->as_mode.first); |
| 177 } else { |
| 178 return B_DC_PRED; |
| 179 } |
| 180 } |
| 181 |
| 182 return (cur_mb->bmi + b - 4)->as_mode.first; |
| 183 } |
| 184 |
| 185 #endif |
OLD | NEW |