pred_common.h 16 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12 13
#ifndef AV1_COMMON_PRED_COMMON_H_
#define AV1_COMMON_PRED_COMMON_H_
Jingning Han's avatar
Jingning Han committed
14

15 16
#include "av1/common/blockd.h"
#include "av1/common/onyxc_int.h"
Yaowu Xu's avatar
Yaowu Xu committed
17
#include "aom_dsp/aom_dsp_common.h"
Jingning Han's avatar
Jingning Han committed
18 19 20 21

#ifdef __cplusplus
extern "C" {
#endif
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

#if CONFIG_Q_SEGMENTATION
/* Picks CDFs based on number of matching segment IDs */
static INLINE int pick_q_seg_cdf(int prev_ul, int prev_u, int prev_l) {
  if ((prev_ul == prev_u) && (prev_ul == prev_l))
    return 2;
  else if ((prev_ul == prev_u) || (prev_ul == prev_l) || (prev_u == prev_l))
    return 1;
  else
    return 0;
}

static INLINE int pick_q_seg_pred(int prev_ul, int prev_u, int prev_l) {
  /* If 2 or more are identical returns that as predictor, otherwise prev_l */
  return (prev_ul == prev_u) ? prev_u : prev_l;
}

static INLINE void set_q_segment_id(const AV1_COMMON *const cm,
                                    uint8_t *segment_ids, BLOCK_SIZE bsize,
                                    int mi_row, int mi_col, int segment_id) {
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
  const int bw = mi_size_wide[bsize];
  const int bh = mi_size_high[bsize];
  const int xmis = AOMMIN(cm->mi_cols - mi_col, bw);
  const int ymis = AOMMIN(cm->mi_rows - mi_row, bh);
  int x, y;

  for (y = 0; y < ymis; ++y)
    for (x = 0; x < xmis; ++x)
      segment_ids[mi_offset + y * cm->mi_cols + x] = segment_id;
}
#endif
Jingning Han's avatar
Jingning Han committed
54

55
static INLINE int get_segment_id(const AV1_COMMON *const cm,
clang-format's avatar
clang-format committed
56 57
                                 const uint8_t *segment_ids, BLOCK_SIZE bsize,
                                 int mi_row, int mi_col) {
Jingning Han's avatar
Jingning Han committed
58
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
59 60
  const int bw = mi_size_wide[bsize];
  const int bh = mi_size_high[bsize];
Yaowu Xu's avatar
Yaowu Xu committed
61 62
  const int xmis = AOMMIN(cm->mi_cols - mi_col, bw);
  const int ymis = AOMMIN(cm->mi_rows - mi_row, bh);
Jingning Han's avatar
Jingning Han committed
63 64 65 66
  int x, y, segment_id = MAX_SEGMENTS;

  for (y = 0; y < ymis; ++y)
    for (x = 0; x < xmis; ++x)
67
      segment_id =
Yaowu Xu's avatar
Yaowu Xu committed
68
          AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Jingning Han's avatar
Jingning Han committed
69 70 71 72 73

  assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
  return segment_id;
}

Yaowu Xu's avatar
Yaowu Xu committed
74
static INLINE int av1_get_pred_context_seg_id(const MACROBLOCKD *xd) {
Jingning Han's avatar
Jingning Han committed
75 76
  const MODE_INFO *const above_mi = xd->above_mi;
  const MODE_INFO *const left_mi = xd->left_mi;
clang-format's avatar
clang-format committed
77 78
  const int above_sip =
      (above_mi != NULL) ? above_mi->mbmi.seg_id_predicted : 0;
Jingning Han's avatar
Jingning Han committed
79 80 81 82 83
  const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0;

  return above_sip + left_sip;
}

Yaowu Xu's avatar
Yaowu Xu committed
84
static INLINE aom_prob av1_get_pred_prob_seg_id(
85
    const struct segmentation_probs *segp, const MACROBLOCKD *xd) {
Yaowu Xu's avatar
Yaowu Xu committed
86
  return segp->pred_probs[av1_get_pred_context_seg_id(xd)];
Jingning Han's avatar
Jingning Han committed
87 88
}

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
#if CONFIG_JNT_COMP
static INLINE int get_comp_index_context(const AV1_COMMON *cm,
                                         const MACROBLOCKD *xd) {
  MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
  int bck_idx = cm->frame_refs[mbmi->ref_frame[0] - LAST_FRAME].idx;
  int fwd_idx = cm->frame_refs[mbmi->ref_frame[1] - LAST_FRAME].idx;
  int bck_frame_index = 0, fwd_frame_index = 0;
  int cur_frame_index = cm->cur_frame->cur_frame_offset;

  if (bck_idx >= 0)
    bck_frame_index = cm->buffer_pool->frame_bufs[bck_idx].cur_frame_offset;

  if (fwd_idx >= 0)
    fwd_frame_index = cm->buffer_pool->frame_bufs[fwd_idx].cur_frame_offset;
  int fwd = abs(fwd_frame_index - cur_frame_index);
  int bck = abs(cur_frame_index - bck_frame_index);

  const MODE_INFO *const above_mi = xd->above_mi;
  const MODE_INFO *const left_mi = xd->left_mi;

  int above_ctx = 0, left_ctx = 0;
110
  const int offset = (fwd == bck);
111 112 113

  if (above_mi) {
    const MB_MODE_INFO *above_mbmi = &above_mi->mbmi;
114
    if (has_second_ref(above_mbmi))
115 116 117 118 119 120 121
      above_ctx = above_mbmi->compound_idx;
    else if (above_mbmi->ref_frame[0] == ALTREF_FRAME)
      above_ctx = 1;
  }

  if (left_mi) {
    const MB_MODE_INFO *left_mbmi = &left_mi->mbmi;
122
    if (has_second_ref(left_mbmi))
123 124 125 126 127 128 129 130 131
      left_ctx = left_mbmi->compound_idx;
    else if (left_mbmi->ref_frame[0] == ALTREF_FRAME)
      left_ctx = 1;
  }

  return above_ctx + left_ctx + 3 * offset;
}
#endif  // CONFIG_JNT_COMP

132 133 134 135 136
static INLINE aom_cdf_prob *av1_get_pred_cdf_seg_id(
    struct segmentation_probs *segp, const MACROBLOCKD *xd) {
  return segp->pred_cdf[av1_get_pred_context_seg_id(xd)];
}

Zoe Liu's avatar
Zoe Liu committed
137 138 139 140 141 142 143 144 145 146
#if CONFIG_EXT_SKIP
static INLINE int av1_get_skip_mode_context(const MACROBLOCKD *xd) {
  const MODE_INFO *const above_mi = xd->above_mi;
  const MODE_INFO *const left_mi = xd->left_mi;
  const int above_skip_mode = above_mi ? above_mi->mbmi.skip_mode : 0;
  const int left_skip_mode = left_mi ? left_mi->mbmi.skip_mode : 0;
  return above_skip_mode + left_skip_mode;
}
#endif  // CONFIG_EXT_SKIP

Yaowu Xu's avatar
Yaowu Xu committed
147
static INLINE int av1_get_skip_context(const MACROBLOCKD *xd) {
Jingning Han's avatar
Jingning Han committed
148 149 150 151 152 153 154
  const MODE_INFO *const above_mi = xd->above_mi;
  const MODE_INFO *const left_mi = xd->left_mi;
  const int above_skip = (above_mi != NULL) ? above_mi->mbmi.skip : 0;
  const int left_skip = (left_mi != NULL) ? left_mi->mbmi.skip : 0;
  return above_skip + left_skip;
}

155
#if CONFIG_DUAL_FILTER
Yaowu Xu's avatar
Yaowu Xu committed
156
int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir);
157
#else
Yaowu Xu's avatar
Yaowu Xu committed
158
int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
159
#endif
Jingning Han's avatar
Jingning Han committed
160

