Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg	(revision 849)
@@ -22,6 +22,10 @@
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
+
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 4        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg	(revision 849)
@@ -22,6 +22,10 @@
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
+
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 4        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg	(revision 849)
@@ -22,6 +22,10 @@
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
+
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 4        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 4        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg	(revision 849)
@@ -22,6 +22,9 @@
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
-NumScaledRefLayerOffsets1     : 1           # Number of scaled entry offsets for this layer
-ScaledRefLayerId1             : 0           # Scaled reference layer ID
-ScaledRefLayerBottomOffset1   : -4          # offset for spatial alignment of the base and enhancement layers
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 4        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
 QP1                           : 20
Index: /branches/SHM-dev/cfg/per-sequence-svc/BQTerrace-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 849)
@@ -24,2 +24,10 @@
 ConformanceMode1              : 1           # conformance mode
 QP1                           : 20
+
+#============= Reference location offset parameters ==================
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
Index: /branches/SHM-dev/cfg/per-sequence-svc/BasketballDrive-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 849)
@@ -24,2 +24,10 @@
 ConformanceMode1              : 1           # conformance mode
 QP1                           : 20
+
+#============= Reference location offset parameters ==================
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
Index: /branches/SHM-dev/cfg/per-sequence-svc/Cactus-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 849)
@@ -24,2 +24,10 @@
 ConformanceMode1              : 1           # conformance mode
 QP1                           : 20
+
+#============= Reference location offset parameters ==================
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
Index: /branches/SHM-dev/cfg/per-sequence-svc/Kimono-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 849)
@@ -24,2 +24,10 @@
 ConformanceMode1              : 1           # conformance mode
 QP1                           : 20
+
+#============= Reference location offset parameters ==================
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
Index: /branches/SHM-dev/cfg/per-sequence-svc/ParkScene-2x.cfg
===================================================================
--- /branches/SHM-dev/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 848)
+++ /branches/SHM-dev/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 849)
@@ -24,2 +24,10 @@
 ConformanceMode1              : 1           # conformance mode
 QP1                           : 20
+
+#============= Reference location offset parameters ==================
+NumScaledRefLayerOffsets1        : 1        # Number of reference location offset parameters
+ScaledRefLayerId1                : 0        # List of ref layer id (i-th entry for i-th ref loc offset parameters)
+ScaledRefLayerOffsetPresentFlag1 : 0        # List of scaled ref layer offset present flags
+RefRegionOffsetPresentFlag1      : 1        # List of ref region offset present flags
+RefRegionBottomOffset1           : 2        # List of ref region bottom offsets
+ResamplePhaseSetPresentFlag1     : 0        # List of resample phase set present flags
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 848)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 849)
@@ -384,6 +384,22 @@
   string    cfg_scaledRefLayerBottomOffset [MAX_LAYERS];
   Int*      cfg_numScaledRefLayerOffsets[MAX_LAYERS];
+#if REF_REGION_OFFSET
+  string    cfg_scaledRefLayerOffsetPresentFlag [MAX_LAYERS];
+  string    cfg_refRegionOffsetPresentFlag      [MAX_LAYERS];
+  string    cfg_refRegionLeftOffset   [MAX_LAYERS];
+  string    cfg_refRegionTopOffset    [MAX_LAYERS];
+  string    cfg_refRegionRightOffset  [MAX_LAYERS];
+  string    cfg_refRegionBottomOffset [MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  string    cfg_resamplePhaseSetPresentFlag [MAX_LAYERS];
+  string    cfg_phaseHorLuma   [MAX_LAYERS];
+  string    cfg_phaseVerLuma   [MAX_LAYERS];
+  string    cfg_phaseHorChroma [MAX_LAYERS];
+  string    cfg_phaseVerChroma [MAX_LAYERS];
+#else
 #if P0312_VERT_PHASE_ADJ
   string    cfg_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
 #endif
 
@@ -395,4 +411,19 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
+#if REF_REGION_OFFSET
+  string*    cfg_scaledRefLayerOffsetPresentFlagPtr [MAX_LAYERS];
+  string*    cfg_refRegionOffsetPresentFlagPtr      [MAX_LAYERS];
+  string*    cfg_refRegionLeftOffsetPtr   [MAX_LAYERS];
+  string*    cfg_refRegionTopOffsetPtr    [MAX_LAYERS];
+  string*    cfg_refRegionRightOffsetPtr  [MAX_LAYERS];
+  string*    cfg_refRegionBottomOffsetPtr [MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  string*    cfg_resamplePhaseSetPresentFlagPtr [MAX_LAYERS];
+  string*    cfg_phaseHorLumaPtr   [MAX_LAYERS];
+  string*    cfg_phaseVerLumaPtr   [MAX_LAYERS];
+  string*    cfg_phaseHorChromaPtr [MAX_LAYERS];
+  string*    cfg_phaseVerChromaPtr [MAX_LAYERS];
+#endif
 #if P0312_VERT_PHASE_ADJ
   string*    cfg_vertPhasePositionEnableFlagPtr[MAX_LAYERS];
@@ -466,4 +497,19 @@
 #if P0312_VERT_PHASE_ADJ
       cfg_vertPhasePositionEnableFlagPtr[layer] = &cfg_vertPhasePositionEnableFlag[layer];
+#endif
+#if REF_REGION_OFFSET
+      cfg_scaledRefLayerOffsetPresentFlagPtr [layer] = &cfg_scaledRefLayerOffsetPresentFlag [layer];
+      cfg_refRegionOffsetPresentFlagPtr      [layer] = &cfg_refRegionOffsetPresentFlag      [layer];
+      cfg_refRegionLeftOffsetPtr  [layer] = &cfg_refRegionLeftOffset  [layer];
+      cfg_refRegionTopOffsetPtr   [layer] = &cfg_refRegionTopOffset   [layer];
+      cfg_refRegionRightOffsetPtr [layer] = &cfg_refRegionRightOffset [layer];
+      cfg_refRegionBottomOffsetPtr[layer] = &cfg_refRegionBottomOffset[layer];
+#endif
+#if R0209_GENERIC_PHASE
+      cfg_resamplePhaseSetPresentFlagPtr [layer] = &cfg_resamplePhaseSetPresentFlag [layer];
+      cfg_phaseHorLumaPtr   [layer] = &cfg_phaseHorLuma   [layer];
+      cfg_phaseVerLumaPtr   [layer] = &cfg_phaseVerLuma   [layer];
+      cfg_phaseHorChromaPtr [layer] = &cfg_phaseHorChroma [layer];
+      cfg_phaseVerChromaPtr [layer] = &cfg_phaseVerChroma [layer];
 #endif
     }
@@ -597,4 +643,23 @@
   ("ScaledRefLayerBottomOffset%d", cfg_scaledRefLayerBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
   " bottom-right luma sample of the EL picture, in units of two luma samples")
+#if REF_REGION_OFFSET
+  ("ScaledRefLayerOffsetPresentFlag%d",      cfg_scaledRefLayerOffsetPresentFlagPtr,     string(""), MAX_LAYERS, "presense flag of scaled reference layer offsets")
+  ("RefRegionOffsetPresentFlag%d",           cfg_refRegionOffsetPresentFlagPtr,          string(""), MAX_LAYERS, "presense flag of reference region offsets")
+  ("RefRegionLeftOffset%d",   cfg_refRegionLeftOffsetPtr,  string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of ref region with respect to"
+                                                                 " top-left luma sample of the BL picture, in units of two luma samples")
+  ("RefRegionTopOffset%d",    cfg_refRegionTopOffsetPtr,   string(""), MAX_LAYERS,   "Vertical offset of top-left luma sample of ref region with respect to"
+                                                                 " top-left luma sample of the BL picture, in units of two luma samples")
+  ("RefRegionRightOffset%d",  cfg_refRegionRightOffsetPtr, string(""), MAX_LAYERS, "Horizontal offset of bottom-right luma sample of ref region with respect to"
+                                                                 " bottom-right luma sample of the BL picture, in units of two luma samples")
+  ("RefRegionBottomOffset%d", cfg_refRegionBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of ref region with respect to"
+                                                                 " bottom-right luma sample of the BL picture, in units of two luma samples")
+#endif
+#if R0209_GENERIC_PHASE
+  ("ResamplePhaseSetPresentFlag%d",  cfg_resamplePhaseSetPresentFlagPtr, string(""), MAX_LAYERS, "presense flag of resample phase set")
+  ("PhaseHorLuma%d",   cfg_phaseHorLumaPtr,   string(""), MAX_LAYERS, "luma shift in the horizontal direction used in resampling proces")
+  ("PhaseVerLuma%d",   cfg_phaseVerLumaPtr,   string(""), MAX_LAYERS, "luma shift in the vertical   direction used in resampling proces")
+  ("PhaseHorChroma%d", cfg_phaseHorChromaPtr, string(""), MAX_LAYERS, "chroma shift in the horizontal direction used in resampling proces")
+  ("PhaseVerChroma%d", cfg_phaseVerChromaPtr, string(""), MAX_LAYERS, "chroma shift in the vertical   direction used in resampling proces")
+#endif
 #if P0312_VERT_PHASE_ADJ
   ("VertPhasePositionEnableFlag%d", cfg_vertPhasePositionEnableFlagPtr,string(""), MAX_LAYERS, "VertPhasePositionEnableFlag for layer %d")
@@ -1187,4 +1252,26 @@
       assert( strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""));
 #endif
+#if REF_REGION_OFFSET
+      Bool srloFlag =
+        strcmp(cfg_scaledRefLayerLeftOffset   [layer].c_str(), "") ||
+        strcmp(cfg_scaledRefLayerRightOffset  [layer].c_str(), "") ||
+        strcmp(cfg_scaledRefLayerTopOffset    [layer].c_str(), "") ||
+        strcmp(cfg_scaledRefLayerBottomOffset [layer].c_str(), "");
+      Bool rroFlag =
+        strcmp(cfg_refRegionLeftOffset   [layer].c_str(), "") ||
+        strcmp(cfg_refRegionRightOffset  [layer].c_str(), "") ||
+        strcmp(cfg_refRegionTopOffset    [layer].c_str(), "") ||
+        strcmp(cfg_refRegionBottomOffset [layer].c_str(), "");
+#if R0209_GENERIC_PHASE
+      Bool phaseSetFlag =
+        strcmp(cfg_phaseHorLuma   [layer].c_str(), "") ||
+        strcmp(cfg_phaseVerLuma  [layer].c_str(), "") ||
+        strcmp(cfg_phaseHorChroma    [layer].c_str(), "") ||
+        strcmp(cfg_phaseVerChroma [layer].c_str(), "");
+      assert( srloFlag || rroFlag || phaseSetFlag);
+#else
+      assert( srloFlag || rroFlag );
+#endif
+#else
 #if P0312_VERT_PHASE_ADJ
       assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
@@ -1199,4 +1286,5 @@
               strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"") ); 
 #endif
+#endif
     }
 
@@ -1219,4 +1307,20 @@
 #endif
 
+#if REF_REGION_OFFSET
+    // Presense Flag //
+    if(strcmp(cfg_scaledRefLayerOffsetPresentFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerOffsetPresentFlag[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "ScaledRefLayerOffsetPresentFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_scaledRefLayerOffsetPresentFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
+
     // Left offset //
     if(strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  ""))
@@ -1289,5 +1393,150 @@
     }
 #endif
-  }
+#if REF_REGION_OFFSET
+    // Presense Flag //
+    if(strcmp(cfg_refRegionOffsetPresentFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionOffsetPresentFlag[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionOffsetPresentFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionOffsetPresentFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Left offset //
+    if(strcmp(cfg_refRegionLeftOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionLeftOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionLeftOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionLeftOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Top offset //
+    if(strcmp(cfg_refRegionTopOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionTopOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionTopOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionTopOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Right offset //
+    if(strcmp(cfg_refRegionRightOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionRightOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionRightOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionRightOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Bottom offset //
+    if(strcmp(cfg_refRegionBottomOffset[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_refRegionBottomOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RefRegionBottomOffset");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_refRegionBottomOffset[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
+#if R0209_GENERIC_PHASE
+    Int numPhaseSet = m_acLayerCfg[layer].m_numScaledRefLayerOffsets;
+
+    // Presense Flag //
+    if(strcmp(cfg_resamplePhaseSetPresentFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_resamplePhaseSetPresentFlag[layer], numPhaseSet, "resamplePhaseSetPresentFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_resamplePhaseSetPresentFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Luma horizontal phase //
+    if(strcmp(cfg_phaseHorLuma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseHorLuma[layer], numPhaseSet, "phaseHorLuma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseHorLuma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Luma vertical phase //
+    if(strcmp(cfg_phaseVerLuma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseVerLuma[layer], numPhaseSet, "phaseVerLuma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseVerLuma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Chroma horizontal phase //
+    if(strcmp(cfg_phaseHorChroma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseHorChroma[layer], numPhaseSet, "phaseHorChroma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseHorChroma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+
+    // Chroma vertical phase //
+    if(strcmp(cfg_phaseVerChroma[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_phaseVerChroma[layer], numPhaseSet, "phaseVerChroma");
+      if(tempArray)
+      {
+        for(Int i = 0; i < numPhaseSet; i++)
+        {
+          m_acLayerCfg[layer].m_phaseVerChroma[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
+  }
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 848)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 849)
@@ -60,6 +60,22 @@
   ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
+#if REF_REGION_OFFSET
+  ::memset(m_scaledRefLayerOffsetPresentFlag, 0, sizeof(m_scaledRefLayerOffsetPresentFlag));
+  ::memset(m_refRegionOffsetPresentFlag, 0, sizeof(m_refRegionOffsetPresentFlag));
+  ::memset(m_refRegionLeftOffset,   0, sizeof(m_refRegionLeftOffset));
+  ::memset(m_refRegionTopOffset,    0, sizeof(m_refRegionTopOffset));
+  ::memset(m_refRegionRightOffset,  0, sizeof(m_refRegionRightOffset));
+  ::memset(m_refRegionBottomOffset, 0, sizeof(m_refRegionBottomOffset));
+#endif
+#if R0209_GENERIC_PHASE
+  ::memset(m_resamplePhaseSetPresentFlag, 0, sizeof(m_resamplePhaseSetPresentFlag));
+  ::memset(m_phaseHorLuma,   0, sizeof(m_phaseHorLuma));
+  ::memset(m_phaseVerLuma,   0, sizeof(m_phaseVerLuma));
+  ::memset(m_phaseHorChroma, 0, sizeof(m_phaseHorChroma));
+  ::memset(m_phaseVerChroma, 0, sizeof(m_phaseVerChroma));
+#else
 #if P0312_VERT_PHASE_ADJ 
   ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
+#endif
 #endif
 }
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 848)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 849)
@@ -98,6 +98,21 @@
   Int       m_scaledRefLayerRightOffset [MAX_LAYERS];
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
-#if P0312_VERT_PHASE_ADJ 
+#if REF_REGION_OFFSET
+  Bool      m_scaledRefLayerOffsetPresentFlag [MAX_LAYERS];
+  Bool      m_refRegionOffsetPresentFlag      [MAX_LAYERS];
+  Int       m_refRegionLeftOffset  [MAX_LAYERS];
+  Int       m_refRegionTopOffset   [MAX_LAYERS];
+  Int       m_refRegionRightOffset [MAX_LAYERS];
+  Int       m_refRegionBottomOffset[MAX_LAYERS];
+#endif
+#if P0312_VERT_PHASE_ADJ
   Bool      m_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  Int       m_phaseHorLuma  [MAX_LAYERS];
+  Int       m_phaseVerLuma  [MAX_LAYERS];
+  Int       m_phaseHorChroma[MAX_LAYERS];
+  Int       m_phaseVerChroma[MAX_LAYERS];
+  Bool      m_resamplePhaseSetPresentFlag [MAX_LAYERS];
 #endif
 
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 848)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 849)
@@ -351,4 +351,20 @@
         }
       }
+#if REF_REGION_OFFSET
+      for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+      {
+#if AUXILIARY_PICTURES
+        Int cf = m_acLayerCfg[i].m_chromaFormatIDC;
+        Int rlSubWidthC  = ( cf == CHROMA_420 || cf == CHROMA_422 ) ? 2 : 1;
+        Int rlSubHeightC = ( cf == CHROMA_420 ) ? 2 : 1;
+#else
+        Int rlSubWidthC  = 2;
+        Int rlSubHeightC = 2;
+#endif
+        m_acTEncTop[layer].setRefRegionOffsetPresentFlag( i, m_acLayerCfg[layer].m_refRegionOffsetPresentFlag );
+        m_acTEncTop[layer].getRefLayerWindow(i).setWindow( rlSubWidthC  * m_acLayerCfg[layer].m_refRegionLeftOffset[i], rlSubWidthC  * m_acLayerCfg[layer].m_refRegionRightOffset[i],
+                                                           rlSubHeightC * m_acLayerCfg[layer].m_refRegionTopOffset[i],  rlSubHeightC * m_acLayerCfg[layer].m_refRegionBottomOffset[i]);
+      }
+#endif
     }
     else
@@ -622,4 +638,14 @@
     if( layer > 0 )
     {
+#if REF_REGION_OFFSET
+#if AUXILIARY_PICTURES
+      Int cf = m_acLayerCfg[layer].m_chromaFormatIDC;
+      Int subWidthC  = ( cf == CHROMA_420 || cf == CHROMA_422 ) ? 2 : 1;
+      Int subHeightC = ( cf == CHROMA_420 ) ? 2 : 1;
+#else
+      Int subWidthC  = 2;
+      Int subHeightC = 2;
+#endif
+#endif
       m_acTEncTop[layer].setNumScaledRefLayerOffsets( m_acLayerCfg[layer].m_numScaledRefLayerOffsets );
       for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
@@ -628,4 +654,9 @@
         m_acTEncTop[layer].setScaledRefLayerId(i, m_acLayerCfg[layer].m_scaledRefLayerId[i]);
 #endif
+#if REF_REGION_OFFSET
+        m_acTEncTop[layer].setScaledRefLayerOffsetPresentFlag( i, m_acLayerCfg[layer].m_scaledRefLayerOffsetPresentFlag[i] );
+        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( subWidthC  * m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], subWidthC  * m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
+                                                                 subHeightC * m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i],  subHeightC * m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
+#else
 #if P0312_VERT_PHASE_ADJ
         m_acTEncTop[layer].setVertPhasePositionEnableFlag( i, m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
@@ -635,4 +666,12 @@
         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]);
+#endif
+#endif
+#if R0209_GENERIC_PHASE
+        m_acTEncTop[layer].setResamplePhaseSetPresentFlag( i, m_acLayerCfg[layer].m_resamplePhaseSetPresentFlag[i] );
+        m_acTEncTop[layer].setPhaseHorLuma( i, m_acLayerCfg[layer].m_phaseHorLuma[i] );
+        m_acTEncTop[layer].setPhaseVerLuma( i, m_acLayerCfg[layer].m_phaseVerLuma[i] );
+        m_acTEncTop[layer].setPhaseHorChroma( i, m_acLayerCfg[layer].m_phaseHorChroma[i] );
+        m_acTEncTop[layer].setPhaseVerChroma( i, m_acLayerCfg[layer].m_phaseVerChroma[i] );
 #endif
       }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 849)
@@ -3509,4 +3509,13 @@
 #endif
 
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+  Int leftStartL = baseColPic->getSlice(0)->getPPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
+  Int topStartL  = baseColPic->getSlice(0)->getPPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowTopOffset();
+#else
+  Int leftStartL = baseColPic->getSlice(0)->getPPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
+  Int topStartL  = baseColPic->getSlice(0)->getPPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
   Int leftStartL = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindowForLayer(baseColPic->getSlice(0)->getVPS()->getRefLayerId(getSlice()->getLayerId(), refLayerIdc)).getWindowLeftOffset();
@@ -3516,5 +3525,11 @@
   Int topStartL  = baseColPic->getSlice(0)->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
 #endif
-
+#endif
+
+#if REF_REGION_OFFSET
+  const Window &windowRL = baseColPic->getSlice(0)->getPPS()->getRefLayerWindow(refLayerIdc);
+  Int iBX = (((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16) + windowRL.getWindowLeftOffset();
+  Int iBY = (((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16) + windowRL.getWindowTopOffset();
+#else
 #if Q0200_CONFORMANCE_BL_SIZE
   Int chromaFormatIdc = baseColPic->getSlice(0)->getChromaFormatIdc();
@@ -3525,4 +3540,5 @@
   Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
 #endif
+#endif
 
 #if REF_IDX_MFM
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 849)
@@ -796,8 +796,15 @@
 #else
 #if O0194_JOINT_US_BITSHIFT
+#if REF_REGION_OFFSET
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, const Window altRefWindow )
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, altRefWindow );
+}
+#else
 Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
 {
   m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window);
 }
+#endif
 #else
 Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.h	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.h	(revision 849)
@@ -126,5 +126,9 @@
 #else
 #if O0194_JOINT_US_BITSHIFT
+#if REF_REGION_OFFSET
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, const Window altRefWindow );
+#else
   Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#endif
 #else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 849)
@@ -571,8 +571,16 @@
         UInt refLayerId = m_pcVPS->getRefLayerId( m_layerId, refLayerIdc );
 #if RESAMPLING_CONSTRAINT_BUG_FIX
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+        const Window &scalEL = getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
+#else
+        const Window &scalEL = getPPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
 #else
         const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
+#endif
 #endif
         Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) && 
@@ -3061,5 +3069,7 @@
 , m_layerId                   ( 0 )
 , m_extensionFlag             ( false )
+#if !MOVE_SCALED_OFFSET_TO_PPS
 , m_numScaledRefLayerOffsets  ( 0 )
+#endif
 #if REPN_FORMAT_IN_VPS
 , m_updateRepFormatFlag       (false)
@@ -3084,6 +3094,8 @@
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
 
+#if !MOVE_SCALED_OFFSET_TO_PPS
 #if P0312_VERT_PHASE_ADJ 
   ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
+#endif
 #endif
 }
@@ -3217,4 +3229,5 @@
 const Int TComSPS::m_winUnitY[]={1,2,1,1};
 
+#if !MOVE_SCALED_OFFSET_TO_PPS
 #if O0098_SCALED_REF_LAYER_ID
 Window& TComSPS::getScaledRefLayerWindowForLayer(Int layerId)
@@ -3233,4 +3246,22 @@
   return win;
 }
+#endif
+#if REF_REGION_OFFSET
+Window& TComSPS::getRefLayerWindowForLayer(Int layerId)
+{
+  static Window win;
+
+  for (Int i = 0; i < m_numRefLayerOffsets; i++)
+  {
+    if (layerId == m_refLayerId[i])
+    {
+      return m_refLayerWindow[i];
+    }
+  }
+
+  win.resetWindow();  // reference region offsets are inferred to be zero when not present
+  return win;
+}
+#endif
 #endif
 
@@ -3276,4 +3307,7 @@
 , m_pocResetInfoPresentFlag   (false)
 #endif
+#if MOVE_SCALED_OFFSET_TO_PPS
+, m_numScaledRefLayerOffsets  ( 0 )
+#endif
 #if Q0048_CGS_3D_ASYMLUT
 , m_nCGSFlag(0)
@@ -3284,4 +3318,15 @@
 {
   m_scalingList = new TComScalingList;
+#if REF_REGION_OFFSET
+  ::memset(m_scaledRefLayerOffsetPresentFlag,   0, sizeof(m_scaledRefLayerOffsetPresentFlag));
+  ::memset(m_refRegionOffsetPresentFlag,   0, sizeof(m_refRegionOffsetPresentFlag));
+#endif
+#if R0209_GENERIC_PHASE
+  ::memset(m_resamplePhaseSetPresentFlag,   0, sizeof(m_resamplePhaseSetPresentFlag));
+  ::memset(m_phaseHorLuma,   0, sizeof(m_phaseHorLuma));
+  ::memset(m_phaseVerLuma,   0, sizeof(m_phaseVerLuma));
+  ::memset(m_phaseHorChroma, 0, sizeof(m_phaseHorChroma));
+  ::memset(m_phaseVerChroma, 0, sizeof(m_phaseVerChroma));
+#endif
 }
 
@@ -3293,4 +3338,41 @@
   delete m_scalingList;
 }
+
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+Window& TComPPS::getScaledRefLayerWindowForLayer(Int layerId)
+{
+  static Window win;
+
+  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
+  {
+    if (layerId == m_scaledRefLayerId[i])
+    {
+      return m_scaledRefLayerWindow[i];
+    }
+  }
+
+  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
+  return win;
+}
+#endif
+#if REF_REGION_OFFSET
+Window& TComPPS::getRefLayerWindowForLayer(Int layerId)
+{
+  static Window win;
+
+  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
+  {
+    if (layerId == m_scaledRefLayerId[i])
+    {
+      return m_refLayerWindow[i];
+    }
+  }
+
+  win.resetWindow();  // reference region offsets are inferred to be zero when not present
+  return win;
+}
+#endif
+#endif
 
 TComReferencePictureSet::TComReferencePictureSet()
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 849)
@@ -1243,5 +1243,5 @@
 
   Bool          getWindowEnabledFlag() const      { return m_enabledFlag; }
-#if P0312_VERT_PHASE_ADJ 
+#if P0312_VERT_PHASE_ADJ
   Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; m_vertPhasePositionEnableFlag = false; } 
 #else
@@ -1256,8 +1256,10 @@
   Int           getWindowBottomOffset() const     { return m_enabledFlag ? m_winBottomOffset: 0; }
   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;  }
+#endif
+
+#if P0312_VERT_PHASE_ADJ
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom, Bool vertPhasePositionEnableFlag = 0)
 #else
@@ -1532,10 +1534,12 @@
  Bool         m_vertPhasePositionEnableFlag[MAX_LAYERS];
 #endif
+#if !MOVE_SCALED_OFFSET_TO_PPS
 #if O0098_SCALED_REF_LAYER_ID
   UInt        m_scaledRefLayerId[MAX_LAYERS];
 #endif
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
+#endif
 #if REPN_FORMAT_IN_VPS
-  Bool        m_updateRepFormatFlag;
+  Bool m_updateRepFormatFlag;
 #if O0096_REP_FORMAT_INDEX
   UInt        m_updateRepFormatIndex;
@@ -1547,4 +1551,5 @@
 #endif
 #endif //SVC_EXTENSION
+
 public:
   TComSPS();
@@ -1693,4 +1698,5 @@
   Int      getExtensionFlag()                  { return m_extensionFlag;  }
   Void     setExtensionFlag(Int n)             { m_extensionFlag = n;     }
+#if !MOVE_SCALED_OFFSET_TO_PPS
   UInt     getNumScaledRefLayerOffsets()       { return m_numScaledRefLayerOffsets; }
   Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x;    }
@@ -1705,4 +1711,5 @@
 #endif
   Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
+#endif
 #if REPN_FORMAT_IN_VPS
   Bool     getUpdateRepFormatFlag()       { return m_updateRepFormatFlag; }
@@ -1816,4 +1823,23 @@
 #if POC_RESET_IDC
   Bool     m_pocResetInfoPresentFlag;
+#endif
+#if MOVE_SCALED_OFFSET_TO_PPS
+  UInt     m_numScaledRefLayerOffsets;
+#if O0098_SCALED_REF_LAYER_ID
+  UInt     m_scaledRefLayerId[MAX_LAYERS];
+#endif
+  Window   m_scaledRefLayerWindow[MAX_LAYERS];
+#if REF_REGION_OFFSET
+  Window   m_refLayerWindow[MAX_LAYERS];
+  Bool     m_scaledRefLayerOffsetPresentFlag[MAX_LAYERS];
+  Bool     m_refRegionOffsetPresentFlag[MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  Int      m_phaseHorLuma[MAX_LAYERS];
+  Int      m_phaseVerLuma[MAX_LAYERS];
+  Int      m_phaseHorChroma[MAX_LAYERS];
+  Int      m_phaseVerChroma[MAX_LAYERS];
+  Bool     m_resamplePhaseSetPresentFlag[MAX_LAYERS];
+#endif
 #endif
 #if Q0048_CGS_3D_ASYMLUT
@@ -1944,4 +1970,34 @@
   Bool getPocResetInfoPresentFlag   ()                    { return m_pocResetInfoPresentFlag; }
   Void setPocResetInfoPresentFlag   (const Bool val)      { m_pocResetInfoPresentFlag = val; }
+#endif
+#if MOVE_SCALED_OFFSET_TO_PPS
+  UInt     getNumScaledRefLayerOffsets()       { return m_numScaledRefLayerOffsets; }
+  Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x;    }
+#if O0098_SCALED_REF_LAYER_ID
+  UInt     getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
+  Void     setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
+  Window&  getScaledRefLayerWindowForLayer( Int layerId );
+#endif
+  Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
+#if REF_REGION_OFFSET
+  Window&  getRefLayerWindowForLayer( Int layerId );
+  Window&  getRefLayerWindow( Int x )   { return m_refLayerWindow[x]; }
+  Bool getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; }
+  Void setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; }
+  Bool getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; }
+  Void setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; }
+#endif
+#if R0209_GENERIC_PHASE
+  Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; }
+  Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; }
+  Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; }
+  Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; }
+  Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; }
+  Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; }
+  Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; }
+  Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; }
+  Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; }
+  Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; }
+#endif
 #endif
 #if Q0048_CGS_3D_ASYMLUT
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 849)
@@ -59,5 +59,9 @@
 #else
 #if O0194_JOINT_US_BITSHIFT
+#if REF_REGION_OFFSET
+Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, const Window altRefWindow )
+#else
 Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
+#endif
 #else
 Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
@@ -75,8 +79,19 @@
 #endif
 
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+  const Window &scalEL = currSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
+#else
+  const Window &scalEL = currSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc);
+#endif
+#if REF_REGION_OFFSET
+  const Window &windowRL = currSlice->getPPS()->getRefLayerWindow(refLayerIdc);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
   const Window &scalEL = currSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
 #else
   const Window &scalEL = currSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
+#endif
 #endif
 
@@ -91,8 +106,25 @@
 
 #if Q0200_CONFORMANCE_BL_SIZE
+  const Window &confBL = currSlice->getBaseColPic(refLayerIdc)->getConformanceWindow();
+#endif
+#if Q0200_CONFORMANCE_BL_SIZE || REF_REGION_OFFSET
   Int chromaFormatIdc = currSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
-  const Window &confBL = currSlice->getBaseColPic(refLayerIdc)->getConformanceWindow();
   Int xScal = TComSPS::getWinUnitX( chromaFormatIdc );
   Int yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
+#if R0209_GENERIC_PHASE
+  Int phaseHorLuma   = currSlice->getPPS()->getPhaseHorLuma(refLayerIdc);
+  Int phaseVerLuma   = currSlice->getPPS()->getPhaseVerLuma(refLayerIdc);
+  Int phaseHorChroma = currSlice->getPPS()->getPhaseHorChroma(refLayerIdc);
+  Int phaseVerChroma;
+  if (currSlice->getPPS()->getResamplePhaseSetPresentFlag(refLayerIdc))
+  {
+    phaseVerChroma = currSlice->getPPS()->getPhaseVerChroma(refLayerIdc);
+  }
+  else
+  {
+    Int refRegionHeight = heightBL - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
+    phaseVerChroma = (4 * heightEL + (refRegionHeight >> 1)) / refRegionHeight - 4;
+  }
 #endif
 #if P0312_VERT_PHASE_ADJ
@@ -223,4 +255,19 @@
     Int   shiftY = 16;
 
+#if R0209_GENERIC_PHASE
+    Int phaseX = phaseHorLuma;
+    Int phaseY = phaseVerLuma;
+    Int addX = ( ( phaseX * scaleX + 8 ) >> 4 ) -  (1 << ( shiftX - 5 ));
+    Int addY = ( ( phaseY * scaleY + 8 ) >> 4 ) -  (1 << ( shiftX - 5 ));
+#if REF_REGION_OFFSET
+    Int refOffsetX = windowRL.getWindowLeftOffset() << 4;
+    Int refOffsetY = windowRL.getWindowTopOffset()  << 4;
+#else
+#if Q0200_CONFORMANCE_BL_SIZE
+    Int refOffsetX = ( confBL.getWindowLeftOffset() * xScal ) << 4;
+    Int refOffsetY = ( confBL.getWindowTopOffset()  * yScal ) << 4;
+#endif
+#endif
+#else
 #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;
@@ -258,8 +305,14 @@
 #endif
 
+#if REF_REGION_OFFSET
+    Int refOffsetX = windowRL.getWindowLeftOffset() << 4;
+    Int refOffsetY = windowRL.getWindowTopOffset() << 4;
+#else
 #if Q0200_CONFORMANCE_BL_SIZE
     deltaX -= ( confBL.getWindowLeftOffset() * xScal ) << 4;
     deltaY -= ( confBL.getWindowTopOffset() * yScal ) << 4;
 #endif
+#endif
+#endif
 
     Int shiftXM4 = shiftX - 4;
@@ -272,4 +325,12 @@
     heightBL = min<Int>( pcBasePic->getHeight(), heightEL );
 
+#if R0220_REMOVE_EL_CLIP
+    Int phaseXL = scalEL.getWindowLeftOffset();
+    Int phaseYL = scalEL.getWindowTopOffset();
+    Int rlClipL = -(NTAPS_US_LUMA>>1);
+    Int rlClipR = widthBL -1 + (NTAPS_US_LUMA>>1);
+    Int rlClipT = -(NTAPS_US_LUMA>>1);
+    Int rlClipB = heightBL - 1 + (NTAPS_US_LUMA>>1);
+#else
     Int leftStartL = scalEL.getWindowLeftOffset();
     Int rightEndL  = pcUsPic->getWidth() - scalEL.getWindowRightOffset();
@@ -277,4 +338,5 @@
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
+#endif
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
@@ -293,8 +355,28 @@
     for( i = 0; i < widthEL; i++ )
     {
+#if R0220_REMOVE_EL_CLIP
+      Int x = i;
+#if R0209_GENERIC_PHASE
+      refPos16 = (((x - phaseXL)*scaleX - addX) >> shiftXM4) + refOffsetX;
+#else
+#if REF_REGION_OFFSET
+      refPos16 = (((x - phaseXL)*scaleX + addX) >> shiftXM4) - deltaX + refOffsetX;
+#else
+      refPos16 = (((x - phaseXL)*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
+#endif
+#else
       Int x = Clip3( leftStartL, rightEndL - 1, i );
+#if REF_REGION_OFFSET
+      refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX + refOffsetX;
+#else
       refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
+#if R0220_REMOVE_EL_CLIP
+      refPos   = Clip3( rlClipL, rlClipR, refPos );
+#endif
       coeff = m_lumaFilter[phase];
 
@@ -325,16 +407,37 @@
     for( j = 0; j < pcTempPic->getHeight(); j++ )
     {
+#if R0220_REMOVE_EL_CLIP
+      Int y = j;
+#if R0209_GENERIC_PHASE
+      refPos16 = ((( y - phaseYL )*scaleY - addY) >> shiftYM4) + refOffsetY;
+#else
+#if REF_REGION_OFFSET
+      refPos16 = ((( y - phaseYL )*scaleY + addY) >> shiftYM4) - deltaY + refOffsetY;
+#else
+      refPos16 = ((( y - pahseYL )*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
+#endif
+#else
       Int y = Clip3(topStartL, bottomEndL - 1, j);
+#if REF_REGION_OFFSET
+      refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY + refOffsetY;
+#else
       refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
+#if R0220_REMOVE_EL_CLIP
+      refPos = Clip3( rlClipT, rlClipB, refPos );
+#endif
       coeff = m_lumaFilter[phase];
 
       piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
       Pel* piDstY0 = piDstBufY + j * strideEL;
-      piDstY = piDstY0 + leftOffset;
-      piSrcY += leftOffset;
-
-      for( i = min<Int>(rightEndL, pcTempPic->getWidth()) - max<Int>(0, leftStartL); i > 0; i-- )
+
+#if R0220_REMOVE_EL_CLIP
+      piDstY = piDstY0;
+
+      for( i = pcTempPic->getWidth(); i > 0; i-- )
       {
         *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
@@ -342,4 +445,14 @@
         piDstY++;
       }
+#else
+      piDstY = piDstY0 + leftOffset;
+      piSrcY += leftOffset;
+
+      for( i = min<Int>(rightEndL, pcTempPic->getWidth()) - max<Int>(0, leftStartL); i > 0; i-- )
+      {
+        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcY++;
+        piDstY++;
+      }
 
       for( i = rightEndL; i < pcTempPic->getWidth(); i++ )
@@ -355,5 +468,5 @@
         piDstY++;
       }
-
+#endif
     }
 
@@ -374,4 +487,12 @@
     strideEL  = pcUsPic->getCStride();
 
+#if R0220_REMOVE_EL_CLIP
+    Int srlLOffsetC = scalEL.getWindowLeftOffset() >> 1;
+    Int srlTOffsetC = scalEL.getWindowTopOffset() >> 1;
+    rlClipL = -(NTAPS_US_CHROMA>>1);
+    rlClipR = widthBL -1 + (NTAPS_US_CHROMA>>1);
+    rlClipT = -(NTAPS_US_CHROMA>>1);
+    rlClipB = heightBL - 1 + (NTAPS_US_CHROMA>>1);
+#else
     Int leftStartC = scalEL.getWindowLeftOffset() >> 1;
     Int rightEndC  = (pcUsPic->getWidth() >> 1) - (scalEL.getWindowRightOffset() >> 1);
@@ -379,7 +500,14 @@
     Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
     leftOffset = leftStartC > 0 ? leftStartC : 0;
+#endif
     shiftX = 16;
     shiftY = 16;
 
+#if R0209_GENERIC_PHASE
+    addX = ( ( phaseHorChroma * scaleX + 8 ) >> 4 ) -  (1 << ( shiftX - 5 ));
+    addY = ( ( phaseVerChroma * scaleY + 8 ) >> 4 ) -  (1 << ( shiftX - 5 ));
+    Int refOffsetXC = (windowRL.getWindowLeftOffset() / xScal) << 4;
+    Int refOffsetYC = (windowRL.getWindowTopOffset()  / yScal) << 4;
+#else
 #if O0215_PHASE_ALIGNMENT
     Int phaseXC = phaseAlignFlag;
@@ -417,7 +545,13 @@
 #endif
 
+#if REF_REGION_OFFSET
+    Int refOffsetXC = (windowRL.getWindowLeftOffset() / xScal) << 4;
+    Int refOffsetYC  = (windowRL.getWindowTopOffset()  / yScal) << 4;
+#else
 #if Q0200_CONFORMANCE_BL_SIZE
     deltaX -= ( ( confBL.getWindowLeftOffset() * xScal ) >> 1 ) << 4;
     deltaY  -= ( ( confBL.getWindowTopOffset() * yScal ) >> 1 ) << 4;
+#endif
+#endif
 #endif
 
@@ -447,8 +581,28 @@
     for( i = 0; i < widthEL; i++ )
     {
+#if R0220_REMOVE_EL_CLIP
+      Int x = i;
+#if R0209_GENERIC_PHASE
+      refPos16 = (((x - srlLOffsetC)*scaleX - addX) >> shiftXM4) + refOffsetXC;
+#else
+#if REF_REGION_OFFSET
+      refPos16 = (((x - srlLOffsetC)*scaleX + addX) >> shiftXM4) - deltaX + refOffsetXC;
+#else
+      refPos16 = (((x - srlLOffsetC)*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
+#endif
+#else
       Int x = Clip3(leftStartC, rightEndC - 1, i);
+#if REF_REGION_OFFSET
+      refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX + refOffsetXC;
+#else
       refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
+#if R0220_REMOVE_EL_CLIP
+      refPos   = Clip3(rlClipL, rlClipR, refPos);
+#endif
       coeff = m_chromaFilter[phase];
 
@@ -485,8 +639,28 @@
     for( j = 0; j < pcTempPic->getHeight() >> 1; j++ )
     {
+#if R0220_REMOVE_EL_CLIP
+      Int y = j;
+#if R0209_GENERIC_PHASE
+      refPos16 = (((y - srlTOffsetC)*scaleX - addY) >> shiftYM4) + refOffsetYC;
+#else
+#if REF_REGION_OFFSET
+      refPos16 = (((y - srlTOffsetC)*scaleY + addY) >> shiftYM4) - deltaY + refOffsetYC;
+#else
+      refPos16 = (((y - srlTOffsetC)*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
+#endif
+#else
       Int y = Clip3(topStartC, bottomEndC - 1, j);
+#if REF_REGION_OFFSET
+      refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY + refOffsetYC;
+#else
       refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
+#if R0220_REMOVE_EL_CLIP
+      refPos = Clip3(rlClipT, rlClipB, refPos);
+#endif
       coeff = m_chromaFilter[phase];
 
@@ -496,10 +670,10 @@
       Pel* piDstU0 = piDstBufU + j*strideEL;
       Pel* piDstV0 = piDstBufV + j*strideEL;
-      piDstU = piDstU0 + leftOffset;
-      piDstV = piDstV0 + leftOffset;
-      piSrcU += leftOffset;
-      piSrcV += leftOffset;
-
-      for( i = min<Int>(rightEndC, pcTempPic->getWidth() >> 1) - max<Int>(0, leftStartC); i > 0; i-- )
+
+#if R0220_REMOVE_EL_CLIP
+      piDstU = piDstU0;
+      piDstV = piDstV0;
+
+      for( i = pcTempPic->getWidth() >> 1; i > 0; i-- )
       {
         *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
@@ -510,4 +684,19 @@
         piDstV++;
       }
+#else
+      piDstU = piDstU0 + leftOffset;
+      piDstV = piDstV0 + leftOffset;
+      piSrcU += leftOffset;
+      piSrcV += leftOffset;
+
+      for( i = min<Int>(rightEndC, pcTempPic->getWidth() >> 1) - max<Int>(0, leftStartC); i > 0; i-- )
+      {
+        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
+        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcU++;
+        piSrcV++;
+        piDstU++;
+        piDstV++;
+      }
 
       for( i = rightEndC; i < pcTempPic->getWidth() >> 1; i++ )
@@ -528,4 +717,5 @@
         piDstV++;
       }
+#endif
 
     }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 849)
@@ -51,5 +51,9 @@
 #else
 #if O0194_JOINT_US_BITSHIFT
+#if REF_REGION_OFFSET
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, const Window altRefWindow );
+#else
   Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#endif
 #else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
Index: /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 849)
@@ -62,9 +62,4 @@
 #define Q0146_SSH_EXT_DATA_BIT           1      ///< JCTVC-Q0146; Bug-fix -- the SSH_EXT_DATA_BIT can have any value -- not required to be 1
 
-#define Q0200_CONFORMANCE_BL_SIZE        1      ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
-#define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
-#if P0312_VERT_PHASE_ADJ
-#define Q0120_PHASE_CALCULATION          1      ///< JCTVC-Q0120 phase offset derivation for combination of spatial scalibility and field coding.
-#endif
 #define P0130_EOB                        1      ///< JCTVC-P0130, set layer Id of EOB NALU to be fixed to 0
 #define T_ID_EOB_BUG_FIX                 1      ///< Bug fix for the value of temporal id of EOB NALU. It must be set to 0
@@ -235,4 +230,20 @@
 #define HRD_BPB                          1      ///< JCTVC-Q0101 Bitstream Partition Buffering Proposals
 #define DPB_CONSTRAINTS                  1      ///< JCTVC-Q0100 RPS DPB constraints
+
+#define R0340_RESAMPLING_MODIFICATION    1      ///< JCTVC-R0340: set of changes regarding resampling (as listed below)
+#if R0340_RESAMPLING_MODIFICATION
+#define MOVE_SCALED_OFFSET_TO_PPS        1      ///< JCTVC-R0013: move scaled reference layer offset from SPS to PPS
+#if MOVE_SCALED_OFFSET_TO_PPS
+#define REF_REGION_OFFSET                1      ///< JCTVC-Q0159/R0220: reference region offset
+#define R0209_GENERIC_PHASE              1      ///< JCTVC-R0209: resampling with generic phase
+#define R0220_REMOVE_EL_CLIP             1      ///< JCTVC-R0220: remove clip to scaled ref window in resampling process
+#endif
+#else
+#define Q0200_CONFORMANCE_BL_SIZE        1      ///< JCTVC-Q0200; use conformance picture size in re-sampling processs
+#define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
+#if P0312_VERT_PHASE_ADJ
+#define Q0120_PHASE_CALCULATION          1      ///< JCTVC-Q0120 phase offset derivation for combination of spatial scalibility and field coding.
+#endif
+#endif
 
 /// scalability types
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 849)
@@ -359,4 +359,60 @@
       READ_FLAG( uiCode, "poc_reset_info_present_flag" );
       pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
+#if REF_REGION_OFFSET
+      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        READ_CODE( 6, uiCode,  "scaled_ref_layer_id" );  pcPPS->setScaledRefLayerId( i, uiCode );
+        READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );   pcPPS->setScaledRefLayerOffsetPresentFlag( i, uiCode );
+        if (uiCode)
+        {
+          Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+          READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+          READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+          READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+          READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+          READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
+#endif
+        }
+        READ_FLAG( uiCode, "ref_region_offset_present_flag" );   pcPPS->setRefRegionOffsetPresentFlag( i, uiCode );
+        if (uiCode)
+        {
+          Window& refWindow = pcPPS->getRefLayerWindow(i);
+          READ_SVLC( iCode, "ref_region_left_offset" );    refWindow.setWindowLeftOffset  (iCode << 1);
+          READ_SVLC( iCode, "ref_region_top_offset" );     refWindow.setWindowTopOffset   (iCode << 1);
+          READ_SVLC( iCode, "ref_region_right_offset" );   refWindow.setWindowRightOffset (iCode << 1);
+          READ_SVLC( iCode, "ref_region_bottom_offset" );  refWindow.setWindowBottomOffset(iCode << 1);
+        }
+#if R0209_GENERIC_PHASE
+        READ_FLAG( uiCode, "resample_phase_set_present_flag" );   pcPPS->setResamplePhaseSetPresentFlag( i, uiCode );
+        if (uiCode)
+        {
+          READ_UVLC( uiCode, "phase_hor_luma" );    pcPPS->setPhaseHorLuma ( i, uiCode );
+          READ_UVLC( uiCode, "phase_ver_luma" );    pcPPS->setPhaseVerLuma ( i, uiCode );
+          READ_UVLC( uiCode, "phase_hor_chroma_plus8" );  pcPPS->setPhaseHorChroma (i, uiCode - 8);
+          READ_UVLC( uiCode, "phase_ver_chroma_plus8" );  pcPPS->setPhaseVerChroma (i, uiCode - 8);
+        }
+#endif
+      }
+#else
+#if MOVE_SCALED_OFFSET_TO_PPS
+      READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcPPS->setNumScaledRefLayerOffsets(uiCode);
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        Window& scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+#if O0098_SCALED_REF_LAYER_ID
+        READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcPPS->setScaledRefLayerId( i, uiCode );
+#endif
+        READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+        READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+        READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcPPS->setVertPhasePositionEnableFlag( pcPPS->getScaledRefLayerId(i), uiCode);
+#endif
+      }
+#endif
+#endif
 #if Q0048_CGS_3D_ASYMLUT
       READ_FLAG( uiCode , "colour_mapping_enabled_flag" ); 
@@ -897,4 +953,5 @@
   assert( uiCode == 0 );
 
+#if !MOVE_SCALED_OFFSET_TO_PPS
   if( pcSPS->getLayerId() > 0 )
   {
@@ -916,4 +973,5 @@
     }
   }
+#endif
 }
 #endif
@@ -3027,11 +3085,15 @@
   }
 #if P0312_VERT_PHASE_ADJ
-  for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
-  {
-    UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
-    if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
-    {
-      READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
-    }
+    for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
+    {
+      UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
+#if !MOVE_SCALED_OFFSET_TO_PPS
+      if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+#else
+      if( rpcSlice->getPPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+#endif
+      {
+        READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
+      }
   }
 #endif
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 849)
@@ -350,4 +350,11 @@
       for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
       {
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
+#else
+        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(i);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
@@ -355,5 +362,12 @@
         const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
 #endif
+#endif
+#if REF_REGION_OFFSET
+        const Window refEL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
+        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
+                             && refEL.getWindowLeftOffset() == 0 && refEL.getWindowRightOffset() == 0 && refEL.getWindowTopOffset() == 0 && refEL.getWindowBottomOffset() == 0 );
+#else
         Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+#endif
 
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -763,4 +777,18 @@
 
 #if P0312_VERT_PHASE_ADJ
+#if MOVE_SCALED_OFFSET_TO_PPS
+  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
+  {    
+    for(Int i = 0; i < activePPS->getNumScaledRefLayerOffsets(); i++)
+    {
+      UInt scaledRefLayerId = activePPS->getScaledRefLayerId(i);
+      if( activePPS->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;
+      }
+    }
+  }
+#else
   if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
   {    
@@ -775,4 +803,5 @@
     }
   }
+#endif
 #endif
 
@@ -1726,4 +1755,11 @@
 #endif
 
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
+#else
+        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
@@ -1731,5 +1767,11 @@
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
 #endif
-
+#endif
+
+#if REF_REGION_OFFSET
+        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
+#else
         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
@@ -1740,4 +1782,5 @@
         heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
 #endif
+#endif
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
@@ -1786,7 +1829,11 @@
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+#if MOVE_SCALED_OFFSET_TO_PPS
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#endif
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #endif
@@ -1794,7 +1841,11 @@
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#if REF_REGION_OFFSET
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
+#else
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#endif
+#else
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #else
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp	(revision 849)
@@ -462,5 +462,9 @@
   TComSlice * pSlice = pCurPic->getSlice(pCurPic->getCurrSliceIdx());
   UInt refLayerId = pSlice->getVPS()->getRefLayerId(pSlice->getLayerId(), refLayerIdc);
+#if MOVE_SCALED_OFFSET_TO_PPS
+  const Window &scalEL = pSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId); 
+#else
   const Window &scalEL = pSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId); 
+#endif
   TComPicYuv *pcRecPicBL = pSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
   // borders of down-sampled picture
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 849)
@@ -273,4 +273,54 @@
     {
       WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag() ? 1 : 0, "poc_reset_info_present_flag" );
+#if REF_REGION_OFFSET
+      WRITE_UVLC( pcPPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        WRITE_CODE( pcPPS->getScaledRefLayerId(i), 6, "scaled_ref_layer_id" );
+        WRITE_FLAG( pcPPS->getScaledRefLayerOffsetPresentFlag(i) ? 1 : 0, "scaled_ref_layer_offset_prsent_flag" );
+        if (pcPPS->getScaledRefLayerOffsetPresentFlag(i))
+        {
+          Window scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+          WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
+          WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
+          WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
+          WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
+        }
+        WRITE_FLAG( pcPPS->getRefRegionOffsetPresentFlag(i) ? 1 : 0, "ref_region_offset_prsent_flag" );
+        if (pcPPS->getRefRegionOffsetPresentFlag(i))
+        {
+          Window refWindow = pcPPS->getRefLayerWindow(i);
+          WRITE_SVLC( refWindow.getWindowLeftOffset()   >> 1, "ref_layer_left_offset" );
+          WRITE_SVLC( refWindow.getWindowTopOffset()    >> 1, "ref_layer_top_offset" );
+          WRITE_SVLC( refWindow.getWindowRightOffset()  >> 1, "ref_layer_right_offset" );
+          WRITE_SVLC( refWindow.getWindowBottomOffset() >> 1, "ref_layer_bottom_offset" );
+        }
+#if R0209_GENERIC_PHASE
+        WRITE_FLAG( pcPPS->getResamplePhaseSetPresentFlag(i) ? 1 : 0, "resample_phase_set_present_flag" );
+        if (pcPPS->getResamplePhaseSetPresentFlag(i))
+        {
+          WRITE_UVLC( pcPPS->getPhaseHorLuma(i), "phase_hor_luma" );
+          WRITE_UVLC( pcPPS->getPhaseVerLuma(i), "phase_ver_luma" );
+          WRITE_UVLC( pcPPS->getPhaseHorChroma(i) + 8, "phase_hor_chroma_plus8" );
+          WRITE_UVLC( pcPPS->getPhaseVerChroma(i) + 8, "phase_ver_chroma_plus8" );
+        }
+#endif
+      }
+#else
+#if MOVE_SCALED_OFFSET_TO_PPS
+      WRITE_UVLC( pcPPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
+      for(Int i = 0; i < pcPPS->getNumScaledRefLayerOffsets(); i++)
+      {
+        Window scaledWindow = pcPPS->getScaledRefLayerWindow(i);
+#if O0098_SCALED_REF_LAYER_ID
+        WRITE_CODE( pcPPS->getScaledRefLayerId(i), 6,          "scaled_ref_layer_id" );
+#endif
+        WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
+        WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
+        WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
+        WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
+      }
+#endif
+#endif
 #if Q0048_CGS_3D_ASYMLUT
       UInt uiPos = getNumberOfWrittenBits();
@@ -672,4 +722,5 @@
   WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" );
 
+#if !MOVE_SCALED_OFFSET_TO_PPS
   if( pcSPS->getLayerId() > 0 )
   {
@@ -690,4 +741,5 @@
     }
   }
+#endif
 }
 #endif //SVC_EXTENSION
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 849)
@@ -411,5 +411,5 @@
 
   Window   &getConformanceWindow()                           { return m_conformanceWindow; }
-#if P0312_VERT_PHASE_ADJ 
+#if P0312_VERT_PHASE_ADJ && !R0209_GENERIC_PHASE
   Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom, false); }
 #else
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 849)
@@ -1132,4 +1132,9 @@
 #endif
 
+#if REF_REGION_OFFSET
+        const Window &windowRL  = m_pcEncTop->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
+#else
         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
@@ -1140,4 +1145,5 @@
         heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
 #endif
+#endif
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
@@ -1209,7 +1215,11 @@
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-            m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-            m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#if REF_REGION_OFFSET
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
+#else
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#endif
+#else
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #else
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 849)
@@ -779,4 +779,11 @@
         for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
         {
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+          const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
+#else
+          const Window scalEL = getPPS()->getScaledRefLayerWindow(i);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
           const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
@@ -784,5 +791,12 @@
           const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
 #endif
+#endif
+#if REF_REGION_OFFSET
+          const Window altRL  = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
+          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
+                               && altRL.getWindowLeftOffset() == 0 && altRL.getWindowRightOffset() == 0 && altRL.getWindowTopOffset() == 0 && altRL.getWindowBottomOffset() == 0);
+#else
           Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+#endif
 
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -839,4 +853,11 @@
         for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
         {
+#if MOVE_SCALED_OFFSET_TO_PPS
+#if O0098_SCALED_REF_LAYER_ID
+          const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
+#else
+          const Window scalEL = getPPS()->getScaledRefLayerWindow(i);
+#endif
+#else
 #if O0098_SCALED_REF_LAYER_ID
           const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
@@ -844,5 +865,12 @@
           const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
 #endif
+#endif
+#if REF_REGION_OFFSET
+          const Window altRL  = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
+          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
+                               && altRL.getWindowLeftOffset() == 0 && altRL.getWindowRightOffset() == 0 && altRL.getWindowTopOffset() == 0 && altRL.getWindowBottomOffset() == 0);
+#else
           Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+#endif
 
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -918,4 +946,5 @@
   m_cSPS.setLayerId(m_layerId);
 #endif
+#if !MOVE_SCALED_OFFSET_TO_PPS
   m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
   for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
@@ -929,4 +958,5 @@
 #endif
   }
+#endif
 #endif //SVC_EXTENSION
   ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
@@ -1205,4 +1235,29 @@
   }
 #endif
+#if MOVE_SCALED_OFFSET_TO_PPS
+  m_cPPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
+  for(Int i = 0; i < m_cPPS.getNumScaledRefLayerOffsets(); i++)
+  {
+#if O0098_SCALED_REF_LAYER_ID
+    m_cPPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]);
+#endif
+    m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
+#if REF_REGION_OFFSET
+    m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i];
+    m_cPPS.setScaledRefLayerOffsetPresentFlag( m_scaledRefLayerId[i], m_scaledRefLayerOffsetPresentFlag[i] );
+    m_cPPS.setRefRegionOffsetPresentFlag( m_scaledRefLayerId[i], m_refRegionOffsetPresentFlag[i] );
+#endif
+#if R0209_GENERIC_PHASE
+    m_cPPS.setResamplePhaseSetPresentFlag( m_scaledRefLayerId[i], m_resamplePhaseSetPresentFlag[i] );
+    m_cPPS.setPhaseHorLuma( m_scaledRefLayerId[i], m_phaseHorLuma[i] );
+    m_cPPS.setPhaseVerLuma( m_scaledRefLayerId[i], m_phaseVerLuma[i] );
+    m_cPPS.setPhaseHorChroma( m_scaledRefLayerId[i], m_phaseHorChroma[i] );
+    m_cPPS.setPhaseVerChroma( m_scaledRefLayerId[i], m_phaseVerChroma[i] );
+#endif
+#if P0312_VERT_PHASE_ADJ
+    m_cPPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() );
+#endif
+  }
+#endif
 #if Q0048_CGS_3D_ASYMLUT
   m_cPPS.setCGSFlag( m_nCGSFlag );
@@ -1682,4 +1737,21 @@
   return win;
 }
+#if REF_REGION_OFFSET
+Window& TEncTop::getRefLayerWindowForLayer(Int layerId)
+{
+  static Window win;
+
+  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
+  {
+    if (layerId == m_refLayerId[i])
+    {
+      return m_refLayerWindow[i];
+    }
+  }
+
+  win.resetWindow();  // reference offsets are inferred to be zero when not present
+  return win;
+}
+#endif
 #endif
 
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 848)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 849)
@@ -136,4 +136,18 @@
 #endif
   Window                  m_scaledRefLayerWindow[MAX_LAYERS];
+#if REF_REGION_OFFSET
+  UInt                    m_numRefLayerOffsets;
+  UInt                    m_refLayerId[MAX_LAYERS];
+  Window                  m_refLayerWindow[MAX_LAYERS];
+  Bool                    m_scaledRefLayerOffsetPresentFlag[MAX_LAYERS];
+  Bool                    m_refRegionOffsetPresentFlag[MAX_LAYERS];
+#endif
+#if R0209_GENERIC_PHASE
+  Int                     m_phaseHorLuma  [MAX_LAYERS];
+  Int                     m_phaseVerLuma  [MAX_LAYERS];
+  Int                     m_phaseHorChroma[MAX_LAYERS];
+  Int                     m_phaseVerChroma[MAX_LAYERS];
+  Int                     m_resamplePhaseSetPresentFlag[MAX_LAYERS];
+#endif
 #if P0312_VERT_PHASE_ADJ
   Bool                    m_vertPhasePositionEnableFlag[MAX_LAYERS];
@@ -229,7 +243,31 @@
 #endif
   Window&   getScaledRefLayerWindow(Int x)                 { return m_scaledRefLayerWindow[x];        }
+#if REF_REGION_OFFSET
+  Void      setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; }
+  UInt      getNumRefLayerOffsets() { return m_numRefLayerOffsets; }
+  Void      setRefLayerId(Int x, UInt id) { m_refLayerId[x] = id;   }
+  UInt      getRefLayerId(Int x)          { return m_refLayerId[x]; }
+  Window&   getRefLayerWindowForLayer(Int layerId);
+  Window&   getRefLayerWindow(Int x)            { return m_refLayerWindow[x]; }
+  Bool      getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; }
+  Void      setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; }
+  Bool      getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; }
+  Void      setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; }
+#endif
 #if P0312_VERT_PHASE_ADJ
   Void      setVertPhasePositionEnableFlag(Int x, Bool b)  { m_vertPhasePositionEnableFlag[x] = b;    }
   UInt      getVertPhasePositionEnableFlag(Int x)          { return m_vertPhasePositionEnableFlag[x]; }
+#endif
+#if R0209_GENERIC_PHASE
+  Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; }
+  Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; }
+  Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; }
+  Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; }
+  Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; }
+  Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; }
+  Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; }
+  Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; }
+  Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; }
+  Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; }
 #endif
 
