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

Last change on this file since 423 was 408, checked in by lg, 12 years ago

D0135->D0092->D0091

  • Property svn:eol-style set to native
File size: 70.8 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#if LGE_SAO_MIGRATION_D0091
824  m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
825#else
826  m_saoInterleavingFlag = pSrc->m_saoInterleavingFlag;
827  m_saoEnabledFlagCb = pSrc->m_saoEnabledFlagCb;
828  m_saoEnabledFlagCr = pSrc->m_saoEnabledFlagCr; 
829#endif
830#if CABAC_INIT_FLAG
831  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
832#endif
833  m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
834
835  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
836#if SHARP_ILLUCOMP_PARSE_D0060
837  m_bApplyIC = pSrc->m_bApplyIC;
838  m_icSkipParseFlag = pSrc->m_icSkipParseFlag;
839#endif
840}
841
842int TComSlice::m_prevPOC = 0;
843/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
844 * \param uiTLayer Temporal layer ID of the current slice
845 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
846 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
847 * temporal_layer_switching_point_flag is set accordingly.
848 */
849Void TComSlice::setTLayerInfo( UInt uiTLayer )
850{
851
852  m_uiTLayer = uiTLayer;
853}
854
855#if H0566_TLA_SET_FOR_SWITCHING_POINTS
856/** Function for checking if this is a switching-point
857*/
858Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
859{
860  TComPic* rpcPic;
861  // loop through all pictures in the reference picture buffer
862  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
863  while ( iterPic != rcListPic.end())
864  {
865    rpcPic = *(iterPic++);
866    if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC())
867    {
868      if(rpcPic->getTLayer() >= getTLayer())
869      {
870        return false;
871      }
872    }
873  }
874  return true;
875}
876#endif
877
878/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
879*/
880Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
881{
882  TComPic* rpcPic;
883  Int i, isReference;
884
885  Int j = 0;
886  // loop through all pictures in the reference picture buffer
887  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
888  while ( iterPic != rcListPic.end())
889  {
890    j++;
891    rpcPic = *(iterPic++);
892
893    isReference = 0;
894    // loop through all pictures in the Reference Picture Set to see if the picture should be kept as reference picture
895    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
896    {
897#if QC_IV_AS_LT_B0046
898       if( rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
899#else
900      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
901#endif
902      {
903        isReference = 1;
904        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
905        rpcPic->setIsLongTerm(0);
906      }
907    }
908    // long term pictures
909    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
910    {
911#if QC_IV_AS_LT_B0046
912     if( (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
913#else
914      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()))
915#endif
916      {
917        isReference = 1;
918        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
919      }
920    }
921    // mark the picture as "unused for reference" if it is not in
922    // the Reference Picture Set
923    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
924    {           
925      rpcPic->getSlice( 0 )->setReferenced( false );   
926      rpcPic->setIsLongTerm(0);
927    }
928  } 
929}
930
931/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
932*/
933Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool outputFlag, Int pocRandomAccess)
934{
935  TComPic* rpcPic;
936  Int i, isAvailable, j;
937  Int atLeastOneLost = 0;
938  Int atLeastOneRemoved = 0;
939  Int iPocLost = 0;
940
941  // loop through all long-term pictures in the Reference Picture Set
942  // to see if the picture should be kept as reference picture
943  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
944  {
945    j = 0;
946    isAvailable = 0;
947    // loop through all pictures in the reference picture buffer
948    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
949    while ( iterPic != rcListPic.end())
950    {
951      j++;
952      rpcPic = *(iterPic++);
953      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())
954      {
955        isAvailable = 1;
956      }
957    }
958    // if there was no such long-term check the short terms
959    if(!isAvailable)
960    {
961      iterPic = rcListPic.begin();
962      while ( iterPic != rcListPic.end())
963      {
964        j++;
965        rpcPic = *(iterPic++);
966
967        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())
968        {
969          isAvailable = 1;
970          rpcPic->setIsLongTerm(1);
971          break;
972        }
973      }
974    }
975    // report that a picture is lost if it is in the Reference Picture Set
976    // but not available as reference picture
977    if(isAvailable == 0)   
978    {           
979      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
980      {
981        if(!pReferencePictureSet->getUsed(i) )
982        {
983          if(outputFlag)
984            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
985          atLeastOneRemoved = 1;
986        }
987        else
988        {
989          if(outputFlag)
990            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
991          atLeastOneLost = 1;
992          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
993        }
994      }
995    }
996  } 
997  // loop through all short-term pictures in the Reference Picture Set
998  // to see if the picture should be kept as reference picture
999  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
1000  {
1001    j = 0;
1002    isAvailable = 0;
1003    // loop through all pictures in the reference picture buffer
1004    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1005    while ( iterPic != rcListPic.end())
1006    {
1007      j++;
1008      rpcPic = *(iterPic++);
1009
1010      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1011      {
1012        isAvailable = 1;
1013      }
1014    }
1015    // report that a picture is lost if it is in the Reference Picture Set
1016    // but not available as reference picture
1017    if(isAvailable == 0)   
1018    {           
1019      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1020      {
1021        if(!pReferencePictureSet->getUsed(i) )
1022        {
1023          if(outputFlag)
1024            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1025          atLeastOneRemoved = 1;
1026        }
1027        else
1028        {
1029          if(outputFlag)
1030            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1031          atLeastOneLost = 1;
1032          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1033        }
1034      }
1035    }
1036  }   
1037  if(atLeastOneLost)
1038  {
1039    return iPocLost+1;
1040  }
1041  if(atLeastOneRemoved)
1042  {
1043    return -2;
1044  }
1045  else
1046    return 0;
1047}
1048
1049/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1050*/
1051Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
1052{
1053  TComPic* rpcPic;
1054  Int i, j;
1055  Int k = 0;
1056  Int nrOfNegativePictures = 0;
1057  Int nrOfPositivePictures = 0;
1058  TComReferencePictureSet* pcRPS = this->getLocalRPS();
1059
1060  // loop through all pictures in the Reference Picture Set
1061  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1062  {
1063    j = 0;
1064    // loop through all pictures in the reference picture buffer
1065    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1066    while ( iterPic != rcListPic.end())
1067    {
1068      j++;
1069      rpcPic = *(iterPic++);
1070
1071      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1072      {
1073        // This picture exists as a reference picture
1074        // and should be added to the explicit Reference Picture Set
1075        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1076        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
1077        if(pcRPS->getDeltaPOC(k) < 0)
1078          nrOfNegativePictures++;
1079        else
1080          nrOfPositivePictures++;
1081        k++;
1082      }
1083    }
1084  }
1085  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1086  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1087  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1088  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1089  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1090  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1091  if (!pReferencePictureSet->getInterRPSPrediction())
1092  {
1093    pcRPS->setInterRPSPrediction(false);
1094    pcRPS->setNumRefIdc(0);
1095  }
1096  else
1097  {
1098    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1099    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1100    TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1101    Int iRefPics = pcRefRPS->getNumberOfPictures();
1102    Int iNewIdc=0;
1103    for(i=0; i<= iRefPics; i++) 
1104    {
1105      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1106      Int iRefIdc = 0;
1107      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1108      {
1109        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
1110        {
1111          if (pcRPS->getUsed(j))
1112          {
1113            iRefIdc = 1;
1114          }
1115          else
1116          {
1117            iRefIdc = 2;
1118          }
1119        }
1120      }
1121      pcRPS->setRefIdc(i, iRefIdc);
1122      iNewIdc++;
1123    }
1124    pcRPS->setInterRPSPrediction(true);
1125    pcRPS->setNumRefIdc(iNewIdc);
1126    pcRPS->setDeltaRPS(deltaRPS); 
1127    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1128  }
1129
1130  this->setRPS(pcRPS);
1131  this->setRPSidx(-1);
1132}
1133
1134Void TComSlice::decodingMarkingForNoTMVP( TComList<TComPic*>& rcListPic, Int currentPOC )
1135{
1136  TComList<TComPic*>::iterator it;
1137  for ( it = rcListPic.begin(); it != rcListPic.end(); it++ )
1138  {
1139    if ( (*it)->getSlice(0)->getPOC() != currentPOC )
1140    {
1141      (*it)->setUsedForTMVP( false );
1142    }
1143  }
1144}
1145
1146/** get AC and DC values for weighted pred
1147 * \param *wp
1148 * \returns Void
1149 */
1150Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
1151{
1152  wp = m_weightACDCParam;
1153}
1154
1155/** init AC and DC values for weighted pred
1156 * \returns Void
1157 */
1158Void  TComSlice::initWpAcDcParam()
1159{
1160  for(Int iComp = 0; iComp < 3; iComp++ )
1161  {
1162    m_weightACDCParam[iComp].iAC = 0;
1163    m_weightACDCParam[iComp].iDC = 0;
1164  }
1165}
1166
1167/** get WP tables for weighted pred
1168 * \param RefPicList
1169 * \param iRefIdx
1170 * \param *&wpScalingParam
1171 * \returns Void
1172 */
1173Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
1174{
1175  wp = m_weightPredTable[e][iRefIdx];
1176}
1177
1178/** reset Default WP tables settings : no weight.
1179 * \param wpScalingParam
1180 * \returns Void
1181 */
1182Void  TComSlice::resetWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
1183{
1184  for ( int e=0 ; e<2 ; e++ ) 
1185  {
1186    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1187    {
1188      for ( int yuv=0 ; yuv<3 ; yuv++ ) 
1189      {
1190        wpScalingParam  *pwp = &(wp[e][i][yuv]);
1191        pwp->bPresentFlag      = false;
1192        pwp->uiLog2WeightDenom = 0;
1193        pwp->uiLog2WeightDenom = 0;
1194        pwp->iWeight           = 1;
1195        pwp->iOffset           = 0;
1196      }
1197    }
1198  }
1199}
1200
1201/** init WP table
1202 * \returns Void
1203 */
1204Void  TComSlice::initWpScaling()
1205{
1206  initWpScaling(m_weightPredTable);
1207}
1208
1209/** set WP tables
1210 * \param wpScalingParam
1211 * \returns Void
1212 */
1213Void  TComSlice::initWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
1214{
1215  for ( int e=0 ; e<2 ; e++ ) 
1216  {
1217    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1218    {
1219      for ( int yuv=0 ; yuv<3 ; yuv++ ) 
1220      {
1221        wpScalingParam  *pwp = &(wp[e][i][yuv]);
1222        if ( !pwp->bPresentFlag ) {
1223          // Inferring values not present :
1224          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1225          pwp->iOffset = 0;
1226        }
1227
1228        pwp->w      = pwp->iWeight;
1229        pwp->o      = pwp->iOffset * (1 << (g_uiBitDepth-8));
1230        pwp->shift  = pwp->uiLog2WeightDenom;
1231        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1232      }
1233    }
1234  }
1235}
1236
1237/** get WP tables for weighted pred of LC
1238 * \param iRefIdxLC
1239 * \param *&wpScalingParam
1240 * \returns Void
1241 */
1242Void TComSlice::getWpScalingLC( Int iRefIdx, wpScalingParam *&wp )
1243{
1244  wp = m_weightPredTableLC[iRefIdx];
1245}
1246/** reset Default WP tables settings for LC : no weight.
1247 * \param wpScalingParam
1248 * \returns Void
1249 */
1250Void TComSlice::resetWpScalingLC(wpScalingParam  wp[2*MAX_NUM_REF][3])
1251{
1252  for ( int i=0 ; i<2*MAX_NUM_REF ; i++ )
1253  {
1254    for ( int yuv=0 ; yuv<3 ; yuv++ ) 
1255    {
1256      wpScalingParam  *pwp = &(wp[i][yuv]);
1257      pwp->bPresentFlag      = false;
1258      pwp->uiLog2WeightDenom = 0;
1259      pwp->uiLog2WeightDenom = 0;
1260      pwp->iWeight           = 1;
1261      pwp->iOffset           = 0;
1262    }
1263  }
1264}
1265/** set current WP tables settings for LC
1266 * \returns Void
1267 */
1268Void TComSlice::setWpParamforLC()
1269{
1270  for ( Int iRefIdx=0 ; iRefIdx<getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ )
1271  {
1272    RefPicList eRefPicList = (RefPicList)getListIdFromIdxOfLC(iRefIdx);
1273    Int iCombRefIdx = getRefIdxFromIdxOfLC(iRefIdx);
1274
1275    wpScalingParam  *wp_src, *wp_dst;
1276    getWpScalingLC(iRefIdx, wp_src);
1277    getWpScaling(eRefPicList, iCombRefIdx, wp_dst);
1278    copyWPtable(wp_src, wp_dst);
1279
1280    if(eRefPicList == REF_PIC_LIST_0)
1281    {
1282      Int iRefIdxL1 = getRefIdxOfL1FromRefIdxOfL0(iCombRefIdx);
1283      if(iRefIdxL1 >= 0)
1284      {
1285        getWpScaling(REF_PIC_LIST_1, iRefIdxL1, wp_dst);
1286        copyWPtable(wp_src, wp_dst);
1287      }
1288    }
1289    if(eRefPicList == REF_PIC_LIST_1)
1290    {
1291      Int iRefIdxL0 = getRefIdxOfL0FromRefIdxOfL1(iCombRefIdx);
1292      if(iRefIdxL0 >= 0)
1293      {
1294        getWpScaling(REF_PIC_LIST_0, iRefIdxL0, wp_dst);
1295        copyWPtable(wp_src, wp_dst);
1296      }
1297    }
1298  }
1299  initWpScaling();
1300}
1301/** copy source WP tables to destination table for LC
1302 * \param wpScalingParam *&wp_src : source
1303 * \param wpScalingParam *&wp_dst : destination
1304 * \returns Void
1305 */
1306Void TComSlice::copyWPtable(wpScalingParam *&wp_src, wpScalingParam *&wp_dst)
1307{
1308  for ( Int iComp = 0; iComp < 3; iComp++ )
1309  {
1310    wp_dst[iComp].uiLog2WeightDenom = (iComp==0) ? wp_src[0].uiLog2WeightDenom : wp_src[1].uiLog2WeightDenom;
1311    wp_dst[iComp].bPresentFlag = wp_src[iComp].bPresentFlag;
1312    wp_dst[iComp].iWeight = wp_src[iComp].iWeight;
1313    wp_dst[iComp].iOffset = wp_src[iComp].iOffset;
1314  }
1315}
1316
1317#if LGE_ILLUCOMP_B0045
1318Void TComSlice::xSetApplyIC()
1319{
1320  Int iMaxPelValue = (1<<g_uiBitDepth); 
1321  Int *aiRefOrgHist;
1322  Int *aiCurrHist;
1323  aiRefOrgHist = new Int;
1324  aiCurrHist   = new Int;
1325  aiRefOrgHist = (Int *)xMalloc(Int,iMaxPelValue);
1326  aiCurrHist   = (Int *)xMalloc(Int,iMaxPelValue);
1327  memset(aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) );
1328  memset(aiCurrHist, 0, iMaxPelValue*sizeof(Int) );
1329  // Reference Idx Number
1330  Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 );
1331  TComPic* pcCurrPic = NULL;
1332  TComPic* pcRefPic = NULL;
1333  TComPicYuv* pcCurrPicYuv = NULL;
1334  TComPicYuv* pcRefPicYuvOrg = NULL;
1335  pcCurrPic = getPic();
1336  pcCurrPicYuv = pcCurrPic->getPicYuvOrg();
1337  Int iWidth = pcCurrPicYuv->getWidth();
1338  Int iHeight = pcCurrPicYuv->getHeight();
1339
1340
1341  // Get InterView Reference picture
1342  // !!!!! Assume only one Interview Reference Picture in L0
1343  for (Int i = 0; i < iNumRefIdx; i++)
1344  {
1345    pcRefPic = getRefPic( REF_PIC_LIST_0, i);
1346    if (pcRefPic != NULL)
1347    {
1348      // Current Picture
1349      if (pcCurrPic->getViewId() != pcRefPic->getViewId())
1350      {
1351        pcRefPicYuvOrg = pcRefPic->getPicYuvOrg();
1352      }
1353    }
1354  }
1355  if (pcRefPicYuvOrg != NULL)
1356  {
1357    Pel* pCurrY = pcCurrPicYuv ->getLumaAddr();
1358    Pel* pRefOrgY = pcRefPicYuvOrg  ->getLumaAddr();
1359    Int iCurrStride = pcCurrPicYuv->getStride();
1360    Int iRefStride = pcRefPicYuvOrg->getStride();
1361    Int iSumOrgSAD = 0;
1362#if LGE_ILLUCOMP_DEPTH_C0046
1363    Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05;
1364#else
1365    double dThresholdOrgSAD = 0.05;
1366#endif
1367    // Histogram building - luminance
1368    for ( Int y = 0; y < iHeight; y++)
1369    {
1370      for ( Int x = 0; x < iWidth; x++)
1371      {
1372        aiCurrHist[pCurrY[x]]++;
1373        aiRefOrgHist[pRefOrgY[x]]++;
1374      }
1375      pCurrY += iCurrStride;
1376      pRefOrgY += iRefStride;
1377    }
1378    // Calc SAD
1379    for (Int i = 0; i < iMaxPelValue; i++)
1380    {
1381      iSumOrgSAD += abs(aiCurrHist[i] - aiRefOrgHist[i]);
1382    }
1383    // Setting
1384    if ( iSumOrgSAD > Int(dThresholdOrgSAD * iWidth * iHeight) )
1385    {
1386      m_bApplyIC = true;
1387    }
1388    else
1389    {
1390      m_bApplyIC = false;
1391    }
1392  }
1393  xFree(aiCurrHist);
1394  xFree(aiRefOrgHist);
1395  aiCurrHist = NULL;
1396  aiRefOrgHist = NULL;
1397}
1398#endif
1399
1400// ------------------------------------------------------------------------------------------------
1401// Video parameter set (VPS)
1402// ------------------------------------------------------------------------------------------------
1403#if QC_MVHEVC_B0046
1404TComVPS::TComVPS()
1405: m_VPSId                     (  0)
1406, m_uiMaxTLayers              (  1)
1407, m_uiMaxLayers               (  1)
1408, m_bTemporalIdNestingFlag    (false)
1409, m_uiNumHRDParameter         (  0)
1410, m_numAddiLayerOperationPoints (2)
1411, m_numAddiProLevelSets       (  1)
1412{
1413  for( Int i = 0; i < MAX_LAYER_NUM; i++)
1414  {
1415  m_numOpLayerIdMinus1[i] = 0;
1416  if(i)
1417      m_numDirectRefLayer[i] = 1;
1418  else
1419    m_numDirectRefLayer[i] = 0;
1420  for( Int j = 0; j < MAX_LAYER_NUM; j++)
1421  {
1422    m_numDirectRefID[i][j] = 0;
1423    m_numOpLayerId[i][j]   = 0;
1424  }
1425    m_uiViewId[i] = 0;
1426    m_iViewOrderIdx[i] = 0;
1427  }
1428 
1429  for( Int i = 0; i < MAX_TLAYER; i++)
1430  {
1431    m_numReorderPics[i] = 0;
1432    m_uiMaxDecPicBuffering[i] = 0; 
1433    m_uiMaxLatencyIncrease[i] = 0;
1434  }
1435}
1436
1437TComVPS::~TComVPS()
1438{
1439}
1440#else
1441#if VIDYO_VPS_INTEGRATION
1442TComVPS::TComVPS()
1443: m_VPSId                     (  0)
1444, m_uiMaxTLayers              (  1)
1445, m_uiMaxLayers               (  1)
1446, m_bTemporalIdNestingFlag    (false)
1447, m_uiExtensionType           (  0)
1448{
1449  for( Int i = 0; i < MAX_LAYER_NUM; i++)
1450  {
1451    m_uiDependentLayer[i] = i? i-1: 0;
1452    m_bDependentFlag[i] = false;
1453    m_uiViewId[i] = 0;
1454    m_bDepthFlag[i] = 0;
1455    m_iViewOrderIdx[i] = 0;
1456  }
1457 
1458  for( Int i = 0; i < MAX_TLAYER; i++)
1459  {
1460    m_numReorderPics[i] = 0;
1461    m_uiMaxDecPicBuffering[i] = 0; 
1462    m_uiMaxLatencyIncrease[i] = 0;
1463  }
1464}
1465
1466TComVPS::~TComVPS()
1467{
1468 
1469 
1470}
1471
1472#endif
1473#endif
1474
1475// ------------------------------------------------------------------------------------------------
1476// Sequence parameter set (SPS)
1477// ------------------------------------------------------------------------------------------------
1478
1479TComSPS::TComSPS()
1480#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
1481: m_VPSId                     (  0)
1482, m_SPSId                     (  0)
1483#else
1484: m_SPSId                     (  0)
1485#endif
1486, m_ProfileIdc                (  0)
1487, m_LevelIdc                  (  0)
1488, m_chromaFormatIdc           (CHROMA_420)
1489, m_uiMaxTLayers              (  1)
1490// Structure
1491, m_picWidthInLumaSamples     (352)
1492, m_picHeightInLumaSamples    (288)
1493, m_picCroppingFlag           (false)
1494, m_picCropLeftOffset         (  0)
1495, m_picCropRightOffset        (  0)
1496, m_picCropTopOffset          (  0)
1497, m_picCropBottomOffset       (  0) 
1498, m_uiMaxCUWidth              ( 32)
1499, m_uiMaxCUHeight             ( 32)
1500, m_uiMaxCUDepth              (  3)
1501, m_uiMinTrDepth              (  0)
1502, m_uiMaxTrDepth              (  1)
1503, m_bLongTermRefsPresent      (false)
1504, m_iNumberOfUsableInterViewRefs( 0 )
1505, m_uiQuadtreeTULog2MaxSize   (  0)
1506, m_uiQuadtreeTULog2MinSize   (  0)
1507, m_uiQuadtreeTUMaxDepthInter (  0)
1508, m_uiQuadtreeTUMaxDepthIntra (  0)
1509// Tool list
1510, m_usePCM                   (false)
1511, m_pcmLog2MaxSize            (  5)
1512, m_uiPCMLog2MinSize          (  7)
1513, m_bDisInter4x4              (  1)
1514, m_bUseALF                   (false)
1515, m_bALFCoefInSlice           (false)
1516, m_bUseLMChroma              (false)
1517, m_bUseLComb                 (false)
1518, m_bLCMod                    (false)
1519#if QC_MVHEVC_B0046
1520, m_restrictedRefPicListsFlag   (  0)
1521#else
1522, m_restrictedRefPicListsFlag   (  1)
1523#endif
1524, m_listsModificationPresentFlag(  0)
1525, m_uiBitDepth                (  8)
1526, m_uiBitIncrement            (  0)
1527, m_qpBDOffsetY               (  0)
1528, m_qpBDOffsetC               (  0)
1529#if LOSSLESS_CODING
1530, m_useLossless               (false)
1531#endif
1532, m_uiPCMBitDepthLuma         (  8)
1533, m_uiPCMBitDepthChroma       (  8)
1534, m_bPCMFilterDisableFlag     (false)
1535, m_uiBitsForPOC              (  8)
1536, m_uiMaxTrSize               ( 32)
1537, m_bLFCrossSliceBoundaryFlag (false)
1538, m_bUseSAO                   (false) 
1539#if HHI_MPI
1540, m_bUseMVI                   (false)
1541#endif
1542, m_bLFCrossTileBoundaryFlag  (false) 
1543, m_iUniformSpacingIdr        (  0 )
1544, m_iTileBoundaryIndependenceIdr (  0 )
1545, m_iNumColumnsMinus1         (  0 )
1546, m_puiColumnWidth            ( NULL )
1547, m_iNumRowsMinus1            (  0 )
1548, m_puiRowHeight              ( NULL )
1549, m_bTemporalIdNestingFlag    (false)
1550, m_scalingListEnabledFlag    (false)
1551,  m_tilesOrEntropyCodingSyncIdc( 0 )
1552,  m_numSubstreams              ( 0 )
1553#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1554, m_bUseDMM                   (false)
1555#endif
1556#if FLEX_CODING_ORDER_M23723 && HHI_DMM_PRED_TEX
1557, m_bUseDMM34                   (false)
1558#endif
1559#if H3D_QTL
1560, m_bUseQTLPC                 (false)
1561#endif
1562{
1563  // AMVP parameter
1564  ::memset( m_aeAMVPMode, 0, sizeof( m_aeAMVPMode ) );
1565  for ( Int i = 0; i < MAX_TLAYER; i++ )
1566  {
1567    m_uiMaxLatencyIncrease[i] = 0;
1568    m_uiMaxDecPicBuffering[i] = 0;
1569    m_numReorderPics[i]       = 0;
1570  }
1571
1572  m_uiViewId              = 0;
1573  m_iViewOrderIdx         = 0;
1574  m_bDepth                = false;
1575  m_uiCamParPrecision     = 0;
1576  m_bCamParInSliceHeader  = false;
1577  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
1578  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
1579
1580#if DEPTH_MAP_GENERATION
1581  m_uiPredDepthMapGeneration = 0;
1582  m_uiPdmPrecision           = 0;
1583  ::memset( m_aiPdmScaleNomDelta, 0x00, sizeof( m_aiPdmScaleNomDelta  ) );
1584  ::memset( m_aiPdmOffset,        0x00, sizeof( m_aiPdmOffset         ) );
1585#endif
1586#if H3D_IVMP
1587  m_uiMultiviewMvPredMode    = 0;
1588#endif
1589
1590  ::memset( m_aiUsableInterViewRefs, 0, sizeof( m_aiUsableInterViewRefs ) );
1591 
1592#if RWTH_SDC_DLT_B0036
1593  m_bUseDLT = false;
1594 
1595  m_uiBitsPerDepthValue = g_uiBitDepth;
1596  m_uiNumDepthmapValues = 0;
1597  m_uiDepthValue2Idx    = NULL;
1598  m_uiIdx2DepthValue    = NULL;
1599#endif
1600}
1601
1602TComSPS::~TComSPS()
1603{
1604  if( m_iNumColumnsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1605  {
1606    delete [] m_puiColumnWidth; 
1607    m_puiColumnWidth = NULL;
1608  }
1609  if( m_iNumRowsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1610  {
1611    delete [] m_puiRowHeight;
1612    m_puiRowHeight = NULL;
1613  }
1614}
1615
1616#if RWTH_SDC_DLT_B0036
1617Void TComSPS::setDepthLUTs(UInt* uidx2DepthValue, UInt uiNumDepthValues)
1618{
1619  UInt uiMaxDepthValue = g_uiIBDI_MAX;
1620 
1621  // allocate some memory
1622  if( m_uiNumDepthmapValues == 0 )
1623  {
1624    m_uiNumDepthmapValues = uiMaxDepthValue+1;
1625    m_uiBitsPerDepthValue = (UInt)ceil(Log2(m_uiNumDepthmapValues));
1626   
1627    m_uiDepthValue2Idx    = (UInt*) xMalloc(UInt, m_uiNumDepthmapValues);
1628    m_uiIdx2DepthValue    = (UInt*) xMalloc(UInt, m_uiNumDepthmapValues);
1629   
1630    //default mapping
1631    for (Int i=0; i<m_uiNumDepthmapValues; i++)
1632    {
1633      m_uiDepthValue2Idx[i] = i;
1634      m_uiIdx2DepthValue[i] = i;
1635    }
1636  }
1637 
1638  if( uidx2DepthValue == NULL || uiNumDepthValues == 0 ) // default mapping only
1639    return;
1640 
1641  // copy idx2DepthValue to internal array
1642  memcpy(m_uiIdx2DepthValue, uidx2DepthValue, uiNumDepthValues*sizeof(UInt));
1643 
1644  for(Int p=0; p<=uiMaxDepthValue; p++)
1645  {
1646    Int iIdxDown    = 0;
1647    Int iIdxUp      = uiNumDepthValues-1;
1648    Bool bFound     = false;
1649   
1650    // iterate over indices to find lower closest depth
1651    Int i = 1;
1652    while(!bFound && i<uiNumDepthValues)
1653    {
1654      if( m_uiIdx2DepthValue[i] > p )
1655      {
1656        iIdxDown  = i-1;
1657        bFound    = true;
1658      }
1659     
1660      i++;
1661    }
1662    // iterate over indices to find upper closest depth
1663    i = uiNumDepthValues-2;
1664    bFound = false;
1665    while(!bFound && i>=0)
1666    {
1667      if( m_uiIdx2DepthValue[i] < p )
1668      {
1669        iIdxUp  = i+1;
1670        bFound    = true;
1671      }
1672     
1673      i--;
1674    }
1675   
1676    // assert monotony
1677    assert(iIdxDown<=iIdxUp);
1678   
1679    // assign closer depth value/idx
1680    if( abs(p-(Int)m_uiIdx2DepthValue[iIdxDown]) < abs(p-(Int)m_uiIdx2DepthValue[iIdxUp]) )
1681    {
1682      m_uiDepthValue2Idx[p] = iIdxDown;
1683    }
1684    else
1685    {
1686      m_uiDepthValue2Idx[p] = iIdxUp;
1687    }
1688   
1689  }
1690 
1691  // update globals
1692  m_uiNumDepthmapValues = uiNumDepthValues;
1693  m_uiBitsPerDepthValue = (UInt)ceil(Log2(m_uiNumDepthmapValues));
1694}
1695#endif
1696
1697TComPPS::TComPPS()
1698: m_PPSId                       (0)
1699, m_SPSId                       (0)
1700, m_picInitQPMinus26            (0)
1701, m_useDQP                      (false)
1702, m_bConstrainedIntraPred       (false)
1703, m_pcSPS                       (NULL)
1704, m_uiMaxCuDQPDepth             (0)
1705, m_uiMinCuDQPSize              (0)
1706, m_iChromaQpOffset             (0)
1707, m_iChromaQpOffset2nd          (0)
1708, m_iSliceGranularity           (0)
1709, m_iTileBehaviorControlPresentFlag (0)
1710, m_bLFCrossTileBoundaryFlag     (true)
1711, m_iColumnRowInfoPresent        (0)
1712, m_iUniformSpacingIdr           (0)
1713, m_iNumColumnsMinus1            (0)
1714, m_puiColumnWidth               (NULL)
1715, m_iNumRowsMinus1               (0)
1716, m_puiRowHeight                 (NULL)
1717,  m_iNumSubstreams             (1)
1718, m_signHideFlag(0)
1719, m_signHidingThreshold(0)
1720#if CABAC_INIT_FLAG
1721, m_cabacInitPresentFlag        (false)
1722, m_encCABACTableIdx            (0)
1723#if FIX_POZNAN_CABAC_INIT_FLAG
1724, m_encPrevPOC            (0)
1725#endif
1726#endif
1727{
1728}
1729
1730TComPPS::~TComPPS()
1731{
1732  if( m_iNumColumnsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1733  {
1734    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
1735    m_puiColumnWidth = NULL;
1736  }
1737  if( m_iNumRowsMinus1 > 0 && m_iUniformSpacingIdr == 0 )
1738  {
1739    if (m_puiRowHeight) delete [] m_puiRowHeight;
1740    m_puiRowHeight = NULL;
1741  }
1742}
1743
1744Void
1745TComSPS::initMultiviewSPS( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
1746{
1747#if !QC_MVHEVC_B0046
1748  AOT( uiViewId == 0 && iViewOrderIdx != 0 );
1749  AOT( uiViewId != 0 && iViewOrderIdx == 0 );
1750  AOT( uiViewId != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) );
1751#endif
1752  m_uiViewId              = uiViewId;
1753  m_iViewOrderIdx         = iViewOrderIdx;
1754  m_bDepth                = false;
1755  m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
1756  m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
1757  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
1758  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
1759#if !QC_MVHEVC_B0046
1760  if( !m_bCamParInSliceHeader )
1761  {
1762    for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
1763    {
1764      m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
1765      m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
1766      m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
1767      m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
1768    }
1769  }
1770#endif
1771}
1772
1773Void
1774#if FCO_FIX_SPS_CHANGE
1775TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
1776#else
1777TComSPS::initMultiviewSPSDepth( UInt uiViewId, Int iViewOrderIdx )
1778#endif
1779{
1780  AOT( uiViewId == 0 && iViewOrderIdx != 0 );
1781  AOT( uiViewId != 0 && iViewOrderIdx == 0 );
1782
1783  m_uiViewId              = uiViewId;
1784  m_iViewOrderIdx         = iViewOrderIdx;
1785  m_bDepth                = true;
1786#if FCO_FIX_SPS_CHANGE
1787  m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
1788  m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
1789#else
1790  m_uiCamParPrecision     = 0;
1791  m_bCamParInSliceHeader  = false;
1792#endif
1793  ::memset( m_aaiCodedScale,  0x00, sizeof( m_aaiCodedScale  ) );
1794  ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
1795#if FCO_FIX_SPS_CHANGE
1796#if !QC_MVHEVC_B0046
1797  if( !m_bCamParInSliceHeader )
1798  {
1799    for( UInt uiBaseViewId = 0; uiBaseViewId < m_uiViewId; uiBaseViewId++ )
1800    {
1801      m_aaiCodedScale [ 0 ][ uiBaseViewId ] = aaiScale [ uiBaseViewId ][   m_uiViewId ];
1802      m_aaiCodedScale [ 1 ][ uiBaseViewId ] = aaiScale [   m_uiViewId ][ uiBaseViewId ];
1803      m_aaiCodedOffset[ 0 ][ uiBaseViewId ] = aaiOffset[ uiBaseViewId ][   m_uiViewId ];
1804      m_aaiCodedOffset[ 1 ][ uiBaseViewId ] = aaiOffset[   m_uiViewId ][ uiBaseViewId ];
1805    }
1806  }
1807#endif
1808#endif
1809
1810}
1811
1812#if DEPTH_MAP_GENERATION
1813Void
1814TComSPS::setPredDepthMapGeneration( UInt uiViewId, Bool bIsDepth, UInt uiPdmGenMode, UInt uiPdmMvPredMode, UInt uiPdmPrec, Int** aaiPdmScaleNomDelta, Int** aaiPdmOffset )
1815{ 
1816  AOF( m_uiViewId == uiViewId );
1817  AOF( m_bDepth   == bIsDepth );
1818  AOT( ( uiViewId == 0 || bIsDepth ) && uiPdmGenMode );
1819  AOT( uiPdmGenMode && ( aaiPdmScaleNomDelta == 0 || aaiPdmOffset == 0 ) );
1820  AOT( uiPdmMvPredMode && uiPdmGenMode == 0 );
1821
1822  m_uiPredDepthMapGeneration = uiPdmGenMode;
1823#if H3D_IVMP
1824  m_uiMultiviewMvPredMode    = uiPdmMvPredMode;
1825#endif
1826
1827  m_uiPdmPrecision           = ( m_uiPredDepthMapGeneration ? uiPdmPrec : 0 );
1828  ::memset( m_aiPdmScaleNomDelta, 0x00, sizeof( m_aiPdmScaleNomDelta  ) );
1829  ::memset( m_aiPdmOffset,        0x00, sizeof( m_aiPdmOffset         ) );
1830  if( m_uiPredDepthMapGeneration )
1831  {
1832    for( UInt uiBaseId = 0; uiBaseId < m_uiViewId; uiBaseId++ )
1833    {
1834      m_aiPdmScaleNomDelta[ uiBaseId ]  = aaiPdmScaleNomDelta[ m_uiViewId ][ uiBaseId ];
1835      m_aiPdmOffset       [ uiBaseId ]  = aaiPdmOffset       [ m_uiViewId ][ uiBaseId ];
1836    }
1837  }
1838}
1839#endif
1840
1841TComReferencePictureSet::TComReferencePictureSet()
1842: m_numberOfPictures (0)
1843, m_numberOfNegativePictures (0)
1844, m_numberOfPositivePictures (0)
1845, m_numberOfLongtermPictures (0)
1846, m_interRPSPrediction (0) 
1847, m_deltaRIdxMinus1 (0)   
1848, m_deltaRPS (0) 
1849, m_numRefIdc (0) 
1850{
1851  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
1852  ::memset( m_POC, 0, sizeof(m_POC) );
1853  ::memset( m_used, 0, sizeof(m_used) );
1854  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
1855}
1856
1857TComReferencePictureSet::~TComReferencePictureSet()
1858{
1859}
1860
1861Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
1862{
1863  m_used[bufferNum] = used;
1864}
1865
1866Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
1867{
1868  m_deltaPOC[bufferNum] = deltaPOC;
1869}
1870
1871Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
1872{
1873  m_numberOfPictures = numberOfPictures;
1874}
1875
1876Int TComReferencePictureSet::getUsed(Int bufferNum)
1877{
1878  return m_used[bufferNum];
1879}
1880
1881Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
1882{
1883  return m_deltaPOC[bufferNum];
1884}
1885
1886Int TComReferencePictureSet::getNumberOfPictures()
1887{
1888  return m_numberOfPictures;
1889}
1890
1891Int TComReferencePictureSet::getPOC(Int bufferNum)
1892{
1893  return m_POC[bufferNum];
1894}
1895Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
1896{
1897  m_POC[bufferNum] = POC;
1898}
1899
1900/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
1901 * \param uiBufferNum
1902 * \param iRefIdc
1903 * \returns Void
1904 */
1905Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
1906{
1907  m_refIdc[bufferNum] = refIdc;
1908}
1909
1910/** get the reference idc value at uiBufferNum
1911 * \param uiBufferNum
1912 * \returns Int
1913 */
1914Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
1915{
1916  return m_refIdc[bufferNum];
1917}
1918
1919/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
1920 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
1921 *  +ve values are in increasing order.
1922 * \returns Void
1923 */
1924Void TComReferencePictureSet::sortDeltaPOC()
1925{
1926  // sort in increasing order (smallest first)
1927  for(Int j=1; j < getNumberOfPictures(); j++)
1928  { 
1929    Int deltaPOC = getDeltaPOC(j);
1930    Bool used = getUsed(j);
1931    for (Int k=j-1; k >= 0; k--)
1932    {
1933      Int temp = getDeltaPOC(k);
1934      if (deltaPOC < temp)
1935      {
1936        setDeltaPOC(k+1, temp);
1937        setUsed(k+1, getUsed(k));
1938        setDeltaPOC(k, deltaPOC);
1939        setUsed(k, used);
1940      }
1941    }
1942  }
1943  // flip the negative values to largest first
1944  Int numNegPics = getNumberOfNegativePictures();
1945  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
1946  { 
1947    Int deltaPOC = getDeltaPOC(j);
1948    Bool used = getUsed(j);
1949    setDeltaPOC(j, getDeltaPOC(k));
1950    setUsed(j, getUsed(k));
1951    setDeltaPOC(k, deltaPOC);
1952    setUsed(k, used);
1953  }
1954}
1955
1956/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
1957 *  A "*" is added to the deltaPOC value if it is Used bu current.
1958 * \returns Void
1959 */
1960Void TComReferencePictureSet::printDeltaPOC()
1961{
1962  printf("DeltaPOC = { ");
1963  for(Int j=0; j < getNumberOfPictures(); j++)
1964  {
1965    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
1966  } 
1967  if (getInterRPSPrediction()) 
1968  {
1969    printf("}, RefIdc = { ");
1970    for(Int j=0; j < getNumRefIdc(); j++)
1971    {
1972      printf("%d ", getRefIdc(j));
1973    } 
1974  }
1975  printf("}\n");
1976}
1977
1978TComRPSList::TComRPSList()
1979{
1980}
1981
1982TComRPSList::~TComRPSList()
1983{
1984}
1985
1986Void TComRPSList::create( Int numberOfReferencePictureSets)
1987{
1988  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
1989  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
1990}
1991
1992Void TComRPSList::destroy()
1993{
1994  delete [] m_referencePictureSets;
1995  m_numberOfReferencePictureSets = 0;
1996  m_referencePictureSets = NULL;
1997}
1998
1999
2000
2001TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
2002{
2003  return &m_referencePictureSets[referencePictureSetNum];
2004}
2005
2006Int TComRPSList::getNumberOfReferencePictureSets()
2007{
2008  return m_numberOfReferencePictureSets;
2009}
2010
2011Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
2012{
2013  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2014}
2015
2016TComRefPicListModification::TComRefPicListModification()
2017: m_bRefPicListModificationFlagL0 (false)
2018, m_bRefPicListModificationFlagL1 (false)
2019{
2020  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
2021  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
2022}
2023
2024TComRefPicListModification::~TComRefPicListModification()
2025{
2026}
2027
2028TComAPS::TComAPS()
2029{
2030  m_apsID = 0;
2031  m_bAlfEnabled = false;
2032  m_bSaoEnabled = false;
2033  m_pSaoParam = NULL;
2034  m_alfParamSet = NULL;
2035  m_scalingList = NULL;
2036  m_scalingListEnabled = false;
2037}
2038
2039TComAPS::~TComAPS()
2040{
2041
2042}
2043
2044TComAPS& TComAPS::operator= (const TComAPS& src)
2045{
2046  m_apsID       = src.m_apsID;
2047  m_loopFilterOffsetInAPS = src.m_loopFilterOffsetInAPS;
2048  m_loopFilterDisable = src.m_loopFilterDisable;
2049  m_loopFilterBetaOffsetDiv2 = src.m_loopFilterBetaOffsetDiv2;
2050  m_loopFilterTcOffsetDiv2 = src.m_loopFilterTcOffsetDiv2;
2051  m_bAlfEnabled = src.m_bAlfEnabled;
2052  m_bSaoEnabled = src.m_bSaoEnabled;
2053  m_pSaoParam   = src.m_pSaoParam; 
2054  m_alfParamSet    = src.m_alfParamSet;
2055  m_scalingList = src.m_scalingList;
2056  m_scalingListEnabled = src.m_scalingListEnabled;
2057#if !LGE_SAO_MIGRATION_D0091
2058  m_saoInterleavingFlag = src.m_saoInterleavingFlag;
2059#endif
2060
2061  return *this;
2062}
2063
2064Void TComAPS::createSaoParam()
2065{
2066  m_pSaoParam = new SAOParam;
2067}
2068
2069Void TComAPS::destroySaoParam()
2070{
2071  if(m_pSaoParam != NULL)
2072  {
2073    delete m_pSaoParam;
2074    m_pSaoParam = NULL;
2075  }
2076}
2077
2078Void TComAPS::createAlfParam()
2079{
2080  m_alfParamSet = new AlfParamSet;
2081}
2082Void TComAPS::destroyAlfParam()
2083{
2084  if(m_alfParamSet != NULL)
2085  {
2086    delete m_alfParamSet;
2087    m_alfParamSet = NULL;
2088  }
2089}
2090
2091Void TComAPS::createScalingList()
2092{
2093  m_scalingList = new TComScalingList;
2094}
2095Void TComAPS::destroyScalingList()
2096{
2097  delete m_scalingList;
2098}
2099
2100TComScalingList::TComScalingList()
2101{
2102  init();
2103}
2104TComScalingList::~TComScalingList()
2105{
2106  destroy();
2107}
2108
2109/** set default quantization matrix to array
2110*/
2111Void TComSlice::setDefaultScalingList()
2112{
2113  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2114  {
2115    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2116    {
2117      getScalingList()->processDefaultMarix(sizeId, listId);
2118    }
2119  }
2120}
2121/** check if use default quantization matrix
2122 * \returns true if use default quantization matrix in all size
2123*/
2124Bool TComSlice::checkDefaultScalingList()
2125{
2126  UInt defaultCounter=0;
2127
2128  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2129  {
2130    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2131    {
2132      if(getScalingList()->getUseDefaultScalingMatrixFlag(sizeId,listId))
2133      {
2134        defaultCounter++;
2135      }
2136    }
2137  }
2138  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? true : false; // -4 for 32x32
2139}
2140/** get scaling matrix from RefMatrixID
2141 * \param sizeId size index
2142 * \param Index of input matrix
2143 * \param Index of reference matrix
2144 */
2145Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
2146{
2147  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListAddress(sizeId, refListId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2148}
2149/** parse syntax infomation
2150 *  \param pchFile syntax infomation
2151 *  \returns false if successful
2152 */
2153Bool TComScalingList::xParseScalingList(char* pchFile)
2154{
2155  FILE *fp;
2156  Char line[1024];
2157  UInt sizeIdc,listIdc;
2158  UInt i,size = 0;
2159  Int *src=0,data;
2160  Char *ret;
2161  UInt  retval;
2162
2163  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
2164  {
2165    printf("can't open file %s :: set Default Matrix\n",pchFile);
2166    return true;
2167  }
2168
2169  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
2170  {
2171    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
2172    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
2173    {
2174      src = getScalingListAddress(sizeIdc, listIdc);
2175
2176      fseek(fp,0,0);
2177      do 
2178      {
2179        ret = fgets(line, 1024, fp);
2180        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
2181        {
2182          printf("Error: can't read Matrix :: set Default Matrix\n");
2183          return true;
2184        }
2185      }
2186      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
2187      for (i=0; i<size; i++)
2188      {
2189        retval = fscanf(fp, "%d,", &data);
2190        if (retval!=1)
2191        {
2192          printf("Error: can't read Matrix :: set Default Matrix\n");
2193          return true;
2194        }
2195        src[i] = data;
2196      }
2197      //set DC value for default matrix check
2198      setScalingListDC(sizeIdc,listIdc,src[0]);
2199
2200      if(sizeIdc > SCALING_LIST_8x8)
2201      {
2202        fseek(fp,0,0);
2203        do 
2204        {
2205          ret = fgets(line, 1024, fp);
2206          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
2207          {
2208            printf("Error: can't read DC :: set Default Matrix\n");
2209            return true;
2210          }
2211        }
2212        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
2213          retval = fscanf(fp, "%d,", &data);
2214          if (retval!=1)
2215          {
2216            printf("Error: can't read Matrix :: set Default Matrix\n");
2217            return true;
2218          }
2219          //overwrite DC value when size of matrix is larger than 16x16
2220          setScalingListDC(sizeIdc,listIdc,data);
2221      }
2222    }
2223  }
2224  fclose(fp);
2225  return false;
2226}
2227
2228/** initialization process of quantization matrix array
2229 */
2230Void TComScalingList::init()
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      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
2237    }
2238  }
2239  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
2240}
2241/** destroy quantization matrix array
2242 */
2243Void TComScalingList::destroy()
2244{
2245  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2246  {
2247    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2248    {
2249      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
2250    }
2251  }
2252}
2253/** get default address of quantization matrix
2254 * \param sizeId size index
2255 * \param listId list index
2256 * \returns pointer of quantization matrix
2257 */
2258Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
2259{
2260  Int *src = 0;
2261  switch(sizeId)
2262  {
2263    case SCALING_LIST_4x4:
2264      src = (listId<3) ? g_quantIntraDefault4x4 : g_quantInterDefault4x4;
2265      break;
2266    case SCALING_LIST_8x8:
2267      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2268      break;
2269    case SCALING_LIST_16x16:
2270      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2271      break;
2272    case SCALING_LIST_32x32:
2273      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2274      break;
2275    default:
2276      assert(0);
2277      src = NULL;
2278      break;
2279  }
2280  return src;
2281}
2282/** process of default matrix
2283 * \param sizeId size index
2284 * \param Index of input matrix
2285 */
2286Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId)
2287{
2288  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2289  setUseDefaultScalingMatrixFlag(sizeId,listId,true);
2290  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
2291}
2292/** check DC value of matrix for default matrix signaling
2293 */
2294Void TComScalingList::checkDcOfMatrix()
2295{
2296  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2297  {
2298    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2299    {
2300      setUseDefaultScalingMatrixFlag(sizeId,listId,false);
2301      //check default matrix?
2302      if(getScalingListDC(sizeId,listId) == 0)
2303      {
2304        processDefaultMarix(sizeId, listId);
2305      }
2306    }
2307  }
2308}
2309
2310ParameterSetManager::ParameterSetManager()
2311: m_spsMap(MAX_NUM_SPS)
2312, m_ppsMap(MAX_NUM_PPS)
2313, m_apsMap(MAX_NUM_APS)
2314#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
2315, m_vpsMap(MAX_NUM_VPS)
2316#endif
2317{
2318}
2319
2320
2321ParameterSetManager::~ParameterSetManager()
2322{
2323}
2324
2325//! \}
Note: See TracBrowser for help on using the repository browser.