Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 713)
@@ -58,7 +58,7 @@
 #if SVC_EXTENSION
 #include <vector>
-#define NV_VERSION        "5.1 (HM-13.0)"                 ///< Current software version
+#define NV_VERSION        "6.0 (HM-14.0)"                 ///< Current software version
 #else
-#define NV_VERSION        "13.0"                ///< Current software version
+#define NV_VERSION        "14.0"                ///< Current software version
 #endif
 
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 713)
@@ -79,13 +79,16 @@
 #endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-    INTER_LAYER_CONSTRAINED_TILE_SETS    = 138
+    INTER_LAYER_CONSTRAINED_TILE_SETS    = 138,
 #endif
 #if SUB_BITSTREAM_PROPERTY_SEI
-   ,SUB_BITSTREAM_PROPERTY               = 139    // Final PayloadType to be defined after finalization
+    SUB_BITSTREAM_PROPERTY               = 139,    // Final PayloadType to be defined after finalization
 #endif
 #if O0164_MULTI_LAYER_HRD
-   ,BSP_NESTING                          = 140
-   ,BSP_INITIAL_ARRIVAL_TIME             = 141
-   ,BSP_HRD                              = 142
+    BSP_NESTING                          = 140,
+    BSP_INITIAL_ARRIVAL_TIME             = 141,
+    BSP_HRD                              = 142,
+#endif
+#if Q0074_SEI_COLOR_MAPPING
+    COLOR_MAPPING_INFO                   = 143,
 #endif
   };
@@ -142,6 +145,6 @@
   SEIActiveParameterSets() 
     : activeVPSId            (0)
-    , m_fullRandomAccessFlag (false)
-    , m_noParamSetUpdateFlag (false)
+    , m_selfContainedCvsFlag (false)
+    , m_noParameterSetUpdateFlag (false)
     , numSpsIdsMinus1        (0)
   {}
@@ -149,8 +152,8 @@
 
   Int activeVPSId; 
-  Bool m_fullRandomAccessFlag;
-  Bool m_noParamSetUpdateFlag;
+  Bool m_selfContainedCvsFlag;
+  Bool m_noParameterSetUpdateFlag;
   Int numSpsIdsMinus1;
-  std::vector<Int> activeSeqParamSetId; 
+  std::vector<Int> activeSeqParameterSetId; 
 };
 
@@ -393,4 +396,6 @@
   Int    m_cameraIsoSpeedIdc;
   Int    m_cameraIsoSpeedValue;
+  Int    m_exposureIndexIdc;
+  Int    m_exposureIndexValue;
   Int    m_exposureCompensationValueSignFlag;
   Int    m_exposureCompensationValueNumerator;
@@ -402,4 +407,40 @@
   Int    m_extendedWhiteLevelLumaCodeValue;
 };
+
+#if Q0074_SEI_COLOR_MAPPING
+class SEIColorMappingInfo : public SEI
+{
+public:
+  PayloadType payloadType() const { return COLOR_MAPPING_INFO; }
+  SEIColorMappingInfo() {
+  }
+  virtual ~SEIColorMappingInfo() {}
+
+  Int   m_colorMapId;
+  Bool  m_colorMapCancelFlag;
+  Bool  m_colorMapPersistenceFlag;
+  Bool  m_colorMap_video_signal_type_present_flag;
+  Bool  m_colorMap_video_full_range_flag;
+  Int   m_colorMap_primaries;
+  Int   m_colorMap_transfer_characteristics;
+  Int   m_colorMap_matrix_coeffs;
+  Int   m_colorMapModelId;
+
+  Int   m_colour_map_coded_data_bit_depth;
+  Int   m_colour_map_target_bit_depth;
+
+  Int   m_num_input_pivots[3];
+  Int*  m_coded_input_pivot_value[3];
+  Int*  m_target_input_pivot_value[3];
+  
+  Bool  m_matrix_flag;
+  Int   m_log2_matrix_denom;
+  Int   m_matrix_coef[3][3];
+
+  Int   m_num_output_pivots[3];
+  Int*  m_coded_output_pivot_value[3];
+  Int*  m_target_output_pivot_value[3];
+};
+#endif
 
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
Index: trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp	(revision 713)
+++ trunk/source/Lib/TLibCommon/TCom3DAsymLUT.cpp	(revision 713)
@@ -0,0 +1,279 @@
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cmath>
+#include <algorithm>
+
+#include "TypeDef.h"
+#include "TCom3DAsymLUT.h"
+#include "TComPicYuv.h"
+
+#if Q0048_CGS_3D_ASYMLUT
+
+const Int TCom3DAsymLUT::m_nVertexIdxOffset[4][3] = { { 0 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 1 , 1 } , { 1 , 1 , 1 } };
+
+TCom3DAsymLUT::TCom3DAsymLUT()
+{
+  m_pCuboid = NULL;
+  m_nResQuanBit = 0;
+}
+
+TCom3DAsymLUT::~TCom3DAsymLUT()
+{
+  destroy();
+}
+
+Void TCom3DAsymLUT::create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 )
+{
+  m_nMaxOctantDepth = nMaxOctantDepth;
+  m_nInputBitDepthY = nInputBitDepth;
+  m_nOutputBitDepthY = nOutputBitDepth;
+  m_nInputBitDepthC = nInputBitDepthC;
+  m_nOutputBitDepthC = nOutputBitDepthC;
+  m_nDeltaBitDepthC = m_nOutputBitDepthC - m_nInputBitDepthC;
+  m_nDeltaBitDepth = m_nOutputBitDepthY - m_nInputBitDepthY;
+  m_nMaxYPartNumLog2 = nMaxYPartNumLog2;
+  m_nMaxPartNumLog2 = 3 * m_nMaxOctantDepth + m_nMaxYPartNumLog2;
+
+  xUpdatePartitioning( nMaxOctantDepth , nMaxYPartNumLog2 );
+
+  m_nYSize = 1 << ( m_nMaxOctantDepth + m_nMaxYPartNumLog2 );
+  m_nUSize = 1 << m_nMaxOctantDepth;
+  m_nVSize = 1 << m_nMaxOctantDepth;
+  assert( m_nYSize > 0 && m_nUSize > 0 && m_nVSize > 0 );
+
+  if( m_pCuboid != NULL )
+    destroy();
+  xAllocate3DArray( m_pCuboid , m_nYSize , m_nUSize , m_nVSize );
+}
+
+Void TCom3DAsymLUT::destroy()
+{
+  xFree3DArray( m_pCuboid );
+}
+
+Void TCom3DAsymLUT::xUpdatePartitioning( Int nCurOctantDepth , Int nCurYPartNumLog2 )
+{
+  assert( nCurOctantDepth <= m_nMaxOctantDepth );
+  assert( nCurYPartNumLog2 <= m_nMaxYPartNumLog2 );
+
+  m_nCurOctantDepth = nCurOctantDepth;
+  m_nCurYPartNumLog2 = nCurYPartNumLog2;
+  m_nYShift2Idx = m_nInputBitDepthY - m_nCurOctantDepth - m_nCurYPartNumLog2;
+  m_nUShift2Idx = m_nVShift2Idx = m_nInputBitDepthC - m_nCurOctantDepth;
+  m_nMappingShift = m_nYShift2Idx + m_nUShift2Idx;
+  m_nMappingOffset = 1 << ( m_nMappingShift - 1 );
+}
+
+Void TCom3DAsymLUT::colorMapping( TComPicYuv * pcPic, TComPicYuv * pcPicDst )
+{
+  Int nWidth = pcPic->getWidth();
+  Int nHeight = pcPic->getHeight();
+  Int nStrideY = pcPic->getStride();
+  Int nStrideC = pcPic->getCStride();
+  Pel * pY = pcPic->getLumaAddr();
+  Pel * pU = pcPic->getCbAddr();
+  Pel * pV = pcPic->getCrAddr();
+
+  Int nDstStrideY = pcPicDst->getStride();
+  Int nDstStrideC = pcPicDst->getCStride();
+  Pel * pYDst = pcPicDst->getLumaAddr();
+  Pel * pUDst = pcPicDst->getCbAddr();
+  Pel * pVDst = pcPicDst->getCrAddr();
+
+  Pel *pUPrev = pU;
+  Pel *pVPrev = pV;
+  Pel *pUNext = pU+nStrideC;
+  Pel *pVNext = pV+nStrideC;
+
+  // alignment padding
+  pU += (nWidth>>1);
+  pV += (nWidth>>1);
+  for( Int y = 0 ; y < (nHeight>>1) ; y ++ )
+  {
+    *pU = pU[-1];
+    *pV = pV[-1];
+    pU += nStrideC;
+    pV += nStrideC;
+  }
+  memcpy(pU-(nWidth>>1), pU-(nWidth>>1)-nStrideC, ((nWidth>>1)+1)*sizeof(Pel));
+  memcpy(pV-(nWidth>>1), pV-(nWidth>>1)-nStrideC, ((nWidth>>1)+1)*sizeof(Pel));
+  pU = pcPic->getCbAddr();
+  pV = pcPic->getCrAddr();
+
+  Pel iMaxValY = (1<<getOutputBitDepthY())-1;
+  Pel iMaxValC = (1<<getOutputBitDepthC())-1;
+  for( Int y = 0 ; y < nHeight ; y += 2 )
+  {
+    for( Int xY = 0 , xC = 0 ; xY < nWidth ; xY += 2 , xC++ )
+    {
+      Pel srcY00 = pY[xY];
+      Pel srcY01 = pY[xY+1];
+      Pel srcY10 = pY[xY+nStrideY];
+      Pel srcY11 = pY[xY+nStrideY+1];
+      Pel srcYaver;
+      Pel srcU = pU[xC];
+      Pel srcV = pV[xC];
+      Pel dstY00, dstY01, dstY10, dstY11;
+
+      // alignment
+      srcYaver =  (srcY00 + srcY10 + 1 ) >> 1;
+      Pel srcUP0 = pUPrev[xC];
+      Pel srcVP0 = pVPrev[xC];        
+      Pel tmpU =  (srcUP0 + srcU + (srcU<<1) + 2 ) >> 2;
+      Pel tmpV =  (srcVP0 + srcV + (srcV<<1) + 2 ) >> 2;
+      dstY00 = xMapY( srcY00 , tmpU , tmpV );
+      Pel a = pU[xC+1] + srcU;
+      tmpU =  ((a<<1) + a + srcUP0 + pUPrev[xC+1] + 4 ) >> 3;
+      Pel b = pV[xC+1] + srcV;
+      tmpV =  ((b<<1) + b + srcVP0 + pVPrev[xC+1] + 4 ) >> 3;
+      dstY01 = xMapY( srcY01 , tmpU , tmpV );
+
+      srcUP0 = pUNext[xC];
+      srcVP0 = pVNext[xC];
+      tmpU =  (srcUP0 + srcU + (srcU<<1) + 2 ) >> 2;
+      tmpV =  (srcVP0 + srcV + (srcV<<1) + 2 ) >> 2;
+      dstY10 = xMapY( srcY10 , tmpU , tmpV );
+      tmpU =  ((a<<1) + a + srcUP0 + pUNext[xC+1] + 4 ) >> 3;
+      tmpV =  ((b<<1) + b + srcVP0 + pVNext[xC+1] + 4 ) >> 3;
+      dstY11 = xMapY( srcY11 , tmpU , tmpV );
+
+      SYUVP dstUV = xMapUV( srcYaver , srcU , srcV );
+      pYDst[xY] = Clip3((Pel)0, iMaxValY, dstY00 );
+      pYDst[xY+1] = Clip3((Pel)0, iMaxValY, dstY01 );
+      pYDst[xY+nDstStrideY] = Clip3((Pel)0, iMaxValY, dstY10 );
+      pYDst[xY+nDstStrideY+1] = Clip3((Pel)0, iMaxValY, dstY11 );
+      pUDst[xC] = Clip3((Pel)0, iMaxValC, dstUV.U );
+      pVDst[xC] = Clip3((Pel)0, iMaxValC, dstUV.V );
+    }
+    pY += nStrideY + nStrideY;
+
+    // alignment
+    pUPrev = pU;
+    pVPrev = pV;
+    pU = pUNext;
+    pV = pVNext;
+    pUNext += nStrideC;
+    pVNext += nStrideC;
+
+    pYDst += nDstStrideY + nDstStrideY;
+    pUDst += nDstStrideC;
+    pVDst += nDstStrideC;
+  }
+}
+
+SYUVP TCom3DAsymLUT::xGetCuboidVertexPredA( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx )
+{
+  assert( nVertexIdx < 4 );
+  
+  SYUVP sPred;
+  sPred.Y = ( yIdx + m_nVertexIdxOffset[nVertexIdx][0] ) << ( m_nYShift2Idx + m_nDeltaBitDepth );
+  sPred.U = ( uIdx + m_nVertexIdxOffset[nVertexIdx][1] ) << ( m_nUShift2Idx + m_nDeltaBitDepthC );
+  sPred.V = ( vIdx + m_nVertexIdxOffset[nVertexIdx][2] ) << ( m_nVShift2Idx + m_nDeltaBitDepthC );
+  return( sPred );
+}
+
+SYUVP  TCom3DAsymLUT::xGetCuboidVertexPredAll( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , SCuboid *** pCurCuboid )
+{
+  SCuboid***  pCuboid = pCurCuboid ? pCurCuboid : m_pCuboid ;
+
+  // PredA
+  SYUVP sPredA = xGetCuboidVertexPredA( yIdx , uIdx , vIdx , nVertexIdx );
+
+  // PredB
+  SYUVP sPredB; 
+  memset( &sPredB , 0 , sizeof( sPredB ) );
+  if( yIdx > 0 )
+  {
+    SYUVP & recNeighborP = pCuboid[yIdx-1][uIdx][vIdx].P[nVertexIdx];
+    SYUVP sPredNeighbor = xGetCuboidVertexPredA( yIdx - 1 , uIdx , vIdx , nVertexIdx );
+    sPredB.Y += recNeighborP.Y - sPredNeighbor.Y ;
+    sPredB.U += recNeighborP.U - sPredNeighbor.U ;
+    sPredB.V += recNeighborP.V - sPredNeighbor.V ;
+
+    Pel min = - ( 1 << ( getOutputBitDepthY() - 2 ) );
+    Pel max =  - min;
+    sPredB.Y = Clip3( min , max , sPredB.Y );
+    min = - ( 1 << ( getOutputBitDepthC() - 2 ) );
+    max =  - min;
+    sPredB.U = Clip3( min , max , sPredB.U );
+    sPredB.V = Clip3( min , max , sPredB.V );
+  }
+
+  SYUVP sPred;
+  sPred.Y = sPredA.Y + sPredB.Y;
+  sPred.U = sPredA.U + sPredB.U;
+  sPred.V = sPredA.V + sPredB.V;
+
+  return sPred ;
+}
+
+SYUVP TCom3DAsymLUT::getCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx )
+{
+  const SYUVP & rYUVP = m_pCuboid[yIdx][uIdx][vIdx].P[nVertexIdx];
+  SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , nVertexIdx );
+
+  SYUVP sResidue;
+  sResidue.Y = ( rYUVP.Y - sPred.Y ) >> m_nResQuanBit;
+  sResidue.U = ( rYUVP.U - sPred.U ) >> m_nResQuanBit;
+  sResidue.V = ( rYUVP.V - sPred.V ) >> m_nResQuanBit;
+  return( sResidue );
+}
+
+Void TCom3DAsymLUT::setCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , Int deltaY , Int deltaU , Int deltaV )
+{
+  SYUVP & rYUVP = m_pCuboid[yIdx][uIdx][vIdx].P[nVertexIdx];
+  SYUVP sPred = xGetCuboidVertexPredAll( yIdx , uIdx , vIdx , nVertexIdx );
+
+  rYUVP.Y = sPred.Y + ( deltaY << m_nResQuanBit );
+  rYUVP.U = sPred.U + ( deltaU << m_nResQuanBit );
+  rYUVP.V = sPred.V + ( deltaV << m_nResQuanBit );
+}
+
+Pel TCom3DAsymLUT::xMapY( Pel y , Pel u , Pel v )
+{
+  const SCuboid & rCuboid = m_pCuboid[y>>m_nYShift2Idx][u>>m_nUShift2Idx][v>>m_nVShift2Idx];
+  Pel dstY = rCuboid.P[0].Y;
+  Int deltaY = y - ( y >> m_nYShift2Idx << m_nYShift2Idx );
+  Int deltaU = u - ( u >> m_nUShift2Idx << m_nUShift2Idx );
+  Int deltaV = v - ( v >> m_nVShift2Idx << m_nVShift2Idx );
+  dstY += ( Pel )( ( ( ( deltaY * ( rCuboid.P[3].Y - rCuboid.P[2].Y ) ) << m_nUShift2Idx ) 
+                   + ( ( deltaU * ( rCuboid.P[1].Y - rCuboid.P[0].Y ) ) << m_nYShift2Idx )
+                   + ( ( deltaV * ( rCuboid.P[2].Y - rCuboid.P[1].Y ) ) << m_nYShift2Idx ) 
+                   + m_nMappingOffset ) >> m_nMappingShift );
+  return( dstY );
+}
+
+SYUVP TCom3DAsymLUT::xMapUV( Pel y , Pel u , Pel v )
+{
+  const SCuboid & rCuboid = m_pCuboid[y>>m_nYShift2Idx][u>>m_nUShift2Idx][v>>m_nVShift2Idx];
+  SYUVP dst = rCuboid.P[0];
+  Int deltaY = y - ( y >> m_nYShift2Idx << m_nYShift2Idx );
+  Int deltaU = u - ( u >> m_nUShift2Idx << m_nUShift2Idx );
+  Int deltaV = v - ( v >> m_nVShift2Idx << m_nVShift2Idx );
+  dst.U += ( Pel )( ( ( ( deltaY * ( rCuboid.P[3].U - rCuboid.P[2].U ) ) << m_nUShift2Idx ) 
+                    + ( ( deltaU * ( rCuboid.P[1].U - rCuboid.P[0].U ) ) << m_nYShift2Idx )
+                    + ( ( deltaV * ( rCuboid.P[2].U - rCuboid.P[1].U ) ) << m_nYShift2Idx ) 
+                    + m_nMappingOffset ) >> m_nMappingShift );
+  dst.V += ( Pel )( ( ( ( deltaY * ( rCuboid.P[3].V - rCuboid.P[2].V ) ) << m_nUShift2Idx ) 
+                    + ( ( deltaU * ( rCuboid.P[1].V - rCuboid.P[0].V ) ) << m_nYShift2Idx )
+                    + ( ( deltaV * ( rCuboid.P[2].V - rCuboid.P[1].V ) ) << m_nYShift2Idx ) 
+                    + m_nMappingOffset ) >> m_nMappingShift );
+  return( dst );
+}
+
+Void TCom3DAsymLUT::xSaveCuboids( SCuboid *** pSrcCuboid )
+{
+  memcpy( m_pCuboid[0][0] , pSrcCuboid[0][0] , sizeof( SCuboid ) * m_nYSize * m_nUSize * m_nVSize );
+}
+
+Void TCom3DAsymLUT::copy3DAsymLUT( TCom3DAsymLUT * pSrc )
+{
+  assert( pSrc->getMaxOctantDepth() == getMaxOctantDepth() && pSrc->getMaxYPartNumLog2() == getMaxYPartNumLog2() );
+  xUpdatePartitioning( pSrc->getCurOctantDepth() , pSrc->getCurYPartNumLog2() );
+  setResQuantBit( pSrc->getResQuantBit() );
+  xSaveCuboids( pSrc->m_pCuboid );
+}
+
+#endif
+
Index: trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h
===================================================================
--- trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h	(revision 713)
+++ trunk/source/Lib/TLibCommon/TCom3DAsymLUT.h	(revision 713)
@@ -0,0 +1,135 @@
+
+#ifndef __TCOM3DASYMLUT__
+#define __TCOM3DASYMLUT__
+
+#include "TypeDef.h"
+
+#if Q0048_CGS_3D_ASYMLUT
+
+typedef struct _SYUVP
+{
+  Pel   Y , U , V;
+}SYUVP;
+
+typedef struct _SCuboid // vertexes for tetrahedral interpolation
+{
+  SYUVP P[4];     // YUV: P0(0,0,0), P1(0,1,0), P3(0,1,1), P7(1,1,1)
+}SCuboid;
+
+class TComPicYuv;
+
+class TCom3DAsymLUT
+{
+public:
+  TCom3DAsymLUT();
+  virtual ~TCom3DAsymLUT();
+
+  virtual Void  create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 );
+  virtual Void  destroy();
+
+  Int   getMaxOctantDepth() { return m_nMaxOctantDepth; }
+  Int   getCurOctantDepth() { return m_nCurOctantDepth; }
+  Int   getInputBitDepthY()  { return m_nInputBitDepthY;  }
+  Int   getOutputBitDepthY()  { return m_nOutputBitDepthY;  }
+  Int   getInputBitDepthC()  { return m_nInputBitDepthC;  }
+  Int   getOutputBitDepthC()  { return m_nOutputBitDepthC;  }
+  Int   getResQuantBit()     { return m_nResQuanBit; }
+  Void  setResQuantBit(Int n){ m_nResQuanBit = n; }
+  Int   getMaxYPartNumLog2() { return m_nMaxYPartNumLog2; }
+  Int   getCurYPartNumLog2() { return m_nCurYPartNumLog2; }
+
+  Void  colorMapping( TComPicYuv * pcPicSrc,  TComPicYuv * pcPicDst );
+  Void  copy3DAsymLUT( TCom3DAsymLUT * pSrc );
+
+  SYUVP xGetCuboidVertexPredAll( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , SCuboid *** pCurCuboid=NULL );
+  SYUVP getCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx );
+  Void  setCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , Int deltaY , Int deltaU , Int deltaV );
+
+
+private:
+  Int   m_nMaxOctantDepth;
+  Int   m_nCurOctantDepth;
+  Int   m_nInputBitDepthY;
+  Int   m_nOutputBitDepthY;
+  Int   m_nInputBitDepthC;
+  Int   m_nOutputBitDepthC;
+  Int   m_nDeltaBitDepthC;
+  Int   m_nDeltaBitDepth;
+  Int   m_nMaxYPartNumLog2;
+  Int   m_nCurYPartNumLog2;
+  Int   m_nMaxPartNumLog2;
+  Int   m_nYSize;
+  Int   m_nUSize;
+  Int   m_nVSize;
+  Int   m_nYShift2Idx;
+  Int   m_nUShift2Idx;
+  Int   m_nVShift2Idx;
+  Int   m_nMappingShift;
+  Int   m_nMappingOffset;
+  Int   m_nResQuanBit;
+  SCuboid *** m_pCuboid;
+  const static Int m_nVertexIdxOffset[4][3];
+
+protected:
+  template <class T> 
+  Void xAllocate3DArray( T*** &p , Int xSize , Int ySize , Int zSize );
+  template <class T> 
+  Void xReset3DArray( T*** &p , Int xSize , Int ySize , Int zSize );
+  template <class T>
+  Void xFree3DArray( T *** &p );
+
+  Void  xUpdatePartitioning( Int nCurOctantDepth , Int nCurYPartNumLog2 );
+  SYUVP xGetCuboidVertexPredA( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx );
+  Pel   xMapY( Pel y , Pel u , Pel v );
+  SYUVP xMapUV( Pel y , Pel u , Pel v );
+  Int   xGetMaxPartNumLog2()  { return m_nMaxPartNumLog2; }
+  Int   xGetYSize()  { return m_nYSize;  }
+  Int   xGetUSize()  { return m_nUSize;  }
+  Int   xGetVSize()  { return m_nVSize;  }
+  Int   xGetYShift2Idx() { return m_nYShift2Idx; }
+  Int   xGetUShift2Idx() { return m_nUShift2Idx; }
+  Int   xGetVShift2Idx() { return m_nVShift2Idx; } 
+  SCuboid & xGetCuboid( Int yIdx , Int uIdx , Int vIdx ){ return m_pCuboid[yIdx][uIdx][vIdx];  }
+  Void  xSaveCuboids( SCuboid *** pSrcCuboid );
+};
+
+template <class T> 
+Void TCom3DAsymLUT::xAllocate3DArray( T *** &p , Int xSize , Int ySize , Int zSize )
+{
+  p = new T**[xSize];
+  p[0] = new T*[xSize*ySize];
+  for( Int x = 1 ; x < xSize ; x++ )
+    p[x] = p[x-1] + ySize;
+  p[0][0] = new T[xSize*ySize*zSize];
+  for( Int x = 0 ; x < xSize ; x++ )
+  {
+    for( Int y = 0 ; y < ySize ; y++ )
+      p[x][y] = p[0][0] + x * ySize * zSize + y * zSize;
+  }
+}
+
+template <class T>
+Void TCom3DAsymLUT::xFree3DArray( T *** &p )
+{
+  if( p != NULL )
+  {
+    if( p[0] != NULL )
+    {
+      if( p[0][0] != NULL )
+        delete [] p[0][0];
+      delete [] p[0];
+    }
+    delete [] p;
+    p = NULL;
+  }
+}
+
+template <class T>
+Void TCom3DAsymLUT::xReset3DArray( T*** &p , Int xSize , Int ySize , Int zSize )
+{
+  memset( p[0][0] , 0 , sizeof( T ) * xSize * ySize * zSize );
+}
+
+#endif
+
+#endif
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 713)
@@ -172,12 +172,18 @@
     memset( m_pcTrCoeffCb, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
     memset( m_pcTrCoeffCr, 0,uiWidth*uiHeight/4 * sizeof( TCoeff ) );
-#if ADAPTIVE_QP_SELECTION    
+#if ADAPTIVE_QP_SELECTION
     if( bGlobalRMARLBuffer )
     {
       if( m_pcGlbArlCoeffY == NULL )
       {
+#if LAYER_CTB
+        m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE);
+        m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE/4);
+        m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, MAX_CU_SIZE * MAX_CU_SIZE/4);
+#else
         m_pcGlbArlCoeffY   = (Int*)xMalloc(Int, uiWidth*uiHeight);
         m_pcGlbArlCoeffCb  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
         m_pcGlbArlCoeffCr  = (Int*)xMalloc(Int, uiWidth*uiHeight/4);
+#endif
       }
       m_pcArlCoeffY        = m_pcGlbArlCoeffY;
@@ -1690,68 +1696,4 @@
 }
 
-
-#if FAST_INTRA_SHVC
-/** generate limited set of remaining modes
-*\param   uiAbsPartIdx
-*\param   uiIntraDirPred  pointer to the array for MPM storage
-*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
-*/
-Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
-{
-  // check BL mode
-  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
-  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
-  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
-
-  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
-  {
-    return( NUM_INTRA_MODE-1 );
-  }
-
-  // compute set of enabled modes g_reducedSetIntraModes[...]
-  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
-  Int nbModes;
-  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
-  {
-    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
-    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
-  }
-
-  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
-  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
-  {
-    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
-    authorizedMode[ iColBaseDir ] = 0;
-  }
-
-  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
-  if ( iRefMode > 1 )    //add neighboring modes of refMode
-  {
-    UInt Left  = iRefMode;
-    UInt Right = iRefMode;
-    while ( nbModes < NB_REMAIN_MODES+3 )
-    {
-      Left = ((Left + 29) % 32) + 2;
-      Right = ((Right - 1 ) % 32) + 2;
-      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
-      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
-    }
-  }
-  else      //add pre-defined modes
-  {
-    Int  idx = 0;
-    while ( nbModes < NB_REMAIN_MODES+3 )
-    {
-      UInt mode = g_predefSetIntraModes[idx++];
-      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
-    }
-  }
-
-  fullSetOfModes = 0;
-  return ( nbModes );
-}
-#endif
-
-
 UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
 {
@@ -1809,67 +1751,4 @@
   return log2MinTUSizeInCU;
 }
-
-#if REF_IDX_ME_ZEROMV
-Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
-{
-  Bool checkZeroMVILR = true;
-
-  if(uhInterDir&0x1)  //list0
-  {
-    Int refIdxL0 = cMvFieldL0.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
-    {
-      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
-    }
-  }
-  if(uhInterDir&0x2)  //list1
-  {
-    Int refIdxL1  = cMvFieldL1.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
-    {
-      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
-    }
-  }
-
-  return checkZeroMVILR;
-}
-
-Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
-{
-  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
-  assert(eRefPicList == REF_PIC_LIST_1);
-
-  Bool checkZeroMVILR = true;
-
-  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
-  {
-    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
-    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
-    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
-  }
-
-  return checkZeroMVILR;
-}
-#endif
-
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
-{
-  Bool checkILR = false;
-
-  if(uhInterDir&0x1)  //list0
-  {
-    Int refIdxL0 = cMvFieldL0.getRefIdx();
-    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
-  }
-  if(uhInterDir&0x2)  //list1
-  {
-    Int refIdxL1  = cMvFieldL1.getRefIdx();
-    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
-  }
-
-  return checkILR;
-}
-#endif
 
 UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
@@ -2168,5 +2047,5 @@
 }
 
-UChar TComDataCU::getNumPartInter()
+UChar TComDataCU::getNumPartitions()
 {
   UChar iNumPart = 0;
@@ -3612,5 +3491,5 @@
 TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping )
 {
-  TComPic* cBaseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
+  TComPic* baseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
 
   uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
@@ -3622,23 +3501,30 @@
 
 #if O0098_SCALED_REF_LAYER_ID
-  Int leftStartL = getSlice()->getSPS()->getScaledRefLayerWindowForLayer(getSlice()->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
-  Int topStartL  = getSlice()->getSPS()->getScaledRefLayerWindowForLayer(getSlice()->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowTopOffset();
+  Int leftStartL = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
+  Int topStartL  = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowTopOffset();
 #else
-  Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
-  Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
-#endif
+  Int leftStartL = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
+  Int topStartL  = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
+#endif
+
+#if Q0200_CONFORMANCE_BL_SIZE
+  Int chromaFormatIdc = baseColPic->getSlice(0)->getChromaFormatIdc();
+  Int iBX = (((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16) + baseColPic->getConformanceWindow().getWindowLeftOffset() * TComSPS::getWinUnitX( chromaFormatIdc );
+  Int iBY = (((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16) + baseColPic->getConformanceWindow().getWindowTopOffset() * TComSPS::getWinUnitY( chromaFormatIdc );
+#else
   Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
   Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
+#endif
 
 #if N0139_POSITION_ROUNDING_OFFSET
   if( iMotionMapping == 1 )
   {
-    iBX += 4;
-    iBY += 4;
-  }
-#endif
-
-  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
-       iBX < 0                                        || iBY < 0                                           )
+    // actually, motion field compression is performed in the Void TComPic::compressMotion() function, but with (+4) the rounding may have effect on the picture boundary check.
+    iBX = ( ( iBX + 4 ) >> 4 ) << 4;
+    iBY = ( ( iBY + 4 ) >> 4 ) << 4;
+  }
+#endif
+
+  if ( iBX < 0 || iBX >= baseColPic->getPicYuvRec()->getWidth() || iBY < 0 || iBY >= baseColPic->getPicYuvRec()->getHeight() )
   {
     return NULL;
@@ -3646,21 +3532,21 @@
 
 #if LAYER_CTB
-  UInt baseMaxCUHeight = cBaseColPic->getPicSym()->getMaxCUHeight();
-  UInt baseMaxCUWidth  = cBaseColPic->getPicSym()->getMaxCUWidth();
-  UInt baseMinUnitSize = cBaseColPic->getMinCUWidth();
-  
-  uiCUAddrBase = ( iBY / cBaseColPic->getPicSym()->getMaxCUHeight() ) * cBaseColPic->getFrameWidthInCU() + ( iBX / cBaseColPic->getPicSym()->getMaxCUWidth() );
+  UInt baseMaxCUHeight = baseColPic->getPicSym()->getMaxCUHeight();
+  UInt baseMaxCUWidth  = baseColPic->getPicSym()->getMaxCUWidth();
+  UInt baseMinUnitSize = baseColPic->getMinCUWidth();
+  
+  uiCUAddrBase = ( iBY / baseMaxCUHeight ) * baseColPic->getFrameWidthInCU() + ( iBX / baseMaxCUWidth );
 #else
-  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
-#endif
-
-  assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
+  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*baseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
+#endif
+
+  assert(uiCUAddrBase < baseColPic->getNumCUsInFrame());
 
 #if LAYER_CTB
-  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * cBaseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
-  
-  uiAbsPartIdxBase = g_auiLayerRasterToZscan[cBaseColPic->getLayerId()][uiRasterAddrBase];
+  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * baseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
+  
+  uiAbsPartIdxBase = g_auiLayerRasterToZscan[baseColPic->getLayerId()][uiRasterAddrBase];
 #else
-  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
+  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*baseColPic->getNumPartInWidth()
     + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
 
@@ -3668,5 +3554,5 @@
 #endif
 
-  return cBaseColPic->getCU(uiCUAddrBase);
+  return baseColPic->getCU(uiCUAddrBase);
 }
 
@@ -3680,4 +3566,130 @@
   rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
 }
+
+#if FAST_INTRA_SHVC
+/** generate limited set of remaining modes
+*\param   uiAbsPartIdx
+*\param   uiIntraDirPred  pointer to the array for MPM storage
+*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
+*/
+Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
+{
+  // check BL mode
+  UInt          uiCUAddrBase = 0, uiAbsPartAddrBase = 0;
+  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
+  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase, 0 );
+
+  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
+  {
+    return( NUM_INTRA_MODE-1 );
+  }
+
+  // compute set of enabled modes g_reducedSetIntraModes[...]
+  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+  Int nbModes;
+  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
+  {
+    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
+    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
+  }
+
+  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
+  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
+  {
+    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
+    authorizedMode[ iColBaseDir ] = 0;
+  }
+
+  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
+  if ( iRefMode > 1 )    //add neighboring modes of refMode
+  {
+    UInt Left  = iRefMode;
+    UInt Right = iRefMode;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      Left = ((Left + 29) % 32) + 2;
+      Right = ((Right - 1 ) % 32) + 2;
+      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
+      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
+    }
+  }
+  else      //add pre-defined modes
+  {
+    Int  idx = 0;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      UInt mode = g_predefSetIntraModes[idx++];
+      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
+    }
+  }
+
+  fullSetOfModes = 0;
+  return ( nbModes );
+}
+#endif
+
+#if REF_IDX_ME_ZEROMV
+Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkZeroMVILR = true;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
+    {
+      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
+    }
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
+    {
+      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
+    }
+  }
+
+  return checkZeroMVILR;
+}
+
+Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
+{
+  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
+  assert(eRefPicList == REF_PIC_LIST_1);
+
+  Bool checkZeroMVILR = true;
+
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
+  {
+    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
+    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
+    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+#endif
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkILR = false;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
+  }
+
+  return checkILR;
+}
+#endif
+
 #endif //SVC_EXTENSION
 //! \}
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 713)
@@ -352,5 +352,5 @@
   
   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
-  UChar         getNumPartInter       ();
+  UChar         getNumPartitions       ();
   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
   
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 713)
@@ -141,9 +141,4 @@
   Void    setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
 
-#if AVC_SYNTAX
-  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
-  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
-#endif
-
   Void setNumPartition( Int iNumPart )
   {
@@ -159,4 +154,9 @@
   
   Void compress(Char* pePredMode, Int scale); 
+
+#if AVC_SYNTAX
+  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
+  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
+#endif
 
 #if REF_IDX_MFM
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 713)
@@ -89,4 +89,7 @@
   TComPicYuv*           m_pcFullPelBaseRec[MAX_LAYERS];    // upsampled base layer recontruction for difference domain inter prediction
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int                   m_nFrameBit;
+#endif
 
 public:
@@ -115,4 +118,5 @@
   UInt          getTLayer()                { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
+
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
   Void          setUsedByCurr( Bool bUsed ) { m_bUsedByCurr = bUsed; }
@@ -219,4 +223,8 @@
 #endif
 
+#if Q0048_CGS_3D_ASYMLUT
+  Void  setFrameBit( Int n )  { m_nFrameBit = n;    }
+  Int   getFrameBit()         { return m_nFrameBit; }
+#endif
 };// END CLASS DEFINITION TComPic
 
Index: trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 713)
@@ -174,6 +174,11 @@
   Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0);
   
+#if LAYER_CTB
+  m_iLumaMarginX    = uiMaxCUWidth  + 16; // for 16-byte alignment
+  m_iLumaMarginY    = uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
+#else
   m_iLumaMarginX    = g_uiMaxCUWidth  + 16; // for 16-byte alignment
   m_iLumaMarginY    = g_uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
+#endif
   
   m_apiPicBufY      = (Pel*)xMalloc( Pel, ( m_iPicWidth       + (m_iLumaMarginX  <<1)) * ( m_iPicHeight       + (m_iLumaMarginY  <<1)));
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 713)
@@ -447,5 +447,5 @@
   }
 
-  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ )
+  for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ )
   {
     pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
@@ -768,7 +768,7 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag )
-{
-  m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
+Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag )
+{
+  m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, phaseAlignFlag );
 }
 #else
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 713)
@@ -121,5 +121,5 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag );
 #else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 713)
@@ -112,6 +112,7 @@
     m_offsetClipTable[compIdx] = NULL;
   }
+#if !SAO_SGN_FUNC
   m_signTable = NULL; 
-
+#endif
   
   m_lineBufWidth = 0;
@@ -169,5 +170,8 @@
   }
 
+#if !SAO_SGN_FUNC
   //look-up table for clipping
+  Int overallMaxSampleValue=0;
+#endif
   for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
   {
@@ -179,4 +183,7 @@
     Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 
 #endif
+#if !SAO_SGN_FUNC
+    if (maxSampleValue>overallMaxSampleValue) overallMaxSampleValue=maxSampleValue;
+#endif
 
     m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
@@ -194,18 +201,17 @@
       *(offsetClipPtr -k -1 )              = 0;
     }
-    if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC
-    {
-      m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ];
-      m_sign = &(m_signTable[maxSampleValue-1]);
-
-      m_sign[0] = 0;
-      for(Int k=1; k< maxSampleValue; k++)
-      {
-        m_sign[k] = 1;
-        m_sign[-k]= -1;
-      }
-    }
-  }  
-
+  }
+
+#if !SAO_SGN_FUNC
+  m_signTable = new Short[ 2*(overallMaxSampleValue-1) + 1 ];
+  m_sign = &(m_signTable[overallMaxSampleValue-1]);
+
+  m_sign[0] = 0;
+  for(Int k=1; k< overallMaxSampleValue; k++)
+  {
+    m_sign[k] = 1;
+    m_sign[-k]= -1;
+  }
+#endif
 }
 
@@ -226,8 +232,10 @@
     }
   }
+#if !SAO_SGN_FUNC
   if( m_signTable )
   {
     delete[] m_signTable; m_signTable = NULL;
   }
+#endif
 }
 
@@ -406,8 +414,16 @@
       for (y=0; y< height; y++)
       {
+#if SAO_SGN_FUNC
+        signLeft = (Char)sgn(srcLine[startX] - srcLine[startX-1]);
+#else
         signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
+#endif
         for (x=startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signRight = (Char)sgn(srcLine[x] - srcLine[x+1]); 
+#else
           signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 
+#endif
           edgeType =  signRight + signLeft;
           signLeft  = -signRight;
@@ -437,5 +453,9 @@
       for (x=0; x< width; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLine[x] - srcLineAbove[x]);
+#else
         signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
+#endif
       }
 
@@ -447,5 +467,9 @@
         for (x=0; x< width; x++)
         {
+#if SAO_SGN_FUNC
+          signDown  = (Char)sgn(srcLine[x] - srcLineBelow[x]);
+#else
           signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 
+#endif
           edgeType = signDown + signUpLine[x];
           signUpLine[x]= -signDown;
@@ -474,5 +498,9 @@
       for (x=startX; x< endX+1; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x- 1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
+#endif
       }
 
@@ -483,5 +511,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType  =  sgn(srcLine[x] - srcLineAbove[x- 1]) - signUpLine[x+1];
+#else
         edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -497,5 +529,9 @@
         for (x=startX; x<endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x+ 1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
@@ -503,5 +539,9 @@
           signDownLine[x+1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signDownLine[startX] = (Char)sgn(srcLineBelow[startX] - srcLine[startX-1]);
+#else
         signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
+#endif
 
         signTmpLine  = signUpLine;
@@ -519,5 +559,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType =  sgn(srcLine[x] - srcLineBelow[x+ 1]) + signUpLine[x];
+#else
         edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
@@ -537,5 +581,9 @@
       for (x=startX-1; x< endX; x++)
       {
+#if SAO_SGN_FUNC
+        signUpLine[x] = (Char)sgn(srcLineBelow[x] - srcLine[x+1]);
+#else
         signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
+#endif
       }
 
@@ -547,5 +595,9 @@
       for(x= firstLineStartX; x< firstLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineAbove[x+1]) -signUpLine[x-1];
+#else
         edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
       }
@@ -560,10 +612,18 @@
         for(x= startX; x< endX; x++)
         {
+#if SAO_SGN_FUNC
+          signDown =  (Char)sgn(srcLine[x] - srcLineBelow[x-1]);
+#else
           signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
+#endif
           edgeType =  signDown + signUpLine[x];
           resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
           signUpLine[x-1] = -signDown; 
         }
+#if SAO_SGN_FUNC
+        signUpLine[endX-1] = (Char)sgn(srcLineBelow[endX-1] - srcLine[endX]);
+#else
         signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
+#endif
         srcLine  += srcStride;
         resLine += resStride;
@@ -576,5 +636,9 @@
       for(x= lastLineStartX; x< lastLineEndX; x++)
       {
+#if SAO_SGN_FUNC
+        edgeType = sgn(srcLine[x] - srcLineBelow[x-1]) + signUpLine[x];
+#else
         edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
+#endif
         resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
 
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 713)
@@ -56,4 +56,10 @@
 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
 #endif
+#if SAO_SGN_FUNC
+template <typename T> int sgn(T val) 
+{
+  return (T(0) < val) - (val < T(0));
+}
+#endif
 
 class TComSampleAdaptiveOffset
@@ -88,5 +94,7 @@
   UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step  
   Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation
+#if !SAO_SGN_FUNC
   Short* m_sign; //sign table for fast operation
+#endif
   TComPicYuv*   m_tempPicYuv; //temporary buffer
   Int m_picWidth;
@@ -105,5 +113,7 @@
   Bool m_picSAOEnabled[NUM_SAO_COMPONENTS];
   Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
+#if !SAO_SGN_FUNC
   Short* m_signTable;
+#endif
 #if SVC_EXTENSION
   UInt m_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 713)
@@ -75,4 +75,9 @@
 , m_pcPic                         ( NULL )
 , m_colFromL0Flag                 ( 1 )
+#if SETTING_NO_OUT_PIC_PRIOR
+, m_noOutputPriorPicsFlag         ( false )
+, m_noRaslOutputFlag              ( false )
+, m_handleCraAsBlaFlag            ( false )
+#endif
 , m_colRefIdx                     ( 0 )
 , m_uiTLayer                      ( 0 )
@@ -111,9 +116,4 @@
 , m_bCrossLayerBLAFlag            ( false )
 #endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-, m_noOutputOfPriorPicsFlag       ( false )
-, m_noRaslOutputFlag              ( false )
-, m_handleCraAsBlaFlag            ( false )
-#endif
 #if POC_RESET_IDC_SIGNALLING
 , m_pocResetIdc                   ( 0 )
@@ -536,7 +536,8 @@
       {
         UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+        UInt refLayerId = m_pcVPS->getRefLayerId( m_layerId, refLayerIdc );
 #if RESAMPLING_CONSTRAINT_BUG_FIX
 #if O0098_SCALED_REF_LAYER_ID
-        const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_pcVPS->getRefLayerId( m_layerId, m_interLayerPredLayerIdc[i] ));
+        const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
 #else
         const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
@@ -548,8 +549,18 @@
                             );
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        Int sameBitDepth = g_bitDepthYLayer[m_layerId] - g_bitDepthYLayer[refLayerId] + g_bitDepthCLayer[m_layerId] - g_bitDepthCLayer[refLayerId];
+
+        if( !( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || !scalingOffset || !sameBitDepth 
+#if Q0048_CGS_3D_ASYMLUT
+          || getPPS()->getCGSFlag()
+#endif
+          ) // ratio 1x
+#else
         if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || (!scalingOffset)) // ratio 1x
+#endif
         {
 #if MOTION_RESAMPLING_CONSTRAINT
-          UInt predType = m_pcVPS->getDirectDependencyType( m_layerId, m_pcVPS->getRefLayerId( m_layerId, refLayerIdc ) ) + 1;
+          UInt predType = m_pcVPS->getDirectDependencyType( m_layerId, refLayerId ) + 1;
 
           if( predType & 0x1 )
@@ -596,10 +607,10 @@
     // 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:
 #if SVC_EXTENSION    // inter-layer prediction is allowed for BLA, CRA pictures of nuh_layer_id>0
-    // – If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, 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 the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, 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() && getLayerId()==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 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
@@ -1008,4 +1019,49 @@
  */
 #if NO_CLRAS_OUTPUT_FLAG
+Void TComSlice::decodingRefreshMarking( TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag )
+{
+  if( !isIRAP() )
+  {
+    return;
+  }
+
+  Int pocCurr = getPOC();
+  TComPic* rpcPic = NULL;
+
+  // When the current picture is an IRAP picture with nuh_layer_id equal to 0 and NoClrasOutputFlag is equal to 1, 
+  // all reference pictures with any value of nuh_layer_id currently in the DPB (if any) are marked as "unused for reference".
+  if( m_layerId == 0 && noClrasOutputFlag )
+  {
+    // mark all pictures for all layers as not used for reference
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while( iterPic != rcListPic.end() )
+    {
+      rpcPic = *(iterPic);
+      if( rpcPic->getPOC() != pocCurr )
+      {
+        rpcPic->getSlice(0)->setReferenced(false);
+      }
+      iterPic++;
+    }
+  }
+
+  // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1, 
+  // all reference pictures with nuh_layer_id equal to currPicLayerId currently in the DPB (if any) are marked as "unused for reference".
+  if( m_noRaslOutputFlag )
+  {
+    // mark all pictures of a current layer as not used for reference
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while( iterPic != rcListPic.end() )
+    {
+      rpcPic = *(iterPic);
+      if( rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId )
+      {
+        rpcPic->getSlice(0)->setReferenced(false);
+      }
+      iterPic++;
+    }
+  }
+}
+
 Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag)
 #else
@@ -1051,7 +1107,31 @@
       pocCRA = pocCurr;
     }
+#if EFFICIENT_FIELD_IRAP
+    bRefreshPending = true;
+#endif
   }
   else // CRA or No DR
   {
+#if EFFICIENT_FIELD_IRAP
+    if(getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
+    {
+      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending 
+      {
+        TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
+        while (iterPic != rcListPic.end())
+        {
+          rpcPic = *(iterPic);
+          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != m_iLastIDR)
+          {
+            rpcPic->getSlice(0)->setReferenced(false);
+          }
+          iterPic++;
+        }
+        bRefreshPending = false; 
+      }
+    }
+    else
+    {
+#endif
     if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending 
     {
@@ -1068,4 +1148,7 @@
       bRefreshPending = false; 
     }
+#if EFFICIENT_FIELD_IRAP
+    }
+#endif
     if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
     {
@@ -1323,5 +1406,9 @@
     // in decoding order shall precede the IRAP picture in output order.
     // (Note that any picture following in output order would be present in the DPB)
+#if !SETTING_NO_OUT_PIC_PRIOR
     if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
+#else
+    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
+#endif
     {
       if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
@@ -1502,6 +1589,14 @@
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
-{
+#endif
+{
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int atLeastOneUnabledByRecoveryPoint = 0;
+  Int atLeastOneFlushedByPreviousIDR = 0;
+#endif
   TComPic* rpcPic;
   Int i, isAvailable;
@@ -1524,5 +1619,16 @@
         if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1534,5 +1640,16 @@
         if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
+        }
+#else
+          isAvailable = 1;
+#endif
         }
       }
@@ -1557,7 +1674,20 @@
         if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
         {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+          {
+            isAvailable = 0;
+          }
+          else
+          {
           isAvailable = 1;
           rpcPic->setIsLongTerm(1);
           break;
+        }
+#else
+          isAvailable = 1;
+          rpcPic->setIsLongTerm(1);
+          break;
+#endif
         }
       }
@@ -1587,4 +1717,14 @@
         }
       }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
     }
   }  
@@ -1602,5 +1742,16 @@
       if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
       {
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
+        {
+          isAvailable = 0;
+        }
+        else
+        {
         isAvailable = 1;
+      }
+#else
+        isAvailable = 1;
+#endif
       }
     }
@@ -1629,6 +1780,22 @@
         }
       }
-    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
+      {
+        atLeastOneUnabledByRecoveryPoint = 1;
+      }
+      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
+      {
+        atLeastOneFlushedByPreviousIDR = 1;
+      }
+#endif
+    }
+    }
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
+  {
+    return -1;
   }    
+#endif
   if(atLeastOneLost)
   {
@@ -1647,5 +1814,9 @@
 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
 */
+#if ALLOW_RECOVERY_POINT_AS_RAP
+Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint)
+#else
 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
+#endif
 {
   TComPic* rpcPic;
@@ -1673,4 +1844,7 @@
         pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
+#if ALLOW_RECOVERY_POINT_AS_RAP
+        pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) ); 
+#endif
         if(pcRPS->getDeltaPOC(k) < 0)
         {
@@ -1685,4 +1859,24 @@
     }
   }
+#if EFFICIENT_FIELD_IRAP
+  Bool useNewRPS = false;
+  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS. 
+  if(m_pcPic->isField())
+  {
+    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
+    while ( iterPic != rcListPic.end())
+    {
+      rpcPic = *(iterPic++);
+      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
+      {
+        pcRPS->setDeltaPOC(k, 1);
+        pcRPS->setUsed(k, true);
+        nrOfPositivePictures++;
+        k ++;
+        useNewRPS = true;
+      }
+    }
+  }
+#endif
   pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
   pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
@@ -1691,5 +1885,9 @@
   // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
   // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
-  if (!pReferencePictureSet->getInterRPSPrediction())
+  if (!pReferencePictureSet->getInterRPSPrediction()
+#if EFFICIENT_FIELD_IRAP
+    || useNewRPS
+#endif
+    )
   {
     pcRPS->setInterRPSPrediction(false);
@@ -1888,5 +2086,12 @@
   if( layerId == 0 )
   {
-    retVal = sps->getChromaFormatIdc();
+    if( vps->getAvcBaseLayerFlag() )
+    {
+      retVal = vps->getVpsRepFormat(layerId)->getChromaFormatVpsIdc();
+    }
+    else
+    {
+      retVal = sps->getChromaFormatIdc();
+    }
   }
   else
@@ -2034,5 +2239,9 @@
 #endif
 #if REPN_FORMAT_IN_VPS
+#if Q0195_REP_FORMAT_CLEANUP
+, m_repFormatIdxPresentFlag   (false)
+#else
 , m_repFormatIdxPresentFlag   (true)
+#endif
 , m_vpsNumRepFormats          (1)
 #endif
@@ -2306,11 +2515,11 @@
 Void TComVPS::setRefLayersFlags(Int currLayerId)
 {
-  for (Int i = 0; i < getNumDirectRefLayers(currLayerId); i++)
+  for (Int i = 0; i < m_numDirectRefLayers[currLayerId]; i++)
   {
     UInt refLayerId = getRefLayerId(currLayerId, i);
-    setRecursiveRefLayerFlag(currLayerId, refLayerId, true);
+    m_recursiveRefLayerFlag[currLayerId][refLayerId] = true;
     for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++)
     {
-      setRecursiveRefLayerFlag(currLayerId, k, (getRecursiveRefLayerFlag(currLayerId, k) | getRecursiveRefLayerFlag(refLayerId, k)));
+      m_recursiveRefLayerFlag[currLayerId][k] = m_recursiveRefLayerFlag[currLayerId][k] | m_recursiveRefLayerFlag[refLayerId][k];
     }
   }
@@ -2319,11 +2528,11 @@
 Void TComVPS::setNumRefLayers(Int currLayerId)
 {
-  for (Int i = 0; i <= getMaxLayers(); i++)
-  {
-    UInt iNuhLId = getLayerIdInNuh(i);
+  for (Int i = 0; i < m_uiMaxLayers; i++)
+  {
+    UInt iNuhLId = m_layerIdInNuh[i];
     setRefLayersFlags(iNuhLId);
     for (UInt j = 0; j < MAX_NUM_LAYER_IDS; j++)
     {
-      m_numberRefLayers[iNuhLId] += (getRecursiveRefLayerFlag(iNuhLId, j) == true ? 1 : 0);
+      m_numberRefLayers[iNuhLId] += (m_recursiveRefLayerFlag[iNuhLId][j] == true ? 1 : 0);
     }
   }
@@ -3526,4 +3735,5 @@
 
     TComPic* pcRefPicBL = pcRefPicRL[refLayerIdc];
+
     //set reference picture POC of each ILP reference 
     Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
@@ -3532,6 +3742,12 @@
     ilpPic[refLayerIdc]->getSlice(0)->setBaseColPic( refLayerIdc, pcRefPicBL );
 
-    //copy reference pictures marking from the reference layer
-    ilpPic[refLayerIdc]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
+    //copy layer id from the reference layer    
+    ilpPic[refLayerIdc]->setLayerId( pcRefPicBL->getLayerId() );
+
+    //copy slice type from the reference layer
+    ilpPic[refLayerIdc]->getSlice(0)->setSliceType( pcRefPicBL->getSlice(0)->getSliceType() );
+
+    //copy "used for reference"
+    ilpPic[refLayerIdc]->getSlice(0)->setReferenced( pcRefPicBL->getSlice(0)->isReferenced() );
 
     for( Int refList = 0; refList < 2; refList++ )
@@ -3555,4 +3771,10 @@
         ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
         ilpPic[refLayerIdc]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
+      }
+
+      //copy reference pictures' marking from the reference layer
+      for(Int j = 0; j < MAX_NUM_REF + 1; j++)
+      {
+        ilpPic[refLayerIdc]->getSlice(0)->setIsUsedAsLongTerm(refList, j, pcRefPicBL->getSlice(0)->getIsUsedAsLongTerm(refList, j));
       }
     }
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 713)
@@ -231,5 +231,5 @@
 {
   ProfileTierLevel m_generalPTL;
-  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 ( = 6 )
+  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 (= 6)
   Bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
   Bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
@@ -581,5 +581,5 @@
 #if VPS_TSLAYERS
   Bool       m_maxTSLayersPresentFlag;
-  UInt       m_maxTSLayerMinus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
+  UInt       m_maxTSLayerMinus1[MAX_LAYERS];
 #endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -684,4 +684,5 @@
   Bool       m_vpsVuiPresentFlag;
 #endif
+  Bool       m_vpsExtensionFlag;
 
 #if O0164_MULTI_LAYER_HRD
@@ -1131,7 +1132,9 @@
 
 #if O0109_MOVE_VPS_VUI_FLAG
-  Bool   getVpsVuiPresentFlag()                                 { return m_vpsVuiPresentFlag; }
-  Void   setVpsVuiPresentFlag(Bool x)                           { m_vpsVuiPresentFlag = x; }
-#endif
+  Bool   getVpsVuiPresentFlag()                        { return m_vpsVuiPresentFlag; }
+  Void   setVpsVuiPresentFlag(Bool x)                  { m_vpsVuiPresentFlag = x;    }
+#endif
+  Bool   getVpsExtensionFlag()                         { return m_vpsExtensionFlag;  }
+  Void   setVpsExtensionFlag(Bool x)                   { m_vpsExtensionFlag = x;     }
 
 #if !P0307_REMOVE_VPS_VUI_OFFSET
@@ -1741,4 +1744,9 @@
   Bool     m_pocResetInfoPresentFlag;
 #endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int      m_nCGSFlag;
+  Int      m_nCGSOutputBitDepthY; // not for syntax
+  Int      m_nCGSOutputBitDepthC; // not for syntax
+#endif
 #endif
 
@@ -1881,4 +1889,12 @@
   Bool getPocResetInfoPresentFlag   ()                    { return m_pocResetInfoPresentFlag; }
   Void setPocResetInfoPresentFlag   (const Bool val)      { m_pocResetInfoPresentFlag = val; }
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int     getCGSFlag()                { return m_nCGSFlag;  }
+  Void    setCGSFlag(Int n)           { m_nCGSFlag = n;     }
+  Int     getCGSOutputBitDepthY()     { return m_nCGSOutputBitDepthY;  }
+  Void    setCGSOutputBitDepthY(Int n){ m_nCGSOutputBitDepthY = n;     }
+  Int     getCGSOutputBitDepthC()     { return m_nCGSOutputBitDepthC;  }
+  Void    setCGSOutputBitDepthC(Int n){ m_nCGSOutputBitDepthC = n;     }
 #endif
 };
@@ -1963,4 +1979,10 @@
   UInt        m_colFromL0Flag;  // collocated picture from List0 flag
   
+#if SETTING_NO_OUT_PIC_PRIOR
+  Bool        m_noOutputPriorPicsFlag;
+  Bool        m_noRaslOutputFlag;
+  Bool        m_handleCraAsBlaFlag;
+#endif
+  
   UInt        m_colRefIdx;
   UInt        m_maxNumMergeCand;
@@ -2030,9 +2052,4 @@
   Bool        m_bCrossLayerBLAFlag;
 #endif
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Bool        m_noOutputOfPriorPicsFlag;
-  Bool        m_noRaslOutputFlag;
-  Bool        m_handleCraAsBlaFlag;
-#endif
 #if POC_RESET_IDC_SIGNALLING
   Int         m_pocResetIdc;
@@ -2043,4 +2060,7 @@
   Bool        m_pocMsbValRequiredFlag;
   Bool        m_pocMsbValPresentFlag;
+#endif
+#if Q0048_CGS_3D_ASYMLUT
+  Int        m_nCGSOverWritePPS;  // for optimization, not output to bitstream
 #endif
 #endif //SVC_EXTENSION
@@ -2130,12 +2150,9 @@
   NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
   Bool      getRapPicFlag       ();  
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Bool      getBlaPicFlag       ();
-  Bool      getCraPicFlag       ();
-#endif
   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, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
 #if NO_CLRAS_OUTPUT_FLAG
+  Void      decodingRefreshMarking( TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag );
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag);
 #else
@@ -2163,4 +2180,8 @@
 #if SVC_EXTENSION
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false, TComPic** ilpPic = NULL );
+#if Q0048_CGS_3D_ASYMLUT
+  Int       getCGSOverWritePPS()              { return m_nCGSOverWritePPS;    }
+  Void      setCGSOverWritePPS(Int n)         { m_nCGSOverWritePPS = n;       }
+#endif
 #else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
@@ -2203,9 +2224,25 @@
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
-  Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
-  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  Int  checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+  Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess = 0, Bool bUseRecoveryPoint = false);
+#else
+  Int  checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
+  Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#endif
 
   Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
   UInt getMaxNumMergeCand               ()                  { return m_maxNumMergeCand;                   }
+
+#if SETTING_NO_OUT_PIC_PRIOR
+  Void setNoOutputPriorPicsFlag         ( Bool val )        { m_noOutputPriorPicsFlag = val;                    }
+  Bool getNoOutputPriorPicsFlag         ()                  { return m_noOutputPriorPicsFlag;                   }
+
+  Void setNoRaslOutputFlag              ( Bool val )        { m_noRaslOutputFlag = val;                    }
+  Bool getNoRaslOutputFlag              ()                  { return m_noRaslOutputFlag;                   }
+
+  Void setHandleCraAsBlaFlag            ( Bool val )        { m_handleCraAsBlaFlag = val;                    }
+  Bool getHandleCraAsBlaFlag            ()                  { return m_handleCraAsBlaFlag;                   }
+#endif
 
   Void setSliceMode                     ( UInt uiMode )     { m_sliceMode = uiMode;                     }
@@ -2360,15 +2397,4 @@
 
   Void setILRPic(TComPic **pcIlpPic);
-#if NO_OUTPUT_OF_PRIOR_PICS
-  Void setNoOutputOfPriorPicsFlag(const Bool x)   { m_noOutputOfPriorPicsFlag = x;    }
-  Bool getNoOutputOfPriorPicsFlag()               { return m_noOutputOfPriorPicsFlag; }
-
-  Void setNoRaslOutputFlag    ( const Bool val )   { m_noRaslOutputFlag = val;  }
-  Bool getNoRaslOutputFlag    ()                   { return m_noRaslOutputFlag; }
-
-  Void setHandleCraAsBlaFlag  ( const Bool val )   { m_handleCraAsBlaFlag = val;  }
-  Bool getHandleCraAsBlaFlag  ()                   { return m_handleCraAsBlaFlag; }
-
-#endif
 #if POC_RESET_IDC_SIGNALLING
   Int       getPocResetIdc       ()                              { return m_pocResetIdc;       }
@@ -2388,4 +2414,9 @@
 #endif
 
+#if NO_OUTPUT_OF_PRIOR_PICS
+  Bool      getBlaPicFlag       ();
+  Bool      getCraPicFlag       ();
+#endif
+
 #endif //SVC_EXTENSION
 protected:
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 713)
@@ -99,7 +99,7 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
-#else
-Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag )
+#else
+Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag )
 #endif
 #else
@@ -116,7 +116,16 @@
   Int i, j;
 
+#if O0194_JOINT_US_BITSHIFT
+  UInt currLayerId = currSlice->getLayerId();
+  UInt refLayerId  = currSlice->getVPS()->getRefLayerId( currLayerId, refLayerIdc );
+#endif
+
+#if O0098_SCALED_REF_LAYER_ID
+  const Window &scalEL = currSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
+#else
+  const Window &scalEL = currSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
+#endif
+
   //========== Y component upsampling ===========
-  const Window &scalEL = window;
-
   Int widthBL   = pcBasePic->getWidth ();
   Int heightBL  = pcBasePic->getHeight();
@@ -127,4 +136,10 @@
   Int strideEL  = pcUsPic->getStride();
 
+#if Q0200_CONFORMANCE_BL_SIZE
+  Int chromaFormatIdc = currSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
+  const Window &confBL = currSlice->getBaseColPic(refLayerIdc)->getConformanceWindow();
+  Int xScal = TComSPS::getWinUnitX( chromaFormatIdc );
+  Int yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
 #if P0312_VERT_PHASE_ADJ
   Bool vertPhasePositionEnableFlag = scalEL.getVertPhasePositionEnableFlag();
@@ -159,9 +174,4 @@
   Int scaleY = g_posScalingFactor[refLayerIdc][1];
 
-#if O0194_JOINT_US_BITSHIFT
-  UInt currLayerId = currSlice->getLayerId();
-  UInt refLayerId  = currSlice->getVPS()->getRefLayerId( currLayerId, refLayerIdc );
-#endif
-
   // non-normative software optimization for certain simple resampling cases
   if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
@@ -172,4 +182,11 @@
 #if O0194_JOINT_US_BITSHIFT
     Int shift = g_bitDepthYLayer[currLayerId] - g_bitDepthYLayer[refLayerId];
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift = g_bitDepthYLayer[currLayerId] - currSlice->getPPS()->getCGSOutputBitDepthY();
+    }
+    assert( shift >= 0 );
+#endif
 #endif
 
@@ -205,4 +222,10 @@
 #if O0194_JOINT_US_BITSHIFT
     shift = g_bitDepthCLayer[currLayerId] - g_bitDepthCLayer[refLayerId];
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift = g_bitDepthCLayer[currLayerId] - currSlice->getPPS()->getCGSOutputBitDepthC();
+    }
+#endif
 #endif
 
@@ -254,5 +277,9 @@
     Int   phaseX = 2*phaseAlignFlag;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int   phaseY = 2*phaseAlignFlag;
+#else
     Int   phaseY = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( 2 * phaseAlignFlag );
+#endif
 #else
     Int   phaseY = 2*phaseAlignFlag;
@@ -261,29 +288,43 @@
     Int   phaseX = 0;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int   phaseY = 0;
+#else
     Int   phaseY = (vertPhasePositionEnableFlag?(vertPhasePositionFlag *4):(0));
+#endif
 #else
     Int   phaseY = 0;
 #endif
 #endif
-
+ 
 #if ROUNDING_OFFSET
     Int   addX = ( ( phaseX * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
     Int   addY = ( ( phaseY * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
 #else
-    Int   addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    Int   addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
-
-    Int   deltaX     = 4 * phaseX;
-    Int   deltaY     = 4 * phaseY;
+    Int   addX = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    Int   addY = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+#endif
+
+#if Q0120_PHASE_CALCULATION
+    Int   deltaX = (Int)phaseAlignFlag <<3;
+    Int   deltaY = (((Int)phaseAlignFlag <<3)>>(Int)vertPhasePositionEnableFlag) + ((Int)vertPhasePositionFlag<<3);
+#else
+    Int   deltaX = 4 * phaseX;
+    Int   deltaY = 4 * phaseY;
+#endif
+
+#if Q0200_CONFORMANCE_BL_SIZE
+    deltaX -= ( confBL.getWindowLeftOffset() * xScal ) << 4;
+    deltaY -= ( confBL.getWindowTopOffset() * yScal ) << 4;
+#endif
 
     Int shiftXM4 = shiftX - 4;
     Int shiftYM4 = shiftY - 4;
 
-    widthEL   = pcUsPic->getWidth ();
-    heightEL  = pcUsPic->getHeight();
-
-    widthBL   = pcBasePic->getWidth ();
-    heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
+    widthEL  = pcUsPic->getWidth ();
+    heightEL = pcUsPic->getHeight();
+
+    widthBL  = pcBasePic->getWidth ();
+    heightBL = min<Int>( pcBasePic->getHeight(), heightEL );
 
     Int leftStartL = scalEL.getWindowLeftOffset();
@@ -292,9 +333,14 @@
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
-
 #if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
     Int shift1 = g_bitDepthYLayer[refLayerId] - 8;
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift1 = currSlice->getPPS()->getCGSOutputBitDepthY() - 8;
+    }
+#endif
 #else
     Int shift1 = g_bitDepthY - 8;
@@ -380,5 +426,4 @@
     widthBL   = pcBasePic->getWidth ();
     heightBL  = pcBasePic->getHeight();
-
     widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
@@ -400,5 +445,4 @@
     Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
     leftOffset = leftStartC > 0 ? leftStartC : 0;
-
     shiftX = 16;
     shiftY = 16;
@@ -407,5 +451,9 @@
     Int phaseXC = phaseAlignFlag;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int phaseYC = phaseAlignFlag + 1;
+#else
     Int phaseYC = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( phaseAlignFlag + 1 );
+#endif
 #else
     Int phaseYC = phaseAlignFlag + 1;
@@ -414,5 +462,9 @@
     Int phaseXC = 0;
 #if P0312_VERT_PHASE_ADJ
+#if Q0120_PHASE_CALCULATION
+    Int phaseYC = 1;
+#else
     Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4): 1;
+#endif
 #else
     Int phaseYC = 1;
@@ -428,6 +480,16 @@
 #endif
 
+#if Q0120_PHASE_CALCULATION
+    deltaX     = (Int)phaseAlignFlag << 2;
+    deltaY     = ((( (Int)phaseAlignFlag +1)<<2)>>(Int)vertPhasePositionEnableFlag)+((Int)vertPhasePositionFlag<<3);
+#else
     deltaX     = 4 * phaseXC;
     deltaY     = 4 * phaseYC;
+#endif
+
+#if Q0200_CONFORMANCE_BL_SIZE
+    deltaX -= ( ( confBL.getWindowLeftOffset() * xScal ) >> 1 ) << 4;
+    deltaY  -= ( ( confBL.getWindowTopOffset() * yScal ) >> 1 ) << 4;
+#endif
 
     shiftXM4 = shiftX - 4;
@@ -444,4 +506,10 @@
     // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
     shift1 = g_bitDepthCLayer[refLayerId] - 8;
+#if Q0048_CGS_3D_ASYMLUT
+    if( currSlice->getPPS()->getCGSFlag() )
+    {
+      shift1 = currSlice->getPPS()->getCGSOutputBitDepthC() - 8;
+    }
+#endif
 #else
     shift1 = g_bitDepthC - 8;
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 713)
@@ -45,5 +45,5 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag );
 #else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 644)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 713)
@@ -42,5 +42,4 @@
 
 #define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
-
 #if SVC_EXTENSION
 #define MAX_LAYERS                       8      ///< max number of layers the codec is supposed to handle
@@ -50,5 +49,9 @@
 #define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
 
+#define Q0200_CONFORMANCE_BL_SIZE        1       ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
 #define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
+#if P0312_VERT_PHASE_ADJ
+#define Q0120_PHASE_CALCULATION          1      ///< JCTVC-Q0120 phase offset derivation for combination of spatial scalibility and field coding.
+#endif
 #define P0130_EOB                        1      ///< JCTVC-P0130, set layer Id of EOB NALU to be fixed to 0
 #define P0307_REMOVE_VPS_VUI_OFFSET      1      ///< JCTVC-P0307, remove implementation related to VPS VUI offset signalling
@@ -81,4 +84,5 @@
 
 #define O0164_MULTI_LAYER_HRD            1      ///< JCTVC-O0164: Multi-layer HRD operation
+#define Q0074_SEI_COLOR_MAPPING          1      ///< JCTVC-Q0074, SEI Color Mapping
 
 #define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters (and Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled)
@@ -86,5 +90,10 @@
 #define O0194_JOINT_US_BITSHIFT          1      ///< JCTVC-O0194: Joint Upsampling and bit-shift
 #endif
+#define Q0048_CGS_3D_ASYMLUT             1      ///< JCTVC-Q0048: Colour gamut scalability with look-up table
+#if Q0048_CGS_3D_ASYMLUT
+#define O0194_WEIGHTED_PREDICTION_CGS    0
+#else
 #define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
+#endif
 #define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
 #define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
@@ -185,4 +194,5 @@
 #define TSLAYERS_IL_RPS                  1      ///< JCTVC-O0120 IL RPS based on max temporal sub-layers
 #define P0079_DERIVE_NUMACTIVE_REF_PICS  1      ///< JCTVC-P0079 Modification of derivation of variable NumActiveRefLayerPics
+#define Q0060_MAX_TID_REF_EQUAL_TO_ZERO  1      ///< JCTVC-Q0060 handling the case max_tid_il_ref_pics_plus1 is equal to 0.
 #if REF_IDX_MFM
 #define N0139_POSITION_ROUNDING_OFFSET   1      ///< JCTVC-N0139: offset for collocated block in motion mapping
@@ -226,4 +236,7 @@
 #define O0096_DEFAULT_DEPENDENCY_TYPE    1      ///< JCTVC-O0096: specify default dependency type for all direct reference layers
 
+#define Q0195_REP_FORMAT_CLEANUP         1      ///< JCTVC-Q0195: restructureing of rep_format() signaling
+#define REP_FORMAT_FIX                   1      ///< update_rep_format_flag should be inferred to be equal to 0
+
 #define RESAMPLING_CONSTRAINT_BUG_FIX    1
 #define O0098_SCALED_REF_LAYER_ID        1      ///< JCTVC-O0098: signal scaled reference id
@@ -231,4 +244,7 @@
 #define O0153_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-O0153: alt output layer flag
 #define P0300_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-P0300: alt output layer flag
+
+#define Q0165_OUTPUT_LAYER_SET           1      ///< JCTVC-Q0165: add a constraint to disallow an empty output layer set
+#define Q0165_NUM_ADD_OUTPUT_LAYER_SETS  1      ///< JCTVC-Q0165: signal num_add_output_layer_set and default_target_output_layer_idc when vps_num_layer_sets_minus1 is greater than 0
 
 #define VPS_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: signaling DPB-related parameters
@@ -264,8 +280,22 @@
 //! \ingroup TLibCommon
 //! \{
+#define HARMONIZE_GOP_FIRST_FIELD_COUPLE  1
+#define FIX_FIELD_DEPTH                 1
+#define EFFICIENT_FIELD_IRAP            1
+#define ALLOW_RECOVERY_POINT_AS_RAP     1
 #define BUGFIX_INTRAPERIOD 1
 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
 
+#define SAO_SGN_FUNC 1
+
 #define FIX1172 1 ///< fix ticket #1172
+
+#define SETTING_PIC_OUTPUT_MARK     1
+#define SETTING_NO_OUT_PIC_PRIOR    1
+#define FIX_EMPTY_PAYLOAD_NAL       1
+#define FIX_WRITING_OUTPUT          1
+#define FIX_OUTPUT_EOS              1
+
+#define FIX_POC_CRA_NORASL_OUTPUT   1
 
 #define MAX_NUM_PICS_IN_SOP           1024
