Crop distortion to visible MIs

Ported from VP9 with some heavy modifications

bsize_dist@2017-03-29T23:18:27.564Z -> bcropped_dist@2017-03-29T23:21:00.200Z

   PSNR | PSNR Cb | PSNR Cr | PSNR HVS |    SSIM | MS SSIM | CIEDE 2000
-0.0966 | -0.0922 |  0.0032 |  -0.0618 | -0.0579 | -0.0441 |  -0.0959

Change-Id: Icdfcf47a9017fd3180e7fbc963196a43c5376c4e
This commit is contained in:
Alex Converse 2017-03-29 15:26:03 -07:00
Родитель 29608d84af
Коммит 61f37b8760
1 изменённых файлов: 96 добавлений и 20 удалений

Просмотреть файл

@ -1301,9 +1301,80 @@ int av1_cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
}
#endif // !CONFIG_PVQ || CONFIG_VAR_TX
static void dist_block(const AV1_COMP *cpi, MACROBLOCK *x, int plane, int block,
int blk_row, int blk_col, TX_SIZE tx_size,
int64_t *out_dist, int64_t *out_sse) {
// Get transform block visible dimensions cropped to the MI units.
static void get_txb_dimensions(const MACROBLOCKD *xd, int plane,
BLOCK_SIZE plane_bsize, int blk_row, int blk_col,
BLOCK_SIZE tx_bsize, int *width, int *height,
int *visible_width, int *visible_height) {
assert(tx_bsize <= plane_bsize);
int txb_height = block_size_high[tx_bsize];
int txb_width = block_size_wide[tx_bsize];
const int block_height = block_size_high[plane_bsize];
const int block_width = block_size_wide[plane_bsize];
const struct macroblockd_plane *const pd = &xd->plane[plane];
// TODO(aconverse@google.com): Investigate using crop_width/height here rather
// than the MI size
const int block_rows =
(xd->mb_to_bottom_edge >= 0)
? block_height
: (xd->mb_to_bottom_edge >> (3 + pd->subsampling_y)) + block_height;
const int block_cols =
(xd->mb_to_right_edge >= 0)
? block_width
: (xd->mb_to_right_edge >> (3 + pd->subsampling_x)) + block_width;
const int tx_unit_size = tx_size_wide_log2[0];
if (width) *width = txb_width;
if (height) *height = txb_height;
*visible_width = clamp(block_cols - (blk_col << tx_unit_size), 0, txb_width);
*visible_height =
clamp(block_rows - (blk_row << tx_unit_size), 0, txb_height);
}
// Compute the pixel domain sum square error on all visible 4x4s in the
// transform block.
static unsigned pixel_sse(const AV1_COMP *const cpi, const MACROBLOCKD *xd,
int plane, const uint8_t *src, const int src_stride,
const uint8_t *dst, const int dst_stride, int blk_row,
int blk_col, const BLOCK_SIZE plane_bsize,
const BLOCK_SIZE tx_bsize) {
int txb_rows, txb_cols, visible_rows, visible_cols;
get_txb_dimensions(xd, plane, plane_bsize, blk_row, blk_col, tx_bsize,
&txb_cols, &txb_rows, &visible_cols, &visible_rows);
assert(visible_rows > 0);
assert(visible_cols > 0);
if (txb_rows == visible_rows && txb_cols == visible_cols) {
unsigned sse;
cpi->fn_ptr[tx_bsize].vf(src, src_stride, dst, dst_stride, &sse);
return sse;
}
#if CONFIG_AOM_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
uint64_t sse = aom_highbd_sse_odd_size(src, src_stride, dst, dst_stride,
visible_cols, visible_rows);
return (unsigned int)ROUND_POWER_OF_TWO(sse, (xd->bd - 8) * 2);
}
#endif // CONFIG_AOM_HIGHBITDEPTH
unsigned sse = aom_sse_odd_size(src, src_stride, dst, dst_stride,
visible_cols, visible_rows);
return sse;
}
// Compute the squares sum squares on all visible 4x4s in the transform block.
static int64_t sum_squares_visible(const MACROBLOCKD *xd, int plane,
const int16_t *diff, const int diff_stride,
int blk_row, int blk_col,
const BLOCK_SIZE plane_bsize,
const BLOCK_SIZE tx_bsize) {
int visible_rows, visible_cols;
get_txb_dimensions(xd, plane, plane_bsize, blk_row, blk_col, tx_bsize, NULL,
NULL, &visible_cols, &visible_rows);
return aom_sum_squares_2d_i16(diff, diff_stride, visible_cols, visible_rows);
}
static void dist_block(const AV1_COMP *cpi, MACROBLOCK *x, int plane,
BLOCK_SIZE plane_bsize, int block, int blk_row,
int blk_col, TX_SIZE tx_size, int64_t *out_dist,
int64_t *out_sse) {
MACROBLOCKD *const xd = &x->e_mbd;
const struct macroblock_plane *const p = &x->plane[plane];
const struct macroblockd_plane *const pd = &xd->plane[plane];
@ -1376,7 +1447,8 @@ static void dist_block(const AV1_COMP *cpi, MACROBLOCK *x, int plane, int block,
tmp = 0;
} else
#endif // CONFIG_DAALA_DIST
cpi->fn_ptr[tx_bsize].vf(src, src_stride, dst, dst_stride, &tmp);
tmp = pixel_sse(cpi, xd, plane, src, src_stride, dst, dst_stride, blk_row,
blk_col, plane_bsize, tx_bsize);
*out_sse = (int64_t)tmp * 16;
@ -1431,7 +1503,8 @@ static void dist_block(const AV1_COMP *cpi, MACROBLOCK *x, int plane, int block,
tmp = 0;
} else
#endif // CONFIG_DAALA_DIST
cpi->fn_ptr[tx_bsize].vf(src, src_stride, recon, MAX_TX_SIZE, &tmp);
tmp = pixel_sse(cpi, xd, plane, src, src_stride, recon, MAX_TX_SIZE,
blk_row, blk_col, plane_bsize, tx_bsize);
}
*out_dist = (int64_t)tmp * 16;
}
@ -1446,12 +1519,6 @@ static int rate_block(int plane, int block, const ENTROPY_CONTEXT *a,
}
#endif // !CONFIG_PVQ
static uint64_t sum_squares_2d(const int16_t *diff, int diff_stride,
TX_SIZE tx_size) {
return aom_sum_squares_2d_i16(diff, diff_stride, tx_size_wide[tx_size],
tx_size_high[tx_size]);
}
static void block_rd_txfm(int plane, int block, int blk_row, int blk_col,
BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) {
struct rdcost_block_args *args = arg;
@ -1487,13 +1554,12 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col,
av1_encode_block_intra(plane, block, blk_row, blk_col, plane_bsize, tx_size,
&b_args);
if (args->cpi->sf.use_transform_domain_distortion && !CONFIG_DAALA_DIST) {
dist_block(args->cpi, x, plane, block, blk_row, blk_col, tx_size,
&this_rd_stats.dist, &this_rd_stats.sse);
dist_block(args->cpi, x, plane, plane_bsize, block, blk_row, blk_col,
tx_size, &this_rd_stats.dist, &this_rd_stats.sse);
} else {
// Note that the encode block_intra call above already calls
// av1_inv_txfm_add, so we can't just call dist_block here.
const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size];
const aom_variance_fn_t variance = args->cpi->fn_ptr[tx_bsize].vf;
const struct macroblock_plane *const p = &x->plane[plane];
const struct macroblockd_plane *const pd = &xd->plane[plane];
@ -1534,7 +1600,9 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col,
} else
#endif // CONFIG_DAALA_DIST
{
this_rd_stats.sse = sum_squares_2d(diff, diff_stride, tx_size);
this_rd_stats.sse =
sum_squares_visible(xd, plane, diff, diff_stride, blk_row, blk_col,
plane_bsize, tx_bsize);
#if CONFIG_AOM_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
@ -1557,7 +1625,8 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col,
tmp = 0;
} else
#endif // CONFIG_DAALA_DIST
variance(src, src_stride, dst, dst_stride, &tmp);
tmp = pixel_sse(args->cpi, xd, plane, src, src_stride, dst, dst_stride,
blk_row, blk_col, plane_bsize, tx_bsize);
this_rd_stats.dist = (int64_t)tmp * 16;
}
} else {
@ -1573,8 +1642,8 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col,
if (x->plane[plane].eobs[block] && !xd->lossless[mbmi->segment_id])
av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
#endif // !CONFIG_PVQ
dist_block(args->cpi, x, plane, block, blk_row, blk_col, tx_size,
&this_rd_stats.dist, &this_rd_stats.sse);
dist_block(args->cpi, x, plane, plane_bsize, block, blk_row, blk_col,
tx_size, &this_rd_stats.dist, &this_rd_stats.sse);
}
rd = RDCOST(x->rdmult, x->rddiv, 0, this_rd_stats.dist);
@ -3897,6 +3966,13 @@ static int super_block_uvrd(const AV1_COMP *const cpi, MACROBLOCK *x,
}
#if CONFIG_VAR_TX
// FIXME crop these calls
static uint64_t sum_squares_2d(const int16_t *diff, int diff_stride,
TX_SIZE tx_size) {
return aom_sum_squares_2d_i16(diff, diff_stride, tx_size_wide[tx_size],
tx_size_high[tx_size]);
}
void av1_tx_block_rd_b(const AV1_COMP *cpi, MACROBLOCK *x, TX_SIZE tx_size,
int blk_row, int blk_col, int plane, int block,
int plane_bsize, const ENTROPY_CONTEXT *a,
@ -5360,8 +5436,8 @@ static int64_t encode_inter_mb_segment_sub8x8(
av1_xform_quant(cm, x, 0, block, idy + (i >> 1), idx + (i & 0x01),
BLOCK_8X8, tx_size, coeff_ctx, AV1_XFORM_QUANT_FP);
#endif // !CONFIG_PVQ
dist_block(cpi, x, 0, block, idy + (i >> 1), idx + (i & 0x1), tx_size,
&dist, &ssz);
dist_block(cpi, x, 0, BLOCK_8X8, block, idy + (i >> 1), idx + (i & 0x1),
tx_size, &dist, &ssz);
thisdistortion += dist;
thissse += ssz;
#if !CONFIG_PVQ