Coverage Report

Created: 2022-08-24 06:17

/src/aom/av1/encoder/encodemb.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include "config/aom_config.h"
13
#include "config/av1_rtcd.h"
14
#include "config/aom_dsp_rtcd.h"
15
16
#include "aom_dsp/bitwriter.h"
17
#include "aom_dsp/quantize.h"
18
#include "aom_mem/aom_mem.h"
19
#include "aom_ports/mem.h"
20
21
#if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
22
#include "aom_util/debug_util.h"
23
#endif  // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG
24
25
#include "av1/common/cfl.h"
26
#include "av1/common/idct.h"
27
#include "av1/common/reconinter.h"
28
#include "av1/common/reconintra.h"
29
#include "av1/common/scan.h"
30
31
#include "av1/encoder/av1_quantize.h"
32
#include "av1/encoder/encodemb.h"
33
#include "av1/encoder/hybrid_fwd_txfm.h"
34
#include "av1/encoder/txb_rdopt.h"
35
#include "av1/encoder/rd.h"
36
#include "av1/encoder/rdopt.h"
37
38
void av1_subtract_block(BitDepthInfo bd_info, int rows, int cols, int16_t *diff,
39
                        ptrdiff_t diff_stride, const uint8_t *src8,
40
                        ptrdiff_t src_stride, const uint8_t *pred8,
41
51.7M
                        ptrdiff_t pred_stride) {
42
51.7M
  assert(rows >= 4 && cols >= 4);
43
51.7M
#if CONFIG_AV1_HIGHBITDEPTH
44
51.7M
  if (bd_info.use_highbitdepth_buf) {
45
0
    aom_highbd_subtract_block(rows, cols, diff, diff_stride, src8, src_stride,
46
0
                              pred8, pred_stride, bd_info.bit_depth);
47
0
    return;
48
0
  }
49
51.7M
#endif
50
51.7M
  (void)bd_info;
51
51.7M
  aom_subtract_block(rows, cols, diff, diff_stride, src8, src_stride, pred8,
52
51.7M
                     pred_stride);
53
51.7M
}
54
55
void av1_subtract_txb(MACROBLOCK *x, int plane, BLOCK_SIZE plane_bsize,
56
44.9M
                      int blk_col, int blk_row, TX_SIZE tx_size) {
57
44.9M
  MACROBLOCKD *const xd = &x->e_mbd;
58
44.9M
  const BitDepthInfo bd_info = get_bit_depth_info(xd);
59
44.9M
  struct macroblock_plane *const p = &x->plane[plane];
60
44.9M
  const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane];
61
44.9M
  const int diff_stride = block_size_wide[plane_bsize];
62
44.9M
  const int src_stride = p->src.stride;
63
44.9M
  const int dst_stride = pd->dst.stride;
64
44.9M
  const int tx1d_width = tx_size_wide[tx_size];
65
44.9M
  const int tx1d_height = tx_size_high[tx_size];
66
44.9M
  uint8_t *dst = &pd->dst.buf[(blk_row * dst_stride + blk_col) << MI_SIZE_LOG2];
67
44.9M
  uint8_t *src = &p->src.buf[(blk_row * src_stride + blk_col) << MI_SIZE_LOG2];
68
44.9M
  int16_t *src_diff =
69
44.9M
      &p->src_diff[(blk_row * diff_stride + blk_col) << MI_SIZE_LOG2];
70
44.9M
  av1_subtract_block(bd_info, tx1d_height, tx1d_width, src_diff, diff_stride,
71
44.9M
                     src, src_stride, dst, dst_stride);
72
44.9M
}
73
74
0
void av1_subtract_plane(MACROBLOCK *x, BLOCK_SIZE plane_bsize, int plane) {
75
0
  struct macroblock_plane *const p = &x->plane[plane];
76
0
  const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane];
77
0
  assert(plane_bsize < BLOCK_SIZES_ALL);
78
0
  const int bw = block_size_wide[plane_bsize];
79
0
  const int bh = block_size_high[plane_bsize];
80
0
  const MACROBLOCKD *xd = &x->e_mbd;
81
0
  const BitDepthInfo bd_info = get_bit_depth_info(xd);
82
83
0
  av1_subtract_block(bd_info, bh, bw, p->src_diff, bw, p->src.buf,
84
0
                     p->src.stride, pd->dst.buf, pd->dst.stride);
