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/vp9_blockd.h"
19 #include "vp10/common/vp9_reconinter.h"
20 #include "vp10/common/vp9_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 BLOCK_SIZE plane_bsize = get_plane_block_size(bsize,
140 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
141 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
142 const int bw = 4 * num_4x4_w;
143 const int bh = 4 * num_4x4_h;
145 if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
147 assert(bsize == BLOCK_8X8);
148 for (y = 0; y < num_4x4_h; ++y)
149 for (x = 0; x < num_4x4_w; ++x)
150 build_inter_predictors(xd, plane, i++, bw, bh,
151 4 * x, 4 * y, 4, 4, mi_x, mi_y);
153 build_inter_predictors(xd, plane, 0, bw, bh,
154 0, 0, bw, bh, mi_x, mi_y);
159 void vp10_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
161 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
164 void vp10_build_inter_predictors_sbp(MACROBLOCKD *xd, int mi_row, int mi_col,
165 BLOCK_SIZE bsize, int plane) {
166 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, plane, plane);
169 void vp10_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
171 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
175 void vp10_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
177 build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
181 void vp10_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
182 const YV12_BUFFER_CONFIG *src,
183 int mi_row, int mi_col) {
184 uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
186 const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
190 for (i = 0; i < MAX_MB_PLANE; ++i) {
191 struct macroblockd_plane *const pd = &planes[i];
192 setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
193 pd->subsampling_x, pd->subsampling_y);
197 void vp10_setup_pre_planes(MACROBLOCKD *xd, int idx,
198 const YV12_BUFFER_CONFIG *src,
199 int mi_row, int mi_col,
200 const struct scale_factors *sf) {
203 uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
205 const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
207 for (i = 0; i < MAX_MB_PLANE; ++i) {
208 struct macroblockd_plane *const pd = &xd->plane[i];
209 setup_pred_plane(&pd->pre[idx], buffers[i], strides[i], mi_row, mi_col,
210 sf, pd->subsampling_x, pd->subsampling_y);