decodemv.c 104 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

36
#define DEC_MISMATCH_DEBUG 0
37

38
static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) {
Hui Su's avatar
Hui Su committed
39
  return (PREDICTION_MODE)aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR);
40
}
Jingning Han's avatar
Jingning Han committed
41

42 43 44 45 46 47 48 49
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);
Thomas Davies's avatar
Thomas Davies committed
50 51 52 53
  int rem_bits, thr;
  int i, smallval;
  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
  (void)cm;
54

55
  if ((bsize != BLOCK_LARGEST || mbmi->skip == 0) && read_delta_q_flag) {
Thomas Davies's avatar
Thomas Davies committed
56 57 58 59 60 61 62 63
    abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR);
    smallval = (abs < DELTA_Q_SMALL);
    if (counts) {
      for (i = 0; i < abs; ++i) counts->delta_q[i][1]++;
      if (smallval) counts->delta_q[abs][0]++;
    }

    if (!smallval) {
64
      rem_bits = aom_read_literal(r, 3, ACCT_STR) + 1;
65 66 67 68 69 70 71 72 73 74 75 76 77 78
      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;
}
Fangwen Fu's avatar
Fangwen Fu committed
79 80
#if CONFIG_EXT_DELTA_Q
static int read_delta_lflevel(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
81 82 83
#if CONFIG_LOOPFILTER_LEVEL
                              int lf_id,
#endif
Fangwen Fu's avatar
Fangwen Fu committed
84 85 86 87 88 89 90 91 92 93 94 95 96
                              MB_MODE_INFO *const mbmi, int mi_col,
                              int mi_row) {
  FRAME_COUNTS *counts = xd->counts;
  int sign, abs, reduced_delta_lflevel = 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_lf_flag = (b_col == 0 && b_row == 0);
  int rem_bits, thr;
  int i, smallval;
  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
  (void)cm;

97
  if ((bsize != cm->sb_size || mbmi->skip == 0) && read_delta_lf_flag) {
98
#if CONFIG_LOOPFILTER_LEVEL
99 100 101 102 103 104 105 106
    if (cm->delta_lf_multi) {
      assert(lf_id >= 0 && lf_id < FRAME_LF_COUNT);
      abs = aom_read_symbol(r, ec_ctx->delta_lf_multi_cdf[lf_id],
                            DELTA_LF_PROBS + 1, ACCT_STR);
    } else {
      abs = aom_read_symbol(r, ec_ctx->delta_lf_cdf, DELTA_LF_PROBS + 1,
                            ACCT_STR);
    }
107
#else
Fangwen Fu's avatar
Fangwen Fu committed
108 109
    abs =
        aom_read_symbol(r, ec_ctx->delta_lf_cdf, DELTA_LF_PROBS + 1, ACCT_STR);
110
#endif  // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu's avatar
Fangwen Fu committed
111 112
    smallval = (abs < DELTA_LF_SMALL);
    if (counts) {
113
#if CONFIG_LOOPFILTER_LEVEL
114 115 116 117 118 119 120
      if (cm->delta_lf_multi) {
        for (i = 0; i < abs; ++i) counts->delta_lf_multi[lf_id][i][1]++;
        if (smallval) counts->delta_lf_multi[lf_id][abs][0]++;
      } else {
        for (i = 0; i < abs; ++i) counts->delta_lf[i][1]++;
        if (smallval) counts->delta_lf[abs][0]++;
      }
121
#else
Fangwen Fu's avatar
Fangwen Fu committed
122 123
      for (i = 0; i < abs; ++i) counts->delta_lf[i][1]++;
      if (smallval) counts->delta_lf[abs][0]++;
124
#endif  // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu's avatar
Fangwen Fu committed
125 126
    }
    if (!smallval) {
127
      rem_bits = aom_read_literal(r, 3, ACCT_STR) + 1;
Fangwen Fu's avatar
Fangwen Fu committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
      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_lflevel = sign ? -abs : abs;
  }
  return reduced_delta_lflevel;
}
#endif
143

Luc Trudeau's avatar
Luc Trudeau committed
144
static UV_PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx,
145
                                             aom_reader *r,
Luc Trudeau's avatar
Luc Trudeau committed
146 147
                                             PREDICTION_MODE y_mode) {
  const UV_PREDICTION_MODE uv_mode =
148 149 150
#if CONFIG_CFL
      aom_read_symbol(r, ec_ctx->uv_mode_cdf[y_mode], UV_INTRA_MODES, ACCT_STR);
#else
151
      read_intra_mode(r, ec_ctx->uv_mode_cdf[y_mode]);
152
#endif  // CONFIG_CFL
Jingning Han's avatar
Jingning Han committed
153 154 155
  return uv_mode;
}

Luc Trudeau's avatar
Luc Trudeau committed
156
#if CONFIG_CFL
157
static int read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r,
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                           int *signs_out) {
  const int joint_sign =
      aom_read_symbol(r, ec_ctx->cfl_sign_cdf, CFL_JOINT_SIGNS, "cfl:signs");
  int idx = 0;
  // Magnitudes are only coded for nonzero values
  if (CFL_SIGN_U(joint_sign) != CFL_SIGN_ZERO) {
    aom_cdf_prob *cdf_u = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_U(joint_sign)];
    idx = aom_read_symbol(r, cdf_u, CFL_ALPHABET_SIZE, "cfl:alpha_u")
          << CFL_ALPHABET_SIZE_LOG2;
  }
  if (CFL_SIGN_V(joint_sign) != CFL_SIGN_ZERO) {
    aom_cdf_prob *cdf_v = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_V(joint_sign)];
    idx += aom_read_symbol(r, cdf_v, CFL_ALPHABET_SIZE, "cfl:alpha_v");
  }
  *signs_out = joint_sign;
  return idx;
Luc Trudeau's avatar
Luc Trudeau committed
174 175 176
}
#endif

177
#if CONFIG_INTERINTRA
Yaowu Xu's avatar
Yaowu Xu committed
178 179
static INTERINTRA_MODE read_interintra_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
                                            aom_reader *r, int size_group) {
180 181 182 183
  (void)cm;
  const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_symbol(
      r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES,
      ACCT_STR);
184
  FRAME_COUNTS *counts = xd->counts;
185
  if (counts) ++counts->interintra_mode[size_group][ii_mode];
186 187
  return ii_mode;
}
188
#endif  // CONFIG_INTERINTRA
189

190
static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xu's avatar
Yaowu Xu committed
191
                                       aom_reader *r, int16_t ctx) {
192
  FRAME_COUNTS *counts = xd->counts;
193
  int16_t mode_ctx = ctx & NEWMV_CTX_MASK;
194 195 196 197 198 199 200
  int is_newmv, is_zeromv, is_refmv;
#if CONFIG_NEW_MULTISYMBOL
  is_newmv = aom_read_symbol(r, ec_ctx->newmv_cdf[mode_ctx], 2, ACCT_STR) == 0;
#else
  is_newmv = aom_read(r, ec_ctx->newmv_prob[mode_ctx], ACCT_STR) == 0;
#endif
  if (is_newmv) {
201
    if (counts) ++counts->newmv_mode[mode_ctx][0];
202
    return NEWMV;
203
  }
204 205
  if (counts) ++counts->newmv_mode[mode_ctx][1];
  if (ctx & (1 << ALL_ZERO_FLAG_OFFSET)) return ZEROMV;
206
  mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK;
207 208 209 210 211 212 213
#if CONFIG_NEW_MULTISYMBOL
  is_zeromv =
      aom_read_symbol(r, ec_ctx->zeromv_cdf[mode_ctx], 2, ACCT_STR) == 0;
#else
  is_zeromv = aom_read(r, ec_ctx->zeromv_prob[mode_ctx], ACCT_STR) == 0;
#endif
  if (is_zeromv) {
214
    if (counts) ++counts->zeromv_mode[mode_ctx][0];
215 216
    return ZEROMV;
  }
217
  if (counts) ++counts->zeromv_mode[mode_ctx][1];
218
  mode_ctx = (ctx >> REFMV_OFFSET) & REFMV_CTX_MASK;
219 220 221
  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;
222 223 224 225 226 227
#if CONFIG_NEW_MULTISYMBOL
  is_refmv = aom_read_symbol(r, ec_ctx->refmv_cdf[mode_ctx], 2, ACCT_STR) == 0;
#else
  is_refmv = aom_read(r, ec_ctx->refmv_prob[mode_ctx], ACCT_STR) == 0;
#endif
  if (is_refmv) {
228
    if (counts) ++counts->refmv_mode[mode_ctx][0];
229 230
    return NEARESTMV;
  } else {
231
    if (counts) ++counts->refmv_mode[mode_ctx][1];
232 233 234 235
    return NEARMV;
  }
  // Invalid prediction mode.
  assert(0);
Jingning Han's avatar
Jingning Han committed
236 237
}

238
static void read_drl_idx(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd,
Yaowu Xu's avatar
Yaowu Xu committed
239 240
                         MB_MODE_INFO *mbmi, aom_reader *r) {
  uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
241
  mbmi->ref_mv_idx = 0;
242
  if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV
243
#if CONFIG_COMPOUND_SINGLEREF
244
      || mbmi->mode == SR_NEW_NEWMV
245
#endif  // CONFIG_COMPOUND_SINGLEREF
246
      ) {
247 248 249
    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
250
        uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
251 252 253 254 255 256 257 258
#if CONFIG_NEW_MULTISYMBOL
        int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR);
#else
        int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR);
#endif
        mbmi->ref_mv_idx = idx + drl_idx;
        if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx];
        if (!drl_idx) return;
259 260 261
      }
    }
  }
David Barker's avatar
David Barker committed
262
  if (have_nearmv_in_inter_mode(mbmi->mode)) {
263 264 265 266 267 268
    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
269
        uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx);
270 271 272 273 274 275 276 277
#if CONFIG_NEW_MULTISYMBOL
        int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR);
#else
        int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR);
#endif
        mbmi->ref_mv_idx = idx + drl_idx - 1;
        if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx];
        if (!drl_idx) return;
278 279 280 281 282
      }
    }
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
283 284
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
285 286
                                    MODE_INFO *mi, aom_reader *r) {
  MB_MODE_INFO *mbmi = &mi->mbmi;
287 288
#if !CONFIG_MOTION_VAR || !CONFIG_WARPED_MOTION || CONFIG_NEW_MULTISYMBOL || \
    CONFIG_NCOBMC_ADAPT_WEIGHT
Thomas Davies's avatar
Thomas Davies committed
289 290 291
  (void)cm;
#endif

292 293
  const MOTION_MODE last_motion_mode_allowed =
      motion_mode_allowed(0, xd->global_motion,
294
#if CONFIG_WARPED_MOTION
295
                          xd,
296
#endif
297
                          mi);
Yue Chen's avatar
Yue Chen committed
298 299
  int motion_mode;
  FRAME_COUNTS *counts = xd->counts;
Yaowu Xu's avatar
Yaowu Xu committed
300

Yue Chen's avatar
Yue Chen committed
301 302
  if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION;
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
303 304 305 306 307 308 309 310 311 312 313 314 315
#if CONFIG_NCOBMC_ADAPT_WEIGHT
  if (last_motion_mode_allowed == NCOBMC_ADAPT_WEIGHT) {
    motion_mode = aom_read_symbol(r, xd->tile_ctx->ncobmc_cdf[mbmi->sb_type],
                                  OBMC_FAMILY_MODES, ACCT_STR);
    if (counts) ++counts->ncobmc[mbmi->sb_type][motion_mode];
    return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
  } else if (last_motion_mode_allowed == OBMC_CAUSAL) {
    motion_mode =
        aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->sb_type], 2, ACCT_STR);
    if (counts) ++counts->obmc[mbmi->sb_type][motion_mode];
    return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
  } else {
#else
Yue Chen's avatar
Yue Chen committed
316
  if (last_motion_mode_allowed == OBMC_CAUSAL) {
317 318 319 320
#if CONFIG_NEW_MULTISYMBOL
    motion_mode =
        aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->sb_type], 2, ACCT_STR);
#else
Yue Chen's avatar
Yue Chen committed
321
    motion_mode = aom_read(r, cm->fc->obmc_prob[mbmi->sb_type], ACCT_STR);
322
#endif
Yue Chen's avatar
Yue Chen committed
323 324 325
    if (counts) ++counts->obmc[mbmi->sb_type][motion_mode];
    return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
  } else {
326
#endif  // CONFIG_NCOBMC_ADAPT_WEIGHT
Yue Chen's avatar
Yue Chen committed
327
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
328
    motion_mode =
Thomas Davies's avatar
Thomas Davies committed
329 330
        aom_read_symbol(r, xd->tile_ctx->motion_mode_cdf[mbmi->sb_type],
                        MOTION_MODES, ACCT_STR);
Yaowu Xu's avatar
Yaowu Xu committed
331 332
    if (counts) ++counts->motion_mode[mbmi->sb_type][motion_mode];
    return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode);
Yue Chen's avatar
Yue Chen committed
333
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
334
  }
Yue Chen's avatar
Yue Chen committed
335
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yaowu Xu's avatar
Yaowu Xu committed
336
}
337 338

#if CONFIG_NCOBMC_ADAPT_WEIGHT
339
static void read_ncobmc_mode(MACROBLOCKD *xd, MODE_INFO *mi,
340
                             NCOBMC_MODE ncobmc_mode[2], aom_reader *r) {
341 342 343
  MB_MODE_INFO *mbmi = &mi->mbmi;
  FRAME_COUNTS *counts = xd->counts;
  ADAPT_OVERLAP_BLOCK ao_block = adapt_overlap_block_lookup[mbmi->sb_type];
344
  if (mbmi->motion_mode != NCOBMC_ADAPT_WEIGHT) return;
345

346 347
  ncobmc_mode[0] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
                                   MAX_NCOBMC_MODES, ACCT_STR);
348 349 350
  if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0]];

  if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) {
351 352
    ncobmc_mode[1] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block],
                                     MAX_NCOBMC_MODES, ACCT_STR);
353 354 355
    if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1]];
  }
}
356
#endif  // CONFIG_NCOBMC_ADAPT_WEIGHT
Yaowu Xu's avatar
Yaowu Xu committed
357 358
#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION

Yaowu Xu's avatar
Yaowu Xu committed
359 360
static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd,
                                                aom_reader *r, int16_t ctx) {
361 362 363 364
  (void)cm;
  const int mode =
      aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx],
                      INTER_COMPOUND_MODES, ACCT_STR);
365
  FRAME_COUNTS *counts = xd->counts;
366
  if (counts) ++counts->inter_compound_mode[ctx][mode];
367 368 369
  assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode));
  return NEAREST_NEARESTMV + mode;
}
370 371

#if CONFIG_COMPOUND_SINGLEREF
372
static PREDICTION_MODE read_inter_singleref_comp_mode(MACROBLOCKD *xd,
373 374 375
                                                      aom_reader *r,
                                                      int16_t ctx) {
  const int mode =
376 377
      aom_read_symbol(r, xd->tile_ctx->inter_singleref_comp_mode_cdf[ctx],
                      INTER_SINGLEREF_COMP_MODES, ACCT_STR);
378 379 380 381 382 383 384 385
  FRAME_COUNTS *counts = xd->counts;

  if (counts) ++counts->inter_singleref_comp_mode[ctx][mode];

  assert(is_inter_singleref_comp_mode(SR_NEAREST_NEARMV + mode));
  return SR_NEAREST_NEARMV + mode;
}
#endif  // CONFIG_COMPOUND_SINGLEREF
386

387
static int read_segment_id(aom_reader *r, struct segmentation_probs *segp) {
Michael Bebenita's avatar
Michael Bebenita committed
388
  return aom_read_symbol(r, segp->tree_cdf, MAX_SEGMENTS, ACCT_STR);
Jingning Han's avatar
Jingning Han committed
389 390
}

Yaowu Xu's avatar
Yaowu Xu committed
391
static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd,
392
                               MB_MODE_INFO *mbmi, FRAME_COUNTS *counts,
393 394
                               TX_SIZE tx_size, int depth, int blk_row,
                               int blk_col, aom_reader *r) {
395 396 397 398
#if CONFIG_NEW_MULTISYMBOL
  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
  (void)cm;
#endif
399
  int is_split = 0;
400 401
  const int tx_row = blk_row >> 1;
  const int tx_col = blk_col >> 1;
402 403
  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);
404 405
  int ctx = txfm_partition_context(xd->above_txfm_context + blk_col,
                                   xd->left_txfm_context + blk_row,
406
                                   mbmi->sb_type, tx_size);
clang-format's avatar
clang-format committed
407
  TX_SIZE(*const inter_tx_size)
