Index: branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/TAppComCamPara.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/TAppComCamPara.cpp	(revision 438)
@@ -0,0 +1,1511 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+
+// Include files
+#include "TAppComCamPara.h"
+
+
+#include <stdlib.h>
+#include <math.h>
+#include <errno.h>
+#include <assert.h>
+#include <vector>
+#include <iostream>
+#include <fstream>
+#include <algorithm>
+#include <functional>
+#include <string>
+
+
+
+Void
+TAppComCamPara::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams )
+{
+  AOF( m_uiBitDepthForLUT == 8 );
+  AOF( radShiftParams == NULL && raiShiftParams == NULL && radLUT == NULL && raiLUT == NULL );
+
+  uiNumberSourceViews = max( 1, uiNumberSourceViews );
+  uiNumberTargetViews = Max( 1, uiNumberTargetViews );
+
+  radShiftParams = new Double** [ uiNumberSourceViews ];
+  raiShiftParams = new Int64 ** [ uiNumberSourceViews ];
+  radLUT         = new Double***[ uiNumberSourceViews ];
+  raiLUT         = new Int   ***[ uiNumberSourceViews ];
+
+  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
+  {
+    radShiftParams[ uiSourceView ] = new Double* [ uiNumberTargetViews ];
+    raiShiftParams[ uiSourceView ] = new Int64 * [ uiNumberTargetViews ];
+    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
+    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
+
+    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
+    {
+      radShiftParams[ uiSourceView ][ uiTargetView ]      = new Double [ 2 ];
+      raiShiftParams[ uiSourceView ][ uiTargetView ]      = new Int64  [ 2 ];
+
+      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
+      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
+      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
+
+      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
+      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
+      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
+    }
+  }
+}
+
+Void
+TAppComCamPara::xCreate2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray )
+{
+  AOT( raaiArray || uiNum1Ids == 0 || uiNum2Ids == 0 );
+  raaiArray = new Int* [ uiNum1Ids ];
+  for( UInt uiId1 = 0; uiId1 < uiNum1Ids; uiId1++ )
+  {
+    raaiArray[ uiId1 ] = new Int [ uiNum2Ids ];
+  }
+}
+
+
+Void
+TAppComCamPara::xInit2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray, Int iValue )
+{
+  for( UInt uiId1 = 0; uiId1 < uiNum1Ids; uiId1++ )
+  {
+    for( UInt uiId2 = 0; uiId2 < uiNum2Ids; uiId2++ )
+    {
+      raaiArray[ uiId1 ][ uiId2 ] = iValue;
+    }
+  }
+}
+
+
+Void
+TAppComCamPara::convertNumberString( Char* pchViewNumberString, std::vector<Int>& raiViewNumbers, Double dViewNumPrec )
+{
+  Bool bStringIsRange = false;
+  Int  iIdx           = 0;
+  std::vector<Double> adViewNumbers;
+
+  while( pchViewNumberString != 0 && pchViewNumberString[ iIdx ] != 0 )
+  {
+    if( pchViewNumberString[ iIdx ] == ':' )
+    {
+      bStringIsRange              = true;
+      pchViewNumberString[ iIdx ] = ' ';
+    }
+    iIdx++;
+  }
+
+  Char* pcNextStart = pchViewNumberString;
+  Char* pcEnd       = pcNextStart + iIdx;
+  Char* pcOldStart  = 0;
+
+  while( pcNextStart < pcEnd )
+  {
+    errno = 0;
+    adViewNumbers.push_back( ( strtod( pcNextStart, &pcNextStart ) ) );
+
+    if( errno == ERANGE || pcNextStart == pcOldStart )
+    {
+      std::cerr << "Error Parsing View Number String: `" << pchViewNumberString << "'" << std::endl;
+      AOT(true);
+      exit( EXIT_FAILURE );
+    };
+
+    while( pcNextStart < pcEnd && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++;
+
+    pcOldStart = pcNextStart;
+  }
+
+  if( bStringIsRange )
+  {
+    if( adViewNumbers.size() != 3 )
+    {
+      std::cerr << "Error Parsing SynthViewNumbers: `" << pchViewNumberString << "'" << std::endl;
+      AOT(true);
+      exit( EXIT_FAILURE );
+    }
+
+    Double dRangeBegin = adViewNumbers[0];
+    Double dRangeStep  = adViewNumbers[1];
+    Double dRangeEnd   = adViewNumbers[2];
+
+    if( ( ( dRangeEnd - dRangeBegin > 0 ) != ( dRangeStep > 0 ) ) || dRangeStep == 0 )
+    {
+      std::cerr << "Error Parsing SynthViewNumbers: `" << pchViewNumberString << "'" << std::endl;
+      AOT(true);
+      exit( EXIT_FAILURE );
+    }
+
+    raiViewNumbers.clear();
+
+    Double dFac = ( dRangeBegin > dRangeEnd ? -1 : 1 );
+
+    for( Double dViewNumber = dRangeBegin; ( dViewNumber - dRangeEnd ) * dFac <= 0; dViewNumber += dRangeStep )
+    {
+      raiViewNumbers.push_back( (Int)( dViewNumber * dViewNumPrec ) );
+    }
+  }
+  else
+  {
+    for( UInt uiViewNum = 0; uiViewNum < adViewNumbers.size(); uiViewNum++ )
+    {
+      raiViewNumbers.push_back( (Int)( adViewNumbers[ uiViewNum ] * dViewNumPrec ) );
+    }
+  }
+}
+
+
+Void
+TAppComCamPara::xReadCameraParameterFile( Char* pchCfgFileName )
+{
+  std::ifstream cCfgStream( pchCfgFileName, std::ifstream::in );
+  if( !cCfgStream )
+  {
+    std::cerr << "Failed to open camera parameter file: `" << pchCfgFileName << "'" << std::endl;
+    exit( EXIT_FAILURE );
+  }
+
+  Int iLineNumber = 0;
+  do
+  {
+    std::string cLine;
+    getline( cCfgStream, cLine );
+    iLineNumber++;
+
+    size_t iStart = cLine.find_first_not_of( " \t\n\r" );
+
+    if( iStart == std::string::npos )
+    {
+      continue;
+    }
+
+    if( cLine[iStart] == '#' )
+    {
+      continue;
+    }
+
+    Char* pcNextStart = (Char*) cLine.data();
+    Char* pcEnd = pcNextStart + cLine.length();
+
+    std::vector<Double> caNewLine;
+    caNewLine.clear();
+
+    Char* pcOldStart = 0;
+    while( pcNextStart < pcEnd )
+    {
+      errno = 0;
+      caNewLine.push_back( strtod( pcNextStart, &pcNextStart ) ) ;
+
+      if( errno == ERANGE || ( pcNextStart == pcOldStart ) )
+      {
+        std::cerr << "Failed reading config file: `" << pchCfgFileName << "' Error parsing double values in Line: " << iLineNumber << ' ' << std::endl;
+        assert( 0 );
+        exit( EXIT_FAILURE );
+      };
+      pcOldStart = pcNextStart;
+
+      while( ( pcNextStart < pcEnd ) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++;
+    }
+
+    if ( ( caNewLine.size() != 2 ) && ( caNewLine.size() != 7 ) && ( caNewLine.size() != 6 ) && ( caNewLine.size() != 8 ) )
+    {
+      std::cerr << "Failed reading config file: `" << pchCfgFileName << "'" << std::endl;
+      std::cerr << "Invalid number of entries" << std::endl;
+      AOF(false);
+      exit( EXIT_FAILURE );
+    }
+    m_aadCameraParameters.push_back( caNewLine );
+  }
+  while( cCfgStream );
+}
+
+Void
+TAppComCamPara::xGetCodedCameraData( UInt uiSourceView, UInt uiTargetView, Bool bByIdx,  UInt uiFrame, Int& riScale, Int& riOffset, Int& riPrecision )
+{
+  if( bByIdx )
+  {
+    uiSourceView = m_aiBaseViews[ uiSourceView ];
+    uiTargetView = m_aiBaseViews[ uiTargetView ];
+  }
+
+  Int iFoundLine = -1;
+  for( UInt uiCurViewLine = 0; uiCurViewLine < m_aadCameraParameters.size(); uiCurViewLine++ )
+  {
+    if ( m_aadCameraParameters[uiCurViewLine].size() == 2 )
+      continue;
+
+    if(      ( (Int)( m_aadCameraParameters[ uiCurViewLine ][ 3 ] * m_dViewNumPrec ) == uiSourceView )
+          && ( (Int)( m_aadCameraParameters[ uiCurViewLine ][ 2 ] * m_dViewNumPrec ) == uiTargetView )
+      )
+    {
+      if( ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 0 ] <= uiFrame ) && ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 1 ] >= uiFrame ) )
+      {
+        if( iFoundLine != -1 )
+        {
+          std::cerr << "Error CameraParameters for SourceView " << (Double) uiSourceView / m_dViewNumPrec << " and Target View " << (Double) uiTargetView / m_dViewNumPrec << " and Frame " << uiFrame << " given multiple times."  << std::endl;
+          AOT(true);
+          exit( EXIT_FAILURE );
+        }
+        else
+        {
+          iFoundLine = uiCurViewLine;
+        }
+      }
+    }
+  }
+
+  if ( iFoundLine == -1 )
+  {
+    std::cerr << "Error CameraParameters for SourceView " << (Double) uiSourceView / m_dViewNumPrec << " and Target View " << (Double) uiTargetView / m_dViewNumPrec << " and Frame " << uiFrame << " not found."  << std::endl;
+    AOT(true);
+    exit( EXIT_FAILURE );
+  }
+
+  riScale     = (Int)( m_aadCameraParameters[ iFoundLine ][ 4 ] );
+  riOffset    = (Int)( m_aadCameraParameters[ iFoundLine ][ 5 ] );
+  riPrecision = (Int)( m_aadCameraParameters[ iFoundLine ][ 6 ] );
+}
+
+Bool
+TAppComCamPara::xGetCameraDataRow( Int iView, UInt uiFrame, UInt& ruiFoundLine )
+{
+  ruiFoundLine = -1;
+  for( UInt uiCurViewLine = 0; uiCurViewLine < m_aadCameraParameters.size(); uiCurViewLine++ )
+  {
+    if( (Int)( m_aadCameraParameters[ uiCurViewLine ][ 0 ] * m_dViewNumPrec ) == iView )
+    {
+      if( ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 1 ] <= uiFrame ) && ( (UInt)m_aadCameraParameters[ uiCurViewLine ][ 2 ] >= uiFrame ) )
+      {
+        if( ruiFoundLine != -1 )
+        {
+          std::cerr << "Error CameraParameters for View " << (Double) iView / m_dViewNumPrec << " and Frame " << uiFrame << " given multiple times."  << std::endl;
+          exit( EXIT_FAILURE );
+        }
+        else
+        {
+          ruiFoundLine = uiCurViewLine;
+        }
+      }
+    }
+  }
+  return ( ruiFoundLine == -1 );
+}
+
+
+Void
+TAppComCamPara::xGetSortedViewList( const std::vector<Int>& raiViews, std::vector<Int>& raiSortedViews, std::vector<Int>& raiId2SortedId, std::vector<Int>& raiSortedId2Id )
+{
+  AOF( raiViews.size() > 0 );
+  Int iNumViews   = (Int)raiViews.size();
+  raiId2SortedId  = std::vector<Int>( raiViews.size(), -1 );
+  raiSortedId2Id.clear();
+  raiSortedViews.clear();
+  for( Int iSortId = 0; iSortId < iNumViews; iSortId++ )
+  {
+    Int  iLeftMostBaseId = -1;
+    for( Int iBaseId = 0; iLeftMostBaseId == -1 && iBaseId < iNumViews; iBaseId++ )
+    {
+      if( raiId2SortedId[ iBaseId ] == -1 )
+      {
+        UInt   uiFoundLine   = -1;
+        xGetCameraDataRow( raiViews[ iBaseId ], 0, uiFoundLine );
+        AOT(   uiFoundLine  == -1 ); // something wrong
+        Double dXPos         = m_aadCameraParameters[ uiFoundLine ][ 4 ];
+        Double dZNear        = m_aadCameraParameters[ uiFoundLine ][ 6 ];
+        Double dZFar         = m_aadCameraParameters[ uiFoundLine ][ 7 ];
+        Double dSign         = ( dZFar > 0 ? 1.0 : -1.0 );
+        Bool   bLeftMost     = true;
+        AOF( dZNear * dZFar  > 0.0 ); // otherwise, z parameters are not correct
+
+        for( Int iTestBaseId = 0; bLeftMost && iTestBaseId < iNumViews; iTestBaseId++ )
+        {
+          if( iTestBaseId != iBaseId && raiId2SortedId[ iTestBaseId ] == -1 )
+          {
+            UInt   uiFoundLineTest  = -1;
+            xGetCameraDataRow( raiViews[ iTestBaseId ], 0, uiFoundLineTest );
+            AOT(   uiFoundLineTest == -1 ); // something wrong
+            Double dXPosTest        = m_aadCameraParameters[ uiFoundLineTest ][ 4 ];
+            Double dZNearTest       = m_aadCameraParameters[ uiFoundLineTest ][ 6 ];
+            Double dZFarTest        = m_aadCameraParameters[ uiFoundLineTest ][ 7 ];
+            AOF( dZNearTest * dZFarTest > 0.0 ); // otherwise, z parameters are not correct
+            AOF( dZNearTest * dSign     > 0.0 ); // otherwise, z parameters are not consistent
+            Double dDeltaXPos       = dSign * ( dXPosTest - dXPos );
+            bLeftMost               = ( bLeftMost && dDeltaXPos > 0.0 );
+          }
+        }
+        if( bLeftMost )
+        {
+          iLeftMostBaseId = iBaseId;
+        }
+      }
+    }
+    AOT( iLeftMostBaseId == -1 ); // something wrong
+    raiId2SortedId[ iLeftMostBaseId ] = iSortId;
+    raiSortedId2Id.push_back( iLeftMostBaseId );
+    raiSortedViews.push_back( raiViews[ iLeftMostBaseId ] );
+  }
+
+  // sanity check
+  if( iNumViews > 2 )
+  {
+    Int   iDeltaView  = gSign( raiSortedViews[ 1 ] - raiSortedViews[ 0 ] );
+    Bool  bOutOfOrder = false;
+    for(  Int  iSIdx  = 2; iSIdx < iNumViews; iSIdx++ )
+    {
+      bOutOfOrder = ( bOutOfOrder || iDeltaView * gSign( raiSortedViews[ iSIdx ] - raiSortedViews[ iSIdx - 1 ] ) < 0 );
+    }
+    if( bOutOfOrder )
+    {
+      std::cerr << "ERROR: View numbering must be strictly increasing or decreasing from left to right" << std::endl;
+      exit(EXIT_FAILURE);
+    }
+  }
+}
+
+
+Void
+TAppComCamPara::xGetViewOrderIndices( const std::vector<Int>& raiId2SortedId, std::vector<Int>& raiVOIdx )
+{
+  AOF( raiId2SortedId.size() );
+  raiVOIdx  =      raiId2SortedId;
+  Int iSize = (Int)raiId2SortedId.size();
+  Int iOffs =      raiId2SortedId[ 0 ];
+  for( Int iIdx = 0; iIdx < iSize; iIdx++ )
+  {
+    raiVOIdx[ iIdx ] -= iOffs;
+  }
+}
+
+
+Bool
+TAppComCamPara::xGetCamParsChangeFlag()
+{
+  Bool bChangeDetected = false;
+  for( Int iBaseViewId = 0; !bChangeDetected && iBaseViewId < m_iNumberOfBaseViews; iBaseViewId++ )
+  {
+    if ( m_bSetupFromCoded )
+    {
+      for( Int iTargetViewId = 0; !bChangeDetected && iTargetViewId < m_iNumberOfBaseViews; iTargetViewId++ )
+      {
+        Int iTargetView = m_aiBaseViews[iTargetViewId];
+        Int iSourceView = m_aiBaseViews[iBaseViewId  ];
+
+        Int iS1 ,iSX;
+        Int iO1 ,iOX;
+        Int iP1 ,iPX;
+
+        if ( iSourceView == iTargetView )
+          continue;
+
+        xGetCodedCameraData( iSourceView, iTargetView, false, 0, iS1, iO1, iP1 );
+        for( UInt uiFrameId = m_uiFirstFrameId + 1; !bChangeDetected && uiFrameId <= m_uiLastFrameId; uiFrameId++ )
+        {
+          xGetCodedCameraData( iSourceView, iTargetView, false, uiFrameId, iSX, iOX, iPX );
+
+          if( iS1 != iSX || iO1 != iOX || iP1 != iPX )
+          {
+            bChangeDetected = true;
+          }
+        }
+      }
+    }
+    else
+    {
+    Int     iBaseView  = m_aiBaseViews[ iBaseViewId ];
+    Double  dFL1, dFLX;
+    Double  dCP1, dCPX;
+    Double  dCS1, dCSX;
+    Double  dZN1, dZNX;
+    Double  dZF1, dZFX;
+    Bool    bInterpolated;
+    xGetGeometryData( iBaseView, m_uiFirstFrameId, dFL1, dCP1, dCS1, bInterpolated );  AOT( bInterpolated );
+    xGetZNearZFar   ( iBaseView, m_uiFirstFrameId, dZN1, dZF1 );
+
+    for( UInt uiFrameId = m_uiFirstFrameId + 1; !bChangeDetected && uiFrameId <= m_uiLastFrameId; uiFrameId++ )
+    {
+      xGetGeometryData( iBaseView, uiFrameId, dFLX, dCPX, dCSX, bInterpolated );  AOT( bInterpolated );
+      xGetZNearZFar   ( iBaseView, uiFrameId, dZNX, dZFX );
+
+      if( dFL1 != dFLX || dCP1 != dCPX || dCS1 != dCSX || dZN1 != dZNX || dZF1 != dZFX )
+      {
+        bChangeDetected = true;
+      }
+    }
+  }
+  }
+  return bChangeDetected;
+}
+
+Int
+TAppComCamPara::xGetViewId( std::vector<Int> aiViewList, Int iBaseView )
+{
+  Int  iViewId = -1;
+  for( Int iId = 0; iId < (Int)aiViewList.size(); iId++ )
+  {
+    if( aiViewList[ iId ] == iBaseView )
+    {
+      iViewId = iId;
+      break;
+    }
+  }
+  AOT(   iViewId == -1 );
+  return iViewId;
+}
+
+Int
+TAppComCamPara::xGetBaseViewId( Int iBaseView )
+{
+  return xGetViewId( m_aiBaseViews, iBaseView );
+}
+
+
+Bool
+TAppComCamPara::xGetLeftRightView( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx )
+{
+  Bool bFoundLRView  = false;
+  Int  iLeftView     = -1;
+  Int  iRightView    = -1;
+  Int  iLeftViewIdx  = -1;
+  Int  iRightViewIdx = -1;
+  Bool bDecencdingVN = ( aiSortedViews.size() >= 2 && aiSortedViews[ 0 ] > aiSortedViews[ 1 ] );
+  Int  iFactor       = ( bDecencdingVN ? -1 : 1 );
+
+  for( Int iIdx = -1; iIdx < (Int)aiSortedViews.size(); iIdx++ )
+  {
+    if( iIdx == -1 )
+    {
+      if( ( aiSortedViews[ iIdx + 1 ] - iView ) * iFactor > 0  )
+      {
+        bFoundLRView  = false;
+        iLeftView     = -1;
+        iRightView    = aiSortedViews[ iIdx + 1 ];
+        iLeftViewIdx  = -1;
+        iRightViewIdx = iIdx + 1;
+        break;
+      }
+    }
+    else if ( iIdx == (Int)aiSortedViews.size() - 1 )
+    {
+      if( ( aiSortedViews[ iIdx ] - iView ) * iFactor < 0  )
+      {
+        bFoundLRView  = false;
+        iLeftView     = aiSortedViews[ iIdx ];
+        iRightView    = -1;
+        iLeftViewIdx  = iIdx;
+        iRightViewIdx = -1;
+        break;
+      }
+    }
+    else
+    {
+      if( ( ( aiSortedViews[ iIdx ] - iView ) * iFactor <= 0 ) && ( ( aiSortedViews[ iIdx + 1 ] - iView ) * iFactor >= 0 ) )
+      {
+        bFoundLRView  = true;
+        iLeftView     = aiSortedViews[ iIdx ];
+        iRightView    = aiSortedViews[ iIdx + 1 ];
+        iLeftViewIdx  = iIdx;
+        iRightViewIdx = iIdx + 1;
+        break;
+      }
+    }
+  }
+
+  if ( ( iView == iLeftView ) || ( iView == iRightView ) )
+  {
+    iLeftViewIdx  = ( iView == iLeftView ) ? iLeftViewIdx : iRightViewIdx;
+    iRightViewIdx = iLeftViewIdx;
+    iLeftView     = iView;
+    iRightView    = iView;
+    bFoundLRView  = false;
+  }
+
+  riLeftView           = iLeftView;
+  riRightView          = iRightView;
+  riLeftSortedViewIdx  = iLeftViewIdx;
+  riRightSortedViewIdx = iRightViewIdx;
+
+  return bFoundLRView;
+}
+
+
+Void
+TAppComCamPara::xGetPrevAndNextBaseView( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum )
+{
+  Int iLeftView;
+  Int iRightView;
+  Int iDummy;
+  xGetLeftRightView( iTargetViewNum, m_aiSortedBaseViews, iLeftView, iRightView, iDummy, iDummy );
+
+  if( iLeftView == iRightView )
+  {
+    riPrevBaseViewNum = iLeftView;
+    riNextBaseViewNum = iLeftView;
+  }
+  else
+  {
+    Bool bDecencdingVN   = ( m_aiSortedBaseViews.size() >= 2 && m_aiSortedBaseViews[ 0 ] > m_aiSortedBaseViews[ 1 ] );
+    Bool bNextViewIsLeft = ( bDecencdingVN ? ( iSourceViewNum < iTargetViewNum ) : ( iSourceViewNum > iTargetViewNum ) );
+    if ( bNextViewIsLeft )
+    {
+      riPrevBaseViewNum = iRightView;
+      riNextBaseViewNum = iLeftView;
+    }
+    else
+    {
+      riPrevBaseViewNum = iLeftView;
+      riNextBaseViewNum = iRightView;
+    }
+  }
+}
+
+
+Void
+TAppComCamPara::xGetZNearZFar( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar )
+{
+  UInt uiFoundLine = -1;
+  if( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) || !( m_aadCameraParameters[ uiFoundLine ].size() < 8 ) )
+  {
+    rdZNear = m_aadCameraParameters[ uiFoundLine ][ 6 ];
+    rdZFar  = m_aadCameraParameters[ uiFoundLine ][ 7 ];
+  }
+  else
+  {
+    std::cerr << "No ZNear or no ZFar for View " << (Double)iView / m_dViewNumPrec << " and Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
+    exit( EXIT_FAILURE );
+  }
+}
+
+
+Void
+TAppComCamPara::xGetGeometryData( Int iView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated )
+{
+  UInt uiFoundLine = -1;
+  if ( !xGetCameraDataRow( iView, uiFrame, uiFoundLine ) )
+  {
+    AOT( m_aadCameraParameters[ uiFoundLine ].size() < 6 );
+    rbInterpolated = false;
+    rdFocalLength =  m_aadCameraParameters[ uiFoundLine ][ 3 ];
+    rdPosition    =  m_aadCameraParameters[ uiFoundLine ][ 4 ];
+    rdCameraShift =  m_aadCameraParameters[ uiFoundLine ][ 5 ];
+  }
+  else
+  {
+    UInt uiLeftViewLine;
+    UInt uiRightViewLine;
+    Int  iLeftView;
+    Int  iRightView;
+    Int  iDummy;
+
+    if( !xGetLeftRightView( iView, m_aiViewsInCfgFile, iLeftView, iRightView, iDummy, iDummy ) ||
+         xGetCameraDataRow( iLeftView,  uiFrame, uiLeftViewLine  )                             ||
+         xGetCameraDataRow( iRightView, uiFrame, uiRightViewLine )
+      )
+    {
+      std::cerr << "No Left or no Right View next to View " << (Double)iView / m_dViewNumPrec << " for Frame " << uiFrame << " given in CameraParameterFile" << std::endl;
+      AOT(true);
+      exit( EXIT_FAILURE );
+    }
+    AOT( m_aadCameraParameters[ uiLeftViewLine  ].size() < 6 );
+    AOT( m_aadCameraParameters[ uiRightViewLine ].size() < 6 );
+
+    // Linear Interpolation
+    Double dFactor = ( (Double)( iView - iLeftView ) ) / ( (Double)( iRightView - iLeftView ) );
+    rdFocalLength  = m_aadCameraParameters[ uiLeftViewLine ][ 3 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 3 ] - m_aadCameraParameters[ uiLeftViewLine ][ 3 ] );
+    rdPosition     = m_aadCameraParameters[ uiLeftViewLine ][ 4 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 4 ] - m_aadCameraParameters[ uiLeftViewLine ][ 4 ] );
+    rdCameraShift  = m_aadCameraParameters[ uiLeftViewLine ][ 5 ] + dFactor * ( m_aadCameraParameters[ uiRightViewLine ][ 5 ] - m_aadCameraParameters[ uiLeftViewLine ][ 5 ] );
+    rbInterpolated = true;
+  }
+}
+
+Bool
+TAppComCamPara::xGetShiftParameterReal( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset )
+{
+  AOT( m_bSetupFromCoded );
+
+  Bool   bInterpolatedSource;
+  Double dMinDepthSource;
+  Double dMaxDepthSource;
+  Double dFocalLengthSource;
+  Double dPositionSource;
+  Double dIntersectionSource;
+
+  Bool   bInterpolatedTarget;
+  Double dPositionTarget;
+  Double dIntersectionTarget;
+  Double dFocalLengthTarget;
+
+  Int    iTargetViewNum;
+  Int    iSourceViewNum;
+
+  if( bByIdx )
+  {
+    iSourceViewNum = m_aiBaseViews[ uiSourceView ];
+    iTargetViewNum = ( bExternal ? m_aiSynthViews[ uiTargetView ] : m_aiBaseViews[ uiTargetView ] );
+  }
+  else
+  {
+    iSourceViewNum = (Int) uiSourceView;
+    iTargetViewNum = (Int) uiTargetView;
+  }
+
+  xGetGeometryData( iSourceViewNum, uiFrame, dFocalLengthSource, dPositionSource, dIntersectionSource, bInterpolatedSource );
+  xGetZNearZFar   ( iSourceViewNum, uiFrame, dMinDepthSource,    dMaxDepthSource );
+  xGetGeometryData( iTargetViewNum, uiFrame, dFocalLengthTarget, dPositionTarget, dIntersectionTarget, bInterpolatedTarget );
+
+  Double dFactor = dFocalLengthSource * ( dPositionTarget - dPositionSource );
+  rdScale        = dFactor * ( 1.0 / dMinDepthSource - 1.0 / dMaxDepthSource ) / (Double)( ( 1 << m_uiInputBitDepth ) - 1 );
+  rdOffset       = dFactor / dMaxDepthSource - dIntersectionTarget + dIntersectionSource;
+
+  return ( bInterpolatedSource || bInterpolatedTarget );
+}
+
+
+Void
+TAppComCamPara::xGetShiftParameterCoded( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bByIdx, Int& riScale, Int& riOffset )
+{
+  if ( m_bSetupFromCoded )
+  {
+    if ( uiSourceView == uiTargetView )
+    {
+      riScale  = 0;
+      riOffset = 0;
+      return;
+    }
+    Int iCamParsCodedPrecision;
+    xGetCodedCameraData( uiSourceView, uiTargetView,  bByIdx, uiFrame, riScale, riOffset, iCamParsCodedPrecision );
+
+    if ( m_bCamParsCodedPrecSet )
+    {
+      AOT( m_uiCamParsCodedPrecision != (UInt) iCamParsCodedPrecision );
+    }
+    else
+    {
+      m_uiCamParsCodedPrecision = (UInt) iCamParsCodedPrecision;
+      m_bCamParsCodedPrecSet    = true;
+    }
+  }
+  else
+  {
+  Double  dScale, dOffset;
+  Bool    bInterpolated = xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, false, bByIdx, dScale, dOffset );
+  AOT(    bInterpolated ); // must be base view
+
+  Double  dMultOffset   = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 ) );
+  Double  dMultScale    = (Double)( 1 << ( m_uiCamParsCodedPrecision + 1 + m_uiInputBitDepth ) );
+  riOffset              = (Int)floor( dMultOffset * dOffset + .5 );
+  riScale               = (Int)floor( dMultScale  * dScale  + .5 );
+}
+
+}
+
+
+Void
+TAppComCamPara::xGetShiftParameterInt( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64& riScale, Int64& riOffset )
+{
+  Int    iTargetViewNum;
+  Int    iSourceViewNum;
+  Int    iPrevBaseViewNum;
+  Int    iNextBaseViewNum;
+  Int    iTargetViewRelNum;
+
+  if( bByIdx )
+  {
+
+    iSourceViewNum = m_aiBaseViews[ uiSourceView ];
+
+    if ( bExternal )
+    {
+      iTargetViewNum    = m_aiSynthViews      [ uiTargetView ];
+      iTargetViewRelNum = m_aiRelSynthViewsNum[ uiTargetView ];
+    }
+    else
+    {
+      iTargetViewNum    = m_aiBaseViews       [ uiTargetView ];
+      iTargetViewRelNum = m_aiBaseId2SortedId [ uiTargetView ] * ((Int) m_dViewNumPrec );
+    }
+  }
+  else
+  {
+    iSourceViewNum = (Int) uiSourceView;
+    iTargetViewNum = (Int) uiTargetView;
+
+    if ( bExternal )
+    {
+      iTargetViewRelNum = m_aiRelSynthViewsNum[ xGetViewId( m_aiSynthViews, (Int) uiTargetView )];
+    }
+    else
+    {
+      iTargetViewRelNum = m_aiBaseId2SortedId[ xGetBaseViewId( uiTargetView) ] * ((Int) m_dViewNumPrec );
+    }
+  }
+  xGetPrevAndNextBaseView( iSourceViewNum, iTargetViewNum, iPrevBaseViewNum, iNextBaseViewNum );
+  AOT( iPrevBaseViewNum == -1 ); // should not happen
+  AOT( iNextBaseViewNum == -1 ); // should not happen
+
+  Int iSrcId    = xGetBaseViewId( iSourceViewNum   );
+  Int iPrevId   = xGetBaseViewId( iPrevBaseViewNum );
+  Int iNextId   = xGetBaseViewId( iNextBaseViewNum );
+  AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iPrevId ] ); // coded scale and offset must be set
+  AOF( m_aaiScaleAndOffsetSet[ iSrcId ][ iNextId ] ); // coded scale and offset must be set
+
+  Int iNextBaseViewRelNum = m_aiBaseId2SortedId[ iNextId ] * ((Int) m_dViewNumPrec );
+  Int iPrevBaseViewRelNum = m_aiBaseId2SortedId[ iPrevId ] * ((Int) m_dViewNumPrec );
+
+  Int64 iPrevScale  = (Int64)m_aaiCodedScale [ iSrcId ][ iPrevId ];
+  Int64 iNextScale  = (Int64)m_aaiCodedScale [ iSrcId ][ iNextId ];
+  Int64 iPrevOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iPrevId ] << m_uiBitDepthForLUT;
+  Int64 iNextOffset = (Int64)m_aaiCodedOffset[ iSrcId ][ iNextId ] << m_uiBitDepthForLUT;
+
+  if( iPrevBaseViewNum == iNextBaseViewNum )
+  {
+    riScale   = iNextScale;
+    riOffset  = iNextOffset;
+  }
+  else
+  {
+    riScale   = Int64( iTargetViewRelNum    - iPrevBaseViewRelNum ) * iNextScale;
+    riScale  += Int64( iNextBaseViewRelNum  - iTargetViewRelNum   ) * iPrevScale;
+    riOffset  = Int64( iTargetViewRelNum   - iPrevBaseViewRelNum ) * iNextOffset;
+    riOffset += Int64( iNextBaseViewRelNum - iTargetViewRelNum   ) * iPrevOffset;
+    Int64 iD  = Int64( iNextBaseViewRelNum - iPrevBaseViewRelNum );
+    Int64 iSA = ( riScale  > 0 ? iD / 2 : -iD / 2 );
+    Int64 iOA = ( riOffset > 0 ? iD / 2 : -iD / 2 );
+    riScale   = ( riScale  + iSA  ) / iD;
+    riOffset  = ( riOffset + iOA  ) / iD;
+  }
+}
+
+
+Void
+TAppComCamPara::xSetCodedScaleOffset( UInt uiFrame )
+{
+  for( UInt uiSourceId = 0; uiSourceId < m_iNumberOfBaseViews; uiSourceId++ )
+  {
+    for( UInt uiTargetId = 0; uiTargetId < m_iNumberOfBaseViews; uiTargetId++ )
+    {
+      Int iScale, iOffset;
+      xGetShiftParameterCoded( uiSourceId, uiTargetId, uiFrame, true, iScale, iOffset );
+      m_aaiCodedScale        [ uiSourceId ][ uiTargetId ] = iScale;
+      m_aaiCodedOffset       [ uiSourceId ][ uiTargetId ] = iOffset;
+      m_aaiScaleAndOffsetSet [ uiSourceId ][ uiTargetId ] = 1;
+    }
+  }
+}
+
+
+Void
+TAppComCamPara::xSetShiftParametersAndLUT( UInt uiNumberSourceViews, UInt uiNumberTargetViews, UInt uiFrame, Bool bExternalReference , Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams )
+{
+  if( uiNumberSourceViews <= 1 || uiNumberTargetViews == 0 )
+  {
+    return;
+  }
+  AOF( radShiftParams != NULL && raiShiftParams != NULL && radLUT != NULL && raiLUT != NULL );
+  AOF( m_uiBitDepthForLUT == 8 );
+
+  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
+  Int     iLog2DivChroma = iLog2DivLuma + 1;
+  Double  dMaxDispDev    = 0.0;
+  Double  dMaxRndDispDvL = 0.0;
+  Double  dMaxRndDispDvC = 0.0;
+  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
+  {
+    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
+    {
+
+      // integer-valued scale and offset
+      Int64 iScale, iOffset;
+      xGetShiftParameterInt ( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, iScale, iOffset );
+      raiShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = iScale;
+      raiShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = iOffset;
+
+      // offsets including rounding offsets
+      Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
+      Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
+
+      // real-valued scale and offset
+      Double dScale, dOffset;
+
+      if ( m_bSetupFromCoded )
+      {
+        dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
+        dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
+      }
+      else
+      {
+        xGetShiftParameterReal( uiSourceView, uiTargetView, uiFrame, bExternalReference, true, dScale, dOffset );
+      }
+
+      radShiftParams[ uiSourceView][ uiTargetView ][ 0 ] = dScale;
+      radShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = dOffset;
+
+      for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
+      {
+        // real-valued look-up tables
+        Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+        Double  dShiftChroma    = dShiftLuma / 2;
+        radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
+        radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
+
+        // integer-valued look-up tables
+        Int64   iTempScale      = (Int64)uiDepthValue * iScale;
+        Int64   iTestScale      = ( iTempScale + iOffset       );   // for checking accuracy of camera parameters
+        Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
+        Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
+        raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
+        raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
+
+        // maximum deviation
+        dMaxDispDev     = Max( dMaxDispDev,    fabs( Double( (Int) iTestScale   ) - dShiftLuma * Double( 1 << iLog2DivLuma ) ) / Double( 1 << iLog2DivLuma ) );
+        dMaxRndDispDvL  = Max( dMaxRndDispDvL, fabs( Double( (Int) iShiftLuma   ) - dShiftLuma   ) );
+        dMaxRndDispDvC  = Max( dMaxRndDispDvC, fabs( Double( (Int) iShiftChroma ) - dShiftChroma ) );
+      }
+
+      radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+      radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+      raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
+      raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
+    }
+  }
+
+  // check maximum deviation
+  Double  dMaxAllowedDispDev    =       Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision );       //  counting only the impact of camera parameter rounding
+  Double  dMaxAllowedRndDispDvL = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision );       // final rounding and impact of camera parameter rounding
+  Double  dMaxAllowedRndDispDvC = 0.5 + Double( 1 << m_iLog2Precision ) / Double( 1 << m_uiCamParsCodedPrecision ) / 2.0; // final rounding and impact of camera parameter rounding
+
+  if( ( dMaxDispDev >= dMaxAllowedDispDev || dMaxRndDispDvL >= dMaxAllowedRndDispDvL || dMaxRndDispDvC >= dMaxAllowedRndDispDvC ) && !m_bSetupFromCoded )
+  {
+    std::cout << "Warning: Something wrong with the accuracy of coded camera parameters:" << std::endl;
+    if( dMaxDispDev    >= dMaxAllowedDispDev    )
+    {
+      std::cout << "   max disparity difference is " << dMaxDispDev    << " (allowed: " << dMaxAllowedDispDev    << ")" << std::endl;
+    }
+    if( dMaxRndDispDvL >= dMaxAllowedRndDispDvL )
+    {
+      std::cout << "   max rnd luma   disp diff is " << dMaxRndDispDvL << " (allowed: " << dMaxAllowedRndDispDvL << ")" << std::endl;
+    }
+    if( dMaxRndDispDvC >= dMaxAllowedRndDispDvC )
+    {
+      std::cout << "   max rnd chroma disp diff is " << dMaxRndDispDvC << " (allowed: " << dMaxAllowedRndDispDvC << ")" << std::endl;
+    }
+  }
+}
+
+Void
+TAppComCamPara::xSetShiftParametersAndLUT( UInt uiFrame )
+{
+  xInit2dArray             ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiScaleAndOffsetSet, 0 );
+  xSetCodedScaleOffset     (                                                          uiFrame );
+  xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  uiFrame, false, m_adBaseViewShiftLUT,  m_aiBaseViewShiftLUT,  m_adBaseViewShiftParameter,  m_aiBaseViewShiftParameter  );
+  xSetShiftParametersAndLUT( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, uiFrame, true,  m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter );
+};
+
+
+Void
+TAppComCamPara::xGetCameraShifts( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift )
+{
+  Double  dDummy, dCamPosSource, dCamPosTarget, dPicPosSource, dPicPosTarget;
+  Bool    bInterpolatedSource, bInterpolatedTarget;
+  Int     iTargetViewNum = m_aiBaseViews[ uiTargetView ];
+  Int     iSourceViewNum = m_aiBaseViews[ uiSourceView ];
+
+  xGetGeometryData( iSourceViewNum, uiFrame, dDummy, dCamPosSource, dPicPosSource, bInterpolatedSource );
+  xGetGeometryData( iTargetViewNum, uiFrame, dDummy, dCamPosTarget, dPicPosTarget, bInterpolatedTarget );
+  AOT( bInterpolatedSource || bInterpolatedTarget );
+
+  rdCamPosShift =  ( dCamPosTarget - dCamPosSource );
+  rdPicPosShift = -( dPicPosTarget - dPicPosSource ); // to be consistent
+}
+
+
+Void
+TAppComCamPara::xSetPdmConversionParams()
+{
+  AOF( m_aiViewOrderIndex[ 0 ] == 0 );
+  if ( m_bSetupFromCoded || m_iNumberOfBaseViews    <  2 )
+  {
+    return;
+  }
+
+  //--- determine (virtual) camera parameter shift between view order index 1 and base view (view order index 0) ---
+  Double        dCamPosShift, dPicPosShift;
+  Int           iMinVOI       = (1<<30);
+  Int           iMinAbsVOI    = (1<<30);
+  Int           iMinAbsVOIId  = 0;
+  for( Int iBaseId = 1; iBaseId < m_iNumberOfBaseViews; iBaseId++ )
+  {
+    Int iAbsVOI = ( m_aiViewOrderIndex[ iBaseId ] < 0 ? -m_aiViewOrderIndex[ iBaseId ] : m_aiViewOrderIndex[ iBaseId ] );
+    if( iAbsVOI < iMinAbsVOI )
+    {
+      iMinVOI      = m_aiViewOrderIndex[ iBaseId ];
+      iMinAbsVOI   = iAbsVOI;
+      iMinAbsVOIId = iBaseId;
+    }
+  }
+  AOF( iMinAbsVOIId != 0 && iMinAbsVOI != 0 );
+  xGetCameraShifts( 0, iMinAbsVOIId, m_uiFirstFrameId, dCamPosShift, dPicPosShift );
+  Double  dCamPosShiftVOI01     = dCamPosShift / Double( iMinVOI );
+
+  //--- determine maximum absolute camera position shift, precision, and base scale ---
+  Double  dMaxAbsCamPosShift = 0.0;
+  for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ )
+  {
+    for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ )
+    {
+      xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift );
+      dCamPosShift        = ( dCamPosShift < 0.0                ? -dCamPosShift : dCamPosShift       );
+      dMaxAbsCamPosShift  = ( dCamPosShift > dMaxAbsCamPosShift ?  dCamPosShift : dMaxAbsCamPosShift );
+    }
+  }
+  Int     iPrecision  = 0;
+#if 0 // enabling this lines might be reasonable, but produces different results for the 2 view and 3 view test cases
+  Double  dEpsilon    = 1e-15;
+  Double  dAbsCamPosShiftVOI01  = ( dCamPosShiftVOI01 < 0.0 ? -dCamPosShiftVOI01 : dCamPosShiftVOI01 );
+  Double  dShiftRatio = dMaxAbsCamPosShift / dAbsCamPosShiftVOI01 - dEpsilon;
+  for( ; (Double)( 1 << iPrecision ) < dShiftRatio; iPrecision++ );
+#endif
+  Int     iPrecShift  = iPrecision + PDM_INTER_CALC_SHIFT + PDM_VIRT_DEPTH_PRECISION - 2;
+  AOF(    iPrecShift  < PDM_INTERNAL_CALC_BIT_DEPTH );
+  Int     iScaleVOI01 = 1 << iPrecShift;
+  m_iPdmPrecision     = iPrecision;
+
+  //--- loop over target views ---
+  for( Int iTargetId = 1; iTargetId < m_iNumberOfBaseViews; iTargetId++ )
+  {
+    // set scale and offset parameters for other views
+    for( Int iBaseId = 0; iBaseId < iTargetId; iBaseId++ )
+    {
+      xGetCameraShifts( (UInt)iBaseId, (UInt)iTargetId, m_uiFirstFrameId, dCamPosShift, dPicPosShift );
+      Double  dScale      = Double( iScaleVOI01 ) * dCamPosShiftVOI01 / dCamPosShift;
+      Int     iDiv        = m_aiViewOrderIndex[ iTargetId ] - m_aiViewOrderIndex[ iBaseId ];
+      Int     iAdd        = ( iDiv > 0 ? iDiv / 2 : -iDiv / 2 );
+      Int     iScalePred  = ( iScaleVOI01 + iAdd ) / iDiv;
+      Double  dFactor     = dScale / (Double)iScalePred * pow( 2.0, PDM_LOG4_SCALE_DENOMINATOR );
+      Int     iNominator  = (Int)floor( dFactor + .5 );
+      Int     iNomDelta   = iNominator - ( 1 << PDM_LOG4_SCALE_DENOMINATOR );
+      Int     iScale      = Int( ( (Int64)iNominator * (Int64)iScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR );
+      Double  dOffset     = -dPicPosShift * Double( iScale ) * pow( 2.0, 2 - PDM_OFFSET_SHIFT );
+      Int     iOffset     = (Int)floor( dOffset + .5 );
+
+      m_aaiPdmScaleNomDelta [ iTargetId ][ iBaseId ]  = iNomDelta;
+      m_aaiPdmOffset        [ iTargetId ][ iBaseId ]  = iOffset;
+    }
+  }
+}
+
+
+
+TAppComCamPara::TAppComCamPara()
+{
+  m_dViewNumPrec              = VIEW_NUM_PREC;  // fixed
+  m_iLog2Precision            = -1;
+  m_uiInputBitDepth           = 0;
+  m_uiBitDepthForLUT          = 8;              // fixed
+  m_uiFirstFrameId            = 0;
+  m_uiLastFrameId             = 0;
+
+  m_iNumberOfBaseViews        = -1;
+  m_iNumberOfSynthViews       = -1;
+
+  m_uiCamParsCodedPrecision   = 0;
+  m_bCamParsVaryOverTime      = true;
+
+  m_aaiCodedScale             = 0;
+  m_aaiCodedOffset            = 0;
+  m_aaiScaleAndOffsetSet      = 0;
+
+  m_iPdmPrecision             = 0;
+  m_aaiPdmScaleNomDelta       = 0;
+  m_aaiPdmOffset              = 0;
+
+  m_adBaseViewShiftParameter  = 0;
+  m_aiBaseViewShiftParameter  = 0;
+  m_adSynthViewShiftParameter = 0;
+  m_aiSynthViewShiftParameter = 0;
+
+  m_adBaseViewShiftLUT        = 0;
+  m_aiBaseViewShiftLUT        = 0;
+  m_adSynthViewShiftLUT       = 0;
+  m_aiSynthViewShiftLUT       = 0;
+
+  m_bSetupFromCoded           = false;
+  m_bCamParsCodedPrecSet      = false;
+
+
+}
+
+
+TAppComCamPara::~TAppComCamPara()
+{
+  xDeleteArray( m_adBaseViewShiftParameter,  m_iNumberOfBaseViews, m_iNumberOfBaseViews     );
+  xDeleteArray( m_aiBaseViewShiftParameter,  m_iNumberOfBaseViews, m_iNumberOfBaseViews     );
+  xDeleteArray( m_adBaseViewShiftLUT,        m_iNumberOfBaseViews, m_iNumberOfBaseViews,  2 );
+  xDeleteArray( m_aiBaseViewShiftLUT,        m_iNumberOfBaseViews, m_iNumberOfBaseViews,  2 );
+
+  xDeleteArray( m_adSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews));
+  xDeleteArray( m_aiSynthViewShiftParameter, m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews));
+  xDeleteArray( m_adSynthViewShiftLUT,       m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 );
+  xDeleteArray( m_aiSynthViewShiftLUT,       m_iNumberOfBaseViews, Max(1,m_iNumberOfSynthViews), 2 );
+
+  xDeleteArray( m_aaiCodedScale,             m_iNumberOfBaseViews );
+  xDeleteArray( m_aaiCodedOffset,            m_iNumberOfBaseViews );
+  xDeleteArray( m_aaiScaleAndOffsetSet,      m_iNumberOfBaseViews );
+
+  xDeleteArray( m_aaiPdmScaleNomDelta,       m_iNumberOfBaseViews );
+  xDeleteArray( m_aaiPdmOffset,              m_iNumberOfBaseViews );
+}
+
+Void
+TAppComCamPara::xSetupBaseViewsFromCoded()
+{
+  //===== get and sort views given in camera parameter file and set list of base views and related arrays =====
+  // get left-right order and coding order from cfg-file
+  std::vector<Int> aiViewOrderIdx;   // Left Right Order
+  std::vector<Int> aiViewId ;        // Coding     Order
+
+  Int iMinViewOrderIdx = MAX_INT;
+  for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ )
+  {
+    if (m_aadCameraParameters[uiRow].size() != 2 )
+      break;
+
+    Int iViewOrderIdx  = (Int)( m_aadCameraParameters[ uiRow ][ 1 ] );
+    iMinViewOrderIdx   = Min( iViewOrderIdx, iMinViewOrderIdx );
+
+    aiViewOrderIdx     .push_back( iViewOrderIdx );
+    aiViewId           .push_back( (Int) m_aadCameraParameters[ uiRow ][ 0 ]  );
+  }
+
+  // create base view numbers
+  AOT( aiViewId.size() != aiViewOrderIdx.size() );
+  m_iNumberOfBaseViews = (Int) aiViewId.size();
+  for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ )
+  {
+    aiViewOrderIdx[iCurBaseView] = ( aiViewOrderIdx[iCurBaseView] - iMinViewOrderIdx);
+    m_aiBaseViews      .push_back(  aiViewOrderIdx[iCurBaseView] * ( (Int) m_dViewNumPrec) );
+    m_aiBaseId2SortedId.push_back( iCurBaseView );
+    m_aiBaseSortedId2Id.push_back( iCurBaseView );
+
+  }
+
+  m_iNumberOfBaseViews = (Int) m_aiBaseViews.size();
+
+  std::vector<Int> aiSortedViewOrderIdx = aiViewOrderIdx;
+
+  // sort base views according to View Order Idx
+  m_aiSortedBaseViews = m_aiBaseViews;
+  for (Int iCurBaseView = 1; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ )
+  {
+    Int iCurViewOrder = aiSortedViewOrderIdx[iCurBaseView];
+    for (Int iCurSearchPos = iCurBaseView; iCurSearchPos >= 0; iCurSearchPos-- )
+    {
+      if ( iCurViewOrder < aiSortedViewOrderIdx[iCurSearchPos] )
+      {
+        Int iTempViewId = m_aiSortedBaseViews[iCurSearchPos];
+        m_aiSortedBaseViews[iCurSearchPos] = m_aiSortedBaseViews[iCurBaseView];
+        m_aiSortedBaseViews[iCurBaseView ] = iTempViewId;
+
+        Int iTempViewOrderIdx = aiSortedViewOrderIdx[iCurSearchPos];
+        aiSortedViewOrderIdx[iCurSearchPos] = aiSortedViewOrderIdx[iCurBaseView];
+        aiSortedViewOrderIdx[iCurBaseView ] = iTempViewOrderIdx;
+
+        Int iTempPos = m_aiBaseSortedId2Id[iCurSearchPos];
+        m_aiBaseSortedId2Id[iCurSearchPos] = m_aiBaseSortedId2Id[iCurBaseView];
+        m_aiBaseSortedId2Id[iCurBaseView] = iTempPos;
+        iCurBaseView--;
+      }
+    }
+  }
+
+  for (Int iCurBaseView = 0; iCurBaseView < m_iNumberOfBaseViews; iCurBaseView++ )
+  {
+    m_aiBaseId2SortedId[m_aiBaseSortedId2Id[iCurBaseView]] = iCurBaseView;
+  }
+
+  m_aiViewsInCfgFile = m_aiSortedBaseViews;
+
+  // check
+  if( m_aiViewsInCfgFile.size() < 2 )
+  {
+    std::cerr << "Failed reading camera parameter file" << std::endl;
+    std::cerr << "At least two views must be given" << std::endl;
+    AOT(true);
+    exit( EXIT_FAILURE );
+  }
+
+  // translate coding order to view order
+  for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ )
+{
+    if (m_aadCameraParameters[uiRow].size() == 2 )
+      continue;
+
+    m_aadCameraParameters[ uiRow ][ 2 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 2 ] ) ];
+    m_aadCameraParameters[ uiRow ][ 3 ] = (Double) aiViewOrderIdx[ xGetViewId( aiViewId, (Int) m_aadCameraParameters[ uiRow ][ 3 ] ) ];
+  }
+}
+
+Void TAppComCamPara::xSetupBaseViews( Char* pchBaseViewNumbers, UInt uiNumBaseViews )
+  {
+    // init list
+    std::vector<Int> aiViewsInCfg;
+    for( UInt uiRow = 0; uiRow < m_aadCameraParameters.size(); uiRow++ )
+    {
+      aiViewsInCfg.push_back( (Int)( m_aadCameraParameters[ uiRow ][ 0 ] * m_dViewNumPrec ) );
+    }
+    // remove duplicated items
+    std::sort( aiViewsInCfg.begin(), aiViewsInCfg.end() );
+    std::vector<Int>::iterator cIterNewEnd = std::unique( aiViewsInCfg.begin(), aiViewsInCfg.end() );
+    aiViewsInCfg.erase( cIterNewEnd, aiViewsInCfg.end() );
+    // sort (from left to right)
+    std::vector<Int> aiDummyI2SI, aiDummySI2I;
+    xGetSortedViewList( aiViewsInCfg, m_aiViewsInCfgFile, aiDummyI2SI, aiDummySI2I );
+    // check
+    if( m_aiViewsInCfgFile.size() < 2 )
+    {
+    std::cerr << "Failed reading config file" << std::endl;
+      std::cerr << "At least two views must be given" << std::endl;
+      exit( EXIT_FAILURE );
+    }
+
+
+
+  //===== set list of base views and related arrays =====
+  if( pchBaseViewNumbers == 0 )
+  {
+    std::cerr << "BaseViewCameraNumbers must be given" << std::endl;
+    exit( EXIT_FAILURE );
+  };
+
+  convertNumberString( pchBaseViewNumbers, m_aiBaseViews, m_dViewNumPrec  );
+  while( (UInt)m_aiBaseViews.size() > uiNumBaseViews )
+  {
+    m_aiBaseViews.pop_back();
+  }
+  xGetSortedViewList( m_aiBaseViews, m_aiSortedBaseViews, m_aiBaseId2SortedId, m_aiBaseSortedId2Id );
+  m_iNumberOfBaseViews = (Int)m_aiBaseViews.size();
+}
+
+
+Void
+TAppComCamPara::init( UInt   uiNumBaseViews,
+                      UInt   uiInputBitDepth,
+                      UInt   uiCodedCamParsPrecision,
+                      UInt   uiStartFrameId,
+                      UInt   uiNumFrames,
+                      Char*  pchCfgFileName,
+                      Char*  pchBaseViewNumbers,
+                      Char*  pchSynthViewNumbers,
+                      std::vector<Int>* paiSynthViewNumbers,
+                      Int    iLog2Precision )
+{
+  //===== set miscellaneous variables =====
+  m_uiInputBitDepth         = uiInputBitDepth;
+  m_uiFirstFrameId          = uiStartFrameId;
+  m_uiLastFrameId           = uiStartFrameId + uiNumFrames - 1;
+  m_uiCamParsCodedPrecision = uiCodedCamParsPrecision;
+  m_iLog2Precision          = iLog2Precision;
+#if HHI_INTERVIEW_SKIP
+  m_iCurrentFrameId         = 0 ;
+#endif
+
+  xReadCameraParameterFile( pchCfgFileName );
+
+  m_bSetupFromCoded         = ( m_aadCameraParameters[ 0 ].size() == 2 );
+
+  if ( m_bSetupFromCoded )
+  {
+    std::cout << "Detected decoded camera parameter file. Overwriting base view settings from cfg file. " << std::endl;
+    xSetupBaseViewsFromCoded();
+  }
+  else
+  {
+    xSetupBaseViews( pchBaseViewNumbers, uiNumBaseViews );
+  }
+
+  //===== set list of external (virtual) views =====
+  m_aiSynthViews.clear();
+
+  if( pchSynthViewNumbers != 0 || paiSynthViewNumbers != 0)
+  {
+    std::vector<Int> aiTmpSynthViews;
+
+    AOT( ( pchSynthViewNumbers != NULL ) && ( paiSynthViewNumbers != NULL ) );
+
+    if ( pchSynthViewNumbers != NULL )
+    {
+      convertNumberString( pchSynthViewNumbers, aiTmpSynthViews, m_dViewNumPrec );
+    }
+    else
+    {
+      aiTmpSynthViews = (*paiSynthViewNumbers);
+    }
+
+    for( UInt uiSId = 0; uiSId < (UInt)aiTmpSynthViews.size(); uiSId++ )
+    {
+
+      Int iViewNumPrec        = (Int) m_dViewNumPrec;
+      Int iLeftBaseViewIdx    =   aiTmpSynthViews[ uiSId ]                        / iViewNumPrec;
+      Int iRightBaseViewIdx   = ( aiTmpSynthViews[ uiSId ] + (iViewNumPrec - 1) ) / iViewNumPrec;
+
+      if ( iLeftBaseViewIdx < 0 || iRightBaseViewIdx >= m_iNumberOfBaseViews )
+      {
+        std::cerr << "SynthViewCameraNumbers must be greater and equal to 0 and smaller than number of base views" << std::endl;
+        AOT(true);
+        exit( EXIT_FAILURE );
+      }
+
+      Int64  iLeftBaseViewRelNum = iLeftBaseViewIdx  * iViewNumPrec;
+      Int64 iRightBaseViewRelNum = iRightBaseViewIdx * iViewNumPrec;
+
+      Int64 iDiffBaseViewRelNum  = iRightBaseViewRelNum - iLeftBaseViewRelNum;
+
+      Int64 iSynthViewRelNum     = aiTmpSynthViews[ uiSId ];
+      Int64 iLeftBaseNum         = m_aiSortedBaseViews[ iLeftBaseViewIdx  ];
+      Int64 iRightBaseNum        = m_aiSortedBaseViews[ iRightBaseViewIdx ];
+      Int64 iDiffBaseNum         = iRightBaseNum - iLeftBaseNum;
+      Int64 iSynthViewNum;
+
+      if ( iDiffBaseViewRelNum != 0)
+      {
+        AOT( (Int) iDiffBaseViewRelNum != iViewNumPrec );
+        Int iFact = iDiffBaseNum > 0 ? 1 : -1;
+        iSynthViewNum = iLeftBaseNum + ( iDiffBaseNum * ( iSynthViewRelNum - iLeftBaseViewRelNum ) + (iViewNumPrec >> 1) * iFact ) / ( iViewNumPrec );
+      }
+      else
+      {
+        iSynthViewNum = iLeftBaseNum;
+      }
+
+      m_aiRelSynthViewsNum.push_back(  aiTmpSynthViews[ uiSId ] );
+      m_aiSynthViews      .push_back(  (Int) iSynthViewNum  );
+    }
+  }
+  m_iNumberOfSynthViews = (Int)m_aiSynthViews.size();
+
+
+  //===== set derived parameters =====
+  xGetViewOrderIndices( m_aiBaseId2SortedId, m_aiViewOrderIndex );
+  m_bCamParsVaryOverTime = xGetCamParsChangeFlag();
+
+
+  //===== create arrays =====
+  xCreateLUTs   ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_adBaseViewShiftLUT,  m_aiBaseViewShiftLUT,  m_adBaseViewShiftParameter,  m_aiBaseViewShiftParameter  );
+  xCreateLUTs   ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfSynthViews, m_adSynthViewShiftLUT, m_aiSynthViewShiftLUT, m_adSynthViewShiftParameter, m_aiSynthViewShiftParameter );
+  xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiCodedScale           );
+  xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiCodedOffset          );
+  xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiScaleAndOffsetSet    );
+  xInit2dArray  ( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiScaleAndOffsetSet, 0 );
+
+  xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiPdmScaleNomDelta     );
+  xCreate2dArray( (UInt)m_iNumberOfBaseViews, (UInt)m_iNumberOfBaseViews,  m_aaiPdmOffset            );
+
+  //===== init disparity to virtual depth conversion parameters =====
+  xSetPdmConversionParams();
+
+  //===== init arrays for first frame =====
+  xSetShiftParametersAndLUT( m_uiFirstFrameId );
+}
+
+
+Void
+TAppComCamPara::check( Bool bCheckViewRange, Bool bCheckFrameRange )
+{
+  if( bCheckFrameRange )
+  {
+    Double dDummy;
+
+    for( UInt uiBaseView = 0; uiBaseView < m_aiBaseViews.size(); uiBaseView++ )
+    {
+      if ( m_bSetupFromCoded )
+      {
+        for( UInt uiTargetView = 0; uiTargetView < m_aiBaseViews.size(); uiTargetView++ )
+        {
+          if ( uiTargetView == uiBaseView )
+            continue;
+
+          for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ )
+          {
+            Int iDummy;
+
+            xGetCodedCameraData( uiBaseView, uiTargetView, true , uiFrame, iDummy, iDummy, iDummy );
+          }
+        }
+      }
+      else
+      {
+      for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ )
+      {
+        Bool bInterpolatedCur;
+        xGetGeometryData( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur );
+        xGetZNearZFar   ( m_aiBaseViews[ uiBaseView ], uiFrame, dDummy, dDummy );
+
+        if( bInterpolatedCur )
+        {
+          std::cerr << "Error: CameraParameters for BaseView " << (Double)m_aiBaseViews[ uiBaseView ] / m_dViewNumPrec << " and Frame " << uiFrame << " not defined. "  << std::endl;
+          exit( EXIT_FAILURE );
+        }
+      }
+
+      }
+    }
+
+    for( UInt uiERView = 0; uiERView < m_aiSynthViews.size() && !m_bSetupFromCoded; uiERView++ )
+    {
+      Bool bInterpolated = false;
+      for( UInt uiFrame = m_uiFirstFrameId; uiFrame <= m_uiLastFrameId; uiFrame++ )
+      {
+        Bool bInterpolatedCur;
+        xGetGeometryData( m_aiSynthViews[ uiERView ], uiFrame, dDummy, dDummy, dDummy, bInterpolatedCur );
+        bInterpolated |= bInterpolatedCur;
+      }
+      if( bInterpolated )
+      {
+        std::cout << "Interpolating Camera Parameters for View " << (Double)m_aiSynthViews[ uiERView ] / m_dViewNumPrec << std::endl;
+      }
+    }
+  }
+
+  if( bCheckViewRange )
+  {
+    Bool bAllExist = true;
+    for( Int iSynthViewIdx = 0; iSynthViewIdx < m_iNumberOfSynthViews; iSynthViewIdx++ )
+    {
+      Bool bIsBaseView;
+      Int  iDummy;
+      Bool bExist = getLeftRightBaseView( iSynthViewIdx, iDummy, iDummy, iDummy, bIsBaseView );
+      bAllExist  &= ( bExist || bIsBaseView );
+    }
+    if( !bAllExist )
+    {
+      std::cerr << "SynthViewNumbers must be within the range of BaseViewNumbers"  << std::endl;
+      exit( EXIT_FAILURE );
+    }
+  }
+}
+
+
+Void
+TAppComCamPara::update( UInt uiFrameId )
+{
+
+  m_iCurrentFrameId = uiFrameId;
+  m_bCamParsCodedPrecSet = false;
+
+  if ( m_bCamParsVaryOverTime )
+  {
+    xSetShiftParametersAndLUT( m_uiFirstFrameId + uiFrameId );
+  }
+}
+
+#if SAIT_VSO_EST_A0033
+Void
+TAppComCamPara::xSetDispCoeff( UInt uiFrameId, Int iViewIdx )
+{
+  UInt uiFrame = m_uiFirstFrameId + uiFrameId;
+  Int  iSourceViewNum = m_aiBaseViews[ iViewIdx ];
+  Double dBaseLine = 0.0;
+  Double dFL1, dCS1, dCP1, dZN1, dZF1; 
+  Bool bInterpolated;
+  double dPos[3];
+
+  if( m_iNumberOfBaseViews == 3 )
+  {
+    xGetGeometryData( m_aiBaseViews[0], uiFrame, dFL1, dPos[0], dCS1, bInterpolated );
+    xGetGeometryData( m_aiBaseViews[1], uiFrame, dFL1, dPos[1], dCS1, bInterpolated );
+    xGetGeometryData( m_aiBaseViews[2], uiFrame, dFL1, dPos[2], dCS1, bInterpolated );
+
+    xGetGeometryData( iSourceViewNum, uiFrame, dFL1, dCP1, dCS1, bInterpolated );
+    xGetZNearZFar   ( iSourceViewNum, uiFrame, dZN1, dZF1 );
+
+    dBaseLine = ( Max( dPos[0], Max( dPos[1], dPos[2] ) ) - Min( dPos[0], Min( dPos[1], dPos[2] ) ) ) / 2.0;
+  }
+  else if( m_iNumberOfBaseViews == 2 )
+  {
+    xGetGeometryData( m_aiBaseViews[0], uiFrame, dFL1, dPos[0], dCS1, bInterpolated );
+    xGetGeometryData( m_aiBaseViews[1], uiFrame, dFL1, dPos[1], dCS1, bInterpolated );
+
+    xGetGeometryData( iSourceViewNum, uiFrame, dFL1, dCP1, dCS1, bInterpolated );
+    xGetZNearZFar   ( iSourceViewNum, uiFrame, dZN1, dZF1 );
+
+    dBaseLine = dPos[0] - dPos[1];
+  }
+
+
+  m_dDispCoeff = fabs( dFL1 * ( dBaseLine / 2.0 ) / 255.0 * ( 1.0/dZN1 - 1.0/dZF1 ) );
+}
+#endif
+
+Bool
+TAppComCamPara::getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView )
+{
+  Int    iLeftSortedViewIdx, iRightSortedViewIdx, iDummy;
+  Bool   bExist  = xGetLeftRightView( m_aiSynthViews[ iSynthViewIdx ], m_aiSortedBaseViews, iDummy, iDummy, iLeftSortedViewIdx, iRightSortedViewIdx );
+  rbIsBaseView   = ( iLeftSortedViewIdx == iRightSortedViewIdx && iLeftSortedViewIdx != -1 );
+
+  Int iLeftViewIdx  = ( iLeftSortedViewIdx  != -1 ? m_aiBaseSortedId2Id[ iLeftSortedViewIdx  ] : -1 );
+  Int iRightViewIdx = ( iRightSortedViewIdx != -1 ? m_aiBaseSortedId2Id[ iRightSortedViewIdx ] : -1 );
+
+  if ( iLeftSortedViewIdx != -1 && iRightSortedViewIdx != -1 )
+  {
+    riRelDistToLeft = getRelDistLeft(  iSynthViewIdx, iLeftViewIdx, iRightViewIdx);
+  }
+  else
+  {
+    riRelDistToLeft = -1;
+  }
+
+  riLeftViewIdx  = iLeftViewIdx;
+  riRightViewIdx = iRightViewIdx;
+
+  return bExist;
+}
+
+Int TAppComCamPara::getRelDistLeft( Int iSynthViewIdx, Int iLeftViewIdx, Int iRightViewIdx )
+{
+  //GT: Get normalized distance
+  Int iLeftViewDist  = abs ( m_aiBaseId2SortedId[ iLeftViewIdx  ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]);
+  Int iRightViewDist = abs ( m_aiBaseId2SortedId[ iRightViewIdx ] * ((Int) m_dViewNumPrec) - m_aiRelSynthViewsNum [ iSynthViewIdx ]);
+  Int64 iDistSum = iLeftViewDist + iRightViewDist;
+  return (iDistSum == 0) ? (1 << (REN_VDWEIGHT_PREC -1) ) : (Int) (( (((Int64) iLeftViewDist ) << REN_VDWEIGHT_PREC ) + (iDistSum >> 1) )  / iDistSum );
+}
+
+Int
+TAppComCamPara::synthRelNum2Idx( Int iRelNum )
+{
+  return xGetViewId(m_aiRelSynthViewsNum, iRelNum );
+}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/TAppComCamPara.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/TAppComCamPara.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/TAppComCamPara.h	(revision 438)
@@ -0,0 +1,289 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+#ifndef __TAPPCOMCAMPARA__
+#define __TAPPCOMCAMPARA__
+
+// Include files
+#include "../../Lib/TLibCommon/CommonDef.h"
+#include <vector>
+
+
+#define LOG10_VIEW_NUM_PREC         5  // Precision of view numbering
+#define VIEW_NUM_PREC               pow( 10.0, (Int)LOG10_VIEW_NUM_PREC )
+
+// ====================================================================================================================
+// Class definition
+// ====================================================================================================================
+
+class TAppComCamPara
+{
+private:
+  // camera parameter data
+  std::vector< std::vector<Double> >  m_aadCameraParameters;  ///< buffer for double values from file
+
+  // miscellaneous variables
+  Double              m_dViewNumPrec;                         ///< factor for camera number to create integer representation
+  Int                 m_iLog2Precision;                       ///< shift precision in LUT
+  UInt                m_uiInputBitDepth;                      ///< bit depth of input depth maps
+  UInt                m_uiBitDepthForLUT;                     ///< bit depth used for table look-up
+  UInt                m_uiFirstFrameId;                       ///< first frame id
+  UInt                m_uiLastFrameId;                        ///< last frame id
+  UInt                m_iCurrentFrameId;                      ///< currently set frame id
+
+  Bool                m_bSetupFromCoded;                      ///< setup from coded parameter file
+  Bool                m_bCamParsCodedPrecSet;                 ///< Coded Cam Para precision set for current frame;
+
+#if SAIT_VSO_EST_A0033
+  Double              m_dDispCoeff;
+#endif
+
+  // view lists
+  std::vector<Int>    m_aiViewsInCfgFile;                     ///< views for which parameters are specified in cfg file (from left to right)
+  std::vector<Int>    m_aiSynthViews;                         ///< View numbers of External ViewReferences
+  std::vector<Int>    m_aiRelSynthViewsNum;                   ///< Relative view numbers of External ViewReferences
+  std::vector<Int>    m_aiBaseViews;                          ///< View numbers of Base View References (in coding order)
+  std::vector<Int>    m_aiSortedBaseViews;                    ///< View numbers of Base View References (from left to right)
+  std::vector<Int>    m_aiBaseId2SortedId;                    ///< mapping from coding order to left-right order for base views
+  std::vector<Int>    m_aiBaseSortedId2Id;                    ///< mapping from left-right order to coding order for base views
+  Int                 m_iNumberOfBaseViews;                   ///< number of base views
+  Int                 m_iNumberOfSynthViews;                  ///< number of synthesized views
+
+  // SPS and slice header related variables
+  std::vector<Int>    m_aiViewOrderIndex;                     ///< list of view order indices
+  UInt                m_uiCamParsCodedPrecision;              ///< precision for coding of camera parameters (x: max error in disparity is 2^(-x) luma samples)
+  Bool                m_bCamParsVaryOverTime;                 ///< flag specifying whether camera parameters vary for given frame numbers
+  Int**               m_aaiCodedScale;                        ///< array of coded scaling parameters [RefView][TargetView]
+  Int**               m_aaiCodedOffset;                       ///< array of coded offset  parameters [RefView][TargetView]
+  Int**               m_aaiScaleAndOffsetSet;                 ///< array indicating whether scale and offset have been set
+
+  // parameters for virtual depth map generation
+  Int                 m_iPdmPrecision;                        ///< additional precision for disparity - virtual depth conversion
+  Int**               m_aaiPdmScaleNomDelta;                  ///< [TargetView][RefView] delta for nominator of scale factor
+  Int**               m_aaiPdmOffset;                         ///< [TargetView][RefView] offset parameter
+
+  // scale and offset parameters
+  Double***           m_adBaseViewShiftParameter;             ///< ShiftParameters between BaseViews e.g. [2][1][0] shift scale from view 2 to view 1; [2][1][1] shift offset from view 2 to view 1
+  Int64 ***           m_aiBaseViewShiftParameter;             ///< ShiftParameters between BaseViews e.g. [2][1][0] shift scale from view 2 to view 1; [2][1][1] shift offset from view 2 to view 1     /* do we need 64 bit? */
+  Double***           m_adSynthViewShiftParameter;            ///< ShiftParameters between BaseViews and ERViews e.g. [2][1][0] shift scale from base view 2 to er view 1;
+  Int64 ***           m_aiSynthViewShiftParameter;            ///< ShiftParameters between BaseViews and ERViews e.g. [2][1][0] shift scale from base view 2 to er view 1;    /* do we need 64 bit? */
+
+  // look-up tables
+  Double****          m_adBaseViewShiftLUT;                    ///< Disparity LUT
+  Int****             m_aiBaseViewShiftLUT;                    ///< Disparity LUT
+  Double****          m_adSynthViewShiftLUT;                   ///< Disparity LUT
+  Int****             m_aiSynthViewShiftLUT;                   ///< Disparity LUT
+
+protected:
+  // create and delete arrays
+  Void                    xCreateLUTs   ( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams );
+  Void                    xCreate2dArray( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray );
+  Void                    xInit2dArray  ( UInt uiNum1Ids, UInt uiNum2Ids, Int**& raaiArray, Int iValue );
+  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 );
+  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize1, UInt uiSize2 );
+  template<class T> Void  xDeleteArray  ( T*& rpt, UInt uiSize );
+
+  // functions for reading, initialization, sorting, getting data, etc.
+  Void  xReadCameraParameterFile  ( Char* pchCfgFileName );
+  Bool  xGetCameraDataRow         ( Int iView, UInt uiFrame, UInt& ruiFoundLine );
+
+  Void  xGetSortedViewList        ( const std::vector<Int>& raiViews, std::vector<Int>& raiSortedViews, std::vector<Int>& raiId2SortedId, std::vector<Int>& raiSortedId2Id );
+  Void  xGetViewOrderIndices      ( const std::vector<Int>& raiId2SortedId, std::vector<Int>& raiVOIdx );
+  Bool  xGetCamParsChangeFlag     ();
+  Int   xGetBaseViewId            ( Int iBaseView );
+  Int   xGetViewId                 ( std::vector<Int> aiViewList, Int iBaseView );
+
+  Bool  xGetLeftRightView         ( Int iView, std::vector<Int> aiSortedViews, Int& riLeftView, Int& riRightView, Int& riLeftSortedViewIdx, Int& riRightSortedViewIdx );
+  Void  xGetPrevAndNextBaseView   ( Int iSourceViewNum, Int iTargetViewNum, Int& riPrevBaseViewNum, Int& riNextBaseViewNum );
+  Void  xGetZNearZFar             ( Int iView, UInt uiFrame, Double& rdZNear, Double& rdZFar );
+  Void  xGetGeometryData          ( Int dView, UInt uiFrame, Double& rdFocalLength, Double& rdPosition, Double& rdCameraShift, Bool& rbInterpolated );
+  Void  xSetupBaseViewsFromCoded  ();
+  Void  xSetupBaseViews           ( Char* pchBaseViewNumbers, UInt uiNumBaseViews );
+
+  // functions for getting and setting scales and offsets
+  Bool  xGetShiftParameterReal    ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Double& rdScale, Double& rdOffset );
+  Void  xGetShiftParameterCoded   ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame,                 Bool bByIdx, Int&    riScale, Int&    riOffset );
+  Void  xGetShiftParameterInt     ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Bool bExternal, Bool bByIdx, Int64&  riScale, Int64&  riOffset );
+  Void  xGetCodedCameraData       ( UInt uiSourceView, UInt uiTargetView, Bool bByIdx,  UInt uiFrame, Int& riScale, Int& riOffset, Int& riPrecision );
+
+  Void  xSetCodedScaleOffset      ( UInt uiFrame );
+  Void  xSetShiftParametersAndLUT ( UInt uiNumViewDim1, UInt uiNumViewDim2, UInt uiFrame, Bool bExternalReference, Double****& radLUT, Int****& raiLUT, Double***& radShiftParams, Int64***& raiShiftParams );
+  Void  xSetShiftParametersAndLUT ( UInt uiFrame );
+
+  // getting conversion parameters for disparity to virtual depth conversion
+  Void  xGetCameraShifts          ( UInt uiSourceView, UInt uiTargetView, UInt uiFrame, Double& rdCamPosShift, Double& rdPicPosShift );
+  Void  xSetPdmConversionParams   ();
+
+public:
+  // constructor and destructor
+  TAppComCamPara();
+  ~TAppComCamPara();
+
+  // initialization, check, and and update
+  Void init   ( UInt    uiNumBaseViews,
+                UInt    uiInputBitDepth,
+                UInt    uiCodedCamParsPrecision,
+                UInt    uiStartFrameId,
+                UInt    uiNumFrames,
+                Char*   pchCfgFileName,
+                Char*   pchBaseViewNumbers,
+                Char*   pchSynthViewNumbers,
+                std::vector<Int>* paiSynthViewNumbers,
+                Int     iLog2Precision );
+
+  Void init   ( UInt    uiInputBitDepth,
+                UInt    uiStartFrameId,
+                UInt    uiNumFrames,
+                Char*   pchCfgFileName,
+                Char*   pchSynthViewNumbers,
+                std::vector<Int>* paiSynthViewNumbers,
+                Int     iLog2Precision
+              );
+
+
+
+  Void check  ( Bool    bCheckViewRange,
+                Bool    bCheckFrameRange );
+  Void update ( UInt    uiFrameId );
+
+  // miscellaneous functions
+
+  Int                 synthRelNum2Idx           ( Int iRelNum );
+  Bool getLeftRightBaseView( Int iSynthViewIdx, Int &riLeftViewIdx, Int &riRightViewIdx, Int &riRelDistToLeft, Bool& rbIsBaseView );
+  Int                 getRelDistLeft            ( Int iSynthViewIdx, Int   iLeftViewIdx, Int iRightViewIdx );
+  UInt                getCurFrameId             ()  { return m_iCurrentFrameId;   }
+  static Void         convertNumberString       ( Char* pchViewNumberString, std::vector<Int>& raiViewNumbers, Double dViewNumPrec );
+
+#if SAIT_VSO_EST_A0033
+  Void xSetDispCoeff( UInt uiStartFrameId, Int iViewIdx );
+  Double getDispCoeff() { return m_dDispCoeff; }
+#endif
+
+  // function for getting parameters and parameter arrays
+  std::vector<Int>&   getBaseViewNumbers        ()  { return m_aiBaseViews;       }
+  std::vector<Int>&   getSortedBaseViewNumbers  ()  { return m_aiSortedBaseViews; }
+  std::vector<Int>&   getSynthViewNumbers       ()  { return m_aiSynthViews;      }
+  std::vector<Int>&   getRelSynthViewNumbers    ()  { return m_aiRelSynthViewsNum;}
+
+  std::vector<Int>&   getBaseId2SortedId        ()   { return m_aiBaseId2SortedId; }
+  std::vector<Int>&   getBaseSortedId2Id        ()   { return m_aiBaseSortedId2Id; }
+
+
+  Double***           getBaseViewShiftParameterD()  { return         m_adBaseViewShiftParameter;  }
+  Int***              getBaseViewShiftParameterI()  { return (Int***)m_aiBaseViewShiftParameter;  }
+
+  Double****          getSynthViewShiftLUTD     ()  { return m_adSynthViewShiftLUT;  }
+  Double****          getBaseViewShiftLUTD      ()  { return m_adBaseViewShiftLUT;   }
+  Int****             getSynthViewShiftLUTI     ()  { return m_aiSynthViewShiftLUT;  }
+  Int****             getBaseViewShiftLUTI      ()  { return m_aiBaseViewShiftLUT;   }
+
+  Bool                getVaryingCameraParameters()  { return m_bCamParsVaryOverTime;    }
+  UInt                getCamParsCodedPrecision  ()  { return m_uiCamParsCodedPrecision; }
+  std::vector<Int>&   getViewOrderIndex         ()  { return m_aiViewOrderIndex;        }
+  Int**               getCodedScale             ()  { return m_aaiCodedScale;           }
+  Int**               getCodedOffset            ()  { return m_aaiCodedOffset;          }
+
+  // parameters for virtual depth map generation
+  Int                 getPdmPrecision           ()  { return m_iPdmPrecision;           }
+  Int**               getPdmScaleNomDelta       ()  { return m_aaiPdmScaleNomDelta;     }
+  Int**               getPdmOffset              ()  { return m_aaiPdmOffset;            }
+};
+
+
+
+
+
+template <class T>
+Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 )
+{
+  if( rpt )
+  {
+    for( UInt uiK = 0; uiK < uiSize1; uiK++ )
+    {
+      for( UInt uiL = 0; uiL < uiSize2; uiL++ )
+      {
+        for( UInt uiM = 0; uiM < uiSize3; uiM++ )
+        {
+          delete[] rpt[ uiK ][ uiL ][ uiM ];
+        }
+        delete[] rpt[ uiK ][ uiL ];
+      }
+      delete[] rpt[ uiK ];
+    }
+    delete[] rpt;
+  }
+  rpt = NULL;
+};
+
+
+template <class T>
+Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2 )
+{
+  if( rpt )
+  {
+    for( UInt uiK = 0; uiK < uiSize1; uiK++ )
+    {
+      for( UInt uiL = 0; uiL < uiSize2; uiL++ )
+      {
+        delete[] rpt[ uiK ][ uiL ];
+      }
+      delete[] rpt[ uiK ];
+    }
+    delete[] rpt;
+  }
+  rpt = NULL;
+};
+
+
+template <class T>
+Void TAppComCamPara::xDeleteArray( T*& rpt, UInt uiSize )
+{
+  if( rpt )
+  {
+    for( UInt uiK = 0; uiK < uiSize; uiK++ )
+    {
+      delete[] rpt[ uiK ];
+    }
+    delete[] rpt;
+  }
+  rpt = NULL;
+};
+
+
+
+#endif // __TAPPCOMCAMPARA__
+
+
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/program_options_lite.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/program_options_lite.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TAppCommon/program_options_lite.h	(revision 438)
@@ -46,4 +46,5 @@
 #endif
 #endif
+
 //! \ingroup TAppCommon
 //! \{
@@ -282,4 +283,5 @@
     }
 #endif
+
     /** Option class for argument handling using a user provided function */
     struct OptionFunc : public OptionBase
@@ -380,4 +382,5 @@
       }
 #endif
+
       /**
        * Add option described by name to the parent Options list,
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/CommonDef.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/CommonDef.h	(revision 438)
@@ -57,8 +57,8 @@
 
 #if H_MV
-#define NV_VERSION        "0.2"                 ///< Current software version
-#define HM_VERSION        "10.1"                ///< 
-#else
-#define NV_VERSION        "10.1"                 ///< Current software version
+#define NV_VERSION        "0.1"                 ///< Current software version
+#define HM_VERSION        "10.0"                ///< 
+#else
+#define NV_VERSION        "10.0"                 ///< Current software version
 #endif
 
@@ -115,7 +115,5 @@
 #define MAX_NUM_REF_PICS            16          ///< max. number of pictures used for reference
 #define MAX_NUM_REF                 16          ///< max. number of entries in picture reference list
-#if !L0034_COMBINED_LIST_CLEANUP
 #define MAX_NUM_REF_LC              MAX_NUM_REF_PICS  // TODO: remove this macro definition (leftover from combined list concept)
-#endif
 
 #define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
@@ -138,4 +136,6 @@
 template <typename T> inline T ClipY(T x) { return std::min<T>(T((1 << g_bitDepthY)-1), std::max<T>( T(0), x)); }
 template <typename T> inline T ClipC(T x) { return std::min<T>(T((1 << g_bitDepthC)-1), std::max<T>( T(0), x)); }
+
+template <typename T> inline T Clip(T x) { return std::min<T>(T((1 << g_bitDepthY)-1), std::max<T>( T(0), x)); }
 
 /** clip a, such that minVal <= a <= maxVal */
@@ -168,4 +168,5 @@
 
 #endif
+
 
 // ====================================================================================================================
@@ -215,5 +216,5 @@
   
   NAL_UNIT_CODED_SLICE_TSA_N,     // 2
-  NAL_UNIT_CODED_SLICE_TLA_R,       // 3
+  NAL_UNIT_CODED_SLICE_TLA,       // 3   // Current name in the spec: TSA_R
   
   NAL_UNIT_CODED_SLICE_STSA_N,    // 4
@@ -221,33 +222,33 @@
 
   NAL_UNIT_CODED_SLICE_RADL_N,    // 6
-  NAL_UNIT_CODED_SLICE_RADL_R,      // 7
+  NAL_UNIT_CODED_SLICE_DLP,       // 7 // Current name in the spec: RADL_R
   
   NAL_UNIT_CODED_SLICE_RASL_N,    // 8
-  NAL_UNIT_CODED_SLICE_RASL_R,      // 9
-
-  NAL_UNIT_RESERVED_VCL_N10,
-  NAL_UNIT_RESERVED_VCL_R11,
-  NAL_UNIT_RESERVED_VCL_N12,
-  NAL_UNIT_RESERVED_VCL_R13,
-  NAL_UNIT_RESERVED_VCL_N14,
-  NAL_UNIT_RESERVED_VCL_R15,
-
-  NAL_UNIT_CODED_SLICE_BLA_W_LP,    // 16
-  NAL_UNIT_CODED_SLICE_BLA_W_RADL,  // 17
+  NAL_UNIT_CODED_SLICE_TFD,       // 9 // Current name in the spec: RASL_R
+
+  NAL_UNIT_RESERVED_10,
+  NAL_UNIT_RESERVED_11,
+  NAL_UNIT_RESERVED_12,
+  NAL_UNIT_RESERVED_13,
+  NAL_UNIT_RESERVED_14,
+  NAL_UNIT_RESERVED_15,
+
+  NAL_UNIT_CODED_SLICE_BLA,       // 16   // Current name in the spec: BLA_W_LP
+  NAL_UNIT_CODED_SLICE_BLANT,     // 17   // Current name in the spec: BLA_W_DLP
   NAL_UNIT_CODED_SLICE_BLA_N_LP,  // 18
-  NAL_UNIT_CODED_SLICE_IDR_W_RADL,  // 19
+  NAL_UNIT_CODED_SLICE_IDR,       // 19  // Current name in the spec: IDR_W_DLP
   NAL_UNIT_CODED_SLICE_IDR_N_LP,  // 20
   NAL_UNIT_CODED_SLICE_CRA,       // 21
-  NAL_UNIT_RESERVED_IRAP_VCL22,
-  NAL_UNIT_RESERVED_IRAP_VCL23,
-
-  NAL_UNIT_RESERVED_VCL24,
-  NAL_UNIT_RESERVED_VCL25,
-  NAL_UNIT_RESERVED_VCL26,
-  NAL_UNIT_RESERVED_VCL27,
-  NAL_UNIT_RESERVED_VCL28,
-  NAL_UNIT_RESERVED_VCL29,
-  NAL_UNIT_RESERVED_VCL30,
-  NAL_UNIT_RESERVED_VCL31,
+  NAL_UNIT_RESERVED_22,
+  NAL_UNIT_RESERVED_23,
+
+  NAL_UNIT_RESERVED_24,
+  NAL_UNIT_RESERVED_25,
+  NAL_UNIT_RESERVED_26,
+  NAL_UNIT_RESERVED_27,
+  NAL_UNIT_RESERVED_28,
+  NAL_UNIT_RESERVED_29,
+  NAL_UNIT_RESERVED_30,
+  NAL_UNIT_RESERVED_31,
 
   NAL_UNIT_VPS,                   // 32
@@ -258,13 +259,13 @@
   NAL_UNIT_EOB,                   // 37
   NAL_UNIT_FILLER_DATA,           // 38
-  NAL_UNIT_PREFIX_SEI,              // 39
-  NAL_UNIT_SUFFIX_SEI,              // 40
-  NAL_UNIT_RESERVED_NVCL41,
-  NAL_UNIT_RESERVED_NVCL42,
-  NAL_UNIT_RESERVED_NVCL43,
-  NAL_UNIT_RESERVED_NVCL44,
-  NAL_UNIT_RESERVED_NVCL45,
-  NAL_UNIT_RESERVED_NVCL46,
-  NAL_UNIT_RESERVED_NVCL47,
+  NAL_UNIT_SEI,                   // 39 Prefix SEI
+  NAL_UNIT_SEI_SUFFIX,            // 40 Suffix SEI
+  NAL_UNIT_RESERVED_41,
+  NAL_UNIT_RESERVED_42,
+  NAL_UNIT_RESERVED_43,
+  NAL_UNIT_RESERVED_44,
+  NAL_UNIT_RESERVED_45,
+  NAL_UNIT_RESERVED_46,
+  NAL_UNIT_RESERVED_47,
   NAL_UNIT_UNSPECIFIED_48,
   NAL_UNIT_UNSPECIFIED_49,
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/NAL.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/NAL.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/NAL.h	(revision 438)
@@ -47,4 +47,5 @@
   NalUnitType m_nalUnitType; ///< nal_unit_type
   UInt        m_temporalId;  ///< temporal_id
+
 #if H_MV
   Int         m_layerId;     ///< layer id
@@ -79,24 +80,24 @@
     return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA_R
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLANT
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_DLP
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R;
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TFD;
   }
 #if L0045_NON_NESTED_SEI_RESTRICTIONS
   Bool isSei()
   {
-    return m_nalUnitType == NAL_UNIT_PREFIX_SEI 
-        || m_nalUnitType == NAL_UNIT_SUFFIX_SEI;
+    return m_nalUnitType == NAL_UNIT_SEI 
+        || m_nalUnitType == NAL_UNIT_SEI_SUFFIX;
   }
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/SEI.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/SEI.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/SEI.cpp	(revision 438)
@@ -38,9 +38,4 @@
 #include "CommonDef.h"
 #include "SEI.h"
-
-#if J0149_TONE_MAPPING_SEI 
-//Table D-7 Meaning of camera iso sensitivity indicator and exposure index rating indicator
-Int  Table_exp_indicator[32] = {0, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, -1};
-#endif
 
 SEIMessages getSeisByType(SEIMessages &seiList, SEI::PayloadType seiType)
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/SEI.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/SEI.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/SEI.h	(revision 438)
@@ -355,58 +355,4 @@
 };
 
-#if L0208_SOP_DESCRIPTION_SEI
-class SEISOPDescription : public SEI
-{
-public:
-  PayloadType payloadType() const { return SOP_DESCRIPTION; }
-
-  SEISOPDescription() {}
-  virtual ~SEISOPDescription() {}
-
-  UInt m_sopSeqParameterSetId;
-  UInt m_numPicsInSopMinus1;
-
-  UInt m_sopDescVclNaluType[MAX_NUM_PICS_IN_SOP];
-  UInt m_sopDescTemporalId[MAX_NUM_PICS_IN_SOP];
-  UInt m_sopDescStRpsIdx[MAX_NUM_PICS_IN_SOP];
-  Int m_sopDescPocDelta[MAX_NUM_PICS_IN_SOP];
-};
-#endif
-
-#if J0149_TONE_MAPPING_SEI 
-class SEIToneMappingInfo : public SEI
-{
-public:
-  PayloadType payloadType() const { return TONE_MAPPING_INFO; }
-  SEIToneMappingInfo() {}
-  virtual ~SEIToneMappingInfo() {}
-
-  Int    m_toneMapId;
-  Bool   m_toneMapCancelFlag;
-  Bool   m_toneMapPersistenceFlag;
-  Int    m_codedDataBitDepth;
-  Int    m_targetBitDepth;
-  Int    m_modelId;
-  Int    m_minValue;
-  Int    m_maxValue;
-  Int    m_sigmoidMidpoint;
-  Int    m_sigmoidWidth;
-  std::vector<Int> m_startOfCodedInterval;
-  Int    m_numPivots;
-  std::vector<Int> m_codedPivotValue;
-  std::vector<Int> m_targetPivotValue;
-  Int    m_cameraIsoSpeedIdc;
-  Int    m_cameraIsoSpeedValue;
-  Int    m_exposureCompensationValueSignFlag;
-  Int    m_exposureCompensationValueNumerator;
-  Int    m_exposureCompensationValueDenomIdc;
-  Int    m_refScreenLuminanceWhite;
-  Int    m_extendedRangeWhiteLevel;
-  Int    m_nominalBlackLevelLumaCodeValue;
-  Int    m_nominalWhiteLevelLumaCodeValue;
-  Int    m_extendedWhiteLevelLumaCodeValue;
-};
-#endif
-
 typedef std::list<SEI*> SEIMessages;
 
@@ -420,35 +366,3 @@
 Void deleteSEIs (SEIMessages &seiList);
 
-#if K0180_SCALABLE_NESTING_SEI
-class SEIScalableNesting : public SEI
-{
-public:
-  PayloadType payloadType() const { return SCALABLE_NESTING; }
-
-  SEIScalableNesting() {}
-  virtual ~SEIScalableNesting()
-  {
-    if (!m_callerOwnsSEIs)
-    {
-      deleteSEIs(m_nestedSEIs);
-    }
-  }
-
-  Bool  m_bitStreamSubsetFlag;
-  Bool  m_nestingOpFlag;
-  Bool  m_defaultOpFlag;                             //value valid if m_nestingOpFlag != 0
-  UInt  m_nestingNumOpsMinus1;                       // -"-
-  UInt  m_nestingMaxTemporalIdPlus1[MAX_TLAYER];     // -"-
-  UInt  m_nestingOpIdx[MAX_NESTING_NUM_OPS];         // -"-
-
-  Bool  m_allLayersFlag;                             //value valid if m_nestingOpFlag == 0
-  UInt  m_nestingNoOpMaxTemporalIdPlus1;             //value valid if m_nestingOpFlag == 0 and m_allLayersFlag == 0
-  UInt  m_nestingNumLayersMinus1;                    //value valid if m_nestingOpFlag == 0 and m_allLayersFlag == 0
-  UChar m_nestingLayerId[MAX_NESTING_NUM_LAYER];     //value valid if m_nestingOpFlag == 0 and m_allLayersFlag == 0. This can e.g. be a static array of 64 unsigned char values
-
-  Bool  m_callerOwnsSEIs;
-  SEIMessages m_nestedSEIs;
-};
-#endif
-
 //! \}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComBitStream.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComBitStream.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComBitStream.cpp	(revision 438)
@@ -177,5 +177,4 @@
   }
 }
-
 Void TComOutputBitstream::writeByteAlignment()
 {
@@ -183,37 +182,4 @@
   writeAlignZero();
 }
-
-Int TComOutputBitstream::countStartCodeEmulations()
-{
-  UInt cnt = 0;
-  vector<uint8_t>& rbsp   = getFIFO();
-  for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
-  {
-    vector<uint8_t>::iterator found = it;
-    do
-    {
-      // find the next emulated 00 00 {00,01,02,03}
-      // NB, end()-1, prevents finding a trailing two byte sequence
-      found = search_n(found, rbsp.end()-1, 2, 0);
-      found++;
-      // if not found, found == end, otherwise found = second zero byte
-      if (found == rbsp.end())
-      {
-        break;
-      }
-      if (*(++found) <= 3)
-      {
-        break;
-      }
-    } while (true);
-    it = found;
-    if (found != rbsp.end())
-    {
-      cnt++;
-    }
-  }
-  return cnt;
-}
-
 /**
  * read #uiNumberOfBits# from bitstream without updating the bitstream
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComBitStream.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComBitStream.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComBitStream.h	(revision 438)
@@ -154,7 +154,4 @@
   Void          addSubstream    ( TComOutputBitstream* pcSubstream );
   Void writeByteAlignment();
-
-  //! returns the number of start code emulations contained in the current buffer
-  Int countStartCodeEmulations();
 };
 
@@ -166,5 +163,4 @@
 {
   std::vector<uint8_t> *m_fifo; /// FIFO for storage of complete bytes
-  std::vector<UInt> m_emulationPreventionByteLocation;
 
 protected:
@@ -210,11 +206,4 @@
   UInt  getNumBitsRead() { return m_numBitsRead; }
   Void readByteAlignment();
-
-  Void      pushEmulationPreventionByteLocation ( UInt pos )                  { m_emulationPreventionByteLocation.push_back( pos ); }
-  UInt      numEmulationPreventionBytesRead     ()                            { return (UInt) m_emulationPreventionByteLocation.size();    }
-  std::vector<UInt>  getEmulationPreventionByteLocation  ()                   { return m_emulationPreventionByteLocation;           }
-  UInt      getEmulationPreventionByteLocation  ( UInt idx )                  { return m_emulationPreventionByteLocation[ idx ];    }
-  Void      clearEmulationPreventionByteLocation()                            { m_emulationPreventionByteLocation.clear();          }
-  Void      setEmulationPreventionByteLocation  ( std::vector<UInt> vec )     { m_emulationPreventionByteLocation = vec;            }
 };
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 438)
@@ -3200,4 +3200,5 @@
   Bool bIsCurrRefLongTerm = m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getIsLongTerm();
   Bool bIsNeibRefLongTerm = false;
+
   //---------------  V1 (END) ------------------//
   if( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0)
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 438)
@@ -57,10 +57,10 @@
 // ====================================================================================================================
 
-const UChar TComLoopFilter::sm_tcTable[54] =
+const UChar tctable_8x8[54] =
 {
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,8,9,10,11,13,14,16,18,20,22,24
 };
 
-const UChar TComLoopFilter::sm_betaTable[52] =
+const UChar betatable_8x8[52] =
 {
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64
@@ -585,6 +585,6 @@
       Int iIndexB = Clip3(0, MAX_QP, iQP + (betaOffsetDiv2 << 1));
       
-      Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
-      Int iBeta = sm_betaTable[iIndexB]*iBitdepthScale;
+      Int iTc =  tctable_8x8[iIndexTC]*iBitdepthScale;
+      Int iBeta = betatable_8x8[iIndexB]*iBitdepthScale;
       Int iSideThreshold = (iBeta+(iBeta>>1))>>3;
       Int iThrCut = iTc*10;
@@ -735,5 +735,5 @@
 
         Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET*(ucBs - 1) + (tcOffsetDiv2 << 1));
-        Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
+        Int iTc =  tctable_8x8[iIndexTC]*iBitdepthScale;
 
         for ( UInt uiStep = 0; uiStep < uiPelsInPartChroma; uiStep++ )
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComLoopFilter.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComLoopFilter.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComLoopFilter.h	(revision 438)
@@ -99,7 +99,4 @@
   __inline Int xCalcDQ( Pel* piSrc, Int iOffset);
   
-  static const UChar sm_tcTable[54];
-  static const UChar sm_betaTable[52];
-
 public:
   TComLoopFilter();
@@ -114,10 +111,4 @@
   /// picture-level deblocking filter
   Void loopFilterPic( TComPic* pcPic );
-
-  static Int getBeta( Int qp )
-  {
-    Int indexB = Clip3( 0, MAX_QP, qp );
-    return sm_betaTable[ indexB ];
-  }
 };
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 438)
@@ -481,4 +481,3 @@
 #endif
 
-
 //! \}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPic.h	(revision 438)
@@ -93,4 +93,5 @@
 #endif
 #endif
+
 public:
   TComPic();
@@ -115,4 +116,5 @@
 #endif
 #endif
+
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
   Void          setUsedByCurr( Bool bUsed ) { m_bUsedByCurr = bUsed; }
@@ -184,4 +186,7 @@
   Void          print( Bool legend );
 #endif
+
+
+
   /** transfer ownership of seis to this picture */
   void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 438)
@@ -83,6 +83,6 @@
   if( m_piYuvExt == NULL )
   {
-    Int extWidth  = MAX_CU_SIZE + 16; 
-    Int extHeight = MAX_CU_SIZE + 1;
+    Int extWidth  = g_uiMaxCUWidth + 16; 
+    Int extHeight = g_uiMaxCUHeight + 1;
     Int i, j;
     for (i = 0; i < 4; i++)
@@ -94,18 +94,18 @@
       }
     }
-    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
-    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
+    m_iYuvExtHeight  = ((g_uiMaxCUHeight + 2) << 4);
+    m_iYuvExtStride = ((g_uiMaxCUWidth  + 8) << 4);
     m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
 
     // new structure
-    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
-    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
-
-    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
-  }
-
-  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
-  {
-    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
+    m_acYuvPred[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
+    m_acYuvPred[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
+
+    m_cYuvPredTemp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
+  }
+
+  if (m_iLumaRecStride != (g_uiMaxCUWidth>>1) + 1)
+  {
+    m_iLumaRecStride =  (g_uiMaxCUWidth>>1) + 1;
     if (!m_pLumaRecBuffer)
     {
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComRom.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComRom.cpp	(revision 438)
@@ -62,4 +62,5 @@
   g_aucConvertToBit[ i ] = c;
   
+  // g_auiFrameScanXY[ g_aucConvertToBit[ transformSize ] ]: zigzag scan array for transformSize
   c=2;
   for ( i=0; i<MAX_CU_DEPTH; i++ )
@@ -76,5 +77,7 @@
 Void destroyROM()
 {
-  for (Int i=0; i<MAX_CU_DEPTH; i++ )
+  Int i;
+  
+  for ( i=0; i<MAX_CU_DEPTH; i++ )
   {
     delete[] g_auiSigLastScan[0][i];
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 438)
@@ -49,5 +49,5 @@
 , m_iPOC                          ( 0 )
 , m_iLastIDR                      ( 0 )
-, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
+, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR )
 , m_eSliceType                    ( I_SLICE )
 , m_iSliceQp                      ( 0 )
@@ -60,8 +60,6 @@
 , m_deblockingFilterBetaOffsetDiv2 ( 0 )
 , m_deblockingFilterTcOffsetDiv2   ( 0 )
-#if !L0034_COMBINED_LIST_CLEANUP
 , m_bRefPicListModificationFlagLC ( false )
 , m_bRefPicListCombinationFlag    ( false )
-#endif
 , m_bCheckLDC                     ( false )
 , m_iSliceQpDelta                 ( 0 )
@@ -81,7 +79,5 @@
 , m_dLambda                       ( 0.0 )
 #endif
-#if !L0034_COMBINED_LIST_CLEANUP
 , m_bNoBackPredFlag               ( false )
-#endif
 , m_uiTLayer                      ( 0 )
 , m_bTLayerSwitchingFlag          ( false )
@@ -115,18 +111,8 @@
 #endif
 {
-#if L0034_COMBINED_LIST_CLEANUP
-  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
-#else
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
-#endif
   
   initEqualRef();
   
-#if L0034_COMBINED_LIST_CLEANUP
-  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
-  {
-    m_list1IdxToList0Idx[idx] = -1;
-  }
-#else
   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
   {
@@ -138,5 +124,4 @@
     m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
   }    
-#endif
   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
   {
@@ -150,5 +135,5 @@
 #endif
   }
-  resetWpScaling();
+  resetWpScaling(m_weightPredTable);
   initWpAcDcParam();
   m_saoEnabledFlag = false;
@@ -171,16 +156,12 @@
   m_colRefIdx = 0;
   initEqualRef();
-#if !L0034_COMBINED_LIST_CLEANUP
   m_bNoBackPredFlag = false;
   m_bRefPicListCombinationFlag = false;
   m_bRefPicListModificationFlagLC = false;
-#endif
   m_bCheckLDC = false;
   m_iSliceQpDeltaCb = 0;
   m_iSliceQpDeltaCr = 0;
 
-#if !L0034_COMBINED_LIST_CLEANUP
   m_aiNumRefIdx[REF_PIC_LIST_C]      = 0;
-#endif
 
   m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
@@ -196,9 +177,9 @@
 Bool TComSlice::getRapPicFlag()
 {
-  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
+      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
 }
@@ -270,28 +251,14 @@
 
 
-TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
+TComPic* TComSlice::xGetLongTermRefPic (TComList<TComPic*>& rcListPic,
+                                        Int                 poc)
 {
   TComList<TComPic*>::iterator  iterPic = rcListPic.begin();  
   TComPic*                      pcPic = *(iterPic);
   TComPic*                      pcStPic = pcPic;
-  
-  Int pocCycle = 1 << getSPS()->getBitsForPOC();
-  if (!pocHasMsb)
-  {
-    poc = poc % pocCycle;
-  }
-  
   while ( iterPic != rcListPic.end() )
   {
     pcPic = *(iterPic);
-    if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced())
-    {
-      Int picPoc = pcPic->getPOC();
-      if (!pocHasMsb)
-      {
-        picPoc = picPoc % pocCycle;
-      }
-      
-      if (poc == picPoc)
+    if(pcPic && (pcPic->getPOC()%(1<<getSPS()->getBitsForPOC())) == (poc%(1<<getSPS()->getBitsForPOC())))
     {
       if(pcPic->getIsLongTerm())
@@ -305,9 +272,7 @@
       break;
     }
-    }
 
     iterPic++;
   }
-  
   return  pcStPic;
 }
@@ -328,22 +293,4 @@
 }
 
-#if L0034_COMBINED_LIST_CLEANUP
-Void TComSlice::setList1IdxToList0Idx()
-{
-  Int idxL0, idxL1;
-  for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ )
-  {
-    m_list1IdxToList0Idx[idxL1] = -1;
-    for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ )
-    {
-      if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
-      {
-        m_list1IdxToList0Idx[idxL1] = idxL0;
-        break;
-      }
-    }
-  }
-}
-#else
 Void TComSlice::generateCombinedList()
 {
@@ -418,33 +365,23 @@
   }
 }
-#endif
 
 #if H_MV
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
-#else
-#if FIX1071
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer )
 #else
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
 #endif
-#endif
-{
-#if FIX1071
-  if (!checkNumPocTotalCurr)
-#endif
-  {
-    if (m_eSliceType == I_SLICE)
-    {
-      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
-      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-      
-      return;
-    }
+{
+  if (m_eSliceType == I_SLICE)
+  {
+    ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+    ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
     
+    return;
+  }
+  
 #if !H_MV
-    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
-    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-#endif
-  }
+  m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+  m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+#endif
 
   TComPic*  pcRefPic= NULL;
@@ -473,5 +410,4 @@
     }
   }
-  
   for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
   {
@@ -486,10 +422,9 @@
     }
   }
-  
   for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
   {
     if(m_pcRPS->getUsed(i))
     {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
       pcRefPic->setIsLongTerm(1);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -499,5 +434,5 @@
     if(pcRefPic==NULL) 
     {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
     }
     pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
@@ -513,62 +448,33 @@
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
 #endif
-#if FIX1071
-  if (checkNumPocTotalCurr)
-  {
-    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
+
+  {
+    Int cIdx = 0;
+    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
+    {
+      rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
+    }
+    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
+    {
+      rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
+    }
+    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+    {
+      rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
+    }
 #if H_MV
-    // – If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
-    if ( getRapPicFlag() && m_layerId == 0 )
-#else
-    // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
-    if (getRapPicFlag())
-#endif
-    {
-      assert(numPocTotalCurr == 0);
-    }
-
-    if (m_eSliceType == I_SLICE)
-    {
-      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
-      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-      
-      return;
-    }
-    
-    assert(numPocTotalCurr != 0);
-    
-    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
-    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-  }
-#endif
-
-  Int cIdx = 0;
-  for ( i=0; i<NumPocStCurr0; i++, cIdx++)
-  {
-    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
-  }
-  for ( i=0; i<NumPocStCurr1; i++, cIdx++)
-  {
-    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
-  }
-  for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
-  {
-    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
-  }
-#if H_MV
-  for ( i=0; i<numDirectRefLayers;  i++, cIdx++)
-  {
-    if( cIdx <= MAX_NUM_REF )
-    {
-      rpsCurrList0[cIdx] = refPicSetInterLayer[i];
-    }
-  }
-#endif
+    for ( i=0; i<numDirectRefLayers;  i++, cIdx++)
+    {
+      if( cIdx <= MAX_NUM_REF )
+      {
+        rpsCurrList0[cIdx] = refPicSetInterLayer[i];
+      }
+    }
+#endif
+  }
 
   if (m_eSliceType==B_SLICE)
   {
-    cIdx = 0;
+    Int cIdx = 0;
     for ( i=0; i<NumPocStCurr1; i++, cIdx++)
     {
@@ -679,5 +585,5 @@
 }
 
-Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
+Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA)
 {
   for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
@@ -692,15 +598,8 @@
     if(pocCRA < MAX_UINT && getPOC() > pocCRA)
     {
-      if (!pReferencePictureSet->getCheckLTMSBPresent(i))
-      {
-        assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA);
-      }
-      else
-      {
       assert(pReferencePictureSet->getPOC(i) >= pocCRA);
     }
   }
-  }
-  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
+  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
   {
     pocCRA = getPOC();
@@ -712,6 +611,6 @@
     prevRAPisBLA = false;
   }
-  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
+         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
          || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
   {
@@ -744,8 +643,8 @@
   Int pocCurr = getPOC(); 
 
-  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
     || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
     || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
   {
@@ -759,6 +658,6 @@
       iterPic++;
     }
-    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
+      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     {
@@ -774,8 +673,5 @@
       {
         rpcPic = *(iterPic);
-        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
-        {
-          rpcPic->getSlice(0)->setReferenced(false);
-        }
+        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) rpcPic->getSlice(0)->setReferenced(false);
         iterPic++;
       }
@@ -811,19 +707,9 @@
   m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
   
-#if L0034_COMBINED_LIST_CLEANUP
-  for (i = 0; i < 2; i++)
-#else
   for (i = 0; i < 3; i++)
-#endif
   {
     m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
   }
 
-#if L0034_COMBINED_LIST_CLEANUP
-  for (i = 0; i < MAX_NUM_REF; i++)
-  {
-    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
-  } 
-#else
   for (i = 0; i < 2; i++)
   {
@@ -842,5 +728,4 @@
   m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC;
   m_bRefPicListCombinationFlag    = pSrc->m_bRefPicListCombinationFlag;
-#endif
   m_bCheckLDC             = pSrc->m_bCheckLDC;
   m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
@@ -900,7 +785,5 @@
   }
 
-#if !L0034_COMBINED_LIST_CLEANUP
   m_bNoBackPredFlag      = pSrc->m_bNoBackPredFlag;
-#endif
   m_uiTLayer                      = pSrc->m_uiTLayer;
   m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
@@ -936,5 +819,4 @@
 
 Int TComSlice::m_prevPOC = 0;
-
 /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
  * \param uiTLayer Temporal layer ID of the current slice
@@ -997,14 +879,11 @@
   Int i, isReference;
 
+  Int j = 0;
   // loop through all pictures in the reference picture buffer
   TComList<TComPic*>::iterator iterPic = rcListPic.begin();
   while ( iterPic != rcListPic.end())
   {
+    j++;
     rpcPic = *(iterPic++);
-
-    if(!rpcPic->getSlice( 0 )->isReferenced())
-    {
-      continue;
-    }
 
     isReference = 0;
@@ -1045,5 +924,4 @@
     {            
       rpcPic->getSlice( 0 )->setReferenced( false );   
-      rpcPic->setUsedByCurr(0);
       rpcPic->setIsLongTerm(0);
     }
@@ -1051,8 +929,9 @@
     assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
     //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
-    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
+    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
     {
       assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
     }
+
     //check that pictures marked as temporal layer non-reference pictures are not used for reference
     if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
@@ -1068,5 +947,5 @@
 {
   TComPic* rpcPic;
-  Int i, isAvailable;
+  Int i, isAvailable, j;
   Int atLeastOneLost = 0;
   Int atLeastOneRemoved = 0;
@@ -1077,4 +956,5 @@
   for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
   {
+    j = 0;
     isAvailable = 0;
     // loop through all pictures in the reference picture buffer
@@ -1082,4 +962,5 @@
     while ( iterPic != rcListPic.end())
     {
+      j++;
       rpcPic = *(iterPic++);
       if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
@@ -1104,16 +985,8 @@
       while ( iterPic != rcListPic.end())
       {
+        j++;
         rpcPic = *(iterPic++);
 
-        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
-        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
-        Int refPoc = pReferencePictureSet->getPOC(i);
-        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
-        {
-          curPoc = curPoc % pocCycle;
-          refPoc = refPoc % pocCycle;
-        }
-        
-        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
+        if((rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == (this->getPOC() + pReferencePictureSet->getDeltaPOC(i))%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
         {
           isAvailable = 1;
@@ -1153,4 +1026,5 @@
   for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
   {
+    j = 0;
     isAvailable = 0;
     // loop through all pictures in the reference picture buffer
@@ -1158,4 +1032,5 @@
     while ( iterPic != rcListPic.end())
     {
+      j++;
       rpcPic = *(iterPic++);
 
@@ -1174,7 +1049,5 @@
         {
           if(printErrors)
-          {
             printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
-          }
           atLeastOneRemoved = 1;
         }
@@ -1182,7 +1055,5 @@
         {
           if(printErrors)
-          {
             printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
-          }
           atLeastOneLost = 1;
           iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
@@ -1330,5 +1201,5 @@
  * \returns Void
  */
-Void  TComSlice::resetWpScaling()
+Void  TComSlice::resetWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
 {
   for ( Int e=0 ; e<2 ; e++ )
@@ -1338,5 +1209,5 @@
       for ( Int yuv=0 ; yuv<3 ; yuv++ )
       {
-        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
+        wpScalingParam  *pwp = &(wp[e][i][yuv]);
         pwp->bPresentFlag      = false;
         pwp->uiLog2WeightDenom = 0;
@@ -1354,4 +1225,13 @@
 Void  TComSlice::initWpScaling()
 {
+  initWpScaling(m_weightPredTable);
+}
+
+/** set WP tables 
+ * \param wpScalingParam
+ * \returns Void
+ */
+Void  TComSlice::initWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
+{
   for ( Int e=0 ; e<2 ; e++ )
   {
@@ -1360,7 +1240,6 @@
       for ( Int yuv=0 ; yuv<3 ; yuv++ )
       {
-        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
-        if ( !pwp->bPresentFlag ) 
-        {
+        wpScalingParam  *pwp = &(wp[e][i][yuv]);
+        if ( !pwp->bPresentFlag ) {
           // Inferring values not present :
           pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
@@ -1396,12 +1275,9 @@
 , m_cprmsPresentFlag          (NULL)
 {
+
   for( Int i = 0; i < MAX_TLAYER; i++)
   {
     m_numReorderPics[i] = 0;
-#if L0323_DPB
-    m_uiMaxDecPicBuffering[i] = 1; 
-#else
     m_uiMaxDecPicBuffering[i] = 0; 
-#endif
     m_uiMaxLatencyIncrease[i] = 0;
   }
@@ -1457,7 +1333,7 @@
 TComVPS::~TComVPS()
 {
-if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
-  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
-  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
+  if( m_hrdParameters    != NULL )     delete m_hrdParameters;
+  if( m_hrdOpSetIdx      != NULL )     delete m_hrdOpSetIdx;
+  if( m_cprmsPresentFlag != NULL )     delete m_cprmsPresentFlag;
 }
 
@@ -1549,4 +1425,5 @@
 }
 #endif
+
 // ------------------------------------------------------------------------------------------------
 // Sequence parameter set (SPS)
@@ -1561,9 +1438,9 @@
 , m_picWidthInLumaSamples     (352)
 , m_picHeightInLumaSamples    (288)
-, m_log2MinCodingBlockSize    (  0)
-, m_log2DiffMaxMinCodingBlockSize (0)
 , m_uiMaxCUWidth              ( 32)
 , m_uiMaxCUHeight             ( 32)
 , m_uiMaxCUDepth              (  3)
+, m_uiMinTrDepth              (  0)
+, m_uiMaxTrDepth              (  1)
 , m_bLongTermRefsPresent      (false)
 , m_uiQuadtreeTULog2MaxSize   (  0)
@@ -1575,7 +1452,5 @@
 , m_pcmLog2MaxSize            (  5)
 , m_uiPCMLog2MinSize          (  7)
-#if !L0034_COMBINED_LIST_CLEANUP
 , m_bUseLComb                 (false)
-#endif
 , m_bitDepthY                 (  8)
 , m_bitDepthC                 (  8)
@@ -1595,16 +1470,9 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
-#if H_MV
-, m_interViewMvVertConstraintFlag (false)
-#endif
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
   {
     m_uiMaxLatencyIncrease[i] = 0;
-#if L0323_DPB
-    m_uiMaxDecPicBuffering[i] = 1;
-#else
     m_uiMaxDecPicBuffering[i] = 0;
-#endif
     m_numReorderPics[i]       = 0;
   }
@@ -1625,5 +1493,4 @@
   m_RPSList.create(numRPS);
 }
-
 Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
 {
@@ -1870,15 +1737,12 @@
   return m_POC[bufferNum];
 }
-
 Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
 {
   m_POC[bufferNum] = POC;
 }
-
 Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
 {
   return m_bCheckLTMSB[bufferNum];
 }
-
 Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
 {
@@ -2148,4 +2012,5 @@
 }
 #endif
+
 /** get scaling matrix from RefMatrixID
  * \param sizeId size index
@@ -2157,5 +2022,4 @@
   ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
 }
-
 /** parse syntax infomation 
  *  \param pchFile syntax infomation
@@ -2250,5 +2114,4 @@
   m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
 }
-
 /** destroy quantization matrix array
  */
@@ -2263,5 +2126,4 @@
   }
 }
-
 /** get default address of quantization matrix 
  * \param sizeId size index
@@ -2293,5 +2155,4 @@
   return src;
 }
-
 /** process of default matrix
  * \param sizeId size index
@@ -2303,5 +2164,4 @@
   setScalingListDC(sizeId,listId,SCALING_LIST_DC);
 }
-
 /** check DC value of matrix for default matrix signaling
  */
@@ -2364,5 +2224,5 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
-Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR)
 {
   TComPPS *pps = m_ppsMap.getPS(ppsId);
@@ -2373,7 +2233,7 @@
     // active parameter sets per layer should be used here
 #else
-    if (!isIRAP && (spsId != m_activeSPSId))
-    {
-      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
+    if (!isIDR && (spsId != m_activeSPSId))
+    {
+      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
       return false;
     }
@@ -2383,7 +2243,7 @@
     {
       Int vpsId = sps->getVPSId();
-      if (!isIRAP && (vpsId != m_activeVPSId))
-      {
-        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
+      if (!isIDR && (vpsId != m_activeVPSId))
+      {
+        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IDR.");
         return false;
       }
@@ -2444,4 +2304,5 @@
 }
 #endif
+
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
 TComBitRatePicRateInfo::TComBitRatePicRateInfo()
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComSlice.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComSlice.h	(revision 438)
@@ -248,4 +248,5 @@
   ProfileTierLevel* getGeneralPTL()  { return &m_generalPTL; }
   ProfileTierLevel* getSubLayerPTL(Int i)  { return &m_subLayerPTL[i]; }
+
 #if H_MV
   Void copyLevelFrom( TComPTL* source );
@@ -535,4 +536,5 @@
 
 #endif
+
 public:
   TComVPS();
@@ -594,4 +596,5 @@
   TComPTL* getPTL() { return &m_pcPTL; }
 #endif
+
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   TComBitRatePicRateInfo *getBitratePicrateInfo() { return &m_bitRatePicRateInfo; }
@@ -600,4 +603,5 @@
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
 #endif
+
 #if H_MV
   Void    setAvcBaseLayerFlag( Bool val )                                  { m_avcBaseLayerFlag = val;  }
@@ -901,12 +905,11 @@
   UInt        m_picHeightInLumaSamples;
   
-  Int         m_log2MinCodingBlockSize;
-  Int         m_log2DiffMaxMinCodingBlockSize;
+  Window      m_conformanceWindow;
+
   UInt        m_uiMaxCUWidth;
   UInt        m_uiMaxCUHeight;
   UInt        m_uiMaxCUDepth;
-
-  Window      m_conformanceWindow;
-
+  UInt        m_uiMinTrDepth;
+  UInt        m_uiMaxTrDepth;
   TComRPSList m_RPSList;
   Bool        m_bLongTermRefsPresent;
@@ -924,7 +927,5 @@
   Bool        m_useAMP;
 
-#if !L0034_COMBINED_LIST_CLEANUP
   Bool        m_bUseLComb;
-#endif
   
   // Parameter
@@ -967,7 +968,4 @@
   static const Int   m_winUnitY[MAX_CHROMA_FORMAT_IDC+1];
   TComPTL     m_pcPTL;
-#if H_MV
-  Bool        m_interViewMvVertConstraintFlag;
-#endif
 public:
   TComSPS();
@@ -1001,10 +999,4 @@
   Bool getUsedByCurrPicLtSPSFlag(Int i)        {return m_usedByCurrPicLtSPSFlag[i];}
   Void setUsedByCurrPicLtSPSFlag(Int i, Bool x)      { m_usedByCurrPicLtSPSFlag[i] = x;}
-
-  Int  getLog2MinCodingBlockSize() const           { return m_log2MinCodingBlockSize; }
-  Void setLog2MinCodingBlockSize(Int val)          { m_log2MinCodingBlockSize = val; }
-  Int  getLog2DiffMaxMinCodingBlockSize() const    { return m_log2DiffMaxMinCodingBlockSize; }
-  Void setLog2DiffMaxMinCodingBlockSize(Int val)   { m_log2DiffMaxMinCodingBlockSize = val; }
-
   Void setMaxCUWidth  ( UInt u ) { m_uiMaxCUWidth = u;      }
   UInt getMaxCUWidth  ()         { return  m_uiMaxCUWidth;  }
@@ -1023,4 +1015,8 @@
   Bool getUseAMP() { return m_useAMP; }
   Void setUseAMP( Bool b ) { m_useAMP = b; }
+  Void setMinTrDepth  ( UInt u ) { m_uiMinTrDepth = u;      }
+  UInt getMinTrDepth  ()         { return  m_uiMinTrDepth;  }
+  Void setMaxTrDepth  ( UInt u ) { m_uiMaxTrDepth = u;      }
+  UInt getMaxTrDepth  ()         { return  m_uiMaxTrDepth;  }
   Void setQuadtreeTULog2MaxSize( UInt u ) { m_uiQuadtreeTULog2MaxSize = u;    }
   UInt getQuadtreeTULog2MaxSize()         { return m_uiQuadtreeTULog2MaxSize; }
@@ -1044,8 +1040,6 @@
   
   // Tool list
-#if !L0034_COMBINED_LIST_CLEANUP
   Void setUseLComb    (Bool b)   { m_bUseLComb = b;         }
   Bool getUseLComb    ()         { return m_bUseLComb;      }
-#endif
 
   Bool getUseLossless ()         { return m_useLossless; }
@@ -1100,8 +1094,4 @@
 
   TComPTL* getPTL()     { return &m_pcPTL; }
-#if H_MV
-  Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
-  Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
-#endif
 };
 
@@ -1130,4 +1120,5 @@
   Void       setRefPicSetIdxL1(UInt idx, UInt refPicSetIdx) { m_RefPicSetIdxL1[idx] = refPicSetIdx; }
   UInt       getRefPicSetIdxL1(UInt idx) { return m_RefPicSetIdxL1[idx]; }
+
 #if H_MV
   // Why not an listIdx for all members, would avoid code duplication?? 
@@ -1366,8 +1357,5 @@
   Int         m_deblockingFilterBetaOffsetDiv2;    //< beta offset for deblocking filter
   Int         m_deblockingFilterTcOffsetDiv2;      //< tc offset for deblocking filter
-#if L0034_COMBINED_LIST_CLEANUP
-  Int         m_list1IdxToList0Idx[MAX_NUM_REF];
-  Int         m_aiNumRefIdx   [2];    //  for multiple reference of current slice
-#else
+  
   Int         m_aiNumRefIdx   [3];    //  for multiple reference of current slice
 
@@ -1379,5 +1367,4 @@
   Bool        m_bRefPicListModificationFlagLC;
   Bool        m_bRefPicListCombinationFlag;
-#endif
 
   Bool        m_bCheckLDC;
@@ -1420,7 +1407,6 @@
 
   Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
-#if !L0034_COMBINED_LIST_CLEANUP
+  
   Bool        m_bNoBackPredFlag;
-#endif
   UInt        m_uiTLayer;
   Bool        m_bTLayerSwitchingFlag;
@@ -1457,4 +1443,5 @@
 
   Bool       m_enableTMVPFlag;
+
 #if H_MV
   Int        m_layerId; 
@@ -1464,4 +1451,5 @@
 #endif
 #endif
+
 public:
   TComSlice();
@@ -1528,7 +1516,4 @@
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
   Int       getNumRpsCurrTempList();
-#if L0034_COMBINED_LIST_CLEANUP
-  Int       getList1IdxToList0Idx ( Int list1Idx )               { return m_list1IdxToList0Idx[list1Idx]; }
-#else
   Int       getRefIdxOfLC       (RefPicList e, Int iRefIdx)     { return m_iRefIdxOfLC[e][iRefIdx];           }
   Int       getListIdFromIdxOfLC(Int iRefIdx)                   { return m_eListIdFromIdxOfLC[iRefIdx];       }
@@ -1540,14 +1525,12 @@
   Bool      getRefPicListCombinationFlag()                      {return m_bRefPicListCombinationFlag;}
   Void      setRefPicListCombinationFlag(Bool bflag)            {m_bRefPicListCombinationFlag=bflag;}   
-#endif
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
   Bool      isReferenced()                                      { return m_bRefenced; }
   Void      setPOC              ( Int i )                       { m_iPOC              = i; if(getTLayer()==0) m_prevPOC=i; }
   Void      setNalUnitType      ( NalUnitType e )               { m_eNalUnitType      = e;      }
-  NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
+  NalUnitType getNalUnitType    ()                              { return m_eNalUnitType;        }
   Bool      getRapPicFlag       ();  
-  Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
-  Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
-  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
+  Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
+  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
   Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
@@ -1575,11 +1558,7 @@
 #endif
 #if H_MV
-  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& interLayerRefPicSet , Bool checkNumPocTotalCurr = false );
-#else
-#if FIX1071
-  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
+  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& interLayerRefPicSet );
 #else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
-#endif
 #endif
   Void      setRefPOCList       ();
@@ -1615,11 +1594,8 @@
   
   static Void      sortPicList         ( TComList<TComPic*>& rcListPic );
-#if L0034_COMBINED_LIST_CLEANUP
-  Void setList1IdxToList0Idx();
-#else
+  
   Bool getNoBackPredFlag() { return m_bNoBackPredFlag; }
   Void setNoBackPredFlag( Bool b ) { m_bNoBackPredFlag = b; }
   Void generateCombinedList       ();
-#endif
 
   UInt getTLayer             ()                            { return m_uiTLayer;                      }
@@ -1629,4 +1605,5 @@
   Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum ); 
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
+
 #if H_MV
   Void createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer );
@@ -1637,4 +1614,5 @@
   Void xPrintRefPicList();
 #endif
+
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
@@ -1677,5 +1655,6 @@
   Void  getWpScaling    ( RefPicList e, Int iRefIdx, wpScalingParam *&wp);
 
-  Void  resetWpScaling  ();
+  Void  resetWpScaling  (wpScalingParam  wp[2][MAX_NUM_REF][3]);
+  Void  initWpScaling    (wpScalingParam  wp[2][MAX_NUM_REF][3]);
   Void  initWpScaling   ();
   inline Bool applyWP   () { return( (m_eSliceType==P_SLICE && m_pcPPS->getUseWP()) || (m_eSliceType==B_SLICE && m_pcPPS->getWPBiPred()) ); }
@@ -1723,8 +1702,10 @@
 #endif
 #endif
+
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
                          Int                 poc);
-TComPic*  xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb);
+  TComPic*  xGetLongTermRefPic  (TComList<TComPic*>& rcListPic,
+                         Int                 poc);
 #if H_MV
   TComPic*  xGetInterLayerRefPic( std::vector<TComPic*>& rcListIlPic, Int layerId );
@@ -1813,5 +1794,5 @@
   //! activate a PPS and depending on isIDR parameter also SPS and VPS
   //! \returns true, if activation is successful
-  Bool activatePPS(Int ppsId, Bool isIRAP);
+  Bool activatePPS(Int ppsId, Bool isIDR);
 
   TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 438)
@@ -1986,5 +1986,5 @@
           }
           
-          if(piDstCoeff[minPos] == 32767 || piDstCoeff[minPos] == -32768)
+          if(piQCoef[minPos] == 32767 || piQCoef[minPos] == -32768)
           {
             finalChange = -1;
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TypeDef.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibCommon/TypeDef.h	(revision 438)
@@ -49,15 +49,6 @@
 #endif
 
-///// ***** HM 10.1 *********
-#define FIX1071 1 ///< Temporary fix for issue #1071
-
-#define L0208_SOP_DESCRIPTION_SEI     1 ///< L0208: add SOP descrioption SEI
-#define MAX_NUM_PICS_IN_SOP           1024
-
-#define K0180_SCALABLE_NESTING_SEI  1   ///JCTVC-K0180 scalable nesting sei message
-#define MAX_NESTING_NUM_OPS         1024
-#define MAX_NESTING_NUM_LAYER       64
-
-#define J0149_TONE_MAPPING_SEI        1 ///< J0149: Tone mapping information SEI
+///// ***** HM 10.0 *********
+
 #define L0363_DU_BIT_RATE             1 ///< L0363: add bit_rate_du_value_minus1 to HRD parameters
 #define L0328_SPLICING                1 ///< L0328: splicing support in HRD
@@ -84,11 +75,8 @@
 #define SIGNAL_BITRATE_PICRATE_IN_VPS               0  ///< K0125: Signal bit_rate and pic_rate in VPS
 #define L0232_RD_PENALTY           1  ///< L0232: RD-penalty for 32x32 TU for intra in non-intra slices
-#define L0386_DB_METRIC            1  ///< L0386: non-normative blockiness metric (automatically configures deblocking parameters in bitstream)
-#define L0323_DPB                     1 ///< L0323: Specification of active reference indices and decoded picture buffer
-
-#define L0034_COMBINED_LIST_CLEANUP 1
 
 #define MAX_VPS_NUM_HRD_PARAMETERS                1
 #define MAX_VPS_OP_SETS_PLUS1                     1024
+
 #if H_MV
 #define MAX_VPS_NUH_LAYER_ID_PLUS1  64
@@ -104,7 +92,5 @@
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
 #define MAX_NUM_LAYER_IDS               64
-#if H_MV
 #define MAX_NUM_LAYERS                  64
-#endif
 
 #define COEF_REMAIN_BIN_REDUCTION        3 ///< indicates the level at which the VLC 
@@ -426,7 +412,5 @@
   REF_PIC_LIST_0 = 0,   ///< reference list 0
   REF_PIC_LIST_1 = 1,   ///< reference list 1
-#if !L0034_COMBINED_LIST_CLEANUP
   REF_PIC_LIST_C = 2,   ///< combined reference list for uni-prediction in B-Slices
-#endif
   REF_PIC_LIST_X = 100  ///< special mark
 };
@@ -570,2 +554,3 @@
 #endif
 #endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/NALread.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/NALread.cpp	(revision 438)
@@ -50,18 +50,14 @@
 //! \ingroup TLibDecoder
 //! \{
-static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, TComInputBitstream *bitstream, Bool isVclNalUnit)
+static void convertPayloadToRBSP(vector<uint8_t>& nalUnitBuf, Bool isVclNalUnit)
 {
   UInt zeroCount = 0;
   vector<uint8_t>::iterator it_read, it_write;
 
-  UInt pos = 0;
-  bitstream->clearEmulationPreventionByteLocation();
-  for (it_read = it_write = nalUnitBuf.begin(); it_read != nalUnitBuf.end(); it_read++, it_write++, pos++)
+  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)
     {
-      bitstream->pushEmulationPreventionByteLocation( pos );
-      pos++;
       it_read++;
       zeroCount = 0;
@@ -113,8 +109,8 @@
   if ( nalu.m_temporalId )
   {
-    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
+    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_W_RADL
+         && 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
@@ -126,5 +122,5 @@
   else
   {
-    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R
+    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
@@ -140,8 +136,7 @@
   /* perform anti-emulation prevention */
   TComInputBitstream *pcBitstream = new TComInputBitstream(NULL);
-  convertPayloadToRBSP(nalUnitBuf, pcBitstream, (nalUnitBuf[0] & 64) == 0);
+  convertPayloadToRBSP(nalUnitBuf, (nalUnitBuf[0] & 64) == 0);
   
   nalu.m_Bitstream = new TComInputBitstream(&nalUnitBuf);
-  nalu.m_Bitstream->setEmulationPreventionByteLocation(pcBitstream->getEmulationPreventionByteLocation());
   delete pcBitstream;
   readNalUnitHeader(nalu);
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 438)
@@ -90,19 +90,4 @@
     fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
     break;
-#if J0149_TONE_MAPPING_SEI
-  case SEI::TONE_MAPPING_INFO:
-    fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
-    break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
-  case SEI::SOP_DESCRIPTION:
-    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
-    break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  case SEI::SCALABLE_NESTING:
-    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
-    break;
-#endif
   default:
     fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
@@ -169,5 +154,5 @@
   SEI *sei = NULL;
 
-  if(nalUnitType == NAL_UNIT_PREFIX_SEI)
+  if(nalUnitType == NAL_UNIT_SEI)
   {
     switch (payloadType)
@@ -234,22 +219,4 @@
       xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
       break;
-#if J0149_TONE_MAPPING_SEI
-    case SEI::TONE_MAPPING_INFO:
-      sei = new SEIToneMappingInfo;
-      xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
-      break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
-    case SEI::SOP_DESCRIPTION:
-      sei = new SEISOPDescription;
-      xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
-      break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-    case SEI::SCALABLE_NESTING:
-      sei = new SEIScalableNesting;
-      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
-      break;
-#endif
     default:
       for (UInt i = 0; i < payloadSize; i++)
@@ -317,13 +284,10 @@
     {
       UInt reservedPayloadExtensionData;
-      READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data");
+      READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data");
     }
 
     UInt dummy;
-    READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--;
-    while (payloadBitsRemaining)
-    {
-      READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--;
-    }
+    READ_CODE (1, dummy, "payload_bit_equal_to_one");
+    READ_CODE (payloadBitsRemaining-1, dummy, "payload_bit_equal_to_zero");
   }
 
@@ -668,162 +632,4 @@
 }
 
-#if J0149_TONE_MAPPING_SEI
-Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
-{
-  Int i;
-  UInt val;
-  READ_UVLC( val, "tone_map_id" );                         sei.m_toneMapId = val;
-  READ_FLAG( val, "tone_map_cancel_flag" );                sei.m_toneMapCancelFlag = val;
-
-  if ( !sei.m_toneMapCancelFlag )
-  {
-    READ_FLAG( val, "tone_map_persistence_flag" );         sei.m_toneMapPersistenceFlag = val; 
-    READ_CODE( 8, val, "coded_data_bit_depth" );           sei.m_codedDataBitDepth = val;
-    READ_CODE( 8, val, "target_bit_depth" );               sei.m_targetBitDepth = val;
-    READ_UVLC( val, "model_id" );                          sei.m_modelId = val; 
-    switch(sei.m_modelId)
-    {
-    case 0:
-      {
-        READ_CODE( 32, val, "min_value" );                 sei.m_minValue = val;
-        READ_CODE( 32, val, "max_value" );                 sei.m_maxValue = val;
-        break;
-      }
-    case 1:
-      {
-        READ_CODE( 32, val, "sigmoid_midpoint" );          sei.m_sigmoidMidpoint = val;
-        READ_CODE( 32, val, "sigmoid_width" );             sei.m_sigmoidWidth = val;
-        break;
-      }
-    case 2:
-      {
-        UInt num = 1u << sei.m_targetBitDepth;
-        sei.m_startOfCodedInterval.resize(num+1);
-        for(i = 0; i < num; i++)
-        {
-          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" );
-          sei.m_startOfCodedInterval[i] = val;
-        }
-        sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth;
-        break;
-      }
-    case 3:
-      {
-        READ_CODE( 16, val,  "num_pivots" );                       sei.m_numPivots = val;
-        sei.m_codedPivotValue.resize(sei.m_numPivots);
-        sei.m_targetPivotValue.resize(sei.m_numPivots);
-        for(i = 0; i < sei.m_numPivots; i++ )
-        {
-          READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" );
-          sei.m_codedPivotValue[i] = val;
-          READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3),    val, "target_pivot_value" );
-          sei.m_targetPivotValue[i] = val;
-        }
-        break;
-      }
-    case 4:
-      {
-        READ_CODE( 8, val, "camera_iso_speed_idc" );                     sei.m_cameraIsoSpeedValue = val;
-        if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO
-        {
-          READ_CODE( 32,   val,   "camera_iso_speed_value" );            sei.m_cameraIsoSpeedValue = val;
-        }
-        READ_FLAG( val, "exposure_compensation_value_sign_flag" );       sei.m_exposureCompensationValueSignFlag = val;
-        READ_CODE( 16, val, "exposure_compensation_value_numerator" );   sei.m_exposureCompensationValueNumerator = val;
-        READ_CODE( 16, val, "exposure_compensation_value_denom_idc" );   sei.m_exposureCompensationValueDenomIdc = val;
-        READ_CODE( 32, val, "ref_screen_luminance_white" );              sei.m_refScreenLuminanceWhite = val;
-        READ_CODE( 32, val, "extended_range_white_level" );              sei.m_extendedRangeWhiteLevel = val;
-        READ_CODE( 16, val, "nominal_black_level_luma_code_value" );     sei.m_nominalBlackLevelLumaCodeValue = val;
-        READ_CODE( 16, val, "nominal_white_level_luma_code_value" );     sei.m_nominalWhiteLevelLumaCodeValue= val;
-        READ_CODE( 16, val, "extended_white_level_luma_code_value" );    sei.m_extendedWhiteLevelLumaCodeValue = val;
-        break;
-      }
-    default:
-      {
-        assert(!"Undefined SEIToneMapModelId");
-        break;
-      }
-    }//switch model id
-  }// if(!sei.m_toneMapCancelFlag) 
-
-  xParseByteAlign();
-}
-#endif
-
-#if L0208_SOP_DESCRIPTION_SEI
-Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
-{
-  Int iCode;
-  UInt uiCode;
-
-  READ_UVLC( uiCode,           "sop_seq_parameter_set_id"            ); sei.m_sopSeqParameterSetId = uiCode;
-  READ_UVLC( uiCode,           "num_pics_in_sop_minus1"              ); sei.m_numPicsInSopMinus1 = uiCode;
-  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
-  {
-    READ_CODE( 6, uiCode,                     "sop_desc_vcl_nalu_type" );  sei.m_sopDescVclNaluType[i] = uiCode;
-    READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id"   );  sei.m_sopDescTemporalId[i] = uiCode;
-    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
-    {
-      READ_UVLC( sei.m_sopDescStRpsIdx[i],    "sop_desc_st_rps_idx"    ); sei.m_sopDescStRpsIdx[i] = uiCode;
-    }
-    if (i > 0)
-    {
-      READ_SVLC( iCode,                       "sop_desc_poc_delta"     ); sei.m_sopDescPocDelta[i] = iCode;
-    }
-  }
-
-  xParseByteAlign();
-}
-#endif
-
-#if K0180_SCALABLE_NESTING_SEI
-Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
-{
-  UInt uiCode;
-  SEIMessages seis;
-
-  READ_FLAG( uiCode,            "bitstream_subset_flag"         ); sei.m_bitStreamSubsetFlag = uiCode;
-  READ_FLAG( uiCode,            "nesting_op_flag"               ); sei.m_nestingOpFlag = uiCode;
-  if (sei.m_nestingOpFlag)
-  {
-    READ_FLAG( uiCode,            "default_op_flag"               ); sei.m_defaultOpFlag = uiCode;
-    READ_UVLC( uiCode,            "nesting_num_ops_minus1"        ); sei.m_nestingNumOpsMinus1 = uiCode;
-    for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++)
-    {
-      READ_CODE( 3,        uiCode,  "nesting_max_temporal_id_plus1"   ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode;
-      READ_UVLC( uiCode,            "nesting_op_idx"                  ); sei.m_nestingOpIdx[i] = uiCode;
-    }
-  }
-  else
-  {
-    READ_FLAG( uiCode,            "all_layers_flag"               ); sei.m_allLayersFlag       = uiCode;
-    if (!sei.m_allLayersFlag)
-    {
-      READ_CODE( 3,        uiCode,  "nesting_no_op_max_temporal_id_plus1"  ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode;
-      READ_UVLC( uiCode,            "nesting_num_layers_minus1"            ); sei.m_nestingNumLayersMinus1        = uiCode;
-      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
-      {
-        READ_CODE( 6,           uiCode,     "nesting_layer_id"      ); sei.m_nestingLayerId[i]   = uiCode;
-      }
-    }
-  }
-
-  // byte alignment
-  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
-  {
-    UInt code;
-    READ_FLAG( code, "nesting_zero_bit" );
-  }
-
-  sei.m_callerOwnsSEIs = false;
-
-  // read nested SEI messages
-  do {
-    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
-  } while (m_pcBitstream->getNumBitsLeft() > 8);
-
-}
-#endif
-
 Void SEIReader::xParseByteAlign()
 {
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/SEIread.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/SEIread.h	(revision 438)
@@ -70,13 +70,4 @@
   Void xParseSEITemporalLevel0Index   (SEITemporalLevel0Index &sei, UInt payloadSize);
   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
-#if J0149_TONE_MAPPING_SEI
-  Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
-  Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
-#endif
   Void xParseByteAlign();
 };
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 438)
@@ -175,4 +175,32 @@
 }
 
+/** copy SAO parameter
+* \param dst  
+* \param src 
+*/
+inline Void copySaoOneLcuParam(SaoLcuParam* dst,  SaoLcuParam* src)
+{
+  Int i;
+  dst->partIdx = src->partIdx;
+  dst->typeIdx = src->typeIdx;
+  if (dst->typeIdx != -1)
+  {
+    dst->subTypeIdx = src->subTypeIdx ;
+    dst->length  = src->length;
+    for (i=0;i<dst->length;i++)
+    {
+      dst->offset[i] = src->offset[i];
+    }
+  }
+  else
+  {
+    dst->length  = 0;
+    for (i=0;i<SAO_BO_LEN;i++)
+    {
+      dst->offset[i] = 0;
+    }
+  }
+}
+
 Void TDecCavlc::parsePPS(TComPPS* pcPPS)
 {
@@ -372,4 +400,5 @@
 
   READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
+  assert(pcVUI->getFieldSeqFlag() == false);        // not supported yet
 
   READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
@@ -564,9 +593,11 @@
 
   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
-  pcSPS->setBitDepthY( uiCode + 8 );
+  g_bitDepthY = 8 + uiCode;
+  pcSPS->setBitDepthY(g_bitDepthY);
   pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
 
   READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
-  pcSPS->setBitDepthC( uiCode + 8 );
+  g_bitDepthC = 8 + uiCode;
+  pcSPS->setBitDepthC(g_bitDepthC);
   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
 
@@ -577,26 +608,9 @@
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
-#if H_MV
-    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1[i]");
-#else
-    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
-#endif
-    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
-#else
     READ_UVLC ( uiCode, "sps_max_dec_pic_buffering");
     pcSPS->setMaxDecPicBuffering( uiCode, i);
-#endif
-#if H_MV
-    READ_UVLC ( uiCode, "sps_num_reorder_pics[i]" );
-#else
     READ_UVLC ( uiCode, "sps_num_reorder_pics" );
-#endif
     pcSPS->setNumReorderPics(uiCode, i);
-#if H_MV
-    READ_UVLC ( uiCode, "sps_max_latency_increase[i]");
-#else
     READ_UVLC ( uiCode, "sps_max_latency_increase");
-#endif
     pcSPS->setMaxLatencyIncrease( uiCode, i );
 
@@ -614,11 +628,9 @@
 
   READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
-  Int log2MinCUSize = uiCode + 3;
-  pcSPS->setLog2MinCodingBlockSize(log2MinCUSize);
+  UInt log2MinCUSize = uiCode + 3;
   READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
-  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
-  Int maxCUDepthDelta = uiCode;
-  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
-  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
+  UInt uiMaxCUDepthCorrect = uiCode;
+  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUWidth  = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
+  pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUHeight = 1<<(log2MinCUSize + uiMaxCUDepthCorrect);
   READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
 
@@ -628,8 +640,14 @@
   READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" );    pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 );
   READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" );    pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 );
-
-  Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
-  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
-
+  g_uiAddCUDepth = 0;
+  while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth )  ) )
+  {
+    g_uiAddCUDepth++;
+  }
+  pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth  ); 
+  g_uiMaxCUDepth  = uiMaxCUDepthCorrect+g_uiAddCUDepth;
+  // BB: these parameters may be removed completly and replaced by the fixed values
+  pcSPS->setMinTrDepth( 0 );
+  pcSPS->setMaxTrDepth( 1 );
   READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
   if(pcSPS->getScalingListFlag())
@@ -692,12 +710,8 @@
   if (uiCode)
   {
-#if H_MV
-    READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
-#else
     while ( xMoreRbspData() )
     {
       READ_FLAG( uiCode, "sps_extension_data_flag");
     }
-#endif
   }
 }
@@ -706,5 +720,5 @@
 {
   UInt  uiCode;
-   
+  
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
@@ -730,9 +744,5 @@
   for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
-    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
-#else
     READ_UVLC( uiCode,  "vps_max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
-#endif
     READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
     READ_UVLC( uiCode,  "vps_max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
@@ -1042,6 +1052,6 @@
         iPOCmsb = iPrevPOCmsb;
       }
-      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
+        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
       {
@@ -1052,10 +1062,10 @@
 
       TComReferencePictureSet* rps;
-      rps = rpcSlice->getLocalRPS();
-      rpcSlice->setRPS(rps);
       READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
       if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
       {
+        rps = rpcSlice->getLocalRPS();
         parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
+        rpcSlice->setRPS(rps);
       }
       else // use reference to short-term reference picture set in PPS
@@ -1074,5 +1084,7 @@
           uiCode = 0;
         }
-        memcpy(rps,sps->getRPSList()->getReferencePictureSet(uiCode),sizeof(TComReferencePictureSet));
+        rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode));
+
+        rps = rpcSlice->getRPS();
       }
       if(sps->getLongTermRefsPresent())
@@ -1097,5 +1109,5 @@
         rps->setNumberOfLongtermPictures(numOfLtrp);
         Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC();
-        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
+        Int prevLSB = 0, prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;;
         for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
         {
@@ -1124,6 +1136,6 @@
             READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
             Bool deltaFlag = false;
-            //            First LTRP                               || First LTRP from SH
-            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
+            //            First LTRP                               || First LTRP from SH           || curr LSB    != prev LSB
+            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) || (pocLsbLt != prevLSB) )
             {
               deltaFlag = true;
@@ -1150,4 +1162,5 @@
             rps->setCheckLTMSBPresent(j,false);  
           }
+          prevLSB = pocLsbLt;
           prevDeltaMSB = deltaPocMSBCycleLT;
         }
@@ -1155,6 +1168,6 @@
         rps->setNumberOfPictures(offset);        
       }  
-      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
+        || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
       {
@@ -1216,7 +1229,6 @@
       }
     }
-    // } 
+    // }
     TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification();
-
     if(!rpcSlice->isIntra())
     {
@@ -1389,10 +1401,6 @@
         if(!rpcSlice->getDeblockingFilterDisable())
         {
-          READ_SVLC( iCode, "slice_beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
-          assert(rpcSlice->getDeblockingFilterBetaOffsetDiv2() >= -6 &&
-                 rpcSlice->getDeblockingFilterBetaOffsetDiv2() <=  6);
-          READ_SVLC( iCode, "slice_tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
-          assert(rpcSlice->getDeblockingFilterTcOffsetDiv2() >= -6 &&
-                 rpcSlice->getDeblockingFilterTcOffsetDiv2() <=  6);
+          READ_SVLC( iCode, "beta_offset_div2" );                       rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode);
+          READ_SVLC( iCode, "tc_offset_div2" );                         rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode);
         }
       }
@@ -1426,8 +1434,9 @@
   }
   
+  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
+  {
     UInt *entryPointOffset          = NULL;
     UInt numEntryPointOffsets, offsetLenMinus1;
-  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
-  {
+
     READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets );
     if (numEntryPointOffsets>0)
@@ -1446,43 +1455,4 @@
 #endif
     }
-  }
-  else
-  {
-    rpcSlice->setNumEntryPointOffsets ( 0 );
-  }
-
-  if(pps->getSliceHeaderExtensionPresentFlag())
-  {
-    READ_UVLC(uiCode,"slice_header_extension_length");
-    for(Int i=0; i<uiCode; i++)
-    {
-      UInt ignore;
-      READ_CODE(8,ignore,"slice_header_extension_data_byte");
-    }
-  }
-  m_pcBitstream->readByteAlignment();
-
-  if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() )
-  {
-    Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
-    Int  curEntryPointOffset     = 0;
-    Int  prevEntryPointOffset    = 0;
-    for (UInt idx=0; idx<numEntryPointOffsets; idx++)
-    {
-      curEntryPointOffset += entryPointOffset[ idx ];
-
-      Int emulationPreventionByteCount = 0;
-      for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
-      {
-        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
-             m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
-        {
-          emulationPreventionByteCount++;
-        }
-      }
-
-      entryPointOffset[ idx ] -= emulationPreventionByteCount;
-      prevEntryPointOffset = curEntryPointOffset;
-    }
 
     if ( pps->getTilesEnabledFlag() )
@@ -1520,5 +1490,19 @@
     }
   }
-
+  else
+  {
+    rpcSlice->setNumEntryPointOffsets ( 0 );
+  }
+
+  if(pps->getSliceHeaderExtensionPresentFlag())
+  {
+    READ_UVLC(uiCode,"slice_header_extension_length");
+    for(Int i=0; i<uiCode; i++)
+    {
+      UInt ignore;
+      READ_CODE(8,ignore,"slice_header_extension_data_byte");
+    }
+  }
+  m_pcBitstream->readByteAlignment();
   return;
 }
@@ -1771,4 +1755,112 @@
 // ====================================================================================================================
 
+
+/** Parse PCM alignment zero bits.
+* \returns Void
+*/
+Void TDecCavlc::xReadPCMAlignZero( )
+{
+  UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned();
+
+  if(uiNumberOfBits)
+  {
+    UInt uiBits;
+    UInt uiSymbol;
+
+    for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++)
+    {
+      xReadFlag( uiSymbol );
+      assert( uiSymbol == 0 );
+    }
+  }
+}
+
+Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol )
+{
+  if (uiMaxSymbol == 0)
+  {
+    ruiSymbol = 0;
+    return;
+  }
+
+  xReadFlag( ruiSymbol );
+
+  if (ruiSymbol == 0 || uiMaxSymbol == 1)
+  {
+    return;
+  }
+
+  UInt uiSymbol = 0;
+  UInt uiCont;
+
+  do
+  {
+    xReadFlag( uiCont );
+    uiSymbol++;
+  }
+  while( uiCont && (uiSymbol < uiMaxSymbol-1) );
+
+  if( uiCont && (uiSymbol == uiMaxSymbol-1) )
+  {
+    uiSymbol++;
+  }
+
+  ruiSymbol = uiSymbol;
+}
+
+Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol )
+{
+  UInt uiSymbol ;
+  UInt uiCount = 0;
+  do
+  {
+    xReadFlag( uiSymbol );
+    uiCount++;
+  }
+  while( uiSymbol && (uiCount != 13));
+
+  ruiSymbol = uiCount-1;
+
+  if( uiSymbol )
+  {
+    xReadEpExGolomb( uiSymbol, 0 );
+    ruiSymbol += uiSymbol+1;
+  }
+
+  return;
+}
+
+Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount )
+{
+  UInt uiSymbol = 0;
+  UInt uiBit = 1;
+
+
+  while( uiBit )
+  {
+    xReadFlag( uiBit );
+    uiSymbol += uiBit << uiCount++;
+  }
+
+  uiCount--;
+  while( uiCount-- )
+  {
+    xReadFlag( uiBit );
+    uiSymbol += uiBit << uiCount;
+  }
+
+  ruiSymbol = uiSymbol;
+
+  return;
+}
+
+UInt TDecCavlc::xGetBit()
+{
+  UInt ruiCode;
+  m_pcBitstream->read( 1, ruiCode );
+  return ruiCode;
+}
+
+
 /** parse explicit wp tables
 * \param TComSlice* pcSlice
@@ -1787,10 +1879,8 @@
   // decode delta_luma_log2_weight_denom :
   READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
-  assert( uiLog2WeightDenomLuma <= 7 );
   if( bChroma ) 
   {
     READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
     assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0);
-    assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)<=7);
     uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma);
   }
@@ -1831,10 +1921,6 @@
         Int iDeltaWeight;
         READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" );  // se(v): delta_luma_weight_l0[i]
-        assert( iDeltaWeight >= -128 );
-        assert( iDeltaWeight <=  127 );
         wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom));
         READ_SVLC( wp[0].iOffset, "luma_offset_lX" );       // se(v): luma_offset_l0[i]
-        assert( wp[0].iOffset >= -128 );
-        assert( wp[0].iOffset <=  127 );
       }
       else 
@@ -1851,12 +1937,8 @@
             Int iDeltaWeight;
             READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );  // se(v): chroma_weight_l0[i][j]
-            assert( iDeltaWeight >= -128 );
-            assert( iDeltaWeight <=  127 );
             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]
-            assert( iDeltaChroma >= -512 );
-            assert( iDeltaChroma <=  511 );
             Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
             wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) );
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 438)
@@ -61,5 +61,14 @@
   
 protected:
+  Void  xReadEpExGolomb       ( UInt& ruiSymbol, UInt uiCount );
+  Void  xReadExGolombLevel    ( UInt& ruiSymbol );
+  Void  xReadUnaryMaxSymbol   ( UInt& ruiSymbol, UInt uiMaxSymbol );
+  
+  Void  xReadPCMAlignZero     ();
+
+  UInt  xGetBit             ();
+  
   void  parseShortTermRefPicSet            (TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Int idx);
+private:
   
 public:
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 438)
@@ -208,8 +208,10 @@
   rpcPic->compressMotion(); 
 #endif
+
   Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
   if (!pcSlice->isReferenced()) c += 32;
 
   //-- For time output for each slice
+
 #if H_MV
   printf("\nLayer %2d   POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getLayerId(),
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecSlice.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecSlice.h	(revision 438)
@@ -84,5 +84,4 @@
   Void      initCtxMem(  UInt i );
   Void      setCtxMem( TDecSbac* sb, Int b )   { CTXMem[b] = sb; }
-  Int       getCtxMemSize( )                   { return (Int)CTXMem.size(); }
 };
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 438)
@@ -42,4 +42,5 @@
 ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
 #endif
+
 //! \ingroup TLibDecoder
 //! \{
@@ -50,14 +51,7 @@
   m_iMaxRefPicNum = 0;
 #if ENC_DEC_TRACE
-#if H_MV
-  if ( g_hTrace == NULL )
-  {
-#endif
   g_hTrace = fopen( "TraceDec.txt", "wb" );
   g_bJustDoIt = g_bEncDecTraceDisable;
   g_nSymbolCounter = 0;
-#if H_MV
-  }
-#endif
 #endif
   m_pocCRA = 0;
@@ -100,4 +94,5 @@
 }
 
+
 Void TDecTop::init()
 {
@@ -106,4 +101,5 @@
   initROM();
 #endif
+
   m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
   m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
@@ -153,9 +149,5 @@
   }
 
-#if L0323_DPB
-  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
-#else
   m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
-#endif
   if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
   {
@@ -227,8 +219,10 @@
   rpcListPic          = &m_cListPic;  
   m_cCuDecoder.destroy();        
+
 #if H_MV 
   TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
   TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
 #endif
+
   m_bFirstSliceInPicture  = true;
 
@@ -296,5 +290,5 @@
   assert (sps != 0);
 
-  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->getIdrPicFlag()))
   {
     printf ("Parameter set activation failed!");
@@ -302,43 +296,21 @@
   }
 
-  if( pps->getDependentSliceSegmentsEnabledFlag() )
-  {
-    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
-
-    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
-    {
-      m_cSliceDecoder.initCtxMem(NumCtx);
-      for ( UInt st = 0; st < NumCtx; st++ )
-      {
-        TDecSbac* ctx = NULL;
-        ctx = new TDecSbac;
-        ctx->init( &m_cBinCABAC );
-        m_cSliceDecoder.setCtxMem( ctx, st );
-      }
-    }
-  }
-
   m_apcSlicePilot->setPPS(pps);
   m_apcSlicePilot->setSPS(sps);
+
 #if H_MV
   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
 #endif
+
   pps->setSPS(sps);
   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
   pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
 
-  g_bitDepthY     = sps->getBitDepthY();
-  g_bitDepthC     = sps->getBitDepthC();
-  g_uiMaxCUWidth  = sps->getMaxCUWidth();
-  g_uiMaxCUHeight = sps->getMaxCUHeight();
-  g_uiMaxCUDepth  = sps->getMaxCUDepth();
-  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
-
-  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
+  for (Int i = 0; i < sps->getMaxCUDepth() - g_uiAddCUDepth; i++)
   {
     sps->setAMPAcc( i, sps->getUseAMP() );
   }
 
-  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
+  for (Int i = sps->getMaxCUDepth() - g_uiAddCUDepth; i < sps->getMaxCUDepth(); i++)
   {
     sps->setAMPAcc( i, 0 );
@@ -346,6 +318,6 @@
 
   m_cSAO.destroy();
-  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
-  m_cLoopFilter.create( sps->getMaxCUDepth() );
+  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight );
+  m_cLoopFilter.        create( g_uiMaxCUDepth );
 }
 
@@ -373,11 +345,10 @@
 
   m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
-  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
-  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
-  
+  if((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N) ||
+     (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) ||
+     (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N))
+  {
+    m_apcSlicePilot->setTemporalLayerNonReferenceFlag(true);
+  }
   m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
@@ -386,4 +357,5 @@
   m_apcSlicePilot->setLayerId( nalu.m_layerId );
 #endif
+
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
 
@@ -399,4 +371,7 @@
 #endif
 #endif
+
+  if (m_apcSlicePilot->isNextSlice())
+  {
     // Skip pictures due to random access
     if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
@@ -409,12 +384,8 @@
       return false;
     }
-
-  //we should only get a different poc for a new picture (with CTU address==0)
-  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
-  {
-    printf ("Warning, the first slice of a picture might have been lost!\n");
-  }
+  } 
+
   // exit when a new picture is found
-  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
+  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
   {
     if (m_prevPOC >= m_pocRandomAccess)
@@ -425,4 +396,5 @@
     m_prevPOC = m_apcSlicePilot->getPOC();
   }
+
 #if H_MV
   if ( newLayerFlag )
@@ -431,4 +403,6 @@
   }
 #endif
+
+
   // actual decoding starts here
   xActivateParameterSets();
@@ -445,4 +419,5 @@
     xCreateLostPicture(lostPoc-1);
   }
+
   if (m_bFirstSliceInPicture)
   {
@@ -450,7 +425,10 @@
     m_cPrediction.initTempBuff();
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
+    
 #if H_MV
     m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
 #endif
+
+
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
@@ -591,18 +569,16 @@
 #endif
 #endif
+
   if (bNextSlice)
   {
-    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
+    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA );
     // Set reference list
+
 #if H_MV    
-    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );    
-#else
-#if FIX1071
-    pcSlice->setRefPicList( m_cListPic, true );
+    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer );    
 #else
     pcSlice->setRefPicList( m_cListPic );
 #endif
 
-#endif
     // For generalized B
     // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
@@ -646,5 +622,4 @@
     //---------------
     pcSlice->setRefPOCList();
-#if !L0034_COMBINED_LIST_CLEANUP
     pcSlice->setNoBackPredFlag( false );
     if ( pcSlice->getSliceType() == B_SLICE )
@@ -663,5 +638,4 @@
       }
     }
-#endif
   }
 
@@ -717,9 +691,22 @@
   m_cEntropyDecoder.decodePPS( pps );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
+
+  if( pps->getDependentSliceSegmentsEnabledFlag() )
+  {
+    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
+    m_cSliceDecoder.initCtxMem(NumCtx);
+    for ( UInt st = 0; st < NumCtx; st++ )
+    {
+      TDecSbac* ctx = NULL;
+      ctx = new TDecSbac;
+      ctx->init( &m_cBinCABAC );
+      m_cSliceDecoder.setCtxMem( ctx, st );
+    }
+  }
 }
 
 Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
 {
-  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
+  if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
   {
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
@@ -766,6 +753,6 @@
       return false;
       
-    case NAL_UNIT_PREFIX_SEI:
-    case NAL_UNIT_SUFFIX_SEI:
+    case NAL_UNIT_SEI:
+    case NAL_UNIT_SEI_SUFFIX:
       xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
       return false;
@@ -773,18 +760,18 @@
     case NAL_UNIT_CODED_SLICE_TRAIL_R:
     case NAL_UNIT_CODED_SLICE_TRAIL_N:
-    case NAL_UNIT_CODED_SLICE_TLA_R:
+    case NAL_UNIT_CODED_SLICE_TLA:
     case NAL_UNIT_CODED_SLICE_TSA_N:
     case NAL_UNIT_CODED_SLICE_STSA_R:
     case NAL_UNIT_CODED_SLICE_STSA_N:
-    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
-    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
+    case NAL_UNIT_CODED_SLICE_BLA:
+    case NAL_UNIT_CODED_SLICE_BLANT:
     case NAL_UNIT_CODED_SLICE_BLA_N_LP:
-    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
+    case NAL_UNIT_CODED_SLICE_IDR:
     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_RADL_R:
+    case NAL_UNIT_CODED_SLICE_DLP:
     case NAL_UNIT_CODED_SLICE_RASL_N:
-    case NAL_UNIT_CODED_SLICE_RASL_R:
+    case NAL_UNIT_CODED_SLICE_TFD:
 #if H_MV
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
@@ -808,5 +795,5 @@
 Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
 {
-  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
+  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++;
@@ -839,12 +826,12 @@
   {
     if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
-        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
         || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
+        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT )
     {
       // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
       m_pocRandomAccess = m_apcSlicePilot->getPOC();
     }
-    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
+    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     {
       m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
@@ -862,5 +849,5 @@
   }
   // skip the reordered pictures, if necessary
-  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
+  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++;
@@ -894,3 +881,4 @@
 
 #endif
+
 //! \}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 438)
@@ -64,4 +64,5 @@
 class TAppDecTop;
 #endif
+
 /// decoder class
 class TDecTop
@@ -80,4 +81,5 @@
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
 #endif
+
   TComSlice*              m_apcSlicePilot;
   
@@ -140,4 +142,5 @@
 #endif
   
+
 #if H_MV    
   TComPic*                getPic                ( Int poc );
@@ -155,4 +158,5 @@
 #endif
 #endif
+  
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 438)
@@ -84,19 +84,4 @@
     fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
     break;
-#if J0149_TONE_MAPPING_SEI
-  case SEI::TONE_MAPPING_INFO:
-    fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
-    break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
-  case SEI::SOP_DESCRIPTION:
-    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
-    break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  case SEI::SCALABLE_NESTING:
-    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
-    break;
-#endif
   default:
     fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
@@ -106,9 +91,5 @@
 #endif
 
-#if K0180_SCALABLE_NESTING_SEI
-void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
-#else
 void SEIWriter::xWriteSEIpayloadData(const SEI& sei, TComSPS *sps)
-#endif
 {
   switch (sei.payloadType())
@@ -147,19 +128,4 @@
     xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
     break;
-#if J0149_TONE_MAPPING_SEI
-  case SEI::TONE_MAPPING_INFO:
-    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
-    break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
-  case SEI::SOP_DESCRIPTION:
-    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
-    break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  case SEI::SCALABLE_NESTING:
-    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
-    break;
-#endif
   default:
     assert(!"Unhandled SEI message");
@@ -179,18 +145,4 @@
   setBitstream(&bs_count);
 
-
-#if K0180_SCALABLE_NESTING_SEI
-
-#if ENC_DEC_TRACE
-  Bool traceEnable = g_HLSTraceEnable;
-  g_HLSTraceEnable = false;
-#endif
-  xWriteSEIpayloadData(bs_count, sei, sps);
-#if ENC_DEC_TRACE
-  g_HLSTraceEnable = traceEnable;
-#endif
-
-#else
-
 #if ENC_DEC_TRACE
   g_HLSTraceEnable = false;
@@ -200,7 +152,4 @@
   g_HLSTraceEnable = true;
 #endif
-
-#endif
-
   UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
   assert(0 == payload_data_num_bits % 8);
@@ -209,7 +158,4 @@
 
 #if ENC_DEC_TRACE
-#if K0180_SCALABLE_NESTING_SEI
-  if (g_HLSTraceEnable)
-#endif
   xTraceSEIHeader();
 #endif
@@ -231,15 +177,8 @@
   /* payloadData */
 #if ENC_DEC_TRACE
-#if K0180_SCALABLE_NESTING_SEI
-  if (g_HLSTraceEnable)
-#endif
   xTraceSEIMessageType(sei.payloadType());
 #endif
 
-#if K0180_SCALABLE_NESTING_SEI
-  xWriteSEIpayloadData(bs, sei, sps);
-#else
   xWriteSEIpayloadData(sei, sps);
-#endif
 }
 
@@ -482,79 +421,4 @@
   xWriteByteAlign();
 }
-
-#if J0149_TONE_MAPPING_SEI
-Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
-{
-  Int i;
-  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
-  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
-  if( !sei.m_toneMapCancelFlag ) 
-  {
-    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
-    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
-    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
-    WRITE_UVLC( sei.m_modelId,                    "model_id" );
-    switch(sei.m_modelId)
-    {
-    case 0:
-      {
-        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
-        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
-        break;
-      }
-    case 1:
-      {
-        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
-        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
-        break;
-      }
-    case 2:
-      {
-        UInt num = 1u << sei.m_targetBitDepth;
-        for(i = 0; i < num; i++)
-        {
-          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
-        }
-        break;
-      }
-    case 3:
-      {
-        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
-        for(i = 0; i < sei.m_numPivots; i++ )
-        {
-          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
-          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
-        }
-        break;
-      }
-    case 4:
-      {
-        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
-        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
-        {
-          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
-        }
-        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
-        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
-        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
-        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
-        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
-        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
-        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
-        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
-        break;
-      }
-    default:
-      {
-        assert(!"Undefined SEIToneMapModelId");
-        break;
-      }
-    }//switch m_modelId
-  }//if(!sei.m_toneMapCancelFlag)
-
-  xWriteByteAlign();
-}
-#endif
-
 Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
 {
@@ -591,71 +455,4 @@
 }
 
-#if L0208_SOP_DESCRIPTION_SEI
-Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
-{
-  WRITE_UVLC( sei.m_sopSeqParameterSetId,           "sop_seq_parameter_set_id"               );
-  WRITE_UVLC( sei.m_numPicsInSopMinus1,             "num_pics_in_sop_minus1"               );
-  for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++)
-  {
-    WRITE_CODE( sei.m_sopDescVclNaluType[i], 6, "sop_desc_vcl_nalu_type" );
-    WRITE_CODE( sei.m_sopDescTemporalId[i],  3, "sop_desc_temporal_id" );
-    if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP)
-    {
-      WRITE_UVLC( sei.m_sopDescStRpsIdx[i],           "sop_desc_st_rps_idx"               );
-    }
-    if (i > 0)
-    {
-      WRITE_SVLC( sei.m_sopDescPocDelta[i],           "sop_desc_poc_delta"               );
-    }
-  }
-
-  xWriteByteAlign();
-}
-#endif
-
-#if K0180_SCALABLE_NESTING_SEI
-Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
-{
-  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
-  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
-  if (sei.m_nestingOpFlag)
-  {
-    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
-    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
-    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
-    {
-      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
-      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
-      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
-    }
-  }
-  else
-  {
-    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
-    if (!sei.m_allLayersFlag)
-    {
-      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
-      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
-      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
-      {
-        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
-      }
-    }
-  }
- 
-  // byte alignment
-  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
-  {
-    WRITE_FLAG( 0, "nesting_zero_bit" );
-  }
-
-  // write nested SEI messages
-  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
-  {
-    writeSEImessage(bs, *(*it), sps);
-  }
-}
-#endif
-
 Void SEIWriter::xWriteByteAlign()
 {
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/SEIwrite.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/SEIwrite.h	(revision 438)
@@ -50,9 +50,5 @@
 
 protected:
-#if K0180_SCALABLE_NESTING_SEI
-  Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps);
-#else
   Void xWriteSEIpayloadData(const SEI& sei, TComSPS *sps);
-#endif
   Void xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei);
   Void xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei);
@@ -67,13 +63,4 @@
   Void xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei);
   Void xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei);
-#if J0149_TONE_MAPPING_SEI
-  Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
-  Void xWriteSEISOPDescription(const SEISOPDescription& sei);
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
-#endif
   Void xWriteByteAlign();
 };
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	(revision 438)
@@ -185,5 +185,4 @@
 {
   {
-#if !H_MV
     DTRACE_CABAC_VL( g_nSymbolCounter++ )
     DTRACE_CABAC_T( "\tstate=" )
@@ -192,5 +191,4 @@
     DTRACE_CABAC_V( binValue )
     DTRACE_CABAC_T( "\n" )
-#endif
   }
   m_uiBinsCoded += m_binCountIncrement;
@@ -233,10 +231,8 @@
 {
   {
-#if !H_MV
     DTRACE_CABAC_VL( g_nSymbolCounter++ )
     DTRACE_CABAC_T( "\tEPsymbol=" )
     DTRACE_CABAC_V( binValue )
     DTRACE_CABAC_T( "\n" )
-#endif
   }
   m_uiBinsCoded += m_binCountIncrement;
@@ -263,10 +259,8 @@
   for ( Int i = 0; i < numBins; i++ )
   {
-#if !H_MV
     DTRACE_CABAC_VL( g_nSymbolCounter++ )
     DTRACE_CABAC_T( "\tEPsymbol=" )
     DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 )
     DTRACE_CABAC_T( "\n" )
-#endif
   }
   
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 438)
@@ -285,4 +285,5 @@
   WRITE_FLAG(pcVUI->getNeutralChromaIndicationFlag(),           "neutral_chroma_indication_flag");
   WRITE_FLAG(pcVUI->getFieldSeqFlag(),                          "field_seq_flag");
+  assert(pcVUI->getFieldSeqFlag() == 0);                        // not currently supported
   WRITE_FLAG(pcVUI->getFrameFieldInfoPresentFlag(),             "frame_field_info_present_flag");
 
@@ -473,9 +474,5 @@
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
-    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1,       "sps_max_dec_pic_buffering_minus1[i]" );
-#else
     WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "sps_max_dec_pic_buffering[i]" );
-#endif
     WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_num_reorder_pics[i]" );
     WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase[i]" );
@@ -487,6 +484,14 @@
   assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
   
-  WRITE_UVLC( pcSPS->getLog2MinCodingBlockSize() - 3,                                "log2_min_coding_block_size_minus3" );
-  WRITE_UVLC( pcSPS->getLog2DiffMaxMinCodingBlockSize(),                             "log2_diff_max_min_coding_block_size" );
+  UInt MinCUSize = pcSPS->getMaxCUWidth() >> ( pcSPS->getMaxCUDepth()-g_uiAddCUDepth );
+  UInt log2MinCUSize = 0;
+  while(MinCUSize > 1)
+  {
+    MinCUSize >>= 1;
+    log2MinCUSize++;
+  }
+
+  WRITE_UVLC( log2MinCUSize - 3,                                                     "log2_min_coding_block_size_minus3" );
+  WRITE_UVLC( pcSPS->getMaxCUDepth()-g_uiAddCUDepth,                                 "log2_diff_max_min_coding_block_size" );
   WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_transform_block_size_minus2" );
   WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" );
@@ -549,11 +554,5 @@
   }
 
-#if H_MV
-  WRITE_FLAG( 1, "sps_extension_flag" );
-
-  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
-#else
   WRITE_FLAG( 0, "sps_extension_flag" );
-#endif
 }
 
@@ -570,9 +569,5 @@
   WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
-#if H_MV
   WRITE_CODE( 0xffff,                              16,        "vps_extension_offset" );
-#else
-  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
-#endif
   codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
@@ -583,9 +578,5 @@
   for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
-    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1,       "vps_max_dec_pic_buffering_minus1[i]" );
-#else
     WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "vps_max_dec_pic_buffering[i]" );
-#endif
     WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_num_reorder_pics[i]" );
     WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase[i]" );
@@ -654,4 +645,5 @@
   }
 #endif
+
 #if H_MV
   WRITE_FLAG( 1,                                             "vps_extension_flag" );
@@ -792,36 +784,5 @@
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
       TComReferencePictureSet* rps = pcSlice->getRPS();
-      
-#if FIX1071
-      // Deal with bitstream restriction stating that:
-      // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-      // Ideally this process should not be repeated for each slice in a picture
-      TComReferencePictureSet altRps;
-      Bool useAltRps = false;
-#if H_MV
-      if (pcSlice->getRapPicFlag() && ( pcSlice->getLayerId() == 0 ) )
-#else
-      if (pcSlice->getRapPicFlag())
-#endif
-      {
-        for (Int picIdx = 0; !useAltRps && picIdx < rps->getNumberOfPictures(); picIdx++)
-        {
-          useAltRps = rps->getUsed(picIdx);
-        }
-        if (useAltRps)
-        {
-          memcpy(&altRps, rps, sizeof(TComReferencePictureSet));
-          rps = &altRps;
-          for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
-          {
-            rps->setUsed(picIdx, false);
-          }
-        }
-      }
-
-      if(pcSlice->getRPSidx() < 0 || useAltRps)
-#else
       if(pcSlice->getRPSidx() < 0)
-#endif
       {
         WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
@@ -1406,4 +1367,82 @@
 // ====================================================================================================================
 
+
+/** Write PCM alignment bits. 
+ * \returns Void
+ */
+Void  TEncCavlc::xWritePCMAlignZero    ()
+{
+  m_pcBitIf->writeAlignZero();
+}
+
+Void TEncCavlc::xWriteUnaryMaxSymbol( UInt uiSymbol, UInt uiMaxSymbol )
+{
+  if (uiMaxSymbol == 0)
+  {
+    return;
+  }
+  xWriteFlag( uiSymbol ? 1 : 0 );
+  if ( uiSymbol == 0 )
+  {
+    return;
+  }
+  
+  Bool bCodeLast = ( uiMaxSymbol > uiSymbol );
+  
+  while( --uiSymbol )
+  {
+    xWriteFlag( 1 );
+  }
+  if( bCodeLast )
+  {
+    xWriteFlag( 0 );
+  }
+  return;
+}
+
+Void TEncCavlc::xWriteExGolombLevel( UInt uiSymbol )
+{
+  if( uiSymbol )
+  {
+    xWriteFlag( 1 );
+    UInt uiCount = 0;
+    Bool bNoExGo = (uiSymbol < 13);
+    
+    while( --uiSymbol && ++uiCount < 13 )
+    {
+      xWriteFlag( 1 );
+    }
+    if( bNoExGo )
+    {
+      xWriteFlag( 0 );
+    }
+    else
+    {
+      xWriteEpExGolomb( uiSymbol, 0 );
+    }
+  }
+  else
+  {
+    xWriteFlag( 0 );
+  }
+  return;
+}
+
+Void TEncCavlc::xWriteEpExGolomb( UInt uiSymbol, UInt uiCount )
+{
+  while( uiSymbol >= (UInt)(1<<uiCount) )
+  {
+    xWriteFlag( 1 );
+    uiSymbol -= 1<<uiCount;
+    uiCount  ++;
+  }
+  xWriteFlag( 0 );
+  while( uiCount-- )
+  {
+    xWriteFlag( (uiSymbol>>uiCount) & 1 );
+  }
+  return;
+}
+
 /** code explicit wp tables
  * \param TComSlice* pcSlice
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCavlc.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCavlc.h	(revision 438)
@@ -68,4 +68,9 @@
   TComSlice*    m_pcSlice;
   UInt          m_uiCoeffCost;
+
+  Void  xWritePCMAlignZero    ();
+  Void  xWriteEpExGolomb      ( UInt uiSymbol, UInt uiCount );
+  Void  xWriteExGolombLevel    ( UInt uiSymbol );
+  Void  xWriteUnaryMaxSymbol  ( UInt uiSymbol, UInt uiMaxSymbol );
 
   Void codeShortTermRefPicSet              ( TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Bool calledFromSliceHeader, Int idx );
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 438)
@@ -74,4 +74,5 @@
   Int m_interViewRefPosL[2][MAX_NUM_REF_PICS];  
 #endif
+
   GOPEntry()
   : m_POC(-1)
@@ -171,7 +172,4 @@
   Int       m_loopFilterTcOffsetDiv2;
   Bool      m_DeblockingFilterControlPresent;
-#if L0386_DB_METRIC
-  Bool      m_DeblockingFilterMetric;
-#endif
   Bool      m_bUseSAO;
   Int       m_maxNumOffsetsPerPic;
@@ -204,7 +202,5 @@
   Bool      m_bUseASR;
   Bool      m_bUseHADME;
-#if !L0034_COMBINED_LIST_CLEANUP
   Bool      m_bUseLComb;
-#endif
   Bool      m_useRDOQ;
   Bool      m_useRDOQTS;
@@ -252,31 +248,4 @@
   Int       m_pictureTimingSEIEnabled;
   Int       m_recoveryPointSEIEnabled;
-#if J0149_TONE_MAPPING_SEI
-  Bool      m_toneMappingInfoSEIEnabled;
-  Int       m_toneMapId;
-  Bool      m_toneMapCancelFlag;
-  Bool      m_toneMapPersistenceFlag;
-  Int       m_codedDataBitDepth;
-  Int       m_targetBitDepth;
-  Int       m_modelId; 
-  Int       m_minValue;
-  Int       m_maxValue;
-  Int       m_sigmoidMidpoint;
-  Int       m_sigmoidWidth;
-  Int       m_numPivots;
-  Int       m_cameraIsoSpeedIdc;
-  Int       m_cameraIsoSpeedValue;
-  Int       m_exposureCompensationValueSignFlag;
-  Int       m_exposureCompensationValueNumerator;
-  Int       m_exposureCompensationValueDenomIdc;
-  Int       m_refScreenLuminanceWhite;
-  Int       m_extendedRangeWhiteLevel;
-  Int       m_nominalBlackLevelLumaCodeValue;
-  Int       m_nominalWhiteLevelLumaCodeValue;
-  Int       m_extendedWhiteLevelLumaCodeValue;
-  Int*      m_startOfCodedInterval;
-  Int*      m_codedPivotValue;
-  Int*      m_targetPivotValue;
-#endif
   Int       m_framePackingSEIEnabled;
   Int       m_framePackingSEIType;
@@ -288,10 +257,4 @@
   Int       m_gradualDecodingRefreshInfoEnabled;
   Int       m_decodingUnitInfoSEIEnabled;
-#if L0208_SOP_DESCRIPTION_SEI
-  Int       m_SOPDescriptionSEIEnabled;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  Int       m_scalableNestingSEIEnabled;
-#endif
   //====== Weighted Prediction ========
   Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
@@ -362,4 +325,5 @@
 #endif
 #endif
+
 public:
   TEncCfg()
@@ -407,4 +371,5 @@
 #endif
 #endif
+
   //====== Coding Structure ========
   Void      setIntraPeriod                  ( Int   i )      { m_uiIntraPeriod = (UInt)i; }
@@ -444,7 +409,4 @@
   Void      setLoopFilterTcOffset           ( Int   i )      { m_loopFilterTcOffsetDiv2    = i; }
   Void      setDeblockingFilterControlPresent ( Bool b ) { m_DeblockingFilterControlPresent = b; }
-#if L0386_DB_METRIC
-  Void      setDeblockingFilterMetric       ( Bool  b )      { m_DeblockingFilterMetric = b; }
-#endif
 
   //====== Motion search ========
@@ -501,7 +463,4 @@
   Int       getLoopFilterTcOffset           ()      { return m_loopFilterTcOffsetDiv2; }
   Bool      getDeblockingFilterControlPresent()  { return  m_DeblockingFilterControlPresent; }
-#if L0386_DB_METRIC
-  Bool      getDeblockingFilterMetric       ()      { return m_DeblockingFilterMetric; }
-#endif
 
   //==== Motion search ========
@@ -521,7 +480,5 @@
   Void      setUseASR                       ( Bool  b )     { m_bUseASR     = b; }
   Void      setUseHADME                     ( Bool  b )     { m_bUseHADME   = b; }
-#if !L0034_COMBINED_LIST_CLEANUP
   Void      setUseLComb                     ( Bool  b )     { m_bUseLComb   = b; }
-#endif
   Void      setUseRDOQ                      ( Bool  b )     { m_useRDOQ    = b; }
   Void      setUseRDOQTS                    ( Bool  b )     { m_useRDOQTS  = b; }
@@ -545,7 +502,5 @@
   Bool      getUseASR                       ()      { return m_bUseASR;     }
   Bool      getUseHADME                     ()      { return m_bUseHADME;   }
-#if !L0034_COMBINED_LIST_CLEANUP
   Bool      getUseLComb                     ()      { return m_bUseLComb;   }
-#endif
   Bool      getUseRDOQ                      ()      { return m_useRDOQ;    }
   Bool      getUseRDOQTS                    ()      { return m_useRDOQTS;  }
@@ -644,56 +599,4 @@
   Void  setRecoveryPointSEIEnabled(Int b)                { m_recoveryPointSEIEnabled = b; }
   Int   getRecoveryPointSEIEnabled()                     { return m_recoveryPointSEIEnabled; }
-#if J0149_TONE_MAPPING_SEI
-  Void  setToneMappingInfoSEIEnabled(Bool b)                 {  m_toneMappingInfoSEIEnabled = b;  }
-  Bool  getToneMappingInfoSEIEnabled()                       {  return m_toneMappingInfoSEIEnabled;  }
-  Void  setTMISEIToneMapId(Int b)                            {  m_toneMapId = b;  }
-  Int   getTMISEIToneMapId()                                 {  return m_toneMapId;  }
-  Void  setTMISEIToneMapCancelFlag(Bool b)                   {  m_toneMapCancelFlag=b;  }
-  Bool  getTMISEIToneMapCancelFlag()                         {  return m_toneMapCancelFlag;  }
-  Void  setTMISEIToneMapPersistenceFlag(Bool b)              {  m_toneMapPersistenceFlag = b;  }
-  Bool   getTMISEIToneMapPersistenceFlag()                   {  return m_toneMapPersistenceFlag;  }
-  Void  setTMISEICodedDataBitDepth(Int b)                    {  m_codedDataBitDepth = b;  }
-  Int   getTMISEICodedDataBitDepth()                         {  return m_codedDataBitDepth;  }
-  Void  setTMISEITargetBitDepth(Int b)                       {  m_targetBitDepth = b;  }
-  Int   getTMISEITargetBitDepth()                            {  return m_targetBitDepth;  }
-  Void  setTMISEIModelID(Int b)                              {  m_modelId = b;  }
-  Int   getTMISEIModelID()                                   {  return m_modelId;  }
-  Void  setTMISEIMinValue(Int b)                             {  m_minValue = b;  }
-  Int   getTMISEIMinValue()                                  {  return m_minValue;  }
-  Void  setTMISEIMaxValue(Int b)                             {  m_maxValue = b;  }
-  Int   getTMISEIMaxValue()                                  {  return m_maxValue;  }
-  Void  setTMISEISigmoidMidpoint(Int b)                      {  m_sigmoidMidpoint = b;  }
-  Int   getTMISEISigmoidMidpoint()                           {  return m_sigmoidMidpoint;  }
-  Void  setTMISEISigmoidWidth(Int b)                         {  m_sigmoidWidth = b;  }
-  Int   getTMISEISigmoidWidth()                              {  return m_sigmoidWidth;  }
-  Void  setTMISEIStartOfCodedInterva( Int*  p )              {  m_startOfCodedInterval = p;  }
-  Int*  getTMISEIStartOfCodedInterva()                       {  return m_startOfCodedInterval;  }
-  Void  setTMISEINumPivots(Int b)                            {  m_numPivots = b;  }
-  Int   getTMISEINumPivots()                                 {  return m_numPivots;  }
-  Void  setTMISEICodedPivotValue( Int*  p )                  {  m_codedPivotValue = p;  }
-  Int*  getTMISEICodedPivotValue()                           {  return m_codedPivotValue;  }
-  Void  setTMISEITargetPivotValue( Int*  p )                 {  m_targetPivotValue = p;  }
-  Int*  getTMISEITargetPivotValue()                          {  return m_targetPivotValue;  }
-  Void  setTMISEICameraIsoSpeedIdc(Int b)                    {  m_cameraIsoSpeedIdc = b;  }
-  Int   getTMISEICameraIsoSpeedIdc()                         {  return m_cameraIsoSpeedIdc;  }
-  Void  setTMISEICameraIsoSpeedValue(Int b)                  {  m_cameraIsoSpeedValue = b;  }
-  Int   getTMISEICameraIsoSpeedValue()                       {  return m_cameraIsoSpeedValue;  }
-  Void  setTMISEIExposureCompensationValueSignFlag(Int b)    {  m_exposureCompensationValueSignFlag = b;  }
-  Int   getTMISEIExposureCompensationValueSignFlag()         {  return m_exposureCompensationValueSignFlag;  }
-  Void  setTMISEIExposureCompensationValueNumerator(Int b)   {  m_exposureCompensationValueNumerator = b;  }
-  Int   getTMISEIExposureCompensationValueNumerator()        {  return m_exposureCompensationValueNumerator;  }
-  Void  setTMISEIExposureCompensationValueDenomIdc(Int b)    {  m_exposureCompensationValueDenomIdc =b;  }
-  Int   getTMISEIExposureCompensationValueDenomIdc()         {  return m_exposureCompensationValueDenomIdc;  }
-  Void  setTMISEIRefScreenLuminanceWhite(Int b)              {  m_refScreenLuminanceWhite = b;  }
-  Int   getTMISEIRefScreenLuminanceWhite()                   {  return m_refScreenLuminanceWhite;  }
-  Void  setTMISEIExtendedRangeWhiteLevel(Int b)              {  m_extendedRangeWhiteLevel = b;  }
-  Int   getTMISEIExtendedRangeWhiteLevel()                   {  return m_extendedRangeWhiteLevel;  }
-  Void  setTMISEINominalBlackLevelLumaCodeValue(Int b)       {  m_nominalBlackLevelLumaCodeValue = b;  }
-  Int   getTMISEINominalBlackLevelLumaCodeValue()            {  return m_nominalBlackLevelLumaCodeValue;  }
-  Void  setTMISEINominalWhiteLevelLumaCodeValue(Int b)       {  m_nominalWhiteLevelLumaCodeValue = b;  }
-  Int   getTMISEINominalWhiteLevelLumaCodeValue()            {  return m_nominalWhiteLevelLumaCodeValue;  }
-  Void  setTMISEIExtendedWhiteLevelLumaCodeValue(Int b)      {  m_extendedWhiteLevelLumaCodeValue =b;  }
-  Int   getTMISEIExtendedWhiteLevelLumaCodeValue()           {  return m_extendedWhiteLevelLumaCodeValue;  }
-#endif
   Void  setFramePackingArrangementSEIEnabled(Int b)      { m_framePackingSEIEnabled = b; }
   Int   getFramePackingArrangementSEIEnabled()           { return m_framePackingSEIEnabled; }
@@ -714,12 +617,4 @@
   Void  setDecodingUnitInfoSEIEnabled(Int b)                { m_decodingUnitInfoSEIEnabled = b;    }
   Int   getDecodingUnitInfoSEIEnabled()                     { return m_decodingUnitInfoSEIEnabled; }
-#if L0208_SOP_DESCRIPTION_SEI
-  Void  setSOPDescriptionSEIEnabled(Int b)                { m_SOPDescriptionSEIEnabled = b; }
-  Int   getSOPDescriptionSEIEnabled()                     { return m_SOPDescriptionSEIEnabled; }
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
-  Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
-#endif
   Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
   Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 438)
@@ -587,10 +587,8 @@
   if( pcCU->isIntra(uiAbsPartIdx) )
   {
-#if !H_MV
     DTRACE_CABAC_VL( g_nSymbolCounter++ )
     DTRACE_CABAC_T( "\tdecodeTransformIdx()\tCUDepth=" )
     DTRACE_CABAC_V( uiDepth )
     DTRACE_CABAC_T( "\n" )
-#endif
   }
   else
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 438)
@@ -96,8 +96,6 @@
 #if L0045_NON_NESTED_SEI_RESTRICTIONS
   xResetNonNestedSEIPresentFlags();
-#if K0180_SCALABLE_NESTING_SEI
-  xResetNestedSEIPresentFlags();
-#endif
-#endif
+#endif
+
 #if H_MV
   m_layerId      = 0;
@@ -108,4 +106,5 @@
 #endif
 #endif
+
   return;
 }
@@ -212,94 +211,7 @@
 }
 
-#if J0149_TONE_MAPPING_SEI
-SEIToneMappingInfo*  TEncGOP::xCreateSEIToneMappingInfo()
-{
-  SEIToneMappingInfo *seiToneMappingInfo = new SEIToneMappingInfo();
-  seiToneMappingInfo->m_toneMapId = m_pcCfg->getTMISEIToneMapId();
-  seiToneMappingInfo->m_toneMapCancelFlag = m_pcCfg->getTMISEIToneMapCancelFlag();
-  seiToneMappingInfo->m_toneMapPersistenceFlag = m_pcCfg->getTMISEIToneMapPersistenceFlag();
-
-  seiToneMappingInfo->m_codedDataBitDepth = m_pcCfg->getTMISEICodedDataBitDepth();
-  assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14);
-  seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth();
-  assert( (seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17) || (seiToneMappingInfo->m_targetBitDepth  == 255) );
-  seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID();
-  assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4);
-
-  switch( seiToneMappingInfo->m_modelId)
-  {
-  case 0:
-    {
-      seiToneMappingInfo->m_minValue = m_pcCfg->getTMISEIMinValue();
-      seiToneMappingInfo->m_maxValue = m_pcCfg->getTMISEIMaxValue();
-      break;
-    }
-  case 1:
-    {
-      seiToneMappingInfo->m_sigmoidMidpoint = m_pcCfg->getTMISEISigmoidMidpoint();
-      seiToneMappingInfo->m_sigmoidWidth = m_pcCfg->getTMISEISigmoidWidth();
-      break;
-    }
-  case 2:
-    {
-      UInt num = 1u<<(seiToneMappingInfo->m_targetBitDepth);
-      seiToneMappingInfo->m_startOfCodedInterval.resize(num);
-      Int* ptmp = m_pcCfg->getTMISEIStartOfCodedInterva();
-      if(ptmp)
-      {
-        for(int i=0; i<num;i++)
-        {
-          seiToneMappingInfo->m_startOfCodedInterval[i] = ptmp[i];
-        }
-      }
-      break;
-    }
-  case 3:
-    {
-      seiToneMappingInfo->m_numPivots = m_pcCfg->getTMISEINumPivots();
-      seiToneMappingInfo->m_codedPivotValue.resize(seiToneMappingInfo->m_numPivots);
-      seiToneMappingInfo->m_targetPivotValue.resize(seiToneMappingInfo->m_numPivots);
-      Int* ptmpcoded = m_pcCfg->getTMISEICodedPivotValue();
-      Int* ptmptarget = m_pcCfg->getTMISEITargetPivotValue();
-      if(ptmpcoded&&ptmptarget)
-      {
-        for(int i=0; i<(seiToneMappingInfo->m_numPivots);i++)
-        {
-          seiToneMappingInfo->m_codedPivotValue[i]=ptmpcoded[i];
-          seiToneMappingInfo->m_targetPivotValue[i]=ptmptarget[i];
-         }
-       }
-       break;
-     }
-  case 4:
-     {
-       seiToneMappingInfo->m_cameraIsoSpeedIdc = m_pcCfg->getTMISEICameraIsoSpeedIdc();
-       seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue();
-       assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 );
-       seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag();
-       seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator();
-       seiToneMappingInfo->m_exposureCompensationValueDenomIdc = m_pcCfg->getTMISEIExposureCompensationValueDenomIdc();
-       seiToneMappingInfo->m_refScreenLuminanceWhite = m_pcCfg->getTMISEIRefScreenLuminanceWhite();
-       seiToneMappingInfo->m_extendedRangeWhiteLevel = m_pcCfg->getTMISEIExtendedRangeWhiteLevel();
-       assert( seiToneMappingInfo->m_extendedRangeWhiteLevel >= 100 );
-       seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue = m_pcCfg->getTMISEINominalBlackLevelLumaCodeValue();
-       seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue = m_pcCfg->getTMISEINominalWhiteLevelLumaCodeValue();
-       assert( seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue > seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue );
-       seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue = m_pcCfg->getTMISEIExtendedWhiteLevelLumaCodeValue();
-       assert( seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue >= seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue );
-       break;
-    }
-  default:
-    {
-      assert(!"Undefined SEIToneMapModelId");
-      break;
-    }
-  }
-  return seiToneMappingInfo;
-}
-#endif
 Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
 {
-  OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
+  OutputNALUnit nalu(NAL_UNIT_SEI);
 
   if(m_pcCfg->getActiveParameterSetsSEIEnabled())
@@ -322,5 +234,5 @@
     SEIFramePacking *sei = xCreateSEIFramePacking ();
 
-    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
+    nalu = NALUnit(NAL_UNIT_SEI);
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
@@ -333,5 +245,5 @@
     SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation();
 
-    nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 
+    nalu = NALUnit(NAL_UNIT_SEI); 
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
@@ -340,17 +252,4 @@
     delete sei;
   }
-#if J0149_TONE_MAPPING_SEI
-  if(m_pcCfg->getToneMappingInfoSEIEnabled())
-  {
-    SEIToneMappingInfo *sei = xCreateSEIToneMappingInfo ();
-      
-    nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 
-    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
-    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
-    writeRBSPTrailingBits(nalu.m_Bitstream);
-    accessUnit.push_back(new NALUnitEBSP(nalu));
-    delete sei;
-  }
-#endif
 }
 
@@ -358,4 +257,5 @@
 // Public member functions
 // ====================================================================================================================
+
 #if H_MV
 Void TEncGOP::initGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
@@ -365,4 +265,5 @@
 }
 #endif
+
 #if H_MV
 Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid)
@@ -374,6 +275,5 @@
   TComPicYuv*     pcPicYuvRecOut;
   TComSlice*      pcSlice;
-  TComOutputBitstream  *pcBitstreamRedirect;
-  pcBitstreamRedirect = new TComOutputBitstream;
+  TComOutputBitstream* pcBitstreamRedirect = new TComOutputBitstream;
   AccessUnit::iterator  itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted
   UInt                  uiOneBitstreamPerSliceLength = 0;
@@ -386,20 +286,6 @@
   m_iNumPicCoded = 0;
 #endif
+
   SEIPictureTiming pictureTimingSEI;
-#if L0208_SOP_DESCRIPTION_SEI
-  Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled();
-#endif
-#if K0180_SCALABLE_NESTING_SEI
-  // Initialize Scalable Nesting SEI with single layer values
-  SEIScalableNesting scalableNestingSEI;
-  scalableNestingSEI.m_bitStreamSubsetFlag           = 1;      // If the nested SEI messages are picture buffereing SEI mesages, picure timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1
-  scalableNestingSEI.m_nestingOpFlag                 = 0;
-  scalableNestingSEI.m_nestingNumOpsMinus1           = 0;      //nesting_num_ops_minus1
-  scalableNestingSEI.m_allLayersFlag                 = 0;
-  scalableNestingSEI.m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1;  //nesting_no_op_max_temporal_id_plus1
-  scalableNestingSEI.m_nestingNumLayersMinus1        = 1 - 1;  //nesting_num_layers_minus1
-  scalableNestingSEI.m_nestingLayerId[0]             = 0;
-  scalableNestingSEI.m_callerOwnsSEIs                = true;
-#endif
 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
   Int picSptDpbOutputDuDelay = 0;
@@ -408,7 +294,9 @@
   UInt *accumNalsDU = NULL;
   SEIDecodingUnitInfo decodingUnitInfoSEI;
+
 #if !H_MV
   for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
 #endif
+
   {
     UInt uiColDir = 1;
@@ -469,4 +357,5 @@
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     {
+
 #if H_MV
       delete pcBitstreamRedirect;
@@ -475,7 +364,8 @@
       continue;
 #endif
-    }
-
-    if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
+
+    }
+
+    if( getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     {
       m_iLastIDR = pocCurr;
@@ -495,4 +385,5 @@
     pcSlice->setLastIDR(m_iLastIDR);
     pcSlice->setSliceIdx(0);
+
 #if H_MV
     pcPic  ->setLayerId     ( getLayerId() );
@@ -506,4 +397,5 @@
 #endif
 #endif
+
     //set default slice level flag to the same as SPS level flag
     pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
@@ -545,5 +437,5 @@
 #if H_MV
     // Set the nal unit type
-    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
+    pcSlice->setNalUnitType(getNalUnitType(pocCurr));
     if( pcSlice->getSliceType() == B_SLICE )
     {
@@ -559,19 +451,11 @@
     }
     // Set the nal unit type
-    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
-#endif
-    if(pcSlice->getTemporalLayerNonReferenceFlag())
-    {
-      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
+    pcSlice->setNalUnitType(getNalUnitType(pocCurr));
+#endif
+    if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
+    {
+      if(pcSlice->getTemporalLayerNonReferenceFlag())
       {
         pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
-      }
-      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R)
-      {
-        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N);
-      }
-      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R)
-      {
-        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N);
       }
     }
@@ -598,5 +482,5 @@
         else
         {
-          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
+          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA);
         }
       }
@@ -684,5 +568,5 @@
     }
 #endif
-#if !L0034_COMBINED_LIST_CLEANUP
+
     if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb())
     {
@@ -696,5 +580,4 @@
       pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0));
     }
-#endif
 
     if (pcSlice->getSliceType() == B_SLICE)
@@ -722,8 +605,4 @@
       pcSlice->setCheckLDC(bLowDelay);  
     }
-    else
-    {
-      pcSlice->setCheckLDC(true);  
-    }
 
     uiColDir = 1-uiColDir;
@@ -732,7 +611,4 @@
     pcSlice->setRefPOCList();
 
-#if L0034_COMBINED_LIST_CLEANUP
-    pcSlice->setList1IdxToList0Idx();
-#else
     pcSlice->setNoBackPredFlag( false );
     if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
@@ -758,5 +634,4 @@
     }
     pcSlice->generateCombinedList();
-#endif
 
     if (m_pcEncTop->getTMVPModeId() == 2)
@@ -1064,10 +939,4 @@
     Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
-#if L0386_DB_METRIC
-    if ( m_pcCfg->getDeblockingFilterMetric() )
-    {
-      dblMetric(pcPic, uiNumSlices);
-    }
-#endif
     m_pcLoopFilter->loopFilterPic( pcPic );
 
@@ -1168,44 +1037,4 @@
     }
 
-#if L0208_SOP_DESCRIPTION_SEI
-    if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP
-    {
-      Int SOPcurrPOC = pocCurr;
-
-      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
-      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
-      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
-
-      SEISOPDescription SOPDescriptionSEI;
-      SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId();
-
-      UInt i = 0;
-      UInt prevEntryId = iGOPid;
-      for (j = iGOPid; j < m_iGopSize; j++)
-      {
-        Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC;
-        if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded())
-        {
-          SOPcurrPOC += deltaPOC;
-          SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR);
-          SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId;
-          SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j);
-          SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC;
-
-          prevEntryId = j;
-          i++;
-        }
-      }
-
-      SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1;
-
-      m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS());
-      writeRBSPTrailingBits(nalu.m_Bitstream);
-      accessUnit.push_back(new NALUnitEBSP(nalu));
-
-      writeSOP = false;
-    }
-#endif
-
     if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
         ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) &&
@@ -1253,5 +1082,5 @@
        || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) )
     {
-      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
+      OutputNALUnit nalu(NAL_UNIT_SEI);
       m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
@@ -1294,5 +1123,4 @@
       writeRBSPTrailingBits(nalu.m_Bitstream);
 #if L0045_NON_NESTED_SEI_RESTRICTIONS
-      {
       UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
       UInt offsetPosition = m_activeParameterSetSEIPresentInAU;   // Insert BP SEI after APS SEI
@@ -1304,35 +1132,8 @@
       accessUnit.insert(it, new NALUnitEBSP(nalu));
       m_bufferingPeriodSEIPresentInAU = true;
-      }
 #else
       accessUnit.push_back(new NALUnitEBSP(nalu));
 #endif
 
-#if K0180_SCALABLE_NESTING_SEI
-      if (m_pcCfg->getScalableNestingSEIEnabled())
-      {
-        OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI);
-        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
-        m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream);
-        scalableNestingSEI.m_nestedSEIs.clear();
-        scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period);
-        m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
-        writeRBSPTrailingBits(naluTmp.m_Bitstream);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
-        UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
-        UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU;   // Insert BP SEI after non-nested APS, BP and PT SEIs
-        AccessUnit::iterator it;
-        for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
-        {
-          it++;
-        }
-        accessUnit.insert(it, new NALUnitEBSP(naluTmp));
-        m_nestedBufferingPeriodSEIPresentInAU = true;
-#else
-        accessUnit.push_back(new NALUnitEBSP(naluTmp));
-#endif
-      }
-#endif
-
       m_lastBPSEI = m_totalCoded;
       m_cpbRemovalDelay = 0;
@@ -1344,5 +1145,5 @@
       {
         // Gradual decoding refresh SEI 
-        OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
+        OutputNALUnit nalu(NAL_UNIT_SEI);
         m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
         m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
@@ -1356,5 +1157,5 @@
       }
     // Recovery point SEI
-      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
+      OutputNALUnit nalu(NAL_UNIT_SEI);
       m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
@@ -1547,6 +1348,13 @@
 
           pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength );
+          if (!sliceSegment)
+          {
             pcSlice->setTileLocationCount ( 0 );
-          m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut);
+            m_pcSliceEncoder->encodeSlice(pcPic, pcBitstreamRedirect, pcSubstreamsOut); // redirect is only used for CAVLC tile position info.
+          }
+          else
+          {
+            m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info.
+          }
 
           {
@@ -1580,5 +1388,5 @@
               if (ui+1 < pcSlice->getPPS()->getNumSubstreams())
               {
-                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3);
+                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits();
               }
             }
@@ -1612,5 +1420,5 @@
           // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list.
           Bool bNALUAlignedWrittenToList    = false; // used to ensure current NALU is not written more than once to the NALU list.
-          xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect);
+          xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice);
           accessUnit.push_back(new NALUnitEBSP(nalu));
 #if RATE_CONTROL_LAMBDA_DOMAIN
@@ -1640,5 +1448,5 @@
             {
               UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
-              if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
+              if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
               {
                 numRBSPBytes += numRBSPBytes_nal;
@@ -1710,4 +1518,5 @@
       pcPic->compressMotion(); 
 #endif
+
 #if H_MV
       m_pocLastCoded = pcPic->getPOC();
@@ -1740,5 +1549,5 @@
           digestStr = digestToString(sei_recon_picture_digest.digest, 4);
         }
-        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer());
+        OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer());
 
         /* write the SEI messages */
@@ -1764,5 +1573,5 @@
         sei_temporal_level0_index.rapIdx = m_rapIdx;
 
-        OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 
+        OutputNALUnit nalu(NAL_UNIT_SEI); 
 
         /* write the SEI messages */
@@ -1904,6 +1713,5 @@
         if( m_pcCfg->getPictureTimingSEIEnabled() )
         {
-          {
-            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
+          OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer());
           m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
           m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
@@ -1925,32 +1733,4 @@
 #endif
         }
-#if K0180_SCALABLE_NESTING_SEI
-          if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI
-          {
-            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
-            m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
-            scalableNestingSEI.m_nestedSEIs.clear();
-            scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI);
-            m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
-            writeRBSPTrailingBits(nalu.m_Bitstream);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
-            UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
-            UInt offsetPosition = m_activeParameterSetSEIPresentInAU 
-              + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU;    // Insert PT SEI after APS and BP SEI
-            AccessUnit::iterator it;
-            for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
-            {
-              it++;
-            }
-            accessUnit.insert(it, new NALUnitEBSP(nalu));
-            m_nestedPictureTimingSEIPresentInAU = true;
-#else
-            AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
-            accessUnit.insert(it, new NALUnitEBSP(nalu));
-#endif
-          }
-#endif
-
-        }
         if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() )
         {             
@@ -1958,5 +1738,5 @@
           for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ )
           {
-            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
+            OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer());
 
             SEIDecodingUnitInfo tempSEI;
@@ -2006,5 +1786,5 @@
                   break;
                 }
-                if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
+                if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
                 {
                   ctr++;
@@ -2017,7 +1797,4 @@
 #if L0045_NON_NESTED_SEI_RESTRICTIONS
       xResetNonNestedSEIPresentFlags();
-#if K0180_SCALABLE_NESTING_SEI
-      xResetNestedSEIPresentFlags();
-#endif
 #endif
       pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
@@ -2052,4 +1829,5 @@
   assert ( m_iNumPicCoded == iNumPicRcvd );
 #endif
+
 }
 
@@ -2245,16 +2023,16 @@
     case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
     case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
-    case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
+    case NAL_UNIT_CODED_SLICE_TLA: return "TLA";
     case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
     case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
     case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
-    case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
-    case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
+    case NAL_UNIT_CODED_SLICE_BLA: return "BLA";
+    case NAL_UNIT_CODED_SLICE_BLANT: return "BLANT";
     case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
-    case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
+    case NAL_UNIT_CODED_SLICE_IDR: return "IDR";
     case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
     case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
-    case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
-    case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
+    case NAL_UNIT_CODED_SLICE_DLP: return "DLP";
+    case NAL_UNIT_CODED_SLICE_TFD: return "TFD";
     case NAL_UNIT_VPS: return "VPS";
     case NAL_UNIT_SPS: return "SPS";
@@ -2264,6 +2042,5 @@
     case NAL_UNIT_EOB: return "EOB";
     case NAL_UNIT_FILLER_DATA: return "FILLER";
-    case NAL_UNIT_PREFIX_SEI:             return "SEI";
-    case NAL_UNIT_SUFFIX_SEI:             return "SEI";
+    case NAL_UNIT_SEI: return "SEI";
     default: return "UNK";
   }
@@ -2356,5 +2133,5 @@
     printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal);
 #endif
-    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
+    if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     {
       numRBSPBytes += numRBSPBytes_nal;
@@ -2366,4 +2143,5 @@
 
   //===== add PSNR =====
+
 #if H_MV
   m_pcEncTop->getAnalyzeAll()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
@@ -2371,7 +2149,9 @@
   m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
 #endif
+
   TComSlice*  pcSlice = pcPic->getSlice(0);
   if (pcSlice->isIntra())
   {
+
 #if H_MV
     m_pcEncTop->getAnalyzeI()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
@@ -2379,7 +2159,9 @@
     m_gcAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
 #endif
+
   }
   if (pcSlice->isInterP())
   {
+
 #if H_MV
     m_pcEncTop->getAnalyzeP()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
@@ -2387,7 +2169,9 @@
     m_gcAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
 #endif
+
   }
   if (pcSlice->isInterB())
   {
+
 #if H_MV
     m_pcEncTop->getAnalyzeB()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
@@ -2395,4 +2179,5 @@
     m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
 #endif
+
   }
 
@@ -2401,4 +2186,5 @@
 
 #if ADAPTIVE_QP_SELECTION
+
 #if H_MV
   printf("Layer %3d   POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits",
@@ -2419,5 +2205,7 @@
          uibits );
 #endif
+
 #else
+
 #if H_MV
   printf("Layer %3d   POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits",
@@ -2436,4 +2224,5 @@
          uibits );
 #endif
+
 #endif
 
@@ -2468,9 +2257,9 @@
  * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
  */
-NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR)
+NalUnitType TEncGOP::getNalUnitType(Int pocCurr)
 {
   if (pocCurr == 0)
   {
-    return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
+    return NAL_UNIT_CODED_SLICE_IDR;
   }
   if (pocCurr % m_pcCfg->getIntraPeriod() == 0)
@@ -2482,5 +2271,5 @@
     else if (m_pcCfg->getDecodingRefreshType() == 2)
     {
-      return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
+      return NAL_UNIT_CODED_SLICE_IDR;
     }
   }
@@ -2494,12 +2283,5 @@
       // controlling the reference pictures used for encoding that leading picture. Such a leading 
       // picture need not be marked as a TFD picture.
-      return NAL_UNIT_CODED_SLICE_RASL_R;
-    }
-  }
-  if (lastIDR>0)
-  {
-    if (pocCurr < lastIDR)
-    {
-      return NAL_UNIT_CODED_SLICE_RADL_R;
+      return NAL_UNIT_CODED_SLICE_TFD;
     }
   }
@@ -2552,10 +2334,9 @@
 }
 
-/** Attaches the input bitstream to the stream in the output NAL unit
-    Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call.
- *  \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu
- *  \param rNalu          target NAL unit
+/** Determine the difference between consecutive tile sizes (in bytes) and writes it to  bistream rNalu [slice header]
+ * \param rpcBitstreamRedirect contains the bitstream to be concatenated to rNalu. rpcBitstreamRedirect contains slice payload. rpcSlice contains tile location information.
+ * \returns Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call.
  */
-Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData)
+Void TEncGOP::xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice)
 {
   // Byte-align
@@ -2563,12 +2344,30 @@
 
   // Perform bitstream concatenation
-  if (codedSliceData->getNumberOfWrittenBits() > 0)
-    {
-    rNalu.m_Bitstream.addSubstream(codedSliceData);
+  if (rpcBitstreamRedirect->getNumberOfWrittenBits() > 0)
+  {
+    UInt uiBitCount  = rpcBitstreamRedirect->getNumberOfWrittenBits();
+    if (rpcBitstreamRedirect->getByteStreamLength()>0)
+    {
+      UChar *pucStart  =  reinterpret_cast<UChar*>(rpcBitstreamRedirect->getByteStream());
+      UInt uiWriteByteCount = 0;
+      while (uiWriteByteCount < (uiBitCount >> 3) )
+      {
+        UInt uiBits = (*pucStart);
+        rNalu.m_Bitstream.write(uiBits, 8);
+        pucStart++;
+        uiWriteByteCount++;
+      }
+    }
+    UInt uiBitsHeld = (uiBitCount & 0x07);
+    for (UInt uiIdx=0; uiIdx < uiBitsHeld; uiIdx++)
+    {
+      rNalu.m_Bitstream.write((rpcBitstreamRedirect->getHeldBits() & (1 << (7-uiIdx))) >> (7-uiIdx), 1);
+    }          
   }
 
   m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream);
 
-  codedSliceData->clear();
+  delete rpcBitstreamRedirect;
+  rpcBitstreamRedirect = new TComOutputBitstream;
 }
 
@@ -2695,132 +2494,9 @@
      }               
   }
-//  assert(it != accessUnit.end());  // Triggers with some legit configurations
+  assert(it != accessUnit.end());
   return seiStartPos;
 }
 #endif
 
-#if L0386_DB_METRIC
-Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
-{
-  TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec();
-  Pel* Rec    = pcPicYuvRec->getLumaAddr( 0 );
-  Pel* tempRec = Rec;
-  Int  stride = pcPicYuvRec->getStride();
-  UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize();
-  UInt maxTBsize = (1<<log2maxTB);
-  const UInt minBlockArtSize = 8;
-  const UInt picWidth = pcPicYuvRec->getWidth();
-  const UInt picHeight = pcPicYuvRec->getHeight();
-  const UInt noCol = (picWidth>>log2maxTB);
-  const UInt noRows = (picHeight>>log2maxTB);
-  UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
-  UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
-  UInt colIdx = 0;
-  UInt rowIdx = 0;
-  Pel p0, p1, p2, q0, q1, q2;
-  
-  Int qp = pcPic->getSlice(0)->getSliceQp();
-  Int bitdepthScale = 1 << (g_bitDepthY-8);
-  Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale;
-  const Int thr2 = (beta>>2);
-  const Int thr1 = 2*bitdepthScale;
-  UInt a = 0;
-  
-  memset(colSAD, 0, noCol*sizeof(UInt64));
-  memset(rowSAD, 0, noRows*sizeof(UInt64));
-  
-  if (maxTBsize > minBlockArtSize)
-  {
-    // Analyze vertical artifact edges
-    for(Int c = maxTBsize; c < picWidth; c += maxTBsize)
-    {
-      for(Int r = 0; r < picHeight; r++)
-      {
-        p2 = Rec[c-3];
-        p1 = Rec[c-2];
-        p0 = Rec[c-1];
-        q0 = Rec[c];
-        q1 = Rec[c+1];
-        q2 = Rec[c+2];
-        a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1);
-        if ( thr1 < a && a < thr2)
-        {
-          colSAD[colIdx] += abs(p0 - q0);
-        }
-        Rec += stride;
-      }
-      colIdx++;
-      Rec = tempRec;
-    }
-    
-    // Analyze horizontal artifact edges
-    for(Int r = maxTBsize; r < picHeight; r += maxTBsize)
-    {
-      for(Int c = 0; c < picWidth; c++)
-      {
-        p2 = Rec[c + (r-3)*stride];
-        p1 = Rec[c + (r-2)*stride];
-        p0 = Rec[c + (r-1)*stride];
-        q0 = Rec[c + r*stride];
-        q1 = Rec[c + (r+1)*stride];
-        q2 = Rec[c + (r+2)*stride];
-        a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1);
-        if (thr1 < a && a < thr2)
-        {
-          rowSAD[rowIdx] += abs(p0 - q0);
-        }
-      }
-      rowIdx++;
-    }
-  }
-  
-  UInt64 colSADsum = 0;
-  UInt64 rowSADsum = 0;
-  for(Int c = 0; c < noCol-1; c++)
-  {
-    colSADsum += colSAD[c];
-  }
-  for(Int r = 0; r < noRows-1; r++)
-  {
-    rowSADsum += rowSAD[r];
-  }
-  
-  colSADsum <<= 10;
-  rowSADsum <<= 10;
-  colSADsum /= (noCol-1);
-  colSADsum /= picHeight;
-  rowSADsum /= (noRows-1);
-  rowSADsum /= picWidth;
-  
-  UInt64 avgSAD = ((colSADsum + rowSADsum)>>1);
-  avgSAD >>= (g_bitDepthY-8);
-  
-  if ( avgSAD > 2048 )
-  {
-    avgSAD >>= 9;
-    Int offset = Clip3(2,6,(Int)avgSAD);
-    for (Int i=0; i<uiNumSlices; i++)
-    {
-      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true);
-      pcPic->getSlice(i)->setDeblockingFilterDisable(false);
-      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset );
-      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset );
-    }
-  }
-  else
-  {
-    for (Int i=0; i<uiNumSlices; i++)
-    {
-      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false);
-      pcPic->getSlice(i)->setDeblockingFilterDisable(        pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() );
-      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
-      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2(   pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2()   );
-    }
-  }
-  
-  free(colSAD);
-  free(rowSAD);
-}
-#endif
 #if H_MV
 Void TEncGOP::xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid )
@@ -2846,5 +2522,5 @@
   {
     Int numModifications = 0;
-
+    
     for( Int k = 0; k < ge.m_numInterViewRefPics; k++ ) 
     {
@@ -2853,10 +2529,11 @@
 
     // set inter-view modifications
-    Bool isModified = false;
-    Int tempList[16];
-    for( Int k = 0; k < 16; k++ ) { tempList[k] = -1; }
-
     if( (maxRefListSize > 1) && (numModifications > 0) )
     {
+      refPicListModification->setRefPicListModificationFlagL( li, true );
+      Int tempList[16];
+      for( Int k = 0; k < 16; k++ ) { tempList[k] = -1; }
+
+      Bool isModified = false;
       for( Int k = 0; k < ge.m_numInterViewRefPics; k++ )
       {
@@ -2877,26 +2554,28 @@
         }
       }
-    }
-
-    refPicListModification->setRefPicListModificationFlagL( li, isModified );  
-
-    if( isModified )
-    {
-      Int temporalRefIdx = 0;
-      for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
-      {
-        if( tempList[i] >= 0 ) 
-        {
-          refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
-        }
-        else
-        {
-          refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
-          temporalRefIdx++;
-        }
-      }
-    }    
+      if( isModified )
+      {
+        Int temporalRefIdx = 0;
+        for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
+        {
+          if( tempList[i] >= 0 ) 
+          {
+            refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
+          }
+          else
+          {
+            refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
+            temporalRefIdx++;
+          }
+        }
+      }
+      else
+      {
+        refPicListModification->setRefPicListModificationFlagL( li, false );
+      }
+    }
   }
 }
 #endif
+
 //! \}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 438)
@@ -108,4 +108,5 @@
 #endif
 #endif
+
   //--Adaptive Loop filter
   TEncSampleAdaptiveOffset*  m_pcSAO;
@@ -131,8 +132,4 @@
   Bool                    m_bufferingPeriodSEIPresentInAU;
   Bool                    m_pictureTimingSEIPresentInAU;
-#if K0180_SCALABLE_NESTING_SEI
-  Bool                    m_nestedBufferingPeriodSEIPresentInAU;
-  Bool                    m_nestedPictureTimingSEIPresentInAU;
-#endif
 #endif
 public:
@@ -144,4 +141,5 @@
   
   Void  init        ( TEncTop* pcTEncTop );
+
 #if H_MV
   Void  initGOP     ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP);
@@ -150,5 +148,6 @@
   Void  compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
 #endif
-  Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
+
+  Void xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice);
 
 #if H_MV
@@ -168,8 +167,9 @@
   Void  printOutSummary      ( UInt uiNumAllPicCoded );
 #endif
+
   Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
   
   TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
-  NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );
+  NalUnitType getNalUnitType( Int pocCurr );
   Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& );
 protected:
@@ -189,8 +189,4 @@
   SEIFramePacking*        xCreateSEIFramePacking();
   SEIDisplayOrientation*  xCreateSEIDisplayOrientation();
-
-#if J0149_TONE_MAPPING_SEI
-  SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
-#endif
 
   Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
@@ -203,18 +199,10 @@
     m_pictureTimingSEIPresentInAU      = false;
   }
-#if K0180_SCALABLE_NESTING_SEI
-  Void xResetNestedSEIPresentFlags()
-  {
-    m_nestedBufferingPeriodSEIPresentInAU    = false;
-    m_nestedPictureTimingSEIPresentInAU      = false;
-  }
-#endif
-#endif
+#endif
+
 #if H_MV
    Void  xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid );
 #endif
-#if L0386_DB_METRIC
-  Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
-#endif
+
 };// END CLASS DEFINITION TEncGOP
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 438)
@@ -1677,4 +1677,12 @@
 #endif
 {
+#if SAO_CHROMA_LAMBDA 
+  m_dLambdaLuma    = dLambdaLuma;
+  m_dLambdaChroma  = dLambdaChroma;
+#else
+  m_dLambdaLuma    = dLambda;
+  m_dLambdaChroma  = dLambda;
+#endif
+
   if(m_bUseNIF)
   {
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h	(revision 438)
@@ -57,4 +57,7 @@
 {
 private:
+  Double            m_dLambdaLuma;
+  Double            m_dLambdaChroma;
+
   TEncEntropy*      m_pcEntropyCoder;
   TEncSbac***       m_pppcRDSbacCoder;              ///< for CABAC
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSbac.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSbac.h	(revision 438)
@@ -109,4 +109,5 @@
   Void  xWriteEpExGolomb     ( UInt uiSymbol, UInt uiCount );
   Void  xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam );
+  Void  xWriteTerminatingBit ( UInt uiBit );
   
   Void  xCopyFrom            ( TEncSbac* pSrc );
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 438)
@@ -3209,11 +3209,4 @@
     UInt          uiBitsTempL0[MAX_NUM_REF];
 
-#if L0034_COMBINED_LIST_CLEANUP
-    TComMv        mvValidList1;
-    Int           refIdxValidList1 = 0;
-    UInt          bitsValidList1 = MAX_UINT;
-    UInt          costValidList1 = MAX_UINT;
-#endif
-
     xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     
@@ -3262,10 +3255,6 @@
         uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
 #if ZERO_MVD_EST
-#if L0034_COMBINED_LIST_CLEANUP
-        if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
-#else
         if ((iRefList != 1 || !pcCU->getSlice()->getNoBackPredFlag()) &&
             (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 || pcCU->getSlice()->getRefIdxOfLC(eRefPicList, iRefIdxTemp)>=0))
-#endif
         {
           uiZeroMvdBitsTemp = uiBitsTemp;
@@ -3287,29 +3276,4 @@
         
 #if GPB_SIMPLE_UNI
-#if L0034_COMBINED_LIST_CLEANUP
-        if ( iRefList == 1 )    // list 1
-        {
-          if ( pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) >= 0 )
-          {
-            cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )];
-            uiCostTemp = uiCostTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )];
-            /*first subtract the bit-rate part of the cost of the other list*/
-            uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp )] );
-            /*correct the bit-rate part of the current ref*/
-            m_pcRdCost->setPredictor  ( cMvPred[iRefList][iRefIdxTemp] );
-            uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() );
-            /*calculate the correct cost*/
-            uiCostTemp += m_pcRdCost->getCost( uiBitsTemp );
-          }
-          else
-          {
-            xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
-          }
-        }
-        else
-        {
-          xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
-        }
-#else
         if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0)
         {
@@ -3353,5 +3317,4 @@
           }        
         }
-#endif
 #else
         xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
@@ -3360,30 +3323,4 @@
         xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
 
-#if L0034_COMBINED_LIST_CLEANUP
-        if ( iRefList == 0 )
-        {
-          uiCostTempL0[iRefIdxTemp] = uiCostTemp;
-          uiBitsTempL0[iRefIdxTemp] = uiBitsTemp;
-        }
-        if ( uiCostTemp < uiCost[iRefList] )
-        {
-          uiCost[iRefList] = uiCostTemp;
-          uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction
-
-          // set motion
-          cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
-          iRefIdx[iRefList] = iRefIdxTemp;
-        }
-
-        if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
-        {
-          costValidList1 = uiCostTemp;
-          bitsValidList1 = uiBitsTemp;
-
-          // set motion
-          mvValidList1     = cMvTemp[iRefList][iRefIdxTemp];
-          refIdxValidList1 = iRefIdxTemp;
-        }
-#else
         if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && !pcCU->getSlice()->getNoBackPredFlag())
         {
@@ -3435,5 +3372,4 @@
             }
           }
-#endif
       }
     }
@@ -3499,33 +3435,8 @@
         
         Int         iRefList    = iIter % 2;
-#if L0034_COMBINED_LIST_CLEANUP
-        if ( m_pcEncCfg->getUseFastEnc() )
-        {
-          if( uiCost[0] <= uiCost[1] )
-          {
-            iRefList = 1;
-          }
-          else
-          {
-            iRefList = 0;
-          }
-        }
-        else if ( iIter == 0 )
-        {
-          iRefList = 0;
-        }
-        if ( iIter == 0 && !pcCU->getSlice()->getMvdL1ZeroFlag())
-        {
-          pcCU->getCUMvField(RefPicList(1-iRefList))->setAllMv( cMv[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
-          pcCU->getCUMvField(RefPicList(1-iRefList))->setAllRefIdx( iRefIdx[1-iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
-          TComYuv*  pcYuvPred = &m_acYuvPred[1-iRefList];
-          motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx );
-        }
-#else
         if ( m_pcEncCfg->getUseFastEnc() && (pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 )) )
         {
           iRefList = 1;
         }
-#endif
         RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
 
@@ -3662,15 +3573,8 @@
     UInt uiMEBits = 0;
     // Set Motion Field_
-#if L0034_COMBINED_LIST_CLEANUP
-    cMv[1] = mvValidList1;
-    iRefIdx[1] = refIdxValidList1;
-    uiBits[1] = bitsValidList1;
-    uiCost[1] = costValidList1;
-#else
     if ( pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 ) )
     {
       uiCost[1] = MAX_UINT;
     }
-#endif
 #if AMP_MRG
     if (bTestNormalMC)
@@ -4618,5 +4522,5 @@
     while( pcCU->getWidth(0) > (pcCU->getSlice()->getSPS()->getMaxTrSize()<<uiTrLevel) ) uiTrLevel++;
   }
-  UInt uiMaxTrMode = 1 + uiTrLevel;
+  UInt uiMaxTrMode = pcCU->getSlice()->getSPS()->getMaxTrDepth() + uiTrLevel;
   
   while((uiWidth>>uiMaxTrMode) < (g_uiMaxCUWidth>>g_uiMaxCUDepth)) uiMaxTrMode--;
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 438)
@@ -414,5 +414,4 @@
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
 #endif
-
   rpcSlice->setSliceType        ( eSliceType );
 #endif
@@ -439,13 +438,4 @@
 #endif
 
-#if L0386_DB_METRIC
-  if ( m_pcCfg->getDeblockingFilterMetric() )
-  {
-    rpcSlice->setDeblockingFilterOverrideFlag(true);
-    rpcSlice->setDeblockingFilterDisable(false);
-    rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
-    rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
-  } else
-#endif
   if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
   {
@@ -1233,5 +1223,5 @@
  \retval rpcBitstream  bitstream class
  */
-Void TEncSlice::encodeSlice   ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams )
+Void TEncSlice::encodeSlice   ( TComPic*& rpcPic, TComOutputBitstream* pcBitstream, TComOutputBitstream* pcSubstreams )
 {
   UInt       uiCUAddr;
@@ -1413,5 +1403,37 @@
       }
       {
-        UInt numStartCodeEmulations = pcSubstreams[uiSubStrm].countStartCodeEmulations();
+          UInt uiCounter = 0;
+          vector<uint8_t>& rbsp   = pcSubstreams[uiSubStrm].getFIFO();
+          for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
+          {
+            /* 1) find the next emulated 00 00 {00,01,02,03}
+             * 2a) if not found, write all remaining bytes out, stop.
+             * 2b) otherwise, write all non-emulated bytes out
+             * 3) insert emulation_prevention_three_byte
+             */
+            vector<uint8_t>::iterator found = it;
+            do
+            {
+              /* NB, end()-1, prevents finding a trailing two byte sequence */
+              found = search_n(found, rbsp.end()-1, 2, 0);
+              found++;
+              /* if not found, found == end, otherwise found = second zero byte */
+              if (found == rbsp.end())
+              {
+                break;
+              }
+              if (*(++found) <= 3)
+              {
+                break;
+              }
+            } while (true);
+            it = found;
+            if (found != rbsp.end())
+            {
+              it++;
+              uiCounter++;
+            }
+          }
+        
         UInt uiAccumulatedSubstreamLength = 0;
         for (Int iSubstrmIdx=0; iSubstrmIdx < iNumSubstreams; iSubstrmIdx++)
@@ -1421,5 +1443,5 @@
         // add bits coded in previous dependent slices + bits coded so far
         // add number of emulation prevention byte count in the tile
-        pcSlice->addTileLocation( ((pcSlice->getTileOffstForMultES() + uiAccumulatedSubstreamLength - uiBitsOriginallyInSubstreams) >> 3) + numStartCodeEmulations );
+        pcSlice->addTileLocation( ((pcSlice->getTileOffstForMultES() + uiAccumulatedSubstreamLength - uiBitsOriginallyInSubstreams) >> 3) + uiCounter );
       }
     }
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSlice.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncSlice.h	(revision 438)
@@ -122,5 +122,5 @@
   Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
   Void    compressSlice       ( TComPic*& rpcPic                                );      ///< analysis stage of slice
-  Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams  );
+  Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* rpcBitstream, TComOutputBitstream* pcSubstreams  );
   
   // misc. functions
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 438)
@@ -81,4 +81,5 @@
   m_pcBitCounters          = NULL;
   m_pcRdCosts              = NULL;
+
 #if H_MV
   m_ivPicLists = NULL;
@@ -95,4 +96,5 @@
 Void TEncTop::create ()
 {
+
 #if !H_MV
   // initialize global variables
@@ -286,4 +288,5 @@
 Void TEncTop::init()
 {
+
   // initialize SPS
   xInitSPS();
@@ -345,4 +348,5 @@
 }
 #endif
+
 Void TEncTop::deletePicBuffer()
 {
@@ -371,11 +375,11 @@
  \retval  iNumEncoded         number of encoded pictures
  */
+Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded 
 #if H_MV
-Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded , Int gopId )
-{
-#else
-Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
-{
-#endif
+                     , Int gopId 
+#endif               
+                     )
+{
+
 #if H_3D
   TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() );
@@ -385,4 +389,5 @@
   }
 #endif
+
 #if H_MV
   if( gopId == 0)
@@ -438,7 +443,9 @@
   m_iNumPicRcvd       = 0;
   m_uiNumAllPicCoded += iNumEncoded;
+
 #if H_MV
 }
 #endif
+
 }
 
@@ -540,15 +547,6 @@
   m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
   m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
-
-  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
-  Int log2MinCUSize = 0;
-  while(minCUSize > 1)
-  {
-    minCUSize >>= 1;
-    log2MinCUSize++;
-  }
-
-  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
-  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth);
+  m_cSPS.setMinTrDepth    ( 0                   );
+  m_cSPS.setMaxTrDepth    ( 1                   );
   
   m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
@@ -565,7 +563,6 @@
 
   m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
-#if !L0034_COMBINED_LIST_CLEANUP
+  
   m_cSPS.setUseLComb    ( m_bUseLComb           );
-#endif
   
   Int i;
@@ -719,20 +716,5 @@
   m_cPPS.setOutputFlagPresentFlag( false );
   m_cPPS.setSignHideFlag(getSignHideFlag());
-#if L0386_DB_METRIC
-  if ( getDeblockingFilterMetric() )
-  {
-    m_cPPS.setDeblockingFilterControlPresentFlag (true);
-    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
-    m_cPPS.setPicDisableDeblockingFilterFlag(false);
-    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
-    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
-  } 
-  else
-  {
   m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
-  }
-#else
-  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
-#endif
   m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
   m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
@@ -1006,38 +988,5 @@
   }
 #endif
-
-}
-
-#if L0208_SOP_DESCRIPTION_SEI
-Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
-{
-  int rpsIdx = GOPid;
-
-  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
-  {    
-    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
-    {
-      Int POCIndex = POCCurr%m_uiIntraPeriod;
-      if(POCIndex == 0)
-      {
-        POCIndex = m_uiIntraPeriod;
-      }
-      if(POCIndex == m_GOPList[extraNum].m_POC)
-      {
-        rpsIdx = extraNum;
-      }
-    }
-    else
-    {
-      if(POCCurr==m_GOPList[extraNum].m_POC)
-      {
-        rpsIdx = extraNum;
-      }
-    }
-  }
-
-  return rpsIdx;
-}
-#endif
+}
 
 Void  TEncTop::xInitPPSforTiles()
@@ -1120,4 +1069,5 @@
   }
 }
+
 #if H_MV
 Void TEncTop::printSummary( Int numAllPicCoded )
@@ -1182,3 +1132,4 @@
 }
 #endif
+
 //! \}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 438)
@@ -63,4 +63,6 @@
 // Class definition
 // ====================================================================================================================
+
+
 
 /// encoder class
@@ -131,4 +133,5 @@
   TEncAnalyze             m_cAnalyzeB;  
 #endif
+
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -145,8 +148,11 @@
   Void      create          ();
   Void      destroy         ();
+
   Void      init            ();
+
 #if H_MV  
   TComPicLists* getIvPicLists() { return m_ivPicLists; }
 #endif
+
   Void      deletePicBuffer ();
 
@@ -156,4 +162,5 @@
   Void      initNewPic(TComPicYuv* pcPicYuvOrg);
 #endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // member access functions
@@ -188,8 +195,6 @@
   TComPPS*                getPPS                () { return  &m_cPPS;                 }
   Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid );
-#if L0208_SOP_DESCRIPTION_SEI
-  Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid );
-#endif
   TComScalingList*        getScalingList        () { return  &m_scalingList;         }
+
 #if H_MV
   TEncAnalyze*            getAnalyzeAll         () { return &m_cAnalyzeAll; }
@@ -205,4 +210,6 @@
   Void                    setIvPicLists         ( TComPicLists* picLists) { m_ivPicLists = picLists; }
 #endif
+
+
   // -------------------------------------------------------------------------------------------------------------------
   // encoder function
@@ -210,16 +217,17 @@
 
   /// encode several number of pictures until end-of-sequence
-#if H_MV
-  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded  , Int gopId  );  
-#else
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
-              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );  
-#endif
-
-#if H_MV
-  Void printSummary      ( Int numAllPicCoded ); 
+              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded 
+#if H_MV
+              , Int gopId 
+#endif        
+              );  
+
+#if H_MV
+  void printSummary      ( Int numAllPicCoded ); 
 #else
   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
 #endif
+
 };
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp	(revision 437)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp	(revision 438)
@@ -235,15 +235,11 @@
         Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom );
 
-        // Chroma offset range limitation
+        // Chroma offset range limination
         if(comp)
         {
-          Int pred = ( 128 - ( ( 128*weight)>>(log2Denom) ) );
+          Int shift = 1 << (g_bitDepthC - 1);
+          Int pred = ( shift - ( ( shift*weight)>>(log2Denom) ) );
           Int deltaOffset = Clip3( -512, 511, (offset - pred) );    // signed 10bit
           offset = Clip3( -128, 127, (deltaOffset + pred) );        // signed 8bit
-        }
-        // Luma offset range limitation
-        else
-        {
-          offset = Clip3( -128, 127, offset);
         }
 
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibExtractor/TExtrTop.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 438)
@@ -0,0 +1,111 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.  
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file     TExtrTop.cpp
+    \brief    extractor class
+*/
+
+#include "TExtrTop.h"
+
+TExtrTop::TExtrTop()
+{
+}
+
+TExtrTop::~TExtrTop()
+{
+}
+
+Void TExtrTop::init()
+{
+  m_cEntropyDecoder.init(&m_cPrediction);
+
+  m_acSPSBuffer.clear();
+}
+
+Bool TExtrTop::extract( InputNALUnit& nalu, std::set<UInt>& rsuiExtractLayerIds )
+{
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
+  //extraction now has to be done using layer_id
+  UInt uiLayerId = nalu.m_layerId;
+#else
+  UInt uiLayerId = xGetLayerId( nalu.m_viewId, nalu.m_isDepth );
+#endif
+  // Initialize entropy decoder
+  m_cEntropyDecoder.setEntropyDecoder( &m_cCavlcDecoder );
+  m_cEntropyDecoder.setBitstream     ( nalu.m_Bitstream );
+  
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
+  if ( nalu.m_nalUnitType == NAL_UNIT_VPS )
+  {
+    // a hack for now assuming there's only one VPS in the bitstream
+    m_cEntropyDecoder.decodeVPS( &m_cVPS );
+      
+  }
+#endif
+
+  if ( nalu.m_nalUnitType == NAL_UNIT_SPS )
+  {
+     TComSPS cSPS;
+     TComRPSList cRPS;
+     cSPS.setRPSList( &cRPS );
+#if HHI_MPI || H3D_QTL
+#if VIDYO_VPS_INTEGRATION
+     m_cEntropyDecoder.decodeSPS( &cSPS, m_cVPS.getDepthFlag(uiLayerId) );
+#else
+     m_cEntropyDecoder.decodeSPS( &cSPS, nalu.m_isDepth );
+#endif
+#else
+     m_cEntropyDecoder.decodeSPS( &cSPS );
+#endif
+
+     m_acSPSBuffer.push_back( cSPS );
+  }
+
+  return ( rsuiExtractLayerIds.find( uiLayerId ) != rsuiExtractLayerIds.end() );
+}
+
+
+Void TExtrTop::dumpSpsInfo( std::ostream& rcSpsInfoHandle )
+{
+  rcSpsInfoHandle << "NumSPS = " << m_acSPSBuffer.size() << std::endl;
+
+  for( std::list<TComSPS>::iterator iterSPS = m_acSPSBuffer.begin(); iterSPS != m_acSPSBuffer.end(); iterSPS++ )
+  {
+     rcSpsInfoHandle << std::endl;
+     rcSpsInfoHandle << "layer_id = "              << xGetLayerId( iterSPS->getViewId(), iterSPS->isDepth() ) << std::endl;
+     rcSpsInfoHandle << "seq_parameter_set_id = "  << iterSPS->getSPSId() << std::endl;
+     rcSpsInfoHandle << "view_id = "               << iterSPS->getViewId() << std::endl;
+     rcSpsInfoHandle << "view_order_idx = "        << iterSPS->getViewOrderIdx() << std::endl;
+     rcSpsInfoHandle << "is_depth = "              << iterSPS->isDepth() << std::endl;
+  }
+}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibExtractor/TExtrTop.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibExtractor/TExtrTop.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibExtractor/TExtrTop.h	(revision 438)
@@ -0,0 +1,83 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.  
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** \file     TDecTop.h
+    \brief    decoder class (header)
+*/
+
+#ifndef __TEXTRTOP__
+#define __TEXTRTOP__
+
+#include "../TLibCommon/TComSlice.h"
+#include "../TLibCommon/TComPrediction.h"
+#include "../TLibDecoder/TDecCAVLC.h"
+#include "../TLibDecoder/NALread.h"
+#include <list>
+#include <set>
+
+// ====================================================================================================================
+// Class definition
+// ====================================================================================================================
+
+/// decoder class
+class TExtrTop
+{
+private:
+#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
+  TComVPS                 m_cVPS;
+#endif
+   std::list<TComSPS>      m_acSPSBuffer;
+
+  // functional classes
+  TComPrediction           m_cPrediction;
+  TDecEntropy              m_cEntropyDecoder;
+  TDecCavlc                m_cCavlcDecoder;
+
+public:
+  TExtrTop();
+  virtual ~TExtrTop();
+  
+  Void     init();
+
+  Bool     extract( InputNALUnit& nalu, std::set<UInt>& rsuiExtractLayerIds );
+  Void     dumpSpsInfo( std::ostream& rcSpsInfoHandle );
+  
+  TComSPS *getFirstSPS() { return m_acSPSBuffer.empty() ? 0 : &(m_acSPSBuffer.front()); }
+
+protected:
+   UInt     xGetLayerId( UInt uiViewId, Bool bIsDepth ) { return ( ( uiViewId << 1 ) + ( bIsDepth ? 1 : 0 ) ); }
+};// END CLASS DEFINITION TExtrTop
+
+
+#endif // __TEXTRTOP__
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenFilter.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenFilter.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenFilter.cpp	(revision 438)
@@ -0,0 +1,1433 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "TRenImage.h"
+#include "TRenFilter.h"
+#include "TRenInterpFilter.h"
+
+
+///// COMMON /////
+Void TRenFilter::setSubPelShiftLUT( Int iLutPrec, Int** piSubPelShiftLUT, Int iShift )
+{
+  //ToDo: use same rounding for left and right
+  AOT( iLutPrec < 0 || iLutPrec > 2 );
+  Int iStep = 1 << iLutPrec;
+  for (Int iDelta = 0; iDelta < (iStep << 1)+1; iDelta++ )
+  {
+    for (Int iCurDelta = 0; iCurDelta < (iStep << 1)+1; iCurDelta++ )
+    {
+      if (iCurDelta <= iDelta)
+      {
+        piSubPelShiftLUT[iDelta][iCurDelta] =  (iDelta != 0) ?( ( iStep * iCurDelta + ( iDelta >> 1) )/ iDelta) + iShift * iStep :  iShift * iStep;
+      }
+      else
+      {
+        piSubPelShiftLUT[iDelta][iCurDelta] = 0xdeaddead;
+      }
+    }
+  }
+}
+
+Void TRenFilter::setupZLUT( Bool bBlendUseDistWeight, Int iBlendZThresPerc, Int iRelDistToLeft, Int** ppiBaseShiftLUTLeft, Int** ppiBaseShiftLUTRight, Int& riBlendZThres, Int& riBlendDistWeight, Int* piInvZLUTLeft, Int* piInvZLUTRight )
+{
+  AOT( iRelDistToLeft == -1 );
+  riBlendDistWeight = bBlendUseDistWeight ? iRelDistToLeft :  1 << (REN_VDWEIGHT_PREC - 1);
+
+  for (UInt uiDepthValue = 0; uiDepthValue <= 256; uiDepthValue++)
+  {
+    //GT: retrieve depth approx from shift
+    piInvZLUTLeft [uiDepthValue] = abs( ppiBaseShiftLUTLeft [0][uiDepthValue] );
+    piInvZLUTRight[uiDepthValue] = abs( ppiBaseShiftLUTRight[0][uiDepthValue] );
+  }
+  // Set Threshold
+  riBlendZThres  = ( Max( abs(piInvZLUTLeft[0]- piInvZLUTLeft[255]), abs(piInvZLUTRight[0]- piInvZLUTRight[255]) ) * iBlendZThresPerc + 50)  / 100;
+}
+
+Void TRenFilter::filledToUsedPelMap( PelImage* pcFilledImage, PelImage* pcUsedPelsImage, Int iUsedPelMapMarExt )
+{
+  // Convert to binary map
+  Int iWidth  = pcFilledImage      ->getPlane(0)->getWidth ();
+  Int iHeight = pcFilledImage      ->getPlane(0)->getHeight();
+
+  AOT( iWidth  != pcUsedPelsImage  ->getPlane(0)->getWidth () );
+  AOT( iHeight != pcUsedPelsImage  ->getPlane(0)->getHeight() );
+  AOF( pcUsedPelsImage->is420() );
+
+  Int iSrcStride  = pcFilledImage  ->getPlane(0)->getStride();
+  Int iDstStrideY = pcUsedPelsImage->getPlane(0)->getStride();
+  Int iDstStrideU = pcUsedPelsImage->getPlane(1)->getStride();
+  Int iDstStrideV = pcUsedPelsImage->getPlane(2)->getStride();
+
+  Pel* pcSrcData  = pcFilledImage  ->getPlane(0)->getPlaneData();
+  Pel* pcDstDataY = pcUsedPelsImage->getPlane(0)->getPlaneData();
+  Pel* pcDstDataU = pcUsedPelsImage->getPlane(1)->getPlaneData();
+  Pel* pcDstDataV = pcUsedPelsImage->getPlane(2)->getPlaneData(); // Only used as buffer
+
+  for (Int iPosY = 0; iPosY < iHeight; iPosY++ )
+  {
+    for (Int iPosX = 0; iPosX < iWidth; iPosX++ )
+    {
+      pcDstDataY[iPosX] = ( pcSrcData[iPosX] != REN_IS_FILLED ) ? REN_USED_PEL : REN_UNUSED_PEL;
+
+      if ((iPosX & 1) && (iPosY & 1))
+      {
+        pcDstDataU[iPosX >> 1] = (   ( pcSrcData[iPosX                 ] != REN_IS_FILLED )
+          || ( pcSrcData[iPosX - 1             ] != REN_IS_FILLED )
+          || ( pcSrcData[iPosX     - iSrcStride] != REN_IS_FILLED )
+          || ( pcSrcData[iPosX - 1 - iSrcStride] != REN_IS_FILLED )
+          ) ? REN_USED_PEL : REN_UNUSED_PEL;
+      }
+    }
+
+    if ( iPosY & 1 )
+    {
+      pcDstDataU += iDstStrideU;
+    }
+
+    pcDstDataY += iDstStrideY;
+    pcSrcData  += iSrcStride;
+  }
+
+  //// Dilatation for Interpolation Filters ////
+  //GT: should better be defined somewhere else ...
+  const Int iLumaIntFiltHalfSize   = 4;
+  const Int iChromaIntFiltHalfSize = 2;
+
+  Int iDilateSizeLuma   = iLumaIntFiltHalfSize   +   iUsedPelMapMarExt      ;
+  Int iDilateSizeChroma = iChromaIntFiltHalfSize + ( iUsedPelMapMarExt >> 1);
+
+  pcDstDataY = pcUsedPelsImage->getPlane(0)->getPlaneData();
+  pcDstDataU = pcUsedPelsImage->getPlane(1)->getPlaneData();
+  pcDstDataV = pcUsedPelsImage->getPlane(2)->getPlaneData();
+
+  // Dilate Luma horizontally
+  xDilate( pcDstDataY, iDstStrideY, iWidth, iHeight, pcDstDataY, iDstStrideY, iDilateSizeLuma, false, true  );
+  xDilate( pcDstDataY, iDstStrideY, iWidth, iHeight, pcDstDataY, iDstStrideY, iDilateSizeLuma, false, false );
+
+  // Dilate Chorma vertically and horizontally (for UV-up)
+  xDilate( pcDstDataU, iDstStrideU, iWidth>>1, iHeight>>1, pcDstDataU, iDstStrideU, iDilateSizeChroma, false, true  );
+  xDilate( pcDstDataU, iDstStrideU, iWidth>>1, iHeight>>1, pcDstDataU, iDstStrideU, iDilateSizeChroma, false, false );
+
+  xDilate( pcDstDataU, iDstStrideU, iWidth>>1, iHeight>>1, pcDstDataU, iDstStrideU, iChromaIntFiltHalfSize, true, true  );
+  xDilate( pcDstDataU, iDstStrideU, iWidth>>1, iHeight>>1, pcDstDataU, iDstStrideU, iChromaIntFiltHalfSize, true, false );
+
+  for (Int iPosY = 0; iPosY < (iHeight >> 1); iPosY++ )
+  {
+    for (Int iPosX = 0; iPosX < (iWidth >> 1); iPosX++ )
+    {
+      pcDstDataV[iPosX] = pcDstDataU[iPosX];
+    }
+
+    pcDstDataU += iDstStrideU;
+    pcDstDataV += iDstStrideV;
+  }
+}
+
+/////////// Copy /////////////
+Void TRenFilter::copy(Pel* pcInputPlaneData, Int iInputStride, Int iWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  xDistributeArray(pcInputPlaneData, iInputStride, 1, 1, iWidth, iHeight ,pcOutputPlaneData, iOutputStride, 1 , 1 );
+
+}
+
+/////////// Horizontal Mirror ///////////
+template <typename T>
+Void TRenFilter::mirrorHor( TRenImage<T> *pcImage )
+{
+  for (UInt uCurPlane = 0 ; uCurPlane < pcImage->getNumberOfPlanes(); uCurPlane++ )
+  {
+    mirrorHor( pcImage->getPlane(uCurPlane) );
+  }
+}
+
+template <typename T>
+Void TRenFilter::mirrorHor( TRenImagePlane<T> *pcImagePlane )
+{
+  T* pcPlaneData = pcImagePlane->getPlaneDataOrg();
+  T cTemp;
+  UInt uiStride = pcImagePlane->getStride();
+  UInt uiHeight = pcImagePlane->getHeightOrg();
+  UInt uiWidth  = pcImagePlane->getWidthOrg();
+
+  for (UInt uiPosY = 0; uiPosY < uiHeight; uiPosY++)
+  {
+    for (UInt uiPosX = 0; uiPosX < ( (uiWidth+1) >> 1); uiPosX++ )
+    {
+      cTemp = pcPlaneData[uiPosX];
+      pcPlaneData[uiPosX] = pcPlaneData[uiWidth - uiPosX-1];
+      pcPlaneData[uiWidth-uiPosX-1] = cTemp;
+    }
+    pcPlaneData += uiStride;
+  }
+}
+
+/////////// Comparison ///////////
+Int64 TRenFilter::SSE   (PelImagePlane* pcInputPlane1, PelImagePlane* pcInputPlane2   )
+{
+  UInt uiWidth     = pcInputPlane1->getWidth();
+  UInt uiHeight    = pcInputPlane1->getHeight();
+
+  UInt uiStride1   = pcInputPlane1->getStride();
+  UInt uiStride2   = pcInputPlane2->getStride();
+
+  Pel* pucImData1  = pcInputPlane1->getPlaneData();
+  Pel* pucImData2  = pcInputPlane2->getPlaneData();
+
+  return SSE( pucImData1, (Int) uiStride1, (Int) uiWidth, (Int) uiHeight, pucImData2, (Int) uiStride2 );
+}
+
+Int64 TRenFilter::SSE( Pel* piSrc1, Int iSrcStride1, Int iWidth, Int iHeight,  Pel* piSrc2, Int iSrcStride2 )
+{
+  Int64 iSSE = 0;
+
+  Int iShift = g_uiBitIncrement << 1;
+  for(Int iPosY = 0; iPosY < iHeight; iPosY++)
+  {
+    for(Int iPosX = 0; iPosX < iWidth; iPosX++)
+    {
+      Int iDiff = ( piSrc1[iPosX] - piSrc2[iPosX] );
+      iSSE += (( iDiff * iDiff ) >> iShift);
+    }
+    piSrc1 += iSrcStride1;
+    piSrc2 += iSrcStride2;
+  }
+  return iSSE;
+}
+
+template <typename T>
+Bool TRenFilter::compare( TRenImage<T> *pInputImage1, TRenImage<T> *pInputImage2 )
+{
+  Bool bIsEqual = true;
+  for (UInt uiCurPlane = 0 ; uiCurPlane < pInputImage1->getNumberOfPlanes(); uiCurPlane++ )
+  {
+    bIsEqual = bIsEqual && compare(pInputImage1->getPlane(uiCurPlane), pInputImage2->getPlane(uiCurPlane));
+  }
+  return bIsEqual;
+}
+
+template <typename T>
+Bool TRenFilter::compare   (TRenImagePlane<T>* pcInputPlane1  , TRenImagePlane<T>* pcInputPlane2   )
+{
+  UInt uiWidth  = pcInputPlane1->getWidth();
+  UInt uiHeight = pcInputPlane1->getHeight();
+
+  UInt uiStride1 = pcInputPlane1->getStride();
+  UInt uiStride2 = pcInputPlane2->getStride();
+
+  T* pucImData1  = pcInputPlane1->getPlaneData();
+  T* pucImData2  = pcInputPlane2->getPlaneData();
+
+  Bool bEqual = true;
+  for(UInt uiPosY = 0; uiPosY < uiHeight; uiPosY++)
+  {
+
+    for(UInt uiPosX = 0; uiPosX < uiWidth; uiPosX++)
+    {
+      bEqual = bEqual && ( pucImData1[uiPosX] == pucImData2[uiPosX]);
+    }
+    pucImData1 += uiStride1;
+    pucImData2 += uiStride2;
+  }
+  return bEqual;
+}
+
+/////////// Sampling ///////////
+
+inline Void TRenFilter::sampleUp2Tap13(PelImage* pcInputImage, PelImage* pcOutputImage)
+{// UpSampling from JSVM Software (DownConvertStatic) ???
+  UInt uiNumPlanes = pcInputImage->getNumberOfPlanes();
+
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumPlanes; uiCurPlane++)
+  {
+    PelImagePlane* pcInputPlane  = pcInputImage ->getPlane(uiCurPlane);
+    PelImagePlane* pcOutputPlane = pcOutputImage->getPlane(uiCurPlane);
+
+    Int iWidth  = pcInputPlane->getWidth();
+    Int iHeight = pcInputPlane->getHeight();
+
+    Int iInputStride  = pcInputPlane->getStride();
+    Int iOutputStride = pcOutputPlane->getStride();
+
+    assert( iWidth  == 2 * pcOutputPlane->getWidth ());
+    assert( iHeight == 2 * pcOutputPlane->getHeight());
+
+    Int iOffset;
+
+    Pel *pcInputPlaneData   = pcInputPlane->getPlaneData();
+    Int *piDataVerUp        = new Int[iWidth * iHeight * 2];
+    Pel *pcOutputPlaneData  = pcOutputPlane->getPlaneData();
+
+    // Up sampling filter.
+    Int aiFilterCoeff[16] = { 0, 0, 1, 0, -5, 0, 20, 32, 20, 0, -5,  0, 1, 0, 0, 32 };
+
+    // Normalization factors for filtered values.
+    Int iDivH = 1, iDivV = 1, iAddH = 0, iAddV = 0;
+
+    // Factors after horizontal and vertical filtering.
+    iDivH = (aiFilterCoeff[15]*aiFilterCoeff[15]); iAddH = iDivH / 2;
+
+    Int* piDst = new Int[2*iWidth];
+    //1) VERTICAL UPSAMPLING.
+
+    // Process all cols.
+    for(Int i=0; i<iWidth; i++ )
+    {
+      // Set source (col) poInter.
+      Pel* pcSrc = &pcInputPlaneData[i];
+
+      // Process all rows.
+      for( Int j=0; j<iHeight; j++ )
+      {
+        // Adjust indices of border samples.
+        Int i00 = ((j <   3) ? 0   : j-3) * iInputStride;
+        Int i01 = ((j <   2) ? 0   : j-2) * iInputStride;
+        Int i02 = ((j <   1) ? 0   : j-1) * iInputStride;
+        Int i03 = ((j < iHeight  ) ? j   : j-1) * iInputStride;
+        Int i04 = ((j < iHeight-1) ? j+1 : j-1) * iInputStride;
+        Int i05 = ((j < iHeight-2) ? j+2 : j-1) * iInputStride;
+        Int i06 = ((j < iHeight-3) ? j+3 : j-1) * iInputStride;
+        Int i07 = ((j < iHeight-4) ? j+4 : j-1) * iInputStride;
+
+        // Calculate filtered (even) sample.
+        piDst[2*j+0] = aiFilterCoeff[13] * pcSrc[i00]
+        + aiFilterCoeff[11] * pcSrc[i01]
+        + aiFilterCoeff[ 9] * pcSrc[i02]
+        + aiFilterCoeff[ 7] * pcSrc[i03]
+        + aiFilterCoeff[ 5] * pcSrc[i04]
+        + aiFilterCoeff[ 3] * pcSrc[i05]
+        + aiFilterCoeff[ 1] * pcSrc[i06];
+
+        // Calculate filtered (odd) sample.
+        piDst[2*j+1] = aiFilterCoeff[14] * pcSrc[i00]
+        + aiFilterCoeff[12] * pcSrc[i01]
+        + aiFilterCoeff[10] * pcSrc[i02]
+        + aiFilterCoeff[ 8] * pcSrc[i03]
+        + aiFilterCoeff[ 6] * pcSrc[i04]
+        + aiFilterCoeff[ 4] * pcSrc[i05]
+        + aiFilterCoeff[ 2] * pcSrc[i06]
+        + aiFilterCoeff[ 0] * pcSrc[i07];
+      }
+
+      // Process all filtered samples.
+      for(Int j=0; j<(2*iHeight); j++ )
+      {
+        // Scale and copy to image buffer.
+        piDataVerUp[iWidth*j+i] = (piDst[j] + iAddV) / iDivV;
+      }
+    }
+
+    // Update h
+    iHeight *= 2;
+
+    // 2) HORIZONTAL UPSAMPLING.
+
+    // Process all rows.
+    for( Int j=0; j<iHeight; j++ )
+    {
+      // Set source (row) poInter.
+      Int* piSrc = &piDataVerUp[iWidth*j];
+
+      // Process all cols.
+      for( Int i=0; i<iWidth; i++ )
+      {
+        // Adjust indices of border samples.
+        Int i00 = (i <   3) ? 0   : i-3;
+        Int i01 = (i <   2) ? 0   : i-2;
+        Int i02 = (i <   1) ? 0   : i-1;
+        Int i03 = (i < iWidth  ) ? i   : iWidth-1;
+        Int i04 = (i < iWidth-1) ? i+1 : iWidth-1;
+        Int i05 = (i < iWidth-2) ? i+2 : iWidth-1;
+        Int i06 = (i < iWidth-3) ? i+3 : iWidth-1;
+        Int i07 = (i < iWidth-4) ? i+4 : iWidth-1;
+
+        // Calculate filtered (even) sample.
+        piDst[2*i+0] =   aiFilterCoeff[13] * piSrc[i00]
+        + aiFilterCoeff[11] * piSrc[i01]
+        + aiFilterCoeff[ 9] * piSrc[i02]
+        + aiFilterCoeff[ 7] * piSrc[i03]
+        + aiFilterCoeff[ 5] * piSrc[i04]
+        + aiFilterCoeff[ 3] * piSrc[i05]
+        + aiFilterCoeff[ 1] * piSrc[i06];
+
+        // Calculate filtered (odd) sample.
+        piDst[2*i+1] = aiFilterCoeff[14] * piSrc[i00]
+        + aiFilterCoeff[12] * piSrc[i01]
+        + aiFilterCoeff[10] * piSrc[i02]
+        + aiFilterCoeff[ 8] * piSrc[i03]
+        + aiFilterCoeff[ 6] * piSrc[i04]
+        + aiFilterCoeff[ 4] * piSrc[i05]
+        + aiFilterCoeff[ 2] * piSrc[i06]
+        + aiFilterCoeff[ 0] * piSrc[i07];
+      }
+
+      iOffset = 2* iOutputStride * j;
+      // Process all filtered samples.
+      for(Int i=0; i<iWidth*2; i++ )
+      {
+        // Scale and copy to image buffer.
+        pcOutputPlaneData[iOffset+i] = max(min((Pel) ((piDst[i] + iAddH) / iDivH), g_uiBASE_MAX ),0);
+      }
+    }
+
+    delete [] piDataVerUp;
+    delete [] piDst;
+
+  }
+}
+
+
+Void TRenFilter::sampleDown2Tap13(PelImage* pcInputImage, PelImage* pcOutputImage)
+{ // DownSampling from JSVM Software (DownConvertStatic) ??
+
+  UInt uiNumPlanes = pcInputImage->getNumberOfPlanes();
+
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumPlanes; uiCurPlane++)
+  {
+    sampleDown2Tap13( pcInputImage ->getPlane(uiCurPlane),  pcOutputImage->getPlane(uiCurPlane) );
+  }
+};
+
+Void TRenFilter::sampleDown2Tap13( Pel* pcInputPlaneData, Int iInputStride, Int iWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{ // DownSampling from JSVM Software (DownConvertStatic) ??
+  Int iOffset, iPosX, iPosY, k;
+  Int* piDataHorDown = new Int[(Int)(iWidth * iHeight / 2)];
+
+  // Downsampling filter.
+  Int aiFilterCoeff[16] = { 0, 2, 0, -4, -3, 5, 19, 26, 19, 5, -3, -4, 0, 2, 0, 64 };
+
+  // Normalization factors for filtered values.
+  Int iDivH = 1, iDivV = 1, iAddH = 0, iAddV = 0;
+
+  iDivV = (aiFilterCoeff[15]*aiFilterCoeff[15]); iAddV = iDivV / 2;
+
+  // Allocate and init single row of filtered samples.
+  Int* piDst = new Int[iWidth];
+
+  // 1) HORIZONTAL DOWNSAMPLING.
+
+  // Process all rows.
+  for( iPosY=0; iPosY<iHeight; iPosY++ )
+  {
+    // Set source (row) poInter.
+    Pel* pcSrc = &pcInputPlaneData[iInputStride*iPosY];
+
+    // Process all cols.
+    for( iPosX=0, k=0; iPosX<(iWidth/2); iPosX++, k+=2 )
+    {
+      // Adjust indices of border samples.
+      Int i00 = (k <       7) ? 0   : k    -7;
+      Int i01 = (k <       6) ? 0   : k    -6;
+      Int i02 = (k <       5) ? 0   : k    -5;
+      Int i03 = (k <       4) ? 0   : k    -4;
+      Int i04 = (k <       3) ? 0   : k    -3;
+      Int i05 = (k <       2) ? 0   : k    -2;
+      Int i06 = (k <       1) ? 0   : k    -1;
+      Int i07 = (k < iWidth  ) ? k   : iWidth-1;
+      Int i08 = (k < iWidth-1) ? k+1 : iWidth-1;
+      Int i09 = (k < iWidth-2) ? k+2 : iWidth-1;
+      Int i10 = (k < iWidth-3) ? k+3 : iWidth-1;
+      Int i11 = (k < iWidth-4) ? k+4 : iWidth-1;
+      Int i12 = (k < iWidth-5) ? k+5 : iWidth-1;
+      Int i13 = (k < iWidth-6) ? k+6 : iWidth-1;
+      Int i14 = (k < iWidth-7) ? k+7 : iWidth-1;
+
+      // Calculate filtered sample.
+      piDst[iPosX] =     aiFilterCoeff[ 0] * pcSrc[i00]
+      + aiFilterCoeff[ 1] * pcSrc[i01]
+      + aiFilterCoeff[ 2] * pcSrc[i02]
+      + aiFilterCoeff[ 3] * pcSrc[i03]
+      + aiFilterCoeff[ 4] * pcSrc[i04]
+      + aiFilterCoeff[ 5] * pcSrc[i05]
+      + aiFilterCoeff[ 6] * pcSrc[i06]
+      + aiFilterCoeff[ 7] * pcSrc[i07]
+      + aiFilterCoeff[ 8] * pcSrc[i08]
+      + aiFilterCoeff[ 9] * pcSrc[i09]
+      + aiFilterCoeff[10] * pcSrc[i10]
+      + aiFilterCoeff[11] * pcSrc[i11]
+      + aiFilterCoeff[12] * pcSrc[i12]
+      + aiFilterCoeff[13] * pcSrc[i13]
+      + aiFilterCoeff[14] * pcSrc[i14];
+    }
+
+    iOffset = iPosY * iWidth/2;
+    // Process all filtered samples.
+    for( iPosX=0; iPosX<(iWidth/2); iPosX++ )
+    {
+      // Scale and copy back to image buffer.
+      piDataHorDown[iOffset+iPosX] = (piDst[iPosX] + iAddH) / iDivH;
+    }
+  }
+
+  // Update w.
+  iWidth >>= 1;
+
+  // 2) VERTICAL DOWNSAMPLING.
+
+  // Process all cols.
+  for(  iPosX=0; iPosX<iWidth; iPosX++ )
+  {
+    // Set source (col) poInter.
+    Int* piSrc = &piDataHorDown[iPosX];
+
+    // Process all rows.
+    for(  iPosY=0, k=0; iPosY<(iHeight/2); iPosY++, k+=2 )
+    {
+      // Adjust indices of border samples.
+      Int i00 = ((k <       7) ? 0   : k    -7) * iWidth;
+      Int i01 = ((k <       6) ? 0   : k    -6) * iWidth;
+      Int i02 = ((k <       5) ? 0   : k    -5) * iWidth;
+      Int i03 = ((k <       4) ? 0   : k    -4) * iWidth;
+      Int i04 = ((k <       3) ? 0   : k    -3) * iWidth;
+      Int i05 = ((k <       2) ? 0   : k    -2) * iWidth;
+      Int i06 = ((k <       1) ? 0   : k    -1) * iWidth;
+      Int i07 = ((k < iHeight  ) ? k   : iHeight-1) * iWidth;
+      Int i08 = ((k < iHeight-1) ? k+1 : iHeight-1) * iWidth;
+      Int i09 = ((k < iHeight-2) ? k+2 : iHeight-1) * iWidth;
+      Int i10 = ((k < iHeight-3) ? k+3 : iHeight-1) * iWidth;
+      Int i11 = ((k < iHeight-4) ? k+4 : iHeight-1) * iWidth;
+      Int i12 = ((k < iHeight-5) ? k+5 : iHeight-1) * iWidth;
+      Int i13 = ((k < iHeight-6) ? k+6 : iHeight-1) * iWidth;
+      Int i14 = ((k < iHeight-7) ? k+7 : iHeight-1) * iWidth;
+
+      // Calculate filtered sample.
+      piDst[iPosY] =     aiFilterCoeff[ 0] * piSrc[i00]
+      + aiFilterCoeff[ 1] * piSrc[i01]
+      + aiFilterCoeff[ 2] * piSrc[i02]
+      + aiFilterCoeff[ 3] * piSrc[i03]
+      + aiFilterCoeff[ 4] * piSrc[i04]
+      + aiFilterCoeff[ 5] * piSrc[i05]
+      + aiFilterCoeff[ 6] * piSrc[i06]
+      + aiFilterCoeff[ 7] * piSrc[i07]
+      + aiFilterCoeff[ 8] * piSrc[i08]
+      + aiFilterCoeff[ 9] * piSrc[i09]
+      + aiFilterCoeff[10] * piSrc[i10]
+      + aiFilterCoeff[11] * piSrc[i11]
+      + aiFilterCoeff[12] * piSrc[i12]
+      + aiFilterCoeff[13] * piSrc[i13]
+      + aiFilterCoeff[14] * piSrc[i14];
+    }
+
+    // Process all filtered samples.
+    for( iPosY=0; iPosY<(iHeight/2); iPosY++ )
+    {
+      // Scale and copy back to image buffer.
+      pcOutputPlaneData[iOutputStride*iPosY+iPosX] = max(min( ( Pel) ( (piDst[iPosY] + iAddV) / iDivV), g_uiBASE_MAX ),0);
+    }
+  }
+
+  delete [] piDataHorDown;
+  delete [] piDst;
+}
+
+Void TRenFilter::sampleDown2Tap13(PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane)
+{ // DownSampling from JSVM Software (DownConvertStatic) ??
+  Int iWidth       = pcInputPlane->getWidth();
+  Int iHeight      = pcInputPlane->getHeight();
+
+  assert( pcOutputPlane->getWidth () == (iWidth  >> 1 ));
+  assert( pcOutputPlane->getHeight() == (iHeight >> 1 ));
+
+  Int iInputStride  = pcInputPlane->getStride();
+  Int iOutputStride = pcOutputPlane->getStride();
+
+  Pel* pcInputPlaneData = pcInputPlane ->getPlaneData();
+  Pel* pcOutputPlaneData = pcOutputPlane->getPlaneData();
+
+  sampleDown2Tap13( pcInputPlaneData, iInputStride, iWidth, iHeight, pcOutputPlaneData, iOutputStride );
+};
+
+Void TRenFilter::sampleVerDown2Tap13( PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane, Int uiPad)
+{ // DownSampling from JSVM Software (DownConvertStatic) ??
+  Int iWidth       = pcInputPlane->getWidth();
+  Int iHeight      = pcInputPlane->getHeight();
+
+  assert( pcOutputPlane->getWidth () ==  iWidth       );
+  assert( pcOutputPlane->getHeight() == (iHeight >> 1));
+  assert (pcInputPlane ->getPad()    >=            12 );
+  assert (pcOutputPlane->getPad()    >=         uiPad );
+
+  Int iInputStride  = pcInputPlane->getStride();
+  Int iOutputStride = pcOutputPlane->getStride();
+
+  Pel* pcInputPlaneData  = pcInputPlane ->getPlaneData();
+  Pel* pcOutputPlaneData = pcOutputPlane->getPlaneData();
+
+  Int iStr0  = 0;
+  Int iStr1  = iInputStride;
+  Int iStr2  = iStr1  + iInputStride;
+  Int iStr3  = iStr2  + iInputStride;
+  Int iStr4  = iStr3  + iInputStride;
+  Int iStr5  = iStr4  + iInputStride;
+  Int iStr6  = iStr5  + iInputStride;
+  Int iStr7  = iStr6  + iInputStride;
+  Int iStr8  = iStr7  + iInputStride;
+  Int iStr9  = iStr8  + iInputStride;
+  Int iStr10 = iStr9  + iInputStride;
+  Int iStr11 = iStr10 + iInputStride;
+  Int iStr12 = iStr11 + iInputStride;;
+
+
+  // Downsampling filter { 0, 2, 0, -4, -3, 5, 19, 26, 19, 5, -3, -4, 0, 2, 0, 64 };
+  for ( Int iYPos = 0; iYPos < (iHeight >> 1); iYPos++)
+  {
+    Pel* pcTmpIn = pcInputPlaneData - 12 * iInputStride - uiPad;
+    for ( Int iXPos = -uiPad; iXPos < iWidth + uiPad; iXPos++)
+    {
+      Int iTmp0, iTmp1, iTmp2, iTmp3, iTmp4, iTmp5;
+      iTmp0 = pcTmpIn[iStr0] + pcTmpIn[iStr12];
+      iTmp1 = pcTmpIn[iStr2] + pcTmpIn[iStr10];
+      iTmp2 = pcTmpIn[iStr3] + pcTmpIn[iStr9 ];
+      iTmp3 = pcTmpIn[iStr4] + pcTmpIn[iStr8 ];
+      iTmp4 = pcTmpIn[iStr5] + pcTmpIn[iStr7 ];
+      iTmp5 = pcTmpIn[iStr6];
+
+      Int iSum = iTmp4 + iTmp3 - iTmp2 + ((iTmp0 + iTmp4 + iTmp5 - iTmp2) << 1) + ( ( iTmp3 - iTmp1)  << 2) + (  iTmp5 << 3 ) + (( iTmp4 + iTmp5 ) << 4);
+      pcOutputPlaneData[ iXPos ] = (Pel) Clip((iSum + 32) >> 6);
+      pcTmpIn++;
+    }
+    pcOutputPlaneData += iOutputStride;
+    pcInputPlaneData  += (iInputStride << 1);
+  }
+};
+
+Void TRenFilter::sampleHorDown2Tap13( PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane, Int uiPad )
+{ // DownSampling from JSVM Software (DownConvertStatic) ??
+  Int iWidth       = pcInputPlane->getWidth();
+  Int iHeight      = pcInputPlane->getHeight();
+
+  assert( pcOutputPlane->getWidth () == (iWidth  >> 1));
+  assert( pcOutputPlane->getHeight() ==  iHeight      );
+  assert (pcInputPlane ->getPad()    >=            12 );
+  assert (pcOutputPlane->getPad()    >=         uiPad );
+
+  Int iInputStride  = pcInputPlane ->getStride();
+  Int iOutputStride = pcOutputPlane->getStride();
+
+  Pel* pcInputPlaneData  = pcInputPlane ->getPlaneData()- uiPad * iInputStride ;
+  Pel* pcOutputPlaneData = pcOutputPlane->getPlaneData()- uiPad * iOutputStride;
+
+  // Downsampling filter { 0, 2, 0, -4, -3, 5, 19, 26, 19, 5, -3, -4, 0, 2, 0, 64 };
+  for ( Int iYPos = 0; iYPos < iHeight + 2*uiPad; iYPos++)
+  {
+    Pel* pcTmpIn = pcInputPlaneData - 12;
+    for ( Int iXPos = 0; iXPos < ( iWidth >> 1); iXPos++)
+    {
+      Int iTmp0, iTmp1, iTmp2, iTmp3, iTmp4, iTmp5;
+      iTmp0 = pcTmpIn[0]+ pcTmpIn[12];
+      iTmp1 = pcTmpIn[2]+ pcTmpIn[10];
+      iTmp2 = pcTmpIn[3]+ pcTmpIn[9 ];
+      iTmp3 = pcTmpIn[4]+ pcTmpIn[8 ];
+      iTmp4 = pcTmpIn[5]+ pcTmpIn[7 ];
+      iTmp5 = pcTmpIn[6];
+
+      Int iSum = iTmp4 + iTmp3 - iTmp2 + ((iTmp0 + iTmp4 + iTmp5 - iTmp2) << 1) + ( ( iTmp3 - iTmp1)  << 2) + (  iTmp5 << 3 ) + (( iTmp4 + iTmp5 ) << 4);
+      pcOutputPlaneData[ iXPos ] = (Pel) Clip((iSum + 32) >> 6);
+      pcTmpIn += 2;
+    }
+    pcOutputPlaneData += iOutputStride;
+    pcInputPlaneData  += iInputStride ;
+  }
+};
+
+inline Pel TRenFilter::xMedian3(Pel* pcData)
+{
+  Bool bGT01 = pcData[0] >  pcData[1];
+  Bool bGT12 = pcData[1] >  pcData[2];
+  Bool bGT20 = pcData[2] >  pcData[0];
+
+  return ( (bGT01 && bGT20) || (!bGT01 && !bGT20) ) ?  pcData[0] : ( ( (bGT12 && bGT01) || (!bGT12 && !bGT01) ) ?  pcData[1] : pcData[2]) ;
+}
+
+
+Void TRenFilter::lineMedian3( PelImage* pcImage )
+{
+
+  PelImage* pcTemp = pcImage->create();
+
+  for (UInt uiCurPlane = 0; uiCurPlane < pcImage->getNumberOfPlanes(); uiCurPlane++)
+  {
+    PelImagePlane* pcImPlane   = pcImage->getPlane(uiCurPlane);
+    PelImagePlane* pcTempPlane = pcTemp ->getPlane(uiCurPlane);
+
+    UInt uiWidth  = pcImPlane->getWidth();
+    UInt uiHeight = pcImPlane->getHeight();
+
+    Pel* pcImData   = pcImPlane  ->getPlaneData();
+    Pel* pcTempData = pcTempPlane->getPlaneData();
+
+    UInt uiImDataStride   = pcImPlane  ->getStride();
+    UInt uiTempDataStride = pcTempPlane->getStride();
+
+    for(UInt uiPosY = 0; uiPosY < uiHeight; uiPosY++)
+    {
+      for(UInt uiPosX = 0; uiPosX < uiWidth; uiPosX++)
+      {
+        if ( (uiPosX >= 1) && (uiPosX < (uiWidth - 2)) )
+        {
+          pcTempData[uiPosX] = xMedian3(pcImData + uiPosX - 1);
+        }
+        else
+        {
+          pcTempData[uiPosX] = pcImData[uiPosX];
+        }
+      }
+      pcTempData += uiTempDataStride;
+      pcImData   += uiImDataStride;
+    }
+  }
+
+  pcImage->assign(pcTemp);
+  delete pcTemp;
+}
+
+
+Void TRenFilter::convRect( PelImage* pcImage, UInt uiSize )
+{
+  DoubleImage cKernel(uiSize, uiSize,1,0);
+  cKernel.getPlane(0)->assign( 1 / ( Double( uiSize )  * Double( uiSize) ));
+  conv(pcImage, &cKernel);
+}
+
+Void TRenFilter::binominal( PelImage* pcInputImage, PelImage* pcOutputImage, UInt uiSize )
+{
+  assert( pcInputImage->getNumberOfFullPlanes()   == pcOutputImage->getNumberOfFullPlanes  () );
+  assert( pcInputImage->getNumberOfQuaterPlanes() == pcOutputImage->getNumberOfQuaterPlanes() );
+
+  UInt uiPlane;
+  for (uiPlane = 0; uiPlane < pcInputImage->getNumberOfFullPlanes(); uiPlane ++)
+  {
+    binominal( pcInputImage->getPlane(uiPlane), pcOutputImage->getPlane(uiPlane), uiSize );
+  }
+
+  for (  ; uiPlane < pcInputImage->getNumberOfPlanes(); uiPlane ++)
+  {
+    binominal( pcInputImage->getPlane(uiPlane), pcOutputImage->getPlane(uiPlane), uiSize >> 1 );
+ }
+}
+
+Void TRenFilter::binominal( PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane, UInt uiSize )
+{
+  Int iWidth  = pcInputPlane ->getWidth ();
+  Int iHeight = pcInputPlane ->getHeight();
+
+  assert( pcOutputPlane->getWidth () == iWidth  );
+  assert( pcOutputPlane->getHeight() == iHeight );
+  assert( pcInputPlane ->getPad   () >= uiSize );
+  assert( pcOutputPlane->getPad   () >= uiSize );
+
+  if (uiSize == 0)
+  {
+    pcOutputPlane->assign( pcInputPlane );
+    return;
+  };
+
+  Int iInputStride  = pcInputPlane ->getStride();
+  Int iOutputStride = pcOutputPlane->getStride();
+  Int iTempStride   = iWidth + (uiSize << 1);
+
+
+  Pel* pcCurInputData  = pcInputPlane ->getPlaneData() - uiSize;
+  Pel* pcTempData      = new Pel[iTempStride * iHeight];
+  Pel* pcCurTempData   = pcTempData;
+
+  Pel (*fpFilter) ( Pel*, Int ) = NULL;
+
+  switch( uiSize )
+  {
+  case 1:
+    fpFilter = &TRenFilter::xFiltBinom3;
+    break;
+  case 2:
+    fpFilter = &TRenFilter::xFiltBinom5;
+    break;
+  case 3:
+    fpFilter = &TRenFilter::xFiltBinom7;
+    break;
+  case 4:
+    fpFilter = &TRenFilter::xFiltBinom9;
+    break;
+  default:
+      AOT(true);
+  }
+
+  for (Int iPosY = 0; iPosY < iHeight; iPosY++ )
+  {
+    for (Int iPosX = 0; iPosX < iWidth + (uiSize << 1); iPosX++)
+    {
+      pcCurTempData[iPosX] = (*fpFilter)(pcCurInputData + iPosX, iInputStride );
+    }
+    pcCurTempData   += iTempStride;
+    pcCurInputData  += iInputStride;
+  }
+
+  pcCurTempData   = pcTempData + uiSize;
+  Pel* pcCurOutputData = pcOutputPlane->getPlaneData();
+
+  for (Int iPosY = 0; iPosY < iHeight; iPosY++ )
+  {
+    for (Int iPosX = 0; iPosX < iWidth; iPosX++)
+    {
+      pcCurOutputData[iPosX] = (*fpFilter)(pcCurTempData + iPosX, 1);
+    }
+    pcCurTempData    += iTempStride;
+    pcCurOutputData  += iOutputStride;
+  }
+
+  delete[] pcTempData;
+}
+
+Pel TRenFilter::xFiltBinom3( Pel* pcInputData, Int iStride )
+{
+  Int iSum = pcInputData[-1 * iStride ] + pcInputData[ 0 ] +  (pcInputData[iStride ] << 1 );
+  return Clip( (iSum +  2) >>  2 );
+}
+
+Pel TRenFilter::xFiltBinom5( Pel* pcInputData, Int iStride )
+{
+  // { 1,4,6,4,1 }
+  Int iStride0  = 0;
+  Int iStrideM1 = iStride0  - iStride;
+  Int iStrideM2 = iStrideM1 - iStride;
+  Int iStrideP1 = iStride0  + iStride;
+  Int iStrideP2 = iStrideP1 + iStride;
+
+  Int iTmp0 = pcInputData[iStrideM2] + pcInputData[iStrideP2];
+  Int iTmp1 = pcInputData[iStrideM1] + pcInputData[iStrideP1];
+  Int iTmp2 = pcInputData[iStride0 ];
+
+  Int iSum = iTmp0 +  (iTmp2 << 1) + ((iTmp1 + iTmp2) << 2);
+  return Clip( (iSum +  8) >>  4 );
+}
+
+Pel TRenFilter::xFiltBinom7( Pel* pcInputData, Int iStride )
+{
+  // { 1,6,15,20,15,6,1 }
+  Int iStride0  = 0;
+  Int iStrideM1 = iStride0  - iStride;
+  Int iStrideM2 = iStrideM1 - iStride;
+  Int iStrideM3 = iStrideM1 - iStride;
+  Int iStrideP1 = iStride0  + iStride;
+  Int iStrideP2 = iStrideP1 + iStride;
+  Int iStrideP3 = iStrideP1 + iStride;
+
+  Int iTmp0 = pcInputData[iStrideM3] + pcInputData[iStrideP3];
+  Int iTmp1 = pcInputData[iStrideM2] + pcInputData[iStrideP2];
+  Int iTmp2 = pcInputData[iStrideM1] + pcInputData[iStrideP1];
+  Int iTmp3 = pcInputData[iStride0];
+
+  Int iSum = iTmp0 - iTmp2 + ( iTmp1  << 1) + ( (iTmp1 + iTmp3) << 2) + ((iTmp2 + iTmp3) << 4);
+
+  return Clip( (iSum +  32) >>  6 );
+}
+
+Pel TRenFilter::xFiltBinom9( Pel* pcInputData, Int iStride )
+{
+  // {  1     8    28    56    70    56    28     8     1 }
+  Int iStride0  = 0;
+  Int iStrideM1 = iStride0  - iStride;
+  Int iStrideM2 = iStrideM1 - iStride;
+  Int iStrideM3 = iStrideM1 - iStride;
+  Int iStrideM4 = iStrideM1 - iStride;
+  Int iStrideP1 = iStride0  + iStride;
+  Int iStrideP2 = iStrideP1 + iStride;
+  Int iStrideP3 = iStrideP1 + iStride;
+  Int iStrideP4 = iStrideP1 + iStride;
+
+  Int iTmp0 = pcInputData[iStrideM4] + pcInputData[iStrideP4];
+  Int iTmp1 = pcInputData[iStrideM3] + pcInputData[iStrideP3];
+  Int iTmp2 = pcInputData[iStrideM2] + pcInputData[iStrideP2];
+  Int iTmp3 = pcInputData[iStrideM1] + pcInputData[iStrideP1];
+  Int iTmp4 = pcInputData[iStride0];
+
+  Int iSum = iTmp0 + ((iTmp4 ) << 1) + ( ( iTmp4 - iTmp2 ) << 2) +  ( (iTmp1 - iTmp3) << 3 ) +  ((iTmp2 ) << 5) + ((iTmp3+ iTmp4 ) << 6);
+
+  return Clip( (iSum +  128) >>  8 );
+}
+
+
+Pel TRenFilter::interpCHSpline(Double dX, Double dS0, Double dS1, Int iQ0, Int iQ1, Int iQ2, Int iQ3)
+{
+  Double dSq = (dX - dS0) / (dS1 - dS0);
+
+  Double adP[4];
+  Double dSqP2 = dSq * dSq;
+  Double dSqP3 = dSqP2 * dSq;
+
+  adP[0] = 1 - 3 * dSqP2 + 2 * dSqP3;
+  adP[1] = dSq - 2 * dSqP2 + dSqP3;
+  adP[2] = 3 * dSqP2 - 2 * dSqP3;
+  adP[3] = -dSqP2 + dSqP3;
+
+  Double dQ  = adP[0] * iQ0 + adP[1] * iQ1 + adP[2] * iQ2 + adP[3] * iQ3 ;
+
+  Pel cQ = (Pel) ( dQ + 0.5);
+
+  cQ = ( cQ < 0   ? 0   : cQ );
+  cQ = ( cQ > 255 ? 255 : cQ );
+
+  return cQ;
+
+}
+
+Void TRenFilter::diffHorSym(PelImage* pcInputImage, IntImage* pcOutputImage)
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < pcInputImage->getNumberOfPlanes(); uiCurPlane++)
+  {
+    diffHorSym( pcInputImage->getPlane(uiCurPlane), pcOutputImage->getPlane(uiCurPlane));
+  };
+}
+
+Void TRenFilter::diffHorSym(PelImagePlane* pcInputPlane, IntImagePlane* pcOutputPlane)
+{
+  UInt uiInputStride  = pcInputPlane ->getStride();
+  UInt uiOutputStride = pcOutputPlane->getStride();
+  UInt uiWidth        = pcInputPlane ->getWidth();
+  UInt uiHeight       = pcInputPlane ->getHeight();
+
+  Pel*   pcInputData  = pcInputPlane ->getPlaneData();
+  Int*   piOutputData = pcOutputPlane->getPlaneData();
+
+  for (UInt uiPosY = 0; uiPosY < uiHeight; uiPosY++)
+  {
+    for (UInt uiPosX = 1; uiPosX < uiWidth-1; uiPosX++)
+    {
+      piOutputData[uiPosX] = ((Int) pcInputData[uiPosX+1] - (Int) pcInputData[uiPosX-1]);
+      piOutputData[uiPosX] /= 2;
+    };
+
+    piOutputData[0]         = piOutputData[1];
+    piOutputData[uiWidth-1] = piOutputData[uiWidth-2];
+    pcInputData            += uiInputStride;
+    piOutputData           += uiOutputStride;
+  };
+}
+
+Void TRenFilter::laplace( DoubleImage* pcInputImage, DoubleImage* pcOutputImage )
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < pcInputImage->getNumberOfPlanes(); uiCurPlane++)
+  {
+    DoubleImagePlane* pcInputPlane  = pcInputImage  ->getPlane(uiCurPlane);
+    DoubleImagePlane* pcOutputPlane = pcOutputImage ->getPlane(uiCurPlane);
+
+    UInt uiWidth  = pcInputPlane->getWidth();
+    UInt uiHeight = pcInputPlane->getHeight();
+
+    Double* pdInputData  = pcInputPlane  ->getPlaneData();
+    Double* pdOutputData = pcOutputPlane ->getPlaneData();
+
+    for (UInt uiPosY = 1; uiPosY < uiHeight-1; uiPosY++)
+    {
+      UInt uOff = uiPosY * uiWidth;
+      for(UInt uiPosX = 1; uiPosX < uiWidth-1; uiPosX++)
+      {
+        UInt uOff2 = uOff + uiPosX;
+        pdOutputData[uOff2] =     4 * pdInputData[uOff2]
+        -   pdInputData[uOff2 - 1]
+        -   pdInputData[uOff2 + 1]
+        -   pdInputData[uOff2 - uiWidth]
+        -   pdInputData[uOff2 + uiWidth];
+      }
+    };
+
+    // left and right margin
+    for (UInt uiPosY = 1; uiPosY < uiHeight-1; uiPosY++)
+    {
+      UInt uOff  = uiPosY * uiWidth;
+      pdOutputData[uOff] = 3 * pdInputData[uOff]
+      -   pdInputData[uOff + 1]
+      -   pdInputData[uOff - uiWidth]
+      -   pdInputData[uOff + uiWidth];
+
+
+      uOff = (uiPosY + 1) * uiWidth - 1;
+      pdOutputData[uOff] = 3 * pdInputData[uOff]
+      -   pdInputData[uOff - 1]
+      -   pdInputData[uOff - uiWidth]
+      -   pdInputData[uOff + uiWidth];
+    }
+
+    for (UInt uiPosX = 1; uiPosX < uiWidth-1; uiPosX++)
+    {
+      UInt uOff  = uiPosX;
+      pdOutputData[uOff] = 3 * pdInputData[uOff]
+      -   pdInputData[uOff + 1]
+      -   pdInputData[uOff - 1]
+      -   pdInputData[uOff + uiWidth];
+
+
+      uOff = (uiHeight - 1) * uiWidth + uiPosX;
+      pdOutputData[uOff] = 3 * pdInputData[uOff]
+      -   pdInputData[uOff + 1]
+      -   pdInputData[uOff - 1]
+      -   pdInputData[uOff - uiWidth];
+    }
+
+    UInt uOff = 0;
+    pdOutputData[uOff] = 2 * pdInputData[uOff] - pdInputData[uOff+1] - pdInputData[ uOff + uiWidth];
+    uOff = uiWidth - 1;
+    pdOutputData[uOff] = 2 * pdInputData[uOff] - pdInputData[uOff-1] - pdInputData[ uOff + uiWidth ];
+    uOff = (uiHeight - 1) * uiWidth;
+    pdOutputData[uOff] = 2 * pdInputData[uOff] - pdInputData[uOff+1] - pdInputData[ uOff - uiWidth];
+    uOff = uiHeight * uiWidth - 1;
+    pdOutputData[uOff] = 2 * pdInputData[uOff] - pdInputData[uOff-1] - pdInputData[ uOff - uiWidth];
+
+  }
+}
+
+
+Void TRenFilter::conv( PelImage* pcImage, DoubleImage* pcKernel )
+{
+  PelImage* pcTemp = pcImage->create();
+
+  DoubleImagePlane* pcKernelPlane = 0;
+  for (UInt uiCurPlane = 0; uiCurPlane < pcImage->getNumberOfPlanes(); uiCurPlane++) {
+
+    PelImagePlane* pcPlane     = pcImage->getPlane(uiCurPlane);
+    PelImagePlane* pcTempPlane = pcTemp ->getPlane(uiCurPlane);
+
+    if ( uiCurPlane <= pcKernel->getNumberOfPlanes() )
+    {
+      pcKernelPlane = pcKernel->getPlane(uiCurPlane);
+    };
+
+    UInt uiWidth  = pcPlane->getWidth();
+    UInt uiHeight = pcPlane->getHeight();
+
+    UInt uiKernelWidth  = pcKernelPlane->getWidth();
+    UInt uiKernelHeight = pcKernelPlane->getHeight();
+
+    Pel*    pcData         = pcPlane      ->getPlaneData();
+    Pel*    pcTempData     = pcTempPlane  ->getPlaneData();
+    Double* pdKernelData   = pcKernelPlane->getPlaneData();
+
+    UInt uiDataStride       = pcPlane      ->getStride();
+    UInt uiTempDataStride   = pcTempPlane  ->getStride();
+    UInt uiKernelDataStride = pcKernelPlane->getStride();
+
+    for(UInt uiPosY = 0; uiPosY < uiHeight; uiPosY++)
+    {
+      UInt uOff = uiPosY * uiTempDataStride;
+      for(UInt uiPosX = 0; uiPosX < uiWidth; uiPosX++)
+      {
+        Double dSum = 0;
+        for(UInt uKY = 0; uKY < uiKernelHeight; uKY++)
+        {
+          UInt uKOff = uKY * uiKernelDataStride;
+
+          Int iYSrc = uiPosY - (uiKernelHeight/2) + uKY;
+
+          if (iYSrc < 0)
+            iYSrc = -iYSrc;
+
+          if (iYSrc >= (Int)uiHeight)
+            iYSrc = 2*uiHeight - iYSrc - 1;
+
+          UInt uSrcOff = iYSrc * uiDataStride;
+
+          for(UInt uKX = 0; uKX < uiKernelWidth; uKX++)
+          {
+            Int iXSrc = uiPosX - (uiKernelWidth/2) + uKX;
+
+            if (iXSrc < 0)
+              iXSrc = -iXSrc;
+
+            if (iXSrc >= (Int)uiWidth)
+              iXSrc = 2*uiWidth - iXSrc - 1;
+
+            dSum += pcData[uSrcOff + iXSrc] * pdKernelData[uKOff + uKX];
+          }
+        }
+        pcTempData[uOff + uiPosX] = (Pel) (dSum + ( ( dSum < 0 ) ? -0.5 : 0.5)  );
+      }
+    }
+  }
+
+  pcImage->assign(pcTemp);
+  delete pcTemp;
+}
+
+
+// Horizontal Up sampling luma
+Void TRenFilter::sampleHorUp( Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  TRenInterpFilter cFilter;
+  switch ( iLog2HorSampFac )
+  {
+  case 0:
+    xDistributeArray              ( pcInputPlaneData, iInputStride, 1 , 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 1, 1 );
+    break;
+  case 1:
+    xDistributeArray              ( pcInputPlaneData, iInputStride, 1 , 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 2, 1 );
+    cFilter.xCTI_FilterHalfHor    ( pcInputPlaneData, iInputStride,     1, iInputWidth, iHeight, iOutputStride, 2, ++pcOutputPlaneData );
+    break;
+  case 2:
+    xDistributeArray              ( pcInputPlaneData, iInputStride, 1 , 1, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride, 4, 1 );
+    cFilter.xCTI_FilterQuarter0Hor( pcInputPlaneData, iInputStride, 1, iInputWidth, iHeight, iOutputStride, 4, ++pcOutputPlaneData );
+    cFilter.xCTI_FilterHalfHor    ( pcInputPlaneData, iInputStride, 1, iInputWidth, iHeight, iOutputStride, 4, ++pcOutputPlaneData );
+    cFilter.xCTI_FilterQuarter1Hor( pcInputPlaneData, iInputStride, 1, iInputWidth, iHeight, iOutputStride, 4, ++pcOutputPlaneData );
+    break;
+  }
+}
+
+// horizontal up sampling chroma
+Void TRenFilter::sampleCHorUp(Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  switch ( iLog2HorSampFac )
+  {
+  case 0:
+    xDistributeArray( pcInputPlaneData,   iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                  , iOutputStride, 1 , 1 );
+    break;
+  case 1:
+    xDistributeArray( pcInputPlaneData,   iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                  , iOutputStride, 2 , 1 );
+    xInterpHorChroma( pcInputPlaneData  , iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                +1, iOutputStride, 2 , 1, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    break;
+  case 2:
+    xDistributeArray( pcInputPlaneData,   iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                  , iOutputStride, 4 , 1 );
+    xInterpHorChroma( pcInputPlaneData  , iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                +1, iOutputStride, 4 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA0 );
+    xInterpHorChroma( pcInputPlaneData  , iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                +2, iOutputStride, 4 , 1, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    xInterpHorChroma( pcInputPlaneData  , iInputStride  , 1, 1, iInputWidth,   iHeight   , pcOutputPlaneData                +3, iOutputStride, 4 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA1 );
+    break;
+  }
+}
+
+Void TRenFilter::sampleCUpHorUp( Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+
+  switch ( iLog2HorSampFac )
+  {
+  case 0:
+    xDistributeArray( pcInputPlaneData-1, iInputStride  , 1, 1, iInputWidth+3, iHeight   , pcOutputPlaneData                -2, iOutputStride, 2,  2 );
+    xInterpVerChroma( pcInputPlaneData-1, iInputStride  , 1, 1, iInputWidth+3, iHeight   , pcOutputPlaneData+1*iOutputStride-2, iOutputStride, 2 , 2, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 2, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData+1                , iOutputStride, 2 , 1, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    break;
+  case 1:
+    xDistributeArray( pcInputPlaneData-1, iInputStride  , 1, 1, iInputWidth+3, iHeight   , pcOutputPlaneData                -4, iOutputStride, 4 , 2 );
+    xInterpVerChroma( pcInputPlaneData-1, iInputStride  , 1, 1, iInputWidth+3, iHeight   , pcOutputPlaneData+1*iOutputStride-4, iOutputStride, 4 , 2, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 4, 1, iInputWidth, iHeight*2 , pcOutputPlaneData                +1, iOutputStride, 4 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA0 );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 4, 1, iInputWidth, iHeight*2 , pcOutputPlaneData                +2, iOutputStride, 4 , 1, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 4, 1, iInputWidth, iHeight*2 , pcOutputPlaneData                +3, iOutputStride, 4 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA1 );
+    break;
+  case 2:
+    xDistributeArray( pcInputPlaneData-1, iInputStride  , 1, 1, iInputWidth+3, iHeight   , pcOutputPlaneData                -8, iOutputStride, 8 , 2 );
+    xInterpVerChroma( pcInputPlaneData-1, iInputStride  , 1, 1, iInputWidth+3, iHeight   , pcOutputPlaneData+1*iOutputStride-8, iOutputStride, 8 , 2, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +1, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT0 );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +2, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA0 );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +3, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT1 );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +4, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VPS04_C_HAL );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +5, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT2 );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +6, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_QUA1 );
+    xInterpHorChroma( pcOutputPlaneData , iOutputStride , 8, 1, iInputWidth,   iHeight*2 , pcOutputPlaneData                +7, iOutputStride, 8 , 1, &TRenInterpFilter::xCTI_Filter_VP04_C_OCT3 );
+    break;
+  }
+}
+
+// Down Sampling
+// Down sample luma
+Void TRenFilter::sampleHorDown(Int iLog2HorSampFac,  Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  switch ( iLog2HorSampFac )
+  {
+  case 0:
+    xDistributeArray( pcInputPlaneData, iInputStride, 1, 1, iInputWidth,iHeight, pcOutputPlaneData, iOutputStride, 1 , 1 );
+    break;
+  case 1:
+    xSampleDownHor2(pcInputPlaneData, iInputStride, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride);
+    break;
+  case 2:
+    xSampleDownHor4(pcInputPlaneData, iInputStride, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride);
+    break;
+  }
+}
+
+
+Void TRenFilter::sampleCHorDown(Int iLog2HorSampFac,  Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  //GT: currently the same as for luma
+  sampleHorDown( iLog2HorSampFac, pcInputPlaneData, iInputStride, iInputWidth, iHeight, pcOutputPlaneData, iOutputStride);
+}
+
+
+
+// Up sampling chroma
+Void TRenFilter::sampleCDownHorDown( Int iLog2HorSampFac,  Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iInputHeight, Pel* pcOutputPlaneData, Int iOutputStride  )
+{
+  // create buffer
+  Int iBufferStride   = iInputWidth >> (iLog2HorSampFac + 1);
+  Pel* piBuffer       = new Pel[ iBufferStride * (iInputHeight+2) ];
+
+  switch ( iLog2HorSampFac )
+  {
+  case 0:
+    xSampleDownHor2( pcInputPlaneData - iInputStride,  iInputStride, iInputWidth  , iInputHeight+1, piBuffer,  iBufferStride);
+    break;
+  case 1:
+    xSampleDownHor4( pcInputPlaneData - iInputStride , iInputStride,  iInputWidth , iInputHeight+1, piBuffer, iBufferStride);
+    break;
+  case 2:
+    xSampleDownHor8( pcInputPlaneData - iInputStride , iInputStride,  iInputWidth  , iInputHeight+1, piBuffer, iBufferStride);
+    break;
+  }
+  xSampleDownVer2( piBuffer + iBufferStride       , iBufferStride, iBufferStride, iInputHeight,   pcOutputPlaneData, iOutputStride);
+  delete[] piBuffer;
+}
+
+Void TRenFilter::xDistributeArray(Pel* pcSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* pcDst, Int iDstStride, Int iDstStepX, Int iDstStepY)
+{
+  iDstStride *= iDstStepY;
+  iSrcStride *= iSrcStepY;
+  for (Int iYPos = 0; iYPos < iHeight; iYPos++ )
+  {
+    Pel* pcCurDst = pcDst;
+    Pel* pcCurSrc  = pcSrc;
+    for (Int iXPos = 0; iXPos < iWidth; iXPos ++)
+    {
+      *pcCurDst = *pcCurSrc;
+
+      pcCurDst += iDstStepX;
+      pcCurSrc += iSrcStepX;
+    }
+    pcDst  += iDstStride;
+    pcSrc  += iSrcStride;
+  }
+}
+
+Void TRenFilter::xInterpHorChroma( Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, FpChromaIntFilt fpFilter )
+{
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  TRenInterpFilter cFilter;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = piSrc - iSrcStepX;
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      iSum      = (cFilter.*fpFilter)( piSrcTmp,  iSrcStepX );
+      piDst[x * iDstStepX ] =  Clip ((iSum +  32) >>  6 );
+      piSrcTmp+= iSrcStepX;
+    }
+    piSrc += iSrcStride * iSrcStepY;
+    piDst += iDstStride * iDstStepY;
+  }
+}
+
+Void TRenFilter::xInterpVerChroma( Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, FpChromaIntFilt fpFilter )
+{
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  TRenInterpFilter cFilter;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = piSrc - iSrcStepY * iSrcStride;
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      iSum      = (cFilter.*fpFilter)( piSrcTmp,  iSrcStepY * iSrcStride );
+      piDst[x * iDstStepX ]  =  Clip ((iSum +  32) >>  6 );
+      piSrcTmp += iSrcStepX;
+    }
+    piSrc += iSrcStride * iSrcStepY;
+    piDst += iDstStride * iDstStepY;
+  }
+}
+
+
+Void TRenFilter::xSampleDownHor2( Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iHeight, Pel* piDst, Int iDstStride  )
+{
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = piSrc - 1 ;
+    for ( Int x = 0; x < (iSrcWidth >> 1); x++ )
+    {
+      // { 1,2,1 }
+      iSum = piSrcTmp[0] + piSrcTmp[2] +  (piSrcTmp[1] << 1);
+      piDst[x] = Clip( (iSum +  2) >>  2 );
+      piSrcTmp += 2;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+};
+
+Void TRenFilter::xSampleDownVer2( Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iSrcHeight, Pel* piDst, Int iDstStride  )
+{
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  for ( Int y = (iSrcHeight >> 1); y != 0; y-- )
+  {
+    piSrcTmp = piSrc -1 * iSrcStride;
+    for ( Int x = 0; x < iSrcWidth; x++ )
+    {
+      // { 1,2,1 }
+      iSum = piSrcTmp[0] + piSrcTmp[ iSrcStride << 1] +  (piSrcTmp[ iSrcStride ] << 1);
+      piDst[x] = Clip( (iSum +  2) >>  2 );
+      piSrcTmp += 1;
+    }
+    piSrc += (iSrcStride << 1);
+    piDst += iDstStride;
+  }
+};
+
+Void TRenFilter::xSampleDownHor4( Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iHeight, Pel* piDst, Int iDstStride  )
+{
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  Int iTmp0, iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = piSrc -2 ;
+    for ( Int x = 0; x < (iSrcWidth >> 2); x++ )
+    {
+      // { 1,4,6,4,1 }
+      iTmp0 = piSrcTmp[0] + piSrcTmp[4];
+      iTmp1 = piSrcTmp[1] + piSrcTmp[3];
+      iTmp2 = piSrcTmp[2];
+
+      iSum = iTmp0 +  (iTmp2 << 1) + ((iTmp1 + iTmp2) << 2);
+      piDst[x] = Clip( (iSum +  8) >>  4 );
+      piSrcTmp += 4;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+};
+
+Void TRenFilter::xSampleDownHor8( Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iHeight, Pel* piDst, Int iDstStride  )
+{
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  Int iTmp0, iTmp1, iTmp2, iTmp3;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = piSrc -3;
+    for ( Int x = 0; x < (iSrcWidth >> 3); x++ )
+    {
+      // { 1,6,15,20,15,6,1 }
+      iTmp0 = piSrcTmp[0] + piSrcTmp[6];
+      iTmp1 = piSrcTmp[1] + piSrcTmp[5];
+      iTmp2 = piSrcTmp[2] + piSrcTmp[4];
+      iTmp3 = piSrcTmp[3];
+
+      iSum = iTmp0 - iTmp2 + ( iTmp1  << 1) + ( (iTmp1 + iTmp3) << 2) + ((iTmp2 + iTmp3) << 4);
+      piDst[x] = Clip( (iSum +  32) >>  6 );
+      piSrcTmp += 8;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+};
+
+Void TRenFilter::xDilate( Pel* piSrc, Int iSrcStride, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iSize, Bool bVerticalDir, Bool bToTopOrLeft )
+{
+  Int iFDimStart   = 0;
+  Int iInc         = 1;
+  Int iSDimStart   = 0;
+
+  Int iFDimSrcStrd = bVerticalDir ? 1          : iSrcStride;
+  Int iFDimDstStrd = bVerticalDir ? 1          : iDstStride;
+
+  Int iSDimSrcStrd = bVerticalDir ? iSrcStride : 1;
+  Int iSDimDstStrd = bVerticalDir ? iDstStride : 1;
+
+  Int iFDimEnd     = bVerticalDir ? iWidth -1  : iHeight - 1;
+  Int iSDimEnd     = bVerticalDir ? iHeight-1  : iWidth  - 1;
+
+  if ( bToTopOrLeft )
+  {
+    iSDimStart    = iSDimEnd;
+    iSDimEnd      = 0;
+    iInc         *= -1;
+  }
+
+  for (Int iPosFDim = iFDimStart; iPosFDim <= iFDimEnd; iPosFDim++ )
+  {
+    Int  iCount      = 0;
+    Bool bLastWasOne = false;
+    Bool bDilate     = false;
+    Int  iPosSDim    = iSDimStart;
+    Bool bContinue   = true;
+
+    while ( bContinue )
+    {
+      if ( iCount == iSize )
+      {
+        iCount  = 0;
+        bDilate = false;
+      }
+
+      Pel iVal = piSrc[iPosSDim*iSDimSrcStrd];
+      if( iVal == 0 && bLastWasOne )
+      {
+        iCount  = 0;
+        bDilate = true;
+      }
+
+      if( bDilate )
+      {
+        piDst[iPosSDim*iSDimDstStrd] = REN_USED_PEL;
+        iCount++;
+      }
+      else
+      {
+        piDst[iPosSDim*iSDimDstStrd] = iVal;
+      }
+
+
+      bLastWasOne = (iVal == REN_USED_PEL);
+      bContinue   = (iPosSDim != iSDimEnd);
+      iPosSDim    += iInc;
+    }
+
+    piSrc += iFDimSrcStrd;
+    piDst += iFDimDstStrd;
+  }
+};
+
+
+template Bool TRenFilter::compare   (TRenImage<Pel     >*, TRenImage<Pel>*      );
+template Bool TRenFilter::compare   (TRenImagePlane<Pel>*, TRenImagePlane<Pel>* );
+
+template Void TRenFilter::mirrorHor(        TRenImage<Double>        *pcImage );
+template Void TRenFilter::mirrorHor(        TRenImage<Pel>           *pcImage );
+template Void TRenFilter::mirrorHor(        TRenImage<Int>           *pcImage );
+template Void TRenFilter::mirrorHor(        TRenImagePlane<Pel>      *pcImagePlane );
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenFilter.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenFilter.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenFilter.h	(revision 438)
@@ -0,0 +1,141 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+#ifndef __TRENFILTER__
+#define __TRENFILTER__
+
+#include "TLibCommon/CommonDef.h"
+#include "TRenImage.h"
+#include "TRenInterpFilter.h"
+
+typedef Int (TRenInterpFilter::*FpChromaIntFilt) ( Pel*, Int );
+
+class TRenFilter
+{
+public:
+
+  /////////// Helpers ////////
+  static Void setSubPelShiftLUT ( Int iLutPrec, Int** piSubPelShiftLUT, Int iShift );
+  static Void setupZLUT         ( Bool bBlendUseDistWeight, Int iBlendZThresPerc, Int iRelDistToLeft, Int** ppiBaseShiftLUTLeft, Int** ppiBaseShiftLUTRight, Int& riBlendZThres, Int& riBlendDistWeight, Int* piInvZLUTLeft, Int* piInvZLUTRight );
+  static Void filledToUsedPelMap( PelImage* pcFilledImage, PelImage* pcUsedPelsImage, Int iUsedPelMapMarExt  );
+
+  /////////// Copy ///////////
+  static Void copy( Pel* pcInputPlaneData, Int iInputStride, Int iWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride);
+
+  /////////// Horizontal Mirroring ///////////
+  template <typename T> static Void mirrorHor(        TRenImage<T> *pcInputImage );
+  //Plane
+  template <typename T> static Void mirrorHor(   TRenImagePlane<T> *pcImagePlane );
+
+  /////////// Comparison ///////////
+
+  static Int64                          SSE  ( PelImagePlane*     pcInputPlane1, PelImagePlane*      pcInputPlane2 );
+  static Int64                          SSE  ( Pel* piSrc1,       Int iSrcStride1, Int iWidth, Int iHeight,  Pel* piSrc2, Int iSrcStride2 );
+
+  template <typename T> static Bool compare  (TRenImage<T> *pcInputImage1     , TRenImage<T> *pcInputImage2);
+  //Plane
+  template <typename T> static Bool compare  (TRenImagePlane<T>* pcInputPlane1, TRenImagePlane<T>* pcInputPlane2 );
+
+  /////////// other Filters ///////////
+  static Void binominal  ( PelImage*      pcInputImage,  PelImage*      pcOutputPlane, UInt uiSize);
+  static Void binominal  ( PelImagePlane* pcInputPlane,  PelImagePlane* pcOutputPlane, UInt uiSize );
+
+  static Void lineMedian3( PelImage*      pcImage );
+  static Void convRect   ( PelImage*      pcImage,       UInt uiSize);
+  static Void laplace    ( DoubleImage*   pcInputImage,  DoubleImage* pcOutputImage);
+  static Void diffHorSym ( PelImage*      pcInputImage,  IntImage* pcOutputImage);
+
+  //Plane
+  static Void diffHorSym (PelImagePlane* pcInputPlane, IntImagePlane* pcOutputPlane);
+
+  ///////////  Convolution ///////////
+  static Void conv (PelImage* pcImage, DoubleImage* pcKernel);
+
+  /////////// InterPolation ///////////
+  static Pel interpCHSpline(Double dX, Double dS0, Double dS1, Int iQ0, Int iQ1, Int iQ2, Int iQ3);
+
+
+  /////////// HEVC/ binomial Up and Down sampling ///////////
+  //// Down sampling (binomial)
+  // Horizontally
+  static Void sampleHorDown     (Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight     , Pel* pcOutputPlaneData, Int iOutputStride );
+  static Void sampleCHorDown    (Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iInputHeight, Pel* pcOutputPlaneData, Int iOutputStride );
+  // 444->420 and horizontally
+  static Void sampleCDownHorDown(Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iInputHeight, Pel* pcOutputPlaneData, Int iOutputStride );
+
+  //// Up sampling (HEVC 8/4 tap)
+  // Horizontally
+  static Void sampleHorUp       (Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight,      Pel* pcOutputPlaneData, Int iOutputStride );
+  static Void sampleCHorUp      (Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight,      Pel* pcOutputPlaneData, Int iOutputStride );
+  // 420->444 and horizontally
+  static Void sampleCUpHorUp    (Int iLog2HorSampFac, Pel* pcInputPlaneData, Int iInputStride, Int iInputWidth, Int iHeight,      Pel* pcOutputPlaneData, Int iOutputStride );
+
+  //// Down sampling (13 tap)
+
+  static Void sampleDown2Tap13   ( Pel* pcInputPlaneData, Int iInputStride, Int iWidth, Int iHeight, Pel* pcOutputPlaneData, Int iOutputStride );
+  // Plane
+  static Void sampleHorDown2Tap13(PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane, Int uiPad);
+  static Void sampleVerDown2Tap13(PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane, Int uiPad);
+  static Void sampleDown2Tap13   (PelImagePlane* pcInputPlane, PelImagePlane* pcOutputPlane);
+  // Image
+  static Void sampleDown2Tap13   (PelImage*      pcInputImage, PelImage*      pcOutputImage);
+  static Void sampleUp2Tap13     (PelImage*      pcInputImage, PelImage*      pcOutImage   );
+private:
+
+  // Helper Functions
+  static inline Pel   xMedian3 (Pel* pcData);
+  static Void         xDilate (Pel* piSrc, Int iSrcStride, Int    iWidth, Int iHeight,    Pel* piDst, Int iDstStride, Int iSize, Bool bVerticalDir, Bool bToTopOrLeft );
+
+  // Down sampling (binomial)
+  static Void xSampleDownHor2 (Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iHeight,    Pel* piDst, Int iDstStride );
+  static Void xSampleDownHor4 (Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iHeight,    Pel* piDst, Int iDstStride );
+  static Void xSampleDownHor8 (Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iHeight,    Pel* piDst, Int iDstStride );
+
+  static Void xSampleDownVer2 (Pel* piSrc, Int iSrcStride, Int iSrcWidth, Int iSrcHeight, Pel* piDst, Int iDstStride );
+
+  // Up sampling (8/4-Tap HEVC)
+  static Void xInterpVerChroma(Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, FpChromaIntFilt fpFilter);
+  static Void xInterpHorChroma(Pel* piSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* piDst, Int iDstStride, Int iDstStepX, Int iDstStepY, FpChromaIntFilt fpFilter);
+  static Void xDistributeArray(Pel* pcSrc, Int iSrcStride, Int iSrcStepX, Int iSrcStepY, Int iWidth, Int iHeight, Pel* pcDst, Int iDstStride, Int iDstStepX, Int iDstStepY );
+
+  // Binominal Filtering
+  static Pel  xFiltBinom3     (Pel* pcInputData, Int iStride );
+  static Pel  xFiltBinom5     (Pel* pcInputData, Int iStride );
+  static Pel  xFiltBinom7     (Pel* pcInputData, Int iStride );
+  static Pel  xFiltBinom9     (Pel* pcInputData, Int iStride );
+};
+
+
+#endif //__TRENFILTER__
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImage.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImage.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImage.cpp	(revision 438)
@@ -0,0 +1,271 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "TRenImage.h"
+#include "TRenImagePlane.h"
+#include "TRenFilter.h"
+#include "assert.h"
+
+template<typename T>
+TRenImage<T>::TRenImage( TRenImage& rcIn )
+{
+  allocatePlanes( rcIn.getPlane(0)->getWidth(), rcIn.getPlane(0)->getHeight(), rcIn.getNumberOfFullPlanes(), rcIn.getNumberOfQuaterPlanes() ) ; assign(&rcIn);
+}
+
+template<typename T>
+TRenImage<T>::TRenImage( UInt uiWidth, UInt uiHeight, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes )
+{
+  allocatePlanes( uiWidth, uiHeight, uiNumberOfFullPlanes, uiNumberOfQuaterPlanes );
+}
+
+template<typename T>
+TRenImage<T>::TRenImage() : m_uiNumberOfFullPlanes(0), m_uiNumberOfQuaterPlanes(0), m_uiNumberOfPlanes(0), m_apcPlanes(0)
+{
+
+}
+
+
+template<>
+TRenImage<Pel>::TRenImage( TComPicYuv* pcPicYuv, Bool bFirstPlaneOnly )
+{
+  if (bFirstPlaneOnly) //400
+  {
+    m_uiNumberOfPlanes       = 1;
+    m_uiNumberOfFullPlanes   = 1;
+    m_uiNumberOfQuaterPlanes = 0;
+    m_apcPlanes    = new TRenImagePlane<Pel>*[ m_uiNumberOfPlanes ];
+    m_apcPlanes[0] = new TRenImagePlane<Pel>( pcPicYuv->getBufY(), pcPicYuv->getWidth() + (REN_LUMA_MARGIN << 1),   pcPicYuv->getHeight()+ (REN_LUMA_MARGIN << 1), pcPicYuv->getStride (), REN_LUMA_MARGIN, g_uiPCMBitDepthLuma );
+  }
+  else //420
+  {
+    m_uiNumberOfPlanes       = 3;
+    m_uiNumberOfFullPlanes   = 1;
+    m_uiNumberOfQuaterPlanes = 2;
+
+    m_apcPlanes    = new TRenImagePlane<Pel>*[ m_uiNumberOfPlanes ];
+    m_apcPlanes[0] = new TRenImagePlane<Pel>( pcPicYuv->getBufY(),   pcPicYuv->getWidth()     + (REN_LUMA_MARGIN << 1),  pcPicYuv->getHeight()      + (REN_LUMA_MARGIN << 1), pcPicYuv->getStride (), REN_LUMA_MARGIN     , g_uiPCMBitDepthLuma   );
+    m_apcPlanes[1] = new TRenImagePlane<Pel>( pcPicYuv->getBufU(),   (pcPicYuv->getWidth()>>1)+  REN_LUMA_MARGIN      ,  (pcPicYuv->getHeight()>>1) +  REN_LUMA_MARGIN      , pcPicYuv->getCStride(), REN_LUMA_MARGIN >> 1, g_uiPCMBitDepthChroma );
+    m_apcPlanes[2] = new TRenImagePlane<Pel>( pcPicYuv->getBufV(),   (pcPicYuv->getWidth()>>1)+  REN_LUMA_MARGIN      ,  (pcPicYuv->getHeight()>>1) +  REN_LUMA_MARGIN      , pcPicYuv->getCStride(), REN_LUMA_MARGIN >> 1, g_uiPCMBitDepthChroma );
+  }
+}
+
+template<typename T>
+TRenImage<T>* TRenImage<T>::create()
+{
+  return new TRenImage( m_apcPlanes[0]->getWidth(), m_apcPlanes[0]->getHeight(), m_uiNumberOfFullPlanes, m_uiNumberOfQuaterPlanes );
+}
+
+
+template<typename T>
+TRenImage<T>::TRenImage( TComPicYuv* pcPicYuv, Bool bFirstPlaneOnly )
+{
+  assert(0);
+}
+
+template<class T>
+TRenImagePlane<T>* TRenImage<T>::getPlane(UInt uiPlaneNumber) const
+{
+  return m_apcPlanes[uiPlaneNumber];
+}
+
+template<class T>
+TRenImagePlane<T>** TRenImage<T>::getPlanes() const
+{
+  return m_apcPlanes;
+}
+
+template<typename T>
+Void TRenImage<T>::getDataAndStrides( T** pptData, Int* piStrides )
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++ )
+  {
+    piStrides[uiCurPlane] = m_apcPlanes[uiCurPlane]->getStride   ();
+    pptData  [uiCurPlane] = m_apcPlanes[uiCurPlane]->getPlaneData();
+  }
+}
+
+
+template<typename T>
+Void TRenImage<T>::getWidthAndHeight( Int* ppiWidths, Int* ppiHeights )
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++ )
+  {
+    ppiWidths [uiCurPlane] = m_apcPlanes[uiCurPlane]->getWidth ();
+    ppiHeights[uiCurPlane] = m_apcPlanes[uiCurPlane]->getHeight();
+  }
+}
+
+template<typename T>
+Void TRenImage<T>::allocatePlanes( UInt uiWidth, UInt uiHeight, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes )
+{
+  assert( uiNumberOfFullPlanes + uiNumberOfQuaterPlanes);
+
+  UInt uiHalfWidth  = uiWidth  >> 1;
+  UInt uiHalfHeight = uiHeight >> 1;
+
+  uiHalfWidth  = (uiHalfWidth  == 0) ? 1 : uiHalfWidth ;
+  uiHalfHeight = (uiHalfHeight == 0) ? 1 : uiHalfHeight;
+
+  m_uiNumberOfPlanes       = uiNumberOfFullPlanes + uiNumberOfQuaterPlanes; ;
+  m_uiNumberOfFullPlanes   = uiNumberOfFullPlanes;
+  m_uiNumberOfQuaterPlanes = uiNumberOfQuaterPlanes;
+
+  this->m_apcPlanes    = new TRenImagePlane<T>*[m_uiNumberOfPlanes];
+
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfFullPlanes; uiCurPlane++)
+  {
+    this->m_apcPlanes[uiCurPlane] = new TRenImagePlane<T>(uiWidth, uiHeight, REN_LUMA_MARGIN, g_uiPCMBitDepthLuma );
+  };
+
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfQuaterPlanes; uiCurPlane++)
+  {
+    this->m_apcPlanes[uiCurPlane+uiNumberOfFullPlanes] = new TRenImagePlane<T>(uiHalfWidth, uiHalfHeight, REN_LUMA_MARGIN >> 1, g_uiPCMBitDepthChroma);
+  };
+}
+
+
+template<class T>
+Void TRenImage<T>::assign(Int iVal)
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++)
+  {
+    m_apcPlanes[uiCurPlane]->assign( iVal);
+  }
+}
+
+
+template<class T>
+Void TRenImage<T>::devide( Double dDevisor )
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++)
+  {
+    m_apcPlanes[uiCurPlane]->devide(dDevisor);
+  }
+}
+
+
+template<class T> template<class S>
+Void TRenImage<T>::assign( TRenImage<S>* pcSrcImage )
+{
+  if (pcSrcImage->getNumberOfPlanes() != m_uiNumberOfPlanes )
+  {
+    assert(0);
+  }
+
+  for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++)
+  {
+    m_apcPlanes[uiCurPlane]->assign(pcSrcImage->getPlane(uiCurPlane)->getPlaneDataOrg(),pcSrcImage->getPlane(uiCurPlane)->getStride());
+  }
+}
+
+
+template<typename T>
+Void TRenImage<T>::setData( TRenImage* pcInputImage, Bool bClean )
+{
+  for (UInt uiPlane = 0; uiPlane < m_uiNumberOfPlanes; uiPlane++)
+  {
+    m_apcPlanes[uiPlane]->setData( pcInputImage->getPlane( uiPlane ), bClean );
+  }
+}
+
+template<typename T>
+Void TRenImage<T>::extendMargin()
+{
+  for (UInt uiPlane = 0; uiPlane < m_uiNumberOfPlanes; uiPlane++)
+  {
+    m_apcPlanes[uiPlane]->extendMargin();
+  }
+}
+
+template<class T>
+Void TRenImage<T>::xDeletePlanes()
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++)
+  {
+    if ( m_apcPlanes[uiCurPlane])
+    {
+      delete m_apcPlanes[uiCurPlane];
+    }
+    m_apcPlanes[uiCurPlane] = 0;
+  }
+}
+
+
+template<class T>
+Void TRenImage<T>::init()
+{
+  // YUV-init
+  m_apcPlanes[0]->assign((Pel) 0 );
+
+  for (UInt uiCurPlane = 1; uiCurPlane < m_uiNumberOfPlanes; uiCurPlane++)
+  {
+    m_apcPlanes[uiCurPlane]->assign( (Pel) ((g_uiIBDI_MAX+1) >> 1) );
+  }
+}
+
+
+template<class T>
+TRenImage<T>::~TRenImage() {
+  xDeletePlanes();
+  delete[] m_apcPlanes;
+}
+
+
+
+template<class T>
+UInt TRenImage<T>::getNumberOfPlanes() const
+{
+  return m_uiNumberOfPlanes;
+}
+
+template<class T>
+UInt TRenImage<T>::getNumberOfQuaterPlanes() const
+{
+  return m_uiNumberOfQuaterPlanes;
+}
+
+template<class T>
+UInt TRenImage<T>::getNumberOfFullPlanes() const
+{
+  return m_uiNumberOfFullPlanes;
+}
+
+template class TRenImage<Pel>;
+template class TRenImage<Int>;
+template class TRenImage<Double>;
+template class TRenImage<Bool>;
+
+
+template Void TRenImage<Pel>::assign<Pel>    (TRenImage<Pel>*   );
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImage.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImage.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImage.h	(revision 438)
@@ -0,0 +1,103 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef __TRENIMAGE__
+#define __TRENIMAGE__
+
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPicYuv.h"
+#include "TRenImagePlane.h"
+
+
+#define PelImage    TRenImage<Pel>
+#define DoubleImage TRenImage<Double>
+#define IntImage    TRenImage<Int>
+
+
+template<typename T>
+class TRenImage
+{
+public:
+
+  // Construction
+  TRenImage( TRenImage& rcInputImage );
+  TRenImage();
+//  TRenImage( TRenImagePlane<T>** ppcYPlanes, UInt uiNumberOfFullPlanes, UInt uiNumberOfQuaterPlanes );
+
+  TRenImage( UInt uiWidth, UInt uiHeight, UInt uiNumPlanes, UInt uiNumQPlanes );
+  TRenImage( TComPicYuv* pcPicYuvIn, Bool bFirstPlaneOnly = false );
+
+  Void allocatePlanes(UInt uiWidth, UInt uiHeight, UInt uiNumFullPlanes, UInt uiNumQuaterPlanes);
+  ~TRenImage();
+
+  TRenImage* create();
+  Void       init();
+
+  // Get Planes and data
+  TRenImagePlane<T>*  getPlane(UInt uiPlaneNumber) const;
+  TRenImagePlane<T>** getPlanes() const;
+
+  Void getDataAndStrides( T**    pptData, Int*  piStrides );
+  Void getWidthAndHeight( Int*  piWidths, Int*  piHeights );
+
+  UInt getNumberOfPlanes()  const;
+  UInt getNumberOfQuaterPlanes() const;
+  UInt getNumberOfFullPlanes() const;
+  Bool is420() {return m_uiNumberOfFullPlanes == 1 && m_uiNumberOfQuaterPlanes == 2; };
+  Bool is444() {return m_uiNumberOfFullPlanes == 3 && m_uiNumberOfQuaterPlanes == 0; };
+  Bool is400() {return m_uiNumberOfFullPlanes == 1 && m_uiNumberOfQuaterPlanes == 0; };
+
+  // Assign
+  Void assign(Int iVal);
+  template<typename S> Void assign(TRenImage<S>* pcSrcImage);
+  Void setData( TRenImage* pcInputImage, Bool bClean );
+
+  Void extendMargin();
+  // Operators
+  Void devide( Double dDevisor );
+
+
+private:
+
+  UInt m_uiNumberOfFullPlanes;
+  UInt m_uiNumberOfQuaterPlanes;
+  UInt m_uiNumberOfPlanes;
+  TRenImagePlane<T> ** m_apcPlanes;   // First Full Planes, then Quater Planes
+
+  Void xDeletePlanes();
+};
+
+#endif // __TRENIMAGE__
+
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImagePlane.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImagePlane.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImagePlane.cpp	(revision 438)
@@ -0,0 +1,535 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "TRenImagePlane.h"
+#include "TRenFilter.h"
+#include <string.h>
+/////// TRenImagePlane ///////
+
+template<class T>
+TRenImagePlane<T>::TRenImagePlane() { m_bClean = true; }
+
+template<class T>
+TRenImagePlane<T>::TRenImagePlane(UInt uiWidth, UInt uiHeight, UInt uiPad, UInt uiBitDepth )
+: m_uiWidth    (uiWidth), 
+  m_uiHeight   (uiHeight),
+  m_uiStride   (uiWidth+2*uiPad), 
+  m_uiWidthOrg (uiWidth+2*uiPad), 
+  m_uiHeightOrg(uiHeight+2*uiPad), 
+  m_uiPad      (uiPad),
+  m_uiBitDepth (uiBitDepth)
+{
+  m_pcDataOrg = new T[ m_uiWidthOrg * m_uiHeightOrg ];
+  m_pcData    = m_pcDataOrg + m_uiPad * m_uiStride + m_uiPad;
+  m_bClean    = true;
+}
+
+template<class T>
+TRenImagePlane<T>::TRenImagePlane(TRenImagePlane* pcPlane)
+: m_uiWidth    (pcPlane->getWidth   ())
+, m_uiHeight   (pcPlane->getHeight  ())
+, m_uiStride   (pcPlane->getStride  ())
+, m_uiWidthOrg (pcPlane->getWidthOrg())
+, m_uiHeightOrg(pcPlane->getHeightOrg())
+, m_uiPad      (pcPlane->getPad     ())
+, m_uiBitDepth (pcPlane->getBitDepth())
+{
+  m_pcData = new T[m_uiWidthOrg*m_uiHeightOrg];
+  m_bClean = true;
+  assign( pcPlane );
+}
+
+template<typename T>
+TRenImagePlane<T>::TRenImagePlane( T* pcDataOrg, UInt uiWidthOrg, UInt uiHeightOrg, UInt uiStride, UInt uiPad, UInt uiBitDepth )
+: m_pcData     (pcDataOrg + uiStride * uiPad + uiPad )
+, m_uiWidth    (uiWidthOrg  - 2* uiPad )
+, m_uiHeight   (uiHeightOrg - 2* uiPad )
+, m_uiStride   (uiStride   )
+, m_pcDataOrg  (pcDataOrg  )
+, m_uiWidthOrg (uiWidthOrg )
+, m_uiHeightOrg(uiHeightOrg)
+, m_uiPad      (uiPad      )
+, m_bClean     (false      )
+, m_uiBitDepth (uiBitDepth )
+{
+
+}
+
+template<typename T>
+Void TRenImagePlane<T>::setData( T* pDataOrg, UInt uiWidthOrg, UInt uiHeightOrg, UInt uiStride, UInt uiPad, Bool bClean /*= false*/ ) 
+{
+  deleteData();
+  m_uiPad       = uiPad;
+  m_pcDataOrg   = pDataOrg;
+  m_uiWidthOrg  = uiWidthOrg;
+  m_uiHeightOrg = uiHeightOrg;
+  m_uiWidth     = uiWidthOrg  - 2* uiPad;
+  m_uiHeight    = uiHeightOrg - 2* uiPad;
+  m_uiStride    = uiStride;
+  m_pcData      = m_pcDataOrg + uiPad * m_uiStride + uiPad;
+  m_bClean      = bClean;
+}
+
+template<typename T>
+Void TRenImagePlane<T>::setData( TRenImagePlane<T>* pcInPlane, Bool bClean )
+{
+  deleteData();
+  m_uiPad       = pcInPlane->getPad();
+  m_pcDataOrg   = pcInPlane->getPlaneDataOrg();
+  m_uiWidthOrg  = pcInPlane->getWidthOrg();
+  m_uiHeightOrg = pcInPlane->getHeightOrg();
+  m_uiWidth     = pcInPlane->getWidth();
+  m_uiHeight    = pcInPlane->getHeight();
+  m_uiStride    = pcInPlane->getStride();
+  m_pcData      = pcInPlane->getPlaneData();
+  m_bClean      = bClean;
+  pcInPlane->setClean( !m_bClean );
+}
+
+template<typename T>
+Void TRenImagePlane<T>::setClean( Bool bClean )
+{
+  m_bClean = bClean;
+}
+
+template<class T>
+T* TRenImagePlane<T>::getPlaneData()
+{
+  return m_pcData;
+}
+
+
+template<class T>
+T* TRenImagePlane<T>::getPlaneDataOrg()
+{
+  return m_pcDataOrg;
+}
+
+
+template<class T>
+Void TRenImagePlane<T>::assign(Pel* pcSourceData, UInt uiSourceStride )
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) pcSourceData[uiXPos];
+    }
+    pcTargetData += m_uiStride;
+    pcSourceData += uiSourceStride;
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(Pel cData)
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) cData;
+    }
+    pcTargetData  += m_uiStride;
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(Double* pdData, UInt uiSourceStride )
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) pdData[uiXPos];
+    }
+    pcTargetData += m_uiStride;
+    pdData       +=  uiSourceStride;
+
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(Double dData)
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) dData;
+    }
+    pcTargetData  += m_uiStride;
+  }
+}
+
+
+template<class T>
+Void TRenImagePlane<T>::assign(Bool* pbData, UInt uiSourceStride )
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) pbData[uiXPos];
+    }
+    pcTargetData += m_uiStride;
+    pbData       += uiSourceStride;
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(Int iData)
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) iData;
+    }
+    pcTargetData += m_uiStride;
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(Int* piData, UInt uiSourceStride )
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) piData[uiXPos];
+    }
+    pcTargetData += m_uiStride;
+    piData       += uiSourceStride;
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(Bool data)
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (T) data;
+    }
+    pcTargetData += m_uiStride;
+  }
+}
+
+// Assignments to Bool
+
+template<>
+Void TRenImagePlane<Bool>::assign(Int* piData, UInt uiSourceStride )
+{
+  Bool* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (piData[uiXPos] == 0);
+    }
+    pcTargetData  += m_uiStride;
+    piData        += uiSourceStride;
+
+  }
+}
+
+template<>
+Void TRenImagePlane<Bool>::assign(Int iData)
+{
+  Bool* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (iData == 0);
+    }
+    pcTargetData += m_uiStride;
+  }
+}
+
+template<>
+Void TRenImagePlane<Bool>::assign(Pel* pcData, UInt uiSourceStride )
+{
+  Bool* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (pcData[uiXPos] == 0);
+    }
+    pcTargetData += m_uiStride;
+    pcData       +=  uiSourceStride;
+
+  }
+}
+
+template<>
+Void TRenImagePlane<Bool>::assign(Pel cData)
+{
+  Bool* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (cData == 0);
+    }
+    pcTargetData += m_uiStride;
+  }
+}
+
+template<>
+Void TRenImagePlane<Bool>::assign(Double* pdData, UInt uiSourceStride )
+{
+  Bool* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = ( pdData[uiXPos] == 0);
+    }
+    pcTargetData += m_uiStride;
+    pdData       += uiSourceStride;
+
+  }
+}
+
+
+
+template<>
+Void TRenImagePlane<Bool>::assign(Double dData)
+{
+  Bool* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData [uiXPos] = (dData == 0);
+    }
+    pcTargetData  += m_uiStride;
+  }
+}
+
+
+// Assignments to Pel
+template<>
+Void TRenImagePlane<Pel>::assign(Double* pdData, UInt uiSourceStride )
+{
+  Pel* pcTargetData = m_pcDataOrg;
+  for (UInt uiYPos = 0; uiYPos < m_uiHeightOrg; uiYPos++)
+  {
+    for (UInt uiXPos = 0; uiXPos < m_uiWidthOrg; uiXPos++)
+    {
+      pcTargetData[uiXPos] = (Pel) ( pdData[uiXPos] + pdData[uiXPos] < 0 ? -0.5 : 0.5 ) ;
+    }
+    pcTargetData += m_uiStride;
+    pdData       += uiSourceStride;
+  }
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(TRenImagePlane<T>* pcPlane)
+{
+  assign(pcPlane->getPlaneDataOrg(), pcPlane->getStride());
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(TRenImagePlane<T>* pcPlane, UInt uiRow, UInt uiStartOffset, UInt uiEndOffset)
+{
+  T* pcTargetData = m_pcData                + uiRow * m_uiStride;
+  T* pcSourceData = pcPlane->getPlaneData() + uiRow * pcPlane->getStride();
+
+  for (UInt uiPosX = uiStartOffset; uiPosX <= uiEndOffset; uiPosX++)
+  {
+    pcTargetData[uiPosX] = pcSourceData[uiPosX];
+  }
+
+}
+
+template<class T>
+Void TRenImagePlane<T>::assign(TRenImagePlane<T>* pcSourcePlane, UInt uiSourceRowStart, UInt uiSourceColStart, UInt uiWidth, UInt uiHeight)
+{
+  T* acSourceData;
+  T* acDestData;
+
+  acSourceData = pcSourcePlane->getPlaneData();
+  acSourceData += uiSourceRowStart * pcSourcePlane->getStride() + uiSourceColStart;
+  acDestData    = m_pcData;
+
+  for (UInt uiPosY = 0; uiPosY < uiHeight ; uiPosY++)
+  {
+    for (UInt uiPosX = 0; uiPosX < uiWidth ; uiPosX++)
+    {
+      acDestData[uiPosX] = acSourceData[uiPosX];
+    }
+    acSourceData += pcSourcePlane->getStride();
+    acDestData   += this        ->getStride();
+  };
+}
+
+
+
+template<class T>
+Void TRenImagePlane<T>::assign( T data , UInt uiRow, UInt uiStartOffset, UInt uiEndOffset)
+{
+  T* pcTargetData = m_pcData + uiRow * m_uiStride;
+  for (UInt uiPosX = uiStartOffset; uiPosX <= uiEndOffset; uiPosX++)
+  {
+    pcTargetData[uiPosX] = data;
+  }
+}
+
+
+template<class T>
+Void TRenImagePlane<T>::devide( Double dDevisor )
+{
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiPosY = 0; uiPosY < (m_uiHeightOrg); uiPosY++)
+  {
+    for (UInt uiPosX = 0; uiPosX < m_uiWidthOrg; uiPosX++)
+    {
+      pcTargetData[uiPosX] = (T)  ( ( Double )pcTargetData[uiPosX] / dDevisor );
+    }
+    pcTargetData += m_uiStride;
+  }
+};
+
+template<class T>
+Void TRenImagePlane<T>::multiply( Double dMultiplier ) {
+  T* pcTargetData = m_pcDataOrg;
+  for (UInt uiPosY = 0; uiPosY < (m_uiHeightOrg); uiPosY++)
+  {
+    for (UInt uiPosX = 0; uiPosX < m_uiWidthOrg; uiPosX++)
+    {
+      pcTargetData[uiPosX] = (T)  ( ( Double )pcTargetData[uiPosX] * dMultiplier );
+    }
+    pcTargetData += m_uiStride;
+  }
+};
+
+
+template<>
+Void TRenImagePlane<Bool>::devide( Double dDevisor )
+{
+  assert(0);
+};
+
+template<>
+Void TRenImagePlane<Bool>::multiply( Double dMultiplier )
+{
+  assert(0);
+};
+
+
+template<class T>
+Void TRenImagePlane<T>::deleteData()
+{
+  if (m_bClean)
+  {
+    if (m_pcDataOrg)
+    {
+      delete[] m_pcDataOrg;
+    };
+  }
+}
+
+template<class T>
+TRenImagePlane<T>::~TRenImagePlane()
+{
+  deleteData();
+}
+
+
+template<typename T>
+Void TRenImagePlane<T>::extendMargin()
+{
+  Int iPad = (Int) m_uiPad;
+  T* pcData = m_pcData;
+
+  for ( Int iPosY = 0; iPosY < (Int) m_uiHeight; iPosY++)
+  {
+    for ( Int iPosX = 0; iPosX < (Int) iPad; iPosX++ )
+    {
+      pcData[ -iPad + iPosX ]  = pcData[0];
+      pcData[m_uiWidth + iPosX ]  = pcData[m_uiWidth -1 ];
+    }
+    pcData += m_uiStride;
+  }
+
+
+  pcData -= (m_uiStride + iPad);
+  for ( Int iPosY = 0; iPosY < iPad; iPosY++ )
+  {
+    memcpy( pcData + (iPosY+1)*m_uiStride, pcData, sizeof(T)*(m_uiWidth + (iPad<<1)) );
+  }
+
+  pcData -= ((m_uiHeight-1) * m_uiStride);
+  for ( Int iPosY = 0; iPosY < iPad; iPosY++ )
+  {
+    memcpy( pcData - (iPosY+1)*m_uiStride, pcData, sizeof(T)*(m_uiWidth + (iPad<<1)) );
+  }
+}
+
+template class TRenImagePlane<Pel>;
+template class TRenImagePlane<Double>;
+template class TRenImagePlane<Bool>;
+template class TRenImagePlane<Int>;
+
+/////// TRenImagePlanePart ///////
+
+template<typename T>
+TRenImagePlanePart<T>::TRenImagePlanePart( TRenImagePlane<T>* pPlane, UInt uHorOff, UInt uVerOff, UInt uWidth, UInt uHeight )
+: TRenImagePlane<T>( pPlane->getPlaneData() + uHorOff + uVerOff * pPlane->getStride(), uWidth, uHeight, pPlane->getStride(),0, pPlane->getBitDepth())
+{
+
+}
+
+template<typename T>
+TRenImagePlanePart<T>::~TRenImagePlanePart()
+{
+  this->m_pcData = NULL;
+}
+
+template class TRenImagePlanePart<Pel>;
+template class TRenImagePlanePart<Double>;
+template class TRenImagePlanePart<Bool>;
+template class TRenImagePlanePart<Int>;
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImagePlane.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImagePlane.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenImagePlane.h	(revision 438)
@@ -0,0 +1,124 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef __TRENIMAGEPLANE__
+#define __TRENIMAGEPLANE__
+
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPicYuv.h"
+
+#define PelImagePlane     TRenImagePlane<Pel>
+#define DoubleImagePlane  TRenImagePlane<Double>
+#define IntImagePlane     TRenImagePlane<Int>
+
+template<typename T>
+class TRenImagePlane
+{
+public:
+  // Construction
+  TRenImagePlane();
+  TRenImagePlane( UInt uiWidth, UInt uiHeight, UInt uiPad, UInt uiBitDepth );
+  TRenImagePlane( TRenImagePlane* pcInputPlane );
+  TRenImagePlane( T* pcDataOrg, UInt uiWidthOrg, UInt uiHeightOrg, UInt uiStride, UInt uiPad, UInt uiBitDepth  );
+
+  ~TRenImagePlane();
+
+  // Get Data
+  T*   getPlaneData();
+  UInt getWidth    () { return m_uiWidth; };
+  UInt getHeight   () { return m_uiHeight; };
+
+  T*   getPlaneDataOrg();
+  UInt getWidthOrg () { return m_uiWidthOrg;  };
+  UInt getHeightOrg() { return m_uiHeightOrg; };
+  UInt getPad      () { return m_uiPad;       };
+  UInt getBitDepth () { return m_uiBitDepth; };
+  UInt getStride   () { return m_uiStride; };
+
+  Void setData ( T* pDataOrg, UInt uiWidthOrg, UInt uiHeightOrg, UInt uiStride, UInt uiPad, Bool bClean /*= false*/ ); 
+  
+  Void setData ( TRenImagePlane<T>* pcInPlane, Bool bClean );
+  Void setClean( Bool bClean );
+  Void extendMargin();
+
+  // Assignment
+  Void assign( Pel*    data, UInt uiSourceStride );
+  Void assign( Pel     data );
+
+  Void assign( Double* data, UInt uiSourceStride );
+  Void assign( Double  data );
+
+  Void assign( Bool*  data, UInt uiSourceStride );
+  Void assign( Bool   data );
+
+  Void assign( Int*   data, UInt uiSourceStride );
+  Void assign( Int    data );
+
+  Void assign( TRenImagePlane<T>* pcPlane);
+
+  Void assign( T data , UInt uRow, UInt uStartOffset, UInt uEndOffset);
+  Void assign( TRenImagePlane<T>* pcPlane, UInt uRow, UInt uStartOffset, UInt uEndOffset);
+  Void assign( TRenImagePlane<T>* pcSourcePlane, UInt uSourceRowStart, UInt uSourceColStart, UInt uWidth, UInt uHeight);
+
+  // Operators
+  Void devide(   Double dDevisor );
+  Void multiply( Double dMultiplier );
+
+protected:
+  T     *m_pcData;
+  UInt   m_uiWidth;
+  UInt   m_uiHeight;
+  UInt   m_uiStride;
+
+  T     *m_pcDataOrg;
+  UInt   m_uiWidthOrg;
+  UInt   m_uiHeightOrg;
+  UInt   m_uiPad;
+  UInt   m_uiBitDepth; 
+
+  Bool   m_bClean;
+
+private:
+  Void deleteData();
+};
+
+template<typename T>
+class TRenImagePlanePart : public TRenImagePlane< T >
+{
+public:
+  TRenImagePlanePart( TRenImagePlane<T>* pcPlane, UInt uHorOff, UInt uVerOff, UInt uWidth, UInt uHeight);;
+  ~TRenImagePlanePart();;
+};
+
+#endif // __TRENIMAGEPLANE__
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenInterpFilter.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenInterpFilter.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenInterpFilter.cpp	(revision 438)
@@ -0,0 +1,50 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+/** \file     TRenInterpFilter.cpp
+    \brief    interpolation filter class (From HM 3.0 TComPredFilter)
+*/
+
+#include "TRenInterpFilter.h"
+
+// ====================================================================================================================
+// Constructor
+// ====================================================================================================================
+
+TRenInterpFilter::TRenInterpFilter()
+{
+  // initial number of taps for Luma
+}
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenInterpFilter.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenInterpFilter.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenInterpFilter.h	(revision 438)
@@ -0,0 +1,2234 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+
+/** \file     TRenInterpFilter.h
+    \brief    interpolation filter class (header), (From HM 3.0 TComPredFilter))
+*/
+
+#ifndef __TRENINTERPFILTER__
+#define __TRENINTERPFILTER__
+
+// Include files
+#include "TLibCommon/CommonDef.h"
+#include "assert.h"
+// ====================================================================================================================
+// Constants
+// ====================================================================================================================
+
+// Local type definitions
+#define HAL_IDX   1
+#define QU0_IDX   0
+#define QU1_IDX   2
+
+// ====================================================================================================================
+// Class definition
+// ====================================================================================================================
+
+/// interpolation filter class
+class TRenInterpFilter
+{
+public:
+  TRenInterpFilter();
+  
+  // DIF filter interface (for half & quarter)
+  __inline Void xCTI_FilterHalfHor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
+  __inline Void xCTI_FilterHalfHor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
+  
+  __inline Void xCTI_FilterQuarter0Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
+  __inline Void xCTI_FilterQuarter0Hor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
+  
+  __inline Void xCTI_FilterQuarter1Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
+  __inline Void xCTI_FilterQuarter1Hor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);
+  
+  __inline Void xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst, Int iDstStridePel, Pel*& rpiDstPel );
+  __inline Void xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst );
+  __inline Void xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst );
+  
+  __inline Void xCTI_FilterQuarter0Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst );
+  __inline Void xCTI_FilterQuarter0Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst );
+  
+  __inline Void xCTI_FilterQuarter1Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst );
+  __inline Void xCTI_FilterQuarter1Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst );
+  
+  __inline Void xCTI_Filter2DVerC (Pel* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Int*& rpiDst, Int iMv);
+  __inline Void xCTI_Filter2DHorC (Int* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV);
+  __inline Void xCTI_Filter1DHorC (Pel* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV);
+  __inline Void xCTI_Filter1DVerC (Pel* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV);
+
+   __inline Int xCTI_Filter_VPS04_C_HAL( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VIS04_C_HAL( Int* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VP04_C_OCT0( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VI04_C_OCT0( Int* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VP04_C_QUA0( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VI04_C_QUA0( Int* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VP04_C_OCT1( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VI04_C_OCT1( Int* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VP04_C_OCT2( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VI04_C_OCT2( Int* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VP04_C_QUA1( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VI04_C_QUA1( Int* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VP04_C_OCT3( Pel* pSrc, Int iStride );
+   __inline Int xCTI_Filter_VI04_C_OCT3( Int* pSrc, Int iStride );
+
+#if HIGH_ACCURACY_BI
+  __inline Void xCTI_FilterHalfHor_ha(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst); //
+  __inline Void xCTI_FilterHalfHor_ha(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst);//
+  
+    
+  __inline Void xCTI_FilterQuarter0Hor_ha(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst); //
+  __inline Void xCTI_FilterQuarter0Hor_ha(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst); //
+  
+  __inline Void xCTI_FilterQuarter1Hor_ha(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst); //
+  __inline Void xCTI_FilterQuarter1Hor_ha(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst); //
+  
+  __inline Void xCTI_FilterHalfVer_ha (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst ); //
+  
+  __inline Void xCTI_FilterQuarter0Ver_ha (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst );
+  __inline Void xCTI_FilterQuarter1Ver_ha (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst );
+  
+  __inline Void xCTI_Filter1DHorC_ha (Pel* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV);
+  __inline Void xCTI_Filter1DVerC_ha (Pel* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV);
+  __inline Void xCTI_Filter2DHorC_ha (Int* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV);
+
+#endif
+};
+
+#if HIGH_ACCURACY_BI
+__inline Void TRenInterpFilter::xCTI_FilterHalfHor_ha(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+  Int shiftNum = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[        0]+piSrcTmp[iSrcStep7];
+      iTmp1 = piSrcTmp[iSrcStep]+piSrcTmp[iSrcStep6];
+      iTmp2 = piSrcTmp[iSrcStep2]+piSrcTmp[iSrcStep5];
+      iTmp3 = piSrcTmp[iSrcStep3]+piSrcTmp[iSrcStep4];
+
+      iTmpA = (iTmp3 << 2) - iTmp2;
+
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfHor_ha(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+ 
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+  Int shiftNum = 6 + g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[        0]+piSrcTmp[iSrcStep7];
+      iTmp1 = piSrcTmp[iSrcStep ]+piSrcTmp[iSrcStep6];
+      iTmp2 = piSrcTmp[iSrcStep2]+piSrcTmp[iSrcStep5];
+      iTmp3 = piSrcTmp[iSrcStep3]+piSrcTmp[iSrcStep4];
+      
+      iTmpA = (iTmp3 << 2) - iTmp2;
+      
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;
+      
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Hor_ha(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int  iTmp1, iTmp2;
+  Int shiftNum = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStep3] + piSrcTmp[iSrcStep5];
+      iTmp2 = piSrcTmp[iSrcStep6] + piSrcTmp[iSrcStep4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep2] - iTmp2 ) << 1 )
+            + (  piSrcTmp[iSrcStep]             << 2 )
+            - ( ( piSrcTmp[iSrcStep2] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep4]           << 4 )
+            + ( piSrcTmp[iSrcStep3]             << 6);
+      
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum + shiftOffset) >> shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0,16383, (iSum + shiftOffset) >> shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Hor_ha(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+  
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+  Int shiftNum = 6 + g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  Int  iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+    
+      iTmp1 = piSrcTmp[iSrcStep3] + piSrcTmp[iSrcStep5];
+      iTmp2 = piSrcTmp[iSrcStep6] + piSrcTmp[iSrcStep4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep2] - iTmp2 ) << 1 )
+            + (  piSrcTmp[iSrcStep]             << 2 )
+            - ( ( piSrcTmp[iSrcStep2] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep4]           << 4 )
+            + (   piSrcTmp[iSrcStep3]           << 6 );
+      
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0, 16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Hor_ha(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+  Int shiftNum = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStep4] + piSrcTmp[iSrcStep2];
+      iTmp2 = piSrcTmp[iSrcStep ] + piSrcTmp[iSrcStep3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStep6]           << 2 )
+            - ( ( piSrcTmp[iSrcStep5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep3]           << 4 )
+            + (   piSrcTmp[iSrcStep4]           << 6 );
+
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0, 16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Hor_ha(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+  Int shiftNum = 6+g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStep4] + piSrcTmp[iSrcStep2];
+      iTmp2 = piSrcTmp[iSrcStep ] + piSrcTmp[iSrcStep3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStep6]           << 2 )
+            - ( ( piSrcTmp[iSrcStep5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep3]           << 4 )
+            + (   piSrcTmp[iSrcStep4]           << 6 );
+      
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0, 16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Ver_ha (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+  Int shiftNum = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStride3] + piSrcTmp[iSrcStride5];
+      iTmp2 = piSrcTmp[iSrcStride6] + piSrcTmp[iSrcStride4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStride7]
+            - ( ( piSrcTmp[iSrcStride2] - iTmp2 ) << 1 )
+            + (  piSrcTmp[iSrcStride]             << 2 )
+            - ( ( piSrcTmp[iSrcStride2] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStride4]           << 4 )
+            + (   piSrcTmp[iSrcStride3]           << 6);
+      
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0, 16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Ver_ha (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+  Int shiftNum = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  Int  iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      /// {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      iTmp1 = piSrcTmp[iSrcStride4] + piSrcTmp[iSrcStride2];
+      iTmp2 = piSrcTmp[iSrcStride ] + piSrcTmp[iSrcStride3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStride7]
+            - ( ( piSrcTmp[iSrcStride5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStride6]           << 2 )
+            - ( ( piSrcTmp[iSrcStride5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStride3]           << 4 )
+            + (   piSrcTmp[iSrcStride4]           << 6 );
+            
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0, 16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfVer_ha  (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+  Int shiftNum = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+  Int  iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[          0]+piSrcTmp[iSrcStride7];
+      iTmp1 = piSrcTmp[iSrcStride ]+piSrcTmp[iSrcStride6];
+      iTmp2 = piSrcTmp[iSrcStride2]+piSrcTmp[iSrcStride5];
+      iTmp3 = piSrcTmp[iSrcStride3]+piSrcTmp[iSrcStride4];
+      
+      iTmpA = (iTmp3 << 2) - iTmp2;
+      
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;        
+      
+#if REMOVE_INTERMEDIATE_CLIPPING
+      piDst   [x * iDstStep] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+      piDst   [x * iDstStep] = Clip3(0, 16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+
+}
+
+
+#endif
+
+// ------------------------------------------------------------------------------------------------
+// DCTIF filters
+// ------------------------------------------------------------------------------------------------
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfHor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[        0]+piSrcTmp[iSrcStep7];
+      iTmp1 = piSrcTmp[iSrcStep]+piSrcTmp[iSrcStep6];
+      iTmp2 = piSrcTmp[iSrcStep2]+piSrcTmp[iSrcStep5];
+      iTmp3 = piSrcTmp[iSrcStep3]+piSrcTmp[iSrcStep4];
+
+      iTmpA = (iTmp3 << 2) - iTmp2;
+
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;
+
+      piDst   [x * iDstStep] = ClipY( (iSum +  32) >>  6 );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfHor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[        0]+piSrcTmp[iSrcStep7];
+      iTmp1 = piSrcTmp[iSrcStep ]+piSrcTmp[iSrcStep6];
+      iTmp2 = piSrcTmp[iSrcStep2]+piSrcTmp[iSrcStep5];
+      iTmp3 = piSrcTmp[iSrcStep3]+piSrcTmp[iSrcStep4];
+      
+      iTmpA = (iTmp3 << 2) - iTmp2;
+      
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;
+      
+      piDst   [x * iDstStep] = ClipY( (iSum +  2048) >>  12 );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int  iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStep3] + piSrcTmp[iSrcStep5];
+      iTmp2 = piSrcTmp[iSrcStep6] + piSrcTmp[iSrcStep4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+             - ( ( piSrcTmp[iSrcStep2] - iTmp2 ) << 1 )
+             + (  piSrcTmp[iSrcStep]             << 2 )
+             - ( ( piSrcTmp[iSrcStep2] + iTmp1 ) << 3 )
+             + (   piSrcTmp[iSrcStep4]           << 4 );
+      
+      piDst   [x * iDstStep] = ClipY(( (iSum +  32) >>  6 )+ piSrcTmp[iSrcStep3]);
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Hor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int  iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+    
+      iTmp1 = piSrcTmp[iSrcStep3] + piSrcTmp[iSrcStep5];
+      iTmp2 = piSrcTmp[iSrcStep6] + piSrcTmp[iSrcStep4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep2] - iTmp2 ) << 1 )
+            + (  piSrcTmp[iSrcStep]             << 2 )
+            - ( ( piSrcTmp[iSrcStep2] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep4]           << 4 )
+            + (   piSrcTmp[iSrcStep3]           << 6 );
+      
+      piDst   [x * iDstStep] = ClipY( (iSum +  2048) >>  12 );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Hor(Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStep4] + piSrcTmp[iSrcStep2];
+      iTmp2 = piSrcTmp[iSrcStep ] + piSrcTmp[iSrcStep3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStep6]           << 2 )
+            - ( ( piSrcTmp[iSrcStep5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep3]           << 4 );
+      
+      piDst   [x * iDstStep] = Clip( ((iSum +  32) >>  6) + piSrcTmp[iSrcStep4] );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Hor(Int* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+  Int iSrcStep2 = iSrcStep*2;
+  Int iSrcStep3 = iSrcStep*3;
+  Int iSrcStep4 = iSrcStep*4;
+  Int iSrcStep5 = iSrcStep*5;
+  Int iSrcStep6 = iSrcStep*6;
+  Int iSrcStep7 = iSrcStep*7;
+
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStep ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStep4] + piSrcTmp[iSrcStep2];
+      iTmp2 = piSrcTmp[iSrcStep ] + piSrcTmp[iSrcStep3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStep7]
+            - ( ( piSrcTmp[iSrcStep5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStep6]           << 2 )
+            - ( ( piSrcTmp[iSrcStep5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStep3]           << 4 )
+            + (   piSrcTmp[iSrcStep4]           << 6 );
+      
+      piDst   [x * iDstStep] = Clip( (iSum +  2048) >>  12 );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst, Int iDstStridePel, Pel*& rpiDstPel )
+{
+  Int*  piDst = rpiDst;
+  Pel*  piDstPel = rpiDstPel;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[          0]+piSrcTmp[iSrcStride7];
+      iTmp1 = piSrcTmp[iSrcStride ]+piSrcTmp[iSrcStride6];
+      iTmp2 = piSrcTmp[iSrcStride2]+piSrcTmp[iSrcStride5];
+      iTmp3 = piSrcTmp[iSrcStride3]+piSrcTmp[iSrcStride4];
+      
+      iTmpA = (iTmp3 << 2) - iTmp2;
+      
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;
+      
+      piDst[x * iDstStep]    = iSum;
+      piDstPel[x * iDstStep] = Clip( (iSum +  32) >>  6 );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+    piDstPel += iDstStridePel;
+  }
+ return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst)
+{
+  Int*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[          0]+piSrcTmp[iSrcStride7];
+      iTmp1 = piSrcTmp[iSrcStride ]+piSrcTmp[iSrcStride6];
+      iTmp2 = piSrcTmp[iSrcStride2]+piSrcTmp[iSrcStride5];
+      iTmp3 = piSrcTmp[iSrcStride3]+piSrcTmp[iSrcStride4];
+      
+      iTmpA = (iTmp3 << 2) - iTmp2;
+      
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;        
+      
+      piDst[x * iDstStep] = iSum;
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterHalfVer (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp0, iTmp1, iTmp2, iTmp3, iTmpA;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // { -1,4,-11,40,40,-11,4,-1   } 
+      iTmp0 = piSrcTmp[          0]+piSrcTmp[iSrcStride7];
+      iTmp1 = piSrcTmp[iSrcStride ]+piSrcTmp[iSrcStride6];
+      iTmp2 = piSrcTmp[iSrcStride2]+piSrcTmp[iSrcStride5];
+      iTmp3 = piSrcTmp[iSrcStride3]+piSrcTmp[iSrcStride4];
+      
+      iTmpA = (iTmp3 << 2) - iTmp2;
+      
+      iSum  = (   iTmp1          << 2 )
+            + (   iTmpA          << 3 )
+            + (   iTmpA          << 1 )
+            -    iTmp0 -  iTmp2;        
+      
+      piDst[x * iDstStep] = Clip( (iSum +  32) >>  6 );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst)
+{
+  Int*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStride3] + piSrcTmp[iSrcStride5];
+      iTmp2 = piSrcTmp[iSrcStride6] + piSrcTmp[iSrcStride4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStride7]
+            - ( ( piSrcTmp[iSrcStride2] - iTmp2 ) << 1 )
+            + (  piSrcTmp[iSrcStride]             << 2 )
+            - ( ( piSrcTmp[iSrcStride2] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStride4]           << 4 )
+            + (   piSrcTmp[iSrcStride3]           << 6 );
+      
+      piDst[x * iDstStep] = iSum;
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter0Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp1, iTmp2;
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      // {-1,   4,  -10,  57,   19,  -7,   3,   -1  },
+      
+      iTmp1 = piSrcTmp[iSrcStride3] + piSrcTmp[iSrcStride5];
+      iTmp2 = piSrcTmp[iSrcStride6] + piSrcTmp[iSrcStride4];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStride7]
+            - ( ( piSrcTmp[iSrcStride2] - iTmp2 ) << 1 )
+            + (  piSrcTmp[iSrcStride]             << 2 )
+            - ( ( piSrcTmp[iSrcStride2] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStride4]           << 4 );
+      
+      piDst[x * iDstStep] = Clip( ((iSum +  32) >>  6) + piSrcTmp[iSrcStride3] );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Int*& rpiDst)
+{
+  Int*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      /// {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      iTmp1 = piSrcTmp[iSrcStride4] + piSrcTmp[iSrcStride2];
+      iTmp2 = piSrcTmp[iSrcStride ] + piSrcTmp[iSrcStride3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStride7]
+            - ( ( piSrcTmp[iSrcStride5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStride6]           << 2 )
+            - ( ( piSrcTmp[iSrcStride5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStride3]           << 4 )
+            + (   piSrcTmp[iSrcStride4]           << 6 );
+            
+      piDst[x * iDstStep] = iSum;
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_FilterQuarter1Ver (Pel* piSrc, Int iSrcStride, Int iSrcStep, Int iWidth, Int iHeight, Int iDstStride, Int iDstStep, Pel*& rpiDst)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int iSrcStride2 = iSrcStride*2;
+  Int iSrcStride3 = iSrcStride*3;
+  Int iSrcStride4 = iSrcStride*4;
+  Int iSrcStride5 = iSrcStride*5;
+  Int iSrcStride6 = iSrcStride*6;
+  Int iSrcStride7 = iSrcStride*7;
+
+  Int  iTmp1, iTmp2;
+
+  for ( Int y = iHeight; y != 0; y-- )
+  {
+    piSrcTmp = &piSrc[ -3*iSrcStride ];
+    for ( Int x = 0; x < iWidth; x++ )
+    {
+      /// {-1,   3,  -7,  19,   57,  -10,   4,   -1  },
+      iTmp1 = piSrcTmp[iSrcStride4] + piSrcTmp[iSrcStride2];
+      iTmp2 = piSrcTmp[iSrcStride ] + piSrcTmp[iSrcStride3];
+      
+      iSum  =  iTmp1 + iTmp2 - piSrcTmp[0] - piSrcTmp[iSrcStride7]
+            - ( ( piSrcTmp[iSrcStride5] - iTmp2 ) << 1 )
+            + (   piSrcTmp[iSrcStride6]           << 2 )
+            - ( ( piSrcTmp[iSrcStride5] + iTmp1 ) << 3 )
+            + (   piSrcTmp[iSrcStride3]           << 4 );
+            
+      piDst[x * iDstStep] = Clip( ((iSum +  32) >>  6) +  piSrcTmp[iSrcStride4] );
+      piSrcTmp += iSrcStep;
+    }
+    piSrc += iSrcStride;
+    piDst += iDstStride;
+  }
+  return;
+}
+
+// ------------------------------------------------------------------------------------------------
+// DCTIF filters for Chroma
+// ------------------------------------------------------------------------------------------------
+__inline Void TRenInterpFilter::xCTI_Filter2DVerC (Pel* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Int*& rpiDst, Int iMV)
+{
+  Int*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT0( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA0( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:  
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA1( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:  
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT1( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT2( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT3( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4: 
+  {
+
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VPS04_C_HAL( piSrcTmp, iSrcStride );
+          piDst[x ] = iSum;
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_Filter2DHorC(Int* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT0( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_QUA0( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_QUA1( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT1( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT2( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT3( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4:
+  {
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VIS04_C_HAL( piSrcTmp, 1 );
+          piDst   [x ] = Clip ((iSum +  2048) >>  12 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+  }
+
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_Filter1DVerC (Pel* piSrc, Int iSrcStride, Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT0( piSrcTmp,  iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA0( piSrcTmp,  iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA1( piSrcTmp,  iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT1( piSrcTmp,  iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT2( piSrcTmp,  iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT3( piSrcTmp,  iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4:
+  {
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[-iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VPS04_C_HAL( piSrcTmp, iSrcStride );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+  }
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_Filter1DHorC(Pel* piSrc, Int iSrcStride, Int iWidth, Int iHeight, Int iDstStride, Pel*& rpiDst, Int iMV)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_OCT0( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_QUA0( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_QUA1( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_OCT1( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_OCT2( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_OCT3( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4:
+  {
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VPS04_C_HAL( piSrcTmp,  1 );
+          piDst[x ] = Clip ((iSum +  32) >>  6 );
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+ }
+  return;
+}
+
+#if HIGH_ACCURACY_BI
+__inline Void TRenInterpFilter::xCTI_Filter2DHorC_ha(Int* piSrc, Int iSrcStride,  Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Int*  piSrcTmp;
+  Int shiftNum  = 6 + g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT0( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_QUA0( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_QUA1( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT1( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT2( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VI04_C_OCT3( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4:
+  {
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VIS04_C_HAL( piSrcTmp, 1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+  }
+
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_Filter1DVerC_ha (Pel* piSrc, Int iSrcStride, Int iWidth, Int iHeight, Int iDstStride,  Pel*& rpiDst, Int iMV)
+{
+  Pel*  piDst = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int shiftNum  = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+    
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT0( piSrcTmp,  iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA0( piSrcTmp,  iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA1( piSrcTmp,  iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT1( piSrcTmp,  iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT2( piSrcTmp,  iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT3( piSrcTmp,  iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4:
+  {
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[-iSrcStride ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VPS04_C_HAL( piSrcTmp, iSrcStride );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+  }    
+  return;
+}
+
+__inline Void TRenInterpFilter::xCTI_Filter1DHorC_ha(Pel* piSrc, Int iSrcStride, Int iWidth, Int iHeight, Int iDstStride, Pel*& rpiDst, Int iMV)
+{
+  Pel*  piDst    = rpiDst;
+  Int   iSum;
+  Pel*  piSrcTmp;
+  Int shiftNum  = g_uiBitIncrement + g_uiBitDepth - 8;
+  Int shiftOffset = (shiftNum > 0) ? ( 1 << (shiftNum - 1)) : 0 ;
+
+  switch (iMV)
+  {
+  case 1:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT0( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 2:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_QUA0( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 6:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_QUA1( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 3:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum      = xCTI_Filter_VP04_C_OCT1( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 5:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_OCT2( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 7:
+  {  
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum         = xCTI_Filter_VP04_C_OCT3( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  case 4:
+  {
+      for ( Int y = iHeight; y != 0; y-- )
+      {
+        piSrcTmp = &piSrc[ -1 ];
+        for ( Int x = 0; x < iWidth; x++ )
+        {
+          iSum    = xCTI_Filter_VPS04_C_HAL( piSrcTmp,  1 );
+#if REMOVE_INTERMEDIATE_CLIPPING
+          piDst[x ] = (iSum +  shiftOffset) >>  shiftNum;
+#else
+          piDst[x ] = Clip3(0,16383, (iSum +  shiftOffset) >>  shiftNum );
+#endif
+          piSrcTmp++;
+        }
+        piSrc += iSrcStride;
+        piDst += iDstStride;
+      }
+  }
+  break;
+  default:
+    assert( 0 );
+
+ }
+  return;
+}
+#endif
+
+
+__inline Int TRenInterpFilter::xCTI_Filter_VP04_C_OCT0( Pel* pSrc,  Int iStride )
+{// {  -3,  60,   8,   -1,} // 1/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p1<<6) -((p1+p0)<<2) +p0 +(p2<<3) -p3;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VI04_C_OCT0( Int* pSrc, Int iStride )
+{ // {  -3,  60,   8,   -1,} //1/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p1<<6) -((p1+p0)<<2) +p0 +(p2<<3) -p3;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VP04_C_QUA0( Pel* pSrc,  Int iStride )
+{// {  -4,  54,  16,   -2,} // 1/4
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p1 << 6) + (p2 << 4) - (p1 << 3) - ( p0 << 2) - ((p1 + p3) << 1);
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VI04_C_QUA0( Int* pSrc, Int iStride )
+{ // {  -4,  54,  16,   -2,} //1/4
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p1 << 6) + (p2 << 4) - (p1 << 3) - ( p0 << 2) - ((p1 + p3) << 1);
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VP04_C_QUA1( Pel* pSrc,  Int iStride )
+{// {  -2,  16,  54,   -4,}// 3/4
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p2 << 6) + (p1 << 4) - (p2 << 3) - ( p3 << 2) - ((p2 + p0) << 1);
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VI04_C_QUA1( Int* pSrc, Int iStride )
+{// {  -2,  16,  54,   -4,}// 3/4
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p2 << 6) + (p1 << 4) - (p2 << 3) - ( p3 << 2) - ((p2 + p0) << 1);
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VP04_C_OCT1( Pel* pSrc,  Int iStride )
+{// {  -5,  46,  27,   -4,} // 3/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  Int t = p0 + p2;
+  iSum = ((p1 + p2) << 5) + (p1 << 4) - ( (t + p3) << 2) - ( p1 << 1) - t;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VI04_C_OCT1( Int* pSrc, Int iStride )
+{ // {  -5,  46,  27,   -4,} //3/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  Int t = p0 + p2;
+  iSum = ((p1 + p2) << 5) + (p1 << 4) - ( (t + p3) << 2) - ( p1 << 1) - t;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VPS04_C_HAL( Pel* pSrc, Int iStride )
+{
+  // {  -4,  36,  36,   -4,}, // 1/2
+  Int iSum;
+  Int iTemp0 = pSrc[iStride*1]+pSrc[iStride*2];
+  Int iTemp1 = pSrc[        0]+pSrc[iStride*3];
+
+  iSum  = ((iTemp0<<3) + iTemp0 -iTemp1)<<2;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VIS04_C_HAL( Int* pSrc, Int iStride )
+{
+  // {  -4,  36,  36,   -4,}, //1/2
+  Int iSum;
+  Int iTemp0 = pSrc[iStride*1]+pSrc[iStride*2];
+  Int iTemp1 = pSrc[        0]+pSrc[iStride*3];
+
+  iSum  = ((iTemp0<<3) + iTemp0 -iTemp1)<<2;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VP04_C_OCT2( Pel* pSrc,  Int iStride )
+{// {  -4,  27,  46,   -5,}, // 5/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  Int t = p1 + p3;
+  iSum = ((p1 + p2) << 5) + (p2 << 4) - ( (t + p0) << 2) - ( p2 << 1) - t;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VI04_C_OCT2( Int* pSrc, Int iStride )
+{ // {  -4,  27,  46,   -5,}, // 5/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  Int t = p1 + p3;
+  iSum = ((p1 + p2) << 5) + (p2 << 4) - ( (t + p0) << 2) - ( p2 << 1) - t;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VP04_C_OCT3( Pel* pSrc,  Int iStride )
+{// {  -1,   8,  60,   -3,} // 7/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p2<<6) -((p2+p3)<<2) +p3 +(p1<<3) -p0;
+
+  return iSum;
+}
+__inline Int TRenInterpFilter::xCTI_Filter_VI04_C_OCT3( Int* pSrc, Int iStride )
+{ // {  -1,   8,  60,   -3,} // 7/8
+  Int iSum, iIdx = 0;
+
+  Int p0 = pSrc[0];     iIdx+= iStride;
+  Int p1 = pSrc[iIdx];  iIdx+= iStride;
+  Int p2 = pSrc[iIdx];  iIdx+= iStride;
+  Int p3 = pSrc[iIdx];  
+  iSum = (p2<<6) -((p2+p3)<<2) +p3 +(p1<<3) -p0;
+
+  return iSum;
+}
+
+#endif // __TRENINTERP__
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.cpp	(revision 438)
@@ -0,0 +1,453 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "TRenImage.h"
+#include "TRenFilter.h"
+#include "TRenModSetupStrParser.h"
+#if !QC_MVHEVC_B0046
+Int
+TRenModSetupStrParser::getNumOfModels()
+{
+  return m_iNumberOfModels;
+}
+
+Int
+TRenModSetupStrParser::getNumOfBaseViews()
+{
+  return (Int) m_aiAllBaseViewIdx  .size();
+}
+
+Int
+TRenModSetupStrParser::getNumOfModelsForView( Int iViewIdx, Int iContent )
+{
+  return (Int) m_aaaiModelNums[iContent][iViewIdx].size();
+}
+
+Int
+TRenModSetupStrParser::getNumOfBaseViewsForView( Int iViewIdx, Int iContent )
+{
+  return (Int) m_aaaiBaseViewsIdx[iContent][iViewIdx].size();
+}
+
+Void
+TRenModSetupStrParser::getSingleModelData( Int iSrcViewIdx,
+                                           Int iSrcCnt,
+                                           Int iCurModel,
+                                           Int& riModelNum,
+                                           Int& riBlendMode,
+                                           Int& riLeftBaseViewIdx,
+                                           Int& riRightBaseViewIdx,
+                                           Int& riOrgRefBaseViewIdx,
+                                           Int& riSynthViewRelNum )
+{
+  Bool bExtrapolate    = m_aaabExtrapolate[iSrcCnt][iSrcViewIdx][iCurModel];
+  Bool bOrgRef         = m_aaabOrgRef     [iSrcCnt][iSrcViewIdx][iCurModel];
+
+  riOrgRefBaseViewIdx = bOrgRef ? m_aaaiSynthViewNums[iSrcCnt][iSrcViewIdx][iCurModel] / ( (Int) VIEW_NUM_PREC ) : -1;
+  riSynthViewRelNum    = m_aaaiSynthViewNums[iSrcCnt][iSrcViewIdx][iCurModel];
+  riModelNum           = m_aaaiModelNums    [iSrcCnt][iSrcViewIdx][iCurModel];
+  riBlendMode          = m_aaaiBlendMode    [iSrcCnt][iSrcViewIdx][iCurModel];
+
+
+  Int iSrcViewNum = iSrcViewIdx * ((Int) VIEW_NUM_PREC );
+  if ( iSrcViewNum < riSynthViewRelNum )
+  {
+    riLeftBaseViewIdx  = iSrcViewIdx;
+    riRightBaseViewIdx = -1;
+  }
+  else
+  {
+    riLeftBaseViewIdx = -1;
+    riRightBaseViewIdx  = iSrcViewIdx;
+  }
+
+  if ( !bExtrapolate )
+  {
+    std::vector<Int> cCurBaseViews = m_aaaiBaseViewsIdx[iSrcCnt][iSrcViewIdx];
+
+    Int iMinDist = MAX_INT;
+    Int iNearestNum = -1;
+
+    for (Int iCurBaseView = 0; iCurBaseView < cCurBaseViews.size(); iCurBaseView++ )
+    {
+      Int iCurBaseNum = m_aaaiBaseViewsIdx [iSrcCnt][iSrcViewIdx][iCurBaseView];
+
+      if ( iCurBaseNum == iSrcViewNum )
+        continue;
+
+      Int iDist = iCurBaseNum - riSynthViewRelNum;
+
+      if ( ( iDist <= 0  && riLeftBaseViewIdx == -1) || ( iDist >= 0  && riRightBaseViewIdx == -1 ) )
+      {
+        if ( abs(iDist) < iMinDist )
+        {
+          iMinDist = abs(iDist);
+          iNearestNum = iCurBaseNum;
+        }
+      }
+    }
+    xError(iNearestNum == -1);
+
+    if (riLeftBaseViewIdx == -1 )
+    {
+      riLeftBaseViewIdx = iNearestNum / (Int) (VIEW_NUM_PREC);
+    }
+    else
+    {
+      riRightBaseViewIdx = iNearestNum / (Int) (VIEW_NUM_PREC);
+    }
+
+    xError(riLeftBaseViewIdx  == -1 );
+    xError(riRightBaseViewIdx == -1 );
+    xError(riLeftBaseViewIdx  >= riRightBaseViewIdx );
+  }
+}
+
+Void
+TRenModSetupStrParser::getBaseViewData( Int iSourceViewIdx, Int iSourceContent, Int iCurView, Int& riBaseViewSIdx, Int& riVideoDistMode, Int& riDepthDistMode )
+{
+  riBaseViewSIdx = m_aaaiBaseViewsIdx  [iSourceContent][iSourceViewIdx][iCurView] / (Int) VIEW_NUM_PREC;
+  riVideoDistMode            = m_aaaiVideoDistMode [iSourceContent][iSourceViewIdx][iCurView];
+  riDepthDistMode            = m_aaaiDepthDistMode [iSourceContent][iSourceViewIdx][iCurView];
+}
+
+TRenModSetupStrParser::TRenModSetupStrParser()
+{
+  m_pchSetStr       = NULL;
+  m_iPosInStr       = 0;
+  m_iNumberOfModels = 0;
+  m_bCurrentViewSet = false;
+}
+
+Void
+TRenModSetupStrParser::setString( Int iNumOfBaseViews, Char* pchSetStr )
+{
+  for (Int iContent = 0; iContent < 2; iContent++)
+  {
+    m_aaaiBaseViewsIdx  [iContent].resize( iNumOfBaseViews );
+    m_aaaiDepthDistMode [iContent].resize( iNumOfBaseViews );
+    m_aaaiVideoDistMode [iContent].resize( iNumOfBaseViews );
+    m_aaaiSynthViewNums [iContent].resize( iNumOfBaseViews );
+    m_aaaiModelNums     [iContent].resize( iNumOfBaseViews );
+    m_aaabOrgRef        [iContent].resize( iNumOfBaseViews );
+    m_aaabExtrapolate   [iContent].resize( iNumOfBaseViews );
+    m_aaaiBlendMode     [iContent].resize( iNumOfBaseViews );
+  }
+
+  AOT( m_pchSetStr );
+  m_pchSetStr = pchSetStr;
+  m_iPosInStr       = 0;
+  m_bCurrentViewSet = false;
+
+  xParseString();
+}
+
+Void
+TRenModSetupStrParser::xParseString()
+{
+  Char cChar;
+  xGetNextChar(cChar);
+  while(  cChar != '\0' )
+  {
+    xParseSourceView();
+    xGetNextChar(cChar);
+  }
+  // CHECK
+  size_t iNumOfSrcViews = m_aaaiBaseViewsIdx[0].size();
+
+  for (Int iSrcView = 0; iSrcView < iNumOfSrcViews; iSrcView++)
+  {
+    for (Int iContent = 0; iContent < 2; iContent++ )
+    {
+      size_t iNumOfBase  = m_aaaiBaseViewsIdx  [iContent][iSrcView].size();
+      AOF( iNumOfBase   == m_aaaiDepthDistMode [iContent][iSrcView].size());
+      AOF( iNumOfBase   == m_aaaiVideoDistMode [iContent][iSrcView].size());
+
+      size_t iNumOfModels = m_aaaiSynthViewNums[iContent][iSrcView].size();
+      AOF( iNumOfModels == m_aaaiModelNums     [iContent][iSrcView].size());
+      AOF( iNumOfModels == m_aaabOrgRef        [iContent][iSrcView].size());
+      AOF( iNumOfModels == m_aaabExtrapolate   [iContent][iSrcView].size());
+    }
+  }
+
+  // SORT
+  std::vector<Int>::iterator cIterNewEnd;
+
+  std::sort( m_aiAllBaseViewIdx.begin(), m_aiAllBaseViewIdx.end() );
+  cIterNewEnd = std::unique( m_aiAllBaseViewIdx.begin(), m_aiAllBaseViewIdx.end() );
+  m_aiAllBaseViewIdx.erase( cIterNewEnd, m_aiAllBaseViewIdx.end() );
+
+  std::sort( m_aiAllSynthViewNums.begin(), m_aiAllSynthViewNums.end() );
+  cIterNewEnd = std::unique( m_aiAllSynthViewNums.begin(), m_aiAllSynthViewNums.end() );
+  m_aiAllSynthViewNums.erase( cIterNewEnd, m_aiAllSynthViewNums.end() );
+}
+
+Void
+TRenModSetupStrParser::xParseSourceView()
+{
+  m_bCurrentViewSet = false;
+
+  Char cChar;
+  xGetNextCharGoOn( cChar );
+  xError( cChar != '[' );
+  xReadViewInfo('B');
+
+  Bool bContinueReading = true;
+  while( bContinueReading )
+  {
+    xGetNextCharGoOn( cChar );
+    switch ( cChar )
+    {
+    case 'B':
+    case 'I':
+    case 'E':
+    case 'L':
+    case 'R':
+      xReadViews( cChar );
+      break;
+    case ']':
+      bContinueReading = false;
+      break;
+    default:
+      xError(true);
+      break;
+    }
+  }
+}
+
+Void
+TRenModSetupStrParser::xReadViews( Char cType )
+{
+  Char cChar;
+  xGetNextCharGoOn( cChar );
+  xError( cChar != '(' );
+
+  Bool bContinue = true;
+  while ( bContinue )
+  {
+    xGetNextChar( cChar );
+    if (cChar == ')')
+    {
+      xGetNextCharGoOn( cChar );
+      bContinue = false;
+    }
+    else
+    {
+      xReadViewInfo( cType );
+    }
+  }
+}
+
+Void
+TRenModSetupStrParser::xReadViewInfo( Char cType )
+{
+  std::vector<Int> aiViewNums;
+  aiViewNums.clear();
+
+  switch ( cType )
+  {
+  case 'B':
+    Char cVideoType;
+    Char cDepthType;
+
+    xGetNextCharGoOn   ( cVideoType );
+    xGetNextCharGoOn   ( cDepthType );
+    xGetViewNumberRange( aiViewNums );
+
+    if ( !m_bCurrentViewSet )
+    {
+      xError( aiViewNums.size() != 1 );
+      m_iCurrentView = aiViewNums[0] / (Int) VIEW_NUM_PREC;
+      if      ( cVideoType == 'x' )
+      {
+        m_iCurrentContent = 0;
+        m_bCurrentViewSet = true;
+      }
+      else if ( cDepthType == 'x' )
+      {
+        m_iCurrentContent = 1;
+        m_bCurrentViewSet = true;
+      }
+      else
+      {
+        xError( true );
+      }
+    }
+
+    for ( Int iIdx = 0; iIdx < aiViewNums.size(); iIdx++ )
+    {
+      xAddBaseView( aiViewNums[iIdx], cVideoType, cDepthType );
+    }
+    break;
+
+  case 'E':
+  case 'I':
+  case 'L':
+  case 'R':
+    Char cRefType;
+    xGetNextCharGoOn   ( cRefType   );
+    xGetViewNumberRange( aiViewNums );
+    for ( Int iIdx = 0; iIdx < aiViewNums.size(); iIdx++ )
+    {
+      xAddSynthView( aiViewNums[iIdx], cType, cRefType );
+    }
+  }
+}
+
+Void
+TRenModSetupStrParser::xAddBaseView( Int iViewIdx, Char cVideoType, Char cDepthType )
+{
+  AOF( m_bCurrentViewSet );
+
+  if ( cDepthType == 'x' ) cDepthType = 'o';
+  if ( cVideoType == 'x' ) cVideoType = 'o';
+
+
+
+  xError( cDepthType != 'o' && cDepthType != 'c' && cVideoType != 'r' );
+  xError( cVideoType != 'o' && cVideoType != 'c' && cVideoType != 'r' );
+  m_aiAllBaseViewIdx.push_back( iViewIdx );
+  m_aaaiBaseViewsIdx  [m_iCurrentContent][m_iCurrentView].push_back( iViewIdx          );
+  m_aaaiVideoDistMode [m_iCurrentContent][m_iCurrentView].push_back( ( cVideoType == 'c' ) ? 2 : ( (cVideoType == 'r') ? 1 :  0 ) );
+  m_aaaiDepthDistMode [m_iCurrentContent][m_iCurrentView].push_back( ( cDepthType == 'c' ) ? 2 : ( (cDepthType == 'r') ? 1 :  0 ) );
+}
+
+Void
+TRenModSetupStrParser::xAddSynthView( Int iViewNum, Char cType, Char cRefType )
+{
+  AOF( m_bCurrentViewSet );
+
+  xError( cRefType != 's' && cRefType != 'o' );
+
+  m_aiAllSynthViewNums.push_back( iViewNum );
+
+  Int iBlendMode;
+  switch ( cType )
+  {
+  case 'E':
+    iBlendMode = BLEND_NONE;
+    break;
+  case 'I':
+    iBlendMode = BLEND_AVRG;
+    break;
+  case 'L':
+    iBlendMode = BLEND_LEFT;
+    break;
+  case 'R':
+    iBlendMode = BLEND_RIGHT;
+    break;
+  default:
+    xError(false);
+    break;
+  }
+
+  m_aaaiBlendMode    [m_iCurrentContent][m_iCurrentView].push_back( iBlendMode        );
+  m_aaaiSynthViewNums[m_iCurrentContent][m_iCurrentView].push_back( iViewNum          );
+  m_aaabExtrapolate  [m_iCurrentContent][m_iCurrentView].push_back( cType    == 'E'   );
+  m_aaabOrgRef       [m_iCurrentContent][m_iCurrentView].push_back( cRefType == 'o'   );
+  m_aaaiModelNums    [m_iCurrentContent][m_iCurrentView].push_back( m_iNumberOfModels );
+
+  m_iNumberOfModels++;
+}
+
+Void
+TRenModSetupStrParser::xError( Bool bIsError )
+{
+  if ( bIsError )
+  {
+    std::cout << "RenModel setup string invalid. Last character read: " << m_iPosInStr << std::endl;
+    AOF( false );
+    exit(0);
+  }
+}
+
+Void
+TRenModSetupStrParser::xGetViewNumberRange( std::vector<Int>& raiViewNumbers )
+{
+  size_t iStartPos;
+  size_t iEndPos;
+  Char cChar;
+  xGetNextCharGoOn(cChar );
+  if (cChar == '{')
+  {
+    iStartPos = m_iPosInStr;
+    while( m_pchSetStr[m_iPosInStr] != '}' )
+    {
+      xError( m_iPosInStr == '\0' );
+      m_iPosInStr++;
+    }
+    iEndPos = m_iPosInStr - 1;
+    m_iPosInStr++;
+  }
+  else
+  {
+    iStartPos = m_iPosInStr - 1;
+    while( m_pchSetStr[m_iPosInStr] != ' ' && m_pchSetStr[m_iPosInStr] != ',' && m_pchSetStr[m_iPosInStr] != ')' )
+    {
+      xError( m_iPosInStr == '\0' );
+      m_iPosInStr++;
+    }
+    iEndPos = m_iPosInStr - 1;
+  }
+
+  size_t iNumElem = iEndPos - iStartPos + 1;
+  Char* pcTempBuffer = new Char[  iNumElem + 1];
+  strncpy( pcTempBuffer, m_pchSetStr + iStartPos, iNumElem );
+  pcTempBuffer[iNumElem] = '\0';
+
+  TAppComCamPara::convertNumberString( pcTempBuffer, raiViewNumbers, VIEW_NUM_PREC );
+  delete[] pcTempBuffer;
+}
+
+Void
+TRenModSetupStrParser::xGetNextCharGoOn( Char& rcNextChar )
+{
+  while ( m_pchSetStr[m_iPosInStr] == ' ' || m_pchSetStr[m_iPosInStr] == ',' )
+  {
+    xError( m_pchSetStr[m_iPosInStr] == '\0' );
+    m_iPosInStr++;
+  }
+  rcNextChar = m_pchSetStr[m_iPosInStr];
+  m_iPosInStr++;
+}
+
+Void
+TRenModSetupStrParser::xGetNextChar( Char& rcNextChar )
+{
+  size_t iPos = m_iPosInStr;
+  while ( ( m_pchSetStr[iPos] == ' ' || m_pchSetStr[iPos] == ',' ) && m_pchSetStr[iPos] != '\0' ) iPos++;
+  rcNextChar = m_pchSetStr[iPos];
+}
+#endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModSetupStrParser.h	(revision 438)
@@ -0,0 +1,130 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#if !QC_MVHEVC_B0046
+#ifndef __TRENMODSETUPSTRPARSER__
+#define __TRENMODSETUPSTRPARSER__
+
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPicYuv.h"
+#include "../TLibCommon/TypeDef.h"
+#include "../TAppCommon/TAppComCamPara.h"
+
+
+#include <list>
+#include <vector>
+#include <math.h>
+#include <errno.h>
+#include <vector>
+#include <iostream>
+#include <algorithm>
+#include <functional>
+#include <string>
+#include <cstdio>
+#include <cstring>
+
+
+using namespace std;
+
+class TRenModSetupStrParser
+{
+public:
+
+  Int  getNumOfModels          ();
+  Int  getNumOfBaseViews       ();
+
+  Int  getNumOfModelsForView   ( Int iViewIdx, Int iContent );
+  Int  getNumOfBaseViewsForView( Int iViewIdx, Int iContent );
+
+  Void getSingleModelData      ( Int  iSrcViewIdx,
+                                 Int  iSrcCnt,
+                                 Int  iCurModel,
+                                 Int& riModelNum,
+                                 Int& riInterpolationType,
+                                 Int& riLeftBaseViewIdx,
+                                 Int& riRightBaseViewIdx,
+                                 Int& riOrgRefBaseViewIdx,
+                                 Int& riSynthViewRelNum
+                               );
+
+  Void getBaseViewData         ( Int   iSourceViewIdx,
+                                 Int   iSourceContent,
+                                 Int   iCurView,
+                                 Int&  riBaseViewSIdx,
+                                 Int&  riVideoDistMode,
+                                 Int&  riDepthDistMode
+                                );
+
+  std::vector<Int>* getSynthViews() { return &m_aiAllSynthViewNums;  }
+  std::vector<Int>* getBaseViews()  { return &m_aiAllBaseViewIdx;    }
+
+  TRenModSetupStrParser();
+
+  Void setString( Int iNumOfBaseViews, Char* pchSetStr );
+
+private:
+  std::vector< std::vector<Int > > m_aaaiBaseViewsIdx  [2];
+  std::vector< std::vector<Int > > m_aaaiVideoDistMode [2];
+  std::vector< std::vector<Int > > m_aaaiDepthDistMode [2];
+  std::vector< std::vector<Int > > m_aaaiModelNums     [2];
+  std::vector< std::vector<Int > > m_aaaiSynthViewNums [2];
+  std::vector< std::vector<Bool> > m_aaabOrgRef        [2];
+  std::vector< std::vector<Bool> > m_aaabExtrapolate   [2];
+  std::vector< std::vector<Int > > m_aaaiBlendMode     [2];
+
+  std::vector<Int>                 m_aiAllBaseViewIdx;
+  std::vector<Int>                 m_aiAllSynthViewNums;
+
+  Bool                             m_bCurrentViewSet;
+  Int                              m_iCurrentView;
+  Int                              m_iCurrentContent;
+  Int                              m_iNumberOfModels;
+
+  Char*                            m_pchSetStr;
+  size_t                           m_iPosInStr;
+
+private:
+  Void xParseString();
+  Void xParseSourceView();
+  Void xReadViews         ( Char cType );
+  Void xReadViewInfo      ( Char cType );
+  Void xAddBaseView       ( Int iViewIdx, Char cVideoType, Char cDepthType );
+  Void xAddSynthView      ( Int iViewNum, Char cType, Char cRefType );
+  Void xError             ( Bool bIsError );
+  Void xGetViewNumberRange( std::vector<Int>& raiViewNumbers );
+  Void xGetNextCharGoOn   ( Char& rcNextChar );
+  Void xGetNextChar       ( Char& rcNextChar );
+};
+
+#endif //__TRENMODEL__
+#endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModel.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModel.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModel.cpp	(revision 438)
@@ -0,0 +1,700 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "TRenImage.h"
+#include "TRenFilter.h"
+#include "TRenModel.h"
+#if !QC_MVHEVC_B0046
+///////////  TRENMODEL //////////////////////
+TRenModel::TRenModel()
+{
+  m_iPad               = PICYUV_PAD;
+  m_iWidth             = -1;
+  m_iHeight            = -1;
+  m_iUsedHeight        = -1; 
+  m_iNumOfBaseViews    = -1;
+  m_iSampledWidth      = -1;
+  m_iShiftPrec         =  0;
+  m_iHoleMargin        =  1;
+  m_uiHorOff           = -1;
+#if LGE_VSO_EARLY_SKIP_A0093
+  m_bEarlySkip         = false; 
+#endif
+
+  // Current Error Type ///
+  m_iCurrentView       = -1;
+  m_iCurrentContent    = -1;
+  m_iCurrentPlane      = -1;
+
+  // Array of Models used to determine the Current Error ///
+  m_iNumOfCurRenModels = -1;
+  m_apcCurRenModels    = NULL;
+  m_aiCurPosInModels   = NULL;
+
+  // Array of Models ///
+  m_iNumOfRenModels    = -1;
+  m_apcRenModels       = NULL;
+
+  // Mapping from View number to models ///
+  m_aiNumOfModelsForDepthView = NULL;
+  m_aapcRenModelForDepthView  = NULL;
+  m_aaePosInModelForDepthView = NULL;
+
+  m_aiNumOfModelsForVideoView = NULL;
+  m_aapcRenModelForVideoView  = NULL;
+  m_aaePosInModelForVideoView = NULL;
+  m_aaeBaseViewPosInModel     = NULL;
+
+  // Data
+  m_aapiCurVideoPel      = NULL;
+  m_aaiCurVideoStrides   = NULL;
+  m_apiCurDepthPel       = NULL;
+  m_aiCurDepthStrides    = NULL;
+
+  m_aapiOrgVideoPel      = NULL;
+  m_aaiOrgVideoStrides   = NULL;
+  m_apiOrgDepthPel       = NULL;
+  m_aiOrgDepthStrides    = NULL;
+
+  m_aaaiSubPelShiftLut[0]= NULL;
+  m_aaaiSubPelShiftLut[1]= NULL;
+
+  /// Current Setup data ///
+  m_abSetupVideoFromOrgForView = NULL;
+  m_abSetupDepthFromOrgForView = NULL;
+}
+
+TRenModel::~TRenModel()
+{
+  if ( m_apcRenModels )
+  {
+    for (Int iNumModel = 0; iNumModel < m_iNumOfRenModels; iNumModel++)
+    {
+      if ( m_apcRenModels[iNumModel] ) delete m_apcRenModels[iNumModel];
+    }
+
+    delete[] m_apcRenModels;
+  }
+
+  for (Int iViewNum = 0; iViewNum < m_iNumOfBaseViews; iViewNum++)
+  {
+    if ( m_aapcRenModelForDepthView && m_aapcRenModelForDepthView [iViewNum] )
+    {
+      delete[]   m_aapcRenModelForDepthView [iViewNum];
+    }
+
+    if ( m_aaePosInModelForDepthView && m_aaePosInModelForDepthView[iViewNum] )
+    {
+      delete[]   m_aaePosInModelForDepthView[iViewNum];
+    }
+
+    if ( m_aapcRenModelForVideoView && m_aapcRenModelForVideoView[iViewNum] )
+    {
+      delete[]   m_aapcRenModelForVideoView[iViewNum];
+    }
+
+    if ( m_aaePosInModelForVideoView && m_aaePosInModelForVideoView[iViewNum] )
+    {
+      delete[]   m_aaePosInModelForVideoView[iViewNum];
+    }
+
+    if ( m_aaeBaseViewPosInModel && m_aaeBaseViewPosInModel[iViewNum] )
+    {
+      delete[]   m_aaeBaseViewPosInModel[iViewNum];
+    }
+
+    if ( m_aapiCurVideoPel && m_aapiCurVideoPel    [iViewNum] )
+    {
+      delete[] ( m_aapiCurVideoPel    [iViewNum][0] - m_iPad * m_aaiCurVideoStrides[iViewNum][0] - m_iPad );
+      delete[] ( m_aapiCurVideoPel    [iViewNum][1] - m_iPad * m_aaiCurVideoStrides[iViewNum][1] - m_iPad );
+      delete[] ( m_aapiCurVideoPel    [iViewNum][2] - m_iPad * m_aaiCurVideoStrides[iViewNum][2] - m_iPad );
+      delete[]   m_aapiCurVideoPel    [iViewNum];
+    }
+
+    if ( m_aaiCurVideoStrides && m_aaiCurVideoStrides [iViewNum] )
+    {
+      delete[]   m_aaiCurVideoStrides [iViewNum];
+    }
+
+    if ( m_apiCurDepthPel )
+    {
+      delete[] ( m_apiCurDepthPel     [iViewNum]    - m_iPad * m_aiCurDepthStrides [iViewNum]    - m_iPad );
+    }
+
+    if ( m_aapiOrgVideoPel && m_aapiOrgVideoPel    [iViewNum] )
+    {
+      delete[] ( m_aapiOrgVideoPel    [iViewNum][0] - m_iPad * m_aaiOrgVideoStrides[iViewNum][0] - m_iPad );
+      delete[] ( m_aapiOrgVideoPel    [iViewNum][1] - m_iPad * m_aaiOrgVideoStrides[iViewNum][1] - m_iPad );
+      delete[] ( m_aapiOrgVideoPel    [iViewNum][2] - m_iPad * m_aaiOrgVideoStrides[iViewNum][2] - m_iPad );
+      delete[]   m_aapiOrgVideoPel    [iViewNum];
+    }
+
+    if ( m_aaiOrgVideoStrides && m_aaiOrgVideoStrides [iViewNum] )
+    {
+      delete[]   m_aaiOrgVideoStrides [iViewNum];
+    }
+
+    if ( m_apiOrgDepthPel && m_apiOrgDepthPel     [iViewNum ] )
+    {
+      delete[] ( m_apiOrgDepthPel     [iViewNum]    - m_iPad * m_aiOrgDepthStrides [iViewNum]    - m_iPad );
+    }
+  }
+
+  if(m_aiNumOfModelsForDepthView) delete[] m_aiNumOfModelsForDepthView;
+  if(m_aapcRenModelForDepthView ) delete[] m_aapcRenModelForDepthView ;
+  if(m_aaePosInModelForDepthView) delete[] m_aaePosInModelForDepthView;
+
+  if(m_aiNumOfModelsForVideoView) delete[] m_aiNumOfModelsForVideoView;
+  if(m_aapcRenModelForVideoView ) delete[] m_aapcRenModelForVideoView ;
+  if(m_aaePosInModelForVideoView) delete[] m_aaePosInModelForVideoView;
+
+
+  if(m_aaeBaseViewPosInModel    ) delete[] m_aaeBaseViewPosInModel    ;
+  if(m_aapiCurVideoPel          ) delete[] m_aapiCurVideoPel          ;
+  if(m_aaiCurVideoStrides       ) delete[] m_aaiCurVideoStrides       ;
+
+  if(m_abSetupVideoFromOrgForView) delete[] m_abSetupVideoFromOrgForView;
+  if(m_abSetupDepthFromOrgForView) delete[] m_abSetupDepthFromOrgForView;
+
+  if(m_aapiOrgVideoPel          ) delete[] m_aapiOrgVideoPel          ;
+  if(m_aaiOrgVideoStrides       ) delete[] m_aaiOrgVideoStrides       ;
+
+  if(m_apiOrgDepthPel           ) delete[] m_apiOrgDepthPel           ;
+  if(m_aiOrgDepthStrides        ) delete[] m_aiOrgDepthStrides        ;
+
+  if(m_apiCurDepthPel           ) delete[] m_apiCurDepthPel           ;
+  if(m_aiCurDepthStrides        ) delete[] m_aiCurDepthStrides        ;
+
+  Int iNumEntries = (1 << ( m_iShiftPrec + 1) ) + 1 ;
+
+  for (UInt uiEntry = 0; uiEntry < iNumEntries; uiEntry++)
+  {
+    if ( m_aaaiSubPelShiftLut[0] && m_aaaiSubPelShiftLut[0][uiEntry] )
+      delete[] m_aaaiSubPelShiftLut[0][uiEntry];
+
+    if ( m_aaaiSubPelShiftLut[1] && m_aaaiSubPelShiftLut[1][uiEntry] )
+      delete[] m_aaaiSubPelShiftLut[1][uiEntry];
+  }
+
+  if( m_aaaiSubPelShiftLut[0] ) delete[] m_aaaiSubPelShiftLut[0];
+  if( m_aaaiSubPelShiftLut[1] ) delete[] m_aaaiSubPelShiftLut[1];
+}
+
+
+
+Void
+#if LGE_VSO_EARLY_SKIP_A0093
+TRenModel::create( Int iNumOfBaseViews, Int iNumOfModels, Int iWidth, Int iHeight, Int iShiftPrec, Int iHoleMargin, Bool bEarlySkip )
+#else
+TRenModel::create( Int iNumOfBaseViews, Int iNumOfModels, Int iWidth, Int iHeight, Int iShiftPrec, Int iHoleMargin )
+#endif
+{
+  m_iNumOfBaseViews     = iNumOfBaseViews;
+  m_iNumOfRenModels     = iNumOfModels;
+  m_iWidth              = iWidth;
+  m_iHeight             = iHeight;
+  m_iShiftPrec          = iShiftPrec;
+  m_iHoleMargin         = iHoleMargin;
+#if LGE_VSO_EARLY_SKIP_A0093
+  m_bEarlySkip          = bEarlySkip; 
+#endif
+
+
+// LUTs for sub pel shifting
+  Int iNumEntries = (1 << ( m_iShiftPrec + 1) ) + 1 ;
+  m_aaaiSubPelShiftLut[0] = new Int*[ iNumEntries ];
+  m_aaaiSubPelShiftLut[1] = new Int*[ iNumEntries ];
+  for (UInt uiEntry = 0; uiEntry < iNumEntries; uiEntry++)
+  {
+    m_aaaiSubPelShiftLut[0][uiEntry] = new Int[ iNumEntries ];
+    m_aaaiSubPelShiftLut[1][uiEntry] = new Int[ iNumEntries ];
+  }
+
+  TRenFilter::setSubPelShiftLUT( m_iShiftPrec, m_aaaiSubPelShiftLut[0], 0 );
+  TRenFilter::setSubPelShiftLUT( m_iShiftPrec, m_aaaiSubPelShiftLut[1], 0 );
+
+  m_iSampledWidth       = iWidth << m_iShiftPrec;
+
+
+  m_aapiCurVideoPel     = new Pel**     [m_iNumOfBaseViews];
+  m_aaiCurVideoStrides  = new Int*      [m_iNumOfBaseViews];
+  m_apiCurDepthPel      = new Pel*      [m_iNumOfBaseViews];
+  m_aiCurDepthStrides   = new Int       [m_iNumOfBaseViews];
+
+  m_aapiOrgVideoPel     = new Pel**     [m_iNumOfBaseViews];
+  m_aaiOrgVideoStrides  = new Int*      [m_iNumOfBaseViews];
+
+  m_apiOrgDepthPel      = new Pel*      [m_iNumOfBaseViews];
+  m_aiOrgDepthStrides   = new Int       [m_iNumOfBaseViews];
+
+  m_abSetupVideoFromOrgForView = new Bool[m_iNumOfBaseViews];
+  m_abSetupDepthFromOrgForView = new Bool[m_iNumOfBaseViews];
+
+  m_iNumOfCurRenModels   = 0;
+  m_apcCurRenModels      = NULL;
+  m_aiCurPosInModels     = NULL;
+
+  m_apcRenModels         = new TRenSingleModel*       [m_iNumOfRenModels];
+
+  m_aiNumOfModelsForDepthView = new Int               [m_iNumOfBaseViews];
+  m_aapcRenModelForDepthView  = new TRenSingleModel** [m_iNumOfBaseViews];
+  m_aaePosInModelForDepthView = new Int*              [m_iNumOfBaseViews];
+
+  m_aiNumOfModelsForVideoView = new Int               [m_iNumOfBaseViews];
+  m_aapcRenModelForVideoView  = new TRenSingleModel** [m_iNumOfBaseViews];
+  m_aaePosInModelForVideoView = new Int*              [m_iNumOfBaseViews];
+  m_aaeBaseViewPosInModel     = new Int*              [m_iNumOfBaseViews];
+
+
+  for (Int iModelNum = 0; iModelNum < m_iNumOfRenModels; iModelNum++)
+  {
+    m_apcRenModels         [iModelNum] = NULL;
+  }
+
+  for (Int iViewNum = 0; iViewNum < m_iNumOfBaseViews; iViewNum++ )
+  {
+    m_aiNumOfModelsForDepthView[ iViewNum ] = 0;
+    m_aiNumOfModelsForVideoView[ iViewNum ] = 0;
+
+    m_aapcRenModelForDepthView [iViewNum] = new TRenSingleModel*[m_iNumOfRenModels];
+    m_aapcRenModelForVideoView [iViewNum] = new TRenSingleModel*[m_iNumOfRenModels];
+
+    m_aaePosInModelForDepthView[iViewNum] = new Int             [m_iNumOfRenModels];
+    m_aaePosInModelForVideoView[iViewNum] = new Int             [m_iNumOfRenModels];
+    m_aaeBaseViewPosInModel    [iViewNum] = new Int             [m_iNumOfRenModels];
+
+    for (Int iModelNum = 0; iModelNum< m_iNumOfRenModels; iModelNum++)
+    {
+      m_aapcRenModelForDepthView [iViewNum] [iModelNum] = NULL;
+      m_aapcRenModelForVideoView [iViewNum] [iModelNum] = NULL;
+      m_aaePosInModelForDepthView[iViewNum] [iModelNum] = VIEWPOS_INVALID;
+      m_aaePosInModelForVideoView[iViewNum] [iModelNum] = VIEWPOS_INVALID;
+      m_aaeBaseViewPosInModel    [iViewNum] [iModelNum] = VIEWPOS_INVALID;
+    };
+
+    m_aaiCurVideoStrides  [iViewNum]     =  new Int[3];
+    m_aaiCurVideoStrides  [iViewNum][0]  =  m_iSampledWidth + (m_iPad << 1);
+    m_aaiCurVideoStrides  [iViewNum][1]  =  m_iSampledWidth + (m_iPad << 1);
+    m_aaiCurVideoStrides  [iViewNum][2]  =  m_iSampledWidth + (m_iPad << 1);
+
+    m_aapiCurVideoPel     [iViewNum]     = new Pel*[3];
+    m_aapiCurVideoPel     [iViewNum][0]  = new Pel [ m_aaiCurVideoStrides[iViewNum][0] * ( m_iHeight  + (m_iPad << 1) )];
+    m_aapiCurVideoPel     [iViewNum][1]  = new Pel [ m_aaiCurVideoStrides[iViewNum][1] * ( m_iHeight  + (m_iPad << 1) )];
+    m_aapiCurVideoPel     [iViewNum][2]  = new Pel [ m_aaiCurVideoStrides[iViewNum][2] * ( m_iHeight  + (m_iPad << 1) )];
+
+    m_aapiCurVideoPel     [iViewNum][0] += m_aaiCurVideoStrides[iViewNum][0] * m_iPad + m_iPad;
+    m_aapiCurVideoPel     [iViewNum][1] += m_aaiCurVideoStrides[iViewNum][1] * m_iPad + m_iPad;
+    m_aapiCurVideoPel     [iViewNum][2] += m_aaiCurVideoStrides[iViewNum][2] * m_iPad + m_iPad;
+
+    m_aiCurDepthStrides   [iViewNum]     = m_iWidth + (m_iPad << 1);
+    m_apiCurDepthPel      [iViewNum]     = new Pel[ m_aiCurDepthStrides[iViewNum] * ( m_iHeight  + (m_iPad << 1) ) ];
+    m_apiCurDepthPel      [iViewNum]    += m_aiCurDepthStrides[iViewNum] * m_iPad + m_iPad;
+
+    m_aaiOrgVideoStrides  [iViewNum]    =  new Int[3];
+    m_aaiOrgVideoStrides  [iViewNum][0] = m_iSampledWidth + (m_iPad << 1);
+    m_aaiOrgVideoStrides  [iViewNum][1] = m_iSampledWidth + (m_iPad << 1);
+    m_aaiOrgVideoStrides  [iViewNum][2] = m_iSampledWidth + (m_iPad << 1);
+
+    m_aapiOrgVideoPel     [iViewNum]     = new Pel*[3];
+    m_aapiOrgVideoPel     [iViewNum][0]  = new Pel [ m_aaiOrgVideoStrides[iViewNum][0] * ( m_iHeight  + (m_iPad << 1) )];
+    m_aapiOrgVideoPel     [iViewNum][1]  = new Pel [ m_aaiOrgVideoStrides[iViewNum][1] * ( m_iHeight  + (m_iPad << 1) )];
+    m_aapiOrgVideoPel     [iViewNum][2]  = new Pel [ m_aaiOrgVideoStrides[iViewNum][2] * ( m_iHeight  + (m_iPad << 1) )];
+
+    m_aapiOrgVideoPel     [iViewNum][0] += m_aaiOrgVideoStrides[iViewNum][0] * m_iPad + m_iPad;
+    m_aapiOrgVideoPel     [iViewNum][1] += m_aaiOrgVideoStrides[iViewNum][1] * m_iPad + m_iPad;
+    m_aapiOrgVideoPel     [iViewNum][2] += m_aaiOrgVideoStrides[iViewNum][2] * m_iPad + m_iPad;
+
+    m_aiOrgDepthStrides   [iViewNum]     = m_iWidth + (m_iPad << 1);
+    m_apiOrgDepthPel      [iViewNum]     = new Pel[ m_aiOrgDepthStrides[iViewNum] * ( m_iHeight  + (m_iPad << 1) ) ];
+    m_apiOrgDepthPel      [iViewNum]    += m_aiOrgDepthStrides[iViewNum] * m_iPad + m_iPad;
+
+    m_abSetupVideoFromOrgForView[iViewNum] = false;
+    m_abSetupDepthFromOrgForView[iViewNum] = false;
+  }
+}
+
+Void
+TRenModel::createSingleModel( Int iBaseViewNum, Int iContent, Int iModelNum, Int iLeftViewNum, Int iRightViewNum, Bool bUseOrgRef, Int iBlendMode )
+{
+  Int iMode = ( (iLeftViewNum != -1) && ( iRightViewNum != -1 ) ) ? 2 : ( iLeftViewNum != -1 ? 0 : ( iRightViewNum != -1  ? 1 : -1 ) );
+
+  AOT( iMode == -1);
+  AOT( iModelNum < 0 || iModelNum > m_iNumOfRenModels );  
+  AOT( iLeftViewNum  < -1 || iLeftViewNum  > m_iNumOfBaseViews );
+  AOT( iRightViewNum < -1 || iRightViewNum > m_iNumOfBaseViews );
+  AOT( iBaseViewNum  < -1 || iBaseViewNum  > m_iNumOfBaseViews );
+  AOT( iBaseViewNum != -1 && iBaseViewNum != iLeftViewNum && iBaseViewNum != iRightViewNum );
+  AOT( iContent      < -1 || iContent > 1 );
+  AOT( iBlendMode < -1 || iBlendMode > 2 );
+
+  Bool bBitInc = (g_uiBitIncrement != 0);
+
+  AOT( m_apcRenModels[iModelNum] );
+
+  if ( bBitInc )
+  { 
+    if ( iMode != 2 ) 
+    { // No Blending
+      m_apcRenModels[iModelNum]   = new TRenSingleModelC<BLEND_NONE, true>; 
+    }
+    else
+    {
+      switch ( iBlendMode )
+      {
+      case BLEND_AVRG: // average
+        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_AVRG, true>;       
+        break;
+      case BLEND_LEFT: // left  view is main view
+        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_LEFT, true>;       
+        break;
+      case BLEND_RIGHT: // right view is main view
+        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_RIGHT, true>;       
+        break;
+      default: 
+        AOT(true);
+        break;
+      }    
+    }
+  }
+  else
+  {
+    if ( iMode != 2 ) 
+    { // No Blending
+      m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_NONE, false>; 
+    }
+    else
+    {
+      switch ( iBlendMode )
+      {
+      case BLEND_AVRG: // average
+        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_AVRG, false>;       
+        break;
+      case BLEND_LEFT: // left  view is main view
+        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_LEFT, false>;       
+        break;
+      case BLEND_RIGHT: // right view is main view
+        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_RIGHT, false>;       
+        break;
+      default: 
+        AOT(true);
+        break;
+      }    
+    }
+  }
+
+
+#if LGE_VSO_EARLY_SKIP_A0093
+  m_apcRenModels[iModelNum]->create( iMode ,m_iWidth, m_iHeight, m_iShiftPrec, m_aaaiSubPelShiftLut, m_iHoleMargin,  bUseOrgRef, iBlendMode, m_bEarlySkip );
+#else
+  m_apcRenModels[iModelNum]->create( iMode ,m_iWidth, m_iHeight, m_iShiftPrec, m_aaaiSubPelShiftLut, m_iHoleMargin,  bUseOrgRef, iBlendMode );
+#endif
+
+  if ( iLeftViewNum != -1 )
+  {
+    xSetLRViewAndAddModel( iModelNum, iLeftViewNum, iContent,  VIEWPOS_LEFT,  (iBaseViewNum == -1  || iBaseViewNum == iLeftViewNum   ) );
+  }
+
+  if ( iRightViewNum != -1)
+  {
+    xSetLRViewAndAddModel( iModelNum, iRightViewNum, iContent, VIEWPOS_RIGHT, (iBaseViewNum == -1  || iBaseViewNum == iRightViewNum  ) );
+  }
+}
+
+Void
+TRenModel::setBaseView( Int iViewNum, TComPicYuv* pcPicYuvVideoData, TComPicYuv* pcPicYuvDepthData, TComPicYuv* pcPicYuvOrgVideoData, TComPicYuv* pcPicYuvOrgDepthData )
+{
+  AOT( iViewNum < 0 || iViewNum > m_iNumOfBaseViews );
+  AOF( pcPicYuvVideoData->getHeight() >= m_iUsedHeight + m_uiHorOff && pcPicYuvVideoData->getWidth() == m_iWidth );
+  AOF( pcPicYuvDepthData->getHeight() >= m_iUsedHeight + m_uiHorOff && pcPicYuvDepthData->getWidth() == m_iWidth );
+
+  pcPicYuvVideoData->extendPicBorder();
+
+  TRenFilter::sampleHorUp   ( m_iShiftPrec, pcPicYuvVideoData->getLumaAddr() +  m_uiHorOff        * pcPicYuvVideoData->getStride () , pcPicYuvVideoData->getStride() , m_iWidth,      m_iUsedHeight,      m_aapiCurVideoPel[ iViewNum ][0], m_aaiCurVideoStrides[iViewNum][0] );
+  TRenFilter::sampleCUpHorUp( m_iShiftPrec, pcPicYuvVideoData->getCbAddr()   + (m_uiHorOff >> 1 ) * pcPicYuvVideoData->getCStride() , pcPicYuvVideoData->getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiCurVideoPel[ iViewNum ][1], m_aaiCurVideoStrides[iViewNum][1] );
+  TRenFilter::sampleCUpHorUp( m_iShiftPrec, pcPicYuvVideoData->getCrAddr()   + (m_uiHorOff >> 1 ) * pcPicYuvVideoData->getCStride() , pcPicYuvVideoData->getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiCurVideoPel[ iViewNum ][2], m_aaiCurVideoStrides[iViewNum][2] );
+  TRenFilter::copy          (               pcPicYuvDepthData->getLumaAddr() +  m_uiHorOff        * pcPicYuvDepthData->getStride () , pcPicYuvDepthData->getStride(),  m_iWidth,      m_iUsedHeight,      m_apiCurDepthPel [ iViewNum],     m_aiCurDepthStrides [iViewNum]    );
+
+  // Used for rendering reference pic from original video data
+  m_abSetupVideoFromOrgForView[iViewNum] = (pcPicYuvOrgVideoData != NULL);
+  m_abSetupDepthFromOrgForView[iViewNum] = (pcPicYuvOrgDepthData != NULL);
+
+  if ( m_abSetupVideoFromOrgForView[iViewNum] )
+  {
+    AOF( pcPicYuvOrgVideoData->getHeight() >= m_iUsedHeight + m_uiHorOff && pcPicYuvOrgVideoData->getWidth() == m_iWidth );
+    pcPicYuvOrgVideoData->extendPicBorder();
+    TRenFilter::sampleHorUp   ( m_iShiftPrec, pcPicYuvOrgVideoData->getLumaAddr() +  m_uiHorOff        * pcPicYuvOrgVideoData->getStride() , pcPicYuvOrgVideoData->getStride() , m_iWidth,      m_iUsedHeight,      m_aapiOrgVideoPel[ iViewNum ][0], m_aaiOrgVideoStrides[iViewNum][0] );
+    TRenFilter::sampleCUpHorUp( m_iShiftPrec, pcPicYuvOrgVideoData->getCbAddr()   + (m_uiHorOff >> 1 ) * pcPicYuvOrgVideoData->getCStride(), pcPicYuvOrgVideoData->getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiOrgVideoPel[ iViewNum ][1], m_aaiOrgVideoStrides[iViewNum][1] );
+    TRenFilter::sampleCUpHorUp( m_iShiftPrec, pcPicYuvOrgVideoData->getCrAddr()   + (m_uiHorOff >> 1 ) * pcPicYuvOrgVideoData->getCStride(), pcPicYuvOrgVideoData->getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiOrgVideoPel[ iViewNum ][2], m_aaiOrgVideoStrides[iViewNum][2] );
+  }
+
+  if ( m_abSetupDepthFromOrgForView[iViewNum] )
+  {
+    AOF( pcPicYuvOrgDepthData->getHeight() >= m_iUsedHeight + m_uiHorOff && pcPicYuvOrgDepthData->getWidth() == m_iWidth );
+    TRenFilter::copy          (               pcPicYuvOrgDepthData->getLumaAddr() +  m_uiHorOff        * pcPicYuvOrgDepthData->getStride() , pcPicYuvOrgDepthData->getStride(),  m_iWidth,     m_iUsedHeight,      m_apiOrgDepthPel [ iViewNum],     m_aiOrgDepthStrides [iViewNum]    );
+  }
+}
+
+Void
+TRenModel::setSingleModel( Int iModelNum, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight, Int** ppiBaseShiftLutRight, Int iDistToLeft, TComPicYuv* pcPicYuvRefView )
+{
+  AOT( iModelNum < 0 || iModelNum > m_iNumOfRenModels );
+
+  m_apcRenModels[iModelNum]->setupPart( m_uiHorOff, m_iUsedHeight );
+
+  // Switch model  to original data for setup if given to render reference
+  Bool bAnyRefFromOrg = false;
+  for (Int iBaseViewIdx = 0; iBaseViewIdx < m_iNumOfBaseViews; iBaseViewIdx++ )
+  {
+    Bool bSetupFromOrgVideo = m_abSetupVideoFromOrgForView[iBaseViewIdx];
+    Bool bSetupFromOrgDepth = m_abSetupDepthFromOrgForView[iBaseViewIdx];
+    bAnyRefFromOrg          = bAnyRefFromOrg || bSetupFromOrgVideo || bSetupFromOrgDepth;
+
+    if ( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum] != VIEWPOS_INVALID )
+    {
+      bAnyRefFromOrg = true;
+      m_apcRenModels[iModelNum]->setLRView( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum],
+        ( bSetupFromOrgVideo ? m_aapiOrgVideoPel   : m_aapiCurVideoPel   ) [iBaseViewIdx],
+        ( bSetupFromOrgVideo ? m_aaiOrgVideoStrides: m_aaiCurVideoStrides) [iBaseViewIdx],
+        ( bSetupFromOrgDepth ? m_apiOrgDepthPel    : m_apiCurDepthPel    ) [iBaseViewIdx],
+        ( bSetupFromOrgDepth ? m_aiOrgDepthStrides : m_aiCurDepthStrides ) [iBaseViewIdx] );
+    }
+  }
+
+  m_apcRenModels[iModelNum]->setup     ( pcPicYuvRefView, ppiShiftLutLeft, ppiBaseShiftLutLeft, ppiShiftLutRight, ppiBaseShiftLutRight, iDistToLeft, false );
+
+  // Setup to Org
+  if ( bAnyRefFromOrg )
+  {
+    // Restore old values
+    for (Int iBaseViewIdx = 0; iBaseViewIdx < m_iNumOfBaseViews; iBaseViewIdx++ )
+    {
+      if ( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum] != VIEWPOS_INVALID )
+      {
+        m_apcRenModels[iModelNum]->setLRView(
+          m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum],
+          m_aapiCurVideoPel      [iBaseViewIdx],
+          m_aaiCurVideoStrides   [iBaseViewIdx],
+          m_apiCurDepthPel       [iBaseViewIdx],
+          m_aiCurDepthStrides    [iBaseViewIdx]
+        );
+      }
+    }
+
+    // setup keeping reference rendered from original data
+    m_apcRenModels[iModelNum]->setup     ( pcPicYuvRefView, ppiShiftLutLeft, ppiBaseShiftLutLeft, ppiShiftLutRight, ppiBaseShiftLutRight, iDistToLeft, true );
+  }
+}
+
+Void
+TRenModel::setErrorMode( Int iView, Int iContent, int iPlane )
+{
+  AOT(iView > m_iNumOfBaseViews || iView < 0);
+  AOT(iContent != 0  &&  iContent != 1);
+  AOT(iPlane < 0     || iPlane > 3);
+
+  m_iCurrentView    = iView;
+  m_iCurrentContent = iContent;
+  m_iCurrentPlane   = iPlane;
+
+  if ( iContent == 1 )
+  {
+    m_iNumOfCurRenModels  = m_aiNumOfModelsForDepthView[iView];
+    m_apcCurRenModels     = m_aapcRenModelForDepthView [iView];
+    m_aiCurPosInModels    = m_aaePosInModelForDepthView[iView];
+  }
+  else
+  {
+    m_iNumOfCurRenModels  = m_aiNumOfModelsForVideoView[iView];
+    m_apcCurRenModels     = m_aapcRenModelForVideoView [iView];
+    m_aiCurPosInModels    = m_aaePosInModelForVideoView[iView];
+  }
+}
+
+
+Void
+TRenModel::setupPart ( UInt uiHorOff, Int iUsedHeight )
+{
+  AOT( iUsedHeight > m_iHeight );     
+  m_uiHorOff    = uiHorOff; 
+  m_iUsedHeight = iUsedHeight; 
+}
+
+#if LGE_VSO_EARLY_SKIP_A0093
+RMDist
+TRenModel::getDist( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData, Int iOrgStride)
+#else
+RMDist
+TRenModel::getDist( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+#endif
+{
+  iStartPosY -= m_uiHorOff; 
+
+  AOT( iWidth  + iStartPosX > m_iWidth  );
+  AOT( iHeight + iStartPosY > m_iUsedHeight );
+
+  AOT( iStartPosX < 0);
+  AOT( iStartPosY < 0);
+  AOT( iWidth     < 0);
+  AOT( iHeight    < 0);
+
+  RMDist iDist = 0;
+
+  for (Int iModelNum = 0; iModelNum < m_iNumOfCurRenModels; iModelNum++ )
+  {
+    if (m_iCurrentContent == 1)
+    {
+#if LGE_VSO_EARLY_SKIP_A0093
+      iDist +=  m_apcCurRenModels[iModelNum]->getDistDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY,  iWidth,  iHeight,  iStride,  piNewData , piOrgData, iOrgStride);
+#else
+      iDist +=  m_apcCurRenModels[iModelNum]->getDistDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY,  iWidth,  iHeight,  iStride,  piNewData );
+#endif
+    }
+    else
+    {
+      iDist +=  m_apcCurRenModels[iModelNum]->getDistVideo  ( m_aiCurPosInModels[iModelNum], m_iCurrentPlane ,iStartPosX, iStartPosY, iWidth, iHeight, iStride, piNewData );
+    }
+  }
+
+  return ( iDist + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
+}
+
+Void
+TRenModel::setData( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+{
+  iStartPosY -= m_uiHorOff; 
+
+  iWidth  = min(iWidth , m_iWidth  - iStartPosX );
+  iHeight = min(iHeight, m_iUsedHeight - iStartPosY );
+
+  AOT( iStartPosX < 0);
+  AOT( iStartPosY < 0);
+  AOT( iWidth     < 0);
+  AOT( iHeight    < 0);
+
+  for (Int iModelNum = 0; iModelNum < m_iNumOfCurRenModels; iModelNum++ )
+  {
+    if (m_iCurrentContent == 1)
+    {
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+      Int iTargetStride = m_aiCurDepthStrides[ m_iCurrentView ];
+      m_apcCurRenModels[iModelNum]->setDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY, iWidth, iHeight, iStride, piNewData,m_apiCurDepthPel[ m_iCurrentView ] + iStartPosY * iTargetStride + iStartPosX ,iTargetStride );
+#else
+      m_apcCurRenModels[iModelNum]->setDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY, iWidth, iHeight, iStride, piNewData );
+#endif
+    }
+    else
+    {
+      m_apcCurRenModels[iModelNum]->setVideo  ( m_aiCurPosInModels[iModelNum], m_iCurrentPlane ,iStartPosX, iStartPosY,  iWidth,  iHeight,  iStride, piNewData );
+    }
+  }
+
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  if (m_iCurrentContent == 1)
+  {
+    Int iTargetStride = m_aiCurDepthStrides[ m_iCurrentView ];
+    TRenFilter::copy( piNewData, iStride, iWidth, iHeight,  m_apiCurDepthPel[ m_iCurrentView ] + iStartPosY * iTargetStride + iStartPosX, iTargetStride );
+  }
+#endif
+}
+
+Void
+TRenModel::getSynthVideo( Int iModelNum, Int iViewNum, TComPicYuv* pcPicYuv )
+{
+  m_apcRenModels[iModelNum]->getSynthVideo(iViewNum, pcPicYuv );
+}
+
+Void
+TRenModel::getSynthDepth( Int iModelNum, Int iViewNum, TComPicYuv* pcPicYuv )
+{
+  m_apcRenModels[iModelNum]->getSynthDepth(iViewNum, pcPicYuv );
+}
+
+Void
+TRenModel::getTotalSSE( Int64& riSSEY, Int64& riSSEU, Int64& riSSEV )
+{
+  TComPicYuv cPicYuvSynth;
+  cPicYuvSynth.create( m_iWidth, m_iUsedHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+
+  TComPicYuv cPicYuvTempRef;
+  cPicYuvTempRef.create( m_iWidth, m_iUsedHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
+
+  Int64 iSSEY = 0;
+  Int64 iSSEU = 0;
+  Int64 iSSEV = 0;
+
+  for (Int iCurModel = 0; iCurModel < m_iNumOfCurRenModels; iCurModel++)
+  {
+    m_apcCurRenModels[iCurModel]->getSynthVideo( m_aiCurPosInModels[iCurModel], &cPicYuvSynth );    
+    m_apcCurRenModels[iCurModel]->getRefVideo  ( m_aiCurPosInModels[iCurModel], &cPicYuvTempRef   );
+
+    iSSEY += TRenFilter::SSE( cPicYuvSynth.getLumaAddr(), cPicYuvSynth.getStride(),  m_iWidth,      m_iUsedHeight     , cPicYuvTempRef.getLumaAddr(), cPicYuvTempRef.getStride() );
+    iSSEU += TRenFilter::SSE( cPicYuvSynth.getCbAddr()  , cPicYuvSynth.getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, cPicYuvTempRef.getCbAddr()  , cPicYuvTempRef.getCStride());
+    iSSEV += TRenFilter::SSE( cPicYuvSynth.getCrAddr()  , cPicYuvSynth.getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, cPicYuvTempRef.getCrAddr()  , cPicYuvTempRef.getCStride());
+  }
+
+  riSSEY = ( iSSEY + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
+  riSSEU = ( iSSEU + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
+  riSSEV = ( iSSEV + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
+
+  cPicYuvTempRef.destroy();
+  cPicYuvSynth  .destroy();
+}
+
+Void
+TRenModel::xSetLRViewAndAddModel( Int iModelNum, Int iBaseViewNum, Int iContent, Int iViewPos, Bool bAdd )
+{
+  AOF(iViewPos == VIEWPOS_LEFT  || iViewPos == VIEWPOS_RIGHT);
+  AOF(iContent == -1 || iContent == 0 || iContent == 1);
+  AOT( iBaseViewNum  < 0 || iBaseViewNum  > m_iNumOfBaseViews );
+  AOT( m_aaeBaseViewPosInModel[iBaseViewNum][iModelNum] != VIEWPOS_INVALID );
+  m_aaeBaseViewPosInModel[iBaseViewNum][iModelNum] = iViewPos;
+
+  if (bAdd)
+  {
+    if (iContent == 0 || iContent == -1 )
+    {
+      Int iNewModelIdxForView = m_aiNumOfModelsForVideoView[iBaseViewNum]++;
+      m_aapcRenModelForVideoView [ iBaseViewNum ][ iNewModelIdxForView ] = m_apcRenModels[iModelNum];
+      m_aaePosInModelForVideoView[ iBaseViewNum ][ iNewModelIdxForView ] = iViewPos;
+    }
+
+    if (iContent == 1 || iContent == -1 )
+    {
+      Int iNewModelIdxForView = m_aiNumOfModelsForDepthView[iBaseViewNum]++;
+      m_aapcRenModelForDepthView [ iBaseViewNum ][ iNewModelIdxForView ] = m_apcRenModels[iModelNum];
+      m_aaePosInModelForDepthView[ iBaseViewNum ][ iNewModelIdxForView ] = iViewPos;
+    }
+  }
+}
+#endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModel.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModel.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenModel.h	(revision 438)
@@ -0,0 +1,159 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !QC_MVHEVC_B0046
+#ifndef __TRENMODEL__
+#define __TRENMODEL__
+
+#include "TRenImage.h"
+#include "TRenSingleModel.h"
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPicYuv.h"
+#include "../TLibCommon/TypeDef.h"
+
+class TRenModel
+{
+public:
+
+  TRenModel();
+  ~TRenModel();
+
+  // Creation
+#if LGE_VSO_EARLY_SKIP_A0093
+  Void  create           ( Int iNumOfBaseViews, Int iNumOfModels, Int iWidth, Int iHeight, Int iShiftPrec, Int iHoleMargin, Bool bEarlySkip );
+#else
+  Void  create           ( Int iNumOfBaseViews, Int iNumOfModels, Int iWidth, Int iHeight, Int iShiftPrec, Int iHoleMargin );
+#endif
+  Void  createSingleModel( Int iBaseViewNum, Int iContent, Int iModelNum, Int iLeftViewNum, Int iRightViewNum, Bool bUseOrgRef, Int iBlendMode );
+
+  // Set new Frame
+  Void  setBaseView      ( Int iViewNum, TComPicYuv* pcPicYuvVideoData, TComPicYuv* pcPicYuvDepthData, TComPicYuv* pcPicYuvOrgVideoData, TComPicYuv* pcPicYuvOrgDepthData  );
+  Void  setSingleModel   ( Int iModelNum, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight, Int** ppiBaseShiftLutRight, Int iDistToLeft, TComPicYuv* pcPicYuvRefView );
+
+  // Set horizontal offset
+  Void  setupPart        ( UInt uiHorOff, Int iUsedHeight );
+
+  // Set Mode
+  Void  setErrorMode     ( Int iView, Int iContent, Int iPlane );
+
+  // Get Distortion, set Data
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  Int64 getDist          ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData, Int iOrgStride);
+#else
+  Int64 getDist          ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData  );
+#endif
+  Void  setData          ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData  );
+
+  // Get Rendered View
+
+  Void  getSynthVideo    ( Int iModelNum, Int iViewNum, TComPicYuv* pcPicYuvSynthVideo );
+  Void  getSynthDepth    ( Int iModelNum, Int iViewNum, TComPicYuv* pcPicYuvSynthDepth );
+
+  // Get Total Distortion
+  Void  getTotalSSE      (Int64& riSSEY, Int64& riSSEU, Int64& riSSEV );
+
+private:
+  // helpers
+  Void xSetLRViewAndAddModel( Int iModelNum, Int iBaseViewNum, Int iContent, Int iViewPos, Bool bAdd );
+
+  // Settings
+  Int    m_iShiftPrec;
+  Int**  m_aaaiSubPelShiftLut[2];
+  Int    m_iHoleMargin;
+#if LGE_VSO_EARLY_SKIP_A0093
+  Bool   m_bEarlySkip; 
+#endif
+
+  /// Size of Video and Depth
+  Int m_iWidth;
+  Int m_iHeight;
+  Int m_iSampledWidth;
+  Int m_iPad;
+  Int m_iUsedHeight;   // height currently used in buffer, whereas m_iHeight is the total height of the buffer
+
+
+  Int m_iNumOfBaseViews;
+
+  // Horizontal Offset in input data
+  UInt m_uiHorOff;          
+
+  /// Current Error Type ///
+  Int m_iCurrentView;
+  Int m_iCurrentContent;
+  Int m_iCurrentPlane;
+
+  /// Array of Models used to determine the Current Error ///
+  Int                m_iNumOfCurRenModels;
+  TRenSingleModel**  m_apcCurRenModels;   // Array of pointers used for determination of current error
+  Int*               m_aiCurPosInModels;  // Position of Current View in Model
+
+  /// Array of Models ///
+  Int                m_iNumOfRenModels;
+  TRenSingleModel**  m_apcRenModels;   // Array of pointers to all created models
+
+  /// Mapping from View number and Content type to models ///
+  Int*               m_aiNumOfModelsForDepthView;
+  TRenSingleModel*** m_aapcRenModelForDepthView;   // Dim1: ViewNumber
+  Int**              m_aaePosInModelForDepthView; // Position in Model ( Left or Right)
+
+  Int*               m_aiNumOfModelsForVideoView;
+  TRenSingleModel*** m_aapcRenModelForVideoView;   // Dim1: ViewNumber
+  Int**              m_aaePosInModelForVideoView; // Position in Model ( Left or Right) (local model numbering)
+
+  /// Position of Base Views in Models ( global model numbering )
+  Int**              m_aaeBaseViewPosInModel;
+
+  /// Current Setup data ///
+  Bool*              m_abSetupVideoFromOrgForView;  //: Dim1: ViewNumber, 0 ... use org; 1 ... use coded; 2; use org ref and coded in RDO
+  Bool*              m_abSetupDepthFromOrgForView;
+
+  /// DATA //
+  // Cur
+
+  /// Number of Base Views
+  Pel*** m_aapiCurVideoPel   ; // Dim1: ViewNumber: Plane  0-> Y, 1->U, 2->V
+  Int**  m_aaiCurVideoStrides; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
+
+  Pel**  m_apiCurDepthPel    ; // Dim1: ViewPosition
+  Int*   m_aiCurDepthStrides ; // Dim1: ViewPosition
+
+  Pel*** m_aapiOrgVideoPel   ; // Dim1: ViewPosition  Dim2: Plane  0-> Y, 1->U, 2->V
+  Int**  m_aaiOrgVideoStrides; // Dim1: ViewPosition  Dim2: Plane  0-> Y, 1->U, 2->V
+
+  Pel**  m_apiOrgDepthPel    ;    // Dim1: ViewPosition
+  Int*   m_aiOrgDepthStrides ;    // Dim1: ViewPosition
+};
+
+#endif //__TRENMODEL__
+#endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenSingleModel.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenSingleModel.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenSingleModel.cpp	(revision 438)
@@ -0,0 +1,1960 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "TRenImage.h"
+#include "TRenFilter.h"
+#include "TRenSingleModel.h"
+
+#if !QC_MVHEVC_B0046
+////////////// TRENSINGLE MODEL ///////////////
+template <BlenMod iBM, Bool bBitInc>
+TRenSingleModelC<iBM,bBitInc>::TRenSingleModelC()
+:  m_iDistShift ( g_uiBitIncrement << 1 )
+{
+  m_iWidth  = -1;
+  m_iHeight = -1;
+  m_iStride = -1;
+  m_iUsedHeight = -1; 
+  m_iHorOffset  = -1; 
+  m_iMode   = -1;
+  m_iPad    = PICYUV_PAD;
+  m_iGapTolerance = -1;
+  m_bUseOrgRef = false;
+
+  m_pcPicYuvRef          = NULL;
+
+  m_pcOutputSamples      = NULL; 
+  m_pcOutputSamplesRow   = NULL;   
+  m_iOutputSamplesStride = -1; 
+
+  m_ppiCurLUT            = NULL;
+  m_piInvZLUTLeft        = NULL;
+  m_piInvZLUTRight       = NULL;
+
+  m_aapiRefVideoPel[0]   = NULL;
+  m_aapiRefVideoPel[1]   = NULL;
+  m_aapiRefVideoPel[2]   = NULL;
+
+  m_aiRefVideoStrides[0] = -1;
+  m_aiRefVideoStrides[1] = -1;
+  m_aiRefVideoStrides[2] = -1;
+
+
+  for (UInt uiViewNum = 0 ; uiViewNum < 2; uiViewNum++)
+  {
+    // LUT
+    m_appiShiftLut[uiViewNum] = NULL;
+
+    m_pcInputSamples[uiViewNum] = NULL; 
+    m_iInputSamplesStride       = -1; 
+
+    m_ppiCurLUT               = NULL;
+    m_piInvZLUTLeft           = NULL;
+    m_piInvZLUTRight          = NULL;
+  }
+
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  m_pbHorSkip = NULL;
+#endif
+}
+
+template <BlenMod iBM, Bool bBitInc>
+TRenSingleModelC<iBM,bBitInc>::~TRenSingleModelC()
+{
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  if ( m_pbHorSkip ) 
+  {
+    delete[] m_pbHorSkip;
+    m_pbHorSkip = NULL;
+  }
+#endif
+
+  if ( m_pcInputSamples [0] ) delete[] m_pcInputSamples [0];
+  if ( m_pcInputSamples [1] ) delete[] m_pcInputSamples [1];
+
+  if ( m_pcOutputSamples    ) delete[] m_pcOutputSamples   ;
+
+  if ( m_piInvZLUTLeft  ) delete[] m_piInvZLUTLeft ;
+  if ( m_piInvZLUTRight ) delete[] m_piInvZLUTRight;
+
+  if ( m_aapiRefVideoPel[0] ) delete[] ( m_aapiRefVideoPel[0] - ( m_aiRefVideoStrides[0] * m_iPad + m_iPad ) );
+  if ( m_aapiRefVideoPel[1] ) delete[] ( m_aapiRefVideoPel[1] - ( m_aiRefVideoStrides[1] * m_iPad + m_iPad ) );
+  if ( m_aapiRefVideoPel[2] ) delete[] ( m_aapiRefVideoPel[2] - ( m_aiRefVideoStrides[2] * m_iPad + m_iPad ) );
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+#if LGE_VSO_EARLY_SKIP_A0093
+TRenSingleModelC<iBM,bBitInc>::create( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip )
+#else
+TRenSingleModelC<iBM,bBitInc>::create( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode )
+#endif
+
+{
+#if LGE_VSO_EARLY_SKIP_A0093
+  m_pbHorSkip     = new Bool [MAX_CU_SIZE];
+  m_bEarlySkip    = bEarlySkip; 
+#endif
+
+  AOF( iBlendMode == iBM ); 
+
+  m_iMode = iMode;
+
+  m_iWidth  = iWidth;
+  m_iHeight = iHeight;
+  m_iStride = iWidth;
+
+  m_iSampledWidth  = m_iWidth  << iShiftPrec;
+  m_iSampledStride = m_iStride << iShiftPrec;
+
+  m_iShiftPrec     = iShiftPrec;
+  m_aaiSubPelShiftL = aaaiSubPelShiftTable[0];
+  m_aaiSubPelShiftR = aaaiSubPelShiftTable[1];
+
+  if (m_iMode == 2)
+  {
+    m_piInvZLUTLeft  = new Int[257];
+    m_piInvZLUTRight = new Int[257];
+  }
+
+  m_iGapTolerance  = ( 2 << iShiftPrec );
+  m_iHoleMargin    =  iHoleMargin;
+
+  m_bUseOrgRef = bUseOrgRef;
+
+  m_aiRefVideoStrides[0] = m_iStride + (m_iPad << 1);
+  m_aiRefVideoStrides[1] = m_iStride + (m_iPad << 1);
+  m_aiRefVideoStrides[2] = m_iStride + (m_iPad << 1);
+
+  m_aapiRefVideoPel  [0] = new Pel[ m_aiRefVideoStrides[0] * (m_iHeight + (m_iPad << 1))];
+  m_aapiRefVideoPel  [1] = new Pel[ m_aiRefVideoStrides[1] * (m_iHeight + (m_iPad << 1))];
+  m_aapiRefVideoPel  [2] = new Pel[ m_aiRefVideoStrides[2] * (m_iHeight + (m_iPad << 1))];
+
+  m_aapiRefVideoPel  [0] += m_aiRefVideoStrides[0] * m_iPad + m_iPad;
+  m_aapiRefVideoPel  [1] += m_aiRefVideoStrides[1] * m_iPad + m_iPad;
+  m_aapiRefVideoPel  [2] += m_aiRefVideoStrides[2] * m_iPad + m_iPad;
+
+  m_iInputSamplesStride  = m_iWidth+1;
+  m_iOutputSamplesStride = m_iWidth;
+
+  m_pcInputSamples[0]     = new RenModelInPels[m_iInputSamplesStride*m_iHeight];
+  m_pcInputSamples[1]     = new RenModelInPels[m_iInputSamplesStride*m_iHeight];
+
+  m_pcOutputSamples       = new RenModelOutPels[m_iOutputSamplesStride*m_iHeight];  
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::setLRView( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride )
+{
+  AOF(( iViewPos == 0) || (iViewPos == 1) );
+
+  RenModelInPels* pcCurInputSampleRow = m_pcInputSamples[iViewPos];
+  
+  Pel* piDRow = piCurDepthPel;
+  Pel* piYRow = apiCurVideoPel[0];
+#if HHI_VSO_COLOR_PLANES
+  Pel* piURow = apiCurVideoPel[1];
+  Pel* piVRow = apiCurVideoPel[2];
+#endif  
+
+
+  Int iOffsetX = ( iViewPos == VIEWPOS_RIGHT ) ? 1 : 0;
+
+  for ( Int iPosY = 0; iPosY < m_iUsedHeight; iPosY++ )
+  {
+    if ( iViewPos == VIEWPOS_RIGHT )
+    {
+      Int iSubPosX = (1 << m_iShiftPrec); 
+      pcCurInputSampleRow[0].aiY[iSubPosX] = piYRow[0];
+#if HHI_VSO_COLOR_PLANES 
+      pcCurInputSampleRow[0].aiU[iSubPosX] = piURow[0];
+      pcCurInputSampleRow[0].aiV[iSubPosX] = piVRow[0];
+#endif
+    }
+
+    for ( Int iPosX = 0; iPosX < m_iWidth; iPosX++ )
+    {
+      pcCurInputSampleRow[iPosX].iD = piDRow[iPosX];
+
+      for (Int iSubPosX = 0; iSubPosX < (1 << m_iShiftPrec)+1; iSubPosX++ )
+      { 
+        Int iShift = (iPosX << m_iShiftPrec) + iSubPosX;
+        pcCurInputSampleRow[iPosX+iOffsetX].aiY[iSubPosX] = piYRow[iShift];
+#if HHI_VSO_COLOR_PLANES 
+        pcCurInputSampleRow[iPosX+iOffsetX].aiU[iSubPosX] = piURow[iShift];
+        pcCurInputSampleRow[iPosX+iOffsetX].aiV[iSubPosX] = piVRow[iShift];
+#endif
+      }
+    } 
+
+    pcCurInputSampleRow += m_iInputSamplesStride; 
+
+    piDRow += iCurDepthStride;
+    piYRow += aiCurVideoStride[0];
+#if HHI_VSO_COLOR_PLANES
+    piURow += aiCurVideoStride[1];
+    piVRow += aiCurVideoStride[2];
+#endif
+  }
+
+  
+  m_aapiBaseVideoPel      [iViewPos] = apiCurVideoPel;
+  m_aaiBaseVideoStrides   [iViewPos] = aiCurVideoStride;
+  m_apiBaseDepthPel       [iViewPos] = piCurDepthPel;
+  m_aiBaseDepthStrides    [iViewPos] = iCurDepthStride;
+
+}
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::setupPart ( UInt uiHorOffset,       Int iUsedHeight )
+{
+  AOT( iUsedHeight > m_iHeight );   
+
+  m_iUsedHeight =       iUsedHeight; 
+  m_iHorOffset  = (Int) uiHorOffset;
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::setup( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference )
+{
+  AOT( !m_bUseOrgRef && pcOrgVideo );
+  AOT( (ppiShiftLutLeft  == NULL) && (m_iMode == 0 || m_iMode == 2) );
+  AOT( (ppiShiftLutRight == NULL) && (m_iMode == 1 || m_iMode == 2) );
+
+  m_appiShiftLut[0] = ppiShiftLutLeft;
+  m_appiShiftLut[1] = ppiShiftLutRight;
+
+  // Copy Reference
+  m_pcPicYuvRef = pcOrgVideo;
+
+  if ( pcOrgVideo && !bKeepReference )
+  {
+    TRenFilter::copy(             pcOrgVideo->getLumaAddr() +  m_iHorOffset       * pcOrgVideo->getStride() , pcOrgVideo->getStride() , m_iWidth,      m_iUsedHeight,      m_aapiRefVideoPel[0], m_aiRefVideoStrides[0]);
+    TRenFilter::sampleCUpHorUp(0, pcOrgVideo->getCbAddr()   + (m_iHorOffset >> 1) * pcOrgVideo->getCStride(), pcOrgVideo->getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiRefVideoPel[1], m_aiRefVideoStrides[1]);
+    TRenFilter::sampleCUpHorUp(0, pcOrgVideo->getCrAddr()   + (m_iHorOffset >> 1) * pcOrgVideo->getCStride(), pcOrgVideo->getCStride(), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiRefVideoPel[2], m_aiRefVideoStrides[2]);    
+    xSetStructRefView();
+  }
+
+  // Initial Rendering
+  xResetStructError();
+  xInitSampleStructs();
+  switch ( m_iMode )
+  {  
+  case 0:   
+#if LGE_VSO_EARLY_SKIP_A0093
+    xRenderL<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[0], m_apiBaseDepthPel[0],false );
+#else
+    xRenderL<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[0], m_apiBaseDepthPel[0] );
+#endif   
+    break;
+  case 1:    
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    xRenderR<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[1], m_apiBaseDepthPel[1],false);
+#else
+    xRenderR<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[1], m_apiBaseDepthPel[1] );
+#endif
+    break;
+  case 2:
+    TRenFilter::setupZLUT( true, 30, iDistToLeft, ppiBaseShiftLutLeft, ppiBaseShiftLutRight, m_iBlendZThres, m_iBlendDistWeight, m_piInvZLUTLeft, m_piInvZLUTRight );
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    xRenderL<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[0], m_apiBaseDepthPel[0],false);
+    xRenderR<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[1], m_apiBaseDepthPel[1],false);
+#else      
+    xRenderL<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[0], m_apiBaseDepthPel[0] );
+    xRenderR<true>( 0, 0, m_iWidth, m_iUsedHeight, m_aiBaseDepthStrides[1], m_apiBaseDepthPel[1] );
+#endif
+    break;
+  default:
+    AOT(true);
+  }
+
+  // Get Rendered View as Reference
+  if ( !pcOrgVideo && !bKeepReference )
+  {
+    xResetStructError();
+    xSetStructSynthViewAsRefView();
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+#if HHI_VSO_COLOR_PLANES
+TRenSingleModelC<iBM,bBitInc>::xGetSampleStrTextPtrs( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY, Pel RenModelOutPels::*& rpiSrcU, Pel RenModelOutPels::*& rpiSrcV )
+#else
+TRenSingleModelC<iBM,bBitInc>::xGetSampleStrTextPtrs( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY )
+#endif
+{
+  switch ( iViewNum )
+  {
+  case 0:
+    rpiSrcY = &RenModelOutPels::iYLeft;
+#if HHI_VSO_COLOR_PLANES  
+    rpiSrcU = &RenModelOutPels::iULeft;
+    rpiSrcV = &RenModelOutPels::iVLeft;
+#endif
+    break;
+  case 1:
+    rpiSrcY = &RenModelOutPels::iYRight;
+#if HHI_VSO_COLOR_PLANES  
+    rpiSrcU = &RenModelOutPels::iURight;
+    rpiSrcV = &RenModelOutPels::iVRight;
+#endif
+    break;
+  case 2:
+    rpiSrcY = &RenModelOutPels::iYBlended;
+#if HHI_VSO_COLOR_PLANES  
+    rpiSrcU = &RenModelOutPels::iUBlended;
+    rpiSrcV = &RenModelOutPels::iVBlended;
+#endif
+    break;
+  }
+}
+
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xGetSampleStrDepthPtrs( Int iViewNum, Pel RenModelOutPels::*& rpiSrcD )
+{
+  AOT(iViewNum != 0 && iViewNum != 1);  
+  rpiSrcD = (iViewNum == 1) ? &RenModelOutPels::iDRight : &RenModelOutPels::iDLeft; 
+}
+
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xSetStructRefView( )
+{
+  RenModelOutPels* pcCurOutSampleRow = m_pcOutputSamples;
+  
+  Pel* piYRow = m_aapiRefVideoPel[0];
+#if HHI_VSO_COLOR_PLANES
+  Pel* piURow = m_aapiRefVideoPel[1];
+  Pel* piVRow = m_aapiRefVideoPel[2];
+#endif  
+
+  for ( Int iPosY = 0; iPosY < m_iUsedHeight; iPosY++ )
+  {
+    for ( Int iPosX = 0; iPosX < m_iWidth; iPosX++ )
+    {      
+      pcCurOutSampleRow[iPosX].iYRef = piYRow[iPosX];
+#if HHI_VSO_COLOR_PLANES
+      pcCurOutSampleRow[iPosX].iURef = piURow[iPosX];
+      pcCurOutSampleRow[iPosX].iVRef = piVRow[iPosX];
+#endif
+    } 
+
+    pcCurOutSampleRow += m_iOutputSamplesStride; 
+    
+    piYRow += m_aiRefVideoStrides[0];
+#if HHI_VSO_COLOR_PLANES
+    piURow += m_aiRefVideoStrides[1];
+    piVRow += m_aiRefVideoStrides[2];
+#endif
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xResetStructError( )
+{
+  RenModelOutPels* pcCurOutSampleRow = m_pcOutputSamples;
+
+  for ( Int iPosY = 0; iPosY < m_iHeight; iPosY++ )
+  {
+    for ( Int iPosX = 0; iPosX < m_iWidth; iPosX++ )
+    {      
+      pcCurOutSampleRow[iPosX].iError = 0;
+    } 
+    pcCurOutSampleRow += m_iOutputSamplesStride; 
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xSetStructSynthViewAsRefView( )
+{
+  AOT( m_iMode < 0 || m_iMode > 2);
+
+  RenModelOutPels* pcCurOutSampleRow = m_pcOutputSamples;
+
+  Pel RenModelOutPels::* piSrcY = NULL;
+
+#if HHI_VSO_COLOR_PLANES  
+  Pel RenModelOutPels::* piSrcU = NULL;
+  Pel RenModelOutPels::* piSrcV = NULL;
+  xGetSampleStrTextPtrs( m_iMode, piSrcY, piSrcU, piSrcV );
+#else
+  xGetSampleStrTextPtrs( m_iMode, piSrcY );
+#endif
+
+  for ( Int iPosY = 0; iPosY < m_iUsedHeight; iPosY++ )
+  {
+    for ( Int iPosX = 0; iPosX < m_iWidth; iPosX++ )
+    {      
+      pcCurOutSampleRow[iPosX].iYRef = pcCurOutSampleRow[iPosX].*piSrcY;
+#if HHI_VSO_COLOR_PLANES
+      pcCurOutSampleRow[iPosX].iURef = pcCurOutSampleRow[iPosX].*piSrcU;
+      pcCurOutSampleRow[iPosX].iVRef = pcCurOutSampleRow[iPosX].*piSrcV;
+#endif
+    } 
+    pcCurOutSampleRow += m_iOutputSamplesStride; 
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xInitSampleStructs()
+{
+  RenModelOutPels* pcOutSampleRow      = m_pcOutputSamples;
+  RenModelInPels * pcLeftInSampleRow   = m_pcInputSamples[0];
+  RenModelInPels * pcRightInSampleRow  = m_pcInputSamples[1];
+
+
+  for (Int iPosY = 0; iPosY < m_iHeight; iPosY++)
+  {
+    for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
+    {
+      //// Output Samples
+      pcOutSampleRow[iPosX].iFilledLeft   = REN_IS_HOLE;
+      pcOutSampleRow[iPosX].iFilledRight  = REN_IS_HOLE;
+
+      pcOutSampleRow[iPosX].iDLeft        = 0;
+      pcOutSampleRow[iPosX].iDRight       = 0;
+      pcOutSampleRow[iPosX].iDBlended     = 0;      
+                                     
+      // Y Planes                    
+      pcOutSampleRow[iPosX].iYLeft        = 0;
+      pcOutSampleRow[iPosX].iYRight       = 0;
+      pcOutSampleRow[iPosX].iYBlended     = 0;
+#if HHI_VSO_COLOR_PLANES             
+      // U Planes                    
+      pcOutSampleRow[iPosX].iULeft        = 128 << g_uiBitIncrement;
+      pcOutSampleRow[iPosX].iURight       = 128 << g_uiBitIncrement;
+      pcOutSampleRow[iPosX].iUBlended     = 128 << g_uiBitIncrement;
+                                     
+      // V Planes                    
+      pcOutSampleRow[iPosX].iVLeft        = 128 << g_uiBitIncrement;
+      pcOutSampleRow[iPosX].iVRight       = 128 << g_uiBitIncrement;
+      pcOutSampleRow[iPosX].iVBlended     = 128 << g_uiBitIncrement;
+#endif
+      //// Input Samples
+      pcLeftInSampleRow [iPosX].bOccluded = false;
+      pcRightInSampleRow[iPosX].bOccluded = false;
+    }
+
+    pcOutSampleRow     += m_iOutputSamplesStride;
+    pcLeftInSampleRow  += m_iInputSamplesStride;
+    pcRightInSampleRow += m_iInputSamplesStride;
+  }  
+}
+
+
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+template <BlenMod iBM, Bool bBitInc> RMDist
+TRenSingleModelC<iBM,bBitInc>::getDistDepth( Int iViewPos, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData , Pel * piOrgData, Int iOrgStride )
+#else
+template <BlenMod iBM, Bool bBitInc> RMDist
+TRenSingleModelC<iBM,bBitInc>::getDistDepth( Int iViewPos, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+#endif
+{
+  RMDist iSSE = 0;
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  Bool   bEarlySkip;
+#endif
+  switch ( iViewPos )
+  {
+  case 0:
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    bEarlySkip = m_bEarlySkip ? xDetectEarlySkipL(iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData, piOrgData, iOrgStride) : false;
+    if( !bEarlySkip )
+    {
+      iSSE = xRenderL<false>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData,true );
+    }    
+#else
+    iSSE = xRenderL<false>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData );
+#endif
+    break;
+  case 1:
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    bEarlySkip = m_bEarlySkip ? xDetectEarlySkipR(iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData, piOrgData, iOrgStride) : false;
+    if( !bEarlySkip )
+    {
+      iSSE = xRenderR<false>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData,true );
+    }    
+#else
+    iSSE = xRenderR<false>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData );
+#endif
+    break;
+  default:
+    assert(0);
+  }
+
+  return iSSE;
+}
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::setDepth( Int iViewPos, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel* piOrgData, Int iOrgStride )
+#else
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::setDepth( Int iViewPos, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+#endif
+{
+#ifdef  LGE_VSO_EARLY_SKIP_A0093
+  Bool bEarlySkip;
+#endif
+  switch ( iViewPos )
+  {
+  case 0:
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    bEarlySkip = m_bEarlySkip ? xDetectEarlySkipL(iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData, piOrgData,iOrgStride) : false;
+    if( !bEarlySkip )
+    {
+      xRenderL<true>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData,true );
+    }    
+#else
+    xRenderL<true>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData );
+#endif     
+    break;
+  case 1:
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    bEarlySkip = m_bEarlySkip ? xDetectEarlySkipR(iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData, piOrgData,iOrgStride) : false;
+    if( !bEarlySkip )
+    {
+      xRenderR<true>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData,true ); 
+    }    
+#else
+    xRenderR<true>( iStartPosX,   iStartPosY,   iWidth,   iHeight,   iStride, piNewData );
+#endif     
+    break;
+  default:
+    assert(0);
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::getSynthVideo( Int iViewPos, TComPicYuv* pcPicYuv )
+{  
+  AOT( pcPicYuv->getWidth() != m_iWidth );
+  AOT( pcPicYuv->getHeight() < m_iUsedHeight + m_iHorOffset );
+
+#if HHI_VSO_COLOR_PLANES
+  Pel RenModelOutPels::* piText[3] = { NULL, NULL, NULL };
+  xGetSampleStrTextPtrs(iViewPos, piText[0], piText[1], piText[2]); 
+
+  // Temp image for chroma down sampling
+  PelImage cTempImage( m_iWidth, m_iUsedHeight, 3, 0);
+
+  Int  aiStrides[3]; 
+  Pel* apiData  [3]; 
+
+  cTempImage.getDataAndStrides( apiData, aiStrides ); 
+
+  for (UInt uiCurPlane = 0; uiCurPlane < 3; uiCurPlane++ )
+  {
+    xCopyFromSampleStruct( m_pcOutputSamples, m_iOutputSamplesStride, piText[uiCurPlane], apiData[uiCurPlane], aiStrides[uiCurPlane] , m_iWidth, m_iUsedHeight);
+  }  
+  xCopy2PicYuv( apiData, aiStrides, pcPicYuv );
+#else
+  Pel RenModelOutPels::* piY;
+  xGetSampleStrTextPtrs(iViewPos, piY); 
+  xCopyFromSampleStruct( m_pcOutputSamples, m_iOutputSamplesStride, piY, pcPicYuv->getLumaAddr() + m_iHorOffset * pcPicYuv->getStride(), pcPicYuv->getStride(), m_iWidth, m_iUsedHeight );
+  pcPicYuv->setChromaTo( 128 << g_uiBitIncrement );   
+#endif  
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::getSynthDepth( Int iViewPos, TComPicYuv* pcPicYuv )
+{  
+  AOT( iViewPos != 0 && iViewPos != 1); 
+  AOT( pcPicYuv->getWidth()  != m_iWidth  );
+  AOT( pcPicYuv->getHeight() < m_iUsedHeight + m_iHorOffset );
+
+  Pel RenModelOutPels::* piD = 0;
+  xGetSampleStrDepthPtrs(iViewPos, piD); 
+  xCopyFromSampleStruct( m_pcOutputSamples, m_iOutputSamplesStride, piD, pcPicYuv->getLumaAddr() + pcPicYuv->getStride() * m_iHorOffset, pcPicYuv->getStride(), m_iWidth, m_iUsedHeight );
+  pcPicYuv->setChromaTo( 128 << g_uiBitIncrement );   
+}
+
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::getRefVideo ( Int iViewPos, TComPicYuv* pcPicYuv )
+{  
+  AOT( pcPicYuv->getWidth()  != m_iWidth  );
+  AOT( pcPicYuv->getHeight() <  m_iUsedHeight + m_iHorOffset);
+
+#if HHI_VSO_COLOR_PLANES
+  Pel RenModelOutPels::* piText[3];
+  piText[0] = &RenModelOutPels::iYRef;
+  piText[1] = &RenModelOutPels::iURef;
+  piText[2] = &RenModelOutPels::iVRef;
+
+  // Temp image for chroma down sampling
+
+  PelImage cTempImage( m_iWidth, m_iUsedHeight, 3, 0);
+  Int  aiStrides[3]; 
+  Pel* apiData  [3]; 
+
+  cTempImage.getDataAndStrides( apiData, aiStrides ); 
+
+  for (UInt uiCurPlane = 0; uiCurPlane < 3; uiCurPlane++ )
+  {
+    xCopyFromSampleStruct( m_pcOutputSamples, m_iOutputSamplesStride, piText[uiCurPlane], apiData[uiCurPlane], aiStrides[uiCurPlane] , m_iWidth, m_iUsedHeight);
+  }  
+
+  xCopy2PicYuv( apiData, aiStrides, pcPicYuv );
+#else
+  xCopyFromSampleStruct( m_pcOutputSamples, m_iOutputSamplesStride, &RenModelOutPels::iYRef, pcPicYuv->getLumaAddr() *  pcPicYuv->getStride() + m_iHorOffset, pcPicYuv->getStride(), m_iWidth, m_iUsedHeight );
+  pcPicYuv->setChromaTo( 128 << g_uiBitIncrement );   
+#endif  
+}
+
+template <BlenMod iBM, Bool bBitInc> RMDist
+TRenSingleModelC<iBM,bBitInc>::getDistVideo( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+{
+  AOF(false);
+  return 0;
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::setVideo( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+{
+  AOF(false);
+}
+
+
+
+template <BlenMod iBM, Bool bBitInc> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetViewRow( Int iPosY )
+{
+  m_pcInputSamplesRow[0] = m_pcInputSamples[0] + m_iInputSamplesStride  * iPosY;
+  m_pcInputSamplesRow[1] = m_pcInputSamples[1] + m_iInputSamplesStride  * iPosY;
+  m_pcOutputSamplesRow   = m_pcOutputSamples   + m_iOutputSamplesStride * iPosY;  
+
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xIncViewRow( )
+{
+  m_pcInputSamplesRow[0] += m_iInputSamplesStride ;
+  m_pcInputSamplesRow[1] += m_iInputSamplesStride ;
+  m_pcOutputSamplesRow   += m_iOutputSamplesStride;  
+}
+#if LGE_VSO_EARLY_SKIP_A0093
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline RMDist 
+TRenSingleModelC<iBM,bBitInc>::xRenderL( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Bool bFast)
+#else
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline RMDist 
+TRenSingleModelC<iBM,bBitInc>::xRenderL( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData)
+#endif
+{
+  const Int iCurViewPos   = 0;
+  const Int iOtherViewPos = 1;
+
+  m_iCurViewPos   = iCurViewPos  ; 
+  m_iOtherViewPos = iOtherViewPos;
+
+  m_piNewDepthData   = piNewData;
+  m_iNewDataWidth    = iWidth;
+  m_iStartChangePosX = iStartPosX;
+
+  if ((iWidth == 0) || (iHeight == 0))
+    return 0;
+
+  // Get Data
+  m_ppiCurLUT      = m_appiShiftLut   [iCurViewPos];
+  xSetViewRow      ( iStartPosY);
+
+  // Init Start
+  RMDist iError = 0;
+  Int   iStartChangePos;
+
+  iStartChangePos = m_iStartChangePosX;
+
+  for (Int iPosY = iStartPosY; iPosY < iStartPosY + iHeight; iPosY++ )
+  {
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    if( m_bEarlySkip && bFast )
+    {
+      if ( m_pbHorSkip[iPosY-iStartPosY] )
+      {
+        xIncViewRow();
+        m_piNewDepthData += iStride;
+        continue;
+      }
+    }
+#endif
+    m_bInOcclusion = false;
+
+    Int iLastSPos;
+    Int iEndChangePos         = m_iStartChangePosX + iWidth - 1;
+    Int iPosXinNewData        = iWidth - 1;
+    Int iMinChangedSPos       = m_iSampledWidth;
+
+    if ( iEndChangePos == ( m_iWidth -1 )) // Special processing for rightmost depth sample
+    {
+      m_iCurDepth           = m_piNewDepthData[iPosXinNewData];
+      Int iCurSPos          = xShiftNewData(iEndChangePos, iPosXinNewData);
+      m_iLastOccludedSPos   = iCurSPos + 1;
+      m_iLastOccludedSPosFP = xRangeLeftL( m_iLastOccludedSPos );
+      xExtrapolateMarginL<bSet>  ( iCurSPos, iEndChangePos, iError );
+
+      iMinChangedSPos       = Min( iMinChangedSPos, (iEndChangePos << m_iShiftPrec) - m_ppiCurLUT[0][ RenModRemoveBitInc( Max(m_pcInputSamplesRow[iCurViewPos][iEndChangePos].iD, m_piNewDepthData[iPosXinNewData] )) ]);
+      iLastSPos             = iCurSPos;
+      m_iLastDepth          = m_iCurDepth;
+
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][iEndChangePos].iD = m_piNewDepthData[iPosXinNewData];
+      }
+
+      iPosXinNewData--;
+      iEndChangePos--;
+    }
+    else
+    {
+      iLastSPos    = xShift(iEndChangePos+1);
+      m_iLastDepth = m_pcInputSamplesRow [iCurViewPos][iEndChangePos+1].iD;
+      xInitRenderPartL( iEndChangePos, iLastSPos );
+    }
+
+    //// RENDER NEW DATA
+    Int iCurPosX;
+    for ( iCurPosX = iEndChangePos; iCurPosX >= iStartChangePos; iCurPosX-- )
+    {
+      // Get minimal changed sample position
+
+      iMinChangedSPos = Min( iMinChangedSPos, (iCurPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RenModRemoveBitInc( Max(m_pcInputSamplesRow[iCurViewPos][iCurPosX].iD, m_piNewDepthData[iPosXinNewData] )) ]);
+      Int iCurSPos    = xShiftNewData(iCurPosX,iPosXinNewData);
+      m_iCurDepth     = m_piNewDepthData[iPosXinNewData];
+      xRenderRangeL<bSet>(iCurSPos, iLastSPos, iCurPosX, iError );
+      iLastSPos       = iCurSPos;
+      m_iLastDepth    = m_iCurDepth;
+
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][iCurPosX].iD = m_piNewDepthData[iPosXinNewData];
+      }
+
+      iPosXinNewData--;
+    }
+
+    //// RE-RENDER DATA LEFT TO NEW DATA
+    while ( iCurPosX >= 0 )
+    {
+      Int iCurSPos = xShift(iCurPosX);
+
+      m_iCurDepth  = m_pcInputSamplesRow[iCurViewPos][iCurPosX].iD;
+      xRenderRangeL<bSet>( iCurSPos, iLastSPos, iCurPosX, iError );
+
+      if ( iCurSPos < iMinChangedSPos )
+      {
+          break;
+      }
+
+      iCurPosX--;
+      iLastSPos    = iCurSPos;
+      m_iLastDepth = m_iCurDepth;
+    }
+
+
+    xIncViewRow();
+    m_piNewDepthData += iStride;
+  }
+  return iError;
+}
+
+#ifdef  LGE_VSO_EARLY_SKIP_A0093
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline RMDist
+TRenSingleModelC<iBM,bBitInc>::xRenderR( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData , Bool bFast)
+#else
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline RMDist
+TRenSingleModelC<iBM,bBitInc>::xRenderR( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
+#endif
+{
+
+  const Int iCurViewPos   = 1;
+  const Int iOtherViewPos = 0;
+
+  m_iCurViewPos      = iCurViewPos;
+  m_iOtherViewPos    = iOtherViewPos;
+
+  m_piNewDepthData   = piNewData;
+  m_iNewDataWidth    = iWidth;
+  m_iStartChangePosX = iStartPosX;
+
+  if ((iWidth == 0) || (iHeight == 0))
+    return 0;
+
+  // Get Data
+  m_ppiCurLUT      = m_appiShiftLut   [iCurViewPos];
+  xSetViewRow      ( iStartPosY);
+
+  // Init Start
+  RMDist iError = 0;
+  Int   iEndChangePos;
+
+  iEndChangePos = m_iStartChangePosX + iWidth - 1;
+
+  for (Int iPosY = iStartPosY; iPosY < iStartPosY + iHeight; iPosY++ )
+  {
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+    if( m_bEarlySkip && bFast )
+    {
+      if ( m_pbHorSkip[iPosY-iStartPosY] )
+      {
+        xIncViewRow();
+        m_piNewDepthData += iStride;
+        continue;
+      }
+    }
+#endif
+    m_bInOcclusion = false;
+
+    Int iLastSPos;
+    Int iStartChangePos       = m_iStartChangePosX;
+    Int iPosXinNewData        = 0;
+    Int iMaxChangedSPos = -1;
+
+    if ( iStartChangePos == 0 ) // Special processing for leftmost depth sample
+    {
+      m_iCurDepth           = m_piNewDepthData[iPosXinNewData];
+      Int iCurSPos          = xShiftNewData(iStartChangePos, iPosXinNewData);
+      m_iLastOccludedSPos   = iCurSPos - 1;
+      m_iLastOccludedSPosFP = xRangeRightR( m_iLastOccludedSPos );
+      xExtrapolateMarginR<bSet>     ( iCurSPos, iStartChangePos, iError );
+
+      iMaxChangedSPos       = Max( iMaxChangedSPos, (iStartChangePos << m_iShiftPrec) - m_ppiCurLUT[0][ RenModRemoveBitInc( Max(m_pcInputSamplesRow[iCurViewPos][iStartChangePos].iD, m_piNewDepthData[iPosXinNewData] )) ]);
+      iLastSPos             = iCurSPos;
+      m_iLastDepth          = m_iCurDepth;
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][iStartChangePos].iD = m_piNewDepthData[iPosXinNewData];
+      }
+
+
+      iPosXinNewData++;
+      iStartChangePos++;
+    }
+    else
+    {
+      iLastSPos   = xShift(iStartChangePos-1);
+
+      m_iLastDepth = m_pcInputSamplesRow[iCurViewPos][iStartChangePos-1].iD;
+      xInitRenderPartR( iStartChangePos, iLastSPos );
+    }
+
+    //// RENDER NEW DATA
+    Int iCurPosX;
+    for ( iCurPosX = iStartChangePos; iCurPosX <= iEndChangePos; iCurPosX++ )
+    {
+      // Get minimal changed sample position
+
+      iMaxChangedSPos = Max( iMaxChangedSPos, (iCurPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RenModRemoveBitInc( Max(m_pcInputSamplesRow[iCurViewPos][iCurPosX].iD, m_piNewDepthData[iPosXinNewData] )) ]);
+      Int iCurSPos    = xShiftNewData(iCurPosX,iPosXinNewData);
+      m_iCurDepth     = m_piNewDepthData[iPosXinNewData];
+      xRenderRangeR<bSet>(iCurSPos, iLastSPos, iCurPosX, iError );
+      iLastSPos      = iCurSPos;
+      m_iLastDepth    = m_iCurDepth;
+
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][iCurPosX].iD = m_piNewDepthData[iPosXinNewData];
+      }
+
+      iPosXinNewData++;
+    }
+
+    //// RE-RENDER DATA LEFT TO NEW DATA
+    while ( iCurPosX < m_iWidth )
+    {
+      Int iCurSPos = xShift(iCurPosX);
+
+      m_iCurDepth  = m_pcInputSamplesRow[iCurViewPos][iCurPosX].iD;
+      xRenderRangeR<bSet>( iCurSPos, iLastSPos, iCurPosX, iError );
+
+      if ( iCurSPos > iMaxChangedSPos )
+      {
+          break;
+        }
+      iCurPosX++;
+      iLastSPos    = iCurSPos;
+      m_iLastDepth = m_iCurDepth;
+    }
+
+    xIncViewRow();
+    m_piNewDepthData += iStride;
+  }
+  return iError;
+}
+
+
+template <BlenMod iBM, Bool bBitInc> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xInitRenderPartL(  Int iEndChangePos, Int iLastSPos )
+{
+  const Int iCurViewPos = 0; 
+  // GET MINIMAL OCCLUDED SAMPLE POSITION
+  Int iCurPosX           = iEndChangePos;
+
+
+  if ( ( iCurPosX + 1 < m_iWidth ) && (m_pcInputSamplesRow[iCurViewPos][ iCurPosX + 1].bOccluded ) )
+  {
+    iCurPosX++;
+
+    while ( (iCurPosX + 1 < m_iWidth) &&  (m_pcInputSamplesRow[iCurViewPos][ iCurPosX + 1].bOccluded  )  )
+
+      iCurPosX++;
+
+    if ( iCurPosX + 1 < m_iWidth )
+    {
+      iCurPosX++;
+      m_iLastOccludedSPos = xShift(iCurPosX);
+    }
+    else
+    {
+      m_iLastOccludedSPos = xShift(iCurPosX) + 1;
+    }
+
+    m_iLastOccludedSPosFP = xRoundL( m_iLastOccludedSPos );
+  }
+  else
+  {
+    m_iLastOccludedSPos   = iLastSPos+1;
+    m_iLastOccludedSPosFP = xRangeLeftL( m_iLastOccludedSPos );
+  }
+
+  m_bInOcclusion = iLastSPos >= m_iLastOccludedSPos;
+};
+
+template <BlenMod iBM, Bool bBitInc> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xInitRenderPartR(  Int iStartChangePos, Int iLastSPos )
+{
+    const Int iCurViewPos = 1; 
+  // GET MINIMAL OCCLUDED SAMPLE POSITION
+  Int iCurPosX           = iStartChangePos;
+
+  if ( ( iCurPosX - 1 > -1 ) && (m_pcInputSamplesRow[iCurViewPos][ iCurPosX - 1].bOccluded  ) )
+  {
+    iCurPosX--;
+
+    while ( (iCurPosX - 1 > -1 ) &&  (m_pcInputSamplesRow[iCurViewPos][ iCurPosX - 1].bOccluded  )  )
+      iCurPosX--;
+
+    if ( iCurPosX - 1 > -1 )
+    {
+      iCurPosX--;
+      m_iLastOccludedSPos = xShift(iCurPosX);
+    }
+    else
+    {
+      m_iLastOccludedSPos = xShift(iCurPosX) - 1;
+    }
+    m_iLastOccludedSPosFP = xRoundR( m_iLastOccludedSPos );
+  }
+  else
+  {
+    m_iLastOccludedSPos   = iLastSPos-1;
+    m_iLastOccludedSPosFP = xRangeRightR( m_iLastOccludedSPos );
+  }
+
+  m_bInOcclusion = iLastSPos <= m_iLastOccludedSPos;
+};
+
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xRenderShiftedRangeL(Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError )
+{
+  assert( iCurSPos <= iLastSPos );
+  //assert( iRightSPos < m_iWidth );
+
+  Int iDeltaSPos = iLastSPos - iCurSPos;
+  if ( iDeltaSPos > m_iGapTolerance )
+  {
+    xFillHoleL<bSet>( iCurSPos, iLastSPos, iCurPos, riError );
+  }
+  else
+  {
+    if (iLastSPos < 0 )
+      return;
+
+    RM_AOT( iDeltaSPos    > m_iGapTolerance );
+
+    m_iThisDepth = m_iCurDepth;
+    for (Int iFillSPos = Max(0, xRangeLeftL(iCurSPos) ); iFillSPos <= min(xRangeRightL( iLastSPos ) ,m_iLastOccludedSPosFP-1); iFillSPos++ )
+    {
+      Int iDeltaCurSPos  = (iFillSPos << m_iShiftPrec) - iCurSPos;
+
+      RM_AOT( iDeltaCurSPos > iDeltaSPos );
+      RM_AOT( iDeltaCurSPos < 0 );
+      RM_AOT( m_aaiSubPelShiftL[iDeltaSPos][iDeltaCurSPos] == 0xdeaddead);
+
+      xSetShiftedPelL<bSet>( iCurPos, m_aaiSubPelShiftL[iDeltaSPos][iDeltaCurSPos], iFillSPos, REN_IS_FILLED, riError );
+    }
+  };
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xRenderShiftedRangeR(Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError )
+{
+  assert( iCurSPos >= iLastSPos );
+
+  Int iDeltaSPos = iCurSPos - iLastSPos;
+  if ( iDeltaSPos > m_iGapTolerance )
+  {
+    xFillHoleR<bSet>( iCurSPos, iLastSPos, iCurPos, riError );
+  }
+  else
+  {
+    if (iLastSPos > m_iSampledWidth - 1 )
+      return;
+
+    m_iThisDepth = m_iCurDepth;
+    RM_AOT( iDeltaSPos    > m_iGapTolerance );
+    for (Int iFillSPos = max(m_iLastOccludedSPosFP+1, xRangeLeftR(iLastSPos) ); iFillSPos <= min(xRangeRightR( iCurSPos ) ,m_iWidth -1); iFillSPos++ )
+    {
+      Int iDeltaCurSPos  = (iFillSPos << m_iShiftPrec) - iLastSPos;
+
+      RM_AOT( iDeltaCurSPos > iDeltaSPos );
+      RM_AOT( iDeltaCurSPos < 0 );
+      RM_AOT( m_aaiSubPelShiftR[iDeltaSPos][iDeltaCurSPos] == 0xdeaddead);
+
+      xSetShiftedPelR<bSet>( iCurPos, m_aaiSubPelShiftR[iDeltaSPos][iDeltaCurSPos], iFillSPos, REN_IS_FILLED, riError );
+    }
+  };
+}
+
+
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xRenderRangeL(Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError )
+{
+  const Int iCurViewPos = 0; 
+  if (  !m_bInOcclusion )
+  {
+    if ( iCurSPos >= iLastSPos )
+    {
+      m_iLastOccludedSPos = iLastSPos;
+
+      Int iRightSPosFP = xRoundL( iLastSPos );
+      if ( ( iRightSPosFP == xRangeRightL(iLastSPos)) && (iRightSPosFP >= 0) )
+      {
+        m_iThisDepth = m_iLastDepth;
+
+        xSetShiftedPelL<bSet>( iCurPos+1, 0, iRightSPosFP, REN_IS_FILLED, riError );
+      }
+      m_iLastOccludedSPosFP = iRightSPosFP;
+
+      m_bInOcclusion = true;
+
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = true;
+      }
+    }
+    else
+    {
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = false;
+      }
+
+      xRenderShiftedRangeL<bSet>(iCurSPos, iLastSPos, iCurPos, riError );
+    }
+  }
+  else
+  {
+    if ( iCurSPos < m_iLastOccludedSPos )
+    {
+      m_bInOcclusion = false;
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = false;
+      }
+
+      xRenderShiftedRangeL<bSet>(iCurSPos, iLastSPos, iCurPos, riError );
+    }
+    else
+    {
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = true;
+      }
+    }
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xRenderRangeR(Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError )
+{
+  const Int iCurViewPos = 1; 
+  // Find out if current sample is occluded
+  if (  !m_bInOcclusion )
+  {
+    if ( iCurSPos <= iLastSPos )
+    {
+      m_iLastOccludedSPos = iLastSPos;
+
+      Int iLeftSPosFP = xRoundR( iLastSPos );
+      if ( ( iLeftSPosFP == xRangeLeftR(iLastSPos)) && (iLeftSPosFP <= m_iWidth - 1) )
+      {
+        m_iThisDepth = m_iLastDepth;
+        xSetShiftedPelR<bSet>( iCurPos-1,1 << m_iShiftPrec , iLeftSPosFP, REN_IS_FILLED, riError );
+      }
+      m_iLastOccludedSPosFP = iLeftSPosFP;
+
+      m_bInOcclusion = true;
+
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = true;
+      }
+    }
+    else
+    {
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = false;
+      }
+
+      xRenderShiftedRangeR<bSet>(iCurSPos, iLastSPos, iCurPos, riError );
+    }
+  }
+  else
+  {
+    if ( iCurSPos > m_iLastOccludedSPos )
+    {
+      m_bInOcclusion = false;
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = false;
+      }
+
+      xRenderShiftedRangeR<bSet>(iCurSPos, iLastSPos, iCurPos, riError );
+    }
+    else
+    {
+      if ( bSet )
+      {
+        m_pcInputSamplesRow[iCurViewPos][ iCurPos ].bOccluded  = true;
+      }
+    }
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xFillHoleL( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError )
+{
+  if (iLastSPos < 0)
+    return;
+
+  Int iStartFillSPos = iCurSPos;
+  Int iStartFillPos  = iCurPos;
+  Int iLastPos      = iCurPos + 1;
+
+  Int iStartFillSPosFP = xRangeLeftL(iStartFillSPos);
+
+  if (iStartFillSPosFP == xRoundL(iStartFillSPos))
+  {
+    if ((iStartFillSPosFP >= 0) && (iStartFillSPosFP < m_iLastOccludedSPosFP) )
+    {
+      m_iThisDepth = m_iCurDepth;
+      xSetShiftedPelL<bSet>    ( iStartFillPos, 0, iStartFillSPosFP, REN_IS_FILLED, riError );
+    }
+  }
+  else
+  {
+    iStartFillSPosFP--;
+  }
+
+  m_iThisDepth = m_iLastDepth;
+  for (Int iFillSPos = Max(iStartFillSPosFP+1,0); iFillSPos <= min(xRangeRightL( iLastSPos ), m_iLastOccludedSPosFP-1 ); iFillSPos++ )
+  {
+    xSetShiftedPelL<bSet>( iLastPos, 0,  iFillSPos, REN_IS_HOLE, riError );
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xFillHoleR( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError )
+{
+  if (iLastSPos < 0)
+    return;
+
+  Int iStartFillSPos = iCurSPos;
+  Int iEndFillPos    = iCurPos;
+  Int iLastPos       = iCurPos - 1;
+
+  Int iStartFillSPosFP = xRangeRightR(iStartFillSPos);
+
+  if (iStartFillSPosFP == xRoundR(iStartFillSPos))
+  {
+    if ((iStartFillSPosFP < m_iWidth) && (iStartFillSPosFP > m_iLastOccludedSPosFP) )
+    {
+      m_iThisDepth = m_iCurDepth;
+      xSetShiftedPelR<bSet>( iEndFillPos, 1 << m_iShiftPrec , iStartFillSPosFP, REN_IS_FILLED, riError );
+    }
+  }
+  else
+  {
+    iStartFillSPosFP++;
+  }
+
+  m_iThisDepth = m_iLastDepth;
+  for (Int iFillSPos = max(xRangeLeftR( iLastSPos ), m_iLastOccludedSPosFP+1); iFillSPos <= min(iStartFillSPosFP,m_iWidth)-1 ; iFillSPos++ )
+  {
+    xSetShiftedPelR<bSet>( iLastPos, 1 << m_iShiftPrec, iFillSPos, REN_IS_HOLE, riError );
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xExtrapolateMarginL(Int iCurSPos, Int iCurPos, RMDist& riError )
+{
+//  if (iLeftSPos < 0 )
+//    return;
+
+  Int iSPosFullPel = Max(0,xRangeLeftL(iCurSPos));
+
+  m_iThisDepth = m_iCurDepth;
+  if (iSPosFullPel < m_iWidth)
+  {
+    xSetShiftedPelL<bSet>( iCurPos, 0, iSPosFullPel, REN_IS_FILLED, riError );
+  }
+
+  for (Int iFillSPos = iSPosFullPel +1; iFillSPos < m_iWidth; iFillSPos++ )
+  {
+    xSetShiftedPelL<bSet>( iCurPos, 0, iFillSPos, REN_IS_HOLE, riError );
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xExtrapolateMarginR(Int iCurSPos, Int iCurPos, RMDist& riError )
+{
+  //  if (iLeftSPos < 0 )
+  //    return;
+
+  Int iSPosFullPel = Min(m_iWidth-1,xRangeRightR(iCurSPos));
+
+  m_iThisDepth = m_iCurDepth;
+  if (iSPosFullPel > -1)
+  {
+    xSetShiftedPelR<bSet>( iCurPos, 1 << m_iShiftPrec, iSPosFullPel, REN_IS_FILLED, riError );
+  }
+
+  for (Int iFillSPos = iSPosFullPel -1; iFillSPos > -1; iFillSPos-- )
+  {
+    xSetShiftedPelR<bSet>( iCurPos , 1 << m_iShiftPrec, iFillSPos, REN_IS_HOLE, riError );
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xShiftNewData( Int iPosX, Int iPosInNewData )
+{
+  RM_AOT( iPosInNewData <               0 );
+  RM_AOF( iPosInNewData < m_iNewDataWidth );
+
+  return (iPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RenModRemoveBitInc( m_piNewDepthData[iPosInNewData] )];
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xShift( Int iPosX )
+{
+ RM_AOT( iPosX <        0);
+ RM_AOF( iPosX < m_iWidth);
+
+ return (iPosX  << m_iShiftPrec) - m_ppiCurLUT[0][ RenModRemoveBitInc( m_pcInputSamplesRow[m_iCurViewPos][iPosX].iD )];
+}
+
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xShift( Int iPos, Int iPosInNewData )
+{
+  if ( (iPosInNewData >= 0) && (iPosInNewData < m_iNewDataWidth) )
+  {
+    return xShiftNewData(iPos ,iPosInNewData );
+  }
+  else
+  {
+    return xShift(iPos);
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xRangeLeftL( Int iPos )
+{
+  return  ( iPos +  (1 << m_iShiftPrec) - 1) >> m_iShiftPrec;
+}
+
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xRangeLeftR( Int iPos )
+{
+
+  return  xRangeRightR( iPos ) + 1;
+}
+
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xRangeRightL( Int iPos )
+{
+  return xRangeLeftL(iPos) - 1;
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xRangeRightR( Int iPos )
+{
+  return iPos >> m_iShiftPrec;
+}
+
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xRoundL( Int iPos )
+{
+  return  (iPos + (( 1 << m_iShiftPrec ) >> 1 )) >> m_iShiftPrec;
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xRoundR( Int iPos )
+{
+  return  (m_iShiftPrec == 0) ? iPos : xRoundL(iPos - 1);
+}
+
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xSetPels( Pel* piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Pel iVal )
+{
+  for (Int iYPos = 0; iYPos < iHeight; iYPos++)
+  {
+    for (Int iXPos = 0; iXPos < iWidth; iXPos++)
+    {
+      piPelSource[iXPos] = iVal;
+    }
+    piPelSource += iSourceStride;
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xSetInts( Int* piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Int iVal )
+{
+  for (Int iYPos = 0; iYPos < iHeight; iYPos++)
+  {
+    for (Int iXPos = 0; iXPos < iWidth; iXPos++)
+    {
+      piPelSource[iXPos] = iVal;
+    }
+    piPelSource += iSourceStride;
+  }
+}
+
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xSetBools( Bool* pbPelSource , Int iSourceStride, Int iWidth, Int iHeight, Bool bVal )
+{
+  for (Int iYPos = 0; iYPos < iHeight; iYPos++)
+  {
+    for (Int iXPos = 0; iXPos < iWidth; iXPos++)
+    {
+      pbPelSource[iXPos] = bVal;
+    }
+    pbPelSource += iSourceStride;
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetShiftedPelL(Int iSourcePos, Int iSubSourcePos, Int iTargetSPos, Pel iFilled, RMDist& riError )
+{
+  RM_AOT( iSourcePos    <  0                   );
+  RM_AOT( iSourcePos    >= m_iWidth            );
+  RM_AOT( iSubSourcePos < 0                    );
+  RM_AOT( iSubSourcePos >  (1 << m_iShiftPrec) );
+  RM_AOT( iTargetSPos   < 0                    );
+  RM_AOT( iTargetSPos   >= m_iWidth            );  
+
+  RenModelOutPels* pcOutSample = m_pcOutputSamplesRow              + iTargetSPos;
+  RenModelInPels * pcInSample  = m_pcInputSamplesRow[VIEWPOS_LEFT] + iSourcePos ;
+
+  if ( iBM != BLEND_NONE )
+  {
+    xSetShiftedPelBlendL<bSet>  (pcInSample, iSubSourcePos, pcOutSample, iFilled, riError);
+  }
+  else
+  {
+    xSetShiftedPelNoBlendL<bSet>(pcInSample, iSubSourcePos, pcOutSample, iFilled, riError);
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetShiftedPelNoBlendL(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError )
+{
+  if ( bSet )
+  { 
+    // Filled
+    pcOutSample->iFilledLeft = iFilled;
+
+    // Yuv
+    pcOutSample->iYLeft  = pcInSample->aiY[iSubSourcePos];
+#if HHI_VSO_COLOR_PLANES
+    pcOutSample->iULeft  = pcInSample->aiU[iSubSourcePos];
+    pcOutSample->iVLeft  = pcInSample->aiV[iSubSourcePos];
+
+    pcOutSample->iError = xGetDist( pcOutSample->iYLeft - pcOutSample->iYRef,
+                                    pcOutSample->iULeft - pcOutSample->iURef,    
+                                    pcOutSample->iVLeft - pcOutSample->iVRef
+                                  );    
+#else
+    pcOutSample->iError = xGetDist( pcOutSample->iYLeft - pcOutSample->iYRef );    
+#endif    
+    
+  }
+  else
+  { 
+#if HHI_VSO_COLOR_PLANES
+    riError += xGetDist( pcInSample->aiY[iSubSourcePos] - pcOutSample->iYRef,
+                         pcInSample->aiU[iSubSourcePos] - pcOutSample->iURef,
+                         pcInSample->aiV[iSubSourcePos] - pcOutSample->iVRef
+                       );
+#else               
+    riError += xGetDist( pcInSample->aiY[iSubSourcePos] - pcOutSample->iYRef );
+#endif
+
+    riError -= pcOutSample->iError;
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetShiftedPelBlendL(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError )
+{
+  Pel piBlendedValueY;
+#if HHI_VSO_COLOR_PLANES
+  Pel piBlendedValueU;
+  Pel piBlendedValueV;
+#endif
+
+  xGetBlendedValue (
+    pcInSample ->aiY[iSubSourcePos],
+    pcOutSample->iYRight,    
+#if HHI_VSO_COLOR_PLANES
+    pcInSample ->aiU[iSubSourcePos],
+    pcOutSample->iURight,    
+    pcInSample ->aiV[iSubSourcePos],
+    pcOutSample->iVRight,    
+#endif
+    m_piInvZLUTLeft [RenModRemoveBitInc(m_iThisDepth)        ],
+    m_piInvZLUTRight[RenModRemoveBitInc(pcOutSample->iDRight)],
+    iFilled,
+    pcOutSample->iFilledRight  ,
+    piBlendedValueY
+#if HHI_VSO_COLOR_PLANES
+    , piBlendedValueU,
+    piBlendedValueV
+#endif
+    );
+
+  if ( bSet )
+  {    
+    // Set values
+    pcOutSample->iDLeft      = m_iThisDepth;
+    pcOutSample->iYLeft      = pcInSample ->aiY[iSubSourcePos];
+    pcOutSample->iYBlended   = piBlendedValueY;    
+#if HHI_VSO_COLOR_PLANES  
+    pcOutSample->iULeft      = pcInSample ->aiU[iSubSourcePos];
+    pcOutSample->iUBlended   = piBlendedValueU;    
+    pcOutSample->iVLeft      = pcInSample ->aiV[iSubSourcePos];
+    pcOutSample->iVBlended   = piBlendedValueV;    
+#endif
+    pcOutSample->iFilledLeft = iFilled;
+
+    // Get Error
+    Int iDiffY = pcOutSample->iYRef - piBlendedValueY;
+#if HHI_VSO_COLOR_PLANES
+    Int iDiffU = pcOutSample->iURef - piBlendedValueU;
+    Int iDiffV = pcOutSample->iVRef - piBlendedValueV;
+    pcOutSample->iError  = xGetDist(iDiffY, iDiffU, iDiffV );
+#else
+    pcOutSample->iError  = xGetDist(iDiffY );
+#endif
+  }
+  else
+  {
+    Int iDiffY = pcOutSample->iYRef - piBlendedValueY;
+#if HHI_VSO_COLOR_PLANES
+    Int iDiffU = pcOutSample->iURef - piBlendedValueU;
+    Int iDiffV = pcOutSample->iVRef - piBlendedValueV;
+    riError   += ( xGetDist( iDiffY, iDiffU, iDiffV ) - pcOutSample->iError );
+
+#else
+    riError   += ( xGetDist( iDiffY ) - pcOutSample->iError  );
+#endif
+
+  }
+}
+
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetShiftedPelR(Int iSourcePos, Int iSubSourcePos, Int iTargetSPos, Pel iFilled, RMDist& riError )
+{
+  RM_AOT( iSourcePos    <  0                     );
+  RM_AOT( iSourcePos    >= m_iWidth              );
+  RM_AOT( iSubSourcePos <  0                     );
+  RM_AOT( iSubSourcePos >= (1 << m_iShiftPrec)+1 );
+  RM_AOT( iTargetSPos   < 0                      );
+  RM_AOT( iTargetSPos   >= m_iWidth              );  
+
+  RenModelOutPels* pcOutSample = m_pcOutputSamplesRow               + iTargetSPos;
+  RenModelInPels * pcInSample  = m_pcInputSamplesRow[VIEWPOS_RIGHT] + iSourcePos ;
+
+  if ( iBM != BLEND_NONE )
+  {
+    xSetShiftedPelBlendR<bSet>   (pcInSample, iSubSourcePos, pcOutSample, iFilled, riError);
+  }
+  else
+  {
+    xSetShiftedPelNoBlendR<bSet> (pcInSample, iSubSourcePos, pcOutSample, iFilled, riError);
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetShiftedPelNoBlendR(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError )
+{
+  if ( bSet )
+  { 
+    // Filled
+    pcOutSample->iFilledRight = iFilled;
+
+    // Yuv
+    pcOutSample->iYRight  = pcInSample->aiY[iSubSourcePos];
+#if HHI_VSO_COLOR_PLANES
+    pcOutSample->iURight  = pcInSample->aiU[iSubSourcePos];
+    pcOutSample->iVRight  = pcInSample->aiV[iSubSourcePos];
+
+    pcOutSample->iError = xGetDist( 
+      pcOutSample->iYRight - pcOutSample->iYRef,
+      pcOutSample->iURight - pcOutSample->iURef,    
+      pcOutSample->iVRight - pcOutSample->iVRef
+      );    
+#else
+    pcOutSample->iError = xGetDist( pcOutSample->iYRight - pcOutSample->iYRef );    
+#endif    
+
+  }
+  else
+  { 
+#if HHI_VSO_COLOR_PLANES
+    riError += xGetDist( pcInSample->aiY[iSubSourcePos] - pcOutSample->iYRef,
+      pcInSample->aiU[iSubSourcePos] - pcOutSample->iURef,
+      pcInSample->aiV[iSubSourcePos] - pcOutSample->iVRef
+      );
+#else               
+    riError += xGetDist( pcInSample->aiY[iSubSourcePos] - pcOutSample->iYRef );
+#endif
+
+    riError -= pcOutSample->iError;
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> template<Bool bSet> __inline Void
+TRenSingleModelC<iBM,bBitInc>::xSetShiftedPelBlendR(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError )
+{
+  Pel piBlendedValueY;
+#if HHI_VSO_COLOR_PLANES
+  Pel piBlendedValueU;
+  Pel piBlendedValueV;
+#endif
+
+  xGetBlendedValue (
+    pcOutSample->iYLeft, 
+    pcInSample ->aiY[iSubSourcePos],        
+#if HHI_VSO_COLOR_PLANES
+    pcOutSample->iULeft,    
+    pcInSample ->aiU[iSubSourcePos],
+    pcOutSample->iVLeft,    
+    pcInSample ->aiV[iSubSourcePos],
+#endif
+    m_piInvZLUTLeft  [RenModRemoveBitInc(pcOutSample->iDLeft)],
+    m_piInvZLUTRight [RenModRemoveBitInc(m_iThisDepth)       ],
+    pcOutSample->iFilledLeft,
+    iFilled,
+    piBlendedValueY
+#if HHI_VSO_COLOR_PLANES
+    , piBlendedValueU,
+    piBlendedValueV
+#endif
+    );
+
+  if ( bSet )
+  {    
+    // Set values
+    pcOutSample->iDRight     = m_iThisDepth;
+    pcOutSample->iYRight     = pcInSample ->aiY[iSubSourcePos];
+    pcOutSample->iYBlended   = piBlendedValueY;    
+#if HHI_VSO_COLOR_PLANES  
+    pcOutSample->iURight     = pcInSample ->aiU[iSubSourcePos];
+    pcOutSample->iUBlended   = piBlendedValueU;    
+    pcOutSample->iVRight     = pcInSample ->aiV[iSubSourcePos];
+    pcOutSample->iVBlended   = piBlendedValueV;    
+#endif
+    pcOutSample->iFilledRight = iFilled;
+
+    // Get Error
+    Int iDiffY = pcOutSample->iYRef - piBlendedValueY;
+#if HHI_VSO_COLOR_PLANES
+    Int iDiffU = pcOutSample->iURef - piBlendedValueU;
+    Int iDiffV = pcOutSample->iVRef - piBlendedValueV;
+    pcOutSample->iError  = xGetDist(iDiffY, iDiffU, iDiffV );
+#else
+    pcOutSample->iError  = xGetDist(iDiffY );
+#endif
+  }
+  else
+  {
+    Int iDiffY = pcOutSample->iYRef - piBlendedValueY;
+#if HHI_VSO_COLOR_PLANES
+    Int iDiffU = pcOutSample->iURef - piBlendedValueU;
+    Int iDiffV = pcOutSample->iVRef - piBlendedValueV;
+    riError   += ( xGetDist( iDiffY, iDiffU, iDiffV ) - pcOutSample->iError );
+#else
+    riError   += ( xGetDist( iDiffY ) -  pcOutSample->iError  );
+#endif
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xGetDist( Int iDiffY, Int iDiffU, Int iDiffV )
+{
+
+  if ( !bBitInc )
+  {
+    return (          (iDiffY * iDiffY )
+               +  ((( (iDiffU * iDiffU )
+                     +(iDiffV * iDiffV )
+                    )
+                   ) >> 2
+                  )
+           );
+  }
+  else
+  {
+    return (          ((iDiffY * iDiffY) >> m_iDistShift)
+               +  ((( ((iDiffU * iDiffU) >> m_iDistShift)
+                     +((iDiffV * iDiffV) >> m_iDistShift)
+                    )
+                   ) >> 2
+                  )
+           );
+  
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Int
+TRenSingleModelC<iBM,bBitInc>::xGetDist( Int iDiffY )
+{
+  if ( !bBitInc )
+  {
+    return (iDiffY * iDiffY);
+  }
+  else
+  {
+    return ((iDiffY * iDiffY) >> m_iDistShift);
+  }
+
+}
+
+
+#if HHI_VSO_COLOR_PLANES
+template <BlenMod iBM, Bool bBitInc>  __inline Void
+TRenSingleModelC<iBM,bBitInc>::xGetBlendedValue( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV )
+#else
+template <BlenMod iBM, Bool bBitInc>  __inline Void
+TRenSingleModelC<iBM,bBitInc>::xGetBlendedValue( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY )
+#endif
+{
+
+  RM_AOT( iBM != BLEND_AVRG && iBM != BLEND_LEFT && iBM != BLEND_RIGHT );
+
+  if (iBM != BLEND_AVRG )
+  {
+    if (iBM == BLEND_LEFT )
+    {
+#if HHI_VSO_COLOR_PLANES
+      xGetBlendedValueBM1(  iYL,  iYR,  iUL,  iUR,  iVL,  iVR,  iDepthL,  iDepthR,  iFilledL,  iFilledR,  riY,  riU, riV );
+#else
+      xGetBlendedValueBM1(  iYL,  iYR,  iDepthL,  iDepthR,  iFilledL,  iFilledR,  riY );
+#endif
+    }
+    else
+    {
+#if HHI_VSO_COLOR_PLANES
+      xGetBlendedValueBM2(  iYL,  iYR,  iUL,  iUR,  iVL,  iVR,  iDepthL,  iDepthR,  iFilledL,  iFilledR,  riY,  riU, riV );
+#else
+      xGetBlendedValueBM2(  iYL,  iYR, iDepthL,  iDepthR,  iFilledL,  iFilledR,  riY );
+#endif
+    }
+    return;
+  }
+
+  if (  (iFilledL != REN_IS_HOLE ) && ( iFilledR != REN_IS_HOLE) )
+  {
+    Int iDepthDifference = iDepthR - iDepthL;
+
+    if ( abs ( iDepthDifference ) <= m_iBlendZThres )
+    {
+      if      ((iFilledL == REN_IS_FILLED) && ( iFilledR != REN_IS_FILLED))
+      {
+        riY = xBlend( iYL, iYR, iFilledR >> 1 );
+#if HHI_VSO_COLOR_PLANES
+        riU = xBlend( iUL, iUR, iFilledR >> 1 );
+        riV = xBlend( iVL, iVR, iFilledR >> 1 );
+#endif
+
+      }
+      else if ((iFilledL != REN_IS_FILLED) && ( iFilledR == REN_IS_FILLED))
+      {
+        riY = xBlend( iYR, iYL, (iFilledL >> 1) );
+#if HHI_VSO_COLOR_PLANES
+        riU = xBlend( iUR, iUL, (iFilledL >> 1) );
+        riV = xBlend( iVR, iVL, (iFilledL >> 1) );
+#endif
+      }
+      else
+      {
+        riY = xBlend( iYL, iYR, m_iBlendDistWeight );
+#if HHI_VSO_COLOR_PLANES    
+        riU = xBlend( iUL, iUR, m_iBlendDistWeight );
+        riV = xBlend( iVL, iVR, m_iBlendDistWeight );
+#endif
+      }
+    }
+    else if ( iDepthDifference < 0 )
+    {
+      riY = iYL;
+#if HHI_VSO_COLOR_PLANES
+      riU = iUL;
+      riV = iVL;
+#endif
+    }
+    else
+    {
+      riY = iYR;
+#if HHI_VSO_COLOR_PLANES
+      riU = iUR;
+      riV = iVR;
+#endif
+    }
+  }
+  else if ( (iFilledL == REN_IS_HOLE) && (iFilledR == REN_IS_HOLE))
+  {
+    if ( iDepthR < iDepthL )
+    {
+        riY =  iYR;
+#if HHI_VSO_COLOR_PLANES
+        riU =  iUR;
+        riV =  iVR;
+#endif
+    }
+    else
+    {
+        riY =  iYL;
+#if HHI_VSO_COLOR_PLANES
+        riU =  iUL;
+        riV =  iVL;
+#endif
+    }
+  }
+  else
+  {
+    if (iFilledR == REN_IS_HOLE)
+    {
+        riY = iYL;
+#if HHI_VSO_COLOR_PLANES
+        riU = iUL;
+        riV = iVL;
+#endif
+    }
+    else
+    {
+      riY = iYR;
+#if HHI_VSO_COLOR_PLANES
+      riU = iUR;
+      riV = iVR;
+#endif
+    }
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Void
+#if HHI_VSO_COLOR_PLANES
+TRenSingleModelC<iBM,bBitInc>::xGetBlendedValueBM1( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV )
+#else
+TRenSingleModelC<iBM,bBitInc>::xGetBlendedValueBM1( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY )
+#endif
+{
+  if ( iFilledL == REN_IS_FILLED ||  iFilledR == REN_IS_HOLE )
+  {
+    riY = iYL;
+#if HHI_VSO_COLOR_PLANES
+    riU = iUL;
+    riV = iVL;
+#endif
+  }
+  else if ( iFilledL == REN_IS_HOLE  )
+  {
+    riY = iYR;
+#if HHI_VSO_COLOR_PLANES
+    riU = iUR;
+    riV = iVR;
+#endif
+  }
+  else
+  {
+    riY = xBlend( iYR, iYL, iFilledL );
+#if HHI_VSO_COLOR_PLANES
+    riU = xBlend( iUR, iUL, iFilledL );
+    riV = xBlend( iVR, iUL, iFilledL );
+#endif
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Void
+#if HHI_VSO_COLOR_PLANES
+TRenSingleModelC<iBM,bBitInc>::xGetBlendedValueBM2( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV )
+#else
+TRenSingleModelC<iBM,bBitInc>::xGetBlendedValueBM2( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY )
+#endif
+{
+  if      ( iFilledR == REN_IS_FILLED ||  iFilledL == REN_IS_HOLE )
+  {
+    riY = iYR;
+#if HHI_VSO_COLOR_PLANES
+    riU = iUR;
+    riV = iVR;
+#endif
+  }
+  else if ( iFilledR == REN_IS_HOLE  )
+  {
+    riY = iYL;
+#if HHI_VSO_COLOR_PLANES
+    riU = iUL;
+    riV = iVL;
+#endif
+  }
+  else
+  {
+    riY = xBlend( iYL, iYR, iFilledR );
+#if HHI_VSO_COLOR_PLANES
+    riU = xBlend( iUL, iUR, iFilledR );
+    riV = xBlend( iVL, iUR, iFilledR );
+#endif
+  }
+}
+
+template <BlenMod iBM, Bool bBitInc> __inline Pel
+TRenSingleModelC<iBM,bBitInc>::xBlend( Pel pVal1, Pel pVal2, Int iWeightVal2 )
+{
+  return pVal1  +  (Pel) (  ( (Int) ( pVal2 - pVal1) * iWeightVal2 + (1 << (REN_VDWEIGHT_PREC - 1)) ) >> REN_VDWEIGHT_PREC );
+}
+
+template <BlenMod iBM, Bool bBitInc> Void
+TRenSingleModelC<iBM,bBitInc>::xCopy2PicYuv( Pel** ppiSrcVideoPel, Int* piStrides, TComPicYuv* rpcPicYuvTarget )
+{
+  TRenFilter::copy            ( ppiSrcVideoPel[0], piStrides[0], m_iWidth, m_iUsedHeight, rpcPicYuvTarget->getLumaAddr() +  m_iHorOffset       * rpcPicYuvTarget->getStride() , rpcPicYuvTarget->getStride () );
+  TRenFilter::sampleDown2Tap13( ppiSrcVideoPel[1], piStrides[1], m_iWidth, m_iUsedHeight, rpcPicYuvTarget->getCbAddr  () + (m_iHorOffset >> 1) * rpcPicYuvTarget->getCStride(), rpcPicYuvTarget->getCStride() );
+  TRenFilter::sampleDown2Tap13( ppiSrcVideoPel[2], piStrides[2], m_iWidth, m_iUsedHeight, rpcPicYuvTarget->getCrAddr  () + (m_iHorOffset >> 1) * rpcPicYuvTarget->getCStride(), rpcPicYuvTarget->getCStride() );
+}
+
+template class TRenSingleModelC<BLEND_NONE ,true>;
+template class TRenSingleModelC<BLEND_AVRG ,true>;
+template class TRenSingleModelC<BLEND_LEFT ,true>;
+template class TRenSingleModelC<BLEND_RIGHT,true>;
+
+template class TRenSingleModelC<BLEND_NONE ,false>;
+template class TRenSingleModelC<BLEND_AVRG ,false>;
+template class TRenSingleModelC<BLEND_LEFT ,false>;
+template class TRenSingleModelC<BLEND_RIGHT,false>;
+
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+template <BlenMod iBM, Bool bBitInc> 
+__inline Bool
+TRenSingleModelC<iBM,bBitInc>::xDetectEarlySkipL( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData,Pel* piOrgData, Int iOrgStride)
+{
+  RM_AOF( m_bEarlySkip ); 
+  const Int iCurViewPos = 0;
+  Int** ppiCurLUT       = m_appiShiftLut   [ iCurViewPos ];
+  
+  Bool bNoDiff          = true;   
+  
+  for (Int iPosY=0; iPosY < iHeight; iPosY++)
+  {
+    m_pbHorSkip[iPosY] = true;
+
+    for (Int iPosX = 0; iPosX < iWidth; iPosX++)
+    {
+      Int iDisparityRec = abs(ppiCurLUT[0][ RenModRemoveBitInc(piNewData[iPosX])]);
+      Int iDispartyOrg  = abs(ppiCurLUT[0][ RenModRemoveBitInc(piOrgData[iPosX])]);
+
+      if( iDispartyOrg != iDisparityRec)
+      {
+        m_pbHorSkip[iPosY] = false;
+        bNoDiff            = false;
+        break;
+      }
+    }
+    piNewData += iStride;
+    piOrgData += iOrgStride;
+  }
+  return bNoDiff;
+}
+
+template <BlenMod iBM, Bool bBitInc> 
+__inline Bool
+TRenSingleModelC<iBM,bBitInc>::xDetectEarlySkipR( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData,Pel* piOrgData, Int iOrgStride)
+{
+  RM_AOF( m_bEarlySkip ); 
+  Bool bNoDiff  = true;
+
+  const Int iCurViewPos = 1;
+  Int** ppiCurLUT       = m_appiShiftLut   [ iCurViewPos ];
+
+  for ( Int iPosY = 0; iPosY < iHeight; iPosY++ )
+  {
+    m_pbHorSkip[iPosY] = true;
+
+    for (Int iPosX = 0; iPosX < iWidth; iPosX++)
+    {
+      Int iDisparityRec = abs( ppiCurLUT[0][ RenModRemoveBitInc(piNewData[iPosX])] );
+      Int iDisparityOrg = abs( ppiCurLUT[0][ RenModRemoveBitInc(piOrgData[iPosX])] );
+
+      if( iDisparityRec != iDisparityOrg )
+      {
+        m_pbHorSkip[iPosY] = false;
+        bNoDiff            = false;
+        break;
+      }
+    }
+
+    piNewData += iStride;
+    piOrgData += iOrgStride;
+  }
+  return bNoDiff;
+}
+#endif
+#endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenSingleModel.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenSingleModel.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenSingleModel.h	(revision 438)
@@ -0,0 +1,394 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !QC_MVHEVC_B0046
+#ifndef __TRENSINGLEMODEL__ 
+#define __TRENSINGLEMODEL__
+
+#include "TRenImage.h"
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPicYuv.h"
+#include "../TLibCommon/TypeDef.h"
+#include "../TAppCommon/TAppComCamPara.h"
+
+
+#include <math.h>
+#include <errno.h>
+#include <iostream>
+
+#include <string>
+#include <cstdio>
+#include <cstring>
+
+
+using namespace std;
+
+
+#if HHI_VSO_RM_ASSERTIONS
+#define RM_AOT( exp ) AOT ( exp )
+#define RM_AOF( exp ) AOF ( exp )
+#else
+#define RM_AOT( exp ) ((void)0)
+#define RM_AOF( exp ) ((void)0)
+#endif
+
+#define RenModRemoveBitInc( exp ) bBitInc ? ( RemoveBitIncrement( exp ) ) : ( exp ) 
+
+class TRenSingleModel
+{
+public: 
+
+  virtual ~TRenSingleModel() { }  
+#if LGE_VSO_EARLY_SKIP_A0093
+  virtual Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip ) = 0;
+#else
+  virtual Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode ) = 0;
+#endif
+
+  // Set Frame dependent data
+  virtual Void   setLRView ( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride ) = 0;
+  virtual Void   setupPart ( UInt uiHorOffset,       Int iUsedHeight ) = 0;
+  virtual Void   setup     ( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference ) = 0;
+
+  // Set Data
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  virtual Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel* piOrgData, Int iOrgStride )  = 0;
+#else
+  virtual Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )  = 0;
+#endif
+  virtual Void   setVideo  ( Int iViewPos,     Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData ) = 0;
+
+  // Get Distortion
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  virtual RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData , Int iOrgStride)=0;
+#else
+  virtual RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData ) = 0;
+#endif
+  virtual RMDist getDistVideo  ( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData ) = 0;
+
+  virtual Void   getSynthVideo  ( Int iViewPos, TComPicYuv* pcPicYuv ) = 0;  
+  virtual Void   getSynthDepth  ( Int iViewPos, TComPicYuv* pcPicYuv ) = 0;
+  virtual Void   getRefVideo    ( Int iViewPos, TComPicYuv* pcPicYuv ) = 0;
+};
+
+template < BlenMod iBM, Bool bBitInc >
+class TRenSingleModelC : public TRenSingleModel
+{
+  struct RenModelInPels
+  {
+    // video
+    Pel aiY[5]    ; // y-value
+#if HHI_VSO_COLOR_PLANES
+    Pel aiU[5]    ; // u-value
+    Pel aiV[5]    ; // v-value
+#endif
+    // depth
+    Pel iD        ; // depth
+
+    // state
+    Bool bOccluded; // Occluded
+  };
+
+  struct RenModelOutPels
+  {
+    // video
+    Pel iYLeft    ; 
+    Pel iYRight   ; 
+    Pel iYBlended ; 
+#if HHI_VSO_COLOR_PLANES
+    Pel iULeft    ; 
+    Pel iURight   ; 
+    Pel iUBlended ; 
+    Pel iVLeft    ; 
+    Pel iVRight   ; 
+    Pel iVBlended ; 
+#endif
+    // depth
+    Pel iDLeft    ;
+    Pel iDRight   ; 
+    Pel iDBlended ; 
+
+    // state
+    Int iFilledLeft ; 
+    Int iFilledRight; 
+
+    // error
+    Int  iError   ;
+
+    // reference
+    Pel iYRef    ; 
+#if HHI_VSO_COLOR_PLANES
+    Pel iURef    ; 
+    Pel iVRef    ; 
+#endif        
+  };
+
+
+
+public:
+  TRenSingleModelC();
+  ~TRenSingleModelC();
+
+  // Create Model
+#if LGE_VSO_EARLY_SKIP_A0093
+  Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip  );
+#else
+  Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode );
+#endif
+
+  // Set Frame dependent data
+  Void   setLRView ( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride );
+  Void   setupPart ( UInt uiHorOffset,       Int uiUsedHeight );
+  Void   setup     ( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference );
+
+#if LGE_VSO_EARLY_SKIP_A0093
+  Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel* piOrgData, Int iOrgStride );
+#else
+  Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
+#endif
+  Void   setVideo  ( Int iViewPos,     Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
+
+  // Get Distortion
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData , Int iOrgStride);
+#else
+  RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
+#endif
+  RMDist getDistVideo  ( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
+
+  Void   getSynthVideo  ( Int iViewPos, TComPicYuv* pcPicYuv );  
+  Void   getSynthDepth  ( Int iViewPos, TComPicYuv* pcPicYuv );
+  Void   getRefVideo    ( Int iViewPos, TComPicYuv* pcPicYuv );
+
+private:
+  // Set and inc Current Row
+  __inline Void   xSetViewRow(  Int iPosY );
+  __inline Void   xIncViewRow();
+
+  /////  Rendering /////
+  // Left to Right
+#if LGE_VSO_EARLY_SKIP_A0093
+                      __inline Bool   xDetectEarlySkipL   ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData,Pel* piOrgData, Int iOrgStride );
+                      __inline Bool   xDetectEarlySkipR   ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData,Pel* piOrgData, Int iOrgStride );
+  template<Bool bSet> __inline RMDist xRenderL            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Bool bFast );
+  template<Bool bSet> __inline RMDist xRenderR            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Bool bFast );
+#else
+  template<Bool bSet> __inline RMDist xRenderR            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
+  template<Bool bSet> __inline RMDist xRenderL            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
+#endif
+                      __inline Void   xInitRenderPartL    ( Int iEndChangePos, Int iLastSPos  );
+  template<Bool bSet> __inline Void   xRenderRangeL       ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
+  template<Bool bSet> __inline Void   xRenderShiftedRangeL( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
+  template<Bool bSet> __inline Void   xFillHoleL          ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
+  template<Bool bSet> __inline Void   xExtrapolateMarginL ( Int iCurSPos,                Int iCurPos, RMDist& riError );
+                      __inline Int    xRangeLeftL         ( Int iPos );
+                      __inline Int    xRangeRightL        ( Int iPos );
+                      __inline Int    xRoundL             ( Int iPos );
+
+  // Right to Left
+                      __inline Void   xInitRenderPartR    ( Int iStartChangePos, Int iLastSPos );
+  template<Bool bSet> __inline Void   xRenderShiftedRangeR( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
+  template<Bool bSet> __inline Void   xRenderRangeR       ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
+  template<Bool bSet> __inline Void   xFillHoleR          ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
+  template<Bool bSet> __inline Void   xExtrapolateMarginR ( Int iCurSPos,                Int iCurPos, RMDist& riError );
+                      __inline Int    xRangeLeftR         ( Int iPos );
+                      __inline Int    xRangeRightR        ( Int iPos );
+                      __inline Int    xRoundR             ( Int iPos );
+
+  // Blending
+  template<Bool bSet> __inline Void   xSetShiftedPelBlend ( Int iSourcePos, Int iTargetSPos, Pel iFilled, RMDist& riError );
+
+#if HHI_VSO_COLOR_PLANES
+  __inline Void   xGetBlendedValue    ( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV );
+  __inline Void   xGetBlendedValueBM1 ( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV );
+  __inline Void   xGetBlendedValueBM2 ( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV );
+#else
+  __inline Void   xGetBlendedValue    ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
+  __inline Void   xGetBlendedValueBM1 ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
+  __inline Void   xGetBlendedValueBM2 ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
+#endif
+  __inline Pel    xBlend              ( Pel pVal1, Pel pVal2, Int iWeightVal2 );
+
+  // General
+  template<Bool bSet> __inline Void xSetShiftedPelL       (Int iSourcePos,             Int iSubSourcePos, Int iTargetSPos,              Pel iFilled, RMDist& riError );
+  template<Bool bSet> __inline Void xSetShiftedPelBlendL  (RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
+  template<Bool bSet> __inline Void xSetShiftedPelNoBlendL(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
+
+  template<Bool bSet> __inline Void xSetShiftedPelR       (Int iSourcePos,             Int iSubSourcePos, Int iTargetSPos,              Pel iFilled, RMDist& riError );
+  template<Bool bSet> __inline Void xSetShiftedPelBlendR  (RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
+  template<Bool bSet> __inline Void xSetShiftedPelNoBlendR(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
+
+  __inline Int    xShiftNewData      ( Int iPos, Int iPosInNewData );
+  __inline Int    xShift             ( Int iPos );
+  __inline Int    xShift             ( Int iPos, Int iPosInNewData );
+  __inline Int    xGetDist           ( Int iDiffY, Int iDiffU, Int iDiffV );
+  __inline Int    xGetDist           ( Int iDiffY );
+
+  // Utilities
+  __inline Void   xSetPels   ( Pel*  piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Pel iVal );
+  __inline Void   xSetBools  ( Bool* pbSource    , Int iSourceStride, Int iWidth, Int iHeight, Bool bVal );
+  __inline Void   xSetInts   ( Int*  piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Int iVal );
+
+#if HHI_VSO_COLOR_PLANES
+  Void            xGetSampleStrTextPtrs ( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY, Pel RenModelOutPels::*& rpiSrcU, Pel RenModelOutPels::*& rpiSrcV );
+#else  
+  Void            xGetSampleStrTextPtrs ( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY );
+#endif 
+  Void            xGetSampleStrDepthPtrs( Int iViewNum, Pel RenModelOutPels::*& rpiSrcD );
+       
+  Void            xSetStructRefView            ();
+  Void            xResetStructError            ();
+  Void            xInitSampleStructs           ();
+  Void            xSetStructSynthViewAsRefView ();
+  Void            xCopy2PicYuv                ( Pel** ppiSrcVideoPel, Int* piStrides, TComPicYuv* rpcPicYuvTarget );
+
+  template< typename S, typename T> 
+  Void   xCopyFromSampleStruct ( S* ptSource , Int iSourceStride, T S::* ptSourceElement, T* ptTarget, Int iTargetStride, Int iWidth, Int iHeight )
+  {
+    AOT( iWidth != m_iWidth ); 
+    for (Int iPosY = 0; iPosY < iHeight; iPosY++)
+    {
+      for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
+      {
+        ptTarget[iPosX] = ptSource[iPosX].*ptSourceElement;
+      }
+      ptSource += iSourceStride;
+      ptTarget += iTargetStride;
+    }    
+  }  
+
+  template< typename S, typename T> 
+  Void   xCopyToSampleStruct ( T* ptSource , Int iSourceStride, S* ptTarget, Int iTargetStride, T S::* ptSourceElement, Int iWidth, Int iHeight )
+  {
+    AOT( iWidth != m_iWidth ); 
+    for (Int iPosY = 0; iPosY < iHeight; iPosY++)
+    {
+      for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
+      {
+        ptTarget[iPosX] = ptSource[iPosX].*ptSourceElement;
+      }
+      ptSource += iSourceStride;
+      ptTarget += iTargetStride;
+    }    
+  }   
+
+private:
+
+  // Image sizes
+  Int   m_iWidth;
+  Int   m_iHeight;
+  Int   m_iStride;
+  Int   m_iPad;
+  Int   m_iUsedHeight;
+  Int   m_iHorOffset; 
+
+  Int   m_iSampledWidth;
+  Int   m_iSampledStride;
+
+  RenModelInPels* m_pcInputSamples[2];
+  Int             m_iInputSamplesStride;
+
+  // Base
+  Pel** m_aapiBaseVideoPel     [2]; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
+  Int*  m_aaiBaseVideoStrides  [2]; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
+
+  Pel*  m_apiBaseDepthPel      [2]; // Dim1: ViewPosition
+  Int   m_aiBaseDepthStrides   [2]; // Dim1: ViewPosition
+
+
+  // LUT
+  Int** m_appiShiftLut         [2];
+  Int** m_ppiCurLUT;
+  Int** m_aaiSubPelShiftL;
+  Int** m_aaiSubPelShiftR;
+
+  Int*  m_piInvZLUTLeft;
+  Int*  m_piInvZLUTRight;
+
+
+  //// Reference Data  ////
+  TComPicYuv* m_pcPicYuvRef       ;    // Reference PIcYuv
+
+  //// Output Samples
+  RenModelOutPels* m_pcOutputSamples;
+  Int                   m_iOutputSamplesStride;
+
+  Pel*  m_aapiRefVideoPel      [3];    // Dim1: Plane  0-> Y, 1->U, 2->V
+  Int   m_aiRefVideoStrides    [3];    // Dim1: Plane  0-> Y, 1->U, 2->V
+
+  // Rendering State
+  Bool  m_bInOcclusion;                // Currently rendering in occluded area
+  Int   m_iLastOccludedSPos;           // Position of last topmost shifted position
+  Int   m_iLastOccludedSPosFP;         // Position of last topmost shifted position in FullPels
+
+  Int   m_iCurViewPos;                 // Current View Position 0: Left, 1: Right
+  Int   m_iOtherViewPos;               // Other View Position 0: Left, 1: Right
+  Pel*  m_piNewDepthData;              // Pointer to new depth data
+  Int   m_iStartChangePosX;            // Start Position of new data
+  Int   m_iNewDataWidth;               // Width of new data
+  Pel   m_iCurDepth;                   // Current Depth Value
+  Pel   m_iLastDepth;                  // Last Depth Value
+  Pel   m_iThisDepth;                  // Depth value to use for setting
+
+  //// Settings ////
+  // Input
+  Int   m_iMode;                       // 0: Left to Right, 1: Right to Left, 2: Merge
+  Bool  m_bUseOrgRef;
+  Int   m_iShiftPrec;
+  Int   m_iHoleMargin;
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  Bool  m_bEarlySkip; 
+#endif
+
+  // Derived settings
+  Int   m_iGapTolerance;
+  Int   m_iBlendZThres;
+  Int   m_iBlendDistWeight;
+
+  //// Current Pointers ////
+
+  RenModelInPels*  m_pcInputSamplesRow [2];
+  RenModelOutPels* m_pcOutputSamplesRow;
+
+  //// MISC ////
+  const Int m_iDistShift;                  // Shift in Distortion computation
+
+  //// Early Skip 
+#ifdef LGE_VSO_EARLY_SKIP_A0093
+  Bool* m_pbHorSkip;
+#endif
+};
+
+#endif //__TRENSINGLEMODEL__
+#endif
+
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenTop.cpp
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenTop.cpp	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenTop.cpp	(revision 438)
@@ -0,0 +1,2222 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "TRenImage.h"
+#include "TRenTop.h"
+
+#include "TRenFilter.h"
+#include <iostream>
+#include <math.h>
+#include "../TLibCommon/CommonDef.h"
+
+Void TRenTop::xGetDataPointers( PelImage*& rpcInputImage, PelImage*& rpcOutputImage, PelImage*& rpcInputDepth, PelImage*& rpcOutputDepth, PelImage*& rpcFilled, Bool bRenderDepth )
+{
+  UInt uiWidth = m_auiInputResolution[0] << m_iLog2SamplingFactor;
+
+  UInt uiSubPelWidth  = uiWidth;
+
+  if ( m_iInterpolationMode == eRenInt8Tap )
+  {
+    uiSubPelWidth <<= m_iRelShiftLUTPrec;
+  }
+
+  UInt uiHeight = m_auiInputResolution[1];
+
+  if ( m_bUVUp )
+  {
+    rpcInputDepth  = new PelImage(uiSubPelWidth, uiHeight,1,0);
+    rpcInputImage  = new PelImage(uiSubPelWidth, uiHeight,3,0);
+    rpcOutputImage = new PelImage(uiWidth,        uiHeight,3,0);
+    rpcOutputDepth = bRenderDepth  ? new PelImage(uiWidth, uiHeight,1,0) : 0;
+    rpcFilled      = new PelImage(uiWidth, uiHeight,1,0);
+  }
+  else
+  {
+    rpcInputDepth  = new PelImage(uiSubPelWidth, uiHeight,1,1);
+    rpcInputImage  = new PelImage(uiSubPelWidth, uiHeight,1,2);
+    rpcOutputImage = new PelImage(uiWidth,        uiHeight,1,2);
+    rpcOutputDepth = bRenderDepth ? new PelImage(uiWidth, uiHeight,1,1) : 0;
+    rpcFilled      = new PelImage(uiWidth,        uiHeight,1,1);
+  }
+
+}
+
+Void TRenTop::xGetDataPointerOutputImage( PelImage*& rpcOutputImage, PelImage*& rpcOutputDepth )
+{
+
+  UInt uiWidth  = m_auiInputResolution[0] << m_iLog2SamplingFactor;
+  UInt uiHeight = m_auiInputResolution[1];
+
+  if ( m_bUVUp )
+  {
+    rpcOutputImage = new PelImage(uiWidth, uiHeight,3,0);
+    rpcOutputDepth = (m_iBlendMode == eRenBlendDepthFirst ) ? new PelImage(uiWidth, uiHeight,1,0) : NULL;
+  }
+  else
+  {
+    rpcOutputImage = new PelImage(uiWidth, uiHeight,1,2);
+    rpcOutputDepth = (m_iBlendMode == eRenBlendDepthFirst ) ? new PelImage(uiWidth, uiHeight,1,1) : NULL;
+  }
+}
+
+Void TRenTop::xConvertInputVideo( PelImage* pcOrgInputImage, PelImage* pcConvInputImage)
+{
+  TRenImagePlane<Pel>*  pcOrgPlane ;
+  TRenImagePlane<Pel>*  pcConvPlane;
+
+  Int iLog2SamplingFactor = m_iLog2SamplingFactor;
+
+  if ( m_iInterpolationMode == eRenInt8Tap)
+  {
+    iLog2SamplingFactor += m_iRelShiftLUTPrec;
+  }
+
+  AOT( iLog2SamplingFactor > 2);
+
+  for (UInt uiPlane = 0; uiPlane < 3; uiPlane++)
+  {
+    pcOrgPlane  = pcOrgInputImage ->getPlane(uiPlane);
+    pcConvPlane = pcConvInputImage->getPlane(uiPlane);
+
+    if (uiPlane == 0)
+    {
+      TRenFilter::sampleHorUp    ( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+    }
+    else
+    {
+      if ( m_bUVUp )
+      {
+        TRenFilter::sampleCUpHorUp( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+      }
+      else
+      {
+        TRenFilter::sampleCHorUp   ( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+      }
+    }
+  }
+}
+
+Void TRenTop::xConvertInputDepth( PelImage* pcOrgInputImage, PelImage* pcConvInputImage)
+{
+  PelImagePlane*  pcOrgPlane ;
+  PelImagePlane*  pcConvPlane;
+
+  // Full Plane
+  pcOrgPlane  = pcOrgInputImage ->getPlane(0);
+  pcConvPlane = pcConvInputImage->getPlane(0);
+
+  Int iLog2SamplingFactor = m_iLog2SamplingFactor;
+
+  if ( m_iInterpolationMode == eRenInt8Tap)
+  {
+    iLog2SamplingFactor += m_iRelShiftLUTPrec;
+  }
+  AOT( iLog2SamplingFactor > 2);
+
+  TRenFilter::sampleHorUp(iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+
+  if ( !m_bUVUp ) //GT: depth down
+  {
+    // Quarter Plane
+    PelImagePlane* pcTempPlane = new PelImagePlane(pcOrgInputImage->getPlane(0)->getWidth(), ( pcOrgInputImage->getPlane(0)->getHeight() >> 1), REN_LUMA_MARGIN );
+
+    TRenFilter::sampleVerDown2Tap13(pcOrgInputImage->getPlane(0), pcTempPlane, PICYUV_PAD);
+    pcConvPlane = pcConvInputImage->getPlane(1);
+
+    if ( iLog2SamplingFactor == 0 )
+    {
+      TRenFilter::sampleHorDown2Tap13(pcTempPlane, pcConvPlane, 0 );
+    }
+    else
+    {
+      TRenFilter::sampleHorUp    ( iLog2SamplingFactor - 1, pcTempPlane->getPlaneData(), pcTempPlane->getStride(), pcTempPlane->getWidth(), pcTempPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+    }
+    delete pcTempPlane;
+  }
+}
+
+Void TRenTop::xConvertInputData( PelImage* pcOrgInputImage, PelImage* pcOrgInputDepth, PelImage* pcConvInputImage, PelImage* pcConvInputDepth, Bool bMirror )
+{
+  //ToDo: remove unnecessary copying
+  if ( bMirror )
+  {
+    m_pcTempImage->assign( pcOrgInputImage );
+    TRenFilter::mirrorHor( m_pcTempImage );
+    m_pcTempImage->extendMargin();
+    xConvertInputVideo(    m_pcTempImage, pcConvInputImage );
+
+    m_pcTempImage->getPlane(0)->assign( pcOrgInputDepth->getPlane(0) );
+    TRenFilter::mirrorHor( m_pcTempImage->getPlane(0) );
+    m_pcTempImage->getPlane(0)->extendMargin();
+    xConvertInputDepth( m_pcTempImage, pcConvInputDepth );
+  }
+  else
+  {
+    m_pcTempImage->assign( pcOrgInputImage );
+    m_pcTempImage->extendMargin();
+    xConvertInputVideo( m_pcTempImage, pcConvInputImage );
+
+    m_pcTempImage->getPlane(0)->assign( pcOrgInputDepth->getPlane(0) );
+    m_pcTempImage->getPlane(0)->extendMargin();
+    xConvertInputDepth( m_pcTempImage, pcConvInputDepth );
+  }
+}
+
+Void TRenTop::xConvertOutputData( PelImage* pcOrgOutputImage, PelImage* pcConvOutputImage, Bool bMirror )
+{
+  Int iLog2SamplingFactor = m_iLog2SamplingFactor;
+
+  for ( UInt uiPlane = 0; uiPlane < 3; uiPlane++)
+  {
+    PelImagePlane* pcOrgPlane  = pcOrgOutputImage ->getPlane(uiPlane);
+    PelImagePlane* pcConvPlane = pcConvOutputImage->getPlane(uiPlane);
+
+    pcOrgPlane->extendMargin();
+
+    if ( uiPlane == 0 )
+    {
+      TRenFilter::sampleHorDown( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+    }
+    else
+    {
+      if ( m_bUVUp )
+      {
+        TRenFilter::sampleCDownHorDown( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+      }
+      else
+      {
+        TRenFilter::sampleCHorDown    ( iLog2SamplingFactor, pcOrgPlane->getPlaneData(), pcOrgPlane->getStride(), pcOrgPlane->getWidth(), pcOrgPlane->getHeight(), pcConvPlane->getPlaneData(), pcConvPlane->getStride());
+      }
+    }
+  }
+
+  if ( bMirror )
+  {
+    TRenFilter::mirrorHor( pcConvOutputImage );
+  }
+
+}
+
+Void TRenTop::setShiftLUTs( Double** ppdShiftLUTLeft, Int** ppiShiftLUTLeft, Int** ppiBaseShiftLUTLeft, Double** ppdShiftLUTRight, Int** ppiShiftLUTRight, Int** ppiBaseShiftLUTRight,  Int iRelDistToLeft )
+{
+  m_ppdShiftLUTLeft  = ppdShiftLUTLeft;
+  m_ppdShiftLUTRight = ppdShiftLUTRight;
+
+  m_ppiShiftLUTLeft  = ppiShiftLUTLeft;
+  m_ppiShiftLUTRight = ppiShiftLUTRight;
+
+  if (  m_ppdShiftLUTRight != NULL && m_ppiShiftLUTRight != NULL )
+  {
+    for( UInt uiPlane = 0; uiPlane < 2; uiPlane++)
+    {
+      for (UInt uiDepthValue = 0; uiDepthValue <= 256; uiDepthValue++)
+      {
+        m_ppdShiftLUTRightMirror[uiPlane][uiDepthValue] = - m_ppdShiftLUTRight[uiPlane][uiDepthValue];
+        m_ppiShiftLUTRightMirror[uiPlane][uiDepthValue] = - m_ppiShiftLUTRight[uiPlane][uiDepthValue];
+      }
+    }
+  }
+
+  if ( !m_bExtrapolate )
+  {
+    TRenFilter::setupZLUT( m_bBlendUseDistWeight, m_iBlendZThresPerc, iRelDistToLeft, ppiBaseShiftLUTLeft, ppiBaseShiftLUTRight, m_iBlendZThres, m_iBlendDistWeight, m_piInvZLUTLeft, m_piInvZLUTRight);
+  }
+}
+
+Void TRenTop::extrapolateView( TComPicYuv* pcPicYuvVideo, TComPicYuv* pcPicYuvDepth, TComPicYuv* pcPicYuvSynthOut, Bool bRenderFromLeft )
+{
+  AOF( m_bExtrapolate );
+  AOF( bRenderFromLeft ? m_ppiShiftLUTLeft || m_ppdShiftLUTLeft : m_ppiShiftLUTRight || m_ppdShiftLUTRight );
+  AOF( m_auiInputResolution[0] == pcPicYuvVideo->getWidth ());
+  AOF( m_auiInputResolution[1] == pcPicYuvVideo->getHeight());
+
+  PelImage cInputImage ( pcPicYuvVideo    );
+  PelImage cInputDepth ( pcPicYuvDepth    , true);
+  PelImage cOutputImage( pcPicYuvSynthOut );
+
+  m_pcOutputImage->init();
+  m_pcFilled     ->assign(REN_IS_HOLE);
+
+  xPreProcessDepth ( &cInputDepth,  &cInputDepth);
+  xConvertInputData( &cInputImage, &cInputDepth, m_pcInputImage, m_pcInputDepth, !bRenderFromLeft );
+  xShiftPixels(m_pcInputImage, m_pcInputDepth, m_pcOutputImage, m_pcFilled, bRenderFromLeft);
+  xRemBoundaryNoise ( m_pcOutputImage, m_pcFilled, m_pcOutputImage, bRenderFromLeft); // Erode
+  xFillHoles        ( m_pcOutputImage, m_pcFilled, m_pcOutputImage, bRenderFromLeft);
+  xConvertOutputData( m_pcOutputImage, &cOutputImage, !bRenderFromLeft );
+  xPostProcessImage (&cOutputImage, &cOutputImage);
+  xCutMargin        ( &cOutputImage );
+};
+
+Void TRenTop::getUsedSamplesMap( TComPicYuv* pcPicYuvDepth, TComPicYuv* pcUsedSampleMap, Bool bRenderFromLeft )
+{
+  AOF( bRenderFromLeft ? m_ppiShiftLUTLeft && m_ppdShiftLUTLeft : m_ppiShiftLUTRight && m_ppdShiftLUTRight );
+  AOF(m_auiInputResolution[0] == pcPicYuvDepth->getWidth ());
+  AOF(m_auiInputResolution[1] == pcPicYuvDepth->getHeight());
+
+  PelImage cInputDepth ( pcPicYuvDepth    , true);
+  PelImage cOutputImage( pcUsedSampleMap );
+  PelImage cInputImage ( m_auiInputResolution[0], m_auiInputResolution[1], 1, 2 );
+  cInputImage.assign(0);
+
+  m_pcFilled     ->assign(REN_IS_HOLE);
+  xConvertInputData(  &cInputImage,  &cInputDepth,   m_pcInputImage,  m_pcInputDepth, !bRenderFromLeft );
+  xShiftPixels     (m_pcInputImage, m_pcInputDepth, m_pcOutputImage, m_pcFilled, bRenderFromLeft);
+
+  xCreateAlphaMap  ( m_pcFilled, m_pcFilled, bRenderFromLeft );
+
+  if ( !bRenderFromLeft )
+  {
+    TRenFilter::mirrorHor( m_pcFilled );
+  }
+
+  TRenFilter::filledToUsedPelMap( m_pcFilled, &cOutputImage, m_iUsedPelMapMarExt );
+};
+
+
+Void TRenTop::interpolateView( TComPicYuv* pcPicYuvVideoLeft, TComPicYuv* pcPicYuvDepthLeft, TComPicYuv* pcPicYuvVideoRight, TComPicYuv* pcPicYuvDepthRight, TComPicYuv* pcPicYuvSynthOut, Int iBlendMode, Int iSimEnhBaseView )
+{
+  assert( !m_bExtrapolate );
+  assert( m_auiInputResolution[0] == pcPicYuvVideoLeft ->getWidth () );
+  assert( m_auiInputResolution[1] == pcPicYuvVideoRight->getHeight() );
+
+  AOT( iBlendMode == 3);
+  m_iBlendMode = iBlendMode;
+  m_iSimEnhBaseView = iSimEnhBaseView;
+
+  PelImage cLeftInputImage   ( pcPicYuvVideoLeft  );
+  PelImage cLeftInputDepth   ( pcPicYuvDepthLeft,  true );
+  PelImage cRightInputImage  ( pcPicYuvVideoRight );
+  PelImage cRightInputDepth  ( pcPicYuvDepthRight, true );
+  PelImage cOutputImage      ( pcPicYuvSynthOut   );
+
+  m_pcLeftOutputImage ->init();
+  m_pcRightOutputImage->init();
+  m_pcOutputImage     ->init();
+
+  if ( m_iBlendMode == eRenBlendDepthFirst )
+  {
+    m_pcOutputDepth->init();
+  }
+
+  m_pcLeftFilled ->assign(REN_IS_HOLE);
+  m_pcRightFilled->assign(REN_IS_HOLE);
+
+  xPreProcessDepth(&cLeftInputDepth , &cLeftInputDepth );
+  xPreProcessDepth(&cRightInputDepth, &cRightInputDepth);
+
+  xConvertInputData( &cLeftInputImage,  &cLeftInputDepth,  m_pcLeftInputImage,  m_pcLeftInputDepth  ,false );
+  xConvertInputData( &cRightInputImage, &cRightInputDepth, m_pcRightInputImage, m_pcRightInputDepth ,true  );
+
+  // Render from Left View to Right view
+  if ( m_iBlendMode != eRenBlendDepthFirst )
+  {
+    xShiftPixels(m_pcLeftInputImage,  m_pcLeftInputDepth, m_pcLeftOutputImage, m_pcLeftFilled, true );
+    xFillHoles  (m_pcLeftOutputImage, m_pcLeftFilled,     m_pcLeftOutputImage, true );
+  }
+
+  xShiftPixels(m_pcLeftInputDepth,  m_pcLeftInputDepth, m_pcLeftOutputDepth, m_pcLeftFilled, true );
+  xFillHoles     ( m_pcLeftOutputDepth, m_pcLeftFilled,     m_pcLeftOutputDepth, true);
+  xCreateAlphaMap( m_pcLeftFilled,      m_pcLeftFilled,     true );
+
+  // Render from Right View to Left view
+  if ( m_iBlendMode != eRenBlendDepthFirst )
+  {
+    xShiftPixels(m_pcRightInputImage , m_pcRightInputDepth, m_pcRightOutputImage, m_pcRightFilled, false );
+    xFillHoles  (m_pcRightOutputImage, m_pcRightFilled,     m_pcRightOutputImage, false);
+  }
+
+  xShiftPixels(m_pcRightInputDepth,  m_pcRightInputDepth, m_pcRightOutputDepth, m_pcRightFilled, false);
+  xFillHoles     ( m_pcRightOutputDepth, m_pcRightFilled,     m_pcRightOutputDepth, false);
+  xCreateAlphaMap( m_pcRightFilled,      m_pcRightFilled, false );
+
+  TRenFilter::mirrorHor( m_pcRightOutputImage );
+  TRenFilter::mirrorHor( m_pcRightOutputDepth );
+  TRenFilter::mirrorHor( m_pcRightFilled      );
+
+  xEnhSimilarity( m_pcLeftOutputImage, m_pcRightOutputImage, m_pcLeftFilled, m_pcRightFilled );
+
+  if ( m_iBlendMode == eRenBlendDepthFirst )
+  {
+    xBlend               ( m_pcLeftOutputDepth,  m_pcRightOutputDepth, m_pcLeftFilled,       m_pcRightFilled, m_pcLeftOutputDepth, m_pcRightOutputDepth, m_pcOutputDepth);
+
+    xBackShiftPixels     ( m_pcLeftInputImage,   m_pcOutputDepth,      m_pcLeftOutputImage,  m_pcLeftFilled  , false);
+    xFillHoles           ( m_pcLeftOutputImage,  m_pcLeftFilled,       m_pcLeftOutputImage, false);
+    xCreateAlphaMap      ( m_pcLeftFilled,       m_pcLeftFilled,       true );
+
+    TRenFilter::mirrorHor( m_pcRightInputImage );
+    xBackShiftPixels     ( m_pcRightInputImage,  m_pcOutputDepth,      m_pcRightOutputImage, m_pcRightFilled , true );
+    xFillHoles           ( m_pcRightOutputImage, m_pcRightFilled,      m_pcRightOutputImage, true);
+
+    TRenFilter::mirrorHor( m_pcRightFilled );
+    xCreateAlphaMap      ( m_pcRightFilled,      m_pcRightFilled,      true );
+    TRenFilter::mirrorHor( m_pcRightFilled );
+  }
+
+  xBlend(m_pcLeftOutputImage, m_pcRightOutputImage, m_pcLeftFilled, m_pcRightFilled, m_pcLeftOutputDepth, m_pcRightOutputDepth, m_pcOutputImage);
+  xConvertOutputData( m_pcOutputImage, &cOutputImage , false );
+
+  xPostProcessImage  ( &cOutputImage, &cOutputImage);
+  xCutMargin( &cOutputImage );
+};
+
+
+Void TRenTop::xPreProcessDepth( PelImage* pcInImage, PelImage* pcOutImage )
+{
+  if ( m_iPreProcMode == eRenPreProNone )
+    return;
+
+  PelImage* pcTemp;
+
+  if (pcInImage == pcOutImage)
+  {
+    pcTemp = pcOutImage->create();
+  }
+  else
+  {
+    pcTemp = pcOutImage;
+  }
+
+  pcTemp->assign(pcInImage);
+
+  switch ( m_iPreProcMode )
+  {
+    case eRenPreProBinom:
+      TRenFilter::binominal(pcOutImage, pcTemp, m_iPreFilterSize);
+      break;
+    case eRenPreProNone:
+      break;
+    default:
+      assert(0);
+      break;
+  }
+
+  if (pcInImage == pcOutImage)
+  {
+    pcOutImage->setData(pcTemp, true);
+    delete pcTemp;
+  };
+
+}
+
+Void TRenTop::xShiftPlanePixelsLinInt( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes )
+{
+  Int iWidth        = apcInputPlanes[0]->getWidth();
+  Int iHeight       = apcInputPlanes[0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+  Int iDepthStride  = pcDepthPlane ->getStride();
+
+  pcFilledPlane->assign(REN_IS_HOLE);
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    assert( iWidth        == apcInputPlanes [uiCurPlane]->getWidth()  && iWidth        == apcOutputPlanes[uiCurPlane]->getWidth() );
+    assert( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    assert( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+  }
+
+  Pel* pcDepthData  = pcDepthPlane ->getPlaneData();
+  Pel* pcFilledData = pcFilledPlane->getPlaneData();
+
+  for(Int iPosY = 0; iPosY < iHeight; iPosY++)
+  {
+    Int iPrevShiftedPos = -1;
+    Int iShiftedPos = -1;
+
+    for(Int iPosX = 0; iPosX < iWidth; iPosX ++ )
+    {
+      Bool bExtrapolate = false;
+
+      // compute disparity and shift
+      iShiftedPos  = ( iPosX << m_iRelShiftLUTPrec ) - m_aiShiftLUTCur[RemoveBitIncrement( pcDepthData[iPosX])];
+
+      if (iPosX == 0)
+      {
+        // in first iteration only get dLeftPos
+        iPrevShiftedPos = iShiftedPos;
+        continue;
+      };
+
+      Int iDeltaPos = iShiftedPos - iPrevShiftedPos;
+
+      if ( iDeltaPos <= 0 || (iDeltaPos > (2 << m_iRelShiftLUTPrec)))
+      {
+        // skip Interpolation if pixel is shifted forwards (gap) or if  pixel is shifted backwards (foreground object)
+        bExtrapolate = true;
+      };
+
+      Int iInterPolPos;
+      if (!bExtrapolate)
+      {  // Interpolate between j1 and j2
+        for (iInterPolPos = ( iPrevShiftedPos + (1 << m_iRelShiftLUTPrec) - 1 ) >> m_iRelShiftLUTPrec  ; iInterPolPos <= (iShiftedPos >> m_iRelShiftLUTPrec); iInterPolPos++)
+        {
+          if ( (iInterPolPos >= iWidth) || (iInterPolPos < (Int) 0))
+          {
+            // skip Interpolation if Interpolation position is outside frame
+            continue;
+          };
+
+          // Interpolate
+          Int iDeltaCurPos  = (iInterPolPos << m_iRelShiftLUTPrec) - iPrevShiftedPos;
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            Pel cVal  = (( apcInputData[uiCurPlane][iPosX - 1] * iDeltaPos +  ( apcInputData[uiCurPlane][iPosX] - apcInputData[uiCurPlane][iPosX - 1] ) * iDeltaCurPos ) / iDeltaPos );
+            apcOutputData[uiCurPlane][iInterPolPos]  = cVal;
+          }
+
+          pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+        }
+      }
+      else
+      { // Extrapolate right from dLeftPos and left from dRightPos
+        Int iShiftedPosCeiled = (( iPrevShiftedPos + (1 << m_iRelShiftLUTPrec) - 1) >> m_iRelShiftLUTPrec ) << m_iRelShiftLUTPrec;
+        if ( (iPrevShiftedPos + (m_iRelShiftLUTPrec >> 1) ) > iShiftedPosCeiled )
+        {
+          iInterPolPos = iShiftedPosCeiled >> m_iRelShiftLUTPrec;
+
+          if ( (iInterPolPos >= iWidth) || (iInterPolPos < (Int) 0))
+          {
+            // skip Interpolation if Interpolation position is outside frame
+            iPrevShiftedPos = iShiftedPos;
+            continue;
+          };
+
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX - 1];
+          }
+
+          pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+        }
+
+        Int iPrevShiftedPosFloor = (iShiftedPos >> m_iRelShiftLUTPrec) << m_iRelShiftLUTPrec;
+        if (iShiftedPos - (m_iRelShiftLUTPrec > 1) < iPrevShiftedPosFloor )
+        {
+          iInterPolPos = iPrevShiftedPosFloor >> m_iRelShiftLUTPrec;
+
+          if ( (iInterPolPos >= iWidth) || (iInterPolPos < (Int) 0))
+          {
+            // skip Interpolation if Interpolation position is outside frame
+            iPrevShiftedPos = iShiftedPos;
+            continue;
+          };
+
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX ];
+          }
+
+          pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+        }
+      }
+      iPrevShiftedPos = iShiftedPos;
+    }
+
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+    }
+    pcFilledData += iFilledStride;
+    pcDepthData  += iDepthStride;
+  }
+  delete[] apcInputData;
+  delete[] apcOutputData;
+};
+
+
+Void TRenTop::xShiftPlanePixelsLinReal( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes )
+{
+  Int iWidth        = apcInputPlanes[0]->getWidth();
+  Int iHeight       = apcInputPlanes[0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+  Int iDepthStride  = pcDepthPlane ->getStride();
+
+  pcFilledPlane->assign( REN_IS_HOLE );
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    assert( iWidth        == apcInputPlanes [uiCurPlane]->getWidth()  && iWidth        == apcOutputPlanes[uiCurPlane]->getWidth() );
+    assert( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    assert( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+  }
+
+  Pel* pcDepthData  = pcDepthPlane ->getPlaneData();
+  Pel* pcFilledData = pcFilledPlane->getPlaneData();
+
+  ///// FEM Stuff /////
+  const UInt  cuiMaxPlaneNum = 6;  AOT( uiNumberOfPlanes > cuiMaxPlaneNum );
+  IntImagePlane* apcDiffPlane[ cuiMaxPlaneNum ];
+  Int*          ppiDiffPlanes[ cuiMaxPlaneNum ];
+  Int             iDiffStride = 0;
+
+  if ( m_iInterpolationMode == eRenIntFEM )
+  {
+    AOT( uiNumberOfPlanes > cuiMaxPlaneNum );
+    for ( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++ )
+    {
+      apcDiffPlane[uiCurPlane] = new IntImagePlane( iWidth, iHeight, apcInputPlanes[uiCurPlane]->getPad());
+      TRenFilter::diffHorSym(apcInputPlanes[uiCurPlane] , apcDiffPlane[uiCurPlane]);
+      ppiDiffPlanes[uiCurPlane] = apcDiffPlane[uiCurPlane]->getPlaneData();
+    }
+    iDiffStride = apcDiffPlane[0]->getStride();
+  }
+  ///// FEM Stuff End /////
+
+  for(Int iPosY = 0; iPosY < iHeight; iPosY++)
+  {
+    Double dShiftedPos = 0;
+    Double dPrevShiftedPos = 0;
+
+    for(Int iPosX = 0; iPosX < iWidth; iPosX ++ )
+    {
+        Bool bExtrapolate = false;
+
+        // compute disparity and shift
+        assert( RemoveBitIncrement(pcDepthData[iPosX]) >= 0 && RemoveBitIncrement(pcDepthData[iPosX]) <= 256 );
+        dPrevShiftedPos  = (Double) iPosX - m_adShiftLUTCur[ RemoveBitIncrement(pcDepthData[iPosX])];
+
+        if (iPosX == 0)
+        {
+          // in first iteration only get dLeftPos
+          dShiftedPos = dPrevShiftedPos;
+          continue;
+        };
+
+        Double dDeltaPos = dPrevShiftedPos - dShiftedPos;
+
+        if ((dDeltaPos <= 0) || ( dDeltaPos > 2 ))
+        {
+          // skip Interpolation if pixel is shifted backwards (foreground object)  or if pixel is shifted forwards (gap)
+          bExtrapolate = true;
+        };
+
+        Int iInterPolPos;
+        if (!bExtrapolate)
+        {  // Interpolate between j1 and j2
+          for (iInterPolPos = (Int) ceil(dShiftedPos); iInterPolPos <= floor(dPrevShiftedPos); iInterPolPos++)
+          {
+            if ( (iInterPolPos >= (Int) iWidth) || (iInterPolPos < (Int) 0 ))
+            {
+              // skip Interpolation if Interpolation position is outside frame
+              continue;
+            };
+
+            // Interpolate
+            Pel cVal;
+            if ( m_iInterpolationMode == eRenIntFEM ) //FEM Interpolation
+            {
+              for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+              {
+                cVal  = TRenFilter::interpCHSpline(iInterPolPos, dShiftedPos, dPrevShiftedPos, apcInputData[uiCurPlane][iPosX - 1], ppiDiffPlanes[uiCurPlane][iPosX - 1], apcInputData[uiCurPlane][iPosX], ppiDiffPlanes[uiCurPlane][iPosX] );
+                apcOutputData[uiCurPlane][iInterPolPos]  = cVal;
+              }
+            }
+            else
+            {
+              Double dDeltaJ  = (Double) iInterPolPos - dShiftedPos;
+
+              for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+              {
+                cVal  = (UChar) ( (Double) apcInputData[uiCurPlane][iPosX - 1] +  ( (Double) apcInputData[uiCurPlane][iPosX] - (Double) apcInputData[uiCurPlane][iPosX - 1] ) / dDeltaPos * dDeltaJ + 0.5);
+                apcOutputData[uiCurPlane][iInterPolPos]  = cVal;
+              }
+            };
+
+            pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+          }
+        }
+        else
+        { // Extrapolate right from dLeftPos and left from dRightPos
+          if (dShiftedPos + 0.5 > ceil(dShiftedPos))
+          {
+            iInterPolPos = (Int) ceil(dShiftedPos);
+
+            if ( (iInterPolPos >= (Int) iWidth) || (iInterPolPos < (Int) 0))
+            {
+              // skip Interpolation if Interpolation position is outside frame
+              dShiftedPos = dPrevShiftedPos;
+              continue;
+            };
+
+            for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+            {
+              apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX - 1];
+            }
+
+            pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+          }
+
+          if (dPrevShiftedPos - 0.5 < floor(dPrevShiftedPos))
+          {
+            iInterPolPos = (Int) floor(dPrevShiftedPos);
+
+            if ( (iInterPolPos >= (Int) iWidth) || (iInterPolPos < (Int) 0))
+            {
+              // skip Interpolation if Interpolation position is outside frame
+              dShiftedPos = dPrevShiftedPos;
+              continue;
+            };
+
+            for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+            {
+              apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX ];
+            }
+
+            pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+          }
+        }
+        dShiftedPos = dPrevShiftedPos;
+      }
+
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+
+      if (m_iInterpolationMode ==  eRenIntFEM)
+      {
+        ppiDiffPlanes[ uiCurPlane ] += iDiffStride;
+      }
+    }
+
+    pcFilledData += iFilledStride;
+    pcDepthData  += iDepthStride;
+  }
+
+  if (m_iInterpolationMode ==  eRenIntFEM)
+  {
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      delete apcDiffPlane[uiCurPlane];
+    }
+  }
+
+  delete[] apcInputData;
+  delete[] apcOutputData;
+}
+
+
+Void TRenTop::xShiftPlanePixels( PelImagePlane** apcInPlane, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutPlane, PelImagePlane* pcPlaneFilled, UInt uiNumberOfPlanes )
+{
+  switch ( m_iInterpolationMode)
+  {
+  case eRenIntFullPel:
+    xShiftPlanePixelsFullPel( apcInPlane, pcDepthPlane, apcOutPlane, pcPlaneFilled, uiNumberOfPlanes);
+    break;
+  case eRenIntFEM:
+  case eRenIntLinReal:
+    xShiftPlanePixelsLinReal( apcInPlane, pcDepthPlane, apcOutPlane, pcPlaneFilled, uiNumberOfPlanes);
+    break;
+  case eRenIntLinInt:
+    xShiftPlanePixelsLinInt ( apcInPlane, pcDepthPlane, apcOutPlane, pcPlaneFilled, uiNumberOfPlanes);
+    break;
+  case eRenInt8Tap:
+    xShiftPlanePixels8Tap   ( apcInPlane, pcDepthPlane, apcOutPlane, pcPlaneFilled, uiNumberOfPlanes );
+    break;
+  default:
+    AOF( false );
+  }
+}
+
+
+Void TRenTop::xShiftPlanePixelsFullPel( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes )
+{
+  Int iWidth        = apcInputPlanes[0]->getWidth();
+  Int iHeight       = apcInputPlanes[0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+  Int iDepthStride  = pcDepthPlane ->getStride();
+
+  pcFilledPlane->assign(REN_IS_HOLE);
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    assert( iWidth        == apcInputPlanes [uiCurPlane]->getWidth()  && iWidth        == apcOutputPlanes[uiCurPlane]->getWidth() );
+    assert( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    assert( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+  }
+
+  Pel* pcDepthData  = pcDepthPlane ->getPlaneData();
+  Pel* pcFilledData = pcFilledPlane->getPlaneData();
+
+  for(Int iPosY = 0; iPosY < iHeight; iPosY++)
+  {
+    Int iPrevShiftedPos = -1;
+
+    for(Int iPosX = 0; iPosX < iWidth; iPosX++)
+    {
+      assert( RemoveBitIncrement(pcDepthData[iPosX]) >= 0 && RemoveBitIncrement(pcDepthData[iPosX]) <= 256 );
+      Int iShiftedPos = iPosX - m_aiShiftLUTCur[ RemoveBitIncrement(pcDepthData[iPosX])] ;
+      if (iShiftedPos < iWidth && iShiftedPos >= 0)
+      {
+        Int iDiff = iShiftedPos - iPrevShiftedPos;
+        if (( iDiff <= 2) && (iDiff > 0) )
+        {
+          for (Int iCurPos = iPrevShiftedPos+1; iCurPos <= iShiftedPos; iCurPos++)
+          {
+            for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+            {
+              apcOutputData[uiCurPlane][iCurPos] = apcInputData[uiCurPlane][iPosX];    // Only small gaps, therefor not necessary NN
+            }
+            pcFilledData[iCurPos] = REN_IS_FILLED;
+          }
+        }
+        else
+        {
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            apcOutputData[uiCurPlane][iShiftedPos] = apcInputData[uiCurPlane][iPosX];
+          }
+          pcFilledData[iShiftedPos] = REN_IS_FILLED;
+        }
+        iPrevShiftedPos = iShiftedPos;
+      }
+    }
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+    }
+    pcFilledData += iFilledStride;
+    pcDepthData  += iDepthStride;
+  }
+
+  delete[] apcInputData;
+  delete[] apcOutputData;
+}
+
+Void TRenTop::xBackShiftPlanePixels( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes )
+{
+  Int iOutputWidth  = apcOutputPlanes[0]->getWidth();
+  Int iInputWidth   = apcInputPlanes [0]->getWidth();
+  Int iHeight       = apcInputPlanes [0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+  Int iDepthStride  = pcDepthPlane ->getStride();
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+
+  Int iStep         = (1 << m_iRelShiftLUTPrec);
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    AOF( iInputWidth   == apcInputPlanes [uiCurPlane]->getWidth()  && iOutputWidth  == apcOutputPlanes[uiCurPlane]->getWidth() );
+    AOF( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    AOF( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+    AOF( iInputWidth   == iOutputWidth * iStep );
+  }
+
+  Pel* pcDepthData  = pcDepthPlane ->getPlaneData();
+  Pel* pcFilledData = pcFilledPlane->getPlaneData();
+
+
+  for(Int iPosY = 0; iPosY < iHeight; iPosY++)
+  {
+    for(Int iPosX = 0; iPosX < iOutputWidth; iPosX ++)
+    {
+      Int iBackShiftedPos = (iPosX << m_iRelShiftLUTPrec) - m_aiShiftLUTCur[ RemoveBitIncrement( pcDepthData[iPosX] )];
+      if( ( pcFilledData[iPosX] == REN_IS_FILLED )  && (iBackShiftedPos >= 0 ) && ( iBackShiftedPos < iInputWidth ) )
+      {
+        for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+        {
+          apcOutputData[uiCurPlane][iPosX] = apcInputData[uiCurPlane][iBackShiftedPos];
+        }
+      }
+      else
+      {
+        for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+        {
+          apcOutputData[uiCurPlane][iPosX] = 0;
+        }
+        pcFilledData[iPosX] = REN_IS_HOLE;
+      }
+    }
+
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+    }
+    pcFilledData += iFilledStride;
+    pcDepthData  += iDepthStride;
+  }
+
+  delete[] apcInputData;
+  delete[] apcOutputData;
+}
+
+Void TRenTop::xShiftPlanePixels8Tap( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes  )
+{
+  Bool bRenderDepth = (apcInputPlanes[0] == pcDepthPlane);
+
+  Int iOutputWidth  = apcOutputPlanes[0]->getWidth();
+  Int iInputWidth   = apcInputPlanes [0]->getWidth();
+  Int iHeight       = apcInputPlanes [0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+  Int iDepthStride  = pcDepthPlane ->getStride();
+
+  Int iStep         = (1 << m_iRelShiftLUTPrec);
+
+  pcFilledPlane->assign(REN_IS_HOLE);
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    AOF( iInputWidth   == apcInputPlanes [uiCurPlane]->getWidth()  && iOutputWidth  == apcOutputPlanes[uiCurPlane]->getWidth() );
+    AOF( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    AOF( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+    AOF( iInputWidth   == iOutputWidth * iStep );
+  }
+
+  Pel* pcDepthData  = pcDepthPlane ->getPlaneData();
+  Pel* pcFilledData = pcFilledPlane->getPlaneData();
+
+  for(Int iPosY = 0; iPosY < iHeight; iPosY++)
+  {
+    Int iPrevShiftedPos = -1;
+    Int iShiftedPos     = -1;
+
+    for(Int iPosX = 0; iPosX < iInputWidth; iPosX += iStep )
+    {
+      // compute disparity and shift
+      iShiftedPos  =  iPosX - m_aiShiftLUTCur[RemoveBitIncrement(pcDepthData[iPosX])];
+
+      if ( iPosX == 0 )
+      {
+        // in first iteration only get dLeftPos
+        iPrevShiftedPos = iShiftedPos;
+        continue;
+      };
+
+      Int iDeltaPos = iShiftedPos - iPrevShiftedPos;
+
+      Bool bDisocclusion = ( iDeltaPos > (2 << m_iRelShiftLUTPrec) );
+      Bool bOcclusion    = ( iDeltaPos <= 0 );
+
+      Int iInterPolPos;
+      if ( !bDisocclusion && !bOcclusion )
+      {  // Interpolate between previous shifted pos and shifted pos
+        for (iInterPolPos = xCeil( iPrevShiftedPos ); iInterPolPos <= xCeil (iShiftedPos ) -1 ; iInterPolPos++)
+        {
+          if ( (iInterPolPos < (Int) 0) || (iInterPolPos >= iOutputWidth))
+          {
+            // skip Interpolation if Interpolation position is outside frame
+            continue;
+          };
+
+          // Interpolate
+          Int iDeltaCurPos  = (iInterPolPos << m_iRelShiftLUTPrec) - iPrevShiftedPos;
+
+          AOF( (iDeltaCurPos <= iDeltaPos) && ( iDeltaCurPos >= 0));
+          AOF( iDeltaPos    <= (2 <<  m_iRelShiftLUTPrec)  );
+          AOF( m_aaiSubPelShift[iDeltaPos][iDeltaCurPos] != 0xdeaddead);
+
+          Int iSourcePos;
+
+          if ( bRenderDepth )
+          {
+            iSourcePos = iPosX - iStep; // Render depth with Full Pel accuracy to avoid ringing at sharp depth edges;
+          }
+          else
+          {
+            iSourcePos = iPosX +  m_aaiSubPelShift[iDeltaPos][iDeltaCurPos];   // GT:  = iPosX - iStep + ( iStep * iDeltaCurPos + ( iDeltaPos >> 1) ) / iDeltaPos;
+          }
+
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            apcOutputData[uiCurPlane][iInterPolPos] = apcInputData[uiCurPlane][iSourcePos];
+          }
+
+          pcFilledData[ iInterPolPos]  = REN_IS_FILLED;
+        }
+      }
+      else
+        {
+        // Fill Disocclusion Edge
+
+        if ( bDisocclusion )
+        {
+          Int iPrevShiftedPosCeiled =  xCeil(iPrevShiftedPos) << m_iRelShiftLUTPrec;
+          iInterPolPos = iPrevShiftedPosCeiled >> m_iRelShiftLUTPrec;
+
+          if ((iPrevShiftedPos + (iStep >> 1) ) > iPrevShiftedPosCeiled )
+          {
+            if ( !((iInterPolPos < (Int) 0) || (iInterPolPos >= iOutputWidth)))
+            {
+
+              for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+              {
+                apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX - iStep];
+              }
+              pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+
+            }           
+            iInterPolPos++;
+          }          
+
+          // Fill Disocclusion
+          if ( m_bInstantHoleFilling )
+          {
+            for ( ; iInterPolPos <= xCeil (iShiftedPos ) -1 ; iInterPolPos++)
+            {
+              for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+              {
+                if ( ( iInterPolPos >= 0 ) && ( iInterPolPos < iOutputWidth ) )
+                {
+                  apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX];
+                }
+              }
+            }
+          }
+        }
+
+        //// Last sample next to occlusion
+        Int iShiftedPosFloor = ( iShiftedPos >> m_iRelShiftLUTPrec ) << m_iRelShiftLUTPrec;
+        if ( bOcclusion && (iShiftedPos - (iStep >> 1) < iShiftedPosFloor) )
+        {
+          iInterPolPos = iShiftedPosFloor >> m_iRelShiftLUTPrec;
+          if ( !((iInterPolPos < (Int) 0) || (iInterPolPos >= iOutputWidth)))
+          {        
+            for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+            {
+              apcOutputData[uiCurPlane][iInterPolPos]  = apcInputData[uiCurPlane][iPosX ];
+            }
+
+            pcFilledData[iInterPolPos]  = REN_IS_FILLED;
+          }
+        }
+      }
+      iPrevShiftedPos = iShiftedPos;
+    }
+
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+    }
+    pcFilledData += iFilledStride;
+    pcDepthData  += iDepthStride;
+  }
+  delete[] apcInputData;
+  delete[] apcOutputData;
+};
+
+Void TRenTop::xShiftPixels(PelImage* pcInImage, PelImage* pcDepth, PelImage* pcOutImage, PelImage* pcFilledImage, Bool bShiftFromLeft )
+{
+  PelImage*  pcTemp = 0;
+
+  if (pcInImage == pcOutImage)
+  {
+    pcTemp = pcOutImage->create();
+  }
+  else
+  {
+    pcTemp = pcOutImage;
+  }
+
+  Double ** ppdShiftLUT = bShiftFromLeft ? m_ppdShiftLUTLeft : m_ppdShiftLUTRightMirror;
+  Int    ** ppiShiftLUT = bShiftFromLeft ? m_ppiShiftLUTLeft : m_ppiShiftLUTRightMirror;
+
+  UInt uiNumFullPlanes = pcInImage->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcInImage->getNumberOfQuaterPlanes();
+
+  assert( uiNumFullPlanes == pcOutImage->getNumberOfFullPlanes  () );
+  assert( uiNumQuatPlanes == pcOutImage->getNumberOfQuaterPlanes() );
+
+  m_aiShiftLUTCur = ppiShiftLUT[ 0 ];
+  m_adShiftLUTCur = ppdShiftLUT[ 0 ];
+
+  xShiftPlanePixels( pcInImage->getPlanes(), pcDepth->getPlane(0),  pcOutImage->getPlanes(), pcFilledImage->getPlane(0),  uiNumFullPlanes  );
+
+  if (uiNumQuatPlanes > 0)
+  {
+    assert( pcDepth->getNumberOfPlanes() > 1 && pcFilledImage->getNumberOfPlanes() > 1);
+    m_aiShiftLUTCur = ppiShiftLUT[ 1 ];
+    m_adShiftLUTCur = ppdShiftLUT[ 1 ];
+    xShiftPlanePixels( pcInImage->getPlanes()+uiNumFullPlanes,pcDepth->getPlane(1),  pcOutImage->getPlanes() + uiNumFullPlanes, pcFilledImage->getPlane(1),  uiNumQuatPlanes );
+  }
+
+  if (pcInImage == pcOutImage)
+  {
+    pcOutImage->assign(pcTemp);
+    delete pcTemp;
+  };
+};
+
+Void TRenTop::xBackShiftPixels(PelImage* pcInImage, PelImage* pcDepth, PelImage* pcOutImage, PelImage* pcFilledImage, Bool bShiftFromLeft )
+{
+  PelImage*  pcTemp = 0;
+
+  if (pcInImage == pcOutImage)
+  {
+    pcTemp = pcOutImage->create();
+  }
+  else
+  {
+    pcTemp = pcOutImage;
+  }
+
+  Double ** ppdShiftLUT = bShiftFromLeft ? m_ppdShiftLUTLeft : m_ppdShiftLUTRight;
+  Int    ** ppiShiftLUT = bShiftFromLeft ? m_ppiShiftLUTLeft : m_ppiShiftLUTRight;
+
+  UInt uiNumFullPlanes = pcInImage->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcInImage->getNumberOfQuaterPlanes();
+
+  assert( uiNumFullPlanes == pcOutImage->getNumberOfFullPlanes  () );
+  assert( uiNumQuatPlanes == pcOutImage->getNumberOfQuaterPlanes() );
+
+  m_aiShiftLUTCur = ppiShiftLUT[ 0 ];
+  m_adShiftLUTCur = ppdShiftLUT[ 0 ];
+
+  xBackShiftPlanePixels( pcInImage->getPlanes(), pcDepth->getPlane(0),  pcOutImage->getPlanes(), pcFilledImage->getPlane(0),  uiNumFullPlanes  );
+
+  if (uiNumQuatPlanes > 0)
+  {
+    assert( pcDepth->getNumberOfPlanes() > 1 && pcFilledImage->getNumberOfPlanes() > 1);
+    m_aiShiftLUTCur = ppiShiftLUT[ 1 ];
+    m_adShiftLUTCur = ppdShiftLUT[ 1 ];
+    xBackShiftPlanePixels( pcInImage->getPlanes()+uiNumFullPlanes,pcDepth->getPlane(1),  pcOutImage->getPlanes() + uiNumFullPlanes, pcFilledImage->getPlane(1),  uiNumQuatPlanes );
+  }
+
+  if (pcInImage == pcOutImage)
+  {
+    pcOutImage->assign(pcTemp);
+    delete pcTemp;
+  };
+};
+
+Void TRenTop::xFillHoles(PelImage* pcInImage, PelImage* pcFilled, PelImage* pcOutImage, Bool bRenderFromLeft )
+{
+  if (pcInImage != pcOutImage)
+  {
+    pcOutImage->assign(pcInImage);
+  }
+
+  switch (m_iHoleFillingMode)
+  {
+    case eRenHFNone:
+      break;
+    case eRenHFLWBackExt:
+      xFillLWBackExt( pcInImage, pcFilled, pcOutImage, bRenderFromLeft);
+      break;
+    default:
+      break;
+  }
+};
+
+Void TRenTop::xFillLWBackExt( PelImage* pcInImage, PelImage* pcFilledImage, PelImage* pcOutImage, Bool bRenderFromLeft )
+{
+  UInt uiNumFullPlanes = pcInImage->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcInImage->getNumberOfQuaterPlanes();
+
+  assert( uiNumFullPlanes == pcOutImage->getNumberOfFullPlanes  () );
+  assert( uiNumQuatPlanes == pcOutImage->getNumberOfQuaterPlanes() );
+
+  xFillPlaneHoles( pcInImage->getPlanes(), pcFilledImage->getPlane(0), pcOutImage->getPlanes(),  uiNumFullPlanes, bRenderFromLeft  );
+
+  if (uiNumQuatPlanes > 0)
+  {
+    assert(  pcFilledImage->getNumberOfPlanes() > 1);
+    xFillPlaneHoles( pcInImage->getPlanes()+uiNumFullPlanes, pcFilledImage->getPlane(1), pcOutImage->getPlanes() + uiNumFullPlanes,  uiNumQuatPlanes, bRenderFromLeft );
+  }
+};
+
+Void TRenTop::xCreateAlphaMap(PelImage* pcFilledImage, PelImage* pcAlphaMapImage, Bool bRenderFromLeft )
+{
+  UInt uiNumFullPlanes = pcFilledImage  ->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcFilledImage->getNumberOfQuaterPlanes();
+
+  AOF( uiNumFullPlanes == pcAlphaMapImage->getNumberOfFullPlanes  () );
+  AOF( uiNumQuatPlanes == pcAlphaMapImage->getNumberOfQuaterPlanes() );
+
+  xCreateAlphaMapPlane( pcFilledImage->getPlanes(),  pcAlphaMapImage->getPlanes(),  uiNumFullPlanes, bRenderFromLeft  );
+
+  if (uiNumQuatPlanes > 0)
+  {
+    AOF(  pcFilledImage->getNumberOfPlanes() > 1);
+    xCreateAlphaMapPlane( pcFilledImage->getPlanes()+ uiNumFullPlanes, pcAlphaMapImage->getPlanes()+uiNumFullPlanes,  uiNumQuatPlanes, bRenderFromLeft );
+  }
+};
+
+Void TRenTop::xCreateAlphaMapPlane(PelImagePlane** apcFilledPlanes,  PelImagePlane** apcAlphaPlanes,  UInt uiNumberOfPlanes, Bool bRenderFromLeft)
+{
+  Int iWidth            = apcFilledPlanes [0]->getWidth();
+  Int iHeight           = apcFilledPlanes [0]->getHeight();
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    AOF( iWidth         == apcFilledPlanes [uiCurPlane]->getWidth()  && iWidth        == apcAlphaPlanes[uiCurPlane]->getWidth() );
+    AOF( iHeight        == apcFilledPlanes [uiCurPlane]->getHeight() && iHeight       == apcAlphaPlanes[uiCurPlane]->getHeight());
+  }
+
+  Int iBlendWidth  = m_iBlendHoleMargin;
+  Int iMaxBlendLevel;
+
+  if (!m_bBlendUseDistWeight )
+  {
+    iMaxBlendLevel = ( 1 <<  REN_VDWEIGHT_PREC ) ;
+
+    if ( m_iBlendMode == 0)
+    {
+      iMaxBlendLevel >>= 1;
+    }
+  }
+  else
+  {
+    if ( m_iBlendMode == 0)
+    {
+      iMaxBlendLevel = bRenderFromLeft ? (1 << REN_VDWEIGHT_PREC) - m_iBlendDistWeight :  m_iBlendDistWeight;
+    }
+    else
+    {
+      iMaxBlendLevel  = ( 1 <<  REN_VDWEIGHT_PREC );
+    }
+  }
+
+  Int iWeightStep = (iBlendWidth > 0) ? ( iMaxBlendLevel + (iBlendWidth >> 1) ) / iBlendWidth : 0;
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    Int iFilledStride   = apcFilledPlanes [uiCurPlane]->getStride();
+    Int iAlphaStride    = apcAlphaPlanes  [uiCurPlane]->getStride();
+
+    Pel* pcFilledData = apcFilledPlanes   [uiCurPlane]->getPlaneData();
+    Pel* pcAlphaData  = apcAlphaPlanes    [uiCurPlane]->getPlaneData();
+
+    for(Int iYPos = 0; iYPos < iHeight; iYPos++)
+    {
+      for(Int iXPos = 0 ; iXPos < iWidth; iXPos++ )
+      {
+        if (pcFilledData[iXPos] == REN_IS_HOLE)
+        {
+          while( (pcFilledData[iXPos] == REN_IS_HOLE) && (iXPos < iWidth) )
+          {
+            pcAlphaData[iXPos] = REN_IS_HOLE;
+            iXPos++;
+          }
+
+          if ( iXPos >= iWidth )
+            continue;
+
+          Int iWeight = 0;
+          Int iLastFillPos = iXPos + iBlendWidth;
+
+          while( (pcFilledData[iXPos] != REN_IS_HOLE) && (iXPos < iWidth) && (iXPos < iLastFillPos) )
+          {
+            AOF(  iWeight <= (1 << REN_VDWEIGHT_PREC) );
+            pcAlphaData[iXPos]  = (iWeight == 0) ? 1 : iWeight;
+            iWeight += iWeightStep;
+            iXPos++;
+          }
+        }
+        else
+        {
+          pcAlphaData[iXPos] = REN_IS_FILLED;
+        }
+      }
+      pcAlphaData    += iAlphaStride;
+      pcFilledData   += iFilledStride;
+    }
+  }
+}
+
+Void TRenTop::xRemBoundaryNoise(PelImage* pcInImage, PelImage* pcFilledImage, PelImage* pcOutImage, Bool bRenderFromLeft )
+{
+  if (pcInImage != pcOutImage)
+  {
+    pcOutImage->assign(pcInImage);
+  }
+
+  UInt uiNumFullPlanes = pcInImage->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcInImage->getNumberOfQuaterPlanes();
+
+  AOF( uiNumFullPlanes == pcOutImage->getNumberOfFullPlanes  () );
+  AOF( uiNumQuatPlanes == pcOutImage->getNumberOfQuaterPlanes() );
+
+  xRemBoundaryNoisePlane( pcInImage->getPlanes(), pcFilledImage->getPlane(0), pcOutImage->getPlanes(),  uiNumFullPlanes, bRenderFromLeft  );
+
+  if (uiNumQuatPlanes > 0)
+  {
+    AOF(  pcFilledImage->getNumberOfPlanes() > 1);
+    xRemBoundaryNoisePlane( pcInImage->getPlanes()+uiNumFullPlanes, pcFilledImage->getPlane(1), pcOutImage->getPlanes() + uiNumFullPlanes,  uiNumQuatPlanes, bRenderFromLeft );
+  }
+};
+
+Void TRenTop::xRemBoundaryNoisePlane(PelImagePlane** apcInputPlanes,  PelImagePlane* pcFilledPlane, PelImagePlane** apcOutputPlanes, UInt uiNumberOfPlanes, Bool bRenderFromLeft)
+{
+  Int iWidth        = apcOutputPlanes[0]->getWidth();
+  Int iHeight       = apcInputPlanes [0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+  Pel*   pcFilledData = pcFilledPlane->getPlaneData();
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    AOF( iWidth        == apcInputPlanes [uiCurPlane]->getWidth()  && iWidth        == apcOutputPlanes[uiCurPlane]->getWidth() );
+    AOF( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    AOF( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+  }
+
+  Int iRemovalWidth  = m_iBlendHoleMargin;
+  AOT(iRemovalWidth > 6);  // GT: insufficent padding
+
+  for(Int iYPos = 0; iYPos < iHeight; iYPos++)
+  {
+    for(Int iXPos = iWidth-1; iXPos >= 0; iXPos-- )
+    {
+      if (pcFilledData[iXPos] == REN_IS_HOLE)
+      {
+        Int iSourcePos = iXPos + 1;
+
+        // Get New Value
+        while( (pcFilledData[iSourcePos] != REN_IS_HOLE) && ( iSourcePos < iWidth) && ( iSourcePos < iXPos + iRemovalWidth  ) ) iSourcePos++;
+
+        if (iSourcePos == iWidth || pcFilledData[iSourcePos] != REN_IS_HOLE )
+          iSourcePos--;
+
+        Int iXPosRem = iSourcePos - 1;
+
+        // Remove
+        while( iXPosRem > iXPos)
+        {
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            apcOutputData[uiCurPlane][iXPosRem] = apcInputData[uiCurPlane][iSourcePos];
+          }
+
+          iXPosRem--;
+        }
+
+        // Skip Hole
+        while( (pcFilledData[iXPos] == REN_IS_HOLE) && ( iXPos > 0) ) iXPos--;
+      }
+    }
+
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+    }
+    pcFilledData += iFilledStride;
+  }
+  delete[] apcInputData;
+  delete[] apcOutputData;
+}
+
+Void TRenTop::xFillPlaneHoles(PelImagePlane** apcInputPlanes,  PelImagePlane* pcFilledPlane, PelImagePlane** apcOutputPlanes, UInt uiNumberOfPlanes, Bool bRenderFromLeft)
+{
+  Int iWidth        = apcOutputPlanes[0]->getWidth();
+  Int iHeight       = apcInputPlanes [0]->getHeight();
+
+  Int iInputStride  = apcInputPlanes [0]->getStride();
+  Int iOutputStride = apcOutputPlanes[0]->getStride();
+
+  Int iFilledStride = pcFilledPlane->getStride();
+
+  Pel** apcInputData  = new Pel*[ uiNumberOfPlanes ];
+  Pel** apcOutputData = new Pel*[ uiNumberOfPlanes ];
+  Pel*   pcFilledData = pcFilledPlane->getPlaneData();
+
+  for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+  {
+    apcInputData   [uiCurPlane] = apcInputPlanes [uiCurPlane]->getPlaneData();
+    apcOutputData  [uiCurPlane] = apcOutputPlanes[uiCurPlane]->getPlaneData();
+    AOF( iWidth        == apcInputPlanes [uiCurPlane]->getWidth()  && iWidth        == apcOutputPlanes[uiCurPlane]->getWidth() );
+    AOF( iHeight       == apcInputPlanes [uiCurPlane]->getHeight() && iHeight       == apcOutputPlanes[uiCurPlane]->getHeight());
+    AOF( iInputStride  == apcInputPlanes [uiCurPlane]->getStride() && iOutputStride == apcOutputPlanes[uiCurPlane]->getStride());
+  }
+
+  for(Int iYPos = 0; iYPos < iHeight; iYPos++)
+  {
+    if ( !m_bInstantHoleFilling )
+    {
+    for(Int iXPos = 0 ; iXPos < iWidth; iXPos++ )
+    {
+      if (pcFilledData[iXPos] == REN_IS_HOLE)
+      {
+          Int iSourcePos;
+          Int iLastFillPos;
+
+        Int iXPosSearch = iXPos;
+        while( (pcFilledData[iXPosSearch] == REN_IS_HOLE) && (iXPosSearch < iWidth) ) iXPosSearch++;
+
+          if ( iXPosSearch >= iWidth )
+        {
+            continue;
+          }
+          else
+          {
+            iSourcePos   = iXPosSearch;
+            iLastFillPos = iXPosSearch-1;
+          }
+
+        while( iXPos <= iLastFillPos)
+        {
+          for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+          {
+            apcOutputData[uiCurPlane][iXPos] = apcInputData[uiCurPlane][iSourcePos];
+          }
+          iXPos++;
+        }
+        }
+      }
+    }
+
+    // Fill Right Gap
+    Int iXPosSearch = iWidth -1;
+    while( (pcFilledData[iXPosSearch] == REN_IS_HOLE) && (iXPosSearch >= 0) ) iXPosSearch--;
+    if ( iXPosSearch < 0) iXPosSearch++;
+
+    Int iSourcePos = iXPosSearch;
+
+    for( Int iXPos = iSourcePos + 1; iXPos <  iWidth; iXPos++)
+    {
+      for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+      {
+        apcOutputData[uiCurPlane][iXPos] = apcInputData[uiCurPlane][iSourcePos];
+      }
+    }
+
+    // Fill Left Gap
+    iXPosSearch = 0;
+    while( (pcFilledData[iXPosSearch] == REN_IS_HOLE) && (iXPosSearch < iWidth) ) iXPosSearch++;
+    if ( iXPosSearch >= iWidth) iXPosSearch--;
+
+    iSourcePos = iXPosSearch;
+
+    for( Int iXPos = iSourcePos - 1; iXPos >= 0; iXPos--)
+    {
+      for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+      {
+        apcOutputData[uiCurPlane][iXPos] = apcInputData[uiCurPlane][iSourcePos];
+      }
+    }
+
+    // Go to next line
+    for( UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++)
+    {
+      apcOutputData[uiCurPlane] += iOutputStride;
+      apcInputData [uiCurPlane] += iInputStride;
+    }
+    pcFilledData += iFilledStride;
+  }
+  delete[] apcInputData;
+  delete[] apcOutputData;
+}
+
+Void TRenTop::xPostProcessImage(PelImage* pcInImage, PelImage* pcOutImage)
+{
+  if ( m_iPostProcMode == eRenPostProNone )
+    return;
+
+  PelImage* pcTemp;
+
+  if (pcInImage == pcOutImage)
+  {
+    pcTemp = pcOutImage->create();
+  }
+  else
+  {
+    pcTemp = pcOutImage;
+  }
+
+  pcTemp->assign(pcInImage);
+
+  switch ( m_iPostProcMode )
+  {
+  case eRenPostProMed:
+    TRenFilter::lineMedian3(pcTemp);
+    break;
+  case eRenPostProNone:
+    break;
+  default:
+    assert(0);
+  }
+
+  if (pcInImage == pcOutImage)
+  {
+    pcOutImage->assign(pcTemp);
+    delete pcTemp;
+  };
+}
+
+
+Void TRenTop::xCutPlaneMargin( PelImagePlane* pcImagePlane, Pel cFill, UInt uiScale )
+{
+  UInt uiWidth  = pcImagePlane->getWidth();
+  UInt uiHeight = pcImagePlane->getHeight();
+
+  UInt uiStride    = pcImagePlane->getStride();
+  Pel* pcPlaneData = pcImagePlane->getPlaneData();
+
+  UInt uiCutLeft  =           m_auiCut[0] / uiScale;
+  UInt uiCutRight = uiWidth - m_auiCut[1] / uiScale;
+
+  for(UInt uiYPos = 0; uiYPos < uiHeight; uiYPos++)
+  {
+    for(UInt uiXPos = 0; uiXPos < (UInt) uiWidth ; uiXPos++)
+    {
+      if ( ( uiXPos < uiCutLeft  )  || (  uiXPos >=  uiCutRight )  )
+      {
+        pcPlaneData[uiXPos ] = cFill;
+      }
+    }
+    pcPlaneData += uiStride;
+  }
+};
+
+Void TRenTop::xCutMargin( PelImage* pcInputImage )
+{
+  if  ( ( m_auiCut[0] == 0 ) && ( m_auiCut[1] == 0 ) )
+  {
+    return;
+  };
+
+  UInt uiCurPlane = 0;
+  for (; uiCurPlane < pcInputImage->getNumberOfFullPlanes(); uiCurPlane++ )
+  {
+    xCutPlaneMargin( pcInputImage->getPlane(uiCurPlane), (Pel) 0  , 1 );
+  }
+
+  for (; uiCurPlane < pcInputImage->getNumberOfPlanes(); uiCurPlane++ )
+  {
+    xCutPlaneMargin( pcInputImage->getPlane(uiCurPlane), (Pel) 128  , 2 );
+  }
+
+};
+
+
+Void TRenTop::xEnhSimilarity( PelImage* pcLeftImage, PelImage* pcRightImage, PelImage* pcFilledLeft, PelImage* pcFilledRight )
+{
+  if (m_iSimEnhBaseView == 0)
+    return;
+
+  UInt uiNumFullPlanes = pcLeftImage->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcLeftImage->getNumberOfQuaterPlanes();
+
+  if (uiNumQuatPlanes > 0)
+  {
+    assert( pcFilledLeft ->getNumberOfPlanes() > 1);
+    assert( pcFilledRight->getNumberOfPlanes() > 1);
+  };
+
+  xEnhSimilarityPlane ( pcLeftImage->getPlanes()                , pcRightImage->getPlanes()                , pcFilledLeft->getPlane(0), pcFilledRight->getPlane(0), uiNumFullPlanes);
+  if (uiNumQuatPlanes > 0)
+  {
+    xEnhSimilarityPlane ( pcLeftImage->getPlanes()+uiNumFullPlanes, pcRightImage->getPlanes()+uiNumFullPlanes, pcFilledLeft->getPlane(1), pcFilledRight->getPlane(1), uiNumQuatPlanes);
+  }
+}
+
+Void TRenTop::xEnhSimilarityPlane       ( PelImagePlane** apcLeftPlane, PelImagePlane** apcRightPlane, PelImagePlane* pcFilledLeftPlane, PelImagePlane* pcFilledRightPlane, UInt uiNumberOfPlanes )
+{
+  AOT( m_iSimEnhBaseView != 1 && m_iSimEnhBaseView != 2 );
+  Int iWidth  = (*apcRightPlane)->getWidth ();
+  Int iHeight = (*apcRightPlane)->getHeight();
+
+  Int* aiHistLeft  = new Int[ g_uiIBDI_MAX + 1 ];
+  Int* aiHistRight = new Int[ g_uiIBDI_MAX + 1 ];
+  Pel* aiConvLUT   = new Pel[ g_uiIBDI_MAX + 1 ];
+
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++ )
+  {
+    for (Int iCurVal = 0 ; iCurVal <= g_uiIBDI_MAX; iCurVal++)
+    {
+      aiHistLeft [iCurVal] = 0;
+      aiHistRight[iCurVal] = 0;
+    }
+
+    Pel* pcFilledRightData = pcFilledRightPlane    ->getPlaneData();
+    Pel* pcRightImageData  = (*apcRightPlane )     ->getPlaneData();
+
+    Pel* pcFilledLeftData  = pcFilledLeftPlane     ->getPlaneData();
+    Pel* pcLeftImageData   = (*apcLeftPlane)       ->getPlaneData();
+
+ 
+
+    for (UInt uiYPos = 0; uiYPos < iHeight; uiYPos++ )
+    {
+      for (UInt uiXPos = 0; uiXPos < iWidth; uiXPos++ )
+      {
+          if      ( pcFilledLeftData[uiXPos] == REN_IS_FILLED &&  pcFilledRightData[uiXPos] == REN_IS_FILLED )
+          {
+            aiHistLeft [pcLeftImageData   [uiXPos] ]++;
+            aiHistRight[pcRightImageData  [uiXPos] ]++;
+          }
+      }
+
+
+      pcFilledRightData +=    pcFilledRightPlane  ->getStride();
+      pcRightImageData  += (*apcRightPlane)       ->getStride();
+
+      pcFilledLeftData  +=    pcFilledLeftPlane   ->getStride();
+      pcLeftImageData   +=  (*apcLeftPlane)       ->getStride();
+    }
+
+    Int iCumSumChange  = 0;
+    Int iCumSumBase    = 0;
+    Int iCurBaseVal    = 0;
+    Int iCurChangeVal  = 0;
+
+    Int* aiHistChange  = (m_iSimEnhBaseView == 2 ) ? aiHistLeft  : aiHistRight;
+    Int* aiHistBase    = (m_iSimEnhBaseView == 2 ) ? aiHistRight : aiHistLeft ;
+
+    iCumSumChange += aiHistChange[iCurChangeVal];
+    iCumSumBase   += aiHistBase  [iCurBaseVal]  ;
+
+    Int iCheckSumLeft  = 0;
+    Int iCheckSumRight = 0;
+
+    for (Int iCurVal = 0 ; iCurVal <= g_uiIBDI_MAX; iCurVal++)
+    {
+      iCheckSumLeft  += aiHistLeft [iCurVal];
+      iCheckSumRight += aiHistRight[iCurVal];
+    }
+
+
+    while( iCurChangeVal <= g_uiIBDI_MAX )
+    {
+      if ( iCumSumBase == iCumSumChange )
+      {
+        aiConvLUT[iCurChangeVal] = Min(iCurBaseVal, g_uiIBDI_MAX);
+        iCurBaseVal  ++;
+        iCurChangeVal++;
+        iCumSumChange += aiHistChange[iCurChangeVal];
+        if (iCurBaseVal <= g_uiIBDI_MAX )
+        {
+          iCumSumBase   += aiHistBase  [iCurBaseVal]  ;
+        }
+      }
+      else if ( iCumSumBase < iCumSumChange )
+      {
+        iCurBaseVal++;
+        if (iCurBaseVal <= g_uiIBDI_MAX )
+        {
+          iCumSumBase   += aiHistBase  [iCurBaseVal]  ;
+        }
+      }
+      else if ( iCumSumBase > iCumSumChange)
+      {
+        aiConvLUT[iCurChangeVal] = Min(iCurBaseVal, g_uiIBDI_MAX);
+        iCurChangeVal++;
+        iCumSumChange += aiHistChange  [iCurChangeVal]  ;
+      }
+    }
+
+    Pel* pcChangeImageData   = ( ( m_iSimEnhBaseView == 2 ) ? (*apcLeftPlane) : (*apcRightPlane) )->getPlaneData();
+    Int  iChangeImageStride  = ( ( m_iSimEnhBaseView == 2 ) ? (*apcLeftPlane) : (*apcRightPlane) )->getStride   ();
+
+    for (UInt uiYPos = 0; uiYPos < iHeight; uiYPos++ )
+    {
+      for (UInt uiXPos = 0; uiXPos < iWidth; uiXPos++ )
+      {
+          pcChangeImageData  [uiXPos] = aiConvLUT[ pcChangeImageData[uiXPos]];
+      }
+      pcChangeImageData   +=  iChangeImageStride;
+    }
+
+    apcRightPlane ++;
+    apcLeftPlane  ++;
+
+  }
+
+delete[] aiHistLeft ;
+delete[] aiHistRight;
+delete[] aiConvLUT  ;
+}
+
+
+Void TRenTop::xBlend( PelImage* pcLeftImage, PelImage* pcRightImage, PelImage* pcFilledLeft, PelImage* pcFilledRight, PelImage* pcLeftDepth, PelImage* pcRightDepth, PelImage* pcOutputImage )
+{
+  UInt uiNumFullPlanes = pcLeftImage->getNumberOfFullPlanes();
+  UInt uiNumQuatPlanes = pcLeftImage->getNumberOfQuaterPlanes();
+
+  assert( uiNumFullPlanes == pcRightImage->getNumberOfFullPlanes  () && uiNumFullPlanes == pcOutputImage->getNumberOfFullPlanes    ());
+  assert( uiNumQuatPlanes == pcRightImage->getNumberOfQuaterPlanes() && uiNumQuatPlanes == pcOutputImage->getNumberOfQuaterPlanes  ());
+
+  if (uiNumQuatPlanes > 0)
+  {
+    assert( pcLeftDepth ->getNumberOfPlanes() > 1 || pcFilledLeft ->getNumberOfPlanes() > 1);
+    assert( pcRightDepth->getNumberOfPlanes() > 1 || pcFilledRight->getNumberOfPlanes() > 1);
+  };
+
+  switch (m_iBlendMode)
+  {
+  case eRenBlendAverg:
+  case eRenBlendDepthFirst:
+    xBlendPlanesAvg( pcLeftImage->getPlanes()                , pcRightImage->getPlanes()                , pcFilledLeft->getPlane(0), pcFilledRight->getPlane(0), pcLeftDepth->getPlane(0), pcRightDepth->getPlane(0), pcOutputImage->getPlanes(), uiNumFullPlanes);
+    if (uiNumQuatPlanes > 0)
+    {
+      xBlendPlanesAvg( pcLeftImage->getPlanes()+uiNumFullPlanes, pcRightImage->getPlanes()+uiNumFullPlanes, pcFilledLeft->getPlane(1), pcFilledRight->getPlane(1), pcLeftDepth->getPlane(1), pcRightDepth->getPlane(1), pcOutputImage->getPlanes()+uiNumFullPlanes, uiNumQuatPlanes);
+    }
+    break;
+  case eRenBlendLeft:
+  case eRenBlendRight:
+    xBlendPlanesOneView( pcLeftImage->getPlanes()                , pcRightImage->getPlanes()                , pcFilledLeft->getPlane(0), pcFilledRight->getPlane(0), pcLeftDepth->getPlane(0), pcRightDepth->getPlane(0), pcOutputImage->getPlanes(), uiNumFullPlanes);
+    if (uiNumQuatPlanes > 0)
+    {
+      xBlendPlanesOneView( pcLeftImage->getPlanes()+uiNumFullPlanes, pcRightImage->getPlanes()+uiNumFullPlanes, pcFilledLeft->getPlane(1), pcFilledRight->getPlane(1), pcLeftDepth->getPlane(1), pcRightDepth->getPlane(1), pcOutputImage->getPlanes()+uiNumFullPlanes, uiNumQuatPlanes);
+    }
+    break;
+  }
+}
+
+Void TRenTop::xBlendPlanesOneView( PelImagePlane** apcLeftPlane, PelImagePlane** apcRightPlane, PelImagePlane* pcFilledLeftPlane, PelImagePlane* pcFilledRightPlane, PelImagePlane* pcLeftDepthPlane, PelImagePlane* pcRightDepthPlane, PelImagePlane** apcOutputImagePlane, UInt uiNumberOfPlanes )
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++ )
+  {
+    Pel* pcFilledRightData = pcFilledRightPlane    ->getPlaneData();
+    Pel* pcRightImageData  = (*apcRightPlane )     ->getPlaneData();
+    Pel* pcRightDepthData  = pcRightDepthPlane     ->getPlaneData();
+
+    Pel* pcFilledLeftData  = pcFilledLeftPlane     ->getPlaneData();
+    Pel* pcLeftImageData   = (*apcLeftPlane)       ->getPlaneData();
+    Pel* pcLeftDepthData   = pcLeftDepthPlane      ->getPlaneData();
+    Pel* pcOutputData      = (*apcOutputImagePlane)->getPlaneData();
+
+    for (UInt uiYPos = 0; uiYPos < (*apcOutputImagePlane)->getHeight(); uiYPos++ )
+    {
+      for (UInt uiXPos = 0; uiXPos < (*apcOutputImagePlane)->getWidth(); uiXPos++ )
+      {
+        if      (m_iBlendMode == eRenBlendLeft  )
+        {
+          if      ( pcFilledLeftData[uiXPos] == REN_IS_FILLED ||  pcFilledRightData[uiXPos] == REN_IS_HOLE )
+          {
+            pcOutputData[uiXPos] = pcLeftImageData[uiXPos];
+          }
+          else if ( pcFilledLeftData[uiXPos] == REN_IS_HOLE )
+          {
+            pcOutputData[uiXPos] = pcRightImageData[uiXPos];
+          }
+          else
+          {
+            pcOutputData[uiXPos] = pcRightImageData[uiXPos] +  (Pel) (  ( (Int) ( pcLeftImageData[uiXPos] - pcRightImageData[uiXPos] ) * pcFilledLeftData[uiXPos] + (1 << (REN_VDWEIGHT_PREC - 1)) ) >> REN_VDWEIGHT_PREC );
+          }
+        }
+        else if ( m_iBlendMode == eRenBlendRight )
+        {
+          if      ( pcFilledRightData[uiXPos] == REN_IS_FILLED || pcFilledLeftData[uiXPos] == REN_IS_HOLE )
+          {
+            pcOutputData[uiXPos] = pcRightImageData[uiXPos];
+          }
+          else if ( pcFilledRightData[uiXPos] == REN_IS_HOLE )
+          {
+            pcOutputData[uiXPos] = pcLeftImageData[uiXPos];
+          }
+          else
+          {
+            pcOutputData[uiXPos] = pcLeftImageData[uiXPos] +  (Pel) (  ( (Int) ( pcRightImageData[uiXPos] - pcLeftImageData[uiXPos] ) * pcFilledRightData[uiXPos] + (1 << (REN_VDWEIGHT_PREC - 1)) ) >> REN_VDWEIGHT_PREC );
+          }
+        }
+        else
+        {
+          AOT(true);
+        }
+      }
+
+      pcFilledRightData +=    pcFilledRightPlane  ->getStride();
+      pcRightImageData  += (*apcRightPlane)       ->getStride();
+      pcRightDepthData  +=    pcRightDepthPlane   ->getStride();
+
+      pcFilledLeftData  +=    pcFilledLeftPlane   ->getStride();
+      pcLeftImageData   +=  (*apcLeftPlane)       ->getStride();
+      pcLeftDepthData   +=    pcLeftDepthPlane    ->getStride();
+      pcOutputData      +=  (*apcOutputImagePlane)->getStride();
+    }
+
+    apcRightPlane ++;
+    apcLeftPlane  ++;
+    apcOutputImagePlane++;
+  }
+}
+
+Void TRenTop::xBlendPlanesAvg( PelImagePlane** apcLeftPlane, PelImagePlane** apcRightPlane, PelImagePlane* pcFilledLeftPlane, PelImagePlane* pcFilledRightPlane, PelImagePlane* pcLeftDepthPlane, PelImagePlane* pcRightDepthPlane, PelImagePlane** apcOutputImagePlane, UInt uiNumberOfPlanes )
+{
+  for (UInt uiCurPlane = 0; uiCurPlane < uiNumberOfPlanes; uiCurPlane++ )
+  {
+    Pel* pcFilledRightData = pcFilledRightPlane   ->getPlaneData();
+    Pel* pcRightVideoData  = (*apcRightPlane )    ->getPlaneData();
+    Pel* pcRightDepthData  = pcRightDepthPlane    ->getPlaneData();
+
+    Pel* pcFilledLeftData  = pcFilledLeftPlane    ->getPlaneData();
+    Pel* pcLeftVideoData   = (*apcLeftPlane)      ->getPlaneData();
+    Pel* pcLeftDepthData   = pcLeftDepthPlane     ->getPlaneData();
+
+    Pel* pcOutputData      = (*apcOutputImagePlane)->getPlaneData();
+
+    for (UInt uiYPos = 0; uiYPos < (*apcOutputImagePlane)->getHeight(); uiYPos++ )
+    {
+      for (UInt uiXPos = 0; uiXPos < (*apcOutputImagePlane)->getWidth(); uiXPos++ )
+      {
+        if      (  (pcFilledRightData[uiXPos] != REN_IS_HOLE ) && ( pcFilledLeftData[uiXPos] != REN_IS_HOLE) )
+        {
+          Int iDepthDifference  = m_piInvZLUTLeft[RemoveBitIncrement(pcLeftDepthData[uiXPos])] - m_piInvZLUTRight[RemoveBitIncrement(pcRightDepthData[uiXPos])];
+
+          if ( abs ( iDepthDifference ) <= m_iBlendZThres )
+          {
+            if      ((pcFilledRightData[uiXPos] == REN_IS_FILLED) && ( pcFilledLeftData[uiXPos] != REN_IS_FILLED))
+            {
+              pcOutputData[uiXPos] = pcRightVideoData[uiXPos] +  (Pel) (  ( (Int) ( pcLeftVideoData[uiXPos] - pcRightVideoData[uiXPos] ) * (pcFilledLeftData[uiXPos]) + (1 << (REN_VDWEIGHT_PREC - 1)) ) >> REN_VDWEIGHT_PREC );
+            }
+            else if ((pcFilledRightData[uiXPos] != REN_IS_FILLED) && ( pcFilledLeftData[uiXPos] == REN_IS_FILLED))
+            {
+              pcOutputData[uiXPos] = pcLeftVideoData[uiXPos]  +  (Pel) (  ( (Int) ( pcRightVideoData[uiXPos] - pcLeftVideoData[uiXPos] ) * (pcFilledRightData[uiXPos]) + (1 << (REN_VDWEIGHT_PREC - 1)) ) >> REN_VDWEIGHT_PREC );
+            }
+            else
+            {
+              pcOutputData[uiXPos] = pcLeftVideoData[uiXPos]  +  (Pel) (  ( (Int) ( pcRightVideoData[uiXPos] - pcLeftVideoData[uiXPos] ) * m_iBlendDistWeight               + (1 << (REN_VDWEIGHT_PREC - 1)) ) >> REN_VDWEIGHT_PREC );
+            }
+
+          }
+          else if ( iDepthDifference < 0 )
+          {
+            pcOutputData[uiXPos] = pcRightVideoData[uiXPos];
+          }
+          else
+          {
+            pcOutputData[uiXPos] = pcLeftVideoData[uiXPos];
+          }
+        }
+        else if ( (pcFilledRightData[uiXPos] == REN_IS_HOLE) && (pcFilledLeftData[uiXPos] == REN_IS_HOLE))
+        {
+          pcOutputData[uiXPos] = m_piInvZLUTLeft[RemoveBitIncrement( pcLeftDepthData[uiXPos])]  < m_piInvZLUTRight[RemoveBitIncrement(pcRightDepthData[uiXPos])] ? pcLeftVideoData[uiXPos] : pcRightVideoData[uiXPos];
+        }
+        else
+        {
+          pcOutputData[uiXPos] =  (pcFilledLeftData[uiXPos] == REN_IS_HOLE) ? pcRightVideoData[uiXPos] : pcLeftVideoData[uiXPos];
+        }
+      }
+
+      pcFilledRightData +=    pcFilledRightPlane  ->getStride();
+      pcRightVideoData  += (*apcRightPlane)      ->getStride();
+      pcRightDepthData  +=    pcRightDepthPlane   ->getStride();
+
+      pcFilledLeftData  +=    pcFilledLeftPlane   ->getStride();
+      pcLeftVideoData   +=  (*apcLeftPlane)       ->getStride();
+      pcLeftDepthData   +=    pcLeftDepthPlane    ->getStride();
+      pcOutputData      +=  (*apcOutputImagePlane)->getStride();
+    };
+
+    apcRightPlane ++;
+    apcLeftPlane  ++;
+    apcOutputImagePlane++;
+  }
+}
+
+// Temporal Filter from Zhejiang University: (a little different from m16041: Temporal Improvement Method in View Synthesis)
+Void TRenTop::temporalFilterVSRS( TComPicYuv* pcPicYuvVideoCur, TComPicYuv* pcPicYuvDepthCur, TComPicYuv* pcPicYuvVideoLast, TComPicYuv* pcPicYuvDepthLast, Bool bFirstFrame )
+{
+  Int iSADThres  = 100 ;  //threshold of sad in 4*4 block motion detection
+
+  Int iWidth  = m_auiInputResolution[0];
+  Int iHeight = m_auiInputResolution[1];
+
+  //internal variables
+  Int* piFlagMoving =  m_aiBlkMoving + 2;
+
+  Int iVideoCurStride     = pcPicYuvVideoCur ->getStride();
+  Int iVideoLastStride    = pcPicYuvVideoLast->getStride();
+  Int iDepthCurStride     = pcPicYuvDepthCur ->getStride();
+  Int iDepthLastStride    = pcPicYuvDepthLast->getStride();
+
+  Pel* pcVideoCurData     = pcPicYuvVideoCur ->getLumaAddr();
+  Pel* pcVideoLastData    = pcPicYuvVideoLast->getLumaAddr();
+  Pel* pcDepthCurData     = pcPicYuvDepthCur ->getLumaAddr();
+  Pel* pcDepthLastData    = pcPicYuvDepthLast->getLumaAddr();
+
+  Pel* pcVideoCurDataFrm  = pcVideoCurData ;
+  Pel* pcVideoLastDataFrm = pcVideoLastData;
+  Pel* pcDepthCurDataFrm  = pcDepthCurData ;
+  Pel* pcDepthLastDataFrm = pcDepthLastData;
+
+
+  if( !bFirstFrame ) // first frame need not the weighting, but need to prepare the data
+  {
+    for ( Int iPosY = 0; iPosY < (iHeight >> 2); iPosY++)
+    {
+      //motion detection by SAD
+      for ( Int iPosX = 0; iPosX < (iWidth >> 2);  iPosX++)
+      {
+        Int iSAD = 0;
+
+        Pel* pcVideoCurDataBlk  = pcVideoCurDataFrm  + (iPosX << 2);
+        Pel* pcVideoLastDataBlk = pcVideoLastDataFrm + (iPosX << 2);
+
+        //GT: Check difference of block compared to last frame
+        for( Int iCurPosY = 0; iCurPosY < 4; iCurPosY++)
+        {
+          for( Int iCurPosX = 0; iCurPosX < 4; iCurPosX++)
+          {
+            iSAD += abs( pcVideoLastDataBlk[iCurPosX] - pcVideoCurDataBlk[iCurPosX] );   //SAD
+          }
+          pcVideoLastDataBlk += iVideoLastStride;
+          pcVideoCurDataBlk  += iVideoCurStride;
+        }
+
+        piFlagMoving[iPosX] = ( iSAD < iSADThres ) ? 0 : 1;
+      }
+
+      //temporal weighting according to motion detection result -- do a line
+      for ( Int iPosX = 0; iPosX < (iWidth >> 2);  iPosX++)
+      {
+        //5 block
+       Int iSumMoving = piFlagMoving[iPosX-2] + piFlagMoving[iPosX-1] + piFlagMoving[iPosX]   + piFlagMoving[iPosX+1] + piFlagMoving[iPosX+2];
+
+        if( iSumMoving == 0 ) // if not moving
+        {
+          Pel* pcDepthCurDataBlk  = pcDepthCurDataFrm  + (iPosX << 2);
+          Pel* pcDepthLastDataBlk = pcDepthLastDataFrm + (iPosX << 2);
+
+          for( Int iCurPosY = 0; iCurPosY < 4; iCurPosY++)
+          {
+            for( Int iCurPosX = 0; iCurPosX < 4; iCurPosX++)
+            { //Weight: 0.75
+              Int iFilt = (( (pcDepthLastDataBlk[iCurPosX] << 1 ) + pcDepthLastDataBlk[iCurPosX] + pcDepthCurDataBlk[iCurPosX] + 2 ) >> 2 );
+              assert( (iFilt >= 0) && (iFilt <=  g_uiIBDI_MAX) );
+              pcDepthCurDataBlk[iCurPosX] = pcDepthLastDataBlk[iCurPosX];
+              pcDepthCurDataBlk[iCurPosX] = iFilt;
+            }
+
+            pcDepthCurDataBlk  += iDepthCurStride;
+            pcDepthLastDataBlk += iDepthLastStride;
+          }
+        }
+      }
+
+      pcDepthCurDataFrm  += ( iDepthCurStride  << 2);
+      pcDepthLastDataFrm += ( iDepthLastStride << 2);
+      pcVideoCurDataFrm  += ( iVideoCurStride  << 2);
+      pcVideoLastDataFrm += ( iVideoLastStride << 2);
+    }
+  }
+  pcPicYuvVideoCur->copyToPic( pcPicYuvVideoLast );
+  pcPicYuvDepthCur->copyToPic( pcPicYuvDepthLast );
+}
+
+TRenTop::TRenTop()
+{
+  m_auiInputResolution[0] = 0;
+  m_auiInputResolution[1] = 0;
+
+  // Sub Pel Rendering
+  m_iLog2SamplingFactor = 0;
+
+  // ColorPlaneHandling
+  m_bUVUp = true;
+
+
+  //PreProcessing
+  m_iPreProcMode         = eRenPreProNone;
+  m_iPreFilterSize = 2;
+
+  // Interpolation
+  m_iInterpolationMode   = eRenIntFullPel;
+
+  // Sim Enhancement
+  m_iSimEnhBaseView      = 0;
+
+  // Blending
+  m_iBlendMode           = eRenBlendAverg;
+  m_iBlendZThresPerc     = -1;
+  m_bBlendUseDistWeight  = false;
+  m_iBlendHoleMargin     = -1;
+
+  m_iBlendZThres         = -1;
+  m_iBlendDistWeight     = -1;
+
+  // Hole Filling
+  m_iHoleFillingMode     = eRenHFLWBackExt;
+  m_bInstantHoleFilling  = false;
+
+  // PostProcessing
+  m_iPostProcMode        = eRenPostProNone;
+
+  // Cut
+  m_auiCut[0] = 0;
+  m_auiCut[1] = 0;
+
+  // Data
+  m_uiSampledWidth = -1;
+
+  // LUTs
+  m_ppdShiftLUTLeft  = 0;
+  m_ppdShiftLUTRight = 0;
+
+  m_ppdShiftLUTRightMirror    = new Double*[2];
+  m_ppdShiftLUTRightMirror[0] = new Double [257];
+  m_ppdShiftLUTRightMirror[1] = new Double [257];
+
+  m_adShiftLUTCur    = 0;
+
+  m_ppiShiftLUTLeft  = 0;
+  m_ppiShiftLUTRight = 0;
+  m_ppiShiftLUTRightMirror    = new Int*[2];
+  m_ppiShiftLUTRightMirror[0] = new Int[257];
+  m_ppiShiftLUTRightMirror[1] = new Int[257];
+
+  m_aiShiftLUTCur    = 0;
+  m_piInvZLUTLeft  = new Int[257];
+  m_piInvZLUTRight = new Int[257];
+
+  // Buffers
+  m_pcLeftInputImage   = 0;
+  m_pcLeftInputDepth   = 0;
+  m_pcLeftOutputImage  = 0;
+  m_pcLeftOutputDepth  = 0;
+  m_pcLeftFilled       = 0;
+
+  m_pcRightInputImage  = 0;
+  m_pcRightInputDepth  = 0;
+  m_pcRightOutputImage = 0;
+  m_pcRightOutputDepth = 0;
+  m_pcRightFilled      = 0;
+
+  m_pcOutputImage      = 0;
+  m_pcOutputDepth      = 0;
+
+  //Extrapolation
+  m_pcInputImage       = 0;
+  m_pcInputDepth       = 0;
+  m_pcFilled           = 0;
+
+  // SubPel
+  m_aaiSubPelShift     = 0;
+
+  // Temp
+  m_pcTempImage        = 0;
+
+  //Temporal Filter
+  m_aiBlkMoving        = 0;
+}
+
+
+Void TRenTop::init(UInt uiImageWidth,
+                   UInt uiImageHeight,
+                   Bool  bExtrapolate,
+                   UInt uiLog2SamplingFactor,
+                   Int   iShiftLUTPrec,
+                   Bool  bUVUp,
+                   Int   iPreProcMode,
+                   Int   iPreFilterKernelSize,
+                   Int   iBlendMode,
+                   Int   iBlendZThresPerc,
+                   Bool  bBlendUseDistWeight,
+                   Int   iBlendHoleMargin,
+                   Int   iInterpolationMode,
+                   Int   iHoleFillingMode,
+                   Int   iPostProcMode,
+                   Int   iUsedPelMapMarExt
+                   )
+
+{
+  // Shift LUT Prec
+  m_iRelShiftLUTPrec = iShiftLUTPrec - (Int) uiLog2SamplingFactor;
+
+  // Sub Pel Rendering
+  m_iLog2SamplingFactor = uiLog2SamplingFactor;
+
+  // Extrapolation ?
+  m_bExtrapolate = bExtrapolate;
+
+  // ColorPlaneHandling
+  m_bUVUp = bUVUp;
+
+  //PreProcessing
+  m_iPreProcMode = iPreProcMode;
+  m_iPreFilterSize = iPreFilterKernelSize;
+
+  // Interpolation
+  m_iInterpolationMode = iInterpolationMode;
+
+  //Blending
+  m_iBlendMode          = iBlendMode;
+  m_iBlendZThresPerc    = iBlendZThresPerc;
+  m_bBlendUseDistWeight = bBlendUseDistWeight;
+  m_iBlendHoleMargin    = iBlendHoleMargin;
+
+  // Hole Filling
+  m_iHoleFillingMode = iHoleFillingMode;
+
+  m_bInstantHoleFilling   = (m_iInterpolationMode == eRenInt8Tap ) && (m_iHoleFillingMode != 0 );
+
+  // PostProcessing
+  m_iPostProcMode    = iPostProcMode;
+
+  // Used pel map
+  m_iUsedPelMapMarExt     = iUsedPelMapMarExt;
+
+  // Cut
+  m_auiCut[0] = 0;
+  m_auiCut[1] = 0;
+
+  m_auiInputResolution[0] = uiImageWidth;
+  m_auiInputResolution[1] = uiImageHeight;
+
+  if ( m_bExtrapolate )
+  {
+    PelImage*    pcDump        = 0;
+    xGetDataPointers( m_pcInputImage, m_pcOutputImage, m_pcInputDepth, pcDump, m_pcFilled, false );
+  }
+  else
+  {
+    xGetDataPointers(m_pcLeftInputImage,  m_pcLeftOutputImage,  m_pcLeftInputDepth,  m_pcLeftOutputDepth,  m_pcLeftFilled,  true);
+    xGetDataPointers(m_pcRightInputImage, m_pcRightOutputImage, m_pcRightInputDepth, m_pcRightOutputDepth, m_pcRightFilled, true);
+    xGetDataPointerOutputImage(m_pcOutputImage, m_pcOutputDepth );
+  }
+
+  m_pcTempImage = new PelImage( m_auiInputResolution[0],m_auiInputResolution[1],1,2);
+
+  // SubPelShiftLUT
+  if (iInterpolationMode == eRenInt8Tap)
+  {
+    // SubPel Shift LUT
+    Int iNumEntries = (1 << ( m_iRelShiftLUTPrec + 1) ) + 1 ;
+    m_aaiSubPelShift = new Int*[ iNumEntries ];
+    for (UInt uiEntry = 0; uiEntry < iNumEntries; uiEntry++)
+    {
+      m_aaiSubPelShift[uiEntry] = new Int[ iNumEntries ];
+    }
+
+    TRenFilter::setSubPelShiftLUT(m_iRelShiftLUTPrec, m_aaiSubPelShift, -1);
+  }
+
+  // Zheijang temporal filter
+  m_aiBlkMoving    = new Int[ ( m_auiInputResolution[0] >> 2 ) + 4 ];
+  m_aiBlkMoving[0] = 0;
+  m_aiBlkMoving[1] = 0;
+  m_aiBlkMoving[ ( m_auiInputResolution[0] >> 2 ) + 2 ] = 0;
+  m_aiBlkMoving[ ( m_auiInputResolution[0] >> 2 ) + 3 ] = 0;
+}
+
+
+TRenTop::~TRenTop()
+{
+  if ( m_ppdShiftLUTRightMirror != NULL )
+  {
+    delete[] m_ppdShiftLUTRightMirror[0];
+    delete[] m_ppdShiftLUTRightMirror[1];
+    delete[] m_ppdShiftLUTRightMirror;
+  };
+
+  if ( m_ppiShiftLUTRightMirror != NULL )
+  {
+    delete[] m_ppiShiftLUTRightMirror[0];
+    delete[] m_ppiShiftLUTRightMirror[1];
+    delete[] m_ppiShiftLUTRightMirror;
+  };
+
+  if (m_piInvZLUTLeft      != NULL ) delete[] m_piInvZLUTLeft   ;
+  if (m_piInvZLUTLeft      != NULL ) delete[] m_piInvZLUTRight  ;
+
+  if (m_pcLeftInputImage   != NULL ) delete m_pcLeftInputImage  ;
+  if (m_pcLeftInputDepth   != NULL ) delete m_pcLeftInputDepth  ;
+  if (m_pcLeftOutputImage  != NULL ) delete m_pcLeftOutputImage ;
+  if (m_pcLeftOutputDepth  != NULL ) delete m_pcLeftOutputDepth ;
+  if (m_pcLeftFilled       != NULL ) delete m_pcLeftFilled      ;
+
+  if (m_pcRightInputImage  != NULL ) delete m_pcRightInputImage ;
+  if (m_pcRightInputDepth  != NULL ) delete m_pcRightInputDepth ;
+  if (m_pcRightOutputImage != NULL ) delete m_pcRightOutputImage;
+  if (m_pcRightOutputDepth != NULL ) delete m_pcRightOutputDepth;
+  if (m_pcRightFilled      != NULL ) delete m_pcRightFilled     ;
+
+  if (m_pcOutputImage      != NULL ) delete m_pcOutputImage     ;
+  if (m_pcOutputDepth      != NULL ) delete m_pcOutputDepth     ;
+
+  if (m_pcInputImage       != NULL ) delete m_pcInputImage      ;
+  if (m_pcInputDepth       != NULL ) delete m_pcInputDepth      ;
+  if (m_pcFilled           != NULL ) delete m_pcFilled          ;
+
+  if (m_pcTempImage        != NULL ) delete m_pcTempImage       ;
+
+  // SubPel LUT
+  if ( m_aaiSubPelShift != NULL)
+  {
+    Int iNumEntries = (1 << ( m_iRelShiftLUTPrec + 1) ) + 1;
+    for (UInt uiEntry = 0; uiEntry < iNumEntries; uiEntry++)
+    {
+      delete[] m_aaiSubPelShift[uiEntry];
+    }
+    delete[] m_aaiSubPelShift;
+  }
+
+  // Zheijang temporal filter
+  if(m_aiBlkMoving         != NULL ) delete[] m_aiBlkMoving;
+}
Index: branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenTop.h
===================================================================
--- branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenTop.h	(revision 438)
+++ branches/HTM-DEV-0.2-dev/source/Lib/TLibRenderer/TRenTop.h	(revision 438)
@@ -0,0 +1,270 @@
+/* The copyright in this software is being made available under the BSD
+ * License, included below. This software may be subject to other third party
+ * and contributor rights, including patent rights, and no such rights are
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2011, ISO/IEC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __TRENTOP__
+#define __TRENTOP__
+
+#include "TRenImage.h"
+#include "../TLibCommon/CommonDef.h"
+#include "../TLibCommon/TComPicYuv.h"
+#include <list>
+#include <vector>
+
+using namespace std;
+
+class TRenTop
+{
+// ENUM Modes
+
+
+  // Interpolation Modes
+
+  enum { eRenIntFullPel = 0, eRenIntLinInt = 1, eRenIntLinReal = 2, eRenIntFEM = 3, eRenInt8Tap = 4 };
+
+  // HoleFilling
+  enum { eRenHFNone = 0, eRenHFLWBackExt = 1};
+
+  // Pre-Processing
+  enum { eRenPreProNone = 0, eRenPreProBinom = 1};
+
+  // Post-Processing
+  enum { eRenPostProNone = 0, eRenPostProMed = 1};
+
+  // Merging
+  enum { eRenBlendAverg = 0, eRenBlendLeft = 1, eRenBlendRight = 2, eRenBlendDepthFirst = 5 };
+
+public:
+  TRenTop();
+  ~TRenTop();
+
+  // Init
+  Void init              ( UInt uiImageWitdh,
+                           UInt uiImageHeight,
+                           Bool bExtrapolate,
+                           UInt uiLog2SamplingFactor,
+                           Int  iLUTPrec,
+                           Bool bUVUp,
+                           Int  iPreProcMode,
+                           Int  iPreFilterKernelSize,
+                           Int  iBlendMode,
+                           Int  iBlendZThresPerc,
+                           Bool bBlendUseDistWeight,
+                           Int  iBlendHoleMargin,
+                           Int  iInterpolationMode,
+                           Int  iHoleFillingMode,
+                           Int  iPostProcMode,
+                           Int  iUsedPelMapMarExt );
+
+  Void setShiftLUTs      ( Double** ppdShiftLUTLeft,
+                           Int**    ppiShiftLUTLeft,
+                           Int**    ppiBaseShiftLUTLeft,
+                           Double** ppdShiftLUTRight,
+                           Int**    ppiShiftLUTRight,
+                           Int**    ppiBaseShiftLUTRight,
+                           Int      iRelDistLeft );
+
+  // View Synthesis
+  Void extrapolateView   ( TComPicYuv* pcPicYuvVideo,
+                           TComPicYuv* pcPicYuvDepth,
+                           TComPicYuv* pcPicYuvSynthOut,
+                           Bool bRenderFromLeft );
+
+  Void interpolateView   ( TComPicYuv* pcPicYuvVideoLeft,
+                           TComPicYuv* pcPicYuvDepthLeft,
+                           TComPicYuv* pcPicYuvVideoRight,
+                           TComPicYuv* pcPicYuvDepthRight,
+                           TComPicYuv* pcPicYuvSynthOut,
+                           Int         iBlendMode,
+                           Int         iSimEnhBaseView );
+  // Tools
+  Void getUsedSamplesMap ( TComPicYuv* pcPicYuvDepth,
+                           TComPicYuv* pcUsedSampleMap,
+                           Bool bRenderFromLeft );
+
+  // Zhejiang Temporal Improvement
+  Void temporalFilterVSRS( TComPicYuv* pcPicYuvVideoCur,
+                           TComPicYuv* pcPicYuvDepthCur,
+                           TComPicYuv* pcPicYuvVideoLast,
+                           TComPicYuv* pcPicYuvDepthLast,
+                           Bool bFirstFrame );
+
+private:
+  // Depth PreProcessing
+  Void xPreProcessDepth(PelImage* pcInImage, PelImage* pcOutImage);
+
+  // Pixel Shifting
+  Void xShiftPixels              ( PelImage*        pcInImage,     PelImage*      pcDepth     , PelImage*        pcOutImage    , PelImage*      pcFilledImage, Bool bShiftFromLeft  );
+  Void xShiftPlanePixels         ( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcPlaneFilled, UInt uiNumberOfPlanes);
+  Void xShiftPlanePixelsLinReal  ( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcPlaneFilled, UInt uiNumberOfPlanes);
+  Void xShiftPlanePixelsFullPel  ( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcPlaneFilled, UInt uiNumberOfPlanes);
+  Void xShiftPlanePixelsLinInt   ( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes);
+  Void xShiftPlanePixels8Tap     ( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes);
+
+  Void xBackShiftPixels          ( PelImage*            pcInImage, PelImage*      pcDepth     , PelImage*            pcOutImage, PelImage*      pcFilledImage, Bool bShiftFromLeft   );
+  Void xBackShiftPlanePixels     ( PelImagePlane** apcInputPlanes, PelImagePlane* pcDepthPlane, PelImagePlane** apcOutputPlanes, PelImagePlane* pcFilledPlane, UInt uiNumberOfPlanes );
+
+  Int  xCeil                     ( Int iVal ) { return (( iVal + ( (1 << m_iRelShiftLUTPrec) - 1 ) ) >> m_iRelShiftLUTPrec);  }
+
+  // Hole Filling
+  Void xFillHoles                ( PelImage*       pcInImage,      PelImage*      pcFilled,      PelImage*       pcOutImage                            , Bool bRenderFromLeft );
+  Void xFillLWBackExt            ( PelImage*       pcInImage,      PelImage*      pcFilled,      PelImage*       pcOutImage                            , Bool bRenderFromLeft );
+  Void xFillPlaneHoles           ( PelImagePlane** apcInputPlanes, PelImagePlane* pcPlaneFilled, PelImagePlane** apcOutputPlanes, UInt uiNumberOfPlanes, Bool bRenderFromLeft );
+
+  // Alpha Map Creation
+  Void xCreateAlphaMap           (PelImage* pcFilledImage,         PelImage*       pcAlphaMapImage, Bool bRenderFromLeft );
+  Void xCreateAlphaMapPlane      (PelImagePlane** apcFilledPlanes, PelImagePlane** apcAlphaPlanes,  UInt uiNumberOfPlanes, Bool bRenderFromLeft);
+
+  // BoundaryNoiseErosion
+  Void xRemBoundaryNoise            ( PelImage*       pcInImage,      PelImage*      pcFilled,      PelImage*       pcOutImage                            , Bool bRenderFromLeft );
+  Void xRemBoundaryNoisePlane       ( PelImagePlane** apcInputPlanes, PelImagePlane* pcPlaneFilled, PelImagePlane** apcOutputPlanes, UInt uiNumberOfPlanes, Bool bRenderFromLeft );
+
+  // Similarity Enhancement
+  Void xEnhSimilarity            ( PelImage*      pcLeftImage,   PelImage*        pcRightImage, PelImage*      pcFilledLeft,      PelImage*      pcFilledRight      );
+  Void xEnhSimilarityPlane       ( PelImagePlane** apcLeftPlane, PelImagePlane** apcRightPlane, PelImagePlane* pcFilledLeftPlane, PelImagePlane* pcFilledRightPlane, UInt uNumPlanes );
+
+  // View Blending
+  Void xBlend                    ( PelImage*       pcLeftImage,  PelImage*        pcRightImage, PelImage*      pcFilledLeft,      PelImage*      pcFilledRight,      PelImage* pcLeftDepth,           PelImage* pcRightDepth,           PelImage* pcOutputImage);
+  Void xBlendPlanesAvg           ( PelImagePlane** apcLeftPlane, PelImagePlane** apcRightPlane, PelImagePlane* pcFilledLeftPlane, PelImagePlane* pcFilledRightPlane, PelImagePlane* pcLeftDepthPlane, PelImagePlane* pcRightDepthPlane, PelImagePlane** apcOutputImagePlane, UInt uNumPlanes );
+  Void xBlendPlanesOneView       ( PelImagePlane** apcLeftPlane, PelImagePlane** apcRightPlane, PelImagePlane* pcFilledLeftPlane, PelImagePlane* pcFilledRightPlane, PelImagePlane* pcLeftDepthPlane, PelImagePlane* pcRightDepthPlane, PelImagePlane** apcOutputImagePlane, UInt uNumPlanes );
+
+  // PostProcessing
+  Void xCutMargin                ( PelImage* pcInputImage );
+  Void xCutPlaneMargin           ( PelImagePlane* pcImagePlane, Pel cFill, UInt uiScale);
+  Void xPostProcessImage         ( PelImage* pcInImage,       PelImage* pCOutImage);
+
+  // Input Output Data Conversion
+  Void xConvertInputData         ( PelImage* pcOrgInputImage, PelImage* pcOrgInputDepth, PelImage* pcConvInputImage, PelImage* pcConvInputDepth, Bool bMirror);
+  Void xConvertOutputData        ( PelImage* pOrgOutputImage, PelImage* pConvOutputImage, Bool bMirror);
+
+  Void xGetDataPointers          ( PelImage*& rpcInputImage,  PelImage*& rpcOutputImage, PelImage*& rpcInputDepth, PelImage*& rpcOutputDepth, PelImage*& rpcFilled, Bool bRenderDepth );
+  Void xGetDataPointerOutputImage( PelImage*& rpcOutputImage, PelImage*& rpcOutputDepth );
+
+  Void xConvertInputVideo        ( PelImage* pcOrgInputImage, PelImage* pcConvInputImage);
+  Void xConvertInputDepth        ( PelImage* pcOrgInputImage, PelImage* pcConvInputImage);
+
+
+  // Data
+  UInt m_uiSampledWidth;    // Width after UPsampling
+
+  // Resolution of input view
+  UInt  m_auiInputResolution[2];
+
+  // Extrapolation
+  Bool m_bExtrapolate;
+
+  // Input Conversion
+  Int  m_iLog2SamplingFactor;
+  Bool m_bUVUp;
+
+  // PreProcessing
+  Int  m_iPreProcMode;         //0: none, 1: binominal
+  Int  m_iPreFilterSize;       // Half size
+
+  // Similarity Enhancement
+  Int  m_iSimEnhBaseView;      // 0: none, 1: left, 2: right
+
+  // Blending
+  Int  m_iBlendMode;           // 0: average;
+  Int  m_iBlendZThresPerc;     // in percent of total depth
+  Bool m_bBlendUseDistWeight;  // use weighting depending on viewing distance
+  Int  m_iBlendHoleMargin;     // blending margin next to holes
+
+  Int  m_iBlendZThres;         // absoluteInt  m_iBlendWeight;
+  Int  m_iBlendDistWeight;     // Weight for view distance depending blending
+
+  // Interpolation
+  Int  m_iInterpolationMode;   //0: none; 1: Linear (Double), 2: FEM (Double)
+
+  // Hole Filling
+  Int  m_iHoleFillingMode;     //0: none; 1: LW Background extension
+  Int  m_bInstantHoleFilling;  // perform hole filling while pixel shifting ( only supported for interpolation mode 4 )
+
+  // Post Processing
+  Int  m_iPostProcMode;        //0: none; 1: Median
+
+  // Precision in LUT
+  Int  m_iRelShiftLUTPrec;
+
+  // Cut
+  UInt m_auiCut[2];
+
+  // Look up tables Shift
+  Double** m_ppdShiftLUTLeft;
+  Double** m_ppdShiftLUTRight;
+  Double** m_ppdShiftLUTRightMirror; // For rendering the mirrored view
+  Double*  m_adShiftLUTCur;
+
+  Int**    m_ppiShiftLUTLeft;
+  Int**    m_ppiShiftLUTRight;
+  Int**    m_ppiShiftLUTRightMirror; // For rendering the mirrored view
+  Int*     m_aiShiftLUTCur;
+
+  // Look up tables Z
+  Int*     m_piInvZLUTLeft;          // Look up table entry is proportional to Z
+  Int*     m_piInvZLUTRight;
+
+  // Look up tables sub pel shift
+  Int**    m_aaiSubPelShift;
+
+   // Zhejiang Temporal Improvement
+  Int*    m_aiBlkMoving;
+
+  // Used pel map generation
+  Int      m_iUsedPelMapMarExt;
+
+  // Buffers
+
+  // Interpolation
+  PelImage* m_pcLeftInputImage  ;
+  PelImage* m_pcLeftInputDepth  ;
+  PelImage* m_pcLeftOutputImage ;
+  PelImage* m_pcLeftOutputDepth ;
+  PelImage* m_pcLeftFilled      ;
+  PelImage* m_pcRightInputImage ;
+  PelImage* m_pcRightInputDepth ;
+  PelImage* m_pcRightOutputImage;
+  PelImage* m_pcRightOutputDepth;
+  PelImage* m_pcRightFilled     ;
+  PelImage* m_pcOutputImage     ;
+  PelImage* m_pcOutputDepth     ;
+
+  // Extrapolation
+  PelImage* m_pcInputImage      ;
+  PelImage* m_pcInputDepth      ;
+  PelImage* m_pcFilled          ;
+
+  //Temp
+  PelImage* m_pcTempImage       ;
+};
+
+#endif //__TRENTOP__
