1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_COMMON_PRED_COMMON_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_COMMON_PRED_COMMON_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include <stdint.h>
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_common_int.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/blockd.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/mvref_common.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/aom_dsp_common.h"
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
23*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
24*77c1e3ccSAndroid Build Coastguard Worker #endif
25*77c1e3ccSAndroid Build Coastguard Worker
get_segment_id(const CommonModeInfoParams * const mi_params,const uint8_t * segment_ids,BLOCK_SIZE bsize,int mi_row,int mi_col)26*77c1e3ccSAndroid Build Coastguard Worker static inline uint8_t get_segment_id(
27*77c1e3ccSAndroid Build Coastguard Worker const CommonModeInfoParams *const mi_params, const uint8_t *segment_ids,
28*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE bsize, int mi_row, int mi_col) {
29*77c1e3ccSAndroid Build Coastguard Worker const int mi_offset = mi_row * mi_params->mi_cols + mi_col;
30*77c1e3ccSAndroid Build Coastguard Worker const int bw = mi_size_wide[bsize];
31*77c1e3ccSAndroid Build Coastguard Worker const int bh = mi_size_high[bsize];
32*77c1e3ccSAndroid Build Coastguard Worker const int xmis = AOMMIN(mi_params->mi_cols - mi_col, bw);
33*77c1e3ccSAndroid Build Coastguard Worker const int ymis = AOMMIN(mi_params->mi_rows - mi_row, bh);
34*77c1e3ccSAndroid Build Coastguard Worker const int seg_stride = mi_params->mi_cols;
35*77c1e3ccSAndroid Build Coastguard Worker uint8_t segment_id = MAX_SEGMENTS;
36*77c1e3ccSAndroid Build Coastguard Worker
37*77c1e3ccSAndroid Build Coastguard Worker for (int y = 0; y < ymis; ++y) {
38*77c1e3ccSAndroid Build Coastguard Worker for (int x = 0; x < xmis; ++x) {
39*77c1e3ccSAndroid Build Coastguard Worker segment_id =
40*77c1e3ccSAndroid Build Coastguard Worker AOMMIN(segment_id, segment_ids[mi_offset + y * seg_stride + x]);
41*77c1e3ccSAndroid Build Coastguard Worker }
42*77c1e3ccSAndroid Build Coastguard Worker }
43*77c1e3ccSAndroid Build Coastguard Worker
44*77c1e3ccSAndroid Build Coastguard Worker assert(segment_id < MAX_SEGMENTS);
45*77c1e3ccSAndroid Build Coastguard Worker return segment_id;
46*77c1e3ccSAndroid Build Coastguard Worker }
47*77c1e3ccSAndroid Build Coastguard Worker
av1_get_spatial_seg_pred(const AV1_COMMON * const cm,const MACROBLOCKD * const xd,int * cdf_index,int skip_over4x4)48*77c1e3ccSAndroid Build Coastguard Worker static inline uint8_t av1_get_spatial_seg_pred(const AV1_COMMON *const cm,
49*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *const xd,
50*77c1e3ccSAndroid Build Coastguard Worker int *cdf_index,
51*77c1e3ccSAndroid Build Coastguard Worker int skip_over4x4) {
52*77c1e3ccSAndroid Build Coastguard Worker const int step_size = skip_over4x4 ? 2 : 1;
53*77c1e3ccSAndroid Build Coastguard Worker uint8_t prev_ul = UINT8_MAX; // top left segment_id
54*77c1e3ccSAndroid Build Coastguard Worker uint8_t prev_l = UINT8_MAX; // left segment_id
55*77c1e3ccSAndroid Build Coastguard Worker uint8_t prev_u = UINT8_MAX; // top segment_id
56*77c1e3ccSAndroid Build Coastguard Worker const int mi_row = xd->mi_row;
57*77c1e3ccSAndroid Build Coastguard Worker const int mi_col = xd->mi_col;
58*77c1e3ccSAndroid Build Coastguard Worker const CommonModeInfoParams *const mi_params = &cm->mi_params;
59*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *seg_map = cm->cur_frame->seg_map;
60*77c1e3ccSAndroid Build Coastguard Worker if ((xd->up_available) && (xd->left_available)) {
61*77c1e3ccSAndroid Build Coastguard Worker prev_ul = get_segment_id(mi_params, seg_map, BLOCK_4X4, mi_row - step_size,
62*77c1e3ccSAndroid Build Coastguard Worker mi_col - step_size);
63*77c1e3ccSAndroid Build Coastguard Worker }
64*77c1e3ccSAndroid Build Coastguard Worker if (xd->up_available) {
65*77c1e3ccSAndroid Build Coastguard Worker prev_u = get_segment_id(mi_params, seg_map, BLOCK_4X4, mi_row - step_size,
66*77c1e3ccSAndroid Build Coastguard Worker mi_col - 0);
67*77c1e3ccSAndroid Build Coastguard Worker }
68*77c1e3ccSAndroid Build Coastguard Worker if (xd->left_available) {
69*77c1e3ccSAndroid Build Coastguard Worker prev_l = get_segment_id(mi_params, seg_map, BLOCK_4X4, mi_row - 0,
70*77c1e3ccSAndroid Build Coastguard Worker mi_col - step_size);
71*77c1e3ccSAndroid Build Coastguard Worker }
72*77c1e3ccSAndroid Build Coastguard Worker assert(IMPLIES(prev_ul != UINT8_MAX,
73*77c1e3ccSAndroid Build Coastguard Worker prev_u != UINT8_MAX && prev_l != UINT8_MAX));
74*77c1e3ccSAndroid Build Coastguard Worker
75*77c1e3ccSAndroid Build Coastguard Worker // Pick CDF index based on number of matching/out-of-bounds segment IDs.
76*77c1e3ccSAndroid Build Coastguard Worker if (prev_ul == UINT8_MAX) /* Edge cases */
77*77c1e3ccSAndroid Build Coastguard Worker *cdf_index = 0;
78*77c1e3ccSAndroid Build Coastguard Worker else if ((prev_ul == prev_u) && (prev_ul == prev_l))
79*77c1e3ccSAndroid Build Coastguard Worker *cdf_index = 2;
80*77c1e3ccSAndroid Build Coastguard Worker else if ((prev_ul == prev_u) || (prev_ul == prev_l) || (prev_u == prev_l))
81*77c1e3ccSAndroid Build Coastguard Worker *cdf_index = 1;
82*77c1e3ccSAndroid Build Coastguard Worker else
83*77c1e3ccSAndroid Build Coastguard Worker *cdf_index = 0;
84*77c1e3ccSAndroid Build Coastguard Worker
85*77c1e3ccSAndroid Build Coastguard Worker // If 2 or more are identical returns that as predictor, otherwise prev_l.
86*77c1e3ccSAndroid Build Coastguard Worker if (prev_u == UINT8_MAX) // edge case
87*77c1e3ccSAndroid Build Coastguard Worker return prev_l == UINT8_MAX ? 0 : prev_l;
88*77c1e3ccSAndroid Build Coastguard Worker if (prev_l == UINT8_MAX) // edge case
89*77c1e3ccSAndroid Build Coastguard Worker return prev_u;
90*77c1e3ccSAndroid Build Coastguard Worker return (prev_ul == prev_u) ? prev_u : prev_l;
91*77c1e3ccSAndroid Build Coastguard Worker }
92*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_context_seg_id(const MACROBLOCKD * xd)93*77c1e3ccSAndroid Build Coastguard Worker static inline uint8_t av1_get_pred_context_seg_id(const MACROBLOCKD *xd) {
94*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mi = xd->above_mbmi;
95*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mi = xd->left_mbmi;
96*77c1e3ccSAndroid Build Coastguard Worker const int above_sip = (above_mi != NULL) ? above_mi->seg_id_predicted : 0;
97*77c1e3ccSAndroid Build Coastguard Worker const int left_sip = (left_mi != NULL) ? left_mi->seg_id_predicted : 0;
98*77c1e3ccSAndroid Build Coastguard Worker
99*77c1e3ccSAndroid Build Coastguard Worker return above_sip + left_sip;
100*77c1e3ccSAndroid Build Coastguard Worker }
101*77c1e3ccSAndroid Build Coastguard Worker
get_comp_index_context(const AV1_COMMON * cm,const MACROBLOCKD * xd)102*77c1e3ccSAndroid Build Coastguard Worker static inline int get_comp_index_context(const AV1_COMMON *cm,
103*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
104*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO *mbmi = xd->mi[0];
105*77c1e3ccSAndroid Build Coastguard Worker const RefCntBuffer *const bck_buf = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
106*77c1e3ccSAndroid Build Coastguard Worker const RefCntBuffer *const fwd_buf = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
107*77c1e3ccSAndroid Build Coastguard Worker int bck_frame_index = 0, fwd_frame_index = 0;
108*77c1e3ccSAndroid Build Coastguard Worker int cur_frame_index = cm->cur_frame->order_hint;
109*77c1e3ccSAndroid Build Coastguard Worker
110*77c1e3ccSAndroid Build Coastguard Worker if (bck_buf != NULL) bck_frame_index = bck_buf->order_hint;
111*77c1e3ccSAndroid Build Coastguard Worker if (fwd_buf != NULL) fwd_frame_index = fwd_buf->order_hint;
112*77c1e3ccSAndroid Build Coastguard Worker
113*77c1e3ccSAndroid Build Coastguard Worker int fwd = abs(get_relative_dist(&cm->seq_params->order_hint_info,
114*77c1e3ccSAndroid Build Coastguard Worker fwd_frame_index, cur_frame_index));
115*77c1e3ccSAndroid Build Coastguard Worker int bck = abs(get_relative_dist(&cm->seq_params->order_hint_info,
116*77c1e3ccSAndroid Build Coastguard Worker cur_frame_index, bck_frame_index));
117*77c1e3ccSAndroid Build Coastguard Worker
118*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mi = xd->above_mbmi;
119*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mi = xd->left_mbmi;
120*77c1e3ccSAndroid Build Coastguard Worker
121*77c1e3ccSAndroid Build Coastguard Worker int above_ctx = 0, left_ctx = 0;
122*77c1e3ccSAndroid Build Coastguard Worker const int offset = (fwd == bck);
123*77c1e3ccSAndroid Build Coastguard Worker
124*77c1e3ccSAndroid Build Coastguard Worker if (above_mi != NULL) {
125*77c1e3ccSAndroid Build Coastguard Worker if (has_second_ref(above_mi))
126*77c1e3ccSAndroid Build Coastguard Worker above_ctx = above_mi->compound_idx;
127*77c1e3ccSAndroid Build Coastguard Worker else if (above_mi->ref_frame[0] == ALTREF_FRAME)
128*77c1e3ccSAndroid Build Coastguard Worker above_ctx = 1;
129*77c1e3ccSAndroid Build Coastguard Worker }
130*77c1e3ccSAndroid Build Coastguard Worker
131*77c1e3ccSAndroid Build Coastguard Worker if (left_mi != NULL) {
132*77c1e3ccSAndroid Build Coastguard Worker if (has_second_ref(left_mi))
133*77c1e3ccSAndroid Build Coastguard Worker left_ctx = left_mi->compound_idx;
134*77c1e3ccSAndroid Build Coastguard Worker else if (left_mi->ref_frame[0] == ALTREF_FRAME)
135*77c1e3ccSAndroid Build Coastguard Worker left_ctx = 1;
136*77c1e3ccSAndroid Build Coastguard Worker }
137*77c1e3ccSAndroid Build Coastguard Worker
138*77c1e3ccSAndroid Build Coastguard Worker return above_ctx + left_ctx + 3 * offset;
139*77c1e3ccSAndroid Build Coastguard Worker }
140*77c1e3ccSAndroid Build Coastguard Worker
get_comp_group_idx_context(const MACROBLOCKD * xd)141*77c1e3ccSAndroid Build Coastguard Worker static inline int get_comp_group_idx_context(const MACROBLOCKD *xd) {
142*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mi = xd->above_mbmi;
143*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mi = xd->left_mbmi;
144*77c1e3ccSAndroid Build Coastguard Worker int above_ctx = 0, left_ctx = 0;
145*77c1e3ccSAndroid Build Coastguard Worker
146*77c1e3ccSAndroid Build Coastguard Worker if (above_mi) {
147*77c1e3ccSAndroid Build Coastguard Worker if (has_second_ref(above_mi))
148*77c1e3ccSAndroid Build Coastguard Worker above_ctx = above_mi->comp_group_idx;
149*77c1e3ccSAndroid Build Coastguard Worker else if (above_mi->ref_frame[0] == ALTREF_FRAME)
150*77c1e3ccSAndroid Build Coastguard Worker above_ctx = 3;
151*77c1e3ccSAndroid Build Coastguard Worker }
152*77c1e3ccSAndroid Build Coastguard Worker if (left_mi) {
153*77c1e3ccSAndroid Build Coastguard Worker if (has_second_ref(left_mi))
154*77c1e3ccSAndroid Build Coastguard Worker left_ctx = left_mi->comp_group_idx;
155*77c1e3ccSAndroid Build Coastguard Worker else if (left_mi->ref_frame[0] == ALTREF_FRAME)
156*77c1e3ccSAndroid Build Coastguard Worker left_ctx = 3;
157*77c1e3ccSAndroid Build Coastguard Worker }
158*77c1e3ccSAndroid Build Coastguard Worker
159*77c1e3ccSAndroid Build Coastguard Worker return AOMMIN(5, above_ctx + left_ctx);
160*77c1e3ccSAndroid Build Coastguard Worker }
161*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_seg_id(struct segmentation_probs * segp,const MACROBLOCKD * xd)162*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_seg_id(
163*77c1e3ccSAndroid Build Coastguard Worker struct segmentation_probs *segp, const MACROBLOCKD *xd) {
164*77c1e3ccSAndroid Build Coastguard Worker return segp->pred_cdf[av1_get_pred_context_seg_id(xd)];
165*77c1e3ccSAndroid Build Coastguard Worker }
166*77c1e3ccSAndroid Build Coastguard Worker
av1_get_skip_mode_context(const MACROBLOCKD * xd)167*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_skip_mode_context(const MACROBLOCKD *xd) {
168*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mi = xd->above_mbmi;
169*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mi = xd->left_mbmi;
170*77c1e3ccSAndroid Build Coastguard Worker const int above_skip_mode = above_mi ? above_mi->skip_mode : 0;
171*77c1e3ccSAndroid Build Coastguard Worker const int left_skip_mode = left_mi ? left_mi->skip_mode : 0;
172*77c1e3ccSAndroid Build Coastguard Worker return above_skip_mode + left_skip_mode;
173*77c1e3ccSAndroid Build Coastguard Worker }
174*77c1e3ccSAndroid Build Coastguard Worker
av1_get_skip_txfm_context(const MACROBLOCKD * xd)175*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_skip_txfm_context(const MACROBLOCKD *xd) {
176*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mi = xd->above_mbmi;
177*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mi = xd->left_mbmi;
178*77c1e3ccSAndroid Build Coastguard Worker const int above_skip_txfm = above_mi ? above_mi->skip_txfm : 0;
179*77c1e3ccSAndroid Build Coastguard Worker const int left_skip_txfm = left_mi ? left_mi->skip_txfm : 0;
180*77c1e3ccSAndroid Build Coastguard Worker return above_skip_txfm + left_skip_txfm;
181*77c1e3ccSAndroid Build Coastguard Worker }
182*77c1e3ccSAndroid Build Coastguard Worker
183*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir);
184*77c1e3ccSAndroid Build Coastguard Worker
185*77c1e3ccSAndroid Build Coastguard Worker // Get a list of palette base colors that are used in the above and left blocks,
186*77c1e3ccSAndroid Build Coastguard Worker // referred to as "color cache". The return value is the number of colors in the
187*77c1e3ccSAndroid Build Coastguard Worker // cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache"
188*77c1e3ccSAndroid Build Coastguard Worker // in ascending order.
189*77c1e3ccSAndroid Build Coastguard Worker int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
190*77c1e3ccSAndroid Build Coastguard Worker uint16_t *cache);
191*77c1e3ccSAndroid Build Coastguard Worker
av1_get_palette_bsize_ctx(BLOCK_SIZE bsize)192*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_palette_bsize_ctx(BLOCK_SIZE bsize) {
193*77c1e3ccSAndroid Build Coastguard Worker assert(bsize < BLOCK_SIZES_ALL);
194*77c1e3ccSAndroid Build Coastguard Worker return num_pels_log2_lookup[bsize] - num_pels_log2_lookup[BLOCK_8X8];
195*77c1e3ccSAndroid Build Coastguard Worker }
196*77c1e3ccSAndroid Build Coastguard Worker
av1_get_palette_mode_ctx(const MACROBLOCKD * xd)197*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_palette_mode_ctx(const MACROBLOCKD *xd) {
198*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mi = xd->above_mbmi;
199*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mi = xd->left_mbmi;
200*77c1e3ccSAndroid Build Coastguard Worker int ctx = 0;
201*77c1e3ccSAndroid Build Coastguard Worker if (above_mi) ctx += (above_mi->palette_mode_info.palette_size[0] > 0);
202*77c1e3ccSAndroid Build Coastguard Worker if (left_mi) ctx += (left_mi->palette_mode_info.palette_size[0] > 0);
203*77c1e3ccSAndroid Build Coastguard Worker return ctx;
204*77c1e3ccSAndroid Build Coastguard Worker }
205*77c1e3ccSAndroid Build Coastguard Worker
206*77c1e3ccSAndroid Build Coastguard Worker int av1_get_intra_inter_context(const MACROBLOCKD *xd);
207*77c1e3ccSAndroid Build Coastguard Worker
208*77c1e3ccSAndroid Build Coastguard Worker int av1_get_reference_mode_context(const MACROBLOCKD *xd);
209*77c1e3ccSAndroid Build Coastguard Worker
av1_get_reference_mode_cdf(const MACROBLOCKD * xd)210*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_reference_mode_cdf(const MACROBLOCKD *xd) {
211*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(xd)];
212*77c1e3ccSAndroid Build Coastguard Worker }
213*77c1e3ccSAndroid Build Coastguard Worker
av1_get_skip_txfm_cdf(const MACROBLOCKD * xd)214*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_skip_txfm_cdf(const MACROBLOCKD *xd) {
215*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->skip_txfm_cdfs[av1_get_skip_txfm_context(xd)];
216*77c1e3ccSAndroid Build Coastguard Worker }
217*77c1e3ccSAndroid Build Coastguard Worker
218*77c1e3ccSAndroid Build Coastguard Worker int av1_get_comp_reference_type_context(const MACROBLOCKD *xd);
219*77c1e3ccSAndroid Build Coastguard Worker
220*77c1e3ccSAndroid Build Coastguard Worker // == Uni-directional contexts ==
221*77c1e3ccSAndroid Build Coastguard Worker
222*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd);
223*77c1e3ccSAndroid Build Coastguard Worker
224*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd);
225*77c1e3ccSAndroid Build Coastguard Worker
226*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd);
227*77c1e3ccSAndroid Build Coastguard Worker
av1_get_comp_reference_type_cdf(const MACROBLOCKD * xd)228*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_comp_reference_type_cdf(
229*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
230*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_comp_reference_type_context(xd);
231*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_ref_type_cdf[pred_context];
232*77c1e3ccSAndroid Build Coastguard Worker }
233*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_uni_comp_ref_p(const MACROBLOCKD * xd)234*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p(
235*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
236*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_uni_comp_ref_p(xd);
237*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->uni_comp_ref_cdf[pred_context][0];
238*77c1e3ccSAndroid Build Coastguard Worker }
239*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_uni_comp_ref_p1(const MACROBLOCKD * xd)240*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p1(
241*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
242*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_uni_comp_ref_p1(xd);
243*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->uni_comp_ref_cdf[pred_context][1];
244*77c1e3ccSAndroid Build Coastguard Worker }
245*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_uni_comp_ref_p2(const MACROBLOCKD * xd)246*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p2(
247*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
248*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_uni_comp_ref_p2(xd);
249*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->uni_comp_ref_cdf[pred_context][2];
250*77c1e3ccSAndroid Build Coastguard Worker }
251*77c1e3ccSAndroid Build Coastguard Worker
252*77c1e3ccSAndroid Build Coastguard Worker // == Bi-directional contexts ==
253*77c1e3ccSAndroid Build Coastguard Worker
254*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_comp_ref_p(const MACROBLOCKD *xd);
255*77c1e3ccSAndroid Build Coastguard Worker
256*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_comp_ref_p1(const MACROBLOCKD *xd);
257*77c1e3ccSAndroid Build Coastguard Worker
258*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_comp_ref_p2(const MACROBLOCKD *xd);
259*77c1e3ccSAndroid Build Coastguard Worker
260*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_comp_bwdref_p(const MACROBLOCKD *xd);
261*77c1e3ccSAndroid Build Coastguard Worker
262*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_comp_bwdref_p1(const MACROBLOCKD *xd);
263*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_comp_ref_p(const MACROBLOCKD * xd)264*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_comp_ref_p(const MACROBLOCKD *xd) {
265*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_comp_ref_p(xd);
266*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_ref_cdf[pred_context][0];
267*77c1e3ccSAndroid Build Coastguard Worker }
268*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_comp_ref_p1(const MACROBLOCKD * xd)269*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_comp_ref_p1(
270*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
271*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_comp_ref_p1(xd);
272*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_ref_cdf[pred_context][1];
273*77c1e3ccSAndroid Build Coastguard Worker }
274*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_comp_ref_p2(const MACROBLOCKD * xd)275*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_comp_ref_p2(
276*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
277*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_comp_ref_p2(xd);
278*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_ref_cdf[pred_context][2];
279*77c1e3ccSAndroid Build Coastguard Worker }
280*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_comp_bwdref_p(const MACROBLOCKD * xd)281*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p(
282*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
283*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_comp_bwdref_p(xd);
284*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_bwdref_cdf[pred_context][0];
285*77c1e3ccSAndroid Build Coastguard Worker }
286*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_comp_bwdref_p1(const MACROBLOCKD * xd)287*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p1(
288*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
289*77c1e3ccSAndroid Build Coastguard Worker const int pred_context = av1_get_pred_context_comp_bwdref_p1(xd);
290*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx->comp_bwdref_cdf[pred_context][1];
291*77c1e3ccSAndroid Build Coastguard Worker }
292*77c1e3ccSAndroid Build Coastguard Worker
293*77c1e3ccSAndroid Build Coastguard Worker // == Single contexts ==
294*77c1e3ccSAndroid Build Coastguard Worker
295*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
296*77c1e3ccSAndroid Build Coastguard Worker
297*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
298*77c1e3ccSAndroid Build Coastguard Worker
299*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd);
300*77c1e3ccSAndroid Build Coastguard Worker
301*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd);
302*77c1e3ccSAndroid Build Coastguard Worker
303*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd);
304*77c1e3ccSAndroid Build Coastguard Worker
305*77c1e3ccSAndroid Build Coastguard Worker int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd);
306*77c1e3ccSAndroid Build Coastguard Worker
av1_get_pred_cdf_single_ref_p1(const MACROBLOCKD * xd)307*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_single_ref_p1(
308*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
309*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx
310*77c1e3ccSAndroid Build Coastguard Worker ->single_ref_cdf[av1_get_pred_context_single_ref_p1(xd)][0];
311*77c1e3ccSAndroid Build Coastguard Worker }
av1_get_pred_cdf_single_ref_p2(const MACROBLOCKD * xd)312*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_single_ref_p2(
313*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
314*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx
315*77c1e3ccSAndroid Build Coastguard Worker ->single_ref_cdf[av1_get_pred_context_single_ref_p2(xd)][1];
316*77c1e3ccSAndroid Build Coastguard Worker }
av1_get_pred_cdf_single_ref_p3(const MACROBLOCKD * xd)317*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_single_ref_p3(
318*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
319*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx
320*77c1e3ccSAndroid Build Coastguard Worker ->single_ref_cdf[av1_get_pred_context_single_ref_p3(xd)][2];
321*77c1e3ccSAndroid Build Coastguard Worker }
av1_get_pred_cdf_single_ref_p4(const MACROBLOCKD * xd)322*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_single_ref_p4(
323*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
324*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx
325*77c1e3ccSAndroid Build Coastguard Worker ->single_ref_cdf[av1_get_pred_context_single_ref_p4(xd)][3];
326*77c1e3ccSAndroid Build Coastguard Worker }
av1_get_pred_cdf_single_ref_p5(const MACROBLOCKD * xd)327*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_single_ref_p5(
328*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
329*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx
330*77c1e3ccSAndroid Build Coastguard Worker ->single_ref_cdf[av1_get_pred_context_single_ref_p5(xd)][4];
331*77c1e3ccSAndroid Build Coastguard Worker }
av1_get_pred_cdf_single_ref_p6(const MACROBLOCKD * xd)332*77c1e3ccSAndroid Build Coastguard Worker static inline aom_cdf_prob *av1_get_pred_cdf_single_ref_p6(
333*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd) {
334*77c1e3ccSAndroid Build Coastguard Worker return xd->tile_ctx
335*77c1e3ccSAndroid Build Coastguard Worker ->single_ref_cdf[av1_get_pred_context_single_ref_p6(xd)][5];
336*77c1e3ccSAndroid Build Coastguard Worker }
337*77c1e3ccSAndroid Build Coastguard Worker
338*77c1e3ccSAndroid Build Coastguard Worker // Returns a context number for the given MB prediction signal
339*77c1e3ccSAndroid Build Coastguard Worker // The mode info data structure has a one element border above and to the
340*77c1e3ccSAndroid Build Coastguard Worker // left of the entries corresponding to real blocks.
341*77c1e3ccSAndroid Build Coastguard Worker // The prediction flags in these dummy entries are initialized to 0.
get_tx_size_context(const MACROBLOCKD * xd)342*77c1e3ccSAndroid Build Coastguard Worker static inline int get_tx_size_context(const MACROBLOCKD *xd) {
343*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *mbmi = xd->mi[0];
344*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
345*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
346*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE max_tx_size = max_txsize_rect_lookup[mbmi->bsize];
347*77c1e3ccSAndroid Build Coastguard Worker const int max_tx_wide = tx_size_wide[max_tx_size];
348*77c1e3ccSAndroid Build Coastguard Worker const int max_tx_high = tx_size_high[max_tx_size];
349*77c1e3ccSAndroid Build Coastguard Worker const int has_above = xd->up_available;
350*77c1e3ccSAndroid Build Coastguard Worker const int has_left = xd->left_available;
351*77c1e3ccSAndroid Build Coastguard Worker
352*77c1e3ccSAndroid Build Coastguard Worker int above = xd->above_txfm_context[0] >= max_tx_wide;
353*77c1e3ccSAndroid Build Coastguard Worker int left = xd->left_txfm_context[0] >= max_tx_high;
354*77c1e3ccSAndroid Build Coastguard Worker
355*77c1e3ccSAndroid Build Coastguard Worker if (has_above)
356*77c1e3ccSAndroid Build Coastguard Worker if (is_inter_block(above_mbmi))
357*77c1e3ccSAndroid Build Coastguard Worker above = block_size_wide[above_mbmi->bsize] >= max_tx_wide;
358*77c1e3ccSAndroid Build Coastguard Worker
359*77c1e3ccSAndroid Build Coastguard Worker if (has_left)
360*77c1e3ccSAndroid Build Coastguard Worker if (is_inter_block(left_mbmi))
361*77c1e3ccSAndroid Build Coastguard Worker left = block_size_high[left_mbmi->bsize] >= max_tx_high;
362*77c1e3ccSAndroid Build Coastguard Worker
363*77c1e3ccSAndroid Build Coastguard Worker if (has_above && has_left)
364*77c1e3ccSAndroid Build Coastguard Worker return (above + left);
365*77c1e3ccSAndroid Build Coastguard Worker else if (has_above)
366*77c1e3ccSAndroid Build Coastguard Worker return above;
367*77c1e3ccSAndroid Build Coastguard Worker else if (has_left)
368*77c1e3ccSAndroid Build Coastguard Worker return left;
369*77c1e3ccSAndroid Build Coastguard Worker else
370*77c1e3ccSAndroid Build Coastguard Worker return 0;
371*77c1e3ccSAndroid Build Coastguard Worker }
372*77c1e3ccSAndroid Build Coastguard Worker
373*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
374*77c1e3ccSAndroid Build Coastguard Worker } // extern "C"
375*77c1e3ccSAndroid Build Coastguard Worker #endif
376*77c1e3ccSAndroid Build Coastguard Worker
377*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AV1_COMMON_PRED_COMMON_H_
378