Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibDecoder


Ignore:
Timestamp:
1 Sep 2013, 22:47:26 (11 years ago)
Author:
tech
Message:

Merged DEV-2.0-dev0@604.

Location:
trunk/source/Lib/TLibDecoder
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibDecoder/AnnexBread.cpp

    r56 r608  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3131 * THE POSSIBILITY OF SUCH DAMAGE.
    3232 */
     33
     34/**
     35 \file     AnnexBread.cpp
     36 \brief    reading functions for Annex B byte streams
     37 */
     38
    3339
    3440#include <stdint.h>
     
    111117   */
    112118  /* NB, (unsigned)x > 2 implies n!=0 && n!=1 */
    113   while (bs.eofBeforeNBytes(24/8) || bs.peekBytes(24/8) > 1) // since 0x000002 tile marker may exist in the bitstream
     119  while (bs.eofBeforeNBytes(24/8) || bs.peekBytes(24/8) > 2)
    114120  {
    115121    nalUnit.push_back(bs.readByte());
     
    147153 *         otherwise true.
    148154 */
    149 bool
     155Bool
    150156byteStreamNALUnit(
    151157  InputByteStream& bs,
     
    153159  AnnexBStats& stats)
    154160{
    155   bool eof = false;
     161  Bool eof = false;
    156162  try
    157163  {
     
    162168    eof = true;
    163169  }
    164   stats.m_numBytesInNALUnit = unsigned(nalUnit.size());
     170  stats.m_numBytesInNALUnit = UInt(nalUnit.size());
    165171  return eof;
    166172}
  • trunk/source/Lib/TLibDecoder/AnnexBread.h

    r56 r608  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3232 */
    3333
     34/**
     35 \file     AnnexBread.h
     36 \brief    reading functions for Annex B byte streams
     37 */
     38
    3439#pragma once
    3540
     
    3742#include <istream>
    3843#include <vector>
     44
     45#include "../TLibCommon/TypeDef.h"
    3946
    4047//! \ingroup TLibDecoder
     
    7582   * n bytes.
    7683   */
    77   bool eofBeforeNBytes(unsigned n)
     84  Bool eofBeforeNBytes(UInt n)
    7885  {
    7986    assert(n <= 4);
     
    8491    try
    8592    {
    86       for (unsigned i = 0; i < n; i++)
     93      for (UInt i = 0; i < n; i++)
    8794      {
    8895        m_FutureBytes = (m_FutureBytes << 8) | m_Input.get();
     
    109116   *
    110117   */
    111   uint32_t peekBytes(unsigned n)
     118  uint32_t peekBytes(UInt n)
    112119  {
    113120    eofBeforeNBytes(n);
     
    139146   * the return value.
    140147   */
    141   uint32_t readBytes(unsigned n)
     148  uint32_t readBytes(UInt n)
    142149  {
    143150    uint32_t val = 0;
    144     for (unsigned i = 0; i < n; i++)
     151    for (UInt i = 0; i < n; i++)
    145152      val = (val << 8) | readByte();
    146153    return val;
     
    148155
    149156private:
    150   unsigned m_NumFutureBytes; /* number of valid bytes in m_FutureBytes */
     157  UInt m_NumFutureBytes; /* number of valid bytes in m_FutureBytes */
    151158  uint32_t m_FutureBytes; /* bytes that have been peeked */
    152159  std::istream& m_Input; /* Input stream to read from */
     
    158165struct AnnexBStats
    159166{
    160   unsigned m_numLeadingZero8BitsBytes;
    161   unsigned m_numZeroByteBytes;
    162   unsigned m_numStartCodePrefixBytes;
    163   unsigned m_numBytesInNALUnit;
    164   unsigned m_numTrailingZero8BitsBytes;
     167  UInt m_numLeadingZero8BitsBytes;
     168  UInt m_numZeroByteBytes;
     169  UInt m_numStartCodePrefixBytes;
     170  UInt m_numBytesInNALUnit;
     171  UInt m_numTrailingZero8BitsBytes;
    165172
    166173  AnnexBStats& operator+=(const AnnexBStats& rhs)
     
    175182};
    176183
    177 bool byteStreamNALUnit(InputByteStream& bs, std::vector<uint8_t>& nalUnit, AnnexBStats& stats);
     184Bool byteStreamNALUnit(InputByteStream& bs, std::vector<uint8_t>& nalUnit, AnnexBStats& stats);
    178185
    179186//! \}
  • trunk/source/Lib/TLibDecoder/NALread.cpp

    r296 r608  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3232 */
    3333
     34/**
     35 \file     NALread.cpp
     36 \brief    reading funtionality for NAL units
     37 */
     38
     39
    3440#include <vector>
    3541#include <algorithm>
     
    4450//! \ingroup TLibDecoder
    4551//! \{
    46 static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *pcBitstream)
     52static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit)
    4753{
    48   unsigned zeroCount = 0;
     54  UInt zeroCount = 0;
    4955  vector<uint8_t>::iterator it_read, it_write;
    5056
    51   UInt *auiStoredTileMarkerLocation = new UInt[MAX_MARKER_PER_NALU];
    52   // Remove tile markers and note the bitstream location
    53   for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++ )
     57  UInt pos = 0;
     58  bitstream->clearEmulationPreventionByteLocation();
     59  for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++, pos++)
    5460  {
    55     Bool bTileMarkerFound = false;
    56     if ( ( it_read - nalUnitBuf.begin() ) < ( nalUnitBuf.size() - 2 ) )
    57     {
    58       if ( (*(it_read) == 0x00) && (*(it_read+1) == 0x00) && (*(it_read+2) == 0x02) ) // tile marker detected
    59       {
    60         it_read += 2;
    61         UInt uiDistance  = (UInt) (it_write - nalUnitBuf.begin());
    62         UInt uiCount     = pcBitstream->getTileMarkerLocationCount();
    63         bTileMarkerFound = true;
    64         pcBitstream->setTileMarkerLocation( uiCount, uiDistance );
    65         auiStoredTileMarkerLocation[uiCount] = uiDistance;
    66         pcBitstream->setTileMarkerLocationCount( uiCount + 1 );
    67        
    68       }
    69     }
    70 
    71     if (!bTileMarkerFound)
    72     {
    73       *it_write = *it_read;
    74       it_write++;
    75     }
    76   }
    77   nalUnitBuf.resize(it_write - nalUnitBuf.begin());
    78 
    79   for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++)
    80   {
     61    assert(zeroCount < 2 || *it_read >= 0x03);
    8162    if (zeroCount == 2 && *it_read == 0x03)
    8263    {
    83       // update tile marker location
    84       UInt uiDistance = (UInt) (it_read - nalUnitBuf.begin());
    85       for (UInt uiIdx=0; uiIdx<pcBitstream->getTileMarkerLocationCount(); uiIdx++)
    86       {
    87         if (auiStoredTileMarkerLocation[ uiIdx ] >= uiDistance)
    88         {
    89           pcBitstream->setTileMarkerLocation( uiIdx, pcBitstream->getTileMarkerLocation( uiIdx )-1 );
    90         }
    91       }
     64      bitstream->pushEmulationPreventionByteLocation( pos );
     65      pos++;
    9266      it_read++;
    9367      zeroCount = 0;
     68      if (it_read == nalUnitBuf.end())
     69      {
     70        break;
     71      }
    9472    }
    9573    zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0;
    9674    *it_write = *it_read;
    9775  }
     76  assert(zeroCount == 0);
     77 
     78  if (isVclNalUnit)
     79  {
     80    // Remove cabac_zero_word from payload if present
     81    Int n = 0;
     82   
     83    while (it_write[-1] == 0x00)
     84    {
     85      it_write--;
     86      n++;
     87    }
     88   
     89    if (n > 0)
     90    {
     91      printf("\nDetected %d instances of cabac_zero_word", n/2);     
     92    }
     93  }
    9894
    9995  nalUnitBuf.resize(it_write - nalUnitBuf.begin());
    100   delete [] auiStoredTileMarkerLocation;
    10196}
    10297
     98Void readNalUnitHeader(InputNALUnit& nalu)
     99{
     100  TComInputBitstream& bs = *nalu.m_Bitstream;
     101
     102  Bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
     103  assert(forbidden_zero_bit == 0);
     104  nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
     105#if H_MV
     106  nalu.m_layerId = bs.read(6);                 // layerId
     107#else
     108  nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
     109  assert(nalu.m_reservedZero6Bits == 0);
     110#endif
     111  nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
     112
     113  if ( nalu.m_temporalId )
     114  {
     115    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
     116         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
     117         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
     118         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL
     119         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
     120         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
     121         && nalu.m_nalUnitType != NAL_UNIT_VPS
     122         && nalu.m_nalUnitType != NAL_UNIT_SPS
     123         && nalu.m_nalUnitType != NAL_UNIT_EOS
     124         && nalu.m_nalUnitType != NAL_UNIT_EOB );
     125  }
     126  else
     127  {
     128    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R
     129         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
     130         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
     131         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
     132  }
     133}
    103134/**
    104135 * create a NALunit structure with given header values and storage for
     
    109140  /* perform anti-emulation prevention */
    110141  TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
    111   convertPayloadToRBSP(nalUnitBuf, pcBitstream);
    112 
     142  convertPayloadToRBSP(nalUnitBuf, pcBitstream, (nalUnitBuf[0] & 64) == 0);
     143 
    113144  nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
    114   // copy the tile marker location information
    115   nalu.m_Bitstream->setTileMarkerLocationCount( pcBitstream->getTileMarkerLocationCount() );
    116   for (UInt uiIdx=0; uiIdx < nalu.m_Bitstream->getTileMarkerLocationCount(); uiIdx++)
    117   {
    118     nalu.m_Bitstream->setTileMarkerLocation( uiIdx, pcBitstream->getTileMarkerLocation(uiIdx) );
    119   }
     145  nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation());
    120146  delete pcBitstream;
    121   TComInputBitstream& bs = *nalu.m_Bitstream;
    122 
    123   bool forbidden_zero_bit = bs.read(1);
    124   assert(forbidden_zero_bit == 0);
    125 
    126   nalu.m_nalRefFlag  = (bs.read(1) != 0 );
    127   nalu.m_nalUnitType = (NalUnitType) bs.read(6);
    128 
    129 #if QC_MVHEVC_B0046
    130   //nalu.m_layerId    = bs.read(6);
    131   nalu.m_layerId    = bs.read(5);
    132   nalu.m_temporalId = bs.read(3) - 1;
    133 #else
    134   nalu.m_temporalId = bs.read(3);
    135  //  unsigned reserved_one_5bits = bs.read(5);
    136  //  assert(reserved_one_5bits == 1);
    137 #if VIDYO_VPS_INTEGRATION
    138   nalu.m_layerId  = bs.read(5) - 1;
    139 #else
    140   nalu.m_viewId   = bs.read(4)-1;
    141   nalu.m_isDepth  = bs.read(1);
    142 #endif
    143   if ( nalu.m_temporalId )
    144   {
    145 #if QC_REM_IDV_B0046
    146     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR);
    147 #else
    148     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDV );
    149 #endif
    150   }
    151 #endif
     147  readNalUnitHeader(nalu);
    152148}
    153149//! \}
  • trunk/source/Lib/TLibDecoder/NALread.h

    r56 r608  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3232 */
    3333
     34/**
     35 \file     NALread.h
     36 \brief    reading funtionality for NAL units
     37 */
     38
    3439#pragma once
    3540
     
    4752struct InputNALUnit : public NALUnit
    4853{
     54  InputNALUnit() : m_Bitstream(0) {};
     55  ~InputNALUnit() { delete m_Bitstream; }
     56
    4957  TComInputBitstream* m_Bitstream;
    5058};
  • trunk/source/Lib/TLibDecoder/SEIread.cpp

    r56 r608  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3232 */
    3333
     34/**
     35 \file     SEIread.cpp
     36 \brief    reading functionality for SEI messages
     37 */
     38
     39#include "TLibCommon/CommonDef.h"
    3440#include "TLibCommon/TComBitStream.h"
    3541#include "TLibCommon/SEI.h"
     42#include "TLibCommon/TComSlice.h"
     43#include "SyntaxElementParser.h"
    3644#include "SEIread.h"
    3745
     
    3947//! \{
    4048
    41 static void parseSEIuserDataUnregistered(TComInputBitstream& bs, SEIuserDataUnregistered &sei, unsigned payloadSize);
    42 static void parseSEIpictureDigest(TComInputBitstream& bs, SEIpictureDigest& sei, unsigned payloadSize);
     49#if ENC_DEC_TRACE
     50Void  xTraceSEIHeader()
     51{
     52  fprintf( g_hTrace, "=========== SEI message ===========\n");
     53}
     54
     55Void  xTraceSEIMessageType(SEI::PayloadType payloadType)
     56{
     57  switch (payloadType)
     58  {
     59  case SEI::DECODED_PICTURE_HASH:
     60    fprintf( g_hTrace, "=========== Decoded picture hash SEI message ===========\n");
     61    break;
     62  case SEI::USER_DATA_UNREGISTERED:
     63    fprintf( g_hTrace, "=========== User Data Unregistered SEI message ===========\n");
     64    break;
     65  case SEI::ACTIVE_PARAMETER_SETS:
     66    fprintf( g_hTrace, "=========== Active Parameter sets SEI message ===========\n");
     67    break;
     68  case SEI::BUFFERING_PERIOD:
     69    fprintf( g_hTrace, "=========== Buffering period SEI message ===========\n");
     70    break;
     71  case SEI::PICTURE_TIMING:
     72    fprintf( g_hTrace, "=========== Picture timing SEI message ===========\n");
     73    break;
     74  case SEI::RECOVERY_POINT:
     75    fprintf( g_hTrace, "=========== Recovery point SEI message ===========\n");
     76    break;
     77  case SEI::FRAME_PACKING:
     78    fprintf( g_hTrace, "=========== Frame Packing Arrangement SEI message ===========\n");
     79    break;
     80  case SEI::DISPLAY_ORIENTATION:
     81    fprintf( g_hTrace, "=========== Display Orientation SEI message ===========\n");
     82    break;
     83  case SEI::TEMPORAL_LEVEL0_INDEX:
     84    fprintf( g_hTrace, "=========== Temporal Level Zero Index SEI message ===========\n");
     85    break;
     86  case SEI::REGION_REFRESH_INFO:
     87    fprintf( g_hTrace, "=========== Gradual Decoding Refresh Information SEI message ===========\n");
     88    break;
     89  case SEI::DECODING_UNIT_INFO:
     90    fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
     91    break;
     92  case SEI::TONE_MAPPING_INFO:
     93    fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
     94    break;
     95  case SEI::SOP_DESCRIPTION:
     96    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
     97    break;
     98  case SEI::SCALABLE_NESTING:
     99    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
     100    break;
     101  default:
     102    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
     103    break;
     104  }
     105}
     106#endif
    43107
    44108/**
    45109 * unmarshal a single SEI message from bitstream bs
    46110 */
    47 void parseSEImessage(TComInputBitstream& bs, SEImessages& seis)
    48 {
    49   unsigned payloadType = 0;
    50   for (unsigned char byte = 0xff; 0xff == byte; )
    51   {
    52     payloadType += byte = bs.read(8);
    53   }
    54 
    55   unsigned payloadSize = 0;
    56   for (unsigned char byte = 0xff; 0xff == byte; )
    57   {
    58     payloadSize += byte = bs.read(8);
    59   }
    60 
    61   switch (payloadType)
    62   {
    63   case SEI::USER_DATA_UNREGISTERED:
    64     seis.user_data_unregistered = new SEIuserDataUnregistered;
    65     parseSEIuserDataUnregistered(bs, *seis.user_data_unregistered, payloadSize);
    66     break;
    67   case SEI::PICTURE_DIGEST:
    68     seis.picture_digest = new SEIpictureDigest;
    69     parseSEIpictureDigest(bs, *seis.picture_digest, payloadSize);
    70     break;
    71   default:
    72     assert(!"Unhandled SEI message");
    73   }
     111void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
     112{
     113  setBitstream(bs);
     114
     115  assert(!m_pcBitstream->getNumBitsUntilByteAligned());
     116  do
     117  {
     118    xReadSEImessage(seis, nalUnitType, sps);
     119    /* SEI messages are an integer number of bytes, something has failed
     120    * in the parsing if bitstream not byte-aligned */
     121    assert(!m_pcBitstream->getNumBitsUntilByteAligned());
     122  } while (m_pcBitstream->getNumBitsLeft() > 8);
     123
     124  UInt rbspTrailingBits;
     125  READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
     126  assert(rbspTrailingBits == 0x80);
     127}
     128
     129Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
     130{
     131#if ENC_DEC_TRACE
     132  xTraceSEIHeader();
     133#endif
     134  Int payloadType = 0;
     135  UInt val = 0;
     136
     137  do
     138  {
     139    READ_CODE (8, val, "payload_type");
     140    payloadType += val;
     141  } while (val==0xFF);
     142
     143  UInt payloadSize = 0;
     144  do
     145  {
     146    READ_CODE (8, val, "payload_size");
     147    payloadSize += val;
     148  } while (val==0xFF);
     149
     150#if ENC_DEC_TRACE
     151  xTraceSEIMessageType((SEI::PayloadType)payloadType);
     152#endif
     153
     154  /* extract the payload for this single SEI message.
     155   * This allows greater safety in erroneous parsing of an SEI message
     156   * from affecting subsequent messages.
     157   * After parsing the payload, bs needs to be restored as the primary
     158   * bitstream.
     159   */
     160  TComInputBitstream *bs = getBitstream();
     161  setBitstream(bs->extractSubstream(payloadSize * 8));
     162
     163  SEI *sei = NULL;
     164
     165  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
     166  {
     167    switch (payloadType)
     168    {
     169    case SEI::USER_DATA_UNREGISTERED:
     170      sei = new SEIuserDataUnregistered;
     171      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
     172      break;
     173    case SEI::ACTIVE_PARAMETER_SETS:
     174      sei = new SEIActiveParameterSets;
     175      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize);
     176      break;
     177    case SEI::DECODING_UNIT_INFO:
     178      if (!sps)
     179      {
     180        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
     181      }
     182      else
     183      {
     184        sei = new SEIDecodingUnitInfo;
     185        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
     186      }
     187      break;
     188    case SEI::BUFFERING_PERIOD:
     189      if (!sps)
     190      {
     191        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
     192      }
     193      else
     194      {
     195        sei = new SEIBufferingPeriod;
     196        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
     197      }
     198      break;
     199    case SEI::PICTURE_TIMING:
     200      if (!sps)
     201      {
     202        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
     203      }
     204      else
     205      {
     206        sei = new SEIPictureTiming;
     207        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
     208      }
     209      break;
     210    case SEI::RECOVERY_POINT:
     211      sei = new SEIRecoveryPoint;
     212      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
     213      break;
     214    case SEI::FRAME_PACKING:
     215      sei = new SEIFramePacking;
     216      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
     217      break;
     218    case SEI::DISPLAY_ORIENTATION:
     219      sei = new SEIDisplayOrientation;
     220      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
     221      break;
     222    case SEI::TEMPORAL_LEVEL0_INDEX:
     223      sei = new SEITemporalLevel0Index;
     224      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
     225      break;
     226    case SEI::REGION_REFRESH_INFO:
     227      sei = new SEIGradualDecodingRefreshInfo;
     228      xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
     229      break;
     230    case SEI::TONE_MAPPING_INFO:
     231      sei = new SEIToneMappingInfo;
     232      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
     233      break;
     234    case SEI::SOP_DESCRIPTION:
     235      sei = new SEISOPDescription;
     236      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
     237      break;
     238    case SEI::SCALABLE_NESTING:
     239      sei = new SEIScalableNesting;
     240      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
     241      break;
     242    default:
     243      for (UInt i = 0; i < payloadSize; i++)
     244      {
     245        UInt seiByte;
     246        READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
     247      }
     248      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
     249    }
     250  }
     251  else
     252  {
     253    switch (payloadType)
     254    {
     255      case SEI::USER_DATA_UNREGISTERED:
     256        sei = new SEIuserDataUnregistered;
     257        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
     258        break;
     259      case SEI::DECODED_PICTURE_HASH:
     260        sei = new SEIDecodedPictureHash;
     261        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
     262        break;
     263      default:
     264        for (UInt i = 0; i < payloadSize; i++)
     265        {
     266          UInt seiByte;
     267          READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
     268        }
     269        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
     270    }
     271  }
     272  if (sei != NULL)
     273  {
     274    seis.push_back(sei);
     275  }
     276
     277  /* By definition the underlying bitstream terminates in a byte-aligned manner.
     278   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
     279   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
     280   * 3. Extract the remainingreserved_payload_extension_data bits.
     281   *
     282   * If there are fewer than 9 bits available, extract them.
     283   */
     284  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
     285  if (payloadBitsRemaining) /* more_data_in_payload() */
     286  {
     287    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
     288    {
     289      UInt reservedPayloadExtensionData;
     290      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
     291    }
     292
     293    /* 2 */
     294    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
     295    Int finalPayloadBits = 0;
     296    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
     297    {
     298      continue;
     299    }
     300
     301    /* 3 */
     302    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
     303    {
     304      UInt reservedPayloadExtensionData;
     305      READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
     306    }
     307
     308    UInt dummy;
     309    READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
     310    while (payloadBitsRemaining)
     311    {
     312      READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
     313    }
     314  }
     315
     316  /* restore primary bitstream for sei_message */
     317  delete getBitstream();
     318  setBitstream(bs);
    74319}
    75320
     
    78323 * of payloasSize bytes into sei.
    79324 */
    80 static void parseSEIuserDataUnregistered(TComInputBitstream& bs, SEIuserDataUnregistered &sei, unsigned payloadSize)
     325Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize)
    81326{
    82327  assert(payloadSize >= 16);
    83   for (unsigned i = 0; i < 16; i++)
    84   {
    85     sei.uuid_iso_iec_11578[i] = bs.read(8);
     328  UInt val;
     329
     330  for (UInt i = 0; i < 16; i++)
     331  {
     332    READ_CODE (8, val, "uuid_iso_iec_11578");
     333    sei.uuid_iso_iec_11578[i] = val;
    86334  }
    87335
     
    93341  }
    94342
    95   sei.userData = new unsigned char[sei.userDataLength];
    96   for (unsigned i = 0; i < sei.userDataLength; i++)
    97   {
    98     sei.userData[i] = bs.read(8);
     343  sei.userData = new UChar[sei.userDataLength];
     344  for (UInt i = 0; i < sei.userDataLength; i++)
     345  {
     346    READ_CODE (8, val, "user_data" );
     347    sei.userData[i] = val;
    99348  }
    100349}
    101350
    102351/**
    103  * parse bitstream bs and unpack a picture_digest SEI message
     352 * parse bitstream bs and unpack a decoded picture hash SEI message
    104353 * of payloadSize bytes into sei.
    105354 */
    106 static void parseSEIpictureDigest(TComInputBitstream& bs, SEIpictureDigest& sei, unsigned payloadSize)
    107 {
    108   assert(payloadSize >= 17);
    109   sei.method = static_cast<SEIpictureDigest::Method>(bs.read(8));
    110   assert(SEIpictureDigest::MD5 == sei.method);
    111   for (unsigned i = 0; i < 16; i++)
    112   {
    113     sei.digest[i] = bs.read(8);
    114   }
    115 }
    116 
     355Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
     356{
     357  UInt val;
     358  READ_CODE (8, val, "hash_type");
     359  sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
     360  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
     361  {
     362    if(SEIDecodedPictureHash::MD5 == sei.method)
     363    {
     364      for (UInt i = 0; i < 16; i++)
     365      {
     366        READ_CODE(8, val, "picture_md5");
     367        sei.digest[yuvIdx][i] = val;
     368      }
     369    }
     370    else if(SEIDecodedPictureHash::CRC == sei.method)
     371    {
     372      READ_CODE(16, val, "picture_crc");
     373      sei.digest[yuvIdx][0] = val >> 8 & 0xFF;
     374      sei.digest[yuvIdx][1] = val & 0xFF;
     375    }
     376    else if(SEIDecodedPictureHash::CHECKSUM == sei.method)
     377    {
     378      READ_CODE(32, val, "picture_checksum");
     379      sei.digest[yuvIdx][0] = (val>>24) & 0xff;
     380      sei.digest[yuvIdx][1] = (val>>16) & 0xff;
     381      sei.digest[yuvIdx][2] = (val>>8)  & 0xff;
     382      sei.digest[yuvIdx][3] =  val      & 0xff;
     383    }
     384  }
     385}
     386Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
     387{
     388  UInt val;
     389  READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val;
     390  READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
     391  READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
     392  READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
     393
     394  sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1);
     395  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
     396  {
     397    READ_UVLC(val, "active_seq_param_set_id");  sei.activeSeqParamSetId[i] = val;
     398  }
     399
     400  UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned();
     401 
     402  while(uibits--)
     403  {
     404    READ_FLAG(val, "alignment_bit");
     405  }
     406}
     407
     408Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
     409{
     410  UInt val;
     411  READ_UVLC(val, "decoding_unit_idx");
     412  sei.m_decodingUnitIdx = val;
     413
     414  TComVUI *vui = sps->getVuiParameters();
     415  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
     416  {
     417    READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
     418    sei.m_duSptCpbRemovalDelay = val;
     419  }
     420  else
     421  {
     422    sei.m_duSptCpbRemovalDelay = 0;
     423  }
     424  READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
     425  if(sei.m_dpbOutputDuDelayPresentFlag)
     426  {
     427    READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay");
     428    sei.m_picSptDpbOutputDuDelay = val;
     429  }
     430  xParseByteAlign();
     431}
     432
     433Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
     434{
     435  Int i, nalOrVcl;
     436  UInt code;
     437
     438  TComVUI *pVUI = sps->getVuiParameters();
     439  TComHRD *pHRD = pVUI->getHrdParameters();
     440
     441  READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
     442  if( !pHRD->getSubPicCpbParamsPresentFlag() )
     443  {
     444    READ_FLAG( code, "rap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
     445  }
     446  //read splicing flag and cpb_removal_delay_delta
     447  READ_FLAG( code, "concatenation_flag");
     448  sei.m_concatenationFlag = code;
     449  READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
     450  sei.m_auCpbRemovalDelayDelta = code + 1;
     451  if( sei.m_rapCpbParamsPresentFlag )
     452  {
     453    READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
     454    READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
     455  }
     456  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     457  {
     458    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
     459        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
     460    {
     461      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
     462      {
     463        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
     464        sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
     465        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
     466        sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
     467        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
     468        {
     469          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
     470          sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
     471          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
     472          sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
     473        }
     474      }
     475    }
     476  }
     477  xParseByteAlign();
     478}
     479Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
     480{
     481  Int i;
     482  UInt code;
     483
     484  TComVUI *vui = sps->getVuiParameters();
     485  TComHRD *hrd = vui->getHrdParameters();
     486
     487  if( vui->getFrameFieldInfoPresentFlag() )
     488  {
     489    READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
     490    READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
     491    READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
     492  }
     493
     494  if( hrd->getCpbDpbDelaysPresentFlag())
     495  {
     496    READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
     497    sei.m_auCpbRemovalDelay = code + 1;
     498    READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
     499    sei.m_picDpbOutputDelay = code;
     500
     501    if(hrd->getSubPicCpbParamsPresentFlag())
     502    {
     503      READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
     504      sei.m_picDpbOutputDuDelay = code;
     505    }
     506    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
     507    {
     508      READ_UVLC( code, "num_decoding_units_minus1");
     509      sei.m_numDecodingUnitsMinus1 = code;
     510      READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
     511      sei.m_duCommonCpbRemovalDelayFlag = code;
     512      if( sei.m_duCommonCpbRemovalDelayFlag )
     513      {
     514        READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
     515        sei.m_duCommonCpbRemovalDelayMinus1 = code;
     516      }
     517      if( sei.m_numNalusInDuMinus1 != NULL )
     518      {
     519        delete sei.m_numNalusInDuMinus1;
     520      }
     521      sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
     522      if( sei.m_duCpbRemovalDelayMinus1  != NULL )
     523      {
     524        delete sei.m_duCpbRemovalDelayMinus1;
     525      }
     526      sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
     527
     528      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
     529      {
     530        READ_UVLC( code, "num_nalus_in_du_minus1");
     531        sei.m_numNalusInDuMinus1[ i ] = code;
     532        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
     533        {
     534          READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
     535          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
     536        }
     537      }
     538    }
     539  }
     540  xParseByteAlign();
     541}
     542Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
     543{
     544  Int  iCode;
     545  UInt uiCode;
     546  READ_SVLC( iCode,  "recovery_poc_cnt" );      sei.m_recoveryPocCnt     = iCode;
     547  READ_FLAG( uiCode, "exact_matching_flag" );   sei.m_exactMatchingFlag  = uiCode;
     548  READ_FLAG( uiCode, "broken_link_flag" );      sei.m_brokenLinkFlag     = uiCode;
     549  xParseByteAlign();
     550}
     551Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
     552{
     553  UInt val;
     554  READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
     555  READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
     556
     557  if ( !sei.m_arrangementCancelFlag )
     558  {
     559    READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
     560    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
     561    READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
     562
     563    READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
     564    READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
     565    READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
     566    READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
     567    READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
     568    READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
     569    READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
     570
     571    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
     572    {
     573      READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
     574      READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
     575      READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
     576      READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
     577    }
     578
     579    READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
     580    READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
     581  }
     582  READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
     583
     584  xParseByteAlign();
     585}
     586
     587Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
     588{
     589  UInt val;
     590  READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
     591  if( !sei.cancelFlag )
     592  {
     593    READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
     594    READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
     595    READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
     596    READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
     597  }
     598  xParseByteAlign();
     599}
     600
     601Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
     602{
     603  UInt val;
     604  READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
     605  READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
     606  xParseByteAlign();
     607}
     608
     609Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
     610{
     611  UInt val;
     612  READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
     613  xParseByteAlign();
     614}
     615
     616Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
     617{
     618  Int i;
     619  UInt val;
     620  READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
     621  READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
     622
     623  if ( !sei.m_toneMapCancelFlag )
     624  {
     625    READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val;
     626    READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
     627    READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
     628    READ_UVLC( val, "model_id" );                          sei.m_modelId = val;
     629    switch(sei.m_modelId)
     630    {
     631    case 0:
     632      {
     633        READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
     634        READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
     635        break;
     636      }
     637    case 1:
     638      {
     639        READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
     640        READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
     641        break;
     642      }
     643    case 2:
     644      {
     645        UInt num = 1u << sei.m_targetBitDepth;
     646        sei.m_startOfCodedInterval.resize(num+1);
     647        for(i = 0; i < num; i++)
     648        {
     649          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
     650          sei.m_startOfCodedInterval[i] = val;
     651        }
     652        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
     653        break;
     654      }
     655    case 3:
     656      {
     657        READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
     658        sei.m_codedPivotValue.resize(sei.m_numPivots);
     659        sei.m_targetPivotValue.resize(sei.m_numPivots);
     660        for(i = 0; i < sei.m_numPivots; i++ )
     661        {
     662          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
     663          sei.m_codedPivotValue[i] = val;
     664          READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
     665          sei.m_targetPivotValue[i] = val;
     666        }
     667        break;
     668      }
     669    case 4:
     670      {
     671        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedValue = val;
     672        if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO
     673        {
     674          READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
     675        }
     676        READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
     677        READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
     678        READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
     679        READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
     680        READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
     681        READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
     682        READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
     683        READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
     684        break;
     685      }
     686    default:
     687      {
     688        assert(!"Undefined SEIToneMapModelId");
     689        break;
     690      }
     691    }//switch model id
     692  }// if(!sei.m_toneMapCancelFlag)
     693
     694  xParseByteAlign();
     695}
     696
     697Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
     698{
     699  Int iCode;
     700  UInt uiCode;
     701
     702  READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
     703  READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
     704  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
     705  {
     706    READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
     707    READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
     708    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
     709    {
     710      READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
     711    }
     712    if (i > 0)
     713    {
     714      READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
     715    }
     716  }
     717
     718  xParseByteAlign();
     719}
     720
     721Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
     722{
     723  UInt uiCode;
     724  SEIMessages seis;
     725
     726  READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
     727  READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
     728  if (sei.m_nestingOpFlag)
     729  {
     730    READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
     731    READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
     732    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
     733    {
     734      READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
     735      READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
     736    }
     737  }
     738  else
     739  {
     740    READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
     741    if (!sei.m_allLayersFlag)
     742    {
     743      READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
     744      READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
     745      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
     746      {
     747        READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
     748      }
     749    }
     750  }
     751
     752  // byte alignment
     753  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     754  {
     755    UInt code;
     756    READ_FLAG( code, "nesting_zero_bit" );
     757  }
     758
     759  sei.m_callerOwnsSEIs = false;
     760
     761  // read nested SEI messages
     762  do {
     763    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
     764  } while (m_pcBitstream->getNumBitsLeft() > 8);
     765
     766}
     767
     768Void SEIReader::xParseByteAlign()
     769{
     770  UInt code;
     771  if( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     772  {
     773    READ_FLAG( code, "bit_equal_to_one" );          assert( code == 1 );
     774  }
     775  while( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     776  {
     777    READ_FLAG( code, "bit_equal_to_zero" );         assert( code == 0 );
     778  }
     779}
    117780//! \}
  • trunk/source/Lib/TLibDecoder/SEIread.h

    r56 r608  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3232 */
    3333
     34/**
     35 \file     SEIread.h
     36 \brief    reading funtionality for SEI messages
     37 */
     38
     39#ifndef __SEIREAD__
     40#define __SEIREAD__
     41
     42#if _MSC_VER > 1000
    3443#pragma once
     44#endif // _MSC_VER > 1000
    3545
    3646//! \ingroup TLibDecoder
    3747//! \{
    3848
     49#include "TLibCommon/SEI.h"
    3950class TComInputBitstream;
    40 class SEImessages;
    4151
    42 void parseSEImessage(TComInputBitstream& bs, SEImessages& seis);
     52
     53class SEIReader: public SyntaxElementParser
     54{
     55public:
     56  SEIReader() {};
     57  virtual ~SEIReader() {};
     58  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
     59protected:
     60  Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
     61  Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
     62  Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
     63  Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps);
     64  Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
     65  Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps);
     66  Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps);
     67  Void xParseSEIRecoveryPoint         (SEIRecoveryPoint& sei, UInt payloadSize);
     68  Void xParseSEIFramePacking          (SEIFramePacking& sei, UInt payloadSize);
     69  Void xParseSEIDisplayOrientation    (SEIDisplayOrientation &sei, UInt payloadSize);
     70  Void xParseSEITemporalLevel0Index   (SEITemporalLevel0Index &sei, UInt payloadSize);
     71  Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
     72  Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
     73  Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
     74  Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
     75  Void xParseByteAlign();
     76};
     77
    4378
    4479//! \}
     80
     81#endif
  • trunk/source/Lib/TLibDecoder/TDecBinCoder.h

    r296 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5454  virtual Void  start             ()                                          = 0;
    5555  virtual Void  finish            ()                                          = 0;
    56   virtual Void  flush            ()                                           = 0;
    5756
    5857  virtual Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel )  = 0;
     
    6160  virtual Void  decodeBinTrm      ( UInt& ruiBin                           )  = 0;
    6261 
    63   virtual Void  resetBac          ()                                          = 0;
    64   virtual Void  decodeNumSubseqIPCM( Int& numSubseqIPCM )                  = 0;
    65   virtual Void  decodePCMAlignBits()                                          = 0;
    6662  virtual Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode)              = 0;
    6763
     
    7066  virtual Void  copyState         ( TDecBinIf* pcTDecBinIf )                  = 0;
    7167  virtual TDecBinCABAC*   getTDecBinCABAC   ()  { return 0; }
    72 #if !OL_FLUSH_ALIGN
    73   virtual Int   getBitsReadAhead() { return 0; }
    74 #endif
    7568};
    7669
  • trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp

    r296 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737
    3838#include "TDecBinCoderCABAC.h"
     39#include "../TLibCommon/TComRom.h"
    3940
    4041//! \ingroup TLibDecoder
     
    6566TDecBinCABAC::start()
    6667{
    67 #if OL_FLUSH_ALIGN
    6868  assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 );
    69 #endif
    70  
    7169  m_uiRange    = 510;
    7270  m_bitsNeeded = -8;
    73   m_uiValue    = m_pcTComBitstream->readByte() << 8;
    74 #if !OL_FLUSH_ALIGN
    75   m_uiLastByte = m_pcTComBitstream->readByte();
    76   m_uiValue   |= m_uiLastByte;
    77 #else
     71  m_uiValue    = (m_pcTComBitstream->readByte() << 8);
    7872  m_uiValue   |= m_pcTComBitstream->readByte();
    79 #endif
    8073}
    8174
     
    8376TDecBinCABAC::finish()
    8477{
    85 }
    86 
    87 Void
    88 TDecBinCABAC::flush()
    89 {
    90 #if OL_FLUSH_ALIGN
    91   while (m_pcTComBitstream->getNumBitsLeft() > 0 && m_pcTComBitstream->getNumBitsUntilByteAligned() != 0)
    92   {
    93     UInt uiBits;
    94     m_pcTComBitstream->read ( 1, uiBits );
    95   }
    96   start();
    97 #else
    98   m_uiRange    = 510;
    99   Int iExtra = 16+m_bitsNeeded+1; // m_bitsNeeded is -ve: iExtra is many bits to read to make up 16.
    100   UInt uiExtraBits;
    101   m_pcTComBitstream->read(iExtra, uiExtraBits);
    102   m_uiValue = (m_uiLastByte << iExtra) | uiExtraBits;
    103   m_uiValue &= 0xffff;
    104   m_uiLastByte = m_uiValue;
    105   m_uiLastByte &= 0xff;
    106   m_bitsNeeded = -8;
    107 #endif // OL_FLUSH_ALIGN
     78  UInt lastByte;
     79
     80  m_pcTComBitstream->peekPreviousByte( lastByte );
     81  // Check for proper stop/alignment pattern
     82  assert( ((lastByte << (8 + m_bitsNeeded)) & 0xff) == 0x80 );
    10883}
    10984
     
    12095  m_uiValue   = pcTDecBinCABAC->m_uiValue;
    12196  m_bitsNeeded= pcTDecBinCABAC->m_bitsNeeded;
    122 #if !OL_FLUSH_ALIGN
    123   m_uiLastByte= pcTDecBinCABAC->m_uiLastByte;
    124 #endif
    12597}
    12698
     
    150122    {
    151123      m_bitsNeeded = -8;
    152 #if !OL_FLUSH_ALIGN
    153       m_uiLastByte = m_pcTComBitstream->readByte();
    154       m_uiValue += m_uiLastByte;   
    155 #else
    156124      m_uiValue += m_pcTComBitstream->readByte();     
    157 #endif
    158125    }
    159126  }
     
    171138    if ( m_bitsNeeded >= 0 )
    172139    {
    173 #if !OL_FLUSH_ALIGN
    174       m_uiLastByte = m_pcTComBitstream->readByte();
    175       m_uiValue += m_uiLastByte << m_bitsNeeded;
    176 #else
    177140      m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded;
    178 #endif
    179141      m_bitsNeeded -= 8;
    180142    }
     
    190152  {
    191153    m_bitsNeeded = -8;
    192 #if !OL_FLUSH_ALIGN
    193     m_uiLastByte = m_pcTComBitstream->readByte();
    194     m_uiValue += m_uiLastByte;
    195 #else
    196154    m_uiValue += m_pcTComBitstream->readByte();
    197 #endif
    198155  }
    199156 
     
    213170  while ( numBins > 8 )
    214171  {
    215 #if !OL_FLUSH_ALIGN
    216     m_uiLastByte = m_pcTComBitstream->readByte();
    217     m_uiValue = ( m_uiValue << 8 ) + ( m_uiLastByte << ( 8 + m_bitsNeeded ) );
    218 #else
    219172    m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) );
    220 #endif
    221173   
    222174    UInt scaledRange = m_uiRange << 15;
     
    239191  if ( m_bitsNeeded >= 0 )
    240192  {
    241 #if !OL_FLUSH_ALIGN
    242     m_uiLastByte = m_pcTComBitstream->readByte();
    243     m_uiValue += m_uiLastByte << m_bitsNeeded;
    244 #else
    245193    m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded;
    246 #endif
    247194    m_bitsNeeded -= 8;
    248195  }
     
    283230      {
    284231        m_bitsNeeded = -8;
    285 #if !OL_FLUSH_ALIGN
    286         m_uiLastByte = m_pcTComBitstream->readByte();
    287         m_uiValue += m_uiLastByte;   
    288 #else
    289232        m_uiValue += m_pcTComBitstream->readByte();     
    290 #endif
    291233      }
    292234    }
    293235  }
    294 }
    295 
    296 /** Reset BAC register values.
    297  * \returns Void
    298  */
    299 Void TDecBinCABAC::resetBac()
    300 {
    301   m_uiRange    = 510;
    302   m_bitsNeeded = -8;
    303   m_uiValue    = m_pcTComBitstream->read( 16 );
    304 }
    305 
    306 /** Decode subsequent_pcm_num.
    307  * \param numSubseqIPCM
    308  * \returns Void
    309  */
    310 Void TDecBinCABAC::decodeNumSubseqIPCM( Int& numSubseqIPCM )
    311 {
    312   UInt bit = 0;
    313 
    314   numSubseqIPCM = 0;
    315 
    316   do
    317   {
    318     m_uiValue += m_uiValue;
    319     if ( ++m_bitsNeeded >= 0 )
    320     {
    321       m_bitsNeeded = -8;
    322 #if !OL_FLUSH_ALIGN
    323       m_uiLastByte = m_pcTComBitstream->readByte();
    324       m_uiValue += m_uiLastByte;
    325 #else
    326       m_uiValue += m_pcTComBitstream->readByte();
    327 #endif
    328     }
    329     bit = ((m_uiValue&128)>>7);
    330     numSubseqIPCM++;
    331   }
    332   while( bit && (numSubseqIPCM < 3 ));
    333 
    334   if( bit && (numSubseqIPCM == 3 ))
    335   {
    336     numSubseqIPCM++;
    337   }
    338 
    339   numSubseqIPCM --;
    340 }
    341 
    342 /** Decode PCM alignment zero bits.
    343  * \returns Void
    344  */
    345 Void TDecBinCABAC::decodePCMAlignBits()
    346 {
    347   Int iNum = m_pcTComBitstream->getNumBitsUntilByteAligned();
    348  
    349   UInt uiBit = 0;
    350   m_pcTComBitstream->read( iNum, uiBit );
    351236}
    352237
  • trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h

    r296 r608  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5656  Void  start             ();
    5757  Void  finish            ();
    58   Void  flush             ();
    5958 
    6059  Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel );
     
    6362  Void  decodeBinTrm      ( UInt& ruiBin                           );
    6463 
    65   Void  resetBac          ();
    66   Void  decodeNumSubseqIPCM( Int& numSubseqIPCM ) ;
    67   Void  decodePCMAlignBits();
    6864  Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode );
    6965 
    7066  Void  copyState         ( TDecBinIf* pcTDecBinIf );
    7167  TDecBinCABAC* getTDecBinCABAC()  { return this; }
    72 #if !OL_FLUSH_ALIGN
    73   Int   getBitsReadAhead() { return -m_bitsNeeded; }
    74 #endif
    7568
    7669private:
     
    7871  UInt                m_uiRange;
    7972  UInt                m_uiValue;
    80 #if !OL_FLUSH_ALIGN
    81   UInt                m_uiLastByte;
    82 #endif
    8373  Int                 m_bitsNeeded;
    8474};
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r443 r608  
    11/* 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  */
     2* License, included below. This software may be subject to other third party
     3* and contributor rights, including patent rights, and no such rights are
     4* granted under this license. 
     5*
     6* Copyright (c) 2010-2013, ITU/ISO/IEC
     7* All rights reserved.
     8*
     9* Redistribution and use in source and binary forms, with or without
     10* modification, are permitted provided that the following conditions are met:
     11*
     12*  * Redistributions of source code must retain the above copyright notice,
     13*    this list of conditions and the following disclaimer.
     14*  * Redistributions in binary form must reproduce the above copyright notice,
     15*    this list of conditions and the following disclaimer in the documentation
     16*    and/or other materials provided with the distribution.
     17*  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
     18*    be used to endorse or promote products derived from this software without
     19*    specific prior written permission.
     20*
     21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     22* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
     25* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31* THE POSSIBILITY OF SUCH DAMAGE.
     32*/
    3333
    3434/** \file     TDecCAVLC.cpp
    35     \brief    CAVLC decoder class
     35\brief    CAVLC decoder class
    3636*/
    3737
     
    4545#if ENC_DEC_TRACE
    4646
    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 
    5247Void  xTraceSPSHeader (TComSPS *pSPS)
    5348{
     49#if H_MV_ENC_DEC_TRAC
     50  if ( g_disableHLSTrace )
     51  {
     52    return;
     53  }
     54  // To avoid mismatches
     55  fprintf( g_hTrace, "=========== Sequence Parameter Set ===========\n" );
     56#else
    5457  fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() );
     58#endif
    5559}
    5660
    5761Void  xTracePPSHeader (TComPPS *pPPS)
    5862{
     63#if H_MV_ENC_DEC_TRAC
     64  if ( g_disableHLSTrace )
     65  {
     66    return;
     67  }
     68  fprintf( g_hTrace, "=========== Picture Parameter Set ===========\n" );
     69#else
    5970  fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() );
    60 }
    61 
    62 Void  xTraceAPSHeader (TComAPS *pAPS)
    63 {
    64   fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
     71#endif
    6572}
    6673
    6774Void  xTraceSliceHeader (TComSlice *pSlice)
    6875{
     76#if H_MV_ENC_DEC_TRAC
     77  if ( g_disableHLSTrace )
     78  {
     79    return;
     80  }
     81#endif
    6982  fprintf( g_hTrace, "=========== Slice ===========\n");
    7083}
    7184
    72 
    73 Void  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 
    81 Void  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 
    89 Void  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 
    97 Void  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 
     85#endif
    11586
    11687// ====================================================================================================================
     
    12091TDecCavlc::TDecCavlc()
    12192{
    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   }
     93#if H_3D
     94  m_aaiTempScale            = new Int* [ MAX_NUM_LAYERS ];
     95  m_aaiTempOffset           = new Int* [ MAX_NUM_LAYERS ];
     96  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
     97  {
     98    m_aaiTempScale            [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
     99    m_aaiTempOffset           [ uiVId ] = new Int [ MAX_NUM_LAYERS ];
     100  }
     101#endif
    135102}
    136103
    137104TDecCavlc::~TDecCavlc()
    138105{
    139   for( UInt uiVId = 0; uiVId < MAX_VIEW_NUM; uiVId++ )
     106#if H_3D
     107  for( UInt uiVId = 0; uiVId < MAX_NUM_LAYERS; uiVId++ )
    140108  {
    141109    delete [] m_aaiTempScale            [ uiVId ];
    142110    delete [] m_aaiTempOffset           [ uiVId ];
    143     delete [] m_aaiTempPdmScaleNomDelta [ uiVId ];
    144     delete [] m_aaiTempPdmOffset        [ uiVId ];
    145111  }
    146112  delete [] m_aaiTempScale;
    147113  delete [] m_aaiTempOffset;
    148   delete [] m_aaiTempPdmScaleNomDelta;
    149   delete [] m_aaiTempPdmOffset;
     114#endif
    150115}
    151116
     
    154119// ====================================================================================================================
    155120
    156 /**
    157  * unmarshal a sequence of SEI messages from bitstream.
    158  */
    159 void 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 }
    171121void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
    172122{
    173123  UInt code;
    174124  UInt interRPSPred;
    175   READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
     125  if (idx > 0)
     126  {
     127    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
     128  }
     129  else
     130  {
     131    interRPSPred = false;
     132    rps->setInterRPSPrediction(false);
     133  }
     134
    176135  if (interRPSPred)
    177136  {
    178137    UInt bit;
    179     READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
     138    if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
     139    {
     140      READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
     141    }
     142    else
     143    {
     144      code = 0;
     145    }
     146    assert(code <= idx-1); // delta_idx_minus1 shall not be larger than idx-1, otherwise we will predict from a negative row position that does not exist. When idx equals 0 there is no legal value and interRPSPred must be zero. See J0185-r2
    180147    Int rIdx =  idx - 1 - code;
    181     assert (rIdx <= idx && rIdx >= 0);
     148    assert (rIdx <= idx-1 && rIdx >= 0); // Made assert tighter; if rIdx = idx then prediction is done from itself. rIdx must belong to range 0, idx-1, inclusive, see J0185-r2
    182149    TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
    183150    Int k = 0, k0 = 0, k1 = 0;
    184151    READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
    185152    READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
    186     Int deltaRPS = (1 - (bit<<1)) * (code + 1); // delta_RPS
     153    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
    187154    for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
    188155    {
     
    200167        rps->setUsed(k, (refIdc == 1));
    201168
    202         if (deltaPOC < 0) {
     169        if (deltaPOC < 0)
     170        {
    203171          k0++;
    204172        }
     
    247215}
    248216
    249 Void TDecCavlc::parseAPS(TComAPS* aps)
     217Void TDecCavlc::parsePPS(TComPPS* pcPPS)
    250218{
    251219#if ENC_DEC_TRACE 
    252   xTraceAPSHeader(aps);
    253 #endif
    254 
    255   UInt uiCode;
    256   READ_UVLC(uiCode, "aps_id");                             aps->setAPSID(uiCode);
    257   READ_FLAG(uiCode, "aps_scaling_list_data_present_flag"); aps->setScalingListEnabled( (uiCode==1)?true:false );
    258   READ_FLAG(uiCode, "aps_deblocking_filter_flag");         aps->setLoopFilterOffsetInAPS( (uiCode==1)?true:false );
    259   if(aps->getScalingListEnabled())
    260   {
    261     parseScalingList( aps->getScalingList() );
    262   }
    263   if(aps->getLoopFilterOffsetInAPS())
    264   {
    265     xParseDblParam( aps );   
    266   }
    267 #if !LGE_SAO_MIGRATION_D0091
    268   READ_FLAG(uiCode, "aps_sao_interleaving_flag");      aps->setSaoInterleavingFlag( (uiCode==1)?true:false );
    269   if(!aps->getSaoInterleavingFlag())
    270   {
    271     READ_FLAG(uiCode, "aps_sample_adaptive_offset_flag");      aps->setSaoEnabled( (uiCode==1)?true:false );
    272   if(aps->getSaoEnabled())
    273   {
    274     aps->getSaoParam()->bSaoFlag[0] = true;
    275     xParseSaoParam( aps->getSaoParam() );
    276   }
    277   }
    278 #endif
    279   READ_FLAG(uiCode, "aps_adaptive_loop_filter_flag");      aps->setAlfEnabled( (uiCode==1)?true:false );
    280   if(aps->getAlfEnabled())
    281   {
    282     xParseAlfParam( aps->getAlfParam());
    283   }
    284   READ_FLAG( uiCode, "aps_extension_flag");
     220  xTracePPSHeader (pcPPS);
     221#endif
     222  UInt  uiCode;
     223
     224  Int   iCode;
     225
     226  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
     227  assert(uiCode <= 63);
     228  pcPPS->setPPSId (uiCode);
     229 
     230  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
     231  assert(uiCode <= 15);
     232  pcPPS->setSPSId (uiCode);
     233 
     234  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
     235  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
     236
     237  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
     238  READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
     239
     240  READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
     241
     242  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
     243  assert(uiCode <= 14);
     244  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
     245 
     246  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
     247  assert(uiCode <= 14);
     248  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
     249 
     250  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
     251  READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
     252  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
     253  pcPPS->setUseTransformSkip ( uiCode ? true : false );
     254
     255  READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
     256  if( pcPPS->getUseDQP() )
     257  {
     258    READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
     259    pcPPS->setMaxCuDQPDepth( uiCode );
     260  }
     261  else
     262  {
     263    pcPPS->setMaxCuDQPDepth( 0 );
     264  }
     265  READ_SVLC( iCode, "pps_cb_qp_offset");
     266  pcPPS->setChromaCbQpOffset(iCode);
     267  assert( pcPPS->getChromaCbQpOffset() >= -12 );
     268  assert( pcPPS->getChromaCbQpOffset() <=  12 );
     269
     270  READ_SVLC( iCode, "pps_cr_qp_offset");
     271  pcPPS->setChromaCrQpOffset(iCode);
     272  assert( pcPPS->getChromaCrQpOffset() >= -12 );
     273  assert( pcPPS->getChromaCrQpOffset() <=  12 );
     274
     275  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
     276  pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
     277
     278  READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
     279  pcPPS->setUseWP( uiCode==1 );
     280  READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
     281  pcPPS->setWPBiPred( uiCode==1 );
     282
     283  READ_FLAG( uiCode, "transquant_bypass_enable_flag");
     284  pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
     285  READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
     286  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
     287 
     288  if( pcPPS->getTilesEnabledFlag() )
     289  {
     290    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode ); 
     291    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode ); 
     292    READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
     293
     294    if( !pcPPS->getUniformSpacingFlag())
     295    {
     296      UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
     297      for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
     298      {
     299        READ_UVLC( uiCode, "column_width_minus1" ); 
     300        columnWidth[i] = uiCode+1;
     301      }
     302      pcPPS->setColumnWidth(columnWidth);
     303      free(columnWidth);
     304
     305      UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
     306      for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
     307      {
     308        READ_UVLC( uiCode, "row_height_minus1" );
     309        rowHeight[i] = uiCode + 1;
     310      }
     311      pcPPS->setRowHeight(rowHeight);
     312      free(rowHeight); 
     313    }
     314
     315    if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0)
     316    {
     317      READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" );   pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false );
     318    }
     319  }
     320  READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
     321  READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
     322  if(pcPPS->getDeblockingFilterControlPresentFlag())
     323  {
     324    READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
     325    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
     326    if(!pcPPS->getPicDisableDeblockingFilterFlag())
     327    {
     328      READ_SVLC ( iCode, "pps_beta_offset_div2" );                     pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode );
     329      READ_SVLC ( iCode, "pps_tc_offset_div2" );                       pcPPS->setDeblockingFilterTcOffsetDiv2( iCode );
     330    }
     331  }
     332  READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
     333  if(pcPPS->getScalingListPresentFlag ())
     334  {
     335    parseScalingList( pcPPS->getScalingList() );
     336  }
     337
     338  READ_FLAG( uiCode, "lists_modification_present_flag");
     339  pcPPS->setListsModificationPresentFlag(uiCode);
     340
     341  READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
     342  pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
     343
     344  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
     345  pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
     346
     347  READ_FLAG( uiCode, "pps_extension_flag");
    285348  if (uiCode)
    286349  {
    287350    while ( xMoreRbspData() )
    288351    {
    289       READ_FLAG( uiCode, "aps_extension_data_flag");
    290     }
    291   }
    292 
    293 }
    294 
    295 Void  TDecCavlc::xParseDblParam       ( TComAPS* aps )
    296 {
    297   UInt uiSymbol;
    298   Int iSymbol;
    299 
    300   parseDFFlag(uiSymbol, "loop_filter_disable");
    301   aps->setLoopFilterDisable(uiSymbol?true:false);
    302 
    303   if (!aps->getLoopFilterDisable())
    304   {
    305     parseDFSvlc(iSymbol, "beta_offset_div2");
    306     aps->setLoopFilterBetaOffset(iSymbol);
    307     parseDFSvlc(iSymbol, "tc_offset_div2");
    308     aps->setLoopFilterTcOffset(iSymbol);
    309   }
    310 }
    311 #if !LGE_SAO_MIGRATION_D0091
    312 /** parse SAO parameters
    313  * \param pSaoParam
    314  */
    315 Void TDecCavlc::xParseSaoParam(SAOParam* pSaoParam)
    316 {
    317   UInt uiSymbol;
    318 
    319   int i,j, compIdx;
    320   int numCuInWidth;
    321   int numCuInHeight;
    322   Bool repeatedRow[3];
    323   if (pSaoParam->bSaoFlag[0])                                                                   
    324   {     
    325     READ_FLAG (uiSymbol, "sao_cb_enable_flag");            pSaoParam->bSaoFlag[1]   = uiSymbol? true:false; 
    326     READ_FLAG (uiSymbol, "sao_cr_enable_flag");            pSaoParam->bSaoFlag[2]   = uiSymbol? true:false; 
    327     READ_UVLC (uiSymbol, "sao_num_lcu_in_width_minus1");   pSaoParam->numCuInWidth  = uiSymbol + 1;                         
    328     READ_UVLC (uiSymbol, "sao_num_lcu_in_height_minus1");  pSaoParam->numCuInHeight = uiSymbol + 1;                         
    329     numCuInWidth  = pSaoParam->numCuInWidth;
    330     numCuInHeight = pSaoParam->numCuInHeight;
    331 
    332     READ_FLAG (uiSymbol, "sao_one_luma_unit_flag");  pSaoParam->oneUnitFlag[0] = uiSymbol? true:false; 
    333     if (pSaoParam->oneUnitFlag[0] )
    334       xParseSaoOffset(&(pSaoParam->saoLcuParam[0][0]));
    335 
    336     if (pSaoParam->bSaoFlag[1])
    337     {
    338       READ_FLAG (uiSymbol, "sao_one_cb_unit_flag");  pSaoParam->oneUnitFlag[1] = uiSymbol? true:false; 
    339       if (pSaoParam->oneUnitFlag[1] )
    340         xParseSaoOffset(&(pSaoParam->saoLcuParam[1][0]));
    341     }
    342     if (pSaoParam->bSaoFlag[2])
    343     {
    344       READ_FLAG (uiSymbol, "sao_one_cr_unit_flag");  pSaoParam->oneUnitFlag[2] = uiSymbol? true:false; 
    345       if (pSaoParam->oneUnitFlag[2] )
    346         xParseSaoOffset(&(pSaoParam->saoLcuParam[2][0]));
    347     }
    348     for (j=0;j<numCuInHeight;j++)
    349     {
    350       for (compIdx=0;compIdx<3;compIdx++)
    351       {
    352         repeatedRow[compIdx] = 0;
    353       }
    354       for (i=0;i<numCuInWidth;i++)
    355       {
    356         for (compIdx=0; compIdx<3; compIdx++)
    357         {
    358           if (pSaoParam->bSaoFlag[compIdx]  && !pSaoParam->oneUnitFlag[compIdx])
     352      READ_FLAG( uiCode, "pps_extension_data_flag");
     353    }
     354  }
     355}
     356
     357Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
     358{
     359#if ENC_DEC_TRACE
     360  fprintf( g_hTrace, "----------- vui_parameters -----------\n");
     361#endif
     362  UInt  uiCode;
     363
     364  READ_FLAG(     uiCode, "aspect_ratio_info_present_flag");           pcVUI->setAspectRatioInfoPresentFlag(uiCode);
     365  if (pcVUI->getAspectRatioInfoPresentFlag())
     366  {
     367    READ_CODE(8, uiCode, "aspect_ratio_idc");                         pcVUI->setAspectRatioIdc(uiCode);
     368    if (pcVUI->getAspectRatioIdc() == 255)
     369    {
     370      READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
     371      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
     372    }
     373  }
     374
     375  READ_FLAG(     uiCode, "overscan_info_present_flag");               pcVUI->setOverscanInfoPresentFlag(uiCode);
     376  if (pcVUI->getOverscanInfoPresentFlag())
     377  {
     378    READ_FLAG(   uiCode, "overscan_appropriate_flag");                pcVUI->setOverscanAppropriateFlag(uiCode);
     379  }
     380
     381  READ_FLAG(     uiCode, "video_signal_type_present_flag");           pcVUI->setVideoSignalTypePresentFlag(uiCode);
     382  if (pcVUI->getVideoSignalTypePresentFlag())
     383  {
     384    READ_CODE(3, uiCode, "video_format");                             pcVUI->setVideoFormat(uiCode);
     385    READ_FLAG(   uiCode, "video_full_range_flag");                    pcVUI->setVideoFullRangeFlag(uiCode);
     386    READ_FLAG(   uiCode, "colour_description_present_flag");          pcVUI->setColourDescriptionPresentFlag(uiCode);
     387    if (pcVUI->getColourDescriptionPresentFlag())
     388    {
     389      READ_CODE(8, uiCode, "colour_primaries");                       pcVUI->setColourPrimaries(uiCode);
     390      READ_CODE(8, uiCode, "transfer_characteristics");               pcVUI->setTransferCharacteristics(uiCode);
     391      READ_CODE(8, uiCode, "matrix_coefficients");                    pcVUI->setMatrixCoefficients(uiCode);
     392    }
     393  }
     394
     395  READ_FLAG(     uiCode, "chroma_loc_info_present_flag");             pcVUI->setChromaLocInfoPresentFlag(uiCode);
     396  if (pcVUI->getChromaLocInfoPresentFlag())
     397  {
     398    READ_UVLC(   uiCode, "chroma_sample_loc_type_top_field" );        pcVUI->setChromaSampleLocTypeTopField(uiCode);
     399    READ_UVLC(   uiCode, "chroma_sample_loc_type_bottom_field" );     pcVUI->setChromaSampleLocTypeBottomField(uiCode);
     400  }
     401
     402  READ_FLAG(     uiCode, "neutral_chroma_indication_flag");           pcVUI->setNeutralChromaIndicationFlag(uiCode);
     403
     404  READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
     405
     406  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
     407
     408  READ_FLAG(     uiCode, "default_display_window_flag");
     409  if (uiCode != 0)
     410  {
     411    Window &defDisp = pcVUI->getDefaultDisplayWindow();
     412    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
     413    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
     414    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
     415    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
     416  }
     417  TimingInfo *timingInfo = pcVUI->getTimingInfo();
     418  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     419  if(timingInfo->getTimingInfoPresentFlag())
     420  {
     421    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
     422    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
     423    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
     424    if(timingInfo->getPocProportionalToTimingFlag())
     425    {
     426      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
     427    }
     428  READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
     429  if( pcVUI->getHrdParametersPresentFlag() )
     430  {
     431    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     432  }
     433  }
     434  READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
     435  if (pcVUI->getBitstreamRestrictionFlag())
     436  {
     437    READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
     438#if H_MV
     439    if ( pcSPS->getLayerId() > 0 )
     440    {
     441      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
     442    }
     443#endif
     444    READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
     445    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
     446    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
     447    assert(uiCode < 4096);
     448    READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
     449    READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
     450    READ_UVLC(   uiCode, "log2_max_mv_length_horizontal" );           pcVUI->setLog2MaxMvLengthHorizontal(uiCode);
     451    READ_UVLC(   uiCode, "log2_max_mv_length_vertical" );             pcVUI->setLog2MaxMvLengthVertical(uiCode);
     452  }
     453}
     454
     455Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
     456{
     457  UInt  uiCode;
     458  if( commonInfPresentFlag )
     459  {
     460    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
     461    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
     462    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
     463    {
     464      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
     465      if( hrd->getSubPicCpbParamsPresentFlag() )
     466      {
     467        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
     468        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
     469        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
     470        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
     471      }
     472      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
     473      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
     474      if( hrd->getSubPicCpbParamsPresentFlag() )
     475      {
     476        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
     477      }
     478      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
     479      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
     480      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
     481    }
     482  }
     483  Int i, j, nalOrVcl;
     484  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
     485  {
     486    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
     487    if( !hrd->getFixedPicRateFlag( i ) )
     488    {
     489      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
     490    }
     491    else
     492    {
     493      hrd->setFixedPicRateWithinCvsFlag( i, true );
     494    }
     495    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
     496    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
     497    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
     498    {
     499      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
     500    }
     501    else
     502    {     
     503      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
     504    }
     505    if (!hrd->getLowDelayHrdFlag( i ))
     506    {
     507      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );     
     508    }
     509    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     510    {
     511      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
     512          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
     513      {
     514        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
     515        {
     516          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
     517          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
     518          if( hrd->getSubPicCpbParamsPresentFlag() )
    359519          {
    360             if (j>0 && i==0)
    361             {
    362               READ_FLAG (uiSymbol, "sao_repeat_row_flag");  repeatedRow[compIdx] = uiSymbol? true:false;
    363             }
    364             xParseSaoUnit (i,j, compIdx, pSaoParam, repeatedRow[compIdx]);
     520            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
     521            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
    365522          }
    366         }
    367       }
    368     }
    369   }
    370 }
    371 /** copy SAO parameter
    372  * \param dst 
    373  * \param src
    374  */
    375 inline Void copySaoOneLcuParam(SaoLcuParam* dst,  SaoLcuParam* src)
    376 {
    377   Int i;
    378   dst->partIdx = src->partIdx;
    379   dst->typeIdx = src->typeIdx;
    380   if (dst->typeIdx != -1)
    381   {
    382     if (dst->typeIdx == SAO_BO)
    383     {
    384       dst->bandPosition = src->bandPosition ;
    385     }
    386     else
    387     {
    388       dst->bandPosition = 0;
    389     }
    390     dst->length  = src->length;
    391     for (i=0;i<dst->length;i++)
    392     {
    393       dst->offset[i] = src->offset[i];
    394     }
    395   }
    396   else
    397   {
    398     dst->length  = 0;
    399     for (i=0;i<SAO_BO_LEN;i++)
    400     {
    401       dst->offset[i] = 0;
    402     }
    403   }
    404 }
    405 /** parse SAO offset
    406  * \param saoLcuParam SAO LCU parameters
    407  */
    408 Void TDecCavlc::xParseSaoOffset(SaoLcuParam* saoLcuParam)
    409 {
    410   UInt uiSymbol;
    411   Int iSymbol;
    412   static Int typeLength[MAX_NUM_SAO_TYPE] = {
    413     SAO_EO_LEN,
    414     SAO_EO_LEN,
    415     SAO_EO_LEN,
    416     SAO_EO_LEN,
    417     SAO_BO_LEN
    418   };
    419 
    420   READ_UVLC (uiSymbol, "sao_type_idx");   saoLcuParam->typeIdx = (Int)uiSymbol - 1;       
    421   if (uiSymbol)
    422   {
    423     saoLcuParam->length = typeLength[saoLcuParam->typeIdx];
    424     if( saoLcuParam->typeIdx == SAO_BO )
    425     {
    426       READ_CODE( 5, uiSymbol, "sao_band_position"); saoLcuParam->bandPosition = uiSymbol;
    427       for(Int i=0; i< saoLcuParam->length; i++)
    428       {
    429         READ_SVLC (iSymbol, "sao_offset");    saoLcuParam->offset[i] = iSymbol;   
    430       }   
    431     }
    432     else if( saoLcuParam->typeIdx < 4 )
    433     {
    434       READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[0] = uiSymbol;
    435       READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[1] = uiSymbol;
    436       READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[2] = -(Int)uiSymbol;
    437       READ_UVLC (uiSymbol, "sao_offset");  saoLcuParam->offset[3] = -(Int)uiSymbol;
    438     }
    439   }
    440   else
    441   {
    442     saoLcuParam->length = 0;
    443   }
    444 }
    445 
    446 /** parse SAO unit
    447  * \param rx x-axis location
    448  * \param ry y-axis location
    449  * \param compIdx color component index
    450  * \param saoParam SAO parameters
    451  * \param repeatedRow repeat row flag
    452  */
    453 void TDecCavlc::xParseSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Bool& repeatedRow )
    454 {
    455   int addr, addrUp, addrLeft;
    456   int numCuInWidth  = saoParam->numCuInWidth;
    457   SaoLcuParam* saoOneLcu;
    458   SaoLcuParam* saoOneLcuUp;
    459   SaoLcuParam* saoOneLcuLeft;
    460   UInt uiSymbol;
    461   Int  iSymbol;
    462   Int  runLeft;
    463   UInt maxValue;
    464 
    465   addr      =  rx + ry*numCuInWidth;
    466   addrLeft  =  (addr%numCuInWidth == 0) ? -1 : addr - 1;
    467   addrUp    =  (addr<numCuInWidth)      ? -1 : addr - numCuInWidth;
    468 
    469   saoOneLcu = &(saoParam->saoLcuParam[compIdx][addr]);     
    470   if (!repeatedRow)
    471   {
    472     runLeft = (addrLeft>=0 )  ? saoParam->saoLcuParam[compIdx][addrLeft].run : -1;
    473     if (rx == 0 || runLeft==0)
    474     {
    475       saoOneLcu->mergeLeftFlag = 0;
    476       if (ry == 0)
    477       {
    478         maxValue = numCuInWidth-rx-1;
    479         UInt length = 0;
    480         UInt val = 0;
    481         if (maxValue)
    482         {
    483           for(UInt i=0; i<32; i++)
     523          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
     524        }
     525      }
     526    }
     527  }
     528}
     529
     530#if H_3D
     531Void TDecCavlc::parseSPS(TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
     532#else
     533Void TDecCavlc::parseSPS(TComSPS* pcSPS)
     534#endif
     535{
     536#if ENC_DEC_TRACE 
     537  xTraceSPSHeader (pcSPS);
     538#endif
     539
     540  UInt  uiCode;
     541  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
     542#if H_MV
     543  if ( pcSPS->getLayerId() == 0 )
     544  {
     545#endif
     546  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     547  assert(uiCode <= 6);
     548 
     549  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
     550  if ( pcSPS->getMaxTLayers() == 1 )
     551  {
     552    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
     553    assert( uiCode == 1 );
     554  }
     555 
     556  parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     557#if H_MV
     558  }
     559#endif
     560  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
     561  assert(uiCode <= 15);
     562 
     563  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
     564  assert(uiCode <= 3);
     565  // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
     566  assert (uiCode == 1);
     567  if( uiCode == 3 )
     568  {
     569    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
     570  }
     571
     572  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
     573  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
     574  READ_FLAG(     uiCode, "conformance_window_flag");
     575  if (uiCode != 0)
     576  {
     577    Window &conf = pcSPS->getConformanceWindow();
     578    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     579    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     580    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     581    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     582  }
     583
     584  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
     585  assert(uiCode <= 6);
     586  pcSPS->setBitDepthY( uiCode + 8 );
     587  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
     588
     589  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
     590  assert(uiCode <= 6);
     591  pcSPS->setBitDepthC( uiCode + 8 );
     592  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
     593
     594  READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
     595  assert(uiCode <= 12);
     596
     597  UInt subLayerOrderingInfoPresentFlag;
     598  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
     599 
     600  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
     601  {
     602#if H_MV
     603    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
     604#else
     605    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
     606#endif
     607    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
     608#if H_MV
     609    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
     610#else
     611    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
     612#endif
     613    pcSPS->setNumReorderPics(uiCode, i);
     614#if H_MV
     615    READ_UVLC ( uiCode, "sps_max_latency_increase[i]");
     616#else
     617    READ_UVLC ( uiCode, "sps_max_latency_increase");
     618#endif
     619    pcSPS->setMaxLatencyIncrease( uiCode, i );
     620
     621    if (!subLayerOrderingInfoPresentFlag)
     622    {
     623      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
     624      {
     625        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
     626        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
     627        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
     628      }
     629      break;
     630    }
     631  }
     632
     633  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
     634  Int log2MinCUSize = uiCode + 3;
     635  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
     636  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
     637  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
     638  Int maxCUDepthDelta = uiCode;
     639  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
     640  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
     641  READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
     642
     643  READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
     644  pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
     645
     646  READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
     647  READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
     648
     649  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
     650  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
     651
     652  READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
     653  if(pcSPS->getScalingListFlag())
     654  {
     655    READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     656    if(pcSPS->getScalingListPresentFlag ())
     657    {
     658      parseScalingList( pcSPS->getScalingList() );
     659    }
     660  }
     661  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
     662  READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
     663
     664  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
     665  if( pcSPS->getUsePCM() )
     666  {
     667    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
     668    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
     669    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
     670    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
     671    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
     672  }
     673
     674  READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
     675  assert(uiCode <= 64);
     676  pcSPS->createRPSList(uiCode);
     677
     678  TComRPSList* rpsList = pcSPS->getRPSList();
     679  TComReferencePictureSet* rps;
     680
     681  for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
     682  {
     683    rps = rpsList->getReferencePictureSet(i);
     684    parseShortTermRefPicSet(pcSPS,rps,i);
     685  }
     686  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
     687  if (pcSPS->getLongTermRefsPresent())
     688  {
     689    READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
     690    pcSPS->setNumLongTermRefPicSPS(uiCode);
     691    for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++)
     692    {
     693      READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
     694      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
     695      READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
     696      pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
     697    }
     698  }
     699  READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
     700
     701  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
     702
     703  READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
     704
     705  if (pcSPS->getVuiParametersPresentFlag())
     706  {
     707    parseVUI(pcSPS->getVuiParameters(), pcSPS);
     708  }
     709
     710  READ_FLAG( uiCode, "sps_extension_flag");
     711  if (uiCode)
     712  {
     713#if !H_MV
     714    while ( xMoreRbspData() )
     715    {
     716      READ_FLAG( uiCode, "sps_extension_data_flag");
     717    }
     718#else
     719    READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
     720    ////   sps_extension_vui_parameters( )
     721    if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
     722    { 
     723      READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode );
     724      for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ )
     725      { 
     726        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode );
     727        if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 )
     728        { 
     729          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 );
     730          if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) ) 
    484731          {
    485             if(maxValue&0x1)
    486             {
    487               length = i+1;
    488             }
    489             maxValue = (maxValue >> 1);
     732            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode );
    490733          }
    491           if(length)
     734        } 
     735      } 
     736    }
     737
     738#if H_3D_QTLPC
     739    if( depthFlag )
     740    {
     741      READ_FLAG( uiCode, "use_qtl_flag" );
     742      pcSPS->setUseQTL( uiCode );
     743      READ_FLAG( uiCode, "use_pc_flag" );
     744      pcSPS->setUsePC( uiCode );
     745    }
     746#endif
     747    ////   sps_extension_vui_parameters( ) END
     748    READ_UVLC( uiCode, "sps_shvc_reserved_zero_idc" );
     749    READ_FLAG( uiCode, "sps_extension2_flag");
     750    if ( uiCode )
     751    {
     752#if !H_3D
     753      while ( xMoreRbspData() )
     754      {
     755        READ_FLAG( uiCode, "sps_extension_data_flag");
     756      }
     757#else
     758     
     759      UInt uiCamParPrecision = 0;
     760      Bool bCamParSlice      = false;
     761      if ( !depthFlag )
     762      {     
     763        READ_UVLC( uiCamParPrecision, "cp_precision" );
     764        READ_FLAG( uiCode, "cp_in_slice_header_flag" );    bCamParSlice = ( uiCode == 1 );
     765        if( !bCamParSlice )
     766        {       
     767          for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
    492768          {
    493             READ_CODE(length, val, "sao_run_diff");
     769            Int iCode;
     770            READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
     771            READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
     772            READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
     773            READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
    494774          }
    495775        }
    496         uiSymbol = val;
    497         saoOneLcu->runDiff = uiSymbol;
    498         xParseSaoOffset(saoOneLcu);
    499         saoOneLcu->run = saoOneLcu->runDiff;
    500       }
    501       else
    502       {
    503         saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
    504         READ_SVLC (iSymbol , "sao_run_diff"     );  saoOneLcu->runDiff = iSymbol;
    505         READ_FLAG (uiSymbol, "sao_merge_up_flag");  saoOneLcu->mergeUpFlag   = uiSymbol? true:false;
    506         if (!saoOneLcu->mergeUpFlag)
    507         {
    508           xParseSaoOffset(saoOneLcu);
     776      }
     777      pcSPS->initCamParaSPS( viewIndex, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
     778      READ_FLAG( uiCode, "sps_extension3_flag");
     779      if ( uiCode )
     780      {
     781        while ( xMoreRbspData() )
     782        {
     783          READ_FLAG( uiCode, "sps_extension_data_flag");
     784        }
     785      }
     786#endif // !H_3D
     787    }
     788#endif // !H_MV
     789  }
     790}
     791
     792Void TDecCavlc::parseVPS(TComVPS* pcVPS)
     793{
     794  UInt  uiCode;
     795 
     796  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
     797  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
     798#if H_MV
     799  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
     800#else
     801  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
     802#endif
     803  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
     804  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
     805  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
     806#if H_MV
     807  READ_CODE( 16, uiCode,  "vps_extension_offset" );               
     808#else
     809  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
     810#endif
     811  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
     812  UInt subLayerOrderingInfoPresentFlag;
     813  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
     814  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
     815  {
     816    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
     817    READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
     818    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
     819
     820    if (!subLayerOrderingInfoPresentFlag)
     821    {
     822      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
     823      {
     824        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
     825        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
     826        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
     827      }
     828      break;
     829    }
     830  }
     831
     832  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
     833#if H_MV
     834  assert( pcVPS->getVpsMaxLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
     835  READ_CODE( 6, uiCode, "vps_max_layer_id" );   pcVPS->setVpsMaxLayerId( uiCode );
     836
     837  READ_UVLC(    uiCode, "vps_max_num_layer_sets_minus1" );               pcVPS->setVpsNumLayerSetsMinus1( uiCode );
     838  for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx ++ )
     839  {
     840    for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
     841#else
     842  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
     843  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
     844  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
     845  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
     846  {
     847    // Operation point set
     848    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
     849#endif
     850    {
     851      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
     852    }
     853  }
     854  TimingInfo *timingInfo = pcVPS->getTimingInfo();
     855  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
     856  if(timingInfo->getTimingInfoPresentFlag())
     857  {
     858    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
     859    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
     860    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
     861    if(timingInfo->getPocProportionalToTimingFlag())
     862    {
     863      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
     864    }
     865    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
     866
     867    if( pcVPS->getNumHrdParameters() > 0 )
     868    {
     869      pcVPS->createHrdParamBuffer();
     870    }
     871    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
     872    {
     873      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
     874      if( i > 0 )
     875      {
     876        READ_FLAG( uiCode, "cprms_present_flag[i]" );              pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
     877      }
     878      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     879    }
     880  }
     881  READ_FLAG( uiCode,  "vps_extension_flag" );
     882  if (uiCode)
     883  {
     884#if H_MV
     885    m_pcBitstream->readOutTrailingBits();
     886
     887    READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
     888    READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
     889
     890    for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
     891    {
     892      READ_FLAG( uiCode,  "scalability_mask[i]" );                  pcVPS->setScalabilityMask( sIdx, uiCode == 1 ? true : false );     
     893    }
     894
     895    for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
     896    {
     897        READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
     898    }
     899
     900    if ( pcVPS->getSplittingFlag() )
     901      {
     902      pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
     903      }
     904
     905    READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
     906
     907    for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
     908    {
     909      if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
     910      {
     911        READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
     912      }
     913      else
     914      {
     915        pcVPS->setLayerIdInNuh( i, i );;
     916    }
     917
     918      pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i );
     919   
     920      for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
     921    {
     922        if ( !pcVPS->getSplittingFlag() )
     923      {
     924          READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
    509925        }
    510926        else
    511927        {
    512           saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
    513           copySaoOneLcuParam(saoOneLcu, saoOneLcuUp);
    514         }
    515         saoOneLcu->run = saoOneLcu->runDiff + saoOneLcuUp->run;
    516       }
    517     }
    518     else
    519     {
    520       saoOneLcuLeft = &(saoParam->saoLcuParam[compIdx][addrLeft]);
    521       copySaoOneLcuParam(saoOneLcu, saoOneLcuLeft);
    522       saoOneLcu->mergeLeftFlag = 1;
    523       saoOneLcu->run = saoOneLcuLeft->run-1;
    524     }
    525   }
    526   else
    527   {
    528     if (ry > 0)
    529     {
    530       saoOneLcuUp = &(saoParam->saoLcuParam[compIdx][addrUp]);
    531       copySaoOneLcuParam(saoOneLcu, saoOneLcuUp);
    532       saoOneLcu->mergeLeftFlag = 0;
    533       saoOneLcu->run = saoOneLcuUp->run;
    534     }
    535   }
    536 }
    537 #endif
    538 
    539 Void TDecCavlc::xParseAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS, Int firstLCUAddr, Bool acrossSlice, Int numLCUInWidth, Int numLCUInHeight)
    540 {
    541   Int  numLCU;
    542   UInt uiSymbol;
    543   Bool isEnabled[NUM_ALF_COMPONENT];
    544   Bool isUniParam[NUM_ALF_COMPONENT];
    545  
    546   isEnabled[ALF_Y] = true;
    547   READ_FLAG(uiSymbol, "alf_cb_enable_flag");  isEnabled[ALF_Cb] = ((uiSymbol ==1)?true:false);
    548   READ_FLAG(uiSymbol, "alf_cr_enable_flag");  isEnabled[ALF_Cr] = ((uiSymbol ==1)?true:false);
    549   READ_FLAG(uiSymbol, "alf_one_luma_unit_per_slice_flag");   isUniParam[ALF_Y] = ((uiSymbol ==1)?true:false);
    550  
    551   isUniParam[ALF_Cb] = true;
    552   if (isEnabled[ALF_Cb])
    553   {
    554     READ_FLAG(uiSymbol, "alf_one_cb_unit_per_slice_flag");   isUniParam[ALF_Cb] = ((uiSymbol ==1)?true:false);
    555   }
    556  
    557   isUniParam[ALF_Cr] = true;
    558   if (isEnabled[ALF_Cr])
    559   {
    560     READ_FLAG(uiSymbol, "alf_one_cr_unit_per_slice_flag");   isUniParam[ALF_Cr] = ((uiSymbol ==1)?true:false);
    561   }
    562  
    563   if(bSentInAPS)
    564   {
    565     READ_UVLC(uiSymbol, "alf_num_lcu_in_width_minus1");  numLCUInWidth = uiSymbol+1;
    566     READ_UVLC(uiSymbol, "alf_num_lcu_in_height_minus1");  numLCUInHeight = uiSymbol+1;
    567     numLCU = numLCUInWidth*numLCUInHeight;
    568   }
    569   else //sent in slice header
    570   {
    571     READ_UVLC(uiSymbol, "alf_num_lcu_in_slice_minus1");  numLCU = uiSymbol+1;
    572   }
    573  
    574   assert(pAlfParamSet != NULL);
    575  
    576   pAlfParamSet->create(numLCUInWidth, numLCUInHeight, numLCU);
    577   for(Int compIdx = 0; compIdx < NUM_ALF_COMPONENT; compIdx++)
    578   {
    579     pAlfParamSet->isEnabled[compIdx] = isEnabled[compIdx];
    580     pAlfParamSet->isUniParam[compIdx]= isUniParam[compIdx];
    581   }
    582  
    583   parseAlfParamSet(pAlfParamSet, firstLCUAddr, acrossSlice);
    584 }
    585 
    586 
    587 Void TDecCavlc::parseAlfParamSet(AlfParamSet* pAlfParamSet, Int firstLCUAddr, Bool alfAcrossSlice)
    588 {
    589   Int numLCUInWidth = pAlfParamSet->numLCUInWidth;
    590   Int numLCU        = pAlfParamSet->numLCU;
    591  
    592   static Bool isRepeatedRow   [NUM_ALF_COMPONENT];
    593   static Int  numStoredFilters[NUM_ALF_COMPONENT];
    594   static Int* run             [NUM_ALF_COMPONENT];
    595  
    596   for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
    597   {
    598     isRepeatedRow[compIdx]    = false;
    599     numStoredFilters[compIdx] = 0;
    600    
    601     run[compIdx] = new Int[numLCU+1];
    602     run[compIdx][0] = -1;
    603   }
    604  
    605   UInt uiSymbol;
    606   Int  iSymbol, ry, rx, addrUp;
    607  
    608   for(Int i=0; i< numLCU; i++)
    609   {
    610     rx    = (i+ firstLCUAddr)% numLCUInWidth;
    611     ry    = (i+ firstLCUAddr)/ numLCUInWidth;
    612    
    613     for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
    614     {
    615       AlfUnitParam& alfUnitParam = pAlfParamSet->alfUnitParam[compIdx][i];
    616      
    617       if(pAlfParamSet->isEnabled[compIdx])
    618       {
    619         if(!pAlfParamSet->isUniParam[compIdx])
    620         {
    621           addrUp = i-numLCUInWidth;
    622           if(rx ==0 && addrUp >=0)
     928          pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
     929        }
     930      }
     931    }
     932
     933
     934    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
     935    {
     936      for( Int j = 0; j < i; j++ )
     937      {
     938        READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
     939      }
     940    }
     941
     942    for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
     943    {
     944      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode );
     945    }
     946
     947    READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode );
     948    READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
     949
     950    for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
     951    {
     952      READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
     953      if( !pcVPS->getVpsProfilePresentFlag( i ) )
     954      {
     955        READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
     956      }
     957      parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
     958      if( !pcVPS->getVpsProfilePresentFlag( i ) )
     959      {
     960        TComPTL temp = *pcVPS->getPTL( i );
     961        *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
     962        pcVPS->getPTL( i )->copyLevelFrom( &temp );
     963      }
     964    }
     965
     966    Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1;
     967
     968    READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
     969
     970    if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
     971    {
     972      READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
     973      numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1);
     974    }
     975
     976    if( numOutputLayerSets > 1)
     977    {
     978      READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1);
     979    } 
     980
     981    for( Int i = 1; i < numOutputLayerSets; i++ )
     982    {
     983      if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
     984      {       
     985        READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode );
     986        for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
     987        {
     988          READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 );
     989        }       
     990      }
     991      if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
     992      {     
     993        READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode );
     994      }
     995    }
     996
     997    READ_FLAG( uiCode , "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag( uiCode == 1 );
     998    READ_UVLC( uiCode,  "direct_dep_type_len_minus2"); pcVPS->setDirectDepTypeLenMinus2 ( uiCode );
     999
     1000    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
     1001    {
     1002      for( Int j = 0; j < i; j++ )
     1003      {
     1004        if (pcVPS->getDirectDependencyFlag( i, j) )
     1005        {       
     1006          READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
     1007        }
     1008      }
     1009    }
     1010
     1011    READ_FLAG ( uiCode,                    "vps_shvc_reserved_zero_flag" );
     1012
     1013#if H_3D   
     1014    READ_FLAG( uiCode,  "vps_extension2_flag" );
     1015    if (uiCode)
     1016    {
     1017      m_pcBitstream->readOutTrailingBits();
     1018
     1019      for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
     1020      {
     1021
     1022#if H_3D_ARP
     1023        pcVPS->setUseAdvRP  ( i, 0 );
     1024        pcVPS->setARPStepNum( i, 1 );
     1025#endif 
     1026        if ( i != 0 )
     1027        {
     1028          if( !( pcVPS->getDepthId( i ) == 1 ) )
    6231029          {
    624             READ_FLAG(uiSymbol, "alf_repeat_row _flag"); isRepeatedRow[compIdx] = ((uiSymbol ==1)?true:false);
    625           }
    626          
    627           if(isRepeatedRow[compIdx])
    628           {
    629             alfUnitParam.mergeType = ALF_MERGE_UP;
    630             assert(addrUp >=0);
    631             run[compIdx][i] = run[compIdx][addrUp];
     1030#if H_3D_IV_MERGE
     1031                READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
     1032#endif
     1033#if H_3D_ARP
     1034                READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );  pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
     1035
     1036#endif
     1037#if H_3D_NBDV_REF
     1038                READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
     1039#endif
     1040#if H_3D_VSP
     1041                READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
     1042#endif
    6321043          }
    6331044          else
    6341045          {
    635             if(rx == 0 || run[compIdx][i] < 0)
    636             {             
    637               if(addrUp < 0)
     1046
     1047            READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
     1048            //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false );
     1049#if H_3D_DIM_DLT
     1050            if( pcVPS->getVpsDepthModesFlag( i ) )
     1051            {
     1052              READ_FLAG( uiCode, "dlt_flag[i]" );                       pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
     1053            }
     1054            if( pcVPS->getUseDLTFlag( i ) )
     1055            {
     1056              // decode mapping
     1057              UInt uiNumDepthValues;
     1058              // parse number of values in DLT
     1059              READ_UVLC(uiNumDepthValues, "num_depth_values_in_dlt[i]");
     1060
     1061              // parse actual DLT values
     1062              Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
     1063              for(Int d=0; d<uiNumDepthValues; d++)
    6381064              {
    639                 //alf_run_diff u(v)
    640                 parseAlfFixedLengthRun(uiSymbol, rx, numLCUInWidth);
    641                 run[compIdx][i] = uiSymbol;
     1065                READ_UVLC(uiCode, "dlt_depth_value[i][d]");
     1066                aiIdx2DepthValue[d] = (Int)uiCode;
    6421067              }
    643               else
    644               {
    645                 //alf_run_diff s(v)
    646                 READ_SVLC(iSymbol, "alf_run_diff");
    647                 run[compIdx][i] = run[compIdx][addrUp] + iSymbol;
    648                 assert(run[compIdx][i] >= 0);
    649               }
    650              
    651               if(ry > 0 && (addrUp >=0 || alfAcrossSlice))
    652               {
    653                 //alf_merge_up_flag
    654                 READ_FLAG(uiSymbol, "alf_merge_up_flag");  alfUnitParam.mergeType = ((uiSymbol ==1)?ALF_MERGE_UP:ALF_MERGE_DISABLED);
    655               }
    656               else
    657               {
    658                 alfUnitParam.mergeType = ALF_MERGE_DISABLED;
    659               }
    660              
    661               if(alfUnitParam.mergeType != ALF_MERGE_UP)
    662               {
    663                 //alf_lcu_enable_flag
    664                 READ_FLAG(uiSymbol, "alf_lcu_enable_flag");  alfUnitParam.isEnabled = ((uiSymbol ==1)?true:false);
    665                
    666                 if(alfUnitParam.isEnabled)
    667                 {
    668                   if(numStoredFilters[compIdx] > 0)
    669                   {
    670                     //alf_new_filter_set_flag
    671                     READ_FLAG(uiSymbol, "alf_new_filter_set_flag");  alfUnitParam.isNewFilt = ((uiSymbol ==1)?true:false);
    672                    
    673                     if(!alfUnitParam.isNewFilt)
    674                     {
    675                       //alf_stored_filter_set_idx
    676                       parseAlfStoredFilterIdx(uiSymbol, numStoredFilters[compIdx]);
    677                      
    678                       alfUnitParam.storedFiltIdx = uiSymbol;
    679                      
    680                       assert( alfUnitParam.storedFiltIdx < numStoredFilters[compIdx]);
    681                     }
    682                   }
    683                   else
    684                   {
    685                     alfUnitParam.isNewFilt = true;
    686                   }
    687                  
    688                   if(alfUnitParam.isNewFilt)
    689                   {
    690                     alfUnitParam.alfFiltParam = new ALFParam(compIdx);
    691                     xParseAlfParam(alfUnitParam.alfFiltParam);
    692                     alfUnitParam.alfFiltParam->alf_flag = 1;
    693                    
    694                     numStoredFilters[compIdx]++;
    695                   }
    696                 }
    697                
    698               }
     1068
     1069              pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
     1070
     1071              // clean memory
     1072              free(aiIdx2DepthValue);
    6991073            }
    700             else
    701             {
    702               alfUnitParam.mergeType = ALF_MERGE_LEFT;
    703             }
    704            
    705             run[compIdx][i+1] = run[compIdx][i] -1;
     1074#endif
     1075#if LGE_INTER_SDC_E0156
     1076            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
     1077#endif
    7061078          }
    707          
    708         }
    709         else // uni-param
    710         {
    711           if(i == 0)
    712           {
    713             alfUnitParam.mergeType = ALF_MERGE_DISABLED;
    714            
    715             //alf_lcu_enable_flag
    716             READ_FLAG(uiSymbol, "alf_lcu_enable_flag");  alfUnitParam.isEnabled = ((uiSymbol ==1)?true:false);
    717             if(alfUnitParam.isEnabled)
    718             {
    719               alfUnitParam.isNewFilt = true;
    720               alfUnitParam.alfFiltParam = new ALFParam(compIdx);
    721               xParseAlfParam(alfUnitParam.alfFiltParam);
    722               alfUnitParam.alfFiltParam->alf_flag = 1;
    723             }
    724           }
    725           else
    726           {
    727             alfUnitParam.mergeType = ALF_MERGE_FIRST;
    728           }
    729          
    730         }
    731       }
    732       else
    733       {
    734         alfUnitParam.mergeType = ALF_MERGE_DISABLED;
    735         alfUnitParam.isEnabled = false;
    736       }
    737     }
    738   }
    739  
    740   for(Int compIdx =0; compIdx < NUM_ALF_COMPONENT; compIdx++)
    741   {
    742     delete[] run[compIdx];
    743   }
    744 }
    745 
    746 
    747 Void TDecCavlc::parseAlfFixedLengthRun( UInt& idx, UInt rx, UInt numLCUInWidth )
    748 {
    749   assert(numLCUInWidth > rx);
    750  
    751   UInt length = 0; 
    752   UInt maxNumRun = numLCUInWidth - rx - 1;
    753  
    754   for(UInt i=0; i<32; i++)
    755   {
    756     if(maxNumRun&0x1)
    757     {
    758       length = i+1;
    759     }
    760     maxNumRun = (maxNumRun >> 1);
    761   }
    762  
    763   idx = 0;
    764   if(length)
    765   {
    766     READ_CODE( length, idx, "alf_run_diff" );
    767   }
    768   else
    769   {
    770     idx = 0;
    771   }
    772 }
    773 
    774 
    775 Void TDecCavlc::parseAlfStoredFilterIdx( UInt& idx, UInt numFilterSetsInBuffer )
    776 {
    777   assert(numFilterSetsInBuffer > 0);
    778  
    779   UInt length = 0; 
    780   UInt maxValue = numFilterSetsInBuffer - 1;
    781  
    782   for(UInt i=0; i<32; i++)
    783   {
    784     if(maxValue&0x1)
    785     {
    786       length = i+1;
    787     }
    788     maxValue = (maxValue >> 1);
    789   }
    790  
    791   idx = 0;
    792   if(length)
    793   {
    794     READ_CODE( length, idx, "alf_stored_filter_set_idx" );
    795   }
    796   else
    797   {
    798     idx = 0;
    799   }
    800 }
    801 
    802 
    803 Void TDecCavlc::xParseAlfParam(ALFParam* pAlfParam)
    804 {
    805   UInt uiSymbol;
    806   Int iSymbol;
    807   Int sqrFiltLengthTab[NUM_ALF_FILTER_SHAPE] = {ALF_FILTER_LEN};
    808 
    809   switch(pAlfParam->componentID)
    810   {
    811   case ALF_Cb:
    812   case ALF_Cr:
    813     {
    814       pAlfParam->filter_shape = ALF_CROSS9x7_SQUARE3x3;
    815       pAlfParam->num_coeff = sqrFiltLengthTab[pAlfParam->filter_shape];
    816       pAlfParam->filters_per_group = 1;
    817       for(Int pos=0; pos< pAlfParam->num_coeff; pos++)
    818       {
    819         READ_SVLC(iSymbol, "alf_filt_coeff");
    820         pAlfParam->coeffmulti[0][pos] = iSymbol;
    821       }
    822     }
    823     break;
    824   case ALF_Y:
    825     {
    826   pAlfParam->filters_per_group = 0;
    827   memset (pAlfParam->filterPattern, 0 , sizeof(Int)*NO_VAR_BINS);
    828   pAlfParam->filter_shape = 0;
    829   pAlfParam->num_coeff = sqrFiltLengthTab[pAlfParam->filter_shape];
    830 
    831   // filters_per_fr
    832   READ_UVLC (uiSymbol, "alf_no_filters_minus1");
    833   pAlfParam->filters_per_group = uiSymbol + 1;
    834 
    835   if(uiSymbol == 1) // filters_per_group == 2
    836   {
    837     READ_UVLC (uiSymbol, "alf_start_second_filter");
    838     pAlfParam->startSecondFilter = uiSymbol;
    839     pAlfParam->filterPattern [uiSymbol] = 1;
    840   }
    841   else if (uiSymbol > 1) // filters_per_group > 2
    842   {
    843     pAlfParam->filters_per_group = 1;
    844     Int numMergeFlags = 16;
    845     for (Int i=1; i<numMergeFlags; i++)
    846     {
    847       READ_FLAG (uiSymbol,  "alf_filter_pattern");
    848       pAlfParam->filterPattern[i] = uiSymbol;
    849       pAlfParam->filters_per_group += uiSymbol;
    850     }
    851   }
    852 
    853   if (pAlfParam->filters_per_group > 1)
    854   {
    855     READ_FLAG (uiSymbol, "alf_pred_method");
    856     pAlfParam->predMethod = uiSymbol;
    857   }
    858   for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
    859   {
    860     READ_FLAG (uiSymbol,"alf_nb_pred_luma");
    861     pAlfParam->nbSPred[idx] = uiSymbol;
    862   }
    863 
    864   Int minScanVal = MIN_SCAN_POS_CROSS;
    865 
    866   // Determine maxScanVal
    867   Int maxScanVal = 0;
    868   Int *pDepthInt = pDepthIntTabShapes[pAlfParam->filter_shape];
    869   for(Int idx = 0; idx < pAlfParam->num_coeff; idx++)
    870   {
    871     maxScanVal = max(maxScanVal, pDepthInt[idx]);
    872   }
    873 
    874   // Golomb parameters
    875   if( pAlfParam->filters_per_group > 1 )
    876   {
    877   READ_UVLC (uiSymbol, "alf_min_kstart_minus1");
    878   pAlfParam->minKStart = 1 + uiSymbol;
    879 
    880   Int kMin = pAlfParam->minKStart;
    881 
    882   for(Int scanPos = minScanVal; scanPos < maxScanVal; scanPos++)
    883   {
    884     READ_FLAG (uiSymbol, "alf_golomb_index_bit");
    885     pAlfParam->kMinTab[scanPos] = kMin + uiSymbol;
    886     kMin = pAlfParam->kMinTab[scanPos];
    887   }
    888   }
    889 
    890   Int scanPos;
    891   for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
    892   {
    893     for(Int i = 0; i < pAlfParam->num_coeff; i++)
    894     {
    895       scanPos = pDepthInt[i] - 1;
    896       Int k = (pAlfParam->filters_per_group == 1) ? kTableTabShapes[ALF_CROSS9x7_SQUARE3x3][i] : pAlfParam->kMinTab[scanPos];
    897       pAlfParam->coeffmulti[idx][i] = xGolombDecode(k);
    898     }
    899   }
    900     }
    901     break;
    902   default:
    903     {
    904       printf("Not a legal component ID for ALF\n");
    905       assert(0);
    906       exit(-1);
    907     }
    908   }
    909 }
    910 
    911 Int TDecCavlc::xGolombDecode(Int k)
    912 {
    913   UInt uiSymbol;
    914   Int q = -1;
    915   Int nr = 0;
    916   Int a;
    917 
    918   uiSymbol = 1;
    919   while (uiSymbol)
    920   {
    921     xReadFlag(uiSymbol);
    922     q++;
    923   }
    924   for(a = 0; a < k; ++a)          // read out the sequential log2(M) bits
    925   {
    926     xReadFlag(uiSymbol);
    927     if(uiSymbol)
    928       nr += 1 << a;
    929   }
    930   nr += q << k;
    931   if(nr != 0)
    932   {
    933     xReadFlag(uiSymbol);
    934     nr = (uiSymbol)? nr: -nr;
    935   }
    936 #if ENC_DEC_TRACE
    937   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    938   fprintf( g_hTrace, "%-40s ge(v) : %d\n", "alf_coeff_luma", nr );
    939 #endif
    940   return nr;
    941 }
    942 
    943 Void TDecCavlc::parsePPS(TComPPS* pcPPS, ParameterSetManagerDecoder *parameterSet)
    944 {
    945 #if ENC_DEC_TRACE 
    946   xTracePPSHeader (pcPPS);
    947 #endif
    948   UInt  uiCode;
    949 
    950   Int   iCode;
    951 
    952   READ_UVLC( uiCode, "pic_parameter_set_id");                      pcPPS->setPPSId (uiCode);
    953   READ_UVLC( uiCode, "seq_parameter_set_id");                      pcPPS->setSPSId (uiCode);
    954 
    955   READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
    956   if( pcPPS->getSignHideFlag() )
    957   {
    958     READ_CODE( 4, uiCode, "sign_hiding_threshold"); pcPPS->setTSIG(uiCode);
    959   }
    960 
    961 #if CABAC_INIT_FLAG
    962   READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
    963 #endif
    964   // entropy_coding_mode_flag
    965   // We code the entropy_coding_mode_flag, it's needed for tests.
    966   READ_FLAG( uiCode, "entropy_coding_mode_flag" );                 pcPPS->setEntropyCodingMode( uiCode ? true : false );
    967   if (pcPPS->getEntropyCodingMode())
    968   {
    969   }
    970  
    971   // num_ref_idx_l0_default_active_minus1
    972   // num_ref_idx_l1_default_active_minus1
    973   READ_SVLC(iCode, "pic_init_qp_minus26" );                        pcPPS->setPicInitQPMinus26(iCode);
    974   READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
    975   READ_FLAG( uiCode, "enable_temporal_mvp_flag" );                 pcPPS->setEnableTMVPFlag( uiCode ? true : false );
    976   READ_CODE( 2, uiCode, "slice_granularity" );                     pcPPS->setSliceGranularity(uiCode);
    977 
    978   // alf_param() ?
    979 
    980   READ_UVLC( uiCode, "max_cu_qp_delta_depth");
    981   if(uiCode == 0)
    982   {
    983     pcPPS->setUseDQP (false);
    984     pcPPS->setMaxCuDQPDepth( 0 );
    985   }
    986   else
    987   {
    988     pcPPS->setUseDQP (true);
    989     pcPPS->setMaxCuDQPDepth(uiCode - 1);
    990   }
    991 
    992   READ_SVLC( iCode, "chroma_qp_offset");
    993   pcPPS->setChromaQpOffset(iCode);
    994 
    995   READ_SVLC( iCode, "chroma_qp_offset_2nd");
    996   pcPPS->setChromaQpOffset2nd(iCode);
    997 
    998   READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
    999   pcPPS->setUseWP( uiCode==1 );
    1000   READ_CODE( 2, uiCode, "weighted_bipred_idc" );      // Use of Bi-Directional Weighting Prediction (B_SLICE)
    1001   pcPPS->setWPBiPredIdc( uiCode );
    1002 //printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPredIdc());
    1003 
    1004   READ_FLAG( uiCode, "output_flag_present_flag" );
    1005   pcPPS->setOutputFlagPresentFlag( uiCode==1 );
    1006 
    1007   if(parameterSet->getPrefetchedSPS(pcPPS->getSPSId())->getTilesOrEntropyCodingSyncIdc()==1)
    1008   {
    1009     READ_FLAG ( uiCode, "tile_info_present_flag" );
    1010     pcPPS->setColumnRowInfoPresent(uiCode);
    1011     READ_FLAG ( uiCode, "tile_control_present_flag" );
    1012     pcPPS->setTileBehaviorControlPresentFlag(uiCode);
    1013     if( pcPPS->getColumnRowInfoPresent() == 1 )
    1014     {
    1015       READ_UVLC ( uiCode, "num_tile_columns_minus1" );   
    1016       pcPPS->setNumColumnsMinus1( uiCode ); 
    1017       READ_UVLC ( uiCode, "num_tile_rows_minus1" ); 
    1018       pcPPS->setNumRowsMinus1( uiCode ); 
    1019       READ_FLAG ( uiCode, "uniform_spacing_flag" ); 
    1020       pcPPS->setUniformSpacingIdr( uiCode );
    1021 
    1022       if( pcPPS->getUniformSpacingIdr() == 0 )
    1023       {
    1024         UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
    1025         for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
    1026         {
    1027           READ_UVLC( uiCode, "column_width" ); 
    1028           columnWidth[i] = uiCode; 
    1029         }
    1030         pcPPS->setColumnWidth(columnWidth);
    1031         free(columnWidth);
    1032 
    1033         UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt));
    1034         for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++)
    1035         {
    1036           READ_UVLC( uiCode, "row_height" ); 
    1037           rowHeight[i] = uiCode; 
    1038         }
    1039         pcPPS->setRowHeight(rowHeight);
    1040         free(rowHeight); 
    1041       }
    1042     }
    1043 
    1044 
    1045     if(pcPPS->getTileBehaviorControlPresentFlag() == 1)
    1046     {
    1047       Int iNumColTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumColumnsMinus1());
    1048       Int iNumRowTilesMinus1 = (pcPPS->getColumnRowInfoPresent() == 1)?(pcPPS->getNumColumnsMinus1()):(pcPPS->getSPS()->getNumRowsMinus1());
    1049       pcPPS->setLFCrossTileBoundaryFlag(true); //default
    1050 
    1051       if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0)
    1052       {
    1053           READ_FLAG ( uiCode, "loop_filter_across_tile_flag" ); 
    1054           pcPPS->setLFCrossTileBoundaryFlag( (uiCode == 1)?true:false );
    1055       }
    1056     }
    1057   }
    1058   else if(parameterSet->getPrefetchedSPS(pcPPS->getSPSId())->getTilesOrEntropyCodingSyncIdc()==2)
    1059   {
    1060     READ_UVLC( uiCode, "num_substreams_minus1" );                pcPPS->setNumSubstreams(uiCode+1);
    1061   }
    1062 
    1063   READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );
    1064   pcPPS->setDeblockingFilterControlPresent( uiCode ? true : false);
    1065   READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
    1066   assert(uiCode == LOG2_PARALLEL_MERGE_LEVEL_MINUS2);
    1067   pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
    1068 
    1069   READ_FLAG( uiCode, "pps_extension_flag");
    1070   if (uiCode)
    1071   {
     1079        }
     1080      }
     1081      READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false );
     1082    }
     1083#endif
     1084    pcVPS->checkVPSExtensionSyntax();
     1085
     1086    pcVPS->setRefLayers();
     1087
     1088#else
    10721089    while ( xMoreRbspData() )
    10731090    {
    1074       READ_FLAG( uiCode, "pps_extension_data_flag");
    1075     }
    1076   }
    1077 }
    1078 #if QC_MVHEVC_B0046
    1079 Void TDecCavlc::parseVPS(TComVPS* pcVPS)
    1080 {
    1081   UInt  uiCode;
    1082   READ_CODE( 4, uiCode,  "video_parameter_set_id"   );       pcVPS->setVPSId( uiCode );
    1083   READ_FLAG( uiCode,     "temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
    1084   READ_CODE( 2, uiCode,  "vps_reserved_zero_2bits" );         assert( !uiCode );
    1085   READ_CODE( 6, uiCode,  "vps_max_layers_minus1" );               pcVPS->setMaxLayers( uiCode + 1 );
    1086   READ_CODE( 3, uiCode,  "vps_max_sub_layers_minus1" );      pcVPS->setMaxTLayers( uiCode + 1 );
    1087   READ_CODE( 12, uiCode, "vps_extension_offset"      );      assert( !uiCode );
    1088   for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
    1089   {
    1090     READ_UVLC( uiCode,  "max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
    1091     READ_UVLC( uiCode,  "num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
    1092     READ_UVLC( uiCode,  "max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
    1093   }
    1094   READ_UVLC( uiCode,                 "vps_num_hrd_parameters"   ); pcVPS->setNumHRDParameters(uiCode);
    1095   assert(pcVPS->getNumHRDParameters()==0);
    1096   for ( UInt i = 0; i < pcVPS->getNumHRDParameters(); i ++)
    1097   {
    1098    //   if( i > 0 ) 
    1099     //{
    1100     //  READ_UVLC (0, "op_num_layer_id_values_minus1[ opIdx ]");
    1101     //  for( i = 0; i <= op_num_layer_id_values_minus1[ opIdx ]; i++ ) 
    1102     //    READ_UVLC(0, 6, "op_layer_id[ opIdx ][ i ]");
    1103     //} 
    1104     //hrd_parameters( i  = =  0, vps_max_sub_layers_minus1 ); 
    1105   }
    1106  
    1107   READ_CODE( 1, uiCode, "bit_equal_to_one" );             assert( uiCode );
    1108   //vps_extension_byte_alignment_reserved_one_bit
    1109   xReadVPSAlignOne();
    1110   READ_CODE( 8, uiCode, "num_additional_layer_operation_points" );     pcVPS->setNumAddiLayerOperationPoints( uiCode );
    1111   READ_CODE( 8, uiCode, "num_additional_profile_level_sets"     );     pcVPS->setNumAddiProLevelSets( uiCode);
    1112 
    1113 
    1114   for(UInt i=0; i <= pcVPS->getMaxLayers()-1; i++)
    1115   {
    1116     READ_CODE( 4,  uiCode,             "num_types_zero_4bits[i]" );   assert( !uiCode );
    1117     READ_CODE( 4,  uiCode,             "type_zero_4bits[i]"      );   assert( !uiCode );
    1118     READ_CODE( 8,  uiCode,             "view_id[i]" );                pcVPS->setViewId(uiCode, i);
    1119     // WRITE_SVLC( pcVPS->getViewOrderIdx(i),                  "view_order_idx[i]" );
    1120     if(i)
    1121     {
    1122       READ_CODE( 6, uiCode,  "num_direct_ref_layers[ i ]" );    pcVPS->setNumDirectRefLayer(uiCode, i);
    1123       for (UInt j = 0; j< pcVPS->getNumDirectRefLayer(i); j++)
    1124       {
    1125         READ_CODE( 6, uiCode, "ref_layer_id[i][j]" );         pcVPS->setDirectRefLayerId (uiCode, i, j);
    1126       }
    1127     }
    1128   }
    1129   for( UInt i=1; i<=pcVPS->getNumAddiProLevelSets(); i++)
    1130   {
    1131     //profile_tier_level
    1132   }
    1133   for( UInt i=1; i<= pcVPS->getNumAddiLayerOperationPoints(); i++)
    1134   {   
    1135     if(pcVPS->getMaxLayers() == 3)
    1136     {
    1137       pcVPS->setNumOpLayerIdMinus1((i < pcVPS->getNumAddiLayerOperationPoints() ? 1: 2), (i-1));
    1138     }
    1139     else if( i==1 )
    1140     {
    1141       assert(pcVPS->getNumAddiLayerOperationPoints()==1);
    1142       pcVPS->setNumOpLayerIdMinus1(pcVPS->getMaxLayers()-1, (i-1));
    1143     }
    1144     READ_UVLC( uiCode,           "op_num_layer_id_values_minus1[ opIdx ]" ); pcVPS->setNumOpLayerIdMinus1(uiCode, i-1);
    1145     for(UInt j = 0; j <= pcVPS->getNumOpLayerIdMinus1(i-1); j++ )
    1146     {
    1147       READ_UVLC( uiCode,           "op_layer_id[ opIdx ][ i ]" ); pcVPS->setNumOpLayerId(uiCode, i-1, j);
    1148     }
    1149     if (pcVPS->getNumAddiProLevelSets())
    1150     {
    1151       //profile_level_idx[ i ]
    1152     }
    1153   }
     1091      READ_FLAG( uiCode, "vps_extension_data_flag");
     1092    }
     1093#endif   
     1094  }
     1095
     1096#if H_3D
     1097  pcVPS->initViewIndex();
     1098#endif
    11541099  return;
    11551100}
    1156 #else
    1157 #if VIDYO_VPS_INTEGRATION
    1158 Void TDecCavlc::parseVPS(TComVPS* pcVPS)
     1101
     1102Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
    11591103{
    11601104  UInt  uiCode;
    11611105  Int   iCode;
    1162  
    1163   READ_CODE( 3, uiCode, "max_temporal_layers_minus1" );   pcVPS->setMaxTLayers( uiCode + 1 );
    1164   READ_CODE( 5, uiCode, "max_layers_minus1" );            pcVPS->setMaxLayers( uiCode + 1 );
    1165   READ_FLAG( uiCode,  "temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
    1166   READ_UVLC( uiCode,  "video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
    1167   for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
    1168   {
    1169     READ_UVLC( uiCode,  "max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
    1170     READ_UVLC( uiCode,  "num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
    1171     READ_UVLC( uiCode,  "max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
    1172   }
    1173  
    1174   READ_CODE( 1, uiCode, "bit_equal_to_one" );             assert( uiCode );
    1175  
    1176   if( pcVPS->getMaxLayers() - 1 > 0 )
    1177   {
    1178     READ_UVLC( uiCode,  "extension_type" );               pcVPS->setExtensionType( uiCode );
    1179    
    1180     pcVPS->setViewOrderIdx( 0, 0 );
    1181     pcVPS->setViewId( 0, 0 );
    1182     pcVPS->setDepthFlag( 0, 0 );
    1183     for(UInt i = 1; i <= pcVPS->getMaxLayers()-1; i++)
    1184     {
    1185       READ_FLAG( uiCode, "dependent_flag[i]" );           pcVPS->setDependentFlag( uiCode ? true:false, i);
    1186       if( pcVPS->getDependentFlag(i) )
    1187       {
    1188         READ_UVLC( uiCode,  "delta_reference_layer_id_minus1[i]" ); pcVPS->setDependentLayer( i - uiCode + 1, i );
    1189         if( pcVPS->getExtensionType() == VPS_EXTENSION_TYPE_MULTI_VIEW )
    1190         {
    1191           READ_UVLC( uiCode,  "view_id[i]" );             pcVPS->setViewId( uiCode, i );
    1192           READ_FLAG( uiCode,  "depth_flag[i]" );          pcVPS->setDepthFlag( uiCode ? true:false, i );
    1193           READ_SVLC( iCode,  "view_order_idx[i]" );       pcVPS->setViewOrderIdx( iCode, i );
    1194         }
    1195        
    1196       }
    1197     }
    1198 #if INTER_VIEW_VECTOR_SCALING_C0115
    1199     READ_FLAG( uiCode,  "inter_view_vector_scaling_flag" );    pcVPS->setIVScalingFlag( uiCode ? true:false);
    1200 #endif
    1201   }
    1202  
    1203   READ_FLAG( uiCode,  "vps_extension_flag" );          assert(!uiCode);
    1204   //future extensions go here..
    1205  
    1206   return;
    1207 }
    1208 
    1209 #endif
    1210 #endif
    1211 #if HHI_MPI || H3D_QTL
    1212 Void TDecCavlc::parseSPS(TComSPS* pcSPS, Bool bIsDepth)
    1213 #else
    1214 Void TDecCavlc::parseSPS(TComSPS* pcSPS)
    1215 #endif
    1216 {
    1217 #if ENC_DEC_TRACE 
    1218   xTraceSPSHeader (pcSPS);
    1219 #endif
    1220  
    1221   UInt  uiCode;
    1222 #if !QC_MVHEVC_B0046
    1223   Int   iCode;
    1224 #endif
    1225   READ_CODE( 8,  uiCode, "profile_idc" );                        pcSPS->setProfileIdc( uiCode );
    1226   READ_CODE( 8,  uiCode, "reserved_zero_8bits" );
    1227   READ_CODE( 8,  uiCode, "level_idc" );                          pcSPS->setLevelIdc( uiCode );
    1228   READ_UVLC(     uiCode, "seq_parameter_set_id" );               pcSPS->setSPSId( uiCode );
    1229 #if VIDYO_VPS_INTEGRATION
    1230   READ_UVLC(     uiCode, "video_parameter_set_id" );             pcSPS->setVPSId( uiCode );
    1231 #endif
    1232   READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
    1233   READ_CODE( 3,  uiCode, "max_temporal_layers_minus1" );         pcSPS->setMaxTLayers( uiCode+1 );
    1234   READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
    1235   READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
    1236   READ_FLAG(     uiCode, "pic_cropping_flag");                   pcSPS->setPicCroppingFlag ( uiCode ? true : false );
    1237   if (uiCode != 0)
    1238   {
    1239     READ_UVLC(   uiCode, "pic_crop_left_offset" );               pcSPS->setPicCropLeftOffset( uiCode );
    1240     READ_UVLC(   uiCode, "pic_crop_right_offset" );              pcSPS->setPicCropRightOffset( uiCode );
    1241     READ_UVLC(   uiCode, "pic_crop_top_offset" );                pcSPS->setPicCropTopOffset( uiCode );
    1242     READ_UVLC(   uiCode, "pic_crop_bottom_offset" );             pcSPS->setPicCropBottomOffset( uiCode );
    1243   }
    1244 
    1245 #if FULL_NBIT
    1246   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    1247   g_uiBitDepth = 8 + uiCode;
    1248   g_uiBitIncrement = 0;
    1249   pcSPS->setBitDepth(g_uiBitDepth);
    1250   pcSPS->setBitIncrement(g_uiBitIncrement);
    1251 #else
    1252   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
    1253   g_uiBitDepth = 8;
    1254   g_uiBitIncrement = uiCode;
    1255   pcSPS->setBitDepth(g_uiBitDepth);
    1256   pcSPS->setBitIncrement(g_uiBitIncrement);
    1257 #endif
    1258  
    1259 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1260   g_iDeltaDCsQuantOffset = g_uiBitIncrement - 2;
    1261 #endif
    1262 
    1263   pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
    1264 
    1265   g_uiBASE_MAX  = ((1<<(g_uiBitDepth))-1);
    1266  
    1267 #if IBDI_NOCLIP_RANGE
    1268   g_uiIBDI_MAX  = g_uiBASE_MAX << g_uiBitIncrement;
    1269 #else
    1270   g_uiIBDI_MAX  = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1);
    1271 #endif
    1272   READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
    1273   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
    1274 
    1275   READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
    1276 
    1277   if( pcSPS->getUsePCM() )
    1278   {
    1279     READ_CODE( 4, uiCode, "pcm_bit_depth_luma_minus1" );           pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
    1280     READ_CODE( 4, uiCode, "pcm_bit_depth_chroma_minus1" );         pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
    1281   }
    1282 
    1283 #if LOSSLESS_CODING
    1284   READ_FLAG( uiCode, "qpprime_y_zero_transquant_bypass_flag" );    pcSPS->setUseLossless ( uiCode ? true : false );
    1285 #endif
    1286 
    1287   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
    1288   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    1289   {
    1290     READ_UVLC ( uiCode, "max_dec_pic_buffering");
    1291     pcSPS->setMaxDecPicBuffering( uiCode, i);
    1292     READ_UVLC ( uiCode, "num_reorder_pics" );
    1293     pcSPS->setNumReorderPics(uiCode, i);
    1294     READ_UVLC ( uiCode, "max_latency_increase");
    1295     pcSPS->setMaxLatencyIncrease( uiCode, i );
    1296   }
    1297 
    1298   READ_FLAG( uiCode, "restricted_ref_pic_lists_flag" );
    1299   pcSPS->setRestrictedRefPicListsFlag( uiCode );
    1300   if( pcSPS->getRestrictedRefPicListsFlag() )
    1301   {
    1302     READ_FLAG( uiCode, "lists_modification_present_flag" );
    1303     pcSPS->setListsModificationPresentFlag(uiCode);
    1304   }
    1305   else
    1306   {
    1307     pcSPS->setListsModificationPresentFlag(true);
    1308   }
    1309   READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
    1310   UInt log2MinCUSize = uiCode + 3;
    1311   READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
    1312   UInt uiMaxCUDepthCorrect = uiCode;
    1313   pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUWidth  = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
    1314   pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUHeight = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
    1315   READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
    1316 
    1317   READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
    1318   pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
    1319 
    1320   if(log2MinCUSize == 3)
    1321   {
    1322     xReadFlag( uiCode ); pcSPS->setDisInter4x4( uiCode ? true : false );
    1323   }
    1324 
    1325   if( pcSPS->getUsePCM() )
    1326   {
    1327     READ_UVLC( uiCode, "log2_min_pcm_coding_block_size_minus3" );  pcSPS->setPCMLog2MinSize (uiCode+3);
    1328     READ_UVLC( uiCode, "log2_diff_max_min_pcm_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
    1329   }
    1330 
    1331   READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
    1332   READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
    1333   g_uiAddCUDepth = 0;
    1334   while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth )  ) )
    1335   {
    1336     g_uiAddCUDepth++;
    1337   }
    1338   pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth  );
    1339   g_uiMaxCUDepth  = uiMaxCUDepthCorrect+g_uiAddCUDepth;
    1340   // BB: these parameters may be removed completly and replaced by the fixed values
    1341   pcSPS->setMinTrDepth( 0 );
    1342   pcSPS->setMaxTrDepth( 1 );
    1343   READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
    1344   READ_FLAG( uiCode, "chroma_pred_from_luma_enabled_flag" );        pcSPS->setUseLMChroma ( uiCode ? true : false );
    1345   READ_FLAG( uiCode, "deblocking_filter_in_aps_enabled_flag" );     pcSPS->setUseDF ( uiCode ? true : false ); 
    1346   READ_FLAG( uiCode, "loop_filter_across_slice_flag" );             pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false);
    1347   READ_FLAG( uiCode, "asymmetric_motion_partitions_enabled_flag" ); pcSPS->setUseAMP( uiCode );
    1348   READ_FLAG( uiCode, "non_square_quadtree_enabled_flag" );          pcSPS->setUseNSQT( uiCode );
    1349   READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false ); 
    1350   READ_FLAG( uiCode, "adaptive_loop_filter_enabled_flag" );         pcSPS->setUseALF ( uiCode ? true : false );
    1351   if(pcSPS->getUseALF())
    1352   {
    1353     READ_FLAG( uiCode, "alf_coef_in_slice_flag" );      pcSPS->setUseALFCoefInSlice ( uiCode ? true : false );
    1354   }
    1355   if( pcSPS->getUsePCM() )
    1356   {
    1357     READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );           pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
    1358   }
    1359 
    1360   READ_FLAG( uiCode, "temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
    1361 
    1362 
    1363   TComRPSList* rpsList = pcSPS->getRPSList();
    1364   TComReferencePictureSet* rps;
    1365 
    1366   READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
    1367   rpsList->create(uiCode);
    1368 
    1369   for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++)
    1370   {
    1371     rps = rpsList->getReferencePictureSet(i);
    1372     parseShortTermRefPicSet(pcSPS,rps,i);
    1373   }
    1374   READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
    1375  
    1376   // AMVP mode for each depth (AM_NONE or AM_EXPL)
    1377   for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
    1378   {
    1379     xReadFlag( uiCode );
    1380     pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode );
    1381   }
    1382 
    1383   READ_CODE(2, uiCode, "tiles_or_entropy_coding_sync_idc");         pcSPS->setTilesOrEntropyCodingSyncIdc(uiCode);
    1384 
    1385   if(pcSPS->getTilesOrEntropyCodingSyncIdc() == 1)
    1386   {
    1387     READ_UVLC ( uiCode, "num_tile_columns_minus1" );
    1388     pcSPS->setNumColumnsMinus1( uiCode ); 
    1389     READ_UVLC ( uiCode, "num_tile_rows_minus1" );
    1390     pcSPS->setNumRowsMinus1( uiCode );
    1391     READ_FLAG ( uiCode, "uniform_spacing_flag" );
    1392     pcSPS->setUniformSpacingIdr( uiCode );
    1393     if( pcSPS->getUniformSpacingIdr() == 0 )
    1394     {
    1395       UInt* columnWidth = (UInt*)malloc(pcSPS->getNumColumnsMinus1()*sizeof(UInt));
    1396       for(UInt i=0; i<pcSPS->getNumColumnsMinus1(); i++)
    1397       {
    1398         READ_UVLC( uiCode, "column_width" );
    1399         columnWidth[i] = uiCode; 
    1400       }
    1401       pcSPS->setColumnWidth(columnWidth);
    1402       free(columnWidth);
    1403 
    1404       UInt* rowHeight = (UInt*)malloc(pcSPS->getNumRowsMinus1()*sizeof(UInt));
    1405       for(UInt i=0; i<pcSPS->getNumRowsMinus1(); i++)
    1406       {
    1407         READ_UVLC( uiCode, "row_height" );
    1408         rowHeight[i] = uiCode; 
    1409       }
    1410       pcSPS->setRowHeight(rowHeight);
    1411       free(rowHeight); 
    1412     }
    1413     pcSPS->setLFCrossTileBoundaryFlag(true); //default
    1414 
    1415     if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0)
    1416     {
    1417         READ_FLAG ( uiCode, "loop_filter_across_tile_flag" ); 
    1418         pcSPS->setLFCrossTileBoundaryFlag( (uiCode==1)?true:false);
    1419     }
    1420   }
    1421   READ_FLAG( uiCode, "sps_extension_flag");
    1422 #if !QC_MVHEVC_B0046
    1423   if(uiCode)
    1424   {
    1425     READ_FLAG( uiCode, "interview_refs_present_flag");
    1426     if(uiCode)
    1427     {
    1428       READ_UVLC( uiCode, "num_usable_interview_refs_minus1" );
    1429       pcSPS->setNumberOfUsableInterViewRefs( uiCode + 1 );
    1430 
    1431       Int prev = 0;
    1432       for( Int j = 0 ; j < pcSPS->getNumberOfUsableInterViewRefs(); j++ )
    1433       {
    1434         READ_UVLC(uiCode, "delta_usable_interview_ref_minus1");
    1435         pcSPS->setUsableInterViewRef( j, (prev - uiCode - 1) );
    1436         prev = pcSPS->getUsableInterViewRef( j );
    1437       }
    1438     }
    1439 
    1440 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    1441     READ_FLAG( uiCode, "enable_dmm_flag" );
    1442     pcSPS->setUseDMM( uiCode );
    1443 #endif
    1444 
    1445 #if HHI_MPI
    1446     if( bIsDepth )
    1447     {
    1448       READ_FLAG( uiCode, "use_mvi_flag" );
    1449       pcSPS->setUseMVI( uiCode );
    1450     }
    1451 #endif
    1452 #if H3D_QTL
    1453     if( bIsDepth )
    1454     {
    1455       READ_FLAG( uiCode, "use_qtlpc_flag" );
    1456       pcSPS->setUseQTLPC( uiCode );
    1457     }
    1458 #endif
    1459    
    1460 #if RWTH_SDC_DLT_B0036
    1461     if( bIsDepth )
    1462     {
    1463       READ_FLAG( uiCode, "use_dlt_flag" );
    1464       pcSPS->setUseDLT( uiCode );
    1465       if( pcSPS->getUseDLT() )
    1466       {
    1467         // decode mapping
    1468         UInt uiNumDepthValues;
    1469         // parse number of values in DLT
    1470         xReadUvlc( uiNumDepthValues );
    1471        
    1472         // parse actual DLT values
    1473         UInt* auiIdx2DepthValue = (UInt*) calloc(uiNumDepthValues, sizeof(UInt));
    1474         for(UInt d=0; d<uiNumDepthValues; d++)
    1475         {
    1476           xReadUvlc( uiCode );
    1477           auiIdx2DepthValue[d] = uiCode;
    1478         }
    1479        
    1480         pcSPS->setDepthLUTs(auiIdx2DepthValue, uiNumDepthValues);
    1481        
    1482         // clean memory
    1483         free(auiIdx2DepthValue);
    1484       }
    1485       else
    1486         pcSPS->setDepthLUTs();
    1487     }
    1488 #endif
    1489 
    1490     READ_FLAG( uiCode, "base_view_flag" );
    1491     if( uiCode )
    1492     { // baseview SPS -> set standard values
    1493       pcSPS->initMultiviewSPS         ( 0 );
    1494 #if DEPTH_MAP_GENERATION
    1495       pcSPS->setPredDepthMapGeneration( 0, false );
    1496 #endif
    1497 #if H3D_IVRP
    1498 #if QC_ARP_D0177
    1499      pcSPS->setUseAdvRP  ( 0 );
    1500      pcSPS->setARPStepNum( 1 );
    1501 #else
    1502      pcSPS->setMultiviewResPredMode  ( 0 );
    1503 #endif
    1504 #endif
    1505 
    1506     }
    1507     else
    1508     {
    1509       READ_FLAG( uiCode, "depth_flag" );
    1510       if( uiCode )
    1511       {
    1512 #if FCO_FIX_SPS_CHANGE
    1513         UInt  uiViewId, uiCamParPrecision;
    1514         Int   iVOI;
    1515         Bool  bCamParSlice;
    1516         READ_UVLC( uiCode, "view_id" );
    1517         READ_SVLC( iCode, "view_order_idx" );
    1518         uiViewId = uiCode;
    1519         iVOI = iCode;
    1520 
    1521         if ( uiViewId == 0 )
    1522         {
    1523           pcSPS->initMultiviewSPSDepth    ( uiViewId, iVOI );
    1524         }
    1525         else
    1526         {
    1527           READ_UVLC( uiCamParPrecision, "camera_parameter_precision" );
    1528           READ_FLAG( uiCode, "camera_parameter_in_slice_header" );    bCamParSlice = ( uiCode == 1 );
    1529           if( !bCamParSlice )
    1530           {
    1531             for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    1532             {
    1533               READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
    1534               READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
    1535               READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
    1536               READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
    1537             }
    1538           }
    1539           pcSPS->initMultiviewSPSDepth( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
    1540 
    1541         }
    1542 #else
    1543         READ_UVLC( uiCode, "view_id" );
    1544         READ_SVLC(  iCode, "view_order_idx" );
    1545         pcSPS->initMultiviewSPSDepth    ( uiCode, iCode );
    1546 #endif
    1547 #if DEPTH_MAP_GENERATION
    1548 #if FCO_FIX_SPS_CHANGE
    1549         pcSPS->setPredDepthMapGeneration( uiViewId, true );
    1550 #else
    1551         pcSPS->setPredDepthMapGeneration( uiCode, true );
    1552 #endif
    1553 #endif
    1554 #if H3D_IVRP
    1555 #if QC_ARP_D0177
    1556       pcSPS->setUseAdvRP  ( 0 );
    1557       pcSPS->setARPStepNum( 1 );
    1558 #else
    1559       pcSPS->setMultiviewResPredMode  ( 0 );
    1560 #endif
    1561 #endif
    1562 
    1563       }
    1564       else
    1565       {
    1566         UInt  uiViewId, uiCamParPrecision;
    1567         Int   iVOI;
    1568         Bool  bCamParSlice;
    1569         READ_UVLC( uiViewId, "view_id" );  uiViewId++;
    1570         READ_SVLC( iVOI, "view_order_idx" );
    1571         READ_UVLC( uiCamParPrecision, "camera_parameter_precision" );
    1572         READ_FLAG( uiCode, "camera_parameter_in_slice_header" );    bCamParSlice = ( uiCode == 1 );
    1573         if( !bCamParSlice )
    1574         {
    1575           for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    1576           {
    1577             READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
    1578             READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
    1579             READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
    1580             READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
    1581           }
    1582         }
    1583         pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset );
    1584 
    1585 #if DEPTH_MAP_GENERATION
    1586         UInt uiPredDepthMapGeneration = 0, uiPdmPrecision = 0;
    1587 #if H3D_IVMP
    1588         UInt uiMultiviewMvPredMode = 0;
    1589 #endif
    1590 #if H3D_IVRP & !QC_ARP_D0177
    1591       UInt uiMultiviewResPredMode = 0;
    1592 #endif
    1593         READ_UVLC( uiPredDepthMapGeneration, "Pdm_generation" );
    1594         if( uiPredDepthMapGeneration )
    1595         {
    1596           READ_UVLC( uiPdmPrecision, "Pdm_precision" );
    1597           for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    1598           {
    1599             READ_SVLC( iCode, "Pdm_scale_nom_delta" );   m_aaiTempPdmScaleNomDelta[ uiViewId ][ uiBaseId ] = iCode;
    1600             READ_SVLC( iCode, "Pdm_offset" );   m_aaiTempPdmOffset       [ uiViewId ][ uiBaseId ] = iCode;
    1601           }
    1602 #if H3D_IVMP
    1603           READ_UVLC( uiMultiviewMvPredMode, "multi_view_mv_pred_mode" );
    1604 #endif
    1605 #if H3D_IVRP & !QC_ARP_D0177
    1606           READ_FLAG( uiMultiviewResPredMode, "multi_view_residual_pred_mode" );
    1607 #endif
    1608         }
    1609 #if H3D_IVMP
    1610         pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, uiMultiviewMvPredMode, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
    1611 #else
    1612         pcSPS->setPredDepthMapGeneration( uiViewId, false, uiPredDepthMapGeneration, 0, uiPdmPrecision, m_aaiTempPdmScaleNomDelta, m_aaiTempPdmOffset );
    1613 #endif
    1614 #endif
    1615 #if H3D_IVRP
    1616 #if QC_ARP_D0177
    1617       READ_FLAG( uiCode , "advanced_residual_pred_flag" );           pcSPS->setUseAdvRP( uiCode );
    1618       if( pcSPS->getUseAdvRP()  )
    1619           pcSPS->setARPStepNum( QC_ARP_WFNR );
    1620       else
    1621        pcSPS->setARPStepNum( 1 );
    1622 #else
    1623       pcSPS->setMultiviewResPredMode  ( uiMultiviewResPredMode );
    1624 #endif
    1625 #endif
    1626 
    1627       }
    1628 
    1629 #if MTK_D0156
    1630 
    1631       pcSPS->setUseVSPCompensation( false );
    1632       pcSPS->setUseDVPRefine( false );
    1633 
    1634       //Comments: Currently, BVSP and DoNBDV are not used for depth coding
    1635 #if MERL_VSP_COMPENSATION_C0152
    1636       READ_FLAG( uiCode, "view_synthesis_pred_flag" );pcSPS->setUseVSPCompensation( uiCode ? true : false );
    1637 #endif
    1638       READ_FLAG( uiCode, "dv_refine_flag" );          pcSPS->setUseDVPRefine( uiCode ? true : false );
    1639 #endif
    1640     }
    1641     READ_FLAG( uiCode, "sps_extension2_flag");
    1642     if (uiCode)
    1643     {
    1644       while ( xMoreRbspData() )
    1645       {
    1646         READ_FLAG( uiCode, "sps_extension2_data_flag");
    1647       }
    1648     }
    1649   }
    1650 #endif
    1651 }
    1652 
    1653 Void TDecCavlc::readTileMarker   ( UInt& uiTileIdx, UInt uiBitsUsed )
    1654 {
    1655   xReadCode ( uiBitsUsed, uiTileIdx );
    1656 }
    1657 
    1658 #if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
    1659 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet, bool isDepth)
    1660 #else
    1661 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager, AlfCUCtrlInfo &alfCUCtrl, AlfParamSet& alfParamSet)
    1662 #endif
    1663 {
    1664   UInt  uiCode;
    1665   Int   iCode;
    1666  
     1106
    16671107#if ENC_DEC_TRACE
    16681108  xTraceSliceHeader(rpcSlice);
    16691109#endif
    1670   Int numCUs = ((rpcSlice->getSPS()->getPicWidthInLumaSamples()+rpcSlice->getSPS()->getMaxCUWidth()-1)/rpcSlice->getSPS()->getMaxCUWidth())*((rpcSlice->getSPS()->getPicHeightInLumaSamples()+rpcSlice->getSPS()->getMaxCUHeight()-1)/rpcSlice->getSPS()->getMaxCUHeight());
    1671   Int maxParts = (1<<(rpcSlice->getSPS()->getMaxCUDepth()<<1));
    1672   Int numParts = (1<<(rpcSlice->getPPS()->getSliceGranularity()<<1));
    1673   UInt lCUAddress = 0;
    1674   Int reqBitsOuter = 0;
    1675   while(numCUs>(1<<reqBitsOuter))
    1676   {
    1677     reqBitsOuter++;
    1678   }
    1679   Int reqBitsInner = 0;
    1680   while((numParts)>(1<<reqBitsInner))
    1681   {
    1682     reqBitsInner++;
    1683   }
    1684 
    1685   READ_FLAG( uiCode, "first_slice_in_pic_flag" );
    1686   UInt address;
    1687   UInt innerAddress = 0;
    1688 
    1689 #if LGE_ILLUCOMP_B0045
    1690   // IC flag is on only first_slice_in_pic
    1691   if (uiCode)
    1692   {
    1693     UInt uiCodeTmp = 0;
    1694     if ( rpcSlice->getSPS()->getViewId()
    1695 #if !LGE_ILLUCOMP_DEPTH_C0046
    1696         && !rpcSlice->getSPS()->isDepth()
    1697 #endif
    1698         )
    1699     {
    1700       READ_FLAG (uiCodeTmp, "applying IC flag");
    1701     }
    1702     rpcSlice->setApplyIC(uiCodeTmp);
    1703 #if SHARP_ILLUCOMP_PARSE_D0060
    1704     if (rpcSlice->getApplyIC())
    1705     {
    1706       READ_FLAG (uiCodeTmp, "ic_skip_mergeidx0");
    1707       rpcSlice->setIcSkipParseFlag(uiCodeTmp);
    1708     }
    1709 #endif
    1710   }
    1711 #endif
    1712 
    1713   if(!uiCode)
    1714   {
    1715     READ_CODE( reqBitsOuter+reqBitsInner, address, "slice_address" );
    1716     lCUAddress = address >> reqBitsInner;
    1717     innerAddress = address - (lCUAddress<<reqBitsInner);
    1718   }
    1719   //set uiCode to equal slice start address (or entropy slice start address)
    1720   uiCode=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(rpcSlice->getPPS()->getSliceGranularity()<<1)));
    1721  
    1722   rpcSlice->setEntropySliceCurStartCUAddr( uiCode );
    1723   rpcSlice->setEntropySliceCurEndCUAddr(numCUs*maxParts);
    1724 
    1725   //   slice_type
    1726   READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
    1727   // lightweight_slice_flag
    1728   READ_FLAG( uiCode, "entropy_slice_flag" );
    1729   Bool bEntropySlice = uiCode ? true : false;
    1730 
    1731   if (bEntropySlice)
    1732   {
    1733     rpcSlice->setNextSlice        ( false );
    1734     rpcSlice->setNextEntropySlice ( true  );
    1735   }
    1736   else
    1737   {
    1738     rpcSlice->setNextSlice        ( true  );
    1739     rpcSlice->setNextEntropySlice ( false );
    1740    
    1741     uiCode=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(rpcSlice->getPPS()->getSliceGranularity()<<1)));
    1742     rpcSlice->setSliceCurStartCUAddr(uiCode);
    1743     rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts);
    1744   }
    17451110  TComPPS* pps = NULL;
    17461111  TComSPS* sps = NULL;
    1747 
    1748   if (!bEntropySlice)
    1749   {
    1750     READ_UVLC (    uiCode, "pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
    1751     pps = parameterSetManager->getPrefetchedPPS(uiCode);
    1752     sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
    1753     rpcSlice->setSPS(sps);
    1754     rpcSlice->setPPS(pps);
     1112#if H_MV
     1113  TComVPS* vps = NULL;
     1114#endif
     1115
     1116  UInt firstSliceSegmentInPic;
     1117  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
     1118  if( rpcSlice->getRapPicFlag())
     1119  {
     1120    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
     1121  }
     1122  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
     1123  pps = parameterSetManager->getPrefetchedPPS(uiCode);
     1124  //!KS: need to add error handling code here, if PPS is not available
     1125  assert(pps!=0);
     1126  sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId());
     1127  //!KS: need to add error handling code here, if SPS is not available
     1128  assert(sps!=0);
     1129#if H_MV
     1130  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
     1131  assert(vps!=0);
     1132  rpcSlice->setVPS(vps);     
     1133  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerIdInVps() )      );
     1134#if H_3D 
     1135  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerIdInVps() )      ); 
     1136  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerIdInVps() ) == 1 );
     1137#endif
     1138#endif
     1139  rpcSlice->setSPS(sps);
     1140  rpcSlice->setPPS(pps);
     1141  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
     1142  {
     1143    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
     1144  }
     1145  else
     1146  {
     1147    rpcSlice->setDependentSliceSegmentFlag(false);
     1148  }
     1149  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
     1150  Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
     1151  UInt sliceSegmentAddress = 0;
     1152  Int bitsSliceSegmentAddress = 0;
     1153  while(numCTUs>(1<<bitsSliceSegmentAddress))
     1154  {
     1155    bitsSliceSegmentAddress++;
     1156  }
     1157
     1158  if(!firstSliceSegmentInPic)
     1159  {
     1160    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
     1161  }
     1162  //set uiCode to equal slice start address (or dependent slice start address)
     1163  Int startCuAddress = maxParts*sliceSegmentAddress;
     1164  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
     1165  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
     1166
     1167  if (rpcSlice->getDependentSliceSegmentFlag())
     1168  {
     1169    rpcSlice->setNextSlice          ( false );
     1170    rpcSlice->setNextSliceSegment ( true  );
     1171  }
     1172  else
     1173  {
     1174    rpcSlice->setNextSlice          ( true  );
     1175    rpcSlice->setNextSliceSegment ( false );
     1176
     1177    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
     1178    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
     1179  }
     1180 
     1181  if(!rpcSlice->getDependentSliceSegmentFlag())
     1182  {
     1183#if H_MV   
     1184    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     1185    {
     1186      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
     1187    }
     1188
     1189    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)   
     1190#else
     1191    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     1192#endif     
     1193    {
     1194      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     1195    }
     1196
     1197    READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
    17551198    if( pps->getOutputFlagPresentFlag() )
    17561199    {
    1757       READ_FLAG( uiCode, "pic_output_flag" );
    1758       rpcSlice->setPicOutputFlag( uiCode ? true : false );
     1200      READ_FLAG( uiCode, "pic_output_flag" );    rpcSlice->setPicOutputFlag( uiCode ? true : false );
    17591201    }
    17601202    else
     
    17621204      rpcSlice->setPicOutputFlag( true );
    17631205    }
    1764 #if QC_REM_IDV_B0046
    1765 #if !QC_MVHEVC_B0046
    1766   if(rpcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR && rpcSlice->getSPS()->getViewId() == 0)
    1767 #else
    1768   if(rpcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR && rpcSlice->getViewId() == 0)
    1769 #endif
    1770 #else
    1771     if(rpcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR)
    1772 #endif
    1773     {
    1774       READ_UVLC( uiCode, "idr_pic_id" );  //ignored
    1775       READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
     1206    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
     1207    assert (sps->getChromaFormatIdc() == 1 );
     1208    // if( separate_colour_plane_flag  ==  1 )
     1209    //   colour_plane_id                                      u(2)
     1210
     1211    if( rpcSlice->getIdrPicFlag() )
     1212    {
    17761213      rpcSlice->setPOC(0);
    17771214      TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
     
    17811218      rps->setNumberOfPictures(0);
    17821219      rpcSlice->setRPS(rps);
     1220#if H_MV
     1221      rpcSlice->setEnableTMVPFlag(false);
     1222#endif
    17831223    }
    17841224    else
     
    18031243        iPOCmsb = iPrevPOCmsb;
    18041244      }
    1805       rpcSlice->setPOC( iPOCmsb+iPOClsb );
    1806 #if QC_REM_IDV_B0046
    1807 #if !QC_MVHEVC_B0046
    1808       if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR &&  rpcSlice->getSPS()->getViewId() && rpcSlice->getPOC() == 0 )
    1809 #else
    1810       if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR &&  rpcSlice->getViewId() && rpcSlice->getPOC() == 0 )
    1811 #endif
    1812 #else
    1813       if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDV && rpcSlice->getPOC() == 0 )
    1814 #endif
    1815       {
    1816         TComReferencePictureSet* rps = rpcSlice->getLocalRPS();
     1245      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1246        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     1247        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     1248      {
     1249        // For BLA picture types, POCmsb is set to 0.
     1250        iPOCmsb = 0;
     1251      }
     1252      rpcSlice->setPOC              (iPOCmsb+iPOClsb);
     1253
     1254      TComReferencePictureSet* rps;
     1255      rps = rpcSlice->getLocalRPS();
     1256      rpcSlice->setRPS(rps);
     1257      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
     1258      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
     1259      {
     1260        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
     1261      }
     1262      else // use reference to short-term reference picture set in PPS
     1263      {
     1264        Int numBits = 0;
     1265        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     1266        {
     1267          numBits++;
     1268        }
     1269        if (numBits > 0)
     1270        {
     1271          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
     1272        }
     1273        else
     1274        {
     1275          uiCode = 0;
     1276        }
     1277        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
     1278      }
     1279      if(sps->getLongTermRefsPresent())
     1280      {
     1281        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
     1282        UInt numOfLtrp = 0;
     1283        UInt numLtrpInSPS = 0;
     1284        if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0)
     1285        {
     1286          READ_UVLC( uiCode, "num_long_term_sps");
     1287          numLtrpInSPS = uiCode;
     1288          numOfLtrp += numLtrpInSPS;
     1289          rps->setNumberOfLongtermPictures(numOfLtrp);
     1290        }
     1291        Int bitsForLtrpInSPS = 0;
     1292        while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
     1293        {
     1294          bitsForLtrpInSPS++;
     1295        }
     1296        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
     1297        numOfLtrp += uiCode;
     1298        rps->setNumberOfLongtermPictures(numOfLtrp);
     1299        Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
     1300        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
     1301        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
     1302        {
     1303          Int pocLsbLt;
     1304          if (k < numLtrpInSPS)
     1305          {
     1306            uiCode = 0;
     1307            if (bitsForLtrpInSPS > 0)
     1308            {
     1309              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
     1310            }
     1311            Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
     1312
     1313            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
     1314            rps->setUsed(j,usedByCurrFromSPS);
     1315          }
     1316          else
     1317          {
     1318            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
     1319            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
     1320          }
     1321          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
     1322          Bool mSBPresentFlag = uiCode ? true : false;
     1323          if(mSBPresentFlag)                 
     1324          {
     1325            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
     1326            Bool deltaFlag = false;
     1327            //            First LTRP                               || First LTRP from SH
     1328            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
     1329            {
     1330              deltaFlag = true;
     1331            }
     1332            if(deltaFlag)
     1333            {
     1334              deltaPocMSBCycleLT = uiCode;
     1335            }
     1336            else
     1337            {
     1338              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;             
     1339            }
     1340
     1341            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
     1342                                        - iPOClsb + pocLsbLt;
     1343            rps->setPOC     (j, pocLTCurr);
     1344            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
     1345            rps->setCheckLTMSBPresent(j,true); 
     1346          }
     1347          else
     1348          {
     1349            rps->setPOC     (j, pocLsbLt);
     1350            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
     1351            rps->setCheckLTMSBPresent(j,false); 
     1352          }
     1353          prevDeltaMSB = deltaPocMSBCycleLT;
     1354        }
     1355        offset += rps->getNumberOfLongtermPictures();
     1356        rps->setNumberOfPictures(offset);       
     1357      } 
     1358      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     1359        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     1360        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     1361      {
     1362        // In the case of BLA picture types, rps data is read from slice header but ignored
     1363        rps = rpcSlice->getLocalRPS();
    18171364        rps->setNumberOfNegativePictures(0);
    18181365        rps->setNumberOfPositivePictures(0);
     
    18211368        rpcSlice->setRPS(rps);
    18221369      }
     1370      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
     1371      {
     1372        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
     1373        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
     1374      }
    18231375      else
    18241376      {
    1825         TComReferencePictureSet* rps;
    1826         READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
    1827         if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
    1828         {
    1829           rps = rpcSlice->getLocalRPS();
    1830           parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
    1831           rpcSlice->setRPS(rps);
    1832         }
    1833         else // use reference to short-term reference picture set in PPS
    1834         {
    1835           READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode));
    1836           rps = rpcSlice->getRPS();
    1837         }
    1838         if(sps->getLongTermRefsPresent())
    1839         {
    1840           Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
    1841           READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
    1842           Int prev = 0;
    1843           Int prevMsb=0;
    1844           Int prevDeltaPocLt=0;
    1845           for(Int j=rps->getNumberOfLongtermPictures()+offset-1 ; j > offset-1; j--)
    1846           {
    1847             READ_UVLC(uiCode,"delta_poc_lsb_lt");
    1848             prev += uiCode;
    1849 
    1850             READ_FLAG(uiCode,"delta_poc_msb_present_flag");
    1851             Int decDeltaPOCMsbPresent=uiCode;
    1852 
    1853             if(decDeltaPOCMsbPresent==1)
    1854             {
    1855               READ_UVLC(uiCode, "delta_poc_msb_cycle_lt_minus1");
    1856               if(  (j==(rps->getNumberOfLongtermPictures()+offset-1)) || (prev!=prevDeltaPocLt) )
    1857               {
    1858                 prevMsb=(1+uiCode);
    1859               }
    1860               else
    1861               {
    1862                 prevMsb+=(1+uiCode);
    1863               }
    1864               Int decMaxPocLsb = 1<<rpcSlice->getSPS()->getBitsForPOC();
    1865               rps->setPOC(j,rpcSlice->getPOC()-prev-(prevMsb)*decMaxPocLsb);
    1866               rps->setDeltaPOC(j,-(Int)(prev+(prevMsb)*decMaxPocLsb));
    1867             }
    1868             else
    1869             {
    1870               rps->setPOC(j,rpcSlice->getPOC()-prev);         
    1871               rps->setDeltaPOC(j,-(Int)prev);
    1872             }
    1873             prevDeltaPocLt=prev;
    1874             READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
    1875           }
    1876           offset += rps->getNumberOfLongtermPictures();
    1877           rps->setNumberOfPictures(offset);       
    1878         } 
    1879       }
    1880     }
    1881 
    1882     if(sps->getUseSAO() || sps->getUseALF() || sps->getScalingListFlag() || sps->getUseDF())
    1883     {
    1884       //!!!KS: order is different in WD5!
    1885       if (sps->getUseALF())
    1886       {
    1887         READ_FLAG(uiCode, "slice_adaptive_loop_filter_flag");
    1888         rpcSlice->setAlfEnabledFlag((Bool)uiCode);
    1889       }
    1890       if (sps->getUseSAO())
    1891       {
    1892 #if LGE_SAO_MIGRATION_D0091
    1893         READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
    1894         READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
    1895 #else
    1896         READ_FLAG(uiCode, "slice_sao_interleaving_flag");        rpcSlice->setSaoInterleavingFlag(uiCode);
    1897         READ_FLAG(uiCode, "slice_sample_adaptive_offset_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
    1898         if (rpcSlice->getSaoEnabledFlag() && rpcSlice->getSaoInterleavingFlag())
    1899         {
    1900           READ_FLAG(uiCode, "sao_cb_enable_flag");  rpcSlice->setSaoEnabledFlagCb((Bool)uiCode);
    1901           READ_FLAG(uiCode, "sao_cr_enable_flag");  rpcSlice->setSaoEnabledFlagCr((Bool)uiCode);
    1902         }
    1903         else
    1904         {
    1905           rpcSlice->setSaoEnabledFlagCb(0);
    1906           rpcSlice->setSaoEnabledFlagCr(0);
    1907         }
    1908 #endif
    1909       }
    1910       READ_UVLC (    uiCode, "aps_id" );  rpcSlice->setAPSId(uiCode);
     1377        rpcSlice->setEnableTMVPFlag(false);
     1378      }
     1379    }
     1380#if H_MV
     1381    Int layerIdInVps       = rpcSlice->getLayerIdInVps();
     1382    if( rpcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
     1383    {   
     1384      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
     1385      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
     1386      {           
     1387        if( !vps->getMaxOneActiveRefLayerFlag()) 
     1388        {
     1389          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
     1390        }
     1391        for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
     1392        {
     1393          READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( i, uiCode );
     1394        }
     1395      } 
     1396    }
     1397
     1398    rpcSlice->setActiveMotionPredRefLayers( );
     1399
     1400    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  rpcSlice->getNumActiveRefLayerPics() > 0 )
     1401    {
     1402      READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" ); rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode == 1 );
     1403    }
     1404
     1405#endif
     1406    if(sps->getUseSAO())
     1407    {
     1408      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
     1409      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
     1410    }
     1411
     1412    if (rpcSlice->getIdrPicFlag())
     1413    {
     1414      rpcSlice->setEnableTMVPFlag(false);
    19111415    }
    19121416    if (!rpcSlice->isIntra())
    19131417    {
     1418
    19141419      READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
    19151420      if (uiCode)
    19161421      {
    1917         READ_CODE (3, uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
     1422        READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 );
    19181423        if (rpcSlice->isInterB())
    19191424        {
    1920           READ_CODE (3, uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
     1425          READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" );  rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 );
    19211426        }
    19221427        else
     
    19271432      else
    19281433      {
    1929         rpcSlice->setNumRefIdx(REF_PIC_LIST_0, 0);
    1930         rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    1931       }
    1932     }
     1434        rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive());
     1435        if (rpcSlice->isInterB())
     1436        {
     1437          rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive());
     1438        }
     1439        else
     1440        {
     1441          rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0);
     1442        }
     1443      }
     1444    }
     1445    // }
    19331446    TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
    1934     if( !rpcSlice->isIntra() )
    1935     {
    1936 #if QC_MVHEVC_B0046
    1937     if( !rpcSlice->getViewId() || !rpcSlice->getSPS()->getListsModificationPresentFlag() )
    1938 #else
    1939       if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
    1940 #endif
     1447    if(!rpcSlice->isIntra())
     1448    {
     1449      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
    19411450      {
    19421451        refPicListModification->setRefPicListModificationFlagL0( 0 );
     
    19461455        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 );
    19471456      }
    1948      
     1457
    19491458      if(refPicListModification->getRefPicListModificationFlagL0())
    1950       {
     1459      { 
    19511460        uiCode = 0;
    19521461        Int i = 0;
    1953         Int NumPocTotalCurr = rpcSlice->getNumPocTotalCurrMvc();
    1954         if ( NumPocTotalCurr > 1 )
     1462        Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList();
     1463        if ( numRpsCurrTempList0 > 1 )
    19551464        {
    19561465          Int length = 1;
    1957           NumPocTotalCurr --;
    1958           while ( NumPocTotalCurr >>= 1)
     1466          numRpsCurrTempList0 --;
     1467          while ( numRpsCurrTempList0 >>= 1)
    19591468          {
    19601469            length ++;
     
    19811490    if(rpcSlice->isInterB())
    19821491    {
    1983 #if QC_MVHEVC_B0046
    1984     if( !rpcSlice->getViewId() || !rpcSlice->getSPS()->getListsModificationPresentFlag() )
    1985 #else
    1986       if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
    1987 #endif
     1492      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
    19881493      {
    19891494        refPicListModification->setRefPicListModificationFlagL1( 0 );
     
    19971502        uiCode = 0;
    19981503        Int i = 0;
    1999         Int NumPocTotalCurr = rpcSlice->getNumPocTotalCurrMvc();
    2000         if ( NumPocTotalCurr > 1 )
     1504        Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList();
     1505        if ( numRpsCurrTempList1 > 1 )
    20011506        {
    20021507          Int length = 1;
    2003           NumPocTotalCurr --;
    2004           while ( NumPocTotalCurr >>= 1)
     1508          numRpsCurrTempList1 --;
     1509          while ( numRpsCurrTempList1 >>= 1)
    20051510          {
    20061511            length ++;
     
    20251530      refPicListModification->setRefPicListModificationFlagL1(0);
    20261531    }
    2027   }
    2028   else
    2029   {
    2030     // initialize from previous slice
    2031     pps = rpcSlice->getPPS();
    2032     sps = rpcSlice->getSPS();
    2033   }
    2034   // ref_pic_list_combination( )
    2035   //!!!KS: ref_pic_list_combination() should be conditioned on entropy_slice_flag
    2036   if (rpcSlice->isInterB())
    2037   {
    2038     READ_FLAG( uiCode, "ref_pic_list_combination_flag" );       rpcSlice->setRefPicListCombinationFlag( uiCode ? 1 : 0 );
    2039     if(uiCode)
    2040     {
    2041       READ_UVLC( uiCode, "num_ref_idx_lc_active_minus1" );      rpcSlice->setNumRefIdx( REF_PIC_LIST_C, uiCode + 1 );
    2042      
    2043 #if QC_MVHEVC_B0046
    2044     if( rpcSlice->getViewId() && rpcSlice->getSPS()->getListsModificationPresentFlag() )
     1532    if (rpcSlice->isInterB())
     1533    {
     1534      READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
     1535    }
     1536
     1537    rpcSlice->setCabacInitFlag( false ); // default
     1538    if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
     1539    {
     1540      READ_FLAG(uiCode, "cabac_init_flag");
     1541      rpcSlice->setCabacInitFlag( uiCode ? true : false );
     1542    }
     1543
     1544    if ( rpcSlice->getEnableTMVPFlag() )
     1545    {
     1546#if H_MV
     1547      if( rpcSlice->getLayerId() > 0 && rpcSlice->getNumActiveMotionPredRefLayers() > 0 )
     1548      {
     1549        READ_FLAG( uiCode, "alt_collocated_indication_flag" ); rpcSlice->setAltCollocatedIndicationFlag( uiCode == 1 );
     1550      }
     1551
     1552      if( rpcSlice->getAltCollocatedIndicationFlag() && rpcSlice->getNumActiveMotionPredRefLayers() > 1 )
     1553      {         
     1554        READ_UVLC( uiCode, "collocated_ref_layer_idx" ); rpcSlice->setCollocatedRefLayerIdx( uiCode );
     1555      }     
     1556      else
     1557      {
     1558#endif
     1559      if ( rpcSlice->getSliceType() == B_SLICE )
     1560      {
     1561        READ_FLAG( uiCode, "collocated_from_l0_flag" );
     1562        rpcSlice->setColFromL0Flag(uiCode);
     1563      }
     1564      else
     1565      {
     1566        rpcSlice->setColFromL0Flag( 1 );
     1567      }
     1568
     1569      if ( rpcSlice->getSliceType() != I_SLICE &&
     1570          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
     1571           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
     1572      {
     1573        READ_UVLC( uiCode, "collocated_ref_idx" );
     1574        rpcSlice->setColRefIdx(uiCode);
     1575      }
     1576      else
     1577      {
     1578        rpcSlice->setColRefIdx(0);
     1579      }
     1580#if H_MV
     1581      }
     1582#endif
     1583    }
     1584    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
     1585    {
     1586      xParsePredWeightTable(rpcSlice);
     1587      rpcSlice->initWpScaling();
     1588    }
     1589#if H_3D_IC
     1590    else if( rpcSlice->getViewIndex() && ( rpcSlice->getSliceType() == P_SLICE || rpcSlice->getSliceType() == B_SLICE ) )
     1591    {
     1592      UInt uiCodeTmp = 0;
     1593
     1594      READ_FLAG ( uiCodeTmp, "slice_ic_enable_flag" );
     1595      rpcSlice->setApplyIC( uiCodeTmp );
     1596
     1597      if ( uiCodeTmp )
     1598      {
     1599        READ_FLAG ( uiCodeTmp, "ic_skip_mergeidx0" );
     1600        rpcSlice->setIcSkipParseFlag( uiCodeTmp );
     1601      }
     1602    }
     1603#endif
     1604    if (!rpcSlice->isIntra())
     1605    {
     1606      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
     1607#if H_3D_IV_MERGE
     1608      Bool ivMvPredFlag = rpcSlice->getVPS()->getIvMvPredFlag( rpcSlice->getLayerIdInVps() ) ;
     1609      rpcSlice->setMaxNumMergeCand(( ivMvPredFlag ? MRG_MAX_NUM_CANDS_MEM : MRG_MAX_NUM_CANDS) - uiCode);
    20451610#else
    2046     if(rpcSlice->getSPS()->getListsModificationPresentFlag() )
    2047 #endif
    2048       {
    2049         READ_FLAG( uiCode, "ref_pic_list_modification_flag_lc" ); rpcSlice->setRefPicListModificationFlagLC( uiCode ? 1 : 0 );
    2050         if(uiCode)
    2051         {
    2052           for (UInt i=0;i<rpcSlice->getNumRefIdx(REF_PIC_LIST_C);i++)
    2053           {
    2054             READ_FLAG( uiCode, "pic_from_list_0_flag" );
    2055             rpcSlice->setListIdFromIdxOfLC(i, uiCode);
    2056           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)) )
    2057           {
    2058             uiCode = 0;
    2059           }
    2060           else
    2061           {
    2062             READ_UVLC( uiCode, "ref_idx_list_curr" );
    2063           }
    2064             rpcSlice->setRefIdxFromIdxOfLC(i, uiCode);
    2065             rpcSlice->setRefIdxOfLC((RefPicList)rpcSlice->getListIdFromIdxOfLC(i), rpcSlice->getRefIdxFromIdxOfLC(i), i);
    2066           }
    2067         }
    2068       }
    2069       else
    2070       {
    2071         rpcSlice->setRefPicListModificationFlagLC(false);
    2072       }
    2073     }
    2074     else
    2075     {
    2076       rpcSlice->setRefPicListModificationFlagLC(false);
    2077       rpcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
    2078     }
    2079   }
    2080   else
    2081   {
    2082     rpcSlice->setRefPicListCombinationFlag(false);     
    2083   }
    2084  
    2085   if (rpcSlice->isInterB())
    2086   {
    2087     READ_FLAG( uiCode, "mvd_l1_zero_flag" );       rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) );
    2088   }
    2089 
    2090 #if CABAC_INIT_FLAG
    2091   rpcSlice->setCabacInitFlag( false ); // default
    2092   if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra())
    2093   {
    2094     READ_FLAG(uiCode, "cabac_init_flag");
    2095     rpcSlice->setCabacInitFlag( uiCode ? true : false );
    2096   }
    2097 #else
    2098   if(pps->getEntropyCodingMode() && !rpcSlice->isIntra())
    2099   {
    2100     READ_UVLC(uiCode, "cabac_init_idc");
    2101     rpcSlice->setCABACinitIDC(uiCode);
    2102   }
    2103   else if (pps->getEntropyCodingMode() && rpcSlice->isIntra())
    2104   {
    2105     rpcSlice->setCABACinitIDC(0);
    2106   }
    2107 #endif
    2108 
    2109   if(!bEntropySlice)
    2110   {
    2111     READ_SVLC( iCode, "slice_qp_delta" );
     1611      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
     1612#endif
     1613    }
     1614
     1615    READ_SVLC( iCode, "slice_qp_delta" );
    21121616    rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
    21131617
     
    21151619    assert( rpcSlice->getSliceQp() <=  51 );
    21161620
    2117     if (rpcSlice->getPPS()->getDeblockingFilterControlPresent())
    2118     {
    2119       if ( rpcSlice->getSPS()->getUseDF() )
    2120       {
    2121         READ_FLAG ( uiCode, "inherit_dbl_param_from_APS_flag" ); rpcSlice->setInheritDblParamFromAPS(uiCode ? 1 : 0);
    2122       } else
    2123       {
    2124         rpcSlice->setInheritDblParamFromAPS(0);
    2125       }
    2126       if(!rpcSlice->getInheritDblParamFromAPS())
    2127       {
    2128         READ_FLAG ( uiCode, "disable_deblocking_filter_flag" );  rpcSlice->setLoopFilterDisable(uiCode ? 1 : 0);
    2129         if(!rpcSlice->getLoopFilterDisable())
    2130         {
    2131           READ_SVLC( iCode, "beta_offset_div2" ); rpcSlice->setLoopFilterBetaOffset(iCode);
    2132           READ_SVLC( iCode, "tc_offset_div2" ); rpcSlice->setLoopFilterTcOffset(iCode);
    2133         }
    2134       }
    2135    }
    2136     if ( rpcSlice->getSliceType() == B_SLICE )
    2137     {
    2138       READ_FLAG( uiCode, "collocated_from_l0_flag" );
    2139       rpcSlice->setColDir(uiCode);
    2140     }
    2141 
    2142 #if COLLOCATED_REF_IDX
    2143     if ( rpcSlice->getSliceType() != I_SLICE &&
    2144       ((rpcSlice->getColDir()==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
    2145       (rpcSlice->getColDir() ==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
    2146     {
    2147       READ_UVLC( uiCode, "collocated_ref_idx" );
    2148       rpcSlice->setColRefIdx(uiCode);
    2149     }
    2150 #endif
    2151    
    2152     if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPredIdc() && rpcSlice->getSliceType()==B_SLICE) )
    2153     {
    2154       xParsePredWeightTable(rpcSlice);
    2155       rpcSlice->initWpScaling();
    2156     }
    2157   }
    2158  
    2159   if (!bEntropySlice)
    2160   {
    2161     if( rpcSlice->getSPS()->hasCamParInSliceHeader() )
    2162     {
    2163       UInt uiViewId = rpcSlice->getSPS()->getViewId();
    2164       for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
    2165       {
    2166         READ_SVLC( iCode, "coded_scale" );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
    2167         READ_SVLC( iCode, "coded_offset" );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
    2168         READ_SVLC( iCode, "inverse_coded_scale_plus_coded_scale" );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
    2169         READ_SVLC( iCode, "inverse_coded_offset_plus_coded_offset" );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
    2170       }
    2171       rpcSlice->initMultiviewSlice( m_aaiTempScale, m_aaiTempOffset );
    2172     }
    2173   }
    2174 
    2175 #if ( HHI_MPI || H3D_IVMP )
    2176   #if ( HHI_MPI && H3D_IVMP )
    2177   const int iExtraMergeCandidates = ( sps->getUseMVI() || sps->getMultiviewMvPredMode() ) ? 1 : 0;
    2178   #elif HHI_MPI
    2179   const int iExtraMergeCandidates = sps->getUseMVI() ? 1 : 0;
    2180   #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
    2181   const int iExtraMergeCandidates = (  (isDepth || sps->getMultiviewMvPredMode()) ) ? 1 : 0;   
    2182   #else
    2183   const int iExtraMergeCandidates = sps->getMultiviewMvPredMode() ? 1 : 0;
    2184   #endif
    2185   READ_UVLC( uiCode, "5_minus_max_num_merge_cand");
    2186   rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS + iExtraMergeCandidates - uiCode);
    2187   assert(rpcSlice->getMaxNumMergeCand()==(MRG_MAX_NUM_CANDS_SIGNALED+iExtraMergeCandidates));
    2188 #else
    2189   READ_UVLC( uiCode, "5_minus_max_num_merge_cand");
    2190   rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
    2191   assert(rpcSlice->getMaxNumMergeCand()==MRG_MAX_NUM_CANDS_SIGNALED);
    2192 #endif
    2193 
    2194   if (!bEntropySlice)
    2195   {
    2196     if(sps->getUseALF() && rpcSlice->getAlfEnabledFlag())
    2197     {
    2198       UInt uiNumLCUsInWidth   = sps->getPicWidthInLumaSamples()  / g_uiMaxCUWidth;
    2199       UInt uiNumLCUsInHeight  = sps->getPicHeightInLumaSamples() / g_uiMaxCUHeight;
    2200 
    2201       uiNumLCUsInWidth  += ( sps->getPicWidthInLumaSamples() % g_uiMaxCUWidth ) ? 1 : 0;
    2202       uiNumLCUsInHeight += ( sps->getPicHeightInLumaSamples() % g_uiMaxCUHeight ) ? 1 : 0;
    2203 
    2204       Int uiNumCUsInFrame = uiNumLCUsInWidth* uiNumLCUsInHeight;
    2205       if(sps->getUseALFCoefInSlice())
    2206       {
    2207         alfParamSet.releaseALFParam();
    2208         alfParamSet.init();
    2209         Bool isAcrossSlice = sps->getLFCrossSliceBoundaryFlag();   
    2210         Int numSUinLCU    = 1<< (g_uiMaxCUDepth << 1);
    2211         Int firstLCUAddr   = rpcSlice->getSliceCurStartCUAddr() / numSUinLCU; 
    2212         xParseAlfParam(&alfParamSet, false, firstLCUAddr, isAcrossSlice, uiNumLCUsInWidth, uiNumLCUsInHeight);
    2213       }
    2214 
    2215       if(!sps->getUseALFCoefInSlice())
    2216       {
    2217       xParseAlfCuControlParam(alfCUCtrl, uiNumCUsInFrame);
    2218       }
    2219 
    2220     }
     1621    if (rpcSlice->getPPS()->getSliceChromaQpFlag())
     1622    {
     1623      READ_SVLC( iCode, "slice_qp_delta_cb" );
     1624      rpcSlice->setSliceQpDeltaCb( iCode );
     1625      assert( rpcSlice->getSliceQpDeltaCb() >= -12 );
     1626      assert( rpcSlice->getSliceQpDeltaCb() <=  12 );
     1627      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 );
     1628      assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <=  12 );
     1629
     1630      READ_SVLC( iCode, "slice_qp_delta_cr" );
     1631      rpcSlice->setSliceQpDeltaCr( iCode );
     1632      assert( rpcSlice->getSliceQpDeltaCr() >= -12 );
     1633      assert( rpcSlice->getSliceQpDeltaCr() <=  12 );
     1634      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 );
     1635      assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
     1636    }
     1637
     1638    if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
     1639    {
     1640      if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag())
     1641      {
     1642        READ_FLAG ( uiCode, "deblocking_filter_override_flag" );        rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false);
     1643      }
     1644      else
     1645      { 
     1646        rpcSlice->setDeblockingFilterOverrideFlag(0);
     1647      }
     1648      if(rpcSlice->getDeblockingFilterOverrideFlag())
     1649      {
     1650        READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" );   rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0);
     1651        if(!rpcSlice->getDeblockingFilterDisable())
     1652        {
     1653          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
     1654          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
     1655                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
     1656          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
     1657          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
     1658                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
     1659        }
     1660      }
     1661      else
     1662      {
     1663        rpcSlice->setDeblockingFilterDisable   ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() );
     1664        rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
     1665        rpcSlice->setDeblockingFilterTcOffsetDiv2  ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() );
     1666      }
     1667    }
     1668    else
     1669    { 
     1670      rpcSlice->setDeblockingFilterDisable       ( false );
     1671      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
     1672      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
     1673    }
     1674
     1675    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
     1676    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
     1677
     1678    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
     1679    {
     1680      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
     1681    }
     1682    else
     1683    {
     1684      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
     1685    }
     1686    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
     1687
    22211688  }
    22221689 
    2223   //!!!KS: The following syntax is not aligned with the working draft, TRACE support needs to be added
    2224   rpcSlice->setTileMarkerFlag ( 0 ); // default
    2225   if (!bEntropySlice)
    2226   {
    2227     xReadCode(1, uiCode); // read flag indicating if tile markers transmitted
    2228     rpcSlice->setTileMarkerFlag( uiCode );
    2229   }
    2230 
    2231   Int tilesOrEntropyCodingSyncIdc = rpcSlice->getSPS()->getTilesOrEntropyCodingSyncIdc();
    2232   UInt *entryPointOffset          = NULL;
    2233   UInt numEntryPointOffsets, offsetLenMinus1;
    2234 
    2235   rpcSlice->setNumEntryPointOffsets ( 0 ); // default
    2236  
    2237   if (tilesOrEntropyCodingSyncIdc>0)
     1690    UInt *entryPointOffset          = NULL;
     1691    UInt numEntryPointOffsets, offsetLenMinus1;
     1692  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
    22381693  {
    22391694    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
     
    22451700    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    22461701    {
    2247       Int bitsRead = m_pcBitstream->getNumBitsRead();
    2248       READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
    2249       entryPointOffset[ idx ] = uiCode;
    2250       if ( idx == 0 && tilesOrEntropyCodingSyncIdc == 2 )
    2251       {
    2252         // Subtract distance from NALU header start to provide WPP 0-th substream the correct size.
    2253         entryPointOffset[ idx ] -= ( bitsRead + numEntryPointOffsets*(offsetLenMinus1+1) ) >> 3;
    2254       }
    2255     }
    2256   }
    2257 
    2258   if ( tilesOrEntropyCodingSyncIdc == 1 ) // tiles
    2259   {
    2260     rpcSlice->setTileLocationCount( numEntryPointOffsets );
    2261 
    2262     UInt prevPos = 0;
    2263     for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
    2264     {
    2265       rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
    2266       prevPos += entryPointOffset[ idx ];
    2267     }
    2268   }
    2269   else if ( tilesOrEntropyCodingSyncIdc == 2 ) // wavefront
    2270   {
    2271     Int numSubstreams = pps->getNumSubstreams();
    2272     rpcSlice->allocSubstreamSizes(numSubstreams);
    2273     UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
    2274     for (Int idx=0; idx<numSubstreams-1; idx++)
    2275     {
    2276       if ( idx < numEntryPointOffsets )
    2277       {
    2278         pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
    2279       }
    2280       else
    2281       {
    2282         pSubstreamSizes[ idx ] = 0;
    2283       }
    2284     }
    2285   }
    2286 
    2287   if (entryPointOffset)
    2288   {
    2289     delete [] entryPointOffset;
    2290   }
    2291 
    2292   if (!bEntropySlice)
    2293   {
    2294     // Reading location information
    2295 
    2296       // read out trailing bits
    2297     m_pcBitstream->readOutTrailingBits();
    2298   }
     1702      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
     1703      entryPointOffset[ idx ] = uiCode + 1;
     1704    }
     1705  }
     1706  else
     1707  {
     1708    rpcSlice->setNumEntryPointOffsets ( 0 );
     1709  }
     1710
     1711  if(pps->getSliceHeaderExtensionPresentFlag())
     1712  {
     1713    READ_UVLC(uiCode,"slice_header_extension_length");
     1714#if H_3D
     1715    if( rpcSlice->getSPS()->hasCamParInSliceHeader() )
     1716    {
     1717      UInt uiViewIndex = rpcSlice->getViewIndex();
     1718      for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
     1719      {
     1720        READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ] = iCode;
     1721        READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ] = iCode;
     1722        READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale [ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ uiViewIndex ];
     1723        READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset[ uiViewIndex ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ uiViewIndex ];
     1724      }
     1725      rpcSlice->setCamparaSlice( m_aaiTempScale, m_aaiTempOffset );
     1726    }
     1727
     1728    READ_FLAG(uiCode,"slice_segment_header_extension2_flag");
     1729    if ( uiCode )
     1730    {   
     1731      READ_UVLC(uiCode,"slice_header_extension2_length");
     1732      for(Int i=0; i<uiCode; i++)
     1733      {
     1734        UInt ignore;
     1735        READ_CODE(8,ignore,"slice_header_extension2_data_byte");
     1736      }
     1737    }
     1738  }
     1739#else
     1740    for(Int i=0; i<uiCode; i++)
     1741    {
     1742      UInt ignore;
     1743      READ_CODE(8,ignore,"slice_header_extension_data_byte");
     1744    }
     1745  }
     1746#endif
     1747  m_pcBitstream->readByteAlignment();
     1748
     1749  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
     1750  {
     1751    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
     1752   
     1753    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
     1754    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     1755    {
     1756      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
     1757      {
     1758        endOfSliceHeaderLocation++;
     1759      }
     1760    }
     1761
     1762    Int  curEntryPointOffset     = 0;
     1763    Int  prevEntryPointOffset    = 0;
     1764    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     1765    {
     1766      curEntryPointOffset += entryPointOffset[ idx ];
     1767
     1768      Int emulationPreventionByteCount = 0;
     1769      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
     1770      {
     1771        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
     1772             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
     1773        {
     1774          emulationPreventionByteCount++;
     1775        }
     1776      }
     1777
     1778      entryPointOffset[ idx ] -= emulationPreventionByteCount;
     1779      prevEntryPointOffset = curEntryPointOffset;
     1780    }
     1781
     1782    if ( pps->getTilesEnabledFlag() )
     1783    {
     1784      rpcSlice->setTileLocationCount( numEntryPointOffsets );
     1785
     1786      UInt prevPos = 0;
     1787      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
     1788      {
     1789        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
     1790        prevPos += entryPointOffset[ idx ];
     1791      }
     1792    }
     1793    else if ( pps->getEntropyCodingSyncEnabledFlag() )
     1794    {
     1795    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
     1796      rpcSlice->allocSubstreamSizes(numSubstreams);
     1797      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
     1798      for (Int idx=0; idx<numSubstreams-1; idx++)
     1799      {
     1800        if ( idx < numEntryPointOffsets )
     1801        {
     1802          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
     1803        }
     1804        else
     1805        {
     1806          pSubstreamSizes[ idx ] = 0;
     1807        }
     1808      }
     1809    }
     1810
     1811    if (entryPointOffset)
     1812    {
     1813      delete [] entryPointOffset;
     1814    }
     1815  }
     1816
    22991817  return;
    23001818}
    2301 
    2302 Void TDecCavlc::xParseAlfCuControlParam(AlfCUCtrlInfo& cAlfParam, Int iNumCUsInPic)
    2303 {
    2304   UInt uiSymbol;
    2305   Int iSymbol;
    2306 
    2307   READ_FLAG (uiSymbol, "alf_cu_control_flag");
    2308   cAlfParam.cu_control_flag = uiSymbol;
    2309   if (cAlfParam.cu_control_flag)
    2310   {
    2311     READ_UVLC (uiSymbol, "alf_cu_control_max_depth");
    2312     cAlfParam.alf_max_depth = uiSymbol;
    2313 
    2314     READ_SVLC (iSymbol, "alf_length_cu_control_info");
    2315     cAlfParam.num_alf_cu_flag = (UInt)(iSymbol + iNumCUsInPic);
    2316 
    2317     cAlfParam.alf_cu_flag.resize(cAlfParam.num_alf_cu_flag);
    2318 
    2319     for(UInt i=0; i< cAlfParam.num_alf_cu_flag; i++)
    2320     {
    2321       READ_FLAG (cAlfParam.alf_cu_flag[i], "alf_cu_flag");
    2322     }
    2323   }
    2324 }
    2325 
    2326 #if !CABAC_INIT_FLAG
    2327 Void TDecCavlc::resetEntropy          (TComSlice* pcSlice)
    2328 {
    2329 }
    2330 #endif
     1819 
     1820Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
     1821{
     1822  UInt uiCode;
     1823  if(profilePresentFlag)
     1824  {
     1825    parseProfileTier(rpcPTL->getGeneralPTL());
     1826  }
     1827  READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
     1828
     1829  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
     1830  {
     1831#if !H_MV
     1832    if(profilePresentFlag)
     1833    {
     1834#endif
     1835      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
     1836#if H_MV
     1837    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
     1838#else
     1839    }
     1840#endif
     1841    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
     1842  }
     1843 
     1844  if (maxNumSubLayersMinus1 > 0)
     1845  {
     1846    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
     1847    {
     1848      READ_CODE(2, uiCode, "reserved_zero_2bits");
     1849      assert(uiCode == 0);
     1850    }
     1851  }
     1852 
     1853  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
     1854  {
     1855    if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
     1856    {
     1857      parseProfileTier(rpcPTL->getSubLayerPTL(i));
     1858    }
     1859    if(rpcPTL->getSubLayerLevelPresentFlag(i))
     1860    {
     1861      READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" );   rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode);
     1862    }
     1863  }
     1864}
     1865
     1866Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
     1867{
     1868  UInt uiCode;
     1869  READ_CODE(2 , uiCode, "XXX_profile_space[]");   ptl->setProfileSpace(uiCode);
     1870  READ_FLAG(    uiCode, "XXX_tier_flag[]"    );   ptl->setTierFlag    (uiCode ? 1 : 0);
     1871  READ_CODE(5 , uiCode, "XXX_profile_idc[]"  );   ptl->setProfileIdc  (uiCode);
     1872  for(Int j = 0; j < 32; j++)
     1873  {
     1874    READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
     1875  }
     1876  READ_FLAG(uiCode, "general_progressive_source_flag");
     1877  ptl->setProgressiveSourceFlag(uiCode ? true : false);
     1878
     1879  READ_FLAG(uiCode, "general_interlaced_source_flag");
     1880  ptl->setInterlacedSourceFlag(uiCode ? true : false);
     1881 
     1882  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
     1883  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
     1884 
     1885  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
     1886  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
     1887 
     1888  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
     1889  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
     1890  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
     1891}
    23311892
    23321893Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
     
    23441905}
    23451906
    2346 Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1907Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23471908{
    23481909  assert(0);
    23491910}
    23501911
    2351 #if LGE_ILLUCOMP_B0045
    2352 Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1912Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23531913{
    23541914  assert(0);
    23551915}
    2356 #endif
    2357 
    2358 #if H3D_IVMP
    2359 Void TDecCavlc::parseMVPIdx( Int& riMVPIdx, Int iAMVPCands )
    2360 #else
    2361 Void TDecCavlc::parseMVPIdx( Int& riMVPIdx )
    2362 #endif
     1916
     1917Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
    23631918{
    23641919  assert(0);
    23651920}
    23661921
    2367 Void TDecCavlc::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1922Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23681923{
    23691924  assert(0);
    23701925}
    23711926
    2372 Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1927Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23731928{
    23741929  assert(0);
    23751930}
    23761931
    2377 Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1932Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23781933{
    23791934  assert(0);
     
    23811936
    23821937/** Parse I_PCM information.
    2383  * \param pcCU pointer to CU
    2384  * \param uiAbsPartIdx CU index
    2385  * \param uiDepth CU depth
    2386  * \returns Void
    2387  *
    2388  * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
    2389  */
    2390 Void TDecCavlc::parseIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1938* \param pcCU pointer to CU
     1939* \param uiAbsPartIdx CU index
     1940* \param uiDepth CU depth
     1941* \returns Void
     1942*
     1943* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. 
     1944*/
     1945Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23911946{
    23921947  assert(0);
    23931948}
    23941949
    2395 Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1950Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    23961951{
    23971952  assert(0);
    23981953}
    23991954
    2400 Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     1955Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
    24011956{
    24021957  assert(0);
    24031958}
    24041959
    2405 Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
     1960Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
    24061961{
    24071962  assert(0);
    24081963}
    24091964
    2410 Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
     1965Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
    24111966{
    24121967  assert(0);
    24131968}
    24141969
    2415 Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
     1970Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
    24161971{
    24171972  assert(0);
     
    24221977  Int qp;
    24231978  Int  iDQp;
    2424  
     1979
    24251980  xReadSvlc( iDQp );
    24261981
     
    24281983  qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
    24291984
    2430   UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)))<<(8-(pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()<<1)) ;
     1985  UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ;
    24311986  UInt uiQpCUDepth =   min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ;
    24321987
     
    24341989}
    24351990
    2436 Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
     1991Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
    24371992{
    24381993  assert(0);
    24391994}
    24401995
    2441 Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
     1996Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
    24421997{
    24431998  assert(0);
    24441999}
    24452000
    2446 Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
     2001Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
    24472002{
    24482003  assert(0);
    24492004}
    24502005
    2451 Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
     2006Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
    24522007{
    24532008  assert(0);
    24542009}
    24552010
    2456 
    2457 Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
     2011Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
    24582012{
    24592013  assert(0);
    24602014}
    24612015
    2462 Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
     2016Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
    24632017{
    24642018  assert(0);
    24652019}
    24662020
    2467 #if H3D_IVRP
    2468 Void
    2469 TDecCavlc::parseResPredFlag( TComDataCU* pcCU, Bool& rbResPredFlag, UInt uiAbsPartIdx, UInt uiDepth )
     2021Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
    24702022{
    24712023  assert(0);
    24722024}
    2473 #endif
    2474 #if QC_ARP_D0177
     2025
     2026#if H_3D_ARP
    24752027Void TDecCavlc::parseARPW( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    24762028{
    2477   assert( false );
    2478 }
    2479 #endif
    2480 #if RWTH_SDC_DLT_B0036
    2481 #if !PKU_QC_DEPTH_INTRA_UNI_D0195
    2482 Void TDecCavlc::parseSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    2483 {
    24842029  assert(0);
    24852030}
    2486 Void TDecCavlc::parseSDCPredMode    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
     2031#endif
     2032#if H_3D_IC
     2033Void TDecCavlc::parseICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    24872034{
    24882035  assert(0);
    24892036}
    24902037#endif
    2491 Void TDecCavlc::parseSDCResidualData     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
     2038#if LGE_INTER_SDC_E0156
     2039Void TDecCavlc::parseInterSDCFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    24922040{
    24932041  assert(0);
    24942042}
    2495 #endif
    2496 
     2043
     2044Void TDecCavlc::parseInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPart )
     2045{
     2046  assert(0);
     2047}
     2048#endif
    24972049// ====================================================================================================================
    24982050// Protected member functions
    24992051// ====================================================================================================================
    25002052
    2501 Void TDecCavlc::xReadCode (UInt uiLength, UInt& ruiCode)
    2502 {
    2503   assert ( uiLength > 0 );
    2504   m_pcBitstream->read (uiLength, ruiCode);
    2505 }
    2506 
    2507 Void TDecCavlc::xReadUvlc( UInt& ruiVal)
    2508 {
    2509   UInt uiVal = 0;
    2510   UInt uiCode = 0;
    2511   UInt uiLength;
    2512   m_pcBitstream->read( 1, uiCode );
    2513  
    2514   if( 0 == uiCode )
    2515   {
    2516     uiLength = 0;
    2517    
    2518     while( ! ( uiCode & 1 ))
    2519     {
    2520       m_pcBitstream->read( 1, uiCode );
    2521       uiLength++;
    2522     }
    2523    
    2524     m_pcBitstream->read( uiLength, uiVal );
    2525    
    2526     uiVal += (1 << uiLength)-1;
    2527   }
    2528  
    2529   ruiVal = uiVal;
    2530 }
    2531 
    2532 Void TDecCavlc::xReadSvlc( Int& riVal)
    2533 {
    2534   UInt uiBits = 0;
    2535   m_pcBitstream->read( 1, uiBits );
    2536   if( 0 == uiBits )
    2537   {
    2538     UInt uiLength = 0;
    2539    
    2540     while( ! ( uiBits & 1 ))
    2541     {
    2542       m_pcBitstream->read( 1, uiBits );
    2543       uiLength++;
    2544     }
    2545    
    2546     m_pcBitstream->read( uiLength, uiBits );
    2547    
    2548     uiBits += (1 << uiLength);
    2549     riVal = ( uiBits & 1) ? -(Int)(uiBits>>1) : (Int)(uiBits>>1);
    2550   }
    2551   else
    2552   {
    2553     riVal = 0;
    2554   }
    2555 }
    2556 
    2557 Void TDecCavlc::xReadFlag (UInt& ruiCode)
    2558 {
    2559   m_pcBitstream->read( 1, ruiCode );
    2560 }
    2561 
    2562 #if QC_MVHEVC_B0046
    2563 /** Parse VPS alignment one bits.
    2564  * \returns Void
    2565  */
    2566 Void TDecCavlc::xReadVPSAlignOne( )
    2567 {
    2568   UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned();
    2569 
    2570   if(uiNumberOfBits)
    2571   {
    2572     UInt uiBits;
    2573     UInt uiSymbol;
    2574 
    2575     for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++)
    2576     {
    2577       xReadFlag( uiSymbol );
    2578 
    2579       if(!uiSymbol)
    2580       {
    2581         printf("\nWarning! vps_extension_byte_alignment_reserved_one_bit include a non-zero value.\n");
    2582       }
    2583     }
    2584   }
    2585 }
    2586 #endif
    2587 /** Parse PCM alignment zero bits.
    2588  * \returns Void
    2589  */
    2590 Void TDecCavlc::xReadPCMAlignZero( )
    2591 {
    2592   UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned();
    2593 
    2594   if(uiNumberOfBits)
    2595   {
    2596     UInt uiBits;
    2597     UInt uiSymbol;
    2598 
    2599     for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++)
    2600     {
    2601       xReadFlag( uiSymbol );
    2602 
    2603       if(uiSymbol)
    2604       {
    2605         printf("\nWarning! pcm_align_zero include a non-zero value.\n");
    2606       }
    2607     }
    2608   }
    2609 }
    2610 
    2611 Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol )
    2612 {
    2613   if (uiMaxSymbol == 0)
    2614   {
    2615     ruiSymbol = 0;
    2616     return;
    2617   }
    2618  
    2619   xReadFlag( ruiSymbol );
    2620  
    2621   if (ruiSymbol == 0 || uiMaxSymbol == 1)
    2622   {
    2623     return;
    2624   }
    2625  
    2626   UInt uiSymbol = 0;
    2627   UInt uiCont;
    2628  
    2629   do
    2630   {
    2631     xReadFlag( uiCont );
    2632     uiSymbol++;
    2633   }
    2634   while( uiCont && (uiSymbol < uiMaxSymbol-1) );
    2635  
    2636   if( uiCont && (uiSymbol == uiMaxSymbol-1) )
    2637   {
    2638     uiSymbol++;
    2639   }
    2640  
    2641   ruiSymbol = uiSymbol;
    2642 }
    2643 
    2644 Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol )
    2645 {
    2646   UInt uiSymbol ;
    2647   UInt uiCount = 0;
    2648   do
    2649   {
    2650     xReadFlag( uiSymbol );
    2651     uiCount++;
    2652   }
    2653   while( uiSymbol && (uiCount != 13));
    2654  
    2655   ruiSymbol = uiCount-1;
    2656  
    2657   if( uiSymbol )
    2658   {
    2659     xReadEpExGolomb( uiSymbol, 0 );
    2660     ruiSymbol += uiSymbol+1;
    2661   }
    2662  
    2663   return;
    2664 }
    2665 
    2666 Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
    2667 {
    2668   UInt uiSymbol = 0;
    2669   UInt uiBit = 1;
    2670  
    2671  
    2672   while( uiBit )
    2673   {
    2674     xReadFlag( uiBit );
    2675     uiSymbol += uiBit << uiCount++;
    2676   }
    2677  
    2678   uiCount--;
    2679   while( uiCount-- )
    2680   {
    2681     xReadFlag( uiBit );
    2682     uiSymbol += uiBit << uiCount;
    2683   }
    2684  
    2685   ruiSymbol = uiSymbol;
    2686  
    2687   return;
    2688 }
    2689 
    2690 UInt TDecCavlc::xGetBit()
    2691 {
    2692   UInt ruiCode;
    2693   m_pcBitstream->read( 1, ruiCode );
    2694   return ruiCode;
    2695 }
    2696 
    2697 
    26982053/** parse explicit wp tables
    2699  * \param TComSlice* pcSlice
    2700  * \returns Void
    2701  */
     2054* \param TComSlice* pcSlice
     2055* \returns Void
     2056*/
    27022057Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice )
    27032058{
    27042059  wpScalingParam  *wp;
    27052060  Bool            bChroma     = true; // color always present in HEVC ?
    2706   TComPPS*        pps         = pcSlice->getPPS();
    27072061  SliceType       eSliceType  = pcSlice->getSliceType();
    27082062  Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
    27092063  UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
    2710   UInt            uiMode      = 0;
    2711 
    2712   if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag()==0) )
    2713     uiMode = 1; // explicit
    2714   else if ( eSliceType==B_SLICE && pps->getWPBiPredIdc()==2 )
    2715     uiMode = 2; // implicit
    2716   else if (eSliceType==B_SLICE && pps->getWPBiPredIdc()==1 && pcSlice->getRefPicListCombinationFlag())
    2717     uiMode = 3; // combined explicit
    2718 
    2719   if ( uiMode == 1 )  // explicit
    2720   {
    2721     printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) explicit...\n", pcSlice->getPOC());
    2722     Int iDeltaDenom;
    2723     // decode delta_luma_log2_weight_denom :
    2724     READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
    2725     if( bChroma )
    2726     {
    2727       READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
    2728       assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
    2729       uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
    2730     }
    2731 
    2732     for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
    2733     {
    2734       RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    2735       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
    2736       {
    2737         pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    2738 
    2739         wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
    2740         wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    2741         wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
    2742 
    2743         UInt  uiCode;
    2744         READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
    2745         wp[0].bPresentFlag = ( uiCode == 1 );
    2746         if ( wp[0].bPresentFlag )
    2747         {
    2748           Int iDeltaWeight;
    2749           READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
    2750           wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
    2751           READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
    2752         }
    2753         else
    2754         {
    2755           wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
    2756           wp[0].iOffset = 0;
    2757         }
    2758         if ( bChroma )
    2759         {
    2760           READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
    2761           wp[1].bPresentFlag = ( uiCode == 1 );
    2762           wp[2].bPresentFlag = ( uiCode == 1 );
    2763           if ( wp[1].bPresentFlag )
    2764           {
    2765             for ( Int j=1 ; j<3 ; j++ )
    2766             {
    2767               Int iDeltaWeight;
    2768               READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
    2769               wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
    2770 
    2771               Int iDeltaChroma;
    2772               READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
    2773               wp[j].iOffset = iDeltaChroma - ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) + (g_uiIBDI_MAX>>1);
    2774             }
    2775           }
    2776           else
    2777           {
    2778             for ( Int j=1 ; j<3 ; j++ )
    2779             {
    2780               wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
    2781               wp[j].iOffset = 0;
    2782             }
    2783           }
    2784         }
    2785       }
    2786 
    2787       for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
    2788       {
    2789         pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    2790 
    2791         wp[0].bPresentFlag = false;
    2792         wp[1].bPresentFlag = false;
    2793         wp[2].bPresentFlag = false;
    2794       }
    2795     }
    2796   }
    2797   else if ( uiMode == 2 )  // implicit
    2798   {
    2799     printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) implicit...\n", pcSlice->getPOC());
    2800   }
    2801   else if ( uiMode == 3 )  // combined explicit
    2802   {
    2803     printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) combined explicit...\n", pcSlice->getPOC());
    2804     Int iDeltaDenom;
    2805     // decode delta_luma_log2_weight_denom :
    2806     READ_UVLC ( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
    2807     if( bChroma )
    2808     {
    2809       READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );      // ue(v): delta_chroma_log2_weight_denom
    2810       assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
    2811       uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
    2812     }
    2813 
    2814     for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx++ )
    2815     {
    2816       pcSlice->getWpScalingLC(iRefIdx, wp);
     2064  UInt            uiTotalSignalledWeightFlags = 0;
     2065 
     2066  Int iDeltaDenom;
     2067  // decode delta_luma_log2_weight_denom :
     2068  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
     2069  assert( uiLog2WeightDenomLuma <= 7 );
     2070  if( bChroma )
     2071  {
     2072    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
     2073    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
     2074    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
     2075    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
     2076  }
     2077
     2078  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
     2079  {
     2080    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     2081    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2082    {
     2083      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    28172084
    28182085      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
     
    28212088
    28222089      UInt  uiCode;
    2823       READ_FLAG( uiCode, "luma_weight_lc_flag" );                  // u(1): luma_weight_lc_flag
     2090      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
    28242091      wp[0].bPresentFlag = ( uiCode == 1 );
     2092      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
     2093    }
     2094    if ( bChroma )
     2095    {
     2096      UInt  uiCode;
     2097      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2098      {
     2099        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
     2100        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
     2101        wp[1].bPresentFlag = ( uiCode == 1 );
     2102        wp[2].bPresentFlag = ( uiCode == 1 );
     2103        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
     2104      }
     2105    }
     2106    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     2107    {
     2108      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    28252109      if ( wp[0].bPresentFlag )
    28262110      {
    28272111        Int iDeltaWeight;
    2828         READ_SVLC( iDeltaWeight, "delta_luma_weight_lc" );          // se(v): delta_luma_weight_lc
     2112        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
     2113        assert( iDeltaWeight >= -128 );
     2114        assert( iDeltaWeight <=  127 );
    28292115        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
    2830         READ_SVLC( wp[0].iOffset, "luma_offset_lc" );               // se(v): luma_offset_lc
     2116        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
     2117        assert( wp[0].iOffset >= -128 );
     2118        assert( wp[0].iOffset <=  127 );
    28312119      }
    28322120      else
     
    28372125      if ( bChroma )
    28382126      {
    2839         READ_FLAG( uiCode, "chroma_weight_lc_flag" );                // u(1): chroma_weight_lc_flag
    2840         wp[1].bPresentFlag = ( uiCode == 1 );
    2841         wp[2].bPresentFlag = ( uiCode == 1 );
    28422127        if ( wp[1].bPresentFlag )
    28432128        {
     
    28452130          {
    28462131            Int iDeltaWeight;
    2847             READ_SVLC( iDeltaWeight, "delta_chroma_weight_lc" );      // se(v): delta_chroma_weight_lc
     2132            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
     2133            assert( iDeltaWeight >= -128 );
     2134            assert( iDeltaWeight <=  127 );
    28482135            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
    28492136
    28502137            Int iDeltaChroma;
    2851             READ_SVLC( iDeltaChroma, "delta_chroma_offset_lc" );      // se(v): delta_chroma_offset_lc
    2852             wp[j].iOffset = iDeltaChroma - ( ( (g_uiIBDI_MAX>>1)*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) + (g_uiIBDI_MAX>>1);
     2138            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
     2139            assert( iDeltaChroma >= -512 );
     2140            assert( iDeltaChroma <=  511 );
     2141            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
     2142            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
    28532143          }
    28542144        }
     
    28642154    }
    28652155
    2866     for ( Int iRefIdx=pcSlice->getNumRefIdx(REF_PIC_LIST_C) ; iRefIdx<2*MAX_NUM_REF ; iRefIdx++ )
    2867     {
    2868       pcSlice->getWpScalingLC(iRefIdx, wp);
     2156    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     2157    {
     2158      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    28692159
    28702160      wp[0].bPresentFlag = false;
     
    28732163    }
    28742164  }
    2875   else
    2876   {
    2877     printf("\n wrong weight pred table syntax \n ");
    2878     assert(0);
    2879   }
     2165  assert(uiTotalSignalledWeightFlags<=24);
    28802166}
    28812167
    28822168/** decode quantization matrix
    2883  * \param scalingList quantization matrix information
    2884  */
     2169* \param scalingList quantization matrix information
     2170*/
    28852171Void TDecCavlc::parseScalingList(TComScalingList* scalingList)
    28862172{
    28872173  UInt  code, sizeId, listId;
    28882174  Bool scalingListPredModeFlag;
    2889   READ_FLAG( code, "scaling_list_present_flag" );
    2890   scalingList->setScalingListPresentFlag ( (code==1)?true:false );
    2891   if(scalingList->getScalingListPresentFlag() == false)
    2892   {
    2893       //for each size
    2894     for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
    2895     {
    2896       for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
    2897       {
    2898         READ_FLAG( code, "scaling_list_pred_mode_flag");
    2899         scalingListPredModeFlag = (code) ? true : false;
    2900         if(!scalingListPredModeFlag) //Copy Mode
    2901         {
    2902           READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
    2903           scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code+1)));
    2904           if( sizeId > SCALING_LIST_8x8 )
    2905           {
    2906             scalingList->setScalingListDC(sizeId,listId,scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId)));
    2907           }
    2908           scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
    2909          
    2910         }
    2911         else //DPCM Mode
    2912         {
    2913           xDecodeScalingList(scalingList, sizeId, listId);
    2914         }
     2175  //for each size
     2176  for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     2177  {
     2178    for(listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
     2179    {
     2180      READ_FLAG( code, "scaling_list_pred_mode_flag");
     2181      scalingListPredModeFlag = (code) ? true : false;
     2182      if(!scalingListPredModeFlag) //Copy Mode
     2183      {
     2184        READ_UVLC( code, "scaling_list_pred_matrix_id_delta");
     2185        scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code)));
     2186        if( sizeId > SCALING_LIST_8x8 )
     2187        {
     2188          scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId))));
     2189        }
     2190        scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId));
     2191
     2192      }
     2193      else //DPCM Mode
     2194      {
     2195        xDecodeScalingList(scalingList, sizeId, listId);
    29152196      }
    29162197    }
     
    29202201}
    29212202/** decode DPCM
    2922  * \param scalingList  quantization matrix information
    2923  * \param sizeId size index
    2924  * \param listId list index
    2925  */
     2203* \param scalingList  quantization matrix information
     2204* \param sizeId size index
     2205* \param listId list index
     2206*/
    29262207Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId)
    29272208{
     
    29302211  Int scalingListDcCoefMinus8 = 0;
    29312212  Int nextCoef = SCALING_LIST_START_VALUE;
    2932   UInt* scan  = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2 ];
    2933   Bool stopNow = false;
     2213  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
    29342214  Int *dst = scalingList->getScalingListAddress(sizeId, listId);
    29352215
    2936   scalingList->setUseDefaultScalingMatrixFlag(sizeId,listId,false);
    29372216  if( sizeId > SCALING_LIST_8x8 )
    29382217  {
    29392218    READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8");
    29402219    scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8);
    2941     if(scalingListDcCoefMinus8 == -8)
    2942     {
    2943       scalingList->processDefaultMarix(sizeId,listId);
    2944     }
    2945   }
    2946 
    2947   if( !scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
    2948   {
    2949     for(i = 0; i < coefNum && !stopNow ; i++)
    2950     {
    2951       READ_SVLC( data, "scaling_list_delta_coef");
    2952       nextCoef = (nextCoef + data + 256 ) % 256;
    2953       if(sizeId < SCALING_LIST_16x16)
    2954       {
    2955         if( i == 0 && nextCoef == 0 )
    2956         {
    2957           scalingList->processDefaultMarix(sizeId,listId);
    2958           stopNow = true;
    2959         }
    2960       }
    2961       if(!stopNow)
    2962       {
    2963         dst[scan[i]] = nextCoef;
    2964       }
    2965     }
    2966   }
    2967 }
    2968 
    2969 Void TDecCavlc::parseDFFlag(UInt& ruiVal, const Char *pSymbolName)
    2970 {
    2971   READ_FLAG(ruiVal, pSymbolName);
    2972 }
    2973 Void TDecCavlc::parseDFSvlc(Int&  riVal, const Char *pSymbolName)
    2974 {
    2975   READ_SVLC(riVal, pSymbolName);
     2220    nextCoef = scalingList->getScalingListDC(sizeId,listId);
     2221  }
     2222
     2223  for(i = 0; i < coefNum; i++)
     2224  {
     2225    READ_SVLC( data, "scaling_list_delta_coef");
     2226    nextCoef = (nextCoef + data + 256 ) % 256;
     2227    dst[scan[i]] = nextCoef;