Coverage Report

Created: 2026-12-01 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/avm/av2/common/reconintra.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
3
 *
4
 * This source code is subject to the terms of the BSD 3-Clause Clear License
5
 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6
 * License was not distributed with this source code in the LICENSE file, you
7
 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
8
 * Alliance for Open Media Patent License 1.0 was not distributed with this
9
 * source code in the PATENTS file, you can obtain it at
10
 * aomedia.org/license/patent-license/.
11
 */
12
13
#include <math.h>
14
15
#include "config/avm_config.h"
16
#include "config/avm_dsp_rtcd.h"
17
#include "config/av2_rtcd.h"
18
19
#include "avm_dsp/avm_dsp_common.h"
20
#include "avm_mem/avm_mem.h"
21
#include "avm_ports/avm_once.h"
22
#include "avm_ports/mem.h"
23
#include "avm_ports/system_state.h"
24
#include "av2/common/av2_common_int.h"
25
#include "av2/common/cfl.h"
26
#include "av2/common/intra_dip.h"
27
#include "av2/common/reconintra.h"
28
#include <av2/encoder/block.h>
29
30
enum {
31
  NEED_LEFT = 1 << 1,
32
  NEED_ABOVE = 1 << 2,
33
  NEED_ABOVERIGHT = 1 << 3,
34
  NEED_ABOVELEFT = 1 << 4,
35
  NEED_BOTTOMLEFT = 1 << 5,
36
};
37
38
#define INTRA_EDGE_FILT 3
39
0
#define INTRA_EDGE_TAPS 5
40
51.5k
#define NUM_INTRA_NEIGHBOUR_PIXELS (MAX_TX_SIZE * 2 + 64)
41
42
static const uint8_t extend_modes[INTRA_MODES] = {
43
  NEED_ABOVE | NEED_LEFT | NEED_ABOVELEFT,  // DC
44
  NEED_ABOVE,                               // V
45
  NEED_LEFT,                                // H
46
  NEED_ABOVE | NEED_ABOVERIGHT,             // D45
47
  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // D135
48
  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // D113
49
  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // D157
50
  NEED_LEFT | NEED_BOTTOMLEFT,              // D203
51
  NEED_ABOVE | NEED_ABOVERIGHT,             // D67
52
  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT | NEED_ABOVERIGHT |
53
      NEED_BOTTOMLEFT,                       // SMOOTH
54
  NEED_LEFT | NEED_ABOVE | NEED_BOTTOMLEFT,  // SMOOTH_V
55
  NEED_LEFT | NEED_ABOVE | NEED_ABOVERIGHT,  // SMOOTH_H
56
  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,   // PAETH
57
};
58
59
static int has_top_right(const AV2_COMMON *cm, const MACROBLOCKD *xd,
60
                         BLOCK_SIZE bsize, int mi_row, int mi_col,
61
                         int top_available, int right_available, TX_SIZE txsz,
62
                         int plane, int row_off, int col_off, int ss_x,
63
                         int ss_y, int px_to_right_edge, int *px_top_right,
64
909k
                         int is_bsize_altered_for_chroma) {
65
909k
  if (!top_available || !right_available) return 0;
66
67
662k
  const int bw_unit = mi_size_wide[bsize];
68
662k
  const int plane_bw_unit = AVMMAX(bw_unit >> ss_x, 1);
69
662k
  const int top_right_count_unit = tx_size_wide_unit[txsz];
70
662k
  const int px_tr_common = AVMMIN(tx_size_wide[txsz], px_to_right_edge);
71
72
662k
  if (px_tr_common <= 0) return 0;
73
74
  // Do not allow more than 64 top reference samples for intra prediction
75
662k
  if (plane != AVM_PLANE_Y && tx_size_wide[txsz] > 32) return 0;
76
77
657k
  *px_top_right = px_tr_common;
78
79
657k
  if (plane == AVM_PLANE_Y) {
80
492k
    int txb_idx = xd->mi[0]->txb_idx;
81
492k
    TX_PARTITION_TYPE partition = xd->mi[0]->tx_partition_type[0];
82
492k
    if (partition == TX_PARTITION_HORZ5 || partition == TX_PARTITION_VERT5) {
83
22.4k
      if (txb_idx >= 1) return 0;
84
22.4k
    }
85
492k
  }
86
87
643k
  if (row_off > 0) {  // Just need to check if enough pixels on the right.
88
146k
    const int plane_bw_unit_64 = mi_size_wide[BLOCK_64X64] >> ss_x;
89
146k
    if (block_size_wide[bsize] > block_size_wide[BLOCK_64X64]) {
90
      // Special case: For 256 and 128 blocks, if the tx unit's top right center
91
      // is aligned with 64x64 boundary and we are not at the right most column,
92
      // then the tx unit may have pixels available at its top-right corner.
93
54.4k
      const int tr_col = col_off + top_right_count_unit;
94
54.4k
      const int plane_bh_unit_64 = mi_size_high[BLOCK_64X64] >> ss_y;
95
54.4k
      if (tr_col != plane_bw_unit && tr_col % plane_bw_unit_64 == 0 &&
96
10.3k
          row_off % plane_bh_unit_64 == 0) {
97
8.58k
        const int plane_bw_unit_128 = mi_size_wide[BLOCK_128X128] >> ss_x;
98
8.58k
        const int plane_bh_unit_128 = mi_size_high[BLOCK_128X128] >> ss_y;
99
        // Since 64x64 TUs are decoded in 128x128 units, the top-right reference
100
        // samples of the top-right transform block in the bottom-right 64x64
101
        // transform block within a 128x128 block, i.e., ((row_off %
102
        // plane_bh_unit_128) && !(tr_col % plane_bw_unit_128)), are unavailable
103
8.58k
        return ((row_off % plane_bh_unit_128) && !(tr_col % plane_bw_unit_128))
104
8.58k
                   ? 0
105
8.58k
                   : 1;
106
8.58k
      }
107
45.8k
      const int col_off_64 = col_off % plane_bw_unit_64;
108
45.8k
      return col_off_64 + top_right_count_unit < plane_bw_unit_64;
109
54.4k
    }
110
92.0k
    return col_off + top_right_count_unit < plane_bw_unit;
111
496k
  } else {
112
    // All top-right pixels are in the block above, which is already available.
113
496k
    if (col_off + top_right_count_unit < plane_bw_unit) return 1;
114
115
    // Handle the top-right intra tx block of the coding block
116
451k
    const int sb_mi_size = mi_size_wide[cm->sb_size];
117
451k
    const int mi_row_aligned =
118
451k
        is_bsize_altered_for_chroma
119
451k
            ? xd->mi[0]->chroma_ref_info.mi_row_chroma_base
120
451k
            : mi_row;
121
451k
    const int mi_col_aligned =
122
451k
        is_bsize_altered_for_chroma
123
451k
            ? xd->mi[0]->chroma_ref_info.mi_col_chroma_base
124
451k
            : mi_col;
125
451k
    const int tr_mask_row = (mi_row_aligned & (sb_mi_size - 1)) - 1;
126
451k
    const int tr_mask_col =
127
451k
        (mi_col_aligned & (sb_mi_size - 1)) + mi_size_wide[bsize];
128
129
451k
    if (tr_mask_row < 0) {
130
98.0k
      return 1;
131
353k
    } else if (tr_mask_col >= sb_mi_size) {
132
39.4k
      return 0;
133
314k
    } else {  // Handle the general case: the top_right mi is in the same SB
134
314k
      const int tr_offset = tr_mask_row * xd->is_mi_coded_stride + tr_mask_col;
135
      // As long as the first mi is available, we determine tr is available
136
314k
      int has_tr =
137
314k
          (xd->is_mi_coded[av2_get_sdp_idx(xd->tree_type)][tr_offset] == 1);
138
139
      // Calculate px_top_right: how many top-right pixels are available. If it
140
      // is less than tx_size_wide[txsz], px_top_right will be used to
141
      // determine the location of the last available pixel, which will be used
142
      // for padding.
143
314k
      if (has_tr) {
144
183k
        int mi_tr = 0;
145
1.02M
        for (int i = 0; i < top_right_count_unit << ss_x; ++i) {
146
846k
          if ((tr_mask_col + i) >= sb_mi_size ||
147
845k
              xd->is_mi_coded[av2_get_sdp_idx(xd->tree_type)][tr_offset + i] !=
148
845k
                  1) {
149
2.93k
            break;
150
843k
          } else {
151
843k
            mi_tr++;
152
843k
          }
153
846k
        }
154
155
183k
        *px_top_right = AVMMIN((mi_tr << MI_SIZE_LOG2) >> ss_x, px_tr_common);
156
183k
      }
157
158
314k
      return has_tr;
159
314k
    }
160
451k
  }
161
643k
}
162
163
static int has_bottom_left(const AV2_COMMON *cm, const MACROBLOCKD *xd,
164
                           BLOCK_SIZE bsize, int mi_row, int mi_col,
165
                           int bottom_available, int left_available,
166
                           TX_SIZE txsz, int plane, int row_off, int col_off,
167
                           int ss_x, int ss_y, int px_to_bottom_edge,
168
                           int *px_bottom_left,
169
840k
                           int is_bsize_altered_for_chroma) {
170
840k
  if (!bottom_available || !left_available) return 0;
171
172
620k
  const int px_bl_common = AVMMIN(tx_size_high[txsz], px_to_bottom_edge);
173
174
620k
  if (px_bl_common <= 0) return 0;
175
176
  // Do not allow more than 64 left reference samples for intra prediction
177
620k
  if (plane != AVM_PLANE_Y && tx_size_high[txsz] > 32) return 0;
178
179
614k
  if (plane == AVM_PLANE_Y) {
180
471k
    int txb_idx = xd->mi[0]->txb_idx;
181
471k
    TX_PARTITION_TYPE partition = xd->mi[0]->tx_partition_type[0];
182
471k
    if (partition == TX_PARTITION_HORZ5 || partition == TX_PARTITION_VERT5) {
183
23.2k
      if (txb_idx >= 1) return 0;
184
23.2k
    }
185
471k
  }
186
598k
  *px_bottom_left = px_bl_common;
187
188
  // Special case for 256x* and 128x* coding blocks. This is needed because
189
  // 256x* and 128x* coding blocks are divided into 64x* blocks, and each 64x*
190
  // block is coded in 128x* unit. For example, for a 256x256 coding block, the
191
  // coding order of 64x64 residual blocks are following
192
  // A B E F
193
  // C D G H
194
  // I J M N
195
  // K L O P
196
598k
  if (block_size_wide[bsize] > block_size_wide[BLOCK_64X64] && col_off > 0) {
197
59.1k
    const int plane_bw_unit_64 = mi_size_wide[BLOCK_64X64] >> ss_x;
198
59.1k
    const int col_off_64 = col_off % plane_bw_unit_64;
199
59.1k
    if (col_off_64 == 0) {
200
      // We are at the left edge of top-right or bottom-right 64x* block.
201
27.0k
      const int plane_bh_unit_64 = mi_size_high[BLOCK_64X64] >> ss_y;
202
27.0k
      const int row_off_64 = row_off % plane_bh_unit_64;
203
27.0k
      const int plane_bh_unit =
204
27.0k
          AVMMIN(mi_size_high[bsize] >> ss_y, plane_bh_unit_64);
205
      // Check if all bottom-left pixels are in the left 64x* block (which is
206
      // already coded).
207
27.0k
      const int plane_bw_unit_128 = mi_size_wide[BLOCK_128X128] >> ss_x;
208
27.0k
      const int col_off_128 = col_off % plane_bw_unit_128;
209
27.0k
      if (col_off_128 == 0) {
210
        // Since 64x64 TUs are decoded in 128x128 units, the bottom-left
211
        // reference samples of the top-left 64x64 transform block within a
212
        // 128x128 block, i.e., (col_off_64 == 0 && row_off_128 +
213
        // tx_size_high_unit[txsz] < plane_bh_unit_128), become available
214
0
        const int plane_bh_unit_128 = mi_size_high[BLOCK_128X128] >> ss_y;
215
0
        const int row_off_128 = row_off % plane_bh_unit_128;
216
0
        return row_off_128 + tx_size_high_unit[txsz] < plane_bh_unit_128;
217
0
      } else
218
27.0k
        return row_off_64 + tx_size_high_unit[txsz] < plane_bh_unit;
219
27.0k
    }
220
59.1k
  }
221
222
570k
  if (col_off > 0) {
223
    // Bottom-left pixels are in the bottom-left block, which is not available.
224
105k
    return 0;
225
465k
  } else {
226
465k
    const int bh_unit = mi_size_high[bsize];
227
465k
    const int plane_bh_unit = AVMMAX(bh_unit >> ss_y, 1);
228
465k
    const int bottom_left_count_unit = tx_size_high_unit[txsz];
229
230
    // All bottom-left pixels are in the left block, which is already available.
231
465k
    if (row_off + bottom_left_count_unit < plane_bh_unit) return 1;
232
233
    // The general case: neither the leftmost column nor the bottom row. The
234
    // bottom-left mi is in the same SB
235
437k
    const int sb_mi_size = mi_size_high[cm->sb_size];
236
437k
    const int mi_row_aligned =
237
437k
        is_bsize_altered_for_chroma
238
437k
            ? xd->mi[0]->chroma_ref_info.mi_row_chroma_base
239
437k
            : mi_row;
240
437k
    const int mi_col_aligned =
241
437k
        is_bsize_altered_for_chroma
242
437k
            ? xd->mi[0]->chroma_ref_info.mi_col_chroma_base
243
437k
            : mi_col;
244
437k
    const int bl_mask_row =
245
437k
        (mi_row_aligned & (sb_mi_size - 1)) + mi_size_high[bsize];
246
437k
    const int bl_mask_col = (mi_col_aligned & (sb_mi_size - 1)) - 1;
247
248
437k
    if (bl_mask_col < 0) {
249
63.6k
      const int plane_sb_height = block_size_high[cm->sb_size] >> ss_y;
250
63.6k
      const int plane_bottom_row =
251
63.6k
          (((mi_row_aligned & (sb_mi_size - 1)) << MI_SIZE_LOG2) +
252
63.6k
           block_size_high[bsize]) >>
253
63.6k
          ss_y;
254
63.6k
      *px_bottom_left =
255
63.6k
          AVMMIN(plane_sb_height - plane_bottom_row, px_bl_common);
256
257
63.6k
      return *px_bottom_left > 0;
258
374k
    } else if (bl_mask_row >= sb_mi_size) {
259
77.5k
      return 0;
260
296k
    } else {
261
296k
      const int bl_offset = bl_mask_row * xd->is_mi_coded_stride + bl_mask_col;
262
      // As long as there is one bottom-left mi available, we determine bl is
263
      // available
264
296k
      int has_bl =
265
296k
          (xd->is_mi_coded[av2_get_sdp_idx(xd->tree_type)][bl_offset] == 1);
266
267
      // Calculate px_bottom_left: how many bottom-left pixels are available. If
268
      // it is less than tx_size_high[txsz], px_bottom_left will be used to
269
      // determine the location of the last available pixel, which will be used
270
      // for padding.
271
296k
      if (has_bl) {
272
136k
        int mi_bl = 0;
273
671k
        for (int i = 0; i < bottom_left_count_unit << ss_y; ++i) {
274
538k
          if ((bl_mask_row + i) >= sb_mi_size ||
275
536k
              xd->is_mi_coded[av2_get_sdp_idx(xd->tree_type)]
276
536k
                             [bl_offset + i * xd->is_mi_coded_stride] != 1) {
277
4.00k
            break;
278
534k
          } else {
279
534k
            mi_bl++;
280
534k
          }
281
538k
        }
282
283
136k
        *px_bottom_left = AVMMIN((mi_bl << MI_SIZE_LOG2) >> ss_y, px_bl_common);
284
136k
      }
285
286
296k
      return has_bl;
287
296k
    }
288
437k
  }
289
570k
}
290
291
typedef void (*intra_high_pred_fn)(uint16_t *dst, ptrdiff_t stride,
292
                                   const uint16_t *above, const uint16_t *left,
293
                                   int bd);
