Index: trunk/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/NALwrite.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/NALwrite.cpp	(revision 77)
@@ -64,4 +64,8 @@
 #endif
 
+#if VIDYO_VPS_INTEGRATION
+  bsNALUHeader.write(nalu.m_temporalId, 3); // temporal_id
+  bsNALUHeader.write(nalu.m_layerId + 1, 5); // layer_id_plus1
+#else
 #if H0388
   bsNALUHeader.write(nalu.m_temporalId, 3); // temporal_id
@@ -90,4 +94,6 @@
   }
 #endif
+#endif
+  
   out.write(bsNALUHeader.getByteStream(), bsNALUHeader.getByteStreamLength());
 
@@ -201,10 +207,17 @@
   naluDest.m_nalRefIDC   = naluSrc.m_nalRefIDC;
 #endif
+#if !VIDYO_VPS_INTEGRATION
   naluDest.m_viewId      = naluSrc.m_viewId;
   naluDest.m_isDepth     = naluSrc.m_isDepth;
+#endif
   naluDest.m_temporalId  = naluSrc.m_temporalId;
+#if VIDYO_VPS_INTEGRATION
+  naluDest.m_layerId = naluSrc.m_layerId;
+#else
+  
 #if !H0388
   naluDest.m_OutputFlag  = naluSrc.m_OutputFlag;
 #endif
+#endif
   naluDest.m_Bitstream   = naluSrc.m_Bitstream;
 }
Index: trunk/source/Lib/TLibEncoder/NALwrite.h
===================================================================
--- trunk/source/Lib/TLibEncoder/NALwrite.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/NALwrite.h	(revision 77)
@@ -62,11 +62,23 @@
     NalRefIdc nalRefIDC,
 #endif
+#if VIDYO_VPS_INTEGRATION
+    unsigned layerId,
+#else
     Int viewId,
     Bool isDepth,
+#endif
     unsigned temporalID = 0)
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+  : NALUnit(nalUnitType, nalRefFlag, layerId, temporalID)
+#else
   : NALUnit(nalUnitType, nalRefFlag, viewId, isDepth, temporalID)
+#endif
+#else
+#if VIDYO_VPS_INTEGRATION
+  : NALUnit(nalUnitType, nalRefIDC, layerId, temporalID)
 #else
   : NALUnit(nalUnitType, nalRefIDC, viewId, isDepth, temporalID)
+#endif
 #endif
   , m_Bitstream()
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 77)
@@ -375,4 +375,49 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void TEncCavlc::codeVPS( TComVPS* pcVPS )
+{
+	WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
+  WRITE_CODE( pcVPS->getMaxLayers() - 1,      5,        "max_layers_minus1" );
+  WRITE_FLAG( pcVPS->getTemporalNestingFlag() - 1,      "temporal_id_nesting_flag" );
+  WRITE_UVLC( pcVPS->getVPSId(),                        "video_parameter_set_id" );
+  for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
+  {
+    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
+    WRITE_UVLC( pcVPS->getNumReorderPics(i),               "num_reorder_pics[i]" );
+    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
+  }
+  
+  WRITE_CODE( 1,      1,        "bit_equal_to_one" );
+  
+  if( pcVPS->getMaxLayers() - 1 > 0 )
+  {
+    WRITE_UVLC( pcVPS->getExtensionType(),                        "extension_type" );
+    
+    for(UInt i=1; i <= pcVPS->getMaxLayers()-1; i++)
+    {
+      WRITE_FLAG( pcVPS->getDependentFlag(i),                     "dependent_flag[i]" );
+      if( pcVPS->getDependentFlag(i) )
+      {
+        WRITE_UVLC( i - pcVPS->getDependentLayer(i) - 1,          "delta_reference_layer_id_minus1[i]" );
+        if( pcVPS->getExtensionType() == VPS_EXTENSION_TYPE_MULTI_VIEW )
+        {
+          WRITE_UVLC( pcVPS->getViewId(i),                        "view_id[i]" );
+          WRITE_FLAG( pcVPS->getDepthFlag(i),                     "depth_flag[i]" );
+          WRITE_SVLC( pcVPS->getViewOrderIdx(i),                  "view_order_idx[i]" );
+        }
+        
+      }
+    }
+  }
+  
+  WRITE_FLAG( 0,                     "vps_extension_flag" );
+  
+  //future extensions here..
+  
+  return;
+}
+#endif
+
 #if HHI_MPI
 Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
