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

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

H_MV_HLS_7_VPS_P0307_23

Implementation for adoption of (VPS/P0307/VPS VUI extension)

  • Move vps_vui_present_flag to the end of syntax table
  • Remove vps_vui_offset
  • Add vps_non_vui_extension_length and vps_non_vui_extension_data_byte

submitted by Hendry (fhendry@…

  • Property svn:eol-style set to native
File size: 117.6 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    // mark the picture as "unused for reference" if it is not in
1333    // the Reference Picture Set
1334    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
1335    {           
1336      rpcPic->getSlice( 0 )->setReferenced( false );   
1337      rpcPic->setUsedByCurr(0);
1338      rpcPic->setIsLongTerm(0);
1339    }
1340    //check that pictures of higher temporal layers are not used
1341    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
1342    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
1343    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
1344    {
1345      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
1346    }
1347    //check that pictures marked as temporal layer non-reference pictures are not used for reference
1348    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
1349    {
1350      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false);
1351    }
1352  }
1353}
1354
1355/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1356*/
1357Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
1358{
1359  TComPic* rpcPic;
1360  Int i, isAvailable;
1361  Int atLeastOneLost = 0;
1362  Int atLeastOneRemoved = 0;
1363  Int iPocLost = 0;
1364
1365  // loop through all long-term pictures in the Reference Picture Set
1366  // to see if the picture should be kept as reference picture
1367  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
1368  {
1369    isAvailable = 0;
1370    // loop through all pictures in the reference picture buffer
1371    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1372    while ( iterPic != rcListPic.end())
1373    {
1374      rpcPic = *(iterPic++);
1375      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1376      {
1377        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
1378        {
1379          isAvailable = 1;
1380        }
1381      }
1382      else 
1383      {
1384        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1385        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1386        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1387        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
1388        {
1389          isAvailable = 1;
1390        }
1391      }
1392    }
1393    // if there was no such long-term check the short terms
1394    if(!isAvailable)
1395    {
1396      iterPic = rcListPic.begin();
1397      while ( iterPic != rcListPic.end())
1398      {
1399        rpcPic = *(iterPic++);
1400
1401        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1402        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
1403        Int refPoc = pReferencePictureSet->getPOC(i);
1404        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
1405        {
1406          curPoc = curPoc & (pocCycle - 1);
1407          refPoc = refPoc & (pocCycle - 1);
1408        }
1409       
1410        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
1411        {
1412          isAvailable = 1;
1413          rpcPic->setIsLongTerm(1);
1414          break;
1415        }
1416      }
1417    }
1418    // report that a picture is lost if it is in the Reference Picture Set
1419    // but not available as reference picture
1420    if(isAvailable == 0)   
1421    {           
1422      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1423      {
1424        if(!pReferencePictureSet->getUsed(i) )
1425        {
1426          if(printErrors)
1427          {
1428            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1429          }
1430          atLeastOneRemoved = 1;
1431        }
1432        else
1433        {
1434          if(printErrors)
1435          {
1436            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1437          }
1438          atLeastOneLost = 1;
1439          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1440        }
1441      }
1442    }
1443  } 
1444  // loop through all short-term pictures in the Reference Picture Set
1445  // to see if the picture should be kept as reference picture
1446  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
1447  {
1448    isAvailable = 0;
1449    // loop through all pictures in the reference picture buffer
1450    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1451    while ( iterPic != rcListPic.end())
1452    {
1453      rpcPic = *(iterPic++);
1454
1455      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1456      {
1457        isAvailable = 1;
1458      }
1459    }
1460    // report that a picture is lost if it is in the Reference Picture Set
1461    // but not available as reference picture
1462    if(isAvailable == 0)   
1463    {           
1464      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1465      {
1466        if(!pReferencePictureSet->getUsed(i) )
1467        {
1468          if(printErrors)
1469          {
1470            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1471          }
1472          atLeastOneRemoved = 1;
1473        }
1474        else
1475        {
1476          if(printErrors)
1477          {
1478            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1479          }
1480          atLeastOneLost = 1;
1481          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1482        }
1483      }
1484    }
1485  }   
1486  if(atLeastOneLost)
1487  {
1488    return iPocLost+1;
1489  }
1490  if(atLeastOneRemoved)
1491  {
1492    return -2;
1493  }
1494  else
1495  {
1496    return 0;
1497  }
1498}
1499
1500/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1501*/
1502Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
1503{
1504  TComPic* rpcPic;
1505  Int i, j;
1506  Int k = 0;
1507  Int nrOfNegativePictures = 0;
1508  Int nrOfPositivePictures = 0;
1509  TComReferencePictureSet* pcRPS = this->getLocalRPS();
1510
1511  // loop through all pictures in the Reference Picture Set
1512  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1513  {
1514    j = 0;
1515    // loop through all pictures in the reference picture buffer
1516    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1517    while ( iterPic != rcListPic.end())
1518    {
1519      j++;
1520      rpcPic = *(iterPic++);
1521
1522      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1523      {
1524        // This picture exists as a reference picture
1525        // and should be added to the explicit Reference Picture Set
1526        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1527        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
1528        if(pcRPS->getDeltaPOC(k) < 0)
1529        {
1530          nrOfNegativePictures++;
1531        }
1532        else
1533        {
1534          nrOfPositivePictures++;
1535        }
1536        k++;
1537      }
1538    }
1539  }
1540  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1541  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1542  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1543  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1544  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1545  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1546  if (!pReferencePictureSet->getInterRPSPrediction())
1547  {
1548    pcRPS->setInterRPSPrediction(false);
1549    pcRPS->setNumRefIdc(0);
1550  }
1551  else
1552  {
1553    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1554    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1555    TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1556    Int iRefPics = pcRefRPS->getNumberOfPictures();
1557    Int iNewIdc=0;
1558    for(i=0; i<= iRefPics; i++) 
1559    {
1560      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1561      Int iRefIdc = 0;
1562      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1563      {
1564        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
1565        {
1566          if (pcRPS->getUsed(j))
1567          {
1568            iRefIdc = 1;
1569          }
1570          else
1571          {
1572            iRefIdc = 2;
1573          }
1574        }
1575      }
1576      pcRPS->setRefIdc(i, iRefIdc);
1577      iNewIdc++;
1578    }
1579    pcRPS->setInterRPSPrediction(true);
1580    pcRPS->setNumRefIdc(iNewIdc);
1581    pcRPS->setDeltaRPS(deltaRPS); 
1582    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1583  }
1584
1585  this->setRPS(pcRPS);
1586  this->setRPSidx(-1);
1587}
1588
1589/** get AC and DC values for weighted pred
1590 * \param *wp
1591 * \returns Void
1592 */
1593Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
1594{
1595  wp = m_weightACDCParam;
1596}
1597
1598/** init AC and DC values for weighted pred
1599 * \returns Void
1600 */
1601Void  TComSlice::initWpAcDcParam()
1602{
1603  for(Int iComp = 0; iComp < 3; iComp++ )
1604  {
1605    m_weightACDCParam[iComp].iAC = 0;
1606    m_weightACDCParam[iComp].iDC = 0;
1607  }
1608}
1609
1610/** get WP tables for weighted pred
1611 * \param RefPicList
1612 * \param iRefIdx
1613 * \param *&wpScalingParam
1614 * \returns Void
1615 */
1616Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
1617{
1618  wp = m_weightPredTable[e][iRefIdx];
1619}
1620
1621/** reset Default WP tables settings : no weight.
1622 * \param wpScalingParam
1623 * \returns Void
1624 */
1625Void  TComSlice::resetWpScaling()
1626{
1627  for ( Int e=0 ; e<2 ; e++ )
1628  {
1629    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1630    {
1631      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1632      {
1633        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1634        pwp->bPresentFlag      = false;
1635        pwp->uiLog2WeightDenom = 0;
1636        pwp->uiLog2WeightDenom = 0;
1637        pwp->iWeight           = 1;
1638        pwp->iOffset           = 0;
1639      }
1640    }
1641  }
1642}
1643
1644/** init WP table
1645 * \returns Void
1646 */
1647Void  TComSlice::initWpScaling()
1648{
1649  for ( Int e=0 ; e<2 ; e++ )
1650  {
1651    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1652    {
1653      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1654      {
1655        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1656        if ( !pwp->bPresentFlag ) 
1657        {
1658          // Inferring values not present :
1659          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1660          pwp->iOffset = 0;
1661        }
1662
1663        pwp->w      = pwp->iWeight;
1664        Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
1665        pwp->o      = pwp->iOffset << (bitDepth-8);
1666        pwp->shift  = pwp->uiLog2WeightDenom;
1667        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1668      }
1669    }
1670  }
1671}
1672
1673// ------------------------------------------------------------------------------------------------
1674// Video parameter set (VPS)
1675// ------------------------------------------------------------------------------------------------
1676TComVPS::TComVPS()
1677: m_VPSId                     (  0)
1678, m_uiMaxTLayers              (  1)
1679#if H_MV
1680, m_uiMaxLayersMinus1         (  0)
1681#else
1682, m_uiMaxLayers               (  1)
1683#endif
1684, m_bTemporalIdNestingFlag    (false)
1685, m_numHrdParameters          (  0)
1686#if H_MV
1687, m_maxLayerId             (  0)
1688#else
1689, m_maxNuhReservedZeroLayerId (  0)
1690#endif
1691, m_hrdParameters             (NULL)
1692, m_hrdOpSetIdx               (NULL)
1693, m_cprmsPresentFlag          (NULL)
1694#if H_MV
1695, m_dpbSize                   (NULL)
1696, m_vpsVUI                 (  NULL )
1697#endif
1698{
1699  for( Int i = 0; i < MAX_TLAYER; i++)
1700  {
1701    m_numReorderPics[i] = 0;
1702    m_uiMaxDecPicBuffering[i] = 1; 
1703    m_uiMaxLatencyIncrease[i] = 0;
1704  }
1705#if H_MV
1706  for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ )
1707  { 
1708    for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ )
1709    {
1710      m_layerIdIncludedFlag[lsIdx][layerId] = (( lsIdx == 0 ) && ( layerId == 0 )) ; 
1711    }
1712  } 
1713#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1714  m_vpsNumberLayerSetsMinus1     = -1; 
1715#endif
1716  m_vpsNumProfileTierLevelMinus1 = -1; 
1717   
1718#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1719  for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++)
1720  {
1721#if !H_MV_HLS_7_VPS_P0048_14
1722    m_profileRefMinus1[ i ] = -1; 
1723#endif
1724  }
1725   
1726  m_moreOutputLayerSetsThanDefaultFlag = false;   
1727  m_numAddOutputLayerSetsMinus1        = -1;   
1728  m_defaultOneTargetOutputLayerIdc     = 0; 
1729#else
1730  m_numAddOutputLayerSets              = -1;   
1731  m_defaultTargetOutputLayerIdc     = 0; 
1732#endif
1733 
1734  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
1735  {
1736    m_outputLayerSetIdxMinus1[i]  = -1; 
1737    m_profileLevelTierIdx[i]      = 0; 
1738    for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
1739    {
1740      m_outputLayerFlag[i][j] = false; 
1741    }
1742#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1743    m_altOutputLayerFlag[ i ]       = false; 
1744#endif
1745  }
1746#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
1747  m_altOutputLayerFlag       = false; 
1748#endif
1749  m_maxOneActiveRefLayerFlag = false; 
1750  m_directDepTypeLenMinus2   = 0;         
1751 
1752
1753  m_avcBaseLayerFlag = false;
1754#if H_MV_HLS_7_VPS_P0307_23
1755  m_vpsNonVuiExtensionLength = 0;
1756#else
1757  m_vpsVuiOffset     = 0; 
1758#endif
1759  m_splittingFlag    = false;
1760 
1761  for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
1762  {
1763    m_scalabilityMaskFlag[i] = false;
1764    m_dimensionIdLen [i]  = -1; 
1765  }
1766
1767  m_vpsNuhLayerIdPresentFlag = false;
1768
1769  for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
1770  {
1771    m_vpsProfilePresentFlag   [i] = false;
1772#if !H_MV_HLS_7_VPS_P0048_14
1773    m_profileRefMinus1[i] = 0;
1774#endif
1775    m_outputLayerSetIdxMinus1       [i] = 0;
1776    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
1777    {
1778      m_outputLayerFlag[i][j] = false;
1779    }
1780  }
1781
1782  for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
1783  {
1784    m_layerIdInVps[i] =  (i == 0 ) ? 0 : -1;         
1785  }
1786
1787  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1788  {
1789    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
1790    m_numDirectRefLayers[i] = 0; 
1791    m_vpsRepFormatIdx    [i] = 0; 
1792    m_pocLsbNotPresentFlag[i] = 0;
1793    m_repFormat          [i] = NULL; 
1794    m_viewIdVal          [i] = 0; 
1795
1796#if H_3D
1797    m_viewIndex         [i] = -1; 
1798    m_vpsDepthModesFlag [i] = false;
1799    m_ivMvScalingFlag = true; 
1800#endif
1801
1802    for( Int j = 0; j < MAX_NUM_LAYERS; j++ )
1803    {
1804      m_directDependencyFlag[i][j] = false;
1805      m_directDependencyType[i][j] = -1; 
1806      m_refLayerId[i][j]           = -1; 
1807      m_maxTidIlRefPicsPlus1[i][j]  = 7;
1808    }
1809
1810    for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ )
1811    {
1812      m_dimensionId[i][j] = 0;
1813    }
1814#if H_3D_ARP
1815    m_uiUseAdvResPred[i]  = 0;
1816    m_uiARPStepNum[i]     = 1;
1817#endif
1818  }
1819  m_vpsVUI = new TComVPSVUI; 
1820  m_dpbSize = new TComDpbSize; 
1821
1822#if H_3D
1823  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1824  {
1825#if H_3D_IV_MERGE
1826    m_ivMvPredFlag         [ i ] = false;
1827#if H_3D_SPIVMP
1828    m_iSubPULog2Size       [ i ] = 0;
1829#endif
1830#endif
1831#if H_3D_VSP
1832    m_viewSynthesisPredFlag[ i ] = false;
1833#endif
1834#if H_3D_NBDV_REF
1835    m_depthRefinementFlag  [ i ] = false;
1836#endif
1837#if H_3D_INTER_SDC
1838    m_bInterSDCFlag        [ i ] = false;
1839#endif
1840#if H_3D_DBBP
1841    m_dbbpFlag             [ i ] = false;
1842#endif
1843#if H_3D_IV_MERGE
1844    m_bMPIFlag             [ i ] = false;
1845#endif
1846  } 
1847#endif
1848#endif
1849}
1850
1851TComVPS::~TComVPS()
1852{
1853  if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
1854  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
1855  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
1856#if H_MV
1857  if ( m_vpsVUI          != NULL )     delete m_vpsVUI; 
1858  if ( m_dpbSize         != NULL )     delete m_dpbSize; 
1859
1860  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
1861  {
1862    if (m_repFormat[ i ] != NULL )      delete m_repFormat[ i ];   
1863  }
1864#endif
1865#if H_3D
1866  deleteCamPars();
1867#endif
1868}
1869
1870#if H_MV
1871
1872Bool TComVPS::checkVPSExtensionSyntax()
1873{
1874  for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
1875  {
1876    // check layer_id_in_nuh constraint
1877    assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
1878  }
1879  return true; 
1880}
1881
1882Int TComVPS::getNumScalabilityTypes()
1883{
1884  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
1885}
1886
1887Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
1888{
1889  assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
1890  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
1891  Int scalIdx = 0; 
1892  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
1893  {
1894    scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
1895
1896  }
1897
1898  return scalIdx; 
1899}
1900Void TComVPS::setScalabilityMaskFlag( UInt val )
1901{
1902  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
1903  {
1904    setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 );
1905  }
1906}
1907
1908Void TComVPS::setRefLayers()
1909{
1910  for( Int i = 0; i  <= getMaxLayersMinus1(); i++ )
1911  {
1912    Int iNuhLId = getLayerIdInNuh( i ); 
1913    m_numDirectRefLayers[ iNuhLId ] = 0; 
1914    for( Int j = 0; j < i; j++ )
1915    {
1916      if( getDirectDependencyFlag(i , j) )
1917      {
1918        m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j );
1919      }
1920    }
1921  }
1922}
1923
1924Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx )
1925{
1926  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] );     
1927  Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ];   
1928  assert ( refLayerIdInNuh >= 0 ); 
1929  return refLayerIdInNuh;
1930}
1931
1932Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
1933{
1934  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
1935}
1936
1937#if H_3D
1938Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
1939{
1940  Int foundLayerIdinNuh = -1; 
1941
1942  for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ )
1943  {
1944    Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); 
1945    if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) )  )
1946    {
1947      foundLayerIdinNuh = layerIdInNuh; 
1948      break; 
1949    }
1950  }
1951  assert( foundLayerIdinNuh != -1 ); 
1952
1953  return foundLayerIdinNuh;
1954}
1955
1956Void TComVPS::createCamPars(Int iNumViews)
1957{
1958  Int i = 0, j = 0;
1959
1960  m_bCamParPresent = new Bool[ iNumViews ];
1961  m_bCamParInSliceHeader = new Bool[ iNumViews ];
1962
1963  m_aaaiCodedScale = new Int**[ iNumViews ];
1964  m_aaaiCodedOffset = new Int**[ iNumViews ];
1965  for ( i = 0; i < iNumViews ; i++ )
1966  {
1967    m_bCamParInSliceHeader[i] = false; 
1968    m_aaaiCodedScale[i] = new Int*[ 2 ];
1969    m_aaaiCodedOffset[i] = new Int*[ 2 ];
1970    for ( j = 0; j < 2; j++ )
1971    {
1972      m_aaaiCodedScale[i][j] = new Int[ MAX_NUM_LAYERS ];
1973      m_aaaiCodedOffset[i][j] = new Int[ MAX_NUM_LAYERS ];
1974      for ( Int k = 0; k < MAX_NUM_LAYERS; k++ )
1975      {
1976        m_aaaiCodedScale[i][j][k] = 0;
1977        m_aaaiCodedOffset[i][j][k] = 0;
1978      }
1979    }
1980  }
1981}
1982
1983Void TComVPS::deleteCamPars()
1984{
1985  Int iNumViews = getNumViews();
1986  Int i = 0, j = 0;
1987
1988  if ( m_bCamParPresent != NULL )
1989  {
1990    delete [] m_bCamParPresent;
1991  }
1992  if ( m_bCamParInSliceHeader != NULL )
1993  {
1994    delete [] m_bCamParInSliceHeader;
1995  }
1996
1997  if ( m_aaaiCodedScale != NULL )
1998  {
1999    for ( i = 0; i < iNumViews ; i++ )
2000    {
2001      for ( j = 0; j < 2; j++ )
2002      {
2003        delete [] m_aaaiCodedScale[i][j];
2004      }
2005      delete [] m_aaaiCodedScale[i];
2006    }
2007    delete [] m_aaaiCodedScale;
2008  }
2009
2010  if ( m_aaaiCodedOffset != NULL )
2011  {
2012    for ( i = 0; i < iNumViews ; i++ )
2013    {
2014      for ( j = 0; j < 2; j++ )
2015      {
2016        delete [] m_aaaiCodedOffset[i][j];
2017      }
2018      delete [] m_aaaiCodedOffset[i];
2019    }
2020    delete [] m_aaaiCodedOffset;
2021  }
2022}
2023
2024
2025Void
2026  TComVPS::initCamParaVPS( UInt uiViewIndex, Bool bCamParPresent, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
2027{
2028  AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); 
2029
2030  m_uiCamParPrecision = ( ( uiViewIndex != 0 )? uiCamParPrecision : 0 );
2031  m_bCamParPresent[ uiViewIndex ] = (( uiViewIndex != 0 )? bCamParPresent  : false );
2032  m_bCamParInSliceHeader[ uiViewIndex ]  = ( (uiViewIndex != 0)? bCamParSlice  : false );
2033
2034  if( !m_bCamParInSliceHeader[ uiViewIndex ] )
2035  {
2036    for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
2037    {
2038      m_aaaiCodedScale [ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][     uiViewIndex ];
2039      m_aaaiCodedScale [ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiScale [     uiViewIndex ][ uiBaseViewIndex ];
2040      m_aaaiCodedOffset[ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][     uiViewIndex ];
2041      m_aaaiCodedOffset[ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiOffset[     uiViewIndex ][ uiBaseViewIndex ];
2042    }
2043  }
2044}
2045
2046#endif // H_3D
2047
2048
2049Int TComVPS::xGetDimBitOffset( Int j )
2050{
2051  Int dimBitOffset = 0; 
2052  if ( getSplittingFlag() && j == getNumScalabilityTypes() )
2053  {
2054     dimBitOffset = 6; 
2055  }
2056  else
2057  {
2058    for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++)
2059    {
2060      dimBitOffset += getDimensionIdLen( dimIdx ); 
2061    }
2062  }
2063  return dimBitOffset; 
2064}
2065
2066Int TComVPS::inferDimensionId( Int i, Int j )
2067{
2068    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); 
2069}
2070
2071Int TComVPS::inferLastDimsionIdLenMinus1()
2072{
2073  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); 
2074}
2075
2076Int TComVPS::getNumLayersInIdList( Int lsIdx )
2077{
2078  assert( lsIdx >= 0 ); 
2079  assert( lsIdx <= getVpsNumLayerSetsMinus1() ); 
2080  return (Int) m_layerSetLayerIdList[ lsIdx ].size(); 
2081}
2082
2083Int    TComVPS::getNumOutputLayerSets() 
2084{
2085#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
2086  return getNumAddOutputLayerSets() + getVpsNumLayerSetsMinus1() + 1; 
2087#else
2088  Int numOutputLayerSets = getVpsNumberLayerSetsMinus1( ) + 1; 
2089  if ( getMoreOutputLayerSetsThanDefaultFlag( ) )
2090  {     
2091    numOutputLayerSets += (getNumAddOutputLayerSetsMinus1( ) + 1); 
2092}
2093  return numOutputLayerSets; 
2094#endif
2095}
2096
2097Int TComVPS::getNumViews()
2098{
2099  Int numViews = 1; 
2100  for( Int i = 0; i <=  getMaxLayersMinus1(); i++ )
2101  {
2102    Int lId = getLayerIdInNuh( i ); 
2103    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
2104    {
2105      numViews++; 
2106    }   
2107  }
2108
2109  return numViews;
2110}
2111
2112Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ )
2113{
2114  assert( depth < 65 ); 
2115  Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); 
2116
2117  for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ )
2118  {
2119    if ( getDirectDependencyFlag( depLayeridInVps, i ) )
2120    {
2121      dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); 
2122    }
2123  }
2124  return dependentFlag;
2125}
2126
2127Void TComVPS::deriveLayerSetLayerIdList()
2128{
2129  m_layerSetLayerIdList.resize( getVpsNumLayerSetsMinus1() + 1 ); 
2130  for (Int i = 0; i <= getVpsNumLayerSetsMinus1(); i++ )
2131  {
2132    for( Int m = 0; m  <= getVpsMaxLayerId(); m++ )
2133    {
2134      if( getLayerIdIncludedFlag( i, m) ) 
2135      {
2136        m_layerSetLayerIdList[ i ].push_back( m );       
2137      }
2138    }
2139  }
2140}
2141
2142#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
2143Void TComVPS::initTargetLayerIdLists()
2144{
2145  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); 
2146  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); 
2147}
2148
2149Void TComVPS::deriveTargetLayerIdList( Int i )
2150{ 
2151  Int lsIdx = getLayerSetIdxForOutputLayerSet( i );     
2152 
2153  for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
2154  {
2155    m_targetDecLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); 
2156    if( getOutputLayerFlag( i, j  ))
2157    {
2158      m_targetOptLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
2159    }
2160  } 
2161}
2162#else
2163Void TComVPS::deriveTargetLayerIdLists()
2164{
2165  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); 
2166  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); 
2167
2168  for (Int targetOptLayerSetIdx = 0; targetOptLayerSetIdx < getNumOutputLayerSets(); targetOptLayerSetIdx++ )
2169  {
2170    Int targetDecLayerSetIdx = getOutputLayerSetIdxMinus1( targetOptLayerSetIdx ) + 1;     
2171    Int lsIdx                = targetDecLayerSetIdx;
2172
2173    for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
2174    {
2175      m_targetDecLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); 
2176      if( getOutputLayerFlag( targetOptLayerSetIdx, j  )) // This seems to be wrong in draft text
2177      {
2178        m_targetOptLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
2179      }
2180    } 
2181  }
2182}
2183#endif
2184
2185#endif // H_MV
2186
2187// ------------------------------------------------------------------------------------------------
2188// Sequence parameter set (SPS)
2189// ------------------------------------------------------------------------------------------------
2190
2191TComSPS::TComSPS()
2192: m_SPSId                     (  0)
2193, m_VPSId                     (  0)
2194, m_chromaFormatIdc           (CHROMA_420)
2195, m_uiMaxTLayers              (  1)
2196// Structure
2197, m_picWidthInLumaSamples     (352)
2198, m_picHeightInLumaSamples    (288)
2199, m_log2MinCodingBlockSize    (  0)
2200, m_log2DiffMaxMinCodingBlockSize (0)
2201, m_uiMaxCUWidth              ( 32)
2202, m_uiMaxCUHeight             ( 32)
2203, m_uiMaxCUDepth              (  3)
2204, m_bLongTermRefsPresent      (false)
2205, m_uiQuadtreeTULog2MaxSize   (  0)
2206, m_uiQuadtreeTULog2MinSize   (  0)
2207, m_uiQuadtreeTUMaxDepthInter (  0)
2208, m_uiQuadtreeTUMaxDepthIntra (  0)
2209// Tool list
2210, m_usePCM                   (false)
2211, m_pcmLog2MaxSize            (  5)
2212, m_uiPCMLog2MinSize          (  7)
2213#if H_3D_QTLPC
2214, m_bUseQTL                   (false)
2215, m_bUsePC                    (false)
2216#endif
2217, m_bitDepthY                 (  8)
2218, m_bitDepthC                 (  8)
2219, m_qpBDOffsetY               (  0)
2220, m_qpBDOffsetC               (  0)
2221, m_uiPCMBitDepthLuma         (  8)
2222, m_uiPCMBitDepthChroma       (  8)
2223, m_bPCMFilterDisableFlag     (false)
2224, m_uiBitsForPOC              (  8)
2225, m_numLongTermRefPicSPS    (  0) 
2226, m_uiMaxTrSize               ( 32)
2227, m_bUseSAO                   (false) 
2228, m_bTemporalIdNestingFlag    (false)
2229, m_scalingListEnabledFlag    (false)
2230, m_useStrongIntraSmoothing   (false)
2231, m_vuiParametersPresentFlag  (false)
2232, m_vuiParameters             ()
2233#if H_MV
2234, m_pcVPS                     ( NULL )
2235, m_spsInferScalingListFlag   ( false )
2236, m_spsScalingListRefLayerId  ( 0 )
2237
2238, m_updateRepFormatFlag       ( false ) 
2239, m_spsRepFormatIdx           ( 0 )
2240, m_interViewMvVertConstraintFlag (false)
2241#endif
2242#if H_3D
2243, m_bCamParInSliceHeader      (false)
2244#endif
2245{
2246  for ( Int i = 0; i < MAX_TLAYER; i++ )
2247  {
2248    m_uiMaxLatencyIncrease[i] = 0;
2249    m_uiMaxDecPicBuffering[i] = 1;
2250    m_numReorderPics[i]       = 0;
2251  }
2252  m_scalingList = new TComScalingList;
2253  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
2254  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
2255#if H_MV
2256  m_spsExtensionFlag = false; 
2257  for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) 
2258  {
2259    m_spsExtensionTypeFlag[ i ] = false;
2260  }
2261  m_numScaledRefLayerOffsets = 0; 
2262
2263  for (Int i = 0; i < MAX_NUM_SCALED_REF_LAYERS; i++ )
2264  {
2265    m_scaledRefLayerId             [i] = -1;
2266  }
2267
2268  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
2269  {
2270    m_scaledRefLayerLeftOffset     [i] = 0;
2271    m_scaledRefLayerTopOffset      [i] = 0;
2272    m_scaledRefLayerRightOffset    [i] = 0;
2273    m_scaledRefLayerBottomOffset   [i] = 0;
2274  }
2275#endif
2276}
2277
2278TComSPS::~TComSPS()
2279{
2280  delete m_scalingList;
2281  m_RPSList.destroy();
2282}
2283
2284Void  TComSPS::createRPSList( Int numRPS )
2285{ 
2286  m_RPSList.destroy();
2287  m_RPSList.create(numRPS);
2288}
2289
2290Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
2291{
2292  if( !getVuiParametersPresentFlag() )
2293  {
2294    return;
2295  }
2296
2297  TComVUI *vui = getVuiParameters();
2298  TComHRD *hrd = vui->getHrdParameters();
2299
2300  TimingInfo *timingInfo = vui->getTimingInfo();
2301  timingInfo->setTimingInfoPresentFlag( true );
2302  switch( frameRate )
2303  {
2304  case 24:
2305    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
2306    break;
2307  case 25:
2308    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
2309    break;
2310  case 30:
2311    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
2312    break;
2313  case 50:
2314    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
2315    break;
2316  case 60:
2317    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
2318    break;
2319  default:
2320    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
2321    break;
2322  }
2323
2324  Bool rateCnt = ( bitRate > 0 );
2325  hrd->setNalHrdParametersPresentFlag( rateCnt );
2326  hrd->setVclHrdParametersPresentFlag( rateCnt );
2327
2328  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
2329
2330  if( hrd->getSubPicCpbParamsPresentFlag() )
2331  {
2332    hrd->setTickDivisorMinus2( 100 - 2 );                          //
2333    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
2334    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
2335    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
2336  }
2337  else
2338  {
2339    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
2340  }
2341
2342  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
2343  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2344  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2345 
2346  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
2347  if( randomAccess )
2348  {
2349    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
2350    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
2351  }
2352  else
2353  {
2354    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
2355    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
2356  }
2357
2358/*
2359   Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
2360*/
2361  Int i, j;
2362  UInt birateValue, cpbSizeValue;
2363  UInt ducpbSizeValue;
2364  UInt duBitRateValue = 0;
2365
2366  for( i = 0; i < MAX_TLAYER; i ++ )
2367  {
2368    hrd->setFixedPicRateFlag( i, 1 );
2369    hrd->setPicDurationInTcMinus1( i, 0 );
2370    hrd->setLowDelayHrdFlag( i, 0 );
2371    hrd->setCpbCntMinus1( i, 0 );
2372
2373    birateValue  = bitRate;
2374    cpbSizeValue = bitRate;                                     // 1 second
2375    ducpbSizeValue = bitRate/numDU;
2376    duBitRateValue = bitRate;
2377    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
2378    {
2379      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
2380      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
2381      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
2382      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
2383
2384      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
2385      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
2386      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
2387      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
2388      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
2389    }
2390  }
2391}
2392const Int TComSPS::m_winUnitX[]={1,2,2,1};
2393const Int TComSPS::m_winUnitY[]={1,2,1,1};
2394
2395TComPPS::TComPPS()
2396: m_PPSId                       (0)
2397, m_SPSId                       (0)
2398, m_picInitQPMinus26            (0)
2399, m_useDQP                      (false)
2400, m_bConstrainedIntraPred       (false)
2401, m_bSliceChromaQpFlag          (false)
2402, m_pcSPS                       (NULL)
2403, m_uiMaxCuDQPDepth             (0)
2404, m_uiMinCuDQPSize              (0)
2405, m_chromaCbQpOffset            (0)
2406, m_chromaCrQpOffset            (0)
2407, m_numRefIdxL0DefaultActive    (1)
2408, m_numRefIdxL1DefaultActive    (1)
2409, m_TransquantBypassEnableFlag  (false)
2410, m_useTransformSkip             (false)
2411, m_dependentSliceSegmentsEnabledFlag    (false)
2412, m_tilesEnabledFlag               (false)
2413, m_entropyCodingSyncEnabledFlag   (false)
2414, m_loopFilterAcrossTilesEnabledFlag  (true)
2415, m_uniformSpacingFlag           (0)
2416, m_iNumColumnsMinus1            (0)
2417, m_puiColumnWidth               (NULL)
2418, m_iNumRowsMinus1               (0)
2419, m_puiRowHeight                 (NULL)
2420, m_iNumSubstreams             (1)
2421, m_signHideFlag(0)
2422, m_cabacInitPresentFlag        (false)
2423, m_encCABACTableIdx            (I_SLICE)
2424, m_sliceHeaderExtensionPresentFlag    (false)
2425, m_loopFilterAcrossSlicesEnabledFlag (false)
2426, m_listsModificationPresentFlag(  0)
2427, m_numExtraSliceHeaderBits(0)
2428#if H_MV
2429, m_ppsInferScalingListFlag(false)
2430, m_ppsScalingListRefLayerId(0)
2431#if H_3D
2432, m_pcDLT(NULL)
2433#endif
2434#endif
2435{
2436  m_scalingList = new TComScalingList;
2437
2438#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION 
2439  for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) 
2440  {
2441    m_ppsExtensionTypeFlag[ i ] = false;
2442  }
2443#endif
2444
2445}
2446
2447TComPPS::~TComPPS()
2448{
2449  if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 )
2450  {
2451    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
2452    m_puiColumnWidth = NULL;
2453  }
2454  if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 )
2455  {
2456    if (m_puiRowHeight) delete [] m_puiRowHeight;
2457    m_puiRowHeight = NULL;
2458  }
2459  delete m_scalingList;
2460}
2461
2462#if H_3D
2463TComDLT::TComDLT()
2464: m_bDltPresentFlag(false)
2465, m_iNumDepthViews(0)
2466, m_uiDepthViewBitDepth(8)
2467{
2468  m_uiDepthViewBitDepth = g_bitDepthY; 
2469
2470  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2471  {
2472    m_bUseDLTFlag                 [i] = false;
2473    m_bInterViewDltPredEnableFlag [i] = false;
2474
2475    // allocate some memory and initialize with default mapping
2476    m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1;
2477    m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]);
2478
2479    m_iDepthValue2Idx[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
2480    m_iIdx2DepthValue[i]    = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]);
2481
2482    //default mapping
2483    for (Int d=0; d<m_iNumDepthmapValues[i]; d++)
2484    {
2485      m_iDepthValue2Idx[i][d] = d;
2486      m_iIdx2DepthValue[i][d] = d;
2487    }
2488  }
2489}
2490
2491TComDLT::~TComDLT()
2492{
2493  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
2494  {
2495    if ( m_iDepthValue2Idx[i] != NULL ) 
2496    {
2497      xFree( m_iDepthValue2Idx[i] );
2498      m_iDepthValue2Idx[i] = NULL; 
2499    }
2500
2501    if ( m_iIdx2DepthValue[i] != NULL ) 
2502    {
2503      xFree( m_iIdx2DepthValue[i] );
2504      m_iIdx2DepthValue[i] = NULL; 
2505    }
2506  }
2507}
2508
2509Void TComDLT::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues)
2510{
2511  if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only
2512    return;
2513
2514  // copy idx2DepthValue to internal array
2515  memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt));
2516
2517  UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
2518  for(Int p=0; p<=uiMaxDepthValue; p++)
2519  {
2520    Int iIdxDown    = 0;
2521    Int iIdxUp      = iNumDepthValues-1;
2522    Bool bFound     = false;
2523
2524    // iterate over indices to find lower closest depth
2525    Int i = 1;
2526    while(!bFound && i<iNumDepthValues)
2527    {
2528      if( m_iIdx2DepthValue[layerIdInVps][i] > p )
2529      {
2530        iIdxDown  = i-1;
2531        bFound    = true;
2532      }
2533
2534      i++;
2535    }
2536    // iterate over indices to find upper closest depth
2537    i = iNumDepthValues-2;
2538    bFound = false;
2539    while(!bFound && i>=0)
2540    {
2541      if( m_iIdx2DepthValue[layerIdInVps][i] < p )
2542      {
2543        iIdxUp  = i+1;
2544        bFound    = true;
2545      }
2546
2547      i--;
2548    }
2549
2550    // assert monotony
2551    assert(iIdxDown<=iIdxUp);
2552
2553    // assign closer depth value/idx
2554    if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) )
2555    {
2556      m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown;
2557    }
2558    else
2559    {
2560      m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp;
2561    }
2562
2563  }
2564
2565  // update DLT variables
2566  m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues;
2567  m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]);
2568}
2569
2570#if H_3D_DELTA_DLT
2571Void TComDLT::getDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTOut, UInt *puiDeltaDLTOutNum )
2572{
2573  Bool abBM0[ 256 ];
2574  Bool abBM1[ 256 ];
2575 
2576  memset( abBM0, 0, sizeof( abBM0 ));
2577  memset( abBM1, 0, sizeof( abBM1 ));
2578 
2579  // convert reference DLT to bit string
2580  for( Int i = 0; i < uiDLTInRefNum; i++ )
2581  {
2582    abBM0[ piDLTInRef[ i ] ] = true;
2583  }
2584  // convert internal DLT to bit string
2585  for( Int i = 0; i < m_iNumDepthmapValues[ layerIdInVps ]; i++ )
2586  {
2587    abBM1[ m_iIdx2DepthValue[ layerIdInVps ][ i ] ] = true;
2588  }
2589 
2590  *puiDeltaDLTOutNum = 0;
2591  for( Int i = 0; i < 256; i++ )
2592  {
2593    if( abBM0[ i ] ^ abBM1[ i ] )
2594    {
2595      piDeltaDLTOut[ *puiDeltaDLTOutNum ] = i;
2596      *puiDeltaDLTOutNum = *puiDeltaDLTOutNum + 1;
2597    }
2598  }
2599}
2600
2601Void TComDLT::setDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTIn, UInt uiDeltaDLTInNum )
2602{
2603  Bool abBM0[ 256 ];
2604  Bool abBM1[ 256 ];
2605 
2606  memset( abBM0, 0, sizeof( abBM0 ));
2607  memset( abBM1, 0, sizeof( abBM1 ));
2608 
2609  // convert reference DLT to bit string
2610  for( Int i = 0; i < uiDLTInRefNum; i++ )
2611  {
2612    abBM0[ piDLTInRef[ i ] ] = true;
2613  }
2614  // convert delta DLT to bit string
2615  for( Int i = 0; i < uiDeltaDLTInNum; i++ )
2616  {
2617    abBM1[ piDeltaDLTIn[ i ] ] = true;
2618  }
2619 
2620  Int aiIdx2DepthValue[256];
2621  UInt uiNumDepthValues = 0;
2622  memset( aiIdx2DepthValue, 0, sizeof( aiIdx2DepthValue ));
2623 
2624  for( Int i = 0; i < 256; i++ )
2625  {
2626    if( abBM0[ i ] ^ abBM1[ i ] )
2627    {
2628      aiIdx2DepthValue[ uiNumDepthValues++ ] = i;
2629    }
2630  }
2631 
2632  // update internal tables
2633  setDepthLUTs(layerIdInVps, aiIdx2DepthValue, uiNumDepthValues);
2634}
2635#endif
2636
2637#endif
2638
2639#if H_MV
2640Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
2641{
2642  if ( layerIdCurr > 0 )
2643  { 
2644    Int            repFormatIdx = getUpdateRepFormatFlag() ?  getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ;
2645    TComRepFormat* repFormat    = vps->getRepFormat( repFormatIdx ); 
2646      setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() );         
2647      //// ToDo: add when supported:
2648      // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ;
2649
2650      setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  ); 
2651      setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); 
2652
2653      setBitDepthY             ( repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
2654      setQpBDOffsetY           ( (Int) (6*( getBitDepthY() - 8 )) );
2655
2656      setBitDepthC             ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
2657      setQpBDOffsetC           ( (Int) (6* ( getBitDepthC() -8 ) ) );
2658    if ( getLayerId() > 0 && getUpdateRepFormatFlag() )
2659    {
2660      assert( getChromaFormatIdc()      <=  repFormat->getChromaFormatVpsIdc()         ); 
2661      //// ToDo: add when supported:
2662      // assert( getSeperateColourPlaneFlag() <=  repFormat->getSeparateColourPlaneVpsFlag() ) ;
2663
2664      assert( getPicWidthInLumaSamples()  <= repFormat->getPicWidthVpsInLumaSamples()    ); 
2665      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   ); 
2666
2667      assert( getBitDepthY()              <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
2668      assert( getBitDepthC()              <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
2669    }
2670  }
2671
2672  // Set conformance window
2673  Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ;
2674  getConformanceWindow().scaleOffsets( scal );
2675  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
2676}
2677
2678Void TComSPS::inferScalingList( TComSPS* spsSrc )
2679{
2680  if ( getSpsInferScalingListFlag() ) 
2681  {
2682    assert( spsSrc != NULL ); 
2683    assert( !spsSrc->getSpsInferScalingListFlag() );             
2684    getScalingList()->inferFrom( spsSrc->getScalingList() ); 
2685  }
2686}
2687#endif
2688
2689TComReferencePictureSet::TComReferencePictureSet()
2690: m_numberOfPictures (0)
2691, m_numberOfNegativePictures (0)
2692, m_numberOfPositivePictures (0)
2693, m_numberOfLongtermPictures (0)
2694, m_interRPSPrediction (0) 
2695, m_deltaRIdxMinus1 (0)   
2696, m_deltaRPS (0) 
2697, m_numRefIdc (0) 
2698{
2699  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
2700  ::memset( m_POC, 0, sizeof(m_POC) );
2701  ::memset( m_used, 0, sizeof(m_used) );
2702  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
2703}
2704
2705TComReferencePictureSet::~TComReferencePictureSet()
2706{
2707}
2708
2709Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
2710{
2711  m_used[bufferNum] = used;
2712}
2713
2714Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
2715{
2716  m_deltaPOC[bufferNum] = deltaPOC;
2717}
2718
2719Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
2720{
2721  m_numberOfPictures = numberOfPictures;
2722}
2723
2724Int TComReferencePictureSet::getUsed(Int bufferNum)
2725{
2726  return m_used[bufferNum];
2727}
2728
2729Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
2730{
2731  return m_deltaPOC[bufferNum];
2732}
2733
2734Int TComReferencePictureSet::getNumberOfPictures()
2735{
2736  return m_numberOfPictures;
2737}
2738
2739Int TComReferencePictureSet::getPOC(Int bufferNum)
2740{
2741  return m_POC[bufferNum];
2742}
2743
2744Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
2745{
2746  m_POC[bufferNum] = POC;
2747}
2748
2749Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
2750{
2751  return m_bCheckLTMSB[bufferNum];
2752}
2753
2754Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
2755{
2756  m_bCheckLTMSB[bufferNum] = b;
2757}
2758
2759/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
2760 * \param uiBufferNum
2761 * \param iRefIdc
2762 * \returns Void
2763 */
2764Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
2765{
2766  m_refIdc[bufferNum] = refIdc;
2767}
2768
2769/** get the reference idc value at uiBufferNum
2770 * \param uiBufferNum
2771 * \returns Int
2772 */
2773Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
2774{
2775  return m_refIdc[bufferNum];
2776}
2777
2778/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
2779 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
2780 *  +ve values are in increasing order.
2781 * \returns Void
2782 */
2783Void TComReferencePictureSet::sortDeltaPOC()
2784{
2785  // sort in increasing order (smallest first)
2786  for(Int j=1; j < getNumberOfPictures(); j++)
2787  { 
2788    Int deltaPOC = getDeltaPOC(j);
2789    Bool used = getUsed(j);
2790    for (Int k=j-1; k >= 0; k--)
2791    {
2792      Int temp = getDeltaPOC(k);
2793      if (deltaPOC < temp)
2794      {
2795        setDeltaPOC(k+1, temp);
2796        setUsed(k+1, getUsed(k));
2797        setDeltaPOC(k, deltaPOC);
2798        setUsed(k, used);
2799      }
2800    }
2801  }
2802  // flip the negative values to largest first
2803  Int numNegPics = getNumberOfNegativePictures();
2804  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
2805  { 
2806    Int deltaPOC = getDeltaPOC(j);
2807    Bool used = getUsed(j);
2808    setDeltaPOC(j, getDeltaPOC(k));
2809    setUsed(j, getUsed(k));
2810    setDeltaPOC(k, deltaPOC);
2811    setUsed(k, used);
2812  }
2813}
2814
2815/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
2816 *  A "*" is added to the deltaPOC value if it is Used bu current.
2817 * \returns Void
2818 */
2819Void TComReferencePictureSet::printDeltaPOC()
2820{
2821  printf("DeltaPOC = { ");
2822  for(Int j=0; j < getNumberOfPictures(); j++)
2823  {
2824    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
2825  } 
2826  if (getInterRPSPrediction()) 
2827  {
2828    printf("}, RefIdc = { ");
2829    for(Int j=0; j < getNumRefIdc(); j++)
2830    {
2831      printf("%d ", getRefIdc(j));
2832    } 
2833  }
2834  printf("}\n");
2835}
2836
2837TComRPSList::TComRPSList()
2838:m_referencePictureSets (NULL)
2839{
2840}
2841
2842TComRPSList::~TComRPSList()
2843{
2844}
2845
2846Void TComRPSList::create( Int numberOfReferencePictureSets)
2847{
2848  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2849  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
2850}
2851
2852Void TComRPSList::destroy()
2853{
2854  if (m_referencePictureSets)
2855  {
2856    delete [] m_referencePictureSets;
2857  }
2858  m_numberOfReferencePictureSets = 0;
2859  m_referencePictureSets = NULL;
2860}
2861
2862
2863
2864TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
2865{
2866  return &m_referencePictureSets[referencePictureSetNum];
2867}
2868
2869Int TComRPSList::getNumberOfReferencePictureSets()
2870{
2871  return m_numberOfReferencePictureSets;
2872}
2873
2874Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
2875{
2876  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2877}
2878
2879TComRefPicListModification::TComRefPicListModification()
2880: m_bRefPicListModificationFlagL0 (false)
2881, m_bRefPicListModificationFlagL1 (false)
2882{
2883  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
2884  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
2885}
2886
2887TComRefPicListModification::~TComRefPicListModification()
2888{
2889}
2890
2891TComScalingList::TComScalingList()
2892{
2893  init();
2894}
2895TComScalingList::~TComScalingList()
2896{
2897  destroy();
2898}
2899
2900/** set default quantization matrix to array
2901*/
2902Void TComSlice::setDefaultScalingList()
2903{
2904  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2905  {
2906    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2907    {
2908      getScalingList()->processDefaultMatrix(sizeId, listId);
2909    }
2910  }
2911}
2912/** check if use default quantization matrix
2913 * \returns true if use default quantization matrix in all size
2914*/
2915Bool TComSlice::checkDefaultScalingList()
2916{
2917  UInt defaultCounter=0;
2918
2919  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2920  {
2921    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2922    {
2923      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
2924     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
2925      {
2926        defaultCounter++;
2927      }
2928    }
2929  }
2930  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
2931}
2932
2933#if H_MV
2934Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
2935{
2936  refPicSetInterLayer0.clear(); 
2937  refPicSetInterLayer1.clear(); 
2938
2939  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
2940  {
2941    Int layerIdRef = getRefPicLayerId( i ); 
2942    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
2943    assert ( picRef != 0 ); 
2944
2945    picRef->getPicYuvRec()->extendPicBorder(); 
2946    picRef->setIsLongTerm( true );       
2947    picRef->getSlice(0)->setReferenced( true );       
2948
2949    Int viewIdCur  = getVPS()->getViewId( getLayerId() ); 
2950    Int viewIdZero = getVPS()->getViewId( 0 );
2951    Int viewIdRef  = getVPS()->getViewId( layerIdRef ); 
2952
2953    if (  ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) )
2954    {
2955      refPicSetInterLayer0.push_back( picRef ); 
2956    }
2957    else
2958    {
2959      refPicSetInterLayer1.push_back( picRef ); 
2960    }
2961    // Consider to check here:
2962    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "   
2963#if H_MV_HLS7_GEN
2964    // "There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1".   
2965#endif
2966  }
2967}
2968
2969Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
2970{
2971  // Mark as shortterm
2972  for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
2973  {
2974    refPicSetInterLayer0[i]->setIsLongTerm( false ); 
2975  }
2976
2977  for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) 
2978  {
2979    refPicSetInterLayer1[i]->setIsLongTerm( false ); 
2980  }
2981
2982}
2983Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
2984{
2985  // Fill targetDecLayerIdSet with all layers if empty (at encoder side)
2986  if (targetDecLayerIdSet.size() == 0 )   
2987  {
2988    for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ )
2989    {
2990      targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); 
2991    }
2992  }     
2993
2994  Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); 
2995  Int latestDecIdx; 
2996  for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++)
2997  {
2998    if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId )
2999    {
3000      break; 
3001  }       
3002  }       
3003
3004  for( Int i = 0; i <= latestDecIdx; i++ ) 
3005  {
3006    if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) )
3007    {
3008      TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); 
3009      if ( pcPic )
3010      {
3011      if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) 
3012      { 
3013        Bool remainingInterLayerReferencesFlag = false; 
3014        for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
3015        { 
3016          TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); 
3017          if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
3018          {
3019            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ )
3020            {
3021              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ],  k  ) )
3022              {
3023                remainingInterLayerReferencesFlag = true;
3024          }
3025        }
3026          }
3027        }
3028        if( !remainingInterLayerReferencesFlag )
3029        {
3030          pcPic->getSlice(0)->setReferenced( false );                   
3031      }
3032    }
3033      }
3034  }
3035}
3036}
3037
3038Void TComSlice::printRefPicList()
3039{ 
3040  for ( Int li = 0; li < 2; li++)
3041  {   
3042    std::cout << std::endl << "RefPicListL" <<  li << ":" << std::endl; 
3043    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
3044    {     
3045      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
3046       
3047      m_apcRefPicList[li][rIdx]->print( false );
3048    }
3049  }
3050}
3051
3052Void TComSlice::markCurrPic( TComPic* currPic )
3053{
3054  if ( !currPic->getSlice(0)->getDiscardableFlag() )
3055  {
3056    currPic->getSlice(0)->setReferenced( true ) ; 
3057    currPic->setIsLongTerm( false ); 
3058  }
3059  else
3060  {
3061    currPic->getSlice(0)->setReferenced( false ) ; 
3062  }
3063}
3064
3065Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
3066{
3067  m_refPicSetInterLayer0 = refPicSetInterLayer0; 
3068  m_refPicSetInterLayer1 = refPicSetInterLayer1; 
3069}
3070
3071TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId )
3072{
3073  assert ( setIdc == 0 || setIdc == 1);   
3074  std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1);   
3075  assert( refPicSetInterLayer != 0 ); 
3076 
3077  TComPic* pcPic = NULL; 
3078  for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ )
3079  {
3080    if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId )
3081    {
3082      pcPic = (*refPicSetInterLayer)[ i ]; 
3083    }
3084  }
3085
3086  assert(pcPic != NULL); 
3087  return pcPic;
3088}
3089
3090
3091Int  TComSlice::getRefLayerPicFlag( Int i ) 
3092{
3093  TComVPS* vps = getVPS(); 
3094  Int refLayerIdx = vps->getLayerIdInVps( vps->getRefLayerId( getLayerId(), i ) ); 
3095
3096  Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >=  getTLayer() )  && 
3097    ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); 
3098
3099  return refLayerPicFlag;       
3100}   
3101
3102Int TComSlice::getRefLayerPicIdc( Int j ) 
3103{ 
3104  Int refLayerPicIdc = -1; 
3105  Int curj = 0; 
3106  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3107  {
3108    if( getRefLayerPicFlag( i ) )
3109    {
3110      if ( curj == j ) 
3111      {
3112        refLayerPicIdc = i;         
3113        break;
3114      }
3115      curj++; 
3116    }
3117  }
3118
3119  assert( curj == j ); 
3120  assert( refLayerPicIdc != -1 ); 
3121  return refLayerPicIdc; 
3122}
3123
3124Int  TComSlice::getNumRefLayerPics( )
3125{ 
3126  Int numRefLayerPics = 0; 
3127  for( Int i = 0;  i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ )
3128  {
3129    numRefLayerPics += getRefLayerPicFlag( i ); 
3130  }
3131  return numRefLayerPics; 
3132}
3133
3134
3135
3136Int TComSlice::getNumActiveRefLayerPics()
3137{
3138  Int numActiveRefLayerPics; 
3139
3140#if H_MV_HLS_7_MISC_P0079_18
3141  if( getLayerId() == 0 || getNumRefLayerPics() ==  0 )
3142#else
3143  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) ==  0 )
3144#endif
3145  {
3146    numActiveRefLayerPics = 0; 
3147  }
3148  else if (getVPS()->getAllRefLayersActiveFlag() )
3149  {
3150    numActiveRefLayerPics = getNumRefLayerPics(); 
3151  }
3152  else if ( !getInterLayerPredEnabledFlag() )
3153  {
3154    numActiveRefLayerPics = 0; 
3155  }
3156  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
3157  {
3158#if H_MV_HLS_7_MISC_P0079_18
3159    numActiveRefLayerPics = 1; 
3160#else
3161    numActiveRefLayerPics = getRefLayerPicFlag( 0 ) ? 1 : 0; 
3162#endif
3163  }
3164  else
3165  {
3166    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
3167  }
3168  return numActiveRefLayerPics;
3169}
3170
3171Int TComSlice::getRefPicLayerId( Int i )
3172{
3173  return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) );
3174}
3175
3176#if H_3D_ARP
3177Void TComSlice::setARPStepNum( TComPicLists*ivPicLists )
3178{
3179  Bool tempRefPicInListsFlag = false;
3180  if(!getVPS()->getUseAdvRP(getLayerId()) || this->isIRAP())
3181  {
3182    m_nARPStepNum = 0;
3183  }
3184  else
3185  {
3186    setFirstTRefIdx (REF_PIC_LIST_0, -1);
3187    setFirstTRefIdx (REF_PIC_LIST_1, -1);
3188    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3189    {
3190#if MTK_ARP_REF_SELECTION_G0053
3191      Int diffPOC=MAX_INT;
3192      Int idx=-1;
3193#endif
3194      for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ )
3195      {
3196        if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() )
3197        {
3198#if MTK_ARP_REF_SELECTION_G0053
3199          if( abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC()) < diffPOC)
3200          {
3201            diffPOC=abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC());
3202            idx=i;
3203          }
3204#else
3205          setFirstTRefIdx (RefPicList(refListIdx), i);
3206          break;
3207#endif
3208        }
3209#if MTK_ARP_REF_SELECTION_G0053
3210        if(idx>=0)
3211        {
3212          setFirstTRefIdx (RefPicList(refListIdx), idx);
3213        }
3214#endif
3215      }
3216    }
3217    tempRefPicInListsFlag = getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0;
3218    m_nARPStepNum = tempRefPicInListsFlag ? getVPS()->getARPStepNum(getLayerId()) : 0;
3219  }
3220
3221  if (tempRefPicInListsFlag)
3222  {
3223    for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ )
3224    {
3225      RefPicList eRefPicList = RefPicList( refListIdx );
3226      Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC();
3227      for( Int i = 0; i < getNumActiveRefLayerPics(); i++ )
3228      {
3229        Int layerIdInNuh = getRefPicLayerId( i );
3230        Int viewIdx = getVPS()->getViewId( layerIdInNuh );
3231        TComPic*pcPicPrev = ivPicLists->getPic(viewIdx, 0, prevPOC);
3232        if (getFirstTRefIdx(eRefPicList) >= 0 && pcPicPrev && pcPicPrev->getSlice( 0 )->isReferenced())
3233        {
3234          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true;
3235        }
3236        else
3237        {
3238          m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false;
3239        }
3240      }
3241    }
3242  }
3243}
3244#endif
3245#if H_3D_IC
3246Void TComSlice::xSetApplyIC()
3247{
3248  Int iMaxPelValue = ( 1 << g_bitDepthY ); 
3249  Int *aiRefOrgHist;
3250  Int *aiCurrHist;
3251  aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue );
3252  aiCurrHist   = (Int *) xMalloc( Int,iMaxPelValue );
3253  memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
3254  memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
3255  // Reference Idx Number
3256  Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 );
3257  TComPic* pcCurrPic = NULL;
3258  TComPic* pcRefPic = NULL;
3259  TComPicYuv* pcCurrPicYuv = NULL;
3260  TComPicYuv* pcRefPicYuvOrg = NULL;
3261  pcCurrPic = getPic();
3262  pcCurrPicYuv = pcCurrPic->getPicYuvOrg();
3263  Int iWidth = pcCurrPicYuv->getWidth();
3264  Int iHeight = pcCurrPicYuv->getHeight();
3265
3266
3267  // Get InterView Reference picture
3268  // !!!!! Assume only one Interview Reference Picture in L0
3269  for ( Int i = 0; i < iNumRefIdx; i++ )
3270  {
3271    pcRefPic = getRefPic( REF_PIC_LIST_0, i );
3272    if ( pcRefPic != NULL )
3273    {
3274      if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
3275      {
3276        pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
3277      }
3278    }
3279  }
3280
3281  if ( pcRefPicYuvOrg != NULL )
3282  {
3283    Pel* pCurrY = pcCurrPicYuv ->getLumaAddr();
3284    Pel* pRefOrgY = pcRefPicYuvOrg  ->getLumaAddr();
3285    Int iCurrStride = pcCurrPicYuv->getStride();
3286    Int iRefStride = pcRefPicYuvOrg->getStride();
3287    Int iSumOrgSAD = 0;
3288    Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
3289
3290    // Histogram building - luminance
3291    for ( Int y = 0; y < iHeight; y++ )
3292    {
3293      for ( Int x = 0; x < iWidth; x++ )
3294      {
3295        aiCurrHist[pCurrY[x]]++;
3296        aiRefOrgHist[pRefOrgY[x]]++;
3297      }
3298      pCurrY += iCurrStride;
3299      pRefOrgY += iRefStride;
3300    }
3301    // Histogram SAD
3302    for ( Int i = 0; i < iMaxPelValue; i++ )
3303    {
3304      iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] );
3305    }
3306    // Setting
3307    if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) )
3308    {
3309      m_bApplyIC = true;
3310    }
3311    else
3312    {
3313      m_bApplyIC = false;
3314    }
3315  }
3316
3317  xFree( aiCurrHist   );
3318  xFree( aiRefOrgHist );
3319  aiCurrHist = NULL;
3320  aiRefOrgHist = NULL;
3321}
3322#endif
3323#if H_3D
3324Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
3325{
3326  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
3327  {     
3328    for ( Int depthId = 0; depthId < 2; depthId++ )
3329    {
3330      m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL;
3331    }       
3332  } 
3333}
3334Void TComSlice::setDepthToDisparityLUTs()
3335{ 
3336  Bool setupLUT = false; 
3337  Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); 
3338
3339#if H_3D_VSP
3340  setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); 
3341#endif
3342
3343#if H_3D_NBDV_REF
3344  setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS );
3345#endif
3346
3347#if H_3D_IV_MERGE
3348  setupLUT = setupLUT || ( getVPS()->getIvMvPredFlag(layerIdInVPS ) && getIsDepth() );
3349#endif
3350
3351#if MTK_DDD_G0063
3352  if( getIsDepth() && getViewIndex() > 0 )
3353  {
3354      TComSlice *pcTextSlice = getTexturePic()->getSlice( 0 );
3355      memcpy( m_aiDDDInvScale, pcTextSlice->m_aiDDDInvScale, sizeof( Int ) * getViewIndex() );
3356      memcpy( m_aiDDDInvOffset, pcTextSlice->m_aiDDDInvOffset, sizeof( Int ) * getViewIndex() );
3357      memcpy( m_aiDDDShift, pcTextSlice->m_aiDDDShift, sizeof( Int ) * getViewIndex() );             
3358  } 
3359#endif
3360
3361  if( !setupLUT )
3362    return; 
3363
3364  /// GT: Allocation should be moved to a better place later;
3365  if ( m_depthToDisparityB == NULL )
3366  {
3367    m_depthToDisparityB = new Int*[ getViewIndex() ];
3368    for ( Int i = 0; i < getViewIndex(); i++ )
3369    {
3370      m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
3371    }
3372  }
3373
3374  if ( m_depthToDisparityF == NULL )
3375  {
3376    m_depthToDisparityF= new Int*[ getViewIndex() ];
3377    for ( Int i = 0; i < getViewIndex(); i++ )
3378    {
3379      m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; 
3380    }
3381  }
3382
3383  assert( m_depthToDisparityB != NULL ); 
3384  assert( m_depthToDisparityF != NULL ); 
3385
3386  TComVPS* vps = getVPS(); 
3387
3388  Int log2Div = g_bitDepthY - 1 + vps->getCamParPrecision();
3389  Int viewIndex = getViewIndex();
3390
3391  Bool camParaSH = vps->hasCamParInSliceHeader( viewIndex );
3392
3393  Int* codScale     = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale    ( viewIndex ); 
3394  Int* codOffset    = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset   ( viewIndex ); 
3395  Int* invCodScale  = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( viewIndex ); 
3396  Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( viewIndex ); 
3397
3398  for (Int i = 0; i <= ( getViewIndex() - 1); i++)
3399  {
3400    for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ )
3401    {
3402      Int offset =    ( codOffset  [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
3403      m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; 
3404
3405      Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 );         
3406      m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; 
3407    }
3408
3409#if MTK_DDD_G0063
3410    InitializeDDDPara( vps->getCamParPrecision(), codScale[ i ], codOffset[ i ], i );
3411#endif
3412  }
3413}
3414#endif
3415#endif
3416
3417#if MTK_DDD_G0063
3418Void TComSlice::InitializeDDDPara( UInt uiCamParsCodedPrecision, Int  iCodedScale,Int  iCodedOffset, Int iBaseViewIdx )
3419{
3420    UInt uiViewId     = getViewIndex();
3421
3422    if( uiViewId == 0 )
3423    {
3424        m_aiDDDInvScale[ iBaseViewIdx ] = m_aiDDDInvOffset[ iBaseViewIdx ] = m_aiDDDShift[ iBaseViewIdx ] = 0;
3425        return;
3426    }
3427
3428
3429    Int iSign = iCodedScale >= 0 ? 1 : -1;
3430    iCodedScale = abs( iCodedScale );
3431
3432    Int iBitWidth = 0;
3433
3434    const Int iInvPres = 9;
3435
3436    while( ((( 1 << iBitWidth ) << 1 ) <= iCodedScale ) )
3437    {
3438        iBitWidth ++;
3439    }
3440    iBitWidth += iInvPres;
3441    Int iTargetValue =  1 << iBitWidth;
3442
3443    Int iMinError = MAX_INT;
3444    Int iBestD = 1 << ( iInvPres - 1 );
3445    for( Int d = 1 << ( iInvPres - 1 ); d < ( 1 << iInvPres ); d++ )
3446    {
3447        Int iError = abs( iCodedScale * d - iTargetValue );
3448        if( iError < iMinError )
3449        {
3450            iMinError = iError;
3451            iBestD = d;
3452        }
3453        if( iMinError == 0 )
3454        {
3455            break;
3456        }
3457    }
3458    Int iRoundingDir = 0;
3459    if( iCodedScale * iBestD > iTargetValue )
3460    {
3461        iRoundingDir = -1;
3462    }
3463    else if( iCodedScale * iBestD < iTargetValue )
3464    {
3465        iRoundingDir = 1;
3466    }
3467    Int iCamPres = uiCamParsCodedPrecision - 1;
3468    m_aiDDDInvScale [ iBaseViewIdx ] = ( iBestD << ( iCamPres + g_bitDepthY )) * iSign;
3469    m_aiDDDInvOffset[ iBaseViewIdx ] = -iSign * iBestD * ( iCodedOffset << g_bitDepthY );
3470    m_aiDDDShift    [ iBaseViewIdx ] = iBitWidth;
3471    m_aiDDDInvOffset[ iBaseViewIdx ] += 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 1 );
3472    m_aiDDDInvOffset[ iBaseViewIdx ] += ( 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 4 ) ) * iRoundingDir;
3473
3474    return;
3475}
3476#endif
3477
3478/** get scaling matrix from RefMatrixID
3479 * \param sizeId size index
3480 * \param Index of input matrix
3481 * \param Index of reference matrix
3482 */
3483Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
3484{
3485  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3486}
3487
3488/** parse syntax infomation
3489 *  \param pchFile syntax infomation
3490 *  \returns false if successful
3491 */
3492Bool TComScalingList::xParseScalingList(Char* pchFile)
3493{
3494  FILE *fp;
3495  Char line[1024];
3496  UInt sizeIdc,listIdc;
3497  UInt i,size = 0;
3498  Int *src=0,data;
3499  Char *ret;
3500  UInt  retval;
3501
3502  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
3503  {
3504    printf("can't open file %s :: set Default Matrix\n",pchFile);
3505    return true;
3506  }
3507
3508  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
3509  {
3510    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
3511    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
3512    {
3513      src = getScalingListAddress(sizeIdc, listIdc);
3514
3515      fseek(fp,0,0);
3516      do 
3517      {
3518        ret = fgets(line, 1024, fp);
3519        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
3520        {
3521          printf("Error: can't read Matrix :: set Default Matrix\n");
3522          return true;
3523        }
3524      }
3525      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
3526      for (i=0; i<size; i++)
3527      {
3528        retval = fscanf(fp, "%d,", &data);
3529        if (retval!=1)
3530        {
3531          printf("Error: can't read Matrix :: set Default Matrix\n");
3532          return true;
3533        }
3534        src[i] = data;
3535      }
3536      //set DC value for default matrix check
3537      setScalingListDC(sizeIdc,listIdc,src[0]);
3538
3539      if(sizeIdc > SCALING_LIST_8x8)
3540      {
3541        fseek(fp,0,0);
3542        do 
3543        {
3544          ret = fgets(line, 1024, fp);
3545          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
3546          {
3547            printf("Error: can't read DC :: set Default Matrix\n");
3548            return true;
3549          }
3550        }
3551        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
3552        retval = fscanf(fp, "%d,", &data);
3553        if (retval!=1)
3554        {
3555          printf("Error: can't read Matrix :: set Default Matrix\n");
3556          return true;
3557        }
3558        //overwrite DC value when size of matrix is larger than 16x16
3559        setScalingListDC(sizeIdc,listIdc,data);
3560      }
3561    }
3562  }
3563  fclose(fp);
3564  return false;
3565}
3566
3567#if H_MV
3568Void TComScalingList::inferFrom( TComScalingList* srcScLi )
3569{
3570  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3571  {
3572    for(Int listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3573    {
3574      setRefMatrixId  (sizeId,listId, srcScLi->getRefMatrixId  (sizeId,listId));
3575      setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId));         
3576      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3577    }
3578  }
3579}
3580#endif
3581/** initialization process of quantization matrix array
3582 */
3583Void TComScalingList::init()
3584{
3585  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3586  {
3587    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3588    {
3589      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
3590    }
3591  }
3592  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
3593}
3594
3595/** destroy quantization matrix array
3596 */
3597Void TComScalingList::destroy()
3598{
3599  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3600  {
3601    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3602    {
3603      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
3604    }
3605  }
3606}
3607
3608/** get default address of quantization matrix
3609 * \param sizeId size index
3610 * \param listId list index
3611 * \returns pointer of quantization matrix
3612 */
3613Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
3614{
3615  Int *src = 0;
3616  switch(sizeId)
3617  {
3618    case SCALING_LIST_4x4:
3619      src = g_quantTSDefault4x4;
3620      break;
3621    case SCALING_LIST_8x8:
3622      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3623      break;
3624    case SCALING_LIST_16x16:
3625      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3626      break;
3627    case SCALING_LIST_32x32:
3628      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3629      break;
3630    default:
3631      assert(0);
3632      src = NULL;
3633      break;
3634  }
3635  return src;
3636}
3637
3638/** process of default matrix
3639 * \param sizeId size index
3640 * \param Index of input matrix
3641 */
3642Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
3643{
3644  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3645  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
3646}
3647
3648/** check DC value of matrix for default matrix signaling
3649 */
3650Void TComScalingList::checkDcOfMatrix()
3651{
3652  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3653  {
3654    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3655    {
3656      //check default matrix?
3657      if(getScalingListDC(sizeId,listId) == 0)
3658      {
3659        processDefaultMatrix(sizeId, listId);
3660      }
3661    }
3662  }
3663}
3664
3665ParameterSetManager::ParameterSetManager()
3666: m_vpsMap(MAX_NUM_VPS)
3667, m_spsMap(MAX_NUM_SPS)
3668, m_ppsMap(MAX_NUM_PPS)
3669, m_activeVPSId(-1)
3670#if !H_MV
3671, m_activeSPSId(-1)
3672, m_activePPSId(-1)
3673{
3674#else
3675{
3676  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
3677  {
3678    m_activeSPSId[ i ] = -1; 
3679    m_activePPSId[ i ] = -1; 
3680  }
3681#endif
3682}
3683
3684
3685ParameterSetManager::~ParameterSetManager()
3686{
3687}
3688
3689//! activate a SPS from a active parameter sets SEI message
3690//! \returns true, if activation is successful
3691#if H_MV
3692Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
3693#else
3694Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
3695#endif
3696{
3697  TComSPS *sps = m_spsMap.getPS(spsId);
3698  if (sps)
3699  {
3700    Int vpsId = sps->getVPSId();
3701    if (m_vpsMap.getPS(vpsId))
3702    {
3703      m_activeVPSId = vpsId;
3704#if H_MV
3705      m_activeSPSId[ layerId ] = spsId;
3706#else
3707      m_activeSPSId = spsId;
3708#endif
3709      return true;
3710    }
3711    else
3712    {
3713      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
3714    }
3715  }
3716  else
3717  {
3718    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
3719  }
3720  return false;
3721}
3722
3723//! activate a PPS and depending on isIDR parameter also SPS and VPS
3724//! \returns true, if activation is successful
3725#if H_MV
3726Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
3727#else
3728Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
3729#endif
3730{
3731  TComPPS *pps = m_ppsMap.getPS(ppsId);
3732  if (pps)
3733  {
3734    Int spsId = pps->getSPSId();
3735#if H_MV
3736    if (!isIRAP && (spsId != m_activeSPSId[ layerId ]))
3737#else
3738    if (!isIRAP && (spsId != m_activeSPSId))
3739#endif
3740    {
3741      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
3742      return false;
3743    }
3744
3745    TComSPS *sps = m_spsMap.getPS(spsId);
3746    if (sps)
3747    {
3748      Int vpsId = sps->getVPSId();
3749      if (!isIRAP && (vpsId != m_activeVPSId))
3750      {
3751        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
3752        return false;
3753      }
3754      if (m_vpsMap.getPS(vpsId))
3755      {
3756#if H_MV
3757        m_activePPSId[ layerId ] = ppsId;
3758        m_activeVPSId = vpsId;
3759        m_activeSPSId[ layerId ] = spsId;
3760#else
3761        m_activePPSId = ppsId;
3762        m_activeVPSId = vpsId;
3763        m_activeSPSId = spsId;
3764#endif
3765        return true;
3766      }
3767      else
3768      {
3769        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
3770      }
3771    }
3772    else
3773    {
3774      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
3775    }
3776  }
3777  else
3778  {
3779    printf("Warning: tried to activate non-existing PPS.");
3780  }
3781  return false;
3782}
3783
3784ProfileTierLevel::ProfileTierLevel()
3785  : m_profileSpace    (0)
3786  , m_tierFlag        (false)
3787  , m_profileIdc      (0)
3788  , m_levelIdc        (0)
3789, m_progressiveSourceFlag  (false)
3790, m_interlacedSourceFlag   (false)
3791, m_nonPackedConstraintFlag(false)
3792, m_frameOnlyConstraintFlag(false)
3793{
3794  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
3795}
3796
3797TComPTL::TComPTL()
3798{
3799  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
3800  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
3801}
3802
3803#if H_MV
3804Void TComPTL::copyLevelFrom( TComPTL* source )
3805{
3806  getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() );
3807  for( Int subLayer = 0; subLayer < 6; subLayer++ )
3808  {
3809    setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) );
3810    getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() );
3811  }
3812}
3813#endif
3814//! \}
3815
3816#if H_MV
3817TComVPSVUI::TComVPSVUI()
3818{
3819  m_crossLayerIrapAlignedFlag = true; 
3820#if H_MV_HLS_7_MISC_P0068_21
3821  m_allLayersIdrAlignedFlag   = false; 
3822#endif
3823  m_bitRatePresentVpsFlag = false;
3824  m_picRatePresentVpsFlag = false;
3825  for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++)
3826  {   
3827    for ( Int j = 0; j < MAX_TLAYER; j++)
3828    {   
3829      m_bitRatePresentFlag          [i][j] = false;
3830      m_picRatePresentFlag          [i][j] = false;
3831      m_avgBitRate                  [i][j] = -1;
3832      m_maxBitRate                  [i][j] = -1;
3833      m_constantPicRateIdc          [i][j] = -1;
3834      m_avgPicRate                  [i][j] = -1;
3835    }
3836  }
3837
3838  m_ilpRestrictedRefLayersFlag = false;
3839
3840  for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
3841  {         
3842    for ( Int j = 0; j < MAX_NUM_LAYERS; j++)
3843    {   
3844      m_tileBoundariesAlignedFlag   [i][j] = false;
3845      m_minSpatialSegmentOffsetPlus1[i][j] = 0;
3846      m_ctuBasedOffsetEnabledFlag   [i][j] = false;
3847      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
3848    }
3849#if H_MV_HLS_7_MISC_P0182_13
3850    m_baseLayerParameterSetCompatibilityFlag[i] = false;
3851#endif
3852  }
3853  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
3854  {
3855    m_videoSignalInfo          [i] = NULL;     
3856  }
3857
3858  m_vpsVuiBspHrdPresentFlag = false; 
3859  m_vpsVuiBspHrdParameters  = new TComVpsVuiBspHrdParameters();
3860}
3861
3862TComVPSVUI::~TComVPSVUI()
3863{
3864  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
3865  {
3866    if (m_videoSignalInfo[ i ] != NULL )      delete m_videoSignalInfo[ i ];   
3867    m_videoSignalInfo    [ i ] = NULL; 
3868  }
3869
3870  if ( m_vpsVuiBspHrdParameters ) delete m_vpsVuiBspHrdParameters;
3871  m_vpsVuiBspHrdParameters = NULL; 
3872}
3873
3874Void TComRepFormat::inferChromaAndBitDepth( TComRepFormat* prevRepFormat, Bool encoderFlag )
3875{
3876  if ( !encoderFlag )
3877  {
3878    setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
3879    setSeparateColourPlaneVpsFlag     ( prevRepFormat->getSeparateColourPlaneVpsFlag     () );
3880    setBitDepthVpsLumaMinus8          ( prevRepFormat->getBitDepthVpsLumaMinus8          () );
3881    setBitDepthVpsChromaMinus8        ( prevRepFormat->getBitDepthVpsChromaMinus8        () );
3882  }
3883  else
3884  {
3885    assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() );
3886    assert( getSeparateColourPlaneVpsFlag     () == prevRepFormat->getSeparateColourPlaneVpsFlag     () );
3887    assert( getBitDepthVpsLumaMinus8          () == prevRepFormat->getBitDepthVpsLumaMinus8          () );
3888    assert( getBitDepthVpsChromaMinus8        () == prevRepFormat->getBitDepthVpsChromaMinus8        () );
3889}
3890}
3891
3892Void TComVpsVuiBspHrdParameters::checkLayerInBspFlag( TComVPS* vps, Int h )
3893{
3894  // It is a requirement of bitstream conformance that bitstream partition with index j shall not include
3895  // direct or indirect reference layers of any layers in bitstream partition i for any values of i and j
3896  // in the range of 0 to num_bitstream_partitions[ h ] ?1, inclusive, such that i is less than j.
3897
3898  for ( Int partJ = 0; partJ < getNumBitstreamPartitions( h ); partJ++ )
3899  {       
3900    for ( Int partI = 0; partI < partJ; partI++ )
3901    {
3902      for ( Int layerJ = 0; layerJ < vps->getMaxLayersMinus1(); layerJ++ )
3903      {
3904        if ( m_layerInBspFlag[ h ][partJ][layerJ ] )
3905        {
3906          for ( Int layerI = 0; layerI < vps->getMaxLayersMinus1(); layerI++ )
3907          {
3908            if ( m_layerInBspFlag[ h ][partI][layerI] )
3909            {
3910              assert( !vps->getInDirectDependencyFlag( layerI, layerJ ) ); 
3911            }
3912          }
3913        }
3914      }
3915    }
3916  }
3917}
3918
3919Void TComVUI::inferVideoSignalInfo( TComVPS* vps, Int layerIdCurr )
3920{
3921  if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() ) 
3922  {
3923    return; 
3924  }
3925
3926  TComVPSVUI* vpsVUI = vps->getVPSVUI(); 
3927  assert( vpsVUI != NULL ); 
3928
3929  TComVideoSignalInfo* videoSignalInfo = vpsVUI->getVideoSignalInfo( vpsVUI->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); 
3930  assert( videoSignalInfo != NULL );
3931
3932  setVideoFormat            ( videoSignalInfo->getVideoVpsFormat            () ); 
3933  setVideoFullRangeFlag     ( videoSignalInfo->getVideoFullRangeVpsFlag     () );
3934  setColourPrimaries        ( videoSignalInfo->getColourPrimariesVps        () );
3935  setTransferCharacteristics( videoSignalInfo->getTransferCharacteristicsVps() );
3936  setMatrixCoefficients     ( videoSignalInfo->getMatrixCoeffsVps           () );
3937}
3938#endif
Note: See TracBrowser for help on using the repository browser.