source: 3DVCSoftware/branches/HTM-14.1-update-dev2-Qualcomm/source/Lib/TLibCommon/TComSlice.cpp @ 1417

Last change on this file since 1417 was 1214, checked in by qualcomm, 10 years ago

TMVP minor code cleanup: Ying Chen

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