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

11
#include <assert.h>
John Koleszar's avatar
John Koleszar committed
12

13
#include "./vpx_config.h"
14
#include "vpx/vpx_integer.h"
15
#include "vp9/common/vp9_blockd.h"
16
#include "vp9/common/vp9_filter.h"
17
#include "vp9/common/vp9_reconinter.h"
18
#include "vp9/common/vp9_reconintra.h"
John Koleszar's avatar
John Koleszar committed
19

20
void vp9_setup_interp_filters(MACROBLOCKD *xd,
21
                              INTERPOLATIONFILTERTYPE mcomp_filter_type,
22
                              VP9_COMMON *cm) {
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  // TODO(agrange): Investigate the best choice of functions to use here
  // for EIGHTTAP_SMOOTH. Since it is not interpolating, need to choose what
  // to do at full-pel offsets. The current selection, where the filter is
  // applied in one direction only, and not at all for 0,0, seems to give the
  // best quality, but it may be worth trying an additional mode that does
  // do the filtering on full-pel.
  xd->subpix.predict[0][0][0] = vp9_convolve_copy;
  xd->subpix.predict[0][0][1] = vp9_convolve_avg;
  xd->subpix.predict[0][1][0] = vp9_convolve8_vert;
  xd->subpix.predict[0][1][1] = vp9_convolve8_avg_vert;
  xd->subpix.predict[1][0][0] = vp9_convolve8_horiz;
  xd->subpix.predict[1][0][1] = vp9_convolve8_avg_horiz;
  xd->subpix.predict[1][1][0] = vp9_convolve8;
  xd->subpix.predict[1][1][1] = vp9_convolve8_avg;

  xd->subpix.x_step_q4 = 16;
  xd->subpix.y_step_q4 = 16;
  switch (mcomp_filter_type) {
    case EIGHTTAP:
    case SWITCHABLE:
      xd->subpix.filter_x = xd->subpix.filter_y = vp9_sub_pel_filters_8;
      break;
    case EIGHTTAP_SMOOTH:
      xd->subpix.filter_x = xd->subpix.filter_y = vp9_sub_pel_filters_8lp;
      break;
    case EIGHTTAP_SHARP:
      xd->subpix.filter_x = xd->subpix.filter_y = vp9_sub_pel_filters_8s;
      break;
    case BILINEAR:
      xd->subpix.filter_x = xd->subpix.filter_y = vp9_bilinear_filters;
      break;
Adrian Grange's avatar
Adrian Grange committed
54
#if CONFIG_ENABLE_6TAP
55
56
57
    case SIXTAP:
      xd->subpix.filter_x = xd->subpix.filter_y = vp9_sub_pel_filters_6;
      break;
Adrian Grange's avatar
Adrian Grange committed
58
59
#endif
  }
60
61
}

62
void vp9_copy_mem16x16_c(const uint8_t *src,
63
                         int src_stride,
64
                         uint8_t *dst,
65
                         int dst_stride) {
John Koleszar's avatar
John Koleszar committed
66
  int r;
John Koleszar's avatar
John Koleszar committed
67

John Koleszar's avatar
John Koleszar committed
68
  for (r = 0; r < 16; r++) {
69
#if !(CONFIG_FAST_UNALIGNED)
John Koleszar's avatar
John Koleszar committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    dst[0] = src[0];
    dst[1] = src[1];
    dst[2] = src[2];
    dst[3] = src[3];
    dst[4] = src[4];
    dst[5] = src[5];
    dst[6] = src[6];
    dst[7] = src[7];
    dst[8] = src[8];
    dst[9] = src[9];
    dst[10] = src[10];
    dst[11] = src[11];
    dst[12] = src[12];
    dst[13] = src[13];
    dst[14] = src[14];
    dst[15] = src[15];
John Koleszar's avatar
John Koleszar committed
86
87

#else
88
89
90
91
    ((uint32_t *)dst)[0] = ((const uint32_t *)src)[0];
    ((uint32_t *)dst)[1] = ((const uint32_t *)src)[1];
    ((uint32_t *)dst)[2] = ((const uint32_t *)src)[2];
    ((uint32_t *)dst)[3] = ((const uint32_t *)src)[3];
John Koleszar's avatar
John Koleszar committed
92
93

#endif
John Koleszar's avatar
John Koleszar committed
94
95
96
    src += src_stride;
    dst += dst_stride;
  }
John Koleszar's avatar
John Koleszar committed
97
98
}

99
void vp9_copy_mem8x8_c(const uint8_t *src,
100
                       int src_stride,
101
                       uint8_t *dst,
102
                       int dst_stride) {
John Koleszar's avatar
John Koleszar committed
103
104
105
  int r;

  for (r = 0; r < 8; r++) {
106
#if !(CONFIG_FAST_UNALIGNED)
John Koleszar's avatar
John Koleszar committed
107
108
109
110
111
112
113
114
    dst[0] = src[0];
    dst[1] = src[1];
    dst[2] = src[2];
    dst[3] = src[3];
    dst[4] = src[4];
    dst[5] = src[5];
    dst[6] = src[6];
    dst[7] = src[7];
John Koleszar's avatar
John Koleszar committed
115
#else
116
117
    ((uint32_t *)dst)[0] = ((const uint32_t *)src)[0];
    ((uint32_t *)dst)[1] = ((const uint32_t *)src)[1];
John Koleszar's avatar
John Koleszar committed
118
#endif
John Koleszar's avatar
John Koleszar committed
119
120
121
    src += src_stride;
    dst += dst_stride;
  }
John Koleszar's avatar
John Koleszar committed
122
123
}

124
void vp9_copy_mem8x4_c(const uint8_t *src,
125
                       int src_stride,
126
                       uint8_t *dst,
127
                       int dst_stride) {
John Koleszar's avatar
John Koleszar committed
128
129
130
  int r;

  for (r = 0; r < 4; r++) {
131
#if !(CONFIG_FAST_UNALIGNED)
John Koleszar's avatar
John Koleszar committed
132
133
134
135
136
137
138
139
    dst[0] = src[0];
    dst[1] = src[1];
    dst[2] = src[2];
    dst[3] = src[3];
    dst[4] = src[4];
    dst[5] = src[5];
    dst[6] = src[6];
    dst[7] = src[7];
John Koleszar's avatar
John Koleszar committed
140
#else
141
142
    ((uint32_t *)dst)[0] = ((const uint32_t *)src)[0];
    ((uint32_t *)dst)[1] = ((const uint32_t *)src)[1];
John Koleszar's avatar
John Koleszar committed
143
#endif
John Koleszar's avatar
John Koleszar committed
144
145
146
    src += src_stride;
    dst += dst_stride;
  }
John Koleszar's avatar
John Koleszar committed
147
148
}

