reconinter.c 88.2 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 *  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"
#include "./vpx_config.h"

#include "vpx/vpx_integer.h"

18
19
20
#include "vp10/common/blockd.h"
#include "vp10/common/reconinter.h"
#include "vp10/common/reconintra.h"
21
22
23
#if CONFIG_OBMC
#include "vp10/common/onyxc_int.h"
#endif  // CONFIG_OBMC
Jingning Han's avatar
Jingning Han committed
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#if CONFIG_EXT_INTER
static int get_masked_weight(int m) {
  #define SMOOTHER_LEN  32
  static const uint8_t smoothfn[2 * SMOOTHER_LEN + 1] = {
    0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  1,  1,  1,
    1,  1,  2,  2,  3,  4,  5,  6,
    8,  9, 12, 14, 17, 21, 24, 28,
    32,
    36, 40, 43, 47, 50, 52, 55, 56,
    58, 59, 60, 61, 62, 62, 63, 63,
    63, 63, 63, 64, 64, 64, 64, 64,
    64, 64, 64, 64, 64, 64, 64, 64,
  };
  if (m < -SMOOTHER_LEN)
    return 0;
  else if (m > SMOOTHER_LEN)
    return (1 << WEDGE_WEIGHT_BITS);
  else
    return smoothfn[m + SMOOTHER_LEN];
}

Debargha Mukherjee's avatar
Debargha Mukherjee committed
47
48
49
50
51
#define WEDGE_OBLIQUE  1
#define WEDGE_STRAIGHT 0

#define WEDGE_PARMS    5

52
53
54
55
56
57
58
// [negative][transpose][reverse]
DECLARE_ALIGNED(16, static uint8_t,
                wedge_mask_obl[2][2][2][MASK_MASTER_SIZE * MASK_MASTER_SIZE]);
// [negative][transpose]
DECLARE_ALIGNED(16, static uint8_t,
                wedge_mask_str[2][2][MASK_MASTER_SIZE * MASK_MASTER_SIZE]);

Debargha Mukherjee's avatar
Debargha Mukherjee committed
59
// Equation of line: f(x, y) = a[0]*(x - a[2]*w/4) + a[1]*(y - a[3]*h/4) = 0
60
61
62
63
64
65
66
67
68
69
70
71
void vp10_init_wedge_masks() {
  int i, j;
  const int w = MASK_MASTER_SIZE;
  const int h = MASK_MASTER_SIZE;
  const int stride = MASK_MASTER_STRIDE;
  const int a[4] = {2, 1, 2, 2};
  for (i = 0; i < h; ++i)
    for (j = 0; j < w; ++j) {
      int x = (2 * j + 1 - (a[2] * w) / 2);
      int y = (2 * i + 1 - (a[3] * h) / 2);
      int m = (a[0] * x + a[1] * y) / 2;
      wedge_mask_obl[1][0][0][i * stride + j] =
Debargha Mukherjee's avatar
Debargha Mukherjee committed
72
73
74
75
      wedge_mask_obl[1][1][0][j * stride + i] =
          get_masked_weight(m);
      wedge_mask_obl[1][0][1][i * stride + w - 1 - j] =
      wedge_mask_obl[1][1][1][(w - 1 - j) * stride + i] =
76
          (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m);
Debargha Mukherjee's avatar
Debargha Mukherjee committed
77
78
79
80
81
82
      wedge_mask_obl[0][0][0][i * stride + j] =
      wedge_mask_obl[0][1][0][j * stride + i] =
          (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m);
      wedge_mask_obl[0][0][1][i * stride + w - 1 - j] =
      wedge_mask_obl[0][1][1][(w - 1 - j) * stride + i] =
          get_masked_weight(m);
83
      wedge_mask_str[1][0][i * stride + j] =
Debargha Mukherjee's avatar
Debargha Mukherjee committed
84
85
86
87
      wedge_mask_str[1][1][j * stride + i] =
          get_masked_weight(x);
      wedge_mask_str[0][0][i * stride + j] =
      wedge_mask_str[0][1][j * stride + i] =
88
89
90
91
          (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(x);
    }
}

Debargha Mukherjee's avatar
Debargha Mukherjee committed
92
93
94
95
96
97
98
static const int wedge_params_sml[1 << WEDGE_BITS_SML]
                                 [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},
};
99

Debargha Mukherjee's avatar
Debargha Mukherjee committed
100
101
102
103
104
105
106
107
108
109
110
static const int wedge_params_med_hgtw[1 << WEDGE_BITS_MED]
                                      [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},

    {WEDGE_OBLIQUE,  1, 1, 2, 1},
    {WEDGE_OBLIQUE,  1, 1, 2, 3},
    {WEDGE_OBLIQUE,  1, 0, 2, 1},
    {WEDGE_OBLIQUE,  1, 0, 2, 3},
111
112
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
113
114
115
116
117
118
119
120
121
122
123
static const int wedge_params_med_hltw[1 << WEDGE_BITS_MED]
                                      [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},

    {WEDGE_OBLIQUE,  0, 1, 1, 2},
    {WEDGE_OBLIQUE,  0, 1, 3, 2},
    {WEDGE_OBLIQUE,  0, 0, 1, 2},
    {WEDGE_OBLIQUE,  0, 0, 3, 2},
124
125
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
126
127
128
129
130
131
132
133
134
135
136
static const int wedge_params_med_heqw[1 << WEDGE_BITS_MED]
                                      [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},

    {WEDGE_STRAIGHT, 1, 0, 2, 1},
    {WEDGE_STRAIGHT, 1, 0, 2, 3},
    {WEDGE_STRAIGHT, 0, 0, 1, 2},
    {WEDGE_STRAIGHT, 0, 0, 3, 2},
137
138
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
static const int wedge_params_big_hgtw[1 << WEDGE_BITS_BIG]
                                      [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},

    {WEDGE_OBLIQUE,  1, 1, 2, 1},
    {WEDGE_OBLIQUE,  1, 1, 2, 3},
    {WEDGE_OBLIQUE,  1, 0, 2, 1},
    {WEDGE_OBLIQUE,  1, 0, 2, 3},

    {WEDGE_OBLIQUE,  0, 1, 1, 2},
    {WEDGE_OBLIQUE,  0, 1, 3, 2},
    {WEDGE_OBLIQUE,  0, 0, 1, 2},
    {WEDGE_OBLIQUE,  0, 0, 3, 2},

    {WEDGE_STRAIGHT, 1, 0, 2, 1},
    {WEDGE_STRAIGHT, 1, 0, 2, 2},
    {WEDGE_STRAIGHT, 1, 0, 2, 3},
    {WEDGE_STRAIGHT, 0, 0, 2, 2},
160
161
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
static const int wedge_params_big_hltw[1 << WEDGE_BITS_BIG]
                                      [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},

    {WEDGE_OBLIQUE,  1, 1, 2, 1},
    {WEDGE_OBLIQUE,  1, 1, 2, 3},
    {WEDGE_OBLIQUE,  1, 0, 2, 1},
    {WEDGE_OBLIQUE,  1, 0, 2, 3},

    {WEDGE_OBLIQUE,  0, 1, 1, 2},
    {WEDGE_OBLIQUE,  0, 1, 3, 2},
    {WEDGE_OBLIQUE,  0, 0, 1, 2},
    {WEDGE_OBLIQUE,  0, 0, 3, 2},

    {WEDGE_STRAIGHT, 0, 0, 1, 2},
    {WEDGE_STRAIGHT, 0, 0, 2, 2},
    {WEDGE_STRAIGHT, 0, 0, 3, 2},
    {WEDGE_STRAIGHT, 1, 0, 2, 2},
183
184
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
static const int wedge_params_big_heqw[1 << WEDGE_BITS_BIG]
                                      [WEDGE_PARMS] = {
    {WEDGE_OBLIQUE,  1, 1, 2, 2},
    {WEDGE_OBLIQUE,  1, 0, 2, 2},
    {WEDGE_OBLIQUE,  0, 1, 2, 2},
    {WEDGE_OBLIQUE,  0, 0, 2, 2},

    {WEDGE_OBLIQUE,  1, 1, 2, 1},
    {WEDGE_OBLIQUE,  1, 1, 2, 3},
    {WEDGE_OBLIQUE,  1, 0, 2, 1},
    {WEDGE_OBLIQUE,  1, 0, 2, 3},

    {WEDGE_OBLIQUE,  0, 1, 1, 2},
    {WEDGE_OBLIQUE,  0, 1, 3, 2},
    {WEDGE_OBLIQUE,  0, 0, 1, 2},
    {WEDGE_OBLIQUE,  0, 0, 3, 2},

    {WEDGE_STRAIGHT, 1, 0, 2, 1},
    {WEDGE_STRAIGHT, 1, 0, 2, 3},
    {WEDGE_STRAIGHT, 0, 0, 1, 2},
    {WEDGE_STRAIGHT, 0, 0, 3, 2},
206
207
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
static const int *get_wedge_params_lookup[BLOCK_SIZES] = {
  NULL,
  NULL,
  NULL,
  &wedge_params_sml[0][0],
  &wedge_params_med_hgtw[0][0],
  &wedge_params_med_hltw[0][0],
  &wedge_params_med_heqw[0][0],
  &wedge_params_med_hgtw[0][0],
  &wedge_params_med_hltw[0][0],
  &wedge_params_med_heqw[0][0],
  &wedge_params_big_hgtw[0][0],
  &wedge_params_big_hltw[0][0],
  &wedge_params_big_heqw[0][0],
#if CONFIG_EXT_PARTITION
  &wedge_params_big_hgtw[0][0],
  &wedge_params_big_hltw[0][0],
  &wedge_params_big_heqw[0][0],
#endif  // CONFIG_EXT_PARTITION
227
228
};

229
230
231
232
233
234
235
236
237
238
static const int *get_wedge_params(int wedge_index,
                                   BLOCK_SIZE sb_type) {
  const int *a = NULL;
  if (wedge_index != WEDGE_NONE) {
    return get_wedge_params_lookup[sb_type] + WEDGE_PARMS * wedge_index;
  }
  return a;
}

static const uint8_t *get_wedge_mask_inplace(int wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
239
                                             int neg,
240
                                             BLOCK_SIZE sb_type) {
Debargha Mukherjee's avatar
Debargha Mukherjee committed
241
  const uint8_t *master;
242
243
244
245
  const int bh = 4 << b_height_log2_lookup[sb_type];
  const int bw = 4 << b_width_log2_lookup[sb_type];
  const int *a = get_wedge_params(wedge_index, sb_type);
  int woff, hoff;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
246
  if (!a) return NULL;
247
248
  woff = (a[3] * bw) >> 2;
  hoff = (a[4] * bh) >> 2;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
249
250
251
252
253
254
255
256
  master = (a[0] ?
            wedge_mask_obl[neg][a[1]][a[2]] :
            wedge_mask_str[neg][a[1]]) +
      MASK_MASTER_STRIDE * (MASK_MASTER_SIZE / 2 - hoff) +
      MASK_MASTER_SIZE / 2 - woff;
  return master;
}

257
const uint8_t *vp10_get_soft_mask(int wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
258
                                  int wedge_sign,
259
                                  BLOCK_SIZE sb_type,
260
261
262
263
264
265
266
                                  int wedge_offset_x,
                                  int wedge_offset_y) {
  const uint8_t *mask =
      get_wedge_mask_inplace(wedge_index, wedge_sign, sb_type);
  if (mask)
    mask -= (wedge_offset_x + wedge_offset_y * MASK_MASTER_STRIDE);
  return mask;
267
268
}

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
static void build_masked_compound(uint8_t *dst, int dst_stride,
                                  uint8_t *dst1, int dst1_stride,
                                  uint8_t *dst2, int dst2_stride,
                                  const uint8_t *mask,
                                  int h, int w, int subh, int subw) {
  int i, j;
  if (subw == 0 && subh == 0) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = mask[i * MASK_MASTER_STRIDE + j];
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
  } else if (subw == 1 && subh == 1) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = (mask[(2 * i) * MASK_MASTER_STRIDE + (2 * j)] +
                 mask[(2 * i + 1) * MASK_MASTER_STRIDE + (2 * j)] +
                 mask[(2 * i) * MASK_MASTER_STRIDE + (2 * j + 1)] +
                 mask[(2 * i + 1) * MASK_MASTER_STRIDE + (2 * j + 1)] + 2) >> 2;
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
  } else if (subw == 1 && subh == 0) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = (mask[i * MASK_MASTER_STRIDE + (2 * j)] +
                 mask[i * MASK_MASTER_STRIDE + (2 * j + 1)] + 1) >> 1;
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
309
  } else {
310
311
312
313
314
315
316
317
318
319
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = (mask[(2 * i) * MASK_MASTER_STRIDE + j] +
                 mask[(2 * i + 1) * MASK_MASTER_STRIDE + j] + 1) >> 1;
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
320
321
322
  }
}

