From 11bf11f33accf2a7f4e55067351bf4d6dd320de5 Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Fri, 21 Feb 2014 15:41:55 +0200 Subject: [PATCH] Changed duplicate scaled QP calculations to use a function --- src/rdo.c | 14 +------------- src/transform.c | 46 ++++++++++++++++++++++------------------------ src/transform.h | 2 ++ 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/rdo.c b/src/rdo.c index 2594aad7..46780227 100644 --- a/src/rdo.c +++ b/src/rdo.c @@ -286,19 +286,7 @@ void rdoq(encoder_control *encoder, coefficient *coef, coefficient *dest_coeff, int32_t scalinglist_type= (block_type == CU_INTRA ? 0 : 3) + (int8_t)("\0\3\1\2"[type]); int32_t qp_base = encoder->QP; - int32_t qp_scaled; - int32_t qp_offset = 0; - - if(type == 0) { - qp_scaled = qp_base + qp_offset; - } else { - qp_scaled = CLIP(-qp_offset, 57, qp_base); - if(qp_scaled < 0) { - qp_scaled = qp_scaled + qp_offset; - } else { - qp_scaled = g_chroma_scale[qp_scaled] + qp_offset; - } - } + int32_t qp_scaled = get_scaled_qp(type, encoder->QP, 0); { int32_t q_bits = QUANT_SHIFT + qp_scaled/6 + transform_shift; diff --git a/src/transform.c b/src/transform.c index a31f96c2..e07b70fe 100644 --- a/src/transform.c +++ b/src/transform.c @@ -169,6 +169,25 @@ const int16_t g_inv_quant_scales[6] = { 40,45,51,57,64,72 }; // FUNCTIONS // +/** + * \brief Get scaled QP used in quantization + * + */ +int32_t get_scaled_qp(int8_t type, int8_t qp, int8_t qp_offset) +{ + int32_t qp_scaled = 0; + if(type == 0) { + qp_scaled = qp + qp_offset; + } else { + qp_scaled = CLIP(-qp_offset, 57, qp); + if(qp_scaled < 0) { + qp_scaled = qp_scaled + qp_offset; + } else { + qp_scaled = g_chroma_scale[qp_scaled] + qp_offset; + } + } + return qp_scaled; +} /** * \brief Initialize scaling lists @@ -798,19 +817,8 @@ void quant(encoder_control *encoder, int16_t *coef, int16_t *q_coef, int32_t wid int32_t delta_u[LCU_WIDTH*LCU_WIDTH>>2]; #endif int32_t qp_base = encoder->QP; - - int32_t qp_scaled; - int32_t qp_offset = 0; - if(type == 0) { - qp_scaled = qp_base + qp_offset; - } else { - qp_scaled = CLIP(-qp_offset, 57, qp_base); - if(qp_scaled < 0) { - qp_scaled = qp_scaled + qp_offset; - } else { - qp_scaled = g_chroma_scale[qp_scaled] + qp_offset; - } - } + + int32_t qp_scaled = get_scaled_qp(type, encoder->QP, 0); //New block for variable definitions { @@ -937,19 +945,9 @@ void dequant(encoder_control *encoder, int16_t *q_coef, int16_t *coef, int32_t w int32_t shift,add,coeff_q,clip_q_coef; int32_t n; int32_t transform_shift = 15 - g_bitdepth - (g_convert_to_bit[ width ] + 2); - int32_t qp_scaled; int32_t qp_base = encoder->QP; - if (type == 0) { - qp_scaled = qp_base; - } else { - qp_scaled = CLIP( 0, 57, qp_base); - if (qp_scaled < 0) { - qp_scaled = qp_scaled; - } else { - qp_scaled = g_chroma_scale[qp_scaled]; - } - } + int32_t qp_scaled = get_scaled_qp(type, encoder->QP, 0); shift = 20 - QUANT_SHIFT - transform_shift; diff --git a/src/transform.h b/src/transform.h index c4035e2e..888bf8eb 100644 --- a/src/transform.h +++ b/src/transform.h @@ -68,4 +68,6 @@ void scalinglist_destroy(); int32_t *scalinglist_get_default(uint32_t size_id, uint32_t list_id); int scalinglist_parse(FILE *fp); +int32_t get_scaled_qp(int8_t type, int8_t qp, int8_t qp_offset); + #endif