Index: trunk/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 21)
+++ trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     TComYuv.cpp
     \brief    general YUV buffer class
@@ -46,4 +44,8 @@
 #include "CommonDef.h"
 #include "TComYuv.h"
+#include "TComInterpolationFilter.h"
+
+//! \ingroup TLibCommon
+//! \{
 
 TComYuv::TComYuv()
@@ -56,24 +58,4 @@
 TComYuv::~TComYuv()
 {
-}
-
-Void TComYuv::printout()
-{
-  Int  x, y;
-  
-  Pel* pSrc = getLumaAddr(  );
-  Int  iStride = getStride();
-  
-  
-  printf("\nY ...");
-  for ( y = 0; y < iStride; y++ )
-  {
-    printf ("\n");
-    for ( x = 0; x < iStride; x++ )
-    {
-      printf ("%d ", pSrc[x]);
-    }
-    pSrc += iStride;
-  }
 }
 
@@ -306,5 +288,5 @@
 }
 #endif
-    
+
 Void TComYuv::copyPartToPartYuv   ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight )
 {
@@ -320,5 +302,5 @@
   Pel* pSrc   = getLumaAddr(uiPartIdx);
   Pel* pDst   = pcYuvDst->getLumaAddr() + uiBlkY * pcYuvDst->getStride() + uiBlkX;
-  
+
   if( pSrc == pDst )
   {
@@ -327,5 +309,5 @@
     return ;
   }
-  
+
   UInt  iSrcStride = getStride();
   UInt  iDstStride = pcYuvDst->getStride();
@@ -402,5 +384,5 @@
     for ( x = uiPartSize-1; x >= 0; x-- )
     {
-      pDst[x] = xClip( pSrc0[x] + pSrc1[x] );      
+      pDst[x] = Clip( pSrc0[x] + pSrc1[x] );      
     }
     pSrc0 += iSrc0Stride;
@@ -410,5 +392,6 @@
 }
 
-Void 
+
+Void
 TComYuv::add( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
 {
@@ -417,5 +400,5 @@
 }
 
-Void 
+Void
 TComYuv::addLuma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
 {
@@ -434,5 +417,5 @@
 }
 
-Void 
+Void
 TComYuv::addChroma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
 {
@@ -455,5 +438,5 @@
 }
 
-Void 
+Void
 TComYuv::clip( Int iWidth, Int iHeight )
 {
@@ -462,5 +445,5 @@
 }
 
-Void 
+Void
 TComYuv::clipLuma( Int iWidth, Int iHeight )
 {
@@ -476,5 +459,5 @@
 }
 
-Void 
+Void
 TComYuv::clipChroma( Int iWidth, Int iHeight )
 {
@@ -492,5 +475,4 @@
 }
 
-
 Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
 {
@@ -514,5 +496,5 @@
     for ( x = uiPartSize-1; x >= 0; x-- )
     {
-      pDst[x] = xClip( pSrc0[x] + pSrc1[x] );
+      pDst[x] = Clip( pSrc0[x] + pSrc1[x] );
     }
     pSrc0 += iSrc0Stride;
@@ -540,6 +522,6 @@
     for ( x = uiPartSize-1; x >= 0; x-- )
     {
-      pDstU[x] = xClip( pSrcU0[x] + pSrcU1[x] );
-      pDstV[x] = xClip( pSrcV0[x] + pSrcV1[x] );
+      pDstU[x] = Clip( pSrcU0[x] + pSrcU1[x] );
+      pDstV[x] = Clip( pSrcV0[x] + pSrcV1[x] );
     }
     
@@ -612,7 +594,5 @@
 }
 
-#ifdef ROUNDING_CONTROL_BIPRED
-
-Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, Bool bRound )
+Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight )
 {
   Int x, y;
@@ -633,18 +613,15 @@
   UInt  iSrc1Stride = pcYuvSrc1->getStride();
   UInt  iDstStride  = getStride();
-
-#if HIGH_ACCURACY_BI
-  Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement);
-  Int offset = (1<<(shiftNum - 1));
-  
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // note: luma min width is 4
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--;
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
+  Int shiftNum = IF_INTERNAL_PREC + 1 - ( g_uiBitDepth + g_uiBitIncrement );
+  Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS;
+  
+  for ( y = 0; y < iHeight; y++ )
+  {
+    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 );
     }
     pSrcY0 += iSrc0Stride;
@@ -678,158 +655,4 @@
     pDstV  += iDstStride;
   }
