Index: trunk/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 56)
+++ trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 77)
@@ -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,4 +676,11 @@
 }
 
+#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 )
 {
@@ -540,6 +688,11 @@
   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
 }
 
