reconinter.c 81.8 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <assert.h>

#include "./vpx_scale_rtcd.h"
Geza Lore's avatar
Geza Lore committed
14
#include "./vpx_dsp_rtcd.h"
Jingning Han's avatar
Jingning Han committed
15 16
#include "./vpx_config.h"

17 18
#include "aom/vpx_integer.h"
#include "aom_dsp/blend.h"
Jingning Han's avatar
Jingning Han committed
19

20 21 22
#include "av1/common/blockd.h"
#include "av1/common/reconinter.h"
#include "av1/common/reconintra.h"
23
#if CONFIG_OBMC
24
#include "av1/common/onyxc_int.h"
25
#endif  // CONFIG_OBMC
26
#if CONFIG_GLOBAL_MOTION
27
#include "av1/common/warped_motion.h"
28
#endif  // CONFIG_GLOBAL_MOTION
Jingning Han's avatar
Jingning Han committed
29

30
#if CONFIG_EXT_INTER
31

clang-format's avatar
clang-format committed
32
#define NSMOOTHERS 1
33
static int get_masked_weight(int m, int smoothness) {
clang-format's avatar
clang-format committed
34 35 36 37 38 39 40
#define SMOOTHER_LEN 32
  static const uint8_t smoothfn[NSMOOTHERS][2 * SMOOTHER_LEN + 1] = { {
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 1, 2, 4, 7, 13, 21, 32, 43, 51, 57, 60, 62, 63, 64, 64, 64, 64, 64, 64,
      64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
      64, 64,
  } };
41 42 43 44 45
  if (m < -SMOOTHER_LEN)
    return 0;
  else if (m > SMOOTHER_LEN)
    return (1 << WEDGE_WEIGHT_BITS);
  else
46
    return smoothfn[smoothness][m + SMOOTHER_LEN];
47 48
}

49 50 51
// [smoother][negative][direction]
DECLARE_ALIGNED(
    16, static uint8_t,
clang-format's avatar
clang-format committed
52 53
    wedge_mask_obl[NSMOOTHERS][2][WEDGE_DIRECTIONS][MASK_MASTER_SIZE *
                                                    MASK_MASTER_SIZE]);
54

clang-format's avatar
clang-format committed
55 56
DECLARE_ALIGNED(16, static uint8_t,
                wedge_signflip_lookup[BLOCK_SIZES][MAX_WEDGE_TYPES]);
57

58 59
// 3 * MAX_WEDGE_SQUARE is an easy to compute and fairly tight upper bound
// on the sum of all mask sizes up to an including MAX_WEDGE_SQUARE.
clang-format's avatar
clang-format committed
60 61
DECLARE_ALIGNED(16, static uint8_t,
                wedge_mask_buf[2 * MAX_WEDGE_TYPES * 3 * MAX_WEDGE_SQUARE]);
62 63 64

static wedge_masks_type wedge_masks[BLOCK_SIZES][2];

65 66 67
// Some unused wedge codebooks left temporarily to facilitate experiments.
// To be removed when setteld.
static wedge_code_type wedge_codebook_8_hgtw[8] = {
clang-format's avatar
clang-format committed
68 69 70 71
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_OBLIQUE27, 4, 2 },  { WEDGE_OBLIQUE27, 4, 6 },
  { WEDGE_OBLIQUE153, 4, 2 }, { WEDGE_OBLIQUE153, 4, 6 },
72 73
};

74
static wedge_code_type wedge_codebook_8_hltw[8] = {
clang-format's avatar
clang-format committed
75 76 77 78
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_OBLIQUE63, 2, 4 },  { WEDGE_OBLIQUE63, 6, 4 },
  { WEDGE_OBLIQUE117, 2, 4 }, { WEDGE_OBLIQUE117, 6, 4 },
79 80
};

81
static wedge_code_type wedge_codebook_8_heqw[8] = {
clang-format's avatar
clang-format committed
82 83 84 85
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 6 },
  { WEDGE_VERTICAL, 2, 4 },   { WEDGE_VERTICAL, 6, 4 },
86 87
};

88 89
#if !USE_LARGE_WEDGE_CODEBOOK
static const wedge_code_type wedge_codebook_16_hgtw[16] = {
clang-format's avatar
clang-format committed
90 91 92 93 94 95 96 97
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 6 }, { WEDGE_VERTICAL, 4, 4 },
  { WEDGE_OBLIQUE27, 4, 2 },  { WEDGE_OBLIQUE27, 4, 6 },
  { WEDGE_OBLIQUE153, 4, 2 }, { WEDGE_OBLIQUE153, 4, 6 },
  { WEDGE_OBLIQUE63, 2, 4 },  { WEDGE_OBLIQUE63, 6, 4 },
  { WEDGE_OBLIQUE117, 2, 4 }, { WEDGE_OBLIQUE117, 6, 4 },
Debargha Mukherjee's avatar
Debargha Mukherjee committed
98
};
99

100
static const wedge_code_type wedge_codebook_16_hltw[16] = {
clang-format's avatar
clang-format committed
101 102 103 104 105 106 107 108
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_VERTICAL, 2, 4 },   { WEDGE_VERTICAL, 4, 4 },
  { WEDGE_VERTICAL, 6, 4 },   { WEDGE_HORIZONTAL, 4, 4 },
  { WEDGE_OBLIQUE27, 4, 2 },  { WEDGE_OBLIQUE27, 4, 6 },
  { WEDGE_OBLIQUE153, 4, 2 }, { WEDGE_OBLIQUE153, 4, 6 },
  { WEDGE_OBLIQUE63, 2, 4 },  { WEDGE_OBLIQUE63, 6, 4 },
  { WEDGE_OBLIQUE117, 2, 4 }, { WEDGE_OBLIQUE117, 6, 4 },
109 110
};

111
static const wedge_code_type wedge_codebook_16_heqw[16] = {
clang-format's avatar
clang-format committed
112 113 114 115 116 117 118 119
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 6 },
  { WEDGE_VERTICAL, 2, 4 },   { WEDGE_VERTICAL, 6, 4 },
  { WEDGE_OBLIQUE27, 4, 2 },  { WEDGE_OBLIQUE27, 4, 6 },
  { WEDGE_OBLIQUE153, 4, 2 }, { WEDGE_OBLIQUE153, 4, 6 },
  { WEDGE_OBLIQUE63, 2, 4 },  { WEDGE_OBLIQUE63, 6, 4 },
  { WEDGE_OBLIQUE117, 2, 4 }, { WEDGE_OBLIQUE117, 6, 4 },
120 121
};

122
const wedge_params_type wedge_params_lookup[BLOCK_SIZES] = {
clang-format's avatar
clang-format committed
123 124 125 126 127 128 129 130 131 132 133 134 135
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
  { 4, wedge_codebook_16_heqw, wedge_signflip_lookup[3], 0, wedge_masks[3] },
  { 4, wedge_codebook_16_hgtw, wedge_signflip_lookup[4], 0, wedge_masks[4] },
  { 4, wedge_codebook_16_hltw, wedge_signflip_lookup[5], 0, wedge_masks[5] },
  { 4, wedge_codebook_16_heqw, wedge_signflip_lookup[6], 0, wedge_masks[6] },
  { 4, wedge_codebook_16_hgtw, wedge_signflip_lookup[7], 0, wedge_masks[7] },
  { 4, wedge_codebook_16_hltw, wedge_signflip_lookup[8], 0, wedge_masks[8] },
  { 4, wedge_codebook_16_heqw, wedge_signflip_lookup[9], 0, wedge_masks[9] },
  { 0, wedge_codebook_8_hgtw, wedge_signflip_lookup[10], 0, wedge_masks[10] },
  { 0, wedge_codebook_8_hltw, wedge_signflip_lookup[11], 0, wedge_masks[11] },
  { 0, wedge_codebook_8_heqw, wedge_signflip_lookup[12], 0, wedge_masks[12] },
136
#if CONFIG_EXT_PARTITION
clang-format's avatar
clang-format committed
137 138 139
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
140
#endif  // CONFIG_EXT_PARTITION
141 142
};

143 144 145
#else

static const wedge_code_type wedge_codebook_32_hgtw[32] = {
clang-format's avatar
clang-format committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 6 }, { WEDGE_VERTICAL, 4, 4 },
  { WEDGE_OBLIQUE27, 4, 1 },  { WEDGE_OBLIQUE27, 4, 2 },
  { WEDGE_OBLIQUE27, 4, 3 },  { WEDGE_OBLIQUE27, 4, 5 },
  { WEDGE_OBLIQUE27, 4, 6 },  { WEDGE_OBLIQUE27, 4, 7 },
  { WEDGE_OBLIQUE153, 4, 1 }, { WEDGE_OBLIQUE153, 4, 2 },
  { WEDGE_OBLIQUE153, 4, 3 }, { WEDGE_OBLIQUE153, 4, 5 },
  { WEDGE_OBLIQUE153, 4, 6 }, { WEDGE_OBLIQUE153, 4, 7 },
  { WEDGE_OBLIQUE63, 1, 4 },  { WEDGE_OBLIQUE63, 2, 4 },
  { WEDGE_OBLIQUE63, 3, 4 },  { WEDGE_OBLIQUE63, 5, 4 },
  { WEDGE_OBLIQUE63, 6, 4 },  { WEDGE_OBLIQUE63, 7, 4 },
  { WEDGE_OBLIQUE117, 1, 4 }, { WEDGE_OBLIQUE117, 2, 4 },
  { WEDGE_OBLIQUE117, 3, 4 }, { WEDGE_OBLIQUE117, 5, 4 },
  { WEDGE_OBLIQUE117, 6, 4 }, { WEDGE_OBLIQUE117, 7, 4 },
162 163
};

164
static const wedge_code_type wedge_codebook_32_hltw[32] = {
clang-format's avatar
clang-format committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_VERTICAL, 2, 4 },   { WEDGE_VERTICAL, 4, 4 },
  { WEDGE_VERTICAL, 6, 4 },   { WEDGE_HORIZONTAL, 4, 4 },
  { WEDGE_OBLIQUE27, 4, 1 },  { WEDGE_OBLIQUE27, 4, 2 },
  { WEDGE_OBLIQUE27, 4, 3 },  { WEDGE_OBLIQUE27, 4, 5 },
  { WEDGE_OBLIQUE27, 4, 6 },  { WEDGE_OBLIQUE27, 4, 7 },
  { WEDGE_OBLIQUE153, 4, 1 }, { WEDGE_OBLIQUE153, 4, 2 },
  { WEDGE_OBLIQUE153, 4, 3 }, { WEDGE_OBLIQUE153, 4, 5 },
  { WEDGE_OBLIQUE153, 4, 6 }, { WEDGE_OBLIQUE153, 4, 7 },
  { WEDGE_OBLIQUE63, 1, 4 },  { WEDGE_OBLIQUE63, 2, 4 },
  { WEDGE_OBLIQUE63, 3, 4 },  { WEDGE_OBLIQUE63, 5, 4 },
  { WEDGE_OBLIQUE63, 6, 4 },  { WEDGE_OBLIQUE63, 7, 4 },
  { WEDGE_OBLIQUE117, 1, 4 }, { WEDGE_OBLIQUE117, 2, 4 },
  { WEDGE_OBLIQUE117, 3, 4 }, { WEDGE_OBLIQUE117, 5, 4 },
  { WEDGE_OBLIQUE117, 6, 4 }, { WEDGE_OBLIQUE117, 7, 4 },
181 182
};

183
static const wedge_code_type wedge_codebook_32_heqw[32] = {
clang-format's avatar
clang-format committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
  { WEDGE_OBLIQUE27, 4, 4 },  { WEDGE_OBLIQUE63, 4, 4 },
  { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 },
  { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 6 },
  { WEDGE_VERTICAL, 2, 4 },   { WEDGE_VERTICAL, 6, 4 },
  { WEDGE_OBLIQUE27, 4, 1 },  { WEDGE_OBLIQUE27, 4, 2 },
  { WEDGE_OBLIQUE27, 4, 3 },  { WEDGE_OBLIQUE27, 4, 5 },
  { WEDGE_OBLIQUE27, 4, 6 },  { WEDGE_OBLIQUE27, 4, 7 },
  { WEDGE_OBLIQUE153, 4, 1 }, { WEDGE_OBLIQUE153, 4, 2 },
  { WEDGE_OBLIQUE153, 4, 3 }, { WEDGE_OBLIQUE153, 4, 5 },
  { WEDGE_OBLIQUE153, 4, 6 }, { WEDGE_OBLIQUE153, 4, 7 },
  { WEDGE_OBLIQUE63, 1, 4 },  { WEDGE_OBLIQUE63, 2, 4 },
  { WEDGE_OBLIQUE63, 3, 4 },  { WEDGE_OBLIQUE63, 5, 4 },
  { WEDGE_OBLIQUE63, 6, 4 },  { WEDGE_OBLIQUE63, 7, 4 },
  { WEDGE_OBLIQUE117, 1, 4 }, { WEDGE_OBLIQUE117, 2, 4 },
  { WEDGE_OBLIQUE117, 3, 4 }, { WEDGE_OBLIQUE117, 5, 4 },
  { WEDGE_OBLIQUE117, 6, 4 }, { WEDGE_OBLIQUE117, 7, 4 },
200 201
};

202
const wedge_params_type wedge_params_lookup[BLOCK_SIZES] = {
clang-format's avatar
clang-format committed
203 204 205 206 207 208 209 210 211 212 213 214 215
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
  { 5, wedge_codebook_32_heqw, wedge_signflip_lookup[3], 0, wedge_masks[3] },
  { 5, wedge_codebook_32_hgtw, wedge_signflip_lookup[4], 0, wedge_masks[4] },
  { 5, wedge_codebook_32_hltw, wedge_signflip_lookup[5], 0, wedge_masks[5] },
  { 5, wedge_codebook_32_heqw, wedge_signflip_lookup[6], 0, wedge_masks[6] },
  { 5, wedge_codebook_32_hgtw, wedge_signflip_lookup[7], 0, wedge_masks[7] },
  { 5, wedge_codebook_32_hltw, wedge_signflip_lookup[8], 0, wedge_masks[8] },
  { 5, wedge_codebook_32_heqw, wedge_signflip_lookup[9], 0, wedge_masks[9] },
  { 0, wedge_codebook_8_hgtw, wedge_signflip_lookup[10], 0, wedge_masks[10] },
  { 0, wedge_codebook_8_hltw, wedge_signflip_lookup[11], 0, wedge_masks[11] },
  { 0, wedge_codebook_8_heqw, wedge_signflip_lookup[12], 0, wedge_masks[12] },
Debargha Mukherjee's avatar
Debargha Mukherjee committed
216
#if CONFIG_EXT_PARTITION
clang-format's avatar
clang-format committed
217 218 219
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
  { 0, NULL, NULL, 0, NULL },
Debargha Mukherjee's avatar
Debargha Mukherjee committed
220
#endif  // CONFIG_EXT_PARTITION
221
};
222
#endif  // USE_LARGE_WEDGE_CODEBOOK
223

