Index: /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComDataCU.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComDataCU.cpp	(revision 62)
@@ -2883,4 +2883,48 @@
 }
 
+#if LG_RESTRICTEDRESPRED_M24766
+Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight, UInt uiAbsPartIdx, Bool bLCU)
+{
+	UInt uiNumPartition  = bLCU ? (getWidth(uiAbsPartIdx)*getHeight(uiAbsPartIdx) >> 4) : m_uiNumPartition;
+	UInt uiTmpAbsPartIdx = bLCU ? uiAbsPartIdx : 0;
+
+	switch ( m_pePartSize[uiTmpAbsPartIdx] )
+	{
+	case SIZE_2NxN:
+		riWidth = getWidth(uiTmpAbsPartIdx);      riHeight = getHeight(uiTmpAbsPartIdx) >> 1; ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 1;
+		break;
+	case SIZE_Nx2N:
+		riWidth = getWidth(uiTmpAbsPartIdx) >> 1; riHeight = getHeight(uiTmpAbsPartIdx);      ruiPartAddr = ( uiPartIdx == 0 )? 0 : uiNumPartition >> 2;
+		break;
+	case SIZE_NxN:
+		riWidth = getWidth(uiTmpAbsPartIdx) >> 1; riHeight = getHeight(uiTmpAbsPartIdx) >> 1; ruiPartAddr = ( uiNumPartition >> 2 ) * uiPartIdx;
+		break;
+	case SIZE_2NxnU:
+		riWidth     = getWidth(uiTmpAbsPartIdx);
+		riHeight    = ( uiPartIdx == 0 ) ?  getHeight(uiTmpAbsPartIdx) >> 2 : ( getHeight(uiTmpAbsPartIdx) >> 2 ) + ( getHeight(uiTmpAbsPartIdx) >> 1 );
+		ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 3;
+		break;
+	case SIZE_2NxnD:
+		riWidth     = getWidth(uiTmpAbsPartIdx);
+		riHeight    = ( uiPartIdx == 0 ) ?  ( getHeight(uiTmpAbsPartIdx) >> 2 ) + ( getHeight(uiTmpAbsPartIdx) >> 1 ) : getHeight(uiTmpAbsPartIdx) >> 2;
+		ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 1) + (uiNumPartition >> 3);
+		break;
+	case SIZE_nLx2N:
+		riWidth     = ( uiPartIdx == 0 ) ? getWidth(uiTmpAbsPartIdx) >> 2 : ( getWidth(uiTmpAbsPartIdx) >> 2 ) + ( getWidth(uiTmpAbsPartIdx) >> 1 );
+		riHeight    = getHeight(uiTmpAbsPartIdx);
+		ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : uiNumPartition >> 4;
+		break;
+	case SIZE_nRx2N:
+		riWidth     = ( uiPartIdx == 0 ) ? ( getWidth(uiTmpAbsPartIdx) >> 2 ) + ( getWidth(uiTmpAbsPartIdx) >> 1 ) : getWidth(uiTmpAbsPartIdx) >> 2;
+		riHeight    = getHeight(uiTmpAbsPartIdx);
+		ruiPartAddr = ( uiPartIdx == 0 ) ? 0 : (uiNumPartition >> 2) + (uiNumPartition >> 4);
+		break;
+	default:
+		assert ( m_pePartSize[0] == SIZE_2Nx2N );
+		riWidth = getWidth(uiTmpAbsPartIdx);      riHeight = getHeight(uiTmpAbsPartIdx);      ruiPartAddr = 0;
+		break;
+	}
+}
+#else
 Void TComDataCU::getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight )
 {
@@ -2922,5 +2966,74 @@
   }
 }
-
+#endif
+
+#if LG_RESTRICTEDRESPRED_M24766
+Int TComDataCU::getResiPredMode(UInt uiPartAddr)
+{
+	Int iAddResiShift = -1;
+
+	for(UInt uiRefIdx = 0; uiRefIdx < 2; uiRefIdx++)
+	{
+		RefPicList eRefList = uiRefIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+		Int iBestRefIdx = getCUMvField(eRefList)->getRefIdx(uiPartAddr);
+		if(iBestRefIdx >= 0 && getSlice()->getViewId() == getSlice()->getRefViewId(eRefList, iBestRefIdx))
+			iAddResiShift++;
+	}
+
+	return iAddResiShift;
+}
+
+Void TComDataCU::getPUResiPredShift(Int *iPUResiPredShift, UInt uiAbsPartIndex)
+{
+	UInt uiPartSize = getPartitionSize(uiAbsPartIndex);
+	UInt uiPartAddr;
+	Int iWidth, iHeight;
+	Int iAddResiShift;
+
+	if(uiPartSize == SIZE_2Nx2N)
+	{
+		iAddResiShift = getResiPredMode(uiAbsPartIndex);
+		for(UInt i = 0; i < 4; i++)
+			iPUResiPredShift[i] = (getSlice()->getPPS()->getUseWP() || getInterDir(uiAbsPartIndex) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+		return;
+	}
+
+	if(uiPartSize == SIZE_2NxN || uiPartSize == SIZE_2NxnU || uiPartSize == SIZE_2NxnD)
+	{
+		for(UInt i = 0; i < 2; i++)
+		{
+			getPartIndexAndSize(i, uiPartAddr, iWidth, iHeight, uiAbsPartIndex, true);
+			uiPartAddr += uiAbsPartIndex;
+			iAddResiShift = getResiPredMode(uiPartAddr);
+			iPUResiPredShift[2*i] = iPUResiPredShift[2*i+1] = (getSlice()->getPPS()->getUseWP() || getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+		}
+		return;
+	}
+
+	if(uiPartSize == SIZE_Nx2N || uiPartSize == SIZE_nLx2N || uiPartSize == SIZE_nRx2N)
+	{
+		for(UInt i = 0; i < 2; i++)
+		{
+			getPartIndexAndSize(i, uiPartAddr, iWidth, iHeight, uiAbsPartIndex, true);
+			uiPartAddr += uiAbsPartIndex;
+			iAddResiShift = getResiPredMode(uiPartAddr);
+			iPUResiPredShift[i] = iPUResiPredShift[2+i] = (getSlice()->getPPS()->getUseWP() || getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+		}
+		return;
+	}
+
+	if(uiPartSize == SIZE_NxN)
+	{
+		for(UInt i = 0; i < 4; i++)
+		{
+			getPartIndexAndSize(i, uiPartAddr, iWidth, iHeight, uiAbsPartIndex, true);
+			uiPartAddr += uiAbsPartIndex;
+			iAddResiShift = getResiPredMode(uiPartAddr);
+			iPUResiPredShift[i] = (getSlice()->getPPS()->getUseWP() || getInterDir(uiPartAddr) != 3) ? (iAddResiShift >= 0 ? 0 : -1) : (iAddResiShift >= 0 ? 1-iAddResiShift : -1);
+		}
+	}
+
+}
+#endif
 
 Void TComDataCU::getMvField ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField )
Index: /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComDataCU.h	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComDataCU.h	(revision 62)
@@ -526,6 +526,13 @@
   // member functions for accessing partition information
   // -------------------------------------------------------------------------------------------------------------------
-  
+#if LG_RESTRICTEDRESPRED_M24766
+  Void          getPartIndexAndSize( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight, UInt uiAbsPartIdx = 0, Bool bLCU = false);
+#else
   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
+#endif
+#if LG_RESTRICTEDRESPRED_M24766
+  Int           getResiPredMode(UInt uiPartAddr);
+  Void          getPUResiPredShift (Int *iPUPredResiShift, UInt uiAbsPartIndex);
+#endif
   UChar         getNumPartInter       ();
   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
Index: /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComResidualGenerator.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComResidualGenerator.cpp	(revision 62)
@@ -335,4 +335,7 @@
   Pel*    pRes      = pcCUResidual->getLumaAddr();
   UInt    uiLumaTrMode, uiChromaTrMode;
+#if LG_RESTRICTEDRESPRED_M24766
+  Int     iPUPredResiShift[4];
+#endif
   pcCU->convertTransIdx             ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode );
 #if H0736_AVC_STYLE_QP_RANGE
@@ -363,5 +366,10 @@
     Bool bOK = pcCU->getResidualSamples( 0, m_ppcYuvTmp[0] );
     AOF( bOK );
+#if LG_RESTRICTEDRESPRED_M24766
+	pcCU->getPUResiPredShift(iPUPredResiShift, 0);
+	pcCUResidual->add(iPUPredResiShift, pcCU->getPartitionSize(0), m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
+#else
     pcCUResidual->add( m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
+#endif
   }
 
Index: /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComYuv.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComYuv.cpp	(revision 62)
@@ -392,5 +392,12 @@
 }
 
-
+#if LG_RESTRICTEDRESPRED_M24766
+Void
+TComYuv::add(Int *iPUResiPredShift, PartSize uhPartitionSize,  TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
+{
+	addLuma   (iPUResiPredShift, uhPartitionSize, pcYuvAdd, iWidth,    iHeight,    bSubtract );
+	addChroma (iPUResiPredShift, uhPartitionSize, pcYuvAdd, iWidth>>1, iHeight>>1, bSubtract );
+}
+#else
 Void
 TComYuv::add( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
@@ -399,7 +406,40 @@
   addChroma ( pcYuvAdd, iWidth>>1, iHeight>>1, bSubtract );
 }
-
+#endif
+
+#if LG_RESTRICTEDRESPRED_M24766
+void
+TComYuv::getPUXYOffset(PartSize uhPartitionSize, Int iWidth, Int iHeight, Int &iXOffset, Int &iYOffset)
+{
+	switch(uhPartitionSize)
+	{	  
+	case SIZE_2NxN:
+		iXOffset = iWidth;      iYOffset = iHeight >> 1;   break;
+	case SIZE_2NxnU:
+		iXOffset = iWidth;      iYOffset = iHeight >> 2;   break;
+	case SIZE_2NxnD: 
+		iXOffset = iWidth;      iYOffset = (iHeight >> 1) + (iHeight >> 2);   break;
+	case SIZE_Nx2N:
+		iXOffset = iWidth >> 1; iYOffset = iHeight; break;
+	case SIZE_nLx2N:
+		iXOffset = iWidth >> 2; iYOffset = iHeight; break;
+	case SIZE_nRx2N:
+		iXOffset = (iWidth >> 1) + (iWidth >> 2); iYOffset = iHeight; break;
+	case SIZE_NxN:
+		iXOffset = iWidth >> 1; iYOffset = iHeight >> 1;  break;
+	default:
+		assert(uhPartitionSize == SIZE_2Nx2N);
+		iXOffset = iWidth; 	  iYOffset = iHeight;	  break;
+	}
+}
+#endif
+
+#if LG_RESTRICTEDRESPRED_M24766
+Void 
+TComYuv::addLuma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
+#else
 Void
 TComYuv::addLuma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
+#endif
 {
   Int   iScale      = ( bSubtract ? -1 : 1 );
@@ -408,4 +448,48 @@
   Pel*  pAddSamples = pcYuvAdd->getLumaAddr();
   Pel*  pDstSamples = getLumaAddr();
+
+#if LG_RESTRICTEDRESPRED_M24766
+  Int iXOffset, iYOffset;
+
+  getPUXYOffset(uhPartitionSize, iWidth, iHeight, iXOffset, iYOffset);
+
+  for( Int iY = 0; iY < iYOffset; iY++, pDstSamples += iDstStride, pAddSamples += iAddStride )
+  {
+	  if(iPUResiPredShift[0] >= 0)
+	  {
+		  for( Int iX = 0; iX < iXOffset; iX++ )
+		  {
+			  pDstSamples[iX] += iScale * (pAddSamples[iX] >> iPUResiPredShift[0]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[1] >= 0)
+	  {
+		  for( Int iX = iXOffset; iX < iWidth; iX++ )
+		  {
+			  pDstSamples[iX] += iScale * (pAddSamples[iX] >> iPUResiPredShift[1]);
+		  }
+	  }
+  }
+
+  for( Int iY = iYOffset; iY < iHeight; iY++, pDstSamples += iDstStride, pAddSamples += iAddStride )
+  {
+	  if(iPUResiPredShift[2] >= 0)
+	  {
+		  for( Int iX = 0; iX < iXOffset; iX++ )
+		  {
+			  pDstSamples[iX] += iScale * (pAddSamples[iX] >> iPUResiPredShift[2]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[3] >= 0)
+	  {
+		  for( Int iX = iXOffset; iX < iWidth; iX++ )
+		  {
+			  pDstSamples[iX] += iScale * (pAddSamples[iX] >> iPUResiPredShift[3]);
+		  }
+	  }
+  }
+#else
   for( Int iY = 0; iY < iHeight; iY++, pDstSamples += iDstStride, pAddSamples += iAddStride )
   {
@@ -415,8 +499,14 @@
     }
   }
-}
-
+#endif
+}
+
+#if LG_RESTRICTEDRESPRED_M24766
+Void 
+TComYuv::addChroma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
+#else
 Void
 TComYuv::addChroma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
+#endif
 {
   Int   iScale        = ( bSubtract ? -1 : 1 );
@@ -427,4 +517,54 @@
   Pel*  pDstSamplesCb = getCbAddr();
   Pel*  pDstSamplesCr = getCrAddr();
+
+#if LG_RESTRICTEDRESPRED_M24766
+  Int iXOffset, iYOffset;
+ 
+  getPUXYOffset(uhPartitionSize, iWidth, iHeight, iXOffset, iYOffset);
+
+  for( Int iY = 0; iY < iYOffset; iY++, pDstSamplesCb += iDstStride, pAddSamplesCb += iAddStride,
+	  pDstSamplesCr += iDstStride, pAddSamplesCr += iAddStride  )
+  {
+	  if(iPUResiPredShift[0] >= 0)
+	  {
+		  for( Int iX = 0; iX < iXOffset; iX++ )
+		  {
+			  pDstSamplesCb[iX] += iScale * (pAddSamplesCb[iX] >> iPUResiPredShift[0]);
+			  pDstSamplesCr[iX] += iScale * (pAddSamplesCr[iX] >> iPUResiPredShift[0]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[1] >= 0)
+	  {
+		  for( Int iX = iXOffset; iX < iWidth; iX++ )
+		  {
+			  pDstSamplesCb[iX] += iScale * (pAddSamplesCb[iX] >> iPUResiPredShift[1]);
+			  pDstSamplesCr[iX] += iScale * (pAddSamplesCr[iX] >> iPUResiPredShift[1]);
+		  }
+	  }
+  }
+
+  for( Int iY = iYOffset; iY < iHeight; iY++, pDstSamplesCb += iDstStride, pAddSamplesCb += iAddStride,
+	  pDstSamplesCr += iDstStride, pAddSamplesCr += iAddStride  )
+  {
+	  if(iPUResiPredShift[2] >= 0)
+	  {
+		  for( Int iX = 0; iX < iXOffset; iX++ )
+		  {
+			  pDstSamplesCb[iX] += iScale * (pAddSamplesCb[iX] >> iPUResiPredShift[2]);
+			  pDstSamplesCr[iX] += iScale * (pAddSamplesCr[iX] >> iPUResiPredShift[2]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[3] >= 0)
+	  {
+		  for( Int iX = iXOffset; iX < iWidth; iX++ )
+		  {
+			  pDstSamplesCb[iX] += iScale * (pAddSamplesCb[iX] >> iPUResiPredShift[3]);
+			  pDstSamplesCr[iX] += iScale * (pAddSamplesCr[iX] >> iPUResiPredShift[3]);
+		  }
+	  }
+  }
+#else
   for( Int iY = 0; iY < iHeight; iY++, pDstSamplesCb += iDstStride, pAddSamplesCb += iAddStride,
                                        pDstSamplesCr += iDstStride, pAddSamplesCr += iAddStride  )
@@ -436,4 +576,5 @@
     }
   }
+#endif
 }
 
@@ -535,11 +676,23 @@
 }
 
+#if LG_RESTRICTEDRESPRED_M24766
+Void TComYuv::subtract(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+{
+	subtractLuma  (iPUResiPredShift, uhPartitionSize, pcYuvSrc0, pcYuvSrc1,  uiTrUnitIdx, uiPartSize    );
+	subtractChroma(iPUResiPredShift, uhPartitionSize, pcYuvSrc0, pcYuvSrc1,  uiTrUnitIdx, uiPartSize>>1 );
+}
+#else
 Void TComYuv::subtract( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
 {
-  subtractLuma  ( pcYuvSrc0, pcYuvSrc1,  uiTrUnitIdx, uiPartSize    );
-  subtractChroma( pcYuvSrc0, pcYuvSrc1,  uiTrUnitIdx, uiPartSize>>1 );
-}
-
+	subtractLuma  ( pcYuvSrc0, pcYuvSrc1,  uiTrUnitIdx, uiPartSize    );
+	subtractChroma( pcYuvSrc0, pcYuvSrc1,  uiTrUnitIdx, uiPartSize>>1 );
+}
+#endif
+
+#if LG_RESTRICTEDRESPRED_M24766
+Void TComYuv::subtractLuma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+#else
 Void TComYuv::subtractLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+#endif
 {
   Int x, y;
@@ -552,4 +705,55 @@
   Int  iSrc1Stride = pcYuvSrc1->getStride();
   Int  iDstStride  = getStride();
+
+#if LG_RESTRICTEDRESPRED_M24766
+  Int iXOffset, iYOffset;
+
+  getPUXYOffset(uhPartitionSize, uiPartSize, uiPartSize, iXOffset, iYOffset);
+
+  for ( y = uiPartSize-1; y >= iYOffset; y-- )
+  {
+	  if(iPUResiPredShift[3] >= 0)
+	  {
+		  for ( x = uiPartSize-1; x >= iXOffset; x-- )
+		  {
+			  pDst[x] = pSrc0[x] - (pSrc1[x] >> iPUResiPredShift[3]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[2] >= 0)
+	  {
+		  for ( x = iXOffset-1; x >= 0; x-- )
+		  {
+			  pDst[x] = pSrc0[x] - (pSrc1[x] >> iPUResiPredShift[2]);
+		  }
+	  }
+	  pSrc0 += iSrc0Stride;
+	  pSrc1 += iSrc1Stride;
+	  pDst  += iDstStride;
+  }
+
+  for ( y = iYOffset-1; y >= 0; y-- )
+  {
+	  if(iPUResiPredShift[1] >= 0)
+	  {
+		  for ( x = uiPartSize-1; x >= iXOffset; x-- )
+		  {
+			  pDst[x] = pSrc0[x] - (pSrc1[x] >> iPUResiPredShift[3]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[0] >= 0)
+	  {
+		  for ( x = iXOffset-1; x >= 0; x-- )
+		  {
+			  pDst[x] = pSrc0[x] - (pSrc1[x] >> iPUResiPredShift[2]);
+		  }
+	  }
+	  pSrc0 += iSrc0Stride;
+	  pSrc1 += iSrc1Stride;
+	  pDst  += iDstStride;
+  }
+
+#else
   for ( y = uiPartSize-1; y >= 0; y-- )
   {
@@ -562,7 +766,12 @@
     pDst  += iDstStride;
   }
-}
-
+#endif
+}
+
+#if LG_RESTRICTEDRESPRED_M24766
+Void TComYuv::subtractChroma(Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+#else
 Void TComYuv::subtractChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+#endif
 {
   Int x, y;
@@ -578,4 +787,63 @@
   Int  iSrc1Stride = pcYuvSrc1->getCStride();
   Int  iDstStride  = getCStride();
+#if LG_RESTRICTEDRESPRED_M24766
+  Int iXOffset, iYOffset;
+ 
+  getPUXYOffset(uhPartitionSize, uiPartSize, uiPartSize, iXOffset, iYOffset);
+
+  for ( y = uiPartSize-1; y >= iYOffset; y-- )
+  {
+	  if(iPUResiPredShift[3] >= 0)
+	  {
+		  for ( x = uiPartSize-1; x >= iXOffset; x-- )
+		  {
+			  pDstU[x] = pSrcU0[x] - (pSrcU1[x]>>iPUResiPredShift[3]);
+			  pDstV[x] = pSrcV0[x] - (pSrcV1[x]>>iPUResiPredShift[3]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[2] >= 0)
+	  {
+		  for ( x = iXOffset-1; x >= 0; x-- )
+		  {
+			  pDstU[x] = pSrcU0[x] - (pSrcU1[x]>>iPUResiPredShift[2]);
+			  pDstV[x] = pSrcV0[x] - (pSrcV1[x]>>iPUResiPredShift[2]);
+		  }
+	  }
+	  pSrcU0 += iSrc0Stride;
+	  pSrcU1 += iSrc1Stride;
+	  pSrcV0 += iSrc0Stride;
+	  pSrcV1 += iSrc1Stride;
+	  pDstU  += iDstStride;
+	  pDstV  += iDstStride;
+  }
+
+  for ( y = iYOffset-1; y >= 0; y-- )
+  {
+	  if(iPUResiPredShift[1] >= 0)
+	  {
+		  for ( x = uiPartSize-1; x >= iXOffset; x-- )
+		  {
+			  pDstU[x] = pSrcU0[x] - (pSrcU1[x]>>iPUResiPredShift[1]);
+			  pDstV[x] = pSrcV0[x] - (pSrcV1[x]>>iPUResiPredShift[1]);
+		  }
+	  }
+
+	  if(iPUResiPredShift[0] >= 0)
+	  {
+		  for ( x = iXOffset-1; x >= 0; x-- )
+		  {
+			  pDstU[x] = pSrcU0[x] - (pSrcU1[x]>>iPUResiPredShift[0]);
+			  pDstV[x] = pSrcV0[x] - (pSrcV1[x]>>iPUResiPredShift[0]);
+		  }
+	  }
+	  pSrcU0 += iSrc0Stride;
+	  pSrcU1 += iSrc1Stride;
+	  pSrcV0 += iSrc0Stride;
+	  pSrcV1 += iSrc1Stride;
+	  pDstU  += iDstStride;
+	  pDstV  += iDstStride;
+  }
+#else
   for ( y = uiPartSize-1; y >= 0; y-- )
   {
@@ -592,4 +860,5 @@
     pDstV  += iDstStride;
   }
+#endif
 }
 
Index: /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComYuv.h	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibCommon/TComYuv.h	(revision 62)
@@ -146,9 +146,14 @@
   Void    addClipPartLuma   ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize ); //GT
 
-  
+#if LG_RESTRICTEDRESPRED_M24766
   //  pcYuvSrc0 - pcYuvSrc1 -> m_apiBuf
+  Void    subtract          (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
+  Void    subtractLuma      (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
+  Void    subtractChroma    (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
+#else
   Void    subtract          ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
   Void    subtractLuma      ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
   Void    subtractChroma    ( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize );
+#endif
   
   //  (pcYuvSrc0 + pcYuvSrc1)/2 for YUV partition
@@ -161,8 +166,14 @@
   //   Remove High frequency
   Void    removeHighFreq    ( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight );
-  
+#if LG_RESTRICTEDRESPRED_M24766
+  void	  getPUXYOffset     (PartSize uhPartitionSize, Int iWidth, Int iHeight, Int &iXOffset, Int &iYOffset);
+  Void    add               (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract = false );
+  Void    addLuma           (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
+  Void    addChroma         (Int *iPUResiPredShift, PartSize uhPartitionSize, TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
+#else
   Void    add               ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract = false );
   Void    addLuma           ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
   Void    addChroma         ( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract );
+#endif
 
   Void    clip              ( Int iWidth, Int iHeight );
Index: /branches/HTM-3.0-LG/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibCommon/TypeDef.h	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibCommon/TypeDef.h	(revision 62)
@@ -68,5 +68,9 @@
 
 
-
+#if HHI_INTER_VIEW_RESIDUAL_PRED
+#define LG_RESTRICTEDRESPRED_M24766     1   // restricted inter-view residual prediction
+#else
+#define LG_RESTRICTEDRESPRED_M24766     0
+#endif
 
 
Index: /branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecCu.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecCu.cpp	(revision 62)
@@ -638,5 +638,11 @@
     Bool bOK = pcCU->getResidualSamples( 0, m_ppcYuvResPred[uiDepth] );
     AOF( bOK );
+#if LG_RESTRICTEDRESPRED_M24766
+	Int iPUResiPredShift[4];
+	pcCU->getPUResiPredShift(iPUResiPredShift, 0);
+	m_ppcYuvReco[uiDepth]->add(iPUResiPredShift, pcCU->getPartitionSize(0), m_ppcYuvResPred[uiDepth], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
+#else
     m_ppcYuvReco[uiDepth]->add( m_ppcYuvResPred[uiDepth], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
+#endif
   }
 #endif
Index: /branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 62)
@@ -104,4 +104,9 @@
   if( bResPredAvailable )
   {
+#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
     m_pcEntropyDecoderIf->parseResPredFlag( pcCU, bResPredFlag, uiAbsPartIdx, uiDepth );
   }
Index: /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncCu.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncCu.cpp	(revision 62)
@@ -1903,4 +1903,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 +1909,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 +1931,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: /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 62)
@@ -471,5 +471,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: /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 62)
@@ -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
-      xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost );
+#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
   {
-  rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
+#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 );
-    rpcYuvRec->add( rpcYuvResPrd,   uiWidth, uiHeight );
-    rpcYuvRec->add( rpcYuvResiBest, uiWidth, uiHeight );
+#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: /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncSearch.h	(revision 61)
+++ /branches/HTM-3.0-LG/source/Lib/TLibEncoder/TEncSearch.h	(revision 62)
@@ -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,
