Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 166)
@@ -1179,4 +1179,17 @@
   WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand");
 #endif
+
+#if VSP_SLICE_HEADER
+  if( pcSlice->getSPS()->getViewId()!=0 
+#if VSP_TEXT_ONLY
+      && !(pcSlice->getSPS()->isDepth()) 
+#endif
+    )
+  {
+    WRITE_FLAG( pcSlice->getVspFlag()?1:0, "vsp_flag" );
+//    printf("[VSP: %d] ", pcSlice->getVspFlag()?1:0);
+  }
+#endif
+
 }
 
@@ -1426,4 +1439,11 @@
   assert(0);
 }
+
+#if FORCE_REF_VSP==1
+Void TEncCavlc::codeVspFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
+{
+  assert(0);
+}
+#endif
 
 Void TEncCavlc::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 166)
@@ -164,4 +164,7 @@
 
   Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#if FORCE_REF_VSP==1
+  Void codeVspFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#endif
   Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCu.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCu.cpp	(revision 166)
@@ -453,4 +453,36 @@
   // get Original YUV data from picture
   m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
+#if FORCE_REF_VSP
+  //Bool bWholeCUCanBeSynthesized = false;
+  //Bool bOneSubCUCanNotBeSynthesied = false;
+  Bool bSubCUCanBeSynthesized[4];
+  if( rpcBestCU->getSlice()->getViewId() )
+  {
+    Bool * pbSubCUCanBeSynthesized = bSubCUCanBeSynthesized;
+    pcPic->checkSynthesisAvailability(/*rpcBestCU, */rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, pbSubCUCanBeSynthesized); //KUBA SYNTH
+    //Int  iSubCUCanNotBeSynthesized = 0;  // Dong: Compiling error, set but not used. DONG_CHECK
+    Int  iSubCUCanBeSynthesizedCnt = 0;
+    for(Int i = 0; i < 4; i++)
+    {
+      if (!bSubCUCanBeSynthesized[i])
+      {
+        //iSubCUCanNotBeSynthesized = i;
+      }
+      else
+      {
+        iSubCUCanBeSynthesizedCnt ++;
+      }
+    }
+    if(iSubCUCanBeSynthesizedCnt == 4)
+    {
+      //bWholeCUCanBeSynthesized = true;
+    }
+    //else if(iSubCUCanBeSynthesizedCnt == 3)
+    //{
+    //  bOneSubCUCanNotBeSynthesied = true;
+    //}
+    //bWholeCUCanBeSynthesized = true;
+  }
+#endif
 
   // variables for fast encoder decision
@@ -654,4 +686,19 @@
             doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
           }
+
+#if FORCE_REF_VSP==1
+#if VSP_TEXT_ONLY
+          if( !rpcBestCU->getSlice()->getSPS()->isDepth() )
+#endif
+#if HHI_INTER_VIEW_RESIDUAL_PRED
+            rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
+#endif
+#if HHI_INTERVIEW_SKIP
+            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec, false, true ); // VSP
+#else
+            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
+#endif
+            rpcTempCU->initEstData( uiDepth, iQP );
+#endif
         }
 #if HHI_INTER_VIEW_RESIDUAL_PRED
@@ -1581,10 +1628,26 @@
     {
       m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
+
+#if FORCE_REF_VSP==1
+      if( (pcCU->isSkipped( uiAbsPartIdx ) || pcCU->isVspMode( uiAbsPartIdx )) && pcCU->getSlice()->getViewId() != 0 )
+#if VSP_TEXT_ONLY
+      if( !pcCU->getSlice()->getSPS()->isDepth() )
+#endif
+      {
+        m_pcEntropyCoder->encodeVspFlag( pcCU, uiAbsPartIdx );
+      }
+#endif
     }
 
     if( pcCU->isSkipped( uiAbsPartIdx ) )
+#if FORCE_REF_VSP==1
+    if( !pcCU->isVspMode( uiAbsPartIdx ) )
+#endif
     {
       m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 );
       finishCU(pcCU,uiAbsPartIdx,uiDepth);
+#if DEBUGLOGOUT
+      m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
       xRestoreDepthWidthHeight( pcCU );
       return;
@@ -1635,7 +1698,20 @@
   {
     m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
+
+#if FORCE_REF_VSP==1
+    if( (pcCU->isSkipped( uiAbsPartIdx ) || pcCU->isVspMode( uiAbsPartIdx )) && pcCU->getSlice()->getViewId() != 0 )
+#if VSP_TEXT_ONLY
+    if( !pcCU->getSlice()->getSPS()->isDepth() )
+#endif
+    {
+      m_pcEntropyCoder->encodeVspFlag( pcCU, uiAbsPartIdx );
+    }
+#endif
   }
   
   if( pcCU->isSkipped( uiAbsPartIdx ) )
+#if FORCE_REF_VSP==1
+  if( !pcCU->isVspMode( uiAbsPartIdx ) )
+#endif
   {
     m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 );
@@ -1644,6 +1720,21 @@
 #endif
     finishCU(pcCU,uiAbsPartIdx,uiDepth);
+#if DEBUGLOGOUT
+    m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
     return;
   }
+
+#if FORCE_REF_VSP==1
+  if( pcCU->isVspMode( uiAbsPartIdx ) )
+  {
+    finishCU(pcCU,uiAbsPartIdx,uiDepth);
+#if DEBUGLOGOUT
+    m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
+    return;
+  }
+#endif
+
 #if HHI_MPI
   if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 )
@@ -1662,4 +1753,7 @@
       // Encode slice finish
       finishCU(pcCU,uiAbsPartIdx,uiDepth);
+#if DEBUGLOGOUT
+      m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
       return;
     }
@@ -1685,4 +1779,7 @@
   // --- write terminating bit ---
   finishCU(pcCU,uiAbsPartIdx,uiDepth);
+#if DEBUGLOGOUT
+  m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
 }
 
@@ -1873,5 +1970,9 @@
 #if AMP_MRG
 #if HHI_INTERVIEW_SKIP
-Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes, Bool bUseMRG)
+Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes, Bool bUseMRG
+#if FORCE_REF_VSP==1
+                               , Bool bForceRefVsp
+#endif
+                               )
 #else
 Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG)
@@ -1910,4 +2011,9 @@
   rpcTempCU->setResPredFlagSubParts ( bResPrdFlag,  0, 0, uhDepth );
 #endif
+#if FORCE_REF_VSP==1
+  if( bForceRefVsp )
+    rpcTempCU->setPredModeSubParts  ( MODE_SYNTH, 0, uhDepth );
+  else
+#endif
   rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
   
@@ -1925,5 +2031,9 @@
   #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
+#if FORCE_REF_VSP==1
+    , bForceRefVsp
+#endif
+    );
 #else
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG  );
@@ -2494,8 +2604,32 @@
     for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ )
     {
-      if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) )
+      if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) 
+#if FORCE_REF_VSP==1
+       || pcTextureCU->isVspMode( rpcTempCU->getZorderIdxInCU() + ui )
+#endif
+      )
       {
         return;
       }
+#if VSP_N
+#if !(!VSP_TEXT_ONLY && FORCE_REF_VSP==2)
+      else // inter
+      {
+        Int aiRefIdx[2] = {NOT_VALID, NOT_VALID};
+        for( Int iList = 0; iList < 2; iList++ )
+        {
+          aiRefIdx[iList] = pcTextureCU->getCUMvField( RefPicList(iList) )->getRefIdx( rpcTempCU->getZorderIdxInCU() + ui );
+          if( aiRefIdx[iList] >= 0 && pcTextureCU->getSlice()->getRefViewId( RefPicList(iList), aiRefIdx[iList] ) == NUM_VIEW_VSP )
+          {
+            return;
+          }
+        }
+        //if( aiRefIdx[0] == NOT_VALID && aiRefIdx[1] == NOT_VALID )
+        //{
+        //  return;
+        //}
+      }
+#endif
+#endif
     }
   }
@@ -2694,6 +2828,16 @@
   m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true );
   m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true );
+#if FORCE_REF_VSP==1
+  if( (pcCU->isSkipped( 0 ) || pcCU->isVspMode( 0 )) && pcCU->getSlice()->getViewId() != 0 )
+#if VSP_TEXT_ONLY
+  if( !pcCU->getSlice()->getSPS()->isDepth() )
+#endif
+    m_pcEntropyCoder->encodeVspFlag ( pcCU, 0, true );
+#endif
 
   if( pcCU->isSkipped( 0 ) )
+#if FORCE_REF_VSP==1
+  if( !pcCU->isVspMode( 0 ) )
+#endif
   {
     m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCu.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncCu.h	(revision 166)
@@ -46,4 +46,7 @@
 #include "TLibCommon/TComBitCounter.h"
 #include "TLibCommon/TComDataCU.h"
+#if DEBUGLOGOUT
+#include "TLibCommon/DebugLog.h"
+#endif
 
 #include "TEncEntropy.h"
@@ -113,4 +116,8 @@
 
 public:
+#if DEBUGLOGOUT
+  DebugLog                m_cDebug;
+#endif
+
   /// copy parameters from encoder class
   Void  init                ( TEncTop* pcEncTop );
@@ -148,5 +155,9 @@
 #if AMP_MRG
 #if HHI_INTERVIEW_SKIP
-  Void xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFullyRendered, Bool bUseMRG = false  ) ;
+  Void xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFullyRendered, Bool bUseMRG = false
+#if FORCE_REF_VSP==1
+    , Bool bForceRefVsp = false
+#endif
+    ) ;
 #else
   Void  xCheckRDCostInter   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG = false  );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 166)
@@ -169,4 +169,20 @@
 }
 
+
+#if FORCE_REF_VSP==1
+Void TEncEntropy::encodeVspFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
+{
+  if ( pcCU->getSlice()->isIntra() || pcCU->getSlice()->getViewId() == 0 )
+  {
+    return;
+  }
+  if( bRD )
+  {
+    uiAbsPartIdx = 0;
+  }
+  m_pcEntropyCoderIf->codeVspFlag( pcCU, uiAbsPartIdx );
+}
+#endif
+
 Void TEncEntropy::codeFiltCountBit(ALFParam* pAlfParam, Int64* ruiRate)
 {
@@ -1285,4 +1301,11 @@
     uiAbsPartIdx = 0;
   }
+
+#if FORCE_REF_VSP==1
+  if( pcCU->isVspMode( uiAbsPartIdx ) )
+  {
+    return;
+  }
+#endif
   
   PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx );
@@ -1345,6 +1368,14 @@
         {
           encodeRefFrmIdxPU ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
+#if VSP_MV_ZERO
+          Int iRefIdx = pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx(uiSubPartIdx);
+          if( !(pcCU->getSlice()->getViewId() && iRefIdx >= 0 && pcCU->getSlice()->getRefViewId( RefPicList( uiRefListIdx ), iRefIdx ) == NUM_VIEW_VSP) )
+          {
+#endif
           encodeMvdPU       ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
           encodeMVPIdxPU    ( pcCU, uiSubPartIdx, RefPicList( uiRefListIdx ) );
+#if VSP_MV_ZERO
+          }
+#endif
         }
       }
@@ -1632,4 +1663,7 @@
   {
     {
+#if FORCE_REF_VSP==1
+      if( !pcCU->isVspMode( uiAbsPartIdx ) )
+#endif
 #if HHI_MPI
       if( !(pcCU->getMergeFlag( uiAbsPartIdx ) && pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N &&
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncEntropy.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncEntropy.h	(revision 166)
@@ -115,4 +115,7 @@
   
   virtual Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
+#if FORCE_REF_VSP==1
+  virtual Void codeVspFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
+#endif
   virtual Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
   virtual Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
@@ -251,4 +254,7 @@
   Void encodeSplitFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
   Void encodeSkipFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
+#if FORCE_REF_VSP==1
+  Void encodeVspFlag           ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
+#endif
   Void encodePUWise       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
   Void encodeInterDirPU   ( TComDataCU* pcSubCU, UInt uiAbsPartIdx  );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 166)
@@ -332,6 +332,19 @@
 #endif
 
+#if VSP_N
+      Int NumberOfVspRefs = ( ( pcPic->getViewId()==0
+#if VSP_TEXT_ONLY
+                                || m_pcEncTop->getIsDepth()
+#endif
+#if VSP_SLICE_HEADER
+                                || !m_pcEncTop->getUseVSP()
+#endif
+                              ) ? 0 : 1 );
+      pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive + NumberOfVspRefs, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs() + NumberOfVspRefs) ) );
+      pcSlice->setNumRefIdx( REF_PIC_LIST_1, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive + NumberOfVspRefs, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs() + NumberOfVspRefs) ) );
+#else
       pcSlice->setNumRefIdx( REF_PIC_LIST_0, min( m_pcCfg->getGOPEntry( (getNalUnitType(uiPOCCurr) == NAL_UNIT_CODED_SLICE_IDV) ? MAX_GOP : iGOPid ).m_numRefPicsActive, (pcSlice->getRPS()->getNumberOfPictures() + pcSlice->getSPS()->getNumberOfUsableInterViewRefs()) ) );
       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()) ) );
+#endif
 
       TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
@@ -358,5 +371,19 @@
 
       std::vector<TComPic*> apcInterViewRefPics = tAppEncTop->getInterViewRefPics( m_pcEncTop->getViewId(), pcSlice->getPOC(), m_pcEncTop->getIsDepth(), pcSlice->getSPS() );
+#if VSP_N
+      Bool bUseVsp = (pcPic->getViewId()!=0);
+#if VSP_TEXT_ONLY
+      if( m_pcEncTop->getIsDepth() ) bUseVsp = false;
+#endif
+#if VSP_SLICE_HEADER
+      if( !m_pcEncTop->getUseVSP() ) bUseVsp = false;
+#endif
+      pcSlice->setRefPicListMvc( rcListPic, apcInterViewRefPics, bUseVsp ? m_pcEncTop->getVSPBuf() : NULL );
+#else
       pcSlice->setRefPicListMvc( rcListPic, apcInterViewRefPics );
+#endif
+#if VSP_SLICE_HEADER
+      pcSlice->setVspFlag( bUseVsp );
+#endif
 
       //  Slice info. refinement
@@ -1130,4 +1157,10 @@
           m_pcSbacCoder->load( &pcSbacCoders[0] );
 
+#if DEBUGLOGOUT
+        char fname[128];
+        sprintf(fname, "%sV%02d_%05d%s.csv", "Log", pcSlice->getViewId(), uiPOCCurr, pcSlice->getIsDepth() ? "depth":"text");
+        getSliceEncoder()->getCUEncoder()->m_cDebug.DebugLogFileOpen( fname );
+#endif
+
         pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength );
         if (!bEntropySlice)
@@ -1140,4 +1173,8 @@
           m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info.
         }
+
+#if DEBUGLOGOUT
+        getSliceEncoder()->getCUEncoder()->m_cDebug.DebugLogFileClose();
+#endif
 
         {
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncGOP.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncGOP.h	(revision 166)
@@ -146,4 +146,5 @@
   Void freeAPS     (TComAPS* pAPS, TComSPS* pSPS);
   Void allocAPS    (TComAPS* pAPS, TComSPS* pSPS);
+
 protected:
   Void encodeAPS   (TComAPS* pcAPS, TComOutputBitstream& APSbs, TComSlice* pcSlice);            //!< encode APS syntax elements
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 166)
@@ -718,5 +718,9 @@
 {
   // get context function is here
+#if FORCE_REF_VSP==1
+  UInt uiSymbol = (pcCU->isSkipped( uiAbsPartIdx ) || pcCU->isVspMode( uiAbsPartIdx )) ? 1 : 0;
+#else
   UInt uiSymbol = pcCU->isSkipped( uiAbsPartIdx ) ? 1 : 0;
+#endif
   UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ;
   m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
@@ -730,4 +734,21 @@
 }
 
