Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BQTerrace-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/BasketballDrive-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Cactus-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Kimono-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 544         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/ParkScene-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1088        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/PeopleOnStreet-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/PeopleOnStreet-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/PeopleOnStreet-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/PeopleOnStreet-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/PeopleOnStreet-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/PeopleOnStreet-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Traffic-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Traffic-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Traffic-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Traffic-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Traffic-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc-avcbase/Traffic-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/BQTerrace-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/BasketballDrive-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Cactus-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Kimono-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-1.5x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-1.5x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-1.5x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/ParkScene-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Traffic-2x.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Traffic-2x.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Traffic-2x.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/cfg/per-sequence-svc/Traffic-SNR.cfg
===================================================================
--- /branches/SHM-3.1-dev/cfg/per-sequence-svc/Traffic-SNR.cfg	(revision 388)
+++ /branches/SHM-3.1-dev/cfg/per-sequence-svc/Traffic-SNR.cfg	(revision 389)
@@ -8,4 +8,5 @@
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
+RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -16,4 +17,5 @@
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
+RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /branches/SHM-3.1-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 389)
@@ -551,4 +551,14 @@
         const Window &conf = pcPic->getConformanceWindow();
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if REPN_FORMAT_IN_VPS
+        UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
+        Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+        m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+                                       conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
+                                       conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
+                                       conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
+                                       conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
+
+#else
         m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
@@ -556,4 +566,5 @@
                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+#endif
       }
       
@@ -630,4 +641,14 @@
         const Window &conf = pcPic->getConformanceWindow();
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if REPN_FORMAT_IN_VPS
+        UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
+        Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+        m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
+                                       conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
+                                       conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
+                                       conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
+                                       conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
+
+#else
         m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
@@ -635,4 +656,5 @@
                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
+#endif
       }
       
Index: /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 389)
@@ -351,4 +351,7 @@
   Double* cfg_fQP           [MAX_LAYERS];
 
+#if REPN_FORMAT_IN_VPS
+  Int*    cfg_repFormatIdx  [MAX_LAYERS];
+#endif
   Int*    cfg_SourceWidth   [MAX_LAYERS]; 
   Int*    cfg_SourceHeight  [MAX_LAYERS];
@@ -399,4 +402,7 @@
     cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
     cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
+#if REPN_FORMAT_IN_VPS
+    cfg_repFormatIdx[layer] = &m_acLayerCfg[layer].m_repFormatIdx;
+#endif
     cfg_SourceWidth[layer]  = &m_acLayerCfg[layer].m_iSourceWidth;
     cfg_SourceHeight[layer] = &m_acLayerCfg[layer].m_iSourceHeight;
@@ -469,4 +475,7 @@
   ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
   ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+#if REPN_FORMAT_IN_VPS
+  ("RepFormatIdx%d",          cfg_repFormatIdx, -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -1127,5 +1136,12 @@
 #endif
   m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
-  
+
+#if REPN_FORMAT_IN_VPS_123
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    m_acLayerCfg[layer].setSourceHeight( m_repFormatCfg[ m_acLayerCfg[layer].getRepFormatIdx() ].m_picHeightInLumaSamples);
+    m_acLayerCfg[layer].setSourceWidth ( m_repFormatCfg[ m_acLayerCfg[layer].getRepFormatIdx() ].m_picWidthInLumaSamples );
+  }
+#endif
   /* rules for input, output and internal bitdepths as per help text */
   if (!m_internalBitDepthY) { m_internalBitDepthY = m_inputBitDepthY; }
Index: /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 389)
@@ -354,4 +354,7 @@
   Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
 #endif
+#if REPN_FORMAT_IN_VPS
+  RepFormatCfg m_repFormatCfg[16];                            ///< Rep_format structures
+#endif
 public:
   TAppEncCfg();
@@ -381,4 +384,7 @@
   Void cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString);
 #endif
+#if REPN_FORMAT_IN_VPS
+  RepFormatCfg* getRepFormatCfg(Int i)  { return &m_repFormatCfg[i]; }
+#endif
 #endif
 };// END CLASS DEFINITION TAppEncCfg
Index: /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 389)
@@ -32,4 +32,7 @@
   m_conformanceMode( 0 ),
   m_aidQP(NULL)
+#if REPN_FORMAT_IN_VPS
+, m_repFormatIdx (-1)
+#endif
 {
   m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
Index: /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 389)
@@ -84,4 +84,7 @@
   GOPEntry  m_GOPListLayer[MAX_GOP];                            ///< for layer
 #endif
+#if REPN_FORMAT_IN_VPS
+  Int       m_repFormatIdx;
+#endif
 public:
   TAppEncLayerCfg();
@@ -147,4 +150,9 @@
   GOPEntry getGOPEntry(Int i )        {return m_GOPListLayer[i];  }
 #endif
+#if REPN_FORMAT_IN_VPS
+  Int     getRepFormatIdx()           { return m_repFormatIdx; }
+  Void    setSourceWidth(Int x)            {m_iSourceWidth = x;     }
+  Void    setSourceHeight(Int x)           {m_iSourceHeight = x;    }
+#endif
 }; // END CLASS DEFINITION TAppEncLayerCfg
 
Index: /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 389)
@@ -90,5 +90,43 @@
     vps->setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
   }
-
+#if REPN_FORMAT_IN_VPS
+  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
+  Int maxRepFormatIdx = -1;
+  for(UInt layer=0; layer < m_numLayers; layer++)
+  {
+    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1, "RepFormatIdx not assigned for a layer" );   
+    vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
+    maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
+  }
+  assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
+  Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
+  // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS
+  for(Int i = 0; i <= maxRepFormatIdx; i++)
+  {
+    mapIdxToLayer[i] = -1;
+    UInt layer;
+    for(layer=0; layer < m_numLayers; layer++)
+    {
+      if( vps->getVpsRepFormatIdx(layer) == i )
+      {
+        mapIdxToLayer[i] = layer;
+        break;
+      }
+    }
+    assert( layer != m_numLayers );   // One of the VPS Rep format indices not set
+  }
+  vps->setVpsNumRepFormats( maxRepFormatIdx + 1 );
+  for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
+  {
+    RepFormat *repFormat = vps->getVpsRepFormat( idx );    
+    repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
+    repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
+    repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
+    repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
+    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
+    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
+  }
+  delete [] mapIdxToLayer;
+#endif
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 389)
@@ -1273,5 +1273,9 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
   
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
+#endif
   {
     uiARPartUnitIdx = MAX_UINT;
@@ -1335,6 +1339,10 @@
   UInt uiAbsZorderCUIdxLB = g_auiZscanToRaster[ m_uiAbsIdxInLCU ] + (m_puhHeight[0] / m_pcPic->getMinCUHeight() - 1)*m_pcPic->getNumPartInWidth();
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
-  
+
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
+#endif
   {
     uiBLPartUnitIdx = MAX_UINT;
@@ -1384,5 +1392,9 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
   
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicHeightInLumaSamples())
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxLB] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples())
+#endif
   {
     uiBLPartUnitIdx = MAX_UINT;
@@ -1432,5 +1444,9 @@
   UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
   
+#if REPN_FORMAT_IN_VPS
+  if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getPicWidthInLumaSamples() )
+#else
   if( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxRT] + (m_pcPic->getPicSym()->getMinCUHeight() * uiPartUnitOffset)) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )
+#endif
   {
     uiARPartUnitIdx = MAX_UINT;
@@ -2684,4 +2700,12 @@
     Int uiLCUIdx = -1;
 
+#if REPN_FORMAT_IN_VPS
+    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
+    {
+    }
+    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
+    {
+    }
+#else
     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     {
@@ -2690,4 +2714,5 @@
     {
     }
+#endif
     else
     {
@@ -3020,4 +3045,12 @@
     uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
     Int uiLCUIdx = -1;
+#if REPN_FORMAT_IN_VPS
+    if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getPicWidthInLumaSamples() )  // image boundary check
+    {
+    }
+    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getPicHeightInLumaSamples() )
+    {
+    }
+#else
     if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     {
@@ -3026,4 +3059,5 @@
     {
     }
+#endif
     else
     {
@@ -3095,8 +3129,16 @@
   Int  iMvShift = 2;
   Int iOffset = 8;
+#if REPN_FORMAT_IN_VPS
+  Int iHorMax = ( m_pcSlice->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
+#else
   Int iHorMax = ( m_pcSlice->getSPS()->getPicWidthInLumaSamples() + iOffset - m_uiCUPelX - 1 ) << iMvShift;
+#endif
   Int iHorMin = (       -(Int)g_uiMaxCUWidth - iOffset - (Int)m_uiCUPelX + 1 ) << iMvShift;
   
+#if REPN_FORMAT_IN_VPS
+  Int iVerMax = ( m_pcSlice->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
+#else
   Int iVerMax = ( m_pcSlice->getSPS()->getPicHeightInLumaSamples() + iOffset - m_uiCUPelY - 1 ) << iMvShift;
+#endif
   Int iVerMin = (       -(Int)g_uiMaxCUHeight - iOffset - (Int)m_uiCUPelY + 1 ) << iMvShift;
   
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 389)
@@ -180,5 +180,9 @@
       UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
       UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
+#if REPN_FORMAT_IN_VPS
+      if( ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
+#else
       if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xDeblockCU( pcCU, uiAbsZorderIdx, uiDepth+1, Edge );
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 389)
@@ -213,6 +213,11 @@
   UInt maxNumSUInLCU = getNumPartInCU();
   UInt numLCUInPic   = getNumCUsInFrame();
+#if REPN_FORMAT_IN_VPS
+  UInt picWidth      = getSlice(0)->getPicWidthInLumaSamples();
+  UInt picHeight     = getSlice(0)->getPicHeightInLumaSamples();
+#else
   UInt picWidth      = getSlice(0)->getSPS()->getPicWidthInLumaSamples();
   UInt picHeight     = getSlice(0)->getSPS()->getPicHeightInLumaSamples();
+#endif
   Int  numLCUsInPicWidth = getFrameWidthInCU();
   Int  numLCUsInPicHeight= getFrameHeightInCU();
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 389)
@@ -1414,5 +1414,9 @@
       UInt uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsZorderIdx] ];
       UInt uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsZorderIdx] ];
+#if REPN_FORMAT_IN_VPS
+      if( ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples() ) )
+#else
       if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
         xPCMCURestoration( pcCU, uiAbsZorderIdx, uiDepth+1 );
     }
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 389)
@@ -1587,4 +1587,99 @@
 }
 
+#if REPN_FORMAT_IN_VPS
+UInt TComSlice::getPicWidthInLumaSamples()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getPicWidthInLumaSamples();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicWidthVpsInLumaSamples();
+  }
+  return retVal;
+}
+UInt TComSlice::getPicHeightInLumaSamples()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getPicHeightInLumaSamples();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicHeightVpsInLumaSamples();
+  }
+  return retVal;
+}
+UInt TComSlice::getChromaFormatIdc()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getChromaFormatIdc();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
+  }
+  return retVal;
+}
+UInt TComSlice::getBitDepthY()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getBitDepthY();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
+  }
+  return retVal;
+}
+UInt TComSlice::getBitDepthC()
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+  UInt retVal, layerId = getLayerId();
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getBitDepthC();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
+  }
+  return retVal;
+}
+Int TComSlice::getQpBDOffsetY()
+{
+  return (getBitDepthY() - 8) * 6;
+}
+Int TComSlice::getQpBDOffsetC()
+{
+  return (getBitDepthC() - 8) * 6;
+}
+
+RepFormat::RepFormat()
+: m_chromaFormatVpsIdc          (0)
+, m_separateColourPlaneVpsFlag  (false)
+, m_picWidthVpsInLumaSamples    (0)
+, m_picHeightVpsInLumaSamples   (0)
+, m_bitDepthVpsLuma             (0)
+, m_bitDepthVpsChroma           (0)
+{}
+#endif
+
 // ------------------------------------------------------------------------------------------------
 // Video parameter set (VPS)
@@ -1619,4 +1714,8 @@
 , m_picRatePresentVpsFlag     (false)
 #endif
+#if REPN_FORMAT_IN_VPS
+, m_repFormatIdxPresentFlag   (true)
+, m_vpsNumRepFormats          (1)
+#endif
 {
   for( Int i = 0; i < MAX_TLAYER; i++)
@@ -1692,4 +1791,7 @@
   ::memset(m_constPicRateIdc   , 0, sizeof(m_constPicRateIdc)   );
   ::memset(m_avgPicRate        , 0, sizeof(m_avgPicRate)        );
+#endif
+#if REPN_FORMAT_IN_VPS
+  ::memset( m_vpsRepFormatIdx, 0, sizeof(m_vpsRepFormatIdx) );
 #endif
 }
@@ -1778,4 +1880,7 @@
 , m_numScaledRefLayerOffsets  (0)
 #endif
+#if REPN_FORMAT_IN_VPS
+, m_updateRepFormatFlag       (false)
+#endif
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 389)
@@ -406,4 +406,36 @@
 };
 
+#if REPN_FORMAT_IN_VPS
+class RepFormat
+{
+  Int  m_chromaFormatVpsIdc;
+  Bool m_separateColourPlaneVpsFlag;
+  Int  m_picWidthVpsInLumaSamples;
+  Int  m_picHeightVpsInLumaSamples;
+  Int  m_bitDepthVpsLuma;               // coded as minus8
+  Int  m_bitDepthVpsChroma;             // coded as minus8
+
+public:
+  RepFormat();
+
+  Int  getChromaFormatVpsIdc()        { return m_chromaFormatVpsIdc; }
+  Void setChromaFormatVpsIdc(Int x)   { m_chromaFormatVpsIdc = x;    }
+
+  Bool getSeparateColourPlaneVpsFlag()        { return m_separateColourPlaneVpsFlag; }
+  Void setSeparateColourPlaneVpsFlag(Bool x)  { m_separateColourPlaneVpsFlag = x;    }
+
+  Int  getPicWidthVpsInLumaSamples()        { return m_picWidthVpsInLumaSamples; }
+  Void setPicWidthVpsInLumaSamples(Int x)   { m_picWidthVpsInLumaSamples = x;    }
+
+  Int  getPicHeightVpsInLumaSamples()        { return m_picHeightVpsInLumaSamples; }
+  Void setPicHeightVpsInLumaSamples(Int x)   { m_picHeightVpsInLumaSamples = x;    }
+
+  Int  getBitDepthVpsLuma()           { return m_bitDepthVpsLuma;   }
+  Void setBitDepthVpsLuma(Int x)      { m_bitDepthVpsLuma = x;      }
+
+  Int  getBitDepthVpsChroma()           { return m_bitDepthVpsChroma;   }
+  Void setBitDepthVpsChroma(Int x)      { m_bitDepthVpsChroma = x;      }
+};
+#endif
 class TComVPS
 {
@@ -519,4 +551,10 @@
   Int         m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
 #endif
+#if REPN_FORMAT_IN_VPS
+  Bool       m_repFormatIdxPresentFlag;
+  Int        m_vpsNumRepFormats;            // coded as minus1
+  RepFormat  m_vpsRepFormat[16];
+  Int        m_vpsRepFormatIdx[16];
+#endif
 public:
   TComVPS();
@@ -727,4 +765,17 @@
   Int  getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
   Void setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
+#endif
+
+#if REPN_FORMAT_IN_VPS
+  Bool   getRepFormatIdxPresentFlag()       { return m_repFormatIdxPresentFlag; }
+  Void   setRepFormatIdxPresentFlag(Bool x) { m_repFormatIdxPresentFlag = x;    }
+
+  Int    getVpsNumRepFormats()              { return m_vpsNumRepFormats;        }
+  Void   setVpsNumRepFormats(Int x)         { m_vpsNumRepFormats = x;           }
+
+  RepFormat* getVpsRepFormat(Int idx)       { return &m_vpsRepFormat[idx];      }
+
+  Int    getVpsRepFormatIdx(Int idx)        { return m_vpsRepFormatIdx[idx];   }
+  Void   setVpsRepFormatIdx(Int idx, Int x) { m_vpsRepFormatIdx[idx] = x;      }         
 #endif
 };
@@ -1041,4 +1092,7 @@
   UInt        m_numScaledRefLayerOffsets;
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
+#endif
+#if REPN_FORMAT_IN_VPS
+  Bool m_updateRepFormatFlag;
 #endif
 public:
@@ -1200,4 +1254,8 @@
   Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
 #endif
+#if REPN_FORMAT_IN_VPS
+  Bool     getUpdateRepFormatFlag()       { return m_updateRepFormatFlag; }
+  Void     setUpdateRepFormatFlag(Bool x) { m_updateRepFormatFlag = x;    }
+#endif
 };
 
@@ -1866,4 +1924,13 @@
 #endif //SVC_EXTENSION
 
+#if REPN_FORMAT_IN_VPS
+  UInt getPicWidthInLumaSamples();
+  UInt getPicHeightInLumaSamples();
+  UInt getChromaFormatIdc();
+  UInt getBitDepthY();
+  UInt getBitDepthC();
+  Int getQpBDOffsetY();
+  Int getQpBDOffsetC();
+#endif
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 389)
@@ -42,5 +42,5 @@
 #include "TComPic.h"
 #include "ContextTables.h"
-
+#define MAYBE_BUGFIX 1
 typedef struct
 {
@@ -50,4 +50,14 @@
   Double d64SigCost;
   Double d64SigCost_0;
+#if MAYBE_BUGFIX
+  Void init()
+  {
+    iNNZbeforePos0 = 0;
+  d64CodedLevelandDist = 0;
+  d64UncodedDist = 0;
+  d64SigCost = 0;
+  d64SigCost_0 = 0;
+  }
+#endif
 } coeffGroupRDStats;
 
@@ -1033,5 +1043,9 @@
 
     Int qpScaled;
+#if REPN_FORMAT_IN_VPS
+    Int qpBDOffset = (eTType == TEXT_LUMA)? pcCU->getSlice()->getQpBDOffsetY() : pcCU->getSlice()->getQpBDOffsetC();
+#else
     Int qpBDOffset = (eTType == TEXT_LUMA)? pcCU->getSlice()->getSPS()->getQpBDOffsetY() : pcCU->getSlice()->getSPS()->getQpBDOffsetC();
+#endif
 
     if(eTType == TEXT_LUMA)
@@ -1581,6 +1595,9 @@
     UInt uiCGPosY   = uiCGBlkPos / uiNumBlkSide;
     UInt uiCGPosX   = uiCGBlkPos - (uiCGPosY * uiNumBlkSide);
+#if MAYBE_BUGFIX
+    rdStats.init();
+#else
     ::memset( &rdStats, 0, sizeof (coeffGroupRDStats));
-    
+#endif
     const Int patternSigCtx = TComTrQuant::calcPatternSigCtx(uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiWidth, uiHeight);
     for (Int iScanPosinCG = uiCGSize-1; iScanPosinCG >= 0; iScanPosinCG--)
Index: /branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 389)
@@ -48,4 +48,5 @@
 #if SVC_EXTENSION
 #define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+#define REPN_FORMAT_IN_VPS               1      ///< N0092: Signal represenation format (spatial resolution, bit depth, colour format) in the VPS
 #define TIMING_INFO_NONZERO_LAYERID_SPS  1      ///< N0085: Semantics of vui_timing_info_present_flag to always set that flag to zero for non-zero layer ID SPS 
 #define RPL_INIT_N0316_N0082             1      ///< N0316, N0082: initial reference picture list construction 
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 389)
@@ -542,36 +542,64 @@
   READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
   assert(uiCode <= 15);
-  
-  READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
-  assert(uiCode <= 3);
-  // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
-  assert (uiCode == 1);
-  if( uiCode == 3 )
-  {
-    READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
-  }
-
-  READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
-  READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
+
+#if REPN_FORMAT_IN_VPS
+  if( pcSPS->getLayerId() > 0 )
+  {
+    READ_FLAG( uiCode, "update_rep_format_flag" );                 
+    pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
+  }
+  else
+  {
+    pcSPS->setUpdateRepFormatFlag( true );
+  }
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+#endif
+    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
+    assert(uiCode <= 3);
+    // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
+    assert (uiCode == 1);
+    if( uiCode == 3 )
+    {
+      READ_FLAG(     uiCode, "separate_colour_plane_flag");        assert(uiCode == 0);
+    }
+
+    READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
+    READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   READ_FLAG(     uiCode, "conformance_window_flag");
   if (uiCode != 0)
   {
     Window &conf = pcSPS->getConformanceWindow();
+#if REPN_FORMAT_IN_VPS
+    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode );
+    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode );
+    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode );
+    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode );
+#else
     READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-  }
-
-  READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
-  assert(uiCode <= 6);
-  pcSPS->setBitDepthY( uiCode + 8 );
-  pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
-
-  READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
-  assert(uiCode <= 6);
-  pcSPS->setBitDepthC( uiCode + 8 );
-  pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
-
+#endif
+  }
+#if REPN_FORMAT_IN_VPS
+  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+#endif
+    READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
+    assert(uiCode <= 6);
+    pcSPS->setBitDepthY( uiCode + 8 );
+    pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
+
+    READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
+    assert(uiCode <= 6);
+    pcSPS->setBitDepthC( uiCode + 8 );
+    pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
   assert(uiCode <= 12);
@@ -1107,7 +1135,55 @@
 #endif
 #endif
+#if REPN_FORMAT_IN_VPS
+  READ_FLAG( uiCode, "rep_format_idx_present_flag"); 
+  vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
+
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" );
+    vps->setVpsNumRepFormats( uiCode + 1 );
+  }
+  else
+  {
+    // default assignment
+    assert (vps->getMaxLayers() <= 16);       // If max_layers_is more than 15, num_rep_formats has to be signaled
+    vps->setVpsNumRepFormats( vps->getMaxLayers() );
+  }
+  for(Int i = 0; i < vps->getVpsNumRepFormats(); i++)
+  {
+    // Read rep_format_structures
+    parseRepFormat( vps->getVpsRepFormat(i) );
+  }
+  
+  // Default assignment for layer 0
+  vps->setVpsRepFormatIdx( 0, 0 );
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    for(Int i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if( vps->getVpsNumRepFormats() > 1 )
+      {
+        READ_CODE( 4, uiCode, "vps_rep_format_idx[i]" );
+        vps->setVpsRepFormatIdx( i, uiCode );
+      }
+      else
+      {
+        // default assignment - only one rep_format() structure
+        vps->setVpsRepFormatIdx( i, 0 );
+      }
+    }
+  }
+  else
+  {
+    // default assignment - each layer assigned each rep_format() structure in the order signaled
+    for(Int i = 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setVpsRepFormatIdx( i, i );
+    }
+  }
+#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
-   READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
-   vps->setMaxOneActiveRefLayerFlag(uiCode);
+  READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
+  vps->setMaxOneActiveRefLayerFlag(uiCode);
 #endif
 
@@ -1163,5 +1239,23 @@
 }
 #endif
-
+#if REPN_FORMAT_IN_VPS
+Void  TDecCavlc::parseRepFormat      ( RepFormat *repFormat )
+{
+  UInt uiCode;
+  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
+  
+  if( repFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    READ_FLAG( uiCode, "separate_colour_plane_flag");        repFormat->setSeparateColourPlaneVpsFlag(uiCode ? true : false);
+  }
+
+  READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
+  READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
+  
+  READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
+  READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
+
+}
+#endif
 #if VPS_VUI
 Void TDecCavlc::parseVPSVUI(TComVPS *vps)
@@ -1285,5 +1379,9 @@
     rpcSlice->setDependentSliceSegmentFlag(false);
   }
+#if REPN_FORMAT_IN_VPS
+  Int numCTUs = ((rpcSlice->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((rpcSlice->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
+#else
   Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight());
+#endif
   Int maxParts = (1<<(sps->getMaxCUDepth()<<1));
   UInt sliceSegmentAddress = 0;
@@ -1801,5 +1899,9 @@
     rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode);
 
+#if REPN_FORMAT_IN_VPS
+    assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
+#else
     assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() );
+#endif
     assert( rpcSlice->getSliceQp() <=  51 );
 
@@ -2132,5 +2234,9 @@
   xReadSvlc( iDQp );
 
+#if REPN_FORMAT_IN_VPS
+  Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
+#else
   Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
   qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) -  qpBdOffsetY;
 
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 389)
@@ -78,4 +78,7 @@
   Void  parseVPSVUI   ( TComVPS* pcVPS );
 #endif 
+#if REPN_FORMAT_IN_VPS
+  Void  parseRepFormat      ( RepFormat *repFormat );
+#endif
 #if SPS_SUB_LAYER_INFO
   Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager );
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCu.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCu.cpp	(revision 389)
@@ -177,6 +177,11 @@
   TComSlice * pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
   UInt uiCurNumParts    = pcPic->getNumPartInCU() >> (uiDepth<<1);
+#if REPN_FORMAT_IN_VPS
+  UInt uiWidth  = pcSlice->getPicWidthInLumaSamples();
+  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   UInt uiGranularityWidth = g_uiMaxCUWidth;
   UInt uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
@@ -230,5 +235,9 @@
   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
+#if REPN_FORMAT_IN_VPS
+  if((!bStartInCU) && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if((!bStartInCU) && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     m_pcEntropyDecoder->decodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
@@ -256,5 +265,9 @@
       if ( bSubInSlice )
       {
+#if REPN_FORMAT_IN_VPS
+        if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcCU->getSlice()->getPicHeightInLumaSamples()           ) )
+#else
         if ( !ruiIsLast && ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
         {
           xDecodeCU( pcCU, uiIdx, uiDepth+1, ruiIsLast );
@@ -385,5 +398,9 @@
   TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
   Bool bStartInCU = pcCU->getSCUAddr()+uiAbsPartIdx+uiCurNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurStartCUAddr();
+#if REPN_FORMAT_IN_VPS
+  if(bStartInCU||( uiRPelX >= pcSlice->getPicWidthInLumaSamples()           ) || ( uiBPelY >= pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if(bStartInCU||( uiRPelX >= pcSlice->getSPS()->getPicWidthInLumaSamples() ) || ( uiBPelY >= pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     bBoundary = true;
@@ -401,5 +418,9 @@
       
       Bool binSlice = (pcCU->getSCUAddr()+uiIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr())&&(pcCU->getSCUAddr()+uiIdx<pcSlice->getSliceSegmentCurEndCUAddr());
+#if REPN_FORMAT_IN_VPS
+      if(binSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
       if(binSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xDecompressCU(pcCU, uiIdx, uiNextDepth );
@@ -494,5 +515,9 @@
   
   //===== inverse transform =====
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
@@ -733,5 +758,9 @@
   pResi = m_ppcYuvResi[uiDepth]->getLumaAddr();
 
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
   m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pResi, 0, m_ppcYuvResi[uiDepth]->getStride(), uiWidth, uiHeight, trMode, 0, piCoeff );
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 389)
@@ -860,5 +860,9 @@
   {
     UInt uiSign;
+#if REPN_FORMAT_IN_VPS
+    Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY();
+#else
     Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
     m_pcTDecBinIf->decodeBinEP(uiSign);
     iDQp = uiDQp;
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 389)
@@ -139,10 +139,26 @@
 
 #if SVC_EXTENSION
-Void TDecTop::xInitILRP(TComSPS *pcSPS)
-{
+#if !REPN_FORMAT_IN_VPS
+Void TDecTop::xInitILRP(TComSPS *pcSPS
+#else
+Void TDecTop::xInitILRP(TComSlice *slice)
+#endif
+{
+#if REPN_FORMAT_IN_VPS
+  TComSPS* pcSPS = slice->getSPS();
+  Int bitDepthY   = slice->getBitDepthY();
+  Int bitDepthC   = slice->getBitDepthC();
+  Int picWidth    = slice->getPicWidthInLumaSamples();
+  Int picHeight   = slice->getPicHeightInLumaSamples();
+#endif
   if(m_layerId>0)
   {
+#if REPN_FORMAT_IN_VPS
+    g_bitDepthY     = bitDepthY;
+    g_bitDepthC     = bitDepthC;
+#else
     g_bitDepthY     = pcSPS->getBitDepthY();
     g_bitDepthC     = pcSPS->getBitDepthC();
+#endif
     g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
     g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
@@ -165,8 +181,16 @@
 
         m_cIlpPic[j] = new  TComPic;
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
 #if SVC_UPSAMPLING
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
 #else
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
         for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
@@ -178,4 +202,6 @@
   }
 }
+
+
 
 Void TDecTop::setILRPic(TComPic *pcPic)
@@ -271,5 +297,9 @@
         //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
         TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
+#if REPN_FORMAT_IN_VPS
+        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
+#else
         if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
+#endif
         {
           rpcPic->setSpatialEnhLayerFlag( i, true );
@@ -288,4 +318,13 @@
 #endif
     
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
 #if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
@@ -295,4 +334,6 @@
                      conformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
+#endif
+
     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
     m_cListPic.pushBack( rpcPic );
@@ -334,4 +375,14 @@
   rpcPic->destroy();
 
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
 #if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
@@ -341,4 +392,5 @@
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
   rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
@@ -548,9 +600,18 @@
   m_apcSlicePilot->setSPS(sps);
   pps->setSPS(sps);
+#if REPN_FORMAT_IN_VPS
   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
+#else
+  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
+#endif
   pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
 
+#if REPN_FORMAT_IN_VPS
+  g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
+  g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
+#else
   g_bitDepthY     = sps->getBitDepthY();
   g_bitDepthC     = sps->getBitDepthC();
+#endif
   g_uiMaxCUWidth  = sps->getMaxCUWidth();
   g_uiMaxCUHeight = sps->getMaxCUHeight();
@@ -569,5 +630,9 @@
 
   m_cSAO.destroy();
+#if REPN_FORMAT_IN_VPS
+  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
+#else
   m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
+#endif
   m_cLoopFilter.create( sps->getMaxCUDepth() );
 }
@@ -684,5 +749,10 @@
   // actual decoding starts here
   xActivateParameterSets();
-
+#if REPN_FORMAT_IN_VPS
+  // Initialize ILRP if needed, only for the current layer  
+  // ILRP intialization should go along with activation of parameters sets, 
+  // although activation of parameter sets itself need not be done for each and every slice!!!
+  xInitILRP(m_apcSlicePilot);
+#endif
   if (m_apcSlicePilot->isNextSlice()) 
   {
@@ -954,4 +1024,5 @@
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
 
+
         Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
         Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
@@ -1123,8 +1194,10 @@
 #endif
 #if SVC_EXTENSION
+#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
   if(m_numLayer>0)
   {
     xInitILRP(sps);
   }
+#endif
 #endif
 }
Index: /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 389)
@@ -211,5 +211,9 @@
   Int       getBLHeight() { return  m_iBLSourceHeight; }
 #endif
+#if REPN_FORMAT_IN_VPS
+  Void      xInitILRP(TComSlice *slice);
+#else
   Void      xInitILRP(TComSPS *pcSPS);
+#endif
   Void      setILRPic(TComPic *pcPic);
 #endif
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 389)
@@ -423,14 +423,25 @@
 #endif
   WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
-  WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
-  assert(pcSPS->getChromaFormatIdc () == 1);
-  // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
-  if( pcSPS->getChromaFormatIdc () == 3 )
-  {
-    WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
-  }
-
-  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
-  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
+#if REPN_FORMAT_IN_VPS
+  if( pcSPS->getLayerId() > 0 )
+  {
+    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" );
+  }
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+#endif
+    WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
+    assert(pcSPS->getChromaFormatIdc () == 1);
+    // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
+    if( pcSPS->getChromaFormatIdc () == 3 )
+    {
+      WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
+    }
+
+    WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
+    WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   Window conf = pcSPS->getConformanceWindow();
 
@@ -444,7 +455,15 @@
   }
 
-  WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
-  WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
-
+#if REPN_FORMAT_IN_VPS
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  {
+    assert( pcSPS->getBitDepthY() >= 8 );
+    assert( pcSPS->getBitDepthC() >= 8 );
+#endif
+    WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
+    WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
+#if REPN_FORMAT_IN_VPS
+  }
+#endif
   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
 
@@ -863,4 +882,30 @@
 #endif
 #endif
+
+#if REPN_FORMAT_IN_VPS
+  WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); 
+
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 4, "vps_num_rep_formats_minus1" );
+  }
+  for(Int i = 0; i < vps->getVpsNumRepFormats(); i++)
+  {
+    // Read rep_format_structures
+    codeRepFormat( vps->getVpsRepFormat(i) );
+  }
+  
+  if( vps->getRepFormatIdxPresentFlag() )
+  {
+    for(Int i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if( vps->getVpsNumRepFormats() > 1 )
+      {
+        WRITE_CODE( vps->getVpsRepFormatIdx(i), 4, "vps_rep_format_idx[i]" );
+      }
+    }
+  }
+#endif
+
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
       WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
@@ -909,5 +954,24 @@
 }
 #endif
-
+#if REPN_FORMAT_IN_VPS
+Void  TEncCavlc::codeRepFormat      ( RepFormat *repFormat )
+{
+  WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );    
+  
+  if( repFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag");      
+  }
+
+  WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" );    
+  WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" );    
+  
+  assert( repFormat->getBitDepthVpsLuma() >= 8 );
+  assert( repFormat->getBitDepthVpsChroma() >= 8 );
+  WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
+  WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );         
+
+}
+#endif
 #if VPS_VUI
 Void TEncCavlc::codeVPSVUI (TComVPS *vps)
@@ -1052,6 +1116,11 @@
     }
 
+#if REPN_FORMAT_IN_VPS
+    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
+    assert( pcSlice->getChromaFormatIdc() == 1 );
+#else
     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
     assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 );
+#endif
     // if( separate_colour_plane_flag  ==  1 )
     //   colour_plane_id                                      u(2)
@@ -1653,5 +1722,9 @@
   Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
 
+#if REPN_FORMAT_IN_VPS
+  Int qpBdOffsetY =  pcCU->getSlice()->getQpBDOffsetY();
+#else
   Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
   iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
 
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.h	(revision 389)
@@ -90,4 +90,7 @@
   Void codeVPSVUI               (TComVPS *vps);
 #endif
+#if REPN_FORMAT_IN_VPS
+  Void  codeRepFormat           ( RepFormat *repFormat );
+#endif
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
   Void  codeSPS                 ( TComSPS* pcSPS );
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 389)
@@ -101,4 +101,26 @@
 
 std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry);     //input
+
+#if REPN_FORMAT_IN_VPS
+struct RepFormatCfg
+{
+  Int   m_chromaFormatIdc;
+  Bool  m_separateColourPlaneFlag;
+  Int   m_picWidthInLumaSamples;
+  Int   m_picHeightInLumaSamples;
+  Int   m_bitDepthLuma;
+  Int   m_bitDepthChroma;
+  RepFormatCfg()
+    : m_chromaFormatIdc         (CHROMA_420)
+    , m_separateColourPlaneFlag (0)
+    , m_picWidthInLumaSamples   (352)
+    , m_picHeightInLumaSamples  (288)
+    , m_bitDepthLuma            (8)
+    , m_bitDepthChroma          (8)
+  {}
+};
+std::istringstream &operator>>(std::istringstream &in, RepFormatCfg &repFormatCfg);
+#endif
+
 //! \ingroup TLibEncoder
 //! \{
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 389)
@@ -412,11 +412,20 @@
   Int iMaxQP;
   Bool isAddLowestQP = false;
+#if REPN_FORMAT_IN_VPS
+  Int lowestQP = -rpcTempCU->getSlice()->getQpBDOffsetY();
+#else
   Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
 
   if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
   {
     Int idQP = m_pcEncCfg->getMaxDeltaQP();
+#if REPN_FORMAT_IN_VPS
     iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
     iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#else
+    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
+    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#endif
     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
     {
@@ -450,5 +459,9 @@
   Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();
   Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());
+#if REPN_FORMAT_IN_VPS
+  Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiBPelY < rpcBestCU->getSlice()->getPicHeightInLumaSamples()           );
+#else
   Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
+#endif
   // We need to split, so don't try these modes.
   if(!bSliceEnd && !bSliceStart && bInsidePicture )
@@ -827,6 +840,11 @@
   {
     Int idQP = m_pcEncCfg->getMaxDeltaQP();
+#if REPN_FORMAT_IN_VPS
+    iMinQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
+    iMaxQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#else
     iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
     iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
+#endif
     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
     {
@@ -890,5 +908,9 @@
 
         Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr();
+#if REPN_FORMAT_IN_VPS
+        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getPicWidthInLumaSamples()           ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
         if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
         {
           if( m_bUseSBACRD )
@@ -1038,6 +1060,11 @@
   UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
   UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+  UInt uiWidth =  pcSlice->getPicWidthInLumaSamples();
+  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   while(uiPosX>=uiWidth||uiPosY>=uiHeight)
   {
@@ -1136,5 +1163,9 @@
     iQpOffset = Int(floor( dQpOffset + 0.49999 ));
   }
+#if REPN_FORMAT_IN_VPS
+  return Clip3(-pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
+#else
   return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
+#endif
 }
 
@@ -1160,5 +1191,9 @@
     pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );
   // We need to split, so don't try these modes.
+#if REPN_FORMAT_IN_VPS
+  if(!bSliceStart&&( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
@@ -1181,5 +1216,9 @@
       uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
       Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr();
+#if REPN_FORMAT_IN_VPS
+      if(bInSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
       if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
@@ -1706,5 +1745,9 @@
   Bool bSliceEnd   = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 
     pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
+#if REPN_FORMAT_IN_VPS
+  if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
   if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
   {
     UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
@@ -1727,5 +1770,9 @@
       Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && 
         rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr();
+#if REPN_FORMAT_IN_VPS
+      if(bInSlice&&( uiSubCULPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiSubCUTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
+#else
       if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
+#endif
       {
         xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY );   // Copy Yuv data to picture Yuv
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 389)
@@ -1095,5 +1095,9 @@
       }
 
+#if REPN_FORMAT_IN_VPS
+      sliceQP = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, sliceQP );
+#else
       sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP );
+#endif
       m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP );
 
@@ -1108,6 +1112,11 @@
     UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
     UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+    UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
+    UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
     UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
     UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
     while(uiPosX>=uiWidth||uiPosY>=uiHeight) 
     {
@@ -1656,6 +1665,12 @@
           uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
           uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+
+#if REPN_FORMAT_IN_VPS
+          uiWidth = pcSlice->getPicWidthInLumaSamples();
+          uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
           uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
           uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
           while(uiPosX>=uiWidth||uiPosY>=uiHeight)
           {
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 389)
@@ -804,5 +804,9 @@
   Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
   
+#if REPN_FORMAT_IN_VPS
+  Int qpBdOffsetY =  pcCU->getSlice()->getQpBDOffsetY();
+#else
   Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
+#endif
   iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
 
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 389)
@@ -1104,5 +1104,9 @@
   pcCU       ->setTrIdxSubParts ( uiTrDepth, uiAbsPartIdx, uiFullDepth );
 
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant    ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
   m_pcTrQuant->setQPforQuant    ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
 #if RDOQ_CHROMA_LAMBDA 
@@ -4610,6 +4614,11 @@
   while((uiWidth>>uiMaxTrMode) < (g_uiMaxCUWidth>>g_uiMaxCUDepth)) uiMaxTrMode--;
   
+#if REPN_FORMAT_IN_VPS
+  qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
+  qpMax =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 );
+#else
   qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
   qpMax =  bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 );
+#endif
 
   rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
@@ -4860,5 +4869,9 @@
     }
 
+#if REPN_FORMAT_IN_VPS
+    m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
     m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
 #if RDOQ_CHROMA_LAMBDA 
