Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 166)
@@ -2348,4 +2348,16 @@
 #endif
 
+#if VSP_SLICE_HEADER
+  if( rpcSlice->getSPS()->getViewId()!=0 
+#if VSP_TEXT_ONLY
+      && !(rpcSlice->getSPS()->isDepth()) 
+#endif
+    )
+  {
+    READ_FLAG( uiCode, "vsp_flag" );
+    rpcSlice->setVspFlag( uiCode ? true : false );
+  }
+#endif
+
   if (!bEntropySlice)
   {
@@ -2601,4 +2613,11 @@
 }
 
+#if FORCE_REF_VSP==1
+Void TDecCavlc::parseVspFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  assert(0);
+}
+#endif
+
 #if HHI_INTER_VIEW_MOTION_PRED
 Void TDecCavlc::parseMVPIdx( Int& riMVPIdx, Int iAMVPCands )
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 166)
@@ -142,4 +142,7 @@
   
   Void  parseSkipFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#if FORCE_REF_VSP==1
+  Void  parseVspFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
   Void parseMergeFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
   Void parseMergeIndex      ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 166)
@@ -52,4 +52,8 @@
   m_ppcYuvResPred = NULL;
 #endif
+#if FORCE_REF_VSP
+  m_ppcYuvAvail   = NULL;
+  m_ppcYuvSynth   = NULL;
+#endif
   m_ppcCU      = NULL;
 }
@@ -79,4 +83,8 @@
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   m_ppcYuvResPred = new TComYuv*   [m_uiMaxDepth-1];
+#endif
+#if FORCE_REF_VSP
+  m_ppcYuvAvail   = new TComYuv*    [m_uiMaxDepth-1];
+  m_ppcYuvSynth   = new TComYuv*    [m_uiMaxDepth-1];
 #endif
   m_ppcCU      = new TComDataCU*[m_uiMaxDepth-1];
@@ -94,4 +102,8 @@
     m_ppcYuvResPred[ui] = new TComYuv;    m_ppcYuvResPred[ui]->create( uiWidth, uiHeight );
 #endif
+#if FORCE_REF_VSP
+    m_ppcYuvAvail  [ui] = new TComYuv;    m_ppcYuvAvail  [ui]->create( uiWidth, uiHeight );
+    m_ppcYuvSynth  [ui] = new TComYuv;    m_ppcYuvSynth  [ui]->create( uiWidth, uiHeight );
+#endif
     m_ppcCU     [ui] = new TComDataCU; m_ppcCU     [ui]->create( uiNumPartitions, uiWidth, uiHeight, true, uiMaxWidth >> (m_uiMaxDepth - 1) );
   }
@@ -118,4 +130,8 @@
     m_ppcYuvResPred[ui]->destroy(); delete m_ppcYuvResPred[ui]; m_ppcYuvResPred[ui] = NULL;
 #endif
+#if FORCE_REF_VSP
+    m_ppcYuvAvail  [ui]->destroy(); delete m_ppcYuvAvail  [ui]; m_ppcYuvAvail  [ui] = NULL;
+    m_ppcYuvSynth  [ui]->destroy(); delete m_ppcYuvSynth  [ui]; m_ppcYuvSynth  [ui] = NULL;
+#endif
     m_ppcCU     [ui]->destroy(); delete m_ppcCU     [ui]; m_ppcCU     [ui] = NULL;
   }
@@ -125,4 +141,8 @@
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   delete [] m_ppcYuvResPred; m_ppcYuvResPred = NULL;
+#endif
+#if FORCE_REF_VSP
+  delete [] m_ppcYuvAvail;   m_ppcYuvAvail   = NULL;
+  delete [] m_ppcYuvSynth;   m_ppcYuvSynth   = NULL;
 #endif
   delete [] m_ppcCU     ; m_ppcCU      = NULL;
@@ -328,7 +348,20 @@
   {
     m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
+
+#if FORCE_REF_VSP==1
+    if( pcCU->isSkipped(uiAbsPartIdx) && pcCU->getSlice()->getViewId() != 0 )
+#if VSP_TEXT_ONLY
+    if( !pcCU->getSlice()->getSPS()->isDepth() )
+#endif
+    {
+      m_pcEntropyDecoder->decodeVspFlag( pcCU, uiAbsPartIdx, uiDepth );
+    }
+#endif
   }
  
   if( pcCU->isSkipped(uiAbsPartIdx) )
+#if FORCE_REF_VSP==1
+  if( !pcCU->isVspMode(uiAbsPartIdx) )
+#endif
   {
     m_ppcCU[uiDepth]->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
@@ -352,6 +385,14 @@
     if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == uiDepth )
     {
+#if DEBUGLOGOUT
+      PredMode   eOrgPred = pcCU->getPredictionMode( uiAbsPartIdx );
+#endif
       TComDataCU *pcTextureCU = pcCU->getSlice()->getTexturePic()->getCU( pcCU->getAddr() );
       pcCU->copyTextureMotionDataFrom( pcTextureCU, uiDepth, pcCU->getZorderIdxInCU() + uiAbsPartIdx, uiAbsPartIdx );
+#if DEBUGLOGOUT
+      if( eOrgPred == MODE_SKIP )
+        pcCU->setPredModeSubParts( MODE_SKIP, uiAbsPartIdx, uiDepth );
+      m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
 
       UInt uiCurrPartNumb = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
@@ -396,6 +437,45 @@
 #endif
     xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
+#if DEBUGLOGOUT
+#if HHI_MPI
+    if( pcCU->getTextureModeDepth( uiAbsPartIdx ) != uiDepth )
+#endif
+      m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
     return;
   }
+
+#if FORCE_REF_VSP==1
+  if( pcCU->isVspMode( uiAbsPartIdx ) )
+  {
+    TComMv cMvZero;
+
+    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
+    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
+
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), SIZE_2Nx2N, uiAbsPartIdx, uiDepth, 0 );
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), SIZE_2Nx2N, uiAbsPartIdx, uiDepth, 0 );
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,       SIZE_2Nx2N, uiAbsPartIdx, uiDepth, 0 );
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( cMvZero,       SIZE_2Nx2N, uiAbsPartIdx, uiDepth, 0 );
+
+    //pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx ( pcCU->getSlice()->getRefIdxVsp(REF_PIC_LIST_0), SIZE_2Nx2N, 0, pcCU->getDepth(0), 0 );
+    //pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx ( pcCU->getSlice()->getRefIdxVsp(REF_PIC_LIST_1), SIZE_2Nx2N, 0, pcCU->getDepth(0), 0 );
+
+    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiAbsPartIdx, 0, uiDepth );
+    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiAbsPartIdx, 0, uiDepth );
+    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiAbsPartIdx, 0, uiDepth );
+    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiAbsPartIdx, 0, uiDepth );
+
+    pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
+    pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
+    pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth );
+
+    xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
+#if DEBUGLOGOUT
+    m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
+    return;
+  }
+#endif
 
 #if HHI_MPI
@@ -428,4 +508,7 @@
     {
       xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
+#if DEBUGLOGOUT
+      m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
       return;
     }
@@ -527,4 +610,7 @@
   setdQPFlag( bCodeDQP );
   xFinishDecodeCU( pcCU, uiAbsPartIdx, uiDepth, ruiIsLast );
+#if DEBUGLOGOUT
+  m_cDebug.DebugLogOut( pcCU, uiAbsPartIdx, uiDepth );
+#endif
 }
 
