From dbc7fd48bf59db65dbde34253fd0cb3e32a6ed7d Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Mon, 24 May 2021 18:57:37 +0300 Subject: [PATCH] [LMCS] Initialize some m_reshapeCW values to avoid division by zero --- src/encoderstate.c | 7 ++++++- src/reshape.c | 6 +++--- src/search.c | 2 +- src/strategies/avx2/quant-avx2.c | 14 ++------------ src/strategies/generic/quant-generic.c | 15 +++------------ 5 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/encoderstate.c b/src/encoderstate.c index d70a0294..f7dde6e3 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -1639,6 +1639,11 @@ static void encoder_state_init_new_frame(encoder_state_t * const state, kvz_pict state->tile->frame->lmcs_aps = calloc(1, sizeof(lmcs_aps)); kvz_init_lmcs_aps(state->tile->frame->lmcs_aps, state->encoder_control->cfg.width, state->encoder_control->cfg.height, LCU_CU_WIDTH, LCU_CU_WIDTH, state->encoder_control->bitdepth); + + state->tile->frame->lmcs_aps->m_reshapeCW.rspPicSize = state->tile->frame->width * state->tile->frame->height; + state->tile->frame->lmcs_aps->m_reshapeCW.rspBaseQP = state->encoder_control->cfg.qp; + state->tile->frame->lmcs_aps->m_reshapeCW.rspFpsToIp = 16; + // ToDo: support other signal types in LMCS kvz_lmcs_preanalyzer(state, state->tile->frame, state->tile->frame->lmcs_aps, RESHAPE_SIGNAL_SDR); kvz_construct_reshaper_lmcs(state->tile->frame->lmcs_aps); @@ -1647,7 +1652,7 @@ static void encoder_state_init_new_frame(encoder_state_t * const state, kvz_pict kvz_pixel* luma_lmcs = state->tile->frame->source_lmcs->y; for (int y = 0; y < state->tile->frame->source->height; y++) { for (int x = 0; x < state->tile->frame->source->width; x++) { - //luma[x] = state->tile->frame->lmcs_aps->m_fwdLUT[luma[x]]; + luma_lmcs[x] = state->tile->frame->lmcs_aps->m_fwdLUT[luma[x]]; } luma += state->tile->frame->source->stride; luma_lmcs += state->tile->frame->source->stride; diff --git a/src/reshape.c b/src/reshape.c index 6efb98c5..a1f018c1 100644 --- a/src/reshape.c +++ b/src/reshape.c @@ -110,7 +110,7 @@ void kvz_calc_seq_stats(struct encoder_state_t* const state, const videoframe_t* const encoder_control_t* const encoder = state->encoder_control; int32_t m_binNum = PIC_CODE_CW_BINS; - kvz_pixel* picY = &frame->source->y[CU_TO_PIXEL(0, 0, 0, frame->source->stride)]; + kvz_pixel* picY = &frame->source->y[0]; const int width = frame->source->width; const int height = frame->source->height; const int stride = frame->source->stride; @@ -134,7 +134,7 @@ void kvz_calc_seq_stats(struct encoder_state_t* const state, const videoframe_t* memset(topColSum, 0, width * sizeof(int64_t)); memset(topColSumSq, 0, width * sizeof(int64_t)); memset(binCnt, 0, m_binNum * sizeof(uint32_t)); - + kvz_init_lmcs_seq_stats(stats,m_binNum); for (uint32_t y = 0; y < height; y++) { @@ -831,7 +831,7 @@ void kvz_lmcs_preanalyzer(struct encoder_state_t* const state, const videoframe_ aps->m_sliceReshapeInfo.sliceReshaperModelPresentFlag = true; aps->m_sliceReshapeInfo.sliceReshaperEnableFlag = true; - int modIP = 0;// state->frame->poc - state->frame->poc / aps->m_reshapeCW.rspFpsToIp * aps->m_reshapeCW.rspFpsToIp; + int modIP = state->frame->poc - state->frame->poc / aps->m_reshapeCW.rspFpsToIp * aps->m_reshapeCW.rspFpsToIp; if (sliceType == KVZ_SLICE_I || (aps->m_reshapeCW.updateCtrl == 2 && modIP == 0)) { if (aps->m_sliceReshapeInfo.sliceReshaperModelPresentFlag == true) diff --git a/src/search.c b/src/search.c index 52b891eb..7910f02e 100644 --- a/src/search.c +++ b/src/search.c @@ -943,7 +943,7 @@ static void init_lcu_t(const encoder_state_t * const state, const int x, const i int x_max_c = x_max / 2; int y_max_c = y_max / 2; - kvz_pixels_blit(&frame->source->y[x + y * frame->source->stride], lcu->ref.y, + kvz_pixels_blit(&frame->source_lmcs->y[x + y * frame->source->stride], lcu->ref.y, x_max, y_max, frame->source->stride, LCU_WIDTH); if (state->encoder_control->chroma_format != KVZ_CSP_400) { kvz_pixels_blit(&frame->source->u[x_c + y_c * frame->source->stride / 2], lcu->ref.u, diff --git a/src/strategies/avx2/quant-avx2.c b/src/strategies/avx2/quant-avx2.c index c71fa0dc..c9ed94c3 100644 --- a/src/strategies/avx2/quant-avx2.c +++ b/src/strategies/avx2/quant-avx2.c @@ -665,18 +665,8 @@ int kvz_quantize_residual_avx2(encoder_state_t *const state, assert(width <= TR_MAX_WIDTH); assert(width >= TR_MIN_WIDTH); - int y, x; - // ToDo: do something with the LMCS for better performance - if (state->encoder_control->cfg.lmcs_enable && color == COLOR_Y) { - for (y = 0; y < width; ++y) { - for (x = 0; x < width; ++x) { - residual[x + y * width] = (int16_t)(state->tile->frame->lmcs_aps->m_fwdLUT[ref_in[x + y * in_stride]] - pred_in[x + y * in_stride]); - } - } - } else { - // Get residual. (ref_in - pred_in -> residual) - get_residual_avx2(ref_in, pred_in, residual, width, in_stride); - } + // Get residual. (ref_in - pred_in -> residual) + get_residual_avx2(ref_in, pred_in, residual, width, in_stride); // Transform residual. (residual -> coeff) if (use_trskip) { diff --git a/src/strategies/generic/quant-generic.c b/src/strategies/generic/quant-generic.c index 62609b34..2e60824c 100644 --- a/src/strategies/generic/quant-generic.c +++ b/src/strategies/generic/quant-generic.c @@ -207,18 +207,9 @@ int kvz_quantize_residual_generic(encoder_state_t *const state, // Get residual. (ref_in - pred_in -> residual) { int y, x; - if (state->encoder_control->cfg.lmcs_enable && color == COLOR_Y) { - for (y = 0; y < width; ++y) { - for (x = 0; x < width; ++x) { - residual[x + y * width] = (int16_t)(state->tile->frame->lmcs_aps->m_fwdLUT[ref_in[x + y * in_stride]] - pred_in[x + y * in_stride]); - } - } - } - else { - for (y = 0; y < width; ++y) { - for (x = 0; x < width; ++x) { - residual[x + y * width] = (int16_t)(ref_in[x + y * in_stride] - pred_in[x + y * in_stride]); - } + for (y = 0; y < width; ++y) { + for (x = 0; x < width; ++x) { + residual[x + y * width] = (int16_t)(ref_in[x + y * in_stride] - pred_in[x + y * in_stride]); } } }