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