Index: /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 633)
@@ -396,5 +396,5 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
-  #if P0312_VERT_PHASE_ADJ
+#if P0312_VERT_PHASE_ADJ
   string*    cfg_vertPhasePositionEnableFlagPtr[MAX_LAYERS];
 #endif
@@ -458,12 +458,12 @@
     {
 #if O0098_SCALED_REF_LAYER_ID
-      cfg_scaledRefLayerIdPtr          [layer] = &cfg_scaledRefLayerId[layer]          ;
-#endif
-      cfg_scaledRefLayerLeftOffsetPtr  [layer] = &cfg_scaledRefLayerLeftOffset[layer]  ;
-      cfg_scaledRefLayerTopOffsetPtr   [layer] = &cfg_scaledRefLayerTopOffset[layer]   ;
-      cfg_scaledRefLayerRightOffsetPtr [layer] = &cfg_scaledRefLayerRightOffset[layer] ;
+      cfg_scaledRefLayerIdPtr          [layer] = &cfg_scaledRefLayerId[layer];
+#endif
+      cfg_scaledRefLayerLeftOffsetPtr  [layer] = &cfg_scaledRefLayerLeftOffset[layer];
+      cfg_scaledRefLayerTopOffsetPtr   [layer] = &cfg_scaledRefLayerTopOffset[layer];
+      cfg_scaledRefLayerRightOffsetPtr [layer] = &cfg_scaledRefLayerRightOffset[layer];
       cfg_scaledRefLayerBottomOffsetPtr[layer] = &cfg_scaledRefLayerBottomOffset[layer];
 #if P0312_VERT_PHASE_ADJ
-      cfg_vertPhasePositionEnableFlagPtr [layer]   = &cfg_vertPhasePositionEnableFlag[layer] ;
+      cfg_vertPhasePositionEnableFlagPtr[layer] = &cfg_vertPhasePositionEnableFlag[layer];
 #endif
     }
Index: /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 633)
@@ -61,5 +61,5 @@
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
 #if P0312_VERT_PHASE_ADJ 
-  ::memset(m_vertPhasePositionEnableFlag,    0, sizeof(m_vertPhasePositionEnableFlag));
+  ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
 #endif
 }
Index: /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 633)
@@ -571,7 +571,7 @@
 #endif
 #if P0312_VERT_PHASE_ADJ
-        m_acTEncTop[layer].setVertPhasePositionEnableFlag( i, m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i]);
+        m_acTEncTop[layer].setVertPhasePositionEnableFlag( i, m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
         m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
-                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i], m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i], false);
+                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i], m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
 #else
         m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
@@ -1359,4 +1359,20 @@
 #endif
 
+#if P0312_VERT_PHASE_ADJ
+  Bool vpsVuiVertPhaseInUseFlag = false;
+  for( UInt layerId = 1; layerId < m_numLayers; layerId++ )
+  {
+    for(Int i = 0; i < m_acLayerCfg[layerId].m_numScaledRefLayerOffsets; i++)
+    {
+      if( m_acTEncTop[layerId].getVertPhasePositionEnableFlag(i) )
+      {
+        vpsVuiVertPhaseInUseFlag = true;
+        break;
+      }
+    }
+  }
+  vps->setVpsVuiVertPhaseInUseFlag( vpsVuiVertPhaseInUseFlag );
+#endif
+
 #if O0164_MULTI_LAYER_HRD
   vps->setVpsVuiBspHrdPresentFlag(false);
Index: /branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 633)
@@ -569,5 +569,5 @@
 #endif
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
-  Bool       m_crossLayerAlignedIdrOnlyFlag;;
+  Bool       m_crossLayerAlignedIdrOnlyFlag;
 #endif
 #if O0225_MAX_TID_FOR_REF_LAYERS
@@ -602,32 +602,32 @@
 #endif 
 #if N0160_VUI_EXT_ILP_REF    
