[x265] [PATCH] Modify FrameFilter structure to support multiple color space formats

ashok at multicorewareinc.com ashok at multicorewareinc.com
Fri Jan 3 13:46:54 CET 2014


# HG changeset patch
# User ashok at multicorewareinc.com
# Date 1388753178 -19800
#      Fri Jan 03 18:16:18 2014 +0530
# Node ID f83443bbae4d5b0e98bc85e011d8a4f4fe0bce95
# Parent  019ad3c515b3219497dfa51bd8f8c3a709b7ec5d
Modify FrameFilter structure to support multiple color space formats

diff -r 019ad3c515b3 -r f83443bbae4d source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Jan 03 18:14:34 2014 +0530
+++ b/source/encoder/encoder.cpp	Fri Jan 03 18:16:18 2014 +0530
@@ -1288,6 +1288,8 @@
         bEnableRDOQTS = 0;
     }
 
+    m_csp = _param->internalCsp;
+
     //====== Coding Tools ========
 
     uint32_t tuQTMaxLog2Size = g_convertToBit[_param->maxCUSize] + 2 - 1;
diff -r 019ad3c515b3 -r f83443bbae4d source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Jan 03 18:14:34 2014 +0530
+++ b/source/encoder/frameencoder.cpp	Fri Jan 03 18:16:18 2014 +0530
@@ -330,11 +330,11 @@
     // instead we weight the distortion of chroma.
     int chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
     int qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double cbWeight = pow(2.0, (qp - g_chromaScale[qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double cbWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
 
     chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
     qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double crWeight = pow(2.0, (qp - g_chromaScale[qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double crWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
     double chromaLambda = lambda / crWeight;
 
     m_rows[row].m_search.setQPLambda(qp, lambda, chromaLambda);
@@ -371,10 +371,10 @@
     int qpc;
     int chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
     qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double cbWeight = pow(2.0, (qp - g_chromaScale[qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double cbWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
     chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
     qpc = Clip3(0, 70, qp + chromaQPOffset);
-    double crWeight = pow(2.0, (qp - g_chromaScale[qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
+    double crWeight = pow(2.0, (qp - g_chromaScale[slice->getSPS()->getChromaFormatIdc()][qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
     double chromaLambda = lambda / crWeight;
 
     TComPicYuv *fenc = slice->getPic()->getPicYuvOrg();
diff -r 019ad3c515b3 -r f83443bbae4d source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Fri Jan 03 18:14:34 2014 +0530
+++ b/source/encoder/framefilter.cpp	Fri Jan 03 18:16:18 2014 +0530
@@ -64,6 +64,9 @@
     m_cfg = top;
     m_numRows = numRows;
 
+    m_hChromaShift = CHROMA_H_SHIFT(m_cfg->getColorFormat());
+    m_vChromaShift = CHROMA_V_SHIFT(m_cfg->getColorFormat());
+
     // NOTE: for sao only, I write this code because I want to exact match with HM's bug bitstream
     m_rdGoOnSbacCoderRow0 = rdGoOnSbacCoder;
 
@@ -77,7 +80,7 @@
         m_sao.setSaoLcuBoundary(top->param.saoLcuBoundary);
         m_sao.setSaoLcuBasedOptimization(top->param.saoLcuBasedOptimization);
         m_sao.setMaxNumOffsetsPerPic(top->getMaxNumOffsetsPerPic());
-        m_sao.create(top->param.sourceWidth, top->param.sourceHeight, g_maxCUWidth, g_maxCUHeight);
+        m_sao.create(top->param.sourceWidth, top->param.sourceHeight, g_maxCUWidth, g_maxCUHeight, m_cfg->getColorFormat());
         m_sao.createEncBuffer();
     }
 
@@ -222,8 +225,8 @@
 
     // Border extend Left and Right
     primitives.extendRowBorder(recon->getLumaAddr(lineStartCUAddr), recon->getStride(), recon->getWidth(), realH, recon->getLumaMarginX());
-    primitives.extendRowBorder(recon->getCbAddr(lineStartCUAddr), recon->getCStride(), recon->getWidth() >> 1, realH >> 1, recon->getChromaMarginX());
-    primitives.extendRowBorder(recon->getCrAddr(lineStartCUAddr), recon->getCStride(), recon->getWidth() >> 1, realH >> 1, recon->getChromaMarginX());
+    primitives.extendRowBorder(recon->getCbAddr(lineStartCUAddr), recon->getCStride(), recon->getWidth() >> m_hChromaShift, realH >> m_vChromaShift, recon->getChromaMarginX());
+    primitives.extendRowBorder(recon->getCrAddr(lineStartCUAddr), recon->getCStride(), recon->getWidth() >> m_hChromaShift, realH >> m_vChromaShift, recon->getChromaMarginX());
 
     // Border extend Top
     if (row == 0)
@@ -252,8 +255,8 @@
         const intptr_t stride = recon->getStride();
         const intptr_t strideC = recon->getCStride();
         pixel *pixY = recon->getLumaAddr(lineStartCUAddr) - recon->getLumaMarginX() + (realH - 1) * stride;
-        pixel *pixU = recon->getCbAddr(lineStartCUAddr) - recon->getChromaMarginX() + ((realH >> 1) - 1) * strideC;
-        pixel *pixV = recon->getCrAddr(lineStartCUAddr) - recon->getChromaMarginX() + ((realH >> 1) - 1) * strideC;
+        pixel *pixU = recon->getCbAddr(lineStartCUAddr) - recon->getChromaMarginX() + ((realH >> m_vChromaShift) - 1) * strideC;
+        pixel *pixV = recon->getCrAddr(lineStartCUAddr) - recon->getChromaMarginX() + ((realH >> m_vChromaShift) - 1) * strideC;
 
         for (int y = 0; y < recon->getLumaMarginY(); y++)
         {
@@ -290,8 +293,8 @@
 
         uint64_t ssdY = computeSSD(orig->getLumaAddr(cuAddr), recon->getLumaAddr(cuAddr), stride, width, height);
 
-        height >>= 1;
-        width  >>= 1;
+        height >>= m_vChromaShift;
+        width  >>= m_hChromaShift;
         stride = recon->getCStride();
 
         uint64_t ssdU = computeSSD(orig->getCbAddr(cuAddr), recon->getCbAddr(cuAddr), stride, width, height);
@@ -337,8 +340,8 @@
 
         updateMD5Plane(m_pic->m_state[0], recon->getLumaAddr(cuAddr), width, height, stride);
 
-        width >>= 1;
-        height >>= 1;
+        width  >>= m_hChromaShift;
+        height >>= m_vChromaShift;
         stride = recon->getCStride();
 
         updateMD5Plane(m_pic->m_state[1], recon->getCbAddr(cuAddr), width, height, stride);
@@ -356,8 +359,8 @@
         }
         updateCRC(recon->getLumaAddr(cuAddr), m_pic->m_crc[0], height, width, stride);
 
-        width >>= 1;
-        height >>= 1;
+        width  >>= m_hChromaShift;
+        height >>= m_vChromaShift;
         stride = recon->getCStride();
 
         updateCRC(recon->getCbAddr(cuAddr), m_pic->m_crc[1], height, width, stride);
@@ -374,10 +377,10 @@
             m_pic->m_checksum[0] = m_pic->m_checksum[1] = m_pic->m_checksum[2] = 0;
         }
         updateChecksum(recon->getLumaAddr(), m_pic->m_checksum[0], height, width, stride, row, cuHeight);
-        width >>= 1;
-        height >>= 1;
+        width  >>= m_hChromaShift;
+        height >>= m_vChromaShift;
         stride = recon->getCStride();
-        cuHeight >>= 1;
+        cuHeight >>= m_vChromaShift;
         updateChecksum(recon->getCbAddr(), m_pic->m_checksum[1], height, width, stride, row, cuHeight);
         updateChecksum(recon->getCrAddr(), m_pic->m_checksum[2], height, width, stride, row, cuHeight);
     }
diff -r 019ad3c515b3 -r f83443bbae4d source/encoder/framefilter.h
--- a/source/encoder/framefilter.h	Fri Jan 03 18:14:34 2014 +0530
+++ b/source/encoder/framefilter.h	Fri Jan 03 18:16:18 2014 +0530
@@ -59,6 +59,9 @@
     TEncCfg*                    m_cfg;
     TComPic*                    m_pic;
 
+    int                         m_hChromaShift;
+    int                         m_vChromaShift;
+
 public:
 
     TComLoopFilter              m_loopFilter;


More information about the x265-devel mailing list