-
-#else
-
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // note: luma min width is 4
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
-    }
-    pSrcY0 += iSrc0Stride;
-    pSrcY1 += iSrc1Stride;
-    pDstY  += iDstStride;
-  }
-  
-  iSrc0Stride = pcYuvSrc0->getCStride();
-  iSrc1Stride = pcYuvSrc1->getCStride();
-  iDstStride  = getCStride();
-  
-  iWidth  >>=1;
-  iHeight >>=1;
-  
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // note: chroma min width is 2
-      pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1;
-      pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--;
-      pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1;
-      pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--;
-    }
-    
-    pSrcU0 += iSrc0Stride;
-    pSrcU1 += iSrc1Stride;
-    pSrcV0 += iSrc0Stride;
-    pSrcV1 += iSrc1Stride;
-    pDstU  += iDstStride;
-    pDstV  += iDstStride;
-  }
-#endif
-}
-
-#endif
-
-Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight )
-{
-  Int x, y;
-  
-  Pel* pSrcY0  = pcYuvSrc0->getLumaAddr( iPartUnitIdx );
-  Pel* pSrcU0  = pcYuvSrc0->getCbAddr  ( iPartUnitIdx );
-  Pel* pSrcV0  = pcYuvSrc0->getCrAddr  ( iPartUnitIdx );
-  
-  Pel* pSrcY1  = pcYuvSrc1->getLumaAddr( iPartUnitIdx );
-  Pel* pSrcU1  = pcYuvSrc1->getCbAddr  ( iPartUnitIdx );
-  Pel* pSrcV1  = pcYuvSrc1->getCrAddr  ( iPartUnitIdx );
-  
-  Pel* pDstY   = getLumaAddr( iPartUnitIdx );
-  Pel* pDstU   = getCbAddr  ( iPartUnitIdx );
-  Pel* pDstV   = getCrAddr  ( iPartUnitIdx );
-  
-  UInt  iSrc0Stride = pcYuvSrc0->getStride();
-  UInt  iSrc1Stride = pcYuvSrc1->getStride();
-  UInt  iDstStride  = getStride();
-#if HIGH_ACCURACY_BI
-  Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement);
-  Int offset = (1<<(shiftNum - 1));
-  
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // note: luma min width is 4
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--;
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
-      pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
-    }
-    pSrcY0 += iSrc0Stride;
-    pSrcY1 += iSrc1Stride;
-    pDstY  += iDstStride;
-  }
-  
-  iSrc0Stride = pcYuvSrc0->getCStride();
-  iSrc1Stride = pcYuvSrc1->getCStride();
-  iDstStride  = getCStride();
-  
-  iWidth  >>=1;
-  iHeight >>=1;
-  
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // 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--;
-    }
-    
-    pSrcU0 += iSrc0Stride;
-    pSrcU1 += iSrc1Stride;
-    pSrcV0 += iSrc0Stride;
-    pSrcV1 += iSrc1Stride;
-    pDstU  += iDstStride;
-    pDstV  += iDstStride;
-  }
-
-#else  
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // note: luma min width is 4
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
-      pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
-    }
-    pSrcY0 += iSrc0Stride;
-    pSrcY1 += iSrc1Stride;
-    pDstY  += iDstStride;
-  }
-  
-  iSrc0Stride = pcYuvSrc0->getCStride();
-  iSrc1Stride = pcYuvSrc1->getCStride();
-  iDstStride  = getCStride();
-  
-  iWidth  >>=1;
-  iHeight >>=1;
-  
-  for ( y = iHeight-1; y >= 0; y-- )
-  {
-    for ( x = iWidth-1; x >= 0; )
-    {
-      // note: chroma min width is 2
-      pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1;
-      pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--;
-      pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1;
-      pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--;
-    }
-    
-    pSrcU0 += iSrc0Stride;
-    pSrcU1 += iSrc1Stride;
-    pSrcV0 += iSrc0Stride;
-    pSrcV1 += iSrc1Stride;
-    pDstU  += iDstStride;
-    pDstV  += iDstStride;
-  }
-#endif
 }
 
@@ -844,5 +667,5 @@
   Pel* pSrcY1  = pcYuvSrc1->getLumaAddr( iPartUnitIdx );
   Pel* pDstY   = getLumaAddr() + uiBlkY * getStride() + uiBlkX;
-  
+
   UInt  iSrc0Stride = pcYuvSrc0->getStride();
   UInt  iSrc1Stride = pcYuvSrc1->getStride();
@@ -862,16 +685,15 @@
 #endif
 
-
-Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiWidht, UInt uiHeight )
+Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight )
 {
   Int x, y;
   
-  Pel* pSrc  = pcYuvSrc->getLumaAddr();
-  Pel* pSrcU = pcYuvSrc->getCbAddr();
-  Pel* pSrcV = pcYuvSrc->getCrAddr();
-  
-  Pel* pDst  = m_apiBufY;
-  Pel* pDstU = m_apiBufU;
-  Pel* pDstV = m_apiBufV;
+  Pel* pSrc  = pcYuvSrc->getLumaAddr(uiPartIdx);
+  Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx);
+  Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx);
+  
+  Pel* pDst  = getLumaAddr(uiPartIdx);
+  Pel* pDstU = getCbAddr(uiPartIdx);
+  Pel* pDstV = getCrAddr(uiPartIdx);
   
   Int  iSrcStride = pcYuvSrc->getStride();
