Index: branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1144)
+++ branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1152)
@@ -2322,7 +2322,9 @@
     Int iPictureWidth  = depthPicYuv->getWidth();
     Int iPictureHeight = depthPicYuv->getHeight();
-    
+ 
+#if !HS_DBBP_CLEAN_K0048
     Int iWidth  = uiWidth;
     Int iHeight = uiHeight;
+#endif
     
     Bool depthRefineFlag = false;
@@ -2337,6 +2339,11 @@
     }
     
+#if HS_DBBP_CLEAN_K0048
+    Int depthPosX = Clip3(0,   iPictureWidth - 1,  iBlkX + ((cDv.getHor()+2)>>2));
+    Int depthPosY = Clip3(0,   iPictureHeight - 1, iBlkY + ((cDv.getVer()+2)>>2));
+#else
     Int depthPosX = Clip3(0,   iPictureWidth - iWidth,  iBlkX + ((cDv.getHor()+2)>>2));
     Int depthPosY = Clip3(0,   iPictureHeight- iHeight, iBlkY + ((cDv.getVer()+2)>>2));
+#endif
     
     pDepthPels = depthPicYuv->getLumaAddr() + depthPosX + depthPosY * uiDepthStride;
Index: branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1144)
+++ branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1152)
@@ -630,24 +630,62 @@
 
 #if H_3D_DBBP
+#if HS_DBBP_CLEAN_K0048
+PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU)
+#else
 PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize)
+#endif
 {
   // find virtual partitioning for this CU based on depth block
   // segmentation of texture block --> mask IDs
-  Pel*  pDepthBlockStart      = pDepthPels;
+  Pel*  pDepthBlockStart    = pDepthPels;
   
   // first compute average of depth block for thresholding
   Int iSumDepth = 0;
   Int iSubSample = 4;
+#if HS_DBBP_CLEAN_K0048
+  Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth();
+  Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight();
+  TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag(  ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV;
+  if( pcCU->getSlice()->getDepthRefinementFlag(  ) )
+  {
+    cDv.setVer(0);
+  }
+  Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2);
+  Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2);
+  UInt t=0;
+
   for (Int y=0; y<uiSize; y+=iSubSample)
-  {
+   {
     for (Int x=0; x<uiSize; x+=iSubSample)
-    {
-      Int depthPel = pDepthPels[x];
-      
-      iSumDepth += depthPel;
-    }
+   {
+if (iBlkX+x>iPictureWidth)
+{
+    Int depthPel = pDepthPels[t];
+    iSumDepth += depthPel;
+} 
+else
+{
+    Int depthPel = pDepthPels[x];
+    t=x;
+    iSumDepth += depthPel;
+}
+   }
     
     // next row
+    if (!(iBlkY+y+4>iPictureHeight))
     pDepthPels += uiDepthStride*iSubSample;
+#else
+  for (Int y=0; y<uiSize; y+=iSubSample)
+  {
+     for (Int x=0; x<uiSize; x+=iSubSample)
+        {
+                  Int depthPel = pDepthPels[x];
+
+                  iSumDepth += depthPel;
+        }
+
+          // next row
+          pDepthPels += uiDepthStride*iSubSample;
+#endif
   }
   
@@ -667,5 +705,18 @@
     for (Int x=0; x<uiSize; x+=iSubSample)
     {
-      Int depthPel = pDepthPels[x];
+#if HS_DBBP_CLEAN_K0048
+      Int depthPel = 0;
+if (iBlkX+x>iPictureWidth)
+{
+    depthPel = pDepthPels[t];
+}
+else
+{ 
+    depthPel = pDepthPels[x];
+     t=x;
+}
+#else
+            Int depthPel = pDepthPels[x];
+#endif
       
       // decide which segment this pixel belongs to
@@ -696,4 +747,7 @@
     
     // next row
+#if HS_DBBP_CLEAN_K0048
+    if (!(iBlkY+y+4>iPictureHeight))
+#endif
     pDepthPels += uiDepthStride*iSubSample;
   }
@@ -719,5 +773,9 @@
 }
 
-Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask )
+#if HS_DBBP_CLEAN_K0048
+Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU)
+#else
+Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask)
+#endif
 {
   // segmentation of texture block --> mask IDs
@@ -728,5 +786,67 @@
   Int uiMinDepth = MAX_INT;
   Int uiMaxDepth = 0;
-
+#if HS_DBBP_CLEAN_K0048
+  uiMinDepth = pDepthPels[ 0 ];
+  uiMaxDepth = pDepthPels[ 0 ];
+  iSumDepth  = pDepthPels[ 0 ];
+    UInt t=0;
+  Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth();
+  Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight();  
+  TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag(  ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV;
+  if( pcCU->getSlice()->getDepthRefinementFlag(  ) )
+  {
+      cDv.setVer(0);
+  }
+  Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2);
+  Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2);
+if (iBlkX>(Int)(iPictureWidth - uiWidth))
+{
+  iSumDepth += pDepthPels[ iPictureWidth - iBlkX - 1 ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]);
+}
+else
+{
+  iSumDepth += pDepthPels[ uiWidth - 1 ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiWidth - 1 ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiWidth - 1 ]);
+}
+if (iBlkY>(Int)(iPictureHeight - uiHeight))
+{
+  iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]);
+}
+else
+{
+  iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]);
+}
+if (iBlkY>(Int)(iPictureHeight - uiHeight) && iBlkX>(Int)(iPictureWidth - uiWidth))
+{
+  iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]);
+}
+else if (iBlkY>(Int)(iPictureHeight - uiHeight))
+{
+  iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]);
+}
+else if (iBlkX>(Int)(iPictureWidth - uiWidth))
+{
+  iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]);
+}
+else
+{
+  iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ];
+  uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]);
+  uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]);
+}
+#else
   iSumDepth  = pDepthPels[ 0 ];
   iSumDepth += pDepthPels[ uiWidth - 1 ];