-  Bool        m_ilpRestrictedRefLayersFlag;
-  Int         m_minSpatialSegmentOffsetPlus1[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  Int         m_minHorizontalCtuOffsetPlus1 [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Bool       m_ilpRestrictedRefLayersFlag;
+  Int        m_minSpatialSegmentOffsetPlus1[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Bool       m_ctuBasedOffsetEnabledFlag   [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int        m_minHorizontalCtuOffsetPlus1 [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
 #endif 
 #if VPS_VUI_VIDEO_SIGNAL
-  Bool        m_vidSigPresentVpsFlag;
-  Int         m_vpsVidSigInfo;
-  Int         m_vpsVidSigIdx[MAX_VPS_LAYER_ID_PLUS1];
-  Int         m_vpsVidFormat[16];
-  Bool        m_vpsFullRangeFlag[16];
-  Int         m_vpsColorPrimaries[16];
-  Int         m_vpsTransChar[16];
-  Int         m_vpsMatCoeff[16];
+  Bool       m_vidSigPresentVpsFlag;
+  Int        m_vpsVidSigInfo;
+  Int        m_vpsVidSigIdx[MAX_VPS_LAYER_ID_PLUS1];
+  Int        m_vpsVidFormat[16];
+  Bool       m_vpsFullRangeFlag[16];
+  Int        m_vpsColorPrimaries[16];
+  Int        m_vpsTransChar[16];
+  Int        m_vpsMatCoeff[16];
 #endif 
 #if VPS_VUI_BITRATE_PICRATE
-  Bool        m_bitRatePresentVpsFlag;
-  Bool        m_picRatePresentVpsFlag;
-  Bool        m_bitRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Bool        m_picRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_avgBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_maxBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_constPicRateIdc     [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Bool       m_bitRatePresentVpsFlag;
+  Bool       m_picRatePresentVpsFlag;
+  Bool       m_bitRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Bool       m_picRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_avgBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_maxBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_constPicRateIdc     [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
 #endif
   
 #if P0312_VERT_PHASE_ADJ
-  Bool        m_vpsVuiVertPhaseInUseFlag;
+  Bool       m_vpsVuiVertPhaseInUseFlag;
 #endif
 
@@ -647,9 +647,9 @@
 #if VIEW_ID_RELATED_SIGNALING 
 #if O0109_VIEW_ID_LEN
-  Int         m_viewIdLen;
+  Int        m_viewIdLen;
 #else
-  Int         m_viewIdLenMinus1;
-#endif
-  Int         m_viewIdVal                [MAX_LAYERS];
+  Int        m_viewIdLenMinus1;
+#endif
+  Int        m_viewIdVal                [MAX_LAYERS];
 #endif
 
@@ -663,19 +663,19 @@
 #endif
 #if SPS_DPB_PARAMS
-    Int         m_TolsIdx;
+  Int        m_TolsIdx;
 #endif
 #if VPS_DPB_SIZE_TABLE
-  Bool    m_subLayerFlagInfoPresentFlag [MAX_VPS_OP_LAYER_SETS_PLUS1];
-  Bool    m_subLayerDpbInfoPresentFlag  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
-  Int     m_maxVpsDecPicBufferingMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];
+  Bool       m_subLayerFlagInfoPresentFlag [MAX_VPS_OP_LAYER_SETS_PLUS1];
+  Bool       m_subLayerDpbInfoPresentFlag  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_maxVpsDecPicBufferingMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];
 #if RESOLUTION_BASED_DPB
-  Int     m_maxVpsLayerDecPicBuffMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];  
-#endif
-  Int     m_maxVpsNumReorderPics        [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
-  Int     m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_maxVpsLayerDecPicBuffMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];  
+#endif
+  Int        m_maxVpsNumReorderPics        [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
 #if CHANGE_NUMSUBDPB_IDX
-  Int     m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
+  Int        m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
 #else
-  Int     m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
+  Int        m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
 #endif
 #endif
@@ -698,19 +698,19 @@
 
 #if P0182_VPS_VUI_PS_FLAG
-  UInt        m_SPSId[MAX_LAYERS];
-  UInt        m_PPSId[MAX_LAYERS];
-  UInt        m_baseLayerPSCompatibilityFlag[MAX_LAYERS];
+  UInt       m_SPSId[MAX_LAYERS];
+  UInt       m_PPSId[MAX_LAYERS];
+  UInt       m_baseLayerPSCompatibilityFlag[MAX_LAYERS];
 #endif
 
 #if !P0307_REMOVE_VPS_VUI_OFFSET
 #if VPS_VUI_OFFSET
-  Int     m_vpsVuiOffset;
+  Int        m_vpsVuiOffset;
 #endif
 #endif
 #if P0307_VPS_NON_VUI_EXTENSION
-  Int     m_vpsNonVuiExtLength;
+  Int        m_vpsNonVuiExtLength;
 #endif
 #if RESOLUTION_BASED_DPB
-  Int     m_subDpbAssigned            [MAX_VPS_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_subDpbAssigned            [MAX_VPS_LAYER_SETS_PLUS1][MAX_LAYERS];
 #endif
 #endif //SVC_EXTENSION
@@ -943,8 +943,8 @@
 #endif 
 #if VPS_TSLAYERS
-    Bool   getMaxTSLayersPresentFlag()                                  { return m_maxTSLayersPresentFlag ;}
-    Void   setMaxTSLayersPresentFlag(Bool x)                            { m_maxTSLayersPresentFlag = x;}
-    UInt   getMaxTSLayersMinus1(Int layerId)                            { return m_maxTSLayerMinus1[layerId];}
-    Void   setMaxTSLayersMinus1(Int layerId, UInt maxTSublayer)         { m_maxTSLayerMinus1[layerId] = maxTSublayer;}
+  Bool   getMaxTSLayersPresentFlag()                                  { return m_maxTSLayersPresentFlag ;}
+  Void   setMaxTSLayersPresentFlag(Bool x)                            { m_maxTSLayersPresentFlag = x;}
+  UInt   getMaxTSLayersMinus1(Int layerId)                            { return m_maxTSLayerMinus1[layerId];}
+  Void   setMaxTSLayersMinus1(Int layerId, UInt maxTSublayer)         { m_maxTSLayerMinus1[layerId] = maxTSublayer;}
 #endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -975,54 +975,54 @@
 #endif 
 #if N0160_VUI_EXT_ILP_REF  
-  Bool  getIlpRestrictedRefLayersFlag   ( )                                        { return m_ilpRestrictedRefLayersFlag        ;}
-  Void  setIlpRestrictedRefLayersFlag   ( Int val )                                { m_ilpRestrictedRefLayersFlag         = val;}
-  
-  Int  getMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId )          { return m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId];}
-  Void setMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId, Int val ) { m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId] = val;}
-  
-  Bool getCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId )            { return m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId];}
-  Void setCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId, Bool flag ) { m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId] = flag;}
-  
-  Int  getMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId )            { return m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId];}
-  Void setMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId, Int val )   { m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId] = val;}  
+  Bool   getIlpRestrictedRefLayersFlag   ( )                                        { return m_ilpRestrictedRefLayersFlag        ;}
+  Void   setIlpRestrictedRefLayersFlag   ( Int val )                                { m_ilpRestrictedRefLayersFlag         = val;}
+  
+  Int    getMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId )          { return m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId];}
+  Void   setMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId, Int val ) { m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId] = val;}
+  
+  Bool   getCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId )            { return m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId];}
+  Void   setCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId, Bool flag ) { m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId] = flag;}
+  
+  Int    getMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId )            { return m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId];}
+  Void   setMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId, Int val )   { m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId] = val;}  
 #endif
 #if VPS_VUI_VIDEO_SIGNAL
-    Bool   getVideoSigPresentVpsFlag()           { return m_vidSigPresentVpsFlag; }
-    Void   setVideoSigPresentVpsFlag(Bool x)     { m_vidSigPresentVpsFlag = x;    }
-    Int    getNumVideoSignalInfo()               { return m_vpsVidSigInfo;        }
-    Void   setNumVideoSignalInfo(Int x)          { m_vpsVidSigInfo = x;           }
-    Int    getVideoSignalInfoIdx(Int idx)        { return m_vpsVidSigIdx[idx];    }
-    Void   setVideoSignalInfoIdx(Int idx, Int x) { m_vpsVidSigIdx[idx] = x;       }
-    Int    getVideoVPSFormat(Int idx)            { return m_vpsVidFormat[idx];    }
-    Void   setVideoVPSFormat(Int idx, Int x)     { m_vpsVidFormat[idx] = x;       }
-    Bool   getVideoFullRangeVpsFlag(Int idx)     { return m_vpsFullRangeFlag[idx];}
-    Void   setVideoFullRangeVpsFlag(Int idx, Bool x) { m_vpsFullRangeFlag[idx] = x;   }
-    Int    getColorPrimaries(Int idx)            { return m_vpsColorPrimaries[idx];   }
-    Void   setColorPrimaries(Int idx, Int x)     { m_vpsColorPrimaries[idx] = x;      }
-    Int    getTransCharacter(Int idx)            { return m_vpsTransChar[idx];    }
-    Void   setTransCharacter(Int idx, Int x)     { m_vpsTransChar[idx] = x;       }
-    Int    getMaxtrixCoeff(Int idx)              { return m_vpsMatCoeff[idx];     }
-    Void   setMaxtrixCoeff(Int idx, Int x)       { m_vpsMatCoeff[idx] = x;        }
+  Bool   getVideoSigPresentVpsFlag()           { return m_vidSigPresentVpsFlag; }
+  Void   setVideoSigPresentVpsFlag(Bool x)     { m_vidSigPresentVpsFlag = x;    }
+  Int    getNumVideoSignalInfo()               { return m_vpsVidSigInfo;        }
+  Void   setNumVideoSignalInfo(Int x)          { m_vpsVidSigInfo = x;           }
+  Int    getVideoSignalInfoIdx(Int idx)        { return m_vpsVidSigIdx[idx];    }
+  Void   setVideoSignalInfoIdx(Int idx, Int x) { m_vpsVidSigIdx[idx] = x;       }
+  Int    getVideoVPSFormat(Int idx)            { return m_vpsVidFormat[idx];    }
+  Void   setVideoVPSFormat(Int idx, Int x)     { m_vpsVidFormat[idx] = x;       }
+  Bool   getVideoFullRangeVpsFlag(Int idx)     { return m_vpsFullRangeFlag[idx];}
+  Void   setVideoFullRangeVpsFlag(Int idx, Bool x) { m_vpsFullRangeFlag[idx] = x;   }
+  Int    getColorPrimaries(Int idx)            { return m_vpsColorPrimaries[idx];   }
+  Void   setColorPrimaries(Int idx, Int x)     { m_vpsColorPrimaries[idx] = x;      }
+  Int    getTransCharacter(Int idx)            { return m_vpsTransChar[idx];    }
+  Void   setTransCharacter(Int idx, Int x)     { m_vpsTransChar[idx] = x;       }
+  Int    getMaxtrixCoeff(Int idx)              { return m_vpsMatCoeff[idx];     }
+  Void   setMaxtrixCoeff(Int idx, Int x)       { m_vpsMatCoeff[idx] = x;        }
 #endif
 #if VPS_VUI_BITRATE_PICRATE