149
150
void vp9_build_inter_predictors_b(BLOCKD *d, int pitch,
                                  struct subpix_fn_table *subpix) {
151
152
153
  uint8_t *ptr_base;
  uint8_t *ptr;
  uint8_t *pred_ptr = d->predictor;
John Koleszar's avatar
John Koleszar committed
154
  int_mv mv;
John Koleszar's avatar
John Koleszar committed
155

John Koleszar's avatar
John Koleszar committed
156
  ptr_base = *(d->base_pre);
157
  mv.as_int = d->bmi.as_mv[0].as_int;
158
159
  ptr = ptr_base + d->pre + (mv.as_mv.row >> 3) * d->pre_stride +
        (mv.as_mv.col >> 3);
John Koleszar's avatar
John Koleszar committed
160

161
162
163
164
165
  subpix->predict[!!(mv.as_mv.col & 7)][!!(mv.as_mv.row & 7)][0](
      ptr, d->pre_stride, pred_ptr, pitch,
      subpix->filter_x[(mv.as_mv.col & 7) << 1], subpix->x_step_q4,
      subpix->filter_y[(mv.as_mv.row & 7) << 1], subpix->y_step_q4,
      4, 4);
John Koleszar's avatar
John Koleszar committed
166
167
}

168
/*
169
 * Similar to vp9_build_inter_predictors_b(), but instead of storing the
170
 * results in d->predictor, we average the contents of d->predictor (which
171
 * come from an earlier call to vp9_build_inter_predictors_b()) with the
172
173
 * predictor of the second reference frame / motion vector.
 */
174
void vp9_build_2nd_inter_predictors_b(BLOCKD *d, int pitch,
175
                                      struct subpix_fn_table *subpix) {
176
177
178
  uint8_t *ptr_base;
  uint8_t *ptr;
  uint8_t *pred_ptr = d->predictor;
John Koleszar's avatar
John Koleszar committed
179
180
181
  int_mv mv;

  ptr_base = *(d->base_second_pre);
182
  mv.as_int = d->bmi.as_mv[1].as_int;
183
184
  ptr = ptr_base + d->pre + (mv.as_mv.row >> 3) * d->pre_stride +
        (mv.as_mv.col >> 3);
John Koleszar's avatar
John Koleszar committed
185

186
187
188
189
190
  subpix->predict[!!(mv.as_mv.col & 7)][!!(mv.as_mv.row & 7)][1](
      ptr, d->pre_stride, pred_ptr, pitch,
      subpix->filter_x[(mv.as_mv.col & 7) << 1], subpix->x_step_q4,
      subpix->filter_y[(mv.as_mv.row & 7) << 1], subpix->y_step_q4,
      4, 4);
191
192
}

193
void vp9_build_inter_predictors4b(MACROBLOCKD *xd, BLOCKD *d, int pitch) {
194
195
196
  uint8_t *ptr_base;
  uint8_t *ptr;
  uint8_t *pred_ptr = d->predictor;
John Koleszar's avatar
John Koleszar committed
197
  int_mv mv;
John Koleszar's avatar
John Koleszar committed
198

John Koleszar's avatar
John Koleszar committed
199
  ptr_base = *(d->base_pre);
200
  mv.as_int = d->bmi.as_mv[0].as_int;
Paul Wilkins's avatar
Paul Wilkins committed
201
202
  ptr = ptr_base + d->pre + (mv.as_mv.row >> 3) * d->pre_stride +
        (mv.as_mv.col >> 3);
John Koleszar's avatar
John Koleszar committed
203

204
205
206
207
208
  xd->subpix.predict[!!(mv.as_mv.col & 7)][!!(mv.as_mv.row & 7)][0](
      ptr, d->pre_stride, pred_ptr, pitch,
      xd->subpix.filter_x[(mv.as_mv.col & 7) << 1], xd->subpix.x_step_q4,
      xd->subpix.filter_y[(mv.as_mv.row & 7) << 1], xd->subpix.y_step_q4,
      8, 8);
John Koleszar's avatar
John Koleszar committed
209
210
}

211
212
213
214
215
216
/*
 * Similar to build_inter_predictors_4b(), but instead of storing the
 * results in d->predictor, we average the contents of d->predictor (which
 * come from an earlier call to build_inter_predictors_4b()) with the
 * predictor of the second reference frame / motion vector.
 */
217
void vp9_build_2nd_inter_predictors4b(MACROBLOCKD *xd,
218
                                      BLOCKD *d, int pitch) {
219
220
221
  uint8_t *ptr_base;
  uint8_t *ptr;
  uint8_t *pred_ptr = d->predictor;
John Koleszar's avatar
John Koleszar committed
222
223
224
  int_mv mv;

  ptr_base = *(d->base_second_pre);
225
  mv.as_int = d->bmi.as_mv[1].as_int;
Paul Wilkins's avatar
Paul Wilkins committed
226
227
  ptr = ptr_base + d->pre + (mv.as_mv.row >> 3) * d->pre_stride +
        (mv.as_mv.col >> 3);
228

229
230
231
232
233
  xd->subpix.predict[!!(mv.as_mv.col & 7)][!!(mv.as_mv.row & 7)][1](
      ptr, d->pre_stride, pred_ptr, pitch,
      xd->subpix.filter_x[(mv.as_mv.col & 7) << 1], xd->subpix.x_step_q4,
      xd->subpix.filter_y[(mv.as_mv.row & 7) << 1], xd->subpix.y_step_q4,
      8, 8);
234
235
}

Paul Wilkins's avatar
Paul Wilkins committed
236
static void build_inter_predictors2b(MACROBLOCKD *xd, BLOCKD *d, int pitch) {
237
238
239
  uint8_t *ptr_base;
  uint8_t *ptr;
  uint8_t *pred_ptr = d->predictor;
John Koleszar's avatar
John Koleszar committed
240
  int_mv mv;
John Koleszar's avatar
John Koleszar committed
241

John Koleszar's avatar
John Koleszar committed
242
  ptr_base = *(d->base_pre);
243
  mv.as_int = d->bmi.as_mv[0].as_int;
Paul Wilkins's avatar
Paul Wilkins committed
244
245
  ptr = ptr_base + d->pre + (mv.as_mv.row >> 3) * d->pre_stride +
        (mv.as_mv.col >> 3);
John Koleszar's avatar
John Koleszar committed
246

247
248
249
250
251
  xd->subpix.predict[!!(mv.as_mv.col & 7)][!!(mv.as_mv.row & 7)][0](
      ptr, d->pre_stride, pred_ptr, pitch,
      xd->subpix.filter_x[(mv.as_mv.col & 7) << 1], xd->subpix.x_step_q4,
      xd->subpix.filter_y[(mv.as_mv.row & 7) << 1], xd->subpix.y_step_q4,
      8, 4);
John Koleszar's avatar
John Koleszar committed
252
253
}

