Coverage Report

Created: 2026-05-24 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/encoder/reconinter_enc.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include <assert.h>
13
#include <stdbool.h>
14
#include <stdio.h>
15
#include <limits.h>
16
17
#include "config/aom_config.h"
18
#include "config/aom_dsp_rtcd.h"
19
#include "config/aom_scale_rtcd.h"
20
21
#include "aom/aom_integer.h"
22
#include "aom_dsp/blend.h"
23
24
#include "av1/common/av1_common_int.h"
25
#include "av1/common/blockd.h"
26
#include "av1/common/mvref_common.h"
27
#include "av1/common/obmc.h"
28
#include "av1/common/reconinter.h"
29
#include "av1/common/reconintra.h"
30
#include "av1/encoder/reconinter_enc.h"
31
32
static inline void enc_calc_subpel_params(
33
    const MV *const src_mv, InterPredParams *const inter_pred_params,
34
0
    uint8_t **pre, SubpelParams *subpel_params, int *src_stride) {
35
0
  struct buf_2d *pre_buf = &inter_pred_params->ref_frame_buf;
36
0
  init_subpel_params(src_mv, inter_pred_params, subpel_params, pre_buf->width,
37
0
                     pre_buf->height);
38
0
  *pre = pre_buf->buf0 +
39
0
         (subpel_params->pos_y >> SCALE_SUBPEL_BITS) * pre_buf->stride +
40
0
         (subpel_params->pos_x >> SCALE_SUBPEL_BITS);
41
0
  *src_stride = pre_buf->stride;
42
0
}
43
44
#define IS_DEC 0
45
#include "av1/common/reconinter_template.inc"
46
#undef IS_DEC
47
48
void av1_enc_build_one_inter_predictor(uint8_t *dst, int dst_stride,
49
                                       const MV *src_mv,
50
0
                                       InterPredParams *inter_pred_params) {
51
0
  build_one_inter_predictor(dst, dst_stride, src_mv, inter_pred_params);
52
0
}
53
54
static void enc_build_inter_predictors(const AV1_COMMON *cm, MACROBLOCKD *xd,
55
                                       int plane, const MB_MODE_INFO *mi,
56
0
                                       int bw, int bh, int mi_x, int mi_y) {
57
0
  build_inter_predictors(cm, xd, plane, mi, /*build_for_obmc=*/0, bw, bh, mi_x,
58
0
                         mi_y);
59
0
}
60
61
0
void av1_enc_build_inter_predictor_y(MACROBLOCKD *xd, int mi_row, int mi_col) {
62
0
  const int mi_x = mi_col * MI_SIZE;
63
0
  const int mi_y = mi_row * MI_SIZE;
64
0
  struct macroblockd_plane *const pd = &xd->plane[AOM_PLANE_Y];
65
0
  InterPredParams inter_pred_params;
66
67
0
  struct buf_2d *const dst_buf = &pd->dst;
68
0
  uint8_t *const dst = dst_buf->buf;
69
0
  const MV mv = xd->mi[0]->mv[0].as_mv;
70
0
  const struct scale_factors *const sf = xd->block_ref_scale_factors[0];
71
72
0
  av1_init_inter_params(&inter_pred_params, pd->width, pd->height, mi_y, mi_x,
73
0
                        pd->subsampling_x, pd->subsampling_y, xd->bd,
74
0
                        is_cur_buf_hbd(xd), false, sf, pd->pre,
75
0
                        xd->mi[0]->interp_filters);
76
77
0
  inter_pred_params.conv_params = get_conv_params_no_round(
78
0
      0, AOM_PLANE_Y, xd->tmp_conv_dst, MAX_SB_SIZE, false, xd->bd);
79
80
0
  inter_pred_params.conv_params.use_dist_wtd_comp_avg = 0;
81
0
  av1_enc_build_one_inter_predictor(dst, dst_buf->stride, &mv,
82
0
                                    &inter_pred_params);
83
0
}
84
85
void av1_enc_build_inter_predictor_y_nonrd(MACROBLOCKD *xd,
86
                                           InterPredParams *inter_pred_params,
87
0
                                           const SubpelParams *subpel_params) {
88
0
  struct macroblockd_plane *const pd = &xd->plane[AOM_PLANE_Y];
89
90
0
  const MB_MODE_INFO *mbmi = xd->mi[0];
91
0
  struct buf_2d *const dst_buf = &pd->dst;
92
0
  const struct buf_2d *pre_buf = &pd->pre[0];
93
0
  const uint8_t *src =
94
0
      pre_buf->buf0 +
95
0
      (subpel_params->pos_y >> SCALE_SUBPEL_BITS) * pre_buf->stride +
96
0
      (subpel_params->pos_x >> SCALE_SUBPEL_BITS);
97
0
  uint8_t *const dst = dst_buf->buf;
98
0
  int src_stride = pre_buf->stride;
99
0
  int dst_stride = dst_buf->stride;
100
0
  inter_pred_params->ref_frame_buf = *pre_buf;
101
102
  // Initialize interp filter for single reference mode.
103
0
  init_interp_filter_params(inter_pred_params->interp_filter_params,
104
0
                            &mbmi->interp_filters.as_filters, pd->width,
105
0
                            pd->height, /*is_intrabc=*/0);
106
107
0
  av1_make_inter_predictor(src, src_stride, dst, dst_stride, inter_pred_params,
108
0
                           subpel_params);
109
0
}
110
111
void av1_enc_build_inter_predictor(const AV1_COMMON *cm, MACROBLOCKD *xd,
112
                                   int mi_row, int mi_col,
113
                                   const BUFFER_SET *ctx, BLOCK_SIZE bsize,
114
0
                                   int plane_from, int plane_to) {
115
0
  for (int plane = plane_from; plane <= plane_to; ++plane) {
116
0
    if (plane && !xd->is_chroma_ref) break;
117
0
    const int mi_x = mi_col * MI_SIZE;
118
0
    const int mi_y = mi_row * MI_SIZE;
119
0
    enc_build_inter_predictors(cm, xd, plane, xd->mi[0], xd->plane[plane].width,
120
0
                               xd->plane[plane].height, mi_x, mi_y);
121
122
0
    if (is_interintra_pred(xd->mi[0])) {
123
0
      BUFFER_SET default_ctx = {
124
0
        { xd->plane[0].dst.buf, xd->plane[1].dst.buf, xd->plane[2].dst.buf },
125
0
        { xd->plane[0].dst.stride, xd->plane[1].dst.stride,
126
0
          xd->plane[2].dst.stride }
127
0
      };
128
0
      if (!ctx) {
129
0
        ctx = &default_ctx;
130
0
      }
131
0
      av1_build_interintra_predictor(cm, xd, xd->plane[plane].dst.buf,
132
0
                                     xd->plane[plane].dst.stride, ctx, plane,
133
0
                                     bsize);
134
0
    }
135
0
  }
136
0
}
137
138
static void setup_address_for_obmc(MACROBLOCKD *xd, int mi_row_offset,
139
                                   int mi_col_offset, MB_MODE_INFO *ref_mbmi,
140
                                   struct build_prediction_ctxt *ctxt,
141
0
                                   const int num_planes) {
142
0
  const BLOCK_SIZE ref_bsize = AOMMAX(BLOCK_8X8, ref_mbmi->bsize);
143
0
  const int ref_mi_row = xd->mi_row + mi_row_offset;
144
0
  const int ref_mi_col = xd->mi_col + mi_col_offset;
145
146
0
  for (int plane = 0; plane < num_planes; ++plane) {
147
0
    struct macroblockd_plane *const pd = &xd->plane[plane];
148
0
    setup_pred_plane(&pd->dst, ref_bsize, ctxt->tmp_buf[plane],
149
0
                     ctxt->tmp_width[plane], ctxt->tmp_height[plane],
150
0
                     ctxt->tmp_stride[plane], mi_row_offset, mi_col_offset,
151
0
                     NULL, pd->subsampling_x, pd->subsampling_y);
152
0
  }
153
154
0
  const MV_REFERENCE_FRAME frame = ref_mbmi->ref_frame[0];
155
156
0
  const RefCntBuffer *const ref_buf = get_ref_frame_buf(ctxt->cm, frame);
157
0
  const struct scale_factors *const sf =
158
0
      get_ref_scale_factors_const(ctxt->cm, frame);
159
160
0
  xd->block_ref_scale_factors[0] = sf;
161
0
  if (!av1_is_valid_scale(sf))
162
0
    aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM,
163
0
                       "Reference frame has invalid dimensions");
164
165
0
  av1_setup_pre_planes(xd, 0, &ref_buf->buf, ref_mi_row, ref_mi_col, sf,
166
0
                       num_planes);
167
0
}
168
169
static inline void build_obmc_prediction(MACROBLOCKD *xd, int rel_mi_row,
170
                                         int rel_mi_col, uint8_t op_mi_size,
171
                                         int dir, MB_MODE_INFO *above_mbmi,
172
0
                                         void *fun_ctxt, const int num_planes) {
173
0
  struct build_prediction_ctxt *ctxt = (struct build_prediction_ctxt *)fun_ctxt;
174
0
  setup_address_for_obmc(xd, rel_mi_row, rel_mi_col, above_mbmi, ctxt,
175
0
                         num_planes);
176
177
0
  const int mi_x = (xd->mi_col + rel_mi_col) << MI_SIZE_LOG2;
178
0
  const int mi_y = (xd->mi_row + rel_mi_row) << MI_SIZE_LOG2;
179
180
0
  const BLOCK_SIZE bsize = xd->mi[0]->bsize;
181
182
0
  InterPredParams inter_pred_params;
183
184
0
  for (int j = 0; j < num_planes; ++j) {
185
0
    const struct macroblockd_plane *pd = &xd->plane[j];
186
0
    int bw = 0, bh = 0;
187
188
0
    if (dir) {
189
      // prepare left reference block size
190
0
      bw = clamp(block_size_wide[bsize] >> (pd->subsampling_x + 1), 4,
191
0
                 block_size_wide[BLOCK_64X64] >> (pd->subsampling_x + 1));
192
0
      bh = (op_mi_size << MI_SIZE_LOG2) >> pd->subsampling_y;
193
0
    } else {
194
      // prepare above reference block size
195
0
      bw = (op_mi_size * MI_SIZE) >> pd->subsampling_x;
196
0
      bh = clamp(block_size_high[bsize] >> (pd->subsampling_y + 1), 4,
197
0
                 block_size_high[BLOCK_64X64] >> (pd->subsampling_y + 1));
198
0
    }
199
200
0
    if (av1_skip_u4x4_pred_in_obmc(bsize, pd, dir)) continue;
201
202
0
    const struct buf_2d *const pre_buf = &pd->pre[0];
203
0
    const MV mv = above_mbmi->mv[0].as_mv;
204
205
0
    av1_init_inter_params(&inter_pred_params, bw, bh, mi_y >> pd->subsampling_y,
206
0
                          mi_x >> pd->subsampling_x, pd->subsampling_x,
207
0
                          pd->subsampling_y, xd->bd, is_cur_buf_hbd(xd), 0,
208
0
                          xd->block_ref_scale_factors[0], pre_buf,
209
0
                          above_mbmi->interp_filters);
210
0
    inter_pred_params.conv_params = get_conv_params(0, j, xd->bd);
211
212
0
    av1_enc_build_one_inter_predictor(pd->dst.buf, pd->dst.stride, &mv,
213
0
                                      &inter_pred_params);
214
0
  }
215
0
}
216
217
void av1_build_prediction_by_above_preds(const AV1_COMMON *cm, MACROBLOCKD *xd,
218
                                         uint8_t *tmp_buf[MAX_MB_PLANE],
219
                                         int tmp_width[MAX_MB_PLANE],
220
                                         int tmp_height[MAX_MB_PLANE],
221
0
                                         int tmp_stride[MAX_MB_PLANE]) {
222
0
  if (!xd->up_available) return;
223
0
  struct build_prediction_ctxt ctxt = {
224
0
    cm, tmp_buf, tmp_width, tmp_height, tmp_stride, xd->mb_to_right_edge, NULL
225
0
  };
226
0
  BLOCK_SIZE bsize = xd->mi[0]->bsize;
227
0
  foreach_overlappable_nb_above(cm, xd,
228
0
                                max_neighbor_obmc[mi_size_wide_log2[bsize]],
229
0
                                build_obmc_prediction, &ctxt);
230
0
}
231
232
void av1_build_prediction_by_left_preds(const AV1_COMMON *cm, MACROBLOCKD *xd,
233
                                        uint8_t *tmp_buf[MAX_MB_PLANE],
234
                                        int tmp_width[MAX_MB_PLANE],
235
                                        int tmp_height[MAX_MB_PLANE],
236
0
                                        int tmp_stride[MAX_MB_PLANE]) {
237
0
  if (!xd->left_available) return;
238
0
  struct build_prediction_ctxt ctxt = {
239
0
    cm, tmp_buf, tmp_width, tmp_height, tmp_stride, xd->mb_to_bottom_edge, NULL
240
0
  };
241
0
  BLOCK_SIZE bsize = xd->mi[0]->bsize;
242
0
  foreach_overlappable_nb_left(cm, xd,
243
0
                               max_neighbor_obmc[mi_size_high_log2[bsize]],
244
0
                               build_obmc_prediction, &ctxt);
245
0
}
246
247
0
void av1_build_obmc_inter_predictors_sb(const AV1_COMMON *cm, MACROBLOCKD *xd) {
248
0
  const int num_planes = av1_num_planes(cm);
249
0
  uint8_t *dst_buf1[MAX_MB_PLANE], *dst_buf2[MAX_MB_PLANE];
250
0
  int dst_stride1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
251
0
  int dst_stride2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
252
0
  int dst_width1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
253
0
  int dst_width2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
254
0
  int dst_height1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
255
0
  int dst_height2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
256
257
0
  av1_setup_obmc_dst_bufs(xd, dst_buf1, dst_buf2);
258
259
0
  const int mi_row = xd->mi_row;
260
0
  const int mi_col = xd->mi_col;
261
0
  av1_build_prediction_by_above_preds(cm, xd, dst_buf1, dst_width1, dst_height1,
262
0
                                      dst_stride1);
263
0
  av1_build_prediction_by_left_preds(cm, xd, dst_buf2, dst_width2, dst_height2,
264
0
                                     dst_stride2);
265
0
  av1_setup_dst_planes(xd->plane, xd->mi[0]->bsize, &cm->cur_frame->buf, mi_row,
266
0
                       mi_col, 0, num_planes);
267
0
  av1_build_obmc_inter_prediction(cm, xd, dst_buf1, dst_stride1, dst_buf2,
268
0
                                  dst_stride2);
269
0
}
270
271
void av1_build_inter_predictors_for_planes_single_buf(
272
    MACROBLOCKD *xd, BLOCK_SIZE bsize, int plane_from, int plane_to, int ref,
273
0
    uint8_t *ext_dst[], int ext_dst_stride[]) {
274
0
  assert(bsize < BLOCK_SIZES_ALL);
275
0
  const MB_MODE_INFO *mi = xd->mi[0];
276
0
  const int mi_row = xd->mi_row;
277
0
  const int mi_col = xd->mi_col;
278
0
  const int mi_x = mi_col * MI_SIZE;
279
0
  const int mi_y = mi_row * MI_SIZE;
280
0
  WarpTypesAllowed warp_types;
281
0
  const WarpedMotionParams *const wm = &xd->global_motion[mi->ref_frame[ref]];
282
0
  warp_types.global_warp_allowed = is_global_mv_block(mi, wm->wmtype);
283
0
  warp_types.local_warp_allowed = mi->motion_mode == WARPED_CAUSAL;
284
285
0
  for (int plane = plane_from; plane <= plane_to; ++plane) {
286
0
    const struct macroblockd_plane *pd = &xd->plane[plane];
287
0
    const BLOCK_SIZE plane_bsize =
288
0
        get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
289
0
    const int bw = block_size_wide[plane_bsize];
290
0
    const int bh = block_size_high[plane_bsize];
291
292
0
    InterPredParams inter_pred_params;
293
294
0
    av1_init_inter_params(&inter_pred_params, bw, bh, mi_y >> pd->subsampling_y,
295
0
                          mi_x >> pd->subsampling_x, pd->subsampling_x,
296
0
                          pd->subsampling_y, xd->bd, is_cur_buf_hbd(xd), 0,
297
0
                          xd->block_ref_scale_factors[ref], &pd->pre[ref],
298
0
                          mi->interp_filters);
299
0
    inter_pred_params.conv_params = get_conv_params(0, plane, xd->bd);
300
0
    av1_init_warp_params(&inter_pred_params, &warp_types, ref, xd, mi);
301
302
0
    uint8_t *const dst = get_buf_by_bd(xd, ext_dst[plane]);
303
0
    const MV mv = mi->mv[ref].as_mv;
304
305
0
    av1_enc_build_one_inter_predictor(dst, ext_dst_stride[plane], &mv,
306
0
                                      &inter_pred_params);
307
0
  }
308
0
}
309
310
static void build_masked_compound(
311
    uint8_t *dst, int dst_stride, const uint8_t *src0, int src0_stride,
312
    const uint8_t *src1, int src1_stride,
313
    const INTERINTER_COMPOUND_DATA *const comp_data, BLOCK_SIZE sb_type, int h,
314
0
    int w) {
315
  // Derive subsampling from h and w passed in. May be refactored to
316
  // pass in subsampling factors directly.
317
0
  const int subh = (2 << mi_size_high_log2[sb_type]) == h;
318
0
  const int subw = (2 << mi_size_wide_log2[sb_type]) == w;
319
0
  const uint8_t *mask = av1_get_compound_type_mask(comp_data, sb_type);
320
0
  aom_blend_a64_mask(dst, dst_stride, src0, src0_stride, src1, src1_stride,
321
0
                     mask, block_size_wide[sb_type], w, h, subw, subh);
322
0
}
323
324
#if CONFIG_AV1_HIGHBITDEPTH
325
static void build_masked_compound_highbd(
326
    uint8_t *dst_8, int dst_stride, const uint8_t *src0_8, int src0_stride,
327
    const uint8_t *src1_8, int src1_stride,
328
    const INTERINTER_COMPOUND_DATA *const comp_data, BLOCK_SIZE sb_type, int h,
329
0
    int w, int bd) {
330
  // Derive subsampling from h and w passed in. May be refactored to
331
  // pass in subsampling factors directly.
332
0
  const int subh = (2 << mi_size_high_log2[sb_type]) == h;
333
0
  const int subw = (2 << mi_size_wide_log2[sb_type]) == w;
334
0
  const uint8_t *mask = av1_get_compound_type_mask(comp_data, sb_type);
335
  // const uint8_t *mask =
336
  //     av1_get_contiguous_soft_mask(wedge_index, wedge_sign, sb_type);
337
0
  aom_highbd_blend_a64_mask(dst_8, dst_stride, src0_8, src0_stride, src1_8,
338
0
                            src1_stride, mask, block_size_wide[sb_type], w, h,
339
0
                            subw, subh, bd);
340
0
}
341
#endif
342
343
static void build_wedge_inter_predictor_from_buf(
344
    MACROBLOCKD *xd, int plane, int x, int y, int w, int h, uint8_t *ext_dst0,
345
0
    int ext_dst_stride0, uint8_t *ext_dst1, int ext_dst_stride1) {
346
0
  MB_MODE_INFO *const mbmi = xd->mi[0];
347
0
  const int is_compound = has_second_ref(mbmi);
348
0
  MACROBLOCKD_PLANE *const pd = &xd->plane[plane];
349
0
  struct buf_2d *const dst_buf = &pd->dst;
350
0
  uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
351
0
  mbmi->interinter_comp.seg_mask = xd->seg_mask;
352
0
  const INTERINTER_COMPOUND_DATA *comp_data = &mbmi->interinter_comp;
353
0
  const int is_hbd = is_cur_buf_hbd(xd);
354
355
0
  if (is_compound && is_masked_compound_type(comp_data->type)) {
356
0
    if (!plane && comp_data->type == COMPOUND_DIFFWTD) {
357
0
#if CONFIG_AV1_HIGHBITDEPTH
358
0
      if (is_hbd) {
359
0
        av1_build_compound_diffwtd_mask_highbd(
360
0
            comp_data->seg_mask, comp_data->mask_type,
361
0
            CONVERT_TO_BYTEPTR(ext_dst0), ext_dst_stride0,
362
0
            CONVERT_TO_BYTEPTR(ext_dst1), ext_dst_stride1, h, w, xd->bd);
363
0
      } else {
364
0
        av1_build_compound_diffwtd_mask(
365
0
            comp_data->seg_mask, comp_data->mask_type, ext_dst0,
366
0
            ext_dst_stride0, ext_dst1, ext_dst_stride1, h, w);
367
0
      }
368
#else
369
      (void)is_hbd;
370
      av1_build_compound_diffwtd_mask(comp_data->seg_mask, comp_data->mask_type,
371
                                      ext_dst0, ext_dst_stride0, ext_dst1,
372
                                      ext_dst_stride1, h, w);
373
#endif  // CONFIG_AV1_HIGHBITDEPTH
374
0
    }
375
0
#if CONFIG_AV1_HIGHBITDEPTH
376
0
    if (is_hbd) {
377
0
      build_masked_compound_highbd(
378
0
          dst, dst_buf->stride, CONVERT_TO_BYTEPTR(ext_dst0), ext_dst_stride0,
379
0
          CONVERT_TO_BYTEPTR(ext_dst1), ext_dst_stride1, comp_data, mbmi->bsize,
380
0
          h, w, xd->bd);
381
0
    } else {
382
0
      build_masked_compound(dst, dst_buf->stride, ext_dst0, ext_dst_stride0,
383
0
                            ext_dst1, ext_dst_stride1, comp_data, mbmi->bsize,
384
0
                            h, w);
385
0
    }
386
#else
387
    build_masked_compound(dst, dst_buf->stride, ext_dst0, ext_dst_stride0,
388
                          ext_dst1, ext_dst_stride1, comp_data, mbmi->bsize, h,
389
                          w);
390
#endif
391
0
  } else {
392
0
#if CONFIG_AV1_HIGHBITDEPTH
393
0
    if (is_hbd) {
394
0
      aom_highbd_convolve_copy(CONVERT_TO_SHORTPTR(ext_dst0), ext_dst_stride0,
395
0
                               CONVERT_TO_SHORTPTR(dst), dst_buf->stride, w, h);
396
0
    } else {
397
0
      aom_convolve_copy(ext_dst0, ext_dst_stride0, dst, dst_buf->stride, w, h);
398
0
    }
399
#else
400
    aom_convolve_copy(ext_dst0, ext_dst_stride0, dst, dst_buf->stride, w, h);
401
#endif
402
0
  }
403
0
}
404
405
void av1_build_wedge_inter_predictor_from_buf(MACROBLOCKD *xd, BLOCK_SIZE bsize,
406
                                              int plane_from, int plane_to,
407
                                              uint8_t *ext_dst0[],
408
                                              int ext_dst_stride0[],
409
                                              uint8_t *ext_dst1[],
410
0
                                              int ext_dst_stride1[]) {
411
0
  int plane;
412
0
  assert(bsize < BLOCK_SIZES_ALL);
413
0
  for (plane = plane_from; plane <= plane_to; ++plane) {
414
0
    const BLOCK_SIZE plane_bsize = get_plane_block_size(
415
0
        bsize, xd->plane[plane].subsampling_x, xd->plane[plane].subsampling_y);
416
0
    const int bw = block_size_wide[plane_bsize];
417
0
    const int bh = block_size_high[plane_bsize];
418
0
    build_wedge_inter_predictor_from_buf(
419
0
        xd, plane, 0, 0, bw, bh, ext_dst0[plane], ext_dst_stride0[plane],
420
0
        ext_dst1[plane], ext_dst_stride1[plane]);
421
0
  }
422
0
}
423
424
bool aom_upsampled_pred_scaled(MACROBLOCKD *xd, const AV1_COMMON *const cm,
425
                               int mi_row, int mi_col, const MV *const mv,
426
0
                               uint8_t *comp_pred, int width, int height) {
427
  // expect xd == NULL only in tests
428
0
  if (xd != NULL) {
429
0
    const MB_MODE_INFO *mi = xd->mi[0];
430
0
    const int ref_num = 0;
431
0
    const int is_intrabc = is_intrabc_block(mi);
432
0
    const struct scale_factors *const sf =
433
0
        is_intrabc ? &cm->sf_identity : xd->block_ref_scale_factors[ref_num];
434
0
    const int is_scaled = av1_is_scaled(sf);
435
436
0
    if (is_scaled) {
437
0
      int plane = 0;
438
0
      const int mi_x = mi_col * MI_SIZE;
439
0
      const int mi_y = mi_row * MI_SIZE;
440
0
      const struct macroblockd_plane *const pd = &xd->plane[plane];
441
0
      const struct buf_2d *const dst_buf = &pd->dst;
442
0
      const struct buf_2d *const pre_buf =
443
0
          is_intrabc ? dst_buf : &pd->pre[ref_num];
444
445
0
      InterPredParams inter_pred_params;
446
0
      inter_pred_params.conv_params = get_conv_params(0, plane, xd->bd);
447
0
      const int_interpfilters filters =
448
0
          av1_broadcast_interp_filter(EIGHTTAP_REGULAR);
449
0
      av1_init_inter_params(
450
0
          &inter_pred_params, width, height, mi_y >> pd->subsampling_y,
451
0
          mi_x >> pd->subsampling_x, pd->subsampling_x, pd->subsampling_y,
452
0
          xd->bd, is_cur_buf_hbd(xd), is_intrabc, sf, pre_buf, filters);
453
0
      av1_enc_build_one_inter_predictor(comp_pred, width, mv,
454
0
                                        &inter_pred_params);
455
0
      return true;
456
0
    }
457
0
  }
458
0
  return false;
459
0
}
460
461
// Get pred block from up-sampled reference.
462
void aom_upsampled_pred_c(MACROBLOCKD *xd, const AV1_COMMON *const cm,
463
                          int mi_row, int mi_col, const MV *const mv,
464
                          uint8_t *comp_pred, int width, int height,
465
                          int subpel_x_q3, int subpel_y_q3, const uint8_t *ref,
466
0
                          int ref_stride, int subpel_search) {
467
0
  if (aom_upsampled_pred_scaled(xd, cm, mi_row, mi_col, mv, comp_pred, width,
468
0
                                height)) {
469
0
    return;
470
0
  }
471
472
0
  const InterpFilterParams *filter = av1_get_filter(subpel_search);
473
474
0
  if (!subpel_x_q3 && !subpel_y_q3) {
475
0
    for (int i = 0; i < height; i++) {
476
0
      memcpy(comp_pred, ref, width * sizeof(*comp_pred));
477
0
      comp_pred += width;
478
0
      ref += ref_stride;
479
0
    }
480
0
  } else if (!subpel_y_q3) {
481
0
    const int16_t *const kernel =
482
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_x_q3 << 1);
483
0
    aom_convolve8_horiz_c(ref, ref_stride, comp_pred, width, kernel, 16, NULL,
484
0
                          -1, width, height);
485
0
  } else if (!subpel_x_q3) {
486
0
    const int16_t *const kernel =
487
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_y_q3 << 1);
488
0
    aom_convolve8_vert_c(ref, ref_stride, comp_pred, width, NULL, -1, kernel,
489
0
                         16, width, height);