294
static intra_high_pred_fn pred_high[INTRA_MODES][TX_SIZES_ALL];
295
static intra_high_pred_fn dc_pred_high[2][2][TX_SIZES_ALL];
296
static intra_high_pred_fn ibp_dc_pred_high[2][2][TX_SIZES_ALL];
297
298
1
static void init_intra_predictors_internal(void) {
299
1
  assert(NELEMENTS(mode_to_angle_map) == INTRA_MODES);
300
301
1
#define INIT_RECTANGULAR(p, type)             \
302
14
  p[TX_4X8] = avm_##type##_predictor_4x8;     \
303
14
  p[TX_8X4] = avm_##type##_predictor_8x4;     \
304
14
  p[TX_8X16] = avm_##type##_predictor_8x16;   \
305
14
  p[TX_16X8] = avm_##type##_predictor_16x8;   \
306
14
  p[TX_16X32] = avm_##type##_predictor_16x32; \
307
14
  p[TX_32X16] = avm_##type##_predictor_32x16; \
308
14
  p[TX_32X64] = avm_##type##_predictor_32x64; \
309
14
  p[TX_64X32] = avm_##type##_predictor_64x32; \
310
14
  p[TX_4X16] = avm_##type##_predictor_4x16;   \
311
14
  p[TX_16X4] = avm_##type##_predictor_16x4;   \
312
14
  p[TX_8X32] = avm_##type##_predictor_8x32;   \
313
14
  p[TX_32X8] = avm_##type##_predictor_32x8;   \
314
14
  p[TX_16X64] = avm_##type##_predictor_16x64; \
315
14
  p[TX_64X16] = avm_##type##_predictor_64x16; \
316
14
  p[TX_4X32] = avm_##type##_predictor_4x32;   \
317
14
  p[TX_32X4] = avm_##type##_predictor_32x4;   \
318
14
  p[TX_8X64] = avm_##type##_predictor_8x64;   \
319
14
  p[TX_64X8] = avm_##type##_predictor_64x8;   \
320
14
  p[TX_4X64] = avm_##type##_predictor_4x64;   \
321
14
  p[TX_64X4] = avm_##type##_predictor_64x4;
322
323
1
#define INIT_NO_4X4(p, type)                  \
324
14
  p[TX_8X8] = avm_##type##_predictor_8x8;     \
325
14
  p[TX_16X16] = avm_##type##_predictor_16x16; \
326
14
  p[TX_32X32] = avm_##type##_predictor_32x32; \
327
14
  p[TX_64X64] = avm_##type##_predictor_64x64; \
328
14
  INIT_RECTANGULAR(p, type)
329
330
1
#define INIT_ALL_SIZES(p, type)           \
331
14
  p[TX_4X4] = avm_##type##_predictor_4x4; \
332
14
  INIT_NO_4X4(p, type)
333
334
1
  INIT_ALL_SIZES(pred_high[V_PRED], highbd_v);
335
1
  INIT_ALL_SIZES(pred_high[H_PRED], highbd_h);
336
1
  INIT_ALL_SIZES(pred_high[PAETH_PRED], highbd_paeth);
337
1
  INIT_ALL_SIZES(pred_high[SMOOTH_PRED], highbd_smooth);
338
1
  INIT_ALL_SIZES(pred_high[SMOOTH_V_PRED], highbd_smooth_v);
339
1
  INIT_ALL_SIZES(pred_high[SMOOTH_H_PRED], highbd_smooth_h);
340
1
  INIT_ALL_SIZES(dc_pred_high[0][0], highbd_dc_128);
341
1
  INIT_ALL_SIZES(dc_pred_high[0][1], highbd_dc_top);
342
1
  INIT_ALL_SIZES(dc_pred_high[1][0], highbd_dc_left);
343
1
  INIT_ALL_SIZES(dc_pred_high[1][1], highbd_dc);
344
1
  INIT_ALL_SIZES(ibp_dc_pred_high[0][0], highbd_dc_128);
345
1
  INIT_ALL_SIZES(ibp_dc_pred_high[0][1], highbd_ibp_dc_top);
346
1
  INIT_ALL_SIZES(ibp_dc_pred_high[1][0], highbd_ibp_dc_left);
347
1
  INIT_ALL_SIZES(ibp_dc_pred_high[1][1], highbd_ibp_dc);
348
1
#undef intra_pred_allsizes
349
1
}
350
351
// get the context for y_mode_idx
352
// the context of y_mode_idx depends on the count of directional neighboring
353
// modes
354
617k
int get_y_mode_idx_ctx(MACROBLOCKD *const xd) {
355
617k
  const PREDICTION_MODE above_joint_mode =
356
617k
      av2_get_joint_mode(xd->above_right_mbmi);
357
617k
  const PREDICTION_MODE left_joint_mode =
358
617k
      av2_get_joint_mode(xd->bottom_left_mbmi);
359
617k
  const int is_above_angular =
360
617k
      above_joint_mode >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
361
617k
  const int is_left_angular =
362
617k
      left_joint_mode >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
363
617k
  return is_above_angular + is_left_angular;
364
617k
}
365
/*! \brief set the luma intra mode and delta angles for a given mode index.
366
 * \param[in]    mode_idx           mode index in intra mode decision
367
 *                                  process.
368
 * \param[in]    mbmi               Pointer to structure holding
369
 *                                  the mode info for the current macroblock.
370
 */