@@ -882,5 +704,9 @@
     for ( x = uiWidht-1; x >= 0; x-- )
     {
-      pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] );
+#if DISABLING_CLIP_FOR_BIPREDME
+      pDst[x ] = (pDst[x ]<<1) - pSrc[x ] ;
+#else
+      pDst[x ] = Clip( (pDst[x ]<<1) - pSrc[x ] );
+#endif
     }
     pSrc += iSrcStride;
@@ -898,6 +724,11 @@
     for ( x = uiWidht-1; x >= 0; x-- )
     {
-      pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] );
-      pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] );
+#if DISABLING_CLIP_FOR_BIPREDME
+      pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ] ;
+      pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ] ;
+#else
+      pDstU[x ] = Clip( (pDstU[x ]<<1) - pSrcU[x ] );
+      pDstV[x ] = Clip( (pDstV[x ]<<1) - pSrcV[x ] );
+#endif
     }
     pSrcU += iSrcStride;
@@ -907,105 +738,3 @@
   }
 }
-
-Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight )
-{
-  Int x, y;
-  
-  Pel* pSrc  = pcYuvSrc->getLumaAddr(uiPartIdx);
-  Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx);
-  Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx);
-  
-  Pel* pDst  = getLumaAddr(uiPartIdx);
-  Pel* pDstU = getCbAddr(uiPartIdx);
-  Pel* pDstV = getCrAddr(uiPartIdx);
-  
-  Int  iSrcStride = pcYuvSrc->getStride();
-  Int  iDstStride = getStride();
-  
-  for ( y = uiHeight-1; y >= 0; y-- )
-  {
-    for ( x = uiWidht-1; x >= 0; x-- )
-    {
-      pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] );
-    }
-    pSrc += iSrcStride;
-    pDst += iDstStride;
-  }
-  
-  iSrcStride = pcYuvSrc->getCStride();
-  iDstStride = getCStride();
-  
-  uiHeight >>= 1;
-  uiWidht  >>= 1;
-  
-  for ( y = uiHeight-1; y >= 0; y-- )
-  {
-    for ( x = uiWidht-1; x >= 0; x-- )
-    {
-      pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] );
-      pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] );
-    }
-    pSrcU += iSrcStride;
-    pSrcV += iSrcStride;
-    pDstU += iDstStride;
-    pDstV += iDstStride;
-  }
-}
-
-
-Pel* TComYuv::getLumaAddr( UInt uiPartUnitIdx )
-{
-  UInt iBlkX;
-  UInt iBlkY;
-  iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]];
-  iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]];
-  
-  return m_apiBufY + iBlkY*getStride() + iBlkX;
-}
-
-Pel* TComYuv::getCbAddr( UInt uiPartUnitIdx )
-{
-  UInt iBlkX;
-  UInt iBlkY;
-  iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
-  iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
-  
-  return m_apiBufU + iBlkY*getCStride() + iBlkX;
-}
-
-Pel* TComYuv::getCrAddr( UInt uiPartUnitIdx )
-{
-  UInt iBlkX;
-  UInt iBlkY;
-  iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
-  iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
-  
-  return m_apiBufV + iBlkY*getCStride() + iBlkX;
-}
-
-Pel* TComYuv::getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize )
-{
-  UInt uiNumTrInWidth = m_iWidth / iBlkSize;
-  UInt   iBlkX   = iTransUnitIdx % uiNumTrInWidth;
-  UInt   iBlkY   = iTransUnitIdx / uiNumTrInWidth;
-  
-  return m_apiBufY + (iBlkX + iBlkY * getStride()) * iBlkSize;
-}
-
-Pel* TComYuv::getCbAddr( UInt iTransUnitIdx, UInt iBlkSize )
-{
-  UInt uiNumTrInWidth = m_iCWidth / iBlkSize;
-  UInt   iBlkX   = iTransUnitIdx % uiNumTrInWidth;
-  UInt   iBlkY   = iTransUnitIdx / uiNumTrInWidth;
-  
-  return m_apiBufU + (iBlkX + iBlkY * getCStride()) * iBlkSize;
-}
-
-Pel* TComYuv::getCrAddr( UInt iTransUnitIdx, UInt iBlkSize )
-{
-  UInt uiNumTrInWidth = m_iCWidth / iBlkSize;
-  UInt   iBlkX   = iTransUnitIdx % uiNumTrInWidth;
-  UInt   iBlkY   = iTransUnitIdx / uiNumTrInWidth;
-  
-  return m_apiBufV + (iBlkX + iBlkY * getCStride()) * iBlkSize;
-}
+//! \}