@@ -553,4 +639,8 @@
 {
   TComPic* pcPic = pcCU->getPic();
+#if FORCE_REF_VSP
+  if(pcPic->getPicYuvSynth())  m_ppcYuvSynth[uiDepth]->copyFromPicYuv( pcPic->getPicYuvSynth(), pcCU->getAddr(), uiAbsPartIdx );
+  if(pcPic->getPicYuvAvail())  m_ppcYuvAvail[uiDepth]->copyFromPicYuv( pcPic->getPicYuvAvail(), pcCU->getAddr(), uiAbsPartIdx );
+#endif
   
   Bool bBoundary = false;
@@ -603,4 +693,9 @@
       xReconIntraQT( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
       break;
+#if FORCE_REF_VSP==1
+    case MODE_SYNTH:
+      m_ppcYuvReco[uiDepth]->copyFromPicYuv(pcPic->getPicYuvSynth(), pcCU->getAddr(), uiAbsPartIdx);
+      break;
+#endif
     default:
       assert(0);
@@ -615,4 +710,7 @@
   
   xCopyToPic( m_ppcCU[uiDepth], pcPic, uiAbsPartIdx, uiDepth );
+#if DEBUGIMGOUT
+  xColsetToPicMerge( m_ppcCU[uiDepth], pcPic->getPicYuvRecDbg(), uiAbsPartIdx, uiDepth );
+#endif
 }
 
@@ -626,5 +724,4 @@
   // inter prediction
   m_pcPrediction->motionCompensation( pcCU, m_ppcYuvReco[uiDepth] );
-  
 #if HHI_MPI
   if( pcCU->getTextureModeDepth( 0 ) != -1 )
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCu.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecCu.h	(revision 166)
@@ -46,4 +46,7 @@
 #include "TLibCommon/TComPrediction.h"
 #include "TDecEntropy.h"
+#if DEBUGIMGOUT || DEBUGLOGOUT
+#include "TLibCommon/DebugLog.h"
+#endif
 
 //! \ingroup TLibDecoder
@@ -64,4 +67,8 @@
   TComYuv**           m_ppcYuvResPred;    ///< residual prediction buffer
 #endif
+#if VSP_N
+  TComYuv**           m_ppcYuvAvail;      ///< array of available map buffer
+  TComYuv**           m_ppcYuvSynth;      ///< array of synth buffer
+#endif
   TComDataCU**        m_ppcCU;            ///< CU data array
   
@@ -77,4 +84,8 @@
   virtual ~TDecCu();
   
+#if DEBUGLOGOUT
+  DebugLog            m_cDebug;
+#endif
+
   /// initialize access channels
   Void  init                    ( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction );
@@ -121,4 +132,8 @@
   Void xFillPCMBuffer           (TComDataCU* pCU, UInt absPartIdx, UInt depth);
 #endif
+#if DEBUGIMGOUT
+  Void xColsetToPic             ( TComDataCU* pcCU, TComPicYuv* pcPicYuv, UInt uiZorderIdx, UInt uiDepth );
+  Void xColsetToPicMerge        ( TComDataCU* pcCU, TComPicYuv* pcPicYuv, UInt uiZorderIdx, UInt uiDepth );
+#endif
 };
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 166)
@@ -54,4 +54,11 @@
 }
 