371
void av2_set_y_mode_and_delta_angle(const int mode_idx,
372
618k
                                    MB_MODE_INFO *const mbmi) {
373
618k
  if (mode_idx < NON_DIRECTIONAL_MODES_COUNT) {
374
361k
    mbmi->mode = mode_idx;
375
361k
    mbmi->angle_delta[PLANE_TYPE_Y] = 0;
376
361k
  } else {
377
257k
    mbmi->mode =
378
257k
        (mode_idx - NON_DIRECTIONAL_MODES_COUNT) / TOTAL_ANGLE_DELTA_COUNT +
379
257k
        NON_DIRECTIONAL_MODES_COUNT;
380
257k
    mbmi->angle_delta[PLANE_TYPE_Y] =
381
257k
        (mode_idx - NON_DIRECTIONAL_MODES_COUNT) % TOTAL_ANGLE_DELTA_COUNT -
382
257k
        MAX_ANGLE_DELTA;
383
257k
  }
384
618k
  mbmi->mode = reordered_y_mode[mbmi->mode];
385
618k
}
386
387
// re-order the intra prediction modes for y component based
388
// on the neighboring intra prediction modes. The intra prediction
389
// mode list for 4x4, 4x8, and 8x4 blocks are fixed, and not dependent
390
// on the intra prediction modes of neighboring blocks
391
618k
void get_y_intra_mode_set(MB_MODE_INFO *mi, MACROBLOCKD *const xd) {
392
618k
  int neighbor_joint_modes[2];
393
618k
  neighbor_joint_modes[0] = av2_get_joint_mode(xd->bottom_left_mbmi);
394
618k
  neighbor_joint_modes[1] = av2_get_joint_mode(xd->above_right_mbmi);
395
618k
  const int is_left_directional_mode =
396
618k
      neighbor_joint_modes[0] >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
397
618k
  const int is_above_directional_mode =
398
618k
      neighbor_joint_modes[1] >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
399
  // To mark whether each intra prediction mode is added into intra mode list or
400
  // not
401
618k
  int is_mode_selected_list[LUMA_MODE_COUNT];
402
403
618k
  const int block_width = block_size_wide[mi->sb_type[PLANE_TYPE_Y]];
404
618k
  const int block_height = block_size_high[mi->sb_type[PLANE_TYPE_Y]];
405
  // Check whether the block area size is greater than 64 samples
406
618k
  const int is_large_block = (block_width * block_height > 64);
407
408
618k
  const int is_small_block = (mi->sb_type[PLANE_TYPE_Y] < BLOCK_8X8);
409
410
618k
  int i, j;
411
618k
  int mode_idx = 0;
412
38.3M
  for (i = 0; i < LUMA_MODE_COUNT; i++) {
413
37.7M
    is_mode_selected_list[i] = -1;
414
37.7M
    mi->y_intra_mode_list[i] = -1;
415
37.7M
  }
416
417
  // always put non-directional modes into the first positions of the mode list
418
3.70M
  for (i = 0; i < NON_DIRECTIONAL_MODES_COUNT; ++i) {
419
3.09M
    mi->y_intra_mode_list[mode_idx++] = i;
420
3.09M
    is_mode_selected_list[i] = 1;
421
3.09M
  }
422
423
618k
  if (is_small_block == 0) {
424
563k
    int directional_mode_cnt =
425
563k
        is_above_directional_mode + is_left_directional_mode;
426
563k
    if (directional_mode_cnt == 2 &&
427
82.6k
        neighbor_joint_modes[0] == neighbor_joint_modes[1])
428
16.0k
      directional_mode_cnt = 1;
429
    // copy above mode to left mode, if left mode is non-directiona mode and
430
    // above mode is directional mode
431
563k
    if (directional_mode_cnt == 1 && is_left_directional_mode == 0) {
432
118k
      neighbor_joint_modes[0] = neighbor_joint_modes[1];
433
118k
    }
434
927k
    for (i = 0; i < directional_mode_cnt; ++i) {
435
363k
      mi->y_intra_mode_list[mode_idx++] = neighbor_joint_modes[i];
436
363k
      is_mode_selected_list[neighbor_joint_modes[i]] = 1;
437
363k
    }
438
439
    // Add offsets to derive the neighboring modes
440
563k
    if (is_large_block) {
441
2.48M
      for (i = 0; i < 4; ++i) {
442
3.23M
        for (j = 0; j < directional_mode_cnt; ++j) {
443
1.24M
          int left_derived_mode = (neighbor_joint_modes[j] - i +
444
1.24M
                                   (56 - NON_DIRECTIONAL_MODES_COUNT - 1)) %
445
1.24M
                                      56 +
446
1.24M
                                  NON_DIRECTIONAL_MODES_COUNT;
447
1.24M
          int right_derived_mode = (neighbor_joint_modes[j] + i -
448
1.24M
                                    (NON_DIRECTIONAL_MODES_COUNT - 1)) %
449
1.24M
                                       56 +
450
1.24M
                                   NON_DIRECTIONAL_MODES_COUNT;
451
452
1.24M
          if (is_mode_selected_list[left_derived_mode] == -1) {
453
1.16M
            mi->y_intra_mode_list[mode_idx++] = left_derived_mode;
454
1.16M
            is_mode_selected_list[left_derived_mode] = 1;
455
1.16M
          }
456
1.24M
          if (is_mode_selected_list[right_derived_mode] == -1) {
457
1.16M
            mi->y_intra_mode_list[mode_idx++] = right_derived_mode;
458
1.16M
            is_mode_selected_list[right_derived_mode] = 1;
459
1.16M
          }
460
1.24M
        }
461
1.98M
      }
462
497k
    }
463
563k
  }
464
465
  // Everything added so far came from neighbouring blocks, so record how many
466
  // entries that is. What the default fill adds below does not count.
467
618k
  mi->num_y_intra_mpm = mode_idx;
468
469
  // fill the remaining list with default modes
470
34.9M
  for (i = 0; i < LUMA_MODE_COUNT - NON_DIRECTIONAL_MODES_COUNT &&
471
34.4M
              mode_idx < LUMA_MODE_COUNT;
472
34.3M
       ++i) {
473
34.3M
    if (is_mode_selected_list[default_mode_list_y[i] +
474
34.3M
                              NON_DIRECTIONAL_MODES_COUNT] == -1) {
475
31.7M
      mi->y_intra_mode_list[mode_idx++] =
476
31.7M
          default_mode_list_y[i] + NON_DIRECTIONAL_MODES_COUNT;
477
31.7M
      is_mode_selected_list[default_mode_list_y[i] +
478
31.7M
                            NON_DIRECTIONAL_MODES_COUNT] = 1;
479
31.7M
    }
480
34.3M
  }
481
618k
}
482
483
// re-order the intra prediction mode of uv component based on the
484
// intra prediction mode of co-located y block
485
249k
void get_uv_intra_mode_set(MB_MODE_INFO *mi) {
486
249k
  int is_mode_selected_list[UV_INTRA_MODES - 1];
487
249k
  int i;
488
249k
  int mode_idx = 0;
489
3.49M
  for (i = 0; i < UV_INTRA_MODES - 1; i++) {
490
3.24M
    is_mode_selected_list[i] = -1;
491
3.24M
    mi->uv_intra_mode_list[i] = -1;
492
3.24M
  }
493
  // check whether co-located y mode is directional mode or not
494
249k
  if (av2_is_directional_mode(mi->mode)) {
495
103k
    mi->uv_intra_mode_list[mode_idx++] = mi->mode;
496
103k
    is_mode_selected_list[mi->mode] = 1;
497
103k
  }
498
499
  // put non-directional modes into the mode list
500
249k
  mi->uv_intra_mode_list[mode_idx++] = UV_DC_PRED;
501
249k
  is_mode_selected_list[UV_DC_PRED] = 1;
502
249k
  mi->uv_intra_mode_list[mode_idx++] = UV_SMOOTH_PRED;
503
249k
  is_mode_selected_list[UV_SMOOTH_PRED] = 1;
504
249k
  mi->uv_intra_mode_list[mode_idx++] = UV_SMOOTH_V_PRED;
505
249k
  is_mode_selected_list[UV_SMOOTH_V_PRED] = 1;
506
249k
  mi->uv_intra_mode_list[mode_idx++] = UV_SMOOTH_H_PRED;
507
249k
  is_mode_selected_list[UV_SMOOTH_H_PRED] = 1;
508
249k
  mi->uv_intra_mode_list[mode_idx++] = UV_PAETH_PRED;
509
249k
  is_mode_selected_list[UV_PAETH_PRED] = 1;
510
511
  // fill the remaining list with default modes
512
249k
  const int directional_mode_count = DIR_MODE_END - DIR_MODE_START;
513
2.24M
  for (i = 0; i < directional_mode_count; ++i) {
514
1.99M
    if (is_mode_selected_list[default_mode_list_uv[i]] == -1) {
515
1.89M
      mi->uv_intra_mode_list[mode_idx++] = default_mode_list_uv[i];
516
1.89M
      is_mode_selected_list[default_mode_list_uv[i]] = 1;
517
1.89M
    }
518
1.99M
  }
519
249k
}
520
521
415k
int get_cfl_ctx(MACROBLOCKD *xd) {
522
415k
  const int above_ctx =
523
415k
      xd->chroma_above_mbmi ? xd->chroma_above_mbmi->uv_mode == UV_CFL_PRED : 0;
524
415k
  const int left_ctx =
525
415k
      xd->chroma_left_mbmi ? xd->chroma_left_mbmi->uv_mode == UV_CFL_PRED : 0;
526
415k
  return above_ctx + left_ctx;
527
415k
}
528
529
// Directional prediction, zone 1: 0 < angle < 90
530
void av2_highbd_dr_prediction_z1_c(uint16_t *dst, ptrdiff_t stride, int bw,
531
                                   int bh, const uint16_t *above,
532
                                   const uint16_t *left, int dx, int dy, int bd,
533
0
                                   int mrl_index) {
534
0
  int r, c, x, base, shift, val;
535
536
0
  (void)left;
537
0
  (void)dy;
538
0
  (void)bd;
539
0
  assert(dy == 1);
540
0
  assert(dx > 0);
541
542
0
  const int max_base_x = (bw + bh) - 1 + (mrl_index << 1);
543
0
  const int frac_bits = 6;
544
0
  const int base_inc = 1;
545
0
  x = dx * (1 + mrl_index);
546
0
  for (r = 0; r < bh; ++r, dst += stride, x += dx) {
547
0
    base = x >> frac_bits;
548
0
    shift = (x & 0x3F) >> 1;
549
550
0
    if (base >= max_base_x) {
551
0
      for (int i = r; i < bh; ++i) {
552
0
        avm_memset16(dst, above[max_base_x], bw);
553
0
        dst += stride;
554
0
      }
555
0
      return;
556
0
    }
557
558
0
    for (c = 0; c < bw; ++c, base += base_inc) {
559
0
      if (base < max_base_x) {
560
0
        val = above[base] * (32 - shift) + above[base + 1] * shift;
561
0
        dst[c] = ROUND_POWER_OF_TWO(val, 5);
562
0
      } else {
563
0
        dst[c] = above[max_base_x];
564
0
      }
565
0
    }
566
0
  }
567
0
}
568
569
// Directional prediction, zone 2: 90 < angle < 180
570
void av2_highbd_dr_prediction_z2_c(uint16_t *dst, ptrdiff_t stride, int bw,
571
                                   int bh, const uint16_t *above,
572
                                   const uint16_t *left, int dx, int dy, int bd,
573
0
                                   int mrl_index) {
574
0
  (void)bd;
575
0
  assert(dx > 0);
576
0
  assert(dy > 0);
577
578
0
  const int min_base_x = -1 - mrl_index;
579
0
  const int min_base_y = -1 - mrl_index;
580
0
  (void)min_base_y;
581
0
  const int frac_bits_x = 6;
582
0
  const int frac_bits_y = 6;
583
584
0
  for (int r = 0; r < bh; ++r) {
585
0
    for (int c = 0; c < bw; ++c) {
586
0
      int val;
587
0
      int y = r + 1;
588
0
      int x = (c << 6) - (y + mrl_index) * dx;
589
0
      const int base_x = x >> frac_bits_x;
590
0
      if (base_x >= min_base_x) {
591
0
        const int shift = (x & 0x3F) >> 1;
592
0
        val = above[base_x] * (32 - shift) + above[base_x + 1] * shift;
593
0
        val = ROUND_POWER_OF_TWO(val, 5);
594
0
      } else {
595
0
        x = c + 1;
596
0
        y = (r << 6) - (x + mrl_index) * dy;
597
0
        const int base_y = y >> frac_bits_y;
598
0
        assert(base_y >= min_base_y);
599
0
        const int shift = (y & 0x3F) >> 1;
600
0
        val = left[base_y] * (32 - shift) + left[base_y + 1] * shift;
601
0
        val = ROUND_POWER_OF_TWO(val, 5);
602
0
      }
603
0
      dst[c] = val;
604
0
    }
605
0
    dst += stride;
606
0
  }
607
0
}
608
609
// Directional prediction, zone 3: 180 < angle < 270
610
void av2_highbd_dr_prediction_z3_c(uint16_t *dst, ptrdiff_t stride, int bw,
611
                                   int bh, const uint16_t *above,
612
                                   const uint16_t *left, int dx, int dy, int bd,
613
0
                                   int mrl_index) {
614
0
  int r, c, y, base, shift, val;
615
616
0
  (void)above;
617
0
  (void)dx;
618
0
  (void)bd;
619
0
  assert(dx == 1);
620
0
  assert(dy > 0);
621
622
0
  const int max_base_y = (bw + bh - 1) + (mrl_index << 1);
623
0
  const int frac_bits = 6;
624
0
  const int base_inc = 1;
625
0
  y = dy * (1 + mrl_index);
626
0
  for (c = 0; c < bw; ++c, y += dy) {
627
0
    base = y >> frac_bits;
628
0
    shift = (y & 0x3F) >> 1;
629
630
0
    for (r = 0; r < bh; ++r, base += base_inc) {
631
0
      if (base < max_base_y) {
632
0
        val = left[base] * (32 - shift) + left[base + 1] * shift;
633
0
        dst[r * stride + c] = ROUND_POWER_OF_TWO(val, 5);
634
0
      } else {
635
0
        for (; r < bh; ++r) dst[r * stride + c] = left[max_base_y];
636
0
        break;
637
0
      }
638
0
    }
639
0
  }
640
0
}
641
642
// Directional prediction, zone 1: 0 < angle < 90 using IDIF
643
void av2_highbd_dr_prediction_z1_idif_c(uint16_t *dst, ptrdiff_t stride, int bw,
644
                                        int bh, const uint16_t *above,
645
                                        const uint16_t *left, int dx, int dy,
646
0
                                        int bd, int mrl_index) {
647
0
  int r, c, x, base, shift, val;
648
649
0
  uint16_t ref[4] = { 0 };
650
651
0
  (void)left;
652
0
  (void)dy;
653
0
  (void)bd;
654
0
  assert(dy == 1);
655
0
  assert(dx > 0);
656
657
0
  const int max_base_x = (bw + bh) - 1 + (mrl_index << 1);
658
0
  const int frac_bits = 6;
659
0
  const int base_inc = 1;
660
661
0
  x = dx * (1 + mrl_index);
662
0
  for (r = 0; r < bh; ++r, dst += stride, x += dx) {
663
0
    base = x >> frac_bits;
664
0
    shift = (x & 0x3F) >> 1;
665
666
0
    if (base > max_base_x) {
667
0
      for (int i = r; i < bh; ++i) {
668
0
        avm_memset16(dst, above[max_base_x], bw);
669
0
        dst += stride;
670
0
      }
671
0
      return;
672
0
    }
673
674
0
    for (c = 0; c < bw; ++c, base += base_inc) {
675
0
      if (base <= max_base_x) {
676
        // 4-tap filter
677
0
        ref[0] = above[base - 1];
678
0
        ref[1] = above[base];
679
0
        ref[2] = above[base + 1];
680
0
        ref[3] = above[base + 2];
681
682
0
        val = av2_dr_interp_filter[shift][0] * ref[0] +
683
0
              av2_dr_interp_filter[shift][1] * ref[1] +
684
0
              av2_dr_interp_filter[shift][2] * ref[2] +
685
0
              av2_dr_interp_filter[shift][3] * ref[3];
686
687
0
        dst[c] = clip_pixel_highbd(
688
0
            ROUND_POWER_OF_TWO(val, POWER_DR_INTERP_FILTER), bd);
689
0
      } else {
690
0
        dst[c] = above[max_base_x];
691
0
      }
692
0
    }
693
0
  }
694
0
}
695
696
// Directional prediction, zone 2: 90 < angle < 180 using IDIF
697
void av2_highbd_dr_prediction_z2_idif_c(uint16_t *dst, ptrdiff_t stride, int bw,
698
                                        int bh, const uint16_t *above,
699
                                        const uint16_t *left, int dx, int dy,
700
0
                                        int bd, int mrl_index) {
701
0
  (void)bd;
702
0
  assert(dx > 0);
703
0
  assert(dy > 0);
704
705
0
  const int min_base_x = -1 - mrl_index;
706
0
  const int min_base_y = -1 - mrl_index;
707
708
0
  (void)min_base_y;
709
0
  const int frac_bits_x = 6;
710
0
  const int frac_bits_y = 6;
711
712
0
  uint16_t ref[4] = { 0 };
713
714
0
  for (int r = 0; r < bh; ++r) {
715
0
    for (int c = 0; c < bw; ++c) {
716
0
      int val;
717
0
      int y = r + 1;
718
0
      int x = (c << 6) - (y + mrl_index) * dx;
719
0
      const int base_x = x >> frac_bits_x;
720
0
      if (base_x >= min_base_x) {
721
0
        const int shift = (x & 0x3F) >> 1;
722
        // 4-tap filter
723
0
        ref[0] = above[base_x - 1];
724
0
        ref[1] = above[base_x];
725
0
        ref[2] = above[base_x + 1];
726
0
        ref[3] = above[base_x + 2];
727
728
0
        val = av2_dr_interp_filter[shift][0] * ref[0] +
729
0
              av2_dr_interp_filter[shift][1] * ref[1] +
730
0
              av2_dr_interp_filter[shift][2] * ref[2] +
731
0
              av2_dr_interp_filter[shift][3] * ref[3];
732
733
0
        val = clip_pixel_highbd(ROUND_POWER_OF_TWO(val, POWER_DR_INTERP_FILTER),
734
0
                                bd);
735
0
      } else {
736
0
        x = c + 1;
737
0
        y = (r << 6) - (x + mrl_index) * dy;
738
0
        const int base_y = y >> frac_bits_y;
739
0
        assert(base_y >= min_base_y);
740
0
        const int shift = (y & 0x3F) >> 1;
741
        // 4-tap filter
742
0
        ref[0] = left[base_y - 1];
743
0
        ref[1] = left[base_y];
744
0
        ref[2] = left[base_y + 1];
745
0
        ref[3] = left[base_y + 2];
746
747
0
        val = av2_dr_interp_filter[shift][0] * ref[0] +
748
0
              av2_dr_interp_filter[shift][1] * ref[1] +
749
0
              av2_dr_interp_filter[shift][2] * ref[2] +
750
0
              av2_dr_interp_filter[shift][3] * ref[3];
751
752
0
        val = clip_pixel_highbd(ROUND_POWER_OF_TWO(val, POWER_DR_INTERP_FILTER),
753
0
                                bd);
754
0
      }
755
0
      dst[c] = val;
756
0
    }
757
0
    dst += stride;
758
0
  }
759
0
}
760
761
// Directional prediction, zone 3: 180 < angle < 270 using IDIF
762
void av2_highbd_dr_prediction_z3_idif_c(uint16_t *dst, ptrdiff_t stride, int bw,
763
                                        int bh, const uint16_t *above,
764
                                        const uint16_t *left, int dx, int dy,
765
0
                                        int bd, int mrl_index) {
766
0
  int r, c, y, base, shift, val;
767
768
0
  (void)above;
769
0
  (void)dx;
770
0
  (void)bd;
771
0
  assert(dx == 1);
772
0
  assert(dy > 0);
773
774
0
  uint16_t ref[4] = { 0 };
775
776
0
  const int max_base_y = (bw + bh) - 1 + (mrl_index << 1);
777
0
  const int frac_bits = 6;
778
0
  const int base_inc = 1;
779
780
0
  y = dy * (1 + mrl_index);
781
0
  for (c = 0; c < bw; ++c, y += dy) {
782
0
    base = y >> frac_bits;
783
0
    shift = (y & 0x3F) >> 1;
784
785
0
    for (r = 0; r < bh; ++r, base += base_inc) {
786
0
      if (base <= max_base_y) {
787
        // 4-tap filter
788
0
        ref[0] = left[base - 1];
789
0
        ref[1] = left[base];
790
0
        ref[2] = left[base + 1];
791
0
        ref[3] = left[base + 2];
792
793
0
        val = av2_dr_interp_filter[shift][0] * ref[0] +
794
0
              av2_dr_interp_filter[shift][1] * ref[1] +
795
0
              av2_dr_interp_filter[shift][2] * ref[2] +
796
0
              av2_dr_interp_filter[shift][3] * ref[3];
797
798
0
        dst[r * stride + c] = clip_pixel_highbd(
799
0
            ROUND_POWER_OF_TWO(val, POWER_DR_INTERP_FILTER), bd);
800
0
      } else {
801
0
        for (; r < bh; ++r) dst[r * stride + c] = left[max_base_y];
802
0
        break;
803
0
      }
804
0
    }
805
0
  }
806
0
}
807
808
static void highbd_dr_predictor_idif(uint16_t *dst, ptrdiff_t stride,
809
                                     TX_SIZE tx_size, uint16_t *above,
810
                                     uint16_t *left, int angle, int bd,
811
1.21M
                                     int mrl_index) {
812
1.21M
  const int dx = av2_get_dx(angle);
813
1.21M
  const int dy = av2_get_dy(angle);
814
1.21M
  const int bw = tx_size_wide[tx_size];
815
1.21M
  const int bh = tx_size_high[tx_size];
816
1.21M
  assert(angle > 0 && angle < 270);
817
818
1.21M
  const int max_base_z1_z3 = (bw + bh) - 1 + (mrl_index << 1);
819
1.21M
  const int max_base_z2_above = bw - 1;
820
1.21M
  const int max_base_z2_left = bh - 1;
821
1.21M
  const int min_base_z2 = -(1 + mrl_index);
822
823
1.21M
  if (angle > 0 && angle < 90) {
824
146k
    above[max_base_z1_z3 + 1] = above[max_base_z1_z3];
825
146k
    above[max_base_z1_z3 + 2] = above[max_base_z1_z3];
826
146k
    av2_highbd_dr_prediction_z1_idif(dst, stride, bw, bh, above, left, dx, dy,
827
146k
                                     bd, mrl_index);
828
829
1.06M
  } else if (angle > 90 && angle < 180) {
830
196k
    above[min_base_z2 - 1] = above[min_base_z2];
831
196k
    left[min_base_z2 - 1] = left[min_base_z2];
832
196k
    if (mrl_index == 0) {
833
187k
      above[max_base_z2_above + 1] = above[max_base_z2_above];
834
187k
      left[max_base_z2_left + 1] = left[max_base_z2_left];
835
187k
    }
836
196k
    av2_highbd_dr_prediction_z2_idif(dst, stride, bw, bh, above, left, dx, dy,
837
196k
                                     bd, mrl_index);
838
839
868k
  } else if (angle > 180 && angle < 270) {
840
71.9k
    left[max_base_z1_z3 + 1] = left[max_base_z1_z3];
841
71.9k
    left[max_base_z1_z3 + 2] = left[max_base_z1_z3];
842
71.9k
    av2_highbd_dr_prediction_z3_idif(dst, stride, bw, bh, above, left, dx, dy,
843
71.9k
                                     bd, mrl_index);
844
845
796k
  } else if (angle == 90) {
846
569k
    pred_high[V_PRED][tx_size](dst, stride, above, left, bd);
847
569k
  } else if (angle == 180) {
848
226k
    pred_high[H_PRED][tx_size](dst, stride, above, left, bd);
849
226k
  }
850
1.21M
}
851
852
static void highbd_dr_predictor(uint16_t *dst, ptrdiff_t stride,
853
                                TX_SIZE tx_size, const uint16_t *above,
854
                                const uint16_t *left, int angle, int bd,
855
334k
                                int mrl_index) {
856
334k
  const int dx = av2_get_dx(angle);
857
334k
  const int dy = av2_get_dy(angle);
858
334k
  const int bw = tx_size_wide[tx_size];
859
334k
  const int bh = tx_size_high[tx_size];
860
334k
  assert(angle > 0 && angle < 270);
861
862
334k
  if (angle > 0 && angle < 90) {
863
61.0k
    av2_highbd_dr_prediction_z1(dst, stride, bw, bh, above, left, dx, dy, bd,
864
61.0k
                                mrl_index);
865
273k
  } else if (angle > 90 && angle < 180) {
866
53.3k
    av2_highbd_dr_prediction_z2(dst, stride, bw, bh, above, left, dx, dy, bd,
867
53.3k
                                mrl_index);
868
220k
  } else if (angle > 180 && angle < 270) {
869
29.4k
    av2_highbd_dr_prediction_z3(dst, stride, bw, bh, above, left, dx, dy, bd,
870
29.4k
                                mrl_index);
871
190k
  } else if (angle == 90) {
872
83.2k
    pred_high[V_PRED][tx_size](dst, stride, above, left, bd);
873
107k
  } else if (angle == 180) {
874
107k
    pred_high[H_PRED][tx_size](dst, stride, above, left, bd);
875
107k
  }
876
334k
}
877
878
// Generate the second directional predictor for IBP
879
static void highbd_second_dr_predictor(uint16_t *dst, ptrdiff_t stride,
880
                                       TX_SIZE tx_size, const uint16_t *above,
881
                                       const uint16_t *left, int angle,
882
0
                                       int bd) {
883
0
  const int bw = tx_size_wide[tx_size];
884
0
  const int bh = tx_size_high[tx_size];
885
886
0
  if (angle > 0 && angle < 90) {
887
0
    int dy = dr_intra_derivative[90 - angle];
888
0
    int dx = 1;
889
0
    av2_highbd_dr_prediction_z3(dst, stride, bw, bh, above, left, dx, dy, bd,
890
0
                                0);
891
0
  } else if (angle > 180 && angle < 270) {
892
0
    int dx = dr_intra_derivative[angle - 180];
893
0
    int dy = 1;
894
0
    av2_highbd_dr_prediction_z1(dst, stride, bw, bh, above, left, dx, dy, bd,
895
0
                                0);
896
0
  }
897
0
}
898
899
// Generate the second directional predictor for IBP
900
static void highbd_second_dr_predictor_idif(uint16_t *dst, ptrdiff_t stride,
901
                                            TX_SIZE tx_size, uint16_t *above,
902
75.4k
                                            uint16_t *left, int angle, int bd) {
903
75.4k
  const int bw = tx_size_wide[tx_size];
904
75.4k
  const int bh = tx_size_high[tx_size];
905
906
75.4k
  const int max_base = ((bw + bh) - 1);
907
908
75.4k
  if (angle > 0 && angle < 90) {
909
47.9k
    int dy = dr_intra_derivative[90 - angle];
910
47.9k
    int dx = 1;
911
47.9k
    left[max_base + 1] = left[max_base];
912
47.9k
    left[max_base + 2] = left[max_base];
913
47.9k
    av2_highbd_dr_prediction_z3_idif(dst, stride, bw, bh, above, left, dx, dy,
914
47.9k
                                     bd, 0);
915
47.9k
  } else if (angle > 180 && angle < 270) {
916
27.4k
    int dx = dr_intra_derivative[angle - 180];
917
27.4k
    int dy = 1;
918
27.4k
    above[max_base + 1] = above[max_base];
919
27.4k
    above[max_base + 2] = above[max_base];
920
27.4k
    av2_highbd_dr_prediction_z1_idif(dst, stride, bw, bh, above, left, dx, dy,
921
27.4k
                                     bd, 0);
922
27.4k
  }
923
75.4k
}
924
925
824k
static int is_smooth(const MB_MODE_INFO *mbmi, int plane, TREE_TYPE tree_type) {
926
824k
  (void)tree_type;
927
824k
  if (plane == 0) {
928
548k
    const PREDICTION_MODE mode = mbmi->mode;
929
548k
    return (mode == SMOOTH_PRED || mode == SMOOTH_V_PRED ||
930
488k
            mode == SMOOTH_H_PRED);
931
548k
  } else {
932
    // uv_mode is not set for inter blocks, so need to explicitly
933
    // detect that case.
934
275k
    if (is_inter_block(
935
275k
            mbmi, mbmi->tree_type == SHARED_PART ? SHARED_PART : CHROMA_PART))
936
1.87k
      return 0;
937
938
273k
    const UV_PREDICTION_MODE uv_mode = mbmi->uv_mode;
939
273k
    return (uv_mode == UV_SMOOTH_PRED || uv_mode == UV_SMOOTH_V_PRED ||
940
236k
            uv_mode == UV_SMOOTH_H_PRED);
941
275k
  }
942
824k
}
943
944
407k
static int get_filt_type(const MACROBLOCKD *xd, int plane) {
945
407k
  int ab_sm, le_sm;
946
947
407k
  if (plane == 0) {
948
264k
    const MB_MODE_INFO *ab = xd->above_mbmi;
949
264k
    const MB_MODE_INFO *le = xd->left_mbmi;
950
264k
    ab_sm = ab ? is_smooth(ab, plane, xd->tree_type) : 0;
951
264k
    le_sm = le ? is_smooth(le, plane, xd->tree_type) : 0;
952
264k
  } else {
953
142k
    const MB_MODE_INFO *ab = xd->chroma_above_mbmi;
954
142k
    const MB_MODE_INFO *le = xd->chroma_left_mbmi;
955
142k
    ab_sm = ab ? is_smooth(ab, plane, xd->tree_type) : 0;
956
142k
    le_sm = le ? is_smooth(le, plane, xd->tree_type) : 0;
957
142k
  }
958
959
407k
  return (ab_sm || le_sm) ? 1 : 0;
960
407k
}
961
962
292k
static int intra_edge_filter_strength(int bs0, int bs1, int delta, int type) {
963
292k
  const int d = abs(delta);
964
292k
  int strength = 0;
965
966
292k
  const int blk_wh = bs0 + bs1;
967
292k
  if (type == 0) {
968
237k
    if (blk_wh <= 8) {
969
65.2k
      if (d >= 56) strength = 1;
970
171k
    } else if (blk_wh <= 12) {
971
16.4k
      if (d >= 40) strength = 1;
972
155k
    } else if (blk_wh <= 16) {
973
16.7k
      if (d >= 40) strength = 1;
974
138k
    } else if (blk_wh <= 24) {
975
37.2k
      if (d >= 8) strength = 1;
976
37.2k
      if (d >= 16) strength = 2;
977
37.2k
      if (d >= 32) strength = 3;
978
101k
    } else if (blk_wh <= 32) {
979
20.7k
      if (d >= 1) strength = 1;
980
20.7k
      if (d >= 4) strength = 2;
981
20.7k
      if (d >= 32) strength = 3;
982
80.7k
    } else {
983
80.7k
      if (d >= 1) strength = 3;
984
80.7k
    }
985
237k
  } else {
986
55.7k
    if (blk_wh <= 8) {
987
7.74k
      if (d >= 40) strength = 1;
988
7.74k
      if (d >= 64) strength = 2;
989
48.0k
    } else if (blk_wh <= 16) {
990
12.0k
      if (d >= 20) strength = 1;
991
12.0k
      if (d >= 48) strength = 2;
992
35.9k
    } else if (blk_wh <= 24) {
993
10.2k
      if (d >= 4) strength = 3;
994
25.7k
    } else {
995
25.7k
      if (d >= 1) strength = 3;
996
25.7k
    }
997
55.7k
  }
998
292k
  return strength;
999
292k
}
1000
1001
0
void av2_filter_intra_edge_high_c(uint16_t *p, int sz, int strength) {
1002
0
  if (!strength) return;
1003
1004
0
  const int kernel[INTRA_EDGE_FILT][INTRA_EDGE_TAPS] = { { 0, 4, 8, 4, 0 },
1005
0
                                                         { 0, 5, 6, 5, 0 },
1006
0
                                                         { 2, 4, 4, 4, 2 } };
1007
0
  const int filt = strength - 1;
1008
0
  uint16_t edge[129];
1009
1010
0
  memcpy(edge, p, sz * sizeof(*p));
1011
0
  for (int i = 1; i < sz; i++) {
1012
0
    int s = 0;
1013
0
    for (int j = 0; j < INTRA_EDGE_TAPS; j++) {
1014
0
      int k = i - 2 + j;
1015
0
      k = (k < 0) ? 0 : k;
1016
0
      k = (k > sz - 1) ? sz - 1 : k;
1017
0
      s += edge[k] * kernel[filt][j];
1018
0
    }
1019
0
    s = (s + 8) >> 4;
1020
0
    p[i] = s;
1021
0
  }
1022
0
}
1023
1024
79.4k
static void filter_intra_edge_corner_high(uint16_t *p_above, uint16_t *p_left) {
1025
79.4k
  const int kernel[3] = { 5, 6, 5 };
1026
1027
79.4k
  int s = (p_left[0] * kernel[0]) + (p_above[-1] * kernel[1]) +
1028
79.4k
          (p_above[0] * kernel[2]);
1029
79.4k
  s = (s + 8) >> 4;
1030
79.4k
  p_above[-1] = s;
1031
79.4k
  p_left[-1] = s;
1032
79.4k
}
1033
1034
void av2_highbd_ibp_dr_prediction_z1_c(
1035
    const IbpWeightsType weights[][IBP_WEIGHT_SIZE][DIR_MODES_0_90],
1036
    int mode_idx, uint16_t *dst, ptrdiff_t stride, uint16_t *second_pred,
1037
48.1k
    ptrdiff_t second_stride, int bw, int bh) {
1038
48.1k
  const int col_shift = bw >> (IBP_WEIGHT_SIZE_LOG2 + 1);
1039
48.1k
  const int row_shift = bh >> (IBP_WEIGHT_SIZE_LOG2 + 1);
1040
48.1k
  int r, c;
1041
1.19M
  for (r = 0; r < bh; ++r) {
1042
1.14M
    const int row_idx = r >> row_shift;
1043
45.9M
    for (c = 0; c < bw; ++c) {
1044
44.7M
      const int col_idx = c >> col_shift;
1045
44.7M
      const uint8_t weight = weights[row_idx][col_idx][mode_idx];
1046
44.7M
      dst[c] = ROUND_POWER_OF_TWO(
1047
44.7M
          dst[c] * weight + second_pred[c] * (IBP_WEIGHT_MAX - weight),
1048
44.7M
          IBP_WEIGHT_SHIFT);
1049
44.7M
    }
1050
1.14M
    dst += stride;
1051
1.14M
    second_pred += second_stride;
1052
1.14M
  }
1053
48.1k
}
1054
1055
void av2_highbd_ibp_dr_prediction_z3_c(
1056
    const IbpWeightsType weights[][IBP_WEIGHT_SIZE][DIR_MODES_0_90],
1057
    int mode_idx, uint16_t *dst, ptrdiff_t stride, uint16_t *second_pred,
1058
27.5k
    ptrdiff_t second_stride, int bw, int bh) {
1059
27.5k
  const int col_shift = bw >> (IBP_WEIGHT_SIZE_LOG2 + 1);
1060
27.5k
  const int row_shift = bh >> (IBP_WEIGHT_SIZE_LOG2 + 1);
1061
27.5k
  int r, c;
1062
648k
  for (c = 0; c < bw; ++c) {
1063
621k
    const int col_idx = c >> col_shift;
1064
621k
    uint16_t *tmp_dst = dst + c;
1065
621k
    uint16_t *tmp_second = second_pred + c;
1066
24.6M
    for (r = 0; r < bh; ++r) {
1067
23.9M
      const int row_idx = r >> row_shift;
1068
23.9M
      const uint8_t weight = weights[col_idx][row_idx][mode_idx];
1069
23.9M
      tmp_dst[0] = ROUND_POWER_OF_TWO(
1070
23.9M
          tmp_dst[0] * weight + tmp_second[0] * (IBP_WEIGHT_MAX - weight),
1071
23.9M
          IBP_WEIGHT_SHIFT);
1072
23.9M
      tmp_dst += stride;
1073
23.9M
      tmp_second += second_stride;
1074
23.9M
    }
1075
621k
  }
1076
27.5k
}
1077
1078
void av2_build_intra_predictors_high(
1079
    const MACROBLOCKD *xd, const uint16_t *ref, int ref_stride, uint16_t *dst,
1080
    int dst_stride, PREDICTION_MODE mode, int p_angle, int angle_delta,
1081
    TX_SIZE tx_size, int disable_edge_filter, int n_top_px, int n_topright_px,
1082
    int n_left_px, int n_bottomleft_px, int plane, int is_sb_boundary,
1083
    const int seq_ibp_flag,
1084
    const IbpWeightsType ibp_weights[][IBP_WEIGHT_SIZE][DIR_MODES_0_90],
1085
22.2k
    uint8_t mrl_index) {
1086
22.2k
  MB_MODE_INFO *const mbmi = xd->mi[0];
1087
22.2k
  int i;
1088
22.2k
  DECLARE_ALIGNED(16, uint16_t, left_data_1st[NUM_INTRA_NEIGHBOUR_PIXELS]);
1089
22.2k
  DECLARE_ALIGNED(16, uint16_t, above_data_1st[NUM_INTRA_NEIGHBOUR_PIXELS]);
1090
22.2k
  DECLARE_ALIGNED(16, uint16_t, left_data_2nd[NUM_INTRA_NEIGHBOUR_PIXELS]);
1091
22.2k
  DECLARE_ALIGNED(16, uint16_t, above_data_2nd[NUM_INTRA_NEIGHBOUR_PIXELS]);
1092
22.2k
  DECLARE_ALIGNED(16, uint16_t, second_pred_data[MAX_TX_SQUARE + 32]);
1093
22.2k
  DECLARE_ALIGNED(16, uint16_t, mrl_line_0_data[MAX_TX_SQUARE + 32]);
1094
22.2k
  uint16_t *const above_row_1st = above_data_1st + 32;
1095
22.2k
  uint16_t *const left_col_1st = left_data_1st + 32;
1096
22.2k
  uint16_t *const above_row_2nd = above_data_2nd + 32;
1097
22.2k
  uint16_t *const left_col_2nd = left_data_2nd + 32;
1098
1099
22.2k
  uint16_t *const second_pred = second_pred_data + 16;
1100
22.2k
  uint16_t *dst_mrl_line_0 = mrl_line_0_data + 16;
1101
22.2k
  const int txwpx = tx_size_wide[tx_size];
1102
22.2k
  const int txhpx = tx_size_high[tx_size];
1103
22.2k
  int need_left = extend_modes[mode] & NEED_LEFT;
1104
22.2k
  int need_above = extend_modes[mode] & NEED_ABOVE;
1105
22.2k
  int need_above_left = extend_modes[mode] & NEED_ABOVELEFT;
1106
22.2k
  const int above_mrl_idx = is_sb_boundary ? 0 : mrl_index;
1107
22.2k
  const uint16_t *above_ref_1st = ref - ref_stride * (above_mrl_idx + 1);
1108
22.2k
  const uint16_t *left_ref_1st = ref - 1 - mrl_index;
1109
22.2k
  const uint16_t *above_ref_2nd = ref - ref_stride;
1110
22.2k
  const uint16_t *left_ref_2nd = ref - 1;
1111
1112
22.2k
  const int is_dr_mode = av2_is_directional_mode(mode);
1113
22.2k
  const int use_intra_dip = mbmi->use_intra_dip && plane == PLANE_TYPE_Y;
1114
22.2k
  int base = 128 << (xd->bd - 8);
1115
  // The second reference line is not always needed. Use |need_2nd_line| to
1116
  // guard whether memset is necessary.
1117
22.2k
  const int is_multi_line_mrls_allowed_blk_sz = (tx_size == TX_4X4) ? 0 : 1;
1118
22.2k
  const int need_2nd_line =
1119
22.2k
      mbmi->multi_line_mrl && mrl_index && is_multi_line_mrls_allowed_blk_sz;
1120
  // The left_data, above_data buffers must be zeroed to fix some intermittent
1121
  // valgrind errors. Uninitialized reads in intra pred modules (e.g. width =
1122
  // 4 path in av2_highbd_dr_prediction_z2_avx2()) from left_data, above_data
1123
  // are seen to be the potential reason for this issue.
1124
22.2k
  avm_memset16(left_data_1st, base + 1, NUM_INTRA_NEIGHBOUR_PIXELS);
1125
22.2k
  avm_memset16(above_data_1st, base - 1, NUM_INTRA_NEIGHBOUR_PIXELS);
1126
22.2k
  if (need_2nd_line) {
1127
3.55k
    avm_memset16(left_data_2nd, base + 1, NUM_INTRA_NEIGHBOUR_PIXELS);
1128
3.55k
    avm_memset16(above_data_2nd, base - 1, NUM_INTRA_NEIGHBOUR_PIXELS);
1129
3.55k
  }
1130
1131
  // The default values if ref pixels are not available:
1132
  // base   base-1 base-1 .. base-1 base-1 base-1 base-1 base-1 base-1
1133
  // base+1   A      B  ..     Y      Z
1134
  // base+1   C      D  ..     W      X
1135
  // base+1   E      F  ..     U      V
1136
  // base+1   G      H  ..     S      T      T      T      T      T
1137
1138
22.2k
  const bool is_ibp_allowed_blk_sz = tx_size != TX_4X4;
1139
22.2k
  const int apply_ibp = seq_ibp_flag && is_ibp_allowed_blk_sz;
1140
22.2k
  if (is_dr_mode) {
1141
22.1k
    if (p_angle < 90)
1142
8.01k
      need_above = 1, need_left = 0, need_above_left = 1;
1143
14.1k
    else if (p_angle == 90)
1144
180
      need_above = 1, need_left = 0, need_above_left = 0;
1145
13.9k
    else if (p_angle < 180)
1146
8.34k
      need_above = 1, need_left = 1, need_above_left = 1;
1147
5.59k
    else if (p_angle == 180)
1148
157
      need_above = 0, need_left = 1, need_above_left = 0;
1149
5.44k
    else
1150
5.44k
      need_above = 0, need_left = 1, need_above_left = 1;
1151
22.1k
    if (apply_ibp) {
1152
7.68k
      need_above = 1, need_left = 1, need_above_left = 1;
1153
7.68k
    }
1154
22.1k
  }
1155
22.2k
  if (use_intra_dip) need_left = need_above = need_above_left = 1;
1156
22.2k
  assert(n_top_px >= 0);
1157
22.2k
  assert(n_topright_px >= 0);
1158
22.2k
  assert(n_left_px >= 0);
1159
22.2k
  assert(n_bottomleft_px >= 0);
1160
1161
22.2k
  if (xd->mi[0]->multi_line_mrl == 0 &&
1162
12.6k
      ((!need_above && n_left_px == 0) || (!need_left && n_top_px == 0))) {
1163
100
    int val;
1164
100
    if (need_left) {
1165
24
      val = (n_top_px > 0) ? above_ref_1st[0] : base + 1;
1166
76
    } else {
1167
76
      val = (n_left_px > 0) ? left_ref_1st[0] : base - 1;
1168
76
    }
1169
4.80k
    for (i = 0; i < txhpx; ++i) {
1170
4.70k
      avm_memset16(dst, val, txwpx);
1171
4.70k
      dst += dst_stride;
1172
4.70k
    }
1173
100
    return;
1174
100
  }
1175
1176
  // NEED_LEFT
1177
22.1k
  if (need_left) {
1178
17.0k
    int need_bottom = extend_modes[mode] & NEED_BOTTOMLEFT;
1179
17.0k
    if (use_intra_dip) need_bottom = 1;
1180
17.0k
    if (is_dr_mode)
1181
17.0k
      need_bottom =
1182
17.0k
          apply_ibp ? (p_angle < 90) || (p_angle > 180) : p_angle > 180;
1183
17.0k
    int num_left_pixels_needed =
1184
17.0k
        txhpx + (need_bottom ? txwpx : 3) + (mrl_index << 1);
1185
17.0k
    if (use_intra_dip) {
1186
      // DIP mode requires left edge + 1/4 tx height for overhang feature.
1187
0
      num_left_pixels_needed = txhpx + (txhpx >> 2);
1188
0
    }
1189
17.0k
    i = 0;
1190
17.0k
    if (n_left_px > 0) {
1191
208k
      for (; i < n_left_px; i++) {
1192
193k
        left_col_1st[i] = left_ref_1st[i * ref_stride];
1193
193k
        if (need_2nd_line) left_col_2nd[i] = left_ref_2nd[i * ref_stride];
1194
193k
      }
1195
15.3k
      if (need_bottom && n_bottomleft_px > 0) {
1196
1.74k
        assert(i == txhpx);
1197
26.3k
        for (; i < txhpx + n_bottomleft_px; i++) {
1198
24.5k
          left_col_1st[i] = left_ref_1st[i * ref_stride];
1199
24.5k
          if (need_2nd_line) left_col_2nd[i] = left_ref_2nd[i * ref_stride];
1200
24.5k
        }
1201
1.74k
      }
1202
15.3k
      if (i < num_left_pixels_needed) {
1203
15.0k
        avm_memset16(&left_col_1st[i], left_col_1st[i - 1],
1204
15.0k
                     num_left_pixels_needed - i);
1205
15.0k
        if (need_2nd_line)
1206
2.72k
          avm_memset16(&left_col_2nd[i], left_col_2nd[i - 1],
1207
2.72k
                       num_left_pixels_needed - i);
1208
15.0k
      }
1209
15.3k
    } else if (n_top_px > 0) {
1210
1.68k
      avm_memset16(left_col_1st, above_ref_1st[0], num_left_pixels_needed);
1211
1.68k
      if (need_2nd_line)
1212
394
        avm_memset16(left_col_2nd, above_ref_2nd[0], num_left_pixels_needed);
1213
1.68k
    }
1214
17.0k
  }
1215
1216
  // NEED_ABOVE
1217
22.1k
  if (need_above) {
1218
18.3k
    int need_right = extend_modes[mode] & NEED_ABOVERIGHT;
1219
18.3k
    if (use_intra_dip) need_right = 1;
1220
18.3k
    if (is_dr_mode)
1221
18.3k
      need_right = apply_ibp ? (p_angle < 90) || (p_angle > 180) : p_angle < 90;
1222
18.3k
    int num_top_pixels_needed =
1223
18.3k
        txwpx + (need_right ? txhpx : 0) + (mrl_index << 1);
1224
18.3k
    if (use_intra_dip) {
1225
      // DIP mode requires above line + 1/4 tx width for overhang feature.
1226
0
      num_top_pixels_needed = txwpx + (txwpx >> 2);
1227
0
    }
1228
18.3k
    if (n_top_px > 0) {
1229
18.0k
      memcpy(above_row_1st, above_ref_1st, n_top_px * sizeof(above_ref_1st[0]));
1230
18.0k
      if (need_2nd_line)
1231
3.25k
        memcpy(above_row_2nd, above_ref_2nd,
1232
3.25k
               n_top_px * sizeof(above_ref_2nd[0]));
1233
18.0k
      i = n_top_px;
1234
18.0k
      if (need_right && n_topright_px > 0) {
1235
5.98k
        assert(n_top_px == txwpx);
1236
5.98k
        memcpy(above_row_1st + txwpx, above_ref_1st + txwpx,
1237
5.98k
               n_topright_px * sizeof(above_ref_1st[0]));
1238
5.98k
        if (need_2nd_line)
1239
680
          memcpy(above_row_2nd + txwpx, above_ref_2nd + txwpx,
1240
680
                 n_topright_px * sizeof(above_ref_2nd[0]));
1241
5.98k
        i += n_topright_px;
1242
5.98k
      }
1243
18.0k
      if (i < num_top_pixels_needed) {
1244
17.6k
        avm_memset16(&above_row_1st[i], above_row_1st[i - 1],
1245
17.6k
                     num_top_pixels_needed - i);
1246
17.6k
        if (need_2nd_line)
1247
3.08k
          avm_memset16(&above_row_2nd[i], above_row_2nd[i - 1],
1248
3.08k
                       num_top_pixels_needed - i);
1249
17.6k
      }
1250
18.0k
    } else if (n_left_px > 0) {
1251
314
      avm_memset16(above_row_1st, left_ref_1st[0], num_top_pixels_needed);
1252
314
      if (need_2nd_line)
1253
61
        avm_memset16(above_row_2nd, left_ref_2nd[0], num_top_pixels_needed);
1254
314
    }
1255
18.3k
  }
1256
1257
22.1k
  if (need_above_left) {
1258
80.8k
    for (i = 1; i <= mrl_index + 1; i++) {
1259
58.9k
      if (n_top_px > 0 && n_left_px > 0) {
1260
52.9k
        above_row_1st[-i] = above_ref_1st[-i];
1261
52.9k
        if (need_2nd_line) above_row_2nd[-i] = above_ref_2nd[-i];
1262
52.9k
        if (is_sb_boundary) {
1263
4.96k
          left_col_1st[-i] = left_ref_1st[-ref_stride];
1264
4.96k
          if (need_2nd_line) left_col_2nd[-i] = left_ref_2nd[-ref_stride];
1265
47.9k
        } else {
1266
47.9k
          left_col_1st[-i] = left_ref_1st[-i * ref_stride];
1267
47.9k
          if (need_2nd_line) left_col_2nd[-i] = left_ref_2nd[-i * ref_stride];
1268
47.9k
        }
1269
52.9k
      } else if (n_top_px > 0) {
1270
5.15k
        above_row_1st[-i] = left_col_1st[-i] = above_ref_1st[0];
1271
5.15k
        if (need_2nd_line)
1272
1.02k
          above_row_2nd[-i] = left_col_2nd[-i] = above_ref_2nd[0];
1273
5.15k
      } else if (n_left_px > 0) {
1274
876
        above_row_1st[-i] = left_col_1st[-i] = left_ref_1st[0];
1275
876
        if (need_2nd_line)
1276
186
          above_row_2nd[-i] = left_col_2nd[-i] = left_ref_2nd[0];
1277
18.4E
      } else {
1278
18.4E
        above_row_1st[-i] = left_col_1st[-i] = base;
1279
18.4E
        if (need_2nd_line) above_row_2nd[-i] = left_col_2nd[-i] = base;
1280
18.4E
      }
1281
58.9k
    }
1282
21.8k
  }
1283
1284
22.1k
  if (use_intra_dip) {
1285
0
    av2_highbd_intra_dip_predictor(mbmi->intra_dip_mode, dst, dst_stride,
1286
0
                                   above_row_1st, left_col_1st, tx_size, xd->bd
1287
0
#if CONFIG_DIP_EXT_PRUNING
1288
0
                                   ,
1289
0
                                   mbmi->intra_dip_features
1290
0
#endif  // CONFIG_DIP_EXT_PRUNING
1291
0
    );
1292
0
    return;
1293
0
  }
1294
1295
22.1k
  if (is_dr_mode) {
1296
22.0k
    if (!disable_edge_filter && mrl_index == 0) {
1297
0
      int need_right = p_angle < 90;
1298
0
      int need_bottom = p_angle > 180;
1299
0
      int filt_type_above = get_filt_type(xd, plane);
1300
0
      int filt_type_left = filt_type_above;
1301
0
      int angle_above = p_angle - 90;
1302
0
      int angle_left = p_angle - 180;
1303
0
      if (apply_ibp) {
1304
0
        need_right |= p_angle > 180;
1305
0
        need_bottom |= p_angle < 90;
1306
0
        const MB_MODE_INFO *ab =
1307
0
            (plane == 0) ? xd->above_mbmi : xd->chroma_above_mbmi;
1308
0
        const MB_MODE_INFO *le =
1309
0
            (plane == 0) ? xd->left_mbmi : xd->chroma_left_mbmi;
1310
0
        filt_type_above = ab ? is_smooth(ab, plane, xd->tree_type) : 0;
1311
0
        filt_type_left = le ? is_smooth(le, plane, xd->tree_type) : 0;
1312
0
        angle_above = p_angle > 180 ? (p_angle - 180 - 90) : angle_above;
1313
0
        angle_left = p_angle < 90 ? p_angle : angle_left;
1314
0
      }
1315
1316
0
      if (p_angle != 90 && p_angle != 180) {
1317
0
        const int ab_le = need_above_left ? 1 : 0;
1318
0
        if (need_above && need_left && (txwpx + txhpx >= 24)) {
1319
0
          filter_intra_edge_corner_high(above_row_1st, left_col_1st);
1320
0
        }
1321
0
        if (need_above && n_top_px > 0) {
1322
0
          const int strength = intra_edge_filter_strength(
1323
0
              txwpx, txhpx, angle_above, filt_type_above);
1324
0
          const int n_px = n_top_px + ab_le + (need_right ? txhpx : 0);
1325
0
          av2_filter_intra_edge_high(above_row_1st - ab_le, n_px, strength);
1326
0
        }
1327
0
        if (need_left && n_left_px > 0) {
1328
0
          const int strength = intra_edge_filter_strength(
1329
0
              txhpx, txwpx, angle_left, filt_type_left);
1330
0
          const int n_px = n_left_px + ab_le + (need_bottom ? txwpx : 0);
1331
0
          av2_filter_intra_edge_high(left_col_1st - ab_le, n_px, strength);
1332
0
        }
1333
0
      }
1334
0
    }
1335
22.0k
    if (plane == AVM_PLANE_Y) {
1336
22.0k
      highbd_dr_predictor_idif(dst, dst_stride, tx_size, above_row_1st,
1337
22.0k
                               left_col_1st, p_angle, xd->bd, mrl_index);
1338
1339
22.0k
      if (need_2nd_line) {
1340
3.54k
        highbd_dr_predictor_idif(dst_mrl_line_0, txwpx, tx_size, above_row_2nd,
1341
3.54k
                                 left_col_2nd, p_angle, xd->bd, 0);
1342
1343
3.54k
        int r, c;
1344
77.8k
        for (r = 0; r < txhpx; ++r) {
1345
2.23M
          for (c = 0; c < txwpx; ++c) {
1346
2.16M
            dst[r * dst_stride + c] =
1347
2.16M
                (dst[r * dst_stride + c] + dst_mrl_line_0[r * txwpx + c] + 1) /
1348
2.16M
                2;
1349
2.16M
          }
1350
74.3k
        }
1351
3.54k
      }
1352
18.4E
    } else {
1353
18.4E
      highbd_dr_predictor(dst, dst_stride, tx_size, above_row_1st, left_col_1st,
1354
18.4E
                          p_angle, xd->bd, mrl_index);
1355
18.4E
      if (need_2nd_line) {
1356
0
        highbd_dr_predictor(dst_mrl_line_0, txwpx, tx_size, above_row_2nd,
1357
0
                            left_col_2nd, p_angle, xd->bd, 0);
1358
1359
0
        int r, c;
1360
0
        for (r = 0; r < txhpx; ++r) {
1361
0
          for (c = 0; c < txwpx; ++c) {
1362
0
            dst[r * dst_stride + c] =
1363
0
                (dst[r * dst_stride + c] + dst_mrl_line_0[r * txwpx + c] + 1) /
1364
0
                2;
1365
0
          }
1366
0
        }
1367
0
      }
1368
18.4E
    }
1369
22.0k
    if (apply_ibp) {
1370
7.67k
      if (mrl_index == 0 && (angle_delta % 2 == 0) && plane == PLANE_TYPE_Y) {
1371
0
        if (p_angle > 0 && p_angle < 90) {
1372
0
          int mode_index = angle_to_mode_index[p_angle];
1373
0
          if (is_ibp_enabled[mode_index]) {
1374
0
            if (plane == AVM_PLANE_Y) {
1375
0
              highbd_second_dr_predictor_idif(second_pred, txwpx, tx_size,
1376
0
                                              above_row_1st, left_col_1st,
1377
0
                                              p_angle, xd->bd);
1378
0
            } else {
1379
0
              highbd_second_dr_predictor(second_pred, txwpx, tx_size,
1380
0
                                         above_row_1st, left_col_1st, p_angle,
1381
0
                                         xd->bd);
1382
0
            }
1383
0
            av2_highbd_ibp_dr_prediction_z1_c(ibp_weights, mode_index, dst,
1384
0
                                              dst_stride, second_pred, txwpx,
1385
0
                                              txwpx, txhpx);
1386
0
          }
1387
0
        }
1388
0
        if (p_angle > 180 && p_angle < 270) {
1389
0
          int mode_index = angle_to_mode_index[270 - p_angle];
1390
0
          if (is_ibp_enabled[mode_index]) {
1391
0
            if (plane == AVM_PLANE_Y) {
1392
0
              highbd_second_dr_predictor_idif(second_pred, txwpx, tx_size,
1393
0
                                              above_row_1st, left_col_1st,
1394
0
                                              p_angle, xd->bd);
1395
0
            } else {
1396
0
              highbd_second_dr_predictor(second_pred, txwpx, tx_size,
1397
0
                                         above_row_1st, left_col_1st, p_angle,
1398
0
                                         xd->bd);
1399
0
            }
1400
0
            av2_highbd_ibp_dr_prediction_z3_c(ibp_weights, mode_index, dst,
1401
0
                                              dst_stride, second_pred, txwpx,
1402
0
                                              txwpx, txhpx);
1403
0
          }
1404
0
        }
1405
0
      }
1406
7.67k
    }
1407
1408
22.0k
    return;
1409
22.0k
  }
1410
  // predict
1411
63
  if (mode == DC_PRED) {
1412
0
    if (plane != AVM_PLANE_Y && mbmi->uv_mode == UV_CFL_PRED &&
1413
0
        (txwpx > 32 || txhpx > 32)) {
1414
0
      highbd_dc_predictor_subsampled(dst, dst_stride, n_top_px > 0,
1415
0
                                     n_left_px > 0, txwpx, txhpx, above_row_1st,
1416
0
                                     left_col_1st, xd->bd);
1417
0
    } else
1418
0
      dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
1419
0
          dst, dst_stride, above_row_1st, left_col_1st, xd->bd);
1420
0
    if (apply_ibp && ((plane == 0) || (xd->mi[0]->uv_mode != UV_CFL_PRED)) &&
1421
0
        ((n_left_px > 0) || (n_top_px > 0))) {
1422
0
      ibp_dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
1423
0
          dst, dst_stride, above_row_1st, left_col_1st, xd->bd);
1424
0
    }
