Index: /branches/HTM-5.1-dev3-MERL/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/App/TAppDecoder/TAppDecTop.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/App/TAppDecoder/TAppDecTop.cpp	(revision 231)
@@ -764,3 +764,19 @@
 #endif
 }
+
+#if MERL_VSP_C0152
+Void TAppDecTop::setBWVSPLUT(TComSlice* pcSlice,  Int iCodedViewIdx,  Int iCurPoc)
+{
+  //first view does not have VSP 
+  if((iCodedViewIdx == 0)) return;
+
+  AOT( iCodedViewIdx <= 0);
+  //AOT( iCodedViewIdx >= m_iNumberOfViews );
+  Int iNeighborViewId = 0;
+  //  Int* piShiftLUT = bRenderFromLeft ? m_cCamParsCollector.getBaseViewShiftLUTI()[iCodedViewIdx][iNeighborViewId][0] : m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
+  Int* piShiftLUT = m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
+  pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT );
+}
+#endif
+
 //! \}
Index: /branches/HTM-5.1-dev3-MERL/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/App/TAppDecoder/TAppDecTop.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/App/TAppDecoder/TAppDecTop.h	(revision 231)
@@ -112,4 +112,8 @@
 #endif
 
+#if MERL_VSP_C0152
+  Void  setBWVSPLUT( TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc   );
+#endif
+
 protected:
 //  Void  xCreateDecLib     (); ///< create internal classes
Index: /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 231)
@@ -220,25 +220,25 @@
   
   /* File, I/O and source parameters */
-  ("InputFile_%d,i_%d",       m_pchInputFileList,       (char *) 0 , MAX_VIEW_NUM , "original Yuv input file name %d")
-  ("DepthInputFile_%d,di_%d", m_pchDepthInputFileList,  (char *) 0 , MAX_VIEW_NUM , "original Yuv depth input file name %d")
-  ("ReconFile_%d,o_%d",       m_pchReconFileList,       (char *) 0 , MAX_VIEW_NUM , "reconstructed Yuv output file name %d")
-  ("DepthReconFile_%d,do_%d", m_pchDepthReconFileList,  (char *) 0 , MAX_VIEW_NUM , "reconstructed Yuv depth output file name %d")
-  ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream output file name")
-  ("CodeDepthMaps",         m_bUsingDepthMaps, false, "Encode depth maps" )
-  ("CodedCamParsPrecision", m_iCodedCamParPrecision, STD_CAM_PARAMETERS_PRECISION, "precision for coding of camera parameters (in units of 2^(-x) luma samples)" )
-  ("LambdaModifier0,-LM0", m_adLambdaModifier[ 0 ], ( double )1.0, "Lambda modifier for temporal layer 0")
-  ("LambdaModifier1,-LM1", m_adLambdaModifier[ 1 ], ( double )1.0, "Lambda modifier for temporal layer 1")
-  ("LambdaModifier2,-LM2", m_adLambdaModifier[ 2 ], ( double )1.0, "Lambda modifier for temporal layer 2")
-  ("LambdaModifier3,-LM3", m_adLambdaModifier[ 3 ], ( double )1.0, "Lambda modifier for temporal layer 3")
-  ("SourceWidth,-wdt",      m_iSourceWidth,  0, "Source picture width")
-  ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
+  ("InputFile_%d,i_%d",       m_pchInputFileList,       (char *) 0 , MAX_VIEW_NUM ,   "original Yuv input file name %d")
+  ("DepthInputFile_%d,di_%d", m_pchDepthInputFileList,  (char *) 0 , MAX_VIEW_NUM ,   "original Yuv depth input file name %d")
+  ("ReconFile_%d,o_%d",       m_pchReconFileList,       (char *) 0 , MAX_VIEW_NUM ,   "reconstructed Yuv output file name %d")
+  ("DepthReconFile_%d,do_%d", m_pchDepthReconFileList,  (char *) 0 , MAX_VIEW_NUM ,   "reconstructed Yuv depth output file name %d")
+  ("BitstreamFile,b",         cfg_BitstreamFile,        string(""),                   "bitstream output file name")
+  ("CodeDepthMaps",           m_bUsingDepthMaps,        false,                        "Encode depth maps" )
+  ("CodedCamParsPrecision",   m_iCodedCamParPrecision,  STD_CAM_PARAMETERS_PRECISION, "precision for coding of camera parameters (in units of 2^(-x) luma samples)" )
+  ("LambdaModifier0,-LM0",    m_adLambdaModifier[ 0 ],  ( double )1.0,                "Lambda modifier for temporal layer 0")
+  ("LambdaModifier1,-LM1",    m_adLambdaModifier[ 1 ],  ( double )1.0,                "Lambda modifier for temporal layer 1")
+  ("LambdaModifier2,-LM2",    m_adLambdaModifier[ 2 ],  ( double )1.0,                "Lambda modifier for temporal layer 2")
+  ("LambdaModifier3,-LM3",    m_adLambdaModifier[ 3 ],  ( double )1.0,                "Lambda modifier for temporal layer 3")
+  ("SourceWidth,-wdt",        m_iSourceWidth,           0,                            "Source picture width")
+  ("SourceHeight,-hgt",       m_iSourceHeight,          0,                            "Source picture height")
 #if PIC_CROPPING
-  ("CroppingMode",          m_croppingMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
-  ("CropLeft",              m_cropLeft,      0, "Left cropping/padding for cropping mode 3")
-  ("CropRight",             m_cropRight,     0, "Right cropping/padding for cropping mode 3")
-  ("CropTop",               m_cropTop,       0, "Top cropping/padding for cropping mode 3")
-  ("CropBottom",            m_cropBottom,    0, "Bottom cropping/padding for cropping mode 3")
-  ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding for cropping mode 2")
-  ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding for cropping mode 2")
+  ("CroppingMode",            m_croppingMode,           0,                            "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+  ("CropLeft",                m_cropLeft,               0,                            "Left cropping/padding for cropping mode 3")
+  ("CropRight",               m_cropRight,              0,                            "Right cropping/padding for cropping mode 3")
+  ("CropTop",                 m_cropTop,                0,                            "Top cropping/padding for cropping mode 3")
+  ("CropBottom",              m_cropBottom,             0,                            "Bottom cropping/padding for cropping mode 3")
+  ("HorizontalPadding,-pdx",  m_aiPad[0],               0,                            "horizontal source padding for cropping mode 2")
+  ("VerticalPadding,-pdy",    m_aiPad[1],               0,                            "vertical source padding for cropping mode 2")
 #endif
   ("InputBitDepth",         m_uiInputBitDepth, 8u, "bit-depth of input file")
@@ -254,5 +254,5 @@
   ("FrameSkip,-fs",         m_FrameSkip,         0u, "Number of frames to skip at start of input YUV")
   ("FramesToBeEncoded,f",   m_iFrameToBeEncoded, 0, "number of frames to be encoded (default=all)")
-  ("FrameToBeEncoded",        m_iFrameToBeEncoded, 0, "deprecated alias of FramesToBeEncoded")
+  ("FrameToBeEncoded",      m_iFrameToBeEncoded, 0, "deprecated alias of FramesToBeEncoded")
   
   ("NumberOfViews",         m_iNumberOfViews,    0, "Number of views")
Index: /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncTop.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncTop.cpp	(revision 231)
@@ -793,5 +793,4 @@
   m_cUsedPelsRenderer.init(m_iSourceWidth, m_iSourceHeight, true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
 #endif
-
 }
 
@@ -931,5 +930,5 @@
   TComPicYuv*       pcPicYuvRec = NULL;
   TComPicYuv*       pcDepthPicYuvRec = NULL;
-  
+
   // initialize internal class & member variables
   xInitLibCfg();
@@ -1033,5 +1032,5 @@
       if ( iNextPoc < m_iFrameToBeEncoded )
       {
-      m_cCameraData.update( iNextPoc );
+        m_cCameraData.update( iNextPoc );
       }
 #endif
@@ -1096,4 +1095,17 @@
 #endif
         iNumEncoded = 0;
+
+#if MERL_VSP_C0152
+        Int iCurPoc = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
+        if( iCurPoc < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
+        {
+          TComPic* pcBaseTxtPic   = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), false ); //get base view reconstructed texture
+          TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), true );  //get base view reconstructed depth
+          TEncSlice* pEncSlice = m_acTEncTopList[iViewIdx]->getSliceEncoder();
+          pEncSlice->setRefPicBaseTxt(pcBaseTxtPic);
+          pEncSlice->setRefPicBaseDepth(pcBaseDepthPic);
+        }
+        setBWVSPLUT( iViewIdx, gopId, false);
+#endif
         // call encoding function for one frame
         m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
@@ -1103,4 +1115,15 @@
         {
           Int  iNumDepthEncoded = 0;
+#if MERL_VSP_C0152
+        Int iCurPocDepth = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
+        if( iCurPocDepth < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
+        {
+          TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), true );
+          TEncSlice* pcSlice = (TEncSlice*) m_acTEncDepthTopList[iViewIdx]->getSliceEncoder();
+          pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
+        }
+        setBWVSPLUT( iViewIdx, gopId, true);
+#endif
+
           // call encoding function for one depth frame
           m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
@@ -1634,3 +1657,30 @@
 #endif
 
+#if MERL_VSP_C0152
+Void TAppEncTop::setBWVSPLUT(Int iCodedViewIdx, Int gopId, Bool isDepth)
+{
+  //first view does not have VSP 
+  if((iCodedViewIdx == 0)) return;
+
+  AOT( iCodedViewIdx <= 0);
+  AOT( iCodedViewIdx >= m_iNumberOfViews );
+
+  Int iNeighborViewId = 0;
+  //setting look-up table
+  Int* piShiftLUT = m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0];
+
+  if(isDepth)
+  {
+    TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncDepthTopList[iCodedViewIdx]->getSliceEncoder();
+    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
+  }
+  else
+  {
+    TEncSlice* pcEncSlice = (TEncSlice*) m_acTEncTopList[iCodedViewIdx]->getSliceEncoder();
+    pcEncSlice->setBWVSPLUTParam(  piShiftLUT, LOG2_DISP_PREC_LUT );
+  }
+
+}
+#endif
+
 //! \}
Index: /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncTop.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/App/TAppEncoder/TAppEncTop.h	(revision 231)
@@ -99,4 +99,5 @@
   TRenTop  m_cUsedPelsRenderer;                               ///< renderer for used pels map
 #endif
+
 protected:
   // initialization
@@ -165,4 +166,7 @@
 #endif
 
+#if MERL_VSP_C0152
+  Void setBWVSPLUT( Int iCodedViewIdx, Int gopId, Bool isDepth);
+#endif
 };// END CLASS DEFINITION TAppEncTop
 
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TAppCommon/TAppComCamPara.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 231)
@@ -89,5 +89,4 @@
 }
 
-
 Void
 TAppComCamPara::xCreate2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray )
@@ -928,5 +927,4 @@
 }
 
-
 Void
 TAppComCamPara::xSetShiftParametersAndLUT( UInt uiFrame )
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TAppCommon/TAppComCamPara.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TAppCommon/TAppComCamPara.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TAppCommon/TAppComCamPara.h	(revision 231)
@@ -107,5 +107,4 @@
   Int****             m_aiSynthViewShiftLUT;                   ///< Disparity LUT
 
-
 protected:
   // create and delete arrays
@@ -143,5 +142,4 @@
   Void  xSetShiftParametersAndLUT ( UInt uiNumViewDim1, UInt uiNumViewDim2, UInt uiFrame, Bool bExternalReference, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams );
   Void  xSetShiftParametersAndLUT ( UInt uiFrame );
-
 
   // getting conversion parameters for disparity to virtual depth conversion
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDataCU.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDataCU.cpp	(revision 231)
@@ -51,4 +51,73 @@
 #endif
 
+#if MERL_VSP_C0152
+
+#define CHECK_ADD_YET(pcCURef,uiIdx,vspIdx) && !( (pcCURef)->getVSPIndex(uiIdx) == vspIdx && bVspMvZeroDone[vspIdx-1] )
+
+inline Void TComDataCU::xInheritVspMode( TComDataCU* pcCURef, UInt uiIdx, Bool* bVspMvZeroDone, Int iCount, Int* iVSPIndexTrue, TComMvField* pcMvFieldNeighbours, DisInfo* pDInfo )
+{
+  Int vspIdx = (Int) pcCURef->getVSPIndex(uiIdx);
+  if( vspIdx != 0 )
+  {
+    Int idx = vspIdx - 1;
+    bVspMvZeroDone[idx] = true;
+    iVSPIndexTrue [idx] = iCount;
+
+    // no need to reset Inter Dir
+
+    // set MV using checked disparity
+    if (vspIdx < 4)
+    {
+      pcMvFieldNeighbours[ iCount<<1].setMvField ( pDInfo->m_acMvCand[0],  NOT_VALID );
+      if ( pcCURef->getSlice()->isInterB() )
+      {
+         pcMvFieldNeighbours[(iCount<<1)+1 ].setMvField ( pDInfo->m_acMvCand[0],  NOT_VALID );
+      }
+    }
+  }
+}
+
+inline Bool TComDataCU::xAddVspMergeCand( UChar ucVspMergePos, Int vspIdx, Bool* bVspMvZeroDone, UInt uiDepth, Bool* abCandIsInter, Int& iCount,
+                                          UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int* iVSPIndexTrue, Int mrgCandIdx, DisInfo* pDInfo )
+{
+  if( ucVspMergePos == VSP_MERGE_POS )
+  {
+    Int idx = vspIdx - 1;
+    {
+      if( getSlice()->getSPS()->getViewId() != 0 && bVspMvZeroDone[idx] == false )
+      {
+        {
+          abCandIsInter [iCount] = true;
+          bVspMvZeroDone[idx] = true;
+
+          // get Inter Dir
+          Int iInterDir = ((getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 && getSlice()->getNumRefIdx(REF_PIC_LIST_1) > 0) ? 3 :
+            (getSlice()->getNumRefIdx(REF_PIC_LIST_0) > 0 ? 1 : 2));
+          puhInterDirNeighbours[iCount] = iInterDir; // The direction information does not matter
+          // get Mv using checked disparity vector
+          if (vspIdx < 4) // spatial
+          {
+            pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0], NOT_VALID );
+            if ( getSlice()->isInterB() )
+            {
+              pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], NOT_VALID );
+            }
+          }
+          iVSPIndexTrue[idx] = iCount;
+#if SIMP_MRG_PRUN
+          if ( mrgCandIdx == iCount )
+          {
+            return false;
+          }
+#endif
+          iCount ++;
+        }
+      }
+    }
+  }
+  return true;
+}
+#endif
+
 // ====================================================================================================================
 // Constructor / destructor / create / destroy
@@ -79,4 +148,7 @@
 #endif
   m_puhMergeIndex      = NULL;
+#if MERL_VSP_C0152
+  m_piVSPIndex         = NULL;
+#endif
   m_puhLumaIntraDir    = NULL;
   m_puhChromaIntraDir  = NULL;
@@ -213,4 +285,7 @@
 #endif
     m_puhMergeIndex      = (UChar* )xMalloc(UChar,  uiNumPartition);
+#if MERL_VSP_C0152
+    m_piVSPIndex         = (Char*  )xMalloc(Char,   uiNumPartition);
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
     m_pbResPredAvailable = (Bool*  )xMalloc(Bool,   uiNumPartition);
@@ -364,4 +439,7 @@
     if ( m_pbICFlag           ) { xFree(m_pbICFlag);            m_pbICFlag          = NULL; }
 #endif
+#if MERL_VSP_C0152
+    if ( m_piVSPIndex         ) { xFree(m_piVSPIndex);          m_piVSPIndex        = NULL; }
+#endif
     if ( m_puhMergeIndex      ) { xFree(m_puhMergeIndex);       m_puhMergeIndex     = NULL; }
 #if HHI_INTER_VIEW_RESIDUAL_PRED
@@ -558,4 +636,7 @@
 #endif
     m_puhMergeIndex[ui]=pcFrom->m_puhMergeIndex[ui];
+#if MERL_VSP_C0152
+    m_piVSPIndex[ui] = pcFrom->m_piVSPIndex[ui];
+#endif
     m_puhLumaIntraDir[ui]=pcFrom->m_puhLumaIntraDir[ui];
     m_puhChromaIntraDir[ui]=pcFrom->m_puhChromaIntraDir[ui];
@@ -598,4 +679,7 @@
 #endif
     memset( m_puhMergeIndex     + firstElement, 0,                        numElements * sizeof( *m_puhMergeIndex ) );
+#if MERL_VSP_C0152
+    memset( m_piVSPIndex        + firstElement, 0,                        numElements * sizeof( *m_piVSPIndex ) );
+#endif
     memset( m_puhLumaIntraDir   + firstElement, 2,                        numElements * sizeof( *m_puhLumaIntraDir ) );
     memset( m_puhChromaIntraDir + firstElement, 0,                        numElements * sizeof( *m_puhChromaIntraDir ) );
@@ -781,4 +865,7 @@
 #endif
       m_puhMergeIndex[ui] = 0;
+#if MERL_VSP_C0152
+      m_piVSPIndex[ui] = 0;
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
       m_pbResPredAvailable[ui] = 0;
@@ -876,4 +963,7 @@
   Int iSizeInUchar = sizeof( UChar  ) * m_uiNumPartition;
   Int iSizeInBool  = sizeof( Bool   ) * m_uiNumPartition;
+#if MERL_VSP_C0152
+  Int iSizeInChar  = sizeof( Char   ) * m_uiNumPartition;
+#endif
 
 #if H0736_AVC_STYLE_QP_RANGE
@@ -893,4 +983,7 @@
 #endif
   memset( m_puhMergeIndex,      0, iSizeInUchar );
+#if MERL_VSP_C0152
+  memset( m_piVSPIndex,         0, iSizeInChar );
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   memset( m_pbResPredAvailable, 0, iSizeInBool  );
@@ -973,4 +1066,7 @@
 #endif
       m_puhMergeIndex[ui]=pcCU->m_puhMergeIndex[uiPartOffset+ui];
+#if MERL_VSP_C0152
+      m_piVSPIndex[ui]=pcCU->m_piVSPIndex[uiPartOffset+ui];
+#endif
       m_puhLumaIntraDir[ui]=pcCU->m_puhLumaIntraDir[uiPartOffset+ui];
       m_puhChromaIntraDir[ui]=pcCU->m_puhChromaIntraDir[uiPartOffset+ui];
@@ -1117,4 +1213,7 @@
 #endif
   m_puhMergeIndex       = pcCU->getMergeIndex()       + uiPart;
+#if MERL_VSP_C0152
+  m_piVSPIndex          = pcCU->getVSPIndex()         + uiPart;
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   m_pbResPredAvailable  = pcCU->getResPredAvail()     + uiPart;
@@ -1227,5 +1326,5 @@
   m_uiCUAddr           = pcCU->getAddr();
   m_uiAbsIdxInLCU      = uiAbsPartIdx;
-  
+
   Int iRastPartIdx     = g_auiZscanToRaster[uiAbsPartIdx];
   m_uiCUPelX           = pcCU->getCUPelX() + m_pcPic->getMinCUWidth ()*( iRastPartIdx % m_pcPic->getNumPartInWidth() );
@@ -1257,4 +1356,7 @@
 #endif
   m_puhMergeIndex      = pcCU->getMergeIndex()            + uiAbsPartIdx;
+#if MERL_VSP_C0152
+  m_piVSPIndex         = pcCU->getVSPIndex()              + uiAbsPartIdx;
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   m_pbResPredAvailable = pcCU->getResPredAvail()          + uiAbsPartIdx;
@@ -1288,4 +1390,7 @@
   Int iSizeInUchar  = sizeof( UChar ) * uiNumPartition;
   Int iSizeInBool   = sizeof( Bool  ) * uiNumPartition;
+#if MERL_VSP_C0152
+  Int iSizeInChar   = sizeof( Char )  * uiNumPartition;
+#endif
   
 #if H0736_AVC_STYLE_QP_RANGE
@@ -1306,4 +1411,7 @@
 #endif
   memcpy( m_puhMergeIndex       + uiOffset, pcCU->getMergeIndex(),        iSizeInUchar );
+#if MERL_VSP_C0152
+  memcpy( m_piVSPIndex          + uiOffset, pcCU->getVSPIndex(),          iSizeInChar );
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   memcpy( m_pbResPredAvailable  + uiOffset, pcCU->getResPredAvail(),      iSizeInBool  );
@@ -1419,4 +1527,7 @@
   Int iSizeInUchar  = sizeof( UChar ) * m_uiNumPartition;
   Int iSizeInBool   = sizeof( Bool  ) * m_uiNumPartition;
+#if MERL_VSP_C0152
+  Int iSizeInChar   = sizeof( Char  ) * m_uiNumPartition;
+#endif
   
 #if H0736_AVC_STYLE_QP_RANGE
@@ -1440,4 +1551,7 @@
 #endif
   memcpy( rpcCU->getMergeIndex()        + m_uiAbsIdxInLCU, m_puhMergeIndex,       iSizeInUchar );
+#if MERL_VSP_C0152
+  memcpy( rpcCU->getVSPIndex()          + m_uiAbsIdxInLCU, m_piVSPIndex,         iSizeInChar );
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   memcpy( rpcCU->getResPredAvail()      + m_uiAbsIdxInLCU, m_pbResPredAvailable,  iSizeInBool  );
@@ -1547,4 +1661,7 @@
   Int iSizeInUchar  = sizeof( UChar  ) * uiQNumPart;
   Int iSizeInBool   = sizeof( Bool   ) * uiQNumPart;
+#if MERL_VSP_C0152
+  Int iSizeInChar   = sizeof( Char   ) * uiQNumPart;
+#endif
   
 #if H0736_AVC_STYLE_QP_RANGE
@@ -1566,4 +1683,7 @@
 #endif
   memcpy( rpcCU->getMergeIndex()        + uiPartOffset, m_puhMergeIndex,       iSizeInUchar );
+#if MERL_VSP_C0152
+  memcpy( rpcCU->getVSPIndex()          + uiPartOffset, m_piVSPIndex,         iSizeInChar );
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   memcpy( rpcCU->getResPredAvail()      + uiPartOffset, m_pbResPredAvailable,  iSizeInBool  );
@@ -3033,4 +3153,11 @@
 }
 
+#if MERL_VSP_C0152
+Void TComDataCU::setVSPIndexSubParts ( Char iVSPIdx, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  setSubPart<Char>( iVSPIdx, m_piVSPIndex, uiAbsPartIdx, uiDepth, uiPartIdx );
+}
+#endif
+
 #if HHI_INTER_VIEW_RESIDUAL_PRED
 Void TComDataCU::setResPredAvailSubParts( Bool bResPredAvailable, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
@@ -3084,7 +3211,5 @@
 
       if((getInterDir(uiPartAddr) & (uiRefIdx+1)) && iBestRefIdx >= 0 && getSlice()->getViewId() != getSlice()->getRefViewId(eRefList, iBestRefIdx))
-      {
         return true;
-      }
     }
   }
@@ -3618,5 +3743,9 @@
  */
 #if SIMP_MRG_PRUN
+#if MERL_VSP_C0152
+Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int* iVSPIndexTrue, Int mrgCandIdx )
+#else
 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx )
+#endif
 #else
 Void TComDataCU::getInterMergeCandidates( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand )
@@ -3645,4 +3774,8 @@
 #endif
 
+#if MERL_VSP_C0152
+  Bool bVspMvZeroDone[3] = {false, false, false};
+#endif
+  
   Int iCount = 0;
 
@@ -3687,6 +3820,8 @@
     getDisMvpCand2(uiPUIdx, uiAbsPartIdx, &cDisInfo
 #if LGE_IVMP_PARALLEL_MERGE_B0136==QC_SIMPLE_NBDV_B0047
-,
-true
+            , true
+#endif
+#if MERL_VSP_C0152
+            , true
 #endif
 );
@@ -3714,4 +3849,5 @@
   Int     iPdmInterDir      = getPdmMergeCandidate( uiPUIdx, aiPdmRefIdx, acPdmMv );
 #endif
+
 #if QC_MRG_CANS_B0048
   if( iPdmDir[0] && !bNoPdmMerge && PDM_MERGE_POS == 0 )
@@ -3785,4 +3921,12 @@
   }
 #endif
+
+#if MERL_VSP_COMPENSATION_C0152
+  //===== vsp 0 ===== 
+  if( iCount < 4 + extraMergeCand )
+    if ( !xAddVspMergeCand(0, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+      return;
+#endif
+
   //left
   UInt uiLeftPartIdx = 0;
@@ -3805,5 +3949,9 @@
   if (!(uiPUIdx == 1 && (partSize == SIZE_Nx2N || partSize == SIZE_nLx2N || partSize == SIZE_nRx2N)))
   {
-  if ( pcCULeft && !pcCULeft->isIntra( uiLeftPartIdx ) )
+  if ( pcCULeft && !pcCULeft->isIntra( uiLeftPartIdx )
+#if MERL_VSP_C0152
+     CHECK_ADD_YET(pcCULeft, uiLeftPartIdx, 1)
+#endif
+  )
   {
     abCandIsInter[iCount] = true;
@@ -3852,4 +4000,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if MERL_VSP_C0152
+     xInheritVspMode( pcCULeft, uiLeftPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3902,4 +4053,11 @@
     iCount ++;
   }
+#endif
+
+#if MERL_VSP_COMPENSATION_C0152
+  //===== vsp 1 =====
+  if( iCount < 4 + extraMergeCand )
+    if ( !xAddVspMergeCand(1, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+      return;
 #endif
 
@@ -3928,4 +4086,7 @@
 #if SIMP_MRG_PRUN
   if ( pcCUAbove && !pcCUAbove->isIntra( uiAbovePartIdx ) 
+#if MERL_VSP_C0152
+    CHECK_ADD_YET(pcCUAbove, uiAbovePartIdx, 1)
+#endif
     && !(uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD))
     && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
@@ -3978,4 +4139,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if MERL_VSP_C0152
+     xInheritVspMode( pcCUAbove, uiAbovePartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -4030,4 +4194,11 @@
     iCount ++;
   }
+#endif
+
+#if MERL_VSP_COMPENSATION_C0152
+  //===== vsp 2 =====
+  if( iCount < 4 + extraMergeCand )
+    if ( !xAddVspMergeCand(2, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+      return;
 #endif
 
@@ -4050,5 +4221,9 @@
 #endif
 #if SIMP_MRG_PRUN
-  if ( pcCUAboveRight && !pcCUAboveRight->isIntra( uiAboveRightPartIdx ) && ( !pcCUAbove || pcCUAbove->isIntra( uiAbovePartIdx ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
+  if ( pcCUAboveRight && !pcCUAboveRight->isIntra( uiAboveRightPartIdx ) 
+#if MERL_VSP_C0152
+    CHECK_ADD_YET(pcCUAboveRight, uiAboveRightPartIdx, 1)
+#endif
+    && ( !pcCUAbove || pcCUAbove->isIntra( uiAbovePartIdx ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
 #else
   if ( pcCUAboveRight && !pcCUAboveRight->isIntra( uiAboveRightPartIdx ) )
@@ -4074,4 +4249,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if MERL_VSP_C0152
+    xInheritVspMode( pcCUAboveRight, uiAboveRightPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -4128,5 +4306,5 @@
     {
       assert(iCount < MRG_MAX_NUM_CANDS_MEM);
-      Bool bRemoveSpa = false; //prunign to A1, B1
+      Bool bRemoveSpa = false; //pruning to A1, B1
       abCandIsInter        [ iCount ] = true;
       puhInterDirNeighbours[ iCount ] = iPdmDir[1];
@@ -4173,4 +4351,22 @@
   }
 #endif
+#if MERL_VSP_COMPENSATION_C0152
+  //===== vsp 3 =====
+  if( iCount < 4 + extraMergeCand )
+    if ( !xAddVspMergeCand(3, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+      return;
+#endif
+
+#if MERL_VSP_C0152
+#if VSP_MERGE_POS < 4
+#if HHI_INTER_VIEW_MOTION_PRED
+  if( iCount < 4 + extraMergeCand )
+#else
+  if( iCount < 4 )
+#endif
+  {
+#endif
+#endif
+
   //left bottom
   UInt uiLeftBottomPartIdx = 0;
@@ -4191,5 +4387,9 @@
 #endif
 #if SIMP_MRG_PRUN
-  if ( pcCULeftBottom && !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
+  if ( pcCULeftBottom && !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) 
+#if MERL_VSP_C0152
+    CHECK_ADD_YET(pcCULeftBottom, uiLeftBottomPartIdx, 1)
+#endif
+    && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
 #else
   if ( pcCULeftBottom && !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) )
@@ -4215,4 +4415,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if MERL_VSP_C0152
+     xInheritVspMode( pcCULeftBottom, uiLeftBottomPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -4223,5 +4426,10 @@
     iCount ++;
   }
-
+#if MERL_VSP_C0152
+#if VSP_MERGE_POS < 4
+  }
+#endif
+#endif
+  
 #if HHI_INTER_VIEW_MOTION_PRED
 #if QC_MRG_CANS_B0048
@@ -4263,5 +4471,12 @@
 #endif
 
-  // above left 
+#if MERL_VSP_COMPENSATION_C0152
+  //===== vsp 4 =====
+  if( iCount < 4 + extraMergeCand )
+    if ( !xAddVspMergeCand(4, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+      return;
+#endif
+  
+  // above left
 #if HHI_INTER_VIEW_MOTION_PRED
   if( iCount < 4 + extraMergeCand )
@@ -4288,4 +4503,7 @@
 #if SIMP_MRG_PRUN
     if( pcCUAboveLeft && !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx )
+#if MERL_VSP_C0152
+     CHECK_ADD_YET(pcCUAboveLeft, uiAboveLeftPartIdx, 1)
+#endif
      && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
      && ( !pcCUAbove || pcCUAbove->isIntra( uiAbovePartIdx ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
@@ -4314,4 +4532,7 @@
       pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if MERL_VSP_C0152
+     xInheritVspMode( pcCUAboveLeft, uiAboveLeftPartIdx, bVspMvZeroDone, iCount, iVSPIndexTrue, pcMvFieldNeighbours, &cDisInfo ) ;
+#endif
 #if SIMP_MRG_PRUN
       if ( mrgCandIdx == iCount )
@@ -4323,4 +4544,11 @@
     }
   }
+
+#if MERL_VSP_COMPENSATION_C0152
+  //===== vsp 5 =====
+  if( iCount < 4 + extraMergeCand )
+    if ( !xAddVspMergeCand(5, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+      return;
+#endif
 
   if ( getSlice()->getPPS()->getEnableTMVPFlag() 
@@ -4356,4 +4584,12 @@
     Int uiLCUIdx = getAddr();
     PartSize eCUMode = getPartitionSize( 0 );
+
+#if MERL_VSP_C0152 // Potential bug, not related to BW_VSP
+    if (eCUMode==SIZE_NxN)
+    {
+      printf("Size NxN ???");
+      assert(0);
+    }
+#endif
 
     deriveRightBottomIdx( eCUMode, uiPUIdx, uiPartIdxRB );  
@@ -4598,5 +4834,14 @@
     {
       Int i = uiPriorityList0[idx]; Int j = uiPriorityList1[idx];
-      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2))
+#if MERL_VSP_C0152
+      Bool bValid = true;
+      if (pcMvFieldNeighbours[i<<1].getRefIdx() < 0 || pcMvFieldNeighbours[(j<<1)+1].getRefIdx() < 0) // NOT_VALID
+        bValid = false;
+#endif
+      if (abCandIsInter[i] && abCandIsInter[j]&& (puhInterDirNeighbours[i]&0x1)&&(puhInterDirNeighbours[j]&0x2)
+#if MERL_VSP_C0152
+       && bValid
+#endif
+         )
       {
         abCandIsInter[uiArrayAddr] = true;
@@ -4770,5 +5015,9 @@
   if( uiIter == 0 )
   {
-    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) )
+    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) 
+#if MERL_VSP_C0152
+     && !pcCorner->getVSPIndex( uiCornerPUIdx )
+#endif
+    )
     {
       rbValidCand = true;
@@ -4805,5 +5054,9 @@
   else
   {
-    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) )
+    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) 
+#if MERL_VSP_C0152
+     && !pcCorner->getVSPIndex( uiCornerPUIdx )
+#endif
+    )
     {
       rbValidCand = true;
@@ -4954,4 +5207,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+#if MERL_VSP_C0152
+  if(! pcTmpCU->getVSPIndex(uiIdx))
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -4980,4 +5236,7 @@
 
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if MERL_VSP_C0152
+  if(! pcTmpCU->getVSPIndex(uiIdx))
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -5006,4 +5265,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+#if MERL_VSP_C0152
+  if(! pcTmpCU->getVSPIndex(uiIdx))
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -5031,4 +5293,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if MERL_VSP_C0152
+  if(! pcTmpCU->getVSPIndex(uiIdx))
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -5059,4 +5324,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if MERL_VSP_C0152
+  if(! pcTmpCU->getVSPIndex(uiIdx))
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -5257,4 +5525,56 @@
 }
 
+#if MERL_VSP_C0152
+Pel TComDataCU::getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iWidth, Int iHeight, Int* aiShiftLUT, Int iShiftPrec)
+{
+  Int depStride =  pcBaseViewDepthPicYuv->getStride();
+
+  Int width  = pcBaseViewDepthPicYuv->getWidth();
+  Int height = pcBaseViewDepthPicYuv->getHeight();
+
+  Int depthPosX = Clip3(0,   width - iWidth  - 1,  iBlkX + (mv->getHor()>>2));
+  Int depthPosY = Clip3(0,   height- iHeight - 1,  iBlkY + (mv->getVer()>>2));
+
+  Pel *depth  = pcBaseViewDepthPicYuv->getLumaAddr() + depthPosX + depthPosY * depStride;
+  Pel  maxDepth = 0;
+
+  for (Int j = 0; j < iHeight; j++)
+  {
+    for (Int i = 0; i < iWidth; i++)
+    {
+      if (maxDepth < depth[i])
+        maxDepth = depth[i];
+    }
+    depth += depStride;
+  }
+
+  Int disparity = aiShiftLUT[ maxDepth ] << iShiftPrec;
+
+  return disparity;
+}
+
+Void TComDataCU::estimateDVFromDM(UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred)
+{
+  if (picDepth)
+  {
+    UInt uiAbsPartAddrCurrCU = m_uiAbsIdxInLCU + uiPartAddr;
+    Int iWidth, iHeight;
+    getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); // The modified value of uiPartAddr won't be used any more
+    
+    TComPicYuv* pcBaseViewDepthPicYuv = picDepth->getPicYuvRec();
+    Int iBlkX = ( getAddr() % picDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
+    Int iBlkY = ( getAddr() / picDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartAddrCurrCU ] ];
+    Int* aiShiftLUT;
+    Int  iShiftPrec;
+    getSlice()->getBWVSPLUTParam(aiShiftLUT, iShiftPrec);
+    
+    Pel x = getMcpFromDM( pcBaseViewDepthPicYuv, cMvPred, iBlkX, iBlkY, iWidth, iHeight, aiShiftLUT, iShiftPrec );
+
+    cMvPred->setHor(x);
+    clipMv(*cMvPred);
+  }
+}
+#endif
+
 #if LGE_DVMCP_A0126
 #if QC_SIMPLE_NBDV_B0047
@@ -5263,4 +5583,7 @@
                                 , Bool bParMerge
 #endif
+#if MERL_VSP_C0152
+                                , Bool bDepthRefine
+#endif
 #else
 Void TComDataCU::getDisMvpCand2( UInt uiPartIdx, UInt uiPartAddr,DisInfo* pDInfo, Bool bMerge, RefPicList eRefPicList0, Int iRefIdx0
@@ -5345,10 +5668,21 @@
       {
         Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
-        if (refViewIdx!= m_pcSlice->getViewId()) // DCP
+        if (refViewIdx != m_pcSlice->getViewId()) // DCP
         {
           TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
           clipMv(cMvPred);
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
           pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
           pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+#else
+          {
+            TComPic* picDepth = NULL;
+            picDepth = getSlice()->getRefPicBaseDepth();
+            if (picDepth && bDepthRefine)
+              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred);
+            pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          }
+#endif
           return;
         }
@@ -5364,4 +5698,19 @@
         }
       }
+#if MERL_VSP_C0152
+      else if (pcTmpCU->getVSPIndex(uiIdx) != 0) // is VSP
+      {
+        TComPic* picDepth = NULL;
+        TComMv myMv = pcTmpCU->getCUMvField( eRefPicList )->getMv( uiIdx );
+        picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
+        if (picDepth && bDepthRefine)
+          estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &myMv);
+        myMv.setVer(0);
+
+        pDInfo->m_acMvCand[ pDInfo->iN] = myMv;
+        pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; // refViewIdx;
+        return;
+      }
+#endif
     }
   }
@@ -5405,6 +5754,17 @@
           TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
           clipMv(cMvPred);
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
           pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
           pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+#else
+          {
+            TComPic* picDepth = NULL;
+            picDepth = getSlice()->getRefPicBaseDepth();
+            if (picDepth && bDepthRefine)
+              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred);
+            pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          }
+#endif
           return;
         }
@@ -5424,4 +5784,19 @@
         }
       }
+#if MERL_VSP_C0152
+      else if (pcTmpCU->getVSPIndex(uiIdx) != 0) // is VSP
+      {
+        TComPic* picDepth = NULL;
+        TComMv myMv = pcTmpCU->getCUMvField( eRefPicList )->getMv( uiIdx );
+        picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
+        if (picDepth && bDepthRefine)
+          estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &myMv);
+        myMv.setVer(0);
+
+        pDInfo->m_acMvCand[ pDInfo->iN] = myMv;
+        pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; // refViewIdx;
+        return;
+      }
+#endif
     }
   }
@@ -5459,6 +5834,17 @@
           TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
           clipMv(cMvPred);
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
           pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
           pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+#else
+          {
+            TComPic* picDepth = NULL;
+            picDepth = getSlice()->getRefPicBaseDepth();
+            if (picDepth && bDepthRefine)
+              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred);
+            pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          }
+#endif
           return;
         }
@@ -5478,4 +5864,19 @@
         }
       }
+#if MERL_VSP_C0152
+      else if (pcTmpCU->getVSPIndex(uiIdx) != 0) // is VSP
+      {
+        TComPic* picDepth = NULL;
+        TComMv myMv = pcTmpCU->getCUMvField( eRefPicList )->getMv( uiIdx );
+        picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
+        if (picDepth && bDepthRefine)
+          estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &myMv);
+        myMv.setVer(0);
+
+        pDInfo->m_acMvCand[ pDInfo->iN] = myMv;
+        pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; // refViewIdx;
+        return;
+      }
+#endif
     }
   }
@@ -5509,6 +5910,17 @@
           TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
           clipMv(cMvPred);
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
           pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
           pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+#else
+          {
+            TComPic* picDepth = NULL;
+            picDepth = getSlice()->getRefPicBaseDepth();
+            if (picDepth && bDepthRefine)
+              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred);
+            pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          }
+#endif
           return;
         }
@@ -5524,4 +5936,19 @@
         }
       }
+#if MERL_VSP_C0152
+      else if (pcTmpCU->getVSPIndex(uiIdx) != 0) // is VSP
+      {
+        TComPic* picDepth = NULL;
+        TComMv myMv = pcTmpCU->getCUMvField( eRefPicList )->getMv( uiIdx );
+        picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
+        if (picDepth && bDepthRefine)
+          estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &myMv);
+        myMv.setVer(0);
+
+        pDInfo->m_acMvCand[ pDInfo->iN] = myMv;
+        pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; // refViewIdx;
+        return;
+      }
+#endif
     }
   }
@@ -5561,6 +5988,17 @@
           TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
           clipMv(cMvPred);
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
           pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred; 
           pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+#else
+          {
+            TComPic* picDepth = NULL;
+            picDepth = getSlice()->getRefPicBaseDepth();
+            if (picDepth && bDepthRefine)
+              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cMvPred);
+            pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
+          }
+#endif
           return;
         }
@@ -5580,4 +6018,19 @@
         }
       }
+#if MERL_VSP_C0152
+      else if (pcTmpCU->getVSPIndex(uiIdx) != 0) // is VSP
+      {
+        TComPic* picDepth = NULL;
+        TComMv myMv = pcTmpCU->getCUMvField( eRefPicList )->getMv( uiIdx );
+        picDepth = pcTmpCU->getSlice()->getRefPicBaseDepth();
+        if (picDepth && bDepthRefine)
+          estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &myMv);
+        myMv.setVer(0);
+
+        pDInfo->m_acMvCand[ pDInfo->iN] = myMv;
+        pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; // refViewIdx;
+        return;
+      }
+#endif
     }
   }
@@ -5810,6 +6263,18 @@
           {
             clipMv(cColMv);
-            pDInfo->m_acMvCand[pDInfo->iN] = cColMv;
-            pDInfo->m_aVIdxCan[pDInfo->iN++] = iTargetViewIdx;
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
+            pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
+#else
+            {
+              TComPic* picDepth = NULL;
+              picDepth = getSlice()->getRefPicBaseDepth();
+              if (picDepth && bDepthRefine)
+                estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cColMv);
+
+              pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
+              pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
+            }
+#endif
             return ;
           }
