Fixed a bug of ALF failing when CC-ALF was not enabled. Added ALF to README.md parameters.

This commit is contained in:
Arttu Makinen 2020-12-21 14:05:05 +02:00
parent 75b51c1d27
commit e06759eb6e
3 changed files with 56 additions and 59 deletions

View file

@ -191,6 +191,10 @@ Compression tools:
- band: Band offset only - band: Band offset only
- edge: Edge offset only - edge: Edge offset only
- full: Full SAO - full: Full SAO
--alf <string> : Adaptive Loop Filter [off]
- off: ALF disabled
- no-cc: ALF enabled without cross component refinement
- full: Full ALF
--(no-)rdoq : Rate-distortion optimized quantization [enabled] --(no-)rdoq : Rate-distortion optimized quantization [enabled]
--(no-)rdoq-skip : Skip RDOQ for 4x4 blocks. [disabled] --(no-)rdoq-skip : Skip RDOQ for 4x4 blocks. [disabled]
--(no-)signhide : Sign hiding [disabled] --(no-)signhide : Sign hiding [disabled]

View file

@ -32,12 +32,6 @@ int comparator(const void *v1, const void *v2)
void set_aps_map(kvz_config *const cfg) void set_aps_map(kvz_config *const cfg)
{ {
cfg->param_set_map = malloc(ALF_CTB_MAX_NUM_APS * sizeof(param_set_map)); cfg->param_set_map = malloc(ALF_CTB_MAX_NUM_APS * sizeof(param_set_map));
//memset(cfg->param_set_map, 0, ALF_CTB_MAX_NUM_APS * sizeof(*cfg->param_set_map));
if (g_frame_count == state->frame->num) {
return;
}
g_frame_count = state->frame->num;
reset_alf_param(&alf_param); reset_alf_param(&alf_param);
cfg->param_set_map[aps_idx + T_ALF_APS].b_changed = false; cfg->param_set_map[aps_idx + T_ALF_APS].b_changed = false;
reset_aps(&cfg->param_set_map[aps_idx + T_ALF_APS].parameter_set, cfg->alf_type == KVZ_ALF_FULL); reset_aps(&cfg->param_set_map[aps_idx + T_ALF_APS].parameter_set, cfg->alf_type == KVZ_ALF_FULL);
@ -50,7 +44,6 @@ void reset_aps(alf_aps *src, bool cc_alf_enabled)
src->aps_id = -1; src->aps_id = -1;
src->temporal_id = 0; src->temporal_id = 0;
src->layer_id = 0; src->layer_id = 0;
reset_alf_param(src); reset_alf_param(src);
if (cc_alf_enabled) { if (cc_alf_enabled) {
reset_cc_alf_aps_param(&src->cc_alf_aps_param); reset_cc_alf_aps_param(&src->cc_alf_aps_param);
@ -1759,6 +1752,11 @@ void kvz_alf_enc_process(encoder_state_t *const state)
kvz_alf_reconstruct(state, &arr_vars); kvz_alf_reconstruct(state, &arr_vars);
if (state->encoder_control->cfg.alf_type != KVZ_ALF_FULL)
{
return;
}
// Do not transmit CC ALF if it is unchanged // Do not transmit CC ALF if it is unchanged
if(state->slice->tile_group_alf_enabled_flag[COMPONENT_Y]) if(state->slice->tile_group_alf_enabled_flag[COMPONENT_Y])
{ {
@ -1784,11 +1782,6 @@ void kvz_alf_enc_process(encoder_state_t *const state)
aps->cc_alf_aps_param.new_cc_alf_filter[1] = false; aps->cc_alf_aps_param.new_cc_alf_filter[1] = false;
} }
if (state->encoder_control->cfg.alf_type != 2)
{
return;
}
const kvz_picture *org_yuv = state->tile->frame->source; const kvz_picture *org_yuv = state->tile->frame->source;
const kvz_picture *rec_yuv = state->tile->frame->rec; const kvz_picture *rec_yuv = state->tile->frame->rec;
@ -4820,19 +4813,18 @@ void kvz_encode_alf_bits(encoder_state_t * const state, const int ctu_idx)
} }
} }
if (state->encoder_control->cfg.alf_type == KVZ_ALF_FULL) {
int num_components = state->encoder_control->chroma_format == KVZ_CSP_400 ? 1 : MAX_NUM_COMPONENT; int num_components = state->encoder_control->chroma_format == KVZ_CSP_400 ? 1 : MAX_NUM_COMPONENT;
for (int comp_idx = 1; comp_idx < num_components; comp_idx++) for (int comp_idx = 1; comp_idx < num_components; comp_idx++) {
{ if (cc_filter_param->cc_alf_filter_enabled[comp_idx - 1]) {
if (cc_filter_param->cc_alf_filter_enabled[comp_idx - 1])
{
const int filter_count = cc_filter_param->cc_alf_filter_count[comp_idx - 1]; const int filter_count = cc_filter_param->cc_alf_filter_count[comp_idx - 1];
code_cc_alf_filter_control_idc(state, &state->cabac, alf_info->cc_alf_filter_control[comp_idx - 1][ctu_idx], comp_idx, code_cc_alf_filter_control_idc(state, &state->cabac, alf_info->cc_alf_filter_control[comp_idx - 1][ctu_idx], comp_idx,
ctu_idx, alf_info->cc_alf_filter_control[comp_idx - 1], filter_count); ctu_idx, alf_info->cc_alf_filter_control[comp_idx - 1], filter_count);
} }
} }
} }
} }
}
void encoder_state_write_adaptation_parameter_set(encoder_state_t * const state, alf_aps *aps) void encoder_state_write_adaptation_parameter_set(encoder_state_t * const state, alf_aps *aps)
{ {
@ -4865,6 +4857,7 @@ void encode_alf_aps_flags(encoder_state_t * const state,
alf_aps* aps) alf_aps* aps)
{ {
bitstream_t * const stream = &state->stream; bitstream_t * const stream = &state->stream;
const bool cc_alf_enabled = state->encoder_control->cfg.alf_type == KVZ_ALF_FULL;
WRITE_U(stream, aps->new_filter_flag[CHANNEL_TYPE_LUMA], 1, "alf_luma_new_filter"); WRITE_U(stream, aps->new_filter_flag[CHANNEL_TYPE_LUMA], 1, "alf_luma_new_filter");
if (state->encoder_control->chroma_format != KVZ_CSP_400) if (state->encoder_control->chroma_format != KVZ_CSP_400)
@ -4874,9 +4867,15 @@ void encode_alf_aps_flags(encoder_state_t * const state,
if (state->encoder_control->chroma_format != KVZ_CSP_400) if (state->encoder_control->chroma_format != KVZ_CSP_400)
{ {
if (cc_alf_enabled) {
WRITE_U(stream, aps->cc_alf_aps_param.new_cc_alf_filter[COMPONENT_Cb - 1], 1, "alf_cc_cb_filter_signal_flag"); WRITE_U(stream, aps->cc_alf_aps_param.new_cc_alf_filter[COMPONENT_Cb - 1], 1, "alf_cc_cb_filter_signal_flag");
WRITE_U(stream, aps->cc_alf_aps_param.new_cc_alf_filter[COMPONENT_Cr - 1], 1, "alf_cc_cr_filter_signal_flag"); WRITE_U(stream, aps->cc_alf_aps_param.new_cc_alf_filter[COMPONENT_Cr - 1], 1, "alf_cc_cr_filter_signal_flag");
} }
else {
WRITE_U(stream, 0, 1, "alf_cc_cb_filter_signal_flag");
WRITE_U(stream, 0, 1, "alf_cc_cr_filter_signal_flag");
}
}
if (aps->new_filter_flag[CHANNEL_TYPE_LUMA]) if (aps->new_filter_flag[CHANNEL_TYPE_LUMA])
{ {
@ -4956,6 +4955,7 @@ void encode_alf_aps_flags(encoder_state_t * const state,
#endif*/ #endif*/
} }
if (cc_alf_enabled) {
for (int cc_idx = 0; cc_idx < 2; cc_idx++) for (int cc_idx = 0; cc_idx < 2; cc_idx++)
{ {
if (aps->cc_alf_aps_param.new_cc_alf_filter[cc_idx]) if (aps->cc_alf_aps_param.new_cc_alf_filter[cc_idx])
@ -4972,7 +4972,7 @@ void encode_alf_aps_flags(encoder_state_t * const state,
for (int filter_idx = 0; filter_idx < filter_count; filter_idx++) for (int filter_idx = 0; filter_idx < filter_count; filter_idx++)
{ {
int num_coeff = 8; //CC_ALF_FILTER int num_coeff = MAX_NUM_CC_ALF_CHROMA_COEFF; //CC_ALF_FILTER
const short *coeff = aps->cc_alf_aps_param.cc_alf_coeff[cc_idx][filter_idx]; const short *coeff = aps->cc_alf_aps_param.cc_alf_coeff[cc_idx][filter_idx];
// Filter coefficients // Filter coefficients
@ -4990,13 +4990,7 @@ void encode_alf_aps_flags(encoder_state_t * const state,
WRITE_U(stream, coeff[i] < 0 ? 1 : 0, 1, cc_idx == 0 ? "alf_cc_cb_coeff_sign" : "alf_cc_cr_coeff_sign"); WRITE_U(stream, coeff[i] < 0 ? 1 : 0, 1, cc_idx == 0 ? "alf_cc_cb_coeff_sign" : "alf_cc_cr_coeff_sign");
} }
} }
/*DTRACE(g_trace_ctx, D_SYNTAX, "%s coeff filter_idx %d: ", cc_idx == 0 ? "Cb" : "Cr", filter_idx);
for (int i = 0; i < alfShape.numCoeff; i++)
{
DTRACE(g_trace_ctx, D_SYNTAX, "%d ", coeff[i]);
} }
DTRACE(g_trace_ctx, D_SYNTAX, "\n");*/
} }
} }
} }
@ -5477,7 +5471,6 @@ void code_cc_alf_filter_control_idc(encoder_state_t * const state,
CABAC_BIN_EP(cabac, 0, "cc_alf_filter_control_flag"); CABAC_BIN_EP(cabac, 0, "cc_alf_filter_control_flag");
} }
} }
//DTRACE(g_trace_ctx, D_SYNTAX, "ccAlfFilterControlIdc() comp_id=%d pos=(%d,%d) ctxt=%d, filter_count=%d, idc_val=%d\n", comp_id, lumaPos.x, lumaPos.y, ctxt, filter_count, idc_val);
} }
//--------------------------------------------------------------------- //---------------------------------------------------------------------