254
/*encoder only*/
255
void vp9_build_inter4x4_predictors_mbuv(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
256
  int i, j;
Paul Wilkins's avatar
Paul Wilkins committed
257
  BLOCKD *blockd = xd->block;
John Koleszar's avatar
John Koleszar committed
258
259
260
261
262
263
264
265
266

  /* build uv mvs */
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 2; j++) {
      int yoffset = i * 8 + j * 2;
      int uoffset = 16 + i * 2 + j;
      int voffset = 20 + i * 2 + j;
      int temp;

267
268
269
270
      temp = blockd[yoffset  ].bmi.as_mv[0].as_mv.row
             + blockd[yoffset + 1].bmi.as_mv[0].as_mv.row
             + blockd[yoffset + 4].bmi.as_mv[0].as_mv.row
             + blockd[yoffset + 5].bmi.as_mv[0].as_mv.row;
John Koleszar's avatar
John Koleszar committed
271
272
273
274

      if (temp < 0) temp -= 4;
      else temp += 4;

275
      xd->block[uoffset].bmi.as_mv[0].as_mv.row = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
276
        xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
277

278
279
280
281
      temp = blockd[yoffset  ].bmi.as_mv[0].as_mv.col
             + blockd[yoffset + 1].bmi.as_mv[0].as_mv.col
             + blockd[yoffset + 4].bmi.as_mv[0].as_mv.col
             + blockd[yoffset + 5].bmi.as_mv[0].as_mv.col;
John Koleszar's avatar
John Koleszar committed
282
283
284
285

      if (temp < 0) temp -= 4;
      else temp += 4;

286
      blockd[uoffset].bmi.as_mv[0].as_mv.col = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
287
        xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
288

289
290
291
292
      blockd[voffset].bmi.as_mv[0].as_mv.row =
        blockd[uoffset].bmi.as_mv[0].as_mv.row;
      blockd[voffset].bmi.as_mv[0].as_mv.col =
        blockd[uoffset].bmi.as_mv[0].as_mv.col;
John Koleszar's avatar
John Koleszar committed
293

294
      if (xd->mode_info_context->mbmi.second_ref_frame > 0) {
295
296
297
298
        temp = blockd[yoffset  ].bmi.as_mv[1].as_mv.row
               + blockd[yoffset + 1].bmi.as_mv[1].as_mv.row
               + blockd[yoffset + 4].bmi.as_mv[1].as_mv.row
               + blockd[yoffset + 5].bmi.as_mv[1].as_mv.row;
John Koleszar's avatar
John Koleszar committed
299
300
301
302
303

        if (temp < 0) {
          temp -= 4;
        } else {
          temp += 4;
304
305
        }

306
        blockd[uoffset].bmi.as_mv[1].as_mv.row = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
307
          xd->fullpixel_mask;
308

309
310
311
312
        temp = blockd[yoffset  ].bmi.as_mv[1].as_mv.col
               + blockd[yoffset + 1].bmi.as_mv[1].as_mv.col
               + blockd[yoffset + 4].bmi.as_mv[1].as_mv.col
               + blockd[yoffset + 5].bmi.as_mv[1].as_mv.col;
John Koleszar's avatar
John Koleszar committed
313
314
315
316
317

        if (temp < 0) {
          temp -= 4;
        } else {
          temp += 4;
318
        }
John Koleszar's avatar
John Koleszar committed
319

320
        blockd[uoffset].bmi.as_mv[1].as_mv.col = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
321
          xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
322

323
324
325
326
        blockd[voffset].bmi.as_mv[1].as_mv.row =
          blockd[uoffset].bmi.as_mv[1].as_mv.row;
        blockd[voffset].bmi.as_mv[1].as_mv.col =
          blockd[uoffset].bmi.as_mv[1].as_mv.col;
John Koleszar's avatar
John Koleszar committed
327
      }
John Koleszar's avatar
John Koleszar committed
328
    }
John Koleszar's avatar
John Koleszar committed
329
330
331
  }

  for (i = 16; i < 24; i += 2) {
Paul Wilkins's avatar
Paul Wilkins committed
332
333
    BLOCKD *d0 = &blockd[i];
    BLOCKD *d1 = &blockd[i + 1];
John Koleszar's avatar
John Koleszar committed
334

335
    if (d0->bmi.as_mv[0].as_int == d1->bmi.as_mv[0].as_int)
Paul Wilkins's avatar
Paul Wilkins committed
336
      build_inter_predictors2b(xd, d0, 8);
John Koleszar's avatar
John Koleszar committed
337
    else {
338
339
      vp9_build_inter_predictors_b(d0, 8, &xd->subpix);
      vp9_build_inter_predictors_b(d1, 8, &xd->subpix);
John Koleszar's avatar
John Koleszar committed
340
341
    }

342
    if (xd->mode_info_context->mbmi.second_ref_frame > 0) {
343
344
      vp9_build_2nd_inter_predictors_b(d0, 8, &xd->subpix);
      vp9_build_2nd_inter_predictors_b(d1, 8, &xd->subpix);
John Koleszar's avatar
John Koleszar committed
345
346
    }
  }
John Koleszar's avatar
John Koleszar committed
347
348
}

John Koleszar's avatar
John Koleszar committed
349
350
351
352
353
354
355
356
357
358
static void clamp_mv_to_umv_border(MV *mv, const MACROBLOCKD *xd) {
  /* If the MV points so far into the UMV border that no visible pixels
   * are used for reconstruction, the subpel part of the MV can be
   * discarded and the MV limited to 16 pixels with equivalent results.
   *
   * This limit kicks in at 19 pixels for the top and left edges, for
   * the 16 pixels plus 3 taps right of the central pixel when subpel
   * filtering. The bottom and right edges use 16 pixels plus 2 pixels
   * left of the central pixel when filtering.
   */
John Koleszar's avatar
John Koleszar committed
359
  if (mv->col < (xd->mb_to_left_edge - ((16 + VP9_INTERP_EXTEND) << 3)))
John Koleszar's avatar
John Koleszar committed
360
    mv->col = xd->mb_to_left_edge - (16 << 3);
John Koleszar's avatar
John Koleszar committed
361
  else if (mv->col > xd->mb_to_right_edge + ((15 + VP9_INTERP_EXTEND) << 3))
John Koleszar's avatar
John Koleszar committed
362
363
    mv->col = xd->mb_to_right_edge + (16 << 3);

John Koleszar's avatar
John Koleszar committed
364
  if (mv->row < (xd->mb_to_top_edge - ((16 + VP9_INTERP_EXTEND) << 3)))
John Koleszar's avatar
John Koleszar committed
365
    mv->row = xd->mb_to_top_edge - (16 << 3);
John Koleszar's avatar
John Koleszar committed
366
  else if (mv->row > xd->mb_to_bottom_edge + ((15 + VP9_INTERP_EXTEND) << 3))
John Koleszar's avatar
John Koleszar committed
367
    mv->row = xd->mb_to_bottom_edge + (16 << 3);
368
369
370
}

