source: 3DVCSoftware/branches/HTM-14.1-update-dev1-RWTH/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1243

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