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

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

Fixed linux compiler warnings.

  • Property svn:eol-style set to native
File size: 154.5 KB
Line 
1/*  The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-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#endif
1881
1882  for( Int i = 0; i < MAX_TLAYER; i++)
1883  {
1884    m_numReorderPics[i] = 0;
1885    m_uiMaxDecPicBuffering[i] = 1; 
1886    m_uiMaxLatencyIncrease[i] = 0;
1887  }
1888#if H_MV
1889  for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ )
1890  { 
1891    for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ )
1892    {
1893      m_layerIdIncludedFlag[lsIdx][layerId] = (( lsIdx == 0 ) && ( layerId == 0 )) ; 
1894    }
1895  } 
1896  m_vpsNumProfileTierLevelMinus1 = -1; 
1897   
1898  m_numAddLayerSets              = 0;   
1899  m_numAddOlss                   = 0; 
1900  m_defaultOutputLayerIdc     = 0; 
1901 
1902  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
1903  {
1904    m_layerSetIdxForOlsMinus1[i]  = -1; 
1905    for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
1906    {
1907      m_profileTierLevelIdx[i][j] = -1; 
1908      m_outputLayerFlag[i][j] = false; 
1909    }
1910    m_altOutputLayerFlag[ i ]       = false; 
1911  }
1912
1913  m_repFormatIdxPresentFlag = false; 
1914  m_maxOneActiveRefLayerFlag = false; 
1915  m_directDepTypeLenMinus2   = 0;         
1916 
1917
1918  m_vpsExtensionFlag = true; 
1919  m_vpsNonVuiExtensionLength = 0;
1920  m_splittingFlag    = false;
1921 
1922  for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
1923  {
1924    m_scalabilityMaskFlag[i] = false;
1925    m_dimensionIdLen [i]  = -1; 
1926  }
1927
1928  m_vpsNuhLayerIdPresentFlag = false;
1929
1930  for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
1931  {
1932    m_vpsProfilePresentFlag   [i] = false;
1933    m_layerSetIdxForOlsMinus1       [i] = 0;
1934    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
1935    {
1936      m_outputLayerFlag[i][j] = false;
1937    }
1938  }
1939
1940  for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
1941  {
1942    m_layerIdInVps[i] =  (i == 0 ) ? 0 : -1;         
1943  }
1944
1945  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1946  {
1947    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
1948    m_numDirectRefLayers[i] = 0; 
1949#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
1950#if H_3D
1951    m_numRefListLayers[i] = 0; 
1952#endif
1953#endif
1954    m_vpsRepFormatIdx    [i] = 0; 
1955    m_pocLsbNotPresentFlag[i] = 0;
1956    m_repFormat          [i] = NULL; 
1957    m_viewIdVal          [i] = 0; 
1958
1959#if H_3D
1960    m_viewIndex         [i] = -1; 
1961#if !HHI_TOOL_PARAMETERS_I2_J0107
1962    m_vpsDepthModesFlag [i] = false;
1963    m_ivMvScalingFlag[i] = true; 
1964    m_bIVPFlag [i]      = false;
1965#endif
1966#endif
1967
1968    for( Int j = 0; j < MAX_NUM_LAYERS; j++ )
1969    {
1970      m_directDependencyFlag[i][j] = false;
1971      m_directDependencyType[i][j] = -1; 
1972      m_dependencyFlag  [i][j]    = false; 
1973      m_idDirectRefLayer[i][j]    = -1; 
1974#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
1975#if H_3D
1976      m_idRefListLayer[i][j]    = -1; 
1977#endif
1978#endif
1979      m_idPredictedLayer[i][j]    = -1; 
1980      m_idRefLayer      [i][j]    = -1; 
1981      m_maxTidIlRefPicsPlus1[i][j]  = 7;
1982    }
1983
1984    for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ )
1985    {
1986      m_dimensionId[i][j] = 0;
1987    }
1988#if H_3D_ARP
1989#if !HHI_TOOL_PARAMETERS_I2_J0107
1990    m_uiUseAdvResPred[i]  = 0;
1991    m_uiARPStepNum[i]     = 1;
1992#endif
1993#endif
1994  }
1995  m_vpsVUI = new TComVPSVUI; 
1996  m_dpbSize = new TComDpbSize; 
1997
1998#if !HHI_TOOL_PARAMETERS_I2_J0107
1999#if H_3D
2000  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2001  {
2002#if H_3D_IV_MERGE
2003    m_ivMvPredFlag         [ i ] = false;
2004#if H_3D_SPIVMP
2005    m_iSubPULog2Size       [ i ] = 0;
2006#endif
2007#endif
2008#if H_3D_QTLPC
2009    m_bLimQtPredFlag       [ i ] = false;
2010#endif
2011#if H_3D_VSP
2012    m_viewSynthesisPredFlag[ i ] = false;
2013#endif
2014#if H_3D_NBDV_REF
2015    m_depthRefinementFlag  [ i ] = false;
2016#endif
2017#if H_3D_INTER_SDC
2018    m_bInterSDCFlag        [ i ] = false;
2019#endif
2020#if H_3D
2021    m_bIVPFlag             [ i ] = false;
2022#endif
2023#if H_3D_DBBP
2024    m_dbbpFlag             [ i ] = false;
2025#endif
2026#if H_3D_IV_MERGE
2027    m_bMPIFlag             [ i ] = false;
2028#endif
2029  } 
2030#endif
2031#endif
2032
2033#endif
2034}
2035
2036TComVPS::~TComVPS()
2037{
2038  if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
2039  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
2040  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
2041#if H_MV
2042  if ( m_vpsVUI          != NULL )     delete m_vpsVUI; 
2043  if ( m_dpbSize         != NULL )     delete m_dpbSize; 
2044
2045  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2046  {
2047    if (m_repFormat[ i ] != NULL )      delete m_repFormat[ i ];   
2048  }
2049#endif
2050#if H_3D
2051  deleteCamPars();
2052#endif
2053}
2054
2055#if H_MV
2056
2057Bool TComVPS::checkVPSExtensionSyntax()
2058{
2059  for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
2060  {
2061    // check layer_id_in_nuh constraint
2062    assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
2063  }
2064
2065  //The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
2066  assert( getVpsNumRepFormatsMinus1() >= 0 ); 
2067  assert( getVpsNumRepFormatsMinus1() <= 255 ); 
2068
2069  // The value of num_add_layer_sets shall be in the range of 0 to 1023, inclusive.
2070  assert( getNumAddLayerSets() >= 0 && getNumAddLayerSets() <= 1023 ); 
2071  return true; 
2072}
2073
2074Int TComVPS::getNumScalabilityTypes()
2075{
2076  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
2077}
2078
2079Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
2080{
2081  assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
2082  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
2083  Int scalIdx = 0; 
2084  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
2085  {
2086    scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
2087
2088  }
2089
2090  return scalIdx; 
2091}
2092Void TComVPS::setScalabilityMaskFlag( UInt val )
2093{
2094  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
2095  {
2096    setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 );
2097  }
2098}
2099
2100Void TComVPS::setRefLayers()
2101{
2102
2103  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
2104  {
2105    for( Int j = 0; j  <=  getMaxLayersMinus1(); j++ )
2106    {
2107      m_dependencyFlag[ i ][ j ] = getDirectDependencyFlag( i , j );
2108      for( Int k = 0; k < i; k++ )
2109      {
2110        if( getDirectDependencyFlag(i , k )  &&  m_dependencyFlag[k][j] )
2111        {
2112          m_dependencyFlag[ i ][ j ] = true;
2113        }
2114      }
2115    }
2116  }
2117
2118  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
2119  {
2120    Int iNuhLId = getLayerIdInNuh( i );
2121    Int d = 0;
2122#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
2123#if H_3D
2124    Int l = 0; 
2125#endif
2126#endif
2127    Int r = 0;
2128    Int p = 0;
2129
2130    for( Int j = 0; j  <=  getMaxLayersMinus1(); j++ )
2131    {
2132      Int jNuhLid = getLayerIdInNuh( j );
2133      if( getDirectDependencyFlag( i , j ) )
2134      {
2135        m_idDirectRefLayer[iNuhLId][d++] = jNuhLid;
2136      }
2137#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
2138#if H_3D
2139      if( getDirectDependencyFlag( i , j ) && ( getDepthId( iNuhLId ) == getDepthId( jNuhLid ) ))
2140      {
2141        m_idRefListLayer [iNuhLId][l++] = jNuhLid;
2142      }
2143#endif
2144#endif
2145
2146      if( getDependencyFlag( i , j ) )
2147      {
2148        m_idRefLayer      [iNuhLId][r++] = jNuhLid;
2149      }
2150      if( getDependencyFlag( j , i ) )
2151      {
2152        m_idPredictedLayer[iNuhLId][p++] = jNuhLid;
2153      }
2154    }
2155    m_numDirectRefLayers[ iNuhLId ] = d;
2156#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
2157#if H_3D
2158    m_numRefListLayers[ iNuhLId ] = l; 
2159#endif
2160#endif
2161
2162    m_numRefLayers      [ iNuhLId ] = r;
2163    m_numPredictedLayers[ iNuhLId ] = p;
2164  }
2165 
2166  Bool layerIdInListFlag[ 64 ]; 
2167  for( Int i = 0; i  <=  63; i++ )
2168  {
2169    layerIdInListFlag[ i ] = 0;
2170  }
2171
2172  Int k = 0; 
2173  for( Int i = 0; i  <=  getMaxLayersMinus1(); i++ )
2174  {
2175    Int iNuhLId = getLayerIdInNuh( i );
2176    if( getNumDirectRefLayers( iNuhLId )  ==  0 )
2177    {
2178      m_treePartitionLayerIdList[ k ][ 0 ] = iNuhLId;
2179      Int h = 1; 
2180      for( Int j = 0; j < getNumPredictedLayers( iNuhLId ); j++ ) 
2181      {
2182        Int predLId = getIdPredictedLayer( iNuhLId, j );
2183        if ( !layerIdInListFlag[ predLId ] )
2184        {
2185          m_treePartitionLayerIdList[ k ][ h++ ] = predLId;
2186          layerIdInListFlag[ predLId ] = 1; 
2187        }         
2188      }
2189      m_numLayersInTreePartition[ k++ ] = h;
2190    }
2191  }
2192  m_numIndependentLayers = k;
2193}
2194
2195
2196Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
2197{
2198  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
2199}
2200
2201#if H_3D
2202Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
2203{
2204  Int foundLayerIdinNuh = -1; 
2205
2206  for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ )
2207  {
2208    Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); 
2209    if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) )  )
2210    {
2211      foundLayerIdinNuh = layerIdInNuh; 
2212      break; 
2213    }
2214  }
2215#if !BUG_FIX_TK65
2216  assert( foundLayerIdinNuh != -1 ); 
2217#endif
2218  return foundLayerIdinNuh;
2219}
2220
2221Void TComVPS::createCamPars(Int iNumViews)
2222{
2223  Int i = 0, j = 0;
2224
2225  m_bCamParPresent = new Bool[ iNumViews ];
2226  m_bCamParInSliceHeader = new Bool[ iNumViews ];
2227
2228  m_aaaiCodedScale = new Int**[ iNumViews ];
2229  m_aaaiCodedOffset = new Int**[ iNumViews ];
2230  for ( i = 0; i < iNumViews ; i++ )
2231  {
2232    m_bCamParPresent[i] = false; 
2233    m_bCamParInSliceHeader[i] = false; 
2234    m_aaaiCodedScale[i] = new Int*[ 2 ];
2235    m_aaaiCodedOffset[i] = new Int*[ 2 ];
2236    for ( j = 0; j < 2; j++ )
2237    {
2238      m_aaaiCodedScale[i][j] = new Int[ MAX_NUM_LAYERS ];
2239      m_aaaiCodedOffset[i][j] = new Int[ MAX_NUM_LAYERS ];
2240      for ( Int k = 0; k < MAX_NUM_LAYERS; k++ )
2241      {
2242        m_aaaiCodedScale[i][j][k] = 0;
2243        m_aaaiCodedOffset[i][j][k] = 0;
2244      }
2245    }
2246  }
2247}
2248
2249Void TComVPS::deleteCamPars()
2250{
2251  Int iNumViews = getNumViews();
2252  Int i = 0, j = 0;
2253
2254  if ( m_bCamParPresent != NULL )
2255  {
2256    delete [] m_bCamParPresent;
2257  }
2258  if ( m_bCamParInSliceHeader != NULL )
2259  {
2260    delete [] m_bCamParInSliceHeader;
2261  }
2262
2263  if ( m_aaaiCodedScale != NULL )
2264  {
2265    for ( i = 0; i < iNumViews ; i++ )
2266    {
2267      for ( j = 0; j < 2; j++ )
2268      {
2269        delete [] m_aaaiCodedScale[i][j];
2270      }
2271      delete [] m_aaaiCodedScale[i];
2272    }
2273    delete [] m_aaaiCodedScale;
2274  }
2275
2276  if ( m_aaaiCodedOffset != NULL )
2277  {
2278    for ( i = 0; i < iNumViews ; i++ )
2279    {
2280      for ( j = 0; j < 2; j++ )
2281      {
2282        delete [] m_aaaiCodedOffset[i][j];
2283      }
2284      delete [] m_aaaiCodedOffset[i];
2285    }
2286    delete [] m_aaaiCodedOffset;
2287  }
2288}
2289
2290
2291Void
2292  TComVPS::initCamParaVPS( UInt uiViewIndex, Bool bCamParPresent, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
2293{
2294  AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); 
2295
2296  m_uiCamParPrecision = ( ( uiViewIndex != 0 )? uiCamParPrecision : 0 );
2297  m_bCamParPresent[ uiViewIndex ] = (( uiViewIndex != 0 )? bCamParPresent  : false );
2298  m_bCamParInSliceHeader[ uiViewIndex ]  = ( (uiViewIndex != 0)? bCamParSlice  : false );
2299
2300  if( !m_bCamParInSliceHeader[ uiViewIndex ] )
2301  {
2302    for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
2303    {
2304      m_aaaiCodedScale [ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][     uiViewIndex ];
2305      m_aaaiCodedScale [ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiScale [     uiViewIndex ][ uiBaseViewIndex ];
2306      m_aaaiCodedOffset[ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][     uiViewIndex ];
2307      m_aaaiCodedOffset[ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiOffset[     uiViewIndex ][ uiBaseViewIndex ];
2308    }
2309  }
2310}
2311
2312#endif // H_3D
2313
2314
2315Int TComVPS::xGetDimBitOffset( Int j )
2316{
2317  Int dimBitOffset = 0; 
2318  if ( getSplittingFlag() && j == getNumScalabilityTypes() )
2319  {
2320     dimBitOffset = 6; 
2321  }
2322  else
2323  {
2324    for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++)
2325    {
2326      dimBitOffset += getDimensionIdLen( dimIdx ); 
2327    }
2328  }
2329  return dimBitOffset; 
2330}
2331
2332Int TComVPS::inferDimensionId( Int i, Int j )
2333{
2334    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); 
2335}
2336
2337Int TComVPS::inferLastDimsionIdLenMinus1()
2338{
2339  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); 
2340}
2341
2342Int TComVPS::getNumLayersInIdList( Int lsIdx )
2343{
2344  assert( lsIdx >= 0 ); 
2345  assert( lsIdx <= getNumLayerSets() ); 
2346  return (Int) m_layerSetLayerIdList[ lsIdx ].size(); 
2347}
2348
2349Int    TComVPS::getNumOutputLayerSets() 
2350{
2351  return getNumAddOlss() + getNumLayerSets(); 
2352}
2353
2354Int TComVPS::getNumViews()
2355{
2356  Int numViews = 1; 
2357  for( Int i = 0; i <=  getMaxLayersMinus1(); i++ )
2358  {
2359    Int lId = getLayerIdInNuh( i ); 
2360    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
2361    {
2362      numViews++; 
2363    }   
2364  }
2365
2366  return numViews;
2367}
2368
2369
2370Void TComVPS::deriveLayerSetLayerIdList()
2371{
2372  m_layerSetLayerIdList.resize( getVpsNumLayerSetsMinus1() + 1 ); 
2373  for (Int i = 0; i <= getVpsNumLayerSetsMinus1(); i++ )
2374  {
2375    for( Int m = 0; m  <= getVpsMaxLayerId(); m++ )
2376    {
2377      if( getLayerIdIncludedFlag( i, m) ) 
2378      {
2379        m_layerSetLayerIdList[ i ].push_back( m );       
2380      }
2381    }
2382  }
2383}
2384
2385Void TComVPS::initTargetLayerIdLists()
2386{
2387  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); 
2388  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); 
2389}
2390
2391Void TComVPS::deriveTargetLayerIdList( Int i )
2392{ 
2393  Int lsIdx = olsIdxToLsIdx( i );     
2394
2395  for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
2396  {
2397    if ( getNecessaryLayerFlag( i , j ))
2398    {
2399      m_targetDecLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); 
2400    }
2401
2402    if( getOutputLayerFlag( i, j  ))
2403    {
2404      m_targetOptLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
2405    }
2406  } 
2407  assert( getNumOutputLayersInOutputLayerSet( i ) > 0 ); 
2408}
2409
2410Bool TComVPS::inferOutputLayerFlag( Int i, Int j )
2411{
2412  Bool outputLayerFlag; 
2413  switch ( getDefaultOutputLayerIdc( ) )
2414  {
2415  case 0:
2416    outputLayerFlag = true; 
2417    break; 
2418  case 1:
2419    outputLayerFlag = ( j == m_layerSetLayerIdList[ olsIdxToLsIdx( i ) ].size() - 1 ); 
2420    break;
2421  case 2:
2422    if ( i == 0 && j == 0)
2423    {     
2424      outputLayerFlag = true;  // This is a software only fix for a bug in the spec. In spec outputLayerFlag is neither present nor inferred.
2425    }
2426    else
2427    {
2428      assert( 0 ); 
2429    }
2430    break; 
2431  default:     
2432    assert( 0 );
2433    break; 
2434  }
2435  return outputLayerFlag;
2436}
2437
2438Int TComVPS::getMaxSubLayersInLayerSetMinus1( Int i )
2439{
2440  Int maxSLMinus1 = 0; 
2441  for( Int k = 0; k < getNumLayersInIdList( i ); k++ )
2442  {
2443    Int lId = m_layerSetLayerIdList[i][k];
2444    maxSLMinus1 = std::max( maxSLMinus1, getSubLayersVpsMaxMinus1( getLayerIdInVps( lId ) ));
2445  }
2446  return maxSLMinus1;
2447}
2448
2449Bool TComVPS::getAltOutputLayerFlagVar( Int i )
2450{
2451  // Semantics variable not syntax element !
2452
2453  Bool altOptLayerFlag = false;     
2454  if ( i > 0 && getNumOutputLayersInOutputLayerSet( i ) == 1 && 
2455    getNumDirectRefLayers( getOlsHighestOutputLayerId( i ) ) > 0 )
2456  {
2457    altOptLayerFlag = getAltOutputLayerFlag( i ); 
2458  }
2459  return altOptLayerFlag;
2460}
2461
2462
2463
2464Int TComVPS::inferProfileTierLevelIdx(Int i, Int j)
2465{
2466  Bool inferZero        = ( i == 0 && j == 0 &&  getVpsBaseLayerInternalFlag() );
2467  Bool inferGreaterZero = getNecessaryLayerFlag(i,j) && ( getVpsNumProfileTierLevelMinus1() == 0 ); 
2468  assert( inferZero || inferGreaterZero );
2469
2470  Bool ptlIdx = 0; // inference for greaterZero
2471  if ( inferZero )
2472  {
2473    ptlIdx = getMaxLayersMinus1() > 0 ? 1 : 0; 
2474    if ( inferGreaterZero )
2475    {
2476      assert( ptlIdx == 0 ); 
2477      // This should never happen since :
2478      // 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.
2479    }
2480  }
2481  return ptlIdx;
2482}
2483
2484Void TComVPS::deriveAddLayerSetLayerIdList(Int i)
2485{
2486  assert( m_layerSetLayerIdList.size() ==  ( getVpsNumLayerSetsMinus1() + 1 + i ) ); 
2487  std::vector<Int> layerSetLayerIdList;
2488
2489  for( Int treeIdx = 1; treeIdx < getNumIndependentLayers(); treeIdx++ )
2490  { 
2491    // The value of highest_layer_idx_plus1[ i ][ j ] shall be in the range of 0 to NumLayersInTreePartition[ j ], inclusive.
2492    assert( getHighestLayerIdxPlus1( i, treeIdx ) >= 0 && getHighestLayerIdxPlus1( i, treeIdx ) <= getNumLayersInTreePartition( treeIdx ) );
2493
2494    for( Int layerCnt = 0; layerCnt < getHighestLayerIdxPlus1( i, treeIdx ); layerCnt++ )
2495    {
2496      layerSetLayerIdList.push_back( getTreePartitionLayerIdList( treeIdx, layerCnt ) );
2497    }
2498  }
2499  m_layerSetLayerIdList.push_back( layerSetLayerIdList ); 
2500
2501  //It is a requirement of bitstream conformance that
2502  //NumLayersInIdList[ vps_num_layer_sets_minus1 + 1 + i ] shall be greater than 0.
2503  assert( getNumLayersInIdList( getVpsNumLayerSetsMinus1() + 1 + i ) > 0 );
2504}
2505
2506
2507Void TComVPS::deriveNecessaryLayerFlags(Int olsIdx)
2508{
2509  AOF( olsIdx >= 0 && olsIdx < getNumOutputLayerSets() ); 
2510  Int lsIdx = olsIdxToLsIdx( olsIdx );
2511  for( Int lsLayerIdx = 0; lsLayerIdx < getNumLayersInIdList( lsIdx) ; lsLayerIdx++ )
2512  {
2513    m_necessaryLayerFlag[ olsIdx ][ lsLayerIdx ] = 0;
2514  }
2515  for( Int lsLayerIdx = 0; lsLayerIdx < getNumLayersInIdList( lsIdx ); lsLayerIdx++ )
2516  {
2517    if( getOutputLayerFlag( olsIdx, lsLayerIdx  ))
2518    {
2519      m_necessaryLayerFlag[ olsIdx ][ lsLayerIdx ] = 1;
2520      Int currLayerId = getLayerSetLayerIdList( lsIdx, lsLayerIdx );
2521      for( Int rLsLayerIdx = 0; rLsLayerIdx < lsLayerIdx; rLsLayerIdx++ )
2522      {
2523        Int refLayerId = getLayerSetLayerIdList( lsIdx, rLsLayerIdx );
2524        if( getDependencyFlag( getLayerIdInVps( currLayerId ), getLayerIdInVps( refLayerId ) ) )
2525        {
2526          m_necessaryLayerFlag[ olsIdx ][ rLsLayerIdx ] = 1;
2527        }
2528      }
2529    }
2530  }
2531  m_numNecessaryLayers[ olsIdx ] = 0;
2532  for( Int lsLayerIdx = 0; lsLayerIdx < getNumLayersInIdList( lsIdx ); lsLayerIdx++ ) 
2533  {
2534    m_numNecessaryLayers[ olsIdx ]  +=  m_necessaryLayerFlag[ olsIdx ][ lsLayerIdx ];
2535  }
2536}
2537
2538Void TComVPS::printPTL()
2539{
2540  std::vector<Int> idx; 
2541  std::vector<Int> num; 
2542  std::vector< std::vector<Int> > ptlInfo; 
2543
2544  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "PTLI" << std::endl; 
2545
2546  for ( Int i = 0; i <= getVpsNumProfileTierLevelMinus1(); i++ )
2547  {
2548    std::vector<Int> curPtlInfo;
2549    ProfileTierLevel* ptl = getPTL( i )->getGeneralPTL(); 
2550    curPtlInfo.push_back( (Int) ptl->getProfileIdc()  );
2551    curPtlInfo.push_back( (Int) ptl->getTierFlag()    );
2552    curPtlInfo.push_back( (Int) ptl->getLevelIdc()    );
2553    curPtlInfo.push_back( (Int) ptl->getInbldFlag()   );
2554
2555    idx.push_back ( i );
2556    num.push_back ( 4 ); 
2557    ptlInfo.push_back( curPtlInfo );
2558  } 
2559
2560  xPrintArray( "VpsProfileTierLevel", getVpsNumProfileTierLevelMinus1() + 1, idx, num, ptlInfo, false  ); 
2561
2562  num.clear(); 
2563  idx.clear(); 
2564  for (Int i = 0; i < getNumOutputLayerSets(); i++)
2565  {
2566    num.push_back ( getNumLayersInIdList( olsIdxToLsIdx( i ))  ); 
2567    idx.push_back( i ); 
2568  }
2569
2570  xPrintArray( "profile_tier_level_idx", getNumOutputLayerSets(), idx, num, m_profileTierLevelIdx, true );
2571  std::cout << std::endl;
2572}
2573
2574Void TComVPS::printLayerDependencies()
2575{
2576  vector<Int> fullArray;
2577  vector<Int> range; 
2578
2579#if H_3D
2580  vector<Int> depthId; 
2581#endif
2582
2583  vector<Int> viewOrderIndex;
2584  vector<Int> auxId;
2585  vector<Int> dependencyId; 
2586  vector<Int> viewId; 
2587  for (Int i = 0; i <= getMaxLayersMinus1(); i++ )
2588  {
2589    fullArray.push_back( getMaxLayersMinus1() + 1 ); 
2590    range.push_back( i ); 
2591    viewOrderIndex.push_back( getViewIndex   ( i ) );
2592    dependencyId  .push_back( getDependencyId( i ) );
2593    auxId         .push_back( getAuxId       ( i ) );     
2594    viewId        .push_back( getViewId      ( getLayerIdInNuh( i ) ) );
2595#if H_3D 
2596    depthId.push_back( getDepthId( i ) );
2597#endif
2598  }
2599  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "Layer Dependencies" << std::endl; 
2600  xPrintArray( "direct_dependency_flag", getMaxLayersMinus1()+1, range, fullArray, m_directDependencyFlag, false ); 
2601  xPrintArray( "DependencyFlag", getMaxLayersMinus1()+1, range, fullArray, m_dependencyFlag, false ); 
2602  xPrintArray( "layer_id_in_nuh", getMaxLayersMinus1()+1, m_layerIdInNuh, true  );     
2603  xPrintArray( "IdPredictedLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numPredictedLayers, m_idPredictedLayer, true );
2604  xPrintArray( "IdRefLayer"      , getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numRefLayers, m_idRefLayer, true );
2605  xPrintArray( "IdDirectRefLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numDirectRefLayers, m_idDirectRefLayer, true );
2606#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
2607#if H_3D
2608  xPrintArray( "IdRefListLayer", getMaxLayersMinus1() + 1, m_layerIdInNuh, m_numRefListLayers, m_idRefListLayer, true );
2609#endif
2610#endif
2611
2612  std::cout << std::endl;
2613}
2614
2615Void TComVPS::printScalabilityId()
2616{
2617  vector<Int> layerIdxInVps; 
2618
2619#if H_3D
2620  vector<Int> depthId; 
2621#endif
2622
2623  vector<Int> viewOrderIndex;
2624  vector<Int> auxId;
2625  vector<Int> dependencyId; 
2626  vector<Int> viewId; 
2627
2628  for (Int i = 0; i <= getMaxLayersMinus1(); i++ )
2629  {
2630    Int layerIdInNuh = getLayerIdInNuh( i );
2631    layerIdxInVps  .push_back( i ); 
2632    viewOrderIndex.push_back( getViewIndex   ( layerIdInNuh ) );
2633    dependencyId  .push_back( getDependencyId( layerIdInNuh ) );
2634    auxId         .push_back( getAuxId       ( layerIdInNuh ) );     
2635    viewId        .push_back( getViewId      ( layerIdInNuh ) );
2636#if H_3D 
2637    depthId       .push_back( getDepthId     ( layerIdInNuh ) );
2638#endif
2639  }
2640
2641  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "Scalability Ids" << std::endl; 
2642  xPrintArray( "layerIdxInVps"  , getMaxLayersMinus1()+1, layerIdxInVps,          false );
2643  xPrintArray( "layer_id_in_nuh", getMaxLayersMinus1()+1, m_layerIdInNuh, false );     
2644
2645  xPrintArray( "ViewOrderIndex", getMaxLayersMinus1()+1, viewOrderIndex, false );     
2646  xPrintArray( "DependencyId"  , getMaxLayersMinus1()+1, dependencyId  , false );     
2647  xPrintArray( "AuxId"         , getMaxLayersMinus1()+1, auxId         , false );     
2648  xPrintArray( "ViewId"        , getMaxLayersMinus1()+1, viewId        , false );     
2649
2650  std::cout << std::endl;
2651}
2652
2653Void TComVPS::printLayerSets()
2654{
2655  vector<Int> fullArray;
2656  vector<Int> numLayersInIdList; 
2657  vector<Int> rangeLayerSets; 
2658
2659
2660  for (Int i = 0; i < getNumLayerSets(); i++ )
2661  {
2662    numLayersInIdList.push_back( getNumLayersInIdList( i ) );       
2663    rangeLayerSets.push_back( i ); 
2664  }
2665
2666  vector<Int> rangeOutputLayerSets; 
2667  vector<Int> numOutputLayersInOutputLayerSet; 
2668  vector<Int> numDecLayer; 
2669  vector<Int> numLayersInLayerSetForOutputLayerSet; 
2670  vector<Int> vOlsIdxToLsIdx;
2671  for (Int i = 0; i < getNumOutputLayerSets(); i++ )
2672  {
2673    vOlsIdxToLsIdx.push_back( olsIdxToLsIdx(i));
2674    numOutputLayersInOutputLayerSet.push_back( getNumOutputLayersInOutputLayerSet( i ) );       
2675    numDecLayer.push_back( (Int) m_targetDecLayerIdLists[ i ].size() );
2676    rangeOutputLayerSets.push_back( i ); 
2677    numLayersInLayerSetForOutputLayerSet.push_back( getNumLayersInIdList( olsIdxToLsIdx( i ) ) );
2678  }
2679
2680  vector<Int> rangeIndependentLayers;
2681  for(Int i = 0; i < getNumIndependentLayers(); i++ )
2682  {
2683    rangeIndependentLayers.push_back( i );   
2684  }
2685
2686  vector<Int> rangeAddLayerSets;
2687  vector<Int> numHighestLayerIdxPlus1; 
2688  for(Int i = 0; i < getNumAddLayerSets(); i++ )
2689  {
2690    rangeAddLayerSets.push_back( i );   
2691    numHighestLayerIdxPlus1.push_back( getNumIndependentLayers() );
2692  }
2693
2694  std::cout << std::right << std::setw(60) << std::setfill('-') << " " << std::setfill(' ') << std::endl << "Layer Sets" << std::endl;     
2695  xPrintArray( "TreePartitionLayerIdList", getNumIndependentLayers(), rangeIndependentLayers, m_numLayersInTreePartition, m_treePartitionLayerIdList, true );
2696  xPrintArray( "highest_layer_idx_plus1", getNumAddLayerSets(), rangeAddLayerSets, numHighestLayerIdxPlus1, m_highestLayerIdxPlus1, true ); 
2697  xPrintArray( "LayerSetLayerIdList" , (Int) getNumLayerSets()      , rangeLayerSets      , numLayersInIdList, m_layerSetLayerIdList, true );
2698  xPrintArray( "OlsIdxToLsIdx", (Int) vOlsIdxToLsIdx.size(), vOlsIdxToLsIdx, true ); 
2699  xPrintArray( "OutputLayerFlag"     , getNumOutputLayerSets(), rangeOutputLayerSets, numLayersInLayerSetForOutputLayerSet, m_outputLayerFlag, true );
2700  xPrintArray( "TargetOptLayerIdList", getNumOutputLayerSets(), rangeOutputLayerSets, numOutputLayersInOutputLayerSet, m_targetOptLayerIdLists, true );
2701  xPrintArray( "NecessaryLayerFlag"  , getNumOutputLayerSets(), rangeOutputLayerSets, numLayersInLayerSetForOutputLayerSet, m_necessaryLayerFlag   , true );
2702  xPrintArray( "TargetDecLayerIdList", getNumOutputLayerSets(), rangeOutputLayerSets, numDecLayer,                     m_targetDecLayerIdLists, true );
2703  std::cout << endl;
2704}
2705
2706
2707#endif // H_MV
2708
2709// ------------------------------------------------------------------------------------------------
2710// Sequence parameter set (SPS)
2711// ------------------------------------------------------------------------------------------------
2712
2713TComSPS::TComSPS()
2714: m_SPSId                     (  0)
2715, m_VPSId                     (  0)
2716, m_chromaFormatIdc           (CHROMA_420)
2717, m_uiMaxTLayers              (  1)
2718// Structure
2719, m_picWidthInLumaSamples     (352)
2720, m_picHeightInLumaSamples    (288)
2721, m_log2MinCodingBlockSize    (  0)
2722, m_log2DiffMaxMinCodingBlockSize (0)
2723, m_uiMaxCUWidth              ( 32)
2724, m_uiMaxCUHeight             ( 32)
2725, m_uiMaxCUDepth              (  3)
2726, m_bLongTermRefsPresent      (false)
2727, m_uiQuadtreeTULog2MaxSize   (  0)
2728, m_uiQuadtreeTULog2MinSize   (  0)
2729, m_uiQuadtreeTUMaxDepthInter (  0)
2730, m_uiQuadtreeTUMaxDepthIntra (  0)
2731// Tool list
2732, m_usePCM                   (false)
2733, m_pcmLog2MaxSize            (  5)
2734, m_uiPCMLog2MinSize          (  7)
2735, m_bitDepthY                 (  8)
2736, m_bitDepthC                 (  8)
2737, m_qpBDOffsetY               (  0)
2738, m_qpBDOffsetC               (  0)
2739, m_uiPCMBitDepthLuma         (  8)
2740, m_uiPCMBitDepthChroma       (  8)
2741, m_bPCMFilterDisableFlag     (false)
2742, m_uiBitsForPOC              (  8)
2743, m_numLongTermRefPicSPS    (  0) 
2744, m_uiMaxTrSize               ( 32)
2745, m_bUseSAO                   (false) 
2746, m_bTemporalIdNestingFlag    (false)
2747, m_scalingListEnabledFlag    (false)
2748, m_useStrongIntraSmoothing   (false)
2749, m_vuiParametersPresentFlag  (false)
2750, m_vuiParameters             ()
2751#if H_MV
2752, m_pcVPS                     ( NULL )
2753, m_spsInferScalingListFlag   ( false )
2754, m_spsScalingListRefLayerId  ( 0 )
2755
2756, m_updateRepFormatFlag       ( false ) 
2757, m_spsRepFormatIdx           ( 0 )
2758, m_interViewMvVertConstraintFlag (false)
2759#endif
2760#if H_3D
2761, m_bCamParInSliceHeader      (false)
2762#endif
2763{
2764  for ( Int i = 0; i < MAX_TLAYER; i++ )
2765  {
2766    m_uiMaxLatencyIncrease[i] = 0;
2767    m_uiMaxDecPicBuffering[i] = 1;
2768    m_numReorderPics[i]       = 0;
2769  }
2770  m_scalingList = new TComScalingList;
2771  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
2772  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
2773#if H_MV
2774  m_spsRangeExtensionsFlag     = false;
2775  m_spsMultilayerExtensionFlag = false;
2776#if H_3D
2777  m_spsExtension5bits          = 0;
2778  m_sps3dExtensionFlag         = false; 
2779#else
2780  m_spsExtension6bits          = 0;
2781#endif
2782
2783#endif
2784}
2785
2786TComSPS::~TComSPS()
2787{
2788  delete m_scalingList;
2789  m_RPSList.destroy();
2790}
2791
2792Void  TComSPS::createRPSList( Int numRPS )
2793{ 
2794  m_RPSList.destroy();
2795  m_RPSList.create(numRPS);
2796}
2797
2798Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
2799{
2800  if( !getVuiParametersPresentFlag() )
2801  {
2802    return;
2803  }
2804
2805  TComVUI *vui = getVuiParameters();
2806  TComHRD *hrd = vui->getHrdParameters();
2807
2808  TimingInfo *timingInfo = vui->getTimingInfo();
2809  timingInfo->setTimingInfoPresentFlag( true );
2810  switch( frameRate )
2811  {
2812  case 24:
2813    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
2814    break;
2815  case 25:
2816    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
2817    break;
2818  case 30:
2819    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
2820    break;
2821  case 50:
2822    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
2823    break;
2824  case 60:
2825    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
2826    break;
2827  default:
2828    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
2829    break;
2830  }
2831
2832  Bool rateCnt = ( bitRate > 0 );
2833  hrd->setNalHrdParametersPresentFlag( rateCnt );
2834  hrd->setVclHrdParametersPresentFlag( rateCnt );
2835
2836  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
2837
2838  if( hrd->getSubPicCpbParamsPresentFlag() )
2839  {
2840    hrd->setTickDivisorMinus2( 100 - 2 );                          //
2841    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
2842    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
2843    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
2844  }
2845  else
2846  {
2847    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
2848  }
2849
2850  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
2851  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2852  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2853 
2854  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
2855  if( randomAccess )
2856  {
2857    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
2858    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
2859  }
2860  else
2861  {
2862    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
2863    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
2864  }
2865
2866/*
2867   Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
2868*/
2869  Int i, j;
2870  UInt birateValue, cpbSizeValue;
2871  UInt ducpbSizeValue;
2872  UInt duBitRateValue = 0;
2873
2874  for( i = 0; i < MAX_TLAYER; i ++ )
2875  {
2876    hrd->setFixedPicRateFlag( i, 1 );
2877    hrd->setPicDurationInTcMinus1( i, 0 );
2878    hrd->setLowDelayHrdFlag( i, 0 );
2879    hrd->setCpbCntMinus1( i, 0 );
2880
2881    birateValue  = bitRate;
2882    cpbSizeValue = bitRate;                                     // 1 second
2883    ducpbSizeValue = bitRate/numDU;
2884    duBitRateValue = bitRate;
2885    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
2886    {
2887      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
2888      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
2889      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
2890      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
2891
2892      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
2893      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
2894      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
2895      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
2896      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
2897    }
2898  }
2899}
2900const Int TComSPS::m_winUnitX[]={1,2,2,1};
2901const Int TComSPS::m_winUnitY[]={1,2,1,1};
2902
2903TComPPS::TComPPS()
2904: m_PPSId                       (0)
2905, m_SPSId                       (0)
2906, m_picInitQPMinus26            (0)
2907, m_useDQP                      (false)
2908, m_bConstrainedIntraPred       (false)
2909, m_bSliceChromaQpFlag          (false)
2910, m_pcSPS                       (NULL)
2911, m_uiMaxCuDQPDepth             (0)
2912, m_uiMinCuDQPSize              (0)
2913, m_chromaCbQpOffset            (0)
2914, m_chromaCrQpOffset            (0)
2915, m_numRefIdxL0DefaultActive    (1)
2916, m_numRefIdxL1DefaultActive    (1)
2917, m_TransquantBypassEnableFlag  (false)
2918, m_useTransformSkip             (false)
2919, m_dependentSliceSegmentsEnabledFlag    (false)
2920, m_tilesEnabledFlag               (false)
2921, m_entropyCodingSyncEnabledFlag   (false)
2922, m_loopFilterAcrossTilesEnabledFlag  (true)
2923, m_uniformSpacingFlag           (false)
2924, m_numTileColumnsMinus1         (0)
2925, m_numTileRowsMinus1            (0)
2926, m_numSubstreams               (1)
2927, m_signHideFlag(0)
2928, m_cabacInitPresentFlag        (false)
2929, m_encCABACTableIdx            (I_SLICE)
2930, m_sliceHeaderExtensionPresentFlag    (false)
2931, m_loopFilterAcrossSlicesEnabledFlag (false)
2932, m_listsModificationPresentFlag(  0)
2933, m_numExtraSliceHeaderBits(0)
2934#if H_MV
2935, m_ppsInferScalingListFlag(false)
2936, m_ppsScalingListRefLayerId(0)
2937, m_pocResetInfoPresentFlag(false)
2938#if H_3D
2939, m_pcDLT(NULL)
2940#endif
2941#endif
2942{
2943  m_scalingList = new TComScalingList;
2944
2945#if H_MV
2946  m_ppsRangeExtensionsFlag     = false;
2947  m_ppsMultilayerExtensionFlag = false;
2948#if !H_3D
2949  m_ppsExtension6bits          = 0;
2950#else
2951  m_pps3dExtensionFlag         = false;
2952  m_ppsExtension5bits          = 0;
2953#endif
2954#endif
2955}
2956
2957TComPPS::~TComPPS()
2958{
2959  delete m_scalingList;
2960}
2961
2962#if H_3D
2963TComDLT::TComDLT()
2964: m_bDltPresentFlag(false)
2965, m_iNumDepthViews(0)
2966, m_uiDepthViewBitDepth(8)
2967{
2968  m_uiDepthViewBitDepth = g_bitDepthY; 
2969
2970  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2971  {
2972    m_bUseDLTFlag                 [i] = false;
2973    m_bInterViewDltPredEnableFlag [i] = false;
2974
2975    // allocate some memory and initialize with default mapping
2976    m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1;
2977    m_iDepthValue2Idx[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
2978    m_iIdx2DepthValue[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
2979
2980    //default mapping
2981    for (Int d=0; d<m_iNumDepthmapValues[i]; d++)
2982    {
2983      m_iDepthValue2Idx[i][d] = d;
2984      m_iIdx2DepthValue[i][d] = d;
2985    }
2986  }
2987}
2988
2989TComDLT::~TComDLT()
2990{
2991  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2992  {
2993    if ( m_iDepthValue2Idx[i] != NULL ) 
2994    {
2995      xFree( m_iDepthValue2Idx[i] );
2996      m_iDepthValue2Idx[i] = NULL; 
2997    }
2998
2999    if ( m_iIdx2DepthValue[i] != NULL ) 
3000    {
3001      xFree( m_iIdx2DepthValue[i] );
3002      m_iIdx2DepthValue[i] = NULL; 
3003    }
3004  }
3005}
3006
3007Void TComDLT::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues)
3008{
3009  if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only
3010    return;
3011
3012  // copy idx2DepthValue to internal array
3013  memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt));
3014
3015  UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
3016  for(Int p=0; p<=uiMaxDepthValue; p++)
3017  {
3018    Int iIdxDown    = 0;
3019    Int iIdxUp      = iNumDepthValues-1;
3020    Bool bFound     = false;
3021
3022    // iterate over indices to find lower closest depth
3023    Int i = 1;
3024    while(!bFound && i<iNumDepthValues)
3025    {
3026      if( m_iIdx2DepthValue[layerIdInVps][i] > p )
3027      {
3028        iIdxDown  = i-1;
3029        bFound    = true;
3030      }
3031
3032      i++;
3033    }
3034    // iterate over indices to find upper closest depth
3035    i = iNumDepthValues-2;
3036    bFound = false;
3037    while(!bFound && i>=0)
3038    {
3039      if( m_iIdx2DepthValue[layerIdInVps][i] < p )
3040      {
3041        iIdxUp  = i+1;
3042        bFound    = true;
3043      }
3044
3045      i--;
3046    }
3047
3048    // assert monotony
3049    assert(iIdxDown<=iIdxUp);
3050
3051    // assign closer depth value/idx
3052    if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) )
3053    {
3054      m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown;
3055    }
3056    else
3057    {
3058      m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp;
3059    }
3060
3061  }
3062
3063  // update DLT variables
3064  m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues;
3065}
3066
3067Void TComDLT::getDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTOut, UInt *puiDeltaDLTOutNum )
3068{
3069  Bool abBM0[ 256 ];
3070  Bool abBM1[ 256 ];
3071 
3072  memset( abBM0, 0, sizeof( abBM0 ));
3073  memset( abBM1, 0, sizeof( abBM1 ));
3074 
3075  // convert reference DLT to bit string
3076  for( Int i = 0; i < uiDLTInRefNum; i++ )
3077  {
3078    abBM0[ piDLTInRef[ i ] ] = true;
3079  }
3080  // convert internal DLT to bit string
3081  for( Int i = 0; i < m_iNumDepthmapValues[ layerIdInVps ]; i++ )
3082  {
3083    abBM1[ m_iIdx2DepthValue[ layerIdInVps ][ i ] ] = true;
3084  }
3085 
3086  *puiDeltaDLTOutNum = 0;
3087  for( Int i = 0; i < 256; i++ )
3088  {
3089    if( abBM0[ i ] ^ abBM1[ i ] )
3090    {
3091      piDeltaDLTOut[ *puiDeltaDLTOutNum ] = i;
3092      *puiDeltaDLTOutNum = *puiDeltaDLTOutNum + 1;
3093    }
3094  }
3095}
3096
3097Void TComDLT::setDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTIn, UInt uiDeltaDLTInNum )
3098{
3099  Bool abBM0[ 256 ];
3100  Bool abBM1[ 256 ];
3101 
3102  memset( abBM0, 0, sizeof( abBM0 ));
3103  memset( abBM1, 0, sizeof( abBM1 ));
3104 
3105  // convert reference DLT to bit string
3106  for( Int i = 0; i < uiDLTInRefNum; i++ )
3107  {
3108    abBM0[ piDLTInRef[ i ] ] = true;
3109  }
3110  // convert delta DLT to bit string
3111  for( Int i = 0; i < uiDeltaDLTInNum; i++ )
3112  {
3113    abBM1[ piDeltaDLTIn[ i ] ] = true;
3114  }
3115 
3116  Int aiIdx2DepthValue[256];
3117  UInt uiNumDepthValues = 0;
3118  memset( aiIdx2DepthValue, 0, sizeof( aiIdx2DepthValue ));
3119 
3120  for( Int i = 0; i < 256; i++ )
3121  {
3122    if( abBM0[ i ] ^ abBM1[ i ] )
3123    {
3124      aiIdx2DepthValue[ uiNumDepthValues++ ] = i;
3125    }
3126  }
3127 
3128  // update internal tables
3129  setDepthLUTs(layerIdInVps, aiIdx2DepthValue, uiNumDepthValues);
3130}
3131
3132#endif
3133
3134#if H_MV
3135Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
3136{
3137  if ( getMultiLayerExtSpsFlag() )
3138  { 
3139    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
3140    TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx ); 
3141    setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() );         
3142    //// ToDo: add when supported:
3143    // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
3144
3145    setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  ); 
3146    setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); 
3147
3148    setBitDepthY             ( repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
3149    setQpBDOffsetY           ( (Int) (6*( getBitDepthY() - 8 )) );
3150
3151    setBitDepthC             ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
3152    setQpBDOffsetC           ( (Int) (6* ( getBitDepthC() -8 ) ) );
3153    Window &spsConf    = getConformanceWindow();   
3154
3155    // Scaled later
3156    spsConf.setScaledFlag( false ); 
3157    spsConf.setWindowLeftOffset  ( repFormat->getConfWinVpsLeftOffset()    );
3158    spsConf.setWindowRightOffset ( repFormat->getConfWinVpsRightOffset()   );
3159    spsConf.setWindowTopOffset   ( repFormat->getConfWinVpsTopOffset()     );
3160    spsConf.setWindowBottomOffset( repFormat->getConfWinVpsBottomOffset()  );   
3161
3162   if ( getMultiLayerExtSpsFlag() && getUpdateRepFormatFlag() )
3163    {
3164      assert( getChromaFormatIdc()      <=  repFormat->getChromaFormatVpsIdc()         ); 
3165      //// ToDo: add when supported:
3166      // assert( getSeperateColourPlaneFlag() <=  repFormat->getSeparateColourPlaneVpsFlag() ) ;
3167
3168      assert( getPicWidthInLumaSamples()  <= repFormat->getPicWidthVpsInLumaSamples()    ); 
3169      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   ); 
3170
3171      assert( getBitDepthY()              <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
3172      assert( getBitDepthC()              <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
3173    }
3174  }
3175
3176  // Set conformance window
3177  Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ;
3178  getConformanceWindow().scaleOffsets( scal );
3179  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
3180}
3181
3182Void TComSPS::inferScalingList( TComSPS* spsSrc )
3183{
3184  if ( getSpsInferScalingListFlag() ) 
3185  {
3186    assert( spsSrc != NULL ); 
3187    assert( !spsSrc->getSpsInferScalingListFlag() );             
3188    getScalingList()->inferFrom( spsSrc->getScalingList() ); 
3189  }
3190}
3191
3192Void TComSPS::inferSpsMaxDecPicBufferingMinus1( TComVPS* vps, Int targetOptLayerSetIdx, Int currLayerId, Bool encoder )
3193{
3194  const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx )); 
3195
3196  if ( getMultiLayerExtSpsFlag() )
3197  {
3198    Int layerIdx = 0;         
3199    while (layerIdx < (Int) targetDecLayerIdList.size() )
3200    {
3201      if ( targetDecLayerIdList[layerIdx] == currLayerId )
3202      { 
3203        break; 
3204      }
3205      layerIdx++; 
3206    }
3207
3208    assert( layerIdx < (Int) targetDecLayerIdList.size() ); 
3209
3210    for (Int i = 0; i <= getSpsMaxSubLayersMinus1(); i++ ) 
3211    {
3212      Int maxDecPicBufferingMinus1 = vps->getDpbSize()->getMaxVpsDecPicBufferingMinus1( targetOptLayerSetIdx, layerIdx, i ) ; 
3213
3214      // This preliminary fix needs to be checked.
3215      Int maxNumReorderPics       = vps->getDpbSize()->getMaxVpsNumReorderPics( targetOptLayerSetIdx, i ); 
3216      Int maxLatencyIncreasePlus1 = vps->getDpbSize()->getMaxVpsLatencyIncreasePlus1( targetOptLayerSetIdx, i ); 
3217      if ( encoder )     
3218      {
3219        assert( getMaxDecPicBuffering( i ) - 1 == maxDecPicBufferingMinus1 ); 
3220        // This preliminary fix needs to be checked.
3221        assert( getNumReorderPics( i )     == maxNumReorderPics       ); 
3222        assert( getMaxLatencyIncrease( i ) == maxLatencyIncreasePlus1 ); 
3223
3224      }
3225      else
3226      {
3227        // This preliminary fix needs to be checked.
3228        setMaxDecPicBuffering( maxDecPicBufferingMinus1 + 1 , i); 
3229        setNumReorderPics    ( maxNumReorderPics, i );
3230        setMaxLatencyIncrease( maxLatencyIncreasePlus1 - 1 , i); 
3231      }
3232    }   
3233  }
3234}
3235
3236Void TComSPS::checkRpsMaxNumPics( TComVPS* vps, Int currLayerId )
3237{
3238  for (Int i = 0; i < getRPSList()->getNumberOfReferencePictureSets(); i++ )
3239  {
3240    TComReferencePictureSet* rps = getRPSList()->getReferencePictureSet( i ); 
3241    if ( !rps->getInterRPSPrediction() )
3242    {
3243      rps->checkMaxNumPics( vps->getVpsExtensionFlag(), MAX_INT, getLayerId(), getMaxDecPicBuffering( getSpsMaxSubLayersMinus1() ) - 1 );   // INT_MAX to be replaced by DpbSize
3244    }
3245  }
3246}
3247
3248Void TComSPS::inferSpsMaxSubLayersMinus1(Bool atPsActivation, TComVPS* vps)
3249{
3250  assert( getLayerId() != 0 ); 
3251  if ( !atPsActivation   )
3252  {
3253    assert( vps == NULL );
3254    if (getSpsExtOrMaxSubLayersMinus1() != 7)
3255    {
3256      setSpsMaxSubLayersMinus1( getSpsExtOrMaxSubLayersMinus1() );
3257    }
3258  }
3259  else
3260  {
3261    assert( vps != NULL );
3262    if (getSpsExtOrMaxSubLayersMinus1() == 7)
3263    {
3264      setSpsMaxSubLayersMinus1( vps->getMaxSubLayersMinus1() );
3265    }
3266  }
3267}
3268#endif
3269
3270TComReferencePictureSet::TComReferencePictureSet()
3271: m_numberOfPictures (0)
3272, m_numberOfNegativePictures (0)
3273, m_numberOfPositivePictures (0)
3274, m_numberOfLongtermPictures (0)
3275, m_interRPSPrediction (0) 
3276, m_deltaRIdxMinus1 (0)   
3277, m_deltaRPS (0) 
3278, m_numRefIdc (0) 
3279{
3280  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
3281  ::memset( m_POC, 0, sizeof(m_POC) );
3282  ::memset( m_used, 0, sizeof(m_used) );
3283  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
3284}
3285
3286TComReferencePictureSet::~TComReferencePictureSet()
3287{
3288}
3289
3290Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
3291{
3292  m_used[bufferNum] = used;
3293}
3294
3295Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
3296{
3297  m_deltaPOC[bufferNum] = deltaPOC;
3298}
3299
3300Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
3301{
3302  m_numberOfPictures = numberOfPictures;
3303}
3304
3305Int TComReferencePictureSet::getUsed(Int bufferNum)
3306{
3307  return m_used[bufferNum];
3308}
3309
3310Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
3311{
3312  return m_deltaPOC[bufferNum];
3313}
3314
3315Int TComReferencePictureSet::getNumberOfPictures()
3316{
3317  return m_numberOfPictures;
3318}
3319
3320Int TComReferencePictureSet::getPOC(Int bufferNum)
3321{
3322  return m_POC[bufferNum];
3323}
3324
3325Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
3326{
3327  m_POC[bufferNum] = POC;
3328}
3329
3330Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
3331{
3332  return m_bCheckLTMSB[bufferNum];
3333}
3334
3335Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
3336{
3337  m_bCheckLTMSB[bufferNum] = b;
3338}
3339
3340/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
3341 * \param uiBufferNum
3342 * \param iRefIdc
3343 * \returns Void
3344 */
3345Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
3346{
3347  m_refIdc[bufferNum] = refIdc;
3348}
3349
3350/** get the reference idc value at uiBufferNum
3351 * \param uiBufferNum
3352 * \returns Int
3353 */
3354Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
3355{
3356  return m_refIdc[bufferNum];
3357}
3358
3359/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
3360 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
3361 *  +ve values are in increasing order.
3362 * \returns Void
3363 */
3364Void TComReferencePictureSet::sortDeltaPOC()
3365{
3366  // sort in increasing order (smallest first)
3367  for(Int j=1; j < getNumberOfPictures(); j++)
3368  { 
3369    Int deltaPOC = getDeltaPOC(j);
3370    Bool used = getUsed(j);
3371    for (Int k=j-1; k >= 0; k--)
3372    {
3373      Int temp = getDeltaPOC(k);
3374      if (deltaPOC < temp)
3375      {
3376        setDeltaPOC(k+1, temp);
3377        setUsed(k+1, getUsed(k));
3378        setDeltaPOC(k, deltaPOC);
3379        setUsed(k, used);
3380      }
3381    }
3382  }
3383  // flip the negative values to largest first
3384  Int numNegPics = getNumberOfNegativePictures();
3385  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
3386  { 
3387    Int deltaPOC = getDeltaPOC(j);
3388    Bool used = getUsed(j);
3389    setDeltaPOC(j, getDeltaPOC(k));
3390    setUsed(j, getUsed(k));
3391    setDeltaPOC(k, deltaPOC);
3392    setUsed(k, used);
3393  }
3394}
3395
3396/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
3397 *  A "*" is added to the deltaPOC value if it is Used bu current.
3398 * \returns Void
3399 */
3400Void TComReferencePictureSet::printDeltaPOC()
3401{
3402  printf("DeltaPOC = { ");
3403  for(Int j=0; j < getNumberOfPictures(); j++)
3404  {
3405    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
3406  } 
3407  if (getInterRPSPrediction()) 
3408  {
3409    printf("}, RefIdc = { ");
3410    for(Int j=0; j < getNumRefIdc(); j++)
3411    {
3412      printf("%d ", getRefIdc(j));
3413    } 
3414  }
3415  printf("}\n");
3416}
3417#if H_MV
3418Void TComReferencePictureSet::checkMaxNumPics( Bool vpsExtensionFlag, Int maxNumPics, Int nuhLayerId, Int spsMaxDecPicBufferingMinus1 )
3419{
3420  assert( getNumberOfPictures() >= 0 ); 
3421  if ( nuhLayerId == 0 )
3422  {
3423    assert( getNumberOfPictures() <= spsMaxDecPicBufferingMinus1 ); 
3424  }
3425
3426  if ( vpsExtensionFlag )
3427  {
3428    assert( getNumberOfPictures() <= maxNumPics );
3429  }
3430}
3431#endif
3432
3433TComRPSList::TComRPSList()
3434:m_referencePictureSets (NULL)
3435{
3436}
3437
3438TComRPSList::~TComRPSList()
3439{
3440}
3441
3442Void TComRPSList::create( Int numberOfReferencePictureSets)
3443{
3444  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
3445  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
3446}
3447
3448Void TComRPSList::destroy()
3449{
3450  if (m_referencePictureSets)
3451  {
3452    delete [] m_referencePictureSets;
3453  }
3454  m_numberOfReferencePictureSets = 0;
3455  m_referencePictureSets = NULL;
3456}
3457
3458
3459
3460TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
3461{
3462  return &m_referencePictureSets[referencePictureSetNum];
3463}
3464
3465Int TComRPSList::getNumberOfReferencePictureSets()
3466{
3467  return m_numberOfReferencePictureSets;
3468}
3469
3470Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
3471{
3472  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
3473}
3474
3475TComRefPicListModification::TComRefPicListModification()
3476: m_bRefPicListModificationFlagL0 (false)
3477, m_bRefPicListModificationFlagL1 (false)
3478{
3479  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
3480  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
3481}
3482
3483TComRefPicListModification::~TComRefPicListModification()
3484{
3485}
3486
3487TComScalingList::TComScalingList()
3488{
3489  init();
3490}
3491TComScalingList::~TComScalingList()
3492{
3493  destroy();
3494}
3495
3496/** set default quantization matrix to array
3497*/
3498Void TComSlice::setDefaultScalingList()
3499{
3500  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3501  {
3502    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
3503    {
3504      getScalingList()->processDefaultMatrix(sizeId, listId);
3505    }
3506  }
3507}
3508/** check if use default quantization matrix
3509 * \returns true if use default quantization matrix in all size
3510*/
3511Bool TComSlice::checkDefaultScalingList()
3512{
3513  UInt defaultCounter=0;
3514
3515  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3516  {
3517    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
3518    {
3519      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
3520     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
3521      {
3522        defaultCounter++;
3523      }
3524    }
3525  }
3526  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
3527}
3528
3529#if H_MV
3530Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
3531{
3532  refPicSetInterLayer0.clear(); 
3533  refPicSetInterLayer1.clear(); 
3534
3535  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
3536  {
3537    Int layerIdRef = getRefPicLayerId( i ); 
3538    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
3539    assert ( picRef != 0 ); // There shall be no entry equal to "no reference picture" in RefPicSetInterLayer0 or RefPicSetInterLayer1.
3540
3541    picRef->getPicYuvRec()->extendPicBorder(); 
3542    picRef->setIsLongTerm( true );       
3543    picRef->getSlice(0)->setReferenced( true );       
3544
3545    Int viewIdCur  = getVPS()->getViewId( getLayerId() ); 
3546    Int viewIdZero = getVPS()->getViewId( 0 );
3547    Int viewIdRef  = getVPS()->getViewId( layerIdRef ); 
3548
3549    if (  ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) )
3550    {
3551      refPicSetInterLayer0.push_back( picRef ); 
3552    }
3553    else
3554    {
3555      refPicSetInterLayer1.push_back( picRef ); 
3556    }
3557    // Consider to check here:
3558    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "   
3559    assert( picRef->getSlice(0)->getDiscardableFlag() == false ); // "There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1".       
3560  }
3561}
3562
3563Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
3564{
3565  // Mark as short-term
3566  for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
3567  {
3568    refPicSetInterLayer0[i]->setIsLongTerm( false ); 
3569  }
3570
3571  for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) 
3572  {
3573    refPicSetInterLayer1[i]->setIsLongTerm( false ); 
3574  }
3575
3576}
3577
3578Void TComSlice::printRefPicList()
3579{ 
3580  for ( Int li = 0; li < 2; li++)
3581  {   
3582    std::cout << std::endl << "RefPicListL" <<  li << ":" << std::endl; 
3583    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
3584    {     
3585      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
3586       
3587      m_apcRefPicList[li][rIdx]->print( false );
3588    }
3589  }
3590}
3591
3592Void TComSlice::markCurrPic( TComPic* currPic )
3593{
3594  currPic->getSlice(0)->setReferenced( true ) ; 
3595  currPic->setIsLongTerm( false ); 
3596
3597  currPic->setReconMark( true );
3598  currPic->setPicOutputFlag( currPic->getSlice(0)->getPicOutputFlag() );
3599}
3600
3601Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
3602{
3603  m_refPicSetInterLayer0 = refPicSetInterLayer0; 
3604  m_refPicSetInterLayer1 = refPicSetInterLayer1; 
3605}
3606
3607TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId )
3608{
3609  assert ( setIdc == 0 || setIdc == 1);   
3610  std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1);   
3611  assert( refPicSetInterLayer != 0 ); 
3612 
3613  TComPic* pcPic = NULL; 
3614  for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ )
3615  {
3616    if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId )
3617    {
3618      pcPic = (*refPicSetInterLayer)[ i ]; 
3619    }
3620  }
3621
3622  assert(pcPic != NULL); 
3623  return pcPic;
3624}
3625
3626
3627Int  TComSlice::getRefLayerPicFlag( Int i ) 
3628{
3629  TComVPS* vps = getVPS(); 
3630#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
3631#if H_3D
3632  Int refLayerIdx = vps->getLayerIdInVps( vps->getIdRefListLayer( getLayerId(), i ) ); 
3633#else
3634  Int refLayerIdx = vps->getLayerIdInVps( vps->getIdDirectRefLayer( getLayerId(), i ) ); 
3635#endif
3636#else
3637  Int refLayerIdx = vps->getLayerIdInVps( vps->getIdDirectRefLayer( getLayerId(), i ) ); 
3638#endif
3639
3640#if H_MV_FIX_REF_LAYER_PIC_FLAG
3641  Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer()  && ( getTLayer() == 0   ||
3642    vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() )); 
3643#else
3644  Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer() )  && ( getTLayer() == 0  ) &&
3645    ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); 
3646#endif
3647  return refLayerPicFlag;       
3648}   
3649
3650Int TComSlice::getRefLayerPicIdc( Int j ) 
3651{ 
3652  Int refLayerPicIdc = -1; 
3653  Int curj = 0; 
3654#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
3655#if H_3D
3656  for( Int i = 0;  i < getVPS()->getNumRefListLayers( getLayerId()) ; i++ )
3657#else
3658  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3659#endif
3660#else
3661  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3662#endif
3663  {
3664    if( getRefLayerPicFlag( i ) )
3665    {
3666      if ( curj == j ) 
3667      {
3668        refLayerPicIdc = i;         
3669        break;
3670      }
3671      curj++; 
3672    }
3673  }
3674
3675  assert( curj == j ); 
3676  assert( refLayerPicIdc != -1 ); 
3677  return refLayerPicIdc; 
3678}
3679
3680Int  TComSlice::getNumRefLayerPics( )
3681{ 
3682  Int numRefLayerPics = 0; 
3683#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
3684#if H_3D
3685  for( Int i = 0;  i < getVPS()->getNumRefListLayers( getLayerId()) ; i++ )
3686#else
3687  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3688#endif
3689#else
3690  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3691#endif
3692  {
3693    numRefLayerPics += getRefLayerPicFlag( i ); 
3694  }
3695  return numRefLayerPics; 
3696}
3697
3698
3699
3700Int TComSlice::getNumActiveRefLayerPics()
3701{
3702  Int numActiveRefLayerPics; 
3703
3704  if( getLayerId() == 0 || getNumRefLayerPics() ==  0 )
3705  {
3706    numActiveRefLayerPics = 0; 
3707  }
3708  else if (getVPS()->getAllRefLayersActiveFlag() )
3709  {
3710    numActiveRefLayerPics = getNumRefLayerPics(); 
3711  }
3712  else if ( !getInterLayerPredEnabledFlag() )
3713  {
3714    numActiveRefLayerPics = 0; 
3715  }
3716#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
3717#if H_3D
3718  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumRefListLayers( getLayerId() ) == 1 )
3719#else
3720  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
3721#endif
3722#else
3723  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
3724#endif 
3725  {
3726    numActiveRefLayerPics = 1; 
3727  }
3728  else
3729  {
3730    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
3731  }
3732  return numActiveRefLayerPics;
3733}
3734
3735Int TComSlice::getRefPicLayerId( Int i )
3736{
3737#if HHI_DEPENDENCY_SIGNALLING_I1_J0107
3738#if H_3D
3739  return getVPS()->getIdRefListLayer( getLayerId(), getInterLayerPredLayerIdc( i ) );
3740#else
3741  return getVPS()->getIdDirectRefLayer( getLayerId(), getInterLayerPredLayerIdc( i ) );
3742#endif
3743#else
3744  return getVPS()->getIdDirectRefLayer( getLayerId(), getInterLayerPredLayerIdc( i ) );
3745#endif
3746}
3747
3748#if SEC_ARP_VIEW_REF_CHECK_J0037 || SEC_DBBP_VIEW_REF_CHECK_J0037
3749Void TComSlice::setDefaultRefView( )
3750{
3751  setDefaultRefViewIdx( -1 );
3752  setDefaultRefViewIdxAvailableFlag( false ); 
3753
3754  Int valid = 0;
3755  Int DefaultRefViewIdx = -1;
3756  for( UInt curViewIdx = 0; curViewIdx < getViewIndex() && valid == 0; curViewIdx++ )
3757  {
3758    for( Int iRefListId = 0; ( iRefListId < (isInterB() ? 2 : 1) ) && !isIntra() && valid == 0; iRefListId++ )
3759    {
3760      RefPicList eRefPicList = RefPicList( iRefListId );
3761      Int        iNumRefPics = getNumRefIdx( eRefPicList );
3762      for( Int i = 0; i < iNumRefPics; i++ )
3763      { 
3764        if(getPOC() == getRefPic( eRefPicList, i )->getPOC() && curViewIdx == getRefPic( eRefPicList, i )->getViewIndex())
3765        {
3766          valid = 1;
3767          DefaultRefViewIdx = curViewIdx;
3768          break;
3769        }
3770      }
3771    }
3772  }
3773  if( valid )
3774  {
3775    setDefaultRefViewIdx( DefaultRefViewIdx );
3776    setDefaultRefViewIdxAvailableFlag( true );   
3777  }
3778}
3779#endif
3780
3781#if H_3D_ARP
3782Void TComSlice::setARPStepNum( TComPicLists*ivPicLists )
3783{
3784  Bool tempRefPicInListsFlag = false;
3785#if HHI_TOOL_PARAMETERS_I2_J0107
3786  if( !getIvResPredFlag() || this->isIRAP())
3787#else
3788  if(!getVPS()->getUseAdvRP(getLayerId()) || this->isIRAP())
3789#endif
3790  {
3791    m_nARPStepNum = 0;
3792  }
3793  else
3794  {
3795    setFirstTRefIdx (REF_PIC_LIST_0, -1);
3796    setFirstTRefIdx (REF_PIC_LIST_1, -1);
3797    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3798    {
3799      Int diffPOC=MAX_INT;
3800      Int idx=-1;
3801      for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ )
3802      {
3803        if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() )
3804        {
3805          if( abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC()) < diffPOC)
3806          {
3807            diffPOC=abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC());
3808            idx=i;
3809          }
3810        }
3811        if(idx>=0)
3812        {
3813          setFirstTRefIdx (RefPicList(refListIdx), idx);
3814        }
3815      }
3816    }
3817#if SEC_ARP_VIEW_REF_CHECK_J0037
3818    tempRefPicInListsFlag = (getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0) && getDefaultRefViewIdxAvailableFlag();
3819#else
3820    tempRefPicInListsFlag = getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0;
3821#endif
3822#if HHI_TOOL_PARAMETERS_I2_J0107
3823    m_nARPStepNum = tempRefPicInListsFlag ?  H_3D_ARP_WFNR : 0;
3824#else
3825    m_nARPStepNum = tempRefPicInListsFlag ? getVPS()->getARPStepNum(getLayerId()) : 0;
3826#endif
3827  }
3828
3829  if (tempRefPicInListsFlag)
3830  {
3831    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3832    {
3833      RefPicList eRefPicList = RefPicList( refListIdx );
3834      Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC();
3835      for( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
3836      {
3837        Int layerIdInNuh = getRefPicLayerId( i );
3838        Int viewIdx = getVPS()->getViewId( layerIdInNuh );
3839        TComPic*pcPicPrev = ivPicLists->getPic(viewIdx, 0, prevPOC);
3840        if (getFirstTRefIdx(eRefPicList) >= 0 && pcPicPrev && pcPicPrev->getSlice( 0 )->isReferenced())
3841        {
3842          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true;
3843        }
3844        else
3845        {
3846          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false;
3847        }
3848      }
3849    }
3850  }
3851}
3852#endif
3853#if H_3D_IC
3854Void TComSlice::xSetApplyIC(Bool bUseLowLatencyICEnc)
3855{
3856  if(bUseLowLatencyICEnc)
3857  {
3858    Bool existInterViewRef=false;
3859    TComPic* pcCurrPic = getPic();
3860    TComPic* pcRefPic = NULL;
3861    for ( Int i = 0; (i < getNumRefIdx( REF_PIC_LIST_0 )) && !existInterViewRef; i++ )
3862    {
3863      pcRefPic = getRefPic( REF_PIC_LIST_0, i );
3864      if ( pcRefPic != NULL )
3865      {
3866        if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3867        {
3868          existInterViewRef = true;       
3869        }
3870      }
3871    }
3872
3873    for ( Int i = 0; (i < getNumRefIdx( REF_PIC_LIST_1 )) && !existInterViewRef; i++ )
3874    {
3875      pcRefPic = getRefPic( REF_PIC_LIST_1, i );
3876      if ( pcRefPic != NULL )
3877      {
3878        if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3879        {
3880          existInterViewRef = true;       
3881        }
3882      }
3883    }
3884
3885    if(!existInterViewRef)
3886    {
3887      m_bApplyIC = false;
3888    }
3889    else
3890    {
3891      Int curLayer=getDepth();
3892      if( curLayer>9) curLayer=9; // Max layer is 10
3893
3894      m_bApplyIC = true;
3895      Int refLayer = curLayer-1;
3896
3897      Int ICEnableCandidate = getICEnableCandidate(refLayer);
3898      Int ICEnableNum = getICEnableNum(refLayer);
3899      if( (refLayer>=0) && (ICEnableCandidate>0) )
3900      {   
3901        Double ratio=Double(ICEnableNum/Double(ICEnableCandidate));
3902
3903        if( ratio > IC_LOW_LATENCY_ENCODING_THRESHOLD)
3904        {
3905          m_bApplyIC=true;
3906        }
3907        else
3908        {
3909          m_bApplyIC=false;
3910        }
3911      }
3912      setICEnableCandidate(curLayer, 0);
3913      setICEnableNum(curLayer, 0);
3914    }
3915  }
3916  else
3917  {
3918  Int iMaxPelValue = ( 1 << g_bitDepthY ); 
3919  Int *aiRefOrgHist;
3920  Int *aiCurrHist;
3921  aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue );
3922  aiCurrHist   = (Int *) xMalloc( Int,iMaxPelValue );
3923  memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
3924  memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
3925  // Reference Idx Number
3926  Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 );
3927  TComPic* pcCurrPic = NULL;
3928  TComPic* pcRefPic = NULL;
3929  TComPicYuv* pcCurrPicYuv = NULL;
3930  TComPicYuv* pcRefPicYuvOrg = NULL;
3931  pcCurrPic = getPic();
3932  pcCurrPicYuv = pcCurrPic->getPicYuvOrg();
3933  Int iWidth = pcCurrPicYuv->getWidth();
3934  Int iHeight = pcCurrPicYuv->getHeight();
3935
3936
3937  // Get InterView Reference picture
3938  // !!!!! Assume only one Interview Reference Picture in L0
3939  for ( Int i = 0; i < iNumRefIdx; i++ )
3940  {
3941    pcRefPic = getRefPic( REF_PIC_LIST_0, i );
3942    if ( pcRefPic != NULL )
3943    {
3944      if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3945      {
3946        pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
3947      }
3948    }
3949  }
3950
3951  if ( pcRefPicYuvOrg != NULL )
3952  {
3953    Pel* pCurrY = pcCurrPicYuv ->getLumaAddr();
3954    Pel* pRefOrgY = pcRefPicYuvOrg  ->getLumaAddr();
3955    Int iCurrStride = pcCurrPicYuv->getStride();
3956    Int iRefStride = pcRefPicYuvOrg->getStride();
3957    Int iSumOrgSAD = 0;
3958    Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
3959
3960    // Histogram building - luminance
3961    for ( Int y = 0; y < iHeight; y++ )
3962    {
3963      for ( Int x = 0; x < iWidth; x++ )
3964      {
3965        aiCurrHist[pCurrY[x]]++;
3966        aiRefOrgHist[pRefOrgY[x]]++;
3967      }
3968      pCurrY += iCurrStride;
3969      pRefOrgY += iRefStride;
3970    }
3971    // Histogram SAD
3972    for ( Int i = 0; i < iMaxPelValue; i++ )
3973    {
3974      iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] );
3975    }
3976    // Setting
3977    if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) )
3978    {
3979      m_bApplyIC = true;
3980    }
3981    else
3982    {
3983      m_bApplyIC = false;
3984    }
3985  }
3986
3987  xFree( aiCurrHist   );
3988  xFree( aiRefOrgHist );
3989  aiCurrHist = NULL;
3990  aiRefOrgHist = NULL;
3991  }//if(bUseLowLatencyICEnc)
3992}
3993#endif
3994#if H_3D
3995Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
3996{
3997  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
3998  {     
3999    for ( Int depthId = 0; depthId < 2; depthId++ )
4000    {
4001      m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL;
4002    }       
4003  } 
4004}
4005Void TComSlice::setDepthToDisparityLUTs()
4006{ 
4007  Bool setupLUT = false; 
4008  Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); 
4009
4010#if H_3D_VSP
4011#if HHI_TOOL_PARAMETERS_I2_J0107
4012  setupLUT = setupLUT || getViewSynthesisPredFlag( ); 
4013#else
4014  setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); 
4015#endif
4016#endif
4017
4018#if H_3D_NBDV_REF
4019#if HHI_TOOL_PARAMETERS_I2_J0107
4020  setupLUT = setupLUT || getDepthRefinementFlag( );
4021#else
4022  setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS );
4023#endif
4024#endif
4025
4026#if H_3D_IV_MERGE
4027#if HHI_TOOL_PARAMETERS_I2_J0107
4028  setupLUT = setupLUT || ( getIvMvPredFlag() && getIsDepth() );
4029#else
4030  setupLUT = setupLUT || ( getVPS()->getIvMvPredFlag(layerIdInVPS ) && getIsDepth() );
4031#endif
4032#endif
4033
4034#if !LGE_DDD_REMOVAL_J0042_J0030
4035#if H_3D_DDD
4036#if H_3D_FCO
4037  if( getIsDepth() && getViewIndex() > 0 && getVPS()->getMPIFlag(layerIdInVPS))
4038#else
4039  if( getIsDepth() && getViewIndex() > 0 )
4040#endif
4041  {
4042      TComSlice *pcTextSlice = getTexturePic()->getSlice( 0 );
4043      memcpy( m_aiDDDInvScale, pcTextSlice->m_aiDDDInvScale, sizeof( Int ) * getViewIndex() );
4044      memcpy( m_aiDDDInvOffset, pcTextSlice->m_aiDDDInvOffset, sizeof( Int ) * getViewIndex() );
4045      memcpy( m_aiDDDShift, pcTextSlice->m_aiDDDShift, sizeof( Int ) * getViewIndex() );             
4046  } 
4047#endif
4048#endif
4049
4050  if( !setupLUT )
4051    return; 
4052
4053  /// GT: Allocation should be moved to a better place later;
4054  if ( m_depthToDisparityB == NULL )
4055  {
4056    m_depthToDisparityB = new Int*[ getViewIndex() ];
4057    for ( Int i = 0; i < getViewIndex(); i++ )
4058    {
4059      m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
4060    }
4061  }
4062
4063  if ( m_depthToDisparityF == NULL )
4064  {
4065    m_depthToDisparityF= new Int*[ getViewIndex() ];
4066    for ( Int i = 0; i < getViewIndex(); i++ )
4067    {
4068      m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
4069    }
4070  }
4071
4072  assert( m_depthToDisparityB != NULL ); 
4073  assert( m_depthToDisparityF != NULL ); 
4074
4075  TComVPS* vps = getVPS(); 
4076
4077  Int log2Div = g_bitDepthY - 1 + vps->getCamParPrecision();
4078  Int viewIndex = getViewIndex();
4079
4080  Bool camParaSH = vps->hasCamParInSliceHeader( viewIndex );
4081
4082  Int* codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale    ( viewIndex ); 
4083  Int* codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset   ( viewIndex ); 
4084  Int* invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( viewIndex ); 
4085  Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( viewIndex ); 
4086
4087  for (Int i = 0; i <= ( getViewIndex() - 1); i++)
4088  {
4089    for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ )
4090    {
4091      Int offset =    ( codOffset  [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
4092      m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; 
4093
4094      Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
4095      m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; 
4096    }
4097#if !LGE_DDD_REMOVAL_J0042_J0030
4098#if H_3D_DDD
4099    initializeDDDPara( vps->getCamParPrecision(), codScale[ i ], codOffset[ i ], i );
4100#endif
4101#endif
4102  }
4103}
4104#endif
4105#endif
4106
4107#if !LGE_DDD_REMOVAL_J0042_J0030
4108#if H_3D_DDD
4109Void TComSlice::initializeDDDPara( UInt uiCamParsCodedPrecision, Int  iCodedScale,Int  iCodedOffset, Int iBaseViewIdx )
4110{
4111    UInt uiViewId     = getViewIndex();
4112
4113    if( uiViewId == 0 )
4114    {
4115        m_aiDDDInvScale[ iBaseViewIdx ] = m_aiDDDInvOffset[ iBaseViewIdx ] = m_aiDDDShift[ iBaseViewIdx ] = 0;
4116        return;
4117    }
4118
4119
4120    Int iSign = iCodedScale >= 0 ? 1 : -1;
4121    iCodedScale = abs( iCodedScale );
4122
4123    Int iBitWidth = 0;
4124
4125    const Int iInvPres = 9;
4126
4127    while( ((( 1 << iBitWidth ) << 1 ) <= iCodedScale ) )
4128    {
4129        iBitWidth ++;
4130    }
4131    iBitWidth += iInvPres;
4132    Int iTargetValue =  1 << iBitWidth;
4133
4134    Int iMinError = MAX_INT;
4135    Int iBestD = 1 << ( iInvPres - 1 );
4136    for( Int d = 1 << ( iInvPres - 1 ); d < ( 1 << iInvPres ); d++ )
4137    {
4138        Int iError = abs( iCodedScale * d - iTargetValue );
4139        if( iError < iMinError )
4140        {
4141            iMinError = iError;
4142            iBestD = d;
4143        }
4144        if( iMinError == 0 )
4145        {
4146            break;
4147        }
4148    }
4149    Int iRoundingDir = 0;
4150    if( iCodedScale * iBestD > iTargetValue )
4151    {
4152        iRoundingDir = -1;
4153    }
4154    else if( iCodedScale * iBestD < iTargetValue )
4155    {
4156        iRoundingDir = 1;
4157    }
4158    Int iCamPres = uiCamParsCodedPrecision - 1;
4159    m_aiDDDInvScale [ iBaseViewIdx ] = ( iBestD << ( iCamPres + g_bitDepthY )) * iSign;
4160    m_aiDDDInvOffset[ iBaseViewIdx ] = -iSign * iBestD * ( iCodedOffset << g_bitDepthY );
4161    m_aiDDDShift    [ iBaseViewIdx ] = iBitWidth;
4162    m_aiDDDInvOffset[ iBaseViewIdx ] += 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 1 );
4163    m_aiDDDInvOffset[ iBaseViewIdx ] += ( 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 4 ) ) * iRoundingDir;
4164
4165    return;
4166}
4167
4168
4169#endif
4170#endif
4171
4172#if H_MV
4173Void TComSlice::checkCrossLayerBlaFlag()
4174{
4175  // 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.
4176  if ( getLayerId() != 0 || getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
4177  {
4178    assert( m_crossLayerBlaFlag == 0 ); 
4179  }
4180}
4181
4182Bool TComSlice::inferPocMsbValPresentFlag()
4183{
4184  Bool pocMsbValPresentFlag; 
4185  if( getSliceSegmentHeaderExtensionLength() == 0 ) 
4186  {
4187    pocMsbValPresentFlag = false; 
4188  }
4189  else if ( getPocMsbValRequiredFlag() )
4190  {
4191    pocMsbValPresentFlag = true; 
4192  }
4193  else
4194  {
4195    pocMsbValPresentFlag = false; 
4196  }
4197
4198  return pocMsbValPresentFlag;
4199}
4200
4201
4202#endif
4203
4204#if !LGE_DDD_REMOVAL_J0042_J0030
4205#if H_3D_DBBP
4206Int TComSlice::getDepthFromDV( Int iDV, Int iBaseViewIdx )
4207{
4208  return ClipY(( iDV * m_aiDDDInvScale[ iBaseViewIdx ] + m_aiDDDInvOffset[ iBaseViewIdx ] ) >> m_aiDDDShift[ iBaseViewIdx ]);
4209}
4210#endif
4211#endif
4212
4213#if HHI_TOOL_PARAMETERS_I2_J0107
4214#if H_3D
4215
4216Void TComSlice::init3dToolParameters()
4217{
4218  Bool depthFlag = getIsDepth();
4219
4220  Bool depthOfRefViewsAvailFlag = false; 
4221  Bool textOfCurViewAvailFlag = false; 
4222
4223  TComVPS* vps = getVPS(); 
4224
4225  if( !depthFlag )
4226  {
4227    depthOfRefViewsAvailFlag = true;
4228    for( Int i = 0; i <= vps->getNumRefListLayers( getLayerId() ) - 1; i++)
4229    {
4230      Bool curDepthAvailableFlag = false;   
4231      for (Int j = 0; j <= vps->getMaxLayersMinus1(); j++ )
4232      {
4233        if ( vps->getDirectDependencyFlag( vps->getLayerIdInVps( getLayerId() ), j )
4234          && vps->getVpsDepthFlag        ( vps->getLayerIdInNuh( j ) ) == 1
4235          && vps->getViewOrderIdx( vps->getLayerIdInNuh( j ) ) == vps->getViewOrderIdx( vps->getIdRefListLayer( getLayerId(), i ) )
4236          && vps->getDependencyId( vps->getLayerIdInNuh( j ) ) == 0
4237          && vps->getAuxId       ( vps->getLayerIdInNuh( j ) ) == 0
4238          )
4239        {
4240          curDepthAvailableFlag = true; 
4241        }
4242      }
4243      if ( !curDepthAvailableFlag )
4244      {
4245        depthOfRefViewsAvailFlag = false; 
4246      }   
4247    }
4248  }
4249  else
4250  {
4251    for (Int j = 0; j <= vps->getMaxLayersMinus1(); j++ )
4252    {
4253      if ( vps->getDirectDependencyFlag( vps->getLayerIdInVps( getLayerId() ), j ) 
4254        && vps->getVpsDepthFlag( vps->getLayerIdInNuh( j ) ) == 0
4255        && vps->getViewOrderIdx( vps->getLayerIdInNuh( j ) ) == getViewIndex() 
4256        && vps->getDependencyId( vps->getLayerIdInNuh( j ) ) == 0
4257        && vps->getAuxId       ( vps->getLayerIdInNuh( j ) ) == 0
4258        )
4259      {       
4260        textOfCurViewAvailFlag = true; 
4261      }
4262    }
4263  }
4264
4265  Bool lidG0  = ( getLayerId() > 0 );
4266  Bool nRLLG0 =  ( getVPS()->getNumRefListLayers( getLayerId() ) > 0 );     
4267
4268  TComSps3dExtension* sps3dExt = getSPS()->getSps3dExtension();
4269
4270  m_ivMvPredFlag           = sps3dExt->getIvMvPredFlag         ( depthFlag ) && lidG0 && nRLLG0                           ;                             
4271  m_ivMvScalingFlag        = sps3dExt->getIvMvScalingFlag      ( depthFlag ) && lidG0                                    ;                             
4272  m_ivResPredFlag          = sps3dExt->getIvResPredFlag        ( depthFlag ) && lidG0 && nRLLG0                           ;                               
4273  m_depthRefinementFlag    = sps3dExt->getDepthRefinementFlag  ( depthFlag ) && lidG0           && depthOfRefViewsAvailFlag;                           
4274  m_viewSynthesisPredFlag  = sps3dExt->getViewSynthesisPredFlag( depthFlag ) && lidG0 && nRLLG0 && depthOfRefViewsAvailFlag;                         
4275  m_depthBasedBlkPartFlag  = sps3dExt->getDepthBasedBlkPartFlag( depthFlag ) && lidG0           && depthOfRefViewsAvailFlag;                         
4276  m_mpiFlag                = sps3dExt->getMpiFlag              ( depthFlag ) && lidG0           &&   textOfCurViewAvailFlag;
4277  m_intraContourFlag       = sps3dExt->getIntraContourFlag     ( depthFlag ) && lidG0           &&   textOfCurViewAvailFlag;
4278  m_intraSdcWedgeFlag      = sps3dExt->getIntraSdcWedgeFlag    ( depthFlag ) && lidG0                                     ;                         
4279  m_qtPredFlag             = sps3dExt->getQtPredFlag           ( depthFlag ) && lidG0           &&   textOfCurViewAvailFlag;
4280  m_interSdcFlag           = sps3dExt->getInterSdcFlag         ( depthFlag ) && lidG0                                    ;                               
4281  m_intraSingleFlag        = sps3dExt->getIntraSingleFlag      ( depthFlag ) && lidG0                                    ;                         
4282
4283  m_subPbSize              = lidG0 ? ( 1 << ( sps3dExt->getLog2SubPbSizeMinus3   ( depthFlag ) + 3 ) ) : getSPS()->getMaxCUWidth(); 
4284  m_mpiSubPbSize           = 1 << ( sps3dExt->getLog2MpiSubPbSizeMinus3( depthFlag ) + 3 );
4285
4286#if H_3D_OUTPUT_ACTIVE_TOOLS
4287  std::cout << "Layer:                  :" << getLayerId()             << std::endl;
4288  std::cout << "DepthFlag:              :" << getIsDepth()             << std::endl;
4289  std::cout << "ViewOrderIdx:           :" << getViewIndex()           << std::endl;
4290  std::cout << "DepthOfRefViewsAvailFlag:" << depthOfRefViewsAvailFlag << std::endl;
4291  std::cout << "TextOfCurViewAvailFlag  :" << textOfCurViewAvailFlag   << std::endl;
4292 
4293  std::cout << "ivMvPredFlag            :" << m_ivMvPredFlag           << std::endl;
4294  std::cout << "ivMvScalingFlag         :" << m_ivMvScalingFlag        << std::endl;
4295  std::cout << "ivResPredFlag           :" << m_ivResPredFlag          << std::endl;
4296  std::cout << "depthRefinementFlag     :" << m_depthRefinementFlag    << std::endl;
4297  std::cout << "viewSynthesisPredFlag   :" << m_viewSynthesisPredFlag  << std::endl;
4298  std::cout << "depthBasedBlkPartFlag   :" << m_depthBasedBlkPartFlag  << std::endl;
4299  std::cout << "mpiFlag                 :" << m_mpiFlag                << std::endl;
4300  std::cout << "intraContourFlag        :" << m_intraContourFlag       << std::endl;
4301  std::cout << "intraSdcWedgeFlag       :" << m_intraSdcWedgeFlag      << std::endl;
4302  std::cout << "qtPredFlag              :" << m_qtPredFlag             << std::endl;
4303  std::cout << "interSdcFlag            :" << m_interSdcFlag           << std::endl;
4304  std::cout << "intraSingleFlag         :" << m_intraSingleFlag        << std::endl;   
4305  std::cout << "subPbSize               :" << m_subPbSize              << std::endl;
4306  std::cout << "mpiSubPbSize            :" << m_mpiSubPbSize           << std::endl;
4307#endif
4308}
4309#endif
4310#endif
4311
4312
4313/** get scaling matrix from RefMatrixID
4314 * \param sizeId size index
4315 * \param Index of input matrix
4316 * \param Index of reference matrix
4317 */
4318Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
4319{
4320  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
4321}
4322
4323/** parse syntax infomation
4324 *  \param pchFile syntax infomation
4325 *  \returns false if successful
4326 */
4327Bool TComScalingList::xParseScalingList(Char* pchFile)
4328{
4329  FILE *fp;
4330  Char line[1024];
4331  UInt sizeIdc,listIdc;
4332  UInt i,size = 0;
4333  Int *src=0,data;
4334  Char *ret;
4335  UInt  retval;
4336
4337  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
4338  {
4339    printf("can't open file %s :: set Default Matrix\n",pchFile);
4340    return true;
4341  }
4342
4343  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
4344  {
4345    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
4346    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
4347    {
4348      src = getScalingListAddress(sizeIdc, listIdc);
4349
4350      fseek(fp,0,0);
4351      do 
4352      {
4353        ret = fgets(line, 1024, fp);
4354        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
4355        {
4356          printf("Error: can't read Matrix :: set Default Matrix\n");
4357          return true;
4358        }
4359      }
4360      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
4361      for (i=0; i<size; i++)
4362      {
4363        retval = fscanf(fp, "%d,", &data);
4364        if (retval!=1)
4365        {
4366          printf("Error: can't read Matrix :: set Default Matrix\n");
4367          return true;
4368        }
4369        src[i] = data;
4370      }
4371      //set DC value for default matrix check
4372      setScalingListDC(sizeIdc,listIdc,src[0]);
4373
4374      if(sizeIdc > SCALING_LIST_8x8)
4375      {
4376        fseek(fp,0,0);
4377        do 
4378        {
4379          ret = fgets(line, 1024, fp);
4380          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
4381          {
4382            printf("Error: can't read DC :: set Default Matrix\n");
4383            return true;
4384          }
4385        }
4386        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
4387        retval = fscanf(fp, "%d,", &data);
4388        if (retval!=1)
4389        {
4390          printf("Error: can't read Matrix :: set Default Matrix\n");
4391          return true;
4392        }
4393        //overwrite DC value when size of matrix is larger than 16x16
4394        setScalingListDC(sizeIdc,listIdc,data);
4395      }
4396    }
4397  }
4398  fclose(fp);
4399  return false;
4400}
4401
4402#if H_MV
4403Void TComScalingList::inferFrom( TComScalingList* srcScLi )
4404{
4405  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
4406  {
4407    for(Int listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
4408    {
4409      setRefMatrixId  (sizeId,listId, srcScLi->getRefMatrixId  (sizeId,listId));
4410      setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId));         
4411      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
4412    }
4413  }
4414}
4415#endif
4416/** initialization process of quantization matrix array
4417 */
4418Void TComScalingList::init()
4419{
4420  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
4421  {
4422    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
4423    {
4424      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
4425    }
4426  }
4427  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
4428}
4429
4430/** destroy quantization matrix array
4431 */
4432Void TComScalingList::destroy()
4433{
4434  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
4435  {
4436    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
4437    {
4438      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
4439    }
4440  }
4441}
4442
4443/** get default address of quantization matrix
4444 * \param sizeId size index
4445 * \param listId list index
4446 * \returns pointer of quantization matrix
4447 */
4448Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
4449{
4450  Int *src = 0;
4451  switch(sizeId)
4452  {
4453    case SCALING_LIST_4x4:
4454      src = g_quantTSDefault4x4;
4455      break;
4456    case SCALING_LIST_8x8:
4457      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
4458      break;
4459    case SCALING_LIST_16x16:
4460      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
4461      break;
4462    case SCALING_LIST_32x32:
4463      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
4464      break;
4465    default:
4466      assert(0);
4467      src = NULL;
4468      break;
4469  }
4470  return src;
4471}
4472
4473/** process of default matrix
4474 * \param sizeId size index
4475 * \param Index of input matrix
4476 */
4477Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
4478{
4479  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
4480  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
4481}
4482
4483/** check DC value of matrix for default matrix signaling
4484 */
4485Void TComScalingList::checkDcOfMatrix()
4486{
4487  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
4488  {
4489    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
4490    {
4491      //check default matrix?
4492      if(getScalingListDC(sizeId,listId) == 0)
4493      {
4494        processDefaultMatrix(sizeId, listId);
4495      }
4496    }
4497  }
4498}
4499
4500ParameterSetManager::ParameterSetManager()
4501: m_vpsMap(MAX_NUM_VPS)
4502, m_spsMap(MAX_NUM_SPS)
4503, m_ppsMap(MAX_NUM_PPS)
4504, m_activeVPSId(-1)
4505#if !H_MV
4506, m_activeSPSId(-1)
4507, m_activePPSId(-1)
4508{
4509#else
4510{
4511  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
4512  {
4513    m_activeSPSId[ i ] = -1; 
4514    m_activePPSId[ i ] = -1; 
4515  }
4516#endif
4517}
4518
4519
4520ParameterSetManager::~ParameterSetManager()
4521{
4522}
4523
4524//! activate a SPS from a active parameter sets SEI message
4525//! \returns true, if activation is successful
4526#if H_MV
4527Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
4528#else
4529Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
4530#endif
4531{
4532  TComSPS *sps = m_spsMap.getPS(spsId);
4533  if (sps)
4534  {
4535    Int vpsId = sps->getVPSId();
4536    if (m_vpsMap.getPS(vpsId))
4537    {
4538      m_activeVPSId = vpsId;
4539#if H_MV
4540      m_activeSPSId[ layerId ] = spsId;
4541#else
4542      m_activeSPSId = spsId;
4543#endif
4544      return true;
4545    }
4546    else
4547    {
4548      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
4549    }
4550  }
4551  else
4552  {
4553    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
4554  }
4555  return false;
4556}
4557
4558//! activate a PPS and depending on isIDR parameter also SPS and VPS
4559//! \returns true, if activation is successful
4560#if H_MV
4561Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
4562#else
4563Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
4564#endif
4565{
4566  TComPPS *pps = m_ppsMap.getPS(ppsId);
4567  if (pps)
4568  {
4569    Int spsId = pps->getSPSId();
4570#if H_MV
4571    if (!isIRAP && (spsId != m_activeSPSId[ layerId ]))
4572#else
4573    if (!isIRAP && (spsId != m_activeSPSId))
4574#endif
4575    {
4576      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
4577      return false;
4578    }
4579
4580    TComSPS *sps = m_spsMap.getPS(spsId);
4581    if (sps)
4582    {
4583      Int vpsId = sps->getVPSId();
4584      if (!isIRAP && (vpsId != m_activeVPSId))
4585      {
4586        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
4587        return false;
4588      }
4589      if (m_vpsMap.getPS(vpsId))
4590      {
4591#if H_MV
4592        m_activePPSId[ layerId ] = ppsId;
4593        m_activeVPSId = vpsId;
4594        m_activeSPSId[ layerId ] = spsId;
4595#else
4596        m_activePPSId = ppsId;
4597        m_activeVPSId = vpsId;
4598        m_activeSPSId = spsId;
4599#endif
4600        return true;
4601      }
4602      else
4603      {
4604        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
4605      }
4606    }
4607    else
4608    {
4609      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
4610    }
4611  }
4612  else
4613  {
4614    printf("Warning: tried to activate non-existing PPS.");
4615  }
4616  return false;
4617}
4618
4619ProfileTierLevel::ProfileTierLevel()
4620  : m_profileSpace    (0)
4621  , m_tierFlag        (false)
4622  , m_profileIdc      (0)
4623  , m_levelIdc        (0)
4624, m_progressiveSourceFlag  (false)
4625, m_interlacedSourceFlag   (false)
4626, m_nonPackedConstraintFlag(false)
4627, m_frameOnlyConstraintFlag(false)
4628#if H_MV
4629  , m_max12bitConstraintFlag      ( false )
4630  , m_max10bitConstraintFlag      ( false )
4631  , m_max8bitConstraintFlag       ( false )
4632  , m_max422chromaConstraintFlag  ( false )
4633  , m_max420chromaConstraintFlag  ( false )
4634  , m_maxMonochromeConstraintFlag ( false )
4635  , m_intraConstraintFlag         ( false )
4636  , m_onePictureOnlyConstraintFlag( false )
4637  , m_lowerBitRateConstraintFlag  ( false )
4638  , m_inbldFlag                   ( false )
4639#endif
4640{
4641  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
4642}
4643
4644#if H_MV
4645Bool ProfileTierLevel::getV2ConstraintsPresentFlag()
4646{
4647  return ( 
4648    getProfileIdc( ) ==  4 || getProfileCompatibilityFlag( 4 ) || getProfileIdc( ) ==  5 || getProfileCompatibilityFlag( 5 )  ||
4649    getProfileIdc( ) ==  6 || getProfileCompatibilityFlag( 6 ) || getProfileIdc( ) ==  7 || getProfileCompatibilityFlag( 7 ) 
4650    );
4651}
4652
4653Bool ProfileTierLevel::getInbldPresentFlag()
4654{
4655  return ( 
4656    ( getProfileIdc() >= 1 && getProfileIdc() <= 5 )  || getProfileCompatibilityFlag( 1 ) || getProfileCompatibilityFlag( 2 ) || 
4657    getProfileCompatibilityFlag( 3 ) || getProfileCompatibilityFlag( 4 )  ||   getProfileCompatibilityFlag( 5 ) 
4658    );
4659}
4660
4661Void ProfileTierLevel::copyV2ConstraintFlags(ProfileTierLevel* ptlRef)
4662{
4663  setMax12bitConstraintFlag         ( ptlRef->getMax12bitConstraintFlag       ( ) );
4664  setMax10bitConstraintFlag         ( ptlRef->getMax10bitConstraintFlag       ( ) );
4665  setMax8bitConstraintFlag          ( ptlRef->getMax8bitConstraintFlag        ( ) );
4666  setMax422chromaConstraintFlag     ( ptlRef->getMax422chromaConstraintFlag   ( ) );
4667  setMax420chromaConstraintFlag     ( ptlRef->getMax420chromaConstraintFlag   ( ) );
4668  setMaxMonochromeConstraintFlag    ( ptlRef->getMaxMonochromeConstraintFlag  ( ) );
4669  setIntraConstraintFlag            ( ptlRef->getIntraConstraintFlag          ( ) );
4670  setOnePictureOnlyConstraintFlag   ( ptlRef->getOnePictureOnlyConstraintFlag ( ) );
4671  setLowerBitRateConstraintFlag     ( ptlRef->getLowerBitRateConstraintFlag   ( ) );
4672}
4673
4674Void ProfileTierLevel::copyProfile(ProfileTierLevel* ptlRef)
4675{
4676  setProfileSpace            ( ptlRef->getProfileSpace              ( ) );
4677  setTierFlag                ( ptlRef->getTierFlag                  ( ) );
4678  setProfileIdc              ( ptlRef->getProfileIdc                ( ) );
4679  for (Int j = 0; j < 32; j++)
4680  {     
4681    setProfileCompatibilityFlag(j, ptlRef->getProfileCompatibilityFlag  ( j ) );           
4682  }
4683  setProgressiveSourceFlag   ( ptlRef->getProgressiveSourceFlag     ( ) );
4684  setInterlacedSourceFlag    ( ptlRef->getInterlacedSourceFlag      ( ) );
4685  setNonPackedConstraintFlag ( ptlRef->getNonPackedConstraintFlag   ( ) );
4686  setFrameOnlyConstraintFlag ( ptlRef->getFrameOnlyConstraintFlag   ( ) );
4687  copyV2ConstraintFlags      ( ptlRef );
4688}
4689#endif
4690
4691TComPTL::TComPTL()
4692{
4693  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
4694  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
4695}
4696
4697#if H_MV
4698Void TComPTL::inferGeneralValues(Bool profilePresentFlag, Int k, TComPTL* refPTL)
4699{
4700  ProfileTierLevel* refProfileTierLevel = NULL; 
4701  if ( k > 0 )
4702  {   
4703    assert( refPTL != NULL);
4704    refProfileTierLevel = refPTL->getGeneralPTL(); 
4705  }
4706
4707  ProfileTierLevel* curProfileTierLevel = getGeneralPTL( ); 
4708
4709  if( !profilePresentFlag )
4710  {
4711    assert( k > 0 ); 
4712    assert( refProfileTierLevel != NULL ); 
4713    curProfileTierLevel->copyProfile( refProfileTierLevel);
4714  }
4715  else
4716  {
4717    if ( !curProfileTierLevel->getV2ConstraintsPresentFlag() )
4718    {
4719      curProfileTierLevel->setMax12bitConstraintFlag         ( false );
4720      curProfileTierLevel->setMax10bitConstraintFlag         ( false );
4721      curProfileTierLevel->setMax8bitConstraintFlag          ( false );
4722      curProfileTierLevel->setMax422chromaConstraintFlag     ( false );
4723      curProfileTierLevel->setMax420chromaConstraintFlag     ( false );
4724      curProfileTierLevel->setMaxMonochromeConstraintFlag    ( false );
4725      curProfileTierLevel->setIntraConstraintFlag            ( false );
4726      curProfileTierLevel->setOnePictureOnlyConstraintFlag   ( false );
4727      curProfileTierLevel->setLowerBitRateConstraintFlag     ( false );   
4728    }
4729
4730    if ( !curProfileTierLevel->getInbldPresentFlag() )
4731    {
4732      curProfileTierLevel->setInbldFlag( false ); 
4733    }     
4734  }
4735}
4736
4737Void TComPTL::inferSubLayerValues(Int maxNumSubLayersMinus1, Int k, TComPTL* refPTL)
4738{
4739  assert( k == 0 || refPTL != NULL ); 
4740
4741  for (Int i = maxNumSubLayersMinus1; i >= 0; i--)
4742  {
4743    ProfileTierLevel* refProfileTierLevel;
4744    if ( k != 0 )
4745    {
4746      refProfileTierLevel = refPTL->getSubLayerPTL( i );
4747    }
4748    else
4749    {
4750      if ( i == maxNumSubLayersMinus1)     
4751      {
4752        refProfileTierLevel = getGeneralPTL();
4753      }
4754      else
4755      {
4756        refProfileTierLevel = getSubLayerPTL( i + 1 );
4757      }
4758    }   
4759
4760    ProfileTierLevel* curProfileTierLevel = getSubLayerPTL( i ); 
4761    if( !getSubLayerLevelPresentFlag( i ) )
4762    {
4763      curProfileTierLevel->setLevelIdc( refProfileTierLevel->getLevelIdc() ); 
4764    }
4765
4766    if( !getSubLayerProfilePresentFlag( i ) )
4767    {
4768      curProfileTierLevel->copyProfile( refProfileTierLevel);
4769    }
4770    else
4771    {
4772      if ( !curProfileTierLevel->getV2ConstraintsPresentFlag() )
4773      {
4774        curProfileTierLevel->copyV2ConstraintFlags( refProfileTierLevel ); 
4775      }
4776
4777      if ( !curProfileTierLevel->getInbldPresentFlag() )
4778      {
4779        curProfileTierLevel->setInbldFlag( refProfileTierLevel->getInbldFlag() ); 
4780      }     
4781    }     
4782  }
4783}
4784
4785#endif
4786//! \}
4787
4788#if H_MV
4789TComVPSVUI::TComVPSVUI()
4790{
4791  m_crossLayerIrapAlignedFlag = true; 
4792  m_allLayersIdrAlignedFlag   = false; 
4793  m_bitRatePresentVpsFlag = false;
4794  m_picRatePresentVpsFlag = false;
4795  for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++)
4796  {   
4797    for ( Int j = 0; j < MAX_TLAYER; j++)
4798    {   
4799      m_bitRatePresentFlag          [i][j] = false;
4800      m_picRatePresentFlag          [i][j] = false;
4801      m_avgBitRate                  [i][j] = -1;
4802      m_maxBitRate                  [i][j] = -1;
4803      m_constantPicRateIdc          [i][j] = -1;
4804      m_avgPicRate                  [i][j] = -1;
4805    }
4806  }
4807
4808  m_ilpRestrictedRefLayersFlag = false;
4809
4810  for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
4811  {         
4812    for ( Int j = 0; j < MAX_NUM_LAYERS; j++)
4813    {   
4814      m_tileBoundariesAlignedFlag   [i][j] = false;
4815      m_minSpatialSegmentOffsetPlus1[i][j] = 0;
4816      m_ctuBasedOffsetEnabledFlag   [i][j] = false;
4817      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
4818    }
4819    m_baseLayerParameterSetCompatibilityFlag[i] = false;
4820  }
4821  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
4822  {
4823    m_videoSignalInfo          [i] = NULL;     
4824  }
4825
4826  m_vpsVuiBspHrdPresentFlag = false; 
4827  m_vpsVuiBspHrdParameters  = NULL;
4828}
4829
4830TComVPSVUI::~TComVPSVUI()
4831{
4832  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
4833  {
4834    if (m_videoSignalInfo[ i ] != NULL )      delete m_videoSignalInfo[ i ];   
4835    m_videoSignalInfo    [ i ] = NULL; 
4836  }
4837
4838  if ( m_vpsVuiBspHrdParameters ) delete m_vpsVuiBspHrdParameters;
4839  m_vpsVuiBspHrdParameters = NULL; 
4840}
4841
4842Void TComVPSVUI::inferVpsVui( Bool encoderFlag )
4843{
4844  // inference of syntax elements that differ from default inference (as done in constructor), when VPS VUI is not present
4845  if (!encoderFlag )
4846  {
4847    setCrossLayerIrapAlignedFlag( false ); 
4848  }
4849  else
4850  {
4851    assert( !getCrossLayerIrapAlignedFlag() ); 
4852  }
4853}
4854
4855Void TComRepFormat::inferChromaAndBitDepth( TComRepFormat* prevRepFormat, Bool encoderFlag )
4856{
4857  if ( !encoderFlag )
4858  {
4859    setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
4860    setSeparateColourPlaneVpsFlag     ( prevRepFormat->getSeparateColourPlaneVpsFlag     () );
4861    setBitDepthVpsLumaMinus8          ( prevRepFormat->getBitDepthVpsLumaMinus8          () );
4862    setBitDepthVpsChromaMinus8        ( prevRepFormat->getBitDepthVpsChromaMinus8        () );
4863  }
4864  else
4865  {
4866    assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
4867    assert( getSeparateColourPlaneVpsFlag     () == prevRepFormat->getSeparateColourPlaneVpsFlag     () );
4868    assert( getBitDepthVpsLumaMinus8          () == prevRepFormat->getBitDepthVpsLumaMinus8          () );
4869    assert( getBitDepthVpsChromaMinus8        () == prevRepFormat->getBitDepthVpsChromaMinus8        () );
4870  }
4871}
4872
4873
4874
4875TComVpsVuiBspHrdParameters::~TComVpsVuiBspHrdParameters()
4876{
4877  delete[] m_cprmsAddPresentFlag; 
4878  delete[] m_numSubLayerHrdMinus1; 
4879  delete[] m_hrdParameters; 
4880
4881  for (Int h = 0; h < m_numOls; h++)
4882  {
4883    if ( h > 0 )
4884    {   
4885      for (Int i = 0; i < getNumSignalledPartitioningSchemes(h)+1; i++)
4886      {
4887        for (Int t = 0; t < m_vps->getMaxSubLayersInLayerSetMinus1( m_vps->olsIdxToLsIdx(h) ) + 1; t++)
4888        {       
4889          for ( Int j = 0; j <= getNumBspSchedulesMinus1(h,i,j);j++ )
4890          {
4891            delete[] m_bspHrdIdx  [h][i][t][j]; 
4892            delete[] m_bspSchedIdx[h][i][t][j];
4893          }
4894        }
4895        delete[] m_numBspSchedulesMinus1[h][i];
4896      }
4897    }
4898
4899    for (Int j = 0; j <= getNumSignalledPartitioningSchemes(h ) + 1; j++ )
4900    {
4901      for (Int k = 0; k <= getNumPartitionsInSchemeMinus1(h,j); k++ )
4902      {
4903        delete[] m_layerIncludedInPartitionFlag[h][j][k];
4904      }       
4905    }
4906    delete[] m_numPartitionsInSchemeMinus1[h];       
4907  }
4908  delete[] m_numSignalledPartitioningSchemes;
4909}
4910
4911
4912Int TComVpsVuiBspHrdParameters::getBspHrdIdxLen(TComVPS* vps)
4913{
4914  return gCeilLog2( vps->getNumHrdParameters() + getVpsNumAddHrdParams() );
4915}
4916
4917Void TComVpsVuiBspHrdParameters::createAfterVpsNumAddHrdParams( TComVPS* vps )
4918{
4919  assert( vps == NULL ); 
4920  m_vps = vps; 
4921  m_offsetHrdParamIdx = vps->getNumHrdParameters(); 
4922  m_numHrdParam       = vps->getNumHrdParameters() + getVpsNumAddHrdParams() - m_offsetHrdParamIdx;
4923  m_numOls            = vps->getNumOutputLayerSets(); 
4924
4925  m_cprmsAddPresentFlag   = new Bool    [ m_numHrdParam ];
4926  m_numSubLayerHrdMinus1  = new Int     [ m_numHrdParam ];
4927  m_hrdParameters         = new TComHRD [ m_numHrdParam ];
4928
4929  m_numSignalledPartitioningSchemes = new Int    [ m_numOls ]; 
4930  m_numPartitionsInSchemeMinus1     = new Int*   [ m_numOls ];
4931  m_numBspSchedulesMinus1           = new Int**  [ m_numOls ]; 
4932  m_bspHrdIdx                       = new Int****[ m_numOls ];
4933  m_bspSchedIdx                     = new Int****[ m_numOls ];
4934}
4935
4936Void TComVpsVuiBspHrdParameters::createAfterNumSignalledPartitioningSchemes( Int h )
4937{
4938  m_numPartitionsInSchemeMinus1 [h]    = new Int    [ getNumSignalledPartitioningSchemes(h) ];
4939  m_layerIncludedInPartitionFlag[h]    = new Bool** [ getNumSignalledPartitioningSchemes(h) ];   
4940
4941  m_numBspSchedulesMinus1[h]           = new Int*   [ getNumSignalledPartitioningSchemes(h) + 1 ];
4942  for (Int i = 0; i < getNumSignalledPartitioningSchemes(h) + 1; i++)
4943  {
4944    Int tMax = m_vps->getMaxSubLayersInLayerSetMinus1( m_vps->olsIdxToLsIdx(h) ) + 1;
4945    m_numBspSchedulesMinus1[h][i] = new Int  [ tMax ];
4946    m_bspHrdIdx            [h][i] = new Int**[ tMax ];
4947    m_bspSchedIdx          [h][i] = new Int**[ tMax ];
4948  }
4949}
4950
4951Void TComVpsVuiBspHrdParameters::createAfterNumPartitionsInSchemeMinus1( Int h, Int j )
4952{
4953  m_layerIncludedInPartitionFlag[h][j] = new Bool*[ getNumPartitionsInSchemeMinus1(h,j)];
4954  for( Int k = 0; k < getNumPartitionsInSchemeMinus1(h,j); k++ )
4955  {
4956    m_layerIncludedInPartitionFlag[h][j][k] = new Bool[ m_vps->getNumLayersInIdList( m_vps->olsIdxToLsIdx(h))];
4957  }
4958}
4959
4960Void TComVpsVuiBspHrdParameters::createAfterNumBspSchedulesMinus1( Int h, Int i, Int t )
4961{
4962  m_bspSchedIdx[h][i][t] = new Int* [ getNumBspSchedulesMinus1( h, i, t ) + 1 ];
4963  m_bspHrdIdx  [h][i][t] = new Int* [ getNumBspSchedulesMinus1( h, i, t ) + 1 ];
4964  for( Int j = 0; j < getNumBspSchedulesMinus1( h, i, t ) + 1; j++ )
4965  {
4966    m_bspSchedIdx[h][i][t][j] = new Int[ getNumPartitionsInSchemeMinus1( h, i ) ];
4967    m_bspHrdIdx  [h][i][t][j] = new Int[ getNumPartitionsInSchemeMinus1( h, i ) ];
4968  }
4969}
4970
4971
4972Void TComVUI::inferVideoSignalInfo( TComVPS* vps, Int layerIdCurr )
4973{
4974  if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() ) 
4975  {
4976    return; 
4977  }
4978
4979  TComVPSVUI* vpsVUI = vps->getVPSVUI(); 
4980  assert( vpsVUI != NULL ); 
4981
4982  TComVideoSignalInfo* videoSignalInfo = vpsVUI->getVideoSignalInfo( vpsVUI->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); 
4983  assert( videoSignalInfo != NULL );
4984
4985  setVideoFormat            ( videoSignalInfo->getVideoVpsFormat            () ); 
4986  setVideoFullRangeFlag     ( videoSignalInfo->getVideoFullRangeVpsFlag     () );
4987  setColourPrimaries        ( videoSignalInfo->getColourPrimariesVps        () );
4988  setTransferCharacteristics( videoSignalInfo->getTransferCharacteristicsVps() );
4989  setMatrixCoefficients     ( videoSignalInfo->getMatrixCoeffsVps           () );
4990}
4991
4992TComDpbSize::TComDpbSize()
4993{
4994  for (Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++ )
4995  {     
4996    m_subLayerFlagInfoPresentFlag[i]  = false;
4997
4998    for (Int j = 0; j < MAX_TLAYER; j++  )
4999    {       
5000      m_subLayerDpbInfoPresentFlag [i][j] = ( j == 0) ;
5001      m_maxVpsNumReorderPics       [i][j] = 0;
5002      m_maxVpsLatencyIncreasePlus1 [i][j] = 0;
5003
5004      for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++ )
5005      {
5006        m_maxVpsDecPicBufferingMinus1[i][k][j] = MIN_INT; 
5007      }
5008    }
5009  }
5010}
5011
5012Void Window::scaleOffsets( Int scal )
5013{
5014  if (! m_scaledFlag )
5015  {
5016    m_scaledFlag         = true; 
5017    m_winLeftOffset     *= scal; 
5018    m_winRightOffset    *= scal; 
5019    m_winTopOffset      *= scal; 
5020    m_winBottomOffset   *= scal; 
5021  }
5022}
5023#endif
5024
Note: See TracBrowser for help on using the repository browser.