source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.cpp @ 859

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

JCTVC-P0130: Discardable pictures shall not be present in RPS (Macro: H_MV_HLS_7_MISC_P0130_20)

Added assert statements to ensure that discardable pictures are not present in the temporal RPS and inter-layer RPS.

From: Adarsh K. Ramasubramonian <aramasub@…>

  • Property svn:eol-style set to native
File size: 117.9 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-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
47TComSlice::TComSlice()
48: m_iPPSId                        ( -1 )
49, m_iPOC                          ( 0 )
50, m_iLastIDR                      ( 0 )
51, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
52, m_eSliceType                    ( I_SLICE )
53, m_iSliceQp                      ( 0 )
54, m_dependentSliceSegmentFlag            ( false )
55#if ADAPTIVE_QP_SELECTION
56, m_iSliceQpBase                  ( 0 )
57#endif
58, m_deblockingFilterDisable        ( false )
59, m_deblockingFilterOverrideFlag   ( false )
60, m_deblockingFilterBetaOffsetDiv2 ( 0 )
61, m_deblockingFilterTcOffsetDiv2   ( 0 )
62, m_bCheckLDC                     ( false )
63, m_iSliceQpDelta                 ( 0 )
64, m_iSliceQpDeltaCb               ( 0 )
65, m_iSliceQpDeltaCr               ( 0 )
66, m_iDepth                        ( 0 )
67, m_bRefenced                     ( false )
68, m_pcSPS                         ( NULL )
69, m_pcPPS                         ( NULL )
70, m_pcPic                         ( NULL )
71, m_colFromL0Flag                 ( 1 )
72, m_colRefIdx                     ( 0 )
73, m_uiTLayer                      ( 0 )
74, m_bTLayerSwitchingFlag          ( false )
75, m_sliceMode                   ( 0 )
76, m_sliceArgument               ( 0 )
77, m_sliceCurStartCUAddr         ( 0 )
78, m_sliceCurEndCUAddr           ( 0 )
79, m_sliceIdx                    ( 0 )
80, m_sliceSegmentMode            ( 0 )
81, m_sliceSegmentArgument        ( 0 )
82, m_sliceSegmentCurStartCUAddr  ( 0 )
83, m_sliceSegmentCurEndCUAddr    ( 0 )
84, m_nextSlice                    ( false )
85, m_nextSliceSegment             ( false )
86, m_sliceBits                   ( 0 )
87, m_sliceSegmentBits         ( 0 )
88, m_bFinalized                    ( false )
89, m_uiTileOffstForMultES          ( 0 )
90, m_puiSubstreamSizes             ( NULL )
91, m_cabacInitFlag                 ( false )
92, m_bLMvdL1Zero                   ( false )
93, m_numEntryPointOffsets          ( 0 )
94, m_temporalLayerNonReferenceFlag ( false )
95, m_enableTMVPFlag                ( true )
96#if H_MV
97, m_refPicSetInterLayer0           ( NULL )
98, m_refPicSetInterLayer1           ( NULL )
99, m_layerId                       (0)
100, m_viewId                        (0)
101, m_viewIndex                     (0)
102#if H_3D
103, m_isDepth                       (false)
104#endif
105#if !H_MV_HLS7_GEN
106, m_pocResetFlag                  (false)
107#endif
108#if H_MV
109, m_crossLayerBlaFlag             (false)
110#endif
111, m_discardableFlag               (false)
112, m_interLayerPredEnabledFlag     (false)
113, m_numInterLayerRefPicsMinus1    (0)
114#if H_3D_IC
115, m_bApplyIC                      ( false )
116, m_icSkipParseFlag               ( false )
117#endif
118#if H_3D
119, m_depthToDisparityB             ( NULL )
120, m_depthToDisparityF             ( NULL )
121#endif
122#endif
123{
124  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
125 
126  initEqualRef();
127 
128  for (Int component = 0; component < 3; component++)
129  {
130    m_lambdas[component] = 0.0;
131  }
132 
133  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
134  {
135    m_list1IdxToList0Idx[idx] = -1;
136  }
137  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
138  {
139    m_apcRefPicList [0][iNumCount] = NULL;
140    m_apcRefPicList [1][iNumCount] = NULL;
141    m_aiRefPOCList  [0][iNumCount] = 0;
142    m_aiRefPOCList  [1][iNumCount] = 0;
143#if H_MV
144    m_aiRefLayerIdList[0][iNumCount] = 0;
145    m_aiRefLayerIdList[1][iNumCount] = 0;
146#endif
147  }
148  resetWpScaling();
149  initWpAcDcParam();
150  m_saoEnabledFlag = false;
151  m_saoEnabledFlagChroma = false;
152#if H_MV
153  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
154  {
155    m_interLayerPredLayerIdc[ i ] = -1;
156  }
157#endif
158}
159
160TComSlice::~TComSlice()
161{
162  delete[] m_puiSubstreamSizes;
163  m_puiSubstreamSizes = NULL;
164#if H_3D
165  for( UInt i = 0; i < getViewIndex(); i++ )
166  {
167    if ( m_depthToDisparityB && m_depthToDisparityB[ i ] )
168    {
169      delete[] m_depthToDisparityB [ i ];
170    }
171
172    if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) 
173    {
174      delete[] m_depthToDisparityF [ i ];
175  }
176  }
177
178  if ( m_depthToDisparityF )
179  {
180    delete[] m_depthToDisparityF; 
181  }
182
183  m_depthToDisparityF = NULL;
184
185  if ( m_depthToDisparityB )
186    delete[] m_depthToDisparityB; 
187
188  m_depthToDisparityB = NULL;
189#endif
190}
191
192
193Void TComSlice::initSlice()
194{
195  m_aiNumRefIdx[0]      = 0;
196  m_aiNumRefIdx[1]      = 0;
197 
198  m_colFromL0Flag = 1;
199 
200  m_colRefIdx = 0;
201  initEqualRef();
202  m_bCheckLDC = false;
203  m_iSliceQpDeltaCb = 0;
204  m_iSliceQpDeltaCr = 0;
205
206#if H_3D_IV_MERGE
207  m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM;
208#else
209  m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
210#endif
211
212  m_bFinalized=false;
213
214  m_tileByteLocation.clear();
215  m_cabacInitFlag        = false;
216  m_numEntryPointOffsets = 0;
217  m_enableTMVPFlag = true;
218#if H_3D_TMVP
219  m_aiAlterRefIdx[0]                  = -1;
220  m_aiAlterRefIdx[1]                  = -1;
221#endif
222}
223
224Bool TComSlice::getRapPicFlag()
225{
226  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
227      || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
228      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
229      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
230      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
231      || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
232}
233
234/**
235 - allocate table to contain substream sizes to be written to the slice header.
236 .
237 \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1.
238 */
239Void  TComSlice::allocSubstreamSizes(UInt uiNumSubstreams)
240{
241  delete[] m_puiSubstreamSizes;
242  m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0];
243}
244
245Void  TComSlice::sortPicList        (TComList<TComPic*>& rcListPic)
246{
247  TComPic*    pcPicExtract;
248  TComPic*    pcPicInsert;
249 
250  TComList<TComPic*>::iterator    iterPicExtract;
251  TComList<TComPic*>::iterator    iterPicExtract_1;
252  TComList<TComPic*>::iterator    iterPicInsert;
253 
254  for (Int i = 1; i < (Int)(rcListPic.size()); i++)
255  {
256    iterPicExtract = rcListPic.begin();
257    for (Int j = 0; j < i; j++) iterPicExtract++;
258    pcPicExtract = *(iterPicExtract);
259    pcPicExtract->setCurrSliceIdx(0);
260   
261    iterPicInsert = rcListPic.begin();
262    while (iterPicInsert != iterPicExtract)
263    {
264      pcPicInsert = *(iterPicInsert);
265      pcPicInsert->setCurrSliceIdx(0);
266      if (pcPicInsert->getPOC() >= pcPicExtract->getPOC())
267      {
268        break;
269      }
270     
271      iterPicInsert++;
272    }
273   
274    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
275   
276    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
277    rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1);
278    rcListPic.erase  (iterPicExtract);
279  }
280}
281
282TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic,
283                                Int                 poc)
284{
285  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
286  TComPic*                      pcPic = *(iterPic);
287  while ( iterPic != rcListPic.end() )
288  {
289    if(pcPic->getPOC() == poc)
290    {
291      break;
292    }
293    iterPic++;
294    pcPic = *(iterPic);
295  }
296  return  pcPic;
297}
298
299
300TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
301{
302  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
303  TComPic*                      pcPic = *(iterPic);
304  TComPic*                      pcStPic = pcPic;
305 
306  Int pocCycle = 1 << getSPS()->getBitsForPOC();
307  if (!pocHasMsb)
308  {
309    poc = poc & (pocCycle - 1);
310  }
311 
312  while ( iterPic != rcListPic.end() )
313  {
314    pcPic = *(iterPic);
315    if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced())
316    {
317      Int picPoc = pcPic->getPOC();
318      if (!pocHasMsb)
319      {
320        picPoc = picPoc & (pocCycle - 1);
321      }
322     
323      if (poc == picPoc)
324    {
325      if(pcPic->getIsLongTerm())
326      {
327        return pcPic;
328      }
329      else
330      {
331        pcStPic = pcPic;
332      }
333      break;
334    }
335    }
336
337    iterPic++;
338  }
339 
340  return  pcStPic;
341}
342
343Void TComSlice::setRefPOCList       ()
344{
345  for (Int iDir = 0; iDir < 2; iDir++)
346  {
347    for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
348    {
349      m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
350#if H_MV
351      m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId();
352#endif
353    }
354  }
355
356}
357
358Void TComSlice::setList1IdxToList0Idx()
359{
360  Int idxL0, idxL1;
361  for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ )
362  {
363    m_list1IdxToList0Idx[idxL1] = -1;
364    for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ )
365    {
366      if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
367      {
368        m_list1IdxToList0Idx[idxL1] = idxL0;
369        break;
370      }
371    }
372  }
373}
374
375#if !H_MV
376Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
377{
378  if (!checkNumPocTotalCurr)
379  {
380    if (m_eSliceType == I_SLICE)
381    {
382      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
383      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
384
385      return;
386    }
387
388    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
389    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
390  }
391
392  TComPic*  pcRefPic= NULL;
393  TComPic*  RefPicSetStCurr0[16];
394  TComPic*  RefPicSetStCurr1[16];
395  TComPic*  RefPicSetLtCurr[16];
396  UInt NumPocStCurr0 = 0;
397  UInt NumPocStCurr1 = 0;
398  UInt NumPocLtCurr = 0;
399  Int i;
400
401  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
402  {
403    if(m_pcRPS->getUsed(i))
404    {
405      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
406      pcRefPic->setIsLongTerm(0);
407      pcRefPic->getPicYuvRec()->extendPicBorder();
408      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
409      NumPocStCurr0++;
410      pcRefPic->setCheckLTMSBPresent(false); 
411    }
412  }
413
414  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
415  {
416    if(m_pcRPS->getUsed(i))
417    {
418      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
419      pcRefPic->setIsLongTerm(0);
420      pcRefPic->getPicYuvRec()->extendPicBorder();
421      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
422      NumPocStCurr1++;
423      pcRefPic->setCheckLTMSBPresent(false); 
424    }
425  }
426
427  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
428  {
429    if(m_pcRPS->getUsed(i))
430    {
431      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
432      pcRefPic->setIsLongTerm(1);
433      pcRefPic->getPicYuvRec()->extendPicBorder();
434      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
435      NumPocLtCurr++;
436    }
437    if(pcRefPic==NULL) 
438    {
439      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
440    }
441    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
442  }
443
444  // ref_pic_list_init
445  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
446  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
447  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
448  if (checkNumPocTotalCurr)
449  {
450    // 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:
451    // ?If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
452    // ?Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
453    if (getRapPicFlag())
454    {
455      assert(numPocTotalCurr == 0);
456    }
457
458    if (m_eSliceType == I_SLICE)
459    {
460      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
461      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
462
463      return;
464    }
465
466    assert(numPocTotalCurr > 0);
467
468    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
469    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
470  }
471
472  Int cIdx = 0;
473  for ( i=0; i<NumPocStCurr0; i++, cIdx++)
474  {
475    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
476  }
477  for ( i=0; i<NumPocStCurr1; i++, cIdx++)
478  {
479    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
480  }
481  for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
482  {
483    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
484  }
485  assert(cIdx == numPocTotalCurr);
486
487  if (m_eSliceType==B_SLICE)
488  {
489    cIdx = 0;
490    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
491    {
492      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
493    }
494    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
495    {
496      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
497    }
498    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
499    {
500      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
501    }
502    assert(cIdx == numPocTotalCurr);
503  }
504
505  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
506
507  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
508  {
509    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
510    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
511    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
512    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
513  }
514  if ( m_eSliceType != B_SLICE )
515  {
516    m_aiNumRefIdx[1] = 0;
517    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
518  }
519  else
520  {
521    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
522    {
523      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
524      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
525      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
526      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
527    }
528  }
529}
530
531#else
532Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
533                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr )
534{
535  if (!checkNumPocTotalCurr)
536  {
537    if (m_eSliceType == I_SLICE)
538    {     
539      return;
540    }   
541  }
542
543  TComPic*  pcRefPic= NULL;
544  TComPic*  RefPicSetStCurr0[16];
545  TComPic*  RefPicSetStCurr1[16];
546  TComPic*  RefPicSetLtCurr[16];
547  UInt NumPocStCurr0 = 0;
548  UInt NumPocStCurr1 = 0;
549  UInt NumPocLtCurr = 0;
550  Int i;
551
552  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
553  {
554    if(m_pcRPS->getUsed(i))
555    {
556      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
557      pcRefPic->setIsLongTerm(0);
558      pcRefPic->getPicYuvRec()->extendPicBorder();
559      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
560      NumPocStCurr0++;
561      pcRefPic->setCheckLTMSBPresent(false); 
562    }
563  }
564 
565  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
566  {
567    if(m_pcRPS->getUsed(i))
568    {
569      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
570      pcRefPic->setIsLongTerm(0);
571      pcRefPic->getPicYuvRec()->extendPicBorder();
572      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
573      NumPocStCurr1++;
574      pcRefPic->setCheckLTMSBPresent(false); 
575    }
576  }
577 
578  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
579  {
580    if(m_pcRPS->getUsed(i))
581    {
582      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
583      pcRefPic->setIsLongTerm(1);
584      pcRefPic->getPicYuvRec()->extendPicBorder();
585      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
586      NumPocLtCurr++;
587    }
588    if(pcRefPic==NULL) 
589    {
590      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
591    }
592    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
593  }
594
595  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 
596  numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( );
597  assert( numPocTotalCurr == getNumRpsCurrTempList() );
598
599  if (checkNumPocTotalCurr)
600  {
601    // 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:
602    // - 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.
603    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
604    if ( getRapPicFlag() && m_layerId == 0 )
605    {
606      assert(numPocTotalCurr == 0);
607    }
608
609    if (m_eSliceType == I_SLICE)
610    {
611      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
612      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
613     
614      return;
615    }
616   
617    assert(numPocTotalCurr > 0);
618   
619    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
620    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
621  }
622
623  std::vector<TComPic*>* refPicSetInterLayer[2] = { &refPicSetInterLayer0, &refPicSetInterLayer1}; 
624  Int numPocInterLayer[2] = { getNumActiveRefLayerPics0( ), getNumActiveRefLayerPics1( ) }; 
625 
626  TComPic**             refPicSetStCurr    [2] = { RefPicSetStCurr0, RefPicSetStCurr1 };
627  Int numPocStCurr[2] = { NumPocStCurr0, NumPocStCurr1 }; 
628
629  for (Int li = 0; li < ((m_eSliceType==B_SLICE) ? 2 : 1); li++)
630  { 
631    rpsCurrList   [li].resize(MAX_NUM_REF+1,NULL ); 
632    usedAsLongTerm[li].resize(MAX_NUM_REF+1,false); 
633
634    Int cIdx = 0;
635    for ( i=0; i < numPocStCurr[li]; i++, cIdx++)
636    {
637      rpsCurrList[li][cIdx] = refPicSetStCurr[li][i];
638      usedAsLongTerm [li][cIdx] = false; 
639    }
640
641    for ( i=0; i < numPocInterLayer[li];  i++, cIdx++)
642    {   
643      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[li])[i];
644      usedAsLongTerm [li][cIdx] = true; 
645    }
646
647    for ( i=0; i < numPocStCurr[1-li]; i++, cIdx++)
648    {
649      rpsCurrList[li][cIdx] = refPicSetStCurr[1-li][i];
650      usedAsLongTerm [li][cIdx] = false; 
651    }
652
653    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
654    {
655      rpsCurrList[li][cIdx] = RefPicSetLtCurr[i];
656      usedAsLongTerm [li][cIdx] = true; 
657    }
658
659    for ( i=0; i < numPocInterLayer[1-li];  i++, cIdx++)
660    {   
661      assert( cIdx < MAX_NUM_REF );   
662      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[1-li])[i];
663      usedAsLongTerm [li][cIdx] = true; 
664    }
665
666    assert(cIdx == numPocTotalCurr);
667  }
668}
669
670Void TComSlice::setRefPicList( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr )
671
672{
673  if (!checkNumPocTotalCurr)
674  {
675    if (m_eSliceType == I_SLICE)
676    {
677      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
678      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
679
680      return;
681    }   
682  }
683
684  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
685
686  for (Int li = 0; li < 2; li++)
687  {
688    if ( m_eSliceType == P_SLICE && li == 1 )
689    {
690      m_aiNumRefIdx[1] = 0;
691      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
692    } 
693    else
694    {
695      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
696      { 
697        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li ); 
698        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); 
699
700        assert( rpsCurrList[li][ orgIdx ] != NULL ); 
701        m_apcRefPicList    [li][rIdx] = rpsCurrList    [li][ orgIdx ];
702        m_bIsUsedAsLongTerm[li][rIdx] = usedAsLongTerm [li][ orgIdx ] ; 
703      }
704    }
705  }
706}
707#endif
708Int TComSlice::getNumRpsCurrTempList()
709{
710  Int numRpsCurrTempList = 0;
711
712  if (m_eSliceType == I_SLICE) 
713  {
714    return 0;
715  }
716  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
717  {
718    if(m_pcRPS->getUsed(i))
719    {
720      numRpsCurrTempList++;
721    }
722  }
723#if H_MV
724  numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
725#endif
726  return numRpsCurrTempList;
727}
728
729Void TComSlice::initEqualRef()
730{
731  for (Int iDir = 0; iDir < 2; iDir++)
732  {
733    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
734    {
735      for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
736      {
737        m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
738      }
739    }
740  }
741}
742#if H_3D
743#if H_3D_TMVP
744Void TComSlice::generateAlterRefforTMVP()
745{
746  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
747  {       
748    if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0)
749    {
750        continue;
751    }
752    Bool bZeroIdxLtFlag = this->getRefPic(RefPicList(uiRefListIdx), 0)->getIsLongTerm();
753    for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ )
754    {
755      if ( ( bZeroIdxLtFlag && !this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) ||
756           (!bZeroIdxLtFlag &&  this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) )
757      {
758        this->setAlterRefIdx(RefPicList(uiRefListIdx),i);
759        break;
760      }
761    }
762  }
763}
764#endif
765Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset )
766{ 
767  if( m_pcVPS->hasCamParInSliceHeader( m_viewIndex ) )
768  {   
769    for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < m_viewIndex; uiBaseViewIndex++ )
770    {
771      m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][     m_viewIndex ];
772      m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [     m_viewIndex ][ uiBaseViewIndex ];
773      m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][     m_viewIndex ];
774      m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[     m_viewIndex ][ uiBaseViewIndex ];
775    }
776  } 
777}
778#endif
779
780Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic)
781{
782  Int i;
783  TComSlice* curSlice = pic->getSlice(curSliceIdx);
784  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
785  TComSlice* preSlice;
786  Int preColRefPOC;
787  for(i=curSliceIdx-1; i>=0; i--)
788  {
789    preSlice = pic->getSlice(i);
790    if(preSlice->getSliceType() != I_SLICE)
791    {
792      preColRefPOC  = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
793      if(currColRefPOC != preColRefPOC)
794      {
795        printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n");
796        exit(EXIT_FAILURE);
797      }
798      else
799      {
800        break;
801      }
802    }
803  }
804}
805
806Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
807{
808  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
809  {
810    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
811    {
812      assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA);
813    }
814  }
815  for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++)
816  {
817    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
818    {
819      if (!pReferencePictureSet->getCheckLTMSBPresent(i))
820      {
821        assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA);
822      }
823      else
824      {
825      assert(pReferencePictureSet->getPOC(i) >= pocCRA);
826    }
827  }
828  }
829  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
830  {
831    pocCRA = getPOC();
832    associatedIRAPType = getNalUnitType();
833  }
834  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
835  {
836    pocCRA = getPOC();
837    associatedIRAPType = getNalUnitType();
838  }
839  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
840         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
841         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
842  {
843    pocCRA = getPOC();
844    associatedIRAPType = getNalUnitType();
845  }
846}
847
848/** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered.
849 * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture
850 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
851 * \param rcListPic reference to the reference picture list
852 * This function marks the reference pictures as "unused for reference" in the following conditions.
853 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list 
854 * are marked as "unused for reference"
855 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
856 * Otherwise
857 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
858 *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA),
859 *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set
860 *    the bRefreshPending flag to false.
861 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
862 *    reference of the current picture.
863 * Note that the current picture is already placed in the reference list and its marking is not changed.
864 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
865 */
866Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic)
867{
868  TComPic*                 rpcPic;
869#if !FIX1172
870  setAssociatedIRAPPOC(pocCRA);
871#endif
872  Int pocCurr = getPOC(); 
873
874  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
875    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
876    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
877    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
878    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
879  {
880    // mark all pictures as not used for reference
881    TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
882    while (iterPic != rcListPic.end())
883    {
884      rpcPic = *(iterPic);
885      rpcPic->setCurrSliceIdx(0);
886      if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
887      iterPic++;
888    }
889    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
890      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
891      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
892    {
893      pocCRA = pocCurr;
894    }
895  }
896  else // CRA or No DR
897  {
898    if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
899    {
900      TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
901      while (iterPic != rcListPic.end())
902      {
903        rpcPic = *(iterPic);
904        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
905        {
906          rpcPic->getSlice(0)->setReferenced(false);
907        }
908        iterPic++;
909      }
910      bRefreshPending = false; 
911    }
912    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
913    {
914      bRefreshPending = true; 
915      pocCRA = pocCurr;
916    }
917  }
918}
919
920Void TComSlice::copySliceInfo(TComSlice *pSrc)
921{
922  assert( pSrc != NULL );
923
924  Int i, j, k;
925
926  m_iPOC                 = pSrc->m_iPOC;
927  m_eNalUnitType         = pSrc->m_eNalUnitType;
928#if H_MV
929  m_layerId              = pSrc->m_layerId;
930  // GT: Copying of several other values might be be missing here, or is above not necessary?
931#endif
932  m_eSliceType           = pSrc->m_eSliceType;
933  m_iSliceQp             = pSrc->m_iSliceQp;
934#if ADAPTIVE_QP_SELECTION
935  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
936#endif
937  m_deblockingFilterDisable   = pSrc->m_deblockingFilterDisable;
938  m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag;
939  m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2;
940  m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
941 
942  for (i = 0; i < 2; i++)
943  {
944    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
945  }
946
947  for (i = 0; i < MAX_NUM_REF; i++)
948  {
949    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
950  } 
951  m_bCheckLDC             = pSrc->m_bCheckLDC;
952  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
953  m_iSliceQpDeltaCb      = pSrc->m_iSliceQpDeltaCb;
954  m_iSliceQpDeltaCr      = pSrc->m_iSliceQpDeltaCr;
955  for (i = 0; i < 2; i++)
956  {
957    for (j = 0; j < MAX_NUM_REF; j++)
958    {
959      m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
960      m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
961#if H_MV
962      m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j];
963#endif
964    }
965  }
966  for (i = 0; i < 2; i++)
967  {
968    for (j = 0; j < MAX_NUM_REF + 1; j++)
969    {
970      m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
971    }
972  }
973  m_iDepth               = pSrc->m_iDepth;
974
975  // referenced slice
976  m_bRefenced            = pSrc->m_bRefenced;
977
978  // access channel
979#if H_MV
980  m_pcVPS                = pSrc->m_pcVPS;
981#endif
982  m_pcSPS                = pSrc->m_pcSPS;
983  m_pcPPS                = pSrc->m_pcPPS;
984  m_pcRPS                = pSrc->m_pcRPS;
985  m_iLastIDR             = pSrc->m_iLastIDR;
986
987  m_pcPic                = pSrc->m_pcPic;
988
989  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
990  m_colRefIdx            = pSrc->m_colRefIdx;
991  setLambdas(pSrc->getLambdas());
992  for (i = 0; i < 2; i++)
993  {
994    for (j = 0; j < MAX_NUM_REF; j++)
995    {
996      for (k =0; k < MAX_NUM_REF; k++)
997      {
998        m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k];
999      }
1000    }
1001  }
1002
1003  m_uiTLayer                      = pSrc->m_uiTLayer;
1004  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
1005
1006  m_sliceMode                   = pSrc->m_sliceMode;
1007  m_sliceArgument               = pSrc->m_sliceArgument;
1008  m_sliceCurStartCUAddr         = pSrc->m_sliceCurStartCUAddr;
1009  m_sliceCurEndCUAddr           = pSrc->m_sliceCurEndCUAddr;
1010  m_sliceIdx                    = pSrc->m_sliceIdx;
1011  m_sliceSegmentMode            = pSrc->m_sliceSegmentMode;
1012  m_sliceSegmentArgument        = pSrc->m_sliceSegmentArgument; 
1013  m_sliceSegmentCurStartCUAddr  = pSrc->m_sliceSegmentCurStartCUAddr;
1014  m_sliceSegmentCurEndCUAddr    = pSrc->m_sliceSegmentCurEndCUAddr;
1015  m_nextSlice                    = pSrc->m_nextSlice;
1016  m_nextSliceSegment             = pSrc->m_nextSliceSegment;
1017  for ( Int e=0 ; e<2 ; e++ )
1018  {
1019    for ( Int n=0 ; n<MAX_NUM_REF ; n++ )
1020    {
1021      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 );
1022    }
1023  }
1024  m_saoEnabledFlag = pSrc->m_saoEnabledFlag; 
1025  m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
1026  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
1027  m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
1028
1029  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
1030  m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag;
1031  m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
1032  m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
1033
1034#if H_MV
1035  // Additional slice header syntax elements
1036#if !H_MV_HLS7_GEN
1037  m_pocResetFlag               = pSrc->m_pocResetFlag; 
1038#endif
1039  m_discardableFlag            = pSrc->m_discardableFlag; 
1040  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
1041  m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1;
1042
1043  for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ )
1044  {
1045    m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; 
1046  }
1047#endif
1048#if H_3D_IC
1049  m_bApplyIC = pSrc->m_bApplyIC;
1050  m_icSkipParseFlag = pSrc->m_icSkipParseFlag;
1051#endif
1052}
1053
1054Int TComSlice::m_prevTid0POC = 0;
1055
1056/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
1057 * \param uiTLayer Temporal layer ID of the current slice
1058 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
1059 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
1060 * temporal_layer_switching_point_flag is set accordingly.
1061 */
1062Void TComSlice::setTLayerInfo( UInt uiTLayer )
1063{
1064  m_uiTLayer = uiTLayer;
1065}
1066
1067/** Function for checking if this is a switching-point
1068*/
1069Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic )
1070{
1071  TComPic* rpcPic;
1072  // loop through all pictures in the reference picture buffer
1073  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1074  while ( iterPic != rcListPic.end())
1075  {
1076    rpcPic = *(iterPic++);
1077    if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC())
1078    {
1079      if(rpcPic->getTLayer() >= getTLayer())
1080      {
1081        return false;
1082      }
1083    }
1084  }
1085  return true;
1086}
1087
1088/** Function for checking if this is a STSA candidate
1089 */
1090Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic )
1091{
1092    TComPic* rpcPic;
1093   
1094    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1095    while ( iterPic != rcListPic.end())
1096    {
1097        rpcPic = *(iterPic++);
1098        if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
1099        {
1100            if(rpcPic->getTLayer() >= getTLayer())
1101            {
1102                return false;
1103            }
1104        }
1105    }
1106    return true;
1107}
1108
1109
1110Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
1111{
1112  TComPic* rpcPic;
1113
1114  Int nalUnitType = this->getNalUnitType();
1115
1116  // When a picture is a leading picture, it shall be a RADL or RASL picture.
1117  if(this->getAssociatedIRAPPOC() > this->getPOC())
1118  {
1119    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
1120    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
1121       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
1122    {
1123      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1124             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
1125             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1126             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
1127    }
1128  }
1129
1130  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
1131  if(this->getAssociatedIRAPPOC() < this->getPOC())
1132  {
1133    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
1134           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
1135           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
1136           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
1137  }
1138
1139  // No RASL pictures shall be present in the bitstream that are associated
1140  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
1141  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1142     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1143  {
1144    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
1145           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
1146  }
1147
1148  // No RASL pictures shall be present in the bitstream that are associated with
1149  // an IDR picture.
1150  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1151     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1152  {
1153    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
1154           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
1155  }
1156
1157  // No RADL pictures shall be present in the bitstream that are associated with
1158  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
1159  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
1160  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1161     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
1162  {
1163    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
1164           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
1165  }
1166
1167  // loop through all pictures in the reference picture buffer
1168  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1169  while ( iterPic != rcListPic.end())
1170  {
1171    rpcPic = *(iterPic++);
1172#if BUGFIX_INTRAPERIOD
1173    if(!rpcPic->getReconMark())
1174    {
1175      continue;
1176    }
1177#endif
1178    if (rpcPic->getPOC() == this->getPOC())
1179    {
1180      continue;
1181    }
1182
1183    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
1184    // in decoding order shall precede the IRAP picture in output order.
1185    // (Note that any picture following in output order would be present in the DPB)
1186    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
1187    {
1188      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
1189         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
1190         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
1191         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
1192         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
1193         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
1194      {
1195        assert(rpcPic->getPOC() < this->getPOC());
1196      }
1197    }
1198
1199    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
1200    // in decoding order shall precede any RADL picture associated with the IRAP
1201    // picture in output order.
1202    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
1203    {
1204      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1205          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
1206      {
1207        // rpcPic precedes the IRAP in decoding order
1208        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
1209        {
1210          // rpcPic must not be the IRAP picture
1211          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
1212          {
1213            assert(rpcPic->getPOC() < this->getPOC());
1214          }
1215        }
1216      }
1217    }
1218
1219    // When a picture is a leading picture, it shall precede, in decoding order,
1220    // all trailing pictures that are associated with the same IRAP picture.
1221    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1222       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
1223       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1224       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
1225    {
1226      if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
1227      {
1228        // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
1229        // rpcPic would violate the constraint if it was a trailing picture
1230        assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
1231      }
1232    }
1233
1234    // Any RASL picture associated with a CRA or BLA picture shall precede any
1235    // RADL picture associated with the CRA or BLA picture in output order
1236    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1237       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1238    { 
1239      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
1240          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
1241          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
1242          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
1243          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
1244      {
1245        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
1246           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
1247        {
1248          assert(rpcPic->getPOC() > this->getPOC());
1249        }
1250      }
1251    }
1252
1253    // Any RASL picture associated with a CRA picture shall follow, in output
1254    // order, any IRAP picture that precedes the CRA picture in decoding order.
1255    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1256       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1257    {
1258      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
1259      {
1260        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
1261           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
1262            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
1263            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
1264            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
1265            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
1266            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
1267        {
1268          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
1269        }
1270      }
1271    }
1272  }
1273}
1274
1275
1276
1277/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1278*/
1279Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
1280{
1281  TComPic* rpcPic;
1282  Int i, isReference;
1283
1284  checkLeadingPictureRestrictions(rcListPic);
1285
1286  // loop through all pictures in the reference picture buffer
1287  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1288  while ( iterPic != rcListPic.end())
1289  {
1290    rpcPic = *(iterPic++);
1291
1292    if(!rpcPic->getSlice( 0 )->isReferenced())
1293    {
1294      continue;
1295    }
1296
1297    isReference = 0;
1298    // loop through all pictures in the Reference Picture Set
1299    // to see if the picture should be kept as reference picture
1300    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
1301    {
1302      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
1303      {
1304        isReference = 1;
1305        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1306        rpcPic->setIsLongTerm(0);
1307      }
1308    }
1309    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
1310    {
1311      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1312      {
1313        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i))
1314        {
1315          isReference = 1;
1316          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1317        }
1318      }
1319      else 
1320      {
1321        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1322        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1323        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1324        if(rpcPic->getIsLongTerm() && curPoc == refPoc)
1325        {
1326          isReference = 1;
1327          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1328        }
1329      }
1330
1331    }
1332#if H_MV_HLS_7_MISC_P0130_20
1333    if( isReference ) // Current picture is in the temporal RPS
1334    {
1335      assert( rpcPic->getSlice(0)->getDiscardableFlag() == 0 ); // Temporal RPS shall not contain picture with discardable_flag equal to 1
1336    }
1337#endif
1338    // mark the picture as "unused for reference" if it is not in
1339    // the Reference Picture Set
1340    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
1341    {           
1342      rpcPic->getSlice( 0 )->setReferenced( false );   
1343      rpcPic->setUsedByCurr(0);
1344      rpcPic->setIsLongTerm(0);
1345    }
1346    //check that pictures of higher temporal layers are not used
1347    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
1348    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
1349    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
1350    {
1351      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
1352    }
1353    //check that pictures marked as temporal layer non-reference pictures are not used for reference
1354    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
1355    {
1356      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false);
1357    }
1358  }
1359}
1360
1361/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1362*/
1363Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
1364{
1365  TComPic* rpcPic;
1366  Int i, isAvailable;
1367  Int atLeastOneLost = 0;
1368  Int atLeastOneRemoved = 0;
1369  Int iPocLost = 0;
1370
1371  // loop through all long-term pictures in the Reference Picture Set
1372  // to see if the picture should be kept as reference picture
1373  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
1374  {
1375    isAvailable = 0;
1376    // loop through all pictures in the reference picture buffer
1377    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1378    while ( iterPic != rcListPic.end())
1379    {
1380      rpcPic = *(iterPic++);
1381      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1382      {
1383        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
1384        {
1385          isAvailable = 1;
1386        }
1387      }
1388      else 
1389      {
1390        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1391        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1392        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1393        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
1394        {
1395          isAvailable = 1;
1396        }
1397      }
1398    }
1399    // if there was no such long-term check the short terms
1400    if(!isAvailable)
1401    {
1402      iterPic = rcListPic.begin();
1403      while ( iterPic != rcListPic.end())
1404      {
1405        rpcPic = *(iterPic++);
1406
1407        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1408        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
1409        Int refPoc = pReferencePictureSet->getPOC(i);
1410        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
1411        {
1412          curPoc = curPoc & (pocCycle - 1);
1413          refPoc = refPoc & (pocCycle - 1);
1414        }
1415       
1416        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
1417        {
1418          isAvailable = 1;
1419          rpcPic->setIsLongTerm(1);
1420          break;
1421        }
1422      }
1423    }
1424    // report that a picture is lost if it is in the Reference Picture Set
1425    // but not available as reference picture
1426    if(isAvailable == 0)   
1427    {           
1428      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1429      {
1430        if(!pReferencePictureSet->getUsed(i) )
1431        {
1432          if(printErrors)
1433          {
1434            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1435          }
1436          atLeastOneRemoved = 1;
1437        }
1438        else
1439        {
1440          if(printErrors)
1441          {
1442            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1443          }
1444          atLeastOneLost = 1;
1445          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1446        }
1447      }
1448    }
1449  } 
1450  // loop through all short-term pictures in the Reference Picture Set
1451  // to see if the picture should be kept as reference picture
1452  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
1453  {
1454    isAvailable = 0;
1455    // loop through all pictures in the reference picture buffer
1456    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1457    while ( iterPic != rcListPic.end())
1458    {
1459      rpcPic = *(iterPic++);
1460
1461      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1462      {
1463        isAvailable = 1;
1464      }
1465    }
1466    // report that a picture is lost if it is in the Reference Picture Set
1467    // but not available as reference picture
1468    if(isAvailable == 0)   
1469    {           
1470      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1471      {
1472        if(!pReferencePictureSet->getUsed(i) )
1473        {
1474          if(printErrors)
1475          {
1476            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1477          }
1478          atLeastOneRemoved = 1;
1479        }
1480        else
1481        {
1482          if(printErrors)
1483          {
1484            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1485          }
1486          atLeastOneLost = 1;
1487          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1488        }
1489      }
1490    }
1491  }   
1492  if(atLeastOneLost)
1493  {
1494    return iPocLost+1;
1495  }
1496  if(atLeastOneRemoved)
1497  {
1498    return -2;
1499  }
1500  else
1501  {
1502    return 0;
1503  }
1504}
1505
1506/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1507*/
1508Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
1509{
1510  TComPic* rpcPic;
1511  Int i, j;
1512  Int k = 0;
1513  Int nrOfNegativePictures = 0;
1514  Int nrOfPositivePictures = 0;
1515  TComReferencePictureSet* pcRPS = this->getLocalRPS();
1516
1517  // loop through all pictures in the Reference Picture Set
1518  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1519  {
1520    j = 0;
1521    // loop through all pictures in the reference picture buffer
1522    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1523    while ( iterPic != rcListPic.end())
1524    {
1525      j++;
1526      rpcPic = *(iterPic++);
1527
1528      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1529      {
1530        // This picture exists as a reference picture
1531        // and should be added to the explicit Reference Picture Set
1532        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1533        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
1534        if(pcRPS->getDeltaPOC(k) < 0)
1535        {
1536          nrOfNegativePictures++;
1537        }
1538        else
1539        {
1540          nrOfPositivePictures++;
1541        }
1542        k++;
1543      }
1544    }
1545  }
1546  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1547  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1548  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1549  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1550  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1551  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1552  if (!pReferencePictureSet->getInterRPSPrediction())
1553  {
1554    pcRPS->setInterRPSPrediction(false);
1555    pcRPS->setNumRefIdc(0);
1556  }
1557  else
1558  {
1559    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1560    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1561    TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1562    Int iRefPics = pcRefRPS->getNumberOfPictures();
1563    Int iNewIdc=0;
1564    for(i=0; i<= iRefPics; i++) 
1565    {
1566      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1567      Int iRefIdc = 0;
1568      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1569      {
1570        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
1571        {
1572          if (pcRPS->getUsed(j))
1573          {
1574            iRefIdc = 1;
1575          }
1576          else
1577          {
1578            iRefIdc = 2;
1579          }
1580        }
1581      }
1582      pcRPS->setRefIdc(i, iRefIdc);
1583      iNewIdc++;
1584    }
1585    pcRPS->setInterRPSPrediction(true);
1586    pcRPS->setNumRefIdc(iNewIdc);
1587    pcRPS->setDeltaRPS(deltaRPS); 
1588    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1589  }
1590
1591  this->setRPS(pcRPS);
1592  this->setRPSidx(-1);
1593}
1594
1595/** get AC and DC values for weighted pred
1596 * \param *wp
1597 * \returns Void
1598 */
1599Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
1600{
1601  wp = m_weightACDCParam;
1602}
1603
1604/** init AC and DC values for weighted pred
1605 * \returns Void
1606 */
1607Void  TComSlice::initWpAcDcParam()
1608{
1609  for(Int iComp = 0; iComp < 3; iComp++ )
1610  {
1611    m_weightACDCParam[iComp].iAC = 0;
1612    m_weightACDCParam[iComp].iDC = 0;
1613  }
1614}
1615
1616/** get WP tables for weighted pred
1617 * \param RefPicList
1618 * \param iRefIdx
1619 * \param *&wpScalingParam
1620 * \returns Void
1621 */
1622Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
1623{
1624  wp = m_weightPredTable[e][iRefIdx];
1625}
1626
1627/** reset Default WP tables settings : no weight.
1628 * \param wpScalingParam
1629 * \returns Void
1630 */
1631Void  TComSlice::resetWpScaling()
1632{
1633  for ( Int e=0 ; e<2 ; e++ )
1634  {
1635    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1636    {
1637      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1638      {
1639        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1640        pwp->bPresentFlag      = false;
1641        pwp->uiLog2WeightDenom = 0;
1642        pwp->uiLog2WeightDenom = 0;
1643        pwp->iWeight           = 1;
1644        pwp->iOffset           = 0;
1645      }
1646    }
1647  }
1648}
1649
1650/** init WP table
1651 * \returns Void
1652 */
1653Void  TComSlice::initWpScaling()
1654{
1655  for ( Int e=0 ; e<2 ; e++ )
1656  {
1657    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1658    {
1659      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1660      {
1661        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1662        if ( !pwp->bPresentFlag ) 
1663        {
1664          // Inferring values not present :
1665          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1666          pwp->iOffset = 0;
1667        }
1668
1669        pwp->w      = pwp->iWeight;
1670        Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
1671        pwp->o      = pwp->iOffset << (bitDepth-8);
1672        pwp->shift  = pwp->uiLog2WeightDenom;
1673        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1674      }
1675    }
1676  }
1677}
1678
1679// ------------------------------------------------------------------------------------------------
1680// Video parameter set (VPS)
1681// ------------------------------------------------------------------------------------------------
1682TComVPS::TComVPS()
1683: m_VPSId                     (  0)
1684, m_uiMaxTLayers              (  1)
1685#if H_MV
1686, m_uiMaxLayersMinus1         (  0)
1687#else
1688, m_uiMaxLayers               (  1)
1689#endif
1690, m_bTemporalIdNestingFlag    (false)
1691, m_numHrdParameters          (  0)
1692#if H_MV
1693, m_maxLayerId             (  0)
1694#else
1695, m_maxNuhReservedZeroLayerId (  0)
1696#endif
1697, m_hrdParameters             (NULL)
1698, m_hrdOpSetIdx               (NULL)
1699, m_cprmsPresentFlag          (NULL)
1700#if H_MV
1701, m_dpbSize                   (NULL)
1702, m_vpsVUI                 (  NULL )
1703#endif
1704{
1705  for( Int i = 0; i < MAX_TLAYER; i++)
1706  {
1707    m_numReorderPics[i] = 0;
1708    m_uiMaxDecPicBuffering[i] = 1; 
1709    m_uiMaxLatencyIncrease[i] = 0;
1710  }
1711#if H_MV
1712  for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ )
1713  { 
1714    for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ )
1715    {
1716      m_layerIdIncludedFlag[lsIdx][layerId] = (( lsIdx == 0 ) && ( layerId == 0 )) ; 
1717    }
1718  } 
1719#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1720  m_vpsNumberLayerSetsMinus1     = -1; 
1721#endif
1722  m_vpsNumProfileTierLevelMinus1 = -1; 
1723   
1724#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1725  for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++)
1726  {
1727#if !H_MV_HLS_7_VPS_P0048_14
1728    m_profileRefMinus1[ i ] = -1; 
1729#endif
1730  }
1731   
1732  m_moreOutputLayerSetsThanDefaultFlag = false;   
1733  m_numAddOutputLayerSetsMinus1        = -1;   
1734  m_defaultOneTargetOutputLayerIdc     = 0; 
1735#else
1736  m_numAddOutputLayerSets              = -1;   
1737  m_defaultTargetOutputLayerIdc     = 0; 
1738#endif
1739 
1740  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
1741  {
1742    m_outputLayerSetIdxMinus1[i]  = -1; 
1743    m_profileLevelTierIdx[i]      = 0; 
1744    for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
1745    {
1746      m_outputLayerFlag[i][j] = false; 
1747    }
1748#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1749    m_altOutputLayerFlag[ i ]       = false; 
1750#endif
1751  }
1752#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1753  m_altOutputLayerFlag       = false; 
1754#endif
1755  m_maxOneActiveRefLayerFlag = false; 
1756  m_directDepTypeLenMinus2   = 0;         
1757 
1758
1759  m_avcBaseLayerFlag = false;
1760#if H_MV_HLS_7_VPS_P0307_23
1761  m_vpsNonVuiExtensionLength = 0;
1762#else
1763  m_vpsVuiOffset     = 0; 
1764#endif
1765  m_splittingFlag    = false;
1766 
1767  for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
1768  {
1769    m_scalabilityMaskFlag[i] = false;
1770    m_dimensionIdLen [i]  = -1; 
1771  }
1772
1773  m_vpsNuhLayerIdPresentFlag = false;
1774
1775  for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
1776  {
1777    m_vpsProfilePresentFlag   [i] = false;
1778#if !H_MV_HLS_7_VPS_P0048_14
1779    m_profileRefMinus1[i] = 0;
1780#endif
1781    m_outputLayerSetIdxMinus1       [i] = 0;
1782    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
1783    {
1784      m_outputLayerFlag[i][j] = false;
1785    }
1786  }
1787
1788  for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
1789  {
1790    m_layerIdInVps[i] =  (i == 0 ) ? 0 : -1;         
1791  }
1792
1793  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1794  {
1795    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
1796    m_numDirectRefLayers[i] = 0; 
1797    m_vpsRepFormatIdx    [i] = 0; 
1798    m_pocLsbNotPresentFlag[i] = 0;
1799    m_repFormat          [i] = NULL; 
1800    m_viewIdVal          [i] = 0; 
1801
1802#if H_3D
1803    m_viewIndex         [i] = -1; 
1804    m_vpsDepthModesFlag [i] = false;
1805    m_ivMvScalingFlag = true; 
1806#endif
1807
1808    for( Int j = 0; j < MAX_NUM_LAYERS; j++ )
1809    {
1810      m_directDependencyFlag[i][j] = false;
1811      m_directDependencyType[i][j] = -1; 
1812      m_refLayerId[i][j]           = -1; 
1813      m_maxTidIlRefPicsPlus1[i][j]  = 7;
1814    }
1815
1816    for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ )
1817    {
1818      m_dimensionId[i][j] = 0;
1819    }
1820#if H_3D_ARP
1821    m_uiUseAdvResPred[i]  = 0;
1822    m_uiARPStepNum[i]     = 1;
1823#endif
1824  }
1825  m_vpsVUI = new TComVPSVUI; 
1826  m_dpbSize = new TComDpbSize; 
1827
1828#if H_3D
1829  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1830  {
1831#if H_3D_IV_MERGE
1832    m_ivMvPredFlag         [ i ] = false;
1833#if H_3D_SPIVMP
1834    m_iSubPULog2Size       [ i ] = 0;
1835#endif
1836#endif
1837#if H_3D_VSP
1838    m_viewSynthesisPredFlag[ i ] = false;
1839#endif
1840#if H_3D_NBDV_REF
1841    m_depthRefinementFlag  [ i ] = false;
1842#endif
1843#if H_3D_INTER_SDC
1844    m_bInterSDCFlag        [ i ] = false;
1845#endif
1846#if H_3D_DBBP
1847    m_dbbpFlag             [ i ] = false;
1848#endif
1849#if H_3D_IV_MERGE
1850    m_bMPIFlag             [ i ] = false;
1851#endif
1852  } 
1853#endif
1854#endif
1855}
1856
1857TComVPS::~TComVPS()
1858{
1859  if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
1860  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
1861  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
1862#if H_MV
1863  if ( m_vpsVUI          != NULL )     delete m_vpsVUI; 
1864  if ( m_dpbSize         != NULL )     delete m_dpbSize; 
1865
1866  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1867  {
1868    if (m_repFormat[ i ] != NULL )      delete m_repFormat[ i ];   
1869  }
1870#endif
1871#if H_3D
1872  deleteCamPars();
1873#endif
1874}
1875
1876#if H_MV
1877
1878Bool TComVPS::checkVPSExtensionSyntax()
1879{
1880  for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
1881  {
1882    // check layer_id_in_nuh constraint
1883    assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
1884  }
1885  return true; 
1886}
1887
1888Int TComVPS::getNumScalabilityTypes()
1889{
1890  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
1891}
1892
1893Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
1894{
1895  assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
1896  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
1897  Int scalIdx = 0; 
1898  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
1899  {
1900    scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
1901
1902  }
1903
1904  return scalIdx; 
1905}
1906Void TComVPS::setScalabilityMaskFlag( UInt val )
1907{
1908  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
1909  {
1910    setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 );
1911  }
1912}
1913
1914Void TComVPS::setRefLayers()
1915{
1916  for( Int i = 0; i  <= getMaxLayersMinus1(); i++ )
1917  {
1918    Int iNuhLId = getLayerIdInNuh( i ); 
1919    m_numDirectRefLayers[ iNuhLId ] = 0; 
1920    for( Int j = 0; j < i; j++ )
1921    {
1922      if( getDirectDependencyFlag(i , j) )
1923      {
1924        m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j );
1925      }
1926    }
1927  }
1928}
1929
1930Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx )
1931{
1932  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] );     
1933  Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ];   
1934  assert ( refLayerIdInNuh >= 0 ); 
1935  return refLayerIdInNuh;
1936}
1937
1938Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
1939{
1940  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
1941}
1942
1943#if H_3D
1944Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
1945{
1946  Int foundLayerIdinNuh = -1; 
1947
1948  for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ )
1949  {
1950    Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); 
1951    if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) )  )
1952    {
1953      foundLayerIdinNuh = layerIdInNuh; 
1954      break; 
1955    }
1956  }
1957  assert( foundLayerIdinNuh != -1 ); 
1958
1959  return foundLayerIdinNuh;
1960}
1961
1962Void TComVPS::createCamPars(Int iNumViews)
1963{
1964  Int i = 0, j = 0;
1965
1966  m_bCamParPresent = new Bool[ iNumViews ];
1967  m_bCamParInSliceHeader = new Bool[ iNumViews ];
1968
1969  m_aaaiCodedScale = new Int**[ iNumViews ];
1970  m_aaaiCodedOffset = new Int**[ iNumViews ];
1971  for ( i = 0; i < iNumViews ; i++ )
1972  {
1973    m_bCamParInSliceHeader[i] = false; 
1974    m_aaaiCodedScale[i] = new Int*[ 2 ];
1975    m_aaaiCodedOffset[i] = new Int*[ 2 ];
1976    for ( j = 0; j < 2; j++ )
1977    {
1978      m_aaaiCodedScale[i][j] = new Int[ MAX_NUM_LAYERS ];
1979      m_aaaiCodedOffset[i][j] = new Int[ MAX_NUM_LAYERS ];
1980      for ( Int k = 0; k < MAX_NUM_LAYERS; k++ )
1981      {
1982        m_aaaiCodedScale[i][j][k] = 0;
1983        m_aaaiCodedOffset[i][j][k] = 0;
1984      }
1985    }
1986  }
1987}
1988
1989Void TComVPS::deleteCamPars()
1990{
1991  Int iNumViews = getNumViews();
1992  Int i = 0, j = 0;
1993
1994  if ( m_bCamParPresent != NULL )
1995  {
1996    delete [] m_bCamParPresent;
1997  }
1998  if ( m_bCamParInSliceHeader != NULL )
1999  {
2000    delete [] m_bCamParInSliceHeader;
2001  }
2002
2003  if ( m_aaaiCodedScale != NULL )
2004  {
2005    for ( i = 0; i < iNumViews ; i++ )
2006    {
2007      for ( j = 0; j < 2; j++ )
2008      {
2009        delete [] m_aaaiCodedScale[i][j];
2010      }
2011      delete [] m_aaaiCodedScale[i];
2012    }
2013    delete [] m_aaaiCodedScale;
2014  }
2015
2016  if ( m_aaaiCodedOffset != NULL )
2017  {
2018    for ( i = 0; i < iNumViews ; i++ )
2019    {
2020      for ( j = 0; j < 2; j++ )
2021      {
2022        delete [] m_aaaiCodedOffset[i][j];
2023      }
2024      delete [] m_aaaiCodedOffset[i];
2025    }
2026    delete [] m_aaaiCodedOffset;
2027  }
2028}
2029
2030
2031Void
2032  TComVPS::initCamParaVPS( UInt uiViewIndex, Bool bCamParPresent, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
2033{
2034  AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); 
2035
2036  m_uiCamParPrecision = ( ( uiViewIndex != 0 )? uiCamParPrecision : 0 );
2037  m_bCamParPresent[ uiViewIndex ] = (( uiViewIndex != 0 )? bCamParPresent  : false );
2038  m_bCamParInSliceHeader[ uiViewIndex ]  = ( (uiViewIndex != 0)? bCamParSlice  : false );
2039
2040  if( !m_bCamParInSliceHeader[ uiViewIndex ] )
2041  {
2042    for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
2043    {
2044      m_aaaiCodedScale [ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][     uiViewIndex ];
2045      m_aaaiCodedScale [ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiScale [     uiViewIndex ][ uiBaseViewIndex ];
2046      m_aaaiCodedOffset[ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][     uiViewIndex ];
2047      m_aaaiCodedOffset[ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiOffset[     uiViewIndex ][ uiBaseViewIndex ];
2048    }
2049  }
2050}
2051
2052#endif // H_3D
2053
2054
2055Int TComVPS::xGetDimBitOffset( Int j )
2056{
2057  Int dimBitOffset = 0; 
2058  if ( getSplittingFlag() && j == getNumScalabilityTypes() )
2059  {
2060     dimBitOffset = 6; 
2061  }
2062  else
2063  {
2064    for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++)
2065    {
2066      dimBitOffset += getDimensionIdLen( dimIdx ); 
2067    }
2068  }
2069  return dimBitOffset; 
2070}
2071
2072Int TComVPS::inferDimensionId( Int i, Int j )
2073{
2074    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); 
2075}
2076
2077Int TComVPS::inferLastDimsionIdLenMinus1()
2078{
2079  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); 
2080}
2081
2082Int TComVPS::getNumLayersInIdList( Int lsIdx )
2083{
2084  assert( lsIdx >= 0 ); 
2085  assert( lsIdx <= getVpsNumLayerSetsMinus1() ); 
2086  return (Int) m_layerSetLayerIdList[ lsIdx ].size(); 
2087}
2088
2089Int    TComVPS::getNumOutputLayerSets() 
2090{
2091#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
2092  return getNumAddOutputLayerSets() + getVpsNumLayerSetsMinus1() + 1; 
2093#else
2094  Int numOutputLayerSets = getVpsNumberLayerSetsMinus1( ) + 1; 
2095  if ( getMoreOutputLayerSetsThanDefaultFlag( ) )
2096  {     
2097    numOutputLayerSets += (getNumAddOutputLayerSetsMinus1( ) + 1); 
2098}
2099  return numOutputLayerSets; 
2100#endif
2101}
2102
2103Int TComVPS::getNumViews()
2104{
2105  Int numViews = 1; 
2106  for( Int i = 0; i <=  getMaxLayersMinus1(); i++ )
2107  {
2108    Int lId = getLayerIdInNuh( i ); 
2109    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
2110    {
2111      numViews++; 
2112    }   
2113  }
2114
2115  return numViews;
2116}
2117
2118Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ )
2119{
2120  assert( depth < 65 ); 
2121  Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); 
2122
2123  for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ )
2124  {
2125    if ( getDirectDependencyFlag( depLayeridInVps, i ) )
2126    {
2127      dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); 
2128    }
2129  }
2130  return dependentFlag;
2131}
2132
2133Void TComVPS::deriveLayerSetLayerIdList()
2134{
2135  m_layerSetLayerIdList.resize( getVpsNumLayerSetsMinus1() + 1 ); 
2136  for (Int i = 0; i <= getVpsNumLayerSetsMinus1(); i++ )
2137  {
2138    for( Int m = 0; m  <= getVpsMaxLayerId(); m++ )
2139    {
2140      if( getLayerIdIncludedFlag( i, m) ) 
2141      {
2142        m_layerSetLayerIdList[ i ].push_back( m );       
2143      }
2144    }
2145  }
2146}
2147
2148#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
2149Void TComVPS::initTargetLayerIdLists()
2150{
2151  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); 
2152  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); 
2153}
2154
2155Void TComVPS::deriveTargetLayerIdList( Int i )
2156{ 
2157  Int lsIdx = getLayerSetIdxForOutputLayerSet( i );     
2158 
2159  for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
2160  {
2161    m_targetDecLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); 
2162    if( getOutputLayerFlag( i, j  ))
2163    {
2164      m_targetOptLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
2165    }
2166  } 
2167}
2168#else
2169Void TComVPS::deriveTargetLayerIdLists()
2170{
2171  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); 
2172  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); 
2173
2174  for (Int targetOptLayerSetIdx = 0; targetOptLayerSetIdx < getNumOutputLayerSets(); targetOptLayerSetIdx++ )
2175  {
2176    Int targetDecLayerSetIdx = getOutputLayerSetIdxMinus1( targetOptLayerSetIdx ) + 1;     
2177    Int lsIdx                = targetDecLayerSetIdx;
2178
2179    for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
2180    {
2181      m_targetDecLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); 
2182      if( getOutputLayerFlag( targetOptLayerSetIdx, j  )) // This seems to be wrong in draft text
2183      {
2184        m_targetOptLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
2185      }
2186    } 
2187  }
2188}
2189#endif
2190
2191#endif // H_MV
2192
2193// ------------------------------------------------------------------------------------------------
2194// Sequence parameter set (SPS)
2195// ------------------------------------------------------------------------------------------------
2196
2197TComSPS::TComSPS()
2198: m_SPSId                     (  0)
2199, m_VPSId                     (  0)
2200, m_chromaFormatIdc           (CHROMA_420)
2201, m_uiMaxTLayers              (  1)
2202// Structure
2203, m_picWidthInLumaSamples     (352)
2204, m_picHeightInLumaSamples    (288)
2205, m_log2MinCodingBlockSize    (  0)
2206, m_log2DiffMaxMinCodingBlockSize (0)
2207, m_uiMaxCUWidth              ( 32)
2208, m_uiMaxCUHeight             ( 32)
2209, m_uiMaxCUDepth              (  3)
2210, m_bLongTermRefsPresent      (false)
2211, m_uiQuadtreeTULog2MaxSize   (  0)
2212, m_uiQuadtreeTULog2MinSize   (  0)
2213, m_uiQuadtreeTUMaxDepthInter (  0)
2214, m_uiQuadtreeTUMaxDepthIntra (  0)
2215// Tool list
2216, m_usePCM                   (false)
2217, m_pcmLog2MaxSize            (  5)
2218, m_uiPCMLog2MinSize          (  7)
2219#if H_3D_QTLPC
2220, m_bUseQTL                   (false)
2221, m_bUsePC                    (false)
2222#endif
2223, m_bitDepthY                 (  8)
2224, m_bitDepthC                 (  8)
2225, m_qpBDOffsetY               (  0)
2226, m_qpBDOffsetC               (  0)
2227, m_uiPCMBitDepthLuma         (  8)
2228, m_uiPCMBitDepthChroma       (  8)
2229, m_bPCMFilterDisableFlag     (false)
2230, m_uiBitsForPOC              (  8)
2231, m_numLongTermRefPicSPS    (  0) 
2232, m_uiMaxTrSize               ( 32)
2233, m_bUseSAO                   (false) 
2234, m_bTemporalIdNestingFlag    (false)
2235, m_scalingListEnabledFlag    (false)
2236, m_useStrongIntraSmoothing   (false)
2237, m_vuiParametersPresentFlag  (false)
2238, m_vuiParameters             ()
2239#if H_MV
2240, m_pcVPS                     ( NULL )
2241, m_spsInferScalingListFlag   ( false )
2242, m_spsScalingListRefLayerId  ( 0 )
2243
2244, m_updateRepFormatFlag       ( false ) 
2245, m_spsRepFormatIdx           ( 0 )
2246, m_interViewMvVertConstraintFlag (false)
2247#endif
2248#if H_3D
2249, m_bCamParInSliceHeader      (false)
2250#endif
2251{
2252  for ( Int i = 0; i < MAX_TLAYER; i++ )
2253  {
2254    m_uiMaxLatencyIncrease[i] = 0;
2255    m_uiMaxDecPicBuffering[i] = 1;
2256    m_numReorderPics[i]       = 0;
2257  }
2258  m_scalingList = new TComScalingList;
2259  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
2260  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
2261#if H_MV
2262  m_spsExtensionFlag = false; 
2263  for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) 
2264  {
2265    m_spsExtensionTypeFlag[ i ] = false;
2266  }
2267  m_numScaledRefLayerOffsets = 0; 
2268
2269  for (Int i = 0; i < MAX_NUM_SCALED_REF_LAYERS; i++ )
2270  {
2271    m_scaledRefLayerId             [i] = -1;
2272  }
2273
2274  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
2275  {
2276    m_scaledRefLayerLeftOffset     [i] = 0;
2277    m_scaledRefLayerTopOffset      [i] = 0;
2278    m_scaledRefLayerRightOffset    [i] = 0;
2279    m_scaledRefLayerBottomOffset   [i] = 0;
2280  }
2281#endif
2282}
2283
2284TComSPS::~TComSPS()
2285{
2286  delete m_scalingList;
2287  m_RPSList.destroy();
2288}
2289
2290Void  TComSPS::createRPSList( Int numRPS )
2291{ 
2292  m_RPSList.destroy();
2293  m_RPSList.create(numRPS);
2294}
2295
2296Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
2297{
2298  if( !getVuiParametersPresentFlag() )
2299  {
2300    return;
2301  }
2302
2303  TComVUI *vui = getVuiParameters();
2304  TComHRD *hrd = vui->getHrdParameters();
2305
2306  TimingInfo *timingInfo = vui->getTimingInfo();
2307  timingInfo->setTimingInfoPresentFlag( true );
2308  switch( frameRate )
2309  {
2310  case 24:
2311    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
2312    break;
2313  case 25:
2314    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
2315    break;
2316  case 30:
2317    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
2318    break;
2319  case 50:
2320    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
2321    break;
2322  case 60:
2323    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
2324    break;
2325  default:
2326    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
2327    break;
2328  }
2329
2330  Bool rateCnt = ( bitRate > 0 );
2331  hrd->setNalHrdParametersPresentFlag( rateCnt );
2332  hrd->setVclHrdParametersPresentFlag( rateCnt );
2333
2334  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
2335
2336  if( hrd->getSubPicCpbParamsPresentFlag() )
2337  {
2338    hrd->setTickDivisorMinus2( 100 - 2 );                          //
2339    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
2340    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
2341    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
2342  }
2343  else
2344  {
2345    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
2346  }
2347
2348  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
2349  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2350  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2351 
2352  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
2353  if( randomAccess )
2354  {
2355    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
2356    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
2357  }
2358  else
2359  {
2360    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
2361    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
2362  }
2363
2364/*
2365   Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
2366*/
2367  Int i, j;
2368  UInt birateValue, cpbSizeValue;
2369  UInt ducpbSizeValue;
2370  UInt duBitRateValue = 0;
2371
2372  for( i = 0; i < MAX_TLAYER; i ++ )
2373  {
2374    hrd->setFixedPicRateFlag( i, 1 );
2375    hrd->setPicDurationInTcMinus1( i, 0 );
2376    hrd->setLowDelayHrdFlag( i, 0 );
2377    hrd->setCpbCntMinus1( i, 0 );
2378
2379    birateValue  = bitRate;
2380    cpbSizeValue = bitRate;                                     // 1 second
2381    ducpbSizeValue = bitRate/numDU;
2382    duBitRateValue = bitRate;
2383    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
2384    {
2385      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
2386      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
2387      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
2388      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
2389
2390      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
2391      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
2392      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
2393      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
2394      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
2395    }
2396  }
2397}
2398const Int TComSPS::m_winUnitX[]={1,2,2,1};
2399const Int TComSPS::m_winUnitY[]={1,2,1,1};
2400
2401TComPPS::TComPPS()
2402: m_PPSId                       (0)
2403, m_SPSId                       (0)
2404, m_picInitQPMinus26            (0)
2405, m_useDQP                      (false)
2406, m_bConstrainedIntraPred       (false)
2407, m_bSliceChromaQpFlag          (false)
2408, m_pcSPS                       (NULL)
2409, m_uiMaxCuDQPDepth             (0)
2410, m_uiMinCuDQPSize              (0)
2411, m_chromaCbQpOffset            (0)
2412, m_chromaCrQpOffset            (0)
2413, m_numRefIdxL0DefaultActive    (1)
2414, m_numRefIdxL1DefaultActive    (1)
2415, m_TransquantBypassEnableFlag  (false)
2416, m_useTransformSkip             (false)
2417, m_dependentSliceSegmentsEnabledFlag    (false)
2418, m_tilesEnabledFlag               (false)
2419, m_entropyCodingSyncEnabledFlag   (false)
2420, m_loopFilterAcrossTilesEnabledFlag  (true)
2421, m_uniformSpacingFlag           (0)
2422, m_iNumColumnsMinus1            (0)
2423, m_puiColumnWidth               (NULL)
2424, m_iNumRowsMinus1               (0)
2425, m_puiRowHeight                 (NULL)
2426, m_iNumSubstreams             (1)
2427, m_signHideFlag(0)
2428, m_cabacInitPresentFlag        (false)
2429, m_encCABACTableIdx            (I_SLICE)
2430, m_sliceHeaderExtensionPresentFlag    (false)
2431, m_loopFilterAcrossSlicesEnabledFlag (false)
2432, m_listsModificationPresentFlag(  0)
2433, m_numExtraSliceHeaderBits(0)
2434#if H_MV
2435, m_ppsInferScalingListFlag(false)
2436, m_ppsScalingListRefLayerId(0)
2437#if H_3D
2438, m_pcDLT(NULL)
2439#endif
2440#endif
2441{
2442  m_scalingList = new TComScalingList;
2443
2444#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION 
2445  for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) 
2446  {
2447    m_ppsExtensionTypeFlag[ i ] = false;
2448  }
2449#endif
2450
2451}
2452
2453TComPPS::~TComPPS()
2454{
2455  if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 )
2456  {
2457    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
2458    m_puiColumnWidth = NULL;
2459  }
2460  if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 )
2461  {
2462    if (m_puiRowHeight) delete [] m_puiRowHeight;
2463    m_puiRowHeight = NULL;
2464  }
2465  delete m_scalingList;
2466}
2467
2468#if H_3D
2469TComDLT::TComDLT()
2470: m_bDltPresentFlag(false)
2471, m_iNumDepthViews(0)
2472, m_uiDepthViewBitDepth(8)
2473{
2474  m_uiDepthViewBitDepth = g_bitDepthY; 
2475
2476  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2477  {
2478    m_bUseDLTFlag                 [i] = false;
2479    m_bInterViewDltPredEnableFlag [i] = false;
2480
2481    // allocate some memory and initialize with default mapping
2482    m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1;
2483    m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]);
2484
2485    m_iDepthValue2Idx[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
2486    m_iIdx2DepthValue[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
2487
2488    //default mapping
2489    for (Int d=0; d<m_iNumDepthmapValues[i]; d++)
2490    {
2491      m_iDepthValue2Idx[i][d] = d;
2492      m_iIdx2DepthValue[i][d] = d;
2493    }
2494  }
2495}
2496
2497TComDLT::~TComDLT()
2498{
2499  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2500  {
2501    if ( m_iDepthValue2Idx[i] != NULL ) 
2502    {
2503      xFree( m_iDepthValue2Idx[i] );
2504      m_iDepthValue2Idx[i] = NULL; 
2505    }
2506
2507    if ( m_iIdx2DepthValue[i] != NULL ) 
2508    {
2509      xFree( m_iIdx2DepthValue[i] );
2510      m_iIdx2DepthValue[i] = NULL; 
2511    }
2512  }
2513}
2514
2515Void TComDLT::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues)
2516{
2517  if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only
2518    return;
2519
2520  // copy idx2DepthValue to internal array
2521  memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt));
2522
2523  UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
2524  for(Int p=0; p<=uiMaxDepthValue; p++)
2525  {
2526    Int iIdxDown    = 0;
2527    Int iIdxUp      = iNumDepthValues-1;
2528    Bool bFound     = false;
2529
2530    // iterate over indices to find lower closest depth
2531    Int i = 1;
2532    while(!bFound && i<iNumDepthValues)
2533    {
2534      if( m_iIdx2DepthValue[layerIdInVps][i] > p )
2535      {
2536        iIdxDown  = i-1;
2537        bFound    = true;
2538      }
2539
2540      i++;
2541    }
2542    // iterate over indices to find upper closest depth
2543    i = iNumDepthValues-2;
2544    bFound = false;
2545    while(!bFound && i>=0)
2546    {
2547      if( m_iIdx2DepthValue[layerIdInVps][i] < p )
2548      {
2549        iIdxUp  = i+1;
2550        bFound    = true;
2551      }
2552
2553      i--;
2554    }
2555
2556    // assert monotony
2557    assert(iIdxDown<=iIdxUp);
2558
2559    // assign closer depth value/idx
2560    if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) )
2561    {
2562      m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown;
2563    }
2564    else
2565    {
2566      m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp;
2567    }
2568
2569  }
2570
2571  // update DLT variables
2572  m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues;
2573  m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]);
2574}
2575
2576#if H_3D_DELTA_DLT
2577Void TComDLT::getDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTOut, UInt *puiDeltaDLTOutNum )
2578{
2579  Bool abBM0[ 256 ];
2580  Bool abBM1[ 256 ];
2581 
2582  memset( abBM0, 0, sizeof( abBM0 ));
2583  memset( abBM1, 0, sizeof( abBM1 ));
2584 
2585  // convert reference DLT to bit string
2586  for( Int i = 0; i < uiDLTInRefNum; i++ )
2587  {
2588    abBM0[ piDLTInRef[ i ] ] = true;
2589  }
2590  // convert internal DLT to bit string
2591  for( Int i = 0; i < m_iNumDepthmapValues[ layerIdInVps ]; i++ )
2592  {
2593    abBM1[ m_iIdx2DepthValue[ layerIdInVps ][ i ] ] = true;
2594  }
2595 
2596  *puiDeltaDLTOutNum = 0;
2597  for( Int i = 0; i < 256; i++ )
2598  {
2599    if( abBM0[ i ] ^ abBM1[ i ] )
2600    {
2601      piDeltaDLTOut[ *puiDeltaDLTOutNum ] = i;
2602      *puiDeltaDLTOutNum = *puiDeltaDLTOutNum + 1;
2603    }
2604  }
2605}
2606
2607Void TComDLT::setDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTIn, UInt uiDeltaDLTInNum )
2608{
2609  Bool abBM0[ 256 ];
2610  Bool abBM1[ 256 ];
2611 
2612  memset( abBM0, 0, sizeof( abBM0 ));
2613  memset( abBM1, 0, sizeof( abBM1 ));
2614 
2615  // convert reference DLT to bit string
2616  for( Int i = 0; i < uiDLTInRefNum; i++ )
2617  {
2618    abBM0[ piDLTInRef[ i ] ] = true;
2619  }
2620  // convert delta DLT to bit string
2621  for( Int i = 0; i < uiDeltaDLTInNum; i++ )
2622  {
2623    abBM1[ piDeltaDLTIn[ i ] ] = true;
2624  }
2625 
2626  Int aiIdx2DepthValue[256];
2627  UInt uiNumDepthValues = 0;
2628  memset( aiIdx2DepthValue, 0, sizeof( aiIdx2DepthValue ));
2629 
2630  for( Int i = 0; i < 256; i++ )
2631  {
2632    if( abBM0[ i ] ^ abBM1[ i ] )
2633    {
2634      aiIdx2DepthValue[ uiNumDepthValues++ ] = i;
2635    }
2636  }
2637 
2638  // update internal tables
2639  setDepthLUTs(layerIdInVps, aiIdx2DepthValue, uiNumDepthValues);
2640}
2641#endif
2642
2643#endif
2644
2645#if H_MV
2646Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
2647{
2648  if ( layerIdCurr > 0 )
2649  { 
2650    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
2651    TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx ); 
2652      setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() );         
2653      //// ToDo: add when supported:
2654      // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
2655
2656      setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  ); 
2657      setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); 
2658
2659      setBitDepthY             ( repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
2660      setQpBDOffsetY           ( (Int) (6*( getBitDepthY() - 8 )) );
2661
2662      setBitDepthC             ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
2663      setQpBDOffsetC           ( (Int) (6* ( getBitDepthC() -8 ) ) );
2664    if ( getLayerId() > 0 && getUpdateRepFormatFlag() )
2665    {
2666      assert( getChromaFormatIdc()      <=  repFormat->getChromaFormatVpsIdc()         ); 
2667      //// ToDo: add when supported:
2668      // assert( getSeperateColourPlaneFlag() <=  repFormat->getSeparateColourPlaneVpsFlag() ) ;
2669
2670      assert( getPicWidthInLumaSamples()  <= repFormat->getPicWidthVpsInLumaSamples()    ); 
2671      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   ); 
2672
2673      assert( getBitDepthY()              <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
2674      assert( getBitDepthC()              <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
2675    }
2676  }
2677
2678  // Set conformance window
2679  Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ;
2680  getConformanceWindow().scaleOffsets( scal );
2681  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
2682}
2683
2684Void TComSPS::inferScalingList( TComSPS* spsSrc )
2685{
2686  if ( getSpsInferScalingListFlag() ) 
2687  {
2688    assert( spsSrc != NULL ); 
2689    assert( !spsSrc->getSpsInferScalingListFlag() );             
2690    getScalingList()->inferFrom( spsSrc->getScalingList() ); 
2691  }
2692}
2693#endif
2694
2695TComReferencePictureSet::TComReferencePictureSet()
2696: m_numberOfPictures (0)
2697, m_numberOfNegativePictures (0)
2698, m_numberOfPositivePictures (0)
2699, m_numberOfLongtermPictures (0)
2700, m_interRPSPrediction (0) 
2701, m_deltaRIdxMinus1 (0)   
2702, m_deltaRPS (0) 
2703, m_numRefIdc (0) 
2704{
2705  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
2706  ::memset( m_POC, 0, sizeof(m_POC) );
2707  ::memset( m_used, 0, sizeof(m_used) );
2708  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
2709}
2710
2711TComReferencePictureSet::~TComReferencePictureSet()
2712{
2713}
2714
2715Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
2716{
2717  m_used[bufferNum] = used;
2718}
2719
2720Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
2721{
2722  m_deltaPOC[bufferNum] = deltaPOC;
2723}
2724
2725Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
2726{
2727  m_numberOfPictures = numberOfPictures;
2728}
2729
2730Int TComReferencePictureSet::getUsed(Int bufferNum)
2731{
2732  return m_used[bufferNum];
2733}
2734
2735Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
2736{
2737  return m_deltaPOC[bufferNum];
2738}
2739
2740Int TComReferencePictureSet::getNumberOfPictures()
2741{
2742  return m_numberOfPictures;
2743}
2744
2745Int TComReferencePictureSet::getPOC(Int bufferNum)
2746{
2747  return m_POC[bufferNum];
2748}
2749
2750Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
2751{
2752  m_POC[bufferNum] = POC;
2753}
2754
2755Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
2756{
2757  return m_bCheckLTMSB[bufferNum];
2758}
2759
2760Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
2761{
2762  m_bCheckLTMSB[bufferNum] = b;
2763}
2764
2765/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
2766 * \param uiBufferNum
2767 * \param iRefIdc
2768 * \returns Void
2769 */
2770Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
2771{
2772  m_refIdc[bufferNum] = refIdc;
2773}
2774
2775/** get the reference idc value at uiBufferNum
2776 * \param uiBufferNum
2777 * \returns Int
2778 */
2779Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
2780{
2781  return m_refIdc[bufferNum];
2782}
2783
2784/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
2785 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
2786 *  +ve values are in increasing order.
2787 * \returns Void
2788 */
2789Void TComReferencePictureSet::sortDeltaPOC()
2790{
2791  // sort in increasing order (smallest first)
2792  for(Int j=1; j < getNumberOfPictures(); j++)
2793  { 
2794    Int deltaPOC = getDeltaPOC(j);
2795    Bool used = getUsed(j);
2796    for (Int k=j-1; k >= 0; k--)
2797    {
2798      Int temp = getDeltaPOC(k);
2799      if (deltaPOC < temp)
2800      {
2801        setDeltaPOC(k+1, temp);
2802        setUsed(k+1, getUsed(k));
2803        setDeltaPOC(k, deltaPOC);
2804        setUsed(k, used);
2805      }
2806    }
2807  }
2808  // flip the negative values to largest first
2809  Int numNegPics = getNumberOfNegativePictures();
2810  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
2811  { 
2812    Int deltaPOC = getDeltaPOC(j);
2813    Bool used = getUsed(j);
2814    setDeltaPOC(j, getDeltaPOC(k));
2815    setUsed(j, getUsed(k));
2816    setDeltaPOC(k, deltaPOC);
2817    setUsed(k, used);
2818  }
2819}
2820
2821/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
2822 *  A "*" is added to the deltaPOC value if it is Used bu current.
2823 * \returns Void
2824 */
2825Void TComReferencePictureSet::printDeltaPOC()
2826{
2827  printf("DeltaPOC = { ");
2828  for(Int j=0; j < getNumberOfPictures(); j++)
2829  {
2830    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
2831  } 
2832  if (getInterRPSPrediction()) 
2833  {
2834    printf("}, RefIdc = { ");
2835    for(Int j=0; j < getNumRefIdc(); j++)
2836    {
2837      printf("%d ", getRefIdc(j));
2838    } 
2839  }
2840  printf("}\n");
2841}
2842
2843TComRPSList::TComRPSList()
2844:m_referencePictureSets (NULL)
2845{
2846}
2847
2848TComRPSList::~TComRPSList()
2849{
2850}
2851
2852Void TComRPSList::create( Int numberOfReferencePictureSets)
2853{
2854  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2855  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
2856}
2857
2858Void TComRPSList::destroy()
2859{
2860  if (m_referencePictureSets)
2861  {
2862    delete [] m_referencePictureSets;
2863  }
2864  m_numberOfReferencePictureSets = 0;
2865  m_referencePictureSets = NULL;
2866}
2867
2868
2869
2870TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
2871{
2872  return &m_referencePictureSets[referencePictureSetNum];
2873}
2874
2875Int TComRPSList::getNumberOfReferencePictureSets()
2876{
2877  return m_numberOfReferencePictureSets;
2878}
2879
2880Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
2881{
2882  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2883}
2884
2885TComRefPicListModification::TComRefPicListModification()
2886: m_bRefPicListModificationFlagL0 (false)
2887, m_bRefPicListModificationFlagL1 (false)
2888{
2889  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
2890  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
2891}
2892
2893TComRefPicListModification::~TComRefPicListModification()
2894{
2895}
2896
2897TComScalingList::TComScalingList()
2898{
2899  init();
2900}
2901TComScalingList::~TComScalingList()
2902{
2903  destroy();
2904}
2905
2906/** set default quantization matrix to array
2907*/
2908Void TComSlice::setDefaultScalingList()
2909{
2910  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2911  {
2912    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2913    {
2914      getScalingList()->processDefaultMatrix(sizeId, listId);
2915    }
2916  }
2917}
2918/** check if use default quantization matrix
2919 * \returns true if use default quantization matrix in all size
2920*/
2921Bool TComSlice::checkDefaultScalingList()
2922{
2923  UInt defaultCounter=0;
2924
2925  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2926  {
2927    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2928    {
2929      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
2930     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
2931      {
2932        defaultCounter++;
2933      }
2934    }
2935  }
2936  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
2937}
2938
2939#if H_MV
2940Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
2941{
2942  refPicSetInterLayer0.clear(); 
2943  refPicSetInterLayer1.clear(); 
2944
2945  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
2946  {
2947    Int layerIdRef = getRefPicLayerId( i ); 
2948    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
2949    assert ( picRef != 0 ); 
2950
2951    picRef->getPicYuvRec()->extendPicBorder(); 
2952    picRef->setIsLongTerm( true );       
2953    picRef->getSlice(0)->setReferenced( true );       
2954
2955    Int viewIdCur  = getVPS()->getViewId( getLayerId() ); 
2956    Int viewIdZero = getVPS()->getViewId( 0 );
2957    Int viewIdRef  = getVPS()->getViewId( layerIdRef ); 
2958
2959    if (  ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) )
2960    {
2961      refPicSetInterLayer0.push_back( picRef ); 
2962    }
2963    else
2964    {
2965      refPicSetInterLayer1.push_back( picRef ); 
2966    }
2967    // Consider to check here:
2968    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "   
2969#if H_MV_HLS_7_MISC_P0130_20
2970    assert( picRef->getSlice(0)->getDiscardableFlag() == false ); // "There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1".       
2971#endif
2972  }
2973}
2974
2975Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
2976{
2977  // Mark as shortterm
2978  for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
2979  {
2980    refPicSetInterLayer0[i]->setIsLongTerm( false ); 
2981  }
2982
2983  for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) 
2984  {
2985    refPicSetInterLayer1[i]->setIsLongTerm( false ); 
2986  }
2987
2988}
2989Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
2990{
2991  // Fill targetDecLayerIdSet with all layers if empty (at encoder side)
2992  if (targetDecLayerIdSet.size() == 0 )   
2993  {
2994    for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ )
2995    {
2996      targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); 
2997    }
2998  }     
2999
3000  Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); 
3001  Int latestDecIdx; 
3002  for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++)
3003  {
3004    if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId )
3005    {
3006      break; 
3007  }       
3008  }       
3009
3010  for( Int i = 0; i <= latestDecIdx; i++ ) 
3011  {
3012    if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) )
3013    {
3014      TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); 
3015      if ( pcPic )
3016      {
3017      if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) 
3018      { 
3019        Bool remainingInterLayerReferencesFlag = false; 
3020        for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
3021        { 
3022          TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); 
3023          if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
3024          {
3025            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ )
3026            {
3027              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ],  k  ) )
3028              {
3029                remainingInterLayerReferencesFlag = true;
3030          }
3031        }
3032          }
3033        }
3034        if( !remainingInterLayerReferencesFlag )
3035        {
3036          pcPic->getSlice(0)->setReferenced( false );                   
3037      }
3038    }
3039      }
3040  }
3041}
3042}
3043
3044Void TComSlice::printRefPicList()
3045{ 
3046  for ( Int li = 0; li < 2; li++)
3047  {   
3048    std::cout << std::endl << "RefPicListL" <<  li << ":" << std::endl; 
3049    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
3050    {     
3051      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
3052       
3053      m_apcRefPicList[li][rIdx]->print( false );
3054    }
3055  }
3056}
3057
3058Void TComSlice::markCurrPic( TComPic* currPic )
3059{
3060  if ( !currPic->getSlice(0)->getDiscardableFlag() )
3061  {
3062    currPic->getSlice(0)->setReferenced( true ) ; 
3063    currPic->setIsLongTerm( false ); 
3064  }
3065  else
3066  {
3067    currPic->getSlice(0)->setReferenced( false ) ; 
3068  }
3069}
3070
3071Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
3072{
3073  m_refPicSetInterLayer0 = refPicSetInterLayer0; 
3074  m_refPicSetInterLayer1 = refPicSetInterLayer1; 
3075}
3076
3077TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId )
3078{
3079  assert ( setIdc == 0 || setIdc == 1);   
3080  std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1);   
3081  assert( refPicSetInterLayer != 0 ); 
3082 
3083  TComPic* pcPic = NULL; 
3084  for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ )
3085  {
3086    if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId )
3087    {
3088      pcPic = (*refPicSetInterLayer)[ i ]; 
3089    }
3090  }
3091
3092  assert(pcPic != NULL); 
3093  return pcPic;
3094}
3095
3096
3097Int  TComSlice::getRefLayerPicFlag( Int i ) 
3098{
3099  TComVPS* vps = getVPS(); 
3100  Int refLayerIdx = vps->getLayerIdInVps( vps->getRefLayerId( getLayerId(), i ) ); 
3101
3102  Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer() )  && 
3103    ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); 
3104
3105  return refLayerPicFlag;       
3106}   
3107
3108Int TComSlice::getRefLayerPicIdc( Int j ) 
3109{ 
3110  Int refLayerPicIdc = -1; 
3111  Int curj = 0; 
3112  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3113  {
3114    if( getRefLayerPicFlag( i ) )
3115    {
3116      if ( curj == j ) 
3117      {
3118        refLayerPicIdc = i;         
3119        break;
3120      }
3121      curj++; 
3122    }
3123  }
3124
3125  assert( curj == j ); 
3126  assert( refLayerPicIdc != -1 ); 
3127  return refLayerPicIdc; 
3128}
3129
3130Int  TComSlice::getNumRefLayerPics( )
3131{ 
3132  Int numRefLayerPics = 0; 
3133  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3134  {
3135    numRefLayerPics += getRefLayerPicFlag( i ); 
3136  }
3137  return numRefLayerPics; 
3138}
3139
3140
3141
3142Int TComSlice::getNumActiveRefLayerPics()
3143{
3144  Int numActiveRefLayerPics; 
3145
3146#if H_MV_HLS_7_MISC_P0079_18
3147  if( getLayerId() == 0 || getNumRefLayerPics() ==  0 )
3148#else
3149  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) ==  0 )
3150#endif
3151  {
3152    numActiveRefLayerPics = 0; 
3153  }
3154  else if (getVPS()->getAllRefLayersActiveFlag() )
3155  {
3156    numActiveRefLayerPics = getNumRefLayerPics(); 
3157  }
3158  else if ( !getInterLayerPredEnabledFlag() )
3159  {
3160    numActiveRefLayerPics = 0; 
3161  }
3162  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
3163  {
3164#if H_MV_HLS_7_MISC_P0079_18
3165    numActiveRefLayerPics = 1; 
3166#else
3167    numActiveRefLayerPics = getRefLayerPicFlag( 0 ) ? 1 : 0; 
3168#endif
3169  }
3170  else
3171  {
3172    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
3173  }
3174  return numActiveRefLayerPics;
3175}
3176
3177Int TComSlice::getRefPicLayerId( Int i )
3178{
3179  return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) );
3180}
3181
3182#if H_3D_ARP
3183Void TComSlice::setARPStepNum( TComPicLists*ivPicLists )
3184{
3185  Bool tempRefPicInListsFlag = false;
3186  if(!getVPS()->getUseAdvRP(getLayerId()) || this->isIRAP())
3187  {
3188    m_nARPStepNum = 0;
3189  }
3190  else
3191  {
3192    setFirstTRefIdx (REF_PIC_LIST_0, -1);
3193    setFirstTRefIdx (REF_PIC_LIST_1, -1);
3194    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3195    {
3196#if MTK_ARP_REF_SELECTION_G0053
3197      Int diffPOC=MAX_INT;
3198      Int idx=-1;
3199#endif
3200      for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ )
3201      {
3202        if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() )
3203        {
3204#if MTK_ARP_REF_SELECTION_G0053
3205          if( abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC()) < diffPOC)
3206          {
3207            diffPOC=abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC());
3208            idx=i;
3209          }
3210#else
3211          setFirstTRefIdx (RefPicList(refListIdx), i);
3212          break;
3213#endif
3214        }
3215#if MTK_ARP_REF_SELECTION_G0053
3216        if(idx>=0)
3217        {
3218          setFirstTRefIdx (RefPicList(refListIdx), idx);
3219        }
3220#endif
3221      }
3222    }
3223    tempRefPicInListsFlag = getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0;
3224    m_nARPStepNum = tempRefPicInListsFlag ? getVPS()->getARPStepNum(getLayerId()) : 0;
3225  }
3226
3227  if (tempRefPicInListsFlag)
3228  {
3229    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3230    {
3231      RefPicList eRefPicList = RefPicList( refListIdx );
3232      Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC();
3233      for( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
3234      {
3235        Int layerIdInNuh = getRefPicLayerId( i );
3236        Int viewIdx = getVPS()->getViewId( layerIdInNuh );
3237        TComPic*pcPicPrev = ivPicLists->getPic(viewIdx, 0, prevPOC);
3238        if (getFirstTRefIdx(eRefPicList) >= 0 && pcPicPrev && pcPicPrev->getSlice( 0 )->isReferenced())
3239        {
3240          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true;
3241        }
3242        else
3243        {
3244          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false;
3245        }
3246      }
3247    }
3248  }
3249}
3250#endif
3251#if H_3D_IC
3252Void TComSlice::xSetApplyIC()
3253{
3254  Int iMaxPelValue = ( 1 << g_bitDepthY ); 
3255  Int *aiRefOrgHist;
3256  Int *aiCurrHist;
3257  aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue );
3258  aiCurrHist   = (Int *) xMalloc( Int,iMaxPelValue );
3259  memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
3260  memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
3261  // Reference Idx Number
3262  Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 );
3263  TComPic* pcCurrPic = NULL;
3264  TComPic* pcRefPic = NULL;
3265  TComPicYuv* pcCurrPicYuv = NULL;
3266  TComPicYuv* pcRefPicYuvOrg = NULL;
3267  pcCurrPic = getPic();
3268  pcCurrPicYuv = pcCurrPic->getPicYuvOrg();
3269  Int iWidth = pcCurrPicYuv->getWidth();
3270  Int iHeight = pcCurrPicYuv->getHeight();
3271
3272
3273  // Get InterView Reference picture
3274  // !!!!! Assume only one Interview Reference Picture in L0
3275  for ( Int i = 0; i < iNumRefIdx; i++ )
3276  {
3277    pcRefPic = getRefPic( REF_PIC_LIST_0, i );
3278    if ( pcRefPic != NULL )
3279    {
3280      if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3281      {
3282        pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
3283      }
3284    }
3285  }
3286
3287  if ( pcRefPicYuvOrg != NULL )
3288  {
3289    Pel* pCurrY = pcCurrPicYuv ->getLumaAddr();
3290    Pel* pRefOrgY = pcRefPicYuvOrg  ->getLumaAddr();
3291    Int iCurrStride = pcCurrPicYuv->getStride();
3292    Int iRefStride = pcRefPicYuvOrg->getStride();
3293    Int iSumOrgSAD = 0;
3294    Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
3295
3296    // Histogram building - luminance
3297    for ( Int y = 0; y < iHeight; y++ )
3298    {
3299      for ( Int x = 0; x < iWidth; x++ )
3300      {
3301        aiCurrHist[pCurrY[x]]++;
3302        aiRefOrgHist[pRefOrgY[x]]++;
3303      }
3304      pCurrY += iCurrStride;
3305      pRefOrgY += iRefStride;
3306    }
3307    // Histogram SAD
3308    for ( Int i = 0; i < iMaxPelValue; i++ )
3309    {
3310      iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] );
3311    }
3312    // Setting
3313    if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) )
3314    {
3315      m_bApplyIC = true;
3316    }
3317    else
3318    {
3319      m_bApplyIC = false;
3320    }
3321  }
3322
3323  xFree( aiCurrHist   );
3324  xFree( aiRefOrgHist );
3325  aiCurrHist = NULL;
3326  aiRefOrgHist = NULL;
3327}
3328#endif
3329#if H_3D
3330Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
3331{
3332  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
3333  {     
3334    for ( Int depthId = 0; depthId < 2; depthId++ )
3335    {
3336      m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL;
3337    }       
3338  } 
3339}
3340Void TComSlice::setDepthToDisparityLUTs()
3341{ 
3342  Bool setupLUT = false; 
3343  Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); 
3344
3345#if H_3D_VSP
3346  setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); 
3347#endif
3348
3349#if H_3D_NBDV_REF
3350  setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS );
3351#endif
3352
3353#if H_3D_IV_MERGE
3354  setupLUT = setupLUT || ( getVPS()->getIvMvPredFlag(layerIdInVPS ) && getIsDepth() );
3355#endif
3356
3357#if MTK_DDD_G0063
3358  if( getIsDepth() && getViewIndex() > 0 )
3359  {
3360      TComSlice *pcTextSlice = getTexturePic()->getSlice( 0 );
3361      memcpy( m_aiDDDInvScale, pcTextSlice->m_aiDDDInvScale, sizeof( Int ) * getViewIndex() );
3362      memcpy( m_aiDDDInvOffset, pcTextSlice->m_aiDDDInvOffset, sizeof( Int ) * getViewIndex() );
3363      memcpy( m_aiDDDShift, pcTextSlice->m_aiDDDShift, sizeof( Int ) * getViewIndex() );             
3364  } 
3365#endif
3366
3367  if( !setupLUT )
3368    return; 
3369
3370  /// GT: Allocation should be moved to a better place later;
3371  if ( m_depthToDisparityB == NULL )
3372  {
3373    m_depthToDisparityB = new Int*[ getViewIndex() ];
3374    for ( Int i = 0; i < getViewIndex(); i++ )
3375    {
3376      m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
3377    }
3378  }
3379
3380  if ( m_depthToDisparityF == NULL )
3381  {
3382    m_depthToDisparityF= new Int*[ getViewIndex() ];
3383    for ( Int i = 0; i < getViewIndex(); i++ )
3384    {
3385      m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
3386    }
3387  }
3388
3389  assert( m_depthToDisparityB != NULL ); 
3390  assert( m_depthToDisparityF != NULL ); 
3391
3392  TComVPS* vps = getVPS(); 
3393
3394  Int log2Div = g_bitDepthY - 1 + vps->getCamParPrecision();
3395  Int viewIndex = getViewIndex();
3396
3397  Bool camParaSH = vps->hasCamParInSliceHeader( viewIndex );
3398
3399  Int* codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale    ( viewIndex ); 
3400  Int* codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset   ( viewIndex ); 
3401  Int* invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( viewIndex ); 
3402  Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( viewIndex ); 
3403
3404  for (Int i = 0; i <= ( getViewIndex() - 1); i++)
3405  {
3406    for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ )
3407    {
3408      Int offset =    ( codOffset  [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
3409      m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; 
3410
3411      Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
3412      m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; 
3413    }
3414
3415#if MTK_DDD_G0063
3416    InitializeDDDPara( vps->getCamParPrecision(), codScale[ i ], codOffset[ i ], i );
3417#endif
3418  }
3419}
3420#endif
3421#endif
3422
3423#if MTK_DDD_G0063
3424Void TComSlice::InitializeDDDPara( UInt uiCamParsCodedPrecision, Int  iCodedScale,Int  iCodedOffset, Int iBaseViewIdx )
3425{
3426    UInt uiViewId     = getViewIndex();
3427
3428    if( uiViewId == 0 )
3429    {
3430        m_aiDDDInvScale[ iBaseViewIdx ] = m_aiDDDInvOffset[ iBaseViewIdx ] = m_aiDDDShift[ iBaseViewIdx ] = 0;
3431        return;
3432    }
3433
3434
3435    Int iSign = iCodedScale >= 0 ? 1 : -1;
3436    iCodedScale = abs( iCodedScale );
3437
3438    Int iBitWidth = 0;
3439
3440    const Int iInvPres = 9;
3441
3442    while( ((( 1 << iBitWidth ) << 1 ) <= iCodedScale ) )
3443    {
3444        iBitWidth ++;
3445    }
3446    iBitWidth += iInvPres;
3447    Int iTargetValue =  1 << iBitWidth;
3448
3449    Int iMinError = MAX_INT;
3450    Int iBestD = 1 << ( iInvPres - 1 );
3451    for( Int d = 1 << ( iInvPres - 1 ); d < ( 1 << iInvPres ); d++ )
3452    {
3453        Int iError = abs( iCodedScale * d - iTargetValue );
3454        if( iError < iMinError )
3455        {
3456            iMinError = iError;
3457            iBestD = d;
3458        }
3459        if( iMinError == 0 )
3460        {
3461            break;
3462        }
3463    }
3464    Int iRoundingDir = 0;
3465    if( iCodedScale * iBestD > iTargetValue )
3466    {
3467        iRoundingDir = -1;
3468    }
3469    else if( iCodedScale * iBestD < iTargetValue )
3470    {
3471        iRoundingDir = 1;
3472    }
3473    Int iCamPres = uiCamParsCodedPrecision - 1;
3474    m_aiDDDInvScale [ iBaseViewIdx ] = ( iBestD << ( iCamPres + g_bitDepthY )) * iSign;
3475    m_aiDDDInvOffset[ iBaseViewIdx ] = -iSign * iBestD * ( iCodedOffset << g_bitDepthY );
3476    m_aiDDDShift    [ iBaseViewIdx ] = iBitWidth;
3477    m_aiDDDInvOffset[ iBaseViewIdx ] += 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 1 );
3478    m_aiDDDInvOffset[ iBaseViewIdx ] += ( 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 4 ) ) * iRoundingDir;
3479
3480    return;
3481}
3482#endif
3483
3484/** get scaling matrix from RefMatrixID
3485 * \param sizeId size index
3486 * \param Index of input matrix
3487 * \param Index of reference matrix
3488 */
3489Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
3490{
3491  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3492}
3493
3494/** parse syntax infomation
3495 *  \param pchFile syntax infomation
3496 *  \returns false if successful
3497 */
3498Bool TComScalingList::xParseScalingList(Char* pchFile)
3499{
3500  FILE *fp;
3501  Char line[1024];
3502  UInt sizeIdc,listIdc;
3503  UInt i,size = 0;
3504  Int *src=0,data;
3505  Char *ret;
3506  UInt  retval;
3507
3508  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
3509  {
3510    printf("can't open file %s :: set Default Matrix\n",pchFile);
3511    return true;
3512  }
3513
3514  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
3515  {
3516    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
3517    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
3518    {
3519      src = getScalingListAddress(sizeIdc, listIdc);
3520
3521      fseek(fp,0,0);
3522      do 
3523      {
3524        ret = fgets(line, 1024, fp);
3525        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
3526        {
3527          printf("Error: can't read Matrix :: set Default Matrix\n");
3528          return true;
3529        }
3530      }
3531      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
3532      for (i=0; i<size; i++)
3533      {
3534        retval = fscanf(fp, "%d,", &data);
3535        if (retval!=1)
3536        {
3537          printf("Error: can't read Matrix :: set Default Matrix\n");
3538          return true;
3539        }
3540        src[i] = data;
3541      }
3542      //set DC value for default matrix check
3543      setScalingListDC(sizeIdc,listIdc,src[0]);
3544
3545      if(sizeIdc > SCALING_LIST_8x8)
3546      {
3547        fseek(fp,0,0);
3548        do 
3549        {
3550          ret = fgets(line, 1024, fp);
3551          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
3552          {
3553            printf("Error: can't read DC :: set Default Matrix\n");
3554            return true;
3555          }
3556        }
3557        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
3558        retval = fscanf(fp, "%d,", &data);
3559        if (retval!=1)
3560        {
3561          printf("Error: can't read Matrix :: set Default Matrix\n");
3562          return true;
3563        }
3564        //overwrite DC value when size of matrix is larger than 16x16
3565        setScalingListDC(sizeIdc,listIdc,data);
3566      }
3567    }
3568  }
3569  fclose(fp);
3570  return false;
3571}
3572
3573#if H_MV
3574Void TComScalingList::inferFrom( TComScalingList* srcScLi )
3575{
3576  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3577  {
3578    for(Int listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3579    {
3580      setRefMatrixId  (sizeId,listId, srcScLi->getRefMatrixId  (sizeId,listId));
3581      setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId));         
3582      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3583    }
3584  }
3585}
3586#endif
3587/** initialization process of quantization matrix array
3588 */
3589Void TComScalingList::init()
3590{
3591  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3592  {
3593    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3594    {
3595      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
3596    }
3597  }
3598  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
3599}
3600
3601/** destroy quantization matrix array
3602 */
3603Void TComScalingList::destroy()
3604{
3605  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3606  {
3607    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3608    {
3609      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
3610    }
3611  }
3612}
3613
3614/** get default address of quantization matrix
3615 * \param sizeId size index
3616 * \param listId list index
3617 * \returns pointer of quantization matrix
3618 */
3619Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
3620{
3621  Int *src = 0;
3622  switch(sizeId)
3623  {
3624    case SCALING_LIST_4x4:
3625      src = g_quantTSDefault4x4;
3626      break;
3627    case SCALING_LIST_8x8:
3628      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3629      break;
3630    case SCALING_LIST_16x16:
3631      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3632      break;
3633    case SCALING_LIST_32x32:
3634      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3635      break;
3636    default:
3637      assert(0);
3638      src = NULL;
3639      break;
3640  }
3641  return src;
3642}
3643
3644/** process of default matrix
3645 * \param sizeId size index
3646 * \param Index of input matrix
3647 */
3648Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
3649{
3650  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3651  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
3652}
3653
3654/** check DC value of matrix for default matrix signaling
3655 */
3656Void TComScalingList::checkDcOfMatrix()
3657{
3658  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3659  {
3660    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3661    {
3662      //check default matrix?
3663      if(getScalingListDC(sizeId,listId) == 0)
3664      {
3665        processDefaultMatrix(sizeId, listId);
3666      }
3667    }
3668  }
3669}
3670
3671ParameterSetManager::ParameterSetManager()
3672: m_vpsMap(MAX_NUM_VPS)
3673, m_spsMap(MAX_NUM_SPS)
3674, m_ppsMap(MAX_NUM_PPS)
3675, m_activeVPSId(-1)
3676#if !H_MV
3677, m_activeSPSId(-1)
3678, m_activePPSId(-1)
3679{
3680#else
3681{
3682  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
3683  {
3684    m_activeSPSId[ i ] = -1; 
3685    m_activePPSId[ i ] = -1; 
3686  }
3687#endif
3688}
3689
3690
3691ParameterSetManager::~ParameterSetManager()
3692{
3693}
3694
3695//! activate a SPS from a active parameter sets SEI message
3696//! \returns true, if activation is successful
3697#if H_MV
3698Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
3699#else
3700Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
3701#endif
3702{
3703  TComSPS *sps = m_spsMap.getPS(spsId);
3704  if (sps)
3705  {
3706    Int vpsId = sps->getVPSId();
3707    if (m_vpsMap.getPS(vpsId))
3708    {
3709      m_activeVPSId = vpsId;
3710#if H_MV
3711      m_activeSPSId[ layerId ] = spsId;
3712#else
3713      m_activeSPSId = spsId;
3714#endif
3715      return true;
3716    }
3717    else
3718    {
3719      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
3720    }
3721  }
3722  else
3723  {
3724    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
3725  }
3726  return false;
3727}
3728
3729//! activate a PPS and depending on isIDR parameter also SPS and VPS
3730//! \returns true, if activation is successful
3731#if H_MV
3732Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
3733#else
3734Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
3735#endif
3736{
3737  TComPPS *pps = m_ppsMap.getPS(ppsId);
3738  if (pps)
3739  {
3740    Int spsId = pps->getSPSId();
3741#if H_MV
3742    if (!isIRAP && (spsId != m_activeSPSId[ layerId ]))
3743#else
3744    if (!isIRAP && (spsId != m_activeSPSId))
3745#endif
3746    {
3747      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
3748      return false;
3749    }
3750
3751    TComSPS *sps = m_spsMap.getPS(spsId);
3752    if (sps)
3753    {
3754      Int vpsId = sps->getVPSId();
3755      if (!isIRAP && (vpsId != m_activeVPSId))
3756      {
3757        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
3758        return false;
3759      }
3760      if (m_vpsMap.getPS(vpsId))
3761      {
3762#if H_MV
3763        m_activePPSId[ layerId ] = ppsId;
3764        m_activeVPSId = vpsId;
3765        m_activeSPSId[ layerId ] = spsId;
3766#else
3767        m_activePPSId = ppsId;
3768        m_activeVPSId = vpsId;
3769        m_activeSPSId = spsId;
3770#endif
3771        return true;
3772      }
3773      else
3774      {
3775        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
3776      }
3777    }
3778    else
3779    {
3780      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
3781    }
3782  }
3783  else
3784  {
3785    printf("Warning: tried to activate non-existing PPS.");
3786  }
3787  return false;
3788}
3789
3790ProfileTierLevel::ProfileTierLevel()
3791  : m_profileSpace    (0)
3792  , m_tierFlag        (false)
3793  , m_profileIdc      (0)
3794  , m_levelIdc        (0)
3795, m_progressiveSourceFlag  (false)
3796, m_interlacedSourceFlag   (false)
3797, m_nonPackedConstraintFlag(false)
3798, m_frameOnlyConstraintFlag(false)
3799{
3800  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
3801}
3802
3803TComPTL::TComPTL()
3804{
3805  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
3806  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
3807}
3808
3809#if H_MV
3810Void TComPTL::copyLevelFrom( TComPTL* source )
3811{
3812  getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() );
3813  for( Int subLayer = 0; subLayer < 6; subLayer++ )
3814  {
3815    setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) );
3816    getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() );
3817  }
3818}
3819#endif
3820//! \}
3821
3822#if H_MV
3823TComVPSVUI::TComVPSVUI()
3824{
3825  m_crossLayerIrapAlignedFlag = true; 
3826#if H_MV_HLS_7_MISC_P0068_21
3827  m_allLayersIdrAlignedFlag   = false; 
3828#endif
3829  m_bitRatePresentVpsFlag = false;
3830  m_picRatePresentVpsFlag = false;
3831  for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++)
3832  {   
3833    for ( Int j = 0; j < MAX_TLAYER; j++)
3834    {   
3835      m_bitRatePresentFlag          [i][j] = false;
3836      m_picRatePresentFlag          [i][j] = false;
3837      m_avgBitRate                  [i][j] = -1;
3838      m_maxBitRate                  [i][j] = -1;
3839      m_constantPicRateIdc          [i][j] = -1;
3840      m_avgPicRate                  [i][j] = -1;
3841    }
3842  }
3843
3844  m_ilpRestrictedRefLayersFlag = false;
3845
3846  for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
3847  {         
3848    for ( Int j = 0; j < MAX_NUM_LAYERS; j++)
3849    {   
3850      m_tileBoundariesAlignedFlag   [i][j] = false;
3851      m_minSpatialSegmentOffsetPlus1[i][j] = 0;
3852      m_ctuBasedOffsetEnabledFlag   [i][j] = false;
3853      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
3854    }
3855#if H_MV_HLS_7_MISC_P0182_13
3856    m_baseLayerParameterSetCompatibilityFlag[i] = false;
3857#endif
3858  }
3859  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
3860  {
3861    m_videoSignalInfo          [i] = NULL;     
3862  }
3863
3864  m_vpsVuiBspHrdPresentFlag = false; 
3865  m_vpsVuiBspHrdParameters  = new TComVpsVuiBspHrdParameters();
3866}
3867
3868TComVPSVUI::~TComVPSVUI()
3869{
3870  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
3871  {
3872    if (m_videoSignalInfo[ i ] != NULL )      delete m_videoSignalInfo[ i ];   
3873    m_videoSignalInfo    [ i ] = NULL; 
3874  }
3875
3876  if ( m_vpsVuiBspHrdParameters ) delete m_vpsVuiBspHrdParameters;
3877  m_vpsVuiBspHrdParameters = NULL; 
3878}
3879
3880Void TComRepFormat::inferChromaAndBitDepth( TComRepFormat* prevRepFormat, Bool encoderFlag )
3881{
3882  if ( !encoderFlag )
3883  {
3884    setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
3885    setSeparateColourPlaneVpsFlag     ( prevRepFormat->getSeparateColourPlaneVpsFlag     () );
3886    setBitDepthVpsLumaMinus8          ( prevRepFormat->getBitDepthVpsLumaMinus8          () );
3887    setBitDepthVpsChromaMinus8        ( prevRepFormat->getBitDepthVpsChromaMinus8        () );
3888  }
3889  else
3890  {
3891    assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
3892    assert( getSeparateColourPlaneVpsFlag     () == prevRepFormat->getSeparateColourPlaneVpsFlag     () );
3893    assert( getBitDepthVpsLumaMinus8          () == prevRepFormat->getBitDepthVpsLumaMinus8          () );
3894    assert( getBitDepthVpsChromaMinus8        () == prevRepFormat->getBitDepthVpsChromaMinus8        () );
3895}
3896}
3897
3898Void TComVpsVuiBspHrdParameters::checkLayerInBspFlag( TComVPS* vps, Int h )
3899{
3900  // It is a requirement of bitstream conformance that bitstream partition with index j shall not include
3901  // direct or indirect reference layers of any layers in bitstream partition i for any values of i and j
3902  // in the range of 0 to num_bitstream_partitions[ h ] ?1, inclusive, such that i is less than j.
3903
3904  for ( Int partJ = 0; partJ < getNumBitstreamPartitions( h ); partJ++ )
3905  {       
3906    for ( Int partI = 0; partI < partJ; partI++ )
3907    {
3908      for ( Int layerJ = 0; layerJ < vps->getMaxLayersMinus1(); layerJ++ )
3909      {
3910        if ( m_layerInBspFlag[ h ][partJ][layerJ ] )
3911        {
3912          for ( Int layerI = 0; layerI < vps->getMaxLayersMinus1(); layerI++ )
3913          {
3914            if ( m_layerInBspFlag[ h ][partI][layerI] )
3915            {
3916              assert( !vps->getInDirectDependencyFlag( layerI, layerJ ) ); 
3917            }
3918          }
3919        }
3920      }
3921    }
3922  }
3923}
3924
3925Void TComVUI::inferVideoSignalInfo( TComVPS* vps, Int layerIdCurr )
3926{
3927  if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() ) 
3928  {
3929    return; 
3930  }
3931
3932  TComVPSVUI* vpsVUI = vps->getVPSVUI(); 
3933  assert( vpsVUI != NULL ); 
3934
3935  TComVideoSignalInfo* videoSignalInfo = vpsVUI->getVideoSignalInfo( vpsVUI->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); 
3936  assert( videoSignalInfo != NULL );
3937
3938  setVideoFormat            ( videoSignalInfo->getVideoVpsFormat            () ); 
3939  setVideoFullRangeFlag     ( videoSignalInfo->getVideoFullRangeVpsFlag     () );
3940  setColourPrimaries        ( videoSignalInfo->getColourPrimariesVps        () );
3941  setTransferCharacteristics( videoSignalInfo->getTransferCharacteristicsVps() );
3942  setMatrixCoefficients     ( videoSignalInfo->getMatrixCoeffsVps           () );
3943}
3944#endif
Note: See TracBrowser for help on using the repository browser.