-  Bool getBitRatePresentVpsFlag()       { return m_bitRatePresentVpsFlag; }
-  Void setBitRatePresentVpsFlag(Bool x) { m_bitRatePresentVpsFlag = x;    }
-  Bool getPicRatePresentVpsFlag()       { return m_picRatePresentVpsFlag; }
-  Void setPicRatePresentVpsFlag(Bool x) { m_picRatePresentVpsFlag = x;    }
-
-  Bool getBitRatePresentFlag(Int i, Int j)          { return m_bitRatePresentFlag[i][j]; }
-  Void setBitRatePresentFlag(Int i, Int j, Bool x)  { m_bitRatePresentFlag[i][j] = x;    }
-  Bool getPicRatePresentFlag(Int i, Int j)          { return m_picRatePresentFlag[i][j]; }
-  Void setPicRatePresentFlag(Int i, Int j, Bool x)  { m_picRatePresentFlag[i][j] = x;    }
-  
-  Int  getAvgBitRate(Int i, Int j)          { return m_avgBitRate[i][j]; }
-  Void setAvgBitRate(Int i, Int j, Int x)   { m_avgBitRate[i][j] = x;    }
-  Int  getMaxBitRate(Int i, Int j)          { return m_maxBitRate[i][j]; }
-  Void setMaxBitRate(Int i, Int j, Int x)   { m_maxBitRate[i][j] = x;    }
-  
-  Int  getConstPicRateIdc(Int i, Int j)          { return m_constPicRateIdc[i][j]; }
-  Void setConstPicRateIdc(Int i, Int j, Int x)   { m_constPicRateIdc[i][j] = x;    }
-  Int  getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
-  Void setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
+  Bool   getBitRatePresentVpsFlag()       { return m_bitRatePresentVpsFlag; }
+  Void   setBitRatePresentVpsFlag(Bool x) { m_bitRatePresentVpsFlag = x;    }
+  Bool   getPicRatePresentVpsFlag()       { return m_picRatePresentVpsFlag; }
+  Void   setPicRatePresentVpsFlag(Bool x) { m_picRatePresentVpsFlag = x;    }
+         
+  Bool   getBitRatePresentFlag(Int i, Int j)          { return m_bitRatePresentFlag[i][j]; }
+  Void   setBitRatePresentFlag(Int i, Int j, Bool x)  { m_bitRatePresentFlag[i][j] = x;    }
+  Bool   getPicRatePresentFlag(Int i, Int j)          { return m_picRatePresentFlag[i][j]; }
+  Void   setPicRatePresentFlag(Int i, Int j, Bool x)  { m_picRatePresentFlag[i][j] = x;    }
+         
+  Int    getAvgBitRate(Int i, Int j)          { return m_avgBitRate[i][j]; }
+  Void   setAvgBitRate(Int i, Int j, Int x)   { m_avgBitRate[i][j] = x;    }
+  Int    getMaxBitRate(Int i, Int j)          { return m_maxBitRate[i][j]; }
+  Void   setMaxBitRate(Int i, Int j, Int x)   { m_maxBitRate[i][j] = x;    }
+         
+  Int    getConstPicRateIdc(Int i, Int j)          { return m_constPicRateIdc[i][j]; }
+  Void   setConstPicRateIdc(Int i, Int j, Int x)   { m_constPicRateIdc[i][j] = x;    }
+  Int    getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
+  Void   setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
 #endif
 #if O0164_MULTI_LAYER_HRD
@@ -1046,15 +1046,15 @@
 #endif
 #if P0182_VPS_VUI_PS_FLAG
-  Int     getSPSId       (Int layer)                   { return m_SPSId[layer];          }
-  Void    setSPSId       (Int layer, Int val)            { m_SPSId[layer] = val;             }
-  Int     getPPSId       (Int layer)                   { return m_PPSId[layer];          }
-  Void    setPPSId       (Int layer, Int val)            { m_PPSId[layer] = val;             }
-  Void    setBaseLayerPSCompatibilityFlag (Int layer, int val)        { m_baseLayerPSCompatibilityFlag[layer] = val; }
-  Int     getBaseLayerPSCompatibilityFlag (Int layer)   { return m_baseLayerPSCompatibilityFlag[layer];}
+  Int    getSPSId       (Int layer)                   { return m_SPSId[layer];       }
+  Void   setSPSId       (Int layer, Int val)          { m_SPSId[layer] = val;        }
+  Int    getPPSId       (Int layer)                   { return m_PPSId[layer];       }
+  Void   setPPSId       (Int layer, Int val)          { m_PPSId[layer] = val;        }
+  Void   setBaseLayerPSCompatibilityFlag (Int layer, int val)        { m_baseLayerPSCompatibilityFlag[layer] = val; }
+  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;    }
+  Bool   getVpsVuiVertPhaseInUseFlag()       { return m_vpsVuiVertPhaseInUseFlag; }
+  Void   setVpsVuiVertPhaseInUseFlag(Bool x) { m_vpsVuiVertPhaseInUseFlag = x;    }
 #endif
 
@@ -1077,29 +1077,29 @@
   RepFormat* getVpsRepFormat(Int idx)       { return &m_vpsRepFormat[idx];      }
 
-  Int    getVpsRepFormatIdx(Int idx)        { return m_vpsRepFormatIdx[idx];   }
-  Void   setVpsRepFormatIdx(Int idx, Int x) { m_vpsRepFormatIdx[idx] = x;      }         
+  Int    getVpsRepFormatIdx(Int idx)        { return m_vpsRepFormatIdx[idx];    }
+  Void   setVpsRepFormatIdx(Int idx, Int x) { m_vpsRepFormatIdx[idx] = x;       }         
 #endif
 #if VIEW_ID_RELATED_SIGNALING
 #if O0109_VIEW_ID_LEN
-  Void    setViewIdLen( Int  val )                                   { m_viewIdLen = val; } 
-  Int     getViewIdLen(  )                                           { return m_viewIdLen; } 
+  Void   setViewIdLen( Int  val )                                   { m_viewIdLen = val;  } 
+  Int    getViewIdLen(  )                                           { return m_viewIdLen; } 
 #else
