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

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