@@ -5819,6 +6284,17 @@
         {
           clipMv(cColMv);
-          pDInfo->m_acMvCand[pDInfo->iN] = cColMv;
-          pDInfo->m_aVIdxCan[pDInfo->iN++] = iTargetViewIdx;
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
+            pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
+#else
+            {
+              TComPic* picDepth = NULL;
+              picDepth = getSlice()->getRefPicBaseDepth();
+              if (picDepth && bDepthRefine)
+                estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cColMv);
+              pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
+              pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
+            }
+#endif
           return ;
         }
@@ -5828,6 +6304,17 @@
           {
             clipMv(cColMv);
-            pDInfo->m_acMvCand[pDInfo->iN] = cColMv;
-            pDInfo->m_aVIdxCan[pDInfo->iN++] = iTargetViewIdx;
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
+            pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
+#else
+            {
+              TComPic* picDepth = NULL;
+              picDepth = getSlice()->getRefPicBaseDepth();
+              if (picDepth && bDepthRefine)
+                estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &cColMv);
+              pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
+              pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetViewIdx;
+            }
+#endif
             return ;
           }
@@ -5852,6 +6339,17 @@
           TComMv dv( aiDvMcpDvCand[iList][ i ], 0 );
           clipMv( dv );
-          pDInfo->m_acMvCand[ pDInfo->iN  ] = dv;
-          pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0; 
+#if !MERL_MTK_VSP_DVP_REFINE_C0152_C0131
+          pDInfo->m_acMvCand[ pDInfo->iN] = dv;
+          pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0;
+#else
+          {
+            TComPic* picDepth = NULL;
+            picDepth = getSlice()->getRefPicBaseDepth();
+            if (picDepth && bDepthRefine)
+              estimateDVFromDM(uiPartIdx, picDepth, uiPartAddr, &dv);
+            pDInfo->m_acMvCand[ pDInfo->iN] = dv;
+            pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0;
+          }
+#endif
           return;
         }
@@ -5863,4 +6361,5 @@
 }
 #endif
+
 #endif
 
@@ -5904,5 +6403,9 @@
 #if QC_SIMPLE_NBDV_B0047
 #if FIX_LGE_IVMP_PARALLEL_MERGE_B0136
-      getDisMvpCand2(uiPartIdx, uiPartAddr, &cDisInfo, false); 
+      getDisMvpCand2(uiPartIdx, uiPartAddr, &cDisInfo, false
+#if MERL_VSP_C0152
+            , true
+#endif
+              ); 
 #else
       getDisMvpCand2(uiPartIdx, uiPartAddr, &cDisInfo); 
@@ -6407,4 +6910,11 @@
   }
  
+#if MERL_VSP_C0152
+  if(pcTmpCU != NULL && pcTmpCU->getVSPIndex(uiIdx))
+  {
+    return false;
+  }
+#endif
+
   if ( pcTmpCU != NULL && m_pcSlice->isEqualRef(eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx), iRefIdx) )
   {
@@ -6515,4 +7025,5 @@
   TComDataCU* pcTmpCU = NULL;
   UInt uiIdx;
+
   switch( eDir )
   {
@@ -6572,5 +7083,11 @@
     return false;
   }
-  
+
+#if MERL_VSP_C0152
+  if(pcTmpCU->getVSPIndex(uiIdx))
+  {
+    return false;
+  }
+#endif
   RefPicList eRefPicList2nd = REF_PIC_LIST_0;
   if(       eRefPicList == REF_PIC_LIST_0 )
@@ -6702,5 +7219,11 @@
   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
   iColViewIdx = pColCU->getSlice()->getViewId();
-
+#if MERL_VSP_C0152
+  //TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
+  if( pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr) < 0)
+  {
+    return false;
+  }
+#endif
 
   if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiAbsPartAddr))
@@ -7026,5 +7549,5 @@
     return false;
   }
-  
+
   if( m_pcSlice->getRefPic( eRefPicList, iRefIdx )->getViewId() != m_pcSlice->getViewId() )
   {
@@ -7071,4 +7594,9 @@
     }
   }
+
+#if MERL_VSP_C0152 // Preventive
+  if (pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiPartIdxCenter) < 0) // NOT_VALID
+    return false;
+#endif
   
   // Scale the vector.
@@ -7846,4 +8374,8 @@
   memcpy( m_puhInterDir + uiAbsPartIdxDst, pcCU->getInterDir() + uiAbsPartIdxSrc,       sizeof( m_puhInterDir[0] ) * uiNumPartition );
 
+#if MERL_VSP_C0152 && MTK_UNCONSTRAINED_MVI_B0083
+  memcpy( m_piVSPIndex + uiAbsPartIdxDst,  pcCU->getVSPIndex() + uiAbsPartIdxSrc, sizeof( m_piVSPIndex[0] ) * uiNumPartition );
+#endif
+
 #if !MTK_UNCONSTRAINED_MVI_B0083
   memcpy( m_apiMVPIdx[0] + uiAbsPartIdxDst, pcCU->getMVPIdx(REF_PIC_LIST_0) + uiAbsPartIdxSrc, sizeof(*m_apiMVPIdx[0]) * uiNumPartition );
@@ -7953,5 +8485,5 @@
 #if QC_SIMPLE_NBDV_B0047
 #if FIX_LGE_IVMP_PARALLEL_MERGE_B0136
-  getDisMvpCand2( 0, 0,  &cDisInfo, false);
+  getDisMvpCand2( 0, 0,  &cDisInfo, false );
 #else
   getDisMvpCand2( 0, 0,  &cDisInfo);
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDataCU.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDataCU.h	(revision 231)
@@ -197,4 +197,8 @@
 #endif
   UChar*        m_puhMergeIndex;      ///< array of merge candidate indices
+#if MERL_VSP_C0152
+  Char*         m_piVSPIndex;         ///< array of VSP flags to indicate the current block uses synthetic predictor or not
+                                      ///< value 0: non-VSP, value 1: VSP
+#endif
 #if AMP_MRG
   Bool          m_bIsMergeAMP;
@@ -279,5 +283,9 @@
   Bool          xAddMVPCand           ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
   Bool          xAddMVPCandOrder      ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
-
+#if MERL_VSP_C0152
+  inline Bool   xAddVspMergeCand      ( UChar ucVspMergePos, Int vspIdx, Bool* bVspMvZeroDone, UInt uiDepth, Bool* abCandIsInter, Int& iCount,
+                                        UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int* iVSPIndexTrue, Int mrgCandIdx, DisInfo* pDisInfo );
+  inline Void   xInheritVspMode       ( TComDataCU* pcCURef, UInt uiIdx, Bool* bVspMvZeroDone, Int iCount, Int* iVSPIndexTrue, TComMvField* pcMvFieldNeighbours, DisInfo* pDInfo ) ;
+#endif
   Void          deriveRightBottomIdx        ( PartSize eCUMode, UInt uiPartIdx, UInt& ruiPartIdxRB );
   Bool          xGetColMVP( RefPicList eRefPicList, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx );
@@ -366,6 +374,6 @@
   Void          copyTextureMotionDataFrom( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdxSrc, UInt uiAbsPartIdxDst = 0 );
 #endif
-  
-  // -------------------------------------------------------------------------------------------------------------------
+
+   // -------------------------------------------------------------------------------------------------------------------
   // member functions for CU data
   // -------------------------------------------------------------------------------------------------------------------
@@ -471,4 +479,12 @@
   Void          setMergeIndex         ( UInt uiIdx, UInt uiMergeIndex ) { m_puhMergeIndex[uiIdx] = uiMergeIndex;  }
   Void          setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+
+#if MERL_VSP_C0152
+  Char*         getVSPIndex        ()                        { return m_piVSPIndex;        }
+  Char          getVSPIndex        ( UInt uiIdx )            { return m_piVSPIndex[uiIdx]; }
+  Void          setVSPIndex        ( UInt uiIdx, Int n )     { m_piVSPIndex[uiIdx] = n;    }
+  Void          setVSPIndexSubParts( Char bVSPIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
+#endif
+
   template <typename T>
   Void          setSubPart            ( T bParameter, T* pbBaseLCU, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx );
@@ -555,5 +571,8 @@
   Void          getDisMvpCand2( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo
 #if LGE_IVMP_PARALLEL_MERGE_B0136
-    , Bool bParMerg = false
+                              , Bool bParMerg = false
+#endif
+#if MERL_VSP_C0152
+                              , Bool bDepthRefine = false
 #endif
     );
@@ -567,4 +586,9 @@
 #endif
 
+#endif
+
+#if MERL_VSP_C0152
+  Pel           getMcpFromDM(TComPicYuv* pcBaseViewDepthPicYuv, TComMv* mv, Int iBlkX, Int iBlkY, Int iWidth, Int iHeight, Int* aiShiftLUT, Int iShiftPrec);
+  Void          estimateDVFromDM(UInt uiPartIdx, TComPic* picDepth, UInt uiPartAddr, TComMv* cMvPred);
 #endif
   Bool          getIViewOrgDepthMvPred( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv );
@@ -685,10 +709,14 @@
   Bool          hasEqualMotion              ( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx );
 #if SIMP_MRG_PRUN
-  Void          getInterMergeCandidates       ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx = -1 );
-#else
-  Void          getInterMergeCandidates       ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand );
-#endif
-  Void          deriveLeftRightTopIdxGeneral  ( PartSize eCUMode, UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
-  Void          deriveLeftBottomIdxGeneral    ( PartSize eCUMode, UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB );
+#if MERL_VSP_C0152
+  Void          getInterMergeCandidates     ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int* uiVSPIndexTrue, Int mrgCandIdx = -1 );
+#else
+  Void          getInterMergeCandidates     ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx = -1 );
+#endif
+#else
+  Void          getInterMergeCandidates     ( UInt uiAbsPartIdx, UInt uiPUIdx, UInt uiDepth, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand );
+#endif
+  Void          deriveLeftRightTopIdxGeneral( PartSize eCUMode, UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
+  Void          deriveLeftBottomIdxGeneral  ( PartSize eCUMode, UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB );
   
   
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 231)
@@ -562,4 +562,5 @@
   m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
 }
+
 #endif
 
@@ -744,5 +745,5 @@
       Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicList );
       for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
-{
+      {
         if( pcSlice->getRefPOC( eRefPicList, iPdmRefIdx ) == pcSlice->getPOC())
         {
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 231)
@@ -439,5 +439,9 @@
   
   //-- Set BS for Intra MB : BS = 4 or 3
-  if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ) )
+  if ( pcCUP->isIntra(uiPartP) || pcCUQ->isIntra(uiPartQ) 
+#if MERL_VSP_C0152
+    || pcCUP->getVSPIndex(uiPartP) || pcCUQ->getVSPIndex(uiPartQ)
+#endif
+     )
   {
     uiBs = 2;
@@ -445,5 +449,9 @@
   
   //-- Set BS for not Intra MB : BS = 2 or 1 or 0
-  if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ) )
+  if ( !pcCUP->isIntra(uiPartP) && !pcCUQ->isIntra(uiPartQ) 
+#if MERL_VSP_C0152
+    && !pcCUP->getVSPIndex(uiPartP) && !pcCUQ->getVSPIndex(uiPartQ)
+#endif
+  )
   {
 #if NSQT_LFFIX
@@ -542,4 +550,11 @@
   }   // enf of "if( not Intra )"
   
+#if MERL_VSP_C0152
+  if ( pcCUP->getVSPIndex(uiPartP) || pcCUQ->getVSPIndex(uiPartQ))
+  {
+    uiBs = 0;
+  }
+#endif
+
   m_aapucBS[iDir][uiAbsPartIdx] = uiBs;
 }
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComMotionInfo.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 231)
@@ -378,5 +378,6 @@
 
 #if MTK_UNCONSTRAINED_MVI_B0083
