[lfnst] Fix mistakes

This commit is contained in:
Joose Sainio 2022-06-28 13:45:51 +03:00
parent 2fbbae834b
commit e25ea52f6f
4 changed files with 15 additions and 12 deletions

View file

@ -165,7 +165,8 @@ static bool can_use_lfnst_with_isp(const int width, const int height, const int
const int height, const int height,
const int x, const int x,
const int y, const int y,
enum uvg_tree_type tree_type) enum uvg_tree_type tree_type,
const color_t color)
{ {
if (state->encoder_control->cfg.lfnst && pred_cu->type == CU_INTRA) { if (state->encoder_control->cfg.lfnst && pred_cu->type == CU_INTRA) {
const int isp_mode = 0; // ISP_TODO: assign proper ISP mode when ISP is implemented const int isp_mode = 0; // ISP_TODO: assign proper ISP mode when ISP is implemented
@ -185,8 +186,8 @@ static bool can_use_lfnst_with_isp(const int width, const int height, const int
(cu_width > TR_MAX_WIDTH || cu_height > TR_MAX_WIDTH)) { (cu_width > TR_MAX_WIDTH || cu_height > TR_MAX_WIDTH)) {
return false; return false;
} }
bool luma_flag = (depth == 4 && tree_type == UVG_BOTH_T) || tree_type == UVG_LUMA_T; bool luma_flag = (depth == 4 && color == COLOR_Y) || (tree_type != UVG_CHROMA_T && depth != 4);
bool chroma_flag = (depth == 4 && tree_type == UVG_BOTH_T) || tree_type == UVG_CHROMA_T; bool chroma_flag = (depth == 4 && color != COLOR_Y) || tree_type != UVG_LUMA_T;
bool non_zero_coeff_non_ts_corner_8x8 = (luma_flag && pred_cu->violates_lfnst_constrained_luma) || (chroma_flag && pred_cu->violates_lfnst_constrained_chroma); bool non_zero_coeff_non_ts_corner_8x8 = (luma_flag && pred_cu->violates_lfnst_constrained_luma) || (chroma_flag && pred_cu->violates_lfnst_constrained_chroma);
bool is_tr_skip = false; bool is_tr_skip = false;
@ -234,10 +235,11 @@ static bool encode_lfnst_idx(
const int depth, const int depth,
const int width, const int width,
const int height, const int height,
enum uvg_tree_type tree_type) enum uvg_tree_type tree_type,
const color_t color)
{ {
if (uvg_is_lfnst_allowed(state, pred_cu, width, height, x, y, tree_type)) { if (uvg_is_lfnst_allowed(state, pred_cu, width, height, x, y, tree_type, color)) {
// Getting separate tree bool from block size is a temporary fix until a proper dual tree check is possible (there is no dual tree structure at time of writing this). // Getting separate tree bool from block size is a temporary fix until a proper dual tree check is possible (there is no dual tree structure at time of writing this).
// VTM seems to force explicit dual tree structure for small 4x4 blocks // VTM seems to force explicit dual tree structure for small 4x4 blocks
bool is_separate_tree = depth == 4 || tree_type != UVG_BOTH_T; bool is_separate_tree = depth == 4 || tree_type != UVG_BOTH_T;
@ -1717,7 +1719,7 @@ void uvg_encode_coding_tree(
encode_transform_coeff(state, x, y, depth, 0, 0, 0, 0, coeff, tree_type); encode_transform_coeff(state, x, y, depth, 0, 0, 0, 0, coeff, tree_type);
} }
bool lfnst_written = encode_lfnst_idx(state, cabac, cur_cu, x, y, depth, cu_width, cu_height, tree_type); bool lfnst_written = encode_lfnst_idx(state, cabac, cur_cu, x, y, depth, cu_width, cu_height, tree_type, COLOR_Y);
encode_mts_idx(state, cabac, cur_cu); encode_mts_idx(state, cabac, cur_cu);
@ -1733,8 +1735,8 @@ void uvg_encode_coding_tree(
tmp->lfnst_last_scan_pos = false; tmp->lfnst_last_scan_pos = false;
encode_transform_coeff(state, x, y, depth, 0, 0, 0, 1, coeff, tree_type); encode_transform_coeff(state, x, y, depth, 0, 0, 0, 1, coeff, tree_type);
// Write LFNST only once for single tree structure // Write LFNST only once for single tree structure
if (!lfnst_written || tree_type == UVG_CHROMA_T) { if (!lfnst_written || tree_type == UVG_CHROMA_T || depth == 4) {
encode_lfnst_idx(state, cabac, tmp, x, y, depth, cu_width, cu_height, tree_type); encode_lfnst_idx(state, cabac, tmp, x, y, depth, cu_width, cu_height, tree_type, COLOR_UV);
} }
} }
} }

View file

@ -48,7 +48,8 @@ bool uvg_is_lfnst_allowed(
const int height, const int height,
const int x, const int x,
const int y, const int y,
enum uvg_tree_type tree_type); enum uvg_tree_type tree_type,
const color_t color);
void uvg_encode_coding_tree( void uvg_encode_coding_tree(
encoder_state_t * const state, encoder_state_t * const state,

View file

@ -567,7 +567,7 @@ static double cu_rd_cost_tr_split_accurate(
} }
if(depth == 4 || tree_type == UVG_LUMA_T) { if(depth == 4 || tree_type == UVG_LUMA_T) {
if (uvg_is_lfnst_allowed(state, tr_cu, width, width, x_px, y_px, tree_type)) { if (uvg_is_lfnst_allowed(state, tr_cu, width, width, x_px, y_px, tree_type, COLOR_Y)) {
const int lfnst_idx = tr_cu->lfnst_idx; const int lfnst_idx = tr_cu->lfnst_idx;
CABAC_FBITS_UPDATE( CABAC_FBITS_UPDATE(
cabac, cabac,
@ -634,7 +634,7 @@ static double cu_rd_cost_tr_split_accurate(
} }
} }
if (uvg_is_lfnst_allowed(state, tr_cu, width, width, x_px, y_px, tree_type)) { if (uvg_is_lfnst_allowed(state, tr_cu, width, width, x_px, y_px, tree_type, depth == 4 || tree_type == UVG_CHROMA_T ? COLOR_UV : COLOR_Y)) {
const int lfnst_idx = (depth != 4 && tree_type != UVG_CHROMA_T) ? tr_cu->lfnst_idx : tr_cu->cr_lfnst_idx; const int lfnst_idx = (depth != 4 && tree_type != UVG_CHROMA_T) ? tr_cu->lfnst_idx : tr_cu->cr_lfnst_idx;
CABAC_FBITS_UPDATE( CABAC_FBITS_UPDATE(
cabac, cabac,

View file

@ -701,7 +701,7 @@ void uvg_chroma_transform_search(
transforms[i] == CHROMA_TS); transforms[i] == CHROMA_TS);
} }
if((depth == 4 || tree_type == UVG_CHROMA_T) && state->encoder_control->cfg.lfnst && 0) { if((depth == 4 || tree_type == UVG_CHROMA_T) && state->encoder_control->cfg.lfnst && 0) {
if(uvg_is_lfnst_allowed(state, pred_cu, width, height, 0, 0 , UVG_CHROMA_T)) { if(uvg_is_lfnst_allowed(state, pred_cu, width, height, 0, 0 , UVG_CHROMA_T, COLOR_UV)) {
const int lfnst_idx = pred_cu->cr_lfnst_idx; const int lfnst_idx = pred_cu->cr_lfnst_idx;
CABAC_FBITS_UPDATE( CABAC_FBITS_UPDATE(
&state->search_cabac, &state->search_cabac,