[x265] [PATCH] analysis:add logic for calculate qp for a given cu size

sreelakshmy at multicorewareinc.com sreelakshmy at multicorewareinc.com
Thu Mar 12 04:36:47 CET 2015


# HG changeset patch
# User Sreelakshmy V G <sreelakshmy at multicorewareinc.com>
# Date 1426131126 -19800
#      Thu Mar 12 09:02:06 2015 +0530
# Node ID c7182de7496906e81b57cb94278d60cbcc446648
# Parent  b931c50d55011a1ddc08f0a230b9632fcb4674d7
analysis:add logic for calculate qp for a given cu size

diff -r b931c50d5501 -r c7182de74969 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Wed Mar 11 21:58:02 2015 -0500
+++ b/source/encoder/analysis.cpp	Thu Mar 12 09:02:06 2015 +0530
@@ -1895,3 +1895,41 @@
 
     return false;
 }
+
+int Analysis::calculateQpforCuSize(CUData& ctu, const CUGeom& cuGeom)
+{
+    x265_emms();
+    int depth = cuGeom.depth;
+    uint32_t ctuAddr;
+    ctuAddr = ctu.m_cuAddr;
+    double qp = m_frame->m_encData->m_avgQpRc;
+
+    uint32_t width = m_frame->m_fencPic->m_picWidth;
+    uint32_t height = m_frame->m_fencPic->m_picHeight;
+    uint32_t block_x = ctu.m_cuPelX + g_zscanToPelX[cuGeom.absPartIdx];
+    uint32_t block_y = ctu.m_cuPelY + g_zscanToPelY[cuGeom.absPartIdx];
+    uint32_t maxCols = (m_frame->m_fencPic->m_picWidth + (16 - 1)) / 16;
+    uint32_t blockSize = g_maxCUSize / (uint32_t)pow(2, depth);
+    double qp_offset = 0;
+    uint32_t cnt = 0;
+    uint32_t idx;
+
+    /* Use cuTree offsets if cuTree enabled and frame is referenced, else use AQ offsets */
+    bool isReferenced = IS_REFERENCED(m_frame);
+    double *qpoffs = (isReferenced && m_param->rc.cuTree) ? m_frame->m_lowres.qpCuTreeOffset : m_frame->m_lowres.qpAqOffset;
+
+    for (uint32_t block_yy = block_y; block_yy < block_y + blockSize && block_yy < height; block_yy += 16)
+    {
+        for (uint32_t block_xx = block_x; block_xx < block_x + blockSize && block_xx < width; block_xx += 16)
+        {
+            idx = ((block_yy / 16) * (maxCols)) + (block_xx / 16);
+            qp_offset += qpoffs[idx];
+            cnt++;
+        }
+    }
+
+    qp_offset /= cnt;
+    qp += qp_offset;
+    return x265_clip3(QP_MIN, QP_MAX_MAX, (int)(qp + 0.5));
+}
+
diff -r b931c50d5501 -r c7182de74969 source/encoder/analysis.h
--- a/source/encoder/analysis.h	Wed Mar 11 21:58:02 2015 -0500
+++ b/source/encoder/analysis.h	Thu Mar 12 09:02:06 2015 +0530
@@ -139,6 +139,8 @@
     /* generate residual and recon pixels for an entire CTU recursively (RD0) */
     void encodeResidue(const CUData& parentCTU, const CUGeom& cuGeom);
 
+    int calculateQpforCuSize(CUData& ctu, const CUGeom& cuGeom);
+
     /* check whether current mode is the new best */
     inline void checkBestMode(Mode& mode, uint32_t depth)
     {


More information about the x265-devel mailing list