Urvang Joshi's avatar
Urvang Joshi committed
161
#if CONFIG_PALETTE_DELTA_ENCODING
162 163 164 165
// Get a list of palette base colors that are used in the above and left blocks,
// referred to as "color cache". The return value is the number of colors in the
// cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache"
// in ascending order.
166 167
int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
                          uint16_t *cache);
Urvang Joshi's avatar
Urvang Joshi committed
168
#endif  // CONFIG_PALETTE_DELTA_ENCODING
169

Yaowu Xu's avatar
Yaowu Xu committed
170
int av1_get_intra_inter_context(const MACROBLOCKD *xd);
Jingning Han's avatar
Jingning Han committed
171

Yaowu Xu's avatar
Yaowu Xu committed
172
int av1_get_reference_mode_context(const AV1_COMMON *cm, const MACROBLOCKD *xd);
Jingning Han's avatar
Jingning Han committed
173

Yaowu Xu's avatar
Yaowu Xu committed
174 175 176
static INLINE aom_prob av1_get_reference_mode_prob(const AV1_COMMON *cm,
                                                   const MACROBLOCKD *xd) {
  return cm->fc->comp_inter_prob[av1_get_reference_mode_context(cm, xd)];
Jingning Han's avatar
Jingning Han committed
177
}
178 179 180 181
static INLINE aom_cdf_prob *av1_get_reference_mode_cdf(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(cm, xd)];
}
Jingning Han's avatar
Jingning Han committed
182

Zoe Liu's avatar
Zoe Liu committed
183
#if CONFIG_EXT_COMP_REFS
184
int av1_get_comp_reference_type_context(const MACROBLOCKD *xd);
Zoe Liu's avatar
Zoe Liu committed
185 186 187

static INLINE aom_prob av1_get_comp_reference_type_prob(const AV1_COMMON *cm,
                                                        const MACROBLOCKD *xd) {
188
  return cm->fc->comp_ref_type_prob[av1_get_comp_reference_type_context(xd)];
Zoe Liu's avatar
Zoe Liu committed
189 190
}

191
int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd);
Zoe Liu's avatar
Zoe Liu committed
192 193 194

static INLINE aom_prob av1_get_pred_prob_uni_comp_ref_p(const AV1_COMMON *cm,
                                                        const MACROBLOCKD *xd) {
195
  const int pred_context = av1_get_pred_context_uni_comp_ref_p(xd);
Zoe Liu's avatar
Zoe Liu committed
196 197 198
  return cm->fc->uni_comp_ref_prob[pred_context][0];
}

199
int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd);
Zoe Liu's avatar
Zoe Liu committed
200 201 202

static INLINE aom_prob
av1_get_pred_prob_uni_comp_ref_p1(const AV1_COMMON *cm, const MACROBLOCKD *xd) {
203
  const int pred_context = av1_get_pred_context_uni_comp_ref_p1(xd);
Zoe Liu's avatar
Zoe Liu committed
204 205
  return cm->fc->uni_comp_ref_prob[pred_context][1];
}
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd);

static INLINE aom_prob
av1_get_pred_prob_uni_comp_ref_p2(const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_uni_comp_ref_p2(xd);
  return cm->fc->uni_comp_ref_prob[pred_context][2];
}

static INLINE aom_cdf_prob *av1_get_comp_reference_type_cdf(
    const MACROBLOCKD *xd) {
  const int pred_context = av1_get_comp_reference_type_context(xd);
  return xd->tile_ctx->comp_ref_type_cdf[pred_context];
}

static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p(
    const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_uni_comp_ref_p(xd);
  return xd->tile_ctx->uni_comp_ref_cdf[pred_context][0];
}

static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p1(
    const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_uni_comp_ref_p1(xd);
  return xd->tile_ctx->uni_comp_ref_cdf[pred_context][1];
}

static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p2(
    const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_uni_comp_ref_p2(xd);
  return xd->tile_ctx->uni_comp_ref_cdf[pred_context][2];
}
Zoe Liu's avatar
Zoe Liu committed
238 239
#endif  // CONFIG_EXT_COMP_REFS