490
0
  } else {
491
0
    DECLARE_ALIGNED(16, uint8_t,
492
0
                    temp[((MAX_SB_SIZE * 2 + 16) + 16) * MAX_SB_SIZE]);
493
0
    const int16_t *const kernel_x =
494
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_x_q3 << 1);
495
0
    const int16_t *const kernel_y =
496
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_y_q3 << 1);
497
0
    const int intermediate_height =
498
0
        (((height - 1) * 8 + subpel_y_q3) >> 3) + filter->taps;
499
0
    assert(intermediate_height <= (MAX_SB_SIZE * 2 + 16) + 16);
500
0
    aom_convolve8_horiz_c(ref - ref_stride * ((filter->taps >> 1) - 1),
501
0
                          ref_stride, temp, MAX_SB_SIZE, kernel_x, 16, NULL, -1,
502
0
                          width, intermediate_height);
503
0
    aom_convolve8_vert_c(temp + MAX_SB_SIZE * ((filter->taps >> 1) - 1),
504
0
                         MAX_SB_SIZE, comp_pred, width, NULL, -1, kernel_y, 16,
505
0
                         width, height);
506
0
  }
507
0
}
508
509
void aom_comp_avg_upsampled_pred_c(MACROBLOCKD *xd, const AV1_COMMON *const cm,
510
                                   int mi_row, int mi_col, const MV *const mv,
511
                                   uint8_t *comp_pred, const uint8_t *pred,
512
                                   int width, int height, int subpel_x_q3,
513
                                   int subpel_y_q3, const uint8_t *ref,
514
0
                                   int ref_stride, int subpel_search) {
515
0
  int i, j;
516
517
0
  aom_upsampled_pred_c(xd, cm, mi_row, mi_col, mv, comp_pred, width, height,
518
0
                       subpel_x_q3, subpel_y_q3, ref, ref_stride,
519
0
                       subpel_search);
520
0
  for (i = 0; i < height; i++) {
521
0
    for (j = 0; j < width; j++) {
522
0
      comp_pred[j] = ROUND_POWER_OF_TWO(comp_pred[j] + pred[j], 1);
523
0
    }
524
0
    comp_pred += width;
525
0
    pred += width;
526
0
  }
527
0
}
528
529
void aom_comp_mask_upsampled_pred(MACROBLOCKD *xd, const AV1_COMMON *const cm,
530
                                  int mi_row, int mi_col, const MV *const mv,
531
                                  uint8_t *comp_pred, const uint8_t *pred,
532
                                  int width, int height, int subpel_x_q3,
533
                                  int subpel_y_q3, const uint8_t *ref,
534
                                  int ref_stride, const uint8_t *mask,
535
                                  int mask_stride, int invert_mask,
536
0
                                  int subpel_search) {
537
0
  aom_upsampled_pred(xd, cm, mi_row, mi_col, mv, comp_pred, width, height,
538
0
                     subpel_x_q3, subpel_y_q3, ref, ref_stride, subpel_search);
539
0
  aom_comp_mask_pred(comp_pred, pred, width, height, comp_pred, width, mask,
540
0
                     mask_stride, invert_mask);
541
0
}
542
543
#if CONFIG_AV1_HIGHBITDEPTH
544
void aom_highbd_upsampled_pred_c(MACROBLOCKD *xd,
545
                                 const struct AV1Common *const cm, int mi_row,
546
                                 int mi_col, const MV *const mv,
547
                                 uint8_t *comp_pred8, int width, int height,
548
                                 int subpel_x_q3, int subpel_y_q3,
549
                                 const uint8_t *ref8, int ref_stride, int bd,
550
0
                                 int subpel_search) {
551
0
  if (aom_upsampled_pred_scaled(xd, cm, mi_row, mi_col, mv, comp_pred8, width,
552
0
                                height)) {
553
0
    return;
554
0
  }
555
556
0
  const InterpFilterParams *filter = av1_get_filter(subpel_search);
557
558
0
  if (!subpel_x_q3 && !subpel_y_q3) {
559
0
    const uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
560
0
    uint16_t *comp_pred = CONVERT_TO_SHORTPTR(comp_pred8);
561
0
    for (int i = 0; i < height; i++) {
562
0
      memcpy(comp_pred, ref, width * sizeof(*comp_pred));
563
0
      comp_pred += width;
564
0
      ref += ref_stride;
565
0
    }
566
0
  } else if (!subpel_y_q3) {
567
0
    const int16_t *const kernel =
568
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_x_q3 << 1);
569
0
    aom_highbd_convolve8_horiz_c(ref8, ref_stride, comp_pred8, width, kernel,
570
0
                                 16, NULL, -1, width, height, bd);
571
0
  } else if (!subpel_x_q3) {
572
0
    const int16_t *const kernel =
573
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_y_q3 << 1);
574
0
    aom_highbd_convolve8_vert_c(ref8, ref_stride, comp_pred8, width, NULL, -1,
575
0
                                kernel, 16, width, height, bd);
