Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 193)
@@ -103,5 +103,5 @@
   if (!m_pchBitstreamFile)
   {
-    fprintf(stderr, "No input file specifed, aborting\n");
+    fprintf(stderr, "No input file specified, aborting\n");
     return false;
   }
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 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 193)
@@ -262,15 +262,4 @@
     }
   }
-#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++)
@@ -341,11 +330,4 @@
 #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
@@ -406,11 +388,4 @@
 #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
@@ -501,29 +476,5 @@
   }
 #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 )
   {
@@ -587,11 +538,8 @@
 {
   //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 );
+  pcPicVSP->getSlice(0)->setViewId( iCodedViewIdx );
   Int iNeighborViewId = 0;
   Bool bRenderFromLeft;
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 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppDecoder/TAppDecTop.h	(revision 193)
@@ -68,7 +68,4 @@
 
   std::vector<TVideoIOYuv*>       m_tVideoIOYuvReconFile;         ///< reconstruction YUV class
-#if DEBUGIMGOUT
-  std::vector<TVideoIOYuv*>       m_tVideoIOYuvReconDbgFile;      ///< debug YUV class
-#endif
 
   // for output control
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 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 193)
@@ -120,4 +120,25 @@
 #endif
 
+#if FIX_MEM_LEAKS
+ if ( m_pchCameraParameterFile != NULL )
+   free ( m_pchCameraParameterFile ); 
+
+ if ( m_pchBaseViewCameraNumbers != NULL )
+   free ( m_pchBaseViewCameraNumbers ); 
+
+ if ( m_pchdQPFile      != NULL ) 
+   free ( m_pchdQPFile      );
+
+ if ( m_pchColumnWidth  != NULL ) 
+   free ( m_pchColumnWidth  );
+
+ if ( m_pchRowHeight    != NULL ) 
+   free ( m_pchRowHeight    );
+
+ if ( m_scalingListFile != NULL ) 
+   free ( m_scalingListFile );
+
+#endif   
+
 }
 
@@ -168,4 +189,20 @@
     in>>entry.m_interViewRefPosL1[i];
   }
+#if VSP_CFG
+  in>>entry.m_numVSPRefPics;
+  for( Int i = 0; i < entry.m_numVSPRefPics; i++ )
+  {
+    in>>entry.m_VSPRefPics[i];
+  }
+  for( Int i = 0; i < entry.m_numVSPRefPics; i++ )
+  {
+    in>>entry.m_VSPRefPosL0[i];
+  }
+  for( Int i = 0; i < entry.m_numVSPRefPics; i++ )
+  {
+    in>>entry.m_VSPRefPosL1[i];
+  }
+#endif
+
   return in;
 }
@@ -339,5 +376,19 @@
   ("AllowNegDist",                    m_bAllowNegDist           , true          , "Allow negative Distortion in VSO")
 #endif
-
+#if LGE_WVSO_A0119
+  ("WVSO",                            m_bUseWVSO                , false         , "Use depth fidelity term for VSO" )
+  ("VSOWeight",                       m_iVSOWeight              , 10            , "Synthesized View Distortion Change weight" )
+  ("VSDWeight",                       m_iVSDWeight              , 1             , "View Synthesis Distortion estimate weight" )
+  ("DWeight",                         m_iDWeight                , 1             , "Depth Distortion weight" )
+#endif
+
+#if OL_DEPTHLIMIT_A0044
+  ("DPL",                             m_bDepthPartitionLimiting , false         , "Use DepthPartitionLimiting" )
+#endif
+#endif
+
+#if VSP_N
+  ("VSP",                             m_bUseVSP                 , false         , "Use VSP" )    
+  ("VSPDepthDisable",                 m_bVSPDepthDisable        , false         , "Use VSP Depth Disable" )    
 #endif
 
@@ -498,5 +549,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 )
   {
@@ -648,4 +699,7 @@
 #endif
 
+#if LGE_WVSO_A0119
+  m_bUseWVSO = m_bUseVSO && m_bUseWVSO && m_bUsingDepthMaps;
+#endif
   xCleanUpVectors();
 
@@ -1107,4 +1161,49 @@
   }
   xConfirmPara( bErrorIvpEnhV, "Invalid inter-view coding structure for enhancement views given" );
+
+#if VSP_CFG
+  // validate vsp refs
+  Bool bErrorVspEnhV = false;
+  if( m_iNumberOfViews > 1 )
+  {
+    for( Int k = 1; k < m_iNumberOfViews; k++ )
+    {
+      for( Int i = 0; i < MAX_GOP+1; i++ )
+      {
+        if( m_GOPListsMvc[k][i].m_numVSPRefPics < 0 || m_GOPListsMvc[k][i].m_numVSPRefPics > 1 )
+        {
+          printf( "\nError: m_numVSPRefPics < 0 or m_numVSPRefPics > 1 \n" );
+          bErrorVspEnhV = true;
+        }
+
+        for( Int j = 0; j < m_GOPListsMvc[k][i].m_numVSPRefPics; j++ )
+        {
+          Int iAbsViewId = m_GOPListsMvc[k][i].m_VSPRefPics[j] + k;
+          if( iAbsViewId != 0 )
+          {
+            printf( "\nError: VSP is allowed to reference only base view\n" );
+            bErrorVspEnhV = true;
+          }
+          if( m_GOPListsMvc[k][i].m_sliceType == 'P' && m_GOPListsMvc[k][i].m_VSPRefPosL1[j] != 0 )
+          {
+            printf( "\nError: m_sliceType == P and m_VSPRefPosL1 != 0\n" );
+            bErrorVspEnhV = true;
+          }
+        }
+
+        for( Int j = 0; j < m_GOPListsMvc[k][i].m_numVSPRefPics || j < m_GOPListsMvc[k][i].m_numInterViewRefPics; j++ )
+        {
+          if( (m_GOPListsMvc[k][i].m_VSPRefPosL0[j] != 0 && m_GOPListsMvc[k][i].m_VSPRefPosL0[j] == m_GOPListsMvc[k][i].m_interViewRefPosL0[j]) 
+           || (m_GOPListsMvc[k][i].m_VSPRefPosL1[j] != 0 && m_GOPListsMvc[k][i].m_VSPRefPosL1[j] == m_GOPListsMvc[k][i].m_interViewRefPosL1[j]) )
+          {
+            printf( "\nError: vsp_ref_list_pos[%d] == IV ref list pos[%d]\n", j, j );
+            bErrorVspEnhV = true;
+          }
+        }
+      }
+    }
+  }
+  xConfirmPara( bErrorVspEnhV, "Invalid VSP coding structure for enhancement views given" );
+#endif
 
   // validate temporal coding structure
@@ -1692,5 +1791,11 @@
 #if HHI_VSO
   printf("VSO:%d ", m_bUseVSO             );
-#endif  
+#endif
+#if LGE_WVSO_A0119
+  printf("WVSO:%d ", m_bUseWVSO );
+#endif
+#if OL_DEPTHLIMIT_A0044
+  printf("DPL:%d ", m_bDepthPartitionLimiting);
+#endif
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   printf("DMM:%d ", m_bUseDMM );
@@ -1698,4 +1803,7 @@
 #if HHI_MPI
   printf("MVI:%d ", m_bUseMVI ? 1 : 0 );
+#endif
+#if LGE_WVSO_A0119
+  printf("\nVSO : VSD : SAD weight = %d : %d : %d ", m_iVSOWeight, m_iVSDWeight, m_iDWeight );
 #endif
   printf("\n\n");
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.h	(revision 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncCfg.h	(revision 193)
@@ -297,8 +297,22 @@
   Bool      m_bUseEstimatedVSD;                           ///< Flag for using model based VSD estimation instead of VSO for some encoder decisions (JCT3V-A0033 modification 3)  
 #endif
+#if LGE_WVSO_A0119
+  Bool      m_bUseWVSO;                                    ///< flag for using View Synthesis Optimization  
+  Int       m_iVSOWeight;
+  Int       m_iVSDWeight;
+  Int       m_iDWeight;
+#endif
+#if VSP_N
+  Bool      m_bUseVSP;
+  Bool      m_bVSPDepthDisable;
+#endif
 
   // coding tools (depth intra modes)
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
   Bool      m_bUseDMM;                                        ///< flag for using DMM
+#endif
+
+#if OL_DEPTHLIMIT_A0044
+  Bool      m_bDepthPartitionLimiting;
 #endif
 
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 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 193)
@@ -207,4 +207,7 @@
     m_acTEncTopList[iViewIdx]->setUseEstimatedVSD              ( false );
 #endif
+#if LGE_WVSO_A0119
+    m_acTEncTopList[iViewIdx]->setUseWVSO                      ( false ); 
+#endif
 #endif
 
@@ -361,6 +364,14 @@
     m_acTEncTopList[iViewIdx]->setUseDMM                     ( false );
 #endif
+#if OL_DEPTHLIMIT_A0044
+    m_acTEncTopList[iViewIdx]->setUseDPL                     ( false );
+#endif
 #if HHI_MPI
     m_acTEncTopList[iViewIdx]->setUseMVI( false );
+#endif
+
+#if VSP_N
+    m_acTEncTopList[iViewIdx]->setUseVSP( m_bUseVSP );
+    m_acTEncTopList[iViewIdx]->setVSPDepthDisable( m_bVSPDepthDisable );
 #endif
   }
@@ -524,4 +535,7 @@
       m_acTEncDepthTopList[iViewIdx]->setUseEstimatedVSD              ( m_bUseEstimatedVSD );
 #endif
+#if LGE_WVSO_A0119
+      m_acTEncDepthTopList[iViewIdx]->setUseWVSO                      ( m_bUseWVSO         );
+#endif
 #endif
 
@@ -634,6 +648,14 @@
     m_acTEncDepthTopList[iViewIdx]->setUseDMM                     ( m_bUseDMM );
 #endif
+#if OL_DEPTHLIMIT_A0044
+    m_acTEncDepthTopList[iViewIdx]->setUseDPL                      (m_bDepthPartitionLimiting);
+#endif
 #if HHI_MPI
      m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
+#endif
+
+#if VSP_N
+      m_acTEncDepthTopList[iViewIdx]->setUseVSP( m_bUseVSP );
+      m_acTEncDepthTopList[iViewIdx]->setVSPDepthDisable( m_bVSPDepthDisable );
 #endif
     }
@@ -690,4 +712,17 @@
       AOT(true);
     }
+#if LGE_WVSO_A0119 
+    for ( Int iViewNum = 0; iViewNum < m_iNumberOfViews; iViewNum++ )
+    {
+      for (Int iContent = 0; iContent < 2; iContent++ )
+      {
+        TEncTop* pcEncTop = ( iContent == 0 ) ? m_acTEncTopList[iViewNum] : m_acTEncDepthTopList[iViewNum]; 
+        pcEncTop->setUseWVSO  ( m_bUseWVSO );
+        pcEncTop->setVSOWeight( m_iVSOWeight );
+        pcEncTop->setVSDWeight( m_iVSDWeight );
+        pcEncTop->setDWeight  ( m_iDWeight );
+      }
+    }
+#endif
   }
 #endif
@@ -938,7 +973,7 @@
         iNumEncoded = 0;
 
