Move transform coding and chroma cu coding out of encode_intra_coding_unit

This commit is contained in:
Joose Sainio 2022-03-24 12:09:14 +02:00
parent a88553b206
commit b2a94d4276
2 changed files with 36 additions and 34 deletions

View file

@ -814,7 +814,7 @@ static void encode_chroma_intra_cu(cabac_data_t* const cabac, const cu_info_t* c
} }
} }
static void encode_intra_coding_unit(encoder_state_t * const state, static void encode_intra_luma_coding_unit(encoder_state_t * const state,
cabac_data_t * const cabac, cabac_data_t * const cabac,
const cu_info_t * const cur_cu, const cu_info_t * const cur_cu,
int x, int y, int depth, lcu_t* lcu, lcu_coeff_t* coeff, double* bits_out) int x, int y, int depth, lcu_t* lcu, lcu_coeff_t* coeff, double* bits_out)
@ -1063,24 +1063,6 @@ static void encode_intra_coding_unit(encoder_state_t * const state,
if (cabac->only_count && bits_out) *bits_out += 5; if (cabac->only_count && bits_out) *bits_out += 5;
} }
} }
// Code chroma prediction mode.
if (state->encoder_control->chroma_format != KVZ_CSP_400 && depth != 4) {
encode_chroma_intra_cu(cabac, cur_cu, x, y, frame, cu_width, state->encoder_control->cfg.cclm);
}
// if we are counting bits, the cost for transform coeffs is done separately
// To get the distortion at the same time
if (!cabac->only_count) {
encode_transform_coeff(state, x, y, depth, 0, 0, 0, 0, coeff);
encode_mts_idx(state, cabac, cur_cu);
if (state->encoder_control->chroma_format != KVZ_CSP_400 && depth == 4 && x % 8 && y % 8) {
encode_chroma_intra_cu(cabac, cur_cu, x, y, frame, cu_width, state->encoder_control->cfg.cclm);
encode_transform_coeff(state, x, y, depth, 0, 0, 0, 1, coeff);
}
}
} }
/** /**
@ -1511,7 +1493,23 @@ void kvz_encode_coding_tree(encoder_state_t * const state,
} }
} else if (cur_cu->type == CU_INTRA) { } else if (cur_cu->type == CU_INTRA) {
encode_intra_coding_unit(state, cabac, cur_cu, x, y, depth, NULL, coeff, NULL); encode_intra_luma_coding_unit(state, cabac, cur_cu, x, y, depth, NULL, coeff, NULL);
// Code chroma prediction mode.
if (state->encoder_control->chroma_format != KVZ_CSP_400 && depth != 4) {
encode_chroma_intra_cu(cabac, cur_cu, x, y, frame, cu_width, state->encoder_control->cfg.cclm);
}
encode_transform_coeff(state, x, y, depth, 0, 0, 0, 0, coeff);
encode_mts_idx(state, cabac, cur_cu);
// For 4x4 the chroma PU/TU is coded after the last
if (state->encoder_control->chroma_format != KVZ_CSP_400 && depth == 4 && x % 8 && y % 8) {
encode_chroma_intra_cu(cabac, cur_cu, x, y, frame, cu_width, state->encoder_control->cfg.cclm);
encode_transform_coeff(state, x, y, depth, 0, 0, 0, 1, coeff);
}
} }
else { else {
@ -1640,7 +1638,7 @@ double kvz_mock_encode_coding_unit(
} }
} }
else if (cur_cu->type == CU_INTRA) { else if (cur_cu->type == CU_INTRA) {
encode_intra_coding_unit(state, cabac, cur_cu, x, y, depth, lcu, NULL, &bits); encode_intra_luma_coding_unit(state, cabac, cur_cu, x, y, depth, lcu, NULL, &bits);
} }
return bits; return bits;
} }

View file

@ -916,15 +916,19 @@ double kvz_luma_mode_bits(const encoder_state_t *state, int8_t luma_mode, const
} }
} }
cabac_ctx_t* ctx = &(cabac->ctx.luma_planar_model[1]); cabac_ctx_t* ctx = &(cabac->ctx.luma_planar_model[1]);
CABAC_FBITS_UPDATE(cabac, ctx, mode_in_preds, mode_bits, "prev_intra_luma_pred_flag_search"); CABAC_FBITS_UPDATE(
cabac,
ctx,
mode_in_preds != -1,
mode_bits,
"prev_intra_luma_pred_flag_search");
if (state->search_cabac.update) { if (state->search_cabac.update) {
if (mode_in_preds) { if (mode_in_preds) {
CABAC_BIN_EP(cabac, !(luma_mode == intra_preds[0]), "mpm_idx"); CABAC_BIN_EP(cabac, !(luma_mode == intra_preds[0]), "mpm_idx");
if (luma_mode != intra_preds[0]) { if (luma_mode != intra_preds[0]) {
CABAC_BIN_EP(cabac, !(luma_mode == intra_preds[1]), "mpm_idx"); CABAC_BIN_EP(cabac, !(luma_mode == intra_preds[1]), "mpm_idx");
} }
} } else {
else {
// This value should be transformed for actual coding, // This value should be transformed for actual coding,
// but here the value does not actually matter, just that we write 5 bits // but here the value does not actually matter, just that we write 5 bits
CABAC_BINS_EP(cabac, luma_mode, 5, "rem_intra_luma_pred_mode"); CABAC_BINS_EP(cabac, luma_mode, 5, "rem_intra_luma_pred_mode");