-Void TComCUMvField::setUndefinedMv( Int iPartAddr, Int iNumPart, Char* pePredMode, UChar* puhInterDir, Int refIdx, Int InterDir )
+Void TComCUMvField::setUndefinedMv( Int iPartAddr, Int iNumPart, Char* pePredMode, UChar* puhInterDir, Int refIdx, Int InterDir 
+                                   )
 {
   PredMode predMode = MODE_INTRA;
@@ -386,5 +387,5 @@
   { 
     predMode = static_cast<PredMode>( pePredMode[ iPartAddr+i ] );
-    if( predMode==MODE_INTRA  )
+    if( predMode == MODE_INTRA )
     {
       m_pcMv[iPartAddr+i] = cMv;
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPic.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPic.cpp	(revision 231)
@@ -703,4 +703,3 @@
 }
 
-
 //! \}
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPrediction.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPrediction.cpp	(revision 231)
@@ -54,4 +54,11 @@
 {
   m_piYuvExt = NULL;
+#if MERL_VSP_C0152
+  m_pDepth = (Int*) malloc(64*64*sizeof(Int)); // TODO: Use a smart way to determine the size of the array
+  if (m_pDepth == NULL)
+  {
+      printf("ERROR: UKTGHU, No memory allocated.\n");
+  }
+#endif
 }
 
@@ -59,4 +66,10 @@
 {
   
+#if MERL_VSP_C0152
+  if (m_pDepth != NULL)
+  {
+      free(m_pDepth);
+  }
+#endif
   delete[] m_piYuvExt;
 
@@ -886,4 +899,372 @@
   }
 }
+
+#if MERL_VSP_C0152
+#if DEPTH_MAP_GENERATION
+Void TComPrediction::motionCompensationBWVSP( TComDataCU* pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
+#else
+Void TComPrediction::motionCompensationBWVSP ( TComDataCU* pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList, Int iPartIdx )
+#endif
+{
+  Int         iWidth;
+  Int         iHeight;
+  UInt        uiPartAddr;
+
+  if ( iPartIdx >= 0 )
+  {
+    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
+
+#if DEPTH_MAP_GENERATION
+    if( bPrdDepthMap )
+    {
+      iWidth  >>= uiSubSampExpX;
+      iHeight >>= uiSubSampExpY;
+    }
+#endif
+
+    if ( eRefPicList != REF_PIC_LIST_X )
+    {
+#if LGE_ILLUCOMP_B0045
+      if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
+#else
+      if( pcCU->getSlice()->getPPS()->getUseWP())
+#endif
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
+#else
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, true );
+#endif
+      }
+      else
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
+#else
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false );
+#endif
+      }
+#if LGE_ILLUCOMP_B0045
+      if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
+#else
+      if( pcCU->getSlice()->getPPS()->getUseWP())
+#endif
+      {
+        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
+      }
+    }
+    else
+    {
+#if DEPTH_MAP_GENERATION
+      if( xCheckIdenticalMotion( pcCU, uiPartAddr ) && !bPrdDepthMap )
+#else
+      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
+#endif
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
+#else
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, false );
+#endif
+      }
+      else
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterBiBWVSP  (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
+#else
+        xPredInterBiBWVSP  (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, pcYuvPred, iPartIdx );
+#endif
+      }
+    }
+    return;
+  }
+
+  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+  {
+    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
+
+#if DEPTH_MAP_GENERATION
+    if( bPrdDepthMap )
+    {
+      iWidth  >>= uiSubSampExpX;
+      iHeight >>= uiSubSampExpY;
+    }
+#endif
+
+    if ( eRefPicList != REF_PIC_LIST_X )
+    {
+#if LGE_ILLUCOMP_B0045
+      if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
+#else
+      if( pcCU->getSlice()->getPPS()->getUseWP())
+#endif
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
+#else
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, true );
+#endif   
+      }
+      else
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
+#else
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false );
+#endif   
+      }
+#if DEPTH_MAP_GENERATION
+      xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
+#else
+      xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false );
+#endif  
+#if LGE_ILLUCOMP_B0045
+      if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr))
+#else
+      if( pcCU->getSlice()->getPPS()->getUseWP())
+#endif
+      {
+        xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx );
+      }
+    }
+    else
+    {
+      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
+#else
+        xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, false );
+#endif 
+      }
+      else
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterBiBWVSP  (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap );
+#else
+        xPredInterBiBWVSP  (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx );
+#endif
+      }
+    }
+  }
+
+  return;
+}
+
+
+// Output: rpcYuvPred
+#if DEPTH_MAP_GENERATION
+Void TComPrediction::xPredInterUniBWVSP ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi )
+#else
+Void TComPrediction::xPredInterUniBWVSP ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi )
+#endif
+{
+  Int  iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );    
+  Int  vspIdx  = pcCU->getVSPIndex(uiPartAddr);
+  if (vspIdx != 0)
+  {
+    if (iRefIdx >= 0)
+    {
+      printf("vspIdx = %d, iRefIdx = %d\n", vspIdx, iRefIdx);
+    }
+    assert (iRefIdx < 0); // assert (iRefIdx == NOT_VALID);
+  }
+  else
+  {
+    assert (iRefIdx >= 0);
+  }
+
+  TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
+  pcCU->clipMv(cMv);
+
+#if DEPTH_MAP_GENERATION
+  if( bPrdDepthMap )
+  {
+    UInt uiRShift = 0;
+#if PDM_REMOVE_DEPENDENCE
+    if( pcCU->getPic()->getStoredPDMforV2() == 1 )
+      xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMapTemp(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 );
+    else
+#endif
+      xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 );
+
+    return;
+  }
+#endif
+
+#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
+  if( pcCU->getSlice()->getSPS()->isDepth() )
+  {
+    if (vspIdx != 0)
+    { // depth, vsp
+      // get depth estimator here
+      TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
+      TComPicYuv* pcBaseViewDepthPicYuv = NULL;
+      if (vspIdx < 4) // spatial
+      {
+        pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
+      }
+      Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
+      Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
+      Int* pShiftLUT;
+      Int iShiftPrec;
+      pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec);
+      //using disparity to find the depth block of the base view as the depth block estimator of the current block
+      //using depth block estimator and base view texture to get Backward warping
+      xPredInterLumaBlkFromDM  ( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,     pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
+      xPredInterChromaBlkFromDM( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1,  pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
+    }
+    else
+    { // depth, non-vsp
+      UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 );
+      UInt uiOffset = bi ? IF_INTERNAL_OFFS : 0;
+#if DEPTH_MAP_GENERATION
+      xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, 0, 0, rpcYuvPred, uiRShift, uiOffset );
+#else
+      xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift, uiOffset );
+#endif
+
+      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
+    }
+  }
+  else // texture
+  {
+#endif
+    if ( vspIdx != 0 && !pcCU->getSlice()->getSPS()->isDepth())
+    { // texture, vsp
+      TComPic*    pRefPicBaseTxt        = pcCU->getSlice()->getRefPicBaseTxt();
+      TComPicYuv* pcBaseViewTxtPicYuv   = pRefPicBaseTxt->getPicYuvRec();
+      TComPicYuv* pcBaseViewDepthPicYuv = NULL;
+      if (vspIdx < 4) // spatial
+      {
+        TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth();
+        pcBaseViewDepthPicYuv     = pRefPicBaseDepth->getPicYuvRec();
+      }
+      Int iBlkX = ( pcCU->getAddr() % pRefPicBaseTxt->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
+      Int iBlkY = ( pcCU->getAddr() / pRefPicBaseTxt->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
+      Int* pShiftLUT;
+      Int iShiftPrec;
+      pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec);
+
+      //using disparity to find the depth block of the base view as the depth block estimator of the current block
+      //using depth block estimator and base view texture to get Backward warping
+      xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
+      xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred );
+    }
+    else
+    { // texture, non-vsp
+#if LGE_ILLUCOMP_B0045
+      Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId());
+
+      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag);
+      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag );
+#else
+      xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
+      xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi );
+#endif
+    }
+#if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
+  }
+#endif
+}
+
+
+#if DEPTH_MAP_GENERATION
+Void TComPrediction::xPredInterBiBWVSP ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap )
+#else
+Void TComPrediction::xPredInterBiSDM ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred, Int iPartIdx )
+#endif
+{
+  TComYuv* pcMbYuv;
+  Int      iRefIdx[2] = {-1, -1};
+
+  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
+  {
+    RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
+    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
+#if MERL_VSP_C0152
+    if(!pcCU->getVSPIndex(uiPartAddr))
+    {
+      if ( iRefIdx[iRefList] < 0 )
+      {
+        continue;
+      }
+    }
+    else
+    {
+      if ( iRefList== REF_PIC_LIST_1 && iRefIdx[iRefList] < 0 ) // iRefIdx[iRefList] ==NOT_VALID
+      {
+        continue;
+      }
+    }
+#else
+    if ( iRefIdx[iRefList] < 0 )
+    {
+      continue;
+    }
+#endif
+    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
+
+    pcMbYuv = &m_acYuvPred[iRefList];
+    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
+    {
+#if DEPTH_MAP_GENERATION
+      xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
+#else
+      xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true );
+#endif
+    }
+    else
+    {
+      if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true );
+#else
+        xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true );
+#endif
+      }
+      else
+      {
+#if DEPTH_MAP_GENERATION
+        xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false );
+#else
+        xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, false );
+#endif
+      }
+    }
+  }
+
+  if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
+  {
+#if MERL_VSP_C0152
+    if(pcCU->getVSPIndex(uiPartAddr))
+      m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
+    else
+#endif
+    xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
+  }
+  else
+  {
+#if DEPTH_MAP_GENERATION
+    if ( bPrdDepthMap )
+    {
+      xWeightedAveragePdm( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, uiSubSampExpX, uiSubSampExpY );
+    }
+    else
+    {
+#if MERL_VSP_C0152
+      if(pcCU->getVSPIndex(uiPartAddr))
+        m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
+      else
+#endif
+      xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
+    }
+#else
+    xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
+#endif
+  }
+}
+#endif
 
 Void 
@@ -1119,4 +1500,376 @@
 }
 
+#if MERL_VSP_C0152
+// Input:
+// refPic: Ref picture. Full picture, with padding
+// posX, posY:     PU position, texture
+// size_x, size_y: PU size
+// partAddr: z-order index
+// mv: disparity vector. derived from neighboring blocks
+//
+// Output: dstPic, PU predictor 64x64
+Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv* mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
+                                            , TComYuv *&dstPic )
+{
+  Int widthLuma;
+  Int heightLuma;
+
+  if (isDepth)
+  {
+    widthLuma   =  pPicBaseDepth->getWidth();
+    heightLuma  =  pPicBaseDepth->getHeight();
+  }
+  else
+  {
+    widthLuma   =  refPic->getWidth();
+    heightLuma  =  refPic->getHeight();
+  }
+
+#if MERL_VSP_BLOCKSIZE_C0152 != 1
+  Int widthDepth  = pPicBaseDepth->getWidth();
+  Int heightDepth = pPicBaseDepth->getHeight();
+#endif
+
+  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
+  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
+
+  Int refStride = refPic->getStride();
+  Int dstStride = dstPic->getStride();
+  Int depStride =  pPicBaseDepth->getStride();
+
+  Int depthPosX = Clip3(0,   widthLuma - size_x - 1,  (posX/nTxtPerDepthX) + (mv->getHor()>>2));
+  Int depthPosY = Clip3(0,   heightLuma- size_y - 1,  (posY/nTxtPerDepthY) + (mv->getVer()>>2));
+
+  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
+  Pel *dst    = dstPic->getLumaAddr(partAddr);
+  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
+
+#if MERL_VSP_BLOCKSIZE_C0152 != 1
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+  Int  dW = size_x>>1;
+  Int  dH = size_y>>1;
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+  Int  dW = size_x>>2;
+  Int  dH = size_y>>2;
+#endif
+  {
+    Pel* depthi = depth;
+    for (Int j = 0; j < dH; j++)
+    {
+      for (Int i = 0; i < dW; i++)
+      {
+        Pel* depthTmp;
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+        if (depthPosX + (i<<1) < widthDepth)
+          depthTmp = depthi + (i << 1);
+        else
+          depthTmp = depthi + (widthDepth - depthPosX - 1);
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+        if (depthPosX + (i<<2) < widthDepth)
+          depthTmp = depthi + (i << 2);
+        else
+          depthTmp = depthi + (widthDepth - depthPosX - 1);
+#endif
+        Int maxV = 0;
+        for (Int blockj = 0; blockj < MERL_VSP_BLOCKSIZE_C0152; blockj++)
+        {
+          Int iX = 0;
+          for (Int blocki = 0; blocki < MERL_VSP_BLOCKSIZE_C0152; blocki++)
+          {
+            if (maxV < depthTmp[iX])
+              maxV = depthTmp[iX];
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
+#else // MERL_VSP_BLOCKSIZE_C0152 == 4
+            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
+#endif
+              iX++;
+          }
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
+#else // MERL_VSP_BLOCKSIZE_C0152 == 4
+          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
+#endif
+            depthTmp += depStride;
+        }
+        m_pDepth[i+j*dW] = maxV;
+      } // end of i < dW
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+      if (depthPosY + ((j+1)<<1) < heightDepth)
+        depthi += (depStride << 1);
+      else
+        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
+        depthi += (depStride << 2);
+      else
+        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
+#endif
+    }
+  }
+#endif
+  
+#if MERL_VSP_BLOCKSIZE_C0152 != 1
+  Int yDepth = 0;
+#endif
+  for ( Int yTxt = 0; yTxt < size_y; yTxt += nTxtPerDepthY )
+  {
+    for ( Int xTxt = 0, xDepth = 0; xTxt < size_x; xTxt += nTxtPerDepthX, xDepth++ )
+    {
+      Pel rep_depth = 0; // to store the depth value used for warping
+#if MERL_VSP_BLOCKSIZE_C0152 == 1
+      rep_depth = depth[xDepth];
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+      rep_depth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+      rep_depth = m_pDepth[(xTxt>>2) + (yTxt>>2)*dW];
+#endif
+
+      assert( rep_depth >= 0 && rep_depth <= 255 );
+      Int disparity = pShiftLUT[ rep_depth ] << iShiftPrec;
+      Int refOffset = xTxt + (disparity >> 2);
+      Int xFrac = disparity & 0x3;
+      Int absX  = posX + refOffset;
+
+      if (xFrac == 0)
+        absX = Clip3(0, widthLuma-1, absX);
+      else
+        absX = Clip3(4, widthLuma-5, absX);
+
+      refOffset = absX - posX;
+
+      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
+      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true );
+    }
+    ref   += refStride*nTxtPerDepthY;
+    dst   += dstStride*nTxtPerDepthY;
+    depth += depStride;
+#if MERL_VSP_BLOCKSIZE_C0152 != 1
+    yDepth++;
+#endif
+  }
+}
+
+Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv*mv, UInt partAddr, Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
+                                               , TComYuv *&dstPic )
+{
+  Int refStride = refPic->getCStride();
+  Int dstStride = dstPic->getCStride();
+  Int depStride = pPicBaseDepth->getStride();
+
+  Int widthChroma, heightChroma;
+  if( isDepth)
+  {
+     widthChroma   = pPicBaseDepth->getWidth()>>1;
+     heightChroma  = pPicBaseDepth->getHeight()>>1;
+  }
+  else
+  {
+     widthChroma   = refPic->getWidth()>>1;
+     heightChroma  = refPic->getHeight()>>1;
+  }
+
+  // Below is only for Texture chroma component
+
+  Int widthDepth  = pPicBaseDepth->getWidth();
+  Int heightDepth = pPicBaseDepth->getHeight();
+
+  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
+  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
+
+  Int depthPosX;  // Starting position in depth image
+  Int depthPosY;
+
+  if ( widthChroma > widthDepth )
+  {
+    nTxtPerDepthX = widthChroma / widthDepth;
+    nDepthPerTxtX = 1;
+    depthPosX = posX / nTxtPerDepthX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
+  }
+  else
+  {
+    nTxtPerDepthX = 1;
+    nDepthPerTxtX = widthDepth / widthChroma;
+    depthPosX = posX * nDepthPerTxtX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
+  }
+  depthPosX = Clip3(0, widthDepth - (size_x<<1) - 1, depthPosX);
+  
+  if ( heightChroma > heightDepth )
+  {
+    nTxtPerDepthY = heightChroma / heightDepth;
+    nDepthPerTxtY = 1;
+    depthPosY = posY / nTxtPerDepthY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
+  }
+  else
+  {
+    nTxtPerDepthY = 1;
+    nDepthPerTxtY = heightDepth / heightChroma;
+    depthPosY = posY * nDepthPerTxtY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
+  }
+  depthPosY = Clip3(0, heightDepth - (size_y<<1) - 1, depthPosY);
+
+  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
+  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
+  Pel *dstCb  = dstPic->getCbAddr(partAddr);
+  Pel *dstCr  = dstPic->getCrAddr(partAddr);
+  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
+  
+  Int refStrideBlock = refStride * nTxtPerDepthY;
+  Int dstStrideBlock = dstStride * nTxtPerDepthY;
+  Int depStrideBlock = depStride * nDepthPerTxtY;
+
+  if (isDepth)
+  {
+     // DT: Since the call for this function is redundant, ..
+     for (Int y = 0; y < size_y; y++)
+     {
+       for (Int x = 0; x < size_x; x++)
+       {
+         dstCb[x] = 128;
+         dstCr[x] = 128;
+       }
+       dstCb += dstStride;
+       dstCr += dstStride;
+     }
+     return;
+  }
+  
+  if ( widthChroma > widthDepth ) // We assume
+  {
+    assert( heightChroma > heightDepth );
+    printf("This branch should never been reached.\n");
+    exit(0);
+  }
+  else
+  {
+#if MERL_VSP_BLOCKSIZE_C0152 == 1
+  Int  dW = size_x;
+  Int  dH = size_y;
+  Int  sW = 2; // search window size
+  Int  sH = 2;
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+  Int  dW = size_x;
+  Int  dH = size_y;
+  Int  sW = 2; // search window size
+  Int  sH = 2;
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+  Int  dW = size_x>>1;
+  Int  dH = size_y>>1;
+  Int  sW = 4; // search window size
+  Int  sH = 4;
+#endif
+
+  {
+    Pel* depthi = depth;
+    for (Int j = 0; j < dH; j++)
+    {
+      for (Int i = 0; i < dW; i++)
+      {
+        Pel* depthTmp;
+#if MERL_VSP_BLOCKSIZE_C0152 == 1
+        depthTmp = depthi + (i << 1);
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+        if (depthPosX + (i<<1) < widthDepth)
+          depthTmp = depthi + (i << 1);
+        else
+          depthTmp = depthi + (widthDepth - depthPosX - 1);
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+        if (depthPosX + (i<<2) < widthDepth)
+          depthTmp = depthi + (i << 2);
+        else
+          depthTmp = depthi + (widthDepth - depthPosX - 1);
+#endif
+        Int maxV = 0;
+        for (Int blockj = 0; blockj < sH; blockj++)
+        {
+          Int iX = 0;
+          for (Int blocki = 0; blocki < sW; blocki++)
+          {
+            if (maxV < depthTmp[iX])
+              maxV = depthTmp[iX];
+            if (depthPosX + i*sW + blocki < widthDepth - 1)
+              iX++;
+          }
+          if (depthPosY + j*sH + blockj < heightDepth - 1)
+            depthTmp += depStride;
+        }
+        m_pDepth[i+j*dW] = maxV;
+      } // end of i < dW
+#if MERL_VSP_BLOCKSIZE_C0152 == 1
+      if (depthPosY + ((j+1)<<1) < heightDepth)
+        depthi += (depStride << 1);
+      else
+        depthi  = depth + (heightDepth-1)*depStride;
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+      if (depthPosY + ((j+1)<<1) < heightDepth)
+        depthi += (depStride << 1);
+      else
+        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
+        depthi += (depStride << 2);
+      else
+        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
+#endif
+    }
+  }
+
+
+    // (size_x, size_y) is Chroma block size
+    for ( Int yTxt = 0, yDepth = 0; yTxt < size_y; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
+    {
+      for ( Int xTxt = 0, xDepth = 0; xTxt < size_x; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
+      {
+        Pel rep_depth = 0; // to store the depth value used for warping
+#if MERL_VSP_BLOCKSIZE_C0152 == 1
+        rep_depth = m_pDepth[(xTxt) + (yTxt)*dW];
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 2
+        rep_depth = m_pDepth[(xTxt) + (yTxt)*dW];
+#endif
+#if MERL_VSP_BLOCKSIZE_C0152 == 4
+        rep_depth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW];
+#endif
+
+      // calculate the offset in the reference picture
+        Int disparity = pShiftLUT[ rep_depth ] << iShiftPrec;
+        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
+        Int xFrac = disparity & 0x7;
+        Int absX  = posX + refOffset;
+
+        if (xFrac == 0)
+          absX = Clip3(0, widthChroma-1, absX);
+        else
+          absX = Clip3(4, widthChroma-5, absX);
+
+        refOffset = absX - posX;
+
+        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
+        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
+        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true);
+        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true);
+      }
+      refCb += refStrideBlock;
+      refCr += refStrideBlock;
+      dstCb += dstStrideBlock;
+      dstCr += dstStrideBlock;
+      depth += depStrideBlock;
+    }
+  }
+}
+
+#endif // MERL_VSP_C0152
+
 #if DEPTH_MAP_GENERATION
 Void TComPrediction::xWeightedAveragePdm( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY )
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPrediction.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComPrediction.h	(revision 231)
@@ -78,4 +78,8 @@
   UInt   m_uiaShift[ 63 ];       // Table for multiplication to substitue of division operation
 
