[x265] [PATCH V2] rdcost: consistent clipping for chroma QP, combine conditionals

Steve Borho steve at borho.org
Tue May 5 19:13:23 CEST 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1430840579 18000
#      Tue May 05 10:42:59 2015 -0500
# Node ID f74d77615c876a3eb551196a0b30dc0e447f7be9
# Parent  d984cc4216878e9f4ccf422678afea397102981f
rdcost: consistent clipping for chroma QP, combine conditionals

This version performs the clipping to QP_MIN..QP_MAX_MAX prior to g_chromaScale
to protect the table lookup

diff -r d984cc421687 -r f74d77615c87 source/encoder/rdcost.h
--- a/source/encoder/rdcost.h	Tue May 05 11:54:26 2015 +0530
+++ b/source/encoder/rdcost.h	Tue May 05 10:42:59 2015 -0500
@@ -48,6 +48,7 @@
     {
         x265_emms(); /* TODO: if the lambda tables were ints, this would not be necessary */
         m_qp = qp;
+        setLambda(x265_lambda2_tab[qp], x265_lambda_tab[qp]);
 
         /* Scale PSY RD factor by a slice type factor */
         static const uint32_t psyScaleFix8[3] = { 300, 256, 96 }; /* B, P, I */
@@ -60,20 +61,18 @@
             m_psyRd = (m_psyRd * scale) >> 8;
         }
 
-        int qpCb, qpCr;
-        setLambda(x265_lambda2_tab[qp], x265_lambda_tab[qp]);
+        int qpCb = x265_clip3(QP_MIN, QP_MAX_MAX, qp + slice.m_pps->chromaQpOffset[0]);
+        int qpCr = x265_clip3(QP_MIN, QP_MAX_MAX, qp + slice.m_pps->chromaQpOffset[1]);
         if (slice.m_sps->chromaFormatIdc == X265_CSP_I420)
-            qpCb = x265_clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[0]]);
-        else
-            qpCb = X265_MIN(qp + slice.m_pps->chromaQpOffset[0], QP_MAX_SPEC);
+        {
+            qpCb = (int)g_chromaScale[qpCb];
+            qpCr = (int)g_chromaScale[qpCr];
+        }
+
         int chroma_offset_idx = X265_MIN(qp - qpCb + 12, MAX_CHROMA_LAMBDA_OFFSET);
         uint16_t lambdaOffset = m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
         m_chromaDistWeight[0] = lambdaOffset;
 
-        if (slice.m_sps->chromaFormatIdc == X265_CSP_I420)
-            qpCr = x265_clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice.m_pps->chromaQpOffset[1]]);
-        else
-            qpCr = X265_MIN(qp + slice.m_pps->chromaQpOffset[1], QP_MAX_SPEC);
         chroma_offset_idx = X265_MIN(qp - qpCr + 12, MAX_CHROMA_LAMBDA_OFFSET);
         lambdaOffset = m_psyRd ? x265_chroma_lambda2_offset_tab[chroma_offset_idx] : 256;
         m_chromaDistWeight[1] = lambdaOffset;


More information about the x265-devel mailing list