Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComYuv.cpp


Ignore:
Timestamp:
11 May 2012, 21:20:17 (13 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComYuv.cpp

    r21 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     TComYuv.cpp
    3735    \brief    general YUV buffer class
     
    4644#include "CommonDef.h"
    4745#include "TComYuv.h"
     46#include "TComInterpolationFilter.h"
     47
     48//! \ingroup TLibCommon
     49//! \{
    4850
    4951TComYuv::TComYuv()
     
    5658TComYuv::~TComYuv()
    5759{
    58 }
    59 
    60 Void TComYuv::printout()
    61 {
    62   Int  x, y;
    63  
    64   Pel* pSrc = getLumaAddr(  );
    65   Int  iStride = getStride();
    66  
    67  
    68   printf("\nY ...");
    69   for ( y = 0; y < iStride; y++ )
    70   {
    71     printf ("\n");
    72     for ( x = 0; x < iStride; x++ )
    73     {
    74       printf ("%d ", pSrc[x]);
    75     }
    76     pSrc += iStride;
    77   }
    7860}
    7961
     
    306288}
    307289#endif
    308    
     290
    309291Void TComYuv::copyPartToPartYuv   ( TComYuv* pcYuvDst, UInt uiPartIdx, UInt iWidth, UInt iHeight )
    310292{
     
    320302  Pel* pSrc   = getLumaAddr(uiPartIdx);
    321303  Pel* pDst   = pcYuvDst->getLumaAddr() + uiBlkY * pcYuvDst->getStride() + uiBlkX;
    322  
     304
    323305  if( pSrc == pDst )
    324306  {
     
    327309    return ;
    328310  }
    329  
     311
    330312  UInt  iSrcStride = getStride();
    331313  UInt  iDstStride = pcYuvDst->getStride();
     
    402384    for ( x = uiPartSize-1; x >= 0; x-- )
    403385    {
    404       pDst[x] = xClip( pSrc0[x] + pSrc1[x] );     
     386      pDst[x] = Clip( pSrc0[x] + pSrc1[x] );     
    405387    }
    406388    pSrc0 += iSrc0Stride;
     
    410392}
    411393
    412 Void
     394
     395Void
    413396TComYuv::add( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
    414397{
     
    417400}
    418401
    419 Void 
     402Void
    420403TComYuv::addLuma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
    421404{
     
    434417}
    435418
    436 Void 
     419Void
    437420TComYuv::addChroma( TComYuv* pcYuvAdd, Int iWidth, Int iHeight, Bool bSubtract )
    438421{
     
    455438}
    456439
    457 Void 
     440Void
    458441TComYuv::clip( Int iWidth, Int iHeight )
    459442{
     
    462445}
    463446
    464 Void 
     447Void
    465448TComYuv::clipLuma( Int iWidth, Int iHeight )
    466449{
     
    476459}
    477460
    478 Void 
     461Void
    479462TComYuv::clipChroma( Int iWidth, Int iHeight )
    480463{
     
    492475}
    493476
    494 
    495477Void TComYuv::addClip( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
    496478{
     
    514496    for ( x = uiPartSize-1; x >= 0; x-- )
    515497    {
    516       pDst[x] = xClip( pSrc0[x] + pSrc1[x] );
     498      pDst[x] = Clip( pSrc0[x] + pSrc1[x] );
    517499    }
    518500    pSrc0 += iSrc0Stride;
     
    540522    for ( x = uiPartSize-1; x >= 0; x-- )
    541523    {
    542       pDstU[x] = xClip( pSrcU0[x] + pSrcU1[x] );
    543       pDstV[x] = xClip( pSrcV0[x] + pSrcV1[x] );
     524      pDstU[x] = Clip( pSrcU0[x] + pSrcU1[x] );
     525      pDstV[x] = Clip( pSrcV0[x] + pSrcV1[x] );
    544526    }
    545527   
     
    612594}
    613595
    614 #ifdef ROUNDING_CONTROL_BIPRED
    615 
    616 Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, Bool bRound )
     596Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight )
    617597{
    618598  Int x, y;
     
    633613  UInt  iSrc1Stride = pcYuvSrc1->getStride();
    634614  UInt  iDstStride  = getStride();
    635 
    636 #if HIGH_ACCURACY_BI
    637   Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement);
    638   Int offset = (1<<(shiftNum - 1));
    639  
    640   for ( y = iHeight-1; y >= 0; y-- )
    641   {
    642     for ( x = iWidth-1; x >= 0; )
    643     {
    644       // note: luma min width is 4
    645       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--;
    646       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
    647       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
    648       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
     615  Int shiftNum = IF_INTERNAL_PREC + 1 - ( g_uiBitDepth + g_uiBitIncrement );
     616  Int offset = ( 1 << ( shiftNum - 1 ) ) + 2 * IF_INTERNAL_OFFS;
     617 
     618  for ( y = 0; y < iHeight; y++ )
     619  {
     620    for ( x = 0; x < iWidth; x += 4 )
     621    {
     622      pDstY[ x + 0 ] = Clip( ( pSrcY0[ x + 0 ] + pSrcY1[ x + 0 ] + offset ) >> shiftNum );
     623      pDstY[ x + 1 ] = Clip( ( pSrcY0[ x + 1 ] + pSrcY1[ x + 1 ] + offset ) >> shiftNum );
     624      pDstY[ x + 2 ] = Clip( ( pSrcY0[ x + 2 ] + pSrcY1[ x + 2 ] + offset ) >> shiftNum );
     625      pDstY[ x + 3 ] = Clip( ( pSrcY0[ x + 3 ] + pSrcY1[ x + 3 ] + offset ) >> shiftNum );
    649626    }
    650627    pSrcY0 += iSrc0Stride;
     
    678655    pDstV  += iDstStride;
    679656  }
    680 
    681 #else
    682 
    683   for ( y = iHeight-1; y >= 0; y-- )
    684   {
    685     for ( x = iWidth-1; x >= 0; )
    686     {
    687       // note: luma min width is 4
    688       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
    689       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
    690       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
    691       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + bRound) >> 1; x--;
    692     }
    693     pSrcY0 += iSrc0Stride;
    694     pSrcY1 += iSrc1Stride;
    695     pDstY  += iDstStride;
    696   }
    697  
    698   iSrc0Stride = pcYuvSrc0->getCStride();
    699   iSrc1Stride = pcYuvSrc1->getCStride();
    700   iDstStride  = getCStride();
    701  
    702   iWidth  >>=1;
    703   iHeight >>=1;
    704  
    705   for ( y = iHeight-1; y >= 0; y-- )
    706   {
    707     for ( x = iWidth-1; x >= 0; )
    708     {
    709       // note: chroma min width is 2
    710       pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1;
    711       pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--;
    712       pDstU[x] = (pSrcU0[x] + pSrcU1[x] + bRound) >> 1;
    713       pDstV[x] = (pSrcV0[x] + pSrcV1[x] + bRound) >> 1; x--;
    714     }
    715    
    716     pSrcU0 += iSrc0Stride;
    717     pSrcU1 += iSrc1Stride;
    718     pSrcV0 += iSrc0Stride;
    719     pSrcV1 += iSrc1Stride;
    720     pDstU  += iDstStride;
    721     pDstV  += iDstStride;
    722   }
    723 #endif
    724 }
    725 
    726 #endif
    727 
    728 Void TComYuv::addAvg( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight )
    729 {
    730   Int x, y;
    731  
    732   Pel* pSrcY0  = pcYuvSrc0->getLumaAddr( iPartUnitIdx );
    733   Pel* pSrcU0  = pcYuvSrc0->getCbAddr  ( iPartUnitIdx );
    734   Pel* pSrcV0  = pcYuvSrc0->getCrAddr  ( iPartUnitIdx );
    735  
    736   Pel* pSrcY1  = pcYuvSrc1->getLumaAddr( iPartUnitIdx );
    737   Pel* pSrcU1  = pcYuvSrc1->getCbAddr  ( iPartUnitIdx );
    738   Pel* pSrcV1  = pcYuvSrc1->getCrAddr  ( iPartUnitIdx );
    739  
    740   Pel* pDstY   = getLumaAddr( iPartUnitIdx );
    741   Pel* pDstU   = getCbAddr  ( iPartUnitIdx );
    742   Pel* pDstV   = getCrAddr  ( iPartUnitIdx );
    743  
    744   UInt  iSrc0Stride = pcYuvSrc0->getStride();
    745   UInt  iSrc1Stride = pcYuvSrc1->getStride();
    746   UInt  iDstStride  = getStride();
    747 #if HIGH_ACCURACY_BI
    748   Int shiftNum = 15 - (g_uiBitDepth + g_uiBitIncrement);
    749   Int offset = (1<<(shiftNum - 1));
    750  
    751   for ( y = iHeight-1; y >= 0; y-- )
    752   {
    753     for ( x = iWidth-1; x >= 0; )
    754     {
    755       // note: luma min width is 4
    756       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum ); x--;
    757       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
    758       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
    759       pDstY[x] = Clip((pSrcY0[x] + pSrcY1[x] + offset) >> shiftNum); x--;
    760     }
    761     pSrcY0 += iSrc0Stride;
    762     pSrcY1 += iSrc1Stride;
    763     pDstY  += iDstStride;
    764   }
    765  
    766   iSrc0Stride = pcYuvSrc0->getCStride();
    767   iSrc1Stride = pcYuvSrc1->getCStride();
    768   iDstStride  = getCStride();
    769  
    770   iWidth  >>=1;
    771   iHeight >>=1;
    772  
    773   for ( y = iHeight-1; y >= 0; y-- )
    774   {
    775     for ( x = iWidth-1; x >= 0; )
    776     {
    777       // note: chroma min width is 2
    778       pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);
    779       pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;
    780       pDstU[x] = Clip((pSrcU0[x] + pSrcU1[x] + offset) >> shiftNum);
    781       pDstV[x] = Clip((pSrcV0[x] + pSrcV1[x] + offset) >> shiftNum); x--;
    782     }
    783    
    784     pSrcU0 += iSrc0Stride;
    785     pSrcU1 += iSrc1Stride;
    786     pSrcV0 += iSrc0Stride;
    787     pSrcV1 += iSrc1Stride;
    788     pDstU  += iDstStride;
    789     pDstV  += iDstStride;
    790   }
    791 
    792 #else 
    793   for ( y = iHeight-1; y >= 0; y-- )
    794   {
    795     for ( x = iWidth-1; x >= 0; )
    796     {
    797       // note: luma min width is 4
    798       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
    799       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
    800       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
    801       pDstY[x] = (pSrcY0[x] + pSrcY1[x] + 1) >> 1; x--;
    802     }
    803     pSrcY0 += iSrc0Stride;
    804     pSrcY1 += iSrc1Stride;
    805     pDstY  += iDstStride;
    806   }
    807  
    808   iSrc0Stride = pcYuvSrc0->getCStride();
    809   iSrc1Stride = pcYuvSrc1->getCStride();
    810   iDstStride  = getCStride();
    811  
    812   iWidth  >>=1;
    813   iHeight >>=1;
    814  
    815   for ( y = iHeight-1; y >= 0; y-- )
    816   {
    817     for ( x = iWidth-1; x >= 0; )
    818     {
    819       // note: chroma min width is 2
    820       pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1;
    821       pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--;
    822       pDstU[x] = (pSrcU0[x] + pSrcU1[x] + 1) >> 1;
    823       pDstV[x] = (pSrcV0[x] + pSrcV1[x] + 1) >> 1; x--;
    824     }
    825    
    826     pSrcU0 += iSrc0Stride;
    827     pSrcU1 += iSrc1Stride;
    828     pSrcV0 += iSrc0Stride;
    829     pSrcV1 += iSrc1Stride;
    830     pDstU  += iDstStride;
    831     pDstV  += iDstStride;
    832   }
    833 #endif
    834657}
    835658
     
    844667  Pel* pSrcY1  = pcYuvSrc1->getLumaAddr( iPartUnitIdx );
    845668  Pel* pDstY   = getLumaAddr() + uiBlkY * getStride() + uiBlkX;
    846  
     669
    847670  UInt  iSrc0Stride = pcYuvSrc0->getStride();
    848671  UInt  iSrc1Stride = pcYuvSrc1->getStride();
     
    862685#endif
    863686
    864 
    865 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiWidht, UInt uiHeight )
     687Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight )
    866688{
    867689  Int x, y;
    868690 
    869   Pel* pSrc  = pcYuvSrc->getLumaAddr();
    870   Pel* pSrcU = pcYuvSrc->getCbAddr();
    871   Pel* pSrcV = pcYuvSrc->getCrAddr();
    872  
    873   Pel* pDst  = m_apiBufY;
    874   Pel* pDstU = m_apiBufU;
    875   Pel* pDstV = m_apiBufV;
     691  Pel* pSrc  = pcYuvSrc->getLumaAddr(uiPartIdx);
     692  Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx);
     693  Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx);
     694 
     695  Pel* pDst  = getLumaAddr(uiPartIdx);
     696  Pel* pDstU = getCbAddr(uiPartIdx);
     697  Pel* pDstV = getCrAddr(uiPartIdx);
    876698 
    877699  Int  iSrcStride = pcYuvSrc->getStride();
     
    882704    for ( x = uiWidht-1; x >= 0; x-- )
    883705    {
    884       pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] );
     706#if DISABLING_CLIP_FOR_BIPREDME
     707      pDst[x ] = (pDst[x ]<<1) - pSrc[x ] ;
     708#else
     709      pDst[x ] = Clip( (pDst[x ]<<1) - pSrc[x ] );
     710#endif
    885711    }
    886712    pSrc += iSrcStride;
     
    898724    for ( x = uiWidht-1; x >= 0; x-- )
    899725    {
    900       pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] );
    901       pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] );
     726#if DISABLING_CLIP_FOR_BIPREDME
     727      pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ] ;
     728      pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ] ;
     729#else
     730      pDstU[x ] = Clip( (pDstU[x ]<<1) - pSrcU[x ] );
     731      pDstV[x ] = Clip( (pDstV[x ]<<1) - pSrcV[x ] );
     732#endif
    902733    }
    903734    pSrcU += iSrcStride;
     
    907738  }
    908739}
    909 
    910 Void TComYuv::removeHighFreq( TComYuv* pcYuvSrc, UInt uiPartIdx, UInt uiWidht, UInt uiHeight )
    911 {
    912   Int x, y;
    913  
    914   Pel* pSrc  = pcYuvSrc->getLumaAddr(uiPartIdx);
    915   Pel* pSrcU = pcYuvSrc->getCbAddr(uiPartIdx);
    916   Pel* pSrcV = pcYuvSrc->getCrAddr(uiPartIdx);
    917  
    918   Pel* pDst  = getLumaAddr(uiPartIdx);
    919   Pel* pDstU = getCbAddr(uiPartIdx);
    920   Pel* pDstV = getCrAddr(uiPartIdx);
    921  
    922   Int  iSrcStride = pcYuvSrc->getStride();
    923   Int  iDstStride = getStride();
    924  
    925   for ( y = uiHeight-1; y >= 0; y-- )
    926   {
    927     for ( x = uiWidht-1; x >= 0; x-- )
    928     {
    929       pDst[x ] = xClip( (pDst[x ]<<1) - pSrc[x ] );
    930     }
    931     pSrc += iSrcStride;
    932     pDst += iDstStride;
    933   }
    934  
    935   iSrcStride = pcYuvSrc->getCStride();
    936   iDstStride = getCStride();
    937  
    938   uiHeight >>= 1;
    939   uiWidht  >>= 1;
    940  
    941   for ( y = uiHeight-1; y >= 0; y-- )
    942   {
    943     for ( x = uiWidht-1; x >= 0; x-- )
    944     {
    945       pDstU[x ] = xClip( (pDstU[x ]<<1) - pSrcU[x ] );
    946       pDstV[x ] = xClip( (pDstV[x ]<<1) - pSrcV[x ] );
    947     }
    948     pSrcU += iSrcStride;
    949     pSrcV += iSrcStride;
    950     pDstU += iDstStride;
    951     pDstV += iDstStride;
    952   }
    953 }
    954 
    955 
    956 Pel* TComYuv::getLumaAddr( UInt uiPartUnitIdx )
    957 {
    958   UInt iBlkX;
    959   UInt iBlkY;
    960   iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]];
    961   iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]];
    962  
    963   return m_apiBufY + iBlkY*getStride() + iBlkX;
    964 }
    965 
    966 Pel* TComYuv::getCbAddr( UInt uiPartUnitIdx )
    967 {
    968   UInt iBlkX;
    969   UInt iBlkY;
    970   iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
    971   iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
    972  
    973   return m_apiBufU + iBlkY*getCStride() + iBlkX;
    974 }
    975 
    976 Pel* TComYuv::getCrAddr( UInt uiPartUnitIdx )
    977 {
    978   UInt iBlkX;
    979   UInt iBlkY;
    980   iBlkX = g_auiRasterToPelX[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
    981   iBlkY = g_auiRasterToPelY[g_auiZscanToRaster[uiPartUnitIdx]] >> 1;
    982  
    983   return m_apiBufV + iBlkY*getCStride() + iBlkX;
    984 }
    985 
    986 Pel* TComYuv::getLumaAddr( UInt iTransUnitIdx, UInt iBlkSize )
    987 {
    988   UInt uiNumTrInWidth = m_iWidth / iBlkSize;
    989   UInt   iBlkX   = iTransUnitIdx % uiNumTrInWidth;
    990   UInt   iBlkY   = iTransUnitIdx / uiNumTrInWidth;
    991  
    992   return m_apiBufY + (iBlkX + iBlkY * getStride()) * iBlkSize;
    993 }
    994 
    995 Pel* TComYuv::getCbAddr( UInt iTransUnitIdx, UInt iBlkSize )
    996 {
    997   UInt uiNumTrInWidth = m_iCWidth / iBlkSize;
    998   UInt   iBlkX   = iTransUnitIdx % uiNumTrInWidth;
    999   UInt   iBlkY   = iTransUnitIdx / uiNumTrInWidth;
    1000  
    1001   return m_apiBufU + (iBlkX + iBlkY * getCStride()) * iBlkSize;
    1002 }
    1003 
    1004 Pel* TComYuv::getCrAddr( UInt iTransUnitIdx, UInt iBlkSize )
    1005 {
    1006   UInt uiNumTrInWidth = m_iCWidth / iBlkSize;
    1007   UInt   iBlkX   = iTransUnitIdx % uiNumTrInWidth;
    1008   UInt   iBlkY   = iTransUnitIdx / uiNumTrInWidth;
    1009  
    1010   return m_apiBufV + (iBlkX + iBlkY * getCStride()) * iBlkSize;
    1011 }
     740//! \}
Note: See TracChangeset for help on using the changeset viewer.