Index: branches/HTM-4.0.1-VSP-dev0/build/HM_vc9.sln
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/build/HM_vc9.sln	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/build/HM_vc9.sln	(revision 166)
@@ -8,4 +8,5 @@
 		{78018D78-F890-47E3-A0B7-09D273F0B11D} = {78018D78-F890-47E3-A0B7-09D273F0B11D}
 		{D1E8A1C2-15DB-4C94-80E8-4F70CF0A2DC5} = {D1E8A1C2-15DB-4C94-80E8-4F70CF0A2DC5}
+		{457993C6-AE2C-4B9B-B5F9-71033279A0B9} = {457993C6-AE2C-4B9B-B5F9-71033279A0B9}
 	EndProjectSection
 EndProject
Index: branches/HTM-4.0.1-VSP-dev0/build/linux/app/TAppDecoder/makefile
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/build/linux/app/TAppDecoder/makefile	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/build/linux/app/TAppDecoder/makefile	(revision 166)
@@ -41,13 +41,13 @@
 
 
-DYN_DEBUG_LIBS		= -lTLibDecoderd -lTLibCommond -lTLibVideoIOd -lTAppCommond
-DYN_DEBUG_PREREQS		= $(LIB_DIR)/libTLibDecoderd.a $(LIB_DIR)/libTLibCommond.a $(LIB_DIR)/libTLibVideoIOd.a $(LIB_DIR)/libTAppCommond.a
-STAT_DEBUG_LIBS		= -lTLibDecoderStaticd -lTLibCommonStaticd -lTLibVideoIOStaticd -lTAppCommonStaticd
-STAT_DEBUG_PREREQS		= $(LIB_DIR)/libTLibDecoderStaticd.a $(LIB_DIR)/libTLibCommonStaticd.a $(LIB_DIR)/libTLibVideoIOStaticd.a $(LIB_DIR)/libTAppCommonStaticd.a
+DYN_DEBUG_LIBS		= -lTLibDecoderd -lTLibCommond -lTLibVideoIOd -lTAppCommond -lTLibRendererd
+DYN_DEBUG_PREREQS		= $(LIB_DIR)/libTLibDecoderd.a $(LIB_DIR)/libTLibCommond.a $(LIB_DIR)/libTLibVideoIOd.a $(LIB_DIR)/libTAppCommond.a $(LIB_DIR)/libTLibRendererd.a
+STAT_DEBUG_LIBS		= -lTLibDecoderStaticd -lTLibCommonStaticd -lTLibVideoIOStaticd -lTAppCommonStaticd -lTLibRendererStaticd
+STAT_DEBUG_PREREQS		= $(LIB_DIR)/libTLibDecoderStaticd.a $(LIB_DIR)/libTLibCommonStaticd.a $(LIB_DIR)/libTLibVideoIOStaticd.a $(LIB_DIR)/libTAppCommonStaticd.a $(LIB_DIR)/libTLibRendererStaticd.a
 
-DYN_RELEASE_LIBS	= -lTLibDecoder -lTLibCommon -lTLibVideoIO -lTAppCommon
-DYN_RELEASE_PREREQS	= $(LIB_DIR)/libTLibDecoder.a $(LIB_DIR)/libTLibCommon.a $(LIB_DIR)/libTLibVideoIO.a $(LIB_DIR)/libTAppCommon.a
-STAT_RELEASE_LIBS	= -lTLibDecoderStatic -lTLibCommonStatic -lTLibVideoIOStatic -lTAppCommonStatic
-STAT_RELEASE_PREREQS	= $(LIB_DIR)/libTLibDecoderStatic.a $(LIB_DIR)/libTLibCommonStatic.a $(LIB_DIR)/libTLibVideoIOStatic.a $(LIB_DIR)/libTAppCommonStatic.a
+DYN_RELEASE_LIBS	= -lTLibDecoder -lTLibCommon -lTLibVideoIO -lTAppCommon -lTLibRenderer
+DYN_RELEASE_PREREQS	= $(LIB_DIR)/libTLibDecoder.a $(LIB_DIR)/libTLibCommon.a $(LIB_DIR)/libTLibVideoIO.a $(LIB_DIR)/libTAppCommon.a $(LIB_DIR)/libTLibRenderer.a
+STAT_RELEASE_LIBS	= -lTLibDecoderStatic -lTLibCommonStatic -lTLibVideoIOStatic -lTAppCommonStatic -lTLibRendererStatic
+STAT_RELEASE_PREREQS	= $(LIB_DIR)/libTLibDecoderStatic.a $(LIB_DIR)/libTLibCommonStatic.a $(LIB_DIR)/libTLibVideoIOStatic.a $(LIB_DIR)/libTAppCommonStatic.a $(LIB_DIR)/libTLibRendererStatic.a
 
 
Index: branches/HTM-4.0.1-VSP-dev0/build/vc9/TLibCommon_vc9.vcproj
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/build/vc9/TLibCommon_vc9.vcproj	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/build/vc9/TLibCommon_vc9.vcproj	(revision 166)
@@ -2,5 +2,5 @@
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="9,00"
+	Version="9.00"
 	Name="TLibCommon"
 	ProjectGUID="{78018D78-F890-47E3-A0B7-09D273F0B11D}"
@@ -292,4 +292,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\DebugLog.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\libmd5\libmd5.c"
 				>
@@ -418,4 +422,8 @@
 			</File>
 			<File
+				RelativePath="..\..\source\Lib\TLibCommon\DebugLog.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\source\Lib\libmd5\libmd5.h"
 				>
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 166)
@@ -262,4 +262,15 @@
     }
   }
+#if DEBUGIMGOUT
+  for(Int viewDepthIdx=0; viewDepthIdx<m_tVideoIOYuvReconDbgFile.size() ; viewDepthIdx++)
+  {
+    if( m_tVideoIOYuvReconDbgFile[viewDepthIdx] )
+    {
+      m_tVideoIOYuvReconDbgFile[viewDepthIdx]->close();
+      delete m_tVideoIOYuvReconDbgFile[viewDepthIdx]; 
+      m_tVideoIOYuvReconDbgFile[viewDepthIdx] = NULL ;
+    }
+  }
+#endif
 
   for(Int viewDepthIdx=0; viewDepthIdx<m_tDecTop.size() ; viewDepthIdx++)
@@ -330,4 +341,11 @@
 #endif
       }
+#if DEBUGIMGOUT
+#if PIC_CROPPING
+      m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() );
+#else
+      m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), pcPic->getSlice(0)->getSPS()->getPad() );
+#endif
+#endif   
       
       // update POC of display order
@@ -388,4 +406,11 @@
 #endif
       }
+#if DEBUGIMGOUT
+#if PIC_CROPPING
+      m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() );
+#else
+      m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), pcPic->getSlice(0)->getSPS()->getPad() );
+#endif
+#endif
       
       // update POC of display order
@@ -476,5 +501,29 @@
   }
 #endif
-
+#if DEBUGIMGOUT
+  while( m_tVideoIOYuvReconDbgFile.size() < newNumberOfViewDepth)
+  {
+    m_tVideoIOYuvReconDbgFile.push_back(new TVideoIOYuv);
+    Char buffer[4];
+    sprintf(buffer,"_%i", (Int)(m_tVideoIOYuvReconDbgFile.size()-1) / 2 );
+    Char* nextFilename = NULL;
+    if( (m_tVideoIOYuvReconDbgFile.size() % 2) == 0 )
+    {
+      Char* pchTempFilename = NULL;
+      xAppendToFileNameEnd( "DebugImg.yuv", "_depth", pchTempFilename);
+      xAppendToFileNameEnd( pchTempFilename, buffer, nextFilename);
+      free ( pchTempFilename );
+    }
+    else
+    {
+      xAppendToFileNameEnd( "DebugImg.yuv", buffer, nextFilename);
+    }
+    if( isDepth || ( !isDepth && (m_tVideoIOYuvReconDbgFile.size() % 2) == 1 ) )
+    {
+      m_tVideoIOYuvReconDbgFile.back()->open( nextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement );
+    }
+    free ( nextFilename );
+  }
+#endif
   while( m_pocLastDisplay.size() < newNumberOfViewDepth )
   {
@@ -533,3 +582,97 @@
   return pcPic;
 }
+
+#if VSP_N
+Void TAppDecTop::storeVSPInBuffer(TComPic* pcPicVSP, TComPic* pcPicAvail, Int iCodedViewIdx, Int iCoddedViewOrderIdx, Int iCurPoc, Bool bDepth)
+{
+  //first view does not have VSP 
+#if VSP_TEXT_ONLY
+  if((iCodedViewIdx == 0)||(bDepth))
+#else
+  if((iCodedViewIdx == 0))
+#endif
+    return;
+  pcPicVSP->getSlice(0)->setPOC( iCurPoc );
+  Int iNeighborViewId = 0;
+  Bool bRenderFromLeft;
+  //check if the neighboring view is situated to the left of the current view
+  bRenderFromLeft = ((iCoddedViewOrderIdx)>0);
+  //pointers to buffers   
+  TComPicYuv* pcPicYuvVideo = getPicFromView(iNeighborViewId, iCurPoc, bDepth)->getPicYuvRec();
+  TComPicYuv* pcPicYuvDepth = getPicFromView(iNeighborViewId, iCurPoc, true)->getPicYuvRec();
+  TComPicYuv* pcPicYuvVSP   = pcPicVSP->getPicYuvRec();
+  TComPicYuv* pcPicYuvAvail = pcPicAvail->getPicYuvRec();
+  //verifying buffers
+  AOF(pcPicYuvVideo);
+  AOF(pcPicYuvDepth);
+  AOF(pcPicYuvVSP);
+  AOF(pcPicYuvAvail);
+
+  TComPic* pcPic = getPicFromView( iCodedViewIdx, iCurPoc, bDepth );
+  pcPic->setPicYuvSynth( pcPicYuvVSP );
+  pcPic->setPicYuvAvail( pcPicYuvAvail );
+
+  //setting look-up table
+#if 0
+  m_cVSPRendererTop.setShiftLUTs(
+      m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      -1
+      );
+#else
+#if NTT_SUBPEL
+  m_cVSPRendererTop.setShiftLUTs(
+      m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewIPelLUT  ()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewIPelLUT  ()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      -1
+      );
+  m_cVSPRendererTop.setFposLUTs( 
+      m_cCamParsCollector.getBaseViewFPosLUT()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewFPosLUT()[iNeighborViewId][iCodedViewIdx]
+      );
+#else
+  m_cVSPRendererTop.setShiftLUTs(
+      m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      -1
+      );
+#endif
+#endif
+
+#if NTT_SUBPEL
+  m_cVSPRendererTop.setInterpolationMode( (bDepth ? 0 : 5) );
+#endif
+
+  //extrapolate from view iNeighborViewId to the current view, storing in the VSP buffer
+  //m_cVSPRendererTop.extrapolateView(pcPicYuvVideo,pcPicYuvDepth, pcPicYuvVSP, bRenderFromLeft);
+  m_cVSPRendererTop.extrapolateAvailabilityView(pcPicYuvVideo,pcPicYuvDepth, pcPicYuvVSP, pcPicYuvAvail, bRenderFromLeft);
+
+  // mark it should be extended
+  pcPicVSP->getPicYuvRec()->setBorderExtension(false); 
+  pcPicVSP->getPicYuvRec()->extendPicBorder(); //will extend the border for prediction using pixels outside the frame
+  pcPicAvail->getPicYuvRec()->setBorderExtension(false); 
+  pcPicAvail->getPicYuvRec()->extendPicBorder();
+#if VSP_N_DUMP
+  {
+    Char acFilenameBase[1024];
+    ::sprintf(acFilenameBase,"VSP_dec_%sv%d_%dx%d_%04d.yuv",(bDepth?"D":"T"),iCodedViewIdx,pcPicYuvVSP->getWidth(), pcPicYuvVSP->getHeight(), iCurPoc);
+    pcPicYuvVSP->dump(acFilenameBase,0);
+    //pcPicYuvAvail->dump(acFilenameBase,iCurPoc!=0);
+  }
+#endif
+}
+#endif
+
 //! \}
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.h	(revision 166)
@@ -49,4 +49,7 @@
 #include "TLibDecoder/TDecTop.h"
 #include "TAppDecCfg.h"
+#if VSP_N
+#include "../../Lib/TLibRenderer/TRenTop.h"
+#endif
 
 //! \ingroup TAppDecoder
@@ -65,4 +68,7 @@
 
   std::vector<TVideoIOYuv*>       m_tVideoIOYuvReconFile;         ///< reconstruction YUV class
+#if DEBUGIMGOUT
+  std::vector<TVideoIOYuv*>       m_tVideoIOYuvReconDbgFile;      ///< debug YUV class
+#endif
 
   // for output control
@@ -79,4 +85,8 @@
   TComSPSAccess                   m_cSPSAccess;
   TComAUPicAccess                 m_cAUPicAccess;
+#endif
+
+#if VSP_N
+  TRenTop                         m_cVSPRendererTop;
 #endif
 
@@ -107,4 +117,10 @@
 #endif
 
+#if VSP_N
+  Bool              getUseDepth   () { return m_useDepth; }
+  TRenTop*          getVSPRendererTop(){ return &m_cVSPRendererTop; }
+  Void              storeVSPInBuffer(TComPic* pcPicVSP, TComPic* pcPicAvail, Int iCodedViewIdx, Int iCoddedViewOrderIdx, Int iCurPoc, Bool bDepth);
+#endif
+
 protected:
 //  Void  xCreateDecLib     (); ///< create internal classes
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 166)
@@ -194,25 +194,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")
@@ -498,5 +498,5 @@
   m_pchRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
   m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
-  
+
   if ( m_bUsingDepthMaps )
   {
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 166)
@@ -697,4 +697,11 @@
 #endif
 
+#if VSP_N
+#if NTT_SUBPEL
+  m_cVSPRendererTop.init(m_iSourceWidth, m_iSourceHeight, true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 5, 1, 0, 6 );
+#else
+  m_cVSPRendererTop.init(m_iSourceWidth, m_iSourceHeight, true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
+#endif
+#endif
 }
 
@@ -822,5 +829,5 @@
   TComPicYuv*       pcPicYuvRec = NULL;
   TComPicYuv*       pcDepthPicYuvRec = NULL;
-  
+
   // initialize internal class & member variables
   xInitLibCfg();
@@ -918,5 +925,5 @@
       if ( iNextPoc < m_iFrameToBeEncoded )
       {
-      m_cCameraData.update( iNextPoc );
+        m_cCameraData.update( iNextPoc );
       }
       for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
@@ -930,4 +937,20 @@
 #endif
         iNumEncoded = 0;
+
+#if VSP_SLICE_HEADER
+        m_acTEncTopList     [iViewIdx]->setUseVSP( (gopId%VSP_FRAME_INTERVAL==0) );
+        m_acTEncDepthTopList[iViewIdx]->setUseVSP( (gopId%VSP_FRAME_INTERVAL==0) );
+#endif
+
+#if VSP_N
+#if VSP_SLICE_HEADER
+        if( m_acTEncTopList[iViewIdx]->getUseVSP() )
+#endif
+        if( m_bUsingDepthMaps )
+        {
+          // Forward Warping
+          xStoreVSPInBuffer(m_acTEncTopList[iViewIdx]->getVSPBuf(), m_acTEncTopList[iViewIdx]->getVSPAvailBuf(), iViewIdx, false, gopId);
+        }
+#endif
         // call encoding function for one frame
         m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
@@ -937,4 +960,10 @@
         {
           Int  iNumDepthEncoded = 0;
+#if VSP_N
+#if VSP_SLICE_HEADER
+          if( m_acTEncDepthTopList[iViewIdx]->getUseVSP() )
+#endif
+            xStoreVSPInBuffer(m_acTEncDepthTopList[iViewIdx]->getVSPBuf(), m_acTEncDepthTopList[iViewIdx]->getVSPAvailBuf(), iViewIdx, true, gopId);
+#endif
           // call encoding function for one depth frame
           m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
@@ -1377,3 +1406,122 @@
 };
 
+#if VSP_N
+Void TAppEncTop::xStoreVSPInBuffer(TComPic* pcPicVSP, TComPic* pcPicAvail, Int iCodedViewIdx, Bool bDepth, Int gopId)
+{
+  //first view does not have VSP 
+#if VSP_TEXT_ONLY
+  if((iCodedViewIdx == 0)||(bDepth))
+#else
+  if((iCodedViewIdx == 0))
+#endif
+    return;
+
+  AOT( iCodedViewIdx <= 0);
+  AOT( iCodedViewIdx >= m_iNumberOfViews );
+  
+  Int iCurPoc;
+  //getting currrent POC and checking if the frame will be coded
+  if(bDepth)
+  {
+    iCurPoc = m_acTEncDepthTopList[iCodedViewIdx]->getFrameId(gopId);
+    if(iCurPoc>=m_acTEncDepthTopList[iCodedViewIdx]->getFrameToBeEncoded())
+      return;
+    //if(!(m_acTEncDepthTopList[iCodedViewIdx]->currentPocWillBeCoded())) 
+    //  return;
+  }
+  else
+  {
+    iCurPoc = m_acTEncTopList[iCodedViewIdx]->getFrameId(gopId);
+    if(iCurPoc>=m_acTEncTopList[iCodedViewIdx]->getFrameToBeEncoded())
+      return;
+    //if(!(m_acTEncTopList[iCodedViewIdx]->currentPocWillBeCoded())) 
+    //  return;
+  }
+  pcPicVSP->getSlice(0)->setPOC( iCurPoc );
+
+  Int iNeighborViewId = 0;
+  Bool bRenderFromLeft;
+  //check if the neighboring view is situated to the left of the current view
+  bRenderFromLeft = ((m_cCameraData.getBaseSortedId2Id()[iCodedViewIdx]-m_cCameraData.getBaseSortedId2Id()[iNeighborViewId])>0);
+  //pointers to buffers   
+  TComPicYuv* pcPicYuvVideo = xGetPicYuvFromView(iNeighborViewId, iCurPoc, bDepth, true );
+  TComPicYuv* pcPicYuvDepth = xGetPicYuvFromView(iNeighborViewId, iCurPoc, true, true );
+  TComPicYuv* pcPicYuvVSP   = pcPicVSP->getPicYuvRec();
+  TComPicYuv* pcPicYuvAvail = pcPicAvail->getPicYuvRec();
+  //verifying buffers
+  AOF(pcPicYuvVideo);
+  AOF(pcPicYuvDepth);
+  AOF(pcPicYuvVSP);
+  AOF(pcPicYuvAvail);
+  
+  TComPic* pcPic = getPicFromView( iCodedViewIdx, iCurPoc, bDepth );
+  pcPic->setPicYuvSynth( pcPicYuvVSP );
+  pcPic->setPicYuvAvail( pcPicYuvAvail );
+
+  //setting look-up table
+#if 0
+  m_cVSPRendererTop.setShiftLUTs(
+      m_cCameraData.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      -1
+      );
+#else
+#if NTT_SUBPEL
+  m_cVSPRendererTop.setShiftLUTs(
+      m_cCameraData.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewIPelLUT  ()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      m_cCameraData.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewIPelLUT  ()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      -1
+      );
+  m_cVSPRendererTop.setFposLUTs( 
+      m_cCameraData.getBaseViewFPosLUT()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewFPosLUT()[iNeighborViewId][iCodedViewIdx]
+      );
+#else
+  m_cVSPRendererTop.setShiftLUTs(
+      m_cCameraData.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      m_cCameraData.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx],
+      m_cCameraData.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx],
+      NULL,
+      -1
+      );
+#endif
+#endif
+
+#if NTT_SUBPEL
+  m_cVSPRendererTop.setInterpolationMode( (bDepth ? 0 : 5) );
+#endif
+
+  //extrapolate from view iNeighborViewId to the current view, storing in the VSP buffer
+  //m_cVSPRendererTop.extrapolateView(pcPicYuvVideo,pcPicYuvDepth, pcPicYuvVSP, bRenderFromLeft);
+  m_cVSPRendererTop.extrapolateAvailabilityView(pcPicYuvVideo,pcPicYuvDepth, pcPicYuvVSP, pcPicYuvAvail, bRenderFromLeft);
+
+
+  // mark it should be extended
+  pcPicVSP->getPicYuvRec()->setBorderExtension(false); 
+  pcPicVSP->getPicYuvRec()->extendPicBorder();//will extend the border for prediction using pixels outside the frame (done at the slice level as well
+  pcPicAvail->getPicYuvRec()->setBorderExtension(false); 
+  pcPicAvail->getPicYuvRec()->extendPicBorder();
+
+#if VSP_N_DUMP
+  {
+    Char acFilenameBase[1024];
+    ::sprintf(acFilenameBase,"VSP_enc_%sv%d_%dx%d.yuv",(bDepth?"D":"T"),iCodedViewIdx,m_iSourceWidth, m_iSourceHeight);
+    pcPicYuvVSP->dump(acFilenameBase,iCurPoc!=0);
+    //pcPicYuvAvail->dump(acFilenameBase,iCurPoc!=0);
+  }
+#endif
+
+}
+#endif
+
 //! \}
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.h	(revision 166)
@@ -99,4 +99,9 @@
   TRenTop  m_cUsedPelsRenderer;                               ///< renderer for used pels map
 #endif
+
+#if VSP_N
+  TRenTop                     m_cVSPRendererTop;
+#endif
+
 protected:
   // initialization
@@ -162,4 +167,7 @@
 #endif
 
+#if VSP_N
+  Void xStoreVSPInBuffer(TComPic* pcPicVSP, TComPic* pcPicAvail, Int iCodedViewIdx, Bool bDepth, Int gopId);
+#endif
 };// END CLASS DEFINITION TAppEncTop
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TAppCommon/TAppComCamPara.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 166)
@@ -89,4 +89,34 @@
 }
 
+#if NTT_SUBPEL
+Void
+TAppComCamPara::xCreateLUTs_Subpel( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Int****& raiLUT0, Int****& raiLUT1 )
+{
+  AOF( m_uiBitDepthForLUT == 8 );
+  AOF( raiLUT0 == NULL && raiLUT1 == NULL );
+
+  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 ];
+    }
+  }
+}
+#endif
 
 Void
@@ -928,4 +958,60 @@
 }
 
+#if NTT_SUBPEL
+Void
+TAppComCamPara::xSetShiftParametersAndLUT( UInt uiNumberSourceViews, UInt uiNumberTargetViews, UInt uiFrame, Int****& raiLUT_Disp, Int****& raiLUT_Fracpos )
+{
+  if( uiNumberSourceViews <= 1 || uiNumberTargetViews == 0 )
+  {
+    return;
+  }
+  AOF( raiLUT_Disp != NULL && raiLUT_Fracpos != NULL );
+  AOF( m_uiBitDepthForLUT == 8 );
+
+  Int     iLog2Div = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2Div > 0 );
+  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
+  {
+    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
+    {
+      // integer-valued scale and offset
+      Int64 iScale, iOffset;
+      xGetShiftParameterInt ( uiSourceView, uiTargetView, uiFrame, false, true, iScale, iOffset );
+
+      // offsets including rounding offsets
+      iOffset += ( 1 << iLog2Div ) >> 1;
+
+      for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
+      {
+        Int64   iTempScale      = (Int64)uiDepthValue * iScale;
+        Int     iShiftSubpel    = (Int) (( iTempScale + iOffset ) >> iLog2Div);
+        Int     iShiftPelLuma   = iShiftSubpel >> m_iLog2Precision; // better to have rounding ?
+        Int     iShiftPelChroma = iShiftPelLuma >> 1;
+
+        raiLUT_Disp   [ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = iShiftPelLuma;
+        raiLUT_Disp   [ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = iShiftPelChroma;
+        raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = iShiftSubpel - ( iShiftPelLuma << m_iLog2Precision );
+        raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = iShiftSubpel - ( iShiftPelChroma << (m_iLog2Precision+1) );
+
+#if 0 // NTT bugfix
+        if ( raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] < 0 )
+          raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = -4 - raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ];
+        if ( raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] < 0 )
+          raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = -4 - raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ];
+#endif
+
+#if _DEBUG
+        AOF( (raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ]>> m_iLog2Precision   ) == 0 );
+        AOF( (raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ]>>(m_iLog2Precision+1)) == 0 );
+#endif
+      }
+
+      raiLUT_Disp   [ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT_Disp   [ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+      raiLUT_Disp   [ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT_Disp   [ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+      raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+      raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT_Fracpos[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+    }
+  }
+}
+#endif
 
 Void
@@ -936,4 +1022,7 @@
   xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  uiFrame, false, m_adBaseViewShiftLUT,  m_aiBaseViewShiftLUT,  m_adBaseViewShiftParameter,  m_aiBaseViewShiftParameter  );
   xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, uiFrame, true,  m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter );
+#if NTT_SUBPEL
+  xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  uiFrame, m_aiBaseViewShiftLUT_ipel, m_aiBaseViewShiftLUT_fpos );
+#endif
 };
 
@@ -1066,4 +1155,9 @@
   m_aiSynthViewShiftLUT       = 0;
 
+#if NTT_SUBPEL
+  m_aiBaseViewShiftLUT_ipel   = 0;
+  m_aiBaseViewShiftLUT_fpos   = 0;
+#endif
+
   m_bSetupFromCoded           = false;
   m_bCamParsCodedPrecSet      = false;
@@ -1091,4 +1185,9 @@
   xDeleteArray( m_aaiPdmScaleNomDelta,       m_iNumberOfBaseViews );
   xDeleteArray( m_aaiPdmOffset,              m_iNumberOfBaseViews );
+
+#if NTT_SUBPEL
+  xDeleteArray( m_aiBaseViewShiftLUT_ipel,   m_iNumberOfBaseViews, m_iNumberOfBaseViews,  2 );
+  xDeleteArray( m_aiBaseViewShiftLUT_fpos,   m_iNumberOfBaseViews, m_iNumberOfBaseViews,  2 );
+#endif
 }
 
@@ -1337,4 +1436,8 @@
   xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiPdmOffset            );
 
+#if NTT_SUBPEL
+  xCreateLUTs_Subpel( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aiBaseViewShiftLUT_ipel,  m_aiBaseViewShiftLUT_fpos);
+#endif
+
   //===== init disparity to virtual depth conversion parameters =====
   xSetPdmConversionParams();
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TAppCommon/TAppComCamPara.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TAppCommon/TAppComCamPara.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TAppCommon/TAppComCamPara.h	(revision 166)
@@ -107,4 +107,8 @@
   Int****             m_aiSynthViewShiftLUT;                   ///< Disparity LUT
 
+#if NTT_SUBPEL
+  Int****             m_aiBaseViewShiftLUT_ipel;              ///< Disparity LUT
+  Int****             m_aiBaseViewShiftLUT_fpos;              ///< Disparity LUT
+#endif
 
 protected:
@@ -117,4 +121,8 @@
   template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize );
 
+#if NTT_SUBPEL
+  Void                    xCreateLUTs_Subpel  ( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Int****& raiLUT0, Int****& raiLUT1 );
+#endif
+
   // functions for reading, initialization, sorting, getting data, etc.
   Void  xReadCameraParameterFile  ( Char* pchCfgFileName );
@@ -143,5 +151,7 @@
   Void  xSetShiftParametersAndLUT ( UInt uiNumViewDim1, UInt uiNumViewDim2, UInt uiFrame, Bool bExternalReference, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams );
   Void  xSetShiftParametersAndLUT ( UInt uiFrame );
-
+#if NTT_SUBPEL
+  Void  xSetShiftParametersAndLUT ( UInt uiNumViewDim1, UInt uiNumViewDim2, UInt uiFrame, Int****& raiLUT_Disp, Int****& raiLUT_Fracpos );
+#endif
 
   // getting conversion parameters for disparity to virtual depth conversion
@@ -211,4 +221,9 @@
   Int****             getSynthViewShiftLUTI     ()  { return m_aiSynthViewShiftLUT;  }
   Int****             getBaseViewShiftLUTI      ()  { return m_aiBaseViewShiftLUT;   }
+
+#if NTT_SUBPEL
+  Int****             getBaseViewIPelLUT        ()  { return m_aiBaseViewShiftLUT_ipel;   }
+  Int****             getBaseViewFPosLUT        ()  { return m_aiBaseViewShiftLUT_fpos;   }
+#endif
 
   Bool                getVaryingCameraParameters()  { return m_bCamParsVaryOverTime;    }
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/CommonDef.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/CommonDef.h	(revision 166)
@@ -110,6 +110,11 @@
 #define MAX_GOP                     64          ///< max. value of hierarchical GOP size
 
+#if VSP_N
+#define MAX_NUM_REF                 5           ///< max. value of multiple reference frames
+#define MAX_NUM_REF_LC              10          ///< max. value of combined reference frames
+#else
 #define MAX_NUM_REF                 4           ///< max. value of multiple reference frames
 #define MAX_NUM_REF_LC              8           ///< max. value of combined reference frames
+#endif
 
 #define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/DebugLog.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/DebugLog.cpp	(revision 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/DebugLog.cpp	(revision 166)
