source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 1089

Last change on this file since 1089 was 1086, checked in by seregin, 11 years ago

fix layerIdc derivation for OLS index

  • Property svn:eol-style set to native
File size: 172.5 KB
Line 
1/* The copyright in this software is being made available under the BSD
2* License, included below. This software may be subject to other third party
3* and contributor rights, including patent rights, and no such rights are
4* granted under this license.
5*
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7* All rights reserved.
8*
9* Redistribution and use in source and binary forms, with or without
10* modification, are permitted provided that the following conditions are met:
11*
12*  * Redistributions of source code must retain the above copyright notice,
13*    this list of conditions and the following disclaimer.
14*  * Redistributions in binary form must reproduce the above copyright notice,
15*    this list of conditions and the following disclaimer in the documentation
16*    and/or other materials provided with the distribution.
17*  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18*    be used to endorse or promote products derived from this software without
19*    specific prior written permission.
20*
21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31* THE POSSIBILITY OF SUCH DAMAGE.
32*/
33
34/** \file     TDecCAVLC.cpp
35\brief    CAVLC decoder class
36*/
37
38#include "TDecCAVLC.h"
39#include "SEIread.h"
40#include "TDecSlice.h"
41#include "TLibCommon/TComChromaFormat.h"
42#if RExt__DECODER_DEBUG_BIT_STATISTICS
43#include "TLibCommon/TComCodingStatistics.h"
44#endif
45#if Q0048_CGS_3D_ASYMLUT
46#include "../TLibCommon/TCom3DAsymLUT.h"
47#endif
48
49//! \ingroup TLibDecoder
50//! \{
51
52#if ENC_DEC_TRACE
53
54Void  xTraceSPSHeader (TComSPS *pSPS)
55{
56  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
57}
58
59Void  xTracePPSHeader (TComPPS *pPPS)
60{
61  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
62}
63
64Void  xTraceSliceHeader (TComSlice *pSlice)
65{
66  fprintf( g_hTrace, "=========== Slice ===========\n");
67}
68
69#endif
70
71// ====================================================================================================================
72// Constructor / destructor / create / destroy
73// ====================================================================================================================
74
75TDecCavlc::TDecCavlc()
76{
77}
78
79TDecCavlc::~TDecCavlc()
80{
81
82}
83
84// ====================================================================================================================
85// Public member functions
86// ====================================================================================================================
87
88Void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
89{
90  UInt code;
91  UInt interRPSPred;
92  if (idx > 0)
93  {
94    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
95  }
96  else
97  {
98    interRPSPred = false;
99    rps->setInterRPSPrediction(false);
100  }
101
102  if (interRPSPred)
103  {
104    UInt bit;
105    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
106    {
107      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
108    }
109    else
110    {
111      code = 0;
112    }
113    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
114    Int rIdx =  idx - 1 - code;
115    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
116    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
117    Int k = 0, k0 = 0, k1 = 0;
118    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
119    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
120    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
121    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
122    {
123      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
124      Int refIdc = bit;
125      if (refIdc == 0)
126      {
127        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
128        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
129      }
130      if (refIdc == 1 || refIdc == 2)
131      {
132        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
133        rps->setDeltaPOC(k, deltaPOC);
134        rps->setUsed(k, (refIdc == 1));
135
136        if (deltaPOC < 0)
137        {
138          k0++;
139        }
140        else
141        {
142          k1++;
143        }
144        k++;
145      }
146      rps->setRefIdc(j,refIdc);
147    }
148    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);
149    rps->setNumberOfPictures(k);
150    rps->setNumberOfNegativePictures(k0);
151    rps->setNumberOfPositivePictures(k1);
152    rps->sortDeltaPOC();
153  }
154  else
155  {
156    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
157    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
158    Int prev = 0;
159    Int poc;
160    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
161    {
162      READ_UVLC(code, "delta_poc_s0_minus1");
163      poc = prev-code-1;
164      prev = poc;
165      rps->setDeltaPOC(j,poc);
166      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
167    }
168    prev = 0;
169    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
170    {
171      READ_UVLC(code, "delta_poc_s1_minus1");
172      poc = prev+code+1;
173      prev = poc;
174      rps->setDeltaPOC(j,poc);
175      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
176    }
177    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
178  }
179#if PRINT_RPS_INFO
180  rps->printDeltaPOC();
181#endif
182}
183
184#if Q0048_CGS_3D_ASYMLUT
185Void TDecCavlc::parsePPS(TComPPS* pcPPS, TCom3DAsymLUT * pc3DAsymLUT, Int nLayerID)
186#else
187Void TDecCavlc::parsePPS(TComPPS* pcPPS)
188#endif
189
190{
191#if ENC_DEC_TRACE
192  xTracePPSHeader (pcPPS);
193#endif
194  UInt  uiCode;
195
196  Int   iCode;
197
198  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
199  assert(uiCode <= 63);
200  pcPPS->setPPSId (uiCode);
201
202  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
203  assert(uiCode <= 15);
204  pcPPS->setSPSId (uiCode);
205
206  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
207
208  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
209
210  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
211
212  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
213
214  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
215
216  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
217  assert(uiCode <= 14);
218  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
219
220  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
221  assert(uiCode <= 14);
222  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
223
224  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
225  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
226  READ_FLAG( uiCode, "transform_skip_enabled_flag" );
227  pcPPS->setUseTransformSkip ( uiCode ? true : false );
228
229  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
230  if( pcPPS->getUseDQP() )
231  {
232    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
233    pcPPS->setMaxCuDQPDepth( uiCode );
234  }
235  else
236  {
237    pcPPS->setMaxCuDQPDepth( 0 );
238  }
239  READ_SVLC( iCode, "pps_cb_qp_offset");
240  pcPPS->setQpOffset(COMPONENT_Cb, iCode);
241  assert( pcPPS->getQpOffset(COMPONENT_Cb) >= -12 );
242  assert( pcPPS->getQpOffset(COMPONENT_Cb) <=  12 );
243
244  READ_SVLC( iCode, "pps_cr_qp_offset");
245  pcPPS->setQpOffset(COMPONENT_Cr, iCode);
246  assert( pcPPS->getQpOffset(COMPONENT_Cr) >= -12 );
247  assert( pcPPS->getQpOffset(COMPONENT_Cr) <=  12 );
248
249  assert(MAX_NUM_COMPONENT<=3);
250
251  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
252  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
253
254  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
255  pcPPS->setUseWP( uiCode==1 );
256  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
257  pcPPS->setWPBiPred( uiCode==1 );
258
259  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
260  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
261  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
262  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
263
264  if( pcPPS->getTilesEnabledFlag() )
265  {
266    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumTileColumnsMinus1( uiCode ); 
267    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumTileRowsMinus1( uiCode ); 
268    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setTileUniformSpacingFlag( uiCode == 1 );
269
270    const UInt tileColumnsMinus1 = pcPPS->getNumTileColumnsMinus1();
271    const UInt tileRowsMinus1    = pcPPS->getNumTileRowsMinus1();
272 
273    if ( !pcPPS->getTileUniformSpacingFlag())
274    {
275      if (tileColumnsMinus1 > 0)
276      {
277        std::vector<Int> columnWidth(tileColumnsMinus1);
278        for(UInt i = 0; i < tileColumnsMinus1; i++)
279        { 
280          READ_UVLC( uiCode, "column_width_minus1" ); 
281          columnWidth[i] = uiCode+1;
282        }
283        pcPPS->setTileColumnWidth(columnWidth);
284      }
285
286      if (tileRowsMinus1 > 0)
287      {
288        std::vector<Int> rowHeight (tileRowsMinus1);
289        for(UInt i = 0; i < tileRowsMinus1; i++)
290        {
291          READ_UVLC( uiCode, "row_height_minus1" );
292          rowHeight[i] = uiCode + 1;
293        }
294        pcPPS->setTileRowHeight(rowHeight);
295      }
296    }
297
298    if ((tileColumnsMinus1 + tileRowsMinus1) != 0)
299    {
300      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
301    }
302  }
303  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
304  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
305  if(pcPPS->getDeblockingFilterControlPresentFlag())
306  {
307    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
308    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
309    if(!pcPPS->getPicDisableDeblockingFilterFlag())
310    {
311      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
312      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
313    }
314  }
315  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
316  if(pcPPS->getScalingListPresentFlag ())
317  {
318    parseScalingList( pcPPS->getScalingList() );
319  }
320
321  READ_FLAG( uiCode, "lists_modification_present_flag");
322  pcPPS->setListsModificationPresentFlag(uiCode);
323
324  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
325  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
326
327  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
328  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
329
330  READ_FLAG( uiCode, "pps_extension_present_flag");
331
332#if SVC_EXTENSION
333  pcPPS->setExtensionFlag( uiCode ? true : false );
334  if( pcPPS->getExtensionFlag() )
335#else
336  if (uiCode)
337#endif
338  {
339    Bool pps_extension_flags[NUM_PPS_EXTENSION_FLAGS];
340    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++)
341    {
342      READ_FLAG( uiCode, "pps_extension_flag[]" );
343      pps_extension_flags[i] = uiCode!=0;
344    }
345
346    Bool bSkipTrailingExtensionBits=false;
347    for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
348    {
349      if (pps_extension_flags[i])
350      {
351        switch (PPSExtensionFlagIndex(i))
352        {
353          case PPS_EXT__REXT:
354            assert(!bSkipTrailingExtensionBits);
355
356            if (pcPPS->getUseTransformSkip())
357            {
358              READ_UVLC( uiCode, "log2_transform_skip_max_size_minus2");
359              pcPPS->setTransformSkipLog2MaxSize(uiCode+2);
360            }
361
362            READ_FLAG( uiCode, "cross_component_prediction_flag");
363            pcPPS->setUseCrossComponentPrediction(uiCode != 0);
364
365            READ_FLAG( uiCode, "chroma_qp_adjustment_enabled_flag");
366            if (uiCode == 0)
367            {
368              pcPPS->clearChromaQpAdjTable();
369              pcPPS->setMaxCuChromaQpAdjDepth(0);
370            }
371            else
372            {
373              READ_UVLC(uiCode, "diff_cu_chroma_qp_adjustment_depth"); pcPPS->setMaxCuChromaQpAdjDepth(uiCode);
374              UInt tableSizeMinus1 = 0;
375              READ_UVLC(tableSizeMinus1, "chroma_qp_adjustment_table_size_minus1");
376              /* skip zero index */
377              for (Int chromaQpAdjustmentIndex = 1; chromaQpAdjustmentIndex <= (tableSizeMinus1 + 1); chromaQpAdjustmentIndex++)
378              {
379                Int cbOffset;
380                Int crOffset;
381                READ_SVLC(cbOffset, "cb_qp_adjustnemt[i]");
382                READ_SVLC(crOffset, "cr_qp_adjustnemt[i]");
383                pcPPS->setChromaQpAdjTableAt(chromaQpAdjustmentIndex, cbOffset, crOffset);
384              }
385              assert(pcPPS->getChromaQpAdjTableSize() == tableSizeMinus1 + 1);
386            }
387
388            READ_UVLC( uiCode, "sao_luma_bit_shift");
389            pcPPS->setSaoOffsetBitShift(CHANNEL_TYPE_LUMA, uiCode);
390            READ_UVLC( uiCode, "sao_chroma_bit_shift");
391            pcPPS->setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, uiCode);
392            break;
393
394#if SVC_EXTENSION
395          case PPS_EXT__MLAYER:
396            READ_FLAG( uiCode, "poc_reset_info_present_flag" );
397            pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
398
399#if SCALINGLIST_INFERRING
400            READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
401            pcPPS->setInferScalingListFlag( uiCode );
402
403            if( pcPPS->getInferScalingListFlag() )
404            {
405              READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); 
406              pcPPS->setScalingListRefLayerId( uiCode );
407              // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
408              assert( pcPPS->getScalingListRefLayerId() <= 62 );
409              pcPPS->setScalingListPresentFlag( false );
410            }
411#endif
412
413#if REF_REGION_OFFSET
414            READ_UVLC( uiCode,      "num_ref_loc_offsets" ); pcPPS->setNumRefLayerLocationOffsets(uiCode);
415            for(Int k = 0; k < pcPPS->getNumRefLayerLocationOffsets(); k++)
416            {
417              READ_CODE( 6, uiCode,  "ref_loc_offset_layer_id" );  pcPPS->setRefLocationOffsetLayerId( k, uiCode );
418              READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( k, uiCode );
419              if (uiCode)
420              {
421                Window& scaledWindow = pcPPS->getScaledRefLayerWindow(k);
422                READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
423                READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
424                READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
425                READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
426#if P0312_VERT_PHASE_ADJ
427                READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
428#endif
429              }
430              READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( k, uiCode );
431              if (uiCode)
432              {
433                Window& refWindow = pcPPS->getRefLayerWindow(k);
434                READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
435                READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
436                READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
437                READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
438              }
439#if R0209_GENERIC_PHASE
440              READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( k, uiCode );
441              if (uiCode)
442              {
443                READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( k, uiCode );
444                READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( k, uiCode );
445                READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (k, uiCode - 8);
446                READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (k, uiCode - 8);
447              }
448#endif
449            }
450#else
451#if MOVE_SCALED_OFFSET_TO_PPS
452            READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
453            for(Int k = 0; k < pcPPS->getNumScaledRefLayerOffsets(); k++)
454            {
455              Window& scaledWindow = pcPPS->getScaledRefLayerWindow(k);
456#if O0098_SCALED_REF_LAYER_ID
457              READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( k, uiCode );
458#endif
459              READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
460              READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
461              READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
462              READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
463#if P0312_VERT_PHASE_ADJ
464              READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(k), uiCode);
465#endif
466            }
467#endif
468#endif
469#if Q0048_CGS_3D_ASYMLUT
470            READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
471            pcPPS->setCGSFlag( uiCode );
472            if( pcPPS->getCGSFlag() )
473            {
474#if R0157_RESTRICT_PPSID_FOR_CGS_LUT
475              // when pps_pic_parameter_set_id greater than or equal to 8, colour_mapping_enabled_flag shall be equal to 0
476              assert( pcPPS->getPPSId() < 8 );
477#endif
478              xParse3DAsymLUT( pc3DAsymLUT );
479              pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
480              pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
481            }
482#endif
483            break;
484#endif
485          default:
486            bSkipTrailingExtensionBits=true;
487            break;
488        }
489      }
490    }
491    if (bSkipTrailingExtensionBits)
492    {
493      while ( xMoreRbspData() )
494      {
495        READ_FLAG( uiCode, "pps_extension_data_flag");
496      }
497    }
498  }
499}
500
501Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
502{
503#if ENC_DEC_TRACE
504  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
505#endif
506  UInt  uiCode;
507
508  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
509  if (pcVUI->getAspectRatioInfoPresentFlag())
510  {
511    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
512    if (pcVUI->getAspectRatioIdc() == 255)
513    {
514      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
515      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
516    }
517  }
518
519  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
520  if (pcVUI->getOverscanInfoPresentFlag())
521  {
522    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
523  }
524
525  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
526  if (pcVUI->getVideoSignalTypePresentFlag())
527  {
528    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
529    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
530    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
531    if (pcVUI->getColourDescriptionPresentFlag())
532    {
533      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
534      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
535      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
536    }
537  }
538
539  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
540  if (pcVUI->getChromaLocInfoPresentFlag())
541  {
542    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
543    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
544  }
545
546  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
547
548  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
549
550  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
551
552  READ_FLAG(     uiCode, "default_display_window_flag");
553  if (uiCode != 0)
554  {
555    Window &defDisp = pcVUI->getDefaultDisplayWindow();
556    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
557    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
558    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
559    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
560  }
561
562  TimingInfo *timingInfo = pcVUI->getTimingInfo();
563  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
564#if SVC_EXTENSION
565  if( pcSPS->getLayerId() > 0 )
566  {
567    assert( timingInfo->getTimingInfoPresentFlag() == false );
568  }
569#endif
570  if(timingInfo->getTimingInfoPresentFlag())
571  {
572    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
573    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
574    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
575    if(timingInfo->getPocProportionalToTimingFlag())
576    {
577      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
578    }
579
580    READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
581    if( pcVUI->getHrdParametersPresentFlag() )
582    {
583      parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
584    }
585  }
586
587  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
588  if (pcVUI->getBitstreamRestrictionFlag())
589  {
590    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
591    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
592    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
593    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
594    assert(uiCode < 4096);
595    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
596    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
597    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
598    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
599  }
600}
601
602Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
603{
604  UInt  uiCode;
605  if( commonInfPresentFlag )
606  {
607    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
608    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
609    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
610    {
611      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
612      if( hrd->getSubPicCpbParamsPresentFlag() )
613      {
614        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
615        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
616        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
617        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
618      }
619      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
620      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
621      if( hrd->getSubPicCpbParamsPresentFlag() )
622      {
623        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
624      }
625      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
626      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
627      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
628    }
629#if VPS_VUI_BSP_HRD_PARAMS
630    else
631    {
632      hrd->setInitialCpbRemovalDelayLengthMinus1( 23 );
633      // Add inferred values for other syntax elements here.
634    }
635#endif
636  }
637  Int i, j, nalOrVcl;
638  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
639  {
640    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
641    if( !hrd->getFixedPicRateFlag( i ) )
642    {
643      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
644    }
645    else
646    {
647      hrd->setFixedPicRateWithinCvsFlag( i, true );
648    }
649
650    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
651    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
652
653    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
654    {
655      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
656    }
657    else
658    {
659      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
660    }
661    if (!hrd->getLowDelayHrdFlag( i ))
662    {
663      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
664    }
665
666    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
667    {
668      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
669          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
670      {
671        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
672        {
673          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
674          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
675          if( hrd->getSubPicCpbParamsPresentFlag() )
676          {
677            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
678            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
679          }
680          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
681        }
682      }
683    }
684  }
685}
686
687Void TDecCavlc::parseSPS(TComSPS* pcSPS)
688{
689#if ENC_DEC_TRACE
690  xTraceSPSHeader (pcSPS);
691#endif
692
693  UInt  uiCode;
694  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
695
696#if SVC_EXTENSION
697  UInt uiTmp = 0;
698 
699  if(pcSPS->getLayerId() == 0)
700  {
701#endif
702  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
703  assert(uiCode <= 6);
704#if SVC_EXTENSION
705  }
706  else
707  {
708    READ_CODE( 3,  uiCode, "sps_ext_or_max_sub_layers_minus1" );     uiTmp = uiCode;
709
710    if( uiTmp != 7 )
711    {
712      pcSPS->setMaxTLayers(uiTmp + 1);
713    }
714  }
715
716  pcSPS->setMultiLayerExtSpsFlag( pcSPS->getLayerId() != 0 && uiTmp == 7 );
717
718  if( !pcSPS->getMultiLayerExtSpsFlag() )
719  {
720#endif
721  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );           pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
722  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
723#if SVC_EXTENSION
724  }
725#else
726  if ( pcSPS->getMaxTLayers() == 1 )
727  {
728    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
729    assert( uiCode == 1 );
730  }
731#endif
732
733  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
734  assert(uiCode <= 15);
735
736#if SVC_EXTENSION
737  if( pcSPS->getMultiLayerExtSpsFlag() )
738  {
739    READ_FLAG( uiCode, "update_rep_format_flag" );
740    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
741   
742    if( pcSPS->getUpdateRepFormatFlag() )
743    {
744      READ_CODE(8, uiCode, "sps_rep_format_idx");
745      pcSPS->setUpdateRepFormatIndex(uiCode);
746    }
747  }
748  else
749  {
750    pcSPS->setUpdateRepFormatFlag( false );
751#endif
752  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
753  assert(uiCode <= 3);
754
755  if( pcSPS->getChromaFormatIdc() == CHROMA_444 )
756  {
757    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
758  }
759
760  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
761  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
762  READ_FLAG(     uiCode, "conformance_window_flag");
763  if (uiCode != 0)
764  {
765    Window &conf = pcSPS->getConformanceWindow();
766#if REPN_FORMAT_IN_VPS
767    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
768    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
769    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
770    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
771#else
772    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
773    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
774    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
775    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
776#endif
777  }
778
779  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
780#if O0043_BEST_EFFORT_DECODING
781  const UInt forceDecodeBitDepth = pcSPS->getForceDecodeBitDepth();
782  g_bitDepthInStream[CHANNEL_TYPE_LUMA] = 8 + uiCode;
783  if (forceDecodeBitDepth != 0)
784  {
785    uiCode = forceDecodeBitDepth - 8;
786  }
787#endif
788  assert(uiCode <= 8);
789
790  pcSPS->setBitDepth(CHANNEL_TYPE_LUMA, 8 + uiCode);
791#if O0043_BEST_EFFORT_DECODING
792  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*(g_bitDepthInStream[CHANNEL_TYPE_LUMA]-8)) );
793#else
794  pcSPS->setQpBDOffset(CHANNEL_TYPE_LUMA, (Int) (6*uiCode) );
795#endif
796
797  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
798#if O0043_BEST_EFFORT_DECODING
799  g_bitDepthInStream[CHANNEL_TYPE_CHROMA] = 8 + uiCode;
800  if (forceDecodeBitDepth != 0)
801  {
802    uiCode = forceDecodeBitDepth - 8;
803  }
804#endif
805  assert(uiCode <= 8);
806  pcSPS->setBitDepth(CHANNEL_TYPE_CHROMA, 8 + uiCode);
807#if O0043_BEST_EFFORT_DECODING
808  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*(g_bitDepthInStream[CHANNEL_TYPE_CHROMA]-8)) );
809#else
810  pcSPS->setQpBDOffset(CHANNEL_TYPE_CHROMA,  (Int) (6*uiCode) );
811#endif
812
813#if SVC_EXTENSION
814  }
815#endif
816
817
818  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
819  assert(uiCode <= 12);
820
821#if SVC_EXTENSION
822  if( !pcSPS->getMultiLayerExtSpsFlag() ) 
823  {
824#endif
825  UInt subLayerOrderingInfoPresentFlag;
826  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
827
828  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
829  {
830    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
831    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
832    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
833    pcSPS->setNumReorderPics(uiCode, i);
834    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
835    pcSPS->setMaxLatencyIncrease( uiCode, i );
836
837    if (!subLayerOrderingInfoPresentFlag)
838    {
839      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
840      {
841        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
842        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
843        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
844      }
845      break;
846    }
847
848#if SVC_EXTENSION
849    if( i > 0 )
850    {
851      // When i is greater than 0, sps_max_dec_pic_buffering_minus1[ i ] shall be greater than or equal to sps_max_dec_pic_buffering_minus1[ i - 1 ].
852      assert( pcSPS->getMaxDecPicBuffering(i) >= pcSPS->getMaxDecPicBuffering(i-1) );
853    }
854#endif
855
856  }
857#if SVC_EXTENSION
858  }
859#endif
860  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
861  Int log2MinCUSize = uiCode + 3;
862  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
863  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
864  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
865 
866  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
867  {
868    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
869  }
870 
871  Int maxCUDepthDelta = uiCode;
872  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
873  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
874  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
875
876  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
877  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
878
879  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
880  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
881
882  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
883  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth  + getMaxCUDepthOffset(pcSPS->getChromaFormatIdc(), pcSPS->getQuadtreeTULog2MinSize()) );
884
885  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
886  if(pcSPS->getScalingListFlag())
887  {
888#if SVC_EXTENSION
889    if( pcSPS->getMultiLayerExtSpsFlag() )
890    {
891      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
892    }
893
894    if( pcSPS->getInferScalingListFlag() )
895    {
896      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setScalingListRefLayerId( uiCode );
897
898      // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
899      assert( pcSPS->getScalingListRefLayerId() <= 62 );
900
901      pcSPS->setScalingListPresentFlag( false );
902    }
903    else
904    {
905#endif
906    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
907    if(pcSPS->getScalingListPresentFlag ())
908    {
909      parseScalingList( pcSPS->getScalingList() );
910    }
911#if SVC_EXTENSION
912    }
913#endif
914  }
915  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
916  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
917
918  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
919  if( pcSPS->getUsePCM() )
920  {
921    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_LUMA, 1 + uiCode );
922    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepth    ( CHANNEL_TYPE_CHROMA, 1 + uiCode );
923    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
924    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
925    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
926  }
927
928  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
929  assert(uiCode <= 64);
930  pcSPS->createRPSList(uiCode);
931
932  TComRPSList* rpsList = pcSPS->getRPSList();
933  TComReferencePictureSet* rps;
934
935  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
936  {
937    rps = rpsList->getReferencePictureSet(i);
938    parseShortTermRefPicSet(pcSPS,rps,i);
939  }
940  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
941  if (pcSPS->getLongTermRefsPresent())
942  {
943    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
944    pcSPS->setNumLongTermRefPicSPS(uiCode);
945    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
946    {
947      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
948      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
949      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
950      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
951    }
952  }
953  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
954
955  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
956
957  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
958
959  if (pcSPS->getVuiParametersPresentFlag())
960  {
961    parseVUI(pcSPS->getVuiParameters(), pcSPS);
962  }
963
964  READ_FLAG( uiCode, "sps_extension_present_flag");
965
966#if SVC_EXTENSION
967  pcSPS->setExtensionFlag( uiCode ? true : false );
968
969  if( pcSPS->getExtensionFlag() )
970#else
971  if (uiCode)
972#endif
973  {
974    Bool sps_extension_flags[NUM_SPS_EXTENSION_FLAGS];
975    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++)
976    {
977      READ_FLAG( uiCode, "sps_extension_flag[]" );
978      sps_extension_flags[i] = uiCode!=0;
979    }
980
981    Bool bSkipTrailingExtensionBits=false;
982    for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum.
983    {
984      if (sps_extension_flags[i])
985      {
986        switch (SPSExtensionFlagIndex(i))
987        {
988          case SPS_EXT__REXT:
989            assert(!bSkipTrailingExtensionBits);
990
991            READ_FLAG( uiCode, "transform_skip_rotation_enabled_flag");     pcSPS->setUseResidualRotation                    (uiCode != 0);
992            READ_FLAG( uiCode, "transform_skip_context_enabled_flag");      pcSPS->setUseSingleSignificanceMapContext        (uiCode != 0);
993            READ_FLAG( uiCode, "residual_dpcm_implicit_enabled_flag");      pcSPS->setUseResidualDPCM(RDPCM_SIGNAL_IMPLICIT, (uiCode != 0));
994            READ_FLAG( uiCode, "residual_dpcm_explicit_enabled_flag");      pcSPS->setUseResidualDPCM(RDPCM_SIGNAL_EXPLICIT, (uiCode != 0));
995            READ_FLAG( uiCode, "extended_precision_processing_flag");       pcSPS->setUseExtendedPrecision                   (uiCode != 0);
996            READ_FLAG( uiCode, "intra_smoothing_disabled_flag");            pcSPS->setDisableIntraReferenceSmoothing         (uiCode != 0);
997            READ_FLAG( uiCode, "high_precision_prediction_weighting_flag"); pcSPS->setUseHighPrecisionPredictionWeighting    (uiCode != 0);
998            READ_FLAG( uiCode, "golomb_rice_parameter_adaptation_flag");    pcSPS->setUseGolombRiceParameterAdaptation       (uiCode != 0);
999            READ_FLAG( uiCode, "cabac_bypass_alignment_enabled_flag");      pcSPS->setAlignCABACBeforeBypass                 (uiCode != 0);
1000            break;
1001#if SVC_EXTENSION
1002          case SPS_EXT__MLAYER:
1003            parseSPSExtension( pcSPS );
1004            break;
1005#endif
1006          default:
1007            bSkipTrailingExtensionBits=true;
1008            break;
1009        }
1010      }
1011    }
1012    if (bSkipTrailingExtensionBits)
1013    {
1014      while ( xMoreRbspData() )
1015      {
1016        READ_FLAG( uiCode, "sps_extension_data_flag");
1017      }
1018    }
1019  }
1020}
1021
1022Void TDecCavlc::parseVPS(TComVPS* pcVPS)
1023{
1024  UInt  uiCode;
1025
1026  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
1027#if VPS_RESERVED_FLAGS
1028  READ_FLAG( uiCode, "vps_base_layer_internal_flag");             pcVPS->setBaseLayerInternalFlag( uiCode ? true : false );
1029  READ_FLAG( uiCode, "vps_base_layer_available_flag");            pcVPS->setBaseLayerAvailableFlag( uiCode ? true : false );
1030#if VPS_AVC_BL_FLAG_REMOVAL
1031  pcVPS->setNonHEVCBaseLayerFlag( (pcVPS->getBaseLayerAvailableFlag() && !pcVPS->getBaseLayerInternalFlag()) ? true : false);
1032#endif
1033#else
1034  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
1035#endif
1036#if SVC_EXTENSION
1037#if O0137_MAX_LAYERID
1038  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( min( 62u, uiCode) + 1 );
1039#else
1040  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
1041#endif
1042  assert( pcVPS->getBaseLayerInternalFlag() || pcVPS->getMaxLayers() > 1 );
1043#else
1044  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
1045#endif
1046  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );    assert(uiCode+1 <= MAX_TLAYER);
1047  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
1048  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
1049#if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
1050#if VPS_EXTN_OFFSET
1051  READ_CODE( 16, uiCode,  "vps_extension_offset" );               pcVPS->setExtensionOffset( uiCode );
1052#else
1053  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
1054#endif
1055#else
1056  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
1057#endif
1058  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
1059  UInt subLayerOrderingInfoPresentFlag;
1060  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
1061  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
1062  {
1063    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
1064    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
1065    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
1066
1067    if (!subLayerOrderingInfoPresentFlag)
1068    {
1069      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
1070      {
1071        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
1072        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
1073        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
1074      }
1075      break;
1076    }
1077  }
1078
1079#if SVC_EXTENSION
1080  assert( pcVPS->getNumHrdParameters() < MAX_VPS_LAYER_SETS_PLUS1 );
1081  assert( pcVPS->getMaxLayerId()       < MAX_NUM_LAYER_IDS );
1082  READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
1083#if Q0078_ADD_LAYER_SETS
1084  READ_UVLC(uiCode, "vps_num_layer_sets_minus1");  pcVPS->setVpsNumLayerSetsMinus1(uiCode);
1085  pcVPS->setNumLayerSets(pcVPS->getVpsNumLayerSetsMinus1() + 1);
1086  for (UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++)
1087#else
1088  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
1089  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
1090#endif
1091  {
1092    // Operation point set
1093    for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ )
1094#else
1095  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
1096  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
1097  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
1098  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
1099  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
1100  {
1101    // Operation point set
1102    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
1103#endif
1104    {
1105      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );   pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
1106    }
1107  }
1108#if DERIVE_LAYER_ID_LIST_VARIABLES
1109  pcVPS->deriveLayerIdListVariables();
1110#endif
1111  TimingInfo *timingInfo = pcVPS->getTimingInfo();
1112  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
1113  if(timingInfo->getTimingInfoPresentFlag())
1114  {
1115    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
1116    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
1117    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
1118    if(timingInfo->getPocProportionalToTimingFlag())
1119    {
1120      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
1121    }
1122
1123    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
1124
1125    if( pcVPS->getNumHrdParameters() > 0 )
1126    {
1127      pcVPS->createHrdParamBuffer();
1128    }
1129    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
1130    {
1131      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
1132      if( i > 0 )
1133      {
1134        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
1135      }
1136      else
1137      {
1138        pcVPS->setCprmsPresentFlag( true, i );
1139      }
1140
1141      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
1142    }
1143  }
1144
1145#if SVC_EXTENSION
1146  READ_FLAG( uiCode,  "vps_extension_flag" );      pcVPS->setVpsExtensionFlag( uiCode ? true : false );
1147
1148  // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1.
1149  if( pcVPS->getMaxLayers() > 1 )
1150  {
1151    assert( pcVPS->getVpsExtensionFlag() == true );
1152  }
1153
1154  if( pcVPS->getVpsExtensionFlag()  )
1155  {
1156    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1157    {
1158      READ_FLAG( uiCode, "vps_extension_alignment_bit_equal_to_one"); assert(uiCode == 1);
1159    }
1160    parseVPSExtension(pcVPS);
1161    READ_FLAG( uiCode, "vps_entension2_flag" );
1162    if(uiCode)
1163    {
1164      while ( xMoreRbspData() )
1165      {
1166        READ_FLAG( uiCode, "vps_extension_data_flag");
1167      }
1168    }
1169  }
1170  else
1171  {
1172    // set default parameters when syntax elements are not present
1173    defaultVPSExtension(pcVPS);   
1174  }
1175#else
1176  READ_FLAG( uiCode,  "vps_extension_flag" );
1177  if (uiCode)
1178  {
1179    while ( xMoreRbspData() )
1180    {
1181      READ_FLAG( uiCode, "vps_extension_data_flag");
1182    }
1183  }
1184#endif
1185
1186  return;
1187}
1188
1189Void TDecCavlc::parseSliceHeader (TComSlice* pcSlice, ParameterSetManagerDecoder *parameterSetManager)
1190{
1191  UInt  uiCode;
1192  Int   iCode;
1193
1194#if ENC_DEC_TRACE
1195  xTraceSliceHeader(pcSlice);
1196#endif
1197  TComPPS* pps = NULL;
1198  TComSPS* sps = NULL;
1199
1200  UInt firstSliceSegmentInPic;
1201  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
1202  if( pcSlice->getRapPicFlag())
1203  {
1204    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
1205    pcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
1206  }
1207  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  pcSlice->setPPSId(uiCode);
1208  pps = parameterSetManager->getPrefetchedPPS(uiCode);
1209  //!KS: need to add error handling code here, if PPS is not available
1210  assert(pps!=0);
1211  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1212  //!KS: need to add error handling code here, if SPS is not available
1213  assert(sps!=0);
1214  pcSlice->setSPS(sps);
1215  pcSlice->setPPS(pps);
1216
1217  const ChromaFormat chFmt = sps->getChromaFormatIdc();
1218  const UInt numValidComp=getNumberValidComponents(chFmt);
1219  const Bool bChroma=(chFmt!=CHROMA_400);
1220
1221  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
1222  {
1223    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       pcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
1224  }
1225  else
1226  {
1227    pcSlice->setDependentSliceSegmentFlag(false);
1228  }
1229#if REPN_FORMAT_IN_VPS
1230  Int numCTUs = ((pcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((pcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1231#else
1232  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
1233#endif 
1234  UInt sliceSegmentAddress = 0;
1235  Int bitsSliceSegmentAddress = 0;
1236  while(numCTUs>(1<<bitsSliceSegmentAddress))
1237  {
1238    bitsSliceSegmentAddress++;
1239  }
1240
1241  if(!firstSliceSegmentInPic)
1242  {
1243    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
1244  }
1245  //set uiCode to equal slice start address (or dependent slice start address)
1246  pcSlice->setSliceSegmentCurStartCtuTsAddr( sliceSegmentAddress );// this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
1247  pcSlice->setSliceSegmentCurEndCtuTsAddr(numCTUs);                // Set end as the last CTU of the picture.
1248
1249  if (!pcSlice->getDependentSliceSegmentFlag())
1250  {
1251    pcSlice->setSliceCurStartCtuTsAddr(sliceSegmentAddress); // this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
1252    pcSlice->setSliceCurEndCtuTsAddr(numCTUs);
1253  }
1254
1255#if Q0142_POC_LSB_NOT_PRESENT
1256#if SHM_FIX7
1257  Int iPOClsb = 0;
1258#endif
1259#endif
1260
1261  if(!pcSlice->getDependentSliceSegmentFlag())
1262  {
1263#if SVC_EXTENSION
1264#if POC_RESET_FLAG
1265    Int iBits = 0;
1266    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
1267    {
1268      READ_FLAG(uiCode, "poc_reset_flag");      pcSlice->setPocResetFlag( uiCode ? true : false );
1269      iBits++;
1270    }
1271    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
1272    {
1273#if DISCARDABLE_PIC_RPS
1274      READ_FLAG(uiCode, "discardable_flag"); pcSlice->setDiscardableFlag( uiCode ? true : false );
1275#else
1276      READ_FLAG(uiCode, "discardable_flag"); // ignored
1277#endif
1278      iBits++;
1279    }
1280#if O0149_CROSS_LAYER_BLA_FLAG
1281    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
1282    {
1283      READ_FLAG(uiCode, "cross_layer_bla_flag");  pcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
1284      iBits++;
1285    }
1286#endif
1287    for (; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
1288    {
1289      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1290    }
1291#else
1292#if CROSS_LAYER_BLA_FLAG_FIX
1293    Int iBits = 0;
1294    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
1295#else
1296    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
1297#endif
1298    {
1299      READ_FLAG(uiCode, "discardable_flag"); // ignored
1300#if NON_REF_NAL_TYPE_DISCARDABLE
1301      pcSlice->setDiscardableFlag( uiCode ? true : false );
1302      if (uiCode)
1303      {
1304        assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
1305          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
1306          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
1307          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
1308          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
1309      }
1310#endif
1311#if CROSS_LAYER_BLA_FLAG_FIX
1312      iBits++;
1313#endif
1314    }
1315#if CROSS_LAYER_BLA_FLAG_FIX
1316    if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
1317    {
1318      READ_FLAG(uiCode, "cross_layer_bla_flag");  pcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
1319      iBits++;
1320    }
1321    for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
1322#else
1323    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1324#endif
1325    {
1326      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1327    }
1328#endif
1329#else //SVC_EXTENSION
1330    for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
1331    {
1332      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
1333    }
1334#endif //SVC_EXTENSION
1335
1336    READ_UVLC (    uiCode, "slice_type" );            pcSlice->setSliceType((SliceType)uiCode);
1337    if( pps->getOutputFlagPresentFlag() )
1338    {
1339      READ_FLAG( uiCode, "pic_output_flag" );    pcSlice->setPicOutputFlag( uiCode ? true : false );
1340    }
1341    else
1342    {
1343      pcSlice->setPicOutputFlag( true );
1344    }
1345
1346    if( pcSlice->getIdrPicFlag() )
1347    {
1348      pcSlice->setPOC(0);
1349      TComReferencePictureSet* rps = pcSlice->getLocalRPS();
1350      rps->setNumberOfNegativePictures(0);
1351      rps->setNumberOfPositivePictures(0);
1352      rps->setNumberOfLongtermPictures(0);
1353      rps->setNumberOfPictures(0);
1354      pcSlice->setRPS(rps);
1355    }
1356#if N0065_LAYER_POC_ALIGNMENT
1357#if O0062_POC_LSB_NOT_PRESENT_FLAG
1358    if( ( pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag() )
1359#else
1360    if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
1361#endif
1362#else
1363    else
1364#endif
1365    {
1366      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
1367#if POC_RESET_IDC_DECODER
1368      pcSlice->setPicOrderCntLsb( uiCode );
1369#endif
1370#if SVC_EXTENSION
1371      iPOClsb = uiCode;
1372#else
1373      Int iPOClsb = uiCode;
1374#endif
1375      Int iPrevPOC = pcSlice->getPrevTid0POC();
1376      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
1377      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
1378      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
1379      Int iPOCmsb;
1380      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
1381      {
1382        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
1383      }
1384      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
1385      {
1386        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
1387      }
1388      else
1389      {
1390        iPOCmsb = iPrevPOCmsb;
1391      }
1392      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1393        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1394        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1395      {
1396        // For BLA picture types, POCmsb is set to 0.
1397        iPOCmsb = 0;
1398      }
1399      pcSlice->setPOC              (iPOCmsb+iPOClsb);
1400
1401#if N0065_LAYER_POC_ALIGNMENT
1402    }
1403#if POC_RESET_IDC_DECODER
1404    else
1405    {
1406      pcSlice->setPicOrderCntLsb( 0 );
1407    }
1408#endif
1409    if( !pcSlice->getIdrPicFlag() )
1410    {
1411#endif
1412      TComReferencePictureSet* rps;
1413      rps = pcSlice->getLocalRPS();
1414      pcSlice->setRPS(rps);
1415      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
1416      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
1417      {
1418        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
1419      }
1420      else // use reference to short-term reference picture set in PPS
1421      {
1422        Int numBits = 0;
1423        while ((1 << numBits) < pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
1424        {
1425          numBits++;
1426        }
1427        if (numBits > 0)
1428        {
1429          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
1430        }
1431        else
1432        {
1433          uiCode = 0;
1434       
1435        }
1436        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
1437      }
1438      if(sps->getLongTermRefsPresent())
1439      {
1440        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
1441        UInt numOfLtrp = 0;
1442        UInt numLtrpInSPS = 0;
1443        if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
1444        {
1445          READ_UVLC( uiCode, "num_long_term_sps");
1446          numLtrpInSPS = uiCode;
1447          numOfLtrp += numLtrpInSPS;
1448          rps->setNumberOfLongtermPictures(numOfLtrp);
1449        }
1450        Int bitsForLtrpInSPS = 0;
1451        while (pcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
1452        {
1453          bitsForLtrpInSPS++;
1454        }
1455        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
1456        numOfLtrp += uiCode;
1457        rps->setNumberOfLongtermPictures(numOfLtrp);
1458        Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC();
1459        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;
1460        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
1461        {
1462          Int pocLsbLt;
1463          if (k < numLtrpInSPS)
1464          {
1465            uiCode = 0;
1466            if (bitsForLtrpInSPS > 0)
1467            {
1468              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
1469            }
1470            Int usedByCurrFromSPS=pcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
1471
1472            pocLsbLt = pcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
1473            rps->setUsed(j,usedByCurrFromSPS);
1474          }
1475          else
1476          {
1477            READ_CODE(pcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
1478            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
1479          }
1480          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
1481          Bool mSBPresentFlag = uiCode ? true : false;
1482          if(mSBPresentFlag)
1483          {
1484            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
1485            Bool deltaFlag = false;
1486            //            First LTRP                               || First LTRP from SH
1487            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
1488            {
1489              deltaFlag = true;
1490            }
1491            if(deltaFlag)
1492            {
1493              deltaPocMSBCycleLT = uiCode;
1494            }
1495            else
1496            {
1497              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
1498            }
1499
1500            Int pocLTCurr = pcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
1501                                        - iPOClsb + pocLsbLt;
1502            rps->setPOC     (j, pocLTCurr);
1503            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLTCurr);
1504            rps->setCheckLTMSBPresent(j,true);
1505          }
1506          else
1507          {
1508            rps->setPOC     (j, pocLsbLt);
1509            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLsbLt);
1510            rps->setCheckLTMSBPresent(j,false);
1511
1512            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
1513            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
1514            {
1515              deltaPocMSBCycleLT = 0;
1516            }
1517          }
1518          prevDeltaMSB = deltaPocMSBCycleLT;
1519        }
1520        offset += rps->getNumberOfLongtermPictures();
1521        rps->setNumberOfPictures(offset);
1522      }
1523#if DPB_CONSTRAINTS
1524      if(pcSlice->getVPS()->getVpsExtensionFlag()==1)
1525      {
1526#if Q0078_ADD_LAYER_SETS
1527        for (Int ii = 1; ii < (pcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
1528#else
1529        for (Int ii=1; ii< pcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
1530#endif
1531        {
1532          Int layerSetIdxForOutputLayerSet = pcSlice->getVPS()->getOutputLayerSetIdx( ii );
1533          Int chkAssert=0;
1534          for(Int kk = 0; kk < pcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
1535          {
1536#if R0235_SMALLEST_LAYER_ID
1537            if( pcSlice->getVPS()->getNecessaryLayerFlag(ii, kk) && pcSlice->getLayerId() == pcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk) )
1538#else
1539            if(pcSlice->getLayerId() == pcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
1540#endif
1541            {
1542              chkAssert=1;
1543            }
1544          }
1545          if(chkAssert)
1546          {
1547            UInt layerIdc = pcSlice->getVPS()->getLayerIdcForOls( ii, pcSlice->getLayerId() );
1548            assert(rps->getNumberOfNegativePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdc, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
1549            assert(rps->getNumberOfPositivePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdc, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
1550            assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdc, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
1551          }
1552        }
1553
1554
1555      }
1556      if(pcSlice->getLayerId() == 0)
1557      {
1558        assert(rps->getNumberOfNegativePictures() <= pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getSPS()->getMaxTLayers()-1) );
1559        assert(rps->getNumberOfPositivePictures() <= pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
1560        assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getSPS()->getMaxTLayers()-1));
1561      }
1562#endif
1563      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1564        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1565        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1566      {
1567        // In the case of BLA picture types, rps data is read from slice header but ignored
1568        rps = pcSlice->getLocalRPS();
1569        rps->setNumberOfNegativePictures(0);
1570        rps->setNumberOfPositivePictures(0);
1571        rps->setNumberOfLongtermPictures(0);
1572        rps->setNumberOfPictures(0);
1573        pcSlice->setRPS(rps);
1574      }
1575      if (pcSlice->getSPS()->getTMVPFlagsPresent())
1576      {
1577        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
1578        pcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
1579      }
1580      else
1581      {
1582        pcSlice->setEnableTMVPFlag(false);
1583      }
1584    }
1585
1586#if SVC_EXTENSION
1587    pcSlice->setActiveNumILRRefIdx(0);
1588    if((pcSlice->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) )
1589    {
1590      READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
1591      pcSlice->setInterLayerPredEnabledFlag(uiCode);
1592      if( pcSlice->getInterLayerPredEnabledFlag())
1593      {
1594        if(pcSlice->getNumILRRefIdx() > 1)
1595        {
1596          Int numBits = 1;
1597          while ((1 << numBits) < pcSlice->getNumILRRefIdx())
1598          {
1599            numBits++;
1600          }
1601          if( !pcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
1602          {
1603            READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
1604            pcSlice->setActiveNumILRRefIdx(uiCode + 1);
1605          }
1606          else
1607          {
1608#if P0079_DERIVE_NUMACTIVE_REF_PICS
1609            for( Int i = 0; i < pcSlice->getNumILRRefIdx(); i++ ) 
1610            {
1611#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
1612              if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i), pcSlice->getLayerIdx()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
1613                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
1614#else
1615              if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i), pcSlice->getLayerIdx()) >  pcSlice->getTLayer() &&
1616                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
1617#endif
1618              {         
1619                pcSlice->setActiveNumILRRefIdx(1);
1620                break;
1621              }
1622            }
1623#else
1624            pcSlice->setActiveNumILRRefIdx(1);
1625#endif
1626          }
1627
1628          if( pcSlice->getActiveNumILRRefIdx() == pcSlice->getNumILRRefIdx() )
1629          {
1630            for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1631            {
1632              pcSlice->setInterLayerPredLayerIdc(i,i);
1633            }
1634          }
1635          else
1636          {
1637            for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1638            {
1639              READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
1640              pcSlice->setInterLayerPredLayerIdc(uiCode, i);
1641            }
1642          }
1643        }
1644        else
1645        {
1646#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
1647          Int refLayerId = pcSlice->getVPS()->getRefLayerId(pcSlice->getLayerId(), 0);
1648          Int refLayerIdx = pcSlice->getVPS()->getLayerIdxInVps(refLayerId);
1649#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
1650          if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(refLayerIdx, pcSlice->getLayerIdx()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
1651            (pcSlice->getVPS()->getMaxTSLayersMinus1(refLayerIdx) >=  pcSlice->getTLayer()) )
1652#else
1653          if( (pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(refLayerIdx,pcSlice->getLayerIdx()) >  pcSlice->getTLayer()) &&
1654            (pcSlice->getVPS()->getMaxTSLayersMinus1(refLayerIdx) >=  pcSlice->getTLayer()) )
1655#endif
1656          {
1657#endif
1658            pcSlice->setActiveNumILRRefIdx(1);
1659            pcSlice->setInterLayerPredLayerIdc(0, 0);
1660#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
1661          }
1662#endif
1663        }
1664      }
1665    }
1666    else if( pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (pcSlice->getLayerId() > 0 ))
1667    {
1668      pcSlice->setInterLayerPredEnabledFlag(true);
1669
1670#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
1671      Int   numRefLayerPics = 0;
1672      Int   i = 0;
1673      Int   refLayerPicIdc  [MAX_VPS_LAYER_IDX_PLUS1];
1674      for(i = 0, numRefLayerPics = 0;  i < pcSlice->getNumILRRefIdx(); i++ ) 
1675      {
1676#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
1677        if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i), pcSlice->getLayerIdx()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
1678          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
1679#else
1680        if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i), pcSlice->getLayerIdx()) >  pcSlice->getTLayer() &&
1681          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
1682#endif
1683        {         
1684          refLayerPicIdc[ numRefLayerPics++ ] = i;
1685        }
1686      }
1687      pcSlice->setActiveNumILRRefIdx(numRefLayerPics);
1688      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1689      {
1690        pcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i], i);
1691      }
1692#else
1693      pcSlice->setActiveNumILRRefIdx(pcSlice->getNumILRRefIdx());
1694      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1695      {
1696        pcSlice->setInterLayerPredLayerIdc(i,i);
1697      }
1698#endif
1699    }
1700#if P0312_VERT_PHASE_ADJ
1701    for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) 
1702    {
1703      UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1704#if !MOVE_SCALED_OFFSET_TO_PPS
1705      if( pcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
1706#else
1707      if( pcSlice->getPPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
1708#endif
1709      {
1710        READ_FLAG( uiCode, "vert_phase_position_flag" ); pcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
1711      }
1712    }
1713#endif
1714#endif //SVC_EXTENSION
1715
1716    if(sps->getUseSAO())
1717    {
1718      READ_FLAG(uiCode, "slice_sao_luma_flag");  pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_LUMA, (Bool)uiCode);
1719#if SVC_EXTENSION
1720      ChromaFormat format;
1721      if( sps->getLayerId() == 0 )
1722      {
1723        format = sps->getChromaFormatIdc();
1724      }
1725      else
1726      {
1727        format = pcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : pcSlice->getVPS()->getVpsRepFormatIdx( pcSlice->getVPS()->getLayerIdxInVps(sps->getLayerId()) ) )->getChromaFormatVpsIdc();
1728#if Q0195_REP_FORMAT_CLEANUP
1729        assert( (sps->getUpdateRepFormatFlag()==false && pcSlice->getVPS()->getVpsNumRepFormats()==1) || pcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
1730#endif
1731      }
1732      if (format != CHROMA_400)
1733#else
1734      if (bChroma)
1735#endif
1736      {
1737        READ_FLAG(uiCode, "slice_sao_chroma_flag");  pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_CHROMA, (Bool)uiCode);
1738      }
1739#if SVC_EXTENSION
1740      else
1741      {
1742        pcSlice->setSaoEnabledFlag(CHANNEL_TYPE_CHROMA, false);
1743      }
1744#endif
1745    }
1746
1747    if (pcSlice->getIdrPicFlag())
1748    {
1749      pcSlice->setEnableTMVPFlag(false);
1750    }
1751    if (!pcSlice->isIntra())
1752    {
1753
1754      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
1755      if (uiCode)
1756      {
1757        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  pcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
1758        if (pcSlice->isInterB())
1759        {
1760          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  pcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
1761        }
1762        else
1763        {
1764          pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
1765        }
1766      }
1767      else
1768      {
1769        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getPPS()->getNumRefIdxL0DefaultActive());
1770        if (pcSlice->isInterB())
1771        {
1772          pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getPPS()->getNumRefIdxL1DefaultActive());
1773        }
1774        else
1775        {
1776          pcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
1777        }
1778      }
1779    }
1780    // }
1781    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
1782    if(!pcSlice->isIntra())
1783    {
1784      if( !pcSlice->getPPS()->getListsModificationPresentFlag() || pcSlice->getNumRpsCurrTempList() <= 1 )
1785      {
1786        refPicListModification->setRefPicListModificationFlagL0( 0 );
1787      }
1788      else
1789      {
1790        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
1791      }
1792
1793      if(refPicListModification->getRefPicListModificationFlagL0())
1794      {
1795        uiCode = 0;
1796        Int i = 0;
1797        Int numRpsCurrTempList0 = pcSlice->getNumRpsCurrTempList();
1798        if ( numRpsCurrTempList0 > 1 )
1799        {
1800          Int length = 1;
1801          numRpsCurrTempList0 --;
1802          while ( numRpsCurrTempList0 >>= 1)
1803          {
1804            length ++;
1805          }
1806          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1807          {
1808            READ_CODE( length, uiCode, "list_entry_l0" );
1809            refPicListModification->setRefPicSetIdxL0(i, uiCode );
1810          }
1811        }
1812        else
1813        {
1814          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1815          {
1816            refPicListModification->setRefPicSetIdxL0(i, 0 );
1817          }
1818        }
1819      }
1820    }
1821    else
1822    {
1823      refPicListModification->setRefPicListModificationFlagL0(0);
1824    }
1825    if(pcSlice->isInterB())
1826    {
1827      if( !pcSlice->getPPS()->getListsModificationPresentFlag() || pcSlice->getNumRpsCurrTempList() <= 1 )
1828      {
1829        refPicListModification->setRefPicListModificationFlagL1( 0 );
1830      }
1831      else
1832      {
1833        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
1834      }
1835      if(refPicListModification->getRefPicListModificationFlagL1())
1836      {
1837        uiCode = 0;
1838        Int i = 0;
1839        Int numRpsCurrTempList1 = pcSlice->getNumRpsCurrTempList();
1840        if ( numRpsCurrTempList1 > 1 )
1841        {
1842          Int length = 1;
1843          numRpsCurrTempList1 --;
1844          while ( numRpsCurrTempList1 >>= 1)
1845          {
1846            length ++;
1847          }
1848          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1849          {
1850            READ_CODE( length, uiCode, "list_entry_l1" );
1851            refPicListModification->setRefPicSetIdxL1(i, uiCode );
1852          }
1853        }
1854        else
1855        {
1856          for (i = 0; i < pcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1857          {
1858            refPicListModification->setRefPicSetIdxL1(i, 0 );
1859          }
1860        }
1861      }
1862    }
1863    else
1864    {
1865      refPicListModification->setRefPicListModificationFlagL1(0);
1866    }
1867    if (pcSlice->isInterB())
1868    {
1869      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       pcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
1870    }
1871
1872    pcSlice->setCabacInitFlag( false ); // default
1873    if(pps->getCabacInitPresentFlag() && !pcSlice->isIntra())
1874    {
1875      READ_FLAG(uiCode, "cabac_init_flag");
1876      pcSlice->setCabacInitFlag( uiCode ? true : false );
1877    }
1878
1879    if ( pcSlice->getEnableTMVPFlag() )
1880    {
1881#if SVC_EXTENSION && REF_IDX_MFM
1882      // set motion mapping flag
1883      pcSlice->setMFMEnabledFlag( ( pcSlice->getNumMotionPredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() && !pcSlice->isIntra() ) ? true : false );
1884#endif
1885      if ( pcSlice->getSliceType() == B_SLICE )
1886      {
1887        READ_FLAG( uiCode, "collocated_from_l0_flag" );
1888        pcSlice->setColFromL0Flag(uiCode);
1889      }
1890      else
1891      {
1892        pcSlice->setColFromL0Flag( 1 );
1893      }
1894
1895      if ( pcSlice->getSliceType() != I_SLICE &&
1896          ((pcSlice->getColFromL0Flag() == 1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
1897           (pcSlice->getColFromL0Flag() == 0 && pcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
1898      {
1899        READ_UVLC( uiCode, "collocated_ref_idx" );
1900        pcSlice->setColRefIdx(uiCode);
1901      }
1902      else
1903      {
1904        pcSlice->setColRefIdx(0);
1905      }
1906    }
1907    if ( (pps->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
1908    {
1909      xParsePredWeightTable(pcSlice);
1910      pcSlice->initWpScaling();
1911    }
1912    if (!pcSlice->isIntra())
1913    {
1914      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
1915      pcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
1916    }
1917
1918    READ_SVLC( iCode, "slice_qp_delta" );
1919    pcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
1920
1921#if REPN_FORMAT_IN_VPS
1922#if O0194_DIFFERENT_BITDEPTH_EL_BL
1923    g_bitDepthLayer[CHANNEL_TYPE_LUMA][pcSlice->getLayerId()] = pcSlice->getBitDepthY();
1924    g_bitDepthLayer[CHANNEL_TYPE_CHROMA][pcSlice->getLayerId()] = pcSlice->getBitDepthC();
1925#endif
1926    assert( pcSlice->getSliceQp() >= -pcSlice->getQpBDOffsetY() );
1927#else   
1928    assert( pcSlice->getSliceQp() >= -sps->getQpBDOffset(CHANNEL_TYPE_LUMA) );
1929#endif
1930    assert( pcSlice->getSliceQp() <=  51 );
1931
1932    if (pcSlice->getPPS()->getSliceChromaQpFlag())
1933    {
1934      if (numValidComp>COMPONENT_Cb)
1935      {
1936        READ_SVLC( iCode, "slice_qp_delta_cb" );
1937        pcSlice->setSliceChromaQpDelta(COMPONENT_Cb, iCode );
1938        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb) >= -12 );
1939        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb) <=  12 );
1940        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cb) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cb)) >= -12 );
1941        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cb) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cb)) <=  12 );
1942      }
1943
1944      if (numValidComp>COMPONENT_Cr)
1945      {
1946        READ_SVLC( iCode, "slice_qp_delta_cr" );
1947        pcSlice->setSliceChromaQpDelta(COMPONENT_Cr, iCode );
1948        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr) >= -12 );
1949        assert( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr) <=  12 );
1950        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cr) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cr)) >= -12 );
1951        assert( (pcSlice->getPPS()->getQpOffset(COMPONENT_Cr) + pcSlice->getSliceChromaQpDelta(COMPONENT_Cr)) <=  12 );
1952      }
1953    }
1954
1955    if (pcSlice->getPPS()->getChromaQpAdjTableSize() > 0)
1956    {
1957      READ_FLAG(uiCode, "slice_chroma_qp_adjustment_enabled_flag"); pcSlice->setUseChromaQpAdj(uiCode != 0);
1958    }
1959    else pcSlice->setUseChromaQpAdj(false);
1960
1961    if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
1962    {
1963      if(pcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
1964      {
1965        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        pcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
1966      }
1967      else
1968      {
1969        pcSlice->setDeblockingFilterOverrideFlag(0);
1970      }
1971      if(pcSlice->getDeblockingFilterOverrideFlag())
1972      {
1973        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   pcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
1974        if(!pcSlice->getDeblockingFilterDisable())
1975        {
1976          READ_SVLC( iCode, "slice_beta_offset_div2" );                       pcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
1977          assert(pcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
1978                 pcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
1979          READ_SVLC( iCode, "slice_tc_offset_div2" );                         pcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
1980          assert(pcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
1981                 pcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
1982        }
1983      }
1984      else
1985      {
1986        pcSlice->setDeblockingFilterDisable   ( pcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
1987        pcSlice->setDeblockingFilterBetaOffsetDiv2( pcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
1988        pcSlice->setDeblockingFilterTcOffsetDiv2  ( pcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
1989      }
1990    }
1991    else
1992    {
1993      pcSlice->setDeblockingFilterDisable       ( false );
1994      pcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
1995      pcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
1996    }
1997
1998    Bool isSAOEnabled = pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA) || (bChroma && pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA)));
1999    Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
2000
2001    if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
2002    {
2003      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
2004    }
2005    else
2006    {
2007      uiCode = pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
2008    }
2009    pcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
2010
2011  }
2012
2013  std::vector<UInt> entryPointOffset;
2014  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2015  {
2016    UInt numEntryPointOffsets;
2017    UInt offsetLenMinus1;
2018    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets");
2019    if (numEntryPointOffsets>0)
2020    {
2021      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2022      entryPointOffset.resize(numEntryPointOffsets);
2023      for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2024      {
2025        READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
2026        entryPointOffset[ idx ] = uiCode + 1;
2027      }
2028    }
2029  }
2030
2031#if POC_RESET_IDC_SIGNALLING
2032  Int sliceHeaderExtensionLength = 0;
2033  if(pps->getSliceHeaderExtensionPresentFlag())
2034  {
2035    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
2036  }
2037  else
2038  {
2039    sliceHeaderExtensionLength = 0;
2040#if INFERENCE_POC_MSB_VAL_PRESENT
2041    pcSlice->setPocMsbValPresentFlag( false );
2042#endif
2043  }
2044  UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
2045  if( sliceHeaderExtensionLength > 0 )
2046  {
2047    if( pcSlice->getPPS()->getPocResetInfoPresentFlag() )
2048    {
2049      READ_CODE( 2, uiCode,       "poc_reset_idc"); pcSlice->setPocResetIdc(uiCode);
2050#if POC_RESET_RESTRICTIONS
2051      /* The value of poc_reset_idc shall not be equal to 1 or 2 for a RASL picture, a RADL picture,
2052      a sub-layer non-reference picture, or a picture that has TemporalId greater than 0,
2053      or a picture that has discardable_flag equal to 1. */
2054      if( pcSlice->getPocResetIdc() == 1 || pcSlice->getPocResetIdc() == 2 )
2055      {
2056        assert( !pcSlice->isRASL() );
2057        assert( !pcSlice->isRADL() );
2058        assert( !pcSlice->isSLNR() );
2059        assert( pcSlice->getTLayer() == 0 );
2060        assert( pcSlice->getDiscardableFlag() == 0 );
2061      }
2062
2063      // The value of poc_reset_idc of a CRA or BLA picture shall be less than 3.
2064      if( pcSlice->getPocResetIdc() == 3)
2065      {
2066        assert( ! ( pcSlice->isCRA() || pcSlice->isBLA() ) );
2067      }
2068#endif
2069    }
2070    else
2071    {
2072      pcSlice->setPocResetIdc( 0 );
2073    }
2074#if Q0142_POC_LSB_NOT_PRESENT
2075    if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId()) ) && iPOClsb > 0 )
2076    {
2077      assert( pcSlice->getPocResetIdc() != 2 );
2078    }
2079#endif
2080    if( pcSlice->getPocResetIdc() > 0 )
2081    {
2082      READ_CODE(6, uiCode,      "poc_reset_period_id"); pcSlice->setPocResetPeriodId(uiCode);
2083    }
2084    else
2085    {
2086
2087      pcSlice->setPocResetPeriodId( 0 );
2088    }
2089
2090    if (pcSlice->getPocResetIdc() == 3)
2091    {
2092      READ_FLAG( uiCode,        "full_poc_reset_flag"); pcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
2093      READ_CODE(pcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); pcSlice->setPocLsbVal(uiCode);
2094#if Q0142_POC_LSB_NOT_PRESENT
2095      if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId()) ) && pcSlice->getFullPocResetFlag() )
2096      {
2097        assert( pcSlice->getPocLsbVal() == 0 );
2098      }
2099#endif
2100    }
2101
2102    // Derive the value of PocMsbValRequiredFlag
2103#if P0297_VPS_POC_LSB_ALIGNED_FLAG
2104    pcSlice->setPocMsbValRequiredFlag( (pcSlice->getCraPicFlag() || pcSlice->getBlaPicFlag())
2105      && (!pcSlice->getVPS()->getVpsPocLsbAlignedFlag() ||
2106      (pcSlice->getVPS()->getVpsPocLsbAlignedFlag() && pcSlice->getVPS()->getNumDirectRefLayers(pcSlice->getLayerId()) == 0))
2107      );
2108#else
2109    pcSlice->setPocMsbValRequiredFlag( pcSlice->getCraPicFlag() || pcSlice->getBlaPicFlag() );
2110#endif
2111
2112#if P0297_VPS_POC_LSB_ALIGNED_FLAG
2113    if (!pcSlice->getPocMsbValRequiredFlag() && pcSlice->getVPS()->getVpsPocLsbAlignedFlag())
2114#else
2115    if (!pcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */)
2116#endif
2117    {
2118#if P0297_VPS_POC_LSB_ALIGNED_FLAG
2119      READ_FLAG(uiCode, "poc_msb_cycle_val_present_flag"); pcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
2120#else
2121      READ_FLAG(uiCode, "poc_msb_val_present_flag"); pcSlice->setPocMsbValPresentFlag(uiCode ? true : false);
2122#endif
2123    }
2124    else
2125    {
2126#if POC_MSB_VAL_PRESENT_FLAG_SEM
2127      if( sliceHeaderExtensionLength == 0 )
2128      {
2129        pcSlice->setPocMsbValPresentFlag( false );
2130      }
2131      else if( pcSlice->getPocMsbValRequiredFlag() )
2132#else
2133      if( pcSlice->getPocMsbValRequiredFlag() )
2134#endif
2135      {
2136        pcSlice->setPocMsbValPresentFlag( true );
2137      }
2138      else
2139      {
2140        pcSlice->setPocMsbValPresentFlag( false );
2141      }
2142    }
2143
2144#if !POC_RESET_IDC_DECODER
2145    Int maxPocLsb  = 1 << pcSlice->getSPS()->getBitsForPOC();
2146#endif
2147    if( pcSlice->getPocMsbValPresentFlag() )
2148    {
2149#if P0297_VPS_POC_LSB_ALIGNED_FLAG
2150      READ_UVLC( uiCode,    "poc_msb_cycle_val");             pcSlice->setPocMsbVal( uiCode );
2151#else
2152      READ_UVLC( uiCode,    "poc_msb_val");             pcSlice->setPocMsbVal( uiCode );
2153#endif
2154
2155#if !POC_RESET_IDC_DECODER
2156      // Update POC of the slice based on this MSB val
2157      Int pocLsb     = pcSlice->getPOC() % maxPocLsb;
2158      pcSlice->setPOC((pcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
2159    }
2160    else
2161    {
2162      pcSlice->setPocMsbVal( pcSlice->getPOC() / maxPocLsb );
2163#endif
2164    }
2165
2166    // Read remaining bits in the slice header extension.
2167    UInt endBits = m_pcBitstream->getNumBitsRead();
2168    Int counter = (endBits - startBits) % 8;
2169    if( counter )
2170    {
2171      counter = 8 - counter;
2172    }
2173
2174    while( counter )
2175    {
2176#if Q0146_SSH_EXT_DATA_BIT
2177      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
2178#else
2179      READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
2180#endif
2181      counter--;
2182    }
2183  }
2184#else
2185  if(pps->getSliceHeaderExtensionPresentFlag())
2186  {
2187    READ_UVLC(uiCode,"slice_header_extension_length");
2188    for(Int i=0; i<uiCode; i++)
2189    {
2190      UInt ignore;
2191      READ_CODE(8,ignore,"slice_header_extension_data_byte");
2192    }
2193  }
2194#endif
2195#if RExt__DECODER_DEBUG_BIT_STATISTICS
2196  TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,m_pcBitstream->readByteAlignment(),0);
2197#else
2198  m_pcBitstream->readByteAlignment();
2199#endif
2200
2201  pcSlice->clearSubstreamSizes();
2202
2203  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
2204  {
2205    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
2206
2207    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
2208    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2209    {
2210      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
2211      {
2212        endOfSliceHeaderLocation++;
2213      }
2214    }
2215
2216    Int  curEntryPointOffset     = 0;
2217    Int  prevEntryPointOffset    = 0;
2218    for (UInt idx=0; idx<entryPointOffset.size(); idx++)
2219    {
2220      curEntryPointOffset += entryPointOffset[ idx ];
2221
2222      Int emulationPreventionByteCount = 0;
2223      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
2224      {
2225        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
2226             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
2227        {
2228          emulationPreventionByteCount++;
2229        }
2230      }
2231
2232      entryPointOffset[ idx ] -= emulationPreventionByteCount;
2233      prevEntryPointOffset = curEntryPointOffset;
2234      pcSlice->addSubstreamSize(entryPointOffset [ idx ] );
2235    }
2236  }
2237
2238  return;
2239}
2240
2241Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
2242{
2243  UInt uiCode;
2244  if(profilePresentFlag)
2245  {
2246    parseProfileTier(rpcPTL->getGeneralPTL());
2247  }
2248  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(Level::Name(uiCode));
2249
2250  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
2251  {
2252#if MULTIPLE_PTL_SUPPORT
2253    READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2254#else
2255    if(profilePresentFlag)
2256    {
2257      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
2258    }
2259#endif
2260    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
2261  }
2262
2263  if (maxNumSubLayersMinus1 > 0)
2264  {
2265    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
2266    {
2267      READ_CODE(2, uiCode, "reserved_zero_2bits");
2268      assert(uiCode == 0);
2269    }
2270  }
2271
2272  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
2273  {
2274#if MULTIPLE_PTL_SUPPORT
2275    if( rpcPTL->getSubLayerProfilePresentFlag(i) )
2276#else
2277    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
2278#endif
2279    {
2280      parseProfileTier(rpcPTL->getSubLayerPTL(i));
2281    }
2282    if(rpcPTL->getSubLayerLevelPresentFlag(i))
2283    {
2284      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(Level::Name(uiCode));
2285    }
2286  }
2287}
2288
2289Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
2290{
2291  UInt uiCode;
2292  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
2293  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? Level::HIGH : Level::MAIN);
2294  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (Profile::Name(uiCode));
2295  for(Int j = 0; j < 32; j++)
2296  {
2297    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
2298  }
2299  READ_FLAG(uiCode, "general_progressive_source_flag");
2300  ptl->setProgressiveSourceFlag(uiCode ? true : false);
2301
2302  READ_FLAG(uiCode, "general_interlaced_source_flag");
2303  ptl->setInterlacedSourceFlag(uiCode ? true : false);
2304
2305  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
2306  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
2307
2308  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
2309  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
2310
2311  if (ptl->getProfileIdc() == Profile::MAINREXT || ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT )
2312  {
2313    UInt maxBitDepth=16;
2314    READ_FLAG(    uiCode, "general_max_12bit_constraint_flag" ); if (uiCode) maxBitDepth=12;
2315    READ_FLAG(    uiCode, "general_max_10bit_constraint_flag" ); if (uiCode) maxBitDepth=10;
2316    READ_FLAG(    uiCode, "general_max_8bit_constraint_flag"  ); if (uiCode) maxBitDepth=8;
2317    ptl->setBitDepthConstraint(maxBitDepth);
2318    ChromaFormat chromaFmtConstraint=CHROMA_444;
2319    READ_FLAG(    uiCode, "general_max_422chroma_constraint_flag"  ); if (uiCode) chromaFmtConstraint=CHROMA_422;
2320    READ_FLAG(    uiCode, "general_max_420chroma_constraint_flag"  ); if (uiCode) chromaFmtConstraint=CHROMA_420;
2321    READ_FLAG(    uiCode, "general_max_monochrome_constraint_flag" ); if (uiCode) chromaFmtConstraint=CHROMA_400;
2322    ptl->setChromaFormatConstraint(chromaFmtConstraint);
2323    READ_FLAG(    uiCode, "general_intra_constraint_flag");          ptl->setIntraConstraintFlag(uiCode != 0);
2324    READ_FLAG(    uiCode, "general_one_picture_only_constraint_flag");
2325    READ_FLAG(    uiCode, "general_lower_bit_rate_constraint_flag"); ptl->setLowerBitRateConstraintFlag(uiCode != 0);
2326#if MULTIPLE_PTL_SUPPORT
2327    READ_CODE(32, uiCode, "general_reserved_zero_34bits");  READ_CODE(2, uiCode, "general_reserved_zero_34bits");
2328  }
2329  else if( ptl->getProfileIdc() == Profile::SCALABLEMAIN )
2330  {
2331    READ_FLAG(    uiCode, "general_max_12bit_constraint_flag" ); assert (uiCode == 1);
2332    READ_FLAG(    uiCode, "general_max_10bit_constraint_flag" ); assert (uiCode == 1);
2333    READ_FLAG(    uiCode, "general_max_8bit_constraint_flag"  ); ptl->setProfileIdc  ((uiCode) ? Profile::SCALABLEMAIN : Profile::SCALABLEMAIN10);
2334    READ_FLAG(    uiCode, "general_max_422chroma_constraint_flag"  ); assert (uiCode == 1);
2335    READ_FLAG(    uiCode, "general_max_420chroma_constraint_flag"  ); assert (uiCode == 1);
2336    READ_FLAG(    uiCode, "general_max_monochrome_constraint_flag" ); assert (uiCode == 0);
2337    READ_FLAG(    uiCode, "general_intra_constraint_flag"); assert (uiCode == 0);
2338    READ_FLAG(    uiCode, "general_one_picture_only_constraint_flag"); assert (uiCode == 0);
2339    READ_FLAG(    uiCode, "general_lower_bit_rate_constraint_flag"); assert (uiCode == 1);
2340    READ_CODE(32, uiCode, "general_reserved_zero_34bits");  READ_CODE(2, uiCode, "general_reserved_zero_34bits");
2341  }
2342  else
2343  {
2344    ptl->setBitDepthConstraint((ptl->getProfileIdc() == Profile::MAIN10)?10:8);
2345    ptl->setChromaFormatConstraint(CHROMA_420);
2346    ptl->setIntraConstraintFlag(false);
2347    ptl->setLowerBitRateConstraintFlag(true);
2348    READ_CODE(32,  uiCode, "general_reserved_zero_43bits");  READ_CODE(11,  uiCode, "general_reserved_zero_43bits");
2349  }
2350
2351  if( ( ptl->getProfileIdc() >= 1 && ptl->getProfileIdc() <= 5 ) || 
2352      ptl->getProfileCompatibilityFlag(1) || ptl->getProfileCompatibilityFlag(2) || 
2353      ptl->getProfileCompatibilityFlag(3) || ptl->getProfileCompatibilityFlag(4) || 
2354      ptl->getProfileCompatibilityFlag(5)                                           )
2355  {
2356    READ_FLAG(uiCode, "general_inbld_flag");
2357  }
2358  else
2359  {
2360    READ_FLAG(uiCode, "general_reserved_zero_bit");
2361  }
2362#else
2363    READ_CODE(16, uiCode, "XXX_reserved_zero_35bits[0..15]");
2364    READ_CODE(16, uiCode, "XXX_reserved_zero_35bits[16..31]");
2365    READ_CODE(3,  uiCode, "XXX_reserved_zero_35bits[32..34]");
2366  }
2367  else
2368  {
2369    ptl->setBitDepthConstraint((ptl->getProfileIdc() == Profile::MAIN10)?10:8);
2370    ptl->setChromaFormatConstraint(CHROMA_420);
2371    ptl->setIntraConstraintFlag(false);
2372    ptl->setLowerBitRateConstraintFlag(true);
2373    READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
2374    READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
2375    READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
2376  }
2377#endif
2378}
2379
2380Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2381{
2382  ruiBit = false;
2383  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2384  if(iBitsLeft <= 8)
2385  {
2386    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2387    if (uiPeekValue == (1<<(iBitsLeft-1)))
2388    {
2389      ruiBit = true;
2390    }
2391  }
2392}
2393
2394Void TDecCavlc::parseRemainingBytes( Bool noTrailingBytesExpected )
2395{
2396  if (noTrailingBytesExpected)
2397  {
2398    const UInt numberOfRemainingSubstreamBytes=m_pcBitstream->getNumBitsLeft();
2399    assert (numberOfRemainingSubstreamBytes == 0);
2400  }
2401  else
2402  {
2403    while (m_pcBitstream->getNumBitsLeft())
2404    {
2405      UInt trailingNullByte=m_pcBitstream->readByte();
2406      if (trailingNullByte!=0)
2407      {
2408        printf("Trailing byte should be 0, but has value %02x\n", trailingNullByte);
2409        assert(trailingNullByte==0);
2410      }
2411    }
2412  }
2413}
2414
2415Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2416{
2417  assert(0);
2418}
2419
2420Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2421{
2422  assert(0);
2423}
2424
2425Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
2426{
2427  assert(0);
2428}
2429
2430Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2431{
2432  assert(0);
2433}
2434
2435Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2436{
2437  assert(0);
2438}
2439
2440Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2441{
2442  assert(0);
2443}
2444
2445/** Parse I_PCM information.
2446* \param pcCU pointer to CU
2447* \param uiAbsPartIdx CU index
2448* \param uiDepth CU depth
2449* \returns Void
2450*
2451* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
2452*/
2453Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2454{
2455  assert(0);
2456}
2457
2458Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2459{
2460  assert(0);
2461}
2462
2463Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2464{
2465  assert(0);
2466}
2467
2468Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
2469{
2470  assert(0);
2471}
2472
2473Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
2474{
2475  assert(0);
2476}
2477
2478Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
2479{
2480  assert(0);
2481}
2482
2483Void TDecCavlc::parseCrossComponentPrediction( class TComTU& /*rTu*/, ComponentID /*compID*/ )
2484{
2485  assert(0);
2486}
2487
2488Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2489{
2490  Int qp;
2491  Int  iDQp;
2492
2493#if RExt__DECODER_DEBUG_BIT_STATISTICS
2494  READ_SVLC(iDQp, "delta_qp");
2495#else
2496  xReadSvlc( iDQp );
2497#endif
2498
2499#if REPN_FORMAT_IN_VPS
2500  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
2501#else
2502  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA);
2503#endif
2504  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
2505
2506  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
2507  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
2508
2509  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
2510}
2511
2512Void TDecCavlc::parseChromaQpAdjustment( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
2513{
2514  assert(0);
2515}
2516
2517Void TDecCavlc::parseCoeffNxN( TComTU &/*rTu*/, ComponentID /*compID*/ )
2518{
2519  assert(0);
2520}
2521
2522Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
2523{
2524  assert(0);
2525}
2526
2527Void TDecCavlc::parseQtCbf( TComTU &/*rTu*/, const ComponentID /*compID*/, const Bool /*lowestLevel*/ )
2528{
2529  assert(0);
2530}
2531
2532Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
2533{
2534  assert(0);
2535}
2536
2537Void TDecCavlc::parseTransformSkipFlags (TComTU &/*rTu*/, ComponentID /*component*/)
2538{
2539  assert(0);
2540}
2541
2542Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
2543{
2544  assert(0);
2545}
2546
2547Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
2548{
2549  assert(0);
2550}
2551
2552// ====================================================================================================================
2553// Protected member functions
2554// ====================================================================================================================
2555
2556/** parse explicit wp tables
2557* \param TComSlice* pcSlice
2558* \returns Void
2559*/
2560Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
2561{
2562        WPScalingParam *wp;
2563        TComSPS        *sps          = pcSlice->getSPS();
2564  const ChromaFormat    chFmt        = sps->getChromaFormatIdc();
2565  const Int             numValidComp = Int(getNumberValidComponents(chFmt));
2566  const Bool            bChroma      = (chFmt!=CHROMA_400);
2567  const SliceType       eSliceType   = pcSlice->getSliceType();
2568  const Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
2569        UInt            uiLog2WeightDenomLuma=0, uiLog2WeightDenomChroma=0;
2570        UInt            uiTotalSignalledWeightFlags = 0;
2571
2572  Int iDeltaDenom;
2573  // decode delta_luma_log2_weight_denom :
2574  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
2575  assert( uiLog2WeightDenomLuma <= 7 );
2576  if( bChroma )
2577  {
2578    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
2579    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
2580    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
2581    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
2582  }
2583
2584  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
2585  {
2586    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
2587    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
2588    {
2589      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2590
2591      wp[COMPONENT_Y].uiLog2WeightDenom = uiLog2WeightDenomLuma;
2592      for(Int j=1; j<numValidComp; j++)
2593      {
2594        wp[j].uiLog2WeightDenom = uiLog2WeightDenomChroma;
2595      }
2596
2597      UInt  uiCode;
2598      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
2599      wp[COMPONENT_Y].bPresentFlag = ( uiCode == 1 );
2600      uiTotalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag;
2601    }
2602    if ( bChroma )
2603    {
2604      UInt  uiCode;
2605      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
2606      {
2607        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2608        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
2609        for(Int j=1; j<numValidComp; j++)
2610        {
2611          wp[j].bPresentFlag = ( uiCode == 1 );
2612        }
2613        uiTotalSignalledWeightFlags += 2*wp[COMPONENT_Cb].bPresentFlag;
2614      }
2615    }
2616    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
2617    {
2618      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2619      if ( wp[COMPONENT_Y].bPresentFlag )
2620      {
2621        Int iDeltaWeight;
2622        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
2623        assert( iDeltaWeight >= -128 );
2624        assert( iDeltaWeight <=  127 );
2625        wp[COMPONENT_Y].iWeight = (iDeltaWeight + (1<<wp[COMPONENT_Y].uiLog2WeightDenom));
2626        READ_SVLC( wp[COMPONENT_Y].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
2627        Int range=sps->getUseHighPrecisionPredictionWeighting() ? (1<<g_bitDepth[CHANNEL_TYPE_LUMA])/2 : 128;
2628        assert( wp[0].iOffset >= -range );
2629        assert( wp[0].iOffset <   range );
2630      }
2631      else
2632      {
2633        wp[COMPONENT_Y].iWeight = (1 << wp[COMPONENT_Y].uiLog2WeightDenom);
2634        wp[COMPONENT_Y].iOffset = 0;
2635      }
2636      if ( bChroma )
2637      {
2638        if ( wp[COMPONENT_Cb].bPresentFlag )
2639        {
2640          Int range=sps->getUseHighPrecisionPredictionWeighting() ? (1<<g_bitDepth[CHANNEL_TYPE_CHROMA])/2 : 128;
2641          for ( Int j=1 ; j<numValidComp ; j++ )
2642          {
2643            Int iDeltaWeight;
2644            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
2645            assert( iDeltaWeight >= -128 );
2646            assert( iDeltaWeight <=  127 );
2647            wp[j].iWeight = (iDeltaWeight + (1<<wp[j].uiLog2WeightDenom));
2648
2649            Int iDeltaChroma;
2650            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
2651            assert( iDeltaChroma >= -4*range);
2652            assert( iDeltaChroma <   4*range);
2653            Int pred = ( range - ( ( range*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
2654            wp[j].iOffset = Clip3(-range, range-1, (iDeltaChroma + pred) );
2655          }
2656        }
2657        else
2658        {
2659          for ( Int j=1 ; j<numValidComp ; j++ )
2660          {
2661            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
2662            wp[j].iOffset = 0;
2663          }
2664        }
2665      }
2666    }
2667
2668    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
2669    {
2670      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
2671
2672      wp[0].bPresentFlag = false;
2673      wp[1].bPresentFlag = false;
2674      wp[2].bPresentFlag = false;
2675    }
2676  }
2677  assert(uiTotalSignalledWeightFlags<=24);
2678}
2679
2680/** decode quantization matrix
2681* \param scalingList quantization matrix information
2682*/
2683Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
2684{
2685  UInt  code, sizeId, listId;
2686  Bool scalingListPredModeFlag;
2687  //for each size
2688  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2689  {
2690    for(listId = 0; listId <  SCALING_LIST_NUM; listId++)
2691    {
2692      if ((sizeId==SCALING_LIST_32x32) && (listId%(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) != 0))
2693      {
2694        Int *src = scalingList->getScalingListAddress(sizeId, listId);
2695        const Int size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
2696        const Int *srcNextSmallerSize = scalingList->getScalingListAddress(sizeId-1, listId);
2697        for(Int i=0; i<size; i++)
2698        {
2699          src[i] = srcNextSmallerSize[i];
2700        }
2701        scalingList->setScalingListDC(sizeId,listId,(sizeId > SCALING_LIST_8x8) ? scalingList->getScalingListDC(sizeId-1, listId) : src[0]);
2702      }
2703      else
2704      {
2705        READ_FLAG( code, "scaling_list_pred_mode_flag");
2706        scalingListPredModeFlag = (code) ? true : false;
2707        if(!scalingListPredModeFlag) //Copy Mode
2708        {
2709          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
2710
2711          if (sizeId==SCALING_LIST_32x32)
2712            code*=(SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES); // Adjust the decoded code for this size, to cope with the missing 32x32 chroma entries.
2713
2714          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
2715          if( sizeId > SCALING_LIST_8x8 )
2716          {
2717            scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
2718          }
2719          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
2720
2721        }
2722        else //DPCM Mode
2723        {
2724          xDecodeScalingList(scalingList, sizeId, listId);
2725        }
2726      }
2727    }
2728  }
2729
2730  return;
2731}
2732/** decode DPCM
2733* \param scalingList  quantization matrix information
2734* \param sizeId size index
2735* \param listId list index
2736*/
2737Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
2738{
2739  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
2740  Int data;
2741  Int scalingListDcCoefMinus8 = 0;
2742  Int nextCoef = SCALING_LIST_START_VALUE;
2743  UInt* scan  = g_scanOrder[SCAN_UNGROUPED][SCAN_DIAG][sizeId==0 ? 2 : 3][sizeId==0 ? 2 : 3];
2744  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
2745
2746  if( sizeId > SCALING_LIST_8x8 )
2747  {
2748    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
2749    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
2750    nextCoef = scalingList->getScalingListDC(sizeId,listId);
2751  }
2752
2753  for(i = 0; i < coefNum; i++)
2754  {
2755    READ_SVLC( data, "scaling_list_delta_coef");
2756    nextCoef = (nextCoef + data + 256 ) % 256;
2757    dst[scan[i]] = nextCoef;
2758  }
2759}
2760
2761Bool TDecCavlc::xMoreRbspData()
2762{
2763  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
2764
2765  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
2766  if (bitsLeft > 8)
2767  {
2768    return true;
2769  }
2770
2771  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
2772  Int cnt = bitsLeft;
2773
2774  // remove trailing bits equal to zero
2775  while ((cnt>0) && ((lastByte & 1) == 0))
2776  {
2777    lastByte >>= 1;
2778    cnt--;
2779  }
2780  // remove bit equal to one
2781  cnt--;
2782
2783  // we should not have a negative number of bits
2784  assert (cnt>=0);
2785
2786  // we have more data, if cnt is not zero
2787  return (cnt>0);
2788}
2789
2790Void TDecCavlc::parseExplicitRdpcmMode( TComTU &rTu, ComponentID compID )
2791{
2792  assert(0);
2793}
2794
2795#if SVC_EXTENSION
2796Void TDecCavlc::parseVPSExtension(TComVPS *vps)
2797{
2798  UInt uiCode;
2799  // ... More syntax elements to be parsed here
2800#if P0300_ALT_OUTPUT_LAYER_FLAG
2801  Int NumOutputLayersInOutputLayerSet[MAX_VPS_LAYER_SETS_PLUS1];
2802  Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
2803#endif
2804#if LIST_OF_PTL
2805  if( vps->getMaxLayers() > 1 && vps->getBaseLayerInternalFlag() )
2806  {
2807    vps->setProfilePresentFlag(1, false);
2808#if MULTIPLE_PTL_SUPPORT
2809    parsePTL( vps->getPTL(1), vps->getProfilePresentFlag(1), vps->getMaxTLayers() - 1 );
2810#else
2811    vps->getPTLForExtnPtr()->empty();
2812    vps->getPTLForExtnPtr()->resize(2);
2813    vps->getPTLForExtn(1)->copyProfileInfo( vps->getPTL() );
2814    parsePTL( vps->getPTLForExtn(1), vps->getProfilePresentFlag(1), vps->getMaxTLayers() - 1 );
2815#endif
2816  }
2817#endif
2818#if VPS_EXTN_MASK_AND_DIM_INFO
2819  UInt numScalabilityTypes = 0, i = 0, j = 0;
2820
2821#if !VPS_AVC_BL_FLAG_REMOVAL
2822  READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
2823#endif
2824
2825#if !P0307_REMOVE_VPS_VUI_OFFSET
2826#if O0109_MOVE_VPS_VUI_FLAG
2827  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
2828  if ( uiCode )
2829  {
2830#endif
2831#if VPS_VUI_OFFSET
2832    READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
2833#endif
2834#if O0109_MOVE_VPS_VUI_FLAG
2835  }
2836#endif
2837#endif
2838  READ_FLAG( uiCode, "splitting_flag" ); vps->setSplittingFlag(uiCode ? true : false);
2839
2840  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
2841  {
2842    READ_FLAG( uiCode, "scalability_mask[i]" ); vps->setScalabilityMask(i, uiCode ? true : false);
2843    numScalabilityTypes += uiCode;
2844  }
2845  vps->setNumScalabilityTypes(numScalabilityTypes);
2846
2847  for(j = 0; j < numScalabilityTypes - vps->getSplittingFlag(); j++)
2848  {
2849    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
2850  }
2851
2852  // The value of dimBitOffset[ NumScalabilityTypes ] is set equal to 6.
2853  if(vps->getSplittingFlag())
2854  {
2855    UInt numBits = 0;
2856    for(j = 0; j < numScalabilityTypes - 1; j++)
2857    {
2858      numBits += vps->getDimensionIdLen(j);
2859    }
2860    assert( numBits < 6 );
2861    vps->setDimensionIdLen(numScalabilityTypes-1, 6 - numBits);
2862    numBits = 6;
2863  }
2864
2865  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
2866  vps->setLayerIdInNuh(0, 0);
2867  vps->setLayerIdxInVps(0, 0);
2868  for(i = 1; i < vps->getMaxLayers(); i++)
2869  {
2870    if( vps->getNuhLayerIdPresentFlag() )
2871    {
2872      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" ); vps->setLayerIdInNuh(i, uiCode);
2873      assert( uiCode > vps->getLayerIdInNuh(i-1) );
2874    }
2875    else
2876    {
2877      vps->setLayerIdInNuh(i, i);
2878    }
2879    vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
2880
2881    if( !vps->getSplittingFlag() )
2882    {
2883      for(j = 0; j < numScalabilityTypes; j++)
2884      {
2885        READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
2886#if !AUXILIARY_PICTURES
2887        assert( uiCode <= vps->getMaxLayerId() );
2888#endif
2889      }
2890    }
2891  }
2892#endif
2893#if VIEW_ID_RELATED_SIGNALING
2894#if O0109_VIEW_ID_LEN
2895  READ_CODE( 4, uiCode, "view_id_len" ); vps->setViewIdLen( uiCode );
2896#else
2897  READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
2898#endif
2899
2900#if O0109_VIEW_ID_LEN
2901  if ( vps->getViewIdLen() > 0 )
2902  {
2903    for(  i = 0; i < vps->getNumViews(); i++ )
2904    {
2905      READ_CODE( vps->getViewIdLen( ), uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
2906    }
2907  }
2908#else
2909  for(  i = 0; i < vps->getNumViews(); i++ )
2910  {
2911    READ_CODE( vps->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
2912  }
2913#endif
2914#endif // view id related signaling
2915#if VPS_EXTN_DIRECT_REF_LAYERS
2916  // For layer 0
2917  vps->setNumDirectRefLayers(0, 0);
2918  // For other layers
2919  for( Int layerCtr = 1; layerCtr < vps->getMaxLayers(); layerCtr++)
2920  {
2921    UInt layerId = vps->getLayerIdInNuh(layerCtr); 
2922    UInt numDirectRefLayers = 0;
2923    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
2924    {
2925      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
2926      if(uiCode)
2927      {
2928        vps->setRefLayerId(layerId, numDirectRefLayers, vps->getLayerIdInNuh(refLayerCtr));
2929        numDirectRefLayers++;
2930      }
2931    }
2932    vps->setNumDirectRefLayers(layerId, numDirectRefLayers);
2933  }
2934#endif
2935#if Q0078_ADD_LAYER_SETS
2936#if O0092_0094_DEPENDENCY_CONSTRAINT // Moved here
2937  vps->setNumRefLayers();
2938
2939  if (vps->getMaxLayers() > MAX_REF_LAYERS)
2940  {
2941    for (i = 1; i < vps->getMaxLayers(); i++)
2942    {
2943      assert(vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
2944    }
2945  }
2946#endif
2947  vps->setPredictedLayerIds();
2948  vps->setTreePartitionLayerIdList();
2949#endif
2950#if MOVE_ADDN_LS_SIGNALLING
2951#if Q0078_ADD_LAYER_SETS
2952  if (vps->getNumIndependentLayers() > 1)
2953  {
2954    READ_UVLC(uiCode, "num_add_layer_sets"); vps->setNumAddLayerSets(uiCode);
2955    for (i = 0; i < vps->getNumAddLayerSets(); i++)
2956    {
2957      for (j = 1; j < vps->getNumIndependentLayers(); j++)
2958      {
2959        int len = 1;
2960        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
2961        {
2962          len++;
2963        }
2964        READ_CODE(len, uiCode, "highest_layer_idx_plus1[i][j]"); vps->setHighestLayerIdxPlus1(i, j, uiCode);
2965      }
2966    }
2967    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
2968#if FIX_LAYER_ID_INIT
2969    vps->deriveLayerIdListVariablesForAddLayerSets();
2970#else
2971    vps->setLayerIdIncludedFlagsForAddLayerSets();
2972#endif
2973  }
2974  else
2975  {
2976    vps->setNumAddLayerSets(0);
2977  }
2978#endif
2979#endif
2980#if VPS_TSLAYERS
2981  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
2982
2983  if (vps->getMaxTSLayersPresentFlag())
2984  {
2985    for(i = 0; i < vps->getMaxLayers(); i++)
2986    {
2987      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
2988    }
2989  }
2990  else
2991  {
2992    for( i = 0; i < vps->getMaxLayers(); i++)
2993    {
2994      vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
2995    }
2996  }
2997#endif
2998  READ_FLAG( uiCode, "max_tid_ref_present_flag"); vps->setMaxTidRefPresentFlag(uiCode ? true : false);
2999  if (vps->getMaxTidRefPresentFlag())
3000  {
3001    for(i = 0; i < vps->getMaxLayers() - 1; i++)
3002    {
3003      for( j = i+1; j < vps->getMaxLayers(); j++)
3004      {
3005        if(vps->getDirectDependencyFlag(j, i))
3006        {
3007          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);         
3008        }
3009      }
3010    }
3011  }
3012  else
3013  {
3014    for(i = 0; i < vps->getMaxLayers() - 1; i++)
3015    {
3016      for( j = i+1; j < vps->getMaxLayers(); j++)
3017      {
3018        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
3019      }
3020    }
3021  }
3022  READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
3023#if VPS_EXTN_PROFILE_INFO
3024  // Profile-tier-level signalling
3025#if !VPS_EXTN_UEV_CODING
3026  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1" );     assert( uiCode == (vps->getNumLayerSets() - 1) );
3027  READ_CODE(  6, uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
3028#else
3029  READ_UVLC(  uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
3030#endif
3031#if PER_LAYER_PTL
3032  Int const numBitsForPtlIdx = vps->calculateLenOfSyntaxElement( vps->getNumProfileTierLevel() );
3033#endif
3034#if !MULTIPLE_PTL_SUPPORT
3035  vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
3036#endif
3037#if LIST_OF_PTL
3038  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx < vps->getNumProfileTierLevel(); idx++)
3039#else
3040  for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
3041#endif
3042  {
3043    READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
3044    if( !vps->getProfilePresentFlag(idx) )
3045    {
3046#if P0048_REMOVE_PROFILE_REF
3047      // Copy profile information from previous one
3048#if MULTIPLE_PTL_SUPPORT
3049      vps->getPTL(idx)->copyProfileInfo( vps->getPTL( idx - 1 ) );
3050#else
3051      vps->getPTLForExtn(idx)->copyProfileInfo( (idx==1) ? vps->getPTL() : vps->getPTLForExtn( idx - 1 ) );
3052#endif
3053#else
3054      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
3055#if O0109_PROF_REF_MINUS1
3056      assert( vps->getProfileLayerSetRef(idx) <= idx );
3057#else
3058      assert( vps->getProfileLayerSetRef(idx) < idx );
3059#endif
3060      // Copy profile information as indicated
3061      vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
3062#endif
3063    }
3064#if MULTIPLE_PTL_SUPPORT
3065    parsePTL( vps->getPTL(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
3066#else
3067    parsePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
3068#endif
3069  }
3070#endif
3071
3072#if !MOVE_ADDN_LS_SIGNALLING
3073#if Q0078_ADD_LAYER_SETS
3074  if (vps->getNumIndependentLayers() > 1)
3075  {
3076    READ_UVLC(uiCode, "num_add_layer_sets"); vps->setNumAddLayerSets(uiCode);
3077    for (i = 0; i < vps->getNumAddLayerSets(); i++)
3078    {
3079      for (j = 1; j < vps->getNumIndependentLayers(); j++)
3080      {
3081        int len = 1;
3082        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
3083        {
3084          len++;
3085        }
3086        READ_CODE(len, uiCode, "highest_layer_idx_plus1[i][j]"); vps->setHighestLayerIdxPlus1(i, j, uiCode);
3087      }
3088    }
3089    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
3090    vps->setLayerIdIncludedFlagsForAddLayerSets();
3091  }
3092#endif
3093#endif
3094
3095#if !VPS_EXTN_UEV_CODING
3096  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
3097  Int numOutputLayerSets = 0;
3098  if(! vps->getMoreOutputLayerSetsThanDefaultFlag() )
3099  {
3100    numOutputLayerSets = vps->getNumLayerSets();
3101  }
3102  else
3103  {
3104    READ_CODE( 10, uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
3105    numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
3106  }
3107#else
3108
3109#if Q0165_NUM_ADD_OUTPUT_LAYER_SETS
3110  if( vps->getNumLayerSets() > 1 )
3111  {
3112    READ_UVLC( uiCode, "num_add_olss" );            vps->setNumAddOutputLayerSets( uiCode );
3113    READ_CODE( 2, uiCode, "default_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
3114  }
3115  else
3116  {
3117    vps->setNumAddOutputLayerSets( 0 );
3118  }
3119#else
3120  READ_UVLC( uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
3121#endif
3122
3123  // The value of num_add_olss shall be in the range of 0 to 1023, inclusive.
3124  assert( vps->getNumAddOutputLayerSets() >= 0 && vps->getNumAddOutputLayerSets() < 1024 );
3125
3126  Int numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
3127#endif
3128
3129#if P0295_DEFAULT_OUT_LAYER_IDC
3130#if !Q0165_NUM_ADD_OUTPUT_LAYER_SETS
3131  if( numOutputLayerSets > 1 )
3132  {
3133    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
3134  }
3135#endif
3136  vps->setNumOutputLayerSets( numOutputLayerSets );
3137#if NECESSARY_LAYER_FLAG
3138  // Default output layer set
3139  vps->setOutputLayerSetIdx(0, 0);
3140  vps->setOutputLayerFlag(0, 0, true);
3141  vps->deriveNecessaryLayerFlag(0);
3142#if PER_LAYER_PTL
3143  vps->getProfileLevelTierIdx()->resize(numOutputLayerSets);
3144  vps->getProfileLevelTierIdx(0)->push_back( vps->getBaseLayerInternalFlag() && vps->getMaxLayers() > 1 ? 1 : 0);
3145#endif
3146#endif
3147  for(i = 1; i < numOutputLayerSets; i++)
3148  {
3149#if VPS_FIX_TO_MATCH_SPEC
3150    if( vps->getNumLayerSets() > 2 && i >= vps->getNumLayerSets() )
3151#else
3152    if( i > (vps->getNumLayerSets() - 1) )
3153#endif
3154    {
3155      Int numBits = 1;
3156      while ((1 << numBits) < (vps->getNumLayerSets() - 1))
3157      {
3158        numBits++;
3159      }
3160      READ_CODE( numBits, uiCode, "layer_set_idx_for_ols_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
3161    }
3162    else
3163    {
3164      vps->setOutputLayerSetIdx( i, i );
3165    }
3166    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
3167#if Q0078_ADD_LAYER_SETS
3168#if VPS_FIX_TO_MATCH_SPEC
3169    if( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() == 2 )
3170#else
3171    if( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 )
3172#endif
3173#else
3174#if VPS_FIX_TO_MATCH_SPEC
3175    if( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() == 2 )
3176#else
3177    if( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 )
3178#endif
3179#endif
3180    {
3181#if NUM_OL_FLAGS
3182      for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
3183#else
3184      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
3185#endif
3186      {
3187        READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
3188      }
3189    }
3190    else
3191    {
3192      // i <= (vps->getNumLayerSets() - 1)
3193      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
3194      if( vps->getDefaultTargetOutputLayerIdc() == 1 )
3195      {
3196        for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
3197        {
3198#if DEF_OPT_LAYER_IDC
3199          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet)-1))  );
3200
3201#else
3202          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet)-1)) && (vps->getDimensionId(j,1) == 0) );
3203#endif
3204        }
3205      }
3206      else if ( vps->getDefaultTargetOutputLayerIdc() == 0 )
3207      {
3208        for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
3209        {
3210          vps->setOutputLayerFlag(i, j, 1);
3211        }
3212      }
3213    }
3214#if NECESSARY_LAYER_FLAG
3215    vps->deriveNecessaryLayerFlag(i); 
3216#endif
3217#if PER_LAYER_PTL
3218    vps->getProfileLevelTierIdx(i)->assign(vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet), -1);
3219    for(j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet) ; j++)
3220    {
3221#if VPS_FIX_TO_MATCH_SPEC
3222      if( vps->getNecessaryLayerFlag(i, j) && (vps->getNumProfileTierLevel()-1) > 0 )
3223#else
3224      if( vps->getNecessaryLayerFlag(i, j) )
3225#endif
3226      {
3227        READ_CODE( numBitsForPtlIdx, uiCode, "profile_tier_level_idx[i]" ); 
3228        vps->setProfileLevelTierIdx(i, j, uiCode );
3229
3230#if MULTIPLE_PTL_SUPPORT
3231        //For conformance checking
3232        //Conformance of a layer in an output operation point associated with an OLS in a bitstream to the Scalable Main profile is indicated as follows:
3233        //If OpTid of the output operation point is equal to vps_max_sub_layer_minus1, the conformance is indicated by general_profile_idc being equal to 7 or general_profile_compatibility_flag[ 7 ] being equal to 1
3234        //Conformance of a layer in an output operation point associated with an OLS in a bitstream to the Scalable Main 10 profile is indicated as follows:
3235        //If OpTid of the output operation point is equal to vps_max_sub_layer_minus1, the conformance is indicated by general_profile_idc being equal to 7 or general_profile_compatibility_flag[ 7 ] being equal to 1
3236        //The following assert may be updated / upgraded to take care of general_profile_compatibility_flag.
3237#if R0235_SMALLEST_LAYER_ID
3238        // The assertion below is not valid for independent non-base layers
3239        if (vps->getNumAddLayerSets() == 0)
3240        {
3241#endif
3242        if( j > 0 && vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j) != 0 && vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j - 1) != 0 && vps->getNecessaryLayerFlag(i, j-1) )
3243        {
3244          assert(vps->getPTL(vps->getProfileLevelTierIdx(i, j))->getGeneralPTL()->getProfileIdc() == vps->getPTL(vps->getProfileLevelTierIdx(i, j - 1))->getGeneralPTL()->getProfileIdc() ||
3245                 vps->getPTL(vps->getProfileLevelTierIdx(i, j - 1))->getGeneralPTL()->getProfileCompatibilityFlag(vps->getPTL(vps->getProfileLevelTierIdx(i, j))->getGeneralPTL()->getProfileIdc()) || 
3246                 vps->getPTL(vps->getProfileLevelTierIdx(i, j))->getGeneralPTL()->getProfileCompatibilityFlag(vps->getPTL(vps->getProfileLevelTierIdx(i, j - 1))->getGeneralPTL()->getProfileIdc())  );
3247        }
3248#if R0235_SMALLEST_LAYER_ID
3249        }
3250#endif
3251#endif
3252      }
3253    }
3254#else
3255    Int numBits = 1;
3256    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
3257    {
3258      numBits++;
3259    }
3260    READ_CODE( numBits, uiCode, "profile_tier_level_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
3261#endif
3262#if P0300_ALT_OUTPUT_LAYER_FLAG
3263    NumOutputLayersInOutputLayerSet[i] = 0;
3264    for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
3265    {
3266      NumOutputLayersInOutputLayerSet[i] += vps->getOutputLayerFlag(i, j);
3267      if (vps->getOutputLayerFlag(i, j))
3268      {
3269        OlsHighestOutputLayerId[i] = vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j);
3270      }
3271    }
3272    if (NumOutputLayersInOutputLayerSet[i] == 1 && vps->getNumDirectRefLayers(OlsHighestOutputLayerId[i]) > 0)
3273    {
3274      READ_FLAG(uiCode, "alt_output_layer_flag[i]");
3275      vps->setAltOuputLayerFlag(i, uiCode ? true : false);
3276    }
3277#if ALT_OPT_LAYER_FLAG
3278    else
3279    {
3280          uiCode=0;
3281          vps->setAltOuputLayerFlag(i, uiCode ? true : false);
3282    }
3283#endif
3284#if Q0165_OUTPUT_LAYER_SET
3285    assert( NumOutputLayersInOutputLayerSet[i]>0 );
3286#endif
3287
3288#endif
3289  }
3290#if NECESSARY_LAYER_FLAG
3291  vps->checkNecessaryLayerFlagCondition(); 
3292#endif
3293#else
3294  if( numOutputLayerSets > 1 )
3295  {
3296#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
3297    READ_CODE( 2, uiCode, "default_one_target_output_layer_idc" );   vps->setDefaultOneTargetOutputLayerIdc( uiCode );
3298#else
3299    READ_FLAG( uiCode, "default_one_target_output_layer_flag" );   vps->setDefaultOneTargetOutputLayerFlag( uiCode ? true : false );
3300#endif
3301  }
3302  vps->setNumOutputLayerSets( numOutputLayerSets );
3303
3304  for(i = 1; i < numOutputLayerSets; i++)
3305  {
3306    if( i > (vps->getNumLayerSets() - 1) )
3307    {
3308      Int numBits = 1;
3309      while ((1 << numBits) < (vps->getNumLayerSets() - 1))
3310      {
3311        numBits++;
3312      }
3313      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
3314      Int lsIdx = vps->getOutputLayerSetIdx(i);
3315#if NUM_OL_FLAGS
3316      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) ; j++)
3317#else
3318      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
3319#endif
3320      {
3321        READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
3322      }
3323    }
3324    else
3325    {
3326#if VPS_DPB_SIZE_TABLE
3327      vps->setOutputLayerSetIdx( i, i );
3328#endif
3329      // i <= (vps->getNumLayerSets() - 1)
3330      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
3331      Int lsIdx = i;
3332#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
3333      if( vps->getDefaultOneTargetOutputLayerIdc() == 1 )
3334      {
3335        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
3336        {
3337#if O0135_DEFAULT_ONE_OUT_SEMANTIC
3338#if DEF_OPT_LAYER_IDC
3339        vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) );
3340#else
3341          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1)==0) );
3342#endif
3343#else
3344          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
3345#endif
3346        }
3347      }
3348      else if ( vps->getDefaultOneTargetOutputLayerIdc() == 0 )
3349      {
3350        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
3351        {
3352          vps->setOutputLayerFlag(i, j, 1);
3353        }
3354      }
3355      else
3356      {
3357        // Other values of default_one_target_output_layer_idc than 0 and 1 are reserved for future use.
3358      }
3359#else
3360      if( vps->getDefaultOneTargetOutputLayerFlag() )
3361      {
3362        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
3363        {
3364          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
3365        }
3366      }
3367      else
3368      {
3369        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
3370        {
3371          vps->setOutputLayerFlag(i, j, 1);
3372        }
3373      }
3374#endif
3375    }
3376    Int numBits = 1;
3377    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
3378    {
3379      numBits++;
3380    }
3381    READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
3382  }
3383#endif
3384
3385#if !P0300_ALT_OUTPUT_LAYER_FLAG
3386#if O0153_ALT_OUTPUT_LAYER_FLAG
3387  if( vps->getMaxLayers() > 1 )
3388  {
3389    READ_FLAG( uiCode, "alt_output_layer_flag");
3390    vps->setAltOuputLayerFlag( uiCode ? true : false );
3391  }
3392#endif
3393#endif
3394
3395#if REPN_FORMAT_IN_VPS
3396#if Q0195_REP_FORMAT_CLEANUP
3397  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
3398  vps->setVpsNumRepFormats( uiCode + 1 );
3399
3400  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
3401  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
3402
3403  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
3404  {
3405    // Read rep_format_structures
3406    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
3407  }
3408
3409  // Default assignment for layer 0
3410  vps->setVpsRepFormatIdx( 0, 0 );
3411
3412  if( vps->getVpsNumRepFormats() > 1 )
3413  {
3414    READ_FLAG( uiCode, "rep_format_idx_present_flag");
3415    vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
3416  }
3417  else
3418  {
3419    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
3420    vps->setRepFormatIdxPresentFlag( false );
3421  }
3422
3423  if( vps->getRepFormatIdxPresentFlag() )
3424  {
3425#if VPS_FIX_TO_MATCH_SPEC
3426    for( i = vps->getBaseLayerInternalFlag() ? 1 : 0; i < vps->getMaxLayers(); i++ )
3427#else
3428    for (i = 1; i < vps->getMaxLayers(); i++)
3429#endif
3430    {
3431      Int numBits = 1;
3432      while ((1 << numBits) < (vps->getVpsNumRepFormats()))
3433      {
3434        numBits++;
3435      }
3436      READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
3437      vps->setVpsRepFormatIdx( i, uiCode );
3438    }
3439  }
3440  else
3441  {
3442    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min (i, vps_num_rep_formats_minus1)
3443    for(i = 1; i < vps->getMaxLayers(); i++)
3444    {
3445      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats()-1 ) );
3446    }
3447  }
3448#else
3449  READ_FLAG( uiCode, "rep_format_idx_present_flag");
3450  vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
3451
3452  if( vps->getRepFormatIdxPresentFlag() )
3453  {
3454#if O0096_REP_FORMAT_INDEX
3455#if !VPS_EXTN_UEV_CODING
3456    READ_CODE( 8, uiCode, "vps_num_rep_formats_minus1" );
3457#else
3458    READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
3459#endif
3460#else
3461    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" );
3462#endif
3463    vps->setVpsNumRepFormats( uiCode + 1 );
3464  }
3465  else
3466  {
3467    // default assignment
3468    assert (vps->getMaxLayers() <= 16);       // If max_layers_is more than 15, num_rep_formats has to be signaled
3469    vps->setVpsNumRepFormats( vps->getMaxLayers() );
3470  }
3471
3472  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
3473  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
3474
3475  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
3476  {
3477    // Read rep_format_structures
3478    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
3479  }
3480
3481  // Default assignment for layer 0
3482  vps->setVpsRepFormatIdx( 0, 0 );
3483  if( vps->getRepFormatIdxPresentFlag() )
3484  {
3485    for(i = 1; i < vps->getMaxLayers(); i++)
3486    {
3487      if( vps->getVpsNumRepFormats() > 1 )
3488      {
3489#if O0096_REP_FORMAT_INDEX
3490#if !VPS_EXTN_UEV_CODING
3491        READ_CODE( 8, uiCode, "vps_rep_format_idx[i]" );
3492#else
3493        Int numBits = 1;
3494        while ((1 << numBits) < (vps->getVpsNumRepFormats()))
3495        {
3496          numBits++;
3497        }
3498        READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
3499#endif
3500#else
3501        READ_CODE( 4, uiCode, "vps_rep_format_idx[i]" );
3502#endif
3503        vps->setVpsRepFormatIdx( i, uiCode );
3504      }
3505      else
3506      {
3507        // default assignment - only one rep_format() structure
3508        vps->setVpsRepFormatIdx( i, 0 );
3509      }
3510    }
3511  }
3512  else
3513  {
3514    // default assignment - each layer assigned each rep_format() structure in the order signaled
3515    for(i = 1; i < vps->getMaxLayers(); i++)
3516    {
3517      vps->setVpsRepFormatIdx( i, i );
3518    }
3519  }
3520#endif
3521#endif
3522#if RESOLUTION_BASED_DPB
3523  vps->assignSubDpbIndices();
3524#endif
3525  READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
3526  vps->setMaxOneActiveRefLayerFlag(uiCode);
3527#if P0297_VPS_POC_LSB_ALIGNED_FLAG
3528  READ_FLAG(uiCode, "vps_poc_lsb_aligned_flag");
3529  vps->setVpsPocLsbAlignedFlag(uiCode);
3530#endif
3531#if O0062_POC_LSB_NOT_PRESENT_FLAG
3532  for(i = 1; i< vps->getMaxLayers(); i++)
3533  {
3534    if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
3535    {
3536      READ_FLAG(uiCode, "poc_lsb_not_present_flag[i]");
3537      vps->setPocLsbNotPresentFlag(i, uiCode);
3538    }
3539  }
3540#endif
3541#if O0215_PHASE_ALIGNMENT
3542  READ_FLAG( uiCode, "cross_layer_phase_alignment_flag"); vps->setPhaseAlignFlag( uiCode == 1 ? true : false );
3543#endif
3544
3545#if !IRAP_ALIGN_FLAG_IN_VPS_VUI
3546  READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
3547  vps->setCrossLayerIrapAlignFlag(uiCode);
3548#endif
3549
3550#if VPS_DPB_SIZE_TABLE
3551  parseVpsDpbSizeTable(vps);
3552#endif
3553
3554#if VPS_EXTN_DIRECT_REF_LAYERS
3555  READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
3556#if O0096_DEFAULT_DEPENDENCY_TYPE
3557  READ_FLAG(uiCode, "default_direct_dependency_type_flag"); 
3558  vps->setDefaultDirectDependecyTypeFlag(uiCode == 1? true : false);
3559  if (vps->getDefaultDirectDependencyTypeFlag())
3560  {
3561    READ_CODE( vps->getDirectDepTypeLen(), uiCode, "default_direct_dependency_type" ); 
3562    vps->setDefaultDirectDependecyType(uiCode);
3563  }
3564#endif
3565
3566#if VPS_FIX_TO_MATCH_SPEC
3567  for( i = vps->getBaseLayerInternalFlag() ? 1 : 2; i < vps->getMaxLayers(); i++ )
3568#else
3569  for(i = 1; i < vps->getMaxLayers(); i++)
3570#endif
3571  {
3572#if VPS_FIX_TO_MATCH_SPEC
3573    for( j = vps->getBaseLayerInternalFlag() ? 0 : 1; j < i; j++ )
3574#else
3575    for(j = 0; j < i; j++)
3576#endif
3577    {
3578      if (vps->getDirectDependencyFlag(i, j))
3579      {
3580#if O0096_DEFAULT_DEPENDENCY_TYPE
3581        if (vps->getDefaultDirectDependencyTypeFlag())
3582        {
3583          vps->setDirectDependencyType(i, j, vps->getDefaultDirectDependencyType());
3584        }
3585        else
3586        {
3587          READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); 
3588          vps->setDirectDependencyType(i, j, uiCode);
3589        }
3590#else
3591        READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); 
3592        vps->setDirectDependencyType(i, j, uiCode);
3593#endif
3594      }
3595    }
3596  }
3597#endif
3598#if !Q0078_ADD_LAYER_SETS
3599#if O0092_0094_DEPENDENCY_CONSTRAINT // Moved up
3600  vps->setNumRefLayers();
3601
3602  if(vps->getMaxLayers() > MAX_REF_LAYERS)
3603  {
3604    for(i = 1;i < vps->getMaxLayers(); i++)
3605    {
3606      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
3607    }
3608  }
3609#endif
3610#endif
3611
3612#if P0307_VPS_NON_VUI_EXTENSION
3613  READ_UVLC( uiCode,           "vps_non_vui_extension_length"); vps->setVpsNonVuiExtLength((Int)uiCode);
3614
3615  // The value of vps_non_vui_extension_length shall be in the range of 0 to 4096, inclusive.
3616  assert( vps->getVpsNonVuiExtLength() >= 0 && vps->getVpsNonVuiExtLength() <= 4096 );
3617
3618#if P0307_VPS_NON_VUI_EXT_UPDATE
3619  Int nonVuiExtByte = uiCode;
3620  for (i = 1; i <= nonVuiExtByte; i++)
3621  {
3622    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" ); //just parse and discard for now.
3623  }
3624#else
3625  if ( vps->getVpsNonVuiExtLength() > 0 )
3626  {
3627    printf("\n\nUp to the current spec, the value of vps_non_vui_extension_length is supposed to be 0\n");
3628  }
3629#endif
3630#endif
3631
3632#if !O0109_O0199_FLAGS_TO_VUI
3633#if M0040_ADAPTIVE_RESOLUTION_CHANGE
3634  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
3635#endif
3636#if HIGHER_LAYER_IRAP_SKIP_FLAG
3637  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
3638#endif
3639#endif
3640
3641#if P0307_REMOVE_VPS_VUI_OFFSET
3642  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
3643#endif
3644
3645#if O0109_MOVE_VPS_VUI_FLAG
3646  if ( vps->getVpsVuiPresentFlag() )
3647#else
3648  READ_FLAG( uiCode,  "vps_vui_present_flag" );
3649  if (uiCode)
3650#endif
3651  {
3652    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
3653    {
3654      READ_FLAG( uiCode, "vps_vui_alignment_bit_equal_to_one"); assert(uiCode == 1);
3655    }
3656    parseVPSVUI(vps);
3657  }
3658  else
3659  {
3660    // set default values for VPS VUI
3661    defaultVPSVUI( vps );
3662  }
3663}
3664
3665Void TDecCavlc::defaultVPSExtension( TComVPS* vps )
3666{
3667  // set default parameters when they are not present
3668  Int i, j;
3669
3670  // When layer_id_in_nuh[ i ] is not present, the value is inferred to be equal to i.
3671  for(i = 0; i < vps->getMaxLayers(); i++)
3672  {
3673    vps->setLayerIdInNuh(i, i);
3674    vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
3675  }
3676
3677  // When not present, sub_layers_vps_max_minus1[ i ] is inferred to be equal to vps_max_sub_layers_minus1.
3678  for( i = 0; i < vps->getMaxLayers(); i++)
3679  {
3680    vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
3681  }
3682
3683  // When not present, max_tid_il_ref_pics_plus1[ i ][ j ] is inferred to be equal to 7.
3684  for( i = 0; i < vps->getMaxLayers() - 1; i++ )
3685  {
3686    for( j = i + 1; j < vps->getMaxLayers(); j++ )
3687    {
3688      vps->setMaxTidIlRefPicsPlus1(i, j, 7);
3689    }
3690  }
3691
3692  // When not present, the value of num_add_olss is inferred to be equal to 0.
3693  // NumOutputLayerSets = num_add_olss + NumLayerSets
3694  vps->setNumOutputLayerSets( vps->getNumLayerSets() );
3695
3696  // For i in the range of 0 to NumOutputLayerSets-1, inclusive, the variable LayerSetIdxForOutputLayerSet[ i ] is derived as specified in the following:
3697  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : layer_set_idx_for_ols_minus1[ i ] + 1
3698  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
3699  {
3700    vps->setOutputLayerSetIdx( i, i );
3701    Int lsIdx = vps->getOutputLayerSetIdx(i);
3702
3703    for( j = 0; j < vps->getNumLayersInIdList(lsIdx); j++ )
3704    {
3705      vps->setOutputLayerFlag(i, j, 1);
3706    }
3707  }
3708
3709#if NECESSARY_LAYER_FLAG
3710  // Default output layer set
3711  // The value of NumLayersInIdList[ 0 ] is set equal to 1 and the value of LayerSetLayerIdList[ 0 ][ 0 ] is set equal to 0.
3712  vps->setOutputLayerSetIdx(0, 0);
3713
3714  // The value of output_layer_flag[ 0 ][ 0 ] is inferred to be equal to 1.
3715  vps->setOutputLayerFlag(0, 0, true);
3716
3717  vps->deriveNecessaryLayerFlag(0);
3718#endif
3719
3720  // The value of sub_layer_dpb_info_present_flag[ i ][ 0 ] for any possible value of i is inferred to be equal to 1
3721  // When not present, the value of sub_layer_dpb_info_present_flag[ i ][ j ] for j greater than 0 and any possible value of i, is inferred to be equal to be equal to 0.
3722  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
3723  {
3724    vps->setSubLayerDpbInfoPresentFlag( i, 0, true );
3725  }
3726
3727  // When not present, the value of vps_num_rep_formats_minus1 is inferred to be equal to MaxLayersMinus1.
3728  vps->setVpsNumRepFormats( vps->getMaxLayers() );
3729
3730  // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
3731  vps->setRepFormatIdxPresentFlag( false );
3732
3733  if( !vps->getRepFormatIdxPresentFlag() )
3734  {
3735    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min(i, vps_num_rep_formats_minus1).
3736    for(i = 1; i < vps->getMaxLayers(); i++)
3737    {
3738      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats() - 1 ) );
3739    }
3740  }
3741
3742#if P0297_VPS_POC_LSB_ALIGNED_FLAG
3743  vps->setVpsPocLsbAlignedFlag(false);
3744#endif
3745
3746#if O0062_POC_LSB_NOT_PRESENT_FLAG
3747  // When not present, poc_lsb_not_present_flag[ i ] is inferred to be equal to 0.
3748  for(i = 1; i< vps->getMaxLayers(); i++)
3749  {
3750    vps->setPocLsbNotPresentFlag(i, 0);
3751  }
3752#endif
3753
3754  // set default values for VPS VUI
3755  defaultVPSVUI( vps );
3756}
3757
3758Void TDecCavlc::defaultVPSVUI( TComVPS* vps )
3759{
3760  // When not present, the value of all_layers_idr_aligned_flag is inferred to be equal to 0.
3761  vps->setCrossLayerIrapAlignFlag( false );
3762
3763#if M0040_ADAPTIVE_RESOLUTION_CHANGE
3764  // When single_layer_for_non_irap_flag is not present, it is inferred to be equal to 0.
3765  vps->setSingleLayerForNonIrapFlag( false );
3766#endif
3767
3768#if HIGHER_LAYER_IRAP_SKIP_FLAG
3769  // When higher_layer_irap_skip_flag is not present it is inferred to be equal to 0
3770  vps->setHigherLayerIrapSkipFlag( false );
3771#endif
3772}
3773
3774#if REPN_FORMAT_IN_VPS
3775Void  TDecCavlc::parseRepFormat( RepFormat *repFormat, RepFormat *repFormatPrev )
3776{
3777  UInt uiCode;
3778#if REPN_FORMAT_CONTROL_FLAG 
3779  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );        repFormat->setPicWidthVpsInLumaSamples ( uiCode );
3780  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" );       repFormat->setPicHeightVpsInLumaSamples( uiCode );
3781  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" );    repFormat->setChromaAndBitDepthVpsPresentFlag( uiCode ? true : false ); 
3782
3783  if( !repFormatPrev )
3784  {
3785    // The value of chroma_and_bit_depth_vps_present_flag of the first rep_format( ) syntax structure in the VPS shall be equal to 1
3786    assert( repFormat->getChromaAndBitDepthVpsPresentFlag() );
3787  }
3788
3789  if( repFormat->getChromaAndBitDepthVpsPresentFlag() )
3790  {
3791    READ_CODE( 2, uiCode, "chroma_format_vps_idc" );
3792#if AUXILIARY_PICTURES
3793    repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
3794#else
3795    repFormat->setChromaFormatVpsIdc( uiCode );
3796#endif
3797
3798    if( repFormat->getChromaFormatVpsIdc() == 3 )
3799    {
3800      READ_FLAG( uiCode, "separate_colour_plane_vps_flag" );       repFormat->setSeparateColourPlaneVpsFlag( uiCode ? true : false );
3801    }
3802
3803    READ_CODE( 4, uiCode, "bit_depth_vps_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
3804    READ_CODE( 4, uiCode, "bit_depth_vps_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
3805  }
3806  else if( repFormatPrev )
3807  {
3808    // chroma_and_bit_depth_vps_present_flag equal to 0 specifies that the syntax elements, chroma_format_vps_idc, separate_colour_plane_vps_flag, bit_depth_vps_luma_minus8, and
3809    // bit_depth_vps_chroma_minus8 are not present and inferred from the previous rep_format( ) syntax structure in the VPS.
3810
3811    repFormat->setChromaFormatVpsIdc        ( repFormatPrev->getChromaFormatVpsIdc() );
3812    repFormat->setSeparateColourPlaneVpsFlag( repFormatPrev->getSeparateColourPlaneVpsFlag() );
3813    repFormat->setBitDepthVpsLuma           ( repFormatPrev->getBitDepthVpsLuma() );
3814    repFormat->setBitDepthVpsChroma         ( repFormatPrev->getBitDepthVpsChroma() );
3815  }
3816
3817#else
3818#if AUXILIARY_PICTURES
3819  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
3820#else
3821  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
3822#endif
3823
3824  if( repFormat->getChromaFormatVpsIdc() == 3 )
3825  {
3826    READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
3827  }
3828
3829  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
3830  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
3831
3832  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
3833  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
3834#endif
3835
3836#if R0156_CONF_WINDOW_IN_REP_FORMAT
3837  READ_FLAG( uiCode, "conformance_window_vps_flag" );
3838  if( uiCode != 0) 
3839  {
3840    Window &conf = repFormat->getConformanceWindowVps();
3841    READ_UVLC( uiCode, "conf_win_vps_left_offset" );         conf.setWindowLeftOffset  ( uiCode );
3842    READ_UVLC( uiCode, "conf_win_vps_right_offset" );        conf.setWindowRightOffset ( uiCode );
3843    READ_UVLC( uiCode, "conf_win_vps_top_offset" );          conf.setWindowTopOffset   ( uiCode );
3844    READ_UVLC( uiCode, "conf_win_vps_bottom_offset" );       conf.setWindowBottomOffset( uiCode );
3845  }
3846#endif
3847}
3848#endif
3849#if VPS_DPB_SIZE_TABLE
3850Void TDecCavlc::parseVpsDpbSizeTable( TComVPS *vps )
3851{
3852  UInt uiCode;
3853#if SUB_LAYERS_IN_LAYER_SET
3854  vps->calculateMaxSLInLayerSets();
3855#else
3856#if DPB_PARAMS_MAXTLAYERS
3857#if BITRATE_PICRATE_SIGNALLING
3858  Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
3859  for(Int i = 0; i < vps->getNumLayerSets(); i++)
3860#else
3861  Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
3862  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
3863#endif
3864  {
3865    UInt maxSLMinus1 = 0;
3866#if CHANGE_NUMSUBDPB_IDX
3867    Int optLsIdx = vps->getOutputLayerSetIdx( i );
3868#else
3869    Int optLsIdx = i;
3870#endif
3871#if BITRATE_PICRATE_SIGNALLING
3872    optLsIdx = i;
3873#endif
3874    for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
3875      Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
3876      maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdxInVps(lId)));
3877    }
3878    MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
3879#if BITRATE_PICRATE_SIGNALLING
3880    vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
3881#endif
3882  }
3883#endif
3884#endif
3885
3886#if !RESOLUTION_BASED_DPB
3887  vps->deriveNumberOfSubDpbs();
3888#endif
3889  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
3890  {
3891#if CHANGE_NUMSUBDPB_IDX
3892    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
3893#endif
3894    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
3895#if SUB_LAYERS_IN_LAYER_SET
3896    for(Int j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( layerSetIdxForOutputLayerSet ); j++)
3897#else
3898#if DPB_PARAMS_MAXTLAYERS
3899#if BITRATE_PICRATE_SIGNALLING
3900    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ vps->getOutputLayerSetIdx( i ) ]; j++)
3901#else
3902    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
3903#endif
3904#else
3905    for(Int j = 0; j <= vps->getMaxTLayers(); j++)
3906#endif
3907#endif
3908    {
3909      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
3910      {
3911        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag[i]");  vps->setSubLayerDpbInfoPresentFlag( i, j, uiCode ? true : false);
3912      }
3913      else
3914      {
3915        if( j == 0 )  // Always signal for the first sub-layer
3916        {
3917          vps->setSubLayerDpbInfoPresentFlag( i, j, true );
3918        }
3919        else // if (j != 0) && !vps->getSubLayerFlagInfoPresentFlag(i)
3920        {
3921          vps->setSubLayerDpbInfoPresentFlag( i, j, false );
3922        }
3923      }
3924      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is present
3925      {
3926#if CHANGE_NUMSUBDPB_IDX
3927        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
3928#else
3929        for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
3930#endif
3931        {
3932#if DPB_INTERNAL_BL_SIG
3933            uiCode=0;
3934
3935#if VPS_FIX_TO_MATCH_SPEC
3936        if( vps->getNecessaryLayerFlag(i, k) && ( vps->getBaseLayerInternalFlag() || vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, k) ) )
3937#else
3938        if(vps->getBaseLayerInternalFlag() || ( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, k) !=  0 ) )
3939#endif
3940#endif
3941          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
3942        }
3943        READ_UVLC( uiCode, "max_vps_num_reorder_pics[i][j]" );              vps->setMaxVpsNumReorderPics( i, j, uiCode);
3944#if RESOLUTION_BASED_DPB
3945        if( vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) != vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ) ) 
3946        {
3947          for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
3948          {
3949            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1[i][k][j]" ); vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode);
3950          }
3951        }
3952        else  // vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) == vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet )
3953        {         
3954          for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
3955          {
3956            vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j));
3957          }
3958        }
3959#endif
3960        READ_UVLC( uiCode, "max_vps_latency_increase_plus1[i][j]" );        vps->setMaxVpsLatencyIncreasePlus1( i, j, uiCode);
3961      }
3962    }
3963    for(Int j = vps->getMaxTLayers(); j < MAX_TLAYER; j++)
3964    {
3965      vps->setSubLayerDpbInfoPresentFlag( i, j, false );
3966    }
3967  }
3968
3969#if !SUB_LAYERS_IN_LAYER_SET
3970#if BITRATE_PICRATE_SIGNALLING
3971  if( MaxSubLayersInLayerSetMinus1 )
3972  {
3973    delete [] MaxSubLayersInLayerSetMinus1;
3974  }
3975#endif
3976#endif
3977
3978  // Infer values when not signalled
3979  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
3980  {
3981    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
3982    for(Int j = 0; j < MAX_TLAYER; j++)
3983    {
3984      if( !vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is NOT present
3985      {
3986#if RESOLUTION_BASED_DPB
3987        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
3988#else
3989        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
3990#endif
3991        {
3992          vps->setMaxVpsDecPicBufferingMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
3993        }
3994        vps->setMaxVpsNumReorderPics( i, j, vps->getMaxVpsNumReorderPics( i, j - 1) );
3995#if RESOLUTION_BASED_DPB
3996        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
3997        {
3998          vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j - 1));
3999        }
4000#endif
4001        vps->setMaxVpsLatencyIncreasePlus1( i, j, vps->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
4002      }
4003    }
4004  }
4005}
4006#endif
4007
4008Void TDecCavlc::parseVPSVUI(TComVPS *vps)
4009{
4010  UInt i,j;
4011  UInt uiCode;
4012#if O0223_PICTURE_TYPES_ALIGN_FLAG
4013  READ_FLAG(uiCode, "cross_layer_pic_type_aligned_flag" );
4014  vps->setCrossLayerPictureTypeAlignFlag(uiCode);
4015  if (!uiCode) 
4016  {
4017#endif
4018#if IRAP_ALIGN_FLAG_IN_VPS_VUI
4019    READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
4020    vps->setCrossLayerIrapAlignFlag(uiCode);
4021#endif
4022#if O0223_PICTURE_TYPES_ALIGN_FLAG
4023  }
4024  else
4025  {
4026    vps->setCrossLayerIrapAlignFlag(true);
4027  }
4028#endif
4029#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
4030  if( uiCode )
4031  {
4032    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" );
4033    vps->setCrossLayerAlignedIdrOnlyFlag(uiCode);
4034  }
4035#endif
4036
4037  READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
4038  READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
4039
4040#if SIGNALLING_BITRATE_PICRATE_FIX
4041  if ( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
4042  {
4043    for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getNumLayerSets(); i++ )
4044    {
4045      for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( i ); j++ ) 
4046      {
4047        if( vps->getBitRatePresentVpsFlag() )
4048        {
4049          READ_FLAG( uiCode, "bit_rate_present_flag[i][j]" ); vps->setBitRatePresentFlag( i, j, uiCode ? true : false );           
4050        }
4051        if( vps->getPicRatePresentVpsFlag( )  )
4052        {
4053          READ_FLAG( uiCode, "pic_rate_present_flag[i][j]" ); vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
4054        }
4055        if( vps->getBitRatePresentFlag( i, j ) )
4056        {
4057          READ_CODE( 16, uiCode, "avg_bit_rate" ); vps->setAvgBitRate( i, j, uiCode );
4058          READ_CODE( 16, uiCode, "max_bit_rate" ); vps->setMaxBitRate( i, j, uiCode );
4059        }
4060        else
4061        {
4062          vps->setAvgBitRate( i, j, 0 );
4063          vps->setMaxBitRate( i, j, 0 );
4064        }
4065        if( vps->getPicRatePresentFlag( i, j ) )
4066        {
4067          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); vps->setConstPicRateIdc( i, j, uiCode );
4068          READ_CODE( 16, uiCode, "avg_pic_rate" );          vps->setAvgPicRate( i, j, uiCode );
4069        }
4070        else
4071        {
4072          vps->setConstPicRateIdc( i, j, 0 );
4073          vps->setAvgPicRate( i, j, 0 );
4074        }
4075      }
4076    }
4077  }
4078#else
4079  Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
4080
4081#if Q0078_ADD_LAYER_SETS
4082#if R0227_BR_PR_ADD_LAYER_SET
4083  for( i = 0; i < vps->getNumLayerSets(); i++ )
4084#else
4085  for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
4086#endif
4087#else
4088  for( i = 0; i < vps->getNumLayerSets(); i++ )
4089#endif
4090  {
4091#if BITRATE_PICRATE_SIGNALLING
4092    for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ )
4093#else
4094    for( j = 0; j < vps->getMaxTLayers(); j++ )
4095#endif
4096    {
4097      if( parseFlag && vps->getBitRatePresentVpsFlag() )
4098      {
4099        READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
4100      }
4101      else
4102      {
4103        vps->setBitRatePresentFlag( i, j, false );
4104      }
4105      if( parseFlag && vps->getPicRatePresentVpsFlag() )
4106      {
4107        READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
4108      }
4109      else
4110      {
4111        vps->setPicRatePresentFlag( i, j, false );
4112      }
4113      if( parseFlag && vps->getBitRatePresentFlag(i, j) )
4114      {
4115        READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
4116        READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
4117      }
4118      else
4119      {
4120        vps->setAvgBitRate( i, j, 0 );
4121        vps->setMaxBitRate( i, j, 0 );
4122      }
4123      if( parseFlag && vps->getPicRatePresentFlag(i, j) )
4124      {
4125        READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
4126        READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
4127      }
4128      else
4129      {
4130        vps->setConstPicRateIdc( i, j, 0 );
4131        vps->setAvgPicRate     ( i, j, 0 );
4132      }
4133    }
4134  }
4135#endif
4136#if VPS_VUI_VIDEO_SIGNAL_MOVE
4137  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
4138  if (vps->getVideoSigPresentVpsFlag())
4139  {
4140    READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
4141  }
4142  else
4143  {
4144#if VPS_VUI_VST_PARAMS
4145    vps->setNumVideoSignalInfo(vps->getMaxLayers() - vps->getBaseLayerInternalFlag() ? 0 : 1);
4146#else
4147    vps->setNumVideoSignalInfo(vps->getMaxLayers());
4148#endif
4149  }
4150
4151  for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
4152  {
4153    READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
4154    READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
4155    READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
4156    READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
4157    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
4158  }
4159#if VPS_VUI_VST_PARAMS
4160  if( vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 )
4161  {
4162    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
4163    {
4164      READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
4165    }
4166  }
4167  else if ( !vps->getVideoSigPresentVpsFlag() )
4168  {
4169    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
4170    {
4171      vps->setVideoSignalInfoIdx( i, i );
4172    }
4173  }
4174  else // ( vps->getNumVideoSignalInfo() = 0 )
4175  {
4176    for(i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
4177    {
4178      vps->setVideoSignalInfoIdx( i, 0 );
4179    }
4180  }
4181#else
4182  if(!vps->getVideoSigPresentVpsFlag())
4183  {
4184    for (i=0; i < vps->getMaxLayers(); i++)
4185    {
4186      vps->setVideoSignalInfoIdx(i,i);
4187    }
4188  }
4189  else {
4190    vps->setVideoSignalInfoIdx(0,0);
4191    if (vps->getNumVideoSignalInfo() > 1 )
4192    {
4193      for (i=1; i < vps->getMaxLayers(); i++)
4194        READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
4195    }
4196    else {
4197      for (i=1; i < vps->getMaxLayers(); i++)
4198      {
4199        vps->setVideoSignalInfoIdx(i,0);
4200      }
4201    }
4202  }
4203#endif
4204#endif
4205#if VPS_VUI_TILES_NOT_IN_USE__FLAG
4206  UInt layerIdx;
4207  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); vps->setTilesNotInUseFlag(uiCode == 1);
4208  if (!uiCode)
4209  {
4210#if VPS_FIX_TO_MATCH_SPEC
4211    for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++ )
4212#else
4213    for (i = 0; i < vps->getMaxLayers(); i++)
4214#endif
4215    {
4216      READ_FLAG( uiCode, "tiles_in_use_flag[ i ]" ); vps->setTilesInUseFlag(i, (uiCode == 1));
4217      if (uiCode)
4218      {
4219        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[ i ]" ); vps->setLoopFilterNotAcrossTilesFlag(i, (uiCode == 1));
4220      }
4221      else
4222      {
4223        vps->setLoopFilterNotAcrossTilesFlag(i, false);
4224      }
4225    }
4226#endif
4227
4228#if VPS_FIX_TO_MATCH_SPEC
4229      for( i = vps->getBaseLayerInternalFlag() ? 1 : 2; i < vps->getMaxLayers(); i++ )
4230#else
4231      for (i = 1; i < vps->getMaxLayers(); i++)
4232#endif
4233    {
4234      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
4235      {
4236#if VPS_VUI_TILES_NOT_IN_USE__FLAG
4237        layerIdx = vps->getLayerIdxInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
4238        if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
4239          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
4240        }
4241#else
4242        READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
4243#endif
4244      }
4245    }
4246#if VPS_VUI_TILES_NOT_IN_USE__FLAG
4247  }
4248#endif
4249#if VPS_VUI_WPP_NOT_IN_USE__FLAG
4250  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); vps->setWppNotInUseFlag(uiCode == 1);
4251  if (!uiCode)
4252  {
4253#if VPS_FIX_TO_MATCH_SPEC
4254      for (i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++)
4255#else
4256      for (i = 0; i < vps->getMaxLayers(); i++)
4257#endif
4258    {
4259      READ_FLAG( uiCode, "wpp_in_use_flag[ i ]" ); vps->setWppInUseFlag(i, (uiCode == 1));
4260    }
4261  }
4262#endif
4263
4264#if O0109_O0199_FLAGS_TO_VUI
4265#if M0040_ADAPTIVE_RESOLUTION_CHANGE
4266  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
4267#endif
4268#if HIGHER_LAYER_IRAP_SKIP_FLAG
4269  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
4270
4271  // When single_layer_for_non_irap_flag is equal to 0, higher_layer_irap_skip_flag shall be equal to 0
4272  if( !vps->getSingleLayerForNonIrapFlag() )
4273  {
4274    assert( !vps->getHigherLayerIrapSkipFlag() );
4275  }
4276#endif
4277#endif
4278#if P0312_VERT_PHASE_ADJ
4279  READ_FLAG( uiCode, "vps_vui_vert_phase_in_use_flag" ); vps->setVpsVuiVertPhaseInUseFlag(uiCode);
4280#endif
4281#if N0160_VUI_EXT_ILP_REF
4282  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vps->setIlpRestrictedRefLayersFlag( uiCode == 1 );
4283  if( vps->getIlpRestrictedRefLayersFlag())
4284  {
4285    for(i = 1; i < vps->getMaxLayers(); i++)
4286    {
4287      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
4288      {
4289#if VPS_FIX_TO_MATCH_SPEC
4290        if( vps->getBaseLayerInternalFlag() || vps->getRefLayerId(vps->getLayerIdInNuh(i), j) )
4291        {
4292#endif
4293          READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
4294          if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 )
4295          {
4296            READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 );
4297            if(vps->getCtuBasedOffsetEnabledFlag(i,j))
4298            {
4299              READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode );
4300            }
4301          }
4302#if VPS_FIX_TO_MATCH_SPEC
4303        }
4304#endif
4305      }
4306    }
4307  }
4308#endif
4309#if VPS_VUI_VIDEO_SIGNAL
4310#if VPS_VUI_VIDEO_SIGNAL_MOVE
4311#else
4312  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
4313  if (vps->getVideoSigPresentVpsFlag())
4314  {
4315    READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
4316  }
4317  else
4318  {
4319    vps->setNumVideoSignalInfo(vps->getMaxLayers());
4320  }
4321
4322
4323  for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
4324  {
4325    READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
4326    READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
4327    READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
4328    READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
4329    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
4330  }
4331  if(!vps->getVideoSigPresentVpsFlag())
4332  {
4333    for (i=0; i < vps->getMaxLayers(); i++)
4334    {
4335      vps->setVideoSignalInfoIdx(i,i);
4336    }
4337  }
4338  else {
4339    vps->setVideoSignalInfoIdx(0,0);
4340    if (vps->getNumVideoSignalInfo() > 1 )
4341    {
4342      for (i=1; i < vps->getMaxLayers(); i++)
4343        READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
4344    }
4345    else {
4346      for (i=1; i < vps->getMaxLayers(); i++)
4347      {
4348        vps->setVideoSignalInfoIdx(i,0);
4349      }
4350    }
4351  }
4352#endif
4353#endif
4354
4355#if O0164_MULTI_LAYER_HRD
4356  READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
4357  if (vps->getVpsVuiBspHrdPresentFlag())
4358  {
4359#if VPS_VUI_BSP_HRD_PARAMS
4360    parseVpsVuiBspHrdParams(vps);
4361#else
4362#if R0227_VUI_BSP_HRD_FLAG
4363    assert (vps->getTimingInfo()->getTimingInfoPresentFlag() == 1);
4364#endif
4365    READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
4366    vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
4367    for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
4368    {
4369      if( i > 0 )
4370      {
4371        READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
4372      }
4373      parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
4374    }
4375#if Q0078_ADD_LAYER_SETS
4376    for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
4377#else
4378    for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
4379#endif
4380    {
4381      READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
4382#if HRD_BPB
4383      Int chkPart=0;
4384#endif
4385      for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
4386      {
4387        for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
4388        {
4389          if( vps->getLayerIdIncludedFlag(h, j) )
4390          {
4391            READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
4392          }
4393        }
4394#if HRD_BPB
4395        chkPart+=vps->getLayerInBspFlag(h, i, j);
4396#endif
4397      }
4398#if HRD_BPB
4399      assert(chkPart<=1);
4400#endif
4401#if HRD_BPB
4402      if(vps->getNumBitstreamPartitions(h)==1)
4403      {
4404        Int chkPartition1=0; Int chkPartition2=0;
4405        for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
4406        {
4407          if( vps->getLayerIdIncludedFlag(h, j) )
4408          {
4409            chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
4410            chkPartition2++;
4411          }
4412        }
4413        assert(chkPartition1!=chkPartition2);
4414      }
4415#endif
4416      if (vps->getNumBitstreamPartitions(h))
4417      {
4418#if Q0182_MULTI_LAYER_HRD_UPDATE
4419        READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
4420#else
4421        READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
4422#endif
4423        for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
4424        {
4425          for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
4426          {
4427            READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
4428#if HRD_BPB
4429            assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
4430#endif
4431
4432            READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
4433#if HRD_BPB
4434            assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
4435#endif
4436          }
4437        }
4438      }
4439    }
4440#endif
4441  }
4442#endif
4443#if P0182_VPS_VUI_PS_FLAG
4444  for(i = 1; i < vps->getMaxLayers(); i++)
4445  {
4446    if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
4447    {
4448      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); 
4449      vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
4450    }
4451    else
4452    {
4453      vps->setBaseLayerPSCompatibilityFlag( i, 0 );
4454    }
4455  }
4456#endif
4457}
4458
4459Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
4460{
4461  UInt uiCode;
4462  // more syntax elements to be parsed here
4463
4464  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );
4465  // Vertical MV component restriction is not used in SHVC CTC
4466  assert( uiCode == 0 );
4467
4468#if !MOVE_SCALED_OFFSET_TO_PPS
4469  if( pcSPS->getLayerId() > 0 )
4470  {
4471    Int iCode;
4472    READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
4473    for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
4474    {
4475      Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
4476#if O0098_SCALED_REF_LAYER_ID
4477      READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
4478#endif
4479      READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
4480      READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
4481      READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
4482      READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
4483#if P0312_VERT_PHASE_ADJ
4484      READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);   
4485#endif
4486    }
4487  }
4488#endif
4489}
4490#endif
4491
4492#if Q0048_CGS_3D_ASYMLUT
4493Void TDecCavlc::xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
4494{
4495#if R0150_CGS_SIGNAL_CONSTRAINTS
4496  UInt uiNumRefLayersM1;
4497  READ_UVLC( uiNumRefLayersM1 , "num_cm_ref_layers_minus1" );
4498  assert( uiNumRefLayersM1 <= 61 );
4499  for( UInt i = 0 ; i <= uiNumRefLayersM1 ; i++ )
4500  {
4501    UInt uiRefLayerId;
4502    READ_CODE( 6 , uiRefLayerId , "cm_ref_layer_id" );
4503    pc3DAsymLUT->addRefLayerId( uiRefLayerId );
4504  }
4505#endif
4506  UInt uiCurOctantDepth , uiCurPartNumLog2 , uiInputBitDepthM8 , uiOutputBitDepthM8 , uiResQaunBit;
4507#if R0300_CGS_RES_COEFF_CODING
4508  UInt uiDeltaBits; 
4509#endif
4510  READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" ); 
4511  READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
4512#if R0150_CGS_SIGNAL_CONSTRAINTS
4513  UInt uiChromaInputBitDepthM8 , uiChromaOutputBitDepthM8;
4514  READ_UVLC( uiInputBitDepthM8 , "cm_input_luma_bit_depth_minus8" );
4515  READ_UVLC( uiChromaInputBitDepthM8 , "cm_input_chroma_bit_depth_minus8" );
4516  READ_UVLC( uiOutputBitDepthM8 , "cm_output_luma_bit_depth_minus8" );
4517  READ_UVLC( uiChromaOutputBitDepthM8 , "cm_output_chroma_bit_depth_minus8" );
4518#else
4519  READ_CODE( 3 , uiInputBitDepthM8 , "cm_input_bit_depth_minus8" );
4520  Int iInputBitDepthCDelta;
4521  READ_SVLC(iInputBitDepthCDelta, "cm_input_bit_depth_chroma delta");
4522  READ_CODE( 3 , uiOutputBitDepthM8 , "cm_output_bit_depth_minus8" ); 
4523  Int iOutputBitDepthCDelta;
4524  READ_SVLC(iOutputBitDepthCDelta, "cm_output_bit_depth_chroma_delta");
4525#endif
4526  READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
4527#if R0300_CGS_RES_COEFF_CODING
4528  READ_CODE( 2 , uiDeltaBits , "cm_flc_bits" );
4529  pc3DAsymLUT->setDeltaBits(uiDeltaBits + 1);
4530#endif
4531
4532#if R0151_CGS_3D_ASYMLUT_IMPROVE
4533#if R0150_CGS_SIGNAL_CONSTRAINTS
4534  Int nAdaptCThresholdU = 1 << ( uiChromaInputBitDepthM8 + 8 - 1 );
4535  Int nAdaptCThresholdV = 1 << ( uiChromaInputBitDepthM8 + 8 - 1 );
4536#else
4537  Int nAdaptCThresholdU = 1 << ( uiInputBitDepthM8 + 8 + iInputBitDepthCDelta - 1 );
4538  Int nAdaptCThresholdV = 1 << ( uiInputBitDepthM8 + 8 + iInputBitDepthCDelta - 1 );
4539#endif
4540  if( uiCurOctantDepth == 1 )
4541  {
4542    Int delta = 0;
4543    READ_SVLC( delta , "cm_adapt_threshold_u_delta" );
4544    nAdaptCThresholdU += delta;
4545    READ_SVLC( delta , "cm_adapt_threshold_v_delta" );
4546    nAdaptCThresholdV += delta;
4547  }
4548#endif
4549  pc3DAsymLUT->destroy();
4550  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 , 
4551#if R0150_CGS_SIGNAL_CONSTRAINTS
4552    uiChromaInputBitDepthM8 + 8 ,
4553#else
4554    uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, 
4555#endif
4556    uiOutputBitDepthM8 + 8 , 
4557#if R0150_CGS_SIGNAL_CONSTRAINTS
4558    uiChromaOutputBitDepthM8 + 8 ,
4559#else
4560    uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,
4561#endif
4562    uiCurPartNumLog2
4563#if R0151_CGS_3D_ASYMLUT_IMPROVE
4564    , nAdaptCThresholdU , nAdaptCThresholdV
4565#endif   
4566    );
4567  pc3DAsymLUT->setResQuantBit( uiResQaunBit );
4568
4569#if R0164_CGS_LUT_BUGFIX_CHECK
4570  pc3DAsymLUT->xInitCuboids();
4571#endif
4572  xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
4573#if R0164_CGS_LUT_BUGFIX
4574#if R0164_CGS_LUT_BUGFIX_CHECK
4575  printf("============= Before 'xCuboidsFilledCheck()': ================\n");
4576  pc3DAsymLUT->display();
4577  pc3DAsymLUT->xCuboidsFilledCheck( false );
4578  printf("============= After 'xCuboidsFilledCheck()': =================\n");
4579  pc3DAsymLUT->display();
4580#endif
4581#endif
4582}
4583
4584Void TDecCavlc::xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength )
4585{
4586  UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
4587  if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
4588    READ_FLAG( uiOctantSplit , "split_octant_flag" );
4589  Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
4590  if( uiOctantSplit )
4591  {
4592    Int nHalfLength = nLength >> 1;
4593    for( Int l = 0 ; l < 2 ; l++ )
4594    {
4595      for( Int m = 0 ; m < 2 ; m++ )
4596      {
4597        for( Int n = 0 ; n < 2 ; n++ )
4598        {
4599          xParse3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength );
4600        }
4601      }
4602    }
4603  }
4604  else
4605  {
4606#if R0300_CGS_RES_COEFF_CODING
4607    Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-pc3DAsymLUT->getDeltaBits() ; 
4608    nFLCbits = nFLCbits >= 0 ? nFLCbits:0;
4609#endif
4610    for( Int l = 0 ; l < nYPartNum ; l++ )
4611    {
4612#if R0164_CGS_LUT_BUGFIX
4613      Int shift = pc3DAsymLUT->getCurOctantDepth() - nDepth ;
4614#endif
4615      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
4616      {
4617        UInt uiCodeVertex = 0;
4618        Int deltaY = 0 , deltaU = 0 , deltaV = 0;
4619        READ_FLAG( uiCodeVertex , "coded_vertex_flag" );
4620        if( uiCodeVertex )
4621        {
4622#if R0151_CGS_3D_ASYMLUT_IMPROVE
4623#if R0300_CGS_RES_COEFF_CODING
4624          xReadParam( deltaY, nFLCbits );
4625          xReadParam( deltaU, nFLCbits );
4626          xReadParam( deltaV, nFLCbits );
4627#else
4628          xReadParam( deltaY );
4629          xReadParam( deltaU );
4630          xReadParam( deltaV );
4631#endif
4632#else
4633          READ_SVLC( deltaY , "resY" );
4634          READ_SVLC( deltaU , "resU" );
4635          READ_SVLC( deltaV , "resV" );
4636#endif
4637        }
4638#if R0164_CGS_LUT_BUGFIX
4639        pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
4640        for (Int m = 1; m < (1<<shift); m++) {
4641          pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) + m , uIdx , vIdx , nVertexIdx , 0 , 0 , 0 );
4642#if R0164_CGS_LUT_BUGFIX_CHECK
4643          pc3DAsymLUT->xSetFilled( yIdx + (l<<shift) + m , uIdx , vIdx );
4644#endif
4645        }
4646#else
4647        pc3DAsymLUT->setCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
4648#endif
4649      }
4650#if R0164_CGS_LUT_BUGFIX_CHECK
4651      pc3DAsymLUT->xSetExplicit( yIdx + (l<<shift) , uIdx , vIdx );
4652#endif
4653    }
4654#if R0164_CGS_LUT_BUGFIX
4655    for ( Int u=0 ; u<nLength ; u++ ) {
4656      for ( Int v=0 ; v<nLength ; v++ ) {
4657        if ( u!=0 || v!=0 ) {
4658          for ( Int y=0 ; y<nLength*nYPartNum ; y++ ) {
4659            for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
4660            {
4661              pc3DAsymLUT->setCuboidVertexResTree( yIdx + y , uIdx + u , vIdx + v , nVertexIdx , 0 , 0 , 0 );
4662#if R0164_CGS_LUT_BUGFIX_CHECK
4663              pc3DAsymLUT->xSetFilled( yIdx + y , uIdx + u , vIdx + v );
4664#endif
4665            }
4666          }
4667        }
4668      }
4669    }
4670#endif
4671  }
4672}
4673
4674#if R0151_CGS_3D_ASYMLUT_IMPROVE
4675#if R0300_CGS_RES_COEFF_CODING
4676Void TDecCavlc::xReadParam( Int& param, Int rParam )
4677#else
4678Void TDecCavlc::xReadParam( Int& param )
4679#endif
4680{
4681#if !R0300_CGS_RES_COEFF_CODING
4682  const UInt rParam = 7;
4683#endif
4684  UInt prefix;
4685  UInt codeWord ;
4686  UInt rSymbol;
4687  UInt sign;
4688
4689  READ_UVLC( prefix, "quotient")  ;
4690  READ_CODE (rParam, codeWord, "remainder");
4691  rSymbol = (prefix<<rParam) + codeWord;
4692
4693  if(rSymbol)
4694  {
4695    READ_FLAG(sign, "sign");
4696    param = sign ? -(Int)(rSymbol) : (Int)(rSymbol);
4697  }
4698  else param = 0;
4699}
4700#endif
4701#if VPS_VUI_BSP_HRD_PARAMS
4702Void TDecCavlc::parseVpsVuiBspHrdParams( TComVPS *vps )
4703{
4704  UInt uiCode;
4705  assert (vps->getTimingInfo()->getTimingInfoPresentFlag() == 1);
4706  READ_UVLC( uiCode, "vps_num_add_hrd_params" ); vps->setVpsNumAddHrdParams(uiCode);
4707  vps->createBspHrdParamBuffer(vps->getVpsNumAddHrdParams()); // Also allocates m_cprmsAddPresentFlag and m_numSubLayerHrdMinus
4708
4709  for( Int i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ ) // j = i - vps->getNumHrdParameters()
4710  {
4711    if( i > 0 )
4712    {
4713      READ_FLAG( uiCode, "cprms_add_present_flag[i]" );   vps->setCprmsAddPresentFlag(j, uiCode ? true : false);
4714    }
4715    else
4716    {
4717      // i == 0
4718      if( vps->getNumHrdParameters() == 0 )
4719      {
4720        vps->setCprmsAddPresentFlag(0, true);
4721      }
4722    }
4723    READ_UVLC( uiCode, "num_sub_layer_hrd_minus1[i]" ); vps->setNumSubLayerHrdMinus1(j, uiCode );
4724    assert( uiCode <= vps->getMaxTLayers() - 1 );
4725   
4726    parseHrdParameters( vps->getBspHrd(j), vps->getCprmsAddPresentFlag(j), vps->getNumSubLayerHrdMinus1(j) );
4727    if( i > 0 && !vps->getCprmsAddPresentFlag(i) )
4728    {
4729      // Copy common information parameters
4730      if( i == vps->getNumHrdParameters() )
4731      {
4732        vps->getBspHrd(j)->copyCommonInformation( vps->getHrdParameters( vps->getNumHrdParameters() - 1 ) );
4733      }
4734      else
4735      {
4736        vps->getBspHrd(j)->copyCommonInformation( vps->getBspHrd( j - 1 ) );
4737      }
4738    }
4739  }
4740#if VPS_FIX_TO_MATCH_SPEC
4741  if( vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams() > 0 )
4742  {
4743#endif
4744    for (Int h = 1; h < vps->getNumOutputLayerSets(); h++)
4745    {
4746      Int lsIdx = vps->getOutputLayerSetIdx(h);
4747      READ_UVLC(uiCode, "num_signalled_partitioning_schemes[h]"); vps->setNumSignalledPartitioningSchemes(h, uiCode);
4748#if VPS_FIX_TO_MATCH_SPEC
4749      for (Int j = 1; j < vps->getNumSignalledPartitioningSchemes(h) + 1; j++)
4750#else
4751      for (Int j = 0; j < vps->getNumSignalledPartitioningSchemes(h); j++)
4752#endif
4753      {
4754        READ_UVLC(uiCode, "num_partitions_in_scheme_minus1[h][j]"); vps->setNumPartitionsInSchemeMinus1(h, j, uiCode);
4755        for (Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, j); k++)
4756        {
4757          for (Int r = 0; r < vps->getNumLayersInIdList(lsIdx); r++)
4758          {
4759            READ_FLAG(uiCode, "layer_included_in_partition_flag[h][j][k][r]"); vps->setLayerIncludedInPartitionFlag(h, j, k, r, uiCode ? true : false);
4760          }
4761        }
4762      }
4763      for (Int i = 0; i < vps->getNumSignalledPartitioningSchemes(h) + 1; i++)
4764      {
4765        for (Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1(lsIdx); t++)
4766        {
4767          READ_UVLC(uiCode, "num_bsp_schedules_minus1[h][i][t]");              vps->setNumBspSchedulesMinus1(h, i, t, uiCode);
4768          for (Int j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++)
4769          {
4770#if VPS_FIX_TO_MATCH_SPEC
4771            for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, i); k++ )
4772#else
4773            for (Int k = 0; k < vps->getNumPartitionsInSchemeMinus1(h, i); k++)
4774#endif
4775            {
4776#if VPS_FIX_TO_MATCH_SPEC
4777              if( vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams() > 1 )
4778              {
4779                Int numBits = 1;
4780                while ((1 << numBits) < (vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams()))
4781                {
4782                  numBits++;
4783                }
4784                READ_CODE(numBits, uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
4785              }
4786#else
4787              READ_UVLC(uiCode, "bsp_comb_hrd_idx[h][i][t][j][k]");      vps->setBspHrdIdx(h, i, t, j, k, uiCode);
4788#endif
4789              READ_UVLC(uiCode, "bsp_comb_sched_idx[h][i][t][j][k]");    vps->setBspSchedIdx(h, i, t, j, k, uiCode);
4790            }
4791          }
4792        }
4793      }
4794
4795      // To be done: Check each layer included in not more than one BSP in every partitioning scheme,
4796      // and other related checks associated with layers in bitstream partitions.
4797
4798    }
4799#if VPS_FIX_TO_MATCH_SPEC
4800  }
4801#endif
4802}
4803#endif
4804#endif
4805//! \}
4806
Note: See TracBrowser for help on using the repository browser.