+#if FORCE_REF_VSP==1
+Void TDecEntropy::decodeVspFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  m_pcEntropyDecoderIf->parseVspFlag( pcCU, uiAbsPartIdx, uiDepth );
+}
+#endif
+
 /** decode merge flag
  * \param pcSubCU
@@ -301,6 +308,21 @@
         {
           decodeRefFrmIdxPU( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, 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) )
+          {
+            pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( TComMv(0, 0), pcCU->getPartitionSize( uiSubPartIdx ), uiSubPartIdx, uiDepth, uiPartIdx );
+            pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMv ( TComMv(0, 0), pcCU->getPartitionSize( uiSubPartIdx ), uiSubPartIdx, uiDepth, uiPartIdx );
+            pcCU->setMVPIdxSubParts( -1, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, pcCU->getDepth(uiSubPartIdx));
+            pcCU->setMVPNumSubParts( -1, RefPicList( uiRefListIdx ), uiSubPartIdx, uiPartIdx, pcCU->getDepth(uiSubPartIdx));
+          }
+          else
+          {
+#endif
           decodeMvdPU      ( pcCU,    uiSubPartIdx,              uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
           decodeMVPIdxPU   ( pcSubCU, uiSubPartIdx-uiAbsPartIdx, uiDepth, uiPartIdx, RefPicList( uiRefListIdx ) );
+#if VSP_MV_ZERO
+          }
+#endif
         }
       }
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecEntropy.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecEntropy.h	(revision 166)
@@ -103,4 +103,7 @@
 public:
   virtual Void parseSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
+#if FORCE_REF_VSP==1
+  virtual Void parseVspFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
+#endif
   virtual Void parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   virtual Void parseMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) = 0;
@@ -196,4 +199,7 @@
   Void decodeSplitFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void decodeSkipFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#if FORCE_REF_VSP==1
+  Void decodeVspFlag           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
   Void decodeMergeFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
   Void decodeMergeIndex        ( TComDataCU* pcSubCU, UInt uiPartIdx, UInt uiPartAddr, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 166)
@@ -578,4 +578,30 @@
 }
 
+#if FORCE_REF_VSP==1
+Void TDecSbac::parseVspFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  if( pcCU->getSlice()->isIntra() || pcCU->getSlice()->getViewId()==0 )
+  {
+    return;
+  }
+  
+  UInt uiSymbol = 0;
+  UInt uiCtxSkip = pcCU->getCtxSkipFlag( uiAbsPartIdx );
+  m_pcTDecBinIf->decodeBin( 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");
+  
+  if( uiSymbol )
+  {
+    pcCU->setPredModeSubParts( MODE_SYNTH, uiAbsPartIdx, uiDepth );
+  }
+}
+#endif
+
 /** parse merge flag
  * \param pcCU
@@ -610,5 +636,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
   const UInt uiMviMergePos = bMVIAvailable ? HHI_MPI_MERGE_POS : uiNumCand;
 #endif
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSbac.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSbac.h	(revision 166)
@@ -166,4 +166,7 @@
 
   Void parseSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#if FORCE_REF_VSP==1
+  Void parseVspFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+#endif
   Void parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void parseMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 166)
@@ -102,4 +102,9 @@
   rpcPic->setPicYuvResi( 0 );
   
+#if DEBUGLOGOUT
+  char fname[128];
+  sprintf(fname, "%sV%02d_%05d%s.csv", "DecLog", rpcPic->getSlice(0)->getViewId(), rpcPic->getPOC(), rpcPic->getSlice(0)->getIsDepth() ? "depth":"text");
+  m_pcCuDecoder->m_cDebug.DebugLogFileOpen( fname );
+#endif
 #if ENC_DEC_TRACE
   g_bJustDoIt = g_bEncDecTraceEnable;
@@ -439,4 +444,7 @@
 #endif
   }
+#if DEBUGLOGOUT
+  m_pcCuDecoder->m_cDebug.DebugLogFileClose();
+#endif
 
 }
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 166)
@@ -56,4 +56,13 @@
     m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
   }
+
+#if VSP_N
+  xCreateLUTs( (UInt)MAX_VIEW_NUM, (UInt)MAX_VIEW_NUM, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
+  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
+  m_uiBitDepthForLUT = 8; //fixed
+#if NTT_SUBPEL
+  xCreateLUTs_Subpel( (UInt)MAX_VIEW_NUM, (UInt)MAX_VIEW_NUM,  m_aiBaseViewShiftLUT_ipel,  m_aiBaseViewShiftLUT_fpos);
+#endif
+#endif
 }
 
@@ -69,4 +78,13 @@
   delete [] m_aiViewOrderIndex;
   delete [] m_aiViewReceived;
+
+#if VSP_N
+  xDeleteArray( m_adBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
+  xDeleteArray( m_aiBaseViewShiftLUT, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
+#if NTT_SUBPEL
+  xDeleteArray( m_aiBaseViewShiftLUT_ipel, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
+  xDeleteArray( m_aiBaseViewShiftLUT_fpos, MAX_VIEW_NUM, MAX_VIEW_NUM, 2 );
+#endif
+#endif
 }
 
@@ -82,4 +100,184 @@
   m_uiMaxViewId             = 0;
 }
+
+#if VSP_N
+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
+#if POZNAN_NONLINEAR_DEPTH
+    Double  dShiftLuma;
+    if( m_bUseNonlinearDepth )
+      dShiftLuma      = ( m_cNonlinearDepthModel.BackwardD( (Double)uiDepthValue, dScale) + dOffset ) * Double( 1 << m_iLog2Precision );
+    else
+      dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+#else
+    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+#endif
+    Double  dShiftChroma    = dShiftLuma / 2;
+    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
+    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
+
+    // integer-valued look-up tables
+#if POZNAN_NONLINEAR_DEPTH
+    Int64   iTempScale;
+    if( m_bUseNonlinearDepth )
+      iTempScale      = (Int64)m_cNonlinearDepthModel.BackwardI(uiDepthValue, iScale);
+    else
+      iTempScale      = (Int64)uiDepthValue * iScale;
+#else
+    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
+#endif
+    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 ];
+}
+
+Bool
+CamParsCollector::getNearestBaseView( Int iSynthViewIdx, Int &riNearestViewIdx, Int &riRelDistToLeft, Bool& rbRenderFromLeft)
+{
+  /*
+  riNearestViewIdx = 0;
+
+  Bool bDecencdingVN = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] );
+  Int  iFactor       = ( bDecencdingVN ? -1 : 1 );
+
+  if( ( m_aiBaseId2SortedId[iSynthViewIdx] - m_aiBaseId2SortedId[riNearestViewIdx] ) * iFactor  <= 0 )
+  {
+    rbRenderFromLeft = true;
+  }
+  else
+  {
+    rbRenderFromLeft = false;
+  }
+
+  riRelDistToLeft = 128; //Not used for now;
+//*/
+  return true;
+}
+
+#if NTT_SUBPEL
+Void
+CamParsCollector::xCreateLUTs_Subpel( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Int****& raiLUT0, Int****& raiLUT1 )
+{
+  uiNumberSourceViews = Max( 1, uiNumberSourceViews );
+  uiNumberTargetViews = Max( 1, uiNumberTargetViews );
+
+  raiLUT0         = new Int   ***[ uiNumberSourceViews ];
+  raiLUT1         = new Int   ***[ uiNumberSourceViews ];
+
+  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
+  {
+    raiLUT0        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
+    raiLUT1        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
+
+    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
+    {
+      raiLUT0        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
+      raiLUT0        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
+      raiLUT0        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
+      raiLUT1        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
+      raiLUT1        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
+      raiLUT1        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
+    }
+  }
+}
+Void 
+CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Int****& raiLUT_ipel, Int****& raiLUT_fpos)
+{
+  Int   iLog2Div = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2Div > 0 );
+  Int64 iOffset64   = ( Int64(iOffset) << m_uiBitDepthForLUT ) + ( ( 1 << iLog2Div ) >> 1 );
+
+  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
+  {
+    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
+    Int     iShiftSubpel    = (Int) (( iTempScale + iOffset64 ) >> iLog2Div);
+    Int     iShiftPelLuma   = iShiftSubpel >> m_iLog2Precision; // better to have rounding ?
+    Int     iShiftPelChroma = iShiftPelLuma >> 1;
+
+    raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = iShiftPelLuma;
+    raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = iShiftPelChroma;
+    raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = iShiftSubpel - ( iShiftPelLuma << m_iLog2Precision );
+    raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = iShiftSubpel - ( iShiftPelChroma << (m_iLog2Precision+1) );
+
+#if 0 // NTT bugfix
+    if ( raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] < 0 )
+      raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = -4 - raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ];
+    if ( raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] < 0 )
+      raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = -8 - raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ];
+#endif
+
+#if _DEBUG
+    AOF( (raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ]>> m_iLog2Precision   ) == 0 );
+    AOF( (raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ]>>(m_iLog2Precision+1)) == 0 );
+#endif
+  }
+
+  raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+  raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT_ipel[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+  raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+  raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT_fpos[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+}
+#endif
+
+#endif
 
 Void
@@ -164,4 +362,12 @@
         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
+#if VSP_N
+        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);
+#if NTT_SUBPEL
+        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+#endif
+#endif  
       }
       else