@@ -0,0 +1,565 @@
+#include "CommonDef.h"
+#include "TComYuv.h"
+#include "TComPic.h"
+#include "../TLibDecoder/TDecCu.h"
+#include "DebugLog.h"
+
+
+char* pcPartSizeName[] =
+{
+  "SIZE_2Nx2N",           ///< symmetric motion partition,  2Nx2N
+  "SIZE_2NxN",            ///< symmetric motion partition,  2Nx N
+  "SIZE_Nx2N",            ///< symmetric motion partition,   Nx2N
+  "SIZE_NxN",             ///< symmetric motion partition,   Nx N
+
+  "SIZE_2NxnU",           ///< asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
+  "SIZE_2NxnD",           ///< asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
+  "SIZE_nLx2N",           ///< asymmetric motion partition, ( N/2)x2N + (3N/2)x2N
+  "SIZE_nRx2N"            ///< asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
+};
+
+char* pcPredModeName[] = 
+{
+  "MODE_SKIP",            ///< SKIP mode
+  "MODE_INTER",           ///< inter-prediction mode
+  "MODE_INTRA"            ///< intra-prediction mode
+#if FORCE_REF_VSP==1
+  ,"MODE_SYNTH"           ///< vsp skip mode
+#endif
+};
+
+void printMotionInfo( TComDataCU* pcCU, UInt uiIdx, FILE* pfFile )
+{
+  UInt iInterDir = pcCU->getInterDir( uiIdx );
+  fprintf(pfFile, "interDir,%d, ", iInterDir );
+  if (iInterDir != 2) {
+    fprintf(pfFile, "L0Idx,%d, ", pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx( uiIdx ));
+    fprintf(pfFile, "L0Mv(,%d,%d,), ", pcCU->getCUMvField(REF_PIC_LIST_0)->getMv( uiIdx ).getHor(), pcCU->getCUMvField(REF_PIC_LIST_0)->getMv( uiIdx ).getVer() );
+  } else {
+    fprintf(pfFile, "L0Idx,-, L0Mv(,-,-,), ");
+  }
+  if (iInterDir != 1) {
+    fprintf(pfFile, "L1Idx,%d, ", pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx( uiIdx ));
+    fprintf(pfFile, "L1Mv(,%d,%d,), ", pcCU->getCUMvField(REF_PIC_LIST_1)->getMv( uiIdx ).getHor(), pcCU->getCUMvField(REF_PIC_LIST_1)->getMv( uiIdx ).getVer() );
+  } else {
+    fprintf(pfFile, "L1Idx,-, L1Mv(,-,-,), ");
+  }
+}
+
+bool DebugLog::DebugLogOut( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  if ( !m_pfDebugLogFile ) return false;
+
+  int iIdxWidth = (pcCU->getWidth( uiAbsPartIdx ) << uiDepth) >> 2;
+  int iXoffset  = (g_auiZscanToRaster[uiAbsPartIdx] % iIdxWidth) << 2;
+  int iYoffset  = (g_auiZscanToRaster[uiAbsPartIdx] / iIdxWidth) << 2;
+  fprintf(m_pfDebugLogFile, "Pos(,%d,%d,) , PartIdx,%d, ", pcCU->getCUPelX()+iXoffset, pcCU->getCUPelY()+iYoffset, uiAbsPartIdx);
+#if (VSP_N)
+  {
+    char cRefVsp = 0; Int aiRefIdx[2] = {-1, -1};
+    Int iRefIdx = pcCU->getCUMvField( RefPicList(0) )->getRefIdx( uiAbsPartIdx ); aiRefIdx[0] = iRefIdx;
+    if( iRefIdx >= 0 ) cRefVsp |= (pcCU->getSlice()->getRefViewId( RefPicList(0), iRefIdx ) == NUM_VIEW_VSP ? 0x01 : 0);
+    iRefIdx = pcCU->getCUMvField( RefPicList(1) )->getRefIdx( uiAbsPartIdx ); aiRefIdx[1] = iRefIdx;
+    if( iRefIdx >= 0 ) cRefVsp |= (pcCU->getSlice()->getRefViewId( RefPicList(1), iRefIdx ) == NUM_VIEW_VSP ? 0x02 : 0);
+    fprintf(m_pfDebugLogFile, "VSP,%d, RefIdx(,%d,%d,), ", cRefVsp, aiRefIdx[0], aiRefIdx[1] ); // 0:not VSP, 1:VSP L0, 2:VSP L1, 3:VSP Bi
+    fprintf(m_pfDebugLogFile, "MV(");
+    if(aiRefIdx[0]>=0)fprintf(m_pfDebugLogFile, "(,%d,%d,)",pcCU->getCUMvField( RefPicList(0) )->getMv(uiAbsPartIdx).getHor(),pcCU->getCUMvField( RefPicList(0) )->getMv(uiAbsPartIdx).getVer());
+    else              fprintf(m_pfDebugLogFile, "(,-,-,)");
+    if(aiRefIdx[1]>=0)fprintf(m_pfDebugLogFile, "(,%d,%d,)",pcCU->getCUMvField( RefPicList(1) )->getMv(uiAbsPartIdx).getHor(),pcCU->getCUMvField( RefPicList(1) )->getMv(uiAbsPartIdx).getVer());
+    else              fprintf(m_pfDebugLogFile, "(,-,-,)");
+    fprintf(m_pfDebugLogFile, ")");
+  }
+#endif
+    fprintf(m_pfDebugLogFile, "depth,%d,(,%d x %d,), ", uiDepth, pcCU->getWidth( uiAbsPartIdx ), pcCU->getHeight( uiAbsPartIdx ));
+    fprintf(m_pfDebugLogFile, "Predmode,%s, ", 
+#if FORCE_REF_VSP==1
+    pcCU->getPredictionMode( uiAbsPartIdx ) < 4 ? 
+#else
+    pcCU->getPredictionMode( uiAbsPartIdx ) < 3 ? 
+#endif
+    pcPredModeName[(int)pcCU->getPredictionMode( uiAbsPartIdx )] : "SIZE_NONE");
+#if FORCE_REF_VSP==1
+    fprintf(m_pfDebugLogFile, "VspSkipFlg,%d,", pcCU->getPredictionMode( uiAbsPartIdx )==MODE_SYNTH?1:0);
+#endif
+#if HHI_MPI
+    fprintf(m_pfDebugLogFile, "TextModeDepFlg,%d,", pcCU->getSlice()->getIsDepth() ? (pcCU->getTextureModeDepth( uiAbsPartIdx )==uiDepth) : 0 );
+#endif
+    fprintf(m_pfDebugLogFile, "Mergeflag,%d,MergeIdx,%d,", pcCU->getMergeFlag( uiAbsPartIdx ), pcCU->getMergeIndex( uiAbsPartIdx ) );
+    fprintf(m_pfDebugLogFile, "Partsize,%s, ", pcCU->getPartitionSize( uiAbsPartIdx ) < 8 ? pcPartSizeName[(int)pcCU->getPartitionSize( uiAbsPartIdx )] : "SIZE_NONE");
+    fprintf(m_pfDebugLogFile, "Cbf(,%d,%d,%d,), ", pcCU->getCbf(uiAbsPartIdx, TEXT_LUMA), pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U), pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) );
+
+#if OUT_PRED_INFO
+  UInt uiPartOffset = ( pcCU->getPic()->getNumPartInCU() >> ( pcCU->getDepth(uiAbsPartIdx) << 1 ) ) >> 2;
+  if (pcCU->getPredictionMode( uiAbsPartIdx ) != MODE_INTRA) {
+    //InterDirectionNum,L0Idx,L0Mv,L1Idx,L1Mv
+    printMotionInfo( pcCU, uiAbsPartIdx, m_pfDebugLogFile );
+    switch ( pcCU->getPartitionSize( uiAbsPartIdx ) )
+    {
+      case SIZE_2Nx2N:{ break; }
+      case SIZE_2NxN: { printMotionInfo( pcCU, uiAbsPartIdx + (uiPartOffset << 1), m_pfDebugLogFile );    break; }
+      case SIZE_Nx2N: { printMotionInfo( pcCU, uiAbsPartIdx +  uiPartOffset      , m_pfDebugLogFile );    break; }
+      case SIZE_NxN:  
+      {
+        for ( Int iPartIdx = 0; iPartIdx < 4; iPartIdx++ ) {
+          printMotionInfo( pcCU, uiAbsPartIdx + uiPartOffset * iPartIdx, m_pfDebugLogFile );
+        }
+        break;
+      }
+#if ASYMMETRIC_USE
+      case SIZE_2NxnU:{ printMotionInfo( pcCU, uiAbsPartIdx + (uiPartOffset >> 1)                      , m_pfDebugLogFile );    break; }
+      case SIZE_2NxnD:{ printMotionInfo( pcCU, uiAbsPartIdx + (uiPartOffset << 1) + (uiPartOffset >> 1), m_pfDebugLogFile ); break; }
+      case SIZE_nLx2N:{ printMotionInfo( pcCU, uiAbsPartIdx + (uiPartOffset >> 2)                      , m_pfDebugLogFile );    break; }
+      case SIZE_nRx2N:{ printMotionInfo( pcCU, uiAbsPartIdx + (uiPartOffset     ) + (uiPartOffset >> 2), m_pfDebugLogFile ); break; }
+#endif
+      default:        { break; }
+    }
+  } else {
+    //IntraPredDirection
+    fprintf( m_pfDebugLogFile, "IntraDir(L,%d,C,%d,), ", pcCU->getLumaIntraDir( uiAbsPartIdx ), pcCU->getChromaIntraDir( uiAbsPartIdx ) );
+    if (pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN)
+    {
+      for (int i=1; i < 4; i++) {
+        fprintf( m_pfDebugLogFile, "IntraDir(L,%d,C,%d,), ", pcCU->getLumaIntraDir( uiAbsPartIdx + uiPartOffset * i ), pcCU->getChromaIntraDir( uiAbsPartIdx + uiPartOffset * i ) );
+      }
+    }
+  }
+#endif
+  fprintf(m_pfDebugLogFile, "\n");
+  return true;
+}
+
+
+//Color set function of TComYuv 
+#if DEBUGIMGOUT
+Void TComYuv::colsetToPicYuv   ( const UChar ucColor[3], Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx, Bool bDrawLine )
+{
+  colsetToPicLuma  ( ucColor[0],             iOffset, pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx, bDrawLine );
+  for (int i=0; i < 2; i++)
+    for (int j=0; j < 2; j++)
+      iOffset[i][j] >>= 1;
+  colsetToPicChroma( ucColor[1], ucColor[2], iOffset, pcPicYuvDst, iCuAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx, bDrawLine );
+}
+
+Void TComYuv::colsetToPicLuma  ( const UChar ucLumaOffCol, Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx, Bool bDrawLine )
+{
+  Int  offset  = (g_uiBitIncrement>0)?(1<<(g_uiBitIncrement-1)):0;
+  Int  iStartX = bDrawLine ? 1:0;
+  Int  y, x, iWidth, iHeight;
+  iWidth  = m_iWidth >>uiPartDepth;
+  iHeight = m_iHeight>>uiPartDepth;
+
+  Pel* pSrc     = getLumaAddr(uiPartIdx, iWidth);
+  Pel* pDst     = pcPicYuvDst->getLumaAddr ( iCuAddr, uiAbsZorderIdx );
+
+  UInt  iSrcStride  = getStride();
+  UInt  iDstStride  = pcPicYuvDst->getStride();
+
+  pSrc += iOffset[0][1] * iSrcStride + iOffset[0][0]; //TopLeft
+  pDst += iOffset[0][1] * iDstStride + iOffset[0][0]; //TopLeft
+  iWidth  = iOffset[1][0];  //ButtomRight
+  iHeight = iOffset[1][1];  //ButtomRight
+
+
+  if( bDrawLine )
+  {
+    for( x = 0; x < iWidth; x++ )
+      pDst[x] = (((pSrc[x] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL2;  //Top line
+    pDst += iDstStride;
+    pSrc += iSrcStride;
+    iHeight--;
+  }
+
+  if( ucLumaOffCol == 0 )
+  {
+    for ( y = iHeight; y != 0; y-- )
+    {
+      if( bDrawLine )
+        pDst[0] =  (((pSrc[0] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL2;  //Left line
+      for( x = iStartX; x < iWidth; x++ )
+        pDst[x] = (pSrc[x] + offset) >> g_uiBitIncrement;  //glay scale
+      pDst += iDstStride;
+      pSrc += iSrcStride;
+    }
+  } else {
+    for ( y = iHeight; y != 0; y-- )
+    {
+      if( bDrawLine )
+        pDst[0] =  (((pSrc[0] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL2;  //Left line
+      for( x = iStartX; x < iWidth; x++ )
+        pDst[x] = (((pSrc[x] + offset) >> g_uiBitIncrement) >> 2) + ucLumaOffCol;
+      pDst += iDstStride;
+      pSrc += iSrcStride;
+    }
+  }
+}
+
+Void TComYuv::colsetToPicChroma( const UChar ucUCol, const UChar ucVCol, Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx, Bool bDrawLine )
+{
+  Int  y, x, iWidth, iHeight;
+  iWidth  = m_iCWidth >>uiPartDepth;
+  iHeight = m_iCHeight>>uiPartDepth;
+  Int  iStartX = bDrawLine ? 1:0;
+
+  Pel* pDstU      = pcPicYuvDst->getCbAddr( iCuAddr, uiAbsZorderIdx );
+  Pel* pDstV      = pcPicYuvDst->getCrAddr( iCuAddr, uiAbsZorderIdx );
+
+  UInt  iDstStride = pcPicYuvDst->getCStride();
+
+  pDstU += iOffset[0][1] * iDstStride + iOffset[0][0]; //TopLeft
+  pDstV += iOffset[0][1] * iDstStride + iOffset[0][0]; //TopLeft
+  iWidth  = iOffset[1][0];  //ButtomRight
+  iHeight = iOffset[1][1];  //ButtomRight
+
+  if( bDrawLine )
+  {
+    for( x = 0; x < iWidth; x++ )
+    {
+      pDstU[x] = LINE_CB_COL2;  //Top line color
+      pDstV[x] = LINE_CR_COL2;  //Top line color
+    }
+    pDstV += iDstStride;
+    pDstU += iDstStride;
+    iHeight--;
+  }
+  for ( y = iHeight; y != 0; y-- )
+  {
+    if( bDrawLine ) {
+      pDstU[0] =  LINE_CB_COL2;  //Left line color
+      pDstV[0] =  LINE_CR_COL2;  //Left line color
+    }
+    for( x = iStartX; x < iWidth; x++ )
+    {
+      pDstU[x] = ucUCol;
+      pDstV[x] = ucVCol;
+    }
+    pDstU += iDstStride;
+    pDstV += iDstStride;
+  }
+}
+
+Void TComYuv::drawLineToPicYuv ( bool bHor, bool bVer, UInt uiSize, TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx )
+{
+  Int  offset  = (g_uiBitIncrement>0)?(1<<(g_uiBitIncrement-1)):0;
+  Int  y, x, iWidth, iHeight, iWidthC, iHeightC;
+
+  iWidth   = m_iWidth >>uiPartDepth;
+  iHeight  = m_iHeight>>uiPartDepth;
+  iWidthC  = m_iCWidth >>uiPartDepth;
+  iHeightC = m_iCHeight>>uiPartDepth;
+
+
+  Pel* pSrc     = getLumaAddr(uiPartIdx, iWidth);
+  Pel* pDst     = pcPicYuvDst->getLumaAddr ( iCuAddr, uiAbsZorderIdx );
+  Pel* pDstU    = pcPicYuvDst->getCbAddr( iCuAddr, uiAbsZorderIdx );
+  Pel* pDstV    = pcPicYuvDst->getCrAddr( iCuAddr, uiAbsZorderIdx );
+
+  UInt  iSrcStride  = getStride();
+  UInt  iDstStride  = pcPicYuvDst->getStride();
+  UInt  iDstStrideC = pcPicYuvDst->getCStride();
+
+  if ( bHor )
+  {
+    //Luma
+    Pel* pDstHor = pDst + iDstStride * ((iHeight * uiSize) >> 2);
+    Pel* pSrcHor = pSrc + iSrcStride * ((iHeight * uiSize) >> 2);
+    for( x = 1; x < iWidth; x++ )
+      pDstHor[x] = (((pSrcHor[x] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL;
+    //CbCr
+    Pel* pDstUHor = pDstU + iDstStrideC * ((iHeightC * uiSize) >> 2);
+    Pel* pDstVHor = pDstV + iDstStrideC * ((iHeightC * uiSize) >> 2);
+    for( x = 1; x < iWidthC; x++ )
+    {
+      pDstUHor[x] = LINE_CB_COL;
+      pDstVHor[x] = LINE_CR_COL;
+    }
+  }
+  if ( bVer )
+  {
+    //Luma
+    Pel* pDstVer = pDst + iDstStride;
+    Pel* pSrcVer = pSrc + iSrcStride;
+    x = (iWidth * uiSize) >> 2;
+    for ( y = iHeight; y != 1; y-- )
+    {
+      pDstVer[x] = (((pSrcVer[x] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL;
+      pDstVer += iDstStride;
+      pSrcVer += iSrcStride;
+    }
+    //CbCr
+    Pel* pDstVerU = pDstU + iDstStrideC;
+    Pel* pDstVerV = pDstV + iDstStrideC;
+    x = (iHeightC * uiSize) >> 2;
+    for ( y = iHeightC; y != 1; y-- )
+    {
+      pDstVerU[x] = LINE_CB_COL;
+      pDstVerV[x] = LINE_CR_COL;
+      pDstVerU += iDstStrideC;
+      pDstVerV += iDstStrideC;
+    }
+  }
+  
+}
+
+Void TComYuv::drawRectToPicYuv ( TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, UInt uiPartIdx )
+{
+  Int  offset  = (g_uiBitIncrement>0)?(1<<(g_uiBitIncrement-1)):0;
+  Int  y, x, iWidth, iHeight, iWidthC, iHeightC;
+
+  iWidth   = m_iWidth >>uiPartDepth;
+  iHeight  = m_iHeight>>uiPartDepth;
+  iWidthC  = m_iCWidth >>uiPartDepth;
+  iHeightC = m_iCHeight>>uiPartDepth;
+
+
+  Pel* pSrc     = getLumaAddr(uiPartIdx, iWidth);
+  Pel* pDst     = pcPicYuvDst->getLumaAddr ( iCuAddr, uiAbsZorderIdx );
+  Pel* pDstU    = pcPicYuvDst->getCbAddr( iCuAddr, uiAbsZorderIdx );
+  Pel* pDstV    = pcPicYuvDst->getCrAddr( iCuAddr, uiAbsZorderIdx );
+
+  UInt  iSrcStride  = getStride();
+  UInt  iDstStride  = pcPicYuvDst->getStride();
+  UInt  iDstStrideC = pcPicYuvDst->getCStride();
+
+  //X
+  {
+    //Luma
+    Pel* pDstHor = pDst;
+    Pel* pSrcHor = pSrc;
+    for( x = 0; x < iWidth; x++ )
+      pDstHor[x] = (((pSrcHor[x] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL2;
+  //CbCr
+    Pel* pDstUHor = pDstU;
+    Pel* pDstVHor = pDstV;
+    for( x = 0; x < iWidthC; x++ )
+    {
+      pDstUHor[x] = LINE_CB_COL2;
+      pDstVHor[x] = LINE_CR_COL2;
+    }
+  }
+
+  //Y
+  {
+    //Luma
+    Pel* pDstVer = pDst;
+    Pel* pSrcVer = pSrc;
+    x = 0;
+    for ( y = iHeight; y >= 0; y-- )
+    {
+      pDstVer[x] = (((pSrcVer[x] + offset) >> g_uiBitIncrement) >> 2) + LINE_LUMA_OFF_COL2;
+      pDstVer += iDstStride;
+      pSrcVer += iSrcStride;
+    }
+    //CbCr
+    Pel* pDstVerU = pDstU;
+    Pel* pDstVerV = pDstV;
+    x = 0;
+    for ( y = iHeightC; y >= 0; y-- )
+    {
+      pDstVerU[x] = LINE_CB_COL2;
+      pDstVerV[x] = LINE_CR_COL2;
+      pDstVerU += iDstStrideC;
+      pDstVerV += iDstStrideC;
+    }
+  }
+  
+}
+
+Void TDecCu::xColsetToPic( TComDataCU* pcCU, TComPicYuv* pcPicYuv, UInt uiZorderIdx, UInt uiDepth )
+{
+  int       iIdxWidth = (pcCU->getWidth( 0 ) << uiDepth) >> 2;
+  UInt      uiCUAddr  = pcCU->getAddr();
+  PredMode  ePredMode = pcCU->getPredictionMode( 0 );
+  Int       iRect[2][2] = {{0,0}, {0,0}};
+  Int       iColorIdx = 0;
+  UInt      uiPartAddr;
+
+  if ( ePredMode == MODE_INTER )
+  {
+    for (int iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+    {
+      pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRect[1][0], iRect[1][1] );
+      iRect[0][0]  = (g_auiZscanToRaster[uiPartAddr] % iIdxWidth) << 2;
+      iRect[0][1]  = (g_auiZscanToRaster[uiPartAddr] / iIdxWidth) << 2;
+
+#if (VSP_N)
+      {
+        Char cRefVsp = 0x00;
+        Int iRefIdx = pcCU->getCUMvField( RefPicList(0) )->getRefIdx(iPartIdx);
+        if( iRefIdx >= 0 && pcCU->getSlice()->getRefViewId( RefPicList(0), iRefIdx ) == NUM_VIEW_VSP )
+          cRefVsp |= 0x01;
+        iRefIdx = pcCU->getCUMvField( RefPicList(1) )->getRefIdx(iPartIdx);
+        if( iRefIdx >= 0 && pcCU->getSlice()->getRefViewId( RefPicList(1), iRefIdx ) == NUM_VIEW_VSP )
+          cRefVsp |= 0x02;
+#if FORCE_REF_VSP
+        if( pcCU->isVspMode(iPartIdx) )
+          cRefVsp |= 0x04;
+#endif
+
+        switch( cRefVsp )
+        {
+        case 0: // INTER
+          iColorIdx = 2;
+          break;
+        case 1: // VSP L0
+          iColorIdx = 4;
+          break;
+        case 2: // VSP L1
+          iColorIdx = 6;
+          break;
+        case 3: // VSP Bi
+          iColorIdx = 7;
+          break;
+#if FORCE_REF_VSP
+        case 4: // VSP Skip
+          iColorIdx = 5;
+          break;
+#endif
+        default:
+          assert(0);
+          break;
+        }
+      }
+#else
+      iColorIdx = 2;
+#endif
+
+      m_ppcYuvReco[uiDepth]->colsetToPicYuv    ( g_ucCol[iColorIdx], iRect, pcPicYuv, uiCUAddr, uiZorderIdx );
+    }
+  } else {
+    iRect[0][0]=iRect[0][1]=0;
+    iRect[1][0]=pcCU->getWidth(0);
+    iRect[1][1]=pcCU->getHeight(0);
+
+    iColorIdx = ePredMode==MODE_SKIP ? 0 : 1;
+
+    m_ppcYuvReco[uiDepth]->colsetToPicYuv      ( g_ucCol[iColorIdx], iRect, pcPicYuv, uiCUAddr, uiZorderIdx );
+  }
+
+  switch ( pcCU->getPartitionSize( 0 ) )
+  {
+    case SIZE_2Nx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, false, 4, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    case SIZE_2NxN:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , false, 2, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    case SIZE_Nx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, true , 2, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    case SIZE_NxN:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , true , 2, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_2NxnU:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , false, 1, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_2NxnD:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , false, 3, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_nLx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, true , 1, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_nRx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, true , 3, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    default:
+      break;
+  }
+}
+
+Void TDecCu::xColsetToPicMerge( TComDataCU* pcCU, TComPicYuv* pcPicYuv, UInt uiZorderIdx, UInt uiDepth )
+{
+  int       iIdxWidth = (pcCU->getWidth( 0 ) << uiDepth) >> 2;
+  UInt      uiCUAddr  = pcCU->getAddr();
+  PredMode  ePredMode = pcCU->getPredictionMode( 0 );
+  Int       iRect[2][2] = {{0,0}, {0,0}};
+  Int       iColorIdx = 0;
+  UInt      uiPartAddr;
+  UInt      uiMergeIdx;
+  Bool      bSkip     = ePredMode == MODE_SKIP ? true : false;
+
+  if ( ePredMode == MODE_INTER || bSkip )
+  {
+    for (int iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+    {
+      pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRect[1][0], iRect[1][1] );
+      iRect[0][0]  = (g_auiZscanToRaster[uiPartAddr] % iIdxWidth) << 2;
+      iRect[0][1]  = (g_auiZscanToRaster[uiPartAddr] / iIdxWidth) << 2;
+      Bool bMerge  = pcCU->getMergeFlag( iPartIdx );
+
+      if( bSkip || bMerge ) {
+        uiMergeIdx   = pcCU->getMergeIndex( iPartIdx );
+#if (FORCE_REF_VSP)
+        {
+          iColorIdx = bSkip ? 1 : (bMerge ? 5 : 0);
+          Int iRefIdx = pcCU->getCUMvField( RefPicList(0) )->getRefIdx(iPartIdx);
+          char cRefVsp = 0x00;
+          if( iRefIdx >= 0 && pcCU->getSlice()->getRefViewId( RefPicList(0), iRefIdx ) == NUM_VIEW_VSP )
+            cRefVsp |= 0x01;
+          iRefIdx = pcCU->getCUMvField( RefPicList(1) )->getRefIdx(iPartIdx);
+          if( iRefIdx >= 0 && pcCU->getSlice()->getRefViewId( RefPicList(1), iRefIdx ) == NUM_VIEW_VSP )
+            cRefVsp |= 0x02;
+
+          if( cRefVsp ) {
+            iColorIdx += 1;
+          } else if ( uiMergeIdx ) {
+            iColorIdx += 3;
+          }
+        }
+#else
+        iColorIdx = 2;
+#endif
+        assert( iColorIdx > 0 && iColorIdx < 10 );
+
+        m_ppcYuvReco[uiDepth]->colsetToPicYuv  ( g_ucCol[iColorIdx], iRect, pcPicYuv, uiCUAddr, uiZorderIdx );
+
+      } else {
+
+        //Inter Not Merge
+        m_ppcYuvReco[uiDepth]->colsetToPicYuv  ( g_ucCol[0], iRect, pcPicYuv, uiCUAddr, uiZorderIdx );
+
+      }
+    } // end iPartIdx loop
+
+  } else
+  {
+    //Intra , Not Merge Inter
+    iRect[0][0]=iRect[0][1]=0;
+    iRect[1][0]=pcCU->getWidth(0);
+    iRect[1][1]=pcCU->getHeight(0);
+
+    iColorIdx = 0;
+
+    m_ppcYuvReco[uiDepth]->colsetToPicYuv      ( g_ucCol[iColorIdx], iRect, pcPicYuv, uiCUAddr, uiZorderIdx );
+  }
+
+  switch ( pcCU->getPartitionSize( 0 ) )
+  {
+    case SIZE_2Nx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, false, 4, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    case SIZE_2NxN:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , false, 2, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    case SIZE_Nx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, true , 2, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    case SIZE_NxN:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , true , 2, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_2NxnU:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , false, 1, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_2NxnD:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( true , false, 3, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_nLx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, true , 1, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break; 
+    case SIZE_nRx2N:
+      m_ppcYuvReco[uiDepth]->drawLineToPicYuv  ( false, true , 3, pcPicYuv, uiCUAddr, uiZorderIdx );
+      break;
+    default:
+      break;
+  }
+}
+#endif //DEBUGIMGOUT
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/DebugLog.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/DebugLog.h	(revision 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/DebugLog.h	(revision 166)
@@ -0,0 +1,53 @@
+#ifndef __DEBUGLOG_H__
+#define __DEBUGLOG_H__
+
+#define OUT_PRED_INFO  0  //pred info(IntraDir/InterDirNum,Idx,Mv) output
+#define ASYMMETRIC_USE 1
+
+#include "TComDataCU.h"
+
+#define DECLOGFILENAME  "debuglogDec.txt"
+
+class DebugLog 
+{
+private:
+    FILE*  m_pfDebugLogFile;
+
+public:
+    DebugLog() { m_pfDebugLogFile = NULL; }
+    ~DebugLog() {}
+
+    bool   DebugLogFileOpen( char* pcFname ) { m_pfDebugLogFile = fopen( pcFname, "wt" ); return (m_pfDebugLogFile!=NULL); }
+    void   DebugLogFileClose()               { if (m_pfDebugLogFile) fclose(m_pfDebugLogFile); m_pfDebugLogFile=NULL; }
+
+    bool   DebugLogOut( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+};
+
+
+//Colors
+//     Y=Org/2 + YOffset      YOffset  U    V        
+const UChar g_ucCol[11][3] = { {000, 128, 128}, //0 gray scale
+                               {128, 255, 000}, //1 light blue
+                               {128, 255, 128}, //2 lavender
+                               {128, 000, 000}, //3 green yellow
+                               {128, 000, 128}, //4 yellow
+                               {128, 255, 255}, //5 pink
+                               {128, 000, 255}, //6 orange
+                               {064, 000, 255}, //7 red 
+                               {064, 255, 000}, //8 blue
+                               {016, 000, 000}, //9 green
+                               {064, 128, 128}  //10 light gray scale
+                             };
+
+//CU
+#define LINE_LUMA_OFF_COL   g_ucCol[9][0] //9 green
+#define LINE_CB_COL         g_ucCol[9][1]
+#define LINE_CR_COL         g_ucCol[9][2]
+
+//PU
+#define LINE_LUMA_OFF_COL2  g_ucCol[7][0] //7 red
+#define LINE_CB_COL2        g_ucCol[7][1]
+#define LINE_CR_COL2        g_ucCol[7][2]
+
+
+#endif //__DEBUGLOG_H__
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 166)
@@ -49,4 +49,64 @@
 Int * TComDataCU::m_pcGlbArlCoeffCb = NULL;
 Int * TComDataCU::m_pcGlbArlCoeffCr = NULL;
+#endif
+
+#if FORCE_REF_VSP==1
+#define CHECK_ADD_YET(pcCURef,uiIdx) 
+#define SET_AOUND_MVINFO(pcCURef,uiIdx)  \
+{\
+  if((pcCURef)->isVspMode((uiIdx))){\
+    pcMvFieldNeighbours[iCount<<1].setRefIdx(getSlice()->getRefIdxVsp(REF_PIC_LIST_0));\
+    if(getSlice()->isInterB()){\
+      pcMvFieldNeighbours[(iCount<<1)+1].setRefIdx(getSlice()->getRefIdxVsp(REF_PIC_LIST_1));\
+    }\
+  }\
+}
+
+#elif FORCE_REF_VSP==2
+#define CHECK_ADD_YET(pcCURef,uiIdx)  &&!((pcCURef)->isVspMode((uiIdx),TComMv(0,0))&&bVspMvZeroDone)
+#define SET_AOUND_MVINFO(pcCURef,uiIdx)   if((pcCURef)->isVspMode((uiIdx),TComMv(0,0))){bVspMvZeroDone=true;}
+
+inline bool TComDataCU::xAddVspSkip(UChar ucVspMergePos, Bool bVspMvZeroDone, UInt uiDepth, Bool* abCandIsInter, Int& iCount,
+                                    UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int mrgCandIdx)
+{
+#if VSP_SLICE_HEADER
+  if( !getSlice()->getVspFlag() ) return true;
+#endif
+
+  if( ucVspMergePos == VSP_MERGE_POS )
+  {
+#if VSP_TEXT_ONLY
+    if( !getSlice()->getSPS()->isDepth() )
+#endif
+    if( getSlice()->getSPS()->getViewId()!=0 && !bVspMvZeroDone )
+    {
+      Bool bSubCUCanBeSynthesized[4];
+      Bool * pbSubCUCanBeSynthesized = bSubCUCanBeSynthesized;
+      getPic()->checkSynthesisAvailability( getAddr(), getZorderIdxInCU(), uiDepth, pbSubCUCanBeSynthesized );
+      if( bSubCUCanBeSynthesized[0] && bSubCUCanBeSynthesized[1] && bSubCUCanBeSynthesized[2] && bSubCUCanBeSynthesized[3] )
+      {
+        abCandIsInter[iCount] = 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; //pcCUAboveLeft->getInterDir( uiAboveLeftPartIdx );
+        // get Mv from Left
+        pcMvFieldNeighbours[iCount<<1].setMvField( TComMv(0, 0), getSlice()->getRefIdxVsp(REF_PIC_LIST_0) ); //pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
+        if ( getSlice()->isInterB() )
+        {
+          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( TComMv(0, 0), getSlice()->getRefIdxVsp(REF_PIC_LIST_1) ); //pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
+        }
+#if SIMP_MRG_PRUN
+        if ( mrgCandIdx == iCount )
+        {
+          return false;
+        }
+#endif
+        iCount ++;
+      }
+    }
+  }
+  return true;
+}
 #endif
 
@@ -3450,4 +3510,8 @@
 #endif
 
+#if FORCE_REF_VSP==2
+  bool bVspMvZeroDone = false;
+#endif
+
   Int iCount = 0;
 
@@ -3513,5 +3577,11 @@
 #endif
 
-  //left
+#if FORCE_REF_VSP==2
+  //===== vsp 0 ===== 
+  if ( !xAddVspSkip(0, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, mrgCandIdx) )
+    return;
+#endif
+
+  //===== left ===== 
   UInt uiLeftPartIdx = 0;
   TComDataCU* pcCULeft = 0;
@@ -3533,5 +3603,9 @@
   if (!(uiPUIdx == 1 && (partSize == SIZE_Nx2N || partSize == SIZE_nLx2N || partSize == SIZE_nRx2N)))
   {
-  if ( pcCULeft && !pcCULeft->isIntra( uiLeftPartIdx ) )
+  if ( pcCULeft && !pcCULeft->isIntra( uiLeftPartIdx )
+#if FORCE_REF_VSP
+    CHECK_ADD_YET(pcCULeft, uiLeftPartIdx)
+#endif
+  )
   {
     abCandIsInter[iCount] = true;
@@ -3548,4 +3622,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if FORCE_REF_VSP
+    SET_AOUND_MVINFO(pcCULeft, uiLeftPartIdx)
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3581,5 +3658,11 @@
 #endif
 
-  // above
+#if FORCE_REF_VSP==2
+  //===== vsp 1 ===== 
+  if ( !xAddVspSkip(1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, mrgCandIdx) )
+    return;
+#endif
+
+  //===== above ===== 
 #if !SIMP_MRG_PRUN
   partSize = getPartitionSize( uiAbsPartIdx );
@@ -3605,4 +3688,7 @@
 #if SIMP_MRG_PRUN
   if ( pcCUAbove && !pcCUAbove->isIntra( uiAbovePartIdx ) 
+#if FORCE_REF_VSP
+    CHECK_ADD_YET(pcCUAbove, uiAbovePartIdx)
+#endif
     && !(uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD))
     && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAbove, uiAbovePartIdx ) ) )
@@ -3624,4 +3710,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if FORCE_REF_VSP
+    SET_AOUND_MVINFO(pcCUAbove, uiAbovePartIdx)
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3659,5 +3748,11 @@
 #endif
 
-  // above right
+#if FORCE_REF_VSP==2
+  //===== vsp 2 =====
+  if ( !xAddVspSkip(2, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, mrgCandIdx) )
+    return;
+#endif
+
+  //===== above right =====
   UInt uiAboveRightPartIdx = 0;
   TComDataCU* pcCUAboveRight = 0;
@@ -3677,5 +3772,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 FORCE_REF_VSP
+    CHECK_ADD_YET(pcCUAboveRight, uiAboveRightPartIdx)
+#endif
+    && ( !pcCUAbove || pcCUAbove->isIntra( uiAbovePartIdx ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveRight, uiAboveRightPartIdx ) ) )
 #else
   if ( pcCUAboveRight && !pcCUAboveRight->isIntra( uiAboveRightPartIdx ) )
@@ -3695,4 +3794,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if FORCE_REF_VSP
+    SET_AOUND_MVINFO(pcCUAboveRight, uiAboveRightPartIdx)
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3727,5 +3829,19 @@
 #endif
 
-  //left bottom
+#if FORCE_REF_VSP==2
+  //===== vsp 3 =====
+  if ( !xAddVspSkip(3, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, mrgCandIdx) )
+    return;
+#endif
+
+  //===== left bottom =====
+#if VSP_MERGE_POS < 4
+#if HHI_INTER_VIEW_MOTION_PRED
+  if( iCount < 4 + extraMergeCand )
+#else
+  if( iCount < 4 )
+#endif
+  {
+#endif
   UInt uiLeftBottomPartIdx = 0;
   TComDataCU* pcCULeftBottom = 0;
@@ -3745,5 +3861,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 FORCE_REF_VSP
+    CHECK_ADD_YET(pcCULeftBottom, uiLeftBottomPartIdx)
+#endif
+    && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
 #else
   if ( pcCULeftBottom && !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) )
@@ -3763,4 +3883,7 @@
     pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if FORCE_REF_VSP
+    SET_AOUND_MVINFO(pcCULeftBottom, uiLeftBottomPartIdx)
+#endif
 #if SIMP_MRG_PRUN
     if ( mrgCandIdx == iCount )
@@ -3771,4 +3894,7 @@
     iCount ++;
   }
+#if VSP_MERGE_POS < 4
+  }
+#endif
 
 #if HHI_INTER_VIEW_MOTION_PRED
@@ -3795,5 +3921,14 @@
 #endif
 
-  // above left 
+#if FORCE_REF_VSP==2
+  //===== vsp 4 =====
+  if( iCount < 4 + extraMergeCand )
+  {
+    if ( !xAddVspSkip(4, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, mrgCandIdx) )
+      return;
+  }
+#endif
+
+  //===== above left =====
 #if HHI_INTER_VIEW_MOTION_PRED
   if( iCount < 4 + extraMergeCand )
@@ -3820,4 +3955,7 @@
 #if SIMP_MRG_PRUN
     if( pcCUAboveLeft && !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx )
+#if FORCE_REF_VSP
+     CHECK_ADD_YET(pcCUAboveLeft, uiAboveLeftPartIdx)
+#endif
      && ( !pcCULeft || pcCULeft->isIntra( uiLeftPartIdx ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
      && ( !pcCUAbove || pcCUAbove->isIntra( uiAbovePartIdx ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
@@ -3840,4 +3978,7 @@
       pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
 #endif
+#if FORCE_REF_VSP
+      SET_AOUND_MVINFO(pcCUAboveLeft, uiAboveLeftPartIdx)
+#endif
 #if SIMP_MRG_PRUN
       if ( mrgCandIdx == iCount )
@@ -3849,4 +3990,17 @@
     }
   }
+
+#if FORCE_REF_VSP==2
+  //===== vsp 5 =====
+#if HHI_INTER_VIEW_MOTION_PRED
+  if( iCount < 4 + extraMergeCand )
+#else
+  if( iCount < 4 )
+#endif
+  {
+    if ( !xAddVspSkip(5, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, mrgCandIdx) )
+      return;
+  }
+#endif
 
   if ( getSlice()->getPPS()->getEnableTMVPFlag() )
@@ -4268,5 +4422,9 @@
   if( uiIter == 0 )
   {
-    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) )
+    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) 
+#if FORCE_REF_VSP==1
+     && !pcCorner->isVspMode( uiCornerPUIdx )
+#endif
+    )
     {
       rbValidCand = true;
@@ -4303,5 +4461,9 @@
   else
   {
-    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) )
+    if( pcCorner && !pcCorner->isIntra( uiCornerPUIdx ) 
+#if FORCE_REF_VSP==1
+     && !pcCorner->isVspMode( uiCornerPUIdx )
+#endif
+    )
     {
       rbValidCand = true;
@@ -4452,4 +4614,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -4478,4 +4643,7 @@
 
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -4504,4 +4672,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -4529,4 +4700,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -4557,4 +4731,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
@@ -4768,5 +4945,5 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
 
-  Int   aiDvMcpDvCand[2][7] = {{0,},    {0,}}; // dummy, 5 spatial + 1 temporal, DV-MCP ÁÖº¯ ºí·°¿¡¼­ »ç¿ëµÈ DV¸¦ ÀúÀå
+  Int   aiDvMcpDvCand[2][7] = {{0,},    {0,}}; // dummy, 5 spatial + 1 temporal, DV-MCP ÁÖº¯ ºúÓ°¿¡¼­ »ç¿EÈ DV¸¦ ÀúÀE
   Bool  abDvMcpFlag  [2][7] = {{false,},{false,}}; 
   //Int   aiRefPOC     [2][7] = {{-1,},{-1}}; // debug
@@ -4788,4 +4965,7 @@
   UInt uiLeftPartIdx = uiIdx;
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
@@ -4826,4 +5006,7 @@
 
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
@@ -4863,4 +5046,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
@@ -4900,4 +5086,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
@@ -4939,4 +5128,7 @@
 #endif
   if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
+#if VSP_N
+  if(pcTmpCU->getSlice()->getViewId() != NUM_VIEW_VSP)
+#endif
   {
     bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
@@ -5551,4 +5743,65 @@
 }
 
+#if FORCE_REF_VSP==2
+Int TComDataCU::isVspMode ( UInt uiPartIdx )
+{
+  if( m_pePredMode[ uiPartIdx ] == MODE_SKIP  ) return 0;
+  if( m_pePredMode[ uiPartIdx ] == MODE_INTRA ) return 0;
+
+  Int aiRefIdx[2] = {NOT_VALID, NOT_VALID}, iRet = 0;
+  for( Int iList = 0; iList < 2; iList++ )
+  {
+    aiRefIdx[iList] = getCUMvField( RefPicList(iList) )->getRefIdx( uiPartIdx );
+    if( aiRefIdx[iList] >= 0 && getSlice()->getRefViewId( RefPicList(iList), aiRefIdx[iList] ) == NUM_VIEW_VSP )
+    {
+      iRet |= (iList ? 0x02 : 0x01); // L0=1, L1=2, BI=3
+      continue;
+    }
+  }
+
+  return iRet; 
+}
+
+Int TComDataCU::isVspMode ( UInt uiPartIdx, TComMv cCompMv )
+{
+  TComMv cMv;
+  Int iRet = 0, iList = 0;
+
+  if( (iList = isVspMode( uiPartIdx )) )
+  {
+    switch( iList )
+    {
+    case 1:
+      cMv = getCUMvField( RefPicList(0) )->getMv( uiPartIdx );
+      if( cMv == cCompMv )
+      {
+        iRet = 1; // L0=1
+      }
+      break;
+    case 2:
+      cMv = getCUMvField( RefPicList(1) )->getMv( uiPartIdx );
+      if( cMv == cCompMv )
+      {
+        iRet = 2; // L1=2
+      }
+      break;
+    case 3:
+      cMv = getCUMvField( RefPicList(0) )->getMv( uiPartIdx );
+      if( cMv == cCompMv )
+      {
+        cMv = getCUMvField( RefPicList(1) )->getMv( uiPartIdx );
+        if( cMv == cCompMv )
+        {
+          iRet = 3; // BI=3
+        }
+      }
+      break;
+    }
+  }
+
+  return iRet; 
+}
+#endif
+
 // ====================================================================================================================
 // Protected member functions
@@ -5612,4 +5865,11 @@
   }
  
+#if AMVP_VSP_UNAVAILABLE
+  if( pcTmpCU != NULL && pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && pcTmpCU->getSlice()->getRefViewId( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ) == NUM_VIEW_VSP )
+  {
+    return false;
+  }
+#endif
+
   if ( pcTmpCU != NULL && m_pcSlice->isEqualRef(eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx), iRefIdx) )
   {
@@ -5713,4 +5973,7 @@
   TComDataCU* pcTmpCU = NULL;
   UInt uiIdx;
+#if VSP_N
+  Bool bRefVsp = false;
+#endif
   switch( eDir )
   {
@@ -5770,4 +6033,11 @@
     return false;
   }
+
+#if AMVP_VSP_UNAVAILABLE
+  if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && pcTmpCU->getSlice()->getRefViewId( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ) == NUM_VIEW_VSP )
+  {
+    return false;
+  }
+#endif
   
   RefPicList eRefPicList2nd = REF_PIC_LIST_0;
@@ -5815,5 +6085,13 @@
     }
 
+#if VSP_N
+    if( pcTmpCU->getSlice()->getRefViewId( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ) == NUM_VIEW_VSP )
+    {
+      bRefVsp = true;
+    }
+    Int iScale = bRefVsp ? 4096 : xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+#else
     Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+#endif
     if ( iScale == 4096 )
     {
@@ -5842,5 +6120,13 @@
     }
 
+#if VSP_N
+    if( pcTmpCU->getSlice()->getRefViewId( eRefPicList2nd, pcTmpCU->getCUMvField(eRefPicList2nd)->getRefIdx(uiIdx) ) == NUM_VIEW_VSP )
+    {
+      bRefVsp = true;
+    }
+    Int iScale = bRefVsp ? 4096 : xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+#else
     Int iScale = xGetDistScaleFactor( iCurrPOC, iCurrRefPOC, iNeibPOC, iNeibRefPOC );
+#endif
     if ( iScale == 4096 )
     {
@@ -5875,7 +6161,23 @@
   Int iColViewIdx, iColRefViewIdx;
   TComPic *pColPic = getSlice()->getRefPic( eRefPicList, refidx);
+#if VSP_MV_ZERO // shimizu
   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
   iColViewIdx = pColCU->getSlice()->getViewId();
-
+#if VSP_N
+  if( iColViewIdx == NUM_VIEW_VSP )
+  {
+    return false;
+  }
+#endif
+#else  
+#if VSP_N
+  if( pColPic->getSlice(0)->getViewId() == NUM_VIEW_VSP )
+  {
+    return false;
+  }
+#endif
+  TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
+  iColViewIdx = pColCU->getSlice()->getViewId();
+#endif
 
   if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiAbsPartAddr))
@@ -5904,4 +6206,10 @@
 
     iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewId();
+#if VSP_N
+    if( iColRefViewIdx == NUM_VIEW_VSP )
+    {
+      continue;
+    }
+#endif
 
     if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
@@ -6040,4 +6348,11 @@
   iScale = 0;
   iCurrRefViewOrderIdx = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewOrderIdx();
+#if VSP_N
+//  UInt uiColRefViewId = pColCU->getSlice()->getRefPic( eColRefPicList, pColCU->getCUMvField(eColRefPicList)->getRefIdx(uiAbsPartAddr))->getViewId();
+  UInt uiCurRefViewId = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getViewId();
+  if( uiCurRefViewId == NUM_VIEW_VSP )
+    iScale = 4096;
+  else
+#endif
   if((iColPOC != iColRefPOC)&&(iCurrPOC != iCurrRefPOC))
     iScale = xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iColPOC, iColRefPOC);
@@ -6052,4 +6367,9 @@
   if ( iScale == 4096 )
   {
+#if VSP_MV_ZERO
+    if( uiCurRefViewId == NUM_VIEW_VSP )
+      rcMv.setZero();
+    else
+#endif
     rcMv = cColMv;
   }
@@ -6151,4 +6471,9 @@
     return false;
   }
+
+#if VSP_N //??
+  if (pColCU->isSkipped(uiPartIdxCenter))
+    return false;
+#endif
   
   if( m_pcSlice->getRefPic( eRefPicList, iRefIdx )->getViewId() != m_pcSlice->getViewId() )
@@ -7705,2 +8030,3 @@
 
 //! \}
+
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDataCU.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDataCU.h	(revision 166)
@@ -265,4 +265,8 @@
   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 FORCE_REF_VSP==2
+  inline bool   xAddVspSkip(UChar ucVspMergePos, Bool bVspMvZeroDone, UInt uiDepth, Bool* abCandIsInter, Int& iCount,
+                            UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int mrgCandIdx);
+#endif
 
   Void          deriveRightBottomIdx        ( PartSize eCUMode, UInt uiPartIdx, UInt& ruiPartIdxRB );
@@ -656,4 +660,10 @@
   Bool          isIntra   ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA; }
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
+#if FORCE_REF_VSP==1
+  Int           isVspMode ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_SYNTH; }
+#elif FORCE_REF_VSP==2 
+  Int           isVspMode ( UInt uiPartIdx );
+  Int           isVspMode ( UInt uiPartIdx, TComMv cCompMv );
+#endif
   
   // -------------------------------------------------------------------------------------------------------------------
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 166)
@@ -562,4 +562,12 @@
   m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
 }
+
+#if VSP_N
+Void
+TComDepthMapGenerator::clearDepthMap( TComPic* pcPic, Int iVal/*=PDM_UNDEFINED_DEPTH*/ )
+{
+  xClearDepthMap( pcPic, iVal );
+}
+#endif
 #endif
 
@@ -733,5 +741,8 @@
       Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicList );
       for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
-{
+      {
+#if VSP_N
+        if( pcSlice->getRefViewId( eRefPicList, iPdmRefIdx ) != NUM_VIEW_VSP )
+#endif
         if( pcSlice->getRefPOC( eRefPicList, iPdmRefIdx ) == pcSlice->getPOC())
         {
@@ -834,6 +845,17 @@
   Int           iRefPoc     = pcRefPic->getPOC();
   Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
+#if VSP_N
+  Bool          bVsp        = ( pcRefPic->getViewId() == NUM_VIEW_VSP );
+  AOT(  bInterview &&  bVsp && iRefPoc != pcSlice->getPOC() );
+  AOT( !bInterview && !bVsp && iRefPoc == pcSlice->getPOC() );
+#else
   AOT(  bInterview && iRefPoc != pcSlice->getPOC() );
   AOT( !bInterview && iRefPoc == pcSlice->getPOC() );
+#endif
+
+#if FORCE_REF_VSP
+  if( bVsp ) return false;
+#endif
+
   Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
   Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
@@ -924,6 +946,16 @@
   Int           iRefPoc     = pcRefPic->getPOC();
   Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
+#if VSP_N
+  Bool          bVsp        = ( pcRefPic->getViewId() == NUM_VIEW_VSP );
+  AOT(  bInterview &&  bVsp && iRefPoc != pcSlice->getPOC() );
+  AOT( !bInterview && !bVsp && iRefPoc == pcSlice->getPOC() );
+#else
   AOT(  bInterview && iRefPoc != pcSlice->getPOC() );
   AOT( !bInterview && iRefPoc == pcSlice->getPOC() );
+#endif
+
+#if FORCE_REF_VSP
+  if( bVsp ) return false;
+#endif
 
   Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
@@ -1351,4 +1383,9 @@
     xInterPredictCUDepthMap( pcSubCU, pcSubDM );
     break;
+#if FORCE_REF_VSP==1
+  case MODE_SYNTH:
+    xIntraPredictCUDepthMap( pcSubCU, pcSubDM ); //What to do? Need Fix!
+    break;
+#endif
   default:
     AOT( true );
@@ -1464,4 +1501,14 @@
                                           aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != m_uiCurrViewId };
     Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
+#if VSP_N
+    if(( aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getViewId() == NUM_VIEW_VSP ) ||
+       ( aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getViewId() == NUM_VIEW_VSP )) {
+      //if refpic is VSP, copy to Original cuurent PDM
+      TComPicYuv* pcPdm = pcCU->getPic()->getPredDepthMap();
+      UInt  uiZOrderIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
+      assert( pcPdm );
+      pcCUDepthMap->copyFromPicYuv( pcPdm, pcCU->getAddr(), uiZOrderIdx );
+    }
+#endif
     if( bUsesInterViewPrd )
     {
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 166)
@@ -140,4 +140,7 @@
   Void  updateDepthMap        ( TComPic*      pcPic );
   Void  dumpDepthMap          ( TComPic*      pcPic, char* pFilenameBase );
+#if VSP_N
+  Void  clearDepthMap         ( TComPic*      pcPic, Int   iVal  = PDM_UNDEFINED_DEPTH);
+#endif
 #endif
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 166)
@@ -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 FORCE_REF_VSP==1
+    || pcCUP->isVspMode(uiPartP) || pcCUQ->isVspMode(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 FORCE_REF_VSP==1
+    && !pcCUP->isVspMode(uiPartP) && !pcCUQ->isVspMode(uiPartQ) 
+#endif
+  )
   {
 #if NSQT_LFFIX
@@ -542,4 +550,11 @@
   }   // enf of "if( not Intra )"
   
+#if FORCE_REF_VSP==1
+  if ( pcCUP->isVspMode(uiPartP) || pcCUQ->isVspMode(uiPartQ))
+  {
+    uiBs = 0;
+  }
+#endif
+
   m_aapucBS[iDir][uiAbsPartIdx] = uiBs;
 }
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPic.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPic.cpp	(revision 166)
@@ -53,4 +53,8 @@
   m_apcPicYuv[0]      = NULL;
   m_apcPicYuv[1]      = NULL;
+#if VSP_N
+  m_apcPicYuvAvail     = NULL;
+  m_apcPicYuvSynth     = NULL;
+#endif
 #if DEPTH_MAP_GENERATION
   m_pcPredDepthMap    = NULL;
@@ -64,4 +68,7 @@
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   m_pcResidual        = NULL;
+#endif
+#if DEBUGIMGOUT
+  m_acPicYuvDebug     = NULL;
 #endif
   m_pcPicYuvPred      = NULL;
@@ -95,5 +102,8 @@
   }
   m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
-  
+#if DEBUGIMGOUT
+  m_acPicYuvDebug    = new TComPicYuv;  m_acPicYuvDebug->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
+#endif
+
   /* there are no SEI messages associated with this picture initially */
   m_SEIs = NULL;
@@ -162,4 +172,12 @@
     delete m_pcResidual;
     m_pcResidual = NULL;
+  }
+#endif
+#if DEBUGIMGOUT
+  if (m_acPicYuvDebug)
+  {
+    m_acPicYuvDebug->destroy();
+    delete m_acPicYuvDebug;
+    m_acPicYuvDebug = NULL;
   }
 #endif
@@ -623,4 +641,59 @@
 }
 
+#if VSP_N
+Void TComPic::checkSynthesisAvailability( /*TComDataCU*& rpcCU, */UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, Bool *&rpbCUSynthesied )
+{ 
+  rpbCUSynthesied[0] = true;
+  rpbCUSynthesied[1] = true;
+  rpbCUSynthesied[2] = true;
+  rpbCUSynthesied[3] = true;
+
+  if (!getPicYuvAvail())
+  {
+    rpbCUSynthesied[0] = false;
+    rpbCUSynthesied[1] = false;
+    rpbCUSynthesied[2] = false;
+    rpbCUSynthesied[3] = false;
+    return;    
+  }
+  
+  Int x, y;
+  Pel* pAvail  = getPicYuvAvail()->getLumaAddr ( iCuAddr, uiAbsZorderIdx );
+  Int CUHeight = g_uiMaxCUHeight >> uiPartDepth; //rpcCU->getHeight(uiAbsZorderIdx);
+  Int CUWidth  = g_uiMaxCUWidth  >> uiPartDepth; //rpcCU->getWidth(uiAbsZorderIdx);
+  
+  Int  iStride  = getPicYuvAvail()->getStride();
+  for ( y = ((CUHeight - 1) >> 1); y >= 0; y-- )
+  {
+    for ( x = ((CUWidth - 1) >> 1); x >= 0; x-- )
+    {
+      rpbCUSynthesied[0] &= (pAvail[x] != 0);
+    }
+    for ( x = CUWidth - 1; x >= ((CUWidth) >> 1); x-- )
+    {
+      rpbCUSynthesied[1] &= (pAvail[x] != 0);
+    }
+    pAvail += iStride;
+  }
+  //for ( y = CUHeight - 1; y >= ((CUHeight) >> 1); y-- )
+  for ( y = ((CUHeight - 1) >> 1); y >= 0; y-- ) //Owieczka
+  {
+    for ( x = ((CUWidth - 1) >> 1); x >= 0; x-- )
+    {
+      rpbCUSynthesied[2] &= (pAvail[x] != 0);
+    }
+    for ( x = CUWidth - 1; x >= ((CUWidth) >> 1); x-- )
+    {
+      rpbCUSynthesied[3] &= (pAvail[x] != 0);
+    }
+    pAvail += iStride;
+  }
+
+  //rpbCUSynthesied[0] = !rpbCUSynthesied[0];
+  //rpbCUSynthesied[1] = !rpbCUSynthesied[1];
+  //rpbCUSynthesied[2] = !rpbCUSynthesied[2];
+  //rpbCUSynthesied[3] = !rpbCUSynthesied[3];
+}
+#endif
 
 //! \}
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPic.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPic.h	(revision 166)
@@ -65,4 +65,9 @@
   TComPicYuv*           m_apcPicYuv[2];           //  Texture,  0:org / 1:rec
   
+#if VSP_N
+  TComPicYuv*           m_apcPicYuvAvail;         //  Availability Map - Does the given pixel can be synthesised in receiver
+  TComPicYuv*           m_apcPicYuvSynth;         //  Sythesied image
+#endif
+
 #if DEPTH_MAP_GENERATION
   TComPicYuv*           m_pcPredDepthMap;         //  estimated depth map
@@ -85,4 +90,7 @@
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   TComPicYuv*           m_pcResidual;             //  residual buffer (coded or inter-view predicted residual)
+#endif
+#if DEBUGIMGOUT
+  TComPicYuv*           m_acPicYuvDebug;          //  debug image
 #endif
 
@@ -145,4 +153,11 @@
   TComPicYuv*   getPicYuvOrg()        { return  m_apcPicYuv[0]; }
   TComPicYuv*   getPicYuvRec()        { return  m_apcPicYuv[1]; }
+#if VSP_N
+  Void          setPicYuvAvail( TComPicYuv* pc ){ m_apcPicYuvAvail = pc; }
+  Void          setPicYuvSynth( TComPicYuv* pc ){ m_apcPicYuvSynth = pc; }
+  TComPicYuv*   getPicYuvAvail()      { return  m_apcPicYuvAvail; }
+  TComPicYuv*   getPicYuvSynth()      { return  m_apcPicYuvSynth; }
+  Void          checkSynthesisAvailability(  /*TComDataCU*& rpcBestCU, */UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth, Bool *&rpbCUSynthesied);
+#endif
 #if HHI_INTERVIEW_SKIP
   TComPicYuv*   getUsedPelsMap()      { return  m_pcUsedPelsMap; }
@@ -168,4 +183,8 @@
 #if HHI_INTER_VIEW_RESIDUAL_PRED
   TComPicYuv*   getResidual()         { return  m_pcResidual; }
+#endif
+
+#if DEBUGIMGOUT
+  TComPicYuv*   getPicYuvRecDbg()     { return  m_acPicYuvDebug; }
 #endif
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicSym.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicSym.cpp	(revision 166)
@@ -97,4 +97,8 @@
     m_puiInverseCUOrderMap[i] = i;
   }
+
+#if VSP_N
+  m_apcTComTile = NULL;
+#endif
 }
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicYuv.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPicYuv.h	(revision 166)
@@ -184,4 +184,13 @@
   Void  setChromaTo  ( Pel pVal );  
 
+#if DEBUGIMGOUT
+  // Degub tools
+public:
+  Void colsetToPicYuv   ( const UChar ucColor[3],                 Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+  Void colsetToPicLuma  ( const UChar ucLumaOffCol,               Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+  Void colsetToPicChroma( const UChar ucUCol, const UChar ucVCol, Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+  Void drawLineToPicYuv ( bool bHor, bool bVer, UInt uiSize,      TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+#endif
+
 };// END CLASS DEFINITION TComPicYuv
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPrediction.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComPrediction.h	(revision 166)
@@ -95,5 +95,4 @@
   Void xPredInterPrdDepthMap    ( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight,                         TComYuv*& rpcYuv, UInt uiRShift, UInt uiOffset );
 #endif
-
 #if DEPTH_MAP_GENERATION
   Void xWeightedAveragePdm      ( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY );
@@ -103,5 +102,5 @@
   Void xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi );
   Void xWeightedAverage         ( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst );
-  
+
   Void xGetLLSPrediction ( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 );
 
@@ -142,5 +141,5 @@
   Void motionCompensation         ( TComDataCU*  pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList = REF_PIC_LIST_X, Int iPartIdx = -1 );
 #endif
-  
+
   // motion vector prediction
   Void getMvPredAMVP              ( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComResidualGenerator.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 166)
@@ -390,4 +390,9 @@
     xSetRecResidualInterCU( pcSubCU, pcSubRes );
     break;
+#if FORCE_REF_VSP==1
+  case MODE_SYNTH:
+    xSetRecResidualIntraCU( pcSubCU, pcSubRes ); //MayBe it should be seperate function
+    break;
+#endif
   default:
     AOT( true );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 166)
@@ -114,4 +114,8 @@
 {
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
+
+#if FORCE_REF_VSP
+  m_iRefIdxVsp[0] = m_iRefIdxVsp[1] = NOT_VALID;
+#endif
   
   initEqualRef();
@@ -139,4 +143,8 @@
   resetWpScalingLC(m_weightPredTableLC);
   initWpAcDcParam();
+
+#if VSP_SLICE_HEADER
+  m_bVspFlag = false;
+#endif
 }
 
@@ -185,4 +193,8 @@
   m_numEntryPointOffsets = 0;
 #endif
+#if VSP_SLICE_HEADER
+  m_bVspFlag = false;
+#endif
+
 }
 
@@ -407,5 +419,9 @@
 }
 
+#if VSP_N
+Void TComSlice::setRefPicListMvc( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics, TComPic* pcVspPic )
+#else
 Void TComSlice::setRefPicListMvc( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics )
+#endif
 {
   if( m_eSliceType == I_SLICE )
@@ -422,4 +438,7 @@
   TComPic*  RefPicSetLtCurr [16];
   TComPic*  RefPicSetIvCurr [16];
+#if VSP_N
+  TComPic*  RefPicSetVspCurr [16] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; //for Linux comp
+#endif
 
   UInt NumPocStCurr0 = 0;
@@ -427,4 +446,7 @@
   UInt NumPocLtCurr  = 0;
   UInt NumPocIvCurr  = 0;
+#if VSP_N
+  UInt NumPocVspCurr  = 0;
+#endif
 
   Int i;
@@ -474,4 +496,14 @@
     NumPocIvCurr++;
   }
+#if VSP_N
+  if( pcVspPic )
+  {
+    pcRefPic = pcVspPic;
+    pcRefPic->setIsLongTerm( 0 );
+    pcRefPic->getPicYuvRec()->extendPicBorder();
+    RefPicSetVspCurr[NumPocVspCurr] = pcRefPic;
+    NumPocVspCurr++;
+  }
+#endif
 
   // ref_pic_list_init
