mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
Update context selection to match VVC
This commit is contained in:
parent
1fd583eae0
commit
e8eab326fb
20
src/rdo.c
20
src/rdo.c
|
@ -687,7 +687,7 @@ unsigned templateAbsSum(const coeff_t* coeff, int baseLevel, uint32_t posX, uin
|
|||
|
||||
// ToDo: implement new RDOQ
|
||||
void kvz_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, int8_t tr_depth)
|
||||
int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth, uint16_t cbf)
|
||||
{
|
||||
const encoder_control_t * const encoder = state->encoder_control;
|
||||
cabac_data_t * const cabac = &state->cabac;
|
||||
|
@ -970,9 +970,21 @@ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff,
|
|||
best_cost = block_uncoded_cost + lambda * CTX_ENTROPY_BITS(&(cabac->ctx.cu_qt_root_cbf_model),0);
|
||||
base_cost += lambda * CTX_ENTROPY_BITS(&(cabac->ctx.cu_qt_root_cbf_model),1);
|
||||
} else {
|
||||
// ToDo: update for VVC contexts
|
||||
cabac_ctx_t* base_cbf_model = type?(cabac->ctx.qt_cbf_model_cb):(cabac->ctx.qt_cbf_model_luma);
|
||||
ctx_cbf = ( type ? tr_depth : !tr_depth);
|
||||
cabac_ctx_t* base_cbf_model = NULL;
|
||||
switch (type) {
|
||||
case COLOR_Y:
|
||||
base_cbf_model = cabac->ctx.qt_cbf_model_luma;
|
||||
break;
|
||||
case COLOR_U:
|
||||
base_cbf_model = cabac->ctx.qt_cbf_model_cb;
|
||||
break;
|
||||
case COLOR_V:
|
||||
base_cbf_model = cabac->ctx.qt_cbf_model_cr;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
ctx_cbf = ( type != COLOR_V ? 0 : cbf_is_set(cbf, 5 - kvz_math_floor_log2(width), COLOR_U));
|
||||
best_cost = block_uncoded_cost + lambda * CTX_ENTROPY_BITS(&base_cbf_model[ctx_cbf],0);
|
||||
base_cost += lambda * CTX_ENTROPY_BITS(&base_cbf_model[ctx_cbf],1);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ extern const uint32_t kvz_g_go_rice_range[5];
|
|||
extern const uint32_t kvz_g_go_rice_prefix_len[5];
|
||||
|
||||
void kvz_rdoq(encoder_state_t *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, int8_t tr_depth);
|
||||
int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth, uint16_t cbf);
|
||||
|
||||
uint32_t kvz_get_coeff_cost(const encoder_state_t * const state,
|
||||
const coeff_t *coeff,
|
||||
|
|
|
@ -282,7 +282,7 @@ double kvz_cu_rd_cost_luma(const encoder_state_t *const state,
|
|||
cbf_is_set(tr_cu->cbf, depth, COLOR_U) ||
|
||||
cbf_is_set(tr_cu->cbf, depth, COLOR_V))
|
||||
{
|
||||
const cabac_ctx_t *ctx = &(state->cabac.ctx.qt_cbf_model_luma[!tr_depth]);
|
||||
const cabac_ctx_t *ctx = &(state->cabac.ctx.qt_cbf_model_luma[0]);
|
||||
tr_tree_bits += CTX_ENTROPY_FBITS(ctx, cbf_is_set(pred_cu->cbf, depth, COLOR_Y));
|
||||
}
|
||||
|
||||
|
@ -331,10 +331,12 @@ double kvz_cu_rd_cost_chroma(const encoder_state_t *const state,
|
|||
if (depth < MAX_PU_DEPTH) {
|
||||
const int tr_depth = depth - pred_cu->depth;
|
||||
// ToDo: Update for VVC contexts
|
||||
const cabac_ctx_t *ctx = &(state->cabac.ctx.qt_cbf_model_cb[tr_depth]);
|
||||
const cabac_ctx_t *ctx = &(state->cabac.ctx.qt_cbf_model_cb[0]);
|
||||
if (tr_depth == 0 || cbf_is_set(pred_cu->cbf, depth - 1, COLOR_U)) {
|
||||
tr_tree_bits += CTX_ENTROPY_FBITS(ctx, cbf_is_set(pred_cu->cbf, depth, COLOR_U));
|
||||
}
|
||||
int is_set = cbf_is_set(pred_cu->cbf, depth, COLOR_U);
|
||||
ctx = &(state->cabac.ctx.qt_cbf_model_cr[is_set]);
|
||||
if (tr_depth == 0 || cbf_is_set(pred_cu->cbf, depth - 1, COLOR_V)) {
|
||||
tr_tree_bits += CTX_ENTROPY_FBITS(ctx, cbf_is_set(pred_cu->cbf, depth, COLOR_V));
|
||||
}
|
||||
|
|
|
@ -398,10 +398,11 @@ static double search_intra_trdepth(encoder_state_t * const state,
|
|||
const uint8_t tr_depth = depth - pred_cu->depth;
|
||||
|
||||
// ToDo: update for VVC contexts
|
||||
const cabac_ctx_t *ctx = &(state->cabac.ctx.qt_cbf_model_cb[tr_depth]);
|
||||
const cabac_ctx_t* ctx = &(state->cabac.ctx.qt_cbf_model_cb[0]);
|
||||
if (tr_depth == 0 || cbf_is_set(pred_cu->cbf, depth - 1, COLOR_U)) {
|
||||
cbf_bits += CTX_ENTROPY_FBITS(ctx, cbf_is_set(pred_cu->cbf, depth, COLOR_U));
|
||||
}
|
||||
ctx = &(state->cabac.ctx.qt_cbf_model_cr[cbf_is_set(pred_cu->cbf, depth, COLOR_U)]);
|
||||
if (tr_depth == 0 || cbf_is_set(pred_cu->cbf, depth - 1, COLOR_V)) {
|
||||
cbf_bits += CTX_ENTROPY_FBITS(ctx, cbf_is_set(pred_cu->cbf, depth, COLOR_V));
|
||||
}
|
||||
|
|
|
@ -681,10 +681,10 @@ int kvz_quantize_residual_avx2(encoder_state_t *const state,
|
|||
{
|
||||
int8_t tr_depth = cur_cu->tr_depth - cur_cu->depth;
|
||||
tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0);
|
||||
kvz_rdoq(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
|
||||
scan_order, cur_cu->type, tr_depth);
|
||||
kvz_rdoq(state, coeff, coeff_out, width, width, color,
|
||||
scan_order, cur_cu->type, tr_depth, cur_cu->cbf);
|
||||
} else {
|
||||
kvz_quant(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
|
||||
kvz_quant(state, coeff, coeff_out, width, width, color,
|
||||
scan_order, cur_cu->type);
|
||||
}
|
||||
|
||||
|
|
|
@ -227,11 +227,11 @@ int kvz_quantize_residual_generic(encoder_state_t *const state,
|
|||
{
|
||||
int8_t tr_depth = cur_cu->tr_depth - cur_cu->depth;
|
||||
tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0);
|
||||
kvz_rdoq(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
|
||||
scan_order, cur_cu->type, tr_depth);
|
||||
kvz_rdoq(state, coeff, coeff_out, width, width, color,
|
||||
scan_order, cur_cu->type, tr_depth, cur_cu->cbf);
|
||||
} else {
|
||||
|
||||
kvz_quant(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
|
||||
kvz_quant(state, coeff, coeff_out, width, width, color,
|
||||
scan_order, cur_cu->type);
|
||||
}
|
||||
|
||||
|
|
|
@ -321,7 +321,6 @@ static void quantize_tr_residual(encoder_state_t * const state,
|
|||
// Clear coded block flag structures for depths lower than current depth.
|
||||
// This should ensure that the CBF data doesn't get corrupted if this function
|
||||
// is called more than once.
|
||||
cbf_clear(&cur_pu->cbf, depth, color);
|
||||
|
||||
int32_t tr_width;
|
||||
if (color == COLOR_Y) {
|
||||
|
@ -420,6 +419,7 @@ static void quantize_tr_residual(encoder_state_t * const state,
|
|||
early_skip);
|
||||
}
|
||||
|
||||
cbf_clear(&cur_pu->cbf, depth, color);
|
||||
if (has_coeffs) {
|
||||
cbf_set(&cur_pu->cbf, depth, color);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue