source: 3DVCSoftware/branches/HTM-6.2-dev1-Sharp/source/Lib/TLibCommon/TComSlice.cpp @ 374

Last change on this file since 374 was 374, checked in by sharpjp-htm, 12 years ago

D0060: Removal of IC's parsing dependency

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