clang-format's avatar
clang-format committed
224
static const uint8_t *get_wedge_mask_inplace(int wedge_index, int neg,
225
                                             BLOCK_SIZE sb_type) {
Debargha Mukherjee's avatar
Debargha Mukherjee committed
226
  const uint8_t *master;
227 228
  const int bh = 4 << b_height_log2_lookup[sb_type];
  const int bw = 4 << b_width_log2_lookup[sb_type];
229 230 231
  const wedge_code_type *a =
      wedge_params_lookup[sb_type].codebook + wedge_index;
  const int smoother = wedge_params_lookup[sb_type].smoother;
232
  int woff, hoff;
233 234 235 236 237 238 239
  const uint8_t wsignflip = wedge_params_lookup[sb_type].signflip[wedge_index];

  assert(wedge_index >= 0 &&
         wedge_index < (1 << get_wedge_bits_lookup(sb_type)));
  woff = (a->x_offset * bw) >> 3;
  hoff = (a->y_offset * bh) >> 3;
  master = wedge_mask_obl[smoother][neg ^ wsignflip][a->direction] +
clang-format's avatar
clang-format committed
240 241
           MASK_MASTER_STRIDE * (MASK_MASTER_SIZE / 2 - hoff) +
           MASK_MASTER_SIZE / 2 - woff;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
242 243 244
  return master;
}

clang-format's avatar
clang-format committed
245 246
const uint8_t *vp10_get_soft_mask(int wedge_index, int wedge_sign,
                                  BLOCK_SIZE sb_type, int offset_x,
247
                                  int offset_y) {
248
  const uint8_t *mask =
249
      get_wedge_mask_inplace(wedge_index, wedge_sign, sb_type);
clang-format's avatar
clang-format committed
250
  if (mask) mask -= (offset_x + offset_y * MASK_MASTER_STRIDE);
251
  return mask;
252 253
}

254
static void init_wedge_master_masks() {
255 256 257 258
  int i, j, s;
  const int w = MASK_MASTER_SIZE;
  const int h = MASK_MASTER_SIZE;
  const int stride = MASK_MASTER_STRIDE;
clang-format's avatar
clang-format committed
259
  const int a[2] = { 2, 1 };
260 261 262 263 264 265 266 267
  const double asqrt = sqrt(a[0] * a[0] + a[1] * a[1]);
  for (s = 0; s < NSMOOTHERS; s++) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int x = (2 * j + 1 - w);
        int y = (2 * i + 1 - h);
        int m = (int)rint((a[0] * x + a[1] * y) / asqrt);
        wedge_mask_obl[s][1][WEDGE_OBLIQUE63][i * stride + j] =
clang-format's avatar
clang-format committed
268 269
            wedge_mask_obl[s][1][WEDGE_OBLIQUE27][j * stride + i] =
                get_masked_weight(m, s);
270
        wedge_mask_obl[s][1][WEDGE_OBLIQUE117][i * stride + w - 1 - j] =
clang-format's avatar
clang-format committed
271 272
            wedge_mask_obl[s][1][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] =
                (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m, s);
273
        wedge_mask_obl[s][0][WEDGE_OBLIQUE63][i * stride + j] =
clang-format's avatar
clang-format committed
274 275
            wedge_mask_obl[s][0][WEDGE_OBLIQUE27][j * stride + i] =
                (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m, s);
276
        wedge_mask_obl[s][0][WEDGE_OBLIQUE117][i * stride + w - 1 - j] =
clang-format's avatar
clang-format committed
277 278
            wedge_mask_obl[s][0][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] =
                get_masked_weight(m, s);
279
        wedge_mask_obl[s][1][WEDGE_VERTICAL][i * stride + j] =
clang-format's avatar
clang-format committed
280 281
            wedge_mask_obl[s][1][WEDGE_HORIZONTAL][j * stride + i] =
                get_masked_weight(x, s);
282
        wedge_mask_obl[s][0][WEDGE_VERTICAL][i * stride + j] =
clang-format's avatar
clang-format committed
283 284
            wedge_mask_obl[s][0][WEDGE_HORIZONTAL][j * stride + i] =
                (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(x, s);
285 286
      }
  }
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
}

// If the signs for the wedges for various blocksizes are
// inconsistent flip the sign flag. Do it only once for every
// wedge codebook.
static void init_wedge_signs() {
  BLOCK_SIZE sb_type;
  memset(wedge_signflip_lookup, 0, sizeof(wedge_signflip_lookup));
  for (sb_type = BLOCK_4X4; sb_type < BLOCK_SIZES; ++sb_type) {
    const int bw = 4 * num_4x4_blocks_wide_lookup[sb_type];
    const int bh = 4 * num_4x4_blocks_high_lookup[sb_type];
    const wedge_params_type wedge_params = wedge_params_lookup[sb_type];
    const int wbits = wedge_params.bits;
    const int wtypes = 1 << wbits;
    int i, w;
    if (wbits == 0) continue;
    for (w = 0; w < wtypes; ++w) {
      const uint8_t *mask = get_wedge_mask_inplace(w, 0, sb_type);
      int sum = 0;
clang-format's avatar
clang-format committed
306 307
      for (i = 0; i < bw; ++i) sum += mask[i];
      for (i = 0; i < bh; ++i) sum += mask[i * MASK_MASTER_STRIDE];
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
      sum = (sum + (bw + bh) / 2) / (bw + bh);
      wedge_params.signflip[w] = (sum < 32);
    }
  }
}

static void init_wedge_masks() {
  uint8_t *dst = wedge_mask_buf;
  BLOCK_SIZE bsize;
  memset(wedge_masks, 0, sizeof(wedge_masks));
  for (bsize = BLOCK_4X4; bsize < BLOCK_SIZES; ++bsize) {
    const uint8_t *mask;
    const int bw = 4 * num_4x4_blocks_wide_lookup[bsize];
    const int bh = 4 * num_4x4_blocks_high_lookup[bsize];
    const wedge_params_type *wedge_params = &wedge_params_lookup[bsize];
    const int wbits = wedge_params->bits;
    const int wtypes = 1 << wbits;
    int w;
    if (wbits == 0) continue;
    for (w = 0; w < wtypes; ++w) {
      mask = get_wedge_mask_inplace(w, 0, bsize);
clang-format's avatar
clang-format committed
329 330
      vpx_convolve_copy(mask, MASK_MASTER_STRIDE, dst, bw, NULL, 0, NULL, 0, bw,
                        bh);
331 332 333 334
      wedge_params->masks[0][w] = dst;
      dst += bw * bh;

      mask = get_wedge_mask_inplace(w, 1, bsize);
clang-format's avatar
clang-format committed
335 336
      vpx_convolve_copy(mask, MASK_MASTER_STRIDE, dst, bw, NULL, 0, NULL, 0, bw,
                        bh);
337 338 339 340 341 342 343 344 345 346
      wedge_params->masks[1][w] = dst;
      dst += bw * bh;
    }
    assert(sizeof(wedge_mask_buf) >= (size_t)(dst - wedge_mask_buf));
  }
}

// Equation of line: f(x, y) = a[0]*(x - a[2]*w/8) + a[1]*(y - a[3]*h/8) = 0
void vp10_init_wedge_masks() {
  init_wedge_master_masks();
347
  init_wedge_signs();
348
  init_wedge_masks();
349 350
}

351 352
#if CONFIG_SUPERTX
static void build_masked_compound_wedge_extend(
clang-format's avatar
clang-format committed
353 354 355
    uint8_t *dst, int dst_stride, const uint8_t *src0, int src0_stride,
    const uint8_t *src1, int src1_stride, int wedge_index, int wedge_sign,
    BLOCK_SIZE sb_type, int wedge_offset_x, int wedge_offset_y, int h, int w) {
356 357
  const int subh = (2 << b_height_log2_lookup[sb_type]) == h;
  const int subw = (2 << b_width_log2_lookup[sb_type]) == w;
clang-format's avatar
clang-format committed
358 359 360 361
  const uint8_t *mask = vp10_get_soft_mask(wedge_index, wedge_sign, sb_type,
                                           wedge_offset_x, wedge_offset_y);
  vpx_blend_a64_mask(dst, dst_stride, src0, src0_stride, src1, src1_stride,
                     mask, MASK_MASTER_STRIDE, h, w, subh, subw);
362 363 364
}

#if CONFIG_VP9_HIGHBITDEPTH
365
static void build_masked_compound_wedge_extend_highbd(
clang-format's avatar
clang-format committed
366 367 368 369
    uint8_t *dst_8, int dst_stride, const uint8_t *src0_8, int src0_stride,
    const uint8_t *src1_8, int src1_stride, int wedge_index, int wedge_sign,
    BLOCK_SIZE sb_type, int wedge_offset_x, int wedge_offset_y, int h, int w,
    int bd) {
370 371
  const int subh = (2 << b_height_log2_lookup[sb_type]) == h;
  const int subw = (2 << b_width_log2_lookup[sb_type]) == w;
clang-format's avatar
clang-format committed
372 373 374 375 376
  const uint8_t *mask = vp10_get_soft_mask(wedge_index, wedge_sign, sb_type,
                                           wedge_offset_x, wedge_offset_y);
  vpx_highbd_blend_a64_mask(dst_8, dst_stride, src0_8, src0_stride, src1_8,
                            src1_stride, mask, MASK_MASTER_STRIDE, h, w, subh,
                            subw, bd);
377 378
}
#endif  // CONFIG_VP9_HIGHBITDEPTH
379
#endif  // CONFIG_SUPERTX
380

clang-format's avatar
clang-format committed
381 382 383 384 385
static void build_masked_compound_wedge(uint8_t *dst, int dst_stride,
                                        const uint8_t *src0, int src0_stride,
                                        const uint8_t *src1, int src1_stride,
                                        int wedge_index, int wedge_sign,
                                        BLOCK_SIZE sb_type, int h, int w) {
386 387 388 389
  // Derive subsampling from h and w passed in. May be refactored to
  // pass in subsampling factors directly.
  const int subh = (2 << b_height_log2_lookup[sb_type]) == h;
  const int subw = (2 << b_width_log2_lookup[sb_type]) == w;
clang-format's avatar
clang-format committed
390 391 392 393 394
  const uint8_t *mask =
      vp10_get_contiguous_soft_mask(wedge_index, wedge_sign, sb_type);
  vpx_blend_a64_mask(dst, dst_stride, src0, src0_stride, src1, src1_stride,
                     mask, 4 * num_4x4_blocks_wide_lookup[sb_type], h, w, subh,
                     subw);
395 396 397
}

#if CONFIG_VP9_HIGHBITDEPTH
Geza Lore's avatar
Geza Lore committed
398
static void build_masked_compound_wedge_highbd(
clang-format's avatar
clang-format committed
399 400 401
    uint8_t *dst_8, int dst_stride, const uint8_t *src0_8, int src0_stride,
    const uint8_t *src1_8, int src1_stride, int wedge_index, int wedge_sign,
    BLOCK_SIZE sb_type, int h, int w, int bd) {
402 403 404 405
  // Derive subsampling from h and w passed in. May be refactored to
  // pass in subsampling factors directly.
  const int subh = (2 << b_height_log2_lookup[sb_type]) == h;
  const int subw = (2 << b_width_log2_lookup[sb_type]) == w;
clang-format's avatar
clang-format committed
406 407 408 409 410
  const uint8_t *mask =
      vp10_get_contiguous_soft_mask(wedge_index, wedge_sign, sb_type);
  vpx_highbd_blend_a64_mask(
      dst_8, dst_stride, src0_8, src0_stride, src1_8, src1_stride, mask,
      4 * num_4x4_blocks_wide_lookup[sb_type], h, w, subh, subw, bd);
411 412 413
}
#endif  // CONFIG_VP9_HIGHBITDEPTH