-  Void    setViewIdLenMinus1( Int  val )                                   { m_viewIdLenMinus1 = val; } 
-  Int     getViewIdLenMinus1(  )                                           { return m_viewIdLenMinus1; } 
-#endif
-
-  Void    setViewIdVal( Int viewOrderIndex, Int  val )                     { m_viewIdVal[viewOrderIndex] = val; } 
-  Int     getViewIdVal( Int viewOrderIndex )                               { return m_viewIdVal[viewOrderIndex]; } 
-  Int     getScalabilityId(Int, ScalabilityType scalType );
-
-  Int     getViewIndex    ( Int layerIdInNuh )                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
-
-  Int     getNumViews();
-  Int     scalTypeToScalIdx( ScalabilityType scalType );
+  Void   setViewIdLenMinus1( Int  val )                             { m_viewIdLenMinus1 = val;  } 
+  Int    getViewIdLenMinus1(  )                                     { return m_viewIdLenMinus1; } 
+#endif
+
+  Void   setViewIdVal( Int viewOrderIndex, Int  val )               { m_viewIdVal[viewOrderIndex] = val;  } 
+  Int    getViewIdVal( Int viewOrderIndex )                         { return m_viewIdVal[viewOrderIndex]; } 
+  Int    getScalabilityId(Int, ScalabilityType scalType );
+
+  Int    getViewIndex    ( Int layerIdInNuh )                       { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
+
+  Int    getNumViews();
+  Int    scalTypeToScalIdx( ScalabilityType scalType );
 #endif
 #if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
 #if VPS_EXTN_OFFSET
-  Int     getExtensionOffset()                 { return m_extensionOffset;   }
-  Void    setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
+  Int    getExtensionOffset()                 { return m_extensionOffset;   }
+  Void   setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
 #endif
 #endif
@@ -1109,28 +1109,28 @@
 #endif
 #if VPS_DPB_SIZE_TABLE
-  Bool    getSubLayerFlagInfoPresentFlag(Int i)         {return m_subLayerFlagInfoPresentFlag[i]; }
-  Void    setSubLayerFlagInfoPresentFlag(Int i, Bool x) {m_subLayerFlagInfoPresentFlag[i] = x;    }
-
-  Bool    getSubLayerDpbInfoPresentFlag(Int i, Int j)         {return m_subLayerDpbInfoPresentFlag[i][j]; }
-  Void    setSubLayerDpbInfoPresentFlag(Int i, Int j, Bool x) {m_subLayerDpbInfoPresentFlag[i][j] = x;    }
+  Bool   getSubLayerFlagInfoPresentFlag(Int i)         {return m_subLayerFlagInfoPresentFlag[i]; }
+  Void   setSubLayerFlagInfoPresentFlag(Int i, Bool x) {m_subLayerFlagInfoPresentFlag[i] = x;    }
+
+  Bool   getSubLayerDpbInfoPresentFlag(Int i, Int j)         {return m_subLayerDpbInfoPresentFlag[i][j]; }
+  Void   setSubLayerDpbInfoPresentFlag(Int i, Int j, Bool x) {m_subLayerDpbInfoPresentFlag[i][j] = x;    }
 
   // For the 0-th output layer set, use the date from the active SPS for base layer.
-  Int     getMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j)         { assert(i != 0); return m_maxVpsDecPicBufferingMinus1[i][k][j]; }
-  Void    setMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j, Int x) { m_maxVpsDecPicBufferingMinus1[i][k][j] = x;    }
+  Int    getMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j)         { assert(i != 0); return m_maxVpsDecPicBufferingMinus1[i][k][j]; }
+  Void   setMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j, Int x) { m_maxVpsDecPicBufferingMinus1[i][k][j] = x;    }
 
 #if RESOLUTION_BASED_DPB
-  Int     getMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j)        { assert(i != 0); return m_maxVpsLayerDecPicBuffMinus1[i][k][j]; }
-  Void    setMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j, Int x) { m_maxVpsLayerDecPicBuffMinus1[i][k][j] = x;    }
-#endif
-
-  Int     getMaxVpsNumReorderPics(Int i, Int j)         { assert(i != 0); return m_maxVpsNumReorderPics[i][j]; }
-  Void    setMaxVpsNumReorderPics(Int i, Int j, Int x) { m_maxVpsNumReorderPics[i][j] = x;    }
-
-  Int     getMaxVpsLatencyIncreasePlus1(Int i, Int j)         { assert(i != 0); return m_maxVpsLatencyIncreasePlus1[i][j]; }
-  Void    setMaxVpsLatencyIncreasePlus1(Int i, Int j, Int x) { m_maxVpsLatencyIncreasePlus1[i][j] = x;    }
-
-  Int     getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
-  Void    setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
-  Void    determineSubDpbInfoFlags();
+  Int    getMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j)        { assert(i != 0); return m_maxVpsLayerDecPicBuffMinus1[i][k][j]; }
+  Void   setMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j, Int x) { m_maxVpsLayerDecPicBuffMinus1[i][k][j] = x;    }
+#endif
+
+  Int    getMaxVpsNumReorderPics(Int i, Int j)        { assert(i != 0); return m_maxVpsNumReorderPics[i][j]; }
+  Void   setMaxVpsNumReorderPics(Int i, Int j, Int x) { m_maxVpsNumReorderPics[i][j] = x;    }
+
+  Int    getMaxVpsLatencyIncreasePlus1(Int i, Int j)        { assert(i != 0); return m_maxVpsLatencyIncreasePlus1[i][j]; }
+  Void   setMaxVpsLatencyIncreasePlus1(Int i, Int j, Int x) { m_maxVpsLatencyIncreasePlus1[i][j] = x;    }
+
+  Int    getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
+  Void   setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
+  Void   determineSubDpbInfoFlags();
 #endif
 
@@ -1142,16 +1142,16 @@
 #if !P0307_REMOVE_VPS_VUI_OFFSET
 #if VPS_VUI_OFFSET
-  Int     getVpsVuiOffset()         { return m_vpsVuiOffset; }
-  Void    setVpsVuiOffset(Int x)    { m_vpsVuiOffset = x; }
+  Int    getVpsVuiOffset()         { return m_vpsVuiOffset; }
+  Void   setVpsVuiOffset(Int x)    { m_vpsVuiOffset = x; }
 #endif
 #endif
 #if P0307_VPS_NON_VUI_EXTENSION
-  Int     getVpsNonVuiExtLength()         { return m_vpsNonVuiExtLength; }
-  Void    setVpsNonVuiExtLength(Int x)    { m_vpsNonVuiExtLength = x; }
+  Int    getVpsNonVuiExtLength()         { return m_vpsNonVuiExtLength; }
+  Void   setVpsNonVuiExtLength(Int x)    { m_vpsNonVuiExtLength = x; }
 #endif
 #if RESOLUTION_BASED_DPB
-  Void assignSubDpbIndices();
-  Int  getSubDpbAssigned  (Int lsIdx, Int layerIdx) { return m_subDpbAssigned[lsIdx][layerIdx]; }
-  Int  findLayerIdxInLayerSet ( Int lsIdx, Int nuhLayerId );
+  Void   assignSubDpbIndices();
+  Int    getSubDpbAssigned  (Int lsIdx, Int layerIdx) { return m_subDpbAssigned[lsIdx][layerIdx]; }
+  Int    findLayerIdxInLayerSet ( Int lsIdx, Int nuhLayerId );
 #endif
 #if O0164_MULTI_LAYER_HRD
@@ -1171,5 +1171,4 @@
 #if P0312_VERT_PHASE_ADJ
   Bool          m_vertPhasePositionEnableFlag;
-  Bool          m_vertPhasePositionFlag;
 #endif
 public:
@@ -1181,6 +1180,5 @@
   , m_winBottomOffset   (0)
 #if P0312_VERT_PHASE_ADJ
-  , m_vertPhasePositionEnableFlag(false)
-  , m_vertPhasePositionFlag(false)
+  , m_vertPhasePositionEnableFlag(false)  
 #endif
   { }
@@ -1188,5 +1186,5 @@
   Bool          getWindowEnabledFlag() const      { return m_enabledFlag; }
 #if P0312_VERT_PHASE_ADJ 
-  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; m_vertPhasePositionEnableFlag = m_vertPhasePositionFlag = false;} 
+  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; m_vertPhasePositionEnableFlag = false; } 
 #else
   Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0;} 
@@ -1202,11 +1200,7 @@
 
 #if P0312_VERT_PHASE_ADJ
-  Bool          getVertPhasePositionEnableFlag() const     { return m_vertPhasePositionEnableFlag ; }
+  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)
+  Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom, Bool vertPhasePositionEnableFlag = 0)
 #else
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom)
@@ -1219,6 +1213,5 @@
     m_winBottomOffset   = offsetLBottom;
 #if P0312_VERT_PHASE_ADJ
-    m_vertPhasePositionEnableFlag = vertPhasePositionEnableFlag;
-    m_vertPhasePositionFlag = phasePosFlag;
+    m_vertPhasePositionEnableFlag = vertPhasePositionEnableFlag;    
 #endif
   }
@@ -1471,5 +1464,5 @@
 
 #if SVC_EXTENSION
-  UInt m_layerId;
+  UInt        m_layerId;
   UInt        m_numScaledRefLayerOffsets;
 #if P0312_VERT_PHASE_ADJ
@@ -1481,12 +1474,12 @@
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
 #if REPN_FORMAT_IN_VPS
-  Bool m_updateRepFormatFlag;
+  Bool        m_updateRepFormatFlag;
 #if O0096_REP_FORMAT_INDEX
-  UInt m_updateRepFormatIndex;
+  UInt        m_updateRepFormatIndex;
 #endif
 #endif
 #if SCALINGLIST_INFERRING
-  Bool       m_inferScalingListFlag;
-  UInt       m_scalingListRefLayerId;
+  Bool        m_inferScalingListFlag;
+  UInt        m_scalingListRefLayerId;
 #endif
 #endif //SVC_EXTENSION
@@ -1628,15 +1621,15 @@
 
 #if SVC_EXTENSION
-  Void     setLayerId(UInt layerId) { m_layerId = layerId; }
-  UInt     getLayerId() { return m_layerId; }
-  UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
-  Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
+  Void     setLayerId(UInt layerId)            { m_layerId = layerId; }
+  UInt     getLayerId()                        { return m_layerId;    }
+  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; } 
+  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]; }
-  Void     setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id; }
+  Void     setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
   Window&  getScaledRefLayerWindowForLayer( Int layerId );
 #endif
