source: 3DVCSoftware/branches/HTM-9.1-dev0-RWTH/source/Lib/TLibCommon/TComSlice.cpp @ 751

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