/* A version of the above function for chroma block MVs.*/
John Koleszar's avatar
John Koleszar committed
371
static void clamp_uvmv_to_umv_border(MV *mv, const MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
372
373
374
  const int extend = VP9_INTERP_EXTEND;

  mv->col = (2 * mv->col < (xd->mb_to_left_edge - ((16 + extend) << 3))) ?
John Koleszar's avatar
John Koleszar committed
375
            (xd->mb_to_left_edge - (16 << 3)) >> 1 : mv->col;
John Koleszar's avatar
John Koleszar committed
376
  mv->col = (2 * mv->col > xd->mb_to_right_edge + ((15 + extend) << 3)) ?
John Koleszar's avatar
John Koleszar committed
377
378
            (xd->mb_to_right_edge + (16 << 3)) >> 1 : mv->col;

John Koleszar's avatar
John Koleszar committed
379
  mv->row = (2 * mv->row < (xd->mb_to_top_edge - ((16 + extend) << 3))) ?
John Koleszar's avatar
John Koleszar committed
380
            (xd->mb_to_top_edge - (16 << 3)) >> 1 : mv->row;
John Koleszar's avatar
John Koleszar committed
381
  mv->row = (2 * mv->row > xd->mb_to_bottom_edge + ((15 + extend) << 3)) ?
John Koleszar's avatar
John Koleszar committed
382
            (xd->mb_to_bottom_edge + (16 << 3)) >> 1 : mv->row;
383
384
}

385
/*encoder only*/
386
void vp9_build_1st_inter16x16_predictors_mby(MACROBLOCKD *xd,
387
                                             uint8_t *dst_y,
388
389
                                             int dst_ystride,
                                             int clamp_mvs) {
390
391
  uint8_t *ptr_base = xd->pre.y_buffer;
  uint8_t *ptr;
392
393
  int pre_stride = xd->block[0].pre_stride;
  int_mv ymv;
John Koleszar's avatar
John Koleszar committed
394

395
  ymv.as_int = xd->mode_info_context->mbmi.mv[0].as_int;
John Koleszar's avatar
John Koleszar committed
396

397
  if (clamp_mvs)
398
    clamp_mv_to_umv_border(&ymv.as_mv, xd);
399

400
  ptr = ptr_base + (ymv.as_mv.row >> 3) * pre_stride + (ymv.as_mv.col >> 3);
401

402
403
404
405
406
  xd->subpix.predict[!!(ymv.as_mv.col & 7)][!!(ymv.as_mv.row & 7)][0](
      ptr, pre_stride, dst_y, dst_ystride,
      xd->subpix.filter_x[(ymv.as_mv.col & 7) << 1], xd->subpix.x_step_q4,
      xd->subpix.filter_y[(ymv.as_mv.row & 7) << 1], xd->subpix.y_step_q4,
      16, 16);
407
408
}

409
void vp9_build_1st_inter16x16_predictors_mbuv(MACROBLOCKD *xd,
410
411
                                              uint8_t *dst_u,
                                              uint8_t *dst_v,
412
413
                                              int dst_uvstride) {
  int offset;
414
  uint8_t *uptr, *vptr;
Paul Wilkins's avatar
Paul Wilkins committed
415
  int pre_stride = xd->block[0].pre_stride;
416
417
418
  int_mv _o16x16mv;
  int_mv _16x16mv;

Paul Wilkins's avatar
Paul Wilkins committed
419
  _16x16mv.as_int = xd->mode_info_context->mbmi.mv[0].as_int;
420

Paul Wilkins's avatar
Paul Wilkins committed
421
422
  if (xd->mode_info_context->mbmi.need_to_clamp_mvs)
    clamp_mv_to_umv_border(&_16x16mv.as_mv, xd);
John Koleszar's avatar
John Koleszar committed
423

John Koleszar's avatar
John Koleszar committed
424
425
426
427
428
429
  _o16x16mv = _16x16mv;
  /* calc uv motion vectors */
  if (_16x16mv.as_mv.row < 0)
    _16x16mv.as_mv.row -= 1;
  else
    _16x16mv.as_mv.row += 1;
430

John Koleszar's avatar
John Koleszar committed
431
432
433
434
  if (_16x16mv.as_mv.col < 0)
    _16x16mv.as_mv.col -= 1;
  else
    _16x16mv.as_mv.col += 1;
435

John Koleszar's avatar
John Koleszar committed
436
437
  _16x16mv.as_mv.row /= 2;
  _16x16mv.as_mv.col /= 2;
438

Paul Wilkins's avatar
Paul Wilkins committed
439
440
  _16x16mv.as_mv.row &= xd->fullpixel_mask;
  _16x16mv.as_mv.col &= xd->fullpixel_mask;
441

John Koleszar's avatar
John Koleszar committed
442
443
  pre_stride >>= 1;
  offset = (_16x16mv.as_mv.row >> 3) * pre_stride + (_16x16mv.as_mv.col >> 3);
Paul Wilkins's avatar
Paul Wilkins committed
444
445
  uptr = xd->pre.u_buffer + offset;
  vptr = xd->pre.v_buffer + offset;
John Koleszar's avatar
John Koleszar committed
446

447
448
449
450
451
452
453
454
455
456
457
458
459
  xd->subpix.predict[!!(_o16x16mv.as_mv.col & 15)]
                    [!!(_o16x16mv.as_mv.row & 15)][0](
      uptr, pre_stride, dst_u, dst_uvstride,
      xd->subpix.filter_x[_o16x16mv.as_mv.col & 15], xd->subpix.x_step_q4,
      xd->subpix.filter_y[_o16x16mv.as_mv.row & 15], xd->subpix.y_step_q4,
      8, 8);

  xd->subpix.predict[!!(_o16x16mv.as_mv.col & 15)]
                    [!!(_o16x16mv.as_mv.row & 15)][0](
      vptr, pre_stride, dst_v, dst_uvstride,
      xd->subpix.filter_x[_o16x16mv.as_mv.col & 15], xd->subpix.x_step_q4,
      xd->subpix.filter_y[_o16x16mv.as_mv.row & 15], xd->subpix.y_step_q4,
      8, 8);
460
461
462
}


463
void vp9_build_1st_inter16x16_predictors_mb(MACROBLOCKD *xd,
464
465
466
                                            uint8_t *dst_y,
                                            uint8_t *dst_u,
                                            uint8_t *dst_v,
467
                                            int dst_ystride, int dst_uvstride) {
468
  vp9_build_1st_inter16x16_predictors_mby(xd, dst_y, dst_ystride,
469
      xd->mode_info_context->mbmi.need_to_clamp_mvs);
470
  vp9_build_1st_inter16x16_predictors_mbuv(xd, dst_u, dst_v, dst_uvstride);
471
}
John Koleszar's avatar
John Koleszar committed
472

