reconinter.c 84.4 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
};

Debargha Mukherjee's avatar
Debargha Mukherjee committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
static const uint8_t *get_wedge_mask_inplace(const int *a,
                                             int neg,
                                             int h, int w) {
  const uint8_t *master;
  const int woff = (a[3] * w) >> 2;
  const int hoff = (a[4] * h) >> 2;
  if (!a) return NULL;
  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;
}

244
static const int *get_wedge_params(int wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
245
                                   BLOCK_SIZE sb_type) {
246
  const int *a = NULL;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
247
248
  if (wedge_index != WEDGE_NONE) {
    return get_wedge_params_lookup[sb_type] + WEDGE_PARMS * wedge_index;
249
250
251
252
253
  }
  return a;
}

const uint8_t *vp10_get_soft_mask(int wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
254
                                  int wedge_sign,
255
256
                                  BLOCK_SIZE sb_type,
                                  int h, int w) {
Debargha Mukherjee's avatar
Debargha Mukherjee committed
257
258
  const int *a = get_wedge_params(wedge_index, sb_type);
  return get_wedge_mask_inplace(a, wedge_sign, h, w);
259
260
261
}

#if CONFIG_SUPERTX
Debargha Mukherjee's avatar
Debargha Mukherjee committed
262
263
264
const uint8_t *get_soft_mask_extend(int wedge_index,
                                    int wedge_sign,
                                    int plane,
265
266
267
268
269
                                    BLOCK_SIZE sb_type,
                                    int wedge_offset_y,
                                    int wedge_offset_x) {
  int subh = (plane ? 2 : 4) << b_height_log2_lookup[sb_type];
  int subw = (plane ? 2 : 4) << b_width_log2_lookup[sb_type];
Debargha Mukherjee's avatar
Debargha Mukherjee committed
270
  const int *a = get_wedge_params(wedge_index, sb_type);
271
  if (a) {
Debargha Mukherjee's avatar
Debargha Mukherjee committed
272
    const uint8_t *mask = get_wedge_mask_inplace(a, wedge_sign, subh, subw);
273
274
275
276
277
278
279
280
281
282
    mask -= (wedge_offset_x + wedge_offset_y * MASK_MASTER_STRIDE);
    return mask;
  } else {
    return NULL;
  }
}

static void build_masked_compound_extend(uint8_t *dst, int dst_stride,
                                         uint8_t *dst2, int dst2_stride,
                                         int plane,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
283
284
285
                                         int wedge_index,
                                         int wedge_sign,
                                         BLOCK_SIZE sb_type,
286
287
288
289
                                         int wedge_offset_y, int wedge_offset_x,
                                         int h, int w) {
  int i, j;
  const uint8_t *mask = get_soft_mask_extend(
Debargha Mukherjee's avatar
Debargha Mukherjee committed
290
     wedge_index, wedge_sign, plane, sb_type, wedge_offset_y, wedge_offset_x);
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  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] = (dst[i * dst_stride + j] * m +
                                 dst2[i * dst2_stride + j] *
                                 ((1 << WEDGE_WEIGHT_BITS) - m) +
                                 (1 << (WEDGE_WEIGHT_BITS - 1))) >>
                                 WEDGE_WEIGHT_BITS;
    }
}

#if CONFIG_VP9_HIGHBITDEPTH
static void build_masked_compound_extend_highbd(
    uint8_t *dst_8, int dst_stride,
    uint8_t *dst2_8, int dst2_stride, int plane,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
306
    int wedge_index, int wedge_sign, BLOCK_SIZE sb_type,
307
308
309
310
    int wedge_offset_y, int wedge_offset_x,
    int h, int w) {
  int i, j;
  const uint8_t *mask = get_soft_mask_extend(
Debargha Mukherjee's avatar
Debargha Mukherjee committed
311
      wedge_index, wedge_sign, plane, sb_type, wedge_offset_y, wedge_offset_x);
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst_8);
  uint16_t *dst2 = CONVERT_TO_SHORTPTR(dst2_8);
  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] = (dst[i * dst_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

#else   // CONFIG_SUPERTX

static void build_masked_compound(uint8_t *dst, int dst_stride,
                                  uint8_t *dst2, int dst2_stride,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
330
331
                                  int wedge_index, int wedge_sign,
                                  BLOCK_SIZE sb_type,
332
333
                                  int h, int w) {
  int i, j;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
334
335
  const uint8_t *mask = vp10_get_soft_mask(wedge_index, wedge_sign,
                                           sb_type, h, w);
336
337
338
339
340
341
342
343
344
345
346
347
348
349
  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] = (dst[i * dst_stride + j] * m +
                                 dst2[i * dst2_stride + j] *
                                 ((1 << WEDGE_WEIGHT_BITS) - m) +
                                 (1 << (WEDGE_WEIGHT_BITS - 1))) >>
                                 WEDGE_WEIGHT_BITS;
    }
}

#if CONFIG_VP9_HIGHBITDEPTH
static void build_masked_compound_highbd(uint8_t *dst_8, int dst_stride,
                                         uint8_t *dst2_8, int dst2_stride,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
350
351
                                         int wedge_index, int wedge_sign,
                                         BLOCK_SIZE sb_type,
352
353
                                         int h, int w) {
  int i, j;
Debargha Mukherjee's avatar
Debargha Mukherjee committed
354
355
  const uint8_t *mask = vp10_get_soft_mask(wedge_index, wedge_sign,
                                           sb_type, h, w);
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
  uint16_t *dst = CONVERT_TO_SHORTPTR(dst_8);
  uint16_t *dst2 = CONVERT_TO_SHORTPTR(dst2_8);
  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] = (dst[i * dst_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
#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
    int plane, int wedge_offset_x, int wedge_offset_y,
#endif  // CONFIG_SUPERTX
    const MACROBLOCKD *xd) {
  const MODE_INFO *mi = xd->mi[0];
#if CONFIG_VP9_HIGHBITDEPTH
388
  DECLARE_ALIGNED(16, uint8_t, tmp_dst_[2 * MAX_SB_SQUARE]);
389
390
391
  uint8_t *tmp_dst =
      (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
      CONVERT_TO_BYTEPTR(tmp_dst_) : tmp_dst_;
392
  vp10_make_inter_predictor(pre, pre_stride, tmp_dst, MAX_SB_SIZE,
393
394
395
396
397
                            subpel_x, subpel_y, sf, w, h, 0,
                            interp_filter, xs, ys, xd);
#if CONFIG_SUPERTX
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
    build_masked_compound_extend_highbd(
398
        dst, dst_stride, tmp_dst, MAX_SB_SIZE, plane,
399
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
400
        mi->mbmi.interinter_wedge_sign,
401
402
403
404
        mi->mbmi.sb_type,
        wedge_offset_y, wedge_offset_x, h, w);
  else
    build_masked_compound_extend(
405
        dst, dst_stride, tmp_dst, MAX_SB_SIZE, plane,
406
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
407
        mi->mbmi.interinter_wedge_sign,
408
409
410
411
412
        mi->mbmi.sb_type,
        wedge_offset_y, wedge_offset_x, h, w);
#else
  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
    build_masked_compound_highbd(
413
        dst, dst_stride, tmp_dst, MAX_SB_SIZE,
414
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
415
        mi->mbmi.interinter_wedge_sign,
416
417
418
        mi->mbmi.sb_type, h, w);
  else
    build_masked_compound(
419
        dst, dst_stride, tmp_dst, MAX_SB_SIZE,
420
        mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
421
        mi->mbmi.interinter_wedge_sign,
422
423
424
        mi->mbmi.sb_type, h, w);
#endif  // CONFIG_SUPERTX
#else   // CONFIG_VP9_HIGHBITDEPTH
425
  DECLARE_ALIGNED(16, uint8_t, tmp_dst[MAX_SB_SQUARE]);
426
  vp10_make_inter_predictor(pre, pre_stride, tmp_dst, MAX_SB_SIZE,
427
428
429
430
                            subpel_x, subpel_y, sf, w, h, 0,
                            interp_filter, xs, ys, xd);
#if CONFIG_SUPERTX
  build_masked_compound_extend(
431
      dst, dst_stride, tmp_dst, MAX_SB_SIZE, plane,
432
      mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
433
      mi->mbmi.interinter_wedge_sign,
434
435
436
437
      mi->mbmi.sb_type,
      wedge_offset_y, wedge_offset_x, h, w);
#else
  build_masked_compound(
438
      dst, dst_stride, tmp_dst, MAX_SB_SIZE,
439
      mi->mbmi.interinter_wedge_index,
Debargha Mukherjee's avatar
Debargha Mukherjee committed
440
      mi->mbmi.interinter_wedge_sign,
441
442
443
444
445
      mi->mbmi.sb_type, h, w);
#endif  // CONFIG_SUPERTX
#endif  // CONFIG_VP9_HIGHBITDEPTH
}
#endif  // CONFIG_EXT_INTER
446

Jingning Han's avatar
Jingning Han committed
447
448
449
450
451
452
#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,
453
                                      const INTERP_FILTER interp_filter,
Jingning Han's avatar
Jingning Han committed
454
455
456
457
458
459
460
461
462
463
464
                                      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);

465
  highbd_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
466
467
                       sf, w, h, ref, interp_filter, sf->x_step_q4,
                       sf->y_step_q4, bd);
