From fa63b5514ae5de2f876922e00037978cb7b227aa Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Thu, 19 May 2016 13:16:42 +0100 Subject: [PATCH] Use standard rounding in intra filters. Use the same rounding method that is used throughout the codebase, where the halfway value is rounded up rather than down. Change-Id: Ie969ed7eb9fcc88a93a90c7e274fd82f336c7e4d --- vp10/common/reconintra.c | 9 ++------- vpx_ports/mem.h | 5 +++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vp10/common/reconintra.c b/vp10/common/reconintra.c index 6b4a4604d..fa20f2cc1 100644 --- a/vp10/common/reconintra.c +++ b/vp10/common/reconintra.c @@ -391,7 +391,6 @@ static void vp10_init_intra_predictors_internal(void) { #if CONFIG_EXT_INTRA #define FILTER_INTRA_PREC_BITS 10 -#define FILTER_INTRA_ROUND_VAL 511 static const uint8_t ext_intra_extend_modes[FILTER_INTRA_MODES] = { NEED_LEFT | NEED_ABOVE, // FILTER_DC @@ -774,9 +773,7 @@ static void filter_intra_predictors_4tap(uint8_t *dst, ptrdiff_t stride, int bs, for (c = 1; c < 2 * bs + 1 - r; ++c) { ipred = c0 * pred[r - 1][c] + c1 * pred[r][c - 1] + c2 * pred[r - 1][c - 1] + c3 * pred[r - 1][c + 1]; - pred[r][c] = ipred < 0 ? - -((-ipred + FILTER_INTRA_ROUND_VAL) >> FILTER_INTRA_PREC_BITS) : - ((ipred + FILTER_INTRA_ROUND_VAL) >> FILTER_INTRA_PREC_BITS); + pred[r][c] = ROUND_POWER_OF_TWO_SIGNED(ipred, FILTER_INTRA_PREC_BITS); } for (r = 0; r < bs; ++r) { @@ -1050,9 +1047,7 @@ static void highbd_filter_intra_predictors_4tap(uint16_t *dst, ptrdiff_t stride, for (c = 1; c < 2 * bs + 1 - r; ++c) { ipred = c0 * pred[r - 1][c] + c1 * pred[r][c - 1] + c2 * pred[r - 1][c - 1] + c3 * pred[r - 1][c + 1]; - pred[r][c] = ipred < 0 ? - -((-ipred + FILTER_INTRA_ROUND_VAL) >> FILTER_INTRA_PREC_BITS) : - ((ipred + FILTER_INTRA_ROUND_VAL) >> FILTER_INTRA_PREC_BITS); + pred[r][c] = ROUND_POWER_OF_TWO_SIGNED(ipred, FILTER_INTRA_PREC_BITS); } for (r = 0; r < bs; ++r) { diff --git a/vpx_ports/mem.h b/vpx_ports/mem.h index 4dce9c21a..993124a15 100644 --- a/vpx_ports/mem.h +++ b/vpx_ports/mem.h @@ -46,6 +46,11 @@ #define ROUNDZ_POWER_OF_TWO(value, n) \ ((n) ? (((value) + (1 << ((n) - 1))) >> (n)) : (value)) +/* Shift down with rounding for signed integers, for use when n > 0 */ +#define ROUND_POWER_OF_TWO_SIGNED(value, n) \ + (((value) < 0) ? -ROUND_POWER_OF_TWO(-(value), (n)) \ + : ROUND_POWER_OF_TWO((value), (n))) + #define ALIGN_POWER_OF_TWO(value, n) \ (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))