323
324
325
326
327
328
#if CONFIG_VP9_HIGHBITDEPTH
static void build_masked_compound_highbd(uint8_t *dst_8, int dst_stride,
                                         uint8_t *dst1_8, int dst1_stride,
                                         uint8_t *dst2_8, int dst2_stride,
                                         const uint8_t *mask,
                                         int h, int w, int subh, int subw) {
329
  int i, j;
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst_8);
  uint16_t *dst1 = CONVERT_TO_SHORTPTR(dst1_8);
  uint16_t *dst2 = CONVERT_TO_SHORTPTR(dst2_8);
  if (subw == 0 && subh == 0) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = mask[i * MASK_MASTER_STRIDE + j];
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
  } else if (subw == 1 && subh == 1) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = (mask[(2 * i) * MASK_MASTER_STRIDE + (2 * j)] +
                 mask[(2 * i + 1) * MASK_MASTER_STRIDE + (2 * j)] +
                 mask[(2 * i) * MASK_MASTER_STRIDE + (2 * j + 1)] +
                 mask[(2 * i + 1) * MASK_MASTER_STRIDE + (2 * j + 1)] + 2) >> 2;
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
  } else if (subw == 1 && subh == 0) {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = (mask[i * MASK_MASTER_STRIDE + (2 * j)] +
                 mask[i * MASK_MASTER_STRIDE + (2 * j + 1)] + 1) >> 1;
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
  } else {
    for (i = 0; i < h; ++i)
      for (j = 0; j < w; ++j) {
        int m = (mask[(2 * i) * MASK_MASTER_STRIDE + j] +
                 mask[(2 * i + 1) * MASK_MASTER_STRIDE + j] + 1) >> 1;
        dst[i * dst_stride + j] = (dst1[i * dst1_stride + j] * m +
                                   dst2[i * dst2_stride + j] *
                                   ((1 << WEDGE_WEIGHT_BITS) - m) +
                                   (1 << (WEDGE_WEIGHT_BITS - 1))) >>
            WEDGE_WEIGHT_BITS;
      }
  }
}
#endif  // CONFIG_VP9_HIGHBITDEPTH

#if CONFIG_SUPERTX
static void build_masked_compound_wedge_extend(
    uint8_t *dst, int dst_stride,
    uint8_t *dst2, int dst2_stride,
    int wedge_index,
    int wedge_sign,
    BLOCK_SIZE sb_type,
    int wedge_offset_x, int wedge_offset_y,
    int h, int w) {
  const int subh = (2 << b_height_log2_lookup[sb_type]) == h;
  const int subw = (2 << b_width_log2_lookup[sb_type]) == w;
  const uint8_t *mask = vp10_get_soft_mask(
     wedge_index, wedge_sign, sb_type, wedge_offset_x, wedge_offset_y);
  build_masked_compound(dst, dst_stride,
                        dst, dst_stride, dst2, dst2_stride, mask,
                        h, w, subh, subw);
398
399
400
}

#if CONFIG_VP9_HIGHBITDEPTH
401
static void build_masked_compound_wedge_extend_highbd(
402
    uint8_t *dst_8, int dst_stride,
403
404
405
406
    uint8_t *dst2_8, int dst2_stride,
    int wedge_index, int wedge_sign,
    BLOCK_SIZE sb_type,
    int wedge_offset_x, int wedge_offset_y,
407
    int h, int w) {
408
409
410
411
412
413
414
  const int subh = (2 << b_height_log2_lookup[sb_type]) == h;
  const int subw = (2 << b_width_log2_lookup[sb_type]) == w;
  const uint8_t *mask = vp10_get_soft_mask(
      wedge_index, wedge_sign, sb_type, wedge_offset_x, wedge_offset_y);
  build_masked_compound_highbd(dst_8, dst_stride,
                               dst_8, dst_stride, dst2_8, dst2_stride, mask,
                               h, w, subh, subw);
415
416
417
418
419
}
#endif  // CONFIG_VP9_HIGHBITDEPTH

#else   // CONFIG_SUPERTX

420
421
422
423
424
425
426
427
428
static void build_masked_compound_wedge(uint8_t *dst, int dst_stride,
                                        uint8_t *dst2, int dst2_stride,
                                        int wedge_index, int wedge_sign,
                                        BLOCK_SIZE sb_type,
                                        int h, int w) {
  // 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;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
429
  const uint8_t *mask = vp10_get_soft_mask(wedge_index, wedge_sign,
430
431
432
433
                                           sb_type, 0, 0);
  build_masked_compound(dst, dst_stride,
                        dst, dst_stride, dst2, dst2_stride, mask,
                        h, w, subh, subw);
434
435
436
}

#if CONFIG_VP9_HIGHBITDEPTH
437
438
439
440
441
442
443
444
445
static void build_masked_compound_wedge_highbd(uint8_t *dst_8, int dst_stride,
                                               uint8_t *dst2_8, int dst2_stride,
                                               int wedge_index, int wedge_sign,
                                               BLOCK_SIZE sb_type,
                                               int h, int w) {
  // 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;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
446
  const uint8_t *mask = vp10_get_soft_mask(wedge_index, wedge_sign,
447
448
449
450
                                           sb_type, 0, 0);
  build_masked_compound_highbd(dst_8, dst_stride,
                               dst_8, dst_stride, dst2_8, dst2_stride, mask,
                               h, w, subh, subw);
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
}
#endif  // CONFIG_VP9_HIGHBITDEPTH
#endif  // CONFIG_SUPERTX

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,
    const INTERP_FILTER interp_filter,
    int xs, int ys,
#if CONFIG_SUPERTX
467
    int wedge_offset_x, int wedge_offset_y,
