From: Debargha Mukherjee Date: Tue, 17 May 2016 14:10:39 +0000 (-0700) Subject: Wedge refactoring to handle signs better X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5de2ad63274ae2b39b60fbc235bdd9118f78ba9;p=libvpx Wedge refactoring to handle signs better Mostly refactoring. Handles signs better though results are more or less neutral. Change-Id: If499537c8f8da4f34d104ebfda072eb4c85fb12f --- diff --git a/vp10/common/reconinter.c b/vp10/common/reconinter.c index d6ac4bb8d..23caa88c1 100644 --- a/vp10/common/reconinter.c +++ b/vp10/common/reconinter.c @@ -23,7 +23,11 @@ #endif // CONFIG_OBMC #if CONFIG_EXT_INTER -#define NSMOOTHERS 2 + +// Set to one to use larger codebooks +#define USE_LARGE_WEDGE_CODEBOOK 0 + +#define NSMOOTHERS 1 static int get_masked_weight(int m, int smoothness) { #define SMOOTHER_LEN 32 static const uint8_t smoothfn[NSMOOTHERS][2 * SMOOTHER_LEN + 1] = { @@ -37,16 +41,6 @@ static int get_masked_weight(int m, int smoothness) { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - }, { - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 2, 2, - 3, 3, 4, 4, 5, 6, 8, 9, - 11, 13, 15, 17, 20, 23, 26, 29, - 32, - 35, 38, 41, 44, 47, 49, 51, 53, - 55, 56, 58, 59, 60, 60, 61, 61, - 62, 62, 63, 63, 63, 63, 63, 63, - 64, 64, 64, 64, 64, 64, 64, 64, } }; if (m < -SMOOTHER_LEN) @@ -57,18 +51,6 @@ static int get_masked_weight(int m, int smoothness) { return smoothfn[smoothness][m + SMOOTHER_LEN]; } -// Angles are with respect to horizontal anti-clockwise -typedef enum { - WEDGE_HORIZONTAL = 0, - WEDGE_VERTICAL = 1, - WEDGE_OBLIQUE27 = 2, - WEDGE_OBLIQUE63 = 3, - WEDGE_OBLIQUE117 = 4, - WEDGE_OBLIQUE153 = 5, - WEDGE_DIRECTIONS -} WedgeDirectionType; - -#define WEDGE_PARMS 4 // [smoother][negative][direction] DECLARE_ALIGNED( @@ -76,310 +58,252 @@ DECLARE_ALIGNED( wedge_mask_obl[NSMOOTHERS][2][WEDGE_DIRECTIONS] [MASK_MASTER_SIZE * MASK_MASTER_SIZE]); -// Equation of line: f(x, y) = a[0]*(x - a[2]*w/8) + a[1]*(y - a[3]*h/8) = 0 -void vp10_init_wedge_masks() { - int i, j, s; - const int w = MASK_MASTER_SIZE; - const int h = MASK_MASTER_SIZE; - const int stride = MASK_MASTER_STRIDE; - const int a[2] = {2, 1}; - const double asqrt = sqrt(a[0] * a[0] + a[1] * a[1]); - for (s = 0; s < NSMOOTHERS; s++) { - for (i = 0; i < h; ++i) - for (j = 0; j < w; ++j) { - int x = (2 * j + 1 - w); - int y = (2 * i + 1 - h); - int m = (int)rint((a[0] * x + a[1] * y) / asqrt); - wedge_mask_obl[s][1][WEDGE_OBLIQUE63][i * stride + j] = - wedge_mask_obl[s][1][WEDGE_OBLIQUE27][j * stride + i] = - get_masked_weight(m, s); - wedge_mask_obl[s][1][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = - wedge_mask_obl[s][1][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = - (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m, s); - wedge_mask_obl[s][0][WEDGE_OBLIQUE63][i * stride + j] = - wedge_mask_obl[s][0][WEDGE_OBLIQUE27][j * stride + i] = - (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m, s); - wedge_mask_obl[s][0][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = - wedge_mask_obl[s][0][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = - get_masked_weight(m, s); - wedge_mask_obl[s][1][WEDGE_VERTICAL][i * stride + j] = - wedge_mask_obl[s][1][WEDGE_HORIZONTAL][j * stride + i] = - get_masked_weight(x, s); - wedge_mask_obl[s][0][WEDGE_VERTICAL][i * stride + j] = - wedge_mask_obl[s][0][WEDGE_HORIZONTAL][j * stride + i] = - (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(x, s); - } - } -} - -static const int wedge_params_4[1 << WEDGE_BITS_2] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 1}, - {WEDGE_OBLIQUE63, 4, 4, 1}, - {WEDGE_OBLIQUE117, 4, 4, 1}, - {WEDGE_OBLIQUE153, 4, 4, 1}, +DECLARE_ALIGNED( + 16, static uint8_t, + wedge_signflip_lookup[BLOCK_SIZES][MAX_WEDGE_TYPES]); + +// Some unused wedge codebooks left temporarily to facilitate experiments. +// To be removed when setteld. +static wedge_code_type wedge_codebook_8_hgtw[8] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 6}, }; -static const int wedge_params_8_hgtw[1 << WEDGE_BITS_3] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 1}, - {WEDGE_OBLIQUE63, 4, 4, 1}, - {WEDGE_OBLIQUE117, 4, 4, 1}, - {WEDGE_OBLIQUE153, 4, 4, 1}, - - {WEDGE_OBLIQUE27, 4, 2, 1}, - {WEDGE_OBLIQUE27, 4, 6, 1}, - {WEDGE_OBLIQUE153, 4, 2, 1}, - {WEDGE_OBLIQUE153, 4, 6, 1}, +static wedge_code_type wedge_codebook_8_hltw[8] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 6, 4}, }; -static const int wedge_params_8_hltw[1 << WEDGE_BITS_3] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 1}, - {WEDGE_OBLIQUE63, 4, 4, 1}, - {WEDGE_OBLIQUE117, 4, 4, 1}, - {WEDGE_OBLIQUE153, 4, 4, 1}, - - {WEDGE_OBLIQUE63, 2, 4, 1}, - {WEDGE_OBLIQUE63, 6, 4, 1}, - {WEDGE_OBLIQUE117, 2, 4, 1}, - {WEDGE_OBLIQUE117, 6, 4, 1}, +static wedge_code_type wedge_codebook_8_heqw[8] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_HORIZONTAL, 4, 2}, + {WEDGE_HORIZONTAL, 4, 6}, + {WEDGE_VERTICAL, 2, 4}, + {WEDGE_VERTICAL, 6, 4}, }; -static const int wedge_params_8_heqw[1 << WEDGE_BITS_3] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 1}, - {WEDGE_OBLIQUE63, 4, 4, 1}, - {WEDGE_OBLIQUE117, 4, 4, 1}, - {WEDGE_OBLIQUE153, 4, 4, 1}, - - {WEDGE_HORIZONTAL, 4, 2, 1}, - {WEDGE_HORIZONTAL, 4, 6, 1}, - {WEDGE_VERTICAL, 2, 4, 1}, - {WEDGE_VERTICAL, 6, 4, 1}, +#if !USE_LARGE_WEDGE_CODEBOOK +static const wedge_code_type wedge_codebook_16_hgtw[16] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_HORIZONTAL, 4, 2}, + {WEDGE_HORIZONTAL, 4, 4}, + {WEDGE_HORIZONTAL, 4, 6}, + {WEDGE_VERTICAL, 4, 4}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 6}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 6, 4}, }; -static const int wedge_params_16_hgtw[1 << WEDGE_BITS_4] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 0}, - {WEDGE_OBLIQUE63, 4, 4, 0}, - {WEDGE_OBLIQUE117, 4, 4, 0}, - {WEDGE_OBLIQUE153, 4, 4, 0}, - - {WEDGE_HORIZONTAL, 4, 2, 0}, - {WEDGE_HORIZONTAL, 4, 4, 0}, - {WEDGE_HORIZONTAL, 4, 6, 0}, - {WEDGE_VERTICAL, 4, 4, 0}, - - {WEDGE_OBLIQUE27, 4, 2, 0}, - {WEDGE_OBLIQUE27, 4, 6, 0}, - {WEDGE_OBLIQUE153, 4, 2, 0}, - {WEDGE_OBLIQUE153, 4, 6, 0}, - - {WEDGE_OBLIQUE63, 2, 4, 0}, - {WEDGE_OBLIQUE63, 6, 4, 0}, - {WEDGE_OBLIQUE117, 2, 4, 0}, - {WEDGE_OBLIQUE117, 6, 4, 0}, +static const wedge_code_type wedge_codebook_16_hltw[16] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_VERTICAL, 2, 4}, + {WEDGE_VERTICAL, 4, 4}, + {WEDGE_VERTICAL, 6, 4}, + {WEDGE_HORIZONTAL, 4, 4}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 6}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 6, 4}, }; -static const int wedge_params_16_hltw[1 << WEDGE_BITS_4] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 0}, - {WEDGE_OBLIQUE63, 4, 4, 0}, - {WEDGE_OBLIQUE117, 4, 4, 0}, - {WEDGE_OBLIQUE153, 4, 4, 0}, - - {WEDGE_VERTICAL, 2, 4, 0}, - {WEDGE_VERTICAL, 4, 4, 0}, - {WEDGE_VERTICAL, 6, 4, 0}, - {WEDGE_HORIZONTAL, 4, 4, 0}, - - {WEDGE_OBLIQUE27, 4, 2, 0}, - {WEDGE_OBLIQUE27, 4, 6, 0}, - {WEDGE_OBLIQUE153, 4, 2, 0}, - {WEDGE_OBLIQUE153, 4, 6, 0}, - - {WEDGE_OBLIQUE63, 2, 4, 0}, - {WEDGE_OBLIQUE63, 6, 4, 0}, - {WEDGE_OBLIQUE117, 2, 4, 0}, - {WEDGE_OBLIQUE117, 6, 4, 0}, +static const wedge_code_type wedge_codebook_16_heqw[16] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_HORIZONTAL, 4, 2}, + {WEDGE_HORIZONTAL, 4, 6}, + {WEDGE_VERTICAL, 2, 4}, + {WEDGE_VERTICAL, 6, 4}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 6}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 6, 4}, }; -static const int wedge_params_16_heqw[1 << WEDGE_BITS_4] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 0}, - {WEDGE_OBLIQUE63, 4, 4, 0}, - {WEDGE_OBLIQUE117, 4, 4, 0}, - {WEDGE_OBLIQUE153, 4, 4, 0}, - - {WEDGE_HORIZONTAL, 4, 2, 0}, - {WEDGE_HORIZONTAL, 4, 6, 0}, - {WEDGE_VERTICAL, 2, 4, 0}, - {WEDGE_VERTICAL, 6, 4, 0}, - - {WEDGE_OBLIQUE27, 4, 2, 0}, - {WEDGE_OBLIQUE27, 4, 6, 0}, - {WEDGE_OBLIQUE153, 4, 2, 0}, - {WEDGE_OBLIQUE153, 4, 6, 0}, - - {WEDGE_OBLIQUE63, 2, 4, 0}, - {WEDGE_OBLIQUE63, 6, 4, 0}, - {WEDGE_OBLIQUE117, 2, 4, 0}, - {WEDGE_OBLIQUE117, 6, 4, 0}, +const wedge_params_type wedge_params_lookup[BLOCK_SIZES] = { + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, + {4, wedge_codebook_16_heqw, wedge_signflip_lookup[3], 0}, + {4, wedge_codebook_16_hgtw, wedge_signflip_lookup[4], 0}, + {4, wedge_codebook_16_hltw, wedge_signflip_lookup[5], 0}, + {4, wedge_codebook_16_heqw, wedge_signflip_lookup[6], 0}, + {4, wedge_codebook_16_hgtw, wedge_signflip_lookup[7], 0}, + {4, wedge_codebook_16_hltw, wedge_signflip_lookup[8], 0}, + {4, wedge_codebook_16_heqw, wedge_signflip_lookup[9], 0}, + {0, wedge_codebook_8_hgtw, wedge_signflip_lookup[10], 0}, + {0, wedge_codebook_8_hltw, wedge_signflip_lookup[11], 0}, + {0, wedge_codebook_8_heqw, wedge_signflip_lookup[12], 0}, +#if CONFIG_EXT_PARTITION + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, +#endif // CONFIG_EXT_PARTITION }; -static const int wedge_params_32_hgtw[1 << WEDGE_BITS_5] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 0}, - {WEDGE_OBLIQUE63, 4, 4, 0}, - {WEDGE_OBLIQUE117, 4, 4, 0}, - {WEDGE_OBLIQUE153, 4, 4, 0}, - - {WEDGE_HORIZONTAL, 4, 2, 0}, - {WEDGE_HORIZONTAL, 4, 4, 0}, - {WEDGE_HORIZONTAL, 4, 6, 0}, - {WEDGE_VERTICAL, 4, 4, 0}, - - {WEDGE_OBLIQUE27, 4, 1, 0}, - {WEDGE_OBLIQUE27, 4, 2, 0}, - {WEDGE_OBLIQUE27, 4, 3, 0}, - {WEDGE_OBLIQUE27, 4, 5, 0}, - {WEDGE_OBLIQUE27, 4, 6, 0}, - {WEDGE_OBLIQUE27, 4, 7, 0}, - - {WEDGE_OBLIQUE153, 4, 1, 0}, - {WEDGE_OBLIQUE153, 4, 2, 0}, - {WEDGE_OBLIQUE153, 4, 3, 0}, - {WEDGE_OBLIQUE153, 4, 5, 0}, - {WEDGE_OBLIQUE153, 4, 6, 0}, - {WEDGE_OBLIQUE153, 4, 7, 0}, - - {WEDGE_OBLIQUE63, 1, 4, 0}, - {WEDGE_OBLIQUE63, 2, 4, 0}, - {WEDGE_OBLIQUE63, 3, 4, 0}, - {WEDGE_OBLIQUE63, 5, 4, 0}, - {WEDGE_OBLIQUE63, 6, 4, 0}, - {WEDGE_OBLIQUE63, 7, 4, 0}, - - {WEDGE_OBLIQUE117, 1, 4, 0}, - {WEDGE_OBLIQUE117, 2, 4, 0}, - {WEDGE_OBLIQUE117, 3, 4, 0}, - {WEDGE_OBLIQUE117, 5, 4, 0}, - {WEDGE_OBLIQUE117, 6, 4, 0}, - {WEDGE_OBLIQUE117, 7, 4, 0}, +#else + +static const wedge_code_type wedge_codebook_32_hgtw[32] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_HORIZONTAL, 4, 2}, + {WEDGE_HORIZONTAL, 4, 4}, + {WEDGE_HORIZONTAL, 4, 6}, + {WEDGE_VERTICAL, 4, 4}, + {WEDGE_OBLIQUE27, 4, 1}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 3}, + {WEDGE_OBLIQUE27, 4, 5}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE27, 4, 7}, + {WEDGE_OBLIQUE153, 4, 1}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 3}, + {WEDGE_OBLIQUE153, 4, 5}, + {WEDGE_OBLIQUE153, 4, 6}, + {WEDGE_OBLIQUE153, 4, 7}, + {WEDGE_OBLIQUE63, 1, 4}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 3, 4}, + {WEDGE_OBLIQUE63, 5, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE63, 7, 4}, + {WEDGE_OBLIQUE117, 1, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 3, 4}, + {WEDGE_OBLIQUE117, 5, 4}, + {WEDGE_OBLIQUE117, 6, 4}, + {WEDGE_OBLIQUE117, 7, 4}, }; -static const int wedge_params_32_hltw[1 << WEDGE_BITS_5] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 0}, - {WEDGE_OBLIQUE63, 4, 4, 0}, - {WEDGE_OBLIQUE117, 4, 4, 0}, - {WEDGE_OBLIQUE153, 4, 4, 0}, - - {WEDGE_VERTICAL, 2, 4, 0}, - {WEDGE_VERTICAL, 4, 4, 0}, - {WEDGE_VERTICAL, 6, 4, 0}, - {WEDGE_HORIZONTAL, 4, 4, 0}, - - {WEDGE_OBLIQUE27, 4, 1, 0}, - {WEDGE_OBLIQUE27, 4, 2, 0}, - {WEDGE_OBLIQUE27, 4, 3, 0}, - {WEDGE_OBLIQUE27, 4, 5, 0}, - {WEDGE_OBLIQUE27, 4, 6, 0}, - {WEDGE_OBLIQUE27, 4, 7, 0}, - - {WEDGE_OBLIQUE153, 4, 1, 0}, - {WEDGE_OBLIQUE153, 4, 2, 0}, - {WEDGE_OBLIQUE153, 4, 3, 0}, - {WEDGE_OBLIQUE153, 4, 5, 0}, - {WEDGE_OBLIQUE153, 4, 6, 0}, - {WEDGE_OBLIQUE153, 4, 7, 0}, - - {WEDGE_OBLIQUE63, 1, 4, 0}, - {WEDGE_OBLIQUE63, 2, 4, 0}, - {WEDGE_OBLIQUE63, 3, 4, 0}, - {WEDGE_OBLIQUE63, 5, 4, 0}, - {WEDGE_OBLIQUE63, 6, 4, 0}, - {WEDGE_OBLIQUE63, 7, 4, 0}, - - {WEDGE_OBLIQUE117, 1, 4, 0}, - {WEDGE_OBLIQUE117, 2, 4, 0}, - {WEDGE_OBLIQUE117, 3, 4, 0}, - {WEDGE_OBLIQUE117, 5, 4, 0}, - {WEDGE_OBLIQUE117, 6, 4, 0}, - {WEDGE_OBLIQUE117, 7, 4, 0}, +static const wedge_code_type wedge_codebook_32_hltw[32] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_VERTICAL, 2, 4}, + {WEDGE_VERTICAL, 4, 4}, + {WEDGE_VERTICAL, 6, 4}, + {WEDGE_HORIZONTAL, 4, 4}, + {WEDGE_OBLIQUE27, 4, 1}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 3}, + {WEDGE_OBLIQUE27, 4, 5}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE27, 4, 7}, + {WEDGE_OBLIQUE153, 4, 1}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 3}, + {WEDGE_OBLIQUE153, 4, 5}, + {WEDGE_OBLIQUE153, 4, 6}, + {WEDGE_OBLIQUE153, 4, 7}, + {WEDGE_OBLIQUE63, 1, 4}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 3, 4}, + {WEDGE_OBLIQUE63, 5, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE63, 7, 4}, + {WEDGE_OBLIQUE117, 1, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 3, 4}, + {WEDGE_OBLIQUE117, 5, 4}, + {WEDGE_OBLIQUE117, 6, 4}, + {WEDGE_OBLIQUE117, 7, 4}, }; -static const int wedge_params_32_heqw[1 << WEDGE_BITS_5] - [WEDGE_PARMS] = { - {WEDGE_OBLIQUE27, 4, 4, 0}, - {WEDGE_OBLIQUE63, 4, 4, 0}, - {WEDGE_OBLIQUE117, 4, 4, 0}, - {WEDGE_OBLIQUE153, 4, 4, 0}, - - {WEDGE_HORIZONTAL, 4, 2, 0}, - {WEDGE_HORIZONTAL, 4, 6, 0}, - {WEDGE_VERTICAL, 2, 4, 0}, - {WEDGE_VERTICAL, 6, 4, 0}, - - {WEDGE_OBLIQUE27, 4, 1, 0}, - {WEDGE_OBLIQUE27, 4, 2, 0}, - {WEDGE_OBLIQUE27, 4, 3, 0}, - {WEDGE_OBLIQUE27, 4, 5, 0}, - {WEDGE_OBLIQUE27, 4, 6, 0}, - {WEDGE_OBLIQUE27, 4, 7, 0}, - - {WEDGE_OBLIQUE153, 4, 1, 0}, - {WEDGE_OBLIQUE153, 4, 2, 0}, - {WEDGE_OBLIQUE153, 4, 3, 0}, - {WEDGE_OBLIQUE153, 4, 5, 0}, - {WEDGE_OBLIQUE153, 4, 6, 0}, - {WEDGE_OBLIQUE153, 4, 7, 0}, - - {WEDGE_OBLIQUE63, 1, 4, 0}, - {WEDGE_OBLIQUE63, 2, 4, 0}, - {WEDGE_OBLIQUE63, 3, 4, 0}, - {WEDGE_OBLIQUE63, 5, 4, 0}, - {WEDGE_OBLIQUE63, 6, 4, 0}, - {WEDGE_OBLIQUE63, 7, 4, 0}, - - {WEDGE_OBLIQUE117, 1, 4, 0}, - {WEDGE_OBLIQUE117, 2, 4, 0}, - {WEDGE_OBLIQUE117, 3, 4, 0}, - {WEDGE_OBLIQUE117, 5, 4, 0}, - {WEDGE_OBLIQUE117, 6, 4, 0}, - {WEDGE_OBLIQUE117, 7, 4, 0}, +static const wedge_code_type wedge_codebook_32_heqw[32] = { + {WEDGE_OBLIQUE27, 4, 4}, + {WEDGE_OBLIQUE63, 4, 4}, + {WEDGE_OBLIQUE117, 4, 4}, + {WEDGE_OBLIQUE153, 4, 4}, + {WEDGE_HORIZONTAL, 4, 2}, + {WEDGE_HORIZONTAL, 4, 6}, + {WEDGE_VERTICAL, 2, 4}, + {WEDGE_VERTICAL, 6, 4}, + {WEDGE_OBLIQUE27, 4, 1}, + {WEDGE_OBLIQUE27, 4, 2}, + {WEDGE_OBLIQUE27, 4, 3}, + {WEDGE_OBLIQUE27, 4, 5}, + {WEDGE_OBLIQUE27, 4, 6}, + {WEDGE_OBLIQUE27, 4, 7}, + {WEDGE_OBLIQUE153, 4, 1}, + {WEDGE_OBLIQUE153, 4, 2}, + {WEDGE_OBLIQUE153, 4, 3}, + {WEDGE_OBLIQUE153, 4, 5}, + {WEDGE_OBLIQUE153, 4, 6}, + {WEDGE_OBLIQUE153, 4, 7}, + {WEDGE_OBLIQUE63, 1, 4}, + {WEDGE_OBLIQUE63, 2, 4}, + {WEDGE_OBLIQUE63, 3, 4}, + {WEDGE_OBLIQUE63, 5, 4}, + {WEDGE_OBLIQUE63, 6, 4}, + {WEDGE_OBLIQUE63, 7, 4}, + {WEDGE_OBLIQUE117, 1, 4}, + {WEDGE_OBLIQUE117, 2, 4}, + {WEDGE_OBLIQUE117, 3, 4}, + {WEDGE_OBLIQUE117, 5, 4}, + {WEDGE_OBLIQUE117, 6, 4}, + {WEDGE_OBLIQUE117, 7, 4}, }; -static const int *get_wedge_params_lookup[BLOCK_SIZES] = { - NULL, - NULL, - NULL, - &wedge_params_16_heqw[0][0], - &wedge_params_16_hgtw[0][0], - &wedge_params_16_hltw[0][0], - &wedge_params_16_heqw[0][0], - &wedge_params_16_hgtw[0][0], - &wedge_params_16_hltw[0][0], - &wedge_params_16_heqw[0][0], - NULL, - NULL, - NULL, +const wedge_params_type wedge_params_lookup[BLOCK_SIZES] = { + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, + {5, wedge_codebook_32_heqw, wedge_signflip_lookup[3], 0}, + {5, wedge_codebook_32_hgtw, wedge_signflip_lookup[4], 0}, + {5, wedge_codebook_32_hltw, wedge_signflip_lookup[5], 0}, + {5, wedge_codebook_32_heqw, wedge_signflip_lookup[6], 0}, + {5, wedge_codebook_32_hgtw, wedge_signflip_lookup[7], 0}, + {5, wedge_codebook_32_hltw, wedge_signflip_lookup[8], 0}, + {5, wedge_codebook_32_heqw, wedge_signflip_lookup[9], 0}, + {0, wedge_codebook_8_hgtw, wedge_signflip_lookup[10], 0}, + {0, wedge_codebook_8_hltw, wedge_signflip_lookup[11], 0}, + {0, wedge_codebook_8_heqw, wedge_signflip_lookup[12], 0}, #if CONFIG_EXT_PARTITION - NULL, - NULL, - NULL, + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, + {0, NULL, NULL, 0}, #endif // CONFIG_EXT_PARTITION }; - -static const int *get_wedge_params(int wedge_index, - BLOCK_SIZE sb_type) { - const int *a = NULL; - if (wedge_index != WEDGE_NONE) { - return get_wedge_params_lookup[sb_type] + WEDGE_PARMS * wedge_index; - } - return a; -} +#endif // USE_LARGE_WEDGE_CODEBOOK static const uint8_t *get_wedge_mask_inplace(int wedge_index, int neg, @@ -387,12 +311,17 @@ static const uint8_t *get_wedge_mask_inplace(int wedge_index, const uint8_t *master; const int bh = 4 << b_height_log2_lookup[sb_type]; const int bw = 4 << b_width_log2_lookup[sb_type]; - const int *a = get_wedge_params(wedge_index, sb_type); + const wedge_code_type *a = + wedge_params_lookup[sb_type].codebook + wedge_index; + const int smoother = wedge_params_lookup[sb_type].smoother; int woff, hoff; - if (!a) return NULL; - woff = (a[1] * bw) >> 3; - hoff = (a[2] * bh) >> 3; - master = wedge_mask_obl[a[3]][neg][a[0]] + + const uint8_t wsignflip = wedge_params_lookup[sb_type].signflip[wedge_index]; + + assert(wedge_index >= 0 && + wedge_index < (1 << get_wedge_bits_lookup(sb_type))); + woff = (a->x_offset * bw) >> 3; + hoff = (a->y_offset * bh) >> 3; + master = wedge_mask_obl[smoother][neg ^ wsignflip][a->direction] + MASK_MASTER_STRIDE * (MASK_MASTER_SIZE / 2 - hoff) + MASK_MASTER_SIZE / 2 - woff; return master; @@ -410,6 +339,70 @@ const uint8_t *vp10_get_soft_mask(int wedge_index, return mask; } +// If the signs for the wedges for various blocksizes are +// inconsistent flip the sign flag. Do it only once for every +// wedge codebook. +static void init_wedge_signs() { + BLOCK_SIZE sb_type; + memset(wedge_signflip_lookup, 0, sizeof(wedge_signflip_lookup)); + for (sb_type = BLOCK_4X4; sb_type < BLOCK_SIZES; ++sb_type) { + const int bw = 4 * num_4x4_blocks_wide_lookup[sb_type]; + const int bh = 4 * num_4x4_blocks_high_lookup[sb_type]; + const wedge_params_type wedge_params = wedge_params_lookup[sb_type]; + const int wbits = wedge_params.bits; + const int wtypes = 1 << wbits; + int i, w; + if (wbits == 0) continue; + for (w = 0; w < wtypes; ++w) { + const uint8_t *mask = get_wedge_mask_inplace(w, 0, sb_type); + int sum = 0; + for (i = 0; i < bw; ++i) + sum += mask[i]; + for (i = 0; i < bh; ++i) + sum += mask[i * MASK_MASTER_STRIDE]; + sum = (sum + (bw + bh) / 2) / (bw + bh); + wedge_params.signflip[w] = (sum < 32); + } + } +} + +// Equation of line: f(x, y) = a[0]*(x - a[2]*w/8) + a[1]*(y - a[3]*h/8) = 0 +void vp10_init_wedge_masks() { + int i, j, s; + const int w = MASK_MASTER_SIZE; + const int h = MASK_MASTER_SIZE; + const int stride = MASK_MASTER_STRIDE; + const int a[2] = {2, 1}; + const double asqrt = sqrt(a[0] * a[0] + a[1] * a[1]); + for (s = 0; s < NSMOOTHERS; s++) { + for (i = 0; i < h; ++i) + for (j = 0; j < w; ++j) { + int x = (2 * j + 1 - w); + int y = (2 * i + 1 - h); + int m = (int)rint((a[0] * x + a[1] * y) / asqrt); + wedge_mask_obl[s][1][WEDGE_OBLIQUE63][i * stride + j] = + wedge_mask_obl[s][1][WEDGE_OBLIQUE27][j * stride + i] = + get_masked_weight(m, s); + wedge_mask_obl[s][1][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = + wedge_mask_obl[s][1][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = + (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m, s); + wedge_mask_obl[s][0][WEDGE_OBLIQUE63][i * stride + j] = + wedge_mask_obl[s][0][WEDGE_OBLIQUE27][j * stride + i] = + (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(m, s); + wedge_mask_obl[s][0][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = + wedge_mask_obl[s][0][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = + get_masked_weight(m, s); + wedge_mask_obl[s][1][WEDGE_VERTICAL][i * stride + j] = + wedge_mask_obl[s][1][WEDGE_HORIZONTAL][j * stride + i] = + get_masked_weight(x, s); + wedge_mask_obl[s][0][WEDGE_VERTICAL][i * stride + j] = + wedge_mask_obl[s][0][WEDGE_HORIZONTAL][j * stride + i] = + (1 << WEDGE_WEIGHT_BITS) - get_masked_weight(x, s); + } + } + init_wedge_signs(); +} + static void build_masked_compound(uint8_t *dst, int dst_stride, uint8_t *dst1, int dst1_stride, uint8_t *dst2, int dst2_stride, diff --git a/vp10/common/reconinter.h b/vp10/common/reconinter.h index 28a5ae9da..86158a143 100644 --- a/vp10/common/reconinter.h +++ b/vp10/common/reconinter.h @@ -147,51 +147,60 @@ static INLINE void highbd_inter_predictor(const uint8_t *src, int src_stride, #endif // CONFIG_VP9_HIGHBITDEPTH #if CONFIG_EXT_INTER -#define WEDGE_BITS_2 2 -#define WEDGE_BITS_3 3 -#define WEDGE_BITS_4 4 -#define WEDGE_BITS_5 5 -#define WEDGE_NONE -1 +#define MAX_WEDGE_TYPES (1 << 5) + #define WEDGE_WEIGHT_BITS 6 -static const int get_wedge_bits_lookup[BLOCK_SIZES] = { - 0, - 0, - 0, - WEDGE_BITS_4, - WEDGE_BITS_4, - WEDGE_BITS_4, - WEDGE_BITS_4, - WEDGE_BITS_4, - WEDGE_BITS_4, - WEDGE_BITS_4, - 0, - 0, - 0, -#if CONFIG_EXT_PARTITION - 0, - 0, - 0, -#endif // CONFIG_EXT_PARTITION -}; +#define WEDGE_NONE -1 + +// Angles are with respect to horizontal anti-clockwise +typedef enum { + WEDGE_HORIZONTAL = 0, + WEDGE_VERTICAL = 1, + WEDGE_OBLIQUE27 = 2, + WEDGE_OBLIQUE63 = 3, + WEDGE_OBLIQUE117 = 4, + WEDGE_OBLIQUE153 = 5, + WEDGE_DIRECTIONS +} WedgeDirectionType; + +// 3-tuple: {direction, x_offset, y_offset} +typedef struct { + WedgeDirectionType direction; + int x_offset; + int y_offset; +} wedge_code_type; + +typedef struct { + int bits; + const wedge_code_type *codebook; + uint8_t *signflip; + int smoother; +} wedge_params_type; + +extern const wedge_params_type wedge_params_lookup[BLOCK_SIZES]; + +static INLINE int get_wedge_bits_lookup(BLOCK_SIZE sb_type) { + return wedge_params_lookup[sb_type].bits; +} static INLINE int is_interinter_wedge_used(BLOCK_SIZE sb_type) { (void) sb_type; - return get_wedge_bits_lookup[sb_type] > 0; + return wedge_params_lookup[sb_type].bits > 0; } static INLINE int get_interinter_wedge_bits(BLOCK_SIZE sb_type) { - const int wbits = get_wedge_bits_lookup[sb_type]; + const int wbits = wedge_params_lookup[sb_type].bits; return (wbits > 0) ? wbits + 1 : 0; } static INLINE int is_interintra_wedge_used(BLOCK_SIZE sb_type) { (void) sb_type; - return get_wedge_bits_lookup[sb_type] > 0; + return wedge_params_lookup[sb_type].bits > 0; } static INLINE int get_interintra_wedge_bits(BLOCK_SIZE sb_type) { - return get_wedge_bits_lookup[sb_type]; + return wedge_params_lookup[sb_type].bits; } #endif // CONFIG_EXT_INTER diff --git a/vp10/decoder/decodemv.c b/vp10/decoder/decodemv.c index a92af27e9..65360f898 100644 --- a/vp10/decoder/decodemv.c +++ b/vp10/decoder/decodemv.c @@ -1577,7 +1577,7 @@ static void read_inter_block_mode_info(VP10Decoder *const pbi, xd->counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++; if (mbmi->use_wedge_interintra) { mbmi->interintra_wedge_index = - vp10_read_literal(r, get_wedge_bits_lookup[bsize]); + vp10_read_literal(r, get_wedge_bits_lookup(bsize)); mbmi->interintra_wedge_sign = 0; } } @@ -1610,7 +1610,7 @@ static void read_inter_block_mode_info(VP10Decoder *const pbi, xd->counts->wedge_interinter[bsize][mbmi->use_wedge_interinter]++; if (mbmi->use_wedge_interinter) { mbmi->interinter_wedge_index = - vp10_read_literal(r, get_wedge_bits_lookup[bsize]); + vp10_read_literal(r, get_wedge_bits_lookup(bsize)); mbmi->interinter_wedge_sign = vp10_read_bit(r); } } diff --git a/vp10/encoder/bitstream.c b/vp10/encoder/bitstream.c index 9c07051af..c9339ebcd 100644 --- a/vp10/encoder/bitstream.c +++ b/vp10/encoder/bitstream.c @@ -1338,7 +1338,7 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi, cm->fc->wedge_interintra_prob[bsize]); if (mbmi->use_wedge_interintra) { vp10_write_literal(w, mbmi->interintra_wedge_index, - get_wedge_bits_lookup[bsize]); + get_wedge_bits_lookup(bsize)); assert(mbmi->interintra_wedge_sign == 0); } } @@ -1368,7 +1368,7 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi, cm->fc->wedge_interinter_prob[bsize]); if (mbmi->use_wedge_interinter) { vp10_write_literal(w, mbmi->interinter_wedge_index, - get_wedge_bits_lookup[bsize]); + get_wedge_bits_lookup(bsize)); vp10_write_bit(w, mbmi->interinter_wedge_sign); } } diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c index 5e88d157d..78f421589 100644 --- a/vp10/encoder/rdopt.c +++ b/vp10/encoder/rdopt.c @@ -7146,7 +7146,7 @@ static int64_t handle_inter_mode(VP10_COMP *cpi, MACROBLOCK *x, mbmi->use_wedge_interinter = 1; rs = vp10_cost_literal(get_interinter_wedge_bits(bsize)) + vp10_cost_bit(cm->fc->wedge_interinter_prob[bsize], 1); - wedge_types = (1 << get_wedge_bits_lookup[bsize]); + wedge_types = (1 << get_wedge_bits_lookup(bsize)); vp10_build_inter_predictors_for_planes_single_buf( xd, bsize, 0, 0, mi_row, mi_col, 0, preds0, strides); @@ -7384,7 +7384,7 @@ static int64_t handle_inter_mode(VP10_COMP *cpi, MACROBLOCK *x, // Disbale wedge search if source variance is small if (x->source_variance > cpi->sf.disable_wedge_search_var_thresh) { mbmi->use_wedge_interintra = 1; - wedge_types = (1 << get_wedge_bits_lookup[bsize]); + wedge_types = (1 << get_wedge_bits_lookup(bsize)); rwedge = vp10_cost_literal(get_interintra_wedge_bits(bsize)) + vp10_cost_bit(cm->fc->wedge_interintra_prob[bsize], 1); for (wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {