[x265] [PATCH 1 of 4] move calcSaoStatsRowCus_BeforeDblk into encode loop

Min Chen chenm003 at 163.com
Sat Jun 21 01:41:38 CEST 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1403307644 25200
# Node ID 3d5d76ef6559d1d5ffea529f51f1995f8c3facdc
# Parent  c2ebebb66bf4fd92c83288e821e98a24a4ba2610
move calcSaoStatsRowCus_BeforeDblk into encode loop

diff -r c2ebebb66bf4 -r 3d5d76ef6559 source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	Fri Jun 20 16:40:44 2014 -0700
@@ -813,6 +813,309 @@
     }
 }
 
+void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk(TComPic* pic, int idxX, int idxY)
+{
+    int addr;
+    int x, y;
+
+    pixel* fenc;
+    pixel* pRec;
+    int stride;
+    int lcuHeight;
+    int lcuWidth;
+    uint32_t rPelX;
+    uint32_t bPelY;
+    int64_t* stats;
+    int64_t* count;
+    int classIdx;
+    int picWidthTmp = 0;
+    int picHeightTmp = 0;
+    int startX;
+    int startY;
+    int endX;
+    int endY;
+    int firstX, firstY;
+
+    int frameWidthInCU  = m_numCuInWidth;
+
+    int isChroma;
+    int numSkipLine, numSkipLineRight;
+
+    uint32_t lPelX, tPelY;
+    TComDataCU *pTmpCu;
+    pixel* pTableBo;
+    int32_t *tmp_swap;
+
+    // NOTE: Row
+    {
+        // NOTE: Col
+        {
+            lcuHeight = g_maxCUSize;
+            lcuWidth  = g_maxCUSize;
+            addr     = idxX  + frameWidthInCU * idxY;
+            pTmpCu = pic->getCU(addr);
+            lPelX   = pTmpCu->getCUPelX();
+            tPelY   = pTmpCu->getCUPelY();
+
+            memset(m_countPreDblk[addr], 0, 3 * MAX_NUM_SAO_TYPE * MAX_NUM_SAO_CLASS * sizeof(int64_t));
+            memset(m_offsetOrgPreDblk[addr], 0, 3 * MAX_NUM_SAO_TYPE * MAX_NUM_SAO_CLASS * sizeof(int64_t));
+            for (int yCbCr = 0; yCbCr < 3; yCbCr++)
+            {
+                isChroma = (yCbCr != 0) ? 1 : 0;
+
+                if (yCbCr == 0)
+                {
+                    picWidthTmp  = m_picWidth;
+                    picHeightTmp = m_picHeight;
+                }
+                else if (yCbCr == 1)
+                {
+                    picWidthTmp  = m_picWidth  >> isChroma;
+                    picHeightTmp = m_picHeight >> isChroma;
+                    lcuWidth     = lcuWidth    >> isChroma;
+                    lcuHeight    = lcuHeight   >> isChroma;
+                    lPelX       = lPelX      >> isChroma;
+                    tPelY       = tPelY      >> isChroma;
+                }
+                rPelX       = lPelX + lcuWidth;
+                bPelY       = tPelY + lcuHeight;
+                rPelX       = rPelX > picWidthTmp  ? picWidthTmp  : rPelX;
+                bPelY       = bPelY > picHeightTmp ? picHeightTmp : bPelY;
+                lcuWidth     = rPelX - lPelX;
+                lcuHeight    = bPelY - tPelY;
+
+                stride    =  (yCbCr == 0) ? pic->getStride() : pic->getCStride();
+                pTableBo = (yCbCr == 0) ? m_lumaTableBo : m_chromaTableBo;
+
+                //if(iSaoType == BO)
+
+                numSkipLine = isChroma ? 1 : 3;
+                numSkipLineRight = isChroma ? 2 : 4;
+
+                stats = m_offsetOrgPreDblk[addr][yCbCr][SAO_BO];
+                count = m_countPreDblk[addr][yCbCr][SAO_BO];
+
+                fenc = getPicYuvAddr(pic->getPicYuvOrg(), yCbCr, addr);
+                pRec = getPicYuvAddr(pic->getPicYuvRec(), yCbCr, addr);
+
+                startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth - numSkipLineRight;
+                startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight - numSkipLine;
+
+                for (y = 0; y < lcuHeight; y++)
+                {
+                    for (x = 0; x < lcuWidth; x++)
+                    {
+                        if (x < startX && y < startY)
+                            continue;
+
+                        classIdx = pTableBo[pRec[x]];
+                        if (classIdx)
+                        {
+                            stats[classIdx] += (fenc[x] - pRec[x]);
+                            count[classIdx]++;
+                        }
+                    }
+
+                    fenc += stride;
+                    pRec += stride;
+                }
+
+                int signLeft;
+                int signRight;
+                int signDown;
+                int signDown1;
+                int signDown2;
+
+                uint32_t uiEdgeType;
+
+                //if (iSaoType == EO_0)
+
+                numSkipLine = isChroma ? 1 : 3;
+                numSkipLineRight = isChroma ? 3 : 5;
+
+                stats = m_offsetOrgPreDblk[addr][yCbCr][SAO_EO_0];
+                count = m_countPreDblk[addr][yCbCr][SAO_EO_0];
+
+                fenc = getPicYuvAddr(pic->getPicYuvOrg(), yCbCr, addr);
+                pRec = getPicYuvAddr(pic->getPicYuvRec(), yCbCr, addr);
+
+                startX   = (rPelX == picWidthTmp) ? lcuWidth - 1 : lcuWidth - numSkipLineRight;
+                startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight - numSkipLine;
+                firstX   = (lPelX == 0) ? 1 : 0;
+                endX   = (rPelX == picWidthTmp) ? lcuWidth - 1 : lcuWidth;
+
+                for (y = 0; y < lcuHeight; y++)
+                {
+                    signLeft = xSign(pRec[firstX] - pRec[firstX - 1]);
+                    for (x = firstX; x < endX; x++)
+                    {
+                        signRight =  xSign(pRec[x] - pRec[x + 1]);
+                        uiEdgeType =  signRight + signLeft + 2;
+                        signLeft  = -signRight;
+
+                        if (x < startX && y < startY)
+                            continue;
+
+                        stats[m_eoTable[uiEdgeType]] += (fenc[x] - pRec[x]);
+                        count[m_eoTable[uiEdgeType]]++;
+                    }
+
+                    fenc += stride;
+                    pRec += stride;
+                }
+
+                //if (iSaoType == EO_1)
+
+                numSkipLine = isChroma ? 2 : 4;
+                numSkipLineRight = isChroma ? 2 : 4;
+
+                stats = m_offsetOrgPreDblk[addr][yCbCr][SAO_EO_1];
+                count = m_countPreDblk[addr][yCbCr][SAO_EO_1];
+
+                fenc = getPicYuvAddr(pic->getPicYuvOrg(), yCbCr, addr);
+                pRec = getPicYuvAddr(pic->getPicYuvRec(), yCbCr, addr);
+
+                startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth - numSkipLineRight;
+                startY   = (bPelY == picHeightTmp) ? lcuHeight - 1 : lcuHeight - numSkipLine;
+                firstY = (tPelY == 0) ? 1 : 0;
+                endY   = (bPelY == picHeightTmp) ? lcuHeight - 1 : lcuHeight;
+                if (firstY == 1)
+                {
+                    fenc += stride;
+                    pRec += stride;
+                }
+
+                for (x = 0; x < lcuWidth; x++)
+                {
+                    m_upBuff1[x] = xSign(pRec[x] - pRec[x - stride]);
+                }
+
+                for (y = firstY; y < endY; y++)
+                {
+                    for (x = 0; x < lcuWidth; x++)
+                    {
+                        signDown     =  xSign(pRec[x] - pRec[x + stride]);
+                        uiEdgeType    =  signDown + m_upBuff1[x] + 2;
+                        m_upBuff1[x] = -signDown;
+
+                        if (x < startX && y < startY)
+                            continue;
+
+                        stats[m_eoTable[uiEdgeType]] += (fenc[x] - pRec[x]);
+                        count[m_eoTable[uiEdgeType]]++;
+                    }
+
+                    fenc += stride;
+                    pRec += stride;
+                }
+
+                //if (iSaoType == EO_2)
+
+                numSkipLine = isChroma ? 2 : 4;
+                numSkipLineRight = isChroma ? 3 : 5;
+
+                stats = m_offsetOrgPreDblk[addr][yCbCr][SAO_EO_2];
+                count = m_countPreDblk[addr][yCbCr][SAO_EO_2];
+
+                fenc = getPicYuvAddr(pic->getPicYuvOrg(), yCbCr, addr);
+                pRec = getPicYuvAddr(pic->getPicYuvRec(), yCbCr, addr);
+
+                startX   = (rPelX == picWidthTmp) ? lcuWidth - 1 : lcuWidth - numSkipLineRight;
+                startY   = (bPelY == picHeightTmp) ? lcuHeight - 1 : lcuHeight - numSkipLine;
+                firstX   = (lPelX == 0) ? 1 : 0;
+                firstY = (tPelY == 0) ? 1 : 0;
+                endX   = (rPelX == picWidthTmp) ? lcuWidth - 1 : lcuWidth;
+                endY   = (bPelY == picHeightTmp) ? lcuHeight - 1 : lcuHeight;
+                if (firstY == 1)
+                {
+                    fenc += stride;
+                    pRec += stride;
+                }
+
+                for (x = firstX; x < endX; x++)
+                {
+                    m_upBuff1[x] = xSign(pRec[x] - pRec[x - stride - 1]);
+                }
+
+                for (y = firstY; y < endY; y++)
+                {
+                    signDown2 = xSign(pRec[stride + startX] - pRec[startX - 1]);
+                    for (x = firstX; x < endX; x++)
+                    {
+                        signDown1      =  xSign(pRec[x] - pRec[x + stride + 1]);
+                        uiEdgeType      =  signDown1 + m_upBuff1[x] + 2;
+                        m_upBufft[x + 1] = -signDown1;
+
+                        if (x < startX && y < startY)
+                            continue;
+
+                        stats[m_eoTable[uiEdgeType]] += (fenc[x] - pRec[x]);
+                        count[m_eoTable[uiEdgeType]]++;
+                    }
+
+                    m_upBufft[firstX] = signDown2;
+                    tmp_swap  = m_upBuff1;
+                    m_upBuff1 = m_upBufft;
+                    m_upBufft = tmp_swap;
+
+                    pRec += stride;
+                    fenc += stride;
+                }
+
+                //if (iSaoType == EO_3)
+
+                numSkipLine = isChroma ? 2 : 4;
+                numSkipLineRight = isChroma ? 3 : 5;
+
+                stats = m_offsetOrgPreDblk[addr][yCbCr][SAO_EO_3];
+                count = m_countPreDblk[addr][yCbCr][SAO_EO_3];
+
+                fenc = getPicYuvAddr(pic->getPicYuvOrg(), yCbCr, addr);
+                pRec = getPicYuvAddr(pic->getPicYuvRec(), yCbCr, addr);
+
+                startX   = (rPelX == picWidthTmp) ? lcuWidth - 1 : lcuWidth - numSkipLineRight;
+                startY   = (bPelY == picHeightTmp) ? lcuHeight - 1 : lcuHeight - numSkipLine;
+                firstX   = (lPelX == 0) ? 1 : 0;
+                firstY = (tPelY == 0) ? 1 : 0;
+                endX   = (rPelX == picWidthTmp) ? lcuWidth - 1 : lcuWidth;
+                endY   = (bPelY == picHeightTmp) ? lcuHeight - 1 : lcuHeight;
+                if (firstY == 1)
+                {
+                    fenc += stride;
+                    pRec += stride;
+                }
+
+                for (x = firstX - 1; x < endX; x++)
+                {
+                    m_upBuff1[x] = xSign(pRec[x] - pRec[x - stride + 1]);
+                }
+
+                for (y = firstY; y < endY; y++)
+                {
+                    for (x = firstX; x < endX; x++)
+                    {
+                        signDown1      =  xSign(pRec[x] - pRec[x + stride - 1]);
+                        uiEdgeType      =  signDown1 + m_upBuff1[x] + 2;
+                        m_upBuff1[x - 1] = -signDown1;
+
+                        if (x < startX && y < startY)
+                            continue;
+
+                        stats[m_eoTable[uiEdgeType]] += (fenc[x] - pRec[x]);
+                        count[m_eoTable[uiEdgeType]]++;
+                    }
+
+                    m_upBuff1[endX - 1] = xSign(pRec[endX - 1 + stride] - pRec[endX]);
+
+                    pRec += stride;
+                    fenc += stride;
+                }
+            }
+        }
+    }
+}
+
+
 void TEncSampleAdaptiveOffset::calcSaoStatsRowCus_BeforeDblk(TComPic* pic, int idxY)
 {
     int addr, yCbCr;
diff -r c2ebebb66bf4 -r 3d5d76ef6559 source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h	Fri Jun 20 16:40:44 2014 -0700
@@ -100,6 +100,7 @@
     void disablePartTree(SAOQTPart *psQTPart, int partIdx);
     void getSaoStats(SAOQTPart *psQTPart, int yCbCr);
     void calcSaoStatsCu(int addr, int partIdx, int yCbCr);
+    void calcSaoStatsCu_BeforeDblk(TComPic* pic, int idxX, int idxY);
     void calcSaoStatsRowCus_BeforeDblk(TComPic* pic, int idxY);
     void destroyEncBuffer();
     void createEncBuffer();
diff -r c2ebebb66bf4 -r 3d5d76ef6559 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/encoder/frameencoder.cpp	Fri Jun 20 16:40:44 2014 -0700
@@ -1065,6 +1065,18 @@
                 }
             }
         }
+
+        // NOTE: do CU level Filter
+        {
+            // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
+            if (m_param->bEnableSAO && m_param->saoLcuBasedOptimization && m_param->saoLcuBoundary)
+            {
+                // TODO: seems dead code, DEBUG IT!
+                m_frameFilter.m_sao.calcSaoStatsCu_BeforeDblk(m_pic, col, row);
+            }
+        }
+
+        // NOTE: active next row
         if (curRow.m_completed >= 2 && row < m_numRows - 1)
         {
             ScopedLock below(m_rows[row + 1].m_lock);
diff -r c2ebebb66bf4 -r 3d5d76ef6559 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/encoder/framefilter.cpp	Fri Jun 20 16:40:44 2014 -0700
@@ -142,11 +142,7 @@
     const uint32_t numCols = m_pic->getPicSym()->getFrameWidthInCU();
     const uint32_t lineStartCUAddr = row * numCols;
 
-    // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
-    if (m_param->bEnableSAO && m_param->saoLcuBasedOptimization && m_param->saoLcuBoundary)
-    {
-        m_sao.calcSaoStatsRowCus_BeforeDblk(m_pic, row);
-    }
+    // NOTE: remove m_sao.calcSaoStatsRowCus_BeforeDblk at here, we do it in encode loop now
 
     if (m_param->bEnableLoopFilter)
     {



More information about the x265-devel mailing list