Jingning Han's avatar
Jingning Han committed
468
469
470
471
472
473
474
475
}
#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,
476
                               const INTERP_FILTER interp_filter,
Jingning Han's avatar
Jingning Han committed
477
478
479
480
481
482
483
484
485
486
487
488
                               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,
489
                  sf, w, h, ref, interp_filter, sf->x_step_q4, sf->y_step_q4);
Jingning Han's avatar
Jingning Han committed
490
491
}

492
493
494
495
496
void build_inter_predictors(MACROBLOCKD *xd, int plane,
#if CONFIG_OBMC
                            int mi_col_offset, int mi_row_offset,
#endif  // CONFIG_OBMC
                            int block,
497
498
                            int bw, int bh,
                            int x, int y, int w, int h,
499
500
501
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
                            int wedge_offset_x, int wedge_offset_y,
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
502
                            int mi_x, int mi_y) {
Jingning Han's avatar
Jingning Han committed
503
  struct macroblockd_plane *const pd = &xd->plane[plane];
504
505
506
#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
507
  const MODE_INFO *mi = xd->mi[0];
508
#endif  // CONFIG_OBMC
Jingning Han's avatar
Jingning Han committed
509
  const int is_compound = has_second_ref(&mi->mbmi);
510
  const INTERP_FILTER interp_filter = mi->mbmi.interp_filter;
Jingning Han's avatar
Jingning Han committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
  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;
    }
547

Jingning Han's avatar
Jingning Han committed
548
549
550
551
552
    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);

553
#if CONFIG_EXT_INTER
Debargha Mukherjee's avatar
Debargha Mukherjee committed
554
    if (ref && is_interinter_wedge_used(mi->mbmi.sb_type) &&
555
556
557
558
559
560
561
562
563
564
565
566
567
568
        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
          plane, 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, w, h, ref,
                                interp_filter, xs, ys, xd);
Jingning Han's avatar
Jingning Han committed
569
570
571
  }
}

572
573
574
575
576
577
578
579
580
581
582
583
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);
584
  const INTERP_FILTER interp_filter = mi->mbmi.interp_filter;
585
586
587
588
589
590
591
592
593
594

  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,
595
                                      ref, interp_filter, MV_PRECISION_Q3,
596
597
598
599
600
601
602
                                      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,
603
                               interp_filter, MV_PRECISION_Q3,
604
605
606
607
608
609
610
611
                               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,
612
                               interp_filter, MV_PRECISION_Q3,
613
614
615
616
617
618
                               mi_col * MI_SIZE + 4 * ic,
                               mi_row * MI_SIZE + 4 * ir);
#endif  // CONFIG_VP9_HIGHBITDEPTH
  }
}

Jingning Han's avatar
Jingning Han committed
619
620
621
622
623
624
625
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) {
626
627
628
    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
629
630

    if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
631
632
633
634
635
636
637
      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);
638
      int x, y;
639
      assert(bp != PARTITION_NONE && bp < PARTITION_TYPES);
Jingning Han's avatar
Jingning Han committed
640
      assert(bsize == BLOCK_8X8);
641
      assert(pw * num_4x4_w == bw && ph * num_4x4_h == bh);
Jingning Han's avatar
Jingning Han committed
642
643
      for (y = 0; y < num_4x4_h; ++y)
        for (x = 0; x < num_4x4_w; ++x)
644
645
646
647
648
           build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                                  0, 0,
#endif  // CONFIG_OBMC
                                  y * 2 + x, bw, bh,
649
650
651
652
653
                                  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
654
    } else {
655
656
657
658
659
      build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                             0, 0,
#endif  // CONFIG_OBMC
                             0, bw, bh,
660
661
662
663
664
                             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
665
666
667
668
669
670
671
    }
  }
}

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);
672
673
674
675
676
677
678
#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
679
680
681
}

