source: 3DVCSoftware/branches/HTM-6.2-dev2-MERL/source/Lib/TLibCommon/TComSlice.cpp @ 417

Last change on this file since 417 was 412, checked in by mitsubishi-htm, 12 years ago

-D0166 part 1, set refView selection for NBDV.

  • Property svn:eol-style set to native
File size: 72.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2012, 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
42//! \ingroup TLibCommon
43//! \{
44
45TComSlice::TComSlice()
46#if QC_MVHEVC_B0046
47: m_iPPSId                        ( 0  )
48#else
49: m_iPPSId                        ( -1 )
50#endif
51, m_iPOC                          ( 0 )
52, m_iLastIDR                      ( 0 )
53, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR )
54, m_eNalUnitTypeBaseViewMvc       ( NAL_UNIT_INVALID )
55, m_eSliceType                    ( I_SLICE )
56, m_iSliceQp                      ( 0 )
57#if ADAPTIVE_QP_SELECTION
58, m_iSliceQpBase                  ( 0 )
59#endif
60, m_bLoopFilterDisable            ( false )
61, m_inheritDblParamFromAPS       ( true )
62, m_loopFilterBetaOffsetDiv2    ( 0 )
63, m_loopFilterTcOffsetDiv2      ( 0 )
64, m_bRefPicListModificationFlagLC ( false )
65, m_bRefPicListCombinationFlag    ( false )
66, m_bCheckLDC                     ( false )
67, m_iSliceQpDelta                 ( 0 )
68, m_pcTexturePic                  ( NULL )
69, m_iDepth                        ( 0 )
70, m_bRefenced                     ( false )
71, m_pcSPS                         ( NULL )
72, m_pcPPS                         ( NULL )
73, m_pcPic                         ( NULL )
74, m_uiColDir                      ( 0 )
75#if COLLOCATED_REF_IDX
76, m_colRefIdx                     ( 0 )
77#endif
78#if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
79, m_dLambdaLuma( 0.0 )
80, m_dLambdaChroma( 0.0 )
81#else
82, m_dLambda                       ( 0.0 )
83#endif
84, m_bNoBackPredFlag               ( false )
85, m_bRefIdxCombineCoding          ( false )
86, m_uiTLayer                      ( 0 )
87, m_bTLayerSwitchingFlag          ( false )
88, m_uiSliceMode                   ( 0 )
89, m_uiSliceArgument               ( 0 )
90, m_uiSliceCurStartCUAddr         ( 0 )
91, m_uiSliceCurEndCUAddr           ( 0 )
92, m_uiSliceIdx                    ( 0 )
93, m_uiEntropySliceMode            ( 0 )
94, m_uiEntropySliceArgument        ( 0 )
95, m_uiEntropySliceCurStartCUAddr  ( 0 )
96, m_uiEntropySliceCurEndCUAddr    ( 0 )
97, m_bNextSlice                    ( false )
98, m_bNextEntropySlice             ( false )
99, m_uiSliceBits                   ( 0 )
100, m_uiEntropySliceCounter         ( 0 )
101, m_bFinalized                    ( false )
102, m_uiTileByteLocation            ( NULL )
103, m_uiTileCount                   ( 0 )
104, m_iTileMarkerFlag               ( 0 )
105, m_uiTileOffstForMultES          ( 0 )
106, m_puiSubstreamSizes             ( NULL )
107#if CABAC_INIT_FLAG
108, m_cabacInitFlag                 ( false )
109#else
110, m_cabacInitIdc                 ( -1 )
111#endif
112, m_numEntryPointOffsets          ( 0 )
113#if LGE_ILLUCOMP_B0045
114, m_bApplyIC                      ( false )
115#endif
116#if INTER_VIEW_VECTOR_SCALING_C0115
117, m_bIVScalingFlag                (false)
118, m_iViewOrderIdx                 ( 0 )        // will be changed to view_id
119#endif
120{
121#if MERL_VSP_NBDV_RefVId_Fix_D0166
122  for(Int iNumCount = 0; iNumCount < MAX_VIEW_NUM; iNumCount++)
123    m_pcListDepthPic[iNumCount] =NULL;
124#endif
125  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
126
127  initEqualRef();
128 
129  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
130  {
131    m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
132    m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
133    m_eListIdFromIdxOfLC[iNumCount]=0;
134    m_iRefIdxFromIdxOfLC[iNumCount]=0;
135    m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
136    m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
137  }   
138  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF+1; iNumCount++)
139  {
140    m_apcRefPicList  [0][iNumCount] = NULL;
141    m_apcRefPicList  [1][iNumCount] = NULL;
142    m_aiRefPOCList   [0][iNumCount] = 0;
143    m_aiRefPOCList   [1][iNumCount] = 0;
144    m_aiRefViewIdList[0][iNumCount] = 0;
145    m_aiRefViewIdList[1][iNumCount] = 0;
146  }
147  m_bCombineWithReferenceFlag = 0;
148  resetWpScaling(m_weightPredTable);
149  resetWpScalingLC(m_weightPredTableLC);
150  initWpAcDcParam();
151#if QC_IV_AS_LT_B0046
152  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF+1; iNumCount++)
153  {
154     m_bWasLongTerm[0][iNumCount] = false;
155     m_bWasLongTerm[1][iNumCount] = false;
156  }
157#endif
158}
159
160TComSlice::~TComSlice()
161{
162  if (m_uiTileByteLocation) 
163  {
164    delete [] m_uiTileByteLocation;
165    m_uiTileByteLocation = NULL;
166  }
167  delete[] m_puiSubstreamSizes;
168  m_puiSubstreamSizes = NULL;
169}
170
171
172Void TComSlice::initSlice()
173{
174  m_aiNumRefIdx[0]      = 0;
175  m_aiNumRefIdx[1]      = 0;
176 
177  m_uiColDir = 0;
178 
179#if COLLOCATED_REF_IDX
180  m_colRefIdx = 0;
181#endif
182  m_pcTexturePic = NULL;
183
184  initEqualRef();
185  m_bNoBackPredFlag = false;
186  m_bRefIdxCombineCoding = false;
187  m_bRefPicListCombinationFlag = false;
188  m_bRefPicListModificationFlagLC = false;
189  m_bCheckLDC = false;
190
191  m_aiNumRefIdx[REF_PIC_LIST_C]      = 0;
192
193  m_uiMaxNumMergeCand = MRG_MAX_NUM_CANDS_SIGNALED;
194
195  m_bFinalized=false;
196
197  m_uiTileCount          = 0;
198#if CABAC_INIT_FLAG
199  m_cabacInitFlag        = false;
200#endif
201  m_numEntryPointOffsets = 0;
202#if QC_TMVP_MRG_REFIDX_C0047
203  m_aiNewRefIdx[0]                  = -1;
204  m_aiNewRefIdx[1]                  = -1;
205#endif
206}
207
208Void TComSlice::initTiles()
209{
210  Int iWidth             = m_pcSPS->getPicWidthInLumaSamples();
211  Int iHeight            = m_pcSPS->getPicHeightInLumaSamples();
212  UInt uiWidthInCU       = ( iWidth %g_uiMaxCUWidth  ) ? iWidth /g_uiMaxCUWidth  + 1 : iWidth /g_uiMaxCUWidth;
213  UInt uiHeightInCU      = ( iHeight%g_uiMaxCUHeight ) ? iHeight/g_uiMaxCUHeight + 1 : iHeight/g_uiMaxCUHeight;
214  UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
215
216  if (m_uiTileByteLocation==NULL) m_uiTileByteLocation   = new UInt[uiNumCUsInFrame];
217}
218
219
220/**
221 - allocate table to contain substream sizes to be written to the slice header.
222 .
223 \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1.
224 */
225Void  TComSlice::allocSubstreamSizes(UInt uiNumSubstreams)
226{
227  delete[] m_puiSubstreamSizes;
228  m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0];
229}
230
231Void  TComSlice::sortPicList        (TComList<TComPic*>& rcListPic)
232{
233  TComPic*    pcPicExtract;
234  TComPic*    pcPicInsert;
235 
236  TComList<TComPic*>::iterator    iterPicExtract;
237  TComList<TComPic*>::iterator    iterPicExtract_1;
238  TComList<TComPic*>::iterator    iterPicInsert;
239 
240  for (Int i = 1; i < (Int)(rcListPic.size()); i++)
241  {
242    iterPicExtract = rcListPic.begin();
243    for (Int j = 0; j < i; j++) iterPicExtract++;
244    pcPicExtract = *(iterPicExtract);
245    pcPicExtract->setCurrSliceIdx(0);
246   
247    iterPicInsert = rcListPic.begin();
248    while (iterPicInsert != iterPicExtract)
249    {
250      pcPicInsert = *(iterPicInsert);
251      pcPicInsert->setCurrSliceIdx(0);
252      if (pcPicInsert->getPOC() >= pcPicExtract->getPOC())
253      {
254        break;
255      }
256     
257      iterPicInsert++;
258    }
259   
260    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
261   
262    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
263    rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1);
264    rcListPic.erase  (iterPicExtract);
265  }
266}
267
268TComPic* TComSlice::xGetRefPic( TComList<TComPic*>& rcListPic, UInt uiPOC )
269{
270  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
271  TComPic*                      pcPic = *(iterPic);
272  while ( iterPic != rcListPic.end() )
273  {
274    if(pcPic->getPOC() == uiPOC)
275    {
276      break;
277    }
278    iterPic++;
279    pcPic = *(iterPic);
280  }
281  return  pcPic;
282}
283
284
285TComPic* TComSlice::xGetLongTermRefPic( TComList<TComPic*>& rcListPic, UInt uiPOC )
286{
287  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
288  TComPic*                      pcPic = *(iterPic);
289  TComPic*                      pcStPic = pcPic;
290  while ( iterPic != rcListPic.end() )
291  {
292    pcPic = *(iterPic);
293    if(pcPic && (pcPic->getPOC()%(1<<getSPS()->getBitsForPOC())) == (uiPOC%(1<<getSPS()->getBitsForPOC())))
294    {
295      if(pcPic->getIsLongTerm())
296        return pcPic;
297      else
298        pcStPic = pcPic;
299      break;
300    }
301
302    iterPic++;
303  }
304  return  pcStPic;
305}
306
307TComPic* TComSlice::xGetInterViewRefPic( std::vector<TComPic*>& rcListIvPic, UInt uiViewId )
308{
309  TComPic* pcPic = NULL;
310  for( Int k = 0; k < rcListIvPic.size(); k++ )
311  {
312    if( rcListIvPic[k]->getViewId() == uiViewId )
313    {
314      pcPic = rcListIvPic[k];
315      break;
316    }
317  }
318
319  assert( pcPic != NULL );
320  return pcPic;
321}
322
323Int TComSlice::getNumPocTotalCurr()
324{
325  if( m_eSliceType == I_SLICE ) 
326  {
327    return 0;
328  }
329
330  Int numPocTotalCurr = 0;
331  for( UInt i = 0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++ )
332  {
333    if(m_pcRPS->getUsed(i))
334    {
335      numPocTotalCurr++;
336    }
337  }
338
339  return numPocTotalCurr;
340}
341
342Int TComSlice::getNumPocTotalCurrMvc()
343{
344  if( m_eSliceType == I_SLICE ) 
345  {
346    return 0;
347  }
348  return getNumPocTotalCurr() + m_pcSPS->getNumberOfUsableInterViewRefs();
349}
350
351Void TComSlice::setRefPOCnViewListsMvc()
352{
353  for(Int iDir = 0; iDir < 2; iDir++)
354  {
355    for(Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
356    {
357      m_aiRefPOCList   [iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
358      m_aiRefViewIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getViewId();
359    }
360  }
361}
362
363Void TComSlice::generateCombinedList()
364{
365  if(m_aiNumRefIdx[REF_PIC_LIST_C] > 0)
366  {
367    m_aiNumRefIdx[REF_PIC_LIST_C]=0;
368    for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
369    {
370      m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
371      m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
372      m_eListIdFromIdxOfLC[iNumCount]=0;
373      m_iRefIdxFromIdxOfLC[iNumCount]=0;
374      m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
375      m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
376    }
377
378    for (Int iNumRefIdx = 0; iNumRefIdx < MAX_NUM_REF; iNumRefIdx++)
379    {
380      if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_0])
381      {
382        Bool bTempRefIdxInL2 = true;
383        for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
384        {
385          if( (m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC()    == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC()   ) &&
386              (m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getViewId() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getViewId())    )
387          {
388            m_iRefIdxOfL1FromRefIdxOfL0[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
389            m_iRefIdxOfL0FromRefIdxOfL1[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
390            bTempRefIdxInL2 = false;
391            break;
392          }
393        }
394
395        if(bTempRefIdxInL2 == true)
396        { 
397          m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_0;
398          m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
399          m_iRefIdxOfLC[REF_PIC_LIST_0][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
400        }
401      }
402
403      if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_1])
404      {
405        Bool bTempRefIdxInL2 = true;
406        for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
407        {
408          if( (m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC()    == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC()   ) &&
409              (m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getViewId() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getViewId())    )
410          {
411            m_iRefIdxOfL0FromRefIdxOfL1[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
412            m_iRefIdxOfL1FromRefIdxOfL0[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
413            bTempRefIdxInL2 = false;
414            break;
415          }
416        }
417        if(bTempRefIdxInL2 == true)
418        {
419          m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_1;
420          m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
421          m_iRefIdxOfLC[REF_PIC_LIST_1][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
422        }
423      }
424    }
425  }
426#if QC_TMVP_MRG_REFIDX_C0047
427  Int  iCurrPOC = this->getPOC();
428  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )//just to get one updated ref idx for merge in each L0/L1 direction, if it is not avaialbe, it is still -1
429  {       
430    if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0)
431        continue;
432
433    Bool bZeroIdxInterViewFlag =  ( this->getRefPic(RefPicList(uiRefListIdx), 0)->getPOC() == iCurrPOC ) ? true : false;
434    for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ )
435    {
436      if ( (bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() != iCurrPOC ) ||
437           (!bZeroIdxInterViewFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() == iCurrPOC ) )
438      {
439        this->setNewRefIdx(RefPicList(uiRefListIdx),i);
440        break;
441      }
442    }
443  }
444
445#endif
446}
447
448Void TComSlice::setRefPicListMvc( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& rapcInterViewRefPics )
449{
450  if( m_eSliceType == I_SLICE )
451  {
452    ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList) );
453    ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ) );
454
455    return;
456  }
457
458  TComPic*  pcRefPic;
459  TComPic*  RefPicSetStCurr0[16];
460  TComPic*  RefPicSetStCurr1[16];
461  TComPic*  RefPicSetLtCurr [16];
462  TComPic*  RefPicSetIvCurr [16];
463
464  UInt NumPocStCurr0 = 0;
465  UInt NumPocStCurr1 = 0;
466  UInt NumPocLtCurr  = 0;
467  UInt NumPocIvCurr  = 0;
468
469  Int i;
470  // short term negative
471  for( i = 0; i < m_pcRPS->getNumberOfNegativePictures(); i++ )
472  {
473    if( m_pcRPS->getUsed(i) )
474    {
475      pcRefPic = xGetRefPic( rcListPic, getPOC() + m_pcRPS->getDeltaPOC(i) );
476      pcRefPic->setIsLongTerm( 0 );
477      pcRefPic->getPicYuvRec()->extendPicBorder();
478      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
479      NumPocStCurr0++;
480    }
481  }
482  // short term positive
483  for( ; i < m_pcRPS->getNumberOfNegativePictures() + m_pcRPS->getNumberOfPositivePictures(); i++ )
484  {
485    if( m_pcRPS->getUsed(i) )
486    {
487      pcRefPic = xGetRefPic( rcListPic, getPOC() + m_pcRPS->getDeltaPOC(i) );
488      pcRefPic->setIsLongTerm( 0 );
489      pcRefPic->getPicYuvRec()->extendPicBorder();
490      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
491      NumPocStCurr1++;
492    }
493  }
494  // long term
495  for( i = m_pcRPS->getNumberOfNegativePictures() + m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures() - 1; i > m_pcRPS->getNumberOfNegativePictures() + m_pcRPS->getNumberOfPositivePictures() - 1 ; i-- )
496  {
497    if( m_pcRPS->getUsed(i) )
498    {
499      pcRefPic = xGetLongTermRefPic( rcListPic, m_pcRPS->getPOC(i) );
500      pcRefPic->setIsLongTerm( 1 );
501      pcRefPic->getPicYuvRec()->extendPicBorder();
502      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
503      NumPocLtCurr++;
504    }
505  }
506  // inter-view
507  for( i = 0; i < m_pcSPS->getNumberOfUsableInterViewRefs(); i++ )
508  {
509    pcRefPic = xGetInterViewRefPic( rapcInterViewRefPics, getViewId() + m_pcSPS->getUsableInterViewRef(i) );
510#if QC_IV_AS_LT_B0046
511    pcRefPic->setIsLongTerm( 1 );
512#else
513    pcRefPic->setIsLongTerm( 0 );
514#endif
515    pcRefPic->getPicYuvRec()->extendPicBorder();
516    RefPicSetIvCurr[NumPocIvCurr] = pcRefPic;
517    NumPocIvCurr++;
518  }
519
520  // ref_pic_list_init
521  UInt cIdx = 0;
522  UInt num_ref_idx_l0_active_minus1 = m_aiNumRefIdx[0] - 1;
523  UInt num_ref_idx_l1_active_minus1 = m_aiNumRefIdx[1] - 1;
524
525  assert( (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) == getNumPocTotalCurrMvc() );
526  Int numRpsCurrTempList0 = max( (num_ref_idx_l0_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) );
527  Int numRpsCurrTempList1 = max( (num_ref_idx_l1_active_minus1 + 1), (NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + NumPocIvCurr) );
528
529  assert( numRpsCurrTempList0 <= 16 );
530  TComPic* refPicListTemp0[16];
531  assert( numRpsCurrTempList1 <= 16 );
532  TComPic* refPicListTemp1[16];
533
534  cIdx = 0;
535  while( cIdx < numRpsCurrTempList0 )
536  {
537    for( i = 0; i < NumPocStCurr0 && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetStCurr0[i]; }
538    for( i = 0; i < NumPocStCurr1 && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetStCurr1[i]; }
539    for( i = 0; i < NumPocLtCurr  && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetLtCurr [i]; }
540    for( i = 0; i < NumPocIvCurr  && cIdx < numRpsCurrTempList0; cIdx++, i++ ) { refPicListTemp0[cIdx] = RefPicSetIvCurr [i]; }
541  }
542
543  cIdx = 0;
544  while( cIdx < numRpsCurrTempList1 && m_eSliceType == B_SLICE )
545  {
546    for( i = 0; i < NumPocStCurr1 && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetStCurr1[i]; }
547    for( i = 0; i < NumPocStCurr0 && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetStCurr0[i]; }
548    for( i = 0; i < NumPocLtCurr  && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetLtCurr [i]; }
549    for( i = 0; i < NumPocIvCurr  && cIdx < numRpsCurrTempList1; cIdx++, i++ ) { refPicListTemp1[cIdx] = RefPicSetIvCurr [i]; }
550  }
551
552  for( cIdx = 0; cIdx <= num_ref_idx_l0_active_minus1; cIdx ++ )
553  {
554    m_apcRefPicList[0][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? refPicListTemp0[ m_RefPicListModification.getRefPicSetIdxL0(cIdx) ] : refPicListTemp0[cIdx];
555#if QC_IV_AS_LT_B0046
556    setWasLongTerm(m_apcRefPicList[0][cIdx]->getIsLongTerm(), REF_PIC_LIST_0, cIdx);
557#endif
558  }
559  if( m_eSliceType == P_SLICE )
560  {
561    m_aiNumRefIdx[1] = 0;
562    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]) );
563  }
564  else
565  {
566    for( cIdx = 0; cIdx <= num_ref_idx_l1_active_minus1; cIdx ++ )
567    {
568      m_apcRefPicList[1][cIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? refPicListTemp1[ m_RefPicListModification.getRefPicSetIdxL1(cIdx) ] : refPicListTemp1[cIdx];
569#if QC_IV_AS_LT_B0046
570      setWasLongTerm(m_apcRefPicList[1][cIdx]->getIsLongTerm(), REF_PIC_LIST_1, cIdx);
571#endif
572    }
573  }
574}
575
576Void TComSlice::initEqualRef()
577{
578  for (Int iDir = 0; iDir < 2; iDir++)
579  {
580    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
581    {
582      for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
583      {
584        m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
585      }
586    }
587  }
588}
589
590Void TComSlice::initMultiviewSlice( Int** aaiScale, Int** aaiOffset )
591{
592  if( m_pcSPS->hasCamParInSliceHeader() )
593  {
594    UInt uiViewId = m_pcSPS->getViewId();
595    for( UInt uiBaseViewId = 0; uiBaseViewId < uiViewId; uiBaseViewId++ )
596    {
597      m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][     uiViewId ];
598      m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [     uiViewId ][ uiBaseViewId ];
599      m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][     uiViewId ];
600      m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[     uiViewId ][ uiBaseViewId ];
601    }
602  }
603}
604
605#if COLLOCATED_REF_IDX
606Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic)
607{
608  Int i;
609  TComSlice* curSlice = pic->getSlice(curSliceIdx);
610  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(curSlice->getColDir()), curSlice->getColRefIdx());
611  TComSlice* preSlice;
612  Int preColRefPOC;
613  for(i=curSliceIdx-1; i>=0; i--)
614  {
615    preSlice = pic->getSlice(i);
616    if(preSlice->getSliceType() != I_SLICE)
617    {
618      preColRefPOC  = preSlice->getRefPOC( RefPicList(preSlice->getColDir()), preSlice->getColRefIdx());
619      if(currColRefPOC != preColRefPOC)
620      {
621        printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n");
622        exit(EXIT_FAILURE);
623      }
624      else
625      {
626        break;
627      }
628    }
629  }
630}
631#endif
632Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, TComList<TComPic*>& rcListPic)
633{
634  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
635  {
636    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
637    {
638      assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA);
639    }
640  }
641  for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++)
642  {
643    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
644    {
645      assert(pReferencePictureSet->getPOC(i) >= pocCRA);
646    }
647  }
648  if( getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
649  {
650    pocCRA = getPOC();
651  }
652}
653
654/** Function for marking the reference pictures when an IDR and CRA is encountered.
655 * \param pocCRA POC of the CRA picture
656 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
657 * \param rcListPic reference to the reference picture list
658 * This function marks the reference pictures as "unused for reference" in the following conditions.
659 * If the nal_unit_type is IDR all pictures in the reference picture list 
660 * is marked as "unused for reference"
661 * Otherwise do for the CRA case (non CRA case has no effect since both if conditions below will not be true)
662 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
663 *    temporal reference is greater than the temporal reference of the latest CRA picture (pocCRA),
664 *    mark all reference pictures except the latest CRA picture as "unused for reference" and set
665 *    the bRefreshPending flag to false.
666 *    If the nal_unit_type is CRA, set the bRefreshPending flag to true and pocCRA to the temporal
667 *    reference of the current picture.
668 * Note that the current picture is already placed in the reference list and its marking is not changed.
669 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
670 */
671Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic)
672{
673  TComPic*                 rpcPic;
674  UInt uiPOCCurr = getPOC(); 
675
676  if( getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )  // IDR
677  {
678    // mark all pictures as not used for reference
679    TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
680    while (iterPic != rcListPic.end())
681    {
682      rpcPic = *(iterPic);
683      rpcPic->setCurrSliceIdx(0);
684      if (rpcPic->getPOC() != uiPOCCurr) rpcPic->getSlice(0)->setReferenced(false);
685      iterPic++;
686    }
687  }
688  else // CRA or No DR
689  {
690    if (bRefreshPending==true && uiPOCCurr > pocCRA) // CRA reference marking pending
691    {
692      TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
693      while (iterPic != rcListPic.end())
694      {
695        rpcPic = *(iterPic);
696        if (rpcPic->getPOC() != uiPOCCurr && rpcPic->getPOC() != pocCRA) rpcPic->getSlice(0)->setReferenced(false);
697        iterPic++;
698      }
699      bRefreshPending = false; 
700    }
701    if( getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
702    {
703      bRefreshPending = true; 
704      pocCRA = uiPOCCurr;
705    }
706  }
707}
708
709Void TComSlice::copySliceInfo(TComSlice *pSrc)
710{
711  assert( pSrc != NULL );
712
713  Int i, j, k;
714
715  m_iPOC                 = pSrc->m_iPOC;
716  m_viewId               = pSrc->m_viewId;
717#if INTER_VIEW_VECTOR_SCALING_C0115   
718  m_iViewOrderIdx        = pSrc->m_iViewOrderIdx;// will be changed to view_id
719  m_bIVScalingFlag       = pSrc->m_bIVScalingFlag;
720#endif
721  m_eNalUnitType         = pSrc->m_eNalUnitType;
722  m_eNalUnitTypeBaseViewMvc = pSrc->m_eNalUnitTypeBaseViewMvc;
723  m_eSliceType           = pSrc->m_eSliceType;
724  m_iSliceQp             = pSrc->m_iSliceQp;
725#if ADAPTIVE_QP_SELECTION
726  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
727#endif
728  m_bLoopFilterDisable   = pSrc->m_bLoopFilterDisable;
729  m_inheritDblParamFromAPS = pSrc->m_inheritDblParamFromAPS;
730  m_loopFilterBetaOffsetDiv2 = pSrc->m_loopFilterBetaOffsetDiv2;
731  m_loopFilterTcOffsetDiv2 = pSrc->m_loopFilterTcOffsetDiv2;
732 
733  for (i = 0; i < 3; i++)
734  {
735    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
736  }
737
738  for (i = 0; i < 2; i++)
739  {
740    for (j = 0; j < MAX_NUM_REF_LC; j++)
741    {
742       m_iRefIdxOfLC[i][j]  = pSrc->m_iRefIdxOfLC[i][j];
743    }
744  }
745  for (i = 0; i < MAX_NUM_REF_LC; i++)
746  {
747    m_eListIdFromIdxOfLC[i] = pSrc->m_eListIdFromIdxOfLC[i];
748    m_iRefIdxFromIdxOfLC[i] = pSrc->m_iRefIdxFromIdxOfLC[i];
749    m_iRefIdxOfL1FromRefIdxOfL0[i] = pSrc->m_iRefIdxOfL1FromRefIdxOfL0[i];
750    m_iRefIdxOfL0FromRefIdxOfL1[i] = pSrc->m_iRefIdxOfL0FromRefIdxOfL1[i];
751  }
752  m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC;
753  m_bRefPicListCombinationFlag    = pSrc->m_bRefPicListCombinationFlag;
754  m_bCheckLDC             = pSrc->m_bCheckLDC;
755  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
756  for (i = 0; i < 2; i++)
757  {
758    for (j = 0; j < MAX_NUM_REF; j++)
759    {
760      m_apcRefPicList  [i][j] = pSrc->m_apcRefPicList  [i][j];
761      m_aiRefPOCList   [i][j] = pSrc->m_aiRefPOCList   [i][j];
762      m_aiRefViewIdList[i][j] = pSrc->m_aiRefViewIdList[i][j];
763    }
764  } 
765  m_iDepth               = pSrc->m_iDepth;
766
767  // referenced slice
768  m_bRefenced            = pSrc->m_bRefenced;
769
770  // access channel
771  m_pcSPS                = pSrc->m_pcSPS;
772  m_pcPPS                = pSrc->m_pcPPS;
773  m_pcRPS                = pSrc->m_pcRPS;
774  m_iLastIDR             = pSrc->m_iLastIDR;
775
776  m_pcPic                = pSrc->m_pcPic;
777  m_pcAPS                = pSrc->m_pcAPS;
778  m_iAPSId               = pSrc->m_iAPSId;
779
780  m_uiColDir             = pSrc->m_uiColDir;
781#if COLLOCATED_REF_IDX
782  m_colRefIdx            = pSrc->m_colRefIdx;
783#endif
784#if ALF_CHROMA_LAMBDA || SAO_CHROMA_LAMBDA
785  m_dLambdaLuma          = pSrc->m_dLambdaLuma;
786  m_dLambdaChroma        = pSrc->m_dLambdaChroma;
787#else
788  m_dLambda              = pSrc->m_dLambda;
789#endif
790  for (i = 0; i < 2; i++)
791  {
792    for (j = 0; j < MAX_NUM_REF; j++)
793    {
794      for (k =0; k < MAX_NUM_REF; k++)
795      {
796        m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k];
797      }
798    }
799  }
800
801  m_bNoBackPredFlag      = pSrc->m_bNoBackPredFlag;
802  m_bRefIdxCombineCoding = pSrc->m_bRefIdxCombineCoding;
803
804  m_uiTLayer                      = pSrc->m_uiTLayer;
805  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
806
807  m_uiSliceMode                   = pSrc->m_uiSliceMode;
808  m_uiSliceArgument               = pSrc->m_uiSliceArgument;
809  m_uiSliceCurStartCUAddr         = pSrc->m_uiSliceCurStartCUAddr;
810  m_uiSliceCurEndCUAddr           = pSrc->m_uiSliceCurEndCUAddr;
811  m_uiSliceIdx                    = pSrc->m_uiSliceIdx;
812  m_uiEntropySliceMode            = pSrc->m_uiEntropySliceMode;
813  m_uiEntropySliceArgument        = pSrc->m_uiEntropySliceArgument; 
814  m_uiEntropySliceCurStartCUAddr  = pSrc->m_uiEntropySliceCurStartCUAddr;
815  m_uiEntropySliceCurEndCUAddr    = pSrc->m_uiEntropySliceCurEndCUAddr;
816  m_bNextSlice                    = pSrc->m_bNextSlice;
817  m_bNextEntropySlice             = pSrc->m_bNextEntropySlice;
818  m_iTileMarkerFlag             = pSrc->m_iTileMarkerFlag;
819  for ( int e=0 ; e<2 ; e++ )
820    for ( int n=0 ; n<MAX_NUM_REF ; n++ )
821      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 );
822
823  m_saoEnabledFlag = pSrc->m_saoEnabledFlag; 
824  m_saoInterleavingFlag = pSrc->m_saoInterleavingFlag;
825  m_saoEnabledFlagCb = pSrc->m_saoEnabledFlagCb;
826  m_saoEnabledFlagCr = pSrc->m_saoEnabledFlagCr; 
827#if CABAC_INIT_FLAG
828  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
829#endif
830  m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
831
832  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
833}
834
835int TComSlice::m_prevPOC = 0;
836/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
837 * \param uiTLayer Temporal layer ID of the current slice
838 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
839 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
840 * temporal_layer_switching_point_flag is set accordingly.
841 */
842Void TComSlice::setTLayerInfo( UInt uiTLayer )
843{
844
845  m_uiTLayer = uiTLayer;
846}
847
848#if H0566_TLA_SET_FOR_SWITCHING_POINTS
849/** Function for checking if this is a switching-point
850*/
851Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
852{
853  TComPic* rpcPic;
854  // loop through all pictures in the reference picture buffer
855  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
856  while ( iterPic != rcListPic.end())
857  {
858    rpcPic = *(iterPic++);
859    if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC())
860    {
861      if(rpcPic->getTLayer() >= getTLayer())
862      {
863        return false;
864      }
865    }
866  }
867  return true;
868}
869#endif
870
871/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
872*/
873Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
874{
875  TComPic* rpcPic;
876  Int i, isReference;
877
878  Int j = 0;
879  // loop through all pictures in the reference picture buffer
880  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
881  while ( iterPic != rcListPic.end())
882  {
883    j++;
884    rpcPic = *(iterPic++);
885
886    isReference = 0;
887    // loop through all pictures in the Reference Picture Set to see if the picture should be kept as reference picture
888    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
889    {
890#if QC_IV_AS_LT_B0046
891       if( rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
892#else
893      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
894#endif
895      {
896        isReference = 1;
897        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
898        rpcPic->setIsLongTerm(0);
899      }
900    }
901    // long term pictures
902    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
903    {
904#if QC_IV_AS_LT_B0046
905     if( (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
906#else
907      if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
908#endif
909      {
910        isReference = 1;
911        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
912      }
913    }
914    // mark the picture as "unused for reference" if it is not in
915    // the Reference Picture Set
916    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
917    {           
918      rpcPic->getSlice( 0 )->setReferenced( false );   
919      rpcPic->setIsLongTerm(0);
920    }
921  } 
922}
923
924/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
925*/
926Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool outputFlag, Int pocRandomAccess)
927{
928  TComPic* rpcPic;
929  Int i, isAvailable, j;
930  Int atLeastOneLost = 0;
931  Int atLeastOneRemoved = 0;
932  Int iPocLost = 0;
933
934  // loop through all long-term pictures in the Reference Picture Set
935  // to see if the picture should be kept as reference picture
936  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
937  {
938    j = 0;
939    isAvailable = 0;
940    // loop through all pictures in the reference picture buffer
941    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
942    while ( iterPic != rcListPic.end())
943    {
944      j++;
945      rpcPic = *(iterPic++);
946      if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
947      {
948        isAvailable = 1;
949      }
950    }
951    // if there was no such long-term check the short terms
952    if(!isAvailable)
953    {
954      iterPic = rcListPic.begin();
955      while ( iterPic != rcListPic.end())
956      {
957        j++;
958        rpcPic = *(iterPic++);
959
960        if((rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == (this->getPOC() + pReferencePictureSet->getDeltaPOC(i))%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
961        {
962          isAvailable = 1;
963          rpcPic->setIsLongTerm(1);
964          break;
965        }
966      }
967    }
968    // report that a picture is lost if it is in the Reference Picture Set
969    // but not available as reference picture
970    if(isAvailable == 0)   
971    {           
972      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
973      {
974        if(!pReferencePictureSet->getUsed(i) )
975        {
976          if(outputFlag)
977            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
978          atLeastOneRemoved = 1;
979        }
980        else
981        {
982          if(outputFlag)
983            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
984          atLeastOneLost = 1;
985          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
986        }
987      }
988    }
989  } 
990  // loop through all short-term pictures in the Reference Picture Set
991  // to see if the picture should be kept as reference picture
992  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
993  {
994    j = 0;
995    isAvailable = 0;
996    // loop through all pictures in the reference picture buffer
997    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
998    while ( iterPic != rcListPic.end())
999    {
1000      j++;
1001      rpcPic = *(iterPic++);
1002
1003      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1004      {
1005        isAvailable = 1;
1006      }
1007    }
1008    // report that a picture is lost if it is in the Reference Picture Set
1009    // but not available as reference picture
1010    if(isAvailable == 0)   
1011    {           
1012      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1013      {
1014        if(!pReferencePictureSet->getUsed(i) )
1015        {
1016          if(outputFlag)
1017            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1018          atLeastOneRemoved = 1;
1019        }
1020        else
1021        {
1022          if(outputFlag)
1023            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1024          atLeastOneLost = 1;
1025          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1026        }
1027      }
1028    }
1029  }   
1030  if(atLeastOneLost)
1031  {
1032    return iPocLost+1;
1033  }
1034  if(atLeastOneRemoved)
1035  {
1036    return -2;
1037  }
1038  else
1039    return 0;
1040}
1041
1042/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1043*/
1044Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
1045{
1046  TComPic* rpcPic;
1047  Int i, j;
1048  Int k = 0;
1049  Int nrOfNegativePictures = 0;
1050  Int nrOfPositivePictures = 0;
1051  TComReferencePictureSet* pcRPS = this->getLocalRPS();
1052
1053  // loop through all pictures in the Reference Picture Set
1054  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1055  {
1056    j = 0;
1057    // loop through all pictures in the reference picture buffer
1058    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1059    while ( iterPic != rcListPic.end())
1060    {
1061      j++;
1062      rpcPic = *(iterPic++);
1063
1064      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1065      {
1066        // This picture exists as a reference picture
1067        // and should be added to the explicit Reference Picture Set
1068        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1069        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
1070        if(pcRPS->getDeltaPOC(k) < 0)
1071          nrOfNegativePictures++;
1072        else
1073          nrOfPositivePictures++;
1074        k++;
1075      }
1076    }
1077  }
1078  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1079  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1080  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1081  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1082  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1083  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1084  if (!pReferencePictureSet->getInterRPSPrediction())
1085  {
1086    pcRPS->setInterRPSPrediction(false);
1087    pcRPS->setNumRefIdc(0);
1088  }
1089  else
1090  {
1091    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1092    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1093    TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1094    Int iRefPics = pcRefRPS->getNumberOfPictures();
1095    Int iNewIdc=0;
1096    for(i=0; i<= iRefPics; i++) 
1097    {
1098      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1099      Int iRefIdc = 0;
1100      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1101      {
1102        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
1103        {
1104          if (pcRPS->getUsed(j))
1105          {
1106            iRefIdc = 1;
1107          }
1108          else
1109          {
1110            iRefIdc = 2;
1111          }
1112        }
1113      }
1114      pcRPS->setRefIdc(i, iRefIdc);
1115      iNewIdc++;
1116    }
1117    pcRPS->setInterRPSPrediction(true);
1118    pcRPS->setNumRefIdc(iNewIdc);
1119    pcRPS->setDeltaRPS(deltaRPS); 
1120    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1121  }
1122
1123  this->setRPS(pcRPS);
1124  this->setRPSidx(-1);
1125}
1126
1127Void TComSlice::decodingMarkingForNoTMVP( TComList<TComPic*>& rcListPic, Int currentPOC )
1128{
1129  TComList<TComPic*>::iterator it;
1130  for ( it = rcListPic.begin(); it != rcListPic.end(); it++ )
1131  {
1132    if ( (*it)->getSlice(0)->getPOC() != currentPOC )
1133    {
1134      (*it)->setUsedForTMVP( false );
1135    }
1136  }
1137}
1138
1139/** get AC and DC values for weighted pred
1140 * \param *wp
1141 * \returns Void
1142 */
1143Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
1144{
1145  wp = m_weightACDCParam;
1146}
1147
1148/** init AC and DC values for weighted pred
1149 * \returns Void
1150 */
1151Void  TComSlice::initWpAcDcParam()
1152{
1153  for(Int iComp = 0; iComp < 3; iComp++ )
1154  {
1155    m_weightACDCParam[iComp].iAC = 0;
1156    m_weightACDCParam[iComp].iDC = 0;
1157  }
1158}
1159
1160/** get WP tables for weighted pred
1161 * \param RefPicList
1162 * \param iRefIdx
1163 * \param *&wpScalingParam
1164 * \returns Void
1165 */
1166Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
1167{
1168  wp = m_weightPredTable[e][iRefIdx];
1169}
1170
1171/** reset Default WP tables settings : no weight.
1172 * \param wpScalingParam
1173 * \returns Void
1174 */
1175Void  TComSlice::resetWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
1176{
1177  for ( int e=0 ; e<2 ; e++ ) 
1178  {
1179    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1180    {
1181      for ( int yuv=0 ; yuv<3 ; yuv++ ) 
1182      {
1183        wpScalingParam  *pwp = &(wp[e][i][yuv]);
1184        pwp->bPresentFlag      = false;
1185        pwp->uiLog2WeightDenom = 0;
1186        pwp->uiLog2WeightDenom = 0;
1187        pwp->iWeight           = 1;
1188        pwp->iOffset           = 0;
1189      }
1190    }
1191  }
1192}
1193
1194/** init WP table
1195 * \returns Void
1196 */
1197Void  TComSlice::initWpScaling()
1198{
1199  initWpScaling(m_weightPredTable);
1200}
1201
1202/** set WP tables
1203 * \param wpScalingParam
1204 * \returns Void
1205 */
1206Void  TComSlice::initWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
1207{
1208  for ( int e=0 ; e<2 ; e++ ) 
1209  {
1210    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1211    {
1212      for ( int yuv=0 ; yuv<3 ; yuv++ ) 
1213      {
1214        wpScalingParam  *pwp = &(wp[e][i][yuv]);
1215        if ( !pwp->bPresentFlag ) {
1216          // Inferring values not present :
1217          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1218          pwp->iOffset = 0;
1219        }
1220
1221        pwp->w      = pwp->iWeight;
1222        pwp->o      = pwp->iOffset * (1 << (g_uiBitDepth-8));
1223        pwp->shift  = pwp->uiLog2WeightDenom;
1224        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1225      }
1226    }
1227  }
1228}
1229
1230/** get WP tables for weighted pred of LC
1231 * \param iRefIdxLC
1232 * \param *&wpScalingParam
1233 * \returns Void
1234 */
1235Void TComSlice::getWpScalingLC( Int iRefIdx, wpScalingParam *&wp )
1236{
1237  wp = m_weightPredTableLC[iRefIdx];
1238}
1239/** reset Default WP tables settings for LC : no weight.
1240 * \param wpScalingParam
1241 * \returns Void
1242 */
1243Void TComSlice::resetWpScalingLC(wpScalingParam  wp[2*MAX_NUM_REF][3])
1244{
1245  for ( int i=0 ; i<2*MAX_NUM_REF ; i++ )
1246  {
1247    for ( int yuv=0 ; yuv<3 ; yuv++ ) 
1248    {
1249      wpScalingParam  *pwp = &(wp[i][yuv]);
1250      pwp->bPresentFlag      = false;
1251      pwp->uiLog2WeightDenom = 0;
1252      pwp->uiLog2WeightDenom = 0;
1253      pwp->iWeight           = 1;
1254      pwp->iOffset           = 0;
1255    }
1256  }
1257}
1258/** set current WP tables settings for LC
1259 * \returns Void
1260 */
1261Void TComSlice::setWpParamforLC()
1262{
1263  for ( Int iRefIdx=0 ; iRefIdx<getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ )
1264  {
1265    RefPicList eRefPicList = (RefPicList)getListIdFromIdxOfLC(iRefIdx);
1266    Int iCombRefIdx = getRefIdxFromIdxOfLC(iRefIdx);
1267
1268    wpScalingParam  *wp_src, *wp_dst;
1269    getWpScalingLC(iRefIdx, wp_src);
1270    getWpScaling(eRefPicList, iCombRefIdx, wp_dst);
1271    copyWPtable(wp_src, wp_dst);
1272
1273    if(eRefPicList == REF_PIC_LIST_0)
1274    {
1275      Int iRefIdxL1 = getRefIdxOfL1FromRefIdxOfL0(iCombRefIdx);
1276      if(iRefIdxL1 >= 0)
1277      {
1278        getWpScaling(REF_PIC_LIST_1, iRefIdxL1, wp_dst);
1279        copyWPtable(wp_src, wp_dst);
1280      }
1281    }
1282    if(eRefPicList == REF_PIC_LIST_1)
1283    {
1284      Int iRefIdxL0 = getRefIdxOfL0FromRefIdxOfL1(iCombRefIdx);
1285      if(iRefIdxL0 >= 0)
1286      {
1287        getWpScaling(REF_PIC_LIST_0, iRefIdxL0, wp_dst);
1288        copyWPtable(wp_src, wp_dst);
1289      }
1290    }
1291  }
1292  initWpScaling();
1293}
1294/** copy source WP tables to destination table for LC
1295 * \param wpScalingParam *&wp_src : source
1296 * \param wpScalingParam *&wp_dst : destination
1297 * \returns Void
1298 */
1299Void TComSlice::copyWPtable(wpScalingParam *&wp_src, wpScalingParam *&wp_dst)
1300{
1301  for ( Int iComp = 0; iComp < 3; iComp++ )
1302  {
1303    wp_dst[iComp].uiLog2WeightDenom = (iComp==0) ? wp_src[0].uiLog2WeightDenom : wp_src[1].uiLog2WeightDenom;
1304    wp_dst[iComp].bPresentFlag = wp_src[iComp].bPresentFlag;
1305    wp_dst[iComp].iWeight = wp_src[iComp].iWeight;
1306    wp_dst[iComp].iOffset = wp_src[iComp].iOffset;
1307  }
1308}
1309
1310#if LGE_ILLUCOMP_B0045
1311Void TComSlice::xSetApplyIC()
1312{
1313  Int iMaxPelValue = (1<<g_uiBitDepth); 
1314  Int *aiRefOrgHist;
1315  Int *aiCurrHist;
1316  aiRefOrgHist = new Int;
1317  aiCurrHist   = new Int;
1318  aiRefOrgHist = (Int *)xMalloc(Int,iMaxPelValue);
1319  aiCurrHist   = (Int *)xMalloc(Int,iMaxPelValue);
1320  memset(aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
1321  memset(aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
1322  // Reference Idx Number
1323  Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 );
1324  TComPic* pcCurrPic = NULL;
1325  TComPic* pcRefPic = NULL;
1326  TComPicYuv* pcCurrPicYuv = NULL;
1327  TComPicYuv* pcRefPicYuvOrg = NULL;
1328  pcCurrPic = getPic();
1329  pcCurrPicYuv = pcCurrPic->getPicYuvOrg();
1330  Int iWidth = pcCurrPicYuv->getWidth();
1331  Int iHeight = pcCurrPicYuv->getHeight();
1332
1333
1334  // Get InterView Reference picture
1335  // !!!!! Assume only one Interview Reference Picture in L0
1336  for (Int i = 0; i < iNumRefIdx; i++)
1337  {
1338    pcRefPic = getRefPic( REF_PIC_LIST_0, i);
1339    if (pcRefPic != NULL)
1340    {
1341      // Current Picture
1342      if (pcCurrPic->getViewId() != pcRefPic->getViewId())
1343      {
1344        pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
1345      }
1346    }
1347  }
1348  if (pcRefPicYuvOrg != NULL)
1349  {
1350    Pel* pCurrY = pcCurrPicYuv ->getLumaAddr();
1351    Pel* pRefOrgY = pcRefPicYuvOrg  ->getLumaAddr();
1352    Int iCurrStride = pcCurrPicYuv->getStride();
1353    Int iRefStride = pcRefPicYuvOrg->getStride();
1354    Int iSumOrgSAD = 0;
1355#if LGE_ILLUCOMP_DEPTH_C0046
1356    Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
1357#else
1358    double dThresholdOrgSAD = 0.05;
1359#endif
1360    // Histogram building - luminance
1361    for ( Int y = 0; y < iHeight; y++)
1362    {
1363      for ( Int x = 0; x < iWidth; x++)
1364      {
1365        aiCurrHist[pCurrY[x]]++;
1366        aiRefOrgHist[pRefOrgY[x]]++;
1367      }
1368      pCurrY += iCurrStride;
1369      pRefOrgY += iRefStride;
1370    }
1371    // Calc SAD
1372    for (Int i = 0; i < iMaxPelValue; i++)
1373    {
1374      iSumOrgSAD += abs(aiCurrHist[i] - aiRefOrgHist[i]);
1375    }
1376    // Setting
1377    if ( iSumOrgSAD > Int(dThresholdOrgSAD * iWidth * iHeight) )
1378    {
1379      m_bApplyIC = true;
1380    }
1381    else
1382    {
1383      m_bApplyIC = false;
1384    }
1385  }
1386  xFree(aiCurrHist);
1387  xFree(aiRefOrgHist);
1388  aiCurrHist = NULL;
1389  aiRefOrgHist = NULL;
1390}
1391#endif
1392
1393#if MERL_VSP_NBDV_RefVId_Fix_D0166
1394TComPic* TComSlice::getDepthRefPic(Int viewId, Int poc)
1395{
1396  TComPic* pPic = NULL;
1397
1398  if (m_pcListDepthPic[viewId] == NULL)
1399    return NULL;
1400
1401  for( TComList<TComPic*>::iterator it = m_pcListDepthPic[viewId]->begin(); it != m_pcListDepthPic[viewId]->end(); it++ )
1402  {
1403    TComPic* currPic = *it;
1404    TComSlice* currSlice = currPic->getCurrSlice();
1405    Bool isDepth = currSlice->getIsDepth();
1406    //assert(isDepth);
1407    if( isDepth && currPic->getPOC() == poc && currPic->getViewId() == viewId ) // (*it)->getSPS()->isDepth()
1408    {
1409      pPic = *it;
1410      break;
1411    }
1412  }
1413
1414  return pPic;
1415}
1416#endif
1417
1418
1419#if QC_ARP_D0177
1420Void TComSlice::setARPStepNum()                                 
1421{
1422  Bool bAllIvRef = false;
1423  if(!getSPS()->getUseAdvRP())
1424    m_nARPStepNum = 0;
1425  else
1426  {
1427    for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
1428    {
1429      RefPicList  eRefPicList = RefPicList( iRefListId );
1430      Int iNumRefIdx = getNumRefIdx(eRefPicList);
1431      if( iNumRefIdx <= 0 )
1432        continue;
1433      for (Int i = 0; i < iNumRefIdx; i++)
1434      {
1435        if(getRefPic( REF_PIC_LIST_0, i)->getPOC() != getPOC())
1436        {
1437          bAllIvRef = true;
1438          break;
1439        }
1440      }
1441      if( bAllIvRef == true )
1442        break;
1443    }
1444    if(bAllIvRef== true)
1445      m_nARPStepNum = getSPS()->getARPStepNum();
1446    else
1447      m_nARPStepNum = 0;
1448  }
1449}
1450#endif
1451// ------------------------------------------------------------------------------------------------
1452// Video parameter set (VPS)
1453// ------------------------------------------------------------------------------------------------
1454#if QC_MVHEVC_B0046
1455TComVPS::TComVPS()
1456: m_VPSId                     (  0)
1457, m_uiMaxTLayers              (  1)
1458, m_uiMaxLayers               (  1)
1459, m_bTemporalIdNestingFlag    (false)
1460, m_uiNumHRDParameter         (  0)
1461, m_numAddiLayerOperationPoints (2)
1462, m_numAddiProLevelSets       (  1)
1463{
1464  for( Int i = 0; i < MAX_LAYER_NUM; i++)
1465  {
1466  m_numOpLayerIdMinus1[i] = 0;
1467  if(i)
1468      m_numDirectRefLayer[i] = 1;
1469  else
1470    m_numDirectRefLayer[i] = 0;
1471  for( Int j = 0; j < MAX_LAYER_NUM; j++)
1472  {
1473    m_numDirectRefID[i][j] = 0;
1474    m_numOpLayerId[i][j]   = 0;
1475  }
1476    m_uiViewId[i] = 0;
1477    m_iViewOrderIdx[i] = 0;
1478  }
1479 
1480  for( Int i = 0; i < MAX_TLAYER; i++)
1481  {
1482    m_numReorderPics[i] = 0;
1483    m_uiMaxDecPicBuffering[i] = 0; 
1484    m_uiMaxLatencyIncrease[i] = 0;
1485  }
1486}
1487
1488TComVPS::~TComVPS()
1489{
1490}
1491#else
1492#if VIDYO_VPS_INTEGRATION
1493TComVPS::TComVPS()
1494: m_VPSId                     (  0)
1495, m_uiMaxTLayers              (  1)
1496, m_uiMaxLayers               (  1)
1497, m_bTemporalIdNestingFlag    (false)
1498, m_uiExtensionType           (  0)
1499{
1500  for( Int i = 0; i < MAX_LAYER_NUM; i++)
1501  {
1502    m_uiDependentLayer[i] = i? i-1: 0;
1503    m_bDependentFlag[i] = false;
1504    m_uiViewId[i] = 0;
1505    m_bDepthFlag[i] = 0;
1506    m_iViewOrderIdx[i] = 0;
1507  }
1508 
1509  for( Int i = 0; i < MAX_TLAYER; i++)
1510  {
1511    m_numReorderPics[i] = 0;
1512    m_uiMaxDecPicBuffering[i] = 0; 
1513    m_uiMaxLatencyIncrease[i] = 0;
1514  }
1515}
1516
1517TComVPS::~TComVPS()
1518{
1519 
1520 
1521}
1522
1523#endif
1524#endif
1525
1526// ------------------------------------------------------------------------------------------------
1527// Sequence parameter set (SPS)
1528// ------------------------------------------------------------------------------------------------
1529
1530TComSPS::TComSPS()
1531#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
1532: m_VPSId                     (  0)
1533, m_SPSId                     (  0)
1534#else
1535: m_SPSId                     (  0)
1536#endif
1537, m_ProfileIdc                (  0)
1538, m_LevelIdc                  (  0)
1539, m_chromaFormatIdc           (CHROMA_420)
1540, m_uiMaxTLayers              (  1)
1541// Structure
1542, m_picWidthInLumaSamples     (352)
1543, m_picHeightInLumaSamples    (288)
1544, m_picCroppingFlag           (false)
1545, m_picCropLeftOffset         (  0)
1546, m_picCropRightOffset        (  0)
1547, m_picCropTopOffset          (  0)
1548, m_picCropBottomOffset       (  0) 
1549, m_uiMaxCUWidth              ( 32)
1550, m_uiMaxCUHeight             ( 32)
1551, m_uiMaxCUDepth              (  3)
1552, m_uiMinTrDepth              (  0)
1553, m_uiMaxTrDepth              (  1)
1554, m_bLongTermRefsPresent      (false)
1555, m_iNumberOfUsableInterViewRefs( 0 )
1556, m_uiQuadtreeTULog2MaxSize   (  0)
1557, m_uiQuadtreeTULog2MinSize   (  0)
1558, m_uiQuadtreeTUMaxDepthInter (  0)
1559, m_uiQuadtreeTUMaxDepthIntra (  0)
1560// Tool list
1561, m_usePCM                   (false)
1562, m_pcmLog2MaxSize            (  5)
1563, m_uiPCMLog2MinSize          (  7)
1564, m_bDisInter4x4              (  1)
1565, m_bUseALF                   (false)
1566, m_bALFCoefInSlice           (false)
1567, m_bUseLMChroma              (false)
1568, m_bUseLComb                 (false)
1569, m_bLCMod                    (false)
1570#if QC_MVHEVC_B0046
1571, m_restrictedRefPicListsFlag   (  0)
1572#else
1573, m_restrictedRefPicListsFlag   (  1)
1574#endif
1575, m_listsModificationPresentFlag(  0)
1576, m_uiBitDepth                (  8)
1577, m_uiBitIncrement            (  0)
1578, m_qpBDOffsetY               (  0)
1579, m_qpBDOffsetC               (  0)
1580#if LOSSLESS_CODING
1581, m_useLossless               (false)
1582#endif
1583, m_uiPCMBitDepthLuma         (  8)
1584, m_uiPCMBitDepthChroma       (  8)
1585, m_bPCMFilterDisableFlag     (false)
1586, m_uiBitsForPOC              (  8)
1587, m_uiMaxTrSize               ( 32)
1588, m_bLFCrossSliceBoundaryFlag (false)
1589, m_bUseSAO                   (false) 
1590#if HHI_MPI
1591, m_bUseMVI                   (false)
1592#endif
1593, m_bLFCrossTileBoundaryFlag  (false) 
1594, m_iUniformSpacingIdr        (  0 )
1595, m_iTileBoundaryIndependenceIdr (  0 )
1596, m_iNumColumnsMinus1         (  0 )
1597, m_puiColumnWidth            ( NULL )
1598, m_iNumRowsMinus1            (  0 )
1599, m_puiRowHeight              ( NULL )
1600, m_bTemporalIdNestingFlag    (false)
1601, m_scalingListEnabledFlag    (false)
1602,  m_tilesOrEntropyCodingSyncIdc( 0 )
1603,  m_numSubstreams              ( 0 )
1604#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1605, m_bUseDMM                   (false)
1606#endif
1607#if FLEX_CODING_ORDER_M23723 && HHI_DMM_PRED_TEX
1608, m_bUseDMM34                   (false)
1609#endif
1610#if H3D_QTL
1611, m_bUseQTLPC                 (false)
1612#endif
1613{
1614  // AMVP parameter
1615  ::memset( m_aeAMVPMode, 0, sizeof( m_aeAMVPMode ) );
1616  for ( Int i = 0; i < MAX_TLAYER; i++ )
1617  {
1618    m_uiMaxLatencyIncrease[i] = 0;
1619    m_uiMaxDecPicBuffering[i] = 0;
1620    m_numReorderPics[i]       = 0;
1621  }
1622
1623  m_uiViewId              = 0;
1624  m_iViewOrderIdx         = 0;
1625  m_bDepth                = false;
1626  m_uiCamParPrecision     = 0;
1627  m_bCamParInSliceHeader  = false;
1628  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
1629  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
1630
1631#if DEPTH_MAP_GENERATION
1632  m_uiPredDepthMapGeneration = 0;
1633  m_uiPdmPrecision           = 0;
1634  ::memset( m_aiPdmScaleNomDelta, 0x00, sizeof( m_aiPdmScaleNomDelta  ) );
1635  ::memset( m_aiPdmOffset,        0x00, sizeof( m_aiPdmOffset         ) );
1636#endif
1637#if H3D_IVMP
1638  m_uiMultiviewMvPredMode    = 0;
1639#endif
1640#if QC_ARP_D0177
1641  m_nUseAdvResPred           = 0;
1642  m_nARPStepNum              = 1;
1643#endif
1644  ::memset( m_aiUsableInterViewRefs, 0, sizeof( m_aiUsableInterViewRefs ) );
1645 
1646#if RWTH_SDC_DLT_B0036
1647  m_bUseDLT = false;
1648 
1649  m_uiBitsPerDepthValue = g_uiBitDepth;
1650  m_uiNumDepthmapValues = 0;
1651  m_uiDepthValue2Idx    = NULL;
1652  m_uiIdx2DepthValue    = NULL;
1653#endif
1654}
1655
1656TComSPS::~TComSPS()
1657{
1658  if( m_iNumColumnsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1659  {
1660    delete [] m_puiColumnWidth; 
1661    m_puiColumnWidth = NULL;
1662  }
1663  if( m_iNumRowsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1664  {
1665    delete [] m_puiRowHeight;
1666    m_puiRowHeight = NULL;
1667  }
1668}
1669
1670#if RWTH_SDC_DLT_B0036
1671Void TComSPS::setDepthLUTs(UInt* uidx2DepthValue, UInt uiNumDepthValues)
1672{
1673  UInt uiMaxDepthValue = g_uiIBDI_MAX;
1674 
1675  // allocate some memory
1676  if( m_uiNumDepthmapValues == 0 )
1677  {
1678    m_uiNumDepthmapValues = uiMaxDepthValue+1;
1679    m_uiBitsPerDepthValue = (UInt)ceil(Log2(m_uiNumDepthmapValues));
1680   
1681    m_uiDepthValue2Idx    = (UInt*) xMalloc(UInt, m_uiNumDepthmapValues);
1682    m_uiIdx2DepthValue    = (UInt*) xMalloc(UInt, m_uiNumDepthmapValues);
1683   
1684    //default mapping
1685    for (Int i=0; i<m_uiNumDepthmapValues; i++)
1686    {
1687      m_uiDepthValue2Idx[i] = i;
1688      m_uiIdx2DepthValue[i] = i;
1689    }
1690  }
1691 
1692  if( uidx2DepthValue == NULL || uiNumDepthValues == 0 ) // default mapping only
1693    return;
1694 
1695  // copy idx2DepthValue to internal array
1696  memcpy(m_uiIdx2DepthValue, uidx2DepthValue, uiNumDepthValues*sizeof(UInt));
1697 
1698  for(Int p=0; p<=uiMaxDepthValue; p++)
1699  {
1700    Int iIdxDown    = 0;
1701    Int iIdxUp      = uiNumDepthValues-1;
1702    Bool bFound     = false;
1703   
1704    // iterate over indices to find lower closest depth
1705    Int i = 1;
1706    while(!bFound && i<uiNumDepthValues)
1707    {
1708      if( m_uiIdx2DepthValue[i] > p )
1709      {
1710        iIdxDown  = i-1;
1711        bFound    = true;
1712      }
1713     
1714      i++;
1715    }
1716    // iterate over indices to find upper closest depth
1717    i = uiNumDepthValues-2;
1718    bFound = false;
1719    while(!bFound && i>=0)
1720    {
1721      if( m_uiIdx2DepthValue[i] < p )
1722      {
1723        iIdxUp  = i+1;
1724        bFound    = true;
1725      }
1726     
1727      i--;
1728    }
1729   
1730    // assert monotony
1731    assert(iIdxDown<=iIdxUp);
1732   
1733    // assign closer depth value/idx
1734    if( abs(p-(Int)m_uiIdx2DepthValue[iIdxDown]) < abs(p-(Int)m_uiIdx2DepthValue[iIdxUp]) )
1735    {
1736      m_uiDepthValue2Idx[p] = iIdxDown;
1737    }
1738    else
1739    {
1740      m_uiDepthValue2Idx[p] = iIdxUp;
1741    }
1742   
1743  }
1744 
1745  // update globals
1746  m_uiNumDepthmapValues = uiNumDepthValues;
1747  m_uiBitsPerDepthValue = (UInt)ceil(Log2(m_uiNumDepthmapValues));
1748}
1749#endif
1750
1751TComPPS::TComPPS()
1752: m_PPSId                       (0)
1753, m_SPSId                       (0)
1754, m_picInitQPMinus26            (0)
1755, m_useDQP                      (false)
1756, m_bConstrainedIntraPred       (false)
1757, m_pcSPS                       (NULL)
1758, m_uiMaxCuDQPDepth             (0)
1759, m_uiMinCuDQPSize              (0)
1760, m_iChromaQpOffset             (0)
1761, m_iChromaQpOffset2nd          (0)
1762, m_iSliceGranularity           (0)
1763, m_iTileBehaviorControlPresentFlag (0)
1764, m_bLFCrossTileBoundaryFlag     (true)
1765, m_iColumnRowInfoPresent        (0)
1766, m_iUniformSpacingIdr           (0)
1767, m_iNumColumnsMinus1            (0)
1768, m_puiColumnWidth               (NULL)
1769, m_iNumRowsMinus1               (0)
1770, m_puiRowHeight                 (NULL)
1771,  m_iNumSubstreams             (1)
1772, m_signHideFlag(0)
1773, m_signHidingThreshold(0)
1774#if CABAC_INIT_FLAG
1775, m_cabacInitPresentFlag        (false)
1776, m_encCABACTableIdx            (0)
1777#if FIX_POZNAN_CABAC_INIT_FLAG
1778, m_encPrevPOC            (0)
1779#endif
1780#endif
1781{
1782}
1783
1784TComPPS::~TComPPS()
1785{
1786  if( m_iNumColumnsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1787  {
1788    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
1789    m_puiColumnWidth = NULL;
1790  }
1791  if( m_iNumRowsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1792  {
1793    if (m_puiRowHeight) delete [] m_puiRowHeight;
1794    m_puiRowHeight = NULL;
1795  }
1796}
1797
1798Void
1799TComSPS::initMultiviewSPS( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
1800{
1801#if !QC_MVHEVC_B0046
1802  AOT( uiViewId == 0 && iViewOrderIdx != 0 );
1803  AOT( uiViewId != 0 && iViewOrderIdx == 0 );
1804  AOT( uiViewId != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) );
1805#endif
1806  m_uiViewId              = uiViewId;
1807  m_iViewOrderIdx         = iViewOrderIdx;
1808  m_bDepth                = false;
1809  m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
1810  m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
1811  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
1812  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
1813#if !QC_MVHEVC_B0046
1814  if( !m_bCamParInSliceHeader )
1815  {
1816    for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
1817    {
1818      m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
1819      m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
1820      m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
1821      m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
1822    }
1823  }
1824#endif
1825}
1826
1827Void
1828#if FCO_FIX_SPS_CHANGE
1829TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
1830#else
1831TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx )
1832#endif
1833{
1834  AOT( uiViewId == 0 && iViewOrderIdx != 0 );
1835  AOT( uiViewId != 0 && iViewOrderIdx == 0 );
1836
1837  m_uiViewId              = uiViewId;
1838  m_iViewOrderIdx         = iViewOrderIdx;
1839  m_bDepth                = true;
1840#if FCO_FIX_SPS_CHANGE
1841  m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
1842  m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
1843#else
1844  m_uiCamParPrecision     = 0;
1845  m_bCamParInSliceHeader  = false;
1846#endif
1847  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
1848  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
1849#if FCO_FIX_SPS_CHANGE
1850#if !QC_MVHEVC_B0046
1851  if( !m_bCamParInSliceHeader )
1852  {
1853    for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
1854    {
1855      m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
1856      m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
1857      m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
1858      m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
1859    }
1860  }
1861#endif
1862#endif
1863
1864}
1865
1866#if DEPTH_MAP_GENERATION
1867Void
1868TComSPS::setPredDepthMapGeneration( UInt uiViewId, Bool bIsDepth, UInt uiPdmGenMode, UInt uiPdmMvPredMode, UInt uiPdmPrec, Int** aaiPdmScaleNomDelta, Int** aaiPdmOffset )
1869{ 
1870  AOF( m_uiViewId == uiViewId );
1871  AOF( m_bDepth   == bIsDepth );
1872  AOT( ( uiViewId == 0 || bIsDepth ) && uiPdmGenMode );
1873  AOT( uiPdmGenMode && ( aaiPdmScaleNomDelta == 0 || aaiPdmOffset == 0 ) );
1874  AOT( uiPdmMvPredMode && uiPdmGenMode == 0 );
1875
1876  m_uiPredDepthMapGeneration = uiPdmGenMode;
1877#if H3D_IVMP
1878  m_uiMultiviewMvPredMode    = uiPdmMvPredMode;
1879#endif
1880
1881  m_uiPdmPrecision           = ( m_uiPredDepthMapGeneration ? uiPdmPrec : 0 );
1882  ::memset( m_aiPdmScaleNomDelta, 0x00, sizeof( m_aiPdmScaleNomDelta  ) );
1883  ::memset( m_aiPdmOffset,        0x00, sizeof( m_aiPdmOffset         ) );
1884  if( m_uiPredDepthMapGeneration )
1885  {
1886    for( UInt uiBaseId = 0; uiBaseId < m_uiViewId; uiBaseId++ )
1887    {
1888      m_aiPdmScaleNomDelta[ uiBaseId ]  = aaiPdmScaleNomDelta[ m_uiViewId ][ uiBaseId ];
1889      m_aiPdmOffset       [ uiBaseId ]  = aaiPdmOffset       [ m_uiViewId ][ uiBaseId ];
1890    }
1891  }
1892}
1893#endif
1894
1895TComReferencePictureSet::TComReferencePictureSet()
1896: m_numberOfPictures (0)
1897, m_numberOfNegativePictures (0)
1898, m_numberOfPositivePictures (0)
1899, m_numberOfLongtermPictures (0)
1900, m_interRPSPrediction (0) 
1901, m_deltaRIdxMinus1 (0)   
1902, m_deltaRPS (0) 
1903, m_numRefIdc (0) 
1904{
1905  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
1906  ::memset( m_POC, 0, sizeof(m_POC) );
1907  ::memset( m_used, 0, sizeof(m_used) );
1908  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
1909}
1910
1911TComReferencePictureSet::~TComReferencePictureSet()
1912{
1913}
1914
1915Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
1916{
1917  m_used[bufferNum] = used;
1918}
1919
1920Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
1921{
1922  m_deltaPOC[bufferNum] = deltaPOC;
1923}
1924
1925Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
1926{
1927  m_numberOfPictures = numberOfPictures;
1928}
1929
1930Int TComReferencePictureSet::getUsed(Int bufferNum)
1931{
1932  return m_used[bufferNum];
1933}
1934
1935Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
1936{
1937  return m_deltaPOC[bufferNum];
1938}
1939
1940Int TComReferencePictureSet::getNumberOfPictures()
1941{
1942  return m_numberOfPictures;
1943}
1944
1945Int TComReferencePictureSet::getPOC(Int bufferNum)
1946{
1947  return m_POC[bufferNum];
1948}
1949Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
1950{
1951  m_POC[bufferNum] = POC;
1952}
1953
1954/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
1955 * \param uiBufferNum
1956 * \param iRefIdc
1957 * \returns Void
1958 */
1959Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
1960{
1961  m_refIdc[bufferNum] = refIdc;
1962}
1963
1964/** get the reference idc value at uiBufferNum
1965 * \param uiBufferNum
1966 * \returns Int
1967 */
1968Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
1969{
1970  return m_refIdc[bufferNum];
1971}
1972
1973/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
1974 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
1975 *  +ve values are in increasing order.
1976 * \returns Void
1977 */
1978Void TComReferencePictureSet::sortDeltaPOC()
1979{
1980  // sort in increasing order (smallest first)
1981  for(Int j=1; j < getNumberOfPictures(); j++)
1982  { 
1983    Int deltaPOC = getDeltaPOC(j);
1984    Bool used = getUsed(j);
1985    for (Int k=j-1; k >= 0; k--)
1986    {
1987      Int temp = getDeltaPOC(k);
1988      if (deltaPOC < temp)
1989      {
1990        setDeltaPOC(k+1, temp);
1991        setUsed(k+1, getUsed(k));
1992        setDeltaPOC(k, deltaPOC);
1993        setUsed(k, used);
1994      }
1995    }
1996  }
1997  // flip the negative values to largest first
1998  Int numNegPics = getNumberOfNegativePictures();
1999  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
2000  { 
2001    Int deltaPOC = getDeltaPOC(j);
2002    Bool used = getUsed(j);
2003    setDeltaPOC(j, getDeltaPOC(k));
2004    setUsed(j, getUsed(k));
2005    setDeltaPOC(k, deltaPOC);
2006    setUsed(k, used);
2007  }
2008}
2009
2010/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
2011 *  A "*" is added to the deltaPOC value if it is Used bu current.
2012 * \returns Void
2013 */
2014Void TComReferencePictureSet::printDeltaPOC()
2015{
2016  printf("DeltaPOC = { ");
2017  for(Int j=0; j < getNumberOfPictures(); j++)
2018  {
2019    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
2020  } 
2021  if (getInterRPSPrediction()) 
2022  {
2023    printf("}, RefIdc = { ");
2024    for(Int j=0; j < getNumRefIdc(); j++)
2025    {
2026      printf("%d ", getRefIdc(j));
2027    } 
2028  }
2029  printf("}\n");
2030}
2031
2032TComRPSList::TComRPSList()
2033{
2034}
2035
2036TComRPSList::~TComRPSList()
2037{
2038}
2039
2040Void TComRPSList::create( Int numberOfReferencePictureSets)
2041{
2042  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2043  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
2044}
2045
2046Void TComRPSList::destroy()
2047{
2048  delete [] m_referencePictureSets;
2049  m_numberOfReferencePictureSets = 0;
2050  m_referencePictureSets = NULL;
2051}
2052
2053
2054
2055TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
2056{
2057  return &m_referencePictureSets[referencePictureSetNum];
2058}
2059
2060Int TComRPSList::getNumberOfReferencePictureSets()
2061{
2062  return m_numberOfReferencePictureSets;
2063}
2064
2065Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
2066{
2067  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2068}
2069
2070TComRefPicListModification::TComRefPicListModification()
2071: m_bRefPicListModificationFlagL0 (false)
2072, m_bRefPicListModificationFlagL1 (false)
2073{
2074  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
2075  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
2076}
2077
2078TComRefPicListModification::~TComRefPicListModification()
2079{
2080}
2081
2082TComAPS::TComAPS()
2083{
2084  m_apsID = 0;
2085  m_bAlfEnabled = false;
2086  m_bSaoEnabled = false;
2087  m_pSaoParam = NULL;
2088  m_alfParamSet = NULL;
2089  m_scalingList = NULL;
2090  m_scalingListEnabled = false;
2091}
2092
2093TComAPS::~TComAPS()
2094{
2095
2096}
2097
2098TComAPS& TComAPS::operator= (const TComAPS& src)
2099{
2100  m_apsID       = src.m_apsID;
2101  m_loopFilterOffsetInAPS = src.m_loopFilterOffsetInAPS;
2102  m_loopFilterDisable = src.m_loopFilterDisable;
2103  m_loopFilterBetaOffsetDiv2 = src.m_loopFilterBetaOffsetDiv2;
2104  m_loopFilterTcOffsetDiv2 = src.m_loopFilterTcOffsetDiv2;
2105  m_bAlfEnabled = src.m_bAlfEnabled;
2106  m_bSaoEnabled = src.m_bSaoEnabled;
2107  m_pSaoParam   = src.m_pSaoParam; 
2108  m_alfParamSet    = src.m_alfParamSet;
2109  m_scalingList = src.m_scalingList;
2110  m_scalingListEnabled = src.m_scalingListEnabled;
2111  m_saoInterleavingFlag = src.m_saoInterleavingFlag;
2112
2113  return *this;
2114}
2115
2116Void TComAPS::createSaoParam()
2117{
2118  m_pSaoParam = new SAOParam;
2119}
2120
2121Void TComAPS::destroySaoParam()
2122{
2123  if(m_pSaoParam != NULL)
2124  {
2125    delete m_pSaoParam;
2126    m_pSaoParam = NULL;
2127  }
2128}
2129
2130Void TComAPS::createAlfParam()
2131{
2132  m_alfParamSet = new AlfParamSet;
2133}
2134Void TComAPS::destroyAlfParam()
2135{
2136  if(m_alfParamSet != NULL)
2137  {
2138    delete m_alfParamSet;
2139    m_alfParamSet = NULL;
2140  }
2141}
2142
2143Void TComAPS::createScalingList()
2144{
2145  m_scalingList = new TComScalingList;
2146}
2147Void TComAPS::destroyScalingList()
2148{
2149  delete m_scalingList;
2150}
2151
2152TComScalingList::TComScalingList()
2153{
2154  init();
2155}
2156TComScalingList::~TComScalingList()
2157{
2158  destroy();
2159}
2160
2161/** set default quantization matrix to array
2162*/
2163Void TComSlice::setDefaultScalingList()
2164{
2165  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2166  {
2167    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2168    {
2169      getScalingList()->processDefaultMarix(sizeId, listId);
2170    }
2171  }
2172}
2173/** check if use default quantization matrix
2174 * \returns true if use default quantization matrix in all size
2175*/
2176Bool TComSlice::checkDefaultScalingList()
2177{
2178  UInt defaultCounter=0;
2179
2180  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2181  {
2182    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2183    {
2184      if(getScalingList()->getUseDefaultScalingMatrixFlag(sizeId,listId))
2185      {
2186        defaultCounter++;
2187      }
2188    }
2189  }
2190  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? true : false; // -4 for 32x32
2191}
2192/** get scaling matrix from RefMatrixID
2193 * \param sizeId size index
2194 * \param Index of input matrix
2195 * \param Index of reference matrix
2196 */
2197Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
2198{
2199  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListAddress(sizeId, refListId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2200}
2201/** parse syntax infomation
2202 *  \param pchFile syntax infomation
2203 *  \returns false if successful
2204 */
2205Bool TComScalingList::xParseScalingList(char* pchFile)
2206{
2207  FILE *fp;
2208  Char line[1024];
2209  UInt sizeIdc,listIdc;
2210  UInt i,size = 0;
2211  Int *src=0,data;
2212  Char *ret;
2213  UInt  retval;
2214
2215  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
2216  {
2217    printf("can't open file %s :: set Default Matrix\n",pchFile);
2218    return true;
2219  }
2220
2221  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
2222  {
2223    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
2224    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
2225    {
2226      src = getScalingListAddress(sizeIdc, listIdc);
2227
2228      fseek(fp,0,0);
2229      do 
2230      {
2231        ret = fgets(line, 1024, fp);
2232        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
2233        {
2234          printf("Error: can't read Matrix :: set Default Matrix\n");
2235          return true;
2236        }
2237      }
2238      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
2239      for (i=0; i<size; i++)
2240      {
2241        retval = fscanf(fp, "%d,", &data);
2242        if (retval!=1)
2243        {
2244          printf("Error: can't read Matrix :: set Default Matrix\n");
2245          return true;
2246        }
2247        src[i] = data;
2248      }
2249      //set DC value for default matrix check
2250      setScalingListDC(sizeIdc,listIdc,src[0]);
2251
2252      if(sizeIdc > SCALING_LIST_8x8)
2253      {
2254        fseek(fp,0,0);
2255        do 
2256        {
2257          ret = fgets(line, 1024, fp);
2258          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
2259          {
2260            printf("Error: can't read DC :: set Default Matrix\n");
2261            return true;
2262          }
2263        }
2264        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
2265          retval = fscanf(fp, "%d,", &data);
2266          if (retval!=1)
2267          {
2268            printf("Error: can't read Matrix :: set Default Matrix\n");
2269            return true;
2270          }
2271          //overwrite DC value when size of matrix is larger than 16x16
2272          setScalingListDC(sizeIdc,listIdc,data);
2273      }
2274    }
2275  }
2276  fclose(fp);
2277  return false;
2278}
2279
2280/** initialization process of quantization matrix array
2281 */
2282Void TComScalingList::init()
2283{
2284  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2285  {
2286    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2287    {
2288      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
2289    }
2290  }
2291  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
2292}
2293/** destroy quantization matrix array
2294 */
2295Void TComScalingList::destroy()
2296{
2297  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2298  {
2299    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2300    {
2301      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
2302    }
2303  }
2304}
2305/** get default address of quantization matrix
2306 * \param sizeId size index
2307 * \param listId list index
2308 * \returns pointer of quantization matrix
2309 */
2310Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
2311{
2312  Int *src = 0;
2313  switch(sizeId)
2314  {
2315    case SCALING_LIST_4x4:
2316      src = (listId<3) ? g_quantIntraDefault4x4 : g_quantInterDefault4x4;
2317      break;
2318    case SCALING_LIST_8x8:
2319      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2320      break;
2321    case SCALING_LIST_16x16:
2322      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2323      break;
2324    case SCALING_LIST_32x32:
2325      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2326      break;
2327    default:
2328      assert(0);
2329      src = NULL;
2330      break;
2331  }
2332  return src;
2333}
2334/** process of default matrix
2335 * \param sizeId size index
2336 * \param Index of input matrix
2337 */
2338Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId)
2339{
2340  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2341  setUseDefaultScalingMatrixFlag(sizeId,listId,true);
2342  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
2343}
2344/** check DC value of matrix for default matrix signaling
2345 */
2346Void TComScalingList::checkDcOfMatrix()
2347{
2348  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2349  {
2350    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2351    {
2352      setUseDefaultScalingMatrixFlag(sizeId,listId,false);
2353      //check default matrix?
2354      if(getScalingListDC(sizeId,listId) == 0)
2355      {
2356        processDefaultMarix(sizeId, listId);
2357      }
2358    }
2359  }
2360}
2361
2362ParameterSetManager::ParameterSetManager()
2363: m_spsMap(MAX_NUM_SPS)
2364, m_ppsMap(MAX_NUM_PPS)
2365, m_apsMap(MAX_NUM_APS)
2366#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
2367, m_vpsMap(MAX_NUM_VPS)
2368#endif
2369{
2370}
2371
2372
2373ParameterSetManager::~ParameterSetManager()
2374{
2375}
2376
2377//! \}
Note: See TracBrowser for help on using the repository browser.