clang-format's avatar
clang-format committed
414 415 416 417 418
void vp10_make_masked_inter_predictor(const uint8_t *pre, int pre_stride,
                                      uint8_t *dst, int dst_stride,
                                      const int subpel_x, const int subpel_y,
                                      const struct scale_factors *sf, int w,
                                      int h,
419
#if CONFIG_DUAL_FILTER
clang-format's avatar
clang-format committed
420
                                      const INTERP_FILTER *interp_filter,
421
#else
clang-format's avatar
clang-format committed
422
                                      const INTERP_FILTER interp_filter,
423
#endif
clang-format's avatar
clang-format committed
424
                                      int xs, int ys,
425
#if CONFIG_SUPERTX
clang-format's avatar
clang-format committed
426
                                      int wedge_offset_x, int wedge_offset_y,
427
#endif  // CONFIG_SUPERTX
clang-format's avatar
clang-format committed
428
                                      const MACROBLOCKD *xd) {
429
  const MODE_INFO *mi = xd->mi[0];
clang-format's avatar
clang-format committed
430 431
// The prediction filter types used here should be those for
// the second reference block.
Geza Lore's avatar
Geza Lore committed
432 433 434
#if CONFIG_DUAL_FILTER
  INTERP_FILTER tmp_ipf[4] = {
    interp_filter[2], interp_filter[3], interp_filter[2], interp_filter[3],
435
  };
Geza Lore's avatar
Geza Lore committed
436 437 438
#else
  INTERP_FILTER tmp_ipf = interp_filter;
#endif  // CONFIG_DUAL_FILTER
439
#if CONFIG_VP9_HIGHBITDEPTH
440
  DECLARE_ALIGNED(16, uint8_t, tmp_dst_[2 * MAX_SB_SQUARE]);
clang-format's avatar
clang-format committed
441 442 443 444 445
  uint8_t *tmp_dst = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
                         ? CONVERT_TO_BYTEPTR(tmp_dst_)
                         : tmp_dst_;
  vp10_make_inter_predictor(pre, pre_stride, tmp_dst, MAX_SB_SIZE, subpel_x,
                            subpel_y, sf, w, h, 0, tmp_ipf, xs, ys, xd);
446 447
#if CONFIG_SUPERTX
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
448
    build_masked_compound_wedge_extend_highbd(
clang-format's avatar
clang-format committed
449 450 451
        dst, dst_stride, dst, dst_stride, tmp_dst, MAX_SB_SIZE,
        mi->mbmi.interinter_wedge_index, mi->mbmi.interinter_wedge_sign,
        mi->mbmi.sb_type, wedge_offset_x, wedge_offset_y, h, w, xd->bd);
452
  else
453
    build_masked_compound_wedge_extend(
clang-format's avatar
clang-format committed
454 455 456
        dst, dst_stride, dst, dst_stride, tmp_dst, MAX_SB_SIZE,
        mi->mbmi.interinter_wedge_index, mi->mbmi.interinter_wedge_sign,
        mi->mbmi.sb_type, wedge_offset_x, wedge_offset_y, h, w);
457 458
#else
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
459
    build_masked_compound_wedge_highbd(
clang-format's avatar
clang-format committed
460 461
        dst, dst_stride, dst, dst_stride, tmp_dst, MAX_SB_SIZE,
        mi->mbmi.interinter_wedge_index, mi->mbmi.interinter_wedge_sign,
462
        mi->mbmi.sb_type, h, w, xd->bd);
463
  else
clang-format's avatar
clang-format committed
464 465 466 467
    build_masked_compound_wedge(dst, dst_stride, dst, dst_stride, tmp_dst,
                                MAX_SB_SIZE, mi->mbmi.interinter_wedge_index,
                                mi->mbmi.interinter_wedge_sign,
                                mi->mbmi.sb_type, h, w);
468 469
#endif  // CONFIG_SUPERTX
#else   // CONFIG_VP9_HIGHBITDEPTH
470
  DECLARE_ALIGNED(16, uint8_t, tmp_dst[MAX_SB_SQUARE]);
clang-format's avatar
clang-format committed
471 472
  vp10_make_inter_predictor(pre, pre_stride, tmp_dst, MAX_SB_SIZE, subpel_x,
                            subpel_y, sf, w, h, 0, tmp_ipf, xs, ys, xd);
473
#if CONFIG_SUPERTX
474
  build_masked_compound_wedge_extend(
clang-format's avatar
clang-format committed
475 476 477
      dst, dst_stride, dst, dst_stride, tmp_dst, MAX_SB_SIZE,
      mi->mbmi.interinter_wedge_index, mi->mbmi.interinter_wedge_sign,
      mi->mbmi.sb_type, wedge_offset_x, wedge_offset_y, h, w);
478
#else
clang-format's avatar
clang-format committed
479 480 481 482
  build_masked_compound_wedge(dst, dst_stride, dst, dst_stride, tmp_dst,
                              MAX_SB_SIZE, mi->mbmi.interinter_wedge_index,
                              mi->mbmi.interinter_wedge_sign, mi->mbmi.sb_type,
                              h, w);
483 484 485 486
#endif  // CONFIG_SUPERTX
#endif  // CONFIG_VP9_HIGHBITDEPTH
}
#endif  // CONFIG_EXT_INTER
487

Jingning Han's avatar
Jingning Han committed
488
#if CONFIG_VP9_HIGHBITDEPTH
clang-format's avatar
clang-format committed
489 490 491
void vp10_highbd_build_inter_predictor(
    const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride,
    const MV *src_mv, const struct scale_factors *sf, int w, int h, int ref,
492
#if CONFIG_DUAL_FILTER
clang-format's avatar
clang-format committed
493
    const INTERP_FILTER *interp_filter,
494
#else
clang-format's avatar
clang-format committed
495
    const INTERP_FILTER interp_filter,
496
#endif
clang-format's avatar
clang-format committed
497
    enum mv_precision precision, int x, int y, int bd) {
Jingning Han's avatar
Jingning Han committed
498 499 500 501 502 503 504 505 506
  const int is_q4 = precision == MV_PRECISION_Q4;
  const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
                     is_q4 ? src_mv->col : src_mv->col * 2 };
  MV32 mv = vp10_scale_mv(&mv_q4, x, y, sf);
  const int subpel_x = mv.col & SUBPEL_MASK;
  const int subpel_y = mv.row & SUBPEL_MASK;

  src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);

507
  highbd_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
508 509
                         sf, w, h, ref, interp_filter, sf->x_step_q4,
                         sf->y_step_q4, bd);
Jingning Han's avatar
Jingning Han committed
510 511 512 513
}
#endif  // CONFIG_VP9_HIGHBITDEPTH

void vp10_build_inter_predictor(const uint8_t *src, int src_stride,
clang-format's avatar
clang-format committed
514 515 516
                                uint8_t *dst, int dst_stride, const MV *src_mv,
                                const struct scale_factors *sf, int w, int h,
                                int ref,
517
#if CONFIG_DUAL_FILTER
clang-format's avatar
clang-format committed
518
                                const INTERP_FILTER *interp_filter,
519
#else
clang-format's avatar
clang-format committed
520
                                const INTERP_FILTER interp_filter,
521
#endif
clang-format's avatar
clang-format committed
522
                                enum mv_precision precision, int x, int y) {
Jingning Han's avatar
Jingning Han committed
523 524 525 526 527 528 529 530 531
  const int is_q4 = precision == MV_PRECISION_Q4;
  const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
                     is_q4 ? src_mv->col : src_mv->col * 2 };
  MV32 mv = vp10_scale_mv(&mv_q4, x, y, sf);
  const int subpel_x = mv.col & SUBPEL_MASK;
  const int subpel_y = mv.row & SUBPEL_MASK;

  src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);

clang-format's avatar
clang-format committed
532 533
  inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y, sf, w,
                  h, ref, interp_filter, sf->x_step_q4, sf->y_step_q4);
Jingning Han's avatar
Jingning Han committed
534 535
}

536 537 538 539
void build_inter_predictors(MACROBLOCKD *xd, int plane,
#if CONFIG_OBMC
                            int mi_col_offset, int mi_row_offset,
#endif  // CONFIG_OBMC
clang-format's avatar
clang-format committed
540 541
                            int block, int bw, int bh, int x, int y, int w,
                            int h,
542 543 544
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
                            int wedge_offset_x, int wedge_offset_y,
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
545
                            int mi_x, int mi_y) {
Jingning Han's avatar
Jingning Han committed
546
  struct macroblockd_plane *const pd = &xd->plane[plane];
547 548 549
#if CONFIG_OBMC
  const MODE_INFO *mi = xd->mi[mi_col_offset + xd->mi_stride * mi_row_offset];
#else
Jingning Han's avatar
Jingning Han committed
550
  const MODE_INFO *mi = xd->mi[0];
551
#endif  // CONFIG_OBMC
Jingning Han's avatar
Jingning Han committed
552 553
  const int is_compound = has_second_ref(&mi->mbmi);
  int ref;
554 555 556 557 558
#if CONFIG_GLOBAL_MOTION
  Global_Motion_Params *gm[2];
  int is_global[2];
  for (ref = 0; ref < 1 + is_compound; ++ref) {
    gm[ref] = &xd->global_motion[mi->mbmi.ref_frame[ref]];
clang-format's avatar
clang-format committed
559 560
    is_global[ref] =
        (get_y_mode(mi, block) == ZEROMV && get_gmtype(gm[ref]) > GLOBAL_ZERO);
561 562
  }
  // TODO(sarahparker) remove these once gm works with all experiments
clang-format's avatar
clang-format committed
563 564
  (void)gm;
  (void)is_global;
565
#endif  // CONFIG_GLOBAL_MOTION
Jingning Han's avatar
Jingning Han committed
566

567 568
// TODO(sarahparker) enable the use of DUAL_FILTER in warped motion functions
// in order to allow GLOBAL_MOTION and DUAL_FILTER to work together
569 570
#if CONFIG_DUAL_FILTER
  if (mi->mbmi.sb_type < BLOCK_8X8 && plane > 0) {
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
    // block size in log2
    const int b4_wl = b_width_log2_lookup[mi->mbmi.sb_type];
    const int b4_hl = b_height_log2_lookup[mi->mbmi.sb_type];
    const int b8_sl = b_width_log2_lookup[BLOCK_8X8];

    // block size
    const int b4_w = 1 << b4_wl;
    const int b4_h = 1 << b4_hl;
    const int b8_s = 1 << b8_sl;
    int idx, idy;

    const int x_base = x;
    const int y_base = y;

    // processing unit size
    const int x_step = w >> (b8_sl - b4_wl);
    const int y_step = h >> (b8_sl - b4_hl);

    for (idy = 0; idy < b8_s; idy += b4_h) {
      for (idx = 0; idx < b8_s; idx += b4_w) {
        const int chr_idx = (idy * 2) + idx;
        for (ref = 0; ref < 1 + is_compound; ++ref) {
          const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
          struct buf_2d *const pre_buf = &pd->pre[ref];
          struct buf_2d *const dst_buf = &pd->dst;
          uint8_t *dst = dst_buf->buf;
          const MV mv = mi->bmi[chr_idx].as_mv[ref].as_mv;
          const MV mv_q4 = clamp_mv_to_umv_border_sb(
              xd, &mv, bw, bh, pd->subsampling_x, pd->subsampling_y);
          uint8_t *pre;
          MV32 scaled_mv;
          int xs, ys, subpel_x, subpel_y;
          const int is_scaled = vp10_is_scaled(sf);

          x = x_base + idx * x_step;
          y = y_base + idy * y_step;

          dst += dst_buf->stride * y + x;

          if (is_scaled) {
            pre =
                pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
            scaled_mv = vp10_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
            xs = sf->x_step_q4;
            ys = sf->y_step_q4;
          } else {
            pre = pre_buf->buf + y * pre_buf->stride + x;
            scaled_mv.row = mv_q4.row;
            scaled_mv.col = mv_q4.col;
            xs = ys = 16;
          }

          subpel_x = scaled_mv.col & SUBPEL_MASK;
          subpel_y = scaled_mv.row & SUBPEL_MASK;
          pre += (scaled_mv.row >> SUBPEL_BITS) * pre_buf->stride +
                 (scaled_mv.col >> SUBPEL_BITS);
627

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
#if CONFIG_EXT_INTER
          if (ref && is_interinter_wedge_used(mi->mbmi.sb_type) &&
              mi->mbmi.use_wedge_interinter)
            vp10_make_masked_inter_predictor(
                pre, pre_buf->stride, dst, dst_buf->stride, subpel_x, subpel_y,
                sf, w, h, mi->mbmi.interp_filter, xs, ys,
#if CONFIG_SUPERTX
                wedge_offset_x, wedge_offset_y,
#endif  // CONFIG_SUPERTX
                xd);
          else
#endif  // CONFIG_EXT_INTER
            vp10_make_inter_predictor(
                pre, pre_buf->stride, dst, dst_buf->stride, subpel_x, subpel_y,
                sf, x_step, y_step, ref, mi->mbmi.interp_filter, xs, ys, xd);
        }
644 645 646 647 648 649
      }
    }
    return;
  }
#endif

Jingning Han's avatar
Jingning Han committed
650 651 652 653 654 655
  for (ref = 0; ref < 1 + is_compound; ++ref) {
    const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
    struct buf_2d *const pre_buf = &pd->pre[ref];
    struct buf_2d *const dst_buf = &pd->dst;
    uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
    const MV mv = mi->mbmi.sb_type < BLOCK_8X8
clang-format's avatar
clang-format committed
656 657
                      ? average_split_mvs(pd, mi, ref, block)
                      : mi->mbmi.mv[ref].as_mv;
Jingning Han's avatar
Jingning Han committed
658 659 660 661 662 663

    // TODO(jkoleszar): This clamping is done in the incorrect place for the
    // scaling case. It needs to be done on the scaled MV, not the pre-scaling
    // MV. Note however that it performs the subsampling aware scaling so
    // that the result is always q4.
    // mv_precision precision is MV_PRECISION_Q4.
clang-format's avatar
clang-format committed
664 665
    const MV mv_q4 = clamp_mv_to_umv_border_sb(
        xd, &mv, bw, bh, pd->subsampling_x, pd->subsampling_y);
Jingning Han's avatar
Jingning Han committed
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682

    uint8_t *pre;
    MV32 scaled_mv;
    int xs, ys, subpel_x, subpel_y;
    const int is_scaled = vp10_is_scaled(sf);

    if (is_scaled) {
      pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
      scaled_mv = vp10_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
      xs = sf->x_step_q4;
      ys = sf->y_step_q4;
    } else {
      pre = pre_buf->buf + (y * pre_buf->stride + x);
      scaled_mv.row = mv_q4.row;
      scaled_mv.col = mv_q4.col;
      xs = ys = 16;
    }
683

Jingning Han's avatar
Jingning Han committed
684 685
    subpel_x = scaled_mv.col & SUBPEL_MASK;
    subpel_y = scaled_mv.row & SUBPEL_MASK;
clang-format's avatar
clang-format committed
686 687
    pre += (scaled_mv.row >> SUBPEL_BITS) * pre_buf->stride +
           (scaled_mv.col >> SUBPEL_BITS);
Jingning Han's avatar
Jingning Han committed
688

689
#if CONFIG_EXT_INTER
Debargha Mukherjee's avatar
Debargha Mukherjee committed
690
    if (ref && is_interinter_wedge_used(mi->mbmi.sb_type) &&
691
        mi->mbmi.use_wedge_interinter)
clang-format's avatar
clang-format committed
692 693 694
      vp10_make_masked_inter_predictor(pre, pre_buf->stride, dst,
                                       dst_buf->stride, subpel_x, subpel_y, sf,
                                       w, h, mi->mbmi.interp_filter, xs, ys,
695
#if CONFIG_SUPERTX
clang-format's avatar
clang-format committed
696
                                       wedge_offset_x, wedge_offset_y,
697
#endif  // CONFIG_SUPERTX
clang-format's avatar
clang-format committed
698
                                       xd);
699
    else
700 701 702 703 704 705 706 707 708 709 710 711 712
#else  // CONFIG_EXT_INTER
#if CONFIG_GLOBAL_MOTION
    if (is_global[ref])
      vp10_warp_plane(&(gm[ref]->motion_params),
#if CONFIG_VP9_HIGHBITDEPTH
                      xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd,
#endif  // CONFIG_VP9_HIGHBITDEPTH
                      pre_buf->buf0, pre_buf->width, pre_buf->height,
                      pre_buf->stride, dst, (mi_x >> pd->subsampling_x) + x,
                      (mi_y >> pd->subsampling_y) + y, w, h, dst_buf->stride,
                      pd->subsampling_x, pd->subsampling_y, xs, ys);
    else
#endif  // CONFIG_GLOBAL_MOTION
713 714 715
#endif  // CONFIG_EXT_INTER
      vp10_make_inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
                                subpel_x, subpel_y, sf, w, h, ref,
716
                                mi->mbmi.interp_filter, xs, ys, xd);
Jingning Han's avatar
Jingning Han committed
717 718 719
  }
}