@@ -481,6 +513,11 @@
 
   assert( (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) == getNumPocTotalCurrMvc() );
+#if VSP_N
+  Int numRpsCurrTempList0 = max( (num_ref_idx_l0_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr + NumPocVspCurr) );
+  Int numRpsCurrTempList1 = max( (num_ref_idx_l1_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr + NumPocVspCurr) );
+#else
   Int numRpsCurrTempList0 = max( (num_ref_idx_l0_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) );
   Int numRpsCurrTempList1 = max( (num_ref_idx_l1_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) );
+#endif
 
   assert( numRpsCurrTempList0 <= 16 );
@@ -509,5 +546,17 @@
   for( cIdx = 0; cIdx <= num_ref_idx_l0_active_minus1; cIdx ++ )
   {
+#if VSP_N
+    if( pcVspPic && cIdx == num_ref_idx_l0_active_minus1 )
+    {
+      m_apcRefPicList[0][cIdx] = RefPicSetVspCurr[0];
+#if FORCE_REF_VSP
+      m_iRefIdxVsp[0] = cIdx;
+#endif
+    }
+    else
+      m_apcRefPicList[0][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? refPicListTemp0[ m_RefPicListModification.getRefPicSetIdxL0(cIdx) ] : refPicListTemp0[cIdx];
+#else
     m_apcRefPicList[0][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? refPicListTemp0[ m_RefPicListModification.getRefPicSetIdxL0(cIdx) ] : refPicListTemp0[cIdx];
+#endif
   }
   if( m_eSliceType == P_SLICE )
@@ -520,5 +569,17 @@
     for( cIdx = 0; cIdx <= num_ref_idx_l1_active_minus1; cIdx ++ )
     {
+#if VSP_N
+      if( pcVspPic && cIdx == num_ref_idx_l1_active_minus1 )
+      {
+        m_apcRefPicList[1][cIdx] = RefPicSetVspCurr[0];
+#if FORCE_REF_VSP
+        m_iRefIdxVsp[1] = cIdx;
+#endif
+      }
+      else
+        m_apcRefPicList[1][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? refPicListTemp1[ m_RefPicListModification.getRefPicSetIdxL1(cIdx) ] : refPicListTemp1[cIdx];
+#else
       m_apcRefPicList[1][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? refPicListTemp1[ m_RefPicListModification.getRefPicSetIdxL1(cIdx) ] : refPicListTemp1[cIdx];
+#endif
     }
   }
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 166)
@@ -45,5 +45,4 @@
 #include "TComRom.h"
 #include "TComList.h"
-
 //! \ingroup TLibCommon
 //! \{
@@ -1269,5 +1268,13 @@
 
 #if SONY_COLPIC_AVAILABILITY
-  Int         m_iViewOrderIdx;
+  Int        m_iViewOrderIdx;
+#endif
+
+#if FORCE_REF_VSP
+  Int        m_iRefIdxVsp[2]; // L0/L1
+#endif
+
+#if VSP_SLICE_HEADER
+  Bool      m_bVspFlag;
 #endif
 
@@ -1411,5 +1418,9 @@
   Int       getNumPocTotalCurr();
   Int       getNumPocTotalCurrMvc();
+#if VSP_N
+  Void      setRefPicListMvc    ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics, TComPic* pcVspPic );
+#else
   Void      setRefPicListMvc    ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics );
+#endif
   Void      setRefPOCnViewListsMvc();
 
@@ -1565,4 +1576,14 @@
   Int*      getInvCodedOffset     ()  { return m_aaiCodedOffset[1]; }
 
+#if FORCE_REF_VSP
+  Void      setRefIdxVsp ( Int idx, Int refList ) { m_iRefIdxVsp[refList] = idx; }
+  Int       getRefIdxVsp ( Int refList )          { return m_iRefIdxVsp[refList]; }
+#endif
+
+#if VSP_SLICE_HEADER
+  Void      setVspFlag          ( Bool val )    { m_bVspFlag = val; }
+  Bool      getVspFlag          ()              { return m_bVspFlag; }
+#endif
+
 protected:
   TComPic*  xGetRefPic        (TComList<TComPic*>& rcListPic, UInt uiPOC);
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComYuv.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComYuv.h	(revision 166)
@@ -213,4 +213,13 @@
 
   __inline Pel  xClip  (Pel x )      { return ( (x < 0) ? 0 : (x > (Pel)g_uiIBDI_MAX) ? (Pel)g_uiIBDI_MAX : x ); }
+
+#if DEBUGIMGOUT
+public:
+  Void colsetToPicYuv   ( const UChar ucColor[3],                 Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+  Void colsetToPicLuma  ( const UChar ucLumaOffCol,               Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+  Void colsetToPicChroma( const UChar ucUCol, const UChar ucVCol, Int iOffset[2][2], TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+  Void drawLineToPicYuv ( bool bHor, bool bVer, UInt uiSize,      TComPicYuv* pcPicYuvDst, UInt iCuAddr, UInt uiAbsZorderIdx, UInt uiPartDepth = 0, UInt uiPartIdx = 0 );
+#endif
+
 };// END CLASS DEFINITION TComYuv
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 166)
@@ -42,4 +42,23 @@
 //! \{
 
+#define VSP_N                             1
+#if VSP_N
+#define VSP_TEXT_ONLY                     1
+#define NUM_VIEW_VSP                      99
+#define VSP_N_DUMP                        0
+#define FORCE_REF_VSP                     2   // 0=NotUseVSPSKIP 1:VSPSKIPforFlag 2:VSPSKIPforMergeIdx
+#define VSP_MV_ZERO                       0   // use zero vector for VSP
+#if VSP_MV_ZERO
+#define AMVP_VSP_UNAVAILABLE              1
+#endif
+#define VSP_MERGE_POS                     5   // position of vsp in merge list (0..5)
+#define NTT_SUBPEL                        1
+#endif
+#define DEBUGIMGOUT                       0   //Debug YUVImage Out
+#define DEBUGLOGOUT                       0   //Debug Log Out
+
+#define VSP_SLICE_HEADER                  1
+#define VSP_FRAME_INTERVAL                2
+
 #define FIXES                             1
 #define POZNAN_CABAC_INIT_FLAG_FIX        1
@@ -115,5 +134,5 @@
 #define HHI_FULL_PEL_DEPTH_MAP_MV_ACC     1   // full-pel mv accuracy for depth maps
                                        
-#if HHI_INTER_VIEW_MOTION_PRED         
+#if HHI_INTER_VIEW_MOTION_PRED
 #define SAIT_IMPROV_MOTION_PRED_M24829    1   // improved inter-view motion vector prediction
 #else                                  
@@ -727,4 +746,7 @@
   MODE_INTER,           ///< inter-prediction mode
   MODE_INTRA,           ///< intra-prediction mode
+#if FORCE_REF_VSP==1
+  MODE_SYNTH,           ///< synth-mode
+#endif
   MODE_NONE = 15
 };
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:
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
 
   // -------------------------------------------------------------------------------------------------------------------
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenFilter.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenFilter.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenFilter.cpp	(revision 166)
@@ -1154,4 +1154,45 @@
 }
 
+#if NTT_SUBPEL
+// Convert luma sample
+Void TRenFilter::sampleConv( Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride, Pel* pcDepthPlaneData, Int iDepthStride, Int** ppiFposLUT )
+{
+  TRenInterpFilter cFilter;
+
+  xDistributeArrayOnDepthCondition  ( pcInputPlaneData, iInputStride, 1 , 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 1, 1, pcDepthPlaneData, iDepthStride, 1, 1, ppiFposLUT);
+  cFilter.xCTI_FilterQuarter0Hor    ( pcInputPlaneData, iInputStride, 1, iInputWidth, iHeight, iOutputStride, 1, pcOutputPlaneData, pcDepthPlaneData, iDepthStride, 1, ppiFposLUT );
+  cFilter.xCTI_FilterHalfHor        ( pcInputPlaneData, iInputStride, 1, iInputWidth, iHeight, iOutputStride, 1, pcOutputPlaneData, pcDepthPlaneData, iDepthStride, 1, ppiFposLUT );
+  cFilter.xCTI_FilterQuarter1Hor    ( pcInputPlaneData, iInputStride, 1, iInputWidth, iHeight, iOutputStride, 1, pcOutputPlaneData, pcDepthPlaneData, iDepthStride, 1, ppiFposLUT );
+}
+
+Void TRenFilter::sampleCVerUp( Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  xDistributeArray( pcInputPlaneData-3, iInputStride, 1, 1, iInputWidth+6, iHeight, pcOutputPlaneData              -3, iOutputStride, 1, 2 );
+  xInterpVerChroma( pcInputPlaneData-3, iInputStride, 1, 1, iInputWidth+6, iHeight, pcOutputPlaneData+iOutputStride-3, iOutputStride, 1, 2, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+}
+
+Void TRenFilter::sampleCConv( Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride, Pel* pcDepthPlaneData, Int iDepthStride, Int** ppiFposLUT )
+{
+  // assume quater resolution depth 
+  xDistributeArrayOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 1, 1, pcDepthPlaneData, iDepthStride, 2, 2, ppiFposLUT);
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 1, 1, pcDepthPlaneData, iDepthStride, 2, 2, ppiFposLUT, 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA0 );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 1, 1, pcDepthPlaneData, iDepthStride, 2, 2, ppiFposLUT, 2, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 1, 1, pcDepthPlaneData, iDepthStride, 2, 2, ppiFposLUT, 3, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA1 );
+}
+
+Void TRenFilter::sampleCConvHorUp( Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride, Pel* pcDepthPlaneData, Int iDepthStride, Int** ppiFposLUT )
+{
+  xDistributeArrayOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT);
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 1, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT0 );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 2, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA0 );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 3, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT1 );
+
+  pcOutputPlaneData++; pcDepthPlaneData++;
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 0, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 1, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT2 );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 2, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA1 );
+  xInterpHorChromaOnDepthCondition( pcInputPlaneData, iInputStride, 1, 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1, pcDepthPlaneData, iDepthStride, 2, 1, ppiFposLUT, 3, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT3 );
+}
+#endif
 
 // Down Sampling
@@ -1224,4 +1265,71 @@
   }
 }
+
+#if NTT_SUBPEL
+Void TRenFilter::xDistributeArrayOnDepthCondition(Pel* pcSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* pcDst, Int iDstStride, Int iDstStepX, Int iDstStepY, Pel* pcDep, Int iDepStride, Int iDepStepX, Int iDepStepY, Int** ppiFposLUT)
+{
+  iDstStride *= iDstStepY;
+  iSrcStride *= iSrcStepY;
+  iDepStride *= iDepStepY;
+
+  for (Int iYPos = 0; iYPos < iHeight; iYPos++ )
+  {
+    Pel* pcCurDst = pcDst;
+    Pel* pcCurSrc = pcSrc;
+    Pel* pcCurDep = pcDep;
+
+    for (Int iXPos = 0; iXPos < iWidth; iXPos ++)
+    {
+      if( ppiFposLUT[0][ *pcCurDep ] == 0 )
+      {
+        *pcCurDst = *pcCurSrc;
+      }
+      pcCurDst += iDstStepX;
+      pcCurSrc += iSrcStepX;
+      pcCurDep += iDepStepX;
+    }
+    pcDst  += iDstStride;
+    pcSrc  += iSrcStride;
+    pcDep  += iDepStride;
+  }
+}
+
+Void TRenFilter::xInterpHorChromaOnDepthCondition( Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, Pel* piDep, Int iDepStride, Int iDepStepX, Int iDepStepY, Int** ppiFposLUT, Int iTargetFpos, FpChromaIntFilt fpFilter )
+{
+  Int   iSum;
+  Pel*  piSrcTmpP;
+  Pel*  piSrcTmpN;
+  Pel*  piSrcTmp;
+
+  Int   iDepX;
+
+  TRenInterpFilter cFilter;
+  for ( Int y = 0; y < iHeight; y++ )
+  {
+    piSrcTmpP = piSrc - iSrcStepX;
+    piSrcTmpN = piSrc - iSrcStepX*2;
+    iDepX = 0;
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+#if 0 // NTT bugfix
+      if( abs(ppiFposLUT[0][ piDep[iDepX] ]) == iTargetFpos )
+#else
+      if( ppiFposLUT[0][ piDep[iDepX] ] == iTargetFpos || ppiFposLUT[0][ piDep[iDepX] ]+4 == iTargetFpos )
+#endif
+      {
+        piSrcTmp = ppiFposLUT[0][ piDep[ iDepX ] ] >= 0 ? piSrcTmpP : piSrcTmpN;
+        iSum      = (cFilter.*fpFilter)( piSrcTmp,  iSrcStepX );
+        piDst[x * iDstStepX ] =  Clip ((iSum +  32) >>  6 );
+      }
+      piSrcTmpP += iSrcStepX;
+      piSrcTmpN += iSrcStepX;
+      iDepX += iDepStepX;
+    }
+    piSrc += iSrcStride * iSrcStepY;
+    piDst += iDstStride * iDstStepY;
+    piDep += iDepStride * iDepStepY;
+  }
+}
+#endif
 
 
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenFilter.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenFilter.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenFilter.h	(revision 166)
@@ -103,4 +103,11 @@
   static Void sampleCUpHorUp    (Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight,      Pel* pcOutputPlaneData, Int iOutputStride );
 
+#if NTT_SUBPEL
+  static Void sampleConv        (Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride, Pel* pcDepthPlaneData, Int iDepthStride, Int** ppiFposLUT );
+  static Void sampleCVerUp      (Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride );
+  static Void sampleCConv       (Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride, Pel* pcDepthPlaneData, Int iDepthStride, Int** ppiFposLUT );
+  static Void sampleCConvHorUp  (Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride, Pel* pcDepthPlaneData, Int iDepthStride, Int** ppiFposLUT );
+#endif
+
   //// Down sampling (13 tap)
 
@@ -131,4 +138,9 @@
   static Void xDistributeArray(Pel* pcSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* pcDst, Int iDstStride, Int iDstStepX, Int iDstStepY );
 
+#if NTT_SUBPEL
+  static Void xDistributeArrayOnDepthCondition(Pel* pcSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* pcDst, Int iDstStride, Int iDstStepX, Int iDstStepY, Pel* pcDep, Int iDepStride, Int iDepStepX, Int iDepStepY, Int** ppiFposLUT);
+  static Void xInterpHorChromaOnDepthCondition(Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, Pel* piDep, Int iDepStride, Int iDepStepX, Int iDepStepY, Int** ppiFposLUT, Int iTargetFpos, FpChromaIntFilt fpFilter );
+#endif
+
   // Binominal Filtering
   static Pel  xFiltBinom3     (Pel* pcInputData, Int iStride );
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenInterpFilter.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenInterpFilter.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenInterpFilter.h	(revision 166)
@@ -72,5 +72,11 @@
   __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);
-  
+
+#if NTT_SUBPEL
+  __inline Void xCTI_FilterHalfHor    (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst, Pel* piDep, Int iDepStride, Int iDepStep, Int** ppiFposLUT);
+  __inline Void xCTI_FilterQuarter0Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst, Pel* piDep, Int iDepStride, Int iDepStep, Int** ppiFposLUT);
+  __inline Void xCTI_FilterQuarter1Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst, Pel* piDep, Int iDepStride, Int iDepStep, Int** ppiFposLUT);
+#endif
+
   __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 );
@@ -683,4 +689,174 @@
 }
 
+#if NTT_SUBPEL
+__inline Void TRenInterpFilter::xCTI_FilterHalfHor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst, Pel* piDep, Int iDepStride, Int iDepStep, Int** ppiFposLUT)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+
+  Pel *piSrcTmpP, *piSrcTmpN;
+  Int iDepX;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmpP = &piSrc[ -3*iSrcStep ];
+    piSrcTmpN = &piSrc[ -4*iSrcStep ];
+    iDepX = 0;
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+#if 0 // NTT bugfix
+      if( abs(ppiFposLUT[0][ piDep[ iDepX ] ]) == 2 )
+#else
+      if( ppiFposLUT[0][ piDep[ iDepX ] ] == 2 ||  ppiFposLUT[0][ piDep[ iDepX ] ] == -2 )
+#endif
+      {
+        piSrcTmp = ppiFposLUT[0][ piDep[ iDepX ] ] > 0 ? piSrcTmpP : piSrcTmpN;
+
+        iTmp0 = piSrcTmp[        0]+piSrcTmp[iSrcStep7];
+        iTmp1 = piSrcTmp[iSrcStep]+piSrcTmp[iSrcStep6];
+        iTmp2 = piSrcTmp[iSrcStep2]+piSrcTmp[iSrcStep5];
+        iTmp3 = piSrcTmp[iSrcStep3]+piSrcTmp[iSrcStep4];
+
+        iTmpA = (iTmp3 << 2) - iTmp2;
+
+        iSum  = (   iTmp1          << 2 )
+              + (   iTmpA          << 3 )
+              + (   iTmpA          << 1 )
+              -    iTmp0 -  iTmp2;
+
+        piDst   [x * iDstStep] = Clip( (iSum +  32) >>  6 );
+      }
+      piSrcTmpP += iSrcStep;
+      piSrcTmpN += iSrcStep;
+      iDepX += iDepStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+    piDep += iDepStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst, Pel* piDep, Int iDepStride, Int iDepStep, Int** ppiFposLUT)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int iTmp1, iTmp2;
+
+  Pel *piSrcTmpP, *piSrcTmpN;
+  Int iDepX;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmpP = &piSrc[ -3*iSrcStep ];
+    piSrcTmpN = &piSrc[ -4*iSrcStep ];
+    iDepX = 0;
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+#if 0 // NTT bugfix
+      if( abs(ppiFposLUT[0][ piDep[ iDepX ] ]) == 1 )
+#else
+      if( ppiFposLUT[0][ piDep[ iDepX ] ] == 1 ||  ppiFposLUT[0][ piDep[ iDepX ] ] == -3 )
+#endif
+      {
+        piSrcTmp = ppiFposLUT[0][ piDep[ iDepX ] ] > 0 ? piSrcTmpP : piSrcTmpN;
+
+        iTmp1 = piSrcTmp[iSrcStep3] + piSrcTmp[iSrcStep5];
+        iTmp2 = piSrcTmp[iSrcStep6] + piSrcTmp[iSrcStep4];
+
+        iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+               - ( ( piSrcTmp[iSrcStep2] - iTmp2 ) << 1 )
+               + (  piSrcTmp[iSrcStep]             << 2 )
+               - ( ( piSrcTmp[iSrcStep2] + iTmp1 ) << 3 )
+               + (   piSrcTmp[iSrcStep4]           << 4 );
+
+        piDst   [x * iDstStep] = Clip(( (iSum +  32) >>  6 )+ piSrcTmp[iSrcStep3]);
+      }
+      piSrcTmpP += iSrcStep;
+      piSrcTmpN += iSrcStep;
+      iDepX += iDepStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+    piDep += iDepStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst, Pel* piDep, Int iDepStride, Int iDepStep, Int** ppiFposLUT)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int  iTmp1, iTmp2;
+
+  Pel *piSrcTmpP, *piSrcTmpN;
+  Int iDepX;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmpP = &piSrc[ -3*iSrcStep ];
+    piSrcTmpN = &piSrc[ -4*iSrcStep ];
+    iDepX = 0;
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+#if 0 // NTT bugfix
+      if( abs(ppiFposLUT[0][ piDep[ iDepX ] ]) == 3 )
+#else
+      if( ppiFposLUT[0][ piDep[ iDepX ] ] == 3 ||  ppiFposLUT[0][ piDep[ iDepX ] ] == -1 )
+#endif
+      {
+        piSrcTmp = ppiFposLUT[0][ piDep[ iDepX ] ] > 0 ? piSrcTmpP : piSrcTmpN;
+
+        iTmp1 = piSrcTmp[iSrcStep4] + piSrcTmp[iSrcStep2];
+        iTmp2 = piSrcTmp[iSrcStep ] + piSrcTmp[iSrcStep3];
+
+        iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+              - ( ( piSrcTmp[iSrcStep5] - iTmp2 ) << 1 )
+              + (   piSrcTmp[iSrcStep6]           << 2 )
+              - ( ( piSrcTmp[iSrcStep5] + iTmp1 ) << 3 )
+              + (   piSrcTmp[iSrcStep3]           << 4 );
+      
+        piDst   [x * iDstStep] = Clip( ((iSum +  32) >>  6) + piSrcTmp[iSrcStep4] );
+      }
+      piSrcTmpP += iSrcStep;
+      piSrcTmpN += iSrcStep;
+      iDepX += iDepStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+    piDep += iDepStride;
+  }
+  return;
+}
+#endif
+
 __inline Void TRenInterpFilter::xCTI_FilterQuarter0Hor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
 {
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenModel.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenModel.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenModel.cpp	(revision 166)
@@ -700,2 +700,3 @@
   }
 }
+
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenSingleModel.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenSingleModel.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenSingleModel.cpp	(revision 166)
@@ -1943,2 +1943,3 @@
 }
 #endif
+
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenTop.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenTop.cpp	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenTop.cpp	(revision 166)
@@ -127,4 +127,78 @@
 }
 