@@ -388,4 +433,7 @@
   WRITE_CODE( pcSPS->getLevelIdc (),       8,       "level_idc" );
   WRITE_UVLC( pcSPS->getSPSId (),                   "seq_parameter_set_id" );
+#if VIDYO_VPS_INTEGRATION
+  WRITE_UVLC( pcSPS->getVPSId (),                   "video_parameter_set_id" );
+#endif
   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
   WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "max_temporal_layers_minus1" );
@@ -727,6 +775,6 @@
     {
       WRITE_CODE( (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC()), pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
-
-      if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
+#if HHI_FIX
+      if( pcSlice->getPOC() == 0 && pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
       {
         TComReferencePictureSet* rps = pcSlice->getRPS();
@@ -799,4 +847,78 @@
         }
       }
+      if( pcSlice->getPOC() != 0 )
+#else
+      if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
+#endif
+      {
+        TComReferencePictureSet* rps = pcSlice->getRPS();
+        if(pcSlice->getRPSidx() < 0)
+        {
+          WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
+#if RPS_IN_SPS
+          codeShortTermRefPicSet(pcSlice->getSPS(), rps);
+#else
+          codeShortTermRefPicSet(pcSlice->getPPS(), rps);
+#endif
+        }
+        else
+        {
+          WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag");
+          WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
+        }
+#if RPS_IN_SPS
+        if(pcSlice->getSPS()->getLongTermRefsPresent())
+#else
+        if(pcSlice->getPPS()->getLongTermRefsPresent())
+#endif
+        {
+          WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
+          Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC();
+          Int prev = 0;
+#if LTRP_MULT
+          Int prevDeltaPocLt=0;
+          Int currDeltaPocLt=0;
+#endif
+          for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--)
+          {
+            WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt");
+          
+#if LTRP_MULT
+            currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt;
+
+            Int deltaMsbCycle=0;
+            if( (i==(rps->getNumberOfPictures()-1)) )
+            {
+              deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
+            }
+            else if( prevDeltaPocLt!=currDeltaPocLt )
+            {
+              deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
+              if( ((prevDeltaPocLt==maxPocLsb-1) && (currDeltaPocLt==maxPocLsb+1)) ||  ((prevDeltaPocLt==maxPocLsb-2) && (currDeltaPocLt==maxPocLsb)))
+              {
+                deltaMsbCycle=deltaMsbCycle-1;
+              }
+            }
+            else
+            {
+              deltaMsbCycle=((rps->getDeltaPOC(i+1)-rps->getDeltaPOC(i))/maxPocLsb)-1;
+            }
+
+            if(deltaMsbCycle>=0)
+            {
+              WRITE_FLAG( 1, "delta_poc_msb_present_flag");
+              WRITE_UVLC(deltaMsbCycle, "delta_poc_msb_cycle_lt_minus1");
+            }
+            else
+            {
+              WRITE_FLAG( 0, "delta_poc_msb_present_flag");
+            }
+            prevDeltaPocLt=currDeltaPocLt;
+#endif
+            prev = rps->getDeltaPOC(i);
+            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); 
+          }
+        }
+      }
     }
 
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 77)
@@ -114,4 +114,8 @@
   UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
   
+#if VIDYO_VPS_INTEGRATION
+  Void  codeVPS                 ( TComVPS* pcVPS );
+#endif
+
 #if HHI_MPI
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 77)
@@ -290,4 +290,8 @@
 #endif
 
+#if VIDYO_VPS_INTEGRATION
+  UInt     m_layerId;
+#endif
+  
   Int      m_viewId;
   Bool     m_isDepth;
@@ -765,4 +769,8 @@
   Int       getTSIG()                            { return m_signHidingThreshold; }
 #endif
+#if VIDYO_VPS_INTEGRATION
+  Void      setLayerId             ( UInt layerId )   { m_layerId = layerId; }
+  UInt      getLayerId             ()               { return m_layerId; }
+#endif
 
   Void      setViewId             ( Int viewId )   { m_viewId = viewId; }
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 77)
@@ -604,5 +604,9 @@
         if( bResPredAllowed )
         {
-          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, m_ppcResPredTmp[uiDepth] );
+          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, 
+#if QC_SIMPLIFIEDIVRP_M24938
+            true ,
+#endif
+            m_ppcResPredTmp[uiDepth] );
         }
 
