source: 3DVCSoftware/branches/HTM-4.1-dev2-RWTH/source/Lib/TLibDecoder/TDecCAVLC.cpp @ 630

Last change on this file since 630 was 177, checked in by rwth, 13 years ago
  • added RWTH_B0036 (SDC+DLT)
  • Property svn:eol-style set to native
File size: 102.1 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-2012, 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
47#define READ_CODE(length, code, name)     xReadCodeTr ( length, code, name )
48#define READ_UVLC(        code, name)     xReadUvlcTr (         code, name )
49#define READ_SVLC(        code, name)     xReadSvlcTr (         code, name )
50#define READ_FLAG(        code, name)     xReadFlagTr (         code, name )
51
52Void  xTraceSPSHeader (TComSPS *pSPS)
53{
54  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
55}
56
57Void  xTracePPSHeader (TComPPS *pPPS)
58{
59  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
60}
61
62Void  xTraceAPSHeader (TComAPS *pAPS)
63{
64  fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
65}
66
67Void  xTraceSliceHeader (TComSlice *pSlice)
68{
69  fprintf( g_hTrace, "=========== Slice ===========\n");
70}
71
72
73Void  TDecCavlc::xReadCodeTr           (UInt length, UInt& rValue, const Char *pSymbolName)
74{
75  xReadCode (length, rValue);
76  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
77  fprintf( g_hTrace, "%-40s u(%d) : %d\n", pSymbolName, length, rValue ); 
78  fflush ( g_hTrace );
79}
80
81Void  TDecCavlc::xReadUvlcTr           (UInt& rValue, const Char *pSymbolName)
82{
83  xReadUvlc (rValue);
84  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
85  fprintf( g_hTrace, "%-40s u(v) : %d\n", pSymbolName, rValue ); 
86  fflush ( g_hTrace );
87}
88
89Void  TDecCavlc::xReadSvlcTr           (Int& rValue, const Char *pSymbolName)
90{
91  xReadSvlc(rValue);
92  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
93  fprintf( g_hTrace, "%-40s s(v) : %d\n", pSymbolName, rValue ); 
94  fflush ( g_hTrace );
95}
96
97Void  TDecCavlc::xReadFlagTr           (UInt& rValue, const Char *pSymbolName)
98{
99  xReadFlag(rValue);
100  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
101  fprintf( g_hTrace, "%-40s u(1) : %d\n", pSymbolName, rValue ); 
102  fflush ( g_hTrace );
103}
104
105#else
106
107#define READ_CODE(length, code, name)     xReadCode ( length, code )
108#define READ_UVLC(        code, name)     xReadUvlc (         code )
109#define READ_SVLC(        code, name)     xReadSvlc (         code )
110#define READ_FLAG(        code, name)     xReadFlag (         code )
111
112#endif
113
114
115
116// ====================================================================================================================
117// Constructor / destructor / create / destroy
118// ====================================================================================================================
119
120TDecCavlc::TDecCavlc()
121{
122  m_iSliceGranularity = 0;
123
124  m_aaiTempScale            = new Int* [ MAX_VIEW_NUM ];
125  m_aaiTempOffset           = new Int* [ MAX_VIEW_NUM ];
126  m_aaiTempPdmScaleNomDelta = new Int* [ MAX_VIEW_NUM ];
127  m_aaiTempPdmOffset        = new Int* [ MAX_VIEW_NUM ];
128  for( UInt uiVId = 0; uiVId < MAX_VIEW_NUM; uiVId++ )
129  {
130    m_aaiTempScale            [ uiVId ] = new Int [ MAX_VIEW_NUM ];
131    m_aaiTempOffset           [ uiVId ] = new Int [ MAX_VIEW_NUM ];
132    m_aaiTempPdmScaleNomDelta [ uiVId ] = new Int [ MAX_VIEW_NUM ];
133    m_aaiTempPdmOffset        [ uiVId ] = new Int [ MAX_VIEW_NUM ];
134  }
135}
136
137TDecCavlc::~TDecCavlc()
138{
139  for( UInt uiVId = 0; uiVId < MAX_VIEW_NUM; uiVId++ )
140  {
141    delete [] m_aaiTempScale            [ uiVId ];
142    delete [] m_aaiTempOffset           [ uiVId ];
143    delete [] m_aaiTempPdmScaleNomDelta [ uiVId ];
144    delete [] m_aaiTempPdmOffset        [ uiVId ];
145  }
146  delete [] m_aaiTempScale;
147  delete [] m_aaiTempOffset;
148  delete [] m_aaiTempPdmScaleNomDelta;
149  delete [] m_aaiTempPdmOffset;
150}
151
152// ====================================================================================================================
153// Public member functions
154// ====================================================================================================================
155
156/**
157 * unmarshal a sequence of SEI messages from bitstream.
158 */
159void TDecCavlc::parseSEI(SEImessages& seis)
160{
161  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
162  do
163  {
164    parseSEImessage(*m_pcBitstream, seis);
165    /* SEI messages are an integer number of bytes, something has failed
166     * in the parsing if bitstream not byte-aligned */
167    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
168  } while (0x80 != m_pcBitstream->peekBits(8));
169  assert(m_pcBitstream->getNumBitsLeft() == 8); /* rsbp_trailing_bits */
170}
171#if RPS_IN_SPS
172void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
173#else
174void TDecCavlc::parseShortTermRefPicSet( TComPPS* pcPPS, TComReferencePictureSet* rps, Int idx )
175#endif
176{
177  UInt code;
178  UInt interRPSPred;
179  READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
180  if (interRPSPred) 
181  {
182    UInt bit;
183    READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
184    Int rIdx =  idx - 1 - code;
185    assert (rIdx <= idx && rIdx >= 0);
186#if RPS_IN_SPS
187    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
188#else
189    TComReferencePictureSet*   rpsRef = pcPPS->getRPSList()->getReferencePictureSet(rIdx);
190#endif
191    Int k = 0, k0 = 0, k1 = 0;
192    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
193    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
194    Int deltaRPS = (1 - (bit<<1)) * (code + 1); // delta_RPS
195    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
196    {
197      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
198      Int refIdc = bit;
199      if (refIdc == 0) 
200      {
201        READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
202        refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0.
203      }
204      if (refIdc == 1 || refIdc == 2)
205      {
206        Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0);
207        rps->setDeltaPOC(k, deltaPOC);
208        rps->setUsed(k, (refIdc == 1));
209
210        if (deltaPOC < 0) {
211          k0++;
212        }
213        else 
214        {
215          k1++;
216        }
217        k++;
218      } 
219      rps->setRefIdc(j,refIdc); 
220    }
221    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); 
222    rps->setNumberOfPictures(k);
223    rps->setNumberOfNegativePictures(k0);
224    rps->setNumberOfPositivePictures(k1);
225    rps->sortDeltaPOC();
226  }
227  else
228  {
229    READ_UVLC(code, "num_negative_pics");           rps->setNumberOfNegativePictures(code);
230    READ_UVLC(code, "num_positive_pics");           rps->setNumberOfPositivePictures(code);
231    Int prev = 0;
232    Int poc;
233    for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++)
234    {
235      READ_UVLC(code, "delta_poc_s0_minus1");
236      poc = prev-code-1;
237      prev = poc;
238      rps->setDeltaPOC(j,poc);
239      READ_FLAG(code, "used_by_curr_pic_s0_flag");  rps->setUsed(j,code);
240    }
241    prev = 0;
242    for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++)
243    {
244      READ_UVLC(code, "delta_poc_s1_minus1");
245      poc = prev+code+1;
246      prev = poc;
247      rps->setDeltaPOC(j,poc);
248      READ_FLAG(code, "used_by_curr_pic_s1_flag");  rps->setUsed(j,code);
249    }
250    rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures());
251  }
252#if PRINT_RPS_INFO
253  rps->printDeltaPOC();
254#endif
255}
256
257Void TDecCavlc::parseAPS(TComAPS* aps)
258{
259#if ENC_DEC_TRACE 
260  xTraceAPSHeader(aps);
261#endif
262
263  UInt uiCode;
264  READ_UVLC(uiCode, "aps_id");                             aps->setAPSID(uiCode);
265  READ_FLAG(uiCode, "aps_scaling_list_data_present_flag"); aps->setScalingListEnabled( (uiCode==1)?true:false );
266  READ_FLAG(uiCode, "aps_deblocking_filter_flag");         aps->setLoopFilterOffsetInAPS( (uiCode==1)?true:false );
267#if !SAO_UNIT_INTERLEAVING
268  READ_FLAG(uiCode, "aps_sample_adaptive_offset_flag");    aps->setSaoEnabled( (uiCode==1)?true:false );
269#endif
270#if !LCU_SYNTAX_ALF
271  READ_FLAG(uiCode, "aps_adaptive_loop_filter_flag");      aps->setAlfEnabled( (uiCode==1)?true:false );
272#endif
273  if(aps->getScalingListEnabled())
274  {
275    parseScalingList( aps->getScalingList() );
276  }
277#if DBL_CONTROL
278  if(aps->getLoopFilterOffsetInAPS())
279  {
280    xParseDblParam( aps );   
281  }
282#endif
283#if SAO_UNIT_INTERLEAVING
284  READ_FLAG(uiCode, "aps_sao_interleaving_flag");      aps->setSaoInterleavingFlag( (uiCode==1)?true:false );
285  if(!aps->getSaoInterleavingFlag())
286  {
287    READ_FLAG(uiCode, "aps_sample_adaptive_offset_flag");      aps->setSaoEnabled( (uiCode==1)?true:false );
288#endif
289  if(aps->getSaoEnabled())
290  {
291    aps->getSaoParam()->bSaoFlag[0] = true;
292    xParseSaoParam( aps->getSaoParam() );
293  }
294#if SAO_UNIT_INTERLEAVING
295  }
296#endif
297#if LCU_SYNTAX_ALF
298  READ_FLAG(uiCode, "aps_adaptive_loop_filter_flag");      aps->setAlfEnabled( (uiCode==1)?true:false );
299#endif
300  if(aps->getAlfEnabled())
301  {
302#if !LCU_SYNTAX_ALF
303    aps->getAlfParam()->alf_flag = 1;
304#endif
305    xParseAlfParam( aps->getAlfParam());
306  }
307  READ_FLAG( uiCode, "aps_extension_flag");
308  if (uiCode)
309  {
310    while ( xMoreRbspData() )
311    {
312      READ_FLAG( uiCode, "aps_extension_data_flag");
313    }
314  }
315
316}
317
318#if DBL_CONTROL
319Void  TDecCavlc::xParseDblParam       ( TComAPS* aps )
320{
321  UInt uiSymbol;
322  Int iSymbol;
323
324  parseDFFlag(uiSymbol, "loop_filter_disable");
325  aps->setLoopFilterDisable(uiSymbol?true:false);
326
327  if (!aps->getLoopFilterDisable())
328  {
329    parseDFSvlc(iSymbol, "beta_offset_div2");
330    aps->setLoopFilterBetaOffset(iSymbol);
331    parseDFSvlc(iSymbol, "tc_offset_div2");
332    aps->setLoopFilterTcOffset(iSymbol);
333  }
334}
335#endif
336/** parse SAO parameters
337 * \param pSaoParam
338 */
339Void TDecCavlc::xParseSaoParam(SAOParam* pSaoParam)
340{
341  UInt uiSymbol;
342
343#if SAO_UNIT_INTERLEAVING
344  int i,j, compIdx; 
345  int numCuInWidth; 
346  int numCuInHeight; 
347  Bool repeatedRow[3];
348  if (pSaoParam->bSaoFlag[0])                                                                   
349  {     
350    READ_FLAG (uiSymbol, "sao_cb_enable_flag");            pSaoParam->bSaoFlag[1]   = uiSymbol? true:false; 
351    READ_FLAG (uiSymbol, "sao_cr_enable_flag");            pSaoParam->bSaoFlag[2]   = uiSymbol? true:false; 
352    READ_UVLC (uiSymbol, "sao_num_lcu_in_width_minus1");   pSaoParam->numCuInWidth  = uiSymbol + 1;                         
353    READ_UVLC (uiSymbol, "sao_num_lcu_in_height_minus1");  pSaoParam->numCuInHeight = uiSymbol + 1;                         
354    numCuInWidth  = pSaoParam->numCuInWidth;
355    numCuInHeight = pSaoParam->numCuInHeight;
356
357    READ_FLAG (uiSymbol, "sao_one_luma_unit_flag");  pSaoParam->oneUnitFlag[0] = uiSymbol? true:false; 
358    if (pSaoParam->oneUnitFlag[0] )
359      xParseSaoOffset(&(pSaoParam->saoLcuParam[0][0]));
360
361    if (pSaoParam->bSaoFlag[1])
362    {
363      READ_FLAG (uiSymbol, "sao_one_cb_unit_flag");  pSaoParam->oneUnitFlag[1] = uiSymbol? true:false; 
364      if (pSaoParam->oneUnitFlag[1] )
365        xParseSaoOffset(&(pSaoParam->saoLcuParam[1][0]));
366    }
367    if (pSaoParam->bSaoFlag[2])
368    {
369      READ_FLAG (uiSymbol, "sao_one_cr_unit_flag");  pSaoParam->oneUnitFlag[2] = uiSymbol? true:false; 
370      if (pSaoParam->oneUnitFlag[2] )
371        xParseSaoOffset(&(pSaoParam->saoLcuParam[2][0]));
372    }
373    for (j=0;j<numCuInHeight;j++)
374    {
375      for (compIdx=0;compIdx<3;compIdx++)
376      {
377        repeatedRow[compIdx] = 0;
378      }
379      for (i=0;i<numCuInWidth;i++)
380      {
381        for (compIdx=0; compIdx<3; compIdx++)
382        {
383          if (pSaoParam->bSaoFlag[compIdx]  && !pSaoParam->oneUnitFlag[compIdx]) 
384          {
385            if (j>0 && i==0) 
386            {
387              READ_FLAG (uiSymbol, "sao_repeat_row_flag");  repeatedRow[compIdx] = uiSymbol? true:false; 
388            }
389            xParseSaoUnit (i,j, compIdx, pSaoParam, repeatedRow[compIdx]);
390          }
391        }
392      }
393    }
394  }
395#else
396  if (pSaoParam->bSaoFlag[0])
397  {
398    xParseSaoSplitParam (pSaoParam, 0, 0);
399    xParseSaoOffsetParam(pSaoParam, 0, 0);
400    READ_FLAG (uiSymbol, "sao_flag_cb");
401    pSaoParam->bSaoFlag[1] = uiSymbol? true:false;
402    if (pSaoParam->bSaoFlag[1])
403    {
404      xParseSaoSplitParam (pSaoParam, 0, 1);
405      xParseSaoOffsetParam(pSaoParam, 0, 1);
406    }
407
408    READ_FLAG (uiSymbol, "sao_flag_cr");
409    pSaoParam->bSaoFlag[2] = uiSymbol? true:false;
410    if (pSaoParam->bSaoFlag[2])
411    {
412      xParseSaoSplitParam (pSaoParam, 0, 2);
413      xParseSaoOffsetParam(pSaoParam, 0, 2);
414    }
415  }
416#endif
417}
418#if SAO_UNIT_INTERLEAVING
419/** copy SAO parameter
420 * \param dst 
421 * \param src
422 */
423inline Void copySaoOneLcuParam(SaoLcuParam* dst,  SaoLcuParam* src)
424{
425  Int i;
426  dst->partIdx = src->partIdx;
427  dst->typeIdx = src->typeIdx;
428  if (dst->typeIdx != -1)
429  {
430    if (dst->typeIdx == SAO_BO)
431    {
432      dst->bandPosition = src->bandPosition ;
433    }
434    else
435    {
436      dst->bandPosition = 0;
437    }
438    dst->length  = src->length;
439    for (i=0;i<dst->length;i++)
440    {
441      dst->offset[i] = src->offset[i];
442    }
443  }
444  else
445  {
446    dst->length  = 0;
447    for (i=0;i<SAO_BO_LEN;i++)
448    {
449      dst->offset[i] = 0;
450    }
451  }
452}
453/** parse SAO offset
454 * \param saoLcuParam SAO LCU parameters
455 */
456Void TDecCavlc::xParseSaoOffset(SaoLcuParam* saoLcuParam)
457{
458  UInt uiSymbol;
459  Int iSymbol;
460  static Int typeLength[MAX_NUM_SAO_TYPE] = {
461    SAO_EO_LEN,
462    SAO_EO_LEN,
463    SAO_EO_LEN,
464    SAO_EO_LEN,
465    SAO_BO_LEN
466  }; 
467
468  READ_UVLC (uiSymbol, "sao_type_idx");   saoLcuParam->typeIdx = (Int)uiSymbol - 1;       
469  if (uiSymbol)
470  {
471    saoLcuParam->length = typeLength[saoLcuParam->typeIdx];
472    if( saoLcuParam->typeIdx == SAO_BO )
473    {
474      READ_CODE( 5, uiSymbol, "sao_band_position"); saoLcuParam->bandPosition = uiSymbol; 
475      for(Int i=0; i< saoLcuParam->length; i++)
476      {
477        READ_SVLC (iSymbol, "sao_offset");    saoLcuParam->offset[i] = iSymbol;   
478      }   
479    }
480    else if( saoLcuParam->typeIdx < 4 )
481    {
482      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[0] = uiSymbol;
483      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[1] = uiSymbol;
484      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[2] = -(Int)uiSymbol;
485      READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[3] = -(Int)uiSymbol;
486    }
487  }
488  else
489  {
490    saoLcuParam->length = 0;
491  }
492}
493
494/** parse SAO unit
495 * \param rx x-axis location
496 * \param ry y-axis location
497 * \param compIdx color component index
498 * \param saoParam SAO parameters
499 * \param repeatedRow repeat row flag
500 */
501void TDecCavlc::xParseSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Bool& repeatedRow )
502{
503  int addr, addrUp, addrLeft; 
504  int numCuInWidth  = saoParam->numCuInWidth;
505  SaoLcuParam* saoOneLcu;
506  SaoLcuParam* saoOneLcuUp;
507  SaoLcuParam* saoOneLcuLeft;
508  UInt uiSymbol;
509  Int  iSymbol;
510  Int  runLeft;
511  UInt maxValue;
512
513  addr      =  rx + ry*numCuInWidth;
514  addrLeft  =  (addr%numCuInWidth == 0) ? -1 : addr - 1;
515  addrUp    =  (addr<numCuInWidth)      ? -1 : addr - numCuInWidth;
516
517  saoOneLcu = &(saoParam->saoLcuParam[compIdx][addr]);     
518  if (!repeatedRow)
519  {
520    runLeft = (addrLeft>=0 )  ? saoParam->saoLcuParam[compIdx][addrLeft].run : -1;
521    if (rx == 0 || runLeft==0)
522    {
523      saoOneLcu->mergeLeftFlag = 0;
524      if (ry == 0)
525      {
526        maxValue = numCuInWidth-rx-1;
527        UInt length = 0;
528        UInt val = 0;
529        if (maxValue)
530        {
531          for(UInt i=0; i<32; i++)
532          {
533            if(maxValue&0x1)
534            {
535              length = i+1;
536            }
537            maxValue = (maxValue >> 1);
538          }
539          if(length)
540          {
541            READ_CODE(length, val, "sao_run_diff");
542          }
543        }
544        uiSymbol = val;
545        saoOneLcu->runDiff = uiSymbol; 
546        xParseSaoOffset(saoOneLcu);
547        saoOneLcu->run = saoOneLcu->runDiff;
548      }
549      else 
550      {
551        saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
552        READ_SVLC (iSymbol , "sao_run_diff"     );  saoOneLcu->runDiff = iSymbol; 
553        READ_FLAG (uiSymbol, "sao_merge_up_flag");  saoOneLcu->mergeUpFlag   = uiSymbol? true:false;
554        if (!saoOneLcu->mergeUpFlag)
555        {
556          xParseSaoOffset(saoOneLcu);
557        }
558        else
559        {
560          saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
561          copySaoOneLcuParam(saoOneLcu, saoOneLcuUp);
562        }
563        saoOneLcu->run = saoOneLcu->runDiff + saoOneLcuUp->run;
564      }
565    }
566    else
567    {
568      saoOneLcuLeft = &(saoParam->saoLcuParam[compIdx][addrLeft]);
569      copySaoOneLcuParam(saoOneLcu, saoOneLcuLeft);
570      saoOneLcu->mergeLeftFlag = 1;
571      saoOneLcu->run = saoOneLcuLeft->run-1;
572    }
573  }
574  else
575  {
576    if (ry > 0)
577    {
578      saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
579      copySaoOneLcuParam(saoOneLcu, saoOneLcuUp);
580      saoOneLcu->mergeLeftFlag = 0;
581      saoOneLcu->run = saoOneLcuUp->run;
582    }
583  }
584}
585
586#else
587/** Decode quadtree split flag
588 * \param  pSaoParam, iPartIdx
589 */
590Void TDecCavlc::xParseSaoSplitParam(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr)
591{
592  UInt uiSymbol;
593  SAOQTPart*  pSaoPart = NULL;
594  pSaoPart= &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]);
595
596  if(pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel)
597  {
598    READ_FLAG (uiSymbol, "sao_split_flag");
599    pSaoPart->bSplit = uiSymbol? true:false; 
600    if(pSaoPart->bSplit)
601    {
602      for (Int i=0;i<NUM_DOWN_PART;i++)
603      {
604        xParseSaoSplitParam(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr);
605      }
606    }
607  }
608  else
609  {
610    pSaoPart->bSplit = false; 
611  }
612}
613
614/** Decode SAO for one partition
615 * \param  pSaoParam, iPartIdx
616 */
617Void TDecCavlc::xParseSaoOffsetParam(SAOParam* pSaoParam, Int iPartIdx, Int iYCbCr)
618{
619  UInt uiSymbol;
620  Int iSymbol; 
621  SAOQTPart*  pSaoPart = NULL;
622  pSaoPart = &(pSaoParam->psSaoPart[iYCbCr][iPartIdx]);
623
624  static Int iTypeLength[MAX_NUM_SAO_TYPE] = {
625    SAO_EO_LEN,
626    SAO_EO_LEN,
627    SAO_EO_LEN,
628    SAO_EO_LEN,
629    SAO_BO_LEN,
630    SAO_BO_LEN
631  }; 
632  if(!pSaoPart->bSplit)
633  {
634    READ_UVLC (uiSymbol, "sao_type_idx");
635    if (uiSymbol)
636    {
637      pSaoPart->iBestType = uiSymbol-1;
638      pSaoPart->bEnableFlag = true;
639    }
640    else
641    {
642      pSaoPart->iBestType = -1;
643      pSaoPart->bEnableFlag = false;
644    }
645
646    if (pSaoPart->bEnableFlag)
647    {
648      pSaoPart->iLength = iTypeLength[pSaoPart->iBestType];
649      for(Int i=0; i< pSaoPart->iLength; i++)
650      {
651        READ_SVLC (iSymbol, "sao_offset");
652        pSaoPart->iOffset[i] = iSymbol;
653      }
654    }
655    return;
656  }
657
658  //split
659  if (pSaoPart->PartLevel < pSaoParam->iMaxSplitLevel)
660  {
661    for(Int i=0;i<NUM_DOWN_PART;i++)
662    {
663      xParseSaoOffsetParam(pSaoParam, pSaoPart->DownPartsIdx[i], iYCbCr);
664    }
665  }
666}
667#endif
668
669#if LCU_SYNTAX_ALF
670Void TDecCavlc::xParseAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS, Int firstLCUAddr, Bool acrossSlice, Int numLCUInWidth, Int numLCUInHeight)
671{
672  Int  numLCU;
673  UInt uiSymbol;
674  Bool isEnabled[NUM_ALF_COMPONENT];
675  Bool isUniParam[NUM_ALF_COMPONENT];
676 
677  isEnabled[ALF_Y] = true;
678  READ_FLAG(uiSymbol, "alf_cb_enable_flag");  isEnabled[ALF_Cb] = ((uiSymbol ==1)?true:false);
679  READ_FLAG(uiSymbol, "alf_cr_enable_flag");  isEnabled[ALF_Cr] = ((uiSymbol ==1)?true:false);
680  READ_FLAG(uiSymbol, "alf_one_luma_unit_per_slice_flag");   isUniParam[ALF_Y] = ((uiSymbol ==1)?true:false);
681 
682  isUniParam[ALF_Cb] = true;
683  if (isEnabled[ALF_Cb])
684  {
685    READ_FLAG(uiSymbol, "alf_one_cb_unit_per_slice_flag");   isUniParam[ALF_Cb] = ((uiSymbol ==1)?true:false);
686  }
687 
688  isUniParam[ALF_Cr] = true;
689  if (isEnabled[ALF_Cr])
690  {
691    READ_FLAG(uiSymbol, "alf_one_cr_unit_per_slice_flag");   isUniParam[ALF_Cr] = ((uiSymbol ==1)?true:false);
692  }
693 
694  if(bSentInAPS)
695  {
696    READ_UVLC(uiSymbol, "alf_num_lcu_in_width_minus1");  numLCUInWidth = uiSymbol+1;
697    READ_UVLC(uiSymbol, "alf_num_lcu_in_height_minus1");  numLCUInHeight = uiSymbol+1;
698    numLCU = numLCUInWidth*numLCUInHeight;
699  }
700  else //sent in slice header
701  {
702    READ_UVLC(uiSymbol, "alf_num_lcu_in_slice_minus1");  numLCU = uiSymbol+1;
703  }
704 
705  assert(pAlfParamSet != NULL);
706 
707  pAlfParamSet->create(numLCUInWidth, numLCUInHeight, numLCU);
708  for(Int compIdx = 0; compIdx < NUM_ALF_COMPONENT; compIdx++)
709  {
710    pAlfParamSet->isEnabled[compIdx] = isEnabled[compIdx];
711    pAlfParamSet->isUniParam[compIdx]= isUniParam[compIdx];
712  }
713 
714  parseAlfParamSet(pAlfParamSet, firstLCUAddr, acrossSlice);
715}
716
717
718Void TDecCavlc::parseAlfParamSet(AlfParamSet* pAlfParamSet, Int firstLCUAddr, Bool alfAcrossSlice)
719{
720  Int numLCUInWidth = pAlfParamSet->numLCUInWidth;
721  Int numLCU        = pAlfParamSet->numLCU;
722 
723  static Bool isRepeatedRow   [NUM_ALF_COMPONENT];
724  static Int  numStoredFilters[NUM_ALF_COMPONENT];
725  static Int* run             [NUM_ALF_COMPONENT];
726 
727  for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
728  {
729    isRepeatedRow[compIdx]    = false;
730    numStoredFilters[compIdx] = 0;
731   
732    run[compIdx] = new Int[numLCU+1];
733    run[compIdx][0] = -1; 
734  }
735 
736  UInt uiSymbol;
737  Int  iSymbol, ry, rx, addrUp;
738 
739  for(Int i=0; i< numLCU; i++)
740  {
741    rx    = (i+ firstLCUAddr)% numLCUInWidth;
742    ry    = (i+ firstLCUAddr)/ numLCUInWidth;
743   
744    for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
745    {
746      AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][i];
747     
748      if(pAlfParamSet->isEnabled[compIdx])
749      {
750        if(!pAlfParamSet->isUniParam[compIdx])
751        {
752          addrUp = i-numLCUInWidth;
753          if(rx ==0 && addrUp >=0)
754          {
755            READ_FLAG(uiSymbol, "alf_repeat_row _flag"); isRepeatedRow[compIdx] = ((uiSymbol ==1)?true:false);
756          }
757         
758          if(isRepeatedRow[compIdx])
759          {
760            alfUnitParam.mergeType = ALF_MERGE_UP;
761            assert(addrUp >=0);
762            run[compIdx][i] = run[compIdx][addrUp];
763          }
764          else
765          {
766            if(rx == 0 || run[compIdx][i] < 0)
767            {             
768              if(addrUp < 0)
769              {
770                //alf_run_diff u(v)
771                parseAlfFixedLengthRun(uiSymbol, rx, numLCUInWidth);
772                run[compIdx][i] = uiSymbol;
773              }
774              else
775              {
776                //alf_run_diff s(v)
777                READ_SVLC(iSymbol, "alf_run_diff");
778                run[compIdx][i] = run[compIdx][addrUp] + iSymbol;
779                assert(run[compIdx][i] >= 0);
780              }
781             
782              if(ry > 0 && (addrUp >=0 || alfAcrossSlice))
783              {
784                //alf_merge_up_flag
785                READ_FLAG(uiSymbol, "alf_merge_up_flag");  alfUnitParam.mergeType = ((uiSymbol ==1)?ALF_MERGE_UP:ALF_MERGE_DISABLED);
786              }
787              else
788              {
789                alfUnitParam.mergeType = ALF_MERGE_DISABLED;
790              }
791             
792              if(alfUnitParam.mergeType != ALF_MERGE_UP)
793              {
794                //alf_lcu_enable_flag
795                READ_FLAG(uiSymbol, "alf_lcu_enable_flag");  alfUnitParam.isEnabled = ((uiSymbol ==1)?true:false);
796               
797                if(alfUnitParam.isEnabled)
798                {
799                  if(numStoredFilters[compIdx] > 0)
800                  {
801                    //alf_new_filter_set_flag
802                    READ_FLAG(uiSymbol, "alf_new_filter_set_flag");  alfUnitParam.isNewFilt = ((uiSymbol ==1)?true:false);
803                   
804                    if(!alfUnitParam.isNewFilt)
805                    {
806                      //alf_stored_filter_set_idx
807                      parseAlfStoredFilterIdx(uiSymbol, numStoredFilters[compIdx]);
808                     
809                      alfUnitParam.storedFiltIdx = uiSymbol;
810                     
811                      assert( alfUnitParam.storedFiltIdx < numStoredFilters[compIdx]);
812                    }
813                  }
814                  else
815                  {
816                    alfUnitParam.isNewFilt = true;
817                  }
818                 
819                  if(alfUnitParam.isNewFilt)
820                  {
821                    alfUnitParam.alfFiltParam = new ALFParam(compIdx);
822                    xParseAlfParam(alfUnitParam.alfFiltParam);
823                    alfUnitParam.alfFiltParam->alf_flag = 1;
824                   
825                    numStoredFilters[compIdx]++;
826                  }
827                }
828               
829              }
830            }
831            else
832            {
833              alfUnitParam.mergeType = ALF_MERGE_LEFT;
834            }
835           
836            run[compIdx][i+1] = run[compIdx][i] -1;
837          }
838         
839        }
840        else // uni-param
841        {
842          if(i == 0)
843          {
844            alfUnitParam.mergeType = ALF_MERGE_DISABLED;
845           
846            //alf_lcu_enable_flag
847            READ_FLAG(uiSymbol, "alf_lcu_enable_flag");  alfUnitParam.isEnabled = ((uiSymbol ==1)?true:false);
848            if(alfUnitParam.isEnabled)
849            {
850              alfUnitParam.isNewFilt = true;
851              alfUnitParam.alfFiltParam = new ALFParam(compIdx);
852              xParseAlfParam(alfUnitParam.alfFiltParam);
853              alfUnitParam.alfFiltParam->alf_flag = 1;
854            }
855          }
856          else
857          {
858            alfUnitParam.mergeType = ALF_MERGE_FIRST;
859          }
860         
861        }
862      }
863      else
864      {
865        alfUnitParam.mergeType = ALF_MERGE_DISABLED;
866        alfUnitParam.isEnabled = false;
867      }
868    }
869  }
870 
871  for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
872  {
873    delete[] run[compIdx];
874  }
875}
876
877
878Void TDecCavlc::parseAlfFixedLengthRun( UInt& idx, UInt rx, UInt numLCUInWidth )
879{
880  assert(numLCUInWidth > rx);
881 
882  UInt length = 0; 
883  UInt maxNumRun = numLCUInWidth - rx - 1; 
884 
885  for(UInt i=0; i<32; i++)
886  {
887    if(maxNumRun&0x1)
888    {
889      length = i+1;
890    }
891    maxNumRun = (maxNumRun >> 1);
892  }
893 
894  idx = 0;
895  if(length)
896  {
897    READ_CODE( length, idx, "alf_run_diff" );
898  }
899  else
900  {
901    idx = 0;
902  }
903}
904
905
906Void TDecCavlc::parseAlfStoredFilterIdx( UInt& idx, UInt numFilterSetsInBuffer )
907{
908  assert(numFilterSetsInBuffer > 0);
909 
910  UInt length = 0; 
911  UInt maxValue = numFilterSetsInBuffer - 1;
912 
913  for(UInt i=0; i<32; i++)
914  {
915    if(maxValue&0x1)
916    {
917      length = i+1;
918    }
919    maxValue = (maxValue >> 1);
920  }
921 
922  idx = 0;
923  if(length)
924  {
925    READ_CODE( length, idx, "alf_stored_filter_set_idx" );
926  }
927  else
928  {
929    idx = 0;
930  }
931}
932
933#endif
934
935Void TDecCavlc::xParseAlfParam(ALFParam* pAlfParam)
936{
937  UInt uiSymbol;
938  Int iSymbol;
939#if ALF_SINGLE_FILTER_SHAPE
940  Int sqrFiltLengthTab[NUM_ALF_FILTER_SHAPE] = {ALF_FILTER_LEN}; 
941#else
942  Int sqrFiltLengthTab[2] = { 9, 9}; 
943#endif
944
945#if LCU_SYNTAX_ALF
946  switch(pAlfParam->componentID)
947  {
948  case ALF_Cb:
949  case ALF_Cr:
950    {
951      pAlfParam->filter_shape = ALF_CROSS9x7_SQUARE3x3;
952      pAlfParam->num_coeff = sqrFiltLengthTab[pAlfParam->filter_shape];
953      pAlfParam->filters_per_group = 1;
954      for(Int pos=0; pos< pAlfParam->num_coeff; pos++)
955      {
956        READ_SVLC(iSymbol, "alf_filt_coeff");
957        pAlfParam->coeffmulti[0][pos] = iSymbol;
958      }
959    }
960    break;
961  case ALF_Y:
962    {
963#endif
964  pAlfParam->filters_per_group = 0;
965  memset (pAlfParam->filterPattern, 0 , sizeof(Int)*NO_VAR_BINS);
966#if !LCU_SYNTAX_ALF
967  READ_FLAG (uiSymbol, "alf_region_adaptation_flag");
968  pAlfParam->alf_pcr_region_flag = uiSymbol; 
969#endif
970#if ALF_SINGLE_FILTER_SHAPE 
971  pAlfParam->filter_shape = 0;
972#else
973  READ_UVLC (uiSymbol, "alf_length_luma_minus_5_div2");
974  pAlfParam->filter_shape = uiSymbol;
975#endif
976  pAlfParam->num_coeff = sqrFiltLengthTab[pAlfParam->filter_shape];
977
978  // filters_per_fr
979  READ_UVLC (uiSymbol, "alf_no_filters_minus1");
980  pAlfParam->filters_per_group = uiSymbol + 1;
981
982  if(uiSymbol == 1) // filters_per_group == 2
983  {
984    READ_UVLC (uiSymbol, "alf_start_second_filter");
985    pAlfParam->startSecondFilter = uiSymbol;
986    pAlfParam->filterPattern [uiSymbol] = 1;
987  }
988  else if (uiSymbol > 1) // filters_per_group > 2
989  {
990    pAlfParam->filters_per_group = 1;
991#if LCU_SYNTAX_ALF
992#if ALF_16_BA_GROUPS
993    Int numMergeFlags = 16;
994#else
995    Int numMergeFlags = 15;
996#endif
997#else
998#if ALF_16_BA_GROUPS
999    Int numMergeFlags = 16;
1000#else
1001    Int numMergeFlags = pAlfParam->alf_pcr_region_flag ? 16 : 15;
1002#endif
1003#endif
1004    for (Int i=1; i<numMergeFlags; i++) 
1005    {
1006      READ_FLAG (uiSymbol,  "alf_filter_pattern");
1007      pAlfParam->filterPattern[i] = uiSymbol;
1008      pAlfParam->filters_per_group += uiSymbol;
1009    }
1010  }
1011
1012  if (pAlfParam->filters_per_group > 1)
1013  {
1014    READ_FLAG (uiSymbol, "alf_pred_method");
1015    pAlfParam->predMethod = uiSymbol;
1016  }
1017  for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
1018  {
1019    READ_FLAG (uiSymbol,"alf_nb_pred_luma");
1020    pAlfParam->nbSPred[idx] = uiSymbol;
1021  }
1022
1023#if ALF_SINGLE_FILTER_SHAPE
1024  Int minScanVal = MIN_SCAN_POS_CROSS;
1025#else
1026  Int minScanVal = (pAlfParam->filter_shape == ALF_STAR5x5) ? 0: MIN_SCAN_POS_CROSS;
1027#endif
1028
1029  // Determine maxScanVal
1030  Int maxScanVal = 0;
1031  Int *pDepthInt = pDepthIntTabShapes[pAlfParam->filter_shape];
1032  for(Int idx = 0; idx < pAlfParam->num_coeff; idx++)
1033  {
1034    maxScanVal = max(maxScanVal, pDepthInt[idx]);
1035  }
1036
1037  // Golomb parameters
1038#if LCU_SYNTAX_ALF
1039  if( pAlfParam->filters_per_group > 1 )
1040  {
1041#endif
1042  READ_UVLC (uiSymbol, "alf_min_kstart_minus1");
1043  pAlfParam->minKStart = 1 + uiSymbol;
1044
1045  Int kMin = pAlfParam->minKStart;
1046
1047  for(Int scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
1048  {
1049    READ_FLAG (uiSymbol, "alf_golomb_index_bit");
1050    pAlfParam->kMinTab[scanPos] = kMin + uiSymbol;
1051    kMin = pAlfParam->kMinTab[scanPos];
1052  }
1053#if LCU_SYNTAX_ALF
1054  }
1055#endif
1056
1057  Int scanPos;
1058  for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
1059  {
1060    for(Int i = 0; i < pAlfParam->num_coeff; i++)
1061    {
1062      scanPos = pDepthInt[i] - 1;
1063#if LCU_SYNTAX_ALF
1064      Int k = (pAlfParam->filters_per_group == 1) ? kTableTabShapes[ALF_CROSS9x7_SQUARE3x3][i] : pAlfParam->kMinTab[scanPos];
1065      pAlfParam->coeffmulti[idx][i] = xGolombDecode(k);
1066#else
1067      pAlfParam->coeffmulti[idx][i] = xGolombDecode(pAlfParam->kMinTab[scanPos]);
1068#endif
1069    }
1070  }
1071#if LCU_SYNTAX_ALF
1072    }
1073    break;
1074  default:
1075    {
1076      printf("Not a legal component ID for ALF\n");
1077      assert(0);
1078      exit(-1);
1079    }
1080  }
1081#else
1082  // filter parameters for chroma
1083  READ_UVLC (uiSymbol, "alf_chroma_idc");
1084  pAlfParam->chroma_idc = uiSymbol;
1085
1086  if(pAlfParam->chroma_idc)
1087  {
1088
1089#if ALF_SINGLE_FILTER_SHAPE
1090    pAlfParam->filter_shape_chroma  = 0;
1091#else
1092    READ_UVLC (uiSymbol, "alf_length_chroma_minus_5_div2");
1093
1094    pAlfParam->filter_shape_chroma = uiSymbol;
1095#endif
1096    pAlfParam->num_coeff_chroma = sqrFiltLengthTab[pAlfParam->filter_shape_chroma];
1097    // filter coefficients for chroma
1098    for(Int pos=0; pos<pAlfParam->num_coeff_chroma; pos++)
1099    {
1100      READ_SVLC (iSymbol, "alf_coeff_chroma");
1101      pAlfParam->coeff_chroma[pos] = iSymbol;
1102    }
1103  }
1104#endif
1105}
1106
1107Int TDecCavlc::xGolombDecode(Int k)
1108{
1109  UInt uiSymbol;
1110  Int q = -1;
1111  Int nr = 0;
1112  Int a;
1113
1114  uiSymbol = 1;
1115  while (uiSymbol)
1116  {
1117    xReadFlag(uiSymbol);
1118    q++;
1119  }
1120  for(a = 0; a < k; ++a)          // read out the sequential log2(M) bits
1121  {
1122    xReadFlag(uiSymbol);
1123    if(uiSymbol)
1124      nr += 1 << a;
1125  }
1126  nr += q << k;
1127  if(nr != 0)
1128  {
1129    xReadFlag(uiSymbol);
1130    nr = (uiSymbol)? nr: -nr;
1131  }
1132#if ENC_DEC_TRACE
1133  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
1134  fprintf( g_hTrace, "%-40s ge(v) : %d\n", "alf_coeff_luma", nr ); 
1135#endif
1136  return nr;
1137}
1138
1139#if TILES_OR_ENTROPY_SYNC_IDC
1140Void TDecCavlc::parsePPS(TComPPS* pcPPS, ParameterSetManagerDecoder *parameterSet)
1141#else
1142Void TDecCavlc::parsePPS(TComPPS* pcPPS)
1143#endif
1144{
1145#if ENC_DEC_TRACE 
1146  xTracePPSHeader (pcPPS);
1147#endif
1148  UInt  uiCode;
1149
1150  Int   iCode;
1151
1152#if !RPS_IN_SPS
1153  TComRPSList* rpsList = pcPPS->getRPSList();
1154#endif
1155  READ_UVLC( uiCode, "pic_parameter_set_id");                      pcPPS->setPPSId (uiCode);
1156  READ_UVLC( uiCode, "seq_parameter_set_id");                      pcPPS->setSPSId (uiCode);
1157
1158#if MULTIBITS_DATA_HIDING
1159  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
1160  if( pcPPS->getSignHideFlag() )
1161  {
1162    READ_CODE( 4, uiCode, "sign_hiding_threshold"); pcPPS->setTSIG(uiCode);
1163  }
1164#endif
1165
1166#if CABAC_INIT_FLAG
1167  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
1168#endif
1169#if !RPS_IN_SPS
1170  // RPS is put before entropy_coding_mode_flag
1171  // since entropy_coding_mode_flag will probably be removed from the WD
1172  TComReferencePictureSet*      pcRPS;
1173
1174  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
1175  rpsList->create(uiCode);
1176
1177  for(Int i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
1178  {
1179    pcRPS = rpsList->getReferencePictureSet(i);
1180    parseShortTermRefPicSet(pcPPS,pcRPS,i);
1181  }
1182  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcPPS->setLongTermRefsPresent(uiCode);
1183#endif
1184  // entropy_coding_mode_flag
1185  // We code the entropy_coding_mode_flag, it's needed for tests.
1186  READ_FLAG( uiCode, "entropy_coding_mode_flag" );                 pcPPS->setEntropyCodingMode( uiCode ? true : false );
1187  if (pcPPS->getEntropyCodingMode())
1188  {
1189#if !WPP_SIMPLIFICATION
1190    READ_UVLC( uiCode, "entropy_coding_synchro" );                 pcPPS->setEntropyCodingSynchro( uiCode );
1191    READ_FLAG( uiCode, "cabac_istate_reset" );                     pcPPS->setCabacIstateReset( uiCode ? true : false );
1192#endif
1193#if !TILES_OR_ENTROPY_SYNC_IDC
1194#if !WPP_SIMPLIFICATION
1195    if ( pcPPS->getEntropyCodingSynchro() )
1196#endif
1197    {
1198      READ_UVLC( uiCode, "num_substreams_minus1" );                pcPPS->setNumSubstreams(uiCode+1);
1199    }
1200#endif
1201  }
1202#if !H0566_TLA
1203  READ_UVLC( uiCode, "num_temporal_layer_switching_point_flags" ); pcPPS->setNumTLayerSwitchingFlags( uiCode );
1204  for ( UInt i = 0; i < pcPPS->getNumTLayerSwitchingFlags(); i++ )
1205  {
1206    READ_FLAG( uiCode, "temporal_layer_switching_point_flag" );    pcPPS->setTLayerSwitchingFlag( i, uiCode > 0 ? true : false );
1207  }
1208#endif
1209 
1210  // num_ref_idx_l0_default_active_minus1
1211  // num_ref_idx_l1_default_active_minus1
1212  READ_SVLC(iCode, "pic_init_qp_minus26" );                        pcPPS->setPicInitQPMinus26(iCode);
1213  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
1214  READ_FLAG( uiCode, "enable_temporal_mvp_flag" );                 pcPPS->setEnableTMVPFlag( uiCode ? true : false );
1215  READ_CODE( 2, uiCode, "slice_granularity" );                     pcPPS->setSliceGranularity(uiCode);
1216
1217  // alf_param() ?
1218
1219  READ_UVLC( uiCode, "max_cu_qp_delta_depth");
1220  if(uiCode == 0)
1221  {
1222    pcPPS->setUseDQP (false);
1223    pcPPS->setMaxCuDQPDepth( 0 );
1224  }
1225  else
1226  {
1227    pcPPS->setUseDQP (true);
1228    pcPPS->setMaxCuDQPDepth(uiCode - 1);
1229  }
1230
1231  READ_SVLC( iCode, "chroma_qp_offset");
1232  pcPPS->setChromaQpOffset(iCode);
1233
1234  READ_SVLC( iCode, "chroma_qp_offset_2nd");
1235  pcPPS->setChromaQpOffset2nd(iCode);
1236
1237  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
1238  pcPPS->setUseWP( uiCode==1 );
1239  READ_CODE( 2, uiCode, "weighted_bipred_idc" );      // Use of Bi-Directional Weighting Prediction (B_SLICE)
1240  pcPPS->setWPBiPredIdc( uiCode );
1241//printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPredIdc());
1242
1243#if H0388
1244  READ_FLAG( uiCode, "output_flag_present_flag" );
1245  pcPPS->setOutputFlagPresentFlag( uiCode==1 );
1246#endif
1247
1248#if TILES_OR_ENTROPY_SYNC_IDC
1249  if(parameterSet->getPrefetchedSPS(pcPPS->getSPSId())->getTilesOrEntropyCodingSyncIdc()==1)
1250  {
1251#endif
1252    READ_FLAG ( uiCode, "tile_info_present_flag" );
1253    pcPPS->setColumnRowInfoPresent(uiCode);
1254    READ_FLAG ( uiCode, "tile_control_present_flag" );
1255    pcPPS->setTileBehaviorControlPresentFlag(uiCode);
1256    if( pcPPS->getColumnRowInfoPresent() == 1 )
1257    {
1258      READ_UVLC ( uiCode, "num_tile_columns_minus1" );   
1259      pcPPS->setNumColumnsMinus1( uiCode ); 
1260      READ_UVLC ( uiCode, "num_tile_rows_minus1" ); 
1261      pcPPS->setNumRowsMinus1( uiCode ); 
1262      READ_FLAG ( uiCode, "uniform_spacing_flag" ); 
1263      pcPPS->setUniformSpacingIdr( uiCode );
1264
1265      if( pcPPS->getUniformSpacingIdr() == 0 )
1266      {
1267        UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
1268        for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
1269        { 
1270          READ_UVLC( uiCode, "column_width" ); 
1271          columnWidth[i] = uiCode; 
1272        }
1273        pcPPS->setColumnWidth(columnWidth);
1274        free(columnWidth);
1275
1276        UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
1277        for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
1278        {
1279          READ_UVLC( uiCode, "row_height" ); 
1280          rowHeight[i] = uiCode; 
1281        }
1282        pcPPS->setRowHeight(rowHeight);
1283        free(rowHeight); 
1284      }
1285    }
1286
1287
1288    if(pcPPS->getTileBehaviorControlPresentFlag() == 1)
1289    {
1290      Int iNumColTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumColumnsMinus1());
1291      Int iNumRowTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumRowsMinus1());
1292#if !REMOVE_TILE_DEPENDENCE
1293      pcPPS->setTileBoundaryIndependenceIdr( 1 ); //default
1294#endif
1295      pcPPS->setLFCrossTileBoundaryFlag(true); //default
1296
1297      if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0)
1298      {
1299#if !REMOVE_TILE_DEPENDENCE
1300        READ_FLAG ( uiCode, "tile_boundary_independence_flag" ); 
1301        pcPPS->setTileBoundaryIndependenceIdr( uiCode );
1302
1303        if(pcPPS->getTileBoundaryIndependenceIdr() == 1)
1304        {
1305#endif
1306          READ_FLAG ( uiCode, "loop_filter_across_tile_flag" ); 
1307          pcPPS->setLFCrossTileBoundaryFlag( (uiCode == 1)?true:false );
1308#if !REMOVE_TILE_DEPENDENCE
1309        }
1310#endif
1311      }
1312    }
1313#if TILES_OR_ENTROPY_SYNC_IDC
1314  }
1315  else if(parameterSet->getPrefetchedSPS(pcPPS->getSPSId())->getTilesOrEntropyCodingSyncIdc()==2)
1316  {
1317    READ_UVLC( uiCode, "num_substreams_minus1" );                pcPPS->setNumSubstreams(uiCode+1);
1318  }
1319#endif
1320
1321#if DBL_CONTROL
1322  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" ); 
1323  pcPPS->setDeblockingFilterControlPresent( uiCode ? true : false);
1324#endif
1325#if PARALLEL_MERGE
1326  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
1327  assert(uiCode == LOG2_PARALLEL_MERGE_LEVEL_MINUS2);
1328  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
1329#endif
1330
1331  READ_FLAG( uiCode, "pps_extension_flag");
1332  if (uiCode)
1333  {
1334    while ( xMoreRbspData() )
1335    {
1336      READ_FLAG( uiCode, "pps_extension_data_flag");
1337    }
1338  }
1339}
1340
1341#if VIDYO_VPS_INTEGRATION
1342Void TDecCavlc::parseVPS(TComVPS* pcVPS)
1343{
1344  UInt  uiCode;
1345  Int   iCode;
1346 
1347  READ_CODE( 3, uiCode, "max_temporal_layers_minus1" );   pcVPS->setMaxTLayers( uiCode + 1 );
1348  READ_CODE( 5, uiCode, "max_layers_minus1" );            pcVPS->setMaxLayers( uiCode + 1 );
1349  READ_FLAG( uiCode,  "temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
1350  READ_UVLC( uiCode,  "video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
1351  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
1352  {
1353    READ_UVLC( uiCode,  "max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
1354    READ_UVLC( uiCode,  "num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
1355    READ_UVLC( uiCode,  "max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
1356  }
1357 
1358  READ_CODE( 1, uiCode, "bit_equal_to_one" );             assert( uiCode );
1359 
1360  if( pcVPS->getMaxLayers() - 1 > 0 )
1361  {
1362    READ_UVLC( uiCode,  "extension_type" );               pcVPS->setExtensionType( uiCode );
1363   
1364    pcVPS->setViewOrderIdx( 0, 0 );
1365    pcVPS->setViewId( 0, 0 );
1366    pcVPS->setDepthFlag( 0, 0 );
1367    for(UInt i = 1; i <= pcVPS->getMaxLayers()-1; i++)
1368    {
1369      READ_FLAG( uiCode, "dependent_flag[i]" );           pcVPS->setDependentFlag( uiCode ? true:false, i);
1370      if( pcVPS->getDependentFlag(i) )
1371      {
1372        READ_UVLC( uiCode,  "delta_reference_layer_id_minus1[i]" ); pcVPS->setDependentLayer( i - uiCode + 1, i );
1373        if( pcVPS->getExtensionType() == VPS_EXTENSION_TYPE_MULTI_VIEW )
1374        {
1375          READ_UVLC( uiCode,  "view_id[i]" );             pcVPS->setViewId( uiCode, i );
1376          READ_FLAG( uiCode,  "depth_flag[i]" );          pcVPS->setDepthFlag( uiCode ? true:false, i ); 
1377          READ_SVLC( iCode,  "view_order_idx[i]" );       pcVPS->setViewOrderIdx( iCode, i );
1378        }
1379       
1380      }
1381    }
1382  }
1383 
1384  READ_FLAG( uiCode,  "vps_extension_flag" );          assert(!uiCode);
1385  //future extensions go here..
1386 
1387  return;
1388}
1389
1390#endif
1391
1392#if HHI_MPI
1393Void TDecCavlc::parseSPS(TComSPS* pcSPS, Bool bIsDepth)
1394#else
1395Void TDecCavlc::parseSPS(TComSPS* pcSPS)
1396#endif
1397{
1398#if ENC_DEC_TRACE 
1399  xTraceSPSHeader (pcSPS);
1400#endif
1401 
1402  UInt  uiCode;
1403  Int   iCode;
1404
1405  READ_CODE( 8,  uiCode, "profile_idc" );                        pcSPS->setProfileIdc( uiCode );
1406  READ_CODE( 8,  uiCode, "reserved_zero_8bits" );
1407  READ_CODE( 8,  uiCode, "level_idc" );                          pcSPS->setLevelIdc( uiCode );
1408  READ_UVLC(     uiCode, "seq_parameter_set_id" );               pcSPS->setSPSId( uiCode );
1409#if VIDYO_VPS_INTEGRATION
1410  READ_UVLC(     uiCode, "video_parameter_set_id" );             pcSPS->setVPSId( uiCode );
1411#endif
1412  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
1413  READ_CODE( 3,  uiCode, "max_temporal_layers_minus1" );         pcSPS->setMaxTLayers( uiCode+1 );
1414  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
1415  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
1416#if PIC_CROPPING
1417  READ_FLAG(     uiCode, "pic_cropping_flag");                   pcSPS->setPicCroppingFlag ( uiCode ? true : false );
1418  if (uiCode != 0)
1419  {
1420    READ_UVLC(   uiCode, "pic_crop_left_offset" );               pcSPS->setPicCropLeftOffset( uiCode );
1421    READ_UVLC(   uiCode, "pic_crop_right_offset" );              pcSPS->setPicCropRightOffset( uiCode );
1422    READ_UVLC(   uiCode, "pic_crop_top_offset" );                pcSPS->setPicCropTopOffset( uiCode );
1423    READ_UVLC(   uiCode, "pic_crop_bottom_offset" );             pcSPS->setPicCropBottomOffset( uiCode );
1424  }
1425#endif
1426
1427#if FULL_NBIT
1428  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
1429  g_uiBitDepth = 8 + uiCode;
1430  g_uiBitIncrement = 0;
1431  pcSPS->setBitDepth(g_uiBitDepth);
1432  pcSPS->setBitIncrement(g_uiBitIncrement);
1433#else
1434  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
1435  g_uiBitDepth = 8;
1436  g_uiBitIncrement = uiCode;
1437  pcSPS->setBitDepth(g_uiBitDepth);
1438  pcSPS->setBitIncrement(g_uiBitIncrement);
1439#endif
1440 
1441#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1442  g_iDeltaDCsQuantOffset = g_uiBitIncrement - 2;
1443#endif
1444
1445#if H0736_AVC_STYLE_QP_RANGE
1446  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
1447#endif
1448
1449  g_uiBASE_MAX  = ((1<<(g_uiBitDepth))-1);
1450 
1451#if IBDI_NOCLIP_RANGE
1452  g_uiIBDI_MAX  = g_uiBASE_MAX << g_uiBitIncrement;
1453#else
1454  g_uiIBDI_MAX  = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1);
1455#endif
1456  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
1457#if H0736_AVC_STYLE_QP_RANGE
1458  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
1459#endif
1460
1461  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
1462
1463  if( pcSPS->getUsePCM() )
1464  {
1465    READ_CODE( 4, uiCode, "pcm_bit_depth_luma_minus1" );           pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
1466    READ_CODE( 4, uiCode, "pcm_bit_depth_chroma_minus1" );         pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
1467  }
1468
1469#if LOSSLESS_CODING
1470  READ_FLAG( uiCode, "qpprime_y_zero_transquant_bypass_flag" );    pcSPS->setUseLossless ( uiCode ? true : false );
1471#endif
1472
1473  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
1474#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
1475  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
1476  {
1477    READ_UVLC ( uiCode, "max_dec_pic_buffering");
1478    pcSPS->setMaxDecPicBuffering( uiCode, i);
1479    READ_UVLC ( uiCode, "num_reorder_pics" );
1480    pcSPS->setNumReorderPics(uiCode, i);
1481    READ_UVLC ( uiCode, "max_latency_increase");
1482    pcSPS->setMaxLatencyIncrease( uiCode, i );
1483  }
1484#else
1485  READ_UVLC( uiCode,    "max_num_ref_pics" );                    pcSPS->setMaxNumberOfReferencePictures(uiCode);
1486  READ_UVLC( uiCode,    "num_reorder_frames" );                  pcSPS->setNumReorderFrames(uiCode);
1487  READ_UVLC ( uiCode, "max_dec_frame_buffering");
1488  pcSPS->setMaxDecFrameBuffering( uiCode );
1489  READ_UVLC ( uiCode, "max_latency_increase");
1490  pcSPS->setMaxLatencyIncrease( uiCode );
1491#endif
1492
1493#if H0412_REF_PIC_LIST_RESTRICTION
1494  READ_FLAG( uiCode, "restricted_ref_pic_lists_flag" );
1495  pcSPS->setRestrictedRefPicListsFlag( uiCode );
1496  if( pcSPS->getRestrictedRefPicListsFlag() )
1497  {
1498    READ_FLAG( uiCode, "lists_modification_present_flag" );
1499    pcSPS->setListsModificationPresentFlag(uiCode);
1500  }
1501  else 
1502  {
1503    pcSPS->setListsModificationPresentFlag(true);
1504  }
1505#endif
1506  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
1507  UInt log2MinCUSize = uiCode + 3;
1508  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
1509  UInt uiMaxCUDepthCorrect = uiCode;
1510  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUWidth  = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
1511  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUHeight = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
1512  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
1513
1514  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
1515  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
1516
1517  if(log2MinCUSize == 3)
1518  {
1519    xReadFlag( uiCode ); pcSPS->setDisInter4x4( uiCode ? true : false );
1520  }
1521
1522  if( pcSPS->getUsePCM() )
1523  {
1524    READ_UVLC( uiCode, "log2_min_pcm_coding_block_size_minus3" );  pcSPS->setPCMLog2MinSize (uiCode+3); 
1525    READ_UVLC( uiCode, "log2_diff_max_min_pcm_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
1526  }
1527
1528  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
1529  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
1530  g_uiAddCUDepth = 0;
1531  while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth )  ) )
1532  {
1533    g_uiAddCUDepth++;
1534  }
1535  pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth  ); 
1536  g_uiMaxCUDepth  = uiMaxCUDepthCorrect+g_uiAddCUDepth;
1537  // BB: these parameters may be removed completly and replaced by the fixed values
1538  pcSPS->setMinTrDepth( 0 );
1539  pcSPS->setMaxTrDepth( 1 );
1540  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
1541  READ_FLAG( uiCode, "chroma_pred_from_luma_enabled_flag" );        pcSPS->setUseLMChroma ( uiCode ? true : false ); 
1542  READ_FLAG( uiCode, "deblocking_filter_in_aps_enabled_flag" );     pcSPS->setUseDF ( uiCode ? true : false ); 
1543  READ_FLAG( uiCode, "loop_filter_across_slice_flag" );             pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false);
1544  READ_FLAG( uiCode, "asymmetric_motion_partitions_enabled_flag" ); pcSPS->setUseAMP( uiCode );
1545  READ_FLAG( uiCode, "non_square_quadtree_enabled_flag" );          pcSPS->setUseNSQT( uiCode );
1546  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false ); 
1547  READ_FLAG( uiCode, "adaptive_loop_filter_enabled_flag" );         pcSPS->setUseALF ( uiCode ? true : false );
1548#if LCU_SYNTAX_ALF
1549  if(pcSPS->getUseALF())
1550  {
1551    READ_FLAG( uiCode, "alf_coef_in_slice_flag" );      pcSPS->setUseALFCoefInSlice ( uiCode ? true : false );
1552  }
1553#endif
1554  if( pcSPS->getUsePCM() )
1555  {
1556    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );           pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
1557  }
1558
1559  READ_FLAG( uiCode, "temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
1560
1561
1562#if RPS_IN_SPS
1563  TComRPSList* rpsList = pcSPS->getRPSList();
1564  TComReferencePictureSet* rps;
1565
1566  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
1567  rpsList->create(uiCode);
1568
1569  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
1570  {
1571    rps = rpsList->getReferencePictureSet(i);
1572    parseShortTermRefPicSet(pcSPS,rps,i);
1573  }
1574  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
1575#endif
1576#if !PIC_CROPPING
1577  //!!!KS: Syntax not in WD !!!
1578
1579  xReadUvlc ( uiCode ); pcSPS->setPadX        ( uiCode    );
1580  xReadUvlc ( uiCode ); pcSPS->setPadY        ( uiCode    );
1581#endif
1582 
1583  // AMVP mode for each depth (AM_NONE or AM_EXPL)
1584  for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
1585  {
1586    xReadFlag( uiCode );
1587    pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode );
1588  }
1589
1590#if TILES_WPP_ENTRY_POINT_SIGNALLING
1591  READ_CODE(2, uiCode, "tiles_or_entropy_coding_sync_idc");         pcSPS->setTilesOrEntropyCodingSyncIdc(uiCode);
1592#endif
1593
1594#if TILES_OR_ENTROPY_SYNC_IDC
1595  if(pcSPS->getTilesOrEntropyCodingSyncIdc() == 1)
1596  {
1597#endif
1598    READ_UVLC ( uiCode, "num_tile_columns_minus1" );
1599    pcSPS->setNumColumnsMinus1( uiCode ); 
1600    READ_UVLC ( uiCode, "num_tile_rows_minus1" ); 
1601    pcSPS->setNumRowsMinus1( uiCode ); 
1602    READ_FLAG ( uiCode, "uniform_spacing_flag" ); 
1603    pcSPS->setUniformSpacingIdr( uiCode );
1604    if( pcSPS->getUniformSpacingIdr() == 0 )
1605    {
1606      UInt* columnWidth = (UInt*)malloc(pcSPS->getNumColumnsMinus1()*sizeof(UInt));
1607      for(UInt i=0; i<pcSPS->getNumColumnsMinus1(); i++)
1608      { 
1609        READ_UVLC( uiCode, "column_width" );
1610        columnWidth[i] = uiCode; 
1611      }
1612      pcSPS->setColumnWidth(columnWidth);
1613      free(columnWidth);
1614
1615      UInt* rowHeight = (UInt*)malloc(pcSPS->getNumRowsMinus1()*sizeof(UInt));
1616      for(UInt i=0; i<pcSPS->getNumRowsMinus1(); i++)
1617      {
1618        READ_UVLC( uiCode, "row_height" );
1619        rowHeight[i] = uiCode; 
1620      }
1621      pcSPS->setRowHeight(rowHeight);
1622      free(rowHeight); 
1623    }
1624#if !REMOVE_TILE_DEPENDENCE
1625    pcSPS->setTileBoundaryIndependenceIdr( 1 ); //default
1626#endif
1627    pcSPS->setLFCrossTileBoundaryFlag(true); //default
1628
1629    if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0)
1630    {
1631#if !REMOVE_TILE_DEPENDENCE
1632      READ_FLAG ( uiCode, "tile_boundary_independence_flag" ); 
1633      pcSPS->setTileBoundaryIndependenceIdr( uiCode );
1634      if(pcSPS->getTileBoundaryIndependenceIdr() == 1)
1635      {
1636#endif
1637        READ_FLAG ( uiCode, "loop_filter_across_tile_flag" ); 
1638        pcSPS->setLFCrossTileBoundaryFlag( (uiCode==1)?true:false);
1639#if !REMOVE_TILE_DEPENDENCE
1640      }
1641#endif
1642    }
1643#if TILES_OR_ENTROPY_SYNC_IDC
1644  }
1645#endif
1646  READ_FLAG( uiCode, "sps_extension_flag");
1647  if(uiCode)
1648  {
1649    READ_FLAG( uiCode, "interview_refs_present_flag");
1650    if(uiCode)
1651    {
1652      READ_UVLC( uiCode, "num_usable_interview_refs_minus1" );
1653      pcSPS->setNumberOfUsableInterViewRefs( uiCode + 1 );
1654
1655      Int prev = 0;
1656      for( Int j = 0 ; j < pcSPS->getNumberOfUsableInterViewRefs(); j++ )
1657      {
1658        READ_UVLC(uiCode, "delta_usable_interview_ref_minus1");
1659        pcSPS->setUsableInterViewRef( j, (prev - uiCode - 1) );
1660        prev = pcSPS->getUsableInterViewRef( j );
1661      }
1662    }
1663
1664#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1665    READ_FLAG( uiCode, "enable_dmm_flag" ); 
1666    pcSPS->setUseDMM( uiCode );
1667#endif
1668
1669#if HHI_MPI
1670    if( bIsDepth )
1671    {
1672      READ_FLAG( uiCode, "use_mvi_flag" );
1673      pcSPS->setUseMVI( uiCode );
1674    }
1675#endif
1676   
1677#if RWTH_SDC_DLT_B0036
1678    if( bIsDepth )
1679    {
1680      READ_FLAG( uiCode, "use_dlt_flag" );
1681      pcSPS->setUseDLT( uiCode );
1682      if( pcSPS->getUseDLT() )
1683      {
1684        // decode mapping
1685        UInt uiNumDepthValues;
1686        // parse number of values in DLT
1687        xReadUvlc( uiNumDepthValues );
1688       
1689        // parse actual DLT values
1690        UInt* auiIdx2DepthValue = (UInt*) calloc(uiNumDepthValues, sizeof(UInt));
1691        for(UInt d=0; d<uiNumDepthValues; d++)
1692        {
1693          xReadUvlc( uiCode );
1694          auiIdx2DepthValue[d] = uiCode;
1695        }
1696       
1697        pcSPS->setDepthLUTs(auiIdx2DepthValue, uiNumDepthValues);
1698       
1699        // clean memory
1700        free(auiIdx2DepthValue);
1701      }
1702      else
1703        pcSPS->setDepthLUTs();
1704    }
1705#endif
1706
1707    READ_FLAG( uiCode, "base_view_flag" );
1708    if( uiCode )
1709    { // baseview SPS -> set standard values
1710      pcSPS->initMultiviewSPS         ( 0 );
1711#if DEPTH_MAP_GENERATION
1712      pcSPS->setPredDepthMapGeneration( 0, false );
1713#endif
1714#if HHI_INTER_VIEW_RESIDUAL_PRED
1715    pcSPS->setMultiviewResPredMode  ( 0 );
1716#endif
1717    }
1718    else
1719    {
1720      READ_FLAG( uiCode, "depth_flag" ); 
1721      if( uiCode )
1722      {
1723        READ_UVLC( uiCode, "view_id" ); 
1724        READ_SVLC(  iCode, "view_order_idx" ); 
1725        pcSPS->initMultiviewSPSDepth    ( uiCode, iCode );
1726#if DEPTH_MAP_GENERATION
1727        pcSPS->setPredDepthMapGeneration( uiCode, true );
1728#endif
1729#if HHI_INTER_VIEW_RESIDUAL_PRED
1730      pcSPS->setMultiviewResPredMode  ( 0 );
1731#endif
1732      }
1733      else
1734      {
1735        UInt  uiViewId, uiCamParPrecision;
1736        Int   iVOI;
1737        Bool  bCamParSlice;
1738        READ_UVLC( uiViewId, "view_id" );  uiViewId++;
1739        READ_SVLC( iVOI, "view_order_idx" );
1740        READ_UVLC( uiCamParPrecision, "camera_parameter_precision" );
1741        READ_FLAG( uiCode, "camera_parameter_in_slice_header" );    bCamParSlice = ( uiCode == 1 );
1742        if( !bCamParSlice )
1743        {
1744          for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
1745          {
1746            READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
1747            READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
1748            READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
1749            READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
1750          }
1751        }
1752        pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
1753
1754#if DEPTH_MAP_GENERATION
1755        UInt uiPredDepthMapGeneration = 0, uiPdmPrecision = 0;
1756#if HHI_INTER_VIEW_MOTION_PRED
1757        UInt uiMultiviewMvPredMode = 0;
1758#endif
1759#if HHI_INTER_VIEW_RESIDUAL_PRED
1760      UInt uiMultiviewResPredMode = 0;
1761#endif
1762        READ_UVLC( uiPredDepthMapGeneration, "Pdm_generation" );
1763        if( uiPredDepthMapGeneration )
1764        {
1765          READ_UVLC( uiPdmPrecision, "Pdm_precision" );
1766          for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
1767          {
1768            READ_SVLC( iCode, "Pdm_scale_nom_delta" );   m_aaiTempPdmScaleNomDelta[ uiViewId ][ uiBaseId ] = iCode;
1769            READ_SVLC( iCode, "Pdm_offset" );   m_aaiTempPdmOffset       [ uiViewId ][ uiBaseId ] = iCode;
1770          }
1771#if HHI_INTER_VIEW_MOTION_PRED
1772          READ_UVLC( uiMultiviewMvPredMode, "multi_view_mv_pred_mode" );
1773#endif
1774#if HHI_INTER_VIEW_RESIDUAL_PRED
1775          READ_FLAG( uiMultiviewResPredMode, "multi_view_residual_pred_mode" );
1776#endif
1777        }
1778#if HHI_INTER_VIEW_MOTION_PRED
1779        pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
1780#else
1781        pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, 0, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
1782#endif
1783#endif
1784#if HHI_INTER_VIEW_RESIDUAL_PRED
1785      pcSPS->setMultiviewResPredMode  ( uiMultiviewResPredMode );
1786#endif
1787      }
1788    }
1789    READ_FLAG( uiCode, "sps_extension2_flag");
1790    if (uiCode)
1791    {
1792      while ( xMoreRbspData() )
1793      {
1794        READ_FLAG( uiCode, "sps_extension2_data_flag");
1795      }
1796    }
1797  }
1798}
1799
1800Void TDecCavlc::readTileMarker   ( UInt& uiTileIdx, UInt uiBitsUsed )
1801{
1802  xReadCode ( uiBitsUsed, uiTileIdx );
1803}
1804
1805#if LCU_SYNTAX_ALF
1806Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet)
1807#else
1808Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl)
1809#endif
1810{
1811  UInt  uiCode;
1812  Int   iCode;
1813 
1814#if ENC_DEC_TRACE
1815  xTraceSliceHeader(rpcSlice);
1816#endif
1817  Int numCUs = ((rpcSlice->getSPS()->getPicWidthInLumaSamples()+rpcSlice->getSPS()->getMaxCUWidth()-1)/rpcSlice->getSPS()->getMaxCUWidth())*((rpcSlice->getSPS()->getPicHeightInLumaSamples()+rpcSlice->getSPS()->getMaxCUHeight()-1)/rpcSlice->getSPS()->getMaxCUHeight());
1818  Int maxParts = (1<<(rpcSlice->getSPS()->getMaxCUDepth()<<1));
1819  Int numParts = (1<<(rpcSlice->getPPS()->getSliceGranularity()<<1));
1820  UInt lCUAddress = 0;
1821  Int reqBitsOuter = 0;
1822  while(numCUs>(1<<reqBitsOuter))
1823  {
1824    reqBitsOuter++;
1825  }
1826  Int reqBitsInner = 0;
1827  while((numParts)>(1<<reqBitsInner)) 
1828  {
1829    reqBitsInner++;
1830  }
1831
1832  READ_FLAG( uiCode, "first_slice_in_pic_flag" );
1833  UInt address;
1834  UInt innerAddress = 0;
1835
1836#if LGE_ILLUCOMP_B0045
1837  // IC flag is on only first_slice_in_pic
1838  if (uiCode)
1839  {
1840    UInt uiCodeTmp = 0;
1841    if ( rpcSlice->getSPS()->getViewId() && !rpcSlice->getSPS()->isDepth() )
1842    {
1843      READ_FLAG (uiCodeTmp, "applying IC flag");
1844    }
1845    rpcSlice->setApplyIC(uiCodeTmp);
1846  }
1847#endif
1848
1849  if(!uiCode)
1850  {
1851    READ_CODE( reqBitsOuter+reqBitsInner, address, "slice_address" );
1852    lCUAddress = address >> reqBitsInner;
1853    innerAddress = address - (lCUAddress<<reqBitsInner);
1854  }
1855  //set uiCode to equal slice start address (or entropy slice start address)
1856  uiCode=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(rpcSlice->getPPS()->getSliceGranularity()<<1)));
1857 
1858  rpcSlice->setEntropySliceCurStartCUAddr( uiCode );
1859  rpcSlice->setEntropySliceCurEndCUAddr(numCUs*maxParts);
1860
1861  //   slice_type
1862  READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
1863  // lightweight_slice_flag
1864  READ_FLAG( uiCode, "entropy_slice_flag" );
1865  Bool bEntropySlice = uiCode ? true : false;
1866
1867  if (bEntropySlice)
1868  {
1869    rpcSlice->setNextSlice        ( false );
1870    rpcSlice->setNextEntropySlice ( true  );
1871  }
1872  else
1873  {
1874    rpcSlice->setNextSlice        ( true  );
1875    rpcSlice->setNextEntropySlice ( false );
1876   
1877    uiCode=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(rpcSlice->getPPS()->getSliceGranularity()<<1)));
1878    rpcSlice->setSliceCurStartCUAddr(uiCode);
1879    rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts);
1880  }
1881  TComPPS* pps = NULL;
1882  TComSPS* sps = NULL;
1883
1884  if (!bEntropySlice)
1885  {
1886    READ_UVLC (    uiCode, "pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
1887    pps = parameterSetManager->getPrefetchedPPS(uiCode);
1888    sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
1889    rpcSlice->setSPS(sps);
1890    rpcSlice->setPPS(pps);
1891#if H0388
1892    if( pps->getOutputFlagPresentFlag() )
1893    {
1894      READ_FLAG( uiCode, "pic_output_flag" );
1895      rpcSlice->setPicOutputFlag( uiCode ? true : false );
1896    }
1897    else
1898    {
1899      rpcSlice->setPicOutputFlag( true );
1900    }
1901#endif
1902    if(rpcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR) 
1903    { 
1904      READ_UVLC( uiCode, "idr_pic_id" );  //ignored
1905      READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
1906      rpcSlice->setPOC(0);
1907      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
1908      rps->setNumberOfNegativePictures(0);
1909      rps->setNumberOfPositivePictures(0);
1910      rps->setNumberOfLongtermPictures(0);
1911      rps->setNumberOfPictures(0);
1912      rpcSlice->setRPS(rps);
1913    }
1914    else
1915    {
1916      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); 
1917      Int iPOClsb = uiCode;
1918      Int iPrevPOC = rpcSlice->getPrevPOC();
1919      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
1920      Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
1921      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
1922      Int iPOCmsb;
1923      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
1924      {
1925        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
1926      }
1927      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
1928      {
1929        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
1930      }
1931      else
1932      {
1933        iPOCmsb = iPrevPOCmsb;
1934      }
1935      rpcSlice->setPOC( iPOCmsb+iPOClsb );
1936
1937      if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && rpcSlice->getPOC() == 0 )
1938      {
1939        TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
1940        rps->setNumberOfNegativePictures(0);
1941        rps->setNumberOfPositivePictures(0);
1942        rps->setNumberOfLongtermPictures(0);
1943        rps->setNumberOfPictures(0);
1944        rpcSlice->setRPS(rps);
1945      }
1946      else
1947      {
1948        TComReferencePictureSet* rps;
1949        READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
1950        if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
1951        {
1952          rps = rpcSlice->getLocalRPS();
1953#if RPS_IN_SPS
1954          parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
1955#else
1956          parseShortTermRefPicSet(pps,rps, pps->getRPSList()->getNumberOfReferencePictureSets());
1957#endif
1958          rpcSlice->setRPS(rps);
1959        }
1960        else // use reference to short-term reference picture set in PPS
1961        {
1962#if RPS_IN_SPS
1963          READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode));
1964#else
1965          READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(pps->getRPSList()->getReferencePictureSet(uiCode));
1966#endif
1967          rps = rpcSlice->getRPS();
1968        }
1969#if RPS_IN_SPS
1970        if(sps->getLongTermRefsPresent())
1971#else
1972        if(pps->getLongTermRefsPresent())
1973#endif
1974        {
1975          Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
1976          READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
1977          Int prev = 0;
1978#if LTRP_MULT
1979          Int prevMsb=0;
1980          Int prevDeltaPocLt=0;
1981#endif
1982          for(Int j=rps->getNumberOfLongtermPictures()+offset-1 ; j > offset-1; j--)
1983          {
1984            READ_UVLC(uiCode,"delta_poc_lsb_lt"); 
1985            prev += uiCode;
1986
1987#if LTRP_MULT
1988            READ_FLAG(uiCode,"delta_poc_msb_present_flag");
1989            Int decDeltaPOCMsbPresent=uiCode;
1990
1991            if(decDeltaPOCMsbPresent==1)
1992            {
1993              READ_UVLC(uiCode, "delta_poc_msb_cycle_lt_minus1");
1994              if(  (j==(rps->getNumberOfLongtermPictures()+offset-1)) || (prev!=prevDeltaPocLt) )
1995              {
1996                prevMsb=(1+uiCode); 
1997              }
1998              else
1999              {
2000                prevMsb+=(1+uiCode); 
2001              }
2002              Int decMaxPocLsb = 1<<rpcSlice->getSPS()->getBitsForPOC();
2003              rps->setPOC(j,rpcSlice->getPOC()-prev-(prevMsb)*decMaxPocLsb); 
2004              rps->setDeltaPOC(j,-(Int)(prev+(prevMsb)*decMaxPocLsb));
2005            }
2006            else
2007            {
2008#endif
2009              rps->setPOC(j,rpcSlice->getPOC()-prev);         
2010              rps->setDeltaPOC(j,-(Int)prev);
2011#if LTRP_MULT
2012            }
2013            prevDeltaPocLt=prev;
2014#endif
2015            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
2016          }
2017          offset += rps->getNumberOfLongtermPictures();
2018          rps->setNumberOfPictures(offset);       
2019        } 
2020      }
2021    }
2022
2023    if(sps->getUseSAO() || sps->getUseALF() || sps->getScalingListFlag() || sps->getUseDF())
2024    {
2025      //!!!KS: order is different in WD5!
2026      if (sps->getUseALF())
2027      {
2028        READ_FLAG(uiCode, "slice_adaptive_loop_filter_flag");
2029        rpcSlice->setAlfEnabledFlag((Bool)uiCode);
2030      }
2031      if (sps->getUseSAO())
2032      {
2033#if SAO_UNIT_INTERLEAVING
2034        READ_FLAG(uiCode, "slice_sao_interleaving_flag");        rpcSlice->setSaoInterleavingFlag(uiCode);
2035#endif
2036        READ_FLAG(uiCode, "slice_sample_adaptive_offset_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
2037#if SAO_UNIT_INTERLEAVING
2038        if (rpcSlice->getSaoEnabledFlag() && rpcSlice->getSaoInterleavingFlag())
2039        {
2040          READ_FLAG(uiCode, "sao_cb_enable_flag");  rpcSlice->setSaoEnabledFlagCb((Bool)uiCode);
2041          READ_FLAG(uiCode, "sao_cr_enable_flag");  rpcSlice->setSaoEnabledFlagCr((Bool)uiCode);
2042        }
2043        else
2044        {
2045          rpcSlice->setSaoEnabledFlagCb(0);
2046          rpcSlice->setSaoEnabledFlagCr(0);
2047        }
2048#endif
2049      }
2050      READ_UVLC (    uiCode, "aps_id" );  rpcSlice->setAPSId(uiCode);
2051    }
2052    if (!rpcSlice->isIntra())
2053    {
2054      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
2055      if (uiCode)
2056      {
2057        READ_CODE (3, uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
2058        if (rpcSlice->isInterB())
2059        {
2060          READ_CODE (3, uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
2061        }
2062        else
2063        {
2064          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2065        }
2066      }
2067      else
2068      {
2069        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
2070        rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
2071      }
2072    }
2073    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
2074    if( !rpcSlice->isIntra() )
2075    {
2076#if H0412_REF_PIC_LIST_RESTRICTION
2077      if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
2078      {
2079        refPicListModification->setRefPicListModificationFlagL0( 0 );
2080      }
2081      else
2082      {
2083#endif
2084        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
2085#if H0412_REF_PIC_LIST_RESTRICTION
2086      }
2087#endif
2088     
2089      if(refPicListModification->getRefPicListModificationFlagL0())
2090      {
2091        uiCode = 0;
2092        Int i = 0;
2093#if H0137_0138_LIST_MODIFICATION
2094        Int NumPocTotalCurr = rpcSlice->getNumPocTotalCurrMvc();
2095        if ( NumPocTotalCurr > 1 )
2096        {
2097          Int length = 1;
2098          NumPocTotalCurr --;
2099          while ( NumPocTotalCurr >>= 1) 
2100          {
2101            length ++;
2102          }
2103          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2104          {
2105            READ_CODE( length, uiCode, "list_entry_l0" );
2106            refPicListModification->setRefPicSetIdxL0(i, uiCode );
2107          }
2108        }
2109        else
2110        {
2111          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++)
2112          {
2113            refPicListModification->setRefPicSetIdxL0(i, 0 );
2114          }
2115        }
2116#else
2117        Int list_modification_idc = 0;
2118        while(list_modification_idc != 3) 
2119        {
2120          READ_UVLC( uiCode, "list_modification_idc" ); refPicListModification->setListIdcL0(i, uiCode );
2121          list_modification_idc = uiCode;
2122          if(uiCode != 3)
2123          {
2124            READ_UVLC( uiCode, "ref_pic_set_idx" ); refPicListModification->setRefPicSetIdxL0(i, uiCode );
2125          }
2126          i++;
2127        }
2128        refPicListModification->setNumberOfRefPicListModificationsL0(i-1);
2129#endif
2130      }
2131#if !H0137_0138_LIST_MODIFICATION
2132      else
2133      {
2134        refPicListModification->setNumberOfRefPicListModificationsL0(0); 
2135      }
2136#endif
2137    }
2138    else
2139    {
2140      refPicListModification->setRefPicListModificationFlagL0(0);
2141#if !H0137_0138_LIST_MODIFICATION
2142      refPicListModification->setNumberOfRefPicListModificationsL0(0);
2143#endif
2144    }
2145    if(rpcSlice->isInterB())
2146    {
2147#if H0412_REF_PIC_LIST_RESTRICTION
2148      if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
2149      {
2150        refPicListModification->setRefPicListModificationFlagL1( 0 );
2151      }
2152      else
2153      {
2154#endif
2155        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 );
2156#if H0412_REF_PIC_LIST_RESTRICTION
2157      }
2158#endif
2159      if(refPicListModification->getRefPicListModificationFlagL1())
2160      {
2161        uiCode = 0;
2162        Int i = 0;
2163#if H0137_0138_LIST_MODIFICATION
2164        Int NumPocTotalCurr = rpcSlice->getNumPocTotalCurrMvc();
2165        if ( NumPocTotalCurr > 1 )
2166        {
2167          Int length = 1;
2168          NumPocTotalCurr --;
2169          while ( NumPocTotalCurr >>= 1) 
2170          {
2171            length ++;
2172          }
2173          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2174          {
2175            READ_CODE( length, uiCode, "list_entry_l1" );
2176            refPicListModification->setRefPicSetIdxL1(i, uiCode );
2177          }
2178        }
2179        else
2180        {
2181          for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++)
2182          {
2183            refPicListModification->setRefPicSetIdxL1(i, 0 );
2184          }
2185        }
2186#else
2187        Int list_modification_idc = 0;
2188        while(list_modification_idc != 3) 
2189        {
2190          READ_UVLC( uiCode, "list_modification_idc" ); refPicListModification->setListIdcL1(i, uiCode );
2191          list_modification_idc = uiCode;
2192          if(uiCode != 3)
2193          {
2194            READ_UVLC( uiCode, "ref_pic_set_idx" ); refPicListModification->setRefPicSetIdxL1(i, uiCode );
2195          }
2196          i++;
2197        }
2198        refPicListModification->setNumberOfRefPicListModificationsL1(i-1);
2199#endif
2200      }
2201#if !H0137_0138_LIST_MODIFICATION
2202      else
2203      {
2204        refPicListModification->setNumberOfRefPicListModificationsL1(0);
2205      }
2206#endif
2207    } 
2208    else
2209    {
2210      refPicListModification->setRefPicListModificationFlagL1(0);
2211#if !H0137_0138_LIST_MODIFICATION
2212      refPicListModification->setNumberOfRefPicListModificationsL1(0);
2213#endif
2214    }
2215  }
2216  else
2217  {
2218    // initialize from previous slice
2219    pps = rpcSlice->getPPS();
2220    sps = rpcSlice->getSPS();
2221  }
2222  // ref_pic_list_combination( )
2223  //!!!KS: ref_pic_list_combination() should be conditioned on entropy_slice_flag
2224  if (rpcSlice->isInterB())
2225  {
2226    READ_FLAG( uiCode, "ref_pic_list_combination_flag" );       rpcSlice->setRefPicListCombinationFlag( uiCode ? 1 : 0 );
2227    if(uiCode)
2228    {
2229      READ_UVLC( uiCode, "num_ref_idx_lc_active_minus1" );      rpcSlice->setNumRefIdx( REF_PIC_LIST_C, uiCode + 1 );
2230     
2231#if H0412_REF_PIC_LIST_RESTRICTION
2232      if(rpcSlice->getSPS()->getListsModificationPresentFlag() )
2233      {
2234#endif
2235        READ_FLAG( uiCode, "ref_pic_list_modification_flag_lc" ); rpcSlice->setRefPicListModificationFlagLC( uiCode ? 1 : 0 );
2236        if(uiCode)
2237        {
2238          for (UInt i=0;i<rpcSlice->getNumRefIdx(REF_PIC_LIST_C);i++)
2239          {
2240            READ_FLAG( uiCode, "pic_from_list_0_flag" );
2241            rpcSlice->setListIdFromIdxOfLC(i, uiCode);
2242#if H0137_0138_LIST_MODIFICATION
2243          if (((rpcSlice->getListIdFromIdxOfLC(i) == REF_PIC_LIST_0) && (rpcSlice->getNumRefIdx( REF_PIC_LIST_0 ) == 1)) || ((rpcSlice->getListIdFromIdxOfLC(i) == REF_PIC_LIST_1) && (rpcSlice->getNumRefIdx( REF_PIC_LIST_1 ) == 1)) )
2244          {
2245            uiCode = 0;
2246          }
2247          else
2248          {
2249            READ_UVLC( uiCode, "ref_idx_list_curr" );
2250          }
2251#else
2252            READ_UVLC( uiCode, "ref_idx_list_curr" );
2253#endif
2254            rpcSlice->setRefIdxFromIdxOfLC(i, uiCode);
2255            rpcSlice->setRefIdxOfLC((RefPicList)rpcSlice->getListIdFromIdxOfLC(i), rpcSlice->getRefIdxFromIdxOfLC(i), i);
2256          }
2257        }
2258#if H0412_REF_PIC_LIST_RESTRICTION
2259      }
2260      else
2261      {
2262        rpcSlice->setRefPicListModificationFlagLC(false);
2263      }
2264#endif
2265    }
2266    else
2267    {
2268      rpcSlice->setRefPicListModificationFlagLC(false);
2269      rpcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
2270    }
2271  }
2272  else
2273  {
2274    rpcSlice->setRefPicListCombinationFlag(false);     
2275  }
2276 
2277#if H0111_MVD_L1_ZERO
2278  if (rpcSlice->isInterB())
2279  {
2280    READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
2281  }
2282#endif
2283
2284#if CABAC_INIT_FLAG
2285  rpcSlice->setCabacInitFlag( false ); // default
2286  if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
2287  {
2288    READ_FLAG(uiCode, "cabac_init_flag");
2289    rpcSlice->setCabacInitFlag( uiCode ? true : false );
2290  }
2291#else
2292  if(pps->getEntropyCodingMode() && !rpcSlice->isIntra())
2293  {
2294    READ_UVLC(uiCode, "cabac_init_idc");
2295    rpcSlice->setCABACinitIDC(uiCode);
2296  }
2297  else if (pps->getEntropyCodingMode() && rpcSlice->isIntra())
2298  {
2299    rpcSlice->setCABACinitIDC(0);
2300  }
2301#endif
2302
2303  if(!bEntropySlice)
2304  {
2305    READ_SVLC( iCode, "slice_qp_delta" ); 
2306    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
2307
2308#if H0736_AVC_STYLE_QP_RANGE
2309    assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
2310    assert( rpcSlice->getSliceQp() <=  51 );
2311#endif
2312
2313#if DBL_CONTROL
2314    if (rpcSlice->getPPS()->getDeblockingFilterControlPresent())
2315    {
2316      if ( rpcSlice->getSPS()->getUseDF() )
2317      {
2318        READ_FLAG ( uiCode, "inherit_dbl_param_from_APS_flag" ); rpcSlice->setInheritDblParamFromAPS(uiCode ? 1 : 0);
2319      } else
2320      {
2321        rpcSlice->setInheritDblParamFromAPS(0);
2322      }
2323#else
2324    READ_FLAG ( uiCode, "inherit_dbl_param_from_APS_flag" ); rpcSlice->setInheritDblParamFromAPS(uiCode ? 1 : 0);
2325#endif
2326      if(!rpcSlice->getInheritDblParamFromAPS())
2327      {
2328        READ_FLAG ( uiCode, "disable_deblocking_filter_flag" );  rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0);
2329        if(!rpcSlice->getLoopFilterDisable())
2330        {
2331          READ_SVLC( iCode, "beta_offset_div2" ); rpcSlice->setLoopFilterBetaOffset(iCode);
2332          READ_SVLC( iCode, "tc_offset_div2" ); rpcSlice->setLoopFilterTcOffset(iCode);
2333        }
2334      }
2335#if DBL_CONTROL
2336   }
2337#endif
2338    if ( rpcSlice->getSliceType() == B_SLICE )
2339    {
2340      READ_FLAG( uiCode, "collocated_from_l0_flag" );
2341      rpcSlice->setColDir(uiCode);
2342    }
2343
2344#if COLLOCATED_REF_IDX
2345    if ( rpcSlice->getSliceType() != I_SLICE &&
2346      ((rpcSlice->getColDir()==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
2347      (rpcSlice->getColDir() ==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
2348    {
2349      READ_UVLC( uiCode, "collocated_ref_idx" );
2350      rpcSlice->setColRefIdx(uiCode);
2351    }
2352#endif
2353   
2354    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPredIdc() && rpcSlice->getSliceType()==B_SLICE) )
2355    {
2356      xParsePredWeightTable(rpcSlice);
2357      rpcSlice->initWpScaling();
2358    }
2359  }
2360 
2361  if (!bEntropySlice)
2362  {
2363    if( rpcSlice->getSPS()->hasCamParInSliceHeader() )
2364    {
2365      UInt uiViewId = rpcSlice->getSPS()->getViewId();
2366      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
2367      {
2368        READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
2369        READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
2370        READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
2371        READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
2372      }
2373      rpcSlice->initMultiviewSlice( m_aaiTempScale, m_aaiTempOffset );
2374    }
2375  }
2376
2377#if ( HHI_MPI || HHI_INTER_VIEW_MOTION_PRED )
2378  #if ( HHI_MPI && HHI_INTER_VIEW_MOTION_PRED )
2379  const int iExtraMergeCandidates = ( sps->getUseMVI() || sps->getMultiviewMvPredMode() ) ? 1 : 0;
2380  #elif HHI_MPI
2381  const int iExtraMergeCandidates = sps->getUseMVI() ? 1 : 0;
2382  #else
2383  const int iExtraMergeCandidates = sps->getMultiviewMvPredMode() ? 1 : 0;
2384  #endif
2385  READ_UVLC( uiCode, "5_minus_max_num_merge_cand");
2386  rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS + iExtraMergeCandidates - uiCode);
2387  assert(rpcSlice->getMaxNumMergeCand()==(MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates));
2388#else
2389  READ_UVLC( uiCode, "5_minus_max_num_merge_cand");
2390  rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
2391  assert(rpcSlice->getMaxNumMergeCand()==MRG_MAX_NUM_CANDS_SIGNALED);
2392#endif
2393
2394  if (!bEntropySlice)
2395  {
2396    if(sps->getUseALF() && rpcSlice->getAlfEnabledFlag())
2397    {
2398      UInt uiNumLCUsInWidth   = sps->getPicWidthInLumaSamples()  / g_uiMaxCUWidth;
2399      UInt uiNumLCUsInHeight  = sps->getPicHeightInLumaSamples() / g_uiMaxCUHeight;
2400
2401      uiNumLCUsInWidth  += ( sps->getPicWidthInLumaSamples() % g_uiMaxCUWidth ) ? 1 : 0;
2402      uiNumLCUsInHeight += ( sps->getPicHeightInLumaSamples() % g_uiMaxCUHeight ) ? 1 : 0;
2403
2404      Int uiNumCUsInFrame = uiNumLCUsInWidth* uiNumLCUsInHeight; 
2405#if LCU_SYNTAX_ALF
2406      if(sps->getUseALFCoefInSlice())
2407      {
2408        alfParamSet.releaseALFParam();
2409        alfParamSet.init();
2410        Bool isAcrossSlice = sps->getLFCrossSliceBoundaryFlag();   
2411        Int numSUinLCU    = 1<< (g_uiMaxCUDepth << 1); 
2412        Int firstLCUAddr   = rpcSlice->getSliceCurStartCUAddr() / numSUinLCU; 
2413        xParseAlfParam(&alfParamSet, false, firstLCUAddr, isAcrossSlice, uiNumLCUsInWidth, uiNumLCUsInHeight);
2414      }
2415
2416      if(!sps->getUseALFCoefInSlice())
2417      {
2418#endif
2419      xParseAlfCuControlParam(alfCUCtrl, uiNumCUsInFrame);
2420#if LCU_SYNTAX_ALF
2421      }
2422#endif
2423
2424    }
2425  }
2426 
2427  //!!!KS: The following syntax is not aligned with the working draft, TRACE support needs to be added
2428  rpcSlice->setTileMarkerFlag ( 0 ); // default
2429  if (!bEntropySlice)
2430  {
2431#if !REMOVE_TILE_DEPENDENCE
2432    if (sps->getTileBoundaryIndependenceIdr())
2433    {   
2434#endif
2435    xReadCode(1, uiCode); // read flag indicating if tile markers transmitted
2436    rpcSlice->setTileMarkerFlag( uiCode );
2437#if !REMOVE_TILE_DEPENDENCE
2438    }
2439#endif
2440  }
2441
2442#if TILES_WPP_ENTRY_POINT_SIGNALLING
2443  Int tilesOrEntropyCodingSyncIdc = rpcSlice->getSPS()->getTilesOrEntropyCodingSyncIdc();
2444  UInt *entryPointOffset          = NULL;
2445  UInt numEntryPointOffsets, offsetLenMinus1;
2446
2447  rpcSlice->setNumEntryPointOffsets ( 0 ); // default
2448 
2449  if (tilesOrEntropyCodingSyncIdc>0)
2450  {
2451    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
2452    if (numEntryPointOffsets>0)
2453    {
2454      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
2455    }
2456    entryPointOffset = new UInt[numEntryPointOffsets];
2457    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
2458    {
2459      Int bitsRead = m_pcBitstream->getNumBitsRead();
2460      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
2461      entryPointOffset[ idx ] = uiCode;
2462      if ( idx == 0 && tilesOrEntropyCodingSyncIdc == 2 )
2463      {
2464        // Subtract distance from NALU header start to provide WPP 0-th substream the correct size.
2465        entryPointOffset[ idx ] -= ( bitsRead + numEntryPointOffsets*(offsetLenMinus1+1) ) >> 3;
2466      }
2467    }
2468  }
2469
2470  if ( tilesOrEntropyCodingSyncIdc == 1 ) // tiles
2471  {
2472    rpcSlice->setTileLocationCount( numEntryPointOffsets );
2473
2474    UInt prevPos = 0;
2475    for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
2476    {
2477      rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
2478      prevPos += entryPointOffset[ idx ];
2479    }
2480  }
2481  else if ( tilesOrEntropyCodingSyncIdc == 2 ) // wavefront
2482  {
2483    Int numSubstreams = pps->getNumSubstreams();
2484    rpcSlice->allocSubstreamSizes(numSubstreams);
2485    UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
2486    for (Int idx=0; idx<numSubstreams-1; idx++)
2487    {
2488      if ( idx < numEntryPointOffsets )
2489      {
2490        pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
2491      }
2492      else
2493      {
2494        pSubstreamSizes[ idx ] = 0;
2495      }
2496    }
2497  }
2498
2499  if (entryPointOffset)
2500  {
2501    delete [] entryPointOffset;
2502  }
2503#else
2504#if WPP_SIMPLIFICATION
2505  if (pps->getNumSubstreams() > 1)
2506#else
2507  if (pps->getEntropyCodingSynchro())
2508#endif
2509  {
2510    UInt uiNumSubstreams = pps->getNumSubstreams();
2511    rpcSlice->allocSubstreamSizes(uiNumSubstreams);
2512    UInt *puiSubstreamSizes = rpcSlice->getSubstreamSizes();
2513
2514    for (UInt ui = 0; ui+1 < uiNumSubstreams; ui++)
2515    {
2516      xReadCode(2, uiCode);
2517     
2518      switch ( uiCode )
2519      {
2520      case 0:
2521        xReadCode(8,  uiCode);
2522        break;
2523      case 1:
2524        xReadCode(16, uiCode);
2525        break;
2526      case 2:
2527        xReadCode(24, uiCode);
2528        break;
2529      case 3:
2530        xReadCode(32, uiCode);
2531        break;
2532      default:
2533        printf("Error in parseSliceHeader\n");
2534        exit(-1);
2535        break;
2536      }
2537      puiSubstreamSizes[ui] = uiCode;
2538    }
2539  }
2540#endif
2541
2542  if (!bEntropySlice)
2543  {
2544    // Reading location information
2545#if !REMOVE_TILE_DEPENDENCE
2546    if (sps->getTileBoundaryIndependenceIdr())
2547    {   
2548#endif
2549#if !TILES_WPP_ENTRY_POINT_SIGNALLING
2550      xReadCode(1, uiCode); // read flag indicating if location information signaled in slice header
2551      Bool bTileLocationInformationInSliceHeaderFlag = (uiCode)? true : false;
2552
2553      if (bTileLocationInformationInSliceHeaderFlag)
2554      {
2555        // location count
2556        xReadCode(5, uiCode); // number of tiles for which location information signaled
2557        rpcSlice->setTileLocationCount ( uiCode + 1 );
2558
2559        xReadCode(5, uiCode); // number of bits used by diff
2560        Int iBitsUsedByDiff = uiCode + 1;
2561
2562        // read out tile start location
2563        Int iLastSize = 0;
2564        for (UInt uiIdx=0; uiIdx<rpcSlice->getTileLocationCount(); uiIdx++)
2565        {
2566          Int iAbsDiff, iCurSize, iCurDiff;
2567          if (uiIdx==0)
2568          {
2569            xReadCode(iBitsUsedByDiff-1, uiCode); iAbsDiff  = uiCode;
2570            rpcSlice->setTileLocation( uiIdx, iAbsDiff );
2571            iCurDiff  = iAbsDiff;
2572            iLastSize = iAbsDiff;
2573          }
2574          else
2575          {
2576            xReadCode(1, uiCode); // read sign
2577            Int iSign = (uiCode) ? -1 : +1;
2578
2579            xReadCode(iBitsUsedByDiff-1, uiCode); iAbsDiff  = uiCode;
2580            iCurDiff  = (iSign) * iAbsDiff;
2581            iCurSize  = iLastSize + iCurDiff;
2582            iLastSize = iCurSize;
2583            rpcSlice->setTileLocation( uiIdx, rpcSlice->getTileLocation( uiIdx-1 ) + iCurSize ); // calculate byte location
2584          }
2585        }
2586      }
2587#endif
2588
2589      // read out trailing bits
2590    m_pcBitstream->readOutTrailingBits();
2591#if !REMOVE_TILE_DEPENDENCE
2592    }
2593#endif
2594  }
2595  return;
2596}
2597
2598Void TDecCavlc::xParseAlfCuControlParam(AlfCUCtrlInfo& cAlfParam, Int iNumCUsInPic)
2599{
2600  UInt uiSymbol;
2601  Int iSymbol;
2602
2603  READ_FLAG (uiSymbol, "alf_cu_control_flag");
2604  cAlfParam.cu_control_flag = uiSymbol;
2605  if (cAlfParam.cu_control_flag)
2606  {
2607    READ_UVLC (uiSymbol, "alf_cu_control_max_depth"); 
2608    cAlfParam.alf_max_depth = uiSymbol;
2609
2610    READ_SVLC (iSymbol, "alf_length_cu_control_info");
2611    cAlfParam.num_alf_cu_flag = (UInt)(iSymbol + iNumCUsInPic);
2612
2613    cAlfParam.alf_cu_flag.resize(cAlfParam.num_alf_cu_flag);
2614
2615    for(UInt i=0; i< cAlfParam.num_alf_cu_flag; i++)
2616    {
2617      READ_FLAG (cAlfParam.alf_cu_flag[i], "alf_cu_flag");
2618    }
2619  }
2620}
2621
2622#if !CABAC_INIT_FLAG
2623Void TDecCavlc::resetEntropy          (TComSlice* pcSlice)
2624{
2625}
2626#endif
2627
2628Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
2629{
2630  ruiBit = false;
2631  Int iBitsLeft = m_pcBitstream->getNumBitsLeft();
2632  if(iBitsLeft <= 8)
2633  {
2634    UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft);
2635    if (uiPeekValue == (1<<(iBitsLeft-1)))
2636    {
2637      ruiBit = true;
2638    }
2639  }
2640}
2641
2642Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2643{
2644  assert(0);
2645}
2646
2647#if LGE_ILLUCOMP_B0045
2648Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2649{
2650  assert(0);
2651}
2652#endif
2653
2654#if HHI_INTER_VIEW_MOTION_PRED
2655Void TDecCavlc::parseMVPIdx( Int& riMVPIdx, Int iAMVPCands )
2656#else
2657Void TDecCavlc::parseMVPIdx( Int& riMVPIdx )
2658#endif
2659{
2660  assert(0);
2661}
2662
2663Void TDecCavlc::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2664{
2665  assert(0);
2666}
2667
2668Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2669{
2670  assert(0);
2671}
2672
2673Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2674{
2675  assert(0);
2676}
2677
2678/** Parse I_PCM information.
2679 * \param pcCU pointer to CU
2680 * \param uiAbsPartIdx CU index
2681 * \param uiDepth CU depth
2682 * \returns Void
2683 *
2684 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
2685 */
2686Void TDecCavlc::parseIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2687{
2688#if BURST_IPCM
2689  assert(0);
2690#else
2691  UInt uiSymbol;
2692
2693  xReadFlag( uiSymbol );
2694
2695  if ( uiSymbol )
2696  {
2697    Bool bIpcmFlag   = true;
2698
2699    xReadPCMAlignZero();
2700
2701    pcCU->setPartSizeSubParts  ( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
2702    pcCU->setSizeSubParts      ( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth );
2703    pcCU->setIPCMFlagSubParts  ( bIpcmFlag, uiAbsPartIdx, uiDepth );
2704
2705    UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
2706    UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
2707    UInt uiChromaOffset = uiLumaOffset>>2;
2708
2709    Pel* piPCMSample;
2710    UInt uiWidth;
2711    UInt uiHeight;
2712    UInt uiSampleBits;
2713    UInt uiX, uiY;
2714
2715    piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
2716    uiWidth = pcCU->getWidth(uiAbsPartIdx);
2717    uiHeight = pcCU->getHeight(uiAbsPartIdx);
2718    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
2719
2720    for(uiY = 0; uiY < uiHeight; uiY++)
2721    {
2722      for(uiX = 0; uiX < uiWidth; uiX++)
2723      {
2724        UInt uiSample;
2725        xReadCode(uiSampleBits, uiSample);
2726
2727        piPCMSample[uiX] = uiSample;
2728      }
2729      piPCMSample += uiWidth;
2730    }
2731
2732    piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
2733    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
2734    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
2735    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
2736
2737    for(uiY = 0; uiY < uiHeight; uiY++)
2738    {
2739      for(uiX = 0; uiX < uiWidth; uiX++)
2740      {
2741        UInt uiSample;
2742        xReadCode(uiSampleBits, uiSample);
2743        piPCMSample[uiX] = uiSample;
2744      }
2745      piPCMSample += uiWidth;
2746    }
2747
2748    piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
2749    uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
2750    uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
2751    uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
2752
2753    for(uiY = 0; uiY < uiHeight; uiY++)
2754    {
2755      for(uiX = 0; uiX < uiWidth; uiX++)
2756      {
2757        UInt uiSample;
2758        xReadCode(uiSampleBits, uiSample);
2759        piPCMSample[uiX] = uiSample;
2760      }
2761      piPCMSample += uiWidth;
2762    }
2763  }
2764#endif
2765}
2766
2767Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2768{ 
2769  assert(0);
2770}
2771
2772Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2773{
2774  assert(0);
2775}
2776
2777Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
2778{
2779  assert(0);
2780}
2781
2782Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
2783{
2784  assert(0);
2785}
2786
2787Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
2788{
2789  assert(0);
2790}
2791
2792Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2793{
2794#if H0736_AVC_STYLE_QP_RANGE
2795  Int qp;
2796#else
2797  UInt uiQp;
2798#endif
2799  Int  iDQp;
2800 
2801  xReadSvlc( iDQp );
2802
2803#if H0736_AVC_STYLE_QP_RANGE
2804  Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
2805  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
2806#else
2807  uiQp = pcCU->getRefQP( uiAbsPartIdx ) + iDQp;
2808#endif
2809
2810  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)))<<(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)) ;
2811  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
2812
2813#if H0736_AVC_STYLE_QP_RANGE
2814  pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth );
2815#else
2816  pcCU->setQPSubParts( uiQp, uiAbsQpCUPartIdx, uiQpCUDepth );
2817#endif
2818}
2819
2820Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
2821{
2822  assert(0);
2823}
2824
2825Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
2826{
2827  assert(0);
2828}
2829
2830Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
2831{
2832  assert(0);
2833}
2834
2835Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
2836{
2837  assert(0);
2838}
2839
2840
2841Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
2842{
2843  assert(0);
2844}
2845
2846Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
2847{
2848  assert(0);
2849}
2850
2851#if HHI_INTER_VIEW_RESIDUAL_PRED
2852Void
2853TDecCavlc::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth )
2854{
2855  assert(0);
2856}
2857#endif
2858
2859#if RWTH_SDC_DLT_B0036
2860Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2861{
2862  assert(0);
2863}
2864Void TDecCavlc::parseSDCPredMode    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
2865{
2866  assert(0);
2867}
2868Void TDecCavlc::parseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
2869{
2870  assert(0);
2871}
2872#endif
2873
2874// ====================================================================================================================
2875// Protected member functions
2876// ====================================================================================================================
2877
2878Void TDecCavlc::xReadCode (UInt uiLength, UInt& ruiCode)
2879{
2880  assert ( uiLength > 0 );
2881  m_pcBitstream->read (uiLength, ruiCode);
2882}
2883
2884Void TDecCavlc::xReadUvlc( UInt& ruiVal)
2885{
2886  UInt uiVal = 0;
2887  UInt uiCode = 0;
2888  UInt uiLength;
2889  m_pcBitstream->read( 1, uiCode );
2890 
2891  if( 0 == uiCode )
2892  {
2893    uiLength = 0;
2894   
2895    while( ! ( uiCode & 1 ))
2896    {
2897      m_pcBitstream->read( 1, uiCode );
2898      uiLength++;
2899    }
2900   
2901    m_pcBitstream->read( uiLength, uiVal );
2902   
2903    uiVal += (1 << uiLength)-1;
2904  }
2905 
2906  ruiVal = uiVal;
2907}
2908
2909Void TDecCavlc::xReadSvlc( Int& riVal)
2910{
2911  UInt uiBits = 0;
2912  m_pcBitstream->read( 1, uiBits );
2913  if( 0 == uiBits )
2914  {
2915    UInt uiLength = 0;
2916   
2917    while( ! ( uiBits & 1 ))
2918    {
2919      m_pcBitstream->read( 1, uiBits );
2920      uiLength++;
2921    }
2922   
2923    m_pcBitstream->read( uiLength, uiBits );
2924   
2925    uiBits += (1 << uiLength);
2926    riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
2927  }
2928  else
2929  {
2930    riVal = 0;
2931  }
2932}
2933
2934Void TDecCavlc::xReadFlag (UInt& ruiCode)
2935{
2936  m_pcBitstream->read( 1, ruiCode );
2937}
2938
2939/** Parse PCM alignment zero bits.
2940 * \returns Void
2941 */
2942Void TDecCavlc::xReadPCMAlignZero( )
2943{
2944  UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned();
2945
2946  if(uiNumberOfBits)
2947  {
2948    UInt uiBits;
2949    UInt uiSymbol;
2950
2951    for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++)
2952    {
2953      xReadFlag( uiSymbol );
2954
2955      if(uiSymbol)
2956      {
2957        printf("\nWarning! pcm_align_zero include a non-zero value.\n");
2958      }
2959    }
2960  }
2961}
2962
2963Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol )
2964{
2965  if (uiMaxSymbol == 0)
2966  {
2967    ruiSymbol = 0;
2968    return;
2969  }
2970 
2971  xReadFlag( ruiSymbol );
2972 
2973  if (ruiSymbol == 0 || uiMaxSymbol == 1)
2974  {
2975    return;
2976  }
2977 
2978  UInt uiSymbol = 0;
2979  UInt uiCont;
2980 
2981  do
2982  {
2983    xReadFlag( uiCont );
2984    uiSymbol++;
2985  }
2986  while( uiCont && (uiSymbol < uiMaxSymbol-1) );
2987 
2988  if( uiCont && (uiSymbol == uiMaxSymbol-1) )
2989  {
2990    uiSymbol++;
2991  }
2992 
2993  ruiSymbol = uiSymbol;
2994}
2995
2996Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol )
2997{
2998  UInt uiSymbol ;
2999  UInt uiCount = 0;
3000  do
3001  {
3002    xReadFlag( uiSymbol );
3003    uiCount++;
3004  }
3005  while( uiSymbol && (uiCount != 13));
3006 
3007  ruiSymbol = uiCount-1;
3008 
3009  if( uiSymbol )
3010  {
3011    xReadEpExGolomb( uiSymbol, 0 );
3012    ruiSymbol += uiSymbol+1;
3013  }
3014 
3015  return;
3016}
3017
3018Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
3019{
3020  UInt uiSymbol = 0;
3021  UInt uiBit = 1;
3022 
3023 
3024  while( uiBit )
3025  {
3026    xReadFlag( uiBit );
3027    uiSymbol += uiBit << uiCount++;
3028  }
3029 
3030  uiCount--;
3031  while( uiCount-- )
3032  {
3033    xReadFlag( uiBit );
3034    uiSymbol += uiBit << uiCount;
3035  }
3036 
3037  ruiSymbol = uiSymbol;
3038 
3039  return;
3040}
3041
3042UInt TDecCavlc::xGetBit()
3043{
3044  UInt ruiCode;
3045  m_pcBitstream->read( 1, ruiCode );
3046  return ruiCode;
3047}
3048
3049
3050/** parse explicit wp tables
3051 * \param TComSlice* pcSlice
3052 * \returns Void
3053 */
3054Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
3055{
3056  wpScalingParam  *wp;
3057  Bool            bChroma     = true; // color always present in HEVC ?
3058  TComPPS*        pps         = pcSlice->getPPS();
3059  SliceType       eSliceType  = pcSlice->getSliceType();
3060  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
3061  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
3062  UInt            uiMode      = 0;
3063
3064  if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()==0) )
3065    uiMode = 1; // explicit
3066  else if ( eSliceType==B_SLICE && pps->getWPBiPredIdc()==2 )
3067    uiMode = 2; // implicit
3068  else if (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag())
3069    uiMode = 3; // combined explicit
3070
3071  if ( uiMode == 1 )  // explicit
3072  {
3073    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) explicit...\n", pcSlice->getPOC());
3074    Int iDeltaDenom;
3075    // decode delta_luma_log2_weight_denom :
3076    READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3077    if( bChroma ) 
3078    {
3079      READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
3080      assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3081      uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3082    }
3083
3084    for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
3085    {
3086      RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
3087      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
3088      {
3089        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3090
3091        wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3092        wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3093        wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3094
3095        UInt  uiCode;
3096        READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
3097        wp[0].bPresentFlag = ( uiCode == 1 );
3098        if ( wp[0].bPresentFlag ) 
3099        {
3100          Int iDeltaWeight;
3101          READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
3102          wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3103          READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
3104        }
3105        else 
3106        {
3107          wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3108          wp[0].iOffset = 0;
3109        }
3110        if ( bChroma ) 
3111        {
3112          READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
3113          wp[1].bPresentFlag = ( uiCode == 1 );
3114          wp[2].bPresentFlag = ( uiCode == 1 );
3115          if ( wp[1].bPresentFlag ) 
3116          {
3117            for ( Int j=1 ; j<3 ; j++ ) 
3118            {
3119              Int iDeltaWeight;
3120              READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
3121              wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3122
3123              Int iDeltaChroma;
3124              READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
3125              wp[j].iOffset = iDeltaChroma - ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) + (g_uiIBDI_MAX>>1);
3126            }
3127          }
3128          else 
3129          {
3130            for ( Int j=1 ; j<3 ; j++ ) 
3131            {
3132              wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3133              wp[j].iOffset = 0;
3134            }
3135          }
3136        }
3137      }
3138
3139      for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
3140      {
3141        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
3142
3143        wp[0].bPresentFlag = false;
3144        wp[1].bPresentFlag = false;
3145        wp[2].bPresentFlag = false;
3146      }
3147    }
3148  }
3149  else if ( uiMode == 2 )  // implicit
3150  {
3151    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) implicit...\n", pcSlice->getPOC());
3152  }
3153  else if ( uiMode == 3 )  // combined explicit
3154  {
3155    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) combined explicit...\n", pcSlice->getPOC());
3156    Int iDeltaDenom;
3157    // decode delta_luma_log2_weight_denom :
3158    READ_UVLC ( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
3159    if( bChroma ) 
3160    {
3161      READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );      // ue(v): delta_chroma_log2_weight_denom
3162      assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
3163      uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
3164    }
3165
3166    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ ) 
3167    {
3168      pcSlice->getWpScalingLC(iRefIdx, wp);
3169
3170      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
3171      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3172      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
3173
3174      UInt  uiCode;
3175      READ_FLAG( uiCode, "luma_weight_lc_flag" );                  // u(1): luma_weight_lc_flag
3176      wp[0].bPresentFlag = ( uiCode == 1 );
3177      if ( wp[0].bPresentFlag ) 
3178      {
3179        Int iDeltaWeight;
3180        READ_SVLC( iDeltaWeight, "delta_luma_weight_lc" );          // se(v): delta_luma_weight_lc
3181        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
3182        READ_SVLC( wp[0].iOffset, "luma_offset_lc" );               // se(v): luma_offset_lc
3183      }
3184      else 
3185      {
3186        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
3187        wp[0].iOffset = 0;
3188      }
3189      if ( bChroma ) 
3190      {
3191        READ_FLAG( uiCode, "chroma_weight_lc_flag" );                // u(1): chroma_weight_lc_flag
3192        wp[1].bPresentFlag = ( uiCode == 1 );
3193        wp[2].bPresentFlag = ( uiCode == 1 );
3194        if ( wp[1].bPresentFlag ) 
3195        {
3196          for ( Int j=1 ; j<3 ; j++ ) 
3197          {
3198            Int iDeltaWeight;
3199            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lc" );      // se(v): delta_chroma_weight_lc
3200            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
3201
3202            Int iDeltaChroma;
3203            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lc" );      // se(v): delta_chroma_offset_lc
3204            wp[j].iOffset = iDeltaChroma - ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) + (g_uiIBDI_MAX>>1);
3205          }
3206        }
3207        else 
3208        {
3209          for ( Int j=1 ; j<3 ; j++ ) 
3210          {
3211            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
3212            wp[j].iOffset = 0;
3213          }
3214        }
3215      }
3216    }
3217
3218    for ( Int iRefIdx=pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx<2*MAX_NUM_REF ; iRefIdx++ ) 
3219    {
3220      pcSlice->getWpScalingLC(iRefIdx, wp);
3221
3222      wp[0].bPresentFlag = false;
3223      wp[1].bPresentFlag = false;
3224      wp[2].bPresentFlag = false;
3225    }
3226  }
3227  else
3228  {
3229    printf("\n wrong weight pred table syntax \n ");
3230    assert(0);
3231  }
3232}
3233
3234/** decode quantization matrix
3235 * \param scalingList quantization matrix information
3236 */
3237Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
3238{
3239  UInt  code, sizeId, listId;
3240  Bool scalingListPredModeFlag;
3241  READ_FLAG( code, "scaling_list_present_flag" );
3242  scalingList->setScalingListPresentFlag ( (code==1)?true:false );
3243  if(scalingList->getScalingListPresentFlag() == false)
3244  {
3245      //for each size
3246    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3247    {
3248      for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
3249      {
3250        READ_FLAG( code, "scaling_list_pred_mode_flag");
3251        scalingListPredModeFlag = (code) ? true : false;
3252        if(!scalingListPredModeFlag) //Copy Mode
3253        {
3254          READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
3255          scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code+1)));
3256#if SCALING_LIST
3257          if( sizeId > SCALING_LIST_8x8 )
3258          {
3259            scalingList->setScalingListDC(sizeId,listId,scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId)));
3260          }
3261#endif
3262          scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
3263         
3264        }
3265        else //DPCM Mode
3266        {
3267          xDecodeScalingList(scalingList, sizeId, listId);
3268        }
3269      }
3270    }
3271  }
3272
3273  return;
3274}
3275/** decode DPCM
3276 * \param scalingList  quantization matrix information
3277 * \param sizeId size index
3278 * \param listId list index
3279 */
3280Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
3281{
3282#if SCALING_LIST
3283  Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
3284  Int data;
3285  Int scalingListDcCoefMinus8 = 0;
3286  Int nextCoef = SCALING_LIST_START_VALUE;
3287  UInt* scan  = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2 ];
3288  Bool stopNow = false;
3289  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3290
3291  scalingList->setUseDefaultScalingMatrixFlag(sizeId,listId,false);
3292  if( sizeId > SCALING_LIST_8x8 )
3293  {
3294    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
3295    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
3296    if(scalingListDcCoefMinus8 == -8)
3297    {
3298      scalingList->processDefaultMarix(sizeId,listId);
3299    }
3300  }
3301
3302  if( !scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
3303  {
3304    for(i = 0; i < coefNum && !stopNow ; i++)
3305    {
3306      READ_SVLC( data, "scaling_list_delta_coef");
3307      nextCoef = (nextCoef + data + 256 ) % 256;
3308      if(sizeId < SCALING_LIST_16x16)
3309      {
3310        if( i == 0 && nextCoef == 0 )
3311        {
3312          scalingList->processDefaultMarix(sizeId,listId);
3313          stopNow = true;
3314        }
3315      }
3316      if(!stopNow)
3317      {
3318        dst[scan[i]] = nextCoef;
3319      }
3320    }
3321  }
3322#else
3323  Int i,coefNum = g_scalingListSize[sizeId];
3324  Int data;
3325  Int nextCoef = SCALING_LIST_START_VALUE;
3326  UInt* scan  = g_auiFrameScanXY [ sizeId + 1 ];
3327  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
3328
3329  for(i = 0; i < coefNum; i++)
3330  {
3331    READ_SVLC( data, "scaling_list_delta_coef");
3332    nextCoef = (nextCoef + data + 256 ) % 256;
3333    dst[scan[i]] = nextCoef;
3334  }
3335#endif
3336}
3337
3338Void TDecCavlc::parseDFFlag(UInt& ruiVal, const Char *pSymbolName)
3339{
3340  READ_FLAG(ruiVal, pSymbolName);
3341}
3342Void TDecCavlc::parseDFSvlc(Int&  riVal, const Char *pSymbolName)
3343{
3344  READ_SVLC(riVal, pSymbolName);
3345}
3346
3347Bool TDecCavlc::xMoreRbspData()
3348{ 
3349  Int bitsLeft = m_pcBitstream->getNumBitsLeft();
3350
3351  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
3352  if (bitsLeft > 8)
3353  {
3354    return true;
3355  }
3356
3357  UChar lastByte = m_pcBitstream->peekBits(bitsLeft);
3358  Int cnt = bitsLeft;
3359
3360  // remove trailing bits equal to zero
3361  while ((cnt>0) && ((lastByte & 1) == 0))
3362  {
3363    lastByte >>= 1;
3364    cnt--;
3365  }
3366  // remove bit equal to one
3367  cnt--;
3368
3369  // we should not have a negative number of bits
3370  assert (cnt>=0);
3371
3372  // we have more data, if cnt is not zero
3373  return (cnt>0);
3374}
3375
3376//! \}
Note: See TracBrowser for help on using the repository browser.