473
void vp9_build_inter32x32_predictors_sb(MACROBLOCKD *x,
474
475
476
                                        uint8_t *dst_y,
                                        uint8_t *dst_u,
                                        uint8_t *dst_v,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
477
478
479
480
481
                                        int dst_ystride,
                                        int dst_uvstride) {
  uint8_t *y1 = x->pre.y_buffer, *u1 = x->pre.u_buffer, *v1 = x->pre.v_buffer;
  uint8_t *y2 = x->second_pre.y_buffer, *u2 = x->second_pre.u_buffer,
          *v2 = x->second_pre.v_buffer;
482
  int edge[4], n;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
483

484
485
486
487
488
489
  edge[0] = x->mb_to_top_edge;
  edge[1] = x->mb_to_bottom_edge;
  edge[2] = x->mb_to_left_edge;
  edge[3] = x->mb_to_right_edge;

  for (n = 0; n < 4; n++) {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
490
491
    const int x_idx = n & 1, y_idx = n >> 1;

492
493
494
495
496
    x->mb_to_top_edge    = edge[0] -      ((y_idx  * 16) << 3);
    x->mb_to_bottom_edge = edge[1] + (((1 - y_idx) * 16) << 3);
    x->mb_to_left_edge   = edge[2] -      ((x_idx  * 16) << 3);
    x->mb_to_right_edge  = edge[3] + (((1 - x_idx) * 16) << 3);

Ronald S. Bultje's avatar
Ronald S. Bultje committed
497
498
499
500
    x->pre.y_buffer = y1 + y_idx * 16 * x->pre.y_stride  + x_idx * 16;
    x->pre.u_buffer = u1 + y_idx *  8 * x->pre.uv_stride + x_idx *  8;
    x->pre.v_buffer = v1 + y_idx *  8 * x->pre.uv_stride + x_idx *  8;

501
    vp9_build_1st_inter16x16_predictors_mb(x,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
502
503
504
505
      dst_y + y_idx * 16 * dst_ystride  + x_idx * 16,
      dst_u + y_idx *  8 * dst_uvstride + x_idx *  8,
      dst_v + y_idx *  8 * dst_uvstride + x_idx *  8,
      dst_ystride, dst_uvstride);
506
    if (x->mode_info_context->mbmi.second_ref_frame > 0) {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
507
508
509
510
      x->second_pre.y_buffer = y2 + y_idx * 16 * x->pre.y_stride  + x_idx * 16;
      x->second_pre.u_buffer = u2 + y_idx *  8 * x->pre.uv_stride + x_idx *  8;
      x->second_pre.v_buffer = v2 + y_idx *  8 * x->pre.uv_stride + x_idx *  8;

511
      vp9_build_2nd_inter16x16_predictors_mb(x,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
512
513
514
515
516
517
518
        dst_y + y_idx * 16 * dst_ystride  + x_idx * 16,
        dst_u + y_idx *  8 * dst_uvstride + x_idx *  8,
        dst_v + y_idx *  8 * dst_uvstride + x_idx *  8,
        dst_ystride, dst_uvstride);
    }
  }

519
520
521
522
523
  x->mb_to_top_edge    = edge[0];
  x->mb_to_bottom_edge = edge[1];
  x->mb_to_left_edge   = edge[2];
  x->mb_to_right_edge  = edge[3];

Ronald S. Bultje's avatar
Ronald S. Bultje committed
524
525
526
527
  x->pre.y_buffer = y1;
  x->pre.u_buffer = u1;
  x->pre.v_buffer = v1;

528
  if (x->mode_info_context->mbmi.second_ref_frame > 0) {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
529
530
531
532
    x->second_pre.y_buffer = y2;
    x->second_pre.u_buffer = u2;
    x->second_pre.v_buffer = v2;
  }
533
534
535
536
537

#if CONFIG_COMP_INTERINTRA_PRED
  if (x->mode_info_context->mbmi.second_ref_frame == INTRA_FRAME) {
    vp9_build_interintra_32x32_predictors_sb(
        x, dst_y, dst_u, dst_v, dst_ystride, dst_uvstride);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
  }
#endif
}

void vp9_build_inter64x64_predictors_sb(MACROBLOCKD *x,
                                        uint8_t *dst_y,
                                        uint8_t *dst_u,
                                        uint8_t *dst_v,
                                        int dst_ystride,
                                        int dst_uvstride) {
  uint8_t *y1 = x->pre.y_buffer, *u1 = x->pre.u_buffer, *v1 = x->pre.v_buffer;
  uint8_t *y2 = x->second_pre.y_buffer, *u2 = x->second_pre.u_buffer,
          *v2 = x->second_pre.v_buffer;
  int edge[4], n;

  edge[0] = x->mb_to_top_edge;
  edge[1] = x->mb_to_bottom_edge;
  edge[2] = x->mb_to_left_edge;
  edge[3] = x->mb_to_right_edge;

  for (n = 0; n < 4; n++) {
    const int x_idx = n & 1, y_idx = n >> 1;

    x->mb_to_top_edge    = edge[0] -      ((y_idx  * 32) << 3);
    x->mb_to_bottom_edge = edge[1] + (((1 - y_idx) * 32) << 3);
    x->mb_to_left_edge   = edge[2] -      ((x_idx  * 32) << 3);
    x->mb_to_right_edge  = edge[3] + (((1 - x_idx) * 32) << 3);

    x->pre.y_buffer = y1 + y_idx * 32 * x->pre.y_stride  + x_idx * 32;
    x->pre.u_buffer = u1 + y_idx * 16 * x->pre.uv_stride + x_idx * 16;
    x->pre.v_buffer = v1 + y_idx * 16 * x->pre.uv_stride + x_idx * 16;

    if (x->mode_info_context->mbmi.second_ref_frame > 0) {
      x->second_pre.y_buffer = y2 + y_idx * 32 * x->pre.y_stride  + x_idx * 32;
      x->second_pre.u_buffer = u2 + y_idx * 16 * x->pre.uv_stride + x_idx * 16;
      x->second_pre.v_buffer = v2 + y_idx * 16 * x->pre.uv_stride + x_idx * 16;
    }

    vp9_build_inter32x32_predictors_sb(x,
        dst_y + y_idx * 32 * dst_ystride  + x_idx * 32,
        dst_u + y_idx * 16 * dst_uvstride + x_idx * 16,
        dst_v + y_idx * 16 * dst_uvstride + x_idx * 16,
        dst_ystride, dst_uvstride);
  }

  x->mb_to_top_edge    = edge[0];
  x->mb_to_bottom_edge = edge[1];
  x->mb_to_left_edge   = edge[2];
  x->mb_to_right_edge  = edge[3];

  x->pre.y_buffer = y1;
  x->pre.u_buffer = u1;
  x->pre.v_buffer = v1;

  if (x->mode_info_context->mbmi.second_ref_frame > 0) {
    x->second_pre.y_buffer = y2;
    x->second_pre.u_buffer = u2;
    x->second_pre.v_buffer = v2;
  }

#if CONFIG_COMP_INTERINTRA_PRED
  if (x->mode_info_context->mbmi.second_ref_frame == INTRA_FRAME) {
    vp9_build_interintra_64x64_predictors_sb(x, dst_y, dst_u, dst_v,
                                             dst_ystride, dst_uvstride);
602
603
  }
#endif
Ronald S. Bultje's avatar
Ronald S. Bultje committed
604
605
}

