mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
Adjustments and cleaning.
WIP
This commit is contained in:
parent
c76c445142
commit
b04bb66160
449
src/alf.c
449
src/alf.c
|
@ -16,6 +16,13 @@ void kvz_alf_init(encoder_state_t *const state,
|
||||||
encoder_state_config_slice_t *slice)
|
encoder_state_config_slice_t *slice)
|
||||||
//alf_info_t *alf)
|
//alf_info_t *alf)
|
||||||
{
|
{
|
||||||
|
if (g_slice_count == state->slice->id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_slice_count = state->slice->id;
|
||||||
|
|
||||||
|
reset_alf_param(&alf_param);
|
||||||
|
|
||||||
if (false/*cs.slice->getPendingRasInit()*/ || (state->frame->pictype == KVZ_NAL_IDR_W_RADL || state->frame->pictype == KVZ_NAL_IDR_N_LP))
|
if (false/*cs.slice->getPendingRasInit()*/ || (state->frame->pictype == KVZ_NAL_IDR_W_RADL || state->frame->pictype == KVZ_NAL_IDR_N_LP))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++) {
|
for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++) {
|
||||||
|
@ -28,76 +35,6 @@ void kvz_alf_init(encoder_state_t *const state,
|
||||||
g_aps_id_start = ALF_CTB_MAX_NUM_APS;
|
g_aps_id_start = ALF_CTB_MAX_NUM_APS;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum kvz_chroma_format chroma_fmt = state->encoder_control->chroma_format;
|
|
||||||
const int number_of_components = (chroma_fmt == KVZ_CSP_400) ? 1 : MAX_NUM_COMPONENT;
|
|
||||||
|
|
||||||
// init CTU stats buffers
|
|
||||||
for (int comp_idx = 0; comp_idx < number_of_components; comp_idx++)
|
|
||||||
{
|
|
||||||
bool is_luma = comp_idx == 0 ? 1 : 0;
|
|
||||||
const int num_classes = is_luma ? MAX_NUM_ALF_CLASSES : 1;
|
|
||||||
|
|
||||||
for (int shape = 0; shape != 1 /*m_filterShapes[toChannelType(comp_id)].size()*/; shape++)
|
|
||||||
{
|
|
||||||
for (int class_idx = 0; class_idx < num_classes; class_idx++)
|
|
||||||
{
|
|
||||||
for (int ctu_idx = 0; ctu_idx < g_num_ctus_in_pic; ctu_idx++) {
|
|
||||||
reset_alf_covariance(&g_alf_covariance[comp_idx][shape][ctu_idx][class_idx],
|
|
||||||
g_alf_num_clipping_values[comp_idx == COMPONENT_Y ? CHANNEL_TYPE_LUMA : CHANNEL_TYPE_CHROMA]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// init Frame stats buffers
|
|
||||||
const int number_of_channels = (chroma_fmt == KVZ_CSP_400) ? 1 : MAX_NUM_CHANNEL_TYPE;
|
|
||||||
for (int channel_idx = 0; channel_idx < number_of_channels; channel_idx++)
|
|
||||||
{
|
|
||||||
const channel_type channel_id = channel_idx;
|
|
||||||
bool is_luma = channel_id == CHANNEL_TYPE_LUMA ? true : false;
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
const int num_alts = is_luma ? 1 : MAX_NUM_ALF_ALTERNATIVES_CHROMA;
|
|
||||||
//#endif
|
|
||||||
const int num_classes = is_luma ? MAX_NUM_ALF_CLASSES : 1;
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
for (int alt_idx = 0; alt_idx < num_alts; ++alt_idx)
|
|
||||||
{
|
|
||||||
//#endif
|
|
||||||
for (int shape = 0; shape != 1/*m_filterShapes[channel_idx].size()*/; shape++)
|
|
||||||
{
|
|
||||||
for (int class_idx = 0; class_idx < num_classes; class_idx++)
|
|
||||||
{
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
reset_alf_covariance(&g_alf_covariance_frame[channel_idx][shape][is_luma ? class_idx : alt_idx], g_alf_num_clipping_values[channel_id]);
|
|
||||||
/*#else
|
|
||||||
reset_alf_covariance(&g_alf_covariance_frame[channel_idx][shape][class_idx], g_alf_num_clipping_values[channel_id]);
|
|
||||||
#endif*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// init alf enable flags
|
|
||||||
for (int comp_idx = 0; comp_idx < MAX_NUM_COMPONENT; comp_idx++)
|
|
||||||
{
|
|
||||||
for (int ctu_idx = 0; ctu_idx < g_num_ctus_in_pic; ctu_idx++) {
|
|
||||||
g_ctu_enable_flag[comp_idx][ctu_idx] = 0; //cs.picture->getAlfCtuEnableFlag( compIdx );
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
if (comp_idx != 0) {
|
|
||||||
g_ctu_alternative[comp_idx][ctu_idx] = 0; //cs.picture->getAlfCtuAlternativeData(compIdx);
|
|
||||||
}
|
|
||||||
//#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Slice alf init. Johonkin muualle?
|
|
||||||
|
|
||||||
/*
|
|
||||||
for (int i = 0; i < MAX_NUM_APS; i++)
|
|
||||||
{
|
|
||||||
slice->param_set_map[i].parameter_set = malloc(sizeof(alf_aps));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//slice->param_set_map->p_nalu_data = malloc();
|
|
||||||
|
|
||||||
//Default clp_rng for a slice
|
//Default clp_rng for a slice
|
||||||
g_clp_rngs.comp[COMPONENT_Y].min = g_clp_rngs.comp[COMPONENT_Cb].min = g_clp_rngs.comp[COMPONENT_Cr].min = 0;
|
g_clp_rngs.comp[COMPONENT_Y].min = g_clp_rngs.comp[COMPONENT_Cb].min = g_clp_rngs.comp[COMPONENT_Cr].min = 0;
|
||||||
g_clp_rngs.comp[COMPONENT_Y].max = (1<< ALF_NUM_BITS)-1;
|
g_clp_rngs.comp[COMPONENT_Y].max = (1<< ALF_NUM_BITS)-1;
|
||||||
|
@ -1317,72 +1254,12 @@ void kvz_alf_enc_process(encoder_state_t *const state,
|
||||||
//#endif
|
//#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//kerran muualla
|
|
||||||
//if (false/*cs.slice->getPendingRasInit()*/ || (state->frame->pictype == KVZ_NAL_IDR_W_RADL || state->frame->pictype == KVZ_NAL_IDR_N_LP))
|
|
||||||
/*{
|
|
||||||
//memset(state->slice->apss, 0, sizeof(alf_aps) * ALF_CTB_MAX_NUM_APS);
|
|
||||||
for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++) {
|
|
||||||
state->slice->apss[i].aps_id = 0;
|
|
||||||
state->slice->apss[i].aps_type = 0;
|
|
||||||
reset_alf_param(&state->slice->apss[i]);
|
|
||||||
state->slice->apss[i].num_luma_filters = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
g_aps_id_start = ALF_CTB_MAX_NUM_APS;
|
|
||||||
//state->slice->aps = malloc(sizeof(alf_aps*) * MAX_NUM_APS);
|
|
||||||
|
|
||||||
//FREE_POINTER(state->slice->param_set_map);
|
|
||||||
|
|
||||||
/* Tässä ei pitäisi koskaan tapahtua mitään, koska yläpuolella olisi FREE_POINTER
|
|
||||||
for (int i = 0; i < ALF_CTB_MAX_NUM_APS; i++)
|
|
||||||
{
|
|
||||||
alf_aps* alf_aps = &state->slice->param_set_map[i + T_ALF_APS].parameter_set;
|
|
||||||
state->slice->param_set_map[i + T_ALF_APS].b_changed = false;
|
|
||||||
if (alf_aps)
|
|
||||||
{
|
|
||||||
reset_alf_param(alf_aps);
|
|
||||||
alf_aps = NULL;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//}
|
|
||||||
|
|
||||||
//luotava vain kerran encodereille
|
|
||||||
//alf_aps alf_param;
|
|
||||||
//reset_alf_param(&alf_param);
|
|
||||||
|
|
||||||
//const TempCtx ctxStart(m_CtxCache, AlfCtx(m_CABACEstimator->getCtx()));
|
//const TempCtx ctxStart(m_CtxCache, AlfCtx(m_CABACEstimator->getCtx()));
|
||||||
memcpy(&cabac_estimator, &state->cabac, sizeof(cabac_estimator));
|
memcpy(&cabac_estimator, &state->cabac, sizeof(cabac_estimator));
|
||||||
memcpy(&ctx_start, &state->cabac, sizeof(ctx_start));
|
memcpy(&ctx_start, &state->cabac, sizeof(ctx_start));
|
||||||
cabac_estimator.only_count = 1;
|
cabac_estimator.only_count = 1;
|
||||||
ctx_start.only_count = 1;
|
ctx_start.only_count = 1;
|
||||||
|
|
||||||
//muualla kerran
|
|
||||||
// set CTU ALF enable flags, it was already reset before ALF process
|
|
||||||
/*for (int comp_idx = 0; comp_idx < MAX_NUM_COMPONENT; comp_idx++)
|
|
||||||
{
|
|
||||||
for (int ctu_idx = 0; ctu_idx < g_num_ctus_in_pic; ctu_idx++) {
|
|
||||||
g_ctu_enable_flag[comp_idx][ctu_idx] = 0;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//turha
|
|
||||||
//reset_alf_param(&alf_param);
|
|
||||||
|
|
||||||
//int shift_luma = 2 * 0;// DISTORTION_PRECISION_ADJUSTMENT(m_inputBitDepth[CHANNEL_TYPE_LUMA]);
|
|
||||||
//int shift_chroma = 2 * 0;// DISTORTION_PRECISION_ADJUSTMENT(m_inputBitDepth[CHANNEL_TYPE_CHROMA]);
|
|
||||||
|
|
||||||
/* INITssä
|
|
||||||
g_lambda[COMPONENT_Y] = state->lambda;// 981.62883931057581 // lambdas[COMPONENT_Y] * double(1 << shiftLuma);
|
|
||||||
g_lambda[COMPONENT_Cb] = state->lambda;// 1236.7748378312663 // lambdas[COMPONENT_Cb] * double(1 << shiftChroma);
|
|
||||||
g_lambda[COMPONENT_Cr] = state->lambda;// 1236.7748378312663 //lambdas[COMPONENT_Cr] * double(1 << shiftChroma);*/
|
|
||||||
|
|
||||||
|
|
||||||
//PelUnitBuf orgYuv = cs.getOrgBuf();
|
|
||||||
|
|
||||||
//m_tempBuf.copyFrom(cs.getRecoBuf());
|
|
||||||
//PelUnitBuf recYuv = m_tempBuf.getBuf(cs.area);
|
|
||||||
//recYuv.extendBorderPel(MAX_ALF_FILTER_LENGTH >> 1);
|
|
||||||
|
|
||||||
// derive classification
|
// derive classification
|
||||||
//const kvz_pixel rec_luma = state->tile->frame->rec->y;
|
//const kvz_pixel rec_luma = state->tile->frame->rec->y;
|
||||||
//const PreCalcValues& pcv = *cs.pcv;
|
//const PreCalcValues& pcv = *cs.pcv;
|
||||||
|
@ -1468,35 +1345,7 @@ void kvz_alf_enc_process(encoder_state_t *const state,
|
||||||
}*/
|
}*/
|
||||||
g_alf_ctb_filter_index[lcu->index] = ALF_NUM_FIXED_FILTER_SETS;
|
g_alf_ctb_filter_index[lcu->index] = ALF_NUM_FIXED_FILTER_SETS;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------
|
|
||||||
kvz_alf_derive_filter__encode__reconstruct(state, lcu, 0.0);
|
kvz_alf_derive_filter__encode__reconstruct(state, lcu, 0.0);
|
||||||
kvz_alf_enc_destroy(state); //eri paikkaan
|
|
||||||
/*Done in kvz_alf_derive_filter__encode__reconstruct()
|
|
||||||
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
// consider using new filter (only)
|
|
||||||
alfParam.newFilterFlag[CHANNEL_TYPE_LUMA] = true;
|
|
||||||
alfParam.newFilterFlag[CHANNEL_TYPE_CHROMA] = true;
|
|
||||||
cs.slice->setTileGroupNumAps(1); // Only new filter for RD cost optimization
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// derive filter (luma)
|
|
||||||
kvz_alf_encoder(state, lcu, &alf_param, CHANNEL_TYPE_LUMA); //ulkopuolelle
|
|
||||||
|
|
||||||
// derive filter (chroma)
|
|
||||||
kvz_alf_encoder(state, lcu, &alf_param, CHANNEL_TYPE_CHROMA); //ulkopuolelle
|
|
||||||
|
|
||||||
#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
// let alfEncoderCtb decide now
|
|
||||||
alfParam.newFilterFlag[CHANNEL_TYPE_LUMA] = false;
|
|
||||||
alfParam.newFilterFlag[CHANNEL_TYPE_CHROMA] = false;
|
|
||||||
cs.slice->setTileGroupNumAps(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//m_CABACEstimator->getCtx() = AlfCtx(ctxStart);
|
|
||||||
kvz_alf_encoder_ctb(state, lcu, &alf_param);
|
|
||||||
|
|
||||||
kvz_alf_reconstructor(state, lcu);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvz_alf_derive_filter__encode__reconstruct(encoder_state_t *const state,
|
void kvz_alf_derive_filter__encode__reconstruct(encoder_state_t *const state,
|
||||||
|
@ -1506,17 +1355,6 @@ void kvz_alf_derive_filter__encode__reconstruct(encoder_state_t *const state,
|
||||||
//#endif
|
//#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
memcpy(&tmp_rec_pic, state->tile->frame->rec, sizeof(tmp_rec_pic));
|
|
||||||
|
|
||||||
alf_aps alf_param;
|
|
||||||
reset_alf_param(&alf_param);
|
|
||||||
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
|
||||||
/*Done in alf_enc_process/
|
|
||||||
for (int ctbIdx = 0; ctbIdx < m_numCTUsInPic; ctbIdx++)
|
|
||||||
{
|
|
||||||
cs.slice->getPic()->getAlfCtbFilterIndex()[ctbIdx] = NUM_FIXED_FILTER_SETS;
|
|
||||||
}*/
|
|
||||||
// consider using new filter (only)
|
// consider using new filter (only)
|
||||||
alf_param.new_filter_flag[CHANNEL_TYPE_LUMA] = true;
|
alf_param.new_filter_flag[CHANNEL_TYPE_LUMA] = true;
|
||||||
alf_param.new_filter_flag[CHANNEL_TYPE_CHROMA] = true;
|
alf_param.new_filter_flag[CHANNEL_TYPE_CHROMA] = true;
|
||||||
|
@ -1557,8 +1395,6 @@ void kvz_alf_derive_filter__encode__reconstruct(encoder_state_t *const state,
|
||||||
kvz_encode_alf_new(state, lcu->index);
|
kvz_encode_alf_new(state, lcu->index);
|
||||||
|
|
||||||
kvz_alf_reconstructor(state);
|
kvz_alf_reconstructor(state);
|
||||||
|
|
||||||
memcpy(state->tile->frame->rec, &tmp_rec_pic, sizeof(*state->tile->frame->rec));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double kvz_alf_derive_ctb_alf_enable_flags(encoder_state_t * const state,
|
double kvz_alf_derive_ctb_alf_enable_flags(encoder_state_t * const state,
|
||||||
|
@ -1771,6 +1607,11 @@ double kvz_alf_derive_ctb_alf_enable_flags(encoder_state_t * const state,
|
||||||
void kvz_alf_enc_create(encoder_state_t const *state,
|
void kvz_alf_enc_create(encoder_state_t const *state,
|
||||||
const lcu_order_element_t *lcu)
|
const lcu_order_element_t *lcu)
|
||||||
{
|
{
|
||||||
|
if (g_curr_frame == state->tile->frame->poc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_curr_frame = state->tile->frame->poc;
|
||||||
|
|
||||||
kvz_alf_create(state, lcu);
|
kvz_alf_create(state, lcu);
|
||||||
|
|
||||||
for (int channel_idx = 0; channel_idx < MAX_NUM_CHANNEL_TYPE; channel_idx++)
|
for (int channel_idx = 0; channel_idx < MAX_NUM_CHANNEL_TYPE; channel_idx++)
|
||||||
|
@ -1803,7 +1644,7 @@ void kvz_alf_enc_create(encoder_state_t const *state,
|
||||||
g_ctu_enable_flag[comp_idx] = malloc(g_num_ctus_in_pic * sizeof(*g_ctu_enable_flag[comp_idx]));
|
g_ctu_enable_flag[comp_idx] = malloc(g_num_ctus_in_pic * sizeof(*g_ctu_enable_flag[comp_idx]));
|
||||||
g_ctu_enable_flag_tmp[comp_idx] = malloc(g_num_ctus_in_pic * sizeof(*g_ctu_enable_flag_tmp[comp_idx]));
|
g_ctu_enable_flag_tmp[comp_idx] = malloc(g_num_ctus_in_pic * sizeof(*g_ctu_enable_flag_tmp[comp_idx]));
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
g_ctu_enable_flag_tmp2[comp_idx] = malloc(g_num_ctus_in_pic * sizeof(*g_ctu_enable_flag_tmp2[comp_idx]));
|
// g_ctu_enable_flag_tmp2[comp_idx] = malloc(g_num_ctus_in_pic * sizeof(*g_ctu_enable_flag_tmp2[comp_idx]));
|
||||||
if (comp_idx == COMPONENT_Y)
|
if (comp_idx == COMPONENT_Y)
|
||||||
{
|
{
|
||||||
g_ctu_alternative_tmp[comp_idx] = NULL;
|
g_ctu_alternative_tmp[comp_idx] = NULL;
|
||||||
|
@ -1881,15 +1722,106 @@ void kvz_alf_enc_create(encoder_state_t const *state,
|
||||||
g_alf_ctb_filter_set_index_tmp = malloc(g_num_ctus_in_pic * sizeof(*g_alf_ctb_filter_set_index_tmp));
|
g_alf_ctb_filter_set_index_tmp = malloc(g_num_ctus_in_pic * sizeof(*g_alf_ctb_filter_set_index_tmp));
|
||||||
|
|
||||||
memset(g_clip_default_enc, 0, sizeof(g_clip_default_enc));
|
memset(g_clip_default_enc, 0, sizeof(g_clip_default_enc));
|
||||||
|
|
||||||
|
enum kvz_chroma_format chroma_fmt = state->encoder_control->chroma_format;
|
||||||
|
const int number_of_components = (chroma_fmt == KVZ_CSP_400) ? 1 : MAX_NUM_COMPONENT;
|
||||||
|
|
||||||
|
// init CTU stats buffers
|
||||||
|
for (int comp_idx = 0; comp_idx < number_of_components; comp_idx++)
|
||||||
|
{
|
||||||
|
bool is_luma = comp_idx == 0 ? 1 : 0;
|
||||||
|
const int num_classes = is_luma ? MAX_NUM_ALF_CLASSES : 1;
|
||||||
|
|
||||||
|
for (int shape = 0; shape != 1 /*m_filterShapes[toChannelType(comp_id)].size()*/; shape++)
|
||||||
|
{
|
||||||
|
for (int class_idx = 0; class_idx < num_classes; class_idx++)
|
||||||
|
{
|
||||||
|
for (int ctu_idx = 0; ctu_idx < g_num_ctus_in_pic; ctu_idx++) {
|
||||||
|
reset_alf_covariance(&g_alf_covariance[comp_idx][shape][ctu_idx][class_idx],
|
||||||
|
g_alf_num_clipping_values[comp_idx == COMPONENT_Y ? CHANNEL_TYPE_LUMA : CHANNEL_TYPE_CHROMA]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// init Frame stats buffers
|
||||||
|
const int number_of_channels = (chroma_fmt == KVZ_CSP_400) ? 1 : MAX_NUM_CHANNEL_TYPE;
|
||||||
|
for (int channel_idx = 0; channel_idx < number_of_channels; channel_idx++)
|
||||||
|
{
|
||||||
|
const channel_type channel_id = channel_idx;
|
||||||
|
bool is_luma = channel_id == CHANNEL_TYPE_LUMA ? true : false;
|
||||||
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
const int num_alts = is_luma ? 1 : MAX_NUM_ALF_ALTERNATIVES_CHROMA;
|
||||||
|
//#endif
|
||||||
|
const int num_classes = is_luma ? MAX_NUM_ALF_CLASSES : 1;
|
||||||
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
for (int alt_idx = 0; alt_idx < num_alts; ++alt_idx)
|
||||||
|
{
|
||||||
|
//#endif
|
||||||
|
for (int shape = 0; shape != 1/*m_filterShapes[channel_idx].size()*/; shape++)
|
||||||
|
{
|
||||||
|
for (int class_idx = 0; class_idx < num_classes; class_idx++)
|
||||||
|
{
|
||||||
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
reset_alf_covariance(&g_alf_covariance_frame[channel_idx][shape][is_luma ? class_idx : alt_idx], g_alf_num_clipping_values[channel_id]);
|
||||||
|
/*#else
|
||||||
|
reset_alf_covariance(&g_alf_covariance_frame[channel_idx][shape][class_idx], g_alf_num_clipping_values[channel_id]);
|
||||||
|
#endif*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// init alf enable flags
|
||||||
|
for (int comp_idx = 0; comp_idx < MAX_NUM_COMPONENT; comp_idx++)
|
||||||
|
{
|
||||||
|
for (int ctu_idx = 0; ctu_idx < g_num_ctus_in_pic; ctu_idx++) {
|
||||||
|
g_ctu_enable_flag[comp_idx][ctu_idx] = 0; //cs.picture->getAlfCtuEnableFlag( compIdx );
|
||||||
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
if (comp_idx != 0) {
|
||||||
|
g_ctu_alternative[comp_idx][ctu_idx] = 0; //cs.picture->getAlfCtuAlternativeData(compIdx);
|
||||||
|
}
|
||||||
|
//#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t simd_padding_width = 64;
|
||||||
|
int width = state->tile->frame->width;
|
||||||
|
int height = state->tile->frame->height;
|
||||||
|
tmp_rec_pic = MALLOC(kvz_picture, 1);
|
||||||
|
unsigned int luma_size = (width + 8) * (height + 8);
|
||||||
|
unsigned chroma_sizes[] = { 0, luma_size / 4, luma_size / 2, luma_size };
|
||||||
|
unsigned chroma_size = chroma_sizes[chroma_fmt];
|
||||||
|
tmp_rec_pic->fulldata_buf = MALLOC_SIMD_PADDED(kvz_pixel, (luma_size + 2 * chroma_size), simd_padding_width * 2);
|
||||||
|
|
||||||
|
tmp_rec_pic->fulldata = &tmp_rec_pic->fulldata_buf[4 * (width + 8) + 4] + simd_padding_width / sizeof(kvz_pixel);
|
||||||
|
tmp_rec_pic->base_image = tmp_rec_pic;
|
||||||
|
tmp_rec_pic->refcount = 1; //We give a reference to caller
|
||||||
|
tmp_rec_pic->width = width;
|
||||||
|
tmp_rec_pic->height = height;
|
||||||
|
tmp_rec_pic->stride = width + 8;
|
||||||
|
tmp_rec_pic->chroma_format = chroma_fmt;
|
||||||
|
|
||||||
|
tmp_rec_pic->y = tmp_rec_pic->data[COLOR_Y] = &tmp_rec_pic->fulldata[0];
|
||||||
|
|
||||||
|
if (chroma_fmt == KVZ_CSP_400) {
|
||||||
|
tmp_rec_pic->u = tmp_rec_pic->data[COLOR_U] = NULL;
|
||||||
|
tmp_rec_pic->v = tmp_rec_pic->data[COLOR_V] = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmp_rec_pic->u = tmp_rec_pic->data[COLOR_U] = &tmp_rec_pic->fulldata[luma_size - (4 * (width + 8) + 4) + (2 * (tmp_rec_pic->stride / 2) + 2)];
|
||||||
|
tmp_rec_pic->v = tmp_rec_pic->data[COLOR_V] = &tmp_rec_pic->fulldata[luma_size - (4 * (width + 8) + 4) + chroma_size + (2 * (tmp_rec_pic->stride / 2) + 2)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void kvz_alf_enc_destroy(encoder_state_t const *state)
|
void kvz_alf_enc_destroy(videoframe_t * const frame,
|
||||||
|
const lcu_order_element_t *lcu)
|
||||||
{
|
{
|
||||||
//alf_info_t *alf = state->tile->frame->alf_info;
|
if (!(lcu->index == g_num_ctus_in_pic - 1)) {
|
||||||
int32_t pic_height = state->tile->frame->rec->height;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_created)//!alf->g_created)
|
if (!g_created)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1903,13 +1835,6 @@ void kvz_alf_enc_destroy(encoder_state_t const *state)
|
||||||
int num_coeff = channel_idx ? 7 : 13;
|
int num_coeff = channel_idx ? 7 : 13;
|
||||||
for (int i = 0; i != 1/*m_filterShapes[ch_type].size()*/; i++)
|
for (int i = 0; i != 1/*m_filterShapes[ch_type].size()*/; i++)
|
||||||
{
|
{
|
||||||
/*for (int k = 0; k < num_classes; k++)
|
|
||||||
{
|
|
||||||
|
|
||||||
g_alf_covariance_frame[channel_idx][i][k].pix_acc = 0;
|
|
||||||
memset(g_alf_covariance_frame[channel_idx][i][k].y, 0, sizeof(g_alf_covariance_frame[channel_idx][i][k].y));
|
|
||||||
memset(g_alf_covariance_frame[channel_idx][i][k].ee, 0, sizeof(g_alf_covariance_frame[channel_idx][i][k].ee));
|
|
||||||
}*/
|
|
||||||
FREE_POINTER(g_alf_covariance_frame[channel_idx][i]);
|
FREE_POINTER(g_alf_covariance_frame[channel_idx][i]);
|
||||||
}
|
}
|
||||||
FREE_POINTER(g_alf_covariance_frame[channel_idx]);
|
FREE_POINTER(g_alf_covariance_frame[channel_idx]);
|
||||||
|
@ -1930,10 +1855,10 @@ void kvz_alf_enc_destroy(encoder_state_t const *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
if (g_ctu_enable_flag_tmp2[comp_idx])
|
/*if (g_ctu_enable_flag_tmp2[comp_idx])
|
||||||
{
|
{
|
||||||
FREE_POINTER(g_ctu_enable_flag_tmp2[comp_idx]);
|
FREE_POINTER(g_ctu_enable_flag_tmp2[comp_idx]);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (g_ctu_alternative_tmp[comp_idx])
|
if (g_ctu_alternative_tmp[comp_idx])
|
||||||
{
|
{
|
||||||
|
@ -1954,13 +1879,6 @@ void kvz_alf_enc_destroy(encoder_state_t const *state)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < g_num_ctus_in_pic; j++)
|
for (int j = 0; j < g_num_ctus_in_pic; j++)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
for (int k = 0; k < num_classes; k++)
|
|
||||||
{
|
|
||||||
g_alf_covariance[comp_idx][i][j][k].pix_acc = 0;
|
|
||||||
memset(g_alf_covariance[comp_idx][i][j][k].y, 0, sizeof(g_alf_covariance[comp_idx][i][j][k].y));
|
|
||||||
memset(g_alf_covariance[comp_idx][i][j][k].ee, 0, sizeof(g_alf_covariance[comp_idx][i][j][k].ee));
|
|
||||||
}*/
|
|
||||||
FREE_POINTER(g_alf_covariance[comp_idx][i][j]);
|
FREE_POINTER(g_alf_covariance[comp_idx][i][j]);
|
||||||
}
|
}
|
||||||
FREE_POINTER(g_alf_covariance[comp_idx][i]);
|
FREE_POINTER(g_alf_covariance[comp_idx][i]);
|
||||||
|
@ -1969,21 +1887,6 @@ void kvz_alf_enc_destroy(encoder_state_t const *state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
for (int i = 0; i != 1/*m_filterShapes[COMPONENT_Y].size()*//*; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j <= MAX_NUM_ALF_CLASSES + 1; j++)
|
|
||||||
{
|
|
||||||
//m_alfCovarianceMerged[i][j].destroy();
|
|
||||||
for (int ii = 0; ii < g_alf_covariance_merged[i][j].num_coeff; ii++)
|
|
||||||
{
|
|
||||||
FREE_POINTER(g_alf_covariance_merged[i][j].ee[ii]);
|
|
||||||
}
|
|
||||||
FREE_POINTER(g_alf_covariance_merged[i][j].ee);
|
|
||||||
FREE_POINTER(g_alf_covariance_merged[i][j].y);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (g_filter_coeff_set)
|
if (g_filter_coeff_set)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_NUM_ALF_CLASSES; i++)
|
for (int i = 0; i < MAX_NUM_ALF_CLASSES; i++)
|
||||||
|
@ -2022,16 +1925,28 @@ void kvz_alf_enc_destroy(encoder_state_t const *state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kvz_alf_destroy(state);
|
if (g_alf_ctb_filter_index)
|
||||||
|
{
|
||||||
/*
|
FREE_POINTER(g_alf_ctb_filter_index);
|
||||||
for (int aps_idx = 0; aps_idx < MAX_NUM_APS; aps_idx++) {
|
|
||||||
//FREE_POINTER(state->slice->param_set_map[aps_idx].p_nalu_data);
|
|
||||||
}
|
}
|
||||||
FREE_POINTER(state->slice->param_set_map);
|
|
||||||
FREE_POINTER(state->slice->aps);
|
if (g_alf_ctb_filter_set_index_tmp)
|
||||||
FREE_POINTER(state->slice->tile_group_luma_aps_id);
|
{
|
||||||
*/
|
FREE_POINTER(g_alf_ctb_filter_set_index_tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmp_rec_pic)
|
||||||
|
{
|
||||||
|
memcpy(&frame->rec->y, &tmp_rec_pic->y, sizeof(frame->rec->y));
|
||||||
|
memcpy(&frame->rec->u, &tmp_rec_pic->u, sizeof(frame->rec->u));
|
||||||
|
memcpy(&frame->rec->v, &tmp_rec_pic->v, sizeof(frame->rec->v));
|
||||||
|
memcpy(&frame->rec->data[0], &tmp_rec_pic->data[0], sizeof(frame->rec->data[0]));
|
||||||
|
memcpy(&frame->rec->data[1], &tmp_rec_pic->data[1], sizeof(frame->rec->data[1]));
|
||||||
|
memcpy(&frame->rec->data[2], &tmp_rec_pic->data[2], sizeof(frame->rec->data[2]));
|
||||||
|
tmp_rec_pic = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
kvz_alf_destroy(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4198,8 +4113,8 @@ void kvz_alf_reconstructor(encoder_state_t const *state)
|
||||||
clip = g_clip_default;
|
clip = g_clip_default;
|
||||||
}
|
}
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
state->tile->frame->rec->y, tmp_rec_pic.y,
|
state->tile->frame->rec->y, tmp_rec_pic->y,
|
||||||
state->tile->frame->rec->stride, tmp_rec_pic.stride,
|
state->tile->frame->rec->stride, tmp_rec_pic->stride,
|
||||||
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
||||||
w, h, x_start, y_start, x_start, y_start,
|
w, h, x_start, y_start, x_start, y_start,
|
||||||
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
||||||
|
@ -4219,9 +4134,9 @@ void kvz_alf_reconstructor(encoder_state_t const *state)
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
|
||||||
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
||||||
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic.v : tmp_rec_pic.u;
|
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic->v : tmp_rec_pic->u;
|
||||||
const int src_stride = state->tile->frame->rec->stride >> 1;
|
const int src_stride = state->tile->frame->rec->stride >> 1;
|
||||||
const int dst_stride = tmp_rec_pic.stride >> 1;
|
const int dst_stride = tmp_rec_pic->stride >> 1;
|
||||||
|
|
||||||
const int alt_num = g_ctu_alternative[comp_id][ctu_idx];
|
const int alt_num = g_ctu_alternative[comp_id][ctu_idx];
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
|
@ -4269,8 +4184,8 @@ void kvz_alf_reconstructor(encoder_state_t const *state)
|
||||||
clip = g_clip_default;
|
clip = g_clip_default;
|
||||||
}
|
}
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
state->tile->frame->rec->y, tmp_rec_pic.y,
|
state->tile->frame->rec->y, tmp_rec_pic->y,
|
||||||
state->tile->frame->rec->stride, tmp_rec_pic.stride,
|
state->tile->frame->rec->stride, tmp_rec_pic->stride,
|
||||||
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
||||||
width, height, x_pos, y_pos, x_pos, y_pos,
|
width, height, x_pos, y_pos, x_pos, y_pos,
|
||||||
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
||||||
|
@ -4289,9 +4204,9 @@ void kvz_alf_reconstructor(encoder_state_t const *state)
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
|
||||||
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
||||||
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic.v : tmp_rec_pic.u;
|
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic->v : tmp_rec_pic->u;
|
||||||
const int src_stride = state->tile->frame->rec->stride >> 1;
|
const int src_stride = state->tile->frame->rec->stride >> 1;
|
||||||
const int dst_stride = tmp_rec_pic.stride >> 1;
|
const int dst_stride = tmp_rec_pic->stride >> 1;
|
||||||
|
|
||||||
const int alt_num = g_ctu_alternative[comp_id][ctu_idx];
|
const int alt_num = g_ctu_alternative[comp_id][ctu_idx];
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
|
@ -4564,6 +4479,7 @@ void kvz_encode_alf_new(encoder_state_t * const state,
|
||||||
for (int comp_idx = 0; comp_idx < MAX_NUM_COMPONENT; comp_idx++)
|
for (int comp_idx = 0; comp_idx < MAX_NUM_COMPONENT; comp_idx++)
|
||||||
{
|
{
|
||||||
bool is_luma = comp_idx == COMPONENT_Y ? true : false;
|
bool is_luma = comp_idx == COMPONENT_Y ? true : false;
|
||||||
|
//state->slice->tile_group_alf_enabled_flag[component_id] = 0;
|
||||||
code_alf_ctu_enable_flag(state, &state->cabac, ctu_idx, comp_idx, NULL);
|
code_alf_ctu_enable_flag(state, &state->cabac, ctu_idx, comp_idx, NULL);
|
||||||
if (is_luma)
|
if (is_luma)
|
||||||
{
|
{
|
||||||
|
@ -4697,8 +4613,8 @@ void kvz_alf_process(encoder_state_t const *state,
|
||||||
clip = g_clip_default;
|
clip = g_clip_default;
|
||||||
}
|
}
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
state->tile->frame->rec->y, tmp_rec_pic.y,
|
state->tile->frame->rec->y, tmp_rec_pic->y,
|
||||||
state->tile->frame->rec->stride, tmp_rec_pic.stride,
|
state->tile->frame->rec->stride, tmp_rec_pic->stride,
|
||||||
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
||||||
w, h, x_start, y_start, x_start, y_start,
|
w, h, x_start, y_start, x_start, y_start,
|
||||||
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
||||||
|
@ -4719,9 +4635,9 @@ void kvz_alf_process(encoder_state_t const *state,
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
|
||||||
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
||||||
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic.v : tmp_rec_pic.u;
|
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic->v : tmp_rec_pic->u;
|
||||||
const int src_stride = state->tile->frame->rec->stride >> 1;
|
const int src_stride = state->tile->frame->rec->stride >> 1;
|
||||||
const int dst_stride = tmp_rec_pic.stride >> 1;
|
const int dst_stride = tmp_rec_pic->stride >> 1;
|
||||||
|
|
||||||
uint8_t alt_num = g_ctu_alternative[comp_idx][ctu_idx];
|
uint8_t alt_num = g_ctu_alternative[comp_idx][ctu_idx];
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
|
@ -4776,8 +4692,8 @@ void kvz_alf_process(encoder_state_t const *state,
|
||||||
clip = g_clip_default;
|
clip = g_clip_default;
|
||||||
}
|
}
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
state->tile->frame->rec->y, tmp_rec_pic.y,
|
state->tile->frame->rec->y, tmp_rec_pic->y,
|
||||||
state->tile->frame->rec->stride, tmp_rec_pic.stride,
|
state->tile->frame->rec->stride, tmp_rec_pic->stride,
|
||||||
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
coeff, clip, g_clp_rngs.comp[COMPONENT_Y], COMPONENT_Y,
|
||||||
width, height, x_pos, y_pos, x_pos, y_pos,
|
width, height, x_pos, y_pos, x_pos, y_pos,
|
||||||
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
((y_pos + max_cu_height >= luma_height) ? luma_height : g_alf_vb_luma_pos),
|
||||||
|
@ -4796,9 +4712,9 @@ void kvz_alf_process(encoder_state_t const *state,
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
|
||||||
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
const kvz_pixel *src_pixels = comp_id - 1 ? state->tile->frame->rec->v : state->tile->frame->rec->u;
|
||||||
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic.v : tmp_rec_pic.u;
|
kvz_pixel *dst_pixels = comp_id - 1 ? tmp_rec_pic->v : tmp_rec_pic->u;
|
||||||
const int src_stride = state->tile->frame->rec->stride >> 1;
|
const int src_stride = state->tile->frame->rec->stride >> 1;
|
||||||
const int dst_stride = tmp_rec_pic.stride >> 1;
|
const int dst_stride = tmp_rec_pic->stride >> 1;
|
||||||
|
|
||||||
uint8_t alt_num = g_ctu_alternative[comp_idx][ctu_idx];
|
uint8_t alt_num = g_ctu_alternative[comp_idx][ctu_idx];
|
||||||
kvz_alf_filter_block(state,
|
kvz_alf_filter_block(state,
|
||||||
|
@ -5065,20 +4981,18 @@ void kvz_alf_reconstruct_coeff(encoder_state_t *const state,
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvz_alf_create(encoder_state_t const *state,
|
void kvz_alf_create(encoder_state_t const *state,
|
||||||
const lcu_order_element_t const *lcu) //,
|
const lcu_order_element_t const *lcu)
|
||||||
//const int format)
|
|
||||||
{
|
{
|
||||||
//memcpy(m_inputBitDepth, inputBitDepth, sizeof(m_inputBitDepth));
|
if (g_created)
|
||||||
|
{
|
||||||
//int ***g_laplacian = state->tile->frame->alf_info->g_laplacian;
|
return;
|
||||||
//alf_classifier ***g_classifier = &state->tile->frame->alf_info->g_classifier;
|
}
|
||||||
//bool *g_created = &state->tile->frame->alf_info->g_created;
|
|
||||||
enum kvz_chroma_format chroma_fmt = state->encoder_control->chroma_format;
|
|
||||||
|
|
||||||
const int pic_width = state->tile->frame->width;
|
const int pic_width = state->tile->frame->width;
|
||||||
const int pic_height = state->tile->frame->height;
|
const int pic_height = state->tile->frame->height;
|
||||||
const int max_cu_width = LCU_WIDTH; //128
|
const int max_cu_width = LCU_WIDTH; //128
|
||||||
const int max_cu_height = LCU_WIDTH; //128
|
const int max_cu_height = LCU_WIDTH; //128
|
||||||
|
enum kvz_chroma_format chroma_fmt = state->encoder_control->chroma_format;
|
||||||
|
|
||||||
const int num_ctus_in_width = (pic_width / max_cu_width) + ((pic_width % max_cu_width) ? 1 : 0);
|
const int num_ctus_in_width = (pic_width / max_cu_width) + ((pic_width % max_cu_width) ? 1 : 0);
|
||||||
const int num_ctus_in_height = (pic_height / max_cu_height) + ((pic_height % max_cu_height) ? 1 : 0);
|
const int num_ctus_in_height = (pic_height / max_cu_height) + ((pic_height % max_cu_height) ? 1 : 0);
|
||||||
|
@ -5107,39 +5021,13 @@ void kvz_alf_create(encoder_state_t const *state,
|
||||||
(g_alf_num_clipping_values[CHANNEL_TYPE_CHROMA] - i - 1) / (g_alf_num_clipping_values[CHANNEL_TYPE_CHROMA] - 1)));
|
(g_alf_num_clipping_values[CHANNEL_TYPE_CHROMA] - i - 1) / (g_alf_num_clipping_values[CHANNEL_TYPE_CHROMA] - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_created)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//m_tempBuf.destroy();
|
|
||||||
//m_tempBuf.create(format, Area(0, 0, pic_width, pic_height), max_cu_width, MAX_ALF_FILTER_LENGTH >> 1, 0, false);
|
|
||||||
//m_tempBuf2.destroy();
|
|
||||||
//m_tempBuf2.create(format, Area(0, 0, maxCUWidth + (MAX_ALF_PADDING_SIZE << 1), maxCUHeight + (MAX_ALF_PADDING_SIZE << 1)), maxCUWidth, MAX_ALF_PADDING_SIZE, 0, false);
|
|
||||||
|
|
||||||
/*// Laplacian based activity
|
|
||||||
for (int i = 0; i < NUM_DIRECTIONS; i++)
|
|
||||||
{
|
|
||||||
//if (g_laplacian[i] == NULL)
|
|
||||||
//{
|
|
||||||
g_laplacian[i] = malloc((CLASSIFICATION_BLK_SIZE + 5) * sizeof(int*));
|
|
||||||
for (int y = 0; y < CLASSIFICATION_BLK_SIZE + 5; y++)
|
|
||||||
{
|
|
||||||
g_laplacian[i][y] = malloc((CLASSIFICATION_BLK_SIZE + 5) * sizeof(int));
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Classification
|
// Classification
|
||||||
//if (*g_classifier == NULL)
|
|
||||||
//{
|
|
||||||
g_classifier = malloc(pic_height * sizeof(**g_classifier));
|
g_classifier = malloc(pic_height * sizeof(**g_classifier));
|
||||||
g_classifier[0] = malloc(pic_height * pic_width * sizeof(*g_classifier));
|
g_classifier[0] = malloc(pic_height * pic_width * sizeof(*g_classifier));
|
||||||
for (int i = 1; i < pic_height; i++)
|
for (int i = 1; i < pic_height; i++)
|
||||||
{
|
{
|
||||||
g_classifier[i] = g_classifier[0] + i * pic_width;
|
g_classifier[i] = g_classifier[0] + i * pic_width;
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
for (int filter_set_index = 0; filter_set_index < ALF_NUM_FIXED_FILTER_SETS; filter_set_index++)
|
for (int filter_set_index = 0; filter_set_index < ALF_NUM_FIXED_FILTER_SETS; filter_set_index++)
|
||||||
{
|
{
|
||||||
|
@ -5162,44 +5050,19 @@ void kvz_alf_create(encoder_state_t const *state,
|
||||||
g_created = true;
|
g_created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvz_alf_destroy(encoder_state_t const *state)
|
void kvz_alf_destroy(videoframe_t * const frame)
|
||||||
{
|
{
|
||||||
//alf_info_t *alf = state->tile->frame->alf_info;
|
if (!g_created)
|
||||||
//int ***g_laplacian = state->tile->frame->alf_info->g_laplacian;
|
|
||||||
//alf_classifier **g_classifier = state->tile->frame->alf_info->g_classifier;
|
|
||||||
int32_t pic_height = state->tile->frame->rec->height;
|
|
||||||
|
|
||||||
if (g_created)//!alf->g_created)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*for (int i = 0; i < NUM_DIRECTIONS; i++)
|
|
||||||
{
|
|
||||||
if (g_laplacian[i])
|
|
||||||
{
|
|
||||||
for (int y = 0; y < CLASSIFICATION_BLK_SIZE + 5; y++)
|
|
||||||
{
|
|
||||||
if (g_laplacian[i][y] != NULL) {
|
|
||||||
FREE_POINTER(g_laplacian[i][y]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FREE_POINTER(g_laplacian[i]);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (g_classifier)
|
if (g_classifier)
|
||||||
{
|
{
|
||||||
FREE_POINTER(g_classifier[0]);
|
FREE_POINTER(g_classifier[0]);
|
||||||
FREE_POINTER(g_classifier);
|
FREE_POINTER(g_classifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
m_tempBuf.destroy();
|
|
||||||
m_tempBuf2.destroy();
|
|
||||||
*/
|
|
||||||
|
|
||||||
//alf->g_created = false;
|
|
||||||
g_created = false;
|
g_created = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
59
src/alf.h
59
src/alf.h
|
@ -237,18 +237,21 @@ typedef struct alf_classifier {
|
||||||
int transpose_idx;
|
int transpose_idx;
|
||||||
} alf_classifier;
|
} alf_classifier;
|
||||||
|
|
||||||
/*typedef struct alf_info_t {
|
typedef struct alf_info_t {
|
||||||
//alf_type blk_type;
|
alf_covariance*** g_alf_covariance[MAX_NUM_COMPONENT]; //[component_id][filter_type][ctu_idx][class_idx]
|
||||||
//alf_filter_type filter_type;
|
alf_covariance** g_alf_covariance_frame[MAX_NUM_CHANNEL_TYPE]; //[channel][filter_type][class_idx]
|
||||||
//alf_component_id component_id;
|
alf_covariance g_alf_covariance_merged[ALF_NUM_OF_FILTER_TYPES][MAX_NUM_ALF_CLASSES + 2];
|
||||||
//alf_directions direction;
|
int g_alf_clip_merged[ALF_NUM_OF_FILTER_TYPES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_LUMA_COEFF];
|
||||||
//const kvz_pixel *src_buf;
|
uint8_t* g_ctu_enable_flag[MAX_NUM_COMPONENT];
|
||||||
//const kvz_pixel *dst_buf;
|
uint8_t* g_ctu_alternative[MAX_NUM_COMPONENT]; //#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
//alf_classifier **g_classifier;
|
double *g_ctb_distortion_unfilter[MAX_NUM_COMPONENT];
|
||||||
//int **g_laplacian[NUM_DIRECTIONS];
|
int g_aps_id_start;
|
||||||
//bool g_created;
|
int** g_diff_filter_coeff; // [lumaClassIdx][coeffIdx]
|
||||||
//clp_rngs clp_rngs;
|
int** g_filter_coeff_set; // [lumaClassIdx][coeffIdx]
|
||||||
} alf_info_t;*/
|
int** g_filter_clipp_set; // [lumaClassIdx][coeffIdx]
|
||||||
|
short* g_alf_ctb_filter_set_index_tmp; //g_num_ctus_in_pic //voisi olla lokaali muuttuja?
|
||||||
|
short* g_alf_ctb_filter_index; //g_num_ctus_in_pic
|
||||||
|
} alf_info_t;
|
||||||
|
|
||||||
typedef struct alf_aps {
|
typedef struct alf_aps {
|
||||||
int aps_id;
|
int aps_id;
|
||||||
|
@ -315,11 +318,6 @@ static int g_clip_default_enc[MAX_NUM_ALF_LUMA_COEFF];
|
||||||
//static int **g_laplacian[NUM_DIRECTIONS]; // korvattu alemmalla versiolla
|
//static int **g_laplacian[NUM_DIRECTIONS]; // korvattu alemmalla versiolla
|
||||||
static int g_laplacian[NUM_DIRECTIONS][CLASSIFICATION_BLK_SIZE + 5][CLASSIFICATION_BLK_SIZE + 5]; //puhdista vasta koko encodauksen lopuksi
|
static int g_laplacian[NUM_DIRECTIONS][CLASSIFICATION_BLK_SIZE + 5][CLASSIFICATION_BLK_SIZE + 5]; //puhdista vasta koko encodauksen lopuksi
|
||||||
static double g_lambda[MAX_NUM_COMPONENT];
|
static double g_lambda[MAX_NUM_COMPONENT];
|
||||||
int g_alf_vb_luma_ctu_height;
|
|
||||||
int g_alf_vb_chma_ctu_height;
|
|
||||||
int g_alf_vb_luma_pos;
|
|
||||||
int g_alf_vb_chma_pos;
|
|
||||||
short g_alf_clipping_values[MAX_NUM_CHANNEL_TYPE][MAX_ALF_NUM_CLIPPING_VALUES];
|
|
||||||
short g_clip_default[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF];
|
short g_clip_default[MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF];
|
||||||
static short g_filter_indices[MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_CLASSES];
|
static short g_filter_indices[MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_CLASSES];
|
||||||
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
//#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
|
@ -338,16 +336,24 @@ static short g_coeff_aps_luma[ALF_CTB_MAX_NUM_APS][MAX_NUM_ALF_CLASSES * MAX_NUM
|
||||||
static short g_clipp_aps_luma[ALF_CTB_MAX_NUM_APS][MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF];
|
static short g_clipp_aps_luma[ALF_CTB_MAX_NUM_APS][MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF];
|
||||||
static short g_fixed_filter_set_coeff_dec[ALF_NUM_FIXED_FILTER_SETS][MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF];
|
static short g_fixed_filter_set_coeff_dec[ALF_NUM_FIXED_FILTER_SETS][MAX_NUM_ALF_CLASSES * MAX_NUM_ALF_LUMA_COEFF];
|
||||||
|
|
||||||
//once per frame
|
//once ever
|
||||||
|
static int g_num_ctus_in_pic;
|
||||||
|
static int g_alf_vb_luma_ctu_height;
|
||||||
|
static int g_alf_vb_chma_ctu_height;
|
||||||
|
static int g_alf_vb_luma_pos;
|
||||||
|
static int g_alf_vb_chma_pos;
|
||||||
|
static short g_alf_clipping_values[MAX_NUM_CHANNEL_TYPE][MAX_ALF_NUM_CLIPPING_VALUES];
|
||||||
static alf_classifier **g_classifier;
|
static alf_classifier **g_classifier;
|
||||||
static bool g_created = false;
|
static bool g_created = false;
|
||||||
|
static uint32_t g_slice_count = MAX_INT;
|
||||||
|
|
||||||
|
//once per frame
|
||||||
alf_covariance*** g_alf_covariance[MAX_NUM_COMPONENT]; //[component_id][filter_type][ctu_idx][class_idx]
|
alf_covariance*** g_alf_covariance[MAX_NUM_COMPONENT]; //[component_id][filter_type][ctu_idx][class_idx]
|
||||||
alf_covariance** g_alf_covariance_frame[MAX_NUM_CHANNEL_TYPE]; //[channel][filter_type][class_idx]
|
alf_covariance** g_alf_covariance_frame[MAX_NUM_CHANNEL_TYPE]; //[channel][filter_type][class_idx]
|
||||||
alf_covariance g_alf_covariance_merged[ALF_NUM_OF_FILTER_TYPES][MAX_NUM_ALF_CLASSES + 2];
|
alf_covariance g_alf_covariance_merged[ALF_NUM_OF_FILTER_TYPES][MAX_NUM_ALF_CLASSES + 2];
|
||||||
int g_alf_clip_merged[ALF_NUM_OF_FILTER_TYPES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_LUMA_COEFF];
|
int g_alf_clip_merged[ALF_NUM_OF_FILTER_TYPES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_CLASSES][MAX_NUM_ALF_LUMA_COEFF];
|
||||||
uint8_t* g_ctu_enable_flag[MAX_NUM_COMPONENT];
|
uint8_t* g_ctu_enable_flag[MAX_NUM_COMPONENT];
|
||||||
uint8_t* g_ctu_alternative[MAX_NUM_COMPONENT]; //#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
uint8_t* g_ctu_alternative[MAX_NUM_COMPONENT]; //#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
|
||||||
static int g_num_ctus_in_pic;
|
|
||||||
double *g_ctb_distortion_unfilter[MAX_NUM_COMPONENT];
|
double *g_ctb_distortion_unfilter[MAX_NUM_COMPONENT];
|
||||||
static int g_aps_id_start;
|
static int g_aps_id_start;
|
||||||
int** g_diff_filter_coeff; // [lumaClassIdx][coeffIdx]
|
int** g_diff_filter_coeff; // [lumaClassIdx][coeffIdx]
|
||||||
|
@ -355,16 +361,18 @@ int** g_filter_coeff_set; // [lumaClassIdx][coeffIdx]
|
||||||
int** g_filter_clipp_set; // [lumaClassIdx][coeffIdx]
|
int** g_filter_clipp_set; // [lumaClassIdx][coeffIdx]
|
||||||
short* g_alf_ctb_filter_set_index_tmp; //g_num_ctus_in_pic //voisi olla lokaali muuttuja?
|
short* g_alf_ctb_filter_set_index_tmp; //g_num_ctus_in_pic //voisi olla lokaali muuttuja?
|
||||||
short* g_alf_ctb_filter_index; //g_num_ctus_in_pic
|
short* g_alf_ctb_filter_index; //g_num_ctus_in_pic
|
||||||
|
static uint32_t g_curr_frame = MAX_INT;
|
||||||
|
alf_aps alf_param;
|
||||||
|
|
||||||
//temps
|
//temps
|
||||||
static alf_aps g_alf_aps_temp;
|
static alf_aps g_alf_aps_temp;
|
||||||
static alf_aps g_alf_aps_temp_nl;
|
static alf_aps g_alf_aps_temp_nl;
|
||||||
uint8_t* g_ctu_enable_flag_tmp[MAX_NUM_COMPONENT];
|
uint8_t* g_ctu_enable_flag_tmp[MAX_NUM_COMPONENT]; //kerran
|
||||||
uint8_t* g_ctu_enable_flag_tmp2[MAX_NUM_COMPONENT];
|
//uint8_t* g_ctu_enable_flag_tmp2[MAX_NUM_COMPONENT];
|
||||||
uint8_t* g_ctu_alternative_tmp[MAX_NUM_COMPONENT];
|
uint8_t* g_ctu_alternative_tmp[MAX_NUM_COMPONENT]; //kerran
|
||||||
static int g_filter_tmp[MAX_NUM_ALF_LUMA_COEFF];
|
static int g_filter_tmp[MAX_NUM_ALF_LUMA_COEFF];
|
||||||
static int g_clip_tmp[MAX_NUM_ALF_LUMA_COEFF];
|
static int g_clip_tmp[MAX_NUM_ALF_LUMA_COEFF];
|
||||||
static kvz_picture tmp_rec_pic;
|
kvz_picture *tmp_rec_pic;
|
||||||
|
|
||||||
//cabac temps
|
//cabac temps
|
||||||
cabac_data_t ctx_start;
|
cabac_data_t ctx_start;
|
||||||
|
@ -460,7 +468,8 @@ double kvz_alf_derive_ctb_alf_enable_flags(encoder_state_t * const state,
|
||||||
void kvz_alf_enc_create(encoder_state_t const *state,
|
void kvz_alf_enc_create(encoder_state_t const *state,
|
||||||
const lcu_order_element_t *lcu);
|
const lcu_order_element_t *lcu);
|
||||||
|
|
||||||
void kvz_alf_enc_destroy(encoder_state_t const *state);
|
void kvz_alf_enc_destroy(videoframe_t * const frame,
|
||||||
|
const lcu_order_element_t *lcu);
|
||||||
|
|
||||||
void kvz_alf_encoder(encoder_state_t *const state,
|
void kvz_alf_encoder(encoder_state_t *const state,
|
||||||
alf_aps *aps,
|
alf_aps *aps,
|
||||||
|
@ -638,7 +647,7 @@ void kvz_alf_reconstruct_coeff(encoder_state_t *const state,
|
||||||
void kvz_alf_create(encoder_state_t const *state,
|
void kvz_alf_create(encoder_state_t const *state,
|
||||||
const lcu_order_element_t *lcu);
|
const lcu_order_element_t *lcu);
|
||||||
|
|
||||||
void kvz_alf_destroy(encoder_state_t const *state);
|
void kvz_alf_destroy(videoframe_t * const frame);
|
||||||
|
|
||||||
void kvz_alf_derive_classification(encoder_state_t *const state,
|
void kvz_alf_derive_classification(encoder_state_t *const state,
|
||||||
const lcu_order_element_t *const lcu,
|
const lcu_order_element_t *const lcu,
|
||||||
|
|
|
@ -179,7 +179,8 @@ extern bool kvz_cabac_bins_verbose;
|
||||||
uint32_t prev_state = CTX_STATE(data->cur_ctx); \
|
uint32_t prev_state = CTX_STATE(data->cur_ctx); \
|
||||||
kvz_cabac_encode_bins_ep((data), (value), (bins)); \
|
kvz_cabac_encode_bins_ep((data), (value), (bins)); \
|
||||||
if(kvz_cabac_bins_verbose && !data->only_count) { printf("%d %s = %u(%u bins), state = %u -> %u\n", \
|
if(kvz_cabac_bins_verbose && !data->only_count) { printf("%d %s = %u(%u bins), state = %u -> %u\n", \
|
||||||
kvz_cabac_bins_count, (name), (uint32_t)(value), (bins), prev_state, CTX_STATE(data->cur_ctx)); kvz_cabac_bins_count+=bins;}}
|
kvz_cabac_bins_count, (name), (uint32_t)(value), (bins), prev_state, CTX_STATE(data->cur_ctx)); \
|
||||||
|
if (data->only_count == 0) kvz_cabac_bins_count+=bins;}
|
||||||
|
|
||||||
#define CABAC_BIN_EP(data, value, name) { \
|
#define CABAC_BIN_EP(data, value, name) { \
|
||||||
uint32_t prev_state = CTX_STATE(data->cur_ctx); \
|
uint32_t prev_state = CTX_STATE(data->cur_ctx); \
|
||||||
|
|
|
@ -677,34 +677,9 @@ static void encoder_state_worker_encode_lcu(void * opaque)
|
||||||
kvz_alf_enc_create(state, lcu);
|
kvz_alf_enc_create(state, lcu);
|
||||||
kvz_alf_init(state, slice);
|
kvz_alf_init(state, slice);
|
||||||
kvz_alf_enc_process(state, lcu);
|
kvz_alf_enc_process(state, lcu);
|
||||||
//kvz_alf_enc_destroy(state); //pitää muokata ja valita paikka
|
kvz_alf_enc_destroy(frame, lcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Alkuperäinen ALF
|
|
||||||
if (encoder->cfg.alf_enable) {
|
|
||||||
short* filter_set;
|
|
||||||
alf_info_t* alf = state->tile->frame->alf_info;
|
|
||||||
|
|
||||||
/*encoder_state_recdata_before_alf_to_bufs(state,
|
|
||||||
lcu,
|
|
||||||
state->tile->hor_buf_before_alf,
|
|
||||||
state->tile->ver_buf_before_alf);
|
|
||||||
*//*
|
|
||||||
//ALF alustus tähän
|
|
||||||
kvz_alf_init(alf);
|
|
||||||
kvz_alf_derive_classification(state, lcu);
|
|
||||||
clp_rng* clp_rng = state->tile->frame->alf_info->clp_rngs.comp[0];
|
|
||||||
kvz_alf_reconstruct_coeff_aps(state, false, true, false);
|
|
||||||
kvz_alf_filter_block(state, lcu, g_chroma_coeff_final, clp_rng);
|
|
||||||
|
|
||||||
|
|
||||||
cabac_data_t * const cabac = &state->cabac;
|
|
||||||
for (int component = 0; component < 1; component++) {
|
|
||||||
cabac->cur_ctx = &(cabac->ctx.alf_ctb_flag_model[component * 3 + ctx]);
|
|
||||||
CABAC_BIN(cabac, 0, "alf_ctb_flag");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//Encode coding tree
|
//Encode coding tree
|
||||||
kvz_encode_coding_tree(state, lcu->position.x * LCU_WIDTH, lcu->position.y * LCU_WIDTH, 0);
|
kvz_encode_coding_tree(state, lcu->position.x * LCU_WIDTH, lcu->position.y * LCU_WIDTH, 0);
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,7 @@ typedef struct encoder_state_config_slice_t {
|
||||||
int tile_group_num_aps;
|
int tile_group_num_aps;
|
||||||
int *tile_group_luma_aps_id;
|
int *tile_group_luma_aps_id;
|
||||||
int tile_group_chroma_aps_id;
|
int tile_group_chroma_aps_id;
|
||||||
struct param_set_map *param_set_map;
|
struct param_set_map *param_set_map; //mahdollisesti define during run
|
||||||
uint32_t num_of_param_sets;
|
uint32_t num_of_param_sets;
|
||||||
bool tile_group_alf_enabled_flag[3/*MAX_NUM_COMPONENT*/];
|
bool tile_group_alf_enabled_flag[3/*MAX_NUM_COMPONENT*/];
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ videoframe_t * kvz_videoframe_alloc(int32_t width,
|
||||||
frame->sao_chroma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu);
|
frame->sao_chroma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
//frame->alf_info = MALLOC(alf_info_t, frame->width_in_lcu * frame->height_in_lcu);
|
//frame->alf_info = MALLOC(alf_info_t, 1);
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,9 @@ int kvz_videoframe_free(videoframe_t * const frame)
|
||||||
|
|
||||||
FREE_POINTER(frame->sao_luma);
|
FREE_POINTER(frame->sao_luma);
|
||||||
FREE_POINTER(frame->sao_chroma);
|
FREE_POINTER(frame->sao_chroma);
|
||||||
FREE_POINTER(frame->alf_info);
|
|
||||||
|
//kvz_alf_enc_destroy(frame);
|
||||||
|
//FREE_POINTER(frame->alf_info);
|
||||||
|
|
||||||
free(frame);
|
free(frame);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue