Index: trunk/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 443)
+++ trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 608)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -282,11 +282,4 @@
 }
 
-#if DEPTH_MAP_GENERATION
-Void TComYuv::copyPartToPartYuvPdm   ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY )
-{
-  copyPartToPartLumaPdm   (pcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY );
-}
-#endif
-
 Void TComYuv::copyPartToPartYuv   ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight )
 {
@@ -294,30 +287,4 @@
   copyPartToPartChroma (pcYuvDst, uiPartIdx, iWidth>>1, iHeight>>1 );
 }
-
-#if DEPTH_MAP_GENERATION
-Void TComYuv::copyPartToPartLumaPdm  ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY )
-{
-  UInt uiBlkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiPartIdx ] ] >> uiSubSampExpX;
-  UInt uiBlkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiPartIdx ] ] >> uiSubSampExpY;
-  Pel* pSrc   = getLumaAddr(uiPartIdx);
-  Pel* pDst   = pcYuvDst->getLumaAddr() + uiBlkY * pcYuvDst->getStride() + uiBlkX;
-
-  if( pSrc == pDst )
-  {
-    //th not a good idea
-    //th best would be to fix the caller 
-    return ;
-  }
-
-  UInt  iSrcStride = getStride();
-  UInt  iDstStride = pcYuvDst->getStride();
-  for ( UInt y = iHeight; y != 0; y-- )
-  {
-    ::memcpy( pDst, pSrc, iWidth * sizeof(Pel) );
-    pSrc += iSrcStride;
-    pDst += iDstStride;
-  }
-}
-#endif
 
 Void TComYuv::copyPartToPartLuma  ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight )
@@ -369,12 +336,81 @@
 }
 
-Void TComYuv::addClipPartLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
-{
-  Int x, y;
-
-  Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx);
-  Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx);
-  Pel* pDst  = getLumaAddr( uiTrUnitIdx);
-
+Void TComYuv::copyPartToPartChroma( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight, UInt chromaId)
+{
+  if(chromaId == 0)
+  {
+    Pel*  pSrcU =           getCbAddr(uiPartIdx);
+    Pel*  pDstU = pcYuvDst->getCbAddr(uiPartIdx);
+    if( pSrcU == pDstU)
+    {
+      return ;
+    }
+    UInt   iSrcStride = getCStride();
+    UInt   iDstStride = pcYuvDst->getCStride();
+    for ( UInt y = iHeight; y != 0; y-- )
+    {
+      ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) );
+      pSrcU += iSrcStride;
+      pDstU += iDstStride;
+    }
+  }
+  else if (chromaId == 1)
+  {
+    Pel*  pSrcV =           getCrAddr(uiPartIdx);
+    Pel*  pDstV = pcYuvDst->getCrAddr(uiPartIdx);
+    if( pSrcV == pDstV)
+    {
+      return;
+    }
+    UInt   iSrcStride = getCStride();
+    UInt   iDstStride = pcYuvDst->getCStride();
+    for ( UInt y = iHeight; y != 0; y-- )
+    { 
+      ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) );
+      pSrcV += iSrcStride;
+      pDstV += iDstStride;
+    }
+  }
+  else
+  {
+    Pel*  pSrcU =           getCbAddr(uiPartIdx);
+    Pel*  pSrcV =           getCrAddr(uiPartIdx);
+    Pel*  pDstU = pcYuvDst->getCbAddr(uiPartIdx);
+    Pel*  pDstV = pcYuvDst->getCrAddr(uiPartIdx);
+    
+    if( pSrcU == pDstU && pSrcV == pDstV)
+    {
+      //th not a good idea
+      //th best would be to fix the caller 
+      return ;
+    }
+    UInt   iSrcStride = getCStride();
+    UInt   iDstStride = pcYuvDst->getCStride();
+    for ( UInt y = iHeight; y != 0; y-- )
+    {
+      ::memcpy( pDstU, pSrcU, iWidth * sizeof(Pel) );
+      ::memcpy( pDstV, pSrcV, iWidth * sizeof(Pel) );
+      pSrcU += iSrcStride;
+      pSrcV += iSrcStride;
+      pDstU += iDstStride;
+      pDstV += iDstStride;
+    }
+  }
+}
+
+Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+{
+  addClipLuma   ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize     );
+  addClipChroma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1  );
+}
+
+Void TComYuv::addClipLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+{
+  Int x, y;
+  
+  Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize );
+  Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize );
+  Pel* pDst  = getLumaAddr( uiTrUnitIdx, uiPartSize );
+  
   UInt iSrc0Stride = pcYuvSrc0->getStride();
   UInt iSrc1Stride = pcYuvSrc1->getStride();
@@ -384,119 +420,5 @@
     for ( x = uiPartSize-1; x >= 0; x-- )
     {
-      pDst[x] = Clip( pSrc0[x] + pSrc1[x] );      
-    }
-    pSrc0 += iSrc0Stride;
-    pSrc1 += iSrc1Stride;
-    pDst  += iDstStride;
-  }
-}
-
-Void
-TComYuv::add( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
-{
-  addLuma   ( pcYuvAdd, iWidth,    iHeight,    bSubtract );
-  addChroma ( pcYuvAdd, iWidth>>1, iHeight>>1, bSubtract );
-}
-
-
-Void
-TComYuv::addLuma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
-{
-  Int   iScale      = ( bSubtract ? -1 : 1 );
-  Int   iAddStride  = pcYuvAdd->getStride();
-  Int   iDstStride  = getStride();
-  Pel*  pAddSamples = pcYuvAdd->getLumaAddr();
-  Pel*  pDstSamples = getLumaAddr();
-
-  for( Int iY = 0; iY < iHeight; iY++, pDstSamples += iDstStride, pAddSamples += iAddStride )
-  {
-    for( Int iX = 0; iX < iWidth; iX++ )
-    {
-      pDstSamples[iX] += iScale * pAddSamples[iX];
-    }
-  }
-}
-
-Void
-TComYuv::addChroma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
-{
-  Int   iScale        = ( bSubtract ? -1 : 1 );
-  Int   iAddStride    = pcYuvAdd->getCStride();
-  Int   iDstStride    = getCStride();
-  Pel*  pAddSamplesCb = pcYuvAdd->getCbAddr();
-  Pel*  pAddSamplesCr = pcYuvAdd->getCrAddr();
-  Pel*  pDstSamplesCb = getCbAddr();
-  Pel*  pDstSamplesCr = getCrAddr();
-
-  for( Int iY = 0; iY < iHeight; iY++, pDstSamplesCb += iDstStride, pAddSamplesCb += iAddStride,
-                                       pDstSamplesCr += iDstStride, pAddSamplesCr += iAddStride  )
-  {
-    for( Int iX = 0; iX < iWidth; iX++ )
-    {
-      pDstSamplesCb[iX] += iScale * pAddSamplesCb[iX];
-      pDstSamplesCr[iX] += iScale * pAddSamplesCr[iX];
-    }
-  }
-}
-
-Void
-TComYuv::clip( Int iWidth, Int iHeight )
-{
-  clipLuma   ( iWidth,    iHeight    );
-  clipChroma ( iWidth>>1, iHeight>>1 );
-}
-
-Void
-TComYuv::clipLuma( Int iWidth, Int iHeight )
-{
-  Int   iStride  = getStride();
-  Pel*  pSamples = getLumaAddr();
-  for( Int iY = 0; iY < iHeight; iY++, pSamples += iStride )
-  {
-    for( Int iX = 0; iX < iWidth; iX++ )
-    {
-      pSamples[iX] = xClip( pSamples[iX] );
-    }
-  }
-}
-
-Void
-TComYuv::clipChroma( Int iWidth, Int iHeight )
-{
-  Int   iStride    = getCStride();
-  Pel*  pSamplesCb = getCbAddr();
-  Pel*  pSamplesCr = getCrAddr();
-  for( Int iY = 0; iY < iHeight; iY++, pSamplesCb += iStride, pSamplesCr += iStride )
-  {
-    for( Int iX = 0; iX < iWidth; iX++ )
-    {
-      pSamplesCb[iX] = xClip( pSamplesCb[iX] );
-      pSamplesCr[iX] = xClip( pSamplesCr[iX] );
-    }
-  }
-}
-
-Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
-{
-  addClipLuma   ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize     );
-  addClipChroma ( pcYuvSrc0, pcYuvSrc1, uiTrUnitIdx, uiPartSize>>1  );
-}
-
-Void TComYuv::addClipLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
-{
-  Int x, y;
-  
-  Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx, uiPartSize );
-  Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx, uiPartSize );
-  Pel* pDst  = getLumaAddr( uiTrUnitIdx, uiPartSize );
-  
-  UInt iSrc0Stride = pcYuvSrc0->getStride();
-  UInt iSrc1Stride = pcYuvSrc1->getStride();
-  UInt iDstStride  = getStride();
-  for ( y = uiPartSize-1; y >= 0; y-- )
-  {
-    for ( x = uiPartSize-1; x >= 0; x-- )
-    {
-      pDst[x] = Clip( pSrc0[x] + pSrc1[x] );
+      pDst[x] = ClipY( pSrc0[x] + pSrc1[x] );
     }
     pSrc0 += iSrc0Stride;
@@ -524,6 +446,6 @@
     for ( x = uiPartSize-1; x >= 0; x-- )
     {
-      pDstU[x] = Clip( pSrcU0[x] + pSrcU1[x] );
-      pDstV[x] = Clip( pSrcV0[x] + pSrcV1[x] );
+      pDstU[x] = ClipC( pSrcU0[x] + pSrcU1[x] );
+      pDstV[x] = ClipC( pSrcV0[x] + pSrcV1[x] );
     }
     
@@ -554,5 +476,4 @@
   Int  iSrc1Stride = pcYuvSrc1->getStride();
   Int  iDstStride  = getStride();
-
   for ( y = uiPartSize-1; y >= 0; y-- )
   {
@@ -616,5 +537,5 @@
   UInt  iSrc1Stride = pcYuvSrc1->getStride();
   UInt  iDstStride  = getStride();
-  Int shiftNum = IF_INTERNAL_PREC + 1 - ( g_uiBitDepth + g_uiBitIncrement );
+  Int shiftNum = IF_INTERNAL_PREC + 1 - g_bitDepthY;
   Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS;
   
@@ -623,8 +544,8 @@
     for ( x = 0; x < iWidth; x += 4 )
     {
-      pDstY[ x + 0 ] = Clip( ( pSrcY0[ x + 0 ] + pSrcY1[ x + 0 ] + offset ) >> shiftNum );
-      pDstY[ x + 1 ] = Clip( ( pSrcY0[ x + 1 ] + pSrcY1[ x + 1 ] + offset ) >> shiftNum );
-      pDstY[ x + 2 ] = Clip( ( pSrcY0[ x + 2 ] + pSrcY1[ x + 2 ] + offset ) >> shiftNum );
-      pDstY[ x + 3 ] = Clip( ( pSrcY0[ x + 3 ] + pSrcY1[ x + 3 ] + offset ) >> shiftNum );
+      pDstY[ x + 0 ] = ClipY( ( pSrcY0[ x + 0 ] + pSrcY1[ x + 0 ] + offset ) >> shiftNum );
+      pDstY[ x + 1 ] = ClipY( ( pSrcY0[ x + 1 ] + pSrcY1[ x + 1 ] + offset ) >> shiftNum );
+      pDstY[ x + 2 ] = ClipY( ( pSrcY0[ x + 2 ] + pSrcY1[ x + 2 ] + offset ) >> shiftNum );
+      pDstY[ x + 3 ] = ClipY( ( pSrcY0[ x + 3 ] + pSrcY1[ x + 3 ] + offset ) >> shiftNum );
     }
     pSrcY0 += iSrc0Stride;
@@ -633,4 +554,7 @@
   }
   
+  shiftNum = IF_INTERNAL_PREC + 1 - g_bitDepthC;
+  offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS;
+
   iSrc0Stride = pcYuvSrc0->getCStride();
   iSrc1Stride = pcYuvSrc1->getCStride();
@@ -645,8 +569,8 @@
     {
       // note: chroma min width is 2
-      pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);
-      pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;
-      pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);
-      pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;
+      pDstU[x] = ClipC((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);
+      pDstV[x] = ClipC((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;
+      pDstU[x] = ClipC((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);
+      pDstV[x] = ClipC((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;
     }
     
@@ -660,32 +584,4 @@
 }
 
-#if DEPTH_MAP_GENERATION
-Void TComYuv::addAvgPdm( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY )
-{
-  Int x, y;
-
-  UInt uiBlkX  = g_auiRasterToPelX[ g_auiZscanToRaster[ iPartUnitIdx ] ] >> uiSubSampExpX;
-  UInt uiBlkY  = g_auiRasterToPelY[ g_auiZscanToRaster[ iPartUnitIdx ] ] >> uiSubSampExpY;
-  Pel* pSrcY0  = pcYuvSrc0->getLumaAddr( iPartUnitIdx );
-  Pel* pSrcY1  = pcYuvSrc1->getLumaAddr( iPartUnitIdx );
-  Pel* pDstY   = getLumaAddr() + uiBlkY * getStride() + uiBlkX;
-
-  UInt  iSrc0Stride = pcYuvSrc0->getStride();
-  UInt  iSrc1Stride = pcYuvSrc1->getStride();
-  UInt  iDstStride  = getStride();
-
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; x-- )
-    {
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1;
-    }
-    pSrcY0 += iSrc0Stride;
-    pSrcY1 += iSrc1Stride;
-    pDstY  += iDstStride;
-  }
-}
-#endif
-
 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight )
 {
@@ -741,6 +637,31 @@
   }
 }