408 409 410
  [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;
David Barker's avatar
David Barker committed
411
  assert(tx_size > TX_4X4);
412

Jingning Han's avatar
Jingning Han committed
413
  if (depth == MAX_VARTX_DEPTH) {
414 415
    int idx, idy;
    inter_tx_size[0][0] = tx_size;
416 417
    for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
      for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
418 419
        inter_tx_size[idy][idx] = tx_size;
    mbmi->tx_size = tx_size;
420
    mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
421 422
    txfm_partition_update(xd->above_txfm_context + blk_col,
                          xd->left_txfm_context + blk_row, tx_size, tx_size);
423 424 425
    return;
  }

426 427 428
#if CONFIG_NEW_MULTISYMBOL
  is_split = aom_read_symbol(r, ec_ctx->txfm_partition_cdf[ctx], 2, ACCT_STR);
#else
Michael Bebenita's avatar
Michael Bebenita committed
429
  is_split = aom_read(r, cm->fc->txfm_partition_prob[ctx], ACCT_STR);
430
#endif
431 432

  if (is_split) {
433 434
    const TX_SIZE sub_txs = sub_tx_size_map[tx_size];
    const int bsl = tx_size_wide_unit[sub_txs];
435
    int i;
436

437
    if (counts) ++counts->txfm_partition[ctx][1];
438

David Barker's avatar
David Barker committed
439
    if (sub_txs == TX_4X4) {
440
      int idx, idy;
441
      inter_tx_size[0][0] = sub_txs;
442 443
      for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
        for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
444
          inter_tx_size[idy][idx] = inter_tx_size[0][0];
445
      mbmi->tx_size = sub_txs;
446
      mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size);
447 448
      txfm_partition_update(xd->above_txfm_context + blk_col,
                            xd->left_txfm_context + blk_row, sub_txs, tx_size);
449 450 451 452 453
      return;
    }

    assert(bsl > 0);
    for (i = 0; i < 4; ++i) {
454 455 456
      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,
457
                         offsetc, r);
458 459
    }
  } else {
460
    int idx, idy;
461
    inter_tx_size[0][0] = tx_size;
462 463
    for (idy = 0; idy < tx_size_high_unit[tx_size] / 2; ++idy)
      for (idx = 0; idx < tx_size_wide_unit[tx_size] / 2; ++idx)
464 465
        inter_tx_size[idy][idx] = tx_size;
    mbmi->tx_size = tx_size;
466
    mbmi->min_tx_size = AOMMIN(mbmi->min_tx_size, get_min_tx_size(tx_size));
467
    if (counts) ++counts->txfm_partition[ctx][0];
468 469
    txfm_partition_update(xd->above_txfm_context + blk_col,
                          xd->left_txfm_context + blk_row, tx_size, tx_size);
470 471 472
  }
}

Yaowu Xu's avatar
Yaowu Xu committed
473
static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd,
474
                                     int32_t tx_size_cat, aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
475
  const int ctx = get_tx_size_context(xd);
476 477 478
  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
  (void)cm;

479 480
  const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx],
                                    tx_size_cat + 2, ACCT_STR);
481 482
  const TX_SIZE tx_size = depth_to_tx_size(depth);
  assert(!is_rect_tx(tx_size));
483
  return tx_size;
Jingning Han's avatar
Jingning Han committed
484 485
}

486 487 488 489
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;
490
  if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return TX_4X4;
491 492

  if (block_signals_txsize(bsize)) {
493 494 495
    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];
496
      const TX_SIZE coded_tx_size =
497
          read_selected_tx_size(cm, xd, tx_size_cat, r);
498 499
      if (coded_tx_size > max_txsize_lookup[bsize]) {
        assert(coded_tx_size == max_txsize_lookup[bsize] + 1);
Yue Chen's avatar
Yue Chen committed
500
#if CONFIG_RECT_TX_EXT
501
        if (is_quarter_tx_allowed(xd, &xd->mi[0]->mbmi, is_inter)) {
Yue Chen's avatar
Yue Chen committed
502
          int quarter_tx;
503

Yue Chen's avatar
Yue Chen committed
504
          if (quarter_txsize_lookup[bsize] != max_txsize_lookup[bsize]) {
505 506 507 508
#if CONFIG_NEW_MULTISYMBOL
            quarter_tx =
                aom_read_symbol(r, cm->fc->quarter_tx_size_cdf, 2, ACCT_STR);
#else
Yue Chen's avatar
Yue Chen committed
509 510 511
            quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR);
            FRAME_COUNTS *counts = xd->counts;
            if (counts) ++counts->quarter_tx_size[quarter_tx];
512
#endif
Yue Chen's avatar
Yue Chen committed
513 514 515
          } else {
            quarter_tx = 1;
          }
516 517 518
          return quarter_tx ? quarter_txsize_lookup[bsize]
                            : max_txsize_rect_lookup[bsize];
        }
Yue Chen's avatar
Yue Chen committed
519
#endif  // CONFIG_RECT_TX_EXT
520

521 522 523
        return max_txsize_rect_lookup[bsize];
      }
      return coded_tx_size;
