diff --git a/src/encoder_state-bitstream.c b/src/encoder_state-bitstream.c index 705460a1..0bcc0f9b 100644 --- a/src/encoder_state-bitstream.c +++ b/src/encoder_state-bitstream.c @@ -1298,6 +1298,12 @@ void kvz_encoder_state_write_bitstream_slice_header( } } + // ToDo: depquant + + if (state->encoder_control->cfg.signhide_enable) { + WRITE_U(stream, 1, 1, "sh_sign_data_hiding_used_flag"); + } + if (state->frame->slicetype != KVZ_SLICE_I) { // BT Size set only with non-I-frames, in I-frames the size is 32x32 diff --git a/src/rdo.c b/src/rdo.c index 83e8d742..2b2d33f7 100644 --- a/src/rdo.c +++ b/src/rdo.c @@ -638,7 +638,7 @@ void kvz_rdoq_sign_hiding( * coding engines using probability models like CABAC * From HM 12.0 */ -/* + // ToDo: implement new RDOQ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff, int32_t width, int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth) @@ -699,7 +699,7 @@ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff, default: assert(0 && "There should be 1, 4, 16 or 64 coefficient groups"); } - cabac_ctx_t *base_coeff_group_ctx = &(cabac->ctx.cu_sig_coeff_group_model[type]); + cabac_ctx_t *base_coeff_group_ctx = &(cabac->ctx.sig_coeff_group_model[type]); cabac_ctx_t *baseCtx = (type == 0) ? &(cabac->ctx.cu_sig_model_luma[0][0]) : &(cabac->ctx.cu_sig_model_chroma[0][0]); struct { @@ -974,7 +974,7 @@ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff, kvz_rdoq_sign_hiding(state, qp_scaled, scan, &sh_rates, best_last_idx_p1, coef, dest_coeff); } } -*/ + /** * Calculate cost of actual motion vectors using CABAC coding diff --git a/src/rdo.h b/src/rdo.h index d867cc4a..29848e65 100644 --- a/src/rdo.h +++ b/src/rdo.h @@ -36,8 +36,8 @@ extern const uint32_t kvz_g_go_rice_range[5]; extern const uint32_t kvz_g_go_rice_prefix_len[5]; -/*void kvz_rdoq(encoder_state_t *state, coeff_t *coef, coeff_t *dest_coeff, int32_t width, - int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth);*/ +void kvz_rdoq(encoder_state_t *state, coeff_t *coef, coeff_t *dest_coeff, int32_t width, + int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth); uint32_t kvz_get_coeff_cost(const encoder_state_t * const state, const coeff_t *coeff, diff --git a/src/strategies/avx2/quant-avx2.c b/src/strategies/avx2/quant-avx2.c index b50f6505..3909947c 100644 --- a/src/strategies/avx2/quant-avx2.c +++ b/src/strategies/avx2/quant-avx2.c @@ -349,8 +349,8 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr int32_t height, int8_t type, int8_t scan_idx, int8_t block_type) { const encoder_control_t * const encoder = state->encoder_control; - //const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2; - //const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1]; + const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2; + const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1]; int32_t qp_scaled = kvz_get_scaled_qp(type, state->qp, (encoder->bitdepth - 8) * 6); const uint32_t log2_tr_size = kvz_g_convert_to_bit[width] + 2; @@ -359,7 +359,7 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr const int32_t transform_shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size; //!< Represents scaling through forward transform const int32_t q_bits = QUANT_SHIFT + qp_scaled / 6 + transform_shift; const int32_t add = ((state->frame->slicetype == KVZ_SLICE_I) ? 171 : 85) << (q_bits - 9); - //const int32_t q_bits8 = q_bits - 8; + const int32_t q_bits8 = q_bits - 8; uint32_t ac_sum = 0; int32_t last_cg = -1; @@ -433,7 +433,7 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr temp = _mm_add_epi32(temp, _mm_shuffle_epi32(temp, _MM_SHUFFLE(1, 0, 3, 2))); temp = _mm_add_epi32(temp, _mm_shuffle_epi32(temp, _MM_SHUFFLE(0, 1, 0, 1))); ac_sum += _mm_cvtsi128_si32(temp); - /* + // Signhiding disabled in VVC if (!encoder->cfg.signhide_enable || ac_sum < 2) return; @@ -505,7 +505,7 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr #undef VEC_WIDTH #undef SCAN_SET_SIZE #undef LOG2_SCAN_SET_SIZE - */ + } #if KVZ_BIT_DEPTH == 8 @@ -658,7 +658,7 @@ int kvz_quantize_residual_avx2(encoder_state_t *const state, } // Quantize coeffs. (coeff -> coeff_out) - /* + if (state->encoder_control->cfg.rdoq_enable && (width > 4 || !state->encoder_control->cfg.rdoq_skip)) { @@ -666,7 +666,7 @@ int kvz_quantize_residual_avx2(encoder_state_t *const state, tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0); kvz_rdoq(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2), scan_order, cur_cu->type, tr_depth); - } else*/ { + } else { kvz_quant(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2), scan_order, cur_cu->type); } diff --git a/src/strategies/generic/encode_coding_tree-generic.c b/src/strategies/generic/encode_coding_tree-generic.c index 8b6f4bba..1888f0dd 100644 --- a/src/strategies/generic/encode_coding_tree-generic.c +++ b/src/strategies/generic/encode_coding_tree-generic.c @@ -273,6 +273,7 @@ void kvz_encode_coeff_nxn_generic(encoder_state_t * const state, quant_state = (quant_state_transition_table >> ((quant_state << 2) + ((coeff_abs & 1) << 1))) & 3; if (coeff_abs) { num_non_zero++; + first_nz_pos_in_cg = scan_pos; last_nz_pos_in_cg = MAX(last_nz_pos_in_cg, scan_pos); coeff_signs <<= 1; if (coeff[blk_pos] < 0) coeff_signs++; diff --git a/src/strategies/generic/quant-generic.c b/src/strategies/generic/quant-generic.c index 5a29e2ff..0006663d 100644 --- a/src/strategies/generic/quant-generic.c +++ b/src/strategies/generic/quant-generic.c @@ -38,8 +38,8 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff int32_t height, int8_t type, int8_t scan_idx, int8_t block_type) { const encoder_control_t * const encoder = state->encoder_control; - //const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2; - //const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1]; + const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2; + const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1]; int32_t qp_scaled = kvz_get_scaled_qp(type, state->qp, (encoder->bitdepth - 8) * 6); const uint32_t log2_tr_size = kvz_g_convert_to_bit[width] + 2; @@ -48,7 +48,7 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff const int32_t transform_shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size; //!< Represents scaling through forward transform const int32_t q_bits = QUANT_SHIFT + qp_scaled / 6 + transform_shift; const int32_t add = ((state->frame->slicetype == KVZ_SLICE_I) ? 171 : 85) << (q_bits - 9); - //const int32_t q_bits8 = q_bits - 8; + const int32_t q_bits8 = q_bits - 8; uint32_t ac_sum = 0; @@ -67,8 +67,8 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff q_coef[n] = (coeff_t)(CLIP(-32768, 32767, level)); } - /* - // Signhiding disabled in VVC + + // Signhiding if (!encoder->cfg.signhide_enable || ac_sum < 2) return; int32_t delta_u[LCU_WIDTH*LCU_WIDTH >> 2]; @@ -165,7 +165,6 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff #undef SCAN_SET_SIZE #undef LOG2_SCAN_SET_SIZE } - */ } /** @@ -220,7 +219,7 @@ int kvz_quantize_residual_generic(encoder_state_t *const state, } // Quantize coeffs. (coeff -> coeff_out) - /* + if (state->encoder_control->cfg.rdoq_enable && (width > 4 || !state->encoder_control->cfg.rdoq_skip)) { @@ -228,7 +227,7 @@ int kvz_quantize_residual_generic(encoder_state_t *const state, tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0); kvz_rdoq(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2), scan_order, cur_cu->type, tr_depth); - } else*/ { + } else { kvz_quant(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2), scan_order, cur_cu->type); diff --git a/tests/test_intra.sh b/tests/test_intra.sh index 58eba361..d3d93b85 100755 --- a/tests/test_intra.sh +++ b/tests/test_intra.sh @@ -9,3 +9,6 @@ set -eu common_args='256x128 10 -p1 --preset=ultrafast --threads=0 --no-wpp --no-tmvp --no-deblock --sao=0 --alf=full --cpuid=0' valgrind_test $common_args --rd=1 valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 +valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 --rdoq +valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 --signhide +valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 --signhide --rdoq