1425
63
  } else {
1426
63
    pred_high[mode][tx_size](dst, dst_stride, above_row_1st, left_col_1st,
1427
63
                             xd->bd);
1428
63
  }
1429
63
}
1430
1431
// This function avoided the below operations in the original
1432
// function av2_build_intra_predictors_high().
1433
// - Avoided redundant calls to has_top_right() and has_bottom_left()
1434
//   when top-right and bottom-left pixels are not required.
1435
// - Removed the second reference line sample preparation for left and
1436
//   above neighbors and relevant buffers
1437
void av2_build_intra_predictors_high_default(
1438
    const MACROBLOCKD *xd, const uint16_t *ref, int ref_stride, uint16_t *dst,
1439
    int dst_stride, PREDICTION_MODE mode, int p_angle, int angle_delta,
1440
    TX_SIZE tx_size, int disable_edge_filter, int n_top_px, int n_topright_px,
1441
    int n_left_px, int n_bottomleft_px, int plane, int apply_ibp,
1442
    const IbpWeightsType ibp_weights[][IBP_WEIGHT_SIZE][DIR_MODES_0_90],
1443
4.25M
    uint8_t mrl_index) {
1444
4.25M
  (void)mrl_index;
1445
4.25M
  MB_MODE_INFO *const mbmi = xd->mi[0];
1446
4.25M
  int i;
1447
4.25M
  DECLARE_ALIGNED(16, uint16_t, left_data_1st[NUM_INTRA_NEIGHBOUR_PIXELS]);
1448
4.25M
  DECLARE_ALIGNED(16, uint16_t, above_data_1st[NUM_INTRA_NEIGHBOUR_PIXELS]);
1449
4.25M
  DECLARE_ALIGNED(16, uint16_t, second_pred_data[MAX_TX_SQUARE + 32]);
1450
4.25M
  uint16_t *const above_row_1st = above_data_1st + 32;
1451
4.25M
  uint16_t *const left_col_1st = left_data_1st + 32;
1452
4.25M
  uint16_t *const second_pred = second_pred_data + 16;
1453
1454
4.25M
  const int txwpx = tx_size_wide[tx_size];
1455
4.25M
  const int txhpx = tx_size_high[tx_size];
1456
4.25M
  const uint16_t *above_ref_1st = ref - ref_stride;
1457
4.25M
  const uint16_t *left_ref_1st = ref - 1;
1458
1459
4.25M
  const int is_dr_mode = av2_is_directional_mode(mode);
1460
4.25M
  const int use_intra_dip = mbmi->use_intra_dip && plane == PLANE_TYPE_Y;
1461
4.25M
  int base = 128 << (xd->bd - 8);
1462
4.25M
  assert(!mrl_index);
1463
1464
  // The default values if ref pixels are not available:
1465
  // base   base-1 base-1 .. base-1 base-1 base-1 base-1 base-1 base-1
1466
  // base+1   A      B  ..     Y      Z
1467
  // base+1   C      D  ..     W      X
1468
  // base+1   E      F  ..     U      V
1469
  // base+1   G      H  ..     S      T      T      T      T      T
1470
1471
4.25M
  int need_left = extend_modes[mode] & NEED_LEFT;
1472
4.25M
  int need_above = extend_modes[mode] & NEED_ABOVE;
1473
4.25M
  int need_above_left = extend_modes[mode] & NEED_ABOVELEFT;
1474
1475
4.25M
  if (is_dr_mode) {
1476
1.58M
    if (p_angle < 90)
1477
200k
      need_above = 1, need_left = 0, need_above_left = 1;
1478
1.38M
    else if (p_angle == 90)
1479
688k
      need_above = 1, need_left = 0, need_above_left = 0;
1480
695k
    else if (p_angle < 180)
1481
239k
      need_above = 1, need_left = 1, need_above_left = 1;
1482
455k
    else if (p_angle == 180)
1483
358k
      need_above = 0, need_left = 1, need_above_left = 0;
1484
97.2k
    else
1485
97.2k
      need_above = 0, need_left = 1, need_above_left = 1;
1486
1.58M
    if (apply_ibp) {
1487
308k
      need_above = need_left = need_above_left = 1;
1488
308k
    }
1489
1.58M
  }
1490
1491
4.25M
  if (use_intra_dip) need_left = need_above = need_above_left = 1;
1492
1493
4.25M
  assert(n_top_px >= 0);
1494
4.25M
  assert(n_topright_px >= -1);
1495
4.25M
  assert(n_left_px >= 0);
1496
4.25M
  assert(n_bottomleft_px >= -1);
1497
1498
4.25M
  if (mbmi->multi_line_mrl == 0 &&
1499
4.24M
      ((!need_above && n_left_px == 0) || (!need_left && n_top_px == 0))) {
1500
64.2k
    int val;
1501
64.2k
    if (need_left) {
1502
26.2k
      val = (n_top_px > 0) ? above_ref_1st[0] : base + 1;
1503
37.9k
    } else {
1504
37.9k
      val = (n_left_px > 0) ? left_ref_1st[0] : base - 1;
1505
37.9k
    }
1506
538k
    for (i = 0; i < txhpx; ++i) {
1507
473k
      avm_memset16(dst, val, txwpx);
1508
473k
      dst += dst_stride;
1509
473k
    }
1510
64.2k
    return;
1511
64.2k
  }
1512
1513
  // NEED_LEFT
1514
4.18M
  if (need_left) {
1515
3.46M
    int num_left_pixels_needed = txhpx + (n_bottomleft_px >= 0 ? txwpx : 3);
1516
3.46M
    if (use_intra_dip) {
1517
      // DIP mode requires left edge + 1/4 tx height for overhang feature.
1518
42.9k
      num_left_pixels_needed = txhpx + (txhpx >> 2);
1519
42.9k
    }
1520
3.46M
    i = 0;
1521
3.46M
    if (n_left_px > 0) {
1522
37.7M
      for (; i < n_left_px; i++) {
1523
34.7M
        left_col_1st[i] = left_ref_1st[i * ref_stride];
1524
34.7M
      }
1525
2.97M
      if (n_bottomleft_px > 0) {
1526
145k
        assert(i == txhpx);
1527
2.13M
        for (; i < txhpx + n_bottomleft_px; i++) {
1528
1.98M
          left_col_1st[i] = left_ref_1st[i * ref_stride];
1529
1.98M
        }
1530
145k
      }
1531
2.97M
      if (i < num_left_pixels_needed) {
1532
2.89M
        avm_memset16(&left_col_1st[i], left_col_1st[i - 1],
1533
2.89M
                     num_left_pixels_needed - i);
1534
2.89M
      }
1535
2.97M
    } else if (n_top_px > 0) {
1536
425k
      avm_memset16(left_col_1st, above_ref_1st[0], num_left_pixels_needed);
1537
425k
    } else {
1538
56.9k
      avm_memset16(left_col_1st, base + 1, num_left_pixels_needed);
1539
56.9k
    }
1540
3.46M
  }
1541
1542
  // NEED_ABOVE
1543
4.18M
  if (need_above) {
1544
3.85M
    int num_top_pixels_needed = txwpx + (n_topright_px >= 0 ? txhpx : 0);
1545
3.85M
    if (use_intra_dip) {
1546
      // DIP mode requires above line + 1/4 tx width for overhang feature.
1547
42.9k
      num_top_pixels_needed = txwpx + (txwpx >> 2);
1548
42.9k
    }
1549
3.85M
    if (n_top_px > 0) {
1550
3.69M
      memcpy(above_row_1st, above_ref_1st, n_top_px * sizeof(above_ref_1st[0]));
1551
3.69M
      i = n_top_px;
1552
3.69M
      if (n_topright_px > 0) {
1553
339k
        assert(n_top_px == txwpx);
1554
339k
        memcpy(above_row_1st + txwpx, above_ref_1st + txwpx,
1555
339k
               n_topright_px * sizeof(above_ref_1st[0]));
1556
339k
        i += n_topright_px;
1557
339k
      }
1558
3.69M
      if (i < num_top_pixels_needed) {
1559
497k
        avm_memset16(&above_row_1st[i], above_row_1st[i - 1],
1560
497k
                     num_top_pixels_needed - i);
1561
497k
      }
1562
3.69M
    } else if (n_left_px > 0) {
1563
102k
      avm_memset16(above_row_1st, left_ref_1st[0], num_top_pixels_needed);
1564
102k
    } else {
1565
57.8k
      avm_memset16(above_row_1st, base - 1, num_top_pixels_needed);
1566
57.8k
    }
1567
3.85M
  }
1568
1569
4.18M
  if (need_above_left) {
1570
3.08M
    if (n_top_px > 0 && n_left_px > 0) {
1571
2.52M
      above_row_1st[-1] = above_ref_1st[-1];
1572
2.52M
      left_col_1st[-1] = left_ref_1st[-ref_stride];
1573
2.52M
    } else if (n_top_px > 0) {
1574
419k
      above_row_1st[-1] = left_col_1st[-1] = above_ref_1st[0];
1575
419k
    } else if (n_left_px > 0) {
1576
90.2k
      above_row_1st[-1] = left_col_1st[-1] = left_ref_1st[0];
1577
90.2k
    } else {
1578
49.5k
      above_row_1st[-1] = left_col_1st[-1] = base;
1579
49.5k
    }
1580
3.08M
  }
1581
1582
4.18M
  if (use_intra_dip) {
1583
42.9k
    av2_highbd_intra_dip_predictor(mbmi->intra_dip_mode, dst, dst_stride,
1584
42.9k
                                   above_row_1st, left_col_1st, tx_size, xd->bd
1585
42.9k
#if CONFIG_DIP_EXT_PRUNING
1586
42.9k
                                   ,
1587
42.9k
                                   mbmi->intra_dip_features
1588
42.9k
#endif  // CONFIG_DIP_EXT_PRUNING
1589
42.9k
    );
1590
42.9k
    return;
1591
42.9k
  }
1592
1593
4.14M
  if (is_dr_mode) {
1594
1.52M
    if (!disable_edge_filter) {
1595
407k
      int need_right = p_angle < 90;
1596
407k
      int need_bottom = p_angle > 180;
1597
407k
      int filt_type_above = get_filt_type(xd, plane);
1598
407k
      int filt_type_left = filt_type_above;
1599
407k
      int angle_above = p_angle - 90;
1600
407k
      int angle_left = p_angle - 180;
1601
407k
      if (apply_ibp) {
1602
105k
        need_right |= p_angle > 180;
1603
105k
        need_bottom |= p_angle < 90;
1604
105k
        const MB_MODE_INFO *ab =
1605
105k
            (plane == 0) ? xd->above_mbmi : xd->chroma_above_mbmi;
1606
105k
        const MB_MODE_INFO *le =
1607
105k
            (plane == 0) ? xd->left_mbmi : xd->chroma_left_mbmi;
1608
105k
        filt_type_above = ab ? is_smooth(ab, plane, xd->tree_type) : 0;
1609
105k
        filt_type_left = le ? is_smooth(le, plane, xd->tree_type) : 0;
1610
105k
        angle_above = p_angle > 180 ? (p_angle - 180 - 90) : angle_above;
1611
105k
        angle_left = p_angle < 90 ? p_angle : angle_left;
1612
105k
      }
1613
1614
407k
      if (p_angle != 90 && p_angle != 180) {
1615
176k
        const int ab_le = need_above_left ? 1 : 0;
1616
176k
        if (need_above && need_left && (txwpx + txhpx >= 24)) {
1617
79.4k
          filter_intra_edge_corner_high(above_row_1st, left_col_1st);
1618
79.4k
        }
1619
176k
        if (need_above && n_top_px > 0) {
1620
155k
          const int strength = intra_edge_filter_strength(
1621
155k
              txwpx, txhpx, angle_above, filt_type_above);
1622
155k
          const int n_px = n_top_px + ab_le + (need_right ? txhpx : 0);
1623
155k
          av2_filter_intra_edge_high(above_row_1st - ab_le, n_px, strength);
1624
155k
        }
1625
176k
        if (need_left && n_left_px > 0) {
1626
137k
          const int strength = intra_edge_filter_strength(
1627
137k
              txhpx, txwpx, angle_left, filt_type_left);
1628
137k
          const int n_px = n_left_px + ab_le + (need_bottom ? txwpx : 0);
1629
137k
          av2_filter_intra_edge_high(left_col_1st - ab_le, n_px, strength);
1630
137k
        }
1631
176k
      }
1632
407k
    }
1633
1.52M
    if (plane == AVM_PLANE_Y) {
1634
1.18M
      highbd_dr_predictor_idif(dst, dst_stride, tx_size, above_row_1st,
1635
1.18M
                               left_col_1st, p_angle, xd->bd,
1636
1.18M
                               0 /* mrl_index */);
1637
1.18M
    } else {
1638
334k
      highbd_dr_predictor(dst, dst_stride, tx_size, above_row_1st, left_col_1st,
1639
334k
                          p_angle, xd->bd, 0 /* mrl_index */);
1640
334k
    }
1641
1.52M
    if (apply_ibp && (angle_delta % 2 == 0) && plane == PLANE_TYPE_Y) {
1642
139k
      if (p_angle > 0 && p_angle < 90) {
1643
47.9k
        int mode_index = angle_to_mode_index[p_angle];
1644
47.9k
        if (is_ibp_enabled[mode_index]) {
1645
47.9k
          if (plane == AVM_PLANE_Y) {
1646
47.9k
            highbd_second_dr_predictor_idif(second_pred, txwpx, tx_size,
1647
47.9k
                                            above_row_1st, left_col_1st,
1648
47.9k
                                            p_angle, xd->bd);
1649
47.9k
          } else {
1650
0
            highbd_second_dr_predictor(second_pred, txwpx, tx_size,
1651
0
                                       above_row_1st, left_col_1st, p_angle,
1652
0
                                       xd->bd);
1653
0
          }
1654
47.9k
          av2_highbd_ibp_dr_prediction_z1_c(ibp_weights, mode_index, dst,
1655
47.9k
                                            dst_stride, second_pred, txwpx,
1656
47.9k
                                            txwpx, txhpx);
1657
47.9k
        }
1658
47.9k
      }
1659
139k
      if (p_angle > 180 && p_angle < 270) {
1660
27.4k
        int mode_index = angle_to_mode_index[270 - p_angle];
1661
27.4k
        if (is_ibp_enabled[mode_index]) {
1662
27.4k
          if (plane == AVM_PLANE_Y) {
1663
27.4k
            highbd_second_dr_predictor_idif(second_pred, txwpx, tx_size,
1664
27.4k
                                            above_row_1st, left_col_1st,
1665
27.4k
                                            p_angle, xd->bd);
1666
27.4k
          } else {
1667
0
            highbd_second_dr_predictor(second_pred, txwpx, tx_size,
1668
0
                                       above_row_1st, left_col_1st, p_angle,
1669
0
                                       xd->bd);
1670
0
          }
1671
27.4k
          av2_highbd_ibp_dr_prediction_z3_c(ibp_weights, mode_index, dst,
1672
27.4k
                                            dst_stride, second_pred, txwpx,
1673
27.4k
                                            txwpx, txhpx);
1674
27.4k
        }
1675
27.4k
      }
1676
139k
    }
1677
1678
1.52M
    return;
1679
1.52M
  }
1680
  // predict
1681
2.62M
  if (mode == DC_PRED) {
1682
2.08M
    if (plane != AVM_PLANE_Y && mbmi->uv_mode == UV_CFL_PRED &&
1683
484k
        (txwpx > 32 || txhpx > 32)) {
1684
81.0k
      highbd_dc_predictor_subsampled(dst, dst_stride, n_top_px > 0,
1685
81.0k
                                     n_left_px > 0, txwpx, txhpx, above_row_1st,
1686
81.0k
                                     left_col_1st, xd->bd);
1687
81.0k
    } else
1688
2.00M
      dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
1689
2.00M
          dst, dst_stride, above_row_1st, left_col_1st, xd->bd);
1690
2.08M
    if (apply_ibp && ((plane == 0) || (mbmi->uv_mode != UV_CFL_PRED)) &&
1691
239k
        ((n_left_px > 0) || (n_top_px > 0))) {
1692
222k
      ibp_dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
1693
222k
          dst, dst_stride, above_row_1st, left_col_1st, xd->bd);
1694
222k
    }