524
    } else {
525
      return tx_size_from_tx_mode(bsize, tx_mode, is_inter);
526 527
    }
  } else {
528
#if CONFIG_EXT_TX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
529
    assert(IMPLIES(tx_mode == ONLY_4X4, bsize == BLOCK_4X4));
530 531 532
    return max_txsize_rect_lookup[bsize];
#else
    return TX_4X4;
533
#endif  // CONFIG_EXT_TX
534
  }
Jingning Han's avatar
Jingning Han committed
535 536
}

Yaowu Xu's avatar
Yaowu Xu committed
537
static int dec_get_segment_id(const AV1_COMMON *cm, const uint8_t *segment_ids,
Jingning Han's avatar
Jingning Han committed
538 539 540 541 542
                              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++)
543
      segment_id =
Yaowu Xu's avatar
Yaowu Xu committed
544
          AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]);
Jingning Han's avatar
Jingning Han committed
545 546 547 548 549

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

Yaowu Xu's avatar
Yaowu Xu committed
550
static void set_segment_id(AV1_COMMON *cm, int mi_offset, int x_mis, int y_mis,
551
                           int segment_id) {
Jingning Han's avatar
Jingning Han committed
552 553 554 555 556 557 558 559 560
  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
561
static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd,
562
                                 int mi_offset, int x_mis, int y_mis,
Yaowu Xu's avatar
Yaowu Xu committed
563
                                 aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
564
  struct segmentation *const seg = &cm->seg;
565
  FRAME_COUNTS *counts = xd->counts;
566 567
  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
  struct segmentation_probs *const segp = &ec_ctx->seg;
Jingning Han's avatar
Jingning Han committed
568 569
  int segment_id;

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

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

574
  segment_id = read_segment_id(r, segp);
575
  if (counts) ++counts->seg.tree_total[segment_id];
Jingning Han's avatar
Jingning Han committed
576 577 578 579
  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
  return segment_id;
}

Yaowu Xu's avatar
Yaowu Xu committed
580
static void copy_segment_id(const AV1_COMMON *cm,
581 582 583
                            const uint8_t *last_segment_ids,
                            uint8_t *current_segment_ids, int mi_offset,
                            int x_mis, int y_mis) {
584 585 586 587
  int x, y;

  for (y = 0; y < y_mis; y++)
    for (x = 0; x < x_mis; x++)
588 589 590
      current_segment_ids[mi_offset + y * cm->mi_cols + x] =
          last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x]
                           : 0;
591 592
}

Yaowu Xu's avatar
Yaowu Xu committed
593 594
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
595
  struct segmentation *const seg = &cm->seg;
596
  FRAME_COUNTS *counts = xd->counts;
597 598 599
  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
  struct segmentation_probs *const segp = &ec_ctx->seg;

Jingning Han's avatar
Jingning Han committed
600 601 602
  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;
603 604
  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
605 606

  // TODO(slavarnway): move x_mis, y_mis into xd ?????
Yaowu Xu's avatar
Yaowu Xu committed
607 608
  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
609

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

612 613 614 615
  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
616 617 618 619 620 621 622 623

  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
624
    const int ctx = av1_get_pred_context_seg_id(xd);
625 626 627 628
#if CONFIG_NEW_MULTISYMBOL
    aom_cdf_prob *pred_cdf = segp->pred_cdf[ctx];
    mbmi->seg_id_predicted = aom_read_symbol(r, pred_cdf, 2, ACCT_STR);
#else
Yaowu Xu's avatar
Yaowu Xu committed
629
    const aom_prob pred_prob = segp->pred_probs[ctx];
Michael Bebenita's avatar
Michael Bebenita committed
630
    mbmi->seg_id_predicted = aom_read(r, pred_prob, ACCT_STR);
631
#endif
632
    if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted];
633 634 635 636
    if (mbmi->seg_id_predicted) {
      segment_id = predicted_segment_id;
    } else {
      segment_id = read_segment_id(r, segp);
637
      if (counts) ++counts->seg.tree_mispred[segment_id];
638
    }
Jingning Han's avatar
Jingning Han committed
639
  } else {
640
    segment_id = read_segment_id(r, segp);
641
    if (counts) ++counts->seg.tree_total[segment_id];
Jingning Han's avatar
Jingning Han committed
642 643 644 645 646
  }
  set_segment_id(cm, mi_offset, x_mis, y_mis, segment_id);
  return segment_id;
}

