Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
4 : * This source code is subject to the terms of the BSD 2 Clause License and
5 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 : * was not distributed with this source code in the LICENSE file, you can
7 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 : * Media Patent License 1.0 was not distributed with this source code in the
9 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 : */
11 :
12 : #ifndef AV1_COMMON_PRED_COMMON_H_
13 : #define AV1_COMMON_PRED_COMMON_H_
14 :
15 : #include "av1/common/blockd.h"
16 : #include "av1/common/onyxc_int.h"
17 : #include "aom_dsp/aom_dsp_common.h"
18 :
19 : #ifdef __cplusplus
20 : extern "C" {
21 : #endif
22 :
23 0 : static INLINE int get_segment_id(const AV1_COMMON *const cm,
24 : const uint8_t *segment_ids, BLOCK_SIZE bsize,
25 : int mi_row, int mi_col) {
26 0 : const int mi_offset = mi_row * cm->mi_cols + mi_col;
27 0 : const int bw = mi_size_wide[bsize];
28 0 : const int bh = mi_size_high[bsize];
29 0 : const int xmis = AOMMIN(cm->mi_cols - mi_col, bw);
30 0 : const int ymis = AOMMIN(cm->mi_rows - mi_row, bh);
31 0 : int x, y, segment_id = MAX_SEGMENTS;
32 :
33 0 : for (y = 0; y < ymis; ++y)
34 0 : for (x = 0; x < xmis; ++x)
35 0 : segment_id =
36 0 : AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
37 :
38 0 : assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
39 0 : return segment_id;
40 : }
41 :
42 0 : static INLINE int av1_get_pred_context_seg_id(const MACROBLOCKD *xd) {
43 0 : const MODE_INFO *const above_mi = xd->above_mi;
44 0 : const MODE_INFO *const left_mi = xd->left_mi;
45 0 : const int above_sip =
46 0 : (above_mi != NULL) ? above_mi->mbmi.seg_id_predicted : 0;
47 0 : const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0;
48 :
49 0 : return above_sip + left_sip;
50 : }
51 :
52 0 : static INLINE aom_prob av1_get_pred_prob_seg_id(
53 : const struct segmentation_probs *segp, const MACROBLOCKD *xd) {
54 0 : return segp->pred_probs[av1_get_pred_context_seg_id(xd)];
55 : }
56 :
57 0 : static INLINE int av1_get_skip_context(const MACROBLOCKD *xd) {
58 0 : const MODE_INFO *const above_mi = xd->above_mi;
59 0 : const MODE_INFO *const left_mi = xd->left_mi;
60 0 : const int above_skip = (above_mi != NULL) ? above_mi->mbmi.skip : 0;
61 0 : const int left_skip = (left_mi != NULL) ? left_mi->mbmi.skip : 0;
62 0 : return above_skip + left_skip;
63 : }
64 :
65 0 : static INLINE aom_prob av1_get_skip_prob(const AV1_COMMON *cm,
66 : const MACROBLOCKD *xd) {
67 0 : return cm->fc->skip_probs[av1_get_skip_context(xd)];
68 : }
69 :
70 : #if CONFIG_DUAL_FILTER
71 : int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir);
72 : #else
73 : int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
74 : #endif
75 :
76 : #if CONFIG_EXT_INTRA
77 : #if CONFIG_INTRA_INTERP
78 : int av1_get_pred_context_intra_interp(const MACROBLOCKD *xd);
79 : #endif // CONFIG_INTRA_INTERP
80 : #endif // CONFIG_EXT_INTRA
81 :
82 : #if CONFIG_PALETTE && CONFIG_PALETTE_DELTA_ENCODING
83 : // Get a list of palette base colors that are used in the above and left blocks,
84 : // referred to as "color cache". The return value is the number of colors in the
85 : // cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache"
86 : // in ascending order.
87 : int av1_get_palette_cache(const MODE_INFO *above_mi, const MODE_INFO *left_mi,
88 : int plane, uint16_t *cache);
89 : #endif // CONFIG_PALETTE && CONFIG_PALETTE_DELTA_ENCODING
90 :
91 : int av1_get_intra_inter_context(const MACROBLOCKD *xd);
92 :
93 0 : static INLINE aom_prob av1_get_intra_inter_prob(const AV1_COMMON *cm,
94 : const MACROBLOCKD *xd) {
95 0 : return cm->fc->intra_inter_prob[av1_get_intra_inter_context(xd)];
96 : }
97 :
98 : int av1_get_reference_mode_context(const AV1_COMMON *cm, const MACROBLOCKD *xd);
99 :
100 0 : static INLINE aom_prob av1_get_reference_mode_prob(const AV1_COMMON *cm,
101 : const MACROBLOCKD *xd) {
102 0 : return cm->fc->comp_inter_prob[av1_get_reference_mode_context(cm, xd)];
103 : }
104 :
105 : int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
106 : const MACROBLOCKD *xd);
107 :
108 0 : static INLINE aom_prob av1_get_pred_prob_comp_ref_p(const AV1_COMMON *cm,
109 : const MACROBLOCKD *xd) {
110 0 : const int pred_context = av1_get_pred_context_comp_ref_p(cm, xd);
111 0 : return cm->fc->comp_ref_prob[pred_context][0];
112 : }
113 :
114 : #if CONFIG_EXT_REFS
115 : int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
116 : const MACROBLOCKD *xd);
117 :
118 0 : static INLINE aom_prob av1_get_pred_prob_comp_ref_p1(const AV1_COMMON *cm,
119 : const MACROBLOCKD *xd) {
120 0 : const int pred_context = av1_get_pred_context_comp_ref_p1(cm, xd);
121 0 : return cm->fc->comp_ref_prob[pred_context][1];
122 : }
123 :
124 : int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm,
125 : const MACROBLOCKD *xd);
126 :
127 0 : static INLINE aom_prob av1_get_pred_prob_comp_ref_p2(const AV1_COMMON *cm,
128 : const MACROBLOCKD *xd) {
129 0 : const int pred_context = av1_get_pred_context_comp_ref_p2(cm, xd);
130 0 : return cm->fc->comp_ref_prob[pred_context][2];
131 : }
132 :
133 : int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
134 : const MACROBLOCKD *xd);
135 :
136 0 : static INLINE aom_prob av1_get_pred_prob_comp_bwdref_p(const AV1_COMMON *cm,
137 : const MACROBLOCKD *xd) {
138 0 : const int pred_context = av1_get_pred_context_comp_bwdref_p(cm, xd);
139 0 : return cm->fc->comp_bwdref_prob[pred_context][0];
140 : }
141 : #endif // CONFIG_EXT_REFS
142 :
143 : int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
144 :
145 0 : static INLINE aom_prob av1_get_pred_prob_single_ref_p1(const AV1_COMMON *cm,
146 : const MACROBLOCKD *xd) {
147 0 : return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p1(xd)][0];
148 : }
149 :
150 : int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
151 :
152 0 : static INLINE aom_prob av1_get_pred_prob_single_ref_p2(const AV1_COMMON *cm,
153 : const MACROBLOCKD *xd) {
154 0 : return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p2(xd)][1];
155 : }
156 :
157 : #if CONFIG_EXT_REFS
158 : int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd);
159 :
160 0 : static INLINE aom_prob av1_get_pred_prob_single_ref_p3(const AV1_COMMON *cm,
161 : const MACROBLOCKD *xd) {
162 0 : return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p3(xd)][2];
163 : }
164 :
165 : int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd);
166 :
167 0 : static INLINE aom_prob av1_get_pred_prob_single_ref_p4(const AV1_COMMON *cm,
168 : const MACROBLOCKD *xd) {
169 0 : return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p4(xd)][3];
170 : }
171 :
172 : int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd);
173 :
174 0 : static INLINE aom_prob av1_get_pred_prob_single_ref_p5(const AV1_COMMON *cm,
175 : const MACROBLOCKD *xd) {
176 0 : return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p5(xd)][4];
177 : }
178 : #endif // CONFIG_EXT_REFS
179 :
180 : #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
181 : int av1_get_inter_mode_context(const MACROBLOCKD *xd);
182 :
183 : static INLINE aom_prob av1_get_inter_mode_prob(const AV1_COMMON *cm,
184 : const MACROBLOCKD *xd) {
185 : return cm->fc->comp_inter_mode_prob[av1_get_inter_mode_context(xd)];
186 : }
187 : #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
188 :
189 : // Returns a context number for the given MB prediction signal
190 : // The mode info data structure has a one element border above and to the
191 : // left of the entries corresponding to real blocks.
192 : // The prediction flags in these dummy entries are initialized to 0.
193 0 : static INLINE int get_tx_size_context(const MACROBLOCKD *xd) {
194 0 : const int max_tx_size = max_txsize_lookup[xd->mi[0]->mbmi.sb_type];
195 0 : const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
196 0 : const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
197 0 : const int has_above = xd->up_available;
198 0 : const int has_left = xd->left_available;
199 0 : int above_ctx = (has_above && !above_mbmi->skip)
200 0 : ? (int)txsize_sqr_map[above_mbmi->tx_size]
201 0 : : max_tx_size;
202 0 : int left_ctx = (has_left && !left_mbmi->skip)
203 0 : ? (int)txsize_sqr_map[left_mbmi->tx_size]
204 0 : : max_tx_size;
205 :
206 0 : if (!has_left) left_ctx = above_ctx;
207 :
208 0 : if (!has_above) above_ctx = left_ctx;
209 0 : return (above_ctx + left_ctx) > max_tx_size + TX_SIZE_LUMA_MIN;
210 : }
211 :
212 : #if CONFIG_VAR_TX
213 0 : static void update_tx_counts(AV1_COMMON *cm, MACROBLOCKD *xd,
214 : MB_MODE_INFO *mbmi, BLOCK_SIZE plane_bsize,
215 : TX_SIZE tx_size, int blk_row, int blk_col,
216 : TX_SIZE max_tx_size, int ctx) {
217 0 : const struct macroblockd_plane *const pd = &xd->plane[0];
218 0 : const BLOCK_SIZE bsize = txsize_to_bsize[tx_size];
219 0 : const int tx_row = blk_row >> (1 - pd->subsampling_y);
220 0 : const int tx_col = blk_col >> (1 - pd->subsampling_x);
221 0 : const TX_SIZE plane_tx_size = mbmi->inter_tx_size[tx_row][tx_col];
222 0 : const int max_blocks_high = max_block_high(xd, plane_bsize, 0);
223 0 : const int max_blocks_wide = max_block_wide(xd, plane_bsize, 0);
224 :
225 0 : if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
226 :
227 0 : if (tx_size == plane_tx_size) {
228 : int depth;
229 0 : depth = tx_size_to_depth(tx_size);
230 0 : ++xd->counts->tx_size[max_tx_size - TX_SIZE_CTX_MIN][ctx][depth];
231 0 : mbmi->tx_size = tx_size;
232 : } else {
233 0 : int bsl = b_width_log2_lookup[bsize];
234 : int i;
235 :
236 0 : assert(bsl > 0);
237 0 : --bsl;
238 :
239 0 : for (i = 0; i < 4; ++i) {
240 0 : const int offsetr = blk_row + ((i >> 1) << bsl);
241 0 : const int offsetc = blk_col + ((i & 0x01) << bsl);
242 :
243 0 : if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue;
244 0 : update_tx_counts(cm, xd, mbmi, plane_bsize, (TX_SIZE)(tx_size - 1),
245 : offsetr, offsetc, max_tx_size, ctx);
246 : }
247 : }
248 : }
249 :
250 : static INLINE void inter_block_tx_count_update(AV1_COMMON *cm, MACROBLOCKD *xd,
251 : MB_MODE_INFO *mbmi,
252 : BLOCK_SIZE plane_bsize,
253 : int ctx) {
254 : const int mi_width = block_size_wide[plane_bsize] >> tx_size_wide_log2[0];
255 : const int mi_height = block_size_high[plane_bsize] >> tx_size_wide_log2[0];
256 : TX_SIZE max_tx_size = max_txsize_lookup[plane_bsize];
257 : int bh = tx_size_wide_unit[max_tx_size];
258 : int idx, idy;
259 :
260 : for (idy = 0; idy < mi_height; idy += bh)
261 : for (idx = 0; idx < mi_width; idx += bh)
262 : update_tx_counts(cm, xd, mbmi, plane_bsize, max_tx_size, idy, idx,
263 : max_tx_size, ctx);
264 : }
265 : #endif
266 :
267 : #ifdef __cplusplus
268 : } // extern "C"
269 : #endif
270 :
271 : #endif // AV1_COMMON_PRED_COMMON_H_
|