468
469
470
471
#endif  // CONFIG_SUPERTX
    const MACROBLOCKD *xd) {
  const MODE_INFO *mi = xd->mi[0];
#if CONFIG_VP9_HIGHBITDEPTH
472
  DECLARE_ALIGNED(16, uint8_t, tmp_dst_[2 * MAX_SB_SQUARE]);
473
474
475
  uint8_t *tmp_dst =
      (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
      CONVERT_TO_BYTEPTR(tmp_dst_) : tmp_dst_;
476
  vp10_make_inter_predictor(pre, pre_stride, tmp_dst, MAX_SB_SIZE,
477
478
479
480
                            subpel_x, subpel_y, sf, w, h, 0,
                            interp_filter, xs, ys, xd);
#if CONFIG_SUPERTX
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
481
482
    build_masked_compound_wedge_extend_highbd(
        dst, dst_stride, tmp_dst, MAX_SB_SIZE,
483
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
484
        mi->mbmi.interinter_wedge_sign,
485
        mi->mbmi.sb_type,
486
        wedge_offset_x, wedge_offset_y, h, w);
487
  else
488
489
    build_masked_compound_wedge_extend(
        dst, dst_stride, tmp_dst, MAX_SB_SIZE,
490
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
491
        mi->mbmi.interinter_wedge_sign,
492
        mi->mbmi.sb_type,
493
        wedge_offset_x, wedge_offset_y, h, w);
494
495
#else
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
496
    build_masked_compound_wedge_highbd(
497
        dst, dst_stride, tmp_dst, MAX_SB_SIZE,
498
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
499
        mi->mbmi.interinter_wedge_sign,
500
501
        mi->mbmi.sb_type, h, w);
  else
502
    build_masked_compound_wedge(
503
        dst, dst_stride, tmp_dst, MAX_SB_SIZE,
504
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
505
        mi->mbmi.interinter_wedge_sign,
506
507
508
        mi->mbmi.sb_type, h, w);
#endif  // CONFIG_SUPERTX
#else   // CONFIG_VP9_HIGHBITDEPTH
509
  DECLARE_ALIGNED(16, uint8_t, tmp_dst[MAX_SB_SQUARE]);
510
  vp10_make_inter_predictor(pre, pre_stride, tmp_dst, MAX_SB_SIZE,
511
512
513
                            subpel_x, subpel_y, sf, w, h, 0,
                            interp_filter, xs, ys, xd);
#if CONFIG_SUPERTX
514
515
  build_masked_compound_wedge_extend(
      dst, dst_stride, tmp_dst, MAX_SB_SIZE,
516
      mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
517
      mi->mbmi.interinter_wedge_sign,
518
      mi->mbmi.sb_type,
519
      wedge_offset_x, wedge_offset_y, h, w);
520
#else
521
  build_masked_compound_wedge(
522
      dst, dst_stride, tmp_dst, MAX_SB_SIZE,
523
      mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
524
      mi->mbmi.interinter_wedge_sign,
525
526
527
528
529
      mi->mbmi.sb_type, h, w);
#endif  // CONFIG_SUPERTX
#endif  // CONFIG_VP9_HIGHBITDEPTH
}
#endif  // CONFIG_EXT_INTER
530

Jingning Han's avatar
Jingning Han committed
531
532
533
534
535
536
#if CONFIG_VP9_HIGHBITDEPTH
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,
537
                                      const INTERP_FILTER interp_filter,
Jingning Han's avatar
Jingning Han committed
538
539
540
541
542
543
544
545
546
547
548
                                      enum mv_precision precision,
                                      int x, int y, int bd) {
  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);

549
  highbd_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
550
551
                       sf, w, h, ref, interp_filter, sf->x_step_q4,
                       sf->y_step_q4, bd);
Jingning Han's avatar
Jingning Han committed
552
553
554
555
556
557
558
559
}
#endif  // CONFIG_VP9_HIGHBITDEPTH

void vp10_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,
560
                               const INTERP_FILTER interp_filter,
Jingning Han's avatar
Jingning Han committed
561
562
563
564
565
566
567
568
569
570
571
572
                               enum mv_precision precision,
                               int x, int y) {
  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);

  inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
573
                  sf, w, h, ref, interp_filter, sf->x_step_q4, sf->y_step_q4);
Jingning Han's avatar
Jingning Han committed
574
575
}

576
577
578
579
580
void build_inter_predictors(MACROBLOCKD *xd, int plane,
#if CONFIG_OBMC
                            int mi_col_offset, int mi_row_offset,
#endif  // CONFIG_OBMC
                            int block,
581
582
                            int bw, int bh,
                            int x, int y, int w, int h,
583
584
585
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
                            int wedge_offset_x, int wedge_offset_y,
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
586
                            int mi_x, int mi_y) {
Jingning Han's avatar
Jingning Han committed
587
  struct macroblockd_plane *const pd = &xd->plane[plane];
588
589
590
#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
591
  const MODE_INFO *mi = xd->mi[0];
592
#endif  // CONFIG_OBMC
Jingning Han's avatar
Jingning Han committed
593
  const int is_compound = has_second_ref(&mi->mbmi);
594
  const INTERP_FILTER interp_filter = mi->mbmi.interp_filter;
Jingning Han's avatar
Jingning Han committed
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
627
628
629
630
  int ref;

  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
               ? average_split_mvs(pd, mi, ref, block)
               : mi->mbmi.mv[ref].as_mv;

    // 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.
    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);

    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;
    }
631

Jingning Han's avatar
Jingning Han committed
632
633
634
635
636
    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);

637
#if CONFIG_EXT_INTER
Debargha Mukherjee's avatar
Debargha Mukherjee committed
638
    if (ref && is_interinter_wedge_used(mi->mbmi.sb_type) &&
639
640
641
642
643
644
        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,
          interp_filter, xs, ys,
#if CONFIG_SUPERTX
645
          wedge_offset_x, wedge_offset_y,
646
647
648
649
650
651
652
#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, w, h, ref,
                                interp_filter, xs, ys, xd);
Jingning Han's avatar
Jingning Han committed
653
654
655
  }
}

656
657
658
659
660
661
662
663
664
665
666
667
void vp10_build_inter_predictor_sub8x8(MACROBLOCKD *xd, int plane,
                                       int i, int ir, int ic,
                                       int mi_row, int mi_col) {
  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);
668
  const INTERP_FILTER interp_filter = mi->mbmi.interp_filter;
669
670
671
672
673
674
675
676
677
678

  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
  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,
679
                                      ref, interp_filter, MV_PRECISION_Q3,
680
681
682
683
684
685
686
                                      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,
687
                               interp_filter, MV_PRECISION_Q3,
688
689
690
691
692
693
694
695
                               mi_col * MI_SIZE + 4 * ic,
                               mi_row * MI_SIZE + 4 * ir);
  }
#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,
696
                               interp_filter, MV_PRECISION_Q3,
697
698
699
700
701
702
                               mi_col * MI_SIZE + 4 * ic,
                               mi_row * MI_SIZE + 4 * ir);
#endif  // CONFIG_VP9_HIGHBITDEPTH
  }
}

Jingning Han's avatar
Jingning Han committed
703
704
705
706
707
708
709
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) {
710
711
712
    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
713
714

    if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
715
716
717
718
719
720
721
      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);
722
      int x, y;
723
      assert(bp != PARTITION_NONE && bp < PARTITION_TYPES);
Jingning Han's avatar
Jingning Han committed
724
      assert(bsize == BLOCK_8X8);
725
      assert(pw * num_4x4_w == bw && ph * num_4x4_h == bh);
