decodemv.c 71.4 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
12
13
 */

#include <assert.h>

14
15
16
17
18
19
20
#include "av1/common/common.h"
#include "av1/common/entropy.h"
#include "av1/common/entropymode.h"
#include "av1/common/entropymv.h"
#include "av1/common/mvref_common.h"
#include "av1/common/pred_common.h"
#include "av1/common/reconinter.h"
hui su's avatar
hui su committed
21
22
23
#if CONFIG_EXT_INTRA
#include "av1/common/reconintra.h"
#endif  // CONFIG_EXT_INTRA
24
#include "av1/common/seg_common.h"
Yue Chen's avatar
Yue Chen committed
25
26
27
#if CONFIG_WARPED_MOTION
#include "av1/common/warped_motion.h"
#endif  // CONFIG_WARPED_MOTION
28
29

#include "av1/decoder/decodeframe.h"
Jingning Han's avatar
Jingning Han committed
30
#include "av1/decoder/decodemv.h"
31

Yaowu Xu's avatar
Yaowu Xu committed
32
#include "aom_dsp/aom_dsp_common.h"
33

Michael Bebenita's avatar
Michael Bebenita committed
34
#define ACCT_STR __func__
35
#if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE
Yaowu Xu's avatar
Yaowu Xu committed
36
static INLINE int read_uniform(aom_reader *r, int n) {
hui su's avatar
hui su committed
37
38
  int l = get_unsigned_bits(n);
  int m = (1 << l) - n;
Michael Bebenita's avatar
Michael Bebenita committed
39
  int v = aom_read_literal(r, l - 1, ACCT_STR);
hui su's avatar
hui su committed
40
41
42
43
44
45

  assert(l != 0);

  if (v < m)
    return v;
  else
Michael Bebenita's avatar
Michael Bebenita committed
46
    return (v << 1) - m + aom_read_literal(r, 1, ACCT_STR);
hui su's avatar
hui su committed
47
}
48
#endif  // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE
hui su's avatar
hui su committed
49

50
#if CONFIG_EC_MULTISYMBOL
51
static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) {
52
53
54
  return (PREDICTION_MODE)
      av1_intra_mode_inv[aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR)];
}
55
#else
Yaowu Xu's avatar
Yaowu Xu committed
56
static PREDICTION_MODE read_intra_mode(aom_reader *r, const aom_prob *p) {
Michael Bebenita's avatar
Michael Bebenita committed
57
  return (PREDICTION_MODE)aom_read_tree(r, av1_intra_mode_tree, p, ACCT_STR);
Jingning Han's avatar
Jingning Han committed
58
}
59
#endif
Jingning Han's avatar
Jingning Han committed
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#if CONFIG_DELTA_Q
static int read_delta_qindex(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
                             MB_MODE_INFO *const mbmi, int mi_col, int mi_row) {
  FRAME_COUNTS *counts = xd->counts;
  int sign, abs, reduced_delta_qindex = 0;
  BLOCK_SIZE bsize = mbmi->sb_type;
  const int b_col = mi_col & MAX_MIB_MASK;
  const int b_row = mi_row & MAX_MIB_MASK;
  const int read_delta_q_flag = (b_col == 0 && b_row == 0);
  int rem_bits, thr, bit = 1;

  if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_q_flag) {
    abs = 0;
    while (abs < DELTA_Q_SMALL && bit) {
      bit = aom_read(r, cm->fc->delta_q_prob[abs], ACCT_STR);
      if (counts) counts->delta_q[abs][bit]++;
      abs += bit;
    }
    if (abs == DELTA_Q_SMALL) {
      rem_bits = aom_read_literal(r, 3, ACCT_STR);
      thr = (1 << rem_bits) + 1;
      abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr;
    }

    if (abs) {
      sign = aom_read_bit(r, ACCT_STR);
    } else {
      sign = 1;
    }

    reduced_delta_qindex = sign ? -abs : abs;
  }
  return reduced_delta_qindex;
}
#endif

Yaowu Xu's avatar
Yaowu Xu committed
97
98
static PREDICTION_MODE read_intra_mode_y(AV1_COMMON *cm, MACROBLOCKD *xd,
                                         aom_reader *r, int size_group) {
Jingning Han's avatar
Jingning Han committed
99
  const PREDICTION_MODE y_mode =
100
#if CONFIG_EC_MULTISYMBOL
101
      read_intra_mode(r, cm->fc->y_mode_cdf[size_group]);
102
#else
Jingning Han's avatar
Jingning Han committed
103
      read_intra_mode(r, cm->fc->y_mode_prob[size_group]);
104
#endif
Jingning Han's avatar
Jingning Han committed
105
  FRAME_COUNTS *counts = xd->counts;
106
  if (counts) ++counts->y_mode[size_group][y_mode];
Jingning Han's avatar
Jingning Han committed
107
108
109
  return y_mode;
}

Yaowu Xu's avatar
Yaowu Xu committed
110
111
static PREDICTION_MODE read_intra_mode_uv(AV1_COMMON *cm, MACROBLOCKD *xd,
                                          aom_reader *r,
Jingning Han's avatar
Jingning Han committed
112
                                          PREDICTION_MODE y_mode) {
113
  const PREDICTION_MODE uv_mode =
114
#if CONFIG_EC_MULTISYMBOL
115
116
      read_intra_mode(r, cm->fc->uv_mode_cdf[y_mode]);
#else
117
      read_intra_mode(r, cm->fc->uv_mode_prob[y_mode]);
118
#endif
Jingning Han's avatar
Jingning Han committed
119
  FRAME_COUNTS *counts = xd->counts;
120
  if (counts) ++counts->uv_mode[y_mode][uv_mode];
Jingning Han's avatar
Jingning Han committed
121
122
123
  return uv_mode;
}