@@ -171,4 +377,12 @@
         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
+#if VSP_N
+        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 );
+#if NTT_SUBPEL
+        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+#endif
+#endif
       }
     }
@@ -185,4 +399,12 @@
         m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
         m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
+#if VSP_N
+        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 );
+#if NTT_SUBPEL
+        xInitLUTs( uiBaseId, uiViewId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+        xInitLUTs( uiViewId, uiBaseId, m_aaiCodedScale[ uiViewId ][ uiBaseId ], m_aaiCodedOffset[ uiViewId ][ uiBaseId ], m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+#endif
+#endif
       }
     }
@@ -255,5 +477,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;
@@ -266,4 +488,9 @@
   m_bFirstSliceInSequence   = true;
   m_pcCamParsCollector = 0;
+
+#if VSP_N
+  m_pcPicVSP = NULL;
+  m_pcPicAvail = NULL;
+#endif
 }
 
@@ -271,5 +498,6 @@
 {
 #if ENC_DEC_TRACE
-  fclose( g_hTrace );
+  if(g_hTrace) fclose( g_hTrace );
+  g_hTrace=NULL;
 #endif
 }
@@ -298,4 +526,20 @@
   m_cResidualGenerator.destroy();
 #endif
+
+#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
+
 }
 
@@ -732,4 +976,65 @@
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
+#if VSP_N
+#if VSP_SLICE_HEADER
+    if( m_apcSlicePilot->getVspFlag() )
+#endif
+    {
+      if( m_pcPicVSP == NULL )
+      {
+        m_pcPicVSP = new TComPic;
+        m_pcPicVSP->create( m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+        m_pcPicVSP->setCurrSliceIdx(0);
+        m_pcPicVSP->getCurrSlice()->setViewId( NUM_VIEW_VSP );
+        m_pcPicVSP->getCurrSlice()->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
+        m_pcPicVSP->getCurrSlice()->setSPS( m_apcSlicePilot->getSPS() );
+        m_pcPicVSP->getCurrSlice()->setPPS( m_apcSlicePilot->getPPS() );
+        m_pcPicVSP->getCurrSlice()->setPPSId( m_apcSlicePilot->getPPS()->getPPSId() );
+        m_pcPicVSP->getPicSym()->setNumColumnsMinus1( m_apcSlicePilot->getSPS()->getNumColumnsMinus1() );
+        m_pcPicVSP->getPicSym()->setNumRowsMinus1( m_apcSlicePilot->getSPS()->getNumRowsMinus1() );
+        m_pcPicVSP->getPicSym()->xCreateTComTileArray();
+        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
+        UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
+        Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
+        if( bNeedPrdDepthMapBuffer )
+        {
+          m_pcPicVSP->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
+        }
+#endif
+      }
+      if( m_pcPicAvail == NULL )
+      {
+        m_pcPicAvail = new TComPic;
+        m_pcPicAvail->create( m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+        m_pcPicAvail->setCurrSliceIdx(0);
+        m_pcPicAvail->getCurrSlice()->setViewId( 99 );
+        m_pcPicAvail->getCurrSlice()->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
+        m_pcPicAvail->getCurrSlice()->setSPS( m_apcSlicePilot->getSPS() );
+        m_pcPicAvail->getCurrSlice()->setPPS( m_apcSlicePilot->getPPS() );
+        m_pcPicAvail->getCurrSlice()->setPPSId( m_apcSlicePilot->getPPS()->getPPSId() );
+        m_pcPicAvail->getPicSym()->setNumColumnsMinus1( m_apcSlicePilot->getSPS()->getNumColumnsMinus1() );
+        m_pcPicAvail->getPicSym()->setNumRowsMinus1( m_apcSlicePilot->getSPS()->getNumRowsMinus1() );
+        m_pcPicAvail->getPicSym()->xCreateTComTileArray();
+        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
+        UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
+        Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
+        if( bNeedPrdDepthMapBuffer )
+        {
+          m_pcPicAvail->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
+        }
+#endif
+      }
+    }
+#endif
 
 #if SONY_COLPIC_AVAILABILITY
@@ -759,4 +1064,26 @@
     m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
 #endif
+#if !QC_MULTI_DIS_CAN
+#if VSP_N
+#if VSP_SLICE_HEADER
+    if( m_apcSlicePilot->getVspFlag() )
+#endif
+    {
+      UInt uiPdm                  = ( m_viewId ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
+      Bool bNeedPrdDepthMapBuffer = ( !m_isDepth && uiPdm > 0 );
+      if( bNeedPrdDepthMapBuffer )
+      {
+        if( m_pcPicVSP && m_pcPicVSP->getPredDepthMap() )
+        {
+          m_cDepthMapGenerator.clearDepthMap( m_pcPicVSP );
+        }
+        if( m_pcPicAvail && m_pcPicAvail->getPredDepthMap() )
+        {
+          m_cDepthMapGenerator.clearDepthMap( m_pcPicAvail );
+        }
+      }
+    }
+#endif
+#endif
   }
 
@@ -973,5 +1300,23 @@
 
     std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
+#if VSP_N
+    Bool bUseVsp = (m_viewId!=0);
+#if VSP_TEXT_ONLY
+    if( m_isDepth ) bUseVsp = false;
+#endif
+#if VSP_SLICE_HEADER
+    if( !pcSlice->getVspFlag() ) bUseVsp = false;
+#endif
+
+#if VSP_SLICE_HEADER
+    if( bUseVsp )
+#endif
+      m_pcPicVSP->getCurrSlice()->setPOC( pcPic->getPOC() );
+
+    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics, bUseVsp ? m_pcPicVSP : NULL );
+
+#else
     pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
+#endif
 
     // For generalized B
@@ -1068,4 +1413,18 @@
 #endif
 
+#if VSP_N
+  if( m_pcCamParsCollector )
+  {
+    m_pcCamParsCollector->setSlice( pcSlice );
+  }
+#if VSP_SLICE_HEADER
+  if( pcSlice->getVspFlag() )
+#endif
+  if( getTAppDecTop()->getUseDepth() )
+  {
+    getTAppDecTop()->storeVSPInBuffer( m_pcPicVSP, m_pcPicAvail, pcSlice->getViewId(), pcSlice->getSPS()->getViewOrderIdx(), pcSlice->getPOC(), m_isDepth );
+  }
+#endif
+
   //  Decode a picture
   m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
@@ -1108,4 +1467,15 @@
 #if LCU_SYNTAX_ALF
   m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif
+
+#if VSP_N
+  if( !sps->isDepth() && sps->getViewId() == 0 && getTAppDecTop()->getVSPRendererTop() )
+  {
+#if NTT_SUBPEL
+    getTAppDecTop()->getVSPRendererTop()->init( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 5, 1, 0, 6 );
+#else
+    getTAppDecTop()->getVSPRendererTop()->init( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
+#endif
+  }
 #endif
 }
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibDecoder/TDecTop.h	(revision 166)
@@ -77,4 +77,16 @@
   Bool  isInitialized() const { return m_bInitialized; }
 
+#if VSP_N
+  Double****          getBaseViewShiftLUTD      ()  { return m_adBaseViewShiftLUT;   }
+  Int****             getBaseViewShiftLUTI      ()  { return m_aiBaseViewShiftLUT;   }
+  Int**               getBaseViewOffsetI        ()  { return m_aaiCodedOffset;   }
+  Int**               getBaseViewScaleI         ()  { return m_aaiCodedScale;   }
+  Bool                getNearestBaseView        ( Int iSynthViewIdx, Int &riNearestViewIdx, Int &riRelDistToLeft, Bool& rbRenderFromLeft);
+#if NTT_SUBPEL
+  Int****             getBaseViewIPelLUT        ()  { return m_aiBaseViewShiftLUT_ipel;   }
+  Int****             getBaseViewFPosLUT        ()  { return m_aiBaseViewShiftLUT_fpos;   }
+#endif
+#endif
+
 private:
   Bool  xIsComplete ();
@@ -94,5 +106,84 @@
   Int     m_iLastPOC;
   UInt    m_uiMaxViewId;
+
+#if VSP_N
+  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 );
+
+#if NTT_SUBPEL
+  Int****             m_aiBaseViewShiftLUT_ipel;              ///< Disparity LUT
+  Int****             m_aiBaseViewShiftLUT_fpos;              ///< Disparity LUT
+  Void xCreateLUTs_Subpel ( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Int****& raiLUT0, Int****& raiLUT1 );
+  Void xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Int****& raiLUT_ipel, Int****& raiLUT_fpos);
+#endif
+#endif
 };
+
+#if VSP_N
+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
@@ -155,4 +246,9 @@
   NalUnitType             m_nalUnitTypeBaseView;  
 
+#if VSP_N
+  TComPic*                m_pcPicVSP; //view synthesis prediction buffer for current POC to be coded
+  TComPic*                m_pcPicAvail;
+#endif
+
 public:
   TDecTop();
@@ -195,4 +291,8 @@
   TAppDecTop*         getTAppDecTop()                           { return  m_tAppDecTop; }
   NalUnitType         getNalUnitTypeBaseView()                  { return m_nalUnitTypeBaseView; }
+
+#if VSP_N
+  TComPic*            getVSPBuf()                               { return m_pcPicVSP; }
+#endif
 
 protected:
