source: 3DVCSoftware/branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 367

Last change on this file since 367 was 367, checked in by tech, 12 years ago

Further minor cleanups.

  • Property svn:eol-style set to native
File size: 69.6 KB
Line 
1/* The copyright in this software is being made available under the BSD
2* License, included below. This software may be subject to other third party
3* and contributor rights, including patent rights, and no such rights are
4* granted under this license. 
5*
6* Copyright (c) 2010-2013, 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
42//! \ingroup TLibDecoder
43//! \{
44
45#if ENC_DEC_TRACE
46
47Void  xTraceSPSHeader (TComSPS *pSPS)
48{
49  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
50}
51
52Void  xTracePPSHeader (TComPPS *pPPS)
53{
54  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
55}
56
57Void  xTraceSliceHeader (TComSlice *pSlice)
58{
59  fprintf( g_hTrace, "=========== Slice ===========\n");
60}
61
62#endif
63
64// ====================================================================================================================
65// Constructor / destructor / create / destroy
66// ====================================================================================================================
67
68TDecCavlc::TDecCavlc()
69{
70}
71
72TDecCavlc::~TDecCavlc()
73{
74
75}
76
77// ====================================================================================================================
78// Public member functions
79// ====================================================================================================================
80
81void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
82{
83  UInt code;
84  UInt interRPSPred;
85  if (idx > 0)
86  {
87    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
88  }
89  else
90  {
91    interRPSPred = false;
92    rps->setInterRPSPrediction(false);
93  }
94
95  if (interRPSPred) 
96  {
97    UInt bit;
98    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
99    {
100      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
101    }
102    else
103    {
104      code = 0;
105    }
106    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
107    Int rIdx =  idx - 1 - code;
108    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
109    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
110    Int k = 0, k0 = 0, k1 = 0;
111    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
112    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
113    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
114    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
115    {
116      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
117      Int refIdc = bit;
118      if (refIdc == 0) 
119      {
120        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
121        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
122      }
123      if (refIdc == 1 || refIdc == 2)
124      {
125        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
126        rps->setDeltaPOC(k, deltaPOC);
127        rps->setUsed(k, (refIdc == 1));
128
129        if (deltaPOC < 0)
130        {
131          k0++;
132        }
133        else 
134        {
135          k1++;
136        }
137        k++;
138      } 
139      rps->setRefIdc(j,refIdc); 
140    }
141    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
142    rps->setNumberOfPictures(k);
143    rps->setNumberOfNegativePictures(k0);
144    rps->setNumberOfPositivePictures(k1);
145    rps->sortDeltaPOC();
146  }
147  else
148  {
149    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
150    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
151    Int prev = 0;
152    Int poc;
153    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
154    {
155      READ_UVLC(code, "delta_poc_s0_minus1");
156      poc = prev-code-1;
157      prev = poc;
158      rps->setDeltaPOC(j,poc);
159      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
160    }
161    prev = 0;
162    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
163    {
164      READ_UVLC(code, "delta_poc_s1_minus1");
165      poc = prev+code+1;
166      prev = poc;
167      rps->setDeltaPOC(j,poc);
168      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
169    }
170    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
171  }
172#if PRINT_RPS_INFO
173  rps->printDeltaPOC();
174#endif
175}
176
177Void TDecCavlc::parsePPS(TComPPS* pcPPS)
178{
179#if ENC_DEC_TRACE 
180  xTracePPSHeader (pcPPS);
181#endif
182  UInt  uiCode;
183
184  Int   iCode;
185
186  READ_UVLC( uiCode, "pps_pic_parameter_set_id");                     pcPPS->setPPSId (uiCode);
187  READ_UVLC( uiCode, "pps_seq_parameter_set_id");                     pcPPS->setSPSId (uiCode);
188  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
189#if L0255_MOVE_PPS_FLAGS
190  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
191
192  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
193#endif
194  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
195
196  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
197
198#if L0323_LIMIT_DEFAULT_LIST_SIZE
199  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
200  assert(uiCode <= 14);
201  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
202 
203  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
204  assert(uiCode <= 14);
205  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
206#else
207  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");       pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
208  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");       pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
209#endif
210 
211  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
212  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
213  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
214  pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
215
216  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
217  if( pcPPS->getUseDQP() )
218  {
219    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
220    pcPPS->setMaxCuDQPDepth( uiCode );
221  }
222  else
223  {
224    pcPPS->setMaxCuDQPDepth( 0 );
225  }
226  READ_SVLC( iCode, "pps_cb_qp_offset");
227  pcPPS->setChromaCbQpOffset(iCode);
228  assert( pcPPS->getChromaCbQpOffset() >= -12 );
229  assert( pcPPS->getChromaCbQpOffset() <=  12 );
230
231  READ_SVLC( iCode, "pps_cr_qp_offset");
232  pcPPS->setChromaCrQpOffset(iCode);
233  assert( pcPPS->getChromaCrQpOffset() >= -12 );
234  assert( pcPPS->getChromaCrQpOffset() <=  12 );
235
236  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
237  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
238
239  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
240  pcPPS->setUseWP( uiCode==1 );
241  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
242  pcPPS->setWPBiPred( uiCode==1 );
243
244#if !L0255_MOVE_PPS_FLAGS
245  READ_FLAG( uiCode, "output_flag_present_flag" );
246  pcPPS->setOutputFlagPresentFlag( uiCode==1 );
247#endif
248  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
249  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
250  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
251  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
252 
253  if( pcPPS->getTilesEnabledFlag() )
254  {
255    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode ); 
256    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode ); 
257    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
258
259    if( !pcPPS->getUniformSpacingFlag())
260    {
261      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
262      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
263      { 
264        READ_UVLC( uiCode, "column_width_minus1" ); 
265        columnWidth[i] = uiCode+1;
266      }
267      pcPPS->setColumnWidth(columnWidth);
268      free(columnWidth);
269
270      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
271      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
272      {
273        READ_UVLC( uiCode, "row_height_minus1" );
274        rowHeight[i] = uiCode + 1;
275      }
276      pcPPS->setRowHeight(rowHeight);
277      free(rowHeight); 
278    }
279
280    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
281    {
282      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
283    }
284  }
285  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
286  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
287  if(pcPPS->getDeblockingFilterControlPresentFlag())
288  {
289    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
290    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
291    if(!pcPPS->getPicDisableDeblockingFilterFlag())
292    {
293      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
294      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
295    }
296  }
297  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
298  if(pcPPS->getScalingListPresentFlag ())
299  {
300    parseScalingList( pcPPS->getScalingList() );
301  }
302
303  READ_FLAG( uiCode, "lists_modification_present_flag");
304  pcPPS->setListsModificationPresentFlag(uiCode);
305
306  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
307  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
308
309#if !L0255_MOVE_PPS_FLAGS
310  READ_CODE(3, uiCode, "num_extra_slice_header_bits");
311  pcPPS->setNumExtraSliceHeaderBits(uiCode);
312#endif
313  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
314  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
315
316  READ_FLAG( uiCode, "pps_extension_flag");
317  if (uiCode)
318  {
319    while ( xMoreRbspData() )
320    {
321      READ_FLAG( uiCode, "pps_extension_data_flag");
322    }
323  }
324}
325
326Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
327{
328#if ENC_DEC_TRACE
329  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
330#endif
331  UInt  uiCode;
332
333  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
334  if (pcVUI->getAspectRatioInfoPresentFlag())
335  {
336    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
337    if (pcVUI->getAspectRatioIdc() == 255)
338    {
339      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
340      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
341    }
342  }
343
344  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
345  if (pcVUI->getOverscanInfoPresentFlag())
346  {
347    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
348  }
349
350  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
351  if (pcVUI->getVideoSignalTypePresentFlag())
352  {
353    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
354    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
355    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
356    if (pcVUI->getColourDescriptionPresentFlag())
357    {
358      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
359      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
360      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
361    }
362  }
363
364  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
365  if (pcVUI->getChromaLocInfoPresentFlag())
366  {
367    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
368    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
369  }
370
371  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
372
373  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
374
375  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
376
377  READ_FLAG(     uiCode, "default_display_window_flag");
378  if (uiCode != 0)
379  {
380    Window &defDisp = pcVUI->getDefaultDisplayWindow();
381    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
382    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
383    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
384    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
385  }
386#if L0043_TIMING_INFO
387  TimingInfo *timingInfo = pcVUI->getTimingInfo();
388  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
389  if(timingInfo->getTimingInfoPresentFlag())
390  {
391    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
392    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
393    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
394    if(timingInfo->getPocProportionalToTimingFlag())
395    {
396      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
397    }
398#endif 
399  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
400  if( pcVUI->getHrdParametersPresentFlag() )
401  {
402    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
403  }
404#if L0043_TIMING_INFO
405  }
406#endif
407#if !L0043_TIMING_INFO
408  READ_FLAG( uiCode, "poc_proportional_to_timing_flag" ); pcVUI->setPocProportionalToTimingFlag(uiCode ? true : false);
409  if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() )
410  {
411    READ_UVLC( uiCode, "num_ticks_poc_diff_one_minus1" ); pcVUI->setNumTicksPocDiffOneMinus1(uiCode);
412  }
413#endif
414  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
415  if (pcVUI->getBitstreamRestrictionFlag())
416  {
417    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
418    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
419    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
420#if L0043_MSS_IDC
421    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
422    assert(uiCode < 4096);
423#else
424    READ_CODE( 8, uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
425#endif
426    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
427    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
428    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
429    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
430  }
431}
432
433Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
434{
435  UInt  uiCode;
436  if( commonInfPresentFlag )
437  {
438#if !L0043_TIMING_INFO
439    READ_FLAG( uiCode, "timing_info_present_flag" );                  hrd->setTimingInfoPresentFlag( uiCode == 1 ? true : false );
440    if( hrd->getTimingInfoPresentFlag() )
441    {
442      READ_CODE( 32, uiCode, "num_units_in_tick" );                   hrd->setNumUnitsInTick( uiCode );
443      READ_CODE( 32, uiCode, "time_scale" );                          hrd->setTimeScale( uiCode );
444    }
445#endif
446    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
447    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
448    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
449    {
450      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
451      if( hrd->getSubPicCpbParamsPresentFlag() )
452      {
453        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
454        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
455        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
456#if L0044_DU_DPB_OUTPUT_DELAY_HRD
457        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
458#endif
459      }
460      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
461      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
462      if( hrd->getSubPicCpbParamsPresentFlag() )
463      {
464        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
465      }
466      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
467      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
468      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
469    }
470  }
471  Int i, j, nalOrVcl;
472  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
473  {
474    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
475    if( !hrd->getFixedPicRateFlag( i ) )
476    {
477      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
478    }
479    else
480    {
481      hrd->setFixedPicRateWithinCvsFlag( i, true );
482    }
483#if L0372
484    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
485    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
486#endif
487    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
488    {
489      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
490    }
491#if L0372
492    else
493    {     
494      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
495    }
496    if (!hrd->getLowDelayHrdFlag( i ))
497    {
498      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
499    }
500#else
501    READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
502    READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
503#endif
504    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
505    {
506      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
507          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
508      {
509        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
510        {
511          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
512          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
513          if( hrd->getSubPicCpbParamsPresentFlag() )
514          {
515#if L0363_DU_BIT_RATE
516            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
517#endif
518            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
519          }
520          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
521        }
522      }
523    }
524  }
525}
526
527Void TDecCavlc::parseSPS(TComSPS* pcSPS)
528{
529#if ENC_DEC_TRACE 
530  xTraceSPSHeader (pcSPS);
531#endif
532
533  UInt  uiCode;
534  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
535  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
536  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
537  if ( pcSPS->getMaxTLayers() == 1 )
538  {
539    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
540    assert( uiCode == 1 );
541  }
542 
543  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
544  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
545  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
546  // 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
547  assert (uiCode == 1);
548  if( uiCode == 3 )
549  {
550    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
551  }
552
553  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
554  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
555  READ_FLAG(     uiCode, "conformance_window_flag");
556  if (uiCode != 0)
557  {
558    Window &conf = pcSPS->getConformanceWindow();
559    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
560    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
561    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
562    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
563  }
564
565  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
566  pcSPS->setBitDepthY( uiCode + 8 );
567  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
568
569  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
570  pcSPS->setBitDepthC( uiCode + 8 );
571  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
572
573  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
574
575  UInt subLayerOrderingInfoPresentFlag;
576  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
577  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
578  {
579#if L0323_DPB
580    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
581    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
582#else
583    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering");
584    pcSPS->setMaxDecPicBuffering( uiCode, i);
585#endif
586    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
587    pcSPS->setNumReorderPics(uiCode, i);
588    READ_UVLC ( uiCode, "sps_max_latency_increase");
589    pcSPS->setMaxLatencyIncrease( uiCode, i );
590
591    if (!subLayerOrderingInfoPresentFlag)
592    {
593      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
594      {
595        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
596        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
597        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
598      }
599      break;
600    }
601  }
602
603  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
604  Int log2MinCUSize = uiCode + 3;
605  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
606  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
607  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
608  Int maxCUDepthDelta = uiCode;
609  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
610  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
611  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
612
613  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
614  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
615
616  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
617  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
618
619  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
620  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
621
622  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
623  if(pcSPS->getScalingListFlag())
624  {
625    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
626    if(pcSPS->getScalingListPresentFlag ())
627    {
628      parseScalingList( pcSPS->getScalingList() );
629    }
630  }
631  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
632  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
633
634  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
635  if( pcSPS->getUsePCM() )
636  {
637    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
638    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
639    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
640    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
641    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
642  }
643
644  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
645  pcSPS->createRPSList(uiCode);
646
647  TComRPSList* rpsList = pcSPS->getRPSList();
648  TComReferencePictureSet* rps;
649
650  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
651  {
652    rps = rpsList->getReferencePictureSet(i);
653    parseShortTermRefPicSet(pcSPS,rps,i);
654  }
655  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
656  if (pcSPS->getLongTermRefsPresent()) 
657  {
658    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
659    pcSPS->setNumLongTermRefPicSPS(uiCode);
660    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
661    {
662      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
663      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
664      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
665      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
666    }
667  }
668  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
669
670  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
671
672  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
673
674  if (pcSPS->getVuiParametersPresentFlag())
675  {
676    parseVUI(pcSPS->getVuiParameters(), pcSPS);
677  }
678
679  READ_FLAG( uiCode, "sps_extension_flag");
680  if (uiCode)
681  {
682    while ( xMoreRbspData() )
683    {
684      READ_FLAG( uiCode, "sps_extension_data_flag");
685    }
686  }
687}
688
689Void TDecCavlc::parseVPS(TComVPS* pcVPS)
690{
691  UInt  uiCode;
692 
693  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
694  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
695  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
696  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
697  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
698  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
699  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
700  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
701#if SIGNAL_BITRATE_PICRATE_IN_VPS
702  parseBitratePicRateInfo( pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1);
703#endif
704  UInt subLayerOrderingInfoPresentFlag;
705  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
706  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
707  {
708#if L0323_DPB
709    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
710#else
711    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
712#endif
713    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
714    READ_UVLC( uiCode,  "vps_max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
715
716    if (!subLayerOrderingInfoPresentFlag)
717    {
718      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
719      {
720        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
721        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
722        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
723      }
724      break;
725    }
726  }
727
728  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
729  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
730  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
731  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
732  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
733  {
734    // Operation point set
735    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
736    {
737      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
738    }
739  }
740#if L0043_TIMING_INFO
741  TimingInfo *timingInfo = pcVPS->getTimingInfo();
742  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
743  if(timingInfo->getTimingInfoPresentFlag())
744  {
745    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
746    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
747    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
748    if(timingInfo->getPocProportionalToTimingFlag())
749    {
750      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
751    }
752#endif
753    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
754
755    if( pcVPS->getNumHrdParameters() > 0 )
756    {
757      pcVPS->createHrdParamBuffer();
758    }
759    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
760    {
761      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
762      if( i > 0 )
763      {
764        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
765      }
766      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
767    }
768#if L0043_TIMING_INFO
769  }
770#endif
771  READ_FLAG( uiCode,  "vps_extension_flag" );
772  if (uiCode)
773  {
774    while ( xMoreRbspData() )
775    {
776      READ_FLAG( uiCode, "vps_extension_data_flag");
777    }
778  }
779 
780  return;
781}
782
783Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
784{
785  UInt  uiCode;
786  Int   iCode;
787
788#if ENC_DEC_TRACE
789  xTraceSliceHeader(rpcSlice);
790#endif
791  TComPPS* pps = NULL;
792  TComSPS* sps = NULL;
793
794  UInt firstSliceSegmentInPic;
795  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
796  if( rpcSlice->getRapPicFlag())
797  { 
798    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
799  }
800  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
801  pps = parameterSetManager->getPrefetchedPPS(uiCode);
802  //!KS: need to add error handling code here, if PPS is not available
803  assert(pps!=0);
804  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
805  //!KS: need to add error handling code here, if SPS is not available
806  assert(sps!=0);
807  rpcSlice->setSPS(sps);
808  rpcSlice->setPPS(pps);
809  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
810  {
811    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
812  }
813  else
814  {
815    rpcSlice->setDependentSliceSegmentFlag(false);
816  }
817  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
818  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
819  UInt sliceSegmentAddress = 0;
820  Int bitsSliceSegmentAddress = 0;
821  while(numCTUs>(1<<bitsSliceSegmentAddress))
822  {
823    bitsSliceSegmentAddress++;
824  }
825
826  if(!firstSliceSegmentInPic)
827  {
828    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
829  }
830  //set uiCode to equal slice start address (or dependent slice start address)
831  Int startCuAddress = maxParts*sliceSegmentAddress;
832  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
833  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
834
835  if (rpcSlice->getDependentSliceSegmentFlag())
836  {
837    rpcSlice->setNextSlice          ( false );
838    rpcSlice->setNextSliceSegment ( true  );
839  }
840  else
841  {
842    rpcSlice->setNextSlice          ( true  );
843    rpcSlice->setNextSliceSegment ( false );
844
845    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
846    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
847  }
848 
849  if(!rpcSlice->getDependentSliceSegmentFlag())
850  {
851    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
852    {
853      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
854    }
855
856    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
857    if( pps->getOutputFlagPresentFlag() )
858    {
859      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
860    }
861    else
862    {
863      rpcSlice->setPicOutputFlag( true );
864    }
865    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
866    assert (sps->getChromaFormatIdc() == 1 );
867    // if( separate_colour_plane_flag  ==  1 )
868    //   colour_plane_id                                      u(2)
869
870    if( rpcSlice->getIdrPicFlag() )
871    {
872      rpcSlice->setPOC(0);
873      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
874      rps->setNumberOfNegativePictures(0);
875      rps->setNumberOfPositivePictures(0);
876      rps->setNumberOfLongtermPictures(0);
877      rps->setNumberOfPictures(0);
878      rpcSlice->setRPS(rps);
879    }
880    else
881    {
882      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
883      Int iPOClsb = uiCode;
884      Int iPrevPOC = rpcSlice->getPrevPOC();
885      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
886      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
887      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
888      Int iPOCmsb;
889      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
890      {
891        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
892      }
893      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
894      {
895        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
896      }
897      else
898      {
899        iPOCmsb = iPrevPOCmsb;
900      }
901      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
902        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
903        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
904      {
905        // For BLA picture types, POCmsb is set to 0.
906        iPOCmsb = 0;
907      }
908      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
909
910      TComReferencePictureSet* rps;
911      rps = rpcSlice->getLocalRPS();
912      rpcSlice->setRPS(rps);
913      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
914      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
915      {
916        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
917      }
918      else // use reference to short-term reference picture set in PPS
919      {
920        Int numBits = 0;
921        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
922        {
923          numBits++;
924        }
925        if (numBits > 0)
926        {
927          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
928        }
929        else
930        {
931          uiCode = 0;
932        }
933        memcpy(rps,sps->getRPSList()->getReferencePictureSet(uiCode),sizeof(TComReferencePictureSet));
934      }
935      if(sps->getLongTermRefsPresent())
936      {
937        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
938        UInt numOfLtrp = 0;
939        UInt numLtrpInSPS = 0;
940        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
941        {
942          READ_UVLC( uiCode, "num_long_term_sps");
943          numLtrpInSPS = uiCode;
944          numOfLtrp += numLtrpInSPS;
945          rps->setNumberOfLongtermPictures(numOfLtrp);
946        }
947        Int bitsForLtrpInSPS = 0;
948        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
949        {
950          bitsForLtrpInSPS++;
951        }
952        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
953        numOfLtrp += uiCode;
954        rps->setNumberOfLongtermPictures(numOfLtrp);
955        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
956        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
957        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
958        {
959          Int pocLsbLt;
960          if (k < numLtrpInSPS)
961          {
962            uiCode = 0;
963            if (bitsForLtrpInSPS > 0)
964            {
965              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
966            }
967            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
968
969            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
970            rps->setUsed(j,usedByCurrFromSPS);
971          }
972          else
973          {
974            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
975            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
976          }
977          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
978          Bool mSBPresentFlag = uiCode ? true : false;
979          if(mSBPresentFlag)                 
980          {
981            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
982            Bool deltaFlag = false;
983            //            First LTRP                               || First LTRP from SH
984            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
985            {
986              deltaFlag = true;
987            }
988            if(deltaFlag)
989            {
990              deltaPocMSBCycleLT = uiCode;
991            }
992            else
993            {
994              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
995            }
996
997            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
998                                        - iPOClsb + pocLsbLt;
999            rps->setPOC     (j, pocLTCurr); 
1000            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
1001            rps->setCheckLTMSBPresent(j,true); 
1002          }
1003          else
1004          {
1005            rps->setPOC     (j, pocLsbLt);
1006            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
1007            rps->setCheckLTMSBPresent(j,false); 
1008          }
1009          prevDeltaMSB = deltaPocMSBCycleLT;
1010        }
1011        offset += rps->getNumberOfLongtermPictures();
1012        rps->setNumberOfPictures(offset);       
1013      } 
1014      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1015        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1016        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1017      {
1018        // In the case of BLA picture types, rps data is read from slice header but ignored
1019        rps = rpcSlice->getLocalRPS();
1020        rps->setNumberOfNegativePictures(0);
1021        rps->setNumberOfPositivePictures(0);
1022        rps->setNumberOfLongtermPictures(0);
1023        rps->setNumberOfPictures(0);
1024        rpcSlice->setRPS(rps);
1025      }
1026      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
1027      {
1028        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
1029        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
1030      }
1031      else
1032      {
1033        rpcSlice->setEnableTMVPFlag(false);
1034      }
1035    }
1036    if(sps->getUseSAO())
1037    {
1038      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
1039      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
1040    }
1041
1042    if (rpcSlice->getIdrPicFlag())
1043    {
1044      rpcSlice->setEnableTMVPFlag(false);
1045    }
1046    if (!rpcSlice->isIntra())
1047    {
1048
1049      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
1050      if (uiCode)
1051      {
1052        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
1053        if (rpcSlice->isInterB())
1054        {
1055          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
1056        }
1057        else
1058        {
1059          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
1060        }
1061      }
1062      else
1063      {
1064        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
1065        if (rpcSlice->isInterB())
1066        {
1067          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
1068        }
1069        else
1070        {
1071          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
1072        }
1073      }
1074    }
1075    // }
1076    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
1077    if(!rpcSlice->isIntra())
1078    {
1079      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1080      {
1081        refPicListModification->setRefPicListModificationFlagL0( 0 );
1082      }
1083      else
1084      {
1085        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
1086      }
1087
1088      if(refPicListModification->getRefPicListModificationFlagL0())
1089      {
1090        uiCode = 0;
1091        Int i = 0;
1092        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
1093        if ( numRpsCurrTempList0 > 1 )
1094        {
1095          Int length = 1;
1096          numRpsCurrTempList0 --;
1097          while ( numRpsCurrTempList0 >>= 1) 
1098          {
1099            length ++;
1100          }
1101          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1102          {
1103            READ_CODE( length, uiCode, "list_entry_l0" );
1104            refPicListModification->setRefPicSetIdxL0(i, uiCode );
1105          }
1106        }
1107        else
1108        {
1109          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
1110          {
1111            refPicListModification->setRefPicSetIdxL0(i, 0 );
1112          }
1113        }
1114      }
1115    }
1116    else
1117    {
1118      refPicListModification->setRefPicListModificationFlagL0(0);
1119    }
1120    if(rpcSlice->isInterB())
1121    {
1122      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
1123      {
1124        refPicListModification->setRefPicListModificationFlagL1( 0 );
1125      }
1126      else
1127      {
1128        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
1129      }
1130      if(refPicListModification->getRefPicListModificationFlagL1())
1131      {
1132        uiCode = 0;
1133        Int i = 0;
1134        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
1135        if ( numRpsCurrTempList1 > 1 )
1136        {
1137          Int length = 1;
1138          numRpsCurrTempList1 --;
1139          while ( numRpsCurrTempList1 >>= 1) 
1140          {
1141            length ++;
1142          }
1143          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1144          {
1145            READ_CODE( length, uiCode, "list_entry_l1" );
1146            refPicListModification->setRefPicSetIdxL1(i, uiCode );
1147          }
1148        }
1149        else
1150        {
1151          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
1152          {
1153            refPicListModification->setRefPicSetIdxL1(i, 0 );
1154          }
1155        }
1156      }
1157    } 
1158    else
1159    {
1160      refPicListModification->setRefPicListModificationFlagL1(0);
1161    }
1162    if (rpcSlice->isInterB())
1163    {
1164      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
1165    }
1166
1167    rpcSlice->setCabacInitFlag( false ); // default
1168    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
1169    {
1170      READ_FLAG(uiCode, "cabac_init_flag");
1171      rpcSlice->setCabacInitFlag( uiCode ? true : false );
1172    }
1173
1174    if ( rpcSlice->getEnableTMVPFlag() )
1175    {
1176      if ( rpcSlice->getSliceType() == B_SLICE )
1177      {
1178        READ_FLAG( uiCode, "collocated_from_l0_flag" );
1179        rpcSlice->setColFromL0Flag(uiCode);
1180      }
1181      else
1182      {
1183        rpcSlice->setColFromL0Flag( 1 );
1184      }
1185
1186      if ( rpcSlice->getSliceType() != I_SLICE &&
1187          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
1188           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
1189      {
1190        READ_UVLC( uiCode, "collocated_ref_idx" );
1191        rpcSlice->setColRefIdx(uiCode);
1192      }
1193      else
1194      {
1195        rpcSlice->setColRefIdx(0);
1196      }
1197    }
1198    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
1199    {
1200      xParsePredWeightTable(rpcSlice);
1201      rpcSlice->initWpScaling();
1202    }
1203    if (!rpcSlice->isIntra())
1204    {
1205      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
1206      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
1207    }
1208
1209    READ_SVLC( iCode, "slice_qp_delta" );
1210    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
1211
1212    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
1213    assert( rpcSlice->getSliceQp() <=  51 );
1214
1215    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
1216    {
1217      READ_SVLC( iCode, "slice_qp_delta_cb" );
1218      rpcSlice->setSliceQpDeltaCb( iCode );
1219      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
1220      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
1221      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
1222      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
1223
1224      READ_SVLC( iCode, "slice_qp_delta_cr" );
1225      rpcSlice->setSliceQpDeltaCr( iCode );
1226      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
1227      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
1228      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
1229      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
1230    }
1231
1232    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
1233    {
1234      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
1235      {
1236        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
1237      }
1238      else
1239      { 
1240        rpcSlice->setDeblockingFilterOverrideFlag(0);
1241      }
1242      if(rpcSlice->getDeblockingFilterOverrideFlag())
1243      {
1244        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
1245        if(!rpcSlice->getDeblockingFilterDisable())
1246        {
1247          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
1248          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
1249                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
1250          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
1251          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
1252                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
1253        }
1254      }
1255      else
1256      {
1257        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
1258        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
1259        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
1260      }
1261    }
1262    else
1263    { 
1264      rpcSlice->setDeblockingFilterDisable       ( false );
1265      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
1266      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
1267    }
1268
1269    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
1270    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
1271
1272    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
1273    {
1274      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
1275    }
1276    else
1277    {
1278      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
1279    }
1280    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
1281
1282  }
1283 
1284    UInt *entryPointOffset          = NULL;
1285    UInt numEntryPointOffsets, offsetLenMinus1;
1286  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
1287  {
1288    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
1289    if (numEntryPointOffsets>0)
1290    {
1291      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
1292    }
1293    entryPointOffset = new UInt[numEntryPointOffsets];
1294    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
1295    {
1296#if L0116_ENTRY_POINT
1297      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
1298      entryPointOffset[ idx ] = uiCode + 1;
1299#else
1300      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
1301      entryPointOffset[ idx ] = uiCode;
1302#endif
1303    }
1304  }
1305  else
1306  {
1307    rpcSlice->setNumEntryPointOffsets ( 0 );
1308  }
1309
1310  if(pps->getSliceHeaderExtensionPresentFlag())
1311  {
1312    READ_UVLC(uiCode,"slice_header_extension_length");
1313    for(Int i=0; i<uiCode; i++)
1314    {
1315      UInt ignore;
1316      READ_CODE(8,ignore,"slice_header_extension_data_byte");
1317    }
1318  }
1319  m_pcBitstream->readByteAlignment();
1320
1321  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
1322  {
1323    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
1324    Int  curEntryPointOffset     = 0;
1325    Int  prevEntryPointOffset    = 0;
1326    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
1327    {
1328      curEntryPointOffset += entryPointOffset[ idx ];
1329
1330      Int emulationPreventionByteCount = 0;
1331      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
1332      {
1333        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
1334             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
1335        {
1336          emulationPreventionByteCount++;
1337        }
1338      }
1339
1340      entryPointOffset[ idx ] -= emulationPreventionByteCount;
1341      prevEntryPointOffset = curEntryPointOffset;
1342    }
1343
1344    if ( pps->getTilesEnabledFlag() )
1345    {
1346      rpcSlice->setTileLocationCount( numEntryPointOffsets );
1347
1348      UInt prevPos = 0;
1349      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
1350      {
1351        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
1352        prevPos += entryPointOffset[ idx ];
1353      }
1354    }
1355    else if ( pps->getEntropyCodingSyncEnabledFlag() )
1356    {
1357    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
1358      rpcSlice->allocSubstreamSizes(numSubstreams);
1359      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
1360      for (Int idx=0; idx<numSubstreams-1; idx++)
1361      {
1362        if ( idx < numEntryPointOffsets )
1363        {
1364          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
1365        }
1366        else
1367        {
1368          pSubstreamSizes[ idx ] = 0;
1369        }
1370      }
1371    }
1372
1373    if (entryPointOffset)
1374    {
1375      delete [] entryPointOffset;
1376    }
1377  }
1378
1379  return;
1380}
1381 
1382Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
1383{
1384  UInt uiCode;
1385  if(profilePresentFlag)
1386  {
1387    parseProfileTier(rpcPTL->getGeneralPTL());
1388  }
1389  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
1390
1391#if L0363_BYTE_ALIGN
1392  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
1393  {
1394    if(profilePresentFlag)
1395    {
1396      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
1397    }
1398    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
1399  }
1400 
1401  if (maxNumSubLayersMinus1 > 0)
1402  {
1403    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
1404    {
1405      READ_CODE(2, uiCode, "reserved_zero_2bits");
1406      assert(uiCode == 0);
1407    }
1408  }
1409#endif
1410 
1411  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
1412  {
1413#if !L0363_BYTE_ALIGN
1414    if(profilePresentFlag)
1415    {
1416      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
1417    }
1418    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
1419#endif
1420    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
1421    {
1422      parseProfileTier(rpcPTL->getSubLayerPTL(i));
1423    }
1424    if(rpcPTL->getSubLayerLevelPresentFlag(i))
1425    {
1426      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
1427    }
1428  }
1429}
1430
1431Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
1432{
1433  UInt uiCode;
1434  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
1435  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
1436  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
1437  for(Int j = 0; j < 32; j++)
1438  {
1439    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
1440  }
1441#if L0046_CONSTRAINT_FLAGS
1442  READ_FLAG(uiCode, "general_progressive_source_flag");
1443  ptl->setProgressiveSourceFlag(uiCode ? true : false);
1444
1445  READ_FLAG(uiCode, "general_interlaced_source_flag");
1446  ptl->setInterlacedSourceFlag(uiCode ? true : false);
1447 
1448  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
1449  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
1450 
1451  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
1452  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
1453 
1454  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
1455  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
1456  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
1457#elif L0363_MORE_BITS
1458  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[0..15]");
1459  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[16..31]");
1460  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[32..47]");
1461#else
1462  READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]");  assert( uiCode == 0 );
1463#endif
1464}
1465#if SIGNAL_BITRATE_PICRATE_IN_VPS
1466Void TDecCavlc::parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
1467{
1468  UInt uiCode;
1469  for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
1470  {
1471    READ_FLAG( uiCode, "bit_rate_info_present_flag[i]" ); info->setBitRateInfoPresentFlag(i, uiCode ? true : false);
1472    READ_FLAG( uiCode, "pic_rate_info_present_flag[i]" ); info->setPicRateInfoPresentFlag(i, uiCode ? true : false);
1473    if(info->getBitRateInfoPresentFlag(i))
1474    {
1475      READ_CODE( 16, uiCode, "avg_bit_rate[i]" ); info->setAvgBitRate(i, uiCode);
1476      READ_CODE( 16, uiCode, "max_bit_rate[i]" ); info->setMaxBitRate(i, uiCode);
1477    }
1478    if(info->getPicRateInfoPresentFlag(i))
1479    {
1480      READ_CODE(  2, uiCode,  "constant_pic_rate_idc[i]" ); info->setConstantPicRateIdc(i, uiCode);
1481      READ_CODE( 16, uiCode,  "avg_pic_rate[i]"          ); info->setAvgPicRate(i, uiCode);
1482    }
1483  }
1484}
1485#endif 
1486Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
1487{
1488  ruiBit = false;
1489  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
1490  if(iBitsLeft <= 8)
1491  {
1492    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
1493    if (uiPeekValue == (1<<(iBitsLeft-1)))
1494    {
1495      ruiBit = true;
1496    }
1497  }
1498}
1499
1500Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1501{
1502  assert(0);
1503}
1504
1505Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1506{
1507  assert(0);
1508}
1509
1510Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
1511{
1512  assert(0);
1513}
1514
1515Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1516{
1517  assert(0);
1518}
1519
1520Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1521{
1522  assert(0);
1523}
1524
1525Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1526{
1527  assert(0);
1528}
1529
1530/** Parse I_PCM information.
1531* \param pcCU pointer to CU
1532* \param uiAbsPartIdx CU index
1533* \param uiDepth CU depth
1534* \returns Void
1535*
1536* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
1537*/
1538Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1539{
1540  assert(0);
1541}
1542
1543Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1544{ 
1545  assert(0);
1546}
1547
1548Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
1549{
1550  assert(0);
1551}
1552
1553Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
1554{
1555  assert(0);
1556}
1557
1558Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
1559{
1560  assert(0);
1561}
1562
1563Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
1564{
1565  assert(0);
1566}
1567
1568Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1569{
1570  Int qp;
1571  Int  iDQp;
1572
1573  xReadSvlc( iDQp );
1574
1575  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1576  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
1577
1578  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
1579  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
1580
1581  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
1582}
1583
1584Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
1585{
1586  assert(0);
1587}
1588
1589Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
1590{
1591  assert(0);
1592}
1593
1594Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
1595{
1596  assert(0);
1597}
1598
1599Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
1600{
1601  assert(0);
1602}
1603
1604Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
1605{
1606  assert(0);
1607}
1608
1609Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
1610{
1611  assert(0);
1612}
1613
1614Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
1615{
1616  assert(0);
1617}
1618
1619// ====================================================================================================================
1620// Protected member functions
1621// ====================================================================================================================
1622
1623/** parse explicit wp tables
1624* \param TComSlice* pcSlice
1625* \returns Void
1626*/
1627Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
1628{
1629  wpScalingParam  *wp;
1630  Bool            bChroma     = true; // color always present in HEVC ?
1631  SliceType       eSliceType  = pcSlice->getSliceType();
1632  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
1633  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
1634  UInt            uiTotalSignalledWeightFlags = 0;
1635 
1636  Int iDeltaDenom;
1637  // decode delta_luma_log2_weight_denom :
1638  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
1639  assert( uiLog2WeightDenomLuma <= 7 );
1640  if( bChroma ) 
1641  {
1642    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
1643    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
1644    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
1645    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
1646  }
1647
1648  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
1649  {
1650    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
1651    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
1652    {
1653      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
1654
1655      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
1656      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
1657      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
1658
1659      UInt  uiCode;
1660      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
1661      wp[0].bPresentFlag = ( uiCode == 1 );
1662      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
1663    }
1664    if ( bChroma ) 
1665    {
1666      UInt  uiCode;
1667      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
1668      {
1669        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
1670        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
1671        wp[1].bPresentFlag = ( uiCode == 1 );
1672        wp[2].bPresentFlag = ( uiCode == 1 );
1673        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
1674      }
1675    }
1676    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
1677    {
1678      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
1679      if ( wp[0].bPresentFlag ) 
1680      {
1681        Int iDeltaWeight;
1682        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
1683        assert( iDeltaWeight >= -128 );
1684        assert( iDeltaWeight <=  127 );
1685        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
1686        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
1687        assert( wp[0].iOffset >= -128 );
1688        assert( wp[0].iOffset <=  127 );
1689      }
1690      else 
1691      {
1692        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
1693        wp[0].iOffset = 0;
1694      }
1695      if ( bChroma ) 
1696      {
1697        if ( wp[1].bPresentFlag ) 
1698        {
1699          for ( Int j=1 ; j<3 ; j++ ) 
1700          {
1701            Int iDeltaWeight;
1702            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
1703            assert( iDeltaWeight >= -128 );
1704            assert( iDeltaWeight <=  127 );
1705            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
1706
1707            Int iDeltaChroma;
1708            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
1709            assert( iDeltaChroma >= -512 );
1710            assert( iDeltaChroma <=  511 );
1711            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
1712            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
1713          }
1714        }
1715        else 
1716        {
1717          for ( Int j=1 ; j<3 ; j++ ) 
1718          {
1719            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
1720            wp[j].iOffset = 0;
1721          }
1722        }
1723      }
1724    }
1725
1726    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
1727    {
1728      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
1729
1730      wp[0].bPresentFlag = false;
1731      wp[1].bPresentFlag = false;
1732      wp[2].bPresentFlag = false;
1733    }
1734  }
1735  assert(uiTotalSignalledWeightFlags<=24);
1736}
1737
1738/** decode quantization matrix
1739* \param scalingList quantization matrix information
1740*/
1741Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
1742{
1743  UInt  code, sizeId, listId;
1744  Bool scalingListPredModeFlag;
1745  //for each size
1746  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
1747  {
1748    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
1749    {
1750      READ_FLAG( code, "scaling_list_pred_mode_flag");
1751      scalingListPredModeFlag = (code) ? true : false;
1752      if(!scalingListPredModeFlag) //Copy Mode
1753      {
1754        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
1755        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
1756        if( sizeId > SCALING_LIST_8x8 )
1757        {
1758          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
1759        }
1760        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
1761
1762      }
1763      else //DPCM Mode
1764      {
1765        xDecodeScalingList(scalingList, sizeId, listId);
1766      }
1767    }
1768  }
1769
1770  return;
1771}
1772/** decode DPCM
1773* \param scalingList  quantization matrix information
1774* \param sizeId size index
1775* \param listId list index
1776*/
1777Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
1778{
1779  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
1780  Int data;
1781  Int scalingListDcCoefMinus8 = 0;
1782  Int nextCoef = SCALING_LIST_START_VALUE;
1783  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
1784  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
1785
1786  if( sizeId > SCALING_LIST_8x8 )
1787  {
1788    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
1789    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
1790    nextCoef = scalingList->getScalingListDC(sizeId,listId);
1791  }
1792
1793  for(i = 0; i < coefNum; i++)
1794  {
1795    READ_SVLC( data, "scaling_list_delta_coef");
1796    nextCoef = (nextCoef + data + 256 ) % 256;
1797    dst[scan[i]] = nextCoef;
1798  }
1799}
1800
1801Bool TDecCavlc::xMoreRbspData()
1802{ 
1803  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
1804
1805  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
1806  if (bitsLeft > 8)
1807  {
1808    return true;
1809  }
1810
1811  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
1812  Int cnt = bitsLeft;
1813
1814  // remove trailing bits equal to zero
1815  while ((cnt>0) && ((lastByte & 1) == 0))
1816  {
1817    lastByte >>= 1;
1818    cnt--;
1819  }
1820  // remove bit equal to one
1821  cnt--;
1822
1823  // we should not have a negative number of bits
1824  assert (cnt>=0);
1825
1826  // we have more data, if cnt is not zero
1827  return (cnt>0);
1828}
1829
1830//! \}
1831
Note: See TracBrowser for help on using the repository browser.