124
#if CONFIG_EXT_INTER
Yaowu Xu's avatar
Yaowu Xu committed
125
126
127
static INTERINTRA_MODE read_interintra_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
                                            aom_reader *r, int size_group) {
  const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_tree(
Michael Bebenita's avatar
Michael Bebenita committed
128
129
      r, av1_interintra_mode_tree, cm->fc->interintra_mode_prob[size_group],
      ACCT_STR);
130
  FRAME_COUNTS *counts = xd->counts;
131
  if (counts) ++counts->interintra_mode[size_group][ii_mode];
132
133
134
135
  return ii_mode;
}
#endif  // CONFIG_EXT_INTER

Yaowu Xu's avatar
Yaowu Xu committed
136
static PREDICTION_MODE read_inter_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
Yue Chen's avatar
Yue Chen committed
137
138
139
#if CONFIG_REF_MV && CONFIG_EXT_INTER
                                       MB_MODE_INFO *mbmi,
#endif
Yaowu Xu's avatar
Yaowu Xu committed
140
                                       aom_reader *r, int16_t ctx) {
141
142
#if CONFIG_REF_MV
  FRAME_COUNTS *counts = xd->counts;
143
  int16_t mode_ctx = ctx & NEWMV_CTX_MASK;
Yaowu Xu's avatar
Yaowu Xu committed
144
  aom_prob mode_prob = cm->fc->newmv_prob[mode_ctx];
145

Michael Bebenita's avatar
Michael Bebenita committed
146
  if (aom_read(r, mode_prob, ACCT_STR) == 0) {
147
    if (counts) ++counts->newmv_mode[mode_ctx][0];
Yue Chen's avatar
Yue Chen committed
148
149
150
151

#if CONFIG_EXT_INTER
    if (has_second_ref(mbmi)) {
#endif  // CONFIG_EXT_INTER
152
      return NEWMV;
Yue Chen's avatar
Yue Chen committed
153
154
155
#if CONFIG_EXT_INTER
    } else {
      mode_prob = cm->fc->new2mv_prob;
Michael Bebenita's avatar
Michael Bebenita committed
156
      if (aom_read(r, mode_prob, ACCT_STR) == 0) {
157
        if (counts) ++counts->new2mv_mode[0];
Yue Chen's avatar
Yue Chen committed
158
159
        return NEWMV;
      } else {
160
        if (counts) ++counts->new2mv_mode[1];
Yue Chen's avatar
Yue Chen committed
161
162
163
164
        return NEWFROMNEARMV;
      }
    }
#endif  // CONFIG_EXT_INTER
165
  }
166
  if (counts) ++counts->newmv_mode[mode_ctx][1];
167

168
  if (ctx & (1 << ALL_ZERO_FLAG_OFFSET)) return ZEROMV;
169

170
  mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
171
172

  mode_prob = cm->fc->zeromv_prob[mode_ctx];
Michael Bebenita's avatar
Michael Bebenita committed
173
  if (aom_read(r, mode_prob, ACCT_STR) == 0) {
174
    if (counts) ++counts->zeromv_mode[mode_ctx][0];
175
176
    return ZEROMV;
  }
177
  if (counts) ++counts->zeromv_mode[mode_ctx][1];
178

179
  mode_ctx = (ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
180

181
182
183
  if (ctx & (1 << SKIP_NEARESTMV_OFFSET)) mode_ctx = 6;
  if (ctx & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7;
  if (ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8;
184

185
  mode_prob = cm->fc->refmv_prob[mode_ctx];
186

Michael Bebenita's avatar
Michael Bebenita committed
187
  if (aom_read(r, mode_prob, ACCT_STR) == 0) {
188
    if (counts) ++counts->refmv_mode[mode_ctx][0];
189

190
191
    return NEARESTMV;
  } else {
192
    if (counts) ++counts->refmv_mode[mode_ctx][1];
193
194
195
196
197
    return NEARMV;
  }

  // Invalid prediction mode.
  assert(0);
198
#else
199
#if CONFIG_EC_MULTISYMBOL
200
201
  const int mode = av1_inter_mode_inv[aom_read_symbol(
      r, cm->fc->inter_mode_cdf[ctx], INTER_MODES, ACCT_STR)];
202
#else
Michael Bebenita's avatar
Michael Bebenita committed
203
204
  const int mode = aom_read_tree(r, av1_inter_mode_tree,
                                 cm->fc->inter_mode_probs[ctx], ACCT_STR);
205
#endif
Jingning Han's avatar
Jingning Han committed
206
  FRAME_COUNTS *counts = xd->counts;
207
  if (counts) ++counts->inter_mode[ctx][mode];
Jingning Han's avatar
Jingning Han committed
208
209

  return NEARESTMV + mode;
210
#endif
Jingning Han's avatar
Jingning Han committed
211
212
}

213
#if CONFIG_REF_MV
Yaowu Xu's avatar
Yaowu Xu committed
214
215
216
static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
                         MB_MODE_INFO *mbmi, aom_reader *r) {
  uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
217
218
  mbmi->ref_mv_idx = 0;

219
220
221
222
  if (mbmi->mode == NEWMV) {
    int idx;
    for (idx = 0; idx < 2; ++idx) {
      if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
Yaowu Xu's avatar
Yaowu Xu committed
223
224
        uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
        aom_prob drl_prob = cm->fc->drl_prob[drl_ctx];
Michael Bebenita's avatar
Michael Bebenita committed
225
        if (!aom_read(r, drl_prob, ACCT_STR)) {
226
          mbmi->ref_mv_idx = idx;
227
          if (xd->counts) ++xd->counts->drl_mode[drl_ctx][0];
228
229
230
          return;
        }
        mbmi->ref_mv_idx = idx + 1;
231
        if (xd->counts) ++xd->counts->drl_mode[drl_ctx][1];
232
233
234
235
      }
    }
  }

236
237
238
239
240
241
242
  if (mbmi->mode == NEARMV) {
    int idx;
    // Offset the NEARESTMV mode.
    // TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV
    // mode is factored in.
    for (idx = 1; idx < 3; ++idx) {
      if (xd->ref_mv_count[ref_frame_type] > idx + 1) {
Yaowu Xu's avatar
Yaowu Xu committed
243
244
        uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
        aom_prob drl_prob = cm->fc->drl_prob[drl_ctx];
Michael Bebenita's avatar
Michael Bebenita committed
245
        if (!aom_read(r, drl_prob, ACCT_STR)) {
246
          mbmi->ref_mv_idx = idx - 1;
247
          if (xd->counts) ++xd->counts->drl_mode[drl_ctx][0];
248
249
          return;
        }
250
        mbmi->ref_mv_idx = idx;
251
        if (xd->counts) ++xd->counts->drl_mode[drl_ctx][1];
252
253
254
255
256
257
      }
    }
  }
}
#endif

Yaowu Xu's avatar
Yaowu Xu committed
258
259
260
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
                                    MB_MODE_INFO *mbmi, aom_reader *r) {
Yue Chen's avatar
Yue Chen committed
261
262
263
  MOTION_MODE last_motion_mode_allowed = motion_mode_allowed(mbmi);
  int motion_mode;
  FRAME_COUNTS *counts = xd->counts;
Yaowu Xu's avatar
Yaowu Xu committed
264

Yue Chen's avatar
Yue Chen committed
265
266
267
268
269
270
271
272
  if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION;
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
  if (last_motion_mode_allowed == OBMC_CAUSAL) {
    motion_mode = aom_read(r, cm->fc->obmc_prob[mbmi->sb_type], ACCT_STR);
    if (counts) ++counts->obmc[mbmi->sb_type][motion_mode];
    return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
  } else {
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
273
274
275
276
277
    motion_mode =
        aom_read_tree(r, av1_motion_mode_tree,
                      cm->fc->motion_mode_prob[mbmi->sb_type], ACCT_STR);
    if (counts) ++counts->motion_mode[mbmi->sb_type][motion_mode];
    return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
Yue Chen's avatar
Yue Chen committed
278
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
279
  }
Yue Chen's avatar
Yue Chen committed
280
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
281
282
283
}
#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION

284
#if CONFIG_EXT_INTER
Yaowu Xu's avatar
Yaowu Xu committed
285
286
static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
                                                aom_reader *r, int16_t ctx) {
Michael Bebenita's avatar
Michael Bebenita committed
287
288
289
  const int mode =
      aom_read_tree(r, av1_inter_compound_mode_tree,
                    cm->fc->inter_compound_mode_probs[ctx], ACCT_STR);
290
291
  FRAME_COUNTS *counts = xd->counts;

292
  if (counts) ++counts->inter_compound_mode[ctx][mode];
293
294
295
296
297
298

  assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode));
  return NEAREST_NEARESTMV + mode;
}
#endif  // CONFIG_EXT_INTER

299
static int read_segment_id(aom_reader *r, struct segmentation_probs *segp) {
300
#if CONFIG_EC_MULTISYMBOL
Michael Bebenita's avatar
Michael Bebenita committed
301
  return aom_read_symbol(r, segp->tree_cdf, MAX_SEGMENTS, ACCT_STR);
302
#else
Michael Bebenita's avatar
Michael Bebenita committed
303
  return aom_read_tree(r, av1_segment_tree, segp->tree_probs, ACCT_STR);
304
#endif
Jingning Han's avatar
Jingning Han committed
305
306
}

307
#if CONFIG_VAR_TX
Yaowu Xu's avatar
Yaowu Xu committed
308
static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd,
309
                               MB_MODE_INFO *mbmi, FRAME_COUNTS *counts,
310
311
                               TX_SIZE tx_size, int depth, int blk_row,
                               int blk_col, aom_reader *r) {
312
  int is_split = 0;
313
314
  const int tx_row = blk_row >> 1;
  const int tx_col = blk_col >> 1;
315
316
  const int max_blocks_high = max_block_high(xd, mbmi->sb_type, 0);
  const int max_blocks_wide = max_block_wide(xd, mbmi->sb_type, 0);
317
  int ctx = txfm_partition_context(xd->above_txfm_context + tx_col,
318
319
                                   xd->left_txfm_context + tx_row,
                                   mbmi->sb_type, tx_size);
clang-format's avatar
clang-format committed
320
  TX_SIZE(*const inter_tx_size)
321
322
323
  [MAX_MIB_SIZE] =
      (TX_SIZE(*)[MAX_MIB_SIZE]) & mbmi->inter_tx_size[tx_row][tx_col];
  if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
324

Jingning Han's avatar
Jingning Han committed
325
  if (depth == MAX_VARTX_DEPTH) {
326
327
    int idx, idy;
    inter_tx_size[0][0] = tx_size;
328
329
    for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
      for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
330
331
        inter_tx_size[idy][idx] = tx_size;
    mbmi->tx_size = tx_size;
332
    mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
333
334
    if (counts) ++counts->txfm_partition[ctx][0];
    txfm_partition_update(xd->above_txfm_context + tx_col,
335
                          xd->left_txfm_context + tx_row, tx_size, tx_size);
336
337
338
    return;
  }

Michael Bebenita's avatar
Michael Bebenita committed
339
  is_split = aom_read(r, cm->fc->txfm_partition_prob[ctx], ACCT_STR);
340
341

  if (is_split) {
342
343
    const TX_SIZE sub_txs = sub_tx_size_map[tx_size];
    const int bsl = tx_size_wide_unit[sub_txs];
344
    int i;
345

346
    if (counts) ++counts->txfm_partition[ctx][1];
347

348
    if (tx_size == TX_8X8) {
349
      int idx, idy;
350
      inter_tx_size[0][0] = sub_txs;
351
352
      for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
        for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
353
          inter_tx_size[idy][idx] = inter_tx_size[0][0];
354
      mbmi->tx_size = sub_txs;
355
      mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
356
      txfm_partition_update(xd->above_txfm_context + tx_col,
357
                            xd->left_txfm_context + tx_row, sub_txs, tx_size);
358
359
360
361
362
      return;
    }

    assert(bsl > 0);
    for (i = 0; i < 4; ++i) {
363
364
365
      int offsetr = blk_row + (i >> 1) * bsl;
      int offsetc = blk_col + (i & 0x01) * bsl;
      read_tx_size_vartx(cm, xd, mbmi, counts, sub_txs, depth + 1, offsetr,
366
                         offsetc, r);
367
368
    }
  } else {
369
    int idx, idy;
370
    inter_tx_size[0][0] = tx_size;
371
372
    for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
      for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
373
374
        inter_tx_size[idy][idx] = tx_size;
    mbmi->tx_size = tx_size;
375
    mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
376
    if (counts) ++counts->txfm_partition[ctx][0];
377
    txfm_partition_update(xd->above_txfm_context + tx_col,
378
                          xd->left_txfm_context + tx_row, tx_size, tx_size);
379
380
381
382
  }
}
#endif

Yaowu Xu's avatar
Yaowu Xu committed
383
384
static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd,
                                     int tx_size_cat, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
385
386
  FRAME_COUNTS *counts = xd->counts;
  const int ctx = get_tx_size_context(xd);
387
388
389
390
391
392
393
  const int depth =
      aom_read_tree(r, av1_tx_size_tree[tx_size_cat],
                    cm->fc->tx_size_probs[tx_size_cat][ctx], ACCT_STR);
  const TX_SIZE tx_size = depth_to_tx_size(depth);
#if CONFIG_RECT_TX
  assert(!is_rect_tx(tx_size));
#endif  // CONFIG_RECT_TX
394
  if (counts) ++counts->tx_size[tx_size_cat][ctx][depth];
395
  return tx_size;
Jingning Han's avatar
Jingning Han committed
396
397
}

398
399
400
401
static TX_SIZE read_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int is_inter,
                            int allow_select_inter, aom_reader *r) {
  const TX_MODE tx_mode = cm->tx_mode;
  const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
402
  if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return TX_4X4;
403
#if CONFIG_CB4X4 && CONFIG_VAR_TX
404
  if ((bsize > BLOCK_4X4 && is_inter) || bsize >= BLOCK_8X8) {
405
#else
406
  if (bsize >= BLOCK_8X8) {
407
408
409
410
#endif  // CONFIG_CB4X4 && CONFIG_VAR_TX
    if ((!is_inter || allow_select_inter) && tx_mode == TX_MODE_SELECT) {
      const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize]
                                           : intra_tx_size_cat_lookup[bsize];
411
      const TX_SIZE coded_tx_size =
412
          read_selected_tx_size(cm, xd, tx_size_cat, r);
413
#if CONFIG_EXT_TX && CONFIG_RECT_TX
414
415
416
417
      if (coded_tx_size > max_txsize_lookup[bsize]) {
        assert(coded_tx_size == max_txsize_lookup[bsize] + 1);
        return max_txsize_rect_lookup[bsize];
      }
418
419
420
#else
      assert(coded_tx_size <= max_txsize_lookup[bsize]);
#endif  // CONFIG_EXT_TX && CONFIG_RECT_TX
421
      return coded_tx_size;
422
    } else {
423
      return tx_size_from_tx_mode(bsize, tx_mode, is_inter);
424
425
    }
  } else {
426
#if CONFIG_EXT_TX && CONFIG_RECT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
427
    assert(IMPLIES(tx_mode == ONLY_4X4, bsize == BLOCK_4X4));
428
429
430
    return max_txsize_rect_lookup[bsize];
#else
    return TX_4X4;
431
#endif  // CONFIG_EXT_TX && CONFIG_RECT_TX
432
  }
Jingning Han's avatar
Jingning Han committed
433
434
}

