source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComSlice.cpp @ 1196

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

Merged 14.0-dev0@1187.

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