+#if MERL_VSP_C0152
+  Int*   m_pDepth; ///< Local variable, to store a depth block, just to prevent allocate memory every time
+#endif
+
   Void xPredIntraAng            ( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter );
   Void xPredIntraPlanar         ( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height );
@@ -94,4 +98,8 @@
   Void xPredInterBi             ( TComDataCU* pcCU,                          UInt uiPartAddr,               Int iWidth, Int iHeight,                         TComYuv*& rpcYuvPred, Int iPartIdx          );
   Void xPredInterPrdDepthMap    ( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight,                         TComYuv*& rpcYuv, UInt uiRShift, UInt uiOffset );
+#endif
+#if MERL_VSP_C0152
+  Void xPredInterUniBWVSP         ( TComDataCU* pcCU,                          UInt uiPartAddr, UInt uiAbsPartIdx,               Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi=false );
+  Void xPredInterBiBWVSP          ( TComDataCU* pcCU,                          UInt uiPartAddr, UInt uiAbsPartIdx,               Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap );
 #endif
 
@@ -108,5 +116,11 @@
 #endif
   Void xWeightedAverage         ( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst );
-  
+
+#if MERL_VSP_C0152
+  Void xPredInterLumaBlkFromDM    ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
+                                  , TComYuv *&dstPic );
+  Void xPredInterChromaBlkFromDM  ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv *mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx
+                                  , TComYuv *&dstPic );
+#endif
   Void xGetLLSPrediction ( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 );
 #if LGE_ILLUCOMP_B0045
@@ -150,5 +164,9 @@
   Void motionCompensation         ( TComDataCU*  pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList = REF_PIC_LIST_X, Int iPartIdx = -1 );
 #endif
-  
+
+#if MERL_VSP_C0152
+   Void motionCompensationBWVSP   ( TComDataCU*  pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList = REF_PIC_LIST_X, Int iPartIdx = -1, Bool bPrdDepthMap = false, UInt uiSubSampExpX = 0, UInt uiSubSampExpY = 0 );
+#endif
+
   // motion vector prediction
   Void getMvPredAMVP              ( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComSlice.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComSlice.cpp	(revision 231)
@@ -121,5 +121,5 @@
 {
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
-  
+
   initEqualRef();
   
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComSlice.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TComSlice.h	(revision 231)
@@ -1265,5 +1265,5 @@
 #endif
 #if QC_IV_AS_LT_B0046
-  Bool                  m_bWasLongTerm[2][MAX_NUM_REF+1]; //was long-term picture
+  Bool        m_bWasLongTerm[2][MAX_NUM_REF+1]; //was long-term picture
 #endif
   TComSPS*    m_pcSPS;
@@ -1341,8 +1341,15 @@
 
 #if SONY_COLPIC_AVAILABILITY|QC_MVHEVC_B0046
-  Int         m_iViewOrderIdx;
+  Int        m_iViewOrderIdx;
 #endif
 #if LGE_ILLUCOMP_B0045
   Bool        m_bApplyIC;
+#endif
+
+#if MERL_VSP_C0152
+  TComPic*     m_apcRefPicBaseTxt;
+  TComPic*     m_apcRefPicBaseDepth;
+  Int*         m_aiShiftLUT;
+  Int          m_iShiftPrec;
 #endif
 
@@ -1655,4 +1662,14 @@
 #endif
 
+#if MERL_VSP_C0152
+  TComPic*     getRefPicBaseTxt          ()                        { return  m_apcRefPicBaseTxt; }
+  Void         setRefPicBaseTxt          ( TComPic* RefPic)        { m_apcRefPicBaseTxt = RefPic; }
+  TComPic*     getRefPicBaseDepth        ()                        { return  m_apcRefPicBaseDepth; }
+  Void         setRefPicBaseDepth        ( TComPic* RefPic)        { m_apcRefPicBaseDepth = RefPic; }
+
+  Void setBWVSPLUTParam( Int *pShiftLUT, Int iLoG2LUTPrec) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = iLoG2LUTPrec; }
+  Void getBWVSPLUTParam( Int*&pShiftLUT, Int&iLoG2LUTPrec) { pShiftLUT = m_aiShiftLUT; iLoG2LUTPrec = m_iShiftPrec; }
+#endif
+
 protected:
   TComPic*  xGetRefPic        (TComList<TComPic*>& rcListPic, UInt uiPOC);
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TypeDef.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibCommon/TypeDef.h	(revision 231)
@@ -51,4 +51,38 @@
 
 #if !QC_MVHEVC_B0046
+
+///// ***** VSP MODES *********
+#define MERL_VSP_C0152                       1 // JCT3V-C0152: 1: enable VSP-related tools; 0: disable VSP-related tools
+
+#if MERL_VSP_C0152
+
+/*
+ * Two macros are used to configure combinations of JCT3V-C0152 and JCT3V-C0131
+ * 
+ *   a) (full) A full JCT3V-C0152 implementation, including JCT3V-C0131 
+ *      #define MERL_VSP_COMPENSATION_C0152          1
+ *      #define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  1
+ * 
+ *   b) (mvp2off) For partial JCT3V-C0152 excluding overlaps from JCT3V-C0131
+ *      #define MERL_VSP_COMPENSATION_C0152          1
+ *      #define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  0
+ * 
+ *   c) (nocand) For JCT3V-C0131 only
+ *      #define MERL_VSP_COMPENSATION_C0152          0
+ *      #define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  1
+ */
+
+#define MERL_VSP_COMPENSATION_C0152          0 // JCT3V-C0152: 1: add VSP merge candidate to merging candidate list; 0: not to add   (nocand).
+#define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  1 // JCT3V-C0152 && JCT3V-C0131: 1: refine disparity vector using a warped depth block; 0: not to refine  (mvp2off).
+
+#define MERL_VSP_BLOCKSIZE_C0152             4 // JCT3V-C0152: VSP block size, supported values: 1, 2 and 4.
+#define VSP_MERGE_POS                        5 // JCT3V-C0152: fixed position of VSP candidate in merge list, supported values: 5.
+
+#else // !MERL_VSP_C0152
+#define MERL_VSP_COMPENSATION_C0152          0 // JCT3V-C0152: 1: add VSP merge candidate to merging candidate list; 0: not to add
+#define MERL_MTK_VSP_DVP_REFINE_C0152_C0131  0 // JCT3V-C0152 && JCT3V-C0131: 1: refine disparity vector using a warped depth block; 0: not to refine
+#define MERL_VSP_BLOCKSIZE_C0152             4 // JCT3V-C0152: VSP block size, supported values: 1, 2 and 4.
+#endif
+
 ///// ***** FIXES *********
 // A
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecCu.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecCu.cpp	(revision 231)
@@ -361,7 +361,12 @@
 
       UInt uiCurrPartNumb = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
+
       for( UInt ui = 0; ui < uiCurrPartNumb; ui++ )
       {
         const UChar uhNewDepth = max<UInt>( uiDepth, pcTextureCU->getDepth( uiAbsPartIdx + ui ) );
+#if MERL_VSP_C0152
+        Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
+        pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
+#endif
         pcCU->setPredictionMode( uiAbsPartIdx + ui, MODE_SKIP );
         pcCU->setPartitionSize( uiAbsPartIdx + ui, SIZE_2Nx2N );
@@ -376,5 +381,24 @@
 #if SIMP_MRG_PRUN      
     UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
+#if MERL_VSP_C0152
+    Int iVSPIndexTrue[3] = {-1, -1, -1};
+    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, uiMergeIndex );
+    {
+      Int iVSPIdx = 0;
+      Int numVspIdx;
+      numVspIdx = 3;
+      for (Int i = 0; i < numVspIdx; i++)
+      {
+        if (iVSPIndexTrue[i] == uiMergeIndex)
+          {
+            iVSPIdx = i+1;
+            break;
+          }
+      }
+      pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, 0, uiDepth );  //Initialize the VSP, may change later in get InterMergeCandidates()
+    }
+#else
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
+#endif
 #else
     m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
@@ -467,7 +491,12 @@
 
       UInt uiCurrPartNumb = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
