source: 3DVCSoftware/branches/HTM-12.1-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1078

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

Removed MV-HEVC related macros part 4.

  • Property svn:eol-style set to native
File size: 123.5 KB
Line 
1/* The copyright in this software is being made available under the BSD
2* License, included below. This software may be subject to other third party
3* and contributor rights, including patent rights, and no such rights are
4* granted under this license. 
5*
6* Copyright (c) 2010-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     TDecCAVLC.cpp
35\brief    CAVLC decoder class
36*/
37
38#include "TDecCAVLC.h"
39#include "SEIread.h"
40#include "TDecSlice.h"
41
42//! \ingroup TLibDecoder
43//! \{
44
45#if ENC_DEC_TRACE
46
47Void  xTraceSPSHeader (TComSPS *pSPS)
48{
49#if H_MV_ENC_DEC_TRAC
50  if ( g_disableHLSTrace )
51  {
52    return; 
53  }
54  // To avoid mismatches
55  fprintf( g_hTrace, "=========== Sequence Parameter Set LayerId: %d ===========\n", pSPS->getLayerId() );
56#else
57  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
58#endif
59}
60
61Void  xTracePPSHeader (TComPPS *pPPS)
62{
63#if H_MV_ENC_DEC_TRAC
64  if ( g_disableHLSTrace )
65  {
66    return; 
67  }
68  fprintf( g_hTrace, "=========== Picture Parameter Set LayerId: %d ===========\n", pPPS->getLayerId() );
69#else
70  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
71#endif
72}
73
74Void  xTraceSliceHeader (TComSlice *pSlice)
75{
76#if H_MV_ENC_DEC_TRAC
77  if ( g_disableHLSTrace )
78  {
79    return; 
80  }
81#endif
82  fprintf( g_hTrace, "=========== Slice ===========\n");
83}
84
85#endif
86
87// ====================================================================================================================
88// Constructor / destructor / create / destroy
89// ====================================================================================================================
90
91TDecCavlc::TDecCavlc()
92{
93#if H_3D
94  m_aaiTempScale            = new Int* [ MAX_NUM_LAYERS ];
95  m_aaiTempOffset           = new Int* [ MAX_NUM_LAYERS ];
96  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
97  {
98    m_aaiTempScale            [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
99    m_aaiTempOffset           [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
100  }
101#endif
102}
103
104TDecCavlc::~TDecCavlc()
105{
106#if H_3D
107  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
108  {
109    delete [] m_aaiTempScale            [ uiVId ];
110    delete [] m_aaiTempOffset           [ uiVId ];
111  }
112  delete [] m_aaiTempScale;
113  delete [] m_aaiTempOffset;
114#endif
115}
116
117// ====================================================================================================================
118// Public member functions
119// ====================================================================================================================
120
121void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
122{
123  UInt code;
124  UInt interRPSPred;
125  if (idx > 0)
126  {
127    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
128  }
129  else
130  {
131    interRPSPred = false;
132    rps->setInterRPSPrediction(false);
133  }
134
135  if (interRPSPred) 
136  {
137    UInt bit;
138    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
139    {
140      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
141    }
142    else
143    {
144      code = 0;
145    }
146    assert(code <= idx-1); // delta_idx_minus1 shall not be larger than idx-1, otherwise we will predict from a negative row position that does not exist. When idx equals 0 there is no legal value and interRPSPred must be zero. See J0185-r2
147    Int rIdx =  idx - 1 - code;
148    assert (rIdx <= idx-1 && rIdx >= 0); // Made assert tighter; if rIdx = idx then prediction is done from itself. rIdx must belong to range 0, idx-1, inclusive, see J0185-r2
149    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
150    Int k = 0, k0 = 0, k1 = 0;
151    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
152    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
153    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
154    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
155    {
156      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
157      Int refIdc = bit;
158      if (refIdc == 0) 
159      {
160        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
161        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
162      }
163      if (refIdc == 1 || refIdc == 2)
164      {
165        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
166        rps->setDeltaPOC(k, deltaPOC);
167        rps->setUsed(k, (refIdc == 1));
168
169        if (deltaPOC < 0)
170        {
171          k0++;
172        }
173        else 
174        {
175          k1++;
176        }
177        k++;
178      } 
179      rps->setRefIdc(j,refIdc); 
180    }
181    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
182    rps->setNumberOfPictures(k);
183    rps->setNumberOfNegativePictures(k0);
184    rps->setNumberOfPositivePictures(k1);
185    rps->sortDeltaPOC();
186  }
187  else
188  {
189    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
190    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
191    Int prev = 0;
192    Int poc;
193    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
194    {
195      READ_UVLC(code, "delta_poc_s0_minus1");
196      poc = prev-code-1;
197      prev = poc;
198      rps->setDeltaPOC(j,poc);
199      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
200    }
201    prev = 0;
202    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
203    {
204      READ_UVLC(code, "delta_poc_s1_minus1");
205      poc = prev+code+1;
206      prev = poc;
207      rps->setDeltaPOC(j,poc);
208      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
209    }
210    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
211  }
212#if PRINT_RPS_INFO
213  rps->printDeltaPOC();
214#endif
215}
216
217#if H_3D
218Void TDecCavlc::parsePPS(TComPPS* pcPPS, TComVPS* pcVPS )
219#else
220Void TDecCavlc::parsePPS(TComPPS* pcPPS)
221#endif
222{
223#if ENC_DEC_TRACE 
224  xTracePPSHeader (pcPPS);
225#endif
226  UInt  uiCode;
227
228  Int   iCode;
229
230  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
231  assert(uiCode <= 63);
232  pcPPS->setPPSId (uiCode);
233 
234  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
235  assert(uiCode <= 15);
236  pcPPS->setSPSId (uiCode);
237 
238  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
239  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
240
241  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
242  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
243
244  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
245
246  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
247  assert(uiCode <= 14);
248  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
249 
250  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
251  assert(uiCode <= 14);
252  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
253 
254  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
255  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
256  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
257  pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
258
259  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
260  if( pcPPS->getUseDQP() )
261  {
262    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
263    pcPPS->setMaxCuDQPDepth( uiCode );
264  }
265  else
266  {
267    pcPPS->setMaxCuDQPDepth( 0 );
268  }
269  READ_SVLC( iCode, "pps_cb_qp_offset");
270  pcPPS->setChromaCbQpOffset(iCode);
271  assert( pcPPS->getChromaCbQpOffset() >= -12 );
272  assert( pcPPS->getChromaCbQpOffset() <=  12 );
273
274  READ_SVLC( iCode, "pps_cr_qp_offset");
275  pcPPS->setChromaCrQpOffset(iCode);
276  assert( pcPPS->getChromaCrQpOffset() >= -12 );
277  assert( pcPPS->getChromaCrQpOffset() <=  12 );
278
279  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
280  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
281
282  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
283  pcPPS->setUseWP( uiCode==1 );
284  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
285  pcPPS->setWPBiPred( uiCode==1 );
286
287  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
288  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
289  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
290  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
291 
292  if( pcPPS->getTilesEnabledFlag() )
293  {
294    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode ); 
295    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode ); 
296    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
297
298    if( !pcPPS->getUniformSpacingFlag())
299    {
300      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
301      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
302      { 
303        READ_UVLC( uiCode, "column_width_minus1" ); 
304        columnWidth[i] = uiCode+1;
305      }
306      pcPPS->setColumnWidth(columnWidth);
307      free(columnWidth);
308
309      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
310      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
311      {
312        READ_UVLC( uiCode, "row_height_minus1" );
313        rowHeight[i] = uiCode + 1;
314      }
315      pcPPS->setRowHeight(rowHeight);
316      free(rowHeight); 
317    }
318
319    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
320    {
321      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
322    }
323  }
324  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
325  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
326  if(pcPPS->getDeblockingFilterControlPresentFlag())
327  {
328    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
329    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
330    if(!pcPPS->getPicDisableDeblockingFilterFlag())
331    {
332      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
333      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
334    }
335  }
336  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
337  if(pcPPS->getScalingListPresentFlag ())
338  {
339    parseScalingList( pcPPS->getScalingList() );
340  }
341  READ_FLAG( uiCode, "lists_modification_present_flag");
342  pcPPS->setListsModificationPresentFlag(uiCode);
343
344  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
345  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
346
347  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
348  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
349 
350#if H_MV
351  READ_FLAG( uiCode, "pps_extension_present_flag");
352#else
353  READ_FLAG( uiCode, "pps_extension_flag");
354#endif
355  if (uiCode)
356  {
357
358#if H_MV
359    READ_FLAG( uiCode, "pps_range_extensions_flag" ); pcPPS->setPpsRangeExtensionsFlag( uiCode == 1 );
360    READ_FLAG( uiCode, "pps_multilayer_extension_flag" ); pcPPS->setPpsMultilayerExtensionFlag( uiCode == 1 );
361#if !H_3D
362    READ_CODE( 6, uiCode, "pps_extension_6bits" ); pcPPS->setPpsExtension6bits( uiCode );
363#else
364    READ_FLAG( uiCode, "pps_3d_extension_flag" ); pcPPS->setPps3dExtensionFlag( uiCode == 1 );
365    READ_CODE( 5, uiCode, "pps_extension_5bits" ); pcPPS->setPpsExtension5bits( uiCode );
366#endif
367    if ( pcPPS->getPpsRangeExtensionsFlag() )
368    { 
369      assert(0); 
370    }
371
372    if ( pcPPS->getPpsMultilayerExtensionFlag() )
373    { 
374      parsePPSMultilayerExtension( pcPPS ); 
375    }
376#if !H_3D
377    if ( pcPPS->getPpsExtension6bits() )
378    {
379#else
380    if ( pcPPS->getPps3dExtensionFlag() )
381    { 
382      parsePPSExtension( pcPPS, pcVPS );
383    }
384    if ( pcPPS->getPpsExtension5bits() )
385    {
386#endif
387
388#endif
389
390      while ( xMoreRbspData() )
391      {
392        READ_FLAG( uiCode, "pps_extension_data_flag");
393      }
394#if H_MV
395    }
396#endif
397  }
398}
399
400
401#if H_3D
402Void TDecCavlc::parsePPSExtension( TComPPS* pcPPS, TComVPS* pcVPS )
403{
404  //Ed.(GT): pcVPS should not be used here. Needs to be fixed.
405  UInt uiCode = 0; 
406  TComDLT* pcDLT = new TComDLT;
407
408  READ_FLAG(uiCode, "dlt_present_flag");
409  pcDLT->setDltPresentFlag( (uiCode == 1) ? true : false );
410
411  if ( pcDLT->getDltPresentFlag() )
412  {
413    READ_CODE(6, uiCode, "pps_depth_layers_minus1");
414    pcDLT->setNumDepthViews( uiCode );
415
416    READ_CODE(4, uiCode, "pps_bit_depth_for_depth_views_minus8");
417    pcDLT->setDepthViewBitDepth( (uiCode+8) );
418
419    for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
420    {
421      if ( i != 0 )
422      {
423        if( pcVPS->getDepthId( i ) == 1 ) 
424        {
425          READ_FLAG(uiCode, "dlt_flag[i]");
426          pcDLT->setUseDLTFlag(i, (uiCode == 1) ? true : false);
427
428          if ( pcDLT->getUseDLTFlag( i ) )
429          {
430            Bool bDltBitMapRepFlag    = false;
431            UInt uiMaxDiff            = 0xffffffff;
432            UInt uiMinDiff            = 0;
433            UInt uiCodeLength         = 0;
434
435            READ_FLAG(uiCode, "inter_view_dlt_pred_enable_flag[ i ]"); 
436
437            if( uiCode )
438            {
439                assert( pcDLT->getUseDLTFlag( 1 ));
440            }
441            pcDLT->setInterViewDltPredEnableFlag( i, (uiCode == 1) ? true : false );
442
443            if ( pcDLT->getInterViewDltPredEnableFlag( i ) == false )
444            {
445              READ_FLAG(uiCode, "dlt_bit_map_rep_flag[ layerId ]");
446              bDltBitMapRepFlag = (uiCode == 1) ? true : false; 
447            }
448            else
449            {
450              bDltBitMapRepFlag = false;
451            }
452           
453            UInt uiNumDepthValues = 0;
454            Int  aiIdx2DepthValue[256];
455
456            // Bit map
457            if ( bDltBitMapRepFlag )
458            {
459              for (UInt d=0; d<256; d++)
460              {
461                READ_FLAG(uiCode, "dlt_bit_map_flag[ layerId ][ j ]");
462                if (uiCode == 1)
463                {
464                  aiIdx2DepthValue[uiNumDepthValues] = d;
465                  uiNumDepthValues++;
466                }
467              }
468            }
469            // Diff Coding
470            else
471            {
472              READ_CODE(8, uiNumDepthValues, "num_depth_values_in_dlt[i]");   // num_entry
473
474              {
475                // The condition if( pcVPS->getNumDepthValues(i) > 0 ) is always true since for Single-view Diff Coding, there is at least one depth value in depth component.
476
477                if (uiNumDepthValues > 1)
478                {
479                  READ_CODE(8, uiCode, "max_diff[ layerId ]"); 
480                  uiMaxDiff = uiCode;
481                }
482                else
483                {
484                  uiMaxDiff = 0;           // when there is only one value in DLT
485                }
486
487                if (uiNumDepthValues > 2)
488                {
489                  uiCodeLength = (UInt) ceil(Log2(uiMaxDiff + 1));
490                  READ_CODE(uiCodeLength, uiCode, "min_diff_minus1[ layerId ]");
491                  uiMinDiff = uiCode + 1;
492                }
493                else
494                {
495                  uiMinDiff = uiMaxDiff;   // when there are only one or two values in DLT
496                }
497
498                READ_CODE(8, uiCode, "dlt_depth_value0[layerId]");   // entry0
499                aiIdx2DepthValue[0] = uiCode;
500
501                if (uiMaxDiff == uiMinDiff)
502                {
503                  for (UInt d=1; d<uiNumDepthValues; d++)
504                  {
505                    aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + 0;
506                  }
507                }
508                else
509                {
510                  uiCodeLength = (UInt) ceil(Log2(uiMaxDiff - uiMinDiff + 1));
511                  for (UInt d=1; d<uiNumDepthValues; d++)
512                  {
513                    READ_CODE(uiCodeLength, uiCode, "dlt_depth_value_diff_minus_min[ layerId ][ j ]");
514                    aiIdx2DepthValue[d] = aiIdx2DepthValue[d-1] + uiMinDiff + uiCode;
515                  }
516                }
517
518              }
519            }
520           
521            if( pcDLT->getInterViewDltPredEnableFlag( i ) )
522            {
523              // interpret decoded values as delta DLT
524              AOF( pcVPS->getDepthId( 1 ) == 1 );
525              AOF( i > 1 );
526              // assumes ref layer id to be 1
527              Int* piRefDLT = pcDLT->idx2DepthValue( 1 );
528              UInt uiRefNum = pcDLT->getNumDepthValues( 1 );
529              pcDLT->setDeltaDLT(i, piRefDLT, uiRefNum, aiIdx2DepthValue, uiNumDepthValues);
530            }
531            else
532            {
533              // store final DLT
534              pcDLT->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
535            }
536
537          }
538        }
539      }
540    }
541  }
542
543  pcPPS->setDLT( pcDLT );
544}
545#endif
546
547Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
548{
549#if ENC_DEC_TRACE
550  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
551#endif
552  UInt  uiCode;
553
554  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
555  if (pcVUI->getAspectRatioInfoPresentFlag())
556  {
557    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
558    if (pcVUI->getAspectRatioIdc() == 255)
559    {
560      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
561      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
562    }
563  }
564
565  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
566  if (pcVUI->getOverscanInfoPresentFlag())
567  {
568    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
569  }
570
571  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
572#if H_MV
573  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() ); 
574#endif
575  if (pcVUI->getVideoSignalTypePresentFlag())
576  {
577    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
578    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
579    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
580    if (pcVUI->getColourDescriptionPresentFlag())
581    {
582      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
583      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
584      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
585    }
586  }
587
588  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
589  if (pcVUI->getChromaLocInfoPresentFlag())
590  {
591    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
592    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
593  }
594
595  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
596
597  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
598
599  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
600
601  READ_FLAG(     uiCode, "default_display_window_flag");
602  if (uiCode != 0)
603  {
604    Window &defDisp = pcVUI->getDefaultDisplayWindow();
605#if H_MV
606    defDisp.setScaledFlag( false ); 
607    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
608    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode );
609    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode );
610    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode );
611#else
612    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
613    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
614    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
615    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
616#endif
617  }
618  TimingInfo *timingInfo = pcVUI->getTimingInfo();
619  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
620  if(timingInfo->getTimingInfoPresentFlag())
621  {
622    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
623    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
624    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
625    if(timingInfo->getPocProportionalToTimingFlag())
626    {
627      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
628    }
629  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
630  if( pcVUI->getHrdParametersPresentFlag() )
631  {
632    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
633  }
634  }
635  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
636  if (pcVUI->getBitstreamRestrictionFlag())
637  {
638    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
639    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
640    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
641    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
642    assert(uiCode < 4096);
643    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
644    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
645    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
646    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
647  }
648}
649
650Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
651{
652  UInt  uiCode;
653  if( commonInfPresentFlag )
654  {
655    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
656    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
657    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
658    {
659      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
660      if( hrd->getSubPicCpbParamsPresentFlag() )
661      {
662        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
663        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
664        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
665        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
666      }
667      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
668      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
669      if( hrd->getSubPicCpbParamsPresentFlag() )
670      {
671        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
672      }
673      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
674      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
675      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
676    }
677  }
678  Int i, j, nalOrVcl;
679  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
680  {
681    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
682    if( !hrd->getFixedPicRateFlag( i ) )
683    {
684      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
685    }
686    else
687    {
688      hrd->setFixedPicRateWithinCvsFlag( i, true );
689    }
690    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
691    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
692    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
693    {
694      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
695    }
696    else
697    {     
698      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
699    }
700    if (!hrd->getLowDelayHrdFlag( i ))
701    {
702      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
703    }
704    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
705    {
706      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
707          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
708      {
709        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
710        {
711          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
712          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
713          if( hrd->getSubPicCpbParamsPresentFlag() )
714          {
715            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
716            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
717          }
718          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
719        }
720      }
721    }
722  }
723}
724
725#if H_3D
726Void TDecCavlc::parseSPS(TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
727#else
728Void TDecCavlc::parseSPS(TComSPS* pcSPS)
729#endif
730{
731#if ENC_DEC_TRACE 
732  xTraceSPSHeader (pcSPS);
733#endif
734
735  UInt  uiCode;
736  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
737
738#if H_MV
739  if ( pcSPS->getLayerId() == 0 )
740  {
741#endif
742    READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
743    assert(uiCode <= 6);
744#if H_MV
745  }
746  else
747  {
748    READ_CODE( 3, uiCode, "sps_ext_or_max_sub_layers_minus1" ); pcSPS->setSpsExtOrMaxSubLayersMinus1( uiCode );   
749    pcSPS->inferSpsMaxSubLayersMinus1( false, NULL );
750  }
751  if ( !pcSPS->getMultiLayerExtSpsFlag() )
752  {
753#endif
754
755    READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
756    if ( pcSPS->getMaxTLayers() == 1 )
757    {
758      // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
759      assert( uiCode == 1 );
760    }
761
762    parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
763#if H_MV
764    pcSPS->getPTL()->inferGeneralValues ( true, 0, NULL ); 
765    pcSPS->getPTL()->inferSubLayerValues( pcSPS->getMaxTLayers() - 1, 0, NULL );
766  }
767#endif
768  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
769  assert(uiCode <= 15);
770#if H_MV
771  if ( pcSPS->getMultiLayerExtSpsFlag() )
772  {
773    READ_FLAG( uiCode, "update_rep_format_flag" );               pcSPS->setUpdateRepFormatFlag( uiCode == 1 );
774    if ( pcSPS->getUpdateRepFormatFlag() )
775    { 
776      READ_CODE( 8, uiCode, "sps_rep_format_idx" );                pcSPS->setSpsRepFormatIdx( uiCode );
777    }
778  }
779  else
780  {
781#endif
782    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
783    assert(uiCode <= 3);
784    // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
785    assert (uiCode == 1);
786    if( uiCode == 3 )
787    {
788      READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
789    }
790
791    READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
792    READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
793  READ_FLAG(     uiCode, "conformance_window_flag");
794  if (uiCode != 0)
795  {
796    Window &conf = pcSPS->getConformanceWindow();
797#if H_MV
798    // Needs to be scaled later, when ChromaFormatIdc is known.
799    conf.setScaledFlag( false ); 
800    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode  );
801    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode  );
802    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode  );
803    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode  );   
804  }
805#else
806    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
807    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
808    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
809    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
810#endif
811  }
812
813#if H_MV
814  if ( !pcSPS->getMultiLayerExtSpsFlag() )
815  { 
816#endif
817    READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
818    assert(uiCode <= 6);
819    pcSPS->setBitDepthY( uiCode + 8 );
820    pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
821
822    READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
823    assert(uiCode <= 6);
824    pcSPS->setBitDepthC( uiCode + 8 );
825    pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
826#if H_MV
827  }
828#endif
829
830  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
831  assert(uiCode <= 12);
832
833#if H_MV
834  if ( !pcSPS->getMultiLayerExtSpsFlag()) 
835  { 
836#endif
837    UInt subLayerOrderingInfoPresentFlag;
838    READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
839
840    for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
841    {
842      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
843      pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
844      READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
845      pcSPS->setNumReorderPics(uiCode, i);
846      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
847      pcSPS->setMaxLatencyIncrease( uiCode, i );
848
849      if (!subLayerOrderingInfoPresentFlag)
850      {
851        for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
852        {
853          pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
854          pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
855          pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
856        }
857        break;
858      }
859    }
860#if H_MV
861  }
862#endif
863
864  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
865  Int log2MinCUSize = uiCode + 3;
866  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
867  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
868  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
869
870  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
871  {
872    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
873  }
874
875  Int maxCUDepthDelta = uiCode;
876  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
877  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
878  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
879
880  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
881  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
882
883  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
884  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
885
886  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
887  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
888
889  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
890  if(pcSPS->getScalingListFlag())
891  {
892#if H_MV
893    if ( pcSPS->getMultiLayerExtSpsFlag() )
894    {   
895      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setSpsInferScalingListFlag( uiCode == 1 );
896    }
897
898    if ( pcSPS->getSpsInferScalingListFlag() )
899    {
900      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setSpsScalingListRefLayerId( uiCode );
901    }
902    else
903    {   
904#endif
905      READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
906      if(pcSPS->getScalingListPresentFlag ())
907      {
908        parseScalingList( pcSPS->getScalingList() );
909      }
910#if H_MV
911    }
912#endif
913  }
914  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
915  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
916
917  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
918  if( pcSPS->getUsePCM() )
919  {
920    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
921    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
922    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
923    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
924    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
925  }
926
927  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
928  assert(uiCode <= 64);
929  pcSPS->createRPSList(uiCode);
930
931  TComRPSList* rpsList = pcSPS->getRPSList();
932  TComReferencePictureSet* rps;
933
934  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
935  {
936    rps = rpsList->getReferencePictureSet(i);
937    parseShortTermRefPicSet(pcSPS,rps,i);
938  }
939  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
940  if (pcSPS->getLongTermRefsPresent()) 
941  {
942    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
943    pcSPS->setNumLongTermRefPicSPS(uiCode);
944    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
945    {
946      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
947      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
948      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
949      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
950    }
951  }
952  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
953
954  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
955
956  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
957
958  if (pcSPS->getVuiParametersPresentFlag())
959  {
960    parseVUI(pcSPS->getVuiParameters(), pcSPS);
961  }
962
963
964#if H_MV
965  READ_FLAG( uiCode, "sps_extension_present_flag");
966  pcSPS->setSpsExtensionPresentFlag( uiCode ); 
967  if (pcSPS->getSpsExtensionPresentFlag( ) )
968#else
969  READ_FLAG( uiCode, "sps_extension_flag");
970  if (uiCode)
971#endif
972  {
973#if H_MV
974    READ_FLAG( uiCode, "sps_range_extensions_flag" ); pcSPS->setSpsRangeExtensionsFlag( uiCode == 1 );
975    READ_FLAG( uiCode, "sps_multilayer_extension_flag" ); pcSPS->setSpsMultilayerExtensionFlag( uiCode == 1 );
976#if !H_3D
977    READ_CODE( 6, uiCode, "sps_extension_6bits" ); pcSPS->setSpsExtension6bits( uiCode );
978#else
979    READ_FLAG( uiCode, "sps_3d_extension_flag" ); pcSPS->setSps3dExtensionFlag( uiCode == 1 );
980    READ_CODE( 5, uiCode, "sps_extension_5bits" ); pcSPS->setSpsExtension5bits( uiCode );
981#endif
982  }
983
984  if ( pcSPS->getSpsRangeExtensionsFlag() )
985  {
986    assert( 0 ); 
987  }
988
989  if ( pcSPS->getSpsMultilayerExtensionFlag() )
990  {
991    parseSPSExtension( pcSPS ); 
992  }
993
994#if H_3D
995  if ( pcSPS->getSps3dExtensionFlag() )
996  {
997    parseSPSExtension2( pcSPS, viewIndex, depthFlag  ); 
998  }
999
1000  if ( pcSPS->getSpsExtension5bits() )
1001  { 
1002#else
1003  if ( pcSPS->getSpsExtension6bits() )
1004  { 
1005#endif
1006
1007#endif
1008    while ( xMoreRbspData() )
1009    {
1010      READ_FLAG( uiCode, "sps_extension_data_flag");
1011    }
1012  }
1013}
1014
1015#if H_MV
1016Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
1017{
1018  UInt uiCode; 
1019  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
1020 
1021}
1022
1023#if H_3D
1024Void TDecCavlc::parseSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
1025{ 
1026
1027}
1028#endif
1029
1030Void TDecCavlc::parsePPSMultilayerExtension(TComPPS* pcPPS)
1031{
1032  UInt uiCode = 0; 
1033  READ_FLAG( uiCode, "poc_reset_info_present_flag" ); pcPPS->setPocResetInfoPresentFlag( uiCode == 1 );
1034  READ_FLAG( uiCode, "pps_infer_scaling_list_flag" ); pcPPS->setPpsInferScalingListFlag( uiCode == 1 );
1035  READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setPpsScalingListRefLayerId( uiCode );
1036  READ_UVLC( uiCode, "num_ref_loc_offsets" ); assert( uiCode == 0 );
1037}
1038
1039#endif
1040
1041Void TDecCavlc::parseVPS(TComVPS* pcVPS)
1042{
1043  UInt  uiCode;
1044 
1045  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
1046#if H_MV
1047  READ_FLAG( uiCode, "vps_base_layer_internal_flag" );            pcVPS->setVpsBaseLayerInternalFlag( uiCode == 1 );
1048  READ_FLAG( uiCode, "vps_base_layer_available_flag" );           pcVPS->setVpsBaseLayerAvailableFlag( uiCode == 1 );
1049#else
1050  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
1051#endif
1052#if H_MV
1053  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( std::min( uiCode, (UInt) ( MAX_NUM_LAYER_IDS-1) )  );
1054#else
1055  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
1056#endif
1057  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );    assert(uiCode+1 <= MAX_TLAYER);
1058  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
1059  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
1060
1061  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
1062  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
1063#if H_MV
1064  pcVPS->getPTL()->inferGeneralValues ( true, 0, NULL );
1065  pcVPS->getPTL()->inferSubLayerValues( pcVPS->getMaxTLayers() - 1, 0, NULL );
1066#endif
1067  UInt subLayerOrderingInfoPresentFlag;
1068  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
1069  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
1070  {
1071    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
1072    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
1073    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
1074
1075    if (!subLayerOrderingInfoPresentFlag)
1076    {
1077      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
1078      {
1079        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
1080        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
1081        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
1082      }
1083      break;
1084    }
1085  }
1086
1087  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
1088#if H_MV
1089  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
1090  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
1091
1092  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setVpsNumLayerSetsMinus1( uiCode );
1093  for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx ++ )
1094  {
1095    for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
1096#else
1097  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
1098  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
1099  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
1100  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
1101  {
1102    // Operation point set
1103    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
1104#endif
1105    {
1106      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
1107    }
1108  }
1109#if H_MV
1110  pcVPS->deriveLayerSetLayerIdList(); 
1111#endif
1112  TimingInfo *timingInfo = pcVPS->getTimingInfo();
1113  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
1114  if(timingInfo->getTimingInfoPresentFlag())
1115  {
1116    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
1117    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
1118    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
1119    if(timingInfo->getPocProportionalToTimingFlag())
1120    {
1121      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
1122    }
1123    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
1124
1125    if( pcVPS->getNumHrdParameters() > 0 )
1126    {
1127      pcVPS->createHrdParamBuffer();
1128    }
1129    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
1130    {
1131      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
1132      if( i > 0 )
1133      {
1134        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
1135      }
1136      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
1137    }
1138  }
1139#if H_MV
1140  READ_FLAG( uiCode,  "vps_extension_flag" );                      pcVPS->setVpsExtensionFlag( uiCode == 1 ? true : false );
1141  if ( pcVPS->getVpsExtensionFlag() )
1142#else
1143  READ_FLAG( uiCode,  "vps_extension_flag" );
1144  if (uiCode)
1145#endif
1146  {
1147#if H_MV
1148    m_pcBitstream->readOutTrailingBits();
1149    parseVPSExtension( pcVPS );   
1150    READ_FLAG( uiCode,  "vps_extension2_flag" );
1151    if (uiCode)
1152    {
1153#if H_3D
1154      m_pcBitstream->readOutTrailingBits();
1155      pcVPS->createCamPars(pcVPS->getNumViews());
1156      parseVPSExtension2( pcVPS );   
1157      READ_FLAG( uiCode,  "vps_extension3_flag" );
1158      if (uiCode)
1159      {     
1160#endif
1161#endif 
1162        while ( xMoreRbspData() )
1163        {
1164          READ_FLAG( uiCode, "vps_extension_data_flag");
1165        }
1166#if H_MV
1167#if H_3D
1168      }
1169#endif
1170    }
1171#endif
1172  }
1173  return; 
1174}
1175
1176#if H_MV
1177Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
1178{
1179  UInt uiCode; 
1180
1181  if( pcVPS->getMaxLayersMinus1() > 0  &&  pcVPS->getVpsBaseLayerInternalFlag() )
1182  {
1183    parsePTL( pcVPS->getPTL( 1 ),0, pcVPS->getMaxSubLayersMinus1()  ); 
1184   
1185    pcVPS->getPTL( 1 )->inferGeneralValues ( false, 1, pcVPS->getPTL( 0 ) );
1186    pcVPS->getPTL( 1 )->inferSubLayerValues( pcVPS->getMaxSubLayersMinus1(), 1, pcVPS->getPTL( 0 ) );   
1187  }
1188
1189  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
1190
1191  for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
1192  {
1193    READ_FLAG( uiCode,  "scalability_mask_flag[i]" );             pcVPS->setScalabilityMaskFlag( sIdx, uiCode == 1 ? true : false );     
1194  }
1195
1196  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
1197  {
1198    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
1199  }
1200
1201  if ( pcVPS->getSplittingFlag() )
1202  {
1203    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
1204  }
1205
1206  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
1207
1208  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1209  {
1210    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
1211    {
1212      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
1213    }
1214    else
1215    {
1216      pcVPS->setLayerIdInNuh( i, i );; 
1217    }
1218
1219    pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
1220
1221    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
1222    {
1223      if ( !pcVPS->getSplittingFlag() )
1224      {
1225        READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
1226      }
1227      else
1228      {
1229        pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
1230      }
1231    }
1232  }
1233
1234  READ_CODE( 4, uiCode, "view_id_len" ); pcVPS->setViewIdLen( uiCode );
1235
1236  if ( pcVPS->getViewIdLen( ) > 0 )
1237  {   
1238    for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1239    {
1240      READ_CODE( pcVPS->getViewIdLen( ), uiCode, "view_id_val[i]" ); pcVPS->setViewIdVal( i, uiCode );
1241    }
1242  }
1243  else
1244  {
1245    for( Int i = 0; i < pcVPS->getNumViews(); i++ )
1246    {
1247      pcVPS->setViewIdVal( i, 0 ); 
1248    }
1249  }
1250
1251
1252  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1253  {
1254    for( Int j = 0; j < i; j++ )
1255    {
1256      READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
1257    }
1258  }
1259  pcVPS->setRefLayers(); 
1260
1261  if ( pcVPS->getNumIndependentLayers() > 1 ) 
1262  {
1263    READ_UVLC( uiCode, "num_add_layer_sets"      ); pcVPS->setNumAddLayerSets( uiCode );
1264  }
1265  for (Int i = 0; i < pcVPS->getNumAddLayerSets(); i++)
1266  {
1267    for (Int j = 1; j < pcVPS->getNumIndependentLayers(); j++)
1268    {
1269      READ_CODE( pcVPS->getHighestLayerIdxPlus1Len( j ) , uiCode, "highest_layer_idx_plus1" ); pcVPS->setHighestLayerIdxPlus1( i, j, uiCode );
1270    }
1271    pcVPS->deriveAddLayerSetLayerIdList( i );
1272  }
1273
1274  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag" ); pcVPS->setVpsSubLayersMaxMinus1PresentFlag( uiCode == 1 );
1275  if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
1276  {
1277    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1278    {
1279      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1" ); pcVPS->setSubLayersVpsMaxMinus1( i, uiCode );   
1280      pcVPS->checkSubLayersVpsMaxMinus1( i ); 
1281    }
1282  } 
1283  else
1284  {
1285    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
1286    {
1287      pcVPS->setSubLayersVpsMaxMinus1( i, pcVPS->getMaxTLayers( ) - 1);   
1288    }
1289  }
1290  READ_FLAG( uiCode, "max_tid_ref_present_flag" ); pcVPS->setMaxTidRefPresentFlag( uiCode == 1 );
1291
1292  if ( pcVPS->getMaxTidRefPresentFlag() )
1293  {   
1294    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
1295    {
1296      for( Int j = i + 1; j <= pcVPS->getMaxLayersMinus1(); j++ )
1297      {
1298        if ( pcVPS->getDirectDependencyFlag(j,i) )
1299        {
1300          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1" ); pcVPS->setMaxTidIlRefPicsPlus1( i, j, uiCode );
1301        }
1302      }
1303    }
1304  }
1305
1306  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
1307  READ_UVLC( uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode ); 
1308
1309  Int offsetVal =  ( pcVPS->getMaxLayersMinus1() > 0  &&  pcVPS->getVpsBaseLayerInternalFlag() ) ? 2 : 1;   
1310  for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 2 : 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
1311  {
1312    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
1313    parsePTL ( pcVPS->getPTL( offsetVal ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
1314    pcVPS->getPTL( offsetVal )->inferGeneralValues ( pcVPS->getVpsProfilePresentFlag( i ), offsetVal, pcVPS->getPTL( offsetVal - 1 ) );   
1315    pcVPS->getPTL( offsetVal )->inferSubLayerValues( pcVPS->getMaxSubLayersMinus1()      , offsetVal, pcVPS->getPTL( offsetVal - 1 ) );   
1316    offsetVal++;
1317  }
1318
1319
1320  if (pcVPS->getNumLayerSets() > 1)
1321  {
1322    READ_UVLC( uiCode, "num_add_olss" ); pcVPS->setNumAddOlss( uiCode );
1323    READ_CODE( 2, uiCode, "default_output_layer_idc" ); pcVPS->setDefaultOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );   
1324  }
1325
1326  pcVPS->initTargetLayerIdLists( ); 
1327
1328
1329  pcVPS->setOutputLayerFlag(0, 0, pcVPS->inferOutputLayerFlag( 0, 0 )); 
1330  pcVPS->setLayerSetIdxForOlsMinus1(0, -1); 
1331
1332  pcVPS->deriveNecessaryLayerFlags( 0 ); 
1333  pcVPS->deriveTargetLayerIdList( 0 ); 
1334
1335  if (pcVPS->getVpsBaseLayerInternalFlag() )
1336  { 
1337    pcVPS->setProfileTierLevelIdx(0,0, pcVPS->inferProfileTierLevelIdx(0,0) );
1338  }
1339  for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
1340  {
1341    if( i >= pcVPS->getNumLayerSets( ) )   
1342    {       
1343      READ_CODE( pcVPS->getLayerSetIdxForOlsMinus1Len( i ), uiCode, "layer_set_idx_for_ols_minus1[i]" ); pcVPS->setLayerSetIdxForOlsMinus1( i, uiCode ); 
1344    }
1345
1346    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() == 2 )
1347    {       
1348      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
1349      {
1350        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
1351      }
1352    }
1353    else
1354    { 
1355      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
1356      {             
1357        pcVPS->setOutputLayerFlag(i,j, pcVPS->inferOutputLayerFlag( i, j )); 
1358      }
1359    }
1360    pcVPS->deriveNecessaryLayerFlags( i ); 
1361    pcVPS->deriveTargetLayerIdList( i ); 
1362
1363    for ( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx(i)); j++ )
1364    {   
1365      if (pcVPS->getNecessaryLayerFlag( i, j ) && pcVPS->getVpsNumProfileTierLevelMinus1() > 0 )
1366      {
1367        READ_CODE( pcVPS->getProfileTierLevelIdxLen(), uiCode,"profile_tier_level_idx[ i ][ j ]" );   pcVPS->setProfileTierLevelIdx( i, j, uiCode ); 
1368      }
1369      if (pcVPS->getNecessaryLayerFlag( i, j ) && pcVPS->getVpsNumProfileTierLevelMinus1() == 0 )
1370      {
1371        pcVPS->setProfileTierLevelIdx( i , j, pcVPS->inferProfileTierLevelIdx( i, j) );
1372      }
1373    }
1374
1375    if( pcVPS->getNumOutputLayersInOutputLayerSet( i ) == 1 && pcVPS->getNumDirectRefLayers( pcVPS->getOlsHighestOutputLayerId( i ) ) > 0 )
1376    {
1377      READ_FLAG( uiCode, "alt_output_layer_flag[ i ]" ); pcVPS->setAltOutputLayerFlag( i, uiCode == 1 );
1378    }
1379  }
1380
1381  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
1382
1383  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
1384  { 
1385    assert( pcVPS->getRepFormat(i) == NULL ); 
1386    TComRepFormat* curRepFormat = new TComRepFormat(); 
1387    TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL; 
1388    parseRepFormat( i, curRepFormat ,  prevRepFormat); 
1389    pcVPS->setRepFormat(i, curRepFormat ); 
1390  }
1391
1392  if ( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
1393  {
1394    READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
1395  }
1396  if( pcVPS->getRepFormatIdxPresentFlag() ) 
1397  {
1398    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 0; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1399    {
1400        READ_CODE( pcVPS->getVpsRepFormatIdxLen(), uiCode, "vps_rep_format_idx[i]" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
1401    }
1402  }
1403  else
1404  {
1405    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 0; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1406    {
1407      pcVPS->setVpsRepFormatIdx( i, pcVPS->inferVpsRepFormatIdx( i ) );
1408    }
1409  }
1410
1411  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
1412#if H_MV_HLS7_GEN
1413  READ_FLAG( uiCode, "vps_poc_lsb_aligned_flag" ); pcVPS->setVpsPocLsbAlignedFlag( uiCode == 1 );
1414#endif
1415  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1416  {
1417    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) )  ==  0 )
1418    {     
1419      READ_FLAG( uiCode, "poc_lsb_not_present_flag" ); pcVPS->setPocLsbNotPresentFlag( i, uiCode == 1 );
1420    }
1421  }
1422
1423  parseDpbSize( pcVPS ); 
1424
1425  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
1426
1427  READ_FLAG( uiCode, "default_direct_dependency_flag" ); pcVPS->setDefaultDirectDependencyFlag( uiCode == 1 );
1428  if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1429  { 
1430    READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2, uiCode, "default_direct_dependency_type" ); pcVPS->setDefaultDirectDependencyType( uiCode );
1431  }
1432
1433  for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ?  1 : 2; i <= pcVPS->getMaxLayersMinus1(); i++ )
1434  {
1435    for( Int j = pcVPS->getVpsBaseLayerInternalFlag() ?  0 : 1; j < i; j++ )
1436    {
1437      if (pcVPS->getDirectDependencyFlag( i, j) )
1438      {       
1439        if ( pcVPS->getDefaultDirectDependencyFlag( ) )
1440        { 
1441          pcVPS->setDirectDependencyType( i, j , pcVPS->getDefaultDirectDependencyType( ) );
1442        }
1443        else
1444        {
1445
1446          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
1447        }
1448      }
1449    }
1450  } 
1451  READ_UVLC( uiCode, "vps_non_vui_extension_length" ); pcVPS->setVpsNonVuiExtensionLength( uiCode ); 
1452  for ( Int i = 1; i <= pcVPS->getVpsNonVuiExtensionLength(); i++ )
1453  {
1454    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" );
1455  }
1456  READ_FLAG( uiCode, "vps_vui_present_flag" );  pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
1457  if( pcVPS->getVpsVuiPresentFlag() )
1458  {
1459    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
1460    parseVPSVUI( pcVPS ); 
1461  }     
1462  {
1463    TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1464    assert( pcVPSVUI ); 
1465    pcVPSVUI->inferVpsVui( false ); 
1466  }
1467  pcVPS->checkVPSExtensionSyntax(); 
1468}
1469
1470Void TDecCavlc::parseRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
1471{
1472  assert( pcRepFormat ); 
1473
1474  UInt uiCode; 
1475
1476  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
1477  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
1478  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" ); pcRepFormat->setChromaAndBitDepthVpsPresentFlag( uiCode == 1 );
1479
1480  pcRepFormat->checkChromaAndBitDepthVpsPresentFlag( i ); 
1481
1482  if ( pcRepFormat->getChromaAndBitDepthVpsPresentFlag() )
1483  { 
1484    READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
1485    if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
1486    {
1487      READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
1488    }
1489    READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
1490    READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
1491  }
1492  else
1493  {
1494    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, false ); 
1495  }
1496  READ_FLAG( uiCode, "conformance_window_vps_flag" ); pcRepFormat->setConformanceWindowVpsFlag( uiCode == 1 );
1497  if ( pcRepFormat->getConformanceWindowVpsFlag() )
1498  {
1499    READ_UVLC( uiCode, "conf_win_vps_left_offset" ); pcRepFormat->setConfWinVpsLeftOffset( uiCode );
1500    READ_UVLC( uiCode, "conf_win_vps_right_offset" ); pcRepFormat->setConfWinVpsRightOffset( uiCode );
1501    READ_UVLC( uiCode, "conf_win_vps_top_offset" ); pcRepFormat->setConfWinVpsTopOffset( uiCode );
1502    READ_UVLC( uiCode, "conf_win_vps_bottom_offset" ); pcRepFormat->setConfWinVpsBottomOffset( uiCode );
1503  }
1504}
1505
1506
1507Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
1508{
1509  assert( pcVPS ); 
1510
1511  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1512
1513  assert( pcVPSVUI ); 
1514
1515  UInt uiCode; 
1516  READ_FLAG( uiCode, "cross_layer_pic_type_aligned_flag" ); pcVPSVUI->setCrossLayerPicTypeAlignedFlag( uiCode == 1 );
1517  if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
1518  { 
1519    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
1520  }
1521  if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
1522  {
1523    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
1524  }
1525  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
1526  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
1527  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
1528  {
1529    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <  pcVPS->getNumLayerSets(); i++ )
1530    {
1531      for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ ) 
1532      {
1533        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
1534        {
1535          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );           
1536        }
1537        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
1538        {
1539          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
1540        }
1541        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
1542        {
1543          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
1544          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
1545        }
1546        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
1547        {
1548          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
1549          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
1550        }
1551      }
1552    }
1553  }
1554
1555  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
1556  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1557  {
1558    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
1559  }
1560  else
1561  {
1562    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1 ); 
1563  }
1564
1565  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
1566  {
1567    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL ); 
1568    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
1569    parseVideoSignalInfo( curVideoSignalInfo ); 
1570    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo ); 
1571  }
1572
1573  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
1574  {
1575    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1576    {
1577      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
1578    }
1579  }
1580  else if ( !pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
1581  {
1582    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1583    {
1584      pcVPSVUI->setVpsVideoSignalInfoIdx( i, i );
1585    }
1586  }
1587  else
1588  {
1589    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
1590    {
1591      pcVPSVUI->setVpsVideoSignalInfoIdx( i, 0 );
1592    }
1593  }
1594
1595  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
1596  if( !pcVPSVUI->getTilesNotInUseFlag() ) 
1597  {     
1598    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1599    {
1600      READ_FLAG( uiCode, "tiles_in_use_flag[i]" ); pcVPSVUI->setTilesInUseFlag( i, uiCode == 1 );
1601      if( pcVPSVUI->getTilesInUseFlag( i ) ) 
1602      {
1603        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[i]" ); pcVPSVUI->setLoopFilterNotAcrossTilesFlag( i, uiCode == 1 );
1604      }
1605    } 
1606    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 1 : 2; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1607    {
1608      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
1609      {
1610        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getIdDirectRefLayer(pcVPS->getLayerIdInNuh( i ) , j  )); 
1611        if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) ) 
1612        {
1613          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
1614        }
1615      } 
1616    }
1617  } 
1618 
1619  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); pcVPSVUI->setWppNotInUseFlag( uiCode == 1 );
1620 
1621  if( !pcVPSVUI->getWppNotInUseFlag( ))
1622  {
1623    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ ) 
1624    {
1625      READ_FLAG( uiCode, "wpp_in_use_flag[i]" ); pcVPSVUI->setWppInUseFlag( i, uiCode == 1 );
1626    }
1627  }
1628  READ_FLAG( uiCode, "single_layer_for_non_irap_flag" ); pcVPSVUI->setSingleLayerForNonIrapFlag( uiCode == 1 );
1629  READ_FLAG( uiCode, "higher_layer_irap_skip_flag" ); pcVPSVUI->setHigherLayerIrapSkipFlag( uiCode == 1 );
1630  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
1631
1632  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
1633  {
1634    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1635    {
1636      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
1637      {
1638        if( pcVPS->getVpsBaseLayerInternalFlag() || pcVPS->getIdDirectRefLayer( pcVPS->getLayerIdInNuh( i ), j ) > 0 )
1639        {       
1640          READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
1641          if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
1642          {
1643            READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
1644            if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
1645            {
1646              READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
1647            }
1648          }
1649        }
1650      }
1651    }
1652  }
1653
1654  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
1655  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
1656  {
1657    assert(pcVPS->getTimingInfo()->getTimingInfoPresentFlag() == 1);
1658    parseVpsVuiBspHrdParameters( pcVPS ); 
1659  }
1660  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
1661  {
1662    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 ) 
1663    {
1664      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
1665    }
1666  }
1667}
1668
1669Void TDecCavlc::parseVpsVuiBspHrdParameters( TComVPS* pcVPS )
1670{
1671  assert( pcVPS ); 
1672
1673  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
1674
1675  assert( pcVPSVUI ); 
1676
1677  TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters(); 
1678  assert( vpsVuiBspHrdP == NULL ); 
1679  vpsVuiBspHrdP = new TComVpsVuiBspHrdParameters; 
1680  pcVPSVUI->setVpsVuiBspHrdParameters( vpsVuiBspHrdP ); 
1681  UInt uiCode; 
1682  READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vpsVuiBspHrdP->setVpsNumAddHrdParams( uiCode );
1683  vpsVuiBspHrdP->createAfterVpsNumAddHrdParams( pcVPS ); 
1684  for( Int i = pcVPS->getNumHrdParameters(); i < pcVPS->getNumHrdParameters() + vpsVuiBspHrdP->getVpsNumAddHrdParams(); i++ )
1685  { 
1686    if( i > 0 ) 
1687    {
1688      READ_FLAG( uiCode, "cprms_add_present_flag" ); vpsVuiBspHrdP->setCprmsAddPresentFlag( i, uiCode == 1 );
1689    }
1690    else
1691    {
1692       vpsVuiBspHrdP->setCprmsAddPresentFlag( i, true );
1693    }
1694
1695    READ_UVLC( uiCode, "num_sub_layer_hrd_minus1" ); vpsVuiBspHrdP->setNumSubLayerHrdMinus1( i, uiCode );
1696    TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i ); 
1697    parseHrdParameters( hrdParameters, vpsVuiBspHrdP->getCprmsAddPresentFlag( i ), vpsVuiBspHrdP->getNumSubLayerHrdMinus1( i ) );     
1698  }
1699
1700  vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( 0, 0, 0);
1701  vpsVuiBspHrdP->createAfterNumPartitionsInSchemeMinus1( 0, 0 );
1702
1703  for( Int h = 0; h < pcVPS->getNumOutputLayerSets(); h++ )
1704  { 
1705    if ( h == 0)
1706    {
1707      vpsVuiBspHrdP->setNumSignalledPartitioningSchemes( h, 0 );
1708    }
1709    else
1710    {
1711      READ_UVLC( uiCode, "num_signalled_partitioning_schemes" ); vpsVuiBspHrdP->setNumSignalledPartitioningSchemes( h, uiCode );
1712    }   
1713    vpsVuiBspHrdP->createAfterNumSignalledPartitioningSchemes( h );
1714
1715    for( Int j = 0; j < vpsVuiBspHrdP->getNumSignalledPartitioningSchemes( h ) + 1; j++ )
1716    { 
1717      if ( j == 0 && h == 0 )
1718      {
1719        vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, uiCode );
1720      }
1721      else if( j == 0 )
1722      {
1723        vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, pcVPS->getNumLayersInIdList( h ) - 1 );
1724      }
1725      else
1726      {
1727        READ_UVLC( uiCode, "num_partitions_in_scheme_minus1" ); vpsVuiBspHrdP->setNumPartitionsInSchemeMinus1( h, j, uiCode );
1728      }
1729      vpsVuiBspHrdP->createAfterNumPartitionsInSchemeMinus1( h, j );
1730
1731      for( Int k = 0; k  <=  vpsVuiBspHrdP->getNumPartitionsInSchemeMinus1( h, j ); k++ ) 
1732      {
1733        for( Int r = 0; r < pcVPS->getNumLayersInIdList(pcVPS->olsIdxToLsIdx( h ) )   ; r++ ) 
1734        {
1735          if( h == 0 && j == 0 && k == 0 && r == 0 )
1736          {
1737             vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, true );
1738          }
1739          else if ( h > 0 && j == 0 )
1740          {
1741             vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, (k == r) );
1742          }
1743          else
1744          {
1745            READ_FLAG( uiCode, "layer_included_in_partition_flag" ); vpsVuiBspHrdP->setLayerIncludedInPartitionFlag( h, j, k, r, uiCode == 1 );
1746          }         
1747        }
1748      }
1749    } 
1750    if ( h > 0 )
1751    {
1752      for( Int i = 0; i < vpsVuiBspHrdP->getNumSignalledPartitioningSchemes( h ) + 1; i++ ) 
1753      {
1754        for( Int t = 0; t  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( pcVPS->olsIdxToLsIdx( i ) ); t++ )
1755        { 
1756          READ_UVLC( uiCode, "num_bsp_schedules_minus1" ); vpsVuiBspHrdP->setNumBspSchedulesMinus1( h, i, t, uiCode );
1757          vpsVuiBspHrdP->createAfterNumBspSchedulesMinus1( h, i, t );
1758          for( Int j = 0; j  <=  vpsVuiBspHrdP->getNumBspSchedulesMinus1( h, i, t ); j++ ) 
1759          {
1760            for( Int k = 0; k  <=  vpsVuiBspHrdP->getNumPartitionsInSchemeMinus1( h, j ); k++ )
1761            { 
1762              READ_CODE( vpsVuiBspHrdP->getBspHrdIdxLen( pcVPS ), uiCode, "bsp_hrd_idx" ); vpsVuiBspHrdP->setBspHrdIdx( h, i, t, j, k, uiCode );
1763              READ_UVLC( uiCode, "bsp_sched_idx" ); vpsVuiBspHrdP->setBspSchedIdx( h, i, t, j, k, uiCode );
1764            } 
1765          }
1766        } 
1767      }
1768    }
1769  } 
1770}
1771
1772Void TDecCavlc::parseVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo ) 
1773{
1774  UInt uiCode; 
1775  READ_CODE( 3, uiCode, "video_vps_format" );             pcVideoSignalInfo->setVideoVpsFormat( uiCode );
1776  READ_FLAG( uiCode, "video_full_range_vps_flag" );       pcVideoSignalInfo->setVideoFullRangeVpsFlag( uiCode == 1 );
1777  READ_CODE( 8, uiCode, "colour_primaries_vps" );         pcVideoSignalInfo->setColourPrimariesVps( uiCode );
1778  READ_CODE( 8, uiCode, "transfer_characteristics_vps" ); pcVideoSignalInfo->setTransferCharacteristicsVps( uiCode );
1779  READ_CODE( 8, uiCode, "matrix_coeffs_vps" );            pcVideoSignalInfo->setMatrixCoeffsVps( uiCode );
1780}
1781
1782Void TDecCavlc::parseDpbSize( TComVPS* vps )
1783{
1784  UInt uiCode; 
1785  TComDpbSize* dpbSize = vps->getDpbSize(); 
1786  assert ( dpbSize != 0 ); 
1787
1788  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
1789  { 
1790    Int currLsIdx = vps->olsIdxToLsIdx( i ); 
1791    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
1792    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
1793    { 
1794      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
1795      {
1796        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag" ); dpbSize->setSubLayerDpbInfoPresentFlag( i, j, uiCode == 1 );
1797      }
1798      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
1799      { 
1800        for( Int k = 0; k < vps->getNumLayersInIdList( currLsIdx ); k++ )   
1801        {
1802          if ( vps->getNecessaryLayerFlag( i, k ) && ( vps->getVpsBaseLayerInternalFlag() || ( vps->getLayerSetLayerIdList(vps->olsIdxToLsIdx(i),k) != 0 ) ))
1803          {
1804            READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
1805          }
1806          else
1807          {
1808            if ( vps->getNecessaryLayerFlag( i, k ) && ( j == 0 ) && ( k == 0 ))
1809            {
1810              dpbSize->setMaxVpsDecPicBufferingMinus1(i ,k, j, 0 );
1811            }
1812          }
1813        }
1814        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
1815        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
1816      }
1817      else
1818      {
1819        if ( j > 0 )
1820        {
1821          for( Int k = 0; k < vps->getNumLayersInIdList( vps->olsIdxToLsIdx( i ) ); k++ )   
1822          {
1823            if ( vps->getNecessaryLayerFlag(i, k ) )
1824            {           
1825              dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
1826            }
1827          }
1828          dpbSize->setMaxVpsNumReorderPics      ( i, j, dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
1829          dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
1830        }
1831      }
1832    } 
1833  } 
1834}
1835
1836#if H_3D
1837Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
1838{
1839  UInt uiCode; 
1840  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
1841  {
1842#if H_3D_ARP
1843    pcVPS->setUseAdvRP  ( i, 0 );
1844    pcVPS->setARPStepNum( i, 1 );
1845#endif 
1846#if H_3D_SPIVMP
1847    pcVPS->setSubPULog2Size(i, 0);
1848#endif
1849    {
1850#if H_3D_IV_MERGE
1851      READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
1852      READ_FLAG( uiCode, "iv_mv_scaling_flag[i]");       pcVPS->setIvMvScalingFlag         ( i, uiCode == 1 ? true : false );
1853#endif
1854      if( !( pcVPS->getDepthId( i ) == 1 ) )
1855      {
1856#if H_3D_IV_MERGE
1857        if( !pcVPS->getNumDirectRefLayers(i) )
1858        {
1859          assert( !uiCode );         
1860        }
1861#if H_3D_SPIVMP
1862        READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3); 
1863#endif
1864#endif
1865#if H_3D_ARP
1866        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
1867        if( !pcVPS->getNumDirectRefLayers(i) )
1868        {
1869          assert( !uiCode );         
1870        }
1871#endif
1872#if H_3D_NBDV_REF
1873        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
1874#endif
1875#if H_3D_VSP
1876        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
1877        if( !pcVPS->getNumDirectRefLayers(i) )
1878        {
1879          assert( !uiCode );         
1880        }
1881#endif
1882#if H_3D_DBBP
1883          READ_FLAG( uiCode, "use_dbbp_flag[i]" ); pcVPS->setUseDBBP( i, uiCode == 1 ? true : false );
1884#endif
1885      }
1886      else
1887      {
1888#if H_3D_IV_MERGE
1889        READ_FLAG( uiCode, "mpi_flag[i]" );             pcVPS->setMPIFlag( i, uiCode == 1 ? true : false );
1890        READ_UVLC (uiCode, "log2_mpi_sub_PU_size_minus3[i]");     pcVPS->setSubPUMPILog2Size(i, uiCode+3);
1891#endif
1892        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
1893#if H_3D
1894        READ_FLAG( uiCode, "ivp_flag[i]" );                   pcVPS->setIVPFlag( i, uiCode == 1 ? true : false );
1895#endif
1896#if H_3D_QTLPC
1897        READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPredFlag     ( i, uiCode == 1 ? true : false ); 
1898#endif
1899#if H_3D_INTER_SDC
1900            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
1901#endif
1902      }
1903    }
1904  }
1905
1906  UInt uiCamParPrecision = 0; 
1907  Bool bCamParSlice      = false; 
1908  Bool bCamParPresentFlag = false;
1909
1910  READ_UVLC( uiCamParPrecision, "cp_precision" );
1911  for (UInt viewIndex=1; viewIndex<pcVPS->getNumViews(); viewIndex++)
1912  {
1913    pcVPS->setCamParPresent         ( viewIndex, false );
1914    pcVPS->setHasCamParInSliceHeader( viewIndex, false );
1915    READ_FLAG( uiCode, "cp_present_flag[i]" );                  bCamParPresentFlag = ( uiCode == 1);
1916    if ( bCamParPresentFlag )
1917    {
1918      READ_FLAG( uiCode, "cp_in_slice_segment_header_flag[i]" );          bCamParSlice = ( uiCode == 1);
1919      if ( !bCamParSlice )
1920      {
1921        for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
1922        {
1923          Int iCode; 
1924          READ_SVLC( iCode, "vps_cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
1925          READ_SVLC( iCode, "vps_cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
1926          READ_SVLC( iCode, "vps_cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
1927          READ_SVLC( iCode, "vps_cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
1928        }
1929      }
1930      pcVPS->initCamParaVPS( viewIndex, bCamParPresentFlag, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
1931    }
1932  }
1933}
1934#endif
1935#endif
1936#if H_MV
1937Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, Int targetOlsIdx)
1938#else
1939Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
1940#endif
1941{
1942  UInt  uiCode;
1943  Int   iCode;
1944
1945#if ENC_DEC_TRACE
1946  xTraceSliceHeader(rpcSlice);
1947#endif
1948  TComPPS* pps = NULL;
1949  TComSPS* sps = NULL;
1950#if H_MV
1951  TComVPS* vps = NULL;
1952#endif
1953
1954  UInt firstSliceSegmentInPic;
1955  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
1956  if( rpcSlice->getRapPicFlag())
1957  { 
1958    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
1959#if SETTING_NO_OUT_PIC_PRIOR
1960    rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
1961#else
1962    rpcSlice->setNoOutputPicPrior( false );
1963#endif
1964  }
1965
1966  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
1967  pps = parameterSetManager->getPrefetchedPPS(uiCode);
1968  //!KS: need to add error handling code here, if PPS is not available
1969  assert(pps!=0);
1970  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1971  //!KS: need to add error handling code here, if SPS is not available
1972  assert(sps!=0);
1973#if H_MV
1974  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
1975  assert( vps != NULL );
1976 
1977  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
1978  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
1979  sps->inferSpsMaxDecPicBufferingMinus1( vps, targetOlsIdx, rpcSlice->getLayerId(), false ); 
1980
1981  if ( sps->getVuiParametersPresentFlag() )
1982  {
1983    sps->getVuiParameters()->inferVideoSignalInfo( vps, rpcSlice->getLayerId() ); 
1984  }
1985  rpcSlice->setVPS(vps);     
1986  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
1987  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      ); 
1988#if H_3D 
1989  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
1990#endif
1991#endif
1992  rpcSlice->setSPS(sps);
1993  rpcSlice->setPPS(pps);
1994  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
1995  {
1996    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
1997  }
1998  else
1999  {
2000    rpcSlice->setDependentSliceSegmentFlag(false);
2001  }
2002  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2003  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
2004  UInt sliceSegmentAddress = 0;
2005  Int bitsSliceSegmentAddress = 0;
2006  while(numCTUs>(1<<bitsSliceSegmentAddress))
2007  {
2008    bitsSliceSegmentAddress++;
2009  }
2010
2011  if(!firstSliceSegmentInPic)
2012  {
2013    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
2014  }
2015  //set uiCode to equal slice start address (or dependent slice start address)
2016  Int startCuAddress = maxParts*sliceSegmentAddress;
2017  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
2018  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
2019
2020  if (rpcSlice->getDependentSliceSegmentFlag())
2021  {
2022    rpcSlice->setNextSlice          ( false );
2023    rpcSlice->setNextSliceSegment ( true  );
2024  }
2025  else
2026  {
2027    rpcSlice->setNextSlice          ( true  );
2028    rpcSlice->setNextSliceSegment ( false );
2029
2030    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
2031    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
2032  }
2033 
2034#if H_MV
2035    UInt slicePicOrderCntLsb = 0;
2036#endif
2037
2038  if(!rpcSlice->getDependentSliceSegmentFlag())
2039  {
2040#if H_MV   
2041    Int esb = 0; //Don't use i, otherwise will shadow something below
2042
2043    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2044    {
2045      esb++; 
2046      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
2047      if ( uiCode == 1 )
2048      {
2049        assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
2050          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
2051          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
2052          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
2053          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
2054      }
2055    }
2056
2057    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2058    {
2059      esb++; 
2060      READ_FLAG( uiCode, "cross_layer_bla_flag" ); rpcSlice->setCrossLayerBlaFlag( uiCode == 1 );
2061    }
2062    rpcSlice->checkCrossLayerBlaFlag( ); 
2063
2064#if !H_MV_HLS7_GEN
2065    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
2066    {
2067      esb++; 
2068      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
2069    }
2070#endif
2071
2072    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
2073#else
2074    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2075#endif     
2076    {
2077      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2078    }
2079
2080    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
2081    if( pps->getOutputFlagPresentFlag() )
2082    {
2083      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
2084    }
2085    else
2086    {
2087      rpcSlice->setPicOutputFlag( true );
2088    }
2089    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
2090    assert (sps->getChromaFormatIdc() == 1 );
2091    // if( separate_colour_plane_flag  ==  1 )
2092    //   colour_plane_id                                      u(2)
2093
2094
2095#if H_MV
2096    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
2097    if ( (rpcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( rpcSlice->getLayerIdInVps())) || !rpcSlice->getIdrPicFlag() )
2098    {
2099      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");       
2100    }   
2101    rpcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb ); 
2102
2103    Bool picOrderCntMSBZeroFlag = false;     
2104
2105    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
2106    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ); 
2107    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
2108    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ); 
2109    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   rpcSlice->getIdrPicFlag(); 
2110
2111    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() );
2112
2113    Int picOrderCntMSB = 0; 
2114
2115    if ( !picOrderCntMSBZeroFlag )
2116    {
2117      Int prevPicOrderCnt    = rpcSlice->getPrevTid0POC();
2118      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
2119      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
2120      Int prevPicOrderCntMsb = prevPicOrderCnt - prevPicOrderCntLsb;
2121           
2122      if( ( slicePicOrderCntLsb  <  prevPicOrderCntLsb ) && ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
2123      {
2124        picOrderCntMSB = prevPicOrderCntMsb + maxPicOrderCntLsb;
2125      }
2126      else if( (slicePicOrderCntLsb  >  prevPicOrderCntLsb )  && ( (slicePicOrderCntLsb - prevPicOrderCntLsb )  >  ( maxPicOrderCntLsb / 2 ) ) ) 
2127      {
2128        picOrderCntMSB = prevPicOrderCntMsb - maxPicOrderCntLsb;
2129      }
2130      else
2131      {
2132        picOrderCntMSB = prevPicOrderCntMsb;
2133      }   
2134    }
2135     
2136    rpcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
2137    if ( rpcSlice->getPocResetFlag() ) 
2138    {
2139      rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
2140      rpcSlice->setPOC              ( 0 );
2141    }     
2142#endif
2143
2144    if( rpcSlice->getIdrPicFlag() )
2145    {
2146#if !H_MV
2147      rpcSlice->setPOC(0);
2148#endif
2149      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
2150      rps->setNumberOfNegativePictures(0);
2151      rps->setNumberOfPositivePictures(0);
2152      rps->setNumberOfLongtermPictures(0);
2153      rps->setNumberOfPictures(0);
2154      rpcSlice->setRPS(rps);
2155#if H_MV
2156      rpcSlice->setEnableTMVPFlag(false);
2157#endif
2158    }
2159    else
2160    {
2161#if !H_MV
2162      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
2163      Int iPOClsb = uiCode;
2164      Int iPrevPOC = rpcSlice->getPrevTid0POC();
2165      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
2166      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
2167      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
2168      Int iPOCmsb;
2169      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
2170      {
2171        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
2172      }
2173      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
2174      {
2175        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
2176      }
2177      else
2178      {
2179        iPOCmsb = iPrevPOCmsb;
2180      }
2181      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2182        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2183        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2184      {
2185        // For BLA picture types, POCmsb is set to 0.
2186        iPOCmsb = 0;
2187      }
2188      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
2189#endif
2190      TComReferencePictureSet* rps;
2191      rps = rpcSlice->getLocalRPS();
2192      rpcSlice->setRPS(rps);
2193      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
2194      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
2195      {       
2196        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
2197#if H_MV
2198        if ( !rps->getInterRPSPrediction( ) )
2199        { // check sum of num_positive_pics and num_negative_pics
2200          rps->checkMaxNumPics( 
2201            vps->getVpsExtensionFlag(), 
2202            MAX_INT,  // To be replaced by MaxDbpSize
2203            rpcSlice->getLayerId(), 
2204            sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
2205        }
2206#endif
2207      }
2208      else // use reference to short-term reference picture set in PPS
2209      {
2210        Int numBits = 0;
2211        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
2212        {
2213          numBits++;
2214        }
2215        if (numBits > 0)
2216        {
2217          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
2218        }
2219        else
2220        {
2221          uiCode = 0;
2222        }
2223        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
2224      }
2225      if(sps->getLongTermRefsPresent())
2226      {
2227        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
2228        UInt numOfLtrp = 0;
2229        UInt numLtrpInSPS = 0;
2230        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
2231        {
2232          READ_UVLC( uiCode, "num_long_term_sps");
2233          numLtrpInSPS = uiCode;
2234          numOfLtrp += numLtrpInSPS;
2235          rps->setNumberOfLongtermPictures(numOfLtrp);
2236        }
2237        Int bitsForLtrpInSPS = 0;
2238        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
2239        {
2240          bitsForLtrpInSPS++;
2241        }
2242        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
2243        numOfLtrp += uiCode;
2244        rps->setNumberOfLongtermPictures(numOfLtrp);
2245        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
2246        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
2247        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
2248        {
2249          Int pocLsbLt;
2250          if (k < numLtrpInSPS)
2251          {
2252            uiCode = 0;
2253            if (bitsForLtrpInSPS > 0)
2254            {
2255              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
2256            }
2257            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
2258
2259            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
2260            rps->setUsed(j,usedByCurrFromSPS);
2261          }
2262          else
2263          {
2264            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
2265            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2266          }
2267          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
2268          Bool mSBPresentFlag = uiCode ? true : false;
2269          if(mSBPresentFlag)                 
2270          {
2271            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
2272            Bool deltaFlag = false;
2273            //            First LTRP                               || First LTRP from SH
2274            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
2275            {
2276              deltaFlag = true;
2277            }
2278            if(deltaFlag)
2279            {
2280              deltaPocMSBCycleLT = uiCode;
2281            }
2282            else
2283            {
2284              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
2285            }
2286
2287            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
2288                                        - iPOClsb + pocLsbLt;
2289            rps->setPOC     (j, pocLTCurr); 
2290            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
2291            rps->setCheckLTMSBPresent(j,true); 
2292          }
2293          else
2294          {
2295            rps->setPOC     (j, pocLsbLt);
2296            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
2297            rps->setCheckLTMSBPresent(j,false); 
2298           
2299            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
2300            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
2301            {
2302              deltaPocMSBCycleLT = 0;
2303            }
2304          }
2305          prevDeltaMSB = deltaPocMSBCycleLT;
2306        }
2307        offset += rps->getNumberOfLongtermPictures();
2308        rps->setNumberOfPictures(offset);       
2309      } 
2310#if H_MV
2311      if ( !rps->getInterRPSPrediction( ) )
2312      { // check sum of NumPositivePics, NumNegativePics, num_long_term_sps and num_long_term_pics
2313        rps->checkMaxNumPics( 
2314          vps->getVpsExtensionFlag(), 
2315            MAX_INT,  // To be replaced by MaxDbpsize
2316          rpcSlice->getLayerId(), 
2317          sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
2318      }
2319#endif
2320      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2321        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2322        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2323      {
2324        // In the case of BLA picture types, rps data is read from slice header but ignored
2325        rps = rpcSlice->getLocalRPS();
2326        rps->setNumberOfNegativePictures(0);
2327        rps->setNumberOfPositivePictures(0);
2328        rps->setNumberOfLongtermPictures(0);
2329        rps->setNumberOfPictures(0);
2330        rpcSlice->setRPS(rps);
2331      }
2332      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
2333      {
2334#if H_MV
2335        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
2336#else
2337        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
2338#endif
2339        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
2340      }
2341      else
2342      {
2343        rpcSlice->setEnableTMVPFlag(false);
2344      }
2345    }
2346#if H_MV
2347    Bool interLayerPredLayerIdcPresentFlag = false; 
2348    Int layerId       = rpcSlice->getLayerId(); 
2349    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
2350    {   
2351      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
2352      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
2353      {           
2354        if( !vps->getMaxOneActiveRefLayerFlag()) 
2355        {
2356          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
2357        }
2358        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
2359        {
2360          interLayerPredLayerIdcPresentFlag = true; 
2361          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
2362          {
2363            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
2364          }
2365        }
2366      } 
2367    }
2368    if ( !interLayerPredLayerIdcPresentFlag )
2369    {
2370      for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
2371      {
2372        rpcSlice->setInterLayerPredLayerIdc( i, rpcSlice->getRefLayerPicIdc( i ) );
2373      }
2374    }
2375#endif
2376    if(sps->getUseSAO())
2377    {
2378      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2379      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
2380    }
2381
2382    if (rpcSlice->getIdrPicFlag())
2383    {
2384      rpcSlice->setEnableTMVPFlag(false);
2385    }
2386    if (!rpcSlice->isIntra())
2387    {
2388
2389      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2390      if (uiCode)
2391      {
2392        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2393        if (rpcSlice->isInterB())
2394        {
2395          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2396        }
2397        else
2398        {
2399          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2400        }
2401      }
2402      else
2403      {
2404        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
2405        if (rpcSlice->isInterB())
2406        {
2407          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
2408        }
2409        else
2410        {
2411          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
2412        }
2413      }
2414    }
2415    // }
2416    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2417    if(!rpcSlice->isIntra())
2418    {
2419      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2420      {
2421        refPicListModification->setRefPicListModificationFlagL0( 0 );
2422      }
2423      else
2424      {
2425        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2426      }
2427
2428      if(refPicListModification->getRefPicListModificationFlagL0())
2429      { 
2430        uiCode = 0;
2431        Int i = 0;
2432        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
2433        if ( numRpsCurrTempList0 > 1 )
2434        {
2435          Int length = 1;
2436          numRpsCurrTempList0 --;
2437          while ( numRpsCurrTempList0 >>= 1) 
2438          {
2439            length ++;
2440          }
2441          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2442          {
2443            READ_CODE( length, uiCode, "list_entry_l0" );
2444            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2445          }
2446        }
2447        else
2448        {
2449          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2450          {
2451            refPicListModification->setRefPicSetIdxL0(i, 0 );
2452          }
2453        }
2454      }
2455    }
2456    else
2457    {
2458      refPicListModification->setRefPicListModificationFlagL0(0);
2459    }
2460    if(rpcSlice->isInterB())
2461    {
2462      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2463      {
2464        refPicListModification->setRefPicListModificationFlagL1( 0 );
2465      }
2466      else
2467      {
2468        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
2469      }
2470      if(refPicListModification->getRefPicListModificationFlagL1())
2471      {
2472        uiCode = 0;
2473        Int i = 0;
2474        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
2475        if ( numRpsCurrTempList1 > 1 )
2476        {
2477          Int length = 1;
2478          numRpsCurrTempList1 --;
2479          while ( numRpsCurrTempList1 >>= 1) 
2480          {
2481            length ++;
2482          }
2483          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2484          {
2485            READ_CODE( length, uiCode, "list_entry_l1" );
2486            refPicListModification->setRefPicSetIdxL1(i, uiCode );
2487          }
2488        }
2489        else
2490        {
2491          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2492          {
2493            refPicListModification->setRefPicSetIdxL1(i, 0 );
2494          }
2495        }
2496      }
2497    } 
2498    else
2499    {
2500      refPicListModification->setRefPicListModificationFlagL1(0);
2501    }
2502    if (rpcSlice->isInterB())
2503    {
2504      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
2505    }
2506
2507    rpcSlice->setCabacInitFlag( false ); // default
2508    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
2509    {
2510      READ_FLAG(uiCode, "cabac_init_flag");
2511      rpcSlice->setCabacInitFlag( uiCode ? true : false );
2512    }
2513
2514    if ( rpcSlice->getEnableTMVPFlag() )
2515    {
2516      if ( rpcSlice->getSliceType() == B_SLICE )
2517      {
2518        READ_FLAG( uiCode, "collocated_from_l0_flag" );
2519        rpcSlice->setColFromL0Flag(uiCode);
2520      }
2521      else
2522      {
2523        rpcSlice->setColFromL0Flag( 1 );
2524      }
2525
2526      if ( rpcSlice->getSliceType() != I_SLICE &&
2527          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
2528           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
2529      {
2530        READ_UVLC( uiCode, "collocated_ref_idx" );
2531        rpcSlice->setColRefIdx(uiCode);
2532      }
2533      else
2534      {
2535        rpcSlice->setColRefIdx(0);
2536      }
2537    }
2538    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
2539    {
2540      xParsePredWeightTable(rpcSlice);
2541      rpcSlice->initWpScaling();
2542    }
2543#if H_3D_IC
2544    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) && !rpcSlice->getIsDepth() && vps->getNumDirectRefLayers( layerId ) > 0 )
2545    {
2546      UInt uiCodeTmp = 0;
2547
2548      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
2549      rpcSlice->setApplyIC( uiCodeTmp );
2550
2551      if ( uiCodeTmp )
2552      {
2553        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
2554        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
2555      }
2556    }
2557#endif
2558#if H_3D_SINGLE_DEPTH
2559    if(rpcSlice->getIsDepth())
2560    {
2561      UInt uiCodeTmp = 0;
2562      READ_FLAG( uiCodeTmp, "slice_enable_single_depth_mode" );
2563      rpcSlice->setApplySingleDepthMode(uiCodeTmp);
2564    }
2565#endif
2566    if (!rpcSlice->isIntra())
2567    {
2568      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
2569#if H_3D_IV_MERGE
2570      if(rpcSlice->getIsDepth())
2571      {
2572        Bool bMPIFlag = rpcSlice->getVPS()->getMPIFlag( rpcSlice->getLayerIdInVps() ) ;
2573        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2574        rpcSlice->setMaxNumMergeCand(( ( bMPIFlag || ivMvPredFlag ) ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2575      }
2576      else
2577      {
2578        Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
2579        rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
2580      }
2581
2582#else
2583      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
2584#endif
2585    }
2586
2587    READ_SVLC( iCode, "slice_qp_delta" );
2588    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
2589
2590    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
2591    assert( rpcSlice->getSliceQp() <=  51 );
2592
2593    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
2594    {
2595      READ_SVLC( iCode, "slice_qp_delta_cb" );
2596      rpcSlice->setSliceQpDeltaCb( iCode );
2597      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
2598      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
2599      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
2600      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
2601
2602      READ_SVLC( iCode, "slice_qp_delta_cr" );
2603      rpcSlice->setSliceQpDeltaCr( iCode );
2604      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
2605      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
2606      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
2607      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
2608    }
2609
2610    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
2611    {
2612      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
2613      {
2614        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
2615      }
2616      else
2617      { 
2618        rpcSlice->setDeblockingFilterOverrideFlag(0);
2619      }
2620      if(rpcSlice->getDeblockingFilterOverrideFlag())
2621      {
2622        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
2623        if(!rpcSlice->getDeblockingFilterDisable())
2624        {
2625          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
2626          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
2627                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
2628          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
2629          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
2630                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
2631        }
2632      }
2633      else
2634      {
2635        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
2636        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
2637        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
2638      }
2639    }
2640    else
2641    { 
2642      rpcSlice->setDeblockingFilterDisable       ( false );
2643      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
2644      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
2645    }
2646
2647    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
2648    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
2649
2650    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
2651    {
2652      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
2653    }
2654    else
2655    {
2656      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
2657    }
2658    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
2659
2660  }
2661 
2662    UInt *entryPointOffset          = NULL;
2663    UInt numEntryPointOffsets, offsetLenMinus1;
2664  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2665  {
2666    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
2667    if (numEntryPointOffsets>0)
2668    {
2669      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2670    }
2671    entryPointOffset = new UInt[numEntryPointOffsets];
2672    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2673    {
2674      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
2675      entryPointOffset[ idx ] = uiCode + 1;
2676    }
2677  }
2678  else
2679  {
2680    rpcSlice->setNumEntryPointOffsets ( 0 );
2681  }
2682
2683#if H_3D
2684#if H_3D_FCO
2685  if( rpcSlice->getVPS()->hasCamParInSliceHeader( rpcSlice->getViewIndex() )  && rpcSlice->getIsDepth() )
2686#else
2687  if( rpcSlice->getVPS()->hasCamParInSliceHeader( rpcSlice->getViewIndex() )  && !rpcSlice->getIsDepth() )
2688#endif
2689  {
2690    UInt uiViewIndex = rpcSlice->getViewIndex();
2691    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
2692    {
2693      READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
2694      READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
2695      READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
2696      READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
2697    }
2698    rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
2699  }
2700#endif
2701
2702  if(pps->getSliceHeaderExtensionPresentFlag())
2703  {
2704#if H_MV
2705    READ_UVLC( uiCode, "slice_segment_header_extension_length" ); rpcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
2706    UInt posFollSliceSegHeaderExtLen = m_pcBitstream->getNumBitsRead();
2707
2708    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
2709    {
2710      READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
2711    }
2712    else
2713    {
2714      rpcSlice->setPocResetIdc( 0 );
2715    }
2716    rpcSlice->checkPocResetIdc(); 
2717
2718    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && slicePicOrderCntLsb > 0 )
2719    {
2720      assert( rpcSlice->getPocResetIdc() != 2 );
2721    }
2722
2723    if( rpcSlice->getPocResetIdc() !=  0 )
2724    {
2725      READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
2726    }
2727    else
2728    {
2729      // TODO Copy poc_reset_period from earlier picture
2730      rpcSlice->setPocResetPeriodId( 0 );
2731    }
2732   
2733    if( rpcSlice->getPocResetIdc() ==  3 ) 
2734    {
2735      READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
2736      READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
2737    }         
2738    rpcSlice->checkPocLsbVal(); 
2739
2740    // Derive the value of PocMs8bValRequiredFlag
2741    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
2742                                          /* || TODO related to vps_poc_lsb_aligned_flag */
2743                                          );
2744
2745    if( !rpcSlice->getPocMsbValRequiredFlag() /* TODO &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
2746    {
2747      READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
2748    }
2749    else
2750    {
2751      rpcSlice->setPocMsbValPresentFlag( rpcSlice->inferPocMsbValPresentFlag( ) ); 
2752    }
2753
2754   
2755    if( rpcSlice->getPocMsbValPresentFlag() )
2756    {
2757      READ_UVLC( uiCode, "poc_msb_val" ); rpcSlice->setPocMsbVal( uiCode );
2758    }
2759
2760    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
2761    {
2762     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
2763    }
2764    assert( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  ); 
2765#else
2766    READ_UVLC( uiCode, "slice_header_extension_length" );
2767    for(Int i=0; i<uiCode; i++)
2768    {
2769      UInt ignore;
2770      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2771    } 
2772  }
2773  else
2774  {
2775    rpcSlice->setSliceSegmentHeaderExtensionLength( 0 );
2776    rpcSlice->setPocMsbValPresentFlag( false );
2777  }
2778#endif
2779  m_pcBitstream->readByteAlignment();
2780
2781  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2782  {
2783    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2784   
2785    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2786    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2787    {
2788      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2789      {
2790        endOfSliceHeaderLocation++;
2791      }
2792    }
2793
2794    Int  curEntryPointOffset     = 0;
2795    Int  prevEntryPointOffset    = 0;
2796    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2797    {
2798      curEntryPointOffset += entryPointOffset[ idx ];
2799
2800      Int emulationPreventionByteCount = 0;
2801      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2802      {
2803        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
2804             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2805        {
2806          emulationPreventionByteCount++;
2807        }
2808      }
2809
2810      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2811      prevEntryPointOffset = curEntryPointOffset;
2812    }
2813
2814    if ( pps->getTilesEnabledFlag() )
2815    {
2816      rpcSlice->setTileLocationCount( numEntryPointOffsets );
2817
2818      UInt prevPos = 0;
2819      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2820      {
2821        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2822        prevPos += entryPointOffset[ idx ];
2823      }
2824    }
2825    else if ( pps->getEntropyCodingSyncEnabledFlag() )
2826    {
2827    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
2828      rpcSlice->allocSubstreamSizes(numSubstreams);
2829      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2830      for (Int idx=0; idx<numSubstreams-1; idx++)
2831      {
2832        if ( idx < numEntryPointOffsets )
2833        {
2834          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2835        }
2836        else
2837        {
2838          pSubstreamSizes[ idx ] = 0;
2839        }
2840      }
2841    }
2842
2843    if (entryPointOffset)
2844    {
2845      delete [] entryPointOffset;
2846    }
2847  }
2848
2849  return;
2850}
2851 
2852Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2853{
2854  UInt uiCode;
2855  if(profilePresentFlag)
2856  {
2857    parseProfileTier(rpcPTL->getGeneralPTL());
2858  }
2859  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
2860
2861  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2862  {
2863#if !H_MV
2864    if(profilePresentFlag)
2865    {
2866#endif
2867      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2868#if H_MV
2869      // When profilePresentFlag is equal to 0, sub_layer_profile_present_flag[ i ] shall be equal to 0.
2870      assert( profilePresentFlag || !rpcPTL->getSubLayerProfilePresentFlag(i) );
2871#else
2872    }
2873#endif
2874    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2875  }
2876 
2877  if (maxNumSubLayersMinus1 > 0)
2878  {
2879    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2880    {
2881      READ_CODE(2, uiCode, "reserved_zero_2bits");
2882      assert(uiCode == 0);
2883    }
2884  }
2885 
2886  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2887  {
2888#if H_MV
2889    if( rpcPTL->getSubLayerProfilePresentFlag(i) )         
2890#else
2891    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )         
2892#endif
2893    {
2894      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2895    }
2896    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2897    {
2898      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
2899    }
2900  }
2901}
2902
2903Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2904{
2905  UInt uiCode;
2906  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2907  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
2908  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
2909  for(Int j = 0; j < 32; j++)
2910  {
2911    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2912  }
2913  READ_FLAG(uiCode, "general_progressive_source_flag");
2914  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2915
2916  READ_FLAG(uiCode, "general_interlaced_source_flag");
2917  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2918 
2919  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2920  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2921 
2922  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2923  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2924 
2925#if H_MV
2926  if( ptl->getV2ConstraintsPresentFlag() )
2927  {
2928    READ_FLAG( uiCode, "max_12bit_constraint_flag" );        ptl->setMax12bitConstraintFlag      ( uiCode == 1 );
2929    READ_FLAG( uiCode, "max_10bit_constraint_flag" );        ptl->setMax10bitConstraintFlag      ( uiCode == 1 );
2930    READ_FLAG( uiCode, "max_8bit_constraint_flag" );         ptl->setMax8bitConstraintFlag       ( uiCode == 1 );
2931    READ_FLAG( uiCode, "max_422chroma_constraint_flag" );    ptl->setMax422chromaConstraintFlag  ( uiCode == 1 );
2932    READ_FLAG( uiCode, "max_420chroma_constraint_flag" );    ptl->setMax420chromaConstraintFlag  ( uiCode == 1 );
2933    READ_FLAG( uiCode, "max_monochrome_constraint_flag" );   ptl->setMaxMonochromeConstraintFlag ( uiCode == 1 );
2934    READ_FLAG( uiCode, "intra_constraint_flag" );            ptl->setIntraConstraintFlag         ( uiCode == 1 );
2935    READ_FLAG( uiCode, "one_picture_only_constraint_flag" ); ptl->setOnePictureOnlyConstraintFlag( uiCode == 1 );
2936    READ_FLAG( uiCode, "lower_bit_rate_constraint_flag" );   ptl->setLowerBitRateConstraintFlag  ( uiCode == 1 );   
2937    READ_CODE(16, uiCode, "XXX_reserved_zero_34bits[0..15]");
2938    READ_CODE(16, uiCode, "XXX_reserved_zero_34bits[16..31]");
2939    READ_CODE(2 , uiCode, "XXX_reserved_zero_34bits[32..33]");
2940  }
2941  else
2942  {
2943    READ_CODE(16, uiCode, "XXX_reserved_zero_43bits[0..15]");
2944    READ_CODE(16, uiCode, "XXX_reserved_zero_43bits[16..31]");
2945    READ_CODE(11, uiCode, "XXX_reserved_zero_43bits[32..42]");
2946  }
2947  if( ptl->getInbldPresentFlag() )
2948  {
2949    READ_FLAG( uiCode, "inbld_flag" ); ptl->setInbldFlag( uiCode == 1 );
2950  }
2951  else
2952  {
2953    READ_FLAG(uiCode, "reserved_zero_bit");
2954  }
2955#else
2956  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2957  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2958  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2959#endif
2960}
2961
2962Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2963{
2964  ruiBit = false;
2965  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2966  if(iBitsLeft <= 8)
2967  {
2968    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2969    if (uiPeekValue == (1<<(iBitsLeft-1)))
2970    {
2971      ruiBit = true;
2972    }
2973  }
2974}
2975
2976Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2977{
2978  assert(0);
2979}
2980#if H_3D_SINGLE_DEPTH
2981Void TDecCavlc::parseSingleDepthMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2982{
2983  assert(0);
2984}
2985#endif
2986Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2987{
2988  assert(0);
2989}
2990
2991Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2992{
2993  assert(0);
2994}
2995
2996Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2997{
2998  assert(0);
2999}
3000
3001Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3002{
3003  assert(0);
3004}
3005
3006Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3007{
3008  assert(0);
3009}
3010
3011/** Parse I_PCM information.
3012* \param pcCU pointer to CU
3013* \param uiAbsPartIdx CU index
3014* \param uiDepth CU depth
3015* \returns Void
3016*
3017* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
3018*/
3019Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3020{
3021  assert(0);
3022}
3023
3024Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3025{ 
3026  assert(0);
3027}
3028
3029Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3030{
3031  assert(0);
3032}
3033
3034Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
3035{
3036  assert(0);
3037}
3038
3039Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
3040{
3041  assert(0);
3042}
3043
3044Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
3045{
3046  assert(0);
3047}
3048
3049Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3050{
3051  Int qp;
3052  Int  iDQp;
3053
3054  xReadSvlc( iDQp );
3055
3056  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
3057  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
3058
3059  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
3060  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
3061
3062  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
3063}
3064
3065Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
3066{
3067  assert(0);
3068}
3069
3070Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
3071{
3072  assert(0);
3073}
3074
3075Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
3076{
3077  assert(0);
3078}
3079
3080Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
3081{
3082  assert(0);
3083}
3084
3085Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
3086{
3087  assert(0);
3088}
3089
3090Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
3091{
3092  assert(0);
3093}
3094
3095Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
3096{
3097  assert(0);
3098}
3099
3100#if H_3D_ARP
3101Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3102{
3103  assert(0);
3104}
3105#endif
3106#if H_3D_IC
3107Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3108{
3109  assert(0);
3110}
3111#endif
3112#if H_3D_INTER_SDC
3113Void TDecCavlc::parseDeltaDC( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3114{ 
3115  assert(0);
3116}
3117
3118Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3119{
3120  assert(0);
3121}
3122
3123#endif
3124#if H_3D_DBBP
3125  Void TDecCavlc::parseDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3126  {
3127    assert(0);
3128  }
3129#endif
3130// ====================================================================================================================
3131// Protected member functions
3132// ====================================================================================================================
3133
3134/** parse explicit wp tables
3135* \param TComSlice* pcSlice
3136* \returns Void
3137*/
3138Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
3139{
3140  wpScalingParam  *wp;
3141  Bool            bChroma     = true; // color always present in HEVC ?
3142  SliceType       eSliceType  = pcSlice->getSliceType();
3143  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
3144  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
3145  UInt            uiTotalSignalledWeightFlags = 0;
3146 
3147  Int iDeltaDenom;
3148  // decode delta_luma_log2_weight_denom :
3149  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3150  assert( uiLog2WeightDenomLuma <= 7 );
3151  if( bChroma ) 
3152  {
3153    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
3154    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3155    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
3156    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3157  }
3158
3159  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
3160  {
3161    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
3162    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3163    {
3164      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3165
3166      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3167      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3168      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3169
3170      UInt  uiCode;
3171      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
3172      wp[0].bPresentFlag = ( uiCode == 1 );
3173      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
3174    }
3175    if ( bChroma ) 
3176    {
3177      UInt  uiCode;
3178      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3179      {
3180        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3181        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
3182        wp[1].bPresentFlag = ( uiCode == 1 );
3183        wp[2].bPresentFlag = ( uiCode == 1 );
3184        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
3185      }
3186    }
3187    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3188    {
3189      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3190      if ( wp[0].bPresentFlag ) 
3191      {
3192        Int iDeltaWeight;
3193        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
3194        assert( iDeltaWeight >= -128 );
3195        assert( iDeltaWeight <=  127 );
3196        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3197        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
3198        assert( wp[0].iOffset >= -128 );
3199        assert( wp[0].iOffset <=  127 );
3200      }
3201      else 
3202      {
3203        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3204        wp[0].iOffset = 0;
3205      }
3206      if ( bChroma ) 
3207      {
3208        if ( wp[1].bPresentFlag ) 
3209        {
3210          for ( Int j=1 ; j<3 ; j++ ) 
3211          {
3212            Int iDeltaWeight;
3213            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3214            assert( iDeltaWeight >= -128 );
3215            assert( iDeltaWeight <=  127 );
3216            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3217
3218            Int iDeltaChroma;
3219            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3220            assert( iDeltaChroma >= -512 );
3221            assert( iDeltaChroma <=  511 );
3222            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
3223            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
3224          }
3225        }
3226        else 
3227        {
3228          for ( Int j=1 ; j<3 ; j++ ) 
3229          {
3230            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3231            wp[j].iOffset = 0;
3232          }
3233        }
3234      }
3235    }
3236
3237    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
3238    {
3239      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3240
3241      wp[0].bPresentFlag = false;
3242      wp[1].bPresentFlag = false;
3243      wp[2].bPresentFlag = false;
3244    }
3245  }
3246  assert(uiTotalSignalledWeightFlags<=24);
3247}
3248
3249/** decode quantization matrix
3250* \param scalingList quantization matrix information
3251*/
3252Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3253{
3254  UInt  code, sizeId, listId;
3255  Bool scalingListPredModeFlag;
3256  //for each size
3257  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3258  {
3259    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3260    {
3261      READ_FLAG( code, "scaling_list_pred_mode_flag");
3262      scalingListPredModeFlag = (code) ? true : false;
3263      if(!scalingListPredModeFlag) //Copy Mode
3264      {
3265        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3266        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
3267        if( sizeId > SCALING_LIST_8x8 )
3268        {
3269          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
3270        }
3271        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3272
3273      }
3274      else //DPCM Mode
3275      {
3276        xDecodeScalingList(scalingList, sizeId, listId);
3277      }
3278    }
3279  }
3280
3281  return;
3282}
3283/** decode DPCM
3284* \param scalingList  quantization matrix information
3285* \param sizeId size index
3286* \param listId list index
3287*/
3288Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3289{
3290  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3291  Int data;
3292  Int scalingListDcCoefMinus8 = 0;
3293  Int nextCoef = SCALING_LIST_START_VALUE;
3294  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
3295  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3296
3297  if( sizeId > SCALING_LIST_8x8 )
3298  {
3299    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3300    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3301    nextCoef = scalingList->getScalingListDC(sizeId,listId);
3302  }
3303
3304  for(i = 0; i < coefNum; i++)
3305  {
3306    READ_SVLC( data, "scaling_list_delta_coef");
3307    nextCoef = (nextCoef + data + 256 ) % 256;
3308    dst[scan[i]] = nextCoef;
3309  }
3310}
3311
3312Bool TDecCavlc::xMoreRbspData()
3313{ 
3314  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3315
3316  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3317  if (bitsLeft > 8)
3318  {
3319    return true;
3320  }
3321
3322  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3323  Int cnt = bitsLeft;
3324
3325  // remove trailing bits equal to zero
3326  while ((cnt>0) && ((lastByte & 1) == 0))
3327  {
3328    lastByte >>= 1;
3329    cnt--;
3330  }
3331  // remove bit equal to one
3332  cnt--;
3333
3334  // we should not have a negative number of bits
3335  assert (cnt>=0);
3336
3337  // we have more data, if cnt is not zero
3338  return (cnt>0);
3339}
3340
3341//! \}
3342
Note: See TracBrowser for help on using the repository browser.