+#if NTT_SUBPEL
+Void TRenTop::xConvertInputVideoSubpel( PelImage* pcOrgInputImage, PelImage* pcConvInputImage, PelImage* pcInputDepth, Bool bMirror )
+{
+  PelImagePlane*  pcOrgPlane;
+  PelImagePlane*  pcConvPlane;
+  PelImagePlane*  pcDepthPlane;
+  PelImagePlane*  pcTmpPlane;
+
+  Int    ** ppiFposLUT = bMirror ? m_ppiFposLUTRightMirror : m_ppiFposLUTLeft;
+
+  AOT( m_iLog2SamplingFactor );
+  AOF( m_iInterpolationMode == eRenInt8Tap2 );
+
+  pcDepthPlane = pcInputDepth->getPlane( 0 );
+  pcTmpPlane = pcConvInputImage->getPlane( 0 );
+
+  AOF( m_bUVUp ); // Currently only m_bUVUp=true is supported
+  for (UInt uiPlane = 1; uiPlane < 3; uiPlane++)
+  {
+    pcOrgPlane  = pcOrgInputImage ->getPlane(uiPlane);
+    pcConvPlane = pcConvInputImage->getPlane(uiPlane);
+
+    if ( m_bUVUp )
+    {
+      TRenFilter::sampleCVerUp    (pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight()  , pcTmpPlane ->getPlaneData(), pcTmpPlane ->getStride() );
+      TRenFilter::sampleCConvHorUp(pcTmpPlane->getPlaneData(), pcTmpPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight()*2, pcConvPlane->getPlaneData(), pcConvPlane->getStride(), pcDepthPlane->getPlaneData(), pcDepthPlane->getStride(), ppiFposLUT );
+    }
+    else
+    {
+      TRenFilter::sampleCConv     (pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight()*2, pcConvPlane->getPlaneData(), pcConvPlane->getStride(), pcDepthPlane->getPlaneData(), pcDepthPlane->getStride(), ppiFposLUT );
+    }
+  }
+
+  pcOrgPlane  = pcOrgInputImage ->getPlane(0);
+  pcConvPlane = pcConvInputImage->getPlane(0);
+  TRenFilter::sampleConv(pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride(), pcDepthPlane->getPlaneData(), pcDepthPlane->getStride(), ppiFposLUT);
+}
+
+Void TRenTop::xConvertInputDepthSubpel( PelImage* pcOrgInputImage, PelImage* pcConvInputImage)
+{
+  PelImagePlane*  pcOrgPlane ;
+  PelImagePlane*  pcConvPlane;
+
+  // Full Plane
+  pcOrgPlane  = pcOrgInputImage ->getPlane(0);
+  pcConvPlane = pcConvInputImage->getPlane(0);
+
+  AOT( m_iLog2SamplingFactor );
+  AOF( m_iInterpolationMode == eRenInt8Tap2 );
+
+  TRenFilter::sampleHorUp(m_iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+
+  AOF( m_bUVUp );
+  if ( !m_bUVUp ) //GT: depth down
+  {
+    // Quarter Plane
+    PelImagePlane* pcTempPlane = new PelImagePlane(pcOrgInputImage->getPlane(0)->getWidth(), ( pcOrgInputImage->getPlane(0)->getHeight() >> 1), REN_LUMA_MARGIN );
+
+    TRenFilter::sampleVerDown2Tap13(pcOrgInputImage->getPlane(0), pcTempPlane, PICYUV_PAD);
+    pcConvPlane = pcConvInputImage->getPlane(1);
+
+    if ( m_iLog2SamplingFactor == 0 )
+    {
+      TRenFilter::sampleHorDown2Tap13(pcTempPlane, pcConvPlane, 0 );
+    }
+    else
+    {
+      TRenFilter::sampleHorUp    ( m_iLog2SamplingFactor - 1, pcTempPlane->getPlaneData(), pcTempPlane->getStride(), pcTempPlane->getWidth(), pcTempPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+    }
+    delete pcTempPlane;
+  }
+}
+#endif
+
 Void TRenTop::xConvertInputDepth( PelImage* pcOrgInputImage, PelImage* pcConvInputImage)
 {
@@ -193,4 +267,32 @@
 }
 
+#if NTT_SUBPEL
+Void TRenTop::xConvertInputDataSubpel( PelImage* pcOrgInputImage, PelImage* pcOrgInputDepth, PelImage* pcConvInputImage, PelImage* pcConvInputDepth, Bool bMirror )
+{
+  //ToDo: remove unnecessary copying
+  if ( bMirror )
+  {
+    m_pcTempImage->getPlane(0)->assign( pcOrgInputDepth->getPlane(0) );
+    TRenFilter::mirrorHor( m_pcTempImage->getPlane(0) );
+    m_pcTempImage->getPlane(0)->extendMargin();
+    xConvertInputDepthSubpel( m_pcTempImage, pcConvInputDepth );
+
+    m_pcTempImage->assign( pcOrgInputImage );
+    TRenFilter::mirrorHor( m_pcTempImage );
+    m_pcTempImage->extendMargin();
+    xConvertInputVideoSubpel( m_pcTempImage, pcConvInputImage, pcConvInputDepth, bMirror );
+  }
+  else
+  {
+    m_pcTempImage->getPlane(0)->assign( pcOrgInputDepth->getPlane(0) );
+    m_pcTempImage->getPlane(0)->extendMargin();
+    xConvertInputDepthSubpel( m_pcTempImage, pcConvInputDepth );
+
+    m_pcTempImage->assign( pcOrgInputImage );
+    m_pcTempImage->extendMargin();
+    xConvertInputVideoSubpel( m_pcTempImage, pcConvInputImage, pcConvInputDepth, bMirror );
+  }
+}
+#endif
 
 Void TRenTop::xConvertOutputData( PelImage* pcOrgOutputImage, PelImage* pcConvOutputImage, Bool bMirror )
@@ -229,4 +331,24 @@
 }
 
+#if VSP_N
+Void TRenTop::xConvertOutputDataPlane0( PelImage* pcOrgOutputImage, PelImage* pcConvOutputImage, Bool bMirror )
+{
+  Int iLog2SamplingFactor = m_iLog2SamplingFactor;
+
+  PelImagePlane* pcOrgPlane  = pcOrgOutputImage ->getPlane(0);
+  PelImagePlane* pcConvPlane = pcConvOutputImage->getPlane(0);
+
+  pcOrgPlane->extendMargin();
+
+  TRenFilter::sampleHorDown( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+
+  if ( bMirror )
+  {
+    TRenFilter::mirrorHor( pcConvOutputImage );
+  }
+
+}
+#endif
+
 Void TRenTop::setShiftLUTs( Double** ppdShiftLUTLeft, Int** ppiShiftLUTLeft, Int** ppiBaseShiftLUTLeft, Double** ppdShiftLUTRight, Int** ppiShiftLUTRight, Int** ppiBaseShiftLUTRight,  Int iRelDistToLeft )
 {
@@ -254,4 +376,23 @@
   }
 }
+
+#if NTT_SUBPEL
+Void TRenTop::setFposLUTs( Int** ppiFposLUTLeft, Int** ppiFposLUTRight )
+{
+  m_ppiFposLUTLeft  = ppiFposLUTLeft;
+  m_ppiFposLUTRight = ppiFposLUTRight;
+
+  if (  m_ppiFposLUTRight != NULL )
+  {
+    for( UInt uiPlane = 0; uiPlane < 2; uiPlane++)
+    {
+      for (UInt uiDepthValue = 0; uiDepthValue <= 256; uiDepthValue++)
+      {
+        m_ppiFposLUTRightMirror[uiPlane][uiDepthValue] = - m_ppiFposLUTRight[uiPlane][uiDepthValue];
+      }
+    }
+  }
+}
+#endif
 
 Void TRenTop::extrapolateView( TComPicYuv* pcPicYuvVideo, TComPicYuv* pcPicYuvDepth, TComPicYuv* pcPicYuvSynthOut, Bool bRenderFromLeft )
@@ -278,4 +419,40 @@
   xCutMargin        ( &cOutputImage );
 };
+
+#if VSP_N
+Void TRenTop::extrapolateAvailabilityView( TComPicYuv* pcPicYuvVideo, TComPicYuv* pcPicYuvDepth, TComPicYuv* pcPicYuvSynthOut, TComPicYuv* pcPicYuvAvailOut, Bool bRenderFromLeft )
+{
+  AOF( m_bExtrapolate );
+  AOF( bRenderFromLeft ? m_ppiShiftLUTLeft || m_ppdShiftLUTLeft : m_ppiShiftLUTRight || m_ppdShiftLUTRight );
+  AOF( m_auiInputResolution[0] == pcPicYuvVideo->getWidth ());
+  AOF( m_auiInputResolution[1] == pcPicYuvVideo->getHeight());
+
+  PelImage cInputImage ( pcPicYuvVideo    );
+  PelImage cInputDepth ( pcPicYuvDepth    , true);
+  PelImage cOutputImage( pcPicYuvSynthOut );
+  PelImage cFillImage  ( pcPicYuvAvailOut );
+
+  m_pcOutputImage->init();
+  m_pcFilled     ->assign(REN_IS_HOLE);
+
+  xPreProcessDepth ( &cInputDepth,  &cInputDepth);
+#if NTT_SUBPEL
+  if( m_iInterpolationMode == eRenInt8Tap2 )
+    xConvertInputDataSubpel(&cInputImage, &cInputDepth, m_pcInputImage, m_pcInputDepth, !bRenderFromLeft );
+  else
+    xConvertInputData( &cInputImage, &cInputDepth, m_pcInputImage, m_pcInputDepth, !bRenderFromLeft );
+#else
+  xConvertInputData( &cInputImage, &cInputDepth, m_pcInputImage, m_pcInputDepth, !bRenderFromLeft );
+#endif
+  xShiftPixels(m_pcInputImage, m_pcInputDepth, m_pcOutputImage, m_pcFilled, bRenderFromLeft);
+  xRemBoundaryNoise ( m_pcOutputImage, m_pcFilled, m_pcOutputImage, bRenderFromLeft); // Erode
+  xFillHoles        ( m_pcOutputImage, m_pcFilled, m_pcOutputImage, bRenderFromLeft);
+  xConvertOutputData( m_pcOutputImage, &cOutputImage, !bRenderFromLeft );
+  //if (!bRenderFromLeft)  TRenFilter::mirrorHor( &cFillImage );
+  xConvertOutputDataPlane0( m_pcFilled, &cFillImage, !bRenderFromLeft );
+  xPostProcessImage (&cOutputImage, &cOutputImage);
+  xCutMargin        ( &cOutputImage );
+};
+#endif
 
 Void TRenTop::getUsedSamplesMap( TComPicYuv* pcPicYuvDepth, TComPicYuv* pcUsedSampleMap, Bool bRenderFromLeft )
@@ -751,4 +928,7 @@
   {
   case eRenIntFullPel:
+#if NTT_SUBPEL
+  case eRenInt8Tap2:
+#endif
     xShiftPlanePixelsFullPel( apcInPlane, pcDepthPlane, apcOutPlane, pcPlaneFilled, uiNumberOfPlanes);
     break;
@@ -826,8 +1006,37 @@
           }
           pcFilledData[iShiftedPos] = REN_IS_FILLED;
+
+#if NTT_SUBPEL
+          if(m_bInstantHoleFilling && (iDiff > 0) )
+          {
+            Int iRefPos = (iPrevShiftedPos == -1) ? iShiftedPos : iPrevShiftedPos;
+            
+            for (Int iCurPos = iPrevShiftedPos+1; iCurPos < iShiftedPos; iCurPos++)
+            {
+              for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+              {
+                apcOutputData[uiCurPlane][iCurPos] =  apcOutputData[uiCurPlane][iRefPos];
+              }
+              pcFilledData[iCurPos] = REN_IS_FILLED;
+            }
+          }
+#endif
         }
         iPrevShiftedPos = iShiftedPos;
       }
     }
+#if NTT_SUBPEL
+    if( (iPrevShiftedPos+1) != iWidth )
+    {
+      for (Int iCurPos = iPrevShiftedPos+1; iCurPos < iWidth; iCurPos++)
+      {
+        for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+        {
+          apcOutputData[uiCurPlane][iCurPos] =  apcOutputData[uiCurPlane][iPrevShiftedPos];
+        }
+        pcFilledData[iCurPos] = REN_IS_FILLED;
+      }
+    }
+#endif
     for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
     {
@@ -1450,10 +1659,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 +1678,6 @@
       {
         apcOutputData[uiCurPlane][iXPos] = apcInputData[uiCurPlane][iSourcePos];
-          }
-        }
+      }
+    }
 
     // Go to next line
@@ -2032,4 +2241,12 @@
   m_ppiShiftLUTRightMirror[0] = new Int[257];
   m_ppiShiftLUTRightMirror[1] = new Int[257];
+
+#if NTT_SUBPEL
+  m_ppiFposLUTLeft   = 0;
+  m_ppiFposLUTRight  = 0;
+  m_ppiFposLUTRightMirror    = new Int*[2];
+  m_ppiFposLUTRightMirror[0] = new Int[257];
+  m_ppiFposLUTRightMirror[1] = new Int[257];
+#endif
 
   m_aiShiftLUTCur    = 0;
@@ -2116,5 +2333,9 @@
   m_iHoleFillingMode = iHoleFillingMode;
 
+#if NTT_SUBPEL
+  m_bInstantHoleFilling   = (m_iInterpolationMode == eRenInt8Tap || m_iInterpolationMode == eRenInt8Tap2 ) && (m_iHoleFillingMode != 0 );
+#else
   m_bInstantHoleFilling   = (m_iInterpolationMode == eRenInt8Tap ) && (m_iHoleFillingMode != 0 );
+#endif
 
   // PostProcessing
@@ -2154,5 +2375,5 @@
     {
       m_aaiSubPelShift[uiEntry] = new Int[ iNumEntries ];
-        }
+    }
 
     TRenFilter::setSubPelShiftLUT(m_iRelShiftLUTPrec, m_aaiSubPelShift, -1);
@@ -2184,4 +2405,13 @@
   };
 
+#if NTT_SUBPEL
+  if ( m_ppiFposLUTRightMirror != NULL )
+  {
+    delete[] m_ppiFposLUTRightMirror[0];
+    delete[] m_ppiFposLUTRightMirror[1];
+    delete[] m_ppiFposLUTRightMirror;
+  };
+#endif
+
   if (m_piInvZLUTLeft      != NULL ) delete[] m_piInvZLUTLeft   ;
   if (m_piInvZLUTLeft      != NULL ) delete[] m_piInvZLUTRight  ;
Index: branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenTop.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenTop.h	(revision 165)
+++ branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibRenderer/TRenTop.h	(revision 166)
@@ -50,5 +50,9 @@
   // Interpolation Modes
 
+#if NTT_SUBPEL
+  enum { eRenIntFullPel = 0, eRenIntLinInt = 1, eRenIntLinReal = 2, eRenIntFEM = 3, eRenInt8Tap = 4, eRenInt8Tap2 = 5 };
+#else
   enum { eRenIntFullPel = 0, eRenIntLinInt = 1, eRenIntLinReal = 2, eRenIntFEM = 3, eRenInt8Tap = 4 };
+#endif
 
   // HoleFilling
@@ -93,4 +97,8 @@
                            Int**    ppiBaseShiftLUTRight,
                            Int      iRelDistLeft );
+#if NTT_SUBPEL
+  Void setFposLUTs      ( Int**    ppiFposLUTLeft, Int**    ppiFposLUTRight );
+  Void setInterpolationMode ( Int iMode ) { m_iInterpolationMode = iMode; }
+#endif
 
   // View Synthesis
@@ -99,4 +107,12 @@
                            TComPicYuv* pcPicYuvSynthOut,
                            Bool bRenderFromLeft );
+
+#if VSP_N
+  Void extrapolateAvailabilityView   ( TComPicYuv* pcPicYuvVideo,
+                                       TComPicYuv* pcPicYuvDepth,
+                                       TComPicYuv* pcPicYuvSynthOut,
+                                       TComPicYuv* pcPicYuvAvailOut,
+                                       Bool bRenderFromLeft );
+#endif
 
   Void interpolateView   ( TComPicYuv* pcPicYuvVideoLeft,
@@ -166,4 +182,12 @@
   Void xConvertInputData         ( PelImage* pcOrgInputImage, PelImage* pcOrgInputDepth, PelImage* pcConvInputImage, PelImage* pcConvInputDepth, Bool bMirror);
   Void xConvertOutputData        ( PelImage* pOrgOutputImage, PelImage* pConvOutputImage, Bool bMirror);
+#if VSP_N
+  Void xConvertOutputDataPlane0  ( PelImage* pOrgOutputImage, PelImage* pConvOutputImage, Bool bMirror);
+#endif
+#if NTT_SUBPEL
+  Void xConvertInputDataSubpel   ( PelImage* pcOrgInputImage, PelImage* pcOrgInputDepth, PelImage* pcConvInputImage, PelImage* pcConvInputDepth, Bool bMirror);
+  Void xConvertInputVideoSubpel  ( PelImage* pcOrgInputImage, PelImage* pcConvInputImage, PelImage* pcInputDepth, Bool bMirror );
+  Void xConvertInputDepthSubpel  ( PelImage* pcOrgInputImage, PelImage* pcConvInputImage);
+#endif
 
   Void xGetDataPointers          ( PelImage*& rpcInputImage,  PelImage*& rpcOutputImage, PelImage*& rpcInputDepth, PelImage*& rpcOutputDepth, PelImage*& rpcFilled, Bool bRenderDepth );
@@ -229,4 +253,9 @@
   Int**    m_ppiShiftLUTRightMirror; // For rendering the mirrored view
   Int*     m_aiShiftLUTCur;
+#if NTT_SUBPEL
+  Int**    m_ppiFposLUTLeft;
+  Int**    m_ppiFposLUTRight;
+  Int**    m_ppiFposLUTRightMirror; // For rendering the mirrored view
+#endif
 
   // Look up tables Z
