diff --git a/src/encode_coding_tree.c b/src/encode_coding_tree.c index 749a2bf2..b2e14582 100644 --- a/src/encode_coding_tree.c +++ b/src/encode_coding_tree.c @@ -25,6 +25,7 @@ #include "cu.h" #include "encoder.h" #include "extras/crypto.h" +#include "global.h" #include "imagelist.h" #include "inter.h" #include "intra.h" @@ -270,10 +271,7 @@ static void encode_transform_coeff(encoder_state_t * const state, const int qp_pred = kvz_get_cu_ref_qp(state, x_cu, y_cu, state->last_qp); const int qp_delta = cur_cu->qp - qp_pred; // Possible deltaQP range depends on bit depth as stated in HEVC specification. - int qp_bd_offset = 3 * (KVZ_BIT_DEPTH - 8); - int qp_delta_min = -(26 + qp_bd_offset); - int qp_delta_max = 25 + qp_bd_offset; - assert(qp_delta >= qp_delta_min && qp_delta <= qp_delta_max && "QP delta not in valid range."); + assert(qp_delta >= KVZ_QP_DELTA_MIN && qp_delta <= KVZ_QP_DELTA_MAX && "QP delta not in valid range."); const int qp_delta_abs = ABS(qp_delta); cabac_data_t* cabac = &state->cabac; diff --git a/src/global.h b/src/global.h index ef44fc34..23ec550b 100644 --- a/src/global.h +++ b/src/global.h @@ -349,4 +349,8 @@ typedef enum { COLOR_Y = 0, COLOR_U, COLOR_V } color_t; # define COMPILE_ARM 0 #endif +// Min & max delta QP limits based on bit depth +#define KVZ_QP_DELTA_MIN -(26 + 3 * (KVZ_BIT_DEPTH - 8)) +#define KVZ_QP_DELTA_MAX 25 + 3 * (KVZ_BIT_DEPTH - 8) + #endif diff --git a/src/rate_control.c b/src/rate_control.c index d4de5df7..c586c9b7 100644 --- a/src/rate_control.c +++ b/src/rate_control.c @@ -803,9 +803,7 @@ static double qp_to_lambda(encoder_state_t* const state, int qp) // Maximum delta QP is clipped according to ITU T-REC-H.265 specification chapter 7.4.9.10 Transform unit semantics // Clipping range is a function of bit depth // Since this value will be later combined with qp_pred, clip to half of that instead to be safe - int qp_delta_min = (26 + (3 * (KVZ_BIT_DEPTH - 8))) / 2; - int qp_delta_max = (25 + (3 * (KVZ_BIT_DEPTH - 8))) / 2; - state->qp = CLIP(state->frame->QP - qp_delta_min, state->frame->QP + qp_delta_max, state->qp); + state->qp = CLIP(state->frame->QP + KVZ_QP_DELTA_MIN / 2, state->frame->QP + KVZ_QP_DELTA_MAX / 2, state->qp); state->qp = CLIP_TO_QP(state->qp); state->lambda = qp_to_lambda(state, state->qp); state->lambda_sqrt = sqrt(state->lambda); @@ -1149,9 +1147,7 @@ void kvz_set_lcu_lambda_and_qp(encoder_state_t * const state, // Maximum delta QP is clipped according to ITU T-REC-H.265 specification chapter 7.4.9.10 Transform unit semantics // Clipping range is a function of bit depth // Since this value will be later combined with qp_pred, clip to half of that instead to be safe - int qp_delta_min = (26 + (3 * (KVZ_BIT_DEPTH - 8))) / 2; - int qp_delta_max = (25 + (3 * (KVZ_BIT_DEPTH - 8))) / 2; - state->qp = CLIP(state->frame->QP - qp_delta_min, state->frame->QP + qp_delta_max, state->qp); + state->qp = CLIP(state->frame->QP + KVZ_QP_DELTA_MIN / 2, state->frame->QP + KVZ_QP_DELTA_MAX / 2, state->qp); state->qp = CLIP_TO_QP(state->qp); state->lambda = qp_to_lambda(state, state->qp); state->lambda_sqrt = sqrt(state->lambda);