Index: branches/SHM-dev/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/CommonDef.h	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibCommon/CommonDef.h	(revision 1432)
@@ -123,5 +123,6 @@
 #if SVC_EXTENSION
 static const Int    POS_SCALING_FACTOR_1X =                     65536; ///< position scaling factor equal to 1x
-static const Int    MV_SCALING_FACTOR_1X =                      4096 ; ///< MV scaling factor equal to 1x
+static const Int    POS_SCALING_FACTOR_2X =                     32768; ///< position scaling factor equal to 1x
+static const Int    MV_SCALING_FACTOR_1X =                       4096; ///< MV scaling factor equal to 1x
 #endif
 
@@ -257,4 +258,9 @@
 static const Int LAST_SIGNIFICANT_GROUPS =                        10 ;
 
+#if SVC_EXTENSION
+static const Int CGS_FILTER_LENGTH =                               13;
+static const Int CGS_FILTER_PHASES_2X =                             4;
+static const Int CGS_FILTER_PHASES_1X =                             8;
+#endif
 
 // ====================================================================================================================
Index: branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1432)
@@ -3556,10 +3556,10 @@
 {
   UInt uiNumRefLayersM1;
-  READ_UVLC( uiNumRefLayersM1 , "num_cm_ref_layers_minus1" );
+  READ_UVLC( uiNumRefLayersM1, "num_cm_ref_layers_minus1" );
   assert( uiNumRefLayersM1 <= 61 );
   for( UInt i = 0 ; i <= uiNumRefLayersM1 ; i++ )
   {
     UInt uiRefLayerId;
-    READ_CODE( 6 , uiRefLayerId , "cm_ref_layer_id" );
+    READ_CODE( 6, uiRefLayerId, "cm_ref_layer_id" );
     pc3DAsymLUT->addRefLayerId( uiRefLayerId );
   }
@@ -3567,16 +3567,16 @@
   UInt uiCurOctantDepth, uiCurPartNumLog2, uiInputBitDepthM8, uiOutputBitDepthM8, uiResQaunBit, uiDeltaBits;;
   
-  READ_CODE( 2 , uiCurOctantDepth , "cm_octant_depth" ); 
-  READ_CODE( 2 , uiCurPartNumLog2 , "cm_y_part_num_log2" );     
-
-  UInt uiChromaInputBitDepthM8 , uiChromaOutputBitDepthM8;
-
-  READ_UVLC( uiInputBitDepthM8 , "cm_input_luma_bit_depth_minus8" );
+  READ_CODE( 2, uiCurOctantDepth, "cm_octant_depth" ); 
+  READ_CODE( 2, uiCurPartNumLog2, "cm_y_part_num_log2" );     
+
+  UInt uiChromaInputBitDepthM8, uiChromaOutputBitDepthM8;
+
+  READ_UVLC( uiInputBitDepthM8, "cm_input_luma_bit_depth_minus8" );
   READ_UVLC( uiChromaInputBitDepthM8 , "cm_input_chroma_bit_depth_minus8" );
-  READ_UVLC( uiOutputBitDepthM8 , "cm_output_luma_bit_depth_minus8" );
-  READ_UVLC( uiChromaOutputBitDepthM8 , "cm_output_chroma_bit_depth_minus8" );
-  READ_CODE( 2 , uiResQaunBit , "cm_res_quant_bit" );
-
-  READ_CODE( 2 , uiDeltaBits , "cm_flc_bits" );
+  READ_UVLC( uiOutputBitDepthM8, "cm_output_luma_bit_depth_minus8" );
+  READ_UVLC( uiChromaOutputBitDepthM8  "cm_output_chroma_bit_depth_minus8" );
+  READ_CODE( 2, uiResQaunBit, "cm_res_quant_bit" );
+
+  READ_CODE( 2, uiDeltaBits, "cm_flc_bits" );
   pc3DAsymLUT->setDeltaBits(uiDeltaBits + 1);
 
@@ -3587,7 +3587,7 @@
   {
     Int delta = 0;
-    READ_SVLC( delta , "cm_adapt_threshold_u_delta" );
+    READ_SVLC( delta, "cm_adapt_threshold_u_delta" );
     nAdaptCThresholdU += delta;
-    READ_SVLC( delta , "cm_adapt_threshold_v_delta" );
+    READ_SVLC( delta, "cm_adapt_threshold_v_delta" );
     nAdaptCThresholdV += delta;
   }
@@ -3600,5 +3600,5 @@
   pc3DAsymLUT->xInitCuboids();
 #endif
-  xParse3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
+  xParse3DAsymLUTOctant( pc3DAsymLUT, 0, 0, 0, 0, 1 << pc3DAsymLUT->getCurOctantDepth() );
 #if R0164_CGS_LUT_BUGFIX_CHECK
   printf("============= Before 'xCuboidsFilledCheck()': ================\n");
@@ -3610,10 +3610,13 @@
 }
 
-Void TDecCavlc::xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength )
+Void TDecCavlc::xParse3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT, Int nDepth, Int yIdx, Int uIdx, Int vIdx, Int nLength )
 {
   UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth();
   if( nDepth < pc3DAsymLUT->getCurOctantDepth() )
-    READ_FLAG( uiOctantSplit , "split_octant_flag" );
+  {
+    READ_FLAG( uiOctantSplit, "split_octant_flag" );
+  }
   Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2();
+
   if( uiOctantSplit )
   {
@@ -3625,5 +3628,5 @@
         for( Int n = 0 ; n < 2 ; n++ )
         {
-          xParse3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength );
+          xParse3DAsymLUTOctant( pc3DAsymLUT, nDepth + 1, yIdx + l * nHalfLength * nYPartNum, uIdx + m * nHalfLength, vIdx + n * nHalfLength, nHalfLength );
         }
       }
@@ -3635,13 +3638,15 @@
     nFLCbits = nFLCbits >= 0 ? nFLCbits:0;
 
-    for( Int l = 0 ; l < nYPartNum ; l++ )
+    for( Int l = 0; l < nYPartNum; l++ )
     {
       Int shift = pc3DAsymLUT->getCurOctantDepth() - nDepth;
 
-      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
+      for( Int nVertexIdx = 0; nVertexIdx < 4; nVertexIdx++ )
       {
         UInt uiCodeVertex = 0;
-        Int deltaY = 0 , deltaU = 0 , deltaV = 0;
-        READ_FLAG( uiCodeVertex , "coded_vertex_flag" );
+        Int deltaY = 0, deltaU = 0, deltaV = 0;
+
+        READ_FLAG( uiCodeVertex, "coded_vertex_flag" );
+
         if( uiCodeVertex )
         {
@@ -3651,9 +3656,9 @@
         }
 
-        pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx , deltaY , deltaU , deltaV );
+        pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift), uIdx, vIdx, nVertexIdx, deltaY, deltaU, deltaV );
 
         for( Int m = 1; m < (1<<shift); m++ )
         {
-          pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) + m , uIdx , vIdx , nVertexIdx , 0 , 0 , 0 );
+          pc3DAsymLUT->setCuboidVertexResTree( yIdx + (l<<shift) + m, uIdx, vIdx, nVertexIdx, 0, 0, 0 );
 #if R0164_CGS_LUT_BUGFIX_CHECK
           pc3DAsymLUT->xSetFilled( yIdx + (l<<shift) + m , uIdx , vIdx );
@@ -3672,11 +3677,11 @@
         if( u!=0 || v!=0 )
         {
-          for( Int y=0 ; y<nLength*nYPartNum ; y++ )
+          for( Int y=0; y<nLength*nYPartNum; y++ )
           {
-            for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
+            for( Int nVertexIdx = 0; nVertexIdx < 4; nVertexIdx++ )
             {
-              pc3DAsymLUT->setCuboidVertexResTree( yIdx + y , uIdx + u , vIdx + v , nVertexIdx , 0 , 0 , 0 );
+              pc3DAsymLUT->setCuboidVertexResTree( yIdx + y, uIdx +  , vIdx + v, nVertexIdx, 0, 0, 0 );
 #if R0164_CGS_LUT_BUGFIX_CHECK
-              pc3DAsymLUT->xSetFilled( yIdx + y , uIdx + u , vIdx + v );
+              pc3DAsymLUT->xSetFilled( yIdx + y, uIdx + u, vIdx + v );
 #endif
             }
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 1432)
@@ -138,5 +138,5 @@
 }
 
-Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
+Double TEnc3DAsymLUT::xDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
   Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit )
 {
@@ -182,5 +182,5 @@
         {
           Int nTestP7 = Clip3( nMin , nMax , nInitP7 + m * nStepSize );
-          Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , nTestP7 );
+          Double dError = xCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , nTestP7 );
           if( dError < dMinError )
           {
@@ -202,5 +202,5 @@
 Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc )
 {
-  xxCollectData( pCurPic , refLayerIdc );
+  xCollectData( pCurPic , refLayerIdc );
 
   Double dErrorLuma = 0 , dErrorChroma = 0;
@@ -218,12 +218,12 @@
         if( rCuboidColorInfo.N > 0 )
         {
-          dErrorLuma += xxCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
+          dErrorLuma += xCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
             rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y );
         }
         if( rCuboidColorInfoC.N > 0 )
         {
-          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
+          dErrorChroma += xCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
             rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U );
-          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
+          dErrorChroma += xCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
             rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V );
         }
@@ -253,8 +253,8 @@
   Int nMaxPartNumLog2 = xGetMaxPartNumLog2();
 
-  xxMapPartNum2DepthYPart( nMaxPartNumLog2 , nCurOctantDepth , nCurYPartNumLog2 ); 
+  xMapPartNum2DepthYPart( nMaxPartNumLog2 , nCurOctantDepth , nCurYPartNumLog2 ); 
   xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); 
-  xxCollectData( pCurPic , refLayerIdc );
-  xxCopyColorInfo(m_pMaxColorInfo, m_pColorInfo, m_pMaxColorInfoC, m_pColorInfoC); 
+  xCollectData( pCurPic , refLayerIdc );
+  xCopyColorInfo(m_pMaxColorInfo, m_pColorInfo, m_pMaxColorInfoC, m_pColorInfoC); 
  
   sMaxLutSize.iCPartNumLog2 = nCurOctantDepth; 
@@ -275,5 +275,5 @@
 
   // check all LUT sizes 
-  xxGetAllLutSizes(pSlice);  
+  xGetAllLutSizes(pSlice);  
   if (m_nTotalLutSizes == 0) // return if no valid size is found, LUT will not be updated
   {
@@ -291,7 +291,7 @@
     nCurYPartNumLog2 = m_sLutSizes[i].iYPartNumLog2-nCurOctantDepth; 
     xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV ); 
-    xxConsolidateData( &m_sLutSizes[i], &sMaxLutSize );
+    xConsolidateData( &m_sLutSizes[i], &sMaxLutSize );
   
-    dCurError = xxDeriveVertexes(nBestResQuanBit, m_pEncCuboid);
+    dCurError = xDeriveVertexes(nBestResQuanBit, m_pEncCuboid);
 
     setResQuantBit( nBestResQuanBit );
@@ -329,7 +329,7 @@
         nCurYPartNumLog2 = getMaxYPartNumLog2()+getMaxOctantDepth()-nCurOctantDepth; 
       xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
-      xxCollectData( pCurPic , refLayerIdc );
-
-      dCurError = xxDeriveVertexes( nBestResQuanBit , m_pEncCuboid ) ;
+      xCollectData( pCurPic , refLayerIdc );
+
+      dCurError = xDeriveVertexes( nBestResQuanBit , m_pEncCuboid ) ;
       setResQuantBit( nBestResQuanBit );
       xSaveCuboids( m_pEncCuboid ); 
@@ -356,10 +356,10 @@
   // check res_quant_bits only for the best table size and best U/V threshold
   if( !bUseNewColorInfo ) 
-    xxConsolidateData( &m_sLutSizes[iBestLUTSizeIdx], &sMaxLutSize );
-
-  //    xxCollectData( pCurPic , refLayerIdc );
+    xConsolidateData( &m_sLutSizes[iBestLUTSizeIdx], &sMaxLutSize );
+
+  //    xCollectData( pCurPic , refLayerIdc );
   for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ )
   {
-    dCurError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid );
+    dCurError = xDeriveVertexes( nResQuanBit , m_pEncCuboid );
 
     setResQuantBit( nResQuanBit );
@@ -407,5 +407,5 @@
   m_nLUTBitDepth = pCfg->getCGSLUTBit();
   Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0; 
-  xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB );
+  xDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB );
 
   Int nBestResQuanBit = 0;
@@ -435,8 +435,8 @@
 
     xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
-    xxCollectData( pCurPic , refLayerIdc );
+    xCollectData( pCurPic , refLayerIdc );
     for( Int nResQuanBit = 0 ; nResQuanBit < 4 ; nResQuanBit++ )
     {
-      Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ) / ( 1 + ( nResQuanBit > 0 ) * 0.001 * ( pSlice->getDepth() + 1 ) );
+      Double dError = xDeriveVertexes( nResQuanBit , m_pEncCuboid ) / ( 1 + ( nResQuanBit > 0 ) * 0.001 * ( pSlice->getDepth() + 1 ) );
       if( dError <= dMinError )
       {
@@ -465,5 +465,5 @@
 }
 
-Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid )
+Double TEnc3DAsymLUT::xDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid )
 {
   Double dErrorLuma = 0 , dErrorChroma = 0;
@@ -488,5 +488,5 @@
         if( rCuboidColorInfo.N > 0 )
         {
-          dErrorLuma += xxDeriveVertexPerColor( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
+          dErrorLuma += xDeriveVertexPerColor( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
             rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit );
         }
@@ -494,8 +494,8 @@
         if( rCuboidColorInfoC.N > 0 )
         {
-          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
+          dErrorChroma += xDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
             rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit );
 
-          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
+          dErrorChroma += xDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
             rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit );
         }
@@ -519,5 +519,5 @@
 }
 
-Void TEnc3DAsymLUT::xxCollectData( TComPic * pCurPic , UInt refLayerIdc )
+Void TEnc3DAsymLUT::xCollectData( TComPic * pCurPic , UInt refLayerIdc )
 {
   Pel * pSrcY = m_pDsOrigPic->getAddr(COMPONENT_Y);
@@ -659,5 +659,5 @@
 }
 
-Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB )
+Void TEnc3DAsymLUT::xDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB )
 {
   Int nPartNumLog2 = 4;
@@ -684,8 +684,8 @@
 
   nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2()  , nPartNumLog2 );
-  xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 );
-}
-
-Void TEnc3DAsymLUT::xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 )
+  xMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 );
+}
+
+Void TEnc3DAsymLUT::xMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 )
 {
   for( Int y = getMaxYPartNumLog2() ; y >= 0 ; y-- )
@@ -728,5 +728,5 @@
 #if R0179_ENC_OPT_3DLUT_SIZE
 
-Void TEnc3DAsymLUT::xxGetAllLutSizes(TComSlice *pSlice)
+Void TEnc3DAsymLUT::xGetAllLutSizes(TComSlice *pSlice)
 {
   Int iMaxYPartNumLog2, iMaxCPartNumLog2; 
@@ -735,5 +735,5 @@
   Int iNumELFrameBits = m_nPrevELFrameBit[pSlice->getSliceType()][pSlice->getDepth()];
 
-  xxMapPartNum2DepthYPart( xGetMaxPartNumLog2() , iMaxCPartNumLog2 , iMaxYPartNumLog2 );
+  xMapPartNum2DepthYPart( xGetMaxPartNumLog2() , iMaxCPartNumLog2 , iMaxYPartNumLog2 );
   iMaxAddYPartNumLog2 = iMaxYPartNumLog2; 
   iMaxYPartNumLog2 += iMaxCPartNumLog2; 
@@ -762,5 +762,5 @@
 }
 
-Void TEnc3DAsymLUT::xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC )
+Void TEnc3DAsymLUT::xCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC )
 {
   Int yIdx, uIdx, vIdx; 
@@ -780,5 +780,5 @@
 }
 
-Void TEnc3DAsymLUT::xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 )
+Void TEnc3DAsymLUT::xAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 )
 {
   SColorInfo & rCuboidColorInfo  = m_pColorInfo [yIdx][uIdx][vIdx];
@@ -798,5 +798,5 @@
 }
 
-Void TEnc3DAsymLUT::xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize )
+Void TEnc3DAsymLUT::xConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize )
 {
   Int yIdx, uIdx, vIdx; 
@@ -811,5 +811,5 @@
   if (iYDiffLog2 == 0 && iCDiffLog2 == 0) // shouldn't have to do anything 
   {
-    xxCopyColorInfo(m_pColorInfo, m_pMaxColorInfo, m_pColorInfoC, m_pMaxColorInfoC);
+    xCopyColorInfo(m_pColorInfo, m_pMaxColorInfo, m_pColorInfoC, m_pMaxColorInfoC);
     return; 
   }
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h	(revision 1432)
@@ -144,49 +144,48 @@
   Int         m_nLUTBitDepth;
 #if R0179_ENC_OPT_3DLUT_SIZE
-
-  Double m_dDistFactor[3][MAX_TLAYER];         
-  Int    m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE]; 
-  Int    m_nPrevELFrameBit[3][MAX_TLAYER];   
-
-
-  Int   m_nTotalLutSizes;
-  SLUTSize m_sLutSizes[MAX_NUM_LUT_SIZES];
-#endif 
-  Double m_dSumU;
-  Double m_dSumV;
-  Int    m_nNChroma;
+  Double      m_dDistFactor[3][MAX_TLAYER];         
+  Int         m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE]; 
+  Int         m_nPrevELFrameBit[3][MAX_TLAYER];   
+
+
+  Int         m_nTotalLutSizes;
+  SLUTSize    m_sLutSizes[MAX_NUM_LUT_SIZES];
+#endif 
+  Double      m_dSumU;
+  Double      m_dSumV;
+  Int         m_nNChroma;
 #if R0179_ENC_OPT_3DLUT_SIZE
   TComOutputBitstream  *m_pBitstreamRedirect;
-  TEncCavlc *m_pEncCavlc;
+  TEncCavlc  *m_pEncCavlc;
 #endif 
 
 private:
-  Double  xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
-    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
-
-  Void    xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
-  Void    xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
-  Int     xxCoeff2Vertex( Double a , Double b , Double c , Double d , Int y , Int u , Int v ) { return ( ( Int )( a * y + b * u + c * v + d + 0.5 ) ); }
-  Void    xxCollectData( TComPic * pCurPic , UInt refLayerIdc );
-
-  Double  xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
-
-  inline Double xxCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY,
-    Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
-
-  inline Double xxCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d );
-
-  inline Double xxCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
-
-#if R0179_ENC_OPT_3DLUT_SIZE
-  Void    xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
-  Void    xxGetAllLutSizes(TComSlice *pSlice);
-  Void    xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC ); 
-  Void    xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 );
+  Double  xDeriveVertexPerColor( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, 
+                                 Pel & rP0, Pel & rP1, Pel & rP3, Pel & rP7, Int nResQuantBit );
+
+  Void    xDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
+  Void    xMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
+  Int     xCoeff2Vertex( Double a , Double b , Double c , Double d , Int y , Int u , Int v ) { return ( ( Int )( a * y + b * u + c * v + d + 0.5 ) ); }
+  Void    xCollectData( TComPic * pCurPic , UInt refLayerIdc );
+
+  Double  xDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
+
+  inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY,
+                             Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
+
+  inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d );
+
+  inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
+
+#if R0179_ENC_OPT_3DLUT_SIZE
+  Void    xConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
+  Void    xGetAllLutSizes(TComSlice *pSlice);
+  Void    xCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC ); 
+  Void    xAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 );
 #endif 
 };
 
-Double TEnc3DAsymLUT::xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
-  Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 )
+Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY,
+                                   Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )
 {
   Double a = 1.0 * ( nP7 - nP3 ) / nLengthY;
@@ -194,8 +193,8 @@
   Double c = 1.0 * ( nP3 - nP1 ) / nLengthUV;
   Double d = ( ( nP0 * nLengthUV + u0 * nP0 + ( v0 - u0 ) * nP1 - v0 * nP3 ) * nLengthY + y0 * nLengthUV * ( nP3 - nP7 ) ) / nLengthUV / nLengthY;
-  return( xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) );
+  return( xCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) );
 }
 
-Double TEnc3DAsymLUT::xxCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d )  
+Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d )  
 {
   Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
@@ -203,5 +202,5 @@
 };
 
-Double TEnc3DAsymLUT::xxCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )  
+Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )  
 {
   const Int nOne = xGetNormCoeffOne();
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 1432)
@@ -1086,5 +1086,5 @@
 #endif
 #if Q0074_COLOUR_REMAPPING_SEI
-  Void  setCRISEIFileRoot( Char* pch )                       { m_colourRemapSEIFileRoot = pch; }
+  Void  xSetCRISEIFileRoot( Char* pch )                       { m_colourRemapSEIFileRoot = pch; }
   Char* getCRISEIFileRoot()                                  { return m_colourRemapSEIFileRoot; }
 #endif
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1432)
@@ -138,5 +138,5 @@
   if(m_temp)
   {
-    free_mem2DintWithPad(m_temp, m_iTap>>1, 0);
+    xDestroy2DArray(m_temp, m_cgsFilterLength>>1, 0);
     m_temp = NULL;
   }
@@ -697,5 +697,5 @@
 
 #if Q0074_COLOUR_REMAPPING_SEI
-Void TEncGOP::freeColourCRI()
+Void TEncGOP::xFreeColourCRI()
 {
   for( Int c=0 ; c<3 ; c++)
@@ -724,5 +724,5 @@
 }
 
-Int TEncGOP::readingCRIparameters(){
+Int TEncGOP::xReadingCRIparameters(){
 
   // reading external Colour Remapping Information SEI message parameters from file
@@ -938,5 +938,5 @@
 #if Q0074_COLOUR_REMAPPING_SEI
     // insert one CRI by picture (if the file exist)   
-    freeColourCRI();
+    xFreeColourCRI();
 
     // building the CRI file name with poc num in suffix "_poc.txt"
@@ -945,7 +945,7 @@
     string  colourRemapSEIFileWithPoc(m_pcCfg->getCRISEIFileRoot());
     colourRemapSEIFileWithPoc.append(suffix);
-    setCRISEIFile( const_cast<Char*>(colourRemapSEIFileWithPoc.c_str()) );
+    xSetCRISEIFile( const_cast<Char*>(colourRemapSEIFileWithPoc.c_str()) );
   
-    Int ret = readingCRIparameters();
+    Int ret = xReadingCRIparameters();
 
     if(ret != -1 && m_pcCfg->getCRISEIFileRoot())
@@ -1802,5 +1802,5 @@
           {
             //downsampling
-            downScalePic(pcPic->getPicYuvOrg(), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg(), pcSlice->getBitDepths(), pcPic->getPosScalingFactor(refLayerIdc, 0));
+            xDownScalePic(pcPic->getPicYuvOrg(), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg(), pcSlice->getBitDepths(), pcPic->getPosScalingFactor(refLayerIdc, 0));
             
             m_Enc3DAsymLUTPPS.setDsOrigPic(pcSlice->getBaseColPic(refLayerIdc)->getPicYuvOrg());
@@ -4194,5 +4194,5 @@
 }
 
-Void TEncGOP::downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, BitDepths& bitDepth, const Int posScalingFactorX)
+Void TEncGOP::xDownScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, BitDepths& bitDepth, const Int posScalingFactorX)
 {
   pcYuvSrc->setBorderExtension(false);
@@ -4205,40 +4205,45 @@
   if(!m_temp)
   {
-    initDs(iWidth, iHeight, m_pcCfg->getIntraPeriod()>1, posScalingFactorX);
-  }
-
-  filterImg(pcYuvSrc->getAddr(COMPONENT_Y),  pcYuvSrc->getStride(COMPONENT_Y),  pcYuvDest->getAddr(COMPONENT_Y),  pcYuvDest->getStride(COMPONENT_Y),  iHeight,    iWidth,    bitDepth, 0);
-  filterImg(pcYuvSrc->getAddr(COMPONENT_Cb), pcYuvSrc->getStride(COMPONENT_Cb), pcYuvDest->getAddr(COMPONENT_Cb), pcYuvDest->getStride(COMPONENT_Cb), iHeight>>1, iWidth>>1, bitDepth, 1);
-  filterImg(pcYuvSrc->getAddr(COMPONENT_Cr), pcYuvSrc->getStride(COMPONENT_Cr), pcYuvDest->getAddr(COMPONENT_Cr), pcYuvDest->getStride(COMPONENT_Cr), iHeight>>1, iWidth>>1, bitDepth, 2);  
-}
-const Int TEncGOP::m_phase_filter_0_t0[4][13]={
+    xInitDs(iWidth, iHeight, m_pcCfg->getIntraPeriod() > 1, posScalingFactorX);
+  }
+
+  xFilterImg(pcYuvSrc->getAddr(COMPONENT_Y),  pcYuvSrc->getStride(COMPONENT_Y),  pcYuvDest->getAddr(COMPONENT_Y),  pcYuvDest->getStride(COMPONENT_Y),  iHeight,    iWidth,    bitDepth, COMPONENT_Y);
+  xFilterImg(pcYuvSrc->getAddr(COMPONENT_Cb), pcYuvSrc->getStride(COMPONENT_Cb), pcYuvDest->getAddr(COMPONENT_Cb), pcYuvDest->getStride(COMPONENT_Cb), iHeight>>1, iWidth>>1, bitDepth, COMPONENT_Cb);
+  xFilterImg(pcYuvSrc->getAddr(COMPONENT_Cr), pcYuvSrc->getStride(COMPONENT_Cr), pcYuvDest->getAddr(COMPONENT_Cr), pcYuvDest->getStride(COMPONENT_Cr), iHeight>>1, iWidth>>1, bitDepth, COMPONENT_Cr);  
+}
+const Pel TEncGOP::m_phaseFilter0T0[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH] =
+{
   {0,  2,  -3,  -9,   6,  39,  58,  39,   6,  -9,  -3,  2,  0},  
-  {0, 0,  0,  -2,  8,-20, 116, 34, -10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
+  {0,  0,   0,  -2,  8,  -20, 116,  34, -10,   2,   0,  0,  0},            //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
   {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
-  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8, -1,  1}  
 };
 
-const Int TEncGOP::m_phase_filter_0_t1[4][13]={
-  {0,  4,  0,  -12, 0,  40,  64,  40, 0, -12,  0,  4,  0},
-  {0, 0,  0,  -2,  8,-20, 116,34,-10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
-  {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
-  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+const Pel TEncGOP::m_phaseFilter0T1[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH] =
+{
+  {0,  4,  0,  -12, 0,  40,  64,  40,   0, -12,  0,  4,  0},
+  {0,  0,  0,  -2,  8, -20, 116,  34, -10,   2,  0,  0,  0},               //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
+  {0,  1,  0,  -7, -5,  22,  53,  53,  22,  -5, -7,  0,  1},  
+  {0,  0,  1,  -5, -7,  13,  47,  57,  31,  -1, -8, -1,  1}  
 };
-const Int TEncGOP::m_phase_filter_0_t1_chroma[4][13]={
-  {0,  0,  0,   0,  0,   0,  128, 0,  0,  0,  0,  0,  0},
-  {0, 0,  0,  -2,  8,-20, 116,34,-10,  2,  0, 0,  0},                      //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
-  {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1},  
-  {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1}  
+
+const Pel TEncGOP::m_phaseFilter0T1Chroma[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH] =
+{
+  {0,  0,  0,  0,  0,   0, 128,  0,   0,  0,  0,  0, 0},
+  {0,  0,  0, -2,  8, -20, 116, 34, -10,  2,  0,  0, 0},                   //{0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0},  //
+  {0,  1,  0, -7, -5,  22,  53, 53,  22, -5, -7,  0, 1},  
+  {0,  0,  1, -5, -7,  13,  47, 57,  31, -1, -8, -1, 1}  
 };
 
-const Int TEncGOP::m_phase_filter_1[8][13]={
-  {0,   0,  5,  -6,  -10,37,  76,  37,-10,   -6, 5,  0,   0},    
-  {0,  -1,  5,  -3,  -12,29,  75,  45,  -7,   -8, 5,  0,   0},    
-  {0,  -1,  4,  -1,  -13,22,  73,  52,  -3,  -10, 4,  1,   0},    
-  {0,  -1,  4,   1,  -13,14,  70,  59,   2,  -12, 3,  2,  -1},  
-  {0,  -1,  3,   2,  -13, 8,  65,  65,   8,  -13, 2,  3,  -1},    
-  {0,  -1,  2,   3,  -12, 2,  59,  70,  14,  -13, 1,  4,  -1},    
-  {0,   0,  1,   4,  -10,-3,  52,  73,  22,  -13,-1,  4,  -1},    
-  {0,   0,  0,   5,   -8,-7,  45,  75,  29,  -12,-3,  5,  -1}    
+const Pel TEncGOP::m_phaseFilter1[CGS_FILTER_PHASES_1X][CGS_FILTER_LENGTH] =
+{
+  {0,  0, 5, -6, -10, 37, 76, 37, -10,  -6, 5, 0,  0},    
+  {0, -1, 5, -3, -12, 29, 75, 45,  -7,  -8, 5, 0,  0},    
+  {0, -1, 4, -1, -13, 22, 73, 52,  -3, -10, 4, 1,  0},    
+  {0, -1, 4,  1, -13, 14, 70, 59,   2, -12, 3, 2, -1},  
+  {0, -1, 3,  2, -13,  8, 65, 65,   8, -13, 2, 3, -1},    
+  {0, -1, 2,  3, -12,  2, 59, 70,  14, -13, 1, 4, -1},    
+  {0,  0, 1,  4, -10, -3, 52, 73,  22, -13,-1, 4, -1},    
+  {0,  0, 0,  5,  -8, -7, 45, 75,  29, -12,-3, 5, -1}    
 };
 
@@ -4251,104 +4256,106 @@
 #endif
 #endif
-Void TEncGOP::filterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, Int plane )
-{
-  Int length = m_iTap;
-  Int height2,width2;
-  Int k,iSum;
-  Int i0, div_i0, i1;
-  Int j0, div_j0, j1;
-  const Int *p_filter;
-  Pel *p_src, *p_dst;
-  Pel *p_src_line, *p_dst_line;
-  Int **p_temp, *p_tmp;
-  Int shift = bitDepth.recon[CHANNEL_TYPE_LUMA] - bitDepth.recon[CHANNEL_TYPE_CHROMA];
+Void TEncGOP::xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, ComponentID comp )
+{
+  Int height2, width2;
+
+  Pel *srcLine = src;
+  Pel *dstLine = dst;
+  Int length = m_cgsFilterLength;
+  Int shift  = bitDepth.recon[CHANNEL_TYPE_LUMA] - bitDepth.recon[CHANNEL_TYPE_CHROMA];
   Int shift2 = 2*7+shift;
-  Int shift_round = (1 << (shift2 - 1));
-  Int iMax = (1<<(bitDepth.recon[CHANNEL_TYPE_LUMA]-shift))-1;
-  height2 = (height1 * m_iM) / m_iN;
-  width2  = (width1  * m_iM) / m_iN;
-
-  m_phase_filter = plane? m_phase_filter_chroma : m_phase_filter_luma;
+  Int roundingOffset = (1 << (shift2 - 1));
+  Int maxVal = (1<<(bitDepth.recon[toChannelType(comp)]-shift))-1;
+  height2 = (height1 * m_cgsFilterPhases) / m_iN;
+  width2  = (width1  * m_cgsFilterPhases) / m_iN;
+
+  m_phaseFilter = comp == COMPONENT_Y ? m_phaseFilterLuma : m_phaseFilterChroma;
 
   // horizontal filtering
-  p_src_line = src;
-  for(j1 = 0; j1 < height1; j1++)
-  {
-    i0=-m_iN;
-    p_tmp = m_temp[j1];
+  for( Int j1 = 0; j1 < height1; j1++ )
+  {
+    Int i0 = -m_iN;
+    Int *tmp = m_temp[j1];
     
-    for(i1 = 0; i1 < width2; i1++)
-    {
-      i0      += m_iN;
-      div_i0   = (i0 / m_iM);
-      p_src    =  p_src_line + ( div_i0 - (length >> 1));
-      p_filter = m_phase_filter[i0 - div_i0 * m_iM]; // phase_filter[i0 % M]
-      iSum     = 0;
-      for(k = 0; k < length; k++)
-      {
-        iSum += (*p_src++) * (*p_filter++);
-      }
-      *p_tmp++ = iSum;
-    }
-    p_src_line +=  iSrcStride;
+    for( Int i1 = 0; i1 < width2; i1++ )
+    {
+      i0 += m_iN;
+      Int div_i0 = i0 / m_cgsFilterPhases;
+
+      Pel *srcTmp =  srcLine + ( div_i0 - (length >> 1));
+      const Pel *filter = m_phaseFilter[i0 - div_i0 * m_cgsFilterPhases]; // phase_filter[i0 % M]
+
+      Int sum = 0;
+      for(Int k = 0; k < length; k++)
+      {
+        sum += (*srcTmp++) * (*filter++);
+      }
+      *tmp++ = sum;
+    }
+    srcLine += iSrcStride;
   }
 
   // pad temp (vertical)
-  for (k=-(length>>1); k<0; k++)
+  for( Int k = -(length>>1); k<0; k++ )
   {
     memcpy(m_temp[k], m_temp[0], width2*sizeof(Int));
   }
-  for (k=height1; k<(height1+(length>>1)); k++)
-  {
-    memcpy(m_temp[k], m_temp[k-1], (width2)* sizeof(Int));
+
+  for( Int k = height1; k < (height1 + (length>>1)); k++)
+  {
+    memcpy(m_temp[k], m_temp[k-1], (width2) * sizeof(Int));
   }
 
   // vertical filtering
-  j0 = (plane == 0) ? -m_iN : -(m_iN-1);
+  Int j0 = comp == COMPONENT_Y ? -m_iN : (1 - m_iN);
   
-  p_dst_line = dst;
-  for(j1 = 0; j1 < height2; j1++)
-  {
-    j0      += m_iN;
-    div_j0   = (j0 / m_iM);
-    p_dst = p_dst_line;
-    p_temp   = &m_temp[div_j0 - (length>>1)];
-    p_filter = m_phase_filter[j0 - div_j0 * m_iM]; // phase_filter[j0 % M]
-    for(i1 = 0; i1 < width2;i1++)
-    {
-      iSum=0;
-      for(k = 0; k < length; k++)
-      {
-        iSum += p_temp[k][i1] * p_filter[k];
-      }
-      iSum=((iSum + shift_round) >> shift2);
-      *p_dst++ = (Short)(iSum > iMax ? iMax : (iSum < 0 ? 0 : iSum));
-    }
-    p_dst_line += iDstStride;
-  }
-}
-
-Void TEncGOP::initDs(Int iWidth, Int iHeight, Int iType, const Int posScalingFactorX)
-{
-  m_iTap = 13;
-  if(posScalingFactorX == (1<<15))
-  {
-    m_iM = 4;
+  for( Int j1 = 0; j1 < height2; j1++ )
+  {
+    j0 += m_iN;
+    Int div_j0 = j0 / m_cgsFilterPhases;
+
+    Pel* dstTmp = dstLine;
+
+    Int **temp = &m_temp[div_j0 - (length>>1)];
+    const Pel *filter = m_phaseFilter[j0 - div_j0 * m_cgsFilterPhases]; // phase_filter[j0 % M]
+
+    for( Int i1 = 0; i1 < width2;i1++ )
+    {
+      Int sum=0;
+      for( Int k = 0; k < length; k++ )
+      {
+        sum += temp[k][i1] * filter[k];
+      }
+      sum = ((sum + roundingOffset) >> shift2);
+
+      *dstTmp++ = Clip3<Short>(sum < 0 ? 0 : sum, maxVal, sum);
+    }
+    dstLine += iDstStride;
+  }
+}
+
+Void TEncGOP::xInitDs( const Int iWidth, const Int iHeight, const Bool allIntra, const Int posScalingFactorX )
+{
+  m_cgsFilterLength = CGS_FILTER_LENGTH;
+
+  if( posScalingFactorX == POS_SCALING_FACTOR_2X )
+  {
+    m_cgsFilterPhases = CGS_FILTER_PHASES_2X;
     m_iN = 8;
-    m_phase_filter_luma = iType? m_phase_filter_0_t1 : m_phase_filter_0_t0;
-    m_phase_filter_chroma = m_phase_filter_0_t1_chroma;    
+    m_phaseFilterLuma = allIntra ? m_phaseFilter0T1 : m_phaseFilter0T0;
+    m_phaseFilterChroma = m_phaseFilter0T1Chroma;    
   }
   else
   {
-    m_iM = 8;
+    m_cgsFilterPhases = CGS_FILTER_PHASES_1X;
     m_iN = 12;
-    m_phase_filter_luma = m_phase_filter_chroma =  m_phase_filter_1;
-    m_phase_filter = m_phase_filter_1;
-  }
-
-  get_mem2DintWithPad (&m_temp, iHeight, iWidth*m_iM/m_iN, m_iTap>>1, 0);
-}
-
-Int TEncGOP::get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX)
+    m_phaseFilterLuma = m_phaseFilterChroma = m_phaseFilter1;
+    m_phaseFilter = m_phaseFilter1;
+  }
+
+  xCreate2DArray( &m_temp, iHeight, iWidth * m_cgsFilterPhases/m_iN, m_cgsFilterLength >> 1, 0 );
+}
+
+Int TEncGOP::xCreate2DArray(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX)
 {
   Int i;
@@ -4373,5 +4380,5 @@
 }
 
-Void TEncGOP::free_mem2DintWithPad(Int **array2D, Int iPadY, Int iPadX)
+Void TEncGOP::xDestroy2DArray(Int **array2D, Int iPadY, Int iPadX)
 {
   if (array2D)
@@ -4383,5 +4390,5 @@
     else 
     {
-      printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+      printf("xDestroy2DArray: trying to free unused memory\r\nPress Any Key\r\n");
     }
 
@@ -4390,5 +4397,5 @@
   else
   {
-    printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
+    printf("xDestroy2DArray: trying to free unused memory\r\nPress Any Key\r\n");
   }
 }
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 1431)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 1432)
@@ -152,19 +152,20 @@
   TComPicYuv*             m_pColorMappedPic;
 
-  Int m_iTap;
-  const Int (*m_phase_filter)[13];
-  const Int (*m_phase_filter_luma)[13];
-  const Int (*m_phase_filter_chroma)[13];
-  Int m_iM, m_iN;
-  static const Int m_phase_filter_0_t0[4][13];
-  static const Int m_phase_filter_0_t1[4][13];
-  static const Int m_phase_filter_0_t1_chroma[4][13];
-  static const Int m_phase_filter_1[8][13];
-  Int   **m_temp;
-#endif
-  Int   m_lastPocPeriodId;
-  Bool  m_noRaslOutputFlag;
-  Bool  m_prevPicHasEos;
-  static Bool m_signalledVPS;
+  Char                    m_cgsFilterLength;
+  Char                    m_cgsFilterPhases;
+  Int                     m_iN;
+  Int                   **m_temp;
+  const Pel             (*m_phaseFilter)[CGS_FILTER_LENGTH];
+  const Pel             (*m_phaseFilterLuma)[CGS_FILTER_LENGTH];
+  const Pel             (*m_phaseFilterChroma)[CGS_FILTER_LENGTH];
+  static const Pel        m_phaseFilter0T0[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH];
+  static const Pel        m_phaseFilter0T1[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH];
+  static const Pel        m_phaseFilter0T1Chroma[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH];
+  static const Pel        m_phaseFilter1[CGS_FILTER_PHASES_1X][CGS_FILTER_LENGTH];
+#endif
+  Int                     m_lastPocPeriodId;
+  Bool                    m_noRaslOutputFlag;
+  Bool                    m_prevPicHasEos;
+  static Bool             m_signalledVPS;
 #endif
   
@@ -275,8 +276,8 @@
 #if Q0074_COLOUR_REMAPPING_SEI
   TComSEIColourRemappingInfo* xGetSEIColourRemappingInfo()  { return &m_seiColourRemappingInfo; }
-  Void  setCRISEIFile( Char* pch )       { m_seiColourRemappingInfo.m_colourRemapSEIFile = pch; }
-
-  Void freeColourCRI();
-  Int  readingCRIparameters();
+  Void xSetCRISEIFile( Char* pch )                          { m_seiColourRemappingInfo.m_colourRemapSEIFile = pch; }
+
+  Void xFreeColourCRI();
+  Int  xReadingCRIparameters();
   Void xCheckParameter();
 #endif
@@ -287,12 +288,12 @@
 #if CGS_3D_ASYMLUT
   Void xDetermine3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS );
-  Void downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, BitDepths& bitDepth, const Int posScalingFactorX);
-  Void downScaleComponent2x2( const Pel* pSrc, Pel* pDest, const Int iSrcStride, const Int iDestStride, const Int iSrcWidth, const Int iSrcHeight, const Int inputBitDepth, const Int outputBitDepth );
-  inline Short xClip( Short x , Int bitdepth );
-  Void initDs(Int iWidth, Int iHeight, Int iType, const Int posScalingFactorX);
-  Void filterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, Int plane );
-
-  Int get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX);
-  Void free_mem2DintWithPad(Int **array2D, Int iPadY, Int iPadX);
+  Void xDownScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, BitDepths& bitDepth, const Int posScalingFactorX);
+  Void xDownScaleComponent2x2( const Pel* pSrc, Pel* pDest, const Int iSrcStride, const Int iDestStride, const Int iSrcWidth, const Int iSrcHeight, const Int inputBitDepth, const Int outputBitDepth );
+  inline Short xClip( Short x, Int bitdepth );
+  Void xInitDs( const Int iWidth, const Int iHeight, const Bool allIntra, const Int posScalingFactorX);
+  Void xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, ComponentID comp );
+
+  Int  xCreate2DArray(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX);
+  Void xDestroy2DArray(Int **array2D, Int iPadY, Int iPadX);
 #endif
   Void xCheckLayerReset(TComSlice *slice);
