diff --git a/src/encode_coding_tree.c b/src/encode_coding_tree.c index 4884e3ba..e0459239 100644 --- a/src/encode_coding_tree.c +++ b/src/encode_coding_tree.c @@ -352,8 +352,8 @@ void kvz_encode_last_significant_xy(cabac_data_t * const cabac, } static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int depth, const uint8_t width_c, const cu_info_t* cur_pu, int8_t* scan_idx, lcu_coeff_t* coeff, uint8_t joint_chroma) { - int x_local = (x >> 1) % LCU_WIDTH_C; - int y_local = (y >> 1) % LCU_WIDTH_C; + int x_local = ((x & ~7) >> 1) % LCU_WIDTH_C; + int y_local = ((y & ~7) >> 1) % LCU_WIDTH_C; cabac_data_t* const cabac = &state->cabac; *scan_idx = kvz_get_scan_order(cur_pu->type, cur_pu->intra.mode_chroma, depth); if(!joint_chroma){ @@ -367,7 +367,7 @@ static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int dep // TODO: transform skip for chroma blocks CABAC_BIN(cabac, 0, "transform_skip_flag"); } - kvz_encode_coeff_nxn(state, &state->cabac, coeff_u, width_c, 1, *scan_idx, NULL, false); + kvz_encode_coeff_nxn(state, &state->cabac, coeff_u, width_c, COLOR_U, *scan_idx, NULL, false); } if (cbf_is_set(cur_pu->cbf, depth, COLOR_V)) { @@ -375,7 +375,7 @@ static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int dep cabac->cur_ctx = &cabac->ctx.transform_skip_model_chroma; CABAC_BIN(cabac, 0, "transform_skip_flag"); } - kvz_encode_coeff_nxn(state, &state->cabac, coeff_v, width_c, 2, *scan_idx, NULL, false); + kvz_encode_coeff_nxn(state, &state->cabac, coeff_v, width_c, COLOR_V, *scan_idx, NULL, false); } } else { @@ -384,7 +384,7 @@ static void encode_chroma_tu(encoder_state_t* const state, int x, int y, int dep cabac->cur_ctx = &cabac->ctx.transform_skip_model_chroma; CABAC_BIN(cabac, 0, "transform_skip_flag"); } - kvz_encode_coeff_nxn(state, &state->cabac, coeff_uv, width_c, 2, *scan_idx, NULL, false); + kvz_encode_coeff_nxn(state, &state->cabac, coeff_uv, width_c, COLOR_V, *scan_idx, NULL, false); } } @@ -444,8 +444,6 @@ static void encode_transform_unit(encoder_state_t * const state, } else { // Time to to code the chroma transform blocks. Move to the top-left // corner of the block. - x -= 4; - y -= 4; cur_pu = kvz_cu_array_at_const((const cu_array_t *)frame->cu_array, x, y); } } @@ -485,7 +483,7 @@ static void encode_transform_coeff(encoder_state_t * const state, // containing CU. const int x_cu = 8 * (x / 8); const int y_cu = 8 * (y / 8); - const cu_info_t *cur_cu = kvz_cu_array_at_const(frame->cu_array, x_cu, y_cu); + const cu_info_t *cur_cu = kvz_cu_array_at_const(frame->cu_array, x, y); // NxN signifies implicit transform split at the first transform level. // There is a similar implicit split for inter, but it is only used when diff --git a/src/intra.c b/src/intra.c index 88849c4e..c1b0b095 100644 --- a/src/intra.c +++ b/src/intra.c @@ -1534,6 +1534,11 @@ void kvz_intra_recon_cu( } const int8_t mode_luma = search_data->pred_cu.intra.mode; const int8_t mode_chroma= search_data->pred_cu.intra.mode_chroma; + + if(mode_chroma != -1 && mode_luma == -1) { + x &= ~7; + y &= ~7; + } if (mode_luma != -1 && mode_chroma != -1) { if (search_data->pred_cu.intra.mip_flag) { diff --git a/src/search.c b/src/search.c index a474d4c5..8d93390a 100644 --- a/src/search.c +++ b/src/search.c @@ -608,7 +608,7 @@ void kvz_select_jccr_mode( { const vector2d_t lcu_px = { (SUB_SCU(x_px) & ~7) / 2, (SUB_SCU(y_px) & ~7) / 2 }; const int width = (depth < MAX_DEPTH) ? LCU_WIDTH >> (depth + 1) : LCU_WIDTH >> depth; - if (pred_cu == NULL) pred_cu = LCU_GET_CU_AT_PX(lcu, lcu_px.x * 2, lcu_px.y * 2); + if (pred_cu == NULL) pred_cu = LCU_GET_CU_AT_PX(lcu, SUB_SCU(x_px), SUB_SCU(y_px)); assert(pred_cu->depth == pred_cu->tr_depth && "jccr does not support transform splitting"); if (cost_out == NULL && pred_cu->joint_cb_cr == 0) { return; @@ -650,23 +650,23 @@ void kvz_select_jccr_mode( cbf_mask = pred_cu->joint_cb_cr - 1; CABAC_FBITS_UPDATE(cabac, &(cabac->ctx.joint_cb_cr[cbf_mask]), 1, joint_cbcr_tr_tree_bits, "jccr_flag"); } - int ssd = 0; - int joint_ssd = 0; + unsigned ssd = 0; + unsigned joint_ssd = 0; if (!state->encoder_control->cfg.lossless) { - int index = lcu_px.y * LCU_WIDTH_C + lcu_px.x; - int ssd_u = kvz_pixels_calc_ssd(&lcu->ref.u[index], &lcu->rec.u[index], + const int index = lcu_px.y * LCU_WIDTH_C + lcu_px.x; + const unsigned ssd_u = kvz_pixels_calc_ssd(&lcu->ref.u[index], &lcu->rec.u[index], LCU_WIDTH_C, LCU_WIDTH_C, width); - int ssd_v = kvz_pixels_calc_ssd(&lcu->ref.v[index], &lcu->rec.v[index], + const unsigned ssd_v = kvz_pixels_calc_ssd(&lcu->ref.v[index], &lcu->rec.v[index], LCU_WIDTH_C, LCU_WIDTH_C, width); ssd = ssd_u + ssd_v; if (pred_cu->joint_cb_cr) { - int ssd_u_joint = kvz_pixels_calc_ssd(&lcu->ref.u[index], &lcu->rec.joint_u[index], + const unsigned ssd_u_joint = kvz_pixels_calc_ssd(&lcu->ref.u[index], &lcu->rec.joint_u[index], LCU_WIDTH_C, LCU_WIDTH_C, width); - int ssd_v_joint = kvz_pixels_calc_ssd(&lcu->ref.v[index], &lcu->rec.joint_v[index], + const unsigned ssd_v_joint = kvz_pixels_calc_ssd(&lcu->ref.v[index], &lcu->rec.joint_v[index], LCU_WIDTH_C, LCU_WIDTH_C, width); joint_ssd = ssd_u_joint + ssd_v_joint; @@ -1009,13 +1009,13 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, } intra_search.pred_cu.intra.mode = -1; // skip luma kvz_intra_recon_cu(state, - x & ~7, y & ~7, // TODO: as does this + x, y, // TODO: as does this depth, &intra_search, NULL, lcu); if(depth != 0 && state->encoder_control->cfg.jccr && ctrl->cfg.rdo < 3) { kvz_select_jccr_mode(state, - x & ~7, y & ~7, + x, y, depth, NULL, lcu, @@ -1074,7 +1074,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth, false); if (cur_cu->depth == cur_cu->tr_depth && state->encoder_control->cfg.jccr && cur_cu->joint_cb_cr) { kvz_select_jccr_mode(state, - x & ~7, y & ~7, + x, y, depth, NULL, lcu, diff --git a/src/search_intra.c b/src/search_intra.c index 7a8eb41b..7c9ea40c 100644 --- a/src/search_intra.c +++ b/src/search_intra.c @@ -367,7 +367,7 @@ static double search_intra_trdepth( pred_cu->intra.mode_chroma = chroma_mode; pred_cu->joint_cb_cr= 4; // TODO: Maybe check the jccr mode here also but holy shit is the interface of search_intra_rdo bad currently kvz_intra_recon_cu(state, - x_px & ~7, y_px & ~7, + x_px, y_px, depth, search_data, pred_cu, lcu);