findnearmv.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 VPX_VP8_COMMON_FINDNEARMV_H_
  11. #define VPX_VP8_COMMON_FINDNEARMV_H_
  12. #include "./vpx_config.h"
  13. #include "mv.h"
  14. #include "blockd.h"
  15. #include "modecont.h"
  16. #include "treecoder.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. static INLINE void mv_bias(int refmb_ref_frame_sign_bias, int refframe,
  21. int_mv *mvp, const int *ref_frame_sign_bias) {
  22. if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe]) {
  23. mvp->as_mv.row *= -1;
  24. mvp->as_mv.col *= -1;
  25. }
  26. }
  27. #define LEFT_TOP_MARGIN (16 << 3)
  28. #define RIGHT_BOTTOM_MARGIN (16 << 3)
  29. static INLINE void vp8_clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) {
  30. if (mv->as_mv.col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN)) {
  31. mv->as_mv.col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
  32. } else if (mv->as_mv.col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN) {
  33. mv->as_mv.col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
  34. }
  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. }
  41. static INLINE void vp8_clamp_mv(int_mv *mv, int mb_to_left_edge,
  42. int mb_to_right_edge, int mb_to_top_edge,
  43. int mb_to_bottom_edge) {
  44. mv->as_mv.col =
  45. (mv->as_mv.col < mb_to_left_edge) ? mb_to_left_edge : mv->as_mv.col;
  46. mv->as_mv.col =
  47. (mv->as_mv.col > mb_to_right_edge) ? mb_to_right_edge : mv->as_mv.col;
  48. mv->as_mv.row =
  49. (mv->as_mv.row < mb_to_top_edge) ? mb_to_top_edge : mv->as_mv.row;
  50. mv->as_mv.row =
  51. (mv->as_mv.row > mb_to_bottom_edge) ? mb_to_bottom_edge : mv->as_mv.row;
  52. }
  53. static INLINE unsigned int vp8_check_mv_bounds(int_mv *mv, int mb_to_left_edge,
  54. int mb_to_right_edge,
  55. int mb_to_top_edge,
  56. int mb_to_bottom_edge) {
  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(MACROBLOCKD *xd, const MODE_INFO *here, int_mv *nearest,
  65. int_mv *nearby, int_mv *best_mv, int near_mv_ref_cnts[4],
  66. int refframe, int *ref_frame_sign_bias);
  67. int vp8_find_near_mvs_bias(MACROBLOCKD *xd, const MODE_INFO *here,
  68. int_mv mode_mv_sb[2][MB_MODE_COUNT],
  69. int_mv best_mv_sb[2], int cnt[4], int refframe,
  70. int *ref_frame_sign_bias);
  71. vp8_prob *vp8_mv_ref_probs(vp8_prob p[VP8_MVREFS - 1],
  72. const int near_mv_ref_ct[4]);
  73. extern const unsigned char vp8_mbsplit_offset[4][16];
  74. static INLINE uint32_t left_block_mv(const MODE_INFO *cur_mb, int b) {
  75. if (!(b & 3)) {
  76. /* On L edge, get from MB to left of us */
  77. --cur_mb;
  78. if (cur_mb->mbmi.mode != SPLITMV) return cur_mb->mbmi.mv.as_int;
  79. b += 4;
  80. }
  81. return (cur_mb->bmi + b - 1)->mv.as_int;
  82. }
  83. static INLINE uint32_t above_block_mv(const MODE_INFO *cur_mb, int b,
  84. int mi_stride) {
  85. if (!(b >> 2)) {
  86. /* On top edge, get from MB above us */
  87. cur_mb -= mi_stride;
  88. if (cur_mb->mbmi.mode != SPLITMV) return cur_mb->mbmi.mv.as_int;
  89. b += 16;
  90. }
  91. return (cur_mb->bmi + (b - 4))->mv.as_int;
  92. }
  93. static INLINE B_PREDICTION_MODE left_block_mode(const MODE_INFO *cur_mb,
  94. int b) {
  95. if (!(b & 3)) {
  96. /* On L edge, get from MB to left of us */
  97. --cur_mb;
  98. switch (cur_mb->mbmi.mode) {
  99. case B_PRED: return (cur_mb->bmi + b + 3)->as_mode;
  100. case DC_PRED: return B_DC_PRED;
  101. case V_PRED: return B_VE_PRED;
  102. case H_PRED: return B_HE_PRED;
  103. case TM_PRED: return B_TM_PRED;
  104. default: return B_DC_PRED;
  105. }
  106. }
  107. return (cur_mb->bmi + b - 1)->as_mode;
  108. }
  109. static INLINE B_PREDICTION_MODE above_block_mode(const MODE_INFO *cur_mb, int b,
  110. int mi_stride) {
  111. if (!(b >> 2)) {
  112. /* On top edge, get from MB above us */
  113. cur_mb -= mi_stride;
  114. switch (cur_mb->mbmi.mode) {
  115. case B_PRED: return (cur_mb->bmi + b + 12)->as_mode;
  116. case DC_PRED: return B_DC_PRED;
  117. case V_PRED: return B_VE_PRED;
  118. case H_PRED: return B_HE_PRED;
  119. case TM_PRED: return B_TM_PRED;
  120. default: return B_DC_PRED;
  121. }
  122. }
  123. return (cur_mb->bmi + b - 4)->as_mode;
  124. }
  125. #ifdef __cplusplus
  126. } // extern "C"
  127. #endif
  128. #endif // VPX_VP8_COMMON_FINDNEARMV_H_