@@ -743,5 +863,5 @@
   uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]);
   uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]);
-
+#endif
   
   // don't generate mask for blocks with small depth range (encoder decision)
@@ -765,5 +885,18 @@
     for (Int x=0; x<uiHeight; x++)
     {
+#if HS_DBBP_CLEAN_K0048
+      Int depthPel = 0;
+      if (iBlkX+x>iPictureWidth)
+      {
+        depthPel = pDepthPels[t];
+      }
+      else
+      {
+        depthPel = pDepthPels[x];
+         t=x;
+      }
+#else
       Int depthPel = pDepthPels[x];
+#endif
       
       // decide which segment this pixel belongs to
@@ -783,4 +916,7 @@
     
     // next row
+#if HS_DBBP_CLEAN_K0048
+    if (!(iBlkY+y+1>iPictureHeight))
+#endif
     pDepthPels += uiDepthStride;
     pMask += MAX_CU_SIZE;
Index: branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComPrediction.h	(revision 1144)
+++ branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TComPrediction.h	(revision 1152)
@@ -175,6 +175,11 @@
   
 #if H_3D_DBBP
+#if HS_DBBP_CLEAN_K0048
+  PartSize      getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU);
+  Bool          getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU);
+#else
   PartSize      getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize);
   Bool          getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask );
+#endif
   Void          combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize );
 #endif
Index: branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TypeDef.h	(revision 1144)
+++ branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibCommon/TypeDef.h	(revision 1152)
@@ -265,4 +265,5 @@
                                               // SEC_DBBP_DMM4_THRESHOLD_I0076     Simplification of threshold derivation for DBBP and DMM4, JCT3V-I0076
                                               // SEC_DBBP_VIEW_REF_CHECK_J0037     1   // Signaling dbbp_flag when the current slice has view reference picture(s), JCT3V-J0037 item4
+#define HS_DBBP_CLEAN_K0048     1 
 
 #define H_3D_DDD                          1   // Disparity derived depth coding
Index: branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1144)
+++ branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1152)
@@ -835,5 +835,9 @@
   // compute mask by segmenting depth block
   Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
+#if HS_DBBP_CLEAN_K0048
+  Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask, pcCU);
+#else
   Bool bValidMask = m_pcPrediction->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, pcCU->getWidth(0), pcCU->getHeight(0), pMask);
+#endif
   AOF(bValidMask);
   
Index: branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1144)
+++ branches/HTM-13.1-dev2-HiSilicon/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1152)
@@ -2522,5 +2522,11 @@
   AOF( uiDepthStride != 0 );
   
+#if HS_DBBP_CLEAN_K0048
+  PartSize eVirtualPartSize = m_pcPredSearch->getPartitionSizeFromDepth(pDepthPels, uiDepthStride, uiWidth, rpcTempCU);
+
   // derive partitioning from depth
+  Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
+  Bool bValidMask = m_pcPredSearch->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, uiWidth, uiHeight, pMask, rpcTempCU);
+#else
   PartSize eVirtualPartSize = m_pcPredSearch->getPartitionSizeFromDepth(pDepthPels, uiDepthStride, uiWidth);
   
@@ -2528,4 +2534,5 @@
   Bool pMask[MAX_CU_SIZE*MAX_CU_SIZE];
   Bool bValidMask = m_pcPredSearch->getSegmentMaskFromDepth(pDepthPels, uiDepthStride, uiWidth, uiHeight, pMask);
+#endif
   
   if( !bValidMask )
