vp9_pred_common.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (c) 2012 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 VP9_COMMON_VP9_PRED_COMMON_H_
  11. #define VP9_COMMON_VP9_PRED_COMMON_H_
  12. #include "vp9/common/vp9_blockd.h"
  13. #include "vp9/common/vp9_onyxc_int.h"
  14. #include "vpx_dsp/vpx_dsp_common.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. static INLINE int get_segment_id(const VP9_COMMON *cm,
  19. const uint8_t *segment_ids,
  20. BLOCK_SIZE bsize, int mi_row, int mi_col) {
  21. const int mi_offset = mi_row * cm->mi_cols + mi_col;
  22. const int bw = num_8x8_blocks_wide_lookup[bsize];
  23. const int bh = num_8x8_blocks_high_lookup[bsize];
  24. const int xmis = VPXMIN(cm->mi_cols - mi_col, bw);
  25. const int ymis = VPXMIN(cm->mi_rows - mi_row, bh);
  26. int x, y, segment_id = MAX_SEGMENTS;
  27. for (y = 0; y < ymis; ++y)
  28. for (x = 0; x < xmis; ++x)
  29. segment_id =
  30. VPXMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
  31. assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
  32. return segment_id;
  33. }
  34. static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) {
  35. const MODE_INFO *const above_mi = xd->above_mi;
  36. const MODE_INFO *const left_mi = xd->left_mi;
  37. const int above_sip = (above_mi != NULL) ?
  38. above_mi->seg_id_predicted : 0;
  39. const int left_sip = (left_mi != NULL) ? left_mi->seg_id_predicted : 0;
  40. return above_sip + left_sip;
  41. }
  42. static INLINE vpx_prob vp9_get_pred_prob_seg_id(const struct segmentation *seg,
  43. const MACROBLOCKD *xd) {
  44. return seg->pred_probs[vp9_get_pred_context_seg_id(xd)];
  45. }
  46. static INLINE int vp9_get_skip_context(const MACROBLOCKD *xd) {
  47. const MODE_INFO *const above_mi = xd->above_mi;
  48. const MODE_INFO *const left_mi = xd->left_mi;
  49. const int above_skip = (above_mi != NULL) ? above_mi->skip : 0;
  50. const int left_skip = (left_mi != NULL) ? left_mi->skip : 0;
  51. return above_skip + left_skip;
  52. }
  53. static INLINE vpx_prob vp9_get_skip_prob(const VP9_COMMON *cm,
  54. const MACROBLOCKD *xd) {
  55. return cm->fc->skip_probs[vp9_get_skip_context(xd)];
  56. }
  57. int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
  58. // The mode info data structure has a one element border above and to the
  59. // left of the entries corresponding to real macroblocks.
  60. // The prediction flags in these dummy entries are initialized to 0.
  61. // 0 - inter/inter, inter/--, --/inter, --/--
  62. // 1 - intra/inter, inter/intra
  63. // 2 - intra/--, --/intra
  64. // 3 - intra/intra
  65. static INLINE int get_intra_inter_context(const MACROBLOCKD *xd) {
  66. const MODE_INFO *const above_mi = xd->above_mi;
  67. const MODE_INFO *const left_mi = xd->left_mi;
  68. const int has_above = !!above_mi;
  69. const int has_left = !!left_mi;
  70. if (has_above && has_left) { // both edges available
  71. const int above_intra = !is_inter_block(above_mi);
  72. const int left_intra = !is_inter_block(left_mi);
  73. return left_intra && above_intra ? 3 : left_intra || above_intra;
  74. } else if (has_above || has_left) { // one edge available
  75. return 2 * !is_inter_block(has_above ? above_mi : left_mi);
  76. }
  77. return 0;
  78. }
  79. static INLINE vpx_prob vp9_get_intra_inter_prob(const VP9_COMMON *cm,
  80. const MACROBLOCKD *xd) {
  81. return cm->fc->intra_inter_prob[get_intra_inter_context(xd)];
  82. }
  83. int vp9_get_reference_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd);
  84. static INLINE vpx_prob vp9_get_reference_mode_prob(const VP9_COMMON *cm,
  85. const MACROBLOCKD *xd) {
  86. return cm->fc->comp_inter_prob[vp9_get_reference_mode_context(cm, xd)];
  87. }
  88. int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
  89. const MACROBLOCKD *xd);
  90. static INLINE vpx_prob vp9_get_pred_prob_comp_ref_p(const VP9_COMMON *cm,
  91. const MACROBLOCKD *xd) {
  92. const int pred_context = vp9_get_pred_context_comp_ref_p(cm, xd);
  93. return cm->fc->comp_ref_prob[pred_context];
  94. }
  95. int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
  96. static INLINE vpx_prob vp9_get_pred_prob_single_ref_p1(const VP9_COMMON *cm,
  97. const MACROBLOCKD *xd) {
  98. return cm->fc->single_ref_prob[vp9_get_pred_context_single_ref_p1(xd)][0];
  99. }
  100. int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
  101. static INLINE vpx_prob vp9_get_pred_prob_single_ref_p2(const VP9_COMMON *cm,
  102. const MACROBLOCKD *xd) {
  103. return cm->fc->single_ref_prob[vp9_get_pred_context_single_ref_p2(xd)][1];
  104. }
  105. // Returns a context number for the given MB prediction signal
  106. // The mode info data structure has a one element border above and to the
  107. // left of the entries corresponding to real blocks.
  108. // The prediction flags in these dummy entries are initialized to 0.
  109. static INLINE int get_tx_size_context(const MACROBLOCKD *xd) {
  110. const int max_tx_size = max_txsize_lookup[xd->mi[0]->sb_type];
  111. const MODE_INFO *const above_mi = xd->above_mi;
  112. const MODE_INFO *const left_mi = xd->left_mi;
  113. const int has_above = !!above_mi;
  114. const int has_left = !!left_mi;
  115. int above_ctx = (has_above && !above_mi->skip) ? (int)above_mi->tx_size
  116. : max_tx_size;
  117. int left_ctx = (has_left && !left_mi->skip) ? (int)left_mi->tx_size
  118. : max_tx_size;
  119. if (!has_left)
  120. left_ctx = above_ctx;
  121. if (!has_above)
  122. above_ctx = left_ctx;
  123. return (above_ctx + left_ctx) > max_tx_size;
  124. }
  125. static INLINE const vpx_prob *get_tx_probs(TX_SIZE max_tx_size, int ctx,
  126. const struct tx_probs *tx_probs) {
  127. switch (max_tx_size) {
  128. case TX_8X8:
  129. return tx_probs->p8x8[ctx];
  130. case TX_16X16:
  131. return tx_probs->p16x16[ctx];
  132. case TX_32X32:
  133. return tx_probs->p32x32[ctx];
  134. default:
  135. assert(0 && "Invalid max_tx_size.");
  136. return NULL;
  137. }
  138. }
  139. static INLINE const vpx_prob *get_tx_probs2(TX_SIZE max_tx_size,
  140. const MACROBLOCKD *xd,
  141. const struct tx_probs *tx_probs) {
  142. return get_tx_probs(max_tx_size, get_tx_size_context(xd), tx_probs);
  143. }
  144. static INLINE unsigned int *get_tx_counts(TX_SIZE max_tx_size, int ctx,
  145. struct tx_counts *tx_counts) {
  146. switch (max_tx_size) {
  147. case TX_8X8:
  148. return tx_counts->p8x8[ctx];
  149. case TX_16X16:
  150. return tx_counts->p16x16[ctx];
  151. case TX_32X32:
  152. return tx_counts->p32x32[ctx];
  153. default:
  154. assert(0 && "Invalid max_tx_size.");
  155. return NULL;
  156. }
  157. }
  158. #ifdef __cplusplus
  159. } // extern "C"
  160. #endif
  161. #endif // VP9_COMMON_VP9_PRED_COMMON_H_