From 804a3b648ba07dc5eba3e0f51c35bb8a7b636a3d Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Fri, 23 Jan 2015 16:03:59 +0200 Subject: [PATCH] Clean up quantization sign hiding. - To allow for later configuration at runtime. --- src/transform.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/transform.c b/src/transform.c index 47422d39..2f0bde4d 100644 --- a/src/transform.c +++ b/src/transform.c @@ -138,28 +138,20 @@ void quant(const encoder_state * const encoder_state, int16_t *coef, int16_t *q_ const encoder_control * const encoder = encoder_state->encoder_control; const uint32_t log2_block_size = g_convert_to_bit[ width ] + 2; const uint32_t * const scan = g_sig_last_scan[ scan_idx ][ log2_block_size - 1 ]; - uint32_t ac_sum = 0; - - #if ENABLE_SIGN_HIDING == 1 - int32_t delta_u[LCU_WIDTH*LCU_WIDTH>>2]; - #endif int32_t qp_scaled = get_scaled_qp(type, encoder_state->global->QP, 0); //New block for variable definitions { - int32_t n; - uint32_t log2_tr_size = g_convert_to_bit[ width ] + 2; - int32_t scalinglist_type = (block_type == CU_INTRA ? 0 : 3) + (int8_t)("\0\3\1\2"[type]); - + const uint32_t log2_tr_size = g_convert_to_bit[ width ] + 2; + const int32_t scalinglist_type = (block_type == CU_INTRA ? 0 : 3) + (int8_t)("\0\3\1\2"[type]); const int32_t *quant_coeff = encoder->scaling_list.quant_coeff[log2_tr_size-2][scalinglist_type][qp_scaled%6]; + 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 = ((encoder_state->global->slicetype == SLICE_I) ? 171 : 85) << (q_bits - 9); + const int32_t q_bits8 = q_bits - 8; - int32_t transform_shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size; //!< Represents scaling through forward transform - int32_t q_bits = QUANT_SHIFT + qp_scaled/6 + transform_shift; - int32_t add = ((encoder_state->global->slicetype == SLICE_I) ? 171 : 85) << (q_bits - 9); - - int32_t q_bits8 = q_bits - 8; - for (n = 0; n < width * height; n++) { + for (int32_t n = 0; n < width * height; n++) { int32_t level; int32_t sign; @@ -168,16 +160,22 @@ void quant(const encoder_state * const encoder_state, int16_t *coef, int16_t *q_ level = ((int64_t)abs(level) * quant_coeff[n] + add ) >> q_bits; - #if ENABLE_SIGN_HIDING == 1 - delta_u[n] = (int32_t)( ((int64_t)abs(coef[n]) * quant_coeff[n] - (level<> q_bits8 ); - ac_sum += level; - #endif - level *= sign; q_coef[n] = (int16_t)(CLIP( -32768, 32767, level)); } - #if ENABLE_SIGN_HIDING == 1 +#if ENABLE_SIGN_HIDING == 1 + int32_t delta_u[LCU_WIDTH*LCU_WIDTH >> 2]; + uint32_t ac_sum = 0; + + for (int32_t n = 0; n < width * height; n++) { + int32_t level; + level = coef[n]; + level = ((int64_t)abs(level) * quant_coeff[n] + add) >> q_bits; + delta_u[n] = (int32_t)(((int64_t)abs(coef[n]) * quant_coeff[n] - (level << q_bits)) >> q_bits8); + ac_sum += level; + } + if(ac_sum >= 2) { #define SCAN_SET_SIZE 16 #define LOG2_SCAN_SET_SIZE 4 @@ -257,7 +255,7 @@ void quant(const encoder_state * const encoder_state, int16_t *coef, int16_t *q_ #undef SCAN_SET_SIZE #undef LOG2_SCAN_SET_SIZE } - #endif +#endif // SIGN_HIDING } }