Yaowu Xu's avatar
Yaowu Xu committed
435
static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids,
Jingning Han's avatar
Jingning Han committed
436
437
438
439
440
                              int mi_offset, int x_mis, int y_mis) {
  int x, y, segment_id = INT_MAX;

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
441
      segment_id =
Yaowu Xu's avatar
Yaowu Xu committed
442
          AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Jingning Han's avatar
Jingning Han committed
443
444
445
446
447

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

Yaowu Xu's avatar
Yaowu Xu committed
448
static void set_segment_id(AV1_COMMON *cm, int mi_offset, int x_mis, int y_mis,
449
                           int segment_id) {
Jingning Han's avatar
Jingning Han committed
450
451
452
453
454
455
456
457
458
  int x, y;

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

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
      cm->current_frame_seg_map[mi_offset + y * cm->mi_cols + x] = segment_id;
}

Yaowu Xu's avatar
Yaowu Xu committed
459
static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
460
                                 int mi_offset, int x_mis, int y_mis,
Yaowu Xu's avatar
Yaowu Xu committed
461
                                 aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
462
  struct segmentation *const seg = &cm->seg;
463
464
  FRAME_COUNTS *counts = xd->counts;
  struct segmentation_probs *const segp = &cm->fc->seg;
Jingning Han's avatar
Jingning Han committed
465
466
  int segment_id;

467
  if (!seg->enabled) return 0;  // Default for disabled segmentation
Jingning Han's avatar
Jingning Han committed
468

469
  assert(seg->update_map && !seg->temporal_update);
Jingning Han's avatar
Jingning Han committed
470

471
  segment_id = read_segment_id(r, segp);
472
  if (counts) ++counts->seg.tree_total[segment_id];
Jingning Han's avatar
Jingning Han committed
473
474
475
476
  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
  return segment_id;
}

Yaowu Xu's avatar
Yaowu Xu committed
477
static void copy_segment_id(const AV1_COMMON *cm,
478
479
480
                            const uint8_t *last_segment_ids,
                            uint8_t *current_segment_ids, int mi_offset,
                            int x_mis, int y_mis) {
481
482
483
484
  int x, y;

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
485
486
487
      current_segment_ids[mi_offset + y * cm->mi_cols + x] =
          last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x]
                           : 0;
488
489
}

Yaowu Xu's avatar
Yaowu Xu committed
490
491
static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                 int mi_row, int mi_col, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
492
  struct segmentation *const seg = &cm->seg;
493
494
  FRAME_COUNTS *counts = xd->counts;
  struct segmentation_probs *const segp = &cm->fc->seg;
Jingning Han's avatar
Jingning Han committed
495
496
497
  MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
  int predicted_segment_id, segment_id;
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
498
499
  const int bw = mi_size_wide[mbmi->sb_type];
  const int bh = mi_size_high[mbmi->sb_type];
Jingning Han's avatar
Jingning Han committed
500
501

  // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xu's avatar
Yaowu Xu committed
502
503
  const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
  const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Jingning Han's avatar
Jingning Han committed
504

505
  if (!seg->enabled) return 0;  // Default for disabled segmentation
Jingning Han's avatar
Jingning Han committed
506

507
508
509
510
  predicted_segment_id = cm->last_frame_seg_map
                             ? dec_get_segment_id(cm, cm->last_frame_seg_map,
                                                  mi_offset, x_mis, y_mis)
                             : 0;
Jingning Han's avatar
Jingning Han committed
511
512
513
514
515
516
517
518

  if (!seg->update_map) {
    copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
                    mi_offset, x_mis, y_mis);
    return predicted_segment_id;
  }

  if (seg->temporal_update) {
Yaowu Xu's avatar
Yaowu Xu committed
519
520
    const int ctx = av1_get_pred_context_seg_id(xd);
    const aom_prob pred_prob = segp->pred_probs[ctx];
Michael Bebenita's avatar
Michael Bebenita committed
521
    mbmi->seg_id_predicted = aom_read(r, pred_prob, ACCT_STR);
522
    if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted];
523
524
525
526
    if (mbmi->seg_id_predicted) {
      segment_id = predicted_segment_id;
    } else {
      segment_id = read_segment_id(r, segp);
527
      if (counts) ++counts->seg.tree_mispred[segment_id];
528
    }
Jingning Han's avatar
Jingning Han committed
529
  } else {
530
    segment_id = read_segment_id(r, segp);
531
    if (counts) ++counts->seg.tree_total[segment_id];
Jingning Han's avatar
Jingning Han committed
532
533
534
535
536
  }
  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
  return segment_id;
}

Yaowu Xu's avatar
Yaowu Xu committed
537
538
static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
                     aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
539
540
541
  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
    return 1;
  } else {
Yaowu Xu's avatar
Yaowu Xu committed
542
    const int ctx = av1_get_skip_context(xd);
Michael Bebenita's avatar
Michael Bebenita committed
543
    const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR);
Jingning Han's avatar
Jingning Han committed
544
    FRAME_COUNTS *counts = xd->counts;
545
    if (counts) ++counts->skip[ctx][skip];
Jingning Han's avatar
Jingning Han committed
546
547
548
549
    return skip;
  }
}