@@ -698,5 +702,9 @@
         if( bResPredAllowed )
         {
-          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, m_ppcResPredTmp[uiDepth] );
+          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, 
+#if QC_SIMPLIFIEDIVRP_M24938
+            true,
+#endif
+            m_ppcResPredTmp[uiDepth] );
         }
 
@@ -1903,4 +1911,5 @@
   
 #if HHI_INTER_VIEW_RESIDUAL_PRED
+#if !LG_RESTRICTEDRESPRED_M24766
   if( rpcTempCU->getResPredFlag( 0 ) )
   { // subtract residual prediction from original in motion search
@@ -1908,9 +1917,14 @@
   }
 #endif
+#endif
 
 #if AMP_MRG
   rpcTempCU->setMergeAMP (true);
   #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  );
+#else
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG  );
+#endif
 #else
   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG );
@@ -1925,8 +1939,10 @@
 
 #if HHI_INTER_VIEW_RESIDUAL_PRED
+#if !LG_RESTRICTEDRESPRED_M24766
   if( rpcTempCU->getResPredFlag( 0 ) )
   { // add residual prediction to original again
     m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) );
   }
+#endif
 #endif
 
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 77)
@@ -121,4 +121,16 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
+{
+  m_pcEntropyCoderIf->codeVPS( pcVPS );
+  return;
+}
+#endif
+
+#if VIDYO_VPS_INTEGRATION
+Void  codeVPS                 ( TComVPS* pcVPS );
+#endif
+
 #if HHI_MPI
 Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Bool bIsDepth )
@@ -471,5 +483,9 @@
   ROTVS( pcCU->isIntra           ( uiAbsPartIdx )              );
   ROFVS( pcCU->getResPredAvail   ( uiAbsPartIdx )              );
-
+#if LG_RESTRICTEDRESPRED_M24766
+  Int iPUResiPredShift[4];
+  pcCU->getPUResiPredShift(iPUResiPredShift, uiAbsPartIdx);
+  if(iPUResiPredShift[0] >= 0 || iPUResiPredShift[1] >= 0  || iPUResiPredShift[2] >= 0  || iPUResiPredShift[3] >= 0 )
+#endif
   // encode flag
   m_pcEntropyCoderIf->codeResPredFlag( pcCU, uiAbsPartIdx );
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 77)
@@ -76,4 +76,8 @@
   virtual UInt  getCoeffCost          ()                = 0;
 
+#if VIDYO_VPS_INTEGRATION
+	virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
+#endif
+	
 #if HHI_MPI
   virtual Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
@@ -229,4 +233,7 @@
   
 public:
+#if VIDYO_VPS_INTEGRATION
+	Void encodeVPS               ( TComVPS* pcVPS);
+#endif
   // SPS
 #if HHI_MPI
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 77)
@@ -246,5 +246,9 @@
 
       std::vector<TComAPS>& vAPS = m_pcEncTop->getAPS();
+#if VIDYO_VPS_INTEGRATION
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#else
       m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
       pcSlice->setLastIDR(m_iLastIDR);
       pcSlice->setSliceIdx(0);
@@ -809,6 +813,19 @@
       if ( m_bSeqFirst )
       {
+#if VIDYO_VPS_INTEGRATION
+        {
+          OutputNALUnit nalu(NAL_UNIT_VPS, true, m_pcEncTop->getLayerId());
+          m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+          m_pcEntropyCoder->encodeVPS(m_pcEncTop->getEncTop()->getVPS());
+          writeRBSPTrailingBits(nalu.m_Bitstream);
+          accessUnit.push_back(new NALUnitEBSP(nalu));
+        }
+#endif
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+        OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getLayerId());
+#else
         OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
         OutputNALUnit nalu(NAL_UNIT_SPS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -827,5 +844,9 @@
 
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION 
+        nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getLayerId());
+#else
         nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
         nalu = NALUnit(NAL_UNIT_PPS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -954,11 +975,28 @@
 #if H0388
 #if NAL_REF_FLAG
-        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced(), m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
-#else
-        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
-#endif
-#else
-        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer(), true);
-#endif
+        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced(),
+#if !VIDYO_VPS_INTEGRATION
+                           m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
+#else
+                           m_pcEncTop->getLayerId(), pcSlice->getTLayer() );
+#endif
+#else
+        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, 
+#if !VIDYO_VPS_INTEGRATION
+                           m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
+#else
+                           m_pcEncTop->getLayerId(), pcSlice->getTLayer() );
+#endif
+#endif
+#else
+        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, 
+#if !VIDYO_VPS_INTEGRATION
+                           m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer(), true );
+#else
+                           m_pcEncTop->getLayerId(), pcSlice->getTLayer(), true );
+#endif
+
+#endif
+            
         Bool bEntropySlice = (!pcSlice->isNextSlice());
         if (!bEntropySlice)
@@ -1414,5 +1452,9 @@
           {
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+            OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getLayerId());
+#else
             OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
             OutputNALUnit nalu(NAL_UNIT_APS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -1476,5 +1518,9 @@
 
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+        OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getLayerId());
+#else
         OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
         OutputNALUnit nalu(NAL_UNIT_SEI, NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -1962,4 +2008,5 @@
   
 #if HHI_VSO
+#if HHI_VSO_SYNTH_DIST_OUT
   if ( m_pcRdCost->getUseRenModel() )
   {
@@ -1975,4 +2022,5 @@
   }
   else
+#endif
 #endif
   {
Index: trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 77)
@@ -342,4 +342,12 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void TEncSbac::codeVPS( TComVPS* pcVPS )
+{
+	assert (0);
+  return;
+}
+#endif
+
 #if HHI_MPI
 Void TEncSbac::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
Index: trunk/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 77)
@@ -98,4 +98,8 @@
   //--SBAC RD
 
+#if VIDYO_VPS_INTEGRATION
+  Void  codeVPS                 ( TComVPS* pcVPS );
+#endif
+	
 #if HHI_MPI
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 77)
@@ -2505,5 +2505,9 @@
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost, TComMvField* cMvFieldNeighbours, UChar* uhInterDirNeighbours, Int& numValidMergeCand )
 #else
+#if LG_RESTRICTEDRESPRED_M24766
+Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* rpcResiPredYuv, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
+#else
 Void TEncSearch::xMergeEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPUIdx, UInt& uiInterDir, TComMvField* pacMvField, UInt& uiMergeIndex, UInt& ruiCost )
+#endif
 #endif
 {
@@ -2553,5 +2557,8 @@
   const int maxNumMergeCand = MRG_MAX_NUM_CANDS_SIGNALED + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
 #endif
-
+#if LG_RESTRICTEDRESPRED_M24766
+  Int iPUResiPredShift[4];
+  Int iLastAddResiShift = -1000;
+#endif
   ruiCost = MAX_UINT;
   for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
@@ -2565,5 +2572,33 @@
       pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
       pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
-
+#if LG_RESTRICTEDRESPRED_M24766
+	  Int iAddResiShift;
+	  UInt uiPartAddr;
+	  Int iRoiWidth, iRoiHeight;
+
+	  pcCU->getPartIndexAndSize( iPUIdx, uiPartAddr, iRoiWidth, iRoiHeight );
+	  iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
+	  iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1 - iAddResiShift : -1);
+
+	  if( pcCU->getResPredFlag( 0 ))
+	  { // subtract residual prediction from original in motion search
+		  if(iLastAddResiShift != iAddResiShift)
+		  {
+			  //add subtracted residual last time
+			  if(iLastAddResiShift >= 0)
+			  {
+				  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+				  pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+			  }
+			  //subtract residual
+			  if(iAddResiShift >= 0)
+			  {
+				  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
+				  pcYuvOrg->add(iPUResiPredShift, ePartSize, rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
+			  }
+			  iLastAddResiShift = iAddResiShift;
+		  }
+	  }
+#endif
       xGetInterPredictionError( pcCU, pcYuvOrg, iPUIdx, uiCostCand, m_pcEncCfg->getUseHADME() );
       uiBitsCand = uiMergeCand + 1;
@@ -2587,4 +2622,11 @@
     }
   }
+#if LG_RESTRICTEDRESPRED_M24766
+  if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
+  {
+	  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+	  pcYuvOrg->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+  }
+#endif
 }
 
@@ -2599,5 +2641,9 @@
  */
 #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 )
+#endif
 #else
 Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bUseRes )
@@ -2702,5 +2748,7 @@
     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};
+#endif
     xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     
@@ -2718,5 +2766,7 @@
     {
 #endif
-
+#if LG_RESTRICTEDRESPRED_M24766
+		Bool bLastResiFlag = false;
+#endif
     //  Uni-directional prediction
     for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
@@ -2726,4 +2776,21 @@
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
+#if LG_RESTRICTEDRESPRED_M24766
+		  if( pcCU->getResPredFlag( 0 ))
+		  {
+			  if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
+			  { // subtract residual prediction from original in motion search
+				  if(!bLastResiFlag)
+					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
+				  bLastResiFlag = true;
+			  }
+			  else
+			  {
+				  if(bLastResiFlag)
+					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+				  bLastResiFlag = false;
+			  }
+		  }
+#endif
         uiBitsTemp = uiMbBits[iRefList];
         if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
@@ -2889,8 +2956,16 @@
       }
     }
+#if LG_RESTRICTEDRESPRED_M24766
+	if( pcCU->getResPredFlag( 0 ) && bLastResiFlag)
+	{ // subtract residual prediction from original in motion search
+		pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+	}
+#endif
     //  Bi-directional prediction
     if ( pcCU->getSlice()->isInterB() )
     {
-      
+#if LG_RESTRICTEDRESPRED_M24766
+		Int iLastAddResiShift = -1000;
+#endif
       cMvBi[0] = cMv[0];            cMvBi[1] = cMv[1];
       iRefIdxBi[0] = iRefIdx[0];    iRefIdxBi[1] = iRefIdx[1];
@@ -2994,4 +3069,35 @@
 #else
           uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdxBi[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
+#endif
+#if LG_RESTRICTEDRESPRED_M24766
+		  Int iAddResiShift = -1, iPredFrom = 0;
+		  Int iBestRefIdx = pcCU->getCUMvField(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
+
+		  iPredFrom = iBestRefIdx >= 0 ? 3 : 1;
+		  if(iBestRefIdx >= 0 && pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0, iBestRefIdx))
+			  iAddResiShift++;
+		  if(pcCU->getSlice()->getViewId() == pcCU->getSlice()->getRefViewId(eRefPicList, iRefIdxTemp))
+			  iAddResiShift++;
+		  iAddResiShift = (pcCU->getSlice()->getPPS()->getUseWP() || iPredFrom != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+
+		  if( pcCU->getResPredFlag( 0 ) )
+		  {
+			  if(iLastAddResiShift != iAddResiShift)
+			  {
+				  //add substracted residual last time
+				  if(iLastAddResiShift >= 0 )
+				  {
+					  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+				  }
+				  //substract residual
+				  if(iAddResiShift >= 0)
+				  {
+					  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iAddResiShift;
+					  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true );
+				  }
+				  iLastAddResiShift = iAddResiShift;
+			  }
+		  }
 #endif
           // call ME
@@ -3049,4 +3155,11 @@
         }
       } // for loop-iter
+#if LG_RESTRICTEDRESPRED_M24766
+	  if( pcCU->getResPredFlag( 0 ) && iLastAddResiShift >= 0)
+	  {
+		  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = iLastAddResiShift;
+		  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+	  }
+#endif
     } // if (B_SLICE)
 #if ZERO_MVD_EST
@@ -3255,6 +3368,21 @@
       if (bTestNormalMC)
       {
+#if LG_RESTRICTEDRESPRED_M24766
+		  Int iAddResiShift = pcCU->getResiPredMode(uiPartAddr);
+		  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = \
+			  (pcCU->getSlice()->getPPS()->getUseWP() || pcCU->getInterDir(uiPartAddr) != 3)? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+		  if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
+		  {
+			  pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ), true);
+		  }
+#endif
         xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() );
         uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits );
+#if LG_RESTRICTEDRESPRED_M24766
+		if(pcCU->getResPredFlag(0) && iAddResiShift >= 0)
+		{
+			pcOrgYuv->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcResiPredYuv, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ));
+		}
+#endif
       }
 #else
@@ -3274,5 +3402,9 @@
       xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
 #else
+#if LG_RESTRICTEDRESPRED_M24766
+      xMergeEstimation( pcCU, pcOrgYuv, rpcResiPredYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
+#else
       xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
+#endif
 #endif
       if ( uiMRGCost < uiMECost )
@@ -4116,5 +4248,7 @@
   UInt      uiWidth      = pcCU->getWidth ( 0 );
   UInt      uiHeight     = pcCU->getHeight( 0 );
-  
+#if LG_RESTRICTEDRESPRED_M24766
+  Int       iPUResiPredShift[4];
+#endif
   //  No residual coding : SKIP mode
   if ( ePredMode == MODE_SKIP && bSkipRes )
@@ -4128,5 +4262,10 @@
     if( pcCU->getResPredFlag( 0 ) )
     {
+#if LG_RESTRICTEDRESPRED_M24766
+		pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+		rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd, uiWidth, uiHeight );
+#else
       rpcYuvRec->add( rpcYuvResPrd, uiWidth, uiHeight );
+#endif
       rpcYuvRec->clip( uiWidth, uiHeight );
     }
@@ -4237,10 +4376,20 @@
   else
   {
+#if LG_RESTRICTEDRESPRED_M24766
+	  iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
+	  rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), pcYuvOrg, pcYuvPred, 0, uiWidth );
+#else
   rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
+#endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
     // subtract residual prediction
     if( pcCU->getResPredFlag( 0 ) )
     {
+#if LG_RESTRICTEDRESPRED_M24766
+		pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+		rpcYuvResi->subtract(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
+#else
       rpcYuvResi->subtract( rpcYuvResi, rpcYuvResPrd, 0, uiWidth );
+#endif
     }
 #endif
@@ -4456,6 +4605,13 @@
   {
     pcYuvPred->copyToPartYuv( rpcYuvRec, 0 );
+#if LG_RESTRICTEDRESPRED_M24766
+	pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+	rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResPrd,   uiWidth, uiHeight );
+	iPUResiPredShift[0] = iPUResiPredShift[1] = iPUResiPredShift[2] = iPUResiPredShift[3] = 0;
+    rpcYuvRec->add(iPUResiPredShift, pcCU->getPartitionSize(0), rpcYuvResiBest, uiWidth, uiHeight );
+#else
     rpcYuvRec->add( rpcYuvResPrd,   uiWidth, uiHeight );
     rpcYuvRec->add( rpcYuvResiBest, uiWidth, uiHeight );
+#endif
     rpcYuvRec->clip( uiWidth, uiHeight );
   }
Index: trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 77)
@@ -188,4 +188,7 @@
   Void predInterSearch          ( TComDataCU* pcCU,
                                   TComYuv*    pcOrgYuv,
+#if LG_RESTRICTEDRESPRED_M24766
+								  TComYuv*     rpcResiPredYuv,
+#endif
                                   TComYuv*&   rpcPredYuv,
                                   TComYuv*&   rpcResiYuv,
@@ -440,4 +443,7 @@
   Void xMergeEstimation           ( TComDataCU*     pcCU,
                                     TComYuv*        pcYuvOrg,
+#if LG_RESTRICTEDRESPRED_M24766
+									TComYuv*        rpcResiPredYuv, 
+#endif
                                     Int             iPartIdx,
                                     UInt&           uiInterDir,
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 77)
@@ -161,5 +161,9 @@
  \param pPPS          PPS associated with the slice
  */
+#if VIDYO_VPS_INTEGRATION
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS * pVPS, TComSPS* pSPS, TComPPS *pPPS )
+#else
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+#endif
 {
   Double dQP;
@@ -167,4 +171,7 @@
   
   rpcSlice = pcPic->getSlice(0);
+#if VIDYO_VPS_INTEGRATION
+  rpcSlice->setVPS( pVPS );
+#endif
   rpcSlice->setSPS( pSPS );
   rpcSlice->setPPS( pPPS );
Index: trunk/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 77)
@@ -110,6 +110,9 @@
   
   /// preparation of slice encoding (reference marking, QP and lambda)
+#if VIDYO_VPS_INTEGRATION
+  Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS );
+#else
   Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
-
+#endif
   // compress and encode slice
   Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 61)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 77)
@@ -348,5 +348,9 @@
 
 #if DEPTH_MAP_GENERATION
+#if VIDYO_VPS_INTEGRATION
+  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getVPSAccess(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
+#else
   m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
+#endif
 #endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
@@ -977,5 +981,9 @@
 Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid,TComList<TComPic*>& listPic )
 {
+#if HHI_FIX
+  if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && POCCurr == 0 )
+#else
   if( slice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV )
+#endif
   {
     TComReferencePictureSet* rps = slice->getLocalRPS();