-#if QC_ARP_D0177
-Void TComYuv::addARP(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip )
+
+#if H_3D
+Void TComYuv::addClipPartLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
+{
+  Int x, y;
+
+  Pel* pSrc0 = pcYuvSrc0->getLumaAddr( uiTrUnitIdx);
+  Pel* pSrc1 = pcYuvSrc1->getLumaAddr( uiTrUnitIdx);
+  Pel* pDst  = getLumaAddr( uiTrUnitIdx);
+
+  UInt iSrc0Stride = pcYuvSrc0->getStride();
+  UInt iSrc1Stride = pcYuvSrc1->getStride();
+  UInt iDstStride  = getStride();
+  for ( y = uiPartSize-1; y >= 0; y-- )
+  {
+    for ( x = uiPartSize-1; x >= 0; x-- )
+    {
+      pDst[x] = ClipY( pSrc0[x] + pSrc1[x] );      
+    }
+    pSrc0 += iSrc0Stride;
+    pSrc1 += iSrc1Stride;
+    pDst  += iDstStride;
+  }
+}
+
+#if H_3D_ARP
+Void TComYuv::addARP( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip )
 {
   addARPLuma   ( pcYuvSrc0, pcYuvSrc1, uiAbsPartIdx, uiWidth   , uiHeight    , bClip );
@@ -748,5 +669,5 @@
 }
 
-Void TComYuv::addARPLuma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip )
+Void TComYuv::addARPLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip )
 {
   Int x, y;
@@ -765,5 +686,7 @@
       pDst[x] = pSrc0[x] + pSrc1[x];
       if( bClip )
-        pDst[x] = Clip( pDst[x] );
+      {
+        pDst[x] = ClipY( pDst[x] );
+      }
     }
     pSrc0 += iSrc0Stride;
@@ -773,5 +696,5 @@
 }
 
-Void TComYuv::addARPChroma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight , Bool bClip )
+Void TComYuv::addARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool bClip )
 {
   Int x, y;
@@ -795,6 +718,6 @@
       if( bClip )
       {
-        pDstU[x] = Clip( pDstU[x] );
-        pDstV[x] = Clip( pDstV[x] );
+        pDstU[x] = ClipC( pDstU[x] );
+        pDstV[x] = ClipC( pDstV[x] );
       }
     }
@@ -809,5 +732,5 @@
 }
 
-Void TComYuv::subtractARP(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight)
+Void TComYuv::subtractARP( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight )
 {
   subtractARPLuma  ( pcYuvSrc0, pcYuvSrc1,  uiAbsPartIdx, uiWidth    , uiHeight    );
@@ -815,5 +738,5 @@
 }
 
-Void TComYuv::subtractARPLuma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight)
+Void TComYuv::subtractARPLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight )
 {
   Int x, y;
@@ -838,5 +761,5 @@
 }
 
-Void TComYuv::subtractARPChroma(TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight)
+Void TComYuv::subtractARPChroma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiAbsPartIdx, UInt uiWidth , UInt uiHeight )
 {
   Int x, y;
@@ -874,5 +797,5 @@
 }
 
-Void TComYuv::xxMultiplyLine( Pel * pSrcDst , UInt uiWidth , UChar dW )
+Void TComYuv::xxMultiplyLine( Pel* pSrcDst , UInt uiWidth , UChar dW )
 {
   assert( dW == 2 );
@@ -907,3 +830,4 @@
 }
 #endif
+#endif
 //! \}
