From d50ae6990c655681f979c9cb54425cec4972e88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Thu, 27 Jul 2017 09:49:17 +0300 Subject: [PATCH] Add sum of absolute coefficients to strategies --- src/rdo.c | 22 +++------------------- src/search.c | 1 + src/strategies/generic/quant-generic.c | 10 ++++++++++ src/strategies/strategies-quant.c | 3 ++- src/strategies/strategies-quant.h | 4 ++++ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/rdo.c b/src/rdo.c index 67e5088b..ae1dd143 100644 --- a/src/rdo.c +++ b/src/rdo.c @@ -33,6 +33,8 @@ #include "tables.h" #include "transform.h" +#include "strategies/strategies-quant.h" + #define QUANT_SHIFT 14 #define SCAN_SET_SIZE 16 @@ -194,24 +196,6 @@ static INLINE uint32_t get_coeff_cabac_cost( } -/** - * \brief Calculate a fast estimate of coefficient bitcost. - * - * \param coeff coefficient array - * \param width coeff block width - * - * \returns number of bits needed to code coefficients - */ -static INLINE uint32_t get_coeff_fast_cost(const coeff_t *coeff, int32_t width) -{ - uint32_t coeff_sum = 0; - for (int i = 0; i < width * width; i++) { - coeff_sum += abs(coeff[i]); - } - return (uint32_t) COEFF_SUM_MULTIPLIER * coeff_sum + 0.5; -} - - /** * \brief Estimate bitcost for coding coefficients. * @@ -231,7 +215,7 @@ uint32_t kvz_get_coeff_cost(const encoder_state_t * const state, return get_coeff_cabac_cost(state, coeff, width, type, scan_mode); } else { - return get_coeff_fast_cost(coeff, width); + return COEFF_SUM_MULTIPLIER * kvz_coeff_abs_sum(coeff, width * width) + 0.5; } } diff --git a/src/search.c b/src/search.c index ef381f28..49a202b2 100644 --- a/src/search.c +++ b/src/search.c @@ -36,6 +36,7 @@ #include "transform.h" #include "videoframe.h" #include "strategies/strategies-picture.h" +#include "strategies/strategies-quant.h" #define IN_FRAME(x, y, width, height, block_width, block_height) \ diff --git a/src/strategies/generic/quant-generic.c b/src/strategies/generic/quant-generic.c index 4cf40a5d..144cabd7 100644 --- a/src/strategies/generic/quant-generic.c +++ b/src/strategies/generic/quant-generic.c @@ -320,6 +320,15 @@ void kvz_dequant_generic(const encoder_state_t * const state, coeff_t *q_coef, c } } +static uint32_t coeff_abs_sum_generic(const coeff_t *coeffs, size_t length) +{ + uint32_t sum = 0; + for (int i = 0; i < length; i++) { + sum += abs(coeffs[i]); + } + return sum; +} + int kvz_strategy_register_quant_generic(void* opaque, uint8_t bitdepth) { bool success = true; @@ -327,6 +336,7 @@ int kvz_strategy_register_quant_generic(void* opaque, uint8_t bitdepth) success &= kvz_strategyselector_register(opaque, "quant", "generic", 0, &kvz_quant_generic); success &= kvz_strategyselector_register(opaque, "quantize_residual", "generic", 0, &kvz_quantize_residual_generic); success &= kvz_strategyselector_register(opaque, "dequant", "generic", 0, &kvz_dequant_generic); + success &= kvz_strategyselector_register(opaque, "coeff_abs_sum", "generic", 0, &coeff_abs_sum_generic); return success; } diff --git a/src/strategies/strategies-quant.c b/src/strategies/strategies-quant.c index 958cf9a1..40745fe6 100644 --- a/src/strategies/strategies-quant.c +++ b/src/strategies/strategies-quant.c @@ -29,6 +29,7 @@ quant_func *kvz_quant; quant_residual_func *kvz_quantize_residual; dequant_func *kvz_dequant; +coeff_abs_sum_func *kvz_coeff_abs_sum; int kvz_strategy_register_quant(void* opaque, uint8_t bitdepth) { @@ -40,4 +41,4 @@ int kvz_strategy_register_quant(void* opaque, uint8_t bitdepth) { success &= kvz_strategy_register_quant_avx2(opaque, bitdepth); } return success; -} \ No newline at end of file +} diff --git a/src/strategies/strategies-quant.h b/src/strategies/strategies-quant.h index f30c58cd..f568a616 100644 --- a/src/strategies/strategies-quant.h +++ b/src/strategies/strategies-quant.h @@ -45,10 +45,13 @@ typedef unsigned (quant_residual_func)(encoder_state_t *const state, typedef unsigned (dequant_func)(const encoder_state_t * const state, coeff_t *q_coef, coeff_t *coef, int32_t width, int32_t height, int8_t type, int8_t block_type); +typedef uint32_t (coeff_abs_sum_func)(const coeff_t *coeffs, size_t length); + // Declare function pointers. extern quant_func * kvz_quant; extern quant_residual_func * kvz_quantize_residual; extern dequant_func *kvz_dequant; +extern coeff_abs_sum_func *kvz_coeff_abs_sum; int kvz_strategy_register_quant(void* opaque, uint8_t bitdepth); @@ -57,6 +60,7 @@ int kvz_strategy_register_quant(void* opaque, uint8_t bitdepth); {"quant", (void**) &kvz_quant}, \ {"quantize_residual", (void**) &kvz_quantize_residual}, \ {"dequant", (void**) &kvz_dequant}, \ + {"coeff_abs_sum", (void**) &kvz_coeff_abs_sum}, \