/media/libvpx/vp8/common/findnearmv.h

http://github.com/zpao/v8monkey · C Header · 173 lines · 135 code · 25 blank · 13 comment · 18 complexity · 0ec3f6f64953c8bef671d02ec8831eee MD5 · raw file

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