source: 3DVCSoftware/branches/HTM-6.0-Mediatek/source/Lib/TLibCommon/TComSlice.cpp @ 303

Last change on this file since 303 was 303, checked in by mediatek-htm, 11 years ago

Added FCO_FIX, FCO_FIX_SPS_CHANGE, and FCO_DVP_REFINE_C0132_C0170 macros to support FCO.
The new macros are default disabled in CTC.

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