2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
13 #include "./vpx_scale_rtcd.h"
14 #include "./vpx_config.h"
16 #include "vpx/vpx_integer.h"
18 #include "vp10/common/blockd.h"
19 #include "vp10/common/reconinter.h"
20 #include "vp10/common/reconintra.h"
22 #if CONFIG_VP9_HIGHBITDEPTH
23 void vp10_highbd_build_inter_predictor(const uint8_t *src, int src_stride,
24 uint8_t *dst, int dst_stride,
26 const struct scale_factors *sf,
27 int w, int h, int ref,
28 const InterpKernel *kernel,
29 enum mv_precision precision,
30 int x, int y, int bd) {
31 const int is_q4 = precision == MV_PRECISION_Q4;
32 const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
33 is_q4 ? src_mv->col : src_mv->col * 2 };
34 MV32 mv = vp10_scale_mv(&mv_q4, x, y, sf);
35 const int subpel_x = mv.col & SUBPEL_MASK;
36 const int subpel_y = mv.row & SUBPEL_MASK;
38 src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
40 high_inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
41 sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4, bd);
43 #endif // CONFIG_VP9_HIGHBITDEPTH
45 void vp10_build_inter_predictor(const uint8_t *src, int src_stride,
46 uint8_t *dst, int dst_stride,
48 const struct scale_factors *sf,
49 int w, int h, int ref,
50 const InterpKernel *kernel,
51 enum mv_precision precision,
53 const int is_q4 = precision == MV_PRECISION_Q4;
54 const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
55 is_q4 ? src_mv->col : src_mv->col * 2 };
56 MV32 mv = vp10_scale_mv(&mv_q4, x, y, sf);
57 const int subpel_x = mv.col & SUBPEL_MASK;
58 const int subpel_y = mv.row & SUBPEL_MASK;
60 src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
62 inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
63 sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4);
66 void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
68 int x, int y, int w, int h,
70 struct macroblockd_plane *const pd = &xd->plane[plane];
71 const MODE_INFO *mi = xd->mi[0];
72 const int is_compound = has_second_ref(&mi->mbmi);
73 const InterpKernel *kernel = vp10_filter_kernels[mi->mbmi.interp_filter];
76 for (ref = 0; ref < 1 + is_compound; ++ref) {
77 const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
78 struct buf_2d *const pre_buf = &pd->pre[ref];
79 struct buf_2d *const dst_buf = &pd->dst;
80 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
81 const MV mv = mi->mbmi.sb_type < BLOCK_8X8
82 ? average_split_mvs(pd, mi, ref, block)
83 : mi->mbmi.mv[ref].as_mv;
85 // TODO(jkoleszar): This clamping is done in the incorrect place for the
86 // scaling case. It needs to be done on the scaled MV, not the pre-scaling
87 // MV. Note however that it performs the subsampling aware scaling so
88 // that the result is always q4.
89 // mv_precision precision is MV_PRECISION_Q4.
90 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh,
96 int xs, ys, subpel_x, subpel_y;
97 const int is_scaled = vp10_is_scaled(sf);
100 pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
101 scaled_mv = vp10_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
105 pre = pre_buf->buf + (y * pre_buf->stride + x);
106 scaled_mv.row = mv_q4.row;
107 scaled_mv.col = mv_q4.col;
110 subpel_x = scaled_mv.col & SUBPEL_MASK;
111 subpel_y = scaled_mv.row & SUBPEL_MASK;
112 pre += (scaled_mv.row >> SUBPEL_BITS) * pre_buf->stride
113 + (scaled_mv.col >> SUBPEL_BITS);
115 #if CONFIG_VP9_HIGHBITDEPTH
116 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
117 high_inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
118 subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys,
121 inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
122 subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
125 inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
126 subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
127 #endif // CONFIG_VP9_HIGHBITDEPTH
131 static void build_inter_predictors_for_planes(MACROBLOCKD *xd, BLOCK_SIZE bsize,
132 int mi_row, int mi_col,
133 int plane_from, int plane_to) {
135 const int mi_x = mi_col * MI_SIZE;
136 const int mi_y = mi_row * MI_SIZE;
137 for (plane = plane_from; plane <= plane_to; ++plane) {
138 const struct macroblockd_plane *pd = &xd->plane[plane];
139 const int bw = 4 * num_4x4_blocks_wide_lookup[bsize] >> pd->subsampling_x;
140 const int bh = 4 * num_4x4_blocks_high_lookup[bsize] >> pd->subsampling_y;
142 if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
143 const PARTITION_TYPE bp = bsize - xd->mi[0]->mbmi.sb_type;
144 const int have_vsplit = bp != PARTITION_HORZ;
145 const int have_hsplit = bp != PARTITION_VERT;
146 const int num_4x4_w = 2 >> ((!have_vsplit) | pd->subsampling_x);
147 const int num_4x4_h = 2 >> ((!have_hsplit) | pd->subsampling_y);
148 const int pw = 8 >> (have_vsplit | pd->subsampling_x);
149 const int ph = 8 >> (have_hsplit | pd->subsampling_y);
151 assert(bp != PARTITION_NONE && bp < PARTITION_TYPES);
152 assert(bsize == BLOCK_8X8);
153 assert(pw * num_4x4_w == bw && ph * num_4x4_h == bh);
154 for (y = 0; y < num_4x4_h; ++y)
155 for (x = 0; x < num_4x4_w; ++x)
156 build_inter_predictors(xd, plane, y * 2 + x, bw, bh,
157 4 * x, 4 * y, pw, ph, mi_x, mi_y);
159 build_inter_predictors(xd, plane, 0, bw, bh,
160 0, 0, bw, bh, mi_x, mi_y);
165 void vp10_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
167 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
170 void vp10_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
171 BLOCK_SIZE bsize, int plane) {
172 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, plane, plane);
175 void vp10_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
177 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
181 void vp10_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
183 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
187 void vp10_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
188 const YV12_BUFFER_CONFIG *src,
189 int mi_row, int mi_col) {
190 uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
192 const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
196 for (i = 0; i < MAX_MB_PLANE; ++i) {
197 struct macroblockd_plane *const pd = &planes[i];
198 setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
199 pd->subsampling_x, pd->subsampling_y);
203 void vp10_setup_pre_planes(MACROBLOCKD *xd, int idx,
204 const YV12_BUFFER_CONFIG *src,
205 int mi_row, int mi_col,
206 const struct scale_factors *sf) {
209 uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
211 const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
213 for (i = 0; i < MAX_MB_PLANE; ++i) {
214 struct macroblockd_plane *const pd = &xd->plane[i];
215 setup_pred_plane(&pd->pre[idx], buffers[i], strides[i], mi_row, mi_col,
216 sf, pd->subsampling_x, pd->subsampling_y);