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

Last change on this file since 749 was 744, checked in by sharp, 12 years ago

JCTVC-Q0102 Proposal 3 - S. Deshpande <sdeshpande@…>

  • Property svn:eol-style set to native
File size: 134.7 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#if Q0048_CGS_3D_ASYMLUT
42#include "../TLibCommon/TCom3DAsymLUT.h"
43#endif
44
45//! \ingroup TLibDecoder
46//! \{
47
48#if ENC_DEC_TRACE
49
50Void  xTraceSPSHeader (TComSPS *pSPS)
51{
52  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
53}
54
55Void  xTracePPSHeader (TComPPS *pPPS)
56{
57  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
58}
59
60Void  xTraceSliceHeader (TComSlice *pSlice)
61{
62  fprintf( g_hTrace, "=========== Slice ===========\n");
63}
64
65#endif
66
67// ====================================================================================================================
68// Constructor / destructor / create / destroy
69// ====================================================================================================================
70
71TDecCavlc::TDecCavlc()
72{
73}
74
75TDecCavlc::~TDecCavlc()
76{
77
78}
79
80// ====================================================================================================================
81// Public member functions
82// ====================================================================================================================
83
84void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
85{
86  UInt code;
87  UInt interRPSPred;
88  if (idx > 0)
89  {
90    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
91  }
92  else
93  {
94    interRPSPred = false;
95    rps->setInterRPSPrediction(false);
96  }
97
98  if (interRPSPred)
99  {
100    UInt bit;
101    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
102    {
103      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
104    }
105    else
106    {
107      code = 0;
108    }
109    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
110    Int rIdx =  idx - 1 - code;
111    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
112    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
113    Int k = 0, k0 = 0, k1 = 0;
114    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
115    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
116    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
117    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
118    {
119      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
120      Int refIdc = bit;
121      if (refIdc == 0)
122      {
123        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
124        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
125      }
126      if (refIdc == 1 || refIdc == 2)
127      {
128        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
129        rps->setDeltaPOC(k, deltaPOC);
130        rps->setUsed(k, (refIdc == 1));
131
132        if (deltaPOC < 0)
133        {
134          k0++;
135        }
136        else
137        {
138          k1++;
139        }
140        k++;
141      }
142      rps->setRefIdc(j,refIdc);
143    }
144    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);
145    rps->setNumberOfPictures(k);
146    rps->setNumberOfNegativePictures(k0);
147    rps->setNumberOfPositivePictures(k1);
148    rps->sortDeltaPOC();
149  }
150  else
151  {
152    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
153    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
154    Int prev = 0;
155    Int poc;
156    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
157    {
158      READ_UVLC(code, "delta_poc_s0_minus1");
159      poc = prev-code-1;
160      prev = poc;
161      rps->setDeltaPOC(j,poc);
162      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
163    }
164    prev = 0;
165    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
166    {
167      READ_UVLC(code, "delta_poc_s1_minus1");
168      poc = prev+code+1;
169      prev = poc;
170      rps->setDeltaPOC(j,poc);
171      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
172    }
173    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
174  }
175#if PRINT_RPS_INFO
176  rps->printDeltaPOC();
177#endif
178}
179
180Void TDecCavlc::parsePPS(TComPPS* pcPPS
181#if Q0048_CGS_3D_ASYMLUT
182  , TCom3DAsymLUT * pc3DAsymLUT , Int nLayerID
183#endif
184  )
185{
186#if ENC_DEC_TRACE
187  xTracePPSHeader (pcPPS);
188#endif
189  UInt  uiCode;
190
191  Int   iCode;
192
193  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
194  assert(uiCode <= 63);
195  pcPPS->setPPSId (uiCode);
196
197  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
198  assert(uiCode <= 15);
199  pcPPS->setSPSId (uiCode);
200
201  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
202  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
203
204  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
205  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
206
207  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
208
209  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
210  assert(uiCode <= 14);
211  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
212
213  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
214  assert(uiCode <= 14);
215  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
216
217  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
218  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
219  READ_FLAG( uiCode, "transform_skip_enabled_flag" );
220  pcPPS->setUseTransformSkip ( uiCode ? true : false );
221
222  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
223  if( pcPPS->getUseDQP() )
224  {
225    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
226    pcPPS->setMaxCuDQPDepth( uiCode );
227  }
228  else
229  {
230    pcPPS->setMaxCuDQPDepth( 0 );
231  }
232  READ_SVLC( iCode, "pps_cb_qp_offset");
233  pcPPS->setChromaCbQpOffset(iCode);
234  assert( pcPPS->getChromaCbQpOffset() >= -12 );
235  assert( pcPPS->getChromaCbQpOffset() <=  12 );
236
237  READ_SVLC( iCode, "pps_cr_qp_offset");
238  pcPPS->setChromaCrQpOffset(iCode);
239  assert( pcPPS->getChromaCrQpOffset() >= -12 );
240  assert( pcPPS->getChromaCrQpOffset() <=  12 );
241
242  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
243  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
244
245  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
246  pcPPS->setUseWP( uiCode==1 );
247  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
248  pcPPS->setWPBiPred( uiCode==1 );
249
250  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
251  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
252  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
253  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
254
255  if( pcPPS->getTilesEnabledFlag() )
256  {
257    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );
258    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode );
259    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
260
261    if( !pcPPS->getUniformSpacingFlag())
262    {
263      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
264      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
265      {
266        READ_UVLC( uiCode, "column_width_minus1" );
267        columnWidth[i] = uiCode+1;
268      }
269      pcPPS->setColumnWidth(columnWidth);
270      free(columnWidth);
271
272      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
273      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
274      {
275        READ_UVLC( uiCode, "row_height_minus1" );
276        rowHeight[i] = uiCode + 1;
277      }
278      pcPPS->setRowHeight(rowHeight);
279      free(rowHeight);
280    }
281
282    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
283    {
284      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
285    }
286  }
287  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
288  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
289  if(pcPPS->getDeblockingFilterControlPresentFlag())
290  {
291    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
292    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
293    if(!pcPPS->getPicDisableDeblockingFilterFlag())
294    {
295      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
296      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
297    }
298  }
299
300#if SCALINGLIST_INFERRING
301  if( pcPPS->getLayerId() > 0 )
302  {
303    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" );
304    pcPPS->setInferScalingListFlag( uiCode );
305  }
306
307  if( pcPPS->getInferScalingListFlag() )
308  {
309    READ_UVLC( uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setScalingListRefLayerId( uiCode );
310
311    // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
312    assert( pcPPS->getScalingListRefLayerId() <= 62 );
313
314    pcPPS->setScalingListPresentFlag( false );
315  }
316  else
317  {
318#endif
319
320  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
321
322  if(pcPPS->getScalingListPresentFlag ())
323  {
324    parseScalingList( pcPPS->getScalingList() );
325  }
326
327#if SCALINGLIST_INFERRING
328  }
329#endif
330
331  READ_FLAG( uiCode, "lists_modification_present_flag");
332  pcPPS->setListsModificationPresentFlag(uiCode);
333
334  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
335  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
336
337  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
338  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
339
340  READ_FLAG( uiCode, "pps_extension_flag");
341#if POC_RESET_INFO_INFERENCE
342  Bool ppsExtensionFlag = uiCode ? true : false;
343  if( ppsExtensionFlag )
344#else
345  if (uiCode)
346#endif 
347  {
348#if P0166_MODIFIED_PPS_EXTENSION
349    UInt ppsExtensionTypeFlag[8];
350    for (UInt i = 0; i < 8; i++)
351    {
352      READ_FLAG( ppsExtensionTypeFlag[i], "pps_extension_type_flag" );
353    }
354#if !POC_RESET_IDC
355    if (ppsExtensionTypeFlag[1])
356    {
357#else
358    if( ppsExtensionTypeFlag[0] )
359    {
360      READ_FLAG( uiCode, "poc_reset_info_present_flag" );
361      pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
362#if Q0048_CGS_3D_ASYMLUT
363      READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
364      pcPPS->setCGSFlag( uiCode );
365      if( pcPPS->getCGSFlag() )
366      {
367        xParse3DAsymLUT( pc3DAsymLUT );
368        pcPPS->setCGSOutputBitDepthY( pc3DAsymLUT->getOutputBitDepthY() );
369        pcPPS->setCGSOutputBitDepthC( pc3DAsymLUT->getOutputBitDepthC() );
370      }
371#endif
372#endif
373    }
374#if POC_RESET_INFO_INFERENCE
375    else  // Extension type 0 absent
376    {
377      pcPPS->setPocResetInfoPresentFlag( false );
378    }
379#endif
380    if (ppsExtensionTypeFlag[7])
381    {
382#endif
383
384    while ( xMoreRbspData() )
385    {
386      READ_FLAG( uiCode, "pps_extension_data_flag");
387    }
388#if P0166_MODIFIED_PPS_EXTENSION
389    }
390#endif
391  }
392#if POC_RESET_INFO_INFERENCE
393  if( !ppsExtensionFlag )
394  {
395    pcPPS->setPocResetInfoPresentFlag( false );
396  }
397#endif
398}
399
400Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
401{
402#if ENC_DEC_TRACE
403  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
404#endif
405  UInt  uiCode;
406
407  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
408  if (pcVUI->getAspectRatioInfoPresentFlag())
409  {
410    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
411    if (pcVUI->getAspectRatioIdc() == 255)
412    {
413      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
414      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
415    }
416  }
417
418  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
419  if (pcVUI->getOverscanInfoPresentFlag())
420  {
421    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
422  }
423
424  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
425  if (pcVUI->getVideoSignalTypePresentFlag())
426  {
427    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
428    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
429    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
430    if (pcVUI->getColourDescriptionPresentFlag())
431    {
432      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
433      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
434      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
435    }
436  }
437
438  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
439  if (pcVUI->getChromaLocInfoPresentFlag())
440  {
441    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
442    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
443  }
444
445  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
446
447  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
448
449  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
450
451  READ_FLAG(     uiCode, "default_display_window_flag");
452  if (uiCode != 0)
453  {
454    Window &defDisp = pcVUI->getDefaultDisplayWindow();
455    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
456    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
457    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
458    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
459  }
460  TimingInfo *timingInfo = pcVUI->getTimingInfo();
461  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
462#if TIMING_INFO_NONZERO_LAYERID_SPS
463  if( pcSPS->getLayerId() > 0 )
464  {
465    assert( timingInfo->getTimingInfoPresentFlag() == false );
466  }
467#endif
468  if(timingInfo->getTimingInfoPresentFlag())
469  {
470    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
471    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
472    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
473    if(timingInfo->getPocProportionalToTimingFlag())
474    {
475      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
476    }
477  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
478  if( pcVUI->getHrdParametersPresentFlag() )
479  {
480    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
481  }
482  }
483  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
484  if (pcVUI->getBitstreamRestrictionFlag())
485  {
486    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
487    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
488    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
489    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
490    assert(uiCode < 4096);
491    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
492    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
493    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
494    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
495  }
496}
497
498Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
499{
500  UInt  uiCode;
501  if( commonInfPresentFlag )
502  {
503    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
504    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
505    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
506    {
507      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
508      if( hrd->getSubPicCpbParamsPresentFlag() )
509      {
510        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
511        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
512        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
513        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
514      }
515      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
516      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
517      if( hrd->getSubPicCpbParamsPresentFlag() )
518      {
519        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
520      }
521      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
522      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
523      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
524    }
525  }
526  Int i, j, nalOrVcl;
527  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
528  {
529    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
530    if( !hrd->getFixedPicRateFlag( i ) )
531    {
532      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
533    }
534    else
535    {
536      hrd->setFixedPicRateWithinCvsFlag( i, true );
537    }
538    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
539    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
540    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
541    {
542      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
543    }
544    else
545    {
546      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
547    }
548    if (!hrd->getLowDelayHrdFlag( i ))
549    {
550      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
551    }
552    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
553    {
554      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
555          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
556      {
557        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
558        {
559          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
560          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
561          if( hrd->getSubPicCpbParamsPresentFlag() )
562          {
563            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
564            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
565          }
566          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
567        }
568      }
569    }
570  }
571}
572
573#if SVC_EXTENSION && !SPS_DPB_PARAMS
574Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
575#else
576Void TDecCavlc::parseSPS(TComSPS* pcSPS)
577#endif
578{
579#if ENC_DEC_TRACE
580  xTraceSPSHeader (pcSPS);
581#endif
582
583  UInt  uiCode;
584  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
585#if SVC_EXTENSION
586  if(pcSPS->getLayerId() == 0)
587  {
588#endif
589    READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
590    assert(uiCode <= 6);
591
592    READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
593#if SVC_EXTENSION
594  }
595#if !SPS_DPB_PARAMS
596  else
597  {
598    pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
599    pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
600  }
601#endif
602#endif
603
604#if !Q0177_SPS_TEMP_NESTING_FIX   //This part is not needed anymore as it is already covered by implementation in TDecTop::xActivateParameterSets()
605  if ( pcSPS->getMaxTLayers() == 1 )
606  {
607    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
608#if SVC_EXTENSION
609#if !SPS_DPB_PARAMS
610    assert( pcSPS->getTemporalIdNestingFlag() == true );
611#endif
612#else
613    assert( uiCode == 1 );
614#endif
615  }
616#endif
617
618#ifdef SPS_PTL_FIX
619  if ( pcSPS->getLayerId() == 0)
620  {
621    parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
622  }
623#else
624  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
625#endif
626
627  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
628  assert(uiCode <= 15);
629
630#if REPN_FORMAT_IN_VPS
631  if( pcSPS->getLayerId() > 0 )
632  {
633    READ_FLAG( uiCode, "update_rep_format_flag" );
634    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
635  }
636  else
637  {
638#if REP_FORMAT_FIX
639    pcSPS->setUpdateRepFormatFlag( false );
640#else
641    pcSPS->setUpdateRepFormatFlag( true );
642#endif
643  }
644#if O0096_REP_FORMAT_INDEX
645  if( pcSPS->getLayerId() == 0 )
646#else
647  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
648#endif
649  {
650#endif
651#if AUXILIARY_PICTURES
652    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
653#else
654    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
655#endif
656    assert(uiCode <= 3);
657    // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
658    assert (uiCode == 1);
659    if( uiCode == 3 )
660    {
661      READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
662    }
663
664    READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
665    READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
666#if REPN_FORMAT_IN_VPS
667  }
668#if O0096_REP_FORMAT_INDEX
669  else if ( pcSPS->getUpdateRepFormatFlag() )
670  {
671    READ_CODE(8, uiCode, "update_rep_format_index");
672    pcSPS->setUpdateRepFormatIndex(uiCode);
673  }
674#endif
675#endif
676  READ_FLAG(     uiCode, "conformance_window_flag");
677  if (uiCode != 0)
678  {
679    Window &conf = pcSPS->getConformanceWindow();
680#if REPN_FORMAT_IN_VPS
681    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
682    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
683    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
684    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
685#else
686    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
687    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
688    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
689    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
690#endif
691  }
692#if REPN_FORMAT_IN_VPS
693#if O0096_REP_FORMAT_INDEX
694  if( pcSPS->getLayerId() == 0 )
695#else
696  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
697#endif
698  {
699#endif
700    READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
701    assert(uiCode <= 6);
702    pcSPS->setBitDepthY( uiCode + 8 );
703    pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
704
705    READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
706    assert(uiCode <= 6);
707    pcSPS->setBitDepthC( uiCode + 8 );
708    pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
709#if REPN_FORMAT_IN_VPS
710  }
711#endif
712  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
713  assert(uiCode <= 12);
714
715#if SPS_DPB_PARAMS
716  if( pcSPS->getLayerId() == 0 ) 
717  {
718#endif
719    UInt subLayerOrderingInfoPresentFlag;
720    READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
721
722    for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
723    {
724      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
725      pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
726      READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
727      pcSPS->setNumReorderPics(uiCode, i);
728      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
729      pcSPS->setMaxLatencyIncrease( uiCode, i );
730
731      if (!subLayerOrderingInfoPresentFlag)
732      {
733        for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
734        {
735          pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
736          pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
737          pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
738        }
739        break;
740      }
741    }
742#if SPS_DPB_PARAMS
743  }
744#endif
745  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
746  Int log2MinCUSize = uiCode + 3;
747  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
748  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
749  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
750 
751  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
752  {
753    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
754  }
755 
756  Int maxCUDepthDelta = uiCode;
757  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
758  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
759  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
760
761  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
762  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
763
764  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
765  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
766
767  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
768  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
769  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
770
771  if(pcSPS->getScalingListFlag())
772  {
773#if SCALINGLIST_INFERRING
774    if( pcSPS->getLayerId() > 0 )
775    {
776      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setInferScalingListFlag( uiCode );
777    }
778
779    if( pcSPS->getInferScalingListFlag() )
780    {
781      READ_UVLC( uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setScalingListRefLayerId( uiCode );
782
783      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
784      assert( pcSPS->getScalingListRefLayerId() <= 62 );
785
786      pcSPS->setScalingListPresentFlag( false );
787    }
788    else
789    {
790#endif
791    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
792    if(pcSPS->getScalingListPresentFlag ())
793    {
794      parseScalingList( pcSPS->getScalingList() );
795    }
796#if SCALINGLIST_INFERRING
797    }
798#endif
799  }
800  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
801  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
802
803  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
804  if( pcSPS->getUsePCM() )
805  {
806    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
807    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
808    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
809    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
810    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
811  }
812
813  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
814  assert(uiCode <= 64);
815  pcSPS->createRPSList(uiCode);
816
817  TComRPSList* rpsList = pcSPS->getRPSList();
818  TComReferencePictureSet* rps;
819
820  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
821  {
822    rps = rpsList->getReferencePictureSet(i);
823    parseShortTermRefPicSet(pcSPS,rps,i);
824  }
825  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
826  if (pcSPS->getLongTermRefsPresent())
827  {
828    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
829    pcSPS->setNumLongTermRefPicSPS(uiCode);
830    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
831    {
832      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
833      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
834      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
835      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
836    }
837  }
838  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
839  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
840
841  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
842
843  if (pcSPS->getVuiParametersPresentFlag())
844  {
845    parseVUI(pcSPS->getVuiParameters(), pcSPS);
846  }
847
848  READ_FLAG( uiCode, "sps_extension_flag");
849  if (uiCode)
850  {
851#if SPS_EXTENSION
852
853#if O0142_CONDITIONAL_SPS_EXTENSION
854    UInt spsExtensionTypeFlag[8];
855    for (UInt i = 0; i < 8; i++)
856    {
857      READ_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" );
858    }
859    if (spsExtensionTypeFlag[1])
860    {
861      parseSPSExtension( pcSPS );
862    }
863    if (spsExtensionTypeFlag[7])
864    {
865#else
866    parseSPSExtension( pcSPS );
867    READ_FLAG( uiCode, "sps_extension2_flag");
868    if(uiCode)
869    {
870#endif
871
872#endif
873      while ( xMoreRbspData() )
874      {
875        READ_FLAG( uiCode, "sps_extension_data_flag");
876      }
877#if SPS_EXTENSION
878    }
879#endif
880  }
881}
882
883#if SPS_EXTENSION
884Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
885{
886  UInt uiCode;
887  // more syntax elements to be parsed here
888
889  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );
890  // Vertical MV component restriction is not used in SHVC CTC
891  assert( uiCode == 0 );
892
893  if( pcSPS->getLayerId() > 0 )
894  {
895    Int iCode;
896    READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
897    for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
898    {
899      Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
900#if O0098_SCALED_REF_LAYER_ID
901      READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
902#endif
903      READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
904      READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
905      READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
906      READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
907#if P0312_VERT_PHASE_ADJ
908      READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);   
909#endif
910    }
911  }
912}
913#endif
914
915Void TDecCavlc::parseVPS(TComVPS* pcVPS)
916{
917  UInt  uiCode;
918
919  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
920  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
921#if VPS_RENAME
922#if O0137_MAX_LAYERID
923  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( min( 62u, uiCode) + 1 );
924#else
925  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
926#endif
927#else
928  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
929#endif
930  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode+1 <= MAX_TLAYER);
931  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
932  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
933#if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
934#if VPS_EXTN_OFFSET
935  READ_CODE( 16, uiCode,  "vps_extension_offset" );               pcVPS->setExtensionOffset( uiCode );
936#else
937  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
938#endif
939#else
940  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
941#endif
942  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
943  UInt subLayerOrderingInfoPresentFlag;
944  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
945  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
946  {
947    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
948    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
949    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
950
951    if (!subLayerOrderingInfoPresentFlag)
952    {
953      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
954      {
955        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
956        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
957        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
958      }
959      break;
960    }
961  }
962
963#if VPS_RENAME
964  assert( pcVPS->getNumHrdParameters() < MAX_VPS_LAYER_SETS_PLUS1 );
965  assert( pcVPS->getMaxLayerId()       < MAX_VPS_LAYER_ID_PLUS1 );
966  READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
967  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
968  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
969  {
970    // Operation point set
971    for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ )
972#else
973  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
974  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
975  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
976  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
977  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
978  {
979    // Operation point set
980    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
981#endif
982    {
983      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );   pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
984    }
985  }
986#if DERIVE_LAYER_ID_LIST_VARIABLES
987  pcVPS->deriveLayerIdListVariables();
988#endif
989  TimingInfo *timingInfo = pcVPS->getTimingInfo();
990  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
991  if(timingInfo->getTimingInfoPresentFlag())
992  {
993    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
994    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
995    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
996    if(timingInfo->getPocProportionalToTimingFlag())
997    {
998      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
999    }
1000    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
1001
1002    if( pcVPS->getNumHrdParameters() > 0 )
1003    {
1004      pcVPS->createHrdParamBuffer();
1005    }
1006    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
1007    {
1008      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
1009      if( i > 0 )
1010      {
1011        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
1012      }
1013      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
1014    }
1015  }
1016
1017#if VPS_EXTNS
1018  READ_FLAG( uiCode,  "vps_extension_flag" );      pcVPS->setVpsExtensionFlag( uiCode ? true : false );
1019
1020  // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1.
1021  if( pcVPS->getMaxLayers() > 1 )
1022  {
1023    assert( pcVPS->getVpsExtensionFlag() == true );
1024  }
1025
1026  if( pcVPS->getVpsExtensionFlag()  )
1027  {
1028    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1029    {
1030      READ_FLAG( uiCode, "vps_extension_alignment_bit_equal_to_one"); assert(uiCode == 1);
1031    }
1032    parseVPSExtension(pcVPS);
1033    READ_FLAG( uiCode, "vps_entension2_flag" );
1034    if(uiCode)
1035    {
1036      while ( xMoreRbspData() )
1037      {
1038        READ_FLAG( uiCode, "vps_extension_data_flag");
1039      }
1040    }
1041  }
1042  else
1043  {
1044    // set default parameters when syntax elements are not present
1045    defaultVPSExtension(pcVPS);   
1046  }
1047#else
1048  READ_FLAG( uiCode,  "vps_extension_flag" );
1049  if (uiCode)
1050  {
1051    while ( xMoreRbspData() )
1052    {
1053      READ_FLAG( uiCode, "vps_extension_data_flag");
1054    }
1055  }
1056#endif
1057
1058  return;
1059}
1060
1061#if SVC_EXTENSION
1062#if VPS_EXTNS
1063Void TDecCavlc::parseVPSExtension(TComVPS *vps)
1064{
1065  UInt uiCode;
1066  // ... More syntax elements to be parsed here
1067#if P0300_ALT_OUTPUT_LAYER_FLAG
1068  Int NumOutputLayersInOutputLayerSet[MAX_VPS_LAYER_SETS_PLUS1];
1069  Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
1070#endif
1071#if VPS_EXTN_MASK_AND_DIM_INFO
1072  UInt numScalabilityTypes = 0, i = 0, j = 0;
1073
1074  READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
1075
1076#if !P0307_REMOVE_VPS_VUI_OFFSET
1077#if O0109_MOVE_VPS_VUI_FLAG
1078  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
1079  if ( uiCode )
1080  {
1081#endif
1082#if VPS_VUI_OFFSET
1083  READ_CODE( 16, uiCode, "vps_vui_offset" );  vps->setVpsVuiOffset( uiCode );
1084#endif
1085#if O0109_MOVE_VPS_VUI_FLAG
1086  }
1087#endif
1088#endif
1089  READ_FLAG( uiCode, "splitting_flag" ); vps->setSplittingFlag(uiCode ? true : false);
1090
1091  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
1092  {
1093    READ_FLAG( uiCode, "scalability_mask[i]" ); vps->setScalabilityMask(i, uiCode ? true : false);
1094    numScalabilityTypes += uiCode;
1095  }
1096  vps->setNumScalabilityTypes(numScalabilityTypes);
1097
1098  for(j = 0; j < numScalabilityTypes - vps->getSplittingFlag(); j++)
1099  {
1100    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
1101  }
1102
1103  if(vps->getSplittingFlag())
1104  {
1105    UInt numBits = 0;
1106    for(j = 0; j < numScalabilityTypes - 1; j++)
1107    {
1108      numBits += vps->getDimensionIdLen(j);
1109    }
1110    assert( numBits < 6 );
1111    vps->setDimensionIdLen(numScalabilityTypes-1, 6 - numBits);
1112    numBits = 6;
1113  }
1114
1115  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
1116  vps->setLayerIdInNuh(0, 0);
1117  vps->setLayerIdInVps(0, 0);
1118  for(i = 1; i < vps->getMaxLayers(); i++)
1119  {
1120    if( vps->getNuhLayerIdPresentFlag() )
1121    {
1122      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" ); vps->setLayerIdInNuh(i, uiCode);
1123      assert( uiCode > vps->getLayerIdInNuh(i-1) );
1124    }
1125    else
1126    {
1127      vps->setLayerIdInNuh(i, i);
1128    }
1129    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
1130
1131    if( !vps->getSplittingFlag() )
1132    {
1133    for(j = 0; j < numScalabilityTypes; j++)
1134    {
1135      READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
1136#if !AUXILIARY_PICTURES
1137      assert( uiCode <= vps->getMaxLayerId() );
1138#endif
1139    }
1140  }
1141  }
1142#endif
1143#if VIEW_ID_RELATED_SIGNALING
1144  // if ( pcVPS->getNumViews() > 1 )
1145  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
1146  {
1147#if O0109_VIEW_ID_LEN
1148    READ_CODE( 4, uiCode, "view_id_len" ); vps->setViewIdLen( uiCode );
1149#else
1150    READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
1151#endif
1152  }
1153
1154#if O0109_VIEW_ID_LEN
1155  if ( vps->getViewIdLen() > 0 )
1156  {
1157    for(  i = 0; i < vps->getNumViews(); i++ )
1158    {
1159      READ_CODE( vps->getViewIdLen( ), uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
1160    }
1161  }
1162#else
1163  for(  i = 0; i < vps->getNumViews(); i++ )
1164  {
1165    READ_CODE( vps->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); vps->setViewIdVal( i, uiCode );
1166  }
1167#endif
1168#endif // view id related signaling
1169#if VPS_EXTN_DIRECT_REF_LAYERS
1170  // For layer 0
1171  vps->setNumDirectRefLayers(0, 0);
1172  // For other layers
1173  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
1174  {
1175    UInt numDirectRefLayers = 0;
1176    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
1177    {
1178      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
1179      if(uiCode)
1180      {
1181        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
1182        numDirectRefLayers++;
1183      }
1184    }
1185    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
1186  }
1187#endif
1188#if VPS_TSLAYERS
1189  READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
1190
1191  if (vps->getMaxTSLayersPresentFlag())
1192  {
1193    for(i = 0; i < vps->getMaxLayers(); i++)
1194    {
1195      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
1196    }
1197  }
1198  else
1199  {
1200    for( i = 0; i < vps->getMaxLayers(); i++)
1201    {
1202      vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
1203    }
1204  }
1205#endif
1206#if N0120_MAX_TID_REF_PRESENT_FLAG
1207  READ_FLAG( uiCode, "max_tid_ref_present_flag"); vps->setMaxTidRefPresentFlag(uiCode ? true : false);
1208  if (vps->getMaxTidRefPresentFlag())
1209  {
1210    for(i = 0; i < vps->getMaxLayers() - 1; i++)
1211    {
1212#if O0225_MAX_TID_FOR_REF_LAYERS
1213       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
1214       {
1215         if(vps->getDirectDependencyFlag(j, i))
1216         {
1217           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
1218           assert( uiCode <= vps->getMaxTLayers());
1219         }
1220       }
1221#else
1222      READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
1223#if N0120_MAX_TID_REF_CFG
1224      assert( uiCode <= vps->getMaxTLayers());
1225#else
1226      assert( uiCode <= vps->getMaxTLayers()+ 1 );
1227#endif
1228#endif
1229    }
1230  }
1231  else
1232  {
1233    for(i = 0; i < vps->getMaxLayers() - 1; i++)
1234    {
1235#if O0225_MAX_TID_FOR_REF_LAYERS
1236       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
1237       {
1238          vps->setMaxTidIlRefPicsPlus1(i, j, 7);
1239       }
1240#else
1241      vps->setMaxTidIlRefPicsPlus1(i, 7);
1242#endif
1243    }
1244  }
1245#else
1246  for(i = 0; i < vps->getMaxLayers() - 1; i++)
1247  {
1248#if O0225_MAX_TID_FOR_REF_LAYERS
1249       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
1250       {
1251         if(vps->getDirectDependencyFlag(j, i))
1252         {
1253           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
1254           assert( uiCode <= vps->getMaxTLayers() );
1255         }
1256       }
1257#else
1258    READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
1259    assert( uiCode <= vps->getMaxTLayers() );
1260#endif   
1261  }
1262#endif
1263#if ILP_SSH_SIG
1264    READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
1265#endif
1266#if VPS_EXTN_PROFILE_INFO
1267  // Profile-tier-level signalling
1268#if !VPS_EXTN_UEV_CODING
1269  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1" );     assert( uiCode == (vps->getNumLayerSets() - 1) );
1270  READ_CODE(  6, uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
1271#else
1272  READ_UVLC(  uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
1273#endif
1274  vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
1275  for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
1276  {
1277    READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
1278    if( !vps->getProfilePresentFlag(idx) )
1279    {
1280#if P0048_REMOVE_PROFILE_REF
1281      // Copy profile information from previous one
1282      vps->getPTLForExtn(idx)->copyProfileInfo( (idx==1) ? vps->getPTL() : vps->getPTLForExtn( idx - 1 ) );
1283#else
1284      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
1285#if O0109_PROF_REF_MINUS1
1286      assert( vps->getProfileLayerSetRef(idx) <= idx );
1287#else
1288      assert( vps->getProfileLayerSetRef(idx) < idx );
1289#endif
1290      // Copy profile information as indicated
1291      vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
1292#endif
1293    }
1294    parsePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
1295  }
1296#endif
1297
1298#if !VPS_EXTN_UEV_CODING
1299  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
1300  Int numOutputLayerSets = 0;
1301  if(! vps->getMoreOutputLayerSetsThanDefaultFlag() )
1302  {
1303    numOutputLayerSets = vps->getNumLayerSets();
1304  }
1305  else
1306  {
1307    READ_CODE( 10, uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
1308    numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
1309  }
1310#else
1311
1312#if Q0165_NUM_ADD_OUTPUT_LAYER_SETS
1313  if( vps->getNumLayerSets() > 1 )
1314  {
1315    READ_UVLC( uiCode, "num_add_output_layer_sets" );            vps->setNumAddOutputLayerSets( uiCode );
1316    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
1317  }
1318  else
1319  {
1320    vps->setNumAddOutputLayerSets( 0 );
1321  }
1322#else
1323  READ_UVLC( uiCode, "num_add_output_layer_sets" );          vps->setNumAddOutputLayerSets( uiCode );
1324#endif
1325
1326  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
1327  assert( vps->getNumAddOutputLayerSets() >= 0 && vps->getNumAddOutputLayerSets() < 1024 );
1328
1329  Int numOutputLayerSets = vps->getNumLayerSets() + vps->getNumAddOutputLayerSets();
1330#endif
1331
1332#if P0295_DEFAULT_OUT_LAYER_IDC
1333#if !Q0165_NUM_ADD_OUTPUT_LAYER_SETS
1334  if( numOutputLayerSets > 1 )
1335  {
1336    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
1337  }
1338#endif
1339  vps->setNumOutputLayerSets( numOutputLayerSets );
1340
1341  for(i = 1; i < numOutputLayerSets; i++)
1342  {
1343    if( i > (vps->getNumLayerSets() - 1) )
1344    {
1345      Int numBits = 1;
1346      while ((1 << numBits) < (vps->getNumLayerSets() - 1))
1347      {
1348        numBits++;
1349      }
1350      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
1351    }
1352    else
1353    {
1354      vps->setOutputLayerSetIdx( i, i );
1355    }
1356    if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 )
1357    {
1358      Int lsIdx = vps->getOutputLayerSetIdx(i);
1359#if NUM_OL_FLAGS
1360      for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1361#else
1362      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
1363#endif
1364      {
1365        READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
1366      }
1367    }
1368    else
1369    {
1370      // i <= (vps->getNumLayerSets() - 1)
1371      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
1372      Int lsIdx = i;
1373      if( vps->getDefaultTargetOutputLayerIdc() == 1 )
1374      {
1375        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1376        {
1377          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1) == 0) );
1378        }
1379      }
1380      else if ( vps->getDefaultTargetOutputLayerIdc() == 0 )
1381      {
1382        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1383        {
1384          vps->setOutputLayerFlag(i, j, 1);
1385        }
1386      }
1387    }
1388    Int numBits = 1;
1389    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
1390    {
1391      numBits++;
1392    }
1393    READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
1394#if P0300_ALT_OUTPUT_LAYER_FLAG
1395    NumOutputLayersInOutputLayerSet[i] = 0;
1396    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
1397    for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
1398    {
1399      NumOutputLayersInOutputLayerSet[i] += vps->getOutputLayerFlag(i, j);
1400      if (vps->getOutputLayerFlag(i, j))
1401      {
1402        OlsHighestOutputLayerId[i] = vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j);
1403      }
1404    }
1405    if (NumOutputLayersInOutputLayerSet[i] == 1 && vps->getNumDirectRefLayers(OlsHighestOutputLayerId[i]) > 0)
1406    {
1407      READ_FLAG(uiCode, "alt_output_layer_flag[i]");
1408      vps->setAltOuputLayerFlag(i, uiCode ? true : false);
1409    }
1410#if Q0165_OUTPUT_LAYER_SET
1411    assert( NumOutputLayersInOutputLayerSet[i]>0 );
1412#endif
1413
1414#endif
1415  }
1416#else
1417  if( numOutputLayerSets > 1 )
1418  {
1419#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
1420    READ_CODE( 2, uiCode, "default_one_target_output_layer_idc" );   vps->setDefaultOneTargetOutputLayerIdc( uiCode );
1421#else
1422    READ_FLAG( uiCode, "default_one_target_output_layer_flag" );   vps->setDefaultOneTargetOutputLayerFlag( uiCode ? true : false );
1423#endif
1424  }
1425  vps->setNumOutputLayerSets( numOutputLayerSets );
1426
1427  for(i = 1; i < numOutputLayerSets; i++)
1428  {
1429    if( i > (vps->getNumLayerSets() - 1) )
1430    {
1431      Int numBits = 1;
1432      while ((1 << numBits) < (vps->getNumLayerSets() - 1))
1433      {
1434        numBits++;
1435      }
1436      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
1437      Int lsIdx = vps->getOutputLayerSetIdx(i);
1438#if NUM_OL_FLAGS
1439      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) ; j++)
1440#else
1441      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
1442#endif
1443      {
1444        READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
1445      }
1446    }
1447    else
1448    {
1449#if VPS_DPB_SIZE_TABLE
1450      vps->setOutputLayerSetIdx( i, i );
1451#endif
1452      // i <= (vps->getNumLayerSets() - 1)
1453      // Assign OutputLayerFlag depending on default_one_target_output_layer_flag
1454      Int lsIdx = i;
1455#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
1456      if( vps->getDefaultOneTargetOutputLayerIdc() == 1 )
1457      {
1458        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1459        {
1460#if O0135_DEFAULT_ONE_OUT_SEMANTIC
1461          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)) && (vps->getDimensionId(j,1)==0) );
1462#else
1463          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
1464#endif
1465        }
1466      }
1467      else if ( vps->getDefaultOneTargetOutputLayerIdc() == 0 )
1468      {
1469        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1470        {
1471          vps->setOutputLayerFlag(i, j, 1);
1472        }
1473      }
1474      else
1475      {
1476        // Other values of default_one_target_output_layer_idc than 0 and 1 are reserved for future use.
1477      }
1478#else
1479      if( vps->getDefaultOneTargetOutputLayerFlag() )
1480      {
1481        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1482        {
1483          vps->setOutputLayerFlag(i, j, (j == (vps->getNumLayersInIdList(lsIdx)-1)));
1484        }
1485      }
1486      else
1487      {
1488        for(j = 0; j < vps->getNumLayersInIdList(lsIdx); j++)
1489        {
1490          vps->setOutputLayerFlag(i, j, 1);
1491        }
1492      }
1493#endif
1494    }
1495    Int numBits = 1;
1496    while ((1 << numBits) < (vps->getNumProfileTierLevel()))
1497    {
1498      numBits++;
1499    }
1500    READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
1501  }
1502#endif
1503
1504#if !P0300_ALT_OUTPUT_LAYER_FLAG
1505#if O0153_ALT_OUTPUT_LAYER_FLAG
1506  if( vps->getMaxLayers() > 1 )
1507  {
1508    READ_FLAG( uiCode, "alt_output_layer_flag");
1509    vps->setAltOuputLayerFlag( uiCode ? true : false );
1510  }
1511#endif
1512#endif
1513
1514#if REPN_FORMAT_IN_VPS
1515#if Q0195_REP_FORMAT_CLEANUP
1516  READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
1517  vps->setVpsNumRepFormats( uiCode + 1 );
1518
1519  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
1520  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
1521
1522  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
1523  {
1524    // Read rep_format_structures
1525    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
1526  }
1527
1528  // Default assignment for layer 0
1529  vps->setVpsRepFormatIdx( 0, 0 );
1530
1531  if( vps->getVpsNumRepFormats() > 1 )
1532  {
1533    READ_FLAG( uiCode, "rep_format_idx_present_flag");
1534    vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
1535  }
1536  else
1537  {
1538    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
1539    vps->setRepFormatIdxPresentFlag( false );
1540  }
1541
1542  if( vps->getRepFormatIdxPresentFlag() )
1543  {
1544    for(i = 1; i < vps->getMaxLayers(); i++)
1545    {
1546      Int numBits = 1;
1547      while ((1 << numBits) < (vps->getVpsNumRepFormats()))
1548      {
1549        numBits++;
1550      }
1551      READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
1552      vps->setVpsRepFormatIdx( i, uiCode );
1553    }
1554  }
1555  else
1556  {
1557    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min (i, vps_num_rep_formats_minus1)
1558    for(i = 1; i < vps->getMaxLayers(); i++)
1559    {
1560      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats()-1 ) );
1561    }
1562  }
1563#else
1564  READ_FLAG( uiCode, "rep_format_idx_present_flag");
1565  vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
1566
1567  if( vps->getRepFormatIdxPresentFlag() )
1568  {
1569#if O0096_REP_FORMAT_INDEX
1570#if !VPS_EXTN_UEV_CODING
1571    READ_CODE( 8, uiCode, "vps_num_rep_formats_minus1" );
1572#else
1573    READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
1574#endif
1575#else
1576    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" );
1577#endif
1578    vps->setVpsNumRepFormats( uiCode + 1 );
1579  }
1580  else
1581  {
1582    // default assignment
1583    assert (vps->getMaxLayers() <= 16);       // If max_layers_is more than 15, num_rep_formats has to be signaled
1584    vps->setVpsNumRepFormats( vps->getMaxLayers() );
1585  }
1586
1587  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
1588  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
1589
1590  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
1591  {
1592    // Read rep_format_structures
1593    parseRepFormat( vps->getVpsRepFormat(i), i > 0 ? vps->getVpsRepFormat(i-1) : 0 );
1594  }
1595
1596  // Default assignment for layer 0
1597  vps->setVpsRepFormatIdx( 0, 0 );
1598  if( vps->getRepFormatIdxPresentFlag() )
1599  {
1600    for(i = 1; i < vps->getMaxLayers(); i++)
1601    {
1602      if( vps->getVpsNumRepFormats() > 1 )
1603      {
1604#if O0096_REP_FORMAT_INDEX
1605#if !VPS_EXTN_UEV_CODING
1606        READ_CODE( 8, uiCode, "vps_rep_format_idx[i]" );
1607#else
1608        Int numBits = 1;
1609        while ((1 << numBits) < (vps->getVpsNumRepFormats()))
1610        {
1611          numBits++;
1612        }
1613        READ_CODE( numBits, uiCode, "vps_rep_format_idx[i]" );
1614#endif
1615#else
1616        READ_CODE( 4, uiCode, "vps_rep_format_idx[i]" );
1617#endif
1618        vps->setVpsRepFormatIdx( i, uiCode );
1619      }
1620      else
1621      {
1622        // default assignment - only one rep_format() structure
1623        vps->setVpsRepFormatIdx( i, 0 );
1624      }
1625    }
1626  }
1627  else
1628  {
1629    // default assignment - each layer assigned each rep_format() structure in the order signaled
1630    for(i = 1; i < vps->getMaxLayers(); i++)
1631    {
1632      vps->setVpsRepFormatIdx( i, i );
1633    }
1634  }
1635#endif
1636#endif
1637#if RESOLUTION_BASED_DPB
1638  vps->assignSubDpbIndices();
1639#endif
1640  READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
1641  vps->setMaxOneActiveRefLayerFlag(uiCode);
1642#if O0062_POC_LSB_NOT_PRESENT_FLAG
1643  for(i = 1; i< vps->getMaxLayers(); i++)
1644  {
1645    if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
1646    {
1647      READ_FLAG(uiCode, "poc_lsb_not_present_flag[i]");
1648      vps->setPocLsbNotPresentFlag(i, uiCode);
1649    }
1650  }
1651#endif
1652#if O0215_PHASE_ALIGNMENT
1653  READ_FLAG( uiCode, "cross_layer_phase_alignment_flag"); vps->setPhaseAlignFlag( uiCode == 1 ? true : false );
1654#endif
1655
1656#if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI
1657  READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
1658  vps->setCrossLayerIrapAlignFlag(uiCode);
1659#endif
1660
1661#if VPS_DPB_SIZE_TABLE
1662  parseVpsDpbSizeTable(vps);
1663#endif
1664
1665#if VPS_EXTN_DIRECT_REF_LAYERS
1666  READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
1667#if O0096_DEFAULT_DEPENDENCY_TYPE
1668  READ_FLAG(uiCode, "default_direct_dependency_type_flag"); 
1669  vps->setDefaultDirectDependecyTypeFlag(uiCode == 1? true : false);
1670  if (vps->getDefaultDirectDependencyTypeFlag())
1671  {
1672    READ_CODE( vps->getDirectDepTypeLen(), uiCode, "default_direct_dependency_type" ); 
1673    vps->setDefaultDirectDependecyType(uiCode);
1674  }
1675#endif
1676  for(i = 1; i < vps->getMaxLayers(); i++)
1677  {
1678    for(j = 0; j < i; j++)
1679    {
1680      if (vps->getDirectDependencyFlag(i, j))
1681      {
1682#if O0096_DEFAULT_DEPENDENCY_TYPE
1683        if (vps->getDefaultDirectDependencyTypeFlag())
1684        {
1685          vps->setDirectDependencyType(i, j, vps->getDefaultDirectDependencyType());
1686        }
1687        else
1688        {
1689          READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); 
1690          vps->setDirectDependencyType(i, j, uiCode);
1691        }
1692#else
1693        READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); 
1694        vps->setDirectDependencyType(i, j, uiCode);
1695#endif
1696      }
1697    }
1698  }
1699#endif
1700#if O0092_0094_DEPENDENCY_CONSTRAINT
1701  vps->setNumRefLayers();
1702
1703  if(vps->getMaxLayers() > MAX_REF_LAYERS)
1704  {
1705    for(i = 1;i < vps->getMaxLayers(); i++)
1706    {
1707      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
1708    }
1709  }
1710#endif
1711
1712#if P0307_VPS_NON_VUI_EXTENSION
1713  READ_UVLC( uiCode,           "vps_non_vui_extension_length"); vps->setVpsNonVuiExtLength((Int)uiCode);
1714
1715  // The value of vps_non_vui_extension_length shall be in the range of 0 to 4096, inclusive.
1716  assert( vps->getVpsNonVuiExtLength() >= 0 && vps->getVpsNonVuiExtLength() <= 4096 );
1717
1718#if P0307_VPS_NON_VUI_EXT_UPDATE
1719  Int nonVuiExtByte = uiCode;
1720  for (i = 1; i <= nonVuiExtByte; i++)
1721  {
1722    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" ); //just parse and discard for now.
1723  }
1724#else
1725  if ( vps->getVpsNonVuiExtLength() > 0 )
1726  {
1727    printf("\n\nUp to the current spec, the value of vps_non_vui_extension_length is supposed to be 0\n");
1728  }
1729#endif
1730#endif
1731
1732#if !O0109_O0199_FLAGS_TO_VUI
1733#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1734  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
1735#endif
1736#if HIGHER_LAYER_IRAP_SKIP_FLAG
1737  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
1738#endif
1739#endif
1740
1741#if P0307_REMOVE_VPS_VUI_OFFSET
1742  READ_FLAG( uiCode, "vps_vui_present_flag"); vps->setVpsVuiPresentFlag(uiCode ? true : false);
1743#endif
1744
1745#if O0109_MOVE_VPS_VUI_FLAG
1746  if ( vps->getVpsVuiPresentFlag() )
1747#else
1748  READ_FLAG( uiCode,  "vps_vui_present_flag" );
1749  if (uiCode)
1750#endif
1751  {
1752#if VPS_VUI
1753    while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
1754    {
1755      READ_FLAG( uiCode, "vps_vui_alignment_bit_equal_to_one"); assert(uiCode == 1);
1756    }
1757    parseVPSVUI(vps);
1758#endif
1759  }
1760  else
1761  {
1762    // set default values for VPS VUI
1763    defaultVPSVUI( vps );
1764  }
1765}
1766
1767Void TDecCavlc::defaultVPSExtension( TComVPS* vps )
1768{
1769  // set default parameters when they are not present
1770  Int i, j;
1771
1772  // When layer_id_in_nuh[ i ] is not present, the value is inferred to be equal to i.
1773  for(i = 0; i < vps->getMaxLayers(); i++)
1774  {
1775    vps->setLayerIdInNuh(i, i);
1776    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
1777  }
1778
1779  // When not present, sub_layers_vps_max_minus1[ i ] is inferred to be equal to vps_max_sub_layers_minus1.
1780  for( i = 0; i < vps->getMaxLayers(); i++)
1781  {
1782    vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
1783  }
1784
1785  // When not present, max_tid_il_ref_pics_plus1[ i ][ j ] is inferred to be equal to 7.
1786  for( i = 0; i < vps->getMaxLayers() - 1; i++ )
1787  {
1788#if O0225_MAX_TID_FOR_REF_LAYERS
1789    for( j = i + 1; j < vps->getMaxLayers(); j++ )
1790    {
1791      vps->setMaxTidIlRefPicsPlus1(i, j, 7);
1792    }
1793#else
1794    vps->setMaxTidIlRefPicsPlus1(i, 7);
1795#endif
1796  }
1797 
1798  // When not present, the value of num_add_output_layer_sets is inferred to be equal to 0.
1799  // NumOutputLayerSets = num_add_output_layer_sets + vps_num_layer_sets_minus1 + 1
1800  vps->setNumOutputLayerSets( vps->getNumLayerSets() );
1801
1802  // For i in the range of 0 to NumOutputLayerSets-1, inclusive, the variable LayerSetIdxForOutputLayerSet[ i ] is derived as specified in the following:
1803  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : output_layer_set_idx_minus1[ i ] + 1
1804  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
1805  {
1806    vps->setOutputLayerSetIdx( i, i );
1807    Int lsIdx = vps->getOutputLayerSetIdx(i);
1808
1809    for( j = 0; j < vps->getNumLayersInIdList(lsIdx); j++ )
1810    {
1811    vps->setOutputLayerFlag(i, j, 1);
1812    }
1813  }
1814
1815  // The value of sub_layer_dpb_info_present_flag[ i ][ 0 ] for any possible value of i is inferred to be equal to 1
1816  // 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.
1817  for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
1818  {
1819    vps->setSubLayerDpbInfoPresentFlag( i, 0, true );
1820  }
1821 
1822  // When not present, the value of vps_num_rep_formats_minus1 is inferred to be equal to MaxLayersMinus1.
1823  vps->setVpsNumRepFormats( vps->getMaxLayers() );
1824
1825  // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
1826  vps->setRepFormatIdxPresentFlag( false );
1827
1828  if( !vps->getRepFormatIdxPresentFlag() )
1829  {
1830    // When not present, the value of vps_rep_format_idx[ i ] is inferred to be equal to Min(i, vps_num_rep_formats_minus1).
1831    for(i = 1; i < vps->getMaxLayers(); i++)
1832    {
1833      vps->setVpsRepFormatIdx( i, min( (Int)i, vps->getVpsNumRepFormats() - 1 ) );
1834    }
1835  }
1836
1837  // vps_poc_lsb_aligned_flag
1838  // When not present, vps_poc_lsb_aligned_flag is inferred to be equal to 0.
1839 
1840#if O0062_POC_LSB_NOT_PRESENT_FLAG
1841  // When not present, poc_lsb_not_present_flag[ i ] is inferred to be equal to 0.
1842  for(i = 1; i< vps->getMaxLayers(); i++)
1843  {
1844    vps->setPocLsbNotPresentFlag(i, 0);
1845  }
1846#endif
1847
1848  // set default values for VPS VUI
1849  defaultVPSVUI( vps );
1850}
1851
1852Void TDecCavlc::defaultVPSVUI( TComVPS* vps )
1853{
1854#if N0147_IRAP_ALIGN_FLAG
1855  // When not present, the value of all_layers_idr_aligned_flag is inferred to be equal to 0.
1856  vps->setCrossLayerIrapAlignFlag( false );
1857#endif
1858
1859#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1860  // When single_layer_for_non_irap_flag is not present, it is inferred to be equal to 0.
1861  vps->setSingleLayerForNonIrapFlag( false );
1862#endif
1863
1864#if HIGHER_LAYER_IRAP_SKIP_FLAG
1865  // When higher_layer_irap_skip_flag is not present it is inferred to be equal to 0
1866  vps->setHigherLayerIrapSkipFlag( false );
1867#endif
1868}
1869#endif
1870
1871#if REPN_FORMAT_IN_VPS
1872Void  TDecCavlc::parseRepFormat( RepFormat *repFormat, RepFormat *repFormatPrev )
1873{
1874  UInt uiCode;
1875#if REPN_FORMAT_CONTROL_FLAG 
1876  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );        repFormat->setPicWidthVpsInLumaSamples ( uiCode );
1877  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" );       repFormat->setPicHeightVpsInLumaSamples( uiCode );
1878  READ_FLAG( uiCode, "chroma_and_bit_depth_vps_present_flag" );    repFormat->setChromaAndBitDepthVpsPresentFlag( uiCode ? true : false ); 
1879
1880  if( !repFormatPrev )
1881  {
1882    // 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
1883    assert( repFormat->getChromaAndBitDepthVpsPresentFlag() );
1884  }
1885
1886  if( repFormat->getChromaAndBitDepthVpsPresentFlag() )
1887  {
1888    READ_CODE( 2, uiCode, "chroma_format_vps_idc" );
1889#if AUXILIARY_PICTURES
1890    repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
1891#else
1892    repFormat->setChromaFormatVpsIdc( uiCode );
1893#endif
1894
1895    if( repFormat->getChromaFormatVpsIdc() == 3 )
1896    {
1897      READ_FLAG( uiCode, "separate_colour_plane_vps_flag" );       repFormat->setSeparateColourPlaneVpsFlag( uiCode ? true : false );
1898    }
1899
1900    READ_CODE( 4, uiCode, "bit_depth_vps_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
1901    READ_CODE( 4, uiCode, "bit_depth_vps_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
1902  }
1903  else if( repFormatPrev )
1904  {
1905    // 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
1906    // bit_depth_vps_chroma_minus8 are not present and inferred from the previous rep_format( ) syntax structure in the VPS.
1907
1908    repFormat->setChromaFormatVpsIdc        ( repFormatPrev->getChromaFormatVpsIdc() );
1909    repFormat->setSeparateColourPlaneVpsFlag( repFormatPrev->getSeparateColourPlaneVpsFlag() );
1910    repFormat->setBitDepthVpsLuma           ( repFormatPrev->getBitDepthVpsLuma() );
1911    repFormat->setBitDepthVpsChroma         ( repFormatPrev->getBitDepthVpsChroma() );
1912  }
1913#else
1914#if AUXILIARY_PICTURES
1915  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
1916#else
1917  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
1918#endif
1919 
1920  if( repFormat->getChromaFormatVpsIdc() == 3 )
1921  {
1922    READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
1923  }
1924
1925  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
1926  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
1927
1928  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
1929  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
1930#endif
1931}
1932#endif
1933#if VPS_DPB_SIZE_TABLE
1934Void TDecCavlc::parseVpsDpbSizeTable( TComVPS *vps )
1935{
1936  UInt uiCode;
1937#if DPB_PARAMS_MAXTLAYERS
1938#if BITRATE_PICRATE_SIGNALLING
1939    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
1940    for(Int i = 0; i < vps->getNumLayerSets(); i++)
1941#else
1942    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
1943    for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
1944#endif
1945    {
1946        UInt maxSLMinus1 = 0;
1947#if CHANGE_NUMSUBDPB_IDX
1948        Int optLsIdx = vps->getOutputLayerSetIdx( i );
1949#else
1950        Int optLsIdx = i;
1951#endif
1952#if BITRATE_PICRATE_SIGNALLING
1953        optLsIdx = i;
1954#endif
1955        for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
1956            Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
1957            maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
1958        }
1959        MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
1960#if BITRATE_PICRATE_SIGNALLING
1961        vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
1962#endif
1963    }
1964#endif
1965   
1966#if !RESOLUTION_BASED_DPB
1967  vps->deriveNumberOfSubDpbs();
1968#endif
1969  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
1970  {
1971#if CHANGE_NUMSUBDPB_IDX
1972    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
1973#endif
1974    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
1975#if DPB_PARAMS_MAXTLAYERS
1976#if BITRATE_PICRATE_SIGNALLING
1977    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ vps->getOutputLayerSetIdx( i ) ]; j++)
1978#else
1979    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
1980#endif
1981#else
1982    for(Int j = 0; j <= vps->getMaxTLayers(); j++)
1983#endif
1984    {
1985      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
1986      {
1987        READ_FLAG( uiCode, "sub_layer_dpb_info_present_flag[i]");  vps->setSubLayerDpbInfoPresentFlag( i, j, uiCode ? true : false);
1988      }
1989      else
1990      {
1991        if( j == 0 )  // Always signal for the first sub-layer
1992        {
1993          vps->setSubLayerDpbInfoPresentFlag( i, j, true );
1994        }
1995        else // if (j != 0) && !vps->getSubLayerFlagInfoPresentFlag(i)
1996        {
1997          vps->setSubLayerDpbInfoPresentFlag( i, j, false );
1998        }
1999      }
2000      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is present
2001      {
2002#if CHANGE_NUMSUBDPB_IDX
2003        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
2004#else
2005        for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
2006#endif
2007        {
2008          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1[i][k][j]" ); vps->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
2009        }
2010        READ_UVLC( uiCode, "max_vps_num_reorder_pics[i][j]" );              vps->setMaxVpsNumReorderPics( i, j, uiCode);
2011#if RESOLUTION_BASED_DPB
2012        if( vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) != vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ) ) 
2013        {
2014          for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
2015          {
2016            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1[i][k][j]" ); vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode);
2017          }
2018        }
2019        else  // vps->getNumSubDpbs(layerSetIdxForOutputLayerSet) == vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet )
2020        {         
2021          for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
2022          {
2023            vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j));
2024          }
2025        }
2026#endif
2027        READ_UVLC( uiCode, "max_vps_latency_increase_plus1[i][j]" );        vps->setMaxVpsLatencyIncreasePlus1( i, j, uiCode);
2028      }
2029    }
2030    for(Int j = vps->getMaxTLayers(); j < MAX_TLAYER; j++)
2031    {
2032      vps->setSubLayerDpbInfoPresentFlag( i, j, false );
2033    }
2034  }
2035
2036  // Infer values when not signalled
2037  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
2038  {
2039    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
2040    for(Int j = 0; j < MAX_TLAYER; j++)
2041    {
2042      if( !vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is NOT present
2043      {
2044#if RESOLUTION_BASED_DPB
2045        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
2046#else
2047        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
2048#endif
2049        {
2050          vps->setMaxVpsDecPicBufferingMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
2051        }
2052        vps->setMaxVpsNumReorderPics( i, j, vps->getMaxVpsNumReorderPics( i, j - 1) );
2053#if RESOLUTION_BASED_DPB
2054        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
2055        {
2056          vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j - 1));
2057        }
2058#endif
2059        vps->setMaxVpsLatencyIncreasePlus1( i, j, vps->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
2060      }
2061    }
2062  }
2063}
2064#endif
2065#if VPS_VUI
2066Void TDecCavlc::parseVPSVUI(TComVPS *vps)
2067{
2068  UInt i,j;
2069  UInt uiCode;
2070#if O0223_PICTURE_TYPES_ALIGN_FLAG
2071  READ_FLAG(uiCode, "cross_layer_pic_type_aligned_flag" );
2072  vps->setCrossLayerPictureTypeAlignFlag(uiCode);
2073  if (!uiCode) 
2074  {
2075#endif
2076#if IRAP_ALIGN_FLAG_IN_VPS_VUI
2077    READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
2078    vps->setCrossLayerIrapAlignFlag(uiCode);
2079#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
2080    if (uiCode)
2081    {
2082      READ_FLAG(uiCode, "all_layers_idr_aligned_flag" );
2083      vps->setCrossLayerIrapAlignFlag(uiCode);
2084    }
2085#endif
2086#endif
2087#if O0223_PICTURE_TYPES_ALIGN_FLAG
2088  }
2089  else
2090  {
2091    vps->setCrossLayerIrapAlignFlag(true);
2092  }
2093#endif
2094#if VPS_VUI_BITRATE_PICRATE
2095  READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
2096  READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
2097
2098  Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
2099  {
2100    for( i = 0; i < vps->getNumLayerSets(); i++ )
2101    {
2102#if BITRATE_PICRATE_SIGNALLING
2103      for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ )
2104#else
2105      for( j = 0; j < vps->getMaxTLayers(); j++ )
2106#endif
2107      {
2108        if( parseFlag && vps->getBitRatePresentVpsFlag() )
2109        {
2110          READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
2111        }
2112        else
2113        {
2114          vps->setBitRatePresentFlag( i, j, false );
2115        }
2116        if( parseFlag && vps->getPicRatePresentVpsFlag() )
2117        {
2118          READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
2119        }
2120        else
2121        {
2122          vps->setPicRatePresentFlag( i, j, false );
2123        }
2124        if( parseFlag && vps->getBitRatePresentFlag(i, j) )
2125        {
2126          READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
2127          READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
2128        }
2129        else
2130        {
2131          vps->setAvgBitRate( i, j, 0 );
2132          vps->setMaxBitRate( i, j, 0 );
2133        }
2134        if( parseFlag && vps->getPicRatePresentFlag(i, j) )
2135        {
2136          READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
2137          READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
2138        }
2139        else
2140        {
2141          vps->setConstPicRateIdc( i, j, 0 );
2142          vps->setAvgPicRate     ( i, j, 0 );
2143        }
2144      }
2145    }
2146  }
2147#endif
2148#if VPS_VUI_VIDEO_SIGNAL_MOVE
2149  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
2150  if (vps->getVideoSigPresentVpsFlag())
2151  {
2152    READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
2153  }
2154  else
2155  {
2156    vps->setNumVideoSignalInfo(vps->getMaxLayers());
2157  }
2158
2159  for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
2160  {
2161    READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
2162    READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
2163    READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
2164    READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
2165    READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
2166  }
2167  if(!vps->getVideoSigPresentVpsFlag())
2168  {
2169    for (i=0; i < vps->getMaxLayers(); i++)
2170    {
2171      vps->setVideoSignalInfoIdx(i,i);
2172    }
2173  }
2174  else {
2175    vps->setVideoSignalInfoIdx(0,0);
2176    if (vps->getNumVideoSignalInfo() > 1 )
2177    {
2178      for (i=1; i < vps->getMaxLayers(); i++)
2179        READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
2180    }
2181    else {
2182      for (i=1; i < vps->getMaxLayers(); i++)
2183      {
2184        vps->setVideoSignalInfoIdx(i,0);
2185      }
2186    }
2187  }
2188#endif
2189#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2190  UInt layerIdx;
2191  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); vps->setTilesNotInUseFlag(uiCode == 1);
2192  if (!uiCode)
2193  {
2194    for(i = 0; i < vps->getMaxLayers(); i++)
2195    {
2196      READ_FLAG( uiCode, "tiles_in_use_flag[ i ]" ); vps->setTilesInUseFlag(i, (uiCode == 1));
2197      if (uiCode)
2198      {
2199        READ_FLAG( uiCode, "loop_filter_not_across_tiles_flag[ i ]" ); vps->setLoopFilterNotAcrossTilesFlag(i, (uiCode == 1));
2200      }
2201      else
2202      {
2203        vps->setLoopFilterNotAcrossTilesFlag(i, false);
2204      }
2205    }
2206#endif
2207#if TILE_BOUNDARY_ALIGNED_FLAG
2208    for(i = 1; i < vps->getMaxLayers(); i++)
2209    {
2210      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
2211      {
2212#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2213        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
2214        if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
2215          READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
2216        }
2217#else
2218        READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
2219#endif
2220      }
2221    }
2222#endif
2223#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2224  }
2225#endif
2226#if VPS_VUI_WPP_NOT_IN_USE__FLAG
2227  READ_FLAG( uiCode, "wpp_not_in_use_flag" ); vps->setWppNotInUseFlag(uiCode == 1);
2228  if (!uiCode)
2229  {
2230    for(i = 0; i < vps->getMaxLayers(); i++)
2231    {
2232      READ_FLAG( uiCode, "wpp_in_use_flag[ i ]" ); vps->setWppInUseFlag(i, (uiCode == 1));
2233    }
2234  }
2235#endif
2236
2237#if O0109_O0199_FLAGS_TO_VUI
2238#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2239  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
2240#endif
2241#if HIGHER_LAYER_IRAP_SKIP_FLAG
2242  READ_FLAG(uiCode, "higher_layer_irap_skip_flag" ); vps->setHigherLayerIrapSkipFlag(uiCode == 1 ? true : false);
2243
2244  // When single_layer_for_non_irap_flag is equal to 0, higher_layer_irap_skip_flag shall be equal to 0
2245  if( !vps->getSingleLayerForNonIrapFlag() )
2246  {
2247    assert( !vps->getHigherLayerIrapSkipFlag() );
2248  }
2249#endif
2250#endif
2251#if P0312_VERT_PHASE_ADJ
2252  READ_FLAG( uiCode, "vps_vui_vert_phase_in_use_flag" ); vps->setVpsVuiVertPhaseInUseFlag(uiCode);
2253#endif
2254#if N0160_VUI_EXT_ILP_REF
2255  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vps->setIlpRestrictedRefLayersFlag( uiCode == 1 );
2256  if( vps->getIlpRestrictedRefLayersFlag())
2257  {
2258    for(i = 1; i < vps->getMaxLayers(); i++)
2259    {
2260      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
2261      {
2262        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
2263        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 )
2264        {
2265          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 );
2266          if(vps->getCtuBasedOffsetEnabledFlag(i,j))
2267          {
2268            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode );
2269          }
2270        }
2271      }
2272    }
2273  }
2274#endif
2275#if VPS_VUI_VIDEO_SIGNAL
2276#if VPS_VUI_VIDEO_SIGNAL_MOVE
2277#else
2278    READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
2279    if (vps->getVideoSigPresentVpsFlag())
2280    {
2281        READ_CODE(4, uiCode, "vps_num_video_signal_info_minus1" ); vps->setNumVideoSignalInfo(uiCode + 1);
2282    }
2283    else
2284    {
2285        vps->setNumVideoSignalInfo(vps->getMaxLayers());
2286    }
2287   
2288   
2289    for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
2290    {
2291        READ_CODE(3, uiCode, "video_vps_format" ); vps->setVideoVPSFormat(i,uiCode);
2292        READ_FLAG(uiCode, "video_full_range_vps_flag" ); vps->setVideoFullRangeVpsFlag(i,uiCode);
2293        READ_CODE(8, uiCode, "color_primaries_vps" ); vps->setColorPrimaries(i,uiCode);
2294        READ_CODE(8, uiCode, "transfer_characteristics_vps" ); vps->setTransCharacter(i,uiCode);
2295        READ_CODE(8, uiCode, "matrix_coeffs_vps" );vps->setMaxtrixCoeff(i,uiCode);
2296    }
2297    if(!vps->getVideoSigPresentVpsFlag())
2298    {
2299        for (i=0; i < vps->getMaxLayers(); i++)
2300        {
2301            vps->setVideoSignalInfoIdx(i,i);
2302        }
2303    }
2304    else {
2305        vps->setVideoSignalInfoIdx(0,0);
2306        if (vps->getNumVideoSignalInfo() > 1 )
2307        {
2308            for (i=1; i < vps->getMaxLayers(); i++)
2309                READ_CODE(4, uiCode, "vps_video_signal_info_idx" ); vps->setVideoSignalInfoIdx(i, uiCode);
2310        }
2311        else {
2312          for (i=1; i < vps->getMaxLayers(); i++)
2313          {
2314            vps->setVideoSignalInfoIdx(i,0);
2315          }
2316        }
2317    }
2318#endif
2319#endif
2320
2321#if O0164_MULTI_LAYER_HRD
2322    READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
2323    if (vps->getVpsVuiBspHrdPresentFlag())
2324    {
2325      READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
2326      vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
2327      for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
2328      {
2329        if( i > 0 )
2330        {
2331          READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
2332        }
2333        parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
2334      }
2335      for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
2336      {
2337        READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
2338        for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
2339        {
2340          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
2341          {
2342            if( vps->getLayerIdIncludedFlag(h, j) )
2343            {
2344              READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
2345            }
2346          }
2347        }
2348        if (vps->getNumBitstreamPartitions(h))
2349        {
2350#if Q0182_MULTI_LAYER_HRD_UPDATE
2351          READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
2352#else
2353          READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
2354#endif
2355          for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
2356          {
2357            for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
2358            {
2359              READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
2360              READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
2361            }
2362          }
2363        }
2364      }
2365    }
2366#endif
2367
2368#if P0182_VPS_VUI_PS_FLAG
2369    for(i = 1; i < vps->getMaxLayers(); i++)
2370    {
2371      if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
2372      {
2373        READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); 
2374        vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
2375      }
2376      else
2377      {
2378        vps->setBaseLayerPSCompatibilityFlag( i, 0 );
2379      }
2380    }
2381#endif
2382}
2383#endif
2384#endif //SVC_EXTENSION
2385
2386Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
2387{
2388  UInt  uiCode;
2389  Int   iCode;
2390
2391#if ENC_DEC_TRACE
2392  xTraceSliceHeader(rpcSlice);
2393#endif
2394  TComPPS* pps = NULL;
2395  TComSPS* sps = NULL;
2396
2397  UInt firstSliceSegmentInPic;
2398  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
2399  if( rpcSlice->getRapPicFlag())
2400  {
2401    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored -- updated already
2402#if SETTING_NO_OUT_PIC_PRIOR
2403    rpcSlice->setNoOutputPriorPicsFlag(uiCode ? true : false);
2404#else
2405    rpcSlice->setNoOutputPicPrior( false );
2406#endif
2407  }
2408  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
2409  pps = parameterSetManager->getPrefetchedPPS(uiCode);
2410  //!KS: need to add error handling code here, if PPS is not available
2411  assert(pps!=0);
2412  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
2413  //!KS: need to add error handling code here, if SPS is not available
2414  assert(sps!=0);
2415  rpcSlice->setSPS(sps);
2416  rpcSlice->setPPS(pps);
2417  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
2418  {
2419    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
2420  }
2421  else
2422  {
2423    rpcSlice->setDependentSliceSegmentFlag(false);
2424  }
2425#if REPN_FORMAT_IN_VPS
2426  Int numCTUs = ((rpcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((rpcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2427#else
2428  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
2429#endif
2430  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
2431  UInt sliceSegmentAddress = 0;
2432  Int bitsSliceSegmentAddress = 0;
2433  while(numCTUs>(1<<bitsSliceSegmentAddress))
2434  {
2435    bitsSliceSegmentAddress++;
2436  }
2437
2438  if(!firstSliceSegmentInPic)
2439  {
2440    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
2441  }
2442  //set uiCode to equal slice start address (or dependent slice start address)
2443  Int startCuAddress = maxParts*sliceSegmentAddress;
2444  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
2445  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
2446
2447  if (rpcSlice->getDependentSliceSegmentFlag())
2448  {
2449    rpcSlice->setNextSlice          ( false );
2450    rpcSlice->setNextSliceSegment ( true  );
2451  }
2452  else
2453  {
2454    rpcSlice->setNextSlice          ( true  );
2455    rpcSlice->setNextSliceSegment ( false );
2456
2457    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
2458    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
2459  }
2460
2461#if Q0142_POC_LSB_NOT_PRESENT
2462#if SHM_FIX7
2463    Int iPOClsb = 0;
2464#endif
2465#endif
2466
2467  if(!rpcSlice->getDependentSliceSegmentFlag())
2468  {
2469#if SVC_EXTENSION
2470#if POC_RESET_FLAG
2471    Int iBits = 0;
2472    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
2473    {
2474      READ_FLAG(uiCode, "poc_reset_flag");      rpcSlice->setPocResetFlag( uiCode ? true : false );
2475      iBits++;
2476    }
2477    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
2478    {
2479#if DISCARDABLE_PIC_RPS
2480      READ_FLAG(uiCode, "discardable_flag"); rpcSlice->setDiscardableFlag( uiCode ? true : false );
2481#else
2482      READ_FLAG(uiCode, "discardable_flag"); // ignored
2483#endif
2484      iBits++;
2485    }
2486#if O0149_CROSS_LAYER_BLA_FLAG
2487    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
2488    {
2489      READ_FLAG(uiCode, "cross_layer_bla_flag");  rpcSlice->setCrossLayerBLAFlag( uiCode ? true : false );
2490      iBits++;
2491    }
2492#endif
2493    for (; iBits < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
2494    {
2495      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2496    }
2497#else
2498    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
2499    {
2500      READ_FLAG(uiCode, "discardable_flag"); // ignored
2501    }
2502    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2503    {
2504      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2505    }
2506#endif
2507#else //SVC_EXTENSION
2508    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
2509    {
2510      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
2511    }
2512#endif //SVC_EXTENSION
2513
2514    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
2515    if( pps->getOutputFlagPresentFlag() )
2516    {
2517      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
2518    }
2519    else
2520    {
2521      rpcSlice->setPicOutputFlag( true );
2522    }
2523    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
2524    assert (sps->getChromaFormatIdc() == 1 );
2525    // if( separate_colour_plane_flag  ==  1 )
2526    //   colour_plane_id                                      u(2)
2527
2528    if( rpcSlice->getIdrPicFlag() )
2529    {
2530      rpcSlice->setPOC(0);
2531      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
2532      rps->setNumberOfNegativePictures(0);
2533      rps->setNumberOfPositivePictures(0);
2534      rps->setNumberOfLongtermPictures(0);
2535      rps->setNumberOfPictures(0);
2536      rpcSlice->setRPS(rps);
2537    }
2538#if N0065_LAYER_POC_ALIGNMENT
2539#if !Q0142_POC_LSB_NOT_PRESENT
2540#if SHM_FIX7
2541    Int iPOClsb = 0;
2542#endif
2543#endif
2544#if O0062_POC_LSB_NOT_PRESENT_FLAG
2545    if( ( rpcSlice->getLayerId() > 0 && !rpcSlice->getVPS()->getPocLsbNotPresentFlag( rpcSlice->getVPS()->getLayerIdInVps(rpcSlice->getLayerId())) ) || !rpcSlice->getIdrPicFlag())
2546#else
2547    if( rpcSlice->getLayerId() > 0 || !rpcSlice->getIdrPicFlag() )
2548#endif
2549#else
2550    else
2551#endif
2552    {
2553      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
2554#if SHM_FIX7
2555      iPOClsb = uiCode;
2556#else
2557      Int iPOClsb = uiCode;
2558#endif
2559      Int iPrevPOC = rpcSlice->getPrevTid0POC();
2560      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
2561      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
2562      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
2563      Int iPOCmsb;
2564      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
2565      {
2566        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
2567      }
2568      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
2569      {
2570        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
2571      }
2572      else
2573      {
2574        iPOCmsb = iPrevPOCmsb;
2575      }
2576      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2577        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2578        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2579      {
2580        // For BLA picture types, POCmsb is set to 0.
2581        iPOCmsb = 0;
2582      }
2583      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
2584
2585#if N0065_LAYER_POC_ALIGNMENT
2586#if SHM_FIX7
2587      }
2588#endif
2589      if( !rpcSlice->getIdrPicFlag() )
2590      {
2591#endif
2592      TComReferencePictureSet* rps;
2593      rps = rpcSlice->getLocalRPS();
2594      rpcSlice->setRPS(rps);
2595      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
2596      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
2597      {
2598        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
2599      }
2600      else // use reference to short-term reference picture set in PPS
2601      {
2602        Int numBits = 0;
2603        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
2604        {
2605          numBits++;
2606        }
2607        if (numBits > 0)
2608        {
2609          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
2610        }
2611        else
2612        {
2613          uiCode = 0;       
2614        }
2615        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
2616      }
2617      if(sps->getLongTermRefsPresent())
2618      {
2619        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
2620        UInt numOfLtrp = 0;
2621        UInt numLtrpInSPS = 0;
2622        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
2623        {
2624          READ_UVLC( uiCode, "num_long_term_sps");
2625          numLtrpInSPS = uiCode;
2626          numOfLtrp += numLtrpInSPS;
2627          rps->setNumberOfLongtermPictures(numOfLtrp);
2628        }
2629        Int bitsForLtrpInSPS = 0;
2630        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
2631        {
2632          bitsForLtrpInSPS++;
2633        }
2634        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
2635        numOfLtrp += uiCode;
2636        rps->setNumberOfLongtermPictures(numOfLtrp);
2637        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
2638        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
2639        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
2640        {
2641          Int pocLsbLt;
2642          if (k < numLtrpInSPS)
2643          {
2644            uiCode = 0;
2645            if (bitsForLtrpInSPS > 0)
2646            {
2647              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
2648            }
2649            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
2650
2651            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
2652            rps->setUsed(j,usedByCurrFromSPS);
2653          }
2654          else
2655          {
2656            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
2657            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2658          }
2659          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
2660          Bool mSBPresentFlag = uiCode ? true : false;
2661          if(mSBPresentFlag)
2662          {
2663            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
2664            Bool deltaFlag = false;
2665            //            First LTRP                               || First LTRP from SH
2666            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
2667            {
2668              deltaFlag = true;
2669            }
2670            if(deltaFlag)
2671            {
2672              deltaPocMSBCycleLT = uiCode;
2673            }
2674            else
2675            {
2676              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
2677            }
2678
2679            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
2680                                        - iPOClsb + pocLsbLt;
2681            rps->setPOC     (j, pocLTCurr);
2682            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
2683            rps->setCheckLTMSBPresent(j,true);
2684          }
2685          else
2686          {
2687            rps->setPOC     (j, pocLsbLt);
2688            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
2689            rps->setCheckLTMSBPresent(j,false);
2690
2691            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
2692            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
2693            {
2694              deltaPocMSBCycleLT = 0;
2695            }
2696          }
2697          prevDeltaMSB = deltaPocMSBCycleLT;
2698        }
2699        offset += rps->getNumberOfLongtermPictures();
2700        rps->setNumberOfPictures(offset);
2701      }
2702      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2703        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
2704        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
2705      {
2706        // In the case of BLA picture types, rps data is read from slice header but ignored
2707        rps = rpcSlice->getLocalRPS();
2708        rps->setNumberOfNegativePictures(0);
2709        rps->setNumberOfPositivePictures(0);
2710        rps->setNumberOfLongtermPictures(0);
2711        rps->setNumberOfPictures(0);
2712        rpcSlice->setRPS(rps);
2713      }
2714      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
2715      {
2716        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
2717        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
2718      }
2719      else
2720      {
2721        rpcSlice->setEnableTMVPFlag(false);
2722      }
2723#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
2724    }
2725#endif
2726    }
2727
2728#if SVC_EXTENSION
2729    rpcSlice->setActiveNumILRRefIdx(0);
2730#if ILP_SSH_SIG
2731#if ILP_SSH_SIG_FIX
2732    if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
2733#else
2734    if((rpcSlice->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
2735#endif
2736#else
2737    if((rpcSlice->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
2738#endif
2739    {
2740      READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
2741      rpcSlice->setInterLayerPredEnabledFlag(uiCode);
2742      if( rpcSlice->getInterLayerPredEnabledFlag())
2743      {
2744        if(rpcSlice->getNumILRRefIdx() > 1)
2745        {
2746          Int numBits = 1;
2747          while ((1 << numBits) < rpcSlice->getNumILRRefIdx())
2748          {
2749            numBits++;
2750          }
2751          if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
2752          {
2753            READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
2754            rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
2755          }
2756          else
2757          {
2758#if P0079_DERIVE_NUMACTIVE_REF_PICS
2759            for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ ) 
2760            {
2761#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
2762              if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
2763                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2764#else
2765              if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
2766                (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2767#endif
2768              {         
2769                rpcSlice->setActiveNumILRRefIdx(1);
2770                break;
2771              }
2772            }
2773#else
2774            rpcSlice->setActiveNumILRRefIdx(1);
2775#endif
2776          }
2777#if ILP_NUM_REF_CHK
2778          if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
2779          {
2780            for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2781            {
2782              rpcSlice->setInterLayerPredLayerIdc(i,i);
2783            }
2784          }
2785          else
2786          {
2787#endif
2788          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2789          {
2790            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
2791            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
2792          }
2793#if ILP_NUM_REF_CHK
2794          }
2795#endif
2796        }
2797        else
2798        {
2799#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
2800#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
2801          if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
2802            (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
2803#else
2804          if( (rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(0,rpcSlice->getLayerId()) >  rpcSlice->getTLayer()) &&
2805             (rpcSlice->getVPS()->getMaxTSLayersMinus1(0) >=  rpcSlice->getTLayer()) )
2806#endif
2807        {
2808#endif
2809          rpcSlice->setActiveNumILRRefIdx(1);
2810          rpcSlice->setInterLayerPredLayerIdc(0,0);
2811#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
2812        }
2813#endif
2814        }
2815      }
2816    }
2817#if ILP_SSH_SIG
2818#if ILP_SSH_SIG_FIX
2819    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
2820#else
2821    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
2822#endif
2823    {
2824      rpcSlice->setInterLayerPredEnabledFlag(true);
2825
2826#if O0225_TID_BASED_IL_RPS_DERIV && TSLAYERS_IL_RPS
2827      Int   numRefLayerPics = 0;
2828      Int   i = 0;
2829      Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
2830      for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ ) 
2831      {
2832#if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
2833        if((rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() || rpcSlice->getTLayer()==0) &&
2834          (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2835#else
2836        if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
2837           (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
2838#endif
2839        {         
2840          refLayerPicIdc[ numRefLayerPics++ ] = i;
2841        }
2842      }
2843      rpcSlice->setActiveNumILRRefIdx(numRefLayerPics);
2844      for( i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2845      {
2846        rpcSlice->setInterLayerPredLayerIdc(refLayerPicIdc[i],i);
2847      }     
2848#else
2849      rpcSlice->setActiveNumILRRefIdx(rpcSlice->getNumILRRefIdx());
2850      for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
2851      {
2852        rpcSlice->setInterLayerPredLayerIdc(i,i);
2853      }
2854#endif
2855    }
2856#endif
2857#endif
2858#if P0312_VERT_PHASE_ADJ
2859    for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
2860    {
2861      UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
2862      if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
2863      {
2864        READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
2865      }
2866    }
2867#endif
2868
2869    if(sps->getUseSAO())
2870    {
2871      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2872#if AUXILIARY_PICTURES
2873      ChromaFormat format;
2874#if REPN_FORMAT_IN_VPS
2875#if O0096_REP_FORMAT_INDEX
2876      if( sps->getLayerId() == 0 )
2877      {
2878        format = sps->getChromaFormatIdc();
2879      }
2880      else
2881      {
2882        format = rpcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
2883#if Q0195_REP_FORMAT_CLEANUP
2884         assert( (sps->getUpdateRepFormatFlag()==false && rpcSlice->getVPS()->getVpsNumRepFormats()==1) || rpcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
2885#endif
2886      }
2887#else
2888      if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
2889      {
2890        format = sps->getChromaFormatIdc();
2891      }
2892      else
2893      {
2894        format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
2895      }
2896#endif
2897#else
2898      format = sps->getChromaFormatIdc();
2899#endif
2900      if (format != CHROMA_400)
2901      {
2902#endif
2903      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
2904#if AUXILIARY_PICTURES
2905      }
2906      else
2907      {
2908        rpcSlice->setSaoEnabledFlagChroma(false);
2909      }
2910#endif
2911    }
2912
2913    if (rpcSlice->getIdrPicFlag())
2914    {
2915      rpcSlice->setEnableTMVPFlag(false);
2916    }
2917    if (!rpcSlice->isIntra())
2918    {
2919
2920      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2921      if (uiCode)
2922      {
2923        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2924        if (rpcSlice->isInterB())
2925        {
2926          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2927        }
2928        else
2929        {
2930          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2931        }
2932      }
2933      else
2934      {
2935        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
2936        if (rpcSlice->isInterB())
2937        {
2938          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
2939        }
2940        else
2941        {
2942          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
2943        }
2944      }
2945    }
2946    // }
2947    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2948    if(!rpcSlice->isIntra())
2949    {
2950      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2951      {
2952        refPicListModification->setRefPicListModificationFlagL0( 0 );
2953      }
2954      else
2955      {
2956        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2957      }
2958
2959      if(refPicListModification->getRefPicListModificationFlagL0())
2960      {
2961        uiCode = 0;
2962        Int i = 0;
2963        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
2964        if ( numRpsCurrTempList0 > 1 )
2965        {
2966          Int length = 1;
2967          numRpsCurrTempList0 --;
2968          while ( numRpsCurrTempList0 >>= 1)
2969          {
2970            length ++;
2971          }
2972          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2973          {
2974            READ_CODE( length, uiCode, "list_entry_l0" );
2975            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2976          }
2977        }
2978        else
2979        {
2980          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2981          {
2982            refPicListModification->setRefPicSetIdxL0(i, 0 );
2983          }
2984        }
2985      }
2986    }
2987    else
2988    {
2989      refPicListModification->setRefPicListModificationFlagL0(0);
2990    }
2991    if(rpcSlice->isInterB())
2992    {
2993      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
2994      {
2995        refPicListModification->setRefPicListModificationFlagL1( 0 );
2996      }
2997      else
2998      {
2999        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
3000      }
3001      if(refPicListModification->getRefPicListModificationFlagL1())
3002      {
3003        uiCode = 0;
3004        Int i = 0;
3005        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
3006        if ( numRpsCurrTempList1 > 1 )
3007        {
3008          Int length = 1;
3009          numRpsCurrTempList1 --;
3010          while ( numRpsCurrTempList1 >>= 1)
3011          {
3012            length ++;
3013          }
3014          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
3015          {
3016            READ_CODE( length, uiCode, "list_entry_l1" );
3017            refPicListModification->setRefPicSetIdxL1(i, uiCode );
3018          }
3019        }
3020        else
3021        {
3022          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
3023          {
3024            refPicListModification->setRefPicSetIdxL1(i, 0 );
3025          }
3026        }
3027      }
3028    }
3029    else
3030    {
3031      refPicListModification->setRefPicListModificationFlagL1(0);
3032    }
3033    if (rpcSlice->isInterB())
3034    {
3035      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
3036    }
3037
3038    rpcSlice->setCabacInitFlag( false ); // default
3039    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
3040    {
3041      READ_FLAG(uiCode, "cabac_init_flag");
3042      rpcSlice->setCabacInitFlag( uiCode ? true : false );
3043    }
3044
3045    if ( rpcSlice->getEnableTMVPFlag() )
3046    {
3047#if SVC_EXTENSION && REF_IDX_MFM
3048      // set motion mapping flag
3049      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
3050#endif
3051      if ( rpcSlice->getSliceType() == B_SLICE )
3052      {
3053        READ_FLAG( uiCode, "collocated_from_l0_flag" );
3054        rpcSlice->setColFromL0Flag(uiCode);
3055      }
3056      else
3057      {
3058        rpcSlice->setColFromL0Flag( 1 );
3059      }
3060
3061      if ( rpcSlice->getSliceType() != I_SLICE &&
3062          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
3063           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
3064      {
3065        READ_UVLC( uiCode, "collocated_ref_idx" );
3066        rpcSlice->setColRefIdx(uiCode);
3067      }
3068      else
3069      {
3070        rpcSlice->setColRefIdx(0);
3071      }
3072    }
3073    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
3074    {
3075      xParsePredWeightTable(rpcSlice);
3076      rpcSlice->initWpScaling();
3077    }
3078    if (!rpcSlice->isIntra())
3079    {
3080      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
3081      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
3082    }
3083
3084    READ_SVLC( iCode, "slice_qp_delta" );
3085    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
3086
3087#if REPN_FORMAT_IN_VPS
3088#if O0194_DIFFERENT_BITDEPTH_EL_BL
3089    g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
3090    g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
3091#endif
3092    assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
3093#else
3094    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
3095#endif
3096    assert( rpcSlice->getSliceQp() <=  51 );
3097
3098    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
3099    {
3100      READ_SVLC( iCode, "slice_qp_delta_cb" );
3101      rpcSlice->setSliceQpDeltaCb( iCode );
3102      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
3103      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
3104      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
3105      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
3106
3107      READ_SVLC( iCode, "slice_qp_delta_cr" );
3108      rpcSlice->setSliceQpDeltaCr( iCode );
3109      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
3110      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
3111      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
3112      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
3113    }
3114
3115    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
3116    {
3117      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
3118      {
3119        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
3120      }
3121      else
3122      {
3123        rpcSlice->setDeblockingFilterOverrideFlag(0);
3124      }
3125      if(rpcSlice->getDeblockingFilterOverrideFlag())
3126      {
3127        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
3128        if(!rpcSlice->getDeblockingFilterDisable())
3129        {
3130          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
3131          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
3132                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
3133          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
3134          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
3135                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
3136        }
3137      }
3138      else
3139      {
3140        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
3141        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
3142        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
3143      }
3144    }
3145    else
3146    {
3147      rpcSlice->setDeblockingFilterDisable       ( false );
3148      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
3149      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
3150    }
3151
3152    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
3153    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
3154
3155    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
3156    {
3157      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
3158    }
3159    else
3160    {
3161      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
3162    }
3163    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
3164
3165  }
3166
3167    UInt *entryPointOffset          = NULL;
3168    UInt numEntryPointOffsets, offsetLenMinus1;
3169  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
3170  {
3171    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
3172    if (numEntryPointOffsets>0)
3173    {
3174      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
3175    }
3176    entryPointOffset = new UInt[numEntryPointOffsets];
3177    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
3178    {
3179      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
3180      entryPointOffset[ idx ] = uiCode + 1;
3181    }
3182  }
3183  else
3184  {
3185    rpcSlice->setNumEntryPointOffsets ( 0 );
3186  }
3187
3188#if POC_RESET_IDC_SIGNALLING
3189  Int sliceHeaderExtensionLength = 0;
3190  if(pps->getSliceHeaderExtensionPresentFlag())
3191  {
3192    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
3193  }
3194  else
3195  {
3196    sliceHeaderExtensionLength = 0;
3197  }
3198  UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
3199  if( sliceHeaderExtensionLength > 0 )
3200  {
3201    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
3202    {
3203      READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
3204    }
3205    else
3206    {
3207      rpcSlice->setPocResetIdc( 0 );
3208    }
3209#if Q0142_POC_LSB_NOT_PRESENT
3210    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
3211    {
3212      assert( rpcSlice->getPocResetIdc() != 2 );
3213    }
3214#endif
3215    if( rpcSlice->getPocResetIdc() > 0 )
3216    {
3217      READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
3218    }
3219    else
3220    {
3221     
3222      rpcSlice->setPocResetPeriodId( 0 );
3223    }
3224
3225    if (rpcSlice->getPocResetIdc() == 3)
3226    {
3227      READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
3228      READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
3229#if Q0142_POC_LSB_NOT_PRESENT
3230      if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
3231      {
3232        assert( rpcSlice->getPocLsbVal() == 0 );
3233      }
3234#endif
3235    }
3236
3237    // Derive the value of PocMsbValRequiredFlag
3238    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
3239                                          /* || related to vps_poc_lsb_aligned_flag */
3240                                          );
3241
3242    if( !rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */ )
3243    {
3244      READ_FLAG( uiCode,    "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag( uiCode ? true : false );
3245    }
3246    else
3247    {
3248#if POC_MSB_VAL_PRESENT_FLAG_SEM
3249      if( sliceHeaderExtensionLength == 0 )
3250      {
3251        rpcSlice->setPocMsbValPresentFlag( false );
3252      }
3253      else if( rpcSlice->getPocMsbValRequiredFlag() )
3254#else
3255      if( rpcSlice->getPocMsbValRequiredFlag() )
3256#endif
3257      {
3258        rpcSlice->setPocMsbValPresentFlag( true );
3259      }
3260      else
3261      {
3262        rpcSlice->setPocMsbValPresentFlag( false );
3263      }
3264    }
3265
3266    Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
3267    if( rpcSlice->getPocMsbValPresentFlag() )
3268    {
3269      READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
3270      // Update POC of the slice based on this MSB val
3271      Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
3272      rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
3273    }
3274    else
3275    {
3276      rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
3277    }
3278
3279    // Read remaining bits in the slice header extension.
3280    UInt endBits = m_pcBitstream->getNumBitsRead();
3281    Int counter = (endBits - startBits) % 8;
3282    if( counter )
3283    {
3284      counter = 8 - counter;
3285    }
3286
3287    while( counter )
3288    {
3289#if Q0146_SSH_EXT_DATA_BIT
3290      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
3291#else
3292      READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
3293#endif
3294      counter--;
3295    }
3296  }
3297#else
3298  if(pps->getSliceHeaderExtensionPresentFlag())
3299  {
3300    READ_UVLC(uiCode,"slice_header_extension_length");
3301    for(Int i=0; i<uiCode; i++)
3302    {
3303      UInt ignore;
3304      READ_CODE(8,ignore,"slice_header_extension_data_byte");
3305    }
3306  }
3307#endif
3308  m_pcBitstream->readByteAlignment();
3309
3310  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
3311  {
3312    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
3313
3314    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
3315    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
3316    {
3317      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
3318      {
3319        endOfSliceHeaderLocation++;
3320      }
3321    }
3322
3323    Int  curEntryPointOffset     = 0;
3324    Int  prevEntryPointOffset    = 0;
3325    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
3326    {
3327      curEntryPointOffset += entryPointOffset[ idx ];
3328
3329      Int emulationPreventionByteCount = 0;
3330      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
3331      {
3332        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
3333             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
3334        {
3335          emulationPreventionByteCount++;
3336        }
3337      }
3338
3339      entryPointOffset[ idx ] -= emulationPreventionByteCount;
3340      prevEntryPointOffset = curEntryPointOffset;
3341    }
3342
3343    if ( pps->getTilesEnabledFlag() )
3344    {
3345      rpcSlice->setTileLocationCount( numEntryPointOffsets );
3346
3347      UInt prevPos = 0;
3348      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
3349      {
3350        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
3351        prevPos += entryPointOffset[ idx ];
3352      }
3353    }
3354    else if ( pps->getEntropyCodingSyncEnabledFlag() )
3355    {
3356    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
3357      rpcSlice->allocSubstreamSizes(numSubstreams);
3358      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
3359      for (Int idx=0; idx<numSubstreams-1; idx++)
3360      {
3361        if ( idx < numEntryPointOffsets )
3362        {
3363          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
3364        }
3365        else
3366        {
3367          pSubstreamSizes[ idx ] = 0;
3368        }
3369      }
3370    }
3371
3372    if (entryPointOffset)
3373    {
3374      delete [] entryPointOffset;
3375    }
3376  }
3377
3378  return;
3379}
3380
3381Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
3382{
3383  UInt uiCode;
3384  if(profilePresentFlag)
3385  {
3386    parseProfileTier(rpcPTL->getGeneralPTL());
3387  }
3388  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
3389
3390  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
3391  {
3392    if(profilePresentFlag)
3393    {
3394      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
3395    }
3396    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
3397  }
3398
3399  if (maxNumSubLayersMinus1 > 0)
3400  {
3401    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
3402    {
3403      READ_CODE(2, uiCode, "reserved_zero_2bits");
3404      assert(uiCode == 0);
3405    }
3406  }
3407
3408  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
3409  {
3410    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
3411    {
3412      parseProfileTier(rpcPTL->getSubLayerPTL(i));
3413    }
3414    if(rpcPTL->getSubLayerLevelPresentFlag(i))
3415    {
3416      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
3417    }
3418  }
3419}
3420
3421Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
3422{
3423  UInt uiCode;
3424  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
3425  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
3426  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
3427  for(Int j = 0; j < 32; j++)
3428  {
3429    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
3430  }
3431  READ_FLAG(uiCode, "general_progressive_source_flag");
3432  ptl->setProgressiveSourceFlag(uiCode ? true : false);
3433
3434  READ_FLAG(uiCode, "general_interlaced_source_flag");
3435  ptl->setInterlacedSourceFlag(uiCode ? true : false);
3436
3437  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
3438  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
3439
3440  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
3441  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
3442
3443  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
3444  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
3445  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
3446}
3447
3448Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
3449{
3450  ruiBit = false;
3451  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
3452  if(iBitsLeft <= 8)
3453  {
3454    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
3455    if (uiPeekValue == (1<<(iBitsLeft-1)))
3456    {
3457      ruiBit = true;
3458    }
3459  }
3460}
3461
3462Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3463{
3464  assert(0);
3465}
3466
3467Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3468{
3469  assert(0);
3470}
3471
3472Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
3473{
3474  assert(0);
3475}
3476
3477Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3478{
3479  assert(0);
3480}
3481
3482Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3483{
3484  assert(0);
3485}
3486
3487Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3488{
3489  assert(0);
3490}
3491
3492/** Parse I_PCM information.
3493* \param pcCU pointer to CU
3494* \param uiAbsPartIdx CU index
3495* \param uiDepth CU depth
3496* \returns Void
3497*
3498* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
3499*/
3500Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3501{
3502  assert(0);
3503}
3504
3505Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3506{
3507  assert(0);
3508}
3509
3510Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
3511{
3512  assert(0);
3513}
3514
3515Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
3516{
3517  assert(0);
3518}
3519
3520Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
3521{
3522  assert(0);
3523}
3524
3525Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
3526{
3527  assert(0);
3528}
3529
3530Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
3531{
3532  Int qp;
3533  Int  iDQp;
3534
3535  xReadSvlc( iDQp );
3536
3537#if REPN_FORMAT_IN_VPS
3538  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
3539#else
3540  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
3541#endif
3542  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
3543
3544  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
3545  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
3546
3547  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
3548}
3549
3550Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
3551{
3552  assert(0);
3553}
3554
3555Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
3556{
3557  assert(0);
3558}
3559
3560Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
3561{
3562  assert(0);
3563}
3564
3565Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
3566{
3567  assert(0);
3568}
3569
3570Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
3571{
3572  assert(0);
3573}
3574
3575Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
3576{
3577  assert(0);
3578}
3579
3580Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
3581{
3582  assert(0);
3583}
3584
3585// ====================================================================================================================
3586// Protected member functions
3587// ====================================================================================================================
3588
3589/** parse explicit wp tables
3590* \param TComSlice* pcSlice
3591* \returns Void
3592*/
3593Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
3594{
3595  wpScalingParam  *wp;
3596  Bool            bChroma     = true; // color always present in HEVC ?
3597  SliceType       eSliceType  = pcSlice->getSliceType();
3598  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
3599#if SVC_EXTENSION
3600  UInt            uiLog2WeightDenomLuma = 0, uiLog2WeightDenomChroma = 0;
3601#else
3602  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
3603#endif
3604  UInt            uiTotalSignalledWeightFlags = 0;
3605
3606  Int iDeltaDenom;
3607#if AUXILIARY_PICTURES
3608  if (pcSlice->getChromaFormatIdc() == CHROMA_400)
3609  {
3610    bChroma = false;
3611  }
3612#endif
3613  // decode delta_luma_log2_weight_denom :
3614  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3615  assert( uiLog2WeightDenomLuma <= 7 );
3616  if( bChroma )
3617  {
3618    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
3619    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3620    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
3621    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3622  }
3623
3624  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
3625  {
3626    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
3627    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
3628    {
3629      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3630
3631      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3632#if AUXILIARY_PICTURES
3633      if (!bChroma)
3634      {
3635        wp[1].uiLog2WeightDenom = 0;
3636        wp[2].uiLog2WeightDenom = 0;
3637      }
3638      else
3639      {
3640#endif
3641      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3642      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3643#if AUXILIARY_PICTURES
3644      }
3645#endif
3646
3647      UInt  uiCode;
3648      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
3649      wp[0].bPresentFlag = ( uiCode == 1 );
3650      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
3651    }
3652    if ( bChroma )
3653    {
3654      UInt  uiCode;
3655      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
3656      {
3657        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3658        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
3659        wp[1].bPresentFlag = ( uiCode == 1 );
3660        wp[2].bPresentFlag = ( uiCode == 1 );
3661        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
3662      }
3663    }
3664    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
3665    {
3666      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3667      if ( wp[0].bPresentFlag )
3668      {
3669        Int iDeltaWeight;
3670        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
3671        assert( iDeltaWeight >= -128 );
3672        assert( iDeltaWeight <=  127 );
3673        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3674        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
3675        assert( wp[0].iOffset >= -128 );
3676        assert( wp[0].iOffset <=  127 );
3677      }
3678      else
3679      {
3680        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3681        wp[0].iOffset = 0;
3682      }
3683      if ( bChroma )
3684      {
3685        if ( wp[1].bPresentFlag )
3686        {
3687          for ( Int j=1 ; j<3 ; j++ )
3688          {
3689            Int iDeltaWeight;
3690            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3691            assert( iDeltaWeight >= -128 );
3692            assert( iDeltaWeight <=  127 );
3693            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3694
3695            Int iDeltaChroma;
3696            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3697            assert( iDeltaChroma >= -512 );
3698            assert( iDeltaChroma <=  511 );
3699            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
3700            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
3701          }
3702        }
3703        else
3704        {
3705          for ( Int j=1 ; j<3 ; j++ )
3706          {
3707            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3708            wp[j].iOffset = 0;
3709          }
3710        }
3711      }
3712    }
3713
3714    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
3715    {
3716      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3717
3718      wp[0].bPresentFlag = false;
3719      wp[1].bPresentFlag = false;
3720      wp[2].bPresentFlag = false;
3721    }
3722  }
3723  assert(uiTotalSignalledWeightFlags<=24);
3724}
3725
3726/** decode quantization matrix
3727* \param scalingList quantization matrix information
3728*/
3729Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3730{
3731  UInt  code, sizeId, listId;
3732  Bool scalingListPredModeFlag;
3733  //for each size
3734  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3735  {
3736    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3737    {
3738      READ_FLAG( code, "scaling_list_pred_mode_flag");
3739      scalingListPredModeFlag = (code) ? true : false;
3740      if(!scalingListPredModeFlag) //Copy Mode
3741      {
3742        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3743        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
3744        if( sizeId > SCALING_LIST_8x8 )
3745        {
3746          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
3747        }
3748        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3749
3750      }
3751      else //DPCM Mode
3752      {
3753        xDecodeScalingList(scalingList, sizeId, listId);
3754      }
3755    }
3756  }
3757
3758  return;
3759}
3760/** decode DPCM
3761* \param scalingList  quantization matrix information
3762* \param sizeId size index
3763* \param listId list index
3764*/
3765Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3766{
3767  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3768  Int data;
3769  Int scalingListDcCoefMinus8 = 0;
3770  Int nextCoef = SCALING_LIST_START_VALUE;
3771  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
3772  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3773
3774  if( sizeId > SCALING_LIST_8x8 )
3775  {
3776    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3777    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3778    nextCoef = scalingList->getScalingListDC(sizeId,listId);
3779  }
3780
3781  for(i = 0; i < coefNum; i++)
3782  {
3783    READ_SVLC( data, "scaling_list_delta_coef");
3784    nextCoef = (nextCoef + data + 256 ) % 256;
3785    dst[scan[i]] = nextCoef;
3786  }
3787}
3788
3789Bool TDecCavlc::xMoreRbspData()
3790{
3791  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3792
3793  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3794  if (bitsLeft > 8)
3795  {
3796    return true;
3797  }
3798
3799  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3800  Int cnt = bitsLeft;
3801
3802  // remove trailing bits equal to zero
3803  while ((cnt>0) && ((lastByte & 1) == 0))
3804  {
3805    lastByte >>= 1;
3806    cnt--;
3807  }
3808  // remove bit equal to one
3809  cnt--;
3810
3811  // we should not have a negative number of bits
3812  assert (cnt>=0);
3813
3814  // we have more data, if cnt is not zero
3815  return (cnt>0);
3816}
3817
3818#if Q0048_CGS_3D_ASYMLUT
3819Void TDecCavlc::xParse3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
3820{
3821  UInt uiCurOctantDepth , uiCurPartNumLog2 , uiInputBitDepthM8 , uiOutputBitDepthM8 , uiResQaunBit;
3822  READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" ); 
3823  READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
3824  READ_CODE( 3 , uiInputBitDepthM8 , "cm_input_bit_depth_minus8" );
3825  Int iInputBitDepthCDelta;
3826  READ_SVLC(iInputBitDepthCDelta, "cm_input_bit_depth_chroma delta");
3827  READ_CODE( 3 , uiOutputBitDepthM8 , "cm_output_bit_depth_minus8" ); 
3828  Int iOutputBitDepthCDelta;
3829  READ_SVLC(iOutputBitDepthCDelta, "cm_output_bit_depth_chroma_delta");
3830  READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
3831  pc3DAsymLUT->destroy();
3832  pc3DAsymLUT->create( uiCurOctantDepth , uiInputBitDepthM8 + 8 ,  uiInputBitDepthM8 + 8 + iInputBitDepthCDelta, uiOutputBitDepthM8 + 8 , uiOutputBitDepthM8 + 8 + iOutputBitDepthCDelta ,uiCurPartNumLog2 );
3833  pc3DAsymLUT->setResQuantBit( uiResQaunBit );
3834
3835  xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
3836}
3837
3838Void TDecCavlc::xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength )
3839{
3840  UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
3841  if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
3842    READ_FLAG( uiOctantSplit , "split_octant_flag" );
3843  Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
3844  if( uiOctantSplit )
3845  {
3846    Int nHalfLength = nLength >> 1;
3847    for( Int l = 0 ; l < 2 ; l++ )
3848    {
3849      for( Int m = 0 ; m < 2 ; m++ )
3850      {
3851        for( Int n = 0 ; n < 2 ; n++ )
3852        {
3853          xParse3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength );
3854        }
3855      }
3856    }
3857  }
3858  else
3859  {
3860    for( Int l = 0 ; l < nYPartNum ; l++ )
3861    {
3862      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
3863      {
3864        UInt uiCodeVertex = 0;
3865        Int deltaY = 0 , deltaU = 0 , deltaV = 0;
3866        READ_FLAG( uiCodeVertex , "coded_vertex_flag" );
3867        if( uiCodeVertex )
3868        {
3869          READ_SVLC( deltaY , "resY" );
3870          READ_SVLC( deltaU , "resU" );
3871          READ_SVLC( deltaV , "resV" );
3872        }
3873        pc3DAsymLUT->setCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
3874      }
3875    }
3876  }
3877}
3878#endif
3879//! \}
3880
Note: See TracBrowser for help on using the repository browser.