From 351697223743d26b06cac13dfdfa55ce4767d4f8 Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Tue, 18 May 2021 21:22:22 +0300 Subject: [PATCH] [LMCS] Move LMCS mapping / inverse to the source LCU data --- src/intra.c | 35 ----------------------------------- src/search.c | 14 +++++++++++++- src/transform.c | 20 -------------------- 3 files changed, 13 insertions(+), 56 deletions(-) diff --git a/src/intra.c b/src/intra.c index 86258578..65113441 100644 --- a/src/intra.c +++ b/src/intra.c @@ -28,7 +28,6 @@ #include "tables.h" #include "transform.h" #include "videoframe.h" -#include "reshape.h" // Tables for looking up the number of intra reference pixels based on // prediction units coordinate within an LCU. @@ -598,16 +597,6 @@ static void intra_recon_tb_leaf( kvz_intra_references refs; kvz_intra_build_reference(log2width, color, &luma_px, &pic_px, lcu, &refs, cfg->wpp); - if (0&&color == COLOR_Y && state->encoder_control->cfg.lmcs_enable) { - // Map to LMCS - for (int i = 0; i < 256 + 3; i++) { - refs.ref.left[i] = state->tile->frame->lmcs_aps->m_fwdLUT[refs.ref.left[i]]; - refs.ref.top[i] = state->tile->frame->lmcs_aps->m_fwdLUT[refs.ref.top[i]]; - //refs.filtered_ref.left[i] = state->slice->lmcs_aps->m_fwdLUT[refs.filtered_ref.left[i]]; - //refs.filtered_ref.top[i] = state->slice->lmcs_aps->m_fwdLUT[refs.filtered_ref.top[i]]; - } - } - kvz_pixel pred[32 * 32]; const bool filter_boundary = color == COLOR_Y && !(cfg->lossless && cfg->implicit_rdpcm); kvz_intra_predict(state, &refs, log2width, intra_mode, color, pred, filter_boundary); @@ -626,30 +615,6 @@ static void intra_recon_tb_leaf( break; } - if (0&&color == COLOR_Y && state->encoder_control->cfg.lmcs_enable) { - kvz_pixel* lmcs_pix = pred; - for (int y = 0; y < width; y++) { - for (int x = 0; x < width; x++) { - lmcs_pix[x] = state->tile->frame->lmcs_aps->m_fwdLUT[lmcs_pix[x]]; - } - lmcs_pix += width; - } - - - static FILE* lut = NULL; - if (lut == NULL) { - lut = fopen("LUT_kvz.txt", "wb"); - for (int i = 0; i < 256; i++) { - fprintf(lut, "%d ", state->tile->frame->lmcs_aps->m_fwdLUT[i]); - } - fprintf(lut, "\r\n"); - for (int i = 0; i < 256; i++) { - fprintf(lut, "%d ", state->tile->frame->lmcs_aps->m_invLUT[i]); - } - fclose(lut); - lut = (FILE*)123; - } - } kvz_pixels_blit(pred, block , width, width, width, lcu_width); } diff --git a/src/search.c b/src/search.c index cedebdff..0b6b4221 100644 --- a/src/search.c +++ b/src/search.c @@ -37,7 +37,7 @@ #include "videoframe.h" #include "strategies/strategies-picture.h" #include "strategies/strategies-quant.h" - +#include "reshape.h" #define IN_FRAME(x, y, width, height, block_width, block_height) \ ((x) >= 0 && (y) >= 0 \ @@ -909,6 +909,10 @@ static void init_lcu_t(const encoder_state_t * const state, const int x, const i int chroma_bytes = (x_max / 2 + (1 - x_min_in_lcu))*sizeof(kvz_pixel); memcpy(&lcu->top_ref.y[x_min_in_lcu], &hor_buf->y[luma_offset], luma_bytes); + + if(state->encoder_control->cfg.lmcs_enable) + for (int i = 0; i < luma_bytes; i++) lcu->top_ref.y[x_min_in_lcu + i] = state->tile->frame->lmcs_aps->m_fwdLUT[lcu->top_ref.y[x_min_in_lcu + i]]; + if (state->encoder_control->chroma_format != KVZ_CSP_400) { memcpy(&lcu->top_ref.u[x_min_in_lcu], &hor_buf->u[chroma_offset], chroma_bytes); memcpy(&lcu->top_ref.v[x_min_in_lcu], &hor_buf->v[chroma_offset], chroma_bytes); @@ -923,6 +927,10 @@ static void init_lcu_t(const encoder_state_t * const state, const int x, const i int chroma_bytes = (LCU_WIDTH / 2 + (1 - y_min_in_lcu)) * sizeof(kvz_pixel); memcpy(&lcu->left_ref.y[y_min_in_lcu], &ver_buf->y[luma_offset], luma_bytes); + + if (state->encoder_control->cfg.lmcs_enable) + for (int i = 0; i < luma_bytes; i++) lcu->left_ref.y[y_min_in_lcu + i] = state->tile->frame->lmcs_aps->m_fwdLUT[lcu->left_ref.y[y_min_in_lcu + i]]; + if (state->encoder_control->chroma_format != KVZ_CSP_400) { memcpy(&lcu->left_ref.u[y_min_in_lcu], &ver_buf->u[chroma_offset], chroma_bytes); memcpy(&lcu->left_ref.v[y_min_in_lcu], &ver_buf->v[chroma_offset], chroma_bytes); @@ -943,6 +951,8 @@ static void init_lcu_t(const encoder_state_t * const state, const int x, const i kvz_pixels_blit(&frame->source->y[x + y * frame->source->stride], lcu->ref.y, x_max, y_max, frame->source->stride, LCU_WIDTH); + if (state->encoder_control->cfg.lmcs_enable) + for (int i = 0; i < LCU_WIDTH * LCU_WIDTH; i++) lcu->ref.y[i] = state->tile->frame->lmcs_aps->m_fwdLUT[lcu->ref.y[i]]; 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, x_max_c, y_max_c, frame->source->stride / 2, LCU_WIDTH / 2); @@ -1018,6 +1028,8 @@ void kvz_search_lcu(encoder_state_t * const state, const int x, const int y, con // The best decisions through out the LCU got propagated back to depth 0, // so copy those back to the frame. + if (state->encoder_control->cfg.lmcs_enable) + for (int i = 0; i < LCU_WIDTH * LCU_WIDTH; i++) work_tree[0].rec.y[i] = state->tile->frame->lmcs_aps->m_invLUT[work_tree[0].rec.y[i]]; copy_lcu_to_cu_data(state, x, y, &work_tree[0]); // Copy coeffs to encoder state. diff --git a/src/transform.c b/src/transform.c index da94da4d..6f83a04f 100644 --- a/src/transform.c +++ b/src/transform.c @@ -27,7 +27,6 @@ #include "strategies/strategies-quant.h" #include "strategies/strategies-picture.h" #include "tables.h" -#include "reshape.h" /** * \brief RDPCM direction. @@ -364,16 +363,6 @@ static void quantize_tr_residual(encoder_state_t * const state, break; } - if (state->encoder_control->cfg.lmcs_enable && color == COLOR_Y) { - kvz_pixel* luma = pred; - for (int y = 0; y < tr_width; y++) { - for (int x = 0; x < tr_width; x++) { - luma[x] = state->tile->frame->lmcs_aps->m_fwdLUT[luma[x]]; - } - luma += lcu_width; - } - } - const bool can_use_trskip = tr_width == 4 && color == COLOR_Y && cfg->trskip_enable; @@ -434,15 +423,6 @@ static void quantize_tr_residual(encoder_state_t * const state, if (has_coeffs) { cbf_set(&cur_pu->cbf, depth, color); } - if (state->encoder_control->cfg.lmcs_enable && color == COLOR_Y) { - kvz_pixel* luma = pred; - for (int y = 0; y < tr_width; y++) { - for (int x = 0; x < tr_width; x++) { - luma[x] = state->tile->frame->lmcs_aps->m_invLUT[luma[x]]; - } - luma += lcu_width; - } - } }