clang-format's avatar
clang-format committed
720 721
void vp10_build_inter_predictor_sub8x8(MACROBLOCKD *xd, int plane, int i,
                                       int ir, int ic, int mi_row, int mi_col) {
722 723 724 725 726 727 728 729 730 731 732 733 734 735
  struct macroblockd_plane *const pd = &xd->plane[plane];
  MODE_INFO *const mi = xd->mi[0];
  const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
  const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
  const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];

  uint8_t *const dst = &pd->dst.buf[(ir * pd->dst.stride + ic) << 2];
  int ref;
  const int is_compound = has_second_ref(&mi->mbmi);

  for (ref = 0; ref < 1 + is_compound; ++ref) {
    const uint8_t *pre =
        &pd->pre[ref].buf[(ir * pd->pre[ref].stride + ic) << 2];
#if CONFIG_VP9_HIGHBITDEPTH
clang-format's avatar
clang-format committed
736 737 738 739 740 741 742 743 744 745 746 747 748
    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
      vp10_highbd_build_inter_predictor(
          pre, pd->pre[ref].stride, dst, pd->dst.stride,
          &mi->bmi[i].as_mv[ref].as_mv, &xd->block_refs[ref]->sf, width, height,
          ref, mi->mbmi.interp_filter, MV_PRECISION_Q3,
          mi_col * MI_SIZE + 4 * ic, mi_row * MI_SIZE + 4 * ir, xd->bd);
    } else {
      vp10_build_inter_predictor(
          pre, pd->pre[ref].stride, dst, pd->dst.stride,
          &mi->bmi[i].as_mv[ref].as_mv, &xd->block_refs[ref]->sf, width, height,
          ref, mi->mbmi.interp_filter, MV_PRECISION_Q3,
          mi_col * MI_SIZE + 4 * ic, mi_row * MI_SIZE + 4 * ir);
    }
749
#else
clang-format's avatar
clang-format committed
750 751 752 753 754
    vp10_build_inter_predictor(
        pre, pd->pre[ref].stride, dst, pd->dst.stride,
        &mi->bmi[i].as_mv[ref].as_mv, &xd->block_refs[ref]->sf, width, height,
        ref, mi->mbmi.interp_filter, MV_PRECISION_Q3, mi_col * MI_SIZE + 4 * ic,
        mi_row * MI_SIZE + 4 * ir);
755 756 757 758
#endif  // CONFIG_VP9_HIGHBITDEPTH
  }
}

Jingning Han's avatar
Jingning Han committed
759 760 761 762 763 764 765
static void build_inter_predictors_for_planes(MACROBLOCKD *xd, BLOCK_SIZE bsize,
                                              int mi_row, int mi_col,
                                              int plane_from, int plane_to) {
  int plane;
  const int mi_x = mi_col * MI_SIZE;
  const int mi_y = mi_row * MI_SIZE;
  for (plane = plane_from; plane <= plane_to; ++plane) {
766 767 768
    const struct macroblockd_plane *pd = &xd->plane[plane];
    const int bw = 4 * num_4x4_blocks_wide_lookup[bsize] >> pd->subsampling_x;
    const int bh = 4 * num_4x4_blocks_high_lookup[bsize] >> pd->subsampling_y;
Jingning Han's avatar
Jingning Han committed
769 770

    if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
771 772 773 774 775 776 777
      const PARTITION_TYPE bp = bsize - xd->mi[0]->mbmi.sb_type;
      const int have_vsplit = bp != PARTITION_HORZ;
      const int have_hsplit = bp != PARTITION_VERT;
      const int num_4x4_w = 2 >> ((!have_vsplit) | pd->subsampling_x);
      const int num_4x4_h = 2 >> ((!have_hsplit) | pd->subsampling_y);
      const int pw = 8 >> (have_vsplit | pd->subsampling_x);
      const int ph = 8 >> (have_hsplit | pd->subsampling_y);
778
      int x, y;
779
      assert(bp != PARTITION_NONE && bp < PARTITION_TYPES);
Jingning Han's avatar
Jingning Han committed
780
      assert(bsize == BLOCK_8X8);
781
      assert(pw * num_4x4_w == bw && ph * num_4x4_h == bh);
Jingning Han's avatar
Jingning Han committed
782 783
      for (y = 0; y < num_4x4_h; ++y)
        for (x = 0; x < num_4x4_w; ++x)
clang-format's avatar
clang-format committed
784
          build_inter_predictors(xd, plane,
785
#if CONFIG_OBMC
clang-format's avatar
clang-format committed
786
                                 0, 0,
787
#endif  // CONFIG_OBMC
clang-format's avatar
clang-format committed
788
                                 y * 2 + x, bw, bh, 4 * x, 4 * y, pw, ph,
789
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
clang-format's avatar
clang-format committed
790
                                 0, 0,
791
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
clang-format's avatar
clang-format committed
792
                                 mi_x, mi_y);
Jingning Han's avatar
Jingning Han committed
793
    } else {
794 795 796 797
      build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                             0, 0,
#endif  // CONFIG_OBMC
clang-format's avatar
clang-format committed
798
                             0, bw, bh, 0, 0, bw, bh,
799 800 801 802
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
                             0, 0,
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
                             mi_x, mi_y);
Jingning Han's avatar
Jingning Han committed
803 804 805 806 807
    }
  }
}

void vp10_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
clang-format's avatar
clang-format committed
808
                                     BLOCK_SIZE bsize) {
Jingning Han's avatar
Jingning Han committed
809
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
810 811
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
clang-format's avatar
clang-format committed
812 813
    vp10_build_interintra_predictors_sby(xd, xd->plane[0].dst.buf,
                                         xd->plane[0].dst.stride, bsize);
814
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
815 816 817
}

void vp10_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
818
                                     BLOCK_SIZE bsize, int plane) {
Jingning Han's avatar
Jingning Han committed
819
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, plane, plane);
820 821 822
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi)) {
    if (plane == 0) {
clang-format's avatar
clang-format committed
823 824
      vp10_build_interintra_predictors_sby(xd, xd->plane[0].dst.buf,
                                           xd->plane[0].dst.stride, bsize);
825
    } else {
clang-format's avatar
clang-format committed
826 827 828
      vp10_build_interintra_predictors_sbc(xd, xd->plane[plane].dst.buf,
                                           xd->plane[plane].dst.stride, plane,
                                           bsize);
829 830 831
    }
  }
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
832 833 834
}

void vp10_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
835
                                      BLOCK_SIZE bsize) {
Jingning Han's avatar
Jingning Han committed
836 837
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
                                    MAX_MB_PLANE - 1);
