Index: trunk/source/Lib/TLibDecoder/AnnexBread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/AnnexBread.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/AnnexBread.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -31,4 +31,10 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+/**
+ \file     AnnexBread.cpp
+ \brief    reading functions for Annex B byte streams
+ */
+
 
 #include <stdint.h>
@@ -147,5 +153,5 @@
  *         otherwise true.
  */
-bool
+Bool
 byteStreamNALUnit(
   InputByteStream& bs,
@@ -153,5 +159,5 @@
   AnnexBStats& stats)
 {
-  bool eof = false;
+  Bool eof = false;
   try
   {
@@ -162,5 +168,5 @@
     eof = true;
   }
-  stats.m_numBytesInNALUnit = unsigned(nalUnit.size());
+  stats.m_numBytesInNALUnit = UInt(nalUnit.size());
   return eof;
 }
Index: trunk/source/Lib/TLibDecoder/AnnexBread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/AnnexBread.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/AnnexBread.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -32,4 +32,9 @@
  */
 
+/**
+ \file     AnnexBread.h
+ \brief    reading functions for Annex B byte streams
+ */
+
 #pragma once
 
@@ -37,4 +42,6 @@
 #include <istream>
 #include <vector>
+
+#include "TLibCommon/TypeDef.h"
 
 //! \ingroup TLibDecoder
@@ -75,5 +82,5 @@
    * n bytes.
    */
-  bool eofBeforeNBytes(unsigned n)
+  Bool eofBeforeNBytes(UInt n)
   {
     assert(n <= 4);
@@ -84,5 +91,5 @@
     try
     {
-      for (unsigned i = 0; i < n; i++)
+      for (UInt i = 0; i < n; i++)
       {
         m_FutureBytes = (m_FutureBytes << 8) | m_Input.get();
@@ -109,5 +116,5 @@
    *
    */
-  uint32_t peekBytes(unsigned n)
+  uint32_t peekBytes(UInt n)
   {
     eofBeforeNBytes(n);
@@ -139,8 +146,8 @@
    * the return value.
    */
-  uint32_t readBytes(unsigned n)
+  uint32_t readBytes(UInt n)
   {
     uint32_t val = 0;
-    for (unsigned i = 0; i < n; i++)
+    for (UInt i = 0; i < n; i++)
       val = (val << 8) | readByte();
     return val;
@@ -148,5 +155,5 @@
 
 private:
-  unsigned m_NumFutureBytes; /* number of valid bytes in m_FutureBytes */
+  UInt m_NumFutureBytes; /* number of valid bytes in m_FutureBytes */
   uint32_t m_FutureBytes; /* bytes that have been peeked */
   std::istream& m_Input; /* Input stream to read from */
@@ -158,9 +165,9 @@
 struct AnnexBStats
 {
-  unsigned m_numLeadingZero8BitsBytes;
-  unsigned m_numZeroByteBytes;
-  unsigned m_numStartCodePrefixBytes;
-  unsigned m_numBytesInNALUnit;
-  unsigned m_numTrailingZero8BitsBytes;
+  UInt m_numLeadingZero8BitsBytes;
+  UInt m_numZeroByteBytes;
+  UInt m_numStartCodePrefixBytes;
+  UInt m_numBytesInNALUnit;
+  UInt m_numTrailingZero8BitsBytes;
 
   AnnexBStats& operator+=(const AnnexBStats& rhs)
@@ -175,5 +182,5 @@
 };
 
-bool byteStreamNALUnit(InputByteStream& bs, std::vector<uint8_t>& nalUnit, AnnexBStats& stats);
+Bool byteStreamNALUnit(InputByteStream& bs, std::vector<uint8_t>& nalUnit, AnnexBStats& stats);
 
 //! \}
Index: trunk/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -32,4 +32,10 @@
  */
 
+/**
+ \file     NALread.cpp
+ \brief    reading funtionality for NAL units
+ */
+
+
 #include <vector>
 #include <algorithm>
@@ -44,18 +50,41 @@
 //! \ingroup TLibDecoder
 //! \{
-static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *pcBitstream)
+static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, Bool isVclNalUnit)
 {
-  unsigned zeroCount = 0;
+  UInt zeroCount = 0;
   vector<uint8_t>::iterator it_read, it_write;
 
   for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++)
   {
+    assert(zeroCount < 2 || *it_read >= 0x03);
     if (zeroCount == 2 && *it_read == 0x03)
     {
       it_read++;
       zeroCount = 0;
+      if (it_read == nalUnitBuf.end())
+      {
+        break;
+      }
     }
     zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0;
     *it_write = *it_read;
+  }
+  assert(zeroCount == 0);
+  
+  if (isVclNalUnit)
+  {
+    // Remove cabac_zero_word from payload if present
+    Int n = 0;
+    
+    while (it_write[-1] == 0x00)
+    {
+      it_write--;
+      n++;
+    }
+    
+    if (n > 0)
+    {
+      printf("\nDetected %d instances of cabac_zero_word", n/2);      
+    }
   }
 
@@ -63,23 +92,16 @@
 }
 
-#if NAL_UNIT_HEADER
 Void readNalUnitHeader(InputNALUnit& nalu)
 {
   TComInputBitstream& bs = *nalu.m_Bitstream;
 
-  bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
+  Bool forbidden_zero_bit = bs.read(1);           // forbidden_zero_bit
   assert(forbidden_zero_bit == 0);
   nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
+  nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
 #if SVC_EXTENSION
-  nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
   nalu.m_layerId = nalu.m_reservedZero6Bits;
 #else
-#if TARGET_DECLAYERID_SET
-  nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
   assert(nalu.m_reservedZero6Bits == 0);
-#else
-  unsigned reserved_one_6bits = bs.read(6);       // nuh_reserved_zero_6bits
-  assert(reserved_one_6bits == 0);
-#endif
 #endif
   nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
@@ -87,5 +109,4 @@
   if ( nalu.m_temporalId )
   {
-#if NAL_UNIT_TYPES_J1003_D7
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
@@ -98,27 +119,13 @@
          && nalu.m_nalUnitType != NAL_UNIT_EOS
          && nalu.m_nalUnitType != NAL_UNIT_EOB );
-#else
-    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRANT
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR
-         && nalu.m_nalUnitType != NAL_UNIT_VPS
-         && nalu.m_nalUnitType != NAL_UNIT_SPS );
-#endif
   }
   else
   {
-#if NAL_UNIT_TYPES_J1003_D7
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
-#else
-    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA );
-#endif
   }
 }
-#endif
 /**
  * create a NALunit structure with given header values and storage for
@@ -129,58 +136,9 @@
   /* perform anti-emulation prevention */
   TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
-  convertPayloadToRBSP(nalUnitBuf, pcBitstream);
-
+  convertPayloadToRBSP(nalUnitBuf, (nalUnitBuf[0] & 64) == 0);
+  
   nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
   delete pcBitstream;
-#if NAL_UNIT_HEADER
   readNalUnitHeader(nalu);
-#else
-  TComInputBitstream& bs = *nalu.m_Bitstream;
-
-  bool forbidden_zero_bit = bs.read(1);
-  assert(forbidden_zero_bit == 0);
-#if !REMOVE_NAL_REF_FLAG
-  nalu.m_nalRefFlag  = (bs.read(1) != 0 );
-#endif
-  nalu.m_nalUnitType = (NalUnitType) bs.read(6);
-#if REMOVE_NAL_REF_FLAG
-  unsigned reserved_one_6bits = bs.read(6);
-  assert(reserved_one_6bits == 0);
-#endif
-#if TEMPORAL_ID_PLUS1
-  nalu.m_temporalId = bs.read(3) - 1;
-#if !REMOVE_NAL_REF_FLAG
-  unsigned reserved_one_5bits = bs.read(5);
-  assert(reserved_one_5bits == 0);
-#endif
-#else
-  nalu.m_temporalId = bs.read(3);
-  unsigned reserved_one_5bits = bs.read(5);
-#if SVC_EXTENSION
-  assert(reserved_one_5bits >= 1);
-  nalu.m_layerId = reserved_one_5bits - 1;
-#else
-  assert(reserved_one_5bits == 1);
-#endif
-#endif
-
-  if ( nalu.m_temporalId )
-  {
-#if NAL_UNIT_TYPES_J1003_D7
-    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA );
-#else
-    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRANT
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLANT
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR );
-#endif
-  }
-#endif
 }
 //! \}
Index: trunk/source/Lib/TLibDecoder/NALread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/NALread.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/NALread.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -32,4 +32,9 @@
  */
 
+/**
+ \file     NALread.h
+ \brief    reading funtionality for NAL units
+ */
+
 #pragma once
 
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -32,4 +32,9 @@
  */
 
+/** 
+ \file     SEIread.cpp
+ \brief    reading functionality for SEI messages
+ */
+
 #include "TLibCommon/CommonDef.h"
 #include "TLibCommon/TComBitStream.h"
@@ -55,11 +60,33 @@
     fprintf( g_hTrace, "=========== Decoded picture hash SEI message ===========\n");
     break;
-#if ACTIVE_PARAMETER_SETS_SEI_MESSAGE 
-  case SEI::ACTIVE_PARAMETER_SETS:
-    fprintf( g_hTrace, "=========== Active Parameter Sets SEI message ===========\n");
-    break;
-#endif
   case SEI::USER_DATA_UNREGISTERED:
     fprintf( g_hTrace, "=========== User Data Unregistered SEI message ===========\n");
+    break;
+  case SEI::ACTIVE_PARAMETER_SETS:
+    fprintf( g_hTrace, "=========== Active Parameter sets SEI message ===========\n");
+    break;
+  case SEI::BUFFERING_PERIOD:
+    fprintf( g_hTrace, "=========== Buffering period SEI message ===========\n");
+    break;
+  case SEI::PICTURE_TIMING:
+    fprintf( g_hTrace, "=========== Picture timing SEI message ===========\n");
+    break;
+  case SEI::RECOVERY_POINT:
+    fprintf( g_hTrace, "=========== Recovery point SEI message ===========\n");
+    break;
+  case SEI::FRAME_PACKING:
+    fprintf( g_hTrace, "=========== Frame Packing Arrangement SEI message ===========\n");
+    break;
+  case SEI::DISPLAY_ORIENTATION:
+    fprintf( g_hTrace, "=========== Display Orientation SEI message ===========\n");
+    break;
+  case SEI::TEMPORAL_LEVEL0_INDEX:
+    fprintf( g_hTrace, "=========== Temporal Level Zero Index SEI message ===========\n");
+    break;
+  case SEI::REGION_REFRESH_INFO:
+    fprintf( g_hTrace, "=========== Gradual Decoding Refresh Information SEI message ===========\n");
+    break;
+  case SEI::DECODING_UNIT_INFO:
+    fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
     break;
   default:
@@ -73,5 +100,5 @@
  * unmarshal a single SEI message from bitstream bs
  */
-void SEIReader::parseSEImessage(TComInputBitstream* bs, SEImessages& seis)
+void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
 {
   setBitstream(bs);
@@ -80,13 +107,16 @@
   do
   {
-    xReadSEImessage(seis);
+    xReadSEImessage(seis, nalUnitType, sps);
     /* SEI messages are an integer number of bytes, something has failed
     * in the parsing if bitstream not byte-aligned */
     assert(!m_pcBitstream->getNumBitsUntilByteAligned());
-  } while (0x80 != m_pcBitstream->peekBits(8));
-  assert(m_pcBitstream->getNumBitsLeft() == 8); /* rsbp_trailing_bits */
-}
-
-Void SEIReader::xReadSEImessage(SEImessages& seis)
+  } while (m_pcBitstream->getNumBitsLeft() > 8);
+
+  UInt rbspTrailingBits;
+  READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits");
+  assert(rbspTrailingBits == 0x80);
+}
+
+Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
 {
 #if ENC_DEC_TRACE
@@ -113,41 +143,156 @@
 #endif
 
-  switch (payloadType)
-  {
-  case SEI::USER_DATA_UNREGISTERED:
-    seis.user_data_unregistered = new SEIuserDataUnregistered;
-    xParseSEIuserDataUnregistered(*seis.user_data_unregistered, payloadSize);
-    break;
-#if ACTIVE_PARAMETER_SETS_SEI_MESSAGE    
-  case SEI::ACTIVE_PARAMETER_SETS:
-    seis.active_parameter_sets = new SEIActiveParameterSets; 
-    xParseSEIActiveParameterSets(*seis.active_parameter_sets, payloadSize); 
-    break; 
-#endif 
-  case SEI::DECODED_PICTURE_HASH:
-    seis.picture_digest = new SEIDecodedPictureHash;
-    xParseSEIDecodedPictureHash(*seis.picture_digest, payloadSize);
-    break;
-#if BUFFERING_PERIOD_AND_TIMING_SEI
-  case SEI::BUFFERING_PERIOD:
-    seis.buffering_period = new SEIBufferingPeriod;
-    seis.buffering_period->m_sps = seis.m_pSPS;
-    xParseSEIBufferingPeriod(*seis.buffering_period, payloadSize);
-    break;
-  case SEI::PICTURE_TIMING:
-    seis.picture_timing = new SEIPictureTiming;
-    seis.picture_timing->m_sps = seis.m_pSPS;
-    xParseSEIPictureTiming(*seis.picture_timing, payloadSize);
-    break;
-#endif
-#if RECOVERY_POINT_SEI
-  case SEI::RECOVERY_POINT:
-    seis.recovery_point = new SEIRecoveryPoint;
-    xParseSEIRecoveryPoint(*seis.recovery_point, payloadSize);
-    break;
-#endif
-  default:
-    assert(!"Unhandled SEI message");
-  }
+  /* extract the payload for this single SEI message.
+   * This allows greater safety in erroneous parsing of an SEI message
+   * from affecting subsequent messages.
+   * After parsing the payload, bs needs to be restored as the primary
+   * bitstream.
+   */
+  TComInputBitstream *bs = getBitstream();
+  setBitstream(bs->extractSubstream(payloadSize * 8));
+
+  SEI *sei = NULL;
+
+  if(nalUnitType == NAL_UNIT_SEI)
+  {
+    switch (payloadType)
+    {
+    case SEI::USER_DATA_UNREGISTERED:
+      sei = new SEIuserDataUnregistered;
+      xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
+      break;
+    case SEI::ACTIVE_PARAMETER_SETS:
+      sei = new SEIActiveParameterSets; 
+      xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize); 
+      break; 
+    case SEI::DECODING_UNIT_INFO:
+      if (!sps)
+      {
+        printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring.");
+      }
+      else
+      {
+        sei = new SEIDecodingUnitInfo; 
+        xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps);
+      }
+      break; 
+    case SEI::BUFFERING_PERIOD:
+      if (!sps)
+      {
+        printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring.");
+      }
+      else
+      {
+        sei = new SEIBufferingPeriod;
+        xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps);
+      }
+      break;
+    case SEI::PICTURE_TIMING:
+      if (!sps)
+      {
+        printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring.");
+      }
+      else
+      {
+        sei = new SEIPictureTiming;
+        xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps);
+      }
+      break;
+    case SEI::RECOVERY_POINT:
+      sei = new SEIRecoveryPoint;
+      xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize);
+      break;
+    case SEI::FRAME_PACKING:
+      sei = new SEIFramePacking;
+      xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize);
+      break;
+    case SEI::DISPLAY_ORIENTATION:
+      sei = new SEIDisplayOrientation;
+      xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize);
+      break;
+    case SEI::TEMPORAL_LEVEL0_INDEX:
+      sei = new SEITemporalLevel0Index;
+      xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize);
+      break;
+    case SEI::REGION_REFRESH_INFO:
+      sei = new SEIGradualDecodingRefreshInfo;
+      xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
+      break;
+    default:
+      for (UInt i = 0; i < payloadSize; i++)
+      {
+        UInt seiByte;
+        READ_CODE (8, seiByte, "unknown prefix SEI payload byte");
+      }
+      printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType);
+    }
+  }
+  else
+  {
+    switch (payloadType)
+    {
+#if L0363_SEI_ALLOW_SUFFIX
+      case SEI::USER_DATA_UNREGISTERED:
+        sei = new SEIuserDataUnregistered;
+        xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
+        break;
+#endif
+      case SEI::DECODED_PICTURE_HASH:
+        sei = new SEIDecodedPictureHash;
+        xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize);
+        break;
+      default:
+        for (UInt i = 0; i < payloadSize; i++)
+        {
+          UInt seiByte;
+          READ_CODE (8, seiByte, "unknown suffix SEI payload byte");
+        }
+        printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType);
+    }
+  }
+  if (sei != NULL)
+  {
+    seis.push_back(sei);
+  }
+
+  /* By definition the underlying bitstream terminates in a byte-aligned manner.
+   * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data
+   * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker
+   * 3. Extract the remainingreserved_payload_extension_data bits.
+   *
+   * If there are fewer than 9 bits available, extract them.
+   */
+  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
+  if (payloadBitsRemaining) /* more_data_in_payload() */
+  {
+    for (; payloadBitsRemaining > 9; payloadBitsRemaining--)
+    {
+      UInt reservedPayloadExtensionData;
+      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
+    }
+
+    /* 2 */
+    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
+    Int finalPayloadBits = 0;
+    for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++)
+    {
+      continue;
+    }
+
+    /* 3 */
+    for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--)
+    {
+      UInt reservedPayloadExtensionData;
+      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
+    }
+
+    UInt dummy;
+    READ_CODE (1, dummy, "payload_bit_equal_to_one");
+    READ_CODE (payloadBitsRemaining-1, dummy, "payload_bit_equal_to_zero");
+  }
+
+  /* restore primary bitstream for sei_message */
+  delete getBitstream();
+  setBitstream(bs);
 }
 
@@ -186,14 +331,14 @@
  * of payloadSize bytes into sei.
  */
-Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt payloadSize)
+Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/)
 {
   UInt val;
   READ_CODE (8, val, "hash_type");
   sei.method = static_cast<SEIDecodedPictureHash::Method>(val);
-  for(int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
+  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
   {
     if(SEIDecodedPictureHash::MD5 == sei.method)
     {
-      for (unsigned i = 0; i < 16; i++)
+      for (UInt i = 0; i < 16; i++)
       {
         READ_CODE(8, val, "picture_md5");
@@ -217,23 +362,20 @@
   }
 }
-#if ACTIVE_PARAMETER_SETS_SEI_MESSAGE 
-Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, unsigned payloadSize)
+Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/)
 {
   UInt val; 
-  READ_CODE(4, val, "active_vps_id");
-  sei.activeVPSId = val; 
-
-  READ_CODE(1, val, "active_sps_id_present_flag");
-  sei.activeSPSIdPresentFlag = val; 
-
-  if(sei.activeSPSIdPresentFlag)
-  {
-    READ_UVLC(val, "active_seq_param_set_id");
-    sei.activeSeqParamSetId = val; 
-  }
-
-  READ_CODE(1, val, "active_param_set_sei_extension_flag");
-  sei.activeParamSetSEIExtensionFlag = val; 
-  
+  READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val; 
+#if L0047_APS_FLAGS
+  READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
+  READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
+#endif
+  READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
+
+  sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1);
+  for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++)
+  {
+    READ_UVLC(val, "active_seq_param_set_id");  sei.activeSeqParamSetId[i] = val; 
+  }
+
   UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned(); 
   
@@ -243,36 +385,75 @@
   }
 }
-#endif
-
-#if BUFFERING_PERIOD_AND_TIMING_SEI
-Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt payloadSize)
+
+Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps)
+{
+  UInt val;
+  READ_UVLC(val, "decoding_unit_idx");
+  sei.m_decodingUnitIdx = val;
+
+  TComVUI *vui = sps->getVuiParameters();
+  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
+  {
+    READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay");
+    sei.m_duSptCpbRemovalDelay = val;
+  }
+  else
+  {
+    sei.m_duSptCpbRemovalDelay = 0;
+  }
+#if L0044_DU_DPB_OUTPUT_DELAY_HRD
+  READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
+  if(sei.m_dpbOutputDuDelayPresentFlag)
+  {
+    READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 
+    sei.m_picSptDpbOutputDuDelay = val;
+  }
+#endif
+  xParseByteAlign();
+}
+
+Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps)
 {
   Int i, nalOrVcl;
   UInt code;
 
-  TComVUI *pVUI = sei.m_sps->getVuiParameters();
-
-  READ_UVLC( code, "seq_parameter_set_id" );                            sei.m_seqParameterSetId     = code;
-  if( !pVUI->getSubPicCpbParamsPresentFlag() )
-  {
-    READ_FLAG( code, "alt_cpb_params_present_flag" );                   sei.m_altCpbParamsPresentFlag = code;
-  }
-
+  TComVUI *pVUI = sps->getVuiParameters();
+  TComHRD *pHRD = pVUI->getHrdParameters();
+
+  READ_UVLC( code, "bp_seq_parameter_set_id" );                         sei.m_bpSeqParameterSetId     = code;
+  if( !pHRD->getSubPicCpbParamsPresentFlag() )
+  {
+    READ_FLAG( code, "rap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
+  }
+#if L0328_SPLICING
+  //read splicing flag and cpb_removal_delay_delta
+  READ_FLAG( code, "concatenation_flag"); 
+  sei.m_concatenationFlag = code;
+  READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
+  sei.m_auCpbRemovalDelayDelta = code + 1;
+#endif
+#if L0044_CPB_DPB_DELAY_OFFSET
+  if( sei.m_rapCpbParamsPresentFlag )
+  {
+    READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
+    READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
+  }
+#endif
   for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
   {
-    if( ( ( nalOrVcl == 0 ) && ( pVUI->getNalHrdParametersPresentFlag() ) ) ||
-        ( ( nalOrVcl == 1 ) && ( pVUI->getVclHrdParametersPresentFlag() ) ) )
-    {
-      for( i = 0; i < ( pVUI->getCpbCntMinus1( 0 ) + 1 ); i ++ )
-      {
-        READ_CODE( ( pVUI->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
+    if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) ||
+        ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) )
+    {
+      for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ )
+      {
+        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" );
         sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code;
-        READ_CODE( ( pVUI->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
+        READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" );
         sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code;
-        if( pVUI->getSubPicCpbParamsPresentFlag() || sei.m_altCpbParamsPresentFlag )
+        if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
         {
-          READ_CODE( ( pVUI->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
+          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" );
           sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code;
-          READ_CODE( ( pVUI->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
+          READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" );
           sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code;
         }
@@ -282,34 +463,58 @@
   xParseByteAlign();
 }
-Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt payloadSize)
+Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps)
 {
   Int i;
   UInt code;
 
-  TComVUI *vui = sei.m_sps->getVuiParameters();
-
-  if( !vui->getNalHrdParametersPresentFlag() && !vui->getVclHrdParametersPresentFlag() )
+  TComVUI *vui = sps->getVuiParameters();
+  TComHRD *hrd = vui->getHrdParameters();
+
+#if !L0045_CONDITION_SIGNALLING
+  // This condition was probably OK before the pic_struct, progressive_source_idc, duplicate_flag were added
+  if( !hrd->getNalHrdParametersPresentFlag() && !hrd->getVclHrdParametersPresentFlag() )
   {
     return;
   }
-
-  READ_CODE( ( vui->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay" );
-  sei.m_auCpbRemovalDelay = code;
-  READ_CODE( ( vui->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
-  sei.m_picDpbOutputDelay = code;
-
-  if( sei.m_sps->getVuiParameters()->getSubPicCpbParamsPresentFlag() )
-  {
-    READ_UVLC( code, "num_decoding_units_minus1");
-    sei.m_numDecodingUnitsMinus1 = code;
-    READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
-    sei.m_duCommonCpbRemovalDelayFlag = code;
-    if( sei.m_duCommonCpbRemovalDelayFlag )
-    {
-      READ_CODE( ( vui->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
-      sei.m_duCommonCpbRemovalDelayMinus1 = code;
-    }
-    else
-    {
+#endif
+
+  if( vui->getFrameFieldInfoPresentFlag() )
+  {
+    READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
+#if L0046_RENAME_PROG_SRC_IDC
+    READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
+#else
+    READ_CODE( 2, code, "progressive_source_idc" ); sei.m_progressiveSourceIdc = code;
+#endif
+    READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
+  }
+
+#if L0045_CONDITION_SIGNALLING
+  if( hrd->getCpbDpbDelaysPresentFlag())
+  {
+#endif
+    READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
+    sei.m_auCpbRemovalDelay = code + 1;
+    READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" );
+    sei.m_picDpbOutputDelay = code;
+
+#if L0044_DU_DPB_OUTPUT_DELAY_HRD
+    if(hrd->getSubPicCpbParamsPresentFlag())
+    {
+      READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" );
+      sei.m_picDpbOutputDuDelay = code;
+    }
+#endif
+    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
+    {
+      READ_UVLC( code, "num_decoding_units_minus1");
+      sei.m_numDecodingUnitsMinus1 = code;
+      READ_FLAG( code, "du_common_cpb_removal_delay_flag" );
+      sei.m_duCommonCpbRemovalDelayFlag = code;
+      if( sei.m_duCommonCpbRemovalDelayFlag )
+      {
+        READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" );
+        sei.m_duCommonCpbRemovalDelayMinus1 = code;
+      }
       if( sei.m_numNalusInDuMinus1 != NULL )
       {
@@ -323,18 +528,21 @@
       sei.m_duCpbRemovalDelayMinus1  = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ];
 
-      for( i = 0; i < ( sei.m_numDecodingUnitsMinus1 + 1 ); i ++ )
+      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
       {
         READ_UVLC( code, "num_nalus_in_du_minus1");
         sei.m_numNalusInDuMinus1[ i ] = code;
-        READ_CODE( ( vui->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
-        sei.m_duCpbRemovalDelayMinus1[ i ] = code;
-      }
-    }
-  }
-  xParseByteAlign();
-}
-#endif
-#if RECOVERY_POINT_SEI
-Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt payloadSize)
+        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
+        {
+          READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" );
+          sei.m_duCpbRemovalDelayMinus1[ i ] = code;
+        }
+      }
+    }
+#if L0045_CONDITION_SIGNALLING
+  }
+#endif
+  xParseByteAlign();
+}
+Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/)
 {
   Int  iCode;
@@ -345,7 +553,83 @@
   xParseByteAlign();
 }
-#endif
-
-#if RECOVERY_POINT_SEI || BUFFERING_PERIOD_AND_TIMING_SEI
+Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/)
+{
+  UInt val;
+  READ_UVLC( val, "frame_packing_arrangement_id" );                 sei.m_arrangementId = val;
+  READ_FLAG( val, "frame_packing_arrangement_cancel_flag" );        sei.m_arrangementCancelFlag = val;
+
+  if ( !sei.m_arrangementCancelFlag )
+  {
+    READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
+#if L0444_FPA_TYPE
+    assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
+#endif
+    READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
+
+    READ_CODE( 6, val, "content_interpretation_type" );             sei.m_contentInterpretationType = val;
+    READ_FLAG( val, "spatial_flipping_flag" );                      sei.m_spatialFlippingFlag = val;
+    READ_FLAG( val, "frame0_flipped_flag" );                        sei.m_frame0FlippedFlag = val;
+    READ_FLAG( val, "field_views_flag" );                           sei.m_fieldViewsFlag = val;
+    READ_FLAG( val, "current_frame_is_frame0_flag" );               sei.m_currentFrameIsFrame0Flag = val;
+    READ_FLAG( val, "frame0_self_contained_flag" );                 sei.m_frame0SelfContainedFlag = val;
+    READ_FLAG( val, "frame1_self_contained_flag" );                 sei.m_frame1SelfContainedFlag = val;
+
+    if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
+    {
+      READ_CODE( 4, val, "frame0_grid_position_x" );                sei.m_frame0GridPositionX = val;
+      READ_CODE( 4, val, "frame0_grid_position_y" );                sei.m_frame0GridPositionY = val;
+      READ_CODE( 4, val, "frame1_grid_position_x" );                sei.m_frame1GridPositionX = val;
+      READ_CODE( 4, val, "frame1_grid_position_y" );                sei.m_frame1GridPositionY = val;
+    }
+
+    READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
+#if L0045_PERSISTENCE_FLAGS
+    READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
+#else
+    READ_UVLC( val, "frame_packing_arrangement_repetition_period" );  sei.m_arrangementRepetetionPeriod = val;
+#endif
+  }
+  READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
+
+  xParseByteAlign();
+}
+
+Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/)
+{
+  UInt val;
+  READ_FLAG( val,       "display_orientation_cancel_flag" );       sei.cancelFlag            = val;
+  if( !sei.cancelFlag ) 
+  {
+    READ_FLAG( val,     "hor_flip" );                              sei.horFlip               = val;
+    READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
+    READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
+#if L0045_PERSISTENCE_FLAGS
+    READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
+#else
+    READ_UVLC( val,     "display_orientation_repetition_period" ); sei.repetitionPeriod      = val;
+#endif
+#if !REMOVE_SINGLE_SEI_EXTENSION_FLAGS
+    READ_FLAG( val,     "display_orientation_extension_flag" );    sei.extensionFlag         = val;
+    assert( !sei.extensionFlag );
+#endif
+  }
+  xParseByteAlign();
+}
+
+Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/)
+{
+  UInt val;
+  READ_CODE ( 8, val, "tl0_idx" );  sei.tl0Idx = val;
+  READ_CODE ( 8, val, "rap_idx" );  sei.rapIdx = val;
+  xParseByteAlign();
+}
+
+Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/)
+{
+  UInt val;
+  READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0;
+  xParseByteAlign();
+}
+
 Void SEIReader::xParseByteAlign()
 {
@@ -360,4 +644,3 @@
   }
 }
-#endif
 //! \}
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -32,4 +32,9 @@
  */
 
+/**
+ \file     SEIread.h
+ \brief    reading funtionality for SEI messages
+ */
+
 #ifndef __SEIREAD__
 #define __SEIREAD__
@@ -44,5 +49,4 @@
 #include "TLibCommon/SEI.h"
 class TComInputBitstream;
-class SEImessages;
 
 
@@ -52,22 +56,19 @@
   SEIReader() {};
   virtual ~SEIReader() {};
-  Void parseSEImessage(TComInputBitstream* bs, SEImessages& seis);
+  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
 protected:
-  Void xReadSEImessage                (SEImessages& seis);
+  Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
   Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
-#if ACTIVE_PARAMETER_SETS_SEI_MESSAGE 
-  Void xParseSEIActiveParameterSets    (SEIActiveParameterSets& sei, UInt payloadSize);
-#endif
+  Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
+  Void xParseSEIDecodingUnitInfo      (SEIDecodingUnitInfo& sei, UInt payloadSize, TComSPS *sps);
   Void xParseSEIDecodedPictureHash    (SEIDecodedPictureHash& sei, UInt payloadSize);
-#if BUFFERING_PERIOD_AND_TIMING_SEI
-  Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize);
-  Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize);
-#endif
-#if RECOVERY_POINT_SEI
+  Void xParseSEIBufferingPeriod       (SEIBufferingPeriod& sei, UInt payloadSize, TComSPS *sps);
+  Void xParseSEIPictureTiming         (SEIPictureTiming& sei, UInt payloadSize, TComSPS *sps);
   Void xParseSEIRecoveryPoint         (SEIRecoveryPoint& sei, UInt payloadSize);
-#endif
-#if RECOVERY_POINT_SEI || BUFFERING_PERIOD_AND_TIMING_SEI
+  Void xParseSEIFramePacking          (SEIFramePacking& sei, UInt payloadSize);
+  Void xParseSEIDisplayOrientation    (SEIDisplayOrientation &sei, UInt payloadSize);
+  Void xParseSEITemporalLevel0Index   (SEITemporalLevel0Index &sei, UInt payloadSize);
+  Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
   Void xParseByteAlign();
-#endif
 };
 
Index: trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 125)
@@ -4,5 +4,5 @@
 * granted under this license.  
 *
-* Copyright (c) 2010-2012, ITU/ISO/IEC
+* Copyright (c) 2010-2013, ITU/ISO/IEC
 * All rights reserved.
 *
Index: trunk/source/Lib/TLibDecoder/SyntaxElementParser.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SyntaxElementParser.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/SyntaxElementParser.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -90,4 +90,5 @@
 public:
   Void  setBitstream ( TComInputBitstream* p )   { m_pcBitstream = p; }
+  TComInputBitstream* getBitstream() { return m_pcBitstream; }
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecBinCoder.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoder.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoder.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -62,5 +62,4 @@
   
   virtual Void  resetBac          ()                                          = 0;
-  virtual Void  decodeNumSubseqIPCM( Int& numSubseqIPCM )                  = 0;
   virtual Void  decodePCMAlignBits()                                          = 0;
   virtual Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode)              = 0;
Index: trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -251,35 +251,4 @@
 }
 
-/** Decode subsequent_pcm_num.
- * \param numSubseqIPCM
- * \returns Void
- */
-Void TDecBinCABAC::decodeNumSubseqIPCM( Int& numSubseqIPCM )
-{
-  UInt bit = 0;
-
-  numSubseqIPCM = 0;
-
-  do
-  {
-    m_uiValue += m_uiValue;
-    if ( ++m_bitsNeeded >= 0 )
-    {
-      m_bitsNeeded = -8;
-      m_uiValue += m_pcTComBitstream->readByte();
-    }
-    bit = ((m_uiValue&128)>>7);
-    numSubseqIPCM++;
-  }
-  while( bit && (numSubseqIPCM < 3 ));
-
-  if( bit && (numSubseqIPCM == 3 ))
-  {
-    numSubseqIPCM++;
-  }
-
-  numSubseqIPCM --;
-}
-
 /** Decode PCM alignment zero bits.
  * \returns Void
Index: trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -64,5 +64,4 @@
   
   Void  resetBac          ();
-  Void  decodeNumSubseqIPCM( Int& numSubseqIPCM ) ;
   Void  decodePCMAlignBits();
   Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode );
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 125)
@@ -4,5 +4,5 @@
 * granted under this license.  
 *
-* Copyright (c) 2010-2012, ITU/ISO/IEC
+* Copyright (c) 2010-2013, ITU/ISO/IEC
 * All rights reserved.
 *
@@ -55,11 +55,4 @@
 }
 
-#if !REMOVE_APS
-Void  xTraceAPSHeader (TComAPS *pAPS)
-{
-  fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
-}
-#endif
-
 Void  xTraceSliceHeader (TComSlice *pSlice)
 {
@@ -75,7 +68,4 @@
 TDecCavlc::TDecCavlc()
 {
-#if !REMOVE_FGS
-  m_iSliceGranularity = 0;
-#endif
 }
 
@@ -93,9 +83,17 @@
   UInt code;
   UInt interRPSPred;
-  READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
+  if (idx > 0)
+  {
+    READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag");  rps->setInterRPSPrediction(interRPSPred);
+  }
+  else
+  {
+    interRPSPred = false;
+    rps->setInterRPSPrediction(false);
+  }
+
   if (interRPSPred) 
   {
     UInt bit;
-#if J0234_INTER_RPS_SIMPL
     if(idx == sps->getRPSList()->getNumberOfReferencePictureSets())
     {
@@ -107,18 +105,11 @@
     }
     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
-#else
-    READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
-#endif
     Int rIdx =  idx - 1 - code;
-#if J0234_INTER_RPS_SIMPL
     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
-#else
-    assert (rIdx <= idx && rIdx >= 0);
-#endif
     TComReferencePictureSet*   rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx);
     Int k = 0, k0 = 0, k1 = 0;
     READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign
     READ_UVLC(code, "abs_delta_rps_minus1");  // absolute delta RPS minus 1
-    Int deltaRPS = (1 - (bit<<1)) * (code + 1); // delta_RPS
+    Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS
     for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
     {
@@ -136,5 +127,6 @@
         rps->setUsed(k, (refIdc == 1));
 
-        if (deltaPOC < 0) {
+        if (deltaPOC < 0)
+        {
           k0++;
         }
@@ -183,31 +175,4 @@
 }
 
-#if !REMOVE_APS
-Void TDecCavlc::parseAPS(TComAPS* aps)
-{
-#if ENC_DEC_TRACE  
-  xTraceAPSHeader(aps);
-#endif
-
-  UInt uiCode;
-  READ_UVLC(uiCode, "aps_id");                             aps->setAPSID(uiCode);
-#if !REMOVE_ALF
-  for(Int compIdx=0; compIdx< 3; compIdx++)
-  {
-    xParseAlfParam( (aps->getAlfParam())[compIdx]);
-  }
-#endif
-  READ_FLAG( uiCode, "aps_extension_flag");
-  if (uiCode)
-  {
-    while ( xMoreRbspData() )
-    {
-      READ_FLAG( uiCode, "aps_extension_data_flag");
-    }
-  }
-
-}
-#endif
-
 /** copy SAO parameter
 * \param dst  
@@ -221,16 +186,5 @@
   if (dst->typeIdx != -1)
   {
-#if SAO_TYPE_CODING
     dst->subTypeIdx = src->subTypeIdx ;
-#else
-    if (dst->typeIdx == SAO_BO)
-    {
-      dst->bandPosition = src->bandPosition ;
-    }
-    else
-    {
-      dst->bandPosition = 0;
-    }
-#endif
     dst->length  = src->length;
     for (i=0;i<dst->length;i++)
@@ -249,98 +203,4 @@
 }
 
-#if !REMOVE_ALF
-Void TDecCavlc::xParseAlfParam(ALFParam* pAlfParam)
-{
-  UInt uiSymbol;
-  char syntaxString[50];
-  sprintf(syntaxString, "alf_aps_filter_flag[%d]", pAlfParam->componentID);
-  READ_FLAG(uiSymbol, syntaxString);
-  pAlfParam->alf_flag = uiSymbol;
-  if(pAlfParam->alf_flag ==0)
-  {
-    return;
-  }
-  Int iSymbol;
-  pAlfParam->num_coeff = (Int)ALF_MAX_NUM_COEF;
-  switch(pAlfParam->componentID)
-  {
-  case ALF_Cb:
-  case ALF_Cr:
-    {
-      pAlfParam->filter_shape = ALF_CROSS9x7_SQUARE3x3;
-      pAlfParam->filters_per_group = 1;
-      for(Int pos=0; pos< pAlfParam->num_coeff; pos++)
-      {
-        READ_SVLC(iSymbol, "alf_filt_coeff");
-        pAlfParam->coeffmulti[0][pos] = iSymbol;
-      }
-    }
-    break;
-  case ALF_Y:
-    {
-      pAlfParam->filters_per_group = 0;
-      memset (pAlfParam->filterPattern, 0 , sizeof(Int)*NO_VAR_BINS);
-      pAlfParam->filter_shape = 0;
-      // filters_per_fr
-      READ_UVLC (uiSymbol, "alf_no_filters_minus1");
-      pAlfParam->filters_per_group = uiSymbol + 1;
-
-      if(uiSymbol == 1) // filters_per_group == 2
-      {
-        READ_UVLC (uiSymbol, "alf_start_second_filter");
-        pAlfParam->startSecondFilter = uiSymbol;
-        pAlfParam->filterPattern [uiSymbol] = 1;
-      }
-      else if (uiSymbol > 1) // filters_per_group > 2
-      {
-        pAlfParam->filters_per_group = 1;
-        Int numMergeFlags = 16;
-        for (Int i=1; i<numMergeFlags; i++) 
-        {
-          READ_FLAG (uiSymbol,  "alf_filter_pattern");
-          pAlfParam->filterPattern[i] = uiSymbol;
-          pAlfParam->filters_per_group += uiSymbol;
-        }
-      }
-      for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx)
-      {
-        for(Int i = 0; i < pAlfParam->num_coeff; i++)
-        {
-          pAlfParam->coeffmulti[idx][i] = xGolombDecode(kTableTabShapes[ALF_CROSS9x7_SQUARE3x3][i]);
-        }
-      }
-    }
-    break;
-  default:
-    {
-      printf("Not a legal component ID for ALF\n");
-      assert(0);
-      exit(-1);
-    }
-  }
-}
-
-Int TDecCavlc::xGolombDecode(Int k)
-{
-  Int coeff;
-  UInt symbol;
-  xReadEpExGolomb( symbol, k );
-  coeff = symbol;
-  if(symbol != 0)
-  {
-    xReadFlag(symbol);
-    if(symbol == 0)
-    {
-      coeff = -coeff;
-    }
-  }
-#if ENC_DEC_TRACE
-  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
-  fprintf( g_hTrace, "%-40s se(v) : %d\n", "alf_filt_coeff", coeff ); 
-#endif
-  return coeff;
-}
-#endif
-
 Void TDecCavlc::parsePPS(TComPPS* pcPPS)
 {
@@ -352,36 +212,39 @@
   Int   iCode;
 
-  READ_UVLC( uiCode, "pic_parameter_set_id");                      pcPPS->setPPSId (uiCode);
-  READ_UVLC( uiCode, "seq_parameter_set_id");                      pcPPS->setSPSId (uiCode);
-
+  READ_UVLC( uiCode, "pps_pic_parameter_set_id");                     pcPPS->setPPSId (uiCode);
+  READ_UVLC( uiCode, "pps_seq_parameter_set_id");                     pcPPS->setSPSId (uiCode);
+  READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
+#if L0255_MOVE_PPS_FLAGS
+  READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
+
+  READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
+#endif
   READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
 
   READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
 
+#if L0323_LIMIT_DEFAULT_LIST_SIZE
+  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
+  assert(uiCode <= 14);
+  pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
+  
+  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
+  assert(uiCode <= 14);
+  pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
+#else
   READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");       pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
   READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");       pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
-
-  READ_SVLC(iCode, "pic_init_qp_minus26" );                        pcPPS->setPicInitQPMinus26(iCode);
+#endif
+  
+  READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
   READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
-#if PPS_TS_FLAG  
   READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
   pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
-#endif
-
-#if !REMOVE_FGS
-  READ_CODE( 2, uiCode, "slice_granularity" );                     pcPPS->setSliceGranularity(uiCode);
-#endif
-  
-  // alf_param() ?
-#if CU_DQP_ENABLE_FLAG
+
   READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
   if( pcPPS->getUseDQP() )
   {
     READ_UVLC( uiCode, "diff_cu_qp_delta_depth" );
-#if REMOVE_FGS
     pcPPS->setMaxCuDQPDepth( uiCode );
-#else
-    pcPPS->setMaxCuDQPDepth( uiCode + pcPPS->getSliceGranularity() );
-#endif
   }
   else
@@ -389,39 +252,16 @@
     pcPPS->setMaxCuDQPDepth( 0 );
   }
-#else
-  READ_UVLC( uiCode, "diff_cu_qp_delta_depth");
-  if(uiCode == 0)
-  {
-    pcPPS->setUseDQP (false);
-    pcPPS->setMaxCuDQPDepth( 0 );
-  }
-  else
-  {
-    pcPPS->setUseDQP (true);
-#if REMOVE_FGS
-    pcPPS->setMaxCuDQPDepth(uiCode - 1);
-#else
-    pcPPS->setMaxCuDQPDepth(uiCode + pcPPS->getSliceGranularity() - 1);
-#endif
-  }
-#endif
-  READ_SVLC( iCode, "cb_qp_offset");
+  READ_SVLC( iCode, "pps_cb_qp_offset");
   pcPPS->setChromaCbQpOffset(iCode);
-#if CHROMA_QP_EXTENSION
   assert( pcPPS->getChromaCbQpOffset() >= -12 );
   assert( pcPPS->getChromaCbQpOffset() <=  12 );
-#endif
-
-  READ_SVLC( iCode, "cr_qp_offset");
+
+  READ_SVLC( iCode, "pps_cr_qp_offset");
   pcPPS->setChromaCrQpOffset(iCode);
-#if CHROMA_QP_EXTENSION
   assert( pcPPS->getChromaCrQpOffset() >= -12 );
   assert( pcPPS->getChromaCrQpOffset() <=  12 );
-#endif
-
-#if CHROMA_QP_EXTENSION
-  READ_FLAG( uiCode, "slicelevel_chroma_qp_flag" );
+
+  READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" );
   pcPPS->setSliceChromaQpFlag( uiCode ? true : false );
-#endif
 
   READ_FLAG( uiCode, "weighted_pred_flag" );          // Use of Weighting Prediction (P_SLICE)
@@ -429,32 +269,15 @@
   READ_FLAG( uiCode, "weighted_bipred_flag" );         // Use of Bi-Directional Weighting Prediction (B_SLICE)
   pcPPS->setWPBiPred( uiCode==1 );
-  printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPred());
-
+
+#if !L0255_MOVE_PPS_FLAGS
   READ_FLAG( uiCode, "output_flag_present_flag" );
   pcPPS->setOutputFlagPresentFlag( uiCode==1 );
-
-#if !TILES_WPP_ENTROPYSLICES_FLAGS
-#if DEPENDENT_SLICES
-  READ_FLAG( uiCode, "dependent_slices_enabled_flag" );
-  pcPPS->setDependentSliceEnabledFlag( uiCode==1 );
-#endif
-#endif
-
+#endif
   READ_FLAG( uiCode, "transquant_bypass_enable_flag");
   pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
-
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-#if DEPENDENT_SLICES
-  READ_FLAG( uiCode, "dependent_slices_enabled_flag"    );    pcPPS->setDependentSliceEnabledFlag   ( uiCode == 1 );
-#endif
   READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
-  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );   
-  READ_FLAG( uiCode, "entropy_slice_enabled_flag"       );    pcPPS->setEntropySliceEnabledFlag     ( uiCode == 1 );   
-
+  READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
+  
   if( pcPPS->getTilesEnabledFlag() )
-#else
-  READ_CODE(2, uiCode, "tiles_or_entropy_coding_sync_idc");         pcPPS->setTilesOrEntropyCodingSyncIdc(uiCode);
-  if(pcPPS->getTilesOrEntropyCodingSyncIdc() == 1)
-#endif
   {
     READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );  
@@ -488,21 +311,10 @@
     }
   }
-#if !TILES_WPP_ENTROPYSLICES_FLAGS
-#if DEPENDENT_SLICES
-  else if( pcPPS->getTilesOrEntropyCodingSyncIdc()==3 )
-  {
-    READ_FLAG ( uiCode, "cabac_independent_flag" );
-    pcPPS->setCabacIndependentFlag( (uiCode == 1)? true : false );
-  }
-#endif
-#endif
-#if MOVE_LOOP_FILTER_SLICES_FLAG
   READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" );       pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false );
-#endif
   READ_FLAG( uiCode, "deblocking_filter_control_present_flag" );       pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false );
   if(pcPPS->getDeblockingFilterControlPresentFlag())
   {
     READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" );    pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false );
-    READ_FLAG( uiCode, "pic_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
+    READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" );         pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false );
     if(!pcPPS->getPicDisableDeblockingFilterFlag())
     {
@@ -516,11 +328,17 @@
     parseScalingList( pcPPS->getScalingList() );
   }
+
+  READ_FLAG( uiCode, "lists_modification_present_flag");
+  pcPPS->setListsModificationPresentFlag(uiCode);
+
   READ_UVLC( uiCode, "log2_parallel_merge_level_minus2");
   pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
 
-#if SLICE_HEADER_EXTENSION
-  READ_FLAG( uiCode, "slice_header_extension_present_flag");
+#if !L0255_MOVE_PPS_FLAGS
+  READ_CODE(3, uiCode, "num_extra_slice_header_bits");
+  pcPPS->setNumExtraSliceHeaderBits(uiCode);
+#endif
+  READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
   pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
-#endif
 
   READ_FLAG( uiCode, "pps_extension_flag");
@@ -534,10 +352,5 @@
 }
 
-#if SUPPORT_FOR_VUI
-#if !BUFFERING_PERIOD_AND_TIMING_SEI
-Void  TDecCavlc::parseVUI(TComVUI* pcVUI)
-#else
 Void  TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS)
-#endif
 {
 #if ENC_DEC_TRACE
@@ -553,5 +366,5 @@
     {
       READ_CODE(16, uiCode, "sar_width");                             pcVUI->setSarWidth(uiCode);
-      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarWidth(uiCode);
+      READ_CODE(16, uiCode, "sar_height");                            pcVUI->setSarHeight(uiCode);
     }
   }
@@ -589,57 +402,41 @@
   assert(pcVUI->getFieldSeqFlag() == false);        // not supported yet
 
+  READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
+
+  READ_FLAG(     uiCode, "default_display_window_flag");
+  if (uiCode != 0)
+  {
+    Window &defDisp = pcVUI->getDefaultDisplayWindow();
+    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+  }
+#if L0043_TIMING_INFO
+  TimingInfo *timingInfo = pcVUI->getTimingInfo();
+  READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
+  if(timingInfo->getTimingInfoPresentFlag())
+  {
+    READ_CODE( 32, uiCode, "vui_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
+    READ_CODE( 32, uiCode, "vui_time_scale");                       timingInfo->setTimeScale                  (uiCode);
+    READ_FLAG(     uiCode, "vui_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
+    if(timingInfo->getPocProportionalToTimingFlag())
+    {
+      READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
+    }
+#endif  
   READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
-#if !BUFFERING_PERIOD_AND_TIMING_SEI
-  assert(pcVUI->getHrdParametersPresentFlag() == false);  // not supported yet
-#else
   if( pcVUI->getHrdParametersPresentFlag() )
   {
-    READ_FLAG( uiCode, "timing_info_present_flag" );                  pcVUI->setTimingInfoPresentFlag( uiCode );
-    if( pcVUI->getTimingInfoPresentFlag() )
-    {
-      READ_CODE( 32, uiCode, "num_units_in_tick" );                   pcVUI->setNumUnitsInTick( uiCode );
-      READ_CODE( 32, uiCode, "time_scale" );                          pcVUI->setTimeScale( uiCode );
-    }
-    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           pcVUI->setNalHrdParametersPresentFlag( uiCode );
-    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           pcVUI->setVclHrdParametersPresentFlag( uiCode );
-    if( pcVUI->getNalHrdParametersPresentFlag() || pcVUI->getVclHrdParametersPresentFlag() )
-    {
-      READ_FLAG( uiCode, "sub_pic_Cpb_params_present_flag" );         pcVUI->setSubPicCpbParamsPresentFlag( uiCode );
-      if( pcVUI->getSubPicCpbParamsPresentFlag() )
-      {
-        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                pcVUI->setTickDivisorMinus2( uiCode );
-        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); pcVUI->setDuCpbRemovalDelayLengthMinus1( uiCode );
-      }
-      READ_CODE( 4, uiCode, "bit_rate_scale" );                       pcVUI->setBitRateScale( uiCode );
-      READ_CODE( 4, uiCode, "cpb_size_scale" );                       pcVUI->setCpbSizeScale( uiCode );
-      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); pcVUI->setInitialCpbRemovalDelayLengthMinus1( uiCode );
-      READ_CODE( 5, uiCode, "cpb_removal_delay_length_minus1" );      pcVUI->setCpbRemovalDelayLengthMinus1( uiCode );
-      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       pcVUI->setDpbOutputDelayLengthMinus1( uiCode );
-    }
-
-    Int i, j, nalOrVcl;
-    for( i = 0; i < pcSPS->getMaxTLayers(); i ++ )
-    {
-      READ_FLAG( uiCode, "fixed_pic_rate_flag" );                     pcVUI->setFixedPicRateFlag( i, uiCode );
-      if( pcVUI->getFixedPicRateFlag( i ) )
-      {
-        READ_UVLC( uiCode, "pic_duration_in_tc_minus1" );             pcVUI->setPicDurationInTcMinus1( i, uiCode );
-      }
-      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      pcVUI->setLowDelayHrdFlag( i, uiCode );
-      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          pcVUI->setCpbCntMinus1( i, uiCode );
-      for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
-      {
-        if( ( ( nalOrVcl == 0 ) && ( pcVUI->getNalHrdParametersPresentFlag() ) ) ||
-            ( ( nalOrVcl == 1 ) && ( pcVUI->getVclHrdParametersPresentFlag() ) ) )
-        {
-          for( j = 0; j < ( pcVUI->getCpbCntMinus1( i ) + 1 ); j ++ )
-          {
-            READ_UVLC( uiCode, "bit_size_value_minus1" );             pcVUI->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
-            READ_UVLC( uiCode, "cpb_size_value_minus1" );             pcVUI->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
-            READ_FLAG( uiCode, "cbr_flag" );                          pcVUI->setCbrFlag( i, j, nalOrVcl, uiCode );
-          }
-        }
-      }
-    }
+    parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
+  }
+#if L0043_TIMING_INFO
+  }
+#endif
+#if !L0043_TIMING_INFO
+  READ_FLAG( uiCode, "poc_proportional_to_timing_flag" ); pcVUI->setPocProportionalToTimingFlag(uiCode ? true : false);
+  if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() )
+  {
+    READ_UVLC( uiCode, "num_ticks_poc_diff_one_minus1" ); pcVUI->setNumTicksPocDiffOneMinus1(uiCode);
   }
 #endif
@@ -649,4 +446,11 @@
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
+    READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
+#if L0043_MSS_IDC
+    READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
+    assert(uiCode < 4096);
+#else
+    READ_CODE( 8, uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
+#endif
     READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
     READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
@@ -655,5 +459,98 @@
   }
 }
-#endif
+
+Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
+{
+  UInt  uiCode;
+  if( commonInfPresentFlag )
+  {
+#if !L0043_TIMING_INFO
+    READ_FLAG( uiCode, "timing_info_present_flag" );                  hrd->setTimingInfoPresentFlag( uiCode == 1 ? true : false );
+    if( hrd->getTimingInfoPresentFlag() )
+    {
+      READ_CODE( 32, uiCode, "num_units_in_tick" );                   hrd->setNumUnitsInTick( uiCode );
+      READ_CODE( 32, uiCode, "time_scale" );                          hrd->setTimeScale( uiCode );
+    }
+#endif
+    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
+    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
+    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
+    {
+      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
+      if( hrd->getSubPicCpbParamsPresentFlag() )
+      {
+        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
+        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
+        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
+#if L0044_DU_DPB_OUTPUT_DELAY_HRD
+        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
+#endif
+      }
+      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
+      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
+      if( hrd->getSubPicCpbParamsPresentFlag() )
+      {
+        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
+      }
+      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
+      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
+      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
+    }
+  }
+  Int i, j, nalOrVcl;
+  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
+  {
+    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
+    if( !hrd->getFixedPicRateFlag( i ) )
+    {
+      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
+    }
+    else
+    {
+      hrd->setFixedPicRateWithinCvsFlag( i, true );
+    }
+#if L0372
+    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
+    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
+#endif
+    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
+    {
+      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
+    }
+#if L0372
+    else
+    {      
+      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
+    }
+    if (!hrd->getLowDelayHrdFlag( i ))
+    {
+      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );      
+    }
+#else
+    READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
+    READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
+#endif
+    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
+    {
+      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
+          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
+      {
+        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
+        {
+          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
+          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
+          if( hrd->getSubPicCpbParamsPresentFlag() )
+          {
+#if L0363_DU_BIT_RATE
+            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
+#endif
+            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
+          }
+          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
+        }
+      }
+    }
+  }
+}
 
 Void TDecCavlc::parseSPS(TComSPS* pcSPS)
@@ -664,10 +561,15 @@
 
   UInt  uiCode;
-#if SPS_SYNTAX_CHANGES
-  READ_CODE( 4,  uiCode, "video_parameter_set_id");              pcSPS->setVPSId        ( uiCode );
+  READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
   READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
-  READ_FLAG(     uiCode, "sps_reserved_zero_bit");               assert(uiCode == 0);
+  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
+  if ( pcSPS->getMaxTLayers() == 1 )
+  {
+    // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
+    assert( uiCode == 1 );
+  }
+  
   parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
-  READ_UVLC(     uiCode, "seq_parameter_set_id" );               pcSPS->setSPSId( uiCode );
+  READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
   READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
   // 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
@@ -678,82 +580,51 @@
   }
 
-#else
-  READ_CODE( 3,  uiCode, "profile_space" );                      pcSPS->setProfileSpace( uiCode );
-  READ_CODE( 5,  uiCode, "profile_idc" );                        pcSPS->setProfileIdc( uiCode );
-  READ_CODE(16,  uiCode, "reserved_indicator_flags" );           pcSPS->setRsvdIndFlags( uiCode );
-  READ_CODE( 8,  uiCode, "level_idc" );                          pcSPS->setLevelIdc( uiCode );
-  READ_CODE(32,  uiCode, "profile_compatibility");               pcSPS->setProfileCompat( uiCode );
-  READ_UVLC(     uiCode, "seq_parameter_set_id" );               pcSPS->setSPSId( uiCode );
-  READ_UVLC(     uiCode, "video_parameter_set_id" );             pcSPS->setVPSId( uiCode );
-  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
-  READ_CODE( 3,  uiCode, "max_temporal_layers_minus1" );         pcSPS->setMaxTLayers( uiCode+1 );
-#endif
   READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
   READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
-  READ_FLAG(     uiCode, "pic_cropping_flag");                   pcSPS->setPicCroppingFlag ( uiCode ? true : false );
+  READ_FLAG(     uiCode, "conformance_window_flag");
   if (uiCode != 0)
   {
-    READ_UVLC(   uiCode, "pic_crop_left_offset" );               pcSPS->setPicCropLeftOffset  ( uiCode * TComSPS::getCropUnitX( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "pic_crop_right_offset" );              pcSPS->setPicCropRightOffset ( uiCode * TComSPS::getCropUnitX( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "pic_crop_top_offset" );                pcSPS->setPicCropTopOffset   ( uiCode * TComSPS::getCropUnitY( pcSPS->getChromaFormatIdc() ) );
-    READ_UVLC(   uiCode, "pic_crop_bottom_offset" );             pcSPS->setPicCropBottomOffset( uiCode * TComSPS::getCropUnitY( pcSPS->getChromaFormatIdc() ) );
-  }
-
-#if FULL_NBIT
+    Window &conf = pcSPS->getConformanceWindow();
+    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+  }
+
   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
-  g_uiBitDepth = 8 + uiCode;
-  g_uiBitIncrement = 0;
-  pcSPS->setBitDepth(g_uiBitDepth);
-  pcSPS->setBitIncrement(g_uiBitIncrement);
-  UInt m_uiSaoBitIncrease = g_uiBitDepth + (g_uiBitDepth-8) - min((Int)(g_uiBitDepth + (g_uiBitDepth-8)), 10);
-#else
-  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
-  g_uiBitDepth = 8;
-  g_uiBitIncrement = uiCode;
-  pcSPS->setBitDepth(g_uiBitDepth);
-  pcSPS->setBitIncrement(g_uiBitIncrement);
-#endif
+  g_bitDepthY = 8 + uiCode;
+  pcSPS->setBitDepthY(g_bitDepthY);
   pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
 
-  g_uiBASE_MAX  = ((1<<(g_uiBitDepth))-1);
-
-#if IBDI_NOCLIP_RANGE
-  g_uiIBDI_MAX  = g_uiBASE_MAX << g_uiBitIncrement;
-#else
-  g_uiIBDI_MAX  = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1);
-#endif
   READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
+  g_bitDepthC = 8 + uiCode;
+  pcSPS->setBitDepthC(g_bitDepthC);
   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
 
-  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
-
-  if( pcSPS->getUsePCM() )
-  {
-    READ_CODE( 4, uiCode, "pcm_bit_depth_luma_minus1" );           pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
-    READ_CODE( 4, uiCode, "pcm_bit_depth_chroma_minus1" );         pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
-  }
-
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
+
+  UInt subLayerOrderingInfoPresentFlag;
+  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
-    READ_UVLC ( uiCode, "max_dec_pic_buffering");
+    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering");
     pcSPS->setMaxDecPicBuffering( uiCode, i);
-    READ_UVLC ( uiCode, "num_reorder_pics" );
+    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
     pcSPS->setNumReorderPics(uiCode, i);
-    READ_UVLC ( uiCode, "max_latency_increase");
+    READ_UVLC ( uiCode, "sps_max_latency_increase");
     pcSPS->setMaxLatencyIncrease( uiCode, i );
-  }
-
-  READ_FLAG( uiCode, "restricted_ref_pic_lists_flag" );
-  pcSPS->setRestrictedRefPicListsFlag( uiCode );
-  if( pcSPS->getRestrictedRefPicListsFlag() )
-  {
-    READ_FLAG( uiCode, "lists_modification_present_flag" );
-    pcSPS->setListsModificationPresentFlag(uiCode);
-  }
-  else 
-  {
-    pcSPS->setListsModificationPresentFlag(true);
-  }
+
+    if (!subLayerOrderingInfoPresentFlag)
+    {
+      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
+      {
+        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
+        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
+        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
+      }
+      break;
+    }
+  }
+
   READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
   UInt log2MinCUSize = uiCode + 3;
@@ -766,9 +637,4 @@
   READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() );
   pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) );
-  if( pcSPS->getUsePCM() )
-  {
-    READ_UVLC( uiCode, "log2_min_pcm_coding_block_size_minus3" );  pcSPS->setPCMLog2MinSize (uiCode+3); 
-    READ_UVLC( uiCode, "log2_diff_max_min_pcm_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
-  }
 
   READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
@@ -793,27 +659,16 @@
     }
   }
-#if !REMOVE_LMCHROMA
-  READ_FLAG( uiCode, "chroma_pred_from_luma_enabled_flag" );        pcSPS->setUseLMChroma ( uiCode ? true : false );
-#endif
-#if !PPS_TS_FLAG
-  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               pcSPS->setUseTransformSkip ( uiCode ? true : false );
-#endif
-#if !MOVE_LOOP_FILTER_SLICES_FLAG
-  READ_FLAG( uiCode, "loop_filter_across_slice_flag" );             pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false);
-#endif
-  READ_FLAG( uiCode, "asymmetric_motion_partitions_enabled_flag" ); pcSPS->setUseAMP( uiCode );
-#if !REMOVE_NSQT
-  READ_FLAG( uiCode, "non_square_quadtree_enabled_flag" );          pcSPS->setUseNSQT( uiCode );
-#endif
+  READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
   READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" );       pcSPS->setUseSAO ( uiCode ? true : false );
-#if !REMOVE_ALF
-  READ_FLAG( uiCode, "adaptive_loop_filter_enabled_flag" );         pcSPS->setUseALF ( uiCode ? true : false );
-#endif
+
+  READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false );
   if( pcSPS->getUsePCM() )
   {
-    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );           pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
-  }
-
-  READ_FLAG( uiCode, "temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
+    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" );          pcSPS->setPCMBitDepthLuma   ( 1 + uiCode );
+    READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" );        pcSPS->setPCMBitDepthChroma ( 1 + uiCode );
+    READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" );   pcSPS->setPCMLog2MinSize (uiCode+3);
+    READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() );
+    READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
+  }
 
   READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
@@ -829,5 +684,4 @@
   }
   READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
-#if LTRP_IN_SPS
   if (pcSPS->getLongTermRefsPresent()) 
   {
@@ -837,10 +691,9 @@
     {
       READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" );
-      pcSPS->setLtRefPicPocLsbSps(uiCode, k);
+      pcSPS->setLtRefPicPocLsbSps(k, uiCode);
       READ_FLAG( uiCode,  "used_by_curr_pic_lt_sps_flag[i]");
       pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0);
     }
   }
-#endif
   READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
 #if REF_IDX_MFM
@@ -849,27 +702,15 @@
     READ_FLAG( uiCode, "sps_enh_mfm_enable_flag" );
     pcSPS->setMFMEnabledFlag( uiCode ? true : false );
-    assert(pcSPS->getMFMEnabledFlag()); 
-  }
-#endif
-#if SUPPORT_FOR_VUI
+  }
+#endif
+  READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
+
   READ_FLAG( uiCode, "vui_parameters_present_flag" );             pcSPS->setVuiParametersPresentFlag(uiCode);
 
   if (pcSPS->getVuiParametersPresentFlag())
   {
-#if !BUFFERING_PERIOD_AND_TIMING_SEI
-    parseVUI(pcSPS->getVuiParameters());
-#else
     parseVUI(pcSPS->getVuiParameters(), pcSPS);
-#endif
-  }
-#endif
-#if !SPS_AMVP_CLEANUP
-  // AMVP mode for each depth (AM_NONE or AM_EXPL)
-  for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
-  {
-    xReadFlag( uiCode );
-    pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode );
-  }
-#endif
+  }
+
   READ_FLAG( uiCode, "sps_extension_flag");
   if (uiCode)
@@ -886,18 +727,21 @@
   UInt  uiCode;
   
-#if VPS_SYNTAX_CHANGES
-  READ_CODE( 4,  uiCode,  "video_parameter_set_id" );             pcVPS->setVPSId( uiCode );
+  READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
+  READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
+#if VPS_RENAME
+  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1);
+#else
+  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
+#endif
+  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
-  READ_CODE( 2,  uiCode,  "vps_reserved_zero_2bits" );            assert(uiCode == 0);
-  READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
-  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
+  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
+  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
   parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
-  READ_CODE( 12, uiCode,  "vps_reserved_zero_12bits" );           assert(uiCode == 0);
-#else
-  READ_CODE( 3, uiCode, "vps_max_temporal_layers_minus1" );   pcVPS->setMaxTLayers( uiCode + 1 );
-  READ_CODE( 5, uiCode, "vps_max_layers_minus1" );            pcVPS->setMaxLayers( uiCode + 1 );
-  READ_UVLC( uiCode,  "video_parameter_set_id" );             pcVPS->setVPSId( uiCode );
-  READ_FLAG( uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
-#endif
+#if SIGNAL_BITRATE_PICRATE_IN_VPS
+  parseBitratePicRateInfo( pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1);
+#endif
+  UInt subLayerOrderingInfoPresentFlag;
+  READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
   for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
   {
@@ -905,15 +749,211 @@
     READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
     READ_UVLC( uiCode,  "vps_max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
-  }
-#if VPS_SYNTAX_CHANGES
-  READ_UVLC( uiCode,    "vps_num_hrd_parameters" );           assert(uiCode == 0);
-  // hrd_parameters
-#endif  
-  READ_FLAG( uiCode,  "vps_extension_flag" );          assert(!uiCode);
-  //future extensions go here..
+
+    if (!subLayerOrderingInfoPresentFlag)
+    {
+      for (i++; i <= pcVPS->getMaxTLayers()-1; i++)
+      {
+        pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i);
+        pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i);
+        pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i);
+      }
+      break;
+    }
+  }
+
+#if VPS_RENAME
+  assert( pcVPS->getNumHrdParameters() < MAX_VPS_LAYER_SETS_PLUS1 );
+  assert( pcVPS->getMaxLayerId()       < MAX_VPS_LAYER_ID_PLUS1 );
+  READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
+  READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
+  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
+  {
+    // Operation point set
+    for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ )
+#else
+  assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
+  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
+  READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
+  READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
+  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
+  {
+    // Operation point set
+    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
+#endif
+    {
+      READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );   pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
+    }
+  }
+#if L0043_TIMING_INFO
+  TimingInfo *timingInfo = pcVPS->getTimingInfo();
+  READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
+  if(timingInfo->getTimingInfoPresentFlag())
+  {
+    READ_CODE( 32, uiCode, "vps_num_units_in_tick");                timingInfo->setNumUnitsInTick             (uiCode);
+    READ_CODE( 32, uiCode, "vps_time_scale");                       timingInfo->setTimeScale                  (uiCode);
+    READ_FLAG(     uiCode, "vps_poc_proportional_to_timing_flag");  timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false);
+    if(timingInfo->getPocProportionalToTimingFlag())
+    {
+      READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
+    }
+#endif
+    READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
+
+    if( pcVPS->getNumHrdParameters() > 0 )
+    {
+      pcVPS->createHrdParamBuffer();
+    }
+    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
+    {
+      READ_UVLC( uiCode, "hrd_op_set_idx" );                       pcVPS->setHrdOpSetIdx( uiCode, i );
+      if( i > 0 )
+      {
+        READ_FLAG( uiCode, "cprms_present_flag[i]" );               pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i );
+      }
+      parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
+    }
+#if L0043_TIMING_INFO
+  }
+#endif
+  READ_FLAG( uiCode,  "vps_extension_flag" );
+  if (uiCode)
+  {
+#if VPS_EXTNS
+    parseVPSExtension(pcVPS);
+    READ_FLAG( uiCode, "vps_entension2_flag" );
+    if(uiCode)
+    {
+      while ( xMoreRbspData() )
+      {
+        READ_FLAG( uiCode, "vps_extension_data_flag");
+      }
+    }
+#else
+    while ( xMoreRbspData() )
+    {
+      READ_FLAG( uiCode, "vps_extension_data_flag");
+    }
+#endif
+  }
   
   return;
 }
 
+#if VPS_EXTNS
+Void TDecCavlc::parseVPSExtension(TComVPS *vps)
+{  
+  UInt uiCode;
+  // ... More syntax elements to be parsed here
+#if VPS_EXTN_MASK_AND_DIM_INFO
+  UInt numScalabilityTypes = 0, i = 0, j = 0;
+
+  READ_FLAG( uiCode, "avc_base_layer_flag" ); vps->setAvcBaseLayerFlag(uiCode ? true : false);
+  READ_FLAG( uiCode, "splitting_flag" ); vps->setSplittingFlag(uiCode ? true : false);
+
+  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
+  {
+    READ_FLAG( uiCode, "scalability_mask[i]" ); vps->setScalabilityMask(i, uiCode ? true : false);
+    numScalabilityTypes += uiCode;
+    if( i != 1 )
+    {
+      // Multiview and reserved masks are not used in this version of software
+      assert( uiCode == 0 );
+    }
+  }
+  vps->setNumScalabilityTypes(numScalabilityTypes);
+
+  for(j = 0; j < numScalabilityTypes; j++)
+  {
+    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
+  }
+  if(vps->getSplittingFlag())
+  {
+    UInt numBits = 0;
+    for(j = 0; j < numScalabilityTypes; j++)
+    {
+      numBits += vps->getDimensionIdLen(j);
+    }
+    assert( numBits <= 6 );
+  }
+
+  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
+  vps->setLayerIdInNuh(0, 0);
+  vps->setLayerIdInVps(0, 0);
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    if( vps->getNuhLayerIdPresentFlag() )
+    {
+      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" ); vps->setLayerIdInNuh(i, uiCode);
+      assert( uiCode > vps->getLayerIdInNuh(i-1) );
+    }
+    else
+    {
+      vps->setLayerIdInNuh(i, i);
+    }
+    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
+
+    for(j = 0; j < numScalabilityTypes; j++)
+    {
+      READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
+      assert( uiCode <= vps->getMaxLayerId() );
+    }
+  }
+#endif
+
+#if VPS_EXTN_PROFILE_INFO
+  // Profile-tier-level signalling
+  vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
+  for(Int idx = 1; idx <= vps->getNumLayerSets() - 1; idx++)
+  {
+    READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
+    if( !vps->getProfilePresentFlag(idx) )
+    {
+      READ_UVLC( uiCode, "vps_profile_layer_set_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
+      assert( vps->getProfileLayerSetRef(idx) < idx );
+      // Copy profile information as indicated 
+      vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
+    }    
+    parsePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
+  }
+#endif
+
+#if VPS_EXTN_OP_LAYER_SETS
+  // Target output layer signalling
+  READ_UVLC( uiCode,            "vps_num_output_layer_sets"); vps->setNumOutputLayerSets(uiCode);
+  for(i = 0; i < vps->getNumOutputLayerSets(); i++)
+  {
+    READ_UVLC( uiCode,           "vps_output_layer_set_idx[i]"); vps->setOutputLayerSetIdx(i, uiCode);
+    Int lsIdx = vps->getOutputLayerSetIdx(i);
+    for(j = 0; j <= vps->getMaxLayerId(); j++)
+    {
+      if(vps->getLayerIdIncludedFlag(lsIdx, j))
+      {
+        READ_FLAG( uiCode, "vps_output_layer_flag[lsIdx][j]"); vps->setOutputLayerFlag(lsIdx, j, uiCode);
+      }
+    }
+  }  
+#endif
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  // For layer 0
+  vps->setNumDirectRefLayers(0, 0);
+  // For other layers
+  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    UInt numDirectRefLayers = 0;
+    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
+      if(uiCode)
+      {
+        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
+        numDirectRefLayers++;
+      }
+    }
+    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
+  }
+#endif
+}
+#endif
+
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
 {
@@ -927,13 +967,11 @@
   TComSPS* sps = NULL;
 
-  UInt firstSliceInPic;
-  READ_FLAG( firstSliceInPic, "first_slice_in_pic_flag" );
-#if SPLICING_FRIENDLY_PARAMS
+  UInt firstSliceSegmentInPic;
+  READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
   if( rpcSlice->getRapPicFlag())
   { 
     READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
   }
-#endif
-  READ_UVLC (    uiCode, "pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
+  READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
   pps = parameterSetManager->getPrefetchedPPS(uiCode);
   //!KS: need to add error handling code here, if PPS is not available
@@ -944,107 +982,52 @@
   rpcSlice->setSPS(sps);
   rpcSlice->setPPS(pps);
-
-  Int numCUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
+  if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic ))
+  {
+    READ_FLAG( uiCode, "dependent_slice_segment_flag" );       rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false);
+  }
+  else
+  {
+    rpcSlice->setDependentSliceSegmentFlag(false);
+  }
+  Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
   Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
-#if REMOVE_FGS
-  Int numParts = 0;
-#else
-  Int numParts = (1<<(pps->getSliceGranularity()<<1));
-#endif
-  UInt lCUAddress = 0;
-  Int reqBitsOuter = 0;
-  while(numCUs>(1<<reqBitsOuter))
-  {
-    reqBitsOuter++;
-  }
-  Int reqBitsInner = 0;
-  while((numParts)>(1<<reqBitsInner)) 
-  {
-    reqBitsInner++;
-  }
-
-  UInt innerAddress = 0;
-  Int  sliceAddress = 0;
-  if(!firstSliceInPic)
-  {
-    UInt address;
-    READ_CODE( reqBitsOuter+reqBitsInner, address, "slice_address" );
-    lCUAddress = address >> reqBitsInner;
-    innerAddress = address - (lCUAddress<<reqBitsInner);
+  UInt sliceSegmentAddress = 0;
+  Int bitsSliceSegmentAddress = 0;
+  while(numCTUs>(1<<bitsSliceSegmentAddress))
+  {
+    bitsSliceSegmentAddress++;
+  }
+
+  if(!firstSliceSegmentInPic)
+  {
+    READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" );
   }
   //set uiCode to equal slice start address (or dependent slice start address)
-#if REMOVE_FGS
-  sliceAddress=(maxParts*lCUAddress)+(innerAddress);
-#else
-  sliceAddress=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(pps->getSliceGranularity()<<1)));
-#endif
-  rpcSlice->setDependentSliceCurStartCUAddr( sliceAddress );
-  rpcSlice->setDependentSliceCurEndCUAddr(numCUs*maxParts);
-
-#if SLICEHEADER_SYNTAX_FIX
-  if( pps->getDependentSliceEnabledFlag() && (sliceAddress !=0 ))
-  {
-    READ_FLAG( uiCode, "dependent_slice_flag" );       rpcSlice->setDependentSliceFlag(uiCode ? true : false);
+  Int startCuAddress = maxParts*sliceSegmentAddress;
+  rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress );
+  rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts);
+
+  if (rpcSlice->getDependentSliceSegmentFlag())
+  {
+    rpcSlice->setNextSlice          ( false );
+    rpcSlice->setNextSliceSegment ( true  );
   }
   else
   {
-    rpcSlice->setDependentSliceFlag(false);
-  }
-
-  if (rpcSlice->getDependentSliceFlag())
-  {
-    rpcSlice->setNextSlice          ( false );
-    rpcSlice->setNextDependentSlice ( true  );
-  }
-  else
-  {
     rpcSlice->setNextSlice          ( true  );
-    rpcSlice->setNextDependentSlice ( false );
-
-    rpcSlice->setSliceCurStartCUAddr(sliceAddress);
-    rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts);
+    rpcSlice->setNextSliceSegment ( false );
+
+    rpcSlice->setSliceCurStartCUAddr(startCuAddress);
+    rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
   }
   
-  if(!rpcSlice->getDependentSliceFlag())
-  {
-#endif
+  if(!rpcSlice->getDependentSliceSegmentFlag())
+  {
+    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+    {
+      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
+    }
+
     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
-#if !SLICEHEADER_SYNTAX_FIX
-    // lightweight_slice_flag
-    READ_FLAG( uiCode, "dependent_slice_flag" );
-    Bool bDependentSlice = uiCode ? true : false;
-#if DEPENDENT_SLICES
-    if( rpcSlice->getPPS()->getDependentSliceEnabledFlag())
-    {
-      if(bDependentSlice)
-      {
-        rpcSlice->setNextSlice        ( false );
-        rpcSlice->setNextDependentSlice( true  );
-#if BYTE_ALIGNMENT
-        m_pcBitstream->readByteAlignment();
-#else
-        m_pcBitstream->readOutTrailingBits();
-#endif
-        return;
-      }
-    }
-#endif
-  if (bDependentSlice)
-  {
-    rpcSlice->setNextSlice        ( false );
-    rpcSlice->setNextDependentSlice ( true  );
-  }
-  else
-  {
-    rpcSlice->setNextSlice        ( true  );
-    rpcSlice->setNextDependentSlice ( false );
-
-    rpcSlice->setSliceCurStartCUAddr(sliceAddress);
-    rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts);
-  }
-
-  if (!bDependentSlice)
-  {
-#endif // !SLICEHEADER_SYNTAX_FIX
     if( pps->getOutputFlagPresentFlag() )
     {
@@ -1060,26 +1043,5 @@
     //   colour_plane_id                                      u(2)
 
-#if !SPLICING_FRIENDLY_PARAMS
-    if(   rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
-#if SUPPORT_FOR_RAP_N_LP
-      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
-      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-#endif
-      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
-      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-#if !NAL_UNIT_TYPES_J1003_D7
-      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT
-#endif
-      || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
-    { 
-      READ_UVLC( uiCode, "rap_pic_id" );  //ignored
-      READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
-    }
-#endif
-#if SUPPORT_FOR_RAP_N_LP
     if( rpcSlice->getIdrPicFlag() )
-#else
-    if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR )
-#endif
     {
       rpcSlice->setPOC(0);
@@ -1112,12 +1074,7 @@
         iPOCmsb = iPrevPOCmsb;
       }
-#if SUPPORT_FOR_RAP_N_LP
       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
-#else
-      if(   rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT )
-#endif
       {
         // For BLA picture types, POCmsb is set to 0.
@@ -1136,5 +1093,19 @@
       else // use reference to short-term reference picture set in PPS
       {
-        READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode));
+        Int numBits = 0;
+        while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
+        {
+          numBits++;
+        }
+        if (numBits > 0)
+        {
+          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
+        }
+        else
+        {
+          uiCode = 0;
+        }
+        rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode));
+
         rps = rpcSlice->getRPS();
       }
@@ -1142,5 +1113,4 @@
       {
         Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
-#if LTRP_IN_SPS
         UInt numOfLtrp = 0;
         UInt numLtrpInSPS = 0;
@@ -1152,39 +1122,34 @@
           rps->setNumberOfLongtermPictures(numOfLtrp);
         }
-        Int bitsForLtrpInSPS = 1;
+        Int bitsForLtrpInSPS = 0;
         while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
+        {
           bitsForLtrpInSPS++;
+        }
         READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
         numOfLtrp += uiCode;
         rps->setNumberOfLongtermPictures(numOfLtrp);
-#else
-        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
-#endif
         Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
         Int prevLSB = 0, prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
-#if LTRP_IN_SPS
         for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
-#else
-        for(Int j=offset+rps->getNumberOfLongtermPictures()-1 ; j > offset-1; j--)
-#endif
-        {
-#if LTRP_IN_SPS
+        {
+          Int pocLsbLt;
           if (k < numLtrpInSPS)
           {
-            READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
+            uiCode = 0;
+            if (bitsForLtrpInSPS > 0)
+            {
+              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
+            }
             Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode);
 
-            uiCode = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
+            pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode);
             rps->setUsed(j,usedByCurrFromSPS);
           }
           else
           {
-            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); 
+            READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
             READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
           }
-#else
-          READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); 
-#endif
-          Int poc_lsb_lt = uiCode;
           READ_FLAG(uiCode,"delta_poc_msb_present_flag");
           Bool mSBPresentFlag = uiCode ? true : false;
@@ -1193,11 +1158,6 @@
             READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
             Bool deltaFlag = false;
-#if LTRP_IN_SPS
             //            First LTRP                               || First LTRP from SH           || curr LSB    != prev LSB
-            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) || (poc_lsb_lt != prevLSB) )
-#else
-            //            First LTRP                               || curr LSB    != prev LSB
-            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (poc_lsb_lt != prevLSB) )
-#endif
+            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) || (pocLsbLt != prevLSB) )
             {
               deltaFlag = true;
@@ -1213,5 +1173,5 @@
 
             Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB 
-                                        - iPOClsb + poc_lsb_lt;                                      
+                                        - iPOClsb + pocLsbLt;
             rps->setPOC     (j, pocLTCurr); 
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
@@ -1220,12 +1180,9 @@
           else
           {
-            rps->setPOC     (j, poc_lsb_lt);
-            rps->setDeltaPOC(j, - rpcSlice->getPOC() + poc_lsb_lt);
+            rps->setPOC     (j, pocLsbLt);
+            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
             rps->setCheckLTMSBPresent(j,false);  
           }
-#if !LTRP_IN_SPS
-        READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
-#endif
-          prevLSB = poc_lsb_lt;
+          prevLSB = pocLsbLt;
           prevDeltaMSB = deltaPocMSBCycleLT;
         }
@@ -1233,12 +1190,7 @@
         rps->setNumberOfPictures(offset);        
       }  
-#if SUPPORT_FOR_RAP_N_LP
       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
-#else
-      if(   rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT )
-#endif
       {
         // In the case of BLA picture types, rps data is read from slice header but ignored
@@ -1250,52 +1202,27 @@
         rpcSlice->setRPS(rps);
       }
-    }
-#if REMOVE_ALF
+      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
+      {
+        READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
+        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
+      }
+      else
+      {
+        rpcSlice->setEnableTMVPFlag(false);
+      }
+    }
     if(sps->getUseSAO())
-#else
-    if(sps->getUseSAO() || sps->getUseALF())
-#endif
-    {
-      if (sps->getUseSAO())
-      {
-        READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
-#if !SAO_LUM_CHROMA_ONOFF_FLAGS
-        if (rpcSlice->getSaoEnabledFlag() )
-#endif
-        {
-#if SAO_TYPE_SHARING 
-          READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
-#else
-          READ_FLAG(uiCode, "sao_cb_enable_flag");  rpcSlice->setSaoEnabledFlagCb((Bool)uiCode);
-          READ_FLAG(uiCode, "sao_cr_enable_flag");  rpcSlice->setSaoEnabledFlagCr((Bool)uiCode);
-#endif
-        }
-#if !SAO_LUM_CHROMA_ONOFF_FLAGS
-        else
-        {
-#if SAO_TYPE_SHARING
-          rpcSlice->setSaoEnabledFlagChroma(0);
-#else
-          rpcSlice->setSaoEnabledFlagCb(0);
-          rpcSlice->setSaoEnabledFlagCr(0);
-#endif
-        }
-#endif
-      }
-#if !REMOVE_APS
-      READ_UVLC (    uiCode, "aps_id" );  rpcSlice->setAPSId(uiCode);
-#endif
+    {
+      READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
+      READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
+    }
+
+    if (rpcSlice->getIdrPicFlag())
+    {
+      rpcSlice->setEnableTMVPFlag(false);
     }
     if (!rpcSlice->isIntra())
     {
-      if (rpcSlice->getSPS()->getTMVPFlagsPresent())
-      {
-        READ_FLAG( uiCode, "enable_temporal_mvp_flag" );
-        rpcSlice->setEnableTMVPFlag(uiCode); 
-      }
-      else
-      {
-        rpcSlice->setEnableTMVPFlag(false);
-      }
+
       READ_FLAG( uiCode, "num_ref_idx_active_override_flag");
       if (uiCode)
@@ -1328,5 +1255,5 @@
     if(!rpcSlice->isIntra())
     {
-      if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
+      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
       {
         refPicListModification->setRefPicListModificationFlagL0( 0 );
@@ -1371,5 +1298,5 @@
     if(rpcSlice->isInterB())
     {
-      if( !rpcSlice->getSPS()->getListsModificationPresentFlag() )
+      if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 )
       {
         refPicListModification->setRefPicListModificationFlagL1( 0 );
@@ -1411,13 +1338,4 @@
       refPicListModification->setRefPicListModificationFlagL1(0);
     }
-#if !SLICEHEADER_SYNTAX_FIX
-  }
-  else
-  {
-    // initialize from previous slice
-    pps = rpcSlice->getPPS();
-    sps = rpcSlice->getSPS();
-  }
-#endif
     if (rpcSlice->isInterB())
     {
@@ -1432,8 +1350,4 @@
     }
 
-#if !SLICEHEADER_SYNTAX_FIX
-  if(!bDependentSlice)
-  {
-#else
     if ( rpcSlice->getEnableTMVPFlag() )
     {
@@ -1449,6 +1363,6 @@
 
       if ( rpcSlice->getSliceType() != I_SLICE &&
-        ((rpcSlice->getColFromL0Flag()==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
-        (rpcSlice->getColFromL0Flag() ==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
+          ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)||
+           (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1)))
       {
         READ_UVLC( uiCode, "collocated_ref_idx" );
@@ -1465,9 +1379,11 @@
       rpcSlice->initWpScaling();
     }
-    READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
-    rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
-
-#endif
-    READ_SVLC( iCode, "slice_qp_delta" ); 
+    if (!rpcSlice->isIntra())
+    {
+      READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
+      rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
+    }
+
+    READ_SVLC( iCode, "slice_qp_delta" );
     rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
 
@@ -1475,5 +1391,4 @@
     assert( rpcSlice->getSliceQp() <=  51 );
 
-#if CHROMA_QP_EXTENSION
     if (rpcSlice->getPPS()->getSliceChromaQpFlag())
     {
@@ -1492,5 +1407,4 @@
       assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <=  12 );
     }
-#endif
 
     if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
@@ -1520,164 +1434,87 @@
       }
     }
-#if !SLICEHEADER_SYNTAX_FIX
-    if ( rpcSlice->getEnableTMVPFlag() )
-    {
-      if ( rpcSlice->getSliceType() == B_SLICE )
-      {
-        READ_FLAG( uiCode, "collocated_from_l0_flag" );
-        rpcSlice->setColFromL0Flag(uiCode);
-      }
-
-      if ( rpcSlice->getSliceType() != I_SLICE &&
-        ((rpcSlice->getColFromL0Flag()==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
-        (rpcSlice->getColFromL0Flag() ==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
-      {
-        READ_UVLC( uiCode, "collocated_ref_idx" );
-        rpcSlice->setColRefIdx(uiCode);
-      }
-      else
-      {
-        rpcSlice->setColRefIdx(0);
-      }
-    }
-    if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
-    {
-      xParsePredWeightTable(rpcSlice);
-      rpcSlice->initWpScaling();
-    }
-  }
-
-    READ_UVLC( uiCode, "five_minus_max_num_merge_cand");
-    rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode);
-
-  if (!bDependentSlice)
-  {
-#endif
-#if !REMOVE_ALF
-    if(sps->getUseALF())
-    {
-      char syntaxString[50];
-      for(Int compIdx=0; compIdx< 3; compIdx++)
-      {
-        sprintf(syntaxString, "alf_slice_filter_flag[%d]", compIdx);
-        READ_FLAG(uiCode, syntaxString);
-        rpcSlice->setAlfEnabledFlag( (uiCode ==1), compIdx);
-      }
-    }
-    Bool isAlfEnabled = (!rpcSlice->getSPS()->getUseALF())?(false):(rpcSlice->getAlfEnabledFlag(0)||rpcSlice->getAlfEnabledFlag(1)||rpcSlice->getAlfEnabledFlag(2));
-#endif
-#if !SAO_LUM_CHROMA_ONOFF_FLAGS
-    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag());
+    else
+    {  
+      rpcSlice->setDeblockingFilterDisable       ( false );
+      rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
+      rpcSlice->setDeblockingFilterTcOffsetDiv2  ( 0 );
+    }
+
+    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
+    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
+
+    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
+    {
+      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
+    }
+    else
+    {
+      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
+    }
+    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
+
+  }
+  
+  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
+  {
+    UInt *entryPointOffset          = NULL;
+    UInt numEntryPointOffsets, offsetLenMinus1;
+
+    READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
+    if (numEntryPointOffsets>0)
+    {
+      READ_UVLC(offsetLenMinus1, "offset_len_minus1");
+    }
+    entryPointOffset = new UInt[numEntryPointOffsets];
+    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
+    {
+#if L0116_ENTRY_POINT
+      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
+      entryPointOffset[ idx ] = uiCode + 1;
 #else
-    Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma());
-#endif
-    Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable());
-
-#if REMOVE_ALF
-#if MOVE_LOOP_FILTER_SLICES_FLAG
-    if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
-#else
-    if(rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isSAOEnabled || isDBFEnabled ))
-#endif
-#else
-    if(rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isAlfEnabled || isSAOEnabled || isDBFEnabled ))
-#endif
-    {
-      READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag");
-    }
-    else
-    {
-#if MOVE_LOOP_FILTER_SLICES_FLAG
-      uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0;
-#else
-      uiCode = rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag()?1:0;
-#endif
-    }
-    rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false);
-
-#if !SLICEHEADER_SYNTAX_FIX
-  }
-#else
-  }
-    if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
-#endif
-    {
-#if !SLICEHEADER_SYNTAX_FIX
-      Int tilesOrEntropyCodingSyncIdc = pps->getTilesOrEntropyCodingSyncIdc();
-#endif
-      UInt *entryPointOffset          = NULL;
-      UInt numEntryPointOffsets, offsetLenMinus1;
-
-#if !SLICEHEADER_SYNTAX_FIX
-      rpcSlice->setNumEntryPointOffsets ( 0 ); // default
-
-      if (tilesOrEntropyCodingSyncIdc>0)
-      {
-#endif
-      READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
-      if (numEntryPointOffsets>0)
-      {
-        READ_UVLC(offsetLenMinus1, "offset_len_minus1");
-      }
-      entryPointOffset = new UInt[numEntryPointOffsets];
-      for (UInt idx=0; idx<numEntryPointOffsets; idx++)
-      {
-        READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
-        entryPointOffset[ idx ] = uiCode;
-      }
-#if !SLICEHEADER_SYNTAX_FIX
-      }
-#endif
-
-#if !SLICEHEADER_SYNTAX_FIX
-      if ( tilesOrEntropyCodingSyncIdc == 1 ) // tiles
-#else
-      if ( pps->getTilesEnabledFlag() )
-#endif
-      {
-        rpcSlice->setTileLocationCount( numEntryPointOffsets );
-
-        UInt prevPos = 0;
-        for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
-        {
-          rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
-          prevPos += entryPointOffset[ idx ];
-        }
-      }
-#if !SLICEHEADER_SYNTAX_FIX
-      else if ( tilesOrEntropyCodingSyncIdc == 2 ) // wavefront
-#else
-      else if ( pps->getEntropyCodingSyncEnabledFlag() )
-#endif
-      {
-      Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
-        rpcSlice->allocSubstreamSizes(numSubstreams);
-        UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
-        for (Int idx=0; idx<numSubstreams-1; idx++)
-        {
-          if ( idx < numEntryPointOffsets )
-          {
-            pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
-          }
-          else
-          {
-            pSubstreamSizes[ idx ] = 0;
-          }
-        }
-      }
-
-      if (entryPointOffset)
-      {
-        delete [] entryPointOffset;
-      }
-    }
-#if SLICEHEADER_SYNTAX_FIX
-    else
-    {
-      rpcSlice->setNumEntryPointOffsets ( 0 );
-    }
-#endif
-
-#if SLICE_HEADER_EXTENSION
+      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
+      entryPointOffset[ idx ] = uiCode;
+#endif
+    }
+
+    if ( pps->getTilesEnabledFlag() )
+    {
+      rpcSlice->setTileLocationCount( numEntryPointOffsets );
+
+      UInt prevPos = 0;
+      for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++)
+      {
+        rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] );
+        prevPos += entryPointOffset[ idx ];
+      }
+    }
+    else if ( pps->getEntropyCodingSyncEnabledFlag() )
+    {
+    Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1;
+      rpcSlice->allocSubstreamSizes(numSubstreams);
+      UInt *pSubstreamSizes       = rpcSlice->getSubstreamSizes();
+      for (Int idx=0; idx<numSubstreams-1; idx++)
+      {
+        if ( idx < numEntryPointOffsets )
+        {
+          pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ;
+        }
+        else
+        {
+          pSubstreamSizes[ idx ] = 0;
+        }
+      }
+    }
+
+    if (entryPointOffset)
+    {
+      delete [] entryPointOffset;
+    }
+  }
+  else
+  {
+    rpcSlice->setNumEntryPointOffsets ( 0 );
+  }
+
   if(pps->getSliceHeaderExtensionPresentFlag())
   {
@@ -1689,19 +1526,8 @@
     }
   }
-#endif
-#if BYTE_ALIGNMENT
   m_pcBitstream->readByteAlignment();
-#else
-  if (!bDependentSlice)
-  {
-    // Reading location information
-    // read out trailing bits
-    m_pcBitstream->readOutTrailingBits();
-  }
-#endif
   return;
 }
   
-#if PROFILE_TIER_LEVEL_SYNTAX
 Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
 {
@@ -1713,8 +1539,33 @@
   READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
 
+#if L0363_BYTE_ALIGN
+  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
+  {
+    if(profilePresentFlag)
+    {
+      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
+    }
+    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
+  }
+  
+  if (maxNumSubLayersMinus1 > 0)
+  {
+    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
+    {
+      READ_CODE(2, uiCode, "reserved_zero_2bits");
+      assert(uiCode == 0);
+    }
+  }
+#endif
+  
   for(Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
-    READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
+#if !L0363_BYTE_ALIGN
+    if(profilePresentFlag)
+    {
+      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
+    }
     READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
+#endif
     if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
     {
@@ -1727,4 +1578,5 @@
   }
 }
+
 Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl)
 {
@@ -1737,7 +1589,49 @@
     READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
   }
-  READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]");  assert( uiCode == 0 );  
-}
-#endif
+#if L0046_CONSTRAINT_FLAGS
+  READ_FLAG(uiCode, "general_progressive_source_flag");
+  ptl->setProgressiveSourceFlag(uiCode ? true : false);
+
+  READ_FLAG(uiCode, "general_interlaced_source_flag");
+  ptl->setInterlacedSourceFlag(uiCode ? true : false);
+  
+  READ_FLAG(uiCode, "general_non_packed_constraint_flag");
+  ptl->setNonPackedConstraintFlag(uiCode ? true : false);
+  
+  READ_FLAG(uiCode, "general_frame_only_constraint_flag");
+  ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
+  
+  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
+  READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
+  READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
+#elif L0363_MORE_BITS
+  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[0..15]");
+  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[16..31]");
+  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[32..47]");
+#else
+  READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]");  assert( uiCode == 0 );
+#endif
+}
+#if SIGNAL_BITRATE_PICRATE_IN_VPS
+Void TDecCavlc::parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
+{
+  UInt uiCode;
+  for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
+  {
+    READ_FLAG( uiCode, "bit_rate_info_present_flag[i]" ); info->setBitRateInfoPresentFlag(i, uiCode ? true : false);
+    READ_FLAG( uiCode, "pic_rate_info_present_flag[i]" ); info->setPicRateInfoPresentFlag(i, uiCode ? true : false);
+    if(info->getBitRateInfoPresentFlag(i))
+    {
+      READ_CODE( 16, uiCode, "avg_bit_rate[i]" ); info->setAvgBitRate(i, uiCode);
+      READ_CODE( 16, uiCode, "max_bit_rate[i]" ); info->setMaxBitRate(i, uiCode);
+    }
+    if(info->getPicRateInfoPresentFlag(i))
+    {
+      READ_CODE(  2, uiCode,  "constant_pic_rate_idc[i]" ); info->setConstantPicRateIdc(i, uiCode);
+      READ_CODE( 16, uiCode,  "avg_pic_rate[i]"          ); info->setAvgPicRate(i, uiCode);
+    }
+  }
+}
+#endif  
 Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
 {
@@ -1754,37 +1648,30 @@
 }
 
-Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-#if INTRA_BL
-Void TDecCavlc::parseIntraBLFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ )
 {
   assert(0);
 }
-#endif
-
-Void TDecCavlc::parseMVPIdx( Int& riMVPIdx )
+
+Void TDecCavlc::parseSplitFlag     ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
-{
-  assert(0);
-}
-
-Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
@@ -1799,30 +1686,30 @@
 * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.  
 */
-Void TDecCavlc::parseIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 { 
   assert(0);
 }
 
-Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
+Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList )
+Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ )
 {
   assert(0);
@@ -1845,35 +1732,35 @@
 }
 
-Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType )
+Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize )
+Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth )
+Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
+Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType)
+Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/)
 {
   assert(0);
 }
 
-Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx )
+Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ )
 {
   assert(0);
 }
 
-Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ )
 {
   assert(0);
@@ -1900,9 +1787,5 @@
     {
       xReadFlag( uiSymbol );
-
-      if(uiSymbol)
-      {
-        printf("\nWarning! pcm_align_zero include a non-zero value.\n");
-      }
+      assert( uiSymbol == 0 );
     }
   }
@@ -2004,129 +1887,99 @@
   wpScalingParam  *wp;
   Bool            bChroma     = true; // color always present in HEVC ?
-  TComPPS*        pps         = pcSlice->getPPS();
   SliceType       eSliceType  = pcSlice->getSliceType();
   Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
   UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
-  UInt            uiMode      = 0;
-#if NUM_WP_LIMIT
   UInt            uiTotalSignalledWeightFlags = 0;
-#endif
-  if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPred()) )
-  {
-    uiMode = 1; // explicit
-  }
-  if ( uiMode == 1 )  // explicit
-  {
-    printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) explicit...\n", pcSlice->getPOC());
-    Int iDeltaDenom;
-    // decode delta_luma_log2_weight_denom :
-    READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
-    if( bChroma ) 
-    {
-      READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
-      assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
-      uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
-    }
-
-    for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
-    {
-      RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
+  
+  Int iDeltaDenom;
+  // decode delta_luma_log2_weight_denom :
+  READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
+  if( bChroma ) 
+  {
+    READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
+    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
+    uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
+  }
+
+  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
+  {
+    RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
+    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
+    {
+      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
+
+      wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
+      wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
+      wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
+
+      UInt  uiCode;
+      READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
+      wp[0].bPresentFlag = ( uiCode == 1 );
+      uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
+    }
+    if ( bChroma ) 
+    {
+      UInt  uiCode;
       for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
       {
         pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
-
-        wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
-        wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
-        wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
-
-        UInt  uiCode;
-        READ_FLAG( uiCode, "luma_weight_lX_flag" );           // u(1): luma_weight_l0_flag
-        wp[0].bPresentFlag = ( uiCode == 1 );
-#if NUM_WP_LIMIT
-        uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
+        READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
+        wp[1].bPresentFlag = ( uiCode == 1 );
+        wp[2].bPresentFlag = ( uiCode == 1 );
+        uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
+      }
+    }
+    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
+    {
+      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
+      if ( wp[0].bPresentFlag ) 
+      {
+        Int iDeltaWeight;
+        READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
+        wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
+        READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
+      }
+      else 
+      {
+        wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
+        wp[0].iOffset = 0;
       }
       if ( bChroma ) 
       {
-        UInt  uiCode;
-        for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
-        {
-          pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
-          READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
-          wp[1].bPresentFlag = ( uiCode == 1 );
-          wp[2].bPresentFlag = ( uiCode == 1 );
-          uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag;
-        }
-      }
-      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
-      {
-        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
-#endif
-        if ( wp[0].bPresentFlag ) 
-        {
-          Int iDeltaWeight;
-          READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
-          wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
-          READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
+        if ( wp[1].bPresentFlag ) 
+        {
+          for ( Int j=1 ; j<3 ; j++ ) 
+          {
+            Int iDeltaWeight;
+            READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
+            wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
+
+            Int iDeltaChroma;
+            READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
+            Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
+            wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
+          }
         }
         else 
         {
-          wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
-          wp[0].iOffset = 0;
-        }
-        if ( bChroma ) 
-        {
-#if !NUM_WP_LIMIT
-          READ_FLAG( uiCode, "chroma_weight_lX_flag" );      // u(1): chroma_weight_l0_flag
-          wp[1].bPresentFlag = ( uiCode == 1 );
-          wp[2].bPresentFlag = ( uiCode == 1 );
-#endif
-          if ( wp[1].bPresentFlag ) 
+          for ( Int j=1 ; j<3 ; j++ ) 
           {
-            for ( Int j=1 ; j<3 ; j++ ) 
-            {
-              Int iDeltaWeight;
-              READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
-              wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom));
-
-              Int iDeltaChroma;
-              READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );  // se(v): delta_chroma_offset_l0[i][j]
-              Int shift = ((1<<(g_uiBitDepth+g_uiBitIncrement-1)));
-              Int pred = ( shift - ( ( shift*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
-#if WP_PARAM_RANGE_LIMIT
-              wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
-#else
-              wp[j].iOffset = iDeltaChroma + pred;
-#endif
-            }
+            wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
+            wp[j].iOffset = 0;
           }
-          else 
-          {
-            for ( Int j=1 ; j<3 ; j++ ) 
-            {
-              wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
-              wp[j].iOffset = 0;
-            }
-          }
-        }
-      }
-
-      for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
-      {
-        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
-
-        wp[0].bPresentFlag = false;
-        wp[1].bPresentFlag = false;
-        wp[2].bPresentFlag = false;
-      }
-    }
-#if NUM_WP_LIMIT
-    assert(uiTotalSignalledWeightFlags<=24);
-#endif
-  }
-  else
-  {
-    printf("\n wrong weight pred table syntax \n ");
-    assert(0);
-  }
+        }
+      }
+    }
+
+    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
+    {
+      pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
+
+      wp[0].bPresentFlag = false;
+      wp[1].bPresentFlag = false;
+      wp[2].bPresentFlag = false;
+    }
+  }
+  assert(uiTotalSignalledWeightFlags<=24);
 }
 
@@ -2176,9 +2029,5 @@
   Int scalingListDcCoefMinus8 = 0;
   Int nextCoef = SCALING_LIST_START_VALUE;
-#if REMOVE_ZIGZAG_SCAN
   UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
-#else
-  UInt* scan  = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2 ];
-#endif
   Int *dst = scalingList->getScalingListAddress(sizeId, listId);
 
@@ -2227,4 +2076,11 @@
 }
 
+#if INTRA_BL
+Void TDecCavlc::parseIntraBLFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth )
+{
+  assert(0);
+}
+#endif
+
 //! \}
 
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -53,6 +53,4 @@
 // ====================================================================================================================
 
-class SEImessages;
-
 /// CAVLC decoder class
 class TDecCavlc : public SyntaxElementParser, public TDecEntropyIf
@@ -73,41 +71,27 @@
   void  parseShortTermRefPicSet            (TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Int idx);
 private:
-#if !REMOVE_FGS
-  Int           m_iSliceGranularity; //!< slice granularity
-#endif
   
 public:
 
   /// rest entropy coder by intial QP and IDC in CABAC
-  Void  resetEntropy        ( TComSlice* pcSlice  )     { assert(0); };
+  Void  resetEntropy        ( TComSlice* /*pcSlice*/  )     { assert(0); };
   Void  setBitstream        ( TComInputBitstream* p )   { m_pcBitstream = p; }
-#if !REMOVE_FGS
-  /// set slice granularity
-  Void setSliceGranularity(Int iSliceGranularity)  {m_iSliceGranularity = iSliceGranularity;}
-
-  /// get slice granularity
-  Int  getSliceGranularity()                       {return m_iSliceGranularity;             }
-#endif
   Void  parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize );
   Void  parseQtCbf          ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth );
-  Void  parseQtRootCbf      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf );
+  Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
+#if VPS_EXTNS
+  Void  parseVPSExtension   ( TComVPS* pcVPS );
+#endif
   Void  parseSPS            ( TComSPS* pcSPS );
   Void  parsePPS            ( TComPPS* pcPPS);
-#if SUPPORT_FOR_VUI
-#if !BUFFERING_PERIOD_AND_TIMING_SEI
-  Void  parseVUI            ( TComVUI* pcVUI );
-#else
   Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
-#endif
-#endif
-  Void  parseSEI(SEImessages&);
-#if !REMOVE_APS
-  Void  parseAPS            ( TComAPS* pAPS );
-#endif
-#if PROFILE_TIER_LEVEL_SYNTAX
+  Void  parseSEI            ( SEIMessages& );
   Void  parsePTL            ( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 );
   Void  parseProfileTier    (ProfileTierLevel *ptl);
+#if SIGNAL_BITRATE_PICRATE_IN_VPS
+  Void  parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh);
 #endif
+  Void  parseHrdParameters  (TComHRD *hrd, Bool cprms_present_flag, UInt tempLevelHigh);
   Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager);
   Void  parseTerminatingBit ( UInt& ruiBit );
@@ -118,5 +102,5 @@
   Void  parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void parseMergeFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
-  Void parseMergeIndex      ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth );
+  Void parseMergeIndex      ( TComDataCU* pcCU, UInt& ruiMergeIndex );
   Void parseSplitFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void parsePartSize        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -127,6 +111,6 @@
   Void parseIntraDirChroma  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   
-  Void parseInterDir        ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth );
-  Void parseRefFrmIdx       ( TComDataCU* pcCU, Int& riRefFrmIdx,  UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList );
+  Void parseInterDir        ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx );
+  Void parseRefFrmIdx       ( TComDataCU* pcCU, Int& riRefFrmIdx,  RefPicList eRefList );
   Void parseMvd             ( TComDataCU* pcCU, UInt uiAbsPartAddr,UInt uiPartIdx,    UInt uiDepth, RefPicList eRefList );
   
@@ -137,9 +121,9 @@
   Void parseIPCMInfo        ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth);
 
+  Void updateContextTables  ( SliceType /*eSliceType*/, Int /*iQp*/ ) { return; }
+
 #if INTRA_BL
   Void parseIntraBLFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
 #endif
-  Void updateContextTables  ( SliceType eSliceType, Int iQp ) { return; }
-  Void decodeFlush() {};
 
   Void xParsePredWeightTable ( TComSlice* pcSlice );
@@ -147,8 +131,4 @@
   Void xDecodeScalingList    ( TComScalingList *scalingList, UInt sizeId, UInt listId);
 protected:
-#if !REMOVE_ALF
-  Void  xParseAlfParam       ( ALFParam* pAlfParam );
-  Int   xGolombDecode        ( Int k );
-#endif
   Bool  xMoreRbspData();
 };
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -62,21 +62,24 @@
 #if SVC_EXTENSION
 Void TDecCu::init(TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction, UInt layerId)
+{
+  m_pcEntropyDecoder  = pcEntropyDecoder;
+  m_pcTrQuant         = pcTrQuant;
+  m_pcPrediction      = pcPrediction; 
+  m_ppcTDecTop = ppcDecTop;
+  m_layerId = layerId; 
+
+  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
+  {
+    m_ppcCU     [ui]->setLayerId(layerId);
+  }
+}
 #else
 Void TDecCu::init( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction)
-#endif 
 {
   m_pcEntropyDecoder  = pcEntropyDecoder;
   m_pcTrQuant         = pcTrQuant;
   m_pcPrediction      = pcPrediction;
-#if SVC_EXTENSION   
-  m_ppcTDecTop = ppcDecTop;
-  m_layerId = layerId; 
-
-  for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
-  {
-    m_ppcCU     [ui]->setLayerId(layerId);
-  }
-#endif
-}
+}
+#endif
 
 /**
@@ -114,5 +117,4 @@
   // initialize conversion matrix from partition index to pel
   initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
-  initMotionReferIdx ( uiMaxWidth, uiMaxHeight, m_uiMaxDepth );
 }
 
@@ -145,6 +147,4 @@
   }
 
-  pcCU->setNumSucIPCM(0);
-
   // start from the top level CU
 #if SVC_EXTENSION
@@ -158,5 +158,5 @@
 Void TDecCu::decompressCU( TComDataCU* pcCU )
 {
-  xDecompressCU( pcCU, pcCU, 0,  0 );
+  xDecompressCU( pcCU, 0,  0 );
 }
 
@@ -179,9 +179,5 @@
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
-#if REMOVE_FGS
   UInt uiGranularityWidth = g_uiMaxCUWidth;
-#else
-  UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity());
-#endif
   UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
   UInt uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
@@ -199,12 +195,12 @@
   if(uiIsLast) 
   {
-    if(pcSlice->isNextDependentSlice()&&!pcSlice->isNextSlice()) 
-    {
-      pcSlice->setDependentSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
+    if(pcSlice->isNextSliceSegment()&&!pcSlice->isNextSlice()) 
+    {
+      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
     }
     else 
     {
       pcSlice->setSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
-      pcSlice->setDependentSliceCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
+      pcSlice->setSliceSegmentCurEndCUAddr(pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts);
     }
   }
@@ -233,15 +229,8 @@
   
   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
-  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getDependentSliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getDependentSliceCurStartCUAddr();
+  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
   if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
   {
-    if(pcCU->getNumSucIPCM() == 0)
-    {
-      m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
-    }
-    else
-    {
-      pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx );
-    }
+    m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
   }
   else
@@ -264,8 +253,8 @@
       uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
       
-      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getDependentSliceCurStartCUAddr();
+      Bool bSubInSlice = pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr();
       if ( bSubInSlice )
       {
-        if ( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
         {
           xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
@@ -276,8 +265,4 @@
         }
       }
-      if(ruiIsLast)
-      {
-        break;
-      }
       
       uiIdx += uiQNumParts;
@@ -288,7 +273,7 @@
       {
         UInt uiQPSrcPartIdx;
-        if ( pcPic->getCU( pcCU->getAddr() )->getDependentSliceStartCU(uiAbsPartIdx) != pcSlice->getDependentSliceCurStartCUAddr() )
+        if ( pcPic->getCU( pcCU->getAddr() )->getSliceSegmentStartCU(uiAbsPartIdx) != pcSlice->getSliceSegmentCurStartCUAddr() )
         {
-          uiQPSrcPartIdx = pcSlice->getDependentSliceCurStartCUAddr() % pcPic->getNumPartInCU();
+          uiQPSrcPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU();
         }
         else
@@ -308,5 +293,5 @@
   }
 
-  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag() && pcCU->getNumSucIPCM() == 0 )
+  if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
   {
     m_pcEntropyDecoder->decodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx, uiDepth );
@@ -314,5 +299,5 @@
   
   // decode CU mode and the partition size
-  if( !pcCU->getSlice()->isIntra() && pcCU->getNumSucIPCM() == 0 )
+  if( !pcCU->getSlice()->isIntra())
   {
     m_pcEntropyDecoder->decodeSkipFlag( pcCU, uiAbsPartIdx, uiDepth );
@@ -330,7 +315,7 @@
       uhInterDirNeighbours[ui] = 0;
     }
-    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, SIZE_2Nx2N, uhInterDirNeighbours, cMvFieldNeighbours, uiDepth );
+    m_pcEntropyDecoder->decodeMergeIndex( pcCU, 0, uiAbsPartIdx, uiDepth );
     UInt uiMergeIndex = pcCU->getMergeIndex(uiAbsPartIdx);
-    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
+    m_ppcCU[uiDepth]->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
     pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiAbsPartIdx, 0, uiDepth );
 
@@ -359,16 +344,6 @@
 #endif
 
-  if( pcCU->getNumSucIPCM() == 0 ) 
-  {
-    m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
-    m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
-  }
-  else
-  {
-    pcCU->setPredModeSubParts( MODE_INTRA, uiAbsPartIdx, uiDepth );
-    pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
-    pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); 
-    pcCU->setTrIdxSubParts( 0, uiAbsPartIdx, uiDepth );
-  }
+  m_pcEntropyDecoder->decodePredMode( pcCU, uiAbsPartIdx, uiDepth );
+  m_pcEntropyDecoder->decodePartSize( pcCU, uiAbsPartIdx, uiDepth );
 
   if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N )
@@ -381,5 +356,5 @@
       return;
     }
-  }  
+  }
 #if INTRA_BL
   // prediction mode ( Intra : direction mode, Inter : Mv, reference idx )
@@ -409,14 +384,9 @@
     pcCU->setQPSubParts( getdQPFlag()?pcCU->getRefQP(uiAbsPartIdx):pcCU->getCodedQP(), uiAbsPartIdx, uiDepth ); // set QP
   }
-  if( pcCU->getNumSucIPCM() > 0 )
-  {
-    ruiIsLast = 0;
-    return;
-  }
 
   ruiIsLast = xDecodeSliceEnd( pcCU, uiAbsPartIdx, uiDepth);
 }
 
-Void TDecCu::xDecompressCU( TComDataCU* pcCU, TComDataCU* pcCUCur, UInt uiAbsPartIdx,  UInt uiDepth )
+Void TDecCu::xDecompressCU( TComDataCU* pcCU, UInt uiAbsPartIdx,  UInt uiDepth )
 {
   TComPic* pcPic = pcCU->getPic();
@@ -430,5 +400,5 @@
   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
-  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getDependentSliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getDependentSliceCurStartCUAddr();
+  Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
   if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
   {
@@ -446,8 +416,8 @@
       uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
       
-      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getDependentSliceCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getDependentSliceCurEndCUAddr());
+      Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
       if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
       {
-        xDecompressCU(pcCU, m_ppcCU[uiNextDepth], uiIdx, uiNextDepth );
+        xDecompressCU(pcCU, uiIdx, uiNextDepth );
       }
       
@@ -465,8 +435,8 @@
   {
     case MODE_INTER:
-      xReconInter( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
+      xReconInter( m_ppcCU[uiDepth], uiDepth );
       break;
     case MODE_INTRA:
-      xReconIntraQT( m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth );
+      xReconIntraQT( m_ppcCU[uiDepth], uiDepth );
       break;
 #if INTRA_BL
@@ -485,5 +455,5 @@
   if ( m_ppcCU[uiDepth]->isLosslessCoded(0) && (m_ppcCU[uiDepth]->getIPCMFlag(0) == false))
   {
-    xFillPCMBuffer(m_ppcCU[uiDepth], uiAbsPartIdx, uiDepth);    
+    xFillPCMBuffer(m_ppcCU[uiDepth], uiDepth);
   }
   
@@ -491,5 +461,5 @@
 }
 
-Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCu::xReconInter( TComDataCU* pcCU, UInt uiDepth )
 {
   
@@ -553,5 +523,5 @@
   else
 #endif
-  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, pcCU, bAboveAvail, bLeftAvail );
+  m_pcPrediction->predIntraLumaAng( pcCU->getPattern(), uiLumaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
   
   //===== inverse transform =====
@@ -572,5 +542,5 @@
     for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     {
-      pReco    [ uiX ] = Clip( pPred[ uiX ] + pResi[ uiX ] );
+      pReco    [ uiX ] = ClipY( pPred[ uiX ] + pResi[ uiX ] );
       pRecIPred[ uiX ] = pReco[ uiX ];
     }
@@ -629,18 +599,4 @@
   pcCU->getPattern()->initPattern         ( pcCU, uiTrDepth, uiAbsPartIdx );
 
-#if !REMOVE_LMCHROMA
-  if( uiChromaPredMode == LM_CHROMA_IDX && uiChromaId == 0 )
-  {
-    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
-                                     m_pcPrediction->getPredicBuf       (),
-                                     m_pcPrediction->getPredicBufWidth  (),
-                                     m_pcPrediction->getPredicBufHeight (),
-                                     bAboveAvail, bLeftAvail, 
-                                     true );
-
-    m_pcPrediction->getLumaRecPixels( pcCU->getPattern(), uiWidth, uiHeight );
-  }
-#endif
-  
   pcCU->getPattern()->initAdiPatternChroma( pcCU, uiAbsPartIdx, uiTrDepth,
                                            m_pcPrediction->getPredicBuf       (),
@@ -658,11 +614,4 @@
   else
 #endif
-#if !REMOVE_LMCHROMA
-  if( uiChromaPredMode == LM_CHROMA_IDX )
-  {
-    m_pcPrediction->predLMIntraChroma( pcCU->getPattern(), pPatChroma, piPred, uiStride, uiWidth, uiHeight, uiChromaId );
-  }
-  else
-#endif
   {
     if( uiChromaPredMode == DM_CHROMA_IDX )
@@ -670,9 +619,8 @@
       uiChromaPredMode = pcCU->getLumaIntraDir( 0 );
     }
-    m_pcPrediction->predIntraChromaAng( pcCU->getPattern(), pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, pcCU, bAboveAvail, bLeftAvail );  
+    m_pcPrediction->predIntraChromaAng( pPatChroma, uiChromaPredMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );  
   }
 
   //===== inverse transform =====
-#if CHROMA_QP_EXTENSION
   Int curChromaQpOffset;
   if(eText == TEXT_CHROMA_U)
@@ -685,14 +633,4 @@
   }
   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
-#else
-  if(eText == TEXT_CHROMA_U)
-  {
-    m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaCbQpOffset() );
-  }
-  else
-  {
-    m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaCrQpOffset() );
-  }
-#endif
 
   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
@@ -709,5 +647,5 @@
     for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     {
-      pReco    [ uiX ] = Clip( pPred[ uiX ] + pResi[ uiX ] );
+      pReco    [ uiX ] = ClipC( pPred[ uiX ] + pResi[ uiX ] );
       pRecIPred[ uiX ] = pReco[ uiX ];
     }
@@ -721,5 +659,5 @@
 
 Void
-TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+TDecCu::xReconIntraQT( TComDataCU* pcCU, UInt uiDepth )
 {
   UInt  uiInitTrDepth = ( pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1 );
@@ -729,5 +667,5 @@
   if (pcCU->getIPCMFlag(0))
   {
-    xReconPCM( pcCU, uiAbsPartIdx, uiDepth );
+    xReconPCM( pcCU, uiDepth );
     return;
   }
@@ -744,27 +682,4 @@
 
 }
-
-#if NO_RESIDUAL_FLAG_FOR_BLPRED
-Void
-TDecCu::xReconIntraBL( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
-{
-  m_ppcYuvReco[uiDepth]->copyFromPicLuma  ( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, pcCU->getWidth(0), pcCU->getHeight(0));
-  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 0);
-  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 1);
-
-  // inter recon
-  xDecodeInterTexture( pcCU, 0, uiDepth );
-
-  // clip for only non-zero cbp case
-  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
-  {
-    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
-  }
-  else
-  {
-    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
-  }
-}
-#endif
 
 /** Function for deriving recontructed PU/CU Luma sample with QTree structure
@@ -853,7 +768,5 @@
   
   Pel*    pResi;
-  UInt    uiLumaTrMode, uiChromaTrMode;
-  
-  pcCU->convertTransIdx( uiAbsPartIdx, pcCU->getTransformIdx( uiAbsPartIdx ), uiLumaTrMode, uiChromaTrMode );
+  UInt    trMode = pcCU->getTransformIdx( uiAbsPartIdx );
   
   // Y
@@ -863,28 +776,20 @@
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
 
-  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff );
+  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
   
   // Cb and Cr
-#if CHROMA_QP_EXTENSION
   Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
-#else
-  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaCbQpOffset() );
-#endif
 
   uiWidth  >>= 1;
   uiHeight >>= 1;
   piCoeff = pcCU->getCoeffCb(); pResi = m_ppcYuvResi[uiDepth]->getCbAddr();
-  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
-
-#if CHROMA_QP_EXTENSION
+  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
+
   curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
-#else
-  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaCrQpOffset() );
-#endif
 
   piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
-  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
+  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pResi, 0, m_ppcYuvResi[uiDepth]->getCStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
 }
 
@@ -911,5 +816,5 @@
     uiPicStride   = pcCU->getPic()->getPicYuvRec()->getStride();
     piPicReco = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
-    uiPcmLeftShiftBit = g_uiBitDepth + g_uiBitIncrement - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
+    uiPcmLeftShiftBit = g_bitDepthY - pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
   }
   else
@@ -925,5 +830,5 @@
       piPicReco = pcCU->getPic()->getPicYuvRec()->getCrAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiPartIdx);
     }
-    uiPcmLeftShiftBit = g_uiBitDepth + g_uiBitIncrement - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
+    uiPcmLeftShiftBit = g_bitDepthC - pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
   }
 
@@ -943,9 +848,8 @@
 /** Function for reconstructing a PCM mode CU.
  * \param pcCU pointer to current CU
- * \param uiAbsPartIdx CU index
  * \param uiDepth CU Depth
  * \returns Void
  */
-Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecCu::xReconPCM( TComDataCU* pcCU, UInt uiDepth )
 {
   // Luma
@@ -977,9 +881,8 @@
 /** Function for filling the PCM buffer of a CU using its reconstructed sample array 
  * \param pcCU pointer to current CU
- * \param uiAbsPartIdx CU index
  * \param uiDepth CU Depth
  * \returns Void
  */
-Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt absPartIdx, UInt depth)
+Void TDecCu::xFillPCMBuffer(TComDataCU* pCU, UInt depth)
 {
   // Luma
@@ -1028,3 +931,26 @@
 }
 
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+Void
+TDecCu::xReconIntraBL( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
+{
+  m_ppcYuvReco[uiDepth]->copyFromPicLuma  ( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, pcCU->getWidth(0), pcCU->getHeight(0));
+  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 0);
+  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 1);
+
+  // inter recon
+  xDecodeInterTexture( pcCU, 0, uiDepth );
+
+  // clip for only non-zero cbp case
+  if  ( ( pcCU->getCbf( 0, TEXT_LUMA ) ) || ( pcCU->getCbf( 0, TEXT_CHROMA_U ) ) || ( pcCU->getCbf(0, TEXT_CHROMA_V ) ) )
+  {
+    m_ppcYuvReco[uiDepth]->addClip( m_ppcYuvReco[uiDepth], m_ppcYuvResi[uiDepth], 0, pcCU->getWidth( 0 ) );
+  }
+  else
+  {
+    m_ppcYuvReco[uiDepth]->copyPartToPartYuv( m_ppcYuvReco[uiDepth],0, pcCU->getWidth( 0 ),pcCU->getHeight( 0 ));
+  }
+}
+#endif
+
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecCu.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -91,5 +91,5 @@
   Void  init                    ( TDecEntropy* pcEntropyDecoder, TComTrQuant* pcTrQuant, TComPrediction* pcPrediction );
 #endif 
-
+  
   /// create internal buffers
   Void  create                  ( UInt uiMaxDepth, UInt uiMaxWidth, UInt uiMaxHeight );
@@ -106,8 +106,8 @@
 #if SVC_EXTENSION
   TDecTop*   getLayerDec        ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }
-#endif
 #if INTRA_BL
   Void  setBaseRecPic           ( TComPicYuv* p ) { m_pcPicYuvRecBase = p; }
 #endif 
+#endif
 protected:
   
@@ -115,9 +115,9 @@
   Void xFinishDecodeCU          ( TComDataCU* pcCU,                       UInt uiAbsPartIdx, UInt uiDepth, UInt &ruiIsLast);
   Bool xDecodeSliceEnd          ( TComDataCU* pcCU,                       UInt uiAbsPartIdx, UInt uiDepth);
-  Void xDecompressCU            ( TComDataCU* pcCU, TComDataCU* pcCUCur,  UInt uiAbsPartIdx, UInt uiDepth );
+  Void xDecompressCU            ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   
-  Void xReconInter              ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+  Void xReconInter              ( TComDataCU* pcCU, UInt uiDepth );
   
-  Void  xReconIntraQT           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+  Void  xReconIntraQT           ( TComDataCU* pcCU, UInt uiDepth );
   Void  xIntraRecLumaBlk        ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv );
   Void  xIntraRecChromaBlk      ( TComDataCU* pcCU, UInt uiTrDepth, UInt uiAbsPartIdx, TComYuv* pcRecoYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, UInt uiChromaId );
@@ -126,5 +126,5 @@
 #endif
   
-  Void  xReconPCM               ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
+  Void  xReconPCM               ( TComDataCU* pcCU, UInt uiDepth );
 
   Void xDecodeInterTexture      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -138,5 +138,5 @@
   Bool getdQPFlag               ()                        { return m_bDecodeDQP;        }
   Void setdQPFlag               ( Bool b )                { m_bDecodeDQP = b;           }
-  Void xFillPCMBuffer           (TComDataCU* pCU, UInt absPartIdx, UInt depth);
+  Void xFillPCMBuffer           (TComDataCU* pCU, UInt depth);
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -46,5 +46,4 @@
 }
 
-#include "TLibCommon/TComAdaptiveLoopFilter.h"
 #include "TLibCommon/TComSampleAdaptiveOffset.h"
 
@@ -88,8 +87,8 @@
  * \returns Void
  */
-Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth )
+Void TDecEntropy::decodeMergeIndex( TComDataCU* pcCU, UInt uiPartIdx, UInt uiAbsPartIdx, UInt uiDepth )
 {
   UInt uiMergeIndex = 0;
-  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex, uiAbsPartIdx, uiDepth );
+  m_pcEntropyDecoderIf->parseMergeIndex( pcCU, uiMergeIndex );
   pcCU->setMergeIndexSubParts( uiMergeIndex, uiAbsPartIdx, uiPartIdx, uiDepth );
 }
@@ -178,5 +177,5 @@
   }
   Int numValidMergeCand = 0;
-  bool isMerged = false;
+  Bool isMerged = false;
 
   pcSubCU->copyInterPredInfoFrom( pcCU, uiAbsPartIdx, REF_PIC_LIST_0 );
@@ -187,7 +186,7 @@
     if ( pcCU->getMergeFlag( uiSubPartIdx ) )
     {
-      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, ePartSize, uhInterDirNeighbours, cMvFieldNeighbours, uiDepth );
+      decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
       UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
-#if REF_IDX_FRAMEWORK  // HM bug fix
+#if 0 //REF_IDX_FRAMEWORK  // HM bug fix
       if(uiPartIdx)
       {
@@ -204,5 +203,5 @@
         if ( !isMerged )
         {
-          pcSubCU->getInterMergeCandidates( 0, 0, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
+          pcSubCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
           isMerged = true;
         }
@@ -212,5 +211,5 @@
       {
         uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
-        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, uiDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
+        pcSubCU->getInterMergeCandidates( uiSubPartIdx-uiAbsPartIdx, uiPartIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, uiMergeIndex );
       }
       pcCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeIndex], uiSubPartIdx, uiPartIdx, uiDepth );
@@ -268,5 +267,5 @@
   else
   {
-    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx, uiDepth );
+    m_pcEntropyDecoderIf->parseInterDir( pcCU, uiInterDir, uiAbsPartIdx );
   }
 
@@ -281,5 +280,5 @@
   if ( pcCU->getSlice()->getNumRefIdx( eRefList ) > 1 && iParseRefFrmIdx )
   {
-    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, uiAbsPartIdx, uiDepth, eRefList );
+    m_pcEntropyDecoderIf->parseRefFrmIdx( pcCU, iRefFrmIdx, eRefList );
   }
   else if ( !iParseRefFrmIdx )
@@ -326,9 +325,5 @@
   cMv = cZeroMv;
 
-#if !SPS_AMVP_CLEANUP
-  if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) && (pcSubCU->getAMVPMode(uiPartAddr) == AM_EXPL) )
-#else
   if ( (pcSubCU->getInterDir(uiPartAddr) & ( 1 << eRefList )) )
-#endif
   {
     m_pcEntropyDecoderIf->parseMVPIdx( iMVPIdx );
@@ -339,5 +334,5 @@
   if ( iRefIdx >= 0 )
   {
-    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, iRefIdx, cMv);
+    m_pcPrediction->getMvPredAMVP( pcSubCU, uiPartIdx, uiPartAddr, eRefList, cMv);
     cMv += pcSubCUMvField->getMvd( uiPartAddr );
   }
@@ -347,5 +342,5 @@
 }
 
-Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, Bool& bCodeDQP)
+Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
 {
   UInt uiSubdiv;
@@ -388,9 +383,5 @@
   {
     assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
-#if TRANS_SPLIT_FLAG_CTX_REDUCTION
     m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
-#else
-    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, uiDepth );
-#endif
   }
   
@@ -431,6 +422,4 @@
     const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (uiDepth << 1);
     const UInt uiStartAbsPartIdx = uiAbsPartIdx;
-    UInt uiLumaTrMode, uiChromaTrMode;
-    pcCU->convertTransIdx( uiStartAbsPartIdx, uiTrDepth+1, uiLumaTrMode, uiChromaTrMode );
     UInt uiYCbf = 0;
     UInt uiUCbf = 0;
@@ -439,24 +428,17 @@
     for( Int i = 0; i < 4; i++ )
     {
-#if REMOVE_NSQT
-      UInt nsAddr = uiAbsPartIdx;
-#else
-      UInt nsAddr = 0;
-      nsAddr = pcCU->getNSAbsPartIdx( uiLog2TrafoSize-1, uiAbsPartIdx, absTUPartIdx, i, uiTrDepth+1 );
-#endif
-      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, nsAddr, uiDepth, width, height, uiTrIdx, i, bCodeDQP );
-      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode );
-      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiChromaTrMode );
-      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiChromaTrMode );
+      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
+      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
+      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
+      uiVCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth+1 );
       uiAbsPartIdx += uiQPartNum;
       offsetLuma += size;  offsetChroma += (size>>2);
     }
     
-    pcCU->convertTransIdx( uiStartAbsPartIdx, uiTrDepth, uiLumaTrMode, uiChromaTrMode );
     for( UInt ui = 0; ui < 4 * uiQPartNum; ++ui )
     {
-      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiLumaTrMode;
-      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiChromaTrMode;
-      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiChromaTrMode;
+      pcCU->getCbf( TEXT_LUMA     )[uiStartAbsPartIdx + ui] |= uiYCbf << uiTrDepth;
+      pcCU->getCbf( TEXT_CHROMA_U )[uiStartAbsPartIdx + ui] |= uiUCbf << uiTrDepth;
+      pcCU->getCbf( TEXT_CHROMA_V )[uiStartAbsPartIdx + ui] |= uiVCbf << uiTrDepth;
     }
   }
@@ -477,12 +459,4 @@
     }
     
-    UInt uiLumaTrMode, uiChromaTrMode;
-    pcCU->convertTransIdx( uiAbsPartIdx, uiTrDepth, uiLumaTrMode, uiChromaTrMode );
-#if !REMOVE_NSQT
-    if(pcCU->getPredictionMode( uiAbsPartIdx ) == MODE_INTER && pcCU->useNonSquarePU( uiAbsPartIdx ) )
-    {
-      pcCU->setNSQTIdxSubParts( uiLog2TrafoSize, uiAbsPartIdx, absTUPartIdx, uiLumaTrMode );
-    }
-#endif
     pcCU->setCbfSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiDepth );
 #if INTRA_BL
@@ -496,9 +470,9 @@
 #endif 
     {
-      pcCU->setCbfSubParts( 1 << uiLumaTrMode, TEXT_LUMA, uiAbsPartIdx, uiDepth );
+      pcCU->setCbfSubParts( 1 << uiTrDepth, TEXT_LUMA, uiAbsPartIdx, uiDepth );
     }
     else
     {
-      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiLumaTrMode, uiDepth );
+      m_pcEntropyDecoderIf->parseQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrDepth, uiDepth );
     }
 
@@ -533,7 +507,4 @@
       Int trWidth = width;
       Int trHeight = height;
-#if !REMOVE_NSQT
-      pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
-#endif
       m_pcEntropyDecoderIf->parseCoeffNxN( pcCU, (pcCU->getCoeffY()+offsetLuma), uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA );
     }
@@ -542,7 +513,4 @@
       Int trWidth = width >> 1;
       Int trHeight = height >> 1;
-#if !REMOVE_NSQT
-      pcCU->getNSQTSize( uiTrIdx, uiAbsPartIdx, trWidth, trHeight );
-#endif
       if( cbfU )
       {
@@ -561,7 +529,4 @@
         Int trWidth = width;
         Int trHeight = height;
-#if !REMOVE_NSQT
-        pcCU->getNSQTSize( uiTrIdx - 1, uiAbsPartIdx, trWidth, trHeight );
-#endif
         if( cbfU )
         {
@@ -613,5 +578,5 @@
     if( !( pcCU->getPartitionSize( uiAbsPartIdx) == SIZE_2Nx2N && pcCU->getMergeFlag( uiAbsPartIdx ) ) )
     {
-      m_pcEntropyDecoderIf->parseQtRootCbf( pcCU, uiAbsPartIdx, uiDepth, uiQtRootCbf );
+      m_pcEntropyDecoderIf->parseQtRootCbf( uiAbsPartIdx, uiQtRootCbf );
     }
     if ( !uiQtRootCbf )
@@ -619,12 +584,9 @@
       pcCU->setCbfSubParts( 0, 0, 0, uiAbsPartIdx, uiDepth );
       pcCU->setTrIdxSubParts( 0 , uiAbsPartIdx, uiDepth );
-#if !REMOVE_NSQT
-      pcCU->setNSQTIdxSubParts( uiAbsPartIdx, uiDepth );
-#endif
       return;
     }
     
   }
-  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, 0, bCodeDQP );
+  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
 }
 
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -44,10 +44,8 @@
 #include "TLibCommon/TComPic.h"
 #include "TLibCommon/TComPrediction.h"
-#include "TLibCommon/TComAdaptiveLoopFilter.h"
 #include "TLibCommon/TComSampleAdaptiveOffset.h"
 
 class TDecSbac;
 class TDecCavlc;
-class SEImessages;
 class ParameterSetManagerDecoder;
 
@@ -67,11 +65,7 @@
   virtual Void  setBitstream          ( TComInputBitstream* p )  = 0;
 
-  virtual Void  decodeFlush()                                                                      = 0;
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
   virtual Void  parseSPS                  ( TComSPS* pcSPS )                                      = 0;
   virtual Void  parsePPS                  ( TComPPS* pcPPS )                                      = 0;
-#if !REMOVE_APS
-  virtual Void  parseAPS                  ( TComAPS* pAPS  )                                      = 0;
-#endif
 
   virtual Void parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)       = 0;
@@ -86,5 +80,5 @@
   virtual Void parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   virtual Void parseMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) = 0;
-  virtual Void parseMergeIndex    ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
+  virtual Void parseMergeIndex    ( TComDataCU* pcCU, UInt& ruiMergeIndex ) = 0;
   virtual Void parsePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   virtual Void parsePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
@@ -94,11 +88,11 @@
   virtual Void parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
   
-  virtual Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
-  virtual Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) = 0;
+  virtual Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx ) = 0;
+  virtual Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList ) = 0;
   virtual Void parseMvd           ( TComDataCU* pcCU, UInt uiAbsPartAddr, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) = 0;
   
   virtual Void parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) = 0;
   virtual Void parseQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) = 0;
-  virtual Void parseQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) = 0;
+  virtual Void parseQtRootCbf     ( UInt uiAbsPartIdx, UInt& uiQtRootCbf ) = 0;
   
   virtual Void parseDeltaQP       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
@@ -112,11 +106,5 @@
   virtual Void parseIntraBLFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) = 0;
 #endif
-#if !REMOVE_FGS
-  /// set slice granularity
-  virtual Void setSliceGranularity(Int iSliceGranularity) = 0;
 
-  /// get slice granularity
-  virtual Int  getSliceGranularity()                      = 0;
-#endif
   virtual Void updateContextTables( SliceType eSliceType, Int iQp ) = 0;
   
@@ -147,8 +135,5 @@
   Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
   Void    decodeSPS                   ( TComSPS* pcSPS     )    { m_pcEntropyDecoderIf->parseSPS(pcSPS);                    }
-  Void    decodePPS                   ( TComPPS* pcPPS, ParameterSetManagerDecoder *parameterSet    )    { m_pcEntropyDecoderIf->parsePPS(pcPPS);                    }
-#if !REMOVE_APS
-  Void    decodeAPS                   ( TComAPS* pAPS      )    { m_pcEntropyDecoderIf->parseAPS(pAPS);}
-#endif
+  Void    decodePPS                   ( TComPPS* pcPPS )    { m_pcEntropyDecoderIf->parsePPS(pcPPS);                    }
   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager);         }
 
@@ -162,5 +147,5 @@
   Void decodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void decodeMergeFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
-  Void decodeMergeIndex        ( TComDataCU* pcSubCU, UInt uiPartIdx, UInt uiPartAddr, PartSize eCUMode, UChar* puhInterDirNeighbours, TComMvField* pcMvFieldNeighbours, UInt uiDepth );
+  Void decodeMergeIndex        ( TComDataCU* pcSubCU, UInt uiPartIdx, UInt uiPartAddr, UInt uiDepth );
   Void decodePredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void decodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -182,16 +167,9 @@
   
 private:
-  Void xDecodeTransform        ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, Bool& bCodeDQP );
+  Void xDecodeTransform        ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP );
 
 public:
   Void decodeCoeff             ( TComDataCU* pcCU                 , UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP );
   
-#if !REMOVE_FGS
-  /// set slice granularity
-  Void setSliceGranularity (Int iSliceGranularity) {m_pcEntropyDecoderIf->setSliceGranularity(iSliceGranularity);}
-#endif
-  
-  Void decodeFlush() { m_pcEntropyDecoderIf->decodeFlush(); }
-
 };// END CLASS DEFINITION TDecEntropy
 
Index: trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -36,6 +36,4 @@
 */
 
-extern bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem
-
 #include "TDecGop.h"
 #include "TDecCAVLC.h"
@@ -51,7 +49,9 @@
 #include <time.h>
 
+extern Bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem
+
 //! \ingroup TLibDecoder
 //! \{
-static void calcAndPrintHashStatus(TComPicYuv& pic, const SEImessages* seis);
+static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
 // ====================================================================================================================
 // Constructor / destructor / initialization / destroy
@@ -60,5 +60,4 @@
 TDecGop::TDecGop()
 {
-  m_iGopSize = 0;
   m_dDecTime = 0;
   m_pcSbacDecoders = NULL;
@@ -97,7 +96,4 @@
                    TDecSlice*              pcSliceDecoder, 
                    TComLoopFilter*         pcLoopFilter,
-#if !REMOVE_ALF
-                   TComAdaptiveLoopFilter* pcAdaptiveLoopFilter,
-#endif
                    TComSampleAdaptiveOffset* pcSAO
                    )
@@ -109,7 +105,4 @@
   m_pcSliceDecoder        = pcSliceDecoder;
   m_pcLoopFilter          = pcLoopFilter;
-#if !REMOVE_ALF
-  m_pcAdaptiveLoopFilter  = pcAdaptiveLoopFilter;
-#endif
   m_pcSAO  = pcSAO;
 #if SVC_EXTENSION   
@@ -136,5 +129,5 @@
   long iBeforeTime = clock();
   
-  UInt uiStartCUAddr   = pcSlice->getDependentSliceCurStartCUAddr();
+  UInt uiStartCUAddr   = pcSlice->getSliceSegmentCurStartCUAddr();
 
   UInt uiSliceStartCuAddr = pcSlice->getSliceCurStartCUAddr();
@@ -147,9 +140,5 @@
   m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
 
-#if TILES_WPP_ENTROPYSLICES_FLAGS
   UInt uiNumSubstreams = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcSlice->getNumEntryPointOffsets()+1 : pcSlice->getPPS()->getNumSubstreams();
-#else
-  UInt uiNumSubstreams = pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc() == 2 ? pcSlice->getNumEntryPointOffsets()+1 : pcSlice->getPPS()->getNumSubstreams();
-#endif
 
   // init each couple {EntropyDecoder, Substream}
@@ -178,16 +167,7 @@
   {
     m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());
-#if !REMOVE_ALF
-    if(pcSlice->getSPS()->getUseALF())
-    {
-      for(Int compIdx=0; compIdx < 3; compIdx++)
-      {
-        m_sliceAlfEnabled[compIdx].push_back(  pcSlice->getAlfEnabledFlag(compIdx) );
-      }
-    }
-#endif
   }
   m_pcSbacDecoders[0].load(m_pcSbacDecoder);
-  m_pcSliceDecoder->decompressSlice( pcBitstream, ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
+  m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
   m_pcEntropyDecoder->setBitstream(  ppcSubstreams[uiNumSubstreams-1] );
   // deallocate all created substreams, including internal buffers.
@@ -201,5 +181,5 @@
   delete[] m_pcBinCABACs; m_pcBinCABACs = NULL;
 
-  m_dDecTime += (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
+  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
 }
 
@@ -213,73 +193,28 @@
   // deblocking filter
   Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
-  m_pcLoopFilter->setCfg(pcSlice->getPPS()->getDeblockingFilterControlPresentFlag(), pcSlice->getDeblockingFilterDisable(), pcSlice->getDeblockingFilterBetaOffsetDiv2(), pcSlice->getDeblockingFilterTcOffsetDiv2(), bLFCrossTileBoundary);
+  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
   m_pcLoopFilter->loopFilterPic( rpcPic );
 
-  pcSlice = rpcPic->getSlice(0);
-#if REMOVE_ALF
   if(pcSlice->getSPS()->getUseSAO())
-#else
-  if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF())
-#endif
-  {
-#if !REMOVE_FGS
-    Int sliceGranularity = pcSlice->getPPS()->getSliceGranularity();
-#endif
+  {
     m_sliceStartCUAddress.push_back(rpcPic->getNumCUsInFrame()* rpcPic->getNumPartInCU());
-#if REMOVE_FGS
     rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, 0, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary);
-#else
-    rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, sliceGranularity, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary);
-#endif
   }
 
   if( pcSlice->getSPS()->getUseSAO() )
   {
-#if !SAO_LUM_CHROMA_ONOFF_FLAGS
-    if(pcSlice->getSaoEnabledFlag())
-#else
-    if(pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
-#endif
-    {
-#if REMOVE_APS
+    {
       SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
-#else
-      SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
-#endif
       saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag();
-#if SAO_TYPE_SHARING
       saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma();
-#else
-      saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagCb();
-      saoParam->bSaoFlag[2] = pcSlice->getSaoEnabledFlagCr();
-#endif
       m_pcSAO->setSaoLcuBasedOptimization(1);
-      m_pcSAO->createPicSaoInfo(rpcPic, (Int) m_sliceStartCUAddress.size() - 1);
-      m_pcSAO->SAOProcess(rpcPic, saoParam);
-#if !REMOVE_ALF
-      m_pcAdaptiveLoopFilter->PCMLFDisableProcess(rpcPic);
-#else
+      m_pcSAO->createPicSaoInfo(rpcPic);
+      m_pcSAO->SAOProcess(saoParam);
       m_pcSAO->PCMLFDisableProcess(rpcPic);
-#endif
       m_pcSAO->destroyPicSaoInfo();
     }
   }
 
-#if !REMOVE_ALF
-  // adaptive loop filter
-  if( pcSlice->getSPS()->getUseALF() )
-  {
-    m_pcAdaptiveLoopFilter->createPicAlfInfo(rpcPic, (Int) m_sliceStartCUAddress.size()-1);
-    m_pcAdaptiveLoopFilter->ALFProcess(rpcPic, pcSlice->getAPS()->getAlfParam(), m_sliceAlfEnabled);
-    m_pcAdaptiveLoopFilter->PCMLFDisableProcess(rpcPic);
-    m_pcAdaptiveLoopFilter->destroyPicAlfInfo();
-  }
-#endif
-
-#if REMOVE_ALF
   if(pcSlice->getSPS()->getUseSAO())
-#else
-  if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF())
-#endif
   {
     rpcPic->destroyNonDBFilterInfo();
@@ -287,6 +222,4 @@
 
   rpcPic->compressMotion(); 
-
-
   Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
   if (!pcSlice->isReferenced()) c += 32;
@@ -305,5 +238,5 @@
                                                     pcSlice->getSliceQp() );
 #endif
-  m_dDecTime += (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
+  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
   printf ("[DT %6.3f] ", m_dDecTime );
   m_dDecTime  = 0;
@@ -320,20 +253,16 @@
   if (m_decodedPictureHashSEIEnabled)
   {
-    calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), rpcPic->getSEIs());
-  }
-
-#if FIXED_ROUNDING_FRAME_MEMORY
-  rpcPic->getPicYuvRec()->xFixedRoundingPic();
-#endif
+    SEIMessages pictureHashes = getSeisByType(rpcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
+    const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
+    if (pictureHashes.size() > 1)
+    {
+      printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
+    }
+    calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), hash);
+  }
 
   rpcPic->setOutputMark(true);
   rpcPic->setReconMark(true);
   m_sliceStartCUAddress.clear();
-#if !REMOVE_ALF
-  for(Int compIdx=0; compIdx < 3; compIdx++)
-  {
-    m_sliceAlfEnabled[compIdx].clear();
-  }
-#endif
   m_LFCrossSliceBoundaryFlag.clear();
 }
@@ -350,14 +279,14 @@
  *            unk         - no SEI message was available for comparison
  */
-static void calcAndPrintHashStatus(TComPicYuv& pic, const SEImessages* seis)
+static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
 {
   /* calculate MD5sum for entire reconstructed picture */
-  unsigned char recon_digest[3][16];
-  int numChar=0;
-  const char* hashType = "\0";
-
-  if (seis && seis->picture_digest)
-  {
-    switch (seis->picture_digest->method)
+  UChar recon_digest[3][16];
+  Int numChar=0;
+  const Char* hashType = "\0";
+
+  if (pictureHashSEI)
+  {
+    switch (pictureHashSEI->method)
     {
     case SEIDecodedPictureHash::MD5:
@@ -390,15 +319,15 @@
 
   /* compare digest against received version */
-  const char* ok = "(unk)";
-  bool mismatch = false;
-
-  if (seis && seis->picture_digest)
+  const Char* ok = "(unk)";
+  Bool mismatch = false;
+
+  if (pictureHashSEI)
   {
     ok = "(OK)";
-    for(int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
-    {
-      for (unsigned i = 0; i < numChar; i++)
-      {
-        if (recon_digest[yuvIdx][i] != seis->picture_digest->digest[yuvIdx][i])
+    for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
+    {
+      for (UInt i = 0; i < numChar; i++)
+      {
+        if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i])
         {
           ok = "(***ERROR***)";
@@ -414,5 +343,5 @@
   {
     g_md5_mismatch = true;
-    printf("[rx%s:%s] ", hashType, digestToString(seis->picture_digest->digest, numChar));
+    printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar));
   }
 }
Index: trunk/source/Lib/TLibDecoder/TDecGop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecGop.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -49,5 +49,4 @@
 #include "TLibCommon/TComPic.h"
 #include "TLibCommon/TComLoopFilter.h"
-#include "TLibCommon/TComAdaptiveLoopFilter.h"
 #include "TLibCommon/TComSampleAdaptiveOffset.h"
 
@@ -68,5 +67,4 @@
 {
 private:
-  Int                   m_iGopSize;
   TComList<TComPic*>    m_cListPic;         //  Dynamic buffer
   
@@ -81,18 +79,11 @@
   TComLoopFilter*       m_pcLoopFilter;
   
-#if !REMOVE_ALF
-  // Adaptive Loop filter
-  TComAdaptiveLoopFilter*       m_pcAdaptiveLoopFilter;
-#endif
   TComSampleAdaptiveOffset*     m_pcSAO;
   Double                m_dDecTime;
   Int                   m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
 
-  //! list that contains the CU address of each slice plus the end address
+  //! list that contains the CU address of each slice plus the end address 
   std::vector<Int> m_sliceStartCUAddress;
   std::vector<Bool> m_LFCrossSliceBoundaryFlag;
-#if !REMOVE_ALF
-  std::vector<Bool> m_sliceAlfEnabled[3];
-#endif
 
 #if SVC_EXTENSION
@@ -115,7 +106,4 @@
                  TDecSlice*              pcSliceDecoder, 
                  TComLoopFilter*         pcLoopFilter,
-#if !REMOVE_ALF
-                 TComAdaptiveLoopFilter* pcAdaptiveLoopFilter,
-#endif
                  TComSampleAdaptiveOffset* pcSAO
                  );
@@ -126,8 +114,6 @@
 #endif
   Void  destroy ();
-//  Void  decompressGop(TComInputBitstream* pcBitstream, TComPic*& rpcPic, Bool bExecuteDeblockAndAlf );
   Void  decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic );
   Void  filterPicture  (TComPic*& rpcPic );
-  Void  setGopSize( Int i) { m_iGopSize = i; }
 
   void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
Index: trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -56,5 +56,4 @@
 , m_cCUPartSizeSCModel        ( 1,             1,               NUM_PART_SIZE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cCUPredModeSCModel        ( 1,             1,               NUM_PRED_MODE_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cCUAlfCtrlFlagSCModel     ( 1,             1,               NUM_ALF_CTRL_FLAG_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cCUIntraPredSCModel       ( 1,             1,               NUM_ADI_CTX                   , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cCUChromaPredSCModel      ( 1,             1,               NUM_CHROMA_PRED_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
@@ -73,28 +72,14 @@
 , m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cALFFlagSCModel           ( 1,             1,               NUM_ALF_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cALFUvlcSCModel           ( 1,             1,               NUM_ALF_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cALFSvlcSCModel           ( 1,             1,               NUM_ALF_SVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
 , m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
-#if !SAO_ABS_BY_PASS
-, m_cSaoUvlcSCModel           ( 1,             1,               NUM_SAO_UVLC_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
-#endif
-#if SAO_MERGE_ONE_CTX
 , m_cSaoMergeSCModel      ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
-#else
-, m_cSaoMergeLeftSCModel      ( 1,             1,               NUM_SAO_MERGE_LEFT_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cSaoMergeUpSCModel        ( 1,             1,               NUM_SAO_MERGE_UP_FLAG_CTX     , m_contextModels + m_numContextModels, m_numContextModels)
-#endif
+, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
+, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
+, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
 #if INTRA_BL
 , m_cIntraBLPredFlagSCModel   (1,              1,               NUM_INTRA_BL_PRED_CTX         , m_contextModels + m_numContextModels, m_numContextModels)
 #endif
-, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
-, m_cTransformSkipSCModel     ( 1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX    , m_contextModels + m_numContextModels, m_numContextModels)
-, m_CUTransquantBypassFlagSCModel( 1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
 {
   assert( m_numContextModels <= MAX_NUM_CTX_MOD );
-#if !REMOVE_FGS
-  m_iSliceGranularity = 0;
-#endif
 }
 
@@ -131,5 +116,4 @@
   m_cCUMergeFlagExtSCModel.initBuffer    ( sliceType, qp, (UChar*)INIT_MERGE_FLAG_EXT );
   m_cCUMergeIdxExtSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_MERGE_IDX_EXT );
-  m_cCUAlfCtrlFlagSCModel.initBuffer     ( sliceType, qp, (UChar*)INIT_ALF_CTRL_FLAG );
   m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
   m_cCUAMPSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CU_AMP_POS );
@@ -150,16 +134,5 @@
   m_cCUAbsSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_ABS_FLAG );
   m_cMVPIdxSCModel.initBuffer            ( sliceType, qp, (UChar*)INIT_MVP_IDX );
-  m_cALFFlagSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_FLAG );
-  m_cALFUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_UVLC );
-  m_cALFSvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_ALF_SVLC );
-#if !SAO_ABS_BY_PASS
-  m_cSaoUvlcSCModel.initBuffer           ( sliceType, qp, (UChar*)INIT_SAO_UVLC );
-#endif
-#if SAO_MERGE_ONE_CTX
   m_cSaoMergeSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_FLAG );
-#else
-  m_cSaoMergeLeftSCModel.initBuffer      ( sliceType, qp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG );
-  m_cSaoMergeUpSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
-#endif
   m_cSaoTypeIdxSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_SAO_TYPE_IDX );
 
@@ -191,5 +164,4 @@
   m_cCUMergeFlagExtSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_MERGE_FLAG_EXT );
   m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT );
-  m_cCUAlfCtrlFlagSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_ALF_CTRL_FLAG );
   m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
   m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
@@ -210,16 +182,5 @@
   m_cCUAbsSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_ABS_FLAG );
   m_cMVPIdxSCModel.initBuffer            ( eSliceType, iQp, (UChar*)INIT_MVP_IDX );
-  m_cALFFlagSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_FLAG );
-  m_cALFUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_UVLC );
-  m_cALFSvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_ALF_SVLC );
-#if !SAO_ABS_BY_PASS
-  m_cSaoUvlcSCModel.initBuffer           ( eSliceType, iQp, (UChar*)INIT_SAO_UVLC );
-#endif
-#if SAO_MERGE_ONE_CTX
   m_cSaoMergeSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_FLAG );
-#else
-  m_cSaoMergeLeftSCModel.initBuffer      ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_LEFT_FLAG );
-  m_cSaoMergeUpSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_MERGE_UP_FLAG );
-#endif
   m_cSaoTypeIdxSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_SAO_TYPE_IDX );
   m_cCUTransSubdivFlagSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANS_SUBDIV_FLAG );
@@ -334,9 +295,5 @@
   prefix -= codeWord;
   codeWord=0;
-#if COEF_REMAIN_BIN_REDUCTION
   if (prefix < COEF_REMAIN_BIN_REDUCTION )
-#else
-  if (prefix < 8 )
-#endif
   {
     m_pcTDecBinIf->decodeBinsEP(codeWord,rParam);
@@ -345,11 +302,6 @@
   else
   {
-#if COEF_REMAIN_BIN_REDUCTION
     m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-COEF_REMAIN_BIN_REDUCTION+rParam);
     rSymbol = (((1<<(prefix-COEF_REMAIN_BIN_REDUCTION))+COEF_REMAIN_BIN_REDUCTION-1)<<rParam)+codeWord;
-#else
-    m_pcTDecBinIf->decodeBinsEP(codeWord,prefix-8+rParam);
-    rSymbol = (((1<<(prefix-8))+8-1)<<rParam)+codeWord;
-#endif
   }
 }
@@ -366,13 +318,6 @@
 {
   UInt uiSymbol;
-  Int numSubseqIPCM = 0;
   Bool readPCMSampleFlag = false;
 
-  if(pcCU->getNumSucIPCM() > 0) 
-  {
-    readPCMSampleFlag = true;
-  }
-  else
-  {
     m_pcTDecBinIf->decodeBinTrm(uiSymbol);
 
@@ -380,9 +325,6 @@
     {
       readPCMSampleFlag = true;
-      m_pcTDecBinIf->decodeNumSubseqIPCM(numSubseqIPCM);
-      pcCU->setNumSucIPCM(numSubseqIPCM + 1);
       m_pcTDecBinIf->decodePCMAlignBits();
     }
-  }
 
   if (readPCMSampleFlag == true)
@@ -453,9 +395,5 @@
     }
 
-    pcCU->setNumSucIPCM( pcCU->getNumSucIPCM() - 1);
-    if(pcCU->getNumSucIPCM() == 0)
-    {
       m_pcTDecBinIf->resetBac();
-    }
   }
 }
@@ -494,7 +432,5 @@
   if( uiSymbol )
   {
-#if SKIP_FLAG
     pcCU->setSkipFlagSubParts( true,        uiAbsPartIdx, uiDepth );
-#endif
     pcCU->setPredModeSubParts( MODE_INTER,  uiAbsPartIdx, uiDepth );
     pcCU->setPartSizeSubParts( SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
@@ -555,5 +491,5 @@
 }
 
-Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecSbac::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex )
 {
   UInt uiUnaryIdx = 0;
@@ -783,20 +719,4 @@
   else 
   {
-#if !REMOVE_LMCHROMA
-    if( pcCU->getSlice()->getSPS()->getUseLMChroma() )
-    {
-      m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 1 ) );
-    }
-    else
-    {
-      uiSymbol = 1;
-    }
-
-    if( uiSymbol == 0 )
-    {
-      uiSymbol = LM_CHROMA_IDX;
-    } 
-    else
-#endif
     {
       UInt uiIPredMode;
@@ -811,18 +731,14 @@
 }
 
-Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth )
+Void TDecSbac::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx )
 {
   UInt uiSymbol;
   const UInt uiCtx = pcCU->getCtxInterDir( uiAbsPartIdx );
   ContextModel *pCtx = m_cCUInterDirSCModel.get( 0 );
-#if DISALLOW_BIPRED_IN_8x4_4x8PUS
   uiSymbol = 0;
   if (pcCU->getPartitionSize(uiAbsPartIdx) == SIZE_2Nx2N || pcCU->getHeight(uiAbsPartIdx) != 8 )
   {
-#endif
     m_pcTDecBinIf->decodeBin( uiSymbol, *( pCtx + uiCtx ) );
-#if DISALLOW_BIPRED_IN_8x4_4x8PUS
-  }
-#endif
+  }
 
   if( uiSymbol )
@@ -841,5 +757,5 @@
 }
 
-Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList )
+Void TDecSbac::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList )
 {
   UInt uiSymbol;
@@ -850,5 +766,4 @@
     if( uiSymbol )
     {
-#if REF_IDX_BYPASS
       UInt uiRefNum = pcCU->getSlice()->getNumRefIdx( eRefList ) - 2;
       pCtx++;
@@ -870,8 +785,4 @@
       }
       uiSymbol = ui + 1;
-#else
-      xReadUnaryMaxSymbol( uiSymbol, pCtx + 1, 1, pcCU->getSlice()->getNumRefIdx( eRefList )-2 );
-      uiSymbol++;
-#endif
     }
     riRefFrmIdx = uiSymbol;
@@ -958,5 +869,5 @@
 }
 
-Void TDecSbac::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf )
+Void TDecSbac::parseQtRootCbf( UInt uiAbsPartIdx, UInt& uiQtRootCbf )
 {
   UInt uiSymbol;
@@ -982,5 +893,4 @@
   Int  iDQp;
   
-#if CU_DQP_TU_EG
   UInt uiSymbol;
 
@@ -1010,31 +920,4 @@
     qp = pcCU->getRefQP(uiAbsPartIdx);
   }
-#else
-  m_pcTDecBinIf->decodeBin( uiDQp, m_cCUDeltaQpSCModel.get( 0, 0, 0 ) );
-  
-  if ( uiDQp == 0 )
-  {
-    qp = pcCU->getRefQP(uiAbsPartIdx);
-  }
-  else
-  {
-    UInt uiSign;
-    Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
-    m_pcTDecBinIf->decodeBinEP(uiSign);
-
-    UInt uiMaxAbsDQpMinus1 = 24 + (qpBdOffsetY/2) + (uiSign);
-    UInt uiAbsDQpMinus1;
-    xReadUnaryMaxSymbol (uiAbsDQpMinus1,  &m_cCUDeltaQpSCModel.get( 0, 0, 1 ), 1, uiMaxAbsDQpMinus1);
-
-    iDQp = uiAbsDQpMinus1 + 1;
-
-    if(uiSign)
-    {
-      iDQp = -iDQp;
-    }
-
-    qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+qpBdOffsetY)) - qpBdOffsetY;
-  }
-#endif
   pcCU->setQPSubParts(qp, uiAbsPartIdx, uiDepth);  
   pcCU->setCodedQP(qp);
@@ -1044,5 +927,5 @@
 {
   UInt uiSymbol;
-  const UInt uiCtx = pcCU->getCtxQtCbf( uiAbsPartIdx, eType, uiTrDepth );
+  const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
   
@@ -1068,10 +951,4 @@
     return;
   }
-#if !INTER_TRANSFORMSKIP
-  if(!pcCU->isIntra(uiAbsPartIdx))
-  {
-    return;
-  }
-#endif
   if(width != 4 || height != 4)
   {
@@ -1205,9 +1082,5 @@
     uiHeight = pcCU->getSlice()->getSPS()->getMaxTrSize();
   }
-#if PPS_TS_FLAG
   if(pcCU->getSlice()->getPPS()->getUseTransformSkip())
-#else
-  if(pcCU->getSlice()->getSPS()->getUseTransformSkip())
-#endif
   {
     parseTransformSkipFlags( pcCU, uiAbsPartIdx, uiWidth, uiHeight, uiDepth, eTType);
@@ -1221,10 +1094,4 @@
   const UInt  uiMaxNumCoeffM1   = uiMaxNumCoeff - 1;
   UInt uiScanIdx = pcCU->getCoefScanIdx(uiAbsPartIdx, uiWidth, eTType==TEXT_LUMA, pcCU->isIntra(uiAbsPartIdx));
-  int blockType = uiLog2BlockSize;
-  if (uiWidth != uiHeight)
-  {
-    uiScanIdx = SCAN_DIAG;
-    blockType = 4;
-  }
   
   //===== decode last significant =====
@@ -1235,23 +1102,6 @@
 
   //===== decode significance flags =====
-  UInt uiScanPosLast   = uiBlkPosLast;
-  if (uiScanIdx == SCAN_ZIGZAG)
-  {
-    // Map zigzag to diagonal scan
-    uiScanIdx = SCAN_DIAG;
-  }
-#if REMOVE_NSQT
-  const UInt *scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
-#else
-  const UInt * scan;
-  if (uiWidth == uiHeight)
-  {
-    scan = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
-  }
-  else
-  {
-    scan = g_sigScanNSQT[ uiLog2BlockSize - 2 ];
-  }
-#endif
+  UInt uiScanPosLast = uiBlkPosLast;
+  const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
   for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
   {
@@ -1267,9 +1117,5 @@
 
   const Int  iLastScanSet      = uiScanPosLast >> LOG2_SCAN_SET_SIZE;
-#if REMOVE_NUM_GREATER1
   UInt c1 = 1;
-#else
-  UInt uiNumOne                = 0;
-#endif
   UInt uiGoRiceParam           = 0;
 
@@ -1289,7 +1135,4 @@
   const UInt uiNumBlkSide = uiWidth >> (MLS_CG_SIZE >> 1);
   const UInt * scanCG;
-#if !REMOVE_NSQT
-  if (uiWidth == uiHeight)
-#endif
   {
     scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize > 3 ? uiLog2BlockSize-2-1 : 0  ];    
@@ -1303,10 +1146,4 @@
     }
   }
-#if !REMOVE_NSQT
-  else
-  {
-    scanCG = g_sigCGScanNSQT[ uiLog2BlockSize - 2 ];
-  }
-#endif
   Int  iScanPosSig             = (Int) uiScanPosLast;
   for( Int iSubSet = iLastScanSet; iSubSet >= 0; iSubSet-- )
@@ -1332,11 +1169,4 @@
     Int iCGPosY   = iCGBlkPos / uiNumBlkSide;
     Int iCGPosX   = iCGBlkPos - (iCGPosY * uiNumBlkSide);
-#if !REMOVAL_8x2_2x8_CG
-    if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) )
-    {
-      iCGPosY = (uiScanIdx == SCAN_HOR ? iCGBlkPos : 0);
-      iCGPosX = (uiScanIdx == SCAN_VER ? iCGBlkPos : 0);
-    }
-#endif
     if( iSubSet == iLastScanSet || iSubSet == 0)
     {
@@ -1346,5 +1176,5 @@
     {
       UInt uiSigCoeffGroup;
-      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiScanIdx, uiWidth, uiHeight );
+      UInt uiCtxSig  = TComTrQuant::getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, iCGPosX, iCGPosY, uiWidth, uiHeight );
       m_pcTDecBinIf->decodeBin( uiSigCoeffGroup, baseCoeffGroupCtx[ uiCtxSig ] );
       uiSigCoeffGroupFlag[ iCGBlkPos ] = uiSigCoeffGroup;
@@ -1365,9 +1195,5 @@
         if( iScanPosSig > iSubPos || iSubSet == 0  || numNonZero )
         {
-#if REMOVAL_8x2_2x8_CG
-          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );
-#else
-          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );
-#endif
+          uiCtxSig  = TComTrQuant::getSigCtxInc( patternSigCtx, uiScanIdx, uiPosX, uiPosY, uiLog2BlockSize, eTType );
           m_pcTDecBinIf->decodeBin( uiSig, baseCtx[ uiCtxSig ] );
         }
@@ -1394,22 +1220,11 @@
       Bool signHidden = ( lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD );
       absSum = 0;
-#if !REMOVE_NUM_GREATER1
-      UInt c1 = 1;
-#endif
       UInt uiCtxSet    = (iSubSet > 0 && eTType==TEXT_LUMA) ? 2 : 0;
       UInt uiBin;
-#if REMOVE_NUM_GREATER1
       if( c1 == 0 )
-#else
-      if( uiNumOne > 0 )
-#endif
       {
         uiCtxSet++;
       }
-#if REMOVE_NUM_GREATER1
       c1 = 1;
-#else
-      uiNumOne       >>= 1;
-#endif
       ContextModel *baseCtxMod = ( eTType==TEXT_LUMA ) ? m_cCUOneSCModel.get( 0, 0 ) + 4 * uiCtxSet : m_cCUOneSCModel.get( 0, 0 ) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
       Int absCoeff[SCAN_SET_SIZE];
@@ -1480,7 +1295,4 @@
           {
             iFirstCoeff2 = 0;
-#if !REMOVE_NUM_GREATER1
-            uiNumOne++;
-#endif
           }
         }
@@ -1510,10 +1322,4 @@
       }
     }
-#if !REMOVE_NUM_GREATER1
-    else
-    {
-      uiNumOne >>= 1;
-    }
-#endif
   }
   
@@ -1532,9 +1338,5 @@
   UInt code;
   Int  i;
-#if SAO_ABS_BY_PASS
   m_pcTDecBinIf->decodeBinEP( code );
-#else
-  m_pcTDecBinIf->decodeBin( code, m_cSaoUvlcSCModel.get( 0, 0, 0 ) );
-#endif
   if ( code == 0 )
   {
@@ -1546,9 +1348,5 @@
   while (1)
   {
-#if SAO_ABS_BY_PASS
     m_pcTDecBinIf->decodeBinEP( code );
-#else
-    m_pcTDecBinIf->decodeBin( code, m_cSaoUvlcSCModel.get( 0, 0, 1 ) );
-#endif
     if ( code == 0 )
     {
@@ -1564,45 +1362,17 @@
   val = i;
 }
-#if SAO_TYPE_CODING
 Void TDecSbac::parseSaoUflc (UInt uiLength, UInt&  riVal)
 {
   m_pcTDecBinIf->decodeBinsEP ( riVal, uiLength );
 }
-#else
-Void TDecSbac::parseSaoUflc (UInt&  riVal)
-{
-  m_pcTDecBinIf->decodeBinsEP ( riVal, 5 );
-}
-#endif
-#if SAO_MERGE_ONE_CTX
 Void TDecSbac::parseSaoMerge (UInt&  ruiVal)
-#else
-Void TDecSbac::parseSaoMergeLeft (UInt&  ruiVal, UInt uiCompIdx)
-#endif
 {
   UInt uiCode;
-#if SAO_MERGE_ONE_CTX
   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeSCModel.get( 0, 0, 0 ) );
-#else
-#if SAO_SINGLE_MERGE
-  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, 0 ) );
-#else
-  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeLeftSCModel.get( 0, 0, uiCompIdx ) );
-#endif
-#endif
   ruiVal = (Int)uiCode;
 }
-#if !SAO_MERGE_ONE_CTX
-Void TDecSbac::parseSaoMergeUp (UInt&  ruiVal)
+Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
 {
   UInt uiCode;
-  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoMergeUpSCModel.get( 0, 0, 0 ) );
-  ruiVal = (Int)uiCode;
-}
-#endif
-Void TDecSbac::parseSaoTypeIdx (UInt&  ruiVal)
-{
-  UInt uiCode;
-#if SAO_TYPE_CODING
   m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
   if (uiCode == 0) 
@@ -1622,24 +1392,4 @@
     }
   }
-#else
-  Int  i;
-  m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
-  if ( uiCode == 0 )
-  {
-    ruiVal = 0;
-    return;
-  }
-  i=1;
-  while (1)
-  {
-    m_pcTDecBinIf->decodeBin( uiCode, m_cSaoTypeIdxSCModel.get( 0, 0, 1 ) );
-    if ( uiCode == 0 )
-    {
-      break;
-    }
-    i++;
-  }
-  ruiVal = i;
-#endif
 }
 
@@ -1651,16 +1401,5 @@
   if (psDst->typeIdx != -1)
   {
-#if SAO_TYPE_CODING
     psDst->subTypeIdx = psSrc->subTypeIdx ;
-#else
-    if (psDst->typeIdx == SAO_BO)
-    {
-      psDst->bandPosition = psSrc->bandPosition ;
-    }
-    else
-    {
-      psDst->bandPosition = 0;
-    }
-#endif
     psDst->length  = psSrc->length;
     for (i=0;i<psDst->length;i++)
@@ -1679,9 +1418,5 @@
 }
 
-#if SAO_TYPE_SHARING
 Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx)
-#else
-Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam)
-#endif
 {
   UInt uiSymbol;
@@ -1695,33 +1430,22 @@
   }; 
 
-#if SAO_TYPE_SHARING
-if (compIdx==2)
-{
-uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
-}
-else
-{
-parseSaoTypeIdx(uiSymbol);
-}
-#else
-  parseSaoTypeIdx(uiSymbol);
-#endif
+  if (compIdx==2)
+  {
+    uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
+  }
+  else
+  {
+    parseSaoTypeIdx(uiSymbol);
+  }
   psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
   if (uiSymbol)
   {
     psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
-#if FULL_NBIT
-    Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + (g_uiBitDepth-8)-5),5) );
-#else
-    Int offsetTh = 1 << ( min((Int)(g_uiBitDepth + g_uiBitIncrement-5),5) );
-#endif
+
+    Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
+    Int offsetTh = 1 << min(bitDepth - 5,5);
 
     if( psSaoLcuParam->typeIdx == SAO_BO )
     {
-#if !SAO_TYPE_CODING
-    // Parse Left Band Index
-    parseSaoUflc( uiSymbol );
-    psSaoLcuParam->bandPosition = uiSymbol;
-#endif
       for(Int i=0; i< psSaoLcuParam->length; i++)
       {
@@ -1740,8 +1464,6 @@
         }
       }
-#if SAO_TYPE_CODING
       parseSaoUflc(5, uiSymbol );
       psSaoLcuParam->subTypeIdx = uiSymbol;
-#endif
     }
     else if( psSaoLcuParam->typeIdx < 4 )
@@ -1751,6 +1473,4 @@
       parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
       parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
-#if SAO_TYPE_CODING
-#if SAO_TYPE_SHARING
      if (compIdx != 2)
      {
@@ -1759,10 +1479,4 @@
        psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
      }
-#else
-     parseSaoUflc(2, uiSymbol );
-     psSaoLcuParam->subTypeIdx = uiSymbol;
-     psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
-#endif
-#endif
    }
   }
@@ -1777,14 +1491,9 @@
   Int iAddr = pcCU->getAddr();
   UInt uiSymbol;
-#if SAO_SINGLE_MERGE
   for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
   {
     pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
     pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
-#if SAO_TYPE_CODING
     pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx     = 0;
-#else
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition   = 0;
-#endif
     pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        = -1;
     pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]     = 0;
@@ -1794,19 +1503,10 @@
 
   }
-#if SAO_TYPE_SHARING
  if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] )
-#else
- if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] || pSaoParam->bSaoFlag[2])
-#endif
   {
     if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
     {
-#if SAO_MERGE_ONE_CTX
       parseSaoMerge(uiSymbol); 
       pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol;  
-#else
-      parseSaoMergeLeft(uiSymbol, 0); 
-      pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol;   
-#endif
     }
     if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0)
@@ -1814,41 +1514,17 @@
       if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
       {
-#if SAO_MERGE_ONE_CTX
         parseSaoMerge(uiSymbol);
         pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
-#else
-        parseSaoMergeUp(uiSymbol);
-        pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
-#endif
-      }
-    }
-  }
-#endif
+      }
+    }
+  }
 
   for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
   {
-#if !SAO_SINGLE_MERGE
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition   = 0;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        = -1;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]     = 0;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]     = 0;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]     = 0;
-    pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]     = 0;
-#endif
-#if SAO_TYPE_SHARING
     if ((iCompIdx == 0  && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0  && pSaoParam->bSaoFlag[1]) )
-#else
-    if (pSaoParam->bSaoFlag[iCompIdx])
-#endif
     {
       if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
       {
-#if SAO_SINGLE_MERGE
         pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag;
-#else
-        parseSaoMergeLeft(uiSymbol,iCompIdx); pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = (Int)uiSymbol;
-#endif
       }
       else
@@ -1861,9 +1537,5 @@
         if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
         {
-#if SAO_SINGLE_MERGE
           pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag;
-#else
-          parseSaoMergeUp(uiSymbol);  pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = uiSymbol;
-#endif
         }
         else
@@ -1873,10 +1545,6 @@
         if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
         {
-#if SAO_TYPE_SHARING
           pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx;
           parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx);
-#else
-          parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]));
-#endif
         }
         else
@@ -1893,29 +1561,8 @@
     {
       pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1;
-#if SAO_TYPE_CODING
       pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0;
-#else
-      pSaoParam->saoLcuParam[iCompIdx][iAddr].bandPosition = 0;
-#endif
-    }
-  }
-}
-
-#if !REMOVE_ALF
-Void TDecSbac::parseAlfCtrlFlag (Int compIdx, UInt& code)
-{
-  UInt decodedSymbol;
-  m_pcTDecBinIf->decodeBin( decodedSymbol, m_cCUAlfCtrlFlagSCModel.get( 0, 0, 0 ) );
-  code = decodedSymbol;
-
-  DTRACE_CABAC_VL( g_nSymbolCounter++ )
-  DTRACE_CABAC_T( "parseAlfCtrlFlag()" )
-  DTRACE_CABAC_T( "\tsymbol=" )
-  DTRACE_CABAC_V( decodedSymbol )
-  DTRACE_CABAC_T( "\tcompIdx=" )
-  DTRACE_CABAC_V( compIdx )
-  DTRACE_CABAC_T( "\n" )
-}
-#endif
+    }
+  }
+}
 
 /**
@@ -1947,11 +1594,3 @@
   xCopyContextsFrom(pScr);
 }
-
-Void TDecSbac::decodeFlush ( )
-{
-  UInt uiBit;
-  m_pcTDecBinIf->decodeBinTrm(uiBit);
-  m_pcTDecBinIf->flush();
-
-}
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -58,6 +58,4 @@
 // ====================================================================================================================
 
-class SEImessages;
-
 /// SBAC decoder class
 class TDecSbac : public TDecEntropyIf
@@ -74,37 +72,20 @@
   Void xCopyFrom           ( TDecSbac* pSrc );
   Void xCopyContextsFrom       ( TDecSbac* pSrc );
-  Void decodeFlush();
 
   Void  resetEntropy (TComSlice* pSlice );
   Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
-  Void  parseVPS                  ( TComVPS* pcVPS )  {}
-  Void  parseSPS                  ( TComSPS* pcSPS         ) {}
-  Void  parsePPS                  ( TComPPS* pcPPS         ) {}
-#if !REMOVE_APS
-  Void  parseAPS                  ( TComAPS* pAPS          ) {}
-#endif
+  Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
+  Void  parseSPS                  ( TComSPS* /*pcSPS*/ ) {}
+  Void  parsePPS                  ( TComPPS* /*pcPPS*/ ) {}
 
-  Void  parseSliceHeader          ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager) {}
+  Void  parseSliceHeader          ( TComSlice*& /*rpcSlice*/, ParameterSetManagerDecoder* /*parameterSetManager*/) {}
   Void  parseTerminatingBit       ( UInt& ruiBit );
   Void  parseMVPIdx               ( Int& riMVPIdx          );
   Void  parseSaoMaxUvlc           ( UInt& val, UInt maxSymbol );
-#if SAO_MERGE_ONE_CTX
   Void  parseSaoMerge         ( UInt&  ruiVal   );
-#else
-  Void  parseSaoMergeLeft         ( UInt&  ruiVal, UInt uiCompIdx   );
-  Void  parseSaoMergeUp           ( UInt&  ruiVal  );
-#endif
   Void  parseSaoTypeIdx           ( UInt&  ruiVal  );
-#if SAO_TYPE_CODING
   Void  parseSaoUflc              ( UInt uiLength, UInt& ruiVal     );
-#else
-  Void  parseSaoUflc              ( UInt& ruiVal           );
-#endif
   Void  parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
-#if SAO_TYPE_SHARING
   Void  parseSaoOffset            (SaoLcuParam* psSaoLcuParam, UInt compIdx);
-#else
-  Void  parseSaoOffset            (SaoLcuParam* psSaoLcuParam);
-#endif
 private:
   Void  xReadUnarySymbol    ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset );
@@ -116,19 +97,5 @@
   TDecBinIf*        m_pcTDecBinIf;
  
-#if !REMOVE_FGS
-  Int           m_iSliceGranularity; //!< slice granularity
-#endif
-  
 public:
-#if !REMOVE_ALF
-  Void parseAlfCtrlFlag   (Int compIdx, UInt& code);
-#endif
-#if !REMOVE_FGS
-  /// set slice granularity
-  Void setSliceGranularity(Int iSliceGranularity)  {m_iSliceGranularity = iSliceGranularity;}
-
-  /// get slice granularity
-  Int  getSliceGranularity()                       {return m_iSliceGranularity;             }
-#endif
   
   Void parseSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -136,5 +103,5 @@
   Void parseSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void parseMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx );
-  Void parseMergeIndex    ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth );
+  Void parseMergeIndex    ( TComDataCU* pcCU, UInt& ruiMergeIndex );
   Void parsePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   Void parsePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -144,11 +111,11 @@
   Void parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
   
-  Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth );
-  Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList );
+  Void parseInterDir      ( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx );
+  Void parseRefFrmIdx     ( TComDataCU* pcCU, Int& riRefFrmIdx, RefPicList eRefList );
   Void parseMvd           ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList );
   
   Void parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize );
   Void parseQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth );
-  Void parseQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf );
+  Void parseQtRootCbf     ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   
   Void parseDeltaQP       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
@@ -162,5 +129,5 @@
   Void updateContextTables( SliceType eSliceType, Int iQp );
 
-  Void  parseScalingList ( TComScalingList* scalingList ) {}
+  Void  parseScalingList ( TComScalingList* /*scalingList*/ ) {}
 
 #if INTRA_BL
@@ -179,5 +146,4 @@
   ContextModel3DBuffer m_cCUPartSizeSCModel;
   ContextModel3DBuffer m_cCUPredModeSCModel;
-  ContextModel3DBuffer m_cCUAlfCtrlFlagSCModel;
   ContextModel3DBuffer m_cCUIntraPredSCModel;
   ContextModel3DBuffer m_cCUChromaPredSCModel;
@@ -199,23 +165,12 @@
   ContextModel3DBuffer m_cMVPIdxSCModel;
   
-  ContextModel3DBuffer m_cALFFlagSCModel;
-  ContextModel3DBuffer m_cALFUvlcSCModel;
-  ContextModel3DBuffer m_cALFSvlcSCModel;
   ContextModel3DBuffer m_cCUAMPSCModel;
-#if !SAO_ABS_BY_PASS
-  ContextModel3DBuffer m_cSaoUvlcSCModel;
-#endif
-#if SAO_MERGE_ONE_CTX
   ContextModel3DBuffer m_cSaoMergeSCModel;
-#else
-  ContextModel3DBuffer m_cSaoMergeLeftSCModel;
-  ContextModel3DBuffer m_cSaoMergeUpSCModel;
-#endif
+  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
+  ContextModel3DBuffer m_cTransformSkipSCModel;
+  ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
 #if INTRA_BL
   ContextModel3DBuffer m_cIntraBLPredFlagSCModel;
 #endif
-  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
-  ContextModel3DBuffer m_cTransformSkipSCModel;
-  ContextModel3DBuffer m_CUTransquantBypassFlagSCModel;
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -41,4 +41,8 @@
 //! \{
 
+#if SVC_EXTENSION
+  ParameterSetMap<TComVPS> ParameterSetManagerDecoder::m_vpsBuffer(MAX_NUM_VPS);
+#endif
+
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
@@ -55,5 +59,4 @@
 TDecSlice::~TDecSlice()
 {
-#if DEPENDENT_SLICES
   for (std::vector<TDecSbac*>::iterator i = CTXMem.begin(); i != CTXMem.end(); i++)
   {
@@ -61,8 +64,6 @@
   }
   CTXMem.clear();
-#endif
-}
-
-#if DEPENDENT_SLICES
+}
+
 Void TDecSlice::initCtxMem(  UInt i )                
 {   
@@ -74,7 +75,6 @@
   CTXMem.resize(i); 
 }
-#endif
-
-Void TDecSlice::create( TComSlice* pcSlice, Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth )
+
+Void TDecSlice::create()
 {
 }
@@ -106,20 +106,22 @@
 #if SVC_EXTENSION
 Void TDecSlice::init(TDecTop** ppcDecTop,TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
+{
+  m_pcEntropyDecoder  = pcEntropyDecoder;
+  m_pcCuDecoder       = pcCuDecoder;
+  m_ppcTDecTop        = ppcDecTop;
+}
 #else
 Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
-#endif
 {
   m_pcEntropyDecoder  = pcEntropyDecoder;
   m_pcCuDecoder       = pcCuDecoder;
-#if SVC_EXTENSION   
-  m_ppcTDecTop        = ppcDecTop; 
-#endif
-}
-
-Void TDecSlice::decompressSlice(TComInputBitstream* pcBitstream, TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders)
+}
+#endif
+
+Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders)
 {
   TComDataCU* pcCU;
   UInt        uiIsLast = 0;
-  Int   iStartCUEncOrder = max(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU(), rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getDependentSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
+  Int   iStartCUEncOrder = max(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU(), rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceSegmentCurStartCUAddr()/rpcPic->getNumPartInCU());
   Int   iStartCUAddr = rpcPic->getPicSym()->getCUOrderMap(iStartCUEncOrder);
 
@@ -194,34 +196,28 @@
   UInt uiTileStartLCU;
   UInt uiTileLCUX;
-  UInt uiTileLCUY;
-  UInt uiTileWidth;
-  UInt uiTileHeight;
   Int iNumSubstreamsPerTile = 1; // if independent.
-
 #if INTRA_BL
   m_pcCuDecoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec() : NULL);
 #endif
-#if DEPENDENT_SLICES
-  Bool bAllowDependence = false;
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-  if( rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceEnabledFlag()&& (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getEntropySliceEnabledFlag()) )
-#else
-  if( rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceEnabledFlag()&& (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getCabacIndependentFlag()) )
-#endif
-  {
-    bAllowDependence = true;
-  }
-  if( bAllowDependence )
-  {
-    if( !rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice() )
-    {
-      uiTileCol = 0;
-#if TILES_WPP_ENTROPYSLICES_FLAGS
+  Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
+  uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr();
+  if( depSliceSegmentsEnabled )
+  {
+    if( (!rpcPic->getSlice(rpcPic->getCurrSliceIdx())->isNextSlice()) &&
+       iStartCUAddr != rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr())
+    {
       if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
-#else
-      if(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2)
-#endif
-      {
+      {
+        uiTileCol = rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1);
         m_pcBufferSbacDecoders[uiTileCol].loadContexts( CTXMem[1]  );//2.LCU
+        if ( (iStartCUAddr%uiWidthInLCUs+1) >= uiWidthInLCUs  )
+        {
+          uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
+          uiCol     = iStartCUAddr % uiWidthInLCUs;
+          if(uiCol==uiTileLCUX)
+          {
+            CTXMem[0]->loadContexts(pcSbacDecoder);
+          }
+        }
       }
       pcSbacDecoder->loadContexts(CTXMem[0] ); //end of depSlice-1
@@ -230,9 +226,5 @@
     else
     {
-#if TILES_WPP_ENTROPYSLICES_FLAGS
       if(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
-#else
-      if(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2)
-#endif
       {
         CTXMem[1]->loadContexts(pcSbacDecoder);
@@ -241,5 +233,4 @@
     }
   }
-#endif
   for( Int iCUAddr = iStartCUAddr; !uiIsLast && iCUAddr < rpcPic->getNumCUsInFrame(); iCUAddr = rpcPic->getPicSym()->xCalculateNxtCUAddr(iCUAddr) )
   {
@@ -249,20 +240,9 @@
     uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr();
     uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
-    uiTileLCUY = uiTileStartLCU / uiWidthInLCUs;
-    uiTileWidth = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getTileWidth();
-    uiTileHeight = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getTileHeight();
     uiCol     = iCUAddr % uiWidthInLCUs;
     // The 'line' is now relative to the 1st line in the slice, not the 1st line in the picture.
     uiLin     = (iCUAddr/uiWidthInLCUs)-(iStartCUAddr/uiWidthInLCUs);
     // inherit from TR if necessary, select substream to use.
-#if DEPENDENT_SLICES
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-    if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( bAllowDependence  && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) ))
-#else
-    if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( bAllowDependence  && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2) ))
-#endif
-#else
-    if( pcSlice->getPPS()->getNumSubstreams() > 1 )
-#endif
+    if( (pcSlice->getPPS()->getNumSubstreams() > 1) || ( depSliceSegmentsEnabled  && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) ))
     {
       // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
@@ -272,13 +252,5 @@
       m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiSubStrm] );
       // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
-#if DEPENDENT_SLICES
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-      if (((pcSlice->getPPS()->getNumSubstreams() > 1) || bAllowDependence ) && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()))
-#else
-      if (((pcSlice->getPPS()->getNumSubstreams() > 1) || bAllowDependence ) && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2))
-#endif
-#else
-      if (pcSlice->getPPS()->getNumSubstreams() > 1 && uiCol == uiTileLCUX)
-#endif
+      if (((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX)&&(pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()))
       {
         // We'll sync if the TR is available.
@@ -296,18 +268,7 @@
              ((pcCUTR->getSCUAddr()+uiMaxParts-1) < pcSlice->getSliceCurStartCUAddr()) ||
              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)))
-             ))||
-             (true/*bEnforceDependentSliceRestriction*/ &&
-             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || 
-             ((pcCUTR->getSCUAddr()+uiMaxParts-1) < pcSlice->getDependentSliceCurStartCUAddr()) ||
-             ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr)))
              ))
            )
         {
-#if DEPENDENT_SLICES
-          if( (iCUAddr!=0) && ((pcCUTR->getSCUAddr()+uiMaxParts-1) >= pcSlice->getSliceCurStartCUAddr()) && bAllowDependence)
-          {
-             pcSbacDecoders[uiSubStrm].loadContexts( &m_pcBufferSbacDecoders[uiTileCol] ); 
-          }
-#endif
           // TR not available.
         }
@@ -328,7 +289,5 @@
     if ( (iCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getFirstCUAddr()) && // 1st in tile.
          (iCUAddr!=0) && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceCurStartCUAddr())/rpcPic->getNumPartInCU())
-#if DEPENDENT_SLICES
-         && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getDependentSliceCurStartCUAddr())/rpcPic->getNumPartInCU())
-#endif
+         && (iCUAddr!=rpcPic->getPicSym()->getPicSCUAddr(rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getSliceSegmentCurStartCUAddr())/rpcPic->getNumPartInCU())
          ) // !1st in frame && !1st in slice
     {
@@ -366,24 +325,11 @@
     g_bJustDoIt = g_bEncDecTraceEnable;
 #endif
-#if !SAO_LUM_CHROMA_ONOFF_FLAGS
-    if ( pcSlice->getSPS()->getUseSAO() && pcSlice->getSaoEnabledFlag() )
-#else
     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
-#endif
-    {
-#if REMOVE_APS
+    {
       SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
-#else
-      SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
-#endif
       saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag();
       if (iCUAddr == iStartCUAddr)
       {
-#if SAO_TYPE_SHARING
         saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma();
-#else
-        saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagCb();
-        saoParam->bSaoFlag[2] = pcSlice->getSaoEnabledFlagCr();
-#endif
       }
       Int numCuInWidth     = saoParam->numCuInWidth;
@@ -410,19 +356,24 @@
       pcSbacDecoder->parseSaoOneLcuInterleaving(rx, ry, saoParam,pcCU, cuAddrInSlice, cuAddrUpInSlice, allowMergeLeft, allowMergeUp);
     }
-#if !REMOVE_ALF
-    if(pcSlice->getSPS()->getUseALF())
-    {
-      UInt alfEnabledFlag;
-      for(Int compIdx=0; compIdx< 3; compIdx++)
-      {
-        alfEnabledFlag = 0;
-        if(pcSlice->getAlfEnabledFlag(compIdx))
-        {
-          pcSbacDecoder->parseAlfCtrlFlag(compIdx, alfEnabledFlag);
-        }
-        pcCU->setAlfLCUEnabled((alfEnabledFlag==1)?true:false, compIdx);
-      }
-    }
-#endif
+    else if ( pcSlice->getSPS()->getUseSAO() )
+    {
+      Int addr = pcCU->getAddr();
+      SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
+      for (Int cIdx=0; cIdx<3; cIdx++)
+      {
+        SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]);
+        if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma()))
+        {
+          saoLcuParam->mergeUpFlag   = 0;
+          saoLcuParam->mergeLeftFlag = 0;
+          saoLcuParam->subTypeIdx    = 0;
+          saoLcuParam->typeIdx       = -1;
+          saoLcuParam->offset[0]     = 0;
+          saoLcuParam->offset[1]     = 0;
+          saoLcuParam->offset[2]     = 0;
+          saoLcuParam->offset[3]     = 0;
+        }
+      }
+    }
     m_pcCuDecoder->decodeCU     ( pcCU, uiIsLast );
     m_pcCuDecoder->decompressCU ( pcCU );
@@ -431,35 +382,14 @@
     g_bJustDoIt = g_bEncDecTraceDisable;
 #endif
-    /*If at the end of a LCU line but not at the end of a substream, perform CABAC flush*/
-    if (!uiIsLast && pcSlice->getPPS()->getNumSubstreams() > 1)
-    {
-      if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight))
-      {
-        m_pcEntropyDecoder->decodeFlush();
-      }
-    }
     pcSbacDecoders[uiSubStrm].load(pcSbacDecoder);
 
     //Store probabilities of second LCU in line into buffer
-#if DEPENDENT_SLICES
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-    if ( (uiCol == uiTileLCUX+1)&& (bAllowDependence || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) )
-#else
-    if ( (uiCol == uiTileLCUX+1)&& (bAllowDependence || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc() == 2))
-#endif
-#else
-    if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiCol == uiTileLCUX+1))
-#endif
+    if ( (uiCol == uiTileLCUX+1)&& (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) )
     {
       m_pcBufferSbacDecoders[uiTileCol].loadContexts( &pcSbacDecoders[uiSubStrm] );
     }
-#if DEPENDENT_SLICES
-    if( uiIsLast && bAllowDependence )
-    {
-#if TILES_WPP_ENTROPYSLICES_FLAGS
+    if( uiIsLast && depSliceSegmentsEnabled )
+    {
       if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
-#else
-      if (pcSlice->getPPS()->getTilesOrEntropyCodingSyncIdc()==2)
-#endif
        {
          CTXMem[1]->loadContexts( &m_pcBufferSbacDecoders[uiTileCol] );//ctx 2.LCU
@@ -468,17 +398,17 @@
       return;
     }
-#endif
   }
 }
 
 ParameterSetManagerDecoder::ParameterSetManagerDecoder()
+#if SVC_EXTENSION
+: m_spsBuffer(MAX_NUM_SPS)
+, m_ppsBuffer(MAX_NUM_PPS)
+#else
 : m_vpsBuffer(MAX_NUM_VPS)
-,m_spsBuffer(256)
-, m_ppsBuffer(16)
-#if !REMOVE_APS
-, m_apsBuffer(64)
-#endif
-{
-
+, m_spsBuffer(MAX_NUM_SPS)
+, m_ppsBuffer(MAX_NUM_PPS)
+#endif
+{
 }
 
@@ -525,24 +455,7 @@
 }
 
-#if !REMOVE_APS
-TComAPS* ParameterSetManagerDecoder::getPrefetchedAPS  (Int apsId)
-{
-  if (m_apsBuffer.getPS(apsId) != NULL )
-  {
-    return m_apsBuffer.getPS(apsId);
-  }
-  else
-  {
-    return getAPS(apsId);
-  }
-}
-#endif
-
 Void     ParameterSetManagerDecoder::applyPrefetchedPS()
 {
   m_vpsMap.mergePSList(m_vpsBuffer);
-#if !REMOVE_APS
-  m_apsMap.mergePSList(m_apsBuffer);
-#endif
   m_ppsMap.mergePSList(m_ppsBuffer);
   m_spsMap.mergePSList(m_spsBuffer);
Index: trunk/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -71,11 +71,8 @@
   TDecSbac*       m_pcBufferLowLatSbacDecoders;   ///< dependent tiles: line to store temporary contexts, one per column of tiles.
   TDecBinCABAC*   m_pcBufferLowLatBinCABACs;
-#if DEPENDENT_SLICES
   std::vector<TDecSbac*> CTXMem;
-#endif
-
 #if SVC_EXTENSION
   TDecTop**       m_ppcTDecTop;
-#endif  
+#endif 
   
 public:
@@ -88,16 +85,13 @@
   Void  init              ( TDecEntropy* pcEntropyDecoder, TDecCu* pcMbDecoder );
 #endif
-  Void  create            ( TComSlice* pcSlice, Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth );
+  Void  create            ();
   Void  destroy           ();
   
-  Void  decompressSlice   ( TComInputBitstream* pcBitstream, TComInputBitstream** ppcSubstreams,   TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders );
-#if DEPENDENT_SLICES
+  Void  decompressSlice   ( TComInputBitstream** ppcSubstreams,   TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders );
   Void      initCtxMem(  UInt i );
-  Void      setCtxMem( TDecSbac* sb, int b )   { CTXMem[b] = sb; }
-#endif
-
+  Void      setCtxMem( TDecSbac* sb, Int b )   { CTXMem[b] = sb; }
 #if SVC_EXTENSION
   TDecTop*  getLayerDec   ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }  
-#endif 
+#endif
 };
 
@@ -114,17 +108,14 @@
   Void     storePrefetchedPPS(TComPPS *pps)  { m_ppsBuffer.storePS( pps->getPPSId(), pps); };
   TComPPS* getPrefetchedPPS  (Int ppsId);
-#if !REMOVE_APS
-  Void     storePrefetchedAPS(TComAPS *aps)  { m_apsBuffer.storePS( aps->getAPSID(), aps); };
-  TComAPS* getPrefetchedAPS  (Int apsId);
-#endif
   Void     applyPrefetchedPS();
 
 private:
+#if SVC_EXTENSION
+  static ParameterSetMap<TComVPS> m_vpsBuffer;
+#else
   ParameterSetMap<TComVPS> m_vpsBuffer;
+#endif
   ParameterSetMap<TComSPS> m_spsBuffer; 
   ParameterSetMap<TComPPS> m_ppsBuffer;
-#if !REMOVE_APS
-  ParameterSetMap<TComAPS> m_apsBuffer;
-#endif
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -40,5 +40,4 @@
 
 #if SVC_EXTENSION
-ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;  // storage for parameter sets 
 UInt  TDecTop::m_prevPOC = MAX_UINT;
 UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
@@ -50,9 +49,6 @@
 
 TDecTop::TDecTop()
-: m_SEIs(0)
 {
   m_pcPic = 0;
-  m_iGopSize      = 0;
-  m_bGopSizeSet   = false;
   m_iMaxRefPicNum = 0;
 #if ENC_DEC_TRACE
@@ -61,5 +57,4 @@
   g_nSymbolCounter = 0;
 #endif
-  m_bRefreshPending = 0;
   m_pocCRA = 0;
   m_prevRAPisBLA = false;
@@ -134,16 +129,8 @@
 #endif
 #if SVC_EXTENSION
-#if REMOVE_ALF
   m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
-#else
-  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO);
-#endif
   m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
 #else
-#if REMOVE_ALF
   m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
-#else
-  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO);
-#endif
   m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
 #endif
@@ -156,4 +143,13 @@
   if(m_layerId>0)
   {
+    Int  numReorderPics[MAX_TLAYER];
+    Window &conformanceWindow = pcSPS->getConformanceWindow();
+    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
+
+    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
+    {
+      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
+    }
+
     if (m_cIlpPic[0] == NULL)
     {
@@ -163,10 +159,7 @@
         //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
 #if SVC_UPSAMPLING
-        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSPS, true);
-#else
-        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
-#endif
-#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || REF_IDX_MFM
-        m_cIlpPic[j]->setIsILR(true);
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
         for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
@@ -186,4 +179,5 @@
     m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
     m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
+    m_cIlpPic[0]->setLayerId(0); //set reference layerId
     m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
     m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
@@ -216,9 +210,4 @@
   }
   
-#if !REMOVE_ALF
-  // destroy ALF temporary buffers
-  m_cAdaptiveLoopFilter.destroy();
-#endif
-  
   m_cSAO.destroy();
   
@@ -231,24 +220,20 @@
 }
 
-Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
-{
-  if ( !pcSlice->isIntra() && !m_bGopSizeSet)
-  {
-    m_iGopSize    = pcSlice->getPOC();
-    m_bGopSizeSet = true;
-    
-    m_cGopDecoder.setGopSize(m_iGopSize);
-  }
-}
-
 Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
 {
-  xUpdateGopSize(pcSlice);
-  
+  Int  numReorderPics[MAX_TLAYER];
+  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
+  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
+
+  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
+  {
+    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
+  }
+
   m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
   if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
   {
     rpcPic = new TComPic();
-    
+
 #if SVC_EXTENSION //Temporal solution, should be modified
     if(m_layerId > 0)
@@ -265,14 +250,11 @@
     
 #if SVC_UPSAMPLING
-    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSlice->getSPS(), true);
-#else
-    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
-#endif
-
-#if REMOVE_APS
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
-#endif
-
-
     m_cListPic.pushBack( rpcPic );
     
@@ -314,16 +296,15 @@
 
 #if SVC_UPSAMPLING
-  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSlice->getSPS(), true);
-#else
-  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
-#endif
-#if REMOVE_APS
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
   rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
-#endif
-
-
-}
-
-Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
+}
+
+Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
 {
   if (!m_pcPic)
@@ -335,5 +316,5 @@
   TComPic*&   pcPic         = m_pcPic;
 
-  // Execute Deblock and ALF only + Cleanup
+  // Execute Deblock + Cleanup
 
   m_cGopDecoder.filterPicture(pcPic);
@@ -342,7 +323,6 @@
   pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
 #endif
-
   TComSlice::sortPicList( m_cListPic ); // sorting for application output
-  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
+  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
   rpcListPic          = &m_cListPic;  
   m_cCuDecoder.destroy();        
@@ -356,18 +336,22 @@
   printf("\ninserting lost poc : %d\n",iLostPoc);
   TComSlice cFillSlice;
+#if SVC_EXTENSION
+  cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
+  cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
+  cFillSlice.initSlice( m_layerId );
+#else
   cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
   cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
-#if SET_SLICE_LAYER_ID
-  cFillSlice.initSlice( m_parameterSetManagerDecoder.getFirstSPS()->getLayerId() );
-#else
   cFillSlice.initSlice();
 #endif
   TComPic *cFillPic;
   xGetNewPicBuffer(&cFillSlice,cFillPic);
+#if SVC_EXTENSION
+  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
+  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
+  cFillPic->getSlice(0)->initSlice( m_layerId );
+#else
   cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
   cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
-#if SET_SLICE_LAYER_ID
-  cFillPic->getSlice(0)->initSlice( cFillPic->getLayerId() );
-#else
   cFillPic->getSlice(0)->initSlice();
 #endif
@@ -412,6 +396,17 @@
 Void TDecTop::xActivateParameterSets()
 {
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
+  
+  TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId());
+  assert (pps != 0);
+
+  TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId());
+  assert (sps != 0);
+
+  if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->getIdrPicFlag()) )
+#else
   m_parameterSetManagerDecoder.applyPrefetchedPS();
-
+  
   TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
   assert (pps != 0);
@@ -419,23 +414,16 @@
   TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
   assert (sps != 0);
+
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->getIdrPicFlag()))
+#endif
+  {
+    printf ("Parameter set activation failed!");
+    assert (0);
+  }
 
   m_apcSlicePilot->setPPS(pps);
   m_apcSlicePilot->setSPS(sps);
   pps->setSPS(sps);
-#if TILES_WPP_ENTROPYSLICES_FLAGS
   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
-#else
-  pps->setNumSubstreams(pps->getTilesOrEntropyCodingSyncIdc() == 2 ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
-#endif
-#if !REMOVE_APS
-#if REMOVE_ALF
-  if(sps->getUseSAO())
-#else
-  if(sps->getUseSAO() || sps->getUseALF())
-#endif
-  {
-    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
-  }
-#endif
   pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
 
@@ -451,5 +439,5 @@
 
   m_cSAO.destroy();
-  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight );
   m_cLoopFilter.        create( g_uiMaxCUDepth );
 }
@@ -462,5 +450,5 @@
 {
   TComPic*&   pcPic         = m_pcPic;
-#if SET_SLICE_LAYER_ID
+#if SVC_EXTENSION
   m_apcSlicePilot->initSlice( nalu.m_layerId );
 #else
@@ -479,5 +467,4 @@
 
   m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
-#if TEMPORAL_LAYER_NON_REFERENCE
   if((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N) ||
      (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) ||
@@ -486,29 +473,30 @@
     m_apcSlicePilot->setTemporalLayerNonReferenceFlag(true);
   }
-#endif
-#if REMOVE_NAL_REF_FLAG
   m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
-#else
-  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
-#endif
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
+
+#if SVC_EXTENSION
+  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
+#else
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
-#if !BYTE_ALIGNMENT
-  // byte align
-  {
-    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
-    if ( numBitsForByteAlignment > 0 )
-    {
-      UInt bitsForByteAlignment;
-      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
-      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
-    }
-  }
-#endif
+#endif
+  if (m_apcSlicePilot->isNextSlice())
+  {
+    // Skip pictures due to random access
+    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
+    {
+      return false;
+    }
+    // Skip TFD pictures associated with BLA/BLANT pictures
+    if (isSkipPictureForBLA(iPOCLastDisplay))
+    {
+      return false;
+    }
+  } 
+
   // exit when a new picture is found
 #if SVC_EXTENSION
   bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
-  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId)
-    && !m_bFirstSliceInSequence )
+  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
@@ -540,17 +528,4 @@
   }
   m_bFirstSliceInSequence = false;
-  if (m_apcSlicePilot->isNextSlice())
-  {
-    // Skip pictures due to random access
-    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
-    {
-      return false;
-    }
-    // Skip TFD pictures associated with BLA/BLANT pictures
-    if (isSkipPictureForBLA(iPOCLastDisplay))
-    {
-      return false;
-    }
-  }
   //detect lost reference picture and insert copy of earlier frame.
   Int lostPoc;
@@ -566,6 +541,7 @@
     TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
     fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
-    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - pBLPic->getPicYuvRec()->getPicCropLeftOffset() - pBLPic->getPicYuvRec()->getPicCropRightOffset();;
-    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - pBLPic->getPicYuvRec()->getPicCropTopOffset() - pBLPic->getPicYuvRec()->getPicCropBottomOffset();
+    const Window &conf = pBLPic->getConformanceWindow();
+    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
+    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
         
     if( pFile->good() )
@@ -617,7 +593,7 @@
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
 
-    /* transfer any SEI messages that have been received to the picture */
+    // transfer any SEI messages that have been received to the picture
     pcPic->setSEIs(m_SEIs);
-    m_SEIs = NULL;
+    m_SEIs.clear();
 
     // Recursive structure
@@ -630,7 +606,19 @@
     m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
 
-    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
-  }
-
+    m_cSliceDecoder.create();
+  }
+  else
+  {
+    // Check if any new SEI has arrived
+    if(!m_SEIs.empty())
+    {
+      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
+      SEIMessages &picSEI = pcPic->getSEIs();
+      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
+      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
+      deleteSEIs(m_SEIs);
+    }
+  }
+  
   //  Set picture slice pointer
   TComSlice*  pcSlice = m_apcSlicePilot;
@@ -712,6 +700,6 @@
 
   //convert the start and end CU addresses of the slice and dependent slice into encoding order
-  pcSlice->setDependentSliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurStartCUAddr()) );
-  pcSlice->setDependentSliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurEndCUAddr()) );
+  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
+  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
   if(pcSlice->isNextSlice())
   {
@@ -744,7 +732,12 @@
   if (bNextSlice)
   {
-    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic);
-#if !REF_IDX_FRAMEWORK || AVC_SYNTAX
+    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA );
     // Set reference list
+#if REF_LIST_BUGFIX
+    if (m_layerId == 0)
+    {
+      pcSlice->setRefPicList( m_cListPic );
+    }
+#else
     pcSlice->setRefPicList( m_cListPic );
 #endif
@@ -788,8 +781,4 @@
 
 #if REF_IDX_FRAMEWORK
-#if !AVC_SYNTAX
-    // Set reference list
-    pcSlice->setRefPicList( m_cListPic );
-#endif
     if(m_layerId > 0)
     {
@@ -798,9 +787,12 @@
       pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
 #endif
-
+#if REF_LIST_BUGFIX
+      pcSlice->setRefPicListSvc( m_cListPic, m_cIlpPic);
+#else
       pcSlice->addRefPicList ( m_cIlpPic, 
                                1, 
                                ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) && 
                                 (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1);
+#endif
     }
 #endif
@@ -818,5 +810,5 @@
       }
     }
-    if (pcSlice->isInterB())
+    if (!pcSlice->isIntra())
     {
       Bool bLowDelay = true;
@@ -831,10 +823,13 @@
         }
       }
-      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
-      {
-        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
+      if (pcSlice->isInterB())
+      {
+        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
         {
-          bLowDelay = false;
-        }
+          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
+          {
+            bLowDelay = false;
+          }
+        }        
       }
 
@@ -870,7 +865,5 @@
       pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
     }
-#if TS_FLAT_QUANTIZATION_MATRIX
     pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
-#endif
     if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
     {
@@ -900,5 +893,9 @@
   
   m_cEntropyDecoder.decodeVPS( vps );
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
+#else
   m_parameterSetManagerDecoder.storePrefetchedVPS(vps);  
+#endif
 }
 
@@ -910,11 +907,8 @@
 #endif
   m_cEntropyDecoder.decodeSPS( sps );
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
+#else
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
-#if REF_IDX_MFM
-  m_pcSPS = sps;
-  setMFMEnabledFlag(sps->getMFMEnabledFlag());
-#endif
-#if !REMOVE_ALF
-  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
 #endif
 #if REF_IDX_FRAMEWORK
@@ -929,19 +923,14 @@
 {
   TComPPS* pps = new TComPPS();
-  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
+  m_cEntropyDecoder.decodePPS( pps );
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
+#else
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
-
-#if DEPENDENT_SLICES
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-  if( pps->getDependentSliceEnabledFlag() && (!pps->getEntropySliceEnabledFlag()) )
-#else
-  if( pps->getDependentSliceEnabledFlag() && (!pps->getCabacIndependentFlag()) )
-#endif
-  {
-#if TILES_WPP_ENTROPYSLICES_FLAGS
-    int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
-#else
-    int NumCtx = (pps->getTilesOrEntropyCodingSyncIdc() == 2)?2:1;
-#endif
+#endif
+
+  if( pps->getDependentSliceSegmentsEnabledFlag() )
+  {
+    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
     m_cSliceDecoder.initCtxMem(NumCtx);
     for ( UInt st = 0; st < NumCtx; st++ )
@@ -953,27 +942,49 @@
     }
   }
-#endif
-}
-
-#if !REMOVE_APS
-Void TDecTop::xDecodeAPS()
-{
-  TComAPS  *aps = new TComAPS();
-  allocAPS (aps);
-  decodeAPS(aps);
-  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
-}
-#endif
-
-Void TDecTop::xDecodeSEI( TComInputBitstream* bs )
-{
-#if RECOVERY_POINT_SEI || BUFFERING_PERIOD_AND_TIMING_SEI
-  if ( m_SEIs == NULL )
-#endif
-  m_SEIs = new SEImessages;
-#if BUFFERING_PERIOD_AND_TIMING_SEI
-  m_SEIs->m_pSPS = m_parameterSetManagerDecoder.getSPS(0);
-#endif
-  m_seiReader.parseSEImessage( bs, *m_SEIs );
+}
+
+Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
+{
+#if SVC_EXTENSION
+  if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
+  {
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+  }
+  else
+  {
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
+    if (activeParamSets.size()>0)
+    {
+      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
+      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
+      assert(seiAps->activeSeqParamSetId.size()>0);
+      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+      {
+        printf ("Warning SPS activation with Active parameter set SEI failed");
+      }
+    }
+  }
+#else
+  if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
+  {
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+  }
+  else
+  {
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
+    if (activeParamSets.size()>0)
+    {
+      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
+      m_parameterSetManagerDecoder.applyPrefetchedPS();
+      assert(seiAps->activeSeqParamSetId.size()>0);
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+      {
+        printf ("Warning SPS activation with Active parameter set SEI failed");
+      }
+    }
+  }
+#endif
 }
 
@@ -1001,13 +1012,17 @@
         if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
         {
+          TComSPS* sps = new TComSPS();
+          Int  numReorderPics[MAX_TLAYER];
+          Window &conformanceWindow = sps->getConformanceWindow();
+          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
 #if SVC_UPSAMPLING
 #if AVC_SYNTAX
-          TComSPS* sps = new TComSPS();
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, sps, true);
-#else
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, true);
-#endif
-#else
-          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
+
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
+#endif
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, onformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
         }
@@ -1019,15 +1034,10 @@
       xDecodePPS();
       return false;
-#if !REMOVE_APS
-    case NAL_UNIT_APS:
-      xDecodeAPS();
-      return false;
-#endif
       
     case NAL_UNIT_SEI:
-      xDecodeSEI( nalu.m_Bitstream );
+    case NAL_UNIT_SEI_SUFFIX:
+      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
       return false;
 
-#if NAL_UNIT_TYPES_J1003_D7
     case NAL_UNIT_CODED_SLICE_TRAIL_R:
     case NAL_UNIT_CODED_SLICE_TRAIL_N:
@@ -1042,16 +1052,8 @@
     case NAL_UNIT_CODED_SLICE_IDR_N_LP:
     case NAL_UNIT_CODED_SLICE_CRA:
+    case NAL_UNIT_CODED_SLICE_RADL_N:
     case NAL_UNIT_CODED_SLICE_DLP:
+    case NAL_UNIT_CODED_SLICE_RASL_N:
     case NAL_UNIT_CODED_SLICE_TFD:
-#else
-    case NAL_UNIT_CODED_SLICE:
-    case NAL_UNIT_CODED_SLICE_TFD:
-    case NAL_UNIT_CODED_SLICE_TLA:
-    case NAL_UNIT_CODED_SLICE_CRA:
-    case NAL_UNIT_CODED_SLICE_CRANT:
-    case NAL_UNIT_CODED_SLICE_BLA:
-    case NAL_UNIT_CODED_SLICE_BLANT:
-    case NAL_UNIT_CODED_SLICE_IDR:
-#endif
 #if SVC_EXTENSION
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
@@ -1075,5 +1077,5 @@
 Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
 {
-  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD)
+  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
   {
     iPOCLastDisplay++;
@@ -1106,11 +1108,6 @@
   {
     if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
-#if !NAL_UNIT_TYPES_J1003_D7
-        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT
-#endif
         || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-#if SUPPORT_FOR_RAP_N_LP
         || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-#endif
         || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT )
     {
@@ -1118,15 +1115,11 @@
       m_pocRandomAccess = m_apcSlicePilot->getPOC();
     }
-#if SUPPORT_FOR_RAP_N_LP
     else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
-#else
-    else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR)
-#endif
-    {
-      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
+    {
+      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
     }
     else 
     {
-      static bool warningMessage = false;
+      static Bool warningMessage = false;
       if(!warningMessage)
       {
@@ -1138,5 +1131,5 @@
   }
   // skip the reordered pictures, if necessary
-  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD)
+  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
   {
     iPOCLastDisplay++;
@@ -1147,17 +1140,3 @@
 }
 
-#if !REMOVE_APS
-Void TDecTop::allocAPS (TComAPS* pAPS)
-{
-  // we don't know the SPS before it has been activated. These fields could exist
-  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
-  // have to be moved for that
-  pAPS->createSaoParam();
-  m_cSAO.allocSaoParam(pAPS->getSaoParam());
-#if !REMOVE_ALF
-  pAPS->createAlfParam();
-#endif
-}
-#endif
-
 //! \}
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 55)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 125)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2012, ITU/ISO/IEC
+ * Copyright (c) 2010-2013, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -65,9 +65,6 @@
 {
 private:
-  Int                     m_iGopSize;
-  Bool                    m_bGopSizeSet;
   Int                     m_iMaxRefPicNum;
   
-  Bool                    m_bRefreshPending;    ///< refresh pending flag
   Int                     m_pocCRA;            ///< POC number of the latest CRA picture
   Bool                    m_prevRAPisBLA;      ///< true if the previous RAP (CRA/CRANT/BLA/BLANT/IDR) picture is a BLA/BLANT picture
@@ -76,17 +73,12 @@
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
 #if SVC_EXTENSION
-  static ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+  ParameterSetManagerDecoder m_parameterSetManagerDecoder[MAX_LAYERS];  // storage for parameter sets 
 #else
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
 #endif
 
-#if REF_IDX_MFM
-  TComSPS*               m_pcSPS;
-  Bool                   m_bMFMEnabledFlag;
-#endif
-
   TComSlice*              m_apcSlicePilot;
   
-  SEImessages *m_SEIs; ///< "all" SEI messages.  If not NULL, we own the object.
+  SEIMessages             m_SEIs; ///< List of SEI messages that have been received before the first slice and between slices
 
   // functional classes
@@ -102,7 +94,4 @@
   SEIReader               m_seiReader;
   TComLoopFilter          m_cLoopFilter;
-#if !REMOVE_ALF
-  TComAdaptiveLoopFilter  m_cAdaptiveLoopFilter;
-#endif
   TComSampleAdaptiveOffset m_cSAO;
 
@@ -157,5 +146,5 @@
   Void  deletePicBuffer();
 
-  Void executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame,  Int& iPOCLastDisplay);
+  Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
 
 #if SVC_EXTENSION
@@ -183,18 +172,9 @@
   Void      setILRPic(TComPic *pcPic);
 #endif
-#if REF_IDX_MFM
-  TComSPS*  getSPS()                       {return m_pcSPS;}
-  Void      setMFMEnabledFlag(Bool flag)   {m_bMFMEnabledFlag = flag;}
-  Bool      getMFMEnabledFlag()            {return m_bMFMEnabledFlag;}
-#endif
 
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
-  Void  xUpdateGopSize    (TComSlice* pcSlice);
   Void  xCreateLostPicture (Int iLostPOC);
 
-#if !REMOVE_APS
-  Void      decodeAPS( TComAPS* cAPS) { m_cEntropyDecoder.decodeAPS(cAPS); };
-#endif
   Void      xActivateParameterSets();
 #if SVC_EXTENSION
@@ -206,12 +186,6 @@
   Void      xDecodeSPS();
   Void      xDecodePPS();
-#if !REMOVE_APS
-  Void      xDecodeAPS();
-#endif
-  Void      xDecodeSEI( TComInputBitstream* bs );
+  Void      xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType );
 
-#if !REMOVE_APS
-  Void      allocAPS (TComAPS* pAPS); //!< memory allocation for APS
-#endif
 };// END CLASS DEFINITION TDecTop
 
