Changeset 443 in 3DVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
26 May 2013, 15:41:34 (12 years ago)
Author:
tech
Message:
  • Reintegrated branch 6.2-dev0 rev. 442.
  • Changed version number.
  • Added coding results.
Location:
trunk/source/Lib/TLibEncoder
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r332 r443  
    711711        WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" );
    712712#endif
    713 #if H3D_IVRP
     713#if H3D_IVRP & !QC_ARP_D0177
    714714        WRITE_FLAG  ( pcSPS->getMultiviewResPredMode(), "multi_view_residual_pred_mode" );
    715715#endif
    716716      }
    717717#endif
    718     }
     718#if QC_ARP_D0177
     719      WRITE_FLAG( pcSPS->getUseAdvRP () ? 1 : 0,       "advanced_residual_pred_flag"  );
     720#endif
     721    }
     722
     723#if MTK_D0156
     724#if MERL_VSP_COMPENSATION_C0152
     725    WRITE_FLAG( pcSPS->getUseVSPCompensation() ? 1 : 0,              "view_synthesis_pred_flag" );
     726#endif
     727
     728    WRITE_FLAG( pcSPS->getUseDVPRefine() ? 1 : 0,                    "dv_refine_flag" );
     729#endif
    719730  }
    720731  else
     
    790801      WRITE_FLAG( pcSlice->getApplyIC() ? 1 : 0, "applying IC flag" );
    791802    }
     803#if SHARP_ILLUCOMP_PARSE_D0060
     804    if (pcSlice->getApplyIC())
     805    {
     806      WRITE_FLAG( pcSlice->getIcSkipParseFlag() ? 1 : 0, "ic_skip_mergeidx0" );
     807    }
     808#endif
    792809  }
    793810#endif
     
    957974      if (pcSlice->getSPS()->getUseSAO())
    958975      {
     976#if LGE_SAO_MIGRATION_D0091
     977        WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
     978        {
     979            SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
     980            WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
     981        }
     982#else
    959983        WRITE_FLAG( pcSlice->getSaoInterleavingFlag(), "SAO interleaving flag" );
    960984         assert (pcSlice->getSaoEnabledFlag() == pcSlice->getAPS()->getSaoEnabled());
     
    965989           WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[2], "SAO on/off flag for Cr in slice header" );
    966990         }
     991#endif
    967992      }
    968993      WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id");
     
    13211346}
    13221347#endif
    1323 
     1348#if QC_ARP_D0177
     1349Void TEncCavlc::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1350{
     1351  assert( false );
     1352}
     1353#endif
    13241354Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    13251355
     
    14061436}
    14071437
    1408 Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1438Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     1439#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1440                                    , Bool bSdcRD
     1441#endif
     1442                                    )
    14091443{
    14101444  assert(0);
     
    14911525  }
    14921526}
    1493 
     1527#if !LGE_SAO_MIGRATION_D0091
    14941528Void TEncCavlc::codeSaoFlag( UInt uiCode )
    14951529{
     
    15291563  WRITE_CODE( uiCode, uiLength, "sao_run_diff");
    15301564}
     1565#endif
    15311566
    15321567Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
     
    18841919
    18851920#if RWTH_SDC_DLT_B0036
     1921#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    18861922Void TEncCavlc::codeSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    18871923{
    18881924  assert(0);
    18891925}
    1890 
     1926#endif
    18911927Void TEncCavlc::codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
    18921928{
    18931929  assert(0);
    18941930}
    1895 
     1931#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    18961932Void TEncCavlc::codeSDCPredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    18971933{
     
    18991935}
    19001936#endif
     1937#endif
    19011938//! \}
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r332 r443  
    142142  Void codeAPSAlflag(UInt uiCode);
    143143  Void codeAlfFixedLengthIdx( UInt idx, UInt numFilterSetsInBuffer);
     144#if LGE_SAO_MIGRATION_D0091
     145  Void codeSAOSign       ( UInt code   ) { printf("Not supported\n"); assert (0); }
     146  Void codeSaoMaxUvlc    ( UInt   code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}
     147  Void codeSaoMerge  ( UInt uiCode ){printf("Not supported\n"); assert (0);}
     148  Void codeSaoTypeIdx    ( UInt uiCode ){printf("Not supported\n"); assert (0);}
     149  Void codeSaoUflc       ( UInt uiLength, UInt   uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}
     150#else
    144151  Void codeSaoFlag       ( UInt uiCode );
    145152  Void codeSaoUvlc       ( UInt uiCode );
     
    150157  Void codeSaoTypeIdx    ( UInt uiCode ){ xWriteUvlc(uiCode   );}
    151158  Void codeSaoUflc       ( UInt uiCode ){ assert(uiCode < 32); xWriteCode(uiCode, 5);}
     159#endif
    152160
    153161  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    160168  Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    161169#endif
     170#if QC_ARP_D0177
     171  virtual Void codeARPW ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     172#endif
    162173  Void codeAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    163174
     
    183194  Void codeQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    184195 
    185   Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx );
     196  Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     197#if PKU_QC_DEPTH_INTRA_UNI_D0195
     198    , Bool bSdcRD = false
     199#endif
     200    );
    186201 
    187202  Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    209224 
    210225#if RWTH_SDC_DLT_B0036
     226#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    211227  Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     228#endif
    212229  Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
     230#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    213231  Void codeSDCPredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    214232#endif
     233#endif
    215234
    216235};
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r332 r443  
    160160#endif
    161161  Int       m_maxNumOffsetsPerPic;
     162#if LGE_SAO_MIGRATION_D0091
     163  Bool      m_saoLcuBoundary;
     164  Bool      m_saoLcuBasedOptimization;
     165#else
    162166  Bool      m_saoInterleavingFlag;
     167#endif
    163168
    164169  //====== Lossless ========
     
    333338#endif
    334339#if H3D_IVRP
     340#if QC_ARP_D0177
     341  UInt      m_nUseAdvResPred;
     342  UInt      m_nARPStepNum;
     343#else
    335344  UInt        m_uiMultiviewResPredMode;
     345#endif
     346#endif
     347
     348#if MTK_D0156
     349#if MERL_VSP_COMPENSATION_C0152
     350  Bool      m_bUseVSPCompensation;
     351#endif
     352  Bool      m_bUseDVPRefine;
    336353#endif
    337354
     
    414431#endif
    415432#if H3D_IVRP
     433#if QC_ARP_D0177
     434  UInt       getUseAdvRP                    ()                  { return m_nUseAdvResPred; }
     435  Void       setUseAdvRP                    ( UInt  u )         { m_nUseAdvResPred = u;    }
     436  UInt       getARPStepNum                  ()                  { return m_nARPStepNum;    }
     437  Void       setARPStepNum                  ( UInt  u )         { m_nARPStepNum = u;       }
     438#else
    416439  Void      setMultiviewResPredMode         ( UInt  u )      { m_uiMultiviewResPredMode     = u; }
     440#endif
    417441#endif
    418442 
     
    661685  Void  setMaxNumOffsetsPerPic                   (Int iVal)            { m_maxNumOffsetsPerPic = iVal; }
    662686  Int   getMaxNumOffsetsPerPic                   ()                    { return m_maxNumOffsetsPerPic; }
     687#if LGE_SAO_MIGRATION_D0091
     688  Void  setSaoLcuBoundary              (Bool val)      { m_saoLcuBoundary = val; }
     689  Bool  getSaoLcuBoundary              ()              { return m_saoLcuBoundary; }
     690  Void  setSaoLcuBasedOptimization               (Bool val)            { m_saoLcuBasedOptimization = val; }
     691  Bool  getSaoLcuBasedOptimization               ()                    { return m_saoLcuBasedOptimization; }
     692#else
    663693  Void  setSaoInterleavingFlag                   (bool bVal)           { m_saoInterleavingFlag = bVal; }
    664694  Bool  getSaoInterleavingFlag                   ()                    { return m_saoInterleavingFlag; }
     695#endif
    665696  Void  setTileBehaviorControlPresentFlag        ( Int i )             { m_iTileBehaviorControlPresentFlag = i;    }
    666697  Int   getTileBehaviorControlPresentFlag        ()                    { return m_iTileBehaviorControlPresentFlag; }
     
    809840  Int       getViewOrderIdx                 ()      { return  m_iViewOrderIdx; }    // will be changed to view_id
    810841#endif
     842
     843#if MTK_D0156
     844
     845#if MERL_VSP_COMPENSATION_C0152
     846  Bool    getUseVSPCompensation( ){  return m_bUseVSPCompensation;}
     847  Void    setUseVSPCompensation( Bool bValue ){ m_bUseVSPCompensation = bValue;}
     848#endif
     849
     850
     851  Bool    getUseDVPRefine( ){  return m_bUseDVPRefine;}
     852  Void    setUseDVPRefine( Bool bValue ){ m_bUseDVPRefine = bValue;}
     853#endif
     854
    811855};
    812856
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r332 r443  
    6464  m_ppcBestCU      = new TComDataCU*[m_uhTotalDepth-1];
    6565  m_ppcTempCU      = new TComDataCU*[m_uhTotalDepth-1];
    66  
     66#if QC_ARP_D0177
     67  m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1];
     68#endif
    6769  m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1];
    6870  m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1];
     
    9193    m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    9294    m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
    93    
     95#if QC_ARP_D0177
     96    m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) );
     97#endif   
    9498    m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight);
    9599    m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight);
     
    170174    {
    171175      m_ppcResPredTmp [i]->destroy(); delete m_ppcResPredTmp[i];  m_ppcResPredTmp[i] = NULL;
     176    }
     177#endif
     178#if QC_ARP_D0177
     179    if(m_ppcWeightedTempCU[i])
     180    {
     181      m_ppcWeightedTempCU[i]->destroy(); delete m_ppcWeightedTempCU[i]; m_ppcWeightedTempCU[i] = NULL;
    172182    }
    173183#endif
     
    591601      }
    592602#endif
    593 
     603#if QC_CU_NBDV_D0181
     604      DisInfo DvInfo;
     605      DvInfo.bDV = false;
     606      if( rpcTempCU->getSlice()->getSliceType() != I_SLICE )
     607      {
     608#if QC_ARP_D0177
     609        if(( rpcTempCU->getSlice()->getSPS()->getMultiviewMvPredMode() || rpcTempCU->getSlice()->getSPS()->getUseAdvRP()) && rpcTempCU->getSlice()->getViewId())
     610#else
     611        if(( rpcTempCU->getSlice()->getSPS()->getMultiviewMvPredMode() || rpcTempCU->getSlice()->getSPS()->getMultiviewResPredMode()) && rpcTempCU->getSlice()->getViewId())
     612#endif
     613        { 
     614          PartSize ePartTemp = rpcTempCU->getPartitionSize(0);
     615          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth );     
     616#if MERL_VSP_C0152
     617          DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(0, 0, &DvInfo, false, true);
     618#else
     619          DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(0, 0, &DvInfo, false);
     620#endif
     621          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     622          rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     623          rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth );
     624        }
     625
     626        if(DvInfo.bDV==false)
     627        {
     628          DvInfo.iN=1;
     629#if !SEC_DEFAULT_DV_D0112
     630          DvInfo.m_acMvCand[0].setHor(0);
     631          DvInfo.m_acMvCand[0].setVer(0);
     632          DvInfo.m_aVIdxCan[0] = 0;
     633#endif
     634          rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     635          rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     636         }
     637       }
     638#endif
    594639      // do inter modes, SKIP and 2Nx2N
    595640      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
    596641      {
    597642#if H3D_IVRP
     643#if QC_ARP_D0177
     644        Bool  bResPredAvailable   = false;
     645        Bool  bResPredAllowed     =                    (!rpcBestCU->getSlice()->getSPS()->isDepth                () );
     646        bResPredAllowed           = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId              () );
     647        if( bResPredAllowed )
     648        {
     649          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, true, m_ppcResPredTmp[uiDepth] );
     650        }
     651        for( UInt uiResPrdId = 0; uiResPrdId < (rpcBestCU->getSlice()->getSPS()->getUseAdvRP()? 1: ( bResPredAvailable ? 2 : 1 )); uiResPrdId++ )
     652#else
    598653        Bool  bResPredAvailable   = false;
    599654        UInt uiResPrdId = 0;
     655#endif
    600656        {
    601657          Bool bResPredFlag  = ( uiResPrdId > 0 );
     
    665721
    666722#if LGE_ILLUCOMP_B0045
     723#if SHARP_ILLUCOMP_PARSE_D0060
     724    bICEnabled = false;
     725#else
    667726    bICEnabled = rpcBestCU->getICFlag(0);
     727#endif
    668728#endif
    669729
     
    715775      {
    716776#if H3D_IVRP
     777#if QC_ARP_D0177
     778        Bool  bResPredAvailable   = false;
     779        Bool  bResPredAllowed     =                    (!rpcBestCU->getSlice()->getSPS()->isDepth                () );
     780        bResPredAllowed           = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId              () );
     781        if( bResPredAllowed )
     782        {
     783          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, true, m_ppcResPredTmp[uiDepth] );
     784        }
     785        for( UInt uiResPrdId = 0; uiResPrdId < (rpcBestCU->getSlice()->getSPS()->getUseAdvRP()? 1: ( bResPredAvailable ? 2 : 1 )); uiResPrdId++ )
     786#else
    717787        Bool  bResPredAvailable   = false;
    718788        UInt uiResPrdId = 0;
     789#endif
    719790        {
    720791          Bool bResPredFlag  = ( uiResPrdId > 0 );
    721792#if LGE_ILLUCOMP_B0045
     793#if SHARP_ILLUCOMP_PARSE_D0060
     794          {
     795            Bool bICFlag = false;
     796            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     797#else
    722798          for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++)
    723799          {
    724800            Bool bICFlag = (uiICId ? true : false);
    725801            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     802#endif
    726803#endif
    727804#endif
     
    16481725  UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    16491726  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    1650  
     1727
    16511728  if( getCheckBurstIPCMFlag() )
    16521729  {
     
    17601837  {
    17611838    m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 );
     1839
    17621840#if LGE_ILLUCOMP_B0045
    17631841    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx
     
    17671845        );
    17681846#endif
     1847#if QC_ARP_D0177
     1848    m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx, 0, uiDepth);
     1849#endif
    17691850    finishCU(pcCU,uiAbsPartIdx,uiDepth);
    17701851    return;
     
    17751856#endif
    17761857  m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
    1777  
     1858
    17781859  m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
    1779  
     1860
    17801861  if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
    17811862  {
     
    17921873  // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
    17931874  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
     1875
    17941876#if LGE_ILLUCOMP_B0045
    17951877    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx
     
    18331915  Int numValidMergeCand = 0;
    18341916
     1917#if QC_ARP_D0177
     1918  Bool  bResPrdAvail  = rpcTempCU->getResPredAvail( 0 );
     1919  Bool  bResPrdFlag   = rpcTempCU->getResPredFlag ( 0 );
     1920#endif
    18351921#if LGE_ILLUCOMP_B0045
    18361922  Bool  bICFlag = rpcTempCU->getICFlag(0);
     
    18601946  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    18611947#if MERL_VSP_C0152
     1948#if LGE_VSP_INHERIT_D0092
     1949  Int iVSPIndexTrue[MRG_MAX_NUM_CANDS_MEM];
     1950  for (Int i=0; i<MRG_MAX_NUM_CANDS_MEM; i++)
     1951  {
     1952     iVSPIndexTrue[i] = 0;
     1953  }
     1954#else
    18621955  Int iVSPIndexTrue[3] = {-1, -1, -1};
     1956#endif
     1957#if MERL_VSP_NBDV_RefVId_Fix_D0166
     1958  Int iVSPDirTrue[3]   = {-1, -1, -1};
     1959  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue, iVSPDirTrue );
     1960#else
    18631961  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
     1962#endif
    18641963#else
    18651964  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
    18661965#endif
    1867 #if H3D_IVRP
     1966#if H3D_IVRP & !QC_ARP_D0177
    18681967  Bool bResPredAvail = rpcTempCU->getResPredAvail(0);
    18691968#endif
    18701969
    18711970  Bool bestIsSkip = false;
    1872  
     1971#if QC_ARP_D0177
     1972  Int nGRPW = rpcTempCU->getSlice()->getARPStepNum() - 1;
     1973  if(nGRPW < 0 || !bResPrdAvail )
     1974    nGRPW = 0;
     1975  for( ; nGRPW >= 0 ; nGRPW-- )
     1976  {
     1977#endif 
    18731978  for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
    18741979  {
    18751980    {
    18761981      TComYuv* pcPredYuvTemp = NULL;
     1982#if SHARP_ILLUCOMP_PARSE_D0060
     1983      if (rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag())
     1984      {
     1985        if (bICFlag && uiMergeCand == 0)
     1986        {
     1987          continue;
     1988        }
     1989      }
     1990#endif
    18771991#if LOSSLESS_CODING
    18781992      UInt iteration;
     
    19042018          rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level
    19052019          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
     2020#if QC_ARP_D0177
     2021          if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2022            rpcTempCU->setARPWSubParts( ( UChar )nGRPW , 0 , uhDepth );
     2023#endif
    19062024          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
    19072025          rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
    19082026#if MERL_VSP_C0152
     2027
     2028#if MTK_D0156
     2029          if( !rpcTempCU->getSlice()->getSPS()->getUseVSPCompensation() )
     2030          {
     2031              rpcTempCU->setVSPIndexSubParts( 0, 0, 0, uhDepth );
     2032          }
     2033          else
     2034#endif
    19092035          {
    19102036            Int iVSPIdx = 0;
     2037#if LGE_VSP_INHERIT_D0092
     2038            if (iVSPIndexTrue[uiMergeCand] == 1)
     2039            {
     2040                iVSPIdx = 1;
     2041            }
     2042#else
    19112043            Int numVSPIdx;
    19122044            numVSPIdx = 3;
     
    19192051                }
    19202052            }
     2053#endif
    19212054            rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth );
     2055#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2056            rpcTempCU->setVSPDirSubParts(0, 0, 0, uhDepth ); // interprets depth relative to LCU level
     2057#endif
     2058#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     2059           if(iVSPIdx != 0)
     2060           {
     2061             Int iIVCIdx = rpcTempCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==rpcTempCU->getSlice()->getPOC() ? 0: rpcTempCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     2062             cMvFieldNeighbours[2*uiMergeCand].setRefIdx(iIVCIdx);
     2063           }
     2064#endif
    19222065          }
    19232066#endif
     
    19272070
    19282071#if H3D_IVRP
     2072#if !QC_ARP_D0177
    19292073          rpcTempCU->setResPredAvailSubParts(bResPredAvail, 0, 0, uhDepth);
     2074#else
     2075          rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth );
     2076          rpcTempCU->setResPredFlagSubParts ( bResPrdFlag,  0, 0, uhDepth );
     2077#endif 
    19302078#endif
    19312079#if LGE_ILLUCOMP_B0045
    19322080          rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uhDepth);
    19332081#endif
    1934 
     2082#if QC_ARP_D0177
     2083          if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2084          {
     2085            bool bSignalflag[2] = {true, true};
     2086            for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
     2087            {
     2088              Int iRefIdx = cMvFieldNeighbours[uiRefListIdx + 2*uiMergeCand].getRefIdx();
     2089              RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     2090              if(iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx))
     2091                bSignalflag[uiRefListIdx] = false;
     2092            }
     2093            if(!bSignalflag[0]&& !bSignalflag[1])
     2094            {
     2095              rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
     2096            }
     2097          }
     2098#endif
    19352099          // do MC
    19362100#if HHI_INTERVIEW_SKIP
     
    19452109            m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    19462110#endif
    1947 #if H3D_IVRP
     2111#if H3D_IVRP & !QC_ARP_D0177
    19482112            if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
    19492113            {
     
    19642128              m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    19652129#endif
    1966 #if H3D_IVRP
     2130#if H3D_IVRP & !QC_ARP_D0177
    19672131              if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
    19682132              {
     
    20212185    }
    20222186  }
     2187#if QC_ARP_D0177
     2188  }
     2189#endif
    20232190}
    20242191
     
    20382205{
    20392206  UChar uhDepth = rpcTempCU->getDepth( 0 );
    2040  
     2207#if QC_ARP_D0177
     2208  Bool bFirstTime = true;
     2209  Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1;
     2210  if(nARPWMax < 0 || !rpcTempCU->getResPredAvail( 0 ) )
     2211    nARPWMax = 0;
     2212  if( ePartSize != SIZE_2Nx2N)
     2213    nARPWMax = 0;
     2214  Int nARPWStart = 0 , nARPWStep = 1;
     2215  for( Int nCount = 0 , nGRPW = nARPWStart ; nCount <= nARPWMax ; nCount++ , nGRPW += nARPWStep )
     2216  {
     2217    if( bFirstTime == false && rpcTempCU->getSlice()->getSPS()->getUseAdvRP() )
     2218      rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) );
     2219#endif 
    20412220#if HHI_VSO
    20422221  if( m_pcRdCost->getUseRenModel() )
     
    20652244  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    20662245
     2246#if QC_ARP_D0177
     2247  if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2248    rpcTempCU->setARPWSubParts( ( UChar )nGRPW , 0 , uhDepth );
     2249#endif
     2250#if QC_ARP_D0177
     2251  if( bFirstTime == false && rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2252  {
     2253    assert(!rpcTempCU->getSlice()->getSPS()->isDepth());
     2254    rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth, true );
     2255    rpcTempCU->setARPWSubParts( ( UChar )nGRPW , 0 , uhDepth );
     2256#if MERL_VSP_C0152
     2257    m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth], 0);
     2258#else
     2259    m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] );
     2260#endif
     2261    if(rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N)
     2262    {
     2263      bool bSignalflag[2] = {true, true};
     2264      for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
     2265      {
     2266        RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     2267        Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0);
     2268        if(iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx))
     2269          bSignalflag[uiRefListIdx] = false;
     2270      }
     2271      if(!bSignalflag[0]&& !bSignalflag[1])
     2272        rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
     2273    }
     2274  }
     2275  else
     2276  {
     2277    bFirstTime = false;
     2278#endif
    20672279#if AMP_MRG
    20682280  rpcTempCU->setMergeAMP (true);
     
    20792291#endif
    20802292#endif
     2293#if QC_ARP_D0177
     2294   if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2295   {
     2296     m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth );
     2297     if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP() && rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N)
     2298     {
     2299       bool bSignalflag[2] = {true, true};
     2300       for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ )
     2301       {
     2302         RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     2303         Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0);
     2304         if(iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx))
     2305           bSignalflag[uiRefListIdx] = false;
     2306       }
     2307       if(!bSignalflag[0]&& !bSignalflag[1])
     2308         rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth );
     2309     }
     2310   }
     2311  }
     2312#endif
    20812313
    20822314#if AMP_MRG
    20832315  if ( !rpcTempCU->getMergeAMP() )
    20842316  {
     2317#if QC_ARP_D0177
     2318    if(rpcTempCU->getSlice()->getSPS()->getUseAdvRP())
     2319      continue;
     2320    else
     2321#endif
    20852322    return;
    20862323  }
     
    21232360  xCheckDQP( rpcTempCU );
    21242361  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
     2362#if QC_ARP_D0177
     2363  }
     2364#endif
    21252365}
    21262366
     
    27582998      assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE );
    27592999#if MERL_VSP_C0152
    2760       Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui);
     3000      Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui );
    27613001      rpcTempCU->setVSPIndex( ui , vspIdx);
     3002#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3003      Int vspDir = pcTextureCU->getVSPDir  ( rpcTempCU->getZorderIdxInCU() + ui );
     3004      rpcTempCU->setVSPDir( ui, vspDir);
     3005#endif
    27623006#endif
    27633007    }
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r296 r443  
    6969  TComDataCU**            m_ppcBestCU;      ///< Best CUs in each depth
    7070  TComDataCU**            m_ppcTempCU;      ///< Temporary CUs in each depth
     71#if QC_ARP_D0177
     72  TComDataCU**            m_ppcWeightedTempCU;   
     73#endif
    7174  UChar                   m_uhTotalDepth;
    7275 
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r332 r443  
    5454  if (pcSlice->getSPS()->getUseSAO())
    5555  {
     56#if LGE_SAO_MIGRATION_D0091
     57    if (pcSlice->getSPS()->getUseSAO())
     58    {
     59        SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
     60        pcSlice->setSaoEnabledFlag     (saoParam->bSaoFlag[0]);
     61        {
     62            pcSlice->setSaoEnabledFlagChroma   (saoParam->bSaoFlag[1]);
     63        }
     64    }
     65#else
    5666    pcSlice->setSaoInterleavingFlag(pcSlice->getAPS()->getSaoInterleavingFlag());
    5767    pcSlice->setSaoEnabledFlag     (pcSlice->getAPS()->getSaoParam()->bSaoFlag[0]);
     
    6676      pcSlice->setSaoEnabledFlagCr   (0);
    6777    }
     78#endif
    6879  }
    6980
     
    456467
    457468
     469#if QC_ARP_D0177
     470Void TEncEntropy::encodeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD, UInt uiDepth)
     471{
     472  if( pcCU->getSlice()->getViewId() == 0 || pcCU->getSlice()->getIsDepth() == true || !pcCU->getSlice()->getARPStepNum() )
     473  {
     474    return;
     475  }
     476  assert( pcCU->isIntra( uiAbsPartIdx ) == false );
     477  if( bRD )
     478  {
     479    uiAbsPartIdx = 0;
     480  }
     481  bool bSignalflag[2] = {true, true};
     482  if (!(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N || pcCU->isSkipped(uiAbsPartIdx)))
     483  {
     484    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
     485    bSignalflag[0] = false;
     486    bSignalflag[1] = false;
     487 }
     488  if (!(bSignalflag[0]|| bSignalflag[1]))
     489  {
     490    assert(pcCU->getARPW (uiAbsPartIdx) == 0);
     491    if (uiDepth != -1)
     492      pcCU->setARPWSubParts(0, uiAbsPartIdx, uiDepth);
     493  }
     494  else
     495     m_pcEntropyCoderIf->codeARPW( pcCU, uiAbsPartIdx );
     496 
     497}
     498#endif
    458499/** parse the fixed length code (smaller than one max value) in ALF
    459500 * \param run: coded value
     
    828869  m_pcEntropyCoderIf->codePredMode( pcCU, uiAbsPartIdx );
    829870 
     871#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    830872#if RWTH_SDC_DLT_B0036
    831873  // if B-Slice, code SDC flag later
     
    835877    encodeSDCFlag(pcCU, uiAbsPartIdx, bRD);
    836878  }
     879#endif
    837880#endif
    838881}
     
    876919    }
    877920  }
     921#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    878922#if RWTH_SDC_DLT_B0036
    879923  if( !pcCU->getSlice()->isInterB() && pcCU->isIntra(uiAbsPartIdx) && pcCU->getSDCFlag(uiAbsPartIdx)  )
     
    883927  }
    884928#endif
     929#endif
    885930 
    886931  m_pcEntropyCoderIf->codePartSize( pcCU, uiAbsPartIdx, uiDepth );
    887932 
     933#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    888934#if RWTH_SDC_DLT_B0036
    889935  // code SDC flag now!
     
    899945    }
    900946  }
     947#endif
    901948#endif
    902949}
     
    11791226
    11801227// Intra direction for Luma
    1181 Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1182 {
    1183   m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx );
     1228Void TEncEntropy::encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx
     1229#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1230                                           ,Bool bSdcRD
     1231#endif
     1232                                           )
     1233{
     1234  m_pcEntropyCoderIf->codeIntraDirLumaAng( pcCU, uiAbsPartIdx
     1235#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1236    ,bSdcRD
     1237#endif
     1238    );
    11841239}
    11851240
     
    11951250}
    11961251
    1197 Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
     1252Void TEncEntropy::encodePredInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD
     1253#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1254                                 ,Bool bSdcRD
     1255#endif
     1256                                 )
    11981257{
    11991258  if( bRD )
     
    12021261  }
    12031262
     1263#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    12041264#if RWTH_SDC_DLT_B0036
    12051265  if( pcCU->getSDCFlag(uiAbsPartIdx) )
     
    12081268    return;
    12091269  }
     1270#endif
    12101271#endif
    12111272
     
    12221283      encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*2 );
    12231284      encodeIntraDirModeLuma( pcCU, uiAbsPartIdx + uiPartOffset*3 );
     1285#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1286      if(!pcCU->getSDCFlag(uiAbsPartIdx))
     1287#endif
    12241288      encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
    12251289    }
    12261290    else                                                              // if it is not NxN size, encode 1 intra directions
    12271291    {
    1228       encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx );
     1292      encodeIntraDirModeLuma  ( pcCU, uiAbsPartIdx
     1293#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1294        ,bSdcRD
     1295#endif
     1296        );
     1297#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1298      if(!pcCU->getSDCFlag(uiAbsPartIdx))
     1299#endif
    12291300      encodeIntraDirModeChroma( pcCU, uiAbsPartIdx, bRD );
    12301301    }
     
    12331304  {
    12341305    encodePUWise( pcCU, uiAbsPartIdx, bRD );
     1306#if QC_ARP_D0177
     1307    encodeARPW( pcCU , uiAbsPartIdx , bRD );
     1308#endif
    12351309  }
    12361310}
     
    13511425  {
    13521426#if H3D_IVMP
     1427#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     1428    const Int iNumCands = AMVP_MAX_NUM_CANDS;
     1429#else
    13531430    const Int iNumCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     1431#endif
    13541432    m_pcEntropyCoderIf->codeMVPIdx( pcCU, uiAbsPartIdx, eRefList, iNumCands );
    13551433#else
     
    14171495    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_U) == 1 );
    14181496    assert( pcCU->getCbf(uiAbsPartIdx, TEXT_CHROMA_V) == 1 );
    1419    
     1497#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    14201498    encodeSDCResidualData(pcCU, uiAbsPartIdx);
     1499#endif
    14211500    return;
    14221501  }
     
    14951574}
    14961575
     1576#if LGE_SAO_MIGRATION_D0091
     1577Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
     1578{
     1579    UInt uiSymbol;
     1580    Int i;
     1581
     1582    uiSymbol = saoLcuParam->typeIdx + 1;
     1583    if (compIdx!=2)
     1584    {
     1585        m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
     1586    }
     1587
     1588    if (uiSymbol)
     1589    {
     1590        if (saoLcuParam->typeIdx < 4 && compIdx != 2)
     1591        {
     1592            saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
     1593        }
     1594#if FULL_NBIT
     1595        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
     1596#else
     1597        Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
     1598#endif
     1599        if( saoLcuParam->typeIdx == SAO_BO )
     1600        {
     1601            for( i=0; i< saoLcuParam->length; i++)
     1602            {
     1603                UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
     1604                m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
     1605            } 
     1606            for( i=0; i< saoLcuParam->length; i++)
     1607            {
     1608                if (saoLcuParam->offset[i] != 0)
     1609                {
     1610                    UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
     1611                    m_pcEntropyCoderIf->codeSAOSign(sign);
     1612                }
     1613            }
     1614            uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
     1615            m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
     1616        }
     1617        else if( saoLcuParam->typeIdx < 4 )
     1618        {
     1619            m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
     1620            m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
     1621            m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
     1622            m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
     1623
     1624            if (compIdx!=2)
     1625            {
     1626                uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
     1627                m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
     1628            }
     1629        }
     1630    }
     1631}
     1632
     1633/** Encode SAO unit interleaving
     1634* \param  rx
     1635* \param  ry
     1636* \param  pSaoParam
     1637* \param  pcCU
     1638* \param  iCUAddrInSlice
     1639* \param  iCUAddrUpInSlice
     1640* \param  bLFCrossSliceBoundaryFlag
     1641 */
     1642Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
     1643{
     1644    if (saoFlag)
     1645    {
     1646        if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
     1647        {
     1648            m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
     1649        }
     1650        else
     1651        {
     1652            saoLcuParam->mergeLeftFlag = 0;
     1653        }
     1654       
     1655        if (saoLcuParam->mergeLeftFlag == 0)
     1656        {
     1657            if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
     1658            {
     1659                m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
     1660            }
     1661            else
     1662            {
     1663                saoLcuParam->mergeUpFlag = 0;
     1664            }
     1665
     1666            if (!saoLcuParam->mergeUpFlag)
     1667            {
     1668                encodeSaoOffset(saoLcuParam, compIdx);
     1669            }
     1670        }
     1671    }
     1672}
     1673#else
    14971674/** Encode SAO Offset
    14981675 * \param  saoLcuParam SAO LCU paramters
     
    16821859  }
    16831860}
     1861#endif
    16841862
    16851863Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
     
    17151893
    17161894#if RWTH_SDC_DLT_B0036
     1895#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    17171896Void TEncEntropy::encodeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    17181897{
     
    17341913  m_pcEntropyCoderIf->codeSDCFlag(pcCU, uiAbsPartIdx);
    17351914}
    1736 
     1915#endif
    17371916Void TEncEntropy::encodeSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    17381917{
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r332 r443  
    117117  virtual Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
    118118#endif
     119#if QC_ARP_D0177
     120  virtual Void codeARPW         ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     121#endif
    119122  virtual Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
    120123 
     
    123126 
    124127#if RWTH_SDC_DLT_B0036
     128#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    125129  virtual Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     130#endif
    126131  virtual Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) = 0;
     132#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    127133  virtual Void codeSDCPredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     134#endif
    128135#endif
    129136 
     
    133140  virtual Void codeQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) = 0;
    134141  virtual Void codeQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
    135   virtual Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     142  virtual Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     143#if PKU_QC_DEPTH_INTRA_UNI_D0195
     144    , Bool bSdcRD = false
     145#endif
     146    ) = 0;
    136147 
    137148  virtual Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
     
    154165
    155166  virtual Void codeAlfCtrlFlag      ( UInt uiSymbol ) = 0;
     167#if LGE_SAO_MIGRATION_D0091
     168  virtual Void codeSAOSign          ( UInt code   ) = 0;
     169  virtual Void codeSaoMaxUvlc       ( UInt code, UInt maxSymbol ) = 0;
     170  virtual Void codeSaoMerge         ( UInt   uiCode  ) = 0;
     171  virtual Void codeSaoTypeIdx       ( UInt   uiCode) = 0;
     172  virtual Void codeSaoUflc          ( UInt uiLength, UInt   uiCode ) = 0;
     173#else
    156174  virtual Void codeSaoFlag          ( UInt uiCode ) = 0;
    157175  virtual Void codeSaoUvlc          ( UInt uiCode ) = 0;
     
    162180  virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
    163181  virtual Void codeSaoUflc         ( UInt   uiCode) = 0;
     182#endif
    164183  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
    165184 
     
    250269  Void encodeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx );
    251270  Void encodeMergeIndex   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD = false );
     271#if QC_ARP_D0177
     272  Void encodeARPW              ( TComDataCU* pcCU, UInt uiAbspartIdx , Bool bRD = false, UInt uiDepth = -1);
     273#endif
    252274  Void encodeAlfCtrlFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    253275
     
    265287  Void encodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
    266288  Void encodeIPCMInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    267   Void encodePredInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    268   Void encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     289  Void encodePredInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false
     290#if PKU_QC_DEPTH_INTRA_UNI_D0195
     291    ,Bool bSdcRD = false
     292#endif
     293    );
     294  Void encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx
     295#if PKU_QC_DEPTH_INTRA_UNI_D0195
     296 ,Bool bSdcRD = false
     297#endif
     298    );
    269299 
    270300  Void encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     
    284314 
    285315#if RWTH_SDC_DLT_B0036
     316#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    286317  Void encodeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     318#endif
    287319  Void encodeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     320#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    288321  Void encodeSDCPredMode   ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
     322#endif
    289323#endif
    290324
     
    310344  Int golombEncode(int coeff, int k);
    311345  Int lengthGolomb(int coeffVal, int k);
     346#if LGE_SAO_MIGRATION_D0091
     347  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);
     348  Void    encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
     349#else
    312350  Void    encodeSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Int repeatedRow);
    313351  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam);
    314352  Void    encodeSaoUnitInterleaving(Int rx, Int ry, SAOParam* saoParam, TComDataCU* cu, Int cuAddrInSlice, Int cuAddrUpInSlice, Bool lfCrossSliceBoundaryFlag);
    315353  Void    encodeSaoParam         (TComAPS*  aps);
     354#endif
    316355
    317356  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r332 r443  
    7878  m_pcDepthMapGenerator = NULL;
    7979#endif
    80 #if H3D_IVRP
     80#if H3D_IVRP & !QC_ARP_D0177
    8181  m_pcResidualGenerator = NULL;
    8282#endif
     
    131131  m_pcDepthMapGenerator  = pcTEncTop->getDepthMapGenerator();
    132132#endif
    133 #if H3D_IVRP
     133#if H3D_IVRP & !QC_ARP_D0177
    134134  m_pcResidualGenerator  = pcTEncTop->getResidualGenerator();
    135135#endif
     
    390390      std::vector<TComPic*> apcInterViewRefPics = tAppEncTop->getInterViewRefPics( m_pcEncTop->getViewId(), pcSlice->getPOC(), m_pcEncTop->getIsDepth(), pcSlice->getSPS() );
    391391      pcSlice->setRefPicListMvc( rcListPic, apcInterViewRefPics );
    392 
     392#if QC_ARP_D0177
     393      pcSlice->setARPStepNum();
     394      if(pcSlice->getARPStepNum() > 1)
     395      {
     396        for(Int iViewIdx = 0; iViewIdx < pcSlice->getViewId(); iViewIdx ++ )
     397          pcSlice->setBaseViewRefPicList( tAppEncTop->getTEncTop( iViewIdx , false )->getListPic(), iViewIdx );
     398      }
     399#endif
    393400      //  Slice info. refinement
    394401      if( pcSlice->getSliceType() == B_SLICE )
     
    754761      m_pcDepthMapGenerator->covertOrgDepthMap( pcPic );
    755762#endif
    756 #if H3D_IVRP
     763#if H3D_IVRP & !QC_ARP_D0177
    757764      m_pcResidualGenerator->initViewComponent( pcPic );
    758765#endif
     
    818825      pcSlice = pcPic->getSlice(0);
    819826
    820 #if H3D_IVRP
     827#if H3D_IVRP & !QC_ARP_D0177
    821828      // set residual picture
    822829      m_pcResidualGenerator->setRecResidualPic( pcPic );
     
    12571264            TComAPS cAPS;
    12581265            allocAPS(&cAPS, pcSlice->getSPS());
     1266#if !LGE_SAO_MIGRATION_D0091
    12591267            cAPS.setSaoInterleavingFlag(m_pcCfg->getSaoInterleavingFlag());
     1268#endif
    12601269            // set entropy coder for RD
    12611270            m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
     
    12651274              m_pcEntropyCoder->resetEntropy();
    12661275              m_pcEntropyCoder->setBitstream( m_pcBitCounter );
     1276#if LGE_SAO_MIGRATION_D0091
     1277              m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder());
     1278#else
    12671279              m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), NULL);
     1280#endif
    12681281              SAOParam& cSaoParam = *(cAPS.getSaoParam());
    12691282
    12701283#if SAO_CHROMA_LAMBDA
     1284#if LGE_SAO_MIGRATION_D0091
     1285#if SAO_ENCODING_CHOICE
     1286              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth());
     1287#else
    12711288              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
     1289#endif
     1290#else
     1291              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
     1292#endif
    12721293#else
    12731294#if ALF_CHROMA_LAMBDA
     
    15541575    m_pcEntropyCoder->encodeDFParams(pcAPS);
    15551576  }
     1577#if !LGE_SAO_MIGRATION_D0091
    15561578  m_pcEntropyCoder->encodeSaoParam(pcAPS);
     1579#endif
    15571580  m_pcEntropyCoder->encodeAPSAlfFlag( pcAPS->getAlfEnabled()?1:0);
    15581581  if(pcAPS->getAlfEnabled())
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r296 r443  
    9797  TComDepthMapGenerator*  m_pcDepthMapGenerator;
    9898#endif
    99 #if H3D_IVRP
     99#if H3D_IVRP & !QC_ARP_D0177
    100100  TComResidualGenerator*  m_pcResidualGenerator;
    101101#endif
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r296 r443  
    4343//! \ingroup TLibEncoder
    4444//! \{
    45 
     45#if LGE_SAO_MIGRATION_D0091
    4646TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    4747{
    48   m_pcEntropyCoder = NULL;
    49   m_pppcRDSbacCoder = NULL;
    50   m_pcRDGoOnSbacCoder = NULL;
    51   m_pppcBinCoderCABAC = NULL;           
    52   m_iCount = NULL;     
    53   m_iOffset = NULL;     
    54   m_iOffsetOrg = NULL; 
    55   m_iRate = NULL;       
    56   m_iDist = NULL;       
    57   m_dCost = NULL;       
    58   m_dCostPartBest = NULL;
    59   m_iDistOrg = NULL;     
    60   m_iTypePartBest = NULL;
    61 }
     48    m_pcEntropyCoder= NULL;
     49    m_pppcRDSbacCoder = NULL;
     50    m_pcRDGoOnSbacCoder = NULL;
     51    m_pppcBinCoderCABAC = NULL;
     52    m_iCount = NULL;
     53    m_iOffset = NULL;
     54    m_iOffsetOrg = NULL;
     55    m_iRate = NULL;
     56    m_iDist = NULL;
     57    m_dCost = NULL;
     58    m_dCostPartBest = NULL;
     59    m_iDistOrg = NULL;
     60    m_iTypePartBest = NULL;
     61#if SAO_ENCODING_CHOICE_CHROMA
     62    m_depthSaoRate[0][0] = 0;
     63    m_depthSaoRate[0][1] = 0;
     64    m_depthSaoRate[0][2] = 0;
     65    m_depthSaoRate[0][3] = 0;
     66    m_depthSaoRate[1][0] = 0;
     67    m_depthSaoRate[1][1] = 0;
     68    m_depthSaoRate[1][2] = 0;
     69    m_depthSaoRate[1][3] = 0;
     70#endif
     71}
     72
    6273TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
    6374{
     
    7687{
    7788#if FULL_NBIT
    78   Int bitDepthMinus8 = g_uiBitDepth - 8;
    79   return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)) : ((Int)(((Int)(x)-(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)));
     89    Int bitDepthMinus8 = g_uiBitDepth - 8;
     90    return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)) : ((Int)(((Int)(x)-(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)));
    8091#else
    81   return ((x)>0) ? (Int)(((Int)(x)+(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)) : ((Int)(((Int)(x)-(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)));
     92    return ((x)>0) ? (Int)(((Int)(x)+(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)) : ((Int)(((Int)(x)-(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)));
    8293#endif
    8394}
     
    89100{
    90101#if FULL_NBIT
    91   return (g_uiBitDepth > 8 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     102    return (g_uiBitDepth > 8 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
    92103#else
    93   return (g_uiBitIncrement >0 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
    94 #endif
    95 }
    96 
    97 
     104    return (g_uiBitIncrement >0 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     105#endif
     106}
    98107
    99108/** process SAO for one partition
    100109 * \param  *psQTPart, iPartIdx, dLambda
    101110 */
    102 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda)
    103 {
    104   Int iTypeIdx;
    105   Int iNumTotalType = MAX_NUM_SAO_TYPE;
    106   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    107 
    108   Int64 iEstDist;
    109   Int64 iOffsetOrg;
    110   Int64 iOffset;
    111   Int64 iCount;
    112   Int iClassIdx;
    113   Int uiShift = g_uiBitIncrement << 1;
    114   UInt uiDepth = pOnePart->PartLevel;
    115 
    116   m_iDistOrg [iPartIdx] =  0;
    117 
    118   Double  bestRDCostTableBo = MAX_DOUBLE;
    119   Int     bestClassTableBo    = 0;
    120   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    121   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    122 
    123 #if HHI_INTERVIEW_SKIP
    124   Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
    125   Int LcuIdxX = psQTPart->StartCUX;
    126   Int LcuIdxY = psQTPart->StartCUY;
    127   Int iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
    128   TComDataCU *pcCU = m_pcPic->getCU(iAddr);
    129   Bool bRenderable = pcCU->getRenderable(0) ;
    130 
    131 #endif
    132   for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
    133   {
    134     if( m_bUseSBACRD )
    135     {
    136       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    137       m_pcRDGoOnSbacCoder->resetBits();
     111Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr)
     112{
     113    Int iTypeIdx;
     114    Int iNumTotalType = MAX_NUM_SAO_TYPE;
     115    SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     116
     117    Int64 iEstDist;
     118    Int iClassIdx;
     119    Int uiShift = g_uiBitIncrement << 1;
     120    UInt uiDepth = pOnePart->PartLevel;
     121
     122    m_iDistOrg [iPartIdx] =  0;
     123
     124    Double  bestRDCostTableBo = MAX_DOUBLE;
     125    Int     bestClassTableBo    = 0;
     126    Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     127    Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     128
     129    Int addr;
     130    Int allowMergeLeft;
     131    Int allowMergeUp;
     132    Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
     133    SaoLcuParam  saoLcuParamRdo;
     134
     135    for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
     136    {
     137        if( m_bUseSBACRD )
     138        {
     139            m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     140            m_pcRDGoOnSbacCoder->resetBits();
     141        }
     142        else
     143        {
     144            m_pcEntropyCoder->resetEntropy();
     145            m_pcEntropyCoder->resetBits();
     146        }
     147
     148        iEstDist = 0;
     149
     150        if (iTypeIdx == -1)
     151        {     
     152            for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
     153            {
     154                for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
     155                {
     156                    addr = ry * frameWidthInCU + rx;
     157                    // get bits for iTypeIdx = -1
     158                    allowMergeLeft = 1;
     159                    allowMergeUp   = 1;
     160                    if (rx != 0)
     161                    {
     162                        // check tile id and slice id
     163                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     164                        {
     165                            allowMergeLeft = 0;
     166                        }
     167                    }
     168                    if (ry!=0)
     169                    {
     170                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     171                        {
     172                            allowMergeUp = 0;
     173                        }
     174                    }
     175
     176                    // reset
     177                    resetSaoUnit(&saoLcuParamRdo);
     178       
     179                    // set merge flag
     180                    saoLcuParamRdo.mergeUpFlag   = 1;
     181                    saoLcuParamRdo.mergeLeftFlag = 1;
     182       
     183                    if (ry == pOnePart->StartCUY)
     184                    {
     185                        saoLcuParamRdo.mergeUpFlag = 0;
     186                    }
     187
     188                    if (rx == pOnePart->StartCUX)
     189                    {
     190                        saoLcuParamRdo.mergeLeftFlag = 0;
     191                    }
     192
     193                    m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
     194
     195                }
     196            }
     197        }
     198
     199        if (iTypeIdx>=0)
     200        {
     201            iEstDist = estSaoTypeDist(iPartIdx, iTypeIdx, uiShift, dLambda, currentDistortionTableBo, currentRdCostTableBo);
     202            if( iTypeIdx == SAO_BO )
     203            {
     204                // Estimate Best Position
     205                Double currentRDCost = 0.0;
     206   
     207                for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     208                {
     209                    currentRDCost = 0.0;
     210                    for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     211                    {
     212                        currentRDCost += currentRdCostTableBo[uj];
     213                    }
     214
     215                    if( currentRDCost < bestRDCostTableBo)
     216                    {
     217                        bestRDCostTableBo = currentRDCost;
     218                        bestClassTableBo  = i;
     219                    }
     220                }
     221
     222                // Re code all Offsets
     223                // Code Center
     224                for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
     225                {
     226                    iEstDist += currentDistortionTableBo[iClassIdx];
     227                }
     228            }
     229
     230            for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
     231            {
     232                for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
     233                {
     234                    addr = ry * frameWidthInCU + rx;         
     235       
     236                    // get bits for iTypeIdx = -1
     237                    allowMergeLeft = 1;
     238                    allowMergeUp   = 1;
     239                    if (rx != 0)
     240                    {
     241                        // check tile id and slice id
     242                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     243                        {
     244                            allowMergeLeft = 0;
     245                        }
     246                    }
     247                    if (ry!=0)
     248                    {
     249                        if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     250                        {
     251                            allowMergeUp = 0;
     252                        }
     253                    }
     254   
     255                    // reset
     256                    resetSaoUnit(&saoLcuParamRdo);
     257
     258                    // set merge flag
     259                    saoLcuParamRdo.mergeUpFlag   = 1;
     260                    saoLcuParamRdo.mergeLeftFlag = 1;
     261   
     262                    if (ry == pOnePart->StartCUY)
     263                    {
     264                        saoLcuParamRdo.mergeUpFlag = 0;
     265                    }
     266   
     267                    if (rx == pOnePart->StartCUX)
     268                    {
     269                        saoLcuParamRdo.mergeLeftFlag = 0;
     270                    }
     271
     272                    // set type and offsets
     273                    saoLcuParamRdo.typeIdx = iTypeIdx;
     274                    saoLcuParamRdo.subTypeIdx = (iTypeIdx==SAO_BO)?bestClassTableBo:0;
     275                    saoLcuParamRdo.length = m_iNumClass[iTypeIdx];
     276                    for (iClassIdx = 0; iClassIdx < saoLcuParamRdo.length; iClassIdx++)
     277                    {
     278                        saoLcuParamRdo.offset[iClassIdx] = (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+saoLcuParamRdo.subTypeIdx+1];
     279                    }
     280
     281                    m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
     282
     283                }
     284            }
     285
     286            m_iDist[iPartIdx][iTypeIdx] = iEstDist;
     287            m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
     288
     289            m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
     290
     291            if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
     292            {
     293                m_iDistOrg [iPartIdx] = 0;
     294                m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
     295                m_iTypePartBest[iPartIdx] = iTypeIdx;
     296                if( m_bUseSBACRD )
     297                    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     298            }
     299        }
     300        else
     301        {
     302            if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
     303            {
     304                m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
     305                m_iTypePartBest[iPartIdx] = -1;
     306                if( m_bUseSBACRD )
     307                    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     308            }
     309        }
     310    }
     311
     312    pOnePart->bProcessed = true;
     313    pOnePart->bSplit     = false;
     314    pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
     315    pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
     316    pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
     317    pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
     318    if (pOnePart->iBestType != -1)
     319    {
     320        //     pOnePart->bEnableFlag =  1;
     321        pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
     322        Int minIndex = 0;
     323        if( pOnePart->iBestType == SAO_BO )
     324        {
     325            pOnePart->subTypeIdx = bestClassTableBo;
     326            minIndex = pOnePart->subTypeIdx;
     327        }
     328        for (Int i=0; i< pOnePart->iLength ; i++)
     329        {
     330            pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
     331        }
     332
    138333    }
    139334    else
    140335    {
    141       m_pcEntropyCoder->resetEntropy();
    142       m_pcEntropyCoder->resetBits();
    143     }
    144 
    145     iEstDist = 0;
    146 
    147     m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoTypeIdx(iTypeIdx+1);
    148 
    149     if (iTypeIdx>=0)
    150     {
    151 
    152       for(iClassIdx=1; iClassIdx < ( (iTypeIdx < SAO_BO) ?  m_iNumClass[iTypeIdx]+1 : SAO_MAX_BO_CLASSES+1); iClassIdx++)
    153       {
    154         if( iTypeIdx == SAO_BO)
    155         {
    156           currentDistortionTableBo[iClassIdx-1] = 0;
    157           currentRdCostTableBo[iClassIdx-1] = dLambda;
    158         }
    159 #if HHI_INTERVIEW_SKIP
    160         if(m_iCount [iPartIdx][iTypeIdx][iClassIdx] && !bRenderable)
    161 #else
    162         if(m_iCount [iPartIdx][iTypeIdx][iClassIdx])
    163 #endif
    164         {
    165 #if FULL_NBIT
    166           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitDepth-8) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
    167 #else
    168           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitIncrement) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
    169 #endif
    170           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = Clip3(-m_iOffsetTh, m_iOffsetTh-1, (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    171 
    172           if (iTypeIdx < 4)
    173           {
    174             if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]<0 && iClassIdx<3 )
    175             {
    176               m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    177             }
    178             if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]>0 && iClassIdx>=3)
    179             {
    180               m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    181             }
    182           }
    183           {
    184             //Clean up, best_q_offset.
    185             Int64 iIterOffset, iTempOffset;
    186             Int64 iTempDist, iTempRate;
    187             Double dTempCost, dTempMinCost;
    188             UInt uiLength, uiTemp;
    189 
    190             iIterOffset = m_iOffset[iPartIdx][iTypeIdx][iClassIdx];
    191             m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    192             dTempMinCost = dLambda; // 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.
    193 
    194             while (iIterOffset != 0)
    195             {
    196               // Calculate the bits required for signalling the offset
    197               uiLength = 1;
    198               uiTemp = (UInt)((iIterOffset <= 0) ? ( (-iIterOffset<<1) + 1 ) : (iIterOffset<<1));
    199               while( 1 != uiTemp )
    200               {
    201                 uiTemp >>= 1;
    202                 uiLength += 2;
    203               }
    204               iTempRate = (uiLength >> 1) + ((uiLength+1) >> 1);
    205 
    206               // Do the dequntization before distorion calculation
    207               iTempOffset    =  iIterOffset << m_uiSaoBitIncrease;
    208               iTempDist  = (( m_iCount [iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*iTempOffset-m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*2 ) >> uiShift);
    209 
    210               dTempCost = ((Double)iTempDist + dLambda * (Double) iTempRate);
    211               if(dTempCost < dTempMinCost)
    212               {
    213                 dTempMinCost = dTempCost;
    214                 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = iIterOffset;
    215                 if(iTypeIdx == SAO_BO)
    216                 {
    217                   currentDistortionTableBo[iClassIdx-1] = (Int) iTempDist;
    218                   currentRdCostTableBo[iClassIdx-1] = dTempCost;
    219                 }
    220               }
    221               iIterOffset = (iIterOffset > 0) ? (iIterOffset-1):(iIterOffset+1);
    222             }
    223 
    224           }
    225         }
    226         else
    227         {
    228           m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] = 0;
    229           m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
    230         }
    231         if( iTypeIdx != SAO_BO )
    232         {
    233           iCount     =  m_iCount [iPartIdx][iTypeIdx][iClassIdx];
    234           iOffset    =  m_iOffset[iPartIdx][iTypeIdx][iClassIdx] << m_uiSaoBitIncrease;
    235           iOffsetOrg =  m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx];
    236           iEstDist   += (( iCount*iOffset*iOffset-iOffsetOrg*iOffset*2 ) >> uiShift);
    237           if (iTypeIdx < 4)
    238           {
    239             if (iClassIdx<3)
    240             {
    241               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    242             }
    243             else
    244             {
    245               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)-m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    246             }
    247           }
    248           else
    249           {
    250             m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
    251           }
    252         }
    253       }
    254 
    255       if( iTypeIdx == SAO_BO )
    256       {
    257         // Estimate Best Position
    258         Double currentRDCost = 0.0;
    259 
    260         for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    261         {
    262           currentRDCost = 0.0;
    263           for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    264           {
    265             currentRDCost += currentRdCostTableBo[uj];
    266           }
    267 
    268           if( currentRDCost < bestRDCostTableBo)
    269           {
    270             bestRDCostTableBo = currentRDCost;
    271             bestClassTableBo  = i;
    272           }
    273         }
    274 
    275         // Re code all Offsets
    276         // Code Center
    277         m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUflc( (UInt) (bestClassTableBo) );
    278 
    279         for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
    280         {
    281           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+1]);
    282           iEstDist += currentDistortionTableBo[iClassIdx];
    283         }
    284       }
    285 
    286       m_iDist[iPartIdx][iTypeIdx] = iEstDist;
    287       m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
    288 
    289       m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
    290 
    291       if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
    292       {
    293         m_iDistOrg [iPartIdx] = 0;
    294         m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
    295         m_iTypePartBest[iPartIdx] = iTypeIdx;
    296         if( m_bUseSBACRD )
    297           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    298       }
    299     }
    300     else
    301     {
    302       if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
    303       {
    304         m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
    305         m_iTypePartBest[iPartIdx] = -1;
    306         if( m_bUseSBACRD )
    307           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    308       }
    309     }
    310   }
    311 
    312   pOnePart->bProcessed = true;
    313   pOnePart->bSplit     = false;
    314   pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
    315   pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
    316   pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
    317   pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
    318   if (pOnePart->iBestType != -1)
    319   {
    320     //     pOnePart->bEnableFlag =  1;
    321     pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
    322     Int minIndex = 0;
    323     if( pOnePart->iBestType == SAO_BO )
    324     {
    325       pOnePart->bandPosition = bestClassTableBo;
    326       minIndex = pOnePart->bandPosition;
    327     }
    328     for (Int i=0; i< pOnePart->iLength ; i++)
    329     {
    330       pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
    331     }
    332 
    333   }
    334   else
    335   {
    336     //     pOnePart->bEnableFlag = 0;
    337     pOnePart->iLength     = 0;
    338   }
     336        //     pOnePart->bEnableFlag = 0;
     337        pOnePart->iLength     = 0;
     338    }
    339339}
    340340
     
    343343Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx)
    344344{
    345   SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
    346   pOnePart->bSplit      = false;
    347   pOnePart->iLength     =  0;
    348   pOnePart->iBestType   = -1;
    349 
    350   if (pOnePart->PartLevel < m_uiMaxSplitLevel)
    351   {
    352     for (Int i=0; i<NUM_DOWN_PART; i++)
    353     {
    354       disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    355     }
    356   }
     345    SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
     346    pOnePart->bSplit      = false;
     347    pOnePart->iLength     =  0;
     348    pOnePart->iBestType   = -1;
     349
     350    if (pOnePart->PartLevel < m_uiMaxSplitLevel)
     351    {
     352        for (Int i=0; i<NUM_DOWN_PART; i++)
     353        {
     354            disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     355        }
     356    }
    357357}
    358358
     
    360360 * \param  iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal
    361361 */
    362 Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda)
    363 {
    364   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    365 
    366   UInt uiDepth = pOnePart->PartLevel;
    367   UInt uhNextDepth = uiDepth+1;
    368 
    369   if (iPartIdx == 0)
    370   {
    371     dCostFinal = 0;
    372   }
    373 
    374   //SAO for this part
    375   if(!pOnePart->bProcessed)
    376   {
    377     rdoSaoOnePart (psQTPart, iPartIdx, dLambda);
    378   }
    379 
    380   //SAO for sub 4 parts
    381   if (pOnePart->PartLevel < iMaxLevel)
    382   {
    383     Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
    384     Double      dCostSplit    = dLambda;
    385 
    386     for (Int i=0; i< NUM_DOWN_PART ;i++)
    387     {
    388       if( m_bUseSBACRD ) 
    389       {
    390         if ( 0 == i) //initialize RD with previous depth buffer
    391         {
    392           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     362Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr)
     363{
     364    SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     365
     366    UInt uiDepth = pOnePart->PartLevel;
     367    UInt uhNextDepth = uiDepth+1;
     368
     369    if (iPartIdx == 0)
     370    {
     371        dCostFinal = 0;
     372    }
     373
     374    //SAO for this part
     375    if(!pOnePart->bProcessed)
     376    {
     377        rdoSaoOnePart (psQTPart, iPartIdx, dLambda, yCbCr);
     378    }
     379
     380    //SAO for sub 4 parts
     381    if (pOnePart->PartLevel < iMaxLevel)
     382    {
     383        Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
     384        Double      dCostSplit    = dLambda;
     385
     386        for (Int i=0; i< NUM_DOWN_PART ;i++)
     387        {
     388            if( m_bUseSBACRD )
     389            {
     390                if ( 0 == i) //initialize RD with previous depth buffer
     391                {
     392                    m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     393                }
     394                else
     395                {
     396                    m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     397                }
     398            }
     399            runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda, yCbCr);
     400            dCostSplit += dCostFinal;
     401            if( m_bUseSBACRD )
     402            {
     403                m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
     404            }
     405        }
     406
     407        if(dCostSplit < dCostNotSplit)
     408        {
     409            dCostFinal = dCostSplit;
     410            pOnePart->bSplit      = true;
     411            pOnePart->iLength     =  0;
     412            pOnePart->iBestType   = -1;
     413            if( m_bUseSBACRD )
     414            {
     415                m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     416            }
    393417        }
    394418        else
    395419        {
    396           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    397         }
    398       } 
    399       runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda);
    400       dCostSplit += dCostFinal;
    401       if( m_bUseSBACRD )
    402       {
    403         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
    404       }
    405     }
    406 
    407     if(dCostSplit < dCostNotSplit)
    408     {
    409       dCostFinal = dCostSplit;
    410       pOnePart->bSplit      = true;
    411       pOnePart->iLength     =  0;
    412       pOnePart->iBestType   = -1;
    413       if( m_bUseSBACRD )
    414       {
    415         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    416       }
     420            dCostFinal = dCostNotSplit;
     421            pOnePart->bSplit = false;
     422            for (Int i=0; i<NUM_DOWN_PART; i++)
     423            {
     424                disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     425            }
     426            if( m_bUseSBACRD )
     427            {
     428                m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     429            }
     430        }
    417431    }
    418432    else
    419433    {
    420       dCostFinal = dCostNotSplit;
    421       pOnePart->bSplit = false;
    422       for (Int i=0; i<NUM_DOWN_PART; i++)
    423       {
    424         disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    425       }
    426       if( m_bUseSBACRD )
    427       {
    428         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    429       }
    430     }
    431   }
    432   else
    433   {
    434     dCostFinal = pOnePart->dMinCost;
    435   }
     434        dCostFinal = pOnePart->dMinCost;
     435    }
    436436}
    437437
     
    446446      if (m_iCount [i][j])
    447447      {
    448         delete [] m_iCount [i][j]; 
     448        delete [] m_iCount [i][j];
    449449      }
    450450      if (m_iOffset[i][j])
     
    454454      if (m_iOffsetOrg[i][j])
    455455      {
    456         delete [] m_iOffsetOrg[i][j]; 
     456        delete [] m_iOffsetOrg[i][j];
    457457      }
    458458    }
     
    463463    if (m_iDist[i])
    464464    {
    465       delete [] m_iDist[i]; 
     465      delete [] m_iDist[i];
    466466    }
    467467    if (m_dCost[i])
     
    471471    if (m_iCount [i])
    472472    {
    473       delete [] m_iCount [i]; 
     473      delete [] m_iCount [i];
    474474    }
    475475    if (m_iOffset[i])
     
    479479    if (m_iOffsetOrg[i])
    480480    {
    481       delete [] m_iOffsetOrg[i];
    482     }
    483 
     481      delete [] m_iOffsetOrg[i];
     482    }
    484483  }
    485484  if (m_iDistOrg)
     
    518517  {
    519518    delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL;
     519  }
     520  Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
     521
     522  for (Int i=0;i<numLcu;i++)
     523  {
     524    for (Int j=0;j<3;j++)
     525    {
     526      for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
     527      {
     528        if (m_count_PreDblk [i][j][k])
     529        {
     530          delete [] m_count_PreDblk [i][j][k];
     531        }
     532        if (m_offsetOrg_PreDblk[i][j][k])
     533        {
     534          delete [] m_offsetOrg_PreDblk[i][j][k];
     535        }
     536      }
     537      if (m_count_PreDblk [i][j])
     538      {
     539        delete [] m_count_PreDblk [i][j];
     540      }
     541      if (m_offsetOrg_PreDblk[i][j])
     542      {
     543        delete [] m_offsetOrg_PreDblk[i][j];
     544      }
     545    }
     546    if (m_count_PreDblk [i])
     547    {
     548      delete [] m_count_PreDblk [i];
     549    }
     550    if (m_offsetOrg_PreDblk[i])
     551    {
     552      delete [] m_offsetOrg_PreDblk[i];
     553    }
     554  }
     555  if (m_count_PreDblk)
     556  {
     557    delete [] m_count_PreDblk  ; m_count_PreDblk = NULL;
     558  }
     559  if (m_offsetOrg_PreDblk)
     560  {
     561    delete [] m_offsetOrg_PreDblk ; m_offsetOrg_PreDblk = NULL;
    520562  }
    521563
     
    546588Void TEncSampleAdaptiveOffset::createEncBuffer()
    547589{
    548   m_iDistOrg = new Int64 [m_iNumTotalParts]; 
    549   m_dCostPartBest = new Double [m_iNumTotalParts]; 
    550   m_iTypePartBest = new Int [m_iNumTotalParts]; 
     590  m_iDistOrg = new Int64 [m_iNumTotalParts];
     591  m_dCostPartBest = new Double [m_iNumTotalParts];
     592  m_iTypePartBest = new Int [m_iNumTotalParts];
    551593
    552594  m_iRate = new Int64* [m_iNumTotalParts];
     
    561603  {
    562604    m_iRate[i] = new Int64  [MAX_NUM_SAO_TYPE];
    563     m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE]; 
    564     m_dCost[i] = new Double [MAX_NUM_SAO_TYPE]; 
    565 
    566     m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE]; 
    567     m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 
    568     m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 
     605    m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE];
     606    m_dCost[i] = new Double [MAX_NUM_SAO_TYPE];
     607
     608    m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE];
     609    m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE];
     610    m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE];
    569611
    570612    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    571613    {
    572       m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    573       m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    574       m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
     614      m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     615      m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     616      m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
     617    }
     618  }
     619  Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
     620  m_count_PreDblk  = new Int64 ***[numLcu];
     621  m_offsetOrg_PreDblk = new Int64 ***[numLcu];
     622  for (Int i=0; i<numLcu; i++)
     623  {
     624    m_count_PreDblk[i]  = new Int64 **[3];
     625    m_offsetOrg_PreDblk[i] = new Int64 **[3];
     626
     627    for (Int j=0;j<3;j++)
     628    {
     629      m_count_PreDblk [i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
     630      m_offsetOrg_PreDblk[i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
     631
     632      for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
     633      {
     634        m_count_PreDblk [i][j][k]   = new Int64 [MAX_NUM_SAO_CLASS];
     635        m_offsetOrg_PreDblk[i][j][k]= new Int64 [MAX_NUM_SAO_CLASS];
     636      }
    575637    }
    576638  }
     
    606668
    607669/** Start SAO encoder
    608  * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder 
     670 * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder
    609671 */
    610672Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder)
    611673{
    612   if( pcRDGoOnSbacCoder )
    613     m_bUseSBACRD = true;
    614   else
    615     m_bUseSBACRD = false;
    616 
     674  m_bUseSBACRD = true;
    617675  m_pcPic = pcPic;
    618676  m_pcEntropyCoder = pcEntropyCoder;
    619677
    620678  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     679  m_pcEntropyCoder->setEntropyCoder(m_pcRDGoOnSbacCoder, pcPic->getSlice(0));
    621680  m_pcEntropyCoder->resetEntropy();
    622681  m_pcEntropyCoder->resetBits();
     
    672731      if (classIdx)
    673732      {
    674         stats[classIdx] += (pOrg[x] - pRec[x]); 
     733        stats[classIdx] += (pOrg[x] - pRec[x]);
    675734        count[classIdx] ++;
    676735      }
     
    685744  pRec   = pRecStart;
    686745
    687 
    688746  startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    689747  endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     
    693751    for (x=startX; x< endX; x++)
    694752    {
    695       signRight =  xSign(pRec[x] - pRec[x+1]); 
     753      signRight =  xSign(pRec[x] - pRec[x+1]);
    696754      edgeType =  signRight + signLeft + 2;
    697755      signLeft  = -signRight;
     
    726784    for (x=0; x< width; x++)
    727785    {
    728       signDown     =  xSign(pRec[x] - pRec[x+stride]); 
     786      signDown     =  xSign(pRec[x] - pRec[x+stride]);
    729787      edgeType    =  signDown + m_iUpBuff1[x] + 2;
    730788      m_iUpBuff1[x] = -signDown;
     
    785843      count[m_auiEoTable[edgeType]] ++;
    786844
    787       m_iUpBufft[x+1] = -signDown1; 
     845      m_iUpBufft[x+1] = -signDown1;
    788846    }
    789847    m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]);
     
    931989      posOffset = (yPos* stride) + xPos;
    932990
    933 #if HHI_INTERVIEW_SKIP
    934       if( !m_pcPic->getCU(iAddr)->getRenderable(0 ))
    935       {
    936991      calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
    937       }
    938 #else
    939       calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
    940 #endif
    941     }
    942   }
    943 
     992    }
     993  }
    944994}
    945995
     
    9741024  Int iIsChroma = (iYCbCr!=0)? 1:0;
    9751025  Int numSkipLine = iIsChroma? 2:4;
     1026  if (m_saoLcuBasedOptimization == 0)
     1027  {
     1028    numSkipLine = 0;
     1029  }
     1030
     1031#if SAO_SKIP_RIGHT
     1032  Int numSkipLineRight = iIsChroma? 3:5;
     1033  if (m_saoLcuBasedOptimization == 0)
     1034  {
     1035    numSkipLineRight = 0;
     1036  }
     1037#endif
     1038
     1039  iPicWidthTmp  = m_iPicWidth  >> iIsChroma;
     1040  iPicHeightTmp = m_iPicHeight >> iIsChroma;
     1041  iLcuWidth     = iLcuWidth    >> iIsChroma;
     1042  iLcuHeight    = iLcuHeight   >> iIsChroma;
     1043  uiLPelX       = uiLPelX      >> iIsChroma;
     1044  uiTPelY       = uiTPelY      >> iIsChroma;
     1045  uiRPelX       = uiLPelX + iLcuWidth  ;
     1046  uiBPelY       = uiTPelY + iLcuHeight ;
     1047  uiRPelX       = uiRPelX > iPicWidthTmp  ? iPicWidthTmp  : uiRPelX;
     1048  uiBPelY       = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY;
     1049  iLcuWidth     = uiRPelX - uiLPelX;
     1050  iLcuHeight    = uiBPelY - uiTPelY;
     1051
     1052  iStride    =  (iYCbCr == 0)? m_pcPic->getStride(): m_pcPic->getCStride();
     1053
     1054//if(iSaoType == BO_0 || iSaoType == BO_1)
     1055  {
     1056    if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1057    {
     1058      numSkipLine = iIsChroma? 1:3;
     1059      numSkipLineRight = iIsChroma? 2:4;
     1060    }
     1061    iStats = m_iOffsetOrg[iPartIdx][SAO_BO];
     1062    iCount = m_iCount    [iPartIdx][SAO_BO];
     1063
     1064    pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1065    pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1066
     1067#if SAO_SKIP_RIGHT
     1068    iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
     1069#endif
     1070
     1071    iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeight-numSkipLine;
     1072    for (y=0; y<iEndY; y++)
     1073    {
     1074#if SAO_SKIP_RIGHT
     1075      for (x=0; x<iEndX; x++)
     1076#else
     1077      for (x=0; x<iLcuWidth; x++)
     1078#endif
     1079      {
     1080        iClassIdx = m_lumaTableBo[pRec[x]];
     1081        if (iClassIdx)
     1082        {
     1083          iStats[iClassIdx] += (pOrg[x] - pRec[x]);
     1084          iCount[iClassIdx] ++;
     1085        }
     1086      }
     1087      pOrg += iStride;
     1088      pRec += iStride;
     1089    }
     1090
     1091  }
     1092  Int iSignLeft;
     1093  Int iSignRight;
     1094  Int iSignDown;
     1095  Int iSignDown1;
     1096  Int iSignDown2;
     1097
     1098  UInt uiEdgeType;
     1099
     1100//if (iSaoType == EO_0  || iSaoType == EO_1 || iSaoType == EO_2 || iSaoType == EO_3)
     1101  {
     1102  //if (iSaoType == EO_0)
     1103    {
     1104      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1105      {
     1106        numSkipLine = iIsChroma? 1:3;
     1107        numSkipLineRight = iIsChroma? 3:5;
     1108      }
     1109      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_0];
     1110      iCount = m_iCount    [iPartIdx][SAO_EO_0];
     1111
     1112      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1113      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1114
     1115      iStartX = (uiLPelX == 0) ? 1 : 0;
     1116#if SAO_SKIP_RIGHT
     1117      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
     1118#else
     1119      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
     1120#endif
     1121      for (y=0; y<iLcuHeight-numSkipLine; y++)
     1122      {
     1123        iSignLeft = xSign(pRec[iStartX] - pRec[iStartX-1]);
     1124        for (x=iStartX; x< iEndX; x++)
     1125        {
     1126          iSignRight =  xSign(pRec[x] - pRec[x+1]);
     1127          uiEdgeType =  iSignRight + iSignLeft + 2;
     1128          iSignLeft  = -iSignRight;
     1129
     1130          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1131          iCount[m_auiEoTable[uiEdgeType]] ++;
     1132        }
     1133        pOrg += iStride;
     1134        pRec += iStride;
     1135      }
     1136    }
     1137
     1138  //if (iSaoType == EO_1)
     1139    {
     1140      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1141      {
     1142        numSkipLine = iIsChroma? 2:4;
     1143        numSkipLineRight = iIsChroma? 2:4;
     1144      }
     1145      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_1];
     1146      iCount = m_iCount    [iPartIdx][SAO_EO_1];
     1147
     1148      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1149      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1150
     1151      iStartY = (uiTPelY == 0) ? 1 : 0;
     1152#if SAO_SKIP_RIGHT
     1153      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
     1154#endif
     1155      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
     1156      if (uiTPelY == 0)
     1157      {
     1158        pOrg += iStride;
     1159        pRec += iStride;
     1160      }
     1161
     1162      for (x=0; x< iLcuWidth; x++)
     1163      {
     1164        m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride]);
     1165      }
     1166      for (y=iStartY; y<iEndY; y++)
     1167      {
     1168#if SAO_SKIP_RIGHT
     1169        for (x=0; x<iEndX; x++)
     1170#else
     1171        for (x=0; x<iLcuWidth; x++)
     1172#endif
     1173        {
     1174          iSignDown     =  xSign(pRec[x] - pRec[x+iStride]);
     1175          uiEdgeType    =  iSignDown + m_iUpBuff1[x] + 2;
     1176          m_iUpBuff1[x] = -iSignDown;
     1177
     1178          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1179          iCount[m_auiEoTable[uiEdgeType]] ++;
     1180        }
     1181        pOrg += iStride;
     1182        pRec += iStride;
     1183      }
     1184    }
     1185  //if (iSaoType == EO_2)
     1186    {
     1187      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1188      {
     1189        numSkipLine = iIsChroma? 2:4;
     1190        numSkipLineRight = iIsChroma? 3:5;
     1191      }
     1192      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_2];
     1193      iCount = m_iCount    [iPartIdx][SAO_EO_2];
     1194
     1195      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1196      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1197
     1198      iStartX = (uiLPelX == 0) ? 1 : 0;
     1199#if SAO_SKIP_RIGHT
     1200      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
     1201#else
     1202      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
     1203#endif
     1204
     1205      iStartY = (uiTPelY == 0) ? 1 : 0;
     1206      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
     1207      if (uiTPelY == 0)
     1208      {
     1209        pOrg += iStride;
     1210        pRec += iStride;
     1211      }
     1212
     1213      for (x=iStartX; x<iEndX; x++)
     1214      {
     1215        m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride-1]);
     1216      }
     1217      for (y=iStartY; y<iEndY; y++)
     1218      {
     1219        iSignDown2 = xSign(pRec[iStride+iStartX] - pRec[iStartX-1]);
     1220        for (x=iStartX; x<iEndX; x++)
     1221        {
     1222          iSignDown1      =  xSign(pRec[x] - pRec[x+iStride+1]) ;
     1223          uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
     1224          m_iUpBufft[x+1] = -iSignDown1;
     1225          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1226          iCount[m_auiEoTable[uiEdgeType]] ++;
     1227        }
     1228        m_iUpBufft[iStartX] = iSignDown2;
     1229        ipSwap     = m_iUpBuff1;
     1230        m_iUpBuff1 = m_iUpBufft;
     1231        m_iUpBufft = ipSwap;
     1232
     1233        pRec += iStride;
     1234        pOrg += iStride;
     1235      }
     1236    }
     1237  //if (iSaoType == EO_3  )
     1238    {
     1239      if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     1240      {
     1241        numSkipLine = iIsChroma? 2:4;
     1242        numSkipLineRight = iIsChroma? 3:5;
     1243      }
     1244      iStats = m_iOffsetOrg[iPartIdx][SAO_EO_3];
     1245      iCount = m_iCount    [iPartIdx][SAO_EO_3];
     1246
     1247      pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
     1248      pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
     1249
     1250      iStartX = (uiLPelX == 0) ? 1 : 0;
     1251#if SAO_SKIP_RIGHT
     1252      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
     1253#else
     1254      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
     1255#endif
     1256
     1257      iStartY = (uiTPelY == 0) ? 1 : 0;
     1258      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
     1259      if (iStartY == 1)
     1260      {
     1261        pOrg += iStride;
     1262        pRec += iStride;
     1263      }
     1264
     1265      for (x=iStartX-1; x<iEndX; x++)
     1266      {
     1267        m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride+1]);
     1268      }
     1269
     1270      for (y=iStartY; y<iEndY; y++)
     1271      {
     1272        for (x=iStartX; x<iEndX; x++)
     1273        {
     1274          iSignDown1      =  xSign(pRec[x] - pRec[x+iStride-1]) ;
     1275          uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
     1276          m_iUpBuff1[x-1] = -iSignDown1;
     1277          iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1278          iCount[m_auiEoTable[uiEdgeType]] ++;
     1279        }
     1280        m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]);
     1281
     1282        pRec += iStride;
     1283        pOrg += iStride;
     1284      }
     1285    }
     1286  }
     1287}
     1288
     1289
     1290Void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk( TComPic* pcPic )
     1291{
     1292  Int addr, yCbCr;
     1293  Int x,y;
     1294  TComSPS *pTmpSPS =  pcPic->getSlice(0)->getSPS();
     1295
     1296  Pel* pOrg;
     1297  Pel* pRec;
     1298  Int stride;
     1299  Int lcuWidth  = pTmpSPS->getMaxCUHeight();
     1300  Int lcuHeight = pTmpSPS->getMaxCUWidth();
     1301  UInt rPelX;
     1302  UInt bPelY;
     1303  Int64* stats;
     1304  Int64* count;
     1305  Int classIdx;
     1306  Int picWidthTmp = 0;
     1307  Int picHeightTmp = 0;
     1308  Int startX;
     1309  Int startY;
     1310  Int endX;
     1311  Int endY;
     1312  Int firstX, firstY;
     1313
     1314  Int idxY;
     1315  Int idxX;
     1316  Int frameHeightInCU = m_iNumCuInHeight;
     1317  Int frameWidthInCU  = m_iNumCuInWidth;
     1318  Int j, k;
     1319
     1320  Int isChroma;
     1321  Int numSkipLine, numSkipLineRight;
     1322
     1323  UInt lPelX, tPelY;
     1324  TComDataCU *pTmpCu;
     1325
     1326  for (idxY = 0; idxY< frameHeightInCU; idxY++)
     1327  {
     1328    for (idxX = 0; idxX< frameWidthInCU; idxX++)
     1329    {
     1330      lcuWidth  = pTmpSPS->getMaxCUHeight();
     1331      lcuHeight = pTmpSPS->getMaxCUWidth();
     1332      addr     = idxX  + frameWidthInCU*idxY;
     1333      pTmpCu = pcPic->getCU(addr);
     1334      lPelX   = pTmpCu->getCUPelX();
     1335      tPelY   = pTmpCu->getCUPelY();
     1336      for( yCbCr = 0; yCbCr < 3; yCbCr++ )
     1337      {
     1338        isChroma = (yCbCr!=0)? 1:0;
     1339
     1340        for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
     1341        {
     1342          for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
     1343          {
     1344            m_count_PreDblk    [addr][yCbCr][j][k] = 0;
     1345            m_offsetOrg_PreDblk[addr][yCbCr][j][k] = 0;
     1346          } 
     1347        }
     1348        if( yCbCr == 0 )
     1349        {
     1350          picWidthTmp  = m_iPicWidth;
     1351          picHeightTmp = m_iPicHeight;
     1352        }
     1353        else if( yCbCr == 1 )
     1354        {
     1355          picWidthTmp  = m_iPicWidth  >> isChroma;
     1356          picHeightTmp = m_iPicHeight >> isChroma;
     1357          lcuWidth     = lcuWidth    >> isChroma;
     1358          lcuHeight    = lcuHeight   >> isChroma;
     1359          lPelX       = lPelX      >> isChroma;
     1360          tPelY       = tPelY      >> isChroma;
     1361        }
     1362        rPelX       = lPelX + lcuWidth  ;
     1363        bPelY       = tPelY + lcuHeight ;
     1364        rPelX       = rPelX > picWidthTmp  ? picWidthTmp  : rPelX;
     1365        bPelY       = bPelY > picHeightTmp ? picHeightTmp : bPelY;
     1366        lcuWidth     = rPelX - lPelX;
     1367        lcuHeight    = bPelY - tPelY;
     1368
     1369        stride    =  (yCbCr == 0)? pcPic->getStride(): pcPic->getCStride();
     1370
     1371        //if(iSaoType == BO)
     1372
     1373        numSkipLine = isChroma? 1:3;
     1374        numSkipLineRight = isChroma? 2:4;
     1375
     1376        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_BO];
     1377        count = m_count_PreDblk[addr][yCbCr][SAO_BO];
     1378
     1379        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1380        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1381
     1382        startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
     1383        startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
     1384
     1385        for (y=0; y<lcuHeight; y++)
     1386        {
     1387          for (x=0; x<lcuWidth; x++)
     1388          {
     1389            if( x < startX && y < startY )
     1390              continue;
     1391
     1392            classIdx = m_lumaTableBo[pRec[x]];
     1393            if (classIdx)
     1394            {
     1395              stats[classIdx] += (pOrg[x] - pRec[x]);
     1396              count[classIdx] ++;
     1397            }
     1398          }
     1399          pOrg += stride;
     1400          pRec += stride;
     1401        }
     1402
     1403        Int signLeft;
     1404        Int signRight;
     1405        Int signDown;
     1406        Int signDown1;
     1407        Int signDown2;
     1408
     1409        UInt uiEdgeType;
     1410
     1411        //if (iSaoType == EO_0)
     1412
     1413        numSkipLine = isChroma? 1:3;
     1414        numSkipLineRight = isChroma? 3:5;
     1415
     1416        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_0];
     1417        count = m_count_PreDblk[addr][yCbCr][SAO_EO_0];
     1418
     1419        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1420        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1421
     1422        startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
     1423        startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
     1424        firstX   = (lPelX == 0) ? 1 : 0;
     1425        endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
     1426
     1427        for (y=0; y<lcuHeight; y++)
     1428        {
     1429          signLeft = xSign(pRec[firstX] - pRec[firstX-1]);
     1430          for (x=firstX; x< endX; x++)
     1431          {
     1432            signRight =  xSign(pRec[x] - pRec[x+1]);
     1433            uiEdgeType =  signRight + signLeft + 2;
     1434            signLeft  = -signRight;
     1435
     1436            if( x < startX && y < startY )
     1437              continue;
     1438
     1439            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1440            count[m_auiEoTable[uiEdgeType]] ++;
     1441          }
     1442          pOrg += stride;
     1443          pRec += stride;
     1444        }
     1445
     1446        //if (iSaoType == EO_1)
     1447
     1448        numSkipLine = isChroma? 2:4;
     1449        numSkipLineRight = isChroma? 2:4;
     1450
     1451        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_1];
     1452        count = m_count_PreDblk[addr][yCbCr][SAO_EO_1];
     1453
     1454        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1455        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1456
     1457        startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
     1458        startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
     1459        firstY = (tPelY == 0) ? 1 : 0;
     1460        endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
     1461        if (firstY == 1)
     1462        {
     1463          pOrg += stride;
     1464          pRec += stride;
     1465        }
     1466
     1467        for (x=0; x< lcuWidth; x++)
     1468        {
     1469          m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
     1470        }
     1471        for (y=firstY; y<endY; y++)
     1472        {
     1473          for (x=0; x<lcuWidth; x++)
     1474          {
     1475            signDown     =  xSign(pRec[x] - pRec[x+stride]);
     1476            uiEdgeType    =  signDown + m_iUpBuff1[x] + 2;
     1477            m_iUpBuff1[x] = -signDown;
     1478
     1479            if( x < startX && y < startY )
     1480              continue;
     1481
     1482            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1483            count[m_auiEoTable[uiEdgeType]] ++;
     1484          }
     1485          pOrg += stride;
     1486          pRec += stride;
     1487        }
     1488
     1489        //if (iSaoType == EO_2)
     1490
     1491        numSkipLine = isChroma? 2:4;
     1492        numSkipLineRight = isChroma? 3:5;
     1493
     1494        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_2];
     1495        count = m_count_PreDblk[addr][yCbCr][SAO_EO_2];
     1496
     1497        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1498        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1499
     1500        startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
     1501        startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
     1502        firstX   = (lPelX == 0) ? 1 : 0;
     1503        firstY = (tPelY == 0) ? 1 : 0;
     1504        endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
     1505        endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
     1506        if (firstY == 1)
     1507        {
     1508          pOrg += stride;
     1509          pRec += stride;
     1510        }
     1511
     1512        for (x=firstX; x<endX; x++)
     1513        {
     1514          m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride-1]);
     1515        }
     1516        for (y=firstY; y<endY; y++)
     1517        {
     1518          signDown2 = xSign(pRec[stride+startX] - pRec[startX-1]);
     1519          for (x=firstX; x<endX; x++)
     1520          {
     1521            signDown1      =  xSign(pRec[x] - pRec[x+stride+1]) ;
     1522            uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     1523            m_iUpBufft[x+1] = -signDown1;
     1524
     1525            if( x < startX && y < startY )
     1526              continue;
     1527
     1528            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1529            count[m_auiEoTable[uiEdgeType]] ++;
     1530          }
     1531          m_iUpBufft[firstX] = signDown2;
     1532          ipSwap     = m_iUpBuff1;
     1533          m_iUpBuff1 = m_iUpBufft;
     1534          m_iUpBufft = ipSwap;
     1535
     1536          pRec += stride;
     1537          pOrg += stride;
     1538        }
     1539
     1540        //if (iSaoType == EO_3)
     1541
     1542        numSkipLine = isChroma? 2:4;
     1543        numSkipLineRight = isChroma? 3:5;
     1544
     1545        stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_3];
     1546        count = m_count_PreDblk[addr][yCbCr][SAO_EO_3];
     1547
     1548        pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
     1549        pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
     1550
     1551        startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
     1552        startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
     1553        firstX   = (lPelX == 0) ? 1 : 0;
     1554        firstY = (tPelY == 0) ? 1 : 0;
     1555        endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
     1556        endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
     1557        if (firstY == 1)
     1558        {
     1559          pOrg += stride;
     1560          pRec += stride;
     1561        }
     1562
     1563        for (x=firstX-1; x<endX; x++)
     1564        {
     1565          m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride+1]);
     1566        }
     1567
     1568        for (y=firstY; y<endY; y++)
     1569        {
     1570          for (x=firstX; x<endX; x++)
     1571          {
     1572            signDown1      =  xSign(pRec[x] - pRec[x+stride-1]) ;
     1573            uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     1574            m_iUpBuff1[x-1] = -signDown1;
     1575
     1576            if( x < startX && y < startY )
     1577              continue;
     1578
     1579            stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
     1580            count[m_auiEoTable[uiEdgeType]] ++;
     1581          }
     1582          m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
     1583
     1584          pRec += stride;
     1585          pOrg += stride;
     1586        }
     1587      }
     1588    }
     1589  }
     1590}
     1591
     1592
     1593/** get SAO statistics
     1594 * \param  *psQTPart,  iYCbCr
     1595 */
     1596Void TEncSampleAdaptiveOffset::getSaoStats(SAOQTPart *psQTPart, Int iYCbCr)
     1597{
     1598  Int iLevelIdx, iPartIdx, iTypeIdx, iClassIdx;
     1599  Int i;
     1600  Int iNumTotalType = MAX_NUM_SAO_TYPE;
     1601  Int LcuIdxX;
     1602  Int LcuIdxY;
     1603  Int iAddr;
     1604  Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
     1605  Int iDownPartIdx;
     1606  Int iPartStart;
     1607  Int iPartEnd;
     1608  SAOQTPart*  pOnePart;
     1609
     1610  if (m_uiMaxSplitLevel == 0)
     1611  {
     1612    iPartIdx = 0;
     1613    pOnePart = &(psQTPart[iPartIdx]);
     1614    for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
     1615    {
     1616      for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
     1617      {
     1618        iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
     1619        calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
     1620      }
     1621    }
     1622  }
     1623  else
     1624  {
     1625    for(iPartIdx=m_aiNumCulPartsLevel[m_uiMaxSplitLevel-1]; iPartIdx<m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; iPartIdx++)
     1626    {
     1627      pOnePart = &(psQTPart[iPartIdx]);
     1628      for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
     1629      {
     1630        for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
     1631        {
     1632          iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
     1633          calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
     1634        }
     1635      }
     1636    }
     1637    for (iLevelIdx = m_uiMaxSplitLevel-1; iLevelIdx>=0; iLevelIdx-- )
     1638    {
     1639      iPartStart = (iLevelIdx > 0) ? m_aiNumCulPartsLevel[iLevelIdx-1] : 0;
     1640      iPartEnd   = m_aiNumCulPartsLevel[iLevelIdx];
     1641
     1642      for(iPartIdx = iPartStart; iPartIdx < iPartEnd; iPartIdx++)
     1643      {
     1644        pOnePart = &(psQTPart[iPartIdx]);
     1645        for (i=0; i< NUM_DOWN_PART; i++)
     1646        {
     1647          iDownPartIdx = pOnePart->DownPartsIdx[i];
     1648          for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++)
     1649          {
     1650            for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++)
     1651            {
     1652              m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx];
     1653              m_iCount [iPartIdx][iTypeIdx][iClassIdx]    += m_iCount [iDownPartIdx][iTypeIdx][iClassIdx];
     1654            }
     1655          }
     1656        }
     1657      }
     1658    }
     1659  }
     1660}
     1661
     1662/** reset offset statistics
     1663 * \param
     1664 */
     1665Void TEncSampleAdaptiveOffset::resetStats()
     1666{
     1667  for (Int i=0;i<m_iNumTotalParts;i++)
     1668  {
     1669    m_dCostPartBest[i] = MAX_DOUBLE;
     1670    m_iTypePartBest[i] = -1;
     1671    m_iDistOrg[i] = 0;
     1672    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
     1673    {
     1674      m_iDist[i][j] = 0;
     1675      m_iRate[i][j] = 0;
     1676      m_dCost[i][j] = 0;
     1677      for (Int k=0;k<MAX_NUM_SAO_CLASS;k++)
     1678      {
     1679        m_iCount [i][j][k] = 0;
     1680        m_iOffset[i][j][k] = 0;
     1681        m_iOffsetOrg[i][j][k] = 0;
     1682      } 
     1683    }
     1684  }
     1685}
     1686
     1687#if SAO_CHROMA_LAMBDA
     1688/** Sample adaptive offset process
     1689 * \param pcSaoParam
     1690 * \param dLambdaLuma
     1691 * \param dLambdaChroma
     1692 */
     1693#if SAO_ENCODING_CHOICE
     1694Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma, Int depth)
     1695#else
     1696Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma)
     1697#endif
     1698#else
     1699/** Sample adaptive offset process
     1700 * \param dLambda
     1701 */
     1702Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda)
     1703#endif
     1704{
     1705    m_eSliceType          =  m_pcPic->getSlice(0)->getSliceType();
     1706    m_iPicNalReferenceIdc = (m_pcPic->getSlice(0)->isReferenced() ? 1 :0);
     1707
     1708#if SAO_CHROMA_LAMBDA
     1709    m_dLambdaLuma    = dLambdaLuma;
     1710    m_dLambdaChroma  = dLambdaChroma;
     1711#else
     1712    m_dLambdaLuma    = dLambda;
     1713    m_dLambdaChroma  = dLambda;
     1714#endif
     1715
     1716    if(m_bUseNIF)
     1717    {
     1718        m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
     1719    }
     1720
     1721#if FULL_NBIT
     1722    m_uiSaoBitIncrease = g_uiBitDepth + (g_uiBitDepth-8) - min((Int)(g_uiBitDepth + (g_uiBitDepth-8)), 10);
     1723#else
     1724    m_uiSaoBitIncrease = g_uiBitDepth + g_uiBitIncrement - min((Int)(g_uiBitDepth + g_uiBitIncrement), 10);
     1725#endif
     1726
     1727#if FULL_NBIT
     1728    m_iOffsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
     1729#else
     1730    m_iOffsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
     1731#endif
     1732
     1733    resetSAOParam(pcSaoParam);
     1734    if( !m_saoLcuBasedOptimization || !m_saoLcuBoundary )
     1735    {
     1736        resetStats();
     1737    }
     1738    Double dCostFinal = 0;
     1739    if ( m_saoLcuBasedOptimization)
     1740    {
     1741#if SAO_ENCODING_CHOICE
     1742        rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma, depth);
     1743#else
     1744        rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma);
     1745#endif
     1746    }
     1747    else
     1748    {
     1749        pcSaoParam->bSaoFlag[0] = 1;
     1750        pcSaoParam->bSaoFlag[1] = 0;
     1751        dCostFinal = 0;
     1752        Double lambdaRdo =  dLambdaLuma;
     1753        resetStats();
     1754        getSaoStats(pcSaoParam->psSaoPart[0], 0);
     1755        runQuadTreeDecision(pcSaoParam->psSaoPart[0], 0, dCostFinal, m_uiMaxSplitLevel, lambdaRdo, 0);
     1756        pcSaoParam->bSaoFlag[0] = dCostFinal < 0 ? 1:0;
     1757        if(pcSaoParam->bSaoFlag[0])
     1758        {
     1759            convertQT2SaoUnit(pcSaoParam, 0, 0);
     1760            assignSaoUnitSyntax(pcSaoParam->saoLcuParam[0],  pcSaoParam->psSaoPart[0], pcSaoParam->oneUnitFlag[0], 0);
     1761        }
     1762    }
     1763
     1764    if (pcSaoParam->bSaoFlag[0])
     1765    {
     1766        processSaoUnitAll( pcSaoParam->saoLcuParam[0], pcSaoParam->oneUnitFlag[0], 0);
     1767    }
     1768    if (pcSaoParam->bSaoFlag[1])
     1769    {
     1770        processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);
     1771        processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);
     1772    }
     1773}
     1774/** Check merge SAO unit
     1775* \param saoUnitCurr current SAO unit
     1776* \param saoUnitCheck SAO unit tobe check
     1777* \param dir direction
     1778*/
     1779Void TEncSampleAdaptiveOffset::checkMerge(SaoLcuParam * saoUnitCurr, SaoLcuParam * saoUnitCheck, Int dir)
     1780{
     1781    Int i ;
     1782    Int countDiff = 0;
     1783    if (saoUnitCurr->partIdx != saoUnitCheck->partIdx)
     1784    {
     1785        if (saoUnitCurr->typeIdx !=-1)
     1786        {
     1787            if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
     1788            {
     1789                for (i=0;i<saoUnitCurr->length;i++)
     1790                {
     1791                    countDiff += (saoUnitCurr->offset[i] != saoUnitCheck->offset[i]);
     1792                }
     1793                countDiff += (saoUnitCurr->subTypeIdx != saoUnitCheck->subTypeIdx);
     1794                if (countDiff ==0)
     1795                {
     1796                    saoUnitCurr->partIdx = saoUnitCheck->partIdx;
     1797                    if (dir == 1)
     1798                    {
     1799                        saoUnitCurr->mergeUpFlag = 1;
     1800                        saoUnitCurr->mergeLeftFlag = 0;
     1801                    }
     1802                    else
     1803                    {
     1804                        saoUnitCurr->mergeUpFlag = 0;
     1805                        saoUnitCurr->mergeLeftFlag = 1;
     1806                    }
     1807                }
     1808            }
     1809        }
     1810        else
     1811        {
     1812            if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
     1813            {
     1814                saoUnitCurr->partIdx = saoUnitCheck->partIdx;
     1815                if (dir == 1)
     1816                {
     1817                    saoUnitCurr->mergeUpFlag = 1;
     1818                    saoUnitCurr->mergeLeftFlag = 0;
     1819                }
     1820                else
     1821                {
     1822                    saoUnitCurr->mergeUpFlag = 0;
     1823                    saoUnitCurr->mergeLeftFlag = 1;
     1824                }
     1825            }
     1826        }
     1827    }
     1828}
     1829/** Assign SAO unit syntax from picture-based algorithm
     1830* \param saoLcuParam SAO LCU parameters
     1831* \param saoPart SAO part
     1832* \param oneUnitFlag SAO one unit flag
     1833* \param iYCbCr color component Index
     1834*/
     1835Void TEncSampleAdaptiveOffset::assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr)
     1836{
     1837    if (saoPart->bSplit == 0)
     1838    {
     1839        oneUnitFlag = 1;
     1840    }
     1841    else
     1842    {
     1843        Int i,j, addr, addrUp, addrLeft,  idx, idxUp, idxLeft,  idxCount;
     1844   
     1845        oneUnitFlag = 0;
     1846       
     1847        idxCount = -1;
     1848        saoLcuParam[0].mergeUpFlag = 0;
     1849        saoLcuParam[0].mergeLeftFlag = 0;
     1850       
     1851        for (j=0;j<m_iNumCuInHeight;j++)
     1852        {
     1853            for (i=0;i<m_iNumCuInWidth;i++)
     1854            {
     1855                addr     = i + j*m_iNumCuInWidth;
     1856                addrLeft = (addr%m_iNumCuInWidth == 0) ? -1 : addr - 1;
     1857                addrUp   = (addr<m_iNumCuInWidth)      ? -1 : addr - m_iNumCuInWidth;
     1858                idx      = saoLcuParam[addr].partIdxTmp;
     1859                idxLeft  = (addrLeft == -1) ? -1 : saoLcuParam[addrLeft].partIdxTmp;
     1860                idxUp    = (addrUp == -1)   ? -1 : saoLcuParam[addrUp].partIdxTmp;
     1861
     1862                if(idx!=idxLeft && idx!=idxUp)
     1863                {
     1864                    saoLcuParam[addr].mergeUpFlag   = 0; idxCount++;
     1865                    saoLcuParam[addr].mergeLeftFlag = 0;
     1866                    saoLcuParam[addr].partIdx = idxCount;
     1867                }
     1868                else if (idx==idxLeft)
     1869                {       
     1870                    saoLcuParam[addr].mergeUpFlag   = 1;
     1871                    saoLcuParam[addr].mergeLeftFlag = 1;
     1872                    saoLcuParam[addr].partIdx = saoLcuParam[addrLeft].partIdx;
     1873                }
     1874                else if (idx==idxUp)
     1875                {
     1876                    saoLcuParam[addr].mergeUpFlag   = 1;
     1877                    saoLcuParam[addr].mergeLeftFlag = 0;
     1878                    saoLcuParam[addr].partIdx = saoLcuParam[addrUp].partIdx;
     1879                }
     1880                if (addrUp != -1)
     1881                {
     1882                    checkMerge(&saoLcuParam[addr], &saoLcuParam[addrUp], 1);
     1883                }
     1884                if (addrLeft != -1)
     1885                {
     1886                    checkMerge(&saoLcuParam[addr], &saoLcuParam[addrLeft], 0);
     1887                }
     1888            }
     1889        }
     1890    }
     1891}
     1892/** rate distortion optimization of all SAO units
     1893* \param saoParam SAO parameters
     1894* \param lambda
     1895* \param lambdaChroma
     1896*/
     1897#if SAO_ENCODING_CHOICE
     1898Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth)
     1899#else
     1900Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma)
     1901#endif
     1902{
     1903    Int idxY;
     1904    Int idxX;
     1905    Int frameHeightInCU = saoParam->numCuInHeight;
     1906    Int frameWidthInCU  = saoParam->numCuInWidth;
     1907    Int j, k;
     1908    Int addr = 0;
     1909    Int addrUp = -1;
     1910    Int addrLeft = -1;
     1911    Int compIdx = 0;
     1912    SaoLcuParam mergeSaoParam[3][2];
     1913    Double compDistortion[3];
     1914
     1915    saoParam->bSaoFlag[0] = true;
     1916    saoParam->bSaoFlag[1] = true;
     1917    saoParam->oneUnitFlag[0] = false;
     1918    saoParam->oneUnitFlag[1] = false;
     1919    saoParam->oneUnitFlag[2] = false;
     1920
     1921#if SAO_ENCODING_CHOICE
     1922#if SAO_ENCODING_CHOICE_CHROMA
     1923    Int numNoSao[2];
     1924    numNoSao[0] = 0;// Luma
     1925    numNoSao[1] = 0;// Chroma
     1926    if( depth > 0 && m_depthSaoRate[0][depth-1] > SAO_ENCODING_RATE )
     1927    {
     1928        saoParam->bSaoFlag[0] = false;
     1929    }
     1930
     1931    if( depth > 0 && m_depthSaoRate[1][depth-1] > SAO_ENCODING_RATE_CHROMA )
     1932    {
     1933        saoParam->bSaoFlag[1] = false;
     1934    }
     1935#else
     1936    Int numNoSao = 0;
     1937
     1938    if( depth > 0 && m_depth0SaoRate > SAO_ENCODING_RATE )
     1939    {
     1940        saoParam->bSaoFlag[0] = false;
     1941        saoParam->bSaoFlag[1] = false;
     1942    }
     1943#endif
     1944#endif
     1945
     1946    for (idxY = 0; idxY< frameHeightInCU; idxY++)
     1947    {
     1948        for (idxX = 0; idxX< frameWidthInCU; idxX++)
     1949        {
     1950            addr     = idxX  + frameWidthInCU*idxY;
     1951            addrUp   = addr < frameWidthInCU ? -1:idxX   + frameWidthInCU*(idxY-1);
     1952            addrLeft = idxX == 0               ? -1:idxX-1 + frameWidthInCU*idxY;
     1953            Int allowMergeLeft = 1;
     1954            Int allowMergeUp   = 1;
     1955            UInt rate;
     1956            Double bestCost, mergeCost;
     1957
     1958            if (idxX!=0)
     1959            {
     1960                // check tile id and slice id
     1961                if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     1962                {
     1963                    allowMergeLeft = 0;
     1964                }
     1965            }
     1966            else
     1967            {
     1968                allowMergeLeft = 0;
     1969            }
     1970            if (idxY!=0)
     1971            {
     1972                if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
     1973                {
     1974                    allowMergeUp = 0;
     1975                }
     1976            }
     1977            else
     1978            {
     1979                allowMergeUp = 0;
     1980            }
     1981
     1982            compDistortion[0] = 0;
     1983            compDistortion[1] = 0;
     1984            compDistortion[2] = 0;
     1985            m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     1986
     1987            if (allowMergeLeft)
     1988            {
     1989                m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     1990            }
     1991            if (allowMergeUp)
     1992            {
     1993                m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     1994            }
     1995
     1996            m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
     1997
     1998            // reset stats Y, Cb, Cr
     1999            for ( compIdx=0;compIdx<3;compIdx++)
     2000            {
     2001                for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
     2002                {
     2003                    for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
     2004                    {
     2005                        m_iOffset   [compIdx][j][k] = 0;
     2006                        if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
     2007                        {
     2008                            m_iCount    [compIdx][j][k] = m_count_PreDblk    [addr][compIdx][j][k];
     2009                            m_iOffsetOrg[compIdx][j][k] = m_offsetOrg_PreDblk[addr][compIdx][j][k];
     2010                        }
     2011                        else
     2012                        {
     2013                            m_iCount    [compIdx][j][k] = 0;
     2014                            m_iOffsetOrg[compIdx][j][k] = 0;
     2015                        }
     2016                    } 
     2017                }
     2018                saoParam->saoLcuParam[compIdx][addr].typeIdx       =  -1;
     2019                saoParam->saoLcuParam[compIdx][addr].mergeUpFlag   = 0;
     2020                saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0;
     2021                saoParam->saoLcuParam[compIdx][addr].subTypeIdx    = 0;
     2022#if SAO_ENCODING_CHOICE
     2023                if( (compIdx ==0 && saoParam->bSaoFlag[0])|| (compIdx >0 && saoParam->bSaoFlag[1]) )
     2024#endif
     2025                {
     2026                    calcSaoStatsCu(addr, compIdx,  compIdx);
     2027                }
     2028            }
     2029            saoComponentParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, 0,  lambda, &mergeSaoParam[0][0], &compDistortion[0]);
     2030            sao2ChromaParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, lambdaChroma, &mergeSaoParam[1][0], &mergeSaoParam[2][0], &compDistortion[0]);
     2031            if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
     2032            {
     2033                // Cost of new SAO_params
     2034                m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     2035                m_pcRDGoOnSbacCoder->resetBits();
     2036                if (allowMergeLeft)
     2037                {
     2038                    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     2039                }
     2040                if (allowMergeUp)
     2041                {
     2042                    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
     2043                }
     2044                for ( compIdx=0;compIdx<3;compIdx++)
     2045                {
     2046                    if( (compIdx ==0 && saoParam->bSaoFlag[0]) || (compIdx >0 && saoParam->bSaoFlag[1]))
     2047                    {
     2048                        m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
     2049                    }
     2050                }
     2051   
     2052                rate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2053                bestCost = compDistortion[0] + (Double)rate;
     2054                m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2055   
     2056                // Cost of Merge
     2057                for(Int mergeUp=0; mergeUp<2; ++mergeUp)
     2058                {
     2059                    if ( (allowMergeLeft && (mergeUp==0)) || (allowMergeUp && (mergeUp==1)) )
     2060                    {
     2061                        m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     2062                        m_pcRDGoOnSbacCoder->resetBits();
     2063                        if (allowMergeLeft)
     2064                        {
     2065                            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1-mergeUp);
     2066                        }
     2067                        if ( allowMergeUp && (mergeUp==1) )
     2068                        {
     2069                            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1);
     2070                        }
     2071   
     2072                        rate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2073                        mergeCost = compDistortion[mergeUp+1] + (Double)rate;
     2074                        if (mergeCost < bestCost)
     2075                        {
     2076                            bestCost = mergeCost;
     2077                            m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);             
     2078                            for ( compIdx=0;compIdx<3;compIdx++)
     2079                            {
     2080                                mergeSaoParam[compIdx][mergeUp].mergeLeftFlag = 1-mergeUp;
     2081                                mergeSaoParam[compIdx][mergeUp].mergeUpFlag = mergeUp;
     2082                                if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1]))
     2083                                {
     2084                                    copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] );             
     2085                                }
     2086                            }
     2087                        }
     2088                    }
     2089                }
     2090#if SAO_ENCODING_CHOICE
     2091#if SAO_ENCODING_CHOICE_CHROMA
     2092                if( saoParam->saoLcuParam[0][addr].typeIdx == -1)
     2093                {
     2094                    numNoSao[0]++;
     2095                }
     2096                if( saoParam->saoLcuParam[1][addr].typeIdx == -1)
     2097                {
     2098                    numNoSao[1]+=2;
     2099                }
     2100#else
     2101                for ( compIdx=0;compIdx<3;compIdx++)
     2102                {
     2103                    if( depth == 0 && saoParam->saoLcuParam[compIdx][addr].typeIdx == -1)
     2104                    {
     2105                        numNoSao++;
     2106                    }
     2107                }
     2108#endif
     2109#endif
     2110                m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2111                m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     2112            }
     2113        }
     2114    }
     2115#if SAO_ENCODING_CHOICE
     2116#if SAO_ENCODING_CHOICE_CHROMA
     2117#if SAO_ENCODING_CHOICE_CHROMA_BF
     2118    if( !saoParam->bSaoFlag[0])
     2119    {
     2120        m_depthSaoRate[0][depth] = 1.0;
     2121    }
     2122    else
     2123    {
     2124        m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU);
     2125    }
     2126    if( !saoParam->bSaoFlag[1])
     2127    {
     2128        m_depthSaoRate[1][depth] = 1.0;
     2129    }
     2130    else
     2131    {
     2132        m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2);
     2133    }
     2134#else
     2135    m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU);
     2136    m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2);
     2137#endif
     2138#else
     2139    if( depth == 0)
     2140    {
     2141        // update SAO Rate
     2142        m_depth0SaoRate = numNoSao/((Double) frameHeightInCU*frameWidthInCU*3);
     2143    }
     2144#endif
     2145#endif
     2146}
     2147/** rate distortion optimization of SAO unit
     2148* \param saoParam SAO parameters
     2149* \param addr address
     2150* \param addrUp above address
     2151* \param addrLeft left address
     2152* \param yCbCr color component index
     2153* \param lambda
     2154*/
     2155inline Int64 TEncSampleAdaptiveOffset::estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo)
     2156{
     2157    Int64 estDist = 0;
     2158    Int classIdx;
     2159    for(classIdx=1; classIdx < ( (typeIdx < SAO_BO) ?  m_iNumClass[typeIdx]+1 : SAO_MAX_BO_CLASSES+1); classIdx++)
     2160    {
     2161        if( typeIdx == SAO_BO)
     2162        {
     2163            currentDistortionTableBo[classIdx-1] = 0;
     2164            currentRdCostTableBo[classIdx-1] = lambda;
     2165        }
     2166        if(m_iCount [compIdx][typeIdx][classIdx])
     2167        {
     2168#if FULL_NBIT
     2169            m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<g_uiBitDepth-8)   / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<m_uiSaoBitIncrease));
     2170#else
     2171            m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<g_uiBitIncrement) / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<m_uiSaoBitIncrease));
     2172#endif
     2173            m_iOffset[compIdx][typeIdx][classIdx] = Clip3(-m_iOffsetTh+1, m_iOffsetTh-1, (Int)m_iOffset[compIdx][typeIdx][classIdx]);
     2174            if (typeIdx < 4)
     2175            {
     2176                if ( m_iOffset[compIdx][typeIdx][classIdx]<0 && classIdx<3 )
     2177                {
     2178                    m_iOffset[compIdx][typeIdx][classIdx] = 0;
     2179                }
     2180                if ( m_iOffset[compIdx][typeIdx][classIdx]>0 && classIdx>=3)
     2181                {
     2182                    m_iOffset[compIdx][typeIdx][classIdx] = 0;
     2183                }
     2184            }
     2185            m_iOffset[compIdx][typeIdx][classIdx] = estIterOffset( typeIdx, classIdx, lambda, m_iOffset[compIdx][typeIdx][classIdx], m_iCount [compIdx][typeIdx][classIdx], m_iOffsetOrg[compIdx][typeIdx][classIdx], shift, m_uiSaoBitIncrease, currentDistortionTableBo, currentRdCostTableBo );
     2186        }
     2187        else
     2188        {
     2189            m_iOffsetOrg[compIdx][typeIdx][classIdx] = 0;
     2190            m_iOffset[compIdx][typeIdx][classIdx] = 0;
     2191        }
     2192        if( typeIdx != SAO_BO )
     2193        {
     2194            estDist   += estSaoDist( m_iCount [compIdx][typeIdx][classIdx], m_iOffset[compIdx][typeIdx][classIdx] << m_uiSaoBitIncrease, m_iOffsetOrg[compIdx][typeIdx][classIdx], shift);
     2195        }
     2196    }
     2197    return estDist;
     2198}
     2199
     2200inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift)
     2201{
     2202    return (( count*offset*offset-offsetOrg*offset*2 ) >> shift);
     2203}
     2204inline Int64 TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo )
     2205{
     2206    //Clean up, best_q_offset.
     2207    Int64 iterOffset, tempOffset;
     2208    Int64 tempDist, tempRate;
     2209    Double tempCost, tempMinCost;
     2210    Int64 offsetOutput = 0;
     2211    iterOffset = offsetInput;
     2212    // 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.
     2213    tempMinCost = lambda;
     2214    while (iterOffset != 0)
     2215    {
     2216        // Calculate the bits required for signalling the offset
     2217        tempRate = (typeIdx == SAO_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
     2218        if (abs((Int)iterOffset)==m_iOffsetTh-1)
     2219        { 
     2220            tempRate --;
     2221        }
     2222        // Do the dequntization before distorion calculation
     2223        tempOffset  = iterOffset << bitIncrease;
     2224        tempDist    = estSaoDist( count, tempOffset, offsetOrg, shift);
     2225        tempCost    = ((Double)tempDist + lambda * (Double) tempRate);
     2226        if(tempCost < tempMinCost)
     2227        {
     2228            tempMinCost = tempCost;
     2229            offsetOutput = iterOffset;
     2230            if(typeIdx == SAO_BO)
     2231            {
     2232                currentDistortionTableBo[classIdx-1] = (Int) tempDist;
     2233                currentRdCostTableBo[classIdx-1] = tempCost;
     2234            }
     2235        }
     2236        iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1);
     2237    }
     2238    return offsetOutput;
     2239}
     2240
     2241Void TEncSampleAdaptiveOffset::saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *compDistortion)
     2242{
     2243    Int typeIdx;
     2244    Int64 estDist;
     2245    Int classIdx;
     2246
     2247    Int shift = g_uiBitIncrement << 1;
     2248
     2249    Int64 bestDist;
     2250
     2251    SaoLcuParam*  saoLcuParam = &(saoParam->saoLcuParam[yCbCr][addr]);
     2252    SaoLcuParam*  saoLcuParamNeighbor = NULL;
     2253
     2254    resetSaoUnit(saoLcuParam);
     2255    resetSaoUnit(&compSaoParam[0]);
     2256    resetSaoUnit(&compSaoParam[1]);
     2257
     2258    Double dCostPartBest = MAX_DOUBLE;
     2259
     2260    Double  bestRDCostTableBo = MAX_DOUBLE;
     2261    Int     bestClassTableBo    = 0;
     2262    Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     2263    Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     2264
     2265    SaoLcuParam   saoLcuParamRdo;   
     2266    Double   estRate = 0;
     2267
     2268    resetSaoUnit(&saoLcuParamRdo);
     2269
     2270    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2271    m_pcRDGoOnSbacCoder->resetBits();
     2272    m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
     2273    dCostPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
     2274
     2275    copySaoUnit(saoLcuParam, &saoLcuParamRdo );
     2276
     2277    bestDist = 0;
     2278
     2279    for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
     2280    {
     2281        estDist = estSaoTypeDist(yCbCr, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2282        if( typeIdx == SAO_BO )
     2283        {
     2284            // Estimate Best Position
     2285            Double currentRDCost = 0.0;
     2286
     2287            for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     2288            {
     2289                currentRDCost = 0.0;
     2290                for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     2291                {
     2292                    currentRDCost += currentRdCostTableBo[uj];
     2293                }
     2294
     2295                if( currentRDCost < bestRDCostTableBo)
     2296                {
     2297                    bestRDCostTableBo = currentRDCost;
     2298                    bestClassTableBo  = i;
     2299                }
     2300            }
     2301
     2302            // Re code all Offsets
     2303            // Code Center
     2304            estDist = 0;
     2305            for(classIdx = bestClassTableBo; classIdx < bestClassTableBo+SAO_BO_LEN; classIdx++)
     2306            {
     2307                estDist += currentDistortionTableBo[classIdx];
     2308            }
     2309        }
     2310        resetSaoUnit(&saoLcuParamRdo);
     2311        saoLcuParamRdo.length = m_iNumClass[typeIdx];
     2312        saoLcuParamRdo.typeIdx = typeIdx;
     2313        saoLcuParamRdo.mergeLeftFlag = 0;
     2314        saoLcuParamRdo.mergeUpFlag   = 0;
     2315        saoLcuParamRdo.subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo : 0;
     2316        for (classIdx = 0; classIdx < saoLcuParamRdo.length; classIdx++)
     2317        {
     2318            saoLcuParamRdo.offset[classIdx] = (Int)m_iOffset[yCbCr][typeIdx][classIdx+saoLcuParamRdo.subTypeIdx+1];
     2319        }
     2320        m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2321        m_pcRDGoOnSbacCoder->resetBits();
     2322        m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
     2323
     2324        estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2325        m_dCost[yCbCr][typeIdx] = (Double)((Double)estDist + lambda * (Double) estRate);
     2326
     2327        if(m_dCost[yCbCr][typeIdx] < dCostPartBest)
     2328        {
     2329            dCostPartBest = m_dCost[yCbCr][typeIdx];
     2330            copySaoUnit(saoLcuParam, &saoLcuParamRdo );
     2331            bestDist = estDist;       
     2332        }
     2333    }
     2334
     2335    compDistortion[0] += ((Double)bestDist/lambda);
     2336    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2337    m_pcEntropyCoder->encodeSaoOffset(saoLcuParam, yCbCr);
     2338    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
     2339
     2340    // merge left or merge up
     2341    for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
     2342    {
     2343        saoLcuParamNeighbor = NULL;
     2344        if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
     2345        {
     2346            saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrLeft]);
     2347        }
     2348        else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
     2349        {
     2350            saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrUp]);
     2351        }
     2352        if (saoLcuParamNeighbor!=NULL)
     2353        {
     2354            estDist = 0;
     2355            typeIdx = saoLcuParamNeighbor->typeIdx;
     2356            if (typeIdx>=0)
     2357            {
     2358                Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor->subTypeIdx:0;
     2359                Int   merge_iOffset;
     2360                for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
     2361                {
     2362                    merge_iOffset = saoLcuParamNeighbor->offset[classIdx];
     2363                    estDist   += estSaoDist(m_iCount [yCbCr][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[yCbCr][typeIdx][classIdx+mergeBandPosition+1],  shift);
     2364                }
     2365            }
     2366            else
     2367            {
     2368                estDist = 0;
     2369            }
     2370
     2371            copySaoUnit(&compSaoParam[idxNeighbor], saoLcuParamNeighbor );
     2372            compSaoParam[idxNeighbor].mergeUpFlag   = idxNeighbor;
     2373            compSaoParam[idxNeighbor].mergeLeftFlag = !idxNeighbor;
     2374
     2375            compDistortion[idxNeighbor+1] += ((Double)estDist/lambda);
     2376        }
     2377    }
     2378}
     2379
     2380Void TEncSampleAdaptiveOffset::sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion)
     2381{
     2382    Int typeIdx;
     2383
     2384    Int64 estDist[2];
     2385    Int classIdx;
     2386    Int shift = g_uiBitIncrement << 1;
     2387    Int64 bestDist = 0;
     2388
     2389    SaoLcuParam*  saoLcuParam[2] = {&(saoParam->saoLcuParam[1][addr]), &(saoParam->saoLcuParam[2][addr])};
     2390    SaoLcuParam*  saoLcuParamNeighbor[2] = {NULL, NULL};
     2391    SaoLcuParam*  saoMergeParam[2][2];
     2392    saoMergeParam[0][0] = &crSaoParam[0];
     2393    saoMergeParam[0][1] = &crSaoParam[1];
     2394    saoMergeParam[1][0] = &cbSaoParam[0];
     2395    saoMergeParam[1][1] = &cbSaoParam[1];
     2396
     2397    resetSaoUnit(saoLcuParam[0]);
     2398    resetSaoUnit(saoLcuParam[1]);
     2399    resetSaoUnit(saoMergeParam[0][0]);
     2400    resetSaoUnit(saoMergeParam[0][1]);
     2401    resetSaoUnit(saoMergeParam[1][0]);
     2402    resetSaoUnit(saoMergeParam[1][1]);
     2403
     2404    Double costPartBest = MAX_DOUBLE;
     2405
     2406    Double  bestRDCostTableBo;
     2407    Int     bestClassTableBo[2]    = {0, 0};
     2408    Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     2409    Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     2410
     2411    SaoLcuParam   saoLcuParamRdo[2];   
     2412    Double   estRate = 0;
     2413
     2414    resetSaoUnit(&saoLcuParamRdo[0]);
     2415    resetSaoUnit(&saoLcuParamRdo[1]);
     2416
     2417    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2418    m_pcRDGoOnSbacCoder->resetBits();
     2419    m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[0], 1);
     2420    m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[1], 2);
     2421
     2422    costPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
     2423    copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
     2424    copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
     2425
     2426    for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
     2427    {
     2428        if( typeIdx == SAO_BO )
     2429        {
     2430            // Estimate Best Position
     2431            for(Int compIdx = 0; compIdx < 2; compIdx++)
     2432            {
     2433                Double currentRDCost = 0.0;
     2434                bestRDCostTableBo = MAX_DOUBLE;
     2435                estDist[compIdx] = estSaoTypeDist(compIdx+1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2436
     2437                for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     2438                {
     2439                    currentRDCost = 0.0;
     2440                    for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     2441                    {
     2442                        currentRDCost += currentRdCostTableBo[uj];
     2443                    }
     2444
     2445                    if( currentRDCost < bestRDCostTableBo)
     2446                    {
     2447                        bestRDCostTableBo = currentRDCost;
     2448                        bestClassTableBo[compIdx]  = i;
     2449                    }
     2450                }
     2451
     2452                // Re code all Offsets
     2453                // Code Center
     2454                estDist[compIdx] = 0;
     2455                for(classIdx = bestClassTableBo[compIdx]; classIdx < bestClassTableBo[compIdx]+SAO_BO_LEN; classIdx++)
     2456                {
     2457                    estDist[compIdx] += currentDistortionTableBo[classIdx];
     2458                }
     2459            }
     2460        }
     2461        else
     2462        {
     2463            estDist[0] = estSaoTypeDist(1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2464            estDist[1] = estSaoTypeDist(2, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
     2465        }
     2466
     2467        m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2468        m_pcRDGoOnSbacCoder->resetBits();
     2469
     2470        for(Int compIdx = 0; compIdx < 2; compIdx++)
     2471        {
     2472            resetSaoUnit(&saoLcuParamRdo[compIdx]);
     2473            saoLcuParamRdo[compIdx].length = m_iNumClass[typeIdx];
     2474            saoLcuParamRdo[compIdx].typeIdx = typeIdx;
     2475            saoLcuParamRdo[compIdx].mergeLeftFlag = 0;
     2476            saoLcuParamRdo[compIdx].mergeUpFlag   = 0;
     2477            saoLcuParamRdo[compIdx].subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo[compIdx] : 0;
     2478            for (classIdx = 0; classIdx < saoLcuParamRdo[compIdx].length; classIdx++)
     2479            {
     2480                saoLcuParamRdo[compIdx].offset[classIdx] = (Int)m_iOffset[compIdx+1][typeIdx][classIdx+saoLcuParamRdo[compIdx].subTypeIdx+1];
     2481            }
     2482            m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[compIdx], compIdx+1);
     2483        }
     2484        estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
     2485        m_dCost[1][typeIdx] = (Double)((Double)(estDist[0] + estDist[1])  + lambda * (Double) estRate);
     2486
     2487        if(m_dCost[1][typeIdx] < costPartBest)
     2488        {
     2489            costPartBest = m_dCost[1][typeIdx];
     2490            copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
     2491            copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
     2492            bestDist = (estDist[0]+estDist[1]);       
     2493        }
     2494    }
     2495
     2496    distortion[0] += ((Double)bestDist/lambda);
     2497    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     2498    m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[0], 1);
     2499    m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[1], 2);
     2500    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
     2501
     2502    // merge left or merge up
     2503
     2504    for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
     2505    {
     2506        for(Int compIdx = 0; compIdx < 2; compIdx++)
     2507        {
     2508            saoLcuParamNeighbor[compIdx] = NULL;
     2509            if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
     2510            {
     2511                saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrLeft]);
     2512            }
     2513            else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
     2514            {
     2515                saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrUp]);
     2516            }
     2517            if (saoLcuParamNeighbor[compIdx]!=NULL)
     2518            {
     2519                estDist[compIdx] = 0;
     2520                typeIdx = saoLcuParamNeighbor[compIdx]->typeIdx;
     2521                if (typeIdx>=0)
     2522                {
     2523                    Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor[compIdx]->subTypeIdx:0;
     2524                    Int   merge_iOffset;
     2525                    for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
     2526                    {
     2527                        merge_iOffset = saoLcuParamNeighbor[compIdx]->offset[classIdx];
     2528                        estDist[compIdx]   += estSaoDist(m_iCount [compIdx+1][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[compIdx+1][typeIdx][classIdx+mergeBandPosition+1],  shift);
     2529                    }
     2530                }
     2531                else
     2532                {
     2533                    estDist[compIdx] = 0;
     2534                }
     2535
     2536                copySaoUnit(saoMergeParam[compIdx][idxNeighbor], saoLcuParamNeighbor[compIdx] );
     2537                saoMergeParam[compIdx][idxNeighbor]->mergeUpFlag   = idxNeighbor;
     2538                saoMergeParam[compIdx][idxNeighbor]->mergeLeftFlag = !idxNeighbor;
     2539                distortion[idxNeighbor+1] += ((Double)estDist[compIdx]/lambda);
     2540            }
     2541        }
     2542    }
     2543}
     2544#else
     2545TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
     2546{
     2547  m_pcEntropyCoder = NULL;
     2548  m_pppcRDSbacCoder = NULL;
     2549  m_pcRDGoOnSbacCoder = NULL;
     2550  m_pppcBinCoderCABAC = NULL;           
     2551  m_iCount = NULL;     
     2552  m_iOffset = NULL;     
     2553  m_iOffsetOrg = NULL; 
     2554  m_iRate = NULL;       
     2555  m_iDist = NULL;       
     2556  m_dCost = NULL;       
     2557  m_dCostPartBest = NULL;
     2558  m_iDistOrg = NULL;     
     2559  m_iTypePartBest = NULL;
     2560}
     2561TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
     2562{
     2563
     2564}
     2565// ====================================================================================================================
     2566// Constants
     2567// ====================================================================================================================
     2568
     2569
     2570// ====================================================================================================================
     2571// Tables
     2572// ====================================================================================================================
     2573
     2574inline Double xRoundIbdi2(Double x)
     2575{
     2576#if FULL_NBIT
     2577  Int bitDepthMinus8 = g_uiBitDepth - 8;
     2578  return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)) : ((Int)(((Int)(x)-(1<<(bitDepthMinus8-1)))/(1<<bitDepthMinus8)));
     2579#else
     2580  return ((x)>0) ? (Int)(((Int)(x)+(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)) : ((Int)(((Int)(x)-(1<<(g_uiBitIncrement-1)))/(1<<g_uiBitIncrement)));
     2581#endif
     2582}
     2583
     2584/** rounding with IBDI
     2585 * \param  x
     2586 */
     2587inline Double xRoundIbdi(Double x)
     2588{
     2589#if FULL_NBIT
     2590  return (g_uiBitDepth > 8 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     2591#else
     2592  return (g_uiBitIncrement >0 ? xRoundIbdi2((x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     2593#endif
     2594}
     2595
     2596
     2597
     2598/** process SAO for one partition
     2599 * \param  *psQTPart, iPartIdx, dLambda
     2600 */
     2601Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda)
     2602{
     2603  Int iTypeIdx;
     2604  Int iNumTotalType = MAX_NUM_SAO_TYPE;
     2605  SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     2606
     2607  Int64 iEstDist;
     2608  Int64 iOffsetOrg;
     2609  Int64 iOffset;
     2610  Int64 iCount;
     2611  Int iClassIdx;
     2612  Int uiShift = g_uiBitIncrement << 1;
     2613  UInt uiDepth = pOnePart->PartLevel;
     2614
     2615  m_iDistOrg [iPartIdx] =  0;
     2616
     2617  Double  bestRDCostTableBo = MAX_DOUBLE;
     2618  Int     bestClassTableBo    = 0;
     2619  Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
     2620  Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
     2621
     2622#if HHI_INTERVIEW_SKIP
     2623  Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
     2624  Int LcuIdxX = psQTPart->StartCUX;
     2625  Int LcuIdxY = psQTPart->StartCUY;
     2626  Int iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
     2627  TComDataCU *pcCU = m_pcPic->getCU(iAddr);
     2628  Bool bRenderable = pcCU->getRenderable(0) ;
     2629
     2630#endif
     2631  for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
     2632  {
     2633    if( m_bUseSBACRD )
     2634    {
     2635      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     2636      m_pcRDGoOnSbacCoder->resetBits();
     2637    }
     2638    else
     2639    {
     2640      m_pcEntropyCoder->resetEntropy();
     2641      m_pcEntropyCoder->resetBits();
     2642    }
     2643
     2644    iEstDist = 0;
     2645
     2646    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoTypeIdx(iTypeIdx+1);
     2647
     2648    if (iTypeIdx>=0)
     2649    {
     2650
     2651      for(iClassIdx=1; iClassIdx < ( (iTypeIdx < SAO_BO) ?  m_iNumClass[iTypeIdx]+1 : SAO_MAX_BO_CLASSES+1); iClassIdx++)
     2652      {
     2653        if( iTypeIdx == SAO_BO)
     2654        {
     2655          currentDistortionTableBo[iClassIdx-1] = 0;
     2656          currentRdCostTableBo[iClassIdx-1] = dLambda;
     2657        }
     2658#if HHI_INTERVIEW_SKIP
     2659        if(m_iCount [iPartIdx][iTypeIdx][iClassIdx] && !bRenderable)
     2660#else
     2661        if(m_iCount [iPartIdx][iTypeIdx][iClassIdx])
     2662#endif
     2663        {
     2664#if FULL_NBIT
     2665          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitDepth-8) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
     2666#else
     2667          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitIncrement) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));
     2668#endif
     2669          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = Clip3(-m_iOffsetTh, m_iOffsetTh-1, (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2670
     2671          if (iTypeIdx < 4)
     2672          {
     2673            if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]<0 && iClassIdx<3 )
     2674            {
     2675              m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2676            }
     2677            if ( m_iOffset[iPartIdx][iTypeIdx][iClassIdx]>0 && iClassIdx>=3)
     2678            {
     2679              m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2680            }
     2681          }
     2682          {
     2683            //Clean up, best_q_offset.
     2684            Int64 iIterOffset, iTempOffset;
     2685            Int64 iTempDist, iTempRate;
     2686            Double dTempCost, dTempMinCost;
     2687            UInt uiLength, uiTemp;
     2688
     2689            iIterOffset = m_iOffset[iPartIdx][iTypeIdx][iClassIdx];
     2690            m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2691            dTempMinCost = dLambda; // 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.
     2692
     2693            while (iIterOffset != 0)
     2694            {
     2695              // Calculate the bits required for signalling the offset
     2696              uiLength = 1;
     2697              uiTemp = (UInt)((iIterOffset <= 0) ? ( (-iIterOffset<<1) + 1 ) : (iIterOffset<<1));
     2698              while( 1 != uiTemp )
     2699              {
     2700                uiTemp >>= 1;
     2701                uiLength += 2;
     2702              }
     2703              iTempRate = (uiLength >> 1) + ((uiLength+1) >> 1);
     2704
     2705              // Do the dequntization before distorion calculation
     2706              iTempOffset    =  iIterOffset << m_uiSaoBitIncrease;
     2707              iTempDist  = (( m_iCount [iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*iTempOffset-m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]*iTempOffset*2 ) >> uiShift);
     2708
     2709              dTempCost = ((Double)iTempDist + dLambda * (Double) iTempRate);
     2710              if(dTempCost < dTempMinCost)
     2711              {
     2712                dTempMinCost = dTempCost;
     2713                m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = iIterOffset;
     2714                if(iTypeIdx == SAO_BO)
     2715                {
     2716                  currentDistortionTableBo[iClassIdx-1] = (Int) iTempDist;
     2717                  currentRdCostTableBo[iClassIdx-1] = dTempCost;
     2718                }
     2719              }
     2720              iIterOffset = (iIterOffset > 0) ? (iIterOffset-1):(iIterOffset+1);
     2721            }
     2722
     2723          }
     2724        }
     2725        else
     2726        {
     2727          m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2728          m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;
     2729        }
     2730        if( iTypeIdx != SAO_BO )
     2731        {
     2732          iCount     =  m_iCount [iPartIdx][iTypeIdx][iClassIdx];
     2733          iOffset    =  m_iOffset[iPartIdx][iTypeIdx][iClassIdx] << m_uiSaoBitIncrease;
     2734          iOffsetOrg =  m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx];
     2735          iEstDist   += (( iCount*iOffset*iOffset-iOffsetOrg*iOffset*2 ) >> uiShift);
     2736          if (iTypeIdx < 4)
     2737          {
     2738            if (iClassIdx<3)
     2739            {
     2740              m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2741            }
     2742            else
     2743            {
     2744              m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUvlc((Int)-m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2745            }
     2746          }
     2747          else
     2748          {
     2749            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);
     2750          }
     2751        }
     2752      }
     2753
     2754      if( iTypeIdx == SAO_BO )
     2755      {
     2756        // Estimate Best Position
     2757        Double currentRDCost = 0.0;
     2758
     2759        for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
     2760        {
     2761          currentRDCost = 0.0;
     2762          for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     2763          {
     2764            currentRDCost += currentRdCostTableBo[uj];
     2765          }
     2766
     2767          if( currentRDCost < bestRDCostTableBo)
     2768          {
     2769            bestRDCostTableBo = currentRDCost;
     2770            bestClassTableBo  = i;
     2771          }
     2772        }
     2773
     2774        // Re code all Offsets
     2775        // Code Center
     2776        m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoUflc( (UInt) (bestClassTableBo) );
     2777
     2778        for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
     2779        {
     2780          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+1]);
     2781          iEstDist += currentDistortionTableBo[iClassIdx];
     2782        }
     2783      }
     2784
     2785      m_iDist[iPartIdx][iTypeIdx] = iEstDist;
     2786      m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
     2787
     2788      m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
     2789
     2790      if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
     2791      {
     2792        m_iDistOrg [iPartIdx] = 0;
     2793        m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
     2794        m_iTypePartBest[iPartIdx] = iTypeIdx;
     2795        if( m_bUseSBACRD )
     2796          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     2797      }
     2798    }
     2799    else
     2800    {
     2801      if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
     2802      {
     2803        m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
     2804        m_iTypePartBest[iPartIdx] = -1;
     2805        if( m_bUseSBACRD )
     2806          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     2807      }
     2808    }
     2809  }
     2810
     2811  pOnePart->bProcessed = true;
     2812  pOnePart->bSplit     = false;
     2813  pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
     2814  pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
     2815  pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
     2816  pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
     2817  if (pOnePart->iBestType != -1)
     2818  {
     2819    //     pOnePart->bEnableFlag =  1;
     2820    pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
     2821    Int minIndex = 0;
     2822    if( pOnePart->iBestType == SAO_BO )
     2823    {
     2824      pOnePart->bandPosition = bestClassTableBo;
     2825      minIndex = pOnePart->bandPosition;
     2826    }
     2827    for (Int i=0; i< pOnePart->iLength ; i++)
     2828    {
     2829      pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
     2830    }
     2831
     2832  }
     2833  else
     2834  {
     2835    //     pOnePart->bEnableFlag = 0;
     2836    pOnePart->iLength     = 0;
     2837  }
     2838}
     2839
     2840/** Run partition tree disable
     2841 */
     2842Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx)
     2843{
     2844  SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
     2845  pOnePart->bSplit      = false;
     2846  pOnePart->iLength     =  0;
     2847  pOnePart->iBestType   = -1;
     2848
     2849  if (pOnePart->PartLevel < m_uiMaxSplitLevel)
     2850  {
     2851    for (Int i=0; i<NUM_DOWN_PART; i++)
     2852    {
     2853      disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     2854    }
     2855  }
     2856}
     2857
     2858/** Run quadtree decision function
     2859 * \param  iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal
     2860 */
     2861Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda)
     2862{
     2863  SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
     2864
     2865  UInt uiDepth = pOnePart->PartLevel;
     2866  UInt uhNextDepth = uiDepth+1;
     2867
     2868  if (iPartIdx == 0)
     2869  {
     2870    dCostFinal = 0;
     2871  }
     2872
     2873  //SAO for this part
     2874  if(!pOnePart->bProcessed)
     2875  {
     2876    rdoSaoOnePart (psQTPart, iPartIdx, dLambda);
     2877  }
     2878
     2879  //SAO for sub 4 parts
     2880  if (pOnePart->PartLevel < iMaxLevel)
     2881  {
     2882    Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
     2883    Double      dCostSplit    = dLambda;
     2884
     2885    for (Int i=0; i< NUM_DOWN_PART ;i++)
     2886    {
     2887      if( m_bUseSBACRD ) 
     2888      {
     2889        if ( 0 == i) //initialize RD with previous depth buffer
     2890        {
     2891          m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     2892        }
     2893        else
     2894        {
     2895          m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     2896        }
     2897      } 
     2898      runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda);
     2899      dCostSplit += dCostFinal;
     2900      if( m_bUseSBACRD )
     2901      {
     2902        m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
     2903      }
     2904    }
     2905
     2906    if(dCostSplit < dCostNotSplit)
     2907    {
     2908      dCostFinal = dCostSplit;
     2909      pOnePart->bSplit      = true;
     2910      pOnePart->iLength     =  0;
     2911      pOnePart->iBestType   = -1;
     2912      if( m_bUseSBACRD )
     2913      {
     2914        m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
     2915      }
     2916    }
     2917    else
     2918    {
     2919      dCostFinal = dCostNotSplit;
     2920      pOnePart->bSplit = false;
     2921      for (Int i=0; i<NUM_DOWN_PART; i++)
     2922      {
     2923        disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
     2924      }
     2925      if( m_bUseSBACRD )
     2926      {
     2927        m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     2928      }
     2929    }
     2930  }
     2931  else
     2932  {
     2933    dCostFinal = pOnePart->dMinCost;
     2934  }
     2935}
     2936
     2937/** delete allocated memory of TEncSampleAdaptiveOffset class.
     2938 */
     2939Void TEncSampleAdaptiveOffset::destroyEncBuffer()
     2940{
     2941  for (Int i=0;i<m_iNumTotalParts;i++)
     2942  {
     2943    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
     2944    {
     2945      if (m_iCount [i][j])
     2946      {
     2947        delete [] m_iCount [i][j];
     2948      }
     2949      if (m_iOffset[i][j])
     2950      {
     2951        delete [] m_iOffset[i][j];
     2952      }
     2953      if (m_iOffsetOrg[i][j])
     2954      {
     2955        delete [] m_iOffsetOrg[i][j];
     2956      }
     2957    }
     2958    if (m_iRate[i])
     2959    {
     2960      delete [] m_iRate[i];
     2961    }
     2962    if (m_iDist[i])
     2963    {
     2964      delete [] m_iDist[i];
     2965    }
     2966    if (m_dCost[i])
     2967    {
     2968      delete [] m_dCost[i];
     2969    }
     2970    if (m_iCount [i])
     2971    {
     2972      delete [] m_iCount [i];
     2973    }
     2974    if (m_iOffset[i])
     2975    {
     2976      delete [] m_iOffset[i];
     2977    }
     2978    if (m_iOffsetOrg[i])
     2979    {
     2980      delete [] m_iOffsetOrg[i];
     2981    }
     2982
     2983  }
     2984  if (m_iDistOrg)
     2985  {
     2986    delete [] m_iDistOrg ; m_iDistOrg = NULL;
     2987  }
     2988  if (m_dCostPartBest)
     2989  {
     2990    delete [] m_dCostPartBest ; m_dCostPartBest = NULL;
     2991  }
     2992  if (m_iTypePartBest)
     2993  {
     2994    delete [] m_iTypePartBest ; m_iTypePartBest = NULL;
     2995  }
     2996  if (m_iRate)
     2997  {
     2998    delete [] m_iRate ; m_iRate = NULL;
     2999  }
     3000  if (m_iDist)
     3001  {
     3002    delete [] m_iDist ; m_iDist = NULL;
     3003  }
     3004  if (m_dCost)
     3005  {
     3006    delete [] m_dCost ; m_dCost = NULL;
     3007  }
     3008  if (m_iCount)
     3009  {
     3010    delete [] m_iCount  ; m_iCount = NULL;
     3011  }
     3012  if (m_iOffset)
     3013  {
     3014    delete [] m_iOffset ; m_iOffset = NULL;
     3015  }
     3016  if (m_iOffsetOrg)
     3017  {
     3018    delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL;
     3019  }
     3020
     3021  Int iMaxDepth = 4;
     3022  Int iDepth;
     3023  for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
     3024  {
     3025    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     3026    {
     3027      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
     3028      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
     3029    }
     3030  }
     3031
     3032  for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
     3033  {
     3034    delete [] m_pppcRDSbacCoder[iDepth];
     3035    delete [] m_pppcBinCoderCABAC[iDepth];
     3036  }
     3037
     3038  delete [] m_pppcRDSbacCoder;
     3039  delete [] m_pppcBinCoderCABAC;
     3040}
     3041
     3042/** create Encoder Buffer for SAO
     3043 * \param
     3044 */
     3045Void TEncSampleAdaptiveOffset::createEncBuffer()
     3046{
     3047  m_iDistOrg = new Int64 [m_iNumTotalParts];
     3048  m_dCostPartBest = new Double [m_iNumTotalParts];
     3049  m_iTypePartBest = new Int [m_iNumTotalParts];
     3050
     3051  m_iRate = new Int64* [m_iNumTotalParts];
     3052  m_iDist = new Int64* [m_iNumTotalParts];
     3053  m_dCost = new Double*[m_iNumTotalParts];
     3054
     3055  m_iCount  = new Int64 **[m_iNumTotalParts];
     3056  m_iOffset = new Int64 **[m_iNumTotalParts];
     3057  m_iOffsetOrg = new Int64 **[m_iNumTotalParts];
     3058
     3059  for (Int i=0;i<m_iNumTotalParts;i++)
     3060  {
     3061    m_iRate[i] = new Int64  [MAX_NUM_SAO_TYPE];
     3062    m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE];
     3063    m_dCost[i] = new Double [MAX_NUM_SAO_TYPE];
     3064
     3065    m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE];
     3066    m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE];
     3067    m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE];
     3068
     3069    for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
     3070    {
     3071      m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     3072      m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
     3073      m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
     3074    }
     3075  }
     3076
     3077  Int iMaxDepth = 4;
     3078  m_pppcRDSbacCoder = new TEncSbac** [iMaxDepth+1];
     3079#if FAST_BIT_EST
     3080  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [iMaxDepth+1];
     3081#else
     3082  m_pppcBinCoderCABAC = new TEncBinCABAC** [iMaxDepth+1];
     3083#endif
     3084
     3085  for ( Int iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
     3086  {
     3087    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
     3088#if FAST_BIT_EST
     3089    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
     3090#else
     3091    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
     3092#endif
     3093    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     3094    {
     3095      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
     3096#if FAST_BIT_EST
     3097      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
     3098#else
     3099      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
     3100#endif
     3101      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
     3102    }
     3103  }
     3104}
     3105
     3106/** Start SAO encoder
     3107 * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder
     3108 */
     3109Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder)
     3110{
     3111  if( pcRDGoOnSbacCoder )
     3112    m_bUseSBACRD = true;
     3113  else
     3114    m_bUseSBACRD = false;
     3115
     3116  m_pcPic = pcPic;
     3117  m_pcEntropyCoder = pcEntropyCoder;
     3118
     3119  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     3120  m_pcEntropyCoder->resetEntropy();
     3121  m_pcEntropyCoder->resetBits();
     3122
     3123  if( m_bUseSBACRD )
     3124  {
     3125    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
     3126    m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
     3127  }
     3128}
     3129
     3130/** End SAO encoder
     3131 */
     3132Void TEncSampleAdaptiveOffset::endSaoEnc()
     3133{
     3134  m_pcPic = NULL;
     3135  m_pcEntropyCoder = NULL;
     3136}
     3137
     3138inline int xSign(int x)
     3139{
     3140  return ((x >> 31) | ((int)( (((unsigned int) -x)) >> 31)));
     3141}
     3142
     3143/** Calculate SAO statistics for non-cross-slice or non-cross-tile processing
     3144 * \param  pRecStart to-be-filtered block buffer pointer
     3145 * \param  pOrgStart original block buffer pointer
     3146 * \param  stride picture buffer stride
     3147 * \param  ppStat statistics buffer
     3148 * \param  ppCount counter buffer
     3149 * \param  width block width
     3150 * \param  height block height
     3151 * \param  pbBorderAvail availabilities of block border pixels
     3152 */
     3153Void TEncSampleAdaptiveOffset::calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail)
     3154{
     3155  Int64 *stats, *count;
     3156  Int classIdx, posShift, startX, endX, startY, endY, signLeft,signRight,signDown,signDown1;
     3157  Pel *pOrg, *pRec;
     3158  UInt edgeType;
     3159  Int x, y;
     3160
     3161  //--------- Band offset-----------//
     3162  stats = ppStats[SAO_BO];
     3163  count = ppCount[SAO_BO];
     3164  pOrg   = pOrgStart;
     3165  pRec   = pRecStart;
     3166  for (y=0; y< height; y++)
     3167  {
     3168    for (x=0; x< width; x++)
     3169    {
     3170      classIdx = m_lumaTableBo[pRec[x]];
     3171      if (classIdx)
     3172      {
     3173        stats[classIdx] += (pOrg[x] - pRec[x]);
     3174        count[classIdx] ++;
     3175      }
     3176    }
     3177    pOrg += stride;
     3178    pRec += stride;
     3179  }
     3180  //---------- Edge offset 0--------------//
     3181  stats = ppStats[SAO_EO_0];
     3182  count = ppCount[SAO_EO_0];
     3183  pOrg   = pOrgStart;
     3184  pRec   = pRecStart;
     3185
     3186
     3187  startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
     3188  endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     3189  for (y=0; y< height; y++)
     3190  {
     3191    signLeft = xSign(pRec[startX] - pRec[startX-1]);
     3192    for (x=startX; x< endX; x++)
     3193    {
     3194      signRight =  xSign(pRec[x] - pRec[x+1]);
     3195      edgeType =  signRight + signLeft + 2;
     3196      signLeft  = -signRight;
     3197
     3198      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3199      count[m_auiEoTable[edgeType]] ++;
     3200    }
     3201    pRec  += stride;
     3202    pOrg += stride;
     3203  }
     3204
     3205  //---------- Edge offset 1--------------//
     3206  stats = ppStats[SAO_EO_1];
     3207  count = ppCount[SAO_EO_1];
     3208  pOrg   = pOrgStart;
     3209  pRec   = pRecStart;
     3210
     3211  startY = (pbBorderAvail[SGU_T]) ? 0 : 1;
     3212  endY   = (pbBorderAvail[SGU_B]) ? height : height-1;
     3213  if (!pbBorderAvail[SGU_T])
     3214  {
     3215    pRec  += stride;
     3216    pOrg  += stride;
     3217  }
     3218
     3219  for (x=0; x< width; x++)
     3220  {
     3221    m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
     3222  }
     3223  for (y=startY; y<endY; y++)
     3224  {
     3225    for (x=0; x< width; x++)
     3226    {
     3227      signDown     =  xSign(pRec[x] - pRec[x+stride]);
     3228      edgeType    =  signDown + m_iUpBuff1[x] + 2;
     3229      m_iUpBuff1[x] = -signDown;
     3230
     3231      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3232      count[m_auiEoTable[edgeType]] ++;
     3233    }
     3234    pOrg += stride;
     3235    pRec += stride;
     3236  }
     3237  //---------- Edge offset 2--------------//
     3238  stats = ppStats[SAO_EO_2];
     3239  count = ppCount[SAO_EO_2];
     3240  pOrg   = pOrgStart;
     3241  pRec   = pRecStart;
     3242
     3243  posShift= stride + 1;
     3244
     3245  startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ;
     3246  endX   = (pbBorderAvail[SGU_R]) ? width : (width-1);
     3247
     3248  //prepare 2nd line upper sign
     3249  pRec += stride;
     3250  for (x=startX; x< endX+1; x++)
     3251  {
     3252    m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
     3253  }
     3254
     3255  //1st line
     3256  pRec -= stride;
     3257  if(pbBorderAvail[SGU_TL])
     3258  {
     3259    x= 0;
     3260    edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
     3261    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3262    count[m_auiEoTable[edgeType]] ++;
     3263  }
     3264  if(pbBorderAvail[SGU_T])
     3265  {
     3266    for(x= 1; x< endX; x++)
     3267    {
     3268      edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
     3269      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3270      count[m_auiEoTable[edgeType]] ++;
     3271    }
     3272  }
     3273  pRec   += stride;
     3274  pOrg   += stride;
     3275
     3276  //middle lines
     3277  for (y= 1; y< height-1; y++)
     3278  {
     3279    for (x=startX; x<endX; x++)
     3280    {
     3281      signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
     3282      edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     3283      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3284      count[m_auiEoTable[edgeType]] ++;
     3285
     3286      m_iUpBufft[x+1] = -signDown1;
     3287    }
     3288    m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]);
     3289
     3290    ipSwap     = m_iUpBuff1;
     3291    m_iUpBuff1 = m_iUpBufft;
     3292    m_iUpBufft = ipSwap;
     3293
     3294    pRec  += stride;
     3295    pOrg  += stride;
     3296  }
     3297
     3298  //last line
     3299  if(pbBorderAvail[SGU_B])
     3300  {
     3301    for(x= startX; x< width-1; x++)
     3302    {
     3303      edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3304      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3305      count[m_auiEoTable[edgeType]] ++;
     3306    }
     3307  }
     3308  if(pbBorderAvail[SGU_BR])
     3309  {
     3310    x= width -1;
     3311    edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3312    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3313    count[m_auiEoTable[edgeType]] ++;
     3314  }
     3315
     3316  //---------- Edge offset 3--------------//
     3317
     3318  stats = ppStats[SAO_EO_3];
     3319  count = ppCount[SAO_EO_3];
     3320  pOrg   = pOrgStart;
     3321  pRec   = pRecStart;
     3322
     3323  posShift     = stride - 1;
     3324  startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
     3325  endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     3326
     3327  //prepare 2nd line upper sign
     3328  pRec += stride;
     3329  for (x=startX-1; x< endX; x++)
     3330  {
     3331    m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
     3332  }
     3333
     3334
     3335  //first line
     3336  pRec -= stride;
     3337  if(pbBorderAvail[SGU_T])
     3338  {
     3339    for(x= startX; x< width -1; x++)
     3340    {
     3341      edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
     3342      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3343      count[m_auiEoTable[edgeType]] ++;
     3344    }
     3345  }
     3346  if(pbBorderAvail[SGU_TR])
     3347  {
     3348    x= width-1;
     3349    edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
     3350    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3351    count[m_auiEoTable[edgeType]] ++;
     3352  }
     3353  pRec  += stride;
     3354  pOrg  += stride;
     3355
     3356  //middle lines
     3357  for (y= 1; y< height-1; y++)
     3358  {
     3359    for(x= startX; x< endX; x++)
     3360    {
     3361      signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
     3362      edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
     3363
     3364      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3365      count[m_auiEoTable[edgeType]] ++;
     3366      m_iUpBuff1[x-1] = -signDown1;
     3367
     3368    }
     3369    m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
     3370
     3371    pRec  += stride;
     3372    pOrg  += stride;
     3373  }
     3374
     3375  //last line
     3376  if(pbBorderAvail[SGU_BL])
     3377  {
     3378    x= 0;
     3379    edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3380    stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3381    count[m_auiEoTable[edgeType]] ++;
     3382
     3383  }
     3384  if(pbBorderAvail[SGU_B])
     3385  {
     3386    for(x= 1; x< endX; x++)
     3387    {
     3388      edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
     3389      stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
     3390      count[m_auiEoTable[edgeType]] ++;
     3391    }
     3392  }
     3393}
     3394
     3395/** Calculate SAO statistics for current LCU
     3396 * \param  iAddr,  iPartIdx,  iYCbCr
     3397 */
     3398Void TEncSampleAdaptiveOffset::calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr)
     3399{
     3400  if(!m_bUseNIF)
     3401  {
     3402    calcSaoStatsCuOrg( iAddr, iPartIdx, iYCbCr);
     3403  }
     3404  else
     3405  {
     3406    Int64** ppStats = m_iOffsetOrg[iPartIdx];
     3407    Int64** ppCount = m_iCount    [iPartIdx];
     3408
     3409    //parameters
     3410    Int  isChroma = (iYCbCr != 0)? 1:0;
     3411    Int  stride   = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride());
     3412    Pel* pPicOrg = getPicYuvAddr (m_pcPic->getPicYuvOrg(), iYCbCr);
     3413    Pel* pPicRec  = getPicYuvAddr(m_pcYuvTmp, iYCbCr);
     3414
     3415    std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks());
     3416
     3417    //variables
     3418    UInt  xPos, yPos, width, height;
     3419    Bool* pbBorderAvail;
     3420    UInt  posOffset;
     3421
     3422    for(Int i=0; i< vFilterBlocks.size(); i++)
     3423    {
     3424      xPos        = vFilterBlocks[i].posX   >> isChroma;
     3425      yPos        = vFilterBlocks[i].posY   >> isChroma;
     3426      width       = vFilterBlocks[i].width  >> isChroma;
     3427      height      = vFilterBlocks[i].height >> isChroma;
     3428      pbBorderAvail = vFilterBlocks[i].isBorderAvailable;
     3429
     3430      posOffset = (yPos* stride) + xPos;
     3431
     3432#if HHI_INTERVIEW_SKIP
     3433      if( !m_pcPic->getCU(iAddr)->getRenderable(0 ))
     3434      {
     3435      calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
     3436      }
     3437#else
     3438      calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail);
     3439#endif
     3440    }
     3441  }
     3442
     3443}
     3444
     3445/** Calculate SAO statistics for current LCU without non-crossing slice
     3446 * \param  iAddr,  iPartIdx,  iYCbCr
     3447 */
     3448Void TEncSampleAdaptiveOffset::calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr)
     3449{
     3450  Int x,y;
     3451  TComDataCU *pTmpCu = m_pcPic->getCU(iAddr);
     3452  TComSPS *pTmpSPS =  m_pcPic->getSlice(0)->getSPS();
     3453
     3454  Pel* pOrg;
     3455  Pel* pRec;
     3456  Int iStride;
     3457  Int iLcuWidth  = pTmpSPS->getMaxCUHeight();
     3458  Int iLcuHeight = pTmpSPS->getMaxCUWidth();
     3459  UInt uiLPelX   = pTmpCu->getCUPelX();
     3460  UInt uiTPelY   = pTmpCu->getCUPelY();
     3461  UInt uiRPelX;
     3462  UInt uiBPelY;
     3463  Int64* iStats;
     3464  Int64* iCount;
     3465  Int iClassIdx;
     3466  Int iPicWidthTmp;
     3467  Int iPicHeightTmp;
     3468  Int iStartX;
     3469  Int iStartY;
     3470  Int iEndX;
     3471  Int iEndY;
     3472
     3473  Int iIsChroma = (iYCbCr!=0)? 1:0;
     3474  Int numSkipLine = iIsChroma? 2:4;
    9763475  if (m_saoInterleavingFlag == 0)
    9773476  {
     
    19744473
    19754474}
     4475#endif
    19764476
    19774477
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h

    r296 r443  
    7171  Int64  ***m_iOffset;     //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    7272  Int64  ***m_iOffsetOrg;  //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
     73#if LGE_SAO_MIGRATION_D0091
     74  Int64  ****m_count_PreDblk;      //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
     75  Int64  ****m_offsetOrg_PreDblk;  //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
     76#endif
    7377  Int64  **m_iRate;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    7478  Int64  **m_iDist;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
     
    7983  Int     m_iOffsetTh;
    8084  Bool    m_bUseSBACRD;
     85#if SAO_ENCODING_CHOICE
     86#if SAO_ENCODING_CHOICE_CHROMA
     87  Double  m_depthSaoRate[2][4];
     88#else
     89  Double  m_depth0SaoRate;
     90#endif
     91#endif
    8192
    8293public:
     
    8899  Void resetStats();
    89100#if SAO_CHROMA_LAMBDA
     101#if SAO_ENCODING_CHOICE
     102  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
     103#else
    90104  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
     105#endif
    91106#else
    92107  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda);
    93108#endif
     109
     110#if LGE_SAO_MIGRATION_D0091
     111  Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr);
     112  Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr);
     113#else
    94114  Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda);
    95115  Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda);
     116#endif
     117 
    96118  Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx);
    97119  Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr);
     
    99121  Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail);
    100122  Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);
     123#if LGE_SAO_MIGRATION_D0091
     124  Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic );
     125#endif
    101126  Void destroyEncBuffer();
    102127  Void createEncBuffer();
    103128  Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr);
    104129  Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir);
     130#if SAO_ENCODING_CHOICE
     131  Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth);
     132#else
    105133  Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma);
     134#endif
     135#if LGE_SAO_MIGRATION_D0091
     136  Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion);
     137  Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion);
     138  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift);
     139  inline Int64 estIterOffset(Int typeIdx, Int classIdx, double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo );
     140  inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo);
     141#else
    106142  Void rdoSaoUnit(SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda);
     143#endif
    107144  Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; }
    108145  Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r332 r443  
    4242#include <algorithm>
    4343
    44 #if RWTH_SDC_DLT_B0036
    45 #define GetNumDepthValues()     (pcCU->getSlice()->getSPS()->getNumDepthValues())
    46 #define GetBitsPerDepthValue()  (pcCU->getSlice()->getSPS()->getBitsPerDepthValue())
    47 #endif
    48 
    4944//! \ingroup TLibEncoder
    5045//! \{
     
    7267#if H3D_IVRP
    7368, m_cResPredFlagSCModel       ( 1,             1,               NUM_RES_PRED_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
     69#endif
     70#if QC_ARP_D0177
     71, m_cCUPUARPW                 ( 1,             1,               NUM_ARPW_CTX                 , m_contextModels + m_numContextModels, m_numContextModels)
    7472#endif
    7573, m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
     
    9694, m_cALFSvlcSCModel           ( 1,             1,               NUM_ALF_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    9795, m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
     96#if LGE_SAO_MIGRATION_D0091
     97, m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX        , m_contextModels + m_numContextModels, m_numContextModels)
     98, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     99#else
    98100, m_cSaoFlagSCModel           ( 1,             1,               NUM_SAO_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    99101, m_cSaoUvlcSCModel           ( 1,             1,               NUM_SAO_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     
    102104, m_cSaoMergeUpSCModel        ( 1,             1,               NUM_SAO_MERGE_UP_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
    103105, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     106#endif
    104107#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     108#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    105109, m_cDmmFlagSCModel           ( 1,             1,               NUM_DMM_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    106110, m_cDmmModeSCModel           ( 1,             1,               NUM_DMM_MODE_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
     111#endif
    107112, m_cDmmDataSCModel           ( 1,             1,               NUM_DMM_DATA_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    108113#endif
     
    114119#endif
    115120#if RWTH_SDC_DLT_B0036
     121#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    116122, m_cSDCFlagSCModel             ( 1,             1,                 SDC_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     123#else
     124, m_cDepthModeModel             ( 1,             1,                 DEPTH_MODE_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     125, m_cDmmDeltaFlagModel             ( 1,             1,                 DMM_DELTA_NUM_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
     126#endif
     127#if RWTH_SDC_CTX_SIMPL_D0032
     128, m_cSDCResidualFlagSCModel     ( 1,             1,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
     129, m_cSDCResidualSCModel         ( 1,             1,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
     130, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     131#else
    117132, m_cSDCResidualFlagSCModel     ( 1,             2,  SDC_NUM_RESIDUAL_FLAG_CTX  , m_contextModels + m_numContextModels, m_numContextModels)
    118133, m_cSDCResidualSignFlagSCModel ( 1,             2,  SDC_NUM_SIGN_FLAG_CTX      , m_contextModels + m_numContextModels, m_numContextModels)
    119134, m_cSDCResidualSCModel         ( 1,             2,  SDC_NUM_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
    120135, m_cSDCPredModeSCModel             ( 1,             3,                 SDC_NUM_PRED_MODE_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
     136#endif
    121137#endif
    122138{
     
    157173#if H3D_IVRP
    158174  m_cResPredFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG );
     175#endif
     176#if QC_ARP_D0177
     177  m_cCUPUARPW.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_ARPW );
    159178#endif
    160179  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
     
    180199  m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
    181200  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     201#if LGE_SAO_MIGRATION_D0091
     202  m_cSaoMergeSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
     203  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     204#else
    182205  m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
    183206  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
     
    186209  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    187210  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     211#endif
    188212#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     213#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    189214  m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
    190215  m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
     216#endif
    191217  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    192218#endif
     
    198224#endif
    199225#if RWTH_SDC_DLT_B0036
     226#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    200227  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
     228#else
     229  m_cDepthModeModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DEPTHMODE_FLAG );
     230  m_cDmmDeltaFlagModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMMDELTA_FLAG );
     231#endif
    201232  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    202233  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     234#if !RWTH_SDC_CTX_SIMPL_D0032
    203235  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     236#endif
    204237  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    205238#endif
     
    266299      curCost += m_cALFSvlcSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_ALF_SVLC );
    267300      curCost += m_cCUTransSubdivFlagSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     301#if LGE_SAO_MIGRATION_D0091
     302      curCost += m_cSaoMergeSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
     303      curCost += m_cSaoTypeIdxSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     304#else
    268305      curCost += m_cSaoFlagSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_SAO_FLAG );
    269306      curCost += m_cSaoUvlcSCModel.calcCost           ( curSliceType, qp, (UChar*)INIT_SAO_UVLC );
     
    272309      curCost += m_cSaoMergeUpSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    273310      curCost += m_cSaoTypeIdxSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
     311#endif
    274312
    275313      if (curCost < bestCost)
     
    310348#if H3D_IVRP
    311349  m_cResPredFlagSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_RES_PRED_FLAG );
     350#endif
     351#if QC_ARP_D0177
     352  m_cCUPUARPW.initBuffer                 ( eSliceType, iQp, (UChar*)INIT_ARPW );
    312353#endif
    313354  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
     
    333374  m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
    334375  m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
     376#if LGE_SAO_MIGRATION_D0091
     377  m_cSaoMergeSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
     378  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     379#else
    335380  m_cSaoFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_FLAG );
    336381  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
     
    339384  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
    340385  m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
     386#endif
    341387#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     388#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    342389  m_cDmmFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_FLAG );
    343390  m_cDmmModeSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_MODE );
     391#endif
    344392  m_cDmmDataSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMM_DATA );
    345393#endif
    346394#if RWTH_SDC_DLT_B0036
     395#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    347396  m_cSDCFlagSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_FLAG );
     397#else
     398  m_cDepthModeModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_DEPTHMODE_FLAG );
     399  m_cDmmDeltaFlagModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_DMMDELTA_FLAG );
     400#endif
    348401  m_cSDCResidualFlagSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL_FLAG );
    349402  m_cSDCResidualSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_SDC_RESIDUAL );
     403#if !RWTH_SDC_CTX_SIMPL_D0032
    350404  m_cSDCResidualSignFlagSCModel.initBuffer  ( eSliceType, iQp, (UChar*)INIT_SDC_SIGN_FLAG );
     405#endif
    351406  m_cSDCPredModeSCModel.initBuffer              ( eSliceType, iQp, (UChar*)INIT_SDC_PRED_MODE );
    352407#endif
     
    542597}
    543598
    544 
     599#if PKU_QC_DEPTH_INTRA_UNI_D0195
     600Void TEncSbac::loadDepthMode( TEncSbac* pSrc)
     601{
     602  m_pcBinIf->copyState( pSrc->m_pcBinIf );
     603
     604  this->m_cDepthModeModel      .copyFrom( &pSrc->m_cDepthModeModel       );
     605  this->m_cDmmDeltaFlagModel   .copyFrom( &pSrc->m_cDmmDeltaFlagModel       );
     606}
     607#endif
    545608Void  TEncSbac::store( TEncSbac* pDest)
    546609{
     
    840903}
    841904#endif
    842 
     905#if QC_ARP_D0177
     906Void TEncSbac::codeARPW( TComDataCU* pcCU, UInt uiAbsPartIdx )
     907{
     908  Int nW = pcCU->getARPW( uiAbsPartIdx );
     909  Int nMaxW = pcCU->getSlice()->getARPStepNum() - 1;
     910  assert( 0 <= nW && nW <= nMaxW );
     911  assert(nMaxW > 0);
     912  if( nMaxW > 0 )
     913  {
     914    Int nOffset = pcCU->getCTXARPWFlag(uiAbsPartIdx);
     915    assert( 0 <= nOffset && nOffset <= 2 );
     916    Int nBinNum = nW + ( nW != nMaxW );
     917    m_pcBinIf->encodeBin( nW != 0 , m_cCUPUARPW.get( 0, 0, 0 + nOffset ) );
     918    if( nBinNum > 1 )
     919       m_pcBinIf->encodeBin( nW == nMaxW , m_cCUPUARPW.get( 0, 0, 3 ) );
     920  }
     921}
     922#endif
    843923Void TEncSbac::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    844924{
     
    9661046}
    9671047#endif
    968 
    969 Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1048#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1049Void TEncSbac::codeDepthIntraMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1050{
     1051  UInt uiCodeWordTable[3][9] =    {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}};
     1052  UInt uiCodeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3,  4,  5,  5},{1, 2, 0, 0, 0, 0, 2, 0, 0}};
     1053  UInt uiDir = pcCU->getLumaIntraDir(uiAbsPartIdx);
     1054  Bool bSdcFlag = pcCU->getSDCFlag(uiAbsPartIdx);
     1055  UInt uiPuIdx = ( pcCU->getWidth(uiAbsPartIdx) == 64 )? 2 : ( ( pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_NxN && pcCU->getWidth(uiAbsPartIdx) == 8 ) ? 0 : 1 );
     1056  UInt uiCodeIdx = 0;
     1057  if ( bSdcFlag )
     1058  {
     1059    switch(uiDir)
     1060    {
     1061      case PLANAR_IDX: uiCodeIdx = 0; break;
     1062      case DC_IDX:     uiCodeIdx = 6; break;
     1063      default:         uiCodeIdx = 2;
     1064    }
     1065  }
     1066  else if ( uiDir>=EDGE_INTRA_IDX )
     1067  {
     1068    uiCodeIdx = 8;
     1069  }
     1070  else if ( uiDir<NUM_INTRA_MODE ) 
     1071  {
     1072    uiCodeIdx = 1;
     1073  }
     1074  else
     1075  {
     1076    if (uiDir== DMM_WEDGE_FULL_IDX     || uiDir==DMM_WEDGE_FULL_D_IDX     )     {uiCodeIdx = 3;}
     1077    if (uiDir== DMM_CONTOUR_PREDTEX_IDX|| uiDir==DMM_CONTOUR_PREDTEX_D_IDX)     {uiCodeIdx = 4;}
     1078    if (uiDir== DMM_WEDGE_PREDTEX_IDX  || uiDir==DMM_WEDGE_PREDTEX_D_IDX  )     {uiCodeIdx = 5;}
     1079    if (uiDir== DMM_WEDGE_PREDDIR_IDX  || uiDir==DMM_WEDGE_PREDDIR_D_IDX  )     {uiCodeIdx = 7;}
     1080  }
     1081  //mode coding
     1082  for (UInt i=0; i<uiCodeWordLenTable[uiPuIdx][uiCodeIdx]; i++)
     1083  {
     1084    UInt uiBit = uiCodeWordTable[uiPuIdx][uiCodeIdx] & ( 1<<(uiCodeWordLenTable[uiPuIdx][uiCodeIdx]-i-1) );
     1085    UInt uiCtxDepthMode = uiPuIdx*3 + ( i >= 2? 2 : i );
     1086    m_pcBinIf->encodeBin( uiBit!=0 , m_cDepthModeModel.get(0, 0, uiCtxDepthMode) );
     1087  }
     1088}
     1089Void TEncSbac::codeDepthModelingTable( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bSdcRD)
     1090{
     1091  UInt uiDir = pcCU->getLumaIntraDir( uiAbsPartIdx );
     1092  Bool bSdcFlag =  pcCU->getSDCFlag(uiAbsPartIdx);
     1093  Bool bDmmFlag = (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX &&(!bSdcFlag))? 1:0;
     1094
     1095  codeDepthIntraMode(pcCU,uiAbsPartIdx);
     1096 
     1097  if (uiDir >= NUM_INTRA_MODE && uiDir < EDGE_INTRA_IDX )//DMM modes or SDC DMM1
     1098  {
     1099    assert(pcCU->getWidth(uiAbsPartIdx)<64);
     1100    assert(pcCU->getWidth(uiAbsPartIdx)<64);
     1101    if( uiDir == DMM_WEDGE_FULL_IDX || uiDir == DMM_WEDGE_FULL_D_IDX)             { xCodeWedgeFullInfo     ( pcCU, uiAbsPartIdx ); }
     1102    else if( uiDir == DMM_WEDGE_PREDTEX_IDX || uiDir == DMM_WEDGE_PREDTEX_D_IDX ) { xCodeWedgePredTexInfo  ( pcCU, uiAbsPartIdx ); }
     1103    else if( uiDir == DMM_WEDGE_PREDDIR_IDX || uiDir == DMM_WEDGE_PREDDIR_D_IDX)  { xCodeWedgePredDirInfo  ( pcCU, uiAbsPartIdx ); }
     1104  }
     1105  else if(uiDir >= EDGE_INTRA_IDX)//CCM mode
     1106  {
     1107    assert(pcCU->getWidth(uiAbsPartIdx)<64);
     1108    xCodeEdgeIntraInfo( pcCU, uiAbsPartIdx );
     1109  }
     1110
     1111  if (bDmmFlag)
     1112  {
     1113    m_pcBinIf->encodeBin( (uiDir&1) , m_cDmmDeltaFlagModel.get(0, 0, 0) );
     1114    if (uiDir&1)
     1115    {
     1116      Int iDeltaDC1 = 0,iDeltaDC2 = 0;
     1117      if ( uiDir == DMM_WEDGE_FULL_D_IDX )
     1118      {
     1119        iDeltaDC1 = pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx );
     1120        iDeltaDC2 = pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx );
     1121      }
     1122      else if ( uiDir == DMM_WEDGE_PREDTEX_D_IDX )
     1123      {
     1124        iDeltaDC1 = pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx );
     1125        iDeltaDC2 = pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx );
     1126      }
     1127      else if ( uiDir == DMM_WEDGE_PREDDIR_D_IDX )
     1128      {
     1129        iDeltaDC1 = pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx );
     1130        iDeltaDC2 = pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx );
     1131      }
     1132      else if ( uiDir == DMM_CONTOUR_PREDTEX_D_IDX )
     1133      {
     1134        iDeltaDC1 = pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx );
     1135        iDeltaDC2 = pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx );
     1136
     1137      }
     1138
     1139      for ( Int i = 0; i < 2; i++ )
     1140      {
     1141        Int iDeltaDC = (i==0)? iDeltaDC1 : iDeltaDC2;
     1142        xWriteExGolombLevel( UInt( abs( iDeltaDC ) ), m_cDmmDataSCModel.get(0, 0, 1) );
     1143        if ( iDeltaDC != 0 )
     1144        {
     1145          UInt uiSign = iDeltaDC > 0 ? 0 : 1;
     1146          m_pcBinIf->encodeBinEP( uiSign );
     1147        }
     1148      }
     1149    }
     1150  }
     1151  else if (uiDir>=EDGE_INTRA_IDX)
     1152  {
     1153    m_pcBinIf->encodeBin( (uiDir == EDGE_INTRA_DELTA_IDX), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 0) );
     1154    if( uiDir == EDGE_INTRA_DELTA_IDX )
     1155    {
     1156      Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
     1157      Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
     1158
     1159      for ( Int i = 0; i < 2; i++ )
     1160      {
     1161        Int iDeltaDC = (i==0)? iDeltaDC0 : iDeltaDC1;
     1162        xWriteExGolombLevel( UInt( abs( iDeltaDC ) ), m_cEdgeIntraDeltaDCSCModel.get(0, 0, 1) );
     1163        if ( iDeltaDC != 0 )
     1164        {
     1165          UInt uiSign = iDeltaDC > 0 ? 0 : 1;
     1166          m_pcBinIf->encodeBinEP( uiSign );
     1167        }
     1168      }
     1169    }
     1170  }
     1171  if (pcCU->getSDCFlag(uiAbsPartIdx))//SDC mode
     1172  {
     1173    assert(pcCU->getPartitionSize(uiAbsPartIdx)==SIZE_2Nx2N);
     1174    UInt uiNumSegments = ( uiDir == DC_IDX || uiDir == PLANAR_IDX )? 1 : 2;
     1175    if(!bSdcRD)
     1176    {
     1177      for (int uiSeg=0; uiSeg<uiNumSegments; uiSeg++)
     1178      {
     1179        codeSDCResidualData(pcCU, uiAbsPartIdx, uiSeg);
     1180      }
     1181    }
     1182  }
     1183}
     1184#endif
     1185Void TEncSbac::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx
     1186#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1187                                   , Bool bSdcRD
     1188#endif
     1189                                   )
    9701190{
    9711191  UInt uiDir         = pcCU->getLumaIntraDir( uiAbsPartIdx );
    9721192
     1193#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    9731194#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    9741195  if( pcCU->getSlice()->getSPS()->getUseDMM() && pcCU->getWidth( uiAbsPartIdx ) <= DMM_WEDGEMODEL_MAX_SIZE )
     
    10701291  }
    10711292#endif
    1072  
     1293#else
     1294  if (pcCU->getSlice()->getSPS()->isDepth())
     1295  {
     1296    codeDepthModelingTable(pcCU, uiAbsPartIdx, bSdcRD);
     1297  }
     1298  if (pcCU->getLumaIntraDir(uiAbsPartIdx)<NUM_INTRA_MODE && !pcCU->getSDCFlag(uiAbsPartIdx))
     1299  {
     1300#endif
    10731301  Int uiPreds[3] = {-1, -1, -1};
    10741302  Int uiPredNum = pcCU->getIntraDirLumaPredictor(uiAbsPartIdx, uiPreds); 
     
    11161344
    11171345    m_pcBinIf->encodeBinsEP( uiDir, 5 );
     1346#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    11181347#if LGE_EDGE_INTRA_A0070
    11191348  if (bCodeEdgeIntra)
    11201349    if (uiDir == 31) m_pcBinIf->encodeBinsEP(0,1);
    11211350#endif
     1351#endif
    11221352   }
     1353#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1354   }
     1355#else
    11231356#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    11241357  }
    11251358#endif
     1359#endif
     1360
    11261361  return;
    11271362}
     
    18872122  }
    18882123}
    1889 
     2124#if LGE_SAO_MIGRATION_D0091
     2125Void TEncSbac::codeSAOSign( UInt code )
     2126{
     2127  m_pcBinIf->encodeBinEP( code );
     2128}
     2129
     2130Void TEncSbac::codeSaoMaxUvlc    ( UInt code, UInt maxSymbol )
     2131{
     2132  if (maxSymbol == 0)
     2133  {
     2134    return;
     2135  }
     2136
     2137  Int i;
     2138  Bool bCodeLast = ( maxSymbol > code );
     2139
     2140  if ( code == 0 )
     2141  {
     2142    m_pcBinIf->encodeBinEP( 0 );
     2143  }
     2144  else
     2145  {
     2146    m_pcBinIf->encodeBinEP( 1 );
     2147    for ( i=0; i<code-1; i++ )
     2148    {
     2149      m_pcBinIf->encodeBinEP( 1 );
     2150    }
     2151    if( bCodeLast )
     2152    {
     2153      m_pcBinIf->encodeBinEP( 0 );
     2154    }
     2155  }
     2156}
     2157
     2158/** Code SAO EO class or BO band position
     2159 * \param uiLength
     2160 * \param uiCode
     2161 */
     2162Void TEncSbac::codeSaoUflc       ( UInt uiLength, UInt uiCode )
     2163{
     2164   m_pcBinIf->encodeBinsEP ( uiCode, uiLength );
     2165}
     2166/** Code SAO merge flags
     2167 * \param uiCode
     2168 * \param uiCompIdx
     2169 */
     2170Void TEncSbac::codeSaoMerge       ( UInt uiCode )
     2171{
     2172  if (uiCode == 0)
     2173  {
     2174    m_pcBinIf->encodeBin(0,  m_cSaoMergeSCModel.get( 0, 0, 0 ));
     2175  }
     2176  else
     2177  {
     2178    m_pcBinIf->encodeBin(1,  m_cSaoMergeSCModel.get( 0, 0, 0 ));
     2179  }
     2180}
     2181/** Code SAO type index
     2182 * \param uiCode
     2183 */
     2184Void TEncSbac::codeSaoTypeIdx       ( UInt uiCode)
     2185{
     2186  if (uiCode == 0)
     2187  {
     2188    m_pcBinIf->encodeBin( 0, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     2189  }
     2190  else
     2191  {
     2192    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     2193    m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); //determine edge or band
     2194  }
     2195}
     2196#else
    18902197Void TEncSbac::codeSaoFlag       ( UInt uiCode )
    18912198{
     
    20032310  }
    20042311}
     2312#endif
    20052313/*!
    20062314 ****************************************************************************
     
    23972705
    23982706#if RWTH_SDC_DLT_B0036
     2707#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    23992708Void TEncSbac::codeSDCPredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
    24002709{
     
    24112720  {
    24122721    UInt uiBit = (uiPredMode == g_auiSDCPredModes[uiMPModeIdx]) ? 1 : 0;
     2722#if INTEL_SDC64_D0193
     2723    if( !(pcCU->getWidth(uiAbsPartIdx) == 64 && i == 1))
     2724#endif
    24132725    m_pcBinIf->encodeBin( uiBit, m_cSDCPredModeSCModel.get( 0, i, uiCtx ) );
    24142726   
     
    24372749 
    24382750}
     2751#endif
    24392752
    24402753Void TEncSbac::codeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment )
     
    24502763  UInt uiSign     = segmentDCOffset < 0 ? 1 : 0;
    24512764  UInt uiAbsIdx   = abs(segmentDCOffset);
     2765#if !LGE_CONCATENATE_D0141
    24522766  UInt uiBit = 0;
    2453  
    2454   UInt uiMaxResidualBits  = GetBitsPerDepthValue();
     2767#endif
     2768 
     2769  UInt uiMaxResidualBits  = pcCU->getSlice()->getSPS()->getBitsPerDepthValue();
    24552770  assert( uiMaxResidualBits <= g_uiBitDepth );
    24562771 
    24572772  // residual flag
     2773#if RWTH_SDC_CTX_SIMPL_D0032
     2774  m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
     2775#else
    24582776  m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection
     2777#endif
    24592778 
    24602779  if (uiResidual)
    24612780  {
    24622781    // encode sign bit of residual
     2782#if RWTH_SDC_CTX_SIMPL_D0032
     2783    m_pcBinIf->encodeBinEP( uiSign );
     2784#else
    24632785    m_pcBinIf->encodeBin( uiSign, m_cSDCResidualSignFlagSCModel.get( 0, uiSegment, 0 ) ); //TODO depthmap: more sophisticated context selection
     2786#endif
    24642787       
    2465     assert(uiAbsIdx < GetNumDepthValues());
     2788    UInt uiNumDepthValues = pcCU->getSlice()->getSPS()->getNumDepthValues();
     2789    assert(uiAbsIdx < uiNumDepthValues);
    24662790   
    24672791    // encode residual magnitude
    24682792    uiAbsIdx -= 1;
     2793#if LGE_CONCATENATE_D0141
     2794    //prefix part
     2795    if ( uiAbsIdx == 0 )
     2796        m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
     2797    else
     2798    {
     2799        UInt l = uiAbsIdx;
     2800        UInt k = 0;
     2801        UInt uiPrefixThreshold = ((uiNumDepthValues * 3) >> 2);
     2802        while ( l > 0 && k < uiPrefixThreshold )
     2803        {
     2804            m_pcBinIf->encodeBin( 1, m_cSDCResidualSCModel.get(0, 0, 0) );
     2805            l--;
     2806            k++;
     2807        }
     2808        if ( uiAbsIdx < uiPrefixThreshold )
     2809            m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
     2810        //suffix part
     2811        else
     2812        {
     2813            uiAbsIdx -= uiPrefixThreshold;
     2814            UInt uiSuffixLength = ( (UInt)ceil( Log2(uiNumDepthValues - uiPrefixThreshold) ) );
     2815            UInt uiBitInfo = 0;
     2816            for ( Int i = 0; i < uiSuffixLength; i++)
     2817            {
     2818                uiBitInfo = ( uiAbsIdx & ( 1 << i ) ) >> i;
     2819                m_pcBinIf->encodeBinEP( uiBitInfo);
     2820            }
     2821        }
     2822    }
     2823#else
    24692824    for (Int i=0; i<uiMaxResidualBits; i++)
    24702825    {
    24712826      uiBit = (uiAbsIdx & (1<<i))>>i;
    24722827     
     2828#if RWTH_SDC_CTX_SIMPL_D0032
     2829      m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, 0, i ) );
     2830#else
    24732831      m_pcBinIf->encodeBin( uiBit, m_cSDCResidualSCModel.get( 0, uiSegment, i ) ); //TODO depthmap: more sophisticated context selection
    2474     }
     2832#endif
     2833    }
     2834#endif
    24752835   
    24762836  }
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r332 r443  
    9292  Void  load                   ( TEncSbac* pScr  );
    9393  Void  loadIntraDirModeLuma   ( TEncSbac* pScr  );
     94#if PKU_QC_DEPTH_INTRA_UNI_D0195
     95  Void  loadDepthMode          ( TEncSbac* pSrc  );
     96#endif
    9497  Void  store                  ( TEncSbac* pDest );
    9598  Void  loadContexts           ( TEncSbac* pScr  );
     
    126129  Void codeAlfCtrlFlag       ( UInt uiSymbol );
    127130  Void  codeApsExtensionFlag () { assert (0); return; };
     131#if LGE_SAO_MIGRATION_D0091
     132  Void  codeSaoMaxUvlc    ( UInt code, UInt maxSymbol );
     133  Void  codeSaoMerge      ( UInt  uiCode );
     134  Void  codeSaoTypeIdx    ( UInt  uiCode);
     135  Void  codeSaoUflc       ( UInt uiLength, UInt  uiCode );
     136  Void  codeSAOSign       ( UInt  uiCode);  //<! code SAO offset sign
     137#else
    128138  Void  codeSaoFlag       ( UInt uiCode );
    129139  Void  codeSaoUvlc       ( UInt uiCode );
     
    134144  Void  codeSaoTypeIdx    ( UInt  uiCode);
    135145  Void  codeSaoUflc       ( UInt  uiCode);
     146#endif
    136147  Void  codeScalingList      ( TComScalingList* scalingList     ){ assert (0);  return;};
    137148 
    138149#if RWTH_SDC_DLT_B0036
     150#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    139151  Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     152#endif
    140153  Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
     154#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    141155  Void codeSDCPredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     156#endif
    142157#endif
    143158
     
    209224  Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    210225#endif
     226#if QC_ARP_D0177
     227  virtual Void codeARPW ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     228#endif
    211229  Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
    212230#if H3D_IVMP
     
    222240  Void codeQtCbf               ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth );
    223241  Void codeQtRootCbf           ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    224  
    225   Void codeIntraDirLumaAng     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     242#if PKU_QC_DEPTH_INTRA_UNI_D0195
     243  Void codeDepthIntraMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     244  Void codeDepthModelingTable  ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bSdcRD = false );
     245#endif
     246  Void codeIntraDirLumaAng     ( TComDataCU* pcCU, UInt uiAbsPartIdx
     247#if PKU_QC_DEPTH_INTRA_UNI_D0195
     248    , Bool bSdcRD = false
     249#endif
     250    );
    226251 
    227252  Void codeIntraDirChroma      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    265290#if H3D_IVRP
    266291  ContextModel3DBuffer m_cResPredFlagSCModel;
     292#endif
     293#if QC_ARP_D0177
     294  ContextModel3DBuffer m_cCUPUARPW;
    267295#endif
    268296  ContextModel3DBuffer m_cCUPartSizeSCModel;
     
    292320  ContextModel3DBuffer m_cALFSvlcSCModel;
    293321  ContextModel3DBuffer m_cCUAMPSCModel;
     322#if LGE_SAO_MIGRATION_D0091
     323  ContextModel3DBuffer m_cSaoMergeSCModel;
     324  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
     325#else
    294326  ContextModel3DBuffer m_cSaoFlagSCModel;
    295327  ContextModel3DBuffer m_cSaoUvlcSCModel;
     
    298330  ContextModel3DBuffer m_cSaoMergeUpSCModel;
    299331  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
     332#endif
    300333
    301334#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
     335#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    302336  ContextModel3DBuffer m_cDmmFlagSCModel;
    303337  ContextModel3DBuffer m_cDmmModeSCModel;
     338#endif
    304339  ContextModel3DBuffer m_cDmmDataSCModel;
    305340#endif
     
    312347 
    313348#if RWTH_SDC_DLT_B0036
     349#if !PKU_QC_DEPTH_INTRA_UNI_D0195
    314350  ContextModel3DBuffer m_cSDCFlagSCModel;
     351#else
     352  ContextModel3DBuffer m_cDepthModeModel;
     353  ContextModel3DBuffer m_cDmmDeltaFlagModel;
     354#endif
    315355 
    316356  ContextModel3DBuffer m_cSDCResidualFlagSCModel;
     357#if !RWTH_SDC_CTX_SIMPL_D0032
    317358  ContextModel3DBuffer m_cSDCResidualSignFlagSCModel;
     359#endif
    318360  ContextModel3DBuffer m_cSDCResidualSCModel;
    319361 
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r332 r443  
    206206 
    207207#if H3D_IVMP
     208#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     209  const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     210#else
    208211  const Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + 1;
     212#endif
    209213  for( Int iNum = 0; iNum < iNumAMVPCands+1; iNum++)
    210214    for( Int iIdx = 0; iIdx < iNumAMVPCands; iIdx++)
     
    908912      if( uiAbsPartIdx == 0 )
    909913      {
    910         m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, 0 );
     914        m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, 0
     915#if PKU_QC_DEPTH_INTRA_UNI_D0195
     916         ,true
     917#endif
     918          );
    911919      }
    912920    }
     
    17011709      UChar ucSegment = pMask?(UChar)pMask[uiX]:0;
    17021710      assert( ucSegment < uiNumSegments );
     1711#if MTK_SAMPLE_BASED_SDC_D0110     
     1712      Pel pResiDC = apDCResiValues[ucSegment];
    17031713     
     1714      pReco    [ uiX ] = Clip( pPred[ uiX ] + pResiDC );
     1715#else
    17041716      Pel pPredVal= apDCPredValues[ucSegment];
    17051717      Pel pResiDC = apDCResiValues[ucSegment];
    17061718     
    17071719      pReco    [ uiX ] = Clip( pPredVal + pResiDC );
     1720#endif
    17081721      pRecIPred[ uiX ] = pReco[ uiX ];
    17091722    }
     
    17351748  if ( m_pcRdCost->getUseVSO() )
    17361749  {
     1750#if FIX_SDC_ENC_RD_WVSO_D0163 && LGE_WVSO_A0119
     1751    if ( m_pcRdCost->getUseWVSO() )
     1752    {   
     1753      Int iDWeight = m_pcRdCost->getDWeight() * m_pcRdCost->getDWeight();
     1754      Int iVSOWeight = m_pcRdCost->getVSOWeight() * m_pcRdCost->getVSOWeight();
     1755      Dist iD = (Dist) m_pcRdCost->getDistPart( piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
     1756      Dist iVSO = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false, 0 );
     1757      ruiDist += (iDWeight * iD + iVSOWeight * iVSO) / ( iDWeight + iVSOWeight);
     1758    }
     1759    else
     1760#endif
    17371761    ruiDist = m_pcRdCost->getDistVS  ( pcCU, uiAbsPartIdx, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, false, 0 );
    17381762  }
     
    17511775 
    17521776  // encode pred direction + residual data
    1753   m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
    1754  
     1777  m_pcEntropyCoder->encodePredInfo( pcCU, 0, true
     1778#if PKU_QC_DEPTH_INTRA_UNI_D0195
     1779    ,true
     1780#endif
     1781    );
    17551782  UInt   uiBits = m_pcEntropyCoder->getNumberOfWrittenBits();
    17561783 
     
    29212948                                 , Int* iVSPIndexTrue
    29222949#endif
     2950#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2951                                 , Int* iVSPDirTrue
     2952#endif
    29232953                                 )
    29242954{
     
    29622992  }
    29632993#else
     2994
    29642995#if MERL_VSP_C0152
    2965   pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
    2966 #else
    2967   pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    2968 #endif
    2969 #endif
    2970 
     2996  pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue
     2997#if MERL_VSP_NBDV_RefVId_Fix_D0166
     2998                               , iVSPDirTrue
     2999#endif
     3000  );
     3001
     3002#else
     3003  pcCU->getInterMergeCandidates( uiAbsPartIdx, iPUIdx, uiDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand
     3004#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3005                               , iVSPDirTrue
     3006#endif
     3007  );
     3008#endif
     3009
     3010#endif
    29713011
    29723012#if H3D_IVMP
     
    29853025      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    29863026#if MERL_VSP_C0152
     3027#if MTK_D0156
     3028      if( !pcCU->getSlice()->getSPS()->getUseVSPCompensation() )
     3029      {
     3030          pcCU->setVSPIndexSubParts( 0, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     3031      }
     3032      else
     3033#endif
    29873034      {
    29883035        Int iVSPIdx = 0;
     3036#if LGE_VSP_INHERIT_D0092
     3037        if (iVSPIndexTrue[uiMergeCand] == 1)
     3038        {
     3039            iVSPIdx = 1;
     3040        }
     3041#else
    29893042        Int numVSPIdx;
    29903043        numVSPIdx = 3;
     
    29973050            }
    29983051        }
     3052#endif
    29993053        pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     3054#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3055        pcCU->setVSPDirSubParts(0, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     3056#endif
     3057#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     3058       if(iVSPIdx != 0)
     3059       {
     3060        Int iIVCIdx = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==pcCU->getSlice()->getPOC() ? 0: pcCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     3061        cMvFieldNeighbours[ 2*uiMergeIndex].setRefIdx(iIVCIdx);
     3062      }
     3063#endif
    30003064      }
    30013065#endif
     
    31093173
    31103174#if H3D_IVMP
     3175#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     3176  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     3177#else
    31113178  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     3179#endif
    31123180#endif
    31133181
     
    31383206    //reset the VSP flag to be 0
    31393207    pcCU->setVSPIndexSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
     3208#endif
     3209#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3210    pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr) );
    31403211#endif
    31413212#if AMP_MRG
     
    33773448        iNumIter = 1;
    33783449      }
    3379      
     3450
    33803451      for ( Int iIter = 0; iIter < iNumIter; iIter++ )
    33813452      {
     
    36573728      UInt uiMRGIndex = 0;
    36583729#if MERL_VSP_C0152
     3730#if LGE_VSP_INHERIT_D0092
     3731      Int iVSPIndexTrue[MRG_MAX_NUM_CANDS_MEM];
     3732      for (Int i=0; i<MRG_MAX_NUM_CANDS_MEM; i++)
     3733      {
     3734          iVSPIndexTrue[i] = 0;
     3735      }
     3736#else
    36593737      Int iVSPIndexTrue[3] = {-1, -1, -1};
     3738#endif
     3739#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3740      Int iVSPDirTrue[3]   = {-1, -1, -1};
     3741#endif
    36603742#endif
    36613743      UInt uiMEInterDir = 0;
     
    36883770
    36893771
    3690 xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost
     3772      xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost
    36913773#if CU_BASED_MRG_CAND_LIST
    36923774                 , cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand,
     
    36943776#if MERL_VSP_C0152
    36953777                 , iVSPIndexTrue
     3778#endif
     3779#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3780                 , iVSPDirTrue
    36963781#endif
    36973782        );
     
    37033788        pcCU->setMergeIndexSubParts( uiMRGIndex,    uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    37043789#if MERL_VSP_C0152
     3790
     3791#if MTK_D0156
     3792        if( !pcCU->getSlice()->getSPS()->getUseVSPCompensation() )
     3793        {
     3794            pcCU->setVSPIndexSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3795        }
     3796        else
     3797#endif
    37053798        {
    37063799          Int iVSPIdx = 0;
     3800#if LGE_VSP_INHERIT_D0092
     3801          if (iVSPIndexTrue[uiMRGIndex] == 1)
     3802          {
     3803              iVSPIdx = 1;
     3804          }
     3805#else
    37073806          Int numVSPIdx;
    37083807          numVSPIdx = 3;
     
    37153814              }
    37163815          }
     3816#endif
    37173817          pcCU->setVSPIndexSubParts( iVSPIdx, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3818#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3819          pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3820#endif
     3821#if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
     3822         if(iVSPIdx != 0)
     3823         {
     3824           Int iIVCIdx = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==pcCU->getSlice()->getPOC() ? 0: pcCU->getSlice()->getNewRefIdx(REF_PIC_LIST_0);
     3825           cMRGMvField[ 0].setRefIdx(iIVCIdx);
     3826         }
     3827#endif
    37183828        }
    37193829#endif
     
    37383848        pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    37393849#if MERL_VSP_C0152
    3740         pcCU->setVSPIndexSubParts ( 0 ,           uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3850        pcCU->setVSPIndexSubParts ( 0,            uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     3851#endif
     3852#if MERL_VSP_NBDV_RefVId_Fix_D0166
     3853        pcCU->setVSPDirSubParts   ( 0,            uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    37413854#endif
    37423855        {
     
    37993912    {
    38003913#if H3D_IVMP
     3914#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     3915      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     3916#else
    38013917      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     3918#endif
    38023919#if ZERO_MVD_EST
    38033920      (*puiDistBiP) = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, rcMvPred, 0, iNumAMVPCands, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight, uiDist );
     
    38343951      UInt uiTmpCost;
    38353952#if H3D_IVMP
     3953#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     3954      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     3955#else
    38363956      Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     3957#endif
    38373958#if ZERO_MVD_EST
    38383959      uiTmpCost = xGetTemplateCost( pcCU, uiPartIdx, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, pcAMVPInfo->m_acMvCand[i], i, iNumAMVPCands, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight, uiDist );
     
    39674088 
    39684089#if H3D_IVMP
     4090#if SEC_TWO_CANDIDATES_FOR_AMVP_D0122
     4091  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS;
     4092#else
    39694093  Int iNumAMVPCands = AMVP_MAX_NUM_CANDS + ( pcCU->getSlice()->getSPS()->getMultiviewMvPredMode() ? 1 : 0 );
     4094#endif
    39704095#endif
    39714096 
     
    46744799#endif
    46754800      );
     4801#if QC_ARP_D0177
     4802    m_pcEntropyCoder->encodeARPW       ( pcCU , 0 , true );
     4803#endif
    46764804#endif
    46774805#if HHI_MPI
     
    58926020    // Reload only contexts required for coding intra mode information
    58936021    m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     6022#if PKU_QC_DEPTH_INTRA_UNI_D0195
     6023    m_pcRDGoOnSbacCoder->loadDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     6024#endif
    58946025  }
    58956026 
     
    58976028 
    58986029  m_pcEntropyCoder->resetBits();
    5899   m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiPartOffset);
     6030  m_pcEntropyCoder->encodeIntraDirModeLuma ( pcCU, uiPartOffset
     6031#if PKU_QC_DEPTH_INTRA_UNI_D0195
     6032    ,true
     6033#endif
     6034    );
    59006035 
    59016036  return m_pcEntropyCoder->getNumberOfWrittenBits();
     
    59546089      );
    59556090#endif
     6091#if QC_ARP_D0177
     6092    m_pcEntropyCoder->encodeARPW( pcCU , 0 , true );
     6093#endif
    59566094    ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
    59576095  }
     
    59776115#endif
    59786116      );
     6117#if QC_ARP_D0177
     6118    m_pcEntropyCoder->encodeARPW( pcCU , 0 , true );
     6119#endif
    59796120#endif
    59806121#if HHI_MPI
     
    63016442  Int iMaskStride = ( uiWidth<<1 ) + 1;
    63026443  piMask += iMaskStride+1;
     6444#if QC_DC_PREDICTOR_D0183
     6445  getPredDCs( pcWedgelet->getPattern(), pcWedgelet->getStride(), piMask, iMaskStride, iPredDC1, iPredDC2 );
     6446#else
    63036447  getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAboveAvail, bLeftAvail );
     6448#endif
    63046449
    63056450  riDeltaDC1 = iDC1 - iPredDC1;
     
    64786623#endif
    64796624
     6625#if HHI_DELTADC_DLT_D0035
     6626  riDeltaDC1 = (Int)GetDepthValue2Idx( Clip(iPredDC1 + riDeltaDC1) ) - (Int)GetDepthValue2Idx( iPredDC1 );
     6627  riDeltaDC2 = (Int)GetDepthValue2Idx( Clip(iPredDC2 + riDeltaDC2) ) - (Int)GetDepthValue2Idx( iPredDC2 );
     6628#endif
    64806629}
    64816630#endif
     
    78628011
    78638012  // PredDC Calculation
     8013#if QC_DC_PREDICTOR_D0183
     8014  getPredDCs( pbRegion, uiWidth, piMask+iMaskStride+1, iMaskStride, iPredDC0, iPredDC1 );
     8015#else
    78648016  {
    78658017    UInt uiSum0 = 0;
     
    79018053    iPredDC1 = uiSum1 / uiCount1;
    79028054  }
     8055#endif
    79038056
    79048057  iDeltaDC0 = iDC0 - iPredDC0;
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r332 r443  
    511511                                  , Int* iVSPIndexTrue
    512512#endif
     513#if MERL_VSP_NBDV_RefVId_Fix_D0166
     514                                  , Int* iVSPDirTrue
     515#endif
    513516                                   );
    514517  // -------------------------------------------------------------------------------------------------------------------
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r332 r443  
    6060  m_pcBufferLowLatSbacCoders    = NULL;
    6161  m_pcBufferLowLatBinCoderCABACs  = NULL;
     62#if MERL_VSP_NBDV_RefVId_Fix_D0166
     63  for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
     64    m_pcListDepthPic[iNumCount] = NULL;
     65#endif
    6266#if FCO_DVP_REFINE_C0132_C0170
    6367  m_pPicBaseTxt = NULL;
     
    148152  m_pdRdPicQp         = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
    149153  m_piRdPicQp         = (Int*   )xMalloc( Int,    m_pcCfg->getDeltaQpRD() * 2 + 1 );
     154
     155#if MERL_VSP_NBDV_RefVId_Fix_D0166
     156  for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
     157    m_pcListDepthPic[iNumCount] = NULL;
     158#endif
    150159}
    151160
     
    778787  {
    779788    pcSlice ->xSetApplyIC();
     789#if SHARP_ILLUCOMP_PARSE_D0060
     790    if (pcSlice->getApplyIC())
     791    {
     792      pcSlice->setIcSkipParseFlag(rpcPic->getCurrSlice()->getPOC() % m_pcCfg->getIntraPeriod() != 0);
     793    }
     794#endif
    780795  }
    781796#endif
     
    819834#if MERL_VSP_C0152
    820835  // Send Depth/Texture pointers to slice level
     836#if !MERL_VSP_NBDV_RefVId_Fix_D0166
    821837  pcSlice->setBWVSPLUTParam(m_aiShiftLUT, m_iShiftPrec);
     838#endif
    822839  pcSlice->setRefPicBaseTxt(m_pPicBaseTxt);
    823840  pcSlice->setRefPicBaseDepth(m_pPicBaseDepth);
     841#if MERL_VSP_NBDV_RefVId_Fix_D0166
     842  for (Int refViewId=0; refViewId < pcSlice->getViewId(); refViewId++)
     843  {
     844    assert( m_pcListDepthPic[refViewId] );
     845    pcSlice->setListDepthPic(m_pcListDepthPic[refViewId], refViewId);
     846    pcSlice->setBWVSPLUTParam(m_aiShiftLUT[refViewId], m_iShiftPrec, refViewId);
     847  }
     848#endif
    824849#endif
    825850
     
    11991224    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );   
    12001225
     1226#if LGE_SAO_MIGRATION_D0091
     1227    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
     1228    {
     1229        SAOParam *saoParam =  pcSlice->getAPS()->getSaoParam();
     1230        Int iNumCuInWidth     = saoParam->numCuInWidth;
     1231        Int iCUAddrInSlice    = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
     1232        Int iCUAddrUpInSlice  = iCUAddrInSlice - iNumCuInWidth;
     1233        Int rx = uiCUAddr % iNumCuInWidth;
     1234        Int ry = uiCUAddr / iNumCuInWidth;
     1235        Int allowMergeLeft = 1;
     1236        Int allowMergeUp   = 1;
     1237
     1238        if (rx!=0)
     1239        {
     1240            if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
     1241            {
     1242                allowMergeLeft = 0;
     1243            }
     1244        }
     1245        if (ry!=0)
     1246        {
     1247            if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
     1248            {
     1249                allowMergeUp = 0;
     1250            }
     1251        }
     1252
     1253        Int addr = pcCU->getAddr();
     1254        allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0);
     1255        allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0);
     1256
     1257        if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
     1258        {
     1259            Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag;
     1260            Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag;
     1261
     1262            if (allowMergeLeft)
     1263            {
     1264                m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
     1265            }
     1266            else
     1267            {
     1268                mergeLeft = 0;
     1269            }
     1270            if(mergeLeft == 0)
     1271            {
     1272                if (allowMergeUp)
     1273                {
     1274                    m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp);
     1275                }
     1276                else
     1277                {
     1278                    mergeUp = 0;
     1279                }
     1280                if(mergeUp == 0)
     1281                {
     1282                    for (Int compIdx=0;compIdx<3;compIdx++)
     1283                    {
     1284                        if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1]))
     1285                        {
     1286                            m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
     1287                        }
     1288                    }
     1289                }
     1290            }
     1291        }
     1292    }
     1293#else
    12011294    if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getAPS()->getSaoInterleavingFlag() && pcSlice->getSaoEnabledFlag() )
    12021295    {
     
    12081301      m_pcEntropyCoder->encodeSaoUnitInterleaving( rx, ry, pcSlice->getAPS()->getSaoParam(),pcCU, iCUAddrInSlice, iCUAddrUpInSlice, pcSlice->getSPS()->getLFCrossSliceBoundaryFlag());
    12091302    }
     1303#endif
    12101304#if ENC_DEC_TRACE
    12111305    g_bJustDoIt = g_bEncDecTraceEnable;
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r296 r443  
    106106  TComPic* m_pPicBaseTxt;
    107107  TComPic* m_pPicBaseDepth;
     108#if MERL_VSP_NBDV_RefVId_Fix_D0166
     109  Int*     m_aiShiftLUT[2]; ///< For reference views from LIST0 and LIST1
     110#else
    108111  Int*     m_aiShiftLUT;
     112#endif
    109113  Int      m_iShiftPrec;
    110114#endif
    111 
     115#if MERL_VSP_NBDV_RefVId_Fix_D0166
     116  TComList<TComPic*>*  m_pcListDepthPic[MAX_VIEW_NUM]; ///< For three views in total, indexed as viewId = 0, 1, 2
     117#endif
    112118public:
    113119  TEncSlice();
     
    143149
    144150#if MERL_VSP_C0152
    145    Void     setBWVSPLUTParam    ( Int *pShiftLUT, Int iLoG2LUTPrec ) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
     151#if MERL_VSP_NBDV_RefVId_Fix_D0166
     152  Void     setBWVSPLUTParam  ( Int *pShiftLUT, Int iLoG2LUTPrec, Int iNeighborViewId ) { m_aiShiftLUT[iNeighborViewId] = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
     153#else
     154  Void     setBWVSPLUTParam    ( Int *pShiftLUT, Int iLoG2LUTPrec ) { m_aiShiftLUT = pShiftLUT; m_iShiftPrec = 2-iLoG2LUTPrec; }
     155#endif
    146156   Void     setRefPicBaseTxt    ( TComPic*pPicTxt   ) { m_pPicBaseTxt = pPicTxt;    }
    147157   Void     setRefPicBaseDepth  ( TComPic*pPicDepth ) { m_pPicBaseDepth = pPicDepth;}
     158#if MERL_VSP_NBDV_RefVId_Fix_D0166
     159   Void     getBWVSPLUTParam  ( Int*& pShiftLUT, Int& iShiftPrec, Int iNeighborViewId ) { pShiftLUT = m_aiShiftLUT[iNeighborViewId]; iShiftPrec = m_iShiftPrec; }
     160#else
    148161   Void     getBWVSPLUTParam    ( Int*& pShiftLUT, Int& iShiftPrec ) { pShiftLUT = m_aiShiftLUT; iShiftPrec = m_iShiftPrec; }
     162#endif
    149163   TComPic* getRefPicBaseTxt    () { return m_pPicBaseTxt;   }
    150164   TComPic* getRefPicBaseDepth  () { return m_pPicBaseDepth; }
     165#if MERL_VSP_NBDV_RefVId_Fix_D0166
     166   Void     setListDepthPic     ( TComList<TComPic*>* pListDepthPic, Int viewId ) { m_pcListDepthPic[viewId] = pListDepthPic; }
     167   TComList<TComPic*>* getListDepthPic(Int viewId)  { return m_pcListDepthPic[viewId]; }
     168#endif
    151169#endif
    152170};
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r332 r443  
    103103  if (m_bUseSAO)
    104104  {
     105#if LGE_SAO_MIGRATION_D0091
     106    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
     107    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
     108#else
    105109    m_cEncSAO.setSaoInterleavingFlag(getSaoInterleavingFlag());
     110#endif
    106111    m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
    107112    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     
    120125  m_cDepthMapGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
    121126#endif
    122 #if H3D_IVRP
     127#if H3D_IVRP & !QC_ARP_D0177
    123128  m_cResidualGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
    124129#endif
     
    251256  m_cDepthMapGenerator. destroy();
    252257#endif
    253 #if H3D_IVRP
     258#if H3D_IVRP & !QC_ARP_D0177
    254259  m_cResidualGenerator. destroy();
    255260#endif
     
    347352#endif
    348353#endif
    349 #if H3D_IVRP
     354#if H3D_IVRP & !QC_ARP_D0177
    350355  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
    351356#endif
     
    710715#endif
    711716
     717
     718#if MTK_D0156
     719#if MERL_VSP_COMPENSATION_C0152
     720  m_cSPS.setUseVSPCompensation           ( m_bUseVSPCompensation );
     721#endif
     722  m_cSPS.setUseDVPRefine                 ( m_bUseDVPRefine       );
     723#endif
     724
    712725  if( m_isDepth )
    713726  {
     
    722735#endif
    723736#if H3D_IVRP
     737#if QC_ARP_D0177
     738    m_cSPS.setUseAdvRP              ( 0 );
     739    m_cSPS.setARPStepNum            ( 1 );
     740#else
    724741    m_cSPS.setMultiviewResPredMode  ( 0 );
    725742#endif
     743#endif
     744
    726745  }
    727746  else
     
    742761#endif
    743762#if H3D_IVRP
    744       m_cSPS.setMultiviewResPredMode  ( m_uiMultiviewResPredMode );
     763#if QC_ARP_D0177
     764     m_cSPS.setUseAdvRP  ( m_viewId > 0   ? m_nUseAdvResPred : 0 );
     765     m_cSPS.setARPStepNum( m_viewId > 0   ? QC_ARP_WFNR      : 1 );
     766#else
     767     m_cSPS.setMultiviewResPredMode  ( m_uiMultiviewResPredMode );
     768#endif
    745769#endif
    746770    }
     
    751775#endif
    752776#if H3D_IVRP
     777#if QC_ARP_D0177
     778      m_cSPS.setUseAdvRP              ( 0 );
     779      m_cSPS.setARPStepNum            ( 1 );
     780#else
    753781      m_cSPS.setMultiviewResPredMode  ( 0 );
     782#endif
    754783#endif
    755784    }
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r296 r443  
    103103  TComDepthMapGenerator   m_cDepthMapGenerator;           ///< depth map generator
    104104#endif
    105 #if H3D_IVRP
     105#if H3D_IVRP & !QC_ARP_D0177
    106106  TComResidualGenerator   m_cResidualGenerator;           ///< generator for residual pictures
    107107#endif
     
    234234  TComDepthMapGenerator*  getDepthMapGenerator  () { return  &m_cDepthMapGenerator;   }
    235235#endif
    236 #if H3D_IVRP
     236#if H3D_IVRP & !QC_ARP_D0177
    237237  TComResidualGenerator*  getResidualGenerator  () { return  &m_cResidualGenerator;   }
    238238#endif
Note: See TracChangeset for help on using the changeset viewer.