Yaowu Xu's avatar
Yaowu Xu committed
240 241
int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
                                    const MACROBLOCKD *xd);
Jingning Han's avatar
Jingning Han committed
242

243 244 245 246 247 248
static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p(const AV1_COMMON *cm,
                                                        const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_ref_p(cm, xd);
  return xd->tile_ctx->comp_ref_cdf[pred_context][0];
}

Yaowu Xu's avatar
Yaowu Xu committed
249 250 251
static INLINE aom_prob av1_get_pred_prob_comp_ref_p(const AV1_COMMON *cm,
                                                    const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_ref_p(cm, xd);
252
  return cm->fc->comp_ref_prob[pred_context][0];
Jingning Han's avatar
Jingning Han committed
253 254
}

Yaowu Xu's avatar
Yaowu Xu committed
255 256
int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
                                     const MACROBLOCKD *xd);
257

258 259 260 261 262 263
static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p1(
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_ref_p1(cm, xd);
  return xd->tile_ctx->comp_ref_cdf[pred_context][1];
}

Yaowu Xu's avatar
Yaowu Xu committed
264 265 266
static INLINE aom_prob av1_get_pred_prob_comp_ref_p1(const AV1_COMMON *cm,
                                                     const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_ref_p1(cm, xd);
267 268 269
  return cm->fc->comp_ref_prob[pred_context][1];
}

Yaowu Xu's avatar
Yaowu Xu committed
270 271
int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm,
                                     const MACROBLOCKD *xd);
272

273 274 275 276 277 278
static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p2(
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_ref_p2(cm, xd);
  return xd->tile_ctx->comp_ref_cdf[pred_context][2];
}

Yaowu Xu's avatar
Yaowu Xu committed
279 280 281
static INLINE aom_prob av1_get_pred_prob_comp_ref_p2(const AV1_COMMON *cm,
                                                     const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_ref_p2(cm, xd);
282 283 284
  return cm->fc->comp_ref_prob[pred_context][2];
}

Yaowu Xu's avatar
Yaowu Xu committed
285 286
int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
                                       const MACROBLOCKD *xd);
287

288 289 290 291 292
static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p(
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_bwdref_p(cm, xd);
  return xd->tile_ctx->comp_bwdref_cdf[pred_context][0];
}
293

Yaowu Xu's avatar
Yaowu Xu committed
294 295 296
static INLINE aom_prob av1_get_pred_prob_comp_bwdref_p(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_bwdref_p(cm, xd);
297 298
  return cm->fc->comp_bwdref_prob[pred_context][0];
}
299 300 301 302

int av1_get_pred_context_comp_bwdref_p1(const AV1_COMMON *cm,
                                        const MACROBLOCKD *xd);

303 304 305 306 307 308
static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p1(
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_bwdref_p1(cm, xd);
  return xd->tile_ctx->comp_bwdref_cdf[pred_context][1];
}

309 310 311 312 313
static INLINE aom_prob av1_get_pred_prob_comp_bwdref_p1(const AV1_COMMON *cm,
                                                        const MACROBLOCKD *xd) {
  const int pred_context = av1_get_pred_context_comp_bwdref_p1(cm, xd);
  return cm->fc->comp_bwdref_prob[pred_context][1];
}
314

Yaowu Xu's avatar
Yaowu Xu committed
315
int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
Jingning Han's avatar
Jingning Han committed
316

Yaowu Xu's avatar
Yaowu Xu committed
317 318 319
static INLINE aom_prob av1_get_pred_prob_single_ref_p1(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p1(xd)][0];
Jingning Han's avatar
Jingning Han committed
320 321
}

Yaowu Xu's avatar
Yaowu Xu committed
322
int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd);
Jingning Han's avatar
Jingning Han committed
323

Yaowu Xu's avatar
Yaowu Xu committed
324 325 326
static INLINE aom_prob av1_get_pred_prob_single_ref_p2(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p2(xd)][1];
Jingning Han's avatar
Jingning Han committed
327 328
}