606
/*
607
 * The following functions should be called after an initial
608
 * call to vp9_build_1st_inter16x16_predictors_mb() or _mby()/_mbuv().
Adrian Grange's avatar
Adrian Grange committed
609
 * It will run a second filter on a (different) ref
610
 * frame and average the result with the output of the
Adrian Grange's avatar
Adrian Grange committed
611
 * first filter. The second reference frame is stored
612
613
614
615
616
617
618
619
 * in x->second_pre (the reference frame index is in
 * x->mode_info_context->mbmi.second_ref_frame). The second
 * motion vector is x->mode_info_context->mbmi.second_mv.
 *
 * This allows blending prediction from two reference frames
 * which sometimes leads to better prediction than from a
 * single reference framer.
 */
620
void vp9_build_2nd_inter16x16_predictors_mby(MACROBLOCKD *xd,
621
                                             uint8_t *dst_y,
622
                                             int dst_ystride) {
623
  uint8_t *ptr;
624

John Koleszar's avatar
John Koleszar committed
625
626
627
  int_mv _16x16mv;
  int mv_row;
  int mv_col;
Yaowu Xu's avatar
Yaowu Xu committed
628

629
  uint8_t *ptr_base = xd->second_pre.y_buffer;
Paul Wilkins's avatar
Paul Wilkins committed
630
  int pre_stride = xd->block[0].pre_stride;
631

Paul Wilkins's avatar
Paul Wilkins committed
632
  _16x16mv.as_int = xd->mode_info_context->mbmi.mv[1].as_int;
Yaowu Xu's avatar
Yaowu Xu committed
633

Paul Wilkins's avatar
Paul Wilkins committed
634
635
  if (xd->mode_info_context->mbmi.need_to_clamp_secondmv)
    clamp_mv_to_umv_border(&_16x16mv.as_mv, xd);
Yaowu Xu's avatar
Yaowu Xu committed
636

John Koleszar's avatar
John Koleszar committed
637
638
  mv_row = _16x16mv.as_mv.row;
  mv_col = _16x16mv.as_mv.col;
Yaowu Xu's avatar
Yaowu Xu committed
639

John Koleszar's avatar
John Koleszar committed
640
  ptr = ptr_base + (mv_row >> 3) * pre_stride + (mv_col >> 3);
641

642
643
644
645
646
  xd->subpix.predict[!!(mv_col & 7)][!!(mv_row & 7)][1](
      ptr, pre_stride, dst_y, dst_ystride,
      xd->subpix.filter_x[(mv_col & 7) << 1], xd->subpix.x_step_q4,
      xd->subpix.filter_y[(mv_row & 7) << 1], xd->subpix.y_step_q4,
      16, 16);
647
648
}

649
void vp9_build_2nd_inter16x16_predictors_mbuv(MACROBLOCKD *xd,
650
651
                                              uint8_t *dst_u,
                                              uint8_t *dst_v,
652
653
                                              int dst_uvstride) {
  int offset;
654
  uint8_t *uptr, *vptr;
655
656
657
658
659
660

  int_mv _16x16mv;
  int mv_row;
  int mv_col;
  int omv_row, omv_col;

Paul Wilkins's avatar
Paul Wilkins committed
661
  int pre_stride = xd->block[0].pre_stride;
662

Paul Wilkins's avatar
Paul Wilkins committed
663
  _16x16mv.as_int = xd->mode_info_context->mbmi.mv[1].as_int;
664

Paul Wilkins's avatar
Paul Wilkins committed
665
666
  if (xd->mode_info_context->mbmi.need_to_clamp_secondmv)
    clamp_mv_to_umv_border(&_16x16mv.as_mv, xd);
667
668
669

  mv_row = _16x16mv.as_mv.row;
  mv_col = _16x16mv.as_mv.col;
670

John Koleszar's avatar
John Koleszar committed
671
672
673
674
675
  /* calc uv motion vectors */
  omv_row = mv_row;
  omv_col = mv_col;
  mv_row = (mv_row + (mv_row > 0)) >> 1;
  mv_col = (mv_col + (mv_col > 0)) >> 1;
676

Paul Wilkins's avatar
Paul Wilkins committed
677
678
  mv_row &= xd->fullpixel_mask;
  mv_col &= xd->fullpixel_mask;
679

John Koleszar's avatar
John Koleszar committed
680
681
  pre_stride >>= 1;
  offset = (mv_row >> 3) * pre_stride + (mv_col >> 3);
Paul Wilkins's avatar
Paul Wilkins committed
682
683
  uptr = xd->second_pre.u_buffer + offset;
  vptr = xd->second_pre.v_buffer + offset;
684

685
686
687
688
689
690
691
692
693
694
695
  xd->subpix.predict[!!(omv_col & 15)][!!(omv_row & 15)][1](
      uptr, pre_stride, dst_u, dst_uvstride,
      xd->subpix.filter_x[omv_col & 15], xd->subpix.x_step_q4,
      xd->subpix.filter_y[omv_row & 15], xd->subpix.y_step_q4,
      8, 8);

  xd->subpix.predict[!!(omv_col & 15)][!!(omv_row & 15)][1](
      vptr, pre_stride, dst_v, dst_uvstride,
      xd->subpix.filter_x[omv_col & 15], xd->subpix.x_step_q4,
      xd->subpix.filter_y[omv_row & 15], xd->subpix.y_step_q4,
      8, 8);
696
697
}

698
void vp9_build_2nd_inter16x16_predictors_mb(MACROBLOCKD *xd,
699
700
701
                                            uint8_t *dst_y,
                                            uint8_t *dst_u,
                                            uint8_t *dst_v,
702
703
                                            int dst_ystride,
                                            int dst_uvstride) {
704
705
  vp9_build_2nd_inter16x16_predictors_mby(xd, dst_y, dst_ystride);
  vp9_build_2nd_inter16x16_predictors_mbuv(xd, dst_u, dst_v, dst_uvstride);
706
707
}