838 839
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
clang-format's avatar
clang-format committed
840 841 842
    vp10_build_interintra_predictors_sbuv(
        xd, xd->plane[1].dst.buf, xd->plane[2].dst.buf, xd->plane[1].dst.stride,
        xd->plane[2].dst.stride, bsize);
843
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
844 845 846
}

void vp10_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
clang-format's avatar
clang-format committed
847
                                    BLOCK_SIZE bsize) {
Jingning Han's avatar
Jingning Han committed
848 849
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
                                    MAX_MB_PLANE - 1);
850 851
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
clang-format's avatar
clang-format committed
852 853 854 855
    vp10_build_interintra_predictors(
        xd, xd->plane[0].dst.buf, xd->plane[1].dst.buf, xd->plane[2].dst.buf,
        xd->plane[0].dst.stride, xd->plane[1].dst.stride,
        xd->plane[2].dst.stride, bsize);
856
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
857 858 859
}

void vp10_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
clang-format's avatar
clang-format committed
860 861
                           const YV12_BUFFER_CONFIG *src, int mi_row,
                           int mi_col) {
Jingning Han's avatar
Jingning Han committed
862
  uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
clang-format's avatar
clang-format committed
863
                                           src->v_buffer };
864
  const int widths[MAX_MB_PLANE] = { src->y_crop_width, src->uv_crop_width,
clang-format's avatar
clang-format committed
865
                                     src->uv_crop_width };
866
  const int heights[MAX_MB_PLANE] = { src->y_crop_height, src->uv_crop_height,
clang-format's avatar
clang-format committed
867
                                      src->uv_crop_height };
Jingning Han's avatar
Jingning Han committed
868
  const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
clang-format's avatar
clang-format committed
869
                                      src->uv_stride };
Jingning Han's avatar
Jingning Han committed
870 871 872 873
  int i;

  for (i = 0; i < MAX_MB_PLANE; ++i) {
    struct macroblockd_plane *const pd = &planes[i];
clang-format's avatar
clang-format committed
874 875 876
    setup_pred_plane(&pd->dst, buffers[i], widths[i], heights[i], strides[i],
                     mi_row, mi_col, NULL, pd->subsampling_x,
                     pd->subsampling_y);
Jingning Han's avatar
Jingning Han committed
877 878 879 880
  }
}

void vp10_setup_pre_planes(MACROBLOCKD *xd, int idx,
clang-format's avatar
clang-format committed
881 882
                           const YV12_BUFFER_CONFIG *src, int mi_row,
                           int mi_col, const struct scale_factors *sf) {
Jingning Han's avatar
Jingning Han committed
883 884 885
  if (src != NULL) {
    int i;
    uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
clang-format's avatar
clang-format committed
886
                                             src->v_buffer };
887
    const int widths[MAX_MB_PLANE] = { src->y_crop_width, src->uv_crop_width,
clang-format's avatar
clang-format committed
888
                                       src->uv_crop_width };
889
    const int heights[MAX_MB_PLANE] = { src->y_crop_height, src->uv_crop_height,
clang-format's avatar
clang-format committed
890
                                        src->uv_crop_height };
Jingning Han's avatar
Jingning Han committed
891
    const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
clang-format's avatar
clang-format committed
892
                                        src->uv_stride };
Jingning Han's avatar
Jingning Han committed
893 894
    for (i = 0; i < MAX_MB_PLANE; ++i) {
      struct macroblockd_plane *const pd = &xd->plane[i];
clang-format's avatar
clang-format committed
895 896 897
      setup_pred_plane(&pd->pre[idx], buffers[i], widths[i], heights[i],
                       strides[i], mi_row, mi_col, sf, pd->subsampling_x,
                       pd->subsampling_y);
Jingning Han's avatar
Jingning Han committed
898 899 900
    }
  }
}
901 902

#if CONFIG_SUPERTX
clang-format's avatar
clang-format committed
903
static const uint8_t mask_8[8] = { 64, 64, 62, 52, 12, 2, 0, 0 };
904

clang-format's avatar
clang-format committed
905 906
static const uint8_t mask_16[16] = { 63, 62, 60, 58, 55, 50, 43, 36,
                                     28, 21, 14, 9,  6,  4,  2,  1 };
907

clang-format's avatar
clang-format committed
908 909 910
static const uint8_t mask_32[32] = { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 63,
                                     61, 57, 52, 45, 36, 28, 19, 12, 7,  3,  1,
                                     0,  0,  0,  0,  0,  0,  0,  0,  0,  0 };
911

clang-format's avatar
clang-format committed
912
static const uint8_t mask_8_uv[8] = { 64, 64, 62, 52, 12, 2, 0, 0 };
913

clang-format's avatar
clang-format committed
914 915
static const uint8_t mask_16_uv[16] = { 64, 64, 64, 64, 61, 53, 45, 36,
                                        28, 19, 11, 3,  0,  0,  0,  0 };
916

clang-format's avatar
clang-format committed
917 918 919 920
static const uint8_t mask_32_uv[32] = { 64, 64, 64, 64, 64, 64, 64, 64,
                                        64, 64, 64, 64, 60, 54, 46, 36,
                                        28, 18, 10, 4,  0,  0,  0,  0,
                                        0,  0,  0,  0,  0,  0,  0,  0 };
921

clang-format's avatar
clang-format committed
922
static const uint8_t *get_supertx_mask(int length, int plane) {
923
  switch (length) {
clang-format's avatar
clang-format committed
924 925 926 927
    case 8: return plane ? mask_8_uv : mask_8;
    case 16: return plane ? mask_16_uv : mask_16;
    case 32: return plane ? mask_32_uv : mask_32;
    default: assert(0);
928
  }
929
  return NULL;
930 931 932
}

void vp10_build_masked_inter_predictor_complex(
clang-format's avatar
clang-format committed
933 934 935 936
    MACROBLOCKD *xd, uint8_t *dst, int dst_stride, const uint8_t *pre,
    int pre_stride, int mi_row, int mi_col, int mi_row_ori, int mi_col_ori,
    BLOCK_SIZE bsize, BLOCK_SIZE top_bsize, PARTITION_TYPE partition,
    int plane) {
937
  const struct macroblockd_plane *pd = &xd->plane[plane];
938 939 940 941 942 943 944 945 946 947
  const int ssx = pd->subsampling_x;
  const int ssy = pd->subsampling_y;
  const int top_w = (4 << b_width_log2_lookup[top_bsize]) >> ssx;
  const int top_h = (4 << b_height_log2_lookup[top_bsize]) >> ssy;
  const int w = (4 << b_width_log2_lookup[bsize]) >> ssx;
  const int h = (4 << b_height_log2_lookup[bsize]) >> ssy;
  const int w_offset = ((mi_col - mi_col_ori) * MI_SIZE) >> ssx;
  const int h_offset = ((mi_row - mi_row_ori) * MI_SIZE) >> ssy;

  int w_remain, h_remain;
948 949

#if CONFIG_VP9_HIGHBITDEPTH
950
  const int is_hdb = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0;
951 952
#endif  // CONFIG_VP9_HIGHBITDEPTH

953
  assert(bsize <= BLOCK_32X32);
954 955
  assert(IMPLIES(plane == 0, ssx == 0));
  assert(IMPLIES(plane == 0, ssy == 0));
956 957

  switch (partition) {
958 959