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