85
0
}
86
87
int av1_optimize_b(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
88
                   int block, TX_SIZE tx_size, TX_TYPE tx_type,
89
3.50M
                   const TXB_CTX *const txb_ctx, int *rate_cost) {
90
3.50M
  MACROBLOCKD *const xd = &x->e_mbd;
91
3.50M
  struct macroblock_plane *const p = &x->plane[plane];
92
3.50M
  const int eob = p->eobs[block];
93
3.50M
  const int segment_id = xd->mi[0]->segment_id;
94
95
3.50M
  if (eob == 0 || !cpi->optimize_seg_arr[segment_id] ||
96
3.50M
      xd->lossless[segment_id]) {
97
3.30M
    *rate_cost = av1_cost_skip_txb(&x->coeff_costs, txb_ctx, plane, tx_size);
98
3.30M
    return eob;
99
3.30M
  }
100
101
200k
  return av1_optimize_txb(cpi, x, plane, block, tx_size, tx_type, txb_ctx,
102
200k
                          rate_cost, cpi->oxcf.algo_cfg.sharpness);
103
3.50M
}
104
105
// Hyper-parameters for dropout optimization, based on following logics.
106
// TODO(yjshen): These settings are tuned by experiments. They may still be
107
// optimized for better performance.
108
// (1) Coefficients which are large enough will ALWAYS be kept.
109
const tran_low_t DROPOUT_COEFF_MAX = 2;  // Max dropout-able coefficient.
110
// (2) Continuous coefficients will ALWAYS be kept. Here rigorous continuity is
111
//     NOT required. For example, `5 0 0 0 7` is treated as two continuous
112
//     coefficients if three zeros do not fulfill the dropout condition.
113
const int DROPOUT_CONTINUITY_MAX = 2;  // Max dropout-able continuous coeff.
114
// (3) Dropout operation is NOT applicable to blocks with large or small
115
//     quantization index.
116
const int DROPOUT_Q_MAX = 128;
117
const int DROPOUT_Q_MIN = 16;
118
// (4) Recall that dropout optimization will forcibly set some quantized
119
//     coefficients to zero. The key logic on determining whether a coefficient
120
//     should be dropped is to check the number of continuous zeros before AND
121
//     after this coefficient. The exact number of zeros for judgement depends
122
//     on block size and quantization index. More concretely, block size
123
//     determines the base number of zeros, while quantization index determines
124
//     the multiplier. Intuitively, larger block requires more zeros and larger
125
//     quantization index also requires more zeros (more information is lost
126
//     when using larger quantization index).
127
const int DROPOUT_BEFORE_BASE_MAX = 32;  // Max base number for leading zeros.
128
const int DROPOUT_BEFORE_BASE_MIN = 16;  // Min base number for leading zeros.
129
const int DROPOUT_AFTER_BASE_MAX = 32;   // Max base number for trailing zeros.
130
const int DROPOUT_AFTER_BASE_MIN = 16;   // Min base number for trailing zeros.
131
const int DROPOUT_MULTIPLIER_MAX = 8;    // Max multiplier on number of zeros.
132
const int DROPOUT_MULTIPLIER_MIN = 2;    // Min multiplier on number of zeros.
133
const int DROPOUT_MULTIPLIER_Q_BASE = 32;  // Base Q to compute multiplier.
134
135
void av1_dropout_qcoeff(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size,
136
455k
                        TX_TYPE tx_type, int qindex) {
137
455k
  const int tx_width = tx_size_wide[tx_size];
138
455k
  const int tx_height = tx_size_high[tx_size];
139
140
  // Early return if `qindex` is out of range.
141
455k
  if (qindex > DROPOUT_Q_MAX || qindex < DROPOUT_Q_MIN) {
142
435k
    return;
143
435k
  }
144
145
  // Compute number of zeros used for dropout judgement.
146
19.4k
  const int base_size = AOMMAX(tx_width, tx_height);
147
19.4k
  const int multiplier = CLIP(qindex / DROPOUT_MULTIPLIER_Q_BASE,
148
19.4k
                              DROPOUT_MULTIPLIER_MIN, DROPOUT_MULTIPLIER_MAX);
149
19.4k
  const int dropout_num_before =
150
19.4k
      multiplier *
151
19.4k
      CLIP(base_size, DROPOUT_BEFORE_BASE_MIN, DROPOUT_BEFORE_BASE_MAX);
152
19.4k
  const int dropout_num_after =
153
19.4k
      multiplier *
154
19.4k
      CLIP(base_size, DROPOUT_AFTER_BASE_MIN, DROPOUT_AFTER_BASE_MAX);
155
156
19.4k
  av1_dropout_qcoeff_num(mb, plane, block, tx_size, tx_type, dropout_num_before,
157
19.4k
                         dropout_num_after);
158
19.4k
}
159
160
void av1_dropout_qcoeff_num(MACROBLOCK *mb, int plane, int block,
161
                            TX_SIZE tx_size, TX_TYPE tx_type,
162
19.4k
                            int dropout_num_before, int dropout_num_after) {
163
19.4k
  const struct macroblock_plane *const p = &mb->plane[plane];
164
19.4k
  tran_low_t *const qcoeff = p->qcoeff + BLOCK_OFFSET(block);
165
19.4k
  tran_low_t *const dqcoeff = p->dqcoeff + BLOCK_OFFSET(block);
166
19.4k
  const int max_eob = av1_get_max_eob(tx_size);
167
19.4k
  const SCAN_ORDER *const scan_order = get_scan(tx_size, tx_type);
168
169
  // Early return if there are not enough non-zero coefficients.
170
19.4k
  if (p->eobs[block] == 0 || p->eobs[block] <= dropout_num_before) {
171
19.4k
    return;
172
19.4k
  }
173
174
0
  int count_zeros_before = 0;
175
0
  int count_zeros_after = 0;
176
0
  int count_nonzeros = 0;
177
  // Index of the first non-zero coefficient after sufficient number of
178
  // continuous zeros. If equals to `-1`, it means number of leading zeros
179
  // hasn't reach `dropout_num_before`.
180
0
  int idx = -1;
181
0
  int eob = 0;  // New end of block.
182
183
0
  for (int i = 0; i < p->eobs[block]; ++i) {
184
0
    const int scan_idx = scan_order->scan[i];
185
0
    if (abs(qcoeff[scan_idx]) > DROPOUT_COEFF_MAX) {
186
      // Keep large coefficients.
187
0
      count_zeros_before = 0;
188
0
      count_zeros_after = 0;
189
0
      idx = -1;
190
0
      eob = i + 1;
191
0
    } else if (qcoeff[scan_idx] == 0) {  // Count zeros.
192
0
      if (idx == -1) {
193
0
        ++count_zeros_before;
194
0
      } else {
195
0
        ++count_zeros_after;
196
0
      }
197
0
    } else {  // Count non-zeros.
198
0
      if (count_zeros_before >= dropout_num_before) {
199
0
        idx = (idx == -1) ? i : idx;
200
0
        ++count_nonzeros;
201
0
      } else {
202
0
        count_zeros_before = 0;
203
0
        eob = i + 1;
204
0
      }
205
0
    }
206
207
    // Handle continuity.
208
0
    if (count_nonzeros > DROPOUT_CONTINUITY_MAX) {
209
0
      count_zeros_before = 0;
210
0
      count_zeros_after = 0;
211
0
      count_nonzeros = 0;
212
0
      idx = -1;
213
0
      eob = i + 1;
214
0
    }
215
216
    // Handle the trailing zeros after original end of block.
217
0
    if (idx != -1 && i == p->eobs[block] - 1) {
218
0
      count_zeros_after += (max_eob - p->eobs[block]);
219
0
    }
220
221
    // Set redundant coefficients to zeros if needed.
222
0
    if (count_zeros_after >= dropout_num_after) {
223
0
      for (int j = idx; j <= i; ++j) {
224
0
        qcoeff[scan_order->scan[j]] = 0;
225
0
        dqcoeff[scan_order->scan[j]] = 0;
226
0
      }
227
0
      count_zeros_before += (i - idx + 1);
228
0
      count_zeros_after = 0;
229
0
      count_nonzeros = 0;
230
0
    } else if (i == p->eobs[block] - 1) {
231
0
      eob = i + 1;
232
0
    }
233
0
  }
234
235
0
  if (eob != p->eobs[block]) {
236
0
    p->eobs[block] = eob;
237
0
    p->txb_entropy_ctx[block] =
238
0
        av1_get_txb_entropy_context(qcoeff, scan_order, eob);
239
0
  }
240
0
}
241
242
// Settings for optimization type. NOTE: To set optimization type for all intra
243
// frames, both `KEY_BLOCK_OPT_TYPE` and `INTRA_BLOCK_OPT_TYPE` should be set.
244
// TODO(yjshen): These settings are hard-coded and look okay for now. They
245
// should be made configurable later.
246
// Blocks of key frames ONLY.
247
const OPT_TYPE KEY_BLOCK_OPT_TYPE = TRELLIS_DROPOUT_OPT;
248
// Blocks of intra frames (key frames EXCLUSIVE).
249
const OPT_TYPE INTRA_BLOCK_OPT_TYPE = TRELLIS_DROPOUT_OPT;
250
// Blocks of inter frames. (NOTE: Dropout optimization is DISABLED by default
251
// if trellis optimization is on for inter frames.)
252
const OPT_TYPE INTER_BLOCK_OPT_TYPE = TRELLIS_DROPOUT_OPT;
253
254
enum {
255
  QUANT_FUNC_LOWBD = 0,
256
  QUANT_FUNC_HIGHBD = 1,
257
  QUANT_FUNC_TYPES = 2
258
} UENUM1BYTE(QUANT_FUNC);
259
260
#if CONFIG_AV1_HIGHBITDEPTH
261
static AV1_QUANT_FACADE
262
    quant_func_list[AV1_XFORM_QUANT_TYPES][QUANT_FUNC_TYPES] = {
263
      { av1_quantize_fp_facade, av1_highbd_quantize_fp_facade },
264
      { av1_quantize_b_facade, av1_highbd_quantize_b_facade },
265
      { av1_quantize_dc_facade, av1_highbd_quantize_dc_facade },
266
      { NULL, NULL }
267
    };
268
#else
269
static AV1_QUANT_FACADE quant_func_list[AV1_XFORM_QUANT_TYPES] = {
270
  av1_quantize_fp_facade, av1_quantize_b_facade, av1_quantize_dc_facade, NULL
271
};
272
#endif
273
274
// Computes the transform for DC only blocks
275
void av1_xform_dc_only(MACROBLOCK *x, int plane, int block,
276
0
                       TxfmParam *txfm_param, int64_t per_px_mean) {
277
0
  assert(per_px_mean != INT64_MAX);
278
0
  const struct macroblock_plane *const p = &x->plane[plane];
279
0
  const int block_offset = BLOCK_OFFSET(block);
280
0
  tran_low_t *const coeff = p->coeff + block_offset;
281
0
  const int n_coeffs = av1_get_max_eob(txfm_param->tx_size);
282
0
  memset(coeff, 0, sizeof(*coeff) * n_coeffs);
283
0
  coeff[0] =
284
0
      (tran_low_t)((per_px_mean * dc_coeff_scale[txfm_param->tx_size]) >> 12);
285
0
}
286
287
void av1_xform_quant(MACROBLOCK *x, int plane, int block, int blk_row,
288
                     int blk_col, BLOCK_SIZE plane_bsize, TxfmParam *txfm_param,
289
1.85M
                     const QUANT_PARAM *qparam) {
290
1.85M
  av1_xform(x, plane, block, blk_row, blk_col, plane_bsize, txfm_param);
291
1.85M
  av1_quant(x, plane, block, txfm_param, qparam);
292
1.85M
}
293
294
void av1_xform(MACROBLOCK *x, int plane, int block, int blk_row, int blk_col,
295
45.7M
               BLOCK_SIZE plane_bsize, TxfmParam *txfm_param) {
296
45.7M
  const struct macroblock_plane *const p = &x->plane[plane];
297
45.7M
  const int block_offset = BLOCK_OFFSET(block);
298
45.7M
  tran_low_t *const coeff = p->coeff + block_offset;
299
45.7M
  const int diff_stride = block_size_wide[plane_bsize];
300
301
45.7M
  const int src_offset = (blk_row * diff_stride + blk_col);
302
45.7M
  const int16_t *src_diff = &p->src_diff[src_offset << MI_SIZE_LOG2];
303
304
45.7M
  av1_fwd_txfm(src_diff, coeff, diff_stride, txfm_param);
305
45.7M
}
306
307
void av1_quant(MACROBLOCK *x, int plane, int block, TxfmParam *txfm_param,
308
46.1M
               const QUANT_PARAM *qparam) {
309
46.1M
  const struct macroblock_plane *const p = &x->plane[plane];
310
46.1M
  const SCAN_ORDER *const scan_order =
311
46.1M
      get_scan(txfm_param->tx_size, txfm_param->tx_type);
312
46.1M
  const int block_offset = BLOCK_OFFSET(block);
313
46.1M
  tran_low_t *const coeff = p->coeff + block_offset;
314
46.1M
  tran_low_t *const qcoeff = p->qcoeff + block_offset;
315
46.1M
  tran_low_t *const dqcoeff = p->dqcoeff + block_offset;
316
46.1M
  uint16_t *const eob = &p->eobs[block];
317
318
46.1M
  if (qparam->xform_quant_idx != AV1_XFORM_QUANT_SKIP_QUANT) {
319
46.1M
    const int n_coeffs = av1_get_max_eob(txfm_param->tx_size);
320
46.2M
    if (LIKELY(!x->seg_skip_block)) {
321
46.2M
#if CONFIG_AV1_HIGHBITDEPTH
322
46.2M
      quant_func_list[qparam->xform_quant_idx][txfm_param->is_hbd](
323
46.2M
          coeff, n_coeffs, p, qcoeff, dqcoeff, eob, scan_order, qparam);
324
#else
325
      quant_func_list[qparam->xform_quant_idx](
326
          coeff, n_coeffs, p, qcoeff, dqcoeff, eob, scan_order, qparam);
327
#endif
328
18.4E
    } else {
329
18.4E
      av1_quantize_skip(n_coeffs, qcoeff, dqcoeff, eob);
330
18.4E
    }
331
46.1M
  }
332
  // use_optimize_b is true means av1_optimze_b will be called,
333
  // thus cannot update entropy ctx now (performed in optimize_b)
334
46.1M
  if (qparam->use_optimize_b) {
335
4.90M
    p->txb_entropy_ctx[block] = 0;
336
41.2M
  } else {
337
41.2M
    p->txb_entropy_ctx[block] =
338
41.2M
        av1_get_txb_entropy_context(qcoeff, scan_order, *eob);
339
41.2M
  }
340
46.1M
}
341
342
void av1_setup_xform(const AV1_COMMON *cm, MACROBLOCK *x, TX_SIZE tx_size,
343
44.6M
                     TX_TYPE tx_type, TxfmParam *txfm_param) {
344
44.6M
  MACROBLOCKD *const xd = &x->e_mbd;
345
44.6M
  MB_MODE_INFO *const mbmi = xd->mi[0];
346
347
44.6M
  txfm_param->tx_type = tx_type;
348
44.6M
  txfm_param->tx_size = tx_size;
349
44.6M
  txfm_param->lossless = xd->lossless[mbmi->segment_id];
350
44.6M
  txfm_param->tx_set_type = av1_get_ext_tx_set_type(
351
44.6M
      tx_size, is_inter_block(mbmi), cm->features.reduced_tx_set_used);
352
353
44.6M
  txfm_param->bd = xd->bd;
354
44.6M
  txfm_param->is_hbd = is_cur_buf_hbd(xd);
355
44.6M
}
356
void av1_setup_quant(TX_SIZE tx_size, int use_optimize_b, int xform_quant_idx,
357
47.6M
                     int use_quant_b_adapt, QUANT_PARAM *qparam) {
358
47.6M
  qparam->log_scale = av1_get_tx_scale(tx_size);
359
47.6M
  qparam->tx_size = tx_size;
360
361
47.6M
  qparam->use_quant_b_adapt = use_quant_b_adapt;
362
363
  // TODO(bohanli): optimize_b and quantization idx has relationship,
364
  // but is kind of buried and complicated in different encoding stages.
365
  // Should have a unified function to derive quant_idx, rather than
366
  // determine and pass in the quant_idx
367
47.6M
  qparam->use_optimize_b = use_optimize_b;
368
47.6M
  qparam->xform_quant_idx = xform_quant_idx;
369
370
47.6M
  qparam->qmatrix = NULL;
371
47.6M
  qparam->iqmatrix = NULL;
372
47.6M
}
373
void av1_setup_qmatrix(const CommonQuantParams *quant_params,
374
                       const MACROBLOCKD *xd, int plane, TX_SIZE tx_size,
375
1.85M
                       TX_TYPE tx_type, QUANT_PARAM *qparam) {
376
1.85M
  qparam->qmatrix = av1_get_qmatrix(quant_params, xd, plane, tx_size, tx_type);
377
1.85M
  qparam->iqmatrix =
378
1.85M
      av1_get_iqmatrix(quant_params, xd, plane, tx_size, tx_type);
379
1.85M
}
380
381
static void encode_block(int plane, int block, int blk_row, int blk_col,
382
                         BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg,
383
0
                         RUN_TYPE dry_run) {
384
0
  (void)dry_run;
385
0
  struct encode_b_args *const args = arg;
386
0
  const AV1_COMP *const cpi = args->cpi;
387
0
  const AV1_COMMON *const cm = &cpi->common;
388
0
  MACROBLOCK *const x = args->x;
389
0
  MACROBLOCKD *const xd = &x->e_mbd;
390
0
  MB_MODE_INFO *mbmi = xd->mi[0];
391
0
  struct macroblock_plane *const p = &x->plane[plane];
392
0
  struct macroblockd_plane *const pd = &xd->plane[plane];
393
0
  tran_low_t *const dqcoeff = p->dqcoeff + BLOCK_OFFSET(block);
394
0
  uint8_t *dst;
395
0
  ENTROPY_CONTEXT *a, *l;
396
0
  int dummy_rate_cost = 0;
397
398
0
  const int bw = mi_size_wide[plane_bsize];
399
0
  dst = &pd->dst.buf[(blk_row * pd->dst.stride + blk_col) << MI_SIZE_LOG2];
400
401
0
  a = &args->ta[blk_col];
402
0
  l = &args->tl[blk_row];
403
404
0
  TX_TYPE tx_type = DCT_DCT;
405
0
  const int blk_skip_idx = cpi->sf.rt_sf.use_nonrd_pick_mode
406
0
                               ? blk_row * bw / 4 + blk_col / 2
407
0
                               : blk_row * bw + blk_col;
408
0
  if (!is_blk_skip(x->txfm_search_info.blk_skip, plane, blk_skip_idx) &&
409
0
      !mbmi->skip_mode) {
410
0
    tx_type = av1_get_tx_type(xd, pd->plane_type, blk_row, blk_col, tx_size,
411
0
                              cm->features.reduced_tx_set_used);
412
0
    TxfmParam txfm_param;
413
0
    QUANT_PARAM quant_param;
414
0
    const int use_trellis = is_trellis_used(args->enable_optimize_b, dry_run);
415
0
    int quant_idx;
416
0
    if (use_trellis)
417
0
      quant_idx = AV1_XFORM_QUANT_FP;
418
0
    else
419
0
      quant_idx =
420
0
          USE_B_QUANT_NO_TRELLIS ? AV1_XFORM_QUANT_B : AV1_XFORM_QUANT_FP;
421
0
    av1_setup_xform(cm, x, tx_size, tx_type, &txfm_param);
422
0
    av1_setup_quant(tx_size, use_trellis, quant_idx,
423
0
                    cpi->oxcf.q_cfg.quant_b_adapt, &quant_param);
424
0
    av1_setup_qmatrix(&cm->quant_params, xd, plane, tx_size, tx_type,
425
0
                      &quant_param);
426
0
    av1_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize, &txfm_param,
427
0
                    &quant_param);
428
429
    // Whether trellis or dropout optimization is required for inter frames.
430
0
    const bool do_trellis = INTER_BLOCK_OPT_TYPE == TRELLIS_OPT ||
431
0
                            INTER_BLOCK_OPT_TYPE == TRELLIS_DROPOUT_OPT;
432
0
    const bool do_dropout = INTER_BLOCK_OPT_TYPE == DROPOUT_OPT ||
433
0
                            INTER_BLOCK_OPT_TYPE == TRELLIS_DROPOUT_OPT;
434
435
0
    if (quant_param.use_optimize_b && do_trellis) {
436
0
      TXB_CTX txb_ctx;
437
0
      get_txb_ctx(plane_bsize, tx_size, plane, a, l, &txb_ctx);
438
0
      av1_optimize_b(args->cpi, x, plane, block, tx_size, tx_type, &txb_ctx,
439
0
                     &dummy_rate_cost);
440
0
    }
441
0
    if (!quant_param.use_optimize_b && do_dropout) {
442
0
      av1_dropout_qcoeff(x, plane, block, tx_size, tx_type,
443
0
                         cm->quant_params.base_qindex);
444
0
    }
445
0
  } else {
446
0
    p->eobs[block] = 0;
447
0
    p->txb_entropy_ctx[block] = 0;
448
0
  }
449
450
0
  av1_set_txb_context(x, plane, block, tx_size, a, l);
451
452
0
  if (p->eobs[block]) {
453
0
    *(args->skip) = 0;
454
0
    av1_inverse_transform_block(xd, dqcoeff, plane, tx_type, tx_size, dst,
455
0
                                pd->dst.stride, p->eobs[block],
456
0
                                cm->features.reduced_tx_set_used);
457
0
  }
458
459
  // TODO(debargha, jingning): Temporarily disable txk_type check for eob=0
460
  // case. It is possible that certain collision in hash index would cause
461
  // the assertion failure. To further optimize the rate-distortion
462
  // performance, we need to re-visit this part and enable this assert
463
  // again.
464
0
  if (p->eobs[block] == 0 && plane == 0) {
465
#if 0
466
    if (args->cpi->oxcf.q_cfg.aq_mode == NO_AQ &&
467
        args->cpi->oxcf.q_cfg.deltaq_mode == NO_DELTA_Q) {
468
      // TODO(jingning,angiebird,huisu@google.com): enable txk_check when
469
      // enable_optimize_b is true to detect potential RD bug.
470
      const uint8_t disable_txk_check = args->enable_optimize_b;
471
      if (!disable_txk_check) {
472
        assert(xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col)] ==
473
            DCT_DCT);
474
      }
475
    }
476
#endif
477
0
    update_txk_array(xd, blk_row, blk_col, tx_size, DCT_DCT);
478
0
  }
479
480
#if CONFIG_MISMATCH_DEBUG
481
  if (dry_run == OUTPUT_ENABLED) {
482
    int pixel_c, pixel_r;
483
    BLOCK_SIZE bsize = txsize_to_bsize[tx_size];
484
    int blk_w = block_size_wide[bsize];
485
    int blk_h = block_size_high[bsize];
486
    mi_to_pixel_loc(&pixel_c, &pixel_r, xd->mi_col, xd->mi_row, blk_col,
487
                    blk_row, pd->subsampling_x, pd->subsampling_y);
488
    mismatch_record_block_tx(dst, pd->dst.stride, cm->current_frame.order_hint,
489
                             plane, pixel_c, pixel_r, blk_w, blk_h,
490
                             xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
491
  }
492
#endif
493
0
}
494
495
static void encode_block_inter(int plane, int block, int blk_row, int blk_col,
496
                               BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
497
0
                               void *arg, RUN_TYPE dry_run) {
498
0
  struct encode_b_args *const args = arg;
499
0
  MACROBLOCK *const x = args->x;
500
0
  MACROBLOCKD *const xd = &x->e_mbd;
501
0
  MB_MODE_INFO *const mbmi = xd->mi[0];
502
0
  const struct macroblockd_plane *const pd = &xd->plane[plane];
503
0
  const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
504
0
  const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
505
506
0
  if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
507
508
0
  const TX_SIZE plane_tx_size =
509
0
      plane ? av1_get_max_uv_txsize(mbmi->bsize, pd->subsampling_x,
510
0
                                    pd->subsampling_y)
511
0
            : mbmi->inter_tx_size[av1_get_txb_size_index(plane_bsize, blk_row,
512
0
                                                         blk_col)];
513
0
  if (!plane) {
514
0
    assert(tx_size_wide[tx_size] >= tx_size_wide[plane_tx_size] &&
515
0
           tx_size_high[tx_size] >= tx_size_high[plane_tx_size]);
516
0
  }
517
518
0
  if (tx_size == plane_tx_size || plane) {
519
0
    encode_block(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg,
520
0
                 dry_run);
521
0
  } else {
522
0
    assert(tx_size < TX_SIZES_ALL);
523
0
    const TX_SIZE sub_txs = sub_tx_size_map[tx_size];
524
0
    assert(IMPLIES(tx_size <= TX_4X4, sub_txs == tx_size));
525
0
    assert(IMPLIES(tx_size > TX_4X4, sub_txs < tx_size));
526
    // This is the square transform block partition entry point.
527
0
    const int bsw = tx_size_wide_unit[sub_txs];
528
0
    const int bsh = tx_size_high_unit[sub_txs];
529
0
    const int step = bsh * bsw;
530
0
    const int row_end =
531
0
        AOMMIN(tx_size_high_unit[tx_size], max_blocks_high - blk_row);
532
0
    const int col_end =
533
0
        AOMMIN(tx_size_wide_unit[tx_size], max_blocks_wide - blk_col);
534
0
    assert(bsw > 0 && bsh > 0);
535
536
0
    for (int row = 0; row < row_end; row += bsh) {
537
0
      const int offsetr = blk_row + row;
538
0
      for (int col = 0; col < col_end; col += bsw) {
539
0
        const int offsetc = blk_col + col;
540
541
0
        encode_block_inter(plane, block, offsetr, offsetc, plane_bsize, sub_txs,
542
0
                           arg, dry_run);
543
0
        block += step;
544
0
      }
545
0
    }
546
0
  }
547
0
}
548
549
void av1_foreach_transformed_block_in_plane(
550
    const MACROBLOCKD *const xd, BLOCK_SIZE plane_bsize, int plane,
551
4.99M
    foreach_transformed_block_visitor visit, void *arg) {
552
4.99M
  const struct macroblockd_plane *const pd = &xd->plane[plane];
553
  // block and transform sizes, in number of 4x4 blocks log 2 ("*_b")
554
  // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
555
  // transform size varies per plane, look it up in a common way.
556
4.99M
  const TX_SIZE tx_size = av1_get_tx_size(plane, xd);
557
4.99M
  const uint8_t txw_unit = tx_size_wide_unit[tx_size];
558
4.99M
  const uint8_t txh_unit = tx_size_high_unit[tx_size];
559
4.99M
  const int step = txw_unit * txh_unit;
560
561
  // If mb_to_right_edge is < 0 we are in a situation in which
562
  // the current block size extends into the UMV and we won't
563
  // visit the sub blocks that are wholly within the UMV.
564
4.99M
  const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
565
4.99M
  const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
566
4.99M
  const BLOCK_SIZE max_unit_bsize =
567
4.99M
      get_plane_block_size(BLOCK_64X64, pd->subsampling_x, pd->subsampling_y);
568
4.99M
  const int mu_blocks_wide =
569
4.99M
      AOMMIN(mi_size_wide[max_unit_bsize], max_blocks_wide);
570
4.99M
  const int mu_blocks_high =
571
4.99M
      AOMMIN(mi_size_high[max_unit_bsize], max_blocks_high);
572
573
  // Keep track of the row and column of the blocks we use so that we know
574
  // if we are in the unrestricted motion border.
575
4.99M
  int i = 0;
576
9.99M
  for (int r = 0; r < max_blocks_high; r += mu_blocks_high) {
577
4.99M
    const int unit_height = AOMMIN(mu_blocks_high + r, max_blocks_high);
578
    // Skip visiting the sub blocks that are wholly within the UMV.
579
9.99M
    for (int c = 0; c < max_blocks_wide; c += mu_blocks_wide) {
580
4.99M
      const int unit_width = AOMMIN(mu_blocks_wide + c, max_blocks_wide);
581
15.0M
      for (int blk_row = r; blk_row < unit_height; blk_row += txh_unit) {
582
56.9M
        for (int blk_col = c; blk_col < unit_width; blk_col += txw_unit) {
583
46.9M
          visit(plane, i, blk_row, blk_col, plane_bsize, tx_size, arg);
584
46.9M
          i += step;
585
46.9M
        }
586
10.0M
      }
587
4.99M
    }
588
4.99M
  }
589
4.99M
}
590
591
typedef struct encode_block_pass1_args {
592
  AV1_COMP *cpi;
593
  MACROBLOCK *x;
594
} encode_block_pass1_args;
595
596
static void encode_block_pass1(int plane, int block, int blk_row, int blk_col,
597
                               BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
598
0
                               void *arg) {
599
0
  encode_block_pass1_args *args = (encode_block_pass1_args *)arg;
600
0
  AV1_COMP *cpi = args->cpi;
601
0
  AV1_COMMON *cm = &cpi->common;
602
0
  MACROBLOCK *const x = args->x;
603
0
  MACROBLOCKD *const xd = &x->e_mbd;
604
0
  struct macroblock_plane *const p = &x->plane[plane];
605
0
  struct macroblockd_plane *const pd = &xd->plane[plane];
606
0
  tran_low_t *const dqcoeff = p->dqcoeff + BLOCK_OFFSET(block);
607
608
0
  uint8_t *dst;
609
0
  dst = &pd->dst.buf[(blk_row * pd->dst.stride + blk_col) << MI_SIZE_LOG2];
610
611
0
  TxfmParam txfm_param;
612
0
  QUANT_PARAM quant_param;
613
614
0
  av1_setup_xform(cm, x, tx_size, DCT_DCT, &txfm_param);
615
0
  av1_setup_quant(tx_size, 0, AV1_XFORM_QUANT_B, cpi->oxcf.q_cfg.quant_b_adapt,
616
0
                  &quant_param);
617
0
  av1_setup_qmatrix(&cm->quant_params, xd, plane, tx_size, DCT_DCT,
618
0
                    &quant_param);
619
620
0
  av1_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize, &txfm_param,
621
0
                  &quant_param);