+
       for( UInt ui = 0; ui < uiCurrPartNumb; ui++ )
       {
         const UChar uhNewDepth = max<UInt>( uiDepth, pcTextureCU->getDepth( uiAbsPartIdx + ui ) );
+#if MERL_VSP_C0152
+        Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
+        pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
+#endif
         pcCU->setPredictionMode( uiAbsPartIdx + ui, MODE_INTER );
         pcCU->setPartitionSize( uiAbsPartIdx + ui, SIZE_2Nx2N );
@@ -658,6 +687,9 @@
   
   // inter prediction
+#if MERL_VSP_C0152
+  m_pcPrediction->motionCompensationBWVSP( pcCU, m_ppcYuvReco[uiDepth], uiAbsPartIdx );
+#else
   m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
-  
+#endif
 #if HHI_MPI
   if( pcCU->getTextureModeDepth( 0 ) != -1 )
@@ -1047,5 +1079,5 @@
   // reconstruct residual based on mask + DC residuals
   Pel apDCResiValues[2];
-  Pel apDCRecoValues[2];
+  //Pel apDCRecoValues[2];
   for( UInt ui = 0; ui < uiNumSegments; ui++ )
   {
@@ -1054,5 +1086,5 @@
     Pel   pRecoValue  = GetIdx2DepthValue( pPredIdx + pResiIdx );
     
-    apDCRecoValues[ui]  = pRecoValue;
+    //apDCRecoValues[ui]  = pRecoValue;
     apDCResiValues[ui]  = pRecoValue - apDCPredValues[ui];
   }
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecCu.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecCu.h	(revision 231)
@@ -65,5 +65,5 @@
 #endif
   TComDataCU**        m_ppcCU;            ///< CU data array
-  
+
   // access channel
   TComTrQuant*        m_pcTrQuant;
@@ -85,5 +85,5 @@
   /// destroy internal buffers
   Void  destroy                 ();
-  
+
   /// decode CU information
   Void  decodeCU                ( TComDataCU* pcCU, UInt& ruiIsLast );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 231)
@@ -337,5 +337,37 @@
 #if SIMP_MRG_PRUN       
       UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
+#if MERL_VSP_C0152
+      Int iVSPIndexTrue[3] = {-1, -1, -1};
+      pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, uiMergeIndex );
+
+      if(pcCU->getTextureModeDepth( uiSubPartIdx ) == uiDepth)//MPI is used
+      {
+        TComDataCU *pcTextureCU = pcCU->getSlice()->getTexturePic()->getCU( pcCU->getAddr() );
+        UInt uiCurrPartNumb = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
+        for( UInt ui = 0; ui < uiCurrPartNumb; ui++ )
+        {
+          Int vspIdx = pcTextureCU->getVSPIndex( uiAbsPartIdx + ui);
+          pcCU->setVSPIndex( uiAbsPartIdx + ui, vspIdx);
+        }
+      }
+      else // MPI not used
+      {
+        Int iVSPIdx = 0;
+        Int numVspIdx;
+        numVspIdx = 3;
+        for (Int i = 0; i < numVspIdx; i++)
+        {
+          if (iVSPIndexTrue[i] == uiMergeIndex)
+            {
+              iVSPIdx = i+1;
+              break;
+            }
+        }
+        pcCU->setVSPIndexSubParts( iVSPIdx, uiSubPartIdx, uiPartIdx, uiDepth );  //Initialize the VSP, may change later in get InterMergeCandidates()
+      }
+
+#else
       pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
+#endif
 #else      
       pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecGop.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecGop.cpp	(revision 231)
@@ -511,4 +511,5 @@
     m_vAlfCUCtrlSlices.clear();
   }
+  fflush(stdout);
 }
 
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecTop.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecTop.cpp	(revision 231)
@@ -59,4 +59,10 @@
     m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
   }
+
+#if MERL_VSP_C0152
+  xCreateLUTs( (UInt)MAX_VIEW_NUM, (UInt)MAX_VIEW_NUM, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
+  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
+  m_uiBitDepthForLUT = 8; // fixed
+#endif
 }
 
@@ -72,4 +78,9 @@
   delete [] m_aiViewOrderIndex;
   delete [] m_aiViewReceived;
+
+#if MERL_VSP_C0152
+  xDeleteArray( m_adBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
+  xDeleteArray( m_aiBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
+#endif
 }
 
@@ -85,4 +96,80 @@
   m_uiMaxViewId             = 0;
 }
+
+#if MERL_VSP_C0152
+Void
+CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
+{
+  //AOF( m_uiBitDepthForLUT == 8 );
+  //AOF(radLUT == NULL && raiLUT == NULL );
+
+  uiNumberSourceViews = Max( 1, uiNumberSourceViews );
+  uiNumberTargetViews = Max( 1, uiNumberTargetViews );
+
+  radLUT         = new Double***[ uiNumberSourceViews ];
+  raiLUT         = new Int   ***[ uiNumberSourceViews ];
+
+  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
+  {
+    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
+    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
+
+    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
+    {
+      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
+      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
+      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
+
+      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
+      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
+      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
+    }
+  }
+}
+
+Void 
+  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
+{
+  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
+  Int     iLog2DivChroma = iLog2DivLuma + 1;
+
+  iOffset <<= m_uiBitDepthForLUT;
+
+  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
+  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
+
+  // offsets including rounding offsets
+  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
+  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
+
+
+  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
+  {
+
+    // real-valued look-up tables
+    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+    Double  dShiftChroma    = dShiftLuma / 2;
+    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
+    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
+
+    // integer-valued look-up tables
+    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
+    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
+    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
+    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
+    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
+
+    // maximum deviation
+    //dMaxDispDev     = Max( dMaxDispDev,    fabs( Double( (Int) iTestScale   ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) );
+    //dMaxRndDispDvL  = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma   ) - dShiftLuma   ) );
+    //dMaxRndDispDvC  = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) );
+  }
+
+  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+}
+#endif // end MERL_VSP_C0152
 
 Void
@@ -167,4 +254,8 @@
         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
+#if MERL_VSP_C0152
+        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
+        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
+#endif
       }
       else
@@ -174,4 +265,8 @@
         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
+#if MERL_VSP_C0152
+        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
+        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
+#endif
       }
     }
@@ -188,4 +283,8 @@
         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
+#if MERL_VSP_C0152
+        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
+        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
+#endif
       }
     }
@@ -258,5 +357,5 @@
 #endif
 #if ENC_DEC_TRACE
-  g_hTrace = fopen( "TraceDec.txt", "wb" );
+  if(!g_hTrace) g_hTrace = fopen( "TraceDec.txt", "wb" );
   g_bJustDoIt = g_bEncDecTraceDisable;
   g_nSymbolCounter = 0;
@@ -277,5 +376,6 @@
 {
 #if ENC_DEC_TRACE
-  fclose( g_hTrace );
+  if(g_hTrace) fclose( g_hTrace );
+  g_hTrace=NULL;
 #endif
 }
@@ -304,4 +404,5 @@
   m_cResidualGenerator.destroy();
 #endif
+
 }
 
@@ -1109,4 +1210,19 @@
     initWedgeLists();
   }
+#endif
+
+#if MERL_VSP_C0152 // set BW LUT 
+  if( m_pcCamParsCollector ) // Initialize the LUT elements 
+  {
+    m_pcCamParsCollector->setSlice( pcSlice );
+  }
+  if( pcSlice->getViewId() !=0 )
+  {
+    TComPic* pcBaseTxtPic = m_tAppDecTop->getPicFromView(  0, pcSlice->getPOC(), false );  // get base view reconstructed texture
+    TComPic* pcBaseDepthPic = m_tAppDecTop->getPicFromView(  0, pcSlice->getPOC(), true ); // get base view reconstructed depth
+     pcSlice->setRefPicBaseTxt(pcBaseTxtPic);
+     pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
+  }
+  getTAppDecTop()->setBWVSPLUT( pcSlice, pcSlice->getViewId(),  pcSlice->getPOC() ); // get the LUT for backward warping
 #endif
 
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecTop.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibDecoder/TDecTop.h	(revision 231)
@@ -77,4 +77,7 @@
   Bool  isInitialized() const { return m_bInitialized; }
 
+#if MERL_VSP_C0152
+  Int**** getBaseViewShiftLUTI()  { return m_aiBaseViewShiftLUT;   }
+#endif
 private:
   Bool  xIsComplete ();
@@ -97,5 +100,79 @@
   Int     m_iLastPOC;
   UInt    m_uiMaxViewId;
+
+#if MERL_VSP_C0152
+  UInt    m_uiBitDepthForLUT;
+  UInt    m_iLog2Precision;
+  UInt    m_uiInputBitDepth;
+  // look-up tables
+  Double****   m_adBaseViewShiftLUT;       ///< Disparity LUT
+  Int****      m_aiBaseViewShiftLUT;       ///< Disparity LUT
+  Void xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT);
+  Void xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT);
+  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 );
+  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize1, UInt uiSize2 );
+  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize );
+#endif
+
 };
+
+#if MERL_VSP_C0152
+template <class T>
+Void CamParsCollector::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 )
+{
+  if( rpt )
+  {
+    for( UInt uiK = 0; uiK < uiSize1; uiK++ )
+    {
+      for( UInt uiL = 0; uiL < uiSize2; uiL++ )
+      {
+        for( UInt uiM = 0; uiM < uiSize3; uiM++ )
+        {
+          delete[] rpt[ uiK ][ uiL ][ uiM ];
+        }
+        delete[] rpt[ uiK ][ uiL ];
+      }
+      delete[] rpt[ uiK ];
+    }
+    delete[] rpt;
+  }
+  rpt = NULL;
+};
+
+
+template <class T>
+Void CamParsCollector::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2 )
+{
+  if( rpt )
+  {
+    for( UInt uiK = 0; uiK < uiSize1; uiK++ )
+    {
+      for( UInt uiL = 0; uiL < uiSize2; uiL++ )
+      {
+        delete[] rpt[ uiK ][ uiL ];
+      }
+      delete[] rpt[ uiK ];
+    }
+    delete[] rpt;
+  }
+  rpt = NULL;
+};
+
+
+template <class T>
+Void CamParsCollector::xDeleteArray( T*& rpt, UInt uiSize )
+{
+  if( rpt )
+  {
+    for( UInt uiK = 0; uiK < uiSize; uiK++ )
+    {
+      delete[] rpt[ uiK ];
+    }
+    delete[] rpt;
+  }
+  rpt = NULL;
+};
+
+#endif
 
 /// decoder class
@@ -206,4 +283,5 @@
   ParameterSetManagerDecoder* xGetParaSetDec ()        {return  &m_parameterSetManagerDecoder;}
 #endif
+
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncCu.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncCu.cpp	(revision 231)
@@ -1890,6 +1890,10 @@
 
   rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
-  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
-
+#if MERL_VSP_C0152
+  Int iVSPIndexTrue[3] = {-1, -1, -1};
+  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
+#else
+  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
+#endif
 #if FAST_DECISION_FOR_MRG_RD_COST
   Bool bestIsSkip = false;
@@ -1933,4 +1937,20 @@
           rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
           rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
+#if MERL_VSP_C0152
+          {
+            Int iVSPIdx = 0;
+            Int numVSPIdx;
+            numVSPIdx = 3;
+            for (Int i = 0; i < numVSPIdx; i++)
+            {
+              if (iVSPIndexTrue[i] == uiMergeCand)
+                {
+                  iVSPIdx = i+1;
+                  break;
+                }
+            }
+            rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth );
+          }
+#endif
           rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
           rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
@@ -1952,5 +1972,9 @@
 #endif
         {
+#if MERL_VSP_C0152
+            m_pcPredSearch->motionCompensationBWVSP ( rpcTempCU, m_ppcPredYuvTemp[uhDepth],  rpcTempCU->getZorderIdxInCU() );
+#else
             m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
+#endif
             // save pred adress
             pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth];
@@ -1962,5 +1986,9 @@
             if( bestIsSkip)
             {
+#if MERL_VSP_C0152
+              m_pcPredSearch->motionCompensationBWVSP ( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() );
+#else
               m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
+#endif
               // save pred adress
               pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth];
@@ -2065,4 +2093,5 @@
   
   rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
+
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth );
@@ -2084,5 +2113,5 @@
   #if HHI_INTERVIEW_SKIP
 #if LG_RESTRICTEDRESPRED_M24766
-  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG  );
+  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG);
 #else
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG  );
@@ -2787,8 +2816,16 @@
       assert( rpcTempCU->getInterDir( ui ) != 0 );
       assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE );
-    }
+#if MERL_VSP_C0152
+      Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui);
+      rpcTempCU->setVSPIndex( ui , vspIdx);
+#endif
+    }
+
     rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth );
+#if MERL_VSP_C0152
+    m_pcPredSearch->motionCompensationBWVSP( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU()  );
+#else
     m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
-
+#endif
     // get Original YUV data from picture
     m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncCu.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncCu.h	(revision 231)
@@ -81,5 +81,5 @@
   TComYuv**               m_ppcResPredTmp;  ///< Temporary residual prediction for each depth
 #endif
-  
+
   //  Data : encoder control
   Bool                    m_bEncodeDQP;
@@ -121,5 +121,5 @@
   /// destroy internal buffers
   Void  destroy             ();
-  
+
   /// CU analysis function
   Void  compressCU          ( TComDataCU*&  rpcCU );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 231)
@@ -1347,5 +1347,5 @@
     uiAbsPartIdx = 0;
   }
-  
+
 #if RWTH_SDC_DLT_B0036
   if( pcCU->getSDCFlag(uiAbsPartIdx) )
@@ -1355,5 +1355,5 @@
   }
 #endif
-  
+
   PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx );
   
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 231)
@@ -254,5 +254,5 @@
       pcSlice->setSliceIdx(0);
       pcSlice->setViewId( m_pcEncTop->getViewId() );
-      pcSlice->setIsDepth( m_pcEncTop->getIsDepth() ); 
+      pcSlice->setIsDepth( m_pcEncTop->getIsDepth() );
 
       m_pcEncTop->getSPS()->setDisInter4x4(m_pcEncTop->getDisInter4x4());
@@ -340,11 +340,11 @@
       pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
 #else
-
-    Bool bNalRAP = ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR)) && (pcSlice->getSPS()->getViewId())  ? 1: 0;
-    pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
-    pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
-#endif
-    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
-    refPicListModification->setRefPicListModificationFlagL0( false );
+      Bool bNalRAP = ((getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_CRA) || (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDR)) && (pcSlice->getSPS()->getViewId())  ? 1: 0;
+      pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
+      pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( bNalRAP ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
+#endif
+      
+      TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
+      refPicListModification->setRefPicListModificationFlagL0( false );
 #if !H0137_0138_LIST_MODIFICATION
       refPicListModification->setNumberOfRefPicListModificationsL0(0);
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 231)
@@ -1277,4 +1277,10 @@
       xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( REF_PIC_LIST_C )-2 );
     }
+#if MERL_VSP_C0152
+    else if (iRefFrame < 0) // NOT_VALID
+    {
+      assert(0);
+    }
+#endif
   }
   else
@@ -1288,4 +1294,10 @@
       xWriteUnaryMaxSymbol( iRefFrame - 1, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 );
     }
+#if MERL_VSP_C0152
+    else if (iRefFrame < 0) // NOT_VALID
+    {
+      assert(0);
+    }
+#endif
   }
   return;
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 231)
@@ -696,5 +696,6 @@
 UInt TEncSearch::xPatternRefinement( TComPattern* pcPatternKey,
                                     TComMv baseRefMv,
-                                    Int iFrac, TComMv& rcMvFrac )
+                                    Int iFrac, TComMv& rcMvFrac
+                                   )
 {
   UInt  uiDist;
@@ -1688,5 +1689,5 @@
   // reconstruct residual based on mask + DC residuals
   Pel apDCResiValues[2];
-  Pel apDCRecoValues[2];
+  //Pel apDCRecoValues[2];
   for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
   {
@@ -1695,5 +1696,5 @@
     Pel   pRecoValue  = GetIdx2DepthValue( pPredIdx + pResiIdx );
     
-    apDCRecoValues[uiSegment]  = pRecoValue;
+    //apDCRecoValues[uiSegment]  = pRecoValue;
     apDCResiValues[uiSegment]  = pRecoValue - apDCPredValues[uiSegment];
   }
@@ -2897,11 +2898,14 @@
 Void TEncSearch::xGetInterPredictionError( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, UInt& ruiErr, Bool bHadamard )
 {
+#if !MERL_VSP_C0152
   motionCompensation( pcCU, &m_tmpYuvPred, REF_PIC_LIST_X, iPartIdx );
-
+#endif
   UInt uiAbsPartIdx = 0;
   Int iWidth = 0;
   Int iHeight = 0;
   pcCU->getPartIndexAndSize( iPartIdx, uiAbsPartIdx, iWidth, iHeight );
-
+#if MERL_VSP_C0152
+  motionCompensationBWVSP( pcCU, &m_tmpYuvPred,  pcCU->getZorderIdxInCU(), REF_PIC_LIST_X, iPartIdx );
+#endif
   DistParam cDistParam;
 
@@ -2943,5 +2947,9 @@
 #else
 #if LG_RESTRICTEDRESPRED_M24766
+#if MERL_VSP_C0152
+Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* rpcResiPredYuv, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost, Int* iVSPIndexTrue )
+#else
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* rpcResiPredYuv, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
+#endif
 #else
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
@@ -2988,6 +2996,11 @@
   }
 #else
+#if MERL_VSP_C0152
+  pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
+#else
   pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
 #endif
+#endif
+
 
 #if HHI_INTER_VIEW_MOTION_PRED
@@ -3009,4 +3022,20 @@
       pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
       pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
+#if MERL_VSP_C0152
+      {
+        Int iVSPIdx = 0;
+        Int numVSPIdx;
+        numVSPIdx = 3;
+        for (Int i = 0; i < numVSPIdx; i++)
+        {
+          if (iVSPIndexTrue[i] == uiMergeCand)
+            {
+              iVSPIdx = i+1;
+              break;
+            }
+        }
+        pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+      }
+#endif
 #if LG_RESTRICTEDRESPRED_M24766
       Int iAddResiShift;
@@ -3081,5 +3110,5 @@
 Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* rpcResiPredYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG )
 #else
-Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG )
+Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG)
 #endif
 #else
@@ -3185,4 +3214,5 @@
     for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT;
     UInt          uiBitsTempL0[MAX_NUM_REF];
+
 #if LG_RESTRICTEDRESPRED_M24766
     Int iPUResiPredShift[4] = {0, 0, 0, 0};
@@ -3191,5 +3221,8 @@
     
     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
-    
+#if MERL_VSP_C0152
+    //reset the VSP flag to be 0
+    pcCU->setVSPIndexSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
+#endif
 #if AMP_MRG
     Bool bTestNormalMC = true;
@@ -3206,4 +3239,5 @@
       Bool bLastResiFlag = false;
 #endif
+
     //  Uni-directional prediction
     for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
@@ -3545,5 +3579,5 @@
             xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
           }
-          
+
           if ( uiCostTemp < uiCostBi )
           {
@@ -3793,5 +3827,7 @@
       TComMvField cMRGMvField[2];
       UInt uiMRGIndex = 0;
-
+#if MERL_VSP_C0152
+      Int iVSPIndexTrue[3] = {-1, -1, -1};
+#endif
       UInt uiMEInterDir = 0;
       TComMvField cMEMvField[2];
@@ -3844,5 +3880,9 @@
 #else
 #if LG_RESTRICTEDRESPRED_M24766
+#if MERL_VSP_C0152
+      xMergeEstimation( pcCU, pcOrgYuv, rpcResiPredYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost,  iVSPIndexTrue );
+#else
       xMergeEstimation( pcCU, pcOrgYuv, rpcResiPredYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
+#endif
 #else
       xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
@@ -3854,4 +3894,20 @@
         pcCU->setMergeFlagSubParts ( true,          uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
         pcCU->setMergeIndexSubParts( uiMRGIndex,    uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#if MERL_VSP_C0152
+        {
+          Int iVSPIdx = 0;
+          Int numVSPIdx;
+          numVSPIdx = 3;
+          for (Int i = 0; i < numVSPIdx; i++)
+          {
+            if (iVSPIndexTrue[i] == uiMRGIndex)
+              {
+                iVSPIdx = i+1;
+                break;
+              }
+          }
+          pcCU->setVSPIndexSubParts( iVSPIdx, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+        }
+#endif
         pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
         {
@@ -3873,4 +3929,7 @@
         pcCU->setMergeFlagSubParts( false,        uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
         pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#if MERL_VSP_C0152
+        pcCU->setVSPIndexSubParts ( 0 ,           uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+#endif
         {
           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
@@ -3881,6 +3940,9 @@
 
     //  MC
+#if MERL_VSP_C0152
+    motionCompensationBWVSP ( pcCU, rpcPredYuv, pcCU->getZorderIdxInCU(), REF_PIC_LIST_X, iPartIdx);
+#else
     motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
-    
+#endif
   } //  end of for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
 
@@ -4338,4 +4400,5 @@
   m_pcRdCost->setMultiviewReg( 0 );
 #endif
+
   setWpScalingDistParam( pcCU, iRefIdxPred, eRefPicList );
   //  Do integer search
@@ -4351,4 +4414,5 @@
   
   m_pcRdCost->getMotionCost( 1, 0 );
+
 #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
   if( ! pcCU->getSlice()->getIsDepth() )
@@ -4378,5 +4442,5 @@
     ruiCost += m_pcRdCost->getCost( uiMvBits );
 #endif
-  
+
   ruiBits      += uiMvBits;
   ruiCost       = (UInt)( floor( fWeight * ( (Double)ruiCost - (Double)m_pcRdCost->getCost( uiMvBits ) ) ) + (Double)m_pcRdCost->getCost( ruiBits ) );
@@ -4723,5 +4787,5 @@
   rcMvQter = *pcMvInt;   rcMvQter <<= 1;    // for mv-cost
   rcMvQter += rcMvHalf;  rcMvQter <<= 1;
-  ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 1, rcMvQter );
+  ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 1, rcMvQter);
 }
 
@@ -4758,5 +4822,5 @@
 #endif
   //  No residual coding : SKIP mode
-  if ( ePredMode == MODE_SKIP && bSkipRes )
+  if ( (ePredMode == MODE_SKIP && bSkipRes) )
   {
     rpcYuvResi->clear();
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSearch.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSearch.h	(revision 231)
@@ -152,5 +152,5 @@
   UInt  xPatternRefinement( TComPattern* pcPatternKey,
                            TComMv baseRefMv,
-                           Int iFrac, TComMv& rcMvFrac );
+                           Int iFrac, TComMv& rcMvFrac);
   
   typedef struct
@@ -513,4 +513,7 @@
                                     Int& numValidMergeCand
 #endif
+#if MERL_VSP_C0152
+                                  , Int* iVSPIndexTrue
+#endif
                                    );
   // -------------------------------------------------------------------------------------------------------------------
@@ -579,6 +582,5 @@
                                     TComMv&       rcMvQter,
                                     UInt&         ruiCost 
-                                   ,Bool biPred
-                                   );
+                                   ,Bool biPred);
   
   Void xExtDIFUpSamplingH( TComPattern* pcPattern, Bool biPred  );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 231)
@@ -811,4 +811,12 @@
       m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
   }
+
+#if MERL_VSP_C0152
+  // Send Depth/Texture pointers to slice level
+  pcSlice->setBWVSPLUTParam(m_aiShiftLUT, m_iShiftPrec);
+  pcSlice->setRefPicBaseTxt(m_pPicBaseTxt);
+  pcSlice->setRefPicBaseDepth(m_pPicBaseDepth);
+#endif
+
   UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
   //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
@@ -1138,4 +1146,5 @@
 
   UInt uiEncCUOrder;
+
   uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());  /*for tiles, uiStartCUAddr is NOT the real raster scan address, it is actually
                                                                                               an encoding order index, so we need to convert the index (uiStartCUAddr)
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSlice.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibEncoder/TEncSlice.h	(revision 231)
@@ -101,4 +101,13 @@
   
   UInt                    m_uiSliceIdx;
+
+#if MERL_VSP_C0152
+  // Data temporarily stored, will be sent to TComSlice level where the data will be actually used
+  TComPic* m_pPicBaseTxt;
+  TComPic* m_pPicBaseDepth;
+  Int*     m_aiShiftLUT;
+  Int      m_iShiftPrec;
+#endif
+
 public:
   TEncSlice();
@@ -128,4 +137,13 @@
   UInt    getSliceIdx()         { return m_uiSliceIdx;                    }
   Void    setSliceIdx(UInt i)   { m_uiSliceIdx = i;                       }
+
+#if MERL_VSP_C0152
+   Void     setBWVSPLUTParam    ( Int *pShiftLUT, Int iLoG2LUTPrec ) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
+   Void     setRefPicBaseTxt    ( TComPic*pPicTxt   ) { m_pPicBaseTxt = pPicTxt;    }
+   Void     setRefPicBaseDepth  ( TComPic*pPicDepth ) { m_pPicBaseDepth = pPicDepth;}
+   Void     getBWVSPLUTParam    ( Int*& pShiftLUT, Int& iShiftPrec ) { pShiftLUT = m_aiShiftLUT; iShiftPrec = m_iShiftPrec; }
+   TComPic* getRefPicBaseTxt    () { return m_pPicBaseTxt;   }
+   TComPic* getRefPicBaseDepth  () { return m_pPicBaseDepth; }
+#endif
 };
 
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenFilter.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenFilter.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenFilter.cpp	(revision 231)
@@ -1154,5 +1154,4 @@
 }
 
-
 // Down Sampling
 // Down sample luma
@@ -1224,5 +1223,4 @@
   }
 }
-
 
 Void TRenFilter::xInterpHorChroma( Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, FpChromaIntFilt fpFilter )
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenInterpFilter.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenInterpFilter.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenInterpFilter.h	(revision 231)
@@ -72,5 +72,5 @@
   __inline Void xCTI_FilterQuarter1Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
   __inline Void xCTI_FilterQuarter1Hor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
-  
+
   __inline Void xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst, Int iDstStridePel, Pel*& rpiDstPel );
   __inline Void xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst );
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenSingleModel.h
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenSingleModel.h	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenSingleModel.h	(revision 231)
@@ -33,5 +33,5 @@
 
 #if !QC_MVHEVC_B0046
-#ifndef __TRENSINGLEMODEL__ 
+#ifndef __TRENSINGLEMODEL__
 #define __TRENSINGLEMODEL__
 
Index: /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenTop.cpp
===================================================================
--- /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenTop.cpp	(revision 230)
+++ /branches/HTM-5.1-dev3-MERL/source/Lib/TLibRenderer/TRenTop.cpp	(revision 231)
@@ -193,5 +193,4 @@
 }
 
-
 Void TRenTop::xConvertOutputData( PelImage* pcOrgOutputImage, PelImage* pcConvOutputImage, Bool bMirror )
 {
@@ -1450,10 +1449,10 @@
 
     for( Int iXPos = iSourcePos + 1; iXPos <  iWidth; iXPos++)
-        {
+    {
       for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
-          {
+      {
         apcOutputData[uiCurPlane][iXPos] = apcInputData[uiCurPlane][iSourcePos];
       }
-            }
+    }
 
     // Fill Left Gap
@@ -1469,6 +1468,6 @@
       {
         apcOutputData[uiCurPlane][iXPos] = apcInputData[uiCurPlane][iSourcePos];
-          }
-        }
+      }
+    }
 
     // Go to next line
@@ -2154,5 +2153,5 @@
     {
       m_aaiSubPelShift[uiEntry] = new Int[ iNumEntries ];
-        }
+    }
 
     TRenFilter::setSubPelShiftLUT(m_iRelShiftLUTPrec, m_aaiSubPelShift, -1);