@@ -4946,5 +4959,9 @@
       Pel *pcResiCurrY = m_pcQTTempTComYuv[ uiQTTempAccessLayer ].getLumaAddr( absTUPartIdx );
 
+#if REPN_FORMAT_IN_VPS
       m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#else
+      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
       Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
@@ -5195,5 +5212,9 @@
       }
 
+#if REPN_FORMAT_IN_VPS
+      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
       m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
 #if RDOQ_CHROMA_LAMBDA 
@@ -5214,5 +5235,9 @@
         const UInt uiTsSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits();
 
+#if REPN_FORMAT_IN_VPS
+        m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
+#else
         m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
+#endif
 
         Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 389)
@@ -260,5 +260,9 @@
   if(eSliceType!=I_SLICE)
   {
+#if REPN_FORMAT_IN_VPS
+    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
+#else
     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
+#endif
     {
       dQP += m_pcCfg->getGOPEntry(iGOPid).m_QPOffset;
@@ -327,5 +331,9 @@
     }
     
+#if REPN_FORMAT_IN_VPS
+    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
+#else
     iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
+#endif
 
     m_pdRdPicLambda[iDQpIdx] = dLambda;
@@ -412,5 +420,9 @@
   {
     dQP = xGetQPValueAccordingToLambda( dLambda );
+#if REPN_FORMAT_IN_VPS
+    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );    
+#else
     iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );    
+#endif
   }
 
@@ -606,5 +618,9 @@
     }
 
+#if REPN_FORMAT_IN_VPS
+    qp = max( -pcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
+#else
     qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
+#endif
 
     m_pdRdPicLambda[deltqQpIdx] = lambda;
@@ -849,6 +865,11 @@
     pcCU->initCU( rpcPic, uiCUAddr );
 
+#if REPN_FORMAT_IN_VPS
+    Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+    Int width   = min( pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#else
     Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#endif
 
     iSumHad = m_pcCuEncoder->updateLCUDataISlice(pcCU, uiCUAddr, width, height);
@@ -1148,5 +1169,9 @@
 #endif
 
+#if REPN_FORMAT_IN_VPS
+          estQP     = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, estQP );
+#else
           estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
+#endif
 
           m_pcRdCost->setLambda(estLambda);
@@ -1176,6 +1201,11 @@
 #if !M0036_RC_IMPROVEMENT
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
+#if REPN_FORMAT_IN_VPS
+        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->>getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#else
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#endif
         Double MAD = (Double)SAD / (Double)(height * width);
         MAD = MAD * MAD;
@@ -1253,6 +1283,11 @@
 #if !M0036_RC_IMPROVEMENT
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
+#if REPN_FORMAT_IN_VPS
+        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#else
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+#endif
         Double MAD = (Double)SAD / (Double)(height * width);
         MAD = MAD * MAD;
@@ -1919,6 +1954,11 @@
   UInt uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
   UInt uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+  UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
+  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
   {
@@ -1942,6 +1982,11 @@
   uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
   uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
+#if REPN_FORMAT_IN_VPS
+  uiWidth = pcSlice->getPicWidthInLumaSamples();
+  uiHeight = pcSlice->getPicHeightInLumaSamples();
+#else
   uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
   uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
+#endif
   while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
   {
Index: /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 388)
+++ /branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 389)
@@ -679,4 +679,11 @@
   }
 
+#if REPN_FORMAT_IN_VPS
+  m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() );
+  m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  );
+
+  m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma()  - 8) );
+  m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  - 8) );
+#else
   m_cSPS.setBitDepthY( g_bitDepthY );
   m_cSPS.setBitDepthC( g_bitDepthC );
@@ -684,4 +691,5 @@
   m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
   m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
+#endif
 
   m_cSPS.setUseSAO( m_bUseSAO );
@@ -745,5 +753,17 @@
   Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
 
+#if REPN_FORMAT_IN_VPS
+  Int lowestQP;
+  if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
+  {
+    lowestQP = - m_cSPS.getQpBDOffsetY();
+  }
+  else
+  {
+    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
+  }
+#else
   Int lowestQP = - m_cSPS.getQpBDOffsetY();
+#endif
 
   if(getUseLossless())
@@ -1212,4 +1232,5 @@
 
 #if SVC_EXTENSION
+#if !REPN_FORMAT_IN_VPS
 Void TEncTop::xInitILRP()
 {
@@ -1245,5 +1266,57 @@
   }
 }
-
+#else
+Void TEncTop::xInitILRP()
+{
+  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
+  Int bitDepthY,bitDepthC,picWidth,picHeight;
+
+  if( m_cSPS.getUpdateRepFormatFlag() )
+  {
+    bitDepthY   = m_cSPS.getBitDepthY();
+    bitDepthC   = m_cSPS.getBitDepthC();
+    picWidth    = m_cSPS.getPicWidthInLumaSamples();
+    picHeight   = m_cSPS.getPicHeightInLumaSamples();
+  }
+  else
+  {
+    bitDepthY   = repFormat->getBitDepthVpsLuma();
+    bitDepthC   = repFormat->getBitDepthVpsChroma();
+    picWidth    = repFormat->getPicWidthVpsInLumaSamples();
+    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
+  }
+  
+  if(m_layerId > 0)
+  {
+    g_bitDepthY     = bitDepthY;
+    g_bitDepthC     = bitDepthC;
+    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
+    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
+    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
+    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
+
+    Int  numReorderPics[MAX_TLAYER];
+    Window &conformanceWindow = m_cSPS.getConformanceWindow();
+    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
+
+    if (m_cIlpPic[0] == NULL)
+    {
+      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
+      {
+        m_cIlpPic[j] = new  TComPic;
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
+#else
+        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
+        {
+          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
+        }
+      }
+    }
+  }
+}
+#endif
 Void TEncTop::setILRPic(TComPic *pcPic)
 {