void vp10_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
682
                                     BLOCK_SIZE bsize, int plane) {
Jingning Han's avatar
Jingning Han committed
683
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, plane, plane);
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
#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
699
700
701
}

void vp10_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
702
                                      BLOCK_SIZE bsize) {
Jingning Han's avatar
Jingning Han committed
703
704
  build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
                                    MAX_MB_PLANE - 1);
705
706
707
708
709
710
711
712
713
#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
714
715
716
717
718
719
}

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);
720
721
722
723
724
725
726
727
728
729
730
#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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
}

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);
    }
  }
}
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

#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,
    const struct macroblockd_plane *pd, 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) {
  int i, j;
817
818
819
820
821
822
823
  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;
824
825
826
827
828
829
830

#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

831
832
  assert(bsize <= BLOCK_32X32);

833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
  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
859
860
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
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
          }
          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
887
888
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
          }
          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
923
924
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
          }
          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
947
948
              dst_tmp[j] = ROUND_POWER_OF_TWO(dst_tmp[j] * m +
                                              dst2_tmp[j] * (64 - m), 6);
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
          }
            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;
}

966
967
968
969
970
971
972
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) {
973
974
975
976
977
978
979
980
  // 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;
981
982
983
984
#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
985
986
987
988
989
990
991
992
993
994
995
996
997

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

998
999
1000
1001
1002
    build_inter_predictors(xd, plane,
#if CONFIG_OBMC
                           0, 0,
#endif  // CONFIG_OBMC
                           block, bw, bh,
1003
                           0, 0, bw, bh,
1004
1005
1006
1007
#if CONFIG_EXT_INTER
                           wedge_offset_x >> (xd->plane[plane].subsampling_x),
                           wedge_offset_y >> (xd->plane[plane].subsampling_y),
#endif  // CONFIG_SUPERTX
1008
1009
                           mi_x, mi_y);
  }
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
#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
1021
}
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044

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
1045
      int x, y;
1046
1047
1048
1049
1050
1051
1052
1053
      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
1054
               y * 2 + x, bw, bh, 4 * x, 4 * y, 4, 4,
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
#if CONFIG_EXT_INTER
               wedge_offset_x >> (xd->plane[plane].subsampling_x),
               wedge_offset_y >> (xd->plane[plane].subsampling_y),
#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
          wedge_offset_x >> (xd->plane[plane].subsampling_x),
          wedge_offset_y >> (xd->plane[plane].subsampling_y),
#endif  // CONFIG_EXT_INTER
          mi_x, mi_y);
    }
  }
}
1075
#endif  // CONFIG_SUPERTX
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

#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] = {
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
    { 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] = {
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
    {
      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,
    }
1128
};
1129
1130
#endif  // CONFIG_EXT_PARTITION

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157

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;
1158
1159
1160
1161
1162
1163
#if CONFIG_EXT_PARTITION
    case 64:
      mask[0] = obmc_mask_64[0];
      mask[1] = obmc_mask_64[1];
      break;
#endif  // CONFIG_EXT_PARTITION
1164
    default:
1165
1166
      mask[0] = NULL;
      mask[1] = NULL;
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
      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;
1188
1189
1190
1191
1192
#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
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
#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
1222
  for (i = 0; above_available && i < VPXMIN(xd->n8_w, cm->mi_cols - mi_col);
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
       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]);

1234
    if (!is_neighbor_overlappable(above_mbmi))
1235
1236
      continue;

1237
    overlap = num_4x4_blocks_high_lookup[bsize] << 1;
1238
1239
1240

    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
      const struct macroblockd_plane *pd = &xd->plane[plane];
1241
      int bw = (mi_step * MI_SIZE) >> pd->subsampling_x;
1242
1243
1244
1245
      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 ?
1246
1247
          &final_buf[plane][(i * MI_SIZE) >> pd->subsampling_x] :
          &pd->dst.buf[(i * MI_SIZE) >> pd->subsampling_x];
1248
      int tmp_stride = tmp_stride1[plane];
1249
      uint8_t *tmp = &tmp_buf1[plane][(i * MI_SIZE) >> pd->subsampling_x];
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
      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) {
1260
          for (col = 0; col < bw; ++col)
1261
1262
1263
            dst16[col] = ROUND_POWER_OF_TWO(mask[0][row] * dst16[col] +
                                            mask[1][row] * tmp16[col], 6);

1264
1265
1266
1267
1268
1269
          dst16 += dst_stride;
          tmp16 += tmp_stride;
        }
      } else {
#endif  // CONFIG_VP9_HIGHBITDEPTH
      for (row = 0; row < bh; ++row) {
1270
        for (col = 0; col < bw; ++col)
1271
1272
          dst[col] = ROUND_POWER_OF_TWO(mask[0][row] * dst[col] +
                                        mask[1][row] * tmp[col], 6);
1273
1274
1275
1276
1277
1278
1279
1280
1281
        dst += dst_stride;
        tmp += tmp_stride;
      }
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }
  }  // each mi in the above row

