Use fixed point in get_mvd_coding_cost

This commit is contained in:
Ari Koivula 2016-08-30 18:12:14 +03:00
parent ec7507a935
commit d0512d25c6
3 changed files with 17 additions and 13 deletions

View file

@ -42,8 +42,6 @@
const uint32_t kvz_g_go_rice_range[5] = { 7, 14, 26, 46, 78 };
const uint32_t kvz_g_go_rice_prefix_len[5] = { 8, 7, 6, 5, 4 };
#define CTX_ENTROPY_BITS(ctx,val) kvz_entropy_bits[(ctx)->uc_state ^ val]
/**
* Entropy bits to estimate coded bits in RDO / RDOQ (From HM 12.0)
*/

View file

@ -57,7 +57,12 @@ uint32_t kvz_get_mvd_coding_cost_cabac(encoder_state_t * const state, vector2d_t
uint8_t kvz_skip_unnecessary_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff, int32_t width,
int32_t height, int8_t type, int8_t scan_mode, int8_t block_type);
// Fixed points fractional bits, 16b.16b
extern const uint32_t kvz_entropy_bits[128];
#define CTX_ENTROPY_BITS(ctx, val) kvz_entropy_bits[(ctx)->uc_state ^ (val)]
// Floating point fractional bits, derived from kvz_entropy_bits
extern const float kvz_f_entropy_bits[128];
#define CTX_ENTROPY_FBITS(ctx,val) kvz_f_entropy_bits[(ctx)->uc_state ^ (val)]
#define CTX_ENTROPY_FBITS(ctx, val) kvz_f_entropy_bits[(ctx)->uc_state ^ (val)]
#endif

View file

@ -184,28 +184,29 @@ static unsigned select_starting_point(int16_t num_cand, inter_merge_cand_t *merg
static uint32_t get_mvd_coding_cost(encoder_state_t * const state, vector2d_t *mvd, const cabac_data_t* cabac)
{
double bitcost = 0;
unsigned bitcost = 0;
const vector2d_t abs_mvd = { abs(mvd->x), abs(mvd->y) };
bitcost += CTX_ENTROPY_FBITS(&cabac->ctx.cu_mvd_model[0], abs_mvd.x > 0);
bitcost += CTX_ENTROPY_BITS(&cabac->ctx.cu_mvd_model[0], abs_mvd.x > 0);
if (abs_mvd.x > 0) {
bitcost += CTX_ENTROPY_FBITS(&cabac->ctx.cu_mvd_model[1], abs_mvd.x > 1);
bitcost += CTX_ENTROPY_BITS(&cabac->ctx.cu_mvd_model[1], abs_mvd.x > 1);
if (abs_mvd.x > 1) {
bitcost += get_ep_ex_golomb_bitcost(abs_mvd.x - 2);
bitcost += get_ep_ex_golomb_bitcost(abs_mvd.x - 2) << 15;
}
bitcost += 1; // sign
bitcost += 1 << 15; // sign
}
bitcost += CTX_ENTROPY_FBITS(&cabac->ctx.cu_mvd_model[0], abs_mvd.y > 0);
bitcost += CTX_ENTROPY_BITS(&cabac->ctx.cu_mvd_model[0], abs_mvd.y > 0);
if (abs_mvd.y > 0) {
bitcost += CTX_ENTROPY_FBITS(&cabac->ctx.cu_mvd_model[1], abs_mvd.y > 1);
bitcost += CTX_ENTROPY_BITS(&cabac->ctx.cu_mvd_model[1], abs_mvd.y > 1);
if (abs_mvd.y > 1) {
bitcost += get_ep_ex_golomb_bitcost(abs_mvd.y - 2);
bitcost += get_ep_ex_golomb_bitcost(abs_mvd.y - 2) << 15;
}
bitcost += 1; // sign
bitcost += 1 << 15; // sign
}
return bitcost + 0.5;
// Round and shift back to integer bits.
return (bitcost + (1 << 14)) >> 15;
}