+#if FORCE_REF_VSP==1
+Void TEncSbac::codeVspFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
+{
+  // get context function is here
+  UInt uiSymbol = (UInt)pcCU->isVspMode( uiAbsPartIdx );
+  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx ) ;
+  m_pcBinIf->encodeBin( uiSymbol, m_cCUSkipFlagSCModel.get( 0, 0, uiCtxSkip ) );
+  DTRACE_CABAC_VL( g_nSymbolCounter++ );
+  DTRACE_CABAC_T( "\tVspFlag" );
+  DTRACE_CABAC_T( "\tuiCtxSkip: ");
+  DTRACE_CABAC_V( uiCtxSkip );
+  DTRACE_CABAC_T( "\tuiSymbol: ");
+  DTRACE_CABAC_V( uiSymbol );
+  DTRACE_CABAC_T( "\n");
+}
+#endif
+
 /** code merge flag
  * \param pcCU
@@ -764,5 +785,14 @@
   uiNumCand = pcCU->getSlice()->getMaxNumMergeCand();
 #if HHI_MPI
+#if VSP_TEXT_ONLY
+  TComDataCU* pcTextCU = pcCU->getSlice()->getSPS()->getUseMVI() ? pcCU->getSlice()->getTexturePic()->getCU( pcCU->getAddr() ) : NULL;
+  Int aiRefIdxVsp[2] = { pcTextCU ? pcTextCU->getCUMvField( RefPicList(0) )->getRefIdx( uiAbsPartIdx ) : -1,
+                         pcTextCU ? pcTextCU->getCUMvField( RefPicList(1) )->getRefIdx( uiAbsPartIdx ) : -1 };
+  const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE
+    && !( aiRefIdxVsp[0] >= 0 && pcTextCU->getSlice()->getRefViewId( RefPicList(0), aiRefIdxVsp[0] ) == NUM_VIEW_VSP )
+    && !( aiRefIdxVsp[1] >= 0 && pcTextCU->getSlice()->getRefViewId( RefPicList(1), aiRefIdxVsp[1] ) == NUM_VIEW_VSP );
+#else
   const Bool bMVIAvailable = pcCU->getSlice()->getSPS()->getUseMVI() && pcCU->getSlice()->getSliceType() != I_SLICE;
+#endif
   if( bMVIAvailable )
   {
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSbac.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSbac.h	(revision 166)
@@ -202,4 +202,7 @@
   Void codeAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#if FORCE_REF_VSP==1
+  Void codeVspFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx );
+#endif
   Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 166)
@@ -683,5 +683,9 @@
 UInt TEncSearch::xPatternRefinement( TComPattern* pcPatternKey,
                                     TComMv baseRefMv,
-                                    Int iFrac, TComMv& rcMvFrac )
+                                    Int iFrac, TComMv& rcMvFrac
+#if VSP_MV_ZERO
+                                   ,Bool bIsVsp
+#endif
+                                   )
 {
   UInt  uiDist;
@@ -699,5 +703,10 @@
   TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ);
   
+#if VSP_MV_ZERO
+  UInt iAround = ( bIsVsp )? 1:9;
+  for (UInt i = 0; i < iAround; i++)
+#else
   for (UInt i = 0; i < 9; i++)
+#endif
   {
     TComMv cMvTest = pcMvRefine[i];
@@ -871,4 +880,11 @@
       {
         m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true );
+#if FORCE_REF_VSP==1
+        if( pcCU->getSlice()->getViewId() != 0 )
+#if VSP_TEXT_ONLY
+        if( !pcCU->getSlice()->getSPS()->isDepth() )
+#endif
+          m_pcEntropyCoder->encodeVspFlag ( pcCU, 0, true );
+#endif
         m_pcEntropyCoder->encodePredMode( pcCU, 0, true );
       }
@@ -2751,7 +2767,15 @@
 #if AMP_MRG
 #if LG_RESTRICTEDRESPRED_M24766
-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* rpcResiPredYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG 
+#if FORCE_REF_VSP==1
+                                 , Bool bForceRefVsp
+#endif
+                                 )
+#else
+Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes, Bool bUseMRG
+#if FORCE_REF_VSP==1
+                                 , Bool bForceRefVsp
+#endif
+                                 )
 #endif
 #else
@@ -2813,4 +2837,30 @@
 #endif
 
+#if FORCE_REF_VSP==1
+  if( bForceRefVsp )
+  {
+    assert( ePartSize == SIZE_2Nx2N );
+
+    //  Clear Motion Field
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, 0, pcCU->getDepth(0), 0 );
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, 0, pcCU->getDepth(0), 0 );
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,       ePartSize, 0, pcCU->getDepth(0), 0 );
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( cMvZero,       ePartSize, 0, pcCU->getDepth(0), 0 );
+
+    //pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx ( pcCU->getSlice()->getRefIdxVsp(REF_PIC_LIST_0), ePartSize, 0, pcCU->getDepth(0), 0 );
+    //pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx ( pcCU->getSlice()->getRefIdxVsp(REF_PIC_LIST_1), ePartSize, 0, pcCU->getDepth(0), 0 );
+
+    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, 0, 0, pcCU->getDepth(0));
+    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, 0, 0, pcCU->getDepth(0));
+    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, 0, 0, pcCU->getDepth(0));
+    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, 0, 0, pcCU->getDepth(0));
+
+    rpcPredYuv->copyFromPicYuv( pcCU->getPic()->getPicYuvSynth(), pcCU->getAddr(), pcCU->getZorderIdxInCU() );
+    setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
+
+    return;
+  }
+#endif
+
 #if ZERO_MVD_EST
   Int           aiZeroMvdMvpIdx[2] = {-1, -1};
@@ -2833,4 +2883,27 @@
 #if HHI_INTER_VIEW_MOTION_PRED
   Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
+#endif
+
+#if VSP_MV_ZERO
+  bool bIsVsp = false;
+  //Bool bWholeCUCanBeSynthesized = false;
+  //Bool bSubCUCanBeSynthesized[4];
+  //if( pcCU->getSlice()->getViewId() )
+  //{
+  //  Bool * pbSubCUCanBeSynthesized = bSubCUCanBeSynthesized;
+  //  pcCU->getPic()->checkSynthesisAvailability(/*rpcBestCU, */pcCU->getAddr(), pcCU->getZorderIdxInCU(), pcCU->getDepth(0), pbSubCUCanBeSynthesized); //KUBA SYNTH
+  //  Int  iSubCUCanBeSynthesizedCnt = 0;
+  //  for(Int i = 0; i < 4; i++)
+  //  {
+  //    if (bSubCUCanBeSynthesized[i])
+  //    {
+  //      iSubCUCanBeSynthesizedCnt ++;
+  //    }
+  //  }
+  //  if(iSubCUCanBeSynthesizedCnt == 4)
+  //  {
+  //    bWholeCUCanBeSynthesized = true;
+  //  }
+  //}
 #endif
 
