Changeset 540 in SHVCSoftware for trunk/source/Lib


Ignore:
Timestamp:
9 Jan 2014, 05:04:17 (11 years ago)
Author:
seregin
Message:

merge SHM-4.1-dev branch

Location:
trunk
Files:
55 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

  • trunk/source/Lib/TAppCommon/program_options_lite.cpp

    r313 r540  
    3838#include <list>
    3939#include <map>
     40#include <algorithm>
    4041#include "program_options_lite.h"
    4142
  • trunk/source/Lib/TLibCommon/CommonDef.h

    r499 r540  
    4040
    4141#include <algorithm>
    42 
    4342#if _MSC_VER > 1000
    4443// disable "signed and unsigned mismatch"
     
    5756
    5857#if SVC_EXTENSION
    59 #define NV_VERSION        "4.0"                 ///< Current software version
     58#include <vector>
     59#define NV_VERSION        "4.1"                 ///< Current software version
    6060#else
    61 #define NV_VERSION        "12.0"                ///< Current software version
     61#define NV_VERSION        "12.1"                ///< Current software version
    6262#endif
    6363
     
    209209 
    210210  NAL_UNIT_CODED_SLICE_TSA_N,     // 2
    211   NAL_UNIT_CODED_SLICE_TLA_R,       // 3
     211  NAL_UNIT_CODED_SLICE_TSA_R,       // 3
    212212 
    213213  NAL_UNIT_CODED_SLICE_STSA_N,    // 4
     
    280280};
    281281
     282#if OUTPUT_LAYER_SET_INDEX
     283class CommonDecoderParams
     284{
     285  Int m_targetLayerId;
     286  Int m_outputLayerSetIdx;
     287  std::vector<Int> *m_targetDecLayerIdSet;
     288  Bool m_valueCheckedFlag;
     289public:
     290  CommonDecoderParams():
     291    m_targetLayerId(0)
     292    , m_outputLayerSetIdx(-1)
     293    , m_targetDecLayerIdSet(NULL)
     294    , m_valueCheckedFlag(false)
     295 {}
     296
     297  Void setTargetLayerId(const Int x) { m_targetLayerId = x;   }
     298  Int  getTargetLayerId()            { return m_targetLayerId;}
     299 
     300  Void setOutputLayerSetIdx(const Int x) { m_outputLayerSetIdx = x;   }
     301  Int  getOutputLayerSetIdx()            { return m_outputLayerSetIdx;}
     302
     303  Void               setTargetDecLayerIdSet(std::vector<Int> *x) { m_targetDecLayerIdSet = x;   }
     304  std::vector<Int>*  getTargetDecLayerIdSet()                    { return m_targetDecLayerIdSet;}
     305 
     306  Void setValueCheckedFlag(const Bool x) { m_valueCheckedFlag = x;   }
     307  Bool getValueCheckedFlag()            { return m_valueCheckedFlag;}
     308 
     309};
     310#endif
    282311//! \}
    283312
  • trunk/source/Lib/TLibCommon/NAL.h

    r313 r540  
    7676    return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R
    7777        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N
    78         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA_R
     78        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R
    7979        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N
    8080        || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R
  • trunk/source/Lib/TLibCommon/TComDataCU.cpp

    r494 r540  
    309309  }
    310310}
    311 
     311#if !HM_CLEANUP_SAO
    312312const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
    313313{
     
    328328}
    329329
    330 
     330#endif
    331331// ====================================================================================================================
    332332// Public member functions
     
    36383638  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU;
    36393639}
    3640 
     3640#if !HM_CLEANUP_SAO
    36413641/** Set neighboring blocks availabilities for non-deblocked filtering
    36423642 * \param numLCUInPicWidth number of LCUs in picture width
     
    40084008}
    40094009
     4010#endif
     4011
    40104012#if SVC_EXTENSION
    40114013TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping )
     
    40284030#endif
    40294031
     4032#if O0098_SCALED_REF_LAYER_ID
     4033  Int leftStartL = getSlice()->getSPS()->getScaledRefLayerWindowForLayer(getSlice()->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
     4034  Int topStartL  = getSlice()->getSPS()->getScaledRefLayerWindowForLayer(getSlice()->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowTopOffset();
     4035#else
    40304036  Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
    40314037  Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
     4038#endif
    40324039  Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
    40334040  Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
  • trunk/source/Lib/TLibCommon/TComDataCU.h

    r494 r540  
    5555//! \{
    5656
     57#if !HM_CLEANUP_SAO
    5758// ====================================================================================================================
    5859// Non-deblocking in-loop filter processing block data structure
     
    9293  const NDBFBlockInfo& operator= (const NDBFBlockInfo& src);  //!< "=" operator
    9394};
     95#endif
    9496
    9597
     
    159161  Pel*          m_pcIPCMSampleCr;     ///< PCM sample buffer (Cr)
    160162
     163#if !HM_CLEANUP_SAO
    161164  Int*          m_piSliceSUMap;       ///< pointer of slice ID map
    162165  std::vector<NDBFBlockInfo> m_vNDFBlock;
    163 
     166#endif
    164167  // -------------------------------------------------------------------------------------------------------------------
    165168  // neighbour access variables
     
    389392  Void          setIPCMFlagSubParts   (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth);
    390393
     394#if !HM_CLEANUP_SAO
    391395  /// get slice ID for SU
    392396  Int           getSUSliceID          (UInt uiIdx)              {return m_piSliceSUMap[uiIdx];      }
     
    403407                                          ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
    404408                                          ,Bool bIndependentTileBoundaryEnabled );
     409#endif
    405410  // -------------------------------------------------------------------------------------------------------------------
    406411  // member functions for accessing partition information
  • trunk/source/Lib/TLibCommon/TComPic.cpp

    r494 r540  
    5959, m_bNeededForOutput                      (false)
    6060, m_uiCurrSliceIdx                        (0)
     61#if !HM_CLEANUP_SAO
    6162, m_pSliceSUMap                           (NULL)
    6263, m_pbValidSlice                          (NULL)
     
    6566, m_bIndependentTileBoundaryForNDBFilter  (false)
    6667, m_pNDBFilterYuvTmp                      (NULL)
     68#endif
    6769, m_bCheckLTMSB                           (false)
    6870{
     
    212214  }
    213215}
    214 
     216#if HM_CLEANUP_SAO
     217Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
     218{
     219  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU()));
     220  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
     221  return (mergeCtbInSliceSeg && mergeCtbInTile);
     222}
     223#else
    215224/** Create non-deblocked filter information
    216225 * \param pSliceStartAddress array for storing slice start addresses
     
    548557
    549558}
     559#endif
    550560
    551561#if SVC_EXTENSION
  • trunk/source/Lib/TLibCommon/TComPic.h

    r494 r540  
    7575  Bool                  m_bNeededForOutput;
    7676  UInt                  m_uiCurrSliceIdx;         // Index of current slice
     77#if !HM_CLEANUP_SAO
    7778  Int*                  m_pSliceSUMap;
    7879  Bool*                 m_pbValidSlice;
     
    8182  Bool                  m_bIndependentTileBoundaryForNDBFilter;
    8283  TComPicYuv*           m_pNDBFilterYuvTmp;    //!< temporary picture buffer when non-cross slice/tile boundary in-loop filtering is enabled
     84#endif
    8385  Bool                  m_bCheckLTMSB;
    8486 
     
    199201  Window&       getDefDisplayWindow()   { return m_defaultDisplayWindow; }
    200202
     203#if HM_CLEANUP_SAO
     204  Bool          getSAOMergeAvailability(Int currAddr, Int mergeAddr);
     205#else
    201206  Void          createNonDBFilterInfo   (std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
    202207                                        ,std::vector<Bool>* LFCrossSliceBoundary
     
    211216  TComPicYuv*   getYuvPicBufferForIndependentBoundaryProcessing()             {return m_pNDBFilterYuvTmp;}
    212217  std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
     218#endif
    213219
    214220  /* field coding parameters*/
  • trunk/source/Lib/TLibCommon/TComPicSym.cpp

    r442 r540  
    6767,m_puiTileIdxMap(NULL)
    6868,m_puiInverseCUOrderMap(NULL)
     69#if HM_CLEANUP_SAO
     70,m_saoBlkParams(NULL)
     71#endif
    6972{};
    7073
     
    127130    m_puiInverseCUOrderMap[i] = i;
    128131  }
     132
     133#if HM_CLEANUP_SAO
     134  m_saoBlkParams = new SAOBlkParam[m_uiNumCUsInFrame];
     135#else
    129136  m_saoParam = NULL;
     137#endif
    130138}
    131139
     
    183191  m_puiInverseCUOrderMap = NULL;
    184192 
     193#if HM_CLEANUP_SAO
     194  if(m_saoBlkParams)
     195  {
     196    delete[] m_saoBlkParams; m_saoBlkParams = NULL;
     197  }
     198#else
    185199  if (m_saoParam)
    186200  {
     
    189203    m_saoParam = NULL;
    190204  }
     205#endif
    191206}
    192207
     
    332347}
    333348
     349
     350#if HM_CLEANUP_SAO
     351Void TComPicSym::deriveLoopFilterBoundaryAvailibility(Int ctu,
     352                                                      Bool& isLeftAvail,
     353                                                      Bool& isRightAvail,
     354                                                      Bool& isAboveAvail,
     355                                                      Bool& isBelowAvail,
     356                                                      Bool& isAboveLeftAvail,
     357                                                      Bool& isAboveRightAvail,
     358                                                      Bool& isBelowLeftAvail,
     359                                                      Bool& isBelowRightAvail
     360                                                      )
     361{
     362
     363  isLeftAvail      = (ctu % m_uiWidthInCU != 0);
     364  isRightAvail     = (ctu % m_uiWidthInCU != m_uiWidthInCU-1);
     365  isAboveAvail     = (ctu >= m_uiWidthInCU );
     366  isBelowAvail     = (ctu <  m_uiNumCUsInFrame - m_uiWidthInCU);
     367  isAboveLeftAvail = (isAboveAvail && isLeftAvail);
     368  isAboveRightAvail= (isAboveAvail && isRightAvail);
     369  isBelowLeftAvail = (isBelowAvail && isLeftAvail);
     370  isBelowRightAvail= (isBelowAvail && isRightAvail);
     371
     372  Bool isLoopFiltAcrossTilePPS = getCU(ctu)->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     373
     374  {
     375    TComDataCU* ctuCurr  = getCU(ctu);
     376    TComDataCU* ctuLeft  = isLeftAvail ?getCU(ctu-1):NULL;
     377    TComDataCU* ctuRight = isRightAvail?getCU(ctu+1):NULL;
     378    TComDataCU* ctuAbove = isAboveAvail?getCU(ctu-m_uiWidthInCU):NULL;
     379    TComDataCU* ctuBelow = isBelowAvail?getCU(ctu+m_uiWidthInCU):NULL;
     380    TComDataCU* ctuAboveLeft  = isAboveLeftAvail ? getCU(ctu-m_uiWidthInCU-1):NULL;
     381    TComDataCU* ctuAboveRigtht= isAboveRightAvail? getCU(ctu-m_uiWidthInCU+1):NULL;
     382    TComDataCU* ctuBelowLeft  = isBelowLeftAvail ? getCU(ctu+m_uiWidthInCU-1):NULL;
     383    TComDataCU* ctuBelowRight = isBelowRightAvail? getCU(ctu+m_uiWidthInCU+1):NULL;
     384
     385    {
     386      //left
     387      if(ctuLeft != NULL)
     388      {
     389        isLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
     390      }
     391      //above
     392      if(ctuAbove != NULL)
     393      {
     394        isAboveAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAbove->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
     395      }
     396      //right
     397      if(ctuRight != NULL)
     398      {
     399        isRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuRight->getSlice()->getSliceCurStartCUAddr())?ctuRight->getSlice()->getLFCrossSliceBoundaryFlag():true;
     400      }
     401      //below
     402      if(ctuBelow != NULL)
     403      {
     404        isBelowAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelow->getSlice()->getSliceCurStartCUAddr())?ctuBelow->getSlice()->getLFCrossSliceBoundaryFlag():true;
     405      }
     406      //above-left
     407      if(ctuAboveLeft != NULL)
     408      {
     409        isAboveLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAboveLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
     410      }
     411      //below-right
     412      if(ctuBelowRight != NULL)
     413      {
     414        isBelowRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelowRight->getSlice()->getSliceCurStartCUAddr())?ctuBelowRight->getSlice()->getLFCrossSliceBoundaryFlag():true;
     415      }
     416
     417
     418      //above-right
     419      if(ctuAboveRigtht != NULL)
     420      {
     421        Int curSliceStartTS  = getCUOrderMap(ctuCurr->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
     422        Int aboveRigthtSliceStartTS = getCUOrderMap(ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
     423
     424        isAboveRightAvail = (curSliceStartTS == aboveRigthtSliceStartTS)?(true):
     425          (
     426          (curSliceStartTS > aboveRigthtSliceStartTS)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
     427          :(ctuAboveRigtht->getSlice()->getLFCrossSliceBoundaryFlag())
     428          );         
     429      }
     430      //below-left
     431      if(ctuBelowLeft != NULL)
     432      {
     433        Int curSliceStartTS       = getCUOrderMap(ctuCurr->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
     434        Int belowLeftSliceStartTS = getCUOrderMap(ctuBelowLeft->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
     435
     436        isBelowLeftAvail = (curSliceStartTS == belowLeftSliceStartTS)?(true):
     437          (
     438          (curSliceStartTS > belowLeftSliceStartTS)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
     439          :(ctuBelowLeft->getSlice()->getLFCrossSliceBoundaryFlag())
     440          );
     441      }       
     442    }
     443
     444    if(!isLoopFiltAcrossTilePPS)
     445    {     
     446      isLeftAvail      = (!isLeftAvail      ) ?false:(getTileIdxMap( ctuLeft->getAddr()         ) == getTileIdxMap( ctu ));
     447      isAboveAvail     = (!isAboveAvail     ) ?false:(getTileIdxMap( ctuAbove->getAddr()        ) == getTileIdxMap( ctu ));
     448      isRightAvail     = (!isRightAvail     ) ?false:(getTileIdxMap( ctuRight->getAddr()        ) == getTileIdxMap( ctu ));
     449      isBelowAvail     = (!isBelowAvail     ) ?false:(getTileIdxMap( ctuBelow->getAddr()        ) == getTileIdxMap( ctu ));
     450      isAboveLeftAvail = (!isAboveLeftAvail ) ?false:(getTileIdxMap( ctuAboveLeft->getAddr()    ) == getTileIdxMap( ctu ));
     451      isAboveRightAvail= (!isAboveRightAvail) ?false:(getTileIdxMap( ctuAboveRigtht->getAddr()  ) == getTileIdxMap( ctu ));
     452      isBelowLeftAvail = (!isBelowLeftAvail ) ?false:(getTileIdxMap( ctuBelowLeft->getAddr()    ) == getTileIdxMap( ctu ));
     453      isBelowRightAvail= (!isBelowRightAvail) ?false:(getTileIdxMap( ctuBelowRight->getAddr()   ) == getTileIdxMap( ctu ));
     454    }
     455  }
     456
     457}
     458#else
    334459Void TComPicSym::allocSaoParam(TComSampleAdaptiveOffset *sao)
    335460{
     
    337462  sao->allocSaoParam(m_saoParam);
    338463}
     464#endif
    339465
    340466TComTile::TComTile()
  • trunk/source/Lib/TLibCommon/TComPicSym.h

    r494 r540  
    112112  UInt*         m_puiInverseCUOrderMap;
    113113
     114#if HM_CLEANUP_SAO
     115  SAOBlkParam *m_saoBlkParams;
     116#else
    114117  SAOParam *m_saoParam;
     118#endif
     119
    115120public:
    116121  Void        create  ( Int iPicWidth, Int iPicHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth );
     
    171176  Void         xInitTiles();
    172177  UInt         xCalculateNxtCUAddr( UInt uiCurrCUAddr );
     178#if HM_CLEANUP_SAO
     179  SAOBlkParam* getSAOBlkParam() { return m_saoBlkParams;}
     180  Void deriveLoopFilterBoundaryAvailibility(Int ctu, Bool& isLeftAvail,Bool& isRightAvail,Bool& isAboveAvail,Bool& isBelowAvail,Bool& isAboveLeftAvail,Bool& isAboveRightAvail,Bool& isBelowLeftAvail,Bool& isBelowRightAvail);
     181#else
    173182  Void allocSaoParam(TComSampleAdaptiveOffset *sao);
    174183  SAOParam *getSaoParam() { return m_saoParam; }
     184#endif
     185
     186
    175187};// END CLASS DEFINITION TComPicSym
    176188
  • trunk/source/Lib/TLibCommon/TComRdCost.cpp

    r494 r540  
    330330
    331331// Setting the Distortion Parameter for Inter (subpel ME with step)
    332 #if NS_HAD
    333 Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME, Bool bUseNSHAD )
    334 #else
    335332Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME )
    336 #endif
    337333{
    338334#if O0194_WEIGHTED_PREDICTION_CGS
     
    353349  rcDistParam.iCols    = pcPatternKey->getROIYWidth();
    354350  rcDistParam.iRows    = pcPatternKey->getROIYHeight();
    355 #if NS_HAD
    356   rcDistParam.bUseNSHAD = bUseNSHAD;
    357 #endif
    358351
    359352  // set distortion function
     
    386379
    387380Void
    388 #if NS_HAD
    389 TComRdCost::setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard, Bool bUseNSHAD )
    390 #else
    391381TComRdCost::setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard )
    392 #endif
    393382{
    394383  rcDP.pOrg       = p1;
     
    402391  rcDP.bitDepth   = bitDepth;
    403392  rcDP.DistFunc   = m_afpDistortFunc[ ( bHadamard ? DF_HADS : DF_SADS ) + g_aucConvertToBit[ iWidth ] + 1 ];
    404 #if NS_HAD
    405   rcDP.bUseNSHAD  = bUseNSHAD;
    406 #endif
    407393}
    408394
     
    453439}
    454440
    455 #if WEIGHTED_CHROMA_DISTORTION
    456441UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText, DFunc eDFunc)
    457 #else
    458 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc )
    459 #endif
    460442{
    461443  DistParam cDtParam;
     
    471453  cDtParam.bitDepth = bitDepth;
    472454
    473 #if WEIGHTED_CHROMA_DISTORTION
    474455  if (eText == TEXT_CHROMA_U)
    475456  {
     
    484465    return cDtParam.DistFunc( &cDtParam );
    485466  }
    486 #else
    487   return cDtParam.DistFunc( &cDtParam );
    488 #endif
    489 }
    490 
    491 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    492 UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height )
    493 {
    494   UInt SAD = 0;
    495   Int shift = DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
    496   for ( Int i=0; i<height; i++ )
    497   {
    498     for( Int j=0; j<width; j++ )
    499     {
    500       SAD += abs((pelCur[j] - pelOrg[j])) >> shift;
    501     }
    502     pelCur = pelCur + curStride;
    503     pelOrg = pelOrg + orgStride;
    504   }
    505   return SAD;
    506 }
    507 #endif
     467}
    508468
    509469// ====================================================================================================================
     
    15791539}
    15801540
    1581 #if NS_HAD
    1582 UInt TComRdCost::xCalcHADs16x4( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )
    1583 {
    1584   Int k, i, j, jj, sad=0;
    1585   Int diff[64], m1[4][16], m2[4][16];
    1586   assert( iStep == 1 );
    1587   for( k = 0; k < 64; k += 16 )
    1588   {
    1589     diff[k+0] = piOrg[0] - piCur[0];
    1590     diff[k+1] = piOrg[1] - piCur[1];
    1591     diff[k+2] = piOrg[2] - piCur[2];
    1592     diff[k+3] = piOrg[3] - piCur[3];
    1593     diff[k+4] = piOrg[4] - piCur[4];
    1594     diff[k+5] = piOrg[5] - piCur[5];
    1595     diff[k+6] = piOrg[6] - piCur[6];
    1596     diff[k+7] = piOrg[7] - piCur[7];
    1597 
    1598     diff[k+8]  = piOrg[8]  - piCur[8] ;
    1599     diff[k+9]  = piOrg[9]  - piCur[9] ;
    1600     diff[k+10] = piOrg[10] - piCur[10];
    1601     diff[k+11] = piOrg[11] - piCur[11];
    1602     diff[k+12] = piOrg[12] - piCur[12];
    1603     diff[k+13] = piOrg[13] - piCur[13];
    1604     diff[k+14] = piOrg[14] - piCur[14];
    1605     diff[k+15] = piOrg[15] - piCur[15];
    1606 
    1607     piCur += iStrideCur;
    1608     piOrg += iStrideOrg;
    1609   }
    1610 
    1611   //horizontal
    1612   for (j=0; j < 4; j++)
    1613   {
    1614     jj = j << 4;
    1615 
    1616     m2[j][0]  = diff[jj  ] + diff[jj+8];
    1617     m2[j][1]  = diff[jj+1] + diff[jj+9];
    1618     m2[j][2]  = diff[jj+2] + diff[jj+10];
    1619     m2[j][3]  = diff[jj+3] + diff[jj+11];
    1620     m2[j][4]  = diff[jj+4] + diff[jj+12];
    1621     m2[j][5]  = diff[jj+5] + diff[jj+13];
    1622     m2[j][6]  = diff[jj+6] + diff[jj+14];
    1623     m2[j][7]  = diff[jj+7] + diff[jj+15];
    1624     m2[j][8]  = diff[jj  ] - diff[jj+8];
    1625     m2[j][9]  = diff[jj+1] - diff[jj+9];
    1626     m2[j][10] = diff[jj+2] - diff[jj+10];
    1627     m2[j][11] = diff[jj+3] - diff[jj+11];
    1628     m2[j][12] = diff[jj+4] - diff[jj+12];
    1629     m2[j][13] = diff[jj+5] - diff[jj+13];
    1630     m2[j][14] = diff[jj+6] - diff[jj+14];
    1631     m2[j][15] = diff[jj+7] - diff[jj+15];
    1632 
    1633     m1[j][0]  = m2[j][0]  + m2[j][4];
    1634     m1[j][1]  = m2[j][1]  + m2[j][5];
    1635     m1[j][2]  = m2[j][2]  + m2[j][6];
    1636     m1[j][3]  = m2[j][3]  + m2[j][7];
    1637     m1[j][4]  = m2[j][0]  - m2[j][4];
    1638     m1[j][5]  = m2[j][1]  - m2[j][5];
    1639     m1[j][6]  = m2[j][2]  - m2[j][6];
    1640     m1[j][7]  = m2[j][3]  - m2[j][7];
    1641     m1[j][8]  = m2[j][8]  + m2[j][12];
    1642     m1[j][9]  = m2[j][9]  + m2[j][13];
    1643     m1[j][10] = m2[j][10] + m2[j][14];
    1644     m1[j][11] = m2[j][11] + m2[j][15];
    1645     m1[j][12] = m2[j][8]  - m2[j][12];
    1646     m1[j][13] = m2[j][9]  - m2[j][13];
    1647     m1[j][14] = m2[j][10] - m2[j][14];
    1648     m1[j][15] = m2[j][11] - m2[j][15];
    1649 
    1650     m2[j][0]  = m1[j][0]  + m1[j][2];
    1651     m2[j][1]  = m1[j][1]  + m1[j][3];
    1652     m2[j][2]  = m1[j][0]  - m1[j][2];
    1653     m2[j][3]  = m1[j][1]  - m1[j][3];
    1654     m2[j][4]  = m1[j][4]  + m1[j][6];
    1655     m2[j][5]  = m1[j][5]  + m1[j][7];
    1656     m2[j][6]  = m1[j][4]  - m1[j][6];
    1657     m2[j][7]  = m1[j][5]  - m1[j][7];
    1658     m2[j][8]  = m1[j][8]  + m1[j][10];
    1659     m2[j][9]  = m1[j][9]  + m1[j][11];
    1660     m2[j][10] = m1[j][8]  - m1[j][10];
    1661     m2[j][11] = m1[j][9]  - m1[j][11];
    1662     m2[j][12] = m1[j][12] + m1[j][14];
    1663     m2[j][13] = m1[j][13] + m1[j][15];
    1664     m2[j][14] = m1[j][12] - m1[j][14];
    1665     m2[j][15] = m1[j][13] - m1[j][15];
    1666 
    1667     m1[j][0]  = m2[j][0]  + m2[j][1];
    1668     m1[j][1]  = m2[j][0]  - m2[j][1];
    1669     m1[j][2]  = m2[j][2]  + m2[j][3];
    1670     m1[j][3]  = m2[j][2]  - m2[j][3];
    1671     m1[j][4]  = m2[j][4]  + m2[j][5];
    1672     m1[j][5]  = m2[j][4]  - m2[j][5];
    1673     m1[j][6]  = m2[j][6]  + m2[j][7];
    1674     m1[j][7]  = m2[j][6]  - m2[j][7];
    1675     m1[j][8]  = m2[j][8]  + m2[j][9];
    1676     m1[j][9]  = m2[j][8]  - m2[j][9];
    1677     m1[j][10] = m2[j][10] + m2[j][11];
    1678     m1[j][11] = m2[j][10] - m2[j][11];
    1679     m1[j][12] = m2[j][12] + m2[j][13];
    1680     m1[j][13] = m2[j][12] - m2[j][13];
    1681     m1[j][14] = m2[j][14] + m2[j][15];
    1682     m1[j][15] = m2[j][14] - m2[j][15];
    1683   }
    1684 
    1685   //vertical
    1686   for (i=0; i < 16; i++)
    1687   {
    1688     m2[0][i] = m1[0][i] + m1[2][i];
    1689     m2[1][i] = m1[1][i] + m1[3][i];
    1690     m2[2][i] = m1[0][i] - m1[2][i];
    1691     m2[3][i] = m1[1][i] - m1[3][i];
    1692 
    1693     m1[0][i] = m2[0][i] + m2[1][i];
    1694     m1[1][i] = m2[0][i] - m2[1][i];
    1695     m1[2][i] = m2[2][i] + m2[3][i];
    1696     m1[3][i] = m2[2][i] - m2[3][i];
    1697   }
    1698 
    1699   for (i = 0; i < 4; i++)
    1700   {
    1701     for (j = 0; j < 16; j++)
    1702     {
    1703       sad += abs(m1[i][j]);
    1704     }
    1705   }
    1706 
    1707   sad=((sad+2)>>2);
    1708 
    1709   return sad;
    1710 }
    1711 
    1712 UInt TComRdCost::xCalcHADs4x16( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )
    1713 {
    1714   Int k, i, j, jj, sad=0;
    1715   Int diff[64], m1[16][4], m2[16][4], m3[16][4];
    1716   assert( iStep == 1 );
    1717   for( k = 0; k < 64; k += 4 )
    1718   {
    1719     diff[k+0] = piOrg[0] - piCur[0];
    1720     diff[k+1] = piOrg[1] - piCur[1];
    1721     diff[k+2] = piOrg[2] - piCur[2];
    1722     diff[k+3] = piOrg[3] - piCur[3];
    1723 
    1724     piCur += iStrideCur;
    1725     piOrg += iStrideOrg;
    1726   }
    1727 
    1728   //horizontal
    1729   for (j=0; j < 16; j++)
    1730   {
    1731     jj = j << 2;
    1732     m2[j][0] = diff[jj  ] + diff[jj+2];
    1733     m2[j][1] = diff[jj+1] + diff[jj+3];
    1734     m2[j][2] = diff[jj  ] - diff[jj+2];
    1735     m2[j][3] = diff[jj+1] - diff[jj+3];
    1736 
    1737     m1[j][0] = m2[j][0] + m2[j][1];
    1738     m1[j][1] = m2[j][0] - m2[j][1];
    1739     m1[j][2] = m2[j][2] + m2[j][3];
    1740     m1[j][3] = m2[j][2] - m2[j][3];
    1741   }
    1742 
    1743   //vertical
    1744   for (i=0; i < 4; i++)
    1745   {
    1746     m2[0][i]  = m1[0][i] + m1[8][i];
    1747     m2[1][i]  = m1[1][i] + m1[9][i];
    1748     m2[2][i]  = m1[2][i] + m1[10][i];
    1749     m2[3][i]  = m1[3][i] + m1[11][i];
    1750     m2[4][i]  = m1[4][i] + m1[12][i];
    1751     m2[5][i]  = m1[5][i] + m1[13][i];
    1752     m2[6][i]  = m1[6][i] + m1[14][i];
    1753     m2[7][i]  = m1[7][i] + m1[15][i];
    1754     m2[8][i]  = m1[0][i] - m1[8][i];
    1755     m2[9][i]  = m1[1][i] - m1[9][i];
    1756     m2[10][i] = m1[2][i] - m1[10][i];
    1757     m2[11][i] = m1[3][i] - m1[11][i];
    1758     m2[12][i] = m1[4][i] - m1[12][i];
    1759     m2[13][i] = m1[5][i] - m1[13][i];
    1760     m2[14][i] = m1[6][i] - m1[14][i];
    1761     m2[15][i] = m1[7][i] - m1[15][i];
    1762 
    1763     m3[0][i]  = m2[0][i]  + m2[4][i];
    1764     m3[1][i]  = m2[1][i]  + m2[5][i];
    1765     m3[2][i]  = m2[2][i]  + m2[6][i];
    1766     m3[3][i]  = m2[3][i]  + m2[7][i];
    1767     m3[4][i]  = m2[0][i]  - m2[4][i];
    1768     m3[5][i]  = m2[1][i]  - m2[5][i];
    1769     m3[6][i]  = m2[2][i]  - m2[6][i];
    1770     m3[7][i]  = m2[3][i]  - m2[7][i];
    1771     m3[8][i]  = m2[8][i]  + m2[12][i];
    1772     m3[9][i]  = m2[9][i]  + m2[13][i];
    1773     m3[10][i] = m2[10][i] + m2[14][i];
    1774     m3[11][i] = m2[11][i] + m2[15][i];
    1775     m3[12][i] = m2[8][i]  - m2[12][i];
    1776     m3[13][i] = m2[9][i]  - m2[13][i];
    1777     m3[14][i] = m2[10][i] - m2[14][i];
    1778     m3[15][i] = m2[11][i] - m2[15][i];
    1779 
    1780     m1[0][i]  = m3[0][i]  + m3[2][i];
    1781     m1[1][i]  = m3[1][i]  + m3[3][i];
    1782     m1[2][i]  = m3[0][i]  - m3[2][i];
    1783     m1[3][i]  = m3[1][i]  - m3[3][i];
    1784     m1[4][i]  = m3[4][i]  + m3[6][i];
    1785     m1[5][i]  = m3[5][i]  + m3[7][i];
    1786     m1[6][i]  = m3[4][i]  - m3[6][i];
    1787     m1[7][i]  = m3[5][i]  - m3[7][i];
    1788     m1[8][i]  = m3[8][i]  + m3[10][i];
    1789     m1[9][i]  = m3[9][i]  + m3[11][i];
    1790     m1[10][i] = m3[8][i]  - m3[10][i];
    1791     m1[11][i] = m3[9][i]  - m3[11][i];
    1792     m1[12][i] = m3[12][i] + m3[14][i];
    1793     m1[13][i] = m3[13][i] + m3[15][i];
    1794     m1[14][i] = m3[12][i] - m3[14][i];
    1795     m1[15][i] = m3[13][i] - m3[15][i];
    1796 
    1797     m2[0][i]  = m1[0][i]  + m1[1][i];
    1798     m2[1][i]  = m1[0][i]  - m1[1][i];
    1799     m2[2][i]  = m1[2][i]  + m1[3][i];
    1800     m2[3][i]  = m1[2][i]  - m1[3][i];
    1801     m2[4][i]  = m1[4][i]  + m1[5][i];
    1802     m2[5][i]  = m1[4][i]  - m1[5][i];
    1803     m2[6][i]  = m1[6][i]  + m1[7][i];
    1804     m2[7][i]  = m1[6][i]  - m1[7][i];
    1805     m2[8][i]  = m1[8][i]  + m1[9][i];
    1806     m2[9][i]  = m1[8][i]  - m1[9][i];
    1807     m2[10][i] = m1[10][i] + m1[11][i];
    1808     m2[11][i] = m1[10][i] - m1[11][i];
    1809     m2[12][i] = m1[12][i] + m1[13][i];
    1810     m2[13][i] = m1[12][i] - m1[13][i];
    1811     m2[14][i] = m1[14][i] + m1[15][i];
    1812     m2[15][i] = m1[14][i] - m1[15][i];
    1813   }
    1814 
    1815   for (i = 0; i < 16; i++)
    1816   {
    1817     for (j = 0; j < 4; j++)
    1818     {
    1819       sad += abs(m2[i][j]);
    1820     }
    1821   }
    1822 
    1823   sad=((sad+2)>>2);
    1824 
    1825   return sad;
    1826 }
    1827 #endif
    1828 
    18291541UInt TComRdCost::xGetHADs4( DistParam* pcDtParam )
    18301542{
     
    19091621  UInt uiSum = 0;
    19101622
    1911 #if NS_HAD
    1912   if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )
    1913 #else
    19141623  if( ( iRows % 8 == 0) && (iCols % 8 == 0) )
    1915 #endif
    19161624  {
    19171625    Int  iOffsetOrg = iStrideOrg<<3;
     
    19271635    }
    19281636  }
    1929 #if NS_HAD
    1930   else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )
    1931   {
    1932     Int  iOffsetOrg = iStrideOrg<<2;
    1933     Int  iOffsetCur = iStrideCur<<2;
    1934     for ( y=0; y<iRows; y+= 4 )
    1935     {
    1936       for ( x=0; x<iCols; x+= 16 )
    1937       {
    1938         uiSum += xCalcHADs16x4( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );
    1939       }
    1940       piOrg += iOffsetOrg;
    1941       piCur += iOffsetCur;
    1942     }
    1943   }
    1944   else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )
    1945   {
    1946     Int  iOffsetOrg = iStrideOrg<<4;
    1947     Int  iOffsetCur = iStrideCur<<4;
    1948     for ( y=0; y<iRows; y+= 16 )
    1949     {
    1950       for ( x=0; x<iCols; x+= 4 )
    1951       {
    1952         uiSum += xCalcHADs4x16( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );
    1953       }
    1954       piOrg += iOffsetOrg;
    1955       piCur += iOffsetCur;
    1956     }
    1957   }
    1958 #endif
    19591637  else if( ( iRows % 4 == 0) && (iCols % 4 == 0) )
    19601638  {
  • trunk/source/Lib/TLibCommon/TComRdCost.h

    r442 r540  
    8484  UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)
    8585
    86 #if NS_HAD
    87   Bool            bUseNSHAD;
    88 #endif
    89 
    9086  // (vertical) subsampling shift (for reducing complexity)
    9187  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
     
    104100    iSubShift = 0;
    105101    bitDepth = 0;
    106 #if NS_HAD
    107     bUseNSHAD = false;
    108 #endif
    109102  }
    110103};
     
    123116#endif 
    124117 
    125 #if WEIGHTED_CHROMA_DISTORTION
    126118  Double                  m_cbDistortionWeight;
    127119  Double                  m_crDistortionWeight;
    128 #endif
    129120  Double                  m_dLambda;
    130121  Double                  m_sqrtLambda;
     
    155146  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    156147 
    157 #if WEIGHTED_CHROMA_DISTORTION
    158148  Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
    159149  Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
    160 #endif
    161150  Void    setLambda      ( Double dLambda );
    162151  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
     
    164153  Double  getSqrtLambda ()   { return m_sqrtLambda; }
    165154
    166 #if RATE_CONTROL_LAMBDA_DOMAIN
    167155  Double  getLambda() { return m_dLambda; }
    168 #if M0036_RC_IMPROVEMENT
    169156  Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
    170 #endif
    171 #endif
    172157 
    173158  // Distortion Functions
     
    176161  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
    177162  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
    178 #if NS_HAD
    179   Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
    180   Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
    181 #else
    182163  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
    183164  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
    184 #endif
    185165 
    186166  UInt    calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight );
     
    253233  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    254234  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    255 #if NS_HAD
    256   static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    257   static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    258 #endif
    259235 
    260236public:
    261 #if WEIGHTED_CHROMA_DISTORTION
    262237  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
    263 #else
    264   UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
    265 #endif
    266 
    267 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    268   UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
    269 #endif
     238
    270239};// END CLASS DEFINITION TComRdCost
    271240
  • trunk/source/Lib/TLibCommon/TComRom.cpp

    r494 r540  
    363363const UInt g_uiGroupIdx[ 32 ]   = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9};
    364364
    365 // Rice parameters for absolute transform levels
    366 const UInt g_auiGoRiceRange[5] =
    367 {
    368   7, 14, 26, 46, 78
    369 };
    370 
    371 const UInt g_auiGoRicePrefixLen[5] =
    372 {
    373   8, 7, 6, 5, 4
    374 };
    375 
    376365Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight)
    377366{
     
    541530Int g_mvScalingFactor  [MAX_LAYERS][2] = {{0,0}, {0,0}};
    542531Int g_posScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}};
    543 
    544 #if IL_SL_SIGNALLING_N0371
    545 Int ref_scalingListDC         [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
    546 Int ref_scalingListCoef       [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][MAX_MATRIX_COEF_NUM];
    547 Int activeRefPPSId            [MAX_LAYERS];
    548 Int activeRefSPSId            [MAX_LAYERS];
    549 #endif
    550532#endif
    551533
  • trunk/source/Lib/TLibCommon/TComRom.h

    r494 r540  
    131131extern const UInt   g_uiMinInGroup[ 10 ];
    132132
    133 extern const UInt   g_auiGoRiceRange[5];                  //!< maximum value coded with Rice codes
    134 extern const UInt   g_auiGoRicePrefixLen[5];              //!< prefix length for each maximum value
    135  
    136133extern const UInt   g_sigLastScan8x8[ 3 ][ 4 ];           //!< coefficient group scan order for 8x8 TUs
    137134extern       UInt   g_sigLastScanCG32x32[ 64 ];
     
    291288#if SVC_EXTENSION
    292289extern Int g_mvScalingFactor  [MAX_LAYERS][2];
    293 extern Int g_posScalingFactor [MAX_LAYERS][2];
    294 
    295 #if IL_SL_SIGNALLING_N0371
    296 extern Int ref_scalingListDC         [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
    297 extern Int ref_scalingListCoef       [MAX_LAYERS][SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][MAX_MATRIX_COEF_NUM];
    298 extern Int activeRefPPSId            [MAX_LAYERS];
    299 extern Int activeRefSPSId            [MAX_LAYERS]; 
    300 #endif   
     290extern Int g_posScalingFactor [MAX_LAYERS][2];
    301291#endif
    302292
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp

    r442 r540  
    4444//! \ingroup TLibCommon
    4545//! \{
     46#if HM_CLEANUP_SAO
     47UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS];
     48
     49SAOOffset::SAOOffset()
     50{
     51  reset();
     52}
     53
     54SAOOffset::~SAOOffset()
     55{
     56
     57}
     58
     59Void SAOOffset::reset()
     60{
     61  modeIdc = SAO_MODE_OFF;
     62  typeIdc = -1;
     63  typeAuxInfo = -1;
     64  ::memset(offset, 0, sizeof(Int)* MAX_NUM_SAO_CLASSES);
     65}
     66
     67const SAOOffset& SAOOffset::operator= (const SAOOffset& src)
     68{
     69  modeIdc = src.modeIdc;
     70  typeIdc = src.typeIdc;
     71  typeAuxInfo = src.typeAuxInfo;
     72  ::memcpy(offset, src.offset, sizeof(Int)* MAX_NUM_SAO_CLASSES);
     73
     74  return *this;
     75}
     76
     77
     78SAOBlkParam::SAOBlkParam()
     79{
     80  reset();
     81}
     82
     83SAOBlkParam::~SAOBlkParam()
     84{
     85
     86}
     87
     88Void SAOBlkParam::reset()
     89{
     90  for(Int compIdx=0; compIdx< 3; compIdx++)
     91  {
     92    offsetParam[compIdx].reset();
     93  }
     94}
     95
     96const SAOBlkParam& SAOBlkParam::operator= (const SAOBlkParam& src)
     97{
     98  for(Int compIdx=0; compIdx< 3; compIdx++)
     99  {
     100    offsetParam[compIdx] = src.offsetParam[compIdx];
     101  }
     102  return *this;
     103
     104}
     105
     106TComSampleAdaptiveOffset::TComSampleAdaptiveOffset()
     107{
     108  m_tempPicYuv = NULL;
     109  for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     110  {
     111    m_offsetClipTable[compIdx] = NULL;
     112  }
     113  m_signTable = NULL;
     114
     115 
     116  m_lineBufWidth = 0;
     117  m_signLineBuf1 = NULL;
     118  m_signLineBuf2 = NULL;
     119}
     120
     121
     122TComSampleAdaptiveOffset::~TComSampleAdaptiveOffset()
     123{
     124  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#if AUXILIARY_PICTURES
     131Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, ChromaFormat chromaFormatIDC, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth )
     132#else
     133Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth )
     134#endif
     135{
     136  destroy();
     137
     138  m_picWidth = picWidth;   
     139  m_picHeight= picHeight;
     140  m_maxCUWidth= maxCUWidth;
     141  m_maxCUHeight= maxCUHeight;
     142
     143  m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0);
     144  m_numCTUInHeight= (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0);
     145  m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth;
     146
     147  //temporary picture buffer
     148  if ( !m_tempPicYuv )
     149  {
     150    m_tempPicYuv = new TComPicYuv;
     151#if AUXILIARY_PICTURES
     152    m_tempPicYuv->create( m_picWidth, m_picHeight, chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, maxCUDepth );
     153#else
     154    m_tempPicYuv->create( m_picWidth, m_picHeight, m_maxCUWidth, m_maxCUHeight, maxCUDepth );
     155#endif
     156  }
     157
     158  //bit-depth related
     159  for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     160  {
     161    Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC;
     162    m_offsetStepLog2  [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0);
     163    g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive
     164  }
     165
     166  //look-up table for clipping
     167  for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     168  {
     169    Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive
     170    Int maxSampleValue = (1<< bitDepthSample); //exclusive
     171    Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]);
     172
     173    m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
     174    m_offsetClip[compIdx] = &(m_offsetClipTable[compIdx][maxOffsetValue]);
     175
     176    //assign clipped values
     177    Int* offsetClipPtr = m_offsetClip[compIdx];
     178    for(Int k=0; k< maxSampleValue; k++)
     179    {
     180      *(offsetClipPtr + k) = k;
     181    }
     182    for(Int k=0; k< maxOffsetValue; k++ )
     183    {
     184      *(offsetClipPtr + maxSampleValue+ k) = maxSampleValue-1;
     185      *(offsetClipPtr -k -1 )              = 0;
     186    }
     187    if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC
     188    {
     189      m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ];
     190      m_sign = &(m_signTable[maxSampleValue-1]);
     191
     192      m_sign[0] = 0;
     193      for(Int k=1; k< maxSampleValue; k++)
     194      {
     195        m_sign[k] = 1;
     196        m_sign[-k]= -1;
     197      }
     198    }
     199  } 
     200
     201}
     202
     203Void TComSampleAdaptiveOffset::destroy()
     204{
     205  if ( m_tempPicYuv )
     206  {
     207    m_tempPicYuv->destroy();
     208    delete m_tempPicYuv;
     209    m_tempPicYuv = NULL;
     210  }
     211
     212  for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     213  {
     214    if(m_offsetClipTable[compIdx])
     215    {
     216      delete[] m_offsetClipTable[compIdx]; m_offsetClipTable[compIdx] = NULL;
     217    }
     218  }
     219  if( m_signTable )
     220  {
     221    delete[] m_signTable; m_signTable = NULL;
     222  }
     223}
     224
     225Void TComSampleAdaptiveOffset::invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets)
     226{
     227  Int codedOffset[MAX_NUM_SAO_CLASSES];
     228
     229  ::memcpy(codedOffset, srcOffsets, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     230  ::memset(dstOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     231
     232  if(typeIdc == SAO_TYPE_START_BO)
     233  {
     234    for(Int i=0; i< 4; i++)
     235    {
     236      dstOffsets[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES] = codedOffset[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES]*(1<<m_offsetStepLog2[compIdx]);
     237    }
     238  }
     239  else //EO
     240  {
     241    for(Int i=0; i< NUM_SAO_EO_CLASSES; i++)
     242    {
     243      dstOffsets[i] = codedOffset[i] *(1<<m_offsetStepLog2[compIdx]);
     244    }
     245    assert(dstOffsets[SAO_CLASS_EO_PLAIN] == 0); //keep EO plain offset as zero
     246  }
     247
     248}
     249
     250Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList)
     251{
     252  Int ctuX = ctu % m_numCTUInWidth;
     253  Int ctuY = ctu / m_numCTUInWidth;
     254  Int mergedCTUPos;
     255  Int numValidMergeCandidates = 0;
     256
     257  for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++)
     258  {
     259    SAOBlkParam* mergeCandidate = NULL;
     260
     261    switch(mergeType)
     262    {
     263    case SAO_MERGE_ABOVE:
     264      {
     265        if(ctuY > 0)
     266        {
     267          mergedCTUPos = ctu- m_numCTUInWidth;
     268          if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) )
     269          {
     270            mergeCandidate = &(blkParams[mergedCTUPos]);
     271          }
     272        }
     273      }
     274      break;
     275    case SAO_MERGE_LEFT:
     276      {
     277        if(ctuX > 0)
     278        {
     279          mergedCTUPos = ctu- 1;
     280          if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) )
     281          {
     282            mergeCandidate = &(blkParams[mergedCTUPos]);
     283          }
     284        }
     285      }
     286      break;
     287    default:
     288      {
     289        printf("not a supported merge type");
     290        assert(0);
     291        exit(-1);
     292      }
     293    }
     294
     295    mergeList.push_back(mergeCandidate);
     296    if (mergeCandidate != NULL)
     297    {
     298      numValidMergeCandidates++;
     299    }
     300  }
     301
     302  return numValidMergeCandidates;
     303}
     304
     305
     306Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList)
     307{
     308  for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     309  {
     310    SAOOffset& offsetParam = recParam[compIdx];
     311
     312    if(offsetParam.modeIdc == SAO_MODE_OFF)
     313    {
     314      continue;
     315    }
     316
     317    switch(offsetParam.modeIdc)
     318    {
     319    case SAO_MODE_NEW:
     320      {
     321        invertQuantOffsets(compIdx, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset);
     322      }
     323      break;
     324    case SAO_MODE_MERGE:
     325      {
     326        SAOBlkParam* mergeTarget = mergeList[offsetParam.typeIdc];
     327        assert(mergeTarget != NULL);
     328
     329        offsetParam = (*mergeTarget)[compIdx];
     330      }
     331      break;
     332    default:
     333      {
     334        printf("Not a supported mode");
     335        assert(0);
     336        exit(-1);
     337      }
     338    }
     339  }
     340}
     341
     342Void TComSampleAdaptiveOffset::reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams)
     343{
     344  m_picSAOEnabled[SAO_Y] = m_picSAOEnabled[SAO_Cb] = m_picSAOEnabled[SAO_Cr] = false;
     345
     346  for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     347  {
     348    std::vector<SAOBlkParam*> mergeList;
     349    getMergeList(pic, ctu, saoBlkParams, mergeList);
     350
     351    reconstructBlkSAOParam(saoBlkParams[ctu], mergeList);
     352
     353    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     354    {
     355      if(saoBlkParams[ctu][compIdx].modeIdc != SAO_MODE_OFF)
     356      {
     357        m_picSAOEnabled[compIdx] = true;
     358      }
     359    }
     360  }
     361
     362
     363}
     364
     365
     366Void TComSampleAdaptiveOffset::offsetBlock(Int compIdx, Int typeIdx, Int* offset 
     367                                          , Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride,  Int width, Int height
     368                                          , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail)
     369{
     370  if(m_lineBufWidth != m_maxCUWidth)
     371  {
     372    m_lineBufWidth = m_maxCUWidth;
     373   
     374    if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     375    m_signLineBuf1 = new Char[m_lineBufWidth+1];
     376   
     377    if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     378    m_signLineBuf2 = new Char[m_lineBufWidth+1];
     379  }
     380
     381  Int* offsetClip = m_offsetClip[compIdx];
     382
     383  Int x,y, startX, startY, endX, endY, edgeType;
     384  Int firstLineStartX, firstLineEndX, lastLineStartX, lastLineEndX;
     385  Char signLeft, signRight, signDown;
     386
     387  Pel* srcLine = srcBlk;
     388  Pel* resLine = resBlk;
     389
     390  switch(typeIdx)
     391  {
     392  case SAO_TYPE_EO_0:
     393    {
     394      offset += 2;
     395      startX = isLeftAvail ? 0 : 1;
     396      endX   = isRightAvail ? width : (width -1);
     397      for (y=0; y< height; y++)
     398      {
     399        signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     400        for (x=startX; x< endX; x++)
     401        {
     402          signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];
     403          edgeType =  signRight + signLeft;
     404          signLeft  = -signRight;
     405
     406          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     407        }
     408        srcLine  += srcStride;
     409        resLine += resStride;
     410      }
     411
     412    }
     413    break;
     414  case SAO_TYPE_EO_90:
     415    {
     416      offset += 2;
     417      Char *signUpLine = m_signLineBuf1;
     418
     419      startY = isAboveAvail ? 0 : 1;
     420      endY   = isBelowAvail ? height : height-1;
     421      if (!isAboveAvail)
     422      {
     423        srcLine += srcStride;
     424        resLine += resStride;
     425      }
     426
     427      Pel* srcLineAbove= srcLine- srcStride;
     428      for (x=0; x< width; x++)
     429      {
     430        signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
     431      }
     432
     433      Pel* srcLineBelow;
     434      for (y=startY; y<endY; y++)
     435      {
     436        srcLineBelow= srcLine+ srcStride;
     437
     438        for (x=0; x< width; x++)
     439        {
     440          signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
     441          edgeType = signDown + signUpLine[x];
     442          signUpLine[x]= -signDown;
     443
     444          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     445        }
     446        srcLine += srcStride;
     447        resLine += resStride;
     448      }
     449
     450    }
     451    break;
     452  case SAO_TYPE_EO_135:
     453    {
     454      offset += 2;
     455      Char *signUpLine, *signDownLine, *signTmpLine;
     456
     457      signUpLine  = m_signLineBuf1;
     458      signDownLine= m_signLineBuf2;
     459
     460      startX = isLeftAvail ? 0 : 1 ;
     461      endX   = isRightAvail ? width : (width-1);
     462
     463      //prepare 2nd line's upper sign
     464      Pel* srcLineBelow= srcLine+ srcStride;
     465      for (x=startX; x< endX+1; x++)
     466      {
     467        signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
     468      }
     469
     470      //1st line
     471      Pel* srcLineAbove= srcLine- srcStride;
     472      firstLineStartX = isAboveLeftAvail ? 0 : 1;
     473      firstLineEndX   = isAboveAvail? endX: 1;
     474      for(x= firstLineStartX; x< firstLineEndX; x++)
     475      {
     476        edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
     477        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     478      }
     479      srcLine  += srcStride;
     480      resLine  += resStride;
     481
     482
     483      //middle lines
     484      for (y= 1; y< height-1; y++)
     485      {
     486        srcLineBelow= srcLine+ srcStride;
     487
     488        for (x=startX; x<endX; x++)
     489        {
     490          signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
     491          edgeType =  signDown + signUpLine[x];
     492          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     493
     494          signDownLine[x+1] = -signDown;
     495        }
     496        signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
     497
     498        signTmpLine  = signUpLine;
     499        signUpLine   = signDownLine;
     500        signDownLine = signTmpLine;
     501
     502        srcLine += srcStride;
     503        resLine += resStride;
     504      }
     505
     506      //last line
     507      srcLineBelow= srcLine+ srcStride;
     508      lastLineStartX = isBelowAvail ? startX : (width -1);
     509      lastLineEndX   = isBelowRightAvail ? width : (width -1);
     510      for(x= lastLineStartX; x< lastLineEndX; x++)
     511      {
     512        edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
     513        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     514
     515      }
     516    }
     517    break;
     518  case SAO_TYPE_EO_45:
     519    {
     520      offset += 2;
     521      Char *signUpLine = m_signLineBuf1+1;
     522
     523      startX = isLeftAvail ? 0 : 1;
     524      endX   = isRightAvail ? width : (width -1);
     525
     526      //prepare 2nd line upper sign
     527      Pel* srcLineBelow= srcLine+ srcStride;
     528      for (x=startX-1; x< endX; x++)
     529      {
     530        signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
     531      }
     532
     533
     534      //first line
     535      Pel* srcLineAbove= srcLine- srcStride;
     536      firstLineStartX = isAboveAvail ? startX : (width -1 );
     537      firstLineEndX   = isAboveRightAvail ? width : (width-1);
     538      for(x= firstLineStartX; x< firstLineEndX; x++)
     539      {
     540        edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
     541        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     542      }
     543      srcLine += srcStride;
     544      resLine += resStride;
     545
     546      //middle lines
     547      for (y= 1; y< height-1; y++)
     548      {
     549        srcLineBelow= srcLine+ srcStride;
     550
     551        for(x= startX; x< endX; x++)
     552        {
     553          signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
     554          edgeType =  signDown + signUpLine[x];
     555          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     556          signUpLine[x-1] = -signDown;
     557        }
     558        signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
     559        srcLine  += srcStride;
     560        resLine += resStride;
     561      }
     562
     563      //last line
     564      srcLineBelow= srcLine+ srcStride;
     565      lastLineStartX = isBelowLeftAvail ? 0 : 1;
     566      lastLineEndX   = isBelowAvail ? endX : 1;
     567      for(x= lastLineStartX; x< lastLineEndX; x++)
     568      {
     569        edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
     570        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     571
     572      }
     573    }
     574    break;
     575  case SAO_TYPE_BO:
     576    {
     577      Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
     578      for (y=0; y< height; y++)
     579      {
     580        for (x=0; x< width; x++)
     581        {
     582          resLine[x] = offsetClip[ srcLine[x] + offset[srcLine[x] >> shiftBits] ];
     583        }
     584        srcLine += srcStride;
     585        resLine += resStride;
     586      }
     587    }
     588    break;
     589  default:
     590    {
     591      printf("Not a supported SAO types\n");
     592      assert(0);
     593      exit(-1);
     594    }
     595  }
     596
     597
     598}
     599
     600Void TComSampleAdaptiveOffset::offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic)
     601{
     602  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
     603
     604  if(
     605    (saoblkParam[SAO_Y ].modeIdc == SAO_MODE_OFF) &&
     606    (saoblkParam[SAO_Cb].modeIdc == SAO_MODE_OFF) &&
     607    (saoblkParam[SAO_Cr].modeIdc == SAO_MODE_OFF)
     608    )
     609  {
     610    return;
     611  }
     612
     613  //block boundary availability
     614  pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     615
     616  Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
     617  Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     618  Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
     619  Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
     620
     621  for(Int compIdx= 0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     622  {
     623    SAOOffset& ctbOffset = saoblkParam[compIdx];
     624
     625    if(ctbOffset.modeIdc != SAO_MODE_OFF)
     626    {
     627      Bool isLuma     = (compIdx == SAO_Y);
     628      Int  formatShift= isLuma?0:1;
     629
     630      Int  blkWidth   = (width  >> formatShift);
     631      Int  blkHeight  = (height >> formatShift);
     632      Int  blkYPos    = (yPos   >> formatShift);
     633      Int  blkXPos    = (xPos   >> formatShift);
     634
     635      Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
     636      Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
     637
     638      Int  resStride  = isLuma?resYuv->getStride():resYuv->getCStride();
     639      Pel* resBlk     = getPicBuf(resYuv, compIdx)+ blkYPos*resStride+ blkXPos;
     640
     641      offsetBlock( compIdx, ctbOffset.typeIdc, ctbOffset.offset
     642                  , srcBlk, resBlk, srcStride, resStride, blkWidth, blkHeight
     643                  , isLeftAvail, isRightAvail
     644                  , isAboveAvail, isBelowAvail
     645                  , isAboveLeftAvail, isAboveRightAvail
     646                  , isBelowLeftAvail, isBelowRightAvail
     647                  );
     648    }
     649  } //compIdx
     650
     651}
     652
     653
     654Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pDecPic)
     655{
     656  if(!m_picSAOEnabled[SAO_Y] && !m_picSAOEnabled[SAO_Cb] && !m_picSAOEnabled[SAO_Cr])
     657  {
     658    return;
     659  }
     660  TComPicYuv* resYuv = pDecPic->getPicYuvRec();
     661  TComPicYuv* srcYuv = m_tempPicYuv;
     662  resYuv->copyToPic(srcYuv);
     663  for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
     664  {
     665    offsetCTU(ctu, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctu], pDecPic);
     666  } //ctu
     667}
     668
     669
     670Pel* TComSampleAdaptiveOffset::getPicBuf(TComPicYuv* pPicYuv, Int compIdx)
     671{
     672  Pel* pBuf = NULL;
     673  switch(compIdx)
     674  {
     675  case SAO_Y:
     676    {
     677      pBuf = pPicYuv->getLumaAddr();
     678    }
     679    break;
     680  case SAO_Cb:
     681    {
     682      pBuf = pPicYuv->getCbAddr();
     683    }
     684    break;
     685  case SAO_Cr:
     686    {
     687      pBuf = pPicYuv->getCrAddr();
     688    }
     689    break;
     690  default:
     691    {
     692      printf("Not a legal component ID for SAO\n");
     693      assert(0);
     694      exit(-1);
     695    }
     696  }
     697
     698  return pBuf;
     699}
     700#else
    46701
    47702SAOParam::~SAOParam()
     
    13642019  }
    13652020}
    1366 
     2021#endif
    13672022/** PCM LF disable process.
    13682023 * \param pcPic picture (TComPic) pointer
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h

    r313 r540  
    4545//! \{
    4646
     47
     48#if HM_CLEANUP_SAO
     49// ====================================================================================================================
     50// Constants
     51// ====================================================================================================================
     52
     53#define MAX_SAO_TRUNCATED_BITDEPTH     10
     54// ====================================================================================================================
     55// Class definition
     56// ====================================================================================================================
     57extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS];
     58
     59class TComSampleAdaptiveOffset
     60{
     61public:
     62  TComSampleAdaptiveOffset();
     63  virtual ~TComSampleAdaptiveOffset();
     64  Void SAOProcess(TComPic* pDecPic);
     65#if AUXILIARY_PICTURES
     66  Void create( Int picWidth, Int picHeight, ChromaFormat chromaFormatIDC, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth );
     67#else
     68  Void create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth );
     69#endif
     70  Void destroy();
     71  Void reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams);
     72  Void PCMLFDisableProcess (TComPic* pcPic);
     73protected:
     74  Void offsetBlock(Int compIdx, Int typeIdx, Int* offset, Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride,  Int width, Int height
     75                  , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail);
     76  Pel* getPicBuf(TComPicYuv* pPicYuv, Int compIdx);
     77  Void invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets);
     78  Void reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList);
     79  Int  getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList);
     80  Void offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic);
     81  Void xPCMRestoration(TComPic* pcPic);
     82  Void xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth );
     83  Void xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);
     84protected:
     85  UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step 
     86  Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation
     87  Short* m_sign; //sign table for fast operation
     88  TComPicYuv*   m_tempPicYuv; //temporary buffer
     89  Int m_picWidth;
     90  Int m_picHeight;
     91  Int m_maxCUWidth;
     92  Int m_maxCUHeight;
     93  Int m_numCTUInWidth;
     94  Int m_numCTUInHeight;
     95  Int m_numCTUsPic;
     96 
     97 
     98  Int m_lineBufWidth;
     99  Char* m_signLineBuf1;
     100  Char* m_signLineBuf2;
     101private:
     102  Bool m_picSAOEnabled[NUM_SAO_COMPONENTS];
     103  Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
     104  Short* m_signTable;
     105
     106};
     107#else
     108
    47109// ====================================================================================================================
    48110// Constants
     
    145207};
    146208
     209#endif
     210
    147211//! \}
    148212#endif
  • trunk/source/Lib/TLibCommon/TComSlice.cpp

    r494 r540  
    4848ParameterSetMap<TComVPS> ParameterSetManager::m_vpsMap(MAX_NUM_VPS);
    4949Int ParameterSetManager::m_activeVPSId = -1;
    50 #if IL_SL_SIGNALLING_N0371
    51 TComSPS* TComSPS::m_pcSPS[MAX_LAYERS];
    52 TComPPS* TComPPS::m_pcPPS[MAX_LAYERS];
    53 #endif
    5450#endif
    5551
     
    8076, m_colFromL0Flag                 ( 1 )
    8177, m_colRefIdx                     ( 0 )
    82 #if SAO_CHROMA_LAMBDA
    83 , m_dLambdaLuma( 0.0 )
    84 , m_dLambdaChroma( 0.0 )
    85 #else
    86 , m_dLambda                       ( 0.0 )
    87 #endif
    8878, m_uiTLayer                      ( 0 )
    8979, m_bTLayerSwitchingFlag          ( false )
     
    118108#endif
    119109, m_bDiscardableFlag              ( false )
     110#if O0149_CROSS_LAYER_BLA_FLAG
     111, m_bCrossLayerBLAFlag            ( false )
     112#endif
    120113#endif //SVC_EXTENSION
    121114{
     
    143136  initEqualRef();
    144137 
     138  for (Int component = 0; component < 3; component++)
     139  {
     140    m_lambdas[component] = 0.0;
     141  }
     142 
    145143  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
    146144  {
     
    157155  initWpAcDcParam();
    158156  m_saoEnabledFlag = false;
     157#if HM_CLEANUP_SAO
     158  m_saoEnabledFlagChroma = false;
     159#endif
    159160}
    160161
     
    276277    }
    277278    iterPic++;
     279#if SVC_EXTENSION
     280    // return NULL, if picture with requested POC is not in the list, otherwise iterator goes outside of the list
     281    if( iterPic == rcListPic.end() )
     282    {
     283      return NULL;
     284    }
     285#endif
    278286    pcPic = *(iterPic);
    279287  }
     
    308316      }
    309317     
     318#if POC_RESET_RPS
     319      if( ((!pocHasMsb) && ((poc & (pocCycle-1)) == picPoc)) || ( pocHasMsb && (poc == picPoc)) )
     320#else
    310321      if (poc == picPoc)
     322#endif
    311323      {
    312324       if (pcPic->getIsLongTerm())
     
    357369}
    358370
    359 #if FIX1071
    360371#if SVC_EXTENSION
    361372Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr, TComPic** ilpPic)
     
    363374Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
    364375#endif
    365 #else
    366 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
    367 #endif
    368 {
    369 #if FIX1071
     376{
    370377  if (!checkNumPocTotalCurr)
    371 #endif
    372378  {
    373379    if (m_eSliceType == I_SLICE)
     
    522528      memset( refResamplingLayer, 0, sizeof( refResamplingLayer ) );
    523529#endif
     530#if !RESAMPLING_CONSTRAINT_BUG_FIX
    524531      const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
    525532      Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) &&
     
    528535                           (scalEL.getWindowBottomOffset() == 0 )
    529536                          );
     537#endif
    530538
    531539      for( i=0; i < m_activeNumILRRefIdx; i++ )
    532540      {
    533541        UInt refLayerIdc = m_interLayerPredLayerIdc[i];
     542#if RESAMPLING_CONSTRAINT_BUG_FIX
     543#if O0098_SCALED_REF_LAYER_ID
     544        const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_pcVPS->getRefLayerId( m_layerId, m_interLayerPredLayerIdc[i] ));
     545#else
     546        const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
     547#endif
     548        Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) &&
     549                             (scalEL.getWindowRightOffset()  == 0 ) &&
     550                             (scalEL.getWindowTopOffset()    == 0 ) &&
     551                             (scalEL.getWindowBottomOffset() == 0 )
     552                            );
     553#endif
    534554        if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || (!scalingOffset)) // ratio 1x
    535555        {
     
    585605  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
    586606#endif //SVC_EXTENSION
    587 #if FIX1071
     607
    588608  if (checkNumPocTotalCurr)
    589609  {
     
    615635    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
    616636  }
    617 #endif
    618637
    619638#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     
    932951    numRpsCurrTempList += getNumILRRefIdx();
    933952#endif
    934   }
     953}
    935954#endif
    936955
     
    10381057 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
    10391058 */
     1059#if NO_CLRAS_OUTPUT_FLAG
     1060Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag)
     1061#else
    10401062Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic)
     1063#endif
    10411064{
    10421065  TComPic*                 rpcPic;
     
    10561079      rpcPic = *(iterPic);
    10571080      rpcPic->setCurrSliceIdx(0);
     1081#if NO_CLRAS_OUTPUT_FLAG
     1082      if (noClrasOutputFlag)
     1083      {
     1084        if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);  // all layers
     1085      }
     1086      else
     1087      {
     1088        if (rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId) rpcPic->getSlice(0)->setReferenced(false);  // only current layer
     1089      }
     1090#else
    10581091      if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
     1092#endif
    10591093      iterPic++;
    10601094    }
     
    11601194  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
    11611195  m_colRefIdx            = pSrc->m_colRefIdx;
    1162 #if SAO_CHROMA_LAMBDA
    1163   m_dLambdaLuma          = pSrc->m_dLambdaLuma;
    1164   m_dLambdaChroma        = pSrc->m_dLambdaChroma;
    1165 #else
    1166   m_dLambda              = pSrc->m_dLambda;
    1167 #endif
     1196  setLambdas(pSrc->getLambdas());
    11681197  for (i = 0; i < 2; i++)
    11691198  {
     
    14901519    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
    14911520    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
    1492     if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
     1521    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
    14931522    {
    14941523      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
     
    16491678/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
    16501679*/
    1651 #if FIX1071
    16521680Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
    1653 #else
    1654 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
    1655 #endif
    16561681{
    16571682  TComPic* rpcPic;
     
    16781703        // and should be added to the explicit Reference Picture Set
    16791704        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
    1680 #if FIX1071
    16811705        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
    1682 #else
    1683         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
    1684 #endif
    16851706        if(pcRPS->getDeltaPOC(k) < 0)
    16861707        {
     
    18341855  TComVPS *vps = getVPS();
    18351856  UInt retVal, layerId = getLayerId();
     1857#if O0096_REP_FORMAT_INDEX
     1858  if ( layerId == 0 )
     1859  {
     1860    retVal = sps->getPicWidthInLumaSamples();
     1861  }
     1862  else
     1863  {
     1864    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getPicWidthVpsInLumaSamples();
     1865  }
     1866#else
    18361867  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
    18371868  {
     
    18421873    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicWidthVpsInLumaSamples();
    18431874  }
     1875#endif
    18441876  return retVal;
    18451877}
     
    18491881  TComVPS *vps = getVPS();
    18501882  UInt retVal, layerId = getLayerId();
     1883#if O0096_REP_FORMAT_INDEX
     1884  if( layerId == 0 )
     1885  {
     1886    retVal = sps->getPicHeightInLumaSamples();
     1887  }
     1888  else
     1889  {
     1890    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getPicHeightVpsInLumaSamples();
     1891  }
     1892#else
    18511893  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
    18521894  {
     
    18571899    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicHeightVpsInLumaSamples();
    18581900  }
     1901#endif
    18591902  return retVal;
    18601903}
     
    18731916  UInt retVal, layerId = getLayerId();
    18741917#endif
     1918#if O0096_REP_FORMAT_INDEX
     1919  if( layerId == 0 )
     1920  {
     1921    retVal = sps->getChromaFormatIdc();
     1922  }
     1923  else
     1924  {
     1925    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getChromaFormatVpsIdc();
     1926  }
     1927#else
    18751928  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
    18761929  {
     
    18811934    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
    18821935  }
     1936#endif
    18831937  return retVal;
    18841938}
     
    18881942  TComVPS *vps = getVPS();
    18891943  UInt retVal, layerId = getLayerId();
     1944#if O0096_REP_FORMAT_INDEX
     1945  if( layerId == 0 )
     1946  {
     1947    retVal = sps->getBitDepthY();
     1948  }
     1949  else
     1950  {
     1951    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getBitDepthVpsLuma();
     1952  }
     1953#else
    18901954  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
    18911955  {
     
    18961960    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
    18971961  }
     1962#endif
    18981963  return retVal;
    18991964}
     
    19031968  TComVPS *vps = getVPS();
    19041969  UInt retVal, layerId = getLayerId();
     1970#if O0096_REP_FORMAT_INDEX
     1971  if( layerId == 0 )
     1972  {
     1973    retVal = sps->getBitDepthC();
     1974  }
     1975  else
     1976  {
     1977    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getBitDepthVpsChroma();
     1978  }
     1979#else
    19051980  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
    19061981  {
     
    19111986    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
    19121987  }
     1988#endif
    19131989  return retVal;
    19141990}
     
    20232099  ::memset(m_pocLsbNotPresentFlag, 0, sizeof(m_pocLsbNotPresentFlag));
    20242100#endif
     2101#if O0223_PICTURE_TYPES_ALIGN_FLAG
     2102  m_crossLayerPictureTypeAlignFlag = true;
     2103#endif
    20252104#if N0147_IRAP_ALIGN_FLAG
    20262105  m_crossLayerIrapAlignFlag = true;
     
    20422121  }
    20432122#endif
     2123#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     2124   m_tilesNotInUseFlag = true;
     2125   ::memset(m_tilesInUseFlag,  0, sizeof(m_tilesInUseFlag));
     2126   ::memset(m_loopFilterNotAcrossTilesFlag,  0, sizeof(m_loopFilterNotAcrossTilesFlag));
     2127#endif
    20442128#if TILE_BOUNDARY_ALIGNED_FLAG
    20452129   ::memset(m_tileBoundariesAlignedFlag,  0, sizeof(m_tileBoundariesAlignedFlag));
    20462130#endif
     2131#if VPS_VUI_WPP_NOT_IN_USE__FLAG
     2132   m_wppNotInUseFlag = true;
     2133   ::memset(m_wppInUseFlag,  0, sizeof(m_wppInUseFlag));
     2134#endif
    20472135#if N0160_VUI_EXT_ILP_REF
    20482136   m_numIlpRestrictedRefLayers = false;
     
    20502138   ::memset(m_ctuBasedOffsetEnabledFlag,     0, sizeof(m_ctuBasedOffsetEnabledFlag));
    20512139   ::memset(m_minHorizontalCtuOffsetPlus1,   0, sizeof(m_minHorizontalCtuOffsetPlus1));
     2140#endif
     2141#if VPS_VUI_VIDEO_SIGNAL
     2142    m_vidSigPresentVpsFlag=true;
     2143    m_vpsVidSigInfo=1;
     2144    ::memset( m_vpsVidSigIdx, 0, sizeof(m_vpsVidSigIdx) );
     2145    m_vpsVidSigIdx[0]=0;
     2146    for (Int i=0; i < 16; i++)
     2147    {
     2148      m_vpsVidFormat[i] = 5;
     2149      m_vpsFullRangeFlag[i] = false;
     2150      m_vpsColorPrimaries[i] = 2;
     2151      m_vpsTransChar[i] = 2;
     2152      m_vpsMatCoeff[i] = 2;
     2153    }
    20522154#endif
    20532155#if VPS_VUI_BITRATE_PICRATE 
     
    20642166#if VIEW_ID_RELATED_SIGNALING
    20652167  ::memset(m_viewIdVal, 0, sizeof(m_viewIdVal));
     2168#endif
     2169#if O0092_0094_DEPENDENCY_CONSTRAINT
     2170  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
     2171  {
     2172    m_numberRefLayers[i] = 0;
     2173    for (Int j = 0; j < MAX_NUM_LAYER_IDS; j++)
     2174    {
     2175      m_recursiveRefLayerFlag[i][j] = 0;
     2176    }
     2177  }
     2178#endif
     2179#if VPS_DPB_SIZE_TABLE
     2180  ::memset( m_subLayerFlagInfoPresentFlag,  0, sizeof(m_subLayerFlagInfoPresentFlag ) );
     2181  ::memset( m_subLayerDpbInfoPresentFlag,   0, sizeof(m_subLayerDpbInfoPresentFlag )  );
     2182  ::memset( m_maxVpsDecPicBufferingMinus1,  0, sizeof(m_maxVpsDecPicBufferingMinus1 ) );
     2183  ::memset( m_maxVpsNumReorderPics,         0, sizeof(m_maxVpsNumReorderPics )        );
     2184  ::memset( m_maxVpsLatencyIncreasePlus1,   0, sizeof(m_maxVpsLatencyIncreasePlus1 )  );
     2185  ::memset( m_numSubDpbs                ,   0, sizeof(m_numSubDpbs)                   );
    20662186#endif
    20672187}
     
    21172237}
    21182238#endif
    2119 
    2120 #if IL_SL_SIGNALLING_N0371
    2121 Bool TComVPS::checkLayerDependency(UInt i, UInt j)
    2122 {
    2123   if( this->getDirectDependencyFlag(i, j) == true )
    2124   {                                                                                                                                   
    2125     return true;                                                                                                                       
    2126   }                                                                                                                                   
    2127   else                                                                                                                                   
    2128   {                                                                                                                                   
    2129     for(UInt k=i-1; k>j; k--)
    2130     {                                                                                                                               
    2131       if( this->getDirectDependencyFlag(i, k) == true )
    2132       {                                                                                                                           
    2133         checkLayerDependency( k,j );                                                                                           
    2134       }
    2135     }
    2136   }
    2137   return false;       
     2239#if VPS_DPB_SIZE_TABLE
     2240Void TComVPS::deriveNumberOfSubDpbs()
     2241{
     2242  // Derive number of sub-DPBs
     2243  // For output layer set 0
     2244  setNumSubDpbs(0, 1);
     2245  // For other output layer sets
     2246  for( Int i = 1; i < getNumOutputLayerSets(); i++)
     2247  {
     2248    setNumSubDpbs( i, getNumLayersInIdList( getOutputLayerSetIdx(i)) );
     2249  }
     2250}
     2251#endif
     2252#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     2253Void TComVPS::setTilesNotInUseFlag(Bool x)
     2254{
     2255  m_tilesNotInUseFlag = x;
     2256  if (m_tilesNotInUseFlag)
     2257  {
     2258    for (int i = 0; i < getMaxLayers(); i++)
     2259    {
     2260      m_tilesInUseFlag[i] = m_loopFilterNotAcrossTilesFlag[i] = m_tilesNotInUseFlag;
     2261    }
     2262  }
     2263#if TILE_BOUNDARY_ALIGNED_FLAG 
     2264  if (m_tilesNotInUseFlag)
     2265  {
     2266    for (int i = 1; i < getMaxLayers(); i++)
     2267    {
     2268      for(int j = 0; j < getNumDirectRefLayers(getLayerIdInNuh(i)); j++)
     2269      {
     2270        setTileBoundariesAlignedFlag(i, j, m_tilesNotInUseFlag);
     2271      }
     2272    }
     2273  }
     2274#endif
     2275}
     2276#endif
     2277#if VPS_VUI_WPP_NOT_IN_USE__FLAG
     2278Void TComVPS::setWppNotInUseFlag(Bool x)
     2279{
     2280  m_wppNotInUseFlag = x;
     2281  if (m_wppNotInUseFlag)
     2282  {
     2283    for (int i = 0; i < getMaxLayers(); i++)
     2284    {
     2285      m_wppInUseFlag[i] = m_wppNotInUseFlag;
     2286    }
     2287  }
     2288}
     2289#endif
     2290#if O0092_0094_DEPENDENCY_CONSTRAINT
     2291Void TComVPS::setRefLayersFlags(Int currLayerId)
     2292{
     2293  for (Int i = 0; i < getNumDirectRefLayers(currLayerId); i++)
     2294  {
     2295    UInt refLayerId = getRefLayerId(currLayerId, i);
     2296    setRecursiveRefLayerFlag(currLayerId, refLayerId, true);
     2297    for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++)
     2298    {
     2299      setRecursiveRefLayerFlag(currLayerId, k, (getRecursiveRefLayerFlag(currLayerId, k) | getRecursiveRefLayerFlag(refLayerId, k)));
     2300    }
     2301  }
     2302}
     2303
     2304Void TComVPS::setNumRefLayers(Int currLayerId)
     2305{
     2306  for (Int i = 0; i <= getMaxLayers(); i++)
     2307  {
     2308    UInt iNuhLId = getLayerIdInNuh(i);
     2309    setRefLayersFlags(iNuhLId);
     2310    for (UInt j = 0; j < MAX_NUM_LAYER_IDS; j++)
     2311    {
     2312      m_numberRefLayers[iNuhLId] += (getRecursiveRefLayerFlag(iNuhLId, j) == true ? 1 : 0);
     2313    }
     2314  }
    21382315}
    21392316#endif
     
    22242401#if REPN_FORMAT_IN_VPS
    22252402, m_updateRepFormatFlag       (false)
     2403#if O0096_REP_FORMAT_INDEX
     2404, m_updateRepFormatIndex      (0)
     2405#endif
     2406#endif
     2407#if SCALINGLIST_INFERRING
     2408, m_inferScalingListFlag ( false )
     2409, m_scalingListRefLayerId ( 0 )
    22262410#endif
    22272411#endif //SVC_EXTENSION
     
    22482432TComSPS::~TComSPS()
    22492433{
     2434#if SCALINGLIST_INFERRING
     2435  if( !m_inferScalingListFlag )
     2436#endif
    22502437  delete m_scalingList;
    22512438  m_RPSList.destroy();
     
    23732560const Int TComSPS::m_winUnitX[]={1,2,2,1};
    23742561const Int TComSPS::m_winUnitY[]={1,2,1,1};
     2562
     2563#if O0098_SCALED_REF_LAYER_ID
     2564Window& TComSPS::getScaledRefLayerWindowForLayer(Int layerId)
     2565{
     2566  static Window win;
     2567
     2568  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
     2569  {
     2570    if (layerId == m_scaledRefLayerId[i])
     2571    {
     2572      return m_scaledRefLayerWindow[i];
     2573    }
     2574  }
     2575
     2576  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
     2577  return win;
     2578}
     2579#endif
    23752580
    23762581TComPPS::TComPPS()
     
    24072612, m_listsModificationPresentFlag(  0)
    24082613, m_numExtraSliceHeaderBits(0)
     2614#if SCALINGLIST_INFERRING
     2615, m_inferScalingListFlag ( false )
     2616, m_scalingListRefLayerId ( 0 )
     2617#endif
    24092618{
    24102619  m_scalingList = new TComScalingList;
     
    24232632    m_puiRowHeight = NULL;
    24242633  }
     2634
     2635#if SCALINGLIST_INFERRING
     2636  if( !m_inferScalingListFlag )
     2637#endif
    24252638  delete m_scalingList;
    24262639}
     
    26402853/** set default quantization matrix to array
    26412854*/
    2642 #if IL_SL_SIGNALLING_N0371
    2643 Void TComSlice::setDefaultScalingList( UInt layerId )
    2644 #else
    26452855Void TComSlice::setDefaultScalingList()
    2646 #endif
    26472856{
    26482857  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    26502859    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
    26512860    {
    2652 #if IL_SL_SIGNALLING_N0371
    2653       getScalingList()->processDefaultMarix(sizeId, listId, layerId);
    2654 #else
    2655       getScalingList()->processDefaultMarix(sizeId, listId);
    2656 #endif
     2861      getScalingList()->processDefaultMatrix(sizeId, listId);
    26572862    }
    26582863  }
     
    28293034 * \param Index of input matrix
    28303035 */
    2831 #if IL_SL_SIGNALLING_N0371
    2832 Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId, UInt layerId)
    2833 #else
    2834 Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId)
    2835 #endif
    2836 {
    2837 #if IL_SL_SIGNALLING_N0371
    2838   Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
    2839   UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
    2840   Int *src = getScalingListDefaultAddress(sizeId, listId);   
    2841 #endif
    2842 
     3036Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
     3037{
    28433038  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
    2844 
    2845 #if IL_SL_SIGNALLING_N0371
    2846   for(i = 0; i < coefNum; i++)
    2847   {
    2848     ref_scalingListCoef[layerId][sizeId][listId][i] = src[scan[i]];
    2849   }
    2850 #endif
    2851 
    28523039  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
    2853 #if IL_SL_SIGNALLING_N0371
    2854   ref_scalingListDC[layerId][sizeId][listId] = SCALING_LIST_DC;
    2855 #endif
    28563040}
    28573041
    28583042/** check DC value of matrix for default matrix signaling
    28593043 */
    2860 #if IL_SL_SIGNALLING_N0371
    2861 Void TComScalingList::checkDcOfMatrix( UInt layerId )
    2862 #else
    28633044Void TComScalingList::checkDcOfMatrix()
    2864 #endif
    28653045{
    28663046  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    28713051      if(getScalingListDC(sizeId,listId) == 0)
    28723052      {
    2873 #if IL_SL_SIGNALLING_N0371
    2874         processDefaultMarix(sizeId, listId, layerId);
    2875 #else
    2876         processDefaultMarix(sizeId, listId);
    2877 #endif
     3053        processDefaultMatrix(sizeId, listId);
    28783054      }
    28793055    }
     
    29563132        m_activeVPSId = vpsId;
    29573133        m_activeSPSId = spsId;
    2958 
    2959 #if IL_SL_SIGNALLING_N0371
    2960         activeRefPPSId[ sps->getLayerId() ] = ppsId;
    2961         activeRefSPSId[ sps->getLayerId() ] = spsId;
    2962 #endif
    29633134
    29643135        return true;
     
    30683239#endif
    30693240
    3070 Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt refLayerIdc )
     3241Bool TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt refLayerIdc )
    30713242
    30723243  if(m_layerId == 0)
    30733244  {
    30743245    memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
    3075     return;
     3246    return false;
    30763247  }       
    30773248#if POC_RESET_FLAG
    3078   if( this->getPocResetFlag() )
    3079   {
    3080     setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, 0));
     3249  TComPic* pic = xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
     3250
     3251  if( pic )
     3252  {
     3253    setBaseColPic(refLayerIdc, pic );
    30813254  }
    30823255  else
    30833256  {
    3084     setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC()));
    3085   }
     3257    return false;
     3258  }
     3259 
     3260  return true;
    30863261#else
    30873262  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC()));
  • trunk/source/Lib/TLibCommon/TComSlice.h

    r494 r540  
    156156  Void     setScalingListPresentFlag    (Bool b)                               { m_scalingListPresentFlag = b;    }
    157157  Bool     getScalingListPresentFlag    ()                                     { return m_scalingListPresentFlag; }
    158 
    159 #if IL_SL_SIGNALLING_N0371
    160   UInt     m_layerId;
    161 
    162   Void     setPredScalingListFlag    (Bool b)                               { m_predScalingListFlag = b;    }
    163   Bool     getPredScalingListFlag    ()                                     { return m_predScalingListFlag; }
    164   Void     setScalingListRefLayerId  (UInt b)                               { m_scalingListRefLayerId = b;  }
    165   UInt     getScalingListRefLayerId  ()                                     { return m_scalingListRefLayerId; }
    166 #endif
    167 
    168158  Int*     getScalingListAddress          (UInt sizeId, UInt listId)           { return m_scalingListCoef[sizeId][listId]; } //!< get matrix coefficient
    169159  Bool     checkPredMode                  (UInt sizeId, UInt listId);
     
    171161  UInt     getRefMatrixId                 (UInt sizeId, UInt listId)           { return m_refMatrixId[sizeId][listId]; }     //!< get reference matrix ID
    172162  Int*     getScalingListDefaultAddress   (UInt sizeId, UInt listId);                                                        //!< get default matrix coefficient
    173 
    174 #if IL_SL_SIGNALLING_N0371
    175   Void     processDefaultMarix            (UInt sizeId, UInt listId, UInt layerId );
    176 #else
    177   Void     processDefaultMarix            (UInt sizeId, UInt listId);
    178 #endif
    179 
     163  Void     processDefaultMatrix            (UInt sizeId, UInt listId);
    180164  Void     setScalingListDC               (UInt sizeId, UInt listId, UInt u)   { m_scalingListDC[sizeId][listId] = u; }      //!< set DC value
    181165
    182166  Int      getScalingListDC               (UInt sizeId, UInt listId)           { return m_scalingListDC[sizeId][listId]; }   //!< get DC value
    183 
    184 #if IL_SL_SIGNALLING_N0371
    185   Void     setLayerId(UInt layerId) { m_layerId = layerId; }
    186   UInt     getLayerId() { return m_layerId; }
    187   Void     checkDcOfMatrix                ( UInt m_layerId );
    188 #else
    189167  Void     checkDcOfMatrix                ();
    190 #endif
    191 
    192168  Void     processRefMatrix               (UInt sizeId, UInt listId , UInt refListId );
    193169  Bool     xParseScalingList              (Char* pchFile);
     
    200176  UInt     m_refMatrixId                 [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< RefMatrixID
    201177  Bool     m_scalingListPresentFlag;                                                //!< flag for using default matrix
    202 
    203 #if IL_SL_SIGNALLING_N0371
    204   Bool     m_predScalingListFlag;                                                   //!< flag for inter-layer scaling-list prediction
    205   UInt     m_scalingListRefLayerId;                                                 //!< scaling_list_ref_layer_id 
    206 #endif
    207 
    208178  UInt     m_predMatrixId                [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< reference list index
    209179  Int      *m_scalingListCoef            [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix                                           
     
    436406class RepFormat
    437407{
     408#if REPN_FORMAT_CONTROL_FLAG
     409  Bool m_chromaAndBitDepthVpsPresentFlag;
     410#endif
    438411#if AUXILIARY_PICTURES
    439412  ChromaFormat m_chromaFormatVpsIdc;
     
    449422public:
    450423  RepFormat();
     424
     425#if REPN_FORMAT_CONTROL_FLAG
     426  Bool getChromaAndBitDepthVpsPresentFlag() { return m_chromaAndBitDepthVpsPresentFlag; }
     427  void setChromaAndBitDepthVpsPresentFlag(Bool x) { m_chromaAndBitDepthVpsPresentFlag = x; }
     428#endif
    451429
    452430#if AUXILIARY_PICTURES
     
    504482  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
    505483  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
    506 #endif
    507 #if IL_SL_SIGNALLING_N0371
    508   Bool        m_scalingListLayerDependency[MAX_LAYERS][MAX_LAYERS];  // layer dependency for scaling list
    509484#endif
    510485#if VPS_EXTN_OFFSET
     
    555530#if M0457_PREDICTION_INDICATIONS
    556531  UInt       m_directDepTypeLen;
     532#if O0096_DEFAULT_DEPENDENCY_TYPE
     533  Bool       m_defaultDirectDependencyTypeFlag;
     534  UInt       m_defaultDirectDependencyType;
     535#endif
    557536  UInt       m_directDependencyType[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
    558537#endif
     
    569548  Bool       m_pocLsbNotPresentFlag[MAX_VPS_LAYER_ID_PLUS1];
    570549#endif
     550#if O0223_PICTURE_TYPES_ALIGN_FLAG
     551  Bool       m_crossLayerPictureTypeAlignFlag;
     552#endif
    571553#if N0147_IRAP_ALIGN_FLAG
    572554  Bool       m_crossLayerIrapAlignFlag;
     
    582564  Bool       m_maxTidRefPresentFlag;
    583565#endif
     566#if VPS_TSLAYERS
     567  Bool       m_maxTSLayersPresentFlag;
     568  UInt       m_maxTSLayerMinus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
     569#endif
    584570#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    585571  Bool       m_singleLayerForNonIrapFlag;
    586572#endif
     573#if HIGHER_LAYER_IRAP_SKIP_FLAG
     574  Bool       m_higherLayerIrapSkipFlag;
     575#endif
     576#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     577  Bool       m_tilesNotInUseFlag;
     578  Bool       m_tilesInUseFlag[MAX_VPS_LAYER_ID_PLUS1];
     579  Bool       m_loopFilterNotAcrossTilesFlag[MAX_VPS_LAYER_ID_PLUS1];
     580#endif
    587581#if TILE_BOUNDARY_ALIGNED_FLAG
    588582  Bool       m_tileBoundariesAlignedFlag[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
     583#endif
     584#if VPS_VUI_WPP_NOT_IN_USE__FLAG
     585  Bool       m_wppNotInUseFlag;
     586  Bool       m_wppInUseFlag[MAX_VPS_LAYER_ID_PLUS1];
    589587#endif
    590588#if N0160_VUI_EXT_ILP_REF   
     
    593591  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
    594592  Int         m_minHorizontalCtuOffsetPlus1 [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
     593#endif
     594#if VPS_VUI_VIDEO_SIGNAL
     595    Bool        m_vidSigPresentVpsFlag;
     596    Int         m_vpsVidSigInfo;
     597    Int         m_vpsVidSigIdx[MAX_VPS_LAYER_ID_PLUS1];
     598    Int         m_vpsVidFormat[16];
     599    Bool        m_vpsFullRangeFlag[16];
     600    Int         m_vpsColorPrimaries[16];
     601    Int         m_vpsTransChar[16];
     602    Int         m_vpsMatCoeff[16];
    595603#endif
    596604#if VPS_VUI_BITRATE_PICRATE
     
    604612  Int         m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
    605613#endif
     614#if O0153_ALT_OUTPUT_LAYER_FLAG
     615  Bool       m_altOutputLayerFlag;
     616#endif
    606617#if REPN_FORMAT_IN_VPS
    607618  Bool       m_repFormatIdxPresentFlag;
     
    617628#if O0215_PHASE_ALIGNMENT
    618629  Bool       m_phaseAlignFlag;
     630#endif
     631
     632#if O0092_0094_DEPENDENCY_CONSTRAINT
     633  Int        m_numberRefLayers[MAX_NUM_LAYER_IDS];  // number of direct and indirect reference layers of a coding layer
     634  Bool       m_recursiveRefLayerFlag[MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];  // flag to indicate if j-th layer is a direct or indirect reference layer of i-th layer
     635#endif
     636#if VPS_DPB_SIZE_TABLE
     637  Bool    m_subLayerFlagInfoPresentFlag [MAX_VPS_OP_LAYER_SETS_PLUS1];
     638  Bool    m_subLayerDpbInfoPresentFlag  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
     639  Int     m_maxVpsDecPicBufferingMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];
     640  Int     m_maxVpsNumReorderPics        [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
     641  Int     m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
     642  Int     m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
    619643#endif
    620644#endif //SVC_EXTENSION
     
    683707  Void    deriveLayerIdListVariables();
    684708#endif
    685 
    686 #if IL_SL_SIGNALLING_N0371
    687   Bool    checkLayerDependency(UInt i, UInt j);
    688   Bool    getScalingListLayerDependency  ( UInt layerId, UInt refLayerId )            { return m_scalingListLayerDependency[layerId][refLayerId]; }
    689   Void    setScalingListLayerDependency  ( UInt layerId, UInt refLayerId, Bool val  ) { m_scalingListLayerDependency[layerId][refLayerId] = val;  }
    690 #endif
    691 
     709#if VPS_DPB_SIZE_TABLE
     710Void      deriveNumberOfSubDpbs();
     711#endif
     712
     713#if O0092_0094_DEPENDENCY_CONSTRAINT
     714  Void    setRefLayersFlags(Int currLayerId);
     715  Bool    getRecursiveRefLayerFlag(Int currLayerId, Int refLayerId)              { return m_recursiveRefLayerFlag[currLayerId][refLayerId];}
     716  Void    setRecursiveRefLayerFlag(Int currLayerId, Int refLayerId, Bool x)      { m_recursiveRefLayerFlag[currLayerId][refLayerId] = x;   }
     717  Int     getNumRefLayers(Int currLayerId)                                       { return m_numberRefLayers[currLayerId];                  }
     718  Void    setNumRefLayers(Int currLayerId);
     719#endif
    692720#if VPS_RENAME
    693721  UInt    getMaxLayerId()                                       { return m_maxLayerId; }
     
    764792  UInt   getDirectDepTypeLen()                                                  { return m_directDepTypeLen;                              }
    765793  Void   setDirectDepTypeLen(UInt x)                                            { m_directDepTypeLen = x;                                 }
    766 
     794#if O0096_DEFAULT_DEPENDENCY_TYPE
     795  Bool   getDefaultDirectDependencyTypeFlag()                                   { return m_defaultDirectDependencyTypeFlag;               }
     796  Void   setDefaultDirectDependecyTypeFlag(Bool x)                              { m_defaultDirectDependencyTypeFlag = x;                  }
     797  UInt   getDefaultDirectDependencyType()                                       { return m_defaultDirectDependencyType;                   }
     798  Void   setDefaultDirectDependecyType(UInt x)                                  { m_defaultDirectDependencyType = x;                      }
     799#endif
    767800  UInt   getDirectDependencyType(Int currLayerId, Int refLayerId)               { return m_directDependencyType[currLayerId][refLayerId]; }
    768801  Void   setDirectDependencyType(Int currLayerId, Int refLayerId, UInt x)       { m_directDependencyType[currLayerId][refLayerId] = x;    }
     
    791824  Void   setPocLsbNotPresentFlag(Int i, Bool x)                                 { m_pocLsbNotPresentFlag[i] = x;    }
    792825#endif
     826#if O0223_PICTURE_TYPES_ALIGN_FLAG
     827  Bool   getCrossLayerPictureTypeAlignFlag()                                    { return m_crossLayerPictureTypeAlignFlag;                      }
     828  Void   setCrossLayerPictureTypeAlignFlag(Bool x)                              { m_crossLayerPictureTypeAlignFlag = x;                         }
     829#endif
    793830#if N0147_IRAP_ALIGN_FLAG
    794831  Bool   getCrossLayerIrapAlignFlag()                                           { return m_crossLayerIrapAlignFlag;                      }
     
    808845  Void   setMaxTidRefPresentFlag(Bool x)                            { m_maxTidRefPresentFlag = x;}
    809846#endif
     847#if VPS_TSLAYERS
     848    Bool   getMaxTSLayersPresentFlag()                                  { return m_maxTSLayersPresentFlag ;}
     849    Void   setMaxTSLayersPresentFlag(Bool x)                            { m_maxTSLayersPresentFlag = x;}
     850    UInt   getMaxTSLayersMinus1(Int layerId)                            { return m_maxTSLayerMinus1[layerId];}
     851    Void   setMaxTSLayersMinus1(Int layerId, UInt maxTSublayer)         { m_maxTSLayerMinus1[layerId] = maxTSublayer;}
     852#endif
    810853#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    811854  Bool   getSingleLayerForNonIrapFlag()                             { return m_singleLayerForNonIrapFlag; }
    812855  Void   setSingleLayerForNonIrapFlag(Bool x)                       { m_singleLayerForNonIrapFlag = x;    }
    813856#endif
     857#if HIGHER_LAYER_IRAP_SKIP_FLAG
     858  Bool   getHigherLayerIrapSkipFlag()                             { return m_higherLayerIrapSkipFlag; }
     859  Void   setHigherLayerIrapSkipFlag(Bool x)                       { m_higherLayerIrapSkipFlag = x;    }
     860#endif
     861#if VPS_VUI_TILES_NOT_IN_USE__FLAG 
     862  Bool   getTilesNotInUseFlag()         { return m_tilesNotInUseFlag; }
     863  Void   setTilesNotInUseFlag(Bool x);
     864  Bool   getTilesInUseFlag(Int currLayerId)    { return m_tilesInUseFlag[currLayerId]; }
     865  Void   setTilesInUseFlag(Int currLayerId, Bool x)    { m_tilesInUseFlag[currLayerId] = x; }
     866  Bool   getLoopFilterNotAcrossTilesFlag(Int currLayerId)    { return m_loopFilterNotAcrossTilesFlag[currLayerId]; }
     867  Void   setLoopFilterNotAcrossTilesFlag(Int currLayerId, Bool x)    { m_loopFilterNotAcrossTilesFlag[currLayerId] = x; }
     868#endif
    814869#if TILE_BOUNDARY_ALIGNED_FLAG 
    815870  Bool   getTileBoundariesAlignedFlag(Int currLayerId, Int refLayerId)           { return m_tileBoundariesAlignedFlag[currLayerId][refLayerId]; }
    816871  Void   setTileBoundariesAlignedFlag(Int currLayerId, Int refLayerId, Bool x)   { m_tileBoundariesAlignedFlag[currLayerId][refLayerId] = x; }
    817872#endif
     873#if VPS_VUI_WPP_NOT_IN_USE__FLAG 
     874  Bool   getWppNotInUseFlag()         { return m_wppNotInUseFlag; }
     875  Void   setWppNotInUseFlag(Bool x);
     876  Bool   getWppInUseFlag(Int currLayerId)    { return m_wppInUseFlag[currLayerId]; }
     877  Void   setWppInUseFlag(Int currLayerId, Bool x)    { m_wppInUseFlag[currLayerId] = x; }
     878#endif
    818879#if N0160_VUI_EXT_ILP_REF 
    819880  Bool  getNumIlpRestrictedRefLayers   ( )                                         { return m_numIlpRestrictedRefLayers        ;}
     
    828889  Int  getMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId )            { return m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId];}
    829890  Void setMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId, Int val )   { m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId] = val;} 
     891#endif
     892#if VPS_VUI_VIDEO_SIGNAL
     893    Bool   getVideoSigPresentVpsFlag()           { return m_vidSigPresentVpsFlag; }
     894    Void   setVideoSigPresentVpsFlag(Bool x)     { m_vidSigPresentVpsFlag = x;    }
     895    Int    getNumVideoSignalInfo()               { return m_vpsVidSigInfo;        }
     896    Void   setNumVideoSignalInfo(Int x)          { m_vpsVidSigInfo = x;           }
     897    Int    getVideoSignalInfoIdx(Int idx)        { return m_vpsVidSigIdx[idx];    }
     898    Void   setVideoSignalInfoIdx(Int idx, Int x) { m_vpsVidSigIdx[idx] = x;       }
     899    Int    getVideoVPSFormat(Int idx)            { return m_vpsVidFormat[idx];    }
     900    Void   setVideoVPSFormat(Int idx, Int x)     { m_vpsVidFormat[idx] = x;       }
     901    Bool   getVideoFullRangeVpsFlag(Int idx)     { return m_vpsFullRangeFlag[idx];}
     902    Void   setVideoFullRangeVpsFlag(Int idx, Bool x) { m_vpsFullRangeFlag[idx] = x;   }
     903    Int    getColorPrimaries(Int idx)            { return m_vpsColorPrimaries[idx];   }
     904    Void   setColorPrimaries(Int idx, Int x)     { m_vpsColorPrimaries[idx] = x;      }
     905    Int    getTransCharacter(Int idx)            { return m_vpsTransChar[idx];    }
     906    Void   setTransCharacter(Int idx, Int x)     { m_vpsTransChar[idx] = x;       }
     907    Int    getMaxtrixCoeff(Int idx)              { return m_vpsMatCoeff[idx];     }
     908    Void   setMaxtrixCoeff(Int idx, Int x)       { m_vpsMatCoeff[idx] = x;        }
    830909#endif
    831910#if VPS_VUI_BITRATE_PICRATE
     
    850929  Void setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
    851930#endif
    852 
     931#if O0153_ALT_OUTPUT_LAYER_FLAG
     932  Bool   getAltOuputLayerFlag()             { return m_altOutputLayerFlag; }
     933  Void   setAltOuputLayerFlag(Bool x)       { m_altOutputLayerFlag = x;    }
     934#endif
    853935#if REPN_FORMAT_IN_VPS
    854936  Bool   getRepFormatIdxPresentFlag()       { return m_repFormatIdxPresentFlag; }
     
    883965  Bool   getPhaseAlignFlag()                             { return m_phaseAlignFlag; }
    884966  Void   setPhaseAlignFlag(Bool x)                       { m_phaseAlignFlag = x;    }
     967#endif
     968#if VPS_DPB_SIZE_TABLE
     969  Bool    getSubLayerFlagInfoPresentFlag(Int i)         {return m_subLayerFlagInfoPresentFlag[i]; }
     970  Void    setSubLayerFlagInfoPresentFlag(Int i, Bool x) {m_subLayerFlagInfoPresentFlag[i] = x;    }
     971
     972  Bool    getSubLayerDpbInfoPresentFlag(Int i, Int j)         {return m_subLayerDpbInfoPresentFlag[i][j]; }
     973  Void    setSubLayerDpbInfoPresentFlag(Int i, Int j, Bool x) {m_subLayerDpbInfoPresentFlag[i][j] = x;    }
     974
     975  // For the 0-th output layer set, use the date from the active SPS for base layer.
     976  Int     getMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j)         { assert(i != 0); return m_maxVpsDecPicBufferingMinus1[i][k][j]; }
     977  Void    setMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j, Int x) { m_maxVpsDecPicBufferingMinus1[i][k][j] = x;    }
     978
     979  Int     getMaxVpsNumReorderPics(Int i, Int j)         { assert(i != 0); return m_maxVpsNumReorderPics[i][j]; }
     980  Void    setMaxVpsNumReorderPics(Int i, Int j, Int x) { m_maxVpsNumReorderPics[i][j] = x;    }
     981
     982  Int     getMaxVpsLatencyIncreasePlus1(Int i, Int j)         { assert(i != 0); return m_maxVpsLatencyIncreasePlus1[i][j]; }
     983  Void    setMaxVpsLatencyIncreasePlus1(Int i, Int j, Int x) { m_maxVpsLatencyIncreasePlus1[i][j] = x;    }
     984
     985  Int     getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
     986  Void    setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
    885987#endif
    886988#endif //SVC_EXTENSION
     
    11851287  UInt m_layerId;
    11861288
    1187 #if IL_SL_SIGNALLING_N0371
    1188   TComVPS*    m_pVPS;
    1189   static TComSPS* m_pcSPS[MAX_LAYERS];
    1190   Bool        m_predScalingListFlag;
    1191   UInt        m_scalingListRefLayerId;
    1192 #endif
    1193 
    11941289#if REF_IDX_MFM
    11951290#if !M0457_COL_PICTURE_SIGNALING
     
    11981293#endif
    11991294  UInt        m_numScaledRefLayerOffsets;
     1295#if O0098_SCALED_REF_LAYER_ID
     1296  UInt        m_scaledRefLayerId[MAX_LAYERS];
     1297#endif
    12001298  Window      m_scaledRefLayerWindow[MAX_LAYERS];
    12011299#if REPN_FORMAT_IN_VPS
    12021300  Bool m_updateRepFormatFlag;
     1301#if O0096_REP_FORMAT_INDEX
     1302  UInt m_updateRepFormatIndex;
     1303#endif
     1304#endif
     1305#if SCALINGLIST_INFERRING
     1306  Bool       m_inferScalingListFlag;
     1307  UInt       m_scalingListRefLayerId;
    12031308#endif
    12041309#endif //SVC_EXTENSION
     
    13221427  Void setScalingListPresentFlag( Bool b ) { m_scalingListPresentFlag  = b;       }
    13231428
    1324 #if IL_SL_SIGNALLING_N0371
    1325   Bool getPredScalingListFlag()         { return m_predScalingListFlag;     }
    1326   Void setPredScalingListFlag( Bool b ) { m_predScalingListFlag  = b;       }
    1327   UInt getScalingListRefLayerId()         { return m_scalingListRefLayerId;   }
    1328   Void setScalingListRefLayerId( UInt b ) { m_scalingListRefLayerId  = b;       }
    1329 
    1330   TComVPS*  getVPS()                      { return  m_pVPS; }
    1331   Void      setVPS( TComVPS* vps )        { m_pVPS = vps;   }
    1332   static   TComSPS* getSPS(UInt layerId)               { return m_pcSPS[layerId]; }
    1333   static   Void     setSPS(UInt layerId, TComSPS* sps) { m_pcSPS[layerId] = sps;  }
    1334 #endif
    1335 
     1429#if SCALINGLIST_INFERRING
     1430  Void setScalingList( TComScalingList *scalingList ) { m_scalingList = scalingList; }
     1431#else
    13361432  Void setScalingList      ( TComScalingList *scalingList);
     1433#endif
    13371434  TComScalingList* getScalingList ()       { return m_scalingList; }               //!< get ScalingList class pointer in SPS
    13381435
     
    13801477  UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
    13811478  Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
     1479#if O0098_SCALED_REF_LAYER_ID
     1480  UInt     getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
     1481  Void     setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id; }
     1482  Window&  getScaledRefLayerWindowForLayer( Int layerId );
     1483#endif
    13821484  Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
    13831485#if REPN_FORMAT_IN_VPS
    13841486  Bool     getUpdateRepFormatFlag()       { return m_updateRepFormatFlag; }
    13851487  Void     setUpdateRepFormatFlag(Bool x) { m_updateRepFormatFlag = x;    }
     1488#if O0096_REP_FORMAT_INDEX
     1489  Int      getUpdateRepFormatIndex()      { return m_updateRepFormatIndex; }
     1490  Void     setUpdateRepFormatIndex(UInt index)  { m_updateRepFormatIndex = index; }
     1491#endif
     1492#endif
     1493#if SCALINGLIST_INFERRING
     1494  Bool     getInferScalingListFlag()  { return m_inferScalingListFlag;  }
     1495  UInt     getScalingListRefLayerId() { return m_scalingListRefLayerId; }
     1496  Void     setInferScalingListFlag( Bool flag )     { m_inferScalingListFlag = flag;     }
     1497  Void     setScalingListRefLayerId( UInt layerId ) { m_scalingListRefLayerId = layerId; }
    13861498#endif
    13871499#endif //SVC_EXTENSION
     
    14681580  Int      m_deblockingFilterTcOffsetDiv2;      //< tc offset for deblocking filter
    14691581  Bool     m_scalingListPresentFlag;
    1470 
    1471 #if SVC_EXTENSION
    1472   UInt m_layerId;
    1473 
    1474 #if IL_SL_SIGNALLING_N0371
    1475   static TComPPS* m_pcPPS[MAX_LAYERS];
    1476   Bool     m_predScalingListFlag;
    1477   UInt     m_scalingListRefLayerId;
    1478 #endif
    1479 
    1480 #endif
    1481 
    14821582  TComScalingList*     m_scalingList;   //!< ScalingList class pointer
    1483 
    14841583  Bool m_listsModificationPresentFlag;
    14851584  UInt m_log2ParallelMergeLevelMinus2;
    14861585  Int m_numExtraSliceHeaderBits;
     1586
     1587#if SVC_EXTENSION
     1588#if SCALINGLIST_INFERRING
     1589  UInt     m_layerId;
     1590  Bool     m_inferScalingListFlag;
     1591  UInt     m_scalingListRefLayerId;
     1592#endif
     1593#endif
    14871594
    14881595public:
     
    15961703  Void     setScalingListPresentFlag( Bool b ) { m_scalingListPresentFlag  = b;       }
    15971704
    1598 #if IL_SL_SIGNALLING_N0371
    1599   Void     setLayerId(UInt layerId) { m_layerId = layerId; }
     1705#if SCALINGLIST_INFERRING
    16001706  UInt     getLayerId() { return m_layerId; }
    1601 
    1602   Bool     getPredScalingListFlag()         { return m_predScalingListFlag;     }
    1603   Void     setPredScalingListFlag( Bool b ) { m_predScalingListFlag  = b;      }
    1604   UInt     getScalingListRefLayerId()         { return m_scalingListRefLayerId;     }
    1605   Void     setScalingListRefLayerId( UInt b ) { m_scalingListRefLayerId  = b;      }
    1606 
    1607   static   TComPPS* getPPS(UInt layerId)               { return m_pcPPS[layerId]; }
    1608   static   Void     setPPS(UInt layerId, TComPPS* pps) { m_pcPPS[layerId] = pps;  }
    1609 #endif
    1610 
     1707  Void     setLayerId( UInt layerId ) { m_layerId = layerId;            }
     1708  Bool     getInferScalingListFlag()  { return m_inferScalingListFlag;  }
     1709  UInt     getScalingListRefLayerId() { return m_scalingListRefLayerId; }
     1710  Void     setInferScalingListFlag( Bool flag )     { m_inferScalingListFlag = flag;     }
     1711  Void     setScalingListRefLayerId( UInt layerId ) { m_scalingListRefLayerId = layerId; }
     1712#endif
     1713
     1714#if SCALINGLIST_INFERRING
     1715  Void     setScalingList( TComScalingList *scalingList ) { m_scalingList = scalingList; }
     1716#else
    16111717  Void     setScalingList      ( TComScalingList *scalingList);
     1718#endif
    16121719  TComScalingList* getScalingList ()          { return m_scalingList; }         //!< get ScalingList class pointer in PPS
    16131720  Bool getListsModificationPresentFlag ()          { return m_listsModificationPresentFlag; }
     
    17051812  UInt        m_maxNumMergeCand;
    17061813
    1707 #if SAO_CHROMA_LAMBDA
    1708   Double      m_dLambdaLuma;
    1709   Double      m_dLambdaChroma;
    1710 #else
    1711   Double      m_dLambda;
    1712 #endif
     1814  Double      m_lambdas[3];
    17131815
    17141816  Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
     
    17801882#endif 
    17811883  Bool        m_bDiscardableFlag;
     1884#if O0149_CROSS_LAYER_BLA_FLAG
     1885  Bool        m_bCrossLayerBLAFlag;
     1886#endif
    17821887#endif //SVC_EXTENSION
    17831888
     
    18191924  Int       getRPSidx          () { return m_iBDidx; }
    18201925  Int       getPrevTid0POC      ()                        { return  m_prevTid0POC;       }
     1926#if PREVTID0_POC_RESET
     1927    Void     adjustPrevTid0POC      (Int adj)             { m_prevTid0POC=m_prevTid0POC-adj; }
     1928#endif
    18211929  TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
    18221930  Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
     
    18661974  Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); } 
    18671975  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
     1976#if NO_CLRAS_OUTPUT_FLAG
     1977  Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag);
     1978#else
    18681979  Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
     1980#endif
    18691981  Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
    18701982  Void      setSliceQp          ( Int i )                       { m_iSliceQp          = i;      }
     
    18861998  Void      setDepth            ( Int iDepth )                  { m_iDepth            = iDepth; }
    18871999
    1888 #if FIX1071
    18892000#if SVC_EXTENSION
    18902001  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false, TComPic** ilpPic = NULL );
    18912002#else
    18922003  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
    1893 #endif
    1894 #else
    1895   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
    18962004#endif
    18972005  Void      setRefPOCList       ();
     
    19052013  Bool      isInterP        ()                          { return  m_eSliceType == P_SLICE;  }
    19062014 
    1907 #if SAO_CHROMA_LAMBDA 
    1908   Void      setLambda( Double d, Double e ) { m_dLambdaLuma = d; m_dLambdaChroma = e;}
    1909   Double    getLambdaLuma() { return m_dLambdaLuma;        }
    1910   Double    getLambdaChroma() { return m_dLambdaChroma;        }
    1911 #else
    1912   Void      setLambda( Double d ) { m_dLambda = d; }
    1913   Double    getLambda() { return m_dLambda;        }
    1914 #endif
     2015  Void      setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; }
     2016  const Double* getLambdas() const { return m_lambdas; }
    19152017 
    19162018  Void      initEqualRef();
     
    19392041  Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
    19402042  Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
    1941 #if FIX1071
    19422043  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
    1943 #else
    1944   Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet);
    1945 #endif
    19462044
    19472045  Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
     
    20012099  Void  setScalingList              ( TComScalingList* scalingList ) { m_scalingList = scalingList; }
    20022100  TComScalingList*   getScalingList ()                               { return m_scalingList; }
    2003 
    2004 #if IL_SL_SIGNALLING_N0371
    2005   Void  setDefaultScalingList       ( UInt m_layerId );
    2006 #else
    20072101  Void  setDefaultScalingList       ();
    2008 #endif
    2009 
    20102102  Bool  checkDefaultScalingList     ();
    20112103  Void      setCabacInitFlag  ( Bool val ) { m_cabacInitFlag = val;      }  //!< set CABAC initial flag
     
    20222114
    20232115#if SVC_EXTENSION
    2024   Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt refLayerIdc );
     2116  Bool      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt refLayerIdc );
    20252117  Void      setBaseColPic       (UInt refLayerIdc, TComPic* p)     { m_pcBaseColPic[refLayerIdc] = p; }
    20262118  TComPic*  getBaseColPic       (UInt refLayerIdc)                { return m_pcBaseColPic[refLayerIdc]; }
     
    20992191  Bool      getDiscardableFlag  ()                           { return m_bDiscardableFlag;    }
    21002192  Void      setDiscardableFlag  (Bool b)                     { m_bDiscardableFlag = b;       }
     2193#if O0149_CROSS_LAYER_BLA_FLAG
     2194  Bool      getCrossLayerBLAFlag  ()                         { return m_bCrossLayerBLAFlag;  }
     2195  Void      setCrossLayerBLAFlag  (Bool b)                   { m_bCrossLayerBLAFlag = b;     }
     2196#endif
    21012197
    21022198#if RPL_INIT_N0316_N0082
  • trunk/source/Lib/TLibCommon/TComTrQuant.cpp

    r442 r540  
    5454  {
    5555    iNNZbeforePos0 = 0;
    56   d64CodedLevelandDist = 0;
    57   d64UncodedDist = 0;
    58   d64SigCost = 0;
    59   d64SigCost_0 = 0;
     56    d64CodedLevelandDist = 0;
     57    d64UncodedDist = 0;
     58    d64SigCost = 0;
     59    d64SigCost_0 = 0;
    6060  }
    6161#endif
     
    19441944              Int64 costUp   = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ;
    19451945              Int64 costDown = rdFactor * (   deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos]
    1946               -   ( abs(piDstCoeff[uiBlkPos])==1?((1<<15)+sigRateDelta[uiBlkPos]):0 );
     1946              -   ((abs(piDstCoeff[uiBlkPos]) == 1) ? sigRateDelta[uiBlkPos] : 0);
    19471947             
    19481948              if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1)
     
    21632163  {
    21642164    Double dErr         = Double( lLevelDouble  - ( uiAbsLevel << iQBits ) );
    2165     Double dCurrCost    = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx );
     2165    Double dCurrCost    = dErr * dErr * dTemp + xGetICost(xGetICRate( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx ));
    21662166    dCurrCost          += dCurrCostSig;
    21672167
     
    21842184 * \returns cost of given absolute transform level
    21852185 */
    2186 __inline Double TComTrQuant::xGetICRateCost  ( UInt                            uiAbsLevel,
     2186__inline Int TComTrQuant::xGetICRate  ( UInt                            uiAbsLevel,
    21872187                                               UShort                          ui16CtxNumOne,
    21882188                                               UShort                          ui16CtxNumAbs,
     
    21922192                                               ) const
    21932193{
    2194   Double iRate = xGetIEPRate();
     2194  Int iRate = Int(xGetIEPRate());
    21952195  UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
    21962196
     
    22362236  else
    22372237  {
    2238     assert (0);
    2239   }
    2240   return xGetICost( iRate );
    2241 }
    2242 
    2243 __inline Int TComTrQuant::xGetICRate  ( UInt                            uiAbsLevel,
    2244                                        UShort                          ui16CtxNumOne,
    2245                                        UShort                          ui16CtxNumAbs,
    2246                                        UShort                          ui16AbsGoRice
    2247                                      , UInt                            c1Idx,
    2248                                        UInt                            c2Idx
    2249                                        ) const
    2250 {
    2251   Int iRate = 0;
    2252   UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
    2253 
    2254   if ( uiAbsLevel >= baseLevel )
    2255   {
    2256     UInt uiSymbol     = uiAbsLevel - baseLevel;
    2257     UInt uiMaxVlc     = g_auiGoRiceRange[ ui16AbsGoRice ];
    2258     Bool bExpGolomb   = ( uiSymbol > uiMaxVlc );
    2259 
    2260     if( bExpGolomb )
    2261     {
    2262       uiAbsLevel  = uiSymbol - uiMaxVlc;
    2263       Int iEGS    = 1;  for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 );
    2264       iRate      += iEGS << 15;
    2265       uiSymbol    = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) );
    2266     }
    2267 
    2268     UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1;
    2269     UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice;
    2270 
    2271     iRate += ui16NumBins << 15;
    2272 
    2273     if (c1Idx < C1FLAG_NUMBER)
    2274     {
    2275       iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];
    2276 
    2277       if (c2Idx < C2FLAG_NUMBER)
    2278       {
    2279         iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ];
    2280       }
    2281     }
    2282   }
    2283   else
    2284   if( uiAbsLevel == 0 )
    2285   {
    2286     return 0;
    2287   }
    2288   else if( uiAbsLevel == 1 )
    2289   {
    2290     iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 0 ];
    2291   }
    2292   else if( uiAbsLevel == 2 )
    2293   {
    2294     iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];
    2295     iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 0 ];
    2296   }
    2297   else
    2298   {
    2299     assert(0);
     2238    iRate = 0;
    23002239  }
    23012240  return iRate;
     
    24942433/** set flat matrix value to quantized coefficient
    24952434 */
    2496 #if IL_SL_SIGNALLING_N0371
    2497 Void TComTrQuant::setFlatScalingList( UInt m_layerId )
    2498 #else
    24992435Void TComTrQuant::setFlatScalingList()
    2500 #endif
    25012436{
    25022437  UInt size,list;
     
    25072442    for(list = 0; list <  g_scalingListNum[size]; list++)
    25082443    {
    2509 #if IL_SL_SIGNALLING_N0371
    2510       ref_scalingListDC[m_layerId][size][list] = SCALING_LIST_DC;
    2511       for(UInt i=0; i<MAX_MATRIX_COEF_NUM; i++)
    2512       {
    2513         ref_scalingListCoef[m_layerId][size][list][i] = SCALING_LIST_DC;
    2514       }
    2515 #endif
    2516 
    25172444      for(qp=0;qp<SCALING_LIST_REM_NUM;qp++)
    25182445      {
  • trunk/source/Lib/TLibCommon/TComTrQuant.h

    r442 r540  
    150150
    151151#if RDOQ_CHROMA_LAMBDA
    152   Void setLambda(Double dLambdaLuma, Double dLambdaChroma) { m_dLambdaLuma = dLambdaLuma; m_dLambdaChroma = dLambdaChroma; }
    153   Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_dLambdaLuma : m_dLambdaChroma; }
     152  Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; }
     153  Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_lambdas[0] : ((eTType == TEXT_CHROMA_U) ? m_lambdas[1] : m_lambdas[2]); }
    154154#else
    155155  Void setLambda(Double dLambda) { m_dLambda = dLambda;}
     
    181181  Void setUseScalingList   ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; };
    182182  Bool getUseScalingList   (){ return m_scalingListEnabledFlag; };
    183 
    184 #if IL_SL_SIGNALLING_N0371
    185   Void setFlatScalingList  ( UInt m_layerId );
    186 #else
    187183  Void setFlatScalingList  ();
    188 #endif
    189 
    190184  Void xsetFlatScalingList ( UInt list, UInt size, UInt qp);
    191185  Void xSetScalingListEnc  ( TComScalingList *scalingList, UInt list, UInt size, UInt qp);
     
    213207  QpParam  m_cQP;
    214208#if RDOQ_CHROMA_LAMBDA
    215   Double   m_dLambdaLuma;
    216   Double   m_dLambdaChroma;
     209  Double   m_lambdas[3];
    217210#endif
    218211  Double   m_dLambda;
     
    279272                                             Double                          dTemp,
    280273                                             Bool                            bLast        ) const;
    281   __inline Double xGetICRateCost   ( UInt                            uiAbsLevel,
    282                                      UShort                          ui16CtxNumOne,
    283                                      UShort                          ui16CtxNumAbs,
    284                                      UShort                          ui16AbsGoRice
    285                                    , UInt                            c1Idx,
    286                                      UInt                            c2Idx
    287                                      ) const;
    288274__inline Int xGetICRate  ( UInt                            uiAbsLevel,
    289275                           UShort                          ui16CtxNumOne,
  • trunk/source/Lib/TLibCommon/TypeDef.h

    r494 r540  
    5151#define O0194_JOINT_US_BITSHIFT          1      ///< JCTVC-O0194: Joint Upsampling and bit-shift
    5252#endif
    53 #define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
     53#define O0194_WEIGHTED_PREDICTION_CGS    0      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
    5454#define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
    5555#define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
     
    5757#define ALIGN_TSA_STSA_PICS              1      ///< JCTVC-N0084: Alignment of TSA and STSA pictures across AU.
    5858#define REPN_FORMAT_IN_VPS               1      ///< JCTVC-N0092: Signal represenation format (spatial resolution, bit depth, colour format) in the VPS
     59#if REPN_FORMAT_IN_VPS
     60#define REPN_FORMAT_CONTROL_FLAG         1      ///< JCTVC-O0179: Add control flag in representation format to control sending of chroma and bitdepth parameters
     61#endif
    5962#define TIMING_INFO_NONZERO_LAYERID_SPS  1      ///< JCTVC-N0085: Semantics of vui_timing_info_present_flag to always set that flag to zero for non-zero layer ID SPS
    6063#define RPL_INIT_N0316_N0082             1      ///< JCTVC-N0316, JCTVC-N0082: initial reference picture list construction
    6164
    62 #define IL_SL_SIGNALLING_N0371           0      ///< JCTVC-N0371: inter-layer scaling list
     65#define SCALINGLIST_INFERRING            1      ///< JCTVC-N0371: inter-layer scaling list
    6366#define M0463_VUI_EXT_ILP_REF            0      ///< JCTVC-M0463: VUI extension inter-layer dependency offset signalling
    6467#define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
     68#if SPS_EXTENSION
     69#define O0142_CONDITIONAL_SPS_EXTENSION  1      ///< JCTVC-O0142: Conditional SPS extension
     70#endif
    6571#define VERT_MV_CONSTRAINT               1      ///< Vertical MV component constraint flag
    6672#define SCALABILITY_MASK_E0104           1      ///< JCT3V-E0104: scalability mask for depth
    6773#define LAYER_CTB                        0      ///< enable layer-specific CTB structure
     74#if POC_RESET_FLAG
     75#define PREVTID0_POC_RESET               1      ///< JCTVC-O0117 Modification of the PicOrderCntVal of prevTid0Pic
     76#define POC_RESET_RPS                    1      ///< JCTVC-O0117 Modification to the decoding process for rps
     77#endif
    6878
    6979#define ILP_SSH_SIG                      1      ///< JCTVC-N0195 proposal 2, JCTVC-N0118: add presence flag in VPS ext to condition inter-layer prediction signaling in slice segment header
     
    8696
    8797#if VPS_VUI
     98#define VPS_VUI_TILES_NOT_IN_USE__FLAG    1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
     99#define VPS_VUI_WPP_NOT_IN_USE__FLAG    1      ///< JCTVC-O0226: VPS VUI flag to indicate tile not in use
    88100#define TILE_BOUNDARY_ALIGNED_FLAG       1      ///< JCTVC-N0160/JCTVC-N0199 proposal 2 variant 2: VPS VUI flag to indicate tile boundary alignment
    89101#define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
    90102#define VPS_VUI_BITRATE_PICRATE          1      ///< JCTVC-N0085: Signal bit rate and picture in VPS VUI
     103#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     104#define HIGHER_LAYER_IRAP_SKIP_FLAG      1      ///< JCTVC-O0199: Indication that higher layer IRAP picture uses skip blocks only
     105#endif
     106#define VPS_VUI_VIDEO_SIGNAL             1      ///< JCTVC-O0118 video signal information
    91107#endif //VPS_VUI
    92108
     
    127143#define N0120_MAX_TID_REF_CFG            1      ///< set max_tid_il_ref_pics_plus1 and max_tid_ref_present_flag in the config. file (configuration setting)
    128144#define O0225_MAX_TID_FOR_REF_LAYERS     1
     145#define O0225_TID_BASED_IL_RPS_DERIV     1
     146
     147#define VPS_TSLAYERS                     1      ///< JCTVC-O0120 signal max temporal sub-layers for each layer
     148#define TSLAYERS_IL_RPS                  1      ///< JCTVC-O0120 IL RPS based on max temporal sub-layers
    129149#endif
    130150#if REF_IDX_MFM
     
    139159#define M0457_IL_SAMPLE_PRED_ONLY_FLAG   0      ///< shall be 0, JCTVC-N0107
    140160#endif
     161
     162#define O0223_PICTURE_TYPES_ALIGN_FLAG   1  ///< a flag to indicatate whether picture types are aligned across layers.
    141163
    142164#define N0147_IRAP_ALIGN_FLAG            1      ///< a flag to indicatate whether IRAPs are aligned across layers
     
    166188#define SHM_FIX7                         1      ///< fix for SHVC WD ticket #7
    167189
     190#define O0092_0094_DEPENDENCY_CONSTRAINT 1      ///< JCTVC-O0092: constraint on the layer_id of SPS/PPS
     191#if O0092_0094_DEPENDENCY_CONSTRAINT
     192#define MAX_REF_LAYERS                   7
     193#endif
     194#define O0096_REP_FORMAT_INDEX           1      ///< JCTVC-O0096: identify SPS rep_format() with an index into the lists of formats in VPS extension.
     195#define O0096_DEFAULT_DEPENDENCY_TYPE    1      ///< JCTVC-O0096: specify default dependency type for all direct reference layers
     196
     197#define RESAMPLING_CONSTRAINT_BUG_FIX    1
     198#define O0098_SCALED_REF_LAYER_ID        1      ///< JCTVC-O0098: signal scaled reference id
     199
     200#define O0153_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-O0153: alt output layer flag
     201
     202#define VPS_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: signaling DPB-related parameters
     203#if VPS_DPB_SIZE_TABLE
     204#define OUTPUT_LAYER_SET_INDEX           1      ///< JCTVC-O0217: DPB operations: Inference/input of output layer set index
     205#if OUTPUT_LAYER_SET_INDEX
     206#define USE_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: Use signaled DPB-size table parameters in the decoder
     207#endif
     208#endif
     209
     210#define NO_CLRAS_OUTPUT_FLAG             1
     211#define O0149_CROSS_LAYER_BLA_FLAG       1      ///< JCTVC-O0149: signal cross_layer_bla_flag in slice header
     212
    168213#else
    169214#define SYNTAX_OUTPUT                    0
     
    174219//! \{
    175220
    176 #define FIX1071 1 ///< fix for issue #1071
     221#define HM_CLEANUP_SAO                  1  ///< JCTVC-N0230, 1) three SAO encoder-only software bugfixes. 2) new SAO implementation without picture quadtree, fine-grained slice legacies, and other redundancies.
     222#if HM_CLEANUP_SAO 
     223#define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
     224#endif
    177225
    178226#define MAX_NUM_PICS_IN_SOP           1024
     
    184232#define MAX_VPS_NUM_SCALABILITY_TYPES             16
    185233#endif
     234#define MAX_VPS_OP_LAYER_SETS_PLUS1               3
    186235#if VPS_RENAME
    187236#define MAX_VPS_LAYER_SETS_PLUS1                  1024
     
    192241#define MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1  1
    193242#endif
    194 #define RATE_CONTROL_LAMBDA_DOMAIN                  1  ///< JCTVC-K0103, rate control by R-lambda model
    195 #define M0036_RC_IMPROVEMENT                        1  ///< JCTVC-M0036, improvement for R-lambda model based rate control
    196 #define TICKET_1090_FIX                             1
    197 
    198 #define RC_FIX                                      1  /// suggested fix for M0036
    199 #define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra
    200243
    201244#define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
     
    216259#define C1FLAG_NUMBER               8 // maximum number of largerThan1 flag coded in one chunk :  16 in HM5
    217260#define C2FLAG_NUMBER               1 // maximum number of largerThan2 flag coded in one chunk:  16 in HM5
    218 
     261#if !HM_CLEANUP_SAO
    219262#define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 1  ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode
    220 
     263#endif
    221264#define SAO_ENCODING_CHOICE              1  ///< I0184: picture early termination
    222265#if SAO_ENCODING_CHOICE
     
    232275#define MAX_NUM_PPS                64
    233276
    234 #define WEIGHTED_CHROMA_DISTORTION  1   ///< F386: weighting of chroma for RDO
    235277#define RDOQ_CHROMA_LAMBDA          1   ///< F386: weighting of chroma for RDOQ
    236 #define SAO_CHROMA_LAMBDA           1   ///< F386: weighting of chroma for SAO
    237278
    238279#define MIN_SCAN_POS_CROSS          4
     
    248289#define LEVEL_RANGE                         30     ///< G382: max coefficient level in statistics collection
    249290#endif
    250 
    251 #define NS_HAD                               0
    252291
    253292#define HHI_RQT_INTRA_SPEEDUP             1           ///< tests one best mode with full rqt
     
    316355#define AMP_MRG                               1           ///< encoder only force merge for AMP partition (no motion search for AMP)
    317356#endif
    318 
    319 #define SCALING_LIST_OUTPUT_RESULT    0 //JCTVC-G880/JCTVC-G1016 quantization matrices
    320357
    321358#define CABAC_INIT_PRESENT_FLAG     1
     
    377414};
    378415
     416#if HM_CLEANUP_SAO
     417enum SAOComponentIdx
     418{
     419  SAO_Y =0,
     420  SAO_Cb,
     421  SAO_Cr,
     422  NUM_SAO_COMPONENTS
     423};
     424
     425enum SAOMode //mode
     426{
     427  SAO_MODE_OFF = 0,
     428  SAO_MODE_NEW,
     429  SAO_MODE_MERGE,
     430  NUM_SAO_MODES
     431};
     432
     433enum SAOModeMergeTypes
     434{
     435  SAO_MERGE_LEFT =0,
     436  SAO_MERGE_ABOVE,
     437  NUM_SAO_MERGE_TYPES
     438};
     439
     440
     441enum SAOModeNewTypes
     442{
     443  SAO_TYPE_START_EO =0,
     444  SAO_TYPE_EO_0 = SAO_TYPE_START_EO,
     445  SAO_TYPE_EO_90,
     446  SAO_TYPE_EO_135,
     447  SAO_TYPE_EO_45,
     448 
     449  SAO_TYPE_START_BO,
     450  SAO_TYPE_BO = SAO_TYPE_START_BO,
     451
     452  NUM_SAO_NEW_TYPES
     453};
     454#define NUM_SAO_EO_TYPES_LOG2 2
     455
     456enum SAOEOClasses
     457{
     458  SAO_CLASS_EO_FULL_VALLEY = 0,
     459  SAO_CLASS_EO_HALF_VALLEY = 1,
     460  SAO_CLASS_EO_PLAIN       = 2,
     461  SAO_CLASS_EO_HALF_PEAK   = 3,
     462  SAO_CLASS_EO_FULL_PEAK   = 4,
     463  NUM_SAO_EO_CLASSES,
     464};
     465
     466
     467#define NUM_SAO_BO_CLASSES_LOG2  5
     468enum SAOBOClasses
     469{
     470  //SAO_CLASS_BO_BAND0 = 0,
     471  //SAO_CLASS_BO_BAND1,
     472  //SAO_CLASS_BO_BAND2,
     473  //...
     474  //SAO_CLASS_BO_BAND31,
     475
     476  NUM_SAO_BO_CLASSES = (1<<NUM_SAO_BO_CLASSES_LOG2),
     477};
     478#define MAX_NUM_SAO_CLASSES  32  //(NUM_SAO_EO_GROUPS > NUM_SAO_BO_GROUPS)?NUM_SAO_EO_GROUPS:NUM_SAO_BO_GROUPS
     479
     480struct SAOOffset
     481{
     482  Int modeIdc; //NEW, MERGE, OFF
     483  Int typeIdc; //NEW: EO_0, EO_90, EO_135, EO_45, BO. MERGE: left, above
     484  Int typeAuxInfo; //BO: starting band index
     485  Int offset[MAX_NUM_SAO_CLASSES];
     486
     487  SAOOffset();
     488  ~SAOOffset();
     489  Void reset();
     490
     491  const SAOOffset& operator= (const SAOOffset& src);
     492};
     493
     494struct SAOBlkParam
     495{
     496
     497  SAOBlkParam();
     498  ~SAOBlkParam();
     499  Void reset();
     500  const SAOBlkParam& operator= (const SAOBlkParam& src);
     501  SAOOffset& operator[](Int compIdx){ return offsetParam[compIdx];}
     502private:
     503  SAOOffset offsetParam[NUM_SAO_COMPONENTS];
     504
     505};
     506
     507
     508#else
    379509#define NUM_DOWN_PART 4
    380510
     
    448578  ~SAOParam();
    449579};
    450 
     580#endif
    451581/// parameters for deblocking filter
    452582typedef struct _LFCUParam
  • trunk/source/Lib/TLibDecoder/NALread.cpp

    r313 r540  
    126126  else
    127127  {
    128     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R
     128    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
    129129         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
    130130         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r494 r540  
    290290    }
    291291  }
     292
     293#if SCALINGLIST_INFERRING
     294  if( pcPPS->getLayerId() > 0 )
     295  {
     296    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
     297    pcPPS->setInferScalingListFlag( uiCode );
     298  }
     299
     300  if( pcPPS->getInferScalingListFlag() )
     301  {
     302    READ_UVLC( uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setScalingListRefLayerId( uiCode );
     303
     304    // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     305    assert( pcPPS->getScalingListRefLayerId() <= 62 );
     306
     307    pcPPS->setScalingListPresentFlag( false );
     308  }
     309  else
     310  {
     311#endif
     312
    292313  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
    293314
    294 #if IL_SL_SIGNALLING_N0371
    295   pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );
    296 #endif
    297 
    298315  if(pcPPS->getScalingListPresentFlag ())
    299316  {
    300 #if IL_SL_SIGNALLING_N0371
    301     pcPPS->getScalingList()->setLayerId( pcPPS->getLayerId() );
    302 
    303     if( pcPPS->getLayerId() > 0 )
    304     {
    305       READ_FLAG( uiCode, "pps_pred_scaling_list_flag" );           pcPPS->setPredScalingListFlag( uiCode ? true : false );
    306       pcPPS->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
    307 
    308       if( pcPPS->getPredScalingListFlag() )
    309       {
    310         READ_UVLC ( uiCode, "scaling_list_pps_ref_layer_id" );   pcPPS->setScalingListRefLayerId( uiCode );
    311 
    312         // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    313         assert( /*pcPPS->getScalingListRefLayerId() >= 0 &&*/ pcPPS->getScalingListRefLayerId() <= 62 );
    314 
    315         // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of pps_scaling_list_ref_layer_id shall be greater than 0
    316         if( pcPPS->getSPS()->getVPS()->getAvcBaseLayerFlag() )
    317         {
    318           assert( pcPPS->getScalingListRefLayerId() > 0 );
    319         }
    320 
    321         // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
    322         // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
    323         assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
    324 
    325         // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
    326         // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
    327         assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
    328 
    329         pcPPS->getScalingList()->setScalingListRefLayerId( pcPPS->getScalingListRefLayerId() );
    330         parseScalingList( pcPPS->getScalingList() );
    331       }
    332       else
    333       {
    334         parseScalingList( pcPPS->getScalingList() );
    335       }
    336     }
    337     else
    338     {
    339       parseScalingList( pcPPS->getScalingList() );
    340     }
    341 #else
    342317    parseScalingList( pcPPS->getScalingList() );
    343 #endif
    344   }
     318  }
     319
     320#if SCALINGLIST_INFERRING
     321  }
     322#endif
    345323
    346324  READ_FLAG( uiCode, "lists_modification_present_flag");
     
    563541    pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
    564542  }
    565 #if IL_SL_SIGNALLING_N0371
    566   pcSPS->setVPS( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId()) );
    567   pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
    568 #endif
    569543#endif
    570544  if ( pcSPS->getMaxTLayers() == 1 )
     
    599573    pcSPS->setUpdateRepFormatFlag( true );
    600574  }
     575#if O0096_REP_FORMAT_INDEX
     576  if( pcSPS->getLayerId() == 0 )
     577#else
    601578  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     579#endif
    602580  {
    603581#endif
     
    619597#if REPN_FORMAT_IN_VPS
    620598  }
     599#if O0096_REP_FORMAT_INDEX
     600  else if ( pcSPS->getUpdateRepFormatFlag() )
     601  {
     602    READ_CODE(8, uiCode, "update_rep_format_index");
     603    pcSPS->setUpdateRepFormatIndex(uiCode);
     604  }
     605#endif
    621606#endif
    622607  READ_FLAG(     uiCode, "conformance_window_flag");
     
    637622  }
    638623#if REPN_FORMAT_IN_VPS
     624#if O0096_REP_FORMAT_INDEX
     625  if( pcSPS->getLayerId() == 0 )
     626#else
    639627  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     628#endif
    640629  {
    641630#endif
     
    701690  if(pcSPS->getScalingListFlag())
    702691  {
     692#if SCALINGLIST_INFERRING
     693    if( pcSPS->getLayerId() > 0 )
     694    {
     695      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
     696    }
     697
     698    if( pcSPS->getInferScalingListFlag() )
     699    {
     700      READ_UVLC( uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setScalingListRefLayerId( uiCode );
     701
     702      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     703      assert( pcSPS->getScalingListRefLayerId() <= 62 );
     704
     705      pcSPS->setScalingListPresentFlag( false );
     706    }
     707    else
     708    {
     709#endif
    703710    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
    704711    if(pcSPS->getScalingListPresentFlag ())
    705712    {
    706 
    707 #if IL_SL_SIGNALLING_N0371
    708       pcSPS->getScalingList()->setLayerId( pcSPS->getLayerId() );
    709 
    710       if( pcSPS->getLayerId() > 0 )
    711       {
    712         READ_FLAG( uiCode, "sps_pred_scaling_list_flag" );  pcSPS->setPredScalingListFlag ( uiCode );
    713         pcSPS->getScalingList()->setPredScalingListFlag( pcSPS->getPredScalingListFlag() );
    714 
    715         if( pcSPS->getPredScalingListFlag() )
    716         {
    717           READ_UVLC( uiCode, "scaling_list_sps_ref_layer_id" );    pcSPS->setScalingListRefLayerId( uiCode );
    718 
    719           // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    720           assert( /*pcSPS->getScalingListRefLayerId() >= 0 &&*/ pcSPS->getScalingListRefLayerId() <= 62 );
    721 
    722           // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
    723           if( pcSPS->getVPS()->getAvcBaseLayerFlag() )
    724           {
    725             assert( pcSPS->getScalingListRefLayerId() > 0 );
    726           }
    727 
    728           // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
    729           // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
    730           assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
    731 
    732           // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
    733           // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
    734           assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
    735 
    736           pcSPS->getScalingList()->setScalingListRefLayerId( pcSPS->getScalingListRefLayerId() );
    737           parseScalingList( pcSPS->getScalingList() );
    738         }
    739         else
    740         {
    741           parseScalingList( pcSPS->getScalingList() );
    742         }
    743       }
    744       else
    745       {
    746         parseScalingList( pcSPS->getScalingList() );
    747       }
    748 #else
    749713      parseScalingList( pcSPS->getScalingList() );
    750 #endif
    751 
    752     }
     714    }
     715#if SCALINGLIST_INFERRING
     716    }
     717#endif
    753718  }
    754719  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
     
    813778  {
    814779#if SPS_EXTENSION
     780
     781#if O0142_CONDITIONAL_SPS_EXTENSION
     782    UInt spsExtensionTypeFlag[8];
     783    for (UInt i = 0; i < 8; i++)
     784    {
     785      READ_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" );
     786    }
     787    if (spsExtensionTypeFlag[1])
     788    {
     789      parseSPSExtension( pcSPS );
     790    }
     791    if (spsExtensionTypeFlag[7])
     792    {
     793#else
    815794    parseSPSExtension( pcSPS );
    816795    READ_FLAG( uiCode, "sps_extension2_flag");
    817796    if(uiCode)
    818797    {
     798#endif
     799
    819800#endif
    820801      while ( xMoreRbspData() )
     
    846827    {
    847828      Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
     829#if O0098_SCALED_REF_LAYER_ID
     830      READ_CODE( 6,  uiCode,  "scaled_ref_layer_left_id" );  pcSPS->setScaledRefLayerId( i, uiCode );
     831#endif
    848832      READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
    849833      READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
     
    10901074    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
    10911075  }
     1076#endif
     1077#if VPS_TSLAYERS
     1078    READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
     1079    if (vps->getMaxTSLayersPresentFlag())
     1080    {
     1081        for(i = 0; i < vps->getMaxLayers() - 1; i++)
     1082        {
     1083            READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
     1084        }
     1085    }
     1086    else
     1087    {
     1088        for( i = 0; i < vps->getMaxLayers() - 1; i++)
     1089        {
     1090            vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
     1091        }
     1092    }
    10921093#endif
    10931094#if JCTVC_M0203_INTERLAYER_PRED_IDC
     
    12081209    else
    12091210    {
     1211#if VPS_DPB_SIZE_TABLE
     1212      vps->setOutputLayerSetIdx( i, i );
     1213#endif
    12101214      // i <= (vps->getNumLayerSets() - 1)
    12111215      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
     
    12341238  }
    12351239
     1240#if O0153_ALT_OUTPUT_LAYER_FLAG
     1241  if( vps->getMaxLayers() > 1 )
     1242  {
     1243    READ_FLAG( uiCode, "alt_output_layer_flag");
     1244    vps->setAltOuputLayerFlag( uiCode ? true : false );
     1245  }
     1246#endif
     1247
    12361248#if REPN_FORMAT_IN_VPS
    12371249  READ_FLAG( uiCode, "rep_format_idx_present_flag");
     
    12401252  if( vps->getRepFormatIdxPresentFlag() )
    12411253  {
     1254#if O0096_REP_FORMAT_INDEX
     1255    READ_CODE( 8, uiCode, "vps_num_rep_formats_minus1" );
     1256#else
    12421257    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" );
     1258#endif
    12431259    vps->setVpsNumRepFormats( uiCode + 1 );
    12441260  }
     
    12631279      if( vps->getVpsNumRepFormats() > 1 )
    12641280      {
     1281#if O0096_REP_FORMAT_INDEX
     1282        READ_CODE( 8, uiCode, "vps_rep_format_idx[i]" );
     1283#else
    12651284        READ_CODE( 4, uiCode, "vps_rep_format_idx[i]" );
     1285#endif
    12661286        vps->setVpsRepFormatIdx( i, uiCode );
    12671287      }
     
    13051325#endif
    13061326
     1327#if VPS_DPB_SIZE_TABLE
     1328  vps->deriveNumberOfSubDpbs();
     1329  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
     1330  {
     1331    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
     1332    for(j = 0; j < vps->getMaxTLayers(); j++)
     1333    {
     1334      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
     1335      {
     1336        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag[i]");  vps->setSubLayerDpbInfoPresentFlag( i, j, uiCode ? true : false);
     1337      }
     1338      else
     1339      {
     1340        if( j == 0 )  // Always signal for the first sub-layer
     1341        {
     1342          vps->setSubLayerDpbInfoPresentFlag( i, j, true );
     1343        }
     1344        else // if (j != 0) && !vps->getSubLayerFlagInfoPresentFlag(i)
     1345        {
     1346          vps->setSubLayerDpbInfoPresentFlag( i, j, false );
     1347        }
     1348      }
     1349      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is present
     1350      {
     1351        for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
     1352        {
     1353          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
     1354        }
     1355        READ_UVLC( uiCode, "max_vps_num_reorder_pics[i][j]" );              vps->setMaxVpsNumReorderPics( i, j, uiCode);
     1356        READ_UVLC( uiCode, "max_vps_latency_increase_plus1[i][j]" );        vps->setMaxVpsLatencyIncreasePlus1( i, j, uiCode);
     1357      }
     1358    }
     1359  }
     1360#endif
    13071361#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
    13081362  READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
     1363#if O0096_DEFAULT_DEPENDENCY_TYPE
     1364  READ_FLAG(uiCode, "default_direct_dependency_type_flag");
     1365  vps->setDefaultDirectDependecyTypeFlag(uiCode == 1? true : false);
     1366  if (vps->getDefaultDirectDependencyTypeFlag())
     1367  {
     1368    READ_CODE( vps->getDirectDepTypeLen(), uiCode, "default_direct_dependency_type" );
     1369    vps->setDefaultDirectDependecyType(uiCode);
     1370  }
     1371#endif
    13091372  for(i = 1; i < vps->getMaxLayers(); i++)
    13101373  {
     
    13131376      if (vps->getDirectDependencyFlag(i, j))
    13141377      {
    1315         READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); vps->setDirectDependencyType(i, j, uiCode);
    1316       }
    1317     }
    1318   }
    1319 
    1320 #endif
    1321 
    1322 #if IL_SL_SIGNALLING_N0371
     1378#if O0096_DEFAULT_DEPENDENCY_TYPE
     1379        if (vps->getDefaultDirectDependencyTypeFlag())
     1380        {
     1381          vps->setDirectDependencyType(i, j, vps->getDefaultDirectDependencyType());
     1382        }
     1383        else
     1384        {
     1385          READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" );
     1386          vps->setDirectDependencyType(i, j, uiCode);
     1387        }
     1388#else
     1389        READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" );
     1390        vps->setDirectDependencyType(i, j, uiCode);
     1391#endif
     1392      }
     1393    }
     1394  }
     1395#endif
     1396#if O0092_0094_DEPENDENCY_CONSTRAINT
    13231397  for(i = 1; i < vps->getMaxLayers(); i++)
    1324     {
    1325       for(j = 0; j < i; j++)
    1326         {
    1327           vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
    1328         }
    1329     }
     1398  {
     1399    vps->setNumRefLayers(vps->getLayerIdInNuh(i));   // identify the number of direct and indirect reference layers of current layer and set recursiveRefLayersFlags
     1400  }
     1401  if(vps->getMaxLayers() > MAX_REF_LAYERS)
     1402  {
     1403    for(i = 1;i < vps->getMaxLayers(); i++)
     1404    {
     1405      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
     1406    }
     1407  }
    13301408#endif
    13311409
     
    13331411  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
    13341412#endif
     1413#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1414  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
     1415#endif
    13351416
    13361417  READ_FLAG( uiCode,  "vps_vui_present_flag" );
     
    13511432{
    13521433  UInt uiCode;
     1434#if REPN_FORMAT_CONTROL_FLAG
     1435  READ_FLAG ( uiCode, "chroma_and_bit_depth_vps_present_flag");   repFormat->setChromaAndBitDepthVpsPresentFlag(uiCode ? true : false);
     1436  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );          repFormat->setPicWidthVpsInLumaSamples ( uiCode );
     1437  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );         repFormat->setPicHeightVpsInLumaSamples( uiCode );
     1438
     1439  if( repFormat->getChromaAndBitDepthVpsPresentFlag() )
     1440  {
     1441#if AUXILIARY_PICTURES
     1442    READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
     1443#else
     1444    READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
     1445#endif
     1446
     1447    if( repFormat->getChromaFormatVpsIdc() == 3 )
     1448    {
     1449      READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
     1450    }
     1451
     1452
     1453    READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
     1454    READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
     1455  }
     1456#else
    13531457#if AUXILIARY_PICTURES
    13541458  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
     
    13671471  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
    13681472  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
    1369 
     1473#endif
    13701474}
    13711475#endif
     
    13751479  UInt i,j;
    13761480  UInt uiCode;
     1481#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1482  READ_FLAG(uiCode, "cross_layer_pic_type_aligned_flag" );
     1483  vps->setCrossLayerPictureTypeAlignFlag(uiCode);
     1484  if (!uiCode)
     1485  {
     1486#endif
    13771487#if IRAP_ALIGN_FLAG_IN_VPS_VUI
    1378   READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
    1379   vps->setCrossLayerIrapAlignFlag(uiCode);
     1488    READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
     1489    vps->setCrossLayerIrapAlignFlag(uiCode);
     1490#endif
     1491#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1492  }
     1493  else
     1494  {
     1495    vps->setCrossLayerIrapAlignFlag(true);
     1496  }
    13801497#endif
    13811498#if VPS_VUI_BITRATE_PICRATE
     
    14291546  }
    14301547#endif
     1548#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1549  UInt layerIdx;
     1550  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); vps->setTilesNotInUseFlag(uiCode == 1);
     1551  if (!uiCode)
     1552  {
     1553    for(i = 0; i < vps->getMaxLayers(); i++)
     1554    {
     1555      READ_FLAG( uiCode, "tiles_in_use_flag[ i ]" ); vps->setTilesInUseFlag(i, (uiCode == 1));
     1556      if (uiCode)
     1557      {
     1558        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[ i ]" ); vps->setLoopFilterNotAcrossTilesFlag(i, (uiCode == 1));
     1559      }
     1560      else
     1561      {
     1562        vps->setLoopFilterNotAcrossTilesFlag(i, false);
     1563      }
     1564    }
     1565#endif
    14311566#if TILE_BOUNDARY_ALIGNED_FLAG
    1432   for(i = 1; i < vps->getMaxLayers(); i++)
    1433   {
    1434     for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
    1435     {
    1436       READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
     1567    for(i = 1; i < vps->getMaxLayers(); i++)
     1568    {
     1569      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     1570      {
     1571#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1572        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
     1573        if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
     1574          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
     1575        }
     1576#else
     1577        READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
     1578#endif
     1579      }
     1580    }
     1581#endif
     1582#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1583  }
     1584#endif
     1585#if VPS_VUI_WPP_NOT_IN_USE__FLAG
     1586  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); vps->setWppNotInUseFlag(uiCode == 1);
     1587  if (!uiCode)
     1588  {
     1589    for(i = 0; i < vps->getMaxLayers(); i++)
     1590    {
     1591      READ_FLAG( uiCode, "wpp_in_use_flag[ i ]" ); vps->setWppInUseFlag(i, (uiCode == 1));
    14371592    }
    14381593  }
     
    14581613    }
    14591614  }
     1615#endif
     1616#if VPS_VUI_VIDEO_SIGNAL
     1617    READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
     1618    if (vps->getVideoSigPresentVpsFlag())
     1619    {
     1620        READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
     1621    }
     1622    else
     1623    {
     1624        vps->setNumVideoSignalInfo(vps->getMaxLayers());
     1625    }
     1626   
     1627   
     1628    for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
     1629    {
     1630        READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
     1631        READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
     1632        READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
     1633        READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
     1634        READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
     1635    }
     1636    if(!vps->getVideoSigPresentVpsFlag())
     1637    {
     1638        for (i=0; i < vps->getMaxLayers(); i++)
     1639        {
     1640            vps->setVideoSignalInfoIdx(i,i);
     1641        }
     1642    }
     1643    else {
     1644        vps->setVideoSignalInfoIdx(0,0);
     1645        if (vps->getNumVideoSignalInfo() > 1 )
     1646        {
     1647            for (i=1; i < vps->getMaxLayers(); i++)
     1648                READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
     1649        }
     1650        else {
     1651          for (i=1; i < vps->getMaxLayers(); i++)
     1652          {
     1653            vps->setVideoSignalInfoIdx(i,0);
     1654          }
     1655        }
     1656    }
    14601657#endif
    14611658}
     
    15481745      iBits++;
    15491746    }
     1747#if O0149_CROSS_LAYER_BLA_FLAG
     1748    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     1749    {
     1750      READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
     1751      iBits++;
     1752    }
     1753#endif
    15501754    for (; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
    15511755    {
     
    17341938            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
    17351939                                        - iPOClsb + pocLsbLt;
    1736 
    17371940            rps->setPOC     (j, pocLTCurr);
    17381941            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
     
    18372040        else
    18382041        {
     2042#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
     2043          if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
     2044             (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
     2045        {
     2046#endif
    18392047          rpcSlice->setActiveNumILRRefIdx(1);
    18402048          rpcSlice->setInterLayerPredLayerIdc(0,0);
     2049#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
     2050        }
     2051#endif
    18412052        }
    18422053      }
     
    18442055#if ILP_SSH_SIG
    18452056#if ILP_SSH_SIG_FIX
    1846     else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true )
     2057    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
    18472058#else
    18482059    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
     
    18502061    {
    18512062      rpcSlice->setInterLayerPredEnabledFlag(true);
     2063
     2064#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
     2065      Int   numRefLayerPics = 0;
     2066      Int   i = 0;
     2067      Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
     2068      for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ )
     2069      {
     2070        if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
     2071           (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
     2072        {         
     2073          refLayerPicIdc[ numRefLayerPics++ ] = i;
     2074        }
     2075      }
     2076      rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
     2077      for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
     2078      {
     2079        rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
     2080      }     
     2081#else
    18522082      rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
    18532083      for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
     
    18552085        rpcSlice->setInterLayerPredLayerIdc(i,i);
    18562086      }
     2087#endif
    18572088    }
    18582089#endif
     
    18792110      ChromaFormat format;
    18802111#if REPN_FORMAT_IN_VPS
     2112#if O0096_REP_FORMAT_INDEX
     2113      if( sps->getLayerId() == 0 )
     2114      {
     2115        format = sps->getChromaFormatIdc();
     2116      }
     2117      else
     2118      {
     2119        format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
     2120      }
     2121#else
    18812122      if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
    18822123      {
     
    18872128        format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
    18882129      }
     2130#endif
    18892131#else
    18902132      format = sps->getChromaFormatIdc();
     
    20392281#if M0457_COL_PICTURE_SIGNALING
    20402282#if REMOVE_COL_PICTURE_SIGNALING
    2041       rpcSlice->setMFMEnabledFlag( rpcSlice->getNumMotionPredRefLayers() > 0 ? true : false );
     2283      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() ) ? true : false );
    20422284#else
    20432285      rpcSlice->setMFMEnabledFlag( false );
     
    26332875  UInt  code, sizeId, listId;
    26342876  Bool scalingListPredModeFlag;
    2635 
    26362877  //for each size
    26372878  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    26392880    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
    26402881    {
    2641 #if IL_SL_SIGNALLING_N0371
    2642       if ( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2643       {
    2644         READ_FLAG( code, "scaling_list_pred_mode_flag");
    2645         scalingListPredModeFlag = (code) ? true : false;
    2646         if(!scalingListPredModeFlag) //Copy Mode
    2647         {
    2648           READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
    2649           scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
    2650           if( sizeId > SCALING_LIST_8x8 )
    2651           {
    2652             scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
    2653           }
    2654           scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
    2655 
    2656         }
    2657         else //DPCM Mode
    2658         {
    2659           xDecodeScalingList(scalingList, sizeId, listId);
    2660         }
    2661       }
    2662       else
    2663       {
    2664         READ_FLAG( code, "scaling_list_pred_mode_flag");
    2665         scalingListPredModeFlag = (code) ? true : false;
    2666         if(!scalingListPredModeFlag) //Copy Mode
    2667         {
    2668           READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
    2669           scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
    2670           if( sizeId > SCALING_LIST_8x8 )
    2671           {
    2672             scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
    2673           }
    2674           scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
    2675 
    2676         }
    2677         else //DPCM Mode
    2678         {
    2679           xDecodeScalingList(scalingList, sizeId, listId);
    2680         }
    2681       }
    2682 #else
    26832882      READ_FLAG( code, "scaling_list_pred_mode_flag");
    26842883      scalingListPredModeFlag = (code) ? true : false;
     
    26982897        xDecodeScalingList(scalingList, sizeId, listId);
    26992898      }
    2700 #endif
    27012899    }
    27022900  }
     
    27202918  if( sizeId > SCALING_LIST_8x8 )
    27212919  {
    2722 #if IL_SL_SIGNALLING_N0371
    2723     if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2724     {
    2725       ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
    2726       scalingList->setScalingListDC(sizeId,listId,ref_scalingListDC[scalingList->getScalingListRefLayerId()][sizeId][listId]);
    2727     }
    2728     else
    2729     {
    2730       READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
    2731       scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
    2732       nextCoef = scalingList->getScalingListDC(sizeId,listId);
    2733       ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
    2734     }
    2735 #else
    27362920    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
    27372921    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
    27382922    nextCoef = scalingList->getScalingListDC(sizeId,listId);
    2739 #endif
    27402923  }
    27412924
    27422925  for(i = 0; i < coefNum; i++)
    27432926  {
    2744 #if IL_SL_SIGNALLING_N0371
    2745     if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2746     {
    2747       ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = dst[scan[i]];
    2748       dst[scan[i]] = ref_scalingListCoef[scalingList->getScalingListRefLayerId()][sizeId][listId][i];
    2749     }
    2750     else
    2751     {
    2752       READ_SVLC( data, "scaling_list_delta_coef");
    2753       nextCoef = (nextCoef + data + 256 ) % 256;
    2754       dst[scan[i]] = nextCoef;
    2755       ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = dst[scan[i]];
    2756     }
    2757 #else
    27582927    READ_SVLC( data, "scaling_list_delta_coef");
    27592928    nextCoef = (nextCoef + data + 256 ) % 256;
    27602929    dst[scan[i]] = nextCoef;
    2761 #endif
    27622930  }
    27632931}
     
    27912959  return (cnt>0);
    27922960}
     2961
    27932962//! \}
    27942963
  • trunk/source/Lib/TLibDecoder/TDecCu.cpp

    r494 r540  
    317317  }
    318318 
     319#if HIGHER_LAYER_IRAP_SKIP_FLAG
     320  if (pcCU->getSlice()->getVPS()->getHigherLayerIrapSkipFlag() && pcCU->getSlice()->getVPS()->getSingleLayerForNonIrapFlag() && pcCU->getLayerId() > 0)
     321  {
     322    Bool lowerLayerExist = false;
     323    for(int i=0;i<pcCU->getLayerId();i++)
     324    {
     325      if(pcCU->getSlice()->getBaseColPic(pcCU->getSlice()->getInterLayerPredLayerIdc(i)))
     326      {
     327        lowerLayerExist = true;
     328      }
     329    }
     330    if(lowerLayerExist)
     331    {
     332      assert(pcCU->isSkipped(uiAbsPartIdx));
     333    }
     334  }
     335#endif
     336 
    319337  if( pcCU->isSkipped(uiAbsPartIdx) )
    320338  {
     
    945963
    946964}
     965
    947966//! \}
  • trunk/source/Lib/TLibDecoder/TDecEntropy.h

    r494 r540  
    106106  virtual Void parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
    107107  virtual Void parseTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) = 0;
    108 
    109108  virtual Void updateContextTables( SliceType eSliceType, Int iQp ) = 0;
    110109 
     
    166165  Void updateContextTables    ( SliceType eSliceType, Int iQp ) { m_pcEntropyDecoderIf->updateContextTables( eSliceType, iQp ); }
    167166 
     167 
    168168private:
    169169  Void xDecodeTransform        ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP );
  • trunk/source/Lib/TLibDecoder/TDecGop.cpp

    r442 r540  
    128128  //-- For time output for each slice
    129129  long iBeforeTime = clock();
    130  
     130#if !HM_CLEANUP_SAO
    131131  UInt uiStartCUAddr   = pcSlice->getSliceSegmentCurStartCUAddr();
    132132
     
    136136    m_sliceStartCUAddress.push_back(uiSliceStartCuAddr);
    137137  }
    138 
     138#endif
    139139  m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC );
    140140  m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
     
    163163  m_pcEntropyDecoder->setBitstream      ( ppcSubstreams[0] );
    164164  m_pcEntropyDecoder->resetEntropy      (pcSlice);
    165 
     165#if !HM_CLEANUP_SAO
    166166  if(uiSliceStartCuAddr == uiStartCUAddr)
    167167  {
    168168    m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());
    169169  }
     170#endif
    170171  m_pcSbacDecoders[0].load(m_pcSbacDecoder);
    171172  m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
     
    195196  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
    196197  m_pcLoopFilter->loopFilterPic( rpcPic );
    197 
     198#if !HM_CLEANUP_SAO
    198199  if(pcSlice->getSPS()->getUseSAO())
    199200  {
     
    201202    rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, 0, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary);
    202203  }
    203 
     204#endif
    204205  if( pcSlice->getSPS()->getUseSAO() )
    205206  {
     207#if HM_CLEANUP_SAO
     208    m_pcSAO->reconstructBlkSAOParams(rpcPic, rpcPic->getPicSym()->getSAOBlkParam());
     209    m_pcSAO->SAOProcess(rpcPic);
     210    m_pcSAO->PCMLFDisableProcess(rpcPic);
     211#else
    206212    {
    207213      SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
     
    214220      m_pcSAO->destroyPicSaoInfo();
    215221    }
    216   }
    217 
     222#endif
     223  }
     224#if !HM_CLEANUP_SAO
    218225  if(pcSlice->getSPS()->getUseSAO())
    219226  {
    220227    rpcPic->destroyNonDBFilterInfo();
    221228  }
    222 
     229#endif
    223230  rpcPic->compressMotion();
    224231  Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
     
    283290  rpcPic->setOutputMark(true);
    284291  rpcPic->setReconMark(true);
     292#if !HM_CLEANUP_SAO
    285293  m_sliceStartCUAddress.clear();
    286294  m_LFCrossSliceBoundaryFlag.clear();
     295#endif
    287296}
    288297
  • trunk/source/Lib/TLibDecoder/TDecGop.h

    r313 r540  
    8383  Int                   m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
    8484
     85#if !HM_CLEANUP_SAO
    8586  //! list that contains the CU address of each slice plus the end address
    8687  std::vector<Int> m_sliceStartCUAddress;
    8788  std::vector<Bool> m_LFCrossSliceBoundaryFlag;
    88 
     89#endif
    8990#if SVC_EXTENSION
    9091  UInt                  m_layerId;
  • trunk/source/Lib/TLibDecoder/TDecSbac.cpp

    r494 r540  
    368368#if AUXILIARY_PICTURES
    369369        if (format == CHROMA_400)
     370        {
    370371          uiSample = uiGrayVal;
     372        }
    371373        else
    372374#endif
     
    389391#if AUXILIARY_PICTURES
    390392        if (format == CHROMA_400)
     393        {
    391394          uiSample = uiGrayVal;
     395        }
    392396        else
    393397#endif
     
    13781382    if (uiCode == 0)
    13791383    {
     1384#if HM_CLEANUP_SAO
     1385      ruiVal = 1;
     1386#else
    13801387      ruiVal = 5;
     1388#endif
    13811389    }
    13821390    else
    13831391    {
     1392#if HM_CLEANUP_SAO
     1393      ruiVal = 2;
     1394#else
    13841395      ruiVal = 1;
    1385     }
    1386   }
    1387 }
     1396#endif
     1397    }
     1398  }
     1399}
     1400
     1401#if HM_CLEANUP_SAO
     1402
     1403Void TDecSbac::parseSaoSign(UInt& val)
     1404{
     1405  m_pcTDecBinIf->decodeBinEP ( val );
     1406}
     1407
     1408Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
     1409                                , Bool* sliceEnabled
     1410                                , Bool leftMergeAvail
     1411                                , Bool aboveMergeAvail
     1412                                )
     1413{
     1414  UInt uiSymbol;
     1415
     1416  Bool isLeftMerge = false;
     1417  Bool isAboveMerge= false;
     1418
     1419  if(leftMergeAvail)
     1420  {
     1421    parseSaoMerge(uiSymbol); //sao_merge_left_flag
     1422    isLeftMerge = (uiSymbol?true:false);
     1423  }
     1424
     1425  if( aboveMergeAvail && !isLeftMerge)
     1426  {
     1427    parseSaoMerge(uiSymbol); //sao_merge_up_flag
     1428    isAboveMerge = (uiSymbol?true:false);
     1429  }
     1430
     1431  if(isLeftMerge || isAboveMerge) //merge mode
     1432  {
     1433    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
     1434    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
     1435  }
     1436  else //new or off mode
     1437  {   
     1438    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     1439    {
     1440      SAOOffset& ctbParam = saoBlkParam[compIdx];
     1441
     1442      if(!sliceEnabled[compIdx])
     1443      {
     1444        //off
     1445        ctbParam.modeIdc = SAO_MODE_OFF;
     1446        continue;
     1447      }
     1448
     1449      //type
     1450      if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1451      {
     1452        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
     1453
     1454        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
     1455
     1456        if(uiSymbol ==0) //OFF
     1457        {
     1458          ctbParam.modeIdc = SAO_MODE_OFF;
     1459        }
     1460        else if(uiSymbol == 1) //BO
     1461        {
     1462          ctbParam.modeIdc = SAO_MODE_NEW;
     1463          ctbParam.typeIdc = SAO_TYPE_START_BO;
     1464        }
     1465        else //2, EO
     1466        {
     1467          ctbParam.modeIdc = SAO_MODE_NEW;
     1468          ctbParam.typeIdc = SAO_TYPE_START_EO;
     1469        }
     1470
     1471      }
     1472      else //Cr, follow Cb SAO type
     1473      {
     1474        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
     1475        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
     1476      }
     1477
     1478      if(ctbParam.modeIdc == SAO_MODE_NEW)
     1479      {
     1480        Int offset[4];
     1481        for(Int i=0; i< 4; i++)
     1482        {
     1483          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     1484          offset[i] = (Int)uiSymbol;
     1485        }
     1486
     1487        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
     1488        {
     1489          for(Int i=0; i< 4; i++)
     1490          {
     1491            if(offset[i] != 0)
     1492            {
     1493              parseSaoSign(uiSymbol); //sao_offset_sign
     1494              if(uiSymbol)
     1495              {
     1496                offset[i] = -offset[i];
     1497              }
     1498            }
     1499          }
     1500          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
     1501          ctbParam.typeAuxInfo = uiSymbol;
     1502       
     1503          for(Int i=0; i<4; i++)
     1504          {
     1505            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
     1506          }     
     1507       
     1508        }
     1509        else //EO
     1510        {
     1511          ctbParam.typeAuxInfo = 0;
     1512
     1513          if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1514          {
     1515            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
     1516            ctbParam.typeIdc += uiSymbol;
     1517          }
     1518          else
     1519          {
     1520            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
     1521          }
     1522          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
     1523          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
     1524          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
     1525          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
     1526          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
     1527        }
     1528      }
     1529    }
     1530  }
     1531}
     1532
     1533#else
    13881534
    13891535inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
     
    15591705}
    15601706
     1707#endif
     1708
    15611709/**
    15621710 - Initialize our contexts from the nominated source.
  • trunk/source/Lib/TLibDecoder/TDecSbac.h

    r494 r540  
    9090  Void  parseSaoTypeIdx           ( UInt&  ruiVal  );
    9191  Void  parseSaoUflc              ( UInt uiLength, UInt& ruiVal     );
     92#if HM_CLEANUP_SAO
     93  Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail);
     94  Void parseSaoSign(UInt& val);
     95#else
    9296  Void  parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
    9397  Void  parseSaoOffset            (SaoLcuParam* psSaoLcuParam, UInt compIdx);
     98#endif
    9499private:
    95100  Void  xReadUnarySymbol    ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset );
  • trunk/source/Lib/TLibDecoder/TDecSlice.cpp

    r345 r540  
    197197  UInt uiTileLCUX;
    198198  Int iNumSubstreamsPerTile = 1; // if independent.
    199 
    200199  Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
    201200  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr();
     
    323322    g_bJustDoIt = g_bEncDecTraceEnable;
    324323#endif
     324
     325#if HM_CLEANUP_SAO
     326    if ( pcSlice->getSPS()->getUseSAO() )
     327    {
     328      SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[iCUAddr];
     329      if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     330      {
     331        Bool sliceEnabled[NUM_SAO_COMPONENTS];
     332        sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
     333        sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
     334
     335        Bool leftMergeAvail = false;
     336        Bool aboveMergeAvail= false;
     337
     338        //merge left condition
     339        Int rx = (iCUAddr % uiWidthInLCUs);
     340        if(rx > 0)
     341        {
     342          leftMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-1);
     343        }
     344        //merge up condition
     345        Int ry = (iCUAddr / uiWidthInLCUs);
     346        if(ry > 0)
     347        {
     348          aboveMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-uiWidthInLCUs);
     349        }
     350
     351        pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
     352      }
     353      else
     354      {
     355        saoblkParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
     356        saoblkParam[SAO_Cb].modeIdc = SAO_MODE_OFF;
     357        saoblkParam[SAO_Cr].modeIdc = SAO_MODE_OFF;
     358      }
     359    }
     360#else
    325361    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    326362    {
     
    374410      }
    375411    }
     412#endif
     413
    376414    m_pcCuDecoder->decodeCU     ( pcCU, uiIsLast );
    377415    m_pcCuDecoder->decompressCU ( pcCU );
  • trunk/source/Lib/TLibDecoder/TDecTop.cpp

    r494 r540  
    7979  m_prevSliceSkipped = false;
    8080  m_skippedPOC = 0;
     81#if NO_CLRAS_OUTPUT_FLAG
     82  m_noClrasOutputFlag          = false;
     83  m_layerInitializedFlag       = false;
     84  m_firstPicInLayerDecodedFlag = false;
     85  m_noOutputOfPriorPicsFlags   = false;
     86  m_bRefreshPending            = false;
     87#endif
    8188}
    8289
     
    170177    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
    171178    {
     179#if USE_DPB_SIZE_TABLE
     180      if( getCommonDecoderParams()->getOutputLayerSetIdx() == 0 )
     181      {
     182        assert( this->getLayerId() == 0 );
     183        numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
     184      }
     185      else
     186      {
     187        TComVPS *vps = slice->getVPS();
     188        // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
     189        numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getOutputLayerSetIdx() , temporalLayer);
     190      }
     191#else
    172192      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
     193#endif
    173194    }
    174195
     
    260281  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
    261282  {
     283#if USE_DPB_SIZE_TABLE
     284    if( getCommonDecoderParams()->getOutputLayerSetIdx() == 0 )
     285    {
     286      assert( this->getLayerId() == 0 );
     287      numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
     288    }
     289    else
     290    {
     291      TComVPS *vps = pcSlice->getVPS();
     292      // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
     293      numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getOutputLayerSetIdx() , temporalLayer);
     294    }
     295#else
    262296    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
    263   }
    264 
     297#endif
     298  }
     299
     300#if USE_DPB_SIZE_TABLE
     301  if( getCommonDecoderParams()->getOutputLayerSetIdx() == 0 )
     302  {
     303    assert( this->getLayerId() == 0 );
     304    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
     305  }
     306  else
     307  {
     308    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
     309  }
     310#else
    265311  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
     312#endif
    266313
    267314#if SVC_EXTENSION
     
    278325      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
    279326      {
     327#if O0098_SCALED_REF_LAYER_ID
     328        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
     329#else
    280330        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
     331#endif
    281332        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
    282333
     
    344395#endif
    345396#endif
    346 
     397#if !HM_CLEANUP_SAO
    347398    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
     399#endif
    348400    m_cListPic.pushBack( rpcPic );
    349401   
     
    425477#endif
    426478#endif
     479#if !HM_CLEANUP_SAO
    427480  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
     481#endif
    428482}
    429483
     
    531585  printf("\ninserting lost poc : %d\n",iLostPoc);
    532586  TComSlice cFillSlice;
    533 #if SVC_EXTENSION
    534   cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
    535   cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
    536   cFillSlice.setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() );
    537   cFillSlice.initSlice( m_layerId );
    538 #else
    539587  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
    540588  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
     589#if SVC_EXTENSION
     590  cFillSlice.setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
     591  cFillSlice.initSlice( m_layerId );
     592#else
    541593  cFillSlice.initSlice();
    542594#endif
    543595  TComPic *cFillPic;
    544596  xGetNewPicBuffer(&cFillSlice,cFillPic);
    545 #if SVC_EXTENSION
    546   cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
    547   cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
    548   cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() );
    549   cFillPic->getSlice(0)->initSlice( m_layerId );
    550 #else
    551597  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
    552598  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
     599#if SVC_EXTENSION
     600  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
     601  cFillPic->getSlice(0)->initSlice( m_layerId );
     602#else
    553603  cFillPic->getSlice(0)->initSlice();
    554604#endif
     
    593643Void TDecTop::xActivateParameterSets()
    594644{
    595 #if SVC_EXTENSION
    596   m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
    597  
    598   TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId());
    599   assert (pps != 0);
    600 
    601   TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId());
    602   assert (sps != 0);
    603 
    604   if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->isIRAP()) )
    605 #else
    606645  m_parameterSetManagerDecoder.applyPrefetchedPS();
    607646 
     
    613652
    614653  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
    615 #endif
    616654  {
    617655    printf ("Parameter set activation failed!");
    618656    assert (0);
    619657  }
     658
     659#if SCALINGLIST_INFERRING
     660  // scaling list settings and checks
     661  TComVPS *activeVPS = m_parameterSetManagerDecoder.getActiveVPS();
     662  TComSPS *activeSPS = m_parameterSetManagerDecoder.getActiveSPS();
     663  TComPPS *activePPS = m_parameterSetManagerDecoder.getActivePPS();
     664
     665  if( activeSPS->getInferScalingListFlag() )
     666  {
     667    UInt refLayerId = activeSPS->getScalingListRefLayerId();
     668    TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
     669
     670    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
     671    if( activeVPS->getAvcBaseLayerFlag() )
     672    {
     673      assert( refLayerId > 0 );
     674    }
     675
     676    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
     677    // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
     678    assert( refSps->getInferScalingListFlag() == false );
     679
     680    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
     681    // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
     682    assert( activeVPS->getRecursiveRefLayerFlag( activeSPS->getLayerId(), refLayerId ) == true );
     683   
     684    if( activeSPS->getScalingList() != refSps->getScalingList() )
     685    {
     686      // delete created instance of scaling list since it will be inferred
     687      delete activeSPS->getScalingList();
     688
     689      // infer scaling list
     690      activeSPS->setScalingList( refSps->getScalingList() );
     691    }
     692  }
     693
     694  if( activePPS->getInferScalingListFlag() )
     695  {
     696    UInt refLayerId = activePPS->getScalingListRefLayerId();
     697    TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
     698
     699    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
     700    if( activeVPS->getAvcBaseLayerFlag() )
     701    {
     702      assert( refLayerId > 0 );
     703    }
     704
     705    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
     706    // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
     707    assert( refPps->getInferScalingListFlag() == false );
     708
     709    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
     710    // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
     711    assert( activeVPS->getRecursiveRefLayerFlag( activePPS->getLayerId(), refLayerId ) == true );
     712   
     713    if( activePPS->getScalingList() != refPps->getScalingList() )
     714    {
     715      // delete created instance of scaling list since it will be inferred
     716      delete activePPS->getScalingList();
     717
     718      // infer scaling list
     719      activePPS->setScalingList( refPps->getScalingList() );
     720    }
     721
     722  }
     723#endif
    620724
    621725  if( pps->getDependentSliceSegmentsEnabledFlag() )
     
    670774  m_cSAO.destroy();
    671775#if REPN_FORMAT_IN_VPS
     776#if AUXILIARY_PICTURES
     777#if HM_CLEANUP_SAO
     778  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
     779#else
    672780  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
     781#endif
     782#else
     783#if HM_CLEANUP_SAO
     784  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
     785#else
     786  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
     787#endif
     788#endif
     789#else
     790#if HM_CLEANUP_SAO
     791  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
    673792#else
    674793  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
     794#endif
    675795#endif
    676796  m_cLoopFilter.create( sps->getMaxCUDepth() );
     
    688808{
    689809  TComPic*&   pcPic         = m_pcPic;
     810#if NO_CLRAS_OUTPUT_FLAG
     811  Bool bFirstSliceInSeq;
     812#endif
    690813#if SVC_EXTENSION
    691   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder[m_layerId].getPrefetchedVPS(0) );
     814  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
     815#if OUTPUT_LAYER_SET_INDEX
     816  // Following check should go wherever the VPS is activated
     817  checkValueOfOutputLayerSetIdx( m_apcSlicePilot->getVPS());
     818#endif
    692819  m_apcSlicePilot->initSlice( nalu.m_layerId );
    693820#else
     
    727854  m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() );
    728855#endif
    729   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
    730 #else
     856#endif
    731857  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
    732 #endif
    733858
    734859  // set POC for dependent slices in skipped pictures
     
    788913  // actual decoding starts here
    789914  xActivateParameterSets();
    790 #if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS
     915#if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS && N0147_IRAP_ALIGN_FLAG
    791916  //Note setting O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS to 0 may cause decoder to crash.
    792917  //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1
     
    801926  }
    802927#endif
    803 
    804928#if REPN_FORMAT_IN_VPS
    805929  // Initialize ILRP if needed, only for the current layer 
     
    816940#endif
    817941  }
     942#if NO_CLRAS_OUTPUT_FLAG
     943  bFirstSliceInSeq = m_bFirstSliceInSequence;
     944#endif
    818945  m_bFirstSliceInSequence = false;
    819946#if POC_RESET_FLAG
     
    829956      Int pocAdjustValue = m_apcSlicePilot->getPOC();
    830957
     958#if PREVTID0_POC_RESET
     959      m_apcSlicePilot->adjustPrevTid0POC(pocAdjustValue);
     960#endif
    831961      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
    832962      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
     
    8821012    // Check for TSA alignment
    8831013    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
    884         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R
     1014        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R
    8851015         )
    8861016    {
     
    8921022        {
    8931023          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
    894                     m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R );    // TSA pictures should be aligned among depenedent layers
     1024                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R );    // TSA pictures should be aligned among depenedent layers
    8951025        }
    8961026      }
     
    9241054  {
    9251055#if AVC_BASE
    926     if( m_layerId == 1 && m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
     1056    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
    9271057    {
    9281058      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
     1059      pBLPic->getSlice(0)->setReferenced(true);
    9291060      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
    9301061      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
     
    9731104#endif
    9741105
     1106#if NO_CLRAS_OUTPUT_FLAG
     1107    if (m_layerId == 0 &&
     1108        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1109      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     1110      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     1111      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     1112      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
     1113      || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     1114    {
     1115      if (bFirstSliceInSeq)
     1116      {
     1117        setNoClrasOutputFlag(true);
     1118      }
     1119      else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1120            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     1121            || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP)
     1122      {
     1123        setNoClrasOutputFlag(true);
     1124      }
     1125#if O0149_CROSS_LAYER_BLA_FLAG
     1126      else if ((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) &&
     1127               m_apcSlicePilot->getCrossLayerBLAFlag())
     1128      {
     1129        setNoClrasOutputFlag(true);
     1130      }
     1131#endif
     1132      else
     1133      {
     1134        setNoClrasOutputFlag(false);
     1135      }
     1136      if (getNoClrasOutputFlag())
     1137      {
     1138        for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
     1139        {
     1140          m_ppcTDecTop[i]->setLayerInitializedFlag(false);
     1141          m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
     1142        }
     1143      }
     1144    }
     1145#endif
     1146
     1147#if NO_CLRAS_OUTPUT_FLAG
     1148    m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
     1149#endif
     1150
    9751151    // Buffer initialize for prediction.
    9761152    m_cPrediction.initTempBuff();
     
    11431319    if (m_layerId == 0)
    11441320#endif
    1145 #if FIX1071
    11461321    pcSlice->setRefPicList( m_cListPic, true );
    1147 #else
    1148     pcSlice->setRefPicList( m_cListPic );
    1149 #endif
    11501322
    11511323#if SVC_EXTENSION
     
    11541326    if( m_layerId > 0 && m_uiSliceIdx == 0 )
    11551327    {     
     1328#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     1329      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
     1330#endif
    11561331      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
    11571332      {
    11581333        UInt refLayerIdc = i;
    11591334#if AVC_BASE
    1160         if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
     1335        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
     1336        {         
     1337          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
     1338
     1339          if( pic )
     1340          {
     1341            pcSlice->setBaseColPic ( refLayerIdc, pic );
     1342          }
     1343          else
     1344          {
     1345            continue;
     1346          }
     1347#if AVC_SYNTAX
     1348          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
     1349          if( pcSlice->getPOC() == 0 )
     1350          {
     1351            // initialize partition order.
     1352            UInt* piTmp = &g_auiZscanToRaster[0];
     1353            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
     1354            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
     1355          }     
     1356          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
     1357          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
     1358#endif
     1359        }
     1360        else
     1361        {
     1362#if VPS_EXTN_DIRECT_REF_LAYERS
     1363          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
     1364#else
     1365          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
     1366#endif
     1367          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
     1368          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
     1369          {
     1370            continue;
     1371          }
     1372        }
     1373#else
     1374#if VPS_EXTN_DIRECT_REF_LAYERS
     1375        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
     1376#else
     1377        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
     1378#endif
     1379        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
     1380        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
     1381#endif
     1382
     1383#if O0098_SCALED_REF_LAYER_ID
     1384        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     1385#else
     1386        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
     1387#endif
     1388
     1389        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
     1390        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
     1391
     1392        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     1393        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
     1394
     1395        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
     1396        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
     1397
     1398        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
     1399        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
     1400
     1401#if SVC_UPSAMPLING
     1402        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
     1403        {   
     1404/*#if O0098_SCALED_REF_LAYER_ID
     1405          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     1406#else
     1407          Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
     1408#endif*/
     1409#if O0215_PHASE_ALIGNMENT
     1410#if O0194_JOINT_US_BITSHIFT
     1411          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
     1412#else
     1413          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
     1414#endif
     1415#else
     1416#if O0194_JOINT_US_BITSHIFT
     1417          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     1418#else
     1419          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     1420#endif
     1421#endif
     1422        }
     1423        else
     1424        {
     1425          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
     1426        }
     1427        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
     1428#endif
     1429      }
     1430    }
     1431
     1432    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     1433    {
     1434      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1435      {
     1436        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
     1437#if AVC_BASE
     1438        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
    11611439        {
    11621440          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
     
    11941472#endif
    11951473
    1196         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
    1197 
    1198         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
    1199         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
    1200 
    1201         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
    1202         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
    1203 
    1204         g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
    1205         g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
    1206 
    1207         g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
    1208         g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
    1209 
    1210 #if SVC_UPSAMPLING
    1211         if( pcPic->isSpatialEnhLayer(refLayerIdc) )
    1212         {   
    1213 #if O0215_PHASE_ALIGNMENT
    1214 #if O0194_JOINT_US_BITSHIFT
    1215           m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    1216 #else
    1217           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    1218 #endif
    1219 #else
    1220 #if O0194_JOINT_US_BITSHIFT
    1221           m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
    1222 #else
    1223           m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
    1224 #endif
    1225 #endif
    1226         }
    1227         else
    1228         {
    1229           pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
    1230         }
    1231         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
    1232 #endif
    1233       }
    1234     }
    1235 
    1236     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
    1237     {
    1238       for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
    1239       {
    1240         UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
    1241 #if AVC_BASE
    1242         if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
    1243         {
    1244           pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
    1245 #if AVC_SYNTAX
    1246           TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
    1247           if( pcSlice->getPOC() == 0 )
    1248           {
    1249             // initialize partition order.
    1250             UInt* piTmp = &g_auiZscanToRaster[0];
    1251             initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
    1252             initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
    1253           }     
    1254           pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
    1255           pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
    1256 #endif
    1257         }
    1258         else
    1259         {
    1260 #if VPS_EXTN_DIRECT_REF_LAYERS
    1261           TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
    1262 #else
    1263           TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
    1264 #endif
    1265           TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
    1266           pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
    1267         }
    1268 #else
    1269 #if VPS_EXTN_DIRECT_REF_LAYERS
    1270         TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
    1271 #else
    1272         TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
    1273 #endif
    1274         TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
    1275         pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
    1276 #endif
    1277 
    12781474        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
    12791475      }
     
    13151511   
    13161512#if N0147_IRAP_ALIGN_FLAG
    1317     if(  m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
    1318     {
     1513    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
     1514    {
     1515#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     1516      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
     1517#endif
    13191518      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
    13201519      {
     
    13761575  if(pcSlice->getSPS()->getScalingListFlag())
    13771576  {
    1378 #if IL_SL_SIGNALLING_N0371
    1379     pcSlice->getSPS()->getScalingList()->setLayerId( m_layerId );
    1380 #endif
    1381 
    13821577    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
    1383 
    13841578    if(pcSlice->getPPS()->getScalingListPresentFlag())
    13851579    {
    1386 #if IL_SL_SIGNALLING_N0371
    1387       pcSlice->getPPS()->getScalingList()->setLayerId( m_layerId );
    1388 #endif
    1389 
    13901580      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
    13911581    }
     1582#if SCALINGLIST_INFERRING
     1583    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
     1584#endif
    13921585    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
    13931586    {
    1394 #if IL_SL_SIGNALLING_N0371
    1395       pcSlice->setDefaultScalingList( m_layerId );
    1396 #else
    13971587      pcSlice->setDefaultScalingList();
    1398 #endif
    13991588    }
    14001589    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
     
    14031592  else
    14041593  {
    1405 #if IL_SL_SIGNALLING_N0371
    1406     m_cTrQuant.setFlatScalingList( m_layerId );
    1407 #else
    14081594    m_cTrQuant.setFlatScalingList();
    1409 #endif
    14101595    m_cTrQuant.setUseScalingList(false);
    14111596  }
     
    14251610 
    14261611  m_cEntropyDecoder.decodeVPS( vps );
    1427 #if SVC_EXTENSION
    1428   m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
    1429 #else
    14301612  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
    1431 #endif
    14321613}
    14331614
     
    14371618#if SVC_EXTENSION
    14381619  sps->setLayerId(m_layerId);
    1439   m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
    1440   m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
     1620  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
     1621  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
    14411622#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
    14421623  if(m_numLayer>0)
     
    14551636  TComPPS* pps = new TComPPS();
    14561637
    1457 #if IL_SL_SIGNALLING_N0371
    1458   pps->setLayerId(m_layerId);
     1638#if SCALINGLIST_INFERRING
     1639  pps->setLayerId( m_layerId );
    14591640#endif
    14601641
    14611642  m_cEntropyDecoder.decodePPS( pps );
    1462 #if SVC_EXTENSION
    1463   m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
    1464 #else
    14651643  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
    1466 #endif
    14671644
    14681645  if( pps->getDependentSliceSegmentsEnabledFlag() )
     
    14921669#endif
    14931670#if M0043_LAYERS_PRESENT_SEI
    1494     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
    1495 #else
    1496     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
     1671    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
     1672#else
     1673    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
    14971674#endif
    14981675  }
     
    15001677  {
    15011678#if M0043_LAYERS_PRESENT_SEI
    1502     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
    1503 #else
    1504     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
     1679    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
     1680#else
     1681    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
    15051682#endif
    15061683    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     
    15081685    {
    15091686      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
    1510       m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
     1687      m_parameterSetManagerDecoder.applyPrefetchedPS();
    15111688      assert(seiAps->activeSeqParamSetId.size()>0);
    1512       if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
     1689      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParamSetId[0] ) )
    15131690      {
    15141691        printf ("Warning SPS activation with Active parameter set SEI failed");
     
    15651742      xDecodeVPS();
    15661743#if AVC_BASE
    1567       if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
     1744      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
    15681745      {
    15691746        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
     
    15911768      xDecodeSPS();
    15921769#if AVC_BASE
    1593       if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
     1770      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
    15941771      {
    15951772        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
     
    15971774        {
    15981775          // using EL SPS with spsId = 1
    1599           TComSPS* sps = m_parameterSetManagerDecoder[nalu.m_layerId].getPrefetchedSPS(1);
     1776          TComSPS* sps = m_parameterSetManagerDecoder.getPrefetchedSPS(1);
    16001777          Int  numReorderPics[MAX_TLAYER];
    16011778          Window &conformanceWindow = sps->getConformanceWindow();
     
    16441821    case NAL_UNIT_CODED_SLICE_TRAIL_R:
    16451822    case NAL_UNIT_CODED_SLICE_TRAIL_N:
    1646     case NAL_UNIT_CODED_SLICE_TLA_R:
     1823    case NAL_UNIT_CODED_SLICE_TSA_R:
    16471824    case NAL_UNIT_CODED_SLICE_TSA_N:
    16481825    case NAL_UNIT_CODED_SLICE_STSA_R:
     
    16641841#endif
    16651842      break;
     1843     
     1844    case NAL_UNIT_EOS:
     1845      m_associatedIRAPType = NAL_UNIT_INVALID;
     1846      m_pocCRA = 0;
     1847      m_pocRandomAccess = MAX_INT;
     1848      m_prevPOC = MAX_INT;
     1849      m_bFirstSliceInPicture = true;
     1850      m_bFirstSliceInSequence = true;
     1851      m_prevSliceSkipped = false;
     1852      m_skippedPOC = 0;
     1853      return false;
     1854     
     1855    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
     1856      // TODO: process AU delimiter
     1857      return false;
     1858     
     1859    case NAL_UNIT_EOB:
     1860      return false;
     1861     
    16661862    default:
    1667       assert (1);
     1863      assert (0);
    16681864  }
    16691865
     
    17461942TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
    17471943{
    1748   TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
     1944  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
    17491945  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
    17501946  {
     
    18382034}
    18392035#endif
    1840 
     2036#if OUTPUT_LAYER_SET_INDEX
     2037Void TDecTop::checkValueOfOutputLayerSetIdx(TComVPS *vps)
     2038{
     2039  CommonDecoderParams* params = this->getCommonDecoderParams();
     2040  if( params->getValueCheckedFlag() )
     2041  {
     2042    return; // Already checked
     2043  }
     2044  if( params->getOutputLayerSetIdx() == -1 )  // Output layer set index not specified
     2045  {
     2046    Bool layerSetMatchFound = false;
     2047    // Output layer set index not assigned.
     2048    // Based on the value of targetLayerId, check if any of the output layer matches
     2049    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
     2050    // Check if any of the output layer sets match this description
     2051    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
     2052    {
     2053      Bool layerSetMatchFlag = true;
     2054      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
     2055      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
     2056      {
     2057        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
     2058        {
     2059          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
     2060          {
     2061            layerSetMatchFlag = false;
     2062            break;
     2063          }
     2064        }
     2065      }
     2066      else
     2067      {
     2068        layerSetMatchFlag = false;
     2069      }
     2070     
     2071      if( layerSetMatchFlag ) // Potential output layer set candidate found
     2072      {
     2073        // If target dec layer ID list is also included - check if they match
     2074        if( params->getTargetDecLayerIdSet() )
     2075        {
     2076          if( params->getTargetDecLayerIdSet()->size() ) 
     2077          {
     2078            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
     2079            {
     2080              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
     2081              {
     2082                layerSetMatchFlag = false;
     2083              }
     2084            }
     2085          }
     2086        }
     2087        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
     2088        {
     2089          // Match found
     2090          layerSetMatchFound = true;
     2091          params->setOutputLayerSetIdx( i );
     2092          params->setValueCheckedFlag( true );
     2093          break;
     2094        }
     2095      }
     2096    }
     2097    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
     2098  }   
     2099  else // Output layer set index is assigned - check if the values match
     2100  {
     2101    // Check if the target decoded layer is the highest layer in the list
     2102    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getOutputLayerSetIdx() );  // Index to the layer set
     2103    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
     2104
     2105    Bool layerSetMatchFlag = true;
     2106    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
     2107    {
     2108      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
     2109      {
     2110        layerSetMatchFlag = false;
     2111        break;
     2112      }
     2113    }
     2114
     2115    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
     2116   
     2117    // Check if the targetdeclayerIdlist matches the output layer set
     2118    if( params->getTargetDecLayerIdSet() )
     2119    {
     2120      if( params->getTargetDecLayerIdSet()->size() ) 
     2121      {
     2122        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
     2123        {
     2124          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
     2125        }
     2126      }
     2127    }
     2128    params->setValueCheckedFlag( true );
     2129
     2130  }
     2131}
     2132#endif
    18412133//! \}
  • trunk/source/Lib/TLibDecoder/TDecTop.h

    r494 r540  
    7272
    7373  TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
    74 #if SVC_EXTENSION
    75   ParameterSetManagerDecoder m_parameterSetManagerDecoder[MAX_LAYERS];  // storage for parameter sets
    76 #else
    7774  ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets
    78 #endif
    79 
    8075  TComSlice*              m_apcSlicePilot;
    8176
     
    134129  TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture
    135130#endif
     131#if OUTPUT_LAYER_SET_INDEX
     132  CommonDecoderParams*    m_commonDecoderParams;
     133#endif
    136134#if AVC_SYNTAX || SYNTAX_OUTPUT
    137135  fstream*               m_pBLSyntaxFile;
     136#endif
     137
     138#if NO_CLRAS_OUTPUT_FLAG
     139  Bool                    m_noClrasOutputFlag;
     140  Bool                    m_layerInitializedFlag;
     141  Bool                    m_firstPicInLayerDecodedFlag;
     142  Bool                    m_noOutputOfPriorPicsFlags;
     143
     144  Bool                   m_bRefreshPending;
    138145#endif
    139146
     
    241248#endif
    242249
     250#if NO_CLRAS_OUTPUT_FLAG
     251  Int  getNoClrasOutputFlag()                { return m_noClrasOutputFlag;}
     252  Void setNoClrasOutputFlag(Bool x)          { m_noClrasOutputFlag = x;   }
     253  Int  getLayerInitializedFlag()             { return m_layerInitializedFlag;}
     254  Void setLayerInitializedFlag(Bool x)       { m_layerInitializedFlag = x;   }
     255  Int  getFirstPicInLayerDecodedFlag()       { return m_firstPicInLayerDecodedFlag;}
     256  Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x;   }
     257  Int  getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
     258  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
     259#endif
     260public:
     261#if OUTPUT_LAYER_SET_INDEX
     262  CommonDecoderParams*    getCommonDecoderParams() { return m_commonDecoderParams; }
     263  Void                    setCommonDecoderParams(CommonDecoderParams* x) { m_commonDecoderParams = x; }
     264  Void      checkValueOfOutputLayerSetIdx(TComVPS *vps);
     265#endif
     266#if SCALINGLIST_INFERRING
     267  ParameterSetManagerDecoder* getParameterSetManager() { return &m_parameterSetManagerDecoder; }
     268#endif
    243269};// END CLASS DEFINITION TDecTop
    244270
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r442 r540  
    5858
    5959TEncAnalyze             m_gcAnalyzeAll_in;
     60
    6061//! \}
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.h

    r442 r540  
    160160  }
    161161 
     162 
    162163  Void    printSummary(Char ch)
    163164  {
     
    207208
    208209extern TEncAnalyze             m_gcAnalyzeAll_in;
     210
    209211//! \}
    210212
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r494 r540  
    220220    }
    221221  }
     222
     223#if SCALINGLIST_INFERRING
     224  if( pcPPS->getLayerId() > 0 )
     225  {
     226    WRITE_FLAG( pcPPS->getInferScalingListFlag() ? 1 : 0, "pps_infer_scaling_list_flag" );
     227  }
     228
     229  if( pcPPS->getInferScalingListFlag() )
     230  {
     231    // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     232    assert( pcPPS->getScalingListRefLayerId() <= 62 );
     233
     234    WRITE_UVLC( pcPPS->getScalingListRefLayerId(), "pps_scaling_list_ref_layer_id" );
     235  }
     236  else
     237  {
     238#endif
     239
    222240  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
    223 
    224 #if IL_SL_SIGNALLING_N0371
    225   pcPPS->setPPS( pcPPS->getLayerId(), pcPPS ); 
    226 #endif
    227 
    228241  if( pcPPS->getScalingListPresentFlag() )
    229242  {
    230 #if SCALING_LIST_OUTPUT_RESULT
    231     printf("PPS\n");
    232 #endif
    233 
    234 #if IL_SL_SIGNALLING_N0371
    235     m_pcSlice->getScalingList()->setLayerId( pcPPS->getLayerId() );
    236 
    237     if( pcPPS->getLayerId() > 0 )
    238     {
    239       WRITE_FLAG( pcPPS->getPredScalingListFlag() ? 1 : 0,                          "pps_pred_scaling_list_flag" );
    240       m_pcSlice->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
    241 
    242       if( pcPPS->getPredScalingListFlag() )
    243       {
    244         // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    245         assert( /*pcPPS->getScalingListRefLayerId() >= 0 &&*/ pcPPS->getScalingListRefLayerId() <= 62 );
    246 
    247         // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of pps_scaling_list_ref_layer_id shall be greater than 0
    248         if( pcPPS->getSPS()->getVPS()->getAvcBaseLayerFlag() )
    249         {
    250           assert( pcPPS->getScalingListRefLayerId() > 0 );
    251         }
    252 
    253         // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
    254         // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
    255         assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
    256 
    257         // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
    258         // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
    259         assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
    260        
    261         WRITE_UVLC( pcPPS->getScalingListRefLayerId(),                            "scaling_list_pps_ref_layer_id" );
    262         m_pcSlice->getScalingList()->setScalingListRefLayerId( pcPPS->getScalingListRefLayerId() );
    263         codeScalingList( m_pcSlice->getScalingList() );
    264       }
    265       else
    266       {
    267         codeScalingList( m_pcSlice->getScalingList() );
    268       }
    269     }
    270     else
    271     {
    272       codeScalingList( m_pcSlice->getScalingList() );
    273     }
    274 #else
    275243    codeScalingList( m_pcSlice->getScalingList() );
    276 #endif
    277 
    278   }
     244  }
     245
     246#if SCALINGLIST_INFERRING
     247  }
     248#endif
     249
    279250  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
    280251  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
     
    471442    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" );
    472443  }
     444#if O0096_REP_FORMAT_INDEX
     445  if( pcSPS->getLayerId() == 0 )
     446#else
    473447  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     448#endif
    474449  {
    475450#endif
     
    486461#if REPN_FORMAT_IN_VPS
    487462  }
     463#if O0096_REP_FORMAT_INDEX
     464  else if (pcSPS->getUpdateRepFormatFlag())
     465  {
     466    WRITE_CODE( pcSPS->getUpdateRepFormatIndex(), 8,   "update_rep_format_index");
     467  }
     468#endif
    488469#endif
    489470  Window conf = pcSPS->getConformanceWindow();
     
    499480
    500481#if REPN_FORMAT_IN_VPS
     482#if O0096_REP_FORMAT_INDEX
     483  if( pcSPS->getLayerId() == 0 )
     484#else
    501485  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     486#endif 
    502487  {
    503488    assert( pcSPS->getBitDepthY() >= 8 );
     
    532517  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
    533518  WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" );
    534 
    535 #if IL_SL_SIGNALLING_N0371
    536   pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
    537 #endif
    538 
    539519  if(pcSPS->getScalingListFlag())
    540520  {
     521#if SCALINGLIST_INFERRING
     522    if( pcSPS->getLayerId() > 0 )
     523    {
     524      WRITE_FLAG( pcSPS->getInferScalingListFlag() ? 1 : 0, "sps_infer_scaling_list_flag" );
     525    }
     526
     527    if( pcSPS->getInferScalingListFlag() )
     528    {
     529      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     530      assert( pcSPS->getScalingListRefLayerId() <= 62 );
     531
     532      WRITE_UVLC( pcSPS->getScalingListRefLayerId(), "sps_scaling_list_ref_layer_id" );
     533    }
     534    else
     535    {
     536#endif
    541537    WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" );
    542538    if(pcSPS->getScalingListPresentFlag())
    543539    {
    544 #if SCALING_LIST_OUTPUT_RESULT
    545     printf("SPS\n");
    546 #endif
    547 
    548 #if IL_SL_SIGNALLING_N0371
    549     m_pcSlice->getScalingList()->setLayerId( pcSPS->getLayerId() );
    550 
    551     if( pcSPS->getLayerId() > 0 )
    552     {
    553       WRITE_FLAG( pcSPS->getPredScalingListFlag() ? 1 : 0,                          "sps_pred_scaling_list_flag" );
    554       m_pcSlice->getScalingList()->setPredScalingListFlag( pcSPS->getPredScalingListFlag() );
    555 
    556       if( pcSPS->getPredScalingListFlag() )
    557       {
    558 
    559         // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    560         assert( /*pcSPS->getScalingListRefLayerId() >= 0 &&*/ pcSPS->getScalingListRefLayerId() <= 62 );
    561        
    562         // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
    563         if( pcSPS->getVPS()->getAvcBaseLayerFlag() )
    564         {
    565           assert( pcSPS->getScalingListRefLayerId() > 0 );
    566         }
    567 
    568         // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
    569         // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
    570         assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
    571 
    572         // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
    573         // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
    574         assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
    575 
    576         WRITE_UVLC( pcSPS->getScalingListRefLayerId(),                            "scaling_list_sps_ref_layer_id" );
    577         m_pcSlice->getScalingList()->setScalingListRefLayerId( pcSPS->getScalingListRefLayerId() );
    578         codeScalingList( m_pcSlice->getScalingList() );
    579       }
    580       else
    581       {
    582         codeScalingList( m_pcSlice->getScalingList() );
    583       }
    584     }
    585     else
    586     {
    587540      codeScalingList( m_pcSlice->getScalingList() );
    588541    }
    589 #else
    590       codeScalingList( m_pcSlice->getScalingList() );
    591 #endif
    592 
    593     }
     542#if SCALINGLIST_INFERRING
     543    }
     544#endif
    594545  }
    595546  WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0,                                            "amp_enabled_flag" );
     
    648599  if( 1 )   // if( sps_extension_flag )
    649600  {
     601#if O0142_CONDITIONAL_SPS_EXTENSION
     602    UInt spsExtensionTypeFlag[8] = { 0, 1, 0, 0, 0, 0, 0, 0 };
     603    for (UInt i = 0; i < 8; i++)
     604    {
     605      WRITE_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" );
     606    }
     607    if (spsExtensionTypeFlag[1])
     608    {
     609      codeSPSExtension( pcSPS );
     610    }
     611#else
    650612    codeSPSExtension( pcSPS );
    651613    WRITE_FLAG( 0, "sps_extension2_flag" );
     614#endif
    652615  }
    653616#else
     
    670633    {
    671634      Window scaledWindow = pcSPS->getScaledRefLayerWindow(i);
     635#if O0098_SCALED_REF_LAYER_ID
     636      WRITE_CODE( pcSPS->getScaledRefLayerId(i), 6,          "scaled_ref_layer_id" );
     637#endif
    672638      WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
    673639      WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     
    891857    }
    892858  }
     859#endif
     860#if VPS_TSLAYERS
     861    WRITE_FLAG( vps->getMaxTSLayersPresentFlag(), "vps_sub_layers_max_minus1_present_flag");
     862    if (vps->getMaxTSLayersPresentFlag())
     863    {
     864        for( i = 0; i < vps->getMaxLayers() - 1; i++)
     865        {
     866            WRITE_CODE(vps->getMaxTSLayersMinus1(i), 3, "sub_layers_vps_max_minus1[i]" );
     867        }
     868    }
    893869#endif
    894870#if JCTVC_M0203_INTERLAYER_PRED_IDC
     
    982958  }
    983959
     960#if O0153_ALT_OUTPUT_LAYER_FLAG
     961  if( vps->getMaxLayers() > 1 )
     962  {
     963    WRITE_FLAG( vps->getAltOuputLayerFlag(), "alt_output_layer_flag" );   
     964  }
     965#endif
     966
    984967#if REPN_FORMAT_IN_VPS
    985968  WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag");
     
    987970  if( vps->getRepFormatIdxPresentFlag() )
    988971  {
     972#if O0096_REP_FORMAT_INDEX
     973    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 8, "vps_num_rep_formats_minus1" );
     974#else
    989975    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 4, "vps_num_rep_formats_minus1" );
     976#endif
    990977  }
    991978  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
     
    1001988      if( vps->getVpsNumRepFormats() > 1 )
    1002989      {
     990#if O0096_REP_FORMAT_INDEX
     991        WRITE_CODE( vps->getVpsRepFormatIdx(i), 8, "vps_rep_format_idx[i]" );
     992#else
    1003993        WRITE_CODE( vps->getVpsRepFormatIdx(i), 4, "vps_rep_format_idx[i]" );
     994#endif
    1004995      }
    1005996    }
     
    10251016  WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
    10261017#endif
     1018#if VPS_DPB_SIZE_TABLE
     1019  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
     1020  {
     1021    WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]"); 
     1022    for(j = 0; j < vps->getMaxTLayers(); j++)
     1023    {
     1024      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
     1025      {
     1026        WRITE_FLAG( vps->getSubLayerDpbInfoPresentFlag( i, j), "sub_layer_dpb_info_present_flag[i]"); 
     1027      }
     1028      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )
     1029      {
     1030        for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
     1031        {
     1032          WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" );
     1033        }
     1034        WRITE_UVLC( vps->getMaxVpsNumReorderPics( i, j), "max_vps_num_reorder_pics[i][j]" );             
     1035        WRITE_UVLC( vps->getMaxVpsLatencyIncreasePlus1( i, j), "max_vps_latency_increase_plus1[i][j]" );       
     1036      }
     1037    }
     1038  }
     1039#endif
    10271040#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
    10281041  WRITE_UVLC( vps->getDirectDepTypeLen()-2,                           "direct_dep_type_len_minus2");
     1042#if O0096_DEFAULT_DEPENDENCY_TYPE
     1043  WRITE_FLAG(vps->getDefaultDirectDependencyTypeFlag(), "default_direct_dependency_flag");
     1044  if (vps->getDefaultDirectDependencyTypeFlag())
     1045  {
     1046    WRITE_CODE( vps->getDefaultDirectDependencyType(), vps->getDirectDepTypeLen(), "default_direct_dependency_type" );
     1047  }
     1048  else
     1049  {
     1050    for(i = 1; i < vps->getMaxLayers(); i++)
     1051    {
     1052      for(j = 0; j < i; j++)
     1053      {
     1054        if (vps->getDirectDependencyFlag(i, j))
     1055        {
     1056          WRITE_CODE( vps->getDirectDependencyType(i, j), vps->getDirectDepTypeLen(), "direct_dependency_type[i][j]" );
     1057        }
     1058      }
     1059    }
     1060  }
     1061#else
    10291062  for(i = 1; i < vps->getMaxLayers(); i++)
    10301063  {
     
    10371070    }
    10381071  }
    1039 
    1040 #if IL_SL_SIGNALLING_N0371
    1041   for(i = 1; i < vps->getMaxLayers(); i++)
    1042   {
    1043     for(j = 0; j < i; j++)
    1044     {
    1045       vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
    1046     }
    1047   }
    1048 #endif
    1049 
     1072#endif
    10501073#endif
    10511074#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    10521075  WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
    10531076#endif
     1077#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1078  WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
     1079#endif
    10541080
    10551081#if !VPS_VUI
     
    10711097Void  TEncCavlc::codeRepFormat      ( RepFormat *repFormat )
    10721098{
     1099#if REPN_FORMAT_CONTROL_FLAG
     1100   WRITE_FLAG ( repFormat->getChromaAndBitDepthVpsPresentFlag(), "chroma_and_bit_depth_vps_presenet_flag");
     1101
     1102   WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" );   
     1103   WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" ); 
     1104
     1105   if ( repFormat->getChromaAndBitDepthVpsPresentFlag() )
     1106   {
     1107     WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );   
     1108
     1109     if( repFormat->getChromaFormatVpsIdc() == 3 )
     1110     {
     1111       WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag");     
     1112     }
     1113
     1114     assert( repFormat->getBitDepthVpsLuma() >= 8 );
     1115     assert( repFormat->getBitDepthVpsChroma() >= 8 );
     1116     WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
     1117     WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
     1118   }
     1119#else
    10731120  WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );   
    10741121 
     
    10841131  assert( repFormat->getBitDepthVpsChroma() >= 8 );
    10851132  WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
    1086   WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );         
     1133  WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
     1134#endif
    10871135
    10881136}
     
    10921140{
    10931141  Int i,j;
     1142#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1143  WRITE_FLAG(vps->getCrossLayerPictureTypeAlignFlag(), "cross_layer_pic_type_aligned_flag");
     1144  if (!vps->getCrossLayerPictureTypeAlignFlag())
     1145  {
     1146#endif
    10941147#if IRAP_ALIGN_FLAG_IN_VPS_VUI
    1095       WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
     1148    WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
    10961149#endif
     1150#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1151  }
     1152#endif
    10971153#if VPS_VUI_BITRATE_PICRATE
    10981154  WRITE_FLAG( vps->getBitRatePresentVpsFlag(),        "bit_rate_present_vps_flag" );
     
    11271183  }
    11281184#endif
     1185#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1186  UInt layerIdx;
     1187  WRITE_FLAG( vps->getTilesNotInUseFlag() ? 1 : 0 , "tiles_not_in_use_flag" );
     1188  if (!vps->getTilesNotInUseFlag())
     1189  {
     1190    for(i = 0; i < vps->getMaxLayers(); i++)
     1191    {
     1192      WRITE_FLAG( vps->getTilesInUseFlag(i) ? 1 : 0 , "tiles_in_use_flag[ i ]" );
     1193      if (vps->getTilesInUseFlag(i))
     1194      {
     1195        WRITE_FLAG( vps->getLoopFilterNotAcrossTilesFlag(i) ? 1 : 0 , "loop_filter_not_across_tiles_flag[ i ]" );
     1196      }
     1197    }
     1198#endif
    11291199#if TILE_BOUNDARY_ALIGNED_FLAG
    1130   for(i = 1; i < vps->getMaxLayers(); i++)
    1131   {
    1132     for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
    1133     {
    1134       WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
    1135     }
    1136   } 
    1137 #endif
     1200    for(i = 1; i < vps->getMaxLayers(); i++)
     1201    {
     1202      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     1203      {
     1204#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1205        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
     1206        if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
     1207          WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
     1208        }
     1209#else
     1210        WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
     1211#endif
     1212      }
     1213    } 
     1214#endif
     1215#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1216  }
     1217#endif
     1218#if VPS_VUI_WPP_NOT_IN_USE__FLAG
     1219  WRITE_FLAG( vps->getWppNotInUseFlag() ? 1 : 0 , "wpp_not_in_use_flag" );
     1220  if (!vps->getWppNotInUseFlag())
     1221  {
     1222    for(i = 0; i < vps->getMaxLayers(); i++)
     1223    {
     1224      WRITE_FLAG( vps->getWppInUseFlag(i) ? 1 : 0 , "wpp_in_use_flag[ i ]" );
     1225    }
     1226  }
     1227#endif
    11381228#if N0160_VUI_EXT_ILP_REF
    11391229  WRITE_FLAG( vps->getNumIlpRestrictedRefLayers() ? 1 : 0 , "num_ilp_restricted_ref_layers" );   
     
    11591249  }
    11601250#endif
     1251#if VPS_VUI_VIDEO_SIGNAL
     1252    WRITE_FLAG( vps->getVideoSigPresentVpsFlag(), "video_signal_info_idx_present_flag" );
     1253    if (vps->getVideoSigPresentVpsFlag())
     1254    {
     1255        WRITE_CODE(vps->getNumVideoSignalInfo()-1, 4, "vps_num_video_signal_info_minus1" );
     1256    }
     1257   
     1258    for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
     1259    {
     1260        WRITE_CODE(vps->getVideoVPSFormat(i), 3, "video_vps_format" );
     1261        WRITE_FLAG(vps->getVideoFullRangeVpsFlag(i), "video_full_range_vps_flag" );
     1262        WRITE_CODE(vps->getColorPrimaries(i), 8, "color_primaries_vps" );
     1263        WRITE_CODE(vps->getTransCharacter(i), 8, "transfer_characteristics_vps" );
     1264        WRITE_CODE(vps->getMaxtrixCoeff(i), 8, "matrix_coeffs_vps" );
     1265    }
     1266   
     1267    if (vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 )
     1268    {
     1269        for (i=1; i < vps->getMaxLayers(); i++)
     1270            WRITE_CODE(vps->getVideoSignalInfoIdx(i), 4, "vps_video_signal_info_idx" );
     1271    }
     1272#endif
    11611273}
    11621274#endif
     
    12211333      iBits++;
    12221334    }
     1335#if O0149_CROSS_LAYER_BLA_FLAG
     1336    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
     1337    {
     1338      assert(!!"cross_layer_bla_flag");
     1339      WRITE_FLAG(pcSlice->getCrossLayerBLAFlag(), "cross_layer_bla_flag");
     1340      iBits++;
     1341    }
     1342#endif
    12231343    for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
    12241344    {
     
    12991419      TComReferencePictureSet* rps = pcSlice->getRPS();
    13001420     
    1301 #if FIX1071
    13021421      // check for bitstream restriction stating that:
    13031422      // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     
    13131432        }
    13141433      }
    1315 #endif
    13161434
    13171435      if(pcSlice->getRPSidx() < 0)
     
    14671585      if (pcSlice->getSPS()->getUseSAO())
    14681586      {
    1469          WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
     1587         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );         
     1588#if AUXILIARY_PICTURES
     1589         if (pcSlice->getChromaFormatIdc() != CHROMA_400)
    14701590         {
     1591#endif
     1592#if HM_CLEANUP_SAO
     1593         WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" );
     1594#else
     1595         {
     1596           SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
     1597           WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
     1598         }
     1599#endif
    14711600#if AUXILIARY_PICTURES
    1472            if (pcSlice->getChromaFormatIdc() != CHROMA_400)
    1473            {
    1474 #endif
    1475            SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1476           WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
    1477 #if AUXILIARY_PICTURES
    1478            }
    1479 #endif
    14801601         }
    1481       }
    1482     }
     1602#endif
     1603      }
     1604    }   
    14831605
    14841606    //check if numrefidxes match the defaults. If not, override
     
    20262148  Bool scalingListPredModeFlag;
    20272149
    2028 #if SCALING_LIST_OUTPUT_RESULT
    2029   Int startBit;
    2030   Int startTotalBit;
    2031   startBit = m_pcBitIf->getNumberOfWrittenBits();
    2032   startTotalBit = m_pcBitIf->getNumberOfWrittenBits();
    2033 #endif
    2034 
    20352150    //for each size
    20362151    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    20382153      for(listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    20392154      {
    2040 #if SCALING_LIST_OUTPUT_RESULT
    2041         startBit = m_pcBitIf->getNumberOfWrittenBits();
    2042 #endif
    2043 
    2044 #if IL_SL_SIGNALLING_N0371
    2045         if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2046         {
    2047           scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    2048           WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
    2049           if(!scalingListPredModeFlag)// Copy Mode
    2050           {
    2051             WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
    2052           }
    2053           else// DPCM Mode
    2054           {
    2055             xCodeScalingList(scalingList, sizeId, listId);
    2056           }
    2057         }
    2058         else
    2059         {
    2060           scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    2061           WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
    2062           if(!scalingListPredModeFlag)// Copy Mode
    2063           {
    2064             WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
    2065           }
    2066           else// DPCM Mode
    2067           {
    2068             xCodeScalingList(scalingList, sizeId, listId);
    2069           }
    2070         }
    2071 #else
    20722155        scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    20732156        WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     
    20802163          xCodeScalingList(scalingList, sizeId, listId);
    20812164        }
    2082 #endif
    2083 
    2084 #if SCALING_LIST_OUTPUT_RESULT
    2085         printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit);
    2086 #endif
    2087 
    2088       }
    2089     }
    2090 #if SCALING_LIST_OUTPUT_RESULT
    2091   printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
    2092 #endif
     2165      }
     2166    }
    20932167  return;
    20942168}
     
    21052179  Int data;
    21062180  Int *src = scalingList->getScalingListAddress(sizeId, listId);
    2107 
    2108     if( sizeId > SCALING_LIST_8x8 )
    2109     {
    2110 #if IL_SL_SIGNALLING_N0371
    2111       if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2112       {
    2113         ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
    2114         scalingList->setScalingListDC(sizeId,listId,ref_scalingListDC[scalingList->getScalingListRefLayerId()][sizeId][listId]);
    2115       }
    2116       else
    2117       {
    2118         WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
    2119         nextCoef = scalingList->getScalingListDC(sizeId,listId);
    2120         ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
    2121       }
    2122 #else
    2123       WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
    2124       nextCoef = scalingList->getScalingListDC(sizeId,listId);
    2125 #endif
    2126     }
    2127     for(Int i=0;i<coefNum;i++)
    2128     {
    2129 #if IL_SL_SIGNALLING_N0371
    2130       if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2131       {
    2132         ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
    2133         src[scan[i]] = ref_scalingListCoef[scalingList->getScalingListRefLayerId()][sizeId][listId][i];
    2134       }
    2135       else
    2136       {
    2137         data = src[scan[i]] - nextCoef;
    2138         ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
    2139         nextCoef = src[scan[i]];
    2140         if(data > 127)
    2141         {
    2142           data = data - 256;
    2143         }
    2144         if(data < -128)
    2145         {
    2146           data = data + 256;
    2147         }
    2148 
    2149         WRITE_SVLC( data,  "scaling_list_delta_coef");
    2150       }
    2151 #else
    2152       data = src[scan[i]] - nextCoef;
    2153       nextCoef = src[scan[i]];
    2154       if(data > 127)
    2155       {
    2156         data = data - 256;
    2157       }
    2158       if(data < -128)
    2159       {
    2160         data = data + 256;
    2161       }
    2162 
    2163       WRITE_SVLC( data,  "scaling_list_delta_coef");
    2164 #endif
    2165     }
     2181  if( sizeId > SCALING_LIST_8x8 )
     2182  {
     2183    WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
     2184    nextCoef = scalingList->getScalingListDC(sizeId,listId);
     2185  }
     2186  for(Int i=0;i<coefNum;i++)
     2187  {
     2188    data = src[scan[i]] - nextCoef;
     2189    nextCoef = src[scan[i]];
     2190    if(data > 127)
     2191    {
     2192      data = data - 256;
     2193    }
     2194    if(data < -128)
     2195    {
     2196      data = data + 256;
     2197    }
     2198
     2199    WRITE_SVLC( data,  "scaling_list_delta_coef");
     2200  }
    21662201}
    21672202Bool TEncCavlc::findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag )
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r442 r540  
    109109 
    110110  Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
     111#if HM_CLEANUP_SAO
     112  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);}
     113#else
    111114  Void codeSAOSign       ( UInt code   ) { printf("Not supported\n"); assert (0); }
    112115  Void codeSaoMaxUvlc    ( UInt   code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}
     
    114117  Void codeSaoTypeIdx    ( UInt uiCode ){printf("Not supported\n"); assert (0);}
    115118  Void codeSaoUflc       ( UInt uiLength, UInt   uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}
    116 
     119#endif
    117120  Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx );
    118121  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r494 r540  
    196196  Int       m_maxNumOffsetsPerPic;
    197197  Bool      m_saoLcuBoundary;
     198#if !HM_CLEANUP_SAO
    198199  Bool      m_saoLcuBasedOptimization;
    199 
     200#endif
    200201  //====== Lossless ========
    201202  Bool      m_useLossless;
     
    328329  Int       m_TMVPModeId;
    329330  Int       m_signHideFlag;
    330 #if RATE_CONTROL_LAMBDA_DOMAIN
    331331  Bool      m_RCEnableRateControl;
    332332  Int       m_RCTargetBitrate;
    333 #if M0036_RC_IMPROVEMENT
    334333  Int       m_RCKeepHierarchicalBit;
    335 #else
    336   Bool      m_RCKeepHierarchicalBit;
    337 #endif
    338334  Bool      m_RCLCULevelRC;
    339335  Bool      m_RCUseLCUSeparateModel;
    340336  Int       m_RCInitialQP;
    341337  Bool      m_RCForceIntraQP;
    342 #else
    343   Bool      m_enableRateCtrl;                                ///< Flag for using rate control algorithm
    344   Int       m_targetBitrate;                                 ///< target bitrate
    345   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit
    346 #endif
    347338  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
    348339  Bool      m_CUTransquantBypassFlagValue;                    ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.
     
    393384  Int       m_adaptiveResolutionChange;
    394385#endif
     386#if O0153_ALT_OUTPUT_LAYER_FLAG
     387  Bool      m_altOutputLayerFlag;
     388#endif
     389#if HIGHER_LAYER_IRAP_SKIP_FLAG
     390  Int       m_skipPictureAtArcSwitch;
     391#endif
     392#if O0149_CROSS_LAYER_BLA_FLAG
     393  Bool      m_crossLayerBLAFlag;
     394#endif
    395395#endif
    396396
     
    629629  Void  setSaoLcuBoundary              (Bool val)      { m_saoLcuBoundary = val; }
    630630  Bool  getSaoLcuBoundary              ()              { return m_saoLcuBoundary; }
     631#if !HM_CLEANUP_SAO
    631632  Void  setSaoLcuBasedOptimization               (Bool val)            { m_saoLcuBasedOptimization = val; }
    632633  Bool  getSaoLcuBasedOptimization               ()                    { return m_saoLcuBasedOptimization; }
     634#endif
    633635  Void  setLFCrossTileBoundaryFlag               ( Bool   val  )       { m_loopFilterAcrossTilesEnabledFlag = val; }
    634636  Bool  getLFCrossTileBoundaryFlag               ()                    { return m_loopFilterAcrossTilesEnabledFlag;   }
     
    806808  Void      setSignHideFlag( Int signHideFlag ) { m_signHideFlag = signHideFlag; }
    807809  Int       getSignHideFlag()                    { return m_signHideFlag; }
    808 #if RATE_CONTROL_LAMBDA_DOMAIN
    809810  Bool      getUseRateCtrl         ()              { return m_RCEnableRateControl;   }
    810811  Void      setUseRateCtrl         ( Bool b )      { m_RCEnableRateControl = b;      }
    811812  Int       getTargetBitrate       ()              { return m_RCTargetBitrate;       }
    812813  Void      setTargetBitrate       ( Int bitrate ) { m_RCTargetBitrate  = bitrate;   }
    813 #if M0036_RC_IMPROVEMENT
    814814  Int       getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    815815  Void      setKeepHierBit         ( Int i )       { m_RCKeepHierarchicalBit = i;    }
    816 #else
    817   Bool      getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    818   Void      setKeepHierBit         ( Bool b )      { m_RCKeepHierarchicalBit = b;    }
    819 #endif
    820816  Bool      getLCULevelRC          ()              { return m_RCLCULevelRC; }
    821817  Void      setLCULevelRC          ( Bool b )      { m_RCLCULevelRC = b; }
     
    826822  Bool      getForceIntraQP        ()              { return m_RCForceIntraQP;        }
    827823  Void      setForceIntraQP        ( Bool b )      { m_RCForceIntraQP = b;           }
    828 #else
    829   Bool      getUseRateCtrl    ()                { return m_enableRateCtrl;    }
    830   Void      setUseRateCtrl    (Bool flag)       { m_enableRateCtrl = flag;    }
    831   Int       getTargetBitrate  ()                { return m_targetBitrate;     }
    832   Void      setTargetBitrate  (Int target)      { m_targetBitrate  = target;  }
    833   Int       getNumLCUInUnit   ()                { return m_numLCUInUnit;      }
    834   Void      setNumLCUInUnit   (Int numLCUs)     { m_numLCUInUnit   = numLCUs; }
    835 #endif
    836824  Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
    837825  Void      setTransquantBypassEnableFlag(Bool flag)  { m_TransquantBypassEnableFlag = flag; }
     
    934922  Int       getAdaptiveResolutionChange()      { return m_adaptiveResolutionChange; }
    935923#endif
     924#if HIGHER_LAYER_IRAP_SKIP_FLAG
     925  Void      setSkipPictureAtArcSwitch(Int x) { m_skipPictureAtArcSwitch = x;    }
     926  Int       getSkipPictureAtArcSwitch()      { return m_skipPictureAtArcSwitch; }
     927#endif
    936928#if AUXILIARY_PICTURES
    937929  Void         setChromaFormatIDC(ChromaFormat x) { m_chromaFormatIDC = x;    }
    938930  ChromaFormat getChromaFormatIDC()               { return m_chromaFormatIDC; }
    939931#endif
     932#if O0153_ALT_OUTPUT_LAYER_FLAG
     933  Bool      getAltOuputLayerFlag() const { return m_altOutputLayerFlag; }
     934  Void      setAltOuputLayerFlag(Bool b) { m_altOutputLayerFlag = b;    }
     935#endif
     936#if O0149_CROSS_LAYER_BLA_FLAG
     937  Bool      getCrossLayerBLAFlag() const { return m_crossLayerBLAFlag; }
     938  Void      setCrossLayerBLAFlag(Bool b) { m_crossLayerBLAFlag = b;    }
     939#endif
    940940#endif
    941941};
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r494 r540  
    9595 
    9696  m_bEncodeDQP = false;
    97 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    98   m_LCUPredictionSAD = 0;
    99   m_addSADDepth      = 0;
    100   m_temporalSAD      = 0;
    101 #endif
    10297
    10398  // initialize partition order.
     
    243238  m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    244239  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    245 
    246 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    247   m_addSADDepth      = 0;
    248   m_LCUPredictionSAD = 0;
    249   m_temporalSAD      = 0;
    250 #endif
    251240
    252241#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     
    433422  }
    434423
    435 #if RATE_CONTROL_LAMBDA_DOMAIN
    436424  if ( m_pcEncCfg->getUseRateCtrl() )
    437425  {
     
    439427    iMaxQP = m_pcRateCtrl->getRCQP();
    440428  }
    441 #else
    442   if(m_pcEncCfg->getUseRateCtrl())
    443   {
    444     Int qp = m_pcRateCtrl->getUnitQP();
    445     iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    446     iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    447   }
    448 #endif
    449429
    450430  // If slice start or slice end is within this cu...
     
    460440  if(!bSliceEnd && !bSliceStart && bInsidePicture )
    461441  {
     442#if HIGHER_LAYER_IRAP_SKIP_FLAG
     443    if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange())
     444    {
     445      rpcTempCU->initEstData( uiDepth, iBaseQP );
     446     
     447      xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true );
     448    }
     449    else
     450    {
     451#endif
    462452#if (ENCODER_FAST_MODE)
    463453    Bool testInter = true;
     
    528518      }
    529519    }
    530 
    531 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    532     if ( uiDepth <= m_addSADDepth )
    533     {
    534       m_LCUPredictionSAD += m_temporalSAD;
    535       m_addSADDepth = uiDepth;
    536     }
    537 #endif
    538520
    539521    if(!earlyDetectionSkipMode)
     
    779761      bSubBranch = true;
    780762    }
     763#if HIGHER_LAYER_IRAP_SKIP_FLAG
     764    }
     765#endif
    781766  }
    782767  else if(!(bSliceEnd && bInsidePicture))
    783768  {
    784769    bBoundary = true;
    785 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    786     m_addSADDepth++;
    787 #endif
    788770  }
    789771
     
    829811    iMaxQP = iStartQP;
    830812  }
    831 #if RATE_CONTROL_LAMBDA_DOMAIN
    832813  if ( m_pcEncCfg->getUseRateCtrl() )
    833814  {
     
    835816    iMaxQP = m_pcRateCtrl->getRCQP();
    836817  }
    837 #else
    838   if(m_pcEncCfg->getUseRateCtrl())
    839   {
    840     Int qp = m_pcRateCtrl->getUnitQP();
    841     iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    842     iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    843   }
    844 #endif
    845818  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    846819  {
     
    11431116 
    11441117  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
     1118#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1119  if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange())
     1120  {
     1121    pcCU->setSkipFlagSubParts(true, uiAbsPartIdx, uiDepth);
     1122  }
     1123#endif
    11451124  // If slice start is within this cu...
    11461125  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&
     
    12311210}
    12321211
    1233 #if RATE_CONTROL_INTRA
    12341212Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
    12351213{
     
    13461324  return(iSumHad);
    13471325}
    1348 #endif
    13491326
    13501327/** check RD costs for a CU block encoded with merge
     
    13531330 * \returns Void
    13541331 */
     1332#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1333Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode, Bool bUseSkip )
     1334#else
    13551335Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode )
     1336#endif
    13561337{
    13571338  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
     
    13871368  }
    13881369
     1370#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1371  for( UInt uiNoResidual = bUseSkip?1:0; uiNoResidual < iteration; ++uiNoResidual )
     1372#else
    13891373  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
     1374#endif
    13901375  {
    13911376    for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
     
    15151500#endif
    15161501
    1517 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    1518   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    1519   {
    1520     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
    1521       m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
    1522       rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
    1523     m_temporalSAD = (Int)SAD;
    1524   }
    1525 #endif
    1526 
    15271502  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
    15281503  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    15551530 
    15561531  m_pcEntropyCoder->resetBits();
    1557 
    15581532  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    15591533  {
     
    16091583
    16101584  m_pcEntropyCoder->resetBits();
    1611 
    16121585  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    16131586  {
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r494 r540  
    103103  Bool                    m_bUseSBACRD;
    104104  TEncRateCtrl*           m_pcRateCtrl;
    105 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    106   UInt                    m_LCUPredictionSAD;
    107   Int                     m_addSADDepth;
    108   Int                     m_temporalSAD;
    109 #endif
     105
    110106#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    111107  Bool                    m_disableILP;
     
    128124 
    129125  Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
    130 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    131   UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
    132 #endif
    133 #if RATE_CONTROL_INTRA
    134126  Int   updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height );
    135 #endif
    136 
    137127protected:
    138128  Void  finishCU            ( TComDataCU*  pcCU, UInt uiAbsPartIdx,           UInt uiDepth        );
     
    146136  Int   xComputeQP          ( TComDataCU* pcCU, UInt uiDepth );
    147137  Void  xCheckBestMode      ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth        );
    148  
     138#if HIGHER_LAYER_IRAP_SKIP_FLAG
     139  Void  xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode, Bool bUseSkip=false);
     140#else 
    149141  Void  xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode);
     142#endif
    150143
    151144#if AMP_MRG
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r494 r540  
    5151Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
    5252{
     53#if !HM_CLEANUP_SAO
    5354  if (pcSlice->getSPS()->getUseSAO())
    5455  {
     
    5960    }
    6061  }
    61 
     62#endif
    6263  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
    6364  return;
     
    638639}
    639640
     641#if !HM_CLEANUP_SAO
    640642/** Encode SAO Offset
    641643 * \param  saoLcuParam SAO LCU paramters
     
    731733}
    732734
     735#endif
     736
    733737Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
    734738{
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r345 r540  
    105105  virtual Void codeCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
    106106  virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0;
     107#if HM_CLEANUP_SAO
     108  virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false)    =0;
     109#else
    107110  virtual Void codeSAOSign          ( UInt code   ) = 0;
    108111  virtual Void codeSaoMaxUvlc       ( UInt code, UInt maxSymbol ) = 0;
     
    110113  virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
    111114  virtual Void codeSaoUflc         ( UInt uiLength, UInt   uiCode ) = 0;
     115#endif
    112116  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
    113117 
     
    188192 
    189193  Void estimateBit             ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType);
     194#if HM_CLEANUP_SAO
     195  Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);}
     196#else
    190197  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);
    191198  Void    encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
     199#endif
    192200  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
    193201
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r494 r540  
    635635    }
    636636#endif
     637#if O0149_CROSS_LAYER_BLA_FLAG
     638    if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP) )
     639    {
     640      pcSlice->setCrossLayerBLAFlag(m_pcEncTop->getCrossLayerBLAFlag());
     641    }
     642    else
     643    {
     644      pcSlice->setCrossLayerBLAFlag(false);
     645    }
     646#endif
     647#if NO_CLRAS_OUTPUT_FLAG
     648    if (m_layerId == 0 &&
     649        (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     650      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     651      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     652      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     653      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
     654      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     655    {
     656      if (m_bFirst)
     657      {
     658        m_pcEncTop->setNoClrasOutputFlag(true);
     659      }
     660      else if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     661            || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     662            || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP)
     663      {
     664        m_pcEncTop->setNoClrasOutputFlag(true);
     665      }
     666#if O0149_CROSS_LAYER_BLA_FLAG
     667      else if ((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) &&
     668               pcSlice->getCrossLayerBLAFlag())
     669      {
     670        m_pcEncTop->setNoClrasOutputFlag(true);
     671      }
     672#endif
     673      else
     674      {
     675        m_pcEncTop->setNoClrasOutputFlag(false);
     676      }
     677      if (m_pcEncTop->getNoClrasOutputFlag())
     678      {
     679        for (UInt i = 0; i < m_pcCfg->getNumLayer(); i++)
     680        {
     681          m_ppcTEncTop[i]->setLayerInitializedFlag(false);
     682          m_ppcTEncTop[i]->setFirstPicInLayerDecodedFlag(false);
     683        }
     684      }
     685    }
     686#endif
    637687#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    638688    if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())
     
    661711#endif
    662712
    663 #if IL_SL_SIGNALLING_N0371
    664     m_pcEncTop->getScalingList()->setLayerId( m_layerId );
    665 #endif
    666 
    667713    pcSlice->setLastIDR(m_iLastIDR);
    668714    pcSlice->setSliceIdx(0);
     
    672718    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    673719    {
    674 #if IL_SL_SIGNALLING_N0371
    675       m_pcEncTop->getTrQuant()->setFlatScalingList( m_layerId );
    676 #else
    677720      m_pcEncTop->getTrQuant()->setFlatScalingList();
    678 #endif
    679721      m_pcEncTop->getTrQuant()->setUseScalingList(false);
    680722      m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
     
    683725    else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT)
    684726    {
    685 #if IL_SL_SIGNALLING_N0371
    686       pcSlice->getScalingList()->setLayerId( m_layerId );
    687 #endif
    688 
    689 #if IL_SL_SIGNALLING_N0371
    690       pcSlice->setDefaultScalingList ( m_layerId );
    691 #else
     727#if SCALINGLIST_INFERRING
     728      // inferring of the scaling list can be moved to the config file
     729      UInt refLayerId = 0;
     730      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     731      {
     732        m_pcEncTop->getSPS()->setInferScalingListFlag( true );
     733        m_pcEncTop->getSPS()->setScalingListRefLayerId( refLayerId );
     734        m_pcEncTop->getSPS()->setScalingListPresentFlag( false );
     735        m_pcEncTop->getPPS()->setInferScalingListFlag( false );
     736        m_pcEncTop->getPPS()->setScalingListPresentFlag( false );
     737
     738        // infer the scaling list from the reference layer
     739        pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() );
     740      }
     741      else
     742      {
     743#endif
    692744      pcSlice->setDefaultScalingList ();
    693 #endif
    694 
    695745      m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
    696746      m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
     747
     748#if SCALINGLIST_INFERRING
     749      }
     750#endif
     751
    697752      m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList());
    698753      m_pcEncTop->getTrQuant()->setUseScalingList(true);
     
    700755    else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ)
    701756    {
    702 #if IL_SL_SIGNALLING_N0371
    703       pcSlice->getScalingList()->setLayerId( m_layerId );
     757#if SCALINGLIST_INFERRING
     758      // inferring of the scaling list can be moved to the config file
     759      UInt refLayerId = 0;
     760      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     761      {
     762        m_pcEncTop->getSPS()->setInferScalingListFlag( true );
     763        m_pcEncTop->getSPS()->setScalingListRefLayerId( refLayerId );
     764        m_pcEncTop->getSPS()->setScalingListPresentFlag( false );
     765        m_pcEncTop->getPPS()->setInferScalingListFlag( false );
     766        m_pcEncTop->getPPS()->setScalingListPresentFlag( false );
     767
     768        // infer the scaling list from the reference layer
     769        pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() );
     770      }
     771      else
     772      {
    704773#endif
    705774
    706775      if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile()))
    707776      {
    708 #if IL_SL_SIGNALLING_N0371
    709         pcSlice->setDefaultScalingList ( m_layerId );
    710 #else
    711777        pcSlice->setDefaultScalingList ();
    712 #endif
    713       }
    714 #if IL_SL_SIGNALLING_N0371
    715       pcSlice->getScalingList()->checkDcOfMatrix( m_layerId );
    716 #else
     778      }
     779
    717780      pcSlice->getScalingList()->checkDcOfMatrix();
    718 #endif
    719781      m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList());
    720 
    721 #if IL_SL_SIGNALLING_N0371
    722       if( m_layerId > 0 )
    723       {
    724         m_pcEncTop->getSPS()->setPredScalingListFlag  (true);
    725         m_pcEncTop->getSPS()->setScalingListRefLayerId( 0 );
    726       }
    727 #endif
    728 
    729782      m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
    730783
    731 #if IL_SL_SIGNALLING_N0371
    732       if( m_layerId > 0 )
    733       {
    734         m_pcEncTop->getPPS()->setPredScalingListFlag  (false);
    735         m_pcEncTop->getPPS()->setScalingListRefLayerId( 0   );
    736       }
     784#if SCALINGLIST_INFERRING
     785    }
    737786#endif
    738787
     
    783832        }
    784833
     834#if O0098_SCALED_REF_LAYER_ID
     835        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     836#else
    785837        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
     838#endif
    786839
    787840        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
     
    800853        if( pcPic->isSpatialEnhLayer(refLayerIdc))
    801854        {
     855/*#if O0098_SCALED_REF_LAYER_ID
     856          Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     857#else
     858          Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
     859#endif*/
    802860#if O0215_PHASE_ALIGNMENT
    803861#if O0194_JOINT_US_BITSHIFT
    804           m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    805 #else
    806           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
     862          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
     863#else
     864          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
    807865#endif
    808866#else
    809867#if O0194_JOINT_US_BITSHIFT
    810           m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
    811 #else
    812           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
     868          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     869#else
     870          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
    813871#endif
    814872#endif
     
    827885        pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i );
    828886      }
     887
     888#if !O0225_TID_BASED_IL_RPS_DERIV
    829889      pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp );
     890#endif
    830891      if ( pcSlice->getActiveNumILRRefIdx() == 0 )
    831892      {
     
    902963
    903964    // Do decoding refresh marking if any
     965#if NO_CLRAS_OUTPUT_FLAG
     966    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag());
     967#else
    904968    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
     969#endif
    905970    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
    906971    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
    907972
    908 #if FIX1071
    909973    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
    910974    {
    911975      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
    912976    }
    913 #else
    914     if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)
    915     {
    916       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());
    917     }
    918 #endif
    919977    pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
    920978
     
    934992            {
    935993              if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) ||
    936                   ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R )
     994                  ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R )
    937995                )
    938996              {
     
    9431001                else
    9441002                {
    945                   pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
     1003                  pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R );
    9461004                }
    9471005                oneRefLayerTSA = true;
     
    9751033            else
    9761034            {
    977               pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
     1035              pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R );
    9781036            }
    9791037          }
     
    9861044        else
    9871045        {
    988           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
     1046          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R);
    9891047        }
    9901048#endif
     
    13561414    pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag());
    13571415
    1358 #if RATE_CONTROL_LAMBDA_DOMAIN
    13591416    Double lambda            = 0.0;
    13601417    Int actualHeadBits       = 0;
     
    13891446      else if ( frameLevel == 0 )   // intra case, but use the model
    13901447      {
    1391 #if RATE_CONTROL_INTRA
    13921448        m_pcSliceEncoder->calCostSliceI(pcPic);
    1393 #endif
    13941449        if ( m_pcCfg->getIntraPeriod() != 1 )   // do not refine allocated bits for all intra case
    13951450        {
    13961451          Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits();
    1397 #if RATE_CONTROL_INTRA
    13981452          bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits );
    1399 #else
    1400           bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );
    1401 #endif
    14021453          if ( bits < 200 )
    14031454          {
     
    14081459
    14091460        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    1410 #if RATE_CONTROL_INTRA
    14111461        m_pcRateCtrl->getRCPic()->getLCUInitTargetBits();
    14121462        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
    1413 #else
    1414         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
    1415 #endif
    14161463        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    14171464      }
     
    14191466      {
    14201467        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    1421 #if RATE_CONTROL_INTRA
    14221468        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
    1423 #else
    1424         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
    1425 #endif
    14261469        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    14271470      }
     
    14361479      m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda );
    14371480    }
    1438 #endif
    14391481
    14401482    UInt uiNumSlices = 1;
     
    16471689
    16481690    // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
     1691#if HM_CLEANUP_SAO
     1692    if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() )
     1693    {
     1694      m_pcSAO->getPreDBFStatistics(pcPic);
     1695    }
     1696#else
    16491697    if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() )
    16501698    {
     
    16521700      m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic );
    16531701    }
    1654 
     1702#endif   
    16551703    //-- Loop filter
    16561704    Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     
    16621710    m_pcLoopFilter->loopFilterPic( pcPic );
    16631711
     1712#if !HM_CLEANUP_SAO   
    16641713    pcSlice = pcPic->getSlice(0);
    16651714    if(pcSlice->getSPS()->getUseSAO())
     
    16811730      m_pcSAO->createPicSaoInfo(pcPic);
    16821731    }
    1683 
     1732#endif
    16841733    /////////////////////////////////////////////////////////////////////////////////////////////////// File writing
    16851734    // Set entropy coder
     
    17131762      writeRBSPTrailingBits(nalu.m_Bitstream);
    17141763      accessUnit.push_back(new NALUnitEBSP(nalu));
    1715 #if RATE_CONTROL_LAMBDA_DOMAIN
    17161764      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1717 #endif
    17181765#if SVC_EXTENSION
    17191766      }
     
    17221769#if SVC_EXTENSION
    17231770      nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId);
    1724 #if IL_SL_SIGNALLING_N0371
    1725       pcSlice->getSPS()->setVPS( pcSlice->getVPS() );
    1726 #endif
    17271771#else
    17281772      nalu = NALUnit(NAL_UNIT_SPS);
     
    17531797        pcSlice->getSPS()->getVuiParameters()->setHrdParametersPresentFlag( true );
    17541798      }
     1799#if O0092_0094_DEPENDENCY_CONSTRAINT
     1800      assert( pcSlice->getSPS()->getLayerId() == 0 || pcSlice->getSPS()->getLayerId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getSPS()->getLayerId()) );
     1801#endif
    17551802      m_pcEntropyCoder->encodeSPS(pcSlice->getSPS());
    17561803      writeRBSPTrailingBits(nalu.m_Bitstream);
    17571804      accessUnit.push_back(new NALUnitEBSP(nalu));
    1758 #if RATE_CONTROL_LAMBDA_DOMAIN
    17591805      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1760 #endif
    17611806
    17621807#if SVC_EXTENSION
     
    17661811#endif
    17671812      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     1813#if O0092_0094_DEPENDENCY_CONSTRAINT
     1814      assert( pcSlice->getPPS()->getPPSId() == 0 || pcSlice->getPPS()->getPPSId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getPPS()->getPPSId()) );
     1815#endif
    17681816      m_pcEntropyCoder->encodePPS(pcSlice->getPPS());
    17691817      writeRBSPTrailingBits(nalu.m_Bitstream);
    17701818      accessUnit.push_back(new NALUnitEBSP(nalu));
    1771 #if RATE_CONTROL_LAMBDA_DOMAIN
    17721819      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1773 #endif
    17741820
    17751821      xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS());
     
    20912137          }
    20922138          m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    2093 #if RATE_CONTROL_LAMBDA_DOMAIN
    20942139          tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
    2095 #endif
    2096 
    20972140          m_pcEntropyCoder->encodeSliceHeader(pcSlice);
    2098 
    2099 #if RATE_CONTROL_LAMBDA_DOMAIN
    21002141          actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
    2101 #endif
    21022142
    21032143          // is it needed?
     
    22202260          xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect);
    22212261          accessUnit.push_back(new NALUnitEBSP(nalu));
    2222 #if RATE_CONTROL_LAMBDA_DOMAIN
    22232262          actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    2224 #endif
    22252263          bNALUAlignedWrittenToList = true;
    22262264          uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment
     
    22622300            // set entropy coder for RD
    22632301            m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
     2302#if HIGHER_LAYER_IRAP_SKIP_FLAG
     2303            if ( pcSlice->getSPS()->getUseSAO() && !( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) )
     2304#else
    22642305            if ( pcSlice->getSPS()->getUseSAO() )
     2306#endif
    22652307            {
    22662308              m_pcEntropyCoder->resetEntropy();
    22672309              m_pcEntropyCoder->setBitstream( m_pcBitCounter );
     2310#if HM_CLEANUP_SAO
     2311              Bool sliceEnabled[NUM_SAO_COMPONENTS];
     2312              m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice);
     2313              m_pcSAO->SAOProcess(pcPic
     2314                , sliceEnabled
     2315                , pcPic->getSlice(0)->getLambdas()
     2316#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     2317                , m_pcCfg->getSaoLcuBoundary()
     2318#endif
     2319              );
     2320              m_pcSAO->PCMLFDisableProcess(pcPic);   
     2321
     2322              //assign SAO slice header
     2323              for(Int s=0; s< uiNumSlices; s++)
     2324              {
     2325                pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]);
     2326                assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]);
     2327                pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]);
     2328              }
     2329#else
    22682330              m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder());
    22692331              SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam();
    22702332
    2271 #if SAO_CHROMA_LAMBDA
    22722333#if SAO_ENCODING_CHOICE
    2273               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth());
     2334              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdas()[TEXT_LUMA], pcPic->getSlice(0)->getLambdas()[TEXT_CHROMA], pcPic->getSlice(0)->getDepth());
    22742335#else
    22752336              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
    2276 #endif
    2277 #else
    2278               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda());
    22792337#endif
    22802338              m_pcSAO->endSaoEnc();
    22812339              m_pcSAO->PCMLFDisableProcess(pcPic);
     2340#endif
    22822341            }
     2342#if !HM_CLEANUP_SAO         
    22832343#if SAO_RDO
    22842344            m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    22852345#endif
     2346#endif
    22862347            processingState = ENCODE_SLICE;
    2287 
     2348#if !HM_CLEANUP_SAO
     2349#if HIGHER_LAYER_IRAP_SKIP_FLAG
     2350            if ( ( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) )
     2351            {
     2352              pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]=0;
     2353              pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[1]=0;
     2354            }
     2355#endif
    22882356            for(Int s=0; s< uiNumSlices; s++)
    22892357            {
     
    22932361              }
    22942362            }
     2363#endif
    22952364          }
    22962365          break;
     
    23032372        }
    23042373      } // end iteration over slices
    2305 
     2374#if !HM_CLEANUP_SAO   
    23062375      if(pcSlice->getSPS()->getUseSAO())
    23072376      {
     
    23122381        pcPic->destroyNonDBFilterInfo();
    23132382      }
    2314 
     2383#endif
    23152384      pcPic->compressMotion();
    23162385     
     
    24122481        }
    24132482      }
    2414 #if RATE_CONTROL_LAMBDA_DOMAIN
    24152483      if ( m_pcCfg->getUseRateCtrl() )
    24162484      {
    2417 #if !M0036_RC_IMPROVEMENT
    2418         Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();
    2419 #endif
    24202485        Double avgQP     = m_pcRateCtrl->getRCPic()->calAverageQP();
    24212486        Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda();
     
    24242489          avgLambda = lambda;
    24252490        }
    2426 #if M0036_RC_IMPROVEMENT
    2427 #if RATE_CONTROL_INTRA
    24282491        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType());
    2429 #else
    2430         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );
    2431 #endif
    2432 #else
    2433         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );
    2434 #endif
    24352492        m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() );
    24362493
     
    24452502        }
    24462503      }
    2447 #else
    2448       if(m_pcCfg->getUseRateCtrl())
    2449       {
    2450         UInt  frameBits = m_vRVM_RP[m_vRVM_RP.size()-1];
    2451         m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType());
    2452       }
    2453 #endif
    24542504
    24552505      if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
     
    26362686      delete[] pcSubstreamsOut;
    26372687  }
    2638 #if !RATE_CONTROL_LAMBDA_DOMAIN
    2639   if(m_pcCfg->getUseRateCtrl())
    2640   {
    2641     m_pcRateCtrl->updateRCGOPStatus();
    2642   }
    2643 #endif
    26442688  delete pcBitstreamRedirect;
    26452689
     
    27242768  m_pcEntropyCoder->resetEntropy    ();
    27252769  m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
     2770#if !HM_CLEANUP_SAO
    27262771  pcSlice = pcPic->getSlice(0);
    27272772  if(pcSlice->getSPS()->getUseSAO())
     
    27382783    pcPic->destroyNonDBFilterInfo();
    27392784  }
    2740  
     2785#endif
    27412786  m_pcEntropyCoder->resetEntropy    ();
    27422787  ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
     
    28102855      iterPicYuvRec--;
    28112856    }
     2857   
    28122858  }
    28132859 
     
    29052951    case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
    29062952    case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
    2907     case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
     2953    case NAL_UNIT_CODED_SLICE_TSA_R:      return "TSA_R";
    29082954    case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
    29092955    case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
     
    31403186    for (Int x = 0; x < width; x++)
    31413187    {
    3142       dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
    3143       dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     3188      dst[x] = isTff ? top[x] : bottom[x];
     3189      dst[stride+x] = isTff ? bottom[x] : top[x];
    31443190    }
    31453191    top += stride;
     
    32983344  delete pcRecInterlaced;
    32993345}
     3346
     3347
    33003348
    33013349/** Function for deciding the nal_unit_type.
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r313 r540  
    4242using namespace std;
    4343
    44 #if RATE_CONTROL_LAMBDA_DOMAIN
    45 
    4644//sequence level
    4745TEncRCSeq::TEncRCSeq()
     
    6765  m_bitsLeft            = 0;
    6866  m_useLCUSeparateModel = false;
    69 #if M0036_RC_IMPROVEMENT
    7067  m_adaptiveBit         = 0;
    7168  m_lastLambda          = 0.0;
    72 #endif
    7369}
    7470
     
    7874}
    7975
    80 #if M0036_RC_IMPROVEMENT
    8176Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )
    82 #else
    83 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )
    84 #endif
    8577{
    8678  destroy();
     
    109101    m_betaUpdate  = 0.025;
    110102  }
    111 #if M0036_RC_IMPROVEMENT
    112103  else if ( m_seqTargetBpp < 0.2 )
    113104  {
     
    125116    m_betaUpdate  = 0.2;
    126117  }
    127 #else
    128   else
    129   {
    130     m_alphaUpdate = 0.1;
    131     m_betaUpdate  = 0.05;
    132   }
    133 #endif
    134118  m_averageBits     = (Int)(m_targetBits / totalFrames);
    135119  Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
     
    172156  m_framesLeft = m_totalFrames;
    173157  m_bitsLeft   = m_targetBits;
    174 #if M0036_RC_IMPROVEMENT
    175158  m_adaptiveBit = adaptiveBit;
    176159  m_lastLambda = 0.0;
    177 #endif
    178160}
    179161
     
    233215    for ( Int i=0; i<m_numberOfLevel; i++ )
    234216    {
    235 #if RATE_CONTROL_INTRA
    236217      if (i>0)
    237218      {
     
    244225        m_picPara[i].m_beta  = BETA2;
    245226      }
    246 #else
    247       m_picPara[i].m_alpha = 3.2003;
    248       m_picPara[i].m_beta  = -1.367;
    249 #endif
    250227    }
    251228  }
     
    271248      for ( Int j=0; j<m_numberOfLCU; j++)
    272249      {
    273 #if RATE_CONTROL_INTRA
    274250        m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha;
    275251        m_LCUPara[i][j].m_beta  = m_picPara[i].m_beta;
    276 #else
    277         m_LCUPara[i][j].m_alpha = 3.2003;
    278         m_LCUPara[i][j].m_beta  = -1.367;
    279 #endif
    280252      }
    281253    }
     
    299271}
    300272
    301 #if !RATE_CONTROL_INTRA
    302 Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )
    303 {
    304   Double bpp = ( (Double)orgBits ) / m_picHeight / m_picHeight;
    305   if ( bpp > 0.2 )
    306   {
    307     return orgBits * 5;
    308   }
    309   if ( bpp > 0.1 )
    310   {
    311     return orgBits * 7;
    312   }
    313   return orgBits * 10;
    314 }
    315 #endif
    316 
    317 #if M0036_RC_IMPROVEMENT
    318273Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB )
    319274{
     
    326281  delete[] bitsRatio;
    327282}
    328 #endif
    329283
    330284//GOP level
     
    349303  Int targetBits = xEstGOPTargetBits( encRCSeq, numPic );
    350304
    351 #if M0036_RC_IMPROVEMENT
    352305  if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 )
    353306  {
     
    409362    delete []equaCoeffB;
    410363  }
    411 #endif
    412364
    413365  m_picTargetBitInGOP = new Int[numPic];
     
    422374  {
    423375    currPicRatio = encRCSeq->getBitRatio( i );
    424 #if M0036_RC_IMPROVEMENT
    425376    m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio );
    426 #else
    427     m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;
    428 #endif
    429377  }
    430378
     
    436384}
    437385
    438 #if M0036_RC_IMPROVEMENT
    439386Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
    440387{
     
    482429  return solution;
    483430}
    484 #endif
    485431
    486432Void TEncRCGOP::destroy()
     
    534480
    535481  m_LCUs         = NULL;
    536 #if !M0036_RC_IMPROVEMENT
    537   m_lastPicture  = NULL;
    538 #endif
    539482  m_picActualHeaderBits = 0;
    540 #if !M0036_RC_IMPROVEMENT
    541   m_totalMAD            = 0.0;
    542 #endif
    543483  m_picActualBits       = 0;
    544484  m_picQP               = 0;
     
    565505  }
    566506
    567 #if M0036_RC_IMPROVEMENT
    568507  targetBits  = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio );
    569 #else
    570   targetBits  = Int( GOPbitsLeft * currPicRatio / totalPicRatio );
    571 #endif
    572508
    573509  if ( targetBits < 100 )
     
    665601      m_LCUs[LCUIdx].m_lambda     = 0.0;
    666602      m_LCUs[LCUIdx].m_targetBits = 0;
    667 #if M0036_RC_IMPROVEMENT
    668603      m_LCUs[LCUIdx].m_bitWeight  = 1.0;
    669 #else
    670       m_LCUs[LCUIdx].m_MAD        = 0.0;
    671 #endif
    672604      Int currWidth  = ( (i == picWidthInLCU -1) ? picWidth  - LCUWidth *(picWidthInLCU -1) : LCUWidth  );
    673605      Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
     
    676608  }
    677609  m_picActualHeaderBits = 0;
    678 #if !M0036_RC_IMPROVEMENT
    679   m_totalMAD            = 0.0;
    680 #endif
    681610  m_picActualBits       = 0;
    682611  m_picQP               = 0;
    683612  m_picLambda           = 0.0;
    684 
    685 #if !M0036_RC_IMPROVEMENT
    686   m_lastPicture = NULL;
    687   list<TEncRCPic*>::reverse_iterator it;
    688   for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
    689   {
    690     if ( (*it)->getFrameLevel() == m_frameLevel )
    691     {
    692       m_lastPicture = (*it);
    693       break;
    694     }
    695   }
    696 #endif
    697613}
    698614
     
    709625
    710626
    711 #if RATE_CONTROL_INTRA
    712627Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType)
    713 #else
    714 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )
    715 #endif
    716628{
    717629  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    718630  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    719631  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
    720 #if RATE_CONTROL_INTRA
    721632  Double estLambda;
    722633  if (eSliceType == I_SLICE)
     
    728639    estLambda = alpha * pow( bpp, beta );
    729640  }
    730 #else
    731   Double estLambda = alpha * pow( bpp, beta );
    732 #endif 
    733641 
    734642  Double lastLevelLambda = -1.0;
     
    778686  m_estPicLambda = estLambda;
    779687
    780 #if M0036_RC_IMPROVEMENT
    781688  Double totalWeight = 0.0;
    782689  // initial BU bit allocation weight
    783690  for ( Int i=0; i<m_numberOfLCU; i++ )
    784691  {
    785 #if RC_FIX
    786692    Double alphaLCU, betaLCU;
    787693    if ( m_encRCSeq->getUseLCUSeparateModel() )
     
    795701      betaLCU  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    796702    }
    797 #else
    798     Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
    799     Double betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
    800 #endif
    801703
    802704    m_LCUs[i].m_bitWeight =  m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU );
     
    813715    m_LCUs[i].m_bitWeight = BUTargetBits;
    814716  }
    815 #endif
    816717
    817718  return estLambda;
     
    856757}
    857758
    858 #if RATE_CONTROL_INTRA
    859759Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
    860 #else
    861 Double TEncRCPic::getLCUTargetBpp()
    862 #endif
    863760{
    864761  Int   LCUIdx    = getLCUCoded();
    865762  Double bpp      = -1.0;
    866763  Int avgBits     = 0;
    867 #if !M0036_RC_IMPROVEMENT
    868   Double totalMAD = -1.0;
    869   Double MAD      = -1.0;
    870 #endif
    871 
    872 #if RATE_CONTROL_INTRA
    873   if (eSliceType == I_SLICE){
     764
     765  if (eSliceType == I_SLICE)
     766  {
    874767    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
    875768    Int bitrateWindow = min(4,noOfLCUsLeft);
     
    889782  else
    890783  {
    891 #endif
    892 #if M0036_RC_IMPROVEMENT
    893784  Double totalWeight = 0;
    894785  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
     
    898789  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
    899790  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
    900 #else
    901   if ( m_lastPicture == NULL )
    902   {
    903     avgBits = Int( m_bitsLeft / m_LCULeft );
    904   }
    905   else
    906   {
    907     MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
    908     totalMAD = m_lastPicture->getTotalMAD();
    909     for ( Int i=0; i<LCUIdx; i++ )
    910     {
    911       totalMAD -= m_lastPicture->getLCU(i).m_MAD;
    912     }
    913 
    914     if ( totalMAD > 0.1 )
    915     {
    916       avgBits = Int( m_bitsLeft * MAD / totalMAD );
    917     }
    918     else
    919     {
    920       avgBits = Int( m_bitsLeft / m_LCULeft );
    921     }
    922   }
    923 #endif
    924 #if RATE_CONTROL_INTRA
    925   }
    926 #endif
     791    }
    927792
    928793  if ( avgBits < 1 )
     
    1050915    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    1051916
    1052 #if M0036_RC_IMPROVEMENT
    1053917    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    1054918    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1055 #else
    1056     alpha = Clip3( 0.05, 20.0, alpha );
    1057     beta  = Clip3( -3.0, -0.1, beta  );
    1058 #endif
    1059919
    1060920    TRCParameter rcPara;
     
    1069929  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    1070930  double lnbpp = log( bpp );
    1071 #if M0036_RC_IMPROVEMENT
    1072931  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    1073 #else
    1074   lnbpp = Clip3( -5.0, 1.0, lnbpp );
    1075 #endif
    1076932  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    1077933
    1078 #if M0036_RC_IMPROVEMENT
    1079934  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    1080935  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1081 #else
    1082   alpha = Clip3( 0.05, 20.0, alpha );
    1083   beta  = Clip3( -3.0, -0.1, beta  );
    1084 #endif
    1085936  TRCParameter rcPara;
    1086937  rcPara.m_alpha = alpha;
     
    1090941}
    1091942
    1092 #if !M0036_RC_IMPROVEMENT
    1093 Double TEncRCPic::getEffectivePercentage()
    1094 {
    1095   Int effectivePiexels = 0;
    1096   Int totalPixels = 0;
    1097 
    1098   for ( Int i=0; i<m_numberOfLCU; i++ )
    1099   {
    1100     totalPixels += m_LCUs[i].m_numberOfPixel;
    1101     if ( m_LCUs[i].m_QP > 0 )
    1102     {
    1103       effectivePiexels += m_LCUs[i].m_numberOfPixel;
    1104     }
    1105   }
    1106 
    1107   Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;
    1108   return effectivePixelPercentage;
    1109 }
    1110 #endif
    1111 
    1112943Double TEncRCPic::calAverageQP()
    1113944{
     
    1164995}
    1165996
    1166 #if M0036_RC_IMPROVEMENT
    1167 #if RATE_CONTROL_INTRA
    1168997Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
    1169 #else
    1170 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )
    1171 #endif
    1172 #else
    1173 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )
    1174 #endif
    1175998{
    1176999  m_picActualHeaderBits = actualHeaderBits;
     
    11851008  }
    11861009  m_picLambda           = averageLambda;
    1187 #if !M0036_RC_IMPROVEMENT
    1188   for ( Int i=0; i<m_numberOfLCU; i++ )
    1189   {
    1190     m_totalMAD += m_LCUs[i].m_MAD;
    1191   }
    1192 #endif
    11931010
    11941011  Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    11951012  Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    1196 #if RATE_CONTROL_INTRA
    11971013  if (eSliceType == I_SLICE)
    11981014  {
     
    12011017  else
    12021018  {
    1203 #endif
    12041019  // update parameters
    12051020  Double picActualBits = ( Double )m_picActualBits;
     
    12081023  Double inputLambda   = m_picLambda;
    12091024
    1210 #if M0036_RC_IMPROVEMENT
    12111025  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 )
    1212 #else
    1213   if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )
    1214 #endif
    12151026  {
    12161027    alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 );
    12171028    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    12181029
    1219 #if M0036_RC_IMPROVEMENT
    12201030    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    12211031    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1222 #else
    1223     alpha = Clip3( 0.05, 20.0, alpha );
    1224     beta  = Clip3( -3.0, -0.1, beta  );
    1225 #endif
    12261032    TRCParameter rcPara;
    12271033    rcPara.m_alpha = alpha;
     
    12351041  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    12361042  double lnbpp = log( picActualBpp );
    1237 #if M0036_RC_IMPROVEMENT
    12381043  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    1239 #else
    1240   lnbpp = Clip3( -5.0, 1.0, lnbpp );
    1241 #endif
    12421044  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    12431045
    1244 #if M0036_RC_IMPROVEMENT
    12451046  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    12461047  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1247 #else
    1248   alpha = Clip3( 0.05, 20.0, alpha );
    1249   beta  = Clip3( -3.0, -0.1, beta  );
    1250 #endif
    1251 #if RATE_CONTROL_INTRA
    1252   }
    1253 #endif
     1048  }
    12541049
    12551050  TRCParameter rcPara;
     
    12591054  m_encRCSeq->setPicPara( m_frameLevel, rcPara );
    12601055
    1261 #if M0036_RC_IMPROVEMENT
    12621056  if ( m_frameLevel == 1 )
    12631057  {
     
    12661060    m_encRCSeq->setLastLambda( updateLastLambda );
    12671061  }
    1268 #endif
    1269 }
    1270 
    1271 #if RATE_CONTROL_INTRA
     1062}
     1063
    12721064Int TEncRCPic::getRefineBitsForIntra( Int orgBits )
    12731065{
     
    13581150  return estLambda;
    13591151}
    1360 #endif
    13611152
    13621153TEncRateCtrl::TEncRateCtrl()
     
    13921183}
    13931184
    1394 #if M0036_RC_IMPROVEMENT
    13951185Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
    1396 #else
    1397 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
    1398 #endif
    13991186{
    14001187  destroy();
     
    14111198
    14121199  Int numberOfLevel = 1;
    1413 #if M0036_RC_IMPROVEMENT
    14141200  Int adaptiveBit = 0;
    14151201  if ( keepHierBits > 0 )
    1416 #else
    1417   if ( keepHierBits )
    1418 #endif
    14191202  {
    14201203    numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1;
     
    14391222  }
    14401223
    1441 #if M0036_RC_IMPROVEMENT
    14421224  if ( keepHierBits > 0 )
    1443 #else
    1444   if ( keepHierBits )
    1445 #endif
    14461225  {
    14471226    Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) );
     
    14761255        bitsRatio[3] = 14;
    14771256      }
    1478 #if M0036_RC_IMPROVEMENT
    14791257      if ( keepHierBits == 2 )
    14801258      {
    14811259        adaptiveBit = 1;
    14821260      }
    1483 #endif
    14841261    }
    14851262    else if ( GOPSize == 8 && !isLowdelay )
     
    15291306        bitsRatio[7] = 1;
    15301307      }
    1531 #if M0036_RC_IMPROVEMENT
    15321308      if ( keepHierBits == 2 )
    15331309      {
    15341310        adaptiveBit = 2;
    15351311      }
    1536 #endif
    15371312    }
    15381313    else
    15391314    {
    1540 #if M0036_RC_IMPROVEMENT
    15411315      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" );
    1542 #else
    1543       printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );
    1544 #endif
    15451316    }
    15461317  }
     
    15551326    }
    15561327  }
    1557 #if M0036_RC_IMPROVEMENT
    15581328  if ( keepHierBits > 0 )
    1559 #else
    1560   if ( keepHierBits )
    1561 #endif
    15621329  {
    15631330    if ( GOPSize == 4 && isLowdelay )
     
    15941361
    15951362  m_encRCSeq = new TEncRCSeq;
    1596 #if M0036_RC_IMPROVEMENT
    15971363  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit );
    1598 #else
    1599   m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );
    1600 #endif
    16011364  m_encRCSeq->initBitsRatio( bitsRatio );
    16021365  m_encRCSeq->initGOPID2Level( GOPID2Level );
     
    16291392}
    16301393
    1631 #else
    1632 
    1633 #define ADJUSTMENT_FACTOR       0.60
    1634 #define HIGH_QSTEP_THRESHOLD    9.5238
    1635 #define HIGH_QSTEP_ALPHA        4.9371
    1636 #define HIGH_QSTEP_BETA         0.0922
    1637 #define LOW_QSTEP_ALPHA         16.7429
    1638 #define LOW_QSTEP_BETA          -1.1494
    1639 
    1640 #define MAD_PRED_Y1             1.0
    1641 #define MAD_PRED_Y2             0.0
    1642 
    1643 enum MAD_HISOTRY {
    1644   MAD_PPPrevious = 0,
    1645   MAD_PPrevious  = 1,
    1646   MAD_Previous   = 2
    1647 };
    1648 
    1649 Void    MADLinearModel::initMADLinearModel()
    1650 {
    1651   m_activeOn = false;
    1652   m_paramY1  = 1.0;
    1653   m_paramY2  = 0.0;
    1654   m_costMADs[0] = m_costMADs[1] = m_costMADs[2] = 0.0;
    1655 }
    1656 
    1657 Double  MADLinearModel::getMAD()
    1658 {
    1659   Double costPredMAD = m_paramY1 * m_costMADs[MAD_Previous] + m_paramY2;
    1660 
    1661   if(costPredMAD < 0)
    1662   {
    1663     costPredMAD = m_costMADs[MAD_Previous];
    1664     m_paramY1   = MAD_PRED_Y1;
    1665     m_paramY2   = MAD_PRED_Y2;
    1666   }
    1667   return costPredMAD;
    1668 }
    1669 
    1670 Void    MADLinearModel::updateMADLiearModel()
    1671 {
    1672   Double dNewY1 = ((m_costMADs[MAD_Previous] - m_costMADs[MAD_PPrevious]) / (m_costMADs[MAD_PPrevious] - m_costMADs[MAD_PPPrevious]));
    1673   Double dNewY2 =  (m_costMADs[MAD_Previous] - (dNewY1*m_costMADs[MAD_PPrevious]));
    1674  
    1675   m_paramY1 = 0.70+0.20*m_paramY1+ 0.10*dNewY1;
    1676   m_paramY2 =      0.20*m_paramY2+ 0.10*dNewY2;
    1677 }
    1678 
    1679 Void    MADLinearModel::updateMADHistory(Double dMAD)
    1680 {
    1681   m_costMADs[MAD_PPPrevious] = m_costMADs[MAD_PPrevious];
    1682   m_costMADs[MAD_PPrevious ] = m_costMADs[MAD_Previous ];
    1683   m_costMADs[MAD_Previous  ] = dMAD;
    1684   m_activeOn = (m_costMADs[MAD_Previous  ] && m_costMADs[MAD_PPrevious ] && m_costMADs[MAD_PPPrevious]);
    1685 }
    1686 
    1687 
    1688 Void    PixelBaseURQQuadraticModel::initPixelBaseQuadraticModel()
    1689 {
    1690   m_paramHighX1 = HIGH_QSTEP_ALPHA;
    1691   m_paramHighX2 = HIGH_QSTEP_BETA;
    1692   m_paramLowX1  = LOW_QSTEP_ALPHA;
    1693   m_paramLowX2  = LOW_QSTEP_BETA;
    1694 }
    1695 
    1696 Int     PixelBaseURQQuadraticModel::getQP(Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD)
    1697 {
    1698   Double qStep;
    1699   Double bppPerMAD = (Double)(targetBits/(numberOfPixels*costPredMAD));
    1700  
    1701   if(xConvertQP2QStep(qp) >= HIGH_QSTEP_THRESHOLD)
    1702   {
    1703     qStep = 1/( sqrt((bppPerMAD/m_paramHighX1)+((m_paramHighX2*m_paramHighX2)/(4*m_paramHighX1*m_paramHighX1))) - (m_paramHighX2/(2*m_paramHighX1)));
    1704   }
    1705   else
    1706   {
    1707     qStep = 1/( sqrt((bppPerMAD/m_paramLowX1)+((m_paramLowX2*m_paramLowX2)/(4*m_paramLowX1*m_paramLowX1))) - (m_paramLowX2/(2*m_paramLowX1)));
    1708   }
    1709  
    1710   return xConvertQStep2QP(qStep);
    1711 }
    1712 
    1713 Void    PixelBaseURQQuadraticModel::updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD)
    1714 {
    1715   Double qStep     = xConvertQP2QStep(qp);
    1716   Double invqStep = (1/qStep);
    1717   Double paramNewX1, paramNewX2;
    1718  
    1719   if(qStep >= HIGH_QSTEP_THRESHOLD)
    1720   {
    1721     paramNewX2    = (((bits/(numberOfPixels*costMAD))-(23.3772*invqStep*invqStep))/((1-200*invqStep)*invqStep));
    1722     paramNewX1    = (23.3772-200*paramNewX2);
    1723     m_paramHighX1 = 0.70*HIGH_QSTEP_ALPHA + 0.20 * m_paramHighX1 + 0.10 * paramNewX1;
    1724     m_paramHighX2 = 0.70*HIGH_QSTEP_BETA  + 0.20 * m_paramHighX2 + 0.10 * paramNewX2;
    1725   }
    1726   else
    1727   {
    1728     paramNewX2   = (((bits/(numberOfPixels*costMAD))-(5.8091*invqStep*invqStep))/((1-9.5455*invqStep)*invqStep));
    1729     paramNewX1   = (5.8091-9.5455*paramNewX2);
    1730     m_paramLowX1 = 0.90*LOW_QSTEP_ALPHA + 0.09 * m_paramLowX1 + 0.01 * paramNewX1;
    1731     m_paramLowX2 = 0.90*LOW_QSTEP_BETA  + 0.09 * m_paramLowX2 + 0.01 * paramNewX2;
    1732   }
    1733 }
    1734 
    1735 Bool    PixelBaseURQQuadraticModel::checkUpdateAvailable(Int qpReference )
    1736 {
    1737   Double qStep = xConvertQP2QStep(qpReference);
    1738 
    1739   if (qStep > xConvertQP2QStep(MAX_QP)
    1740     ||qStep < xConvertQP2QStep(MIN_QP) )
    1741   {
    1742     return false;
    1743   }
    1744 
    1745   return true;
    1746 }
    1747 
    1748 Double  PixelBaseURQQuadraticModel::xConvertQP2QStep(Int qp )
    1749 {
    1750   Int i;
    1751   Double qStep;
    1752   static const Double mapQP2QSTEP[6] = { 0.625, 0.703, 0.797, 0.891, 1.000, 1.125 };
    1753 
    1754   qStep = mapQP2QSTEP[qp % 6];
    1755   for( i=0; i<(qp/6); i++)
    1756   {
    1757     qStep *= 2;
    1758   }
    1759 
    1760   return qStep;
    1761 }
    1762 
    1763 Int     PixelBaseURQQuadraticModel::xConvertQStep2QP(Double qStep )
    1764 {
    1765   Int per = 0, rem = 0;
    1766 
    1767   if( qStep < xConvertQP2QStep(MIN_QP))
    1768   {
    1769     return MIN_QP;
    1770   }
    1771   else if (qStep > xConvertQP2QStep(MAX_QP) )
    1772   {
    1773     return MAX_QP;
    1774   }
    1775 
    1776   while( qStep > xConvertQP2QStep(5) )
    1777   {
    1778     qStep /= 2.0;
    1779     per++;
    1780   }
    1781 
    1782   if (qStep <= 0.625)
    1783   {
    1784     rem = 0;
    1785   }
    1786   else if (qStep <= 0.703)
    1787   {
    1788     rem = 1;
    1789   }
    1790   else if (qStep <= 0.797)
    1791   {
    1792     rem = 2;
    1793   }
    1794   else if (qStep <= 0.891)
    1795   {
    1796     rem = 3;
    1797   }
    1798   else if (qStep <= 1.000)
    1799   {
    1800     rem = 4;
    1801   }
    1802   else
    1803   {
    1804     rem = 5;
    1805   }
    1806   return (per * 6 + rem);
    1807 }
    1808 
    1809 
    1810 Void  TEncRateCtrl::create(Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight)
    1811 {
    1812   Int leftInHeight, leftInWidth;
    1813 
    1814   m_sourceWidthInLCU         = (sourceWidth  / maxCUWidth  ) + (( sourceWidth  %  maxCUWidth ) ? 1 : 0);
    1815   m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0); 
    1816   m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
    1817   m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
    1818   m_currBitrate              = ( targetKbps << 10 );
    1819   m_frameRate                = frameRate;
    1820   m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
    1821   m_nonRefFrameNum           = sizeGOP-m_refFrameNum;
    1822   m_sizeGOP                  = sizeGOP;
    1823   m_numOfPixels              = ((sourceWidth*sourceHeight*3)>>1);
    1824   m_indexGOP                 = 0;
    1825   m_indexFrame               = 0;
    1826   m_indexLCU                 = 0;
    1827   m_indexUnit                = 0;
    1828   m_indexRefFrame            = 0;
    1829   m_indexNonRefFrame         = 0;
    1830   m_occupancyVB              = 0;
    1831   m_initialOVB               = 0;
    1832   m_targetBufLevel           = 0;
    1833   m_initialTBL               = 0;
    1834   m_occupancyVBInFrame       = 0;
    1835   m_remainingBitsInGOP       = (m_currBitrate*sizeGOP/m_frameRate);
    1836   m_remainingBitsInFrame     = 0;
    1837   m_numUnitInFrame           = m_sourceWidthInLCU*m_sourceHeightInLCU;
    1838   m_cMADLinearModel.        initMADLinearModel();
    1839   m_cPixelURQQuadraticModel.initPixelBaseQuadraticModel();
    1840 
    1841   m_costRefAvgWeighting      = 0.0;
    1842   m_costNonRefAvgWeighting   = 0.0;
    1843   m_costAvgbpp               = 0.0; 
    1844   m_activeUnitLevelOn        = false;
    1845 
    1846   m_pcFrameData              = new FrameData   [sizeGOP+1];         initFrameData(qp);
    1847   m_pcLCUData                = new LCUData     [m_numUnitInFrame];  initUnitData (qp);
    1848 
    1849   for(Int i = 0, addressUnit = 0; i < m_sourceHeightInLCU*maxCUHeight; i += maxCUHeight) 
    1850   {
    1851     leftInHeight = sourceHeight - i;
    1852     leftInHeight = min(leftInHeight, maxCUHeight);
    1853     for(Int j = 0; j < m_sourceWidthInLCU*maxCUWidth; j += maxCUWidth, addressUnit++)
    1854     {
    1855       leftInWidth = sourceWidth - j;
    1856       leftInWidth = min(leftInWidth, maxCUWidth);
    1857       m_pcLCUData[addressUnit].m_widthInPixel = leftInWidth;
    1858       m_pcLCUData[addressUnit].m_heightInPixel= leftInHeight;
    1859       m_pcLCUData[addressUnit].m_pixels       = ((leftInHeight*leftInWidth*3)>>1);
    1860     }
    1861   }
    1862 }
    1863 
    1864 Void  TEncRateCtrl::destroy()
    1865 {
    1866   if(m_pcFrameData)
    1867   {
    1868     delete [] m_pcFrameData;
    1869     m_pcFrameData = NULL;
    1870   }
    1871   if(m_pcLCUData)
    1872   {
    1873     delete [] m_pcLCUData;
    1874     m_pcLCUData = NULL;
    1875   }
    1876 }
    1877 
    1878 Void  TEncRateCtrl::initFrameData   (Int qp)
    1879 {
    1880   for(Int i = 0 ; i <= m_sizeGOP; i++)
    1881   {
    1882     m_pcFrameData[i].m_isReferenced = false;
    1883     m_pcFrameData[i].m_costMAD      = 0.0;
    1884     m_pcFrameData[i].m_bits         = 0;
    1885     m_pcFrameData[i].m_qp           = qp;
    1886   }
    1887 }
    1888 
    1889 Void  TEncRateCtrl::initUnitData    (Int qp)
    1890 {
    1891   for(Int i = 1 ; i < m_numUnitInFrame; i++)
    1892   {
    1893     m_pcLCUData[i].m_qp            = qp;
    1894     m_pcLCUData[i].m_bits          = 0;
    1895     m_pcLCUData[i].m_pixels        = 0;
    1896     m_pcLCUData[i].m_widthInPixel  = 0;
    1897     m_pcLCUData[i].m_heightInPixel = 0;
    1898     m_pcLCUData[i].m_costMAD       = 0.0;
    1899   }
    1900 }
    1901 
    1902 Int  TEncRateCtrl::getFrameQP(Bool isReferenced, Int POC)
    1903 {
    1904   Int numofReferenced = 0;
    1905   Int finalQP = 0;
    1906   FrameData* pcFrameData;
    1907 
    1908   m_indexPOCInGOP = (POC%m_sizeGOP) == 0 ? m_sizeGOP : (POC%m_sizeGOP);
    1909   pcFrameData     = &m_pcFrameData[m_indexPOCInGOP];
    1910    
    1911   if(m_indexFrame != 0)
    1912   {
    1913     if(isReferenced)
    1914     {
    1915       Double gamma = m_isLowdelay ? 0.5 : 0.25;
    1916       Double beta  = m_isLowdelay ? 0.9 : 0.6;
    1917       Int    numRemainingRefFrames  = m_refFrameNum    - m_indexRefFrame;
    1918       Int    numRemainingNRefFrames = m_nonRefFrameNum - m_indexNonRefFrame;
    1919      
    1920       Double targetBitsOccupancy  = (m_currBitrate/(Double)m_frameRate) + gamma*(m_targetBufLevel-m_occupancyVB - (m_initialOVB/(Double)m_frameRate));
    1921       Double targetBitsLeftBudget = ((m_costRefAvgWeighting*m_remainingBitsInGOP)/((m_costRefAvgWeighting*numRemainingRefFrames)+(m_costNonRefAvgWeighting*numRemainingNRefFrames)));
    1922 
    1923       m_targetBits = (Int)(beta * targetBitsLeftBudget + (1-beta) * targetBitsOccupancy);
    1924  
    1925       if(m_targetBits <= 0 || m_remainingBitsInGOP <= 0)
    1926       {
    1927         finalQP = m_pcFrameData[m_indexPrevPOCInGOP].m_qp + 2;
    1928       }
    1929       else
    1930       {
    1931         Double costPredMAD   = m_cMADLinearModel.getMAD();
    1932         Int    qpLowerBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp-2;
    1933         Int    qpUpperBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp+2;
    1934         finalQP = m_cPixelURQQuadraticModel.getQP(m_pcFrameData[m_indexPrevPOCInGOP].m_qp, m_targetBits, m_numOfPixels, costPredMAD);
    1935         finalQP = max(qpLowerBound, min(qpUpperBound, finalQP));
    1936         m_activeUnitLevelOn    = true;
    1937         m_remainingBitsInFrame = m_targetBits;
    1938         m_costAvgbpp           = (m_targetBits/(Double)m_numOfPixels);
    1939       }
    1940 
    1941       m_indexRefFrame++;
    1942     }
    1943     else
    1944     {
    1945       Int bwdQP = m_pcFrameData[m_indexPOCInGOP-1].m_qp;
    1946       Int fwdQP = m_pcFrameData[m_indexPOCInGOP+1].m_qp;
    1947        
    1948       if( (fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP-1].m_qp
    1949         ||(fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP+1].m_qp)
    1950       {
    1951         finalQP = (fwdQP+bwdQP);
    1952       }
    1953       else if(bwdQP != fwdQP)
    1954       {
    1955         finalQP = ((bwdQP+fwdQP+2)>>1);
    1956       }
    1957       else
    1958       {
    1959         finalQP = bwdQP+2;
    1960       }
    1961       m_indexNonRefFrame++;
    1962     }
    1963   }
    1964   else
    1965   {
    1966     Int lastQPminus2 = m_pcFrameData[0].m_qp - 2;
    1967     Int lastQPplus2  = m_pcFrameData[0].m_qp + 2;
    1968 
    1969     for(Int idx = 1; idx <= m_sizeGOP; idx++)
    1970     {
    1971       if(m_pcFrameData[idx].m_isReferenced)
    1972       {
    1973         finalQP += m_pcFrameData[idx].m_qp;
    1974         numofReferenced++;
    1975       }
    1976     }
    1977    
    1978     finalQP = (numofReferenced == 0) ? m_pcFrameData[0].m_qp : ((finalQP + (1<<(numofReferenced>>1)))/numofReferenced);
    1979     finalQP = max( lastQPminus2, min( lastQPplus2, finalQP));
    1980 
    1981     Double costAvgFrameBits = m_remainingBitsInGOP/(Double)m_sizeGOP;
    1982     Int    bufLevel  = m_occupancyVB + m_initialOVB;
    1983 
    1984     if(abs(bufLevel) > costAvgFrameBits)
    1985     {
    1986       if(bufLevel < 0)
    1987       {
    1988         finalQP -= 2;
    1989       }
    1990       else
    1991       {
    1992         finalQP += 2;
    1993       }
    1994     }
    1995     m_indexRefFrame++;
    1996   }
    1997   finalQP = max(MIN_QP, min(MAX_QP, finalQP));
    1998 
    1999   for(Int indexLCU = 0 ; indexLCU < m_numUnitInFrame; indexLCU++)
    2000   {
    2001     m_pcLCUData[indexLCU].m_qp = finalQP;
    2002   }
    2003 
    2004   pcFrameData->m_isReferenced = isReferenced;
    2005   pcFrameData->m_qp           = finalQP;
    2006 
    2007   return finalQP;
    2008 }
    2009 
    2010 Bool  TEncRateCtrl::calculateUnitQP ()
    2011 {
    2012   if(!m_activeUnitLevelOn || m_indexLCU == 0)
    2013   {
    2014     return false;
    2015   }
    2016   Int upperQPBound, lowerQPBound, finalQP;
    2017   Int    colQP        = m_pcLCUData[m_indexLCU].m_qp;
    2018   Double colMAD       = m_pcLCUData[m_indexLCU].m_costMAD;
    2019   Double budgetInUnit = m_pcLCUData[m_indexLCU].m_pixels*m_costAvgbpp;
    2020 
    2021 
    2022   Int targetBitsOccupancy = (Int)(budgetInUnit - (m_occupancyVBInFrame/(m_numUnitInFrame-m_indexUnit)));
    2023   Int targetBitsLeftBudget= (Int)((m_remainingBitsInFrame*m_pcLCUData[m_indexLCU].m_pixels)/(Double)(m_numOfPixels-m_codedPixels));
    2024   Int targetBits = (targetBitsLeftBudget>>1) + (targetBitsOccupancy>>1);
    2025  
    2026 
    2027   if( m_indexLCU >= m_sourceWidthInLCU)
    2028   {
    2029     upperQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) + MAX_DELTA_QP;
    2030     lowerQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) - MAX_DELTA_QP;
    2031   }
    2032   else
    2033   {
    2034     upperQPBound = m_pcLCUData[m_indexLCU-1].m_qp + MAX_DELTA_QP;
    2035     lowerQPBound = m_pcLCUData[m_indexLCU-1].m_qp - MAX_DELTA_QP;
    2036   }
    2037 
    2038   if(targetBits < 0)
    2039   {
    2040     finalQP = m_pcLCUData[m_indexLCU-1].m_qp + 1;
    2041   }
    2042   else
    2043   {
    2044     finalQP = m_cPixelURQQuadraticModel.getQP(colQP, targetBits, m_pcLCUData[m_indexLCU].m_pixels, colMAD);
    2045   }
    2046  
    2047   finalQP = max(lowerQPBound, min(upperQPBound, finalQP));
    2048   m_pcLCUData[m_indexLCU].m_qp = max(MIN_QP, min(MAX_QP, finalQP));
    2049  
    2050   return true;
    2051 }
    2052 
    2053 Void  TEncRateCtrl::updateRCGOPStatus()
    2054 {
    2055   m_remainingBitsInGOP = ((m_currBitrate/m_frameRate)*m_sizeGOP) - m_occupancyVB;
    2056  
    2057   FrameData cFrameData = m_pcFrameData[m_sizeGOP];
    2058   initFrameData();
    2059 
    2060   m_pcFrameData[0]   = cFrameData;
    2061   m_indexGOP++;
    2062   m_indexFrame       = 0;
    2063   m_indexRefFrame    = 0;
    2064   m_indexNonRefFrame = 0;
    2065 }
    2066 
    2067 Void  TEncRateCtrl::updataRCFrameStatus(Int frameBits, SliceType eSliceType)
    2068 {
    2069   FrameData* pcFrameData = &m_pcFrameData[m_indexPOCInGOP];
    2070   Int occupancyBits;
    2071   Double adjustmentBits;
    2072 
    2073   m_remainingBitsInGOP = m_remainingBitsInGOP + ( ((m_currBitrate-m_prevBitrate)/m_frameRate)*(m_sizeGOP-m_indexFrame) ) - frameBits;
    2074   occupancyBits        = (Int)((Double)frameBits - (m_currBitrate/(Double)m_frameRate));
    2075  
    2076   if( (occupancyBits < 0) && (m_initialOVB > 0) )
    2077   {
    2078     adjustmentBits = xAdjustmentBits(occupancyBits, m_initialOVB );
    2079 
    2080     if(m_initialOVB < 0)
    2081     {
    2082       adjustmentBits = m_initialOVB;
    2083       occupancyBits += (Int)adjustmentBits;
    2084       m_initialOVB   =  0;
    2085     }
    2086   }
    2087   else if( (occupancyBits > 0) && (m_initialOVB < 0) )
    2088   {
    2089     adjustmentBits = xAdjustmentBits(m_initialOVB, occupancyBits );
    2090    
    2091     if(occupancyBits < 0)
    2092     {
    2093       adjustmentBits = occupancyBits;
    2094       m_initialOVB  += (Int)adjustmentBits;
    2095       occupancyBits  =  0;
    2096     }
    2097   }
    2098 
    2099   if(m_indexGOP == 0)
    2100   {
    2101     m_initialOVB = occupancyBits;
    2102   }
    2103   else
    2104   {
    2105     m_occupancyVB= m_occupancyVB + occupancyBits;
    2106   }
    2107 
    2108   if(pcFrameData->m_isReferenced)
    2109   {
    2110     m_costRefAvgWeighting  = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costRefAvgWeighting)/8.0);
    2111 
    2112     if(m_indexFrame == 0)
    2113     {
    2114       m_initialTBL = m_targetBufLevel  = (frameBits - (m_currBitrate/m_frameRate));
    2115     }
    2116     else
    2117     {
    2118       Int distance = (m_costNonRefAvgWeighting == 0) ? 0 : 1;
    2119       m_targetBufLevel =  m_targetBufLevel
    2120                             - (m_initialTBL/(m_refFrameNum-1))
    2121                             + (Int)((m_costRefAvgWeighting*(distance+1)*m_currBitrate)/(m_frameRate*(m_costRefAvgWeighting+(m_costNonRefAvgWeighting*distance))))
    2122                             - (m_currBitrate/m_frameRate);
    2123     }
    2124 
    2125     if(m_cMADLinearModel.IsUpdateAvailable())
    2126     {
    2127       m_cMADLinearModel.updateMADLiearModel();
    2128     }
    2129 
    2130     if(eSliceType != I_SLICE &&
    2131        m_cPixelURQQuadraticModel.checkUpdateAvailable(pcFrameData->m_qp))
    2132     {
    2133       m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(pcFrameData->m_qp, pcFrameData->m_bits, m_numOfPixels, pcFrameData->m_costMAD);
    2134     }
    2135   }
    2136   else
    2137   {
    2138     m_costNonRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costNonRefAvgWeighting)/8.0);
    2139   }
    2140 
    2141   m_indexFrame++;
    2142   m_indexLCU             = 0;
    2143   m_indexUnit            = 0;
    2144   m_occupancyVBInFrame   = 0;
    2145   m_remainingBitsInFrame = 0;
    2146   m_codedPixels          = 0;
    2147   m_activeUnitLevelOn    = false;
    2148   m_costAvgbpp           = 0.0;
    2149 }
    2150 Void  TEncRateCtrl::updataRCUnitStatus ()
    2151 {
    2152   if(!m_activeUnitLevelOn || m_indexLCU == 0)
    2153   {
    2154     return;
    2155   }
    2156 
    2157   m_codedPixels  += m_pcLCUData[m_indexLCU-1].m_pixels;
    2158   m_remainingBitsInFrame = m_remainingBitsInFrame - m_pcLCUData[m_indexLCU-1].m_bits;
    2159   m_occupancyVBInFrame   = (Int)(m_occupancyVBInFrame + m_pcLCUData[m_indexLCU-1].m_bits - m_pcLCUData[m_indexLCU-1].m_pixels*m_costAvgbpp);
    2160 
    2161   if( m_cPixelURQQuadraticModel.checkUpdateAvailable(m_pcLCUData[m_indexLCU-1].m_qp) )
    2162   {
    2163     m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(m_pcLCUData[m_indexLCU-1].m_qp, m_pcLCUData[m_indexLCU-1].m_bits, m_pcLCUData[m_indexLCU-1].m_pixels, m_pcLCUData[m_indexLCU-1].m_costMAD);
    2164   }
    2165 
    2166   m_indexUnit++;
    2167 }
    2168 
    2169 Void  TEncRateCtrl::updateFrameData(UInt64 actualFrameBits)
    2170 {
    2171   Double costMAD = 0.0;
    2172  
    2173   for(Int i = 0; i < m_numUnitInFrame; i++)
    2174   {
    2175     costMAD    += m_pcLCUData[i].m_costMAD;
    2176   }
    2177  
    2178   m_pcFrameData[m_indexPOCInGOP].m_costMAD = (costMAD/(Double)m_numUnitInFrame);
    2179   m_pcFrameData[m_indexPOCInGOP].m_bits    = (Int)actualFrameBits;
    2180  
    2181   if(m_pcFrameData[m_indexPOCInGOP].m_isReferenced)
    2182   {
    2183     m_indexPrevPOCInGOP = m_indexPOCInGOP;
    2184     m_cMADLinearModel.updateMADHistory(m_pcFrameData[m_indexPOCInGOP].m_costMAD);
    2185   }
    2186 }
    2187 
    2188 Void  TEncRateCtrl::updateLCUData(TComDataCU* pcCU, UInt64 actualLCUBits, Int qp)
    2189 {
    2190   Int     x, y;
    2191   Double  costMAD = 0.0;
    2192 
    2193   Pel*  pOrg   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    2194   Pel*  pRec   = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
    2195   Int   stride = pcCU->getPic()->getStride();
    2196 
    2197   Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
    2198   Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
    2199 
    2200   for( y = 0; y < height; y++ )
    2201   {
    2202     for( x = 0; x < width; x++ )
    2203     {
    2204       costMAD += abs( pOrg[x] - pRec[x] );
    2205     }
    2206     pOrg += stride;
    2207     pRec += stride;
    2208   }
    2209   m_pcLCUData[m_indexLCU  ].m_qp      = qp;
    2210   m_pcLCUData[m_indexLCU  ].m_costMAD = (costMAD /(Double)(width*height));
    2211   m_pcLCUData[m_indexLCU++].m_bits    = (Int)actualLCUBits;
    2212 }
    2213 
    2214 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
    2215 {
    2216   Double adjustment  = ADJUSTMENT_FACTOR*reductionBits;
    2217   reductionBits     -= (Int)adjustment;
    2218   compensationBits  += (Int)adjustment;
    2219 
    2220   return adjustment;
    2221 }
    2222 
    2223 #endif
    2224 
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.h

    r313 r540  
    5555//! \{
    5656
    57 #if RATE_CONTROL_LAMBDA_DOMAIN
    5857#include "../TLibEncoder/TEncCfg.h"
    5958#include <list>
     
    6564const Double g_RCWeightPicTargetBitInGOP    = 0.9;
    6665const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP;
    67 #if M0036_RC_IMPROVEMENT
    6866const Int g_RCIterationNum = 20;
    6967const Double g_RCWeightHistoryLambda = 0.5;
     
    7472const Double g_RCBetaMinValue  = -3.0;
    7573const Double g_RCBetaMaxValue  = -0.1;
    76 #endif
    77 
    78 #if RATE_CONTROL_INTRA
     74
    7975#define ALPHA     6.7542;
    8076#define BETA1     1.2517
    8177#define BETA2     1.7860
    82 #endif
    8378
    8479struct TRCLCU
     
    8883  Int m_targetBits;
    8984  Double m_lambda;
    90 #if M0036_RC_IMPROVEMENT
    9185  Double m_bitWeight;
    92 #else
    93   Double m_MAD;
    94 #endif
    9586  Int m_numberOfPixel;
    96 #if RATE_CONTROL_INTRA
    9787  Double m_costIntra;
    9888  Int m_targetBitsLeft;
    99 #endif
    10089};
    10190
     
    113102
    114103public:
    115 #if M0036_RC_IMPROVEMENT
    116104  Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit );
    117 #else
    118   Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );
    119 #endif
    120105  Void destroy();
    121106  Void initBitsRatio( Int bitsRatio[] );
     
    124109  Void initLCUPara( TRCParameter** LCUPara = NULL );    // NULL to initial with default value
    125110  Void updateAfterPic ( Int bits );
    126 #if !RATE_CONTROL_INTRA
    127   Int  getRefineBitsForIntra( Int orgBits );
    128 #endif
    129 #if M0036_RC_IMPROVEMENT
    130111  Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB );
    131 #endif
    132112
    133113public:
     
    167147  Double getBetaUpdate()                { return m_betaUpdate; }
    168148
    169 #if M0036_RC_IMPROVEMENT
    170149  Int    getAdaptiveBits()              { return m_adaptiveBit;  }
    171150  Double getLastLambda()                { return m_lastLambda;   }
    172151  Void   setLastLambda( Double lamdba ) { m_lastLambda = lamdba; }
    173 #endif
    174152
    175153private:
     
    200178  Bool m_useLCUSeparateModel;
    201179
    202 #if M0036_RC_IMPROVEMENT
    203180  Int m_adaptiveBit;
    204181  Double m_lastLambda;
    205 #endif
    206182};
    207183
     
    219195private:
    220196  Int  xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize );
    221 #if M0036_RC_IMPROVEMENT
    222197  Void   xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
    223198  Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
    224 #endif
    225199
    226200public:
     
    251225  Void destroy();
    252226
    253 #if !RATE_CONTROL_INTRA
    254   Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
    255 #endif
    256227  Int    estimatePicQP    ( Double lambda, list<TEncRCPic*>& listPreviousPictures );
    257 #if RATE_CONTROL_INTRA
    258228  Int    getRefineBitsForIntra(Int orgBits);
    259229  Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel);
     
    264234  Double getLCUTargetBpp(SliceType eSliceType);
    265235  Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP);
    266 #else
    267   Double getLCUTargetBpp();
    268 #endif
    269236  Double getLCUEstLambda( Double bpp );
    270237  Int    getLCUEstQP( Double lambda, Int clipPicQP );
    271238
    272239  Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true );
    273 #if M0036_RC_IMPROVEMENT
    274 #if RATE_CONTROL_INTRA
    275240  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType);
    276 #else
    277   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );
    278 #endif
    279 #else
    280   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );
    281 #endif
    282241
    283242  Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
    284 #if !M0036_RC_IMPROVEMENT
    285   Double getEffectivePercentage();
    286 #endif
    287243  Double calAverageQP();
    288244  Double calAverageLambda();
     
    300256  Int  getNumberOfLCU()                                   { return m_numberOfLCU; }
    301257  Int  getTargetBits()                                    { return m_targetBits; }
    302 #if !RATE_CONTROL_INTRA
    303   Void setTargetBits( Int bits )                          { m_targetBits = bits; }
    304 #endif
    305258  Int  getEstHeaderBits()                                 { return m_estHeaderBits; }
    306259  Int  getLCULeft()                                       { return m_LCULeft; }
     
    312265  TRCLCU& getLCU( Int LCUIdx )                            { return m_LCUs[LCUIdx]; }
    313266  Int  getPicActualHeaderBits()                           { return m_picActualHeaderBits; }
    314 #if !M0036_RC_IMPROVEMENT
    315   Double getTotalMAD()                                    { return m_totalMAD; }
    316   Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
    317 #endif
    318 #if RATE_CONTROL_INTRA
    319267  Void setTargetBits( Int bits )                          { m_targetBits = bits; m_bitsLeft = bits;}
    320268  Void setTotalIntraCost(Double cost)                     { m_totalCostIntra = cost; }
    321269  Void getLCUInitTargetBits();
    322 #endif
    323270
    324271  Int  getPicActualBits()                                 { return m_picActualBits; }
     
    348295  TRCLCU* m_LCUs;
    349296  Int m_picActualHeaderBits;    // only SH and potential APS
    350 #if !M0036_RC_IMPROVEMENT
    351   Double m_totalMAD;
    352 #endif
    353 #if RATE_CONTROL_INTRA
    354297  Double m_totalCostIntra;
    355298  Double m_remainingCostIntra;
    356 #endif
    357299  Int m_picActualBits;          // the whole picture, including header
    358300  Int m_picQP;                  // in integer form
    359301  Double m_picLambda;
    360 #if !M0036_RC_IMPROVEMENT
    361   TEncRCPic* m_lastPicture;
    362 #endif
    363302};
    364303
     
    370309
    371310public:
    372 #if M0036_RC_IMPROVEMENT
    373311  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
    374 #else
    375   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
    376 #endif
    377312  Void destroy();
    378313  Void initRCPic( Int frameLevel );
     
    396331};
    397332
    398 #else
    399 
    400 // ====================================================================================================================
    401 // Class definition
    402 // ====================================================================================================================
    403 #define MAX_DELTA_QP    2
    404 #define MAX_CUDQP_DEPTH 0
    405 
    406 typedef struct FrameData
    407 {
    408   Bool       m_isReferenced;
    409   Int        m_qp;
    410   Int        m_bits;
    411   Double     m_costMAD;
    412 }FrameData;
    413 
    414 typedef struct LCUData
    415 {
    416   Int     m_qp;                ///<  coded QP
    417   Int     m_bits;              ///<  actually generated bits
    418   Int     m_pixels;            ///<  number of pixels for a unit
    419   Int     m_widthInPixel;      ///<  number of pixels for width
    420   Int     m_heightInPixel;     ///<  number of pixels for height
    421   Double  m_costMAD;           ///<  texture complexity for a unit
    422 }LCUData;
    423 
    424 class MADLinearModel
    425 {
    426 private:
    427   Bool   m_activeOn;
    428   Double m_paramY1;
    429   Double m_paramY2;
    430   Double m_costMADs[3];
    431 
    432 public:
    433   MADLinearModel ()   {};
    434   ~MADLinearModel()   {};
    435  
    436   Void    initMADLinearModel      ();
    437   Double  getMAD                  ();
    438   Void    updateMADLiearModel     ();
    439   Void    updateMADHistory        (Double costMAD);
    440   Bool    IsUpdateAvailable       ()              { return m_activeOn; }
    441 };
    442 
    443 class PixelBaseURQQuadraticModel
    444 {
    445 private:
    446   Double m_paramHighX1;
    447   Double m_paramHighX2;
    448   Double m_paramLowX1;
    449   Double m_paramLowX2;
    450 public:
    451   PixelBaseURQQuadraticModel () {};
    452   ~PixelBaseURQQuadraticModel() {};
    453 
    454   Void    initPixelBaseQuadraticModel       ();
    455   Int     getQP                             (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD);
    456   Void    updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD);
    457   Bool    checkUpdateAvailable              (Int qpReference );
    458   Double  xConvertQP2QStep                  (Int qp );
    459   Int     xConvertQStep2QP                  (Double qStep );
    460 };
    461 
    462 class TEncRateCtrl
    463 {
    464 private:
    465   Bool            m_isLowdelay;
    466   Int             m_prevBitrate;
    467   Int             m_currBitrate;
    468   Int             m_frameRate;
    469   Int             m_refFrameNum;
    470   Int             m_nonRefFrameNum;
    471   Int             m_numOfPixels;
    472   Int             m_sourceWidthInLCU;
    473   Int             m_sourceHeightInLCU;     
    474   Int             m_sizeGOP;
    475   Int             m_indexGOP;
    476   Int             m_indexFrame;
    477   Int             m_indexLCU;
    478   Int             m_indexUnit;
    479   Int             m_indexRefFrame;
    480   Int             m_indexNonRefFrame;
    481   Int             m_indexPOCInGOP;
    482   Int             m_indexPrevPOCInGOP;
    483   Int             m_occupancyVB;
    484   Int             m_initialOVB;
    485   Int             m_targetBufLevel;
    486   Int             m_initialTBL;
    487   Int             m_remainingBitsInGOP;
    488   Int             m_remainingBitsInFrame;
    489   Int             m_occupancyVBInFrame;
    490   Int             m_targetBits;
    491   Int             m_numUnitInFrame;
    492   Int             m_codedPixels;
    493   Bool            m_activeUnitLevelOn;
    494   Double          m_costNonRefAvgWeighting;
    495   Double          m_costRefAvgWeighting;
    496   Double          m_costAvgbpp;         
    497  
    498   FrameData*      m_pcFrameData;
    499   LCUData*        m_pcLCUData;
    500 
    501   MADLinearModel              m_cMADLinearModel;
    502   PixelBaseURQQuadraticModel  m_cPixelURQQuadraticModel;
    503  
    504 public:
    505   TEncRateCtrl         () {};
    506   virtual ~TEncRateCtrl() {};
    507 
    508   Void          create                (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight);
    509   Void          destroy               ();
    510 
    511   Void          initFrameData         (Int qp = 0);
    512   Void          initUnitData          (Int qp = 0);
    513   Int           getFrameQP            (Bool isReferenced, Int POC);
    514   Bool          calculateUnitQP       ();
    515   Int           getUnitQP             ()                                          { return m_pcLCUData[m_indexLCU].m_qp;  }
    516   Void          updateRCGOPStatus     ();
    517   Void          updataRCFrameStatus   (Int frameBits, SliceType eSliceType);
    518   Void          updataRCUnitStatus    ();
    519   Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
    520   Void          updateFrameData       (UInt64 actualFrameBits);
    521   Double        xAdjustmentBits       (Int& reductionBits, Int& compensationBits);
    522   Int           getGOPId              ()                                          { return m_indexFrame; }
    523 };
    524333#endif
    525334
    526 #endif
    527 
    528 
     335
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r494 r540  
    4545//! \{
    4646
     47
     48#if HM_CLEANUP_SAO
     49
     50/** rounding with IBDI
     51 * \param  x
     52 */
     53inline Double xRoundIbdi2(Int bitDepth, Double x)
     54{
     55  return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));
     56}
     57
     58inline Double xRoundIbdi(Int bitDepth, Double x)
     59{
     60  return (bitDepth > 8 ? xRoundIbdi2(bitDepth, (x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     61}
     62
     63
     64TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
     65{
     66  m_pppcRDSbacCoder = NULL;           
     67  m_pcRDGoOnSbacCoder = NULL;
     68  m_pppcBinCoderCABAC = NULL;   
     69  m_statData = NULL;
     70#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     71  m_preDBFstatData = NULL;
     72#endif
     73}
     74
     75TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
     76{
     77  destroyEncData();
     78}
     79
     80#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     81Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed)
     82#else
     83Void TEncSampleAdaptiveOffset::createEncData()
     84#endif
     85{
     86
     87  //cabac coder for RDO
     88  m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS];
     89  m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS];
     90
     91  for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++)
     92  {
     93    m_pppcRDSbacCoder[cs] = new TEncSbac;
     94    m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter;
     95    m_pppcRDSbacCoder   [cs]->init( m_pppcBinCoderCABAC [cs] );
     96  }
     97
     98
     99  //statistics
     100  m_statData = new SAOStatData**[m_numCTUsPic];
     101  for(Int i=0; i< m_numCTUsPic; i++)
     102  {
     103    m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
     104    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     105    {
     106      m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     107    }
     108  }
     109#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     110  if(isPreDBFSamplesUsed)
     111  {
     112    m_preDBFstatData = new SAOStatData**[m_numCTUsPic];
     113    for(Int i=0; i< m_numCTUsPic; i++)
     114    {
     115      m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
     116      for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     117      {
     118        m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     119      }
     120    }
     121
     122  }
     123#endif
     124
     125#if SAO_ENCODING_CHOICE
     126  ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate));
     127#endif
     128
     129  for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     130  {
     131    m_skipLinesR[SAO_Y ][typeIdc]= 5;
     132    m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     133
     134    m_skipLinesB[SAO_Y ][typeIdc]= 4;
     135    m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     136
     137#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     138    if(isPreDBFSamplesUsed)
     139    {
     140      switch(typeIdc)
     141      {
     142      case SAO_TYPE_EO_0:
     143        {
     144          m_skipLinesR[SAO_Y ][typeIdc]= 5;
     145          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     146
     147          m_skipLinesB[SAO_Y ][typeIdc]= 3;
     148          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     149        }
     150        break;
     151      case SAO_TYPE_EO_90:
     152        {
     153          m_skipLinesR[SAO_Y ][typeIdc]= 4;
     154          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
     155
     156          m_skipLinesB[SAO_Y ][typeIdc]= 4;
     157          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     158        }
     159        break;
     160      case SAO_TYPE_EO_135:
     161      case SAO_TYPE_EO_45:
     162        {
     163          m_skipLinesR[SAO_Y ][typeIdc]= 5;
     164          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     165
     166          m_skipLinesB[SAO_Y ][typeIdc]= 4;
     167          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     168        }
     169        break;
     170      case SAO_TYPE_BO:
     171        {
     172          m_skipLinesR[SAO_Y ][typeIdc]= 4;
     173          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
     174
     175          m_skipLinesB[SAO_Y ][typeIdc]= 3;
     176          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     177        }
     178        break;
     179      default:
     180        {
     181          printf("Not a supported type");
     182          assert(0);
     183          exit(-1);
     184        }
     185      }
     186    }
     187#endif   
     188  }
     189
     190}
     191
     192Void TEncSampleAdaptiveOffset::destroyEncData()
     193{
     194  if(m_pppcRDSbacCoder != NULL)
     195  {
     196    for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ )
     197    {
     198      delete m_pppcRDSbacCoder[cs];
     199    }
     200    delete[] m_pppcRDSbacCoder; m_pppcRDSbacCoder = NULL;
     201  }
     202
     203  if(m_pppcBinCoderCABAC != NULL)
     204  {
     205    for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ )
     206    {
     207      delete m_pppcBinCoderCABAC[cs];
     208    }
     209    delete[] m_pppcBinCoderCABAC; m_pppcBinCoderCABAC = NULL;
     210  }
     211
     212  if(m_statData != NULL)
     213  {
     214    for(Int i=0; i< m_numCTUsPic; i++)
     215    {
     216      for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     217      {
     218        delete[] m_statData[i][compIdx];
     219      }
     220      delete[] m_statData[i];
     221    }
     222    delete[] m_statData; m_statData = NULL;
     223  }
     224#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     225  if(m_preDBFstatData != NULL)
     226  {
     227    for(Int i=0; i< m_numCTUsPic; i++)
     228    {
     229      for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     230      {
     231        delete[] m_preDBFstatData[i][compIdx];
     232      }
     233      delete[] m_preDBFstatData[i];
     234    }
     235    delete[] m_preDBFstatData; m_preDBFstatData = NULL;
     236  }
     237
     238#endif
     239}
     240
     241Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice)
     242{
     243  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     244  m_pcRDGoOnSbacCoder->setSlice(pcSlice);
     245  m_pcRDGoOnSbacCoder->resetEntropy();
     246  m_pcRDGoOnSbacCoder->resetBits();
     247
     248  m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[SAO_CABACSTATE_PIC_INIT]);
     249}
     250
     251
     252
     253Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
     254#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     255                                         , Bool isPreDBFSamplesUsed
     256#endif
     257                                          )
     258{
     259  TComPicYuv* orgYuv= pPic->getPicYuvOrg();
     260  TComPicYuv* resYuv= pPic->getPicYuvRec();
     261  m_labmda[SAO_Y]= lambdas[0]; m_labmda[SAO_Cb]= lambdas[1]; m_labmda[SAO_Cr]= lambdas[2];
     262  TComPicYuv* srcYuv = m_tempPicYuv;
     263  resYuv->copyToPic(srcYuv);
     264  srcYuv->setBorderExtension(false);
     265  srcYuv->extendPicBorder();
     266
     267  //collect statistics
     268  getStatistics(m_statData, orgYuv, srcYuv, pPic);
     269#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     270  if(isPreDBFSamplesUsed)
     271  {
     272    addPreDBFStatistics(m_statData);
     273  }
     274#endif
     275  //slice on/off
     276  decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth());
     277
     278  //block on/off
     279  SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters
     280  decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam());
     281  delete[] reconParams;
     282
     283}
     284
     285#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     286Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic)
     287{
     288  getStatistics(m_preDBFstatData, pPic->getPicYuvOrg(), pPic->getPicYuvRec(), pPic, true);
     289}
     290
     291Void TEncSampleAdaptiveOffset::addPreDBFStatistics(SAOStatData*** blkStats)
     292{
     293  for(Int n=0; n< m_numCTUsPic; n++)
     294  {
     295    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     296    {
     297      for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     298      {
     299        blkStats[n][compIdx][typeIdc] += m_preDBFstatData[n][compIdx][typeIdc];
     300      }
     301    }
     302  }
     303}
     304
     305#endif
     306
     307Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic
     308#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     309                          , Bool isCalculatePreDeblockSamples
     310#endif
     311                          )
     312{
     313  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
     314
     315  for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
     316  {
     317    Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
     318    Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     319    Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
     320    Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
     321
     322    pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     323
     324    //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities.
     325    //For simplicity, here only picture boundaries are considered.
     326
     327    isRightAvail      = (xPos + m_maxCUWidth  < m_picWidth );
     328    isBelowAvail      = (yPos + m_maxCUHeight < m_picHeight);
     329    isBelowRightAvail = (isRightAvail && isBelowAvail);
     330    isBelowLeftAvail  = ((xPos > 0) && (isBelowAvail));
     331    isAboveRightAvail = ((yPos > 0) && (isRightAvail));
     332
     333    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     334    {
     335      Bool isLuma     = (compIdx == SAO_Y);
     336      Int  formatShift= isLuma?0:1;
     337
     338      Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
     339      Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
     340
     341      Int  orgStride  = isLuma?orgYuv->getStride():orgYuv->getCStride();
     342      Pel* orgBlk     = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift);
     343
     344      getBlkStats(compIdx, blkStats[ctu][compIdx] 
     345                , srcBlk, orgBlk, srcStride, orgStride, (width  >> formatShift), (height >> formatShift)
     346                , isLeftAvail,  isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail
     347#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     348                , isCalculatePreDeblockSamples
     349#endif
     350                );
     351
     352    }
     353  }
     354}
     355
     356Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer)
     357{
     358  //decide sliceEnabled[compIdx]
     359  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     360  {
     361    // reset flags & counters
     362    sliceEnabled[compIdx] = true;
     363
     364#if SAO_ENCODING_CHOICE
     365#if SAO_ENCODING_CHOICE_CHROMA
     366    // decide slice-level on/off based on previous results
     367    if( (picTempLayer > 0)
     368      && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) )
     369    {
     370      sliceEnabled[compIdx] = false;
     371    }
     372#else
     373    // decide slice-level on/off based on previous results
     374    if( (picTempLayer > 0)
     375      && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) )
     376    {
     377      sliceEnabled[compIdx] = false;
     378    }
     379#endif
     380#endif
     381  }
     382}
     383
     384Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData)
     385{
     386  Int64 dist=0;
     387  Int inputBitDepth    = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ;
     388  Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8);
     389
     390  switch(typeIdc)
     391  {
     392    case SAO_TYPE_EO_0:
     393    case SAO_TYPE_EO_90:
     394    case SAO_TYPE_EO_135:
     395    case SAO_TYPE_EO_45:
     396      {
     397        for (Int offsetIdx=0; offsetIdx<NUM_SAO_EO_CLASSES; offsetIdx++)
     398        {
     399          dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift);
     400        }       
     401      }
     402      break;
     403    case SAO_TYPE_BO:
     404      {
     405        for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++)
     406        {
     407          Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ;
     408          dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift);
     409        }
     410      }
     411      break;
     412    default:
     413      {
     414        printf("Not a supported type");
     415        assert(0);
     416        exit(-1);
     417      }
     418  }
     419
     420  return dist;
     421}
     422
     423inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift)
     424{
     425  return (( count*offset*offset-diffSum*offset*2 ) >> shift);
     426}
     427
     428
     429inline Int TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh )
     430{
     431  Int iterOffset, tempOffset;
     432  Int64 tempDist, tempRate;
     433  Double tempCost, tempMinCost;
     434  Int offsetOutput = 0;
     435  iterOffset = offsetInput;
     436  // 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.
     437  tempMinCost = lambda;
     438  while (iterOffset != 0)
     439  {
     440    // Calculate the bits required for signaling the offset
     441    tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
     442    if (abs((Int)iterOffset)==offsetTh) //inclusive
     443    { 
     444      tempRate --;
     445    }
     446    // Do the dequantization before distortion calculation
     447    tempOffset  = iterOffset << bitIncrease;
     448    tempDist    = estSaoDist( count, tempOffset, diffSum, shift);
     449    tempCost    = ((Double)tempDist + lambda * (Double) tempRate);
     450    if(tempCost < tempMinCost)
     451    {
     452      tempMinCost = tempCost;
     453      offsetOutput = iterOffset;
     454      bestDist = tempDist;
     455      bestCost = tempCost;
     456    }
     457    iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1);
     458  }
     459  return offsetOutput;
     460}
     461
     462
     463Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo)
     464{
     465  Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC;
     466  Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
     467  Int offsetTh = g_saoMaxOffsetQVal[compIdx];  //inclusive
     468
     469  ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     470
     471  //derive initial offsets
     472  Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES);
     473  for(Int classIdx=0; classIdx< numClasses; classIdx++)
     474  {
     475    if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN)  )
     476    {
     477      continue; //offset will be zero
     478    }
     479
     480    if(statData.count[classIdx] == 0)
     481    {
     482      continue; //offset will be zero
     483    }
     484
     485    quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8))
     486                                                                  /
     487                                                          (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx])
     488                                               );
     489    quantOffsets[classIdx] = Clip3(-offsetTh, offsetTh, quantOffsets[classIdx]);
     490  }
     491
     492  // adjust offsets
     493  switch(typeIdc)
     494  {
     495    case SAO_TYPE_EO_0:
     496    case SAO_TYPE_EO_90:
     497    case SAO_TYPE_EO_135:
     498    case SAO_TYPE_EO_45:
     499      {
     500        Int64 classDist;
     501        Double classCost;
     502        for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 
     503        {         
     504          if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     505          if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     506          if(classIdx==SAO_CLASS_EO_HALF_PEAK   && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0;
     507          if(classIdx==SAO_CLASS_EO_FULL_PEAK   && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0;
     508
     509          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     510          {
     511            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh );
     512          }
     513        }
     514     
     515        typeAuxInfo =0;
     516      }
     517      break;
     518    case SAO_TYPE_BO:
     519      {
     520        Int64  distBOClasses[NUM_SAO_BO_CLASSES];
     521        Double costBOClasses[NUM_SAO_BO_CLASSES];
     522        ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES);
     523        for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++)
     524        {         
     525          costBOClasses[classIdx]= m_labmda[compIdx];
     526          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     527          {
     528            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh );
     529          }
     530        }
     531
     532        //decide the starting band index
     533        Double minCost = MAX_DOUBLE, cost;
     534        for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++)
     535        {
     536          cost  = costBOClasses[band  ];
     537          cost += costBOClasses[band+1];
     538          cost += costBOClasses[band+2];
     539          cost += costBOClasses[band+3];
     540
     541          if(cost < minCost)
     542          {
     543            minCost = cost;
     544            typeAuxInfo = band;
     545          }
     546        }
     547        //clear those unused classes
     548        Int clearQuantOffset[NUM_SAO_BO_CLASSES];
     549        ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES);
     550        for(Int i=0; i< 4; i++)
     551        {
     552          Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES;
     553          clearQuantOffset[band] = quantOffsets[band];
     554        }
     555        ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES);       
     556      }
     557      break;
     558    default:
     559      {
     560        printf("Not a supported type");
     561        assert(0);
     562        exit(-1);
     563      }
     564
     565  }
     566
     567
     568}
     569
     570
     571Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     572{
     573  Double minCost, cost;
     574  Int rate, minRate;
     575  Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS];
     576  SAOOffset testOffset[NUM_SAO_COMPONENTS];
     577  Int compIdx;
     578  Int invQuantOffset[MAX_NUM_SAO_CLASSES];
     579
     580  modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0;
     581
     582  //pre-encode merge flags
     583  modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
     584  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     585  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true);
     586  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     587
     588  //------ luma --------//
     589  compIdx = SAO_Y;
     590  //"off" case as initial cost
     591  modeParam[compIdx].modeIdc = SAO_MODE_OFF;
     592  m_pcRDGoOnSbacCoder->resetBits();
     593  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
     594  minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     595  modeDist[compIdx] = 0;
     596  minCost= m_labmda[compIdx]*((Double)minRate);
     597  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     598  if(sliceEnabled[compIdx])
     599  {
     600    for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     601    {
     602      testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     603      testOffset[compIdx].typeIdc = typeIdc;
     604
     605      //derive coded offset
     606      deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     607
     608      //inversed quantized offsets
     609      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     610
     611      //get distortion
     612      dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     613
     614      //get rate
     615      m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     616      m_pcRDGoOnSbacCoder->resetBits();
     617      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
     618      rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     619      cost = (Double)dist[compIdx] + m_labmda[compIdx]*((Double)rate);
     620      if(cost < minCost)
     621      {
     622        minCost = cost;
     623        minRate = rate;
     624        modeDist[compIdx] = dist[compIdx];
     625        modeParam[compIdx]= testOffset[compIdx];
     626        m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     627      }
     628    }
     629  }
     630  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     631  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     632
     633  //------ chroma --------//
     634  assert(m_labmda[SAO_Cb] == m_labmda[SAO_Cr]);
     635  Double chromaLambda = m_labmda[SAO_Cb];
     636  //"off" case as initial cost
     637  m_pcRDGoOnSbacCoder->resetBits();
     638  modeParam[SAO_Cb].modeIdc = SAO_MODE_OFF;
     639  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, modeParam[SAO_Cb], sliceEnabled[SAO_Cb]);
     640  modeParam[SAO_Cr].modeIdc = SAO_MODE_OFF;
     641  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, modeParam[SAO_Cr], sliceEnabled[SAO_Cr]);
     642  minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     643  modeDist[SAO_Cb] = modeDist[SAO_Cr]= 0;
     644  minCost= chromaLambda*((Double)minRate);
     645
     646  //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function
     647
     648  for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     649  {
     650    for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     651    {
     652      if(!sliceEnabled[compIdx])
     653      {
     654        testOffset[compIdx].modeIdc = SAO_MODE_OFF;
     655        dist[compIdx]= 0;
     656        continue;
     657      }
     658      testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     659      testOffset[compIdx].typeIdc = typeIdc;
     660
     661      //derive offset & get distortion
     662      deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     663      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     664      dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     665    }
     666
     667    //get rate
     668    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     669    m_pcRDGoOnSbacCoder->resetBits();
     670    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, testOffset[SAO_Cb], sliceEnabled[SAO_Cb]);
     671    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, testOffset[SAO_Cr], sliceEnabled[SAO_Cr]);
     672    rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     673
     674    cost = (Double)(dist[SAO_Cb]+ dist[SAO_Cr]) + chromaLambda*((Double)rate);
     675    if(cost < minCost)
     676    {
     677      minCost = cost;
     678      minRate = rate;
     679      modeDist[SAO_Cb] = dist[SAO_Cb];
     680      modeDist[SAO_Cr] = dist[SAO_Cr];
     681      modeParam[SAO_Cb]= testOffset[SAO_Cb];
     682      modeParam[SAO_Cr]= testOffset[SAO_Cr];
     683    }
     684  }
     685
     686
     687  //----- re-gen rate & normalized cost----//
     688  modeNormCost  = (Double)modeDist[SAO_Y]/m_labmda[SAO_Y];
     689  modeNormCost += (Double)(modeDist[SAO_Cb]+ modeDist[SAO_Cr])/chromaLambda;
     690  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     691  m_pcRDGoOnSbacCoder->resetBits();
     692  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
     693  modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     694
     695}
     696
     697Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     698{
     699  Int mergeListSize = (Int)mergeList.size();
     700  modeNormCost = MAX_DOUBLE;
     701
     702  Double cost;
     703  SAOBlkParam testBlkParam;
     704
     705  for(Int mergeType=0; mergeType< mergeListSize; mergeType++)
     706  {
     707    if(mergeList[mergeType] == NULL)
     708    {
     709      continue;
     710    }
     711
     712    testBlkParam = *(mergeList[mergeType]);
     713    //normalized distortion
     714    Double normDist=0;
     715    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     716    {
     717      testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE;
     718      testBlkParam[compIdx].typeIdc = mergeType;
     719
     720      SAOOffset& mergedOffsetParam = (*(mergeList[mergeType]))[compIdx];
     721
     722      if( mergedOffsetParam.modeIdc != SAO_MODE_OFF)
     723      {
     724        //offsets have been reconstructed. Don't call inversed quantization function.
     725        normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))
     726                       /m_labmda[compIdx]
     727                    );
     728      }
     729
     730    }
     731
     732    //rate
     733    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     734    m_pcRDGoOnSbacCoder->resetBits();
     735    m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
     736    Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     737
     738    cost = normDist+(Double)rate;
     739
     740    if(cost < modeNormCost)
     741    {
     742      modeNormCost = cost;
     743      modeParam    = testBlkParam;
     744      m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     745    }
     746  }
     747
     748  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     749
     750
     751}
     752
     753Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams)
     754{
     755  Bool isAllBlksDisabled = false;
     756  if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr])
     757  {
     758    isAllBlksDisabled = true;
     759  }
     760
     761  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]);
     762
     763  SAOBlkParam modeParam;
     764  Double minCost, modeCost;
     765
     766  for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     767  {
     768    if(isAllBlksDisabled)
     769    {
     770      codedParams[ctu].reset();
     771      continue;
     772    }
     773
     774    m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_CUR ]);
     775
     776    //get merge list
     777    std::vector<SAOBlkParam*> mergeList;
     778    getMergeList(pic, ctu, reconParams, mergeList);
     779
     780    minCost = MAX_DOUBLE;
     781    for(Int mode=0; mode < NUM_SAO_MODES; mode++)
     782    {
     783      switch(mode)
     784      {
     785      case SAO_MODE_OFF:
     786        {
     787          continue; //not necessary, since all-off case will be tested in SAO_MODE_NEW case.
     788        }
     789        break;
     790      case SAO_MODE_NEW:
     791        {
     792          deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     793
     794        }
     795        break;
     796      case SAO_MODE_MERGE:
     797        {
     798          deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     799        }
     800        break;
     801      default:
     802        {
     803          printf("Not a supported SAO mode\n");
     804          assert(0);
     805          exit(-1);
     806        }
     807      }
     808
     809      if(modeCost < minCost)
     810      {
     811        minCost = modeCost;
     812        codedParams[ctu] = modeParam;
     813        m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
     814
     815      }
     816    } //mode
     817    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
     818
     819    //apply reconstructed offsets
     820    reconParams[ctu] = codedParams[ctu];
     821    reconstructBlkSAOParam(reconParams[ctu], mergeList);
     822    offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic);
     823  } //ctu
     824
     825#if SAO_ENCODING_CHOICE
     826  Int picTempLayer = pic->getSlice(0)->getDepth();
     827  Int numLcusForSAOOff[NUM_SAO_COMPONENTS];
     828  numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0;
     829
     830  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     831  {
     832    for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     833    {
     834      if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF)
     835      {
     836        numLcusForSAOOff[compIdx]++;
     837      }
     838    }
     839  }
     840#if SAO_ENCODING_CHOICE_CHROMA
     841  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     842  {
     843    m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic;
     844  }
     845#else
     846  if (picTempLayer == 0)
     847  {
     848    m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3);
     849  }
     850#endif                                             
     851#endif
     852}
     853
     854
     855Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 
     856                        , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height
     857                        , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     858#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     859                        , Bool isCalculatePreDeblockSamples
     860#endif
     861                        )
     862{
     863  if(m_lineBufWidth != m_maxCUWidth)
     864  {
     865    m_lineBufWidth = m_maxCUWidth;
     866
     867    if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     868    m_signLineBuf1 = new Char[m_lineBufWidth+1];
     869
     870    if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     871    m_signLineBuf2 = new Char[m_lineBufWidth+1];
     872  }
     873
     874  Int x,y, startX, startY, endX, endY, edgeType, firstLineStartX, firstLineEndX;
     875  Char signLeft, signRight, signDown;
     876  Int64 *diff, *count;
     877  Pel *srcLine, *orgLine;
     878  Int* skipLinesR = m_skipLinesR[compIdx];
     879  Int* skipLinesB = m_skipLinesB[compIdx];
     880
     881  for(Int typeIdx=0; typeIdx< NUM_SAO_NEW_TYPES; typeIdx++)
     882  {
     883    SAOStatData& statsData= statsDataTypes[typeIdx];
     884    statsData.reset();
     885
     886    srcLine = srcBlk;
     887    orgLine = orgBlk;
     888    diff    = statsData.diff;
     889    count   = statsData.count;
     890    switch(typeIdx)
     891    {
     892    case SAO_TYPE_EO_0:
     893      {
     894        diff +=2;
     895        count+=2;
     896        endY   = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height;
     897#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     898        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     899                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     900                                                 ;
     901#else
     902        startX = isLeftAvail ? 0 : 1;
     903#endif
     904#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     905        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     906                                                 : (isRightAvail ? width : (width - 1))
     907                                                 ;
     908#else
     909        endX   = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);
     910#endif
     911        for (y=0; y<endY; y++)
     912        {
     913          signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     914          for (x=startX; x<endX; x++)
     915          {
     916            signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
     917            edgeType  =  signRight + signLeft;
     918            signLeft  = -signRight;
     919
     920            diff [edgeType] += (orgLine[x] - srcLine[x]);
     921            count[edgeType] ++;
     922          }
     923          srcLine  += srcStride;
     924          orgLine  += orgStride;
     925        }
     926#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     927        if(isCalculatePreDeblockSamples)
     928        {
     929          if(isBelowAvail)
     930          {
     931            startX = isLeftAvail  ? 0 : 1;
     932            endX   = isRightAvail ? width : (width -1);
     933
     934            for(y=0; y<skipLinesB[typeIdx]; y++)
     935            {
     936              signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     937              for (x=startX; x<endX; x++)
     938              {
     939                signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
     940                edgeType  =  signRight + signLeft;
     941                signLeft  = -signRight;
     942
     943                diff [edgeType] += (orgLine[x] - srcLine[x]);
     944                count[edgeType] ++;
     945              }
     946              srcLine  += srcStride;
     947              orgLine  += orgStride;
     948            }
     949          }
     950        }
     951#endif
     952      }
     953      break;
     954    case SAO_TYPE_EO_90:
     955      {
     956        diff +=2;
     957        count+=2;
     958        Char *signUpLine = m_signLineBuf1;
     959
     960#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     961        startX = (!isCalculatePreDeblockSamples) ? 0
     962                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
     963                                                 ;
     964#endif
     965        startY = isAboveAvail ? 0 : 1;
     966#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     967        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
     968                                                 : width
     969                                                 ;
     970#else
     971        endX   = isRightAvail ? (width - skipLinesR[typeIdx]) : width ;
     972#endif
     973        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     974        if (!isAboveAvail)
     975        {
     976          srcLine += srcStride;
     977          orgLine += orgStride;
     978        }
     979
     980        Pel* srcLineAbove = srcLine - srcStride;
     981#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     982        for (x=startX; x<endX; x++)
     983#else
     984        for (x=0; x< endX; x++)
     985#endif
     986        {
     987          signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
     988        }
     989
     990        Pel* srcLineBelow;
     991        for (y=startY; y<endY; y++)
     992        {
     993          srcLineBelow = srcLine + srcStride;
     994
     995#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     996          for (x=startX; x<endX; x++)
     997#else
     998          for (x=0; x<endX; x++)
     999#endif
     1000          {
     1001            signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
     1002            edgeType  = signDown + signUpLine[x];
     1003            signUpLine[x]= -signDown;
     1004
     1005            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1006            count[edgeType] ++;
     1007          }
     1008          srcLine += srcStride;
     1009          orgLine += orgStride;
     1010        }
     1011#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1012        if(isCalculatePreDeblockSamples)
     1013        {
     1014          if(isBelowAvail)
     1015          {
     1016            startX = 0;
     1017            endX   = width;
     1018
     1019            for(y=0; y<skipLinesB[typeIdx]; y++)
     1020            {
     1021              srcLineBelow = srcLine + srcStride;
     1022              srcLineAbove = srcLine - srcStride;
     1023
     1024              for (x=startX; x<endX; x++)
     1025              {
     1026                edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
     1027                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1028                count[edgeType] ++;
     1029              }
     1030              srcLine  += srcStride;
     1031              orgLine  += orgStride;
     1032            }
     1033          }
     1034        }
     1035#endif
     1036
     1037      }
     1038      break;
     1039    case SAO_TYPE_EO_135:
     1040      {
     1041        diff +=2;
     1042        count+=2;
     1043        Char *signUpLine, *signDownLine, *signTmpLine;
     1044
     1045        signUpLine  = m_signLineBuf1;
     1046        signDownLine= m_signLineBuf2;
     1047
     1048#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1049        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     1050                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1051                                                 ;
     1052#else
     1053        startX = isLeftAvail ? 0 : 1 ;
     1054#endif
     1055
     1056#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1057        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1))
     1058                                                 : (isRightAvail ? width : (width - 1))
     1059                                                 ;
     1060#else
     1061        endX   = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);
     1062#endif
     1063        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     1064
     1065        //prepare 2nd line's upper sign
     1066        Pel* srcLineBelow = srcLine + srcStride;
     1067        for (x=startX; x<endX+1; x++)
     1068        {
     1069          signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
     1070        }
     1071
     1072        //1st line
     1073        Pel* srcLineAbove = srcLine - srcStride;
     1074#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1075        firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0    : 1) : startX;
     1076        firstLineEndX   = (!isCalculatePreDeblockSamples) ? (isAboveAvail     ? endX : 1) : endX;
     1077#else
     1078        firstLineStartX = isAboveLeftAvail ? 0    : 1;
     1079        firstLineEndX   = isAboveAvail     ? endX : 1;
     1080#endif
     1081        for(x=firstLineStartX; x<firstLineEndX; x++)
     1082        {
     1083          edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
     1084          diff [edgeType] += (orgLine[x] - srcLine[x]);
     1085          count[edgeType] ++;
     1086        }
     1087        srcLine  += srcStride;
     1088        orgLine  += orgStride;
     1089
     1090
     1091        //middle lines
     1092        for (y=1; y<endY; y++)
     1093        {
     1094          srcLineBelow = srcLine + srcStride;
     1095
     1096          for (x=startX; x<endX; x++)
     1097          {
     1098            signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
     1099            edgeType = signDown + signUpLine[x];
     1100            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1101            count[edgeType] ++;
     1102
     1103            signDownLine[x+1] = -signDown;
     1104          }
     1105          signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
     1106
     1107          signTmpLine  = signUpLine;
     1108          signUpLine   = signDownLine;
     1109          signDownLine = signTmpLine;
     1110
     1111          srcLine += srcStride;
     1112          orgLine += orgStride;
     1113        }
     1114#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1115        if(isCalculatePreDeblockSamples)
     1116        {
     1117          if(isBelowAvail)
     1118          {
     1119            startX = isLeftAvail  ? 0     : 1 ;
     1120            endX   = isRightAvail ? width : (width -1);
     1121
     1122            for(y=0; y<skipLinesB[typeIdx]; y++)
     1123            {
     1124              srcLineBelow = srcLine + srcStride;
     1125              srcLineAbove = srcLine - srcStride;
     1126
     1127              for (x=startX; x< endX; x++)
     1128              {
     1129                edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
     1130                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1131                count[edgeType] ++;
     1132              }
     1133              srcLine  += srcStride;
     1134              orgLine  += orgStride;
     1135            }
     1136          }
     1137        }
     1138#endif
     1139      }
     1140      break;
     1141    case SAO_TYPE_EO_45:
     1142      {
     1143        diff +=2;
     1144        count+=2;
     1145        Char *signUpLine = m_signLineBuf1+1;
     1146
     1147#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1148        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     1149                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1150                                                 ;
     1151#else
     1152        startX = isLeftAvail ? 0 : 1;
     1153#endif
     1154#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1155        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1156                                                 : (isRightAvail ? width : (width - 1))
     1157                                                 ;
     1158#else
     1159        endX   = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1);
     1160#endif
     1161        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     1162
     1163        //prepare 2nd line upper sign
     1164        Pel* srcLineBelow = srcLine + srcStride;
     1165        for (x=startX-1; x<endX; x++)
     1166        {
     1167          signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
     1168        }
     1169
     1170
     1171        //first line
     1172        Pel* srcLineAbove = srcLine - srcStride;
     1173#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1174        firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX)
     1175                                                          : startX
     1176                                                          ;
     1177        firstLineEndX   = (!isCalculatePreDeblockSamples) ? ((!isRightAvail && isAboveRightAvail) ? width : endX)
     1178                                                          : endX
     1179                                                          ;
     1180#else
     1181        firstLineStartX = isAboveAvail ? startX : endX;
     1182        firstLineEndX   = (!isRightAvail && isAboveRightAvail) ? width : endX;
     1183#endif
     1184        for(x=firstLineStartX; x<firstLineEndX; x++)
     1185        {
     1186          edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
     1187          diff [edgeType] += (orgLine[x] - srcLine[x]);
     1188          count[edgeType] ++;
     1189        }
     1190
     1191        srcLine += srcStride;
     1192        orgLine += orgStride;
     1193
     1194        //middle lines
     1195        for (y=1; y<endY; y++)
     1196        {
     1197          srcLineBelow = srcLine + srcStride;
     1198
     1199          for(x=startX; x<endX; x++)
     1200          {
     1201            signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
     1202            edgeType = signDown + signUpLine[x];
     1203
     1204            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1205            count[edgeType] ++;
     1206
     1207            signUpLine[x-1] = -signDown;
     1208          }
     1209          signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
     1210          srcLine  += srcStride;
     1211          orgLine  += orgStride;
     1212        }
     1213#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1214        if(isCalculatePreDeblockSamples)
     1215        {
     1216          if(isBelowAvail)
     1217          {
     1218            startX = isLeftAvail  ? 0     : 1 ;
     1219            endX   = isRightAvail ? width : (width -1);
     1220
     1221            for(y=0; y<skipLinesB[typeIdx]; y++)
     1222            {
     1223              srcLineBelow = srcLine + srcStride;
     1224              srcLineAbove = srcLine - srcStride;
     1225
     1226              for (x=startX; x<endX; x++)
     1227              {
     1228                edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
     1229                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1230                count[edgeType] ++;
     1231              }
     1232              srcLine  += srcStride;
     1233              orgLine  += orgStride;
     1234            }
     1235          }
     1236        }
     1237#endif
     1238      }
     1239      break;
     1240    case SAO_TYPE_BO:
     1241      {
     1242#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1243        startX = (!isCalculatePreDeblockSamples)?0
     1244                                                :( isRightAvail?(width- skipLinesR[typeIdx]):width)
     1245                                                ;
     1246        endX   = (!isCalculatePreDeblockSamples)?(isRightAvail ? (width - skipLinesR[typeIdx]) : width )
     1247                                                :width
     1248                                                ;
     1249#else
     1250        endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width;
     1251#endif
     1252        endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height;
     1253        Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
     1254        for (y=0; y< endY; y++)
     1255        {
     1256#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1257          for (x=startX; x< endX; x++)
     1258#else
     1259          for (x=0; x< endX; x++)
     1260#endif
     1261          {
     1262
     1263            Int bandIdx= srcLine[x] >> shiftBits;
     1264            diff [bandIdx] += (orgLine[x] - srcLine[x]);
     1265            count[bandIdx] ++;
     1266          }
     1267          srcLine += srcStride;
     1268          orgLine += orgStride;
     1269        }
     1270#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1271        if(isCalculatePreDeblockSamples)
     1272        {
     1273          if(isBelowAvail)
     1274          {
     1275            startX = 0;
     1276            endX   = width;
     1277
     1278            for(y= 0; y< skipLinesB[typeIdx]; y++)
     1279            {
     1280              for (x=startX; x< endX; x++)
     1281              {
     1282                Int bandIdx= srcLine[x] >> shiftBits;
     1283                diff [bandIdx] += (orgLine[x] - srcLine[x]);
     1284                count[bandIdx] ++;
     1285              }
     1286              srcLine  += srcStride;
     1287              orgLine  += orgStride;
     1288
     1289            }
     1290
     1291          }
     1292        }
     1293#endif
     1294      }
     1295      break;
     1296    default:
     1297      {
     1298        printf("Not a supported SAO types\n");
     1299        assert(0);
     1300        exit(-1);
     1301      }
     1302    }
     1303  }
     1304}
     1305
     1306#else
     1307
     1308
     1309
    471310TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    481311{
     
    16612924}
    16622925
    1663 #if SAO_CHROMA_LAMBDA
    16642926/** Sample adaptive offset process
    16652927 * \param pcSaoParam
     
    16712933#else
    16722934Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma)
    1673 #endif
    1674 #else
    1675 /** Sample adaptive offset process
    1676  * \param dLambda
    1677  */
    1678 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda)
    16792935#endif
    16802936{
     
    25013757}
    25023758
     3759#endif
     3760
    25033761//! \}
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h

    r313 r540  
    5353// Class definition
    5454// ====================================================================================================================
     55
     56#if HM_CLEANUP_SAO
     57enum SAOCabacStateLablesRDO //CABAC state labels
     58{
     59  SAO_CABACSTATE_PIC_INIT =0,
     60  SAO_CABACSTATE_BLK_CUR,
     61  SAO_CABACSTATE_BLK_NEXT,
     62  SAO_CABACSTATE_BLK_MID,
     63  SAO_CABACSTATE_BLK_TEMP,
     64  NUM_SAO_CABACSTATE_LABELS
     65};
     66
     67struct SAOStatData //data structure for SAO statistics
     68{
     69  Int64 diff[MAX_NUM_SAO_CLASSES];
     70  Int64 count[MAX_NUM_SAO_CLASSES];
     71
     72  SAOStatData(){}
     73  ~SAOStatData(){}
     74  Void reset()
     75  {
     76    ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     77    ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     78  }
     79  const SAOStatData& operator=(const SAOStatData& src)
     80  {
     81    ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     82    ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     83    return *this;
     84  }
     85#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     86  const SAOStatData& operator+= (const SAOStatData& src)
     87  {
     88    for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++)
     89    {
     90      diff[i] += src.diff[i];
     91      count[i] += src.count[i];
     92    }
     93    return *this;
     94  }
     95#endif
     96};
     97
     98class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
     99{
     100public:
     101  TEncSampleAdaptiveOffset();
     102  virtual ~TEncSampleAdaptiveOffset();
     103
     104  //interface
     105#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     106  Void createEncData(Bool isPreDBFSamplesUsed);
     107#else
     108  Void createEncData();
     109#endif
     110  Void destroyEncData();
     111  Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ;
     112  Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
     113#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     114                , Bool isPreDBFSamplesUsed
     115#endif
     116                );
     117public: //methods
     118#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     119  Void getPreDBFStatistics(TComPic* pPic);
     120#endif
     121private: //methods
     122  Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic
     123#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     124                   , Bool isCalculatePreDeblockSamples = false
     125#endif
     126                   );
     127  Void decidePicParams(Bool* sliceEnabled, Int picTempLayer);
     128  Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams);
     129  Void getBlkStats(Int compIdx, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     130#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     131                  , Bool isCalculatePreDeblockSamples
     132#endif
     133                  );
     134  Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
     135  Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
     136  Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData);
     137  Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo);
     138  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift);
     139  inline Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh );
     140#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     141  Void addPreDBFStatistics(SAOStatData*** blkStats);
     142#endif
     143private: //members
     144  //for RDO
     145  TEncSbac**             m_pppcRDSbacCoder;           
     146  TEncSbac*              m_pcRDGoOnSbacCoder;
     147  TEncBinCABACCounter**  m_pppcBinCoderCABAC;   
     148  Double                 m_labmda[NUM_SAO_COMPONENTS];
     149
     150  //statistics
     151  SAOStatData***         m_statData; //[ctu][comp][classes]
     152#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     153  SAOStatData***         m_preDBFstatData;
     154#endif
     155#if SAO_ENCODING_CHOICE
     156  Double                 m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER];
     157#endif
     158  Int                    m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
     159  Int                    m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
     160};
     161#else
     162
    55163
    56164class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
     
    95203  Void endSaoEnc();
    96204  Void resetStats();
    97 #if SAO_CHROMA_LAMBDA
    98205#if SAO_ENCODING_CHOICE
    99206  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
    100207#else
    101208  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
    102 #endif
    103 #else
    104   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda);
    105209#endif
    106210
     
    131235  Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
    132236};
    133 
     237#endif
    134238//! \}
    135239
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r494 r540  
    416416{
    417417  PartSize eSize         = pcCU->getPartitionSize( uiAbsPartIdx );
    418 
    419418  if ( pcCU->isIntra( uiAbsPartIdx ) )
    420419  {
     
    13941393  {
    13951394    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     1395#if HM_CLEANUP_SAO
     1396    m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 );
     1397#else
    13961398    m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 );
     1399#endif
    13971400  }
    13981401}
     
    15971600}
    15981601
     1602#if HM_CLEANUP_SAO
     1603Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled)
     1604{
     1605  UInt uiSymbol;
     1606  if(!sliceEnabled)
     1607  {
     1608    assert(ctbParam.modeIdc == SAO_MODE_OFF);
     1609    return;
     1610  }
     1611
     1612  //type
     1613  if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1614  {
     1615    //sao_type_idx_luma or sao_type_idx_chroma
     1616    if(ctbParam.modeIdc == SAO_MODE_OFF)
     1617    {
     1618      uiSymbol =0;
     1619    }
     1620    else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO
     1621    {
     1622      uiSymbol = 1;
     1623    }
     1624    else
     1625    {
     1626      assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO
     1627      uiSymbol = 2;
     1628    }
     1629    codeSaoTypeIdx(uiSymbol);
     1630  }
     1631
     1632  if(ctbParam.modeIdc == SAO_MODE_NEW)
     1633  {
     1634    Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES;
     1635    Int offset[4];
     1636    Int k=0;
     1637    for(Int i=0; i< numClasses; i++)
     1638    {
     1639      if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN)
     1640      {
     1641        continue;
     1642      }
     1643      Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?(  (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES   ):i;
     1644      offset[k] = ctbParam.offset[classIdx];
     1645      k++;
     1646    }
     1647
     1648    for(Int i=0; i< 4; i++)
     1649    {
     1650      codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]),  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     1651    }
     1652
     1653
     1654    if(ctbParam.typeIdc == SAO_TYPE_BO)
     1655    {
     1656      for(Int i=0; i< 4; i++)
     1657      {
     1658        if(offset[i] != 0)
     1659        {
     1660          codeSAOSign((offset[i]< 0)?1:0);
     1661        }
     1662      }
     1663
     1664      codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position
     1665    }
     1666    else //EO
     1667    {
     1668      if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1669      {
     1670        assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0);
     1671        codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma
     1672      }
     1673    }
     1674
     1675  }
     1676}
     1677
     1678
     1679Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam
     1680                              , Bool* sliceEnabled
     1681                              , Bool leftMergeAvail
     1682                              , Bool aboveMergeAvail
     1683                              , Bool onlyEstMergeInfo // = false
     1684                              )
     1685{
     1686
     1687  Bool isLeftMerge = false;
     1688  Bool isAboveMerge= false;
     1689
     1690  if(leftMergeAvail)
     1691  {
     1692    isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT));
     1693    codeSaoMerge( isLeftMerge?1:0  ); //sao_merge_left_flag
     1694  }
     1695
     1696  if( aboveMergeAvail && !isLeftMerge)
     1697  {
     1698    isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE));
     1699    codeSaoMerge( isAboveMerge?1:0  ); //sao_merge_left_flag
     1700  }
     1701
     1702  if(onlyEstMergeInfo)
     1703  {
     1704    return; //only for RDO
     1705  }
     1706
     1707  if(!isLeftMerge && !isAboveMerge) //not merge mode
     1708  {
     1709    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     1710    {
     1711      codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]);
     1712    }
     1713  }
     1714}
     1715#endif
     1716
    15991717//! \}
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r345 r540  
    103103  Void  codeSAOSign       ( UInt  uiCode);  //<! code SAO offset sign
    104104  Void  codeScalingList      ( TComScalingList* /*scalingList*/     ){ assert (0);  return;};
     105
     106#if HM_CLEANUP_SAO
     107  Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled);
     108  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
     109                    , Bool* sliceEnabled
     110                    , Bool leftMergeAvail
     111                    , Bool aboveMergeAvail
     112                    , Bool onlyEstMergeInfo = false
     113                    );
     114#endif
    105115
    106116private:
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r494 r540  
    720720  Pel*  piRefPos;
    721721  Int iRefStride = m_filteredBlock[0][0].getStride();
    722 #if NS_HAD
    723   m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    724 #else
    725722  m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() );
    726 #endif
    727723 
    728724  const TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ);
     
    737733    piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr();
    738734    if ( horVal == 2 && ( verVal & 1 ) == 0 )
     735    {
    739736      piRefPos += 1;
     737    }
    740738    if ( ( horVal & 1 ) == 0 && verVal == 2 )
     739    {
    741740      piRefPos += iRefStride;
     741    }
    742742    cMvTest = pcMvRefine[i];
    743743    cMvTest += rcMvFrac;
     
    774774  UInt  uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth;
    775775
    776   {
    777     if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 )
    778     {
    779       assert( uiSubdiv );
    780     }
    781     else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
    782     {
    783       assert( uiSubdiv );
    784     }
    785     else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    786     {
    787       assert( !uiSubdiv );
    788     }
    789     else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    790     {
    791       assert( !uiSubdiv );
    792     }
    793     else
    794     {
    795       assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
    796       if( bLuma )
    797       {
    798         m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
    799       }
     776  if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 )
     777  {
     778    assert( uiSubdiv );
     779  }
     780  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     781  {
     782    assert( uiSubdiv );
     783  }
     784  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
     785  {
     786    assert( !uiSubdiv );
     787  }
     788  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     789  {
     790    assert( !uiSubdiv );
     791  }
     792  else
     793  {
     794    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
     795    if( bLuma )
     796    {
     797      m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
    800798    }
    801799  }
     
    806804    {
    807805      if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) )
     806      {
    808807        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth );
     808      }
    809809      if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) )
     810      {
    810811        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth );
     812      }
    811813    }
    812814  }
     
    822824  }
    823825 
    824   {
    825     //===== Cbfs =====
    826     if( bLuma )
    827     {
    828       m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    829     }
     826  //===== Cbfs =====
     827  if( bLuma )
     828  {
     829    m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    830830  }
    831831}
     
    944944    }
    945945  }
    946 
    947946  if( bChroma )
    948947  {
     
    13061305
    13071306#if RDOQ_CHROMA_LAMBDA
    1308     m_pcTrQuant->selectLambda      (TEXT_CHROMA); 
     1307    m_pcTrQuant->selectLambda(eText);
    13091308#endif
    13101309    m_pcTrQuant->transformNxN      ( pcCU, piResi, uiStride, pcCoeff,
     
    13581357 
    13591358  //===== update distortion =====
    1360 #if WEIGHTED_CHROMA_DISTORTION
    13611359  ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText );
    1362 #else
    1363   ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
    1364 #endif
    13651360}
    13661361
     
    25392534     
    25402535      for( Int j=0; j < numCand; j++)
    2541 
    25422536      {
    25432537        Bool mostProbableModeIncluded = false;
     
    30393033                            pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(),
    30403034                            m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(),
    3041 #if NS_HAD
    3042                             iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    3043 #else
    30443035                            iWidth, iHeight, m_pcEncCfg->getUseHADME() );
    3045 #endif
    30463036  ruiErr = cDistParam.DistFunc( &cDistParam );
    30473037}
     
    32463236
    32473237    UInt          uiCostTempL0[MAX_NUM_REF];
    3248     for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT;
     3238    for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++)
     3239    {
     3240      uiCostTempL0[iNumRef] = MAX_UINT;
     3241    }
    32493242    UInt          uiBitsTempL0[MAX_NUM_REF];
    32503243
     
    37163709    {
    37173710      uiLastMode = 2;
    3718       {
    3719             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3720             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3721             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3722             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3723       }
    3724       {
    3725         TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
    3726             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3727       }
    3728       {
    3729         TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
    3730             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3731       }
     3711      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3712      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3713      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3714      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3715     
     3716      TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
     3717      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
     3718     
     3719      TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
     3720      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    37323721     
    37333722      pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     
    37433732    {
    37443733      uiLastMode = 0;
    3745           pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3746           pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3747       {
    3748         TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
    3749             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3750       }
     3734      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3735      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3736      TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
     3737      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    37513738      pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    37523739     
     
    37593746    {
    37603747      uiLastMode = 1;
    3761           pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3762           pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3763       {
    3764         TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
    3765             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3766       }
     3748      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3749      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3750      TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
     3751      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    37673752      pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    37683753     
     
    38163801        pcCU->setMergeIndexSubParts( uiMRGIndex,    uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    38173802        pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    3818         {
    3819           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3820           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3821         }
     3803        pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3804        pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    38223805
    38233806        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
     
    38343817        pcCU->setMergeFlagSubParts( false,        uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    38353818        pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    3836         {
    3837           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3838           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3839         }
     3819        pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3820        pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    38403821      }
    38413822    }
     
    39443925 
    39453926  if (iNum == 1)
     3927  {
    39463928    return 0;
     3929  }
    39473930 
    39483931  UInt uiLength = 1;
     
    41234106                            pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(),
    41244107                            pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(),
    4125 #if NS_HAD
    4126                             iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    4127 #else
    41284108                            iSizeX, iSizeY, m_pcEncCfg->getUseHADME() );
    4129 #endif
    41304109  ruiDist = cDistParam.DistFunc( &cDistParam );
    41314110  uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] );
    41324111#else
    4133 #if WEIGHTED_CHROMA_DISTORTION
    41344112  uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD );
    4135 #else
    4136   uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );
    4137 #endif
    41384113  uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD );
    41394114#endif
     
    42284203  m_pcRdCost->getMotionCost( 1, 0 );
    42294204  m_pcRdCost->setCostScale ( 1 );
    4230  
    4231   {
     4205
    42324206#if REF_IDX_ME_ZEROMV
    4233     if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId()))  //ILR reference pic
    4234     {
    4235       xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
    4236     }
    4237     else    //non ILR reference pic
    4238     {
    4239       xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
    4240     }
     4207  if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId()))  //ILR reference pic
     4208  {
     4209    xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
     4210  }
     4211  else    //non ILR reference pic
     4212  {
     4213    xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
     4214  }
    42414215#else
    4242     xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost
    4243                           ,bBi
    4244                           );
    4245 #endif
    4246   }
    4247  
    4248  
    4249  
     4216  xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost,bBi );
     4217#endif
     4218
    42504219  m_pcRdCost->setCostScale( 0 );
    42514220  rcMv <<= 2;
     
    46014570    pcYuvPred->copyToPartYuv( rpcYuvRec, 0 );
    46024571   
    4603 #if WEIGHTED_CHROMA_DISTORTION
    46044572    uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    46054573    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U )
    46064574    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    4607 #else
    4608     uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    4609     + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
    4610     + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );
    4611 #endif
    46124575
    46134576    if( m_bUseSBACRD )
     4577    {
    46144578      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]);
     4579    }
    46154580   
    46164581    m_pcEntropyCoder->resetBits();
     
    46284593   
    46294594    if( m_bUseSBACRD )
     4595    {
    46304596      m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]);
     4597    }
    46314598   
    46324599    pcCU->setCbfSubParts( 0, 0, 0, 0, pcCU->getDepth( 0 ) );
     
    47994766 
    48004767  // update with clipped distortion and cost (qp estimation loop uses unclipped values)
    4801 #if WEIGHTED_CHROMA_DISTORTION
    48024768    uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    48034769    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U )
    48044770    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    4805 #else
    4806   uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    4807   + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
    4808   + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );
    4809 #endif
    48104771  dCostBest = m_pcRdCost->calcRdCost( uiBitsBest, uiDistortionBest );
    48114772 
     
    48324793  Bool bCheckFull;
    48334794  if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize >  pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) )
     4795  {
    48344796     bCheckFull = false;
     4797  }
    48354798  else
     4799  {
    48364800     bCheckFull =  ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() );
     4801  }
    48374802
    48384803  const Bool bCheckSplit  = ( uiLog2TrSize >  pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
     
    49324897
    49334898#if RDOQ_CHROMA_LAMBDA
    4934       m_pcTrQuant->selectLambda(TEXT_CHROMA);
     4899      m_pcTrQuant->selectLambda(TEXT_CHROMA_U);
    49354900#endif
    49364901
     
    49434908      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    49444909      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
     4910     
     4911#if RDOQ_CHROMA_LAMBDA
     4912      m_pcTrQuant->selectLambda(TEXT_CHROMA_V);
     4913#endif
     4914
    49454915      m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV,
    49464916#if ADAPTIVE_QP_SELECTION
     
    49554925    m_pcEntropyCoder->resetBits();
    49564926   
    4957     {
    4958       m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    4959     }
    4960    
     4927    m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
     4928
    49614929    m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx,  trWidth,  trHeight,    uiDepth, TEXT_LUMA );
    49624930    const UInt uiSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits();
     
    49664934    if( bCodeChroma )
    49674935    {
    4968       {
    4969         m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    4970       }
     4936      m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    49714937      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U );
    49724938      uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY;
    49734939     
    4974       {
    4975         m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    4976       }
     4940      m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    49774941      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V );
    49784942      uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU );
     
    50034967      assert(scalingListType < 6);     
    50044968      m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only
     4969     
    50054970      const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),
    50064971      pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight );
     
    50595024    {
    50605025      uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    5061 #if WEIGHTED_CHROMA_DISTORTION
    50625026                                        , TEXT_CHROMA_U
    5063 #endif
    50645027                                        ); // initialized with zero residual destortion
    50655028      if ( puiZeroDist )
     
    50805043        const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    50815044                                                            pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    5082 #if WEIGHTED_CHROMA_DISTORTION
    50835045                                                            , TEXT_CHROMA_U
    5084 #endif
    50855046                                                            );
    50865047
     
    51185079      {
    51195080        m_pcEntropyCoder->resetBits();
    5120         m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrModeC );
     5081        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode );
    51215082        const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits();
    51225083        minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU );
     
    51345095     
    51355096      uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    5136 #if WEIGHTED_CHROMA_DISTORTION
    51375097                                        , TEXT_CHROMA_V
    5138 #endif
    51395098                                        ); // initialized with zero residual destortion
    51405099      if ( puiZeroDist )
     
    51545113        const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    51555114                                                            pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    5156 #if WEIGHTED_CHROMA_DISTORTION
    51575115                                                            , TEXT_CHROMA_V
    5158 #endif
    51595116                                                            );
    51605117        if (pcCU->isLosslessCoded(0))
     
    51915148      {
    51925149        m_pcEntropyCoder->resetBits();
    5193         m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrModeC );
     5150        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode );
    51945151        const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits();
    51955152        minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV );
     
    53525309
    53535310#if RDOQ_CHROMA_LAMBDA
    5354       m_pcTrQuant->selectLambda(TEXT_CHROMA);
     5311      m_pcTrQuant->selectLambda(TEXT_CHROMA_U);
    53555312#endif
    53565313
     
    53625319      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    53635320      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
     5321#if RDOQ_CHROMA_LAMBDA
     5322      m_pcTrQuant->selectLambda(TEXT_CHROMA_V);
     5323#endif
    53645324      m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV,
    53655325#if ADAPTIVE_QP_SELECTION
     
    53915351        uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    53925352                                                 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    5393 #if WEIGHTED_CHROMA_DISTORTION
    53945353                                                 , TEXT_CHROMA_U
    5395 #endif
    53965354                                                 );
    53975355
     
    54355393        uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    54365394                                                 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    5437 #if WEIGHTED_CHROMA_DISTORTION
    54385395                                                 , TEXT_CHROMA_V
    5439 #endif
    54405396                                                 );
    54415397
     
    54745430    m_pcEntropyCoder->resetBits();
    54755431
    5476     {
    5477       if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    5478       {
    5479         m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize );
    5480       }
    5481     }
    5482 
    5483     {
    5484       if( bCodeChroma )
    5485       {
    5486         m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    5487         m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    5488       }
    5489 
    5490       m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    5491     }
     5432    if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     5433    {
     5434      m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize );
     5435    }
     5436
     5437    if( bCodeChroma )
     5438    {
     5439      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
     5440      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
     5441    }
     5442
     5443    m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    54925444
    54935445    m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight,    uiDepth, TEXT_LUMA );
     
    55465498    m_pcEntropyCoder->resetBits();
    55475499   
    5548     {
    5549       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true,  TEXT_LUMA );
    5550       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA );
    5551       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U );
    5552       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V );
    5553     }
    5554    
     5500    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true,  TEXT_LUMA );
     5501    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA );
     5502    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U );
     5503    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V );
     5504
    55555505    uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits();
    55565506    dSubdivCost  = m_pcRdCost->calcRdCost( uiSubdivBits, uiSubdivDist );
     
    56025552  const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2;
    56035553
    5604   {
    5605     if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    5606     {
    5607       m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize );
    5608     }
    5609   }
    5610 
    5611   {
    5612     assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA );
     5554  if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     5555  {
     5556    m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize );
     5557  }
     5558
     5559  assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA );
    56135560    if( bSubdivAndCbf )
    56145561    {
     
    56315578      }
    56325579    }
    5633   }
    56345580 
    56355581  if( !bSubdiv )
     
    56555601    if( bSubdivAndCbf )
    56565602    {
    5657       {
    5658         m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    5659       }
     5603      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    56605604    }
    56615605    else
     
    57255669      if( bCodeChroma )
    57265670      {
    5727         {
    5728           m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC );
    5729         }
     5671        m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC );
    57305672      }
    57315673    }
     
    58475789    m_pcEntropyCoder->encodePartSize( pcCU, 0, pcCU->getDepth(0), true );
    58485790    m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
    5849 
    58505791    Bool bDummy = false;
    58515792    m_pcEntropyCoder->encodeCoeff   ( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0), bDummy );
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r494 r540  
    194194                                  UInt        uiPreCalcDistC );
    195195 
     196 
    196197  /// encoder estimation - inter prediction (non-skip)
    197198  Void predInterSearch          ( TComDataCU* pcCU,
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r494 r540  
    295295    dQP += pdQPs[ rpcSlice->getPOC() ];
    296296  }
    297 #if !RATE_CONTROL_LAMBDA_DOMAIN
    298   if ( m_pcCfg->getUseRateCtrl())
    299   {
    300     dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
    301   }
    302 #endif
    303297  // ------------------------------------------------------------------------------------------------------------------
    304298  // Lambda computation
     
    386380  // store lambda
    387381  m_pcRdCost ->setLambda( dLambda );
    388 #if WEIGHTED_CHROMA_DISTORTION
    389382// for RDO
    390383  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    391   Double weight = 1.0;
     384  Double weight[2] = { 1.0, 1.0 };
    392385  Int qpc;
    393386  Int chromaQPOffset;
     
    395388  chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb();
    396389  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    397   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    398   m_pcRdCost->setCbDistortionWeight(weight);
     390  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     391  m_pcRdCost->setCbDistortionWeight(weight[0]);
    399392
    400393  chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr();
    401394  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    402   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     395  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     396  m_pcRdCost->setCrDistortionWeight(weight[1]);
     397
    403398#if JCTVC_M0259_LAMBDAREFINEMENT
    404399  if( rpcSlice->getLayerId() > 0 && m_ppcTEncTop[layerId]->getNumActiveRefLayers() && m_pcCfg->getGOPSize() >= 8 && rpcSlice->isIntra() == false && depth == 0 )
    405400  {
    406401    dLambda *= 1.1;
    407     weight *= 1.15;
    408   }
    409 #endif
    410   m_pcRdCost->setCrDistortionWeight(weight);
    411 #endif
    412 
     402    weight[1] *= 1.15;
     403    weight[0] *= 1.15;
     404
     405    m_pcRdCost ->setLambda( dLambda );
     406    m_pcRdCost->setCbDistortionWeight(weight[0]);
     407    m_pcRdCost->setCrDistortionWeight(weight[1]);
     408  }
     409#endif
     410
     411  const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])};
     412 
    413413#if RDOQ_CHROMA_LAMBDA
    414414// for RDOQ
    415   m_pcTrQuant->setLambda( dLambda, dLambda / weight );
     415  m_pcTrQuant->setLambdas( lambdaArray );
    416416#else
    417417  m_pcTrQuant->setLambda( dLambda );
    418418#endif
    419419
    420 #if SAO_CHROMA_LAMBDA
    421420// For SAO
    422   rpcSlice   ->setLambda( dLambda, dLambda / weight );
    423 #else
    424   rpcSlice   ->setLambda( dLambda );
    425 #endif
     421  rpcSlice->setLambdas( lambdaArray );
    426422
    427423#if HB_LAMBDA_FOR_LDC
     
    430426
    431427#if SVC_EXTENSION
    432   if(m_pcCfg->getLayerId() > 0)
     428  if( m_pcCfg->getLayerId() > 0 && m_pcCfg->getNumActiveRefLayers() > 0 )
    433429  {
    434430    eSliceType=B_SLICE;
     
    500496
    501497  pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
    502 
    503498  if(eSliceType==I_SLICE)
    504499  {
     
    517512  rpcSlice->setSliceSegmentArgument ( m_pcCfg->getSliceSegmentArgument() );
    518513  rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()        );
     514#if HIGHER_LAYER_IRAP_SKIP_FLAG
     515  if (m_pcCfg->getSkipPictureAtArcSwitch() && m_pcCfg->getAdaptiveResolutionChange() > 0 && rpcSlice->getLayerId() == 1 && rpcSlice->getPOC() == m_pcCfg->getAdaptiveResolutionChange())
     516  {
     517    rpcSlice->setMaxNumMergeCand        ( 1 );
     518  }
     519#endif
    519520  xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPred() );
    520521
     
    546547}
    547548
    548 #if RATE_CONTROL_LAMBDA_DOMAIN
    549549Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
    550550{
     
    555555  slice->setSliceQpBase ( sliceQP );
    556556  m_pcRdCost ->setLambda( lambda );
    557 #if WEIGHTED_CHROMA_DISTORTION
    558557  // for RDO
    559558  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    560   Double weight;
     559  Double weight[2] = { 1.0, 1.0 };
    561560  Int qpc;
    562561  Int chromaQPOffset;
     
    564563  chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
    565564  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    566   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    567   m_pcRdCost->setCbDistortionWeight(weight);
     565  weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     566  m_pcRdCost->setCbDistortionWeight(weight[0]);
    568567
    569568  chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
    570569  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    571   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    572   m_pcRdCost->setCrDistortionWeight(weight);
    573 #endif
     570  weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     571  m_pcRdCost->setCrDistortionWeight(weight[1]);
     572
     573  const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])};
    574574
    575575#if RDOQ_CHROMA_LAMBDA
    576576  // for RDOQ
    577   m_pcTrQuant->setLambda( lambda, lambda / weight );
     577  m_pcTrQuant->setLambdas( lambdaArray );
    578578#else
    579579  m_pcTrQuant->setLambda( lambda );
    580580#endif
    581581
    582 #if SAO_CHROMA_LAMBDA
    583582  // For SAO
    584   slice   ->setLambda( lambda, lambda / weight );
    585 #else
    586   slice   ->setLambda( lambda );
    587 #endif
     583  slice->setLambdas( lambdaArray );
    588584}
    589 #else
    590 /**
    591  - lambda re-computation based on rate control QP
    592  */
    593 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)
    594 {
    595   Int qp;
    596   Double recalQP= (Double)changeQP;
    597   Double origQP = (Double)recalQP;
    598   Double lambda;
    599 
    600   // pre-compute lambda and QP values for all possible QP candidates
    601   for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )
    602   {
    603     // compute QP value
    604     recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);
    605 
    606     // compute lambda value
    607     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    608     Int    SHIFT_QP = 12;
    609     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
    610 #if FULL_NBIT
    611     Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
    612 #else
    613     Int    bitdepth_luma_qp_scale = 0;
    614 #endif
    615     Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;
    616 #if FULL_NBIT
    617     Double qp_temp_orig = (Double) recalQP - SHIFT_QP;
    618 #endif
    619     // Case #1: I or P-slices (key-frame)
    620     Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;
    621     if ( eSliceType==I_SLICE )
    622     {
    623       dQPFactor=0.57*dLambda_scale;
    624     }
    625     lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
    626 
    627     if ( depth>0 )
    628     {
    629 #if FULL_NBIT
    630       lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    631 #else
    632       lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    633 #endif
    634     }
    635 
    636     // if hadamard is used in ME process
    637     if ( !m_pcCfg->getUseHADME() )
    638     {
    639       lambda *= 0.95;
    640     }
    641 
    642 #if REPN_FORMAT_IN_VPS
    643     qp = max( -pcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
    644 #else
    645     qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
    646 #endif
    647 
    648     m_pdRdPicLambda[deltqQpIdx] = lambda;
    649     m_pdRdPicQp    [deltqQpIdx] = recalQP;
    650     m_piRdPicQp    [deltqQpIdx] = qp;
    651   }
    652 
    653   // obtain dQP = 0 case
    654   lambda  = m_pdRdPicLambda[0];
    655   recalQP = m_pdRdPicQp    [0];
    656   qp      = m_piRdPicQp    [0];
    657 
    658   if( pcSlice->getSliceType( ) != I_SLICE )
    659   {
    660     lambda *= m_pcCfg->getLambdaModifier( depth );
    661   }
    662 
    663   // store lambda
    664   m_pcRdCost ->setLambda( lambda );
    665 #if WEIGHTED_CHROMA_DISTORTION
    666   // for RDO
    667   // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    668   Double weight = 1.0;
    669   Int qpc;
    670   Int chromaQPOffset;
    671 
    672   chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    673   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    674   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    675   m_pcRdCost->setCbDistortionWeight(weight);
    676 
    677   chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    678   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    679   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    680   m_pcRdCost->setCrDistortionWeight(weight);
    681 #endif
    682 
    683 #if RDOQ_CHROMA_LAMBDA
    684   // for RDOQ
    685   m_pcTrQuant->setLambda( lambda, lambda / weight );
    686 #else
    687   m_pcTrQuant->setLambda( lambda );
    688 #endif
    689 
    690 #if SAO_CHROMA_LAMBDA
    691   // For SAO
    692   pcSlice   ->setLambda( lambda, lambda / weight );
    693 #else
    694   pcSlice   ->setLambda( lambda );
    695 #endif
    696 }
    697 #endif
    698585// ====================================================================================================================
    699586// Public member functions
     
    735622  }
    736623
    737 #if RATE_CONTROL_LAMBDA_DOMAIN
    738624  if ( m_pcCfg->getUseRateCtrl() )
    739625  {
     
    741627    assert(0);
    742628  }
    743 #endif
    744629
    745630  TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
     
    773658#endif
    774659    m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    775 #if WEIGHTED_CHROMA_DISTORTION
    776660    // for RDO
    777661    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    778662    Int iQP = m_piRdPicQp    [uiQpIdx];
    779     Double weight = 1.0;
     663    Double weight[2] = { 1.0, 1.0 };
    780664    Int qpc;
    781665    Int chromaQPOffset;
     
    783667    chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    784668    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    785     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    786     m_pcRdCost->setCbDistortionWeight(weight);
     669    weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     670    m_pcRdCost->setCbDistortionWeight(weight[0]);
    787671
    788672    chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    789673    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    790     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    791     m_pcRdCost->setCrDistortionWeight(weight);
    792 #endif
    793 
     674    weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     675    m_pcRdCost->setCrDistortionWeight(weight[1]);
     676
     677    const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])};
    794678#if RDOQ_CHROMA_LAMBDA
    795679    // for RDOQ
    796     m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
     680    m_pcTrQuant->setLambdas( lambdaArray );
    797681#else
    798682    m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    799683#endif
    800 #if SAO_CHROMA_LAMBDA
    801684    // For SAO
    802     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
    803 #else
    804     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    805 #endif
     685    pcSlice->setLambdas( lambdaArray );
    806686
    807687    // try compress
     
    830710#endif
    831711  m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    832 #if WEIGHTED_CHROMA_DISTORTION
    833712  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    834713  Int iQP = m_piRdPicQp    [uiQpIdxBest];
    835   Double weight = 1.0;
     714  Double weight[2] = { 1.0, 1.0 };
    836715  Int qpc;
    837716  Int chromaQPOffset;
     
    839718  chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    840719  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    841   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    842   m_pcRdCost->setCbDistortionWeight(weight);
     720  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     721  m_pcRdCost->setCbDistortionWeight(weight[0]);
    843722
    844723  chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    845724  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    846   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    847   m_pcRdCost->setCrDistortionWeight(weight);
    848 #endif
    849 
     725  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     726  m_pcRdCost->setCrDistortionWeight(weight[1]);
     727
     728  const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])};
    850729#if RDOQ_CHROMA_LAMBDA
    851730  // for RDOQ
    852   m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
     731  m_pcTrQuant->setLambdas( lambdaArray );
    853732#else
    854733  m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    855734#endif
    856 #if SAO_CHROMA_LAMBDA
    857735  // For SAO
    858   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
    859 #else
    860   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    861 #endif
     736  pcSlice->setLambdas( lambdaArray );
    862737}
    863738
    864739/** \param rpcPic   picture class
    865740 */
    866 #if RATE_CONTROL_INTRA
    867741Void TEncSlice::calCostSliceI(TComPic*& rpcPic)
    868742{
     
    903777  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
    904778}
    905 #endif
    906779
    907780Void TEncSlice::compressSlice( TComPic*& rpcPic )
     
    1031904  UInt uiTileStartLCU = 0;
    1032905  UInt uiTileLCUX     = 0;
    1033 
    1034906  Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
    1035907  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     
    1080952    pcCU->initCU( rpcPic, uiCUAddr );
    1081953
    1082 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1083     if(m_pcCfg->getUseRateCtrl())
    1084     {
    1085       if(m_pcRateCtrl->calculateUnitQP())
    1086       {
    1087         xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );
    1088       }
    1089     }
    1090 #endif
    1091954    // inherit from TR if necessary, select substream to use.
    1092955    if( m_pcCfg->getUseSBACRD() )
     
    11631026      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
    11641027
    1165 #if RATE_CONTROL_LAMBDA_DOMAIN
    11661028      Double oldLambda = m_pcRdCost->getLambda();
    11671029      if ( m_pcCfg->getUseRateCtrl() )
     
    11711033        Double bpp       = -1.0;
    11721034
    1173 #if M0036_RC_IMPROVEMENT
    11741035        if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
    1175 #else
    1176         if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
    1177 #endif
    11781036        {
    11791037          estQP = pcSlice->getSliceQp();
     
    11811039        else
    11821040        {
    1183 #if RATE_CONTROL_INTRA
    11841041          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
    11851042          if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
     
    11921049            estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    11931050          }
    1194 #else
    1195           bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
    1196           estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
    1197           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    1198 #endif
    11991051
    12001052#if REPN_FORMAT_IN_VPS
     
    12051057
    12061058          m_pcRdCost->setLambda(estLambda);
    1207 #if M0036_RC_IMPROVEMENT
    12081059#if RDOQ_CHROMA_LAMBDA
    12091060          // set lambda for RDOQ
    12101061          Double weight=m_pcRdCost->getChromaWeight();
    1211           m_pcTrQuant->setLambda( estLambda, estLambda / weight );
     1062          const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) };
     1063          m_pcTrQuant->setLambdas( lambdaArray );
    12121064#else
    12131065          m_pcTrQuant->setLambda( estLambda );
    1214 #endif
    12151066#endif
    12161067        }
     
    12191070        pcCU->getSlice()->setSliceQpBase( estQP );
    12201071      }
    1221 #endif
    12221072
    12231073      // run CU encoder
    12241074      m_pcCuEncoder->compressCU( pcCU );
    1225 
    1226 #if !TICKET_1090_FIX
    1227 #if RATE_CONTROL_LAMBDA_DOMAIN
    1228       if ( m_pcCfg->getUseRateCtrl() )
    1229       {
    1230 #if !M0036_RC_IMPROVEMENT
    1231         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    1232 #if REPN_FORMAT_IN_VPS
    1233         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1234         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->>getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1235 #else
    1236         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1237         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1238 #endif
    1239         Double MAD = (Double)SAD / (Double)(height * width);
    1240         MAD = MAD * MAD;
    1241         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
    1242 #endif
    1243 
    1244         Int actualQP        = g_RCInvalidQPValue;
    1245         Double actualLambda = m_pcRdCost->getLambda();
    1246         Int actualBits      = pcCU->getTotalBits();
    1247         Int numberOfEffectivePixels    = 0;
    1248         for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
    1249         {
    1250           if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
    1251           {
    1252             numberOfEffectivePixels = numberOfEffectivePixels + 16;
    1253             break;
    1254           }
    1255         }
    1256 
    1257         if ( numberOfEffectivePixels == 0 )
    1258         {
    1259           actualQP = g_RCInvalidQPValue;
    1260         }
    1261         else
    1262         {
    1263           actualQP = pcCU->getQP( 0 );
    1264         }
    1265         m_pcRdCost->setLambda(oldLambda);
    1266 #if RATE_CONTROL_INTRA
    1267         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    1268           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1269 #else
    1270         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1271 #endif
    1272       }
    1273 #endif
    1274 #endif
    12751075
    12761076      // restore entropy coder to an initial stage
     
    13061106      }
    13071107
    1308 #if TICKET_1090_FIX
    1309 #if RATE_CONTROL_LAMBDA_DOMAIN
    13101108      if ( m_pcCfg->getUseRateCtrl() )
    13111109      {
    1312 #if !M0036_RC_IMPROVEMENT
    1313         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    1314 #if REPN_FORMAT_IN_VPS
    1315         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1316         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1317 #else
    1318         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1319         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1320 #endif
    1321         Double MAD = (Double)SAD / (Double)(height * width);
    1322         MAD = MAD * MAD;
    1323         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
    1324 #endif
    13251110
    13261111        Int actualQP        = g_RCInvalidQPValue;
     
    13471132        m_pcRdCost->setLambda(oldLambda);
    13481133
    1349 #if RATE_CONTROL_INTRA
    13501134        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    13511135          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1352 #else
    1353         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1354 #endif
    1355       }
    1356 #endif
    1357 #endif
     1136      }
    13581137    }
    13591138    // other case: encodeCU is not called
     
    13771156    m_dPicRdCost     += pcCU->getTotalCost();
    13781157    m_uiPicDist      += pcCU->getTotalDistortion();
    1379 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1380     if(m_pcCfg->getUseRateCtrl())
    1381     {
    1382       m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));
    1383       m_pcRateCtrl->updataRCUnitStatus();
    1384     }
    1385 #endif
    13861158  }
    13871159  if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled)
     
    13981170  }
    13991171  xRestoreWPparam( pcSlice );
    1400 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1401   if(m_pcCfg->getUseRateCtrl())
    1402   {
    1403     m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
    1404   }
    1405 #endif
    14061172}
    14071173
     
    16031369
    16041370    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     1371#if HM_CLEANUP_SAO
     1372    if ( pcSlice->getSPS()->getUseSAO() )
     1373    {
     1374      if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     1375      {
     1376        SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr];
     1377        Bool sliceEnabled[NUM_SAO_COMPONENTS];
     1378        sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
     1379        sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
     1380
     1381        Bool leftMergeAvail = false;
     1382        Bool aboveMergeAvail= false;
     1383        //merge left condition
     1384        Int rx = (uiCUAddr % uiWidthInLCUs);
     1385        if(rx > 0)
     1386        {
     1387          leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1);
     1388        }
     1389
     1390        //merge up condition
     1391        Int ry = (uiCUAddr / uiWidthInLCUs);
     1392        if(ry > 0)
     1393        {
     1394          aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs);
     1395        }
     1396
     1397        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail);
     1398      }
     1399    }
     1400#else
    16051401    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    16061402    {
     
    16851481      }
    16861482    }
     1483#endif
     1484
    16871485#if ENC_DEC_TRACE
    16881486    g_bJustDoIt = g_bEncDecTraceEnable;
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r494 r540  
    131131#endif
    132132
    133 #if RATE_CONTROL_LAMBDA_DOMAIN
    134133  Void    resetQP             ( TComPic* pic, Int sliceQP, Double lambda );
    135 #else
    136   Void    xLamdaRecalculation ( Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice);
    137 #endif
    138134  // compress and encode slice
    139135  Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
    140136  Void    compressSlice       ( TComPic*& rpcPic                                );      ///< analysis stage of slice
    141 #if RATE_CONTROL_INTRA
    142137  Void    calCostSliceI       ( TComPic*& rpcPic );
    143 #endif
    144138  Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams  );
    145139 
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r494 r540  
    9292  m_pocAdjustmentValue     = 0;
    9393#endif
     94#if NO_CLRAS_OUTPUT_FLAG
     95  m_noClrasOutputFlag          = false;
     96  m_layerInitializedFlag       = false;
     97  m_firstPicInLayerDecodedFlag = false;
     98  m_noOutputOfPriorPicsFlags   = false;
     99#endif
    94100#endif //SVC_EXTENSION
    95101}
     
    123129  if (m_bUseSAO)
    124130  {
     131#if HM_CLEANUP_SAO
     132#if AUXILIARY_PICTURES
     133    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     134#else
     135    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     136#endif
     137#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     138    m_cEncSAO.createEncData(getSaoLcuBoundary());
     139#else
     140    m_cEncSAO.createEncData();
     141#endif
     142#else
    125143    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
    126144    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
     
    128146    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
    129147    m_cEncSAO.createEncBuffer();
     148#endif
    130149  }
    131150#if ADAPTIVE_QP_SELECTION
     
    137156  m_cLoopFilter.        create( g_uiMaxCUDepth );
    138157 
    139 #if RATE_CONTROL_LAMBDA_DOMAIN
    140158  if ( m_RCEnableRateControl )
    141159  {
     
    143161                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
    144162  }
    145 #else
    146   m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
    147 #endif
    148163  // if SBAC-based RD optimization is used
    149164  if( m_bUseSBACRD )
     
    244259  if (m_cSPS.getUseSAO())
    245260  {
     261#if HM_CLEANUP_SAO
     262    m_cEncSAO.destroyEncData();
     263    m_cEncSAO.destroy();
     264#else
    246265    m_cEncSAO.destroy();
    247266    m_cEncSAO.destroyEncBuffer();
     267#endif
    248268  }
    249269  m_cLoopFilter.        destroy();
     
    395415{
    396416  // compress GOP
    397 #if RATE_CONTROL_LAMBDA_DOMAIN
    398417#if !RC_SHVC_HARMONIZATION
    399418  if ( m_RCEnableRateControl )
     
    402421  }
    403422#endif
    404 #endif
    405423
    406424  // compress GOP
    407425  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    408426
    409 #if RATE_CONTROL_LAMBDA_DOMAIN
    410427#if !RC_SHVC_HARMONIZATION
    411428  if ( m_RCEnableRateControl )
     
    413430    m_cRateCtrl.destroyRCGOP();
    414431  }
    415 #endif
    416432#endif
    417433 
     
    457473  }
    458474 
    459 #if RATE_CONTROL_LAMBDA_DOMAIN
    460475  if ( m_RCEnableRateControl )
    461476  {
    462477    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
    463478  }
    464 #endif
    465479
    466480  // compress GOP
     
    468482  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    469483
    470 #if RATE_CONTROL_LAMBDA_DOMAIN
    471484  if ( m_RCEnableRateControl )
    472485  {
    473486    m_cRateCtrl.destroyRCGOP();
    474487  }
    475 #endif
    476488 
    477489  iNumEncoded         = m_iNumPicRcvd;
     
    513525    TComPic *pcTopField;
    514526    xGetNewPicBuffer( pcTopField );
     527#if !HM_CLEANUP_SAO
    515528    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     529#endif
    516530    pcTopField->setReconMark (false);
    517531   
     
    534548    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
    535549    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
    536    
     550
    537551    // compute image characteristics
    538552    if ( getUseAdaptiveQP() )
    539553    {
    540554      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
    541     }
    542    
     555    }   
     556
    543557    /* -- Defield -- */
    544558   
     
    554568    TComPic* pcBottomField;
    555569    xGetNewPicBuffer( pcBottomField );
     570#if !HM_CLEANUP_SAO
    556571    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     572#endif
    557573    pcBottomField->setReconMark (false);
    558574   
     
    575591    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
    576592    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
    577    
    578     // Compute image characteristics
     593
     594    // compute image characteristics
    579595    if ( getUseAdaptiveQP() )
    580596    {
    581597      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
    582     }
    583    
     598    }       
     599
    584600    /* -- Defield -- */
    585601   
     
    636652    TComPic *pcTopField;
    637653    xGetNewPicBuffer( pcTopField );
     654#if !HM_CLEANUP_SAO
    638655    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     656#endif
    639657    pcTopField->setReconMark (false);
    640658   
     
    688706    TComPic* pcBottomField;
    689707    xGetNewPicBuffer( pcBottomField );
     708#if !HM_CLEANUP_SAO
    690709    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     710#endif
    691711    pcBottomField->setReconMark (false);
    692712   
    693     TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     713    TComPicYuv* rpcPicYuvRec;
    694714    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
    695715    {
     
    698718    else
    699719    {
     720      rpcPicYuvRec = new TComPicYuv;
    700721      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    701722    }
     
    791812        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
    792813        {
     814#if O0098_SCALED_REF_LAYER_ID
     815          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     816#else
    793817          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
     818#endif
    794819          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
    795820
     
    842867        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
    843868        {
     869#if O0098_SCALED_REF_LAYER_ID
     870          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     871#else
    844872          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
     873#endif
    845874          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
    846875
     
    883912#endif
    884913    }
    885 
     914#if !HM_CLEANUP_SAO
    886915    if (getUseSAO())
    887916    {
    888917      rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
    889918    }
     919#endif
    890920    m_cListPic.pushBack( rpcPic );
    891921  }
     
    912942  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
    913943  {
     944#if O0098_SCALED_REF_LAYER_ID
     945    m_cSPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]);
     946#endif
    914947    m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
    915948  }
     
    10631096Void TEncTop::xInitPPS()
    10641097{
    1065 #if IL_SL_SIGNALLING_N0371
    1066   m_cPPS.setLayerId(m_layerId);
     1098#if SCALINGLIST_INFERRING
     1099  m_cPPS.setLayerId( m_layerId );
    10671100#endif
    10681101
     
    10721105#if REPN_FORMAT_IN_VPS
    10731106  Int lowestQP;
     1107#if O0096_REP_FORMAT_INDEX
     1108  if( m_layerId == 0 )
     1109  {
     1110    lowestQP = - m_cSPS.getQpBDOffsetY();
     1111  }
     1112  else
     1113  {
     1114    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
     1115  }
     1116#else
    10741117  if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
    10751118  {
     
    10801123    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
    10811124  }
     1125#endif
    10821126#else
    10831127  Int lowestQP = - m_cSPS.getQpBDOffsetY();
     
    11191163  }
    11201164
    1121 #if RATE_CONTROL_LAMBDA_DOMAIN
    11221165  if ( m_RCEnableRateControl )
    11231166  {
     
    11261169    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
    11271170  }
    1128 #endif
    11291171
    11301172  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
     
    12091251#if POC_RESET_FLAG
    12101252  m_cPPS.setNumExtraSliceHeaderBits( 2 );
     1253#endif
     1254#if O0149_CROSS_LAYER_BLA_FLAG
     1255  if (m_crossLayerBLAFlag)
     1256  {
     1257    m_cPPS.setNumExtraSliceHeaderBits( 3 );
     1258  }
    12111259#endif
    12121260}
     
    16071655Void TEncTop::xInitILRP()
    16081656{
     1657#if O0096_REP_FORMAT_INDEX
     1658  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) );
     1659#else
    16091660  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
     1661#endif
    16101662  Int bitDepthY,bitDepthC,picWidth,picHeight;
    16111663
     1664#if O0096_REP_FORMAT_INDEX
     1665  bitDepthY   = repFormat->getBitDepthVpsLuma();
     1666  bitDepthC   = repFormat->getBitDepthVpsChroma();
     1667  picWidth    = repFormat->getPicWidthVpsInLumaSamples();
     1668  picHeight   = repFormat->getPicHeightVpsInLumaSamples();
     1669#else
    16121670  if( m_cSPS.getUpdateRepFormatFlag() )
    16131671  {
     
    16241682    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
    16251683  }
     1684#endif
    16261685 
    16271686  if(m_layerId > 0)
     
    16611720}
    16621721#endif
     1722
     1723#if O0098_SCALED_REF_LAYER_ID
     1724Window& TEncTop::getScaledRefLayerWindowForLayer(Int layerId)
     1725{
     1726  static Window win;
     1727
     1728  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
     1729  {
     1730    if (layerId == m_scaledRefLayerId[i])
     1731    {
     1732      return m_scaledRefLayerWindow[i];
     1733    }
     1734  }
     1735
     1736  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
     1737  return win;
     1738}
     1739#endif
     1740
    16631741#endif //SVC_EXTENSION
    16641742//! \}
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r494 r540  
    8383  // encoder search
    8484  TEncSearch              m_cSearch;                      ///< encoder search class
    85   TEncEntropy*            m_pcEntropyCoder;                     ///< entropy encoder
     85  //TEncEntropy*            m_pcEntropyCoder;                     ///< entropy encoder
    8686  TEncCavlc*              m_pcCavlcCoder;                       ///< CAVLC encoder 
    8787  // coding tool
     
    141141#endif
    142142  UInt                    m_numScaledRefLayerOffsets;
     143#if O0098_SCALED_REF_LAYER_ID
     144  UInt                    m_scaledRefLayerId[MAX_LAYERS];
     145#endif
    143146  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
    144147#if POC_RESET_FLAG
    145148  Int                     m_pocAdjustmentValue;
     149#endif
     150#if NO_CLRAS_OUTPUT_FLAG
     151  Bool                    m_noClrasOutputFlag;
     152  Bool                    m_layerInitializedFlag;
     153  Bool                    m_firstPicInLayerDecodedFlag;
     154  Bool                    m_noOutputOfPriorPicsFlags;
    146155#endif
    147156#endif //SVC_EXTENSION
     
    209218  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
    210219  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
     220#if O0098_SCALED_REF_LAYER_ID
     221  Void                    setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
     222  UInt                    getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
     223  Window&  getScaledRefLayerWindowForLayer(Int layerId);
     224#endif
    211225  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
    212226#endif //SVC_EXTENSION
     
    242256  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
    243257#endif
     258#if NO_CLRAS_OUTPUT_FLAG
     259  Int  getNoClrasOutputFlag()                { return m_noClrasOutputFlag;}
     260  Void setNoClrasOutputFlag(Bool x)          { m_noClrasOutputFlag = x;   }
     261  Int  getLayerInitializedFlag()             { return m_layerInitializedFlag;}
     262  Void setLayerInitializedFlag(Bool x)       { m_layerInitializedFlag = x;   }
     263  Int  getFirstPicInLayerDecodedFlag()       { return m_firstPicInLayerDecodedFlag;}
     264  Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x;   }
     265  Int  getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
     266  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
     267#endif
    244268#else //SVC_EXTENSION
    245269  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
Note: See TracChangeset for help on using the changeset viewer.