[x265] [PATCH] refactor: cleanup setting up of lambda

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Wed Aug 13 18:29:16 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1407925761 -19800
#      Wed Aug 13 15:59:21 2014 +0530
# Node ID 504e78b88dd7b65110b3fdb1a8c308d97ef8ea53
# Parent  4aed508841e9abfb861093420d76ff99c5487b7a
refactor: cleanup setting up of lambda

move initialising qp and lambda manipulations in one place.
remove TEncSearch::setQP - misleading function name.

diff -r 4aed508841e9 -r 504e78b88dd7 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Wed Aug 13 15:55:04 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Wed Aug 13 15:59:21 2014 +0530
@@ -127,23 +127,6 @@
     return false;
 }
 
-void TEncSearch::setQP(int qp, int qpCb, int qpCr)
-{
-    double lambda2 = x265_lambda2_tab[qp];
-    double lambdaCb = x265_lambda2_tab[qpCb];
-    double lambdaCr = x265_lambda2_tab[qpCr];
-
-    m_me.setQP(qp);
-    m_quant.setLambdas(lambda2, lambdaCb, lambdaCr);
-    m_rdCost.setLambda(lambda2, x265_lambda_tab[qp]);
-    int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
-    uint16_t lambdaOffset = m_rdCost.m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
-    m_rdCost.setCbDistortionWeight(lambdaOffset);
-    chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
-    lambdaOffset = m_rdCost.m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
-    m_rdCost.setCrDistortionWeight(lambdaOffset);
-}
-
 void TEncSearch::xEncSubdivCbfQTLuma(TComDataCU* cu, uint32_t trDepth, uint32_t absPartIdx)
 {
     uint32_t fullDepth  = cu->getDepth(0) + trDepth;
diff -r 4aed508841e9 -r 504e78b88dd7 source/Lib/TLibEncoder/TEncSearch.h
--- a/source/Lib/TLibEncoder/TEncSearch.h	Wed Aug 13 15:55:04 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.h	Wed Aug 13 15:59:21 2014 +0530
@@ -126,8 +126,6 @@
     int             m_numLayers;
     int             m_refLagPixels;
 
-    void setQP(int qp, int qpCb, int qpCr);
-
     TEncSearch();
     virtual ~TEncSearch();
 
diff -r 4aed508841e9 -r 504e78b88dd7 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Wed Aug 13 15:55:04 2014 +0530
+++ b/source/encoder/frameencoder.cpp	Wed Aug 13 15:59:21 2014 +0530
@@ -677,8 +677,8 @@
         if (m_param->rc.aqMode || bIsVbv)
         {
             int qp = calcQpForCu(cuAddr, cu->m_baseQp);
-            qp = Clip3(-QP_BD_OFFSET, MAX_QP, qp);
             setLambda(qp, tld);
+            qp = Clip3(MIN_QP, MAX_QP, qp);
             cu->setQPSubParts(char(qp), 0, 0);
             if (m_param->rc.aqMode)
                 m_frame->m_qpaAq[row] += qp;
@@ -861,11 +861,22 @@
 void FrameEncoder::setLambda(int qp, ThreadLocalData &tld)
 {
     Slice* slice = m_frame->m_picSym->m_slice;
-  
     int qpCb = Clip3(0, MAX_MAX_QP, qp + slice->m_pps->chromaCbQpOffset);
     int qpCr = Clip3(0, MAX_MAX_QP, qp + slice->m_pps->chromaCrQpOffset);
-    
-    tld.m_cuCoder.setQP(qp, qpCb, qpCr);
+    qp = Clip3(0, MAX_MAX_QP, qp);
+    double lambda2 = x265_lambda2_tab[qp];
+    double lambdaCb = x265_lambda2_tab[qpCb];
+    double lambdaCr = x265_lambda2_tab[qpCr];
+
+    tld.m_cuCoder.m_me.setQP(qp);
+    tld.m_cuCoder.m_quant.setLambdas(lambda2, lambdaCb, lambdaCr);
+    tld.m_cuCoder.m_rdCost.setLambda(lambda2, x265_lambda_tab[qp]);
+    int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
+    uint16_t lambdaOffset = tld.m_cuCoder.m_rdCost.m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
+    tld.m_cuCoder.m_rdCost.setCbDistortionWeight(lambdaOffset);
+    chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
+    lambdaOffset = tld.m_cuCoder.m_rdCost.m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
+    tld.m_cuCoder.m_rdCost.setCrDistortionWeight(lambdaOffset);
 }
 
 /* DCT-domain noise reduction / adaptive deadzone from libavcodec */


More information about the x265-devel mailing list