Ignore:
Timestamp:
12 Nov 2014, 08:09:17 (10 years ago)
Author:
seregin
Message:

initial porting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-upgrade/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r713 r916  
    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-2014, ITU/ISO/IEC
     
    3232 */
    3333
    34 /** 
     34/**
    3535 \file     TEncSampleAdaptiveOffset.cpp
    3636 \brief       estimation part of sample adaptive offset class
     
    6262TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    6363{
    64   m_pppcRDSbacCoder = NULL;           
     64  m_pppcRDSbacCoder = NULL;
    6565  m_pcRDGoOnSbacCoder = NULL;
    66   m_pppcBinCoderCABAC = NULL;   
     66  m_pppcBinCoderCABAC = NULL;
    6767  m_statData = NULL;
    6868#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     
    8585  //cabac coder for RDO
    8686  m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS];
     87#if FAST_BIT_EST
    8788  m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS];
     89#else
     90  m_pppcBinCoderCABAC = new TEncBinCABAC* [NUM_SAO_CABACSTATE_LABELS];
     91#endif
    8892
    8993  for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++)
    9094  {
    9195    m_pppcRDSbacCoder[cs] = new TEncSbac;
     96#if FAST_BIT_EST
    9297    m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter;
     98#else
     99    m_pppcBinCoderCABAC[cs] = new TEncBinCABAC;
     100#endif
    93101    m_pppcRDSbacCoder   [cs]->init( m_pppcBinCoderCABAC [cs] );
    94102  }
     
    99107  for(Int i=0; i< m_numCTUsPic; i++)
    100108  {
    101     m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
    102     for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     109    m_statData[i] = new SAOStatData*[MAX_NUM_COMPONENT];
     110    for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++)
    103111    {
    104112      m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     
    111119    for(Int i=0; i< m_numCTUsPic; i++)
    112120    {
    113       m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
    114       for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     121      m_preDBFstatData[i] = new SAOStatData*[MAX_NUM_COMPONENT];
     122      for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++)
    115123      {
    116124        m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     
    127135  for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
    128136  {
    129     m_skipLinesR[SAO_Y ][typeIdc]= 5;
    130     m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
    131 
    132     m_skipLinesB[SAO_Y ][typeIdc]= 4;
    133     m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     137    m_skipLinesR[COMPONENT_Y ][typeIdc]= 5;
     138    m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3;
     139
     140    m_skipLinesB[COMPONENT_Y ][typeIdc]= 4;
     141    m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2;
    134142
    135143#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     
    140148      case SAO_TYPE_EO_0:
    141149        {
    142           m_skipLinesR[SAO_Y ][typeIdc]= 5;
    143           m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
    144 
    145           m_skipLinesB[SAO_Y ][typeIdc]= 3;
    146           m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     150          m_skipLinesR[COMPONENT_Y ][typeIdc]= 5;
     151          m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3;
     152
     153          m_skipLinesB[COMPONENT_Y ][typeIdc]= 3;
     154          m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 1;
    147155        }
    148156        break;
    149157      case SAO_TYPE_EO_90:
    150158        {
    151           m_skipLinesR[SAO_Y ][typeIdc]= 4;
    152           m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
    153 
    154           m_skipLinesB[SAO_Y ][typeIdc]= 4;
    155           m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     159          m_skipLinesR[COMPONENT_Y ][typeIdc]= 4;
     160          m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 2;
     161
     162          m_skipLinesB[COMPONENT_Y ][typeIdc]= 4;
     163          m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2;
    156164        }
    157165        break;
     
    159167      case SAO_TYPE_EO_45:
    160168        {
    161           m_skipLinesR[SAO_Y ][typeIdc]= 5;
    162           m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
    163 
    164           m_skipLinesB[SAO_Y ][typeIdc]= 4;
    165           m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     169          m_skipLinesR[COMPONENT_Y ][typeIdc]= 5;
     170          m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 3;
     171
     172          m_skipLinesB[COMPONENT_Y ][typeIdc]= 4;
     173          m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 2;
    166174        }
    167175        break;
    168176      case SAO_TYPE_BO:
    169177        {
    170           m_skipLinesR[SAO_Y ][typeIdc]= 4;
    171           m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
    172 
    173           m_skipLinesB[SAO_Y ][typeIdc]= 3;
    174           m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     178          m_skipLinesR[COMPONENT_Y ][typeIdc]= 4;
     179          m_skipLinesR[COMPONENT_Cb][typeIdc]= m_skipLinesR[COMPONENT_Cr][typeIdc]= 2;
     180
     181          m_skipLinesB[COMPONENT_Y ][typeIdc]= 3;
     182          m_skipLinesB[COMPONENT_Cb][typeIdc]= m_skipLinesB[COMPONENT_Cr][typeIdc]= 1;
    175183        }
    176184        break;
     
    183191      }
    184192    }
    185 #endif   
     193#endif
    186194  }
    187195
     
    212220    for(Int i=0; i< m_numCTUsPic; i++)
    213221    {
    214       for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     222      for(Int compIdx=0; compIdx< MAX_NUM_COMPONENT; compIdx++)
    215223      {
    216224        delete[] m_statData[i][compIdx];
     
    225233    for(Int i=0; i< m_numCTUsPic; i++)
    226234    {
    227       for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     235      for(Int compIdx=0; compIdx< MAX_NUM_COMPONENT; compIdx++)
    228236      {
    229237        delete[] m_preDBFstatData[i][compIdx];
     
    237245}
    238246
    239 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 
     247Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice)
    240248{
    241249  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     
    257265  TComPicYuv* orgYuv= pPic->getPicYuvOrg();
    258266  TComPicYuv* resYuv= pPic->getPicYuvRec();
    259   m_lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2];
     267  memcpy(m_lambda, lambdas, sizeof(m_lambda));
    260268  TComPicYuv* srcYuv = m_tempPicYuv;
    261269  resYuv->copyToPic(srcYuv);
     
    271279  }
    272280#endif
    273   //slice on/off 
    274   decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 
    275 
    276   //block on/off 
     281  //slice on/off
     282  decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth());
     283
     284  //block on/off
    277285  SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters
    278286  decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam());
    279287  delete[] reconParams;
    280 
    281288}
    282289
     
    291298  for(Int n=0; n< m_numCTUsPic; n++)
    292299  {
    293     for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     300    for(Int compIdx=0; compIdx < MAX_NUM_COMPONENT; compIdx++)
    294301    {
    295302      for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     
    311318  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
    312319
    313   for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
    314   {
    315     Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
    316     Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     320  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     321
     322  for(Int ctuRsAddr= 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++)
     323  {
     324    Int yPos   = (ctuRsAddr / m_numCTUInWidth)*m_maxCUHeight;
     325    Int xPos   = (ctuRsAddr % m_numCTUInWidth)*m_maxCUWidth;
    317326    Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
    318327    Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
    319328
    320     pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     329    pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctuRsAddr, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
    321330
    322331    //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities.
     
    329338    isAboveRightAvail = ((yPos > 0) && (isRightAvail));
    330339
    331     for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
    332     {
    333       Bool isLuma     = (compIdx == SAO_Y);
    334       Int  formatShift= isLuma?0:1;
    335 
    336       Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
    337       Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
    338 
    339       Int  orgStride  = isLuma?orgYuv->getStride():orgYuv->getCStride();
    340       Pel* orgBlk     = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift);
    341 
    342       getBlkStats(compIdx, blkStats[ctu][compIdx] 
    343                 , srcBlk, orgBlk, srcStride, orgStride, (width  >> formatShift), (height >> formatShift)
     340    for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     341    {
     342      const ComponentID component = ComponentID(compIdx);
     343
     344      const UInt componentScaleX = getComponentScaleX(component, pPic->getChromaFormat());
     345      const UInt componentScaleY = getComponentScaleY(component, pPic->getChromaFormat());
     346
     347      Int  srcStride  = srcYuv->getStride(component);
     348      Pel* srcBlk     = srcYuv->getAddr(component) + ((yPos >> componentScaleY) * srcStride) + (xPos >> componentScaleX);
     349
     350      Int  orgStride  = orgYuv->getStride(component);
     351      Pel* orgBlk     = orgYuv->getAddr(component) + ((yPos >> componentScaleY) * orgStride) + (xPos >> componentScaleX);
     352
     353      getBlkStats(component, blkStats[ctuRsAddr][component]
     354                , srcBlk, orgBlk, srcStride, orgStride, (width  >> componentScaleX), (height >> componentScaleY)
    344355                , isLeftAvail,  isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail
    345356#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     
    355366{
    356367  //decide sliceEnabled[compIdx]
    357   for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     368  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     369  for (Int compIdx = 0; compIdx < MAX_NUM_COMPONENT; compIdx++)
     370  {
     371    sliceEnabled[compIdx] = false;
     372  }
     373
     374  for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
    358375  {
    359376    // reset flags & counters
     
    363380#if SAO_ENCODING_CHOICE_CHROMA
    364381    // decide slice-level on/off based on previous results
    365     if( (picTempLayer > 0) 
    366       && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) )
     382    if( (picTempLayer > 0)
     383      && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==COMPONENT_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) )
    367384    {
    368385      sliceEnabled[compIdx] = false;
     
    370387#else
    371388    // decide slice-level on/off based on previous results
    372     if( (picTempLayer > 0) 
    373       && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) )
     389    if( (picTempLayer > 0)
     390      && (m_saoDisabledRate[COMPONENT_Y][0] > SAO_ENCODING_RATE) )
    374391    {
    375392      sliceEnabled[compIdx] = false;
     
    380397}
    381398
    382 Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData)
    383 {
    384   Int64 dist=0;
    385   Int inputBitDepth    = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ;
    386   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8);
     399Int64 TEncSampleAdaptiveOffset::getDistortion(ComponentID compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData)
     400{
     401  Int64 dist        = 0;
     402  Int shift         = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepth[toChannelType(compIdx)] - 8);
    387403
    388404  switch(typeIdc)
     
    396412        {
    397413          dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift);
    398         }       
     414        }
    399415      }
    400416      break;
     
    403419        for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++)
    404420        {
    405           Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 
     421          Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ;
    406422          dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift);
    407423        }
     
    432448  Int offsetOutput = 0;
    433449  iterOffset = offsetInput;
    434   // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here. 
    435   tempMinCost = lambda; 
     450  // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.
     451  tempMinCost = lambda;
    436452  while (iterOffset != 0)
    437453  {
    438454    // Calculate the bits required for signaling the offset
    439     tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 
    440     if (abs((Int)iterOffset)==offsetTh) //inclusive 
    441     { 
     455    tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
     456    if (abs((Int)iterOffset)==offsetTh) //inclusive
     457    {
    442458      tempRate --;
    443459    }
     
    458474}
    459475
    460 
    461 Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo)
    462 {
    463   Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC;
    464   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
     476Void TEncSampleAdaptiveOffset::deriveOffsets(ComponentID compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo)
     477{
     478  Int bitDepth = g_bitDepth[toChannelType(compIdx)];
     479  Int shift    = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
    465480#if SVC_EXTENSION
    466481  Int offsetTh = getSaoMaxOffsetQVal()[compIdx];  //inclusive
     
    471486  ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
    472487
    473   //derive initial offsets 
     488  //derive initial offsets
    474489  Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES);
    475490  for(Int classIdx=0; classIdx< numClasses; classIdx++)
    476491  {
    477     if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN)  ) 
     492    if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN)  )
    478493    {
    479494      continue; //offset will be zero
     
    485500    }
    486501
    487     quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 
    488                                                                   / 
     502    quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8))
     503                                                                  /
    489504                                                          (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx])
    490505                                               );
     
    502517        Int64 classDist;
    503518        Double classCost;
    504         for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 
    505         {         
     519        for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++)
     520        {
    506521          if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
    507522          if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     
    514529          }
    515530        }
    516      
     531
    517532        typeAuxInfo =0;
    518533      }
     
    524539        ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES);
    525540        for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++)
    526         {         
     541        {
    527542          costBOClasses[classIdx]= m_lambda[compIdx];
    528543          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     
    534549        //decide the starting band index
    535550        Double minCost = MAX_DOUBLE, cost;
    536         for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 
     551        for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++)
    537552        {
    538553          cost  = costBOClasses[band  ];
     
    550565        Int clearQuantOffset[NUM_SAO_BO_CLASSES];
    551566        ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES);
    552         for(Int i=0; i< 4; i++) 
     567        for(Int i=0; i< 4; i++)
    553568        {
    554569          Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES;
    555570          clearQuantOffset[band] = quantOffsets[band];
    556571        }
    557         ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES);       
     572        ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES);
    558573      }
    559574      break;
     
    570585}
    571586
    572 
    573 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     587Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
    574588{
    575589  Double minCost, cost;
    576   Int rate;
    577590  UInt previousWrittenBits;
    578   Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS];
    579   SAOOffset testOffset[NUM_SAO_COMPONENTS];
    580   Int compIdx;
     591  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     592
     593  Int64 dist[MAX_NUM_COMPONENT], modeDist[MAX_NUM_COMPONENT];
     594  SAOOffset testOffset[MAX_NUM_COMPONENT];
    581595  Int invQuantOffset[MAX_NUM_SAO_CLASSES];
    582 
    583   modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0;
     596  for(Int comp=0; comp < MAX_NUM_COMPONENT; comp++)
     597  {
     598    modeDist[comp] = 0;
     599  }
    584600
    585601  //pre-encode merge flags
    586   modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
     602  modeParam[COMPONENT_Y].modeIdc = SAO_MODE_OFF;
    587603  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
    588604#if SVC_EXTENSION
     
    593609  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
    594610
    595   //------ luma --------//
    596   compIdx = SAO_Y;
    597   //"off" case as initial cost
    598   modeParam[compIdx].modeIdc = SAO_MODE_OFF;
    599   m_pcRDGoOnSbacCoder->resetBits();
     611    //------ luma --------//
     612  {
     613    ComponentID compIdx = COMPONENT_Y;
     614    //"off" case as initial cost
     615    modeParam[compIdx].modeIdc = SAO_MODE_OFF;
     616    m_pcRDGoOnSbacCoder->resetBits();
    600617#if SVC_EXTENSION
    601   m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
    602 #else
    603   m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
    604 #endif
    605   modeDist[compIdx] = 0;
    606   minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits());
    607   m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
    608   if(sliceEnabled[compIdx])
    609   {
    610     for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
    611     {
    612       testOffset[compIdx].modeIdc = SAO_MODE_NEW;
    613       testOffset[compIdx].typeIdc = typeIdc;
    614 
    615       //derive coded offset
    616       deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
    617 
    618       //inversed quantized offsets
    619       invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
    620 
    621       //get distortion
    622       dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
    623 
    624       //get rate
    625       m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
    626       m_pcRDGoOnSbacCoder->resetBits();
     618    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
     619#else
     620    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
     621#endif
     622    modeDist[compIdx] = 0;
     623    minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits());
     624    m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     625    if(sliceEnabled[compIdx])
     626    {
     627      for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     628      {
     629        testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     630        testOffset[compIdx].typeIdc = typeIdc;
     631
     632        //derive coded offset
     633        deriveOffsets(compIdx, typeIdc, blkStats[ctuRsAddr][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     634
     635        //inversed quantized offsets
     636        invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     637
     638        //get distortion
     639        dist[compIdx] = getDistortion(compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][compIdx][typeIdc]);
     640
     641        //get rate
     642        m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     643        m_pcRDGoOnSbacCoder->resetBits();
    627644#if SVC_EXTENSION
    628       m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
    629 #else
    630       m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
    631 #endif
    632       rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    633       cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate);
    634       if(cost < minCost)
    635       {
    636         minCost = cost;
    637         modeDist[compIdx] = dist[compIdx];
    638         modeParam[compIdx]= testOffset[compIdx];
    639         m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
    640       }
    641     }
    642   }
    643   m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
    644   m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     645        m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
     646#else
     647        m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
     648#endif
     649        Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     650        cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate);
     651        if(cost < minCost)
     652        {
     653          minCost = cost;
     654          modeDist[compIdx] = dist[compIdx];
     655          modeParam[compIdx]= testOffset[compIdx];
     656          m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     657        }
     658      }
     659    }
     660    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     661    m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     662  }
    645663
    646664  //------ chroma --------//
    647   //"off" case as initial cost
     665//"off" case as initial cost
    648666  cost = 0;
    649667  previousWrittenBits = 0;
    650668  m_pcRDGoOnSbacCoder->resetBits();
    651   for (Int component = SAO_Cb; component < NUM_SAO_COMPONENTS; component++)
    652   {
    653     modeParam[component].modeIdc = SAO_MODE_OFF;
    654     modeDist [component] = 0;
     669  for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++)
     670  {
     671    const ComponentID component = ComponentID(componentIndex);
     672
     673    modeParam[component].modeIdc = SAO_MODE_OFF;
     674    modeDist [component]         = 0;
    655675
    656676#if SVC_EXTENSION
     
    676696    cost = 0;
    677697
    678     for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
    679     {
    680       if(!sliceEnabled[compIdx])
    681       {
    682         testOffset[compIdx].modeIdc = SAO_MODE_OFF;
    683         dist[compIdx]= 0;
     698    for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++)
     699    {
     700      const ComponentID component = ComponentID(componentIndex);
     701      if(!sliceEnabled[component])
     702      {
     703        testOffset[component].modeIdc = SAO_MODE_OFF;
     704        dist[component]= 0;
    684705        continue;
    685706      }
    686       testOffset[compIdx].modeIdc = SAO_MODE_NEW;
    687       testOffset[compIdx].typeIdc = typeIdc;
     707      testOffset[component].modeIdc = SAO_MODE_NEW;
     708      testOffset[component].typeIdc = typeIdc;
    688709
    689710      //derive offset & get distortion
    690       deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
    691       invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
    692       dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     711      deriveOffsets(component, typeIdc, blkStats[ctuRsAddr][component][typeIdc], testOffset[component].offset, testOffset[component].typeAuxInfo);
     712      invertQuantOffsets(component, typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, testOffset[component].offset);
     713      dist[component] = getDistortion(component, typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][component][typeIdc]);
    693714
    694715#if SVC_EXTENSION
    695       m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
    696 #else
    697       m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
     716      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, testOffset[component], sliceEnabled[component], getSaoMaxOffsetQVal());
     717#else
     718      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, testOffset[component], sliceEnabled[component]);
    698719#endif
    699720
    700721      const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    701       cost += dist[compIdx] + (m_lambda[compIdx] * (currentWrittenBits - previousWrittenBits));
     722      cost += dist[component] + (m_lambda[component] * (currentWrittenBits - previousWrittenBits));
    702723      previousWrittenBits = currentWrittenBits;
    703724    }
     
    706727    {
    707728      minCost = cost;
    708       for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
    709       {
    710         modeDist [compIdx] = dist      [compIdx];
    711         modeParam[compIdx] = testOffset[compIdx];
    712       }
    713     }
    714   }
    715 
     729      for(UInt componentIndex = COMPONENT_Cb; componentIndex < numberOfComponents; componentIndex++)
     730      {
     731        modeDist[componentIndex]  = dist[componentIndex];
     732        modeParam[componentIndex] = testOffset[componentIndex];
     733      }
     734    }
     735
     736  } // SAO_TYPE loop
    716737
    717738  //----- re-gen rate & normalized cost----//
    718739  modeNormCost = 0;
    719   for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++)
    720   {
    721     modeNormCost += (Double)modeDist[component] / m_lambda[component];
    722   }
     740  for(UInt componentIndex = COMPONENT_Y; componentIndex < numberOfComponents; componentIndex++)
     741  {
     742    modeNormCost += (Double)modeDist[componentIndex] / m_lambda[componentIndex];
     743  }
     744
    723745  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
    724746  m_pcRDGoOnSbacCoder->resetBits();
     
    729751#endif
    730752  modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    731 
    732 }
    733 
    734 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
    735 {
    736   Int mergeListSize = (Int)mergeList.size();
     753}
     754
     755Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     756{
    737757  modeNormCost = MAX_DOUBLE;
    738758
    739759  Double cost;
    740760  SAOBlkParam testBlkParam;
    741 
    742   for(Int mergeType=0; mergeType< mergeListSize; mergeType++)
     761  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     762
     763  for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++)
    743764  {
    744765    if(mergeList[mergeType] == NULL)
     
    750771    //normalized distortion
    751772    Double normDist=0;
    752     for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     773    for(Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
    753774    {
    754775      testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE;
     
    760781      {
    761782        //offsets have been reconstructed. Don't call inversed quantization function.
    762         normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))
     783        normDist += (((Double)getDistortion(ComponentID(compIdx), mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctuRsAddr][compIdx][mergedOffsetParam.typeIdc]))
    763784                       /m_lambda[compIdx]
    764785                    );
     
    788809
    789810  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
    790 
    791 
    792811}
    793812
    794813Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams)
    795814{
    796   Bool isAllBlksDisabled = false;
    797   if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr])
    798   {
    799     isAllBlksDisabled = true;
     815  Bool allBlksDisabled = true;
     816  const Int numberOfComponents = getNumberValidComponents(m_chromaFormatIDC);
     817  for(Int compId = COMPONENT_Y; compId < numberOfComponents; compId++)
     818  {
     819    if (sliceEnabled[compId])
     820      allBlksDisabled = false;
    800821  }
    801822
     
    805826  Double minCost, modeCost;
    806827
    807   for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
    808   {
    809     if(isAllBlksDisabled)
    810     {
    811       codedParams[ctu].reset();
     828
     829#if RD_TEST_SAO_DISABLE_AT_PICTURE_LEVEL
     830  Double totalCost = 0;
     831#endif
     832
     833  for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++)
     834  {
     835    if(allBlksDisabled)
     836    {
     837      codedParams[ctuRsAddr].reset();
    812838      continue;
    813839    }
     
    816842
    817843    //get merge list
    818     std::vector<SAOBlkParam*> mergeList;
    819     getMergeList(pic, ctu, reconParams, mergeList);
     844    SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES] = { NULL };
     845    getMergeList(pic, ctuRsAddr, reconParams, mergeList);
    820846
    821847    minCost = MAX_DOUBLE;
     
    831857      case SAO_MODE_NEW:
    832858        {
    833           deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     859          deriveModeNewRDO(ctuRsAddr, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
    834860
    835861        }
     
    837863      case SAO_MODE_MERGE:
    838864        {
    839           deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     865          deriveModeMergeRDO(ctuRsAddr, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
    840866        }
    841867        break;
     
    851877      {
    852878        minCost = modeCost;
    853         codedParams[ctu] = modeParam;
     879        codedParams[ctuRsAddr] = modeParam;
    854880        m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
    855 
    856881      }
    857882    } //mode
     883
     884#if RD_TEST_SAO_DISABLE_AT_PICTURE_LEVEL
     885    totalCost += minCost;
     886#endif
     887
    858888    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
    859889
    860890    //apply reconstructed offsets
    861     reconParams[ctu] = codedParams[ctu];
    862     reconstructBlkSAOParam(reconParams[ctu], mergeList);
    863     offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic);
    864   } //ctu
    865 
    866 #if SAO_ENCODING_CHOICE
     891    reconParams[ctuRsAddr] = codedParams[ctuRsAddr];
     892    reconstructBlkSAOParam(reconParams[ctuRsAddr], mergeList);
     893    offsetCTU(ctuRsAddr, srcYuv, resYuv, reconParams[ctuRsAddr], pic);
     894  } //ctuRsAddr
     895
     896#if RD_TEST_SAO_DISABLE_AT_PICTURE_LEVEL
     897  if (!allBlksDisabled && (totalCost >= 0)) //SAO is not beneficial - disable it
     898  {
     899    for(Int ctuRsAddr = 0; ctuRsAddr < m_numCTUsPic; ctuRsAddr++)
     900    {
     901      codedParams[ctuRsAddr].reset();
     902    }
     903
     904    for (UInt componentIndex = 0; componentIndex < MAX_NUM_COMPONENT; componentIndex++)
     905    {
     906      sliceEnabled[componentIndex] = false;
     907    }
     908
     909    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]);
     910  }
     911#endif
     912
     913#if SAO_ENCODING_CHOICE
    867914  Int picTempLayer = pic->getSlice(0)->getDepth();
    868   Int numLcusForSAOOff[NUM_SAO_COMPONENTS];
    869   numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0;
    870 
    871   for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
    872   {
    873     for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
    874     {
    875       if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF)
    876       {
    877         numLcusForSAOOff[compIdx]++;
     915  Int numCtusForSAOOff[MAX_NUM_COMPONENT];
     916
     917  for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     918  {
     919    numCtusForSAOOff[compIdx] = 0;
     920    for(Int ctuRsAddr=0; ctuRsAddr< m_numCTUsPic; ctuRsAddr++)
     921    {
     922      if( reconParams[ctuRsAddr][compIdx].modeIdc == SAO_MODE_OFF)
     923      {
     924        numCtusForSAOOff[compIdx]++;
    878925      }
    879926    }
    880927  }
    881928#if SAO_ENCODING_CHOICE_CHROMA
    882   for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
    883   {
    884     m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic;
     929  for (Int compIdx = 0; compIdx < numberOfComponents; compIdx++)
     930  {
     931    m_saoDisabledRate[compIdx][picTempLayer] = (Double)numCtusForSAOOff[compIdx]/(Double)m_numCTUsPic;
    885932  }
    886933#else
    887934  if (picTempLayer == 0)
    888935  {
    889     m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3);
    890   }
    891 #endif                                             
    892 #endif
    893 }
    894 
    895 
    896 Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 
     936    m_saoDisabledRate[COMPONENT_Y][0] = (Double)(numCtusForSAOOff[COMPONENT_Y]+numCtusForSAOOff[COMPONENT_Cb]+numCtusForSAOOff[COMPONENT_Cr])/(Double)(m_numCTUsPic*3);
     937  }
     938#endif
     939#endif
     940}
     941
     942
     943Void TEncSampleAdaptiveOffset::getBlkStats(ComponentID compIdx, SAOStatData* statsDataTypes
    897944                        , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height
    898945                        , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     
    907954
    908955    if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
    909     m_signLineBuf1 = new Char[m_lineBufWidth+1]; 
     956    m_signLineBuf1 = new Char[m_lineBufWidth+1];
    910957
    911958    if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     
    952999        for (y=0; y<endY; y++)
    9531000        {
    954 #if SAO_SGN_FUNC
    9551001          signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
    956 #else
    957           signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
    958 #endif
    9591002          for (x=startX; x<endX; x++)
    9601003          {
    961 #if SAO_SGN_FUNC
    9621004            signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
    963 #else
    964             signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
    965 #endif
    9661005            edgeType  =  signRight + signLeft;
    9671006            signLeft  = -signRight;
     
    9831022            for(y=0; y<skipLinesB[typeIdx]; y++)
    9841023            {
    985 #if SAO_SGN_FUNC
    9861024              signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
    987 #else
    988               signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
    989 #endif
    9901025              for (x=startX; x<endX; x++)
    9911026              {
    992 #if SAO_SGN_FUNC
    9931027                signRight =  (Char)sgn(srcLine[x] - srcLine[x+1]);
    994 #else
    995                 signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
    996 #endif
    9971028                edgeType  =  signRight + signLeft;
    9981029                signLeft  = -signRight;
     
    10221053        startY = isAboveAvail ? 0 : 1;
    10231054#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
    1024         endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 
     1055        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
    10251056                                                 : width
    10261057                                                 ;
     
    10371068        Pel* srcLineAbove = srcLine - srcStride;
    10381069#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
    1039         for (x=startX; x<endX; x++)
    1040 #else
    1041         for (x=0; x< endX; x++)
    1042 #endif
    1043         {
    1044 #if SAO_SGN_FUNC
     1070        for (x=startX; x<endX; x++)
     1071#else
     1072        for (x=0; x< endX; x++)
     1073#endif
     1074        {
    10451075          signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
    1046 #else
    1047           signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
    1048 #endif
    10491076        }
    10501077
     
    10601087#endif
    10611088          {
    1062 #if SAO_SGN_FUNC
    10631089            signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]);
    1064 #else
    1065             signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
    1066 #endif
    10671090            edgeType  = signDown + signUpLine[x];
    10681091            signUpLine[x]= -signDown;
     
    10891112              for (x=startX; x<endX; x++)
    10901113              {
    1091 #if SAO_SGN_FUNC
    10921114                edgeType = sgn(srcLine[x] - srcLineBelow[x]) + sgn(srcLine[x] - srcLineAbove[x]);
    1093 #else
    1094                 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
    1095 #endif
    10961115                diff [edgeType] += (orgLine[x] - srcLine[x]);
    10971116                count[edgeType] ++;
     
    11361155        for (x=startX; x<endX+1; x++)
    11371156        {
    1138 #if SAO_SGN_FUNC
    11391157          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x-1]);
    1140 #else
    1141           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
    1142 #endif
    11431158        }
    11441159
     
    11541169        for(x=firstLineStartX; x<firstLineEndX; x++)
    11551170        {
    1156 #if SAO_SGN_FUNC
    11571171          edgeType = sgn(srcLine[x] - srcLineAbove[x-1]) - signUpLine[x+1];
    1158 #else
    1159           edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
    1160 #endif
    11611172          diff [edgeType] += (orgLine[x] - srcLine[x]);
    11621173          count[edgeType] ++;
     
    11731184          for (x=startX; x<endX; x++)
    11741185          {
    1175 #if SAO_SGN_FUNC
    11761186            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x+1]);
    1177 #else
    1178             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
    1179 #endif
    11801187            edgeType = signDown + signUpLine[x];
    11811188            diff [edgeType] += (orgLine[x] - srcLine[x]);
    11821189            count[edgeType] ++;
    11831190
    1184             signDownLine[x+1] = -signDown; 
     1191            signDownLine[x+1] = -signDown;
    11851192          }
    1186 #if SAO_SGN_FUNC
    11871193          signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
    1188 #else
    1189           signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
    1190 #endif
    11911194
    11921195          signTmpLine  = signUpLine;
     
    12121215              for (x=startX; x< endX; x++)
    12131216              {
    1214 #if SAO_SGN_FUNC
    12151217                edgeType = sgn(srcLine[x] - srcLineBelow[x+1]) + sgn(srcLine[x] - srcLineAbove[x-1]);
    1216 #else
    1217                 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
    1218 #endif
    12191218                diff [edgeType] += (orgLine[x] - srcLine[x]);
    12201219                count[edgeType] ++;
     
    12541253        for (x=startX-1; x<endX; x++)
    12551254        {
    1256 #if SAO_SGN_FUNC
    12571255          signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
    1258 #else
    1259           signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
    1260 #endif
    12611256        }
    12621257
     
    12771272        for(x=firstLineStartX; x<firstLineEndX; x++)
    12781273        {
    1279 #if SAO_SGN_FUNC
    12801274          edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) - signUpLine[x-1];
    1281 #else
    1282           edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
    1283 #endif
    12841275          diff [edgeType] += (orgLine[x] - srcLine[x]);
    12851276          count[edgeType] ++;
     
    12961287          for(x=startX; x<endX; x++)
    12971288          {
    1298 #if SAO_SGN_FUNC
    12991289            signDown = (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
    1300 #else
    1301             signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
    1302 #endif
    13031290            edgeType = signDown + signUpLine[x];
    13041291
     
    13061293            count[edgeType] ++;
    13071294
    1308             signUpLine[x-1] = -signDown; 
     1295            signUpLine[x-1] = -signDown;
    13091296          }
    1310 #if SAO_SGN_FUNC
    13111297          signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
    1312 #else
    1313           signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
    1314 #endif
    13151298          srcLine  += srcStride;
    13161299          orgLine  += orgStride;
     
    13311314              for (x=startX; x<endX; x++)
    13321315              {
    1333 #if SAO_SGN_FUNC
    13341316                edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + sgn(srcLine[x] - srcLineAbove[x+1]);
    1335 #else
    1336                 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
    1337 #endif
    13381317                diff [edgeType] += (orgLine[x] - srcLine[x]);
    13391318                count[edgeType] ++;
     
    13601339#endif
    13611340        endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height;
    1362         Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
     1341        Int shiftBits = g_bitDepth[toChannelType(compIdx)] - NUM_SAO_BO_CLASSES_LOG2;
    13631342        for (y=0; y< endY; y++)
    13641343        {
     
    13701349          {
    13711350
    1372             Int bandIdx= srcLine[x] >> shiftBits; 
     1351            Int bandIdx= srcLine[x] >> shiftBits;
    13731352            diff [bandIdx] += (orgLine[x] - srcLine[x]);
    13741353            count[bandIdx] ++;
     
    13891368              for (x=startX; x< endX; x++)
    13901369              {
    1391                 Int bandIdx= srcLine[x] >> shiftBits; 
     1370                Int bandIdx= srcLine[x] >> shiftBits;
    13921371                diff [bandIdx] += (orgLine[x] - srcLine[x]);
    13931372                count[bandIdx] ++;
     
    14131392}
    14141393
     1394
    14151395//! \}
Note: See TracChangeset for help on using the changeset viewer.