source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncCavlc.cpp @ 72

Last change on this file since 72 was 56, checked in by hschwarz, 13 years ago

updated trunk (move to HM6.1)

  • Property svn:eol-style set to native
File size: 62.0 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[56]6 * Copyright (c) 2010-2012, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TEncCavlc.cpp
35    \brief    CAVLC encoder class
36*/
37
[56]38#include "../TLibCommon/CommonDef.h"
[2]39#include "TEncCavlc.h"
40#include "SEIwrite.h"
41
[56]42//! \ingroup TLibEncoder
43//! \{
[2]44
[56]45#if ENC_DEC_TRACE
46
47#define WRITE_CODE( value, length, name)    xWriteCodeTr ( value, length, name )
48#define WRITE_UVLC( value,         name)    xWriteUvlcTr ( value,         name )
49#define WRITE_SVLC( value,         name)    xWriteSvlcTr ( value,         name )
50#define WRITE_FLAG( value,         name)    xWriteFlagTr ( value,         name )
51
52Void  xWriteUvlcTr          ( UInt value,               const Char *pSymbolName);
53Void  xWriteSvlcTr          ( Int  value,               const Char *pSymbolName);
54Void  xWriteFlagTr          ( UInt value,               const Char *pSymbolName);
55
56Void  xTraceSPSHeader (TComSPS *pSPS)
[2]57{
[56]58  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
59}
[2]60
[56]61Void  xTracePPSHeader (TComPPS *pPPS)
62{
63  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
[2]64}
65
[56]66Void  xTraceAPSHeader (TComAPS *pAPS)
[2]67{
[56]68  fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
[2]69}
70
[56]71Void  xTraceSliceHeader (TComSlice *pSlice)
72{
73  fprintf( g_hTrace, "=========== Slice ===========\n");
74}
[2]75
76
[56]77Void  TEncCavlc::xWriteCodeTr (UInt value, UInt  length, const Char *pSymbolName)
[2]78{
[56]79  xWriteCode (value,length);
80  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
81  fprintf( g_hTrace, "%-40s u(%d) : %d\n", pSymbolName, length, value ); 
82}
[2]83
[56]84Void  TEncCavlc::xWriteUvlcTr (UInt value, const Char *pSymbolName)
85{
86  xWriteUvlc (value);
87  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
88  fprintf( g_hTrace, "%-40s u(v) : %d\n", pSymbolName, value ); 
89}
[2]90
[56]91Void  TEncCavlc::xWriteSvlcTr (Int value, const Char *pSymbolName)
92{
93  xWriteSvlc(value);
94  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
95  fprintf( g_hTrace, "%-40s s(v) : %d\n", pSymbolName, value ); 
96}
[2]97
[56]98Void  TEncCavlc::xWriteFlagTr(UInt value, const Char *pSymbolName)
99{
100  xWriteFlag(value);
101  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
102  fprintf( g_hTrace, "%-40s u(1) : %d\n", pSymbolName, value ); 
103}
[2]104
105#else
106
[56]107#define WRITE_CODE( value, length, name)     xWriteCode ( value, length )
108#define WRITE_UVLC( value,         name)     xWriteUvlc ( value )
109#define WRITE_SVLC( value,         name)     xWriteSvlc ( value )
110#define WRITE_FLAG( value,         name)     xWriteFlag ( value )
[2]111
112#endif
113
114
115
[56]116// ====================================================================================================================
117// Constructor / destructor / create / destroy
118// ====================================================================================================================
[2]119
[56]120TEncCavlc::TEncCavlc()
[2]121{
[56]122  m_pcBitIf           = NULL;
123  m_uiCoeffCost       = 0;
124  m_bAlfCtrl = false;
125  m_uiMaxAlfCtrlDepth = 0;
126 
127  m_iSliceGranularity = 0;
[2]128}
129
[56]130TEncCavlc::~TEncCavlc()
[2]131{
132}
133
[56]134
135// ====================================================================================================================
136// Public member functions
137// ====================================================================================================================
138
139Void TEncCavlc::resetEntropy()
[2]140{
141}
142
143/**
[56]144 * marshall the SEI message sei.
[2]145 */
146void TEncCavlc::codeSEI(const SEI& sei)
147{
148  writeSEImessage(*m_pcBitIf, sei);
149}
150
[56]151Void  TEncCavlc::codeAPSInitInfo(TComAPS* pcAPS)
[2]152{
[56]153
154#if ENC_DEC_TRACE 
155  xTraceAPSHeader(pcAPS);
[42]156#endif
[56]157  //APS ID
158  WRITE_UVLC( pcAPS->getAPSID(), "aps_id" );
[2]159
[56]160  WRITE_FLAG( pcAPS->getScalingListEnabled()?1:0, "aps_scaling_list_data_present_flag");
161  //DF flag
162  WRITE_FLAG(pcAPS->getLoopFilterOffsetInAPS()?1:0, "aps_deblocking_filter_flag");
163#if !SAO_UNIT_INTERLEAVING
164  //SAO flag
165  WRITE_FLAG( pcAPS->getSaoEnabled()?1:0, "aps_sample_adaptive_offset_flag"); 
[2]166#endif
[56]167#if !LCU_SYNTAX_ALF
168  //ALF flag
169  WRITE_FLAG( pcAPS->getAlfEnabled()?1:0, "aps_adaptive_loop_filter_flag"); 
[2]170#endif
171}
[56]172#if LCU_SYNTAX_ALF
173Void TEncCavlc::codeAPSAlflag(UInt uiCode)
174{
175  WRITE_FLAG(uiCode, "aps_adaptive_loop_filter_flag");
176}
177#endif
[2]178
[56]179Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName)
[42]180{
[56]181  WRITE_FLAG(uiCode, pSymbolName);
[42]182}
[56]183Void TEncCavlc::codeDFSvlc(Int iCode, const Char *pSymbolName)
[2]184{
[56]185  WRITE_SVLC(iCode, pSymbolName);
[2]186}
187
[56]188#if RPS_IN_SPS
189Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps )
[42]190#else
[56]191Void TEncCavlc::codeShortTermRefPicSet( TComPPS* pcPPS, TComReferencePictureSet* rps )
[42]192#endif
[56]193{
194#if PRINT_RPS_INFO
195  int lastBits = getNumberOfWrittenBits();
[2]196#endif
[56]197  WRITE_FLAG( rps->getInterRPSPrediction(), "inter_ref_pic_set_prediction_flag" ); // inter_RPS_prediction_flag
198  if (rps->getInterRPSPrediction()) 
199  {
200    Int deltaRPS = rps->getDeltaRPS();
201    WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
202    WRITE_CODE( (deltaRPS >=0 ? 0: 1), 1, "delta_rps_sign" ); //delta_rps_sign
203    WRITE_UVLC( abs(deltaRPS) - 1, "abs_delta_rps_minus1"); // absolute delta RPS minus 1
[2]204
[56]205    for(Int j=0; j < rps->getNumRefIdc(); j++)
206    {
207      Int refIdc = rps->getRefIdc(j);
208      WRITE_CODE( (refIdc==1? 1: 0), 1, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
209      if (refIdc != 1) 
210      {
211        WRITE_CODE( refIdc>>1, 1, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
212      }
213    }
[2]214  }
[56]215  else
[2]216  {
[56]217    WRITE_UVLC( rps->getNumberOfNegativePictures(), "num_negative_pics" );
218    WRITE_UVLC( rps->getNumberOfPositivePictures(), "num_positive_pics" );
219    Int prev = 0;
220    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
[2]221    {
[56]222      WRITE_UVLC( prev-rps->getDeltaPOC(j)-1, "delta_poc_s0_minus1" );
223      prev = rps->getDeltaPOC(j);
224      WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s0_flag"); 
[2]225    }
[56]226    prev = 0;
227    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
[2]228    {
[56]229      WRITE_UVLC( rps->getDeltaPOC(j)-prev-1, "delta_poc_s1_minus1" );
230      prev = rps->getDeltaPOC(j);
231      WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s1_flag" ); 
[2]232    }
233  }
[56]234
235#if PRINT_RPS_INFO
236  printf("irps=%d (%2d bits) ", rps->getInterRPSPrediction(), getNumberOfWrittenBits() - lastBits);
237  rps->printDeltaPOC();
238#endif
[2]239}
240
[56]241
242Void TEncCavlc::codePPS( TComPPS* pcPPS )
[2]243{
[56]244#if ENC_DEC_TRACE 
245  xTracePPSHeader (pcPPS);
[42]246#endif
[56]247#if !RPS_IN_SPS
248  TComRPSList* rpsList = pcPPS->getRPSList();
[2]249#endif
[56]250 
251  WRITE_UVLC( pcPPS->getPPSId(),                             "pic_parameter_set_id" );
252  WRITE_UVLC( pcPPS->getSPSId(),                             "seq_parameter_set_id" );
[2]253
[56]254#if MULTIBITS_DATA_HIDING
255  WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" );
256  if( pcPPS->getSignHideFlag() )
[2]257  {
[56]258    WRITE_CODE(pcPPS->getTSIG(), 4, "sign_hiding_threshold");
[2]259  }
[56]260#endif
261#if CABAC_INIT_FLAG
262  WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0,   "cabac_init_present_flag" );
263#endif
264#if !RPS_IN_SPS
265  // RPS is put before entropy_coding_mode_flag
266  // since entropy_coding_mode_flag will probably be removed from the WD
267  TComReferencePictureSet*      rps;
268
269  WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
270  for(UInt i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
[2]271  {
[56]272    rps = rpsList->getReferencePictureSet(i);
273    codeShortTermRefPicSet(pcPPS,rps);
[2]274  }
[56]275  WRITE_FLAG( pcPPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
276#endif
277  // entropy_coding_mode_flag
278  // We code the entropy_coding_mode_flag, it's needed for tests.
279  WRITE_FLAG( pcPPS->getEntropyCodingMode() ? 1 : 0,         "entropy_coding_mode_flag" );
280  if (pcPPS->getEntropyCodingMode())
[2]281  {
[56]282#if !WPP_SIMPLIFICATION
283    WRITE_UVLC( pcPPS->getEntropyCodingSynchro(),            "entropy_coding_synchro" );
284    WRITE_FLAG( pcPPS->getCabacIstateReset() ? 1 : 0,        "cabac_istate_reset" );
285#endif
286#if !TILES_OR_ENTROPY_SYNC_IDC
287#if !WPP_SIMPLIFICATION
288    if ( pcPPS->getEntropyCodingSynchro() )
289#endif
290    {
291      WRITE_UVLC( pcPPS->getNumSubstreams()-1,               "num_substreams_minus1" );
292    }
293#endif
[2]294  }
[56]295#if !H0566_TLA
296  WRITE_UVLC( pcPPS->getNumTLayerSwitchingFlags(),           "num_temporal_layer_switching_point_flags" );
297  for( UInt i = 0; i < pcPPS->getNumTLayerSwitchingFlags(); i++ ) 
[2]298  {
[56]299    WRITE_FLAG( pcPPS->getTLayerSwitchingFlag( i ) ? 1 : 0 , "temporal_layer_switching_point_flag" ); 
[2]300  }
[56]301#endif
302  //   num_ref_idx_l0_default_active_minus1
303  //   num_ref_idx_l1_default_active_minus1
304  WRITE_SVLC( pcPPS->getPicInitQPMinus26(),                  "pic_init_qp_minus26");
305  WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0,      "constrained_intra_pred_flag" );
306  WRITE_FLAG( pcPPS->getEnableTMVPFlag() ? 1 : 0,            "enable_temporal_mvp_flag" );
307  WRITE_CODE( pcPPS->getSliceGranularity(), 2,               "slice_granularity");
308  WRITE_UVLC( pcPPS->getMaxCuDQPDepth() + pcPPS->getUseDQP(),                   "max_cu_qp_delta_depth" );
[2]309
[56]310  WRITE_SVLC( pcPPS->getChromaQpOffset(),                   "chroma_qp_offset"     );
311  WRITE_SVLC( pcPPS->getChromaQpOffset2nd(),                "chroma_qp_offset_2nd" );
[2]312
[56]313  WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0,  "weighted_pred_flag" );   // Use of Weighting Prediction (P_SLICE)
314  WRITE_CODE( pcPPS->getWPBiPredIdc(), 2, "weighted_bipred_idc" );  // Use of Weighting Bi-Prediction (B_SLICE)
315#if H0388
316  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,  "output_flag_present_flag" );
317#endif
318#if TILES_OR_ENTROPY_SYNC_IDC
319  if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==1)
320  {
321#endif
322    WRITE_FLAG( pcPPS->getColumnRowInfoPresent(),           "tile_info_present_flag" );
323    WRITE_FLAG( pcPPS->getTileBehaviorControlPresentFlag(),  "tile_control_present_flag");
324    if( pcPPS->getColumnRowInfoPresent() == 1 )
[2]325    {
[56]326      WRITE_UVLC( pcPPS->getNumColumnsMinus1(),                                    "num_tile_columns_minus1" );
327      WRITE_UVLC( pcPPS->getNumRowsMinus1(),                                       "num_tile_rows_minus1" );
328      WRITE_FLAG( pcPPS->getUniformSpacingIdr(),                                   "uniform_spacing_flag" );
329      if( pcPPS->getUniformSpacingIdr() == 0 )
[2]330      {
[56]331        for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
[2]332        {
[56]333          WRITE_UVLC( pcPPS->getColumnWidth(i),                                    "column_width" );
[2]334        }
[56]335        for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
[2]336        {
[56]337          WRITE_UVLC( pcPPS->getRowHeight(i),                                      "row_height" );
[2]338        }
339      }
[56]340    }
[2]341
[56]342    if(pcPPS->getTileBehaviorControlPresentFlag() == 1)
[2]343    {
[56]344      Int iNumColTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumColumnsMinus1());
345      Int iNumRowTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumRowsMinus1());
[2]346
[56]347      if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0)
[2]348      {
[56]349#if !REMOVE_TILE_DEPENDENCE
350        WRITE_FLAG( pcPPS->getTileBoundaryIndependenceIdr(),                         "tile_boundary_independence_flag" );
351        if(pcPPS->getTileBoundaryIndependenceIdr() == 1)
[2]352        {
[56]353#endif
354          WRITE_FLAG( pcPPS->getLFCrossTileBoundaryFlag()?1 : 0,            "loop_filter_across_tile_flag");
355#if !REMOVE_TILE_DEPENDENCE
[2]356        }
357#endif
358      }
359    }
[56]360#if TILES_OR_ENTROPY_SYNC_IDC
[2]361  }
[56]362  else if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==2)
[2]363  {
[56]364    WRITE_UVLC( pcPPS->getNumSubstreams()-1,               "num_substreams_minus1" );
[2]365  }
366#endif
367
[56]368#if DBL_CONTROL
369  WRITE_FLAG( pcPPS->getDeblockingFilterControlPresent()?1 : 0, "deblocking_filter_control_present_flag");
[2]370#endif
[56]371#if PARALLEL_MERGE
372  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
[2]373#endif
[56]374  WRITE_FLAG( 0, "pps_extension_flag" );
[2]375}
376
[56]377#if HHI_MPI
378Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
[2]379#else
[56]380Void TEncCavlc::codeSPS( TComSPS* pcSPS )
[2]381#endif
[56]382{
383#if ENC_DEC_TRACE 
384  xTraceSPSHeader (pcSPS);
[2]385#endif
[56]386  WRITE_CODE( pcSPS->getProfileIdc (),     8,       "profile_idc" );
387  WRITE_CODE( 0,                           8,       "reserved_zero_8bits" );
388  WRITE_CODE( pcSPS->getLevelIdc (),       8,       "level_idc" );
389  WRITE_UVLC( pcSPS->getSPSId (),                   "seq_parameter_set_id" );
390  WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
391  WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "max_temporal_layers_minus1" );
392  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
393  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
394#if PIC_CROPPING
395  WRITE_FLAG( pcSPS->getPicCroppingFlag(),          "pic_cropping_flag" );
396  if (pcSPS->getPicCroppingFlag())
[2]397  {
[56]398    WRITE_UVLC( pcSPS->getPicCropLeftOffset(),      "pic_crop_left_offset" );
399    WRITE_UVLC( pcSPS->getPicCropRightOffset(),     "pic_crop_right_offset" );
400    WRITE_UVLC( pcSPS->getPicCropTopOffset(),       "pic_crop_top_offset" );
401    WRITE_UVLC( pcSPS->getPicCropBottomOffset(),    "pic_crop_bottom_offset" );
[2]402  }
403#endif
404
[56]405#if FULL_NBIT
406  WRITE_UVLC( pcSPS->getBitDepth() - 8,             "bit_depth_luma_minus8" );
[2]407#else
[56]408  WRITE_UVLC( pcSPS->getBitIncrement(),             "bit_depth_luma_minus8" );
[2]409#endif
[56]410#if FULL_NBIT
411  WRITE_UVLC( pcSPS->getBitDepth() - 8,             "bit_depth_chroma_minus8" );
412#else
413  WRITE_UVLC( pcSPS->getBitIncrement(),             "bit_depth_chroma_minus8" );
[2]414#endif
415
[56]416  WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0,                   "pcm_enabled_flag");
[2]417
[56]418  if( pcSPS->getUsePCM() )
[2]419  {
[56]420  WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4,   "pcm_bit_depth_luma_minus1" );
421  WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4, "pcm_bit_depth_chroma_minus1" );
[2]422  }
[56]423
424#if LOSSLESS_CODING
425  WRITE_FLAG( (pcSPS->getUseLossless ()) ? 1 : 0,                                    "qpprime_y_zero_transquant_bypass_flag" );
[2]426#endif
[56]427
428  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
429#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
430  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
[2]431  {
[56]432    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
433    WRITE_UVLC( pcSPS->getNumReorderPics(i),               "num_reorder_pics[i]" );
434    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
[2]435  }
436#else
[56]437  WRITE_UVLC( pcSPS->getMaxNumberOfReferencePictures(), "max_num_ref_pics" ); 
438  WRITE_UVLC( pcSPS->getNumReorderFrames(),             "num_reorder_frames" ); 
439  WRITE_UVLC(pcSPS->getMaxDecFrameBuffering(),          "max_dec_frame_buffering" );
440  WRITE_UVLC(pcSPS->getMaxLatencyIncrease(),            "max_latency_increase"    );
[2]441#endif
[56]442  assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
443 
444  UInt MinCUSize = pcSPS->getMaxCUWidth() >> ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth );
445  UInt log2MinCUSize = 0;
446  while(MinCUSize > 1)
[2]447  {
[56]448    MinCUSize >>= 1;
449    log2MinCUSize++;
[2]450  }
451
[56]452#if H0412_REF_PIC_LIST_RESTRICTION
453  WRITE_FLAG( pcSPS->getRestrictedRefPicListsFlag(),                                 "restricted_ref_pic_lists_flag" );
454  if( pcSPS->getRestrictedRefPicListsFlag() )
[2]455  {
[56]456    WRITE_FLAG( pcSPS->getListsModificationPresentFlag(),                            "lists_modification_present_flag" );
[2]457  }
[5]458#endif
[56]459  WRITE_UVLC( log2MinCUSize - 3,                                                     "log2_min_coding_block_size_minus3" );
460  WRITE_UVLC( pcSPS->getMaxCUDepth()-g_uiAddCUDepth,                                 "log2_diff_max_min_coding_block_size" );
461  WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_transform_block_size_minus2" );
462  WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" );
[2]463
[56]464  if(log2MinCUSize == 3)
[2]465  {
[56]466    xWriteFlag  ( (pcSPS->getDisInter4x4()) ? 1 : 0 );
[2]467  }
468
[56]469  if( pcSPS->getUsePCM() )
[2]470  {
[56]471    WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3,                                      "log2_min_pcm_coding_block_size_minus3" );
472    WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(),             "log2_diff_max_min_pcm_coding_block_size" );
[2]473  }
[56]474  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1,                               "max_transform_hierarchy_depth_inter" );
475  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
476  WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" ); 
477  WRITE_FLAG( pcSPS->getUseLMChroma () ? 1 : 0,                                      "chroma_pred_from_luma_enabled_flag" ); 
478  WRITE_FLAG( pcSPS->getUseDF() ? 1 : 0,                                             "deblocking_filter_in_aps_enabled_flag");
479  WRITE_FLAG( pcSPS->getLFCrossSliceBoundaryFlag()?1 : 0,                            "seq_loop_filter_across_slices_enabled_flag");
480  WRITE_FLAG( pcSPS->getUseAMP(),                                                    "asymmetric_motion_partitions_enabled_flag" );
481  WRITE_FLAG( pcSPS->getUseNSQT(),                                                   "non_square_quadtree_enabled_flag" );
482  WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0,                                            "sample_adaptive_offset_enabled_flag");
483  WRITE_FLAG( pcSPS->getUseALF () ? 1 : 0,                                           "adaptive_loop_filter_enabled_flag");
484#if LCU_SYNTAX_ALF
485  if(pcSPS->getUseALF())
[2]486  {
[56]487    WRITE_FLAG( (pcSPS->getUseALFCoefInSlice()) ? 1 : 0,                             "alf_coef_in_slice_flag");
[2]488  }
489#endif
490
[56]491  if( pcSPS->getUsePCM() )
[2]492  {
[56]493  WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0,                                "pcm_loop_filter_disable_flag");
[2]494  }
495
[56]496  assert( pcSPS->getMaxTLayers() > 0 );         
[2]497
[56]498  WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "temporal_id_nesting_flag" );
[2]499
[56]500#if RPS_IN_SPS
501  TComRPSList* rpsList = pcSPS->getRPSList();
502  TComReferencePictureSet*      rps;
[2]503
[56]504  WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
505  for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
[2]506  {
[56]507    rps = rpsList->getReferencePictureSet(i);
508    codeShortTermRefPicSet(pcSPS,rps);
509  }   
510  WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
[2]511#endif
[56]512#if !PIC_CROPPING
513  //!!!KS: Syntax not in WD !!!
514 
515  xWriteUvlc  ( pcSPS->getPad (0) );
516  xWriteUvlc  ( pcSPS->getPad (1) );
517#endif
518  // AMVP mode for each depth
519  for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
[2]520  {
[56]521    xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0);
[2]522  }
523
[56]524#if TILES_WPP_ENTRY_POINT_SIGNALLING
525  Int tilesOrEntropyCodingSyncIdc = 0;
526  if ( pcSPS->getNumColumnsMinus1() > 0 || pcSPS->getNumRowsMinus1() > 0)
[2]527  {
[56]528    tilesOrEntropyCodingSyncIdc = 1;
[2]529  }
[56]530  else if ( pcSPS->getNumSubstreams() > 1 )
[2]531  {
[56]532    tilesOrEntropyCodingSyncIdc = 2;
[2]533  }
[56]534  pcSPS->setTilesOrEntropyCodingSyncIdc( tilesOrEntropyCodingSyncIdc );
535  WRITE_CODE(tilesOrEntropyCodingSyncIdc, 2, "tiles_or_entropy_coding_sync_idc");
[2]536#endif
[56]537
538#if TILES_OR_ENTROPY_SYNC_IDC
539  if(tilesOrEntropyCodingSyncIdc == 1)
[2]540  {
541#endif
[56]542    WRITE_UVLC( pcSPS->getNumColumnsMinus1(),                           "num_tile_columns_minus1" );
543    WRITE_UVLC( pcSPS->getNumRowsMinus1(),                              "num_tile_rows_minus1" );
544    WRITE_FLAG( pcSPS->getUniformSpacingIdr(),                          "uniform_spacing_flag" );
[2]545
[56]546    if( pcSPS->getUniformSpacingIdr()==0 )
[2]547    {
[56]548      for(UInt i=0; i<pcSPS->getNumColumnsMinus1(); i++)
[2]549      {
[56]550        WRITE_UVLC( pcSPS->getColumnWidth(i),                           "column_width" );
[2]551      }
[56]552      for(UInt i=0; i<pcSPS->getNumRowsMinus1(); i++)
[2]553      {
[56]554        WRITE_UVLC( pcSPS->getRowHeight(i),                             "row_height" );
[2]555      }
556    }
[56]557
558    if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0)
[2]559    {
[56]560#if !REMOVE_TILE_DEPENDENCE
561      WRITE_FLAG( pcSPS->getTileBoundaryIndependenceIdr(),                "tile_boundary_independence_flag" );
562      if(pcSPS->getTileBoundaryIndependenceIdr() == 1)
[2]563      {
[56]564#endif
565        WRITE_FLAG( pcSPS->getLFCrossTileBoundaryFlag()?1 : 0,            "loop_filter_across_tile_flag");
566#if !REMOVE_TILE_DEPENDENCE
[2]567      }
[56]568#endif
[2]569    }
[56]570#if TILES_OR_ENTROPY_SYNC_IDC
[2]571  }
[56]572#endif
573  WRITE_FLAG( 1, "sps_extension_flag" );
[2]574
[56]575  WRITE_FLAG( (pcSPS->getNumberOfUsableInterViewRefs() > 0) ? 1 : 0, "interview_refs_present_flag" );
576  if( pcSPS->getNumberOfUsableInterViewRefs() > 0 )
[2]577  {
[56]578    WRITE_UVLC( pcSPS->getNumberOfUsableInterViewRefs() - 1,   "num_usable_interview_refs_minus1" );
579
580    Int prev = 0;
581    for( Int j = 0 ; j < pcSPS->getNumberOfUsableInterViewRefs(); j++ )
582    {
583      WRITE_UVLC( prev - pcSPS->getUsableInterViewRef( j ) - 1, "delta_usable_interview_ref_minus1" );
584      prev = pcSPS->getUsableInterViewRef( j );
585    }
[2]586  }
587
[56]588#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
589  WRITE_FLAG( pcSPS->getUseDMM(), "enable_dmm_flag" );
[2]590#endif
591
[56]592#if HHI_MPI
593  if( bIsDepth )
[2]594  {
[56]595    WRITE_FLAG( pcSPS->getUseMVI() ? 1 : 0, "use_mvi_flag" );
[2]596  }
597#endif
598
[56]599  if( pcSPS->getViewId() || pcSPS->isDepth() )
[2]600  {
[56]601    WRITE_FLAG( 0, "base_view_flag" ); 
602    if( pcSPS->isDepth() )
[2]603    {
[56]604      WRITE_FLAG( 1, "depth_flag" ); 
605      WRITE_UVLC( pcSPS->getViewId(), "view_id" );
606      WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" );
[2]607    }
608    else
609    {
[56]610      WRITE_FLAG( 0, "depth_flag" ); 
611      WRITE_UVLC( pcSPS->getViewId() - 1, "view_id_minus1" );
612      WRITE_SVLC( pcSPS->getViewOrderIdx(), "view_order_idx" );
613      WRITE_UVLC( pcSPS->getCamParPrecision(), "camera_parameter_precision" );
614      WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "camera_parameter_in_slice_header" );
615      if( !pcSPS->hasCamParInSliceHeader() )
616      {
617        for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
618        {
619          WRITE_SVLC( pcSPS->getCodedScale    ()[ uiId ], "coded_scale" );
620          WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiId ], "coded_offset" );
621          WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" );
622          WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" );
623        }
[2]624      }
[56]625#if DEPTH_MAP_GENERATION
626      WRITE_UVLC( pcSPS->getPredDepthMapGeneration(), "Pdm_generation" );
627      if( pcSPS->getPredDepthMapGeneration() )
[2]628      {
[56]629        WRITE_UVLC( pcSPS->getPdmPrecision(), "Pdm_precision" );
630        for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
631        {
632          WRITE_SVLC( pcSPS->getPdmScaleNomDelta()[ uiId ], "Pdm_scale_nom_delta" );
633          WRITE_SVLC( pcSPS->getPdmOffset       ()[ uiId ], "Pdm_offset" );
634        }
635#if HHI_INTER_VIEW_MOTION_PRED
636        WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" );
637#endif
638#if HHI_INTER_VIEW_RESIDUAL_PRED
639        WRITE_FLAG  ( pcSPS->getMultiviewResPredMode(), "multi_view_residual_pred_mode" );
640#endif
[2]641      }
[56]642#endif
[2]643    }
644  }
[56]645  else
[2]646  {
[56]647    WRITE_FLAG( 1, "base_view_flag" );   
[2]648  }
[56]649  WRITE_FLAG( 0, "sps_extension2_flag" );
650}
[2]651
[56]652Void TEncCavlc::writeTileMarker( UInt uiTileIdx, UInt uiBitsUsed )
653{
654  xWriteCode( uiTileIdx, uiBitsUsed );
[2]655}
656
[56]657Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
[2]658{
[56]659#if ENC_DEC_TRACE 
660  xTraceSliceHeader (pcSlice);
[2]661#endif
662
[56]663  // if( nal_ref_idc != 0 )
664  //   dec_ref_pic_marking( )
665  // if( entropy_coding_mode_flag  &&  slice_type  !=  I)
666  //   cabac_init_idc
667  // first_slice_in_pic_flag
668  // if( first_slice_in_pic_flag == 0 )
669  //    slice_address
670  //calculate number of bits required for slice address
671  Int maxAddrOuter = pcSlice->getPic()->getNumCUsInFrame();
672  Int reqBitsOuter = 0;
673  while(maxAddrOuter>(1<<reqBitsOuter)) 
[2]674  {
[56]675    reqBitsOuter++;
[2]676  }
[56]677  Int maxAddrInner = pcSlice->getPic()->getNumPartInCU()>>(2);
678  maxAddrInner = (1<<(pcSlice->getPPS()->getSliceGranularity()<<1));
679  Int reqBitsInner = 0;
680 
681  while(maxAddrInner>(1<<reqBitsInner))
[2]682  {
[56]683    reqBitsInner++;
[2]684  }
[56]685  Int lCUAddress;
686  Int innerAddress;
687  if (pcSlice->isNextSlice())
[2]688  {
[56]689    // Calculate slice address
690    lCUAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
691    innerAddress = (pcSlice->getSliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1);
[2]692  }
693  else
694  {
[56]695    // Calculate slice address
696    lCUAddress = (pcSlice->getEntropySliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
697    innerAddress = (pcSlice->getEntropySliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1);
698   
[2]699  }
[56]700  //write slice address
701  Int address = (pcSlice->getPic()->getPicSym()->getCUOrderMap(lCUAddress) << reqBitsInner) + innerAddress;
702  WRITE_FLAG( address==0, "first_slice_in_pic_flag" );
703  if(address>0) 
[2]704  {
[56]705    WRITE_CODE( address, reqBitsOuter+reqBitsInner, "slice_address" );
[2]706  }
707
[56]708  WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
709  Bool bEntropySlice = (!pcSlice->isNextSlice());
710  WRITE_FLAG( bEntropySlice ? 1 : 0, "lightweight_slice_flag" );
711 
712  if (!bEntropySlice)
[2]713  {
[56]714    WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "pic_parameter_set_id" );
715#if H0388
716    if( pcSlice->getPPS()->getOutputFlagPresentFlag() )
[2]717    {
[56]718      WRITE_FLAG( pcSlice->getPicOutputFlag() ? 1 : 0, "pic_output_flag" );
[2]719    }
720#endif
[56]721    if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR) 
[2]722    {
[56]723      WRITE_UVLC( 0, "idr_pic_id" );
724      WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
[2]725    }
726    else
727    {
[56]728      WRITE_CODE( (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC()), pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
[2]729
[56]730      if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDV )
[2]731      {
[56]732        TComReferencePictureSet* rps = pcSlice->getRPS();
733        if(pcSlice->getRPSidx() < 0)
734        {
735          WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
736#if RPS_IN_SPS
737          codeShortTermRefPicSet(pcSlice->getSPS(), rps);
738#else
739          codeShortTermRefPicSet(pcSlice->getPPS(), rps);
[2]740#endif
[56]741        }
742        else
[2]743        {
[56]744          WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag");
745          WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
[2]746        }
[56]747#if RPS_IN_SPS
748        if(pcSlice->getSPS()->getLongTermRefsPresent())
749#else
750        if(pcSlice->getPPS()->getLongTermRefsPresent())
[2]751#endif
752        {
[56]753          WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
754          Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC();
755          Int prev = 0;
756#if LTRP_MULT
757          Int prevDeltaPocLt=0;
758          Int currDeltaPocLt=0;
759#endif
760          for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--)
761          {
762            WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt");
763         
764#if LTRP_MULT
765            currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt;
766
767            Int deltaMsbCycle=0;
768            if( (i==(rps->getNumberOfPictures()-1)) )
769            {
770              deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
771            }
772            else if( prevDeltaPocLt!=currDeltaPocLt )
773            {
774              deltaMsbCycle=((-rps->getDeltaPOC(i))/maxPocLsb)-1;
775              if( ((prevDeltaPocLt==maxPocLsb-1) && (currDeltaPocLt==maxPocLsb+1)) ||  ((prevDeltaPocLt==maxPocLsb-2) && (currDeltaPocLt==maxPocLsb)))
776              {
777                deltaMsbCycle=deltaMsbCycle-1;
778              }
779            }
780            else
781            {
782              deltaMsbCycle=((rps->getDeltaPOC(i+1)-rps->getDeltaPOC(i))/maxPocLsb)-1;
783            }
784
785            if(deltaMsbCycle>=0)
786            {
787              WRITE_FLAG( 1, "delta_poc_msb_present_flag");
788              WRITE_UVLC(deltaMsbCycle, "delta_poc_msb_cycle_lt_minus1");
789            }
790            else
791            {
792              WRITE_FLAG( 0, "delta_poc_msb_present_flag");
793            }
794            prevDeltaPocLt=currDeltaPocLt;
795#endif
796            prev = rps->getDeltaPOC(i);
797            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); 
798          }
[2]799        }
800      }
801    }
[56]802
803    if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF()|| pcSlice->getSPS()->getScalingListFlag() || pcSlice->getSPS()->getUseDF())
[2]804    {
[56]805      if (pcSlice->getSPS()->getUseALF())
[2]806      {
[56]807#if !LCU_SYNTAX_ALF
808         if (pcSlice->getAlfEnabledFlag())
809         {
810           assert (pcSlice->getAPS()->getAlfEnabled());
811         }
[2]812#endif
[56]813         WRITE_FLAG( pcSlice->getAlfEnabledFlag(), "ALF on/off flag in slice header" );
[2]814      }
[56]815      if (pcSlice->getSPS()->getUseSAO())
[2]816      {
[56]817#if SAO_UNIT_INTERLEAVING
818        WRITE_FLAG( pcSlice->getSaoInterleavingFlag(), "SAO interleaving flag" );
[2]819#endif
[56]820         assert (pcSlice->getSaoEnabledFlag() == pcSlice->getAPS()->getSaoEnabled());
821         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "SAO on/off flag in slice header" );
822#if SAO_UNIT_INTERLEAVING
823         if (pcSlice->getSaoInterleavingFlag()&&pcSlice->getSaoEnabledFlag() )
824         {
825           WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[1], "SAO on/off flag for Cb in slice header" );
826           WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[2], "SAO on/off flag for Cr in slice header" );
827         }
828#endif
[2]829      }
[56]830      WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id");
[2]831    }
[56]832
833    // we always set num_ref_idx_active_override_flag equal to one. this might be done in a more intelligent way
834    if (!pcSlice->isIntra())
835    {
836      WRITE_FLAG( 1 ,                                             "num_ref_idx_active_override_flag");
837      WRITE_CODE( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1, 3, "num_ref_idx_l0_active_minus1" );
838    }
[2]839    else
840    {
[56]841      pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
[2]842    }
[56]843    if (pcSlice->isInterB())
[2]844    {
[56]845      WRITE_CODE( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - 1, 3, "num_ref_idx_l1_active_minus1" );
[2]846    }
[56]847    else
[2]848    {
[56]849      pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
[2]850    }
[56]851#if H0412_REF_PIC_LIST_RESTRICTION
852    if( pcSlice->getSPS()->getListsModificationPresentFlag() )
853    {
[2]854#endif
[56]855    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
856#if H0137_0138_LIST_MODIFICATION
857    if( !pcSlice->isIntra() )
[2]858    {
[56]859      WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0,       "ref_pic_list_modification_flag_l0" );
860      if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0())
[2]861      {
[56]862        Int NumPocTotalCurr = pcSlice->getNumPocTotalCurrMvc();
863        if (NumPocTotalCurr > 1)
[2]864        {
[56]865          Int length = 1;
866          NumPocTotalCurr --;
867          while ( NumPocTotalCurr >>= 1) 
[2]868          {
[56]869            length ++;
[2]870          }
[56]871          for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++)
[2]872          {
[56]873            WRITE_CODE( refPicListModification->getRefPicSetIdxL0(i), length, "list_entry_l0");
[2]874          }
875        }
876      }
[56]877    }
878    if(pcSlice->isInterB())
879    {   
880      WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0,       "ref_pic_list_modification_flag_l1" );
881      if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1())
[2]882      {
[56]883        Int NumPocTotalCurr = pcSlice->getNumPocTotalCurrMvc();
884        if ( NumPocTotalCurr > 1 )
[2]885        {
[56]886          Int length = 1;
887          NumPocTotalCurr --;
888          while ( NumPocTotalCurr >>= 1)
[2]889          {
[56]890            length ++;
[2]891          }
[56]892          for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++)
[2]893          {
[56]894            WRITE_CODE( refPicListModification->getRefPicSetIdxL1(i), length, "list_entry_l1");
[2]895          }
896        }
897      }
898    }
899#else
[56]900      if(!pcSlice->isIntra())
[2]901      {
[56]902        WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0,       "ref_pic_list_modification_flag" );   
903        for(Int i = 0; i < refPicListModification->getNumberOfRefPicListModificationsL0(); i++)
[2]904        {
[56]905          WRITE_UVLC( refPicListModification->getListIdcL0(i), "ref_pic_list_modification_idc");
906          WRITE_UVLC( refPicListModification->getRefPicSetIdxL0(i), "ref_pic_set_idx");
[2]907        }
[56]908        if(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0())
909          WRITE_UVLC( 3, "ref_pic_list_modification_idc");
910      }
911      if(pcSlice->isInterB())
912      {   
913        WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0,       "ref_pic_list_modification_flag" );
914        for(Int i = 0; i < refPicListModification->getNumberOfRefPicListModificationsL1(); i++)
[2]915        {
[56]916          WRITE_UVLC( refPicListModification->getListIdcL1(i), "ref_pic_list_modification_idc");
917          WRITE_UVLC( refPicListModification->getRefPicSetIdxL1(i), "ref_pic_set_idx");
[2]918        }
[56]919        if(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1())
920          WRITE_UVLC( 3, "ref_pic_list_modification_idc");
[2]921      }
[56]922#endif
923    }
924#if H0412_REF_PIC_LIST_RESTRICTION
925  }
926#endif
927  // ref_pic_list_combination( )
928  // maybe move to own function?
929  if (pcSlice->isInterB())
930  {
931    WRITE_FLAG(pcSlice->getRefPicListCombinationFlag() ? 1 : 0,       "ref_pic_list_combination_flag" );
932    if(pcSlice->getRefPicListCombinationFlag())
933    {
934      WRITE_UVLC( pcSlice->getNumRefIdx(REF_PIC_LIST_C) - 1,          "num_ref_idx lc_active_minus1");
935     
936#if H0412_REF_PIC_LIST_RESTRICTION
937      if( pcSlice->getSPS()->getListsModificationPresentFlag() )
[2]938      {
[56]939#endif
940        WRITE_FLAG( pcSlice->getRefPicListModificationFlagLC() ? 1 : 0, "ref_pic_list_modification_flag_lc" );
941        if(pcSlice->getRefPicListModificationFlagLC())
[2]942        {
[56]943          for (UInt i=0;i<pcSlice->getNumRefIdx(REF_PIC_LIST_C);i++)
944          {
945            WRITE_FLAG( pcSlice->getListIdFromIdxOfLC(i),               "pic_from_list_0_flag" );
946#if H0137_0138_LIST_MODIFICATION
947          if (((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_0) && pcSlice->getNumRefIdx( REF_PIC_LIST_0 )>1 ) || ((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_1) && pcSlice->getNumRefIdx( REF_PIC_LIST_1 )>1 ) )
948          {
949            WRITE_UVLC( pcSlice->getRefIdxFromIdxOfLC(i),               "ref_idx_list_curr" );
950          }
951#else
952            WRITE_UVLC( pcSlice->getRefIdxFromIdxOfLC(i),               "ref_idx_list_curr" );
953#endif
954          }
[2]955        }
[56]956#if H0412_REF_PIC_LIST_RESTRICTION
[2]957      }
958#endif
959    }
960  }
[56]961   
962#if H0111_MVD_L1_ZERO
963  if (pcSlice->isInterB())
[2]964  {
[56]965    WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0,   "mvd_l1_zero_flag");
[2]966  }
967#endif
968
[56]969  if(pcSlice->getPPS()->getEntropyCodingMode() && !pcSlice->isIntra())
[2]970  {
[56]971#if CABAC_INIT_FLAG
972    if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag())
[2]973    {
[56]974      SliceType sliceType   = pcSlice->getSliceType();
975      Int  encCABACTableIdx = pcSlice->getPPS()->getEncCABACTableIdx();
976      Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=0) ? true : false;
977      pcSlice->setCabacInitFlag( encCabacInitFlag );
978      WRITE_FLAG( encCabacInitFlag?1:0, "cabac_init_flag" );
[2]979    }
980#else
[56]981    WRITE_UVLC(pcSlice->getCABACinitIDC(),  "cabac_init_idc");
[2]982#endif
983  }
984
[56]985  // if( !lightweight_slice_flag ) {
986  if (!bEntropySlice)
[2]987  {
[56]988    Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 );
989    WRITE_SVLC( iCode, "slice_qp_delta" ); 
990#if DBL_CONTROL
991    if (pcSlice->getPPS()->getDeblockingFilterControlPresent())
[2]992    {
[56]993      if ( pcSlice->getSPS()->getUseDF() )
[2]994      {
[56]995        WRITE_FLAG(pcSlice->getInheritDblParamFromAPS(), "inherit_dbl_param_from_APS_flag");
[2]996      }
[56]997#else
998    WRITE_FLAG(pcSlice->getInheritDblParamFromAPS(), "inherit_dbl_param_from_APS_flag");
999#endif
1000      if (!pcSlice->getInheritDblParamFromAPS())
[2]1001      {
[56]1002        WRITE_FLAG(pcSlice->getLoopFilterDisable(), "loop_filter_disable");  // should be an IDC
1003        if(!pcSlice->getLoopFilterDisable())
1004        {
1005          WRITE_SVLC (pcSlice->getLoopFilterBetaOffset(), "beta_offset_div2");
1006          WRITE_SVLC (pcSlice->getLoopFilterTcOffset(), "tc_offset_div2");
1007        }
[2]1008      }
[56]1009#if DBL_CONTROL
1010    }
1011#endif
1012    if ( pcSlice->getSliceType() == B_SLICE )
1013    {
1014      WRITE_FLAG( pcSlice->getColDir(), "collocated_from_l0_flag" );
1015    }
[2]1016
[56]1017#if COLLOCATED_REF_IDX
1018    if ( pcSlice->getSliceType() != I_SLICE &&
1019      ((pcSlice->getColDir()==0 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
1020      (pcSlice->getColDir()==1  && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
1021    {
1022      WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
[2]1023    }
[56]1024#endif
1025 
1026    if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE) )
[2]1027    {
[56]1028      xCodePredWeightTable( pcSlice );
[2]1029    }
1030  }
1031
[56]1032  // !!!! sytnax elements not in the WD !!!!
1033  if (!bEntropySlice)
[2]1034  {
[56]1035    if( pcSlice->getSPS()->hasCamParInSliceHeader() )
1036    {
1037      for( UInt uiId = 0; uiId < pcSlice->getSPS()->getViewId(); uiId++ )
1038      {
1039        WRITE_SVLC( pcSlice->getCodedScale    ()[ uiId ], "coded_scale" );
1040        WRITE_SVLC( pcSlice->getCodedOffset   ()[ uiId ], "coded_offset" );
1041        WRITE_SVLC( pcSlice->getInvCodedScale ()[ uiId ] + pcSlice->getCodedScale ()[ uiId ], "inverse_coded_scale_plus_coded_scale" );
1042        WRITE_SVLC( pcSlice->getInvCodedOffset()[ uiId ] + pcSlice->getCodedOffset()[ uiId ], "inverse_coded_offset_plus_coded_offset" );
1043      }
1044    }
[2]1045  }
[56]1046 
1047#if ( HHI_MPI || HHI_INTER_VIEW_MOTION_PRED )
1048  #if ( HHI_MPI && HHI_INTER_VIEW_MOTION_PRED )
1049  const int iExtraMergeCandidates = ( pcSlice->getSPS()->getUseMVI() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0;
1050  #elif HHI_MPI
1051  const int iExtraMergeCandidates = pcSlice->getSPS()->getUseMVI() ? 1 : 0;
1052  #else
1053  const int iExtraMergeCandidates = pcSlice->getSPS()->getMultiviewMvPredMode() ? 1 : 0;
1054  #endif
1055  assert(pcSlice->getMaxNumMergeCand()<=(MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates));
1056  assert(MRG_MAX_NUM_CANDS_SIGNALED<=MRG_MAX_NUM_CANDS);
1057  WRITE_UVLC(MRG_MAX_NUM_CANDS + iExtraMergeCandidates - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand");
[2]1058#else
[56]1059  assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS_SIGNALED);
1060  assert(MRG_MAX_NUM_CANDS_SIGNALED<=MRG_MAX_NUM_CANDS);
1061  WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "maxNumMergeCand");
[2]1062#endif
1063}
1064
1065
[56]1066Void TEncCavlc::codeTileMarkerFlag(TComSlice* pcSlice) 
[2]1067{
[56]1068  Bool bEntropySlice = (!pcSlice->isNextSlice());
1069  if (!bEntropySlice)
1070  {
1071    xWriteFlag  (pcSlice->getTileMarkerFlag() ? 1 : 0 );
1072  }
[2]1073}
1074
[56]1075/**
1076 - write wavefront substreams sizes for the slice header.
1077 .
1078 \param pcSlice Where we find the substream size information.
1079 */
1080#if TILES_WPP_ENTRY_POINT_SIGNALLING
1081Void  TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice )
[2]1082{
[56]1083  Int tilesOrEntropyCodingSyncIdc = pSlice->getSPS()->getTilesOrEntropyCodingSyncIdc();
[2]1084
[56]1085  if ( tilesOrEntropyCodingSyncIdc == 0 )
[2]1086  {
[56]1087    return;
[2]1088  }
1089
[56]1090  UInt numEntryPointOffsets = 0, offsetLenMinus1 = 0, maxOffset = 0;
1091  UInt *entryPointOffset = NULL;
1092  if (tilesOrEntropyCodingSyncIdc == 1) // tiles
[2]1093  {
[56]1094    numEntryPointOffsets = pSlice->getTileLocationCount();
1095    entryPointOffset     = new UInt[numEntryPointOffsets];
1096    for (Int idx=0; idx<pSlice->getTileLocationCount(); idx++)
[2]1097    {
[56]1098      if ( idx == 0 )
[2]1099      {
[56]1100        entryPointOffset [ idx ] = pSlice->getTileLocation( 0 );
[2]1101      }
[56]1102      else
[2]1103      {
[56]1104        entryPointOffset [ idx ] = pSlice->getTileLocation( idx ) - pSlice->getTileLocation( idx-1 );
[2]1105      }
1106
[56]1107      if ( entryPointOffset[ idx ] > maxOffset )
1108      {
1109        maxOffset = entryPointOffset[ idx ];
1110      }
[2]1111    }
1112  }
[56]1113  else if (tilesOrEntropyCodingSyncIdc == 2) // wavefront
[2]1114  {
[56]1115    Int  numZeroSubstreamsAtEndOfSlice  = 0;
1116    UInt* pSubstreamSizes               = pSlice->getSubstreamSizes();
1117    // Find number of zero substreams at the end of slice
1118    for (Int idx=pSlice->getPPS()->getNumSubstreams()-2; idx>=0; idx--)
[2]1119    {
[56]1120      if ( pSubstreamSizes[ idx ] ==  0 )
[2]1121      {
[56]1122        numZeroSubstreamsAtEndOfSlice++; 
[2]1123      }
[56]1124      else
[2]1125      {
[56]1126        break;
[2]1127      }
1128    }
[56]1129    numEntryPointOffsets       = pSlice->getPPS()->getNumSubstreams() - 1 - numZeroSubstreamsAtEndOfSlice;
1130    entryPointOffset           = new UInt[numEntryPointOffsets];
1131    for (Int idx=0; idx<numEntryPointOffsets; idx++)
[2]1132    {
[56]1133      entryPointOffset[ idx ] = ( pSubstreamSizes[ idx ] >> 3 ) ;
1134      if ( entryPointOffset[ idx ] > maxOffset )
[2]1135      {
[56]1136        maxOffset = entryPointOffset[ idx ];
[2]1137      }
1138    }
[56]1139  }
[2]1140
[56]1141  maxOffset += ((m_pcBitIf->getNumberOfWrittenBits() + 16) >> 3) + 8 + 2; // allowing for NALU header, slice header, bytes added for "offset_len_minus1" and "num_entry_point_offsets"
[2]1142
[56]1143  // Determine number of bits "offsetLenMinus1+1" required for entry point information
1144  offsetLenMinus1 = 0;
1145  while (1)
1146  {
1147    if (maxOffset >= (1 << offsetLenMinus1) )
1148    {
1149      offsetLenMinus1++;
1150      if ( offsetLenMinus1 > 32 )
[2]1151      {
[56]1152        FATAL_ERROR_0("exceeded 32-bits", -1);
[2]1153      }
1154    }
[56]1155    else
[2]1156    {
[56]1157      break;
[2]1158    }
1159  }
1160
[56]1161  WRITE_UVLC(numEntryPointOffsets, "num_entry_point_offsets");
1162  if (numEntryPointOffsets>0)
[2]1163  {
[56]1164    WRITE_UVLC(offsetLenMinus1, "offset_len_minus1");
[2]1165  }
[56]1166
1167  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
[2]1168  {
[56]1169    if ( idx == 0 )
1170    {
1171      // Adding sizes of NALU header and slice header information to entryPointOffset[ 0 ]
1172      Int bitDistFromNALUHdrStart    = m_pcBitIf->getNumberOfWrittenBits() + 16;
1173      entryPointOffset[ idx ] += ( bitDistFromNALUHdrStart + numEntryPointOffsets*(offsetLenMinus1+1) ) >> 3;
1174    }
1175    WRITE_CODE(entryPointOffset[ idx ], offsetLenMinus1+1, "entry_point_offset");
[2]1176  }
1177
[56]1178  delete [] entryPointOffset;
[2]1179}
[56]1180#else
1181Void TEncCavlc::codeSliceHeaderSubstreamTable( TComSlice* pcSlice )
1182{
1183  UInt uiNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
1184  UInt*puiSubstreamSizes = pcSlice->getSubstreamSizes();
[2]1185
[56]1186  // Write header information for all substreams except the last.
1187  for (UInt ui = 0; ui+1 < uiNumSubstreams; ui++)
[2]1188  {
[56]1189    UInt uiNumbits = puiSubstreamSizes[ui];
[2]1190
[56]1191    //the 2 first bits are used to give the size of the header
1192    if ( uiNumbits < (1<<8) )
[2]1193    {
[56]1194      xWriteCode(0,         2  );
1195      xWriteCode(uiNumbits, 8  );
[2]1196    }
[56]1197    else if ( uiNumbits < (1<<16) )
1198    {
1199      xWriteCode(1,         2  );
1200      xWriteCode(uiNumbits, 16 );
1201    }
1202    else if ( uiNumbits < (1<<24) )
1203    {
1204      xWriteCode(2,         2  );
1205      xWriteCode(uiNumbits, 24 );
1206    }
1207    else if ( uiNumbits < (1<<31) )
1208    {
1209      xWriteCode(3,         2  );
1210      xWriteCode(uiNumbits, 32 );
1211    }
1212    else
1213    {
1214      printf("Error in codeSliceHeaderTable\n");
1215      exit(-1);
1216    }
[2]1217  }
1218}
[56]1219#endif
[2]1220
[56]1221Void TEncCavlc::codeTerminatingBit      ( UInt uilsLast )
[2]1222{
[56]1223}
[2]1224
[56]1225Void TEncCavlc::codeSliceFinish ()
1226{
1227}
[2]1228
[56]1229#if HHI_INTER_VIEW_MOTION_PRED
1230Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum )
[2]1231#else
[56]1232Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
[2]1233#endif
[56]1234{
1235  assert(0);
1236}
[2]1237
[56]1238Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1239{
1240  assert(0);
1241}
[2]1242
[56]1243Void TEncCavlc::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx )
1244{
1245  assert(0);
1246}
[2]1247
[56]1248Void TEncCavlc::codeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx )
1249{
1250  assert(0);
1251}
[2]1252
[56]1253Void TEncCavlc::codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx )
1254{
1255  assert(0);
1256}
[2]1257
[56]1258#if HHI_INTER_VIEW_RESIDUAL_PRED
1259Void
1260TEncCavlc::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
1261{
1262  assert(0);
1263}
[2]1264#endif
1265
[56]1266Void TEncCavlc::codeAlfCtrlFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
1267{ 
1268  if (!m_bAlfCtrl)
1269  {
1270    return;
[2]1271  }
[56]1272 
1273  if( pcCU->getDepth(uiAbsPartIdx) > m_uiMaxAlfCtrlDepth && !pcCU->isFirstAbsZorderIdxInDepth(uiAbsPartIdx, m_uiMaxAlfCtrlDepth))
1274  {
1275    return;
1276  }
1277 
1278  // get context function is here
1279  UInt uiSymbol = pcCU->getAlfCtrlFlag( uiAbsPartIdx ) ? 1 : 0;
1280 
1281  xWriteFlag( uiSymbol );
1282}
[2]1283
[56]1284Void TEncCavlc::codeApsExtensionFlag ()
1285{
1286  WRITE_FLAG(0, "aps_extension_flag");
[2]1287}
1288
[56]1289Void TEncCavlc::codeAlfCtrlDepth()
1290{ 
1291  if (!m_bAlfCtrl)
[2]1292  {
[56]1293    return;
[2]1294  }
[56]1295 
1296  UInt uiDepth = m_uiMaxAlfCtrlDepth;
1297 
1298  xWriteUvlc(uiDepth);
1299}
[2]1300
[56]1301Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode )
1302{
1303  assert(0);
1304}
[2]1305
[56]1306Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
1307{
1308  assert(0);
1309}
[2]1310
[56]1311Void TEncCavlc::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
1312{
1313  assert(0);
1314}
[2]1315
[56]1316Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx )
1317{
1318  assert(0);
1319}
[2]1320
[56]1321Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
1322{
1323  assert(0);
1324}
[2]1325
[56]1326Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx )
1327{
1328  assert(0);
1329}
[2]1330
[56]1331#if BURST_IPCM
1332/** Code I_PCM information.
1333 * \param pcCU pointer to CU
1334 * \param uiAbsPartIdx CU index
1335 * \param numIPCM the number of succesive IPCM blocks with the same size
1336 * \param firstIPCMFlag
1337 * \returns Void
1338 */
1339Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag)
1340{
1341  assert(0);
1342}
[2]1343#else
[56]1344/** Code I_PCM information.
1345 * \param pcCU pointer to CU
1346 * \param uiAbsPartIdx CU index
1347 * \returns Void
1348 *
1349 * If I_PCM flag indicates that the CU is I_PCM, code its PCM alignment bits and codes. 
1350 */
1351Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx)
1352{
1353  UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0;
[2]1354
[56]1355  xWriteFlag(uiIPCM);
[2]1356
[56]1357  if (uiIPCM)
[2]1358  {
[56]1359    xWritePCMAlignZero();
[2]1360
[56]1361    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
1362    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
1363    UInt uiChromaOffset = uiLumaOffset>>2;
[2]1364
[56]1365    Pel* piPCMSample;
1366    UInt uiWidth;
1367    UInt uiHeight;
1368    UInt uiSampleBits;
1369    UInt uiX, uiY;
[2]1370
[56]1371    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
1372    uiWidth = pcCU->getWidth(uiAbsPartIdx);
1373    uiHeight = pcCU->getHeight(uiAbsPartIdx);
1374    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
1375
1376    for(uiY = 0; uiY < uiHeight; uiY++)
[2]1377    {
[56]1378      for(uiX = 0; uiX < uiWidth; uiX++)
[2]1379      {
[56]1380        UInt uiSample = piPCMSample[uiX];
1381
1382        xWriteCode(uiSample, uiSampleBits);
[2]1383      }
[56]1384      piPCMSample += uiWidth;
[2]1385    }
1386
[56]1387    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
1388    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
1389    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
1390    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1391
1392    for(uiY = 0; uiY < uiHeight; uiY++)
[2]1393    {
[56]1394      for(uiX = 0; uiX < uiWidth; uiX++)
[2]1395      {
[56]1396        UInt uiSample = piPCMSample[uiX];
1397
1398        xWriteCode(uiSample, uiSampleBits);
[2]1399      }
[56]1400      piPCMSample += uiWidth;
[2]1401    }
1402
[56]1403    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
1404    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
1405    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
1406    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
1407
1408    for(uiY = 0; uiY < uiHeight; uiY++)
[2]1409    {
[56]1410      for(uiX = 0; uiX < uiWidth; uiX++)
1411      {
1412        UInt uiSample = piPCMSample[uiX];
1413
1414        xWriteCode(uiSample, uiSampleBits);
1415      }
1416      piPCMSample += uiWidth;
[2]1417    }
[56]1418  }
1419}
[2]1420#endif
1421
[56]1422Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
1423{
1424  assert(0);
1425}
[2]1426
[56]1427Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx )
1428{
1429  assert(0);
[2]1430}
1431
[56]1432Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx )
[2]1433{
[56]1434  assert(0);
1435}
[2]1436
[56]1437Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
1438{
1439  assert(0);
[2]1440}
1441
[56]1442Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )
[2]1443{
[56]1444  assert(0);
[2]1445}
1446
[56]1447Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx )
1448{
1449  Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
1450
1451#if H0736_AVC_STYLE_QP_RANGE
1452  Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
1453  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
1454#endif
1455
1456  xWriteSvlc( iDQp );
1457 
1458  return;
1459}
1460
1461Void TEncCavlc::codeCoeffNxN    ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
1462{
1463  assert(0);
1464}
1465
1466Void TEncCavlc::codeAlfFlag( UInt uiCode )
1467{ 
1468  xWriteFlag( uiCode );
1469}
1470
[2]1471Void TEncCavlc::codeAlfCtrlFlag( UInt uiSymbol )
1472{
1473  xWriteFlag( uiSymbol );
1474}
1475
1476Void TEncCavlc::codeAlfUvlc( UInt uiCode )
1477{
1478  xWriteUvlc( uiCode );
1479}
1480
1481Void TEncCavlc::codeAlfSvlc( Int iCode )
1482{
1483  xWriteSvlc( iCode );
1484}
[56]1485#if LCU_SYNTAX_ALF
1486/** Code the fixed length code (smaller than one max value) in OSALF
1487 * \param idx:  coded value
1488 * \param maxValue: max value
1489 */
1490Void TEncCavlc::codeAlfFixedLengthIdx( UInt idx, UInt maxValue)
[2]1491{
[56]1492  UInt length = 0;
1493  assert(idx<=maxValue);
[2]1494
[56]1495  UInt temp = maxValue;
1496  for(UInt i=0; i<32; i++)
1497  {
1498    if(temp&0x1)
1499    {
1500      length = i+1;
1501    }
1502    temp = (temp >> 1);
1503  }
1504
1505  if(length)
1506  {
1507    xWriteCode( idx, length );
1508  }
1509}
1510#endif
1511
1512Void TEncCavlc::codeSaoFlag( UInt uiCode )
1513{
[2]1514  xWriteFlag( uiCode );
1515}
1516
[56]1517Void TEncCavlc::codeSaoUvlc( UInt uiCode )
[2]1518{
1519    xWriteUvlc( uiCode );
1520}
1521
[56]1522Void TEncCavlc::codeSaoSvlc( Int iCode )
[2]1523{
1524    xWriteSvlc( iCode );
1525}
[56]1526#if SAO_UNIT_INTERLEAVING
1527/** Code SAO run.
1528 * \param uiCode
1529 * \param maxValue
1530 */
1531Void TEncCavlc::codeSaoRun( UInt uiCode, UInt maxValue)
1532{
1533  UInt uiLength = 0;
1534  if (!maxValue)
1535  {
1536    return;
1537  }
1538  assert(uiCode<=maxValue);             
[2]1539
[56]1540  for(UInt i=0; i<32; i++)                                     
1541  {                                                           
1542    if(maxValue&0x1)                                               
1543    {                                                         
1544      uiLength = i+1;                                         
1545    }                                                         
1546    maxValue = (maxValue >> 1);                                       
1547  }
1548  WRITE_CODE( uiCode, uiLength, "sao_run_diff");
1549}
[2]1550#endif
1551
[56]1552Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
[2]1553{
1554  // printf("error : no VLC mode support in this version\n");
1555  return;
1556}
1557
1558// ====================================================================================================================
1559// Protected member functions
1560// ====================================================================================================================
1561
1562Void TEncCavlc::xWriteCode     ( UInt uiCode, UInt uiLength )
1563{
1564  assert ( uiLength > 0 );
1565  m_pcBitIf->write( uiCode, uiLength );
1566}
1567
1568Void TEncCavlc::xWriteUvlc     ( UInt uiCode )
1569{
1570  UInt uiLength = 1;
1571  UInt uiTemp = ++uiCode;
[56]1572 
[2]1573  assert ( uiTemp );
[56]1574 
[2]1575  while( 1 != uiTemp )
1576  {
1577    uiTemp >>= 1;
1578    uiLength += 2;
1579  }
[56]1580 
1581  //m_pcBitIf->write( uiCode, uiLength );
1582  // Take care of cases where uiLength > 32
1583  m_pcBitIf->write( 0, uiLength >> 1);
1584  m_pcBitIf->write( uiCode, (uiLength+1) >> 1);
[2]1585}
1586
1587Void TEncCavlc::xWriteSvlc     ( Int iCode )
1588{
1589  UInt uiCode;
[56]1590 
[2]1591  uiCode = xConvertToUInt( iCode );
1592  xWriteUvlc( uiCode );
1593}
1594
1595Void TEncCavlc::xWriteFlag( UInt uiCode )
1596{
1597  m_pcBitIf->write( uiCode, 1 );
1598}
1599
[56]1600/** Write PCM alignment bits.
1601 * \returns Void
1602 */
1603Void  TEncCavlc::xWritePCMAlignZero    ()
[2]1604{
[56]1605  m_pcBitIf->writeAlignZero();
[2]1606}
1607
1608Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol )
1609{
1610  if (uiMaxSymbol == 0)
1611  {
1612    return;
1613  }
1614  xWriteFlag( uiSymbol ? 1 : 0 );
1615  if ( uiSymbol == 0 )
1616  {
1617    return;
1618  }
[56]1619 
[2]1620  Bool bCodeLast = ( uiMaxSymbol > uiSymbol );
[56]1621 
[2]1622  while( --uiSymbol )
1623  {
1624    xWriteFlag( 1 );
1625  }
1626  if( bCodeLast )
1627  {
1628    xWriteFlag( 0 );
1629  }
1630  return;
1631}
1632
1633Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol )
1634{
1635  if( uiSymbol )
1636  {
1637    xWriteFlag( 1 );
1638    UInt uiCount = 0;
1639    Bool bNoExGo = (uiSymbol < 13);
[56]1640   
[2]1641    while( --uiSymbol && ++uiCount < 13 )
1642    {
1643      xWriteFlag( 1 );
1644    }
1645    if( bNoExGo )
1646    {
1647      xWriteFlag( 0 );
1648    }
1649    else
1650    {
1651      xWriteEpExGolomb( uiSymbol, 0 );
1652    }
1653  }
1654  else
1655  {
1656    xWriteFlag( 0 );
1657  }
1658  return;
1659}
1660
1661Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount )
1662{
1663  while( uiSymbol >= (UInt)(1<<uiCount) )
1664  {
1665    xWriteFlag( 1 );
1666    uiSymbol -= 1<<uiCount;
1667    uiCount  ++;
1668  }
1669  xWriteFlag( 0 );
1670  while( uiCount-- )
1671  {
1672    xWriteFlag( (uiSymbol>>uiCount) & 1 );
1673  }
1674  return;
1675}
1676
[56]1677/** code explicit wp tables
1678 * \param TComSlice* pcSlice
1679 * \returns Void
[2]1680 */
[56]1681Void TEncCavlc::xCodePredWeightTable( TComSlice* pcSlice )
[2]1682{
[56]1683  wpScalingParam  *wp;
1684  Bool            bChroma     = true; // color always present in HEVC ?
1685  Int             iNbRef       = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1);
1686  Bool            bDenomCoded  = false;
[2]1687
[56]1688  UInt            uiMode = 0;
1689  if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()==0 ) )
1690    uiMode = 1; // explicit
1691  else if ( pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==2 )
1692    uiMode = 2; // implicit (does not use this mode in this syntax)
1693  if (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag())
1694    uiMode = 3; // combined explicit
1695  if(uiMode == 1)
[2]1696  {
[56]1697    for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
[2]1698    {
[56]1699      RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
1700      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
[2]1701      {
[56]1702        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
1703        if ( !bDenomCoded ) 
[2]1704        {
[56]1705          Int iDeltaDenom;
1706          WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
[2]1707
[56]1708          if( bChroma )
[2]1709          {
[56]1710            iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom);
1711            WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );       // se(v): delta_chroma_log2_weight_denom
[2]1712          }
[56]1713          bDenomCoded = true;
1714        }
[2]1715
[56]1716        WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lX_flag" );               // u(1): luma_weight_lX_flag
[2]1717
[56]1718        if ( wp[0].bPresentFlag ) 
1719        {
1720          Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom));
1721          WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lX" );                  // se(v): delta_luma_weight_lX
1722          WRITE_SVLC( wp[0].iOffset, "luma_offset_lX" );                       // se(v): luma_offset_lX
1723        }
[2]1724
[56]1725        if ( bChroma ) 
1726        {
1727          WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" );           // u(1): chroma_weight_lX_flag
[2]1728
[56]1729          if ( wp[1].bPresentFlag )
[2]1730          {
[56]1731            for ( Int j=1 ; j<3 ; j++ ) 
[2]1732            {
[56]1733              Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom));
1734              WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );            // se(v): delta_chroma_weight_lX
1735
1736              Int iDeltaChroma = (wp[j].iOffset + ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) - (g_uiIBDI_MAX>>1));
1737              WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );            // se(v): delta_chroma_offset_lX
[2]1738            }
1739          }
1740        }
1741      }
1742    }
1743  }
[56]1744  else if (uiMode == 3)
[2]1745  {
[56]1746    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ ) 
1747    {
1748      RefPicList  eRefPicList = (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIdx);
1749      Int iCombRefIdx = pcSlice->getRefIdxFromIdxOfLC(iRefIdx);
[2]1750
[56]1751      pcSlice->getWpScaling(eRefPicList, iCombRefIdx, wp);
1752      if ( !bDenomCoded ) 
[2]1753      {
[56]1754        Int iDeltaDenom;
1755        WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" );       // ue(v): luma_log2_weight_denom
1756
1757        if( bChroma )
1758        {
1759          iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom);
1760          WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );         // se(v): delta_chroma_log2_weight_denom
1761        }
1762        bDenomCoded = true;
[2]1763      }
1764
[56]1765      WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lc_flag" );                 // u(1): luma_weight_lc_flag
[2]1766
[56]1767      if ( wp[0].bPresentFlag ) 
1768      {
1769        Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom));
1770        WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lc" );                    // se(v): delta_luma_weight_lc
1771        WRITE_SVLC( wp[0].iOffset, "luma_offset_lc" );                         // se(v): luma_offset_lc
1772      }
1773      if ( bChroma ) 
1774      {
1775        WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lc_flag" );             // u(1): luma_weight_lc_flag
[2]1776
[56]1777        if ( wp[1].bPresentFlag )
1778        {
1779          for ( Int j=1 ; j<3 ; j++ ) 
1780          {
1781            Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom));
1782            WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lc" );              // se(v): delta_chroma_weight_lc
[2]1783
[56]1784            Int iDeltaChroma = (wp[j].iOffset + ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) - (g_uiIBDI_MAX>>1));
1785            WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lc" );              // se(v): delta_chroma_offset_lc
1786          }
1787        }
1788      }
[2]1789    }
1790  }
[56]1791}
[2]1792
[56]1793/** code quantization matrix
1794 *  \param scalingList quantization matrix information
1795 */
1796Void TEncCavlc::codeScalingList( TComScalingList* scalingList )
1797{
1798  UInt listId,sizeId;
1799  Bool scalingListPredModeFlag;
[2]1800
[56]1801#if SCALING_LIST_OUTPUT_RESULT
1802  Int startBit;
1803  Int startTotalBit;
1804  startBit = m_pcBitIf->getNumberOfWrittenBits();
1805  startTotalBit = m_pcBitIf->getNumberOfWrittenBits();
[2]1806#endif
1807
[56]1808  WRITE_FLAG( scalingList->getScalingListPresentFlag (), "scaling_list_present_flag" );
1809
1810  if(scalingList->getScalingListPresentFlag () == false)
[2]1811  {
[56]1812#if SCALING_LIST_OUTPUT_RESULT
1813    printf("Header Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startBit);
[2]1814#endif
[56]1815    //for each size
1816    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
[2]1817    {
[56]1818      for(listId = 0; listId < g_scalingListNum[sizeId]; listId++)
[2]1819      {
[56]1820#if SCALING_LIST_OUTPUT_RESULT
1821        startBit = m_pcBitIf->getNumberOfWrittenBits();
[2]1822#endif
[56]1823        scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
1824        WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
1825        if(!scalingListPredModeFlag)// Copy Mode
[2]1826        {
[56]1827          WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId) - 1, "scaling_list_pred_matrix_id_delta");
[2]1828        }
[56]1829        else// DPCM Mode
[2]1830        {
[56]1831          xCodeScalingList(scalingList, sizeId, listId);
[2]1832        }
[56]1833#if SCALING_LIST_OUTPUT_RESULT
1834        printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit);
[2]1835#endif
1836      }
1837    }
1838  }
[56]1839#if SCALING_LIST_OUTPUT_RESULT
1840  else
[2]1841  {
[56]1842    printf("Header Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
[2]1843  }
[56]1844  printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
1845#endif
[2]1846  return;
1847}
[56]1848/** code DPCM
1849 * \param scalingList quantization matrix information
1850 * \param sizeIdc size index
1851 * \param listIdc list index
1852 */
1853Void TEncCavlc::xCodeScalingList(TComScalingList* scalingList, UInt sizeId, UInt listId)
[2]1854{
[56]1855#if SCALING_LIST
1856  Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
1857  UInt* scan    = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2];
[2]1858#else
[56]1859  Int coefNum = (Int)g_scalingListSize[sizeId];
1860  UInt* scan    = g_auiFrameScanXY [ sizeId + 1];
[2]1861#endif
[56]1862  Int nextCoef = SCALING_LIST_START_VALUE;
1863  Int data;
1864  Int *src = scalingList->getScalingListAddress(sizeId, listId);
1865#if SCALING_LIST
1866  if(sizeId > SCALING_LIST_8x8 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
[2]1867  {
[56]1868    WRITE_SVLC( -8, "scaling_list_dc_coef_minus8");
[2]1869  }
[56]1870  else if(sizeId < SCALING_LIST_16x16 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
[2]1871  {
[56]1872    WRITE_SVLC( -8, "scaling_list_delta_coef");
[2]1873  }
[56]1874  else
[2]1875  {
[56]1876    if( sizeId > SCALING_LIST_8x8 )
[2]1877    {
[56]1878      WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
[2]1879    }
[56]1880    for(Int i=0;i<coefNum;i++)
[2]1881    {
[56]1882      data = src[scan[i]] - nextCoef;
1883      nextCoef = src[scan[i]];
1884      if(data > 127)
[2]1885      {
[56]1886        data = data - 256;
[2]1887      }
[56]1888      if(data < -128)
[2]1889      {
[56]1890        data = data + 256;
[2]1891      }
1892
[56]1893      WRITE_SVLC( data,  "scaling_list_delta_coef");
[2]1894    }
1895  }
[56]1896#else
1897  for(Int i=0;i<coefNum;i++)
[2]1898  {
[56]1899    data = src[scan[i]] - nextCoef;
1900    nextCoef = src[scan[i]];
1901    if(data > 127)
[2]1902    {
[56]1903      data = data - 256;
[2]1904    }
[56]1905    if(data < -128)
[2]1906    {
[56]1907      data = data + 256;
[2]1908    }
[56]1909
1910    WRITE_SVLC( data,  "delta_coef");
[2]1911  }
[56]1912#endif
[2]1913}
[56]1914Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId)
1915{
1916  for(Int predListIdx = (Int)listId -1 ; predListIdx >= 0; predListIdx--)
1917  {
1918#if SCALING_LIST
1919    if( !memcmp(getScalingListAddress(sizeId,listId),getScalingListAddress(sizeId, predListIdx),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
1920     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value
1921#else
1922    if( !memcmp(getScalingListAddress(sizeId,listId),getScalingListAddress(sizeId, predListIdx),sizeof(Int)*(Int)g_scalingListSize[sizeId])) // check value of matrix
[2]1923#endif
[56]1924    {
1925      setRefMatrixId(sizeId, listId, predListIdx);
1926      return false;
[2]1927    }
1928  }
[56]1929  return true;
[2]1930}
[56]1931//! \}
Note: See TracBrowser for help on using the repository browser.