Index: /branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp	(revision 1312)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp	(revision 1313)
@@ -68,8 +68,8 @@
   m_chromaFormatIDC = chromaFormatIDC;
 
-  for(Int ch=0; ch<MAX_NUM_COMPONENT; ch++)
+  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
   {
     // memory allocation
-    m_apiBuf[ch]  = (Pel*)xMalloc( Pel, getWidth(ComponentID(ch))*getHeight(ComponentID(ch)) );
+    m_apiBuf[comp]  = (Pel*)xMalloc( Pel, getWidth(ComponentID(comp))*getHeight(ComponentID(comp)) );
   }
 }
@@ -78,10 +78,10 @@
 {
   // memory free
-  for(Int ch=0; ch<MAX_NUM_COMPONENT; ch++)
-  {
-    if (m_apiBuf[ch]!=NULL)
-    {
-      xFree( m_apiBuf[ch] );
-      m_apiBuf[ch] = NULL;
+  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
+  {
+    if (m_apiBuf[comp]!=NULL)
+    {
+      xFree( m_apiBuf[comp] );
+      m_apiBuf[comp] = NULL;
     }
   }
@@ -90,9 +90,9 @@
 Void TComYuv::clear()
 {
-  for(Int ch=0; ch<MAX_NUM_COMPONENT; ch++)
-  {
-    if (m_apiBuf[ch]!=NULL)
-    {
-      ::memset( m_apiBuf[ch], 0, ( getWidth(ComponentID(ch)) * getHeight(ComponentID(ch))  )*sizeof(Pel) );
+  for(Int comp=0; comp<MAX_NUM_COMPONENT; comp++)
+  {
+    if (m_apiBuf[comp]!=NULL)
+    {
+      ::memset( m_apiBuf[comp], 0, ( getWidth(ComponentID(comp)) * getHeight(ComponentID(comp))  )*sizeof(Pel) );
     }
   }
@@ -104,20 +104,20 @@
 Void TComYuv::copyToPicYuv   ( TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const
 {
-  for(Int ch=0; ch<getNumberValidComponents(); ch++)
-  {
-    copyToPicComponent  ( ComponentID(ch), pcPicYuvDst, ctuRsAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx );
-  }
-}
-
-Void TComYuv::copyToPicComponent  ( const ComponentID ch, TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const
-{
-  const Int iWidth  = getWidth(ch) >>uiPartDepth;
-  const Int iHeight = getHeight(ch)>>uiPartDepth;
-
-  const Pel* pSrc     = getAddr(ch, uiPartIdx, iWidth);
-        Pel* pDst     = pcPicYuvDst->getAddr ( ch, ctuRsAddr, uiAbsZorderIdx );
-
-  const UInt  iSrcStride  = getStride(ch);
-  const UInt  iDstStride  = pcPicYuvDst->getStride(ch);
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    copyToPicComponent  ( ComponentID(comp), pcPicYuvDst, ctuRsAddr, uiAbsZorderIdx, uiPartDepth, uiPartIdx );
+  }
+}
+
+Void TComYuv::copyToPicComponent  ( const ComponentID compID, TComPicYuv* pcPicYuvDst, const UInt ctuRsAddr, const UInt uiAbsZorderIdx, const UInt uiPartDepth, const UInt uiPartIdx ) const
+{
+  const Int iWidth  = getWidth(compID) >>uiPartDepth;
+  const Int iHeight = getHeight(compID)>>uiPartDepth;
+
+  const Pel* pSrc     = getAddr(compID, uiPartIdx, iWidth);
+        Pel* pDst     = pcPicYuvDst->getAddr ( compID, ctuRsAddr, uiAbsZorderIdx );
+
+  const UInt  iSrcStride  = getStride(compID);
+  const UInt  iDstStride  = pcPicYuvDst->getStride(compID);
 
   for ( Int y = iHeight; y != 0; y-- )
@@ -134,19 +134,19 @@
 Void TComYuv::copyFromPicYuv   ( const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx )
 {
-  for(Int ch=0; ch<getNumberValidComponents(); ch++)
-  {
-    copyFromPicComponent  ( ComponentID(ch), pcPicYuvSrc, ctuRsAddr, uiAbsZorderIdx );
-  }
-}
-
-Void TComYuv::copyFromPicComponent  ( const ComponentID ch, const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx )
-{
-        Pel* pDst     = getAddr(ch);
-  const Pel* pSrc     = pcPicYuvSrc->getAddr ( ch, ctuRsAddr, uiAbsZorderIdx );
-
-  const UInt iDstStride  = getStride(ch);
-  const UInt iSrcStride  = pcPicYuvSrc->getStride(ch);
-  const Int  iWidth=getWidth(ch);
-  const Int  iHeight=getHeight(ch);
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    copyFromPicComponent  ( ComponentID(comp), pcPicYuvSrc, ctuRsAddr, uiAbsZorderIdx );
+  }
+}
+
+Void TComYuv::copyFromPicComponent  ( const ComponentID compID, const TComPicYuv* pcPicYuvSrc, const UInt ctuRsAddr, const UInt uiAbsZorderIdx )
+{
+        Pel* pDst     = getAddr(compID);
+  const Pel* pSrc     = pcPicYuvSrc->getAddr ( compID, ctuRsAddr, uiAbsZorderIdx );
+
+  const UInt iDstStride  = getStride(compID);
+  const UInt iSrcStride  = pcPicYuvSrc->getStride(compID);
+  const Int  iWidth=getWidth(compID);
+  const Int  iHeight=getHeight(compID);
 
   for (Int y = iHeight; y != 0; y-- )
@@ -163,19 +163,19 @@
 Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const
 {
-  for(Int ch=0; ch<getNumberValidComponents(); ch++)
-  {
-    copyToPartComponent  ( ComponentID(ch), pcYuvDst, uiDstPartIdx );
-  }
-}
-
-Void TComYuv::copyToPartComponent( const ComponentID ch, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const
-{
-  const Pel* pSrc     = getAddr(ch);
-        Pel* pDst     = pcYuvDst->getAddr( ch, uiDstPartIdx );
-
-  const UInt iSrcStride  = getStride(ch);
-  const UInt iDstStride  = pcYuvDst->getStride(ch);
-  const Int  iWidth=getWidth(ch);
-  const Int  iHeight=getHeight(ch);
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    copyToPartComponent  ( ComponentID(comp), pcYuvDst, uiDstPartIdx );
+  }
+}
+
+Void TComYuv::copyToPartComponent( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiDstPartIdx ) const
+{
+  const Pel* pSrc     = getAddr(compID);
+        Pel* pDst     = pcYuvDst->getAddr( compID, uiDstPartIdx );
+
+  const UInt iSrcStride  = getStride(compID);
+  const UInt iDstStride  = pcYuvDst->getStride(compID);
+  const Int  iWidth=getWidth(compID);
+  const Int  iHeight=getHeight(compID);
 
   for (Int y = iHeight; y != 0; y-- )
@@ -192,20 +192,20 @@
 Void TComYuv::copyPartToYuv( TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const
 {
-  for(Int ch=0; ch<getNumberValidComponents(); ch++)
-  {
-    copyPartToComponent  ( ComponentID(ch), pcYuvDst, uiSrcPartIdx );
-  }
-}
-
-Void TComYuv::copyPartToComponent( const ComponentID ch, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const
-{
-  const Pel* pSrc     = getAddr(ch, uiSrcPartIdx);
-        Pel* pDst     = pcYuvDst->getAddr(ch, 0 );
-
-  const UInt  iSrcStride  = getStride(ch);
-  const UInt  iDstStride  = pcYuvDst->getStride(ch);
-
-  const UInt uiHeight = pcYuvDst->getHeight(ch);
-  const UInt uiWidth = pcYuvDst->getWidth(ch);
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    copyPartToComponent  ( ComponentID(comp), pcYuvDst, uiSrcPartIdx );
+  }
+}
+
+Void TComYuv::copyPartToComponent( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiSrcPartIdx ) const
+{
+  const Pel* pSrc     = getAddr(compID, uiSrcPartIdx);
+        Pel* pDst     = pcYuvDst->getAddr(compID, 0 );
+
+  const UInt  iSrcStride  = getStride(compID);
+  const UInt  iDstStride  = pcYuvDst->getStride(compID);
+
+  const UInt uiHeight = pcYuvDst->getHeight(compID);
+  const UInt uiWidth = pcYuvDst->getWidth(compID);
 
   for ( UInt y = uiHeight; y != 0; y-- )
@@ -222,14 +222,14 @@
 Void TComYuv::copyPartToPartYuv   ( TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidth, const UInt iHeight ) const
 {
-  for(Int ch=0; ch<getNumberValidComponents(); ch++)
-  {
-    copyPartToPartComponent   (ComponentID(ch), pcYuvDst, uiPartIdx, iWidth>>getComponentScaleX(ComponentID(ch)), iHeight>>getComponentScaleY(ComponentID(ch)) );
-  }
-}
-
-Void TComYuv::copyPartToPartComponent  ( const ComponentID ch, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidthComponent, const UInt iHeightComponent ) const
-{
-  const Pel* pSrc =           getAddr(ch, uiPartIdx);
-        Pel* pDst = pcYuvDst->getAddr(ch, uiPartIdx);
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    copyPartToPartComponent   (ComponentID(comp), pcYuvDst, uiPartIdx, iWidth>>getComponentScaleX(ComponentID(comp)), iHeight>>getComponentScaleY(ComponentID(comp)) );
+  }
+}
+
+Void TComYuv::copyPartToPartComponent  ( const ComponentID compID, TComYuv* pcYuvDst, const UInt uiPartIdx, const UInt iWidthComponent, const UInt iHeightComponent ) const
+{
+  const Pel* pSrc =           getAddr(compID);
+        Pel* pDst = pcYuvDst->getAddr(compID, uiPartIdx);
   if( pSrc == pDst )
   {
@@ -239,6 +239,6 @@
   }
 
-  const UInt  iSrcStride = getStride(ch);
-  const UInt  iDstStride = pcYuvDst->getStride(ch);
+  const UInt  iSrcStride = getStride(compID);
+  const UInt  iDstStride = pcYuvDst->getStride(compID);
   for ( UInt y = iHeightComponent; y != 0; y-- )
   {
@@ -252,8 +252,8 @@
 
 
-Void TComYuv::copyPartToPartComponentMxN  ( const ComponentID ch, TComYuv* pcYuvDst, const TComRectangle &rect) const
-{
-  const Pel* pSrc =           getAddrPix( ch, rect.x0, rect.y0 );
-        Pel* pDst = pcYuvDst->getAddrPix( ch, rect.x0, rect.y0 );
+Void TComYuv::copyPartToPartComponentMxN  ( const ComponentID compID, TComYuv* pcYuvDst, const TComRectangle &rect) const
+{
+  const Pel* pSrc =           getAddrPix( compID, rect.x0, rect.y0 );
+        Pel* pDst = pcYuvDst->getAddrPix( compID, rect.x0, rect.y0 );
   if( pSrc == pDst )
   {
@@ -263,6 +263,6 @@
   }
 
-  const UInt  iSrcStride = getStride(ch);
-  const UInt  iDstStride = pcYuvDst->getStride(ch);
+  const UInt  iSrcStride = getStride(compID);
+  const UInt  iDstStride = pcYuvDst->getStride(compID);
   const UInt uiHeightComponent=rect.height;
   const UInt uiWidthComponent=rect.width;
@@ -280,20 +280,20 @@
 Void TComYuv::addClip( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize, const BitDepths &clipBitDepths )
 {
-  for(Int chan=0; chan<getNumberValidComponents(); chan++)
-  {
-    const ComponentID ch=ComponentID(chan);
-    const Int uiPartWidth =uiPartSize>>getComponentScaleX(ch);
-    const Int uiPartHeight=uiPartSize>>getComponentScaleY(ch);
-
-    const Pel* pSrc0 = pcYuvSrc0->getAddr(ch, uiTrUnitIdx, uiPartWidth );
-    const Pel* pSrc1 = pcYuvSrc1->getAddr(ch, uiTrUnitIdx, uiPartWidth );
-          Pel* pDst  = getAddr(ch, uiTrUnitIdx, uiPartWidth );
-
-    const UInt iSrc0Stride = pcYuvSrc0->getStride(ch);
-    const UInt iSrc1Stride = pcYuvSrc1->getStride(ch);
-    const UInt iDstStride  = getStride(ch);
-    const Int clipbd = clipBitDepths.recon[toChannelType(ch)];
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    const ComponentID compID=ComponentID(comp);
+    const Int uiPartWidth =uiPartSize>>getComponentScaleX(compID);
+    const Int uiPartHeight=uiPartSize>>getComponentScaleY(compID);
+
+    const Pel* pSrc0 = pcYuvSrc0->getAddr(compID, uiTrUnitIdx, uiPartWidth );
+    const Pel* pSrc1 = pcYuvSrc1->getAddr(compID, uiTrUnitIdx, uiPartWidth );
+          Pel* pDst  = getAddr(compID, uiTrUnitIdx, uiPartWidth );
+
+    const UInt iSrc0Stride = pcYuvSrc0->getStride(compID);
+    const UInt iSrc1Stride = pcYuvSrc1->getStride(compID);
+    const UInt iDstStride  = getStride(compID);
+    const Int clipbd = clipBitDepths.recon[toChannelType(compID)];
 #if O0043_BEST_EFFORT_DECODING
-    const Int bitDepthDelta = clipBitDepths.stream[toChannelType(ch)] - clipbd;
+    const Int bitDepthDelta = clipBitDepths.stream[toChannelType(compID)] - clipbd;
 #endif
 
@@ -320,17 +320,17 @@
 Void TComYuv::subtract( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt uiTrUnitIdx, const UInt uiPartSize )
 {
-  for(Int chan=0; chan<getNumberValidComponents(); chan++)
-  {
-    const ComponentID ch=ComponentID(chan);
-    const Int uiPartWidth =uiPartSize>>getComponentScaleX(ch);
-    const Int uiPartHeight=uiPartSize>>getComponentScaleY(ch);
-
-    const Pel* pSrc0 = pcYuvSrc0->getAddr( ch, uiTrUnitIdx, uiPartWidth );
-    const Pel* pSrc1 = pcYuvSrc1->getAddr( ch, uiTrUnitIdx, uiPartWidth );
-          Pel* pDst  = getAddr( ch, uiTrUnitIdx, uiPartWidth );
-
-    const Int  iSrc0Stride = pcYuvSrc0->getStride(ch);
-    const Int  iSrc1Stride = pcYuvSrc1->getStride(ch);
-    const Int  iDstStride  = getStride(ch);
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    const ComponentID compID=ComponentID(comp);
+    const Int uiPartWidth =uiPartSize>>getComponentScaleX(compID);
+    const Int uiPartHeight=uiPartSize>>getComponentScaleY(compID);
+
+    const Pel* pSrc0 = pcYuvSrc0->getAddr( compID, uiTrUnitIdx, uiPartWidth );
+    const Pel* pSrc1 = pcYuvSrc1->getAddr( compID, uiTrUnitIdx, uiPartWidth );
+          Pel* pDst  = getAddr( compID, uiTrUnitIdx, uiPartWidth );
+
+    const Int  iSrc0Stride = pcYuvSrc0->getStride(compID);
+    const Int  iSrc1Stride = pcYuvSrc1->getStride(compID);
+    const Int  iDstStride  = getStride(compID);
 
     for (Int y = uiPartHeight-1; y >= 0; y-- )
@@ -352,20 +352,20 @@
 Void TComYuv::addAvg( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt uiWidth, const UInt uiHeight, const BitDepths &clipBitDepths )
 {
-  for(Int chan=0; chan<getNumberValidComponents(); chan++)
-  {
-    const ComponentID ch=ComponentID(chan);
-    const Pel* pSrc0  = pcYuvSrc0->getAddr( ch, iPartUnitIdx );
-    const Pel* pSrc1  = pcYuvSrc1->getAddr( ch, iPartUnitIdx );
-    Pel* pDst   = getAddr( ch, iPartUnitIdx );
-
-    const UInt  iSrc0Stride = pcYuvSrc0->getStride(ch);
-    const UInt  iSrc1Stride = pcYuvSrc1->getStride(ch);
-    const UInt  iDstStride  = getStride(ch);
-    const Int   clipbd      = clipBitDepths.recon[toChannelType(ch)];
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    const ComponentID compID=ComponentID(comp);
+    const Pel* pSrc0  = pcYuvSrc0->getAddr( compID, iPartUnitIdx );
+    const Pel* pSrc1  = pcYuvSrc1->getAddr( compID, iPartUnitIdx );
+    Pel* pDst   = getAddr( compID, iPartUnitIdx );
+
+    const UInt  iSrc0Stride = pcYuvSrc0->getStride(compID);
+    const UInt  iSrc1Stride = pcYuvSrc1->getStride(compID);
+    const UInt  iDstStride  = getStride(compID);
+    const Int   clipbd      = clipBitDepths.recon[toChannelType(compID)];
     const Int   shiftNum    = std::max<Int>(2, (IF_INTERNAL_PREC - clipbd)) + 1;
     const Int   offset      = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS;
 
-    const Int   iWidth      = uiWidth  >> getComponentScaleX(ch);
-    const Int   iHeight     = uiHeight >> getComponentScaleY(ch);
+    const Int   iWidth      = uiWidth  >> getComponentScaleX(compID);
+    const Int   iHeight     = uiHeight >> getComponentScaleY(compID);
 
     if (iWidth&1)
@@ -407,20 +407,27 @@
 }
 
-Void TComYuv::removeHighFreq( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, UInt const uiHeight )
-{
-  for(Int chan=0; chan<getNumberValidComponents(); chan++)
-  {
-    const ComponentID ch=ComponentID(chan);
+Void TComYuv::removeHighFreq( const TComYuv* pcYuvSrc,
+                              const UInt uiPartIdx,
+                              const UInt uiWidth,
+                              const UInt uiHeight
 #if !DISABLING_CLIP_FOR_BIPREDME
-    const ChannelType chType=toChannelType(ch);
+                              ,const Int bitDepths[MAX_NUM_CHANNEL_TYPE]
 #endif
-
-    const Pel* pSrc  = pcYuvSrc->getAddr(ch, uiPartIdx);
-    Pel* pDst  = getAddr(ch, uiPartIdx);
-
-    const Int iSrcStride = pcYuvSrc->getStride(ch);
-    const Int iDstStride = getStride(ch);
-    const Int iWidth  = uiWidth >>getComponentScaleX(ch);
-    const Int iHeight = uiHeight>>getComponentScaleY(ch);
+                              )
+{
+  for(Int comp=0; comp<getNumberValidComponents(); comp++)
+  {
+    const ComponentID compID=ComponentID(comp);
+#if !DISABLING_CLIP_FOR_BIPREDME
+    const Int clipBd=bitDepths[toChannelType(compID)];
+#endif
+
+    const Pel* pSrc  = pcYuvSrc->getAddr(compID, uiPartIdx);
+    Pel* pDst  = getAddr(compID, uiPartIdx);
+
+    const Int iSrcStride = pcYuvSrc->getStride(compID);
+    const Int iDstStride = getStride(compID);
+    const Int iWidth  = uiWidth >>getComponentScaleX(compID);
+    const Int iHeight = uiHeight>>getComponentScaleY(compID);
 
     for ( Int y = iHeight-1; y >= 0; y-- )
@@ -431,5 +438,5 @@
         pDst[x ] = (2 * pDst[x]) - pSrc[x];
 #else
-        pDst[x ] = Clip((2 * pDst[x]) - pSrc[x], chType);
+        pDst[x ] = ClipBD((2 * pDst[x]) - pSrc[x], clipBd);
 #endif
       }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComYuv.h	(revision 1312)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComYuv.h	(revision 1313)
@@ -139,5 +139,9 @@
   Void         addAvg                     ( const TComYuv* pcYuvSrc0, const TComYuv* pcYuvSrc1, const UInt iPartUnitIdx, const UInt iWidth, const UInt iHeight, const BitDepths &clipBitDepths );
 
-  Void         removeHighFreq             ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight );
+  Void         removeHighFreq             ( const TComYuv* pcYuvSrc, const UInt uiPartIdx, const UInt uiWidth, const UInt uiHeight
+#if !DISABLING_CLIP_FOR_BIPREDME
+                                          , const Int bitDepths[MAX_NUM_CHANNEL_TYPE]
+#endif
+                                          );
 
   // ------------------------------------------------------------------------------------------------------------------
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1312)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1313)
@@ -3892,5 +3892,9 @@
     pcYuvOrg->copyPartToPartYuv( pcYuv, uiPartAddr, iRoiWidth, iRoiHeight );
 
-    pcYuv->removeHighFreq( pcYuvOther, uiPartAddr, iRoiWidth, iRoiHeight );
+    pcYuv->removeHighFreq( pcYuvOther, uiPartAddr, iRoiWidth, iRoiHeight
+#if !DISABLING_CLIP_FOR_BIPREDME
+                          , pcCU->getSlice()->getSPS()->getBitDepths().recon
+#endif
+                          );
 
     fWeight = 0.5;
