Add assert to check if deltaQP out of bounds. Clip adaptive QP to [-13, 12].

This commit is contained in:
Kari Siivonen (TAU) 2020-02-15 14:54:03 +02:00 committed by siivonek
parent f07990794f
commit c972ca9067
2 changed files with 7 additions and 1 deletions

View file

@ -269,6 +269,8 @@ static void encode_transform_coeff(encoder_state_t * const state,
if (state->must_code_qp_delta) {
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;
assert(KVZ_BIT_DEPTH == 8 && "This range applies only to 8-bit encoding.");
assert(qp_delta >= -26 && qp_delta <= 25 && "QP delta not in valid range [-26, 25]."); // This range applies only to 8-bit encoding
const int qp_delta_abs = ABS(qp_delta);
cabac_data_t* cabac = &state->cabac;

View file

@ -334,7 +334,11 @@ void kvz_set_lcu_lambda_and_qp(encoder_state_t * const state,
};
int id = lcu.x + lcu.y * state->tile->frame->width_in_lcu;
int aq_offset = (int)state->frame->aq_offsets[id]; // TODO: Number stored in aq_offsets may need rounding
state->qp = CLIP_TO_QP(state->qp + aq_offset);
state->qp += aq_offset;
// Maximum delta QP is clipped between [-26, 25] according to ITU T-REC-H.265 specification chapter 7.4.9.10 Transform unit semantics
// Since this value will be later combined with qp_pred, clip to half of that instead to be safe
state->qp = CLIP(state->frame->QP - 13, state->frame->QP + 12, state->qp);
state->qp = CLIP_TO_QP(state->qp);
state->lambda = qp_to_lamba(state, state->qp);
state->lambda_sqrt = sqrt(state->lambda);
}