source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1313

Last change on this file since 1313 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

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