Index: trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp	(revision 296)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp	(revision 608)
@@ -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.
  *
@@ -37,4 +37,5 @@
 
 #include "TDecBinCoderCABAC.h"
+#include "../TLibCommon/TComRom.h"
 
 //! \ingroup TLibDecoder
@@ -65,17 +66,9 @@
 TDecBinCABAC::start()
 {
-#if OL_FLUSH_ALIGN
   assert( m_pcTComBitstream->getNumBitsUntilByteAligned() == 0 );
-#endif
-  
   m_uiRange    = 510;
   m_bitsNeeded = -8;
-  m_uiValue    = m_pcTComBitstream->readByte() << 8;
-#if !OL_FLUSH_ALIGN
-  m_uiLastByte = m_pcTComBitstream->readByte();
-  m_uiValue   |= m_uiLastByte;
-#else
+  m_uiValue    = (m_pcTComBitstream->readByte() << 8);
   m_uiValue   |= m_pcTComBitstream->readByte();
-#endif
 }
 
@@ -83,27 +76,9 @@
 TDecBinCABAC::finish()
 {
-}
-
-Void 
-TDecBinCABAC::flush()
-{
-#if OL_FLUSH_ALIGN
-  while (m_pcTComBitstream->getNumBitsLeft() > 0 && m_pcTComBitstream->getNumBitsUntilByteAligned() != 0)
-  {
-    UInt uiBits;
-    m_pcTComBitstream->read ( 1, uiBits );
-  }
-  start();
-#else
-  m_uiRange    = 510;
-  Int iExtra = 16+m_bitsNeeded+1; // m_bitsNeeded is -ve: iExtra is many bits to read to make up 16.
-  UInt uiExtraBits;
-  m_pcTComBitstream->read(iExtra, uiExtraBits);
-  m_uiValue = (m_uiLastByte << iExtra) | uiExtraBits;
-  m_uiValue &= 0xffff;
-  m_uiLastByte = m_uiValue;
-  m_uiLastByte &= 0xff;
-  m_bitsNeeded = -8;
-#endif // OL_FLUSH_ALIGN
+  UInt lastByte;
+
+  m_pcTComBitstream->peekPreviousByte( lastByte );
+  // Check for proper stop/alignment pattern
+  assert( ((lastByte << (8 + m_bitsNeeded)) & 0xff) == 0x80 );
 }
 
@@ -120,7 +95,4 @@
   m_uiValue   = pcTDecBinCABAC->m_uiValue;
   m_bitsNeeded= pcTDecBinCABAC->m_bitsNeeded;
-#if !OL_FLUSH_ALIGN
-  m_uiLastByte= pcTDecBinCABAC->m_uiLastByte;
-#endif
 }
 
@@ -150,10 +122,5 @@
     {
       m_bitsNeeded = -8;
-#if !OL_FLUSH_ALIGN
-      m_uiLastByte = m_pcTComBitstream->readByte();
-      m_uiValue += m_uiLastByte;    
-#else
       m_uiValue += m_pcTComBitstream->readByte();      
-#endif
     }
   }
@@ -171,10 +138,5 @@
     if ( m_bitsNeeded >= 0 )
     {
-#if !OL_FLUSH_ALIGN
-      m_uiLastByte = m_pcTComBitstream->readByte();
-      m_uiValue += m_uiLastByte << m_bitsNeeded;
-#else
       m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded;
-#endif
       m_bitsNeeded -= 8;
     }
@@ -190,10 +152,5 @@
   {
     m_bitsNeeded = -8;
-#if !OL_FLUSH_ALIGN
-    m_uiLastByte = m_pcTComBitstream->readByte();
-    m_uiValue += m_uiLastByte;
-#else
     m_uiValue += m_pcTComBitstream->readByte();
-#endif
   }
   
@@ -213,10 +170,5 @@
   while ( numBins > 8 )
   {
-#if !OL_FLUSH_ALIGN
-    m_uiLastByte = m_pcTComBitstream->readByte();
-    m_uiValue = ( m_uiValue << 8 ) + ( m_uiLastByte << ( 8 + m_bitsNeeded ) );
-#else
     m_uiValue = ( m_uiValue << 8 ) + ( m_pcTComBitstream->readByte() << ( 8 + m_bitsNeeded ) );
-#endif
     
     UInt scaledRange = m_uiRange << 15;
@@ -239,10 +191,5 @@
   if ( m_bitsNeeded >= 0 )
   {
-#if !OL_FLUSH_ALIGN
-    m_uiLastByte = m_pcTComBitstream->readByte();
-    m_uiValue += m_uiLastByte << m_bitsNeeded;
-#else
     m_uiValue += m_pcTComBitstream->readByte() << m_bitsNeeded;
-#endif
     m_bitsNeeded -= 8;
   }
@@ -283,70 +230,8 @@
       {
         m_bitsNeeded = -8;
-#if !OL_FLUSH_ALIGN
-        m_uiLastByte = m_pcTComBitstream->readByte();
-        m_uiValue += m_uiLastByte;    
-#else
         m_uiValue += m_pcTComBitstream->readByte();      
-#endif
       }
     }
   }
-}
-
-/** Reset BAC register values.
- * \returns Void
- */
-Void TDecBinCABAC::resetBac()
-{
-  m_uiRange    = 510;
-  m_bitsNeeded = -8;
-  m_uiValue    = m_pcTComBitstream->read( 16 );
-}
-
-/** 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;
-#if !OL_FLUSH_ALIGN
-      m_uiLastByte = m_pcTComBitstream->readByte();
-      m_uiValue += m_uiLastByte;
-#else
-      m_uiValue += m_pcTComBitstream->readByte();
-#endif
-    }
-    bit = ((m_uiValue&128)>>7);
-    numSubseqIPCM++;
-  }
-  while( bit && (numSubseqIPCM < 3 ));
-
-  if( bit && (numSubseqIPCM == 3 ))
-  {
-    numSubseqIPCM++;
-  }
-
-  numSubseqIPCM --;
-}
-
-/** Decode PCM alignment zero bits.
- * \returns Void
- */
-Void TDecBinCABAC::decodePCMAlignBits()
-{
-  Int iNum = m_pcTComBitstream->getNumBitsUntilByteAligned();
-  
-  UInt uiBit = 0;
-  m_pcTComBitstream->read( iNum, uiBit );
 }
 
