2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
Convert subpixel filters to use convolve framework
Update the code to call the new convolution functions to do subpixel
prediction rather than the existing functions. Remove the old C and
assembly code, since it is unused. This causes a 50% performance
reduction on the decoder, but that will be resolved when the asm for
the new functions is available.
There is no consensus for whether 6-tap or 2-tap predictors will be
supported in the final codec, so these filters are implemented in
terms of the 8-tap code, so that quality testing of these modes
can continue. Implementing the lower complexity algorithms is a
simple exercise, should it be necessary.
This code produces slightly better results in the EIGHTTAP_SMOOTH
case, since the filter is now applied in only one direction when
the subpel motion is only in one direction. Like the previous code,
the filtering is skipped entirely on full-pel MVs. This combination
seems to give the best quality gains, but this may be indicative of a
bug in the encoder's filter selection, since the encoder could
achieve the result of skipping the filtering on full-pel by selecting
one of the other filters. This should be revisited.
Quality gains on derf positive on almost all clips. The only clip
that seemed to be hurt at all datarates was football
(-0.115% PSNR average, -0.587% min). Overall averages 0.375% PSNR,
0.347% SSIM.
Change-Id: I7d469716091b1d89b4b08adde5863999319d69ff
2013-01-29 01:59:03 +01:00
|
|
|
#include <assert.h>
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-08-09 23:07:09 +02:00
|
|
|
#include "./vpx_scale_rtcd.h"
|
2012-12-23 16:20:10 +01:00
|
|
|
#include "./vpx_config.h"
|
2013-08-09 23:07:09 +02:00
|
|
|
|
2011-07-25 16:11:24 +02:00
|
|
|
#include "vpx/vpx_integer.h"
|
2013-08-09 23:07:09 +02:00
|
|
|
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_blockd.h"
|
Convert subpixel filters to use convolve framework
Update the code to call the new convolution functions to do subpixel
prediction rather than the existing functions. Remove the old C and
assembly code, since it is unused. This causes a 50% performance
reduction on the decoder, but that will be resolved when the asm for
the new functions is available.
There is no consensus for whether 6-tap or 2-tap predictors will be
supported in the final codec, so these filters are implemented in
terms of the 8-tap code, so that quality testing of these modes
can continue. Implementing the lower complexity algorithms is a
simple exercise, should it be necessary.
This code produces slightly better results in the EIGHTTAP_SMOOTH
case, since the filter is now applied in only one direction when
the subpel motion is only in one direction. Like the previous code,
the filtering is skipped entirely on full-pel MVs. This combination
seems to give the best quality gains, but this may be indicative of a
bug in the encoder's filter selection, since the encoder could
achieve the result of skipping the filtering on full-pel by selecting
one of the other filters. This should be revisited.
Quality gains on derf positive on almost all clips. The only clip
that seemed to be hurt at all datarates was football
(-0.115% PSNR average, -0.587% min). Overall averages 0.375% PSNR,
0.347% SSIM.
Change-Id: I7d469716091b1d89b4b08adde5863999319d69ff
2013-01-29 01:59:03 +01:00
|
|
|
#include "vp9/common/vp9_filter.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_reconinter.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_reconintra.h"
|
2013-05-15 02:49:41 +02:00
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
static void build_mc_border(const uint8_t *src, int src_stride,
|
|
|
|
uint8_t *dst, int dst_stride,
|
|
|
|
int x, int y, int b_w, int b_h, int w, int h) {
|
2013-12-06 20:39:38 +01:00
|
|
|
// Get a pointer to the start of the real data for this row.
|
2014-01-13 23:14:44 +01:00
|
|
|
const uint8_t *ref_row = src - x - y * src_stride;
|
2013-12-06 20:39:38 +01:00
|
|
|
|
|
|
|
if (y >= h)
|
2014-01-13 23:14:44 +01:00
|
|
|
ref_row += (h - 1) * src_stride;
|
2013-12-06 20:39:38 +01:00
|
|
|
else if (y > 0)
|
2014-01-13 23:14:44 +01:00
|
|
|
ref_row += y * src_stride;
|
2013-12-06 20:39:38 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
int right = 0, copy;
|
|
|
|
int left = x < 0 ? -x : 0;
|
|
|
|
|
|
|
|
if (left > b_w)
|
|
|
|
left = b_w;
|
|
|
|
|
|
|
|
if (x + b_w > w)
|
|
|
|
right = x + b_w - w;
|
|
|
|
|
|
|
|
if (right > b_w)
|
|
|
|
right = b_w;
|
|
|
|
|
|
|
|
copy = b_w - left - right;
|
|
|
|
|
|
|
|
if (left)
|
|
|
|
memset(dst, ref_row[0], left);
|
|
|
|
|
|
|
|
if (copy)
|
2014-01-13 23:14:44 +01:00
|
|
|
memcpy(dst + left, ref_row + x + left, copy);
|
2013-12-06 20:39:38 +01:00
|
|
|
|
|
|
|
if (right)
|
|
|
|
memset(dst + left + copy, ref_row[w - 1], right);
|
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
dst += dst_stride;
|
2013-12-06 20:39:38 +01:00
|
|
|
++y;
|
|
|
|
|
|
|
|
if (y > 0 && y < h)
|
2014-01-13 23:14:44 +01:00
|
|
|
ref_row += src_stride;
|
2013-12-06 20:39:38 +01:00
|
|
|
} while (--b_h);
|
|
|
|
}
|
2012-07-18 22:43:01 +02:00
|
|
|
|
2013-10-18 17:56:30 +02:00
|
|
|
static void inter_predictor(const uint8_t *src, int src_stride,
|
|
|
|
uint8_t *dst, int dst_stride,
|
2013-12-10 19:36:44 +01:00
|
|
|
const int subpel_x,
|
|
|
|
const int subpel_y,
|
2013-12-20 01:06:33 +01:00
|
|
|
const struct scale_factors *sf,
|
2013-10-18 17:56:30 +02:00
|
|
|
int w, int h, int ref,
|
2014-02-04 01:48:38 +01:00
|
|
|
const InterpKernel *kernel,
|
2013-10-18 17:56:30 +02:00
|
|
|
int xs, int ys) {
|
2013-12-20 01:06:33 +01:00
|
|
|
sf->predict[subpel_x != 0][subpel_y != 0][ref](
|
2013-10-18 17:56:30 +02:00
|
|
|
src, src_stride, dst, dst_stride,
|
2014-01-25 02:06:26 +01:00
|
|
|
kernel[subpel_x], xs, kernel[subpel_y], ys, w, h);
|
2013-10-18 17:56:30 +02:00
|
|
|
}
|
|
|
|
|
2013-02-09 02:49:44 +01:00
|
|
|
void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
|
|
|
|
uint8_t *dst, int dst_stride,
|
2013-08-03 00:26:32 +02:00
|
|
|
const MV *src_mv,
|
2013-12-20 01:06:33 +01:00
|
|
|
const struct scale_factors *sf,
|
2013-08-12 22:54:13 +02:00
|
|
|
int w, int h, int ref,
|
2014-02-04 01:48:38 +01:00
|
|
|
const InterpKernel *kernel,
|
2013-12-19 20:16:05 +01:00
|
|
|
enum mv_precision precision,
|
|
|
|
int x, int y) {
|
2013-08-07 00:43:56 +02:00
|
|
|
const int is_q4 = precision == MV_PRECISION_Q4;
|
2013-09-18 01:31:46 +02:00
|
|
|
const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
|
|
|
|
is_q4 ? src_mv->col : src_mv->col * 2 };
|
2013-12-20 01:06:33 +01:00
|
|
|
MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf);
|
|
|
|
const int subpel_x = mv.col & SUBPEL_MASK;
|
|
|
|
const int subpel_y = mv.row & SUBPEL_MASK;
|
2013-12-19 20:16:05 +01:00
|
|
|
|
2013-12-10 19:36:44 +01:00
|
|
|
src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
|
2013-08-07 00:43:56 +02:00
|
|
|
|
2013-12-10 19:36:44 +01:00
|
|
|
inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
|
2014-01-25 02:06:26 +01:00
|
|
|
sf, w, h, ref, kernel, sf->x_step_q4, sf->y_step_q4);
|
2012-04-18 22:51:58 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 22:41:18 +02:00
|
|
|
static INLINE int round_mv_comp_q4(int value) {
|
|
|
|
return (value < 0 ? value - 2 : value + 2) / 4;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-08-03 01:53:18 +02:00
|
|
|
static MV mi_mv_pred_q4(const MODE_INFO *mi, int idx) {
|
|
|
|
MV res = { round_mv_comp_q4(mi->bmi[0].as_mv[idx].as_mv.row +
|
|
|
|
mi->bmi[1].as_mv[idx].as_mv.row +
|
|
|
|
mi->bmi[2].as_mv[idx].as_mv.row +
|
|
|
|
mi->bmi[3].as_mv[idx].as_mv.row),
|
|
|
|
round_mv_comp_q4(mi->bmi[0].as_mv[idx].as_mv.col +
|
|
|
|
mi->bmi[1].as_mv[idx].as_mv.col +
|
|
|
|
mi->bmi[2].as_mv[idx].as_mv.col +
|
|
|
|
mi->bmi[3].as_mv[idx].as_mv.col) };
|
|
|
|
return res;
|
2013-04-17 21:24:51 +02:00
|
|
|
}
|
|
|
|
|
make buid_inter_predictors block size agnostic (luma)
This commit converts the luma versions of vp9_build_inter_predictors_sb
to use a common function. Update the convolution functions to support
block sizes larger than 16x16, and add a foreach_predicted_block walker.
Next step will be to calculate the UV motion vector and implement SBUV,
then fold in vp9_build_inter16x16_predictors_mb and SPLITMV.
At the 16x16, 32x32, and 64x64 levels implemented in this commit, each
plane is predicted with only a single call to vp9_build_inter_predictor.
This is not yet called for SPLITMV. If the notion of SPLITMV/I8X8/I4X4
goes away, then the prediction block walker can go away, since we'll
always predict the whole bsize in a single step. Implemented using a
block walker at this stage for SPLITMV, as a 4x4 "prediction block size"
within the BLOCK_SIZE_MB16X16 macroblock. It would also support other
rectangular sizes too, if the blocks smaller than 16x16 remain
implemented as a SPLITMV-like thing. Just using 4x4 for now.
There's also a potential to combine with the foreach_transformed_block
walker if the logic for calculating the size of the subsampled
transform is made more straightforward, perhaps as a consequence of
supporing smaller macroblocks than 16x16. Will watch what happens there.
Change-Id: Iddd9973398542216601b630c628b9b7fdee33fe2
2013-04-13 02:19:57 +02:00
|
|
|
// TODO(jkoleszar): yet another mv clamping function :-(
|
2013-08-08 02:02:28 +02:00
|
|
|
MV clamp_mv_to_umv_border_sb(const MACROBLOCKD *xd, const MV *src_mv,
|
|
|
|
int bw, int bh, int ss_x, int ss_y) {
|
2013-08-02 00:06:34 +02:00
|
|
|
// 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.
|
2013-08-08 02:02:28 +02:00
|
|
|
const int spel_left = (VP9_INTERP_EXTEND + bw) << SUBPEL_BITS;
|
|
|
|
const int spel_right = spel_left - SUBPEL_SHIFTS;
|
|
|
|
const int spel_top = (VP9_INTERP_EXTEND + bh) << SUBPEL_BITS;
|
|
|
|
const int spel_bottom = spel_top - SUBPEL_SHIFTS;
|
2013-08-02 00:06:34 +02:00
|
|
|
MV clamped_mv = {
|
2013-09-18 01:31:46 +02:00
|
|
|
src_mv->row * (1 << (1 - ss_y)),
|
|
|
|
src_mv->col * (1 << (1 - ss_x))
|
2013-08-02 00:06:34 +02:00
|
|
|
};
|
2013-04-17 01:26:26 +02:00
|
|
|
assert(ss_x <= 1);
|
|
|
|
assert(ss_y <= 1);
|
2013-08-02 00:06:34 +02:00
|
|
|
|
2013-09-18 01:31:46 +02:00
|
|
|
clamp_mv(&clamped_mv,
|
|
|
|
xd->mb_to_left_edge * (1 << (1 - ss_x)) - spel_left,
|
|
|
|
xd->mb_to_right_edge * (1 << (1 - ss_x)) + spel_right,
|
|
|
|
xd->mb_to_top_edge * (1 << (1 - ss_y)) - spel_top,
|
|
|
|
xd->mb_to_bottom_edge * (1 << (1 - ss_y)) + spel_bottom);
|
2013-08-02 00:06:34 +02:00
|
|
|
|
make buid_inter_predictors block size agnostic (luma)
This commit converts the luma versions of vp9_build_inter_predictors_sb
to use a common function. Update the convolution functions to support
block sizes larger than 16x16, and add a foreach_predicted_block walker.
Next step will be to calculate the UV motion vector and implement SBUV,
then fold in vp9_build_inter16x16_predictors_mb and SPLITMV.
At the 16x16, 32x32, and 64x64 levels implemented in this commit, each
plane is predicted with only a single call to vp9_build_inter_predictor.
This is not yet called for SPLITMV. If the notion of SPLITMV/I8X8/I4X4
goes away, then the prediction block walker can go away, since we'll
always predict the whole bsize in a single step. Implemented using a
block walker at this stage for SPLITMV, as a 4x4 "prediction block size"
within the BLOCK_SIZE_MB16X16 macroblock. It would also support other
rectangular sizes too, if the blocks smaller than 16x16 remain
implemented as a SPLITMV-like thing. Just using 4x4 for now.
There's also a potential to combine with the foreach_transformed_block
walker if the logic for calculating the size of the subsampled
transform is made more straightforward, perhaps as a consequence of
supporing smaller macroblocks than 16x16. Will watch what happens there.
Change-Id: Iddd9973398542216601b630c628b9b7fdee33fe2
2013-04-13 02:19:57 +02:00
|
|
|
return clamped_mv;
|
|
|
|
}
|
|
|
|
|
2013-11-12 03:37:00 +01:00
|
|
|
static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
|
2013-12-04 21:11:01 +01:00
|
|
|
int bw, int bh,
|
|
|
|
int x, int y, int w, int h,
|
2013-11-12 03:37:00 +01:00
|
|
|
int mi_x, int mi_y) {
|
2013-08-08 02:02:28 +02:00
|
|
|
struct macroblockd_plane *const pd = &xd->plane[plane];
|
2014-04-02 01:18:47 +02:00
|
|
|
const MODE_INFO *mi = xd->mi[0];
|
2013-09-26 04:03:04 +02:00
|
|
|
const int is_compound = has_second_ref(&mi->mbmi);
|
2014-04-04 00:28:42 +02:00
|
|
|
const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
|
2013-08-12 22:54:13 +02:00
|
|
|
int ref;
|
make buid_inter_predictors block size agnostic (luma)
This commit converts the luma versions of vp9_build_inter_predictors_sb
to use a common function. Update the convolution functions to support
block sizes larger than 16x16, and add a foreach_predicted_block walker.
Next step will be to calculate the UV motion vector and implement SBUV,
then fold in vp9_build_inter16x16_predictors_mb and SPLITMV.
At the 16x16, 32x32, and 64x64 levels implemented in this commit, each
plane is predicted with only a single call to vp9_build_inter_predictor.
This is not yet called for SPLITMV. If the notion of SPLITMV/I8X8/I4X4
goes away, then the prediction block walker can go away, since we'll
always predict the whole bsize in a single step. Implemented using a
block walker at this stage for SPLITMV, as a 4x4 "prediction block size"
within the BLOCK_SIZE_MB16X16 macroblock. It would also support other
rectangular sizes too, if the blocks smaller than 16x16 remain
implemented as a SPLITMV-like thing. Just using 4x4 for now.
There's also a potential to combine with the foreach_transformed_block
walker if the logic for calculating the size of the subsampled
transform is made more straightforward, perhaps as a consequence of
supporing smaller macroblocks than 16x16. Will watch what happens there.
Change-Id: Iddd9973398542216601b630c628b9b7fdee33fe2
2013-04-13 02:19:57 +02:00
|
|
|
|
2013-09-26 04:03:04 +02:00
|
|
|
for (ref = 0; ref < 1 + is_compound; ++ref) {
|
2013-12-28 03:44:19 +01:00
|
|
|
const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
|
2013-08-16 21:51:20 +02:00
|
|
|
struct buf_2d *const pre_buf = &pd->pre[ref];
|
|
|
|
struct buf_2d *const dst_buf = &pd->dst;
|
2013-08-09 06:25:48 +02:00
|
|
|
uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
|
2013-04-17 22:41:18 +02:00
|
|
|
|
2013-08-03 01:53:18 +02:00
|
|
|
// TODO(jkoleszar): All chroma MVs in SPLITMV mode are taken as the
|
|
|
|
// same MV (the average of the 4 luma MVs) but we could do something
|
|
|
|
// smarter for non-4:2:0. Just punt for now, pending the changes to get
|
|
|
|
// rid of SPLITMV mode entirely.
|
2013-08-06 00:23:49 +02:00
|
|
|
const MV mv = mi->mbmi.sb_type < BLOCK_8X8
|
2013-08-12 22:54:13 +02:00
|
|
|
? (plane == 0 ? mi->bmi[block].as_mv[ref].as_mv
|
|
|
|
: mi_mv_pred_q4(mi, ref))
|
|
|
|
: mi->mbmi.mv[ref].as_mv;
|
2013-08-03 01:53:18 +02:00
|
|
|
|
|
|
|
// 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.
|
2013-10-29 18:40:13 +01:00
|
|
|
// 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);
|
2013-08-08 02:02:28 +02:00
|
|
|
|
2013-10-18 17:56:30 +02:00
|
|
|
uint8_t *pre;
|
|
|
|
MV32 scaled_mv;
|
2013-12-10 19:36:44 +01:00
|
|
|
int xs, ys, subpel_x, subpel_y;
|
2013-10-18 17:56:30 +02:00
|
|
|
|
2013-12-20 01:06:33 +01:00
|
|
|
if (vp9_is_scaled(sf)) {
|
|
|
|
pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
|
|
|
|
scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
|
|
|
|
xs = sf->x_step_q4;
|
|
|
|
ys = sf->y_step_q4;
|
2013-10-18 17:56:30 +02:00
|
|
|
} 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;
|
|
|
|
}
|
2013-12-10 19:36:44 +01:00
|
|
|
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);
|
2013-10-18 17:56:30 +02:00
|
|
|
|
|
|
|
inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
|
2014-04-04 00:28:42 +02:00
|
|
|
subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys);
|
make buid_inter_predictors block size agnostic (luma)
This commit converts the luma versions of vp9_build_inter_predictors_sb
to use a common function. Update the convolution functions to support
block sizes larger than 16x16, and add a foreach_predicted_block walker.
Next step will be to calculate the UV motion vector and implement SBUV,
then fold in vp9_build_inter16x16_predictors_mb and SPLITMV.
At the 16x16, 32x32, and 64x64 levels implemented in this commit, each
plane is predicted with only a single call to vp9_build_inter_predictor.
This is not yet called for SPLITMV. If the notion of SPLITMV/I8X8/I4X4
goes away, then the prediction block walker can go away, since we'll
always predict the whole bsize in a single step. Implemented using a
block walker at this stage for SPLITMV, as a 4x4 "prediction block size"
within the BLOCK_SIZE_MB16X16 macroblock. It would also support other
rectangular sizes too, if the blocks smaller than 16x16 remain
implemented as a SPLITMV-like thing. Just using 4x4 for now.
There's also a potential to combine with the foreach_transformed_block
walker if the logic for calculating the size of the subsampled
transform is made more straightforward, perhaps as a consequence of
supporing smaller macroblocks than 16x16. Will watch what happens there.
Change-Id: Iddd9973398542216601b630c628b9b7fdee33fe2
2013-04-13 02:19:57 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-12 22:54:13 +02:00
|
|
|
|
2013-08-26 20:33:16 +02:00
|
|
|
static void build_inter_predictors_for_planes(MACROBLOCKD *xd, BLOCK_SIZE bsize,
|
2013-08-12 22:54:13 +02:00
|
|
|
int mi_row, int mi_col,
|
|
|
|
int plane_from, int plane_to) {
|
|
|
|
int plane;
|
2013-12-04 21:11:01 +01:00
|
|
|
const int mi_x = mi_col * MI_SIZE;
|
|
|
|
const int mi_y = mi_row * MI_SIZE;
|
2013-08-12 22:54:13 +02:00
|
|
|
for (plane = plane_from; plane <= plane_to; ++plane) {
|
2013-12-04 21:11:01 +01:00
|
|
|
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;
|
2013-11-12 03:37:00 +01:00
|
|
|
|
2014-04-02 01:18:47 +02:00
|
|
|
if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
|
2013-11-12 03:37:00 +01:00
|
|
|
int i = 0, x, y;
|
|
|
|
assert(bsize == BLOCK_8X8);
|
2013-12-04 21:11:01 +01:00
|
|
|
for (y = 0; y < num_4x4_h; ++y)
|
|
|
|
for (x = 0; x < num_4x4_w; ++x)
|
|
|
|
build_inter_predictors(xd, plane, i++, bw, bh,
|
|
|
|
4 * x, 4 * y, 4, 4, mi_x, mi_y);
|
2013-11-12 03:37:00 +01:00
|
|
|
} else {
|
2013-12-04 21:11:01 +01:00
|
|
|
build_inter_predictors(xd, plane, 0, bw, bh,
|
|
|
|
0, 0, bw, bh, mi_x, mi_y);
|
2013-11-12 03:37:00 +01:00
|
|
|
}
|
2013-08-12 22:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:25:48 +02:00
|
|
|
void vp9_build_inter_predictors_sby(MACROBLOCKD *xd, int mi_row, int mi_col,
|
2013-08-26 20:33:16 +02:00
|
|
|
BLOCK_SIZE bsize) {
|
2013-08-12 22:54:13 +02:00
|
|
|
build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0, 0);
|
make buid_inter_predictors block size agnostic (luma)
This commit converts the luma versions of vp9_build_inter_predictors_sb
to use a common function. Update the convolution functions to support
block sizes larger than 16x16, and add a foreach_predicted_block walker.
Next step will be to calculate the UV motion vector and implement SBUV,
then fold in vp9_build_inter16x16_predictors_mb and SPLITMV.
At the 16x16, 32x32, and 64x64 levels implemented in this commit, each
plane is predicted with only a single call to vp9_build_inter_predictor.
This is not yet called for SPLITMV. If the notion of SPLITMV/I8X8/I4X4
goes away, then the prediction block walker can go away, since we'll
always predict the whole bsize in a single step. Implemented using a
block walker at this stage for SPLITMV, as a 4x4 "prediction block size"
within the BLOCK_SIZE_MB16X16 macroblock. It would also support other
rectangular sizes too, if the blocks smaller than 16x16 remain
implemented as a SPLITMV-like thing. Just using 4x4 for now.
There's also a potential to combine with the foreach_transformed_block
walker if the logic for calculating the size of the subsampled
transform is made more straightforward, perhaps as a consequence of
supporing smaller macroblocks than 16x16. Will watch what happens there.
Change-Id: Iddd9973398542216601b630c628b9b7fdee33fe2
2013-04-13 02:19:57 +02:00
|
|
|
}
|
2013-08-09 06:25:48 +02:00
|
|
|
void vp9_build_inter_predictors_sbuv(MACROBLOCKD *xd, int mi_row, int mi_col,
|
2013-08-26 20:33:16 +02:00
|
|
|
BLOCK_SIZE bsize) {
|
2013-08-12 22:54:13 +02:00
|
|
|
build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 1,
|
|
|
|
MAX_MB_PLANE - 1);
|
2013-04-17 01:26:26 +02:00
|
|
|
}
|
2013-08-12 22:54:13 +02:00
|
|
|
void vp9_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
|
2013-08-26 20:33:16 +02:00
|
|
|
BLOCK_SIZE bsize) {
|
2013-08-12 22:54:13 +02:00
|
|
|
build_inter_predictors_for_planes(xd, bsize, mi_row, mi_col, 0,
|
|
|
|
MAX_MB_PLANE - 1);
|
2013-04-17 22:41:18 +02:00
|
|
|
}
|
2011-04-28 16:53:59 +02:00
|
|
|
|
2013-11-22 20:56:29 +01:00
|
|
|
// TODO(jingning): This function serves as a placeholder for decoder prediction
|
|
|
|
// using on demand border extension. It should be moved to /decoder/ directory.
|
|
|
|
static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
|
2014-03-13 03:36:40 +01:00
|
|
|
int bw, int bh,
|
2013-12-04 21:11:01 +01:00
|
|
|
int x, int y, int w, int h,
|
2013-11-22 20:56:29 +01:00
|
|
|
int mi_x, int mi_y) {
|
|
|
|
struct macroblockd_plane *const pd = &xd->plane[plane];
|
2014-04-02 01:18:47 +02:00
|
|
|
const MODE_INFO *mi = xd->mi[0];
|
2013-11-22 20:56:29 +01:00
|
|
|
const int is_compound = has_second_ref(&mi->mbmi);
|
2014-04-04 00:28:42 +02:00
|
|
|
const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
|
2013-11-22 20:56:29 +01:00
|
|
|
int ref;
|
|
|
|
|
|
|
|
for (ref = 0; ref < 1 + is_compound; ++ref) {
|
2013-12-28 03:44:19 +01:00
|
|
|
const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
|
2013-11-22 20:56:29 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
// TODO(jkoleszar): All chroma MVs in SPLITMV mode are taken as the
|
|
|
|
// same MV (the average of the 4 luma MVs) but we could do something
|
|
|
|
// smarter for non-4:2:0. Just punt for now, pending the changes to get
|
|
|
|
// rid of SPLITMV mode entirely.
|
|
|
|
const MV mv = mi->mbmi.sb_type < BLOCK_8X8
|
|
|
|
? (plane == 0 ? mi->bmi[block].as_mv[ref].as_mv
|
|
|
|
: mi_mv_pred_q4(mi, ref))
|
|
|
|
: mi->mbmi.mv[ref].as_mv;
|
2014-03-13 03:36:48 +01:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2013-11-22 20:56:29 +01:00
|
|
|
MV32 scaled_mv;
|
2014-02-04 03:03:17 +01:00
|
|
|
int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, buf_stride,
|
|
|
|
subpel_x, subpel_y;
|
2013-12-10 19:36:44 +01:00
|
|
|
uint8_t *ref_frame, *buf_ptr;
|
2013-12-28 03:44:19 +01:00
|
|
|
const YV12_BUFFER_CONFIG *ref_buf = xd->block_refs[ref]->buf;
|
2013-12-06 20:39:38 +01:00
|
|
|
|
|
|
|
// Get reference frame pointer, width and height.
|
|
|
|
if (plane == 0) {
|
|
|
|
frame_width = ref_buf->y_crop_width;
|
|
|
|
frame_height = ref_buf->y_crop_height;
|
|
|
|
ref_frame = ref_buf->y_buffer;
|
|
|
|
} else {
|
|
|
|
frame_width = ref_buf->uv_crop_width;
|
|
|
|
frame_height = ref_buf->uv_crop_height;
|
|
|
|
ref_frame = plane == 1 ? ref_buf->u_buffer : ref_buf->v_buffer;
|
|
|
|
}
|
|
|
|
|
2014-03-14 23:31:49 +01:00
|
|
|
if (vp9_is_scaled(sf)) {
|
|
|
|
// Co-ordinate of containing block to pixel precision.
|
|
|
|
int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
|
|
|
|
int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
|
2013-12-06 20:39:38 +01:00
|
|
|
|
2014-03-14 23:31:49 +01:00
|
|
|
// Co-ordinate of the block to 1/16th pixel precision.
|
|
|
|
x0_16 = (x_start + x) << SUBPEL_BITS;
|
|
|
|
y0_16 = (y_start + y) << SUBPEL_BITS;
|
2013-11-22 20:56:29 +01:00
|
|
|
|
2014-03-14 23:31:49 +01:00
|
|
|
// Co-ordinate of current block in reference frame
|
|
|
|
// to 1/16th pixel precision.
|
|
|
|
x0_16 = sf->scale_value_x(x0_16, sf);
|
|
|
|
y0_16 = sf->scale_value_y(y0_16, sf);
|
|
|
|
|
|
|
|
// Map the top left corner of the block into the reference frame.
|
2014-03-21 22:27:03 +01:00
|
|
|
x0 = sf->scale_value_x(x_start + x, sf);
|
|
|
|
y0 = sf->scale_value_y(y_start + y, sf);
|
2014-03-14 23:31:49 +01:00
|
|
|
|
|
|
|
// Scale the MV and incorporate the sub-pixel offset of the block
|
|
|
|
// in the reference frame.
|
2013-12-20 01:06:33 +01:00
|
|
|
scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
|
|
|
|
xs = sf->x_step_q4;
|
|
|
|
ys = sf->y_step_q4;
|
2013-11-22 20:56:29 +01:00
|
|
|
} else {
|
2014-03-14 23:31:49 +01:00
|
|
|
// Co-ordinate of containing block to pixel precision.
|
|
|
|
x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x;
|
|
|
|
y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y;
|
|
|
|
|
|
|
|
// Co-ordinate of the block to 1/16th pixel precision.
|
|
|
|
x0_16 = x0 << SUBPEL_BITS;
|
|
|
|
y0_16 = y0 << SUBPEL_BITS;
|
|
|
|
|
2013-11-22 20:56:29 +01:00
|
|
|
scaled_mv.row = mv_q4.row;
|
|
|
|
scaled_mv.col = mv_q4.col;
|
|
|
|
xs = ys = 16;
|
|
|
|
}
|
2013-12-10 19:36:44 +01:00
|
|
|
subpel_x = scaled_mv.col & SUBPEL_MASK;
|
|
|
|
subpel_y = scaled_mv.row & SUBPEL_MASK;
|
2013-11-22 20:56:29 +01:00
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
// Calculate the top left corner of the best matching block in the reference frame.
|
2013-12-06 20:39:38 +01:00
|
|
|
x0 += scaled_mv.col >> SUBPEL_BITS;
|
|
|
|
y0 += scaled_mv.row >> SUBPEL_BITS;
|
|
|
|
x0_16 += scaled_mv.col;
|
|
|
|
y0_16 += scaled_mv.row;
|
|
|
|
|
2013-12-10 19:36:44 +01:00
|
|
|
// Get reference block pointer.
|
|
|
|
buf_ptr = ref_frame + y0 * pre_buf->stride + x0;
|
2014-01-13 23:14:44 +01:00
|
|
|
buf_stride = pre_buf->stride;
|
2013-12-10 19:36:44 +01:00
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
// Do border extension if there is motion or the
|
2013-12-06 20:39:38 +01:00
|
|
|
// width/height is not a multiple of 8 pixels.
|
|
|
|
if (scaled_mv.col || scaled_mv.row ||
|
|
|
|
(frame_width & 0x7) || (frame_height & 0x7)) {
|
2014-02-04 03:03:17 +01:00
|
|
|
// Get reference block bottom right coordinate.
|
|
|
|
int x1 = ((x0_16 + (w - 1) * xs) >> SUBPEL_BITS) + 1;
|
|
|
|
int y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1;
|
2014-01-13 23:14:44 +01:00
|
|
|
int x_pad = 0, y_pad = 0;
|
2013-12-06 20:39:38 +01:00
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
if (subpel_x || (sf->x_step_q4 & SUBPEL_MASK)) {
|
2013-12-06 20:39:38 +01:00
|
|
|
x0 -= VP9_INTERP_EXTEND - 1;
|
|
|
|
x1 += VP9_INTERP_EXTEND;
|
2014-01-13 23:14:44 +01:00
|
|
|
x_pad = 1;
|
2013-12-06 20:39:38 +01:00
|
|
|
}
|
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
if (subpel_y || (sf->y_step_q4 & SUBPEL_MASK)) {
|
2013-12-06 20:39:38 +01:00
|
|
|
y0 -= VP9_INTERP_EXTEND - 1;
|
|
|
|
y1 += VP9_INTERP_EXTEND;
|
2014-01-13 23:14:44 +01:00
|
|
|
y_pad = 1;
|
2013-12-06 20:39:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip border extension if block is inside the frame.
|
|
|
|
if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width ||
|
|
|
|
y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) {
|
2013-12-10 19:36:44 +01:00
|
|
|
uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0;
|
2013-12-06 20:39:38 +01:00
|
|
|
// Extend the border.
|
2014-03-14 23:31:49 +01:00
|
|
|
build_mc_border(buf_ptr1, pre_buf->stride, xd->mc_buf, x1 - x0 + 1,
|
|
|
|
x0, y0, x1 - x0 + 1, y1 - y0 + 1, frame_width,
|
|
|
|
frame_height);
|
|
|
|
buf_stride = x1 - x0 + 1;
|
2014-01-13 23:14:44 +01:00
|
|
|
buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3;
|
2013-12-06 20:39:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-13 23:14:44 +01:00
|
|
|
inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x,
|
2014-04-04 00:28:42 +02:00
|
|
|
subpel_y, sf, w, h, ref, kernel, xs, ys);
|
2013-11-22 20:56:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp9_dec_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
|
|
|
|
BLOCK_SIZE bsize) {
|
|
|
|
int plane;
|
2013-12-04 21:11:01 +01:00
|
|
|
const int mi_x = mi_col * MI_SIZE;
|
|
|
|
const int mi_y = mi_row * MI_SIZE;
|
2013-11-22 20:56:29 +01:00
|
|
|
for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
|
2013-12-04 21:11:01 +01:00
|
|
|
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;
|
2013-11-22 20:56:29 +01:00
|
|
|
|
2014-04-02 01:18:47 +02:00
|
|
|
if (xd->mi[0]->mbmi.sb_type < BLOCK_8X8) {
|
2013-11-22 20:56:29 +01:00
|
|
|
int i = 0, x, y;
|
|
|
|
assert(bsize == BLOCK_8X8);
|
2013-12-04 21:11:01 +01:00
|
|
|
for (y = 0; y < num_4x4_h; ++y)
|
|
|
|
for (x = 0; x < num_4x4_w; ++x)
|
2014-03-13 03:36:40 +01:00
|
|
|
dec_build_inter_predictors(xd, plane, i++, bw, bh,
|
2013-12-04 21:11:01 +01:00
|
|
|
4 * x, 4 * y, 4, 4, mi_x, mi_y);
|
2013-11-22 20:56:29 +01:00
|
|
|
} else {
|
2014-03-13 03:36:40 +01:00
|
|
|
dec_build_inter_predictors(xd, plane, 0, bw, bh,
|
2013-12-04 21:11:01 +01:00
|
|
|
0, 0, bw, bh, mi_x, mi_y);
|
2013-11-22 20:56:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 23:58:43 +01:00
|
|
|
|
2014-05-16 18:48:26 +02:00
|
|
|
void vp9_setup_dst_planes(struct macroblockd_plane planes[MAX_MB_PLANE],
|
2014-03-03 23:58:43 +01:00
|
|
|
const YV12_BUFFER_CONFIG *src,
|
|
|
|
int mi_row, int mi_col) {
|
|
|
|
uint8_t *const buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer,
|
|
|
|
src->alpha_buffer};
|
|
|
|
const int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride,
|
|
|
|
src->alpha_stride};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MB_PLANE; ++i) {
|
2014-05-16 18:48:26 +02:00
|
|
|
struct macroblockd_plane *const pd = &planes[i];
|
2014-03-03 23:58:43 +01:00
|
|
|
setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
|
|
|
|
pd->subsampling_x, pd->subsampling_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp9_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[4] = {src->y_buffer, src->u_buffer, src->v_buffer,
|
|
|
|
src->alpha_buffer};
|
|
|
|
const int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride,
|
|
|
|
src->alpha_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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|