622
623
0
  if (p->eobs[block] > 0) {
624
0
    txfm_param.eob = p->eobs[block];
625
0
    if (txfm_param.is_hbd) {
626
0
      av1_highbd_inv_txfm_add(dqcoeff, dst, pd->dst.stride, &txfm_param);
627
0
      return;
628
0
    }
629
0
    av1_inv_txfm_add(dqcoeff, dst, pd->dst.stride, &txfm_param);
630
0
  }
631
0
}
632
633
0
void av1_encode_sby_pass1(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize) {
634
0
  encode_block_pass1_args args = { cpi, x };
635
0
  av1_subtract_plane(x, bsize, 0);
636
0
  av1_foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0,
637
0
                                         encode_block_pass1, &args);
638
0
}
639
640
void av1_encode_sb(const struct AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
641
0
                   RUN_TYPE dry_run) {
642
0
  assert(bsize < BLOCK_SIZES_ALL);
643
0
  MACROBLOCKD *const xd = &x->e_mbd;
644
0
  MB_MODE_INFO *mbmi = xd->mi[0];
645
0
  mbmi->skip_txfm = 1;
646
0
  if (x->txfm_search_info.skip_txfm) return;
647
648
0
  struct optimize_ctx ctx;
649
0
  struct encode_b_args arg = {
650
0
    cpi,  x,    &ctx,    &mbmi->skip_txfm,
651
0
    NULL, NULL, dry_run, cpi->optimize_seg_arr[mbmi->segment_id]
652
0
  };
653
0
  const AV1_COMMON *const cm = &cpi->common;
654
0
  const int num_planes = av1_num_planes(cm);
655
0
  for (int plane = 0; plane < num_planes; ++plane) {
656
0
    const struct macroblockd_plane *const pd = &xd->plane[plane];
657
0
    const int subsampling_x = pd->subsampling_x;
658
0
    const int subsampling_y = pd->subsampling_y;
659
0
    if (plane && !xd->is_chroma_ref) break;
660
0
    const BLOCK_SIZE plane_bsize =
661
0
        get_plane_block_size(bsize, subsampling_x, subsampling_y);
662
0
    assert(plane_bsize < BLOCK_SIZES_ALL);
663
0
    const int mi_width = mi_size_wide[plane_bsize];
664
0
    const int mi_height = mi_size_high[plane_bsize];
665
0
    const TX_SIZE max_tx_size = get_vartx_max_txsize(xd, plane_bsize, plane);
666
0
    const BLOCK_SIZE txb_size = txsize_to_bsize[max_tx_size];
667
0
    const int bw = mi_size_wide[txb_size];
668
0
    const int bh = mi_size_high[txb_size];
669
0
    int block = 0;
670
0
    const int step =
671
0
        tx_size_wide_unit[max_tx_size] * tx_size_high_unit[max_tx_size];
672
0
    av1_get_entropy_contexts(plane_bsize, pd, ctx.ta[plane], ctx.tl[plane]);
673
0
    av1_subtract_plane(x, plane_bsize, plane);
674
0
    arg.ta = ctx.ta[plane];
675
0
    arg.tl = ctx.tl[plane];
676
0
    const BLOCK_SIZE max_unit_bsize =
677
0
        get_plane_block_size(BLOCK_64X64, subsampling_x, subsampling_y);
678
0
    int mu_blocks_wide = mi_size_wide[max_unit_bsize];
679
0
    int mu_blocks_high = mi_size_high[max_unit_bsize];
680
0
    mu_blocks_wide = AOMMIN(mi_width, mu_blocks_wide);
681
0
    mu_blocks_high = AOMMIN(mi_height, mu_blocks_high);
682
683
0
    for (int idy = 0; idy < mi_height; idy += mu_blocks_high) {
684
0
      for (int idx = 0; idx < mi_width; idx += mu_blocks_wide) {
685
0
        int blk_row, blk_col;
686
0
        const int unit_height = AOMMIN(mu_blocks_high + idy, mi_height);
687
0
        const int unit_width = AOMMIN(mu_blocks_wide + idx, mi_width);
688
0
        for (blk_row = idy; blk_row < unit_height; blk_row += bh) {
689
0
          for (blk_col = idx; blk_col < unit_width; blk_col += bw) {
690
0
            encode_block_inter(plane, block, blk_row, blk_col, plane_bsize,
691
0
                               max_tx_size, &arg, dry_run);
692
0
            block += step;
693
0
          }
694
0
        }
695
0
      }
696
0
    }
697
0
  }
698
0
}
699
700
static void encode_block_intra_and_set_context(int plane, int block,
701
                                               int blk_row, int blk_col,
702
                                               BLOCK_SIZE plane_bsize,
703
1.38M
                                               TX_SIZE tx_size, void *arg) {
704
1.38M
  av1_encode_block_intra(plane, block, blk_row, blk_col, plane_bsize, tx_size,
705
1.38M
                         arg);
706
707
1.38M
  struct encode_b_args *const args = arg;
708
1.38M
  MACROBLOCK *x = args->x;
709
1.38M
  ENTROPY_CONTEXT *a = &args->ta[blk_col];
710
1.38M
  ENTROPY_CONTEXT *l = &args->tl[blk_row];
711
1.38M
  av1_set_txb_context(x, plane, block, tx_size, a, l);
712
1.38M
}
713
714
void av1_encode_block_intra(int plane, int block, int blk_row, int blk_col,
715
                            BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
716
1.38M
                            void *arg) {
717
1.38M
  struct encode_b_args *const args = arg;
718
1.38M
  const AV1_COMP *const cpi = args->cpi;
719
1.38M
  const AV1_COMMON *const cm = &cpi->common;
720
1.38M
  MACROBLOCK *const x = args->x;
721
1.38M
  MACROBLOCKD *const xd = &x->e_mbd;
722
1.38M
  struct macroblock_plane *const p = &x->plane[plane];
723
1.38M
  struct macroblockd_plane *const pd = &xd->plane[plane];
724
1.38M
  tran_low_t *dqcoeff = p->dqcoeff + BLOCK_OFFSET(block);
725
1.38M
  PLANE_TYPE plane_type = get_plane_type(plane);
726
1.38M
  uint16_t *eob = &p->eobs[block];
727
1.38M
  const int dst_stride = pd->dst.stride;
728
1.38M
  uint8_t *dst = &pd->dst.buf[(blk_row * dst_stride + blk_col) << MI_SIZE_LOG2];
729
1.38M
  int dummy_rate_cost = 0;
730
731
1.38M
  av1_predict_intra_block_facade(cm, xd, plane, blk_col, blk_row, tx_size);
732
733
1.38M
  TX_TYPE tx_type = DCT_DCT;
734
1.38M
  const int bw = mi_size_wide[plane_bsize];
735
1.38M
  if (plane == 0 && is_blk_skip(x->txfm_search_info.blk_skip, plane,
736
942k
                                blk_row * bw + blk_col)) {
737
930k
    *eob = 0;
738
930k
    p->txb_entropy_ctx[block] = 0;
739
930k
  } else {
740
452k
    av1_subtract_txb(x, plane, plane_bsize, blk_col, blk_row, tx_size);
741
742
452k
    const ENTROPY_CONTEXT *a = &args->ta[blk_col];
743
452k
    const ENTROPY_CONTEXT *l = &args->tl[blk_row];
744
452k
    tx_type = av1_get_tx_type(xd, plane_type, blk_row, blk_col, tx_size,
745
452k
                              cm->features.reduced_tx_set_used);
746
452k
    TxfmParam txfm_param;
747
452k
    QUANT_PARAM quant_param;
748
452k
    const int use_trellis =
749
452k
        is_trellis_used(args->enable_optimize_b, args->dry_run);
750
452k
    int quant_idx;
751
452k
    if (use_trellis)
752
90.8k
      quant_idx = AV1_XFORM_QUANT_FP;
753
361k
    else
754
361k
      quant_idx =
755
18.4E
          USE_B_QUANT_NO_TRELLIS ? AV1_XFORM_QUANT_B : AV1_XFORM_QUANT_FP;
756
757
452k
    av1_setup_xform(cm, x, tx_size, tx_type, &txfm_param);
758
452k
    av1_setup_quant(tx_size, use_trellis, quant_idx,
759
452k
                    cpi->oxcf.q_cfg.quant_b_adapt, &quant_param);
760
452k
    av1_setup_qmatrix(&cm->quant_params, xd, plane, tx_size, tx_type,
761
452k
                      &quant_param);
762
763
452k
    av1_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize, &txfm_param,
764
452k
                    &quant_param);
765
766
    // Whether trellis or dropout optimization is required for key frames and
767
    // intra frames.
768
452k
    const bool do_trellis = (frame_is_intra_only(cm) &&
769
455k
                             (KEY_BLOCK_OPT_TYPE == TRELLIS_OPT ||
770
455k
                              KEY_BLOCK_OPT_TYPE == TRELLIS_DROPOUT_OPT)) ||
771
452k
                            (!frame_is_intra_only(cm) &&
772
0
                             (INTRA_BLOCK_OPT_TYPE == TRELLIS_OPT ||
773
0
                              INTRA_BLOCK_OPT_TYPE == TRELLIS_DROPOUT_OPT));
774
452k
    const bool do_dropout = (frame_is_intra_only(cm) &&
775
455k
                             (KEY_BLOCK_OPT_TYPE == DROPOUT_OPT ||
776
455k
                              KEY_BLOCK_OPT_TYPE == TRELLIS_DROPOUT_OPT)) ||
777
452k
                            (!frame_is_intra_only(cm) &&
778
0
                             (INTRA_BLOCK_OPT_TYPE == DROPOUT_OPT ||
779
0
                              INTRA_BLOCK_OPT_TYPE == TRELLIS_DROPOUT_OPT));
780
781
452k
    if (quant_param.use_optimize_b && do_trellis) {
782
90.8k
      TXB_CTX txb_ctx;
783
90.8k
      get_txb_ctx(plane_bsize, tx_size, plane, a, l, &txb_ctx);
784
90.8k
      av1_optimize_b(args->cpi, x, plane, block, tx_size, tx_type, &txb_ctx,
785
90.8k
                     &dummy_rate_cost);
786
90.8k
    }
787
455k
    if (do_dropout) {
788
455k
      av1_dropout_qcoeff(x, plane, block, tx_size, tx_type,
789
455k
                         cm->quant_params.base_qindex);
790
455k
    }
791
452k
  }
