From 3dae3f072ebb6c9f5ece2d425bb82c466672f7d9 Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Tue, 25 May 2021 14:27:21 +0300 Subject: [PATCH] [LMCS] Actually allocate the source_lmcs and rec_lmcs --- src/encoderstate.c | 7 ++++++- src/search.c | 1 + src/videoframe.c | 5 +---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/encoderstate.c b/src/encoderstate.c index 0c0e1056..b1aff5f9 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -1371,6 +1371,10 @@ static void encoder_set_source_picture(encoder_state_t * const state, kvz_pictur } state->tile->frame->rec_lmcs = state->tile->frame->rec; + if (state->encoder_control->cfg.lmcs_enable) { + state->tile->frame->rec_lmcs = kvz_image_alloc(state->encoder_control->chroma_format, frame->width, frame->height); + state->tile->frame->source_lmcs = kvz_image_alloc(state->encoder_control->chroma_format, frame->width, frame->height); + } kvz_videoframe_set_poc(state->tile->frame, state->frame->poc); } @@ -1644,7 +1648,8 @@ static void encoder_state_init_new_frame(encoder_state_t * const state, kvz_pict 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; - + state->tile->frame->lmcs_aps->m_reshapeCW.updateCtrl = 1; //ToDo: change "LMCS model update control: 0:RA, 1:AI, 2:LDB/LDP" + // 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); diff --git a/src/search.c b/src/search.c index 7910f02e..f07a4fc0 100644 --- a/src/search.c +++ b/src/search.c @@ -943,6 +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; + // Use LMCS pixels for luma if they are available, otherwise source_lmcs is mapped to normal source 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) { diff --git a/src/videoframe.c b/src/videoframe.c index 652d96fd..b4b1ed47 100644 --- a/src/videoframe.c +++ b/src/videoframe.c @@ -64,13 +64,10 @@ videoframe_t * kvz_videoframe_alloc(int32_t width, */ int kvz_videoframe_free(videoframe_t * const frame) { - if (frame->lmcs_top_level) { + if (frame->source_lmcs_mapped) { kvz_image_free(frame->source_lmcs); kvz_image_free(frame->rec_lmcs); frame->source_lmcs_mapped = false; - } else if(frame->source_lmcs_mapped){ - FREE_POINTER(frame->source_lmcs); - FREE_POINTER(frame->rec_lmcs); } kvz_image_free(frame->source);