1282
  if (mi_col == 0 || (mi_col - 1 < tile->mi_col_start))
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
    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]);

1297
    if (!is_neighbor_overlappable(left_mbmi))
1298
1299
      continue;

1300
    overlap = num_4x4_blocks_wide_lookup[bsize] << 1;
1301
1302
1303
1304

    for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
      const struct macroblockd_plane *pd = &xd->plane[plane];
      int bw = overlap >> pd->subsampling_x;
1305
      int bh = (mi_step * MI_SIZE) >> pd->subsampling_y;
1306
1307
1308
      int row, col;
      int dst_stride = use_tmp_dst_buf ? final_stride[plane] : pd->dst.stride;
      uint8_t *dst = use_tmp_dst_buf ?
1309
1310
          &final_buf[plane][(i * MI_SIZE * dst_stride) >> pd->subsampling_y] :
          &pd->dst.buf[(i * MI_SIZE * dst_stride) >> pd->subsampling_y];
1311
1312
      int tmp_stride = tmp_stride2[plane];
      uint8_t *tmp = &tmp_buf2[plane]
1313
                              [(i * MI_SIZE * tmp_stride) >> pd->subsampling_y];
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
      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) {
1324
          for (col = 0; col < bw; ++col)
1325
1326
            dst16[col] = ROUND_POWER_OF_TWO(mask[0][col] * dst16[col] +
                                            mask[1][col] * tmp16[col], 6);
1327
1328
1329
1330
1331
1332
          dst16 += dst_stride;
          tmp16 += tmp_stride;
        }
      } else {
#endif  // CONFIG_VP9_HIGHBITDEPTH
      for (row = 0; row < bh; ++row) {
1333
        for (col = 0; col < bw; ++col)
1334
1335
          dst[col] = ROUND_POWER_OF_TWO(mask[0][col] * dst[col] +
                                        mask[1][col] * tmp[col], 6);
1336
1337
1338
1339
1340
1341
1342
1343
1344
        dst += dst_stride;
        tmp += tmp_stride;
      }
#if CONFIG_VP9_HIGHBITDEPTH
      }
#endif  // CONFIG_VP9_HIGHBITDEPTH
    }
  }  // each mi in the left column
}
1345

Yue Chen's avatar
Yue Chen committed
1346
1347
1348
1349
#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
1350
  } else if (has_second_ref(mbmi) && is_interinter_wedge_used(mbmi->sb_type) &&
Yue Chen's avatar
Yue Chen committed
1351
1352
1353
1354
1355
1356
1357
1358
             mbmi->use_wedge_interinter) {
    mbmi->use_wedge_interinter = 0;
    mbmi->ref_frame[1] = NONE;
  }
  return;
}
#endif  // CONFIG_EXT_INTER

1359
1360
1361
1362
1363
void vp10_build_prediction_by_above_preds(VP10_COMMON *cm,
                                          MACROBLOCKD *xd,
                                          int mi_row, int mi_col,
                                          uint8_t *tmp_buf[MAX_MB_PLANE],
                                          int tmp_stride[MAX_MB_PLANE]) {
1364
1365
1366
#if CONFIG_EXT_TILE
  const TileInfo *const tile = &xd->tile;
#endif  // CONFIG_EXT_TILE
1367
1368
1369
  BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
  int i, j, mi_step, ref;

1370
1371
1372
#if CONFIG_EXT_TILE
  if (mi_row == 0 || (mi_row - 1) < tile->mi_row_start)
#else
1373
  if (mi_row == 0)
1374
#endif  // CONFIG_EXT_TILE
1375
1376
1377
1378
1379
1380
1381
1382
1383
    return;

  for (i = 0; i < VPXMIN(xd->n8_w, cm->mi_cols - mi_col); i += mi_step) {
    int mi_row_offset = -1;
    int mi_col_offset = i;
    int mi_x, mi_y, bw, bh;
    MODE_INFO *above_mi = xd->mi[mi_col_offset +
                                 mi_row_offset * xd->mi_stride];
    MB_MODE_INFO *above_mbmi = &above_mi->mbmi;
Yue Chen's avatar
Yue Chen committed
1384
1385
1386
#if CONFIG_EXT_INTER
    MB_MODE_INFO backup_mbmi;
#endif  // CONFIG_EXT_INTER
1387
1388
1389
1390
1391
1392
1393

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

    if (!is_neighbor_overlappable(above_mbmi))
      continue;

Yue Chen's avatar
Yue Chen committed
1394
1395
1396
1397
1398
#if CONFIG_EXT_INTER
    backup_mbmi = *above_mbmi;
    modify_neighbor_predictor_for_obmc(above_mbmi);
#endif  // CONFIG_EXT_INTER

1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
    for (j = 0; j < MAX_MB_PLANE; ++j) {
      struct macroblockd_plane *const pd = &xd->plane[j];
      setup_pred_plane(&pd->dst,
                       tmp_buf[j], tmp_stride[j],
                       0, i, NULL,
                       pd->subsampling_x, pd->subsampling_y);
    }
    for (ref = 0; ref < 1 + has_second_ref(above_mbmi); ++ref) {
      MV_REFERENCE_FRAME frame = above_mbmi->ref_frame[ref];
      RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];

      xd->block_refs[ref] = ref_buf;
      if ((!vp10_is_valid_scale(&ref_buf->sf)))
        vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM,
                           "Reference frame has invalid dimensions");
      vp10_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col + i,
                            &ref_buf->sf);
    }

    xd->mb_to_left_edge   = -(((mi_col + i) * MI_SIZE) * 8);
    mi_x = (mi_col + i) << MI_SIZE_LOG2;
    mi_y = mi_row << MI_SIZE_LOG2;

    for (j = 0; j < MAX_MB_PLANE; ++j) {
      const struct macroblockd_plane *pd = &xd->plane[j];
      bw = (mi_step * 8) >> pd->subsampling_x;
      bh = VPXMAX((num_4x4_blocks_high_lookup[bsize] * 2) >> pd->subsampling_y,
                  4);

      if (above_mbmi->sb_type < BLOCK_8X8) {
        const PARTITION_TYPE bp = BLOCK_8X8 - above_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);
        int x, y;

        for (y = 0; y < num_4x4_h; ++y)
          for (x = 0; x < num_4x4_w; ++x) {
            if ((bp == PARTITION_HORZ || bp == PARTITION_SPLIT)
                && y == 0 && !pd->subsampling_y)
              continue;

            build_inter_predictors(xd, j, mi_col_offset, mi_row_offset,
                                   y * 2 + x, bw, bh,
                                   4 * x, 0, pw, bh,
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
                                   0, 0,
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
                                   mi_x, mi_y);
          }
      } else {
        build_inter_predictors(xd, j, mi_col_offset, mi_row_offset,
                               0, bw, bh, 0, 0, bw, bh,
#if CONFIG_SUPERTX && CONFIG_EXT_INTER
                               0, 0,
#endif  // CONFIG_SUPERTX && CONFIG_EXT_INTER
                               mi_x, mi_y);
      }
    }
Yue Chen's avatar
Yue Chen committed
1460
1461
1462
#if CONFIG_EXT_INTER
    *above_mbmi = backup_mbmi;
#endif  // CONFIG_EXT_INTER
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
  }
  xd->mb_to_left_edge   = -((mi_col * MI_SIZE) * 8);
}

void vp10_build_prediction_by_left_preds(VP10_COMMON *cm,
                                         MACROBLOCKD *xd,
                                         int mi_row, int mi_col,
                                         uint8_t *tmp_buf[MAX_MB_PLANE],
                                         int tmp_stride[MAX_MB_PLANE]) {
  const TileInfo *const tile = &xd->tile;
  BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
  int i, j, mi_step, ref;

1476
  if (mi_col == 0 || (mi_col - 1 < tile->mi_col_start))
1477
1478
1479
1480
1481
1482
1483
1484
1485
    return;

  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 mi_x, mi_y, bw, bh;
    MODE_INFO *left_mi = xd->mi[mi_col_offset +
                                mi_row_offset * xd->mi_stride];
    MB_MODE_INFO *left_mbmi = &left_mi->mbmi;
Yue Chen's avatar
Yue Chen committed
1486
1487
1488
#if CONFIG_EXT_INTER
    MB_MODE_INFO backup_mbmi;
#endif  // CONFIG_EXT_INTER
1489
1490