Changeset 125 in SHVCSoftware for trunk/source/Lib/TLibEncoder/TEncSlice.cpp


Ignore:
Timestamp:
16 Apr 2013, 06:39:31 (12 years ago)
Author:
seregin
Message:

copy from HM-10.0-dev-SHM

File:
1 edited

Legend:

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

    r11 r125  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    6363TEncSlice::~TEncSlice()
    6464{
    65 #if DEPENDENT_SLICES
    6665  for (std::vector<TEncSbac*>::iterator i = CTXMem.begin(); i != CTXMem.end(); i++)
    6766  {
    6867    delete (*i);
    6968  }
    70 #endif
    7169}
    7270
    73 #if DEPENDENT_SLICES
    7471Void TEncSlice::initCtxMem(  UInt i )               
    7572{   
     
    8178  CTXMem.resize(i);
    8279}
    83 #endif
    8480
    8581Void TEncSlice::create( Int iWidth, Int iHeight, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth )
     
    173169 .
    174170 \param pcPic         picture class
    175  \param iPOCLast      POC of last picture
    176  \param uiPOCCurr     current POC
     171 \param pocLast       POC of last picture
     172 \param pocCurr       current POC
    177173 \param iNumPicRcvd   number of received pictures
    178174 \param iTimeOffset   POC offset for hierarchical structure
     
    182178 \param pPPS          PPS associated with the slice
    183179 */
    184 Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
     180Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
    185181{
    186182  Double dQP;
     
    192188  rpcSlice->setSliceBits(0);
    193189  rpcSlice->setPic( pcPic );
    194 #if SET_SLICE_LAYER_ID
     190#if SVC_EXTENSION
    195191  rpcSlice->initSlice( pcPic->getLayerId() );
    196192#else
     
    198194#endif
    199195  rpcSlice->setPicOutputFlag( true );
    200   rpcSlice->setPOC( uiPOCCurr );
    201  
    202 #if SVC_EXTENSION && !SET_SLICE_LAYER_ID
    203   rpcSlice->setLayerId( pcPic->getLayerId());
    204 #endif
    205 
     196  rpcSlice->setPOC( pocCurr );
     197 
    206198  // depth computation based on GOP size
    207   int iDepth;
    208   {
    209     Int i, j;
    210     Int iPOC = rpcSlice->getPOC()%m_pcCfg->getGOPSize();
    211     if ( iPOC == 0 )
    212     {
    213       iDepth = 0;
     199  Int depth;
     200  {
     201    Int poc = rpcSlice->getPOC()%m_pcCfg->getGOPSize();
     202    if ( poc == 0 )
     203    {
     204      depth = 0;
    214205    }
    215206    else
    216207    {
    217       Int iStep = m_pcCfg->getGOPSize();
    218       iDepth    = 0;
    219       for( i=iStep>>1; i>=1; i>>=1 )
    220       {
    221         for ( j=i; j<m_pcCfg->getGOPSize(); j+=iStep )
    222         {
    223           if ( j == iPOC )
     208      Int step = m_pcCfg->getGOPSize();
     209      depth    = 0;
     210      for( Int i=step>>1; i>=1; i>>=1 )
     211      {
     212        for ( Int j=i; j<m_pcCfg->getGOPSize(); j+=step )
     213        {
     214          if ( j == poc )
    224215          {
    225216            i=0;
     
    227218          }
    228219        }
    229         iStep>>=1;
    230         iDepth++;
     220        step >>= 1;
     221        depth++;
    231222      }
    232223    }
     
    237228 
    238229  eSliceType=B_SLICE;
    239   eSliceType = (iPOCLast == 0 || uiPOCCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     230  eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    240231 
    241232  rpcSlice->setSliceType    ( eSliceType );
     
    245236  // ------------------------------------------------------------------------------------------------------------------
    246237 
    247 #if TEMPORAL_LAYER_NON_REFERENCE
    248   if(iPOCLast == 0)
     238  if(pocLast == 0)
    249239  {
    250240    rpcSlice->setTemporalLayerNonReferenceFlag(false);
     
    255245  }
    256246  rpcSlice->setReferenced(true);
    257 #else
    258   rpcSlice->setReferenced(m_pcCfg->getGOPEntry(iGOPid).m_refPic);
    259 #endif
    260 #if !REMOVE_NAL_REF_FLAG
    261   rpcSlice->setNalRefFlag(m_pcCfg->getGOPEntry(iGOPid).m_refPic);
    262 #endif
    263 #if !TEMPORAL_LAYER_NON_REFERENCE
    264   if(eSliceType==I_SLICE)
    265   {
    266     rpcSlice->setReferenced(true);
    267   }
    268 #endif
    269247 
    270248  // ------------------------------------------------------------------------------------------------------------------
     
    287265    dQP += pdQPs[ rpcSlice->getPOC() ];
    288266  }
     267#if !RATE_CONTROL_LAMBDA_DOMAIN
    289268  if ( m_pcCfg->getUseRateCtrl())
    290269  {
    291270    dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
    292271  }
     272#endif
    293273  // ------------------------------------------------------------------------------------------------------------------
    294274  // Lambda computation
     
    309289    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
    310290#if FULL_NBIT
    311     Int    bitdepth_luma_qp_scale = 6 * (g_uiBitDepth - 8);
     291    Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
    312292#else
    313293    Int    bitdepth_luma_qp_scale = 0;
     
    325305    dLambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
    326306
    327     if ( iDepth>0 )
     307    if ( depth>0 )
    328308    {
    329309#if FULL_NBIT
     
    335315   
    336316    // if hadamard is used in ME process
    337     if ( !m_pcCfg->getUseHADME() )
     317    if ( !m_pcCfg->getUseHADME() && rpcSlice->getSliceType( ) != I_SLICE )
    338318    {
    339319      dLambda *= 0.95;
     
    363343  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    364344  Double weight = 1.0;
    365   if(iQP >= 0)
    366   {
    367     weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
    368   }
    369   m_pcRdCost ->setChromaDistortionWeight( weight );     
     345  Int qpc;
     346  Int chromaQPOffset;
     347
     348  chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb();
     349  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
     350  weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     351  m_pcRdCost->setCbDistortionWeight(weight);
     352
     353  chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr();
     354  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
     355  weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     356  m_pcRdCost->setCrDistortionWeight(weight);
    370357#endif
    371358
     
    377364#endif
    378365
    379 #if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
    380 // For ALF or SAO
     366#if SAO_CHROMA_LAMBDA
     367// For SAO
    381368  rpcSlice   ->setLambda( dLambda, dLambda / weight ); 
    382369#else
     
    386373#if HB_LAMBDA_FOR_LDC
    387374  // restore original slice type
    388   eSliceType = (iPOCLast == 0 || uiPOCCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     375  eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     376 
    389377#if REF_IDX_FRAMEWORK
    390378  if(m_pcCfg->getLayerId() > 0)
     
    396384#endif
    397385 
    398 #if RECALCULATE_QP_ACCORDING_LAMBDA
    399386  if (m_pcCfg->getUseRecalculateQPAccordingToLambda())
    400387  {
     
    402389    iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );   
    403390  }
    404 #endif
    405391
    406392  rpcSlice->setSliceQp          ( iQP );
     
    409395#endif
    410396  rpcSlice->setSliceQpDelta     ( 0 );
    411 #if CHROMA_QP_EXTENSION
    412397  rpcSlice->setSliceQpDeltaCb   ( 0 );
    413398  rpcSlice->setSliceQpDeltaCr   ( 0 );
    414 #endif
    415399  rpcSlice->setNumRefIdx(REF_PIC_LIST_0,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
    416400  rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
     
    424408    if ( !rpcSlice->getDeblockingFilterDisable())
    425409    {
     410      if ( !m_pcCfg->getLoopFilterOffsetInPPS() && eSliceType!=I_SLICE)
     411      {
     412        rpcSlice->getPPS()->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_betaOffsetDiv2 + m_pcCfg->getLoopFilterBetaOffset() );
     413        rpcSlice->getPPS()->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_tcOffsetDiv2 + m_pcCfg->getLoopFilterTcOffset() );
     414        rpcSlice->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_betaOffsetDiv2 + m_pcCfg->getLoopFilterBetaOffset()  );
     415        rpcSlice->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_tcOffsetDiv2 + m_pcCfg->getLoopFilterTcOffset() );
     416      }
     417      else
     418      {
    426419      rpcSlice->getPPS()->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getLoopFilterBetaOffset() );
    427420      rpcSlice->getPPS()->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getLoopFilterTcOffset() );
    428421      rpcSlice->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getLoopFilterBetaOffset() );
    429422      rpcSlice->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getLoopFilterTcOffset() );
    430     }
    431   }
    432 
    433   rpcSlice->setDepth            ( iDepth );
     423      }
     424    }
     425  }
     426  else
     427  {
     428    rpcSlice->setDeblockingFilterOverrideFlag( false );
     429    rpcSlice->setDeblockingFilterDisable( false );
     430    rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
     431    rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
     432  }
     433
     434  rpcSlice->setDepth            ( depth );
    434435 
    435436  pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
     
    447448  rpcSlice->setSliceMode            ( m_pcCfg->getSliceMode()            );
    448449  rpcSlice->setSliceArgument        ( m_pcCfg->getSliceArgument()        );
    449   rpcSlice->setDependentSliceMode     ( m_pcCfg->getDependentSliceMode()     );
    450   rpcSlice->setDependentSliceArgument ( m_pcCfg->getDependentSliceArgument() );
     450  rpcSlice->setSliceSegmentMode     ( m_pcCfg->getSliceSegmentMode()     );
     451  rpcSlice->setSliceSegmentArgument ( m_pcCfg->getSliceSegmentArgument() );
    451452  rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()        );
    452453  xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPred() );
    453454}
    454455
    455 
     456#if RATE_CONTROL_LAMBDA_DOMAIN
     457Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
     458{
     459  TComSlice* slice = pic->getSlice(0);
     460
     461  // store lambda
     462  slice->setSliceQp( sliceQP );
     463#if L0033_RC_BUGFIX
     464  slice->setSliceQpBase ( sliceQP );
     465#endif
     466  m_pcRdCost ->setLambda( lambda );
     467#if WEIGHTED_CHROMA_DISTORTION
     468  // for RDO
     469  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
     470  Double weight;
     471  Int qpc;
     472  Int chromaQPOffset;
     473
     474  chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
     475  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
     476  weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     477  m_pcRdCost->setCbDistortionWeight(weight);
     478
     479  chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
     480  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
     481  weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     482  m_pcRdCost->setCrDistortionWeight(weight);
     483#endif
     484
     485#if RDOQ_CHROMA_LAMBDA
     486  // for RDOQ
     487  m_pcTrQuant->setLambda( lambda, lambda / weight );
     488#else
     489  m_pcTrQuant->setLambda( lambda );
     490#endif
     491
     492#if SAO_CHROMA_LAMBDA
     493  // For SAO
     494  slice   ->setLambda( lambda, lambda / weight );
     495#else
     496  slice   ->setLambda( lambda );
     497#endif
     498}
     499#else
    456500/**
    457501 - lambda re-computation based on rate control QP
     
    475519    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
    476520#if FULL_NBIT
    477     Int    bitdepth_luma_qp_scale = 6 * (g_uiBitDepth - 8);
     521    Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
    478522#else
    479523    Int    bitdepth_luma_qp_scale = 0;
     
    529573  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    530574  Double weight = 1.0;
    531   if(qp >= 0)
    532   {
    533     weight = pow( 2.0, (qp-g_aucChromaScale[qp])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
    534   }
    535   m_pcRdCost ->setChromaDistortionWeight( weight );     
     575  Int qpc;
     576  Int chromaQPOffset;
     577
     578  chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
     579  qpc = Clip3( 0, 57, qp + chromaQPOffset);
     580  weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     581  m_pcRdCost->setCbDistortionWeight(weight);
     582
     583  chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
     584  qpc = Clip3( 0, 57, qp + chromaQPOffset);
     585  weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     586  m_pcRdCost->setCrDistortionWeight(weight);
    536587#endif
    537588
     
    543594#endif
    544595
    545 #if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
    546   // For ALF or SAO
     596#if SAO_CHROMA_LAMBDA
     597  // For SAO
    547598  pcSlice   ->setLambda( lambda, lambda / weight ); 
    548599#else
     
    550601#endif
    551602}
     603#endif
    552604// ====================================================================================================================
    553605// Public member functions
     
    588640    return;
    589641  }
     642
     643#if RATE_CONTROL_LAMBDA_DOMAIN
     644  if ( m_pcCfg->getUseRateCtrl() )
     645  {
     646    printf( "\nMultiple QP optimization is not allowed when rate control is enabled." );
     647    assert(0);
     648  }
     649#endif
    590650 
    591651  TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
     
    595655  Double dFrameLambda;
    596656#if FULL_NBIT
    597   Int    SHIFT_QP = 12 + 6 * (g_uiBitDepth - 8);
     657  Int    SHIFT_QP = 12 + 6 * (g_bitDepth - 8);
    598658#else
    599659  Int    SHIFT_QP = 12;
     
    622682    // for RDO
    623683    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    624     int iQP = m_piRdPicQp    [uiQpIdx];
     684    Int iQP = m_piRdPicQp    [uiQpIdx];
    625685    Double weight = 1.0;
    626     if(iQP >= 0)
    627     {
    628       weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
    629     }
    630     m_pcRdCost    ->setChromaDistortionWeight( weight );     
     686    Int qpc;
     687    Int chromaQPOffset;
     688
     689    chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
     690    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
     691    weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     692    m_pcRdCost->setCbDistortionWeight(weight);
     693
     694    chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
     695    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
     696    weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     697    m_pcRdCost->setCrDistortionWeight(weight);
    631698#endif
    632699
     
    637704    m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    638705#endif
    639 #if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
    640     // For ALF or SAO
     706#if SAO_CHROMA_LAMBDA
     707    // For SAO
    641708    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
    642709#else
     
    671738#if WEIGHTED_CHROMA_DISTORTION
    672739  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    673   int iQP = m_piRdPicQp    [uiQpIdxBest];
     740  Int iQP = m_piRdPicQp    [uiQpIdxBest];
    674741  Double weight = 1.0;
    675   if(iQP >= 0)
    676   {
    677     weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 );  // takes into account of the chroma qp mapping without chroma qp Offset
    678   }
    679   m_pcRdCost ->setChromaDistortionWeight( weight );     
     742  Int qpc;
     743  Int chromaQPOffset;
     744
     745  chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
     746  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
     747  weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     748  m_pcRdCost->setCbDistortionWeight(weight);
     749
     750  chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
     751  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
     752  weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     753  m_pcRdCost->setCrDistortionWeight(weight);
    680754#endif
    681755
     
    686760  m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    687761#endif
    688 #if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
    689   // For ALF or SAO
     762#if SAO_CHROMA_LAMBDA
     763  // For SAO
    690764  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
    691765#else
     
    701775  UInt   uiStartCUAddr;
    702776  UInt   uiBoundingCUAddr;
    703   rpcPic->getSlice(getSliceIdx())->setDependentSliceCounter(0);
     777  rpcPic->getSlice(getSliceIdx())->setSliceSegmentBits(0);
    704778  TEncBinCABAC* pppcRDSbacCoder = NULL;
    705779  TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
     
    745819    //  Weighted Prediction implemented at Slice level. SliceMode=2 is not supported yet.
    746820    //------------------------------------------------------------------------------
    747     if ( pcSlice->getSliceMode()==2 || pcSlice->getDependentSliceMode()==2 )
     821    if ( pcSlice->getSliceMode()==2 || pcSlice->getSliceSegmentMode()==2 )
    748822    {
    749823      printf("Weighted Prediction is not supported with slice mode determined by max number of bins.\n"); exit(0);
     
    782856    m_pcBufferSbacCoders     = new TEncSbac    [uiTilesAcross];
    783857    m_pcBufferBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
    784     for (int ui = 0; ui < uiTilesAcross; ui++)
     858    for (Int ui = 0; ui < uiTilesAcross; ui++)
    785859    {
    786860      m_pcBufferSbacCoders[ui].init( &m_pcBufferBinCoderCABACs[ui] );
     
    802876    m_pcBufferLowLatSbacCoders     = new TEncSbac    [uiTilesAcross];
    803877    m_pcBufferLowLatBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
    804     for (int ui = 0; ui < uiTilesAcross; ui++)
     878    for (Int ui = 0; ui < uiTilesAcross; ui++)
    805879    {
    806880      m_pcBufferLowLatSbacCoders[ui].init( &m_pcBufferLowLatBinCoderCABACs[ui] );
     
    820894#endif
    821895
    822 
    823 #if DEPENDENT_SLICES
    824   Bool bAllowDependence = false;
    825 #if TILES_WPP_ENTROPYSLICES_FLAGS
    826   if( pcSlice->getPPS()->getDependentSliceEnabledFlag()&&(!pcSlice->getPPS()->getEntropySliceEnabledFlag()) )
    827 #else
    828   if( pcSlice->getPPS()->getDependentSliceEnabledFlag()&&(!pcSlice->getPPS()->getCabacIndependentFlag()) )
    829 #endif
    830   {
    831     bAllowDependence = true;
    832   }
    833   if( bAllowDependence )
    834   {
    835     if(pcSlice->getDependentSliceCurStartCUAddr()!= pcSlice->getSliceCurStartCUAddr())
     896  Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
     897  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     898  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     899  if( depSliceSegmentsEnabled )
     900  {
     901    if((pcSlice->getSliceSegmentCurStartCUAddr()!= pcSlice->getSliceCurStartCUAddr())&&(uiCUAddr != uiTileStartLCU))
    836902    {
    837903      if( m_pcCfg->getWaveFrontsynchro() )
    838904      {
     905        uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
    839906        m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
    840       }
    841       m_pppcRDSbacCoder[0][CI_CURR_BEST]->loadContexts( CTXMem[0] );
    842       if (pcSlice->getPPS()->getNumSubstreams() > 1)
    843       {
    844907        Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    845908        uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     
    847910        uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(rpcPic->getPicSym()->getCUOrderMap(uiCUAddr))*iNumSubstreamsPerTile
    848911          + uiLin%iNumSubstreamsPerTile;
    849       }
     912        if ( (uiCUAddr%uiWidthInLCUs+1) >= uiWidthInLCUs  )
     913        {
     914          uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     915          uiCol     = uiCUAddr % uiWidthInLCUs;
     916          if(uiCol==uiTileStartLCU)
     917          {
     918            CTXMem[0]->loadContexts(m_pcSbacCoder);
     919          }
     920        }
     921      }
     922      m_pppcRDSbacCoder[0][CI_CURR_BEST]->loadContexts( CTXMem[0] );
    850923      ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->loadContexts( CTXMem[0] );
    851924    }
     
    859932    }
    860933  }
    861 #endif
    862934  // for every CU in slice
    863935  UInt uiEncCUOrder;
    864   uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
    865936  for( uiEncCUOrder = uiStartCUAddr/rpcPic->getNumPartInCU();
    866937       uiEncCUOrder < (uiBoundingCUAddr+(rpcPic->getNumPartInCU()-1))/rpcPic->getNumPartInCU();
     
    874945#endif
    875946
     947#if !RATE_CONTROL_LAMBDA_DOMAIN
    876948    if(m_pcCfg->getUseRateCtrl())
    877949    {
     
    881953      }
    882954    }
     955#endif
    883956    // inherit from TR if necessary, select substream to use.
    884957    if( m_pcCfg->getUseSBACRD() )
     
    902975        uiSubStrm = uiLin % iNumSubstreams;
    903976      }
    904 #if DEPENDENT_SLICES
    905       if ( ((pcSlice->getPPS()->getNumSubstreams() > 1) || bAllowDependence ) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
    906 #else
    907       if ( pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX) )
    908 #endif
     977      if ( ((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
    909978      {
    910979        // We'll sync if the TR is available.
     
    920989             (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
    921990             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
    922              )||
    923              ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
    924              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getDependentSliceCurStartCUAddr()) ||
    925              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
    926991             )
    927992           )
    928993        {
    929 #if DEPENDENT_SLICES
    930           if ( (uiCUAddr != 0) && (pcCUTR->getSCUAddr()+uiMaxParts-1 >= pcSlice->getSliceCurStartCUAddr())  && bAllowDependence)
    931           {
    932             ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
    933           }
    934 #endif
    935994          // TR not available.
    936995        }
     
    9471006    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
    9481007        uiCUAddr!=0 &&                                                                                                                                    // cannot be first CU of picture
    949 #if DEPENDENT_SLICES
    950         uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getDependentSliceCurStartCUAddr())/rpcPic->getNumPartInCU() &&
    951 #endif
     1008        uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceSegmentCurStartCUAddr())/rpcPic->getNumPartInCU() &&
    9521009        uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU())     // cannot be first CU of slice
    9531010    {
     
    9701027     
    9711028      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
     1029
     1030#if RATE_CONTROL_LAMBDA_DOMAIN
     1031      Double oldLambda = m_pcRdCost->getLambda();
     1032      if ( m_pcCfg->getUseRateCtrl() )
     1033      {
     1034        Int estQP        = pcSlice->getSliceQp();
     1035        Double estLambda = -1.0;
     1036        Double bpp       = -1.0;
     1037
     1038        if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
     1039        {
     1040          estQP = pcSlice->getSliceQp();
     1041        }
     1042        else
     1043        {
     1044          bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
     1045          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
     1046          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
     1047          estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
     1048
     1049          m_pcRdCost->setLambda(estLambda);
     1050        }
     1051
     1052        m_pcRateCtrl->setRCQP( estQP );
     1053#if L0033_RC_BUGFIX
     1054        pcCU->getSlice()->setSliceQpBase( estQP );
     1055#endif
     1056      }
     1057#endif
     1058
    9721059      // run CU encoder
    9731060      m_pcCuEncoder->compressCU( pcCU );
     1061
     1062#if RATE_CONTROL_LAMBDA_DOMAIN
     1063      if ( m_pcCfg->getUseRateCtrl() )
     1064      {
     1065        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
     1066        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     1067        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     1068        Double MAD = (Double)SAD / (Double)(height * width);
     1069        MAD = MAD * MAD;
     1070        ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
     1071
     1072        Int actualQP        = g_RCInvalidQPValue;
     1073        Double actualLambda = m_pcRdCost->getLambda();
     1074        Int actualBits      = pcCU->getTotalBits();
     1075        Int numberOfEffectivePixels    = 0;
     1076        for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
     1077        {
     1078          if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
     1079          {
     1080            numberOfEffectivePixels = numberOfEffectivePixels + 16;
     1081            break;
     1082          }
     1083        }
     1084
     1085        if ( numberOfEffectivePixels == 0 )
     1086        {
     1087          actualQP = g_RCInvalidQPValue;
     1088        }
     1089        else
     1090        {
     1091          actualQP = pcCU->getQP( 0 );
     1092        }
     1093        m_pcRdCost->setLambda(oldLambda);
     1094
     1095        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
     1096      }
     1097#endif
    9741098     
    9751099      // restore entropy coder to an initial stage
     
    9841108
    9851109      pppcRDSbacCoder->setBinCountingEnableFlag( false );
    986       if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits() + m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     1110      if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits() + m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    9871111      {
    9881112        pcSlice->setNextSlice( true );
    9891113        break;
    9901114      }
    991       if (m_pcCfg->getDependentSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE && pcSlice->getDependentSliceCounter()+pppcRDSbacCoder->getBinsCoded() > m_pcCfg->getDependentSliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getDependentSliceCurEndCUAddr())
    992       {
    993         pcSlice->setNextDependentSlice( true );
     1115      if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+m_pcEntropyCoder->getNumberOfWrittenBits() > (m_pcCfg->getSliceSegmentArgument() << 3) &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
     1116      {
     1117        pcSlice->setNextSliceSegment( true );
    9941118        break;
    9951119      }
     
    9991123       
    10001124         //Store probabilties of second LCU in line into buffer
    1001 #if DEPENDENT_SLICES
    1002          if ( ( uiCol == uiTileLCUX+1) && (bAllowDependence || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
    1003 #else
    1004         if (pcSlice->getPPS()->getNumSubstreams() > 1 && uiCol == uiTileLCUX+1)
    1005 #endif
     1125         if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
    10061126        {
    10071127          m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
     
    10141134      m_pcCuEncoder->compressCU( pcCU );
    10151135      m_pcCuEncoder->encodeCU( pcCU );
    1016       if (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     1136      if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    10171137      {
    10181138        pcSlice->setNextSlice( true );
    10191139        break;
    10201140      }
    1021       if (m_pcCfg->getDependentSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE && pcSlice->getDependentSliceCounter()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getDependentSliceArgument()&&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getDependentSliceCurEndCUAddr())
    1022       {
    1023         pcSlice->setNextDependentSlice( true );
     1141      if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
     1142      {
     1143        pcSlice->setNextSliceSegment( true );
    10241144        break;
    10251145      }
     
    10291149    m_dPicRdCost     += pcCU->getTotalCost();
    10301150    m_uiPicDist      += pcCU->getTotalDistortion();
     1151#if !RATE_CONTROL_LAMBDA_DOMAIN
    10311152    if(m_pcCfg->getUseRateCtrl())
    10321153    {
     
    10341155      m_pcRateCtrl->updataRCUnitStatus();
    10351156    }
    1036   }
    1037 #if DEPENDENT_SLICES
    1038   if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !bAllowDependence)
    1039 #else
    1040   if (pcSlice->getPPS()->getNumSubstreams() > 1)
    1041 #endif
     1157#endif
     1158  }
     1159  if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled)
    10421160  {
    10431161    pcSlice->setNextSlice( true );
    10441162  }
    1045 #if DEPENDENT_SLICES
    1046   if( bAllowDependence )
     1163  if( depSliceSegmentsEnabled )
    10471164  {
    10481165    if (m_pcCfg->getWaveFrontsynchro())
     
    10521169     CTXMem[0]->loadContexts( m_pppcRDSbacCoder[0][CI_CURR_BEST] );//ctx end of dep.slice
    10531170  }
    1054 #endif
    10551171  xRestoreWPparam( pcSlice );
     1172#if !RATE_CONTROL_LAMBDA_DOMAIN
    10561173  if(m_pcCfg->getUseRateCtrl())
    10571174  {
    10581175    m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
    10591176  }
     1177#endif
    10601178}
    10611179
     
    10711189  TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx());
    10721190
    1073   uiStartCUAddr=pcSlice->getDependentSliceCurStartCUAddr();
    1074   uiBoundingCUAddr=pcSlice->getDependentSliceCurEndCUAddr();
     1191  uiStartCUAddr=pcSlice->getSliceSegmentCurStartCUAddr();
     1192  uiBoundingCUAddr=pcSlice->getSliceSegmentCurEndCUAddr();
    10751193  // choose entropy coder
    10761194  {
     
    11211239  UInt uiTileStartLCU = 0;
    11221240  UInt uiTileLCUX     = 0;
    1123 #if DEPENDENT_SLICES
    1124   Bool bAllowDependence = false;
    1125 #if TILES_WPP_ENTROPYSLICES_FLAGS
    1126   if( pcSlice->getPPS()->getDependentSliceEnabledFlag()&&(!pcSlice->getPPS()->getEntropySliceEnabledFlag()) )
    1127 #else
    1128   if( pcSlice->getPPS()->getDependentSliceEnabledFlag()&&(!pcSlice->getPPS()->getCabacIndependentFlag()) )
    1129 #endif
    1130   {
    1131     bAllowDependence = true;
    1132   }
    1133   if( bAllowDependence )
    1134   {
    1135     if(pcSlice->isNextSlice())
     1241  Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
     1242  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());  /* for tiles, uiStartCUAddr is NOT the real raster scan address, it is actually
     1243                                                                                               an encoding order index, so we need to convert the index (uiStartCUAddr)
     1244                                                                                               into the real raster scan address (uiCUAddr) via the CUOrderMap */
     1245  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     1246  if( depSliceSegmentsEnabled )
     1247  {
     1248    if( pcSlice->isNextSlice()||
     1249        uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr())
    11361250    {
    11371251      if(m_pcCfg->getWaveFrontsynchro())
     
    11451259      if(m_pcCfg->getWaveFrontsynchro())
    11461260      {
     1261        uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
    11471262        m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
    1148       }
    1149       if(pcSlice->getPPS()->getNumSubstreams() > 1)
    1150       {
    11511263        Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    1152         uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
    11531264        uiLin     = uiCUAddr / uiWidthInLCUs;
    11541265        uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(rpcPic->getPicSym()->getCUOrderMap( uiCUAddr))*iNumSubstreamsPerTile
    11551266          + uiLin%iNumSubstreamsPerTile;
     1267        if ( (uiCUAddr%uiWidthInLCUs+1) >= uiWidthInLCUs  )
     1268        {
     1269          uiCol     = uiCUAddr % uiWidthInLCUs;
     1270          uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     1271          if(uiCol==uiTileLCUX)
     1272          {
     1273            CTXMem[0]->loadContexts(m_pcSbacCoder);
     1274          }
     1275        }
    11561276      }
    11571277      pcSbacCoders[uiSubStrm].loadContexts( CTXMem[0] );
    11581278    }
    11591279  }
    1160 #endif
    11611280
    11621281  UInt uiEncCUOrder;
    1163   uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());  /*for tiles, uiStartCUAddr is NOT the real raster scan address, it is actually
    1164                                                                                               an encoding order index, so we need to convert the index (uiStartCUAddr)
    1165                                                                                               into the real raster scan address (uiCUAddr) via the CUOrderMap*/
    11661282  for( uiEncCUOrder = uiStartCUAddr /rpcPic->getNumPartInCU();
    11671283       uiEncCUOrder < (uiBoundingCUAddr+rpcPic->getNumPartInCU()-1)/rpcPic->getNumPartInCU();
     
    11911307      m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
    11921308      // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
    1193 #if DEPENDENT_SLICES
    1194       if (((pcSlice->getPPS()->getNumSubstreams() > 1) || bAllowDependence) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
    1195 #else
    1196       if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX))
    1197 #endif
     1309      if (((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
    11981310      {
    11991311        // We'll sync if the TR is available.
     
    12101322             (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
    12111323             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
    1212              ))||
    1213              (true/*bEnforceDependentSliceRestriction*/ &&
    1214              ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
    1215              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getDependentSliceCurStartCUAddr()) ||
    1216              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
    12171324             ))
    12181325           )
    12191326        {
    1220 #if DEPENDENT_SLICES
    1221           if ( (uiCUAddr != 0) && ( pcCUTR->getSCUAddr()+uiMaxParts-1 >= pcSlice->getSliceCurStartCUAddr() ) && bAllowDependence)
    1222           {
    1223             pcSbacCoders[uiSubStrm].loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
    1224           }
    1225 #endif
    12261327          // TR not available.
    12271328        }
     
    12371338    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
    12381339        uiCUAddr!=0 &&                                                                                                                                    // cannot be first CU of picture
    1239 #if DEPENDENT_SLICES
    1240         uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getDependentSliceCurStartCUAddr())/rpcPic->getNumPartInCU() &&
    1241 #endif
     1340        uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceSegmentCurStartCUAddr())/rpcPic->getNumPartInCU() &&
    12421341        uiCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU())     // cannot be first CU of slice
    12431342    {
     
    12581357          }
    12591358          m_pcEntropyCoder->updateContextTables( sliceType, pcSlice->getSliceQp() );
    1260 #if BYTE_ALIGNMENT
    12611359          // Byte-alignment in slice_data() when new tile
    12621360          pcSubstreams[uiSubStrm].writeByteAlignment();
    1263 #else
    1264           pcSubstreams[uiSubStrm].write( 1, 1 );
    1265           pcSubstreams[uiSubStrm].writeAlignZero();
    1266 #endif
    12671361        }
    12681362      }
     
    13131407
    13141408    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );   
    1315 #if !SAO_LUM_CHROMA_ONOFF_FLAGS
    1316     if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getSaoEnabledFlag() )
    1317 #else
    13181409    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    1319 #endif
    1320     {
    1321 #if REMOVE_APS
     1410    {
    13221411      SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1323 #else
    1324       SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
    1325 #endif
    13261412      Int iNumCuInWidth     = saoParam->numCuInWidth;
    13271413      Int iCUAddrInSlice    = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
     
    13461432      }
    13471433      Int addr = pcCU->getAddr();
    1348 #if SAO_SINGLE_MERGE
    13491434      allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0);
    13501435      allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0);
    1351 #if SAO_TYPE_SHARING
    13521436      if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
    1353 #else
    1354       if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] || saoParam->bSaoFlag[2])
    1355 #endif
    13561437      {
    13571438        Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag;
     
    13591440        if (allowMergeLeft)
    13601441        {
    1361 #if SAO_MERGE_ONE_CTX
    13621442          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
    1363 #else
    1364           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMergeLeft(mergeLeft, 0);
    1365 #endif
    13661443        }
    13671444        else
     
    13731450          if (allowMergeUp)
    13741451          {
    1375 #if SAO_MERGE_ONE_CTX
    13761452            m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp);
    1377 #else
    1378             m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMergeUp(mergeUp);
    1379 #endif
    13801453          }
    13811454          else
     
    13871460            for (Int compIdx=0;compIdx<3;compIdx++)
    13881461            {
    1389 #if SAO_TYPE_SHARING
    13901462            if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1]))
    1391 #else
    1392             if( saoParam->bSaoFlag[compIdx])
    1393 #endif
    13941463              {
    1395 #if SAO_TYPE_SHARING
    13961464                m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
    1397 #else
    1398                 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr]);
    1399 #endif
    14001465              }
    14011466            }
     
    14031468        }
    14041469      }
    1405 #else
    1406       m_pcEntropyCoder->encodeSaoUnitInterleaving(0, saoParam->bSaoFlag[0], rx, ry, &(saoParam->saoLcuParam[0][addr]), iCUAddrInSlice, iCUAddrUpInSlice, allowMergeLeft, allowMergeUp);
    1407       m_pcEntropyCoder->encodeSaoUnitInterleaving(1, saoParam->bSaoFlag[1], rx, ry, &(saoParam->saoLcuParam[1][addr]), iCUAddrInSlice, iCUAddrUpInSlice, allowMergeLeft, allowMergeUp);
    1408       m_pcEntropyCoder->encodeSaoUnitInterleaving(2, saoParam->bSaoFlag[2], rx, ry, &(saoParam->saoLcuParam[2][addr]), iCUAddrInSlice, iCUAddrUpInSlice, allowMergeLeft, allowMergeUp);
    1409 #endif
     1470    }
     1471    else if (pcSlice->getSPS()->getUseSAO())
     1472    {
     1473      Int addr = pcCU->getAddr();
     1474      SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
     1475      for (Int cIdx=0; cIdx<3; cIdx++)
     1476      {
     1477        SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]);
     1478        if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma()))
     1479        {
     1480          saoLcuParam->mergeUpFlag   = 0;
     1481          saoLcuParam->mergeLeftFlag = 0;
     1482          saoLcuParam->subTypeIdx    = 0;
     1483          saoLcuParam->typeIdx       = -1;
     1484          saoLcuParam->offset[0]     = 0;
     1485          saoLcuParam->offset[1]     = 0;
     1486          saoLcuParam->offset[2]     = 0;
     1487          saoLcuParam->offset[3]     = 0;
     1488        }
     1489      }
    14101490    }
    14111491#if ENC_DEC_TRACE
    14121492    g_bJustDoIt = g_bEncDecTraceEnable;
    14131493#endif
    1414 #if !REMOVE_ALF
    1415     if( pcSlice->getSPS()->getUseALF())
    1416     {
    1417       for(Int compIdx=0; compIdx< 3; compIdx++)
    1418       {
    1419         if(pcSlice->getAlfEnabledFlag(compIdx))
    1420         {
    1421           m_pcEntropyCoder->encodeAlfCtrlFlag(compIdx, pcCU->getAlfLCUEnabled(compIdx)?1:0);
    1422         }
    1423       }
    1424     }
    1425 #endif
    1426     if ( (m_pcCfg->getSliceMode()!=0 || m_pcCfg->getDependentSliceMode()!=0) &&
     1494    if ( (m_pcCfg->getSliceMode()!=0 || m_pcCfg->getSliceSegmentMode()!=0) &&
    14271495      uiCUAddr == rpcPic->getPicSym()->getCUOrderMap((uiBoundingCUAddr+rpcPic->getNumPartInCU()-1)/rpcPic->getNumPartInCU()-1) )
    14281496    {
    1429       m_pcCuEncoder->encodeCU( pcCU, true );
     1497      m_pcCuEncoder->encodeCU( pcCU );
    14301498    }
    14311499    else
     
    14421510
    14431511       //Store probabilties of second LCU in line into buffer
    1444 #if DEPENDENT_SLICES
    1445        if ( (bAllowDependence || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (uiCol == uiTileLCUX+1) && m_pcCfg->getWaveFrontsynchro())
    1446 #else
    1447       if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX+1))
    1448 #endif
     1512       if ( (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (uiCol == uiTileLCUX+1) && m_pcCfg->getWaveFrontsynchro())
    14491513      {
    14501514        m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
     
    14521516    }
    14531517  }
    1454 #if DEPENDENT_SLICES
    1455   if( bAllowDependence )
     1518  if( depSliceSegmentsEnabled )
    14561519  {
    14571520    if (m_pcCfg->getWaveFrontsynchro())
     
    14611524    CTXMem[0]->loadContexts( m_pcSbacCoder );//ctx end of dep.slice
    14621525  }
    1463 #endif
    14641526#if ADAPTIVE_QP_SELECTION
    14651527  if( m_pcCfg->getUseAdaptQpSelect() )
     
    14701532  if (pcSlice->getPPS()->getCabacInitPresentFlag())
    14711533  {
    1472     if  (pcSlice->getPPS()->getDependentSliceEnabledFlag())
     1534    if  (pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag())
    14731535    {
    14741536      pcSlice->getPPS()->setEncCABACTableIdx( pcSlice->getSliceType() );
     
    14851547 * \returns Updates uiStartCUAddr, uiBoundingCUAddr with appropriate LCU address
    14861548 */
    1487 Void TEncSlice::xDetermineStartAndBoundingCUAddr  ( UInt& uiStartCUAddr, UInt& uiBoundingCUAddr, TComPic*& rpcPic, Bool bEncodeSlice )
     1549Void TEncSlice::xDetermineStartAndBoundingCUAddr  ( UInt& startCUAddr, UInt& boundingCUAddr, TComPic*& rpcPic, Bool bEncodeSlice )
    14881550{
    14891551  TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx());
     
    15031565    switch (m_pcCfg->getSliceMode())
    15041566    {
    1505     case AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE:
     1567    case FIXED_NUMBER_OF_LCU:
    15061568      uiCUAddrIncrement        = m_pcCfg->getSliceArgument();
    15071569      uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU()) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    15081570      break;
    1509     case AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE:
     1571    case FIXED_NUMBER_OF_BYTES:
    15101572      uiCUAddrIncrement        = rpcPic->getNumCUsInFrame();
    15111573      uiBoundingCUAddrSlice    = pcSlice->getSliceCurEndCUAddr();
    15121574      break;
    1513     case AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE:
     1575    case FIXED_NUMBER_OF_TILES:
    15141576      tileIdx                = rpcPic->getPicSym()->getTileIdxMap(
    15151577        rpcPic->getPicSym()->getCUOrderMap(uiStartCUAddrSlice/rpcPic->getNumPartInCU())
     
    15241586          tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
    15251587          tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
    1526 #if REMOVE_FGS
    15271588          uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU());
    1528 #else
    1529           uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU()) >> (m_pcCfg->getSliceGranularity() << 1);
    1530 #endif
    15311589        }
    15321590      }
     
    15391597      break;
    15401598    }
     1599    // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     1600    if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
     1601    {
     1602      uiBoundingCUAddrSlice = min(uiBoundingCUAddrSlice, uiStartCUAddrSlice - (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU())) + (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()));
     1603    }
    15411604    pcSlice->setSliceCurEndCUAddr( uiBoundingCUAddrSlice );
    15421605  }
     
    15461609    switch (m_pcCfg->getSliceMode())
    15471610    {
    1548     case AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE:
     1611    case FIXED_NUMBER_OF_LCU:
    15491612      uiCUAddrIncrement        = m_pcCfg->getSliceArgument();
    15501613      uiBoundingCUAddrSlice    = ((uiStartCUAddrSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU()) ? (uiStartCUAddrSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    15511614      break;
    1552     case AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE:
     1615    case FIXED_NUMBER_OF_TILES:
    15531616      tileIdx                = rpcPic->getPicSym()->getTileIdxMap(
    15541617        rpcPic->getPicSym()->getCUOrderMap(uiStartCUAddrSlice/rpcPic->getNumPartInCU())
     
    15631626          tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
    15641627          tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
    1565 #if REMOVE_FGS
    15661628          uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU());
    1567 #else
    1568           uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU()) >> (m_pcCfg->getSliceGranularity() << 1);
    1569 #endif
    15701629        }
    15711630      }
     
    15781637      break;
    15791638    }
    1580     // set the slice end address to the end of the SCU row if the slice does not start at the beginning of an SCU row
     1639    // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
    15811640    if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
    15821641    {
    1583       uiBoundingCUAddrSlice = uiStartCUAddrSlice - (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU())) + (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU());
     1642      uiBoundingCUAddrSlice = min(uiBoundingCUAddrSlice, uiStartCUAddrSlice - (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU())) + (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()));
    15841643    }
    15851644    pcSlice->setSliceCurEndCUAddr( uiBoundingCUAddrSlice );
     
    15871646
    15881647  Bool tileBoundary = false;
    1589   if ((m_pcCfg->getSliceMode() == AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE || m_pcCfg->getSliceMode() == AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE) &&
     1648  if ((m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_BYTES) &&
    15901649      (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
    15911650  {
     
    16101669
    16111670  // Dependent slice
    1612   UInt uiStartCUAddrDependentSlice, uiBoundingCUAddrDependentSlice;
    1613   uiStartCUAddrDependentSlice    = pcSlice->getDependentSliceCurStartCUAddr();
    1614   uiBoundingCUAddrDependentSlice = uiNumberOfCUsInFrame;
     1671  UInt startCUAddrSliceSegment, boundingCUAddrSliceSegment;
     1672  startCUAddrSliceSegment    = pcSlice->getSliceSegmentCurStartCUAddr();
     1673  boundingCUAddrSliceSegment = uiNumberOfCUsInFrame;
    16151674  if (bEncodeSlice)
    16161675  {
    16171676    UInt uiCUAddrIncrement;
    1618     switch (m_pcCfg->getDependentSliceMode())
    1619     {
    1620     case SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE:
    1621       uiCUAddrIncrement               = m_pcCfg->getDependentSliceArgument();
    1622       uiBoundingCUAddrDependentSlice    = ((uiStartCUAddrDependentSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (uiStartCUAddrDependentSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1677    switch (m_pcCfg->getSliceSegmentMode())
     1678    {
     1679    case FIXED_NUMBER_OF_LCU:
     1680      uiCUAddrIncrement               = m_pcCfg->getSliceSegmentArgument();
     1681      boundingCUAddrSliceSegment    = ((startCUAddrSliceSegment + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (startCUAddrSliceSegment + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    16231682      break;
    1624     case SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE:
     1683    case FIXED_NUMBER_OF_BYTES:
    16251684      uiCUAddrIncrement               = rpcPic->getNumCUsInFrame();
    1626       uiBoundingCUAddrDependentSlice    = pcSlice->getDependentSliceCurEndCUAddr();
     1685      boundingCUAddrSliceSegment    = pcSlice->getSliceSegmentCurEndCUAddr();
    16271686      break;
    1628 #if DEPENDENT_SLICES
    1629     case FIXED_NUMBER_OF_TILES_IN_DEPENDENT_SLICE:
     1687    case FIXED_NUMBER_OF_TILES:
    16301688      tileIdx                = rpcPic->getPicSym()->getTileIdxMap(
    1631         rpcPic->getPicSym()->getCUOrderMap(pcSlice->getDependentSliceCurStartCUAddr()/rpcPic->getNumPartInCU())
     1689        rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceSegmentCurStartCUAddr()/rpcPic->getNumPartInCU())
    16321690        );
    16331691      uiCUAddrIncrement        = 0;
    16341692      tileTotalCount         = (rpcPic->getPicSym()->getNumColumnsMinus1()+1) * (rpcPic->getPicSym()->getNumRowsMinus1()+1);
    16351693
    1636       for(tileIdxIncrement = 0; tileIdxIncrement < m_pcCfg->getDependentSliceArgument(); tileIdxIncrement++)
     1694      for(tileIdxIncrement = 0; tileIdxIncrement < m_pcCfg->getSliceSegmentArgument(); tileIdxIncrement++)
    16371695      {
    16381696        if((tileIdx + tileIdxIncrement) < tileTotalCount)
     
    16401698          tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
    16411699          tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
    1642 #if REMOVE_FGS
    16431700          uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU());
    1644 #else
    1645           uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU()) >> (m_pcCfg->getSliceGranularity() << 1);
    1646 #endif
    1647         }
    1648       }
    1649       uiBoundingCUAddrDependentSlice    = ((uiStartCUAddrDependentSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (uiStartCUAddrDependentSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1701        }
     1702      }
     1703      boundingCUAddrSliceSegment    = ((startCUAddrSliceSegment + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (startCUAddrSliceSegment + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    16501704      break;
    1651 #endif
    16521705    default:
    16531706      uiCUAddrIncrement               = rpcPic->getNumCUsInFrame();
    1654       uiBoundingCUAddrDependentSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1707      boundingCUAddrSliceSegment    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    16551708      break;
    16561709    }
    1657     pcSlice->setDependentSliceCurEndCUAddr( uiBoundingCUAddrDependentSlice );
     1710    // WPP: if a slice segment does not start at the beginning of a CTB row, it must end within the same CTB row
     1711    if (pcSlice->getPPS()->getNumSubstreams() > 1 && (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
     1712    {
     1713      boundingCUAddrSliceSegment = min(boundingCUAddrSliceSegment, startCUAddrSliceSegment - (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU())) + (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()));
     1714    }
     1715    pcSlice->setSliceSegmentCurEndCUAddr( boundingCUAddrSliceSegment );
    16581716  }
    16591717  else
    16601718  {
    16611719    UInt uiCUAddrIncrement;
    1662     switch (m_pcCfg->getDependentSliceMode())
    1663     {
    1664     case SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE:
    1665       uiCUAddrIncrement               = m_pcCfg->getDependentSliceArgument();
    1666       uiBoundingCUAddrDependentSlice    = ((uiStartCUAddrDependentSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (uiStartCUAddrDependentSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1720    switch (m_pcCfg->getSliceSegmentMode())
     1721    {
     1722    case FIXED_NUMBER_OF_LCU:
     1723      uiCUAddrIncrement               = m_pcCfg->getSliceSegmentArgument();
     1724      boundingCUAddrSliceSegment    = ((startCUAddrSliceSegment + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (startCUAddrSliceSegment + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    16671725      break;
    1668 #if DEPENDENT_SLICES
    1669     case FIXED_NUMBER_OF_TILES_IN_DEPENDENT_SLICE:
     1726    case FIXED_NUMBER_OF_TILES:
    16701727      tileIdx                = rpcPic->getPicSym()->getTileIdxMap(
    1671         rpcPic->getPicSym()->getCUOrderMap(pcSlice->getDependentSliceCurStartCUAddr()/rpcPic->getNumPartInCU())
     1728        rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceSegmentCurStartCUAddr()/rpcPic->getNumPartInCU())
    16721729        );
    16731730      uiCUAddrIncrement        = 0;
    16741731      tileTotalCount         = (rpcPic->getPicSym()->getNumColumnsMinus1()+1) * (rpcPic->getPicSym()->getNumRowsMinus1()+1);
    16751732
    1676       for(tileIdxIncrement = 0; tileIdxIncrement < m_pcCfg->getDependentSliceArgument(); tileIdxIncrement++)
     1733      for(tileIdxIncrement = 0; tileIdxIncrement < m_pcCfg->getSliceSegmentArgument(); tileIdxIncrement++)
    16771734      {
    16781735        if((tileIdx + tileIdxIncrement) < tileTotalCount)
     
    16801737          tileWidthInLcu   = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileWidth();
    16811738          tileHeightInLcu  = rpcPic->getPicSym()->getTComTile(tileIdx + tileIdxIncrement)->getTileHeight();
    1682 #if REMOVE_FGS
    16831739          uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU());
    1684 #else
    1685           uiCUAddrIncrement += (tileWidthInLcu * tileHeightInLcu * rpcPic->getNumPartInCU()) >> (m_pcCfg->getSliceGranularity() << 1);
    1686 #endif
    1687         }
    1688       }
    1689       uiBoundingCUAddrDependentSlice    = ((uiStartCUAddrDependentSlice + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (uiStartCUAddrDependentSlice + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1740        }
     1741      }
     1742      boundingCUAddrSliceSegment    = ((startCUAddrSliceSegment + uiCUAddrIncrement) < uiNumberOfCUsInFrame*rpcPic->getNumPartInCU() ) ? (startCUAddrSliceSegment + uiCUAddrIncrement) : uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    16901743      break;
    1691 #endif
    16921744    default:
    16931745      uiCUAddrIncrement               = rpcPic->getNumCUsInFrame();
    1694       uiBoundingCUAddrDependentSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
     1746      boundingCUAddrSliceSegment    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
    16951747      break;
    16961748    }
    1697     pcSlice->setDependentSliceCurEndCUAddr( uiBoundingCUAddrDependentSlice );
    1698   }
    1699   if(uiBoundingCUAddrDependentSlice>uiBoundingCUAddrSlice)
    1700   {
    1701     uiBoundingCUAddrDependentSlice = uiBoundingCUAddrSlice;
    1702     pcSlice->setDependentSliceCurEndCUAddr(uiBoundingCUAddrSlice);
    1703   }
     1749    // WPP: if a slice segment does not start at the beginning of a CTB row, it must end within the same CTB row
     1750    if (pcSlice->getPPS()->getNumSubstreams() > 1 && (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
     1751    {
     1752      boundingCUAddrSliceSegment = min(boundingCUAddrSliceSegment, startCUAddrSliceSegment - (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU())) + (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()));
     1753    }
     1754    pcSlice->setSliceSegmentCurEndCUAddr( boundingCUAddrSliceSegment );
     1755  }
     1756  if ((m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_BYTES) &&
     1757    (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
     1758  {
     1759    UInt lcuEncAddr = (startCUAddrSliceSegment+rpcPic->getNumPartInCU()-1)/rpcPic->getNumPartInCU();
     1760    UInt lcuAddr = rpcPic->getPicSym()->getCUOrderMap(lcuEncAddr);
     1761    UInt startTileIdx = rpcPic->getPicSym()->getTileIdxMap(lcuAddr);
     1762    UInt tileBoundingCUAddrSlice = 0;
     1763    while (lcuEncAddr < uiNumberOfCUsInFrame && rpcPic->getPicSym()->getTileIdxMap(lcuAddr) == startTileIdx)
     1764    {
     1765      lcuEncAddr++;
     1766      lcuAddr = rpcPic->getPicSym()->getCUOrderMap(lcuEncAddr);
     1767    }
     1768    tileBoundingCUAddrSlice = lcuEncAddr*rpcPic->getNumPartInCU();
     1769
     1770    if (tileBoundingCUAddrSlice < boundingCUAddrSliceSegment)
     1771    {
     1772      boundingCUAddrSliceSegment = tileBoundingCUAddrSlice;
     1773      pcSlice->setSliceSegmentCurEndCUAddr( boundingCUAddrSliceSegment );
     1774      tileBoundary = true;
     1775    }
     1776  }
     1777
     1778  if(boundingCUAddrSliceSegment>uiBoundingCUAddrSlice)
     1779  {
     1780    boundingCUAddrSliceSegment = uiBoundingCUAddrSlice;
     1781    pcSlice->setSliceSegmentCurEndCUAddr(uiBoundingCUAddrSlice);
     1782  }
     1783
    17041784  //calculate real dependent slice start address
    1705   UInt uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getDependentSliceCurStartCUAddr()) % rpcPic->getNumPartInCU();
    1706   UInt uiExternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getDependentSliceCurStartCUAddr()) / rpcPic->getNumPartInCU();
     1785  UInt uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurStartCUAddr()) % rpcPic->getNumPartInCU();
     1786  UInt uiExternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurStartCUAddr()) / rpcPic->getNumPartInCU();
    17071787  UInt uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    17081788  UInt uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     
    17221802  UInt uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
    17231803 
    1724   pcSlice->setDependentSliceCurStartCUAddr(uiRealStartAddress);
    1725   uiStartCUAddrDependentSlice=uiRealStartAddress;
     1804  pcSlice->setSliceSegmentCurStartCUAddr(uiRealStartAddress);
     1805  startCUAddrSliceSegment=uiRealStartAddress;
    17261806 
    17271807  //calculate real slice start address
     
    17491829 
    17501830  // Make a joint decision based on reconstruction and dependent slice bounds
    1751   uiStartCUAddr    = max(uiStartCUAddrSlice   , uiStartCUAddrDependentSlice   );
    1752   uiBoundingCUAddr = min(uiBoundingCUAddrSlice, uiBoundingCUAddrDependentSlice);
     1831  startCUAddr    = max(uiStartCUAddrSlice   , startCUAddrSliceSegment   );
     1832  boundingCUAddr = min(uiBoundingCUAddrSlice, boundingCUAddrSliceSegment);
    17531833
    17541834
     
    17571837    // For fixed number of LCU within an entropy and reconstruction slice we already know whether we will encounter end of entropy and/or reconstruction slice
    17581838    // first. Set the flags accordingly.
    1759     if ( (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE && m_pcCfg->getDependentSliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE)
    1760       || (m_pcCfg->getSliceMode()==0 && m_pcCfg->getDependentSliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE)
    1761       || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE && m_pcCfg->getDependentSliceMode()==0)
    1762       || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE && m_pcCfg->getDependentSliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_DEPENDENT_SLICE)
    1763       || (m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE && m_pcCfg->getDependentSliceMode()==0)
    1764 #if DEPENDENT_SLICES
    1765       || (m_pcCfg->getDependentSliceMode()==FIXED_NUMBER_OF_TILES_IN_DEPENDENT_SLICE && m_pcCfg->getSliceMode()==0)
    1766 #endif
     1839    if ( (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
     1840      || (m_pcCfg->getSliceMode()==0 && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
     1841      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==0)
     1842      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
     1843      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==0)
     1844      || (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceMode()==0)
    17671845      || tileBoundary
    17681846)
    17691847    {
    1770       if (uiBoundingCUAddrSlice < uiBoundingCUAddrDependentSlice)
     1848      if (uiBoundingCUAddrSlice < boundingCUAddrSliceSegment)
    17711849      {
    17721850        pcSlice->setNextSlice       ( true );
    1773         pcSlice->setNextDependentSlice( false );
    1774       }
    1775       else if (uiBoundingCUAddrSlice > uiBoundingCUAddrDependentSlice)
     1851        pcSlice->setNextSliceSegment( false );
     1852      }
     1853      else if (uiBoundingCUAddrSlice > boundingCUAddrSliceSegment)
    17761854      {
    17771855        pcSlice->setNextSlice       ( false );
    1778         pcSlice->setNextDependentSlice( true );
     1856        pcSlice->setNextSliceSegment( true );
    17791857      }
    17801858      else
    17811859      {
    17821860        pcSlice->setNextSlice       ( true );
    1783         pcSlice->setNextDependentSlice( true );
     1861        pcSlice->setNextSliceSegment( true );
    17841862      }
    17851863    }
     
    17871865    {
    17881866      pcSlice->setNextSlice       ( false );
    1789       pcSlice->setNextDependentSlice( false );
     1867      pcSlice->setNextSliceSegment( false );
    17901868    }
    17911869  }
    17921870}
    17931871
    1794 #if RECALCULATE_QP_ACCORDING_LAMBDA
    17951872Double TEncSlice::xGetQPValueAccordingToLambda ( Double lambda )
    17961873{
    17971874  return 4.2005*log(lambda) + 13.7122;
    17981875}
    1799 #endif
    18001876
    18011877//! \}
Note: See TracChangeset for help on using the changeset viewer.