Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

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

    r1179 r1313  
    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 *
    66 * Copyright (c) 2010-2015, ITU/ISO/IEC
     
    4444//! \ingroup TLibCommon
    4545//! \{
    46 UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS];
    4746
    4847SAOOffset::SAOOffset()
    49 { 
     48{
    5049  reset();
    5150}
     
    8786Void SAOBlkParam::reset()
    8887{
    89   for(Int compIdx=0; compIdx< 3; compIdx++)
     88  for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++)
    9089  {
    9190    offsetParam[compIdx].reset();
     
    9594const SAOBlkParam& SAOBlkParam::operator= (const SAOBlkParam& src)
    9695{
    97   for(Int compIdx=0; compIdx< 3; compIdx++)
     96  for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++)
    9897  {
    9998    offsetParam[compIdx] = src.offsetParam[compIdx];
     
    106105{
    107106  m_tempPicYuv = NULL;
    108   for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    109   {
    110     m_offsetClipTable[compIdx] = NULL;
    111   }
    112 #if !SAO_SGN_FUNC
    113   m_signTable = NULL;
    114 #endif
    115  
    116107  m_lineBufWidth = 0;
    117108  m_signLineBuf1 = NULL;
     
    123114{
    124115  destroy();
    125  
    126   if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
    127   if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
    128 }
    129 
    130 Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth )
     116
     117  if (m_signLineBuf1)
     118  {
     119    delete[] m_signLineBuf1;
     120    m_signLineBuf1 = NULL;
     121  }
     122  if (m_signLineBuf2)
     123  {
     124    delete[] m_signLineBuf2;
     125    m_signLineBuf2 = NULL;
     126  }
     127}
     128
     129Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, ChromaFormat format, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth, UInt lumaBitShift, UInt chromaBitShift )
    131130{
    132131  destroy();
    133132
    134   m_picWidth = picWidth;   
    135   m_picHeight= picHeight;
    136   m_maxCUWidth= maxCUWidth;
    137   m_maxCUHeight= maxCUHeight;
    138 
    139   m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0);
    140   m_numCTUInHeight= (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0);
    141   m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth;
     133  m_picWidth        = picWidth;
     134  m_picHeight       = picHeight;
     135  m_chromaFormatIDC = format;
     136  m_maxCUWidth      = maxCUWidth;
     137  m_maxCUHeight     = maxCUHeight;
     138
     139  m_numCTUInWidth   = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0);
     140  m_numCTUInHeight  = (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0);
     141  m_numCTUsPic      = m_numCTUInHeight*m_numCTUInWidth;
    142142
    143143  //temporary picture buffer
     
    145145  {
    146146    m_tempPicYuv = new TComPicYuv;
    147     m_tempPicYuv->create( m_picWidth, m_picHeight, m_maxCUWidth, m_maxCUHeight, maxCUDepth );
     147    m_tempPicYuv->create( m_picWidth, m_picHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, maxCUDepth, true );
    148148  }
    149149
    150150  //bit-depth related
    151   for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    152   {
    153     Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC;
    154     m_offsetStepLog2  [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0);
    155     g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive
    156   }
    157 
    158 #if !SAO_SGN_FUNC
    159   //look-up table for clipping
    160   Int overallMaxSampleValue=0;
    161 #endif
    162   for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    163   {
    164     Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive
    165     Int maxSampleValue = (1<< bitDepthSample); //exclusive
    166     Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]);
    167 #if !SAO_SGN_FUNC
    168     if (maxSampleValue>overallMaxSampleValue) overallMaxSampleValue=maxSampleValue;
    169 #endif
    170 
    171     m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
    172     m_offsetClip[compIdx] = &(m_offsetClipTable[compIdx][maxOffsetValue]);
    173 
    174     //assign clipped values
    175     Int* offsetClipPtr = m_offsetClip[compIdx];
    176     for(Int k=0; k< maxSampleValue; k++)
    177     {
    178       *(offsetClipPtr + k) = k;
    179     }
    180     for(Int k=0; k< maxOffsetValue; k++ )
    181     {
    182       *(offsetClipPtr + maxSampleValue+ k) = maxSampleValue-1;
    183       *(offsetClipPtr -k -1 )              = 0;
    184     }
    185   }
    186 
    187 #if !SAO_SGN_FUNC
    188   m_signTable = new Short[ 2*(overallMaxSampleValue-1) + 1 ];
    189   m_sign = &(m_signTable[overallMaxSampleValue-1]);
    190 
    191       m_sign[0] = 0;
    192   for(Int k=1; k< overallMaxSampleValue; k++)
    193       {
    194         m_sign[k] = 1;
    195         m_sign[-k]= -1;
    196       }
    197 #endif
     151  for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++)
     152  {
     153    m_offsetStepLog2  [compIdx] = isLuma(ComponentID(compIdx))? lumaBitShift : chromaBitShift;
     154  }
    198155}
    199156
     
    206163    m_tempPicYuv = NULL;
    207164  }
    208 
    209   for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    210   {
    211     if(m_offsetClipTable[compIdx])
    212     {
    213       delete[] m_offsetClipTable[compIdx]; m_offsetClipTable[compIdx] = NULL;
    214     }
    215   }
    216 #if !SAO_SGN_FUNC
    217   if( m_signTable )
    218   {
    219     delete[] m_signTable; m_signTable = NULL;
    220   }
    221 #endif
    222 }
    223 
    224 Void TComSampleAdaptiveOffset::invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets)
     165}
     166
     167Void TComSampleAdaptiveOffset::invertQuantOffsets(ComponentID compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets)
    225168{
    226169  Int codedOffset[MAX_NUM_SAO_CLASSES];
     
    247190}
    248191
    249 Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList)
    250 {
    251   Int ctuX = ctu % m_numCTUInWidth;
    252   Int ctuY = ctu / m_numCTUInWidth;
     192Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctuRsAddr, SAOBlkParam* blkParams, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES])
     193{
     194  Int ctuX = ctuRsAddr % m_numCTUInWidth;
     195  Int ctuY = ctuRsAddr / m_numCTUInWidth;
    253196  Int mergedCTUPos;
    254197  Int numValidMergeCandidates = 0;
     
    264207        if(ctuY > 0)
    265208        {
    266           mergedCTUPos = ctu- m_numCTUInWidth;
    267           if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) )
     209          mergedCTUPos = ctuRsAddr- m_numCTUInWidth;
     210          if( pic->getSAOMergeAvailability(ctuRsAddr, mergedCTUPos) )
    268211          {
    269212            mergeCandidate = &(blkParams[mergedCTUPos]);
     
    276219        if(ctuX > 0)
    277220        {
    278           mergedCTUPos = ctu- 1;
    279           if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) )
     221          mergedCTUPos = ctuRsAddr- 1;
     222          if( pic->getSAOMergeAvailability(ctuRsAddr, mergedCTUPos) )
    280223          {
    281224            mergeCandidate = &(blkParams[mergedCTUPos]);
     
    292235    }
    293236
    294     mergeList.push_back(mergeCandidate);
     237    mergeList[mergeType]=mergeCandidate;
    295238    if (mergeCandidate != NULL)
    296239    {
     
    303246
    304247
    305 Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList)
    306 {
    307   for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
    308   {
    309     SAOOffset& offsetParam = recParam[compIdx];
     248Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES])
     249{
     250  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     251  for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     252  {
     253    const ComponentID component = ComponentID(compIdx);
     254    SAOOffset& offsetParam = recParam[component];
    310255
    311256    if(offsetParam.modeIdc == SAO_MODE_OFF)
     
    318263    case SAO_MODE_NEW:
    319264      {
    320         invertQuantOffsets(compIdx, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset);
     265        invertQuantOffsets(component, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset);
    321266      }
    322267      break;
     
    326271        assert(mergeTarget != NULL);
    327272
    328         offsetParam = (*mergeTarget)[compIdx];
     273        offsetParam = (*mergeTarget)[component];
    329274      }
    330275      break;
     
    341286Void TComSampleAdaptiveOffset::reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams)
    342287{
    343   m_picSAOEnabled[SAO_Y] = m_picSAOEnabled[SAO_Cb] = m_picSAOEnabled[SAO_Cr] = false;
    344 
    345   for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
    346   {
    347     std::vector<SAOBlkParam*> mergeList;
    348     getMergeList(pic, ctu, saoBlkParams, mergeList);
    349 
    350     reconstructBlkSAOParam(saoBlkParams[ctu], mergeList);
    351 
    352     for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
    353     {
    354       if(saoBlkParams[ctu][compIdx].modeIdc != SAO_MODE_OFF)
     288  for(Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++)
     289  {
     290    m_picSAOEnabled[compIdx] = false;
     291  }
     292
     293  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     294
     295  for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++)
     296  {
     297    SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] = { NULL };
     298    getMergeList(pic, ctuRsAddr, saoBlkParams, mergeList);
     299
     300    reconstructBlkSAOParam(saoBlkParams[ctuRsAddr], mergeList);
     301
     302    for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     303    {
     304      if(saoBlkParams[ctuRsAddr][compIdx].modeIdc != SAO_MODE_OFF)
    355305      {
    356306        m_picSAOEnabled[compIdx] = true;
     
    358308    }
    359309  }
    360 
    361 
    362 }
    363 
    364 
    365 Void TComSampleAdaptiveOffset::offsetBlock(Int compIdx, Int typeIdx, Int* offset 
     310}
     311
     312
     313Void TComSampleAdaptiveOffset::offsetBlock(const Int channelBitDepth, Int typeIdx, Int* offset
    366314                                          , Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride,  Int width, Int height
    367315                                          , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail)
     
    370318  {
    371319    m_lineBufWidth = m_maxCUWidth;
    372    
    373     if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     320
     321    if (m_signLineBuf1)
     322    {
     323      delete[] m_signLineBuf1;
     324      m_signLineBuf1 = NULL;
     325    }
    374326    m_signLineBuf1 = new Char[m_lineBufWidth+1];
    375    
    376     if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     327
     328    if (m_signLineBuf2)
     329    {
     330      delete[] m_signLineBuf2;
     331      m_signLineBuf2 = NULL;
     332    }
    377333    m_signLineBuf2 = new Char[m_lineBufWidth+1];
    378334  }
    379335
    380   Int* offsetClip = m_offsetClip[compIdx];
     336  const Int maxSampleValueIncl = (1<< channelBitDepth )-1;
    381337
    382338  Int x,y, startX, startY, endX, endY, edgeType;
     
    396352      for (y=0; y< height; y++)
    397353      {
    398 #if SAO_SGN_FUNC
    399354        signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
    400 #else
    401         signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
    402 #endif
    403355        for (x=startX; x< endX; x++)
    404356        {
    405 #if SAO_SGN_FUNC
    406357          signRight = (Char)sgn(srcLine[x] - srcLine[x+1]);
    407 #else
    408           signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];
    409 #endif
    410358          edgeType =  signRight + signLeft;
    411359          signLeft  = -signRight;
    412360
    413           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     361          resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
    414362        }
    415363        srcLine  += srcStride;
     
    435383      for (x=0; x< width; x++)
    436384      {
    437 #if SAO_SGN_FUNC
    438385        signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
    439 #else
    440         signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
    441 #endif
    442386      }
    443387
     
    449393        for (x=0; x< width; x++)
    450394        {
    451 #if SAO_SGN_FUNC
    452395          signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]);
    453 #else
    454           signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
    455 #endif
    456396          edgeType = signDown + signUpLine[x];
    457397          signUpLine[x]= -signDown;
    458398
    459           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     399          resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
    460400        }
    461401        srcLine += srcStride;
     
    480420      for (x=startX; x< endX+1; x++)
    481421      {
    482 #if SAO_SGN_FUNC
    483422        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x- 1]);
    484 #else
    485         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
    486 #endif
    487423      }
    488424
     
    493429      for(x= firstLineStartX; x< firstLineEndX; x++)
    494430      {
    495 #if SAO_SGN_FUNC
    496431        edgeType  =  sgn(srcLine[x] - srcLineAbove[x- 1]) - signUpLine[x+1];
    497 #else
    498         edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
    499 #endif
    500         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     432
     433        resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
    501434      }
    502435      srcLine  += srcStride;
     
    511444        for (x=startX; x<endX; x++)
    512445        {
    513 #if SAO_SGN_FUNC
    514446          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x+ 1]);
    515 #else
    516           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
    517 #endif
    518447          edgeType =  signDown + signUpLine[x];
    519           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
    520 
    521           signDownLine[x+1] = -signDown; 
     448          resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
     449
     450          signDownLine[x+1] = -signDown;
    522451        }
    523 #if SAO_SGN_FUNC
    524452        signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
    525 #else
    526         signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
    527 #endif
    528453
    529454        signTmpLine  = signUpLine;
     
    541466      for(x= lastLineStartX; x< lastLineEndX; x++)
    542467      {
    543 #if SAO_SGN_FUNC
    544468        edgeType =  sgn(srcLine[x] - srcLineBelow[x+ 1]) + signUpLine[x];
    545 #else
    546         edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
    547 #endif
    548         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     469        resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
    549470
    550471      }
     
    563484      for (x=startX-1; x< endX; x++)
    564485      {
    565 #if SAO_SGN_FUNC
    566486        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
    567 #else
    568         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
    569 #endif
    570487      }
    571488
     
    577494      for(x= firstLineStartX; x< firstLineEndX; x++)
    578495      {
    579 #if SAO_SGN_FUNC
    580496        edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) -signUpLine[x-1];
    581 #else
    582         edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
    583 #endif
    584         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     497        resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
    585498      }
    586499      srcLine += srcStride;
     
    594507        for(x= startX; x< endX; x++)
    595508        {
    596 #if SAO_SGN_FUNC
    597509          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
    598 #else
    599           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
    600 #endif
    601510          edgeType =  signDown + signUpLine[x];
    602           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
    603           signUpLine[x-1] = -signDown; 
     511          resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
     512          signUpLine[x-1] = -signDown;
    604513        }
    605 #if SAO_SGN_FUNC
    606514        signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
    607 #else
    608         signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
    609 #endif
    610515        srcLine  += srcStride;
    611516        resLine += resStride;
     
    618523      for(x= lastLineStartX; x< lastLineEndX; x++)
    619524      {
    620 #if SAO_SGN_FUNC
    621525        edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + signUpLine[x];
    622 #else
    623         edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
    624 #endif
    625         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     526        resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[edgeType]);
    626527
    627528      }
     
    630531  case SAO_TYPE_BO:
    631532    {
    632       Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
     533      const Int shiftBits = channelBitDepth - NUM_SAO_BO_CLASSES_LOG2;
    633534      for (y=0; y< height; y++)
    634535      {
    635536        for (x=0; x< width; x++)
    636537        {
    637           resLine[x] = offsetClip[ srcLine[x] + offset[srcLine[x] >> shiftBits] ];
     538          resLine[x] = Clip3<Int>(0, maxSampleValueIncl, srcLine[x] + offset[srcLine[x] >> shiftBits] );
    638539        }
    639540        srcLine += srcStride;
     
    649550    }
    650551  }
    651 
    652 
    653 }
    654 
    655 Void TComSampleAdaptiveOffset::offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic)
     552}
     553
     554Void TComSampleAdaptiveOffset::offsetCTU(Int ctuRsAddr, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic)
    656555{
    657556  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
    658557
    659   if(
    660     (saoblkParam[SAO_Y ].modeIdc == SAO_MODE_OFF) &&
    661     (saoblkParam[SAO_Cb].modeIdc == SAO_MODE_OFF) &&
    662     (saoblkParam[SAO_Cr].modeIdc == SAO_MODE_OFF)
    663     )
     558  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     559  Bool bAllOff=true;
     560  for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     561  {
     562    if (saoblkParam[compIdx].modeIdc != SAO_MODE_OFF)
     563    {
     564      bAllOff=false;
     565    }
     566  }
     567  if (bAllOff)
    664568  {
    665569    return;
     
    667571
    668572  //block boundary availability
    669   pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
    670 
    671   Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
    672   Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     573  pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctuRsAddr, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     574
     575  Int yPos   = (ctuRsAddr / m_numCTUInWidth)*m_maxCUHeight;
     576  Int xPos   = (ctuRsAddr % m_numCTUInWidth)*m_maxCUWidth;
    673577  Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
    674578  Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
    675579
    676   for(Int compIdx= 0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
    677   {
     580  for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     581  {
     582    const ComponentID component = ComponentID(compIdx);
    678583    SAOOffset& ctbOffset = saoblkParam[compIdx];
    679584
    680585    if(ctbOffset.modeIdc != SAO_MODE_OFF)
    681586    {
    682       Bool isLuma     = (compIdx == SAO_Y);
    683       Int  formatShift= isLuma?0:1;
    684 
    685       Int  blkWidth   = (width  >> formatShift);
    686       Int  blkHeight  = (height >> formatShift);
    687       Int  blkYPos    = (yPos   >> formatShift);
    688       Int  blkXPos    = (xPos   >> formatShift);
    689 
    690       Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
    691       Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
    692 
    693       Int  resStride  = isLuma?resYuv->getStride():resYuv->getCStride();
    694       Pel* resBlk     = getPicBuf(resYuv, compIdx)+ blkYPos*resStride+ blkXPos;
    695 
    696       offsetBlock( compIdx, ctbOffset.typeIdc, ctbOffset.offset
     587      const UInt componentScaleX = getComponentScaleX(component, pPic->getChromaFormat());
     588      const UInt componentScaleY = getComponentScaleY(component, pPic->getChromaFormat());
     589
     590      Int  blkWidth   = (width  >> componentScaleX);
     591      Int  blkHeight  = (height >> componentScaleY);
     592      Int  blkXPos    = (xPos   >> componentScaleX);
     593      Int  blkYPos    = (yPos   >> componentScaleY);
     594
     595      Int  srcStride  = srcYuv->getStride(component);
     596      Pel* srcBlk     = srcYuv->getAddr(component) + blkYPos*srcStride + blkXPos;
     597
     598      Int  resStride  = resYuv->getStride(component);
     599      Pel* resBlk     = resYuv->getAddr(component) + blkYPos*resStride + blkXPos;
     600
     601      offsetBlock( pPic->getPicSym()->getSPS().getBitDepth(toChannelType(component)), ctbOffset.typeIdc, ctbOffset.offset
    697602                  , srcBlk, resBlk, srcStride, resStride, blkWidth, blkHeight
    698603                  , isLeftAvail, isRightAvail
     
    709614Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pDecPic)
    710615{
    711   if(!m_picSAOEnabled[SAO_Y] && !m_picSAOEnabled[SAO_Cb] && !m_picSAOEnabled[SAO_Cr])
     616  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     617  Bool bAllDisabled=true;
     618  for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     619  {
     620    if (m_picSAOEnabled[compIdx])
     621    {
     622      bAllDisabled=false;
     623    }
     624  }
     625  if (bAllDisabled)
    712626  {
    713627    return;
    714628  }
     629
    715630  TComPicYuv* resYuv = pDecPic->getPicYuvRec();
    716631  TComPicYuv* srcYuv = m_tempPicYuv;
    717632  resYuv->copyToPic(srcYuv);
    718   for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
    719   {
    720     offsetCTU(ctu, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctu], pDecPic);
     633  for(Int ctuRsAddr= 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++)
     634  {
     635    offsetCTU(ctuRsAddr, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctuRsAddr], pDecPic);
    721636  } //ctu
    722637}
    723638
    724 
    725 Pel* TComSampleAdaptiveOffset::getPicBuf(TComPicYuv* pPicYuv, Int compIdx)
    726 {
    727   Pel* pBuf = NULL;
    728   switch(compIdx)
    729   {
    730   case SAO_Y:
    731     {
    732       pBuf = pPicYuv->getLumaAddr();
    733     }
    734     break;
    735   case SAO_Cb:
    736     {
    737       pBuf = pPicYuv->getCbAddr();
    738     }
    739     break;
    740   case SAO_Cr:
    741     {
    742       pBuf = pPicYuv->getCrAddr();
    743     }
    744     break;
    745   default:
    746     {
    747       printf("Not a legal component ID for SAO\n");
    748       assert(0);
    749       exit(-1);
    750     }
    751   }
    752 
    753   return pBuf;
    754 }
    755639
    756640/** PCM LF disable process.
    757641 * \param pcPic picture (TComPic) pointer
    758  * \returns Void
    759642 *
    760643 * \note Replace filtered sample values of PCM mode blocks with the transmitted and reconstructed ones.
     
    765648}
    766649
    767 /** Picture-level PCM restoration. 
     650/** Picture-level PCM restoration.
    768651 * \param pcPic picture (TComPic) pointer
    769  * \returns Void
    770652 */
    771653Void TComSampleAdaptiveOffset::xPCMRestoration(TComPic* pcPic)
     
    775657  if(bPCMFilter || pcPic->getSlice(0)->getPPS()->getTransquantBypassEnableFlag())
    776658  {
    777     for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getNumCUsInFrame() ; uiCUAddr++ )
    778     {
    779       TComDataCU* pcCU = pcPic->getCU(uiCUAddr);
    780 
    781       xPCMCURestoration(pcCU, 0, 0);
    782     }
    783   }
    784 }
    785 
    786 /** PCM CU restoration.
    787  * \param pcCU pointer to current CU
    788  * \param uiAbsPartIdx part index
    789  * \param uiDepth CU depth
    790  * \returns Void
     659    for( UInt ctuRsAddr = 0; ctuRsAddr < pcPic->getNumberOfCtusInFrame() ; ctuRsAddr++ )
     660    {
     661      TComDataCU* pcCU = pcPic->getCtu(ctuRsAddr);
     662
     663      xPCMCURestoration(pcCU, 0, 0);
     664    }
     665  }
     666}
     667
     668/** PCM CU restoration.
     669 * \param pcCU            pointer to current CU
     670 * \param uiAbsZorderIdx  part index
     671 * \param uiDepth         CU depth
    791672 */
    792673Void TComSampleAdaptiveOffset::xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth )
    793674{
    794675  TComPic* pcPic     = pcCU->getPic();
    795   UInt uiCurNumParts = pcPic->getNumPartInCU() >> (uiDepth<<1);
     676  UInt uiCurNumParts = pcPic->getNumPartitionsInCtu() >> (uiDepth<<1);
    796677  UInt uiQNumParts   = uiCurNumParts>>2;
    797678
     
    804685      UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
    805686      if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
     687      {
    806688        xPCMCURestoration( pcCU, uiAbsZorderIdx, uiDepth+1 );
     689      }
    807690    }
    808691    return;
     
    812695  if ((pcCU->getIPCMFlag(uiAbsZorderIdx)&& pcPic->getSlice(0)->getSPS()->getPCMFilterDisableFlag()) || pcCU->isLosslessCoded( uiAbsZorderIdx))
    813696  {
    814     xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_LUMA    );
    815     xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_CHROMA_U);
    816     xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, TEXT_CHROMA_V);
    817   }
    818 }
    819 
    820 /** PCM sample restoration.
    821  * \param pcCU pointer to current CU
    822  * \param uiAbsPartIdx part index
    823  * \param uiDepth CU depth
    824  * \param ttText texture component type
    825  * \returns Void
     697    const UInt numComponents=pcPic->getNumberValidComponents();
     698    for(UInt comp=0; comp<numComponents; comp++)
     699    {
     700      xPCMSampleRestoration (pcCU, uiAbsZorderIdx, uiDepth, ComponentID(comp));
     701    }
     702  }
     703}
     704
     705/** PCM sample restoration.
     706 * \param pcCU           pointer to current CU
     707 * \param uiAbsZorderIdx part index
     708 * \param uiDepth        CU depth
     709 * \param compID         texture component type
    826710 */
    827 Void TComSampleAdaptiveOffset::xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText)
    828 {
    829   TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec();
    830   Pel* piSrc;
    831   Pel* piPcm;
    832   UInt uiStride;
    833   UInt uiWidth;
    834   UInt uiHeight;
    835   UInt uiPcmLeftShiftBit;
    836   UInt uiX, uiY;
    837   UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
    838   UInt uiLumaOffset   = uiMinCoeffSize*uiAbsZorderIdx;
    839   UInt uiChromaOffset = uiLumaOffset>>2;
    840 
    841   if( ttText == TEXT_LUMA )
    842   {
    843     piSrc = pcPicYuvRec->getLumaAddr( pcCU->getAddr(), uiAbsZorderIdx);
    844     piPcm = pcCU->getPCMSampleY() + uiLumaOffset;
    845     uiStride  = pcPicYuvRec->getStride();
    846     uiWidth  = (g_uiMaxCUWidth >> uiDepth);
    847     uiHeight = (g_uiMaxCUHeight >> uiDepth);
    848     if ( pcCU->isLosslessCoded(uiAbsZorderIdx) && !pcCU->getIPCMFlag(uiAbsZorderIdx) )
    849     {
    850       uiPcmLeftShiftBit = 0;
    851     }
    852     else
    853     {
    854       uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
    855     }
     711Void TComSampleAdaptiveOffset::xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, const ComponentID compID)
     712{
     713        TComPicYuv* pcPicYuvRec = pcCU->getPic()->getPicYuvRec();
     714        UInt uiPcmLeftShiftBit;
     715  const UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
     716  const UInt csx=pcPicYuvRec->getComponentScaleX(compID);
     717  const UInt csy=pcPicYuvRec->getComponentScaleY(compID);
     718  const UInt uiOffset   = (uiMinCoeffSize*uiAbsZorderIdx)>>(csx+csy);
     719
     720        Pel *piSrc = pcPicYuvRec->getAddr(compID, pcCU->getCtuRsAddr(), uiAbsZorderIdx);
     721  const Pel *piPcm = pcCU->getPCMSample(compID) + uiOffset;
     722  const UInt uiStride  = pcPicYuvRec->getStride(compID);
     723  const TComSPS &sps = *(pcCU->getSlice()->getSPS());
     724  const UInt uiWidth  = ((sps.getMaxCUWidth()  >> uiDepth) >> csx);
     725  const UInt uiHeight = ((sps.getMaxCUHeight() >> uiDepth) >> csy);
     726
     727  if ( pcCU->isLosslessCoded(uiAbsZorderIdx) && !pcCU->getIPCMFlag(uiAbsZorderIdx) )
     728  {
     729    uiPcmLeftShiftBit = 0;
    856730  }
    857731  else
    858732  {
    859     if( ttText == TEXT_CHROMA_U )
    860     {
    861       piSrc = pcPicYuvRec->getCbAddr( pcCU->getAddr(), uiAbsZorderIdx );
    862       piPcm = pcCU->getPCMSampleCb() + uiChromaOffset;
    863     }
    864     else
    865     {
    866       piSrc = pcPicYuvRec->getCrAddr( pcCU->getAddr(), uiAbsZorderIdx );
    867       piPcm = pcCU->getPCMSampleCr() + uiChromaOffset;
    868     }
    869 
    870     uiStride = pcPicYuvRec->getCStride();
    871     uiWidth  = ((g_uiMaxCUWidth >> uiDepth)/2);
    872     uiHeight = ((g_uiMaxCUWidth >> uiDepth)/2);
    873     if ( pcCU->isLosslessCoded(uiAbsZorderIdx) && !pcCU->getIPCMFlag(uiAbsZorderIdx) )
    874     {
    875       uiPcmLeftShiftBit = 0;
    876     }
    877     else
    878     {
    879       uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    880     }
    881   }
    882 
    883   for( uiY = 0; uiY < uiHeight; uiY++ )
    884   {
    885     for( uiX = 0; uiX < uiWidth; uiX++ )
     733    uiPcmLeftShiftBit = sps.getBitDepth(toChannelType(compID)) - sps.getPCMBitDepth(toChannelType(compID));
     734  }
     735
     736  for(UInt uiY = 0; uiY < uiHeight; uiY++ )
     737  {
     738    for(UInt uiX = 0; uiX < uiWidth; uiX++ )
    886739    {
    887740      piSrc[uiX] = (piPcm[uiX] << uiPcmLeftShiftBit);
Note: See TracChangeset for help on using the changeset viewer.