Index: /trunk/cfg/encoder_intra_he10.cfg
===================================================================
--- /trunk/cfg/encoder_intra_he10.cfg	(revision 493)
+++ /trunk/cfg/encoder_intra_he10.cfg	(revision 494)
@@ -43,5 +43,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # internal bit-depth = BitDepth + BitIncrement
+#InternalBitDepth             : 10          # codec operating bit-depth
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_intra_main.cfg
===================================================================
--- /trunk/cfg/encoder_intra_main.cfg	(revision 493)
+++ /trunk/cfg/encoder_intra_main.cfg	(revision 494)
@@ -48,5 +48,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 8           # codec operating bit-depth
+#InternalBitDepth             : 8           # codec operating bit-depth
+InternalBitDepth0             : 8           # codec operating bit-depth for layer 0
+InternalBitDepth1             : 8           # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_intra_main10.cfg
===================================================================
--- /trunk/cfg/encoder_intra_main10.cfg	(revision 493)
+++ /trunk/cfg/encoder_intra_main10.cfg	(revision 494)
@@ -48,5 +48,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # codec operating bit-depth
+#InternalBitDepth             : 10          # codec operating bit-depth
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_lowdelay_P_he10.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_P_he10.cfg	(revision 493)
+++ /trunk/cfg/encoder_lowdelay_P_he10.cfg	(revision 494)
@@ -50,5 +50,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # internal bit-depth = BitDepth + BitIncrement
+#InternalBitDepth             : 10          # internal bit-depth = BitDepth + BitIncrement
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_lowdelay_P_main.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_P_main.cfg	(revision 493)
+++ /trunk/cfg/encoder_lowdelay_P_main.cfg	(revision 494)
@@ -53,5 +53,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 8           # codec operating bit-depth
+#InternalBitDepth             : 8           # codec operating bit-depth
+InternalBitDepth0             : 8           # codec operating bit-depth for layer 0
+InternalBitDepth1             : 8           # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_lowdelay_P_main10.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_P_main10.cfg	(revision 493)
+++ /trunk/cfg/encoder_lowdelay_P_main10.cfg	(revision 494)
@@ -55,5 +55,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # codec operating bit-depth
+#InternalBitDepth             : 10          # codec operating bit-depth
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_lowdelay_he10.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_he10.cfg	(revision 493)
+++ /trunk/cfg/encoder_lowdelay_he10.cfg	(revision 494)
@@ -48,5 +48,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # internal bit-depth = BitDepth + BitIncrement
+#InternalBitDepth             : 10          # codec operating bit-depth
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_lowdelay_main.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_main.cfg	(revision 493)
+++ /trunk/cfg/encoder_lowdelay_main.cfg	(revision 494)
@@ -53,5 +53,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 8           # codec operating bit-depth
+#InternalBitDepth             : 8           # codec operating bit-depth
+InternalBitDepth0             : 8           # codec operating bit-depth for layer 0
+InternalBitDepth1             : 8           # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_lowdelay_main10.cfg
===================================================================
--- /trunk/cfg/encoder_lowdelay_main10.cfg	(revision 493)
+++ /trunk/cfg/encoder_lowdelay_main10.cfg	(revision 494)
@@ -53,5 +53,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # codec operating bit-depth
+#InternalBitDepth             : 10          # codec operating bit-depth
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_randomaccess_he10.cfg
===================================================================
--- /trunk/cfg/encoder_randomaccess_he10.cfg	(revision 493)
+++ /trunk/cfg/encoder_randomaccess_he10.cfg	(revision 494)
@@ -28,13 +28,4 @@
 Frame8:  B    7   4        0.68     0           2                4         -1 -3 -7 1             1      -2        5         1 1 1 1 0
 
-FrameEL1:  B    8   1        0.442    0           4                4         -8 -10 -12 -16         0
-FrameEL2:  B    4   2        0.3536   0           2                3         -4 -6  4               1       4        5         1 1 0 0 1
-FrameEL3:  B    2   3        0.3536   0           2                4         -2 -4  2 6             1       2        4         1 1 1 1
-FrameEL4:  B    1   4        0.68     0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1
-FrameEL5:  B    3   4        0.68     0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0
-FrameEL6:  B    6   3        0.3536   0           2                4         -2 -4 -6 2             0
-FrameEL7:  B    5   4        0.68     0           2                4         -1 -5  1 3             0
-FrameEL8:  B    7   4        0.68     0           2                4         -1 -3 -7 1             0
-
 ListCombination               : 1           # Use combined list for uni-prediction in B-slices
 
@@ -62,5 +53,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # internal bit-depth = BitDepth + BitIncrement
+#InternalBitDepth             : 10          # codec operating bit-depth
+InternalBitDepth0             : 10          # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10          # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_randomaccess_main.cfg
===================================================================
--- /trunk/cfg/encoder_randomaccess_main.cfg	(revision 493)
+++ /trunk/cfg/encoder_randomaccess_main.cfg	(revision 494)
@@ -31,13 +31,4 @@
 Frame7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             1       1        5         1 0 1 1 1         0
 Frame8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             1      -2        5         1 1 1 1 0         0
-
-FrameEL1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0                                          0
-FrameEL2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1       0
-FrameEL3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1         0
-FrameEL4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1       0
-FrameEL5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0       0
-FrameEL6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             0                                          1    1 1 0 1
-FrameEL7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             0                                          0
-FrameEL8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             0                                          1    1 1 0 1
 #=========== Motion Search =============
 FastSearch                    : 1           # 0:Full search  1:TZ search
@@ -65,5 +56,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 8           # codec operating bit-depth
+#InternalBitDepth             : 8           # codec operating bit-depth
+InternalBitDepth0             : 8           # codec operating bit-depth for layer 0
+InternalBitDepth1             : 8           # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/encoder_randomaccess_main10.cfg
===================================================================
--- /trunk/cfg/encoder_randomaccess_main10.cfg	(revision 493)
+++ /trunk/cfg/encoder_randomaccess_main10.cfg	(revision 494)
@@ -31,13 +31,4 @@
 Frame7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             1       1        5         1 0 1 1 1         0
 Frame8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             1      -2        5         1 1 1 1 0         0
-
-FrameEL1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0                                          0
-FrameEL2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1       0
-FrameEL3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1         0
-FrameEL4:  B    1   4        0.68     0            0              0           2                4         -1  1  3 7             1       1        5         1 0 1 1 1       0
-FrameEL5:  B    3   4        0.68     0            0              0           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0       0
-FrameEL6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             0                                          1    1 1 0 1
-FrameEL7:  B    5   4        0.68     0            0              0           2                4         -1 -5  1 3             0                                          0
-FrameEL8:  B    7   4        0.68     0            0              0           2                4         -1 -3 -7 1             0                                          1    1 1 0 1
 #=========== Motion Search =============
 FastSearch                    : 1           # 0:Full search  1:TZ search
@@ -65,5 +56,7 @@
 
 #=========== Misc. ============
-InternalBitDepth              : 10          # codec operating bit-depth
+#InternalBitDepth             : 10           # codec operating bit-depth
+InternalBitDepth0             : 10           # codec operating bit-depth for layer 0
+InternalBitDepth1             : 10           # codec operating bit-depth for layer 1
 
 #=========== Coding Tools =================
Index: /trunk/cfg/layers.cfg
===================================================================
--- /trunk/cfg/layers.cfg	(revision 493)
+++ /trunk/cfg/layers.cfg	(revision 494)
@@ -3,4 +3,5 @@
 ScalabilityMask1              : 0           # Multiview
 ScalabilityMask2              : 1           # Scalable
+ScalabilityMask3              : 0           # Auxiliary pictures
 AdaptiveResolutionChange      : 0           # Resolution change frame (0: disable)
 MaxTidRefPresentFlag          : 1           # max_tid_ref_present_flag (0=not present, 1=present(default))
Index: /trunk/cfg/per-sequence-svc/BQTerrace-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BQTerrace-1.5x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/BQTerrace-1.5x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 600         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : BQTerrace_1280x720_60_zerophase_0.9pi.yuv
 FrameRate0                    : 60          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : BQTerrace_1920x1080_60.yuv
 FrameRate1                    : 60          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BQTerrace-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/BQTerrace-2x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 600         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : BQTerrace_960x540_60_zerophase_0.9pi.yuv
 FrameRate0                    : 60          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : BQTerrace_1920x1080_60.yuv
 FrameRate1                    : 60          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BQTerrace-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BQTerrace-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/BQTerrace-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 600         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : BQTerrace_1920x1080_60.yuv
 FrameRate0                    : 60          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : BQTerrace_1920x1080_60.yuv
 FrameRate1                    : 60          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 64          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/BasketballDrive-1.5x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 500         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : BasketballDrive_1280x720_50_zerophase_0.9pi.yuv
 FrameRate0                    : 50          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : BasketballDrive_1920x1080_50.yuv
 FrameRate1                    : 50          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BasketballDrive-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/BasketballDrive-2x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 500         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : BasketballDrive_960x540_50_zerophase_0.9pi.yuv
 FrameRate0                    : 50          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : BasketballDrive_1920x1080_50.yuv
 FrameRate1                    : 50          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/BasketballDrive-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/BasketballDrive-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/BasketballDrive-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 500         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : BasketballDrive_1920x1080_50.yuv
 FrameRate0                    : 50          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : BasketballDrive_1920x1080_50.yuv
 FrameRate1                    : 50          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Cactus-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Cactus-1.5x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Cactus-1.5x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 500         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Cactus_1280x720_50_zerophase_0.9pi.yuv
 FrameRate0                    : 50          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Cactus_1920x1080_50.yuv
 FrameRate1                    : 50          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Cactus-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Cactus-2x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 500         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Cactus_960x540_50_zerophase_0.9pi.yuv
 FrameRate0                    : 50          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Cactus_1920x1080_50.yuv
 FrameRate1                    : 50          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Cactus-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Cactus-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Cactus-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 500         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Cactus_1920x1080_50.yuv
 FrameRate0                    : 50          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Cactus_1920x1080_50.yuv
 FrameRate1                    : 50          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 48          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Kimono-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Kimono-1.5x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Kimono-1.5x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 240         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Kimono1_1280x720_24_zerophase_0.9pi.yuv
 FrameRate0                    : 24          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Kimono1_1920x1080_24.yuv
 FrameRate1                    : 24          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Kimono-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Kimono-2x.cfg	(revision 494)
@@ -1,21 +1,23 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 240         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
-InputFile0                    : Kimono1_960x540_24_zerophase_0.9pi.yuv
+InputFile0                    : O:/Kimono1_960x540_24_zerophase_0.9pi.yuv
 FrameRate0                    : 24          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
 QP0                           : 22
 
-InputFile1                    : Kimono1_1920x1080_24.yuv
+InputFile1                    : O:/Kimono1_1920x1080_24.yuv
 FrameRate1                    : 24          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Kimono-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Kimono-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Kimono-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 240         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Kimono1_1920x1080_24.yuv
 FrameRate0                    : 24          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Kimono1_1920x1080_24.yuv
 FrameRate1                    : 24          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/ParkScene-1.5x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/ParkScene-1.5x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/ParkScene-1.5x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 240         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : ParkScene_1280x720_24_zerophase_0.9pi.yuv
 FrameRate0                    : 24          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 720         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : ParkScene_1920x1080_24.yuv
 FrameRate1                    : 24          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/ParkScene-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/ParkScene-2x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 240         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : ParkScene_960x540_24_zerophase_0.9pi.yuv
 FrameRate0                    : 24          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 960         # Input  frame width
 SourceHeight0                 : 540         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : ParkScene_1920x1080_24.yuv
 FrameRate1                    : 24          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/ParkScene-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/ParkScene-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/ParkScene-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 240         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : ParkScene_1920x1080_24.yuv
 FrameRate0                    : 24          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1920        # Input  frame width
 SourceHeight0                 : 1080        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : ParkScene_1920x1080_24.yuv
 FrameRate1                    : 24          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 1920        # Input  frame width
 SourceHeight1                 : 1080        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 24          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/PeopleOnStreet-2x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 150         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : PeopleOnStreet_1280x800_30_crop_zerophase_0.9pi.yuv
 FrameRate0                    : 30          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : PeopleOnStreet_2560x1600_30_crop.yuv
 FrameRate1                    : 30          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/PeopleOnStreet-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 150         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : PeopleOnStreet_2560x1600_30_crop.yuv
 FrameRate0                    : 30          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : PeopleOnStreet_2560x1600_30_crop.yuv
 FrameRate1                    : 30          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Traffic-2x.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Traffic-2x.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Traffic-2x.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 150         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Traffic_1280x800_30_crop_zerophase_0.9pi.yuv
 FrameRate0                    : 30          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 1280        # Input  frame width
 SourceHeight0                 : 800         # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Traffic_2560x1600_30_crop.yuv
 FrameRate1                    : 30          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
-RepFormatIdx1				  : 1 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 1           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/cfg/per-sequence-svc/Traffic-SNR.cfg
===================================================================
--- /trunk/cfg/per-sequence-svc/Traffic-SNR.cfg	(revision 493)
+++ /trunk/cfg/per-sequence-svc/Traffic-SNR.cfg	(revision 494)
@@ -1,12 +1,13 @@
-InputBitDepth                 : 8           # Input bitdepth
 FrameSkip                     : 0           # Number of frames to be skipped in input
 FramesToBeEncoded             : 150         # Number of frames to be coded
+PhaseAlignment                : 0           # Sample location alignment between layers (0: zero position aligned, 1: central position aligned)
 
 #======== File I/O ===============
 InputFile0                    : Traffic_2560x1600_30_crop.yuv
 FrameRate0                    : 30          # Frame Rate per second
+InputBitDepth0                : 8           # Input bitdepth for layer 0
 SourceWidth0                  : 2560        # Input  frame width
 SourceHeight0                 : 1600        # Input  frame height
-RepFormatIdx0				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx0                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod0                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode0              : 1           # conformance mode
@@ -15,7 +16,8 @@
 InputFile1                    : Traffic_2560x1600_30_crop.yuv
 FrameRate1                    : 30          # Frame Rate per second
+InputBitDepth1                : 8           # Input bitdepth for layer 1
 SourceWidth1                  : 2560        # Input  frame width
 SourceHeight1                 : 1600        # Input  frame height
-RepFormatIdx1				  : 0 			# Index of corresponding rep_format() in the VPS
+RepFormatIdx1                 : 0           # Index of corresponding rep_format() in the VPS
 IntraPeriod1                  : 32          # Period of I-Frame ( -1 = only first)
 ConformanceMode1              : 1           # conformance mode
Index: /trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 493)
+++ /trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -80,5 +80,5 @@
     m_pchBitstreamFile = NULL;
   }
-#if SVC_EXTENSION   
+#if SVC_EXTENSION
   for( Int i = 0; i < m_tgtLayerId; i++ )
   {
@@ -88,5 +88,5 @@
       m_pchReconFile[i] = NULL;
     }
-  }  
+  }
 #if AVC_BASE
   if( m_pchBLReconFile )
@@ -225,4 +225,9 @@
     if (bNewPicture || !bitstreamFile)
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      //Bug fix: The bit depth was not set correctly for each layer when doing DBF
+      g_bitDepthY = g_bitDepthYLayer[curLayerId];
+      g_bitDepthC = g_bitDepthCLayer[curLayerId];
+#endif
       m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
 #if EARLY_REF_PIC_MARKING
@@ -235,5 +240,5 @@
       if ( m_pchReconFile[curLayerId] && !openedReconFile[curLayerId] )
       {
-        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }        
+        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
         if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
 
@@ -242,5 +247,5 @@
         openedReconFile[curLayerId] = true;
       }
-      if ( bNewPicture && bNewPOC && 
+      if ( bNewPicture && bNewPOC &&
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
             || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
@@ -276,5 +281,5 @@
   }
 #endif
-  pcBLPic.destroy();  
+  pcBLPic.destroy();
 
   for(UInt layer = layerIdmin; layer <= m_tgtLayerId; layer++)
@@ -285,5 +290,5 @@
     m_acTDecTop[layer].deletePicBuffer();
   }
-  
+
   // destroy internal classes
   xDestroyDecLib();
@@ -394,5 +399,5 @@
         openedReconFile = true;
       }
-      if ( bNewPicture && 
+      if ( bNewPicture &&
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
             || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
@@ -410,5 +415,5 @@
     }
   }
-  
+
 #if SYNTAX_OUTPUT
   if( streamSyntaxFile.is_open() )
@@ -417,9 +422,9 @@
   }
 #endif
-  
+
   xFlushOutput( pcListPic );
   // delete buffers
   m_cTDecTop.deletePicBuffer();
-  
+
   // destroy internal classes
   xDestroyDecLib();
@@ -435,5 +440,5 @@
 #if SVC_EXTENSION
   // initialize global variables
-  initROM();  
+  initROM();
 
   for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
@@ -445,5 +450,5 @@
     m_acTDecTop[layer].create();
 
-    m_acTDecTop[layer].setLayerDec(m_apcTDecTop);   
+    m_acTDecTop[layer].setLayerDec(m_apcTDecTop);
   }
 #else
@@ -474,5 +479,5 @@
     m_cTVideoIOYuvReconFile. close();
   }
-  
+
   // destroy decoder class
   m_cTDecTop.destroy();
@@ -566,5 +571,10 @@
 
 #else
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          // Compile time bug-fix
+          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#else
           m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#endif
             conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
             conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
@@ -723,5 +733,5 @@
   {
     return;
-  } 
+  }
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
 
@@ -759,5 +769,10 @@
 
 #else
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          // Compile time bug-fix
+          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#else
           m_cTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
+#endif
             conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
             conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
@@ -913,5 +928,5 @@
         pcPic = NULL;
       }
-#endif    
+#endif
 #endif
       iterPic++;
Index: /trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 493)
+++ /trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 494)
@@ -221,18 +221,20 @@
   }
 #endif
-#if EXTERNAL_USEDBYCURR_N0082
-  if(entry.m_numRefPics>0){
-    in>>entry.m_UseExtusedByCurrPic;
-    if(entry.m_UseExtusedByCurrPic)
-    {
-      for ( Int i = 0; i < entry.m_numRefPics; i++ )
-      {
-        in>>entry.m_ExtusedByCurrPic[i];
-      }
-    }
-  }
-#endif
   return in;
 }
+
+#if AUXILIARY_PICTURES
+static inline ChromaFormat numberToChromaFormat(const Int val)
+{
+  switch (val)
+  {
+    case 400: return CHROMA_400; break;
+    case 420: return CHROMA_420; break;
+    case 422: return CHROMA_422; break;
+    case 444: return CHROMA_444; break;
+    default:  return NUM_CHROMA_FORMAT;
+  }
+}
+#endif
 
 #if SVC_EXTENSION
@@ -362,4 +364,22 @@
   Int*    cfg_IntraPeriod   [MAX_LAYERS];
   Int*    cfg_conformanceMode  [MAX_LAYERS];
+#if LAYER_CTB
+  // coding unit (CU) definition
+  UInt*      cfg_uiMaxCUWidth[MAX_LAYERS];                                   ///< max. CU width in pixel
+  UInt*      cfg_uiMaxCUHeight[MAX_LAYERS];                                  ///< max. CU height in pixel
+  UInt*      cfg_uiMaxCUDepth[MAX_LAYERS];                                   ///< max. CU depth
+  
+  // transfom unit (TU) definition
+  UInt*      cfg_uiQuadtreeTULog2MaxSize[MAX_LAYERS];
+  UInt*      cfg_uiQuadtreeTULog2MinSize[MAX_LAYERS];
+  
+  UInt*      cfg_uiQuadtreeTUMaxDepthInter[MAX_LAYERS];
+  UInt*      cfg_uiQuadtreeTUMaxDepthIntra[MAX_LAYERS];
+#endif
+#if AUXILIARY_PICTURES
+  Int      cfg_tmpChromaFormatIDC  [MAX_LAYERS];
+  Int      cfg_tmpInputChromaFormat[MAX_LAYERS];
+  Int*     cfg_auxId               [MAX_LAYERS];
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -379,5 +399,4 @@
   string* cfg_predLayerIdsPtr    [MAX_LAYERS];
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   string    cfg_scaledRefLayerLeftOffset [MAX_LAYERS];
   string    cfg_scaledRefLayerTopOffset [MAX_LAYERS];
@@ -390,5 +409,4 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
-#endif
 #if RC_SHVC_HARMONIZATION
   Bool*   cfg_RCEnableRateControl  [MAX_LAYERS];
@@ -400,4 +418,12 @@
   Bool*   cfg_RCForceIntraQP       [MAX_LAYERS];
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  Int*    cfg_InputBitDepthY    [MAX_LAYERS];
+  Int*    cfg_InternalBitDepthY [MAX_LAYERS];
+  Int*    cfg_InputBitDepthC    [MAX_LAYERS];
+  Int*    cfg_InternalBitDepthC [MAX_LAYERS];
+  Int*    cfg_OutputBitDepthY   [MAX_LAYERS];
+  Int*    cfg_OutputBitDepthC   [MAX_LAYERS];
+#endif
 #if N0120_MAX_TID_REF_CFG
   Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
@@ -416,4 +442,17 @@
     cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
     cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
+#if LAYER_CTB
+    // coding unit (CU) definition
+    cfg_uiMaxCUWidth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUWidth;
+    cfg_uiMaxCUHeight[layer] = &m_acLayerCfg[layer].m_uiMaxCUHeight;
+    cfg_uiMaxCUDepth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUDepth;
+
+    // transfom unit (TU) definition.
+    cfg_uiQuadtreeTULog2MaxSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize;
+    cfg_uiQuadtreeTULog2MinSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize;
+
+    cfg_uiQuadtreeTUMaxDepthInter[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter;
+    cfg_uiQuadtreeTUMaxDepthIntra[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra;
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -429,5 +468,4 @@
     cfg_predLayerIdsPtr     [layer]  = &cfg_predLayerIds[layer];
 #endif
-#if SCALED_REF_LAYER_OFFSETS
     cfg_numScaledRefLayerOffsets [layer] = &m_acLayerCfg[layer].m_numScaledRefLayerOffsets;
     for(Int i = 0; i < MAX_LAYERS; i++)
@@ -438,5 +476,4 @@
       cfg_scaledRefLayerBottomOffsetPtr[layer] = &cfg_scaledRefLayerBottomOffset[layer];
     }
-#endif
 #if RC_SHVC_HARMONIZATION
     cfg_RCEnableRateControl[layer]   = &m_acLayerCfg[layer].m_RCEnableRateControl;
@@ -448,7 +485,18 @@
     cfg_RCForceIntraQP[layer]        = &m_acLayerCfg[layer].m_RCForceIntraQP;
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  cfg_InputBitDepthY   [layer] = &m_acLayerCfg[layer].m_inputBitDepthY;
+  cfg_InternalBitDepthY[layer] = &m_acLayerCfg[layer].m_internalBitDepthY;
+  cfg_InputBitDepthC   [layer] = &m_acLayerCfg[layer].m_inputBitDepthC;
+  cfg_InternalBitDepthC[layer] = &m_acLayerCfg[layer].m_internalBitDepthC;
+  cfg_OutputBitDepthY  [layer] = &m_acLayerCfg[layer].m_outputBitDepthY;
+  cfg_OutputBitDepthC  [layer] = &m_acLayerCfg[layer].m_outputBitDepthC;
+#endif
 #if N0120_MAX_TID_REF_CFG
     cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1; 
 #endif 
+#if AUXILIARY_PICTURES
+    cfg_auxId[layer]                = &m_acLayerCfg[layer].m_auxId; 
+#endif
   }
 #if AVC_BASE
@@ -461,10 +509,10 @@
   string  cfg_tileSets;
 #endif
-#else
+#else //SVC_EXTENSION
   string cfg_InputFile;
   string cfg_BitstreamFile;
   string cfg_ReconFile;
   string cfg_dQPFile;
-#endif
+#endif //SVC_EXTENSION
   string cfg_ColumnWidth;
   string cfg_RowHeight;
@@ -487,4 +535,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 O0215_PHASE_ALIGNMENT
+  ("PhaseAlignment",          m_phaseAlignFlag, false, "indicate the sample location alignment between layers (0: zero position aligned, 1: central position aligned)")
+#endif
 #if REPN_FORMAT_IN_VPS
   ("RepFormatIdx%d",          cfg_repFormatIdx, -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
@@ -504,8 +555,16 @@
 #endif
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
+#if AUXILIARY_PICTURES
+  ("InputChromaFormat%d",     cfg_tmpInputChromaFormat,  420, MAX_LAYERS, "InputChromaFormatIDC for layer %d")
+  ("ChromaFormatIDC%d,-cf",   cfg_tmpChromaFormatIDC,    420, MAX_LAYERS, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat) for layer %d")
+  ("AuxId%d",                 cfg_auxId,                 0,   MAX_LAYERS, "Auxilary picture ID for layer %d (0: Not aux pic, 1: Alpha plane, 2: Depth picture, 3: Cb enh, 4: Cr enh")
+#endif
   ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
 #if SCALABILITY_MASK_E0104
   ("ScalabilityMask1",        m_scalabilityMask[1], 0, "scalability_mask[1] (multiview)")
   ("ScalabilityMask2",        m_scalabilityMask[2], 1, "scalability_mask[2] (scalable)" )
+#if AUXILIARY_PICTURES
+  ("ScalabilityMask3",        m_scalabilityMask[3], 0, "scalability_mask[3] (auxiliary pictures)" )
+#endif
 #else
   ("ScalabilityMask0",        m_scalabilityMask[0], 0, "scalability_mask[0] (multiview)")
@@ -513,4 +572,5 @@
 #endif
   ("BitstreamFile,b",         cfg_BitstreamFile, string(""), "Bitstream output file name")
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   ("InputBitDepth",           m_inputBitDepthY,    8, "Bit-depth of input file")
   ("OutputBitDepth",          m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
@@ -520,5 +580,5 @@
   ("OutputBitDepthC",         m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
   ("InternalBitDepthC",       m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
-#if SCALED_REF_LAYER_OFFSETS
+#endif
   ("NumScaledRefLayerOffsets%d",    cfg_numScaledRefLayerOffsets,     0, MAX_LAYERS,  "Number of scaled offset layer sets ")
   ("ScaledRefLayerLeftOffset%d",   cfg_scaledRefLayerLeftOffsetPtr,  string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
@@ -530,4 +590,12 @@
   ("ScaledRefLayerBottomOffset%d", cfg_scaledRefLayerBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
                                                                  " bottom-right luma sample of the EL picture, in units of two luma samples")
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  ("InputBitDepth%d",       cfg_InputBitDepthY,    8, MAX_LAYERS, "Bit-depth of input file for layer %d")
+  ("InternalBitDepth%d",    cfg_InternalBitDepthY, 0, MAX_LAYERS, "Bit-depth the codec operates at. (default:InputBitDepth) for layer %d ")
+//                                                       "If different to InputBitDepth, source data will be converted")
+  ("InputBitDepthC%d",      cfg_InputBitDepthC,    0, MAX_LAYERS, "As per InputBitDepth but for chroma component. (default:InputBitDepth) for layer %d")
+  ("InternalBitDepthC%d",   cfg_InternalBitDepthC, 0, MAX_LAYERS, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth) for layer %d")
+  ("OutputBitDepth%d",      cfg_OutputBitDepthY,   0, MAX_LAYERS, "Bit-depth of output file (default:InternalBitDepth)")
+  ("OutputBitDepthC%d",     cfg_OutputBitDepthC,   0, MAX_LAYERS, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
 #endif
 #if N0120_MAX_TID_REF_CFG
@@ -546,5 +614,5 @@
   ("IlSampleOnlyPred%d",       m_ilSampleOnlyPred, 0, MAX_LAYERS, "Set inter_layer_sample_pred_only_flag for all slices")
 #endif
-#else
+#else //SVC_EXTENSION
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
   ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
@@ -559,4 +627,8 @@
   ("OutputBitDepthC",       m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
   ("InternalBitDepthC",     m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
+#if AUXILIARY_PICTURES
+  ("InputChromaFormat",     tmpInputChromaFormat,                       420, "InputChromaFormatIDC")
+  ("ChromaFormatIDC,-cf",   tmpChromaFormat,                             0, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat)")
+#endif
   ("ConformanceMode",       m_conformanceMode,     0, "Window conformance mode (0: no window, 1:automatic padding, 2:padding, 3:conformance")
   ("HorizontalPadding,-pdx",m_aiPad[0],            0, "Horizontal source padding for conformance window mode 2")
@@ -567,5 +639,5 @@
   ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
   ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
-#endif
+#endif //SVC_EXTENSION
 
   //Field coding parameters
@@ -574,5 +646,4 @@
   ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
   ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
-  
   // Profile and level
   ("Profile", m_profile,   Profile::NONE, "Profile to be used when encoding (Incomplete)")
@@ -585,4 +656,34 @@
   ("FrameOnly",         m_frameOnlyConstraintFlag, false, "Indicate that the bitstream contains only frames")
 
+#if LAYER_CTB
+  // Unit definition parameters
+  ("MaxCUWidth%d",              cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU width")
+  ("MaxCUHeight%d",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU height")
+  // todo: remove defaults from MaxCUSize
+  ("MaxCUSize%d,s%d",           cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxCUSize%d,s%d",           cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxPartitionDepth%d,h%d",   cfg_uiMaxCUDepth,              4u, MAX_LAYERS, "CU depth")
+  
+  ("QuadtreeTULog2MaxSize%d",   cfg_uiQuadtreeTULog2MaxSize,   6u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
+  ("QuadtreeTULog2MinSize%d",   cfg_uiQuadtreeTULog2MinSize,   2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
+  
+  ("QuadtreeTUMaxDepthIntra%d", cfg_uiQuadtreeTUMaxDepthIntra, 1u, MAX_LAYERS, "Depth of TU tree for intra CUs")
+  ("QuadtreeTUMaxDepthInter%d", cfg_uiQuadtreeTUMaxDepthInter, 2u, MAX_LAYERS, "Depth of TU tree for inter CUs")
+
+
+  // set the same CU realted settings across all the layers if config file parameters are not layer specific
+  ("MaxCUWidth",              cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU width")
+  ("MaxCUHeight",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU height")
+  // todo: remove defaults from MaxCUSize
+  ("MaxCUSize,s",             cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxCUSize,s",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU size")
+  ("MaxPartitionDepth,h",     cfg_uiMaxCUDepth,              4u, MAX_LAYERS, "CU depth")
+  
+  ("QuadtreeTULog2MaxSize",   cfg_uiQuadtreeTULog2MaxSize,   6u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
+  ("QuadtreeTULog2MinSize",   cfg_uiQuadtreeTULog2MinSize,   2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
+  
+  ("QuadtreeTUMaxDepthIntra", cfg_uiQuadtreeTUMaxDepthIntra, 1u, MAX_LAYERS, "Depth of TU tree for intra CUs")
+  ("QuadtreeTUMaxDepthInter", cfg_uiQuadtreeTUMaxDepthInter, 2u, MAX_LAYERS, "Depth of TU tree for inter CUs")
+#else
   // Unit definition parameters
   ("MaxCUWidth",              m_uiMaxCUWidth,             64u)
@@ -598,4 +699,5 @@
   ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs")
   ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs")
+#endif
   
   // Coding structure paramters
@@ -864,11 +966,4 @@
     opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
   }
-#if FINAL_RPL_CHANGE_N0082
-  for(Int i=1; i<MAX_GOP+1; i++) {
-    std::ostringstream cOSS;
-    cOSS<<"FrameEL"<<i;
-    opts.addOptions()(cOSS.str(), m_acLayerCfg[1].m_GOPListLayer[i-1], GOPEntry());
-  }
-#endif
   po::setDefaults(opts);
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
@@ -921,10 +1016,10 @@
   m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
 #endif
-#else
+#else //SVC_EXTENSION
   m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
-#endif  
+#endif //SVC_EXTENSION 
 
   Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
@@ -985,5 +1080,5 @@
     m_pRowHeight = NULL;
   }
-#if SCALED_REF_LAYER_OFFSETS
+#if SVC_EXTENSION
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1055,5 +1150,4 @@
     }
   }
-#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -1153,4 +1247,11 @@
   }
 #endif
+#if AUXILIARY_PICTURES
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    m_acLayerCfg[layer].m_InputChromaFormat =  numberToChromaFormat(cfg_tmpChromaFormatIDC[layer]);
+    m_acLayerCfg[layer].m_chromaFormatIDC = ((cfg_tmpChromaFormatIDC[layer] == 0) ? (m_acLayerCfg[layer].m_InputChromaFormat ) : (numberToChromaFormat(cfg_tmpChromaFormatIDC[layer])));
+  }
+#endif
   for(Int layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -1185,14 +1286,18 @@
   }
 #endif
+#endif //SVC_EXTENSION
   m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
 
-#if REPN_FORMAT_IN_VPS_123
+  /* rules for input, output and internal bitdepths as per help text */
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
   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_acLayerCfg[layer].m_internalBitDepthY) { m_acLayerCfg[layer].m_internalBitDepthY = m_acLayerCfg[layer].m_inputBitDepthY; }
+    if (!m_acLayerCfg[layer].m_internalBitDepthC) { m_acLayerCfg[layer].m_internalBitDepthC = m_acLayerCfg[layer].m_internalBitDepthY; }
+    if (!m_acLayerCfg[layer].m_inputBitDepthC) { m_acLayerCfg[layer].m_inputBitDepthC = m_acLayerCfg[layer].m_inputBitDepthY; }
+    if (!m_acLayerCfg[layer].m_outputBitDepthY) { m_acLayerCfg[layer].m_outputBitDepthY = m_acLayerCfg[layer].m_internalBitDepthY; }
+    if (!m_acLayerCfg[layer].m_outputBitDepthC) { m_acLayerCfg[layer].m_outputBitDepthC = m_acLayerCfg[layer].m_internalBitDepthC; }
+  }
+#else
   if (!m_internalBitDepthY) { m_internalBitDepthY = m_inputBitDepthY; }
   if (!m_internalBitDepthC) { m_internalBitDepthC = m_internalBitDepthY; }
@@ -1200,4 +1305,5 @@
   if (!m_outputBitDepthY) { m_outputBitDepthY = m_internalBitDepthY; }
   if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
+#endif
 
 #if !SVC_EXTENSION
@@ -1411,5 +1517,12 @@
   
   // set global varibles
+#if LAYER_CTB
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    xSetGlobal(layer);
+  }
+#else
   xSetGlobal();
+#endif
   
   // print-out parameters
@@ -1450,6 +1563,14 @@
 #define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
   // check range of parameters
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  for(UInt layer=0; layer<m_numLayers; layer++)
+  {
+    xConfirmPara( m_acLayerCfg[layer].m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
+    xConfirmPara( m_acLayerCfg[layer].m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
+  }
+#else
   xConfirmPara( m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
   xConfirmPara( m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
+#endif
 #if !SVC_EXTENSION  
   xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
@@ -1471,5 +1592,12 @@
   xConfirmPara( m_bipredSearchRange < 0 ,                                                   "Search Range must be more than 0" );
   xConfirmPara( m_iMaxDeltaQP > 7,                                                          "Absolute Delta QP exceeds supported range (0 to 7)" );
+#if LAYER_CTB
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    xConfirmPara( m_iMaxCuDQPDepth > m_acLayerCfg[layer].m_uiMaxCUDepth - 1,                "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
+  }
+#else
   xConfirmPara( m_iMaxCuDQPDepth > m_uiMaxCUDepth - 1,                                          "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
+#endif
 
   xConfirmPara( m_cbQpOffset < -12,   "Min. Chroma Cb QP Offset is -12" );
@@ -1485,8 +1613,10 @@
   }
 #endif
+#if !LAYER_CTB
   xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
   xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
   xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
   xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
+#endif
 #if !SVC_EXTENSION
   xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
@@ -1494,4 +1624,5 @@
 #endif
   
+#if !LAYER_CTB
   xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
   xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
@@ -1507,4 +1638,5 @@
   xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
   xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthIntra - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
+#endif
   
   xConfirmPara(  m_maxNumMergeCand < 1,  "MaxNumMergeCand must be 1 or greater.");
@@ -1554,4 +1686,5 @@
 #endif
 
+#if !LAYER_CTB
   // max CU width and height should be power of 2
   UInt ui = m_uiMaxCUWidth;
@@ -1569,5 +1702,5 @@
       xConfirmPara( ui != 1 , "Height should be 2^n");
   }
-
+#endif
 
   /* if this is an intra-only sequence, ie IntraPeriod=1, don't verify the GOP structure
@@ -1590,12 +1723,9 @@
 #endif
   
-#if EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
+
   Bool verifiedGOP=false;
-#endif
   Bool errorGOP=false;
-#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Int checkGOP=1;
   Int numRefs = m_isField ? 2 : 1;
-#endif
   Int refList[MAX_NUM_REF_PICS+1];
   refList[0]=0;
@@ -1609,7 +1739,5 @@
     isOK[i]=false;
   }
-#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
   Int numOK=0;
-#endif
 #if !SVC_EXTENSION
   xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" );
@@ -1654,31 +1782,5 @@
   }
 #endif
-#if FINAL_RPL_CHANGE_N0082
-  for(UInt layer=0; layer<m_numLayers; layer++)
-  {
-    if (m_acLayerCfg[layer].m_GOPListLayer[0].m_POC<0)
-    {
-      memcpy( m_acLayerCfg[layer].m_GOPListLayer, m_GOPList, sizeof(GOPEntry)*MAX_GOP );
-    }
-    errorGOP = xconfirmExtraGOP( m_acLayerCfg[layer].m_GOPListLayer );
-    xConfirmPara(errorGOP,"Invalid GOP structure given");
-  }
-#if TEMP_SCALABILITY_FIX
-  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7  && 
-    m_acLayerCfg[1].m_GOPListLayer[5].m_temporalId == 0 && m_acLayerCfg[1].m_GOPListLayer[7].m_temporalId == 0)
-#else
-  //tentative for encoder
-  if( m_acLayerCfg[1].m_GOPListLayer[5].m_POC == 6  && m_acLayerCfg[1].m_GOPListLayer[7].m_POC == 7 )
-#endif
-  {
-    //RA, POC5
-    m_acLayerCfg[1].m_GOPListLayer[5].m_usedByCurrPic[2] = 0;
-    m_acLayerCfg[1].m_GOPListLayer[5].m_refIdc[2] = 0;
-    //RA, POC7
-    m_acLayerCfg[1].m_GOPListLayer[7].m_usedByCurrPic[2] = 0;
-    m_acLayerCfg[1].m_GOPListLayer[7].m_refIdc[2] = 0;
-  }
-#endif
-#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
+
   m_extraRPSs=0;
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
@@ -1876,20 +1978,5 @@
   }
   xConfirmPara(errorGOP,"Invalid GOP structure given");
-#endif
-#if EXTERNAL_USEDBYCURR_N0082
-  for(UInt layer=0; layer<m_numLayers; layer++)
-  {
-    for (Int i=0; i< m_iGOPSize; i++){
-      if (m_acLayerCfg[layer].m_GOPListLayer[i].m_UseExtusedByCurrPic == 1 )
-      {
-        for(Int j=0; j<m_acLayerCfg[layer].m_GOPListLayer[i].m_numRefPics; j++ )
-        {
-          m_acLayerCfg[layer].m_GOPListLayer[i].m_usedByCurrPic[j] = m_acLayerCfg[layer].m_GOPListLayer[i].m_ExtusedByCurrPic[j];
-          m_acLayerCfg[layer].m_GOPListLayer[i].m_refIdc[j] = m_acLayerCfg[layer].m_GOPListLayer[i].m_ExtusedByCurrPic[j];
-        }
-      }
-    }
-  }
-#endif
+
   m_maxTempLayer = 1;
   for(Int i=0; i<m_iGOPSize; i++) 
@@ -1966,4 +2053,8 @@
     Int m_iSourceWidth = m_acLayerCfg[layer].m_iSourceWidth;
     Int m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight;
+#if LAYER_CTB
+    Int m_uiMaxCUWidth = m_acLayerCfg[layer].m_uiMaxCUWidth;
+    Int m_uiMaxCUHeight = m_acLayerCfg[layer].m_uiMaxCUHeight;
+#endif
 #endif
   if(m_vuiParametersPresentFlag && m_bitstreamRestrictionFlag)
@@ -2201,4 +2292,11 @@
   }
 #endif 
+#if AUXILIARY_PICTURES
+  for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
+  {
+    xConfirmPara(m_acLayerCfg[layer].m_auxId < 0 || m_acLayerCfg[layer].m_auxId > 4, "AuxId must be in range 0 to 4");
+    xConfirmPara(m_acLayerCfg[layer].m_auxId > 0 && m_acLayerCfg[layer].m_chromaFormatIDC != CHROMA_400, "Auxiliary picture must be monochrome picture");
+  }
+#endif 
 #undef xConfirmPara
   if (check_failed)
@@ -2210,4 +2308,36 @@
 /** \todo use of global variables should be removed later
  */
+#if LAYER_CTB
+Void TAppEncCfg::xSetGlobal(UInt layerId)
+{
+  // set max CU width & height
+  g_auiLayerMaxCUWidth[layerId]  = m_acLayerCfg[layerId].m_uiMaxCUWidth;
+  g_auiLayerMaxCUHeight[layerId] = m_acLayerCfg[layerId].m_uiMaxCUHeight;
+  
+  // compute actual CU depth with respect to config depth and max transform size
+  g_auiLayerAddCUDepth[layerId]  = 0;
+  while( (m_acLayerCfg[layerId].m_uiMaxCUWidth>>m_acLayerCfg[layerId].m_uiMaxCUDepth) > ( 1 << ( m_acLayerCfg[layerId].m_uiQuadtreeTULog2MinSize + g_auiLayerAddCUDepth[layerId] )  ) ) g_auiLayerAddCUDepth[layerId]++;
+  
+  m_acLayerCfg[layerId].m_uiMaxCUDepth += g_auiLayerAddCUDepth[layerId];
+  g_auiLayerAddCUDepth[layerId]++;
+  g_auiLayerMaxCUDepth[layerId] = m_acLayerCfg[layerId].m_uiMaxCUDepth;
+  
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // set internal bit-depth to constant value to make sure to be updated later
+  g_bitDepthY = -1;
+  g_bitDepthC = -1;
+  
+  g_uiPCMBitDepthLuma = -1;
+  g_uiPCMBitDepthChroma = -1;
+#else
+  // set internal bit-depth and constants
+  g_bitDepthY = m_internalBitDepthY;
+  g_bitDepthC = m_internalBitDepthC;
+  
+  g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
+  g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
+#endif
+}
+#else
 Void TAppEncCfg::xSetGlobal()
 {
@@ -2224,5 +2354,12 @@
   g_uiMaxCUDepth = m_uiMaxCUDepth;
   
-  // set internal bit-depth and constants
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // set internal bit-depth to constant value to make sure to be updated later
+  g_bitDepthY = -1;
+  g_bitDepthC = -1;
+  
+  g_uiPCMBitDepthLuma = -1;
+  g_uiPCMBitDepthChroma = -1;
+#else
   g_bitDepthY = m_internalBitDepthY;
   g_bitDepthC = m_internalBitDepthC;
@@ -2230,5 +2367,7 @@
   g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
   g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
+#endif
 }
+#endif
 
 Void TAppEncCfg::xPrintParameter()
@@ -2240,4 +2379,7 @@
   printf("Multiview                     : %d\n", m_scalabilityMask[1] );
   printf("Scalable                      : %d\n", m_scalabilityMask[2] );
+#if AUXILIARY_PICTURES
+  printf("Auxiliary pictures            : %d\n", m_scalabilityMask[3] );
+#endif
 #else
   printf("Multiview                     : %d\n", m_scalabilityMask[0] );
@@ -2284,8 +2426,10 @@
     printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
   }
+#if !LAYER_CTB
   printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
   printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
   printf("Max RQT depth inter          : %d\n", m_uiQuadtreeTUMaxDepthInter);
   printf("Max RQT depth intra          : %d\n", m_uiQuadtreeTUMaxDepthIntra);
+#endif
   printf("Min PCM size                 : %d\n", 1 << m_uiPCMLog2MinSize);
   printf("Motion search range          : %d\n", m_iSearchRange );
@@ -2304,6 +2448,11 @@
   printf("QP adaptation                : %d (range=%d)\n", m_bUseAdaptiveQP, (m_bUseAdaptiveQP ? m_iQPAdaptationRange : 0) );
   printf("GOP size                     : %d\n", m_iGOPSize );
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   printf("Internal bit depth           : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
   printf("PCM sample bit depth         : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma );
+#endif
+#if O0215_PHASE_ALIGNMENT
+  printf("cross-layer sample alignment : %d\n", m_phaseAlignFlag);
+#endif
 #if RATE_CONTROL_LAMBDA_DOMAIN
 #if !RC_SHVC_HARMONIZATION
@@ -2331,5 +2480,7 @@
   
   printf("TOOL CFG: ");
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC);
+#endif
   printf("HAD:%d ", m_bUseHADME           );
   printf("SRD:%d ", m_bUseSBACRD          );
@@ -2362,5 +2513,7 @@
   printf("CIP:%d ", m_bUseConstrainedIntraPred);
   printf("SAO:%d ", (m_bUseSAO)?(1):(0));
+#if !LAYER_CTB
   printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
+#endif
   printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
 
@@ -2394,4 +2547,7 @@
   printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
 #endif
+  printf("O0194_DIFFERENT_BITDEPTH_EL_BL: %d ", O0194_DIFFERENT_BITDEPTH_EL_BL);
+  printf("O0194_JOINT_US_BITSHIFT: %d ", O0194_JOINT_US_BITSHIFT);
+  printf("O0194_WEIGHTED_PREDICTION_CGS: %d ",O0194_WEIGHTED_PREDICTION_CGS);
   printf("\n\n");
   
@@ -2408,5 +2564,5 @@
 }
 
-#if SCALED_REF_LAYER_OFFSETS
+#if SVC_EXTENSION
 Void TAppEncCfg::cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString)
 {
@@ -2441,219 +2597,5 @@
   }
 }
-#endif
-
-#if FINAL_RPL_CHANGE_N0082
-Bool  TAppEncCfg::xconfirmExtraGOP (GOPEntry * ge)
-{
-  Bool verifiedGOP=false;
-  Bool errorGOP=false;
-  Int checkGOP=1;
-  Int numRefs = 1;
-  Int refList[MAX_NUM_REF_PICS+1];
-  refList[0]=0;
-  Bool isOK[MAX_GOP];
-  for(Int i=0; i<MAX_GOP; i++) 
-  {
-    isOK[i]=false;
-  }
-  Int numOK=0;
-
-  m_extraRPSs=0;
-  //start looping through frames in coding order until we can verify that the GOP structure is correct.
-  while(!verifiedGOP&&!errorGOP) 
-  {
-    Int curGOP = (checkGOP-1)%m_iGOPSize;
-    Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + ge[curGOP].m_POC;    
-    if(ge[curGOP].m_POC<0) 
-    {
-      printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
-      errorGOP=true;
-    }
-    else 
-    {
-      //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
-      Bool beforeI = false;
-      for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
-      {
-        Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
-        if(absPOC < 0)
-        {
-          beforeI=true;
-        }
-        else 
-        {
-          Bool found=false;
-          for(Int j=0; j<numRefs; j++) 
-          {
-            if(refList[j]==absPOC) 
-            {
-              found=true;
-              for(Int k=0; k<m_iGOPSize; k++)
-              {
-                if(absPOC%m_iGOPSize == ge[k].m_POC%m_iGOPSize)
-                {
-                  if(ge[k].m_temporalId==ge[curGOP].m_temporalId)
-                  {
-                    ge[k].m_refPic = true;
-                  }
-                  ge[curGOP].m_usedByCurrPic[i]=ge[k].m_temporalId<=ge[curGOP].m_temporalId;
-                }
-              }
-            }
-          }
-          if(!found)
-          {
-            printf("\nError: ref pic %d is not available for GOP frame %d\n",ge[curGOP].m_referencePics[i],curGOP+1);
-            errorGOP=true;
-          }
-        }
-      }
-      if(!beforeI&&!errorGOP)
-      {
-        //all ref frames were present
-        if(!isOK[curGOP]) 
-        {
-          numOK++;
-          isOK[curGOP]=true;
-          if(numOK==m_iGOPSize)
-          {
-            verifiedGOP=true;
-          }
-        }
-      }
-      else 
-      {
-        //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
-        ge[m_iGOPSize+m_extraRPSs]=ge[curGOP];
-        Int newRefs=0;
-        for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
-        {
-          Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
-          if(absPOC>=0)
-          {
-            ge[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=ge[curGOP].m_referencePics[i];
-            ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=ge[curGOP].m_usedByCurrPic[i];
-            newRefs++;
-          }
-        }
-        Int numPrefRefs = ge[curGOP].m_numRefPicsActive;
-        
-        for(Int offset = -1; offset>-checkGOP; offset--)
-        {
-          //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
-          Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
-          Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + ge[offGOP].m_POC;
-          if(offPOC>=0&&ge[offGOP].m_temporalId<=ge[curGOP].m_temporalId)
-          {
-            Bool newRef=false;
-            for(Int i=0; i<numRefs; i++)
-            {
-              if(refList[i]==offPOC)
-              {
-                newRef=true;
-              }
-            }
-            for(Int i=0; i<newRefs; i++) 
-            {
-              if(ge[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC)
-              {
-                newRef=false;
-              }
-            }
-            if(newRef) 
-            {
-              Int insertPoint=newRefs;
-              //this picture can be added, find appropriate place in list and insert it.
-              if(ge[offGOP].m_temporalId==ge[curGOP].m_temporalId)
-              {
-                ge[offGOP].m_refPic = true;
-              }
-              for(Int j=0; j<newRefs; j++)
-              {
-                if(ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0)
-                {
-                  insertPoint = j;
-                  break;
-                }
-              }
-              Int prev = offPOC-curPOC;
-              Int prevUsed = ge[offGOP].m_temporalId<=ge[curGOP].m_temporalId;
-              for(Int j=insertPoint; j<newRefs+1; j++)
-              {
-                Int newPrev = ge[m_iGOPSize+m_extraRPSs].m_referencePics[j];
-                Int newUsed = ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j];
-                ge[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev;
-                ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed;
-                prevUsed=newUsed;
-                prev=newPrev;
-              }
-              newRefs++;
-            }
-          }
-          if(newRefs>=numPrefRefs)
-          {
-            break;
-          }
-        }
-        ge[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs;
-        ge[m_iGOPSize+m_extraRPSs].m_POC = curPOC;
-        if (m_extraRPSs == 0)
-        {
-          ge[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0;
-          ge[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0;
-        }
-        else
-        {
-          Int rIdx =  m_iGOPSize + m_extraRPSs - 1;
-          Int refPOC = ge[rIdx].m_POC;
-          Int refPics = ge[rIdx].m_numRefPics;
-          Int newIdc=0;
-          for(Int i = 0; i<= refPics; i++) 
-          {
-            Int deltaPOC = ((i != refPics)? ge[rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
-            Int absPOCref = refPOC+deltaPOC;
-            Int refIdc = 0;
-            for (Int j = 0; j < ge[m_iGOPSize+m_extraRPSs].m_numRefPics; j++)
-            {
-              if ( (absPOCref - curPOC) == ge[m_iGOPSize+m_extraRPSs].m_referencePics[j])
-              {
-                if (ge[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j])
-                {
-                  refIdc = 1;
-                }
-                else
-                {
-                  refIdc = 2;
-                }
-              }
-            }
-            ge[m_iGOPSize+m_extraRPSs].m_refIdc[newIdc]=refIdc;
-            newIdc++;
-          }
-          ge[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 1;  
-          ge[m_iGOPSize+m_extraRPSs].m_numRefIdc = newIdc;
-          ge[m_iGOPSize+m_extraRPSs].m_deltaRPS = refPOC - ge[m_iGOPSize+m_extraRPSs].m_POC; 
-        }
-        curGOP=m_iGOPSize+m_extraRPSs;
-        m_extraRPSs++;
-      }
-      numRefs=0;
-      for(Int i = 0; i< ge[curGOP].m_numRefPics; i++) 
-      {
-        Int absPOC = curPOC+ge[curGOP].m_referencePics[i];
-        if(absPOC >= 0) 
-        {
-          refList[numRefs]=absPOC;
-          numRefs++;
-        }
-      }
-      refList[numRefs]=curPOC;
-      numRefs++;
-    }
-    checkGOP++;
-  }
-
-  return errorGOP; //update
-}
-#endif
+
+#endif //SVC_EXTENSION
 //! \}
Index: /trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 493)
+++ /trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 494)
@@ -101,5 +101,7 @@
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
 #endif  
-
+#if AUXILIARY_PICTURES
+  ChromaFormat m_InputChromaFormatIDC;
+#endif
   Bool      m_isField;                                        ///< enable field coding
   Bool      m_isTopFieldFirst;
@@ -150,4 +152,5 @@
   Int       m_maxTempLayer;                                  ///< Max temporal layer
 
+#if !LAYER_CTB
   // coding unit (CU) definition
   UInt      m_uiMaxCUWidth;                                   ///< max. CU width in pixel
@@ -161,6 +164,8 @@
   UInt      m_uiQuadtreeTUMaxDepthInter;
   UInt      m_uiQuadtreeTUMaxDepthIntra;
+#endif
   
   // coding tools (bit-depth)
+#if !O0194_DIFFERENT_BITDEPTH_EL_BL
   Int       m_inputBitDepthY;                               ///< bit-depth of input file (luma component)
   Int       m_inputBitDepthC;                               ///< bit-depth of input file (chroma component)
@@ -169,4 +174,8 @@
   Int       m_internalBitDepthY;                            ///< bit-depth codec operates at in luma (input/output files will be converted)
   Int       m_internalBitDepthC;                            ///< bit-depth codec operates at in chroma (input/output files will be converted)
+#endif
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC;
+#endif
 
   // coding tools (PCM bit-depth)
@@ -354,11 +363,12 @@
 #endif
   // internal member functions
+#if LAYER_CTB
+  Void  xSetGlobal      (UInt layerId);                       ///< set global variables
+#else
   Void  xSetGlobal      ();                                   ///< set global variables
+#endif
   Void  xCheckParameter ();                                   ///< check validity of configuration values
   Void  xPrintParameter ();                                   ///< print configuration values
   Void  xPrintUsage     ();                                   ///< print usage
-#if FINAL_RPL_CHANGE_N0082
-  Bool  xconfirmExtraGOP (GOPEntry * ge);
-#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
@@ -375,4 +385,7 @@
   UInt      m_ilcIdc[1024];
 #endif
+#if O0215_PHASE_ALIGNMENT
+  bool m_phaseAlignFlag;
+#endif
 public:
   TAppEncCfg();
@@ -388,9 +401,17 @@
   Int  getNumLayer()               {return m_numLayers;        }
   Int  getGOPSize()                {return m_iGOPSize;          }
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  UInt getInternalBitDepthY(Int iLayer)      {return m_acLayerCfg[iLayer].m_internalBitDepthY; }
+  UInt getInternalBitDepthC(Int iLayer)      {return m_acLayerCfg[iLayer].m_internalBitDepthC; }
+  Bool getPCMInputBitDepthFlag()             {return m_bPCMInputBitDepthFlag;                  }
+#else
   UInt getInternalBitDepthY()      {return m_internalBitDepthY; }
   UInt getInternalBitDepthC()      {return m_internalBitDepthC; }
+#endif
+#if !LAYER_CTB
   UInt getMaxCUWidth()             {return m_uiMaxCUWidth;      }
   UInt getMaxCUHeight()            {return m_uiMaxCUHeight;     }
   UInt getMaxCUDepth()             {return m_uiMaxCUDepth;      }
+#endif
   Int  getDecodingRefreshType()    {return m_iDecodingRefreshType; }
   Int  getWaveFrontSynchro()        { return m_iWaveFrontSynchro; }
@@ -399,10 +420,12 @@
   Char* getBLSyntaxFile()           { return m_BLSyntaxFile;      }
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   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
+#if LAYER_CTB
+  Bool getUsePCM()                  { return m_usePCM;               }
+  UInt getPCMLog2MinSize  ()        { return  m_uiPCMLog2MinSize;    }
+#endif
 #endif
 };// END CLASS DEFINITION TAppEncCfg
Index: /trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 493)
+++ /trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 494)
@@ -22,4 +22,18 @@
 //! \{
 
+
+#if AUXILIARY_PICTURES
+static inline ChromaFormat numberToChromaFormat(const Int val)
+{
+  switch (val)
+  {
+    case 400: return CHROMA_400; break;
+    case 420: return CHROMA_420; break;
+    case 422: return CHROMA_422; break;
+    case 444: return CHROMA_444; break;
+    default:  return NUM_CHROMA_FORMAT;
+  }
+}
+#endif
 
 // ====================================================================================================================
@@ -38,5 +52,4 @@
   m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
   m_aiPad[1] = m_aiPad[0] = 0;
-#if SCALED_REF_LAYER_OFFSETS
   m_numScaledRefLayerOffsets = 0;
   ::memset(m_scaledRefLayerLeftOffset,   0, sizeof(m_scaledRefLayerLeftOffset));
@@ -44,5 +57,4 @@
   ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
-#endif
 }
 
@@ -77,4 +89,9 @@
   string cfg_ReconFile;
   string cfg_dQPFile;
+#if AUXILIARY_PICTURES
+  Int tmpInputChromaFormat;
+  Int tmpChromaFormat;
+#endif
+
   po::Options opts;
   opts.addOptions()
@@ -87,4 +104,8 @@
     ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
     ("CroppingMode",          m_conformanceMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+#if AUXILIARY_PICTURES
+    ("InputChromaFormat",     tmpInputChromaFormat,  420, "InputChromaFormatIDC")
+    ("ChromaFormatIDC",       tmpChromaFormat,    420, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat)")
+#endif
     ("CropLeft",              m_confLeft,      0, "Left cropping/padding for cropping mode 3")
     ("CropRight",             m_confRight,     0, "Right cropping/padding for cropping mode 3")
@@ -105,4 +126,8 @@
   m_cReconFile = cfg_ReconFile;
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
+#if AUXILIARY_PICTURES
+  m_InputChromaFormat = numberToChromaFormat(tmpInputChromaFormat);
+  m_chromaFormatIDC   = ((tmpChromaFormat == 0) ? (m_InputChromaFormat) : (numberToChromaFormat(tmpChromaFormat)));
+#endif
 
   // reading external dQP description from file
@@ -142,4 +167,15 @@
   printf("Real     Format               : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
   printf("Internal Format               : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  printf("Input bit depth               : (Y:%d, C:%d)\n", m_inputBitDepthY   , m_inputBitDepthC    );
+  printf("Internal bit depth            : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
+  printf("PCM sample bit depth          : (Y:%d, C:%d)\n", m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthY : m_internalBitDepthY, m_cAppEncCfg->getPCMInputBitDepthFlag() ? m_inputBitDepthC : m_internalBitDepthC );
+#endif
+#if LAYER_CTB
+  printf("CU size / depth               : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
+  printf("RQT trans. size (min / max)   : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
+  printf("Max RQT depth inter           : %d\n", m_uiQuadtreeTUMaxDepthInter);
+  printf("Max RQT depth intra           : %d\n", m_uiQuadtreeTUMaxDepthIntra);
+#endif
   printf("QP                            : %5.2f\n", m_fQP );
   printf("Intra period                  : %d\n", m_iIntraPeriod );
@@ -157,4 +193,7 @@
 #endif
   printf("WaveFrontSynchro:%d WaveFrontSubstreams:%d", m_cAppEncCfg->getWaveFrontSynchro(), m_iWaveFrontSubstreams);
+#if LAYER_CTB
+  printf("PCM:%d ", (m_cAppEncCfg->getUsePCM() && (1<<m_cAppEncCfg->getPCMLog2MinSize()) <= m_uiMaxCUWidth)? 1 : 0);
+#endif
 }
 
@@ -175,5 +214,9 @@
     {
       // automatic padding to minimum CU size
+#if LAYER_CTB
+      Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1);
+#else
       Int minCuSize = m_cAppEncCfg->getMaxCUHeight() >> (m_cAppEncCfg->getMaxCUDepth() - 1);
+#endif
       if (m_iSourceWidth % minCuSize)
       {
@@ -240,7 +283,13 @@
   }
 
+#if LAYER_CTB
+  UInt maxCUWidth = m_uiMaxCUWidth;
+  UInt maxCUHeight = m_uiMaxCUHeight;
+  UInt maxCUDepth = m_uiMaxCUDepth;
+#else
   UInt maxCUWidth = m_cAppEncCfg->getMaxCUWidth();
   UInt maxCUHeight = m_cAppEncCfg->getMaxCUHeight();
   UInt maxCUDepth = m_cAppEncCfg->getMaxCUDepth();
+#endif
   bool check_failed = false; /* abort if there is a fatal configuration problem */
 #define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
@@ -255,8 +304,15 @@
   }
 
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY(layer) - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
+  }
+#else
   xConfirmPara( m_iQP <  -6 * ((Int)m_cAppEncCfg->getInternalBitDepthY() - 8) || m_iQP > 51,                "QP exceeds supported range (-QpBDOffsety to 51)" );
-
-
-  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + m_cAppEncCfg->getMaxCUHeight() - 1) / m_cAppEncCfg->getMaxCUHeight() : 1;
+#endif
+
+
+  m_iWaveFrontSubstreams = m_cAppEncCfg->getWaveFrontSynchro() ? (m_iSourceHeight + maxCUHeight - 1) / maxCUHeight : 1;
   xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
   xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_cAppEncCfg->getWaveFrontSynchro(), "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
@@ -273,9 +329,45 @@
   xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
   xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
+
+#if LAYER_CTB  
+  xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
+  xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
+  xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
+  xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
+  xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
+  xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
+  xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth,                                        "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
+  xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize,                "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize.");
+  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
+  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
+  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth  >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." );
+  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." );
+  xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1,                                                         "QuadtreeTUMaxDepthInter must be greater than or equal to 1" );
+  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthInter - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
+  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
+  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthIntra - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
+
+  // max CU width and height should be power of 2
+  UInt ui = m_uiMaxCUWidth;
+  while(ui)
+  {
+    ui >>= 1;
+    if( (ui & 1) == 1)
+      xConfirmPara( ui != 1 , "Width should be 2^n");
+  }
+  ui = m_uiMaxCUHeight;
+  while(ui)
+  {
+    ui >>= 1;
+    if( (ui & 1) == 1)
+      xConfirmPara( ui != 1 , "Height should be 2^n");
+  }
+#endif
+
 #undef xConfirmPara
   return check_failed;
 }
 
-#endif
+#endif //SVC_EXTENSION
 
 
Index: /trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 493)
+++ /trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 494)
@@ -6,4 +6,5 @@
 #define __TAPPENCLAYERCFG__
 
+#if SVC_EXTENSION
 #include "TLibCommon/CommonDef.h"
 #include "TLibEncoder/TEncCfg.h"
@@ -11,7 +12,5 @@
 
 using namespace std;
-#if SVC_EXTENSION
 class TAppEncCfg;
-#endif
 //! \ingroup TAppEncoder
 //! \{
@@ -43,4 +42,9 @@
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC;
+  ChromaFormat m_InputChromaFormat;
+  Int          m_auxId;
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
 #if M0457_PREDICTION_INDICATIONS
@@ -55,4 +59,18 @@
   Int       *m_predLayerIds;
   Int       m_numActiveRefLayers;
+#endif
+
+#if LAYER_CTB
+  // coding unit (CU) definition
+  UInt      m_uiMaxCUWidth;                                   ///< max. CU width in pixel
+  UInt      m_uiMaxCUHeight;                                  ///< max. CU height in pixel
+  UInt      m_uiMaxCUDepth;                                   ///< max. CU depth
+  
+  // transfom unit (TU) definition
+  UInt      m_uiQuadtreeTULog2MaxSize;
+  UInt      m_uiQuadtreeTULog2MinSize;
+  
+  UInt      m_uiQuadtreeTUMaxDepthInter;
+  UInt      m_uiQuadtreeTUMaxDepthIntra;
 #endif
 
@@ -70,7 +88,5 @@
   Int       m_maxTidIlRefPicsPlus1;
 #endif 
-#if SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
-#endif
 
   Int       m_iQP;                                            ///< QP value of key-picture (integer)
@@ -78,5 +94,4 @@
   Int*      m_aidQP;                                          ///< array of slice QP values
   TAppEncCfg* m_cAppEncCfg;                                   ///< pointer to app encoder config
-#if SCALED_REF_LAYER_OFFSETS
   Int       m_numScaledRefLayerOffsets  ;
   Int       m_scaledRefLayerLeftOffset  [MAX_LAYERS];
@@ -84,7 +99,11 @@
   Int       m_scaledRefLayerRightOffset [MAX_LAYERS];
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
-#endif  
-#if FINAL_RPL_CHANGE_N0082
-  GOPEntry  m_GOPListLayer[MAX_GOP];                            ///< for layer
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  Int       m_inputBitDepthY;                               ///< bit-depth of input file (luma component)
+  Int       m_inputBitDepthC;                               ///< bit-depth of input file (chroma component)
+  Int       m_internalBitDepthY;                            ///< bit-depth codec operates at in luma (input/output files will be converted)
+  Int       m_internalBitDepthC;                            ///< bit-depth codec operates at in chroma (input/output files will be converted)
+  Int       m_outputBitDepthY;                              ///< bit-depth of output file (luma component)
+  Int       m_outputBitDepthC;                              ///< bit-depth of output file (chroma component)
 #endif
 #if REPN_FORMAT_IN_VPS
@@ -122,4 +141,9 @@
   Int     getConfTop()                {return m_confTop;          }
   Int     getConfBottom()             {return m_confBottom;       }
+#if AUXILIARY_PICTURES
+  ChromaFormat getInputChromaFormat()   {return m_InputChromaFormat;}
+  ChromaFormat getChromaFormatIDC()     {return m_chromaFormatIDC;  }
+  Int          getAuxId()               {return m_auxId;            }
+#endif
 
   Int     getIntQP()                  {return m_iQP;              } 
@@ -152,7 +176,4 @@
   Bool    getRCForceIntraQP()         {return m_RCForceIntraQP;        }
 #endif
-#if FINAL_RPL_CHANGE_N0082
-  GOPEntry getGOPEntry(Int i )        {return m_GOPListLayer[i];  }
-#endif
 #if REPN_FORMAT_IN_VPS
   Int     getRepFormatIdx()           { return m_repFormatIdx;  }
@@ -164,5 +185,12 @@
   Int     getMaxTidIlRefPicsPlus1()   { return m_maxTidIlRefPicsPlus1; }
 #endif 
+#if LAYER_CTB
+  UInt    getMaxCUWidth()             {return m_uiMaxCUWidth;      }
+  UInt    getMaxCUHeight()            {return m_uiMaxCUHeight;     }
+  UInt    getMaxCUDepth()             {return m_uiMaxCUDepth;      }
+#endif
 }; // END CLASS DEFINITION TAppEncLayerCfg
+
+#endif //SVC_EXTENSION
 
 //! \}
Index: /trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 493)
+++ /trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -98,10 +98,16 @@
     // Auto generation of the format index
     if( m_acLayerCfg[layer].getRepFormatIdx() == -1 )
-    {
-      // Currently only picture width and height are considred. It has to be updated if different chroma format and bit-depth will are used.
+    {      
       Bool found = false;
       for( UInt idx = 0; idx < layer; idx++ )
       {
-        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight() )
+        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight()
+#if AUXILIARY_PICTURES
+          && m_acLayerCfg[layer].getChromaFormatIDC() == m_acLayerCfg[idx].getChromaFormatIDC()
+#endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          && m_acLayerCfg[layer].m_internalBitDepthY == m_acLayerCfg[idx].m_internalBitDepthY && m_acLayerCfg[layer].m_internalBitDepthC == m_acLayerCfg[idx].m_internalBitDepthC
+#endif
+          )
         {
           found = true;
@@ -117,5 +123,5 @@
     }
 
-    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a 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 );
@@ -141,11 +147,20 @@
   for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
   {
-    RepFormat *repFormat = vps->getVpsRepFormat( idx );    
+    RepFormat *repFormat = vps->getVpsRepFormat( idx );
     repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
     repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
+#if AUXILIARY_PICTURES
+    repFormat->setChromaFormatVpsIdc        ( m_acLayerCfg[mapIdxToLayer[idx]].getChromaFormatIDC() );
+#else
     repFormat->setChromaFormatVpsIdc        ( 1                                             );  // Need modification to change for each layer - corresponds to 420
+#endif
     repFormat->setSeparateColourPlaneVpsFlag( 0                                             );  // Need modification to change for each layer
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY(mapIdxToLayer[idx])      );  // Need modification to change for each layer
+    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC(mapIdxToLayer[idx])      );  // Need modification to change for each layer
+#else
     repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
     repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
+#endif
   }
   delete [] mapIdxToLayer;
@@ -153,4 +168,16 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //1
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+
+    // Set this to be used in Upsampling filter in function "TComUpsampleFilter::upsampleBasePic"
+    g_bitDepthYLayer[layer] = g_bitDepthY;
+    g_bitDepthCLayer[layer] = g_bitDepthC;
+#endif
     //m_acTEncTop[layer].setVPS(&vps);
     m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
@@ -187,6 +214,6 @@
 #endif
 #endif
-    // set layer ID 
-    m_acTEncTop[layer].setLayerId ( layer ); 
+    // set layer ID
+    m_acTEncTop[layer].setLayerId ( layer );
     m_acTEncTop[layer].setNumLayer ( m_numLayers );
     m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
@@ -196,9 +223,6 @@
     m_acTEncTop[layer].setDecodingRefreshType          ( m_iDecodingRefreshType );
     m_acTEncTop[layer].setGOPSize                      ( m_iGOPSize );
-#if FINAL_RPL_CHANGE_N0082
-    m_acTEncTop[layer].setGopList                      ( m_acLayerCfg[layer].m_GOPListLayer );
-#else
     m_acTEncTop[layer].setGopList                      ( m_GOPList );
-#endif
+
     m_acTEncTop[layer].setExtraRPSs                    ( m_extraRPSs );
     for(Int i = 0; i < MAX_TLAYER; i++)
@@ -220,7 +244,7 @@
     if (layer<m_numLayers-1)
     {
-       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1()); 
-    }
-#endif 
+       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1 ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1());
+    }
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
     if(layer)
@@ -241,10 +265,10 @@
       else
       {
-        m_acTEncTop[layer].setNumSamplePredRefLayers   ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );      
+        m_acTEncTop[layer].setNumSamplePredRefLayers   ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumSamplePredRefLayers(); i++)
         {
           m_acTEncTop[layer].setSamplePredRefLayerId   ( i, m_acLayerCfg[layer].getSamplePredRefLayerId(i));
           m_acTEncTop[layer].setSamplePredEnabledFlag  (m_acLayerCfg[layer].getSamplePredRefLayerId(i), true);
-        }        
+        }
       }
       if(m_acLayerCfg[layer].getNumMotionPredRefLayers() == -1)
@@ -257,10 +281,10 @@
       else
       {
-        m_acTEncTop[layer].setNumMotionPredRefLayers   ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );      
+        m_acTEncTop[layer].setNumMotionPredRefLayers   ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumMotionPredRefLayers(); i++)
         {
           m_acTEncTop[layer].setMotionPredRefLayerId   ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
           m_acTEncTop[layer].setMotionPredEnabledFlag  (m_acLayerCfg[layer].getMotionPredRefLayerId(i), true);
-        }        
+        }
       }
       Int numDirectRefLayers = 0;
@@ -283,5 +307,5 @@
       else
       {
-        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );      
+        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++)
         {
@@ -304,5 +328,5 @@
       else
       {
-        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );      
+        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );
         for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
         {
@@ -358,10 +382,17 @@
     m_acTEncTop[layer].setUseRDOQTS                    ( m_useRDOQTS   );
     m_acTEncTop[layer].setRDpenalty                    ( m_rdPenalty );
+#if LAYER_CTB
+    m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize );
+    m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize );
+    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter );
+    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra );
+#else
     m_acTEncTop[layer].setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
     m_acTEncTop[layer].setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
     m_acTEncTop[layer].setQuadtreeTUMaxDepthInter      ( m_uiQuadtreeTUMaxDepthInter );
     m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
+#endif
     m_acTEncTop[layer].setUseFastEnc                   ( m_bUseFastEnc  );
-    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+    m_acTEncTop[layer].setUseEarlyCU                   ( m_bUseEarlyCU  );
     m_acTEncTop[layer].setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
     m_acTEncTop[layer].setUseCbfFastMode               ( m_bUseCbfFastMode  );
@@ -383,4 +414,12 @@
     m_acTEncTop[layer].setUseWP                   ( m_useWeightedPred      );
     m_acTEncTop[layer].setWPBiPred                ( m_useWeightedBiPred   );
+#if O0194_WEIGHTED_PREDICTION_CGS
+    if (layer!=0)
+    {
+      // Enable weighted prediction for enhancement layer
+      m_acTEncTop[layer].setUseWP                 ( true   );
+      m_acTEncTop[layer].setWPBiPred              ( true   );
+    }
+#endif
     //====== Parallel Merge Estimation ========
     m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 );
@@ -393,5 +432,9 @@
     m_acTEncTop[layer].setSliceSegmentMode        ( m_sliceSegmentMode         );
     m_acTEncTop[layer].setSliceSegmentArgument    ( m_sliceSegmentArgument     );
+#if LAYER_CTB
+    Int iNumPartInCU = 1<<(m_acLayerCfg[layer].m_uiMaxCUDepth<<1);
+#else
     Int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
+#endif
     if(m_sliceSegmentMode==FIXED_NUMBER_OF_LCU)
     {
@@ -417,6 +460,6 @@
     m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
     m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
-    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
-    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
+    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
 
     m_acTEncTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
@@ -483,5 +526,5 @@
     if(uiTilesCount == 1)
     {
-      m_bLFCrossTileBoundaryFlag = true; 
+      m_bLFCrossTileBoundaryFlag = true;
     }
     m_acTEncTop[layer].setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
@@ -519,5 +562,5 @@
     m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
     m_acTEncTop[layer].setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
-    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
+    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
     m_acTEncTop[layer].setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
     m_acTEncTop[layer].setAspectRatioIdc( m_aspectRatioIdc );
@@ -550,5 +593,4 @@
     m_acTEncTop[layer].setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
     m_acTEncTop[layer].setElRapSliceTypeB(layer == 0? 0 : m_elRapSliceBEnabled);
-#if SCALED_REF_LAYER_OFFSETS
     if( layer > 0 )
     {
@@ -557,14 +599,16 @@
       {
         m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
-                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);  
-      }
-    }
-#endif
+                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
+      }
+    }
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
     m_acTEncTop[layer].setAdaptiveResolutionChange( m_adaptiveResolutionChange );
 #endif
+#if AUXILIARY_PICTURES
+    m_acTEncTop[layer].setChromaFormatIDC( m_acLayerCfg[layer].m_chromaFormatIDC );
+#endif
   }
 }
-#else
+#else //SVC_EXTENSION
 Void TAppEncTop::xInitLibCfg()
 {
@@ -671,5 +715,5 @@
   m_cTEncTop.setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
   m_cTEncTop.setUseFastEnc                   ( m_bUseFastEnc  );
-  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+  m_cTEncTop.setUseEarlyCU                   ( m_bUseEarlyCU  );
   m_cTEncTop.setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
   m_cTEncTop.setUseCbfFastMode            ( m_bUseCbfFastMode  );
@@ -725,6 +769,6 @@
   m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
   m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
-  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
-  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
+  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
 
   m_cTEncTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
@@ -783,5 +827,5 @@
   if(uiTilesCount == 1)
   {
-    m_bLFCrossTileBoundaryFlag = true; 
+    m_bLFCrossTileBoundaryFlag = true;
   }
   m_cTEncTop.setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
@@ -809,5 +853,5 @@
   m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
   m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
-  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); 
+  m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled );
   m_cTEncTop.setVuiParametersPresentFlag( m_vuiParametersPresentFlag );
   m_cTEncTop.setAspectRatioIdc( m_aspectRatioIdc );
@@ -840,5 +884,5 @@
   m_cTEncTop.setLog2MaxMvLengthVertical( m_log2MaxMvLengthVertical );
 }
-#endif
+#endif //SVC_EXTENSION
 
 Void TAppEncTop::xCreateLib()
@@ -851,15 +895,37 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //2
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+#endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_acLayerCfg[layer].m_inputBitDepthY, m_acLayerCfg[layer].m_inputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // read  mode
+#else
     m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
+#endif
     m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1]);
 
     if (!m_acLayerCfg[layer].getReconFile().empty())
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_acLayerCfg[layer].m_outputBitDepthY, m_acLayerCfg[layer].m_outputBitDepthC, m_acLayerCfg[layer].m_internalBitDepthY, m_acLayerCfg[layer].m_internalBitDepthC );  // write mode
+#else
       m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // write mode
+#endif
     }
 
     m_acTEncTop[layer].create();
   }
-#else
+#else //SVC_EXTENSION
   m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
   m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
@@ -870,5 +936,5 @@
   // Neo Decoder
   m_cTEncTop.create();
-#endif
+#endif //SVC_EXTENSION
 }
 
@@ -882,4 +948,11 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if LAYER_CTB
+    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+#endif
+
     m_acTVideoIOYuvInputFile[layer].close();
     m_acTVideoIOYuvReconFile[layer].close();
@@ -887,5 +960,5 @@
     m_acTEncTop[layer].destroy();
   }
-#else
+#else //SVC_EXTENSION
   m_cTVideoIOYuvInputFile.close();
   m_cTVideoIOYuvReconFile.close();
@@ -893,5 +966,5 @@
   // Neo Decoder
   m_cTEncTop.destroy();
-#endif
+#endif //SVC_EXTENSION
 }
 
@@ -901,4 +974,23 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //3
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+
+    memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
+    memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
+    memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
+    memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
+#endif
     m_acTEncTop[layer].init(isFieldCoding);
   }
@@ -915,4 +1007,12 @@
     for(Int layerId = 0; layerId <= vps->getMaxLayerId(); layerId++)
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      //4
+      g_bitDepthY = m_acLayerCfg[layerId].m_internalBitDepthY;
+      g_bitDepthC = m_acLayerCfg[layerId].m_internalBitDepthC;
+
+      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthY : m_acLayerCfg[layerId].m_internalBitDepthY;
+      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layerId].m_inputBitDepthC : m_acLayerCfg[layerId].m_internalBitDepthC;
+#endif
       vps->setLayerIdIncludedFlag(true, setId, layerId);
     }
@@ -930,5 +1030,5 @@
     vps->setScalabilityMask(i, false);
   }
-  if(m_numLayers > 1) 
+  if(m_numLayers > 1)
   {
     Int scalabilityTypes = 0;
@@ -938,5 +1038,9 @@
       scalabilityTypes += m_scalabilityMask[i];
     }
+#if AUXILIARY_PICTURES
+    assert( scalabilityTypes <= 2 );
+#else
     assert( scalabilityTypes == 1 );
+#endif
     vps->setNumScalabilityTypes(scalabilityTypes);
   }
@@ -959,32 +1063,80 @@
     vps->setDimensionId(i, 0, i);
   }
+#if AUXILIARY_PICTURES
+  if (m_scalabilityMask[3])
+  {
+    UInt maxAuxId = 0;
+    UInt auxDimIdLen = 0;
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if (m_acLayerCfg[i].getAuxId() > maxAuxId)
+      {
+        maxAuxId = m_acLayerCfg[i].getAuxId();
+      }
+    }
+    while((1 << auxDimIdLen) < (maxAuxId + 1))
+    {
+      auxDimIdLen++;
+    }
+    vps->setDimensionIdLen(1, auxDimIdLen);
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      vps->setDimensionId(i, 1, m_acLayerCfg[i].getAuxId());
+    }
+  }
+#endif
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
 #if N0120_MAX_TID_REF_CFG
   vps->setMaxTidRefPresentFlag(m_maxTidRefPresentFlag);
-#else 
+#else
   vps->setMaxTidRefPresentFlag(true);
+#endif
+  if (vps->getMaxTidRefPresentFlag())
+  {
+    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
+    {
+#if N0120_MAX_TID_REF_CFG
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
+      }
+#else
+      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
 #endif 
-  if (vps->getMaxTidRefPresentFlag())
+#else
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, vps->getMaxTLayers()+1);
+      }
+#else
+      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
+#endif
+#endif
+    }
+  }
+  else
   {
     for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
     {
-#if N0120_MAX_TID_REF_CFG
-      vps->setMaxTidIlRefPicsPlus1(i, m_acTEncTop[i].getMaxTidIlRefPicsPlus1()); 
-#else 
-      vps->setMaxTidIlRefPicsPlus1(i, vps->getMaxTLayers()+1);
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      for( Int j = i+1; j <= MAX_VPS_LAYER_ID_PLUS1 - 1; j++)
+      {
+        vps->setMaxTidIlRefPicsPlus1(i, j, 7);
+      }
+#else
+      vps->setMaxTidIlRefPicsPlus1(i, 7);
 #endif 
     }
   }
-  else
-  {
-    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
-    {
-      vps->setMaxTidIlRefPicsPlus1(i, 7);
-    }
-  }
-#endif 
+#endif
 #if ILP_SSH_SIG
+#if ILP_SSH_SIG_FIX
+    vps->setIlpSshSignalingEnabledFlag(false);
+#else
     vps->setIlpSshSignalingEnabledFlag(true);
+#endif
 #endif
 #if VPS_EXTN_PROFILE_INFO
@@ -998,21 +1150,16 @@
 #endif
   // Target output layer
-#if VPS_PROFILE_OUTPUT_LAYERS
-  vps->setNumOutputLayerSets(vps->getNumLayerSets());    
-  vps->setNumProfileTierLevel(vps->getNumLayerSets());   
+  vps->setNumOutputLayerSets(vps->getNumLayerSets());
+  vps->setNumProfileTierLevel(vps->getNumLayerSets());
   vps->setDefaultOneTargetOutputLayerFlag(true);
   for(i = 1; i < vps->getNumLayerSets(); i++)
   {
     vps->setProfileLevelTierIdx(i, i);
-    vps->setOutputLayerSetIdx(i, i); 
-  }
-#else
-  vps->setNumOutputLayerSets(1);
-  Int lsIdx = 1;
-  vps->setOutputLayerSetIdx(0, lsIdx); // Because only one layer set
-#endif
+    vps->setOutputLayerSetIdx(i, i);
+  }
+
   for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
   {
-    // Include the highest layer as output layer 
+    // Include the highest layer as output layer
     for(UInt layer=0; layer <= vps->getMaxLayerId() ; layer++)
     {
@@ -1073,9 +1220,18 @@
 #endif
 #endif
-#if JCTVC_M0458_INTERLAYER_RPS_SIG        
-    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true); 
-#endif 
-#if N0147_IRAP_ALIGN_FLAG    
-    vps->setCrossLayerIrapAlignFlag(true); 
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+    for(i = 1; i< vps->getMaxLayers(); i++)
+    {
+      if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
+      {
+        vps->setPocLsbNotPresentFlag(i, false);
+      }
+    }
+#endif
+#if N0147_IRAP_ALIGN_FLAG
+    vps->setCrossLayerIrapAlignFlag(true);
     for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     {
@@ -1083,5 +1239,5 @@
       {
         if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
-        {          
+        {
           if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
           {
@@ -1097,12 +1253,19 @@
       vps->setCrossLayerIrapAlignFlag(false);
     }
-#endif 
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
 #endif
+#if !VPS_EXTN_OFFSET_CALC
 #if VPS_EXTN_OFFSET
   // to be updated according to the current semantics
   vps->setExtensionOffset( 0xffff );
 #endif
+#endif
+
+#if O0215_PHASE_ALIGNMENT
+  vps->setPhaseAlignFlag( m_phaseAlignFlag );
+#endif
+
 #else //SVC_EXTENSION
   m_cTEncTop.init(isFieldCoding);
@@ -1148,4 +1311,12 @@
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    //5
+    g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+    g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+    g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+    g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
     // allocate original YUV buffer
     pcPicYuvOrg[layer] = new TComPicYuv;
@@ -1153,5 +1324,17 @@
     {
 #if SVC_UPSAMPLING
+#if LAYER_CTB
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#else
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#endif
+#else
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
       pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#endif
+#endif
 #else
       pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1161,5 +1344,17 @@
     {
 #if SVC_UPSAMPLING
+#if LAYER_CTB
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#else
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#endif
+#else
+#if AUXILIARY_PICTURES
+      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
       pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#endif
+#endif
 #else
       pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1190,5 +1385,5 @@
   while ( !bEos )
   {
-    // Read enough frames 
+    // Read enough frames
     Bool bFramesReadyToCode = false;
     while(!bFramesReadyToCode)
@@ -1196,4 +1391,19 @@
       for(UInt layer=0; layer<m_numLayers; layer++)
       {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        //6
+        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+#endif
+
         // get buffers
         xGetBuffer(pcPicYuvRec, layer);
@@ -1201,4 +1411,11 @@
         // read input YUV file
         m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], m_acLayerCfg[layer].getPad() );
+
+#if AUXILIARY_PICTURES
+        if (m_acLayerCfg[layer].getChromaFormatIDC() == CHROMA_400)
+        {
+          pcPicYuvOrg[layer]->convertToMonochrome();
+        }
+#endif
 
         if(layer == m_numLayers-1)
@@ -1257,5 +1474,5 @@
 #endif
 
-    // loop through frames in one GOP 
+    // loop through frames in one GOP
     for ( UInt iPicIdInGOP=0; iPicIdInGOP < (bFirstFrame? 1:m_iGOPSize); iPicIdInGOP++ )
     {
@@ -1263,4 +1480,23 @@
       for(UInt layer=0; layer<m_numLayers; layer++)
       {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        //7
+        g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+        g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+        g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+        g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
+#if LAYER_CTB
+        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
+        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
+        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
+        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
+
+        memcpy( g_auiZscanToRaster, g_auiLayerZscanToRaster[layer], sizeof( g_auiZscanToRaster ) );
+        memcpy( g_auiRasterToZscan, g_auiLayerRasterToZscan[layer], sizeof( g_auiRasterToZscan ) );
+        memcpy( g_auiRasterToPelX,  g_auiLayerRasterToPelX[layer],  sizeof( g_auiRasterToPelX ) );
+        memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
+#endif
         // call encoding function for one frame
         if ( m_isField )
@@ -1288,4 +1524,12 @@
     for(UInt layer=0; layer<m_numLayers; layer++)
     {
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+      //8
+      g_bitDepthY = m_acLayerCfg[layer].m_internalBitDepthY;
+      g_bitDepthC = m_acLayerCfg[layer].m_internalBitDepthC;
+
+      g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthY : m_acLayerCfg[layer].m_internalBitDepthY;
+      g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_inputBitDepthC : m_acLayerCfg[layer].m_internalBitDepthC;
+#endif
       // write bistream to file if necessary
       iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
@@ -1528,5 +1772,17 @@
 
 #if SVC_UPSAMPLING
+#if LAYER_CTB
+#if AUXILIARY_PICTURES
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#else
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxCUDepth, NULL );
+#endif
+#else
+#if AUXILIARY_PICTURES
+    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#else
     rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
+#endif
+#endif
 #else
     rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
@@ -1551,5 +1807,5 @@
       delete pcPicYuvRec; pcPicYuvRec = NULL;
     }
-  }  
+  }
 }
 
@@ -1602,5 +1858,5 @@
 #endif
       {
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), 
+        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
           m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
       }
@@ -1622,5 +1878,5 @@
     for ( i = 0; i < iNumEncoded/2; i++ )
 #endif
-    {      
+    {
       const AccessUnit& auTop = *(iterBitstream++);
       const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
Index: /trunk/source/App/utils/convert_NtoMbit_YCbCr.cpp
===================================================================
--- /trunk/source/App/utils/convert_NtoMbit_YCbCr.cpp	(revision 493)
+++ /trunk/source/App/utils/convert_NtoMbit_YCbCr.cpp	(revision 494)
@@ -82,5 +82,9 @@
 
   TComPicYuv frame;
+#if AUXILIARY_PICTURES
+frame.create( width, height, CHROMA_420, 1, 1, 0 );
+#else
   frame.create( width, height, 1, 1, 0 );
+#endif
 
   int pad[2] = {0, 0};
Index: /trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- /trunk/source/Lib/TLibCommon/CommonDef.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/CommonDef.h	(revision 494)
@@ -130,5 +130,14 @@
 extern Int g_bitDepthY;
 extern Int g_bitDepthC;
-
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+extern Int  g_bitDepthYLayer[MAX_LAYERS];
+extern Int  g_bitDepthCLayer[MAX_LAYERS];
+
+extern UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS];    // PCM bit-depth
+extern UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS];    // PCM bit-depth
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+extern void* g_refWeightACDCParam; //type:wpACDCParam
+#endif
 /** clip x, such that 0 <= x <= #g_maxLumaVal */
 template <typename T> inline T ClipY(T x) { return std::min<T>(T((1 << g_bitDepthY)-1), std::max<T>( T(0), x)); }
Index: /trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 494)
@@ -1872,4 +1872,24 @@
 #endif
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Bool TComDataCU::isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkILR = false;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    checkILR = getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId);
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    checkILR = checkILR || getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId);
+  }
+
+  return checkILR;
+}
+#endif
+
 UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
 {
@@ -4004,15 +4024,12 @@
   uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, uiPelY);
 
+#if !LAYER_CTB
   UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
-
-#if SCALED_REF_LAYER_OFFSETS
+#endif
+
   Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
   Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
   Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
   Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
-#else
-  Int iBX = (uiPelX*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
-  Int iBY = (uiPelY*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
-#endif
 
 #if N0139_POSITION_ROUNDING_OFFSET
@@ -4024,22 +4041,32 @@
 #endif
 
-#if SCALED_REF_LAYER_OFFSETS
   if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
        iBX < 0                                        || iBY < 0                                           )
+  {
+    return NULL;
+  }
+
+#if LAYER_CTB
+  UInt baseMaxCUHeight = cBaseColPic->getPicSym()->getMaxCUHeight();
+  UInt baseMaxCUWidth  = cBaseColPic->getPicSym()->getMaxCUWidth();
+  UInt baseMinUnitSize = cBaseColPic->getMinCUWidth();
+  
+  uiCUAddrBase = ( iBY / cBaseColPic->getPicSym()->getMaxCUHeight() ) * cBaseColPic->getFrameWidthInCU() + ( iBX / cBaseColPic->getPicSym()->getMaxCUWidth() );
 #else
-  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
+  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
 #endif
-  {
-    return NULL;
-  }
-
-  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
 
   assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
 
+#if LAYER_CTB
+  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * cBaseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
+  
+  uiAbsPartIdxBase = g_auiLayerRasterToZscan[cBaseColPic->getLayerId()][uiRasterAddrBase];
+#else
   UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
     + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
 
   uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
+#endif
 
   return cBaseColPic->getCU(uiCUAddrBase);
Index: /trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 494)
@@ -492,4 +492,7 @@
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
   Bool          isBipredRestriction( UInt puIdx );
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool          isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
+#endif
 
   // -------------------------------------------------------------------------------------------------------------------
Index: /trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 494)
@@ -79,14 +79,26 @@
 }
 #if SVC_UPSAMPLING
+#if AUXILIARY_PICTURES
+Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
+                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
+#else
 Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
                       Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
-
+#endif
 {
   m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
   if (!bIsVirtual)
   {
+#if AUXILIARY_PICTURES
+    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#else
     m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
-  }
+#endif
+  }
+#if AUXILIARY_PICTURES
+  m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#else
   m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#endif
 
   for( Int i = 0; i < MAX_LAYERS; i++ )
@@ -94,5 +106,9 @@
     if( m_bSpatialEnhLayer[i] )
     {
+#if AUXILIARY_PICTURES
+      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#else
       m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+#endif
     }
   }
@@ -407,5 +423,10 @@
   {
     m_pNDBFilterYuvTmp = new TComPicYuv();
+#if AUXILIARY_PICTURES
+    m_pNDBFilterYuvTmp->create(picWidth, picHeight, getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
+#else
     m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
+#endif
+
   }
 
@@ -801,4 +822,45 @@
 #endif
 
+#if MFM_ENCCONSTRAINT
+Bool TComPic::checkSameRefInfo()
+{
+  Bool bSameRefInfo = true;
+  TComSlice * pSlice0 = getSlice( 0 );
+  for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- )
+  {
+    TComSlice * pSliceN = getSlice( uSliceID );
+    if( pSlice0->getSliceType() != pSliceN->getSliceType() )
+    {
+      bSameRefInfo = false;
+    }
+    else if( pSlice0->getSliceType() != I_SLICE )
+    {
+      Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1;
+      for( Int nList = 0 ; nList < nListNum ; nList++ )
+      {
+        RefPicList eRefList = ( RefPicList )nList;
+        if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) )
+        {
+          for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- )
+          {
+            if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) )
+            {
+              bSameRefInfo = false;
+              break;
+            }
+          }
+        }
+        else
+        {
+          bSameRefInfo = false;
+          break;
+        }
+      }
+    }
+  }
+
+  return( bSameRefInfo );  
+}
+#endif
 
 //! \}
Index: /trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPic.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPic.h	(revision 494)
@@ -102,4 +102,13 @@
   virtual ~TComPic();
   
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
+                        Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
+#else
+  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
+                        Int *numReorderPics, Bool bIsVirtual = false );                        
+#endif
+#else
 #if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
@@ -109,4 +118,5 @@
                         Int *numReorderPics, Bool bIsVirtual = false );                        
 #endif
+#endif
   virtual Void  destroy();
   
@@ -128,4 +138,7 @@
   Void          copyUpsampledMvField  ( UInt refLayerIdc, TComPic* pcPicBase );
   Void          initUpsampledMvField  ();
+#endif
+#if MFM_ENCCONSTRAINT
+  Bool          checkSameRefInfo();
 #endif
 
@@ -163,4 +176,7 @@
   
   Int           getStride()           { return m_apcPicYuv[1]->getStride(); }
+#if AUXILIARY_PICTURES
+  ChromaFormat  getChromaFormat() const { return m_apcPicYuv[1]->getChromaFormat(); }
+#endif
   Int           getCStride()          { return m_apcPicYuv[1]->getCStride(); }
   
Index: /trunk/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 494)
@@ -126,4 +126,9 @@
   TComDataCU*&  getCU( UInt uiCUAddr )  { return m_apcTComDataCU[uiCUAddr];     }
   
+#if LAYER_CTB
+  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
+  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
+#endif
+
 #if AVC_SYNTAX
   UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
Index: /trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 494)
@@ -67,8 +67,16 @@
 {
 }
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
+#else
+Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
+#endif
+#else
 #if SVC_UPSAMPLING
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
 #else
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
+#endif
 #endif
 {
@@ -86,10 +94,18 @@
   m_iCuWidth        = uiMaxCUWidth;
   m_iCuHeight       = uiMaxCUHeight;
+#if AUXILIARY_PICTURES
+  m_chromaFormatIDC = chromaFormatIDC;
+#endif
 
   Int numCuInWidth  = m_iPicWidth  / m_iCuWidth  + (m_iPicWidth  % m_iCuWidth  != 0);
   Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0);
   
+#if LAYER_CTB
+  m_iLumaMarginX    = uiMaxCUWidth  + 16; // for 16-byte alignment
+  m_iLumaMarginY    = uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
+#else
   m_iLumaMarginX    = g_uiMaxCUWidth  + 16; // for 16-byte alignment
   m_iLumaMarginY    = g_uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
+#endif
   
   m_iChromaMarginX  = m_iLumaMarginX>>1;
@@ -234,4 +250,18 @@
 }
 
+#if AUXILIARY_PICTURES
+Void TComPicYuv::convertToMonochrome()
+{
+  Int numPix = ((m_iPicWidth >> 1) + (m_iChromaMarginX << 1)) * ((m_iPicHeight >> 1) + (m_iChromaMarginY << 1));
+  Pel grayVal = (1 << (g_bitDepthC - 1));
+
+  for (UInt i = 0; i < numPix; i++)
+  {
+    m_apiPicBufU[i] = grayVal;
+    m_apiPicBufV[i] = grayVal;
+  }
+}
+#endif
+
 Void TComPicYuv::extendPicBorder ()
 {
Index: /trunk/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 494)
@@ -75,4 +75,7 @@
   Int   m_iPicWidth;            ///< Width of picture
   Int   m_iPicHeight;           ///< Height of picture
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC; ////< Chroma Format
+#endif
   
   Int   m_iCuWidth;             ///< Width of Coding Unit (CU)
@@ -108,4 +111,11 @@
   //  Memory management
   // ------------------------------------------------------------------------------------------------
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+  Void  create      ( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
+#else
+  Void  create      ( Int iPicWidth, Int iPicHeight, ChromaFormat chromaFormatIDC, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
+#endif  
+#else
 #if SVC_UPSAMPLING
   Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
@@ -113,4 +123,5 @@
   Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
 #endif  
+#endif
   
   Void  destroy     ();
@@ -125,4 +136,7 @@
   Int   getWidth    ()     { return  m_iPicWidth;    }
   Int   getHeight   ()     { return  m_iPicHeight;   }
+#if AUXILIARY_PICTURES
+  ChromaFormat  getChromaFormat   ()                     const { return m_chromaFormatIDC; }
+#endif
   
 #if SVC_EXTENSION
@@ -184,4 +198,8 @@
 #endif
 
+#if AUXILIARY_PICTURES
+  Void convertToMonochrome();
+#endif
+
   // Set border extension flag
   Void  setBorderExtension(Bool b) { m_bIsBorderExtended = b; }
Index: /trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 494)
@@ -765,14 +765,28 @@
 
 #if SVC_UPSAMPLING
-#if SCALED_REF_LAYER_OFFSETS
+#if O0215_PHASE_ALIGNMENT
+#if O0194_JOINT_US_BITSHIFT
+Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+{
+  m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
+}
+#else
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
+}
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window);
+}
+#else
 Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
 {
   m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window);
 }
-#else
-Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
-{
-  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic);
-}
+#endif
 #endif
 #endif
Index: /trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 494)
@@ -120,11 +120,19 @@
 #if SVC_EXTENSION
 #if SVC_UPSAMPLING
-#if SCALED_REF_LAYER_OFFSETS
+#if O0215_PHASE_ALIGNMENT
+#if O0194_JOINT_US_BITSHIFT
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+#else
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
-#else
-  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
 #endif
 #endif
+#endif //SVC_EXTENSION
 };
 
Index: /trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -61,5 +61,5 @@
   Double dRdCost = 0.0;
   Double dLambda = 0.0;
-  
+
   switch ( eDFunc )
   {
@@ -80,5 +80,5 @@
       break;
   }
-  
+
   if (bFlag)
   {
@@ -107,5 +107,5 @@
     }
   }
-  
+
   return dRdCost;
 }
@@ -115,5 +115,5 @@
   Double dRdCost = 0.0;
   Double dLambda = 0.0;
-  
+
   switch ( eDFunc )
   {
@@ -134,5 +134,5 @@
       break;
   }
-  
+
   if (bFlag)
   {
@@ -161,5 +161,5 @@
     }
   }
-  
+
   return dRdCost;
 }
@@ -178,5 +178,5 @@
 {
   m_afpDistortFunc[0]  = NULL;                  // for DF_DEFAULT
-  
+
   m_afpDistortFunc[1]  = TComRdCost::xGetSSE;
   m_afpDistortFunc[2]  = TComRdCost::xGetSSE4;
@@ -186,5 +186,5 @@
   m_afpDistortFunc[6]  = TComRdCost::xGetSSE64;
   m_afpDistortFunc[7]  = TComRdCost::xGetSSE16N;
-  
+
   m_afpDistortFunc[8]  = TComRdCost::xGetSAD;
   m_afpDistortFunc[9]  = TComRdCost::xGetSAD4;
@@ -194,5 +194,5 @@
   m_afpDistortFunc[13] = TComRdCost::xGetSAD64;
   m_afpDistortFunc[14] = TComRdCost::xGetSAD16N;
-  
+
   m_afpDistortFunc[15] = TComRdCost::xGetSAD;
   m_afpDistortFunc[16] = TComRdCost::xGetSAD4;
@@ -202,5 +202,5 @@
   m_afpDistortFunc[20] = TComRdCost::xGetSAD64;
   m_afpDistortFunc[21] = TComRdCost::xGetSAD16N;
-  
+
 #if AMP_SAD
   m_afpDistortFunc[43] = TComRdCost::xGetSAD12;
@@ -219,5 +219,5 @@
   m_afpDistortFunc[27] = TComRdCost::xGetHADs;
   m_afpDistortFunc[28] = TComRdCost::xGetHADs;
-  
+
 #if !FIX203
   m_puiComponentCostOriginP = NULL;
@@ -239,16 +239,16 @@
   iSubPelSearchLimit += 4;
   iSubPelSearchLimit *= 8;
-  
+
   if( m_iSearchLimit != iSubPelSearchLimit )
   {
     xUninit();
-    
+
     m_iSearchLimit = iSubPelSearchLimit;
-    
+
     m_puiComponentCostOriginP = new UInt[ 4 * iSubPelSearchLimit ];
     iSubPelSearchLimit *= 2;
-    
+
     m_puiComponentCost = m_puiComponentCostOriginP + iSubPelSearchLimit;
-    
+
     for( Int n = -iSubPelSearchLimit; n < iSubPelSearchLimit; n++)
     {
@@ -272,7 +272,7 @@
   UInt uiLength = 1;
   UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
-  
+
   assert ( uiTemp );
-  
+
   while ( 1 != uiTemp )
   {
@@ -280,5 +280,5 @@
     uiLength += 2;
   }
-  
+
   return uiLength;
 }
@@ -290,5 +290,5 @@
   rcDistParam.iRows    = uiBlkHeight;
   rcDistParam.DistFunc = m_afpDistortFunc[eDFunc + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
-  
+
   // initialize
   rcDistParam.iSubShift  = 0;
@@ -301,13 +301,13 @@
   rcDistParam.pOrg = pcPatternKey->getROIY();
   rcDistParam.pCur = piRefY;
-  
+
   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride();
   rcDistParam.iStrideCur = iRefStride;
-  
+
   // set Block Width / Height
   rcDistParam.iCols    = pcPatternKey->getROIYWidth();
   rcDistParam.iRows    = pcPatternKey->getROIYHeight();
   rcDistParam.DistFunc = m_afpDistortFunc[DF_SAD + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
-  
+
 #if AMP_SAD
   if (rcDistParam.iCols == 12)
@@ -336,14 +336,18 @@
 #endif
 {
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Bug fix: The correct bit depth has not been used for weighted cost calculation
+  rcDistParam.bitDepth = g_bitDepthY;
+#endif
   // set Original & Curr Pointer / Stride
   rcDistParam.pOrg = pcPatternKey->getROIY();
   rcDistParam.pCur = piRefY;
-  
+
   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride();
   rcDistParam.iStrideCur = iRefStride * iStep;
-  
+
   // set Step for interpolated buffer
   rcDistParam.iStep = iStep;
-  
+
   // set Block Width / Height
   rcDistParam.iCols    = pcPatternKey->getROIYWidth();
@@ -352,5 +356,5 @@
   rcDistParam.bUseNSHAD = bUseNSHAD;
 #endif
-  
+
   // set distortion function
   if ( !bHADME )
@@ -376,5 +380,5 @@
     rcDistParam.DistFunc = m_afpDistortFunc[DF_HADS + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
   }
-  
+
   // initialize
   rcDistParam.iSubShift  = 0;
@@ -407,5 +411,5 @@
   UInt uiSum = 0;
   Int x, y;
-  
+
   if ( ( (iWidth % 8) == 0 ) && ( (iHeight % 8) == 0 ) )
   {
@@ -444,5 +448,5 @@
     }
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
 
@@ -523,7 +527,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur;
   Int  iStrideOrg = pcDtParam->iStrideOrg;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-- )
   {
@@ -535,5 +539,5 @@
     piCur += iStrideCur;
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -541,5 +545,5 @@
 UInt TComRdCost::xGetSAD4( DistParam* pcDtParam )
 {
-  if ( pcDtParam->bApplyWeight ) 
+  if ( pcDtParam->bApplyWeight )
   {
     return xGetSADw( pcDtParam );
@@ -552,7 +556,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -561,9 +565,9 @@
     uiSum += abs( piOrg[2] - piCur[2] );
     uiSum += abs( piOrg[3] - piCur[3] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -583,7 +587,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -596,9 +600,9 @@
     uiSum += abs( piOrg[6] - piCur[6] );
     uiSum += abs( piOrg[7] - piCur[7] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -618,7 +622,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -639,9 +643,9 @@
     uiSum += abs( piOrg[14] - piCur[14] );
     uiSum += abs( piOrg[15] - piCur[15] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -662,7 +666,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -679,9 +683,9 @@
     uiSum += abs( piOrg[10] - piCur[10] );
     uiSum += abs( piOrg[11] - piCur[11] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -699,7 +703,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -726,5 +730,5 @@
     piCur += iStrideCur;
   }
-  
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -744,7 +748,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -781,9 +785,9 @@
     uiSum += abs( piOrg[30] - piCur[30] );
     uiSum += abs( piOrg[31] - piCur[31] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -804,7 +808,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -833,9 +837,9 @@
     uiSum += abs( piOrg[22] - piCur[22] );
     uiSum += abs( piOrg[23] - piCur[23] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -857,7 +861,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -926,9 +930,9 @@
     uiSum += abs( piOrg[62] - piCur[62] );
     uiSum += abs( piOrg[63] - piCur[63] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -949,7 +953,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -1002,9 +1006,9 @@
     uiSum += abs( piOrg[46] - piCur[46] );
     uiSum += abs( piOrg[47] - piCur[47] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -1028,10 +1032,10 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1044,5 +1048,5 @@
     piCur += iStrideCur;
   }
-  
+
   return ( uiSum );
 }
@@ -1060,22 +1064,22 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1093,10 +1097,10 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1109,9 +1113,9 @@
     iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1129,13 +1133,13 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1154,9 +1158,9 @@
     iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1174,14 +1178,14 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
     for (Int n = 0; n < iCols; n+=16 )
     {
-      
+
       iTemp = piOrg[n+ 0] - piCur[n+ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
       iTemp = piOrg[n+ 1] - piCur[n+ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1200,10 +1204,10 @@
       iTemp = piOrg[n+14] - piCur[n+14]; uiSum += ( iTemp * iTemp ) >> uiShift;
       iTemp = piOrg[n+15] - piCur[n+15]; uiSum += ( iTemp * iTemp ) >> uiShift;
-      
-    }
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    }
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1221,12 +1225,12 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1261,9 +1265,9 @@
     iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1281,9 +1285,9 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1352,9 +1356,9 @@
     iTemp = piOrg[62] - piCur[62]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[63] - piCur[63]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1376,10 +1380,10 @@
   m[2] = diff[0] - diff[2];
   m[3] = diff[1] - diff[3];
-  
+
   satd += abs(m[0] + m[1]);
   satd += abs(m[0] - m[1]);
   satd += abs(m[2] + m[3]);
   satd += abs(m[2] - m[3]);
-  
+
   return satd;
 }
@@ -1388,5 +1392,5 @@
 {
   Int k, satd = 0, diff[16], m[16], d[16];
-  
+
   assert( iStep == 1 );
   for( k = 0; k < 16; k+=4 )
@@ -1396,9 +1400,9 @@
     diff[k+2] = piOrg[2] - piCur[2];
     diff[k+3] = piOrg[3] - piCur[3];
-    
-    piCur += iStrideCur;
-    piOrg += iStrideOrg;
-  }
-  
+
+    piCur += iStrideCur;
+    piOrg += iStrideOrg;
+  }
+
   /*===== hadamard transform =====*/
   m[ 0] = diff[ 0] + diff[12];
@@ -1418,5 +1422,5 @@
   m[14] = diff[ 2] - diff[14];
   m[15] = diff[ 3] - diff[15];
-  
+
   d[ 0] = m[ 0] + m[ 4];
   d[ 1] = m[ 1] + m[ 5];
@@ -1435,5 +1439,5 @@
   d[14] = m[14] - m[10];
   d[15] = m[15] - m[11];
-  
+
   m[ 0] = d[ 0] + d[ 3];
   m[ 1] = d[ 1] + d[ 2];
@@ -1452,5 +1456,5 @@
   m[14] = d[13] - d[14];
   m[15] = d[12] - d[15];
-  
+
   d[ 0] = m[ 0] + m[ 1];
   d[ 1] = m[ 0] - m[ 1];
@@ -1469,5 +1473,5 @@
   d[14] = m[14] + m[15];
   d[15] = m[15] - m[14];
-  
+
   for (k=0; k<16; ++k)
   {
@@ -1475,5 +1479,5 @@
   }
   satd = ((satd+1)>>1);
-  
+
   return satd;
 }
@@ -1494,9 +1498,9 @@
     diff[k+6] = piOrg[6] - piCur[6];
     diff[k+7] = piOrg[7] - piCur[7];
-    
-    piCur += iStrideCur;
-    piOrg += iStrideOrg;
-  }
-  
+
+    piCur += iStrideCur;
+    piOrg += iStrideOrg;
+  }
+
   //horizontal
   for (j=0; j < 8; j++)
@@ -1511,5 +1515,5 @@
     m2[j][6] = diff[jj+2] - diff[jj+6];
     m2[j][7] = diff[jj+3] - diff[jj+7];
-    
+
     m1[j][0] = m2[j][0] + m2[j][2];
     m1[j][1] = m2[j][1] + m2[j][3];
@@ -1520,5 +1524,5 @@
     m1[j][6] = m2[j][4] - m2[j][6];
     m1[j][7] = m2[j][5] - m2[j][7];
-    
+
     m2[j][0] = m1[j][0] + m1[j][1];
     m2[j][1] = m1[j][0] - m1[j][1];
@@ -1530,5 +1534,5 @@
     m2[j][7] = m1[j][6] - m1[j][7];
   }
-  
+
   //vertical
   for (i=0; i < 8; i++)
@@ -1542,5 +1546,5 @@
     m3[6][i] = m2[2][i] - m2[6][i];
     m3[7][i] = m2[3][i] - m2[7][i];
-    
+
     m1[0][i] = m3[0][i] + m3[2][i];
     m1[1][i] = m3[1][i] + m3[3][i];
@@ -1551,5 +1555,5 @@
     m1[6][i] = m3[4][i] - m3[6][i];
     m1[7][i] = m3[5][i] - m3[7][i];
-    
+
     m2[0][i] = m1[0][i] + m1[1][i];
     m2[1][i] = m1[0][i] - m1[1][i];
@@ -1561,5 +1565,5 @@
     m2[7][i] = m1[6][i] - m1[7][i];
   }
-  
+
   for (i = 0; i < 8; i++)
   {
@@ -1569,7 +1573,7 @@
     }
   }
-  
+
   sad=((sad+2)>>2);
-  
+
   return sad;
 }
@@ -1681,5 +1685,5 @@
   //vertical
   for (i=0; i < 16; i++)
-  {    
+  {
     m2[0][i] = m1[0][i] + m1[2][i];
     m2[1][i] = m1[1][i] + m1[3][i];
@@ -1838,7 +1842,7 @@
   Int  iOffsetOrg = iStrideOrg<<2;
   Int  iOffsetCur = iStrideCur<<2;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for ( y=0; y<iRows; y+= 4 )
   {
@@ -1847,5 +1851,5 @@
     piCur += iOffsetCur;
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -1864,7 +1868,7 @@
   Int  iStep  = pcDtParam->iStep;
   Int  y;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   if ( iRows == 4 )
   {
@@ -1883,5 +1887,5 @@
     }
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -1900,9 +1904,9 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStep  = pcDtParam->iStep;
-  
+
   Int  x, y;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
 #if NS_HAD
   if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )
@@ -1924,5 +1928,5 @@
   }
 #if NS_HAD
-  else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD ) 
+  else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )
   {
     Int  iOffsetOrg = iStrideOrg<<2;
@@ -1938,5 +1942,5 @@
     }
   }
-  else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD ) 
+  else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )
   {
     Int  iOffsetOrg = iStrideOrg<<4;
@@ -1957,5 +1961,5 @@
     Int  iOffsetOrg = iStrideOrg<<2;
     Int  iOffsetCur = iStrideCur<<2;
-    
+
     for ( y=0; y<iRows; y+= 4 )
     {
@@ -1986,5 +1990,5 @@
     assert(false);
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
Index: /trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 494)
@@ -86,5 +86,14 @@
 // Data structure related table & variable
 // ====================================================================================================================
-
+#if LAYER_CTB
+UInt g_auiLayerMaxCUWidth[MAX_LAYERS];
+UInt g_auiLayerMaxCUHeight[MAX_LAYERS];
+UInt g_auiLayerMaxCUDepth[MAX_LAYERS];
+UInt g_auiLayerAddCUDepth[MAX_LAYERS];
+UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+#endif
 UInt g_uiMaxCUWidth  = MAX_CU_SIZE;
 UInt g_uiMaxCUHeight = MAX_CU_SIZE;
@@ -312,5 +321,14 @@
 UInt g_uiPCMBitDepthLuma     = 8;    // PCM bit-depth
 UInt g_uiPCMBitDepthChroma   = 8;    // PCM bit-depth
-
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+Int  g_bitDepthYLayer[MAX_LAYERS];
+Int  g_bitDepthCLayer[MAX_LAYERS];
+
+UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS];    // PCM bit-depth
+UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS];    // PCM bit-depth
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+void * g_refWeightACDCParam; // type=wpACDCParam
+#endif
 // ====================================================================================================================
 // Misc.
Index: /trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComRom.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComRom.h	(revision 494)
@@ -81,4 +81,14 @@
 
 // global variable (LCU width/height, max. CU depth)
+#if LAYER_CTB
+extern       UInt g_auiLayerMaxCUWidth[MAX_LAYERS];
+extern       UInt g_auiLayerMaxCUHeight[MAX_LAYERS];
+extern       UInt g_auiLayerMaxCUDepth[MAX_LAYERS];
+extern       UInt g_auiLayerAddCUDepth[MAX_LAYERS];
+extern       UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+extern       UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+extern       UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+extern       UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
+#endif
 extern       UInt g_uiMaxCUWidth;
 extern       UInt g_uiMaxCUHeight;
Index: /trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 494)
@@ -75,10 +75,4 @@
 , m_iDepth                        ( 0 )
 , m_bRefenced                     ( false )
-#if POC_RESET_FLAG
-, m_bPocResetFlag                 ( false )
-#endif
-#if SH_DISCARDABLE_FLAG
-, m_bDiscardableFlag              ( false )
-#endif
 , m_pcSPS                         ( NULL )
 , m_pcPPS                         ( NULL )
@@ -93,7 +87,4 @@
 #endif
 , m_uiTLayer                      ( 0 )
-#if SVC_EXTENSION
-, m_layerId                     ( 0 )
-#endif
 , m_bTLayerSwitchingFlag          ( false )
 , m_sliceMode                   ( 0 )
@@ -118,4 +109,14 @@
 , m_temporalLayerNonReferenceFlag ( false )
 , m_enableTMVPFlag                ( true )
+#if SVC_EXTENSION
+, m_layerId                     ( 0 )
+#if REF_IDX_MFM
+, m_bMFMEnabledFlag               ( false )
+#endif
+#if POC_RESET_FLAG
+, m_bPocResetFlag                 ( false )
+#endif
+, m_bDiscardableFlag              ( false )
+#endif //SVC_EXTENSION
 {
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
@@ -138,5 +139,5 @@
   m_interLayerSamplePredOnlyFlag = false;
 #endif
-#endif
+#endif //SVC_EXTENSION
 
   initEqualRef();
@@ -455,11 +456,10 @@
     UInt refLayerIdc = m_interLayerPredLayerIdc[i];
     //inter-layer reference picture
-
-#if ILR_RESTR
+#if O0225_MAX_TID_FOR_REF_LAYERS
+    Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId) : 0;
+#else
     Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
+#endif 
     if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
-#else //#if ILR_RESTR
-    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
-#endif //#if ILR_RESTR
     {
 #if REF_IDX_MFM
@@ -485,5 +485,4 @@
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
 #if SVC_EXTENSION
-#if ILR_RESTR
   Int numInterLayerRPSPics = 0;
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -495,5 +494,9 @@
     for( i=0; i < m_pcVPS->getNumDirectRefLayers( m_layerId ); i++ )
     {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+      Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId(),m_layerId);
+#else
       Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId());
+#endif 
       if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
       {
@@ -574,5 +577,4 @@
 #endif
   }
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_activeNumILRRefIdx;
@@ -580,7 +582,7 @@
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_numILRRefIdx;
 #endif 
-#else
+#else //SVC_EXTENSION
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
-#endif
+#endif //SVC_EXTENSION
 #if FIX1071
   if (checkNumPocTotalCurr)
@@ -631,5 +633,5 @@
 #if RPL_INIT_N0316_N0082
     if( m_layerId > 0 )
-    {
+    {      
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
       for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)      
@@ -639,13 +641,17 @@
       {
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
-#if ILR_RESTR
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
+#else
         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#endif
         if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
-#endif
+        {
           rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
-      }
-    }
-#endif
-#endif 
+        }
+      }
+    }
+#endif
+#endif //SVC_EXTENSION
     for ( i=0; i<NumPocStCurr1; i++, cIdx++)
     {
@@ -667,9 +673,13 @@
       {
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
-#if ILR_RESTR
-         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
+#else
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#endif 
         if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
-#endif
-        rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
+        {
+          rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
+        }
       }
     }
@@ -704,12 +714,16 @@
       {
         Int refLayerIdc = m_interLayerPredLayerIdc[i];
-#if ILR_RESTR
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
+#else
         Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+#endif 
         if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
-#endif
-        rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
-      }
-    }
-#endif
+        {
+          rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
+        }
+      }
+    }
+#endif //SVC_EXTENSION
 
     assert(cIdx == numPocTotalCurr);
@@ -781,7 +795,4 @@
 #if N0147_IRAP_ALIGN_FLAG
   hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_0] > 1 );
-#endif
-#if FINAL_RPL_CHANGE_N0082
-  hasModification = false; //modification is not necessary
 #endif
   refPicListModification->setRefPicListModificationFlagL0(hasModification);
@@ -1133,4 +1144,5 @@
 #if SVC_EXTENSION
   m_pcVPS                = pSrc->m_pcVPS;
+  m_layerId              = pSrc->m_layerId;
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_activeNumILRRefIdx         = pSrc->m_activeNumILRRefIdx;
@@ -1847,5 +1859,29 @@
   return retVal;
 }
+#if AUXILIARY_PICTURES
+ChromaFormat TComSlice::getChromaFormatIdc()
+#else
 UInt TComSlice::getChromaFormatIdc()
+#endif
+{
+  TComSPS *sps = getSPS();
+  TComVPS *vps = getVPS();
+#if AUXILIARY_PICTURES
+  ChromaFormat retVal;
+  UInt layerId = getLayerId();
+#else
+  UInt retVal, layerId = getLayerId();
+#endif
+  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
+  {
+    retVal = sps->getChromaFormatIdc();
+  }
+  else
+  {
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
+  }
+  return retVal;
+}
+UInt TComSlice::getBitDepthY()
 {
   TComSPS *sps = getSPS();
@@ -1854,13 +1890,13 @@
   if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
   {
-    retVal = sps->getChromaFormatIdc();
+    retVal = sps->getBitDepthY();
   }
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
   }
   return retVal;
 }
-UInt TComSlice::getBitDepthY()
+UInt TComSlice::getBitDepthC()
 {
   TComSPS *sps = getSPS();
@@ -1869,27 +1905,12 @@
   if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
   {
-    retVal = sps->getBitDepthY();
+    retVal = sps->getBitDepthC();
   }
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
   }
   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()
 {
@@ -1902,5 +1923,9 @@
 
 RepFormat::RepFormat()
+#if AUXILIARY_PICTURES
+: m_chromaFormatVpsIdc          (CHROMA_420)
+#else
 : m_chromaFormatVpsIdc          (0)
+#endif
 , m_separateColourPlaneVpsFlag  (false)
 , m_picWidthVpsInLumaSamples    (0)
@@ -1914,4 +1939,5 @@
 // Video parameter set (VPS)
 // ------------------------------------------------------------------------------------------------
+#if SVC_EXTENSION
 TComVPS::TComVPS()
 : m_VPSId                     (  0)
@@ -1933,10 +1959,8 @@
 , m_numOutputLayerSets        (0)  
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
 , m_numProfileTierLevel       (0)
 , m_moreOutputLayerSetsThanDefaultFlag (false)
 , m_numAddOutputLayerSets     (0)
 , m_defaultOneTargetOutputLayerFlag    (false)
-#endif
 #if VPS_VUI_BITRATE_PICRATE
 , m_bitRatePresentVpsFlag     (false)
@@ -1992,9 +2016,10 @@
   ::memset(m_numLayerInIdList,     0, sizeof(m_numLayerInIdList   )); 
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
   ::memset(m_profileLevelTierIdx,  0, sizeof(m_profileLevelTierIdx));
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_maxOneActiveRefLayerFlag = true;
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  ::memset(m_pocLsbNotPresentFlag, 0, sizeof(m_pocLsbNotPresentFlag));
 #endif
 #if N0147_IRAP_ALIGN_FLAG
@@ -2007,5 +2032,12 @@
   for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
   {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  for( Int j = 0; j < MAX_VPS_LAYER_ID_PLUS1; j++)
+  {
+    m_maxTidIlRefPicsPlus1[i][j] = m_uiMaxTLayers + 1;
+  }
+#else
     m_maxTidIlRefPicsPlus1[i] = m_uiMaxTLayers + 1;
+#endif 
   }
 #endif
@@ -2034,4 +2066,24 @@
 #endif
 }
+#else
+TComVPS::TComVPS()
+: m_VPSId                     (  0)
+, m_uiMaxTLayers              (  1)
+, m_uiMaxLayers               (  1)
+, m_bTemporalIdNestingFlag    (false)
+, m_numHrdParameters          (  0)
+, m_maxNuhReservedZeroLayerId (  0)
+, m_hrdParameters             (NULL)
+, m_hrdOpSetIdx               (NULL)
+, m_cprmsPresentFlag          (NULL)
+{
+  for( Int i = 0; i < MAX_TLAYER; i++)
+  {
+    m_numReorderPics[i] = 0;
+    m_uiMaxDecPicBuffering[i] = 1; 
+    m_uiMaxLatencyIncrease[i] = 0;
+  }
+}
+#endif //SVC_EXTENSION
 
 TComVPS::~TComVPS()
@@ -2163,17 +2215,15 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
+#if SVC_EXTENSION
 #if M0463_VUI_EXT_ILP_REF
 , m_interViewMvVertConstraintFlag (false)
 , m_numIlpRestrictedRefLayers ( 0 )
 #endif
-#if SVC_EXTENSION
-, m_layerId(0)
-#endif
-#if SCALED_REF_LAYER_OFFSETS
-, m_numScaledRefLayerOffsets  (0)
-#endif
+, m_layerId                   ( 0 )
+, m_numScaledRefLayerOffsets  ( 0 )
 #if REPN_FORMAT_IN_VPS
 , m_updateRepFormatFlag       (false)
 #endif
+#endif //SVC_EXTENSION
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
@@ -3038,5 +3088,15 @@
 #endif
 }
-#endif 
+
+#if MFM_ENCCONSTRAINT
+TComPic* TComSlice::getBaseColPic(  TComList<TComPic*>& rcListPic )
+{
+#if POC_RESET_FLAG
+  return xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
+#else
+  return xGetRefPic( rcListPic, m_iPOC );
+#endif
+}
+#endif
 
 #if REF_IDX_MFM
@@ -3085,3 +3145,26 @@
 #endif
 
+Void TComSlice::setILRPic(TComPic **pcIlpPic)
+{
+  for( Int i = 0; i < m_activeNumILRRefIdx; i++ )
+  {
+    Int refLayerIdc = m_interLayerPredLayerIdc[i];
+
+    if( pcIlpPic[refLayerIdc] )
+    {
+      pcIlpPic[refLayerIdc]->copyUpsampledPictureYuv( m_pcPic->getFullPelBaseRec( refLayerIdc ), pcIlpPic[refLayerIdc]->getPicYuvRec() );
+      pcIlpPic[refLayerIdc]->getSlice(0)->setPOC( m_iPOC );
+      pcIlpPic[refLayerIdc]->setLayerId( m_pcBaseColPic[refLayerIdc]->getLayerId() ); //set reference layerId
+      pcIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension( false );
+      pcIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+      for (Int j=0; j<pcIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
+      {
+        pcIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId( pcIlpPic[refLayerIdc]->getLayerId() );
+      }
+    }
+  }
+}
+
+#endif //SVC_EXTENSION
+
 //! \}
Index: /trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComSlice.h	(revision 494)
@@ -436,5 +436,9 @@
 class RepFormat
 {
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatVpsIdc;
+#else
   Int  m_chromaFormatVpsIdc;
+#endif
   Bool m_separateColourPlaneVpsFlag;
   Int  m_picWidthVpsInLumaSamples;
@@ -446,6 +450,11 @@
   RepFormat();
 
+#if AUXILIARY_PICTURES
+  ChromaFormat getChromaFormatVpsIdc()        { return m_chromaFormatVpsIdc; }
+  Void setChromaFormatVpsIdc(ChromaFormat x)  { m_chromaFormatVpsIdc = x;    }
+#else
   Int  getChromaFormatVpsIdc()        { return m_chromaFormatVpsIdc; }
   Void setChromaFormatVpsIdc(Int x)   { m_chromaFormatVpsIdc = x;    }
+#endif
 
   Bool getSeparateColourPlaneVpsFlag()        { return m_separateColourPlaneVpsFlag; }
@@ -484,24 +493,27 @@
   UInt*       m_hrdOpSetIdx;
   Bool*       m_cprmsPresentFlag;
+#if !SVC_EXTENSION
+  UInt        m_numOpSets;
+  Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
+#endif
+  TComPTL     m_pcPTL;
+  TimingInfo  m_timingInfo;
+
+#if SVC_EXTENSION
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
+#if IL_SL_SIGNALLING_N0371
+  Bool        m_scalingListLayerDependency[MAX_LAYERS][MAX_LAYERS];  // layer dependency for scaling list
+#endif
+#if VPS_EXTN_OFFSET
+  UInt        m_extensionOffset;
+#endif
 #if VPS_RENAME
   UInt        m_maxLayerId;
   UInt        m_numLayerSets;
   Bool        m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-#else
-  UInt        m_numOpSets;
-  Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
-#endif
-#if DERIVE_LAYER_ID_LIST_VARIABLES
-  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
-#endif
-#if IL_SL_SIGNALLING_N0371
-  Bool        m_scalingListLayerDependency[MAX_LAYERS][MAX_LAYERS];  // layer dependency for scaling list
-#endif
-#if VPS_EXTN_OFFSET
-  UInt        m_extensionOffset;
-#endif
-  TComPTL     m_pcPTL;
-  TimingInfo  m_timingInfo;
+#endif
 
   // ------------------------------------------
@@ -546,5 +558,4 @@
 #endif
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
   UInt       m_numProfileTierLevel;
   Bool       m_moreOutputLayerSetsThanDefaultFlag;
@@ -552,13 +563,19 @@
   Bool       m_defaultOneTargetOutputLayerFlag;
   Int        m_profileLevelTierIdx[64];     
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Bool       m_maxOneActiveRefLayerFlag;
 #endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  Bool       m_pocLsbNotPresentFlag[MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #if N0147_IRAP_ALIGN_FLAG
   Bool       m_crossLayerIrapAlignFlag;
 #endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1][MAX_VPS_LAYER_ID_PLUS1];
+#else
   UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
+#endif
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -597,4 +614,9 @@
   Int         m_viewIdVal                [MAX_LAYERS];
 #endif
+
+#if O0215_PHASE_ALIGNMENT
+  Bool       m_phaseAlignFlag;
+#endif
+#endif //SVC_EXTENSION
 public:
   TComVPS();
@@ -637,12 +659,6 @@
   UInt    getNumHrdParameters()                                 { return m_numHrdParameters; }
   Void    setNumHrdParameters(UInt v)                           { m_numHrdParameters = v;    }
-
-#if VPS_RENAME
-  UInt    getMaxLayerId()                                       { return m_maxLayerId; }
-  Void    setMaxLayerId(UInt v)                                 { m_maxLayerId = v;    }
-
-  UInt    getNumLayerSets()                                     { return m_numLayerSets; }
-  Void    setNumLayerSets(UInt v)                               { m_numLayerSets = v;    }
-#else
+  
+#if !SVC_EXTENSION
   UInt    getMaxNuhReservedZeroLayerId()                        { return m_maxNuhReservedZeroLayerId; }
   Void    setMaxNuhReservedZeroLayerId(UInt v)                  { m_maxNuhReservedZeroLayerId = v;    }
@@ -653,4 +669,9 @@
   Bool    getLayerIdIncludedFlag(UInt opsIdx, UInt id)          { return m_layerIdIncludedFlag[opsIdx][id]; }
   Void    setLayerIdIncludedFlag(Bool v, UInt opsIdx, UInt id)  { m_layerIdIncludedFlag[opsIdx][id] = v;    }
+
+  TComPTL* getPTL() { return &m_pcPTL; }
+  TimingInfo* getTimingInfo() { return &m_timingInfo; }
+
+#if SVC_EXTENSION
 #if DERIVE_LAYER_ID_LIST_VARIABLES
   Int     getLayerSetLayerIdList(Int set, Int layerId)          { return m_layerSetLayerIdList[set][layerId]; }
@@ -669,6 +690,11 @@
 #endif
 
-  TComPTL* getPTL() { return &m_pcPTL; }
-  TimingInfo* getTimingInfo() { return &m_timingInfo; }
+#if VPS_RENAME
+  UInt    getMaxLayerId()                                       { return m_maxLayerId; }
+  Void    setMaxLayerId(UInt v)                                 { m_maxLayerId = v;    }
+
+  UInt    getNumLayerSets()                                     { return m_numLayerSets; }
+  Void    setNumLayerSets(UInt v)                               { m_numLayerSets = v;    }
+#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   Bool   getAvcBaseLayerFlag()                                  { return m_avcBaseLayerFlag;       }
@@ -743,5 +769,4 @@
 #endif
 #endif
-#if VPS_PROFILE_OUTPUT_LAYERS
   UInt   getNumProfileTierLevel()                                { return m_numProfileTierLevel; }
   Void   setNumProfileTierLevel(Int x)                           { m_numProfileTierLevel = x;    }
@@ -758,9 +783,12 @@
   Int    getProfileLevelTierIdx(Int i)                        { return m_profileLevelTierIdx[i]; }
   Void   setProfileLevelTierIdx(Int i, Int x)                 { m_profileLevelTierIdx[i] = x   ; }
-#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Bool   getMaxOneActiveRefLayerFlag()                                          { return m_maxOneActiveRefLayerFlag;                      }
   Void   setMaxOneActiveRefLayerFlag(Bool x)                                    { m_maxOneActiveRefLayerFlag = x;                         }
-#endif 
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  UInt   getPocLsbNotPresentFlag(Int i)                                         { return m_pocLsbNotPresentFlag[i]; }
+  Void   setPocLsbNotPresentFlag(Int i, Bool x)                                 { m_pocLsbNotPresentFlag[i] = x;    }
+#endif
 #if N0147_IRAP_ALIGN_FLAG
   Bool   getCrossLayerIrapAlignFlag()                                           { return m_crossLayerIrapAlignFlag;                      }
@@ -768,6 +796,11 @@
 #endif 
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  UInt   getMaxTidIlRefPicsPlus1(Int layerId, Int refLayerId)                     { return m_maxTidIlRefPicsPlus1[layerId][refLayerId];           }
+  Void   setMaxTidIlRefPicsPlus1(Int layerId, Int refLayerId, UInt maxSublayer)   { m_maxTidIlRefPicsPlus1[layerId][refLayerId] = maxSublayer;    }
+#else
   UInt   getMaxTidIlRefPicsPlus1(Int layerId)                     { return m_maxTidIlRefPicsPlus1[layerId];                   }
   Void   setMaxTidIlRefPicsPlus1(Int layerId, UInt maxSublayer)   { m_maxTidIlRefPicsPlus1[layerId] = maxSublayer;            }
+#endif
 #endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -847,4 +880,9 @@
   Void    setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
 #endif
+#if O0215_PHASE_ALIGNMENT
+  Bool   getPhaseAlignFlag()                             { return m_phaseAlignFlag; }
+  Void   setPhaseAlignFlag(Bool x)                       { m_phaseAlignFlag = x;    }
+#endif
+#endif //SVC_EXTENSION
 };
 
@@ -924,8 +962,4 @@
   TComHRD m_hrdParameters;
   TimingInfo m_timingInfo;
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-  Bool m_tileBoundariesAlignedFlag;
-#endif
-
 
 public:
@@ -960,7 +994,4 @@
     ,m_log2MaxMvLengthHorizontal(15)
     ,m_log2MaxMvLengthVertical(15)
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-    ,m_tileBoundariesAlignedFlag(true)
-#endif
   {}
 
@@ -1058,8 +1089,4 @@
   TComHRD* getHrdParameters                 ()             { return &m_hrdParameters; }
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-  Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
-  Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
-#endif
 };
 
@@ -1070,5 +1097,9 @@
   Int         m_SPSId;
   Int         m_VPSId;
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIdc;
+#else
   Int         m_chromaFormatIdc;
+#endif
 
   UInt        m_uiMaxTLayers;           // maximum number of temporal layers
@@ -1143,4 +1174,5 @@
   TComPTL     m_pcPTL;
 
+#if SVC_EXTENSION
 #if M0463_VUI_EXT_ILP_REF
   Bool        m_interViewMvVertConstraintFlag;
@@ -1151,5 +1183,4 @@
 #endif
 
-#if SVC_EXTENSION
   UInt m_layerId;
 
@@ -1161,5 +1192,4 @@
 #endif
 
-#endif
 #if REF_IDX_MFM
 #if !M0457_COL_PICTURE_SIGNALING
@@ -1167,11 +1197,10 @@
 #endif
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   UInt        m_numScaledRefLayerOffsets;
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
-#endif
 #if REPN_FORMAT_IN_VPS
   Bool m_updateRepFormatFlag;
 #endif
+#endif //SVC_EXTENSION
 public:
   TComSPS();
@@ -1182,4 +1211,12 @@
   Int  getSPSId       ()         { return m_SPSId;          }
   Void setSPSId       (Int i)    { m_SPSId = i;             }
+
+#if AUXILIARY_PICTURES
+  ChromaFormat getChromaFormatIdc ()         { return m_chromaFormatIdc;       }
+  Void setChromaFormatIdc (ChromaFormat i)   { m_chromaFormatIdc = i;          }
+
+  static Int getWinUnitX (Int chromaFormatIdc) { assert (chromaFormatIdc >= 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitX[chromaFormatIdc];      }
+  static Int getWinUnitY (Int chromaFormatIdc) { assert (chromaFormatIdc >= 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitY[chromaFormatIdc];      }
+#else
   Int  getChromaFormatIdc ()         { return m_chromaFormatIdc;       }
   Void setChromaFormatIdc (Int i)    { m_chromaFormatIdc = i;          }
@@ -1187,4 +1224,5 @@
   static Int getWinUnitX (Int chromaFormatIdc) { assert (chromaFormatIdc > 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitX[chromaFormatIdc];      }
   static Int getWinUnitY (Int chromaFormatIdc) { assert (chromaFormatIdc > 0 && chromaFormatIdc <= MAX_CHROMA_FORMAT_IDC); return m_winUnitY[chromaFormatIdc];      }
+#endif
   
   // structure
@@ -1334,5 +1372,4 @@
   Void     setLayerId(UInt layerId) { m_layerId = layerId; }
   UInt     getLayerId() { return m_layerId; }
-#endif
 #if REF_IDX_MFM
 #if !M0457_COL_PICTURE_SIGNALING
@@ -1341,13 +1378,12 @@
 #endif
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
   Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
   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
+#endif //SVC_EXTENSION
 };
 
@@ -1604,4 +1640,7 @@
   Int64 iAC;
   Int64 iDC;
+#if O0194_WEIGHTED_PREDICTION_CGS
+  Int iSamples;
+#endif
 } wpACDCParam;
 
@@ -1636,16 +1675,4 @@
   Int         m_deblockingFilterBetaOffsetDiv2;    //< beta offset for deblocking filter
   Int         m_deblockingFilterTcOffsetDiv2;      //< tc offset for deblocking filter
-#if JCTVC_M0458_INTERLAYER_RPS_SIG
-  Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
-  Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
-#else
-#if SVC_EXTENSION
-  Int         m_numILRRefIdx;       //< for inter-layer reference picture ser
-#endif
-#endif 
-#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
-  Int         m_numSamplePredRefLayers;
-  Bool        m_interLayerSamplePredOnlyFlag;
-#endif
   Int         m_list1IdxToList0Idx[MAX_NUM_REF];
   Int         m_aiNumRefIdx   [2];    //  for multiple reference of current slice
@@ -1664,12 +1691,5 @@
   // referenced slice?
   Bool        m_bRefenced;
-  
-#if POC_RESET_FLAG
-  Bool        m_bPocResetFlag;
-  Int         m_pocValueBeforeReset;
-#endif  
-#if SH_DISCARDABLE_FLAG
-  Bool        m_bDiscardableFlag;
-#endif
+
   // access channel
   TComVPS*    m_pcVPS;
@@ -1685,5 +1705,4 @@
   UInt        m_maxNumMergeCand;
 
-
 #if SAO_CHROMA_LAMBDA
   Double      m_dLambdaLuma;
@@ -1695,18 +1714,4 @@
   Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
   UInt        m_uiTLayer;
-#if SVC_EXTENSION
-  UInt        m_layerId;
-  TComPic*    m_pcBaseColPic[MAX_LAYERS];
-  TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
-#if M0457_COL_PICTURE_SIGNALING
-  Int         m_numMotionPredRefLayers;
-#if REF_IDX_MFM
-  Bool        m_bMFMEnabledFlag;
-  Int         m_colRefLayerIdx;
-  Bool        m_altColIndicationFlag;
-  TComPic*    m_pcIlpPic;
-#endif
-#endif
-#endif 
   Bool        m_bTLayerSwitchingFlag;
 
@@ -1742,7 +1747,39 @@
 
   Bool       m_enableTMVPFlag;
+
+#if SVC_EXTENSION
+  UInt        m_layerId;
+  TComPic*    m_pcBaseColPic[MAX_LAYERS];
+  TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
+#if M0457_COL_PICTURE_SIGNALING
+  Int         m_numMotionPredRefLayers;
+#if REF_IDX_MFM
+  Bool        m_bMFMEnabledFlag;
+  Int         m_colRefLayerIdx;
+  Bool        m_altColIndicationFlag;
+  TComPic*    m_pcIlpPic;
+#endif
+#endif
+
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
-  Bool       m_interLayerPredEnabledFlag;
+  Bool        m_interLayerPredEnabledFlag;
+  Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
+  Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
+#else
+#if SVC_EXTENSION
+  Int         m_numILRRefIdx;       //< for inter-layer reference picture ser
+#endif
 #endif 
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+  Int         m_numSamplePredRefLayers;
+  Bool        m_interLayerSamplePredOnlyFlag;
+#endif
+#if POC_RESET_FLAG
+  Bool        m_bPocResetFlag;
+  Int         m_pocValueBeforeReset;
+#endif  
+  Bool        m_bDiscardableFlag;
+#endif //SVC_EXTENSION
+
 public:
   TComSlice();
@@ -1818,7 +1855,4 @@
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
   Int       getNumRpsCurrTempList();
-#if RPL_INIT_N0316_N0082
-  Int       getNumNegativeRpsCurrTempList();
-#endif
   Int       getList1IdxToList0Idx ( Int list1Idx )               { return m_list1IdxToList0Idx[list1Idx]; }
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
@@ -1831,20 +1865,4 @@
   Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
   Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
-#if RESTR_CHK
-   Bool     isRADL() {  return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_R); }
-   Bool     isRASL()   {   return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_R); }
-#endif
-
-#if POC_RESET_FLAG
-  Bool      getPocResetFlag  ()                              { return m_bPocResetFlag; }
-  Void      setPocResetFlag  (Bool b)                        { m_bPocResetFlag = b; }
-  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
-  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ; }
-#endif
-#if SH_DISCARDABLE_FLAG
-  Bool      getDiscardableFlag  ()                              { return m_bDiscardableFlag; }
-  Void      setDiscardableFlag  (Bool b)                        { m_bDiscardableFlag = b; }
-#endif
-
   Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
@@ -2008,4 +2026,7 @@
   TComPic*  getBaseColPic       (UInt refLayerIdc)                { return m_pcBaseColPic[refLayerIdc]; }
   TComPic** getBaseColPic       ()                { return &m_pcBaseColPic[0]; }
+#if MFM_ENCCONSTRAINT
+  TComPic*  getBaseColPic( TComList<TComPic*>& rcListPic );
+#endif
 
   Void      setLayerId (UInt layerId)   { m_layerId = layerId; }
@@ -2063,17 +2084,41 @@
 #endif
 
-TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
-
-#endif //SVC_EXTENSION
+  TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
+
+#if RESTR_CHK
+  Bool     isRADL() {  return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL_R); }
+  Bool     isRASL()   {   return (m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || m_eNalUnitType == NAL_UNIT_CODED_SLICE_RASL_R); }
+#endif
+
+#if POC_RESET_FLAG
+  Bool      getPocResetFlag  ()                              { return m_bPocResetFlag;       }
+  Void      setPocResetFlag  (Bool b)                        { m_bPocResetFlag = b;          }
+  Int       getPocValueBeforeReset ()                        { return m_pocValueBeforeReset; }
+  Void      setPocValueBeforeReset (Int x)                   { m_pocValueBeforeReset = x ;   }
+#endif
+  Bool      getDiscardableFlag  ()                           { return m_bDiscardableFlag;    }
+  Void      setDiscardableFlag  (Bool b)                     { m_bDiscardableFlag = b;       }
+
+#if RPL_INIT_N0316_N0082
+  Int       getNumNegativeRpsCurrTempList();
+#endif
 
 #if REPN_FORMAT_IN_VPS
   UInt getPicWidthInLumaSamples();
   UInt getPicHeightInLumaSamples();
+#if AUXILIARY_PICTURES
+  ChromaFormat getChromaFormatIdc();
+#else
   UInt getChromaFormatIdc();
+#endif
   UInt getBitDepthY();
   UInt getBitDepthC();
-  Int getQpBDOffsetY();
-  Int getQpBDOffsetC();
-#endif
+  Int  getQpBDOffsetY();
+  Int  getQpBDOffsetC();
+#endif
+
+  Void setILRPic(TComPic **pcIlpPic);
+
+#endif //SVC_EXTENSION
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
Index: /trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- /trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 494)
@@ -17,14 +17,14 @@
   {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
   {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-#endif
-  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5      
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+#endif
+  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5
 #if ARBITRARY_SPATIAL_RATIO
   { -1, 3,  -9, 47, 31, -10,  4, -1},
   { -1, 4, -11, 45, 34, -10,  4, -1},
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //       
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
 #endif
   { -1, 4, -11, 40, 40, -11,  4, -1}, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
@@ -33,6 +33,6 @@
   { -1,  4, -10, 31, 47,  -9,  3, -1},
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
 #endif
   { -1, 3,  -8, 26, 52, -11, 4, -1}, // <-> actual phase shift 2/3, used for spatial scalability x1.5
@@ -43,8 +43,8 @@
   { 0,  1,  -2,  4, 63,  -3,  1,  0}
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  //
 #endif
 };
@@ -60,13 +60,13 @@
   {CNU,CNU,CNU,CNU},//
   {CNU,CNU,CNU,CNU},//
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
-  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
-  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)
 #if ARBITRARY_SPATIAL_RATIO
   { -4, 42, 30, -4},
 #else
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
@@ -75,5 +75,5 @@
   { -4, 28, 46, -6},
 #else
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -2, 20, 52, -6},// <-> actual phase shift 2/3, used for spatial scalability x1.5
@@ -82,8 +82,8 @@
   {-2, 14, 56, -4},
 #else
-  {CNU,CNU,CNU,CNU},// 
-  {CNU,CNU,CNU,CNU},// 
-#endif
-  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+#endif
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)
   {  0,  4, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
 };
@@ -97,8 +97,16 @@
 }
 
-#if SCALED_REF_LAYER_OFFSETS
+#if O0215_PHASE_ALIGNMENT
+#if O0194_JOINT_US_BITSHIFT
+Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+#else
+Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+Void TComUpsampleFilter::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
+#else
 Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
-#else
-Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+#endif
 #endif
 {
@@ -109,5 +117,4 @@
 
   //========== Y component upsampling ===========
-#if SCALED_REF_LAYER_OFFSETS
   const Window &scalEL = window;
 
@@ -119,16 +126,5 @@
   Int heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
   Int strideEL  = pcUsPic->getStride();
-#else
-  const Window &confBL = pcBasePic->getConformanceWindow();
-  const Window &confEL = pcUsPic->getConformanceWindow();
-
-  Int widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-  Int strideBL  = pcBasePic->getStride();
-
-  Int widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-  Int heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-  Int strideEL  = pcUsPic->getStride();
-#endif
+
   Pel* piTempBufY = pcTempPic->getLumaAddr();
   Pel* piSrcBufY  = pcBasePic->getLumaAddr();
@@ -153,4 +149,9 @@
   Int scaleX = g_posScalingFactor[refLayerIdc][0];
   Int scaleY = g_posScalingFactor[refLayerIdc][1];
+
+#if O0194_JOINT_US_BITSHIFT
+  UInt currLayerId = currSlice->getLayerId();
+  UInt refLayerId  = currSlice->getVPS()->getRefLayerId( currLayerId, refLayerIdc );
+#endif
 
   if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
@@ -194,5 +195,5 @@
     Int refPos16 = 0;
     Int phase    = 0;
-    Int refPos   = 0; 
+    Int refPos   = 0;
     Int* coeff = m_chromaFilter[phase];
     for ( i = 0; i < 16; i++)
@@ -202,5 +203,5 @@
     }
 
-#if ARBITRARY_SPATIAL_RATIO 
+#if ARBITRARY_SPATIAL_RATIO
     assert ( widthEL >= widthBL );
     assert ( heightEL >= heightBL );
@@ -216,6 +217,11 @@
     Int   shiftY = 16;
 
+#if O0215_PHASE_ALIGNMENT //for Luma, if Phase 0, then both PhaseX  and PhaseY should be 0. If symmetric: both PhaseX and PhaseY should be 2
+    Int   phaseX = 2*phaseAlignFlag;
+    Int   phaseY = 2*phaseAlignFlag;
+#else
     Int   phaseX = 0;
     Int   phaseY = 0;
+#endif
 
 #if ROUNDING_OFFSET
@@ -228,5 +234,5 @@
 
     Int   deltaX     = 4 * phaseX;
-    Int   deltaY     = 4 * phaseY;  
+    Int   deltaY     = 4 * phaseY;
 
     Int shiftXM4 = shiftX - 4;
@@ -238,16 +244,18 @@
     widthBL   = pcBasePic->getWidth ();
     heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
-#if SCALED_REF_LAYER_OFFSETS
+
     Int leftStartL = scalEL.getWindowLeftOffset();
     Int rightEndL  = pcUsPic->getWidth() - scalEL.getWindowRightOffset();
     Int topStartL  = scalEL.getWindowTopOffset();
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
-#if BUGFIX_RESAMPLE
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
-#endif
-#endif
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
+    Int shift1 = g_bitDepthYLayer[refLayerId] - 8;
+#else
     Int shift1 = g_bitDepthY - 8;
+#endif
 #endif
 
@@ -255,10 +263,6 @@
     for( i = 0; i < widthEL; i++ )
     {
-#if SCALED_REF_LAYER_OFFSETS
       Int x = Clip3( leftStartL, rightEndL - 1, i );
       refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX;
-#else
-      refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
-#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -287,22 +291,18 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    Int nShift = 20 - g_bitDepthYLayer[currLayerId];
+#else
     Int nShift = US_FILTER_PREC*2 - shift1;
+#endif
 #else
     const Int nShift = US_FILTER_PREC*2;
 #endif
-    Int iOffset = 1 << (nShift - 1); 
-
-#if SCALED_REF_LAYER_OFFSETS
+    Int iOffset = 1 << (nShift - 1);
+
     for( j = 0; j < pcTempPic->getHeight(); j++ )
-#else
-    for( j = 0; j < heightEL; j++ )
-#endif
-    {
-#if SCALED_REF_LAYER_OFFSETS
+    {
       Int y = Clip3(topStartL, bottomEndL - 1, j);
       refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY;
-#else
-      refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
-#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -310,7 +310,5 @@
 
       piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
-#if SCALED_REF_LAYER_OFFSETS
-#if BUGFIX_RESAMPLE
-      Pel* piDstY0 = piDstBufY + j * strideEL;            
+      Pel* piDstY0 = piDstBufY + j * strideEL;
       piDstY = piDstY0 + leftOffset;
       piSrcY += leftOffset;
@@ -335,58 +333,7 @@
         piDstY++;
       }
-#else
-#if 1 // it should provide identical result
-      Pel* piDstY0 = piDstBufY + j * strideEL;            
-      piDstY = piDstY0 + ( leftStartL > 0 ? leftStartL : 0 );
-
-      for( i = min<Int>(rightEndL, pcTempPic->getWidth()) - max<Int>(0, leftStartL); i > 0; i-- )
-      {
-        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcY++;
-        piDstY++;
-      }
-
-      for( i = rightEndL; i < pcTempPic->getWidth(); i++ )
-      {
-        *piDstY = piDstY0[rightEndL-1];
-        piDstY++;
-      }
-
-      piDstY = piDstY0;
-      for( i = 0; i < leftStartL; i++ )
-      {
-        *piDstY = piDstY0[leftStartL];
-        piDstY++;
-      }
-#else
-      piDstY = piDstBufY + j * strideEL;
-
-      for( i = 0; i < pcTempPic->getWidth(); i++ )
-      {
-        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-
-        // Only increase the x position of reference upsample picture when within the window
-        // "-2" to ensure that pointer doesn't go beyond the boundary rightEndL-1
-        if( (i >= leftStartL) && (i <= rightEndL-2) )
-        {
-          piSrcY++;
-        }
-        piDstY++;
-      }
-#endif
-#endif
-#else
-      piDstY = piDstBufY + j * strideEL;
-
-      for( i = 0; i < widthEL; i++ )
-      {
-        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcY++;
-        piDstY++;
-      }
-#endif
-    }
-
-#if SCALED_REF_LAYER_OFFSETS
+
+    }
+
     widthBL   = pcBasePic->getWidth ();
     heightBL  = pcBasePic->getHeight();
@@ -394,11 +341,4 @@
     widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-    widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-    heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-    widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-    heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
 
     //========== UV component upsampling ===========
@@ -412,17 +352,29 @@
     strideBL  = pcBasePic->getCStride();
     strideEL  = pcUsPic->getCStride();
-#if SCALED_REF_LAYER_OFFSETS
+
     Int leftStartC = scalEL.getWindowLeftOffset() >> 1;
     Int rightEndC  = (pcUsPic->getWidth() >> 1) - (scalEL.getWindowRightOffset() >> 1);
     Int topStartC  = scalEL.getWindowTopOffset() >> 1;
     Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
-#if BUGFIX_RESAMPLE
     leftOffset = leftStartC > 0 ? leftStartC : 0;
-#endif
-#endif
 
     shiftX = 16;
     shiftY = 16;
 
+#if O0215_PHASE_ALIGNMENT
+    Int phaseXC = 0;
+    Int phaseYC = 1;
+
+#if ROUNDING_OFFSET
+    addX       = ( ( (phaseXC+phaseAlignFlag) * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( (phaseYC+phaseAlignFlag) * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
+#else
+    addX       = ( ( ( widthBL * (phaseXC+phaseAlignFlag) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( ( heightBL * (phaseYC+phaseAlignFlag) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+#endif
+
+    deltaX     = 4 * (phaseXC+phaseAlignFlag);
+    deltaY     = 4 * (phaseYC+phaseAlignFlag);
+#else
     phaseX = 0;
     phaseY = 1;
@@ -438,4 +390,5 @@
     deltaX     = 4 * phaseX;
     deltaY     = 4 * phaseY;
+#endif
 
     shiftXM4 = shiftX - 4;
@@ -449,5 +402,10 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
+    shift1 = g_bitDepthCLayer[refLayerId] - 8;
+#else
     shift1 = g_bitDepthC - 8;
+#endif
 #endif
 
@@ -455,10 +413,6 @@
     for( i = 0; i < widthEL; i++ )
     {
-#if SCALED_REF_LAYER_OFFSETS
       Int x = Clip3(leftStartC, rightEndC - 1, i);
       refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX;
-#else
-      refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
-#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -494,28 +448,23 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    nShift = 20 - g_bitDepthCLayer[refLayerId];
+#else
     nShift = US_FILTER_PREC*2 - shift1;
-    iOffset = 1 << (nShift - 1); 
-#endif
-
-#if SCALED_REF_LAYER_OFFSETS
+#endif
+    iOffset = 1 << (nShift - 1);
+#endif
+
     for( j = 0; j < pcTempPic->getHeight() >> 1; j++ )
-#else
-    for( j = 0; j < heightEL; j++ )
-#endif
-    {
-#if SCALED_REF_LAYER_OFFSETS
+    {
       Int y = Clip3(topStartC, bottomEndC - 1, j);
       refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY;
-#else
-      refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
-#endif
       phase    = refPos16 & 15;
-      refPos   = refPos16 >> 4; 
+      refPos   = refPos16 >> 4;
       coeff = m_chromaFilter[phase];
-      
+
       piSrcU = piTempBufU  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
       piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
-#if SCALED_REF_LAYER_OFFSETS
-#if BUGFIX_RESAMPLE
+
       Pel* piDstU0 = piDstBufU + j*strideEL;
       Pel* piDstV0 = piDstBufV + j*strideEL;
@@ -552,74 +501,5 @@
         piDstV++;
       }
-#else
-#if 1 // it should provide identical result
-      Pel* piDstU0 = piDstBufU + j*strideEL;
-      Pel* piDstV0 = piDstBufV + j*strideEL;
-      piDstU = piDstU0 + ( leftStartC > 0 ? leftStartC : 0 );
-      piDstV = piDstV0 + ( leftStartC > 0 ? leftStartC : 0 );
-
-      for( i = min<Int>(rightEndC, pcTempPic->getWidth() >> 1) - max<Int>(0, leftStartC); i > 0; i-- )
-      {
-        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcU++;
-        piSrcV++;
-        piDstU++;
-        piDstV++;
-      }
-
-      for( i = rightEndC; i < pcTempPic->getWidth() >> 1; i++ )
-      {
-        *piDstU = piDstU0[rightEndC-1];
-        *piDstV = piDstV0[rightEndC-1];
-        piDstU++;
-        piDstV++;
-      }
-
-      piDstU = piDstU0;
-      piDstV = piDstV0;
-      for( i = 0; i < leftStartC; i++ )
-      {
-        *piDstU = piDstU0[leftStartC];
-        *piDstV = piDstV0[leftStartC];
-        piDstU++;
-        piDstV++;
-      }
-#else
-      piDstU = piDstBufU + j*strideEL;
-      piDstV = piDstBufV + j*strideEL;
-
-      for( i = 0; i < pcTempPic->getWidth() >> 1; i++ )
-      {
-        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-
-        // Only increase the x position of reference upsample picture when within the window
-        // "-2" to ensure that pointer doesn't go beyond the boundary rightEndC-1
-        if( (i >= leftStartC) && (i <= rightEndC-2) )
-        {
-          piSrcU++;
-          piSrcV++;
-        }
-
-        piDstU++;
-        piDstV++;
-      }
-#endif
-#endif
-#else
-      piDstU = piDstBufU + j*strideEL;
-      piDstV = piDstBufV + j*strideEL;
-
-      for( i = 0; i < widthEL; i++ )
-      {
-        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-        piSrcU++;
-        piSrcV++;
-        piDstU++;
-        piDstV++;
-      }
-#endif
+
     }
   }
Index: /trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 494)
@@ -43,9 +43,18 @@
   ~TComUpsampleFilter(void);
 
-#if SCALED_REF_LAYER_OFFSETS
+#if O0215_PHASE_ALIGNMENT
+#if O0194_JOINT_US_BITSHIFT
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+#else
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#else
   Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
-#else
- Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
+#endif
+
 };
 
Index: /trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 493)
+++ /trunk/source/Lib/TLibCommon/TypeDef.h	(revision 494)
@@ -45,6 +45,13 @@
 #define RANDOM_ACCESS_SEI_FIX            1
 #if SVC_EXTENSION
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
+#define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters (and Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled)
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+#define O0194_JOINT_US_BITSHIFT          1      ///< JCTVC-O0194: Joint Upsampling and bit-shift
+#endif
+#define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
+#define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
 #define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
-#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
 #define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
 #define ALIGN_TSA_STSA_PICS              1      ///< JCTVC-N0084: Alignment of TSA and STSA pictures across AU.
@@ -52,18 +59,16 @@
 #define TIMING_INFO_NONZERO_LAYERID_SPS  1      ///< JCTVC-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      ///< JCTVC-N0316, JCTVC-N0082: initial reference picture list construction 
-#define FINAL_RPL_CHANGE_N0082           1      ///< JCTVC-N0082: final ref picture list change (encoder)
-#if FINAL_RPL_CHANGE_N0082
-#define EXTERNAL_USEDBYCURR_N0082        1      ///< JCTVC-N0082: final ref picture list change (encoder) //dev ver.
-#define TEMP_SCALABILITY_FIX             1      ///< fix for temporal scalability
-#endif
+
 #define IL_SL_SIGNALLING_N0371           0      ///< JCTVC-N0371: inter-layer scaling list
-#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< JCTVC-M0464: VUI flag to indicate tile boundary alignment
 #define M0463_VUI_EXT_ILP_REF            0      ///< JCTVC-M0463: VUI extension inter-layer dependency offset signalling
 #define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
-#define SCALED_REF_LAYER_OFFSETS         1      ///< JCTVC-M0309: Signal scaled reference layer offsets in SPS
 #define VERT_MV_CONSTRAINT               1      ///< Vertical MV component constraint flag
 #define SCALABILITY_MASK_E0104           1      ///< JCT3V-E0104: scalability mask for depth
+#define LAYER_CTB                        0      ///< enable layer-specific CTB structure
 
 #define ILP_SSH_SIG                      1      ///< JCTVC-N0195 proposal 2, JCTVC-N0118: add presence flag in VPS ext to condition inter-layer prediction signaling in slice segment header
+#if ILP_SSH_SIG
+#define ILP_SSH_SIG_FIX                  1      ///< fix for SHM ticket #5
+#endif 
 #define SPL_FLG_CHK                      1      ///< JCTVC-N0195 proposal 5, JCTVC-N0085: constrain sum of lengths to be less than or equal to 6
 #define ILP_NUM_REF_CHK                  1      ///< JCTVC-N0195 proposal 1, JCTVC-N0081, JCTVC-N0154, JCTVC-N0217: a condition on signaling inter_layer_pred_layer_idc[ i ], to avoid sending when NumDirectRefLayers equals NumActiveRefLayerPics, and instead infer values
@@ -76,9 +81,4 @@
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
-#define VPS_OUTPUT_LAYER_SET_IDX         1      ///< JCTVC-M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
-#define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< JCTVC-M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
-#define VPS_PROFILE_OUTPUT_LAYERS        1      ///< JCTVC-M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
-#define SPS_SUB_LAYER_INFO               1      ///< JCTVC-M0268: Do not signal sps_max_sub_layers_minus1 and sps_temporal_id_nesting_flag for nuh_layer_id greater than 0
-#define VPS_SPLIT_FLAG                   1      ///< JCTVC-M0163: Do not signal dimension_id and the last dimension_id_len_minus1, when splitting_flag is equal to 1. 
 #define M0457_PREDICTION_INDICATIONS     1
 #define M0040_ADAPTIVE_RESOLUTION_CHANGE 1
@@ -89,6 +89,4 @@
 #define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
 #define VPS_VUI_BITRATE_PICRATE          1      ///< JCTVC-N0085: Signal bit rate and picture in VPS VUI
-#else
-#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< VUI flag to indicate tile boundary alignment
 #endif //VPS_VUI
 
@@ -96,6 +94,6 @@
 
 #define VPS_EXTN_OFFSET                  1      ///< implementation of vps_extension_offset syntax element
+#define VPS_EXTN_OFFSET_CALC             1      ///< Calculation of VPS extension offset
 #define SPS_PTL_FIX                      1      ///< remove profile_tier_level from enhancement layer SPS
-#define SH_DISCARDABLE_FLAG              1      ///< JCTVC-M0152: Use one reserved flag in the slice header for discardable flag
 
 #define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
@@ -104,6 +102,5 @@
 #define ROUNDING_OFFSET                  1      ///< JCTVC-N0111: upsampling rounding offset using scalling factors
 #define N0214_INTERMEDIATE_BUFFER_16BITS 1      ///< JCTVC-N0214: support base layer input more than 8 bits
-#define ARBITRARY_SPATIAL_RATIO          0      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
-#define BUGFIX_RESAMPLE                  1      ///< JCTVC-N0055: resampling bug fix for positive left scalled offset
+#define ARBITRARY_SPATIAL_RATIO          1      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
 
 #define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
@@ -126,9 +123,8 @@
 #define JCTVC_M0203_INTERLAYER_PRED_IDC  1      ///< JCTVC-M0203: implementation of Inter-layer Prediction Indication
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
-#define ILR_RESTR                        1      ///< JCTVC-M0209: Inter-layer RPS and RPL
-#define ILR_RESTR_FIX                    1      ///< Fix encoder crash when temporal layers are used with scalable coding
 #define EARLY_REF_PIC_MARKING            1      ///< Decoded picture marking of sub-layer non-reference pictures
 #define N0120_MAX_TID_REF_PRESENT_FLAG   1      ///< JCTVC-N0120: max_tid_ref_pics_plus1_present_flag
 #define N0120_MAX_TID_REF_CFG            1      ///< set max_tid_il_ref_pics_plus1 and max_tid_ref_present_flag in the config. file (configuration setting)
+#define O0225_MAX_TID_FOR_REF_LAYERS     1
 #endif
 #if REF_IDX_MFM
@@ -145,4 +141,8 @@
 
 #define N0147_IRAP_ALIGN_FLAG            1      ///< a flag to indicatate whether IRAPs are aligned across layers
+#if N0147_IRAP_ALIGN_FLAG
+#define O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS  1  ///< Remove IRAP align depedency constraints on poc_Reset_flag.
+#define IRAP_ALIGN_FLAG_IN_VPS_VUI       1       ///< Move IRAP align flag to VPS VUI 
+#endif 
 #if !N0147_IRAP_ALIGN_FLAG
 #define IDR_ALIGNMENT                    1      ///< align IDR picures across layers : As per JCTVC-N0373, IDR are not required to be aligned.
@@ -159,4 +159,11 @@
 #define N0383_IL_CONSTRAINED_TILE_SETS_SEI  1
 #define N0065_LAYER_POC_ALIGNMENT        1
+
+#define O0215_PHASE_ALIGNMENT            1      ///< JCTVC_O0215: signal a flag to specify phase alignment case, 0: zero-position-aligned, 1: central-position-aligned,
+#define AUXILIARY_PICTURES               1      ///< JCTVC-O0041: auxiliary picture layers
+
+#define O0062_POC_LSB_NOT_PRESENT_FLAG   1      ///< JCTVC-O0062: signal poc_lsb_not_present_flag for each layer in VPS extension
+#define SHM_FIX7                         1      ///< fix for SHVC WD ticket #7
+
 #else
 #define SYNTAX_OUTPUT                    0
@@ -469,4 +476,7 @@
   CHROMA_422  = 2,
   CHROMA_444  = 3
+#if AUXILIARY_PICTURES
+  ,NUM_CHROMA_FORMAT = 4
+#endif
 };
 
Index: /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 494)
@@ -187,9 +187,9 @@
   assert(uiCode <= 63);
   pcPPS->setPPSId (uiCode);
-  
+
   READ_UVLC( uiCode, "pps_seq_parameter_set_id");
   assert(uiCode <= 15);
   pcPPS->setSPSId (uiCode);
-  
+
   READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
   READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
@@ -293,5 +293,5 @@
 
 #if IL_SL_SIGNALLING_N0371
-  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );  
+  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );
 #endif
 
@@ -301,9 +301,9 @@
     pcPPS->getScalingList()->setLayerId( pcPPS->getLayerId() );
 
-    if( pcPPS->getLayerId() > 0 ) 
+    if( pcPPS->getLayerId() > 0 )
     {
       READ_FLAG( uiCode, "pps_pred_scaling_list_flag" );           pcPPS->setPredScalingListFlag( uiCode ? true : false );
       pcPPS->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
-      
+
       if( pcPPS->getPredScalingListFlag() )
       {
@@ -319,9 +319,9 @@
         }
 
-        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
         // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
         assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
 
-        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
         // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
         assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
@@ -450,10 +450,4 @@
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-    if ( pcSPS->getLayerId() > 0 )
-    {
-      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
-    }
-#endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
     READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
@@ -542,5 +536,5 @@
 }
 
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
 Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
 #else
@@ -554,5 +548,5 @@
   UInt  uiCode;
   READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   if(pcSPS->getLayerId() == 0)
   {
@@ -560,7 +554,7 @@
     READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     assert(uiCode <= 6);
-  
+
     READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   }
   else
@@ -569,13 +563,13 @@
     pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
   }
-#endif 
 #if IL_SL_SIGNALLING_N0371
   pcSPS->setVPS( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId()) );
   pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
 #endif
+#endif
   if ( pcSPS->getMaxTLayers() == 1 )
   {
     // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
     assert( pcSPS->getTemporalIdNestingFlag() == true );
 #else
@@ -598,5 +592,5 @@
   if( pcSPS->getLayerId() > 0 )
   {
-    READ_FLAG( uiCode, "update_rep_format_flag" );                 
+    READ_FLAG( uiCode, "update_rep_format_flag" );
     pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
   }
@@ -605,8 +599,12 @@
     pcSPS->setUpdateRepFormatFlag( true );
   }
-  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
-  {
-#endif
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
+  {
+#endif
+#if AUXILIARY_PICTURES
+    READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( ChromaFormat(uiCode) );
+#else
     READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
+#endif
     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
@@ -639,5 +637,5 @@
   }
 #if REPN_FORMAT_IN_VPS
-  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
   {
 #endif
@@ -659,5 +657,5 @@
   UInt subLayerOrderingInfoPresentFlag;
   READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
-  
+
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
@@ -728,9 +726,9 @@
           }
 
-          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
           // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
           assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
 
-          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
           // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
           assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
@@ -841,8 +839,7 @@
   assert( uiCode == 0 );
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   if( pcSPS->getLayerId() > 0 )
   {
-    Int iCode; 
+    Int iCode;
     READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
     for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
@@ -855,23 +852,22 @@
     }
   }
-#endif
 #if M0463_VUI_EXT_ILP_REF
   ////   sps_extension_vui_parameters( )
   if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
-  {  
-    READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode ); 
-    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
-    {  
-      READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode ); 
-      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
-      {  
-        READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 ); 
-        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
-        {
-          READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode ); 
-        }
-      }  
-    }  
-  }  
+  {
+    READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode );
+    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ )
+    {
+      READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode );
+      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 )
+      {
+        READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 );
+        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )
+        {
+          READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode );
+        }
+      }
+    }
+  }
   ////   sps_extension_vui_parameters( ) END
 #endif
@@ -1000,4 +996,5 @@
 }
 
+#if SVC_EXTENSION
 #if VPS_EXTNS
 Void TDecCavlc::parseVPSExtension(TComVPS *vps)
@@ -1018,13 +1015,9 @@
   vps->setNumScalabilityTypes(numScalabilityTypes);
 
-#if VPS_SPLIT_FLAG
   for(j = 0; j < numScalabilityTypes - vps->getSplittingFlag(); j++)
-#else
-  for(j = 0; j < numScalabilityTypes; j++)
-#endif
   {
     READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
   }
-#if VPS_SPLIT_FLAG
+
   if(vps->getSplittingFlag())
   {
@@ -1038,15 +1031,4 @@
     numBits = 6;
   }
-#else
-  if(vps->getSplittingFlag())
-  {
-    UInt numBits = 0;
-    for(j = 0; j < numScalabilityTypes; j++)
-    {
-      numBits += vps->getDimensionIdLen(j);
-    }
-    assert( numBits <= 6 );
-  }
-#endif
 
   READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
@@ -1066,17 +1048,19 @@
     vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
 
-#if VPS_SPLIT_FLAG
-    if(!vps->getSplittingFlag())
-#endif
+    if( !vps->getSplittingFlag() )
+    {
     for(j = 0; j < numScalabilityTypes; j++)
     {
       READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
+#if !AUXILIARY_PICTURES
       assert( uiCode <= vps->getMaxLayerId() );
-    }
-  }
-#endif
-#if VIEW_ID_RELATED_SIGNALING 
-  // if ( pcVPS->getNumViews() > 1 )  
-  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
+#endif
+    }
+  }
+  }
+#endif
+#if VIEW_ID_RELATED_SIGNALING
+  // if ( pcVPS->getNumViews() > 1 )
+  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
   {
     READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
@@ -1088,5 +1072,4 @@
   }
 #endif
-#if VPS_MOVE_DIR_DEPENDENCY_FLAG
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // For layer 0
@@ -1108,5 +1091,4 @@
   }
 #endif
-#endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -1116,17 +1098,35 @@
     for(i = 0; i < vps->getMaxLayers() - 1; i++)
     {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+       {
+         if(vps->getDirectDependencyFlag(j, i))
+         {
+           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
+           assert( uiCode <= vps->getMaxTLayers());
+         }
+       }
+#else
       READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
 #if N0120_MAX_TID_REF_CFG
       assert( uiCode <= vps->getMaxTLayers());
-#else 
+#else
       assert( uiCode <= vps->getMaxTLayers()+ 1 );
+#endif
 #endif 
     }
   }
-  else 
+  else
   {
     for(i = 0; i < vps->getMaxLayers() - 1; i++)
     {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+       {
+          vps->setMaxTidIlRefPicsPlus1(i, j, 7);
+       }
+#else
       vps->setMaxTidIlRefPicsPlus1(i, 7);
+#endif
     }
   }
@@ -1134,6 +1134,17 @@
   for(i = 0; i < vps->getMaxLayers() - 1; i++)
   {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+       {
+         if(vps->getDirectDependencyFlag(j, i))
+         {
+           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
+           assert( uiCode <= vps->getMaxTLayers() );
+         }
+       }
+#else
     READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
     assert( uiCode <= vps->getMaxTLayers() );
+#endif   
   }
 #endif
@@ -1144,23 +1155,15 @@
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
-#if VPS_PROFILE_OUTPUT_LAYERS
   READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1" );     assert( uiCode == (vps->getNumLayerSets() - 1) );
   READ_CODE(  6, uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
   vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
-#else
-  vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
-  for(Int idx = 1; idx <= vps->getNumLayerSets() - 1; idx++)
-#endif
   {
     READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
     if( !vps->getProfilePresentFlag(idx) )
     {
-#if VPS_PROFILE_OUTPUT_LAYERS
       READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
-#else
-      READ_UVLC( uiCode, "vps_profile_layer_set_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
-#endif
       assert( vps->getProfileLayerSetRef(idx) < idx );
+
       // Copy profile information as indicated
       vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
@@ -1170,5 +1173,4 @@
 #endif
 
-#if VPS_PROFILE_OUTPUT_LAYERS
   READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
   Int numOutputLayerSets = 0;
@@ -1231,28 +1233,7 @@
     READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
   }
-#else
-#if VPS_EXTN_OP_LAYER_SETS
-  // Target output layer signalling
-  READ_UVLC( uiCode,            "vps_num_output_layer_sets"); vps->setNumOutputLayerSets(uiCode);
-  for(i = 0; i < vps->getNumOutputLayerSets(); i++)
-  {
-#if VPS_OUTPUT_LAYER_SET_IDX
-    READ_UVLC( uiCode,           "vps_output_layer_set_idx_minus1[i]"); vps->setOutputLayerSetIdx(i, uiCode + 1);
-#else
-    READ_UVLC( uiCode,           "vps_output_layer_set_idx[i]"); vps->setOutputLayerSetIdx(i, uiCode);
-#endif
-    Int lsIdx = vps->getOutputLayerSetIdx(i);
-    for(j = 0; j <= vps->getMaxLayerId(); j++)
-    {
-      if(vps->getLayerIdIncludedFlag(lsIdx, j))
-      {
-        READ_FLAG( uiCode, "vps_output_layer_flag[lsIdx][j]"); vps->setOutputLayerFlag(lsIdx, j, uiCode);
-      }
-    }
-  }
-#endif
-#endif
+
 #if REPN_FORMAT_IN_VPS
-  READ_FLAG( uiCode, "rep_format_idx_present_flag"); 
+  READ_FLAG( uiCode, "rep_format_idx_present_flag");
   vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
 
@@ -1273,5 +1254,5 @@
     parseRepFormat( vps->getVpsRepFormat(i) );
   }
-  
+
   // Default assignment for layer 0
   vps->setVpsRepFormatIdx( 0, 0 );
@@ -1305,31 +1286,23 @@
   vps->setMaxOneActiveRefLayerFlag(uiCode);
 #endif
-
-#if N0147_IRAP_ALIGN_FLAG
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  for(i = 1; i< vps->getMaxLayers(); i++)
+  {
+    if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
+    {
+      READ_FLAG(uiCode, "poc_lsb_not_present_flag[i]");
+      vps->setPocLsbNotPresentFlag(i, uiCode);
+    }
+  }
+#endif
+#if O0215_PHASE_ALIGNMENT
+  READ_FLAG( uiCode, "cross_layer_phase_alignment_flag"); vps->setPhaseAlignFlag( uiCode == 1 ? true : false );
+#endif
+
+#if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI
   READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
   vps->setCrossLayerIrapAlignFlag(uiCode);
-#endif 
-
-#if !VPS_MOVE_DIR_DEPENDENCY_FLAG
-#if VPS_EXTN_DIRECT_REF_LAYERS
-  // For layer 0
-  vps->setNumDirectRefLayers(0, 0);
-  // For other layers
-  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-  {
-    UInt numDirectRefLayers = 0;
-    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
-    {
-      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
-      if(uiCode)
-      {
-        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
-        numDirectRefLayers++;
-      }
-    }
-    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
-  }
-#endif
-#endif
+#endif
+
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
   READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
@@ -1351,5 +1324,5 @@
     {
       for(j = 0; j < i; j++)
-        {      
+        {
           vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
         }
@@ -1370,5 +1343,5 @@
     }
     parseVPSVUI(vps);
-#endif 
+#endif
   }
 }
@@ -1378,5 +1351,9 @@
 {
   UInt uiCode;
+#if AUXILIARY_PICTURES
+  READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( ChromaFormat(uiCode) );
+#else
   READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
+#endif
   
   if( repFormat->getChromaFormatVpsIdc() == 3 )
@@ -1387,5 +1364,5 @@
   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 );
@@ -1398,4 +1375,8 @@
   UInt i,j;
   UInt uiCode;
+#if IRAP_ALIGN_FLAG_IN_VPS_VUI
+  READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
+  vps->setCrossLayerIrapAlignFlag(uiCode);
+#endif
 #if VPS_VUI_BITRATE_PICRATE
   READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
@@ -1453,10 +1434,10 @@
     for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     {
-      READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));      
-    }
-  }  
-#endif 
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
+    }
+  }
+#endif
 #if N0160_VUI_EXT_ILP_REF
-    READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 ); 
+    READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 );
   if( vps->getNumIlpRestrictedRefLayers())
   {
@@ -1465,19 +1446,21 @@
       for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
       {
-        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode ); 
-        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) 
-        {  
-          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 ); 
-          if(vps->getCtuBasedOffsetEnabledFlag(i,j))  
+        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
+        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 )
+        {
+          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 );
+          if(vps->getCtuBasedOffsetEnabledFlag(i,j))
           {
-            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode ); 
+            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode );
           }
-        }  
-      }  
-    }
-  }
-#endif 
-}
-#endif 
+        }
+      }
+    }
+  }
+#endif
+}
+#endif
+#endif //SVC_EXTENSION
+
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
 {
@@ -1552,6 +1535,7 @@
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
+#if SVC_EXTENSION
 #if POC_RESET_FLAG
-    Int iBits = 0; 
+    Int iBits = 0;
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     {
@@ -1569,5 +1553,4 @@
     }
 #else
-#if SH_DISCARDABLE_FLAG
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     {
@@ -1578,11 +1561,11 @@
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
-#else
+#endif
+#else //SVC_EXTENSION
     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     {
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
-#endif
-#endif
+#endif //SVC_EXTENSION
 
     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
@@ -1611,5 +1594,12 @@
     }
 #if N0065_LAYER_POC_ALIGNMENT
+#if SHM_FIX7
+    Int iPOClsb = 0;
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+    if( ( rpcSlice->getLayerId() > 0 && !rpcSlice->getVPS()->getPocLsbNotPresentFlag( rpcSlice->getVPS()->getLayerIdInVps(rpcSlice->getLayerId())) ) || !rpcSlice->getIdrPicFlag())
+#else
     if( rpcSlice->getLayerId() > 0 || !rpcSlice->getIdrPicFlag() )
+#endif
 #else
     else
@@ -1617,5 +1607,9 @@
     {
       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
+#if SHM_FIX7
+      iPOClsb = uiCode;
+#else
       Int iPOClsb = uiCode;
+#endif
       Int iPrevPOC = rpcSlice->getPrevTid0POC();
       Int iMaxPOClsb = 1<< sps->getBitsForPOC();
@@ -1645,4 +1639,7 @@
 
 #if N0065_LAYER_POC_ALIGNMENT
+#if SHM_FIX7
+      }
+#endif
       if( !rpcSlice->getIdrPicFlag() )
       {
@@ -1737,4 +1734,5 @@
             Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
                                         - iPOClsb + pocLsbLt;
+
             rps->setPOC     (j, pocLTCurr);
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
@@ -1746,5 +1744,5 @@
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
             rps->setCheckLTMSBPresent(j,false);
-            
+
             // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
             if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
@@ -1779,5 +1777,5 @@
         rpcSlice->setEnableTMVPFlag(false);
       }
-#if N0065_LAYER_POC_ALIGNMENT
+#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
     }
 #endif
@@ -1788,5 +1786,9 @@
     rpcSlice->setActiveNumILRRefIdx(0);
 #if ILP_SSH_SIG
+#if ILP_SSH_SIG_FIX
+    if((sps->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
+#else
     if((sps->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
+#endif
 #else
     if((sps->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
@@ -1841,5 +1843,9 @@
     }
 #if ILP_SSH_SIG
+#if ILP_SSH_SIG_FIX
+    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true )
+#else
     else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
+#endif
     {
       rpcSlice->setInterLayerPredEnabledFlag(true);
@@ -1870,5 +1876,29 @@
     {
       READ_FLAG(uiCode, "slice_sao_luma_flag");  rpcSlice->setSaoEnabledFlag((Bool)uiCode);
+#if AUXILIARY_PICTURES
+      ChromaFormat format;
+#if REPN_FORMAT_IN_VPS
+      if( ( sps->getLayerId() == 0 ) || sps->getUpdateRepFormatFlag() )
+      {
+        format = sps->getChromaFormatIdc();
+      }
+      else
+      {
+        format = rpcSlice->getVPS()->getVpsRepFormat( rpcSlice->getVPS()->getVpsRepFormatIdx(sps->getLayerId()) )->getChromaFormatVpsIdc();
+      }
+#else
+      format = sps->getChromaFormatIdc();
+#endif
+      if (format != CHROMA_400)
+      {
+#endif
       READ_FLAG(uiCode, "slice_sao_chroma_flag");  rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode);
+#if AUXILIARY_PICTURES
+      }
+      else
+      {
+        rpcSlice->setSaoEnabledFlagChroma(false);
+      }
+#endif
     }
 
@@ -2069,4 +2099,8 @@
 
 #if REPN_FORMAT_IN_VPS
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+    g_bitDepthYLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthY();
+    g_bitDepthCLayer[rpcSlice->getLayerId()] = rpcSlice->getBitDepthC();
+#endif
     assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
 #else
@@ -2179,5 +2213,5 @@
   {
     Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
-    
+
     // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
     for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
@@ -2465,8 +2499,18 @@
   SliceType       eSliceType  = pcSlice->getSliceType();
   Int             iNbRef       = (eSliceType == B_SLICE ) ? (2) : (1);
+#if SVC_EXTENSION
+  UInt            uiLog2WeightDenomLuma = 0, uiLog2WeightDenomChroma = 0;
+#else
   UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
+#endif
   UInt            uiTotalSignalledWeightFlags = 0;
 
   Int iDeltaDenom;
+#if AUXILIARY_PICTURES
+  if (pcSlice->getChromaFormatIdc() == CHROMA_400)
+  {
+    bChroma = false;
+  }
+#endif
   // decode delta_luma_log2_weight_denom :
   READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
@@ -2488,6 +2532,18 @@
 
       wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma;
+#if AUXILIARY_PICTURES
+      if (!bChroma)
+      {
+        wp[1].uiLog2WeightDenom = 0;
+        wp[2].uiLog2WeightDenom = 0;
+      }
+      else
+      {
+#endif
       wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma;
       wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma;
+#if AUXILIARY_PICTURES
+      }
+#endif
 
       UInt  uiCode;
@@ -2585,5 +2641,5 @@
 #if IL_SL_SIGNALLING_N0371
       if ( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
-      { 
+      {
         READ_FLAG( code, "scaling_list_pred_mode_flag");
         scalingListPredModeFlag = (code) ? true : false;
Index: /trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 494)
@@ -72,4 +72,5 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
+#if SPS_EXTENSION
 #if VPS_EXTNS
   Void  parseVPSExtension   ( TComVPS* pcVPS );
@@ -82,12 +83,9 @@
   Void  parseRepFormat      ( RepFormat *repFormat );
 #endif
-#if SPS_SUB_LAYER_INFO
   Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager );
-#else
+  Void  parseSPSExtension    ( TComSPS* pcSPS );
+#else //SVC_EXTENSION
   Void  parseSPS            ( TComSPS* pcSPS );
-#endif
-#if SPS_EXTENSION
-  Void parseSPSExtension    ( TComSPS* pcSPS );
-#endif
+#endif //SVC_EXTENSION
   Void  parsePPS            ( TComPPS* pcPPS);
   Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
Index: /trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 494)
@@ -616,5 +616,14 @@
     curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
   }
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // Bug-fix
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
+#else
   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
+#else
+  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
 
   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
@@ -768,5 +777,14 @@
   // Cb and Cr
   Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // Bug-fix
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
+#else
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
+#else
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
 
   uiWidth  >>= 1;
@@ -776,5 +794,14 @@
 
   curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+  // Bug-fix
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
+#else
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
+#else
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
 
   piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
Index: /trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 494)
@@ -66,5 +66,5 @@
 
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   virtual Void  parseSPS                  ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )           = 0;
 #else
@@ -134,5 +134,5 @@
   Void    resetEntropy                ( TComSlice* p)           { m_pcEntropyDecoderIf->resetEntropy(p);                    }
   Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   Void    decodeSPS                   ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )    { m_pcEntropyDecoderIf->parseSPS(pcSPS, parameterSetManager);                    }
 #else
Index: /trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 494)
@@ -356,4 +356,8 @@
     uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
+#if AUXILIARY_PICTURES
+    ChromaFormat format = pcCU->getSlice()->getChromaFormatIdc();
+    UInt uiGrayVal = 1 << (uiSampleBits - 1);
+#endif
 
     for(uiY = 0; uiY < uiHeight; uiY++)
@@ -362,4 +366,9 @@
       {
         UInt uiSample;
+#if AUXILIARY_PICTURES
+        if (format == CHROMA_400)
+          uiSample = uiGrayVal;
+        else
+#endif
         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
         piPCMSample[uiX] = uiSample;
@@ -378,4 +387,9 @@
       {
         UInt uiSample;
+#if AUXILIARY_PICTURES
+        if (format == CHROMA_400)
+          uiSample = uiGrayVal;
+        else
+#endif
         m_pcTDecBinIf->xReadPCMCode(uiSampleBits, uiSample);
         piPCMSample[uiX] = uiSample;
@@ -665,4 +679,12 @@
   UInt uiSymbol;
 
+#if AUXILIARY_PICTURES
+  if ( pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 )
+  {
+    uiSymbol = DC_IDX;
+  }
+  else
+  {
+#endif
   m_pcTDecBinIf->decodeBin( uiSymbol, m_cCUChromaPredSCModel.get( 0, 0, 0 ) );
 
@@ -681,4 +703,7 @@
     }
   }
+#if AUXILIARY_PICTURES
+  }
+#endif
   pcCU->setChromIntraDirSubParts( uiSymbol, uiAbsPartIdx, uiDepth );
   return;
@@ -885,5 +910,16 @@
   UInt uiSymbol;
   const UInt uiCtx = pcCU->getCtxQtCbf( eType, uiTrDepth );
+#if AUXILIARY_PICTURES
+  if (pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 && (eType == TEXT_CHROMA_U || eType == TEXT_CHROMA_V))
+  {
+    uiSymbol = 0;
+  }
+  else
+  {
+#endif
   m_pcTDecBinIf->decodeBin( uiSymbol , m_cCUQtCbfSCModel.get( 0, eType ? TEXT_CHROMA: eType, uiCtx ) );
+#if AUXILIARY_PICTURES
+  }
+#endif
   
   DTRACE_CABAC_VL( g_nSymbolCounter++ )
Index: /trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 494)
@@ -76,5 +76,5 @@
   Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
   Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   Void  parseSPS                  ( TComSPS* /*pcSPS*/, ParameterSetManagerDecoder * /*parameterSetManager*/ ) {}
 #else
Index: /trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 494)
@@ -179,4 +179,19 @@
 
         m_cIlpPic[j] = new  TComPic;
+#if AUXILIARY_PICTURES
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
+#else
+        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+#else
 #if REPN_FORMAT_IN_VPS
 #if SVC_UPSAMPLING
@@ -190,4 +205,5 @@
 #else
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
 #endif
@@ -196,27 +212,4 @@
           m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
         }
-      }
-    }
-  }
-}
-
-
-
-Void TDecTop::setILRPic(TComPic *pcPic)
-{
-  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
-  {
-    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
-
-    if(m_cIlpPic[refLayerIdc])
-    {
-      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
-      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
-      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
-      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
-      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
-      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)  // set reference CU layerId
-      {
-        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
       }
     }
@@ -310,18 +303,27 @@
 #endif
         }
-#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
-#if SCALABILITY_MASK_E0104
-        if(pcSlice->getVPS()->getScalabilityMask(2))
-#else
-        if(pcSlice->getVPS()->getScalabilityMask(1))
-#endif
-        {
-          pcSlice->setPic(rpcPic);
-        }
-#endif
       }
     }
 #endif
     
+#if AUXILIARY_PICTURES
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+#else
+    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+#else
 #if REPN_FORMAT_IN_VPS
 #if SVC_UPSAMPLING
@@ -341,4 +343,5 @@
 #endif
 #endif
+#endif
 
     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
@@ -381,4 +384,25 @@
   rpcPic->destroy();
 
+#if AUXILIARY_PICTURES
+#if REPN_FORMAT_IN_VPS
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
+
+#else
+  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+#else
 #if REPN_FORMAT_IN_VPS
 #if SVC_UPSAMPLING
@@ -398,4 +422,5 @@
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
 #endif
 #endif
@@ -473,8 +498,16 @@
 
   Int remainingInterLayerReferencesFlag = 0;
+#if O0225_MAX_TID_FOR_REF_LAYERS
+  for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
+  {
+    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
+    if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
+    {
+#else
   if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
   {
     for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
     {
+#endif 
       for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
       {
@@ -684,4 +717,5 @@
 
 #if SVC_EXTENSION
+  m_apcSlicePilot->setSliceIdx( m_uiSliceIdx ); // it should be removed if HM will reflect it in above
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
   setRefLayerParams(m_apcSlicePilot->getVPS());
@@ -754,5 +788,6 @@
   // actual decoding starts here
   xActivateParameterSets();
-#if 0 // N0147_IRAP_ALIGN_FLAG Disabled for now!
+#if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS
+  //Note setting O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS to 0 may cause decoder to crash.
   //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1 
   if(!m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
@@ -1098,4 +1133,5 @@
   pcPic->setLayerId(nalu.m_layerId);
   pcSlice->setLayerId(nalu.m_layerId);
+  pcSlice->setPic(pcPic);
 #endif
 
@@ -1113,6 +1149,90 @@
 #endif
 
-#if SVC_EXTENSION   
-    if(m_layerId > 0)
+#if SVC_EXTENSION
+    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice. 
+    // Other slices might choose which reference pictures to be used for inter-layer prediction
+    if( m_layerId > 0 && m_uiSliceIdx == 0 )
+    {      
+      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
+      {
+        UInt refLayerIdc = i;
+#if AVC_BASE
+        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
+        {
+          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
+#if AVC_SYNTAX
+          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
+          if( pcSlice->getPOC() == 0 )
+          {
+            // initialize partition order.
+            UInt* piTmp = &g_auiZscanToRaster[0];
+            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
+            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
+          }      
+          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
+          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
+        }
+        else
+        {
+#if VPS_EXTN_DIRECT_REF_LAYERS
+          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
+#else
+          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
+          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
+          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
+        }
+#else
+#if VPS_EXTN_DIRECT_REF_LAYERS
+        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
+#else
+        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
+        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
+        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
+#endif
+
+        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
+
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+
+        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
+        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
+
+        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
+        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
+
+#if SVC_UPSAMPLING
+        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
+        {    
+#if O0215_PHASE_ALIGNMENT
+#if O0194_JOINT_US_BITSHIFT
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
+#endif
+#endif
+        }
+        else
+        {
+          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
+        }
+        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
+#endif
+      }
+    }
+
+    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
       for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
@@ -1156,49 +1276,9 @@
 #endif
 
-#if SCALED_REF_LAYER_OFFSETS
-        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
-
-        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
-        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
-
-        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
-        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-        const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
-        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
-
-        Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-        Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
-        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
-        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
-
-        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
-        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
-
-#if SVC_UPSAMPLING
-        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
-        {    
-#if SCALED_REF_LAYER_OFFSETS
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
-#else
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
-#endif
-        }
-        else
-        {
-          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
-        }
         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
-#endif
-      }
-    }
-
-    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
-    {
-      setILRPic(pcPic);
+      }
+
+      pcSlice->setILRPic( m_cIlpPic );
+
 #if REF_IDX_MFM
 #if M0457_COL_PICTURE_SIGNALING
@@ -1221,8 +1301,17 @@
     }
 #endif
-#endif
-
-#endif //SVC_EXTENSION
-
+#if MFM_ENCCONSTRAINT
+    if( pcSlice->getMFMEnabledFlag() )
+    {
+      Int refLayerId = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() )->getLayerId();
+      if( refLayerId != pcSlice->getLayerId() )
+      {
+        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
+        assert( pColBasePic->checkSameRefInfo() == true );
+      }
+    }
+#endif
+#endif
+    
 #if N0147_IRAP_ALIGN_FLAG
     if(  m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
@@ -1239,4 +1328,5 @@
     }
 #endif 
+#endif //SVC_EXTENSION
     
     // For generalized B
@@ -1347,17 +1437,6 @@
 #if SVC_EXTENSION
   sps->setLayerId(m_layerId);
-#endif
-
-#if SPS_SUB_LAYER_INFO
   m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
-#else
-  m_cEntropyDecoder.decodeSPS( sps );
-#endif
-#if SVC_EXTENSION
   m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
-#else
-  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
-#endif
-#if SVC_EXTENSION
 #if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
   if(m_numLayer>0)
@@ -1366,5 +1445,8 @@
   }
 #endif
-#endif
+#else //SVC_EXTENSION
+  m_cEntropyDecoder.decodeSPS( sps );
+  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
+#endif //SVC_EXTENSION
 }
 
@@ -1519,7 +1601,17 @@
           Window &conformanceWindow = sps->getConformanceWindow();
           Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
+#if AUXILIARY_PICTURES
 #if SVC_UPSAMPLING
 #if AVC_SYNTAX
-
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
+#endif
+#else
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#else
+#if SVC_UPSAMPLING
+#if AVC_SYNTAX
           pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
 #else
@@ -1528,4 +1620,11 @@
 #else
           pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
+#endif
+#endif
+
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          // set AVC BL bit depth, can be an input parameter from the command line
+          g_bitDepthYLayer[0] = 8;
+          g_bitDepthCLayer[0] = 8;
 #endif
         }
Index: /trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 493)
+++ /trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 494)
@@ -213,5 +213,4 @@
   Void      xInitILRP(TComSPS *pcSPS);
 #endif
-  Void      setILRPic(TComPic *pcPic);
 #endif
 #if AVC_SYNTAX || SYNTAX_OUTPUT
Index: /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 494)
@@ -359,10 +359,4 @@
   {
     WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
-#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
-    if ( pcSPS->getLayerId() > 0 )
-    {
-      WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
-    }
-#endif
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
@@ -454,5 +448,5 @@
 #endif
   WRITE_CODE( pcSPS->getVPSId (),          4,       "sps_video_parameter_set_id" );
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   if(pcSPS->getLayerId() == 0)
   {
@@ -460,5 +454,5 @@
     WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
     WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
-#if SPS_SUB_LAYER_INFO
+#if SVC_EXTENSION
   }
 #endif
@@ -670,5 +664,4 @@
   WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" );
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   if( pcSPS->getLayerId() > 0 )
   {
@@ -683,5 +676,4 @@
     }
   }
-#endif
 #if M0463_VUI_EXT_ILP_REF
   ////   sps_extension_vui_parameters( )
@@ -708,4 +700,7 @@
 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
 {
+#if VPS_EXTN_OFFSET_CALC
+  UInt numBytesInVps = this->m_pcBitIf->getNumberOfWrittenBits();
+#endif
   WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
@@ -811,4 +806,9 @@
       WRITE_FLAG(1,                  "vps_extension_alignment_bit_equal_to_one");
     }
+#if VPS_EXTN_OFFSET_CALC
+    Int vpsExntOffsetValueInBits = this->m_pcBitIf->getNumberOfWrittenBits() - numBytesInVps + 16; // 2 bytes for NUH
+    assert( vpsExntOffsetValueInBits % 8 == 0 );
+    pcVPS->setExtensionOffset( vpsExntOffsetValueInBits >> 3 );
+#endif
     codeVPSExtension(pcVPS);
     WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
@@ -820,4 +820,5 @@
 }
 
+#if SVC_EXTENSION
 #if VPS_EXTNS
 Void TEncCavlc::codeVPSExtension (TComVPS *vps)
@@ -835,9 +836,5 @@
   }
 
-#if VPS_SPLIT_FLAG
   for(j = 0; j < vps->getNumScalabilityTypes() - vps->getSplittingFlag(); j++)
-#else
-  for(j = 0; j < vps->getNumScalabilityTypes(); j++)
-#endif
   {
     WRITE_CODE( vps->getDimensionIdLen(j) - 1, 3,      "dimension_id_len_minus1[j]" );
@@ -863,7 +860,7 @@
       WRITE_CODE( vps->getLayerIdInNuh(i),     6,      "layer_id_in_nuh[i]" );
     }
-#if VPS_SPLIT_FLAG
-    if(!vps->getSplittingFlag())
-#endif
+
+    if( !vps->getSplittingFlag() )
+    {
     for(j = 0; j < vps->getNumScalabilityTypes(); j++)
     {
@@ -871,4 +868,5 @@
       WRITE_CODE( vps->getDimensionId(i, j),   bits,   "dimension_id[i][j]" );
     }
+  }
   }
 #endif
@@ -885,5 +883,4 @@
   }
 #endif
-#if VPS_MOVE_DIR_DEPENDENCY_FLAG
 #if VPS_EXTN_DIRECT_REF_LAYERS
   for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
@@ -894,5 +891,4 @@
     }
   }
-#endif
 #endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
@@ -903,5 +899,15 @@
      for( i = 0; i < vps->getMaxLayers() - 1; i++)
      {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+       {
+         if(vps->getDirectDependencyFlag(j, i))
+         {
+           WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i,j), 3, "max_tid_il_ref_pics_plus1[i][j]" );
+         }
+       }
+#else
        WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
+#endif 
      }
    }
@@ -909,5 +915,15 @@
   for( i = 0; i < vps->getMaxLayers() - 1; i++)
   {
+#if O0225_MAX_TID_FOR_REF_LAYERS
+       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
+       {
+         if(vps->getDirectDependencyFlag(j, i))
+         {
+           WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i,j), 3, "max_tid_il_ref_pics_plus1[i][j]" );
+         }
+       }
+#else
     WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
+#endif 
   }
 #endif
@@ -918,20 +934,12 @@
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
-#if VPS_PROFILE_OUTPUT_LAYERS
   WRITE_CODE( vps->getNumLayerSets() - 1   , 10, "vps_number_layer_sets_minus1" );     
   WRITE_CODE( vps->getNumProfileTierLevel() - 1,  6, "vps_num_profile_tier_level_minus1"); 
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
-#else
-  for(Int idx = 1; idx <= vps->getNumLayerSets() - 1; idx++)
-#endif
   {
     WRITE_FLAG( vps->getProfilePresentFlag(idx),       "vps_profile_present_flag[i]" );
     if( !vps->getProfilePresentFlag(idx) )
     {
-#if VPS_PROFILE_OUTPUT_LAYERS
       WRITE_CODE( vps->getProfileLayerSetRef(idx) - 1, 6, "profile_ref_minus1[i]" );
-#else
-      WRITE_UVLC( vps->getProfileLayerSetRef(idx) - 1, "vps_profile_layer_set_ref_minus1[i]" );
-#endif
     }
     codePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
@@ -939,5 +947,4 @@
 #endif
 
-#if VPS_PROFILE_OUTPUT_LAYERS
   Int numOutputLayerSets = vps->getNumOutputLayerSets() ;
   WRITE_FLAG(  (numOutputLayerSets > vps->getNumLayerSets()), "more_output_layer_sets_than_default_flag" ); 
@@ -974,27 +981,4 @@
     WRITE_CODE( vps->getProfileLevelTierIdx(i), numBits, "profile_level_tier_idx[i]" );     
   }
-#else
-#if VPS_EXTN_OP_LAYER_SETS
-  // Target output layer signalling
-  WRITE_UVLC( vps->getNumOutputLayerSets(),            "vps_num_output_layer_sets");
-  for(i = 0; i < vps->getNumOutputLayerSets(); i++)
-  {
-#if VPS_OUTPUT_LAYER_SET_IDX
-    assert(vps->getOutputLayerSetIdx(i) > 0);
-    WRITE_UVLC( vps->getOutputLayerSetIdx(i) - 1,           "vps_output_layer_set_idx_minus1[i]");
-#else
-    WRITE_UVLC( vps->getOutputLayerSetIdx(i),           "vps_output_layer_set_idx[i]");
-#endif
-    Int lsIdx = vps->getOutputLayerSetIdx(i);
-    for(j = 0; j <= vps->getMaxLayerId(); j++)
-    {
-      if(vps->getLayerIdIncludedFlag(lsIdx, j))
-      {
-        WRITE_FLAG( vps->getOutputLayerFlag(lsIdx, j), "vps_output_layer_flag[lsIdx][j]");
-      }
-    }
-  }
-#endif
-#endif
 
 #if REPN_FORMAT_IN_VPS
@@ -1025,19 +1009,20 @@
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
       WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
+#endif
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+  for(i = 1; i< vps->getMaxLayers(); i++)
+  {
+    if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0  )
+    {
+      WRITE_FLAG(vps->getPocLsbNotPresentFlag(i), "poc_lsb_not_present_flag[i]");
+    }
+  }
+#endif
+#if O0215_PHASE_ALIGNMENT
+  WRITE_FLAG(vps->getPhaseAlignFlag(), "cross_layer_phase_alignment_flag" );
+#endif
+#if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI
+  WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
 #endif 
-#if N0147_IRAP_ALIGN_FLAG
-      WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
-#endif 
-#if !VPS_MOVE_DIR_DEPENDENCY_FLAG
-#if VPS_EXTN_DIRECT_REF_LAYERS
-  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-  {
-    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
-    {
-      WRITE_FLAG(vps->getDirectDependencyFlag(layerCtr, refLayerCtr), "direct_dependency_flag[i][j]" );
-    }
-  }
-#endif
-#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
   WRITE_UVLC( vps->getDirectDepTypeLen()-2,                           "direct_dep_type_len_minus2");
@@ -1107,4 +1092,7 @@
 {
   Int i,j;
+#if IRAP_ALIGN_FLAG_IN_VPS_VUI
+      WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
+#endif 
 #if VPS_VUI_BITRATE_PICRATE
   WRITE_FLAG( vps->getBitRatePresentVpsFlag(),        "bit_rate_present_vps_flag" );
@@ -1173,4 +1161,5 @@
 }
 #endif
+#endif //SVC_EXTENSION
 
 Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
@@ -1218,5 +1207,5 @@
   if ( !pcSlice->getDependentSliceSegmentFlag() )
   {
-
+#if SVC_EXTENSION
 #if POC_RESET_FLAG
     Int iBits = 0;
@@ -1238,5 +1227,4 @@
     }
 #else
-#if SH_DISCARDABLE_FLAG
     if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     {
@@ -1249,5 +1237,6 @@
       WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     }
-#else
+#endif
+#else //SVC_EXTENSION
     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     {
@@ -1255,6 +1244,5 @@
       WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     }
-#endif
-#endif
+#endif //SVC_EXTENSION
 
     WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
@@ -1265,4 +1253,5 @@
     }
 
+#if !AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
     // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
@@ -1272,9 +1261,14 @@
     assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 );
 #endif
+#endif
     // if( separate_colour_plane_flag  ==  1 )
     //   colour_plane_id                                      u(2)
 
 #if N0065_LAYER_POC_ALIGNMENT
+#if O0062_POC_LSB_NOT_PRESENT_FLAG
+    if( (pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag())
+#else
     if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
+#endif
 #else
     if( !pcSlice->getIdrPicFlag() )
@@ -1297,4 +1291,7 @@
 
 #if N0065_LAYER_POC_ALIGNMENT
+#if SHM_FIX7
+    }
+#endif
       if( !pcSlice->getIdrPicFlag() )
       {
@@ -1414,5 +1411,5 @@
         WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
       }
-#if N0065_LAYER_POC_ALIGNMENT
+#if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7
       }
 #endif
@@ -1421,5 +1418,9 @@
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
 #if ILP_SSH_SIG
+#if ILP_SSH_SIG_FIX
+    if((pcSlice->getSPS()->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) )
+#else
     if((pcSlice->getSPS()->getLayerId() > 0) && pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (pcSlice->getNumILRRefIdx() > 0) )
+#endif
 #else
     if((pcSlice->getSPS()->getLayerId() > 0)  &&  (pcSlice->getNumILRRefIdx() > 0) )
@@ -1468,6 +1469,13 @@
          WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
          {
+#if AUXILIARY_PICTURES
+           if (pcSlice->getChromaFormatIdc() != CHROMA_400)
+           {
+#endif
            SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
           WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
+#if AUXILIARY_PICTURES
+           }
+#endif
          }
       }
@@ -1934,4 +1942,10 @@
   UInt            uiMode = 0;
   UInt            uiTotalSignalledWeightFlags = 0;
+#if AUXILIARY_PICTURES
+  if (pcSlice->getChromaFormatIdc() == CHROMA_400)
+  {
+    bChroma = false;
+  }
+#endif
   if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred()) )
   {
Index: /trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 494)
@@ -69,8 +69,4 @@
   Int m_numRefIdc;
   Int m_refIdc[MAX_NUM_REF_PICS+1];
-#if EXTERNAL_USEDBYCURR_N0082
-  Int m_UseExtusedByCurrPic;
-  Int m_ExtusedByCurrPic[MAX_NUM_REF_PICS];
-#endif
   GOPEntry()
   : m_POC(-1)
@@ -87,14 +83,8 @@
   , m_deltaRPS(0)
   , m_numRefIdc(0)
-#if EXTERNAL_USEDBYCURR_N0082
-  , m_UseExtusedByCurrPic(0)
-#endif
   {
     ::memset( m_referencePics, 0, sizeof(m_referencePics) );
     ::memset( m_usedByCurrPic, 0, sizeof(m_usedByCurrPic) );
     ::memset( m_refIdc,        0, sizeof(m_refIdc) );
-#if EXTERNAL_USEDBYCURR_N0082
-    ::memset( m_usedByCurrPic, 0, sizeof(m_ExtusedByCurrPic) );
-#endif
   }
 };
@@ -221,4 +211,7 @@
   Int       m_chromaCbQpOffset;                 //  Chroma Cb QP Offset (0:default)
   Int       m_chromaCrQpOffset;                 //  Chroma Cr Qp Offset (0:default)
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC;
+#endif
 
 #if ADAPTIVE_QP_SELECTION
@@ -941,4 +934,8 @@
   Int       getAdaptiveResolutionChange()      { return m_adaptiveResolutionChange; }
 #endif
+#if AUXILIARY_PICTURES
+  Void         setChromaFormatIDC(ChromaFormat x) { m_chromaFormatIDC = x;    }
+  ChromaFormat getChromaFormatIDC()               { return m_chromaFormatIDC; }
+#endif
 #endif
 };
Index: /trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 494)
@@ -250,4 +250,9 @@
 #endif
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  m_disableILP = xCheckTileSetConstraint(rpcCU);
+  m_pcPredSearch->setDisableILP(m_disableILP);
+#endif
+
   // analysis of CU
   xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 );
@@ -261,4 +266,8 @@
     }
   }
+#endif
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  xVerifyTileSetConstraint(rpcCU);
 #endif
 }
@@ -731,5 +740,9 @@
         }
 #if (ENCODER_FAST_MODE)
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+      if(pcPic->getLayerId() > 0 && !m_disableILP)
+#else
       if(pcPic->getLayerId() > 0)
+#endif
       {
         for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++)
@@ -1381,4 +1394,8 @@
       Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]);
       if(bZeroMVILR)
+      {
+#endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+      if (!(rpcTempCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP))
       {
 #endif
@@ -1426,8 +1443,11 @@
           }
         }
+      }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+      }
+#endif
 #if REF_IDX_ME_ZEROMV 
-        }
-#endif
-      }
+      }
+#endif
   }
 
@@ -1808,4 +1828,70 @@
 }
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU )
+{
+  Bool disableILP = false;
+
+  if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getAddr()) >= 0)
+  {
+    if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getAddr()) == 2)
+    {
+      disableILP = true;
+    }
+    if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getAddr()) == 1)
+    {
+      Int currCUaddr = rpcCU->getAddr();
+      Int frameWitdhInCU  = rpcCU->getPic()->getPicSym()->getFrameWidthInCU();
+      Int frameHeightInCU = rpcCU->getPic()->getPicSym()->getFrameHeightInCU();
+      Bool leftCUExists   = (currCUaddr % frameWitdhInCU) > 0;
+      Bool aboveCUExists  = (currCUaddr / frameWitdhInCU) > 0;
+      Bool rightCUExists  = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1);
+      Bool belowCUExists  = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1);
+      Int currTileSetIdx  = rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr);
+      // Check if CU is at tile set boundary
+      if ( (leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-1) != currTileSetIdx) ||
+           (leftCUExists && aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) ||
+           (aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) ||
+           (aboveCUExists && rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) ||
+           (rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+1) != currTileSetIdx) ||
+           (rightCUExists && belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) ||
+           (belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) ||
+           (belowCUExists && leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) )
+      {
+        disableILP = true;  // Disable ILP in tile set boundary CU
+      }
+    }
+  }
+
+  return disableILP;
+}
+
+Void TEncCu::xVerifyTileSetConstraint( TComDataCU*& rpcCU )
+{
+  if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getAddr()) >= 0 &&
+      m_disableILP)
+  {
+    UInt numPartitions = rpcCU->getPic()->getNumPartInCU();
+    for (UInt i = 0; i < numPartitions; i++)
+    {
+      if (!rpcCU->isIntra(i))
+      {
+        for (UInt refList = 0; refList < 2; refList++)
+        {
+          if (rpcCU->getInterDir(i) & (1<<refList))
+          {
+            TComCUMvField *mvField = rpcCU->getCUMvField(RefPicList(refList));
+            if (mvField->getRefIdx(i) >= 0)
+            {
+              assert(!(rpcCU->getSlice()->getRefPic(RefPicList(refList), mvField->getRefIdx(i))->isILR(rpcCU->getLayerId())));
+            }
+          }
+        }
+      }
+    }
+  }
+}
+#endif
+
 /** Collect ARL statistics from one LCU
  * \param pcCU
Index: /trunk/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncCu.h	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncCu.h	(revision 494)
@@ -108,4 +108,7 @@
   Int                     m_temporalSAD;
 #endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool                    m_disableILP;
+#endif
 public:
   /// copy parameters from encoder class
@@ -171,4 +174,9 @@
 #endif
 
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool xCheckTileSetConstraint( TComDataCU*& rpcCU );
+  Void xVerifyTileSetConstraint( TComDataCU*& rpcCU );
+#endif
+
 #if AMP_ENC_SPEEDUP 
 #if AMP_MRG
Index: /trunk/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 494)
@@ -280,4 +280,8 @@
   const UInt uiTrDepthCurr = uiDepth - pcCU->getDepth( uiAbsPartIdx );
   const Bool bFirstCbfOfCU = uiTrDepthCurr == 0;
+#if AUXILIARY_PICTURES
+  if (pcCU->getSlice()->getChromaFormatIdc() != CHROMA_400)
+  {
+#endif
   if( bFirstCbfOfCU || uiLog2TrafoSize > 2 )
   {
@@ -296,4 +300,12 @@
     assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr - 1 ) );
   }
+#if AUXILIARY_PICTURES
+  }
+  else
+  {
+    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepthCurr ) == 0 );
+    assert( pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepthCurr ) == 0 );
+  }
+#endif
   
   if( uiSubdiv )
@@ -402,4 +414,10 @@
 Void TEncEntropy::encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
 {
+#if AUXILIARY_PICTURES
+  if ( pcCU->getSlice()->getChromaFormatIdc() == CHROMA_400 )
+  {
+    return;
+  }
+#endif
   if( bRD )
   {
Index: /trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 494)
@@ -753,10 +753,9 @@
     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
 #if SVC_EXTENSION
-#if ILR_RESTR && ILR_RESTR_FIX
+    if (m_layerId > 0)
+    {
     Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
     Int activeNumILRRefIdxTmp = 0;
-#endif
-    if (m_layerId > 0)
-    {
+
       for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
       {
@@ -769,7 +768,10 @@
         pcSlice->setBaseColPic( *cListPic, refLayerIdc );
 
-#if ILR_RESTR && ILR_RESTR_FIX
         // Apply temporal layer restriction to inter-layer prediction
+#if O0225_MAX_TID_FOR_REF_LAYERS
+        Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId(),m_layerId);
+#else
         Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId());
+#endif 
         if( ((Int)(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getRapPicFlag()) )
         {
@@ -780,7 +782,5 @@
           continue; // ILP is not valid due to temporal layer restriction
         }
-#endif
-
-#if SCALED_REF_LAYER_OFFSETS
+
         const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
 
@@ -790,14 +790,5 @@
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getConformanceWindow();
-        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
-
-        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
+
         g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
         g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
@@ -809,8 +800,16 @@
         if( pcPic->isSpatialEnhLayer(refLayerIdc))
         {
-#if SCALED_REF_LAYER_OFFSETS
+#if O0215_PHASE_ALIGNMENT
+#if O0194_JOINT_US_BITSHIFT
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#endif
+#else
+#if O0194_JOINT_US_BITSHIFT
+          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
+#else
           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
-#else
-          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
+#endif
 #endif
         }
@@ -823,5 +822,4 @@
       }
 
-#if ILR_RESTR && ILR_RESTR_FIX
       // Update the list of active inter-layer pictures
       for ( Int i = 0; i < activeNumILRRefIdxTmp; i++)
@@ -835,5 +833,4 @@
         pcSlice->setInterLayerPredEnabledFlag(false);
       }
-#endif
       
       if( pocCurr % m_pcCfg->getIntraPeriod() == 0 )
@@ -1167,5 +1164,5 @@
     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     {
-      m_pcEncTop->setILRPic(pcPic);
+      pcSlice->setILRPic( m_pcEncTop->getIlpList() );
 #if REF_IDX_MFM
 #if M0457_COL_PICTURE_SIGNALING
@@ -1201,7 +1198,12 @@
         UInt ColFromL0Flag = pcSlice->getColFromL0Flag();
         UInt ColRefIdx     = pcSlice->getColRefIdx();
+
         for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
         { 
-          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) 
+          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) 
+#if MFM_ENCCONSTRAINT
+            && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
+#endif
+            ) 
           { 
             ColRefIdx = colIdx; 
@@ -1216,5 +1218,9 @@
           for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
           { 
-            if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) 
+            if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) 
+#if MFM_ENCCONSTRAINT
+              && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
+#endif
+              ) 
             { 
               ColRefIdx = colIdx; 
@@ -1567,4 +1573,8 @@
     {
       pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() );
+#if O0194_WEIGHTED_PREDICTION_CGS
+      // Calculate for the base layer to be used in EL as Inter layer reference
+      m_pcSliceEncoder->estimateILWpParam( pcSlice );
+#endif
 #if AVC_SYNTAX
       pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
@@ -1607,4 +1617,8 @@
           pcSlice->setSliceSegmentCurStartCUAddr  ( startCUAddrSlice      );
           pcSlice->setSliceBits(0);
+#if SVC_EXTENSION
+          // copy reference list modification info from the first slice, assuming that this information is the same across all slices in the picture
+          memcpy( pcSlice->getRefPicListModification(), pcPic->getSlice(0)->getRefPicListModification(), sizeof(TComRefPicListModification) );
+#endif
           uiNumSlices ++;
         }
@@ -1689,4 +1703,9 @@
 #else
       OutputNALUnit nalu(NAL_UNIT_VPS);
+#endif
+#if VPS_EXTN_OFFSET_CALC
+      OutputNALUnit tempNalu(NAL_UNIT_VPS, 0, 0        ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
+      m_pcEntropyCoder->setBitstream(&tempNalu.m_Bitstream);
+      m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS());  // Use to calculate the VPS extension offset
 #endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
@@ -3162,8 +3181,16 @@
   
   TComPicYuv* pcOrgInterlaced = new TComPicYuv;
+#if AUXILIARY_PICTURES
+  pcOrgInterlaced->create( iWidth, iHeight << 1, pcPicOrgTop->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#else
   pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif
   
   TComPicYuv* pcRecInterlaced = new TComPicYuv;
+#if AUXILIARY_PICTURES
+  pcRecInterlaced->create( iWidth, iHeight << 1, pcPicOrgTop->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#else
   pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif
   
   Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
Index: /trunk/source/Lib/TLibEncoder/TEncPic.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncPic.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncPic.cpp	(revision 494)
@@ -126,4 +126,32 @@
  * \return Void
  */
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+Void TEncPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,  
+                      Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual )
+
+#else
+
+Void TEncPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,
+                      Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual )
+#endif
+{
+#if SVC_UPSAMPLING
+  TComPic::create( iWidth, iHeight, chromaFormat, uiMaxWidth, uiMaxHeight, uiMaxDepth,  
+                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSps, bIsVirtual );
+#else
+  TComPic::create( iWidth, iHeight, chromaFormat, uiMaxWidth, uiMaxHeight, uiMaxDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, bIsVirtual );
+#endif
+  m_uiMaxAQDepth = uiMaxAQDepth;
+  if ( uiMaxAQDepth > 0 )
+  {
+    m_acAQLayer = new TEncPicQPAdaptationLayer[ m_uiMaxAQDepth ];
+    for (UInt d = 0; d < m_uiMaxAQDepth; d++)
+    {
+      m_acAQLayer[d].create( iWidth, iHeight, uiMaxWidth>>d, uiMaxHeight>>d );
+    }
+  }
+}
+#else
 #if SVC_UPSAMPLING
 Void TEncPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,  
@@ -152,4 +180,5 @@
   }
 }
+#endif
 
 /** Clean up
Index: /trunk/source/Lib/TLibEncoder/TEncPic.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncPic.h	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncPic.h	(revision 494)
@@ -105,4 +105,14 @@
   virtual ~TEncPic();
 
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,  
+                      Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual=false );
+#else
+  Void          create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,
+                          Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual = false );
+
+#endif
+#else
 #if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,   
@@ -111,4 +121,5 @@
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, UInt uiMaxAQDepth,   
                         Window &conformanceWindow, Window &defaultDisplayWindow, Int *numReorderPics, Bool bIsVirtual = false );
+#endif
 #endif
   virtual Void  destroy();
Index: /trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 494)
@@ -1871,5 +1871,9 @@
 
   saoParam->bSaoFlag[0] = true;
+#if AUXILIARY_PICTURES
+  saoParam->bSaoFlag[1] = m_pcPic->getChromaFormat() == CHROMA_400 ? false : true;
+#else
   saoParam->bSaoFlag[1] = true;
+#endif
   saoParam->oneUnitFlag[0] = false;
   saoParam->oneUnitFlag[1] = false;
Index: /trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 494)
@@ -914,4 +914,8 @@
     }
 
+#if AUXILIARY_PICTURES
+    if (pcCU->getSlice()->getChromaFormatIdc() != CHROMA_400)
+    {
+#endif
     piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
     uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
@@ -945,4 +949,7 @@
       piPCMSample += uiWidth;
     }
+#if AUXILIARY_PICTURES
+    }
+#endif
     m_pcBinIf->resetBac();
   }
Index: /trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 494)
@@ -3092,4 +3092,8 @@
     {
 #endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    if (!(pcCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP))
+    {
+#endif
       UInt uiCostCand = MAX_UINT;
       UInt uiBitsCand = 0;
@@ -3115,4 +3119,7 @@
         uiMergeIndex = uiMergeCand;
       }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    }
+#endif
 #if REF_IDX_ME_ZEROMV
     }
@@ -3221,38 +3228,4 @@
   Int numValidMergeCand = 0 ;
 
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-  Bool disableILP = false;
-  if (pcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && pcCU->getPic()->getPicSym()->getTileSetIdxMap(pcCU->getAddr()) >= 0)
-  {
-    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 2)
-    {
-      disableILP = true;
-    }
-    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 1)
-    {
-      Int currCUaddr = pcCU->getAddr();
-      Int frameWitdhInCU  = pcCU->getPic()->getPicSym()->getFrameWidthInCU();
-      Int frameHeightInCU = pcCU->getPic()->getPicSym()->getFrameHeightInCU();
-      Bool leftCUExists   = (currCUaddr % frameWitdhInCU) > 0;
-      Bool aboveCUExists  = (currCUaddr / frameWitdhInCU) > 0;
-      Bool rightCUExists  = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1);
-      Bool belowCUExists  = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1);
-      Int currTileSetIdx  = pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr);
-      // Check if CU is at tile set boundary
-      if ( (leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-1) != currTileSetIdx) ||
-           (leftCUExists && aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) ||
-           (aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) ||
-           (aboveCUExists && rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) ||
-           (rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+1) != currTileSetIdx) ||
-           (rightCUExists && belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) ||
-           (belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) ||
-           (belowCUExists && leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) )
-      {
-        disableILP = true;  // Disable ILP in tile set boundary CU
-      }
-    }
-  }
-#endif
-
   for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
   {
@@ -3305,5 +3278,5 @@
       {
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && disableILP)
+        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && m_disableILP)
         {
           continue;
@@ -3529,5 +3502,5 @@
         }
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-        if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
+        if (pcPic->isILR(pcCU->getLayerId()) && m_disableILP)
         {
           testIter = false;
@@ -3550,5 +3523,5 @@
           }
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-          if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
+          if (pcPic->isILR(pcCU->getLayerId()) && m_disableILP)
           {
             testRefIdx = false;
@@ -4119,5 +4092,10 @@
 
   // prediction pattern
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Bug Fix (It did not check WP for BSlices)
+  if ( pcCU->getSlice()->getPPS()->getUseWP())
+#else
   if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType()==P_SLICE )
+#endif
   {
     xPredInterLumaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMvCand, iSizeX, iSizeY, pcTemplateCand, true );
@@ -4128,5 +4106,10 @@
   }
 
+#if O0194_WEIGHTED_PREDICTION_CGS
+  if ( pcCU->getSlice()->getPPS()->getUseWP())
+  ///< Bug Fix (It did not check WP for BSlices)
+#else
   if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType()==P_SLICE )
+#endif
   {
     xWeightedPredictionUni( pcCU, pcTemplateCand, uiPartAddr, iSizeX, iSizeY, eRefPicList, pcTemplateCand, iRefIdx );
Index: /trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 494)
@@ -129,5 +129,9 @@
   // UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS];
   UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1]; //th array bounds
-  
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool            m_disableILP;
+#endif
+
 public:
   TEncSearch();
@@ -220,4 +224,9 @@
   Void xEncPCM    (TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piOrg, Pel* piPCM, Pel* piPred, Pel* piResi, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, TextType eText);
   Void IPCMSearch (TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv );
+
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Void setDisableILP(Bool a) {m_disableILP = a;}
+#endif
+
 protected:
   
Index: /trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -51,5 +51,5 @@
   m_apcPicYuvPred = NULL;
   m_apcPicYuvResi = NULL;
-  
+
   m_pdRdPicLambda = NULL;
   m_pdRdPicQp     = NULL;
@@ -69,14 +69,32 @@
 }
 
-Void TEncSlice::initCtxMem(  UInt i )                
-{   
+Void TEncSlice::initCtxMem(  UInt i )
+{
   for (std::vector<TEncSbac*>::iterator j = CTXMem.begin(); j != CTXMem.end(); j++)
   {
     delete (*j);
   }
-  CTXMem.clear(); 
-  CTXMem.resize(i); 
+  CTXMem.clear();
+  CTXMem.resize(i);
 }
 
+#if AUXILIARY_PICTURES
+Void TEncSlice::create( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth )
+{
+  // create prediction picture
+  if ( m_apcPicYuvPred == NULL )
+  {
+    m_apcPicYuvPred  = new TComPicYuv;
+    m_apcPicYuvPred->create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
+  }
+
+  // create residual picture
+  if( m_apcPicYuvResi == NULL )
+  {
+    m_apcPicYuvResi  = new TComPicYuv;
+    m_apcPicYuvResi->create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
+  }
+}
+#else
 Void TEncSlice::create( Int iWidth, Int iHeight, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth )
 {
@@ -87,5 +105,5 @@
     m_apcPicYuvPred->create( iWidth, iHeight, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
   }
-  
+
   // create residual picture
   if( m_apcPicYuvResi == NULL )
@@ -95,4 +113,5 @@
   }
 }
+#endif
 
 Void TEncSlice::destroy()
@@ -105,5 +124,5 @@
     m_apcPicYuvPred  = NULL;
   }
-  
+
   // destroy residual picture
   if ( m_apcPicYuvResi )
@@ -113,5 +132,5 @@
     m_apcPicYuvResi  = NULL;
   }
-  
+
   // free lambda and QP arrays
   if ( m_pdRdPicLambda ) { xFree( m_pdRdPicLambda ); m_pdRdPicLambda = NULL; }
@@ -139,9 +158,9 @@
 #if SVC_EXTENSION
   m_ppcTEncTop        = pcEncTop->getLayerEnc();
-#endif  
+#endif
   m_pcGOPEncoder      = pcEncTop->getGOPEncoder();
   m_pcCuEncoder       = pcEncTop->getCuEncoder();
   m_pcPredSearch      = pcEncTop->getPredSearch();
-  
+
   m_pcEntropyCoder    = pcEncTop->getEntropyCoder();
   m_pcCavlcCoder      = pcEncTop->getCavlcCoder();
@@ -149,10 +168,10 @@
   m_pcBinCABAC        = pcEncTop->getBinCABAC();
   m_pcTrQuant         = pcEncTop->getTrQuant();
-  
+
   m_pcBitCounter      = pcEncTop->getBitCounter();
   m_pcRdCost          = pcEncTop->getRdCost();
   m_pppcRDSbacCoder   = pcEncTop->getRDSbacCoder();
   m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
-  
+
   // create lambda and QP arrays
   m_pdRdPicLambda     = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
@@ -187,5 +206,5 @@
   Double dQP;
   Double dLambda;
-  
+
   rpcSlice = pcPic->getSlice(0);
   rpcSlice->setSPS( pSPS );
@@ -202,5 +221,5 @@
   rpcSlice->setPicOutputFlag( true );
   rpcSlice->setPOC( pocCurr );
-  
+
   // depth computation based on GOP size
   Int depth;
@@ -230,17 +249,17 @@
     }
   }
-  
+
   // slice type
   SliceType eSliceType;
-  
+
   eSliceType=B_SLICE;
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
-  
+
   rpcSlice->setSliceType    ( eSliceType );
-  
+
   // ------------------------------------------------------------------------------------------------------------------
   // Non-referenced frame marking
   // ------------------------------------------------------------------------------------------------------------------
-  
+
   if(pocLast == 0)
   {
@@ -252,16 +271,16 @@
   }
   rpcSlice->setReferenced(true);
-  
+
   // ------------------------------------------------------------------------------------------------------------------
   // QP setting
   // ------------------------------------------------------------------------------------------------------------------
-  
+
   dQP = m_pcCfg->getQP();
   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()))) 
+    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
     {
@@ -269,5 +288,5 @@
     }
   }
-  
+
   // modify QP
   Int* pdQPs = m_pcCfg->getdQPs();
@@ -285,5 +304,5 @@
   // Lambda computation
   // ------------------------------------------------------------------------------------------------------------------
-  
+
   Int iQP;
   Double dOrigQP = dQP;
@@ -294,5 +313,5 @@
     // compute QP value
     dQP = dOrigQP + ((iDQpIdx+1)>>1)*(iDQpIdx%2 ? -1 : 1);
-    
+
     // compute lambda value
     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
@@ -326,5 +345,5 @@
 #endif
     }
-    
+
     // if hadamard is used in ME process
     if ( !m_pcCfg->getUseHADME() && rpcSlice->getSliceType( ) != I_SLICE )
@@ -332,5 +351,5 @@
       dLambda *= 0.95;
     }
-    
+
 #if REPN_FORMAT_IN_VPS
     iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
@@ -343,10 +362,10 @@
     m_piRdPicQp    [iDQpIdx] = iQP;
   }
-  
+
   // obtain dQP = 0 case
   dLambda = m_pdRdPicLambda[0];
   dQP     = m_pdRdPicQp    [0];
   iQP     = m_piRdPicQp    [0];
-  
+
   if( rpcSlice->getSliceType( ) != I_SLICE )
   {
@@ -359,5 +378,5 @@
     Int nCurLayer = rpcSlice->getLayerId();
     Double gamma = xCalEnhLambdaFactor( m_ppcTEncTop[nCurLayer-1]->getQP() - m_ppcTEncTop[nCurLayer]->getQP() ,
-      1.0 * m_ppcTEncTop[nCurLayer]->getSourceWidth() * m_ppcTEncTop[nCurLayer]->getSourceHeight() 
+      1.0 * m_ppcTEncTop[nCurLayer]->getSourceWidth() * m_ppcTEncTop[nCurLayer]->getSourceHeight()
       / m_ppcTEncTop[nCurLayer-1]->getSourceWidth() / m_ppcTEncTop[nCurLayer-1]->getSourceHeight() );
     dLambda *= gamma;
@@ -392,7 +411,7 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
 // for RDOQ
-  m_pcTrQuant->setLambda( dLambda, dLambda / weight );    
+  m_pcTrQuant->setLambda( dLambda, dLambda / weight );
 #else
   m_pcTrQuant->setLambda( dLambda );
@@ -401,13 +420,13 @@
 #if SAO_CHROMA_LAMBDA
 // For SAO
-  rpcSlice   ->setLambda( dLambda, dLambda / weight );  
+  rpcSlice   ->setLambda( dLambda, dLambda / weight );
 #else
   rpcSlice   ->setLambda( dLambda );
 #endif
-  
+
 #if HB_LAMBDA_FOR_LDC
   // restore original slice type
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
-  
+
 #if SVC_EXTENSION
   if(m_pcCfg->getLayerId() > 0)
@@ -418,12 +437,12 @@
   rpcSlice->setSliceType        ( eSliceType );
 #endif
-  
+
   if (m_pcCfg->getUseRecalculateQPAccordingToLambda())
   {
     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 ) ) );    
+    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
   }
@@ -438,5 +457,5 @@
   rpcSlice->setNumRefIdx(REF_PIC_LIST_0,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
   rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
-  
+
   if ( m_pcCfg->getDeblockingFilterMetric() )
   {
@@ -479,11 +498,8 @@
 
   rpcSlice->setDepth            ( depth );
-  
+
   pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
-#if TEMP_SCALABILITY_FIX
-  if((eSliceType==I_SLICE) || (rpcSlice->getPOC() == 0))
-#else
+
   if(eSliceType==I_SLICE)
-#endif
   {
     pcPic->setTLayer(0);
@@ -493,5 +509,5 @@
   assert( m_apcPicYuvPred );
   assert( m_apcPicYuvResi );
-  
+
   pcPic->setPicYuvPred( m_apcPicYuvPred );
   pcPic->setPicYuvResi( m_apcPicYuvResi );
@@ -557,5 +573,5 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
   // for RDOQ
   m_pcTrQuant->setLambda( lambda, lambda / weight );
@@ -665,7 +681,7 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
   // for RDOQ
-  m_pcTrQuant->setLambda( lambda, lambda / weight );    
+  m_pcTrQuant->setLambda( lambda, lambda / weight );
 #else
   m_pcTrQuant->setLambda( lambda );
@@ -674,5 +690,5 @@
 #if SAO_CHROMA_LAMBDA
   // For SAO
-  pcSlice   ->setLambda( lambda, lambda / weight );  
+  pcSlice   ->setLambda( lambda, lambda / weight );
 #else
   pcSlice   ->setLambda( lambda );
@@ -692,5 +708,5 @@
   Int iMaxSR = m_pcCfg->getSearchRange();
   Int iNumPredDir = pcSlice->isInterP() ? 1 : 2;
- 
+
   for (Int iDir = 0; iDir <= iNumPredDir; iDir++)
   {
@@ -726,9 +742,9 @@
   }
 #endif
-  
+
   TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
   Double     dPicRdCostBest = MAX_DOUBLE;
   UInt       uiQpIdxBest = 0;
-  
+
   Double dFrameLambda;
 #if FULL_NBIT
@@ -737,5 +753,5 @@
   Int    SHIFT_QP = 12;
 #endif
-  
+
   // set frame lambda
   if (m_pcCfg->getGOPSize() > 1)
@@ -748,5 +764,5 @@
   }
   m_pcRdCost      ->setFrameLambda(dFrameLambda);
-  
+
   // for each QP candidate
   for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
@@ -776,5 +792,5 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
     // for RDOQ
     m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
@@ -784,21 +800,21 @@
 #if SAO_CHROMA_LAMBDA
     // For SAO
-    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight ); 
+    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
 #else
     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
 #endif
-    
+
     // try compress
     compressSlice   ( rpcPic );
-    
+
     Double dPicRdCost;
     UInt64 uiPicDist        = m_uiPicDist;
     UInt64 uiALFBits        = 0;
-    
+
     m_pcGOPEncoder->preLoopFilterPicAll( rpcPic, uiPicDist, uiALFBits );
-    
+
     // compute RD cost and choose the best
     dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits + uiALFBits, uiPicDist, true, DF_SSE_FRAME);
-    
+
     if ( dPicRdCost < dPicRdCostBest )
     {
@@ -807,5 +823,5 @@
     }
   }
-  
+
   // set best values
   pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdxBest] );
@@ -832,7 +848,7 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
-  // for RDOQ 
-  m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 
+#if RDOQ_CHROMA_LAMBDA
+  // for RDOQ
+  m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
 #else
   m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
@@ -840,5 +856,5 @@
 #if SAO_CHROMA_LAMBDA
   // For SAO
-  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 
+  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
 #else
   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
@@ -862,5 +878,5 @@
 
   UInt uiEncCUOrder;
-  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU()); 
+  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
   for( uiEncCUOrder = uiStartCUAddr/rpcPic->getNumPartInCU();
        uiEncCUOrder < (uiBoundingCUAddr+(rpcPic->getNumPartInCU()-1))/rpcPic->getNumPartInCU();
@@ -898,10 +914,10 @@
   TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
   xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
-  
+
   // initialize cost values
   m_uiPicTotalBits  = 0;
   m_dPicRdCost      = 0;
   m_uiPicDist       = 0;
-  
+
   // set entropy coder
   if( m_pcCfg->getUseSBACRD() )
@@ -921,5 +937,5 @@
     m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
   }
-  
+
   //------------------------------------------------------------------------------
   //  Weighted Prediction parameters estimation.
@@ -930,4 +946,11 @@
     xCalcACDCParamSlice(pcSlice);
   }
+#if O0194_WEIGHTED_PREDICTION_CGS
+  else
+  {
+    // Calculate for the base layer to be used in EL as Inter layer reference
+    estimateILWpParam( pcSlice );    
+  }
+#endif
 
   Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred());
@@ -1021,5 +1044,5 @@
         m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
         Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
-        uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU()); 
+        uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
         uiLin     = uiCUAddr / uiWidthInLCUs;
         uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(rpcPic->getPicSym()->getCUOrderMap(uiCUAddr))*iNumSubstreamsPerTile
@@ -1098,5 +1121,5 @@
           pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
         }
-        if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || 
+        if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
@@ -1137,5 +1160,5 @@
       m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
       m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
-      
+
       ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
 
@@ -1242,5 +1265,5 @@
         m_pcRdCost->setLambda(oldLambda);
 #if RATE_CONTROL_INTRA
-        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
 #else
@@ -1250,5 +1273,5 @@
 #endif
 #endif
-      
+
       // restore entropy coder to an initial stage
       m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
@@ -1275,5 +1298,5 @@
       {
          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
-       
+
          //Store probabilties of second LCU in line into buffer
          if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
@@ -1325,5 +1348,5 @@
 
 #if RATE_CONTROL_INTRA
-        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
 #else
@@ -1350,5 +1373,5 @@
       }
     }
-    
+
     m_uiPicTotalBits += pcCU->getTotalBits();
     m_dPicRdCost     += pcCU->getTotalCost();
@@ -1401,5 +1424,5 @@
     m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
   }
-  
+
   m_pcCuEncoder->setBitCounter( NULL );
   m_pcBitCounter = NULL;
@@ -1427,5 +1450,5 @@
       m_pcBufferSbacCoders[ui].load(m_pcSbacCoder); //init. state
     }
-    
+
     for (Int iSubstrmIdx=0; iSubstrmIdx < iNumSubstreams; iSubstrmIdx++)
     {
@@ -1524,5 +1547,5 @@
         }
         if ( (true/*bEnforceSliceRestriction*/ &&
-             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || 
+             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
@@ -1579,5 +1602,5 @@
     }
 
-    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );    
+    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
     {
@@ -1613,5 +1636,5 @@
         if (allowMergeLeft)
         {
-          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft); 
+          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
         }
         else
@@ -1676,9 +1699,9 @@
 #if ENC_DEC_TRACE
     g_bJustDoIt = g_bEncDecTraceDisable;
-#endif    
+#endif
     if( m_pcCfg->getUseSBACRD() )
     {
        pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
-       
+
 
        //Store probabilties of second LCU in line into buffer
@@ -1733,5 +1756,5 @@
   UInt uiNumberOfCUsInFrame = rpcPic->getNumCUsInFrame();
   uiBoundingCUAddrSlice     = uiNumberOfCUsInFrame;
-  if (bEncodeSlice) 
+  if (bEncodeSlice)
   {
     UInt uiCUAddrIncrement;
@@ -1769,5 +1792,5 @@
       uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1809,5 +1832,5 @@
       uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1819,5 +1842,5 @@
 
   Bool tileBoundary = false;
-  if ((m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_BYTES) && 
+  if ((m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_BYTES) &&
       (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
   {
@@ -1832,5 +1855,5 @@
     }
     tileBoundingCUAddrSlice = lcuEncAddr*rpcPic->getNumPartInCU();
-    
+
     if (tileBoundingCUAddrSlice < uiBoundingCUAddrSlice)
     {
@@ -1845,5 +1868,5 @@
   startCUAddrSliceSegment    = pcSlice->getSliceSegmentCurStartCUAddr();
   boundingCUAddrSliceSegment = uiNumberOfCUsInFrame;
-  if (bEncodeSlice) 
+  if (bEncodeSlice)
   {
     UInt uiCUAddrIncrement;
@@ -1880,5 +1903,5 @@
       boundingCUAddrSliceSegment    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice segment does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1919,5 +1942,5 @@
       boundingCUAddrSliceSegment    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice segment does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1927,5 +1950,5 @@
     pcSlice->setSliceSegmentCurEndCUAddr( boundingCUAddrSliceSegment );
   }
-  if ((m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_BYTES) && 
+  if ((m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_BYTES) &&
     (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
   {
@@ -1979,8 +2002,8 @@
   }
   UInt uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
-  
+
   pcSlice->setSliceSegmentCurStartCUAddr(uiRealStartAddress);
   startCUAddrSliceSegment=uiRealStartAddress;
-  
+
   //calculate real slice start address
   uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceCurStartCUAddr()) % rpcPic->getNumPartInCU();
@@ -2007,8 +2030,8 @@
   }
   uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
-  
+
   pcSlice->setSliceCurStartCUAddr(uiRealStartAddress);
   uiStartCUAddrSlice=uiRealStartAddress;
-  
+
   // Make a joint decision based on reconstruction and dependent slice bounds
   startCUAddr    = max(uiStartCUAddrSlice   , startCUAddrSliceSegment   );
@@ -2022,7 +2045,7 @@
     if ( (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
       || (m_pcCfg->getSliceMode()==0 && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
-      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==0) 
+      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==0)
       || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
-      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==0) 
+      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==0)
       || (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceMode()==0)
       || tileBoundary
@@ -2066,3 +2089,13 @@
 }
 #endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+Void TEncSlice::estimateILWpParam( TComSlice* pcSlice )
+{
+  xCalcACDCParamSlice(pcSlice);
+  wpACDCParam * temp_weightACDCParam;
+
+  pcSlice->getWpAcDcParam(temp_weightACDCParam);
+  g_refWeightACDCParam = (void *) temp_weightACDCParam;
+}
+#endif
 //! \}
Index: /trunk/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncSlice.h	(revision 494)
@@ -111,5 +111,9 @@
   virtual ~TEncSlice();
   
+#if AUXILIARY_PICTURES
+  Void    create              ( Int iWidth, Int iHeight, ChromaFormat chromaFormat, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth );
+#else
   Void    create              ( Int iWidth, Int iHeight, UInt iMaxCUWidth, UInt iMaxCUHeight, UChar uhTotalDepth );
+#endif
   Void    destroy             ();
   Void    init                ( TEncTop* pcEncTop );
@@ -119,4 +123,7 @@
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField );
+#if O0194_WEIGHTED_PREDICTION_CGS
+  Void    estimateILWpParam   ( TComSlice* pcSlice );
+#endif
 #else
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
Index: /trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 494)
@@ -88,11 +88,9 @@
   m_bMFMEnabledFlag = false;
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   m_numScaledRefLayerOffsets = 0;
-#endif
-#endif
 #if POC_RESET_FLAG
   m_pocAdjustmentValue     = 0;
 #endif
+#endif //SVC_EXTENSION
 }
 
@@ -117,5 +115,9 @@
   m_cGOPEncoder.        create();
 #endif
+#if AUXILIARY_PICTURES
+  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#else
   m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif
   m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
   if (m_bUseSAO)
@@ -175,4 +177,11 @@
     }
   }
+
+#if LAYER_CTB
+  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
+  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
+  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
+  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
+#endif
 }
 
@@ -601,5 +610,9 @@
     else
     {
+#if AUXILIARY_PICTURES
+      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#else
       rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
+#endif
     }
     rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
@@ -801,4 +814,13 @@
 #endif
 
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+      pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
+                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
+#else
+      pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
+                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
+#endif
+#else
 #if SVC_UPSAMPLING
       pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
@@ -807,4 +829,5 @@
       pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
+#endif
 #endif
       rpcPic = pcEPic;
@@ -842,4 +865,13 @@
 #endif
 
+#if AUXILIARY_PICTURES
+#if SVC_UPSAMPLING
+      rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
+#else
+      rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
+                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
+#endif
+#else
 #if SVC_UPSAMPLING
       rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
@@ -849,4 +881,5 @@
                       m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
 #endif
+#endif
     }
 
@@ -871,5 +904,4 @@
 #if SVC_EXTENSION
   m_cSPS.setLayerId(m_layerId);
-#endif
 #if REF_IDX_MFM
 #if !M0457_COL_PICTURE_SIGNALING
@@ -877,5 +909,4 @@
 #endif
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
   for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
@@ -883,5 +914,5 @@
     m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
   }
-#endif
+#endif //SVC_EXTENSION
   ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
   profileTierLevel.setLevelIdc(m_level);
@@ -914,4 +945,7 @@
   m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
   m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
+#if AUXILIARY_PICTURES
+  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
+#endif
 
   Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
@@ -1188,9 +1222,5 @@
   for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
   {
-#if FINAL_RPL_CHANGE_N0082
-    GOPEntry ge = m_ppcTEncTop[m_cSPS.getLayerId()]->getGOPEntry(i);
-#else
     GOPEntry ge = getGOPEntry(i);
-#endif
     rps = rpsList->getReferencePictureSet(i);
     rps->setNumberOfPictures(ge.m_numRefPics);
@@ -1536,5 +1566,4 @@
 #endif
 
-#if SVC_EXTENSION
 #if !REPN_FORMAT_IN_VPS
 Void TEncTop::xInitILRP()
@@ -1559,5 +1588,9 @@
         m_cIlpPic[j] = new  TComPic;
 #if SVC_UPSAMPLING
+#if AUXILIARY_PICTURES
+        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, 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, &m_cSPS, true);
+#endif
 #else
         m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
@@ -1611,5 +1644,9 @@
         m_cIlpPic[j] = new  TComPic;
 #if SVC_UPSAMPLING
+#if AUXILIARY_PICTURES
+        m_cIlpPic[j]->create(picWidth, picHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
+#else
         m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
+#endif
 #else
         m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
@@ -1624,25 +1661,4 @@
 }
 #endif
-Void TEncTop::setILRPic(TComPic *pcPic)
-{
-  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
-  {
-    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
-
-    if(m_cIlpPic[refLayerIdc])
-    {
-      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
-      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
-      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
-      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
-      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
-      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
-      {
-        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
-      }
-    }
-  }
-}
-#endif
-#endif
+#endif //SVC_EXTENSION
 //! \}
Index: /trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 494)
@@ -140,12 +140,10 @@
   Int                     m_ilSampleOnlyPred;
 #endif
-#if SCALED_REF_LAYER_OFFSETS
   UInt                    m_numScaledRefLayerOffsets;
   Window                  m_scaledRefLayerWindow[MAX_LAYERS];
-#endif
 #if POC_RESET_FLAG
   Int                     m_pocAdjustmentValue;
 #endif
-#endif
+#endif //SVC_EXTENSION
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -209,10 +207,8 @@
   Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
   Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
-#if SCALED_REF_LAYER_OFFSETS
   Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
   UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
   Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
-#endif
-#endif
+#endif //SVC_EXTENSION
 
   // -------------------------------------------------------------------------------------------------------------------
@@ -223,5 +219,4 @@
 #if SVC_EXTENSION
   TComPic** getIlpList() { return m_cIlpPic; }
-  Void      setILRPic(TComPic *pcPic);
 #if REF_IDX_MFM
   Void      setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
Index: /trunk/source/Lib/TLibEncoder/WeightPredAnalysis.cpp
===================================================================
--- /trunk/source/Lib/TLibEncoder/WeightPredAnalysis.cpp	(revision 493)
+++ /trunk/source/Lib/TLibEncoder/WeightPredAnalysis.cpp	(revision 494)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -51,5 +51,5 @@
   for ( Int iList =0 ; iList<2 ; iList++ )
   {
-    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
+    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     {
       for ( Int comp=0 ; comp<3 ;comp++ )
@@ -74,4 +74,8 @@
   TComPicYuv*   pPic = slice->getPic()->getPicYuvOrg();
   Int   iSample  = 0;
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Define here to assign the parameter of "iSample"
+  wpACDCParam weightACDCParam[3];
+#endif
 
   // calculate DC/AC value for Y
@@ -81,4 +85,7 @@
   pOrg = pPic->getLumaAddr();
   Int64  iOrgACY  = xCalcACValueSlice(slice, pOrg, iOrgNormDCY);
+#if O0194_WEIGHTED_PREDICTION_CGS
+  weightACDCParam[0].iSamples = iSample;
+#endif
 
   // calculate DC/AC value for Cb
@@ -88,4 +95,7 @@
   pOrg = pPic->getCbAddr();
   Int64  iOrgACCb  = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCb);
+#if O0194_WEIGHTED_PREDICTION_CGS
+  weightACDCParam[1].iSamples = iSample;
+#endif
 
   // calculate DC/AC value for Cr
@@ -95,6 +105,11 @@
   pOrg = pPic->getCrAddr();
   Int64  iOrgACCr  = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCr);
-
+#if O0194_WEIGHTED_PREDICTION_CGS
+  weightACDCParam[2].iSamples = iSample;
+#endif
+
+#if !O0194_WEIGHTED_PREDICTION_CGS
   wpACDCParam weightACDCParam[3];
+#endif
   weightACDCParam[0].iAC = iOrgACY;
   weightACDCParam[0].iDC = iOrgNormDCY;
@@ -138,7 +153,7 @@
   for ( Int iList=0 ; iList<2 ; iList++ )
   {
-    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
-    {
-      for ( Int iComp=0 ; iComp<3 ;iComp++ ) 
+    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
+    {
+      for ( Int iComp=0 ; iComp<3 ;iComp++ )
       {
         wpScalingParam  *pwp = &(m_wp[iList][iRefIdx][iComp]);
@@ -154,7 +169,7 @@
     for ( Int iList=0 ; iList<2 ; iList++ )
     {
-      for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
+      for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
       {
-        for ( Int iComp=0 ; iComp<3 ;iComp++ ) 
+        for ( Int iComp=0 ; iComp<3 ;iComp++ )
         {
           wpScalingParam  *pwp = &(m_wp[iList][iRefIdx][iComp]);
@@ -195,5 +210,5 @@
   // selecting whether WP is used, or not
   xSelectWP(slice, m_wp, iDenom);
-  
+
   slice->setWpScaling( m_wp );
 
@@ -216,4 +231,14 @@
       slice->getWpAcDcParam(currWeightACDCParam);
       slice->getRefPic(eRefPicList, refIdxTemp)->getSlice(0)->getWpAcDcParam(refWeightACDCParam);
+#if O0194_WEIGHTED_PREDICTION_CGS
+      UInt currLayerId = slice->getLayerId();
+      UInt refLayerId  = slice->getRefPic(eRefPicList, refIdxTemp)->getLayerId();
+      Bool validILRPic = slice->getRefPic(eRefPicList, refIdxTemp)->isILR( currLayerId ) && refLayerId == 0;
+
+      if( validILRPic )
+      {
+        refWeightACDCParam = (wpACDCParam *)g_refWeightACDCParam;
+      }
+#endif
 
       for ( Int comp = 0; comp < 3; comp++ )
@@ -229,4 +254,14 @@
         Int64 refDC = refWeightACDCParam[comp].iDC;
         Int64 refAC = refWeightACDCParam[comp].iAC;
+#if O0194_WEIGHTED_PREDICTION_CGS
+        if( validILRPic )
+        {
+          refAC = ( refAC * currWeightACDCParam[comp].iSamples ) /refWeightACDCParam[comp].iSamples;
+#if O0194_JOINT_US_BITSHIFT
+          refAC <<= (g_bitDepthYLayer[currLayerId]-g_bitDepthYLayer[refLayerId]);
+          refDC <<= (g_bitDepthYLayer[currLayerId]-g_bitDepthYLayer[refLayerId]);
+#endif
+        }
+#endif
 
         // calculating iWeight and iOffset params
@@ -234,4 +269,12 @@
         Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) );
         Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom );
+#if O0194_WEIGHTED_PREDICTION_CGS
+        if( !validILRPic )
+        {
+          dWeight = 1;
+          offset  = 0;
+        }
+        weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) );
+#endif
 
         // Chroma offset range limitation
@@ -253,4 +296,12 @@
         if(deltaWeight > 127 || deltaWeight < -128)
           return (false);
+#if O0194_WEIGHTED_PREDICTION_CGS
+        // make sure the reference frames other than ILR are not using weighted prediction
+        else
+        if( !validILRPic )
+        {
+          continue;
+        }
+#endif
 
         m_wp[refList][refIdxTemp][comp].bPresentFlag = true;
@@ -264,5 +315,5 @@
 }
 
-/** select whether weighted pred enables or not. 
+/** select whether weighted pred enables or not.
  * \param TComSlice *slice
  * \param wpScalingParam
@@ -325,5 +376,5 @@
 }
 
-/** calculate DC value of original image for luma. 
+/** calculate DC value of original image for luma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -345,5 +396,5 @@
 }
 
-/** calculate AC value of original image for luma. 
+/** calculate AC value of original image for luma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -363,5 +414,5 @@
 }
 
-/** calculate DC value of original image for chroma. 
+/** calculate DC value of original image for chroma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -383,5 +434,5 @@
 }
 
-/** calculate AC value of original image for chroma. 
+/** calculate AC value of original image for chroma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -401,5 +452,5 @@
 }
 
-/** calculate DC value. 
+/** calculate DC value.
  * \param Pel *pPel
  * \param Int iWidth
@@ -423,5 +474,5 @@
 }
 
-/** calculate AC value. 
+/** calculate AC value.
  * \param Pel *pPel
  * \param Int iWidth
@@ -446,5 +497,5 @@
 }
 
-/** calculate SAD values for both WP version and non-WP version. 
+/** calculate SAD values for both WP version and non-WP version.
  * \param Pel *pOrgPel
  * \param Pel *pRefPel
Index: /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
===================================================================
--- /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 493)
+++ /trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp	(revision 494)
@@ -473,5 +473,9 @@
   {
     dstPicYuv = new TComPicYuv;
+#if AUXILIARY_PICTURES
+    dstPicYuv->create( pPicYuv->getWidth(), pPicYuv->getHeight(), pPicYuv->getChromaFormat(), 1, 1, 0 );
+#else
     dstPicYuv->create( pPicYuv->getWidth(), pPicYuv->getHeight(), 1, 1, 0 );
+#endif
     pPicYuv->copyToPic(dstPicYuv);
 
@@ -567,9 +571,17 @@
   {
     dstPicTop = new TComPicYuv;
+#if AUXILIARY_PICTURES
+    dstPicTop->create( pPicTop->getWidth(), pPicTop->getHeight(), pPicTop->getChromaFormat(), 1, 1, 0 );
+#else
     dstPicTop->create( pPicTop->getWidth(), pPicTop->getHeight(), 1, 1, 0 );
+#endif
     pPicTop->copyToPic(dstPicTop);
     
     dstPicBottom = new TComPicYuv;
+#if AUXILIARY_PICTURES
+    dstPicBottom->create( pPicBottom->getWidth(), pPicBottom->getHeight(), pPicBottom->getChromaFormat(), 1, 1, 0 );
+#else
     dstPicBottom->create( pPicBottom->getWidth(), pPicBottom->getHeight(), 1, 1, 0 );
+#endif
     pPicBottom->copyToPic(dstPicBottom);
     
