Index: branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 625)
+++ branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 627)
@@ -125,4 +125,7 @@
   m_interLayerPredEnabledFlag = 0;
   ::memset( m_interLayerPredLayerIdc, 0, sizeof(m_interLayerPredLayerIdc) );
+#if P0312_VERT_PHASE_ADJ
+  ::memset( m_vertPhasePositionFlag, 0, sizeof(m_vertPhasePositionFlag) );
+#endif
 #endif //SVC_EXTENSION
 
@@ -1122,4 +1125,7 @@
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
   memcpy( m_interLayerPredLayerIdc, pSrc->m_interLayerPredLayerIdc, sizeof( m_interLayerPredLayerIdc ) );
+#if P0312_VERT_PHASE_ADJ
+  memcpy( m_vertPhasePositionFlag, pSrc->m_vertPhasePositionFlag, sizeof( m_vertPhasePositionFlag ) );
+#endif
 #endif
   m_pcSPS                = pSrc->m_pcSPS;
Index: branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 625)
+++ branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 627)
@@ -627,4 +627,9 @@
   Int         m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
 #endif
+  
+#if P0312_VERT_PHASE_ADJ
+  Bool        m_vpsVuiVertPhaseInUseFlag;
+#endif
+
 #if P0300_ALT_OUTPUT_LAYER_FLAG
   Bool       m_altOutputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1];
@@ -1008,4 +1013,10 @@
   Int     getBaseLayerPSCompatibilityFlag (Int layer)   { return m_baseLayerPSCompatibilityFlag[layer];}
 #endif
+
+#if P0312_VERT_PHASE_ADJ
+  Bool getVpsVuiVertPhaseInUseFlag()       { return m_vpsVuiVertPhaseInUseFlag; }
+  Void setVpsVuiVertPhaseInUseFlag(Bool x) { m_vpsVuiVertPhaseInUseFlag = x;    }
+#endif
+
 #if P0300_ALT_OUTPUT_LAYER_FLAG
   Bool   getAltOuputLayerFlag(Int idx)         { return m_altOutputLayerFlag[idx]; }
@@ -1115,4 +1126,8 @@
   Int           m_winTopOffset;
   Int           m_winBottomOffset;
+#if P0312_VERT_PHASE_ADJ
+  Bool          m_vertPhasePositionEnableFlag;
+  Bool          m_vertPhasePositionFlag;
+#endif
 public:
   Window()
@@ -1122,8 +1137,16 @@
   , m_winTopOffset      (0)
   , m_winBottomOffset   (0)
+#if P0312_VERT_PHASE_ADJ
+  , m_vertPhasePositionEnableFlag(false)
+  , m_vertPhasePositionFlag(false)
+#endif
   { }
 
   Bool          getWindowEnabledFlag() const      { return m_enabledFlag; }
-  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; }
+#if P0312_VERT_PHASE_ADJ 
+  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; m_vertPhasePositionEnableFlag = m_vertPhasePositionFlag = false;} 
+#else
+  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0;} 
+#endif
   Int           getWindowLeftOffset() const       { return m_enabledFlag ? m_winLeftOffset : 0; }
   Void          setWindowLeftOffset(Int val)      { m_winLeftOffset = val; m_enabledFlag = true; }
@@ -1135,5 +1158,15 @@
   Void          setWindowBottomOffset(Int val)    { m_winBottomOffset = val; m_enabledFlag = true; }
 
+#if P0312_VERT_PHASE_ADJ
+  Bool          getVertPhasePositionEnableFlag() const     { return m_vertPhasePositionEnableFlag ; }
+  Void          setVertPhasePositionEnableFlag(Bool val)    { m_vertPhasePositionEnableFlag = val;  }
+
+  Bool          getVertPhasePositionFlag() const     { return m_vertPhasePositionEnableFlag ? m_vertPhasePositionFlag: 0; }
+  Void          setVertPhasePositionFlag(Bool val)    { m_vertPhasePositionFlag = val;  }
+
+  Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom  , Bool vertPhasePositionEnableFlag = 0, Bool phasePosFlag = 0)
+#else
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom)
+#endif
   {
     m_enabledFlag       = true;
@@ -1142,4 +1175,8 @@
     m_winTopOffset      = offsetLTop;
     m_winBottomOffset   = offsetLBottom;
+#if P0312_VERT_PHASE_ADJ
+    m_vertPhasePositionEnableFlag = vertPhasePositionEnableFlag;
+    m_vertPhasePositionFlag = phasePosFlag;
+#endif
   }
 };
@@ -1393,4 +1430,7 @@
   UInt m_layerId;
   UInt        m_numScaledRefLayerOffsets;
+#if P0312_VERT_PHASE_ADJ
+ Bool         m_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
 #if O0098_SCALED_REF_LAYER_ID
   UInt        m_scaledRefLayerId[MAX_LAYERS];
@@ -1549,4 +1589,8 @@
   UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
   Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
+#if P0312_VERT_PHASE_ADJ
+  Bool     getVertPhasePositionEnableFlag(Int x)  { return m_vertPhasePositionEnableFlag[x]; }
+  Void     setVertPhasePositionEnableFlag(Int x, Bool b)  { m_vertPhasePositionEnableFlag[x] = b; } 
+#endif
 #if O0098_SCALED_REF_LAYER_ID
   UInt     getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
@@ -1944,4 +1988,7 @@
   Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
   Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
+#if P0312_VERT_PHASE_ADJ
+  Bool        m_vertPhasePositionFlag[MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #if POC_RESET_FLAG
   Bool        m_bPocResetFlag;
@@ -2224,4 +2271,9 @@
   Bool      getInterLayerPredEnabledFlag     ()                { return m_interLayerPredEnabledFlag;}
 
+#if P0312_VERT_PHASE_ADJ
+  Int       getVertPhasePositionFlag (UInt layerIdx)              { return   m_vertPhasePositionFlag[layerIdx];}
+  Void      setVertPhasePositionFlag (Bool b, UInt layerIdx)      {  m_vertPhasePositionFlag[layerIdx] = b;  }
+#endif
+
   Void      setNumMotionPredRefLayers(int i)            { m_numMotionPredRefLayers = i; }
   Int       getNumMotionPredRefLayers()                 { return m_numMotionPredRefLayers; }
Index: branches/SHM-5.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- branches/SHM-5.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 625)
+++ branches/SHM-5.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 627)
@@ -126,4 +126,13 @@
   Int heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
   Int strideEL  = pcUsPic->getStride();
+
+#if P0312_VERT_PHASE_ADJ
+  Bool vertPhasePositionEnableFlag = scalEL.getVertPhasePositionEnableFlag();
+  Bool vertPhasePositionFlag = scalEL.getVertPhasePositionFlag();
+  if (vertPhasePositionFlag)
+  {
+    assert (vertPhasePositionEnableFlag);
+  }
+#endif
 
   Pel* piTempBufY = pcTempPic->getLumaAddr();
@@ -219,8 +228,16 @@
 #if O0215_PHASE_ALIGNMENT //for Luma, if Phase 0, then both PhaseX  and PhaseY should be 0. If symmetric: both PhaseX and PhaseY should be 2
     Int   phaseX = 2*phaseAlignFlag;
+#if P0312_VERT_PHASE_ADJ
+    Int   phaseY = (vertPhasePositionEnableFlag?(vertPhasePositionFlag *4):(2*phaseAlignFlag));
+#else
     Int   phaseY = 2*phaseAlignFlag;
+#endif
 #else
     Int   phaseX = 0;
+#if P0312_VERT_PHASE_ADJ
+    Int   phaseY = (vertPhasePositionEnableFlag?(vertPhasePositionFlag *4):(0));
+#else
     Int   phaseY = 0;
+#endif
 #endif
 
@@ -363,32 +380,29 @@
 
 #if O0215_PHASE_ALIGNMENT
+    Int phaseXC = phaseAlignFlag;
+#if P0312_VERT_PHASE_ADJ
+    Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4):(phaseAlignFlag + 1);
+#else
+    Int phaseYC = phaseAlignFlag + 1;
+#endif
+#else
     Int phaseXC = 0;
+#if P0312_VERT_PHASE_ADJ
+    Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4): 1;;
+#else
     Int phaseYC = 1;
-
+#endif
+#endif
+    
 #if ROUNDING_OFFSET
-    addX       = ( ( (phaseXC+phaseAlignFlag) * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( (phaseYC+phaseAlignFlag) * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
-#else
-    addX       = ( ( ( widthBL * (phaseXC+phaseAlignFlag) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( ( heightBL * (phaseYC+phaseAlignFlag) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
-
-    deltaX     = 4 * (phaseXC+phaseAlignFlag);
-    deltaY     = 4 * (phaseYC+phaseAlignFlag);
-#else
-    phaseX = 0;
-    phaseY = 1;
-
-#if ROUNDING_OFFSET
-    addX       = ( ( phaseX * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( phaseY * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
-#else
-    addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
-
-    deltaX     = 4 * phaseX;
-    deltaY     = 4 * phaseY;
-#endif
+    addX       = ( ( phaseXC * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( phaseYC * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
+#else
+    addX       = ( ( ( widthBL * (phaseXC) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( ( heightBL * (phaseYC) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+#endif
+
+    deltaX     = 4 * phaseXC;
+    deltaY     = 4 * phaseYC;
 
     shiftXM4 = shiftX - 4;
Index: branches/SHM-5.1-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/SHM-5.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 625)
+++ branches/SHM-5.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 627)
@@ -50,4 +50,5 @@
 #define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
 
+#define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
 #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
