Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComSlice.cpp


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (12 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

File:
1 edited

Legend:

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

    r443 r608  
    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 *
     
    3939#include "TComSlice.h"
    4040#include "TComPic.h"
     41#include "TLibEncoder/TEncSbac.h"
     42#include "TLibDecoder/TDecSbac.h"
    4143
    4244//! \ingroup TLibCommon
     
    4446
    4547TComSlice::TComSlice()
    46 #if QC_MVHEVC_B0046
    47 : m_iPPSId                        ( 0  )
    48 #else
    4948: m_iPPSId                        ( -1 )
    50 #endif
    5149, m_iPOC                          ( 0 )
    5250, m_iLastIDR                      ( 0 )
    53 , m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR )
    54 , m_eNalUnitTypeBaseViewMvc       ( NAL_UNIT_INVALID )
     51, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
    5552, m_eSliceType                    ( I_SLICE )
    5653, m_iSliceQp                      ( 0 )
     54, m_dependentSliceSegmentFlag            ( false )
    5755#if ADAPTIVE_QP_SELECTION
    5856, m_iSliceQpBase                  ( 0 )
    5957#endif
    60 , m_bLoopFilterDisable            ( false )
    61 , m_inheritDblParamFromAPS       ( true )
    62 , m_loopFilterBetaOffsetDiv2    ( 0 )
    63 , m_loopFilterTcOffsetDiv2      ( 0 )
    64 , m_bRefPicListModificationFlagLC ( false )
    65 , m_bRefPicListCombinationFlag    ( false )
     58, m_deblockingFilterDisable        ( false )
     59, m_deblockingFilterOverrideFlag   ( false )
     60, m_deblockingFilterBetaOffsetDiv2 ( 0 )
     61, m_deblockingFilterTcOffsetDiv2   ( 0 )
    6662, m_bCheckLDC                     ( false )
    6763, m_iSliceQpDelta                 ( 0 )
    68 , m_pcTexturePic                  ( NULL )
     64, m_iSliceQpDeltaCb               ( 0 )
     65, m_iSliceQpDeltaCr               ( 0 )
    6966, m_iDepth                        ( 0 )
    7067, m_bRefenced                     ( false )
     
    7269, m_pcPPS                         ( NULL )
    7370, m_pcPic                         ( NULL )
    74 , m_uiColDir                      ( 0 )
    75 #if COLLOCATED_REF_IDX
     71, m_colFromL0Flag                 ( 1 )
    7672, m_colRefIdx                     ( 0 )
    77 #endif
    78 #if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
     73#if SAO_CHROMA_LAMBDA
    7974, m_dLambdaLuma( 0.0 )
    8075, m_dLambdaChroma( 0.0 )
     
    8277, m_dLambda                       ( 0.0 )
    8378#endif
    84 , m_bNoBackPredFlag               ( false )
    85 , m_bRefIdxCombineCoding          ( false )
    8679, m_uiTLayer                      ( 0 )
    8780, m_bTLayerSwitchingFlag          ( false )
    88 , m_uiSliceMode                   ( 0 )
    89 , m_uiSliceArgument               ( 0 )
    90 , m_uiSliceCurStartCUAddr         ( 0 )
    91 , m_uiSliceCurEndCUAddr           ( 0 )
    92 , m_uiSliceIdx                    ( 0 )
    93 , m_uiEntropySliceMode            ( 0 )
    94 , m_uiEntropySliceArgument        ( 0 )
    95 , m_uiEntropySliceCurStartCUAddr  ( 0 )
    96 , m_uiEntropySliceCurEndCUAddr    ( 0 )
    97 , m_bNextSlice                    ( false )
    98 , m_bNextEntropySlice             ( false )
    99 , m_uiSliceBits                   ( 0 )
    100 , m_uiEntropySliceCounter         ( 0 )
     81, m_sliceMode                   ( 0 )
     82, m_sliceArgument               ( 0 )
     83, m_sliceCurStartCUAddr         ( 0 )
     84, m_sliceCurEndCUAddr           ( 0 )
     85, m_sliceIdx                    ( 0 )
     86, m_sliceSegmentMode            ( 0 )
     87, m_sliceSegmentArgument        ( 0 )
     88, m_sliceSegmentCurStartCUAddr  ( 0 )
     89, m_sliceSegmentCurEndCUAddr    ( 0 )
     90, m_nextSlice                    ( false )
     91, m_nextSliceSegment             ( false )
     92, m_sliceBits                   ( 0 )
     93, m_sliceSegmentBits         ( 0 )
    10194, m_bFinalized                    ( false )
    102 , m_uiTileByteLocation            ( NULL )
    103 , m_uiTileCount                   ( 0 )
    104 , m_iTileMarkerFlag               ( 0 )
    10595, m_uiTileOffstForMultES          ( 0 )
    10696, m_puiSubstreamSizes             ( NULL )
    107 #if CABAC_INIT_FLAG
    10897, m_cabacInitFlag                 ( false )
    109 #else
    110 , m_cabacInitIdc                 ( -1 )
    111 #endif
     98, m_bLMvdL1Zero                   ( false )
    11299, m_numEntryPointOffsets          ( 0 )
    113 #if LGE_ILLUCOMP_B0045
     100, m_temporalLayerNonReferenceFlag ( false )
     101, m_enableTMVPFlag                ( true )
     102#if H_MV
     103, m_refPicSetInterLayer           ( NULL )
     104, m_layerId                       (0)
     105, m_viewId                        (0)
     106#if H_3D
     107, m_viewIndex                     (0)
     108, m_isDepth                       (false)
     109#endif
     110, m_discardableFlag               (false)
     111, m_interLayerPredEnabledFlag     (false)
     112, m_numInterLayerRefPicsMinus1    (0)
     113, m_interLayerSamplePredOnlyFlag  (false)
     114, m_altCollocatedIndicationFlag   (0)
     115, m_collocatedRefLayerIdx         (0)
     116#if H_3D_IC
    114117, m_bApplyIC                      ( false )
    115 #if SHARP_ILLUCOMP_PARSE_D0060
    116118, m_icSkipParseFlag               ( false )
    117119#endif
    118 #endif
    119 #if INTER_VIEW_VECTOR_SCALING_C0115
    120 , m_bIVScalingFlag                (false)
    121 , m_iViewOrderIdx                 ( 0 )        // will be changed to view_id
    122 #endif
    123 {
    124 #if MERL_VSP_NBDV_RefVId_Fix_D0166
    125   for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
    126     m_pcListDepthPic[iNumCount] =NULL;
    127 #endif
    128   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
    129 
     120#if H_3D
     121, m_depthToDisparityB             ( NULL )
     122, m_depthToDisparityF             ( NULL )
     123#endif
     124#endif
     125{
     126  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
     127 
    130128  initEqualRef();
    131129 
    132   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
    133   {
    134     m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
    135     m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
    136     m_eListIdFromIdxOfLC[iNumCount]=0;
    137     m_iRefIdxFromIdxOfLC[iNumCount]=0;
    138     m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
    139     m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
    140   }   
    141   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF+1; iNumCount++)
    142   {
    143     m_apcRefPicList  [0][iNumCount] = NULL;
    144     m_apcRefPicList  [1][iNumCount] = NULL;
    145     m_aiRefPOCList   [0][iNumCount] = 0;
    146     m_aiRefPOCList   [1][iNumCount] = 0;
    147     m_aiRefViewIdList[0][iNumCount] = 0;
    148     m_aiRefViewIdList[1][iNumCount] = 0;
    149   }
    150   m_bCombineWithReferenceFlag = 0;
    151   resetWpScaling(m_weightPredTable);
    152   resetWpScalingLC(m_weightPredTableLC);
     130  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
     131  {
     132    m_list1IdxToList0Idx[idx] = -1;
     133  }
     134  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
     135  {
     136    m_apcRefPicList [0][iNumCount] = NULL;
     137    m_apcRefPicList [1][iNumCount] = NULL;
     138    m_aiRefPOCList  [0][iNumCount] = 0;
     139    m_aiRefPOCList  [1][iNumCount] = 0;
     140#if H_MV
     141    m_aiRefLayerIdList[0][iNumCount] = 0;
     142    m_aiRefLayerIdList[1][iNumCount] = 0;
     143#endif
     144  }
     145  resetWpScaling();
    153146  initWpAcDcParam();
    154 #if QC_IV_AS_LT_B0046
    155   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF+1; iNumCount++)
    156   {
    157      m_bWasLongTerm[0][iNumCount] = false;
    158      m_bWasLongTerm[1][iNumCount] = false;
     147  m_saoEnabledFlag = false;
     148#if H_MV
     149  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
     150  {
     151   m_interLayerPredLayerIdc[ i ] = 0;
    159152  }
    160153#endif
     
    163156TComSlice::~TComSlice()
    164157{
    165   if (m_uiTileByteLocation)
    166   {
    167     delete [] m_uiTileByteLocation;
    168     m_uiTileByteLocation = NULL;
    169   }
    170158  delete[] m_puiSubstreamSizes;
    171159  m_puiSubstreamSizes = NULL;
     160#if H_3D
     161  for( UInt i = 0; i < getViewIndex(); i++ )
     162  {
     163    if ( m_depthToDisparityB && m_depthToDisparityB[ i ] )
     164      delete[] m_depthToDisparityB [ i ];
     165
     166    if ( m_depthToDisparityF && m_depthToDisparityF[ i ] )
     167      delete[] m_depthToDisparityF [ i ];
     168  }
     169
     170  if ( m_depthToDisparityF )
     171    delete[] m_depthToDisparityF;
     172
     173  m_depthToDisparityF = NULL;
     174
     175  if ( m_depthToDisparityB )
     176    delete[] m_depthToDisparityB;
     177
     178  m_depthToDisparityB = NULL;
     179#endif
    172180}
    173181
     
    178186  m_aiNumRefIdx[1]      = 0;
    179187 
    180   m_uiColDir = 0;
     188  m_colFromL0Flag = 1;
    181189 
    182 #if COLLOCATED_REF_IDX
    183190  m_colRefIdx = 0;
    184 #endif
    185   m_pcTexturePic = NULL;
    186 
    187191  initEqualRef();
    188   m_bNoBackPredFlag = false;
    189   m_bRefIdxCombineCoding = false;
    190   m_bRefPicListCombinationFlag = false;
    191   m_bRefPicListModificationFlagLC = false;
    192192  m_bCheckLDC = false;
    193 
    194   m_aiNumRefIdx[REF_PIC_LIST_C]      = 0;
    195 
    196   m_uiMaxNumMergeCand = MRG_MAX_NUM_CANDS_SIGNALED;
     193  m_iSliceQpDeltaCb = 0;
     194  m_iSliceQpDeltaCr = 0;
     195
     196#if H_3D_IV_MERGE
     197  m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM;
     198#else
     199  m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
     200#endif
    197201
    198202  m_bFinalized=false;
    199203
    200   m_uiTileCount          = 0;
    201 #if CABAC_INIT_FLAG
     204  m_tileByteLocation.clear();
    202205  m_cabacInitFlag        = false;
    203 #endif
    204206  m_numEntryPointOffsets = 0;
    205 #if QC_TMVP_MRG_REFIDX_C0047
    206   m_aiNewRefIdx[0]                  = -1;
    207   m_aiNewRefIdx[1]                  = -1;
    208 #endif
    209 }
    210 
    211 Void TComSlice::initTiles()
    212 {
    213   Int iWidth             = m_pcSPS->getPicWidthInLumaSamples();
    214   Int iHeight            = m_pcSPS->getPicHeightInLumaSamples();
    215   UInt uiWidthInCU       = ( iWidth %g_uiMaxCUWidth  ) ? iWidth /g_uiMaxCUWidth  + 1 : iWidth /g_uiMaxCUWidth;
    216   UInt uiHeightInCU      = ( iHeight%g_uiMaxCUHeight ) ? iHeight/g_uiMaxCUHeight + 1 : iHeight/g_uiMaxCUHeight;
    217   UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
    218 
    219   if (m_uiTileByteLocation==NULL) m_uiTileByteLocation   = new UInt[uiNumCUsInFrame];
    220 }
    221 
     207  m_enableTMVPFlag = true;
     208#if H_3D_TMVP
     209  m_aiAlterRefIdx[0]                  = -1;
     210  m_aiAlterRefIdx[1]                  = -1;
     211#endif
     212}
     213
     214Bool TComSlice::getRapPicFlag()
     215{
     216  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     217      || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
     218      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     219      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     220      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     221      || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
     222}
    222223
    223224/**
     
    269270}
    270271
    271 TComPic* TComSlice::xGetRefPic( TComList<TComPic*>& rcListPic, UInt uiPOC )
     272TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic,
     273                                Int                 poc)
    272274{
    273275  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
     
    275277  while ( iterPic != rcListPic.end() )
    276278  {
    277     if(pcPic->getPOC() == uiPOC)
     279    if(pcPic->getPOC() == poc)
    278280    {
    279281      break;
     
    286288
    287289
    288 TComPic* TComSlice::xGetLongTermRefPic( TComList<TComPic*>& rcListPic, UInt uiPOC )
     290TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
    289291{
    290292  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
    291293  TComPic*                      pcPic = *(iterPic);
    292294  TComPic*                      pcStPic = pcPic;
     295 
     296  Int pocCycle = 1 << getSPS()->getBitsForPOC();
     297  if (!pocHasMsb)
     298  {
     299    poc = poc % pocCycle;
     300  }
     301 
    293302  while ( iterPic != rcListPic.end() )
    294303  {
    295304    pcPic = *(iterPic);
    296     if(pcPic && (pcPic->getPOC()%(1<<getSPS()->getBitsForPOC())) == (uiPOC%(1<<getSPS()->getBitsForPOC())))
     305    if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced())
     306    {
     307      Int picPoc = pcPic->getPOC();
     308      if (!pocHasMsb)
     309      {
     310        picPoc = picPoc % pocCycle;
     311      }
     312     
     313      if (poc == picPoc)
    297314    {
    298315      if(pcPic->getIsLongTerm())
     316      {
    299317        return pcPic;
     318      }
    300319      else
     320      {
    301321        pcStPic = pcPic;
     322      }
    302323      break;
    303324    }
     325    }
    304326
    305327    iterPic++;
    306328  }
     329 
    307330  return  pcStPic;
    308331}
    309332
    310 TComPic* TComSlice::xGetInterViewRefPic( std::vector<TComPic*>& rcListIvPic, UInt uiViewId )
    311 {
    312   TComPic* pcPic = NULL;
    313   for( Int k = 0; k < rcListIvPic.size(); k++ )
    314   {
    315     if( rcListIvPic[k]->getViewId() == uiViewId )
    316     {
    317       pcPic = rcListIvPic[k];
    318       break;
    319     }
    320   }
    321 
    322   assert( pcPic != NULL );
    323   return pcPic;
    324 }
    325 
    326 Int TComSlice::getNumPocTotalCurr()
    327 {
    328   if( m_eSliceType == I_SLICE )
     333Void TComSlice::setRefPOCList       ()
     334{
     335  for (Int iDir = 0; iDir < 2; iDir++)
     336  {
     337    for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
     338    {
     339      m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
     340#if H_MV
     341      m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId();
     342#endif
     343    }
     344  }
     345
     346}
     347
     348Void TComSlice::setList1IdxToList0Idx()
     349{
     350  Int idxL0, idxL1;
     351  for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ )
     352  {
     353    m_list1IdxToList0Idx[idxL1] = -1;
     354    for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ )
     355    {
     356      if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
     357      {
     358        m_list1IdxToList0Idx[idxL1] = idxL0;
     359        break;
     360      }
     361    }
     362  }
     363}
     364#if H_MV
     365Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
     366#else
     367#if FIX1071
     368Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
     369#else
     370Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
     371#endif
     372#endif
     373{
     374#if FIX1071
     375  if (!checkNumPocTotalCurr)
     376#endif
     377  {
     378    if (m_eSliceType == I_SLICE)
     379    {
     380      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
     381      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
     382     
     383      return;
     384    }
     385   
     386#if !H_MV
     387    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
     388    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
     389#endif
     390  }
     391
     392  TComPic*  pcRefPic= NULL;
     393  TComPic*  RefPicSetStCurr0[16];
     394  TComPic*  RefPicSetStCurr1[16];
     395  TComPic*  RefPicSetLtCurr[16];
     396  UInt NumPocStCurr0 = 0;
     397  UInt NumPocStCurr1 = 0;
     398  UInt NumPocLtCurr = 0;
     399  Int i;
     400
     401  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
     402  {
     403    if(m_pcRPS->getUsed(i))
     404    {
     405      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
     406      pcRefPic->setIsLongTerm(0);
     407      pcRefPic->getPicYuvRec()->extendPicBorder();
     408      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
     409      NumPocStCurr0++;
     410      pcRefPic->setCheckLTMSBPresent(false); 
     411    }
     412  }
     413 
     414  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
     415  {
     416    if(m_pcRPS->getUsed(i))
     417    {
     418      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
     419      pcRefPic->setIsLongTerm(0);
     420      pcRefPic->getPicYuvRec()->extendPicBorder();
     421      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
     422      NumPocStCurr1++;
     423      pcRefPic->setCheckLTMSBPresent(false); 
     424    }
     425  }
     426 
     427  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
     428  {
     429    if(m_pcRPS->getUsed(i))
     430    {
     431      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
     432      pcRefPic->setIsLongTerm(1);
     433      pcRefPic->getPicYuvRec()->extendPicBorder();
     434      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
     435      NumPocLtCurr++;
     436    }
     437    if(pcRefPic==NULL)
     438    {
     439      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
     440    }
     441    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
     442  }
     443
     444  // ref_pic_list_init
     445  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
     446  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
     447#if H_MV
     448  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
     449  assert( numPocInterCurr == 0 || getInterRefEnabledInRPLFlag() );
     450  Int numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( );
     451  assert( numPocTotalCurr == getNumRpsCurrTempList() );
     452#else
     453  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
     454#endif
     455#if FIX1071
     456  if (checkNumPocTotalCurr)
     457  {
     458    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
     459#if H_MV
     460    // – If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     461    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     462    if ( getRapPicFlag() && m_layerId == 0 )
     463#else
     464    // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     465    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     466    if (getRapPicFlag())
     467#endif
     468    {
     469      assert(numPocTotalCurr == 0);
     470    }
     471
     472    if (m_eSliceType == I_SLICE)
     473    {
     474      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
     475      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
     476     
     477      return;
     478    }
     479   
     480    assert(numPocTotalCurr > 0);
     481   
     482    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
     483    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
     484  }
     485#endif
     486
     487  Int cIdx = 0;
     488#if H_MV
     489  if ( getInterRefEnabledInRPLFlag() )
     490  { 
     491#endif
     492  for ( i=0; i<NumPocStCurr0; i++, cIdx++)
     493  {
     494    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
     495  }
     496  for ( i=0; i<NumPocStCurr1; i++, cIdx++)
     497  {
     498    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
     499  }
     500  for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
     501  {
     502    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
     503  }
     504#if H_MV
     505  }
     506  for ( i=0; i < getNumActiveRefLayerPics( );  i++, cIdx++)
     507    {
     508    assert( cIdx < MAX_NUM_REF );   
     509      rpsCurrList0[cIdx] = refPicSetInterLayer[i];
     510    }
     511#endif
     512  assert(cIdx == numPocTotalCurr);
     513
     514  if (m_eSliceType==B_SLICE)
     515  {
     516    cIdx = 0;
     517#if H_MV
     518    if ( getInterRefEnabledInRPLFlag() )
     519    { 
     520#endif
     521    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
     522    {
     523      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
     524    }
     525    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
     526    {
     527      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
     528    }
     529    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
     530    {
     531      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
     532    }
     533#if H_MV
     534    }
     535    for ( i=0; i < getNumActiveRefLayerPics( );  i++, cIdx++)
     536      {
     537      assert( cIdx < MAX_NUM_REF );   
     538        rpsCurrList1[cIdx] = refPicSetInterLayer[i];
     539      }
     540#endif
     541    assert(cIdx == numPocTotalCurr);
     542  }
     543
     544  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
     545
     546#if H_MV
     547  Int numPocSt = NumPocStCurr0 + NumPocStCurr1;
     548  assert(  getInterRefEnabledInRPLFlag( ) || numPocSt == 0 );
     549
     550  for (Int li = 0; li < 2; li++)
     551  {
     552    if ( m_eSliceType == P_SLICE && li == 1 )
     553    {
     554      m_aiNumRefIdx[1] = 0;
     555      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
     556    }
     557    else
     558    {
     559      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
     560      {
     561        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li );
     562        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr);
     563
     564        m_apcRefPicList    [li][rIdx] = ( li == 0 )  ? rpsCurrList0[ orgIdx  ] : rpsCurrList1[ orgIdx  ];
     565        m_bIsUsedAsLongTerm[li][rIdx] = ( orgIdx >= numPocSt ) ;
     566      }
     567    }
     568  }
     569#else
     570  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
     571  {
     572    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
     573    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
     574    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
     575    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
     576  }
     577  if ( m_eSliceType != B_SLICE )
     578  {
     579    m_aiNumRefIdx[1] = 0;
     580    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
     581  }
     582  else
     583  {
     584    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
     585    {
     586      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
     587      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
     588      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
     589      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
     590    }
     591  }
     592#endif
     593}
     594
     595Int TComSlice::getNumRpsCurrTempList()
     596{
     597  Int numRpsCurrTempList = 0;
     598
     599  if (m_eSliceType == I_SLICE)
    329600  {
    330601    return 0;
    331602  }
    332 
    333   Int numPocTotalCurr = 0;
    334   for( UInt i = 0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++ )
     603  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
    335604  {
    336605    if(m_pcRPS->getUsed(i))
    337606    {
    338       numPocTotalCurr++;
    339     }
    340   }
    341 
    342   return numPocTotalCurr;
    343 }
    344 
    345 Int TComSlice::getNumPocTotalCurrMvc()
    346 {
    347   if( m_eSliceType == I_SLICE )
    348   {
    349     return 0;
    350   }
    351   return getNumPocTotalCurr() + m_pcSPS->getNumberOfUsableInterViewRefs();
    352 }
    353 
    354 Void TComSlice::setRefPOCnViewListsMvc()
    355 {
    356   for(Int iDir = 0; iDir < 2; iDir++)
    357   {
    358     for(Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
    359     {
    360       m_aiRefPOCList   [iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
    361       m_aiRefViewIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getViewId();
    362     }
    363   }
    364 }
    365 
    366 Void TComSlice::generateCombinedList()
    367 {
    368   if(m_aiNumRefIdx[REF_PIC_LIST_C] > 0)
    369   {
    370     m_aiNumRefIdx[REF_PIC_LIST_C]=0;
    371     for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
    372     {
    373       m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
    374       m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
    375       m_eListIdFromIdxOfLC[iNumCount]=0;
    376       m_iRefIdxFromIdxOfLC[iNumCount]=0;
    377       m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
    378       m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
    379     }
    380 
    381     for (Int iNumRefIdx = 0; iNumRefIdx < MAX_NUM_REF; iNumRefIdx++)
    382     {
    383       if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_0])
    384       {
    385         Bool bTempRefIdxInL2 = true;
    386         for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
    387         {
    388           if( (m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC()    == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC()   ) &&
    389               (m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getViewId() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getViewId())    )
    390           {
    391             m_iRefIdxOfL1FromRefIdxOfL0[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
    392             m_iRefIdxOfL0FromRefIdxOfL1[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
    393             bTempRefIdxInL2 = false;
    394             break;
    395           }
    396         }
    397 
    398         if(bTempRefIdxInL2 == true)
    399         {
    400           m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_0;
    401           m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
    402           m_iRefIdxOfLC[REF_PIC_LIST_0][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
    403         }
    404       }
    405 
    406       if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_1])
    407       {
    408         Bool bTempRefIdxInL2 = true;
    409         for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
    410         {
    411           if( (m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC()    == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC()   ) &&
    412               (m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getViewId() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getViewId())    )
    413           {
    414             m_iRefIdxOfL0FromRefIdxOfL1[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
    415             m_iRefIdxOfL1FromRefIdxOfL0[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
    416             bTempRefIdxInL2 = false;
    417             break;
    418           }
    419         }
    420         if(bTempRefIdxInL2 == true)
    421         {
    422           m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_1;
    423           m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
    424           m_iRefIdxOfLC[REF_PIC_LIST_1][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
    425         }
    426       }
    427     }
    428   }
    429 #if QC_TMVP_MRG_REFIDX_C0047
    430   Int  iCurrPOC = this->getPOC();
    431   for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )//just to get one updated ref idx for merge in each L0/L1 direction, if it is not avaialbe, it is still -1
     607      numRpsCurrTempList++;
     608    }
     609  }
     610#if H_MV
     611  assert( ( numRpsCurrTempList == 0 ) || getInterRefEnabledInRPLFlag() );
     612  numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
     613#endif
     614  return numRpsCurrTempList;
     615}
     616
     617Void TComSlice::initEqualRef()
     618{
     619  for (Int iDir = 0; iDir < 2; iDir++)
     620  {
     621    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
     622    {
     623      for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
     624      {
     625        m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
     626      }
     627    }
     628  }
     629}
     630#if H_3D
     631#if H_3D_TMVP
     632Void TComSlice::generateAlterRefforTMVP()
     633{
     634  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
    432635  {       
    433636    if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0)
    434637        continue;
    435638
    436     Bool bZeroIdxInterViewFlag =  ( this->getRefPic(RefPicList(uiRefListIdx), 0)->getPOC() == iCurrPOC ) ? true : false;
     639    Bool bZeroIdxLtFlag = this->getRefPic(RefPicList(uiRefListIdx), 0)->getIsLongTerm();
    437640    for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ )
    438641    {
    439       if ( (bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() != iCurrPOC ) ||
    440            (!bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() == iCurrPOC ) )
    441       {
    442         this->setNewRefIdx(RefPicList(uiRefListIdx),i);
     642      if ( ( bZeroIdxLtFlag && !this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) ||
     643           (!bZeroIdxLtFlag &&  this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) )
     644      {
     645        this->setAlterRefIdx(RefPicList(uiRefListIdx),i);
    443646        break;
    444647      }
    445648    }
    446649  }
    447 
    448 #endif
    449 }
    450 
    451 Void TComSlice::setRefPicListMvc( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics )
    452 {
    453   if( m_eSliceType == I_SLICE )
    454   {
    455     ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList) );
    456     ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ) );
    457 
    458     return;
    459   }
    460 
    461   TComPic*  pcRefPic;
    462   TComPic*  RefPicSetStCurr0[16];
    463   TComPic*  RefPicSetStCurr1[16];
    464   TComPic*  RefPicSetLtCurr [16];
    465   TComPic*  RefPicSetIvCurr [16];
    466 
    467   UInt NumPocStCurr0 = 0;
    468   UInt NumPocStCurr1 = 0;
    469   UInt NumPocLtCurr  = 0;
    470   UInt NumPocIvCurr  = 0;
    471 
    472   Int i;
    473   // short term negative
    474   for( i = 0; i < m_pcRPS->getNumberOfNegativePictures(); i++ )
    475   {
    476     if( m_pcRPS->getUsed(i) )
    477     {
    478       pcRefPic = xGetRefPic( rcListPic, getPOC() + m_pcRPS->getDeltaPOC(i) );
    479       pcRefPic->setIsLongTerm( 0 );
    480       pcRefPic->getPicYuvRec()->extendPicBorder();
    481       RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
    482       NumPocStCurr0++;
    483     }
    484   }
    485   // short term positive
    486   for( ; i < m_pcRPS->getNumberOfNegativePictures() + m_pcRPS->getNumberOfPositivePictures(); i++ )
    487   {
    488     if( m_pcRPS->getUsed(i) )
    489     {
    490       pcRefPic = xGetRefPic( rcListPic, getPOC() + m_pcRPS->getDeltaPOC(i) );
    491       pcRefPic->setIsLongTerm( 0 );
    492       pcRefPic->getPicYuvRec()->extendPicBorder();
    493       RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
    494       NumPocStCurr1++;
    495     }
    496   }
    497   // long term
    498   for( i = m_pcRPS->getNumberOfNegativePictures() + m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures() - 1; i > m_pcRPS->getNumberOfNegativePictures() + m_pcRPS->getNumberOfPositivePictures() - 1 ; i-- )
    499   {
    500     if( m_pcRPS->getUsed(i) )
    501     {
    502       pcRefPic = xGetLongTermRefPic( rcListPic, m_pcRPS->getPOC(i) );
    503       pcRefPic->setIsLongTerm( 1 );
    504       pcRefPic->getPicYuvRec()->extendPicBorder();
    505       RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
    506       NumPocLtCurr++;
    507     }
    508   }
    509   // inter-view
    510   for( i = 0; i < m_pcSPS->getNumberOfUsableInterViewRefs(); i++ )
    511   {
    512     pcRefPic = xGetInterViewRefPic( rapcInterViewRefPics, getViewId() + m_pcSPS->getUsableInterViewRef(i) );
    513 #if QC_IV_AS_LT_B0046
    514     pcRefPic->setIsLongTerm( 1 );
    515 #else
    516     pcRefPic->setIsLongTerm( 0 );
    517 #endif
    518     pcRefPic->getPicYuvRec()->extendPicBorder();
    519     RefPicSetIvCurr[NumPocIvCurr] = pcRefPic;
    520     NumPocIvCurr++;
    521   }
    522 
    523   // ref_pic_list_init
    524   UInt cIdx = 0;
    525   UInt num_ref_idx_l0_active_minus1 = m_aiNumRefIdx[0] - 1;
    526   UInt num_ref_idx_l1_active_minus1 = m_aiNumRefIdx[1] - 1;
    527 
    528   assert( (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) == getNumPocTotalCurrMvc() );
    529   Int numRpsCurrTempList0 = max( (num_ref_idx_l0_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) );
    530   Int numRpsCurrTempList1 = max( (num_ref_idx_l1_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) );
    531 
    532   assert( numRpsCurrTempList0 <= 16 );
    533   TComPic* refPicListTemp0[16];
    534   assert( numRpsCurrTempList1 <= 16 );
    535   TComPic* refPicListTemp1[16];
    536 
    537   cIdx = 0;
    538   while( cIdx < numRpsCurrTempList0 )
    539   {
    540     for( i = 0; i < NumPocStCurr0 && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetStCurr0[i]; }
    541     for( i = 0; i < NumPocStCurr1 && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetStCurr1[i]; }
    542     for( i = 0; i < NumPocLtCurr  && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetLtCurr [i]; }
    543     for( i = 0; i < NumPocIvCurr  && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetIvCurr [i]; }
    544   }
    545 
    546   cIdx = 0;
    547   while( cIdx < numRpsCurrTempList1 && m_eSliceType == B_SLICE )
    548   {
    549     for( i = 0; i < NumPocStCurr1 && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetStCurr1[i]; }
    550     for( i = 0; i < NumPocStCurr0 && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetStCurr0[i]; }
    551     for( i = 0; i < NumPocLtCurr  && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetLtCurr [i]; }
    552     for( i = 0; i < NumPocIvCurr  && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetIvCurr [i]; }
    553   }
    554 
    555   for( cIdx = 0; cIdx <= num_ref_idx_l0_active_minus1; cIdx ++ )
    556   {
    557     m_apcRefPicList[0][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? refPicListTemp0[ m_RefPicListModification.getRefPicSetIdxL0(cIdx) ] : refPicListTemp0[cIdx];
    558 #if QC_IV_AS_LT_B0046
    559     setWasLongTerm(m_apcRefPicList[0][cIdx]->getIsLongTerm(), REF_PIC_LIST_0, cIdx);
    560 #endif
    561   }
    562   if( m_eSliceType == P_SLICE )
    563   {
    564     m_aiNumRefIdx[1] = 0;
    565     ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]) );
    566   }
    567   else
    568   {
    569     for( cIdx = 0; cIdx <= num_ref_idx_l1_active_minus1; cIdx ++ )
    570     {
    571       m_apcRefPicList[1][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? refPicListTemp1[ m_RefPicListModification.getRefPicSetIdxL1(cIdx) ] : refPicListTemp1[cIdx];
    572 #if QC_IV_AS_LT_B0046
    573       setWasLongTerm(m_apcRefPicList[1][cIdx]->getIsLongTerm(), REF_PIC_LIST_1, cIdx);
    574 #endif
    575     }
    576   }
    577 }
    578 
    579 Void TComSlice::initEqualRef()
    580 {
    581   for (Int iDir = 0; iDir < 2; iDir++)
    582   {
    583     for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
    584     {
    585       for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
    586       {
    587         m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
    588       }
    589     }
    590   }
    591 }
    592 
    593 Void TComSlice::initMultiviewSlice( Int** aaiScale, Int** aaiOffset )
    594 {
     650}
     651#endif
     652Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset )
     653
    595654  if( m_pcSPS->hasCamParInSliceHeader() )
    596   {
    597     UInt uiViewId = m_pcSPS->getViewId();
    598     for( UInt uiBaseViewId = 0; uiBaseViewId < uiViewId; uiBaseViewId++ )
    599     {
    600       m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][     uiViewId ];
    601       m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [     uiViewId ][ uiBaseViewId ];
    602       m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][     uiViewId ];
    603       m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[     uiViewId ][ uiBaseViewId ];
    604     }
    605   }
    606 }
    607 
    608 #if COLLOCATED_REF_IDX
     655  {   
     656    for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < m_viewIndex; uiBaseViewIndex++ )
     657    {
     658      m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][     m_viewIndex ];
     659      m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [     m_viewIndex ][ uiBaseViewIndex ];
     660      m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][     m_viewIndex ];
     661      m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[     m_viewIndex ][ uiBaseViewIndex ];
     662    }
     663  }
     664}
     665#endif
     666
    609667Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic)
    610668{
    611669  Int i;
    612670  TComSlice* curSlice = pic->getSlice(curSliceIdx);
    613   Int currColRefPOC =  curSlice->getRefPOC( RefPicList(curSlice->getColDir()), curSlice->getColRefIdx());
     671  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
    614672  TComSlice* preSlice;
    615673  Int preColRefPOC;
     
    619677    if(preSlice->getSliceType() != I_SLICE)
    620678    {
    621       preColRefPOC  = preSlice->getRefPOC( RefPicList(preSlice->getColDir()), preSlice->getColRefIdx());
     679      preColRefPOC  = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
    622680      if(currColRefPOC != preColRefPOC)
    623681      {
     
    632690  }
    633691}
    634 #endif
    635 Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, TComList<TComPic*>& rcListPic)
     692
     693Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
    636694{
    637695  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
     
    646704    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
    647705    {
     706      if (!pReferencePictureSet->getCheckLTMSBPresent(i))
     707      {
     708        assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA);
     709      }
     710      else
     711      {
    648712      assert(pReferencePictureSet->getPOC(i) >= pocCRA);
    649713    }
    650714  }
    651   if( getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     715  }
     716  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
    652717  {
    653718    pocCRA = getPOC();
    654   }
    655 }
    656 
    657 /** Function for marking the reference pictures when an IDR and CRA is encountered.
    658  * \param pocCRA POC of the CRA picture
     719    prevRAPisBLA = false;
     720  }
     721  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     722  {
     723    pocCRA = getPOC();
     724    prevRAPisBLA = false;
     725  }
     726  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     727         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     728         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
     729  {
     730    pocCRA = getPOC();
     731    prevRAPisBLA = true;
     732  }
     733}
     734
     735/** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered.
     736 * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture
    659737 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
    660738 * \param rcListPic reference to the reference picture list
    661739 * This function marks the reference pictures as "unused for reference" in the following conditions.
    662  * If the nal_unit_type is IDR all pictures in the reference picture list 
    663  * is marked as "unused for reference"
    664  * Otherwise do for the CRA case (non CRA case has no effect since both if conditions below will not be true)
     740 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list 
     741 * are marked as "unused for reference"
     742 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
     743 * Otherwise
    665744 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
    666  *    temporal reference is greater than the temporal reference of the latest CRA picture (pocCRA),
    667  *    mark all reference pictures except the latest CRA picture as "unused for reference" and set
     745 *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA),
     746 *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set
    668747 *    the bRefreshPending flag to false.
    669  *    If the nal_unit_type is CRA, set the bRefreshPending flag to true and pocCRA to the temporal
     748 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
    670749 *    reference of the current picture.
    671750 * Note that the current picture is already placed in the reference list and its marking is not changed.
     
    675754{
    676755  TComPic*                 rpcPic;
    677   UInt uiPOCCurr = getPOC();
    678 
    679   if( getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )  // IDR
     756  Int pocCurr = getPOC();
     757
     758  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     759    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     760    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     761    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     762    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
    680763  {
    681764    // mark all pictures as not used for reference
     
    685768      rpcPic = *(iterPic);
    686769      rpcPic->setCurrSliceIdx(0);
    687       if (rpcPic->getPOC() != uiPOCCurr) rpcPic->getSlice(0)->setReferenced(false);
     770      if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
    688771      iterPic++;
    689772    }
     773    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     774      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     775      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     776    {
     777      pocCRA = pocCurr;
     778    }
    690779  }
    691780  else // CRA or No DR
    692781  {
    693     if (bRefreshPending==true && uiPOCCurr > pocCRA) // CRA reference marking pending
     782    if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
    694783    {
    695784      TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
     
    697786      {
    698787        rpcPic = *(iterPic);
    699         if (rpcPic->getPOC() != uiPOCCurr && rpcPic->getPOC() != pocCRA) rpcPic->getSlice(0)->setReferenced(false);
     788        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
     789        {
     790          rpcPic->getSlice(0)->setReferenced(false);
     791        }
    700792        iterPic++;
    701793      }
    702794      bRefreshPending = false;
    703795    }
    704     if( getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     796    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
    705797    {
    706798      bRefreshPending = true;
    707       pocCRA = uiPOCCurr;
     799      pocCRA = pocCurr;
    708800    }
    709801  }
     
    717809
    718810  m_iPOC                 = pSrc->m_iPOC;
    719   m_viewId               = pSrc->m_viewId;
    720 #if INTER_VIEW_VECTOR_SCALING_C0115   
    721   m_iViewOrderIdx        = pSrc->m_iViewOrderIdx;// will be changed to view_id
    722   m_bIVScalingFlag       = pSrc->m_bIVScalingFlag;
    723 #endif
    724811  m_eNalUnitType         = pSrc->m_eNalUnitType;
    725   m_eNalUnitTypeBaseViewMvc = pSrc->m_eNalUnitTypeBaseViewMvc;
     812#if H_MV
     813  m_layerId              = pSrc->m_layerId;
     814  // GT: Copying of several other values might be be missing here, or is above not necessary?
     815#endif
    726816  m_eSliceType           = pSrc->m_eSliceType;
    727817  m_iSliceQp             = pSrc->m_iSliceQp;
     
    729819  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
    730820#endif
    731   m_bLoopFilterDisable   = pSrc->m_bLoopFilterDisable;
    732   m_inheritDblParamFromAPS = pSrc->m_inheritDblParamFromAPS;
    733   m_loopFilterBetaOffsetDiv2 = pSrc->m_loopFilterBetaOffsetDiv2;
    734   m_loopFilterTcOffsetDiv2 = pSrc->m_loopFilterTcOffsetDiv2;
     821  m_deblockingFilterDisable   = pSrc->m_deblockingFilterDisable;
     822  m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag;
     823  m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2;
     824  m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
    735825 
    736   for (i = 0; i < 3; i++)
     826  for (i = 0; i < 2; i++)
    737827  {
    738828    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
    739829  }
    740830
    741   for (i = 0; i < 2; i++)
    742   {
    743     for (j = 0; j < MAX_NUM_REF_LC; j++)
    744     {
    745        m_iRefIdxOfLC[i][j]  = pSrc->m_iRefIdxOfLC[i][j];
    746     }
    747   }
    748   for (i = 0; i < MAX_NUM_REF_LC; i++)
    749   {
    750     m_eListIdFromIdxOfLC[i] = pSrc->m_eListIdFromIdxOfLC[i];
    751     m_iRefIdxFromIdxOfLC[i] = pSrc->m_iRefIdxFromIdxOfLC[i];
    752     m_iRefIdxOfL1FromRefIdxOfL0[i] = pSrc->m_iRefIdxOfL1FromRefIdxOfL0[i];
    753     m_iRefIdxOfL0FromRefIdxOfL1[i] = pSrc->m_iRefIdxOfL0FromRefIdxOfL1[i];
    754   }
    755   m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC;
    756   m_bRefPicListCombinationFlag    = pSrc->m_bRefPicListCombinationFlag;
     831  for (i = 0; i < MAX_NUM_REF; i++)
     832  {
     833    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
     834  }
    757835  m_bCheckLDC             = pSrc->m_bCheckLDC;
    758836  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
     837  m_iSliceQpDeltaCb      = pSrc->m_iSliceQpDeltaCb;
     838  m_iSliceQpDeltaCr      = pSrc->m_iSliceQpDeltaCr;
    759839  for (i = 0; i < 2; i++)
    760840  {
    761841    for (j = 0; j < MAX_NUM_REF; j++)
    762842    {
    763       m_apcRefPicList  [i][j] = pSrc->m_apcRefPicList  [i][j];
    764       m_aiRefPOCList   [i][j] = pSrc->m_aiRefPOCList   [i][j];
    765       m_aiRefViewIdList[i][j] = pSrc->m_aiRefViewIdList[i][j];
    766     }
    767   } 
     843      m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
     844      m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
     845#if H_MV
     846      m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j];
     847#endif
     848    }
     849  }
     850  for (i = 0; i < 2; i++)
     851  {
     852    for (j = 0; j < MAX_NUM_REF + 1; j++)
     853    {
     854      m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
     855    }
     856  }
    768857  m_iDepth               = pSrc->m_iDepth;
    769858
     
    772861
    773862  // access channel
     863#if H_MV
     864  m_pcVPS                = pSrc->m_pcVPS;
     865#endif
    774866  m_pcSPS                = pSrc->m_pcSPS;
    775867  m_pcPPS                = pSrc->m_pcPPS;
     
    778870
    779871  m_pcPic                = pSrc->m_pcPic;
    780   m_pcAPS                = pSrc->m_pcAPS;
    781   m_iAPSId               = pSrc->m_iAPSId;
    782 
    783   m_uiColDir             = pSrc->m_uiColDir;
    784 #if COLLOCATED_REF_IDX
     872
     873  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
    785874  m_colRefIdx            = pSrc->m_colRefIdx;
    786 #endif
    787 #if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
     875#if SAO_CHROMA_LAMBDA
    788876  m_dLambdaLuma          = pSrc->m_dLambdaLuma;
    789877  m_dLambdaChroma        = pSrc->m_dLambdaChroma;
     
    802890  }
    803891
    804   m_bNoBackPredFlag      = pSrc->m_bNoBackPredFlag;
    805   m_bRefIdxCombineCoding = pSrc->m_bRefIdxCombineCoding;
    806 
    807892  m_uiTLayer                      = pSrc->m_uiTLayer;
    808893  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
    809894
    810   m_uiSliceMode                   = pSrc->m_uiSliceMode;
    811   m_uiSliceArgument               = pSrc->m_uiSliceArgument;
    812   m_uiSliceCurStartCUAddr         = pSrc->m_uiSliceCurStartCUAddr;
    813   m_uiSliceCurEndCUAddr           = pSrc->m_uiSliceCurEndCUAddr;
    814   m_uiSliceIdx                    = pSrc->m_uiSliceIdx;
    815   m_uiEntropySliceMode            = pSrc->m_uiEntropySliceMode;
    816   m_uiEntropySliceArgument        = pSrc->m_uiEntropySliceArgument;
    817   m_uiEntropySliceCurStartCUAddr  = pSrc->m_uiEntropySliceCurStartCUAddr;
    818   m_uiEntropySliceCurEndCUAddr    = pSrc->m_uiEntropySliceCurEndCUAddr;
    819   m_bNextSlice                    = pSrc->m_bNextSlice;
    820   m_bNextEntropySlice             = pSrc->m_bNextEntropySlice;
    821   m_iTileMarkerFlag             = pSrc->m_iTileMarkerFlag;
    822   for ( int e=0 ; e<2 ; e++ )
    823     for ( int n=0 ; n<MAX_NUM_REF ; n++ )
     895  m_sliceMode                   = pSrc->m_sliceMode;
     896  m_sliceArgument               = pSrc->m_sliceArgument;
     897  m_sliceCurStartCUAddr         = pSrc->m_sliceCurStartCUAddr;
     898  m_sliceCurEndCUAddr           = pSrc->m_sliceCurEndCUAddr;
     899  m_sliceIdx                    = pSrc->m_sliceIdx;
     900  m_sliceSegmentMode            = pSrc->m_sliceSegmentMode;
     901  m_sliceSegmentArgument        = pSrc->m_sliceSegmentArgument;
     902  m_sliceSegmentCurStartCUAddr  = pSrc->m_sliceSegmentCurStartCUAddr;
     903  m_sliceSegmentCurEndCUAddr    = pSrc->m_sliceSegmentCurEndCUAddr;
     904  m_nextSlice                    = pSrc->m_nextSlice;
     905  m_nextSliceSegment             = pSrc->m_nextSliceSegment;
     906  for ( Int e=0 ; e<2 ; e++ )
     907  {
     908    for ( Int n=0 ; n<MAX_NUM_REF ; n++ )
     909    {
    824910      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 );
    825 
     911    }
     912  }
    826913  m_saoEnabledFlag = pSrc->m_saoEnabledFlag;
    827 #if LGE_SAO_MIGRATION_D0091
    828914  m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
    829 #else
    830   m_saoInterleavingFlag = pSrc->m_saoInterleavingFlag;
    831   m_saoEnabledFlagCb = pSrc->m_saoEnabledFlagCb;
    832   m_saoEnabledFlagCr = pSrc->m_saoEnabledFlagCr;
    833 #endif
    834 #if CABAC_INIT_FLAG
    835915  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
    836 #endif
    837916  m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
    838917
    839918  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
    840 #if SHARP_ILLUCOMP_PARSE_D0060
     919  m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag;
     920  m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
     921  m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
     922
     923#if H_MV
     924  // Additional slice header syntax elements
     925  m_discardableFlag            = pSrc->m_discardableFlag;
     926  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
     927  m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1;
     928
     929  for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ )
     930  {
     931    m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ];
     932  }
     933 
     934  m_interLayerSamplePredOnlyFlag = pSrc->m_interLayerSamplePredOnlyFlag;
     935  m_altCollocatedIndicationFlag  = pSrc->m_altCollocatedIndicationFlag ;   
     936  m_collocatedRefLayerIdx        = pSrc->m_collocatedRefLayerIdx       ;
     937  m_numActiveMotionPredRefLayers = pSrc->m_numActiveMotionPredRefLayers;
     938
     939  for (Int layer = 0; layer < MAX_NUM_LAYER_IDS; layer++)
     940  {   
     941    m_interLayerPredLayerIdc[layer] = pSrc->m_interLayerPredLayerIdc[layer];
     942  }
     943#endif
     944#if H_3D_IC
    841945  m_bApplyIC = pSrc->m_bApplyIC;
    842946  m_icSkipParseFlag = pSrc->m_icSkipParseFlag;
     
    844948}
    845949
    846 int TComSlice::m_prevPOC = 0;
     950Int TComSlice::m_prevPOC = 0;
     951
    847952/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
    848953 * \param uiTLayer Temporal layer ID of the current slice
     
    853958Void TComSlice::setTLayerInfo( UInt uiTLayer )
    854959{
    855 
    856960  m_uiTLayer = uiTLayer;
    857961}
    858962
    859 #if H0566_TLA_SET_FOR_SWITCHING_POINTS
    860963/** Function for checking if this is a switching-point
    861964*/
    862 Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
     965Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic )
    863966{
    864967  TComPic* rpcPic;
     
    878981  return true;
    879982}
    880 #endif
     983
     984/** Function for checking if this is a STSA candidate
     985 */
     986Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic )
     987{
     988    TComPic* rpcPic;
     989   
     990    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
     991    while ( iterPic != rcListPic.end())
     992    {
     993        rpcPic = *(iterPic++);
     994        if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
     995        {
     996            if(rpcPic->getTLayer() >= getTLayer())
     997            {
     998                return false;
     999            }
     1000        }
     1001    }
     1002    return true;
     1003}
    8811004
    8821005/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
     
    8871010  Int i, isReference;
    8881011
    889   Int j = 0;
    8901012  // loop through all pictures in the reference picture buffer
    8911013  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
    8921014  while ( iterPic != rcListPic.end())
    8931015  {
    894     j++;
    8951016    rpcPic = *(iterPic++);
    8961017
     1018    if(!rpcPic->getSlice( 0 )->isReferenced())
     1019    {
     1020      continue;
     1021    }
     1022
    8971023    isReference = 0;
    898     // loop through all pictures in the Reference Picture Set to see if the picture should be kept as reference picture
     1024    // loop through all pictures in the Reference Picture Set
     1025    // to see if the picture should be kept as reference picture
    8991026    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
    9001027    {
    901 #if QC_IV_AS_LT_B0046
    902        if( rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
    903 #else
    9041028      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
    905 #endif
    9061029      {
    9071030        isReference = 1;
     
    9101033      }
    9111034    }
    912     // long term pictures
    9131035    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
    9141036    {
    915 #if QC_IV_AS_LT_B0046
    916      if( (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
    917 #else
    918       if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
    919 #endif
    920       {
    921         isReference = 1;
    922         rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
    923       }
     1037      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
     1038      {
     1039        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i))
     1040        {
     1041          isReference = 1;
     1042          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
     1043        }
     1044      }
     1045      else
     1046      {
     1047        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
     1048        {
     1049          isReference = 1;
     1050          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
     1051        }
     1052      }
     1053
    9241054    }
    9251055    // mark the picture as "unused for reference" if it is not in
     
    9281058    {           
    9291059      rpcPic->getSlice( 0 )->setReferenced( false );   
     1060      rpcPic->setUsedByCurr(0);
    9301061      rpcPic->setIsLongTerm(0);
    9311062    }
    932   } 
     1063    //check that pictures of higher temporal layers are not used
     1064    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
     1065    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
     1066    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
     1067    {
     1068      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
     1069    }
     1070    //check that pictures marked as temporal layer non-reference pictures are not used for reference
     1071    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
     1072    {
     1073      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false);
     1074    }
     1075  }
    9331076}
    9341077
    9351078/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
    9361079*/
    937 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool outputFlag, Int pocRandomAccess)
     1080Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
    9381081{
    9391082  TComPic* rpcPic;
    940   Int i, isAvailable, j;
     1083  Int i, isAvailable;
    9411084  Int atLeastOneLost = 0;
    9421085  Int atLeastOneRemoved = 0;
     
    9471090  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
    9481091  {
    949     j = 0;
    9501092    isAvailable = 0;
    9511093    // loop through all pictures in the reference picture buffer
     
    9531095    while ( iterPic != rcListPic.end())
    9541096    {
    955       j++;
    9561097      rpcPic = *(iterPic++);
    957       if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
    958       {
    959         isAvailable = 1;
     1098      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
     1099      {
     1100        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
     1101        {
     1102          isAvailable = 1;
     1103        }
     1104      }
     1105      else
     1106      {
     1107        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
     1108        {
     1109          isAvailable = 1;
     1110        }
    9601111      }
    9611112    }
     
    9661117      while ( iterPic != rcListPic.end())
    9671118      {
    968         j++;
    9691119        rpcPic = *(iterPic++);
    9701120
    971         if((rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == (this->getPOC() + pReferencePictureSet->getDeltaPOC(i))%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
     1121        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
     1122        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
     1123        Int refPoc = pReferencePictureSet->getPOC(i);
     1124        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
     1125        {
     1126          curPoc = curPoc % pocCycle;
     1127          refPoc = refPoc % pocCycle;
     1128        }
     1129       
     1130        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
    9721131        {
    9731132          isAvailable = 1;
     
    9851144        if(!pReferencePictureSet->getUsed(i) )
    9861145        {
    987           if(outputFlag)
     1146          if(printErrors)
     1147          {
    9881148            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
     1149          }
    9891150          atLeastOneRemoved = 1;
    9901151        }
    9911152        else
    9921153        {
    993           if(outputFlag)
     1154          if(printErrors)
     1155          {
    9941156            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
     1157          }
    9951158          atLeastOneLost = 1;
    9961159          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
     
    10031166  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
    10041167  {
    1005     j = 0;
    10061168    isAvailable = 0;
    10071169    // loop through all pictures in the reference picture buffer
     
    10091171    while ( iterPic != rcListPic.end())
    10101172    {
    1011       j++;
    10121173      rpcPic = *(iterPic++);
    10131174
     
    10251186        if(!pReferencePictureSet->getUsed(i) )
    10261187        {
    1027           if(outputFlag)
     1188          if(printErrors)
     1189          {
    10281190            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
     1191          }
    10291192          atLeastOneRemoved = 1;
    10301193        }
    10311194        else
    10321195        {
    1033           if(outputFlag)
     1196          if(printErrors)
     1197          {
    10341198            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
     1199          }
    10351200          atLeastOneLost = 1;
    10361201          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
     
    10481213  }
    10491214  else
     1215  {
    10501216    return 0;
     1217  }
    10511218}
    10521219
    10531220/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
    10541221*/
     1222#if FIX1071
     1223Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
     1224#else
    10551225Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
     1226#endif
    10561227{
    10571228  TComPic* rpcPic;
     
    10781249        // and should be added to the explicit Reference Picture Set
    10791250        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
     1251#if FIX1071
     1252        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
     1253#else
    10801254        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
     1255#endif
    10811256        if(pcRPS->getDeltaPOC(k) < 0)
     1257        {
    10821258          nrOfNegativePictures++;
     1259        }
    10831260        else
     1261        {
    10841262          nrOfPositivePictures++;
     1263        }
    10851264        k++;
    10861265      }
     
    11361315}
    11371316
    1138 Void TComSlice::decodingMarkingForNoTMVP( TComList<TComPic*>& rcListPic, Int currentPOC )
    1139 {
    1140   TComList<TComPic*>::iterator it;
    1141   for ( it = rcListPic.begin(); it != rcListPic.end(); it++ )
    1142   {
    1143     if ( (*it)->getSlice(0)->getPOC() != currentPOC )
    1144     {
    1145       (*it)->setUsedForTMVP( false );
    1146     }
    1147   }
    1148 }
    1149 
    11501317/** get AC and DC values for weighted pred
    11511318 * \param *wp
     
    11841351 * \returns Void
    11851352 */
    1186 Void  TComSlice::resetWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
    1187 {
    1188   for ( int e=0 ; e<2 ; e++ )
    1189   {
    1190     for ( int i=0 ; i<MAX_NUM_REF ; i++ )
    1191     {
    1192       for ( int yuv=0 ; yuv<3 ; yuv++ )
    1193       {
    1194         wpScalingParam  *pwp = &(wp[e][i][yuv]);
     1353Void  TComSlice::resetWpScaling()
     1354{
     1355  for ( Int e=0 ; e<2 ; e++ )
     1356  {
     1357    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
     1358    {
     1359      for ( Int yuv=0 ; yuv<3 ; yuv++ )
     1360      {
     1361        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
    11951362        pwp->bPresentFlag      = false;
    11961363        pwp->uiLog2WeightDenom = 0;
     
    12081375Void  TComSlice::initWpScaling()
    12091376{
    1210   initWpScaling(m_weightPredTable);
    1211 }
    1212 
    1213 /** set WP tables
    1214  * \param wpScalingParam
    1215  * \returns Void
    1216  */
    1217 Void  TComSlice::initWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
    1218 {
    1219   for ( int e=0 ; e<2 ; e++ )
    1220   {
    1221     for ( int i=0 ; i<MAX_NUM_REF ; i++ )
    1222     {
    1223       for ( int yuv=0 ; yuv<3 ; yuv++ )
    1224       {
    1225         wpScalingParam  *pwp = &(wp[e][i][yuv]);
    1226         if ( !pwp->bPresentFlag ) {
     1377  for ( Int e=0 ; e<2 ; e++ )
     1378  {
     1379    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
     1380    {
     1381      for ( Int yuv=0 ; yuv<3 ; yuv++ )
     1382      {
     1383        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
     1384        if ( !pwp->bPresentFlag )
     1385        {
    12271386          // Inferring values not present :
    12281387          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
     
    12311390
    12321391        pwp->w      = pwp->iWeight;
    1233         pwp->o      = pwp->iOffset * (1 << (g_uiBitDepth-8));
     1392        Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
     1393        pwp->o      = pwp->iOffset << (bitDepth-8);
    12341394        pwp->shift  = pwp->uiLog2WeightDenom;
    12351395        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
     
    12391399}
    12401400
    1241 /** get WP tables for weighted pred of LC
    1242  * \param iRefIdxLC
    1243  * \param *&wpScalingParam
     1401// ------------------------------------------------------------------------------------------------
     1402// Video parameter set (VPS)
     1403// ------------------------------------------------------------------------------------------------
     1404TComVPS::TComVPS()
     1405: m_VPSId                     (  0)
     1406, m_uiMaxTLayers              (  1)
     1407, m_uiMaxLayers               (  1)
     1408, m_bTemporalIdNestingFlag    (false)
     1409, m_numHrdParameters          (  0)
     1410#if H_MV
     1411, m_maxLayerId             (  0)
     1412#else
     1413, m_maxNuhReservedZeroLayerId (  0)
     1414#endif
     1415, m_hrdParameters             (NULL)
     1416, m_hrdOpSetIdx               (NULL)
     1417, m_cprmsPresentFlag          (NULL)
     1418{
     1419  for( Int i = 0; i < MAX_TLAYER; i++)
     1420  {
     1421    m_numReorderPics[i] = 0;
     1422    m_uiMaxDecPicBuffering[i] = 1;
     1423    m_uiMaxLatencyIncrease[i] = 0;
     1424  }
     1425#if H_MV
     1426  for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ )
     1427  { 
     1428    for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ )
     1429    {
     1430      m_layerIdIncludedFlag[lsIdx][layerId] = false;
     1431    }
     1432  }
     1433
     1434  m_vpsNumberLayerSetsMinus1     = -1;
     1435  m_vpsNumProfileTierLevelMinus1 = -1;
     1436   
     1437  for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++)
     1438  {
     1439    m_profileRefMinus1[ i ] = -1;
     1440  }
     1441   
     1442  m_moreOutputLayerSetsThanDefaultFlag = false;   
     1443  m_numAddOutputLayerSetsMinus1        = -1;   
     1444  m_defaultOneTargetOutputLayerFlag    = false;
     1445 
     1446  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
     1447  {
     1448    m_outputLayerSetIdxMinus1[i]  = -1;
     1449    m_profileLevelTierIdx[i]      = 0;
     1450    for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
     1451    {
     1452      m_outputLayerFlag[i][j] = false;
     1453    }
     1454  }
     1455 
     1456  m_maxOneActiveRefLayerFlag = false;
     1457  m_directDepTypeLenMinus2   = 0;         
     1458 
     1459
     1460  m_avcBaseLayerFlag = false;
     1461  m_splittingFlag    = false;
     1462 
     1463  for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
     1464  {
     1465    m_scalabilityMask[i] = false;
     1466    m_dimensionIdLen [i]  = -1;
     1467  }
     1468
     1469  m_vpsNuhLayerIdPresentFlag = false;
     1470
     1471  for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
     1472  {
     1473    m_vpsProfilePresentFlag   [i] = false;
     1474    m_profileRefMinus1[i] = 0;
     1475    m_outputLayerSetIdxMinus1       [i] = 0;
     1476    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
     1477    {
     1478      m_outputLayerFlag[i][j] = false;
     1479    }
     1480  }
     1481
     1482  for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
     1483  {
     1484    m_layerIdInVps[i] =  (i == 0 ) ? 0 : -1;         
     1485  }
     1486
     1487  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
     1488  {
     1489    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1;
     1490    m_numDirectRefLayers[i] = 0;
     1491    m_maxTidIlRefPicPlus1[i] = -1;
     1492#if H_3D
     1493    m_viewIndex         [i] = -1;
     1494    m_vpsDepthModesFlag [i] = false;
     1495#if H_3D_DIM_DLT
     1496    m_bUseDLTFlag         [i] = false;
     1497   
     1498    // allocate some memory and initialize with default mapping
     1499    m_iNumDepthmapValues[i] = ((1 << g_bitDepthY)-1)+1;
     1500    m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]);
     1501   
     1502    m_iDepthValue2Idx[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
     1503    m_iIdx2DepthValue[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
     1504   
     1505    //default mapping
     1506    for (Int d=0; d<m_iNumDepthmapValues[i]; d++)
     1507    {
     1508      m_iDepthValue2Idx[i][d] = d;
     1509      m_iIdx2DepthValue[i][d] = d;
     1510    }
     1511#endif
     1512#if H_3D_TMVP
     1513    m_ivMvScalingFlag = true;
     1514#endif
     1515#endif
     1516
     1517    for( Int j = 0; j < MAX_NUM_LAYERS; j++ )
     1518    {
     1519      m_directDependencyFlag[i][j] = false;
     1520      m_directDependencyType[i][j] = -1;
     1521      m_refLayerId[i][j]           = -1;
     1522    }
     1523
     1524    for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ )
     1525    {
     1526      m_dimensionId[i][j] = 0;
     1527    }
     1528#if H_3D_ARP
     1529    m_uiUseAdvResPred[i]  = 0;
     1530    m_uiARPStepNum[i]     = 1;
     1531#endif
     1532  }
     1533#if H_3D
     1534  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
     1535  {
     1536#if H_3D_IV_MERGE
     1537    m_ivMvPredFlag         [ i ] = false;
     1538#endif
     1539#if H_3D_VSP
     1540    m_viewSynthesisPredFlag[ i ] = false;
     1541#endif
     1542#if H_3D_NBDV_REF
     1543    m_depthRefinementFlag  [ i ] = false;
     1544#endif
     1545#if LGE_INTER_SDC_E0156
     1546    m_bInterSDCFlag        [ i ] = false;
     1547#endif
     1548  } 
     1549#endif
     1550#endif
     1551}
     1552
     1553TComVPS::~TComVPS()
     1554{
     1555if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
     1556  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
     1557  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
     1558#if H_3D_DIM_DLT
     1559  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
     1560  {
     1561    if ( m_iDepthValue2Idx[i] != 0 )
     1562    {
     1563       xFree( m_iDepthValue2Idx[i] );
     1564       m_iDepthValue2Idx[i] = 0;
     1565    }
     1566
     1567    if ( m_iIdx2DepthValue[i] != 0 )
     1568    {
     1569      xFree( m_iIdx2DepthValue[i] );
     1570      m_iIdx2DepthValue[i] = 0;
     1571
     1572    }
     1573  }
     1574#endif
     1575}
     1576
     1577#if H_3D_DIM_DLT
     1578  Void TComVPS::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues)
     1579  {
     1580    if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only
     1581      return;
     1582   
     1583    // copy idx2DepthValue to internal array
     1584    memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt));
     1585   
     1586    UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
     1587    for(Int p=0; p<=uiMaxDepthValue; p++)
     1588    {
     1589      Int iIdxDown    = 0;
     1590      Int iIdxUp      = iNumDepthValues-1;
     1591      Bool bFound     = false;
     1592     
     1593      // iterate over indices to find lower closest depth
     1594      Int i = 1;
     1595      while(!bFound && i<iNumDepthValues)
     1596      {
     1597        if( m_iIdx2DepthValue[layerIdInVps][i] > p )
     1598        {
     1599          iIdxDown  = i-1;
     1600          bFound    = true;
     1601        }
     1602       
     1603        i++;
     1604      }
     1605      // iterate over indices to find upper closest depth
     1606      i = iNumDepthValues-2;
     1607      bFound = false;
     1608      while(!bFound && i>=0)
     1609      {
     1610        if( m_iIdx2DepthValue[layerIdInVps][i] < p )
     1611        {
     1612          iIdxUp  = i+1;
     1613          bFound    = true;
     1614        }
     1615       
     1616        i--;
     1617      }
     1618     
     1619      // assert monotony
     1620      assert(iIdxDown<=iIdxUp);
     1621     
     1622      // assign closer depth value/idx
     1623      if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) )
     1624      {
     1625        m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown;
     1626      }
     1627      else
     1628      {
     1629        m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp;
     1630      }
     1631     
     1632    }
     1633   
     1634    // update DLT variables
     1635    m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues;
     1636    m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]);
     1637  }
     1638#endif
     1639
     1640#if H_MV
     1641
     1642Bool TComVPS::checkVPSExtensionSyntax()
     1643{
     1644  for( Int layer = 1; layer < getMaxLayers(); layer++ )
     1645  {
     1646    // check layer_id_in_nuh constraint
     1647    assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
     1648  }
     1649  return true;
     1650}
     1651
     1652Int TComVPS::getNumScalabilityTypes()
     1653{
     1654  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
     1655}
     1656
     1657Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
     1658{
     1659  assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES );
     1660  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
     1661
     1662  Int scalIdx = 0;
     1663  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
     1664  {
     1665    scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
     1666  }
     1667
     1668  return scalIdx;
     1669}
     1670
     1671Void TComVPS::setScalabilityMask( UInt val )
     1672{
     1673  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ )
     1674    setScalabilityMask( scalType, ( val & (1 << scalType ) ) != 0 );
     1675}
     1676
     1677Void TComVPS::setRefLayers()
     1678{
     1679  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
     1680  {
     1681    m_numSamplePredRefLayers[ i ] = 0;
     1682    m_numMotionPredRefLayers[ i ] = 0;
     1683    m_numDirectRefLayers[ i ] = 0;
     1684    for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) {
     1685      m_samplePredEnabledFlag[ i ][ j ] = 0;
     1686      m_motionPredEnabledFlag[ i ][ j ] = 0;
     1687      m_refLayerId[ i ][ j ] = 0;
     1688      m_samplePredRefLayerId[ i ][ j ] = 0;
     1689      m_motionPredRefLayerId[ i ][ j ] = 0;
     1690    }
     1691  }
     1692
     1693  for( Int i = 1; i  <= getMaxLayers()- 1; i++ )
     1694  {
     1695    for( Int j = 0; j < i; j++ )
     1696    {
     1697      if( getDirectDependencyFlag(i,j) )
     1698      {
     1699        m_refLayerId[ i ][m_numDirectRefLayers[ i ]++ ] = getLayerIdInNuh( j );
     1700
     1701        m_samplePredEnabledFlag [ i ][ j ]  = ( (   getDirectDependencyType( i , j ) + 1 ) & 1 ) == 1;
     1702        m_numSamplePredRefLayers[ i ]      += m_samplePredEnabledFlag [ i ][ j ] ? 1 : 0;
     1703        m_motionPredEnabledFlag [ i ][ j ]  = ( ( ( getDirectDependencyType( i , j ) + 1 ) & 2 ) >> 1 ) == 1;
     1704        m_numMotionPredRefLayers[ i ]      += m_motionPredEnabledFlag  [ i][ j ] ? 1 : 0;
     1705      }
     1706    }
     1707  }
     1708
     1709  for( Int i = 1, mIdx = 0, sIdx = 0; i <= getMaxLayers()- 1; i++ )
     1710  {   
     1711    for( Int j = 0 ; j < i; j++ )
     1712    {
     1713      if( m_motionPredEnabledFlag[ i ][ j ] )
     1714      {
     1715        m_motionPredRefLayerId[ i ][ mIdx++ ] = getLayerIdInNuh( j );
     1716      }
     1717     
     1718      if( m_samplePredEnabledFlag[ i ][ j ] )
     1719      {
     1720        m_samplePredRefLayerId[ i ][ sIdx++ ] = getLayerIdInNuh( j );
     1721      }
     1722    }
     1723  }
     1724}
     1725
     1726Int TComVPS::getRefLayerId( Int layerIdInVps, Int idx )
     1727{
     1728  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInVps] );     
     1729  Int layerIdInNuh = m_refLayerId[ layerIdInVps ][ idx ];   
     1730  assert ( layerIdInNuh >= 0 );
     1731  return layerIdInNuh;
     1732}
     1733
     1734Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
     1735{
     1736  return getScalabilityMask( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
     1737}
     1738
     1739#if H_3D
     1740Void TComVPS::initViewIndex()
     1741{
     1742  Int viewIdList   [ MAX_NUM_LAYERS ]; // ed. should be changed to MAX_VIEW_ID
     1743  Int viewIndexList[ MAX_NUM_LAYERS ];
     1744  Int numViewIds = 0;
     1745
     1746  for ( Int i = 0 ; i  <  m_uiMaxLayers; i++ )
     1747  {     
     1748    Int currViewId = getViewId( i );
     1749
     1750    Bool viewIdInListFlag = false;
     1751    for ( Int j = 0; j < numViewIds; j ++ )
     1752    {
     1753      viewIdInListFlag  = viewIdInListFlag || ( currViewId  == viewIdList[ j ]  );
     1754    }
     1755
     1756    if ( !viewIdInListFlag )
     1757    {
     1758      viewIdList   [ numViewIds ] = currViewId;
     1759      viewIndexList[ currViewId ] = numViewIds;
     1760
     1761      numViewIds++;
     1762    } 
     1763
     1764    m_viewIndex[ i ] = viewIndexList[ currViewId ];
     1765  }
     1766}
     1767
     1768Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
     1769{
     1770  Int foundlayerId = -1;
     1771
     1772  for (Int layer = 0 ; layer < m_uiMaxLayers; layer++ )
     1773  {
     1774    if( ( getViewIndex( layer ) == viewIndex ) && ( getDepthId( layer ) == ( depthFlag ? 1 : 0 ) )  )
     1775    {
     1776      foundlayerId = layer;
     1777      break;
     1778    }
     1779  }
     1780  assert( foundlayerId != -1 );
     1781
     1782  return getLayerIdInNuh( foundlayerId );
     1783}
     1784
     1785#endif // H_3D
     1786
     1787Int TComVPS::xCeilLog2( Int val )
     1788{
     1789  assert( val > 0 );
     1790  Int ceilLog2 = 0;
     1791  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
     1792  return ceilLog2;
     1793}
     1794
     1795
     1796Int TComVPS::xGetDimBitOffset( Int j )
     1797{
     1798  Int dimBitOffset = 0;
     1799  if ( getSplittingFlag() && j == getNumScalabilityTypes() )
     1800  {
     1801     dimBitOffset = 6;
     1802  }
     1803  else
     1804  {
     1805    for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++)
     1806    {
     1807      dimBitOffset += getDimensionIdLen( dimIdx );
     1808    }
     1809  }
     1810  return dimBitOffset;
     1811}
     1812
     1813Int TComVPS::inferDimensionId( Int i, Int j )
     1814{
     1815    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) );
     1816}
     1817
     1818Int TComVPS::inferLastDimsionIdLenMinus1()
     1819{
     1820  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) );
     1821}
     1822
     1823Int TComVPS::getNumLayersInIdList( Int lsIdx )
     1824{
     1825  assert( lsIdx >= 0 );
     1826  assert( lsIdx <= getVpsNumLayerSetsMinus1() );
     1827  Int numLayersInIdList = 0;
     1828  for (Int layerId = 0; layerId < getVpsMaxLayerId(); layerId++ )
     1829  {
     1830    numLayersInIdList += ( getLayerIdIncludedFlag( lsIdx, layerId ) );
     1831  }
     1832  return numLayersInIdList;
     1833}
     1834#endif // H_MV
     1835
     1836// ------------------------------------------------------------------------------------------------
     1837// Sequence parameter set (SPS)
     1838// ------------------------------------------------------------------------------------------------
     1839
     1840TComSPS::TComSPS()
     1841: m_SPSId                     (  0)
     1842, m_VPSId                     (  0)
     1843, m_chromaFormatIdc           (CHROMA_420)
     1844, m_uiMaxTLayers              (  1)
     1845// Structure
     1846, m_picWidthInLumaSamples     (352)
     1847, m_picHeightInLumaSamples    (288)
     1848, m_log2MinCodingBlockSize    (  0)
     1849, m_log2DiffMaxMinCodingBlockSize (0)
     1850, m_uiMaxCUWidth              ( 32)
     1851, m_uiMaxCUHeight             ( 32)
     1852, m_uiMaxCUDepth              (  3)
     1853, m_bLongTermRefsPresent      (false)
     1854, m_uiQuadtreeTULog2MaxSize   (  0)
     1855, m_uiQuadtreeTULog2MinSize   (  0)
     1856, m_uiQuadtreeTUMaxDepthInter (  0)
     1857, m_uiQuadtreeTUMaxDepthIntra (  0)
     1858// Tool list
     1859, m_usePCM                   (false)
     1860, m_pcmLog2MaxSize            (  5)
     1861, m_uiPCMLog2MinSize          (  7)
     1862#if H_3D_QTLPC
     1863, m_bUseQTL                   (false)
     1864, m_bUsePC                    (false)
     1865#endif
     1866, m_bitDepthY                 (  8)
     1867, m_bitDepthC                 (  8)
     1868, m_qpBDOffsetY               (  0)
     1869, m_qpBDOffsetC               (  0)
     1870, m_useLossless               (false)
     1871, m_uiPCMBitDepthLuma         (  8)
     1872, m_uiPCMBitDepthChroma       (  8)
     1873, m_bPCMFilterDisableFlag     (false)
     1874, m_uiBitsForPOC              (  8)
     1875, m_numLongTermRefPicSPS    (  0) 
     1876, m_uiMaxTrSize               ( 32)
     1877, m_bUseSAO                   (false)
     1878, m_bTemporalIdNestingFlag    (false)
     1879, m_scalingListEnabledFlag    (false)
     1880, m_useStrongIntraSmoothing   (false)
     1881, m_vuiParametersPresentFlag  (false)
     1882, m_vuiParameters             ()
     1883#if H_MV
     1884, m_interViewMvVertConstraintFlag (false)
     1885, m_numIlpRestrictedRefLayers ( 0 )
     1886#endif
     1887#if H_3D
     1888, m_bCamParInSliceHeader      (false)
     1889#endif
     1890{
     1891  for ( Int i = 0; i < MAX_TLAYER; i++ )
     1892  {
     1893    m_uiMaxLatencyIncrease[i] = 0;
     1894    m_uiMaxDecPicBuffering[i] = 1;
     1895    m_numReorderPics[i]       = 0;
     1896  }
     1897  m_scalingList = new TComScalingList;
     1898  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
     1899  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
     1900#if H_MV
     1901  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
     1902  {
     1903    m_minSpatialSegmentOffsetPlus1[ i ] = 0;
     1904    m_ctuBasedOffsetEnabledFlag   [ i ] = false;
     1905    m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
     1906  }
     1907#endif
     1908}
     1909
     1910TComSPS::~TComSPS()
     1911{
     1912  delete m_scalingList;
     1913  m_RPSList.destroy();
     1914}
     1915
     1916Void  TComSPS::createRPSList( Int numRPS )
     1917{
     1918  m_RPSList.destroy();
     1919  m_RPSList.create(numRPS);
     1920}
     1921
     1922Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
     1923{
     1924  if( !getVuiParametersPresentFlag() )
     1925  {
     1926    return;
     1927  }
     1928
     1929  TComVUI *vui = getVuiParameters();
     1930  TComHRD *hrd = vui->getHrdParameters();
     1931
     1932  TimingInfo *timingInfo = vui->getTimingInfo();
     1933  timingInfo->setTimingInfoPresentFlag( true );
     1934  switch( frameRate )
     1935  {
     1936  case 24:
     1937    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
     1938    break;
     1939  case 25:
     1940    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
     1941    break;
     1942  case 30:
     1943    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
     1944    break;
     1945  case 50:
     1946    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
     1947    break;
     1948  case 60:
     1949    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
     1950    break;
     1951  default:
     1952    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
     1953    break;
     1954  }
     1955
     1956  Bool rateCnt = ( bitRate > 0 );
     1957  hrd->setNalHrdParametersPresentFlag( rateCnt );
     1958  hrd->setVclHrdParametersPresentFlag( rateCnt );
     1959
     1960  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
     1961
     1962  if( hrd->getSubPicCpbParamsPresentFlag() )
     1963  {
     1964    hrd->setTickDivisorMinus2( 100 - 2 );                          //
     1965    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
     1966    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
     1967    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
     1968  }
     1969  else
     1970  {
     1971    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
     1972  }
     1973
     1974  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
     1975  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
     1976  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
     1977 
     1978  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
     1979  if( randomAccess )
     1980  {
     1981    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
     1982    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
     1983  }
     1984  else
     1985  {
     1986    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
     1987    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
     1988  }
     1989
     1990/*
     1991   Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
     1992*/
     1993  Int i, j;
     1994  UInt birateValue, cpbSizeValue;
     1995  UInt ducpbSizeValue;
     1996  UInt duBitRateValue = 0;
     1997
     1998  for( i = 0; i < MAX_TLAYER; i ++ )
     1999  {
     2000    hrd->setFixedPicRateFlag( i, 1 );
     2001    hrd->setPicDurationInTcMinus1( i, 0 );
     2002    hrd->setLowDelayHrdFlag( i, 0 );
     2003    hrd->setCpbCntMinus1( i, 0 );
     2004
     2005    birateValue  = bitRate;
     2006    cpbSizeValue = bitRate;                                     // 1 second
     2007    ducpbSizeValue = bitRate/numDU;
     2008    duBitRateValue = bitRate;
     2009    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
     2010    {
     2011      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
     2012      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
     2013      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
     2014      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
     2015
     2016      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
     2017      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
     2018      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
     2019      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
     2020      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
     2021    }
     2022  }
     2023}
     2024const Int TComSPS::m_winUnitX[]={1,2,2,1};
     2025const Int TComSPS::m_winUnitY[]={1,2,1,1};
     2026
     2027TComPPS::TComPPS()
     2028: m_PPSId                       (0)
     2029, m_SPSId                       (0)
     2030, m_picInitQPMinus26            (0)
     2031, m_useDQP                      (false)
     2032, m_bConstrainedIntraPred       (false)
     2033, m_bSliceChromaQpFlag          (false)
     2034, m_pcSPS                       (NULL)
     2035, m_uiMaxCuDQPDepth             (0)
     2036, m_uiMinCuDQPSize              (0)
     2037, m_chromaCbQpOffset            (0)
     2038, m_chromaCrQpOffset            (0)
     2039, m_numRefIdxL0DefaultActive    (1)
     2040, m_numRefIdxL1DefaultActive    (1)
     2041, m_TransquantBypassEnableFlag  (false)
     2042, m_useTransformSkip             (false)
     2043, m_dependentSliceSegmentsEnabledFlag    (false)
     2044, m_tilesEnabledFlag               (false)
     2045, m_entropyCodingSyncEnabledFlag   (false)
     2046, m_loopFilterAcrossTilesEnabledFlag  (true)
     2047, m_uniformSpacingFlag           (0)
     2048, m_iNumColumnsMinus1            (0)
     2049, m_puiColumnWidth               (NULL)
     2050, m_iNumRowsMinus1               (0)
     2051, m_puiRowHeight                 (NULL)
     2052, m_iNumSubstreams             (1)
     2053, m_signHideFlag(0)
     2054, m_cabacInitPresentFlag        (false)
     2055, m_encCABACTableIdx            (I_SLICE)
     2056, m_sliceHeaderExtensionPresentFlag    (false)
     2057, m_loopFilterAcrossSlicesEnabledFlag (false)
     2058, m_listsModificationPresentFlag(  0)
     2059, m_numExtraSliceHeaderBits(0)
     2060{
     2061  m_scalingList = new TComScalingList;
     2062}
     2063
     2064TComPPS::~TComPPS()
     2065{
     2066  if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 )
     2067  {
     2068    if (m_puiColumnWidth) delete [] m_puiColumnWidth;
     2069    m_puiColumnWidth = NULL;
     2070  }
     2071  if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 )
     2072  {
     2073    if (m_puiRowHeight) delete [] m_puiRowHeight;
     2074    m_puiRowHeight = NULL;
     2075  }
     2076  delete m_scalingList;
     2077}
     2078
     2079#if H_3D
     2080Void
     2081TComSPS::initCamParaSPS( UInt uiViewIndex, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
     2082{
     2083  AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); 
     2084 
     2085  m_uiCamParPrecision     = ( uiViewIndex ? uiCamParPrecision : 0 );
     2086  m_bCamParInSliceHeader  = ( uiViewIndex ? bCamParSlice  : false );
     2087  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
     2088  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
     2089
     2090  if( !m_bCamParInSliceHeader )
     2091  {
     2092    for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
     2093    {
     2094      m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][     uiViewIndex ];
     2095      m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [     uiViewIndex ][ uiBaseViewIndex ];
     2096      m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][     uiViewIndex ];
     2097      m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[     uiViewIndex ][ uiBaseViewIndex ];
     2098    }
     2099  }
     2100}
     2101#endif
     2102TComReferencePictureSet::TComReferencePictureSet()
     2103: m_numberOfPictures (0)
     2104, m_numberOfNegativePictures (0)
     2105, m_numberOfPositivePictures (0)
     2106, m_numberOfLongtermPictures (0)
     2107, m_interRPSPrediction (0)
     2108, m_deltaRIdxMinus1 (0)   
     2109, m_deltaRPS (0)
     2110, m_numRefIdc (0)
     2111{
     2112  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
     2113  ::memset( m_POC, 0, sizeof(m_POC) );
     2114  ::memset( m_used, 0, sizeof(m_used) );
     2115  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
     2116}
     2117
     2118TComReferencePictureSet::~TComReferencePictureSet()
     2119{
     2120}
     2121
     2122Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
     2123{
     2124  m_used[bufferNum] = used;
     2125}
     2126
     2127Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
     2128{
     2129  m_deltaPOC[bufferNum] = deltaPOC;
     2130}
     2131
     2132Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
     2133{
     2134  m_numberOfPictures = numberOfPictures;
     2135}
     2136
     2137Int TComReferencePictureSet::getUsed(Int bufferNum)
     2138{
     2139  return m_used[bufferNum];
     2140}
     2141
     2142Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
     2143{
     2144  return m_deltaPOC[bufferNum];
     2145}
     2146
     2147Int TComReferencePictureSet::getNumberOfPictures()
     2148{
     2149  return m_numberOfPictures;
     2150}
     2151
     2152Int TComReferencePictureSet::getPOC(Int bufferNum)
     2153{
     2154  return m_POC[bufferNum];
     2155}
     2156
     2157Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
     2158{
     2159  m_POC[bufferNum] = POC;
     2160}
     2161
     2162Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
     2163{
     2164  return m_bCheckLTMSB[bufferNum];
     2165}
     2166
     2167Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
     2168{
     2169  m_bCheckLTMSB[bufferNum] = b;
     2170}
     2171
     2172/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
     2173 * \param uiBufferNum
     2174 * \param iRefIdc
    12442175 * \returns Void
    12452176 */
    1246 Void TComSlice::getWpScalingLC( Int iRefIdx, wpScalingParam *&wp )
    1247 {
    1248   wp = m_weightPredTableLC[iRefIdx];
    1249 }
    1250 /** reset Default WP tables settings for LC : no weight.
    1251  * \param wpScalingParam
     2177Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
     2178{
     2179  m_refIdc[bufferNum] = refIdc;
     2180}
     2181
     2182/** get the reference idc value at uiBufferNum
     2183 * \param uiBufferNum
     2184 * \returns Int
     2185 */
     2186Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
     2187{
     2188  return m_refIdc[bufferNum];
     2189}
     2190
     2191/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
     2192 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
     2193 *  +ve values are in increasing order.
    12522194 * \returns Void
    12532195 */
    1254 Void TComSlice::resetWpScalingLC(wpScalingParam  wp[2*MAX_NUM_REF][3])
    1255 {
    1256   for ( int i=0 ; i<2*MAX_NUM_REF ; i++ )
    1257   {
    1258     for ( int yuv=0 ; yuv<3 ; yuv++ )
    1259     {
    1260       wpScalingParam  *pwp = &(wp[i][yuv]);
    1261       pwp->bPresentFlag      = false;
    1262       pwp->uiLog2WeightDenom = 0;
    1263       pwp->uiLog2WeightDenom = 0;
    1264       pwp->iWeight           = 1;
    1265       pwp->iOffset           = 0;
    1266     }
    1267   }
    1268 }
    1269 /** set current WP tables settings for LC
     2196Void TComReferencePictureSet::sortDeltaPOC()
     2197{
     2198  // sort in increasing order (smallest first)
     2199  for(Int j=1; j < getNumberOfPictures(); j++)
     2200  {
     2201    Int deltaPOC = getDeltaPOC(j);
     2202    Bool used = getUsed(j);
     2203    for (Int k=j-1; k >= 0; k--)
     2204    {
     2205      Int temp = getDeltaPOC(k);
     2206      if (deltaPOC < temp)
     2207      {
     2208        setDeltaPOC(k+1, temp);
     2209        setUsed(k+1, getUsed(k));
     2210        setDeltaPOC(k, deltaPOC);
     2211        setUsed(k, used);
     2212      }
     2213    }
     2214  }
     2215  // flip the negative values to largest first
     2216  Int numNegPics = getNumberOfNegativePictures();
     2217  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
     2218  {
     2219    Int deltaPOC = getDeltaPOC(j);
     2220    Bool used = getUsed(j);
     2221    setDeltaPOC(j, getDeltaPOC(k));
     2222    setUsed(j, getUsed(k));
     2223    setDeltaPOC(k, deltaPOC);
     2224    setUsed(k, used);
     2225  }
     2226}
     2227
     2228/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
     2229 *  A "*" is added to the deltaPOC value if it is Used bu current.
    12702230 * \returns Void
    12712231 */
    1272 Void TComSlice::setWpParamforLC()
    1273 {
    1274   for ( Int iRefIdx=0 ; iRefIdx<getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ )
    1275   {
    1276     RefPicList eRefPicList = (RefPicList)getListIdFromIdxOfLC(iRefIdx);
    1277     Int iCombRefIdx = getRefIdxFromIdxOfLC(iRefIdx);
    1278 
    1279     wpScalingParam  *wp_src, *wp_dst;
    1280     getWpScalingLC(iRefIdx, wp_src);
    1281     getWpScaling(eRefPicList, iCombRefIdx, wp_dst);
    1282     copyWPtable(wp_src, wp_dst);
    1283 
    1284     if(eRefPicList == REF_PIC_LIST_0)
    1285     {
    1286       Int iRefIdxL1 = getRefIdxOfL1FromRefIdxOfL0(iCombRefIdx);
    1287       if(iRefIdxL1 >= 0)
    1288       {
    1289         getWpScaling(REF_PIC_LIST_1, iRefIdxL1, wp_dst);
    1290         copyWPtable(wp_src, wp_dst);
    1291       }
    1292     }
    1293     if(eRefPicList == REF_PIC_LIST_1)
    1294     {
    1295       Int iRefIdxL0 = getRefIdxOfL0FromRefIdxOfL1(iCombRefIdx);
    1296       if(iRefIdxL0 >= 0)
    1297       {
    1298         getWpScaling(REF_PIC_LIST_0, iRefIdxL0, wp_dst);
    1299         copyWPtable(wp_src, wp_dst);
    1300       }
    1301     }
    1302   }
    1303   initWpScaling();
    1304 }
    1305 /** copy source WP tables to destination table for LC
    1306  * \param wpScalingParam *&wp_src : source
    1307  * \param wpScalingParam *&wp_dst : destination
    1308  * \returns Void
    1309  */
    1310 Void TComSlice::copyWPtable(wpScalingParam *&wp_src, wpScalingParam *&wp_dst)
    1311 {
    1312   for ( Int iComp = 0; iComp < 3; iComp++ )
    1313   {
    1314     wp_dst[iComp].uiLog2WeightDenom = (iComp==0) ? wp_src[0].uiLog2WeightDenom : wp_src[1].uiLog2WeightDenom;
    1315     wp_dst[iComp].bPresentFlag = wp_src[iComp].bPresentFlag;
    1316     wp_dst[iComp].iWeight = wp_src[iComp].iWeight;
    1317     wp_dst[iComp].iOffset = wp_src[iComp].iOffset;
    1318   }
    1319 }
    1320 
    1321 #if LGE_ILLUCOMP_B0045
     2232Void TComReferencePictureSet::printDeltaPOC()
     2233{
     2234  printf("DeltaPOC = { ");
     2235  for(Int j=0; j < getNumberOfPictures(); j++)
     2236  {
     2237    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
     2238  }
     2239  if (getInterRPSPrediction())
     2240  {
     2241    printf("}, RefIdc = { ");
     2242    for(Int j=0; j < getNumRefIdc(); j++)
     2243    {
     2244      printf("%d ", getRefIdc(j));
     2245    }
     2246  }
     2247  printf("}\n");
     2248}
     2249
     2250TComRPSList::TComRPSList()
     2251:m_referencePictureSets (NULL)
     2252{
     2253}
     2254
     2255TComRPSList::~TComRPSList()
     2256{
     2257}
     2258
     2259Void TComRPSList::create( Int numberOfReferencePictureSets)
     2260{
     2261  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
     2262  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
     2263}
     2264
     2265Void TComRPSList::destroy()
     2266{
     2267  if (m_referencePictureSets)
     2268  {
     2269    delete [] m_referencePictureSets;
     2270  }
     2271  m_numberOfReferencePictureSets = 0;
     2272  m_referencePictureSets = NULL;
     2273}
     2274
     2275
     2276
     2277TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
     2278{
     2279  return &m_referencePictureSets[referencePictureSetNum];
     2280}
     2281
     2282Int TComRPSList::getNumberOfReferencePictureSets()
     2283{
     2284  return m_numberOfReferencePictureSets;
     2285}
     2286
     2287Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
     2288{
     2289  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
     2290}
     2291
     2292TComRefPicListModification::TComRefPicListModification()
     2293: m_bRefPicListModificationFlagL0 (false)
     2294, m_bRefPicListModificationFlagL1 (false)
     2295{
     2296  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
     2297  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
     2298}
     2299
     2300TComRefPicListModification::~TComRefPicListModification()
     2301{
     2302}
     2303
     2304TComScalingList::TComScalingList()
     2305{
     2306  m_useTransformSkip = false;
     2307  init();
     2308}
     2309TComScalingList::~TComScalingList()
     2310{
     2311  destroy();
     2312}
     2313
     2314/** set default quantization matrix to array
     2315*/
     2316Void TComSlice::setDefaultScalingList()
     2317{
     2318  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     2319  {
     2320    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
     2321    {
     2322      getScalingList()->processDefaultMarix(sizeId, listId);
     2323    }
     2324  }
     2325}
     2326/** check if use default quantization matrix
     2327 * \returns true if use default quantization matrix in all size
     2328*/
     2329Bool TComSlice::checkDefaultScalingList()
     2330{
     2331  UInt defaultCounter=0;
     2332
     2333  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     2334  {
     2335    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
     2336    {
     2337      if( !memcmp(getScalingList()->getScalingListAddress(sizeId,listId), getScalingList()->getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
     2338     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
     2339      {
     2340        defaultCounter++;
     2341      }
     2342    }
     2343  }
     2344  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
     2345}
     2346
     2347#if H_MV
     2348Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
     2349{
     2350  refPicSetInterLayer.clear();
     2351
     2352  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
     2353  {
     2354    Int layerIdRef = getRefPicLayerId( i );
     2355    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ;
     2356    assert ( picRef != 0 );
     2357
     2358    picRef->getPicYuvRec()->extendPicBorder();
     2359    picRef->setIsLongTerm( true );       
     2360    picRef->getSlice(0)->setReferenced( true );       
     2361
     2362    // Consider to check here:
     2363    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer that is a RASL picture. "
     2364    refPicSetInterLayer.push_back( picRef );
     2365  }
     2366}
     2367
     2368Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer )
     2369{
     2370  // Mark as shortterm
     2371  for ( Int i = 0; i < refPicSetInterLayer.size(); i++ )
     2372  {
     2373    refPicSetInterLayer[i]->setIsLongTerm( false );
     2374  }
     2375}
     2376
     2377Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
     2378{
     2379  // Fill targetDecLayerIdSet with all layers if empty.
     2380  if (targetDecLayerIdSet.size() == 0 )   
     2381  {
     2382    for ( Int layerIdInVps = 0; layerIdInVps < vps->getMaxLayers(); layerIdInVps++ )
     2383    {
     2384      targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) );
     2385    }
     2386  }     
     2387
     2388  Int numTargetDecLayers = (Int) targetDecLayerIdSet.size();
     2389  Int latestDecIdx;
     2390  for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++)
     2391  {
     2392    if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId )
     2393      break;
     2394  }       
     2395
     2396  for( Int i = 0; i <= latestDecIdx; i++ )
     2397  {
     2398    if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) )
     2399    {
     2400      TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc );
     2401      if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() )
     2402      {
     2403        Bool remainingInterLayerReferencesFlag = false;
     2404        for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
     2405        {
     2406          TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS();
     2407          if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
     2408          {
     2409            Int targetDecLayerIdinVPS = vpsSlice->getLayerIdInVps( targetDecLayerIdSet[ j ] );
     2410            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdinVPS ); k++ )
     2411              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdinVPS,  k  ) )
     2412                remainingInterLayerReferencesFlag = true;
     2413          }
     2414        }
     2415        if( !remainingInterLayerReferencesFlag )
     2416          pcPic->getSlice(0)->setReferenced( false );                   
     2417      }
     2418    }
     2419  }
     2420}
     2421
     2422Void TComSlice::xPrintRefPicList()
     2423
     2424  for ( Int li = 0; li < 2; li++)
     2425  {   
     2426    std::cout << std::endl << "RefPicListL" <<  li << ":" << std::endl;
     2427    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
     2428    {     
     2429      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
     2430       
     2431      m_apcRefPicList[li][rIdx]->print( false );
     2432    }
     2433  }
     2434}
     2435Int TComSlice::xCeilLog2( Int val )
     2436{
     2437  assert( val > 0 );
     2438  Int ceilLog2 = 0;
     2439  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
     2440  return ceilLog2;
     2441}
     2442
     2443Void TComSlice::markCurrPic( TComPic* currPic )
     2444{
     2445  if ( !currPic->getSlice(0)->getDiscardableFlag() )
     2446  {
     2447    currPic->getSlice(0)->setReferenced( true ) ;
     2448    currPic->setIsLongTerm( false );
     2449  }
     2450  else
     2451  {
     2452    currPic->getSlice(0)->setReferenced( false ) ;
     2453  }
     2454}
     2455
     2456Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer )
     2457{
     2458  m_refPicSetInterLayer = refPicSetInterLayer;
     2459}
     2460
     2461TComPic* TComSlice::getPicFromRefPicSetInterLayer( Int layerId )
     2462{
     2463  assert( m_refPicSetInterLayer != 0 );
     2464  assert( (*m_refPicSetInterLayer).size() == getNumActiveRefLayerPics() );
     2465  TComPic* pcPic = NULL;
     2466  for ( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
     2467  {
     2468    if ((*m_refPicSetInterLayer)[ i ]->getLayerId() == layerId)
     2469    {
     2470      pcPic = (*m_refPicSetInterLayer)[ i ];
     2471    }
     2472  }
     2473  assert(pcPic != NULL);
     2474  return pcPic;
     2475}
     2476
     2477Int TComSlice::getNumActiveRefLayerPics()
     2478{
     2479  Int numActiveRefLayerPics;
     2480
     2481  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
     2482  {
     2483    numActiveRefLayerPics = 0;
     2484  }
     2485  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
     2486  {
     2487    numActiveRefLayerPics = 1;
     2488  }
     2489  else
     2490  {
     2491    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1;
     2492  }
     2493  return numActiveRefLayerPics;
     2494}
     2495
     2496Int TComSlice::getRefPicLayerId( Int i )
     2497{
     2498  return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
     2499}
     2500
     2501Void TComSlice::setActiveMotionPredRefLayers()
     2502{
     2503  Int j = 0;
     2504  for( Int i = 0; i < getNumActiveRefLayerPics(); i++)
     2505  {
     2506    if( getVPS()->getMotionPredEnabledFlag( getLayerIdInVps(), getInterLayerPredLayerIdc( i ))  )
     2507    {
     2508      m_activeMotionPredRefLayerId[ j++ ] = getVPS()->getRefLayerId( getLayerIdInVps(), i );
     2509    }
     2510  }
     2511  m_numActiveMotionPredRefLayers = j;
     2512
     2513  // Consider incorporating bitstream conformance tests on derived variables here.
     2514}
     2515
     2516Bool TComSlice::getInterRefEnabledInRPLFlag()
     2517{
     2518  Bool interRefEnabledInRPLFlag;
     2519  if ( getVPS()->getNumSamplePredRefLayers( getLayerIdInVps() ) > 0 && getNumActiveRefLayerPics() > 0 )
     2520  {
     2521    interRefEnabledInRPLFlag = !getInterLayerSamplePredOnlyFlag();
     2522  }
     2523  else
     2524  {
     2525    interRefEnabledInRPLFlag = 1;
     2526  }
     2527  return interRefEnabledInRPLFlag;
     2528}
     2529#if H_3D_ARP
     2530Void TComSlice::setARPStepNum()                                 
     2531{
     2532  Bool bAllIvRef = true;
     2533
     2534  if(!getVPS()->getUseAdvRP(getLayerId()))
     2535  {
     2536    m_nARPStepNum = 0;
     2537  }
     2538  else
     2539  {
     2540    for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
     2541    {
     2542      RefPicList  eRefPicList = RefPicList( iRefListId );
     2543      Int iNumRefIdx = getNumRefIdx(eRefPicList);
     2544     
     2545      if( iNumRefIdx <= 0 )
     2546      {
     2547        continue;
     2548      }
     2549
     2550      for ( Int i = 0; i < iNumRefIdx; i++ )
     2551      {
     2552        if( getRefPic( eRefPicList, i)->getPOC() != getPOC() )
     2553        {
     2554          bAllIvRef = false;
     2555          break;
     2556        }
     2557      }
     2558
     2559      if( bAllIvRef == false ) { break; }
     2560    }
     2561    m_nARPStepNum = !bAllIvRef ? getVPS()->getARPStepNum(getLayerId()) : 0;
     2562  }
     2563}
     2564#endif
     2565#if H_3D_IC
    13222566Void TComSlice::xSetApplyIC()
    13232567{
    1324   Int iMaxPelValue = (1<<g_uiBitDepth);
     2568  Int iMaxPelValue = ( 1 << g_bitDepthY );
    13252569  Int *aiRefOrgHist;
    13262570  Int *aiCurrHist;
    1327   aiRefOrgHist = new Int;
    1328   aiCurrHist   = new Int;
    1329   aiRefOrgHist = (Int *)xMalloc(Int,iMaxPelValue);
    1330   aiCurrHist   = (Int *)xMalloc(Int,iMaxPelValue);
    1331   memset(aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
    1332   memset(aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
     2571  aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue );
     2572  aiCurrHist   = (Int *) xMalloc( Int,iMaxPelValue );
     2573  memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
     2574  memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
    13332575  // Reference Idx Number
    13342576  Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 );
     
    13452587  // Get InterView Reference picture
    13462588  // !!!!! Assume only one Interview Reference Picture in L0
    1347   for (Int i = 0; i < iNumRefIdx; i++)
    1348   {
    1349     pcRefPic = getRefPic( REF_PIC_LIST_0, i);
    1350     if (pcRefPic != NULL)
    1351     {
    1352       // Current Picture
    1353       if (pcCurrPic->getViewId() != pcRefPic->getViewId())
     2589  for ( Int i = 0; i < iNumRefIdx; i++ )
     2590  {
     2591    pcRefPic = getRefPic( REF_PIC_LIST_0, i );
     2592    if ( pcRefPic != NULL )
     2593    {
     2594      if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
    13542595      {
    13552596        pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
     
    13572598    }
    13582599  }
    1359   if (pcRefPicYuvOrg != NULL)
     2600
     2601  if ( pcRefPicYuvOrg != NULL )
    13602602  {
    13612603    Pel* pCurrY = pcCurrPicYuv ->getLumaAddr();
     
    13642606    Int iRefStride = pcRefPicYuvOrg->getStride();
    13652607    Int iSumOrgSAD = 0;
    1366 #if LGE_ILLUCOMP_DEPTH_C0046
    13672608    Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
    1368 #else
    1369     double dThresholdOrgSAD = 0.05;
    1370 #endif
     2609
    13712610    // Histogram building - luminance
    1372     for ( Int y = 0; y < iHeight; y++)
    1373     {
    1374       for ( Int x = 0; x < iWidth; x++)
     2611    for ( Int y = 0; y < iHeight; y++ )
     2612    {
     2613      for ( Int x = 0; x < iWidth; x++ )
    13752614      {
    13762615        aiCurrHist[pCurrY[x]]++;
     
    13802619      pRefOrgY += iRefStride;
    13812620    }
    1382     // Calc SAD
    1383     for (Int i = 0; i < iMaxPelValue; i++)
    1384     {
    1385       iSumOrgSAD += abs(aiCurrHist[i] - aiRefOrgHist[i]);
     2621    // Histogram SAD
     2622    for ( Int i = 0; i < iMaxPelValue; i++ )
     2623    {
     2624      iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] );
    13862625    }
    13872626    // Setting
    1388     if ( iSumOrgSAD > Int(dThresholdOrgSAD * iWidth * iHeight) )
     2627    if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) )
    13892628    {
    13902629      m_bApplyIC = true;
     
    13952634    }
    13962635  }
    1397   xFree(aiCurrHist);
    1398   xFree(aiRefOrgHist);
     2636
     2637  xFree( aiCurrHist   );
     2638  xFree( aiRefOrgHist );
    13992639  aiCurrHist = NULL;
    14002640  aiRefOrgHist = NULL;
    14012641}
    14022642#endif
    1403 
    1404 #if MERL_VSP_NBDV_RefVId_Fix_D0166
    1405 TComPic* TComSlice::getDepthRefPic(Int viewId, Int poc)
    1406 {
    1407   TComPic* pPic = NULL;
    1408 
    1409   if (m_pcListDepthPic[viewId] == NULL)
    1410     return NULL;
    1411 
    1412   for( TComList<TComPic*>::iterator it = m_pcListDepthPic[viewId]->begin(); it != m_pcListDepthPic[viewId]->end(); it++ )
    1413   {
    1414     TComPic* currPic = *it;
    1415     TComSlice* currSlice = currPic->getCurrSlice();
    1416     Bool isDepth = currSlice->getIsDepth();
    1417     //assert(isDepth);
    1418     if( isDepth && currPic->getPOC() == poc && currPic->getViewId() == viewId ) // (*it)->getSPS()->isDepth()
    1419     {
    1420       pPic = *it;
    1421       break;
    1422     }
    1423   }
    1424 
    1425   return pPic;
    1426 }
    1427 #endif
    1428 
    1429 
    1430 #if QC_ARP_D0177
    1431 Void TComSlice::setARPStepNum()                                 
    1432 {
    1433   Bool bAllIvRef = false;
    1434   if(!getSPS()->getUseAdvRP())
    1435     m_nARPStepNum = 0;
    1436   else
    1437   {
    1438     for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
    1439     {
    1440       RefPicList  eRefPicList = RefPicList( iRefListId );
    1441       Int iNumRefIdx = getNumRefIdx(eRefPicList);
    1442       if( iNumRefIdx <= 0 )
    1443         continue;
    1444       for (Int i = 0; i < iNumRefIdx; i++)
    1445       {
    1446         if(getRefPic( REF_PIC_LIST_0, i)->getPOC() != getPOC())
    1447         {
    1448           bAllIvRef = true;
    1449           break;
    1450         }
    1451       }
    1452       if( bAllIvRef == true )
    1453         break;
    1454     }
    1455     if(bAllIvRef== true)
    1456       m_nARPStepNum = getSPS()->getARPStepNum();
    1457     else
    1458       m_nARPStepNum = 0;
    1459   }
    1460 }
    1461 #endif
    1462 // ------------------------------------------------------------------------------------------------
    1463 // Video parameter set (VPS)
    1464 // ------------------------------------------------------------------------------------------------
    1465 #if QC_MVHEVC_B0046
    1466 TComVPS::TComVPS()
    1467 : m_VPSId                     (  0)
    1468 , m_uiMaxTLayers              (  1)
    1469 , m_uiMaxLayers               (  1)
    1470 , m_bTemporalIdNestingFlag    (false)
    1471 , m_uiNumHRDParameter         (  0)
    1472 , m_numAddiLayerOperationPoints (2)
    1473 , m_numAddiProLevelSets       (  1)
    1474 {
    1475   for( Int i = 0; i < MAX_LAYER_NUM; i++)
    1476   {
    1477   m_numOpLayerIdMinus1[i] = 0;
    1478   if(i)
    1479       m_numDirectRefLayer[i] = 1;
    1480   else
    1481     m_numDirectRefLayer[i] = 0;
    1482   for( Int j = 0; j < MAX_LAYER_NUM; j++)
    1483   {
    1484     m_numDirectRefID[i][j] = 0;
    1485     m_numOpLayerId[i][j]   = 0;
    1486   }
    1487     m_uiViewId[i] = 0;
    1488     m_iViewOrderIdx[i] = 0;
    1489   }
    1490  
    1491   for( Int i = 0; i < MAX_TLAYER; i++)
    1492   {
    1493     m_numReorderPics[i] = 0;
    1494     m_uiMaxDecPicBuffering[i] = 0;
    1495     m_uiMaxLatencyIncrease[i] = 0;
    1496   }
    1497 }
    1498 
    1499 TComVPS::~TComVPS()
    1500 {
    1501 }
    1502 #else
    1503 #if VIDYO_VPS_INTEGRATION
    1504 TComVPS::TComVPS()
    1505 : m_VPSId                     (  0)
    1506 , m_uiMaxTLayers              (  1)
    1507 , m_uiMaxLayers               (  1)
    1508 , m_bTemporalIdNestingFlag    (false)
    1509 , m_uiExtensionType           (  0)
    1510 {
    1511   for( Int i = 0; i < MAX_LAYER_NUM; i++)
    1512   {
    1513     m_uiDependentLayer[i] = i? i-1: 0;
    1514     m_bDependentFlag[i] = false;
    1515     m_uiViewId[i] = 0;
    1516     m_bDepthFlag[i] = 0;
    1517     m_iViewOrderIdx[i] = 0;
    1518   }
    1519  
    1520   for( Int i = 0; i < MAX_TLAYER; i++)
    1521   {
    1522     m_numReorderPics[i] = 0;
    1523     m_uiMaxDecPicBuffering[i] = 0;
    1524     m_uiMaxLatencyIncrease[i] = 0;
    1525   }
    1526 }
    1527 
    1528 TComVPS::~TComVPS()
    1529 {
    1530  
    1531  
    1532 }
    1533 
    1534 #endif
    1535 #endif
    1536 
    1537 // ------------------------------------------------------------------------------------------------
    1538 // Sequence parameter set (SPS)
    1539 // ------------------------------------------------------------------------------------------------
    1540 
    1541 TComSPS::TComSPS()
    1542 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    1543 : m_VPSId                     (  0)
    1544 , m_SPSId                     (  0)
    1545 #else
    1546 : m_SPSId                     (  0)
    1547 #endif
    1548 , m_ProfileIdc                (  0)
    1549 , m_LevelIdc                  (  0)
    1550 , m_chromaFormatIdc           (CHROMA_420)
    1551 , m_uiMaxTLayers              (  1)
    1552 // Structure
    1553 , m_picWidthInLumaSamples     (352)
    1554 , m_picHeightInLumaSamples    (288)
    1555 , m_picCroppingFlag           (false)
    1556 , m_picCropLeftOffset         (  0)
    1557 , m_picCropRightOffset        (  0)
    1558 , m_picCropTopOffset          (  0)
    1559 , m_picCropBottomOffset       (  0)
    1560 , m_uiMaxCUWidth              ( 32)
    1561 , m_uiMaxCUHeight             ( 32)
    1562 , m_uiMaxCUDepth              (  3)
    1563 , m_uiMinTrDepth              (  0)
    1564 , m_uiMaxTrDepth              (  1)
    1565 , m_bLongTermRefsPresent      (false)
    1566 , m_iNumberOfUsableInterViewRefs( 0 )
    1567 , m_uiQuadtreeTULog2MaxSize   (  0)
    1568 , m_uiQuadtreeTULog2MinSize   (  0)
    1569 , m_uiQuadtreeTUMaxDepthInter (  0)
    1570 , m_uiQuadtreeTUMaxDepthIntra (  0)
    1571 // Tool list
    1572 , m_usePCM                   (false)
    1573 , m_pcmLog2MaxSize            (  5)
    1574 , m_uiPCMLog2MinSize          (  7)
    1575 , m_bDisInter4x4              (  1)
    1576 , m_bUseALF                   (false)
    1577 , m_bALFCoefInSlice           (false)
    1578 , m_bUseLMChroma              (false)
    1579 , m_bUseLComb                 (false)
    1580 , m_bLCMod                    (false)
    1581 #if QC_MVHEVC_B0046
    1582 , m_restrictedRefPicListsFlag   (  0)
    1583 #else
    1584 , m_restrictedRefPicListsFlag   (  1)
    1585 #endif
    1586 , m_listsModificationPresentFlag(  0)
    1587 , m_uiBitDepth                (  8)
    1588 , m_uiBitIncrement            (  0)
    1589 , m_qpBDOffsetY               (  0)
    1590 , m_qpBDOffsetC               (  0)
    1591 #if LOSSLESS_CODING
    1592 , m_useLossless               (false)
    1593 #endif
    1594 , m_uiPCMBitDepthLuma         (  8)
    1595 , m_uiPCMBitDepthChroma       (  8)
    1596 , m_bPCMFilterDisableFlag     (false)
    1597 , m_uiBitsForPOC              (  8)
    1598 , m_uiMaxTrSize               ( 32)
    1599 , m_bLFCrossSliceBoundaryFlag (false)
    1600 , m_bUseSAO                   (false)
    1601 #if HHI_MPI
    1602 , m_bUseMVI                   (false)
    1603 #endif
    1604 , m_bLFCrossTileBoundaryFlag  (false)
    1605 , m_iUniformSpacingIdr        (  0 )
    1606 , m_iTileBoundaryIndependenceIdr (  0 )
    1607 , m_iNumColumnsMinus1         (  0 )
    1608 , m_puiColumnWidth            ( NULL )
    1609 , m_iNumRowsMinus1            (  0 )
    1610 , m_puiRowHeight              ( NULL )
    1611 , m_bTemporalIdNestingFlag    (false)
    1612 , m_scalingListEnabledFlag    (false)
    1613 ,  m_tilesOrEntropyCodingSyncIdc( 0 )
    1614 ,  m_numSubstreams              ( 0 )
    1615 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1616 , m_bUseDMM                   (false)
    1617 #endif
    1618 #if FLEX_CODING_ORDER_M23723 && HHI_DMM_PRED_TEX
    1619 , m_bUseDMM34                   (false)
    1620 #endif
    1621 #if H3D_QTL
    1622 , m_bUseQTLPC                 (false)
    1623 #endif
    1624 {
    1625   // AMVP parameter
    1626   ::memset( m_aeAMVPMode, 0, sizeof( m_aeAMVPMode ) );
    1627   for ( Int i = 0; i < MAX_TLAYER; i++ )
    1628   {
    1629     m_uiMaxLatencyIncrease[i] = 0;
    1630     m_uiMaxDecPicBuffering[i] = 0;
    1631     m_numReorderPics[i]       = 0;
    1632   }
    1633 
    1634   m_uiViewId              = 0;
    1635   m_iViewOrderIdx         = 0;
    1636   m_bDepth                = false;
    1637   m_uiCamParPrecision     = 0;
    1638   m_bCamParInSliceHeader  = false;
    1639   ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
    1640   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
    1641 
    1642 #if DEPTH_MAP_GENERATION
    1643   m_uiPredDepthMapGeneration = 0;
    1644   m_uiPdmPrecision           = 0;
    1645   ::memset( m_aiPdmScaleNomDelta, 0x00, sizeof( m_aiPdmScaleNomDelta  ) );
    1646   ::memset( m_aiPdmOffset,        0x00, sizeof( m_aiPdmOffset         ) );
    1647 #endif
    1648 #if H3D_IVMP
    1649   m_uiMultiviewMvPredMode    = 0;
    1650 #endif
    1651 #if QC_ARP_D0177
    1652   m_nUseAdvResPred           = 0;
    1653   m_nARPStepNum              = 1;
    1654 #endif
    1655   ::memset( m_aiUsableInterViewRefs, 0, sizeof( m_aiUsableInterViewRefs ) );
    1656  
    1657 #if RWTH_SDC_DLT_B0036
    1658   m_bUseDLT = false;
    1659  
    1660   m_uiBitsPerDepthValue = g_uiBitDepth;
    1661   m_uiNumDepthmapValues = 0;
    1662   m_uiDepthValue2Idx    = NULL;
    1663   m_uiIdx2DepthValue    = NULL;
    1664 #endif
    1665 }
    1666 
    1667 TComSPS::~TComSPS()
    1668 {
    1669   if( m_iNumColumnsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
    1670   {
    1671     delete [] m_puiColumnWidth;
    1672     m_puiColumnWidth = NULL;
    1673   }
    1674   if( m_iNumRowsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
    1675   {
    1676     delete [] m_puiRowHeight;
    1677     m_puiRowHeight = NULL;
    1678   }
    1679 }
    1680 
    1681 #if RWTH_SDC_DLT_B0036
    1682 Void TComSPS::setDepthLUTs(UInt* uidx2DepthValue, UInt uiNumDepthValues)
    1683 {
    1684   UInt uiMaxDepthValue = g_uiIBDI_MAX;
    1685  
    1686   // allocate some memory
    1687   if( m_uiNumDepthmapValues == 0 )
    1688   {
    1689     m_uiNumDepthmapValues = uiMaxDepthValue+1;
    1690     m_uiBitsPerDepthValue = (UInt)ceil(Log2(m_uiNumDepthmapValues));
    1691    
    1692     m_uiDepthValue2Idx    = (UInt*) xMalloc(UInt, m_uiNumDepthmapValues);
    1693     m_uiIdx2DepthValue    = (UInt*) xMalloc(UInt, m_uiNumDepthmapValues);
    1694    
    1695     //default mapping
    1696     for (Int i=0; i<m_uiNumDepthmapValues; i++)
    1697     {
    1698       m_uiDepthValue2Idx[i] = i;
    1699       m_uiIdx2DepthValue[i] = i;
    1700     }
    1701   }
    1702  
    1703   if( uidx2DepthValue == NULL || uiNumDepthValues == 0 ) // default mapping only
    1704     return;
    1705  
    1706   // copy idx2DepthValue to internal array
    1707   memcpy(m_uiIdx2DepthValue, uidx2DepthValue, uiNumDepthValues*sizeof(UInt));
    1708  
    1709   for(Int p=0; p<=uiMaxDepthValue; p++)
    1710   {
    1711     Int iIdxDown    = 0;
    1712     Int iIdxUp      = uiNumDepthValues-1;
    1713     Bool bFound     = false;
    1714    
    1715     // iterate over indices to find lower closest depth
    1716     Int i = 1;
    1717     while(!bFound && i<uiNumDepthValues)
    1718     {
    1719       if( m_uiIdx2DepthValue[i] > p )
    1720       {
    1721         iIdxDown  = i-1;
    1722         bFound    = true;
    1723       }
    1724      
    1725       i++;
    1726     }
    1727     // iterate over indices to find upper closest depth
    1728     i = uiNumDepthValues-2;
    1729     bFound = false;
    1730     while(!bFound && i>=0)
    1731     {
    1732       if( m_uiIdx2DepthValue[i] < p )
    1733       {
    1734         iIdxUp  = i+1;
    1735         bFound    = true;
    1736       }
    1737      
    1738       i--;
    1739     }
    1740    
    1741     // assert monotony
    1742     assert(iIdxDown<=iIdxUp);
    1743    
    1744     // assign closer depth value/idx
    1745     if( abs(p-(Int)m_uiIdx2DepthValue[iIdxDown]) < abs(p-(Int)m_uiIdx2DepthValue[iIdxUp]) )
    1746     {
    1747       m_uiDepthValue2Idx[p] = iIdxDown;
    1748     }
    1749     else
    1750     {
    1751       m_uiDepthValue2Idx[p] = iIdxUp;
    1752     }
    1753    
    1754   }
    1755  
    1756   // update globals
    1757   m_uiNumDepthmapValues = uiNumDepthValues;
    1758   m_uiBitsPerDepthValue = (UInt)ceil(Log2(m_uiNumDepthmapValues));
    1759 }
    1760 #endif
    1761 
    1762 TComPPS::TComPPS()
    1763 : m_PPSId                       (0)
    1764 , m_SPSId                       (0)
    1765 , m_picInitQPMinus26            (0)
    1766 , m_useDQP                      (false)
    1767 , m_bConstrainedIntraPred       (false)
    1768 , m_pcSPS                       (NULL)
    1769 , m_uiMaxCuDQPDepth             (0)
    1770 , m_uiMinCuDQPSize              (0)
    1771 , m_iChromaQpOffset             (0)
    1772 , m_iChromaQpOffset2nd          (0)
    1773 , m_iSliceGranularity           (0)
    1774 , m_iTileBehaviorControlPresentFlag (0)
    1775 , m_bLFCrossTileBoundaryFlag     (true)
    1776 , m_iColumnRowInfoPresent        (0)
    1777 , m_iUniformSpacingIdr           (0)
    1778 , m_iNumColumnsMinus1            (0)
    1779 , m_puiColumnWidth               (NULL)
    1780 , m_iNumRowsMinus1               (0)
    1781 , m_puiRowHeight                 (NULL)
    1782 ,  m_iNumSubstreams             (1)
    1783 , m_signHideFlag(0)
    1784 , m_signHidingThreshold(0)
    1785 #if CABAC_INIT_FLAG
    1786 , m_cabacInitPresentFlag        (false)
    1787 , m_encCABACTableIdx            (0)
    1788 #if FIX_POZNAN_CABAC_INIT_FLAG
    1789 , m_encPrevPOC            (0)
    1790 #endif
    1791 #endif
    1792 {
    1793 }
    1794 
    1795 TComPPS::~TComPPS()
    1796 {
    1797   if( m_iNumColumnsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
    1798   {
    1799     if (m_puiColumnWidth) delete [] m_puiColumnWidth;
    1800     m_puiColumnWidth = NULL;
    1801   }
    1802   if( m_iNumRowsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
    1803   {
    1804     if (m_puiRowHeight) delete [] m_puiRowHeight;
    1805     m_puiRowHeight = NULL;
    1806   }
    1807 }
    1808 
    1809 Void
    1810 TComSPS::initMultiviewSPS( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
    1811 {
    1812 #if !QC_MVHEVC_B0046
    1813   AOT( uiViewId == 0 && iViewOrderIdx != 0 );
    1814   AOT( uiViewId != 0 && iViewOrderIdx == 0 );
    1815   AOT( uiViewId != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) );
    1816 #endif
    1817   m_uiViewId              = uiViewId;
    1818   m_iViewOrderIdx         = iViewOrderIdx;
    1819   m_bDepth                = false;
    1820   m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
    1821   m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
    1822   ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
    1823   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
    1824 #if !QC_MVHEVC_B0046
    1825   if( !m_bCamParInSliceHeader )
    1826   {
    1827     for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
    1828     {
    1829       m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
    1830       m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
    1831       m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
    1832       m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
    1833     }
    1834   }
    1835 #endif
    1836 }
    1837 
    1838 Void
    1839 #if FCO_FIX_SPS_CHANGE
    1840 TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
    1841 #else
    1842 TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx )
    1843 #endif
    1844 {
    1845   AOT( uiViewId == 0 && iViewOrderIdx != 0 );
    1846   AOT( uiViewId != 0 && iViewOrderIdx == 0 );
    1847 
    1848   m_uiViewId              = uiViewId;
    1849   m_iViewOrderIdx         = iViewOrderIdx;
    1850   m_bDepth                = true;
    1851 #if FCO_FIX_SPS_CHANGE
    1852   m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
    1853   m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
    1854 #else
    1855   m_uiCamParPrecision     = 0;
    1856   m_bCamParInSliceHeader  = false;
    1857 #endif
    1858   ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
    1859   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
    1860 #if FCO_FIX_SPS_CHANGE
    1861 #if !QC_MVHEVC_B0046
    1862   if( !m_bCamParInSliceHeader )
    1863   {
    1864     for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
    1865     {
    1866       m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
    1867       m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
    1868       m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
    1869       m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
    1870     }
    1871   }
    1872 #endif
    1873 #endif
    1874 
    1875 }
    1876 
    1877 #if DEPTH_MAP_GENERATION
    1878 Void
    1879 TComSPS::setPredDepthMapGeneration( UInt uiViewId, Bool bIsDepth, UInt uiPdmGenMode, UInt uiPdmMvPredMode, UInt uiPdmPrec, Int** aaiPdmScaleNomDelta, Int** aaiPdmOffset )
     2643#if H_3D
     2644Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
     2645{
     2646  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
     2647  {     
     2648    for ( Int depthId = 0; depthId < 2; depthId++ )
     2649    {
     2650      m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL;
     2651    }       
     2652  } 
     2653}
     2654Void TComSlice::setDepthToDisparityLUTs()
    18802655{
    1881   AOF( m_uiViewId == uiViewId );
    1882   AOF( m_bDepth   == bIsDepth );
    1883   AOT( ( uiViewId == 0 || bIsDepth ) && uiPdmGenMode );
    1884   AOT( uiPdmGenMode && ( aaiPdmScaleNomDelta == 0 || aaiPdmOffset == 0 ) );
    1885   AOT( uiPdmMvPredMode && uiPdmGenMode == 0 );
    1886 
    1887   m_uiPredDepthMapGeneration = uiPdmGenMode;
    1888 #if H3D_IVMP
    1889   m_uiMultiviewMvPredMode    = uiPdmMvPredMode;
    1890 #endif
    1891 
    1892   m_uiPdmPrecision           = ( m_uiPredDepthMapGeneration ? uiPdmPrec : 0 );
    1893   ::memset( m_aiPdmScaleNomDelta, 0x00, sizeof( m_aiPdmScaleNomDelta  ) );
    1894   ::memset( m_aiPdmOffset,        0x00, sizeof( m_aiPdmOffset         ) );
    1895   if( m_uiPredDepthMapGeneration )
    1896   {
    1897     for( UInt uiBaseId = 0; uiBaseId < m_uiViewId; uiBaseId++ )
    1898     {
    1899       m_aiPdmScaleNomDelta[ uiBaseId ]  = aaiPdmScaleNomDelta[ m_uiViewId ][ uiBaseId ];
    1900       m_aiPdmOffset       [ uiBaseId ]  = aaiPdmOffset       [ m_uiViewId ][ uiBaseId ];
    1901     }
    1902   }
    1903 }
    1904 #endif
    1905 
    1906 TComReferencePictureSet::TComReferencePictureSet()
    1907 : m_numberOfPictures (0)
    1908 , m_numberOfNegativePictures (0)
    1909 , m_numberOfPositivePictures (0)
    1910 , m_numberOfLongtermPictures (0)
    1911 , m_interRPSPrediction (0)
    1912 , m_deltaRIdxMinus1 (0)   
    1913 , m_deltaRPS (0)
    1914 , m_numRefIdc (0)
    1915 {
    1916   ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
    1917   ::memset( m_POC, 0, sizeof(m_POC) );
    1918   ::memset( m_used, 0, sizeof(m_used) );
    1919   ::memset( m_refIdc, 0, sizeof(m_refIdc) );
    1920 }
    1921 
    1922 TComReferencePictureSet::~TComReferencePictureSet()
    1923 {
    1924 }
    1925 
    1926 Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
    1927 {
    1928   m_used[bufferNum] = used;
    1929 }
    1930 
    1931 Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
    1932 {
    1933   m_deltaPOC[bufferNum] = deltaPOC;
    1934 }
    1935 
    1936 Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
    1937 {
    1938   m_numberOfPictures = numberOfPictures;
    1939 }
    1940 
    1941 Int TComReferencePictureSet::getUsed(Int bufferNum)
    1942 {
    1943   return m_used[bufferNum];
    1944 }
    1945 
    1946 Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
    1947 {
    1948   return m_deltaPOC[bufferNum];
    1949 }
    1950 
    1951 Int TComReferencePictureSet::getNumberOfPictures()
    1952 {
    1953   return m_numberOfPictures;
    1954 }
    1955 
    1956 Int TComReferencePictureSet::getPOC(Int bufferNum)
    1957 {
    1958   return m_POC[bufferNum];
    1959 }
    1960 Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
    1961 {
    1962   m_POC[bufferNum] = POC;
    1963 }
    1964 
    1965 /** set the reference idc value at uiBufferNum entry to the value of iRefIdc
    1966  * \param uiBufferNum
    1967  * \param iRefIdc
    1968  * \returns Void
    1969  */
    1970 Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
    1971 {
    1972   m_refIdc[bufferNum] = refIdc;
    1973 }
    1974 
    1975 /** get the reference idc value at uiBufferNum
    1976  * \param uiBufferNum
    1977  * \returns Int
    1978  */
    1979 Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
    1980 {
    1981   return m_refIdc[bufferNum];
    1982 }
    1983 
    1984 /** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
    1985  *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
    1986  *  +ve values are in increasing order.
    1987  * \returns Void
    1988  */
    1989 Void TComReferencePictureSet::sortDeltaPOC()
    1990 {
    1991   // sort in increasing order (smallest first)
    1992   for(Int j=1; j < getNumberOfPictures(); j++)
    1993   {
    1994     Int deltaPOC = getDeltaPOC(j);
    1995     Bool used = getUsed(j);
    1996     for (Int k=j-1; k >= 0; k--)
    1997     {
    1998       Int temp = getDeltaPOC(k);
    1999       if (deltaPOC < temp)
    2000       {
    2001         setDeltaPOC(k+1, temp);
    2002         setUsed(k+1, getUsed(k));
    2003         setDeltaPOC(k, deltaPOC);
    2004         setUsed(k, used);
    2005       }
    2006     }
    2007   }
    2008   // flip the negative values to largest first
    2009   Int numNegPics = getNumberOfNegativePictures();
    2010   for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
    2011   {
    2012     Int deltaPOC = getDeltaPOC(j);
    2013     Bool used = getUsed(j);
    2014     setDeltaPOC(j, getDeltaPOC(k));
    2015     setUsed(j, getUsed(k));
    2016     setDeltaPOC(k, deltaPOC);
    2017     setUsed(k, used);
    2018   }
    2019 }
    2020 
    2021 /** Prints the deltaPOC and RefIdc (if available) values in the RPS.
    2022  *  A "*" is added to the deltaPOC value if it is Used bu current.
    2023  * \returns Void
    2024  */
    2025 Void TComReferencePictureSet::printDeltaPOC()
    2026 {
    2027   printf("DeltaPOC = { ");
    2028   for(Int j=0; j < getNumberOfPictures(); j++)
    2029   {
    2030     printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
    2031   }
    2032   if (getInterRPSPrediction())
    2033   {
    2034     printf("}, RefIdc = { ");
    2035     for(Int j=0; j < getNumRefIdc(); j++)
    2036     {
    2037       printf("%d ", getRefIdc(j));
    2038     }
    2039   }
    2040   printf("}\n");
    2041 }
    2042 
    2043 TComRPSList::TComRPSList()
    2044 {
    2045 }
    2046 
    2047 TComRPSList::~TComRPSList()
    2048 {
    2049 }
    2050 
    2051 Void TComRPSList::create( Int numberOfReferencePictureSets)
    2052 {
    2053   m_numberOfReferencePictureSets = numberOfReferencePictureSets;
    2054   m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
    2055 }
    2056 
    2057 Void TComRPSList::destroy()
    2058 {
    2059   delete [] m_referencePictureSets;
    2060   m_numberOfReferencePictureSets = 0;
    2061   m_referencePictureSets = NULL;
    2062 }
    2063 
    2064 
    2065 
    2066 TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
    2067 {
    2068   return &m_referencePictureSets[referencePictureSetNum];
    2069 }
    2070 
    2071 Int TComRPSList::getNumberOfReferencePictureSets()
    2072 {
    2073   return m_numberOfReferencePictureSets;
    2074 }
    2075 
    2076 Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
    2077 {
    2078   m_numberOfReferencePictureSets = numberOfReferencePictureSets;
    2079 }
    2080 
    2081 TComRefPicListModification::TComRefPicListModification()
    2082 : m_bRefPicListModificationFlagL0 (false)
    2083 , m_bRefPicListModificationFlagL1 (false)
    2084 {
    2085   ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
    2086   ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
    2087 }
    2088 
    2089 TComRefPicListModification::~TComRefPicListModification()
    2090 {
    2091 }
    2092 
    2093 TComAPS::TComAPS()
    2094 {
    2095   m_apsID = 0;
    2096   m_bAlfEnabled = false;
    2097   m_bSaoEnabled = false;
    2098   m_pSaoParam = NULL;
    2099   m_alfParamSet = NULL;
    2100   m_scalingList = NULL;
    2101   m_scalingListEnabled = false;
    2102 }
    2103 
    2104 TComAPS::~TComAPS()
    2105 {
    2106 
    2107 }
    2108 
    2109 TComAPS& TComAPS::operator= (const TComAPS& src)
    2110 {
    2111   m_apsID       = src.m_apsID;
    2112   m_loopFilterOffsetInAPS = src.m_loopFilterOffsetInAPS;
    2113   m_loopFilterDisable = src.m_loopFilterDisable;
    2114   m_loopFilterBetaOffsetDiv2 = src.m_loopFilterBetaOffsetDiv2;
    2115   m_loopFilterTcOffsetDiv2 = src.m_loopFilterTcOffsetDiv2;
    2116   m_bAlfEnabled = src.m_bAlfEnabled;
    2117   m_bSaoEnabled = src.m_bSaoEnabled;
    2118   m_pSaoParam   = src.m_pSaoParam;
    2119   m_alfParamSet    = src.m_alfParamSet;
    2120   m_scalingList = src.m_scalingList;
    2121   m_scalingListEnabled = src.m_scalingListEnabled;
    2122 #if !LGE_SAO_MIGRATION_D0091
    2123   m_saoInterleavingFlag = src.m_saoInterleavingFlag;
    2124 #endif
    2125 
    2126   return *this;
    2127 }
    2128 
    2129 Void TComAPS::createSaoParam()
    2130 {
    2131   m_pSaoParam = new SAOParam;
    2132 }
    2133 
    2134 Void TComAPS::destroySaoParam()
    2135 {
    2136   if(m_pSaoParam != NULL)
    2137   {
    2138     delete m_pSaoParam;
    2139     m_pSaoParam = NULL;
    2140   }
    2141 }
    2142 
    2143 Void TComAPS::createAlfParam()
    2144 {
    2145   m_alfParamSet = new AlfParamSet;
    2146 }
    2147 Void TComAPS::destroyAlfParam()
    2148 {
    2149   if(m_alfParamSet != NULL)
    2150   {
    2151     delete m_alfParamSet;
    2152     m_alfParamSet = NULL;
    2153   }
    2154 }
    2155 
    2156 Void TComAPS::createScalingList()
    2157 {
    2158   m_scalingList = new TComScalingList;
    2159 }
    2160 Void TComAPS::destroyScalingList()
    2161 {
    2162   delete m_scalingList;
    2163 }
    2164 
    2165 TComScalingList::TComScalingList()
    2166 {
    2167   init();
    2168 }
    2169 TComScalingList::~TComScalingList()
    2170 {
    2171   destroy();
    2172 }
    2173 
    2174 /** set default quantization matrix to array
    2175 */
    2176 Void TComSlice::setDefaultScalingList()
    2177 {
    2178   for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    2179   {
    2180     for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
    2181     {
    2182       getScalingList()->processDefaultMarix(sizeId, listId);
    2183     }
    2184   }
    2185 }
    2186 /** check if use default quantization matrix
    2187  * \returns true if use default quantization matrix in all size
    2188 */
    2189 Bool TComSlice::checkDefaultScalingList()
    2190 {
    2191   UInt defaultCounter=0;
    2192 
    2193   for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    2194   {
    2195     for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
    2196     {
    2197       if(getScalingList()->getUseDefaultScalingMatrixFlag(sizeId,listId))
    2198       {
    2199         defaultCounter++;
    2200       }
    2201     }
    2202   }
    2203   return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? true : false; // -4 for 32x32
    2204 }
     2656  Bool setupLUT = false;
     2657  Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId );
     2658
     2659#if H_3D_VSP
     2660  setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS);
     2661#endif
     2662
     2663#if H_3D_NBDV_REF
     2664  setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS );
     2665#endif
     2666
     2667  if( !setupLUT )
     2668    return;
     2669
     2670  /// GT: Allocation should be moved to a better place later;
     2671  if ( m_depthToDisparityB == NULL )
     2672  {
     2673    m_depthToDisparityB = new Int*[ getViewIndex() ];
     2674    for ( Int i = 0; i < getViewIndex(); i++ )
     2675    {
     2676      m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ];
     2677    }
     2678  }
     2679
     2680  if ( m_depthToDisparityF == NULL )
     2681  {
     2682    m_depthToDisparityF= new Int*[ getViewIndex() ];
     2683    for ( Int i = 0; i < getViewIndex(); i++ )
     2684    {
     2685      m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ];
     2686    }
     2687  }
     2688
     2689  assert( m_depthToDisparityB != NULL );
     2690  assert( m_depthToDisparityF != NULL );
     2691
     2692  TComSPS* sps = getSPS();
     2693
     2694  Int log2Div = g_bitDepthY - 1 + sps->getCamParPrecision();
     2695
     2696  Bool camParaSH = m_pcSPS->hasCamParInSliceHeader();
     2697
     2698  Int* codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : sps->getCodedScale    ();
     2699  Int* codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : sps->getCodedOffset   ();
     2700  Int* invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : sps->getInvCodedScale ();
     2701  Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : sps->getInvCodedOffset();
     2702
     2703  for (Int i = 0; i <= ( getViewIndex() - 1); i++)
     2704  {
     2705    for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ )
     2706    {
     2707      Int offset =    ( codOffset  [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
     2708      m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div;
     2709
     2710      Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
     2711      m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div;
     2712    }
     2713  }
     2714}
     2715#endif
     2716#endif
    22052717/** get scaling matrix from RefMatrixID
    22062718 * \param sizeId size index
     
    22102722Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
    22112723{
    2212   ::memcpy(getScalingListAddress(sizeId, listId),getScalingListAddress(sizeId, refListId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
    2213 }
     2724  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
     2725}
     2726
    22142727/** parse syntax infomation
    22152728 *  \param pchFile syntax infomation
    22162729 *  \returns false if successful
    22172730 */
    2218 Bool TComScalingList::xParseScalingList(char* pchFile)
     2731Bool TComScalingList::xParseScalingList(Char* pchFile)
    22192732{
    22202733  FILE *fp;
     
    22762789        }
    22772790        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
    2278           retval = fscanf(fp, "%d,", &data);
    2279           if (retval!=1)
    2280           {
    2281             printf("Error: can't read Matrix :: set Default Matrix\n");
    2282             return true;
    2283           }
    2284           //overwrite DC value when size of matrix is larger than 16x16
    2285           setScalingListDC(sizeIdc,listIdc,data);
     2791        retval = fscanf(fp, "%d,", &data);
     2792        if (retval!=1)
     2793        {
     2794          printf("Error: can't read Matrix :: set Default Matrix\n");
     2795          return true;
     2796        }
     2797        //overwrite DC value when size of matrix is larger than 16x16
     2798        setScalingListDC(sizeIdc,listIdc,data);
    22862799      }
    22872800    }
     
    23042817  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
    23052818}
     2819
    23062820/** destroy quantization matrix array
    23072821 */
     
    23162830  }
    23172831}
     2832
    23182833/** get default address of quantization matrix
    23192834 * \param sizeId size index
     
    23272842  {
    23282843    case SCALING_LIST_4x4:
    2329       src = (listId<3) ? g_quantIntraDefault4x4 : g_quantInterDefault4x4;
     2844      src = g_quantTSDefault4x4;
    23302845      break;
    23312846    case SCALING_LIST_8x8:
     
    23452860  return src;
    23462861}
     2862
    23472863/** process of default matrix
    23482864 * \param sizeId size index
     
    23522868{
    23532869  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
    2354   setUseDefaultScalingMatrixFlag(sizeId,listId,true);
    23552870  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
    23562871}
     2872
    23572873/** check DC value of matrix for default matrix signaling
    23582874 */
     
    23632879    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    23642880    {
    2365       setUseDefaultScalingMatrixFlag(sizeId,listId,false);
    23662881      //check default matrix?
    23672882      if(getScalingListDC(sizeId,listId) == 0)
     
    23742889
    23752890ParameterSetManager::ParameterSetManager()
    2376 : m_spsMap(MAX_NUM_SPS)
     2891: m_vpsMap(MAX_NUM_VPS)
     2892, m_spsMap(MAX_NUM_SPS)
    23772893, m_ppsMap(MAX_NUM_PPS)
    2378 , m_apsMap(MAX_NUM_APS)
    2379 #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    2380 , m_vpsMap(MAX_NUM_VPS)
    2381 #endif
     2894, m_activeVPSId(-1)
     2895, m_activeSPSId(-1)
     2896, m_activePPSId(-1)
    23822897{
    23832898}
     
    23882903}
    23892904
     2905//! activate a SPS from a active parameter sets SEI message
     2906//! \returns true, if activation is successful
     2907Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
     2908{
     2909  TComSPS *sps = m_spsMap.getPS(spsId);
     2910  if (sps)
     2911  {
     2912    Int vpsId = sps->getVPSId();
     2913    if (m_vpsMap.getPS(vpsId))
     2914    {
     2915      m_activeVPSId = vpsId;
     2916      m_activeSPSId = spsId;
     2917      return true;
     2918    }
     2919    else
     2920    {
     2921      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
     2922    }
     2923  }
     2924  else
     2925  {
     2926    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
     2927  }
     2928  return false;
     2929}
     2930
     2931//! activate a PPS and depending on isIDR parameter also SPS and VPS
     2932//! \returns true, if activation is successful
     2933Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
     2934{
     2935  TComPPS *pps = m_ppsMap.getPS(ppsId);
     2936  if (pps)
     2937  {
     2938    Int spsId = pps->getSPSId();
     2939#if H_MV
     2940    // active parameter sets per layer should be used here
     2941#else
     2942    if (!isIRAP && (spsId != m_activeSPSId))
     2943    {
     2944      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
     2945      return false;
     2946    }
     2947#endif
     2948    TComSPS *sps = m_spsMap.getPS(spsId);
     2949    if (sps)
     2950    {
     2951      Int vpsId = sps->getVPSId();
     2952      if (!isIRAP && (vpsId != m_activeVPSId))
     2953      {
     2954        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
     2955        return false;
     2956      }
     2957      if (m_vpsMap.getPS(vpsId))
     2958      {
     2959        m_activePPSId = ppsId;
     2960        m_activeVPSId = vpsId;
     2961        m_activeSPSId = spsId;
     2962        return true;
     2963      }
     2964      else
     2965      {
     2966        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
     2967      }
     2968    }
     2969    else
     2970    {
     2971      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
     2972    }
     2973  }
     2974  else
     2975  {
     2976    printf("Warning: tried to activate non-existing PPS.");
     2977  }
     2978  return false;
     2979}
     2980
     2981ProfileTierLevel::ProfileTierLevel()
     2982  : m_profileSpace    (0)
     2983  , m_tierFlag        (false)
     2984  , m_profileIdc      (0)
     2985  , m_levelIdc        (0)
     2986, m_progressiveSourceFlag  (false)
     2987, m_interlacedSourceFlag   (false)
     2988, m_nonPackedConstraintFlag(false)
     2989, m_frameOnlyConstraintFlag(false)
     2990{
     2991  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
     2992}
     2993
     2994TComPTL::TComPTL()
     2995{
     2996  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
     2997  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
     2998}
     2999
     3000#if H_MV
     3001Void TComPTL::copyLevelFrom( TComPTL* source )
     3002{
     3003  getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() );
     3004  for( Int subLayer = 0; subLayer < 6; subLayer++ )
     3005  {
     3006    setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) );
     3007    getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() );
     3008  }
     3009}
     3010#endif
     3011#if SIGNAL_BITRATE_PICRATE_IN_VPS
     3012TComBitRatePicRateInfo::TComBitRatePicRateInfo()
     3013{
     3014  ::memset(m_bitRateInfoPresentFlag, 0, sizeof(m_bitRateInfoPresentFlag));
     3015  ::memset(m_picRateInfoPresentFlag, 0, sizeof(m_picRateInfoPresentFlag));
     3016  ::memset(m_avgBitRate,             0, sizeof(m_avgBitRate));
     3017  ::memset(m_maxBitRate,             0, sizeof(m_maxBitRate));
     3018  ::memset(m_constantPicRateIdc,     0, sizeof(m_constantPicRateIdc));
     3019  ::memset(m_avgPicRate,             0, sizeof(m_avgPicRate));
     3020}
     3021#endif
    23903022//! \}
Note: See TracChangeset for help on using the changeset viewer.