576
0
  } else {
577
0
    DECLARE_ALIGNED(16, uint16_t,
578
0
                    temp[((MAX_SB_SIZE + 16) + 16) * MAX_SB_SIZE]);
579
0
    const int16_t *const kernel_x =
580
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_x_q3 << 1);
581
0
    const int16_t *const kernel_y =
582
0
        av1_get_interp_filter_subpel_kernel(filter, subpel_y_q3 << 1);
583
0
    const int intermediate_height =
584
0
        (((height - 1) * 8 + subpel_y_q3) >> 3) + filter->taps;
585
0
    assert(intermediate_height <= (MAX_SB_SIZE * 2 + 16) + 16);
586
0
    aom_highbd_convolve8_horiz_c(ref8 - ref_stride * ((filter->taps >> 1) - 1),
587
0
                                 ref_stride, CONVERT_TO_BYTEPTR(temp),
588
0
                                 MAX_SB_SIZE, kernel_x, 16, NULL, -1, width,
589
0
                                 intermediate_height, bd);
590
0
    aom_highbd_convolve8_vert_c(
591
0
        CONVERT_TO_BYTEPTR(temp + MAX_SB_SIZE * ((filter->taps >> 1) - 1)),
592
0
        MAX_SB_SIZE, comp_pred8, width, NULL, -1, kernel_y, 16, width, height,
593
0
        bd);
