Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / vp9 / common / vp9_reconinter.c
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  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.
9  */
10
11 #include <assert.h>
12
13 #include "./vpx_scale_rtcd.h"
14 #include "./vpx_config.h"
15
16 #include "vpx/vpx_integer.h"
17
18 #include "vp9/common/vp9_blockd.h"
19 #include "vp9/common/vp9_filter.h"
20 #include "vp9/common/vp9_reconinter.h"
21 #include "vp9/common/vp9_reconintra.h"
22
23 static void build_mc_border(const uint8_t *src, int src_stride,
24                             uint8_t *dst, int dst_stride,
25                             int x, int y, int b_w, int b_h, int w, int h) {
26   // Get a pointer to the start of the real data for this row.
27   const uint8_t *ref_row = src - x - y * src_stride;
28
29   if (y >= h)
30     ref_row += (h - 1) * src_stride;
31   else if (y > 0)
32     ref_row += y * src_stride;
33
34   do {
35     int right = 0, copy;
36     int left = x < 0 ? -x : 0;
37
38     if (left > b_w)
39       left = b_w;
40
41     if (x + b_w > w)
42       right = x + b_w - w;
43
44     if (right > b_w)
45       right = b_w;
46
47     copy = b_w - left - right;
48
49     if (left)
50       memset(dst, ref_row[0], left);
51
52     if (copy)
53       memcpy(dst + left, ref_row + x + left, copy);
54
55     if (right)
56       memset(dst + left + copy, ref_row[w - 1], right);
57
58     dst += dst_stride;
59     ++y;
60
61     if (y > 0 && y < h)
62       ref_row += src_stride;
63   } while (--b_h);
64 }
65
66 #if CONFIG_VP9_HIGHBITDEPTH
67 static void high_build_mc_border(const uint8_t *src8, int src_stride,
68                                  uint16_t *dst, int dst_stride,
69                                  int x, int y, int b_w, int b_h,
70                                  int w, int h) {
71   // Get a pointer to the start of the real data for this row.
72   const uint16_t *src = CONVERT_TO_SHORTPTR(src8);
73   const uint16_t *ref_row = src - x - y * src_stride;
74
75   if (y >= h)
76     ref_row += (h - 1) * src_stride;
77   else if (y > 0)
78     ref_row += y * src_stride;
79
80   do {
81     int right = 0, copy;
82     int left = x < 0 ? -x : 0;
83
84     if (left > b_w)
85       left = b_w;
86
87     if (x + b_w > w)
88       right = x + b_w - w;
89
90     if (right > b_w)
91       right = b_w;
92
93     copy = b_w - left - right;
94
95     if (left)
96       vpx_memset16(dst, ref_row[0], left);
97
98     if (copy)
99       memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t));
100
101     if (right)
102       vpx_memset16(dst + left + copy, ref_row[w - 1], right);
103
104     dst += dst_stride;
105     ++y;
106
107     if (y > 0 && y < h)
108       ref_row += src_stride;
109   } while (--b_h);
110 }
111 #endif  // CONFIG_VP9_HIGHBITDEPTH
112
113 static void inter_predictor(const uint8_t *src, int src_stride,
114                             uint8_t *dst, int dst_stride,
115                             const int subpel_x,
116                             const int subpel_y,
117                             const struct scale_factors *sf,
118                             int w, int h, int ref,
119                             const InterpKernel *kernel,
120                             int xs, int ys) {
121   sf->predict[subpel_x != 0][subpel_y != 0][ref](
122       src, src_stride, dst, dst_stride,
123       kernel[subpel_x], xs, kernel[subpel_y], ys, w, h);
124 }
125
126 void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
127                                uint8_t *dst, int dst_stride,
128                                const MV *src_mv,
129                                const struct scale_factors *sf,
130                                int w, int h, int ref,
131                                const InterpKernel *kernel,
132                                enum mv_precision precision,
133                                int x, int y) {
134   const int is_q4 = precision == MV_PRECISION_Q4;
135   const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
136                      is_q4 ? src_mv->col : src_mv->col * 2 };
137   MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf);
138   const int subpel_x = mv.col & SUBPEL_MASK;
139   const int subpel_y = mv.row & SUBPEL_MASK;
140
141   src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
142
143   inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
144                   sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4);
145 }
146
147 #if CONFIG_VP9_HIGHBITDEPTH
148 static void high_inter_predictor(const uint8_t *src, int src_stride,
149                                  uint8_t *dst, int dst_stride,
150                                  const int subpel_x,
151                                  const int subpel_y,
152                                  const struct scale_factors *sf,
153                                  int w, int h, int ref,
154                                  const InterpKernel *kernel,
155                                  int xs, int ys, int bd) {
156   sf->high_predict[subpel_x != 0][subpel_y != 0][ref](
157       src, src_stride, dst, dst_stride,
158       kernel[subpel_x], xs, kernel[subpel_y], ys, w, h, bd);
159 }
160
161 void vp9_high_build_inter_predictor(const uint8_t *src, int src_stride,
162                                     uint8_t *dst, int dst_stride,
163                                     const MV *src_mv,
164                                     const struct scale_factors *sf,
165                                     int w, int h, int ref,
166                                     const InterpKernel *kernel,
167                                     enum mv_precision precision,
168                                     int x, int y, int bd) {
169   const int is_q4 = precision == MV_PRECISION_Q4;
170   const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
171                      is_q4 ? src_mv->col : src_mv->col * 2 };
172   MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf);
173   const int subpel_x = mv.col & SUBPEL_MASK;
174   const int subpel_y = mv.row & SUBPEL_MASK;
175
176   src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
177
178   high_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
179                        sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4, bd);
180 }
181 #endif  // CONFIG_VP9_HIGHBITDEPTH
182
183 static INLINE int round_mv_comp_q4(int value) {
184   return (value < 0 ? value - 2 : value + 2) / 4;
185 }
186
187 static MV mi_mv_pred_q4(const MODE_INFO *mi, int idx) {
188   MV res = { round_mv_comp_q4(mi->bmi[0].as_mv[idx].as_mv.row +
189                               mi->bmi[1].as_mv[idx].as_mv.row +
190                               mi->bmi[2].as_mv[idx].as_mv.row +
191                               mi->bmi[3].as_mv[idx].as_mv.row),
192              round_mv_comp_q4(mi->bmi[0].as_mv[idx].as_mv.col +
193                               mi->bmi[1].as_mv[idx].as_mv.col +
194                               mi->bmi[2].as_mv[idx].as_mv.col +
195                               mi->bmi[3].as_mv[idx].as_mv.col) };
196   return res;
197 }
198
199 static INLINE int round_mv_comp_q2(int value) {
200   return (value < 0 ? value - 1 : value + 1) / 2;
201 }
202
203 static MV mi_mv_pred_q2(const MODE_INFO *mi, int idx, int block0, int block1) {
204   MV res = { round_mv_comp_q2(mi->bmi[block0].as_mv[idx].as_mv.row +
205                               mi->bmi[block1].as_mv[idx].as_mv.row),
206              round_mv_comp_q2(mi->bmi[block0].as_mv[idx].as_mv.col +
207                               mi->bmi[block1].as_mv[idx].as_mv.col) };
208   return res;
209 }
210
211 // TODO(jkoleszar): yet another mv clamping function :-(
212 MV clamp_mv_to_umv_border_sb(const MACROBLOCKD *xd, const MV *src_mv,
213                              int bw, int bh, int ss_x, int ss_y) {
214   // If the MV points so far into the UMV border that no visible pixels
215   // are used for reconstruction, the subpel part of the MV can be
216   // discarded and the MV limited to 16 pixels with equivalent results.
217   const int spel_left = (VP9_INTERP_EXTEND + bw) << SUBPEL_BITS;
218   const int spel_right = spel_left - SUBPEL_SHIFTS;
219   const int spel_top = (VP9_INTERP_EXTEND + bh) << SUBPEL_BITS;
220   const int spel_bottom = spel_top - SUBPEL_SHIFTS;
221   MV clamped_mv = {
222     src_mv->row * (1 << (1 - ss_y)),
223     src_mv->col * (1 << (1 - ss_x))
224   };
225   assert(ss_x <= 1);
226   assert(ss_y <= 1);
227
228   clamp_mv(&clamped_mv,
229            xd->mb_to_left_edge * (1 << (1 - ss_x)) - spel_left,
230            xd->mb_to_right_edge * (1 << (1 - ss_x)) + spel_right,
231            xd->mb_to_top_edge * (1 << (1 - ss_y)) - spel_top,
232            xd->mb_to_bottom_edge * (1 << (1 - ss_y)) + spel_bottom);
233
234   return clamped_mv;
235 }
236
237 static MV average_split_mvs(const struct macroblockd_plane *pd,
238                             const MODE_INFO *mi, int ref, int block) {
239   const int ss_idx = ((pd->subsampling_x > 0) << 1) | (pd->subsampling_y > 0);
240   MV res = {0, 0};
241   switch (ss_idx) {
242     case 0:
243       res = mi->bmi[block].as_mv[ref].as_mv;
244       break;
245     case 1:
246       res = mi_mv_pred_q2(mi, ref, block, block + 2);
247       break;
248     case 2:
249       res = mi_mv_pred_q2(mi, ref, block, block + 1);
250       break;
251     case 3:
252       res = mi_mv_pred_q4(mi, ref);
253       break;
254     default:
255       assert(ss_idx <= 3 || ss_idx >= 0);
256   }
257   return res;
258 }
259
260 static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
261                                    int bw, int bh,
262                                    int x, int y, int w, int h,
263                                    int mi_x, int mi_y) {
264   struct macroblockd_plane *const pd = &xd->plane[plane];
265   const MODE_INFO *mi = xd->mi[0].src_mi;
266   const int is_compound = has_second_ref(&mi->mbmi);
267   const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
268   int ref;
269
270   for (ref = 0; ref < 1 + is_compound; ++ref) {
271     const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
272     struct buf_2d *const pre_buf = &pd->pre[ref];
273     struct buf_2d *const dst_buf = &pd->dst;
274     uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
275     const MV mv = mi->mbmi.sb_type < BLOCK_8X8
276                ? average_split_mvs(pd, mi, ref, block)
277                : mi->mbmi.mv[ref].as_mv;
278
279     // TODO(jkoleszar): This clamping is done in the incorrect place for the
280     // scaling case. It needs to be done on the scaled MV, not the pre-scaling
281     // MV. Note however that it performs the subsampling aware scaling so
282     // that the result is always q4.
283     // mv_precision precision is MV_PRECISION_Q4.
284     const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh,
285                                                pd->subsampling_x,
286                                                pd->subsampling_y);
287
288     uint8_t *pre;
289     MV32 scaled_mv;
290     int xs, ys, subpel_x, subpel_y;
291
292     if (vp9_is_scaled(sf)) {
293       pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
294       scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
295       xs = sf->x_step_q4;
296       ys = sf->y_step_q4;
297     } else {
298       pre = pre_buf->buf + (y * pre_buf->stride + x);
299       scaled_mv.row = mv_q4.row;
300       scaled_mv.col = mv_q4.col;
301       xs = ys = 16;
302     }
303     subpel_x = scaled_mv.col & SUBPEL_MASK;
304     subpel_y = scaled_mv.row & SUBPEL_MASK;
305     pre += (scaled_mv.row >> SUBPEL_BITS) * pre_buf->stride
306            + (scaled_mv.col >> SUBPEL_BITS);
307
308 #if CONFIG_VP9_HIGHBITDEPTH
309     if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
310       high_inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
311                            subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys,
312                            xd->bd);
313     } else {
314       inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
315                       subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
316     }
317 #else
318     inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
319                     subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
320 #endif  // CONFIG_VP9_HIGHBITDEPTH
321   }
322 }
323
324 static void build_inter_predictors_for_planes(MACROBLOCKD *xd, BLOCK_SIZE bsize,
325                                               int mi_row, int mi_col,
326                                               int plane_from, int plane_to) {
327   int plane;
328   const int mi_x = mi_col * MI_SIZE;
329   const int mi_y = mi_row * MI_SIZE;
330   for (plane = plane_from; plane <= plane_to; ++plane) {
331     const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
332                                                         &xd->plane[plane]);
333     const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
334     const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
335     const int bw = 4 * num_4x4_w;
336     const int bh = 4 * num_4x4_h;
337
338     if (xd->mi[0].src_mi->mbmi.sb_type < BLOCK_8X8) {
339       int i = 0, x, y;
340       assert(bsize == BLOCK_8X8);
341       for (y = 0; y < num_4x4_h; ++y)
342         for (x = 0; x < num_4x4_w; ++x)
343            build_inter_predictors(xd, plane, i++, bw, bh,
344                                   4 * x, 4 * y, 4, 4, mi_x, mi_y);
345     } else {
346       build_inter_predictors(xd, plane, 0, bw, bh,
347                              0, 0, bw, bh, mi_x, mi_y);
348     }
349   }
350 }
351
352 void vp9_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
353                                     BLOCK_SIZE bsize) {
354   build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
355 }
356 void vp9_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
357                                      BLOCK_SIZE bsize) {
358   build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
359                                     MAX_MB_PLANE - 1);
360 }
361 void vp9_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
362                                    BLOCK_SIZE bsize) {
363   build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
364                                     MAX_MB_PLANE - 1);
365 }
366
367 // TODO(jingning): This function serves as a placeholder for decoder prediction
368 // using on demand border extension. It should be moved to /decoder/ directory.
369 static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
370                                        int bw, int bh,
371                                        int x, int y, int w, int h,
372                                        int mi_x, int mi_y) {
373   struct macroblockd_plane *const pd = &xd->plane[plane];
374   const MODE_INFO *mi = xd->mi[0].src_mi;
375   const int is_compound = has_second_ref(&mi->mbmi);
376   const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
377   int ref;
378
379   for (ref = 0; ref < 1 + is_compound; ++ref) {
380     const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
381     struct buf_2d *const pre_buf = &pd->pre[ref];
382     struct buf_2d *const dst_buf = &pd->dst;
383     uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
384     const MV mv = mi->mbmi.sb_type < BLOCK_8X8
385                ? average_split_mvs(pd, mi, ref, block)
386                : mi->mbmi.mv[ref].as_mv;
387
388
389     // TODO(jkoleszar): This clamping is done in the incorrect place for the
390     // scaling case. It needs to be done on the scaled MV, not the pre-scaling
391     // MV. Note however that it performs the subsampling aware scaling so
392     // that the result is always q4.
393     // mv_precision precision is MV_PRECISION_Q4.
394     const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh,
395                                                pd->subsampling_x,
396                                                pd->subsampling_y);
397
398     MV32 scaled_mv;
399     int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, buf_stride,
400         subpel_x, subpel_y;
401     uint8_t *ref_frame, *buf_ptr;
402     const YV12_BUFFER_CONFIG *ref_buf = xd->block_refs[ref]->buf;
403
404     // Get reference frame pointer, width and height.
405     if (plane == 0) {
406       frame_width = ref_buf->y_crop_width;
407       frame_height = ref_buf->y_crop_height;
408       ref_frame = ref_buf->y_buffer;
409     } else {
410       frame_width = ref_buf->uv_crop_width;
411       frame_height = ref_buf->uv_crop_height;
412       ref_frame = plane == 1 ? ref_buf->u_buffer : ref_buf->v_buffer;
413     }
414
415     if (vp9_is_scaled(sf)) {
416       // Co-ordinate of containing block to pixel precision.
417       int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
418       int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
419
420       // Co-ordinate of the block to 1/16th pixel precision.
421       x0_16 = (x_start + x) << SUBPEL_BITS;
422       y0_16 = (y_start + y) << SUBPEL_BITS;
423
424       // Co-ordinate of current block in reference frame
425       // to 1/16th pixel precision.
426       x0_16 = sf->scale_value_x(x0_16, sf);
427       y0_16 = sf->scale_value_y(y0_16, sf);
428
429       // Map the top left corner of the block into the reference frame.
430       x0 = sf->scale_value_x(x_start + x, sf);
431       y0 = sf->scale_value_y(y_start + y, sf);
432
433       // Scale the MV and incorporate the sub-pixel offset of the block
434       // in the reference frame.
435       scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
436       xs = sf->x_step_q4;
437       ys = sf->y_step_q4;
438     } else {
439       // Co-ordinate of containing block to pixel precision.
440       x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x;
441       y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y;
442
443       // Co-ordinate of the block to 1/16th pixel precision.
444       x0_16 = x0 << SUBPEL_BITS;
445       y0_16 = y0 << SUBPEL_BITS;
446
447       scaled_mv.row = mv_q4.row;
448       scaled_mv.col = mv_q4.col;
449       xs = ys = 16;
450     }
451     subpel_x = scaled_mv.col & SUBPEL_MASK;
452     subpel_y = scaled_mv.row & SUBPEL_MASK;
453
454     // Calculate the top left corner of the best matching block in the reference frame.
455     x0 += scaled_mv.col >> SUBPEL_BITS;
456     y0 += scaled_mv.row >> SUBPEL_BITS;
457     x0_16 += scaled_mv.col;
458     y0_16 += scaled_mv.row;
459
460     // Get reference block pointer.
461     buf_ptr = ref_frame + y0 * pre_buf->stride + x0;
462     buf_stride = pre_buf->stride;
463
464     // Do border extension if there is motion or the
465     // width/height is not a multiple of 8 pixels.
466     if (scaled_mv.col || scaled_mv.row ||
467         (frame_width & 0x7) || (frame_height & 0x7)) {
468       // Get reference block bottom right coordinate.
469       int x1 = ((x0_16 + (w - 1) * xs) >> SUBPEL_BITS) + 1;
470       int y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1;
471       int x_pad = 0, y_pad = 0;
472
473       if (subpel_x || (sf->x_step_q4 & SUBPEL_MASK)) {
474         x0 -= VP9_INTERP_EXTEND - 1;
475         x1 += VP9_INTERP_EXTEND;
476         x_pad = 1;
477       }
478
479       if (subpel_y || (sf->y_step_q4 & SUBPEL_MASK)) {
480         y0 -= VP9_INTERP_EXTEND - 1;
481         y1 += VP9_INTERP_EXTEND;
482         y_pad = 1;
483       }
484
485       // Skip border extension if block is inside the frame.
486       if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 ||
487           y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) {
488         uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0;
489         // Extend the border.
490 #if CONFIG_VP9_HIGHBITDEPTH
491         if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
492           high_build_mc_border(buf_ptr1,
493                                pre_buf->stride,
494                                xd->mc_buf_high,
495                                x1 - x0 + 1,
496                                x0,
497                                y0,
498                                x1 - x0 + 1,
499                                y1 - y0 + 1,
500                                frame_width,
501                                frame_height);
502           buf_stride = x1 - x0 + 1;
503           buf_ptr = CONVERT_TO_BYTEPTR(xd->mc_buf_high) +
504               y_pad * 3 * buf_stride + x_pad * 3;
505         } else {
506           build_mc_border(buf_ptr1,
507                           pre_buf->stride,
508                           xd->mc_buf,
509                           x1 - x0 + 1,
510                           x0,
511                           y0,
512                           x1 - x0 + 1,
513                           y1 - y0 + 1,
514                           frame_width,
515                           frame_height);
516           buf_stride = x1 - x0 + 1;
517           buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3;
518         }
519 #else
520         build_mc_border(buf_ptr1,
521                         pre_buf->stride,
522                         xd->mc_buf,
523                         x1 - x0 + 1,
524                         x0,
525                         y0,
526                         x1 - x0 + 1,
527                         y1 - y0 + 1,
528                         frame_width,
529                         frame_height);
530         buf_stride = x1 - x0 + 1;
531         buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3;
532 #endif  // CONFIG_VP9_HIGHBITDEPTH
533       }
534     }
535
536 #if CONFIG_VP9_HIGHBITDEPTH
537     if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
538       high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
539                            subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd);
540     } else {
541       inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
542                     subpel_y, sf, w, h, ref, kernel, xs, ys);
543     }
544 #else
545     inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
546                     subpel_y, sf, w, h, ref, kernel, xs, ys);
547 #endif  // CONFIG_VP9_HIGHBITDEPTH
548   }
549 }
550
551 void vp9_dec_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
552                                        BLOCK_SIZE bsize) {
553   int plane;
554   const int mi_x = mi_col * MI_SIZE;
555   const int mi_y = mi_row * MI_SIZE;
556   for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
557     const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
558                                                         &xd->plane[plane]);
559     const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
560     const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
561     const int bw = 4 * num_4x4_w;
562     const int bh = 4 * num_4x4_h;
563
564     if (xd->mi[0].src_mi->mbmi.sb_type < BLOCK_8X8) {
565       int i = 0, x, y;
566       assert(bsize == BLOCK_8X8);
567       for (y = 0; y < num_4x4_h; ++y)
568         for (x = 0; x < num_4x4_w; ++x)
569           dec_build_inter_predictors(xd, plane, i++, bw, bh,
570                                      4 * x, 4 * y, 4, 4, mi_x, mi_y);
571     } else {
572       dec_build_inter_predictors(xd, plane, 0, bw, bh,
573                                  0, 0, bw, bh, mi_x, mi_y);
574     }
575   }
576 }
577
578 void vp9_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
579                           const YV12_BUFFER_CONFIG *src,
580                           int mi_row, int mi_col) {
581   uint8_t *const buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer,
582                                src->alpha_buffer};
583   const int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride,
584                           src->alpha_stride};
585   int i;
586
587   for (i = 0; i < MAX_MB_PLANE; ++i) {
588     struct macroblockd_plane *const pd = &planes[i];
589     setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
590                      pd->subsampling_x, pd->subsampling_y);
591   }
592 }
593
594 void vp9_setup_pre_planes(MACROBLOCKD *xd, int idx,
595                           const YV12_BUFFER_CONFIG *src,
596                           int mi_row, int mi_col,
597                           const struct scale_factors *sf) {
598   if (src != NULL) {
599     int i;
600     uint8_t *const buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer,
601                                  src->alpha_buffer};
602     const int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride,
603                             src->alpha_stride};
604
605     for (i = 0; i < MAX_MB_PLANE; ++i) {
606       struct macroblockd_plane *const pd = &xd->plane[i];
607       setup_pred_plane(&pd->pre[idx], buffers[i], strides[i], mi_row, mi_col,
608                        sf, pd->subsampling_x, pd->subsampling_y);
609     }
610   }
611 }