-#if VSP_SLICE_HEADER
-        m_acTEncTopList     [iViewIdx]->setUseVSP( (gopId%VSP_FRAME_INTERVAL==0) );
-        m_acTEncDepthTopList[iViewIdx]->setUseVSP( (gopId%VSP_FRAME_INTERVAL==0) );
+#if VSP_SLICE_HEADER && !VSP_CFG
+        if( m_acTEncTopList     [iViewIdx]->getUseVSP() ) m_acTEncTopList     [iViewIdx]->setUseVSP( (gopId%VSP_FRAME_INTERVAL==0) );
+        if( m_acTEncDepthTopList[iViewIdx]->getUseVSP() ) m_acTEncDepthTopList[iViewIdx]->setUseVSP( (gopId%VSP_FRAME_INTERVAL==0) );
 #endif
 
@@ -963,4 +998,5 @@
 #if VSP_SLICE_HEADER
           if( m_acTEncDepthTopList[iViewIdx]->getUseVSP() )
+          if( !m_acTEncDepthTopList[iViewIdx]->getVSPDepthDisable() )
 #endif
             xStoreVSPInBuffer(m_acTEncDepthTopList[iViewIdx]->getVSPBuf(), m_acTEncDepthTopList[iViewIdx]->getVSPAvailBuf(), iViewIdx, true, gopId);
@@ -1003,4 +1039,14 @@
   delete pcDepthPicYuvOrg;
   pcDepthPicYuvOrg = NULL;
+  
+#if FIX_MEM_LEAKS
+  if ( pcPdmDepthOrg != NULL )
+  {
+    pcPdmDepthOrg->destroy();
+    delete pcPdmDepthOrg;     
+    pcPdmDepthOrg = NULL; 
+  };
+#endif
+
   
   for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
@@ -1263,5 +1309,9 @@
 Void TAppEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset )
 {
+#if FIX_VSO_SETUP
+  m_cRendererModel.setupPart( iHorOffset, Min( g_uiMaxCUHeight, m_iSourceHeight - iHorOffset ) ); 
+#else
   m_cRendererModel.setHorOffset( iHorOffset ); 
+#endif
 #else
 Void TAppEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent )
@@ -1410,9 +1460,5 @@
 {
   //first view does not have VSP 
-#if VSP_TEXT_ONLY
-  if((iCodedViewIdx == 0)||(bDepth))
-#else
   if((iCodedViewIdx == 0))
-#endif
     return;
 
@@ -1439,6 +1485,7 @@
   }
   pcPicVSP->getSlice(0)->setPOC( iCurPoc );
-
-  Int iNeighborViewId = 0;
+  pcPicVSP->getSlice(0)->setViewId( iCodedViewIdx );
+
+  Int iNeighborViewId = 0;  //iCodedViewIdx + m_GOPListsMvc[iCodedViewIdx][gopId].m_VSPRefPics[0];
   Bool bRenderFromLeft;
   //check if the neighboring view is situated to the left of the current view
Index: branches/HTM-4.0.1-VSP-dev0/source/App/TAppRenderer/TAppRendererTop.cpp
===================================================================
--- branches/HTM-4.0.1-VSP-dev0/source/App/TAppRenderer/TAppRendererTop.cpp	(revision 166)
+++ branches/HTM-4.0.1-VSP-dev0/source/App/TAppRenderer/TAppRendererTop.cpp	(revision 193)
@@ -533,5 +533,9 @@
 
 #if HHI_VSO_SPEEDUP_A0033
+#if FIX_VSO_SETUP
+    cCurModel.setupPart( 0, m_iSourceHeight  ); 
+#else
     cCurModel.setHorOffset( 0 );
+#endif
 #endif
 
@@ -710,5 +714,9 @@
   AOT( m_iLog2SamplingFactor != 0 );
 #if HHI_VSO_SPEEDUP_A0033
+#if FIX_VSO_SETUP
+  cCurModel.setupPart( 0, m_iSourceHeight  ); 
+#else
   cCurModel.setHorOffset( 0 );
+#endif
 #endif
 #if LGE_VSO_EARLY_SKIP_A0093