Index: /branches/SHM-5.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 633)
@@ -129,8 +129,8 @@
 #if P0312_VERT_PHASE_ADJ
   Bool vertPhasePositionEnableFlag = scalEL.getVertPhasePositionEnableFlag();
-  Bool vertPhasePositionFlag = scalEL.getVertPhasePositionFlag();
-  if (vertPhasePositionFlag)
+  Bool vertPhasePositionFlag = currSlice->getVertPhasePositionFlag( refLayerIdc );
+  if( vertPhasePositionFlag )
   {
-    assert (vertPhasePositionEnableFlag);
+    assert( vertPhasePositionEnableFlag );
   }
 #endif
@@ -229,5 +229,5 @@
     Int   phaseX = 2*phaseAlignFlag;
 #if P0312_VERT_PHASE_ADJ
-    Int   phaseY = (vertPhasePositionEnableFlag?(vertPhasePositionFlag *4):(2*phaseAlignFlag));
+    Int   phaseY = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( 2 * phaseAlignFlag );
 #else
     Int   phaseY = 2*phaseAlignFlag;
@@ -382,5 +382,5 @@
     Int phaseXC = phaseAlignFlag;
 #if P0312_VERT_PHASE_ADJ
-    Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4):(phaseAlignFlag + 1);
+    Int phaseYC = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( phaseAlignFlag + 1 );
 #else
     Int phaseYC = phaseAlignFlag + 1;
@@ -389,5 +389,5 @@
     Int phaseXC = 0;
 #if P0312_VERT_PHASE_ADJ
-    Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4): 1;;
+    Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4): 1;
 #else
     Int phaseYC = 1;
Index: /branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 633)
@@ -853,5 +853,5 @@
       Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
 #if O0098_SCALED_REF_LAYER_ID
-      READ_CODE( 6,  uiCode,  "scaled_ref_layer_left_id" );  pcSPS->setScaledRefLayerId( i, uiCode );
+      READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
 #endif
       READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
@@ -860,5 +860,5 @@
       READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
 #if P0312_VERT_PHASE_ADJ
-      READ_FLAG( uiCode, "vert_phase_pos_enable_flag" );scaledWindow.setVertPhasePositionEnableFlag  (uiCode);  pcSPS->setVertPhasePositionEnableFlag(i,uiCode);
+      READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);    
 #endif
     }
@@ -1943,8 +1943,4 @@
 #endif
 
-#if P0312_VERT_PHASE_ADJ
-  READ_FLAG( uiCode, "vps_vui_vert_phase_in_use_flag" ); vps->setVpsVuiVertPhaseInUseFlag(uiCode);
-#endif
-
 #if O0109_O0199_FLAGS_TO_VUI
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -1955,5 +1951,7 @@
 #endif
 #endif
-
+#if P0312_VERT_PHASE_ADJ
+  READ_FLAG( uiCode, "vps_vui_vert_phase_in_use_flag" ); vps->setVpsVuiVertPhaseInUseFlag(uiCode);
+#endif
 #if N0160_VUI_EXT_ILP_REF
   READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vps->setIlpRestrictedRefLayersFlag( uiCode == 1 );
@@ -2539,7 +2537,8 @@
     for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
     {
-      if (rpcSlice->getSPS()->getVertPhasePositionEnableFlag(rpcSlice->getInterLayerPredLayerIdc(i)))
-      {
-        READ_FLAG( uiCode, "phase_pos_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true: false, i);
+      UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
+      if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+      {
+        READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
       }
     }
Index: /branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 633)
@@ -729,4 +729,19 @@
 #endif
 
+#if P0312_VERT_PHASE_ADJ
+  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
+  {    
+    for(Int i = 0; i < activeSPS->getNumScaledRefLayerOffsets(); i++)
+    {
+      UInt scaledRefLayerId = activeSPS->getScaledRefLayerId(i);
+      if( activeSPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
+      {
+        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
+        break;
+      }
+    }
+  }
+#endif
+
   if( pps->getDependentSliceSegmentsEnabledFlag() )
   {
@@ -1467,16 +1482,8 @@
 #endif
 
-#if P0312_VERT_PHASE_ADJ
-#if O0098_SCALED_REF_LAYER_ID
-        Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
-#else
-        Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
-#endif
-#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
 #else
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
-#endif
 #endif
 
@@ -1501,7 +1508,4 @@
           Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
 #endif*/
-#if P0312_VERT_PHASE_ADJ
-          scalEL.setVertPhasePositionFlag (pcSlice->getVertPhasePositionFlag(i));
-#endif
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
Index: /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 633)
@@ -661,5 +661,5 @@
       WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
 #if P0312_VERT_PHASE_ADJ
-      WRITE_FLAG( scaledWindow.getVertPhasePositionEnableFlag(), "vert_phase_pos_enable_flag" ); 
+      WRITE_FLAG( scaledWindow.getVertPhasePositionEnableFlag(), "vert_phase_position_enable_flag" ); 
 #endif
     }
@@ -1460,8 +1460,4 @@
 #endif
 
-#if P0312_VERT_PHASE_ADJ
-    WRITE_FLAG( vps->getVpsVuiVertPhaseInUseFlag(), "vps_vui_vert_phase_in_use_flag" );
-#endif
-
 #if O0109_O0199_FLAGS_TO_VUI
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -1471,4 +1467,7 @@
   WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
 #endif
+#endif
+#if P0312_VERT_PHASE_ADJ
+  WRITE_FLAG( vps->getVpsVuiVertPhaseInUseFlag(), "vps_vui_vert_phase_in_use_flag" );
 #endif
 #if N0160_VUI_EXT_ILP_REF
@@ -1887,7 +1886,8 @@
     for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     {
-      if (pcSlice->getSPS()->getVertPhasePositionEnableFlag(pcSlice->getInterLayerPredLayerIdc(i)))
-      {
-        WRITE_FLAG( pcSlice->getVertPhasePositionFlag(i), "phase_pos_flag" );
+      UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
+      if( pcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+      {
+        WRITE_FLAG( pcSlice->getVertPhasePositionFlag(refLayerIdc), "vert_phase_position_flag" );
       }
     }
Index: /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 633)
@@ -387,5 +387,5 @@
   Window   &getConformanceWindow()                           { return m_conformanceWindow; }
 #if P0312_VERT_PHASE_ADJ 
-  Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom, false, false); }
+  Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom, false); }
 #else
   Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom); }
Index: /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 633)
@@ -795,16 +795,8 @@
         }
 
-#if P0312_VERT_PHASE_ADJ
-#if O0098_SCALED_REF_LAYER_ID
-        Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
-#else
-        Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
-#endif
-#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window &scalEL = m_pcEncTop->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
 #else
         const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
-#endif
 #endif
 
@@ -831,8 +823,7 @@
 #if P0312_VERT_PHASE_ADJ
           //when PhasePositionEnableFlag is equal to 1, set vertPhasePositionFlag to 0 if BL is top field and 1 if bottom
-          if (scalEL.getVertPhasePositionEnableFlag())
+          if( scalEL.getVertPhasePositionEnableFlag() )
           {
-            pcSlice->setVertPhasePositionFlag(pcSlice->getPOC()%2, i);
-            scalEL.setVertPhasePositionFlag (pcSlice->getVertPhasePositionFlag(i));
+            pcSlice->setVertPhasePositionFlag( pcSlice->getPOC()%2, refLayerIdc );
           }
 #endif
Index: /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 633)
@@ -903,5 +903,5 @@
     m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
 #if P0312_VERT_PHASE_ADJ
-    m_cSPS.setVertPhasePositionEnableFlag(i,m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag());
+    m_cSPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() );
 #endif
   }
Index: /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 632)
+++ /branches/SHM-5.1-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 633)
@@ -216,26 +216,26 @@
   /// encode several number of pictures until end-of-sequence
 #if SVC_EXTENSION
-  Void                    setLayerEnc(TEncTop** p) {m_ppcTEncTop = p;}
-  TEncTop**               getLayerEnc()            {return m_ppcTEncTop;}
-  Int                     getPOCLast            () { return m_iPOCLast;               }
-  Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
-  Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
-  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
-  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
+  Void      setLayerEnc(TEncTop** p)            { m_ppcTEncTop = p;                  }
+  TEncTop** getLayerEnc()                       { return m_ppcTEncTop;               }
+  Int       getPOCLast            ()            { return m_iPOCLast;                 }
+  Int       getNumPicRcvd         ()            { return m_iNumPicRcvd;              }
+  Void      setNumPicRcvd         ( Int num )   { m_iNumPicRcvd = num;               }
+  Void      setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x;    }
+  UInt      getNumScaledRefLayerOffsets()       { return m_numScaledRefLayerOffsets; }
 #if O0098_SCALED_REF_LAYER_ID
-  Void                    setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
-  UInt                    getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
-  Window&  getScaledRefLayerWindowForLayer(Int layerId);
-#endif
-  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
+  Void      setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
+  UInt      getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
+  Window&   getScaledRefLayerWindowForLayer(Int layerId);
+#endif
+  Window&   getScaledRefLayerWindow(Int x)                 { return m_scaledRefLayerWindow[x];        }
 #if P0312_VERT_PHASE_ADJ
-  Void                    setVertPhasePositionEnableFlag(Int x, Bool b) { m_vertPhasePositionEnableFlag[x] = b;   }
-  UInt                    getVertPhasePositionEnableFlag(Int x)          { return m_vertPhasePositionEnableFlag[x]; }
+  Void      setVertPhasePositionEnableFlag(Int x, Bool b)  { m_vertPhasePositionEnableFlag[x] = b;    }
+  UInt      getVertPhasePositionEnableFlag(Int x)          { return m_vertPhasePositionEnableFlag[x]; }
 #endif
 
   TComPic** getIlpList() { return m_cIlpPic; }
 #if REF_IDX_MFM
-  Void      setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
-  Bool      getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}    
+  Void      setMFMEnabledFlag       (Bool flag)   { m_bMFMEnabledFlag = flag; }
+  Bool      getMFMEnabledFlag()                   { return m_bMFMEnabledFlag; }    
 #endif
 #if O0194_WEIGHTED_PREDICTION_CGS
@@ -255,6 +255,6 @@
 #endif
 #if POC_RESET_FLAG
-  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
-  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
+  Int       getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
+  Void      setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
 #endif
 #if NO_CLRAS_OUTPUT_FLAG