Yaowu Xu's avatar
Yaowu Xu committed
329
int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd);
330

Yaowu Xu's avatar
Yaowu Xu committed
331 332 333
static INLINE aom_prob av1_get_pred_prob_single_ref_p3(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p3(xd)][2];
334 335
}

Yaowu Xu's avatar
Yaowu Xu committed
336
int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd);
337

Yaowu Xu's avatar
Yaowu Xu committed
338 339 340
static INLINE aom_prob av1_get_pred_prob_single_ref_p4(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p4(xd)][3];
341 342
}

Yaowu Xu's avatar
Yaowu Xu committed
343
int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd);
344

Yaowu Xu's avatar
Yaowu Xu committed
345 346 347
static INLINE aom_prob av1_get_pred_prob_single_ref_p5(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p5(xd)][4];
348
}
349 350 351 352 353 354 355

int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd);

static INLINE aom_prob av1_get_pred_prob_single_ref_p6(const AV1_COMMON *cm,
                                                       const MACROBLOCKD *xd) {
  return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p6(xd)][5];
}
356

357
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p1(
358 359
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  (void)cm;
360 361 362 363
  return xd->tile_ctx
      ->single_ref_cdf[av1_get_pred_context_single_ref_p1(xd)][0];
}
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p2(
364 365
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  (void)cm;
366 367 368 369
  return xd->tile_ctx
      ->single_ref_cdf[av1_get_pred_context_single_ref_p2(xd)][1];
}
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p3(
370 371
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  (void)cm;
372 373 374 375
  return xd->tile_ctx
      ->single_ref_cdf[av1_get_pred_context_single_ref_p3(xd)][2];
}
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p4(
376 377
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  (void)cm;
378 379 380 381
  return xd->tile_ctx
      ->single_ref_cdf[av1_get_pred_context_single_ref_p4(xd)][3];
}
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p5(
382 383
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  (void)cm;
384 385 386
  return xd->tile_ctx
      ->single_ref_cdf[av1_get_pred_context_single_ref_p5(xd)][4];
}
387 388 389 390 391 392
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p6(
    const AV1_COMMON *cm, const MACROBLOCKD *xd) {
  (void)cm;
  return xd->tile_ctx
      ->single_ref_cdf[av1_get_pred_context_single_ref_p6(xd)][5];
}
393

Jingning Han's avatar
Jingning Han committed
394 395 396 397 398 399 400 401 402 403
// Returns a context number for the given MB prediction signal
// The mode info data structure has a one element border above and to the
// left of the entries corresponding to real blocks.
// The prediction flags in these dummy entries are initialized to 0.
static INLINE int get_tx_size_context(const MACROBLOCKD *xd) {
  const int max_tx_size = max_txsize_lookup[xd->mi[0]->mbmi.sb_type];
  const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
  const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
  const int has_above = xd->up_available;
  const int has_left = xd->left_available;
clang-format's avatar
clang-format committed
404 405 406 407 408 409
  int above_ctx = (has_above && !above_mbmi->skip)
                      ? (int)txsize_sqr_map[above_mbmi->tx_size]
                      : max_tx_size;
  int left_ctx = (has_left && !left_mbmi->skip)
                     ? (int)txsize_sqr_map[left_mbmi->tx_size]
                     : max_tx_size;
410

clang-format's avatar
clang-format committed
411
  if (!has_left) left_ctx = above_ctx;
Jingning Han's avatar
Jingning Han committed
412

clang-format's avatar
clang-format committed
413
  if (!has_above) above_ctx = left_ctx;
414
  return (above_ctx + left_ctx) > max_tx_size + TX_SIZE_LUMA_MIN;
Jingning Han's avatar
Jingning Han committed
415 416 417 418 419 420
}

#ifdef __cplusplus
}  // extern "C"
#endif

Yaowu Xu's avatar
Yaowu Xu committed
421
#endif  // AV1_COMMON_PRED_COMMON_H_