source: 3DVCSoftware/branches/HTM-15.2-dev/source/Lib/TLibCommon/TComSlice.cpp @ 1370

Last change on this file since 1370 was 1360, checked in by tech, 9 years ago

Update to HM-16.7.

  • Property svn:eol-style set to native
File size: 172.9 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 *  * Redistributions of source code must retain the above copyright notice,
14 *    this list of conditions and the following disclaimer.
15 *  * Redistributions in binary form must reproduce the above copyright notice,
16 *    this list of conditions and the following disclaimer in the documentation
17 *    and/or other materials provided with the distribution.
18 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
19 *    be used to endorse or promote products derived from this software without
20 *    specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/** \file     TComSlice.cpp
36    \brief    slice header and SPS class
37*/
38
39#include "CommonDef.h"
40#include "TComSlice.h"
41#include "TComPic.h"
42#include "TLibEncoder/TEncSbac.h"
43#include "TLibDecoder/TDecSbac.h"
44
45
46//! \ingroup TLibCommon
47//! \{
48
49TComSlice::TComSlice()
50: m_iPPSId                        ( -1 )
51, m_PicOutputFlag                 ( true )
52#if NH_MV
53, m_slicePicOrderCntLsb           ( 0 )
54#endif
55, m_iPOC                          ( 0 )
56, m_iLastIDR                      ( 0 )
57, m_iAssociatedIRAP               ( 0 )
58, m_iAssociatedIRAPType           ( NAL_UNIT_INVALID )
59, m_pRPS                          ( 0 )
60, m_localRPS                      ( )
61, m_rpsIdx                        ( 0 )
62, m_RefPicListModification        ( )
63, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
64, m_eSliceType                    ( I_SLICE )
65, m_iSliceQp                      ( 0 )
66, m_dependentSliceSegmentFlag     ( false )
67#if ADAPTIVE_QP_SELECTION
68, m_iSliceQpBase                  ( 0 )
69#endif
70, m_ChromaQpAdjEnabled            ( false )
71, m_deblockingFilterDisable       ( false )
72, m_deblockingFilterOverrideFlag  ( false )
73, m_deblockingFilterBetaOffsetDiv2( 0 )
74, m_deblockingFilterTcOffsetDiv2  ( 0 )
75, m_bCheckLDC                     ( false )
76, m_iSliceQpDelta                 ( 0 )
77, m_iDepth                        ( 0 )
78, m_bRefenced                     ( false )
79, m_pcVPS                         ( NULL )
80, m_pcSPS                         ( NULL )
81, m_pcPPS                         ( NULL )
82, m_pcPic                         ( NULL )
83, m_colFromL0Flag                 ( true )
84, m_noOutputPriorPicsFlag         ( false )
85, m_noRaslOutputFlag              ( false )
86, m_handleCraAsBlaFlag            ( false )
87, m_colRefIdx                     ( 0 )
88, m_maxNumMergeCand               ( 0 )
89, m_uiTLayer                      ( 0 )
90, m_bTLayerSwitchingFlag          ( false )
91, m_sliceMode                     ( NO_SLICES )
92, m_sliceArgument                 ( 0 )
93, m_sliceCurStartCtuTsAddr        ( 0 )
94, m_sliceCurEndCtuTsAddr          ( 0 )
95, m_sliceIdx                      ( 0 )
96, m_sliceSegmentMode              ( NO_SLICES )
97, m_sliceSegmentArgument          ( 0 )
98, m_sliceSegmentCurStartCtuTsAddr ( 0 )
99, m_sliceSegmentCurEndCtuTsAddr   ( 0 )
100, m_nextSlice                     ( false )
101, m_nextSliceSegment              ( false )
102, m_sliceBits                     ( 0 )
103, m_sliceSegmentBits              ( 0 )
104, m_bFinalized                    ( false )
105, m_bTestWeightPred               ( false )
106, m_bTestWeightBiPred             ( false )
107, m_substreamSizes                ( )
108, m_cabacInitFlag                 ( false )
109, m_bLMvdL1Zero                   ( false )
110, m_temporalLayerNonReferenceFlag ( false )
111, m_LFCrossSliceBoundaryFlag      ( false )
112, m_enableTMVPFlag                ( true )
113, m_encCABACTableIdx              (I_SLICE)
114#if NH_MV
115, m_refPicSetInterLayer0          ( NULL )
116, m_refPicSetInterLayer1          ( NULL )
117, m_layerId                       (0)
118, m_viewId                        (0)
119, m_viewIndex                     (0)
120#if NH_3D
121, m_isDepth                       (false)
122#endif
123#if NH_MV
124, m_pocResetFlag                  (false)
125, m_crossLayerBlaFlag             (false)
126#endif
127, m_discardableFlag               (false)
128, m_interLayerPredEnabledFlag     (false)
129, m_numInterLayerRefPicsMinus1    (0)
130#if NH_MV
131, m_sliceSegmentHeaderExtensionLength (0)
132, m_pocResetIdc                   (0)
133, m_pocResetPeriodId              (0)
134, m_hasPocResetPeriodIdPresent    (false)
135, m_fullPocResetFlag              (false)
136, m_pocLsbVal                     (0)
137, m_pocMsbCycleValPresentFlag     (false)
138, m_pocMsbCycleVal                (0)
139, m_pocMsbValRequiredFlag         (false)
140#endif
141#if NH_3D_IC
142, m_bApplyIC                      (false)
143, m_icSkipParseFlag               (false)
144#endif
145#if NH_3D
146, m_inCmpPredFlag                 (false)
147, m_numViews                      (0)
148, m_depthToDisparityB             (NULL)
149, m_depthToDisparityF             (NULL)
150#endif
151#if NH_3D_DIS
152, m_bApplyDIS                     (false)
153#endif
154#endif
155{
156
157#if NH_MV
158  m_shortTermRefPicSetIdx = 0; 
159  m_numLongTermSps        = 0; 
160  m_numLongTermPics       = 0; 
161  for (Int i = 0; i < MAX_NUM_PICS_RPS; i++)
162  {
163    m_ltIdxSps          [i] = 0; 
164    m_deltaPocMsbCycleLt[i] = 0;
165  }
166  setSliceTemporalMvpEnabledFlag( false ); 
167#endif
168  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
169  {
170    m_aiNumRefIdx[i] = 0;
171  }
172
173  for (UInt component = 0; component < MAX_NUM_COMPONENT; component++)
174  {
175    m_lambdas            [component] = 0.0;
176    m_iSliceChromaQpDelta[component] = 0;
177  }
178
179  initEqualRef();
180
181  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
182  {
183    m_list1IdxToList0Idx[idx] = -1;
184  }
185
186  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
187  {
188    for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
189    {
190      m_apcRefPicList [i][iNumCount] = NULL;
191      m_aiRefPOCList  [i][iNumCount] = 0;
192    }
193#if NH_MV
194    m_aiRefLayerIdList[0][iNumCount] = 0;
195    m_aiRefLayerIdList[1][iNumCount] = 0;
196#endif
197  }
198
199  resetWpScaling();
200  initWpAcDcParam();
201
202  for(Int ch=0; ch < MAX_NUM_CHANNEL_TYPE; ch++)
203  {
204    m_saoEnabledFlag[ch] = false;
205  }
206#if NH_MV
207  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
208  {
209    m_interLayerPredLayerIdc[ i ] = -1;
210  }
211#endif
212#if NH_3D
213  m_iDefaultRefViewIdx = -1;
214  m_bDefaultRefViewIdxAvailableFlag = false;
215  m_ivMvPredFlag           = false;
216  m_ivMvScalingFlag        = false;
217  m_ivResPredFlag          = false; 
218  m_depthRefinementFlag    = false;
219  m_viewSynthesisPredFlag  = false;
220  m_depthBasedBlkPartFlag  = false;
221  m_mpiFlag                = false;
222  m_intraContourFlag       = false;
223  m_intraSdcWedgeFlag      = false;
224  m_qtPredFlag             = false;
225  m_interSdcFlag           = false;
226  m_depthIntraSkipFlag     = false;
227  m_subPbSize              =  1 << 6;
228  m_mpiSubPbSize           =  1 << 6;
229
230  m_aaiCodedOffset.resize(2);
231  m_aaiCodedScale .resize(2);
232  for (Int i = 0; i < 2; i++)
233  {
234    m_aaiCodedOffset[i].resize(MAX_NUM_LAYERS);
235    m_aaiCodedScale [i].resize(MAX_NUM_LAYERS);
236  }
237 
238#endif
239
240}
241
242TComSlice::~TComSlice()
243{
244#if NH_3D
245  for( UInt i = 0; i < m_numViews; i++ )
246  {
247    if ( m_depthToDisparityB && m_depthToDisparityB[ i ] )
248    {
249      delete[] m_depthToDisparityB [ i ];
250    }
251
252    if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) 
253    {
254      delete[] m_depthToDisparityF [ i ];
255    }
256  }
257
258  if ( m_depthToDisparityF )
259  {
260    delete[] m_depthToDisparityF; 
261  }
262
263  m_depthToDisparityF = NULL;
264
265  if ( m_depthToDisparityB )
266    delete[] m_depthToDisparityB; 
267
268  m_depthToDisparityB = NULL;
269#endif
270
271}
272
273
274Void TComSlice::initSlice()
275{
276  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
277  {
278    m_aiNumRefIdx[i]      = 0;
279  }
280  m_colFromL0Flag = true;
281
282  m_colRefIdx = 0;
283  initEqualRef();
284
285  m_bCheckLDC = false;
286
287  for (UInt component = 0; component < MAX_NUM_COMPONENT; component++)
288  {
289    m_iSliceChromaQpDelta[component] = 0;
290  }
291#if NH_3D_IV_MERGE
292  m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM;
293#else
294  m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
295#endif
296
297  m_bFinalized=false;
298
299  m_substreamSizes.clear();
300  m_cabacInitFlag        = false;
301  m_enableTMVPFlag = true;
302#if NH_3D_TMVP
303  m_aiAlterRefIdx[0]                  = -1;
304  m_aiAlterRefIdx[1]                  = -1;
305#endif
306}
307
308Bool TComSlice::getRapPicFlag() const
309{
310  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
311      || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
312      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
313      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
314      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
315      || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
316}
317
318
319Void  TComSlice::sortPicList        (TComList<TComPic*>& rcListPic)
320{
321  TComPic*    pcPicExtract;
322  TComPic*    pcPicInsert;
323
324  TComList<TComPic*>::iterator    iterPicExtract;
325  TComList<TComPic*>::iterator    iterPicExtract_1;
326  TComList<TComPic*>::iterator    iterPicInsert;
327
328  for (Int i = 1; i < (Int)(rcListPic.size()); i++)
329  {
330    iterPicExtract = rcListPic.begin();
331    for (Int j = 0; j < i; j++)
332    {
333      iterPicExtract++;
334    }
335    pcPicExtract = *(iterPicExtract);
336    pcPicExtract->setCurrSliceIdx(0);
337
338    iterPicInsert = rcListPic.begin();
339    while (iterPicInsert != iterPicExtract)
340    {
341      pcPicInsert = *(iterPicInsert);
342      pcPicInsert->setCurrSliceIdx(0);
343      if (pcPicInsert->getPOC() >= pcPicExtract->getPOC())
344      {
345        break;
346      }
347
348      iterPicInsert++;
349    }
350
351    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
352
353    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
354    rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1);
355    rcListPic.erase  (iterPicExtract);
356  }
357}
358
359TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic, Int poc)
360{
361  TComList<TComPic*>::iterator  iterPic = rcListPic.begin();
362  TComPic*                      pcPic = *(iterPic);
363  while ( iterPic != rcListPic.end() )
364  {
365    if(pcPic->getPOC() == poc)
366    {
367      break;
368    }
369    iterPic++;
370    pcPic = *(iterPic);
371  }
372  return  pcPic;
373}
374
375
376TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
377{
378  TComList<TComPic*>::iterator  iterPic = rcListPic.begin();
379  TComPic*                      pcPic = *(iterPic);
380  TComPic*                      pcStPic = pcPic;
381
382  Int pocCycle = 1 << getSPS()->getBitsForPOC();
383  if (!pocHasMsb)
384  {
385    poc = poc & (pocCycle - 1);
386  }
387
388  while ( iterPic != rcListPic.end() )
389  {
390    pcPic = *(iterPic);
391    if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced())
392    {
393      Int picPoc = pcPic->getPOC();
394      if (!pocHasMsb)
395      {
396        picPoc = picPoc & (pocCycle - 1);
397      }
398
399      if (poc == picPoc)
400      {
401        if(pcPic->getIsLongTerm())
402        {
403          return pcPic;
404        }
405        else
406        {
407          pcStPic = pcPic;
408        }
409        break;
410      }
411    }
412
413    iterPic++;
414  }
415
416  return  pcStPic;
417}
418
419Void TComSlice::setRefPOCList       ()
420{
421  for (Int iDir = 0; iDir < NUM_REF_PIC_LIST_01; iDir++)
422  {
423    for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
424    {
425      m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
426#if NH_MV
427      m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId();
428#endif
429    }
430  }
431
432}
433
434Void TComSlice::setList1IdxToList0Idx()
435{
436  Int idxL0, idxL1;
437  for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ )
438  {
439    m_list1IdxToList0Idx[idxL1] = -1;
440    for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ )
441    {
442      if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
443      {
444        m_list1IdxToList0Idx[idxL1] = idxL0;
445        break;
446      }
447    }
448  }
449}
450
451#if !NH_MV
452Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
453{
454    if (m_eSliceType == I_SLICE)
455    {
456      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
457      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
458
459    if (!checkNumPocTotalCurr)
460    {
461      return;
462    }
463  }
464
465  TComPic*  pcRefPic= NULL;
466  static const UInt MAX_NUM_NEGATIVE_PICTURES=16;
467  TComPic*  RefPicSetStCurr0[MAX_NUM_NEGATIVE_PICTURES];
468  TComPic*  RefPicSetStCurr1[MAX_NUM_NEGATIVE_PICTURES];
469  TComPic*  RefPicSetLtCurr[MAX_NUM_NEGATIVE_PICTURES];
470  UInt NumPicStCurr0 = 0;
471  UInt NumPicStCurr1 = 0;
472  UInt NumPicLtCurr = 0;
473  Int i;
474
475  for(i=0; i < m_pRPS->getNumberOfNegativePictures(); i++)
476  {
477    if(m_pRPS->getUsed(i))
478    {
479      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
480      pcRefPic->setIsLongTerm(0);
481      pcRefPic->getPicYuvRec()->extendPicBorder();
482      RefPicSetStCurr0[NumPicStCurr0] = pcRefPic;
483      NumPicStCurr0++;
484      pcRefPic->setCheckLTMSBPresent(false);
485    }
486  }
487
488  for(; i < m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures(); i++)
489  {
490    if(m_pRPS->getUsed(i))
491    {
492      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
493      pcRefPic->setIsLongTerm(0);
494      pcRefPic->getPicYuvRec()->extendPicBorder();
495      RefPicSetStCurr1[NumPicStCurr1] = pcRefPic;
496      NumPicStCurr1++;
497      pcRefPic->setCheckLTMSBPresent(false);
498    }
499  }
500
501  for(i = m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()+m_pRPS->getNumberOfLongtermPictures()-1; i > m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()-1 ; i--)
502  {
503    if(m_pRPS->getUsed(i))
504    {
505      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
506      pcRefPic->setIsLongTerm(1);
507      pcRefPic->getPicYuvRec()->extendPicBorder();
508      RefPicSetLtCurr[NumPicLtCurr] = pcRefPic;
509      NumPicLtCurr++;
510    }
511    if(pcRefPic==NULL)
512    {
513      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
514    }
515    pcRefPic->setCheckLTMSBPresent(m_pRPS->getCheckLTMSBPresent(i));
516  }
517
518  // ref_pic_list_init
519  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
520  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
521  Int numPicTotalCurr = NumPicStCurr0 + NumPicStCurr1 + NumPicLtCurr;
522
523  if (checkNumPocTotalCurr)
524  {
525    // 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:
526    // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
527    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
528    if (getRapPicFlag())
529    {
530      assert(numPicTotalCurr == 0);
531    }
532
533    if (m_eSliceType == I_SLICE)
534    {
535      return;
536    }
537
538    assert(numPicTotalCurr > 0);
539    // general tier and level limit:
540    assert(numPicTotalCurr <= 8);
541  }
542
543  Int cIdx = 0;
544  for ( i=0; i<NumPicStCurr0; i++, cIdx++)
545  {
546    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
547  }
548  for ( i=0; i<NumPicStCurr1; i++, cIdx++)
549  {
550    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
551  }
552  for ( i=0; i<NumPicLtCurr;  i++, cIdx++)
553  {
554    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
555  }
556  assert(cIdx == numPicTotalCurr);
557
558  if (m_eSliceType==B_SLICE)
559  {
560    cIdx = 0;
561    for ( i=0; i<NumPicStCurr1; i++, cIdx++)
562    {
563      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
564    }
565    for ( i=0; i<NumPicStCurr0; i++, cIdx++)
566    {
567      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
568    }
569    for ( i=0; i<NumPicLtCurr;  i++, cIdx++)
570    {
571      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
572    }
573    assert(cIdx == numPicTotalCurr);
574  }
575
576  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
577
578  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[REF_PIC_LIST_0]; rIdx ++)
579  {
580    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPicTotalCurr;
581    assert(cIdx >= 0 && cIdx < numPicTotalCurr);
582    m_apcRefPicList[REF_PIC_LIST_0][rIdx] = rpsCurrList0[ cIdx ];
583    m_bIsUsedAsLongTerm[REF_PIC_LIST_0][rIdx] = ( cIdx >= NumPicStCurr0 + NumPicStCurr1 );
584  }
585  if ( m_eSliceType != B_SLICE )
586  {
587    m_aiNumRefIdx[REF_PIC_LIST_1] = 0;
588    ::memset( m_apcRefPicList[REF_PIC_LIST_1], 0, sizeof(m_apcRefPicList[REF_PIC_LIST_1]));
589  }
590  else
591  {
592    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[REF_PIC_LIST_1]; rIdx ++)
593    {
594      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPicTotalCurr;
595      assert(cIdx >= 0 && cIdx < numPicTotalCurr);
596      m_apcRefPicList[REF_PIC_LIST_1][rIdx] = rpsCurrList1[ cIdx ];
597      m_bIsUsedAsLongTerm[REF_PIC_LIST_1][rIdx] = ( cIdx >= NumPicStCurr0 + NumPicStCurr1 );
598    }
599  }
600}
601#else
602Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
603                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr )
604{
605  if (!checkNumPocTotalCurr)
606  {
607    if (m_eSliceType == I_SLICE)
608    {     
609      return;
610    }   
611  }
612
613  TComPic*  pcRefPic= NULL;
614  TComPic*  RefPicSetStCurr0[16];
615  TComPic*  RefPicSetStCurr1[16];
616  TComPic*  RefPicSetLtCurr[16];
617  UInt NumPocStCurr0 = 0;
618  UInt NumPocStCurr1 = 0;
619  UInt NumPocLtCurr = 0;
620  Int i;
621#if NH_3D
622  m_pocsInCurrRPSs.clear();
623#endif
624  for(i=0; i < m_pRPS->getNumberOfNegativePictures(); i++)
625  {
626    if(m_pRPS->getUsed(i))
627    {
628      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
629      pcRefPic->setIsLongTerm(0);
630      pcRefPic->getPicYuvRec()->extendPicBorder();
631      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
632      NumPocStCurr0++;
633      pcRefPic->setCheckLTMSBPresent(false); 
634#if NH_3D
635      m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() ); 
636#endif
637    }
638  }
639 
640  for(; i < m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures(); i++)
641  {
642    if(m_pRPS->getUsed(i))
643    {
644      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
645      pcRefPic->setIsLongTerm(0);
646      pcRefPic->getPicYuvRec()->extendPicBorder();
647      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
648      NumPocStCurr1++;
649      pcRefPic->setCheckLTMSBPresent(false); 
650#if NH_3D
651      m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() ); 
652#endif
653    }
654  }
655 
656  for(i = m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()+m_pRPS->getNumberOfLongtermPictures()-1; i > m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()-1 ; i--)
657  {
658    if(m_pRPS->getUsed(i))
659    {
660      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
661      pcRefPic->setIsLongTerm(1);
662      pcRefPic->getPicYuvRec()->extendPicBorder();
663      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
664      NumPocLtCurr++;
665#if NH_3D
666      m_pocsInCurrRPSs.push_back( pcRefPic->getPOC() ); 
667#endif
668    }
669    if(pcRefPic==NULL) 
670    {
671      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
672    }
673    pcRefPic->setCheckLTMSBPresent(m_pRPS->getCheckLTMSBPresent(i)); 
674  }
675
676  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 
677#if NH_3D
678  assert( numPocInterCurr == (Int) m_pocsInCurrRPSs.size() ); 
679#endif
680  numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( );
681  assert( numPocTotalCurr == getNumRpsCurrTempList() );
682
683  if (checkNumPocTotalCurr)
684  {
685    // 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:
686    // - 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.
687    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
688    if ( getRapPicFlag() && m_layerId == 0 )
689    {
690      assert(numPocTotalCurr == 0);
691    }
692
693    if (m_eSliceType == I_SLICE)
694    {
695      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
696      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
697     
698      return;
699    }
700   
701    assert(numPocTotalCurr > 0);
702   
703    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
704    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
705  }
706
707  std::vector<TComPic*>* refPicSetInterLayer[2] = { &refPicSetInterLayer0, &refPicSetInterLayer1}; 
708  Int numPocInterLayer[2] = { getNumActiveRefLayerPics0( ), getNumActiveRefLayerPics1( ) }; 
709 
710  TComPic**             refPicSetStCurr    [2] = { RefPicSetStCurr0, RefPicSetStCurr1 };
711  Int numPocStCurr[2] = { (Int)NumPocStCurr0, (Int)NumPocStCurr1 }; 
712
713  for (Int li = 0; li < ((m_eSliceType==B_SLICE) ? 2 : 1); li++)
714  { 
715    rpsCurrList   [li].resize(MAX_NUM_REF+1,NULL ); 
716    usedAsLongTerm[li].resize(MAX_NUM_REF+1,false); 
717
718    Int cIdx = 0;
719    for ( i=0; i < numPocStCurr[li]; i++, cIdx++)
720    {
721      rpsCurrList[li][cIdx] = refPicSetStCurr[li][i];
722      usedAsLongTerm [li][cIdx] = false; 
723    }
724
725    for ( i=0; i < numPocInterLayer[li];  i++, cIdx++)
726    {   
727      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[li])[i];
728      usedAsLongTerm [li][cIdx] = true; 
729    }
730
731    for ( i=0; i < numPocStCurr[1-li]; i++, cIdx++)
732    {
733      rpsCurrList[li][cIdx] = refPicSetStCurr[1-li][i];
734      usedAsLongTerm [li][cIdx] = false; 
735    }
736
737    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
738    {
739      rpsCurrList[li][cIdx] = RefPicSetLtCurr[i];
740      usedAsLongTerm [li][cIdx] = true; 
741    }
742
743    for ( i=0; i < numPocInterLayer[1-li];  i++, cIdx++)
744    {   
745      assert( cIdx < MAX_NUM_REF );   
746      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[1-li])[i];
747      usedAsLongTerm [li][cIdx] = true; 
748    }
749
750    assert(cIdx == numPocTotalCurr);
751  }
752}
753
754Void TComSlice::setRefPicList( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr )
755
756{
757  if (!checkNumPocTotalCurr)
758  {
759    if (m_eSliceType == I_SLICE)
760    {
761      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
762      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
763
764      return;
765    }   
766  }
767
768  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
769
770  for (Int li = 0; li < 2; li++)
771  {
772    if ( m_eSliceType == P_SLICE && li == 1 )
773    {
774      m_aiNumRefIdx[1] = 0;
775      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
776    } 
777    else
778    {
779      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
780      { 
781        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li ); 
782        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); 
783
784        assert( rpsCurrList[li][ orgIdx ] != NULL ); 
785        assert( rpsCurrList[li][ orgIdx ]->getSlice(0)->getDiscardableFlag() == 0 );    // Inter-layer RPS shall not contain picture with discardable_flag = 1.
786        m_apcRefPicList    [li][rIdx] = rpsCurrList    [li][ orgIdx ];
787        m_bIsUsedAsLongTerm[li][rIdx] = usedAsLongTerm [li][ orgIdx ] ; 
788      }
789    }
790  }
791}
792#endif
793
794
795Int TComSlice::getNumRpsCurrTempList() const
796{
797  Int numRpsCurrTempList = 0;
798
799  if (m_eSliceType == I_SLICE)
800  {
801    return 0;
802  }
803  for(UInt i=0; i < m_pRPS->getNumberOfNegativePictures()+ m_pRPS->getNumberOfPositivePictures() + m_pRPS->getNumberOfLongtermPictures(); i++)
804  {
805    if(m_pRPS->getUsed(i))
806    {
807      numRpsCurrTempList++;
808    }
809  }
810#if NH_MV
811    numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
812#endif
813  return numRpsCurrTempList;
814}
815
816Void TComSlice::initEqualRef()
817{
818  for (Int iDir = 0; iDir < NUM_REF_PIC_LIST_01; iDir++)
819  {
820    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
821    {
822      for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
823      {
824        m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
825      }
826    }
827  }
828}
829#if NH_3D
830#if NH_3D_TMVP
831Void TComSlice::generateAlterRefforTMVP()
832{
833  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
834  {       
835    if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0)
836    {
837        continue;
838    }
839    Bool bZeroIdxLtFlag = this->getRefPic(RefPicList(uiRefListIdx), 0)->getIsLongTerm();
840    for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ )
841    {
842      if ( ( bZeroIdxLtFlag && !this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) ||
843           (!bZeroIdxLtFlag &&  this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) )
844      {
845        this->setAlterRefIdx(RefPicList(uiRefListIdx),i);
846        break;
847      }
848    }
849  }
850}
851#endif
852#endif
853
854#if NH_3D
855Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset )
856{ 
857  Int voiInVps      = m_pcVPS->getVoiInVps(getViewIndex() ); 
858  if( m_pcVPS->getNumCp( voiInVps ) > 0 )
859  {   
860    if( m_pcVPS->getCpInSliceSegmentHeaderFlag( voiInVps ) )
861    {
862      for( Int m = 0; m < m_pcVPS->getNumCp( voiInVps ); m++ )
863      {     
864        Int j      = m_pcVPS->getCpRefVoi( voiInVps, m );
865        Int jInVps = m_pcVPS->getVoiInVps( j ); 
866
867        setCpScale   ( jInVps , aaiScale [ jInVps   ][ voiInVps ]);
868        setCpInvScale( jInVps , aaiScale [ voiInVps ][ jInVps   ]);
869        setCpOff     ( jInVps , aaiOffset[ jInVps   ][ voiInVps ]);
870        setCpInvOff  ( jInVps , aaiOffset[ voiInVps ][ jInVps   ]);
871      }
872    }
873  } 
874}
875#endif
876
877Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic)
878{
879  Int i;
880  TComSlice* curSlice = pic->getSlice(curSliceIdx);
881  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1 - curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
882  TComSlice* preSlice;
883  Int preColRefPOC;
884  for(i=curSliceIdx-1; i>=0; i--)
885  {
886    preSlice = pic->getSlice(i);
887    if(preSlice->getSliceType() != I_SLICE)
888    {
889      preColRefPOC  = preSlice->getRefPOC( RefPicList(1 - preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
890      if(currColRefPOC != preColRefPOC)
891      {
892        printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n");
893        exit(EXIT_FAILURE);
894      }
895      else
896      {
897        break;
898      }
899    }
900  }
901}
902
903Void TComSlice::checkCRA(const TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
904{
905  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
906  {
907    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
908    {
909      assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA);
910    }
911  }
912  for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++)
913  {
914    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
915    {
916      if (!pReferencePictureSet->getCheckLTMSBPresent(i))
917      {
918        assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA);
919      }
920      else
921      {
922        assert(pReferencePictureSet->getPOC(i) >= pocCRA);
923      }
924    }
925  }
926  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
927  {
928    pocCRA = getPOC();
929    associatedIRAPType = getNalUnitType();
930  }
931  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
932  {
933    pocCRA = getPOC();
934    associatedIRAPType = getNalUnitType();
935  }
936  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
937         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
938         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
939  {
940    pocCRA = getPOC();
941    associatedIRAPType = getNalUnitType();
942  }
943}
944
945/** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered.
946 * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture
947 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
948 * \param rcListPic reference to the reference picture list
949 * This function marks the reference pictures as "unused for reference" in the following conditions.
950 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list
951 * are marked as "unused for reference"
952 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
953 * Otherwise
954 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
955 *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA),
956 *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set
957 *    the bRefreshPending flag to false.
958 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
959 *    reference of the current picture.
960 * Note that the current picture is already placed in the reference list and its marking is not changed.
961 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
962 */
963Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, const bool bEfficientFieldIRAPEnabled)
964{
965  TComPic* rpcPic;
966  Int      pocCurr = getPOC();
967
968  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
969    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
970    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
971    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
972    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
973  {
974    // mark all pictures as not used for reference
975    TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
976    while (iterPic != rcListPic.end())
977    {
978      rpcPic = *(iterPic);
979      rpcPic->setCurrSliceIdx(0);
980      if (rpcPic->getPOC() != pocCurr)
981      {
982        rpcPic->getSlice(0)->setReferenced(false);
983      }
984      iterPic++;
985    }
986    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
987      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
988      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
989    {
990      pocCRA = pocCurr;
991    }
992    if (bEfficientFieldIRAPEnabled)
993    {
994    bRefreshPending = true;
995    }
996  }
997  else // CRA or No DR
998  {
999    if(bEfficientFieldIRAPEnabled && (getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL))
1000    {
1001      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending
1002      {
1003        TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
1004        while (iterPic != rcListPic.end())
1005        {
1006          rpcPic = *(iterPic);
1007          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != m_iLastIDR)
1008          {
1009            rpcPic->getSlice(0)->setReferenced(false);
1010          }
1011          iterPic++;
1012        }
1013        bRefreshPending = false; 
1014      }
1015    }
1016    else
1017    {
1018      if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
1019      {
1020        TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1021        while (iterPic != rcListPic.end())
1022        {
1023          rpcPic = *(iterPic);
1024          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
1025          {
1026            rpcPic->getSlice(0)->setReferenced(false);
1027          }
1028          iterPic++;
1029        }
1030        bRefreshPending = false;
1031      }
1032    }
1033    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
1034    {
1035      bRefreshPending = true;
1036      pocCRA = pocCurr;
1037    }
1038  }
1039}
1040
1041Void TComSlice::copySliceInfo(TComSlice *pSrc)
1042{
1043  assert( pSrc != NULL );
1044
1045  Int i, j, k;
1046
1047  m_iPOC                 = pSrc->m_iPOC;
1048  m_eNalUnitType         = pSrc->m_eNalUnitType;
1049#if NH_MV
1050  m_layerId              = pSrc->m_layerId;
1051  // GT: Copying of several other values might be be missing here, or is above not necessary?
1052#endif
1053  m_eSliceType           = pSrc->m_eSliceType;
1054  m_iSliceQp             = pSrc->m_iSliceQp;
1055#if ADAPTIVE_QP_SELECTION
1056  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
1057#endif
1058  m_ChromaQpAdjEnabled = pSrc->m_ChromaQpAdjEnabled;
1059  m_deblockingFilterDisable   = pSrc->m_deblockingFilterDisable;
1060  m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag;
1061  m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2;
1062  m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
1063
1064  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
1065  {
1066    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
1067  }
1068
1069  for (i = 0; i < MAX_NUM_REF; i++)
1070  {
1071    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
1072  }
1073
1074  m_bCheckLDC             = pSrc->m_bCheckLDC;
1075  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
1076  for (UInt component = 0; component < MAX_NUM_COMPONENT; component++)
1077  {
1078    m_iSliceChromaQpDelta[component] = pSrc->m_iSliceChromaQpDelta[component];
1079  }
1080  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
1081  {
1082    for (j = 0; j < MAX_NUM_REF; j++)
1083    {
1084      m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
1085      m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
1086      m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
1087#if NH_MV
1088      m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j];
1089#endif
1090    }
1091    m_bIsUsedAsLongTerm[i][MAX_NUM_REF] = pSrc->m_bIsUsedAsLongTerm[i][MAX_NUM_REF];
1092  }
1093  m_iDepth               = pSrc->m_iDepth;
1094
1095  // referenced slice
1096  m_bRefenced            = pSrc->m_bRefenced;
1097
1098  // access channel
1099#if NH_MV
1100  m_pcVPS                = pSrc->m_pcVPS;
1101#endif
1102  m_pRPS                = pSrc->m_pRPS;
1103  m_iLastIDR             = pSrc->m_iLastIDR;
1104
1105  m_pcPic                = pSrc->m_pcPic;
1106
1107  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
1108  m_colRefIdx            = pSrc->m_colRefIdx;
1109
1110  setLambdas(pSrc->getLambdas());
1111
1112  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
1113  {
1114    for (j = 0; j < MAX_NUM_REF; j++)
1115    {
1116      for (k =0; k < MAX_NUM_REF; k++)
1117      {
1118        m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k];
1119      }
1120    }
1121  }
1122
1123  m_uiTLayer                      = pSrc->m_uiTLayer;
1124  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
1125
1126  m_sliceMode                     = pSrc->m_sliceMode;
1127  m_sliceArgument                 = pSrc->m_sliceArgument;
1128  m_sliceCurStartCtuTsAddr        = pSrc->m_sliceCurStartCtuTsAddr;
1129  m_sliceCurEndCtuTsAddr          = pSrc->m_sliceCurEndCtuTsAddr;
1130  m_sliceIdx                      = pSrc->m_sliceIdx;
1131  m_sliceSegmentMode              = pSrc->m_sliceSegmentMode;
1132  m_sliceSegmentArgument          = pSrc->m_sliceSegmentArgument;
1133  m_sliceSegmentCurStartCtuTsAddr = pSrc->m_sliceSegmentCurStartCtuTsAddr;
1134  m_sliceSegmentCurEndCtuTsAddr   = pSrc->m_sliceSegmentCurEndCtuTsAddr;
1135  m_nextSlice                     = pSrc->m_nextSlice;
1136  m_nextSliceSegment              = pSrc->m_nextSliceSegment;
1137
1138  for ( UInt e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
1139  {
1140    for ( UInt n=0 ; n<MAX_NUM_REF ; n++ )
1141    {
1142      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(WPScalingParam)*MAX_NUM_COMPONENT );
1143    }
1144  }
1145
1146  for( UInt ch = 0 ; ch < MAX_NUM_CHANNEL_TYPE; ch++)
1147  {
1148    m_saoEnabledFlag[ch] = pSrc->m_saoEnabledFlag[ch];
1149  }
1150
1151  m_cabacInitFlag                 = pSrc->m_cabacInitFlag;
1152
1153  m_bLMvdL1Zero                   = pSrc->m_bLMvdL1Zero;
1154  m_LFCrossSliceBoundaryFlag      = pSrc->m_LFCrossSliceBoundaryFlag;
1155  m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
1156  m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
1157  m_encCABACTableIdx              = pSrc->m_encCABACTableIdx;
1158
1159#if NH_MV
1160  // Additional slice header syntax elements
1161  m_pocResetFlag               = pSrc->m_pocResetFlag; 
1162  m_discardableFlag            = pSrc->m_discardableFlag; 
1163  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
1164  m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1;
1165
1166  for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ )
1167  {
1168    m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; 
1169  }
1170#endif
1171#if NH_3D_DIS
1172  m_bApplyDIS = pSrc->m_bApplyDIS;
1173#endif
1174#if NH_3D_IC
1175  m_bApplyIC = pSrc->m_bApplyIC;
1176  m_icSkipParseFlag = pSrc->m_icSkipParseFlag;
1177#endif
1178
1179}
1180
1181
1182/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
1183 * \param uiTLayer Temporal layer ID of the current slice
1184 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
1185 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
1186 * temporal_layer_switching_point_flag is set accordingly.
1187 */
1188Void TComSlice::setTLayerInfo( UInt uiTLayer )
1189{
1190  m_uiTLayer = uiTLayer;
1191}
1192
1193/** Function for checking if this is a switching-point
1194*/
1195Bool TComSlice::isTemporalLayerSwitchingPoint(TComList<TComPic*>& rcListPic)
1196{
1197  TComPic* rpcPic;
1198  // loop through all pictures in the reference picture buffer
1199  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1200  while ( iterPic != rcListPic.end())
1201  {
1202    rpcPic = *(iterPic++);
1203    if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC())
1204    {
1205      if(rpcPic->getTLayer() >= getTLayer())
1206      {
1207        return false;
1208      }
1209    }
1210  }
1211  return true;
1212}
1213
1214/** Function for checking if this is a STSA candidate
1215 */
1216Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate(TComList<TComPic*>& rcListPic)
1217{
1218  TComPic* rpcPic;
1219
1220  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1221  while ( iterPic != rcListPic.end())
1222  {
1223    rpcPic = *(iterPic++);
1224    if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
1225    {
1226      if(rpcPic->getTLayer() >= getTLayer())
1227      {
1228        return false;
1229      }
1230    }
1231  }
1232  return true;
1233}
1234
1235
1236Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
1237{
1238  TComPic* rpcPic;
1239
1240  Int nalUnitType = this->getNalUnitType();
1241
1242  // When a picture is a leading picture, it shall be a RADL or RASL picture.
1243  if(this->getAssociatedIRAPPOC() > this->getPOC())
1244  {
1245    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
1246    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
1247       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
1248    {
1249      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1250             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
1251             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1252             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
1253    }
1254  }
1255
1256  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
1257  if(this->getAssociatedIRAPPOC() < this->getPOC())
1258  {
1259    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
1260           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
1261           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
1262           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
1263  }
1264
1265  // No RASL pictures shall be present in the bitstream that are associated
1266  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
1267  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1268     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1269  {
1270    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
1271           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
1272  }
1273
1274  // No RASL pictures shall be present in the bitstream that are associated with
1275  // an IDR picture.
1276  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1277     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1278  {
1279    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
1280           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
1281  }
1282
1283  // No RADL pictures shall be present in the bitstream that are associated with
1284  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
1285  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
1286  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1287     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
1288  {
1289    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
1290           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
1291  }
1292
1293  // loop through all pictures in the reference picture buffer
1294  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1295  while ( iterPic != rcListPic.end())
1296  {
1297    rpcPic = *(iterPic++);
1298    if(!rpcPic->getReconMark())
1299    {
1300      continue;
1301    }
1302    if (rpcPic->getPOC() == this->getPOC())
1303    {
1304      continue;
1305    }
1306
1307    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
1308    // in decoding order shall precede the IRAP picture in output order.
1309    // (Note that any picture following in output order would be present in the DPB)
1310    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
1311    {
1312      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
1313         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
1314         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
1315         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
1316         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
1317         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
1318      {
1319        assert(rpcPic->getPOC() < this->getPOC());
1320      }
1321    }
1322
1323    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
1324    // in decoding order shall precede any RADL picture associated with the IRAP
1325    // picture in output order.
1326    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
1327    {
1328      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1329          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
1330      {
1331        // rpcPic precedes the IRAP in decoding order
1332        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
1333        {
1334          // rpcPic must not be the IRAP picture
1335          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
1336          {
1337            assert(rpcPic->getPOC() < this->getPOC());
1338          }
1339        }
1340      }
1341    }
1342
1343    // When a picture is a leading picture, it shall precede, in decoding order,
1344    // all trailing pictures that are associated with the same IRAP picture.
1345      if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1346         nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
1347         nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1348         nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
1349      {
1350        if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
1351        {
1352          // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
1353          // rpcPic would violate the constraint if it was a trailing picture
1354          assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
1355        }
1356      }
1357
1358    // Any RASL picture associated with a CRA or BLA picture shall precede any
1359    // RADL picture associated with the CRA or BLA picture in output order
1360    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1361       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1362    {
1363      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
1364          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
1365          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
1366          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
1367          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
1368      {
1369        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
1370           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
1371        {
1372          assert(rpcPic->getPOC() > this->getPOC());
1373        }
1374      }
1375    }
1376
1377    // Any RASL picture associated with a CRA picture shall follow, in output
1378    // order, any IRAP picture that precedes the CRA picture in decoding order.
1379    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1380       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1381    {
1382      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
1383      {
1384        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
1385           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
1386            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
1387            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
1388            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
1389            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
1390            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
1391        {
1392          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
1393        }
1394      }
1395    }
1396  }
1397}
1398
1399
1400
1401/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1402*/
1403Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, const TComReferencePictureSet *pReferencePictureSet)
1404{
1405  TComPic* rpcPic;
1406  Int i, isReference;
1407
1408  checkLeadingPictureRestrictions(rcListPic);
1409
1410  // loop through all pictures in the reference picture buffer
1411  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1412  while ( iterPic != rcListPic.end())
1413  {
1414    rpcPic = *(iterPic++);
1415
1416    if(!rpcPic->getSlice( 0 )->isReferenced())
1417    {
1418      continue;
1419    }
1420
1421    isReference = 0;
1422    // loop through all pictures in the Reference Picture Set
1423    // to see if the picture should be kept as reference picture
1424    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
1425    {
1426      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
1427      {
1428        isReference = 1;
1429        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1430        rpcPic->setIsLongTerm(0);
1431      }
1432    }
1433    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
1434    {
1435      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1436      {
1437        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i))
1438        {
1439          isReference = 1;
1440          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1441        }
1442      }
1443      else
1444      {
1445        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1446        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1447        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1448        if(rpcPic->getIsLongTerm() && curPoc == refPoc)
1449        {
1450          isReference = 1;
1451          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1452        }
1453      }
1454
1455    }
1456#if NH_MV
1457    if( isReference ) // Current picture is in the temporal RPS
1458    {
1459      assert( rpcPic->getSlice(0)->getDiscardableFlag() == 0 ); // Temporal RPS shall not contain picture with discardable_flag equal to 1
1460    }
1461#endif
1462    // mark the picture as "unused for reference" if it is not in
1463    // the Reference Picture Set
1464    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)
1465    {
1466      rpcPic->getSlice( 0 )->setReferenced( false );
1467      rpcPic->setUsedByCurr(0);
1468      rpcPic->setIsLongTerm(0);
1469    }
1470    //check that pictures of higher temporal layers are not used
1471    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
1472    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
1473    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
1474    {
1475      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
1476    }
1477    //check that pictures marked as temporal layer non-reference pictures are not used for reference
1478    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
1479    {
1480      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false);
1481    }
1482  }
1483}
1484
1485/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1486*/
1487Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, const TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
1488{
1489  Int atLeastOneUnabledByRecoveryPoint = 0;
1490  Int atLeastOneFlushedByPreviousIDR = 0;
1491  TComPic* rpcPic;
1492  Int i, isAvailable;
1493  Int atLeastOneLost = 0;
1494  Int atLeastOneRemoved = 0;
1495  Int iPocLost = 0;
1496
1497  // loop through all long-term pictures in the Reference Picture Set
1498  // to see if the picture should be kept as reference picture
1499  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
1500  {
1501    isAvailable = 0;
1502    // loop through all pictures in the reference picture buffer
1503    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1504    while ( iterPic != rcListPic.end())
1505    {
1506      rpcPic = *(iterPic++);
1507      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1508      {
1509        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
1510        {
1511          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1512          {
1513            isAvailable = 0;
1514          }
1515          else
1516          {
1517            isAvailable = 1;
1518          }
1519        }
1520      }
1521      else
1522      {
1523        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1524        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1525        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1526        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
1527        {
1528          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1529          {
1530            isAvailable = 0;
1531          }
1532          else
1533          {
1534            isAvailable = 1;
1535          }
1536        }
1537      }
1538    }
1539    // if there was no such long-term check the short terms
1540    if(!isAvailable)
1541    {
1542      iterPic = rcListPic.begin();
1543      while ( iterPic != rcListPic.end())
1544      {
1545        rpcPic = *(iterPic++);
1546
1547        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1548        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
1549        Int refPoc = pReferencePictureSet->getPOC(i);
1550        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
1551        {
1552          curPoc = curPoc & (pocCycle - 1);
1553          refPoc = refPoc & (pocCycle - 1);
1554        }
1555
1556        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
1557        {
1558          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1559          {
1560            isAvailable = 0;
1561          }
1562          else
1563          {
1564            isAvailable = 1;
1565            rpcPic->setIsLongTerm(1);
1566            break;
1567          }
1568        }
1569      }
1570    }
1571    // report that a picture is lost if it is in the Reference Picture Set
1572    // but not available as reference picture
1573    if(isAvailable == 0)
1574    {
1575      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1576      {
1577        if(!pReferencePictureSet->getUsed(i) )
1578        {
1579          if(printErrors)
1580          {
1581            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1582          }
1583          atLeastOneRemoved = 1;
1584        }
1585        else
1586        {
1587          if(printErrors)
1588          {
1589            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1590          }
1591          atLeastOneLost = 1;
1592          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1593        }
1594      }
1595      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
1596      {
1597        atLeastOneUnabledByRecoveryPoint = 1;
1598      }
1599      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
1600      {
1601        atLeastOneFlushedByPreviousIDR = 1;
1602      }
1603    }
1604  }
1605  // loop through all short-term pictures in the Reference Picture Set
1606  // to see if the picture should be kept as reference picture
1607  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
1608  {
1609    isAvailable = 0;
1610    // loop through all pictures in the reference picture buffer
1611    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1612    while ( iterPic != rcListPic.end())
1613    {
1614      rpcPic = *(iterPic++);
1615
1616      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1617      {
1618        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1619        {
1620          isAvailable = 0;
1621        }
1622        else
1623        {
1624          isAvailable = 1;
1625        }
1626      }
1627    }
1628    // report that a picture is lost if it is in the Reference Picture Set
1629    // but not available as reference picture
1630    if(isAvailable == 0)
1631    {
1632      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1633      {
1634        if(!pReferencePictureSet->getUsed(i) )
1635        {
1636          if(printErrors)
1637          {
1638            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1639          }
1640          atLeastOneRemoved = 1;
1641        }
1642        else
1643        {
1644          if(printErrors)
1645          {
1646            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1647          }
1648          atLeastOneLost = 1;
1649          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1650        }
1651      }
1652      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
1653      {
1654        atLeastOneUnabledByRecoveryPoint = 1;
1655      }
1656      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
1657      {
1658        atLeastOneFlushedByPreviousIDR = 1;
1659      }
1660    }
1661  }
1662
1663  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
1664  {
1665    return -1;
1666  }   
1667  if(atLeastOneLost)
1668  {
1669    return iPocLost+1;
1670  }
1671  if(atLeastOneRemoved)
1672  {
1673    return -2;
1674  }
1675  else
1676  {
1677    return 0;
1678  }
1679}
1680
1681/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1682*/
1683Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, const TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint, const Bool bEfficientFieldIRAPEnabled)
1684{
1685  TComPic* rpcPic;
1686  Int i, j;
1687  Int k = 0;
1688  Int nrOfNegativePictures = 0;
1689  Int nrOfPositivePictures = 0;
1690  TComReferencePictureSet* pLocalRPS = this->getLocalRPS();
1691  (*pLocalRPS)=TComReferencePictureSet();
1692
1693  Bool irapIsInRPS = false; // Used when bEfficientFieldIRAPEnabled==true
1694
1695  // loop through all pictures in the Reference Picture Set
1696  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1697  {
1698    j = 0;
1699    // loop through all pictures in the reference picture buffer
1700    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1701    while ( iterPic != rcListPic.end())
1702    {
1703      j++;
1704      rpcPic = *(iterPic++);
1705
1706      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1707      {
1708        // This picture exists as a reference picture
1709        // and should be added to the explicit Reference Picture Set
1710        pLocalRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1711        pLocalRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
1712        if (bEfficientFieldIRAPEnabled)
1713        {
1714          pLocalRPS->setUsed(k, pLocalRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) );
1715        }
1716
1717        if(pLocalRPS->getDeltaPOC(k) < 0)
1718        {
1719          nrOfNegativePictures++;
1720        }
1721        else
1722        {
1723          if(bEfficientFieldIRAPEnabled && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
1724          {
1725            irapIsInRPS = true;
1726          }
1727          nrOfPositivePictures++;
1728        }
1729        k++;
1730      }
1731    }
1732  }
1733
1734  Bool useNewRPS = false;
1735  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS.
1736  if(bEfficientFieldIRAPEnabled && m_pcPic->isField() && !irapIsInRPS)
1737  {
1738    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1739    while ( iterPic != rcListPic.end())
1740    {
1741      rpcPic = *(iterPic++);
1742      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
1743      {
1744        pLocalRPS->setDeltaPOC(k, 1);
1745        pLocalRPS->setUsed(k, true);
1746        nrOfPositivePictures++;
1747        k ++;
1748        useNewRPS = true;
1749      }
1750    }
1751  }
1752  pLocalRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1753  pLocalRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1754  pLocalRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1755  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1756  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1757  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1758  if (!pReferencePictureSet->getInterRPSPrediction() || useNewRPS )
1759  {
1760    pLocalRPS->setInterRPSPrediction(false);
1761    pLocalRPS->setNumRefIdc(0);
1762  }
1763  else
1764  {
1765    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1766    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1767    const TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1768    Int iRefPics = pcRefRPS->getNumberOfPictures();
1769    Int iNewIdc=0;
1770    for(i=0; i<= iRefPics; i++)
1771    {
1772      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1773      Int iRefIdc = 0;
1774      for (j=0; j < pLocalRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1775      {
1776        if ( (deltaPOC + deltaRPS) == pLocalRPS->getDeltaPOC(j))
1777        {
1778          if (pLocalRPS->getUsed(j))
1779          {
1780            iRefIdc = 1;
1781          }
1782          else
1783          {
1784            iRefIdc = 2;
1785          }
1786        }
1787      }
1788      pLocalRPS->setRefIdc(i, iRefIdc);
1789      iNewIdc++;
1790    }
1791    pLocalRPS->setInterRPSPrediction(true);
1792    pLocalRPS->setNumRefIdc(iNewIdc);
1793    pLocalRPS->setDeltaRPS(deltaRPS);
1794    pLocalRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1795  }
1796
1797  this->setRPS(pLocalRPS);
1798  this->setRPSidx(-1);
1799}
1800
1801//! get AC and DC values for weighted pred
1802Void  TComSlice::getWpAcDcParam(WPACDCParam *&wp)
1803{
1804  wp = m_weightACDCParam;
1805}
1806
1807//! init AC and DC values for weighted pred
1808Void  TComSlice::initWpAcDcParam()
1809{
1810  for(Int iComp = 0; iComp < MAX_NUM_COMPONENT; iComp++ )
1811  {
1812    m_weightACDCParam[iComp].iAC = 0;
1813    m_weightACDCParam[iComp].iDC = 0;
1814  }
1815}
1816
1817//! get tables for weighted prediction
1818Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, WPScalingParam *&wp )
1819{
1820  assert (e<NUM_REF_PIC_LIST_01);
1821  wp = m_weightPredTable[e][iRefIdx];
1822}
1823
1824//! reset Default WP tables settings : no weight.
1825Void  TComSlice::resetWpScaling()
1826{
1827  for ( Int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
1828  {
1829    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1830    {
1831      for ( Int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
1832      {
1833        WPScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1834        pwp->bPresentFlag      = false;
1835        pwp->uiLog2WeightDenom = 0;
1836        pwp->uiLog2WeightDenom = 0;
1837        pwp->iWeight           = 1;
1838        pwp->iOffset           = 0;
1839      }
1840    }
1841  }
1842}
1843
1844//! init WP table
1845Void  TComSlice::initWpScaling(const TComSPS *sps)
1846{
1847  const Bool bUseHighPrecisionPredictionWeighting = sps->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag();
1848  for ( Int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
1849  {
1850    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1851    {
1852      for ( Int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
1853      {
1854        WPScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1855        if ( !pwp->bPresentFlag )
1856        {
1857          // Inferring values not present :
1858          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1859          pwp->iOffset = 0;
1860        }
1861
1862        const Int offsetScalingFactor = bUseHighPrecisionPredictionWeighting ? 1 : (1 << (sps->getBitDepth(toChannelType(ComponentID(yuv)))-8));
1863
1864        pwp->w      = pwp->iWeight;
1865        pwp->o      = pwp->iOffset * offsetScalingFactor; //NOTE: This value of the ".o" variable is never used - .o is set immediately before it gets used
1866        pwp->shift  = pwp->uiLog2WeightDenom;
1867        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1868      }
1869    }
1870  }
1871}
1872
1873// ------------------------------------------------------------------------------------------------
1874// Video parameter set (VPS)
1875// ------------------------------------------------------------------------------------------------
1876TComVPS::TComVPS()
1877: m_VPSId                     (  0)
1878, m_uiMaxTLayers              (  1)
1879#if NH_MV
1880, m_uiMaxLayersMinus1         (  0)
1881#else
1882, m_uiMaxLayers               (  1)
1883#endif
1884, m_bTemporalIdNestingFlag    (false)
1885, m_numHrdParameters          (  0)
1886#if NH_MV
1887, m_maxLayerId             (  0)
1888#else
1889, m_maxNuhReservedZeroLayerId (  0)
1890#endif
1891, m_hrdParameters             ()
1892, m_hrdOpSetIdx               ()
1893, m_cprmsPresentFlag          ()
1894{
1895#if NH_MV
1896  m_vpsBaseLayerInternalFlag = true; 
1897  m_vpsBaseLayerAvailableFlag = true; 
1898
1899  m_numViews = 0; 
1900
1901#endif
1902
1903  for( Int i = 0; i < MAX_TLAYER; i++)
1904  {
1905    m_numReorderPics[i] = 0;
1906    m_uiMaxDecPicBuffering[i] = 1;
1907    m_uiMaxLatencyIncrease[i] = 0;
1908  }
1909#if NH_MV
1910  for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ )
1911  { 
1912    for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ )
1913    {
1914      m_layerIdIncludedFlag[lsIdx][layerId] = (( lsIdx == 0 ) && ( layerId == 0 )) ; 
1915    }
1916  } 
1917  m_vpsNumProfileTierLevelMinus1 = -1; 
1918   
1919  m_numAddLayerSets              = 0;   
1920  m_numAddOlss                   = 0; 
1921  m_defaultOutputLayerIdc     = 0; 
1922 
1923  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
1924  {
1925    m_layerSetIdxForOlsMinus1[i]  = -1; 
1926    for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
1927    {
1928      m_profileTierLevelIdx[i][j] = -1; 
1929      m_outputLayerFlag[i][j] = false; 
1930    }
1931    m_altOutputLayerFlag[ i ]       = false; 
1932  }
1933
1934  m_repFormatIdxPresentFlag = false; 
1935  m_maxOneActiveRefLayerFlag = false; 
1936  m_vpsPocLsbAlignedFlag  = false; 
1937  m_directDepTypeLenMinus2   = 0;         
1938 
1939
1940  m_vpsExtensionFlag = true; 
1941  m_vpsNonVuiExtensionLength = 0;
1942  m_splittingFlag    = false;
1943
1944 
1945  for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
1946  {
1947    m_scalabilityMaskFlag[i] = false;
1948    m_dimensionIdLen [i]  = -1; 
1949  }
1950
1951  m_vpsNuhLayerIdPresentFlag = false;
1952
1953  for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
1954  {
1955    m_vpsProfilePresentFlag   [i] = false;
1956    m_layerSetIdxForOlsMinus1       [i] = 0;
1957    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
1958    {
1959      m_outputLayerFlag[i][j] = false;
1960    }
1961  }
1962
1963  for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
1964  {
1965    m_layerIdInVps[i] =  (i == 0 ) ? 0 : -1;         
1966  }
1967
1968  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1969  {
1970    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
1971    m_numDirectRefLayers[i] = 0; 
1972#if NH_3D
1973    m_numRefListLayers[i] = 0; 
1974#endif
1975    m_vpsRepFormatIdx    [i] = 0; 
1976    m_pocLsbNotPresentFlag[i] = 0;   
1977    m_viewIdVal          [i] = 0; 
1978
1979#if NH_3D
1980    m_viewIndex         [i] = -1; 
1981#endif
1982
1983    for( Int j = 0; j < MAX_NUM_LAYERS; j++ )
1984    {
1985      m_directDependencyFlag[i][j] = false;
1986      m_directDependencyType[i][j] = -1; 
1987      m_dependencyFlag  [i][j]    = false; 
1988      m_idDirectRefLayer[i][j]    = -1; 
1989#if NH_3D
1990      m_idRefListLayer[i][j]    = -1; 
1991#endif
1992      m_idPredictedLayer[i][j]    = -1; 
1993      m_idRefLayer      [i][j]    = -1; 
1994      m_maxTidIlRefPicsPlus1[i][j]  = 7;
1995    }
1996
1997    for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ )
1998    {
1999      m_dimensionId[i][j] = 0;
2000    }
2001#if NH_3D_ARP
2002#endif
2003  } 
2004#endif
2005}
2006
2007TComVPS::~TComVPS()
2008{
2009}
2010
2011#if NH_MV
2012
2013Bool TComVPS::checkVPSExtensionSyntax()
2014{
2015  for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
2016  {
2017    // check layer_id_in_nuh constraint
2018    assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
2019  }
2020
2021  //The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
2022  assert( getVpsNumRepFormatsMinus1() >= 0 ); 
2023  assert( getVpsNumRepFormatsMinus1() <= 255 ); 
2024
2025  // The value of num_add_layer_sets shall be in the range of 0 to 1023, inclusive.
2026  assert( getNumAddLayerSets() >= 0 && getNumAddLayerSets() <= 1023 ); 
2027  return true; 
2028}
2029
2030Int TComVPS::getNumScalabilityTypes() const
2031{
2032  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
2033}
2034
2035Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType ) const
2036{
2037  assert( (Int)scalType >= 0 && (Int)scalType <= MAX_NUM_SCALABILITY_TYPES );
2038  assert( (Int)scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
2039  Int scalIdx = 0; 
2040  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
2041  {
2042    scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
2043
2044  }
2045
2046  return scalIdx; 
2047}
2048Void TComVPS::setScalabilityMaskFlag( UInt val )
2049{
2050  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
2051  {
2052    setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 );
2053  }
2054}
2055
2056Void TComVPS::setRefLayers()
2057{
2058
2059  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
2060  {
2061    for( Int j = 0; j  <=  getMaxLayersMinus1(); j++ )
2062    {
2063      m_dependencyFlag[ i ][ j ] = getDirectDependencyFlag( i , j );
2064      for( Int k = 0; k < i; k++ )
2065      {
2066        if( getDirectDependencyFlag(i , k )  &&  m_dependencyFlag[k][j] )
2067        {
2068          m_dependencyFlag[ i ][ j ] = true;
2069        }
2070      }
2071    }
2072  }
2073
2074  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
2075  {
2076    Int iNuhLId = getLayerIdInNuh( i );
2077    Int d = 0;
2078#if NH_3D
2079    Int l = 0; 
2080#endif
2081    Int r = 0;
2082    Int p = 0;
2083
2084    for( Int j = 0; j  <=  getMaxLayersMinus1(); j++ )
2085    {
2086      Int jNuhLid = getLayerIdInNuh( j );
2087      if( getDirectDependencyFlag( i , j ) )
2088      {
2089        m_idDirectRefLayer[iNuhLId][d++] = jNuhLid;
2090      }
2091#if NH_3D
2092      if( getDirectDependencyFlag( i , j ) && ( getDepthId( iNuhLId ) == getDepthId( jNuhLid ) ))
2093      {
2094        m_idRefListLayer [iNuhLId][l++] = jNuhLid;
2095      }
2096#endif
2097
2098      if( getDependencyFlag( i , j ) )
2099      {
2100        m_idRefLayer      [iNuhLId][r++] = jNuhLid;
2101      }
2102      if( getDependencyFlag( j , i ) )
2103      {
2104        m_idPredictedLayer[iNuhLId][p++] = jNuhLid;
2105      }
2106    }
2107    m_numDirectRefLayers[ iNuhLId ] = d;
2108#if NH_3D
2109    m_numRefListLayers[ iNuhLId ] = l; 
2110#endif
2111
2112    m_numRefLayers      [ iNuhLId ] = r;
2113    m_numPredictedLayers[ iNuhLId ] = p;
2114  }
2115 
2116  Bool layerIdInListFlag[ 64 ]; 
2117  for( Int i = 0; i  <=  63; i++ )
2118  {
2119    layerIdInListFlag[ i ] = 0;
2120  }
2121
2122  Int k = 0; 
2123  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
2124  {
2125    Int iNuhLId = getLayerIdInNuh( i );
2126    if( getNumDirectRefLayers( iNuhLId )  ==  0 )
2127    {
2128      m_treePartitionLayerIdList[ k ][ 0 ] = iNuhLId;
2129      Int h = 1; 
2130      for( Int j = 0; j < getNumPredictedLayers( iNuhLId ); j++ ) 
2131      {
2132        Int predLId = getIdPredictedLayer( iNuhLId, j );
2133        if ( !layerIdInListFlag[ predLId ] )
2134        {
2135          m_treePartitionLayerIdList[ k ][ h++ ] = predLId;
2136          layerIdInListFlag[ predLId ] = 1; 
2137        }         
2138      }
2139      m_numLayersInTreePartition[ k++ ] = h;
2140    }
2141  }
2142  m_numIndependentLayers = k;
2143}
2144
2145
2146Void     TComVPS::initNumViews( )
2147{
2148  m_numViews = 1; 
2149#if NH_3D
2150  AOF( m_viewOIdxList.size() == 0 );   
2151  m_viewOIdxList.push_back( 0 );       
2152#endif
2153
2154  for( Int i = 0; i <=  getMaxLayersMinus1(); i++ )
2155  {
2156    Int lId = getLayerIdInNuh( i ); 
2157    if( i > 0 )
2158    {
2159      Bool newViewFlag = true; 
2160      for( Int j = 0; j < i; j++ )
2161      {
2162        if( getViewOrderIdx( lId )  ==  getViewOrderIdx( getLayerIdInNuh( j ) )  )
2163        {
2164          newViewFlag = false;
2165        }
2166      }
2167      if( newViewFlag )
2168      {
2169        m_numViews++;
2170#if NH_3D
2171        m_viewOIdxList.push_back( getViewOrderIdx( lId ) );       
2172#endif
2173      }
2174    }
2175  }
2176}
2177
2178
2179Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType ) const
2180{
2181  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
2182}
2183
2184#if NH_3D
2185Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag ) const
2186{
2187  Int foundLayerIdinNuh = -1; 
2188
2189  for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ )
2190  {
2191    Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); 
2192    if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) )  )
2193    {
2194      foundLayerIdinNuh = layerIdInNuh; 
2195      break; 
2196    }
2197  }
2198  return foundLayerIdinNuh;
2199}
2200
2201Void TComVPS::createCamPars(Int iNumViews)
2202{
2203  m_numCp                     .resize( iNumViews );
2204  m_cpRefVoi                  .resize( iNumViews );
2205  m_cpInSliceSegmentHeaderFlag.resize( iNumViews );
2206  m_cpPresentFlag             .resize( iNumViews ); 
2207  m_aaaiCodedScale            .resize( iNumViews ); 
2208  m_aaaiCodedOffset           .resize( iNumViews ); 
2209
2210  for ( Int i = 0; i < iNumViews ; i++ )
2211  {
2212    m_numCp                     [i] = 0; 
2213    m_cpRefVoi                  [i].resize( iNumViews );
2214    m_cpInSliceSegmentHeaderFlag[i] = false;         
2215    m_aaaiCodedScale            [i].resize( 2 );
2216    m_aaaiCodedOffset           [i].resize( 2 );       
2217    m_cpPresentFlag             [i].resize( iNumViews ); 
2218
2219    for ( Int j = 0; j < iNumViews; j++)
2220    {
2221      m_cpRefVoi             [i][j] = 0; 
2222      m_cpPresentFlag        [i][j] = false; 
2223    }
2224
2225    for ( Int j = 0; j < 2; j++ )
2226    {
2227      m_aaaiCodedScale       [i][j].resize( MAX_NUM_LAYERS );
2228      m_aaaiCodedOffset      [i][j].resize( MAX_NUM_LAYERS );
2229
2230      for ( Int k = 0; k < MAX_NUM_LAYERS; k++ )
2231      {
2232        m_aaaiCodedScale [i][j][k] = 0;
2233        m_aaaiCodedOffset[i][j][k] = 0;
2234      }
2235    }
2236  }
2237}
2238#endif // NH_3D
2239
2240
2241Int TComVPS::xGetDimBitOffset( Int j ) const
2242{
2243  Int dimBitOffset = 0; 
2244  if ( getSplittingFlag() && j == getNumScalabilityTypes() )
2245  {
2246     dimBitOffset = 6; 
2247  }
2248  else
2249  {
2250    for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++)
2251    {
2252      dimBitOffset += getDimensionIdLen( dimIdx ); 
2253    }
2254  }
2255  return dimBitOffset; 
2256}
2257
2258Int TComVPS::inferDimensionId( Int i, Int j ) const
2259{
2260    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); 
2261}
2262
2263Int TComVPS::inferLastDimsionIdLenMinus1() const
2264{
2265  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); 
2266}
2267
2268Int TComVPS::getNumLayersInIdList( Int lsIdx ) const
2269{
2270  assert( lsIdx >= 0 ); 
2271  assert( lsIdx <= getNumLayerSets() ); 
2272  return (Int) m_layerSetLayerIdList[ lsIdx ].size(); 
2273}
2274
2275Int    TComVPS::getNumOutputLayerSets() const
2276{
2277  return getNumAddOlss() + getNumLayerSets(); 
2278}
2279
2280
2281
2282Void TComVPS::deriveLayerSetLayerIdList()
2283{
2284  m_layerSetLayerIdList.resize( getVpsNumLayerSetsMinus1() + 1 ); 
2285  for (Int i = 0; i <= getVpsNumLayerSetsMinus1(); i++ )
2286  {
2287    for( Int m = 0; m  <= getVpsMaxLayerId(); m++ )
2288    {
2289      if( getLayerIdIncludedFlag( i, m) ) 
2290      {
2291        m_layerSetLayerIdList[ i ].push_back( m );       
2292      }
2293    }
2294  }
2295}
2296
2297Void TComVPS::initTargetLayerIdLists()
2298{
2299  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); 
2300  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); 
2301}
2302
2303Void TComVPS::deriveTargetLayerIdList( Int i )
2304{ 
2305  Int lsIdx = olsIdxToLsIdx( i );     
2306
2307  for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
2308  {
2309    if ( getNecessaryLayerFlag( i , j ))
2310    {
2311      m_targetDecLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); 
2312    }
2313
2314    if( getOutputLayerFlag( i, j  ))
2315    {
2316      m_targetOptLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
2317    }
2318  } 
2319  assert( getNumOutputLayersInOutputLayerSet( i ) > 0 ); 
2320}
2321
2322Bool TComVPS::inferOutputLayerFlag( Int i, Int j ) const
2323{
2324  Bool outputLayerFlag; 
2325  switch ( getDefaultOutputLayerIdc( ) )
2326  {
2327  case 0:
2328    outputLayerFlag = true; 
2329    break; 
2330  case 1:
2331    outputLayerFlag = ( j == m_layerSetLayerIdList[ olsIdxToLsIdx( i ) ].size() - 1 ); 
2332    break;
2333  case 2:
2334    if ( i == 0 && j == 0)
2335    {     
2336      outputLayerFlag = true;  // This is a software only fix for a bug in the spec. In spec outputLayerFlag is neither present nor inferred.
2337    }
2338    else
2339    {
2340      assert( 0 ); 
2341    }
2342    break; 
2343  default:     
2344    assert( 0 );
2345    break; 
2346  }
2347  return outputLayerFlag;
2348}
2349
2350Int TComVPS::getMaxSubLayersInLayerSetMinus1( Int i ) const
2351{
2352  Int maxSLMinus1 = 0; 
2353  for( Int k = 0; k < getNumLayersInIdList( i ); k++ )
2354  {
2355    Int lId = m_layerSetLayerIdList[i][k];
2356    maxSLMinus1 = std::max( maxSLMinus1, getSubLayersVpsMaxMinus1( getLayerIdInVps( lId ) ));
2357  }
2358  return maxSLMinus1;
2359}
2360
2361Bool TComVPS::getAltOutputLayerFlagVar( Int i ) const
2362{
2363  // Semantics variable not syntax element !
2364
2365  Bool altOptLayerFlag = false;     
2366  if ( i > 0 && getNumOutputLayersInOutputLayerSet( i ) == 1 && 
2367    getNumDirectRefLayers( getOlsHighestOutputLayerId( i ) ) > 0 )
2368  {
2369    altOptLayerFlag = getAltOutputLayerFlag( i ); 
2370  }
2371  return altOptLayerFlag;
2372}
2373
2374
2375
2376Int TComVPS::inferProfileTierLevelIdx(Int i, Int j) const
2377{
2378  Bool inferZero        = ( i == 0 && j == 0 &&  getVpsBaseLayerInternalFlag() );
2379  Bool inferGreaterZero = getNecessaryLayerFlag(i,j) && ( getVpsNumProfileTierLevelMinus1() == 0 ); 
2380  assert( inferZero || inferGreaterZero );
2381
2382  Bool ptlIdx = 0; // inference for greaterZero
2383  if ( inferZero )
2384  {
2385    ptlIdx = getMaxLayersMinus1() > 0 ? 1 : 0; 
2386    if ( inferGreaterZero )
2387    {
2388      assert( ptlIdx == 0 ); 
2389      // This should never happen since :
2390      // When vps_max_layers_minus1 is greater than 0, the value of vps_num_profile_tier_level_minus1 shall be greater than or equal to 1.
2391    }
2392  }
2393  return ptlIdx;
2394}
2395
2396Void TComVPS::deriveAddLayerSetLayerIdList(Int i)
2397{
2398  assert( m_layerSetLayerIdList.size() ==  ( getVpsNumLayerSetsMinus1() + 1 + i ) ); 
2399  std::vector<Int> layerSetLayerIdList;
2400
2401  for( Int treeIdx = 1; treeIdx < getNumIndependentLayers(); treeIdx++ )
2402  { 
2403    // The value of highest_layer_idx_plus1[ i ][ j ] shall be in the range of 0 to NumLayersInTreePartition[ j ], inclusive.
2404    assert( getHighestLayerIdxPlus1( i, treeIdx ) >= 0 && getHighestLayerIdxPlus1( i, treeIdx ) <= getNumLayersInTreePartition( treeIdx ) );
2405
2406    for( Int layerCnt = 0; layerCnt < getHighestLayerIdxPlus1( i, treeIdx ); layerCnt++ )
2407    {
2408      layerSetLayerIdList.push_back( getTreePartitionLayerIdList( treeIdx, layerCnt ) );
2409    }
2410  }
2411  m_layerSetLayerIdList.push_back( layerSetLayerIdList ); 
2412
2413  //It is a requirement of bitstream conformance that
2414  //NumLayersInIdList[ vps_num_layer_sets_minus1 + 1 + i ] shall be greater than 0.
2415  assert( getNumLayersInIdList( getVpsNumLayerSetsMinus1() + 1 + i ) > 0 );
2416}
2417
2418
2419Void TComVPS::deriveNecessaryLayerFlags(Int olsIdx)
2420{
2421  AOF( olsIdx >= 0 && olsIdx < getNumOutputLayerSets() ); 
2422  Int lsIdx = olsIdxToLsIdx( olsIdx );
2423  for( Int lsLayerIdx = 0; lsLayerIdx < getNumLayersInIdList( lsIdx) ; lsLayerIdx++ )
2424  {
2425    m_necessaryLayerFlag[ olsIdx ][ lsLayerIdx ] = 0;
2426  }
2427  for( Int lsLayerIdx = 0; lsLayerIdx < getNumLayersInIdList( lsIdx ); lsLayerIdx++ )
2428  {
2429    if( getOutputLayerFlag( olsIdx, lsLayerIdx  ))
2430    {
2431      m_necessaryLayerFlag[ olsIdx ][ lsLayerIdx ] = 1;
2432      Int currLayerId = getLayerSetLayerIdList( lsIdx, lsLayerIdx );
2433      for( Int rLsLayerIdx = 0; rLsLayerIdx < lsLayerIdx; rLsLayerIdx++ )
2434      {
2435        Int refLayerId = getLayerSetLayerIdList( lsIdx, rLsLayerIdx );
2436        if( getDependencyFlag( getLayerIdInVps( currLayerId ), getLayerIdInVps( refLayerId ) ) )
2437        {
2438          m_necessaryLayerFlag[ olsIdx ][ rLsLayerIdx ] = 1;
2439        }
2440      }
2441    }
2442  }
2443  m_numNecessaryLayers[ olsIdx ] = 0;
2444  for( Int lsLayerIdx = 0; lsLayerIdx < getNumLayersInIdList( lsIdx ); lsLayerIdx++ ) 
2445  {
2446    m_numNecessaryLayers[ olsIdx ]  +=  m_necessaryLayerFlag[ olsIdx ][ lsLayerIdx ];
2447  }
2448}
2449
2450Void TComVPS::printPTL() const
2451{
2452  std::vector<Int> idx; 
2453  std::vector<Int> num; 
2454  IntAry2d ptlInfo; 
2455
2456  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "PTLI" << std::endl; 
2457
2458  for ( Int i = 0; i <= getVpsNumProfileTierLevelMinus1(); i++ )
2459  {
2460    std::vector<Int> curPtlInfo;
2461    const ProfileTierLevel* ptl = getPTL( i )->getGeneralPTL(); 
2462    curPtlInfo.push_back( (Int) ptl->getProfileIdc()  );
2463    curPtlInfo.push_back( (Int) ptl->getTierFlag()    );
2464    curPtlInfo.push_back( (Int) ptl->getLevelIdc()    );
2465    curPtlInfo.push_back( (Int) ptl->getInbldFlag()   );
2466
2467    idx.push_back ( i );
2468    num.push_back ( 4 ); 
2469    ptlInfo.push_back( curPtlInfo );
2470  } 
2471
2472  xPrintArray( "VpsProfileTierLevel", getVpsNumProfileTierLevelMinus1() + 1, idx, num, ptlInfo, false  ); 
2473
2474  num.clear(); 
2475  idx.clear(); 
2476  for (Int i = 0; i < getNumOutputLayerSets(); i++)
2477  {
2478    num.push_back ( getNumLayersInIdList( olsIdxToLsIdx( i ))  ); 
2479    idx.push_back( i ); 
2480  }
2481
2482  xPrintArray( "profile_tier_level_idx", getNumOutputLayerSets(), idx, num, m_profileTierLevelIdx, true );
2483  std::cout << std::endl;
2484}
2485
2486Void TComVPS::printLayerDependencies() const
2487{
2488  vector<Int> fullArray;
2489  vector<Int> range; 
2490
2491#if NH_3D
2492  vector<Int> depthId; 
2493#endif
2494
2495  vector<Int> viewOrderIndex;
2496  vector<Int> auxId;
2497  vector<Int> dependencyId; 
2498  vector<Int> viewId; 
2499  for (Int i = 0; i <= getMaxLayersMinus1(); i++ )
2500  {
2501    fullArray.push_back( getMaxLayersMinus1() + 1 ); 
2502    range.push_back( i ); 
2503    viewOrderIndex.push_back( getViewIndex   ( i ) );
2504    dependencyId  .push_back( getDependencyId( i ) );
2505    auxId         .push_back( getAuxId       ( i ) );     
2506    viewId        .push_back( getViewId      ( getLayerIdInNuh( i ) ) );
2507#if NH_3D 
2508    depthId.push_back( getDepthId( i ) );
2509#endif
2510  }
2511  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "Layer Dependencies" << std::endl; 
2512  xPrintArray( "direct_dependency_flag", getMaxLayersMinus1()+1, range, fullArray, m_directDependencyFlag, false ); 
2513  xPrintArray( "DependencyFlag", getMaxLayersMinus1()+1, range, fullArray, m_dependencyFlag, false ); 
2514  xPrintArray( "layer_id_in_nuh", getMaxLayersMinus1()+1, m_layerIdInNuh, true  );     
2515  xPrintArray( "IdPredictedLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numPredictedLayers, m_idPredictedLayer, true );
2516  xPrintArray( "IdRefLayer"      , getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numRefLayers, m_idRefLayer, true );
2517  xPrintArray( "IdDirectRefLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numDirectRefLayers, m_idDirectRefLayer, true );
2518#if NH_3D
2519  xPrintArray( "IdRefListLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numRefListLayers, m_idRefListLayer, true );
2520#endif
2521
2522  std::cout << std::endl;
2523}
2524
2525Void TComVPS::printScalabilityId() const
2526{
2527  vector<Int> layerIdxInVps; 
2528
2529
2530  vector<Int> depthId; 
2531  vector<Int> viewOrderIndex;
2532  vector<Int> auxId;
2533  vector<Int> dependencyId; 
2534  vector<Int> viewId; 
2535
2536  for (Int i = 0; i <= getMaxLayersMinus1(); i++ )
2537  {
2538    Int layerIdInNuh = getLayerIdInNuh( i );
2539    layerIdxInVps  .push_back( i ); 
2540    depthId       .push_back( getDepthId     ( layerIdInNuh ) );
2541    viewOrderIndex.push_back( getViewIndex   ( layerIdInNuh ) );
2542    dependencyId  .push_back( getDependencyId( layerIdInNuh ) );
2543    auxId         .push_back( getAuxId       ( layerIdInNuh ) );     
2544    viewId        .push_back( getViewId      ( layerIdInNuh ) );
2545
2546  }
2547
2548  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "Scalability Ids" << std::endl; 
2549  xPrintArray( "layerIdxInVps"  , getMaxLayersMinus1()+1, layerIdxInVps,          false );
2550  xPrintArray( "layer_id_in_nuh", getMaxLayersMinus1()+1, m_layerIdInNuh, false );     
2551
2552  xPrintArray( "DepthLayerFlag", getMaxLayersMinus1()+1, depthId       , false );     
2553  xPrintArray( "ViewOrderIdx"  , getMaxLayersMinus1()+1, viewOrderIndex, false );     
2554  xPrintArray( "DependencyId"  , getMaxLayersMinus1()+1, dependencyId  , false );     
2555  xPrintArray( "AuxId"         , getMaxLayersMinus1()+1, auxId         , false );     
2556  xPrintArray( "ViewIdVal"     , getMaxLayersMinus1()+1, viewId        , false );     
2557
2558  std::cout << std::endl;
2559}
2560
2561Void TComVPS::printLayerSets() const
2562{
2563  vector<Int> fullArray;
2564  vector<Int> numLayersInIdList; 
2565  vector<Int> rangeLayerSets; 
2566
2567
2568  for (Int i = 0; i < getNumLayerSets(); i++ )
2569  {
2570    numLayersInIdList.push_back( getNumLayersInIdList( i ) );       
2571    rangeLayerSets.push_back( i ); 
2572  }
2573
2574  vector<Int> rangeOutputLayerSets; 
2575  vector<Int> numOutputLayersInOutputLayerSet; 
2576  vector<Int> numDecLayer; 
2577  vector<Int> numLayersInLayerSetForOutputLayerSet; 
2578  vector<Int> vOlsIdxToLsIdx;
2579  for (Int i = 0; i < getNumOutputLayerSets(); i++ )
2580  {
2581    vOlsIdxToLsIdx.push_back( olsIdxToLsIdx(i));
2582    numOutputLayersInOutputLayerSet.push_back( getNumOutputLayersInOutputLayerSet( i ) );       
2583    numDecLayer.push_back( (Int) m_targetDecLayerIdLists[ i ].size() );
2584    rangeOutputLayerSets.push_back( i ); 
2585    numLayersInLayerSetForOutputLayerSet.push_back( getNumLayersInIdList( olsIdxToLsIdx( i ) ) );
2586  }
2587
2588  vector<Int> rangeIndependentLayers;
2589  for(Int i = 0; i < getNumIndependentLayers(); i++ )
2590  {
2591    rangeIndependentLayers.push_back( i );   
2592  }
2593
2594  vector<Int> rangeAddLayerSets;
2595  vector<Int> numHighestLayerIdxPlus1; 
2596  for(Int i = 0; i < getNumAddLayerSets(); i++ )
2597  {
2598    rangeAddLayerSets.push_back( i );   
2599    numHighestLayerIdxPlus1.push_back( getNumIndependentLayers() );
2600  }
2601
2602  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "Layer Sets" << std::endl;     
2603  xPrintArray( "TreePartitionLayerIdList", getNumIndependentLayers(), rangeIndependentLayers, m_numLayersInTreePartition, m_treePartitionLayerIdList, true );
2604  xPrintArray( "highest_layer_idx_plus1", getNumAddLayerSets(), rangeAddLayerSets, numHighestLayerIdxPlus1, m_highestLayerIdxPlus1, true ); 
2605  xPrintArray( "LayerSetLayerIdList" , (Int) getNumLayerSets()      , rangeLayerSets      , numLayersInIdList, m_layerSetLayerIdList, true );
2606  xPrintArray( "OlsIdxToLsIdx", (Int) vOlsIdxToLsIdx.size(), vOlsIdxToLsIdx, true ); 
2607  xPrintArray( "OutputLayerFlag"     , getNumOutputLayerSets(), rangeOutputLayerSets, numLayersInLayerSetForOutputLayerSet, m_outputLayerFlag, true );
2608  xPrintArray( "TargetOptLayerIdList", getNumOutputLayerSets(), rangeOutputLayerSets, numOutputLayersInOutputLayerSet, m_targetOptLayerIdLists, true );
2609  xPrintArray( "NecessaryLayerFlag"  , getNumOutputLayerSets(), rangeOutputLayerSets, numLayersInLayerSetForOutputLayerSet, m_necessaryLayerFlag   , true );
2610  xPrintArray( "TargetDecLayerIdList", getNumOutputLayerSets(), rangeOutputLayerSets, numDecLayer,                     m_targetDecLayerIdLists, true );
2611  std::cout << endl;
2612}
2613
2614#if NH_3D
2615Void TComVPS::initViewCompLayer()
2616{
2617  assert( m_viewCompLayerId.size() == 0 && m_viewCompLayerPresentFlag.size() == 0  );
2618  for( Int i = 0; i < getNumViews(); i++ )
2619  {
2620    m_viewCompLayerId         .push_back( std::vector<Int>(0)  );
2621    m_viewCompLayerPresentFlag.push_back( std::vector<Bool>(0) );     
2622
2623    for( Int depFlag = 0; depFlag  <=  1; depFlag++ )
2624    {
2625      Int iViewOIdx = getViewOIdxList( i );
2626      Int layerId = -1;
2627      for( Int j = 0; j  <=  getMaxLayersMinus1(); j++ ) 
2628      {
2629        Int jNuhLId = getLayerIdInNuh( j );
2630        if( getVpsDepthFlag( jNuhLId ) == ( (Bool) depFlag )  &&  getViewOrderIdx( jNuhLId )  ==  iViewOIdx 
2631          &&  getDependencyId( jNuhLId )  ==  0  &&  getAuxId( jNuhLId )  ==  0 )
2632        {
2633          layerId = jNuhLId;
2634        }
2635      }
2636      m_viewCompLayerPresentFlag[ i ].push_back( layerId  !=  -1 );
2637      m_viewCompLayerId         [ i ].push_back( layerId );       
2638    }
2639  }
2640}
2641
2642Int TComVPS::getVoiInVps(Int viewOIdx) const
2643{
2644  for ( Int i = 0; i < m_viewOIdxList.size(); i++ )
2645  {
2646    if  ( m_viewOIdxList[ i ] == viewOIdx )
2647    {
2648      return i; 
2649    }
2650  }
2651  assert( 0 );   
2652  return -1;
2653}
2654
2655Void TComVPS::deriveCpPresentFlag()
2656{
2657  for( Int nInVps = 0; nInVps < getNumViews(); nInVps++  )
2658  {
2659    for( Int mInVps = 0; mInVps < getNumViews(); mInVps++ )
2660    {
2661      m_cpPresentFlag[nInVps][mInVps] = 0; 
2662    }
2663  }
2664
2665  for( Int n = 1; n < getNumViews(); n++ )
2666  {
2667    Int iInVps = getVoiInVps(  getViewOIdxList( n ) );     
2668    for( Int m = 0; m < getNumCp( iInVps ); m++ )
2669    {
2670      m_cpPresentFlag[ iInVps ][ getVoiInVps( getCpRefVoi( iInVps, m ) ) ] = 1;
2671    }
2672  }
2673}
2674
2675#endif
2676#endif // NH_MV
2677
2678// ------------------------------------------------------------------------------------------------
2679// Sequence parameter set (SPS)
2680// ------------------------------------------------------------------------------------------------
2681
2682TComSPSRExt::TComSPSRExt()
2683 : m_transformSkipRotationEnabledFlag   (false)
2684 , m_transformSkipContextEnabledFlag    (false)
2685// m_rdpcmEnabledFlag initialized below
2686 , m_extendedPrecisionProcessingFlag    (false)
2687 , m_intraSmoothingDisabledFlag         (false)
2688 , m_highPrecisionOffsetsEnabledFlag    (false)
2689 , m_persistentRiceAdaptationEnabledFlag(false)
2690 , m_cabacBypassAlignmentEnabledFlag    (false)
2691{
2692  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
2693  {
2694    m_rdpcmEnabledFlag[signallingModeIndex] = false;
2695  }
2696}
2697
2698TComSPS::TComSPS()
2699: m_SPSId                     (  0)
2700, m_VPSId                     (  0)
2701, m_chromaFormatIdc           (CHROMA_420)
2702, m_uiMaxTLayers              (  1)
2703// Structure
2704, m_picWidthInLumaSamples     (352)
2705, m_picHeightInLumaSamples    (288)
2706, m_log2MinCodingBlockSize    (  0)
2707, m_log2DiffMaxMinCodingBlockSize(0)
2708, m_uiMaxCUWidth              ( 32)
2709, m_uiMaxCUHeight             ( 32)
2710, m_uiMaxTotalCUDepth         (  3)
2711, m_bLongTermRefsPresent      (false)
2712, m_uiQuadtreeTULog2MaxSize   (  0)
2713, m_uiQuadtreeTULog2MinSize   (  0)
2714, m_uiQuadtreeTUMaxDepthInter (  0)
2715, m_uiQuadtreeTUMaxDepthIntra (  0)
2716// Tool list
2717, m_usePCM                    (false)
2718, m_pcmLog2MaxSize            (  5)
2719, m_uiPCMLog2MinSize          (  7)
2720, m_bPCMFilterDisableFlag     (false)
2721, m_uiBitsForPOC              (  8)
2722, m_numLongTermRefPicSPS      (  0)
2723#if NH_MV
2724, m_numShortTermRefPicSets    (   0)
2725#endif
2726, m_uiMaxTrSize               ( 32)
2727, m_bUseSAO                   (false)
2728, m_bTemporalIdNestingFlag    (false)
2729, m_scalingListEnabledFlag    (false)
2730, m_useStrongIntraSmoothing   (false)
2731, m_vuiParametersPresentFlag  (false)
2732, m_vuiParameters             ()
2733#if NH_MV
2734, m_pcVPS                     ( NULL )
2735, m_spsInferScalingListFlag   ( false )
2736, m_spsScalingListRefLayerId  ( 0 )
2737
2738, m_updateRepFormatFlag       ( false ) 
2739, m_spsRepFormatIdx           ( 0 )
2740, m_interViewMvVertConstraintFlag (false)
2741#endif
2742
2743{
2744  for(Int ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
2745  {
2746    m_bitDepths.recon[ch] = 8;
2747#if O0043_BEST_EFFORT_DECODING
2748    m_bitDepths.stream[ch] = 8;
2749#endif
2750    m_pcmBitDepths[ch] = 8;
2751    m_qpBDOffset   [ch] = 0;
2752  }
2753
2754
2755  for ( Int i = 0; i < MAX_TLAYER; i++ )
2756  {
2757#if NH_MV
2758    m_uiSpsMaxLatencyIncreasePlus1[i] = 0;
2759#else
2760    m_uiMaxLatencyIncreasePlus1[i] = 0;
2761#endif
2762    m_uiMaxDecPicBuffering[i] = 1;
2763    m_numReorderPics[i]       = 0;
2764  }
2765
2766  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
2767  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
2768#if NH_MV
2769  m_spsRangeExtensionsFlag     = false;
2770  m_spsMultilayerExtensionFlag = false;
2771  m_spsExtension5bits          = 0;
2772  m_sps3dExtensionFlag         = false; 
2773
2774#endif
2775
2776}
2777
2778TComSPS::~TComSPS()
2779{
2780  m_RPSList.destroy();
2781}
2782
2783Void  TComSPS::createRPSList( Int numRPS )
2784{
2785  m_RPSList.destroy();
2786  m_RPSList.create(numRPS);
2787}
2788
2789const Int TComSPS::m_winUnitX[]={1,2,2,1};
2790const Int TComSPS::m_winUnitY[]={1,2,1,1};
2791
2792TComPPSRExt::TComPPSRExt()
2793: m_log2MaxTransformSkipBlockSize      (2)
2794, m_crossComponentPredictionEnabledFlag(false)
2795, m_diffCuChromaQpOffsetDepth          (0)
2796, m_chromaQpOffsetListLen              (0)
2797// m_ChromaQpAdjTableIncludingNullEntry initialized below
2798// m_log2SaoOffsetScale initialized below
2799{
2800  m_ChromaQpAdjTableIncludingNullEntry[0].u.comp.CbOffset = 0; // Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0. This is initialised here and never subsequently changed.
2801  m_ChromaQpAdjTableIncludingNullEntry[0].u.comp.CrOffset = 0;
2802  for(Int ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
2803  {
2804    m_log2SaoOffsetScale[ch] = 0;
2805  }
2806}
2807
2808TComPPS::TComPPS()
2809: m_PPSId                            (0)
2810, m_SPSId                            (0)
2811, m_picInitQPMinus26                 (0)
2812, m_useDQP                           (false)
2813, m_bConstrainedIntraPred            (false)
2814, m_bSliceChromaQpFlag               (false)
2815, m_uiMaxCuDQPDepth                  (0)
2816, m_chromaCbQpOffset                 (0)
2817, m_chromaCrQpOffset                 (0)
2818, m_numRefIdxL0DefaultActive         (1)
2819, m_numRefIdxL1DefaultActive         (1)
2820, m_TransquantBypassEnableFlag       (false)
2821, m_useTransformSkip                 (false)
2822, m_dependentSliceSegmentsEnabledFlag(false)
2823, m_tilesEnabledFlag                 (false)
2824, m_entropyCodingSyncEnabledFlag     (false)
2825, m_loopFilterAcrossTilesEnabledFlag (true)
2826, m_uniformSpacingFlag               (false)
2827, m_numTileColumnsMinus1             (0)
2828, m_numTileRowsMinus1                (0)
2829, m_signHideFlag                     (false)
2830, m_cabacInitPresentFlag             (false)
2831, m_sliceHeaderExtensionPresentFlag  (false)
2832, m_loopFilterAcrossSlicesEnabledFlag(false)
2833, m_listsModificationPresentFlag     (0)
2834, m_numExtraSliceHeaderBits          (0)
2835#if NH_MV
2836, m_ppsInferScalingListFlag          (false)
2837, m_ppsScalingListRefLayerId         (0)
2838, m_pocResetInfoPresentFlag          (false)
2839#endif
2840#if NH_3D_DLT
2841, m_cDLT                             ()
2842#endif
2843{
2844#if NH_MV
2845  m_ppsRangeExtensionsFlag     = false;
2846  m_ppsMultilayerExtensionFlag = false;
2847  m_pps3dExtensionFlag         = false;
2848  m_ppsExtension5bits          = 0;
2849#endif
2850
2851}
2852
2853TComPPS::~TComPPS()
2854{
2855}
2856
2857#if NH_3D_DLT
2858TComDLT::TComDLT()
2859: m_bDltPresentFlag(false)
2860, m_iNumDepthViews(0)
2861, m_uiDepthViewBitDepth(8)
2862{
2863  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2864  {
2865    m_bUseDLTFlag                 [i] = false;
2866    m_bInterViewDltPredEnableFlag [i] = false;
2867    m_bDltBitMapRepFlag           [i] = false;
2868
2869    // allocate some memory and initialize with default mapping
2870    m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1;
2871    m_iDepthValue2Idx[i]    = std::vector<Int>(m_iNumDepthmapValues[i]);
2872    m_iIdx2DepthValue[i]    = std::vector<Int>(m_iNumDepthmapValues[i]);
2873   
2874    m_iDepthIdxToLayerId[i] = i;
2875
2876    //default mapping
2877    for (Int d=0; d<m_iNumDepthmapValues[i]; d++)
2878    {
2879      m_iDepthValue2Idx[i][d] = d;
2880      m_iIdx2DepthValue[i][d] = d;
2881    }
2882  }
2883}
2884
2885TComDLT::~TComDLT()
2886{
2887 
2888}
2889
2890Void TComDLT::setDepthLUTs(Int layerIdInVps, std::vector<Int> idxToDepthValueTable, Int iNumDepthValues)
2891{
2892  if( iNumDepthValues == 0 ) // default mapping only
2893    return;
2894
2895  // copy idx2DepthValue to internal array
2896  m_iIdx2DepthValue[layerIdInVps] = idxToDepthValueTable;
2897
2898  UInt uiMaxDepthValue = ((1 << m_uiDepthViewBitDepth)-1);
2899  for(Int p=0; p<=uiMaxDepthValue; p++)
2900  {
2901    Int iIdxDown    = 0;
2902    Int iIdxUp      = iNumDepthValues-1;
2903    Bool bFound     = false;
2904
2905    // iterate over indices to find lower closest depth
2906    Int i = 1;
2907    while(!bFound && i<iNumDepthValues)
2908    {
2909      if( m_iIdx2DepthValue[layerIdInVps][i] > p )
2910      {
2911        iIdxDown  = i-1;
2912        bFound    = true;
2913      }
2914
2915      i++;
2916    }
2917    iIdxUp = bFound ?  iIdxDown + 1 : iNumDepthValues-1;
2918
2919    // assign closer depth value/idx
2920    if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) )
2921    {
2922      m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown;
2923    }
2924    else
2925    {
2926      m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp;
2927    }
2928
2929  }
2930
2931  // update DLT variables
2932  m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues;
2933}
2934
2935Void TComDLT::getDeltaDLT( Int layerIdInVps, std::vector<Int> piDLTInRef, UInt uiDLTInRefNum, std::vector<Int>& riDeltaDLTOut, UInt&ruiDeltaDLTOutNum ) const
2936{
2937  Bool abBM0[ 256 ];
2938  Bool abBM1[ 256 ];
2939 
2940  memset( abBM0, 0, sizeof( abBM0 ));
2941  memset( abBM1, 0, sizeof( abBM1 ));
2942 
2943  // convert reference DLT to bit string
2944  for( Int i = 0; i < uiDLTInRefNum; i++ )
2945  {
2946    abBM0[ piDLTInRef[ i ] ] = true;
2947  }
2948  // convert internal DLT to bit string
2949  for( Int i = 0; i < m_iNumDepthmapValues[ layerIdInVps ]; i++ )
2950  {
2951    abBM1[ m_iIdx2DepthValue[ layerIdInVps ][ i ] ] = true;
2952  }
2953 
2954  ruiDeltaDLTOutNum = 0;
2955  for( Int i = 0; i < 256; i++ )
2956  {
2957    if( abBM0[ i ] ^ abBM1[ i ] )
2958    {
2959      riDeltaDLTOut[ ruiDeltaDLTOutNum++ ] = i;
2960    }
2961  }
2962}
2963
2964Void TComDLT::setDeltaDLT( Int layerIdInVps, std::vector<Int> piDLTInRef, UInt uiDLTInRefNum, std::vector<Int> piDeltaDLTIn, UInt uiDeltaDLTInNum )
2965{
2966  Bool abBM0[ 256 ];
2967  Bool abBM1[ 256 ];
2968 
2969  memset( abBM0, 0, sizeof( abBM0 ));
2970  memset( abBM1, 0, sizeof( abBM1 ));
2971 
2972  // convert reference DLT to bit string
2973  for( Int i = 0; i < uiDLTInRefNum; i++ )
2974  {
2975    abBM0[ piDLTInRef[ i ] ] = true;
2976  }
2977  // convert delta DLT to bit string
2978  for( Int i = 0; i < uiDeltaDLTInNum; i++ )
2979  {
2980    abBM1[ piDeltaDLTIn[ i ] ] = true;
2981  }
2982 
2983  std::vector<Int> aiIdx2DepthValue(256, 0);
2984  UInt uiNumDepthValues = 0;
2985  std::fill(aiIdx2DepthValue.begin(), aiIdx2DepthValue.end(), 0);
2986 
2987  for( Int i = 0; i < 256; i++ )
2988  {
2989    if( abBM0[ i ] ^ abBM1[ i ] )
2990    {
2991      aiIdx2DepthValue[ uiNumDepthValues++ ] = i;
2992    }
2993  }
2994 
2995  // update internal tables
2996  setDepthLUTs(layerIdInVps, aiIdx2DepthValue, uiNumDepthValues);
2997}
2998
2999#endif
3000
3001#if NH_MV
3002Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr, Bool encoder )
3003{
3004  if ( getMultiLayerExtSpsFlag() )
3005  {   
3006    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
3007    const TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx ); 
3008
3009    if ( encoder )
3010    {
3011      assert( getChromaFormatIdc() ==  (ChromaFormat) repFormat->getChromaFormatVpsIdc() );         
3012      //// ToDo: add when supported:
3013      // assert( getSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
3014
3015      assert( getPicWidthInLumaSamples()  ==  repFormat->getPicWidthVpsInLumaSamples()  ); 
3016      assert( getPicHeightInLumaSamples() == repFormat->getPicHeightVpsInLumaSamples() ); 
3017
3018      assert( getBitDepth              ( CHANNEL_TYPE_LUMA ) == repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
3019      assert( getQpBDOffset            ( CHANNEL_TYPE_LUMA ) == (Int) (6*( getBitDepth( CHANNEL_TYPE_LUMA ) - 8 )) );
3020
3021      assert( getBitDepth              ( CHANNEL_TYPE_CHROMA ) == repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
3022      assert( getQpBDOffset            ( CHANNEL_TYPE_CHROMA ) == (Int) (6* ( getBitDepth( CHANNEL_TYPE_CHROMA ) -8 ) ) );
3023    }
3024    else
3025    {
3026      setChromaFormatIdc( (ChromaFormat) repFormat->getChromaFormatVpsIdc() );         
3027      //// ToDo: add when supported:
3028      // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
3029
3030      setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  ); 
3031      setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); 
3032
3033      setBitDepth              ( CHANNEL_TYPE_LUMA, repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
3034      setQpBDOffset            ( CHANNEL_TYPE_LUMA, (Int) (6*( getBitDepth( CHANNEL_TYPE_LUMA ) - 8 )) );
3035
3036      setBitDepth              ( CHANNEL_TYPE_CHROMA, repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
3037      setQpBDOffset            ( CHANNEL_TYPE_CHROMA, (Int) (6* ( getBitDepth( CHANNEL_TYPE_CHROMA ) -8 ) ) );
3038      Window &spsConf    = getConformanceWindow();   
3039
3040      // Scaled later
3041      spsConf.setScaledFlag( false ); 
3042      spsConf.setWindowLeftOffset  ( repFormat->getConfWinVpsLeftOffset()    );
3043      spsConf.setWindowRightOffset ( repFormat->getConfWinVpsRightOffset()   );
3044      spsConf.setWindowTopOffset   ( repFormat->getConfWinVpsTopOffset()     );
3045      spsConf.setWindowBottomOffset( repFormat->getConfWinVpsBottomOffset()  );           
3046    }
3047
3048   if ( getMultiLayerExtSpsFlag() && getUpdateRepFormatFlag() )
3049    {
3050      assert( getChromaFormatIdc()      <=  repFormat->getChromaFormatVpsIdc()         ); 
3051      //// ToDo: add when supported:
3052      // assert( getSeperateColourPlaneFlag() <=  repFormat->getSeparateColourPlaneVpsFlag() ) ;
3053
3054      assert( getPicWidthInLumaSamples()  <= repFormat->getPicWidthVpsInLumaSamples()    ); 
3055      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   ); 
3056
3057      assert( getBitDepth( CHANNEL_TYPE_LUMA   )  <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
3058      assert( getBitDepth( CHANNEL_TYPE_CHROMA )  <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
3059    }
3060  }
3061
3062  // Set conformance window
3063  Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ;
3064  getConformanceWindow().scaleOffsets( scal );
3065  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
3066
3067  if (encoder && getMultiLayerExtSpsFlag() )
3068  { 
3069    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
3070    const TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx ); 
3071
3072    Window &spsConf    = getConformanceWindow();   
3073    assert( spsConf.getWindowLeftOffset  () == repFormat->getConfWinVpsLeftOffset()    );
3074    assert( spsConf.getWindowRightOffset () == repFormat->getConfWinVpsRightOffset()   );
3075    assert( spsConf.getWindowTopOffset   () == repFormat->getConfWinVpsTopOffset()     );
3076    assert( spsConf.getWindowBottomOffset() == repFormat->getConfWinVpsBottomOffset()  );           
3077  }
3078}
3079
3080Void TComSPS::inferScalingList( const TComSPS* spsSrc )
3081{
3082  if ( getSpsInferScalingListFlag() ) 
3083  {
3084    assert( spsSrc != NULL ); 
3085    assert( !spsSrc->getSpsInferScalingListFlag() );             
3086    getScalingList().inferFrom( (spsSrc->getScalingList()) ); 
3087  }
3088}
3089
3090Void TComSPS::inferSpsMaxDecPicBufferingMinus1( TComVPS* vps, Int targetOptLayerSetIdx, Int currLayerId, Bool encoder )
3091{
3092  if ( getMultiLayerExtSpsFlag() )
3093  {
3094    const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx )); 
3095    Int layerIdx = 0;         
3096    while (layerIdx < (Int) targetDecLayerIdList.size() )
3097    {
3098      if ( targetDecLayerIdList[layerIdx] == currLayerId )
3099      { 
3100        break; 
3101      }
3102      layerIdx++; 
3103    }
3104
3105    assert( layerIdx < (Int) targetDecLayerIdList.size() ); 
3106
3107    for (Int i = 0; i <= getSpsMaxSubLayersMinus1(); i++ ) 
3108    {
3109      Int maxDecPicBufferingMinus1 = vps->getDpbSize()->getMaxVpsDecPicBufferingMinus1( targetOptLayerSetIdx, layerIdx, i ) ; 
3110
3111      // This preliminary fix needs to be checked.
3112      Int maxNumReorderPics       = vps->getDpbSize()->getMaxVpsNumReorderPics( targetOptLayerSetIdx, i ); 
3113      Int maxLatencyIncreasePlus1 = vps->getDpbSize()->getMaxVpsLatencyIncreasePlus1( targetOptLayerSetIdx, i ); 
3114      if ( encoder )     
3115      {
3116        assert( getMaxDecPicBuffering( i ) - 1 == maxDecPicBufferingMinus1 ); 
3117        // This preliminary fix needs to be checked.
3118        assert( getNumReorderPics( i )     == maxNumReorderPics       ); 
3119        assert( getSpsMaxLatencyIncreasePlus1( i ) == maxLatencyIncreasePlus1 ); 
3120
3121      }
3122      else
3123      {
3124        // This preliminary fix needs to be checked.
3125        setMaxDecPicBuffering( maxDecPicBufferingMinus1 + 1 , i); 
3126        setNumReorderPics    ( maxNumReorderPics, i );
3127        setSpsMaxLatencyIncreasePlus1( maxLatencyIncreasePlus1 , i); 
3128      }
3129    }   
3130  }
3131}
3132
3133Void TComSPS::checkRpsMaxNumPics( const TComVPS* vps, Int currLayerId ) const
3134{
3135  for (Int i = 0; i < getRPSList()->getNumberOfReferencePictureSets(); i++ )
3136  {
3137    const TComReferencePictureSet* rps = getRPSList()->getReferencePictureSet( i ); 
3138    if ( !rps->getInterRPSPrediction() )
3139    {
3140      rps->checkMaxNumPics( vps->getVpsExtensionFlag(), MAX_INT, getLayerId(), getMaxDecPicBuffering( getSpsMaxSubLayersMinus1() ) - 1 );   // INT_MAX to be replaced by DpbSize
3141    }
3142  }
3143}
3144
3145Void TComSPS::inferSpsMaxSubLayersMinus1(Bool atPsActivation, TComVPS* vps)
3146{
3147  assert( getLayerId() != 0 ); 
3148  if ( !atPsActivation   )
3149  {
3150    assert( vps == NULL );
3151    if (getSpsExtOrMaxSubLayersMinus1() != 7)
3152    {
3153      setSpsMaxSubLayersMinus1( getSpsExtOrMaxSubLayersMinus1() );
3154    }
3155  }
3156  else
3157  {
3158    assert( vps != NULL );
3159    if (getSpsExtOrMaxSubLayersMinus1() == 7)
3160    {
3161      setSpsMaxSubLayersMinus1( vps->getMaxSubLayersMinus1() );
3162    }
3163  }
3164}
3165#endif
3166
3167
3168TComReferencePictureSet::TComReferencePictureSet()
3169: m_numberOfPictures (0)
3170, m_numberOfNegativePictures (0)
3171, m_numberOfPositivePictures (0)
3172, m_numberOfLongtermPictures (0)
3173, m_interRPSPrediction (0)
3174, m_deltaRIdxMinus1 (0)
3175, m_deltaRPS (0)
3176, m_numRefIdc (0)
3177{
3178  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
3179  ::memset( m_POC, 0, sizeof(m_POC) );
3180  ::memset( m_used, 0, sizeof(m_used) );
3181  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
3182  ::memset( m_bCheckLTMSB, 0, sizeof(m_bCheckLTMSB) );
3183  ::memset( m_pocLSBLT, 0, sizeof(m_pocLSBLT) );
3184  ::memset( m_deltaPOCMSBCycleLT, 0, sizeof(m_deltaPOCMSBCycleLT) );
3185  ::memset( m_deltaPocMSBPresentFlag, 0, sizeof(m_deltaPocMSBPresentFlag) );
3186}
3187
3188TComReferencePictureSet::~TComReferencePictureSet()
3189{
3190}
3191
3192Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
3193{
3194  m_used[bufferNum] = used;
3195}
3196
3197Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
3198{
3199  m_deltaPOC[bufferNum] = deltaPOC;
3200}
3201
3202Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
3203{
3204  m_numberOfPictures = numberOfPictures;
3205}
3206
3207Int TComReferencePictureSet::getUsed(Int bufferNum) const
3208{
3209  return m_used[bufferNum];
3210}
3211
3212Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) const
3213{
3214  return m_deltaPOC[bufferNum];
3215}
3216
3217Int TComReferencePictureSet::getNumberOfPictures() const
3218{
3219  return m_numberOfPictures;
3220}
3221
3222Int TComReferencePictureSet::getPOC(Int bufferNum) const
3223{
3224  return m_POC[bufferNum];
3225}
3226
3227Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
3228{
3229  m_POC[bufferNum] = POC;
3230}
3231
3232Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) const
3233{
3234  return m_bCheckLTMSB[bufferNum];
3235}
3236
3237Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
3238{
3239  m_bCheckLTMSB[bufferNum] = b;
3240}
3241
3242//! set the reference idc value at uiBufferNum entry to the value of iRefIdc
3243Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
3244{
3245  m_refIdc[bufferNum] = refIdc;
3246}
3247
3248//! get the reference idc value at uiBufferNum
3249Int  TComReferencePictureSet::getRefIdc(Int bufferNum) const
3250{
3251  return m_refIdc[bufferNum];
3252}
3253
3254/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
3255 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
3256 *  +ve values are in increasing order.
3257 * \returns Void
3258 */
3259Void TComReferencePictureSet::sortDeltaPOC()
3260{
3261  // sort in increasing order (smallest first)
3262  for(Int j=1; j < getNumberOfPictures(); j++)
3263  {
3264    Int deltaPOC = getDeltaPOC(j);
3265    Bool used = getUsed(j);
3266    for (Int k=j-1; k >= 0; k--)
3267    {
3268      Int temp = getDeltaPOC(k);
3269      if (deltaPOC < temp)
3270      {
3271        setDeltaPOC(k+1, temp);
3272        setUsed(k+1, getUsed(k));
3273        setDeltaPOC(k, deltaPOC);
3274        setUsed(k, used);
3275      }
3276    }
3277  }
3278  // flip the negative values to largest first
3279  Int numNegPics = getNumberOfNegativePictures();
3280  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
3281  {
3282    Int deltaPOC = getDeltaPOC(j);
3283    Bool used = getUsed(j);
3284    setDeltaPOC(j, getDeltaPOC(k));
3285    setUsed(j, getUsed(k));
3286    setDeltaPOC(k, deltaPOC);
3287    setUsed(k, used);
3288  }
3289}
3290
3291/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
3292 *  A "*" is added to the deltaPOC value if it is Used bu current.
3293 * \returns Void
3294 */
3295Void TComReferencePictureSet::printDeltaPOC() const
3296{
3297  printf("DeltaPOC = { ");
3298  for(Int j=0; j < getNumberOfPictures(); j++)
3299  {
3300    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
3301  }
3302  if (getInterRPSPrediction())
3303  {
3304    printf("}, RefIdc = { ");
3305    for(Int j=0; j < getNumRefIdc(); j++)
3306    {
3307      printf("%d ", getRefIdc(j));
3308    }
3309  }
3310  printf("}\n");
3311}
3312
3313#if NH_MV
3314Void TComReferencePictureSet::checkMaxNumPics( Bool vpsExtensionFlag, Int maxNumPics, Int nuhLayerId, Int spsMaxDecPicBufferingMinus1 ) const
3315{
3316  assert( getNumberOfPictures() >= 0 ); 
3317  if ( nuhLayerId == 0 )
3318  {
3319    assert( getNumberOfPictures() <= spsMaxDecPicBufferingMinus1 ); 
3320  }
3321
3322  if ( vpsExtensionFlag )
3323  {
3324    assert( getNumberOfPictures() <= maxNumPics );
3325  }
3326}
3327#endif
3328
3329
3330
3331
3332TComRefPicListModification::TComRefPicListModification()
3333: m_refPicListModificationFlagL0 (false)
3334, m_refPicListModificationFlagL1 (false)
3335{
3336  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
3337  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
3338}
3339
3340TComRefPicListModification::~TComRefPicListModification()
3341{
3342}
3343
3344TComScalingList::TComScalingList()
3345{
3346  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3347  {
3348    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId++)
3349    {
3350      m_scalingListCoef[sizeId][listId].resize(min<Int>(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3351    }
3352  }
3353}
3354
3355/** set default quantization matrix to array
3356*/
3357Void TComScalingList::setDefaultScalingList()
3358{
3359  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3360  {
3361    for(UInt listId=0;listId<SCALING_LIST_NUM;listId++)
3362    {
3363      processDefaultMatrix(sizeId, listId);
3364    }
3365  }
3366}
3367/** check if use default quantization matrix
3368 * \returns true if use default quantization matrix in all size
3369*/
3370Bool TComScalingList::checkDefaultScalingList()
3371{
3372  UInt defaultCounter=0;
3373
3374  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3375  {
3376    for(UInt listId=0;listId<SCALING_LIST_NUM;listId++)
3377    {
3378      if( !memcmp(getScalingListAddress(sizeId,listId), getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
3379     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == 16))) // check DC value
3380      {
3381        defaultCounter++;
3382      }
3383    }
3384  }
3385
3386  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM )) ? false : true;
3387}
3388
3389#if NH_MV
3390Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
3391{
3392  refPicSetInterLayer0.clear(); 
3393  refPicSetInterLayer1.clear(); 
3394
3395  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
3396  {
3397    Int layerIdRef = getRefPicLayerId( i ); 
3398    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
3399    assert ( picRef != 0 ); // There shall be no entry equal to "no reference picture" in RefPicSetInterLayer0 or RefPicSetInterLayer1.
3400
3401    picRef->getPicYuvRec()->extendPicBorder(); 
3402    picRef->setIsLongTerm( true );       
3403    picRef->getSlice(0)->setReferenced( true );       
3404
3405    Int viewIdCur  = getVPS()->getViewId( getLayerId() ); 
3406    Int viewIdZero = getVPS()->getViewId( 0 );
3407    Int viewIdRef  = getVPS()->getViewId( layerIdRef ); 
3408
3409    if (  ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) )
3410    {
3411      refPicSetInterLayer0.push_back( picRef ); 
3412    }
3413    else
3414    {
3415      refPicSetInterLayer1.push_back( picRef ); 
3416    }
3417    // Consider to check here:
3418    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "   
3419    assert( picRef->getSlice(0)->getDiscardableFlag() == false ); // "There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1".       
3420  }
3421}
3422Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
3423{
3424  // Mark as short-term
3425  for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
3426  {
3427    refPicSetInterLayer0[i]->setIsLongTerm( false ); 
3428  }
3429
3430  for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) 
3431  {
3432    refPicSetInterLayer1[i]->setIsLongTerm( false ); 
3433  }
3434
3435}
3436
3437Void TComSlice::printRefPicList()
3438{ 
3439  for ( Int li = 0; li < 2; li++)
3440  {   
3441    std::cout << std::endl << "RefPicListL" <<  li << ":" << std::endl; 
3442    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
3443    {     
3444      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( 1 );
3445      m_apcRefPicList[li][rIdx]->print( 0 );     
3446       
3447    }
3448  }
3449}
3450
3451Void TComSlice::markCurrPic( TComPic* currPic )
3452{
3453  currPic->getSlice(0)->setReferenced( true ) ; 
3454  currPic->setIsLongTerm( false ); 
3455
3456  currPic->setReconMark( true );
3457  currPic->setPicOutputFlag( currPic->getSlice(0)->getPicOutputFlag() );
3458}
3459
3460Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
3461{
3462  m_refPicSetInterLayer0 = refPicSetInterLayer0; 
3463  m_refPicSetInterLayer1 = refPicSetInterLayer1; 
3464}
3465
3466TComPic* TComSlice::getRefPicSetInterLayer( Int setIdc, Int i ) const
3467{
3468  TComPic* pic = NULL; 
3469  if (setIdc == 0 )
3470  {
3471    pic = (*m_refPicSetInterLayer0)[ i ]; 
3472  }
3473  else if (setIdc == 1 )
3474  {
3475    pic = (*m_refPicSetInterLayer1)[ i ]; 
3476  }
3477
3478  assert( pic != NULL );   
3479
3480  return pic; 
3481}
3482
3483
3484TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) const
3485{
3486  assert ( setIdc == 0 || setIdc == 1);   
3487  std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1);   
3488  assert( refPicSetInterLayer != 0 ); 
3489 
3490  TComPic* pcPic = NULL; 
3491  for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ )
3492  {
3493    if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId )
3494    {
3495      pcPic = (*refPicSetInterLayer)[ i ]; 
3496    }
3497  }
3498
3499  assert(pcPic != NULL); 
3500  return pcPic;
3501}
3502
3503
3504Int  TComSlice::getRefLayerPicFlag( Int i ) const
3505{
3506  const TComVPS* vps = getVPS(); 
3507#if NH_3D
3508  Int refLayerIdx = vps->getLayerIdInVps( vps->getIdRefListLayer( getLayerId(), i ) ); 
3509#else
3510  Int refLayerIdx = vps->getLayerIdInVps( vps->getIdDirectRefLayer( getLayerId(), i ) ); 
3511#endif
3512
3513  Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer()  && ( getTLayer() == 0   ||
3514    vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() )); 
3515  return refLayerPicFlag;       
3516}   
3517
3518Int TComSlice::getRefLayerPicIdc( Int j ) const
3519{ 
3520  Int refLayerPicIdc = -1; 
3521  Int curj = 0; 
3522#if NH_3D
3523  for( Int i = 0;  i < getVPS()->getNumRefListLayers( getLayerId()) ; i++ )
3524#else
3525  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3526#endif
3527  {
3528    if( getRefLayerPicFlag( i ) )
3529    {
3530      if ( curj == j ) 
3531      {
3532        refLayerPicIdc = i;         
3533        break;
3534      }
3535      curj++; 
3536    }
3537  }
3538
3539  assert( curj == j ); 
3540  assert( refLayerPicIdc != -1 ); 
3541  return refLayerPicIdc; 
3542}
3543
3544Int  TComSlice::getNumRefLayerPics( ) const
3545{ 
3546  Int numRefLayerPics = 0; 
3547#if NH_3D
3548  for( Int i = 0;  i < getVPS()->getNumRefListLayers( getLayerId()) ; i++ )
3549#else
3550  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3551#endif
3552  {
3553    numRefLayerPics += getRefLayerPicFlag( i ); 
3554  }
3555  return numRefLayerPics; 
3556}
3557
3558
3559
3560Int TComSlice::getNumActiveRefLayerPics() const
3561{
3562  Int numActiveRefLayerPics; 
3563
3564  if( getLayerId() == 0 || getNumRefLayerPics() ==  0 )
3565  {
3566    numActiveRefLayerPics = 0; 
3567  }
3568  else if (getVPS()->getAllRefLayersActiveFlag() )
3569  {
3570    numActiveRefLayerPics = getNumRefLayerPics(); 
3571  }
3572  else if ( !getInterLayerPredEnabledFlag() )
3573  {
3574    numActiveRefLayerPics = 0; 
3575  }
3576#if NH_3D
3577  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumRefListLayers( getLayerId() ) == 1 )
3578#else
3579  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
3580#endif
3581  {
3582    numActiveRefLayerPics = 1; 
3583  }
3584  else
3585  {
3586    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
3587  }
3588  return numActiveRefLayerPics;
3589}
3590
3591Int TComSlice::getRefPicLayerId( Int i ) const
3592{
3593#if NH_3D
3594  return getVPS()->getIdRefListLayer( getLayerId(), getInterLayerPredLayerIdc( i ) );
3595#else
3596  return getVPS()->getIdDirectRefLayer( getLayerId(), getInterLayerPredLayerIdc( i ) );
3597#endif
3598}
3599#endif
3600#if NH_3D_NBDV
3601Void TComSlice::setDefaultRefView()
3602{
3603  setDefaultRefViewIdx(-1);
3604  setDefaultRefViewIdxAvailableFlag(false); 
3605
3606  Int valid = 0;
3607  Int DefaultRefViewIdx = -1;
3608
3609  for(UInt curViewIdx = 0; curViewIdx < getViewIndex() && valid == 0; curViewIdx++)
3610  {
3611    for(Int iRefListId = 0; (iRefListId < (isInterB() ? 2 : 1)) && !isIntra() && valid == 0; iRefListId++)
3612    {
3613      RefPicList eRefPicList = RefPicList(iRefListId);
3614      Int        iNumRefPics = getNumRefIdx(eRefPicList);
3615
3616      for(Int i = 0; i < iNumRefPics; i++)
3617      { 
3618        if(getPOC() == getRefPic(eRefPicList, i)->getPOC() && curViewIdx == getRefPic(eRefPicList, i)->getViewIndex())
3619        {
3620          valid = 1;
3621          DefaultRefViewIdx = curViewIdx;
3622          break;
3623        }
3624      }
3625    }
3626  }
3627
3628  if(valid)
3629  {
3630    setDefaultRefViewIdx(DefaultRefViewIdx);
3631    setDefaultRefViewIdxAvailableFlag(true);
3632  }
3633}
3634#endif
3635
3636#if NH_3D_ARP
3637Void TComSlice::setARPStepNum( TComPicLists*ivPicLists )
3638{
3639  Bool tempRefPicInListsFlag = false;
3640  if( !getIvResPredFlag() || this->isIRAP())
3641  {
3642    m_nARPStepNum = 0;
3643  }
3644  else
3645  {
3646    setFirstTRefIdx (REF_PIC_LIST_0, -1);
3647    setFirstTRefIdx (REF_PIC_LIST_1, -1);
3648    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3649    {
3650      Int diffPOC=MAX_INT;
3651      Int idx=-1;
3652      for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ )
3653      {
3654        if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() )
3655        {
3656          if( abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC()) < diffPOC)
3657          {
3658            diffPOC=abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC());
3659            idx=i;
3660          }
3661        }
3662        if(idx>=0)
3663        {
3664          setFirstTRefIdx (RefPicList(refListIdx), idx);
3665        }
3666      }
3667    }
3668    tempRefPicInListsFlag = (getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0) && getDefaultRefViewIdxAvailableFlag();
3669    m_nARPStepNum = tempRefPicInListsFlag ?  H_3D_ARP_WFNR : 0;
3670  }
3671
3672  if (tempRefPicInListsFlag)
3673  {
3674    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3675    {
3676      RefPicList eRefPicList = RefPicList( refListIdx );
3677      Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC();
3678      for( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
3679      {
3680        Int layerIdInNuh = getRefPicLayerId( i );
3681
3682        TComPic* picV = getIvPic( getIsDepth(), getVPS()->getViewIndex( layerIdInNuh ) );
3683        assert( picV != NULL ); 
3684        IntAry1d pocsInCurrRPSsPicV = picV->getSlice(0)->getPocsInCurrRPSs(); 
3685        Bool refRpRefAvailFlag = false; 
3686        for (Int idx = 0; idx < pocsInCurrRPSsPicV.size(); idx++)
3687        {
3688          if ( pocsInCurrRPSsPicV[idx] == prevPOC )
3689          {
3690            refRpRefAvailFlag = true; 
3691            break; 
3692          }
3693        }
3694
3695        if (getFirstTRefIdx(eRefPicList) >= 0 && refRpRefAvailFlag )
3696        {
3697          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true;
3698        }
3699        else
3700        {
3701          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false;
3702        }
3703      }
3704    }
3705  }
3706  if( m_nARPStepNum > 1)
3707  {
3708    for(Int i = 0; i < getNumActiveRefLayerPics(); i ++ )
3709    {
3710      Int  iLayerId = getRefPicLayerId( i );
3711      Int  iViewIdx =   getVPS()->getViewIndex(iLayerId);
3712      Bool bIsDepth = ( getVPS()->getDepthId  ( iLayerId ) == 1 );
3713      if( iViewIdx<getViewIndex() && !bIsDepth )
3714      {
3715        setBaseViewRefPicList( ivPicLists->getSubDpb( iLayerId, false ), iViewIdx );
3716      }
3717    }
3718  }
3719}
3720#endif
3721
3722#if NH_3D_IC
3723// This is an encoder only function and should be moved to TEncSlice or TEncSearch!!
3724Void TComSlice::xSetApplyIC(Bool bUseLowLatencyICEnc)
3725{
3726  if(bUseLowLatencyICEnc)
3727  {
3728    Bool existInterViewRef=false;
3729    TComPic* pcCurrPic = getPic();
3730    TComPic* pcRefPic = NULL;
3731    for ( Int i = 0; (i < getNumRefIdx( REF_PIC_LIST_0 )) && !existInterViewRef; i++ )
3732    {
3733      pcRefPic = getRefPic( REF_PIC_LIST_0, i );
3734      if ( pcRefPic != NULL )
3735      {
3736        if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3737        {
3738          existInterViewRef = true;
3739        }
3740      }
3741    }
3742
3743    for ( Int i = 0; (i < getNumRefIdx( REF_PIC_LIST_1 )) && !existInterViewRef; i++ )
3744    {
3745      pcRefPic = getRefPic( REF_PIC_LIST_1, i );
3746      if ( pcRefPic != NULL )
3747      {
3748        if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3749        {
3750          existInterViewRef = true;       
3751        }
3752      }
3753    }
3754
3755    if(!existInterViewRef)
3756    {
3757      m_bApplyIC = false;
3758    }
3759    else
3760    {
3761      Int curLayer=getDepth();
3762      if( curLayer>9) curLayer=9; // Max layer is 10
3763
3764      m_bApplyIC = true;
3765      Int refLayer = curLayer-1;
3766
3767      Int ICEnableCandidate = getICEnableCandidate(refLayer);
3768      Int ICEnableNum = getICEnableNum(refLayer);
3769      if( (refLayer>=0) && (ICEnableCandidate>0) )
3770      {   
3771        Double ratio=Double(ICEnableNum/Double(ICEnableCandidate));
3772
3773        if( ratio > IC_LOW_LATENCY_ENCODING_THRESHOLD)
3774        {
3775          m_bApplyIC=true;
3776        }
3777        else
3778        {
3779          m_bApplyIC=false;
3780        }
3781      }
3782      setICEnableCandidate(curLayer, 0);
3783      setICEnableNum(curLayer, 0);
3784    }
3785  }
3786  else
3787  {       
3788    TComPic*    pcCurrPic = getPic();
3789    TComPicYuv* pcCurrPicYuv = pcCurrPic->getPicYuvOrg();
3790   
3791    // Get InterView Reference picture
3792    // !!!!! Assume only one Interview Reference Picture in L0
3793    // GT: Is this assumption correct?
3794
3795    TComPicYuv* pcRefPicYuvOrg = NULL;
3796    for ( Int i = 0; i < getNumRefIdx( REF_PIC_LIST_0 ); i++ )
3797    {
3798      TComPic* pcRefPic = getRefPic( REF_PIC_LIST_0, i );
3799      if ( pcRefPic != NULL )
3800      {
3801        if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3802        {
3803          pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
3804        }
3805      }
3806    }
3807
3808    if ( pcRefPicYuvOrg != NULL )
3809    {
3810      // Histogram building - luminance
3811      Int iMaxPelValue = ( 1 << getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); 
3812      Int *aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue );
3813      Int *aiCurrHist   = (Int *) xMalloc( Int,iMaxPelValue );
3814      memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
3815      memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
3816
3817      Int iWidth   = pcCurrPicYuv->getWidth(COMPONENT_Y);
3818      Int iHeight  = pcCurrPicYuv->getHeight(COMPONENT_Y);
3819      Pel* pCurrY   = pcCurrPicYuv->getAddr(COMPONENT_Y);
3820      Pel* pRefOrgY = pcRefPicYuvOrg->getAddr(COMPONENT_Y);
3821      Int iCurrStride = pcCurrPicYuv->getStride(COMPONENT_Y);
3822      Int iRefStride = pcRefPicYuvOrg->getStride(COMPONENT_Y);
3823      for ( Int y = 0; y < iHeight; y++ )
3824      {
3825        for ( Int x = 0; x < iWidth; x++ )
3826        {
3827          aiCurrHist[pCurrY[x]]++;
3828          aiRefOrgHist[pRefOrgY[x]]++;
3829        }
3830        pCurrY += iCurrStride;
3831        pRefOrgY += iRefStride;
3832      }
3833
3834      // Histogram SAD
3835      Int iSumOrgSAD = 0;
3836      for ( Int i = 0; i < iMaxPelValue; i++ )
3837      {
3838        iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] );
3839      }
3840
3841      // Setting
3842      Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
3843
3844      if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) )
3845      {
3846        m_bApplyIC = true;
3847      }
3848      else
3849      {
3850        m_bApplyIC = false;
3851      }
3852
3853      xFree( aiCurrHist   );
3854      xFree( aiRefOrgHist );
3855    }
3856  }//if(bUseLowLatencyICEnc)
3857}
3858#endif
3859#if NH_3D
3860Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
3861{ 
3862  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
3863  { 
3864    for ( Int depthId = 0; depthId < 2; depthId++ )
3865    {
3866      m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL;
3867    }       
3868  } 
3869}
3870Void TComSlice::setDepthToDisparityLUTs()
3871{ 
3872  Bool setupLUT = false; 
3873 
3874  setupLUT = setupLUT || getViewSynthesisPredFlag( ); 
3875
3876#if NH_3D_NBDV_REF
3877  setupLUT = setupLUT || getDepthRefinementFlag( );
3878#endif 
3879
3880#if NH_3D_IV_MERGE
3881  setupLUT = setupLUT || ( getIvMvPredFlag() && getIsDepth() );
3882#endif
3883
3884  Int bitDepthY = getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
3885
3886  if( !setupLUT )
3887  {
3888    return; 
3889  }
3890
3891  m_numViews = getVPS()->getNumViews(); 
3892  /// GT: Allocation should be moved to a better place later;
3893  if ( m_depthToDisparityB == NULL )
3894  {
3895    m_depthToDisparityB = new Int*[ m_numViews ];
3896    for ( Int i = 0; i < getVPS()->getNumViews(); i++ )
3897    {
3898      m_depthToDisparityB[ i ] = new Int[ Int(1 << bitDepthY) ]; 
3899    }
3900  }
3901
3902 
3903  if ( m_depthToDisparityF == NULL )
3904  {
3905    m_depthToDisparityF = new Int*[ m_numViews ];
3906    for ( Int i = 0; i < m_numViews; i++ )
3907    {
3908      m_depthToDisparityF[ i ] = new Int[ Int(1 << bitDepthY) ]; 
3909    }
3910  }
3911
3912  assert( m_depthToDisparityB != NULL ); 
3913  assert( m_depthToDisparityF != NULL ); 
3914
3915  const TComVPS* vps = getVPS(); 
3916
3917  Int log2Div = bitDepthY - 1 + vps->getCpPrecision();
3918  Int voiInVps = vps->getVoiInVps( getViewIndex() ); 
3919  Bool camParaSH = vps->getCpInSliceSegmentHeaderFlag( voiInVps ); 
3920
3921  const IntAry1d codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale    ( voiInVps ); 
3922  const IntAry1d codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset   ( voiInVps ); 
3923  const IntAry1d invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( voiInVps ); 
3924  const IntAry1d invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( voiInVps ); 
3925
3926
3927  for (Int i = 0; i < voiInVps; i++)
3928  {
3929    Int iInVoi = vps->getVoiInVps( i ); 
3930#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
3931    if ( g_traceCameraParameters )
3932    {
3933      std::cout << "Cp: " << codScale   [ iInVoi ] << " " <<    codOffset[ iInVoi ] << " "
3934                << invCodScale[ iInVoi ] << " " << invCodOffset[ iInVoi ] << " " << log2Div << std::endl ; 
3935    }
3936#endif
3937    for ( Int d = 0; d <= ( ( 1 << bitDepthY ) - 1 ); d++ )
3938    {     
3939      Int offset =    ( codOffset  [ iInVoi ] << bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
3940      m_depthToDisparityB[ iInVoi ][ d ] = ( codScale [ iInVoi ] * d + offset ) >> log2Div; 
3941
3942      Int invOffset = ( invCodOffset[ iInVoi ] << bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
3943      m_depthToDisparityF[ iInVoi ][ d ] = ( invCodScale[ iInVoi ] * d + invOffset ) >> log2Div; 
3944    }
3945  }
3946}
3947#endif
3948
3949
3950
3951#if NH_MV
3952Void TComSlice::checkCrossLayerBlaFlag() const
3953{
3954  // cross_layer_bla_flag shall be equal to 0 for pictures with nal_unit_type not equal to IDR_W_RADL or IDR_N_LP or with nuh_layer_id not equal to 0.
3955  if ( getLayerId() != 0 || getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
3956  {
3957    assert( m_crossLayerBlaFlag == 0 ); 
3958  }
3959}
3960
3961Bool TComSlice::inferPocMsbCycleValPresentFlag()
3962{
3963  Bool pocMsbValPresentFlag; 
3964  if( getSliceSegmentHeaderExtensionLength() == 0 ) 
3965  {
3966    pocMsbValPresentFlag = false; 
3967  }
3968  else if ( getPocMsbValRequiredFlag() )
3969  {
3970    pocMsbValPresentFlag = true; 
3971  }
3972  else
3973  {
3974    pocMsbValPresentFlag = false; 
3975  }
3976
3977  return pocMsbValPresentFlag;
3978}
3979
3980
3981Void TComSlice::f834decProcForRefPicListConst()
3982{
3983  // This process is invoked at the beginning of the decoding process for each P or B slice.
3984  assert( getSliceType() == B_SLICE || getSliceType() == P_SLICE );
3985
3986  // Reference pictures are addressed through reference indices as specified in clause 8.5.3.3.2. A reference index is an index into
3987  // a reference picture list. When decoding a P slice, there is a single reference picture list RefPicList0. When decoding a B
3988  // slice, there is a second independent reference picture list RefPicList1 in addition to RefPicList0.
3989
3990  // At the beginning of the decoding process for each slice, the reference picture lists RefPicList0 and, for B slices, RefPicList1
3991  // are derived as follows:
3992
3993  // The variable NumRpsCurrTempList0 is set equal to Max( num_ref_idx_l0_active_minus1 + 1, NumPicTotalCurr )
3994  Int numRpsCurrTempList0 = std::max( getNumRefIdxL0ActiveMinus1() + 1, getNumPicTotalCurr() );
3995
3996  // and the list RefPicListTemp0 is constructed as follows:
3997  std::vector<TComPic*> refPicListTemp0;
3998  refPicListTemp0.resize((MAX_NUM_REF+1),NULL);
3999
4000  const TComDecodedRps* decRps = getPic()->getDecodedRps(); 
4001
4002  const std::vector<TComPic*>& refPicSetStCurrBefore  = decRps->m_refPicSetStCurrBefore; 
4003  const std::vector<TComPic*>& refPicSetStCurrAfter   = decRps->m_refPicSetStCurrAfter;
4004  const std::vector<TComPic*>& refPicSetLtCurr        = decRps->m_refPicSetLtCurr; 
4005
4006  const Int                    numPocStCurrBefore     = decRps->m_numPocStCurrBefore; 
4007  const Int                    numPocStCurrAfter      = decRps->m_numPocStCurrAfter;
4008  const Int                    numPocLtCurr           = decRps->m_numPocLtCurr;
4009
4010  const Int                    numActiveRefLayerPics0 = decRps->m_numActiveRefLayerPics0;
4011  const Int                    numActiveRefLayerPics1 = decRps->m_numActiveRefLayerPics1;
4012
4013  const std::vector<TComPic*>& refPicSetInterLayer0   = decRps->m_refPicSetInterLayer0;
4014  const std::vector<TComPic*>& refPicSetInterLayer1   = decRps->m_refPicSetInterLayer1;
4015
4016  Int rIdx = 0;
4017  while( rIdx < numRpsCurrTempList0 )
4018  {
4019    for(Int  i = 0; i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
4020    {
4021      refPicListTemp0[ rIdx ] = refPicSetStCurrBefore[ i ];
4022    }   
4023
4024    for(Int  i = 0; i < numActiveRefLayerPics0; rIdx++, i++ )
4025    {
4026      refPicListTemp0[ rIdx ] = refPicSetInterLayer0[ i ];
4027    }
4028
4029    for(Int  i = 0;  i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )  // (F 65)
4030    {
4031      refPicListTemp0[ rIdx ] = refPicSetStCurrAfter[ i ];
4032    }
4033
4034    for(Int  i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
4035    {
4036      refPicListTemp0[ rIdx ] = refPicSetLtCurr[ i ]; 
4037    }
4038
4039    for(Int  i = 0; i < numActiveRefLayerPics1; rIdx++, i++ )
4040    {
4041      refPicListTemp0[ rIdx ] = refPicSetInterLayer1[ i ];
4042    }
4043  }
4044
4045  // The list RefPicList0 is constructed as follows:
4046  TComRefPicListModification* rplm  = getRefPicListModification(); 
4047  for( rIdx = 0; rIdx  <=  getNumRefIdxL0ActiveMinus1(); rIdx++ )      //  (F 66)
4048  {
4049    m_apcRefPicList[ 0 ][ rIdx ] = rplm->getRefPicListModificationFlagL0( ) ? refPicListTemp0[ rplm->getListEntryL0( rIdx )] : refPicListTemp0[ rIdx ];
4050    // The decoding process below slice level requires the status
4051    // of the reference pictures, when decoding the RPS. So store it here.
4052    m_bIsUsedAsLongTerm[ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getIsLongTerm();
4053    m_aiRefPOCList     [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getPOC();
4054    m_aiRefLayerIdList [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getLayerId();
4055  } 
4056
4057  std::vector<TComPic*> refPicListTemp1;
4058  refPicListTemp1.resize((MAX_NUM_REF+1),NULL);
4059
4060  if (getSliceType() == B_SLICE )
4061  {
4062    // When the slice is a B slice, the variable NumRpsCurrTempList1 is set equal to
4063    // Max( num_ref_idx_l1_active_minus1 + 1, NumPicTotalCurr ) and the list RefPicListTemp1 is constructed as follows:       
4064    Int numRpsCurrTempList1 = std::max( getNumRefIdxL1ActiveMinus1() + 1, getNumPicTotalCurr() );
4065
4066    rIdx = 0; 
4067    while( rIdx < numRpsCurrTempList1 )
4068    {
4069      for( Int i = 0; i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
4070      {
4071        refPicListTemp1[ rIdx ] = refPicSetStCurrAfter[ i ]; 
4072      }
4073      for( Int i = 0; i< numActiveRefLayerPics1; rIdx++, i++ )
4074      {
4075        refPicListTemp1[ rIdx ] = refPicSetInterLayer1[ i ]; 
4076      }
4077      for( Int i = 0;  i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )  // (F 67)
4078      {
4079        refPicListTemp1[ rIdx ] = refPicSetStCurrBefore[ i ];
4080      }         
4081      for( Int i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
4082      {
4083        refPicListTemp1[ rIdx ] = refPicSetLtCurr[ i ];
4084      }
4085      for( Int i = 0; i< numActiveRefLayerPics0; rIdx++, i++ )
4086      {
4087        refPicListTemp1[ rIdx ] = refPicSetInterLayer0[ i ]; 
4088      }
4089    }
4090  }
4091
4092  if (getSliceType() == B_SLICE )
4093  {
4094    //   When the slice is a B slice, the list RefPicList1 is constructed as follows:
4095    for( rIdx = 0; rIdx  <=  getNumRefIdxL1ActiveMinus1(); rIdx++ )      // (F 68)
4096    {
4097      m_apcRefPicList[ 1 ][ rIdx ] = rplm->getRefPicListModificationFlagL1() ? refPicListTemp1[ rplm->getListEntryL1( rIdx ) ] : refPicListTemp1[ rIdx ]; 
4098
4099      // The decoding process below slice level requires the marking status
4100      // of the reference pictures, when decoding the RPS. So store it here.
4101      m_bIsUsedAsLongTerm[ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getIsLongTerm();
4102      m_aiRefPOCList     [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getPOC();
4103      m_aiRefLayerIdList [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getLayerId();
4104    }   
4105  }
4106}
4107
4108
4109Void TComSlice::cl834DecProcForRefPicListConst()
4110{
4111  // This process is invoked at the beginning of the decoding process for each P or B slice.
4112  assert( getSliceType() == B_SLICE || getSliceType() == P_SLICE );
4113
4114  // Reference pictures are addressed through reference indices as specified in clause 8.5.3.3.2. A reference index is an index into
4115  // a reference picture list. When decoding a P slice, there is a single reference picture list RefPicList0. When decoding a B
4116  // slice, there is a second independent reference picture list RefPicList1 in addition to RefPicList0.
4117
4118  // At the beginning of the decoding process for each slice, the reference picture lists RefPicList0 and, for B slices, RefPicList1
4119  // are derived as follows:
4120
4121  // The variable NumRpsCurrTempList0 is set equal to Max( num_ref_idx_l0_active_minus1 + 1, NumPicTotalCurr )
4122  Int numRpsCurrTempList0 = std::max( getNumRefIdxL0ActiveMinus1() + 1, getNumPicTotalCurr() );
4123
4124  // and the list RefPicListTemp0 is constructed as follows:
4125  std::vector<TComPic*> refPicListTemp0; 
4126  refPicListTemp0.resize((MAX_NUM_REF+1),NULL);
4127
4128  const TComDecodedRps* decRps = getPic()->getDecodedRps(); 
4129
4130  const std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore; 
4131  const std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter;
4132  const std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr; 
4133   
4134  const Int                    numPocStCurrBefore    = decRps->m_numPocStCurrBefore; 
4135  const Int                    numPocStCurrAfter     = decRps->m_numPocStCurrAfter;
4136  const Int                    numPocLtCurr          = decRps->m_numPocLtCurr;
4137
4138  Int rIdx = 0;
4139  while( rIdx < numRpsCurrTempList0 )
4140  {
4141    for(Int  i = 0; i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
4142    {
4143      refPicListTemp0[ rIdx ] = refPicSetStCurrBefore[ i ];
4144    }   
4145
4146    for(Int  i = 0;  i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )  // (8 8)
4147    {
4148      refPicListTemp0[ rIdx ] = refPicSetStCurrAfter[ i ];
4149    }
4150
4151    for(Int  i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
4152    {
4153      refPicListTemp0[ rIdx ] = refPicSetLtCurr[ i ]; 
4154    }
4155  }
4156
4157  // The list RefPicList0 is constructed as follows:
4158
4159  TComRefPicListModification* rplm = getRefPicListModification(); 
4160  for( rIdx = 0; rIdx  <=  getNumRefIdxL0ActiveMinus1(); rIdx++ )      //   (8-9)
4161  {
4162    m_apcRefPicList[0][ rIdx ] = rplm->getRefPicListModificationFlagL0( ) ? refPicListTemp0[ rplm->getListEntryL0( rIdx )] : refPicListTemp0[ rIdx ];
4163
4164    // The decoding process below slice level requires the marking status
4165    // of the reference pictures, when decoding the RPS. So store it here.
4166    m_bIsUsedAsLongTerm[ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getIsLongTerm();
4167    m_aiRefPOCList     [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getPOC();
4168    m_aiRefLayerIdList [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getLayerId();
4169  }
4170
4171  std::vector<TComPic*> refPicListTemp1;
4172  refPicListTemp1.resize((MAX_NUM_REF+1),NULL);
4173
4174  if (getSliceType() == B_SLICE )
4175  {
4176    // When the slice is a B slice, the variable NumRpsCurrTempList1 is set equal to
4177    // Max( num_ref_idx_l1_active_minus1 + 1, NumPicTotalCurr ) and the list RefPicListTemp1 is constructed as follows:
4178    Int numRpsCurrTempList1 = std::max( getNumRefIdxL1ActiveMinus1() + 1, getNumPicTotalCurr() );
4179
4180    rIdx = 0; 
4181    while( rIdx < numRpsCurrTempList1 )
4182    {
4183      for( Int i = 0; i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
4184      {
4185        refPicListTemp1[ rIdx ] = refPicSetStCurrAfter[ i ]; 
4186      }
4187      for( Int i = 0;  i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )  // (8-10)
4188      {
4189        refPicListTemp1[ rIdx ] = refPicSetStCurrBefore[ i ];
4190      }         
4191      for( Int i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
4192      {
4193        refPicListTemp1[ rIdx ] = refPicSetLtCurr[ i ];
4194      }
4195    }
4196  }
4197
4198  if (getSliceType() == B_SLICE )
4199  {
4200    //   When the slice is a B slice, the list RefPicList1 is constructed as follows:
4201    for( rIdx = 0; rIdx  <=  getNumRefIdxL1ActiveMinus1(); rIdx++ )      // (F 68)
4202    {
4203      m_apcRefPicList[ 1 ][ rIdx ] = rplm->getRefPicListModificationFlagL1() ? refPicListTemp1[ rplm->getListEntryL1( rIdx ) ] : refPicListTemp1[ rIdx ]; 
4204
4205      // The decoding process below slice level requires the marking status
4206      // of the reference pictures, when decoding the RPS. So store it here.
4207      m_bIsUsedAsLongTerm[ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getIsLongTerm();
4208      m_aiRefPOCList     [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getPOC();
4209      m_aiRefLayerIdList [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getLayerId();
4210    }
4211  }
4212}
4213
4214Int TComSlice::getNumPicTotalCurr() const
4215{
4216  Int numPicTotalCurr = 0;
4217#if NH_MV_FIX_NUM_POC_TOTAL_CUR
4218  if ( !isIdr()  )
4219  {
4220    const TComStRefPicSet* stRps = getStRps( getCurrRpsIdx() ); 
4221#endif
4222    for( Int i = 0; i < stRps->getNumNegativePicsVar(); i++ )
4223    {
4224      if( stRps->getUsedByCurrPicS0Var( i ) )
4225      {
4226        numPicTotalCurr++;
4227      }
4228    }
4229    for( Int i = 0; i < stRps->getNumPositivePicsVar(); i++)  //(7 55)
4230    {
4231      if( stRps->getUsedByCurrPicS1Var(i) )
4232      {
4233        numPicTotalCurr++;
4234      }
4235    }
4236    for( Int i = 0; i < getNumLongTermSps() + getNumLongTermPics(); i++ )
4237    {
4238      if( getUsedByCurrPicLtVar( i ) )
4239      {
4240        numPicTotalCurr++;
4241      }
4242    }
4243#if NH_MV_FIX_NUM_POC_TOTAL_CUR
4244  }
4245#endif
4246
4247  if ( decProcAnnexF() )
4248  {
4249    numPicTotalCurr += getNumActiveRefLayerPics(); 
4250  }
4251  return numPicTotalCurr;
4252}
4253
4254
4255
4256Int TComSlice::getPocLsbLtVar( Int i )
4257{
4258  Int pocLsbLtVar; 
4259  if (i < getNumLongTermSps() )
4260  {
4261
4262    pocLsbLtVar = getSPS()->getLtRefPicPocLsbSps( getLtIdxSps( i ) ); 
4263  }
4264  else
4265  {
4266    pocLsbLtVar = getPocLsbLt( i ); 
4267  }
4268  return pocLsbLtVar;
4269}
4270
4271
4272Bool TComSlice::getUsedByCurrPicLtVar( Int i ) const
4273{
4274  Bool usedByCurrPicLtVar; 
4275  if (i < getNumLongTermSps() )
4276  {
4277    usedByCurrPicLtVar = getSPS()->getUsedByCurrPicLtSPSFlag( getLtIdxSps( i ) ); 
4278  }
4279  else
4280  {
4281    usedByCurrPicLtVar = getUsedByCurrPicLtFlag( i ); 
4282  }
4283  return usedByCurrPicLtVar;
4284}
4285
4286
4287Int TComSlice::getDeltaPocMsbCycleLtVar( Int i ) const
4288{
4289  Int deltaPocMsbCycleVar; 
4290  if (i == 0 || i == getNumLongTermSps() )
4291  {
4292    deltaPocMsbCycleVar = getDeltaPocMsbCycleLt( i ); 
4293  }
4294  else
4295  {
4296    deltaPocMsbCycleVar = getDeltaPocMsbCycleLt( i ) + getDeltaPocMsbCycleLtVar( i - 1 ); 
4297  }
4298  return deltaPocMsbCycleVar;
4299}
4300
4301#endif
4302
4303
4304#if NH_3D
4305Void TComSlice::init3dToolParameters()
4306{
4307  Bool depthFlag = getIsDepth();
4308
4309  Bool nRLLG0 =  ( getVPS()->getNumRefListLayers( getLayerId() ) > 0 );     
4310
4311  const TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
4312
4313  m_ivMvPredFlag           = sps3dExt->getIvMvPredFlag         ( depthFlag ) && nRLLG0                       ;                             
4314  m_ivMvScalingFlag        = sps3dExt->getIvMvScalingFlag      ( depthFlag )                                 ;                             
4315  m_ivResPredFlag          = sps3dExt->getIvResPredFlag        ( depthFlag ) && nRLLG0                       ;                               
4316  m_depthRefinementFlag    = sps3dExt->getDepthRefinementFlag  ( depthFlag )           && getInCompPredFlag() && m_cpAvailableFlag;
4317  m_viewSynthesisPredFlag  = sps3dExt->getViewSynthesisPredFlag( depthFlag ) && nRLLG0 && getInCompPredFlag() && m_cpAvailableFlag;
4318  m_depthBasedBlkPartFlag  = sps3dExt->getDepthBasedBlkPartFlag( depthFlag )           && getInCompPredFlag();                         
4319  m_mpiFlag                = sps3dExt->getMpiFlag              ( depthFlag )           && getInCompPredFlag();
4320  m_intraContourFlag       = sps3dExt->getIntraContourFlag     ( depthFlag )           && getInCompPredFlag();
4321  m_intraSdcWedgeFlag      = sps3dExt->getIntraSdcWedgeFlag    ( depthFlag )                                 ;                         
4322  m_qtPredFlag             = sps3dExt->getQtPredFlag           ( depthFlag )           && getInCompPredFlag();
4323  m_interSdcFlag           = sps3dExt->getInterSdcFlag         ( depthFlag )                                 ; 
4324  m_depthIntraSkipFlag     = sps3dExt->getDepthIntraSkipFlag   ( depthFlag )                                 ;                         
4325
4326  m_subPbSize              =  1 << ( sps3dExt->getLog2SubPbSizeMinus3   ( depthFlag ) + 3 ); 
4327  m_mpiSubPbSize           =  1 << ( sps3dExt->getLog2MpiSubPbSizeMinus3( depthFlag ) + 3 );
4328
4329
4330#if H_3D_OUTPUT_ACTIVE_TOOLS
4331  std::cout << "Layer:                  :" << getLayerId()             << std::endl;
4332  std::cout << "DepthFlag:              :" << getIsDepth()             << std::endl;
4333  std::cout << "ViewOrderIdx:           :" << getViewIndex()           << std::endl;
4334  std::cout << "InterCmpPredAvailableFlag:" << getInCmpPredAvailFlag() << std::endl;
4335  std::cout << "InterCompPredFlag       :"  << getInCompPredFlag()     << std::endl;
4336 
4337  std::cout << "ivMvPredFlag            :" << m_ivMvPredFlag           << std::endl;
4338  std::cout << "ivMvScalingFlag         :" << m_ivMvScalingFlag        << std::endl;
4339  std::cout << "ivResPredFlag           :" << m_ivResPredFlag          << std::endl;
4340  std::cout << "depthRefinementFlag     :" << m_depthRefinementFlag    << std::endl;
4341  std::cout << "viewSynthesisPredFlag   :" << m_viewSynthesisPredFlag  << std::endl;
4342  std::cout << "depthBasedBlkPartFlag   :" << m_depthBasedBlkPartFlag  << std::endl;
4343  std::cout << "mpiFlag                 :" << m_mpiFlag                << std::endl;
4344  std::cout << "intraContourFlag        :" << m_intraContourFlag       << std::endl;
4345  std::cout << "intraSdcWedgeFlag       :" << m_intraSdcWedgeFlag      << std::endl;
4346  std::cout << "qtPredFlag              :" << m_qtPredFlag             << std::endl;
4347  std::cout << "interSdcFlag            :" << m_interSdcFlag           << std::endl;
4348  std::cout << "depthIntraSkipFlag      :" << m_depthIntraSkipFlag     << std::endl;   
4349  std::cout << "subPbSize               :" << m_subPbSize              << std::endl;
4350  std::cout << "mpiSubPbSize            :" << m_mpiSubPbSize           << std::endl;
4351#endif
4352}
4353
4354Void TComSlice::deriveInCmpPredAndCpAvailFlag( )
4355{
4356  Int numCurCmpLIds = getIsDepth() ? 1 : getNumActiveRefLayerPics(); 
4357  std::vector<Int> curCmpLIds;
4358  if ( getIsDepth() )
4359  {
4360    curCmpLIds.push_back( getLayerId() );
4361  }
4362  else
4363  {
4364    for (Int i = 0; i < numCurCmpLIds; i++)
4365    {
4366      curCmpLIds.push_back( getRefPicLayerId( i ) );
4367    }
4368  }
4369
4370  m_cpAvailableFlag = true;
4371  m_inCmpRefViewIdcs.clear();
4372  Bool allRefCmpLayersAvailFlag = true;
4373
4374  for( Int i = 0; i <= numCurCmpLIds - 1; i++ )
4375  {     
4376    m_inCmpRefViewIdcs.push_back( getVPS()->getViewOrderIdx( curCmpLIds[ i ] ));
4377    if( !getVPS()->getCpPresentFlag( getVPS()->getVoiInVps( getViewIndex() ),  getVPS()->getVoiInVps( m_inCmpRefViewIdcs[ i ] ) ) )
4378    {
4379      m_cpAvailableFlag = false;
4380    }
4381    Bool refCmpCurLIdAvailFlag = false;
4382    if( getVPS()->getViewCompLayerPresentFlag( m_inCmpRefViewIdcs[ i ], !getIsDepth() ) )
4383    {
4384      Int j = getVPS()->getLayerIdInVps( getVPS()->getViewCompLayerId( m_inCmpRefViewIdcs[ i ],  !getIsDepth() ) );
4385      if  ( getVPS()->getDirectDependencyFlag( getVPS()->getLayerIdInVps( getLayerId() ) ,  j ) &&
4386        getVPS()->getSubLayersVpsMaxMinus1( j ) >= getTemporalId()   &&
4387        ( getTemporalId() == 0 || getVPS()->getMaxTidIlRefPicsPlus1( j , getVPS()->getLayerIdInVps( getLayerId() ) ) > getTemporalId() )       
4388        )
4389      {
4390        refCmpCurLIdAvailFlag = true;
4391      }
4392    }
4393    if( !refCmpCurLIdAvailFlag )
4394    {
4395      allRefCmpLayersAvailFlag = false;
4396    }
4397  }
4398
4399  if( !allRefCmpLayersAvailFlag )
4400  {
4401    m_inCmpPredAvailFlag = false;
4402  } 
4403  else 
4404  {
4405    const TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
4406    if( !getIsDepth() )
4407    {
4408      m_inCmpPredAvailFlag = sps3dExt->getViewSynthesisPredFlag( getIsDepth() ) || 
4409        sps3dExt->getDepthBasedBlkPartFlag( getIsDepth() ) || 
4410        sps3dExt->getDepthRefinementFlag  ( getIsDepth() );                           
4411    }
4412    else
4413    {
4414      m_inCmpPredAvailFlag = sps3dExt->getIntraContourFlag( getIsDepth() ) || 
4415        sps3dExt->getQtPredFlag( getIsDepth() ) || 
4416        sps3dExt->getMpiFlag( getIsDepth() );                                 
4417    }
4418  }
4419}
4420
4421Void TComSlice::checkInCompPredRefLayers()
4422{ 
4423  if ( getInCompPredFlag() )
4424  {
4425    for (Int i = 0; i < getNumCurCmpLIds(); i++ )
4426    {     
4427      assert( getIvPic(!getIsDepth(), getInCmpRefViewIdcs( i ) ) != NULL );       
4428      //  It is a requirement of bitstream conformance that there
4429      //  is a picture in the DPB with PicOrderCntVal equal to the PicOrderCntVal of the current picture,
4430      //  and a nuh_layer_id value equal to ViewCompLayerId[ inCmpRefViewIdcs[ i ] ][ !DepthFlag ].
4431    }
4432  } 
4433}
4434
4435Void TComSlice::setPocsInCurrRPSs()
4436{
4437  // Currently only needed at decoder side;
4438  m_pocsInCurrRPSs.clear();   
4439  std::vector<TComPic*>** rpsCurr = getPic()->getDecodedRps()->m_refPicSetsCurr;
4440  for (Int i = 0 ; i < 3; i++ )
4441  {
4442    for( Int j = 0; j < rpsCurr[i]->size(); j++ )
4443    {
4444      m_pocsInCurrRPSs.push_back( (*rpsCurr[i])[j]->getPOC() ); 
4445    }
4446  }
4447}
4448
4449#endif
4450
4451/** get scaling matrix from RefMatrixID
4452 * \param sizeId    size index
4453 * \param listId    index of input matrix
4454 * \param refListId index of reference matrix
4455 */
4456Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
4457{
4458  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
4459}
4460
4461Void TComScalingList::checkPredMode(UInt sizeId, UInt listId)
4462{
4463  Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries.
4464
4465  for(Int predListIdx = (Int)listId ; predListIdx >= 0; predListIdx-=predListStep)
4466  {
4467    if( !memcmp(getScalingListAddress(sizeId,listId),((listId == predListIdx) ?
4468      getScalingListDefaultAddress(sizeId, predListIdx): getScalingListAddress(sizeId, predListIdx)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
4469     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value
4470    {
4471      setRefMatrixId(sizeId, listId, predListIdx);
4472      setScalingListPredModeFlag(sizeId, listId, false);
4473      return;
4474    }
4475  }
4476  setScalingListPredModeFlag(sizeId, listId, true);
4477}
4478
4479static Void outputScalingListHelp(std::ostream &os)
4480{
4481  os << "The scaling list file specifies all matrices and their DC values; none can be missing,\n"
4482         "but their order is arbitrary.\n\n"
4483         "The matrices are specified by:\n"
4484         "<matrix name><unchecked data>\n"
4485         "  <value>,<value>,<value>,....\n\n"
4486         "  Line-feeds can be added arbitrarily between values, and the number of values needs to be\n"
4487         "  at least the number of entries for the matrix (superfluous entries are ignored).\n"
4488         "  The <unchecked data> is text on the same line as the matrix that is not checked\n"
4489         "  except to ensure that the matrix name token is unique. It is recommended that it is ' ='\n"
4490         "  The values in the matrices are the absolute values (0-255), not the delta values as\n"
4491         "  exchanged between the encoder and decoder\n\n"
4492         "The DC values (for matrix sizes larger than 8x8) are specified by:\n"
4493         "<matrix name>_DC<unchecked data>\n"
4494         "  <value>\n";
4495
4496  os << "The permitted matrix names are:\n";
4497  for(UInt sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
4498  {
4499    for(UInt listIdc = 0; listIdc < SCALING_LIST_NUM; listIdc++)
4500    {
4501      if ((sizeIdc!=SCALING_LIST_32x32) || (listIdc%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) == 0))
4502      {
4503        os << "  " << MatrixType[sizeIdc][listIdc] << '\n';
4504      }
4505    }
4506  }
4507}
4508
4509Void TComScalingList::outputScalingLists(std::ostream &os) const
4510{
4511  for(UInt sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
4512  {
4513    const UInt size = min(8,4<<(sizeIdc));
4514    for(UInt listIdc = 0; listIdc < SCALING_LIST_NUM; listIdc++)
4515    {
4516      if ((sizeIdc!=SCALING_LIST_32x32) || (listIdc%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) == 0))
4517      {
4518        const Int *src = getScalingListAddress(sizeIdc, listIdc);
4519        os << (MatrixType[sizeIdc][listIdc]) << " =\n  ";
4520        for(UInt y=0; y<size; y++)
4521        {
4522          for(UInt x=0; x<size; x++, src++)
4523          {
4524            os << std::setw(3) << (*src) << ", ";
4525          }
4526          os << (y+1<size?"\n  ":"\n");
4527        }
4528        if(sizeIdc > SCALING_LIST_8x8)
4529        {
4530          os << MatrixType_DC[sizeIdc][listIdc] << " = \n  " << std::setw(3) << getScalingListDC(sizeIdc, listIdc) << "\n";
4531        }
4532        os << "\n";
4533      }
4534    }
4535  }
4536}
4537
4538Bool TComScalingList::xParseScalingList(const std::string &fileName)
4539{
4540  static const Int LINE_SIZE=1024;
4541  FILE *fp = NULL;
4542  TChar line[LINE_SIZE];
4543
4544  if (fileName.empty())
4545  {
4546    fprintf(stderr, "Error: no scaling list file specified. Help on scaling lists being output\n");
4547    outputScalingListHelp(std::cout);
4548    std::cout << "\n\nExample scaling list file using default values:\n\n";
4549    outputScalingLists(std::cout);
4550    exit (1);
4551    return true;
4552  }
4553  else if ((fp = fopen(fileName.c_str(),"r")) == (FILE*)NULL)
4554  {
4555    fprintf(stderr, "Error: cannot open scaling list file %s for reading\n", fileName.c_str());
4556    return true;
4557  }
4558
4559  for(UInt sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
4560  {
4561    const UInt size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
4562
4563    for(UInt listIdc = 0; listIdc < SCALING_LIST_NUM; listIdc++)
4564    {
4565      Int * const src = getScalingListAddress(sizeIdc, listIdc);
4566
4567      if ((sizeIdc==SCALING_LIST_32x32) && (listIdc%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) != 0)) // derive chroma32x32 from chroma16x16
4568      {
4569        const Int *srcNextSmallerSize = getScalingListAddress(sizeIdc-1, listIdc);
4570        for(UInt i=0; i<size; i++)
4571        {
4572          src[i] = srcNextSmallerSize[i];
4573        }
4574        setScalingListDC(sizeIdc,listIdc,(sizeIdc > SCALING_LIST_8x8) ? getScalingListDC(sizeIdc-1, listIdc) : src[0]);
4575      }
4576      else
4577      {
4578        {
4579          fseek(fp, 0, SEEK_SET);
4580          Bool bFound=false;
4581          while ((!feof(fp)) && (!bFound))
4582          {
4583            TChar *ret = fgets(line, LINE_SIZE, fp);
4584            TChar *findNamePosition= ret==NULL ? NULL : strstr(line, MatrixType[sizeIdc][listIdc]);
4585            // This could be a match against the DC string as well, so verify it isn't
4586            if (findNamePosition!= NULL && (MatrixType_DC[sizeIdc][listIdc]==NULL || strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL))
4587            {
4588              bFound=true;
4589            }
4590          }
4591          if (!bFound)
4592          {
4593            fprintf(stderr, "Error: cannot find Matrix %s from scaling list file %s\n", MatrixType[sizeIdc][listIdc], fileName.c_str());
4594            return true;
4595          }
4596        }
4597        for (UInt i=0; i<size; i++)
4598        {
4599          Int data;
4600          if (fscanf(fp, "%d,", &data)!=1)
4601          {
4602            fprintf(stderr, "Error: cannot read value #%d for Matrix %s from scaling list file %s at file position %ld\n", i, MatrixType[sizeIdc][listIdc], fileName.c_str(), ftell(fp));
4603            return true;
4604          }
4605          if (data<0 || data>255)
4606          {
4607            fprintf(stderr, "Error: QMatrix entry #%d of value %d for Matrix %s from scaling list file %s at file position %ld is out of range (0 to 255)\n", i, data, MatrixType[sizeIdc][listIdc], fileName.c_str(), ftell(fp));
4608            return true;
4609          }
4610          src[i] = data;
4611        }
4612
4613        //set DC value for default matrix check
4614        setScalingListDC(sizeIdc,listIdc,src[0]);
4615
4616        if(sizeIdc > SCALING_LIST_8x8)
4617        {
4618          {
4619            fseek(fp, 0, SEEK_SET);
4620            Bool bFound=false;
4621            while ((!feof(fp)) && (!bFound))
4622            {
4623              TChar *ret = fgets(line, LINE_SIZE, fp);
4624              TChar *findNamePosition= ret==NULL ? NULL : strstr(line, MatrixType_DC[sizeIdc][listIdc]);
4625              if (findNamePosition!= NULL)
4626              {
4627                // This won't be a match against the non-DC string.
4628                bFound=true;
4629              }
4630            }
4631            if (!bFound)
4632            {
4633              fprintf(stderr, "Error: cannot find DC Matrix %s from scaling list file %s\n", MatrixType_DC[sizeIdc][listIdc], fileName.c_str());
4634              return true;
4635            }
4636          }
4637          Int data;
4638          if (fscanf(fp, "%d,", &data)!=1)
4639          {
4640            fprintf(stderr, "Error: cannot read DC %s from scaling list file %s at file position %ld\n", MatrixType_DC[sizeIdc][listIdc], fileName.c_str(), ftell(fp));
4641            return true;
4642          }
4643          if (data<0 || data>255)
4644          {
4645            fprintf(stderr, "Error: DC value %d for Matrix %s from scaling list file %s at file position %ld is out of range (0 to 255)\n", data, MatrixType[sizeIdc][listIdc], fileName.c_str(), ftell(fp));
4646            return true;
4647          }
4648          //overwrite DC value when size of matrix is larger than 16x16
4649          setScalingListDC(sizeIdc,listIdc,data);
4650        }
4651      }
4652    }
4653  }
4654//  std::cout << "\n\nRead scaling lists of:\n\n";
4655//  outputScalingLists(std::cout);
4656
4657  fclose(fp);
4658  return false;
4659}
4660
4661#if NH_MV
4662Void TComScalingList::inferFrom( const TComScalingList& srcScLi )
4663{
4664  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
4665  {
4666    for(Int listId = 0; listId <  SCALING_LIST_NUM; listId++)
4667    {
4668      setRefMatrixId  (sizeId,listId, srcScLi.getRefMatrixId  (sizeId,listId));
4669      setScalingListDC(sizeId,listId, srcScLi.getScalingListDC(sizeId,listId));         
4670      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi.getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
4671    }
4672  }
4673}
4674#endif
4675
4676
4677/** get default address of quantization matrix
4678 * \param sizeId size index
4679 * \param listId list index
4680 * \returns pointer of quantization matrix
4681 */
4682const Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
4683{
4684  const Int *src = 0;
4685  switch(sizeId)
4686  {
4687    case SCALING_LIST_4x4:
4688      src = g_quantTSDefault4x4;
4689      break;
4690    case SCALING_LIST_8x8:
4691    case SCALING_LIST_16x16:
4692    case SCALING_LIST_32x32:
4693      src = (listId < (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) ) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
4694      break;
4695    default:
4696      assert(0);
4697      src = NULL;
4698      break;
4699  }
4700  return src;
4701}
4702
4703/** process of default matrix
4704 * \param sizeId size index
4705 * \param listId index of input matrix
4706 */
4707Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
4708{
4709  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
4710  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
4711}
4712
4713/** check DC value of matrix for default matrix signaling
4714 */
4715Void TComScalingList::checkDcOfMatrix()
4716{
4717  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
4718  {
4719    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId++)
4720    {
4721      //check default matrix?
4722      if(getScalingListDC(sizeId,listId) == 0)
4723      {
4724        processDefaultMatrix(sizeId, listId);
4725      }
4726    }
4727  }
4728}
4729
4730ParameterSetManager::ParameterSetManager()
4731: m_vpsMap(MAX_NUM_VPS)
4732, m_spsMap(MAX_NUM_SPS)
4733, m_ppsMap(MAX_NUM_PPS)
4734, m_activeVPSId(-1)
4735#if !NH_MV
4736, m_activeSPSId(-1)
4737#endif
4738{
4739#if NH_MV 
4740  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
4741  {   
4742    m_activeSPSId[i] = -1; 
4743  }
4744#endif
4745}
4746
4747
4748ParameterSetManager::~ParameterSetManager()
4749{
4750}
4751
4752//! activate a SPS from a active parameter sets SEI message
4753//! \returns true, if activation is successful
4754#if NH_MV
4755//Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
4756#else
4757//Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
4758#endif
4759//{
4760//TComSPS *sps = m_spsMap.getPS(spsId);
4761//  if (sps)
4762//  {
4763//    Int vpsId = sps->getVPSId();
4764//    TComVPS *vps = m_vpsMap.getPS(vpsId);
4765//    if (vps)
4766//    {
4767#if NH_MV
4768//      m_activeVPS = *(vps);
4769//      m_activeSPS[ layerId ] = *(sps);
4770#else
4771//      m_activeVPS = *(vps);
4772//      m_activeSPS = *(sps);
4773#endif
4774//      return true;
4775//    }
4776//    else
4777//    {
4778//      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
4779//    }
4780//  }
4781//  else
4782//  {
4783//    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
4784//  }
4785//  return false;
4786//}
4787
4788//! activate a PPS and depending on isIDR parameter also SPS and VPS
4789//! \returns true, if activation is successful
4790#if NH_MV
4791Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
4792#else
4793Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
4794#endif
4795{
4796  TComPPS *pps = m_ppsMap.getPS(ppsId);
4797  if (pps)
4798  {
4799    Int spsId = pps->getSPSId();
4800#if NH_MV
4801    if (!isIRAP && (spsId != m_activeSPSId[ layerId ] ))
4802#else
4803    if (!isIRAP && (spsId != m_activeSPSId ))
4804#endif
4805    {
4806      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
4807    }
4808    else
4809    {
4810      TComSPS *sps = m_spsMap.getPS(spsId);
4811      if (sps)
4812      {
4813        Int vpsId = sps->getVPSId();
4814        if (!isIRAP && (vpsId != m_activeVPSId ))
4815        {
4816          printf("Warning: tried to activate PPS referring to a inactive VPS at non-IDR.");
4817        }
4818        else
4819        {
4820          TComVPS *vps =m_vpsMap.getPS(vpsId);
4821          if (vps)
4822          {
4823            m_activeVPSId = vpsId;
4824#if NH_MV
4825            m_activeSPSId[layerId] = spsId;
4826#else
4827            m_activeSPSId = spsId;
4828#endif
4829            return true;
4830          }
4831          else
4832          {
4833            printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
4834          }
4835        }
4836      }
4837      else
4838      {
4839       printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
4840      }
4841    }
4842  }
4843  else
4844  {
4845    printf("Warning: tried to activate non-existing PPS.");
4846  }
4847
4848  // Failed to activate if reach here.
4849#if NH_MV
4850  m_activeSPSId[layerId]=-1;
4851#else
4852  m_activeSPSId=-1;
4853#endif
4854  m_activeVPSId=-1;
4855
4856  return false;
4857}
4858
4859ProfileTierLevel::ProfileTierLevel()
4860  : m_profileSpace    (0)
4861  , m_tierFlag        (Level::MAIN)
4862  , m_profileIdc      (Profile::NONE)
4863  , m_levelIdc        (Level::NONE)
4864  , m_progressiveSourceFlag  (false)
4865  , m_interlacedSourceFlag   (false)
4866  , m_nonPackedConstraintFlag(false)
4867  , m_frameOnlyConstraintFlag(false)
4868#if NH_MV
4869  , m_intraConstraintFlag         ( false )
4870  , m_onePictureOnlyConstraintFlag( false )
4871  , m_lowerBitRateConstraintFlag  ( false )
4872  , m_max12bitConstraintFlag      ( false )
4873  , m_max10bitConstraintFlag      ( false )
4874  , m_max8bitConstraintFlag       ( false )
4875  , m_max422chromaConstraintFlag  ( false )
4876  , m_max420chromaConstraintFlag  ( false )
4877  , m_maxMonochromeConstraintFlag ( false ) 
4878  , m_inbldFlag                   ( false )
4879#endif
4880{
4881  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
4882}
4883
4884#if NH_MV
4885Bool ProfileTierLevel::getV2ConstraintsPresentFlag() const
4886{
4887  return ( 
4888    getProfileIdc( ) ==  4 || getProfileCompatibilityFlag( 4 ) || getProfileIdc( ) ==  5 || getProfileCompatibilityFlag( 5 )  ||
4889    getProfileIdc( ) ==  6 || getProfileCompatibilityFlag( 6 ) || getProfileIdc( ) ==  7 || getProfileCompatibilityFlag( 7 ) 
4890    );
4891}
4892
4893Bool ProfileTierLevel::getInbldPresentFlag() const
4894{
4895  return ( 
4896    ( getProfileIdc() >= 1 && getProfileIdc() <= 5 )  || getProfileCompatibilityFlag( 1 ) || getProfileCompatibilityFlag( 2 ) || 
4897    getProfileCompatibilityFlag( 3 ) || getProfileCompatibilityFlag( 4 )  ||   getProfileCompatibilityFlag( 5 ) 
4898    );
4899}
4900
4901Void ProfileTierLevel::copyV2ConstraintFlags(ProfileTierLevel* ptlRef)
4902{
4903  setMax12bitConstraintFlag         ( ptlRef->getMax12bitConstraintFlag       ( ) );
4904  setMax10bitConstraintFlag         ( ptlRef->getMax10bitConstraintFlag       ( ) );
4905  setMax8bitConstraintFlag          ( ptlRef->getMax8bitConstraintFlag        ( ) );
4906  setMax422chromaConstraintFlag     ( ptlRef->getMax422chromaConstraintFlag   ( ) );
4907  setMax420chromaConstraintFlag     ( ptlRef->getMax420chromaConstraintFlag   ( ) );
4908  setMaxMonochromeConstraintFlag    ( ptlRef->getMaxMonochromeConstraintFlag  ( ) );
4909  setIntraConstraintFlag            ( ptlRef->getIntraConstraintFlag          ( ) );
4910  setOnePictureOnlyConstraintFlag   ( ptlRef->getOnePictureOnlyConstraintFlag ( ) );
4911  setLowerBitRateConstraintFlag     ( ptlRef->getLowerBitRateConstraintFlag   ( ) );
4912}
4913
4914Void ProfileTierLevel::copyProfile(ProfileTierLevel* ptlRef)
4915{
4916  setProfileSpace            ( ptlRef->getProfileSpace              ( ) );
4917  setTierFlag                ( ptlRef->getTierFlag                  ( ) );
4918  setProfileIdc              ( ptlRef->getProfileIdc                ( ) );
4919  for (Int j = 0; j < 32; j++)
4920  {     
4921    setProfileCompatibilityFlag(j, ptlRef->getProfileCompatibilityFlag  ( j ) );           
4922  }
4923  setProgressiveSourceFlag   ( ptlRef->getProgressiveSourceFlag     ( ) );
4924  setInterlacedSourceFlag    ( ptlRef->getInterlacedSourceFlag      ( ) );
4925  setNonPackedConstraintFlag ( ptlRef->getNonPackedConstraintFlag   ( ) );
4926  setFrameOnlyConstraintFlag ( ptlRef->getFrameOnlyConstraintFlag   ( ) );
4927  copyV2ConstraintFlags      ( ptlRef );
4928}
4929#endif
4930
4931TComPTL::TComPTL()
4932{
4933  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
4934  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
4935}
4936
4937Void calculateParameterSetChangedFlag(Bool &bChanged, const std::vector<UChar> *pOldData, const std::vector<UChar> &newData)
4938{
4939  if (!bChanged)
4940  {
4941    if ((pOldData==0 && pOldData!=0) || (pOldData!=0 && pOldData==0))
4942    {
4943      bChanged=true;
4944    }
4945    else if (pOldData!=0 && pOldData!=0)
4946    {
4947      // compare the two
4948      if (pOldData->size() != pOldData->size())
4949      {
4950        bChanged=true;
4951      }
4952      else
4953      {
4954        const UChar *pNewDataArray=&(newData)[0];
4955        const UChar *pOldDataArray=&(*pOldData)[0];
4956        if (memcmp(pOldDataArray, pNewDataArray, pOldData->size()))
4957        {
4958          bChanged=true;
4959        }
4960      }
4961    }
4962  }
4963}
4964#if NH_MV
4965Void TComPTL::inferGeneralValues(Bool profilePresentFlag, Int k, TComPTL* refPTL)
4966{
4967  ProfileTierLevel* refProfileTierLevel = NULL; 
4968  if ( k > 0 )
4969  {   
4970    assert( refPTL != NULL);
4971    refProfileTierLevel = refPTL->getGeneralPTL(); 
4972  }
4973
4974  ProfileTierLevel* curProfileTierLevel = getGeneralPTL( ); 
4975  assert( curProfileTierLevel != NULL ); 
4976
4977  if( !profilePresentFlag )
4978  {
4979    assert( k > 0 ); 
4980    assert( refProfileTierLevel != NULL ); 
4981    curProfileTierLevel->copyProfile( refProfileTierLevel);
4982  }
4983  else
4984  {
4985    if ( !curProfileTierLevel->getV2ConstraintsPresentFlag() )
4986    {
4987      curProfileTierLevel->setMax12bitConstraintFlag         ( false );
4988      curProfileTierLevel->setMax10bitConstraintFlag         ( false );
4989      curProfileTierLevel->setMax8bitConstraintFlag          ( false );
4990      curProfileTierLevel->setMax422chromaConstraintFlag     ( false );
4991      curProfileTierLevel->setMax420chromaConstraintFlag     ( false );
4992      curProfileTierLevel->setMaxMonochromeConstraintFlag    ( false );
4993      curProfileTierLevel->setIntraConstraintFlag            ( false );
4994      curProfileTierLevel->setOnePictureOnlyConstraintFlag   ( false );
4995      curProfileTierLevel->setLowerBitRateConstraintFlag     ( false );   
4996    }
4997
4998    if ( !curProfileTierLevel->getInbldPresentFlag() )
4999    {
5000      curProfileTierLevel->setInbldFlag( false ); 
5001    }     
5002  }
5003}
5004
5005Void TComPTL::inferSubLayerValues(Int maxNumSubLayersMinus1, Int k, TComPTL* refPTL)
5006{
5007  assert( k == 0 || refPTL != NULL );   
5008  for (Int i = maxNumSubLayersMinus1; i >= 0; i--)
5009  {
5010    ProfileTierLevel* refProfileTierLevel;
5011    if ( k != 0 )
5012    {
5013      refProfileTierLevel = refPTL->getSubLayerPTL( i );
5014    }
5015    else
5016    {
5017      if ( i == maxNumSubLayersMinus1)     
5018      {
5019        refProfileTierLevel = getGeneralPTL();
5020      }
5021      else
5022      {
5023        refProfileTierLevel = getSubLayerPTL( i + 1 );
5024      }
5025    }   
5026
5027    assert( refProfileTierLevel != NULL ); 
5028    ProfileTierLevel* curProfileTierLevel = getSubLayerPTL( i ); 
5029    assert( curProfileTierLevel != NULL ); 
5030    if( !getSubLayerLevelPresentFlag( i ) )
5031    {
5032      curProfileTierLevel->setLevelIdc( refProfileTierLevel->getLevelIdc() ); 
5033    }
5034
5035    if( !getSubLayerProfilePresentFlag( i ) )
5036    {
5037      curProfileTierLevel->copyProfile( refProfileTierLevel);
5038    }
5039    else
5040    {
5041      if ( !curProfileTierLevel->getV2ConstraintsPresentFlag() )
5042      {
5043        curProfileTierLevel->copyV2ConstraintFlags( refProfileTierLevel ); 
5044      }
5045
5046      if ( !curProfileTierLevel->getInbldPresentFlag() )
5047      {
5048        curProfileTierLevel->setInbldFlag( refProfileTierLevel->getInbldFlag() ); 
5049      }     
5050    }     
5051  }
5052}
5053
5054#endif
5055
5056//! \}
5057
5058#if NH_MV
5059Void TComVPSVUI::init( Int numLayerSets, Int maxNumSubLayers, Int maxNumLayers )
5060{
5061  m_crossLayerIrapAlignedFlag = true; 
5062  m_allLayersIdrAlignedFlag   = false; 
5063  m_bitRatePresentVpsFlag     = false;
5064  m_picRatePresentVpsFlag     = false;
5065
5066  m_bitRatePresentFlag          .resize(numLayerSets); 
5067  m_picRatePresentFlag          .resize(numLayerSets); 
5068  m_avgBitRate                  .resize(numLayerSets); 
5069  m_maxBitRate                  .resize(numLayerSets); 
5070  m_constantPicRateIdc          .resize(numLayerSets); 
5071  m_avgPicRate                  .resize(numLayerSets); 
5072
5073  for ( Int i = 0; i < numLayerSets; i++)
5074  { 
5075    m_bitRatePresentFlag          [i].resize( maxNumSubLayers); 
5076    m_picRatePresentFlag          [i].resize( maxNumSubLayers); 
5077    m_avgBitRate                  [i].resize( maxNumSubLayers); 
5078    m_maxBitRate                  [i].resize( maxNumSubLayers); 
5079    m_constantPicRateIdc          [i].resize( maxNumSubLayers); 
5080    m_avgPicRate                  [i].resize( maxNumSubLayers); 
5081    for ( Int j = 0; j < maxNumSubLayers; j++)
5082    {   
5083      m_bitRatePresentFlag          [i][j] = false;
5084      m_picRatePresentFlag          [i][j] = false;
5085      m_avgBitRate                  [i][j] = -1;
5086      m_maxBitRate                  [i][j] = -1;
5087      m_constantPicRateIdc          [i][j] = -1;
5088      m_avgPicRate                  [i][j] = -1;
5089    }
5090  }
5091
5092  m_ilpRestrictedRefLayersFlag = false;
5093
5094  m_tileBoundariesAlignedFlag             .resize( maxNumLayers );
5095  m_minSpatialSegmentOffsetPlus1          .resize( maxNumLayers );
5096  m_ctuBasedOffsetEnabledFlag             .resize( maxNumLayers );
5097  m_minHorizontalCtuOffsetPlus1           .resize( maxNumLayers );
5098  m_baseLayerParameterSetCompatibilityFlag.resize( maxNumLayers );
5099
5100  for ( Int i = 0; i < maxNumLayers; i++)
5101  {         
5102    m_tileBoundariesAlignedFlag   [i].resize( maxNumLayers );
5103    m_minSpatialSegmentOffsetPlus1[i].resize( maxNumLayers );
5104    m_ctuBasedOffsetEnabledFlag   [i].resize( maxNumLayers );
5105    m_minHorizontalCtuOffsetPlus1 [i].resize( maxNumLayers );
5106    for ( Int j = 0; j < maxNumLayers; j++)
5107    {   
5108      m_tileBoundariesAlignedFlag   [i][j] = false;
5109      m_minSpatialSegmentOffsetPlus1[i][j] = 0;
5110      m_ctuBasedOffsetEnabledFlag   [i][j] = false;
5111      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
5112    }
5113    m_baseLayerParameterSetCompatibilityFlag[i] = false;
5114  }
5115  m_vpsVuiBspHrdPresentFlag = false; 
5116}
5117
5118Void TComRepFormat::inferChromaAndBitDepth( const TComRepFormat* prevRepFormat )
5119{
5120    setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
5121    setSeparateColourPlaneVpsFlag     ( prevRepFormat->getSeparateColourPlaneVpsFlag     () );
5122    setBitDepthVpsLumaMinus8          ( prevRepFormat->getBitDepthVpsLumaMinus8          () );
5123    setBitDepthVpsChromaMinus8        ( prevRepFormat->getBitDepthVpsChromaMinus8        () );
5124}
5125
5126Void TComRepFormat::checkInferChromaAndBitDepth( const TComRepFormat* prevRepFormat ) const 
5127{
5128    assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
5129    assert( getSeparateColourPlaneVpsFlag     () == prevRepFormat->getSeparateColourPlaneVpsFlag     () );
5130    assert( getBitDepthVpsLumaMinus8          () == prevRepFormat->getBitDepthVpsLumaMinus8          () );
5131    assert( getBitDepthVpsChromaMinus8        () == prevRepFormat->getBitDepthVpsChromaMinus8        () );
5132}
5133
5134Int TComVpsVuiBspHrdParameters::getBspHrdIdxLen( const TComVPS* vps) const
5135{
5136  return gCeilLog2( vps->getNumHrdParameters() + getVpsNumAddHrdParams() );
5137}
5138
5139Void TComVpsVuiBspHrdParameters::createAfterVpsNumAddHrdParams( const TComVPS* vps )
5140{
5141  m_offsetHrdParamIdx = vps->getNumHrdParameters(); 
5142  m_numHrdParam       = vps->getNumHrdParameters() + getVpsNumAddHrdParams() - m_offsetHrdParamIdx;
5143  m_numOls            = vps->getNumOutputLayerSets(); 
5144
5145  m_cprmsAddPresentFlag .resize( m_numHrdParam );
5146  m_numSubLayerHrdMinus1.resize( m_numHrdParam );
5147  m_hrdParameters       .resize( m_numHrdParam );
5148
5149  m_numSignalledPartitioningSchemes .resize( m_numOls ); 
5150  m_numPartitionsInSchemeMinus1     .resize( m_numOls );
5151  m_numBspSchedulesMinus1           .resize( m_numOls ); 
5152  m_bspHrdIdx                       .resize( m_numOls );
5153  m_bspSchedIdx                     .resize( m_numOls );
5154}
5155
5156Void TComVpsVuiBspHrdParameters::createAfterNumSignalledPartitioningSchemes( const TComVPS* vps, Int h )
5157{
5158  m_numPartitionsInSchemeMinus1 [h].resize( getNumSignalledPartitioningSchemes(h) );
5159  m_layerIncludedInPartitionFlag[h].resize( getNumSignalledPartitioningSchemes(h) );   
5160
5161  m_numBspSchedulesMinus1       [h].resize( getNumSignalledPartitioningSchemes(h) + 1 );
5162  for (Int i = 0; i < getNumSignalledPartitioningSchemes(h) + 1; i++)
5163  {
5164    Int tMax = vps->getMaxSubLayersInLayerSetMinus1( m_vps->olsIdxToLsIdx(h) ) + 1;
5165    m_numBspSchedulesMinus1[h][i].resize( tMax );
5166    m_bspHrdIdx            [h][i].resize( tMax );
5167    m_bspSchedIdx          [h][i].resize( tMax );
5168  }
5169}
5170
5171Void TComVpsVuiBspHrdParameters::createAfterNumPartitionsInSchemeMinus1( const TComVPS* vps, Int h, Int j )
5172{
5173  m_layerIncludedInPartitionFlag[h][j].resize( getNumPartitionsInSchemeMinus1(h,j));
5174  for( Int k = 0; k < getNumPartitionsInSchemeMinus1(h,j); k++ )
5175  {
5176    m_layerIncludedInPartitionFlag[h][j][k].resize( m_vps->getNumLayersInIdList( vps->olsIdxToLsIdx(h)));
5177  }
5178}
5179
5180Void TComVpsVuiBspHrdParameters::createAfterNumBspSchedulesMinus1( const TComVPS* vps, Int h, Int i, Int t )
5181{
5182  m_bspSchedIdx[h][i][t].resize( getNumBspSchedulesMinus1( h, i, t ) + 1 );
5183  m_bspHrdIdx  [h][i][t].resize( getNumBspSchedulesMinus1( h, i, t ) + 1 );
5184  for( Int j = 0; j < getNumBspSchedulesMinus1( h, i, t ) + 1; j++ )
5185  {
5186    m_bspSchedIdx[h][i][t][j].resize( getNumPartitionsInSchemeMinus1( h, i ) );
5187    m_bspHrdIdx  [h][i][t][j].resize( getNumPartitionsInSchemeMinus1( h, i ) );
5188  }
5189}
5190
5191
5192Void TComVUI::inferVideoSignalInfo( const TComVPS* vps, Int layerIdCurr )
5193{
5194  if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() ) 
5195  {
5196    return; 
5197  }
5198
5199  const TComVPSVUI* vpsVui = vps->getVPSVUI(); 
5200  assert( vpsVui != NULL ); 
5201
5202  const TComVideoSignalInfo* videoSignalInfo = vpsVui->getVideoSignalInfo( vpsVui->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); 
5203  assert( videoSignalInfo != NULL );
5204
5205  setVideoFormat            ( videoSignalInfo->getVideoVpsFormat            () ); 
5206  setVideoFullRangeFlag     ( videoSignalInfo->getVideoFullRangeVpsFlag     () );
5207  setColourPrimaries        ( videoSignalInfo->getColourPrimariesVps        () );
5208  setTransferCharacteristics( videoSignalInfo->getTransferCharacteristicsVps() );
5209  setMatrixCoefficients     ( videoSignalInfo->getMatrixCoeffsVps           () );
5210}
5211
5212Void TComDpbSize::init( Int numOutputLayerSets, Int maxNumLayerIds, Int maxNumSubLayers ) 
5213{
5214  m_subLayerFlagInfoPresentFlag.resize( numOutputLayerSets );
5215  m_subLayerDpbInfoPresentFlag .resize( numOutputLayerSets );
5216  m_maxVpsDecPicBufferingMinus1.resize( numOutputLayerSets ); 
5217  m_maxVpsNumReorderPics       .resize( numOutputLayerSets );
5218  m_maxVpsLatencyIncreasePlus1 .resize( numOutputLayerSets );
5219
5220  for (Int i = 0; i < numOutputLayerSets; i++ )
5221  {     
5222    m_subLayerFlagInfoPresentFlag[i]  = false;
5223
5224    m_subLayerDpbInfoPresentFlag [i].resize( maxNumSubLayers );
5225    m_maxVpsDecPicBufferingMinus1[i].resize( maxNumLayerIds ); 
5226    m_maxVpsNumReorderPics       [i].resize( maxNumSubLayers );
5227    m_maxVpsLatencyIncreasePlus1 [i].resize( maxNumSubLayers );   
5228
5229    for (Int j = 0; j < maxNumSubLayers; j++  )
5230    {       
5231      m_subLayerDpbInfoPresentFlag [i][j] = ( j == 0) ;
5232      m_maxVpsNumReorderPics       [i][j] = 0;
5233      m_maxVpsLatencyIncreasePlus1 [i][j] = 0;
5234    }
5235
5236    for (Int k = 0; k < maxNumLayerIds; k++ )
5237    {
5238      m_maxVpsDecPicBufferingMinus1[i][k].resize( maxNumSubLayers );
5239      for (Int j = 0; j < maxNumSubLayers; j++  )
5240      {       
5241        m_maxVpsDecPicBufferingMinus1[i][k][j] = MIN_INT; 
5242      }
5243    }
5244  }
5245}
5246
5247
5248Int TComDpbSize::getVpsMaxLatencyPictures( Int i, Int j ) const
5249{
5250  return getMaxVpsNumReorderPics( i, j ) + getMaxVpsLatencyIncreasePlus1(i, j) - 1; 
5251}
5252
5253Void Window::scaleOffsets( Int scal )
5254{
5255  if (! m_scaledFlag )
5256  {
5257    m_scaledFlag         = true; 
5258    m_winLeftOffset     *= scal; 
5259    m_winRightOffset    *= scal; 
5260    m_winTopOffset      *= scal; 
5261    m_winBottomOffset   *= scal; 
5262  }
5263}
5264
5265Void TComStRefPicSet::inferRps( Int stRpsIdx, TComSPS* sps, Bool encoder )
5266{
5267  if ( getInterRefPicSetPredictionFlag() )
5268  {
5269    // When inter_ref_pic_set_prediction_flag is equal to 1, the variables DeltaPocS0[ stRpsIdx ][ i ], UsedByCurrPicS0[ stRpsIdx ][ i ],
5270    // NumNegativePics[ stRpsIdx ], DeltaPocS1[ stRpsIdx ][ i ], UsedByCurrPicS1[ stRpsIdx ][ i ] and NumPositivePics[ stRpsIdx ] are
5271    // derived as follows:
5272
5273    Int i = 0;
5274    Int refRpsIdx = getRefRpsIdx( stRpsIdx );
5275    TComStRefPicSet* refRps = sps->getStRefPicSet( refRpsIdx ); 
5276
5277    for( Int j = refRps->getNumPositivePicsVar( ) - 1; j >= 0; j-- ) 
5278    {
5279      Int dPoc = refRps->getDeltaPocS1Var( j ) + getDeltaRps();
5280      if( dPoc < 0  &&  getUseDeltaFlag( refRps->getNumNegativePicsVar( ) + j ) ) 
5281      {
5282        setDeltaPocS0Var     ( i, dPoc );
5283        setUsedByCurrPicS0Var( i++ , getUsedByCurrPicFlag( refRps->getNumNegativePicsVar( ) + j ) );
5284      }
5285    }
5286    if( getDeltaRps() < 0  && getUseDeltaFlag( refRps->getNumDeltaPocs() ) )   //   (7 59)
5287    {
5288      setDeltaPocS0Var( i,  getDeltaRps() ); 
5289      setUsedByCurrPicS0Var( i++ , getUsedByCurrPicFlag( refRps->getNumDeltaPocs() ) );
5290    }
5291    for( Int j = 0; j < refRps->getNumNegativePicsVar(); j++ )
5292    {
5293      Int dPoc = refRps->getDeltaPocS0Var( j ) + getDeltaRps(); 
5294      if( dPoc < 0  &&  getUseDeltaFlag( j ) ) 
5295      {
5296        setDeltaPocS0Var( i , dPoc);
5297        setUsedByCurrPicS0Var( i++ , getUsedByCurrPicFlag( j )) ;
5298      }
5299    }
5300
5301    setNumNegativePicsVar( i );
5302
5303    i = 0;
5304    for( Int j = refRps->getNumNegativePicsVar() - 1; j  >=  0; j-- )
5305    {
5306      Int dPoc = refRps->getDeltaPocS0Var( j ) + getDeltaRps(); 
5307      if( dPoc > 0  &&  getUseDeltaFlag( j ) )
5308      {
5309        setDeltaPocS1Var( i, dPoc );
5310        setUsedByCurrPicS1Var(  i++, getUsedByCurrPicFlag( j ) ) ;
5311      }
5312    }
5313
5314    if( getDeltaRps() > 0  &&  getUseDeltaFlag( refRps->getNumDeltaPocs() ) ) //  (7 60)
5315    { 
5316      setDeltaPocS1Var( i , getDeltaRps() );
5317      setUsedByCurrPicS1Var( i++ , getUsedByCurrPicFlag( refRps->getNumDeltaPocs() ));
5318    }
5319
5320    for( Int j = 0; j < refRps->getNumPositivePicsVar( ); j++) 
5321    {
5322      Int dPoc = refRps->getDeltaPocS1Var( j ) + getDeltaRps(); 
5323      if( dPoc > 0  &&  getUseDeltaFlag( refRps->getNumNegativePicsVar() + j ) ) 
5324      {
5325        setDeltaPocS1Var( i, dPoc);
5326        setUsedByCurrPicS1Var( i++, getUsedByCurrPicFlag( refRps->getNumNegativePicsVar() + j ));
5327      }
5328    }
5329    setNumPositivePicsVar(  i );
5330  }
5331  else
5332  {
5333    // When inter_ref_pic_set_prediction_flag is equal to 0, the variables NumNegativePics[ stRpsIdx ], NumPositivePics[ stRpsIdx ],
5334    // UsedByCurrPicS0[ stRpsIdx ][ i ], UsedByCurrPicS1[ stRpsIdx ][ i ], DeltaPocS0[ stRpsIdx ][ i ] and DeltaPocS1[ stRpsIdx ][ i ]
5335    // are derived as follows:
5336
5337    setNumNegativePicsVar( getNumNegativePics( ) );        //  (7 61)
5338    setNumPositivePicsVar( getNumPositivePics( ) );         //  (7 62)
5339
5340    for (Int i = 0 ; i < getNumNegativePics(); i++ )
5341    {     
5342      setUsedByCurrPicS0Var( i,  getUsedByCurrPicS0Flag( i ) ); //  (7 63)
5343      if (i == 0 )
5344      {
5345        setDeltaPocS0Var( i , -( getDeltaPocS0Minus1( i ) + 1 )); // (7 65)
5346      }
5347      else
5348      {
5349        setDeltaPocS0Var( i , getDeltaPocS0Var( i - 1 ) - ( getDeltaPocS0Minus1( i ) + 1 )); //  (7 67)
5350      }
5351    }
5352
5353    for (Int i = 0 ; i < getNumPositivePics(); i++ )
5354    {     
5355      setUsedByCurrPicS1Var( i,  getUsedByCurrPicS1Flag( i ) ); //  (7 64)
5356
5357      if (i == 0 )
5358      {
5359        setDeltaPocS1Var( i , getDeltaPocS1Minus1( i ) + 1    );      // (7 66)
5360      }
5361      else
5362      {
5363        setDeltaPocS1Var( i , getDeltaPocS1Var( i - 1 ) + ( getDeltaPocS1Minus1( i ) + 1 )); //  (7 68)
5364      }
5365    }
5366  }
5367}
5368
5369#endif
Note: See TracBrowser for help on using the repository browser.