source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibCommon/TComSlice.cpp @ 854

Last change on this file since 854 was 854, checked in by tech, 10 years ago

Integrated following MV-HEVC HLS 7 items:

H_MV_HLS7_GEN Stub for further integrations (not tested)
H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
Output layer sets, various

(VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
(VPS/P0156/Num of output_layer_flag) #10 Proposal 3: The output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive. It was remarked that we might be able to just assume that the top layer is always output; however, this was not entirely clear , so the safe thing to do may be to also send the flag for this layer.
(VPS/P0295/Default output layer sets) #5 Discussion from (P0110). Decision: Three-state approach (text in P0295, decoder shall allow 3 to be present and shall treat 3 the same as the value 2).

H_MV_HLS_7_HRD_P0156_7 (HRD/P0156/MaxSubLayersInLayerSetMinus1) #7 Proposal 1: signal, in the VPS extension, the DPB parameters for an output layer set for sub-DPBs only up to the maximum temporal sub-layers in the corresponding layer set
H_MV_HLS_7_VPS_P0048_14
(VPS/P0048/profile_ref_minus1 rem) #14 Remove profile_ref_minus1 from the VPS extension, from JCTVC-P0048
H_MV_HLS_7_VPS_P0076_15 (VPS/P0076/video signal info move) #15 Move video signal information syntax structure earlier in the VPS VUI.
H_MV_HLS_7_SPS_P0155_16_32
(SPS/P0155/sps_sub_layer_ordering_info) #16, #32 Not signal the sps_max_num_reorder_pics[], sps_max_latency_increase_plus1[], and sps_max_dec_pic_buffering_minus1[] syntax elements in the SPS when nuh_layer_id > 0.
H_MV_HLS_7_GEN_P0166_PPS_EXTENSION (GEN/P0166/pps_extension) #17 Add PPS extension type flags for conditional presence of syntax extensions per extension type, aligned with the SPS extension type flags, from JCTVC-P0166. Further align the SPS extension type flags syntax between RExt and MV-HEVC/SHVC
H_MV_HLS_7_FIX_SET_DPB_SIZE
Fix derivation dpb size parameters
H_MV_HLS_7_RESERVED_FLAGS Added flags

(SPS/P0312/SHVC reserved flag) The flag will be used for the syntax vert_phase_position_enable_flag in SHVC draft
(VPS/O0215/SHVC reserved flag): this flag will be used for the syntax cross_layer_phase_alignment_flag in SHVC draft.
(VPS VUI/O0199,P0312/SHVC reserved flags) the 3 reserved bits will be used for the syntaxes single_layer_for_non_irap_flag, higher_layer_irap_skip_flag and vert_phase_position_not_in_use_flag in SHVC draft.

H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO Discard VPS with nuh_layer_Id > 0
H_MV_HLS_7_MISC_P0130_EOS
(MISC/P0130/EOS NAL layer id) #19 Require that end of bitstream NAL unit shall have nuh_layer_id equal to 0, from JCTVC-P0130. Decoders shall allow an end of bitstream NAL unit with nuh_layer_id > 0 to be present, and shall ignore the NAL unit.
H_MV_HLS_7_MISC_P0182_13 (MISC/P0182/BL PS Compatibility flag) #13 Define the flag (in VPS VUI) with the proposed semantics, without specifying an associated extraction process. Editors to select the position in the VPS VUI.
H_MV_HLS_7_MISC_P0068_21
(MISC/P0068/all irap idr flag) #21 Add flag in VUI to indicate that all IRAP pictures are IDRs and that all layer pictures in an AU are IDR aligned, from JCTVC-P0068 proposal 1.
H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG Fix inference of cross_layer_irap_aligned_flag
H_MV_HLS_7_MISC_P0079_18
(MISC/P0079/NumActiveRefLayerPics) #18 Modification of derivation of variable NumActiveRefLayerPics.

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