mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-24 02:24:07 +00:00
Add sum of absolute coefficients to strategies
This commit is contained in:
parent
59faca0646
commit
d50ae6990c
22
src/rdo.c
22
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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}, \
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue