Index: /trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 312)
+++ /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 313)
@@ -429,8 +429,15 @@
       m_cVPS.setDependentLayer                                        ( layerId-1, layerId);
 #endif
+#if FCO_FIX_SPS_CHANGE
+      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
+      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
+      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
+      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
+#else
       m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
       m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
       m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
       m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
+#endif
 
       //====== Coding Structure ========
@@ -970,4 +977,5 @@
     {
       Int  iNumEncoded = 0;
+
 #if !QC_MVHEVC_B0046
       UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId );
@@ -977,4 +985,5 @@
       }
 #endif
+
 
 #if FLEX_CODING_ORDER_M23723
@@ -994,4 +1003,16 @@
             assert(isdigit(m_pchMVCJointCodingOrder[i]));
             iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+#if (FCO_FIX && MERL_VSP_C0152)
+            Int iCurPoc = m_acTEncTopList[iViewIdx]->getFrameId(gopId);
+            if( iCurPoc < m_acTEncTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
+            {
+              TComPic* pcBaseTxtPic   = getPicFromView(  0, m_acTEncTopList[iViewIdx]->getFrameId(gopId), false ); //get base view reconstructed texture
+              TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncTopList[iViewIdx]->getFrameId(gopId), true );  //get base view reconstructed depth
+              TEncSlice* pEncSlice = m_acTEncTopList[iViewIdx]->getSliceEncoder();
+              pEncSlice->setRefPicBaseTxt(pcBaseTxtPic);
+              pEncSlice->setRefPicBaseDepth(pcBaseDepthPic);
+            }
+            setBWVSPLUT( iViewIdx, gopId, false);            
+#endif
 
             m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
@@ -1008,4 +1029,5 @@
               assert(isdigit(m_pchMVCJointCodingOrder[i]));
               iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+
 #if SAIT_VSO_EST_A0033
               if( m_bUseVSO && iNextPoc < m_iFrameToBeEncoded )
@@ -1015,4 +1037,14 @@
               }
 #endif
+#if (FCO_FIX && MERL_VSP_C0152)
+              Int iCurPocDepth = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
+              if( iCurPocDepth < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
+              {
+                TComPic* pcBaseDepthPic = getPicFromView(  0, m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId), true );
+                TEncSlice* pcSlice = (TEncSlice*) m_acTEncDepthTopList[iViewIdx]->getSliceEncoder();
+                pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
+              }
+              setBWVSPLUT( iViewIdx, gopId, true);
+#endif
               m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
               xWriteOutput(bitstreamFile, iNumDepthEncoded, outputAccessUnits, iViewIdx, true);
@@ -1039,4 +1071,8 @@
 
 #if MERL_VSP_C0152
+#if MERL_VSP_C0152_BugFix_ForNoDepthCase
+        if(m_bUsingDepthMaps) //VSP can be used only when depth is available as input
+        {
+#endif
         Int iCurPoc = m_acTEncDepthTopList[iViewIdx]->getFrameId(gopId);
         if( iCurPoc < m_acTEncDepthTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
@@ -1049,4 +1085,18 @@
         }
         setBWVSPLUT( iViewIdx, gopId, false);
+#if MERL_VSP_C0152_BugFix_ForNoDepthCase
+        }
+        else
+        {
+          Int iCurPoc = m_acTEncTopList[iViewIdx]->getFrameId(gopId);
+          if( iCurPoc < m_acTEncTopList[iViewIdx]->getFrameToBeEncoded() && iViewIdx!=0 )
+          {
+            TEncSlice* pEncSlice = m_acTEncTopList[iViewIdx]->getSliceEncoder();
+            pEncSlice->setRefPicBaseTxt(NULL);//Initialize the base view reconstructed texture buffer
+            pEncSlice->setRefPicBaseDepth(NULL);//Initialize the base view reconstructed depth buffer
+          }
+        }
+#endif
+
 #endif
         // call encoding function for one frame
Index: /trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 313)
@@ -81,4 +81,11 @@
                                           UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, Int* iVSPIndexTrue, Int mrgCandIdx, DisInfo* pDInfo )
 {
+#if MERL_VSP_C0152_BugFix_ForNoDepthCase
+  TComPic* pRefPicBaseDepth = NULL;
+  pRefPicBaseDepth = getSlice()->getRefPicBaseDepth();
+  if(ucVspMergePos == VSP_MERGE_POS && pRefPicBaseDepth) //VSP can be used only when depth is used as input
+#else
+  if( ucVspMergePos == VSP_MERGE_POS )
+#endif
   if( ucVspMergePos == VSP_MERGE_POS )
   {
@@ -3596,5 +3603,9 @@
 #if H3D_IVMP
 #if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+#if FCO_FIX
+  const Int extraMergeCand = ( ( ( getSlice()->getIsDepth() && m_pcSlice->getTexturePic() ) || getSlice()->getSPS()->getMultiviewMvPredMode() )? 1 : 0 );
+#else
   const Int extraMergeCand = ( ( getSlice()->getIsDepth() || getSlice()->getSPS()->getMultiviewMvPredMode() )? 1 : 0 );
+#endif
 #else
   const Int extraMergeCand = ( getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
@@ -3651,4 +3662,7 @@
   if(!bNoPdmMerge)
   {
+#if FCO_DVP_REFINE_C0132_C0170
+    if( !getPic()->getDepthCoded() )
+#endif
     getDisMvpCandNBDV(uiPUIdx, uiAbsPartIdx, &cDisInfo , true
 #if MERL_VSP_C0152
@@ -3657,4 +3671,20 @@
 );
   }
+#if FCO_DVP_REFINE_C0132_C0170
+  if(getPic()->getDepthCoded() )
+  {
+    TComPic*      pcCodedDepthMap = getPic()->getRecDepthMap();
+    TComMv        cColMv;
+
+    cColMv.setZero();
+    estimateDVFromDM(uiPUIdx, pcCodedDepthMap, uiAbsPartIdx, &cColMv, false);
+
+    cDisInfo.iN = 1;
+    cDisInfo.m_acMvCand[0].setHor( cColMv.getHor() );
+    cDisInfo.m_acMvCand[0].setVer( cColMv.getVer() );
+    cDisInfo.m_aVIdxCan[0] = 0;
+
+  }
+#endif
   if(cDisInfo.iN==0)
   {
@@ -3669,5 +3699,9 @@
 
 #if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
+#if FCO_FIX
+  if( m_pcSlice->getIsDepth() && m_pcSlice->getTexturePic() )
+#else
   if( m_pcSlice->getIsDepth())
+#endif
   {
     UInt uiPartIdxCenter;
@@ -5140,8 +5174,11 @@
   Int width  = pcBaseViewDepthPicYuv->getWidth();
   Int height = pcBaseViewDepthPicYuv->getHeight();
-
+#if MTK_DVPREFINE_BVSP_BUG_FIX
+  Int depthPosX = Clip3(0,   width - iWidth,  iBlkX + (mv->getHor()>>2));
+  Int depthPosY = Clip3(0,   height - iHeight,  iBlkY + (mv->getVer()>>2));
+#else
   Int depthPosX = Clip3(0,   width - iWidth  - 1,  iBlkX + (mv->getHor()>>2));
   Int depthPosY = Clip3(0,   height- iHeight - 1,  iBlkY + (mv->getVer()>>2));
-
+#endif
   Pel *depth  = pcBaseViewDepthPicYuv->getLumaAddr() + depthPosX + depthPosY * depStride;
   Pel  maxDepth = 0;
@@ -5149,8 +5186,15 @@
   if ( bSimpleDvpRefine )
   {
+#if MTK_DVPREFINE_BVSP_BUG_FIX
+    Int depthStartPosX = Clip3(0,   width - iWidth,  iBlkX + (mv->getHor()>>2));
+    Int depthStartPosY = Clip3(0,   height - iHeight,  iBlkY + (mv->getVer()>>2));
+    Int depthEndPosX = Clip3(0,   width - 1,  iBlkX + iWidth - 1  + (mv->getHor()>>2));
+    Int depthEndPosY = Clip3(0,   height - 1,  iBlkY + iHeight - 1 + (mv->getVer()>>2));
+#else
     Int depthStartPosX = Clip3(0,   width - iWidth  - 1,  iBlkX + (mv->getHor()>>2));
     Int depthStartPosY = Clip3(0,   height- iHeight - 1,  iBlkY + (mv->getVer()>>2));
     Int depthEndPosX = Clip3(0,   width - iWidth  - 1,  iBlkX + iWidth  + (mv->getHor()>>2));
     Int depthEndPosY = Clip3(0,   height- iHeight - 1,  iBlkY + iHeight + (mv->getVer()>>2));
+#endif
     Int iCenterX = (depthStartPosX + depthEndPosX) >> 1;
     Int iCenterY = (depthStartPosY + depthEndPosY) >> 1;
@@ -6079,4 +6123,7 @@
       DisInfo cDisInfo;
       cDisInfo.iN = 0;
+#if FCO_DVP_REFINE_C0132_C0170
+      if( !getPic()->getDepthCoded() )
+#endif
       getDisMvpCandNBDV(uiPartIdx, uiPartAddr, &cDisInfo, false
 #if MERL_VSP_C0152
@@ -6084,4 +6131,19 @@
 #endif
               ); 
+#if FCO_DVP_REFINE_C0132_C0170
+      if(getPic()->getDepthCoded() )
+      {
+        TComPic*      pcCodedDepthMap = getPic()->getRecDepthMap();
+        TComMv        cColMv;
+
+        cColMv.setZero();
+        estimateDVFromDM(uiPartIdx, pcCodedDepthMap, uiPartAddr, &cColMv, false);
+
+        cDisInfo.iN = 1;
+        cDisInfo.m_acMvCand[0].setHor( cColMv.getHor() );
+        cDisInfo.m_acMvCand[0].setVer( cColMv.getVer() );
+        cDisInfo.m_aVIdxCan[0] = 0;
+      }
+#endif
       if(cDisInfo.iN==0)
       {
@@ -7921,4 +7983,21 @@
   PartSize m_peSaved =  getPartitionSize( 0 );
   m_pePartSize[0] =  SIZE_2Nx2N;
+#if FCO_DVP_REFINE_C0132_C0170
+  if(getPic()->getDepthCoded() )
+  {
+    TComPic*      pcCodedDepthMap = getPic()->getRecDepthMap();
+    TComMv        cColMv;
+
+    cColMv.setZero();
+    estimateDVFromDM(0, pcCodedDepthMap, 0, &cColMv, false);
+
+    cDisInfo.iN = 1;
+    cDisInfo.m_acMvCand[0].setHor( cColMv.getHor() );
+    cDisInfo.m_acMvCand[0].setVer( cColMv.getVer() );
+    cDisInfo.m_aVIdxCan[0] = 0;
+
+  }
+  else
+#endif
   getDisMvpCandNBDV( 0, 0,  &cDisInfo, false );
   if( cDisInfo.iN == 0)
Index: /trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 313)
@@ -59,4 +59,8 @@
 #endif
 #endif
+#if FCO_DVP_REFINE_C0132_C0170
+  m_bDepthCoded       = false;
+  m_pcRecDepthMap     = NULL;
+#endif
 #if H3D_IVMP
   m_pcOrgDepthMap     = NULL;
Index: /trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPic.h	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComPic.h	(revision 313)
@@ -73,4 +73,9 @@
 #endif
 
+#if FCO_DVP_REFINE_C0132_C0170
+  Bool                  m_bDepthCoded;
+  TComPic*              m_pcRecDepthMap;   
+#endif
+
 #if LG_ZEROINTRADEPTHRESI_A0087
   Int                   m_uiIntraPeriod;
@@ -171,4 +176,11 @@
   Bool          getCandPicCheckedFlag ()                { return m_checked;}
 #endif
+#endif
+
+#if FCO_DVP_REFINE_C0132_C0170
+  void setRecDepthMap(TComPic * pRecPic)                { m_pcRecDepthMap = pRecPic; }
+  TComPic * getRecDepthMap()                            { return m_pcRecDepthMap; }
+  void setDepthCoded(Bool flag)                         { m_bDepthCoded = flag; }
+  Bool getDepthCoded()                                  { return m_bDepthCoded; }
 #endif
 
Index: /trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 313)
@@ -60,5 +60,12 @@
   m_piPicOrgU       = NULL;
   m_piPicOrgV       = NULL;
-  
+
+#if FIX_APPENCTOP_T_ONLY
+  m_cuOffsetY       = NULL;
+  m_cuOffsetC       = NULL;
+  m_buOffsetY       = NULL;
+  m_buOffsetC       = NULL;
+#endif  
+
   m_bIsBorderExtended = false;
 }
@@ -137,9 +144,15 @@
   if( m_apiPicBufU ){ xFree( m_apiPicBufU );    m_apiPicBufU = NULL; }
   if( m_apiPicBufV ){ xFree( m_apiPicBufV );    m_apiPicBufV = NULL; }
-
+#if FIX_APPENCTOP_T_ONLY
+  if( m_cuOffsetY )
+  {
+#endif
   delete[] m_cuOffsetY;
   delete[] m_cuOffsetC;
   delete[] m_buOffsetY;
   delete[] m_buOffsetC;
+#if FIX_APPENCTOP_T_ONLY
+  }
+#endif
 }
 
Index: /trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 313)
@@ -1066,5 +1066,10 @@
     else
     {
+#if FIX_LGE_WP_FOR_3D_C0223
+      if ( ( pcCU->getSlice()->getPPS()->getUseWP()      && pcCU->getSlice()->getSliceType() == P_SLICE ) || 
+         ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() && pcCU->getSlice()->getSliceType() == B_SLICE ) )
+#else
       if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
+#endif
       {
 #if DEPTH_MAP_GENERATION
@@ -1100,6 +1105,9 @@
     }
   }
-
+#if FIX_LGE_WP_FOR_3D_C0223
+  if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() && pcCU->getSlice()->getSliceType() == B_SLICE  )
+#else
   if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() )
+#endif
   {
 #if MERL_VSP_C0152
@@ -1110,4 +1118,16 @@
     xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
   }
+#if FIX_LGE_WP_FOR_3D_C0223
+  else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE )
+
+  {
+#if MERL_VSP_C0152
+    if(pcCU->getVSPIndex(uiPartAddr))
+      m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight );
+    else
+#endif
+      xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred, iPartIdx ); 
+  }
+#endif
   else
   {
@@ -1434,8 +1454,11 @@
   Int dstStride = dstPic->getStride();
   Int depStride =  pPicBaseDepth->getStride();
-
+#if MTK_DVPREFINE_BVSP_BUG_FIX
+  Int depthPosX = Clip3(0,   widthLuma - size_x,  (posX/nTxtPerDepthX) + (mv->getHor()>>2));
+  Int depthPosY = Clip3(0,   heightLuma- size_y,  (posY/nTxtPerDepthY) + (mv->getVer()>>2));
+#else
   Int depthPosX = Clip3(0,   widthLuma - size_x - 1,  (posX/nTxtPerDepthX) + (mv->getHor()>>2));
   Int depthPosY = Clip3(0,   heightLuma- size_y - 1,  (posY/nTxtPerDepthY) + (mv->getVer()>>2));
-
+#endif
   Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
   Pel *dst    = dstPic->getLumaAddr(partAddr);
@@ -1595,6 +1618,9 @@
     depthPosX = posX * nDepthPerTxtX + (mv->getHor()>>2);        //mv denotes the disparity for VSP
   }
+#if MTK_DVPREFINE_BVSP_BUG_FIX
+  depthPosX = Clip3(0, widthDepth - (size_x<<1), depthPosX);
+#else
   depthPosX = Clip3(0, widthDepth - (size_x<<1) - 1, depthPosX);
-  
+#endif
   if ( heightChroma > heightDepth )
   {
@@ -1609,5 +1635,9 @@
     depthPosY = posY * nDepthPerTxtY + (mv->getVer()>>2);     //mv denotes the disparity for VSP
   }
+#if MTK_DVPREFINE_BVSP_BUG_FIX
+  depthPosY = Clip3(0, heightDepth - (size_y<<1), depthPosY);
+#else
   depthPosY = Clip3(0, heightDepth - (size_y<<1) - 1, depthPosY);
+#endif
 
   Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
Index: /trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp	(revision 313)
@@ -81,45 +81,53 @@
   wpScalingParam  *wpCur    = &(pcDtParam->wpCur[uiComp]);
   Int   w0      = wpCur->w,
-        offset  = wpCur->offset,
-        shift   = wpCur->shift,
-        round   = wpCur->round;
-  
+    offset  = wpCur->offset,
+    shift   = wpCur->shift,
+    round   = wpCur->round;
+
   UInt uiSum = 0;
-  #if HHI_INTERVIEW_SKIP
+#if HHI_INTERVIEW_SKIP
   if( pcDtParam->pUsed )
   {
     Pel*  piUsed      = pcDtParam->pUsed;
     Int   iStrideUsed = pcDtParam->iStrideUsed;
-  for( ; iRows != 0; iRows-- )
-  {
-    for (Int n = 0; n < iCols; n++ )
-    {
+    for( ; iRows != 0; iRows-- )
+    {
+      for (Int n = 0; n < iCols; n++ )
+      {
         if( piUsed[n])
         {
-      pred = ( (w0*piCur[n] + round) >> shift ) + offset ;
-      //uiSum += abs( piOrg[n] - piCur[n] );
-      uiSum += abs( piOrg[n] - pred );
-    }
-    }
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
+          pred = ( (w0*piCur[n] + round) >> shift ) + offset ;
+          uiSum += abs( piOrg[n] - pred );
+        }
+      }
+      piOrg += iStrideOrg;
+      piCur += iStrideCur;
       piUsed += iStrideUsed;
-  }
-#else
-  for( ; iRows != 0; iRows-- )
-  {
-    for (Int n = 0; n < iCols; n++ )
-    {
-      pred = ( (w0*piCur[n] + round) >> shift ) + offset ;
-  
-      uiSum += abs( piOrg[n] - pred );
-    }
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-    #endif
-    #if HHI_INTERVIEW_SKIP
+    }
+#if FIX_LGE_WP_FOR_3D_C0223
+  }
+  else
+  {
+#endif
+#if FIX_LGE_WP_FOR_3D_C0223 //comment of #else
+    //#else
+#endif
+#endif
+    for( ; iRows != 0; iRows-- )
+    {
+      for (Int n = 0; n < iCols; n++ )
+      {
+        pred = ( (w0*piCur[n] + round) >> shift ) + offset ;
+        uiSum += abs( piOrg[n] - pred );
       }
-    #endif
+      piOrg += iStrideOrg;
+      piCur += iStrideCur;
+    }
+#if FIX_LGE_WP_FOR_3D_C0223 //comment of #endif
+    //#endif
+#endif
+#if HHI_INTERVIEW_SKIP
+  }
+#endif
   pcDtParam->uiComp = 255;  // reset for DEBUG (assert test)
 
Index: /trunk/source/Lib/TLibCommon/TComResidualGenerator.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 313)
@@ -614,8 +614,15 @@
   Int           iDesStrideC = pcYuv    ->getCStride();
 #if MTK_RELEASE_DV_CONSTRAINT_C0129
+#if FIX_CHROMA_RESIDUAL_C0129
+  Pel*          pSrcSamplesU0= pcBaseRes->getCbAddr ( 0 ) + iCRefPosY0 * iSrcStrideC;
+  Pel*          pSrcSamplesU1= pcBaseRes->getCbAddr ( 0 ) + iCRefPosY1 * iSrcStrideC;
+  Pel*          pSrcSamplesV0= pcBaseRes->getCrAddr ( 0 ) + iCRefPosY0 * iSrcStrideC;
+  Pel*          pSrcSamplesV1= pcBaseRes->getCrAddr ( 0 ) + iCRefPosY1 * iSrcStrideC;
+#else
   Pel*          pSrcSamplesU0= pcBaseRes->getCbAddr ( 0 ) + ( iCRefPosY0 >> 1 ) * iSrcStrideC;
   Pel*          pSrcSamplesU1= pcBaseRes->getCbAddr ( 0 ) + ( iCRefPosY1 >> 1 ) * iSrcStrideC;
   Pel*          pSrcSamplesV0= pcBaseRes->getCrAddr ( 0 ) + ( iCRefPosY0 >> 1 ) * iSrcStrideC;
   Pel*          pSrcSamplesV1= pcBaseRes->getCrAddr ( 0 ) + ( iCRefPosY1 >> 1 ) * iSrcStrideC;
+#endif
 #else
   Pel*          pSrcSamplesU= pcBaseRes->getCbAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
Index: /trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 313)
@@ -1761,5 +1761,9 @@
 
 Void
+#if FCO_FIX_SPS_CHANGE
+TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
+#else
 TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx )
+#endif
 {
   AOT( uiViewId == 0 && iViewOrderIdx != 0 );
@@ -1769,8 +1773,28 @@
   m_iViewOrderIdx         = iViewOrderIdx;
   m_bDepth                = true;
+#if FCO_FIX_SPS_CHANGE
+  m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
+  m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
+#else
   m_uiCamParPrecision     = 0;
   m_bCamParInSliceHeader  = false;
+#endif
   ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
+#if FCO_FIX_SPS_CHANGE
+#if !QC_MVHEVC_B0046
+  if( !m_bCamParInSliceHeader )
+  {
+    for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
+    {
+      m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
+      m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
+      m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
+      m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
+    }
+  }
+#endif
+#endif
+
 }
 
Index: /trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 313)
@@ -623,5 +623,9 @@
 
   Void initMultiviewSPS      ( UInt uiViewId, Int iViewOrderIdx = 0, UInt uiCamParPrecision = 0, Bool bCamParSlice = false, Int** aaiScale = 0, Int** aaiOffset = 0 );
+#if FCO_FIX_SPS_CHANGE
+  Void initMultiviewSPSDepth ( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision = 0, Bool bCamParSlice = false, Int** aaiScale = 0, Int** aaiOffset = 0 );
+#else
   Void initMultiviewSPSDepth ( UInt uiViewId, Int iViewOrderIdx );
+#endif
 
   UInt getViewId             ()  { return m_uiViewId; }
Index: /trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 312)
+++ /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 313)
@@ -121,4 +121,5 @@
 #define MTK_RELEASE_DV_CONSTRAINT_C0129   1   // JCT3V-C0129
 #define MTK_SIMPLIFY_DVTC_C0135           1   // JCT3V-C0135
+#define FIX_CHROMA_RESIDUAL_C0129         1 
 
 ///// ***** MOTION PARAMETER INHERITANCE  *********
@@ -166,4 +167,6 @@
 #define HHI_DEPTH_INTRA_SEARCH_RAU_C0160  1   // JCT3V-C0160 change 1: full Intra search in depth random access units 
 #define FIX_POZNAN_CABAC_INIT_FLAG        1
+#define FIX_LGE_WP_FOR_3D_C0223           1   // JCT3V-C0223 Weighted Prediction Bug-fix for 3D-HEVC. Caution! There is still crush using WP with Residual Prediction.
+#define FIX_APPENCTOP_T_ONLY              1   // For Texture-only coding
 
 ///// ***** FCO  *********
@@ -171,4 +174,12 @@
 #if FLEX_CODING_ORDER_M23723
 #define DISABLE_FCO_FOR_VSO               0 // Optional compile settings to disable VSO with FCO.
+#define FCO_DVP_REFINE_C0132_C0170        0 // depth oriented disparity vector prediction from JCT3V-C0132 and JCT3V-C0170
+#define FCO_FIX                           0 // Bug fix for C0137 and C0152 on FCO
+#define FCO_FIX_SPS_CHANGE                0 // Sending camera parameters in SPS of depth for depth to disparity conversion used by VSP and DoDVP
+#else
+#define DISABLE_FCO_FOR_VSO               0 // Optional compile settings to disable VSO with FCO.
+#define FCO_DVP_REFINE_C0132_C0170        0 // depth oriented disparity vector prediction from JCT3V-C0132 and JCT3V-C0170
+#define FCO_FIX                           0 // Fixing bugs from HTM 6.0 which 
+#define FCO_FIX_SPS_CHANGE                0 // Fixing bugs from HTM 6.0 which 
 #endif
 
@@ -176,5 +187,5 @@
 #define MERL_VSP_C0152                    1 // JCT3V-C0152: 1: enable VSP-related tools; 0: disable VSP-related tools
 #if MERL_VSP_C0152
-
+#define MERL_VSP_C0152_BugFix_ForNoDepthCase     1// MERL bugfix for test condition of no depth
 /*
  * Two macros are used to configure combinations of JCT3V-C0152 and JCT3V-C0131
@@ -199,4 +210,5 @@
 #define VSP_MERGE_POS                        5 // JCT3V-C0152: fixed position of VSP candidate in merge list, supported values: 5.
 #define LGE_SIMP_DVP_REFINE_C0112            1 // JCT3V-C0112: 1: simplification of refining disparity vector using a warped depth block
+#define MTK_DVPREFINE_BVSP_BUG_FIX               1
 
 #else // !MERL_VSP_C0152
Index: /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 312)
+++ /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 313)
@@ -1501,9 +1501,45 @@
       if( uiCode )
       {
+#if FCO_FIX_SPS_CHANGE
+        UInt  uiViewId, uiCamParPrecision;
+        Int   iVOI;
+        Bool  bCamParSlice;
+        READ_UVLC( uiCode, "view_id" ); 
+        READ_SVLC( iCode, "view_order_idx" );
+        uiViewId = uiCode;
+        iVOI = iCode;
+
+        if ( uiViewId == 0 )
+        {
+          pcSPS->initMultiviewSPSDepth    ( uiViewId, iVOI );
+        }
+        else
+        {
+          READ_UVLC( uiCamParPrecision, "camera_parameter_precision" );
+          READ_FLAG( uiCode, "camera_parameter_in_slice_header" );    bCamParSlice = ( uiCode == 1 );
+          if( !bCamParSlice )
+          {
+            for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
+            {
+              READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
+              READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
+              READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
+              READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
+            }
+          }
+          pcSPS->initMultiviewSPSDepth( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
+
+        }
+#else
         READ_UVLC( uiCode, "view_id" ); 
         READ_SVLC(  iCode, "view_order_idx" ); 
         pcSPS->initMultiviewSPSDepth    ( uiCode, iCode );
+#endif
 #if DEPTH_MAP_GENERATION
+#if FCO_FIX_SPS_CHANGE
+        pcSPS->setPredDepthMapGeneration( uiViewId, true );
+#else
         pcSPS->setPredDepthMapGeneration( uiCode, true );
+#endif
 #endif
 #if H3D_IVRP
Index: /trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 312)
+++ /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 313)
@@ -193,13 +193,18 @@
 
   AOF( pcSlice->getSPS()->getViewId() < MAX_VIEW_NUM );
+#if !FCO_FIX  // Under flexible coding order, depth may need the camera parameters
   if ( pcSlice->getSPS()->isDepth  () )
   {
     return;
   }
+#endif
   Bool  bFirstAU          = ( pcSlice->getPOC()               == 0 );
   Bool  bFirstSliceInAU   = ( pcSlice->getPOC()               != Int ( m_iLastPOC ) );
   Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
   AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
+#if FCO_FIX
+#else
   AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
+#endif
   AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
   AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
@@ -1123,8 +1128,10 @@
     }
 
+#if !FIX_LGE_WP_FOR_3D_C0223
     if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
     {
       pcSlice->setWpParamforLC();
     }
+#endif
     pcSlice->setNoBackPredFlag( false );
     if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
@@ -1171,4 +1178,27 @@
   }
 #endif
+
+#if FCO_DVP_REFINE_C0132_C0170
+  if(m_bFirstSliceInPicture)
+  {
+    pcPic->setDepthCoded(false);
+
+    if(m_viewId != 0)
+    {
+      if( m_isDepth == 0)
+      {
+        TComPic * recDepthMapBuffer;
+        recDepthMapBuffer = m_tAppDecTop->getPicFromView( m_viewId, pcSlice->getPOC(), true );
+        pcPic->setRecDepthMap(recDepthMapBuffer);
+
+        if(recDepthMapBuffer != NULL)
+        {
+          pcPic->setDepthCoded(true);
+        }
+      }
+    }
+  }
+#endif
+
 
 #if MERL_VSP_C0152 // set BW LUT 
Index: /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 312)
+++ /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 313)
@@ -663,4 +663,21 @@
       WRITE_UVLC( pcSPS->getViewId(), "view_id" );
       WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" );
+#if FCO_FIX_SPS_CHANGE
+      if ( pcSPS->getViewId() )
+      {
+        WRITE_UVLC( pcSPS->getCamParPrecision(), "camera_parameter_precision" );
+        WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "camera_parameter_in_slice_header" );
+        if( !pcSPS->hasCamParInSliceHeader() )
+        {
+          for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
+          {
+            WRITE_SVLC( pcSPS->getCodedScale    ()[ uiId ], "coded_scale" );
+            WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiId ], "coded_offset" );
+            WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" );
+            WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" );
+          }
+        }      
+      }
+#endif
     }
     else
@@ -1099,6 +1116,10 @@
     }
 #endif
-  
+
+#if FIX_LGE_WP_FOR_3D_C0223
+    if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc() && pcSlice->getSliceType()==B_SLICE) )
+#else
     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE) )
+#endif    
     {
       xCodePredWeightTable( pcSlice );
Index: /trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 312)
+++ /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 313)
@@ -726,4 +726,22 @@
       m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++]  = uiNextCUAddr;
 
+#if FCO_DVP_REFINE_C0132_C0170
+      pcPic->setDepthCoded(false);
+
+      if(pcSlice->getViewId() != 0)
+      {
+        if(pcSlice->getSPS()->isDepth() == 0 )
+        {
+          TComPic * recDepthMapBuffer;
+          recDepthMapBuffer = m_pcEncTop->getEncTop()->getPicFromView( pcSlice->getViewId(), pcSlice->getPOC(), true );
+          pcSlice->getPic()->setRecDepthMap(recDepthMapBuffer);
+          if(recDepthMapBuffer->getReconMark())
+          {
+            pcPic->setDepthCoded(true);
+          }
+        }
+      }
+#endif
+
 #if DEPTH_MAP_GENERATION
       // init view component and predict virtual depth map
Index: /trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 312)
+++ /trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 313)
@@ -60,4 +60,8 @@
   m_pcBufferLowLatSbacCoders    = NULL;
   m_pcBufferLowLatBinCoderCABACs  = NULL;
+#if FCO_DVP_REFINE_C0132_C0170
+  m_pPicBaseTxt = NULL;
+  m_pPicBaseDepth = NULL;
+#endif
 }
 
@@ -673,9 +677,8 @@
     xCalcACDCParamSlice(pcSlice);
   }
-
-  Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1);
-  Bool bWp_implicit = (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2);
-
-  if ( bWp_explicit || bWp_implicit )
+#if FIX_LGE_WP_FOR_3D_C0223
+  Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc());
+
+  if ( bWp_explicit )
   {
     //------------------------------------------------------------------------------
@@ -686,4 +689,25 @@
       printf("Weighted Prediction is not supported with slice mode determined by max number of bins.\n"); exit(0);
     }
+    xEstimateWPParamSlice( pcSlice );
+    pcSlice->initWpScaling();
+#if !FIX_LGE_WP_FOR_3D_C0223 // Interim fix for encoder/decoder mismatch of non-fade sequence
+    // check WP on/off
+    xCheckWPEnable( pcSlice );
+#endif
+  }
+#else
+
+  Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1);
+  Bool bWp_implicit = (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2);
+
+  if ( bWp_explicit || bWp_implicit )
+  {
+    //------------------------------------------------------------------------------
+    //  Weighted Prediction implemented at Slice level. SliceMode=2 is not supported yet.
+    //------------------------------------------------------------------------------
+    if ( pcSlice->getSliceMode()==2 || pcSlice->getEntropySliceMode()==2 )
+    {
+      printf("Weighted Prediction is not supported with slice mode determined by max number of bins.\n"); exit(0);
+    }
 
     if( bWp_explicit )
@@ -700,5 +724,5 @@
     }
   }
-
+#endif
 #if ADAPTIVE_QP_SELECTION
   if( m_pcCfg->getUseAdaptQpSelect() )
Index: /trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 312)
+++ /trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 313)
@@ -712,5 +712,10 @@
   if( m_isDepth )
   {
+#if FCO_FIX_SPS_CHANGE
+    m_cSPS.initMultiviewSPSDepth    ( m_viewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset );
+#else
     m_cSPS.initMultiviewSPSDepth    ( m_viewId, m_iViewOrderIdx );
+#endif
+
 #if DEPTH_MAP_GENERATION
     m_cSPS.setPredDepthMapGeneration( m_viewId, true );