792
793
1.38M
  if (*eob) {
794
22.8k
    av1_inverse_transform_block(xd, dqcoeff, plane, tx_type, tx_size, dst,
795
22.8k
                                dst_stride, *eob,
796
22.8k
                                cm->features.reduced_tx_set_used);
797
22.8k
  }
798
799
  // TODO(jingning): Temporarily disable txk_type check for eob=0 case.
800
  // It is possible that certain collision in hash index would cause
801
  // the assertion failure. To further optimize the rate-distortion
802
  // performance, we need to re-visit this part and enable this assert
803
  // again.
804
1.38M
  if (*eob == 0 && plane == 0) {
805
#if 0
806
    if (args->cpi->oxcf.q_cfg.aq_mode == NO_AQ
807
        && args->cpi->oxcf.q_cfg.deltaq_mode == NO_DELTA_Q) {
808
      assert(xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col)] ==
809
          DCT_DCT);
810
    }
811
#endif
812
929k
    update_txk_array(xd, blk_row, blk_col, tx_size, DCT_DCT);
813
929k
  }
814
815
  // For intra mode, skipped blocks are so rare that transmitting skip=1 is
816
  // very expensive.
817
1.38M
  *(args->skip) = 0;
818
819
1.38M
  if (plane == AOM_PLANE_Y && xd->cfl.store_y) {
820
111k
    cfl_store_tx(xd, blk_row, blk_col, tx_size, plane_bsize);
821
111k
  }