550
#if CONFIG_PALETTE
Yaowu Xu's avatar
Yaowu Xu committed
551
552
static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                   aom_reader *r) {
hui su's avatar
hui su committed
553
554
  MODE_INFO *const mi = xd->mi[0];
  MB_MODE_INFO *const mbmi = &mi->mbmi;
555
  const MODE_INFO *const above_mi = xd->above_mi;
556
  const MODE_INFO *const left_mi = xd->left_mi;
hui su's avatar
hui su committed
557
  const BLOCK_SIZE bsize = mbmi->sb_type;
558
559
560
561
562
563
564
565
  int i, n, palette_ctx = 0;
  PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;

  if (mbmi->mode == DC_PRED) {
    if (above_mi)
      palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
    if (left_mi)
      palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
Michael Bebenita's avatar
Michael Bebenita committed
566
567
568
    if (aom_read(
            r, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx],
            ACCT_STR)) {
569
      pmi->palette_size[0] =
Yaowu Xu's avatar
Yaowu Xu committed
570
          aom_read_tree(r, av1_palette_size_tree,
Michael Bebenita's avatar
Michael Bebenita committed
571
572
                        av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
                        ACCT_STR) +
573
          2;
574
575
      n = pmi->palette_size[0];
      for (i = 0; i < n; ++i)
Michael Bebenita's avatar
Michael Bebenita committed
576
        pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR);
hui su's avatar
hui su committed
577

578
579
580
581
      xd->plane[0].color_index_map[0] = read_uniform(r, n);
      assert(xd->plane[0].color_index_map[0] < n);
    }
  }
hui su's avatar
hui su committed
582

583
  if (mbmi->uv_mode == DC_PRED) {
Michael Bebenita's avatar
Michael Bebenita committed
584
585
    if (aom_read(r, av1_default_palette_uv_mode_prob[pmi->palette_size[0] > 0],
                 ACCT_STR)) {
586
      pmi->palette_size[1] =
Yaowu Xu's avatar
Yaowu Xu committed
587
          aom_read_tree(r, av1_palette_size_tree,
Michael Bebenita's avatar
Michael Bebenita committed
588
589
                        av1_default_palette_uv_size_prob[bsize - BLOCK_8X8],
                        ACCT_STR) +
590
          2;
591
592
593
      n = pmi->palette_size[1];
      for (i = 0; i < n; ++i) {
        pmi->palette_colors[PALETTE_MAX_SIZE + i] =
Michael Bebenita's avatar
Michael Bebenita committed
594
            aom_read_literal(r, cm->bit_depth, ACCT_STR);
595
        pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
Michael Bebenita's avatar
Michael Bebenita committed
596
            aom_read_literal(r, cm->bit_depth, ACCT_STR);
597
598
599
600
      }
      xd->plane[1].color_index_map[0] = read_uniform(r, n);
      assert(xd->plane[1].color_index_map[0] < n);
    }
hui su's avatar
hui su committed
601
602
  }
}
603
#endif  // CONFIG_PALETTE
hui su's avatar
hui su committed
604

605
606
607
#if CONFIG_FILTER_INTRA
static void read_filter_intra_mode_info(AV1_COMMON *const cm,
                                        MACROBLOCKD *const xd, aom_reader *r) {
hui su's avatar
hui su committed
608
609
610
  MODE_INFO *const mi = xd->mi[0];
  MB_MODE_INFO *const mbmi = &mi->mbmi;
  FRAME_COUNTS *counts = xd->counts;
611
612
  FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
      &mbmi->filter_intra_mode_info;
hui su's avatar
hui su committed
613

614
615
616
617
618
  if (mbmi->mode == DC_PRED
#if CONFIG_PALETTE
      && mbmi->palette_mode_info.palette_size[0] == 0
#endif  // CONFIG_PALETTE
      ) {
619
620
621
622
    filter_intra_mode_info->use_filter_intra_mode[0] =
        aom_read(r, cm->fc->filter_intra_probs[0], ACCT_STR);
    if (filter_intra_mode_info->use_filter_intra_mode[0]) {
      filter_intra_mode_info->filter_intra_mode[0] =
hui su's avatar
hui su committed
623
          read_uniform(r, FILTER_INTRA_MODES);
hui su's avatar
hui su committed
624
    }
625
626
627
628
    if (counts) {
      ++counts->filter_intra[0]
                            [filter_intra_mode_info->use_filter_intra_mode[0]];
    }
hui su's avatar
hui su committed
629
  }
630
631
632
633
634
  if (mbmi->uv_mode == DC_PRED
#if CONFIG_PALETTE
      && mbmi->palette_mode_info.palette_size[1] == 0
#endif  // CONFIG_PALETTE
      ) {
635
636
637
638
    filter_intra_mode_info->use_filter_intra_mode[1] =
        aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR);
    if (filter_intra_mode_info->use_filter_intra_mode[1]) {
      filter_intra_mode_info->filter_intra_mode[1] =
hui su's avatar
hui su committed
639
          read_uniform(r, FILTER_INTRA_MODES);
hui su's avatar
hui su committed
640
    }
641
642
643
644
    if (counts) {
      ++counts->filter_intra[1]
                            [filter_intra_mode_info->use_filter_intra_mode[1]];
    }
hui su's avatar
hui su committed
645
646
  }
}
647
#endif  // CONFIG_FILTER_INTRA
648