@@ -2857,4 +2930,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};
@@ -2885,4 +2959,11 @@
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
+#if VSP_MV_ZERO
+        bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp) == NUM_VIEW_VSP);
+        //if( bIsVsp && !bWholeCUCanBeSynthesized )
+        //{
+        //  continue;
+        //}
+#endif
 #if LG_RESTRICTEDRESPRED_M24766
         if( pcCU->getResPredFlag( 0 ))
@@ -2908,4 +2989,14 @@
           if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
         }
+#if VSP_MV_ZERO
+        if( bIsVsp )
+        {
+          aaiMvpIdx[iRefList][iRefIdxTemp] = -1;
+          aaiMvpNum[iRefList][iRefIdxTemp] = -1;
+          cMvPred[iRefList][iRefIdxTemp].setZero();
+        }
+        else
+        {
+#endif
 #if H0111_MVD_L1_ZERO
 #if ZERO_MVD_EST
@@ -2937,4 +3028,7 @@
 #else
         uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
+#endif
+#if VSP_MV_ZERO
+        } // if( bIsVsp )
 #endif
 #if ZERO_MVD_EST
@@ -2973,8 +3067,20 @@
               else
               {
+#if VSP_MV_ZERO
+                if( pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp) == NUM_VIEW_VSP )
+                {
+                  cMvTemp[1][iRefIdxTemp].setZero();
+                  uiCostTemp = 0;
+                }
+                else
+                {
+#endif
                 cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)]; 
                 uiCostTemp = uiCostTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)];
                 /*first subtract the bit-rate part of the cost of the other list*/
                 uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)] );
+#if VSP_MV_ZERO
+                }
+#endif
               }
               /*correct the bit-rate part of the current ref*/
@@ -2986,5 +3092,9 @@
             else
             {
+#if VSP_MV_ZERO
+              xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], bIsVsp, uiBitsTemp, uiCostTemp );
+#else
               xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
+#endif
             }
         }
@@ -2998,9 +3108,21 @@
           else
           { 
+#if VSP_MV_ZERO
+            xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], bIsVsp, uiBitsTemp, uiCostTemp );
+#else
             xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
+#endif
           }        
         }
 #else
         xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
+#endif
+#if VSP_MV_ZERO
+        if( bIsVsp )
+        {
+          cMvPred[iRefList][iRefIdxTemp].setZero();
+        }
+        else
+        {
 #endif
         xCopyAMVPInfo(pcCU->getCUMvField(eRefPicList)->getAMVPInfo(), &aacAMVPInfo[iRefList][iRefIdxTemp]); // must always be done ( also when AMVP_MODE = AM_NONE )
@@ -3009,4 +3131,7 @@
           xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
         }
+#if VSP_MV_ZERO
+        }
+#endif
 
         if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && !pcCU->getSlice()->getNoBackPredFlag())
@@ -3088,8 +3213,21 @@
       if(pcCU->getSlice()->getMvdL1ZeroFlag())
       {
+#if VSP_MV_ZERO
+        bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_1, bestBiPRefIdxL1) == NUM_VIEW_VSP);
+
+        if( bIsVsp )
+        {
+          cMvPredBi[1][bestBiPRefIdxL1].setZero();
+        }
+        else
+        {
+#endif
         xCopyAMVPInfo(&aacAMVPInfo[1][bestBiPRefIdxL1], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo());
         pcCU->setMVPIdxSubParts( bestBiPMvpL1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
         aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1;
         cMvPredBi[1][bestBiPRefIdxL1]   = pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo()->m_acMvCand[bestBiPMvpL1];
+#if VSP_MV_ZERO
+        }
+#endif
 
         cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1];
@@ -3109,8 +3247,15 @@
         }
 
+#if VSP_MV_ZERO
+        if( !bIsVsp )
+        {
+#endif
 #if HHI_INTER_VIEW_MOTION_PRED
         uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][iNumAMVPCands];
 #else
         uiMotBits[1] += m_auiMVPIdxCost[aaiMvpIdxBi[1][bestBiPRefIdxL1]][AMVP_MAX_NUM_CANDS];
+#endif
+#if VSP_MV_ZERO
+        }
 #endif
 
