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

Last change on this file since 758 was 758, checked in by tech, 10 years ago

Merged HTM-9.1-dev0-MediaTek@757. (3D-HEVC HLS)

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