649
#if CONFIG_EXT_INTRA
Yaowu Xu's avatar
Yaowu Xu committed
650
651
static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                  aom_reader *r) {
652
653
  MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
  const BLOCK_SIZE bsize = mbmi->sb_type;
hui su's avatar
hui su committed
654
#if CONFIG_INTRA_INTERP
Yaowu Xu's avatar
Yaowu Xu committed
655
  const int ctx = av1_get_pred_context_intra_interp(xd);
656
  int p_angle;
hui su's avatar
hui su committed
657
#endif  // CONFIG_INTRA_INTERP
658

hui su's avatar
hui su committed
659
  (void)cm;
660
  if (bsize < BLOCK_8X8) return;
661

hui su's avatar
hui su committed
662
663
  if (av1_is_directional_mode(mbmi->mode, bsize)) {
    const int max_angle_delta = av1_get_max_angle_delta(mbmi->sb_type, 0);
664
    mbmi->angle_delta[0] =
hui su's avatar
hui su committed
665
        read_uniform(r, 2 * max_angle_delta + 1) - max_angle_delta;
hui su's avatar
hui su committed
666
#if CONFIG_INTRA_INTERP
hui su's avatar
hui su committed
667
668
    p_angle = mode_to_angle_map[mbmi->mode] +
              mbmi->angle_delta[0] * av1_get_angle_step(mbmi->sb_type, 0);
Yaowu Xu's avatar
Yaowu Xu committed
669
    if (av1_is_intra_filter_switchable(p_angle)) {
670
      FRAME_COUNTS *counts = xd->counts;
Michael Bebenita's avatar
Michael Bebenita committed
671
672
      mbmi->intra_filter = aom_read_tree(
          r, av1_intra_filter_tree, cm->fc->intra_filter_probs[ctx], ACCT_STR);
673
      if (counts) ++counts->intra_filter[ctx][mbmi->intra_filter];
674
675
676
    } else {
      mbmi->intra_filter = INTRA_FILTER_LINEAR;
    }
hui su's avatar
hui su committed
677
#endif  // CONFIG_INTRA_INTERP
678
679
  }

hui su's avatar
hui su committed
680
  if (av1_is_directional_mode(mbmi->uv_mode, bsize)) {
681
    mbmi->angle_delta[1] =
hui su's avatar
hui su committed
682
        read_uniform(r, 2 * MAX_ANGLE_DELTA_UV + 1) - MAX_ANGLE_DELTA_UV;
683
684
  }
}
hui su's avatar
hui su committed
685
686
#endif  // CONFIG_EXT_INTRA

Jingning Han's avatar
Jingning Han committed
687
688
689
690
691
692
693
static void read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd,
                         MB_MODE_INFO *mbmi,
#if CONFIG_SUPERTX
                         int supertx_enabled,
#endif
                         aom_reader *r) {
  const int inter_block = is_inter_block(mbmi);
694
695
696
#if CONFIG_VAR_TX
  const TX_SIZE tx_size = inter_block ? mbmi->min_tx_size : mbmi->tx_size;
#else
Jingning Han's avatar
Jingning Han committed
697
  const TX_SIZE tx_size = mbmi->tx_size;
698
#endif
Jingning Han's avatar
Jingning Han committed
699
700
  if (!FIXED_TX_TYPE) {
#if CONFIG_EXT_TX
701
    const TX_SIZE square_tx_size = txsize_sqr_map[tx_size];
Jingning Han's avatar
Jingning Han committed
702
    if (get_ext_tx_types(tx_size, mbmi->sb_type, inter_block) > 1 &&
703
704
705
        ((!cm->seg.enabled && cm->base_qindex > 0) ||
         (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) &&
        !mbmi->skip &&
Jingning Han's avatar
Jingning Han committed
706
707
708
709
710
711
712
713
714
715
716
#if CONFIG_SUPERTX
        !supertx_enabled &&
#endif  // CONFIG_SUPERTX
        !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
      int eset = get_ext_tx_set(tx_size, mbmi->sb_type, inter_block);
      FRAME_COUNTS *counts = xd->counts;

      if (inter_block) {
        if (eset > 0) {
          mbmi->tx_type = aom_read_tree(
              r, av1_ext_tx_inter_tree[eset],
717
              cm->fc->inter_ext_tx_prob[eset][square_tx_size], ACCT_STR);
Jingning Han's avatar
Jingning Han committed
718
          if (counts)
719
            ++counts->inter_ext_tx[eset][square_tx_size][mbmi->tx_type];
Jingning Han's avatar
Jingning Han committed
720
721
722
723
724
        }
      } else if (ALLOW_INTRA_EXT_TX) {
        if (eset > 0) {
          mbmi->tx_type = aom_read_tree(
              r, av1_ext_tx_intra_tree[eset],
725
726
              cm->fc->intra_ext_tx_prob[eset][square_tx_size][mbmi->mode],
              ACCT_STR);
Jingning Han's avatar
Jingning Han committed
727
          if (counts)
728
729
            ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode]
                                  [mbmi->tx_type];
Jingning Han's avatar
Jingning Han committed
730
731
732
733
734
735
        }
      }
    } else {
      mbmi->tx_type = DCT_DCT;
    }
#else
736
737
738
739
740

    if (tx_size < TX_32X32 &&
        ((!cm->seg.enabled && cm->base_qindex > 0) ||
         (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) &&
        !mbmi->skip &&
Jingning Han's avatar
Jingning Han committed
741
742
743
744
745
#if CONFIG_SUPERTX
        !supertx_enabled &&
#endif  // CONFIG_SUPERTX
        !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
      FRAME_COUNTS *counts = xd->counts;
746

Jingning Han's avatar
Jingning Han committed
747
      if (inter_block) {
748
#if CONFIG_EC_MULTISYMBOL
Jingning Han's avatar
Jingning Han committed
749
750
751
752
753
754
755
756
757
        mbmi->tx_type = av1_ext_tx_inv[aom_read_symbol(
            r, cm->fc->inter_ext_tx_cdf[tx_size], TX_TYPES, ACCT_STR)];
#else
        mbmi->tx_type = aom_read_tree(
            r, av1_ext_tx_tree, cm->fc->inter_ext_tx_prob[tx_size], ACCT_STR);
#endif
        if (counts) ++counts->inter_ext_tx[tx_size][mbmi->tx_type];
      } else {
        const TX_TYPE tx_type_nom = intra_mode_to_tx_type_context[mbmi->mode];
758
#if CONFIG_EC_MULTISYMBOL
Jingning Han's avatar
Jingning Han committed
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
        mbmi->tx_type = av1_ext_tx_inv[aom_read_symbol(
            r, cm->fc->intra_ext_tx_cdf[tx_size][tx_type_nom], TX_TYPES,
            ACCT_STR)];
#else
        mbmi->tx_type = aom_read_tree(
            r, av1_ext_tx_tree, cm->fc->intra_ext_tx_prob[tx_size][tx_type_nom],
            ACCT_STR);
#endif
        if (counts) ++counts->intra_ext_tx[tx_size][tx_type_nom][mbmi->tx_type];
      }
    } else {
      mbmi->tx_type = DCT_DCT;
    }
#endif  // CONFIG_EXT_TX
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
776
static void read_intra_frame_mode_info(AV1_COMMON *const cm,
777
                                       MACROBLOCKD *const xd, int mi_row,
Yaowu Xu's avatar
Yaowu Xu committed
778
                                       int mi_col, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
779
780
781
  MODE_INFO *const mi = xd->mi[0];
  MB_MODE_INFO *const mbmi = &mi->mbmi;
  const MODE_INFO *above_mi = xd->above_mi;
782
  const MODE_INFO *left_mi = xd->left_mi;
Jingning Han's avatar
Jingning Han committed
783
784
785
  const BLOCK_SIZE bsize = mbmi->sb_type;
  int i;
  const int mi_offset = mi_row * cm->mi_cols + mi_col;
786
787
  const int bw = mi_size_wide[bsize];
  const int bh = mi_size_high[bsize];
Jingning Han's avatar
Jingning Han committed
788
789

  // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xu's avatar
Yaowu Xu committed
790
791
  const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw);
  const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh);
Jingning Han's avatar
Jingning Han committed
792

793
  mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r);
Jingning Han's avatar
Jingning Han committed
794
  mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r);