@@ -3168,4 +3313,11 @@
         for ( Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ )
         {
+#if VSP_MV_ZERO
+          bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp) == NUM_VIEW_VSP);
+          //if( bIsVsp && !bWholeCUCanBeSynthesized )
+          //{
+          //  continue;
+          //}
+#endif
           uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList];
           if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
@@ -3174,8 +3326,15 @@
             if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
           }
+#if VSP_MV_ZERO
+          if( !bIsVsp )
+          {
+#endif
 #if HHI_INTER_VIEW_MOTION_PRED
           uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][iNumAMVPCands];
 #else
           uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
+#endif
+#if VSP_MV_ZERO
+          }
 #endif
 #if LG_RESTRICTEDRESPRED_M24766
@@ -3211,5 +3370,13 @@
 #endif
           // call ME
+#if VSP_MV_ZERO
+          xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], bIsVsp, uiBitsTemp, uiCostTemp, true );
+#else
           xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp, true );
+#endif
+#if VSP_MV_ZERO
+          if( !bIsVsp )
+          {
+#endif
           if ( pcCU->getAMVPMode(uiPartAddr) == AM_EXPL )
           {
@@ -3217,5 +3384,8 @@
             xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
           }
-          
+#if VSP_MV_ZERO
+          }
+#endif
+
           if ( uiCostTemp < uiCostBi )
           {
@@ -3249,12 +3419,30 @@
           if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] && pcCU->getAMVPMode(uiPartAddr) == AM_EXPL )
           {
+#if VSP_MV_ZERO
+            bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_0, iRefIdxBi[0]) == NUM_VIEW_VSP);
+
+            if( !bIsVsp )
+            {
+#endif
             xCopyAMVPInfo(&aacAMVPInfo[0][iRefIdxBi[0]], pcCU->getCUMvField(REF_PIC_LIST_0)->getAMVPInfo());
             xCheckBestMVP(pcCU, REF_PIC_LIST_0, cMvBi[0], cMvPredBi[0][iRefIdxBi[0]], aaiMvpIdxBi[0][iRefIdxBi[0]], uiBits[2], uiCostBi);
+#if VSP_MV_ZERO
+            }
+#endif
 #if H0111_MVD_L1_ZERO
             if(!pcCU->getSlice()->getMvdL1ZeroFlag())
             {
 #endif
+#if VSP_MV_ZERO
+              bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_1, iRefIdxBi[1]) == NUM_VIEW_VSP);
+
+              if( !bIsVsp )
+              {
+#endif
               xCopyAMVPInfo(&aacAMVPInfo[1][iRefIdxBi[1]], pcCU->getCUMvField(REF_PIC_LIST_1)->getAMVPInfo());
               xCheckBestMVP(pcCU, REF_PIC_LIST_1, cMvBi[1], cMvPredBi[1][iRefIdxBi[1]], aaiMvpIdxBi[1][iRefIdxBi[1]], uiBits[2], uiCostBi);
+#if VSP_MV_ZERO
+              }
+#endif
 #if H0111_MVD_L1_ZERO
             }
@@ -3417,8 +3605,22 @@
       pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
       
+#if VSP_MV_ZERO
+      bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_0, iRefIdxBi[0]) == NUM_VIEW_VSP);
+      if( !bIsVsp )
+      {
+#endif
       pcCU->setMVPIdxSubParts( aaiMvpIdxBi[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
       pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdxBi[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+#if VSP_MV_ZERO
+      }
+      bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_1, iRefIdxBi[1]) == NUM_VIEW_VSP);
+      if( !bIsVsp )
+      {
+#endif
       pcCU->setMVPIdxSubParts( aaiMvpIdxBi[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
       pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdxBi[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+#if VSP_MV_ZERO
+      }
+#endif
 
       uiMEBits = uiBits[2];
@@ -3435,6 +3637,14 @@
       pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
       
+#if VSP_MV_ZERO
+      bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_0, iRefIdx[0]) == NUM_VIEW_VSP);
+      if( !bIsVsp )
+      {
+#endif
       pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
       pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+#if VSP_MV_ZERO
+      }
+#endif
 
       uiMEBits = uiBits[0];
@@ -3451,6 +3661,14 @@
       pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
       
+#if VSP_MV_ZERO
+      bIsVsp = (pcCU->getSlice()->getViewId() && pcCU->getSlice()->getRefViewId(REF_PIC_LIST_1, iRefIdx[1]) == NUM_VIEW_VSP);
+      if( !bIsVsp )
+      {
+#endif
       pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
       pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+#if VSP_MV_ZERO
+      }
+#endif
 
       uiMEBits = uiBits[1];
@@ -3888,5 +4106,9 @@
 }
 
+#if VSP_MV_ZERO
+Void TEncSearch::xMotionEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, RefPicList eRefPicList, TComMv* pcMvPred, Int iRefIdxPred, TComMv& rcMv, Bool bIsVsp, UInt& ruiBits, UInt& ruiCost, Bool bBi  )
+#else
 Void TEncSearch::xMotionEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, RefPicList eRefPicList, TComMv* pcMvPred, Int iRefIdxPred, TComMv& rcMv, UInt& ruiBits, UInt& ruiCost, Bool bBi  )
