findnearmv.h 5.1 KB

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