Jingning Han's avatar
Jingning Han committed
726
727
      for (y = 0; y < num_4x4_h; ++y)
        for (x = 0; x < num_4x4_w; ++x)
728
729
730
731
732
           build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                                  0, 0,
#endif  // CONFIG_OBMC
                                  y * 2 + x, bw, bh,
733
734
735
736
737
                                  4 * x, 4 * y, pw, ph,
#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
738
    } else {
739
740
741
742
743
      build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                             0, 0,
#endif  // CONFIG_OBMC
                             0, bw, bh,
744
745
746
747
748
                             0, 0, bw, bh,
#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
749
750
751
752
753
754
755
    }
  }
}

void vp10_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
                                    BLOCK_SIZE bsize) {
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
756
757
758
759
760
761
762
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
    vp10_build_interintra_predictors_sby(xd,
                                         xd->plane[0].dst.buf,
                                         xd->plane[0].dst.stride,
                                         bsize);
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
763
764
765
}

void vp10_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
766
                                     BLOCK_SIZE bsize, int plane) {
Jingning Han's avatar
Jingning Han committed
767
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, plane, plane);
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi)) {
    if (plane == 0) {
      vp10_build_interintra_predictors_sby(xd,
                                           xd->plane[0].dst.buf,
                                           xd->plane[0].dst.stride,
                                           bsize);
    } else {
      vp10_build_interintra_predictors_sbc(xd,
                                           xd->plane[plane].dst.buf,
                                           xd->plane[plane].dst.stride,
                                           plane, bsize);
    }
  }
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
783
784
785
}

void vp10_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
786
                                      BLOCK_SIZE bsize) {
Jingning Han's avatar
Jingning Han committed
787
788
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
                                    MAX_MB_PLANE - 1);
789
790
791
792
793
794
795
796
797
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
    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);
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
798
799
800
801
802
803
}

void vp10_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
                                   BLOCK_SIZE bsize) {
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
                                    MAX_MB_PLANE - 1);
804
805
806
807
808
809
810
811
812
813
814
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
    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);
#endif  // CONFIG_EXT_INTER
Jingning Han's avatar
Jingning Han committed
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
}

void vp10_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
                          const YV12_BUFFER_CONFIG *src,
                          int mi_row, int mi_col) {
  uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
      src->v_buffer};
  const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
      src->uv_stride};
  int i;

  for (i = 0; i < MAX_MB_PLANE; ++i) {
    struct macroblockd_plane *const pd = &planes[i];
    setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
                     pd->subsampling_x, pd->subsampling_y);
  }
}

void vp10_setup_pre_planes(MACROBLOCKD *xd, int idx,
                          const YV12_BUFFER_CONFIG *src,
                          int mi_row, int mi_col,
                          const struct scale_factors *sf) {
  if (src != NULL) {
    int i;
    uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
        src->v_buffer};
    const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
        src->uv_stride};
    for (i = 0; i < MAX_MB_PLANE; ++i) {
      struct macroblockd_plane *const pd = &xd->plane[i];
      setup_pred_plane(&pd->pre[idx], buffers[i], strides[i], mi_row, mi_col,
                       sf, pd->subsampling_x, pd->subsampling_y);
    }
  }
}
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896

#if CONFIG_SUPERTX
static const uint8_t mask_8[8] = {
  64, 64, 62, 52, 12,  2,  0,  0
};

static const uint8_t mask_16[16] = {
  63, 62, 60, 58, 55, 50, 43, 36, 28, 21, 14, 9, 6, 4, 2, 1
};

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
};

static const uint8_t mask_8_uv[8] = {
  64, 64, 62, 52,  12,  2,  0,  0
};

static const uint8_t mask_16_uv[16] = {
  64, 64, 64, 64, 61, 53, 45, 36, 28, 19, 11, 3, 0,  0,  0,  0
};

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
};

static void generate_1dmask(int length, uint8_t *mask, int plane) {
  switch (length) {
    case 8:
      memcpy(mask, plane ? mask_8_uv : mask_8, length);
      break;
    case 16:
      memcpy(mask, plane ? mask_16_uv : mask_16, length);
      break;
    case 32:
      memcpy(mask, plane ? mask_32_uv : mask_32, length);
      break;
    default:
      assert(0);
  }
}

void vp10_build_masked_inter_predictor_complex(
    MACROBLOCKD *xd,
    uint8_t *dst, int dst_stride, uint8_t *dst2, int dst2_stride,
897
    int mi_row, int mi_col,
898
899
900
    int mi_row_ori, int mi_col_ori, BLOCK_SIZE bsize, BLOCK_SIZE top_bsize,
    PARTITION_TYPE partition, int plane) {
  int i, j;
901
  const struct macroblockd_plane *pd = &xd->plane[plane];
902
903
904
905
906
907
908
  uint8_t mask[MAX_TX_SIZE];
  int top_w = 4 << b_width_log2_lookup[top_bsize];
  int top_h = 4 << b_height_log2_lookup[top_bsize];
  int w = 4 << b_width_log2_lookup[bsize];
  int h = 4 << b_height_log2_lookup[bsize];
  int w_offset = (mi_col - mi_col_ori) * MI_SIZE;
  int h_offset = (mi_row - mi_row_ori) * MI_SIZE;
909
910
911
912
913
914
915

#if CONFIG_VP9_HIGHBITDEPTH
  uint16_t *dst16= CONVERT_TO_SHORTPTR(dst);
  uint16_t *dst216 = CONVERT_TO_SHORTPTR(dst2);
  int b_hdb = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0;
#endif  // CONFIG_VP9_HIGHBITDEPTH

916
917
  assert(bsize <= BLOCK_32X32);

918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
  top_w >>= pd->subsampling_x;
  top_h >>= pd->subsampling_y;
  w >>= pd->subsampling_x;
  h >>= pd->subsampling_y;
  w_offset >>= pd->subsampling_x;
  h_offset >>= pd->subsampling_y;

  switch (partition) {
    case PARTITION_HORZ:
    {
#if CONFIG_VP9_HIGHBITDEPTH
      if (b_hdb) {
        uint16_t *dst_tmp = dst16 + h_offset * dst_stride;
        uint16_t *dst2_tmp = dst216 + h_offset * dst2_stride;
        generate_1dmask(h, mask + h_offset,
                        plane && xd->plane[plane].subsampling_y);

        for (i = h_offset; i < h_offset + h; i++) {
          for (j = 0; j < top_w; j++) {
            const int m = mask[i];  assert(m >= 0 && m <= 64);
            if (m == 64)
              continue;

            if (m == 0)
              dst_tmp[j] = dst2_tmp[j];
            else
944
945
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
          }
          dst_tmp += dst_stride;
          dst2_tmp += dst2_stride;
        }

        for (; i < top_h; i ++) {
          memcpy(dst_tmp, dst2_tmp, top_w * sizeof(uint16_t));
          dst_tmp += dst_stride;
          dst2_tmp += dst2_stride;
        }
      } else {
#endif  // CONFIG_VP9_HIGHBITDEPTH
        uint8_t *dst_tmp = dst + h_offset * dst_stride;
        uint8_t *dst2_tmp = dst2 + h_offset * dst2_stride;
        generate_1dmask(h, mask + h_offset,
                        plane && xd->plane[plane].subsampling_y);

        for (i = h_offset; i < h_offset + h; i++) {
          for (j = 0; j < top_w; j++) {
            const int m = mask[i];  assert(m >= 0 && m <= 64);
            if (m == 64)
              continue;

            if (m == 0)
              dst_tmp[j] = dst2_tmp[j];
            else
972
973
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
          }
          dst_tmp += dst_stride;
          dst2_tmp += dst2_stride;
        }

        for (; i < top_h; i ++) {
          memcpy(dst_tmp, dst2_tmp, top_w * sizeof(uint8_t));
          dst_tmp += dst_stride;
          dst2_tmp += dst2_stride;
        }
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }

      break;
    case PARTITION_VERT:
    {
#if CONFIG_VP9_HIGHBITDEPTH
      if (b_hdb) {
        uint16_t *dst_tmp = dst16;
        uint16_t *dst2_tmp = dst216;
        generate_1dmask(w, mask + w_offset,
                        plane && xd->plane[plane].subsampling_x);

        for (i = 0; i < top_h; i++) {
          for (j = w_offset; j < w_offset + w; j++) {
            const int m = mask[j];   assert(m >= 0 && m <= 64);
            if (m == 64)
              continue;

            if (m == 0)
              dst_tmp[j] = dst2_tmp[j];
            else
1008
1009
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
          }
          memcpy(dst_tmp + j, dst2_tmp + j,
                     (top_w - w_offset - w) * sizeof(uint16_t));
          dst_tmp += dst_stride;
          dst2_tmp += dst2_stride;
        }
      } else {
#endif  // CONFIG_VP9_HIGHBITDEPTH
        uint8_t *dst_tmp = dst;
        uint8_t *dst2_tmp = dst2;
        generate_1dmask(w, mask + w_offset,
                        plane && xd->plane[plane].subsampling_x);

        for (i = 0; i < top_h; i++) {
          for (j = w_offset; j < w_offset + w; j++) {
            const int m = mask[j];   assert(m >= 0 && m <= 64);
            if (m == 64)
              continue;

            if (m == 0)
              dst_tmp[j] = dst2_tmp[j];
            else
1032
1033
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
          }
            memcpy(dst_tmp + j, dst2_tmp + j,
                       (top_w - w_offset - w) * sizeof(uint8_t));
          dst_tmp += dst_stride;
          dst2_tmp += dst2_stride;
        }
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }
      break;
    default:
      assert(0);
  }
  (void) xd;
}

1051
1052
1053
1054
1055
1056
1057
void vp10_build_inter_predictors_sb_sub8x8_extend(
    MACROBLOCKD *xd,
#if CONFIG_EXT_INTER
    int mi_row_ori, int mi_col_ori,
#endif  // CONFIG_EXT_INTER
    int mi_row, int mi_col,
    BLOCK_SIZE bsize, int block) {
1058
1059
1060
1061
1062
1063
1064
1065
  // Prediction function used in supertx:
  // Use the mv at current block (which is less than 8x8)
  // to get prediction of a block located at (mi_row, mi_col) at size of bsize
  // bsize can be larger than 8x8.
  // block (0-3): the sub8x8 location of current block
  int plane;
  const int mi_x = mi_col * MI_SIZE;
  const int mi_y = mi_row * MI_SIZE;
1066
1067
1068
1069
#if CONFIG_EXT_INTER
  const int wedge_offset_x = (mi_col_ori - mi_col) * MI_SIZE;
  const int wedge_offset_y = (mi_row_ori - mi_row) * MI_SIZE;
#endif  // CONFIG_EXT_INTER
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

  // For sub8x8 uv:
  // Skip uv prediction in supertx except the first block (block = 0)
  int max_plane = block ? 1 : MAX_MB_PLANE;

  for (plane = 0; plane < max_plane; plane++) {
    const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
                                                        &xd->plane[plane]);
    const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
    const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
    const int bw = 4 * num_4x4_w;
    const int bh = 4 * num_4x4_h;

1083
1084
1085
1086
1087
    build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                           0, 0,
#endif  // CONFIG_OBMC
                           block, bw, bh,
1088
                           0, 0, bw, bh,
1089
#if CONFIG_EXT_INTER
1090
1091
                           wedge_offset_x,
                           wedge_offset_y,
1092
#endif  // CONFIG_SUPERTX
1093
1094
                           mi_x, mi_y);
  }
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
#if CONFIG_EXT_INTER
  if (is_interintra_pred(&xd->mi[0]->mbmi))
    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);
#endif  // CONFIG_EXT_INTER
1106
}
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129

void vp10_build_inter_predictors_sb_extend(MACROBLOCKD *xd,
#if CONFIG_EXT_INTER
                                           int mi_row_ori, int mi_col_ori,
#endif  // CONFIG_EXT_INTER
                                           int mi_row, int mi_col,
                                           BLOCK_SIZE bsize) {
  int plane;
  const int mi_x = mi_col * MI_SIZE;
  const int mi_y = mi_row * MI_SIZE;
#if CONFIG_EXT_INTER
  const int wedge_offset_x = (mi_col_ori - mi_col) * MI_SIZE;
  const int wedge_offset_y = (mi_row_ori - mi_row) * MI_SIZE;
#endif  // CONFIG_EXT_INTER
  for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
    const BLOCK_SIZE plane_bsize = get_plane_block_size(
        bsize, &xd->plane[plane]);
    const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
    const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
    const int bw = 4 * num_4x4_w;
    const int bh = 4 * num_4x4_h;

    if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
Julia Robson's avatar
Julia Robson committed
1130
      int x, y;
1131
1132
1133
1134
1135
1136
1137
1138
      assert(bsize == BLOCK_8X8);
      for (y = 0; y < num_4x4_h; ++y)
        for (x = 0; x < num_4x4_w; ++x)
           build_inter_predictors(
               xd, plane,
#if CONFIG_OBMC
               0, 0,
#endif  // CONFIG_OBMC
Julia Robson's avatar
Julia Robson committed
1139
               y * 2 + x, bw, bh, 4 * x, 4 * y, 4, 4,
1140
#if CONFIG_EXT_INTER
1141
1142
               wedge_offset_x,
               wedge_offset_y,
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
#endif  // CONFIG_EXT_INTER
               mi_x, mi_y);
    } else {
      build_inter_predictors(
          xd, plane,
#if CONFIG_OBMC
          0, 0,
#endif  // CONFIG_OBMC
          0, bw, bh, 0, 0, bw, bh,
#if CONFIG_EXT_INTER
1153
1154
          wedge_offset_x,
          wedge_offset_y,
1155
1156
1157
1158
1159
#endif  // CONFIG_EXT_INTER
          mi_x, mi_y);
    }
  }
}
1160
#endif  // CONFIG_SUPERTX
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189