Paul Wilkins's avatar
Paul Wilkins committed
708
static void build_inter4x4_predictors_mb(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
709
  int i;
Paul Wilkins's avatar
Paul Wilkins committed
710
711
712
  MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
  BLOCKD *blockd = xd->block;

713
  if (xd->mode_info_context->mbmi.partitioning != PARTITIONING_4X4) {
Paul Wilkins's avatar
Paul Wilkins committed
714
715
716
717
718
719
    blockd[ 0].bmi = xd->mode_info_context->bmi[ 0];
    blockd[ 2].bmi = xd->mode_info_context->bmi[ 2];
    blockd[ 8].bmi = xd->mode_info_context->bmi[ 8];
    blockd[10].bmi = xd->mode_info_context->bmi[10];

    if (mbmi->need_to_clamp_mvs) {
720
721
722
723
      clamp_mv_to_umv_border(&blockd[ 0].bmi.as_mv[0].as_mv, xd);
      clamp_mv_to_umv_border(&blockd[ 2].bmi.as_mv[0].as_mv, xd);
      clamp_mv_to_umv_border(&blockd[ 8].bmi.as_mv[0].as_mv, xd);
      clamp_mv_to_umv_border(&blockd[10].bmi.as_mv[0].as_mv, xd);
724
      if (mbmi->second_ref_frame > 0) {
725
726
727
728
        clamp_mv_to_umv_border(&blockd[ 0].bmi.as_mv[1].as_mv, xd);
        clamp_mv_to_umv_border(&blockd[ 2].bmi.as_mv[1].as_mv, xd);
        clamp_mv_to_umv_border(&blockd[ 8].bmi.as_mv[1].as_mv, xd);
        clamp_mv_to_umv_border(&blockd[10].bmi.as_mv[1].as_mv, xd);
John Koleszar's avatar
John Koleszar committed
729
730
      }
    }
731

732

733
734
735
736
    vp9_build_inter_predictors4b(xd, &blockd[ 0], 16);
    vp9_build_inter_predictors4b(xd, &blockd[ 2], 16);
    vp9_build_inter_predictors4b(xd, &blockd[ 8], 16);
    vp9_build_inter_predictors4b(xd, &blockd[10], 16);
737

738
    if (mbmi->second_ref_frame > 0) {
739
740
741
742
      vp9_build_2nd_inter_predictors4b(xd, &blockd[ 0], 16);
      vp9_build_2nd_inter_predictors4b(xd, &blockd[ 2], 16);
      vp9_build_2nd_inter_predictors4b(xd, &blockd[ 8], 16);
      vp9_build_2nd_inter_predictors4b(xd, &blockd[10], 16);
743
    }
John Koleszar's avatar
John Koleszar committed
744
745
  } else {
    for (i = 0; i < 16; i += 2) {
Paul Wilkins's avatar
Paul Wilkins committed
746
747
748
749
750
751
752
      BLOCKD *d0 = &blockd[i];
      BLOCKD *d1 = &blockd[i + 1];

      blockd[i + 0].bmi = xd->mode_info_context->bmi[i + 0];
      blockd[i + 1].bmi = xd->mode_info_context->bmi[i + 1];

      if (mbmi->need_to_clamp_mvs) {
753
754
        clamp_mv_to_umv_border(&blockd[i + 0].bmi.as_mv[0].as_mv, xd);
        clamp_mv_to_umv_border(&blockd[i + 1].bmi.as_mv[0].as_mv, xd);
755
        if (mbmi->second_ref_frame > 0) {
756
757
          clamp_mv_to_umv_border(&blockd[i + 0].bmi.as_mv[1].as_mv, xd);
          clamp_mv_to_umv_border(&blockd[i + 1].bmi.as_mv[1].as_mv, xd);
John Koleszar's avatar
John Koleszar committed
758
        }
John Koleszar's avatar
John Koleszar committed
759
760
      }

761
      if (d0->bmi.as_mv[0].as_int == d1->bmi.as_mv[0].as_int)
Paul Wilkins's avatar
Paul Wilkins committed
762
        build_inter_predictors2b(xd, d0, 16);
John Koleszar's avatar
John Koleszar committed
763
      else {
764
765
        vp9_build_inter_predictors_b(d0, 16, &xd->subpix);
        vp9_build_inter_predictors_b(d1, 16, &xd->subpix);
John Koleszar's avatar
John Koleszar committed
766
767
      }

768
      if (mbmi->second_ref_frame > 0) {
769
770
        vp9_build_2nd_inter_predictors_b(d0, 16, &xd->subpix);
        vp9_build_2nd_inter_predictors_b(d1, 16, &xd->subpix);
John Koleszar's avatar
John Koleszar committed
771
      }
John Koleszar's avatar
John Koleszar committed
772
    }
John Koleszar's avatar
John Koleszar committed
773
  }
774

John Koleszar's avatar
John Koleszar committed
775
  for (i = 16; i < 24; i += 2) {
Paul Wilkins's avatar
Paul Wilkins committed
776
777
    BLOCKD *d0 = &blockd[i];
    BLOCKD *d1 = &blockd[i + 1];
778

779
    if (d0->bmi.as_mv[0].as_int == d1->bmi.as_mv[0].as_int)
Paul Wilkins's avatar
Paul Wilkins committed
780
      build_inter_predictors2b(xd, d0, 8);
John Koleszar's avatar
John Koleszar committed
781
    else {
782
783
      vp9_build_inter_predictors_b(d0, 8, &xd->subpix);
      vp9_build_inter_predictors_b(d1, 8, &xd->subpix);
784
    }
John Koleszar's avatar
John Koleszar committed
785

786
    if (mbmi->second_ref_frame > 0) {
787
788
      vp9_build_2nd_inter_predictors_b(d0, 8, &xd->subpix);
      vp9_build_2nd_inter_predictors_b(d1, 8, &xd->subpix);
John Koleszar's avatar
John Koleszar committed
789
790
    }
  }
791
792
}