View file

@ -618,7 +618,7 @@ static void encoder_state_write_bitstream_seq_parameter_set(bitstream_t* stream,
WRITE_U(stream, encoder->cfg.alf_type ? 1 : 0, 1, "sps_alf_enable_flag"); WRITE_U(stream, encoder->cfg.alf_type ? 1 : 0, 1, "sps_alf_enable_flag");
if (encoder->cfg.alf_type && encoder->chroma_format != KVZ_CSP_400) if (encoder->cfg.alf_type && encoder->chroma_format != KVZ_CSP_400)
{ {
WRITE_U(stream, encoder->cfg.alf_type == 2, 1, "sps_ccalf_enabled_flag"); WRITE_U(stream, encoder->cfg.alf_type == KVZ_ALF_FULL, 1, "sps_ccalf_enabled_flag");
} }
WRITE_U(stream, 0, 1, "sps_lmcs_enable_flag"); WRITE_U(stream, 0, 1, "sps_lmcs_enable_flag");
@ -1270,7 +1270,7 @@ void kvz_encoder_state_write_bitstream_slice_header(
WRITE_U(stream, state->slice->tile_group_chroma_aps_id, 3, "slice_alf_aps_id_chroma"); WRITE_U(stream, state->slice->tile_group_chroma_aps_id, 3, "slice_alf_aps_id_chroma");
} }
if (encoder->cfg.alf_type == 2) if (encoder->cfg.alf_type == KVZ_ALF_FULL)
{ {
WRITE_U(stream, state->slice->cc_filter_param->cc_alf_filter_enabled[COMPONENT_Cb - 1], 1, "slice_cc_alf_cb_enabled_flag"); WRITE_U(stream, state->slice->cc_filter_param->cc_alf_filter_enabled[COMPONENT_Cb - 1], 1, "slice_cc_alf_cb_enabled_flag");
if (state->slice->cc_filter_param->cc_alf_filter_enabled[COMPONENT_Cb - 1]) if (state->slice->cc_filter_param->cc_alf_filter_enabled[COMPONENT_Cb - 1])