594
0
  }
595
0
}
596
597
void aom_highbd_comp_avg_upsampled_pred_c(
598
    MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
599
    const MV *const mv, uint8_t *comp_pred8, const uint8_t *pred8, int width,
600
    int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref8,
601
0
    int ref_stride, int bd, int subpel_search) {
602
0
  int i, j;
603
604
0
  const uint16_t *pred = CONVERT_TO_SHORTPTR(pred8);
605
0
  uint16_t *comp_pred = CONVERT_TO_SHORTPTR(comp_pred8);
606
0
  aom_highbd_upsampled_pred(xd, cm, mi_row, mi_col, mv, comp_pred8, width,
607
0
                            height, subpel_x_q3, subpel_y_q3, ref8, ref_stride,
608
0
                            bd, subpel_search);
609
0
  for (i = 0; i < height; ++i) {
610
0
    for (j = 0; j < width; ++j) {
611
0
      comp_pred[j] = ROUND_POWER_OF_TWO(pred[j] + comp_pred[j], 1);
612
0
    }
613
0
    comp_pred += width;
614
0
    pred += width;
615
0
  }
616
0
}
617
618
void aom_highbd_comp_mask_upsampled_pred(
619
    MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
620
    const MV *const mv, uint8_t *comp_pred8, const uint8_t *pred8, int width,
621
    int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref8,
622
    int ref_stride, const uint8_t *mask, int mask_stride, int invert_mask,
623
0
    int bd, int subpel_search) {
624
0
  aom_highbd_upsampled_pred(xd, cm, mi_row, mi_col, mv, comp_pred8, width,
625
0
                            height, subpel_x_q3, subpel_y_q3, ref8, ref_stride,
626
0
                            bd, subpel_search);
627
0
  aom_highbd_comp_mask_pred(comp_pred8, pred8, width, height, comp_pred8, width,
628
0
                            mask, mask_stride, invert_mask);
629
0
}
630
#endif  // CONFIG_AV1_HIGHBITDEPTH