793
static
Paul Wilkins's avatar
Paul Wilkins committed
794
void build_4x4uvmvs(MACROBLOCKD *xd) {
John Koleszar's avatar
John Koleszar committed
795
  int i, j;
Paul Wilkins's avatar
Paul Wilkins committed
796
  BLOCKD *blockd = xd->block;
John Koleszar's avatar
John Koleszar committed
797
798
799
800
801
802
803
804
805

  for (i = 0; i < 2; i++) {
    for (j = 0; j < 2; j++) {
      int yoffset = i * 8 + j * 2;
      int uoffset = 16 + i * 2 + j;
      int voffset = 20 + i * 2 + j;

      int temp;

806
807
808
809
      temp = xd->mode_info_context->bmi[yoffset + 0].as_mv[0].as_mv.row
             + xd->mode_info_context->bmi[yoffset + 1].as_mv[0].as_mv.row
             + xd->mode_info_context->bmi[yoffset + 4].as_mv[0].as_mv.row
             + xd->mode_info_context->bmi[yoffset + 5].as_mv[0].as_mv.row;
John Koleszar's avatar
John Koleszar committed
810
811
812
813

      if (temp < 0) temp -= 4;
      else temp += 4;

814
      blockd[uoffset].bmi.as_mv[0].as_mv.row = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
815
                                                  xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
816

817
818
819
820
      temp = xd->mode_info_context->bmi[yoffset + 0].as_mv[0].as_mv.col
             + xd->mode_info_context->bmi[yoffset + 1].as_mv[0].as_mv.col
             + xd->mode_info_context->bmi[yoffset + 4].as_mv[0].as_mv.col
             + xd->mode_info_context->bmi[yoffset + 5].as_mv[0].as_mv.col;
John Koleszar's avatar
John Koleszar committed
821
822
823
824

      if (temp < 0) temp -= 4;
      else temp += 4;

825
      blockd[uoffset].bmi.as_mv[0].as_mv.col = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
826
        xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
827
828

      // if (x->mode_info_context->mbmi.need_to_clamp_mvs)
829
      clamp_uvmv_to_umv_border(&blockd[uoffset].bmi.as_mv[0].as_mv, xd);
John Koleszar's avatar
John Koleszar committed
830
831

      // if (x->mode_info_context->mbmi.need_to_clamp_mvs)
832
      clamp_uvmv_to_umv_border(&blockd[uoffset].bmi.as_mv[0].as_mv, xd);
John Koleszar's avatar
John Koleszar committed
833

834
835
836
837
      blockd[voffset].bmi.as_mv[0].as_mv.row =
        blockd[uoffset].bmi.as_mv[0].as_mv.row;
      blockd[voffset].bmi.as_mv[0].as_mv.col =
        blockd[uoffset].bmi.as_mv[0].as_mv.col;
John Koleszar's avatar
John Koleszar committed
838

839
      if (xd->mode_info_context->mbmi.second_ref_frame > 0) {
840
841
842
843
        temp = xd->mode_info_context->bmi[yoffset + 0].as_mv[1].as_mv.row
               + xd->mode_info_context->bmi[yoffset + 1].as_mv[1].as_mv.row
               + xd->mode_info_context->bmi[yoffset + 4].as_mv[1].as_mv.row
               + xd->mode_info_context->bmi[yoffset + 5].as_mv[1].as_mv.row;
John Koleszar's avatar
John Koleszar committed
844
845
846
847
848

        if (temp < 0) {
          temp -= 4;
        } else {
          temp += 4;
John Koleszar's avatar
John Koleszar committed
849
        }
850

851
       blockd[uoffset].bmi.as_mv[1].as_mv.row = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
852
                                                    xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
853

854
855
856
857
        temp = xd->mode_info_context->bmi[yoffset + 0].as_mv[1].as_mv.col
               + xd->mode_info_context->bmi[yoffset + 1].as_mv[1].as_mv.col
               + xd->mode_info_context->bmi[yoffset + 4].as_mv[1].as_mv.col
               + xd->mode_info_context->bmi[yoffset + 5].as_mv[1].as_mv.col;
John Koleszar's avatar
John Koleszar committed
858
859
860
861
862

        if (temp < 0) {
          temp -= 4;
        } else {
          temp += 4;
863
        }
John Koleszar's avatar
John Koleszar committed
864

865
        blockd[uoffset].bmi.as_mv[1].as_mv.col = (temp / 8) &
Paul Wilkins's avatar
Paul Wilkins committed
866
                                                        xd->fullpixel_mask;
John Koleszar's avatar
John Koleszar committed
867

Paul Wilkins's avatar
Paul Wilkins committed
868
869
        // if (mbmi->need_to_clamp_mvs)
        clamp_uvmv_to_umv_border(
870
          &blockd[uoffset].bmi.as_mv[1].as_mv, xd);
John Koleszar's avatar
John Koleszar committed
871

Paul Wilkins's avatar
Paul Wilkins committed
872
873
        // if (mbmi->need_to_clamp_mvs)
        clamp_uvmv_to_umv_border(
874
          &blockd[uoffset].bmi.as_mv[1].as_mv, xd);
John Koleszar's avatar
John Koleszar committed
875

876
877
878
879
        blockd[voffset].bmi.as_mv[1].as_mv.row =
          blockd[uoffset].bmi.as_mv[1].as_mv.row;
        blockd[voffset].bmi.as_mv[1].as_mv.col =
          blockd[uoffset].bmi.as_mv[1].as_mv.col;
John Koleszar's avatar
John Koleszar committed
880
      }
881
    }
John Koleszar's avatar
John Koleszar committed
882
883
884
  }
}

885
void vp9_build_inter_predictors_mb(MACROBLOCKD *xd) {
Paul Wilkins's avatar
Paul Wilkins committed
886
  if (xd->mode_info_context->mbmi.mode != SPLITMV) {
887
    vp9_build_1st_inter16x16_predictors_mb(xd, xd->predictor,
Paul Wilkins's avatar
Paul Wilkins committed
888
889
                                           &xd->predictor[256],
                                           &xd->predictor[320], 16, 8);
John Koleszar's avatar
John Koleszar committed
890

891
    if (xd->mode_info_context->mbmi.second_ref_frame > 0) {
John Koleszar's avatar
John Koleszar committed
892
893
894
      /* 256 = offset of U plane in Y+U+V buffer;
       * 320 = offset of V plane in Y+U+V buffer.
       * (256=16x16, 320=16x16+8x8). */
895
      vp9_build_2nd_inter16x16_predictors_mb(xd, xd->predictor,
Paul Wilkins's avatar
Paul Wilkins committed
896
897
                                             &xd->predictor[256],
                                             &xd->predictor[320], 16, 8);
John Koleszar's avatar
John Koleszar committed
898
    }
899
900
901
902
903
904
905
#if CONFIG_COMP_INTERINTRA_PRED
    else if (xd->mode_info_context->mbmi.second_ref_frame == INTRA_FRAME) {
      vp9_build_interintra_16x16_predictors_mb(xd, xd->predictor,
                                               &xd->predictor[256],
                                               &xd->predictor[320], 16, 8);
    }
#endif
John Koleszar's avatar
John Koleszar committed
906
  } else {
Paul Wilkins's avatar
Paul Wilkins committed
907
908
    build_4x4uvmvs(xd);
    build_inter4x4_predictors_mb(xd);
John Koleszar's avatar
John Koleszar committed
909
  }
John Koleszar's avatar
John Koleszar committed
910
}