diff --git a/src/cli.c b/src/cli.c index ce238506..b7c56efb 100644 --- a/src/cli.c +++ b/src/cli.c @@ -192,11 +192,11 @@ static const struct option long_options[] = { { "dual-tree", no_argument, NULL, 0 }, { "no-dual-tree", no_argument, NULL, 0 }, { "cabac-debug-file", required_argument, NULL, 0 }, - {"mtt-depth-intra", required_argument, NULL, 0 }, - {"mtt-depth-inter", required_argument, NULL, 0 }, - {"mtt-depth-intra-chroma", required_argument, NULL, 0 }, - {"max_bt_size", required_argument, NULL, 0 }, - {"max_tt_size", required_argument, NULL, 0 }, + { "mtt-depth-intra", required_argument, NULL, 0 }, + { "mtt-depth-inter", required_argument, NULL, 0 }, + { "mtt-depth-intra-chroma", required_argument, NULL, 0 }, + { "max-bt-size", required_argument, NULL, 0 }, + { "max-tt-size", required_argument, NULL, 0 }, { "intra-rough-granularity",required_argument, NULL, 0 }, { "ibc", required_argument, NULL, 0 }, { "dep-quant", no_argument, NULL, 0 }, diff --git a/src/cu.c b/src/cu.c index 147875fb..301ca100 100644 --- a/src/cu.c +++ b/src/cu.c @@ -373,18 +373,11 @@ int uvg_get_split_locs( int uvg_get_implicit_split( const encoder_state_t* const state, const cu_loc_t* const cu_loc, - enum - uvg_tree_type tree_type, - uint8_t max_mtt_depth) + uint8_t max_mtt_depth, + bool uses_chroma_coordinates) { - // This checking if cabac is in update state is a very dirty way of checking - // whether we are in the search or writing the bitstream, and unfortunately the - // coordinates are different for chroma tree in those two conditions. It might be - // possible to pass the chroma loc for uvg_get_possible_splits in the search but - // then all of the conditions need to be checked in that function. - // This current solutions *might* not work with alf enabled but I think it should work - bool right_ok = (state->tile->frame->width >> (tree_type == UVG_CHROMA_T && state->cabac.update)) >= cu_loc->x + cu_loc->width; - bool bottom_ok = (state->tile->frame->height >> (tree_type == UVG_CHROMA_T && state->cabac.update)) >= cu_loc->y + cu_loc->height; + bool right_ok = (state->tile->frame->width >> uses_chroma_coordinates) >= cu_loc->x + cu_loc->width; + bool bottom_ok = (state->tile->frame->height >> uses_chroma_coordinates) >= cu_loc->y + cu_loc->height; if (right_ok && bottom_ok) return NO_SPLIT; if (right_ok && max_mtt_depth != 0) return BT_HOR_SPLIT; @@ -394,10 +387,11 @@ int uvg_get_implicit_split( int uvg_get_possible_splits(const encoder_state_t * const state, - const cu_loc_t * const cu_loc, split_tree_t split_tree, enum uvg_tree_type tree_type, bool splits[6]) + const cu_loc_t * const cu_loc, split_tree_t split_tree, enum uvg_tree_type tree_type, bool splits[6], bool + use_chroma_coordinates) { - const int width = tree_type != UVG_CHROMA_T ? cu_loc->width : cu_loc->chroma_width; - const int height = tree_type != UVG_CHROMA_T ? cu_loc->height : cu_loc->chroma_height; + const unsigned width = tree_type != UVG_CHROMA_T ? cu_loc->width : cu_loc->chroma_width; + const unsigned height = tree_type != UVG_CHROMA_T ? cu_loc->height : cu_loc->chroma_height; const int slice_type = state->frame->is_irap ? (tree_type == UVG_CHROMA_T ? 2 : 0) : 1; const unsigned max_btd = @@ -408,7 +402,7 @@ int uvg_get_possible_splits(const encoder_state_t * const state, const unsigned min_tt_size = 1 << MIN_SIZE >> (tree_type == UVG_CHROMA_T); const unsigned min_qt_size = state->encoder_control->cfg.min_qt_size[slice_type]; - const enum split_type implicitSplit = uvg_get_implicit_split(state, cu_loc, tree_type, max_btd); + const enum split_type implicitSplit = uvg_get_implicit_split(state, cu_loc, max_btd, use_chroma_coordinates); splits[NO_SPLIT] = splits[QT_SPLIT] = splits[BT_HOR_SPLIT] = splits[TT_HOR_SPLIT] = splits[BT_VER_SPLIT] = splits[TT_VER_SPLIT] = true; bool can_btt = split_tree.mtt_depth < max_btd; @@ -426,8 +420,8 @@ int uvg_get_possible_splits(const encoder_state_t * const state, { splits[NO_SPLIT] = splits[TT_HOR_SPLIT] = splits[TT_VER_SPLIT] = false; - splits[BT_HOR_SPLIT] = implicitSplit == BT_HOR_SPLIT; - splits[BT_VER_SPLIT] = implicitSplit == BT_VER_SPLIT; + splits[BT_HOR_SPLIT] = implicitSplit == BT_HOR_SPLIT && height <= max_bt_size; + splits[BT_VER_SPLIT] = implicitSplit == BT_VER_SPLIT && width <= max_bt_size; if (tree_type == UVG_CHROMA_T && width == 4) splits[BT_VER_SPLIT] = false; if (!splits[BT_HOR_SPLIT] && !splits[BT_VER_SPLIT] && !splits[QT_SPLIT]) splits[QT_SPLIT] = true; return 1; diff --git a/src/cu.h b/src/cu.h index 843fe582..36cfb239 100644 --- a/src/cu.h +++ b/src/cu.h @@ -203,7 +203,8 @@ int uvg_get_split_locs( cu_loc_t out[4], uint8_t* separate_chroma); int uvg_get_possible_splits(const encoder_state_t* const state, - const cu_loc_t* const cu_loc, split_tree_t split_tree, enum uvg_tree_type tree_type, bool splits[6]); + const cu_loc_t* const cu_loc, split_tree_t split_tree, enum uvg_tree_type tree_type, bool splits[6], bool + use_chroma_coordinates); #define CU_GET_MV_CAND(cu_info_ptr, reflist) \ diff --git a/src/encode_coding_tree.c b/src/encode_coding_tree.c index 5604aa16..a23de174 100644 --- a/src/encode_coding_tree.c +++ b/src/encode_coding_tree.c @@ -1251,7 +1251,7 @@ uint8_t uvg_write_split_flag( bool can_split[6]; - const bool is_implicit = uvg_get_possible_splits(state, cu_loc, split_tree, tree_type, can_split); + const bool is_implicit = uvg_get_possible_splits(state, cu_loc, split_tree, tree_type, can_split, tree_type == UVG_CHROMA_T); bool allow_split = can_split[1] || can_split[2] || can_split[3] || can_split[4] || can_split[5]; diff --git a/src/global.h b/src/global.h index 27058463..972b7e82 100644 --- a/src/global.h +++ b/src/global.h @@ -129,7 +129,7 @@ typedef int16_t coeff_t; typedef int32_t mv_t; //#define VERBOSE 1 -#define UVG_DEBUG_PRINT_CABAC 1 +//#define UVG_DEBUG_PRINT_CABAC 1 //#define UVG_DEBUG 1 //#define UVG_DEBUG_PRINT_YUVIEW_CSV 1 diff --git a/src/search.c b/src/search.c index 40cc012a..f5f6e044 100644 --- a/src/search.c +++ b/src/search.c @@ -1600,6 +1600,8 @@ static double search_cu( cu_loc_t separate_tree_chroma_loc = *cu_loc; separate_tree_chroma_loc.y >>= 1; separate_tree_chroma_loc.x >>= 1; + separate_tree_chroma_loc.width >>= 1; + separate_tree_chroma_loc.height >>= 1; if (cur_cu->type == CU_INTRA || cur_cu->type == CU_INTER) { double bits = 0; @@ -1689,7 +1691,7 @@ static double search_cu( } bool can_split[6]; - bool is_implicit = uvg_get_possible_splits(state, cu_loc, split_tree, tree_type, can_split); + bool is_implicit = uvg_get_possible_splits(state, cu_loc, split_tree, tree_type, can_split, false); const int slice_type = state->frame->is_irap ? (tree_type == UVG_CHROMA_T ? 2 : 0) : 1; const int max_btd = state->encoder_control->cfg.max_btt_depth[slice_type]; diff --git a/src/search_intra.c b/src/search_intra.c index 1c911996..689d872d 100644 --- a/src/search_intra.c +++ b/src/search_intra.c @@ -417,7 +417,7 @@ static double search_intra_trdepth( } if (pred_cu->intra.isp_mode != ISP_MODE_NO_ISP && search_data->best_isp_cbfs == 0) continue; - if (trafo != 0 && !cbf_is_set(pred_cu->cbf, COLOR_Y)) continue; + if ((trafo != 0 || lfnst_idx != 0) && !cbf_is_set(pred_cu->cbf, COLOR_Y)) continue; derive_mts_constraints(pred_cu, lcu, width, height, lcu_px); if (pred_cu->tr_idx > 1) {