+#endif
 {
   UInt          uiPartAddr;
@@ -3901,5 +4123,9 @@
   m_iSearchRange = m_aaiAdaptSR[eRefPicList][iRefIdxPred];
   
+#if VSP_MV_ZERO
+  Int           iSrchRng      = ( bIsVsp ? 0 : ( bBi ? m_bipredSearchRange : m_iSearchRange ) );
+#else
   Int           iSrchRng      = ( bBi ? m_bipredSearchRange : m_iSearchRange );
+#endif
   TComPattern*  pcPatternKey  = pcCU->getPattern        ();
   
@@ -3947,4 +4173,7 @@
   m_pcRdCost->setCostScale  ( 2 );
 
+#if VSP_MV_ZERO
+  if( !bIsVsp )
+#endif
 #if HHI_INTER_VIEW_MOTION_PRED
   { // init inter-view regularization
@@ -3965,8 +4194,17 @@
   }
 #endif
+#if VSP_MV_ZERO
+  else { // bIsVsp
+    m_pcRdCost->setMultiviewReg( 0 );
+  }
+#endif
 
   setWpScalingDistParam( pcCU, iRefIdxPred, eRefPicList );
   //  Do integer search
+#if VSP_MV_ZERO
+  if ( !m_iFastSearch || bBi || bIsVsp )
+#else
   if ( !m_iFastSearch || bBi )
+#endif
   {
     xPatternSearch      ( pcPatternKey, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
@@ -3979,4 +4217,5 @@
   
   m_pcRdCost->getMotionCost( 1, 0 );
+
 #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC
   if( ! pcCU->getSlice()->getIsDepth() )
@@ -3988,4 +4227,7 @@
     xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost
                           ,bBi
+#if VSP_MV_ZERO
+                          ,bIsVsp
+#endif
                           );
   }
@@ -4006,5 +4248,12 @@
     ruiCost += m_pcRdCost->getCost( uiMvBits );
 #endif
-  
+
+#if VSP_MV_ZERO
+  if( bIsVsp ) {
+    uiMvBits = 0; // vector zero & not output
+    assert( rcMv.getHor()==0 && rcMv.getVer()==0 );
+  }
+#endif
+
   ruiBits      += uiMvBits;
   ruiCost       = (UInt)( floor( fWeight * ( (Double)ruiCost - (Double)m_pcRdCost->getCost( uiMvBits ) ) ) + (Double)m_pcRdCost->getCost( ruiBits ) );
@@ -4304,4 +4553,7 @@
                                        UInt& ruiCost
                                        ,Bool biPred
+#if VSP_MV_ZERO
+                                       ,Bool bIsVsp
+#endif
                                        )
 {
@@ -4322,5 +4574,9 @@
   rcMvHalf = *pcMvInt;   rcMvHalf <<= 1;    // for mv-cost
   TComMv baseRefMv(0, 0);
-  ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 2, rcMvHalf   );
+  ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 2, rcMvHalf
+#if VSP_MV_ZERO
+                                   ,bIsVsp
+#endif
+    );
   
   m_pcRdCost->setCostScale( 0 );
@@ -4332,5 +4588,9 @@
   rcMvQter = *pcMvInt;   rcMvQter <<= 1;    // for mv-cost
   rcMvQter += rcMvHalf;  rcMvQter <<= 1;
-  ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 1, rcMvQter );
+  ruiCost = xPatternRefinement( pcPatternKey, baseRefMv, 1, rcMvQter
+#if VSP_MV_ZERO
+                                   ,bIsVsp
+#endif
+    );
 }
 
@@ -4367,5 +4627,9 @@
 #endif
   //  No residual coding : SKIP mode
-  if ( ePredMode == MODE_SKIP && bSkipRes )
+  if ( (ePredMode == MODE_SKIP && bSkipRes) 
+#if FORCE_REF_VSP==1
+    || ePredMode == MODE_SYNTH
+#endif
+    )
   {
     rpcYuvResi->clear();
@@ -5737,4 +6001,11 @@
     m_pcEntropyCoder->resetBits();
     m_pcEntropyCoder->encodeSkipFlag(pcCU, 0, true);
+#if FORCE_REF_VSP==1
+    if( pcCU->getSlice()->getViewId() != 0 )
+#if VSP_TEXT_ONLY
+    if( !pcCU->getSlice()->getSPS()->isDepth() )
+#endif
+      m_pcEntropyCoder->encodeVspFlag ( pcCU, 0, true );
+#endif
     m_pcEntropyCoder->encodeMergeIndex(pcCU, 0, 0, true);
 #if HHI_INTER_VIEW_RESIDUAL_PRED
@@ -5743,4 +6014,13 @@
     ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
   }
+#if FORCE_REF_VSP==1
+  else if( pcCU->isVspMode( 0 ) )
+  {
+    m_pcEntropyCoder->resetBits();
+    m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true );
+    m_pcEntropyCoder->encodeVspFlag ( pcCU, 0, true );
+    ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
+  }
+#endif
   else
   {
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSearch.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncSearch.h	(revision 166)
@@ -144,5 +144,9 @@
   UInt  xPatternRefinement( TComPattern* pcPatternKey,
                            TComMv baseRefMv,
-                           Int iFrac, TComMv& rcMvFrac );
+                           Int iFrac, TComMv& rcMvFrac
+#if VSP_MV_ZERO
+                          ,Bool bIsVsp
+#endif
+                          );
   
   typedef struct
@@ -197,4 +201,7 @@
 #if AMP_MRG
                                  ,Bool        bUseMRG = false
+#endif
+#if FORCE_REF_VSP==1
+                                 ,Bool        bForceRefVsp = false
 #endif
                                 );
@@ -486,4 +493,7 @@
                                     Int           iRefIdxPred,
                                     TComMv&       rcMv,