#if CONFIG_OBMC
// obmc_mask_N[is_neighbor_predictor][overlap_position]
static const uint8_t obmc_mask_1[2][1] = {
    { 55},
    {  9}
};

static const uint8_t obmc_mask_2[2][2] = {
    { 45, 62},
    { 19,  2}
};

static const uint8_t obmc_mask_4[2][4] = {
    { 39, 50, 59, 64},
    { 25, 14,  5,  0}
};

static const uint8_t obmc_mask_8[2][8] = {
    { 36, 42, 48, 53, 57, 61, 63, 64},
    { 28, 22, 16, 11,  7,  3,  1,  0}
};

static const uint8_t obmc_mask_16[2][16] = {
    { 34, 37, 40, 43, 46, 49, 52, 54, 56, 58, 60, 61, 63, 64, 64, 64},
    { 30, 27, 24, 21, 18, 15, 12, 10,  8,  6,  4,  3,  1,  0,  0,  0}
};

static const uint8_t obmc_mask_32[2][32] = {
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
    { 33, 35, 36, 38, 40, 41, 43, 44,
      45, 47, 48, 50, 51, 52, 53, 55,
      56, 57, 58, 59, 60, 60, 61, 62,
      62, 63, 63, 64, 64, 64, 64, 64 },
    { 31, 29, 28, 26, 24, 23, 21, 20,
      19, 17, 16, 14, 13, 12, 11,  9,
       8,  7,  6,  5,  4,  4,  3,  2,
       2,  1,  1,  0,  0,  0,  0,  0 }
};

#if CONFIG_EXT_PARTITION
static const uint8_t obmc_mask_64[2][64] = {
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
    {
      33, 34, 35, 35, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 44, 44,
      45, 46, 47, 47, 48, 49, 50, 51, 51, 51, 52, 52, 53, 54, 55, 56,
      56, 56, 57, 57, 58, 58, 59, 60, 60, 60, 60, 60, 61, 62, 62, 62,
      62, 62, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
    }, {
      31, 30, 29, 29, 28, 27, 26, 25, 24, 24, 23, 22, 21, 20, 20, 20,
      19, 18, 17, 17, 16, 15, 14, 13, 13, 13, 12, 12, 11, 10,  9,  8,
      8,  8,  7,  7,  6,  6,  5, 4,  4,  4,  4,  4,  3,  2,  2,  2,
      2,  2,  1,  1, 1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    }
1213
};
1214
1215
#endif  // CONFIG_EXT_PARTITION

1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242

void setup_obmc_mask(int length, const uint8_t *mask[2]) {
  switch (length) {
    case 1:
      mask[0] = obmc_mask_1[0];
      mask[1] = obmc_mask_1[1];
      break;
    case 2:
      mask[0] = obmc_mask_2[0];
      mask[1] = obmc_mask_2[1];
      break;
    case 4:
      mask[0] = obmc_mask_4[0];
      mask[1] = obmc_mask_4[1];
      break;
    case 8:
      mask[0] = obmc_mask_8[0];
      mask[1] = obmc_mask_8[1];
      break;
    case 16:
      mask[0] = obmc_mask_16[0];
      mask[1] = obmc_mask_16[1];
      break;
    case 32:
      mask[0] = obmc_mask_32[0];
      mask[1] = obmc_mask_32[1];
      break;
1243
1244
1245
1246
1247
1248
#if CONFIG_EXT_PARTITION
    case 64:
      mask[0] = obmc_mask_64[0];
      mask[1] = obmc_mask_64[1];
      break;
#endif  // CONFIG_EXT_PARTITION
1249
    default:
1250
1251
      mask[0] = NULL;
      mask[1] = NULL;
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
      assert(0);
      break;
  }
}

// This function combines motion compensated predictions that is generated by
// top/left neighboring blocks' inter predictors with the regular inter
// prediction. We assume the original prediction (bmc) is stored in
// xd->plane[].dst.buf
void vp10_build_obmc_inter_prediction(VP10_COMMON *cm,
                                      MACROBLOCKD *xd, int mi_row, int mi_col,
                                      int use_tmp_dst_buf,
                                      uint8_t *final_buf[MAX_MB_PLANE],
                                      int final_stride[MAX_MB_PLANE],
                                      uint8_t *tmp_buf1[MAX_MB_PLANE],
                                      int tmp_stride1[MAX_MB_PLANE],
                                      uint8_t *tmp_buf2[MAX_MB_PLANE],
                                      int tmp_stride2[MAX_MB_PLANE]) {
  const TileInfo *const tile = &xd->tile;
  BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
  int plane, i, mi_step;
1273
1274
1275
1276
1277
#if CONFIG_EXT_TILE
  int above_available = mi_row > 0 && (mi_row - 1 >= tile->mi_row_start);
#else
  int above_available = mi_row > 0;
#endif  // CONFIG_EXT_TILE
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
#if CONFIG_VP9_HIGHBITDEPTH
  int is_hbd = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0;
#endif  // CONFIG_VP9_HIGHBITDEPTH

  if (use_tmp_dst_buf) {
    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
      const struct macroblockd_plane *pd = &xd->plane[plane];
      int bw = (xd->n8_w * 8) >> pd->subsampling_x;
      int bh = (xd->n8_h * 8) >> pd->subsampling_y;
      int row;
#if CONFIG_VP9_HIGHBITDEPTH
      if (is_hbd) {
        uint16_t *final_buf16 = CONVERT_TO_SHORTPTR(final_buf[plane]);
        uint16_t *bmc_buf16 = CONVERT_TO_SHORTPTR(pd->dst.buf);
        for (row = 0; row < bh; ++row)
          memcpy(final_buf16 + row * final_stride[plane],
                 bmc_buf16 + row * pd->dst.stride, bw * sizeof(uint16_t));
      } else {
#endif
      for (row = 0; row < bh; ++row)
        memcpy(final_buf[plane] + row * final_stride[plane],
               pd->dst.buf + row * pd->dst.stride, bw);
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }
  }

  // handle above row
1307
  for (i = 0; above_available && i < VPXMIN(xd->n8_w, cm->mi_cols - mi_col);
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
       i += mi_step) {
    int mi_row_offset = -1;
    int mi_col_offset = i;
    int overlap;
    MODE_INFO *above_mi = xd->mi[mi_col_offset +
                                 mi_row_offset * xd->mi_stride];
    MB_MODE_INFO *above_mbmi = &above_mi->mbmi;

    mi_step = VPXMIN(xd->n8_w,
                     num_8x8_blocks_wide_lookup[above_mbmi->sb_type]);

1319
    if (!is_neighbor_overlappable(above_mbmi))
1320
1321
      continue;

1322
    overlap = num_4x4_blocks_high_lookup[bsize] << 1;
1323
1324
1325

    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
      const struct macroblockd_plane *pd = &xd->plane[plane];
1326
      int bw = (mi_step * MI_SIZE) >> pd->subsampling_x;
1327
1328
1329
1330
      int bh = overlap >> pd->subsampling_y;
      int row, col;
      int dst_stride = use_tmp_dst_buf ? final_stride[plane] : pd->dst.stride;
      uint8_t *dst = use_tmp_dst_buf ?
1331
1332
          &final_buf[plane][(i * MI_SIZE) >> pd->subsampling_x] :
          &pd->dst.buf[(i * MI_SIZE) >> pd->subsampling_x];
1333
      int tmp_stride = tmp_stride1[plane];
1334
      uint8_t *tmp = &tmp_buf1[plane][(i * MI_SIZE) >> pd->subsampling_x];
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
      const uint8_t *mask[2];

      setup_obmc_mask(bh, mask);

#if CONFIG_VP9_HIGHBITDEPTH
      if (is_hbd) {
        uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
        uint16_t *tmp16 = CONVERT_TO_SHORTPTR(tmp);

        for (row = 0; row < bh; ++row) {
1345
          for (col = 0; col < bw; ++col)
1346
1347
1348
            dst16[col] = ROUND_POWER_OF_TWO(mask[0][row] * dst16[col] +
                                            mask[1][row] * tmp16[col], 6);

1349
1350
1351
1352
1353
1354
          dst16 += dst_stride;
          tmp16 += tmp_stride;
        }
      } else {
#endif  // CONFIG_VP9_HIGHBITDEPTH
      for (row = 0; row < bh; ++row) {
1355
        for (col = 0; col < bw; ++col)
1356
1357
          dst[col] = ROUND_POWER_OF_TWO(mask[0][row] * dst[col] +
                                        mask[1][row] * tmp[col], 6);
1358
1359
1360
1361
1362
1363
1364
1365
1366
        dst += dst_stride;
        tmp += tmp_stride;
      }
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }
  }  // each mi in the above row

1367
  if (mi_col == 0 || (mi_col - 1 < tile->mi_col_start))
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
    return;
  // handle left column
  for (i = 0; i < VPXMIN(xd->n8_h, cm->mi_rows - mi_row);
       i += mi_step) {
    int mi_row_offset = i;
    int mi_col_offset = -1;
    int overlap;
    MODE_INFO *left_mi = xd->mi[mi_col_offset +
                                mi_row_offset * xd->mi_stride];
    MB_MODE_INFO *left_mbmi = &left_mi->mbmi;

    mi_step = VPXMIN(xd->n8_h,
                     num_8x8_blocks_high_lookup[left_mbmi->sb_type]);

1382
    if (!is_neighbor_overlappable(left_mbmi))
1383
1384
      continue;

1385
    overlap = num_4x4_blocks_wide_lookup[bsize] << 1;
1386
1387
1388
1389

    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
      const struct macroblockd_plane *pd = &xd->plane[plane];
      int bw = overlap >> pd->subsampling_x;
1390
      int bh = (mi_step * MI_SIZE) >> pd->subsampling_y;
1391
1392
1393
      int row, col;
      int dst_stride = use_tmp_dst_buf ? final_stride[plane] : pd->dst.stride;
      uint8_t *dst = use_tmp_dst_buf ?
1394
1395
          &final_buf[plane][(i * MI_SIZE * dst_stride) >> pd->subsampling_y] :
          &pd->dst.buf[(i * MI_SIZE * dst_stride) >> pd->subsampling_y];
1396
1397
      int tmp_stride = tmp_stride2[plane];
      uint8_t *tmp = &tmp_buf2[plane]
1398
                              [(i * MI_SIZE * tmp_stride) >> pd->subsampling_y];
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
      const uint8_t *mask[2];

      setup_obmc_mask(bw, mask);

#if CONFIG_VP9_HIGHBITDEPTH
      if (is_hbd) {
        uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
        uint16_t *tmp16 = CONVERT_TO_SHORTPTR(tmp);

        for (row = 0; row < bh; ++row) {
1409
          for (col = 0; col < bw; ++col)
1410
1411
            dst16[col] = ROUND_POWER_OF_TWO(mask[0][col] * dst16[col] +
                                            mask[1][col] * tmp16[col], 6);
1412
1413
1414
1415
1416
1417
          dst16 += dst_stride;
          tmp16 += tmp_stride;
        }
      } else {
#endif  // CONFIG_VP9_HIGHBITDEPTH
      for (row = 0; row < bh; ++row) {
1418
        for (col = 0; col < bw; ++col)
1419
1420
          dst[col] = ROUND_POWER_OF_TWO(mask[0][col] * dst[col] +
                                        mask[1][col] * tmp[col], 6);
1421
1422
1423
1424
1425
1426
1427
1428
1429
        dst += dst_stride;
        tmp += tmp_stride;
      }
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }
  }  // each mi in the left column
}
1430

Yue Chen's avatar
Yue Chen committed
1431
1432
1433
1434
#if CONFIG_EXT_INTER
void modify_neighbor_predictor_for_obmc(MB_MODE_INFO *mbmi) {
  if (is_interintra_pred(mbmi)) {
    mbmi->ref_frame[1] = NONE;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
1435
  } else if (has_second_ref(mbmi) && is_interinter_wedge_used(mbmi->sb_type) &&
Yue Chen's avatar
Yue Chen committed
1436
1437
1438
1439
1440
1441
1442