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
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
get_above_mi(const MACROBLOCKD * const xd)21 static INLINE const MODE_INFO *get_above_mi(const MACROBLOCKD *const xd) {
22 return xd->up_available ? xd->mi[-xd->mi_stride] : NULL;
23 }
24
get_left_mi(const MACROBLOCKD * const xd)25 static INLINE const MODE_INFO *get_left_mi(const MACROBLOCKD *const xd) {
26 return xd->left_available ? xd->mi[-1] : NULL;
27 }
28
29 int vp9_get_segment_id(const VP9_COMMON *cm, const uint8_t *segment_ids,
30 BLOCK_SIZE bsize, int mi_row, int mi_col);
31
vp9_get_pred_context_seg_id(const MACROBLOCKD * xd)32 static INLINE int vp9_get_pred_context_seg_id(const MACROBLOCKD *xd) {
33 const MODE_INFO *const above_mi = get_above_mi(xd);
34 const MODE_INFO *const left_mi = get_left_mi(xd);
35 const int above_sip = (above_mi != NULL) ?
36 above_mi->mbmi.seg_id_predicted : 0;
37 const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0;
38
39 return above_sip + left_sip;
40 }
41
vp9_get_pred_prob_seg_id(const struct segmentation * seg,const MACROBLOCKD * xd)42 static INLINE vp9_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
vp9_get_skip_context(const MACROBLOCKD * xd)47 static INLINE int vp9_get_skip_context(const MACROBLOCKD *xd) {
48 const MODE_INFO *const above_mi = get_above_mi(xd);
49 const MODE_INFO *const left_mi = get_left_mi(xd);
50 const int above_skip = (above_mi != NULL) ? above_mi->mbmi.skip : 0;
51 const int left_skip = (left_mi != NULL) ? left_mi->mbmi.skip : 0;
52 return above_skip + left_skip;
53 }
54
vp9_get_skip_prob(const VP9_COMMON * cm,const MACROBLOCKD * xd)55 static INLINE vp9_prob vp9_get_skip_prob(const VP9_COMMON *cm,
56 const MACROBLOCKD *xd) {
57 return cm->fc.skip_probs[vp9_get_skip_context(xd)];
58 }
59
60 int vp9_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
61
62 int vp9_get_intra_inter_context(const MACROBLOCKD *xd);
63
vp9_get_intra_inter_prob(const VP9_COMMON * cm,const MACROBLOCKD * xd)64 static INLINE vp9_prob vp9_get_intra_inter_prob(const VP9_COMMON *cm,
65 const MACROBLOCKD *xd) {
66 return cm->fc.intra_inter_prob[vp9_get_intra_inter_context(xd)];
67 }
68
69 int vp9_get_reference_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd);
70
vp9_get_reference_mode_prob(const VP9_COMMON * cm,const MACROBLOCKD * xd)71 static INLINE vp9_prob vp9_get_reference_mode_prob(const VP9_COMMON *cm,
72 const MACROBLOCKD *xd) {
73 return cm->fc.comp_inter_prob[vp9_get_reference_mode_context(cm, xd)];
74 }
75
76 int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
77 const MACROBLOCKD *xd);
78
vp9_get_pred_prob_comp_ref_p(const VP9_COMMON * cm,const MACROBLOCKD * xd)79 static INLINE vp9_prob vp9_get_pred_prob_comp_ref_p(const VP9_COMMON *cm,
80 const MACROBLOCKD *xd) {
81 const int pred_context = vp9_get_pred_context_comp_ref_p(cm, xd);
82 return cm->fc.comp_ref_prob[pred_context];
83 }
84
85 int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
86
vp9_get_pred_prob_single_ref_p1(const VP9_COMMON * cm,const MACROBLOCKD * xd)87 static INLINE vp9_prob vp9_get_pred_prob_single_ref_p1(const VP9_COMMON *cm,
88 const MACROBLOCKD *xd) {
89 return cm->fc.single_ref_prob[vp9_get_pred_context_single_ref_p1(xd)][0];
90 }
91
92 int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
93
vp9_get_pred_prob_single_ref_p2(const VP9_COMMON * cm,const MACROBLOCKD * xd)94 static INLINE vp9_prob vp9_get_pred_prob_single_ref_p2(const VP9_COMMON *cm,
95 const MACROBLOCKD *xd) {
96 return cm->fc.single_ref_prob[vp9_get_pred_context_single_ref_p2(xd)][1];
97 }
98
99 int vp9_get_tx_size_context(const MACROBLOCKD *xd);
100
get_tx_probs(TX_SIZE max_tx_size,int ctx,const struct tx_probs * tx_probs)101 static INLINE const vp9_prob *get_tx_probs(TX_SIZE max_tx_size, int ctx,
102 const struct tx_probs *tx_probs) {
103 switch (max_tx_size) {
104 case TX_8X8:
105 return tx_probs->p8x8[ctx];
106 case TX_16X16:
107 return tx_probs->p16x16[ctx];
108 case TX_32X32:
109 return tx_probs->p32x32[ctx];
110 default:
111 assert(0 && "Invalid max_tx_size.");
112 return NULL;
113 }
114 }
115
get_tx_probs2(TX_SIZE max_tx_size,const MACROBLOCKD * xd,const struct tx_probs * tx_probs)116 static INLINE const vp9_prob *get_tx_probs2(TX_SIZE max_tx_size,
117 const MACROBLOCKD *xd,
118 const struct tx_probs *tx_probs) {
119 return get_tx_probs(max_tx_size, vp9_get_tx_size_context(xd), tx_probs);
120 }
121
get_tx_counts(TX_SIZE max_tx_size,int ctx,struct tx_counts * tx_counts)122 static INLINE unsigned int *get_tx_counts(TX_SIZE max_tx_size, int ctx,
123 struct tx_counts *tx_counts) {
124 switch (max_tx_size) {
125 case TX_8X8:
126 return tx_counts->p8x8[ctx];
127 case TX_16X16:
128 return tx_counts->p16x16[ctx];
129 case TX_32X32:
130 return tx_counts->p32x32[ctx];
131 default:
132 assert(0 && "Invalid max_tx_size.");
133 return NULL;
134 }
135 }
136
137 #ifdef __cplusplus
138 } // extern "C"
139 #endif
140
141 #endif // VP9_COMMON_VP9_PRED_COMMON_H_
142