Yaowu Xu's avatar
Yaowu Xu committed
647 648
static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
                     aom_reader *r) {
Jingning Han's avatar
Jingning Han committed
649 650 651
  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
    return 1;
  } else {
Yaowu Xu's avatar
Yaowu Xu committed
652
    const int ctx = av1_get_skip_context(xd);
653 654 655 656
#if CONFIG_NEW_MULTISYMBOL
    FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
    const int skip = aom_read_symbol(r, ec_ctx->skip_cdfs[ctx], 2, ACCT_STR);
#else
Michael Bebenita's avatar
Michael Bebenita committed
657
    const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR);
658
#endif
Jingning Han's avatar
Jingning Han committed
659
    FRAME_COUNTS *counts = xd->counts;
660
    if (counts) ++counts->skip[ctx][skip];
Jingning Han's avatar
Jingning Han committed
661 662 663 664
    return skip;
  }
}

665
#if CONFIG_PALETTE_DELTA_ENCODING
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
// Merge the sorted list of cached colors(cached_colors[0...n_cached_colors-1])
// and the sorted list of transmitted colors(colors[n_cached_colors...n-1]) into
// one single sorted list(colors[...]).
static void merge_colors(uint16_t *colors, uint16_t *cached_colors,
                         int n_colors, int n_cached_colors) {
  if (n_cached_colors == 0) return;
  int cache_idx = 0, trans_idx = n_cached_colors;
  for (int i = 0; i < n_colors; ++i) {
    if (cache_idx < n_cached_colors &&
        (trans_idx >= n_colors ||
         cached_colors[cache_idx] <= colors[trans_idx])) {
      colors[i] = cached_colors[cache_idx++];
    } else {
      assert(trans_idx < n_colors);
      colors[i] = colors[trans_idx++];
    }
  }
683 684 685 686 687
}

static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth,
                                  PALETTE_MODE_INFO *const pmi, aom_reader *r) {
  uint16_t color_cache[2 * PALETTE_MAX_SIZE];
688
  uint16_t cached_colors[PALETTE_MAX_SIZE];
689
  const int n_cache = av1_get_palette_cache(xd, 0, color_cache);
690 691 692
  const int n = pmi->palette_size[0];
  int idx = 0;
  for (int i = 0; i < n_cache && idx < n; ++i)
693
    if (aom_read_bit(r, ACCT_STR)) cached_colors[idx++] = color_cache[i];
694
  if (idx < n) {
695
    const int n_cached_colors = idx;
696 697 698 699 700 701
    pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR);
    if (idx < n) {
      const int min_bits = bit_depth - 3;
      int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
      int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1;
      for (; idx < n; ++idx) {
702
        assert(range >= 0);
703
        const int delta = aom_read_literal(r, bits, ACCT_STR) + 1;
704 705 706
        pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta,
                                         0, (1 << bit_depth) - 1);
        range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]);
707 708 709
        bits = AOMMIN(bits, av1_ceil_log2(range));
      }
    }
710 711 712
    merge_colors(pmi->palette_colors, cached_colors, n, n_cached_colors);
  } else {
    memcpy(pmi->palette_colors, cached_colors, n * sizeof(cached_colors[0]));
713 714 715 716 717 718 719 720 721
  }
}

static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth,
                                   PALETTE_MODE_INFO *const pmi,
                                   aom_reader *r) {
  const int n = pmi->palette_size[1];
  // U channel colors.
  uint16_t color_cache[2 * PALETTE_MAX_SIZE];
722
  uint16_t cached_colors[PALETTE_MAX_SIZE];
723
  const int n_cache = av1_get_palette_cache(xd, 1, color_cache);
724 725 726 727 728 729
  int idx = 0;
  for (int i = 0; i < n_cache && idx < n; ++i)
    if (aom_read_bit(r, ACCT_STR)) cached_colors[idx++] = color_cache[i];
  if (idx < n) {
    const int n_cached_colors = idx;
    idx += PALETTE_MAX_SIZE;
730 731 732 733 734 735
    pmi->palette_colors[idx++] = aom_read_literal(r, bit_depth, ACCT_STR);
    if (idx < PALETTE_MAX_SIZE + n) {
      const int min_bits = bit_depth - 3;
      int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
      int range = (1 << bit_depth) - pmi->palette_colors[idx - 1];
      for (; idx < PALETTE_MAX_SIZE + n; ++idx) {
736
        assert(range >= 0);
737
        const int delta = aom_read_literal(r, bits, ACCT_STR);
738 739 740
        pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta,
                                         0, (1 << bit_depth) - 1);
        range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]);
741 742 743
        bits = AOMMIN(bits, av1_ceil_log2(range));
      }
    }
