blob: 6a835c467cfaffb448054d3012aecba78e64efe6 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_PRED_COMMON_H_
13#define AV1_COMMON_PRED_COMMON_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "av1/common/blockd.h"
Imdad Sardharwallae68aa8a2018-03-07 18:52:54 +000016#include "av1/common/mvref_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017#include "av1/common/onyxc_int.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070018#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019
20#ifdef __cplusplus
21extern "C" {
22#endif
23
Urvang Joshi52648442016-10-13 17:27:51 -070024static INLINE int get_segment_id(const AV1_COMMON *const cm,
Yaowu Xuc27fc142016-08-22 16:08:15 -070025 const uint8_t *segment_ids, BLOCK_SIZE bsize,
26 int mi_row, int mi_col) {
27 const int mi_offset = mi_row * cm->mi_cols + mi_col;
Jingning Hanc709e1f2016-12-06 14:48:09 -080028 const int bw = mi_size_wide[bsize];
29 const int bh = mi_size_high[bsize];
Yaowu Xuf883b422016-08-30 14:01:10 -070030 const int xmis = AOMMIN(cm->mi_cols - mi_col, bw);
31 const int ymis = AOMMIN(cm->mi_rows - mi_row, bh);
Yaowu Xuc27fc142016-08-22 16:08:15 -070032 int x, y, segment_id = MAX_SEGMENTS;
33
34 for (y = 0; y < ymis; ++y)
35 for (x = 0; x < xmis; ++x)
36 segment_id =
Yaowu Xuf883b422016-08-30 14:01:10 -070037 AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Yaowu Xuc27fc142016-08-22 16:08:15 -070038
39 assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
40 return segment_id;
41}
42
Hui Sucff20b92018-03-13 15:35:52 -070043static INLINE int av1_get_spatial_seg_pred(const AV1_COMMON *const cm,
44 const MACROBLOCKD *const xd,
45 int mi_row, int mi_col,
46 int *cdf_index) {
47 int prev_ul = -1; // top left segment_id
48 int prev_l = -1; // left segment_id
49 int prev_u = -1; // top segment_id
50 if ((xd->up_available) && (xd->left_available)) {
51 prev_ul = get_segment_id(cm, cm->current_frame_seg_map, BLOCK_4X4,
52 mi_row - 1, mi_col - 1);
53 }
54 if (xd->up_available) {
55 prev_u = get_segment_id(cm, cm->current_frame_seg_map, BLOCK_4X4,
56 mi_row - 1, mi_col - 0);
57 }
58 if (xd->left_available) {
59 prev_l = get_segment_id(cm, cm->current_frame_seg_map, BLOCK_4X4,
60 mi_row - 0, mi_col - 1);
61 }
62
63 // Pick CDF index based on number of matching/out-of-bounds segment IDs.
David Barkera56736c2018-03-20 17:13:15 +000064 if (prev_ul < 0 || prev_u < 0 || prev_l < 0) /* Edge case */
65 *cdf_index = 0;
66 else if ((prev_ul == prev_u) && (prev_ul == prev_l))
Hui Sucff20b92018-03-13 15:35:52 -070067 *cdf_index = 2;
68 else if ((prev_ul == prev_u) || (prev_ul == prev_l) || (prev_u == prev_l))
69 *cdf_index = 1;
David Barkera56736c2018-03-20 17:13:15 +000070 else
71 *cdf_index = 0;
Hui Sucff20b92018-03-13 15:35:52 -070072
73 // If 2 or more are identical returns that as predictor, otherwise prev_l.
74 if (prev_u == -1) // edge case
75 return prev_l == -1 ? 0 : prev_l;
76 if (prev_l == -1) // edge case
77 return prev_u;
78 return (prev_ul == prev_u) ? prev_u : prev_l;
79}
Hui Sucff20b92018-03-13 15:35:52 -070080
Yaowu Xuf883b422016-08-30 14:01:10 -070081static INLINE int av1_get_pred_context_seg_id(const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -070082 const MB_MODE_INFO *const above_mi = xd->above_mbmi;
83 const MB_MODE_INFO *const left_mi = xd->left_mbmi;
84 const int above_sip = (above_mi != NULL) ? above_mi->seg_id_predicted : 0;
85 const int left_sip = (left_mi != NULL) ? left_mi->seg_id_predicted : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -070086
87 return above_sip + left_sip;
88}
89
Cheng Chen0a7f2f52017-10-10 15:16:09 -070090static INLINE int get_comp_index_context(const AV1_COMMON *cm,
91 const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -070092 MB_MODE_INFO *mbmi = xd->mi[0];
Cheng Chen0a7f2f52017-10-10 15:16:09 -070093 int bck_idx = cm->frame_refs[mbmi->ref_frame[0] - LAST_FRAME].idx;
94 int fwd_idx = cm->frame_refs[mbmi->ref_frame[1] - LAST_FRAME].idx;
95 int bck_frame_index = 0, fwd_frame_index = 0;
96 int cur_frame_index = cm->cur_frame->cur_frame_offset;
97
98 if (bck_idx >= 0)
99 bck_frame_index = cm->buffer_pool->frame_bufs[bck_idx].cur_frame_offset;
100
101 if (fwd_idx >= 0)
102 fwd_frame_index = cm->buffer_pool->frame_bufs[fwd_idx].cur_frame_offset;
Imdad Sardharwallae68aa8a2018-03-07 18:52:54 +0000103 int fwd = abs(get_relative_dist(cm, fwd_frame_index, cur_frame_index));
104 int bck = abs(get_relative_dist(cm, cur_frame_index, bck_frame_index));
Cheng Chen0a7f2f52017-10-10 15:16:09 -0700105
Yue Chen53b53f02018-03-29 14:31:23 -0700106 const MB_MODE_INFO *const above_mi = xd->above_mbmi;
107 const MB_MODE_INFO *const left_mi = xd->left_mbmi;
Cheng Chen0a7f2f52017-10-10 15:16:09 -0700108
109 int above_ctx = 0, left_ctx = 0;
Cheng Chenc87b3402017-11-03 16:02:41 -0700110 const int offset = (fwd == bck);
Cheng Chen0a7f2f52017-10-10 15:16:09 -0700111
112 if (above_mi) {
Yue Chen53b53f02018-03-29 14:31:23 -0700113 if (has_second_ref(above_mi))
114 above_ctx = above_mi->compound_idx;
115 else if (above_mi->ref_frame[0] == ALTREF_FRAME)
Cheng Chen0a7f2f52017-10-10 15:16:09 -0700116 above_ctx = 1;
117 }
118
119 if (left_mi) {
Yue Chen53b53f02018-03-29 14:31:23 -0700120 if (has_second_ref(left_mi))
121 left_ctx = left_mi->compound_idx;
122 else if (left_mi->ref_frame[0] == ALTREF_FRAME)
Cheng Chen0a7f2f52017-10-10 15:16:09 -0700123 left_ctx = 1;
124 }
125
126 return above_ctx + left_ctx + 3 * offset;
127}
Cheng Chen33a13d92017-11-28 16:49:59 -0800128
129static INLINE int get_comp_group_idx_context(const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -0700130 const MB_MODE_INFO *const above_mi = xd->above_mbmi;
131 const MB_MODE_INFO *const left_mi = xd->left_mbmi;
Cheng Chen33a13d92017-11-28 16:49:59 -0800132 int above_ctx = 0, left_ctx = 0;
133
134 if (above_mi) {
Yue Chen53b53f02018-03-29 14:31:23 -0700135 if (has_second_ref(above_mi))
136 above_ctx = above_mi->comp_group_idx;
137 else if (above_mi->ref_frame[0] == ALTREF_FRAME)
Cheng Chen5a881722017-11-30 17:05:10 -0800138 above_ctx = 3;
Cheng Chen33a13d92017-11-28 16:49:59 -0800139 }
140 if (left_mi) {
Yue Chen53b53f02018-03-29 14:31:23 -0700141 if (has_second_ref(left_mi))
142 left_ctx = left_mi->comp_group_idx;
143 else if (left_mi->ref_frame[0] == ALTREF_FRAME)
Cheng Chen5a881722017-11-30 17:05:10 -0800144 left_ctx = 3;
Cheng Chen33a13d92017-11-28 16:49:59 -0800145 }
146
Jingning Han0c3eb5a2018-03-26 15:29:12 -0700147 return AOMMIN(5, above_ctx + left_ctx);
Cheng Chen33a13d92017-11-28 16:49:59 -0800148}
Cheng Chen0a7f2f52017-10-10 15:16:09 -0700149
Thomas Davies00021352017-07-11 16:07:55 +0100150static INLINE aom_cdf_prob *av1_get_pred_cdf_seg_id(
151 struct segmentation_probs *segp, const MACROBLOCKD *xd) {
152 return segp->pred_cdf[av1_get_pred_context_seg_id(xd)];
153}
Thomas Davies00021352017-07-11 16:07:55 +0100154
Zoe Liuf704a1c2017-10-02 16:55:59 -0700155static INLINE int av1_get_skip_mode_context(const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -0700156 const MB_MODE_INFO *const above_mi = xd->above_mbmi;
157 const MB_MODE_INFO *const left_mi = xd->left_mbmi;
158 const int above_skip_mode = above_mi ? above_mi->skip_mode : 0;
159 const int left_skip_mode = left_mi ? left_mi->skip_mode : 0;
Zoe Liuf704a1c2017-10-02 16:55:59 -0700160 return above_skip_mode + left_skip_mode;
161}
Zoe Liuf704a1c2017-10-02 16:55:59 -0700162
Yaowu Xuf883b422016-08-30 14:01:10 -0700163static INLINE int av1_get_skip_context(const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -0700164 const MB_MODE_INFO *const above_mi = xd->above_mbmi;
165 const MB_MODE_INFO *const left_mi = xd->left_mbmi;
166 const int above_skip = above_mi ? above_mi->skip : 0;
167 const int left_skip = left_mi ? left_mi->skip : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700168 return above_skip + left_skip;
169}
170
Yaowu Xuf883b422016-08-30 14:01:10 -0700171int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700172
hui su33567b22017-04-30 16:40:19 -0700173// Get a list of palette base colors that are used in the above and left blocks,
174// referred to as "color cache". The return value is the number of colors in the
175// cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache"
176// in ascending order.
Hui Su3748bc22017-08-23 11:30:41 -0700177int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
178 uint16_t *cache);
hui su33567b22017-04-30 16:40:19 -0700179
Hui Suc1f411b2017-12-19 15:58:28 -0800180static INLINE int av1_get_palette_bsize_ctx(BLOCK_SIZE bsize) {
Hui Su476f0b52018-04-16 15:51:44 -0700181 return num_pels_log2_lookup[bsize] - num_pels_log2_lookup[BLOCK_8X8];
Hui Suc1f411b2017-12-19 15:58:28 -0800182}
183
Hui Sudb685552018-01-12 16:38:33 -0800184static INLINE int av1_get_palette_mode_ctx(const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -0700185 const MB_MODE_INFO *const above_mi = xd->above_mbmi;
186 const MB_MODE_INFO *const left_mi = xd->left_mbmi;
Hui Sudb685552018-01-12 16:38:33 -0800187 int ctx = 0;
Yue Chen53b53f02018-03-29 14:31:23 -0700188 if (above_mi) ctx += (above_mi->palette_mode_info.palette_size[0] > 0);
189 if (left_mi) ctx += (left_mi->palette_mode_info.palette_size[0] > 0);
Hui Sudb685552018-01-12 16:38:33 -0800190 return ctx;
191}
192
Yaowu Xuf883b422016-08-30 14:01:10 -0700193int av1_get_intra_inter_context(const MACROBLOCKD *xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700194
Yaowu Xu6567c4a2018-03-19 21:39:31 -0700195int av1_get_reference_mode_context(const MACROBLOCKD *xd);
Yaowu Xuf883b422016-08-30 14:01:10 -0700196
Yaowu Xu6567c4a2018-03-19 21:39:31 -0700197static INLINE aom_cdf_prob *av1_get_reference_mode_cdf(const MACROBLOCKD *xd) {
198 return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(xd)];
Thomas Davies860def62017-06-14 10:00:03 +0100199}
Yaowu Xuf883b422016-08-30 14:01:10 -0700200
Zoe Liufcf5fa22017-06-26 16:00:38 -0700201int av1_get_comp_reference_type_context(const MACROBLOCKD *xd);
Zoe Liuc082bbc2017-05-17 13:31:37 -0700202
Zoe Liu49172952018-01-23 14:32:31 -0800203// == Uni-directional contexts ==
204
Zoe Liufcf5fa22017-06-26 16:00:38 -0700205int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd);
Zoe Liuc082bbc2017-05-17 13:31:37 -0700206
Zoe Liufcf5fa22017-06-26 16:00:38 -0700207int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd);
Zoe Liuc082bbc2017-05-17 13:31:37 -0700208
Zoe Liufcf5fa22017-06-26 16:00:38 -0700209int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd);
210
Zoe Liufcf5fa22017-06-26 16:00:38 -0700211static INLINE aom_cdf_prob *av1_get_comp_reference_type_cdf(
212 const MACROBLOCKD *xd) {
213 const int pred_context = av1_get_comp_reference_type_context(xd);
214 return xd->tile_ctx->comp_ref_type_cdf[pred_context];
215}
216
217static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p(
218 const MACROBLOCKD *xd) {
219 const int pred_context = av1_get_pred_context_uni_comp_ref_p(xd);
220 return xd->tile_ctx->uni_comp_ref_cdf[pred_context][0];
221}
222
223static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p1(
224 const MACROBLOCKD *xd) {
225 const int pred_context = av1_get_pred_context_uni_comp_ref_p1(xd);
226 return xd->tile_ctx->uni_comp_ref_cdf[pred_context][1];
227}
228
229static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p2(
230 const MACROBLOCKD *xd) {
231 const int pred_context = av1_get_pred_context_uni_comp_ref_p2(xd);
232 return xd->tile_ctx->uni_comp_ref_cdf[pred_context][2];
233}
Zoe Liuc082bbc2017-05-17 13:31:37 -0700234
Zoe Liu49172952018-01-23 14:32:31 -0800235// == Bi-directional contexts ==
Yaowu Xuc27fc142016-08-22 16:08:15 -0700236
Zoe Liu49172952018-01-23 14:32:31 -0800237int av1_get_pred_context_comp_ref_p(const MACROBLOCKD *xd);
238
239int av1_get_pred_context_comp_ref_p1(const MACROBLOCKD *xd);
240
241int av1_get_pred_context_comp_ref_p2(const MACROBLOCKD *xd);
242
243int av1_get_pred_context_comp_bwdref_p(const MACROBLOCKD *xd);
244
245int av1_get_pred_context_comp_bwdref_p1(const MACROBLOCKD *xd);
246
247static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p(const MACROBLOCKD *xd) {
248 const int pred_context = av1_get_pred_context_comp_ref_p(xd);
Thomas Davies894cc812017-06-22 17:51:33 +0100249 return xd->tile_ctx->comp_ref_cdf[pred_context][0];
250}
Thomas Davies894cc812017-06-22 17:51:33 +0100251
Thomas Davies894cc812017-06-22 17:51:33 +0100252static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p1(
Zoe Liu49172952018-01-23 14:32:31 -0800253 const MACROBLOCKD *xd) {
254 const int pred_context = av1_get_pred_context_comp_ref_p1(xd);
Thomas Davies894cc812017-06-22 17:51:33 +0100255 return xd->tile_ctx->comp_ref_cdf[pred_context][1];
256}
Thomas Davies894cc812017-06-22 17:51:33 +0100257
Thomas Davies894cc812017-06-22 17:51:33 +0100258static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p2(
Zoe Liu49172952018-01-23 14:32:31 -0800259 const MACROBLOCKD *xd) {
260 const int pred_context = av1_get_pred_context_comp_ref_p2(xd);
Thomas Davies894cc812017-06-22 17:51:33 +0100261 return xd->tile_ctx->comp_ref_cdf[pred_context][2];
262}
Thomas Davies894cc812017-06-22 17:51:33 +0100263
Thomas Davies894cc812017-06-22 17:51:33 +0100264static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p(
Zoe Liud15afb22018-02-08 17:10:51 -0800265 const MACROBLOCKD *xd) {
266 const int pred_context = av1_get_pred_context_comp_bwdref_p(xd);
Thomas Davies894cc812017-06-22 17:51:33 +0100267 return xd->tile_ctx->comp_bwdref_cdf[pred_context][0];
268}
Zoe Liu97ad0582017-02-09 10:51:00 -0800269
Zoe Liu3ac20932017-08-30 16:35:55 -0700270static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p1(
Zoe Liud15afb22018-02-08 17:10:51 -0800271 const MACROBLOCKD *xd) {
272 const int pred_context = av1_get_pred_context_comp_bwdref_p1(xd);
Zoe Liu3ac20932017-08-30 16:35:55 -0700273 return xd->tile_ctx->comp_bwdref_cdf[pred_context][1];
274}
Zoe Liu3ac20932017-08-30 16:35:55 -0700275
Zoe Liu49172952018-01-23 14:32:31 -0800276// == Single contexts ==
277
Yaowu Xuf883b422016-08-30 14:01:10 -0700278int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700279
Yaowu Xuf883b422016-08-30 14:01:10 -0700280int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700281
Yaowu Xuf883b422016-08-30 14:01:10 -0700282int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700283
Yaowu Xuf883b422016-08-30 14:01:10 -0700284int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285
Yaowu Xuf883b422016-08-30 14:01:10 -0700286int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700287
Zoe Liu97ad0582017-02-09 10:51:00 -0800288int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd);
289
Thomas Davies315f5782017-06-14 15:14:55 +0100290static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p1(
Zoe Liu50097b72018-02-09 10:35:43 -0800291 const MACROBLOCKD *xd) {
Thomas Davies315f5782017-06-14 15:14:55 +0100292 return xd->tile_ctx
293 ->single_ref_cdf[av1_get_pred_context_single_ref_p1(xd)][0];
294}
295static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p2(
Zoe Liu50097b72018-02-09 10:35:43 -0800296 const MACROBLOCKD *xd) {
Thomas Davies315f5782017-06-14 15:14:55 +0100297 return xd->tile_ctx
298 ->single_ref_cdf[av1_get_pred_context_single_ref_p2(xd)][1];
299}
300static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p3(
Zoe Liu50097b72018-02-09 10:35:43 -0800301 const MACROBLOCKD *xd) {
Thomas Davies315f5782017-06-14 15:14:55 +0100302 return xd->tile_ctx
303 ->single_ref_cdf[av1_get_pred_context_single_ref_p3(xd)][2];
304}
305static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p4(
Zoe Liu50097b72018-02-09 10:35:43 -0800306 const MACROBLOCKD *xd) {
Thomas Davies315f5782017-06-14 15:14:55 +0100307 return xd->tile_ctx
308 ->single_ref_cdf[av1_get_pred_context_single_ref_p4(xd)][3];
309}
310static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p5(
Zoe Liu50097b72018-02-09 10:35:43 -0800311 const MACROBLOCKD *xd) {
Thomas Davies315f5782017-06-14 15:14:55 +0100312 return xd->tile_ctx
313 ->single_ref_cdf[av1_get_pred_context_single_ref_p5(xd)][4];
314}
Zoe Liu3ac20932017-08-30 16:35:55 -0700315static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p6(
Zoe Liu50097b72018-02-09 10:35:43 -0800316 const MACROBLOCKD *xd) {
Zoe Liu3ac20932017-08-30 16:35:55 -0700317 return xd->tile_ctx
318 ->single_ref_cdf[av1_get_pred_context_single_ref_p6(xd)][5];
319}
Thomas Davies315f5782017-06-14 15:14:55 +0100320
Yaowu Xuc27fc142016-08-22 16:08:15 -0700321// Returns a context number for the given MB prediction signal
322// The mode info data structure has a one element border above and to the
323// left of the entries corresponding to real blocks.
324// The prediction flags in these dummy entries are initialized to 0.
Yaowu Xu25ff26a2018-02-26 11:20:10 -0800325static INLINE int get_tx_size_context(const MACROBLOCKD *xd) {
Yue Chen53b53f02018-03-29 14:31:23 -0700326 const MB_MODE_INFO *mbmi = xd->mi[0];
Jingning Han02384572018-02-21 11:28:59 -0800327 const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
328 const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
Jingning Hand26fde22018-02-21 09:24:37 -0800329 const TX_SIZE max_tx_size = max_txsize_rect_lookup[mbmi->sb_type];
Yue Chenee9c4d92018-01-11 00:50:09 -0800330 const int max_tx_wide = tx_size_wide[max_tx_size];
331 const int max_tx_high = tx_size_high[max_tx_size];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700332 const int has_above = xd->up_available;
333 const int has_left = xd->left_available;
Jingning Han3daa4fd2017-01-20 10:33:50 -0800334
Jingning Han02384572018-02-21 11:28:59 -0800335 int above = xd->above_txfm_context[0] >= max_tx_wide;
336 int left = xd->left_txfm_context[0] >= max_tx_high;
337
338 if (has_above)
339 if (is_inter_block(above_mbmi))
340 above = block_size_wide[above_mbmi->sb_type] >= max_tx_wide;
341
342 if (has_left)
343 if (is_inter_block(left_mbmi))
344 left = block_size_high[left_mbmi->sb_type] >= max_tx_high;
345
346 if (has_above && has_left)
347 return (above + left);
348 else if (has_above)
349 return above;
350 else if (has_left)
351 return left;
352 else
353 return 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700354}
355
Yaowu Xuc27fc142016-08-22 16:08:15 -0700356#ifdef __cplusplus
357} // extern "C"
358#endif
359
Yaowu Xuf883b422016-08-30 14:01:10 -0700360#endif // AV1_COMMON_PRED_COMMON_H_