795
796
797

#if CONFIG_DELTA_Q
  if (cm->delta_q_present_flag) {
798
799
800
801
    xd->current_qindex =
        xd->prev_qindex +
        read_delta_qindex(cm, xd, r, mbmi, mi_col, mi_row) * cm->delta_q_res;
    xd->prev_qindex = xd->current_qindex;
802
803
804
  }
#endif

805
  mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r);
Jingning Han's avatar
Jingning Han committed
806
807
808
  mbmi->ref_frame[0] = INTRA_FRAME;
  mbmi->ref_frame[1] = NONE;

809
810
811
#if CONFIG_CB4X4
  (void)i;
  mbmi->mode =
812
#if CONFIG_EC_MULTISYMBOL
813
      read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, 0));
814
815
#else
      read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
816
#endif
817
#else
Jingning Han's avatar
Jingning Han committed
818
819
820
821
  switch (bsize) {
    case BLOCK_4X4:
      for (i = 0; i < 4; ++i)
        mi->bmi[i].as_mode =
822
#if CONFIG_EC_MULTISYMBOL
823
            read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, i));
824
#else
825
            read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, i));
826
#endif
Jingning Han's avatar
Jingning Han committed
827
828
829
830
      mbmi->mode = mi->bmi[3].as_mode;
      break;
    case BLOCK_4X8:
      mi->bmi[0].as_mode = mi->bmi[2].as_mode =
831
#if CONFIG_EC_MULTISYMBOL
832
          read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, 0));
833
#else
834
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
835
#endif
Jingning Han's avatar
Jingning Han committed
836
      mi->bmi[1].as_mode = mi->bmi[3].as_mode = mbmi->mode =
837
#if CONFIG_EC_MULTISYMBOL
838
          read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, 1));
839
#else
840
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 1));
841
#endif
Jingning Han's avatar
Jingning Han committed
842
843
844
      break;
    case BLOCK_8X4:
      mi->bmi[0].as_mode = mi->bmi[1].as_mode =
845
#if CONFIG_EC_MULTISYMBOL
846
          read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, 0));
847
#else
848
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
849
#endif
Jingning Han's avatar
Jingning Han committed
850
      mi->bmi[2].as_mode = mi->bmi[3].as_mode = mbmi->mode =
851
#if CONFIG_EC_MULTISYMBOL
852
          read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, 2));
853
#else
854
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 2));
855
#endif
Jingning Han's avatar
Jingning Han committed
856
857
      break;
    default:
858
      mbmi->mode =
859
#if CONFIG_EC_MULTISYMBOL
860
          read_intra_mode(r, get_y_mode_cdf(cm, mi, above_mi, left_mi, 0));
861
#else
862
          read_intra_mode(r, get_y_mode_probs(cm, mi, above_mi, left_mi, 0));
863
#endif
Jingning Han's avatar
Jingning Han committed
864
  }
865
#endif
Jingning Han's avatar
Jingning Han committed
866

867
  mbmi->uv_mode = read_intra_mode_uv(cm, xd, r, mbmi->mode);
hui su's avatar
hui su committed
868
#if CONFIG_EXT_INTRA
869
870
  read_intra_angle_info(cm, xd, r);
#endif  // CONFIG_EXT_INTRA
871
#if CONFIG_PALETTE
hui su's avatar
hui su committed
872
873
  mbmi->palette_mode_info