744 745 746 747 748
    merge_colors(pmi->palette_colors + PALETTE_MAX_SIZE, cached_colors, n,
                 n_cached_colors);
  } else {
    memcpy(pmi->palette_colors + PALETTE_MAX_SIZE, cached_colors,
           n * sizeof(cached_colors[0]));
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
  }

  // V channel colors.
  if (aom_read_bit(r, ACCT_STR)) {  // Delta encoding.
    const int min_bits_v = bit_depth - 4;
    const int max_val = 1 << bit_depth;
    int bits = min_bits_v + aom_read_literal(r, 2, ACCT_STR);
    pmi->palette_colors[2 * PALETTE_MAX_SIZE] =
        aom_read_literal(r, bit_depth, ACCT_STR);
    for (int i = 1; i < n; ++i) {
      int delta = aom_read_literal(r, bits, ACCT_STR);
      if (delta && aom_read_bit(r, ACCT_STR)) delta = -delta;
      int val = (int)pmi->palette_colors[2 * PALETTE_MAX_SIZE + i - 1] + delta;
      if (val < 0) val += max_val;
      if (val >= max_val) val -= max_val;
      pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = val;
    }
  } else {
    for (int i = 0; i < n; ++i) {
      pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
          aom_read_literal(r, bit_depth, ACCT_STR);
    }
  }
}
#endif  // CONFIG_PALETTE_DELTA_ENCODING

Yaowu Xu's avatar
Yaowu Xu committed
775 776
static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                   aom_reader *r) {
hui su's avatar
hui su committed
777 778
  MODE_INFO *const mi = xd->mi[0];
  MB_MODE_INFO *const mbmi = &mi->mbmi;
779
  const MODE_INFO *const above_mi = xd->above_mi;
780
  const MODE_INFO *const left_mi = xd->left_mi;
hui su's avatar
hui su committed
781
  const BLOCK_SIZE bsize = mbmi->sb_type;
782 783
  PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;

784 785
  assert(bsize >= BLOCK_8X8 && bsize <= BLOCK_LARGEST);
  const int block_palette_idx = bsize - BLOCK_8X8;
786
  int modev;
787

788
  if (mbmi->mode == DC_PRED) {
789
    int palette_y_mode_ctx = 0;
790
    if (above_mi) {
791 792
      palette_y_mode_ctx +=
          (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
793 794
    }
    if (left_mi) {
795 796
      palette_y_mode_ctx +=
          (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
797
    }
798 799 800 801 802 803 804 805 806 807 808 809
#if CONFIG_NEW_MULTISYMBOL
    modev = aom_read_symbol(
        r,
        xd->tile_ctx->palette_y_mode_cdf[block_palette_idx][palette_y_mode_ctx],
        2, ACCT_STR);
#else
    modev = aom_read(
        r,
        av1_default_palette_y_mode_prob[block_palette_idx][palette_y_mode_ctx],
        ACCT_STR);
#endif
    if (modev) {
810
      pmi->palette_size[0] =
811
          aom_read_symbol(r,
812
                          xd->tile_ctx->palette_y_size_cdf[block_palette_idx],
813 814
                          PALETTE_SIZES, ACCT_STR) +
          2;
hui su's avatar
hui su committed
815
#if CONFIG_PALETTE_DELTA_ENCODING
816
      read_palette_colors_y(xd, cm->bit_depth, pmi, r);
hui su's avatar
hui su committed
817
#else
818
      for (int i = 0; i < pmi->palette_size[0]; ++i)
Michael Bebenita's avatar
Michael Bebenita committed
819
        pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR);
hui su's avatar
hui su committed
820
#endif  // CONFIG_PALETTE_DELTA_ENCODING
821 822
    }
  }
Luc Trudeau's avatar
Luc Trudeau committed
823
  if (mbmi->uv_mode == UV_DC_PRED) {
824
    const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
825 826 827 828 829 830 831 832
#if CONFIG_NEW_MULTISYMBOL
    modev = aom_read_symbol(
        r, xd->tile_ctx->palette_uv_mode_cdf[palette_uv_mode_ctx], 2, ACCT_STR);
#else
    modev = aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx],
                     ACCT_STR);
#endif
    if (modev) {
833
      pmi->palette_size[1] =
834
          aom_read_symbol(r,
835
                          xd->tile_ctx->palette_uv_size_cdf[block_palette_idx],
Thomas Davies's avatar