+#if VSP_MV_ZERO
+                                    Bool          bIsVsp,
+#endif
                                     UInt&         ruiBits,
                                     UInt&         ruiCost,
@@ -531,4 +541,7 @@
                                     UInt&         ruiCost 
                                    ,Bool biPred
+#if VSP_MV_ZERO
+                                   ,Bool bIsVsp
+#endif
                                    );
   
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 166)
@@ -79,4 +79,14 @@
   m_pcBitCounters          = NULL;
   m_pcRdCosts              = NULL;
+
+#if VSP_N
+  m_pcPicVSP = NULL;
+  m_pcPicAvail = NULL;
+#endif
+
+#if VSP_SLICE_HEADER
+  m_bUseVSP = false;
+#endif
+
 }
 
@@ -184,4 +194,18 @@
   }
 #endif
+
+#if VSP_N
+  m_pcPicVSP = new TComPic;
+  m_pcPicVSP->create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  //m_pcPicVSP->getCurrSlice()->setViewId( this->getViewId() );
+  m_pcPicVSP->getCurrSlice()->setViewId( NUM_VIEW_VSP );
+  m_pcPicVSP->getCurrSlice()->setViewOrderIdx( m_iViewOrderIdx );
+
+  m_pcPicAvail = new TComPic;
+  m_pcPicAvail->create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  m_pcPicAvail->getCurrSlice()->setViewId( 99 );
+  m_pcPicAvail->getCurrSlice()->setViewOrderIdx( m_iViewOrderIdx );
+#endif
+
 }
 
@@ -325,4 +349,19 @@
   }
   
+#if VSP_N
+  if( m_pcPicVSP )
+  {
+    m_pcPicVSP->destroy();
+    delete m_pcPicVSP;
+    m_pcPicVSP = NULL;
+  }
+  if( m_pcPicAvail )
+  {
+    m_pcPicAvail->destroy();
+    delete m_pcPicAvail;
+    m_pcPicAvail = NULL;
+  }
+#endif
+
   return;
 }
@@ -391,4 +430,51 @@
 
   m_iMaxRefPicNum = 0;
+
+#if VSP_N
+  m_pcPicVSP->setCurrSliceIdx( 0 );
+  m_pcPicVSP->getCurrSlice()->setSPS( this->getSPS() );
+  m_pcPicVSP->getCurrSlice()->setPPS( this->getPPS() );
+  m_pcPicVSP->getCurrSlice()->setPPSId( this->getPPS()->getPPSId() );
+  //initialize the motion vector field with zeros - How about the RefIdx ????
+  //IS THIS REALLY NECESSARY ????
+  for ( int i=0; i<m_pcPicVSP->getPicSym()->getNumberOfCUsInFrame(); i++ )
+  {
+    m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
+    m_pcPicVSP->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
+  }
+#if DEPTH_MAP_GENERATION
+#if !QC_MULTI_DIS_CAN
+  // add extra pic buffers
+  Bool  bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 );
+  if( bNeedPrdDepthMapBuf && !m_pcPicVSP->getPredDepthMap() )
+  {
+    m_pcPicVSP->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
+    m_cDepthMapGenerator.clearDepthMap( m_pcPicVSP );
+  }
+#endif
+#endif
+  m_pcPicAvail->setCurrSliceIdx( 0 );
+  m_pcPicAvail->getCurrSlice()->setSPS( this->getSPS() );
+  m_pcPicAvail->getCurrSlice()->setPPS( this->getPPS() );
+  m_pcPicAvail->getCurrSlice()->setPPSId( this->getPPS()->getPPSId() );
+  //initialize the motion vector field with zeros - How about the RefIdx ????
+  //IS THIS REALLY NECESSARY ????
+  for ( int i=0; i<m_pcPicAvail->getPicSym()->getNumberOfCUsInFrame(); i++ )
+  {
+    m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(0))->clearMvField();
+    m_pcPicAvail->getPicSym()->getCU(i)->getCUMvField(RefPicList(1))->clearMvField();
+  }
+#if DEPTH_MAP_GENERATION
+#if !QC_MULTI_DIS_CAN
+  // add extra pic buffers
+  bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 );
+  if( bNeedPrdDepthMapBuf && !m_pcPicVSP->getPredDepthMap() )
+  {
+    m_pcPicAvail->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
+    m_cDepthMapGenerator.clearDepthMap( m_pcPicAvail );
+  }
+#endif
+#endif
+#endif
 }
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibEncoder/TEncTop.h	(revision 166)
@@ -145,4 +145,13 @@
   TEncAnalyze             m_cAnalyzeB;
 
+#if VSP_N
+  TComPic*                m_pcPicVSP;                     ///< view synthesis prediction buffer for current POC to be coded
+  TComPic*                m_pcPicAvail;
+#endif
+
+#if VSP_SLICE_HEADER
+  Bool                    m_bUseVSP;
+#endif
+
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -237,4 +246,13 @@
   TComResidualGenerator*  getResidualGenerator  () { return  &m_cResidualGenerator;   }
 #endif
+#if VSP_N
+  TComPic*                getVSPBuf             () { return m_pcPicVSP; }
+  TComPic*                getVSPAvailBuf        () { return m_pcPicAvail; }
+#endif
+
+#if VSP_SLICE_HEADER
+  Void                    setUseVSP   ( Bool val ) { m_bUseVSP = val; }
+  Bool                    getUseVSP             () { return m_bUseVSP; }
+#endif
 
   // -------------------------------------------------------------------------------------------------------------------