1695
2.08M
  } else {
1696
540k
    pred_high[mode][tx_size](dst, dst_stride, above_row_1st, left_col_1st,
1697
540k
                             xd->bd);
1698
540k
  }
1699
2.62M
}
1700
1701
#define ARITHMETIC_LEFT_SHIFT(x, shift) \
1702
8.94M
  (((x) >= 0) ? ((x) << (shift)) : (-((-(x)) << (shift))))
1703
1704
void av2_predict_intra_block(const AV2_COMMON *cm, const MACROBLOCKD *xd,
1705
                             int wpx, int hpx, TX_SIZE tx_size,
1706
                             PREDICTION_MODE mode, int angle_delta,
1707
                             int use_palette, const uint16_t *ref,
1708
                             int ref_stride, uint16_t *dst, int dst_stride,
1709
4.27M
                             int col_off, int row_off, int plane) {
1710
4.27M
  const MB_MODE_INFO *const mbmi = xd->mi[0];
1711
4.27M
  const int txwpx = tx_size_wide[tx_size];
1712
4.27M
  const int txhpx = tx_size_high[tx_size];
1713
4.27M
  const int x = col_off << MI_SIZE_LOG2;
1714
4.27M
  const int y = row_off << MI_SIZE_LOG2;
1715
1716
4.27M
  if (use_palette) {
1717
15.5k
    int r, c;
1718
15.5k
    const uint8_t *const map = xd->plane[plane != 0].color_index_map +
1719
15.5k
                               xd->color_index_map_offset[plane != 0];
1720
15.5k
    const uint16_t *const palette =
1721
15.5k
        mbmi->palette_mode_info.palette_colors + plane * PALETTE_MAX_SIZE;
1722
302k
    for (r = 0; r < txhpx; ++r) {
1723
8.78M
      for (c = 0; c < txwpx; ++c) {
1724
8.49M
        dst[r * dst_stride + c] = palette[map[(r + y) * wpx + c + x]];
1725
8.49M
      }
1726
286k
    }
1727
15.5k
    return;
1728
15.5k
  }
1729
1730
4.25M
  const struct macroblockd_plane *const pd = &xd->plane[plane];
1731
4.25M
  const int txw = tx_size_wide_unit[tx_size];
1732
4.25M
  const int txh = tx_size_high_unit[tx_size];
1733
4.25M
  const int ss_x = pd->subsampling_x;
1734
4.25M
  const int ss_y = pd->subsampling_y;
1735
4.25M
  int have_top = 0, have_left = 0;
1736
4.25M
  set_have_top_and_left(&have_top, &have_left, xd, row_off, col_off, plane);
1737
4.25M
  const int mi_row = plane ? xd->mi[0]->chroma_ref_info.mi_row_chroma_base
1738
4.25M
                           : -xd->mb_to_top_edge >> MI_SUBPEL_SIZE_LOG2;
1739
4.25M
  const int mi_col = plane ? xd->mi[0]->chroma_ref_info.mi_col_chroma_base
1740
4.25M
                           : -xd->mb_to_left_edge >> MI_SUBPEL_SIZE_LOG2;
1741
4.25M
  BLOCK_SIZE bsize = mbmi->sb_type[plane > 0];
1742
4.25M
  const BLOCK_SIZE init_bsize = bsize;
1743
  // force 4x4 chroma component block size.
1744
4.25M
  if (ss_x || ss_y) {
1745
1.16M
    bsize = mbmi->chroma_ref_info.bsize_base;
1746
1.16M
  }
1747
4.25M
  const int mi_wide = mi_size_wide[bsize];
1748
4.25M
  const int mi_high = mi_size_high[bsize];
1749
1750
  // Distance between the right edge of this prediction block to
1751
  // the tile right edge
1752
4.25M
  const int xr =
1753
4.25M
      ARITHMETIC_LEFT_SHIFT(xd->tile.mi_col_end - mi_col - mi_wide, 2 - ss_x) +
1754
4.25M
      wpx - x - txwpx;
1755
  // Distance between the bottom edge of this prediction block to
1756
  // the tile bottom edge
1757
4.25M
  const int yd =
1758
4.25M
      ARITHMETIC_LEFT_SHIFT(xd->tile.mi_row_end - mi_row - mi_high, 2 - ss_y) +
1759
4.25M
      hpx - y - txhpx;
1760
4.25M
  const int right_available =
1761
4.25M
      mi_col + ((col_off + txw) << ss_x) < xd->tile.mi_col_end;
1762
4.25M
  const int bottom_available =
1763
4.25M
      (yd > 0) && (mi_row + ((row_off + txh) << ss_y) < xd->tile.mi_row_end);
1764
1765
4.25M
  const bool is_ibp_allowed_blk_sz = tx_size != TX_4X4;
1766
4.25M
  const int apply_ibp = cm->seq_params.enable_ibp && is_ibp_allowed_blk_sz;
1767
4.25M
  const int is_dr_mode = av2_is_directional_mode(mode);
1768
4.25M
  const int use_intra_dip = mbmi->use_intra_dip && plane == PLANE_TYPE_Y;
1769
4.25M
  int need_top_right =
1770
4.25M
      !use_intra_dip ? extend_modes[mode] & NEED_ABOVERIGHT : 1;
1771
4.25M
  int need_bottom_left =
1772
4.25M
      !use_intra_dip ? extend_modes[mode] & NEED_BOTTOMLEFT : 1;
1773
1774
4.25M
  const uint8_t mrl_index =
1775
4.25M
      (plane == PLANE_TYPE_Y && is_inter_block(mbmi, xd->tree_type) == 0)
1776
4.25M
          ? mbmi->mrl_index
1777
4.25M
          : 0;
1778
4.25M
  int p_angle = 0;
1779
4.25M
  const int txb_idx = get_tx_partition_idx(mbmi, plane);
1780
4.25M
  xd->mi[0]->is_wide_angle[plane > 0][txb_idx] = 0;
1781
4.25M
  xd->mi[0]->mapped_intra_mode[plane > 0][txb_idx] = DC_PRED;
1782
4.25M
  if (is_dr_mode) {
1783
1.60M
    p_angle = mode_to_angle_map[mode] + angle_delta;
1784
1.60M
    const int mrl_index_to_delta[4] = { 0, 1, -1, 0 };
1785
1.60M
    assert(mrl_index < 4);
1786
1.60M
    p_angle += mrl_index_to_delta[mrl_index];
1787
1.60M
    assert(p_angle > 0 && p_angle < 270);
1788
1.60M
    if (!is_inter_block(mbmi, xd->tree_type)) {
1789
1.60M
      p_angle =
1790
1.60M
          wide_angle_mapping(xd->mi[0], angle_delta, tx_size, mode, plane);
1791
1.60M
    }
1792
1.60M
    need_top_right =
1793
1.60M
        apply_ibp ? (p_angle < 90) || (p_angle > 180) : p_angle < 90;
1794
1.60M
    need_bottom_left =
1795
1.60M
        apply_ibp ? (p_angle < 90) || (p_angle > 180) : p_angle > 180;
1796
1.60M
  }
1797
1798
  // Possible states for have_top_right(TR) and have_bottom_left(BL)
1799
  // -1 : TR and BL are not needed
1800
  //  0 : TR and BL are needed but not available
1801
  // > 0 : TR and BL are needed and pixels are available
1802
4.25M
  int px_top_right = 0;
1803
4.25M
  const int have_top_right =
1804
4.25M
      need_top_right
1805
4.25M
          ? has_top_right(cm, xd, bsize, mi_row, mi_col, have_top,
1806
689k
                          right_available, tx_size, plane, row_off, col_off,
1807
689k
                          ss_x, ss_y, xr, &px_top_right, bsize != init_bsize)
1808
4.25M
          : -1;
1809
1810
4.25M
  int px_bottom_left = 0;
1811
4.25M
  const int have_bottom_left =
1812
4.25M
      need_bottom_left
1813
4.25M
          ? has_bottom_left(cm, xd, bsize, mi_row, mi_col, bottom_available,
1814
620k
                            have_left, tx_size, plane, row_off, col_off, ss_x,
1815
620k
                            ss_y, yd, &px_bottom_left, bsize != init_bsize)
1816
4.25M
          : -1;
1817
1818
4.25M
  const int disable_edge_filter = !cm->seq_params.enable_intra_edge_filter;
1819
1820
4.25M
  const int is_sb_boundary =
1821
4.25M
      (mi_row % cm->mib_size == 0 && row_off == 0) ? 1 : 0;
1822
1823
4.25M
  if (mrl_index) {
1824
22.1k
    const int n_topright_px = have_top_right ? px_top_right : 0;
1825
22.1k
    const int n_bottomleft_px = have_bottom_left ? px_bottom_left : 0;
1826
22.1k
    av2_build_intra_predictors_high(
1827
22.1k
        xd, ref, ref_stride, dst, dst_stride, mode, p_angle, angle_delta,
1828
22.1k
        tx_size, disable_edge_filter, have_top ? AVMMIN(txwpx, xr + txwpx) : 0,
1829
22.1k
        n_topright_px, have_left ? AVMMIN(txhpx, yd + txhpx) : 0,
1830
22.1k
        n_bottomleft_px, plane, is_sb_boundary, cm->seq_params.enable_ibp,
1831
22.1k
        cm->ibp_directional_weights, mrl_index);
1832
4.23M
  } else {
1833
4.23M
    const int n_topright_px =
1834
4.23M
        have_top_right > 0 ? px_top_right : have_top_right;
1835
4.23M
    const int n_bottomleft_px =
1836
4.23M
        have_bottom_left > 0 ? px_bottom_left : have_bottom_left;
1837
4.23M
    av2_build_intra_predictors_high_default(
1838
4.23M
        xd, ref, ref_stride, dst, dst_stride, mode, p_angle, angle_delta,
1839
4.23M
        tx_size, disable_edge_filter, have_top ? AVMMIN(txwpx, xr + txwpx) : 0,
1840
4.23M
        n_topright_px, have_left ? AVMMIN(txhpx, yd + txhpx) : 0,
1841
4.23M
        n_bottomleft_px, plane, apply_ibp, cm->ibp_directional_weights,
1842
4.23M
        0 /* mrl_index */);
1843
4.23M
  }
1844
4.25M
}
1845
1846
// Fetch neighboring luma samples for multi hypothesis cross component
1847
// prediction for 4:2:0 case.
1848
void av2_mhccp_implicit_fetch_neighbor_luma_420_c(
1849
    const uint16_t *input, int input_stride, int above_lines, int left_lines,
1850
    int is_top_sb_boundary, int ref_width, int ref_height, int sub_y,
1851
    uint8_t cfl_ds_filter_index, int width, int height, uint16_t *output_q3,
1852
0
    int output_stride) {
1853
0
  for (int h = 0; h < ref_height; h += 2) {
1854
0
    for (int w = 0; w < ref_width; w += 2) {
1855
0
      const int bot = w + input_stride;
1856
0
      if ((h >= above_lines && w >= left_lines + width) ||
1857
0
          (h >= above_lines + height && w >= left_lines))
1858
0
        continue;
1859
      // For blocks at the superblock top boundary, we only have one line
1860
      // above available, therefore we need to offset values for above
1861
      // region Proposal E229 (for 4:2:0 case) propose to use only 4 lines
1862
      // and 2 padding lines for the luma reference region, and 2 lines and
1863
      // 1 padding line for the chroma reference region. Therefore, for
1864
      // these 2 padding lines above and to the left, we need to offset the
1865
      // reference region for the top and left boundaries ref_h_t_off is the
1866
      // position offset value of the top pixel in cfl_ds_filter_index == 2
1867
      // for both padding and superblock top boundary.
1868
0
      int ref_h_t_off = 0;
1869
      // ref_h_c_off is the position offset value of the pixel in the same
1870
      // horizontal line of the center pixel for both padding and superblock
1871
      // top boundary.
1872
0
      int ref_h_c_off = 0;
1873
      // ref_h_b_off is the position offset value of the bottom pixel in
1874
      // downsample filtering for both padding and superblock top boundary.
1875
0
      int ref_h_b_off = 0;
1876
      // ref_w_off is the position offset value for padding only in the left
1877
      // and right directions.
1878
0
      int ref_w_off = 0;
1879
      // Preparing the vertical position offset values for superblock top
1880
      // boundary and padding.
1881
0
      if (above_lines == ((LINE_NUM + 1) << sub_y)) {
1882
0
        if (is_top_sb_boundary && (h < above_lines)) {
1883
          // For the top boundary of the superblock, we need to offset the
1884
          // reference region.
1885
0
          ref_h_t_off = h != 0 ? ((LINE_NUM + 1) << sub_y) - h
1886
0
                               : ((LINE_NUM + 1) << sub_y) - (h + 1);
1887
0
          ref_h_c_off = ((LINE_NUM + 1) << sub_y) - (h + 1);
1888
0
          ref_h_b_off = ((LINE_NUM + 1) << sub_y) - (h + 2);
1889
0
        }
1890
0
      }
1891
0
      if (cfl_ds_filter_index == 1) {
1892
0
        output_q3[w >> 1] =
1893
0
            input[AVMMAX(0, w - 1) + ref_w_off + ref_h_c_off * input_stride] +
1894
0
            2 * input[w + ref_w_off + ref_h_c_off * input_stride] +
1895
0
            input[w + 1 + ref_w_off + ref_h_c_off * input_stride] +
1896
0
            input[bot + AVMMAX(-1, -w) + ref_w_off +
1897
0
                  ref_h_b_off * input_stride] +
1898
0
            2 * input[bot + ref_w_off + ref_h_b_off * input_stride] +
1899
0
            input[bot + 1 + ref_w_off + ref_h_b_off * input_stride];
1900
0
      } else if (cfl_ds_filter_index == 2) {
1901
0
        const int top = h != 0 ? w - input_stride : w;
1902
0
        output_q3[w >> 1] =
1903
0
            input[AVMMAX(0, w - 1) + ref_w_off + ref_h_c_off * input_stride] +
1904
0
            4 * input[w + ref_w_off + ref_h_c_off * input_stride] +
1905
0
            input[w + 1 + ref_w_off + ref_h_c_off * input_stride] +
1906
0
            input[top + ref_w_off + ref_h_t_off * input_stride] +
1907
0
            input[bot + ref_w_off + ref_h_b_off * input_stride];
1908
0
      } else {
1909
0
        output_q3[w >> 1] =
1910
0
            (input[w + ref_w_off + ref_h_c_off * input_stride] +
1911
0
             input[w + 1 + ref_w_off + ref_h_c_off * input_stride] +
1912
0
             input[bot + ref_w_off + ref_h_b_off * input_stride] +
1913
0
             input[bot + 1 + ref_w_off + ref_h_b_off * input_stride])
1914
0
            << 1;
1915
0
      }
1916
0
    }
1917
0
    output_q3 += output_stride;
1918
0
    input += (input_stride << 1);
1919
0
  }
1920
0
}
1921
1922
void mhccp_implicit_fetch_neighbor_luma(const AV2_COMMON *cm,
1923
                                        MACROBLOCKD *const xd, int row, int col,
1924
                                        TX_SIZE tx_size, int *above_lines,
1925
                                        int *left_lines, int is_top_sb_boundary,
1926
219k
                                        int *ref_width, int *ref_height) {
1927
219k
  CFL_CTX *const cfl = &xd->cfl;
1928
219k
  struct macroblockd_plane *const pd = &xd->plane[AVM_PLANE_Y];
1929
219k
  const MB_MODE_INFO *const mbmi = xd->mi[0];
1930
1931
219k
  int input_stride = pd->dst.stride;
1932
219k
  uint16_t *dst = &pd->dst.buf[(row * pd->dst.stride + col) << MI_SIZE_LOG2];
1933
1934
219k
  const int sub_x = cfl->subsampling_x;
1935
219k
  const int sub_y = cfl->subsampling_y;
1936
219k
  int width = tx_size_wide[tx_size] << sub_x;
1937
219k
  int height = tx_size_high[tx_size] << sub_y;
1938
219k
  int have_top = 0, have_left = 0;
1939
219k
  set_have_top_and_left(&have_top, &have_left, xd, row, col, 1);
1940
219k
  const int mi_row = -xd->mb_to_top_edge >> MI_SUBPEL_SIZE_LOG2;
1941
219k
  const int mi_col = -xd->mb_to_left_edge >> MI_SUBPEL_SIZE_LOG2;
1942
219k
  BLOCK_SIZE bsize = mbmi->sb_type[1];
1943
219k
  const int mi_wide = mi_size_wide[bsize];
1944
219k
  const int mi_high = mi_size_high[bsize];
1945
1946
219k
  const int row_offset = mi_row - xd->mi[0]->chroma_ref_info.mi_row_chroma_base;
1947
219k
  const int col_offset = mi_col - xd->mi[0]->chroma_ref_info.mi_col_chroma_base;
1948
219k
  *above_lines =
1949
219k
      have_top ? (((int)((xd->mi_row - row_offset) -
1950
211k
                         (int)((LINE_NUM + 1) >> (MI_SIZE_LOG2 >> sub_y))) <
1951
211k
                   xd->tile.mi_row_start)
1952
211k
                      ? ((xd->mi_row - row_offset - xd->tile.mi_row_start)
1953
0
                         << MI_SIZE_LOG2)
1954
211k
                      : ((LINE_NUM + 1) << sub_y))
1955
219k
               : 0;  // This is luma line num
1956
219k
  *left_lines =
1957
219k
      have_left ? (((int)((xd->mi_col - col_offset) -
1958
169k
                          (int)((LINE_NUM + 1) >> (MI_SIZE_LOG2 >> sub_x))) <
1959
169k
                    xd->tile.mi_col_start)
1960
169k
                       ? ((xd->mi_col - col_offset - xd->tile.mi_col_start)
1961
0
                          << MI_SIZE_LOG2)
1962
169k
                       : ((LINE_NUM + 1) << sub_x))
1963
219k
                : 0;
1964
  // Distance between the bottom edge of this prediction block to
1965
  // the frame bottom edge
1966
  // txw,txh width/height in samples of transform block
1967
  // wpx,hpx width/height in pixels of chroma block
1968
  // width,height width height in pixels of transform block
1969
  // wpx - x - width is pixels to right of transform block to edge of chroma
1970
  // block tx_mi_col/tx_mi_row is mi location of transform block
1971
1972
219k
  const BLOCK_SIZE init_bsize = bsize;
1973
  // force 4x4 chroma component block size.
1974
219k
  if (sub_x || sub_y) {
1975
176k
    bsize = mbmi->chroma_ref_info.bsize_base;
1976
176k
  }
1977
219k
  const int hpx = block_size_high[bsize];
1978
219k
  const int wpx = block_size_wide[bsize];
1979
219k
  const int tx_mi_col = xd->mi[0]->chroma_ref_info.mi_col_chroma_base + col;
1980
219k
  const int tx_mi_row = xd->mi[0]->chroma_ref_info.mi_row_chroma_base + row;
1981
1982
219k
  const int x = col << MI_SIZE_LOG2;
1983
219k
  const int xr =
1984
219k
      ARITHMETIC_LEFT_SHIFT(xd->tile.mi_col_end - mi_col - mi_wide, 2 - sub_x) +
1985
219k
      ((wpx - x - width) >> sub_x);
1986
1987
219k
  const int y = row << MI_SIZE_LOG2;
1988
219k
  const int yd =
1989
219k
      ARITHMETIC_LEFT_SHIFT(xd->tile.mi_row_end - mi_row - mi_high, 2 - sub_y) +
1990
219k
      ((hpx - y - height) >> sub_y);
1991
1992
219k
  const int right_available =
1993
219k
      tx_mi_col + (width >> MI_SIZE_LOG2) < xd->tile.mi_col_end;
1994
219k
  const int bottom_available =
1995
219k
      (yd > 0) && (tx_mi_row + (height >> MI_SIZE_LOG2)) < xd->tile.mi_row_end;
1996
1997
219k
  int px_top_right = 0;
1998
219k
  const int have_top_right =
1999
219k
      has_top_right(cm, xd, bsize, mi_row - row_offset, mi_col - col_offset,
2000
219k
                    have_top, right_available, tx_size, 0, row, col, sub_x,
2001
219k
                    sub_y, xr, &px_top_right, bsize != init_bsize);
2002
219k
  int px_bottom_left = 0;
2003
219k
  const int have_bottom_left =
2004
219k
      has_bottom_left(cm, xd, bsize, mi_row - row_offset, mi_col - col_offset,
2005
219k
                      bottom_available, have_left, tx_size, 0, row, col, sub_x,
2006
219k
                      sub_y, yd, &px_bottom_left, bsize != init_bsize);
2007
2008
219k
  *ref_width = AVMMIN(128, *left_lines + width +
2009
219k
                               (have_top_right && width > 4
2010
219k
                                    ? AVMMIN((px_top_right << sub_x), width)
2011
219k
                                    : 0));
2012
2013
219k
  if ((((tx_mi_col) << MI_SIZE_LOG2) + width +
2014
219k
       (have_top_right && width > 4 ? AVMMIN((px_top_right << sub_x), width)
2015
219k
                                    : 0)) >=
2016
219k
      (int)(xd->tile.mi_col_end << MI_SIZE_LOG2)) {
2017
80.0k
    *ref_width = (xd->tile.mi_col_end << MI_SIZE_LOG2) -
2018
80.0k
                 ((tx_mi_col) << MI_SIZE_LOG2) + *left_lines;
2019
80.0k
  }
2020
2021
219k
  *ref_height = AVMMIN(128, *above_lines + height +
2022
219k
                                (have_bottom_left && height > 4
2023
219k
                                     ? AVMMIN((px_bottom_left << sub_y), height)
2024
219k
                                     : 0));
2025
2026
219k
  if ((((tx_mi_row) << MI_SIZE_LOG2) + height +
2027
219k
       (have_bottom_left && height > 4
2028
219k
            ? AVMMIN((px_bottom_left << sub_y), height)
2029
219k
            : 0)) >= (int)(xd->tile.mi_row_end << MI_SIZE_LOG2)) {
2030
18.0k
    *ref_height = *above_lines + (xd->tile.mi_row_end << MI_SIZE_LOG2) -
2031
18.0k
                  ((tx_mi_row) << MI_SIZE_LOG2);
2032
18.0k
  }
2033
2034
219k
  *ref_width = AVMMIN(*ref_width, 128);
2035
219k
  *ref_height = AVMMIN(*ref_height, 128);
2036
2037
219k
  uint16_t *output_q3 = cfl->mhccp_ref_buf_q3[0];
2038
219k
  int output_stride = CFL_BUF_LINE * 2;
2039
219k
  uint16_t *input = dst;
2040
219k
  if (row_offset > 0)
2041
2.36k
    input = input - (row_offset << MI_SIZE_LOG2) * input_stride;
2042
219k
  if (col_offset > 0) input = input - (col_offset << MI_SIZE_LOG2);
2043
219k
  input = input - (*above_lines) * input_stride - *left_lines;
2044
219k
  if ((*above_lines) || (*left_lines)) {
2045
216k
    if (sub_x && sub_y) {
2046
173k
      av2_mhccp_implicit_fetch_neighbor_luma_420(
2047
173k
          input, input_stride, *above_lines, *left_lines, is_top_sb_boundary,
2048
173k
          *ref_width, *ref_height, sub_y, cm->seq_params.cfl_ds_filter_index,
2049
173k
          width, height, output_q3, output_stride);
2050
173k
    } else if (sub_x) {
2051
0
      for (int h = 0; h < (*ref_height); h++) {
2052
0
        for (int i = 0; i < (*ref_width); i += 2) {
2053
0
          const int filter_type = cm->seq_params.cfl_ds_filter_index;
2054
0
          int ref_h_c_off = 0;
2055
0
          int ref_w_off = 0;
2056
0
          if (*above_lines == (LINE_NUM + 1)) {
2057
0
            if (is_top_sb_boundary && (h < *above_lines)) {
2058
              // For the top boundary of the superblock, we need to offset the
2059
              // reference region
2060
0
              ref_h_c_off = (LINE_NUM + 1) - (h + 1);
2061
0
            }
2062
0
          }
2063
0
          if (filter_type == 1) {
2064
0
            output_q3[i >> 1] =
2065
0
                (input[AVMMAX(0, i - 1) + ref_w_off +
2066
0
                       ref_h_c_off * input_stride] +
2067
0
                 2 * input[i + ref_w_off + ref_h_c_off * input_stride] +
2068
0
                 input[i + 1 + ref_w_off + ref_h_c_off * input_stride])
2069
0
                << 1;
2070
0
          } else if (filter_type == 2) {
2071
0
            output_q3[i >> 1] =
2072
0
                input[i + ref_w_off + ref_h_c_off * input_stride] << 3;
2073
0
          } else {
2074
0
            output_q3[i >> 1] =
2075
0
                (input[i + ref_w_off + ref_h_c_off * input_stride] +
2076
0
                 input[i + 1 + ref_w_off + ref_h_c_off * input_stride])
2077
0
                << 2;
2078
0
          }
2079
0
        }
2080
0
        output_q3 += output_stride;
2081
0
        input += input_stride;
2082
0
      }
2083
43.5k
    } else if (sub_y) {
2084
0
      for (int h = 0; h < (*ref_height); h += 2) {
2085
0
        for (int i = 0; i < (*ref_width); ++i) {
2086
0
          const int bot = i + input_stride;
2087
0
          int ref_h_c_off = 0;
2088
0
          int ref_h_b_off = 0;
2089
0
          int ref_w_off = 0;
2090
0
          if (*above_lines == ((LINE_NUM + 1) << sub_y)) {
2091
0
            if (is_top_sb_boundary && (h < *above_lines)) {
2092
              // For the top boundary of the superblock, we need to offset the
2093
              // reference region
2094
0
              ref_h_c_off = ((LINE_NUM + 1) << sub_y) - (h + 1);
2095
0
              ref_h_b_off = ((LINE_NUM + 1) << sub_y) - (h + 2);
2096
0
            }
2097
0
          }
2098
0
          output_q3[i] = (input[i + ref_w_off + ref_h_c_off * input_stride] +
2099
0
                          input[bot + ref_w_off + ref_h_b_off * input_stride])
2100
0
                         << 2;
2101
0
        }
2102
0
        output_q3 += output_stride;
2103
0
        input += input_stride * 2;
2104
0
      }
2105
43.5k
    } else {
2106
948k
      for (int h = 0; h < (*ref_height); h++) {
2107
29.2M
        for (int i = 0; i < (*ref_width); ++i) {
2108
28.3M
          int ref_h_c_off = 0;
2109
28.3M
          int ref_w_off = 0;
2110
          // For the top boundary of the superblock, we need to offset the
2111
          // reference region
2112
28.3M
          if (*above_lines == (LINE_NUM + 1)) {
2113
27.0M
            if (is_top_sb_boundary && (h < *above_lines)) {
2114
378k
              ref_h_c_off = (LINE_NUM + 1) - (h + 1);
2115
378k
            }
2116
27.0M
          }
2117
28.3M
          output_q3[i] = input[i + ref_w_off + ref_h_c_off * input_stride] << 3;
2118
28.3M
        }
2119
904k
        output_q3 += output_stride;
2120
904k
        input += input_stride;
2121
904k
      }
2122
43.5k
    }
2123
216k
  }
2124
219k
}
2125
2126
// Fetch neighboring chroma samples for multi hypothesis cross component
2127
// prediction.
2128
void av2_mhccp_implicit_fetch_neighbor_chroma_c(
2129
    const uint16_t *input, int input_stride, TX_SIZE tx_size, int above_lines,
2130
    int left_lines, int is_top_sb_boundary, int ref_width, int ref_height,
2131
0
    uint16_t *output_q3) {
2132
0
  const int width = tx_size_wide[tx_size];
2133
0
  const int height = tx_size_high[tx_size];
2134
2135
0
  int output_stride = CFL_BUF_LINE * 2;
2136
0
  if (above_lines || left_lines) {
2137
0
    for (int h = 0; h < ref_height; ++h) {
2138
0
      for (int w = 0; w < ref_width; ++w) {
2139
0
        if ((h >= above_lines && w >= left_lines + width) ||
2140
0
            (h >= above_lines + height && w >= left_lines))
2141
0
          continue;
2142
0
        int ref_h_offset = 0, ref_w_offset = 0;
2143
0
        if (above_lines == (LINE_NUM + 1)) {
2144
0
          if (is_top_sb_boundary && (h < above_lines)) {
2145
0
            ref_h_offset = (LINE_NUM + 1) - (h + 1);
2146
0
          } else {
2147
0
            if (h == 0) {
2148
0
              ref_h_offset = 1;
2149
0
            }
2150
0
          }
2151
0
        }
2152
0
        if (left_lines == (LINE_NUM + 1) && (w == 0)) {
2153
0
          ref_w_offset = 1;
2154
0
        }
2155
0
        output_q3[w] = input[w + ref_w_offset + ref_h_offset * input_stride];
2156
0
      }
2157
0
      output_q3 += output_stride;
2158
0
      input += input_stride;
2159
0
    }
2160
0
  }
2161
0
}
2162
#undef ARITHMETIC_LEFT_SHIFT
2163
2164
void av2_predict_intra_block_facade(const AV2_COMMON *cm, MACROBLOCKD *xd,
2165
                                    int plane, int blk_col, int blk_row,
2166
4.25M
                                    TX_SIZE tx_size) {
2167
4.25M
  MB_MODE_INFO *const mbmi = xd->mi[0];
2168
4.25M
  struct macroblockd_plane *const pd = &xd->plane[plane];
2169
4.25M
  const int dst_stride = pd->dst.stride;
2170
4.25M
  uint16_t *dst =
2171
4.25M
      &pd->dst.buf[(blk_row * dst_stride + blk_col) << MI_SIZE_LOG2];
2172
4.25M
  const PREDICTION_MODE mode =
2173
4.25M
      (plane == AVM_PLANE_Y) ? mbmi->mode : get_uv_mode(mbmi->uv_mode);
2174
4.25M
  const int use_palette = mbmi->palette_mode_info.palette_size[plane != 0] > 0;
2175
4.25M
  const int angle_delta = mbmi->angle_delta[plane != AVM_PLANE_Y] * ANGLE_STEP;
2176
2177
4.25M
  if (plane != AVM_PLANE_Y) mbmi->txb_idx = 0;
2178
2179
4.25M
  if (plane != AVM_PLANE_Y && mbmi->uv_mode == UV_CFL_PRED &&
2180
484k
      (cm->seq_params.enable_cfl_intra || cm->seq_params.enable_mhccp)) {
2181
#if CONFIG_DEBUG
2182
    const BLOCK_SIZE plane_bsize = get_mb_plane_block_size(
2183
        xd, mbmi, plane, pd->subsampling_x, pd->subsampling_y);
2184
    (void)plane_bsize;
2185
    assert(plane_bsize < BLOCK_SIZES_ALL);
2186
    if (!xd->lossless[mbmi->segment_id]) {
2187
      assert(blk_col == 0);
2188
      assert(blk_row == 0);
2189
      assert(block_size_wide[plane_bsize] == tx_size_wide[tx_size]);
2190
      assert(block_size_high[plane_bsize] == tx_size_high[tx_size]);
2191
    }
2192
#endif
2193
    // chroma_bsize is the size in units of 4x4 luma samples of the chroma
2194
    // block represented as a BLOCK_SIZE
2195
484k
    const BLOCK_SIZE chroma_bsize = get_bsize_base(xd, mbmi, PLANE_TYPE_UV);
2196
    // chroma_tx_size is the size in units of 4x4 luma samples of the chroma
2197
    // block represented as a TX_SIZE
2198
484k
    CFL_CTX *const cfl = &xd->cfl;
2199
484k
    const int mi_row = -xd->mb_to_top_edge >> MI_SUBPEL_SIZE_LOG2;
2200
484k
    const int mi_col = -xd->mb_to_left_edge >> MI_SUBPEL_SIZE_LOG2;
2201
484k
    const int row_offset =
2202
484k
        mi_row - xd->mi[0]->chroma_ref_info.mi_row_chroma_base;
2203
484k
    const int col_offset =
2204
484k
        mi_col - xd->mi[0]->chroma_ref_info.mi_col_chroma_base;
2205
484k
    struct macroblockd_plane *const luma_pd = &xd->plane[AVM_PLANE_Y];
2206
    // luma_dst points to the top-left luma sample corresponding to the
2207
    // top-left chroma sample of the chroma block
2208
484k
    uint16_t *luma_dst = &luma_pd->dst.buf[-(
2209
484k
        (row_offset * luma_pd->dst.stride + col_offset) << MI_SIZE_LOG2)];
2210
484k
    cfl_store(xd, cfl, luma_dst, luma_pd->dst.stride, 0, 0,
2211
484k
              block_size_wide[chroma_bsize], block_size_high[chroma_bsize],
2212
484k
              cm->seq_params.cfl_ds_filter_index);
2213
2214
484k
    CFL_PRED_TYPE pred_plane = get_cfl_pred_type(plane);
2215
484k
    if (mbmi->cfl_idx == CFL_DERIVED_ALPHA) {
2216
144k
      cfl->dc_pred_is_cached[pred_plane] = 0;
2217
144k
      cfl->use_dc_pred_cache = 0;
2218
144k
    }
2219
484k
    if (cfl->dc_pred_is_cached[pred_plane] == 0) {
2220
484k
      av2_predict_intra_block(cm, xd, pd->width, pd->height, tx_size, mode,
2221
484k
                              angle_delta, use_palette, dst, dst_stride, dst,
2222
484k
                              dst_stride, blk_col, blk_row, plane);
2223
484k
      if (cfl->use_dc_pred_cache) {
2224
0
        av2_cfl_store_dc_pred(xd, dst, pred_plane, tx_size_wide[tx_size]);
2225
0
        cfl->dc_pred_is_cached[pred_plane] = 1;
2226
0
      }
2227
18.4E
    } else {
2228
18.4E
      av2_cfl_load_dc_pred(xd, dst, dst_stride, tx_size, pred_plane);
2229
18.4E
    }
2230
484k
    const int sub_x = cfl->subsampling_x;
2231
484k
    const int sub_y = cfl->subsampling_y;
2232
484k
    int above_lines = 0, left_lines = 0, ref_width = 0, ref_height = 0;
2233
484k
    {
2234
484k
      const int row_start = ((xd->mi[0]->chroma_ref_info.mi_row_chroma_base +
2235
484k
                              (blk_row << cfl->subsampling_y))
2236
484k
                             << MI_SIZE_LOG2);
2237
484k
      const int sb_height = block_size_high[cm->sb_size];
2238
484k
      const int is_top_sb_boundary = !(row_start % sb_height);
2239
2240
484k
      if (mbmi->cfl_idx < CFL_MULTI_PARAM) {
2241
264k
        cfl_implicit_fetch_neighbor_luma(
2242
264k
            cm, xd, blk_row << cfl->subsampling_y,
2243
264k
            blk_col << cfl->subsampling_x, is_top_sb_boundary,
2244
264k
            block_size_wide[chroma_bsize], block_size_high[chroma_bsize]);
2245
264k
        cfl_calc_luma_dc(xd, blk_row, blk_col, tx_size);
2246
264k
      }
2247
484k
      if (mbmi->cfl_idx == CFL_DERIVED_ALPHA) {
2248
144k
        cfl_implicit_fetch_neighbor_chroma(cm, xd, plane, blk_row, blk_col,
2249
144k
                                           tx_size);
2250
144k
        cfl_derive_implicit_scaling_factor(xd, plane, blk_row, blk_col,
2251
144k
                                           tx_size);
2252
339k
      } else if (mbmi->cfl_idx == CFL_MULTI_PARAM) {
2253
219k
        mhccp_implicit_fetch_neighbor_luma(
2254
219k
            cm, xd, blk_row << cfl->subsampling_y,
2255
219k
            blk_col << cfl->subsampling_x, tx_size, &above_lines, &left_lines,
2256
219k
            is_top_sb_boundary, &ref_width, &ref_height);
2257
2258
219k
        above_lines >>= sub_y;
2259
219k
        left_lines >>= sub_x;
2260
219k
        ref_width >>= sub_x;
2261
219k
        ref_height >>= sub_y;
2262
219k
        uint16_t *output_q3 = cfl->mhccp_ref_buf_q3[plane];
2263
219k
        uint16_t *input = dst - above_lines * dst_stride - left_lines;
2264
2265
219k
        av2_mhccp_implicit_fetch_neighbor_chroma(
2266
219k
            input, dst_stride, tx_size, above_lines, left_lines,
2267
219k
            is_top_sb_boundary, ref_width, ref_height, output_q3);
2268
219k
        av2_mhccp_derive_multi_param_hv(xd, plane, above_lines, left_lines,
2269
219k
                                        ref_width, ref_height, mbmi->mh_dir,
2270
219k
                                        is_top_sb_boundary);
2271
219k
      }
2272
484k
    }
2273
484k
    av2_cfl_predict_block(cm->seq_params.enable_cfl_intra,
2274
484k
                          cm->seq_params.enable_mhccp, xd, dst, dst_stride,
2275
484k
                          tx_size, plane, above_lines > 0, left_lines > 0,
2276
484k
                          above_lines, left_lines);
2277
2278
484k
    return;
2279
484k
  }
2280
2281
3.76M
  av2_predict_intra_block(cm, xd, pd->width, pd->height, tx_size, mode,
2282
3.76M
                          angle_delta, use_palette, dst, dst_stride, dst,
2283
3.76M
                          dst_stride, blk_col, blk_row, plane);
2284
3.76M
}
2285
2286
1
void av2_init_intra_predictors(void) {
2287
1
  avm_once(init_intra_predictors_internal);
2288
1
}
2289
2290
DECLARE_ALIGNED(16, const int8_t,
2291
                av2_sub_block_filter_intra_taps_4x4[16][9]) = {
2292
  { 4, 16, 4, 0, 0, 16, 4, 0, 0 }, { 2, 4, 16, 4, 0, 8, 2, 0, 0 },
2293
  { 1, 0, 4, 16, 4, 4, 1, 0, 0 },  { 0, 0, 2, 4, 16, 2, 0, 0, 0 },
2294
2295
  { 2, 8, 2, 0, 0, 4, 16, 4, 0 },  { 0, 2, 8, 2, 0, 2, 8, 2, 0 },
2296
  { 0, 0, 2, 8, 2, 1, 4, 1, 0 },   { 0, 0, 0, 2, 8, 1, 2, 0, 0 },
2297
2298
  { 0, 4, 0, 0, 0, 0, 4, 16, 4 },  { 0, 0, 4, 0, 0, 0, 2, 8, 2 },
2299
  { 0, 0, 1, 4, 1, 0, 1, 4, 1 },   { 0, 0, 0, 2, 4, 0, 0, 4, 0 },
2300
2301
  { 0, 0, 1, 0, 0, 0, 2, 4, 16 },  { 0, 0, 0, 1, 0, 0, 1, 2, 8 },
2302
  { 0, 0, 1, 2, 1, 0, 0, 1, 4 },   { 0, 0, 0, 1, 2, 0, 0, 1, 2 },
2303
};