source: 3DVCSoftware/branches/HTM-12.2-dev2-HHI/source/Lib/TLibCommon/TComSlice.cpp @ 1112

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

Fix num views.

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