822
1.38M
}
823
824
void av1_encode_intra_block_plane(const struct AV1_COMP *cpi, MACROBLOCK *x,
825
                                  BLOCK_SIZE bsize, int plane, RUN_TYPE dry_run,
826
223k
                                  TRELLIS_OPT_TYPE enable_optimize_b) {
827
223k
  assert(bsize < BLOCK_SIZES_ALL);
828
223k
  const MACROBLOCKD *const xd = &x->e_mbd;
829
223k
  if (plane && !xd->is_chroma_ref) return;
830
831
213k
  const struct macroblockd_plane *const pd = &xd->plane[plane];
832
213k
  const int ss_x = pd->subsampling_x;
833
213k
  const int ss_y = pd->subsampling_y;
834
213k
  ENTROPY_CONTEXT ta[MAX_MIB_SIZE] = { 0 };
835
213k
  ENTROPY_CONTEXT tl[MAX_MIB_SIZE] = { 0 };
836
213k
  struct encode_b_args arg = { cpi, x,  NULL,    &(xd->mi[0]->skip_txfm),
837
213k
                               ta,  tl, dry_run, enable_optimize_b };
838
213k
  const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, ss_x, ss_y);
839
213k
  if (enable_optimize_b) {
840
160k
    av1_get_entropy_contexts(plane_bsize, pd, ta, tl);
841
160k
  }
842
213k
  av1_foreach_transformed_block_in_plane(
843
213k
      xd, plane_bsize, plane, encode_block_intra_and_set_context, &arg);
844
213k
}