Index: /branches/SHM-dev/cfg/misc/encoder_lowdelay_main_field_coding.cfg
===================================================================
--- /branches/SHM-dev/cfg/misc/encoder_lowdelay_main_field_coding.cfg	(revision 1460)
+++ /branches/SHM-dev/cfg/misc/encoder_lowdelay_main_field_coding.cfg	(revision 1460)
@@ -0,0 +1,139 @@
+#======== File I/O =====================
+InputFile                     :             # Input filename
+InputBitDepth                 :             # Input bitdepth
+FrameRate                     :             # Frame Rate per second
+FrameSkip                     :             # Number of frames to be skipped in input
+SourceWidth                   :             # Input  frame width
+SourceHeight                  :             # Input  frame height
+FramesToBeEncoded             :             # Number of frames to be coded
+FieldCoding                   : 1           # (0: Frame based coding, 1: Field based coding)
+TopFieldFirst                 : 1           # Field parity order (1: Top field first, 0: Bottom field first)
+ConformanceMode		          : 1
+
+BitstreamFile                 : str.bin
+ReconFile                     : rec.yuv
+
+#======== Profile/Level ================
+Profile                       : main
+Level                         : 6.2
+
+#======== SEI ===========================
+VuiParametersPresent          : 1
+SEIActiveParameterSets        : 1
+SEIPictureTiming              : 1
+FrameFieldInfoPresentFlag     : 1
+
+#======== Unit definition ================
+MaxCUWidth                    : 64          # Maximum coding unit width in pixel
+MaxCUHeight                   : 64          # Maximum coding unit height in pixel
+MaxPartitionDepth             : 4           # Maximum coding unit depth
+QuadtreeTULog2MaxSize         : 5           # Log2 of maximum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTULog2MinSize         : 2           # Log2 of minimum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTUMaxDepthInter       : 3
+QuadtreeTUMaxDepthIntra       : 3
+
+#======== Coding Structure =============
+IntraPeriod                   : 32          # Period of I-Frame ( -1 = only first)
+DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
+GOPSize                       : 8           # GOP Size (number of B slice = GOPSize-1)
+
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures     				predict deltaRPS #ref_idcs reference idcs 
+Frame1:  B    2   3        0.4624   0		 	 0 				0           8                8         -1 -2 -9 -10	-17 -18 -25 -26	    	0
+Frame2:  B    3   4        0.4624   0		 	 0 				0           8                9         -1 -2 -3 -10 -11 -18 -19 -26 -27	    1      	-1       9         1 1 1 1 1 1 1 1 1
+Frame3:  B    4   2        0.4624   0		 	 0 				0           8                8         -1 -2 -3 -4  -11 -12 -19 -20     	1      	-1       10        1 1 1 1 1 1 1 0 0 1          
+Frame4:  B    5   3        0.4624   0		 	 0 				0           8                9         -1 -2 -3 -4  -5  -12 -13 -20 -21   	1      	-1       9         1 1 1 1 1 1 1 1 1
+Frame5:  B    6   3        0.4624   0		 	 0 				0           8                8         -1 -2 -5 -6  -13 -14 -21 -22	    	1      	-1	     10   	   1 0 0 1 1 1 1 1 1 1
+Frame6:  B    7   4        0.4624   0		 	 0 				0           8                9         -1 -2 -3 -6  -7  -14 -15 -22 -23     1      	-1       9         1 1 1 1 1 1 1 1 1
+Frame7:  B    8   1        0.578    0		 	 0 				0           8                8         -1 -2 -7 -8  -15 -16 -23 -24     	1      	-1       10        1 0 0 1 1 1 1 1 1 1            
+Frame8:  B    9   1        0.578    0		 	 0 				0           8                9         -1 -2 -3 -8  -9  -16 -17 -24 -25     1      	-1       9         1 1 1 1 1 1 1 1 1
+
+#=========== Motion Search =============
+FastSearch                    : 1           # 0:Full search  1:TZ search
+SearchRange                   : 64          # (0: Search range is a Full frame)
+BipredSearchRange             : 4           # Search range for bi-prediction refinement
+HadamardME                    : 1           # Use of hadamard measure for fractional ME
+FEN                           : 1           # Fast encoder decision
+FDM                           : 1           # Fast Decision for Merge RD cost
+
+#======== Quantization =============
+QP                            : 32          # Quantization parameter(0-51)
+MaxDeltaQP                    : 0           # CU-based multi-QP optimization
+MaxCuDQPDepth                 : 0           # Max depth of a minimum CuDQP for sub-LCU-level delta QP
+DeltaQpRD                     : 0           # Slice-based multi-QP optimization
+RDOQ                          : 1           # RDOQ
+RDOQTS                        : 1           # RDOQ for transform skip
+
+#=========== Deblock Filter ============
+LoopFilterOffsetInPPS         : 1           # Dbl params: 0=varying params in SliceHeader, param = base_param + GOP_offset_param; 1=constant params in PPS, param = base_param)
+LoopFilterDisable             : 0           # Disable deblocking filter (0=Filter, 1=No Filter)
+LoopFilterBetaOffset_div2     : 0           # base_param: -6 ~ 6
+LoopFilterTcOffset_div2       : 0           # base_param: -6 ~ 6
+DeblockingFilterMetric        : 0           # blockiness metric (automatically configures deblocking parameters in bitstream)
+
+#=========== Misc. ============
+InternalBitDepth              : 8           # codec operating bit-depth
+
+#=========== Coding Tools =================
+SAO                           : 1           # Sample adaptive offset  (0: OFF, 1: ON)
+AMP                           : 1           # Asymmetric motion partitions (0: OFF, 1: ON)
+TransformSkip                 : 1           # Transform skipping (0: OFF, 1: ON)
+TransformSkipFast             : 1           # Fast Transform skipping (0: OFF, 1: ON)
+SAOLcuBoundary                : 0           # SAOLcuBoundary using non-deblocked pixels (0: OFF, 1: ON)
+
+#============ Slices ================
+SliceMode                : 0                # 0: Disable all slice options.
+                                            # 1: Enforce maximum number of LCU in an slice,
+                                            # 2: Enforce maximum number of bytes in an 'slice'
+                                            # 3: Enforce maximum number of tiles in a slice
+SliceArgument            : 1500             # Argument for 'SliceMode'.
+                                            # If SliceMode==1 it represents max. SliceGranularity-sized blocks per slice.
+                                            # If SliceMode==2 it represents max. bytes per slice.
+                                            # If SliceMode==3 it represents max. tiles per slice.
+
+LFCrossSliceBoundaryFlag : 1                # In-loop filtering, including ALF and DB, is across or not across slice boundary.
+                                            # 0:not across, 1: across
+
+#============ PCM ================
+PCMEnabledFlag                      : 0                # 0: No PCM mode
+PCMLog2MaxSize                      : 5                # Log2 of maximum PCM block size.
+PCMLog2MinSize                      : 3                # Log2 of minimum PCM block size.
+PCMInputBitDepthFlag                : 1                # 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
+PCMFilterDisableFlag                : 0                # 0: Enable loop filtering on I_PCM samples. 1: Disable loop filtering on I_PCM samples.
+
+#============ Tiles ================
+TileUniformSpacing                  : 0                # 0: the column boundaries are indicated by TileColumnWidth array, the row boundaries are indicated by TileRowHeight array
+                                                       # 1: the column and row boundaries are distributed uniformly
+NumTileColumnsMinus1                : 0                # Number of tile columns in a picture minus 1
+TileColumnWidthArray                : 2 3              # Array containing tile column width values in units of CTU (from left to right in picture)   
+NumTileRowsMinus1                   : 0                # Number of tile rows in a picture minus 1
+TileRowHeightArray                  : 2                # Array containing tile row height values in units of CTU (from top to bottom in picture)
+
+LFCrossTileBoundaryFlag           : 1                  # In-loop filtering is across or not across tile boundary.
+                                                       # 0:not across, 1: across                                                       
+
+#============ WaveFront ================
+WaveFrontSynchro                    : 0                # 0:  No WaveFront synchronisation (WaveFrontSubstreams must be 1 in this case).
+                                                       # >0: WaveFront synchronises with the LCU above and to the right by this many LCUs.
+
+#=========== Quantization Matrix =================
+ScalingList                   : 0                      # ScalingList 0 : off, 1 : default, 2 : file read
+ScalingListFile               : scaling_list.txt       # Scaling List file name. If file is not exist, use Default Matrix.
+
+#============ Lossless ================
+TransquantBypassEnableFlag          : 0                # Value of PPS flag.
+CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.
+
+#============ Rate Control ======================
+RateControl                         : 0                # Rate control: enable rate control
+TargetBitrate                       : 1000000          # Rate control: target bitrate, in bps
+KeepHierarchicalBit                 : 2                # Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation
+LCULevelRateControl                 : 1                # Rate control: 1: LCU level RC; 0: picture level RC
+RCLCUSeparateModel                  : 1                # Rate control: use LCU level separate R-lambda model
+InitialQP                           : 0                # Rate control: initial QP
+RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
+
Index: /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_2tids.cfg
===================================================================
--- /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_2tids.cfg	(revision 1460)
+++ /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_2tids.cfg	(revision 1460)
@@ -0,0 +1,120 @@
+#======== File I/O =====================
+BitstreamFile                 : str.bin
+ReconFile                     : rec.yuv
+
+#======== Profile ================
+Profile                       : main
+
+#======== Unit definition ================
+MaxCUWidth                    : 64          # Maximum coding unit width in pixel
+MaxCUHeight                   : 64          # Maximum coding unit height in pixel
+MaxPartitionDepth             : 4           # Maximum coding unit depth
+QuadtreeTULog2MaxSize         : 5           # Log2 of maximum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTULog2MinSize         : 2           # Log2 of minimum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTUMaxDepthInter       : 3
+QuadtreeTUMaxDepthIntra       : 3
+
+#======== Coding Structure =============
+IntraPeriod                   : 32          # Period of I-Frame ( -1 = only first)
+DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
+GOPSize                       : 8           # GOP Size (number of B slice = GOPSize-1)
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures     predict deltaRPS #ref_idcs reference idcs 
+Frame1:  B    8   1        0.442    0            0              0           4                4         -8 -10 -12 -16         0
+Frame2:  B    4   2        0.3536   0            0              0           2                3         -4 -6  4               1       4        5         1 1 0 0 1
+Frame3:  B    2   3        0.3536   0            0              0           2                4         -2 -4  2 6             1       2        4         1 1 1 1  
+Frame4:  B    1   4        0.68     0            0              1           2                4         -1  1  3 7             1       1        5         1 0 1 1 1 
+Frame5:  B    3   4        0.68     0            0              1           2                4         -1 -3  1 5             1      -2        5         1 1 1 1 0
+Frame6:  B    6   3        0.3536   0            0              0           2                4         -2 -4 -6 2             1      -3        5         1 1 1 1 0
+Frame7:  B    5   4        0.68     0            0              1           2                4         -1 -5  1 3             1       1        5         1 0 1 1 1  
+Frame8:  B    7   4        0.68     0            0              1           2                4         -1 -3 -7 1             1      -2        5         1 1 1 1 0
+
+#=========== Motion Search =============
+FastSearch                    : 1           # 0:Full search  1:TZ search
+SearchRange                   : 64          # (0: Search range is a Full frame)
+BipredSearchRange             : 4           # Search range for bi-prediction refinement
+HadamardME                    : 1           # Use of hadamard measure for fractional ME
+FEN                           : 1           # Fast encoder decision
+FDM                           : 1           # Fast Decision for Merge RD cost
+
+#======== Quantization =============
+QP                            : 32          # Quantization parameter(0-51)
+MaxDeltaQP                    : 0           # CU-based multi-QP optimization
+MaxCuDQPDepth                 : 0           # Max depth of a minimum CuDQP for sub-LCU-level delta QP
+DeltaQpRD                     : 0           # Slice-based multi-QP optimization
+RDOQ                          : 1           # RDOQ
+RDOQTS                        : 1           # RDOQ for transform skip
+
+#=========== Deblock Filter ============
+LoopFilterOffsetInPPS         : 1           # Dbl params: 0=varying params in SliceHeader, param = base_param + GOP_offset_param; 1=constant params in PPS, param = base_param)
+LoopFilterDisable             : 0           # Disable deblocking filter (0=Filter, 1=No Filter)
+LoopFilterBetaOffset_div2     : 0           # base_param: -6 ~ 6
+LoopFilterTcOffset_div2       : 0           # base_param: -6 ~ 6
+DeblockingFilterMetric        : 0           # blockiness metric (automatically configures deblocking parameters in bitstream)
+
+#=========== Misc. ============
+InternalBitDepth              : 8           # codec operating bit-depth
+
+#=========== Coding Tools =================
+SAO                           : 1           # Sample adaptive offset  (0: OFF, 1: ON)
+AMP                           : 1           # Asymmetric motion partitions (0: OFF, 1: ON)
+TransformSkip                 : 1           # Transform skipping (0: OFF, 1: ON)
+TransformSkipFast             : 1           # Fast Transform skipping (0: OFF, 1: ON)
+SAOLcuBoundary                : 0           # SAOLcuBoundary using non-deblocked pixels (0: OFF, 1: ON)
+
+#============ Slices ================
+SliceMode                : 0                # 0: Disable all slice options.
+                                            # 1: Enforce maximum number of LCU in an slice,
+                                            # 2: Enforce maximum number of bytes in an 'slice'
+                                            # 3: Enforce maximum number of tiles in a slice
+SliceArgument            : 1500             # Argument for 'SliceMode'.
+                                            # If SliceMode==1 it represents max. SliceGranularity-sized blocks per slice.
+                                            # If SliceMode==2 it represents max. bytes per slice.
+                                            # If SliceMode==3 it represents max. tiles per slice.
+
+LFCrossSliceBoundaryFlag : 1                # In-loop filtering, including ALF and DB, is across or not across slice boundary.
+                                            # 0:not across, 1: across
+
+#============ PCM ================
+PCMEnabledFlag                      : 0                # 0: No PCM mode
+PCMLog2MaxSize                      : 5                # Log2 of maximum PCM block size.
+PCMLog2MinSize                      : 3                # Log2 of minimum PCM block size.
+PCMInputBitDepthFlag                : 1                # 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
+PCMFilterDisableFlag                : 0                # 0: Enable loop filtering on I_PCM samples. 1: Disable loop filtering on I_PCM samples.
+
+#============ Tiles ================
+TileUniformSpacing                  : 0                # 0: the column boundaries are indicated by TileColumnWidth array, the row boundaries are indicated by TileRowHeight array
+                                                       # 1: the column and row boundaries are distributed uniformly
+NumTileColumnsMinus1                : 0                # Number of tile columns in a picture minus 1
+TileColumnWidthArray                : 2 3              # Array containing tile column width values in units of CTU (from left to right in picture)   
+NumTileRowsMinus1                   : 0                # Number of tile rows in a picture minus 1
+TileRowHeightArray                  : 2                # Array containing tile row height values in units of CTU (from top to bottom in picture)
+
+LFCrossTileBoundaryFlag             : 1                # In-loop filtering is across or not across tile boundary.
+                                                       # 0:not across, 1: across 
+
+#============ WaveFront ================
+WaveFrontSynchro                    : 0                # 0:  No WaveFront synchronisation (WaveFrontSubstreams must be 1 in this case).
+                                                       # >0: WaveFront synchronises with the LCU above and to the right by this many LCUs.
+
+#=========== Quantization Matrix =================
+ScalingList                   : 0                      # ScalingList 0 : off, 1 : default, 2 : file read
+ScalingListFile               : scaling_list.txt       # Scaling List file name. If file is not exist, use Default Matrix.
+
+#============ Lossless ================
+TransquantBypassEnableFlag : 0                         # Value of PPS flag.
+CUTransquantBypassFlagForce: 0                         # Force transquant bypass mode, when transquant_bypass_enable_flag is enabled
+
+#============ Rate Control ======================
+RateControl                         : 0                # Rate control: enable rate control
+TargetBitrate                       : 1000000          # Rate control: target bitrate, in bps
+KeepHierarchicalBit                 : 2                # Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation
+LCULevelRateControl                 : 1                # Rate control: 1: LCU level RC; 0: picture level RC
+RCLCUSeparateModel                  : 1                # Rate control: use LCU level separate R-lambda model
+InitialQP                           : 0                # Rate control: initial QP
+RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
+
Index: /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_field_coding.cfg
===================================================================
--- /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_field_coding.cfg	(revision 1460)
+++ /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_field_coding.cfg	(revision 1460)
@@ -0,0 +1,151 @@
+#======== File I/O =====================
+InputFile                     :             # Input filename
+InputBitDepth                 :             # Input bitdepth
+FrameRate                     :             # Frame Rate per second
+FrameSkip                     : 	        # Number of frames to be skipped in input
+SourceWidth                   :     	    # Input  frame width
+SourceHeight                  : 	        # Input  frame height
+FramesToBeEncoded             :             # Number of frames to be coded
+FieldCoding					  : 1			#(0: Frame based coding, 1: Field based coding)
+TopFieldFirst				  : 1			# Field parity order (1: Top field first, 0: Bottom field first)
+ConformanceMode				  : 1
+
+BitstreamFile                 : str.bin
+ReconFile                     : rec.yuv
+
+#======== Profile/Level ================
+Profile                       : main
+Level                         : 6.2
+
+#======== SEI ===========================
+VuiParametersPresent          : 1
+SEIActiveParameterSets        : 1
+SEIPictureTiming              : 1
+FrameFieldInfoPresentFlag     : 1
+
+#======== Unit definition ================
+MaxCUWidth                    : 64          # Maximum coding unit width in pixel
+MaxCUHeight                   : 64          # Maximum coding unit height in pixel
+MaxPartitionDepth             : 4           # Maximum coding unit depth
+QuadtreeTULog2MaxSize         : 5           # Log2 of maximum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTULog2MinSize         : 2           # Log2 of minimum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTUMaxDepthInter       : 3
+QuadtreeTUMaxDepthIntra       : 3
+
+#======== Coding Structure =============
+IntraPeriod                   : 32          # Period of I-Frame ( -1 = only first)
+DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
+GOPSize                       : 16          # GOP Size (number of B slice = GOPSize-1)
+
+# field coding GOP: Exchanged coding order of 16th and 17th field for more efficient encoding
+#                   When EfficientFieldIRAPEnabled=1 is enabled, this has no additional effect
+
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics  reference pictures   predict deltaRPS #ref_idcs reference idcs 
+              
+Frame1:  B    17  1        0.442    0		 	 0 				0           4                4         -16 -17 -20 -21        0
+Frame2:  B    16  1        0.442    0		 	 0 				0           3                3         -15 -16 1              1       1        5         1 1 0 0 1
+Frame3:  B    8   2        0.3536   0		 	 0 				0           2                4         -7 -8 8 9              1       8        4         1 1 1 1
+Frame4:  B    9   2        0.3536   0		 	 0 				0           2                5         -1 -8 -9 7 8           1      -1        5         1 1 1 1 1
+Frame5:  B    4   3        0.3536   0		 	 0 				0           2                6         -3 -4 4 5 12 13        1       5        6         1 1 1 1 1 1
+Frame6:  B    5   3        0.3536   0		 	 0 				0           2                7         -1 -4 -5 3 4 11 12     1      -1        7         1 1 1 1 1 1 1 
+Frame7:  B    2   3        0.3536   0		 	 0 				0           2                8         -1 -2 2 3 6 7 14 15    1       3        8         1 1 1 1 1 1 1 1  
+Frame8:  B    3   4        0.68     0		 	 0 				0           2                8         -1 -2 1 2 5 6 13 14    1      -1        9         1 0 1 1 1 1 1 1 1 
+Frame9:  B    6   3        0.3536   0		 	 0 				0           2                6         -1 -2 2 3 10 11        1      -3        9         0 0 1 1 1 1 1 1 0
+Frame10: B    7   4        0.68     0		 	 0 				0           2                7         -1 -2 -3 1 2 9 10      1      -1        7         1 1 1 1 1 1 1 
+Frame11: B    12  3        0.3536   0		 	 0 				0           2                4         -3 -4 4 5              1      -5        8         0 0 0 1 1 1 1 0
+Frame12: B    13  3        0.3536   0		 	 0 				0           2                5         -1 -4 -5 3 4           1      -1        5         1 1 1 1 1
+Frame13: B    10  3        0.3536   0		 	 0 				0           2                6         -1 -2 2 3 6 7          1       3        6         1 1 1 1 1 1
+Frame14: B    11  4        0.68     0		 	 0 				0           2                7         -1 -2 -3 1 2 5 6       1      -1        7         1 1 1 1 1 1 1
+Frame15: B    14  3        0.3536   0			 0 				0           2                5         -1 -2 -5 2 3           1      -3        8         0 1 0 1 1 1 1 0
+Frame16: B    15  4        0.68     0			 0 				0           2                6         -1 -2 -3 -6 1 2        1      -1        6         1 1 1 1 1 1 
+
+#=========== Motion Search =============
+FastSearch                    : 1           # 0:Full search  1:TZ search
+SearchRange                   : 64          # (0: Search range is a Full frame)
+BipredSearchRange             : 4           # Search range for bi-prediction refinement
+HadamardME                    : 1           # Use of hadamard measure for fractional ME
+FEN                           : 1           # Fast encoder decision
+FDM                           : 1           # Fast Decision for Merge RD cost
+
+#======== Quantization =============
+QP                            : 32          # Quantization parameter(0-51)
+MaxDeltaQP                    : 0           # CU-based multi-QP optimization
+MaxCuDQPDepth                 : 0           # Max depth of a minimum CuDQP for sub-LCU-level delta QP
+DeltaQpRD                     : 0           # Slice-based multi-QP optimization
+RDOQ                          : 1           # RDOQ
+RDOQTS                        : 1           # RDOQ for transform skip
+
+#=========== Deblock Filter ============
+LoopFilterOffsetInPPS         : 1           # Dbl params: 0=varying params in SliceHeader, param = base_param + GOP_offset_param; 1=constant params in PPS, param = base_param)
+LoopFilterDisable             : 0           # Disable deblocking filter (0=Filter, 1=No Filter)
+LoopFilterBetaOffset_div2     : 0           # base_param: -6 ~ 6
+LoopFilterTcOffset_div2       : 0           # base_param: -6 ~ 6
+DeblockingFilterMetric        : 0           # blockiness metric (automatically configures deblocking parameters in bitstream)
+
+#=========== Misc. ============
+InternalBitDepth              : 8           # codec operating bit-depth
+
+#=========== Coding Tools =================
+SAO                           : 1           # Sample adaptive offset  (0: OFF, 1: ON)
+AMP                           : 1           # Asymmetric motion partitions (0: OFF, 1: ON)
+TransformSkip                 : 1           # Transform skipping (0: OFF, 1: ON)
+TransformSkipFast             : 1           # Fast Transform skipping (0: OFF, 1: ON)
+SAOLcuBoundary                : 0           # SAOLcuBoundary using non-deblocked pixels (0: OFF, 1: ON)
+
+#============ Slices ================
+SliceMode                : 0                # 0: Disable all slice options.
+                                            # 1: Enforce maximum number of LCU in an slice,
+                                            # 2: Enforce maximum number of bytes in an 'slice'
+                                            # 3: Enforce maximum number of tiles in a slice
+SliceArgument            : 1500             # Argument for 'SliceMode'.
+                                            # If SliceMode==1 it represents max. SliceGranularity-sized blocks per slice.
+                                            # If SliceMode==2 it represents max. bytes per slice.
+                                            # If SliceMode==3 it represents max. tiles per slice.
+
+LFCrossSliceBoundaryFlag : 1                # In-loop filtering, including ALF and DB, is across or not across slice boundary.
+                                            # 0:not across, 1: across
+
+#============ PCM ================
+PCMEnabledFlag                      : 0                # 0: No PCM mode
+PCMLog2MaxSize                      : 5                # Log2 of maximum PCM block size.
+PCMLog2MinSize                      : 3                # Log2 of minimum PCM block size.
+PCMInputBitDepthFlag                : 1                # 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
+PCMFilterDisableFlag                : 0                # 0: Enable loop filtering on I_PCM samples. 1: Disable loop filtering on I_PCM samples.
+
+#============ Tiles ================
+TileUniformSpacing                  : 0                # 0: the column boundaries are indicated by TileColumnWidth array, the row boundaries are indicated by TileRowHeight array
+                                                       # 1: the column and row boundaries are distributed uniformly
+NumTileColumnsMinus1                : 0                # Number of tile columns in a picture minus 1
+TileColumnWidthArray                : 2 3              # Array containing tile column width values in units of CTU (from left to right in picture)   
+NumTileRowsMinus1                   : 0                # Number of tile rows in a picture minus 1
+TileRowHeightArray                  : 2                # Array containing tile row height values in units of CTU (from top to bottom in picture)
+
+LFCrossTileBoundaryFlag             : 1                # In-loop filtering is across or not across tile boundary.
+                                                       # 0:not across, 1: across 
+
+#============ WaveFront ================
+WaveFrontSynchro                    : 0                # 0:  No WaveFront synchronisation (WaveFrontSubstreams must be 1 in this case).
+                                                       # >0: WaveFront synchronises with the LCU above and to the right by this many LCUs.
+
+#=========== Quantization Matrix =================
+ScalingList                   : 0                      # ScalingList 0 : off, 1 : default, 2 : file read
+ScalingListFile               : scaling_list.txt       # Scaling List file name. If file is not exist, use Default Matrix.
+
+#============ Lossless ================
+TransquantBypassEnableFlag: 0  # Value of PPS flag.
+CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.
+
+#============ Rate Control ======================
+RateControl                         : 0                # Rate control: enable rate control
+TargetBitrate                       : 1000000          # Rate control: target bitrate, in bps
+KeepHierarchicalBit                 : 2                # Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation
+LCULevelRateControl                 : 1                # Rate control: 1: LCU level RC; 0: picture level RC
+RCLCUSeparateModel                  : 1                # Rate control: use LCU level separate R-lambda model
+InitialQP                           : 0                # Rate control: initial QP
+RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
+
Index: /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_field_coding_simple_GOP.cfg
===================================================================
--- /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_field_coding_simple_GOP.cfg	(revision 1460)
+++ /branches/SHM-dev/cfg/misc/encoder_randomaccess_main_field_coding_simple_GOP.cfg	(revision 1460)
@@ -0,0 +1,150 @@
+#======== File I/O =====================
+InputFile                     :             # Input filename
+InputBitDepth                 :             # Input bitdepth
+FrameRate                     :             # Frame Rate per second
+FrameSkip                     : 	        # Number of frames to be skipped in input
+SourceWidth                   :     	    # Input  frame width
+SourceHeight                  : 	        # Input  frame height
+FramesToBeEncoded             :             # Number of frames to be coded
+FieldCoding					  : 1			#(0: Frame based coding, 1: Field based coding)
+TopFieldFirst				  : 1			# Field parity order (1: Top field first, 0: Bottom field first)
+ConformanceMode				  : 1
+
+BitstreamFile                 : str.bin
+ReconFile                     : rec.yuv
+
+#======== Profile/Level ================
+Profile                       : main
+Level                         : 6.2
+
+#======== SEI ===========================
+VuiParametersPresent          : 1
+SEIActiveParameterSets        : 1
+SEIPictureTiming              : 1
+FrameFieldInfoPresentFlag     : 1
+
+#======== Unit definition ================
+MaxCUWidth                    : 64          # Maximum coding unit width in pixel
+MaxCUHeight                   : 64          # Maximum coding unit height in pixel
+MaxPartitionDepth             : 4           # Maximum coding unit depth
+QuadtreeTULog2MaxSize         : 5           # Log2 of maximum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTULog2MinSize         : 2           # Log2 of minimum transform size for
+                                            # quadtree-based TU coding (2...6)
+QuadtreeTUMaxDepthInter       : 3
+QuadtreeTUMaxDepthIntra       : 3
+
+#======== Coding Structure =============
+IntraPeriod                   : 32          # Period of I-Frame ( -1 = only first)
+DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
+GOPSize                       : 16          # GOP Size (number of B slice = GOPSize-1)
+
+# simple field coding GOP: When EfficientFieldIRAPEnabled=1 is enabled, the order of frames 16 and 17 is exchanged
+
+#        Type POC QPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics  reference pictures   predict deltaRPS #ref_idcs reference idcs 
+              
+Frame1:  B    16  1        0.442    0            0              0           8                8         -15 -16 -19 -20 -23 -24 -31 -32        0
+Frame2:  B    17  1        0.442    0            0              0           4                9         -1  -16 -17 -20 -21 -24 -25 -32 -33    1      -1        9         1 1 1 1 1 1 1 1 1
+Frame3:  B    8   2        0.3536   0            0              0           4                6         -7  -8  -11 -12  8   9                 1       9        10        1 1 1 1 1 0 0 0 0 1
+Frame4:  B    9   3        0.3536   0            0              0           4                7         -1  -8  -9  -12 -13  7   8             1      -1        7         1 1 1 1 1 1 1
+Frame5:  B    4   3        0.3536   0            0              0           4                8         -3  -4  -7  -8   4   5   12  13        1       5        8         1 1 1 1 1 1 1 1
+Frame6:  B    5   4        0.68     0            0              0           4                9         -1  -4  -5  -8  -9   3   4   11  12    1      -1        9         1 1 1 1 1 1 1 1 1 
+Frame7:  B    2   3        0.3536   0            0              0           4                8         -1  -2   2   3   6   7   14  15        1       3        10        1 1 1 0 0 1 1 1 1 1  
+Frame8:  B    3   4        0.68     0            0              0           4                9         -1  -2  -3   1   2   5   6   13  14    1      -1        9         1 1 1 1 1 1 1 1 1 
+Frame9:  B    6   3        0.3536   0            0              0           4                8         -1  -2  -5  -6   2   3   10  11        1      -3        10        0 1 1 1 1 1 1 1 1 0
+Frame10: B    7   4        0.68     0            0              0           4                9         -1  -2  -3  -6  -7   1   2   9   10    1      -1        9         1 1 1 1 1 1 1 1 1 
+Frame11: B    12  3        0.3536   0            0              0           4                8         -3  -4  -7  -8  -11 -12  4   5         1      -5        10        0 1 1 1 1 1 1 1 1 0
+Frame12: B    13  4        0.68     0            0              0           4                9         -1  -4  -5  -8  -9  -12 -13  3   4     1      -1        9         1 1 1 1 1 1 1 1 1
+Frame13: B    10  3        0.3536   0            0              0           4                8         -1  -2  -9  -10  2   3   6   7         1       3        10        1 1 1 0 0 1 1 1 1 1
+Frame14: B    11  4        0.68     0            0              0           4                9         -1  -2  -3  -10 -11  1   2   5   6     1      -1        9         1 1 1 1 1 1 1 1 1
+Frame15: B    14  3        0.3536   0            0              0           4                8         -1  -2  -5  -6  -13 -14  2   3         1      -3        10        0 1 1 1 1 1 1 1 1 0
+Frame16: B    15  4        0.68     0            0              0           4                9         -1  -2  -3  -6  -7  -14 -15  1   2     1      -1        9         1 1 1 1 1 1 1 1 1  
+
+#=========== Motion Search =============
+FastSearch                    : 1           # 0:Full search  1:TZ search
+SearchRange                   : 64          # (0: Search range is a Full frame)
+BipredSearchRange             : 4           # Search range for bi-prediction refinement
+HadamardME                    : 1           # Use of hadamard measure for fractional ME
+FEN                           : 1           # Fast encoder decision
+FDM                           : 1           # Fast Decision for Merge RD cost
+
+#======== Quantization =============
+QP                            : 32          # Quantization parameter(0-51)
+MaxDeltaQP                    : 0           # CU-based multi-QP optimization
+MaxCuDQPDepth                 : 0           # Max depth of a minimum CuDQP for sub-LCU-level delta QP
+DeltaQpRD                     : 0           # Slice-based multi-QP optimization
+RDOQ                          : 1           # RDOQ
+RDOQTS                        : 1           # RDOQ for transform skip
+
+#=========== Deblock Filter ============
+LoopFilterOffsetInPPS         : 1           # Dbl params: 0=varying params in SliceHeader, param = base_param + GOP_offset_param; 1=constant params in PPS, param = base_param)
+LoopFilterDisable             : 0           # Disable deblocking filter (0=Filter, 1=No Filter)
+LoopFilterBetaOffset_div2     : 0           # base_param: -6 ~ 6
+LoopFilterTcOffset_div2       : 0           # base_param: -6 ~ 6
+DeblockingFilterMetric        : 0           # blockiness metric (automatically configures deblocking parameters in bitstream)
+
+#=========== Misc. ============
+InternalBitDepth              : 8           # codec operating bit-depth
+
+#=========== Coding Tools =================
+SAO                           : 1           # Sample adaptive offset  (0: OFF, 1: ON)
+AMP                           : 1           # Asymmetric motion partitions (0: OFF, 1: ON)
+TransformSkip                 : 1           # Transform skipping (0: OFF, 1: ON)
+TransformSkipFast             : 1           # Fast Transform skipping (0: OFF, 1: ON)
+SAOLcuBoundary                : 0           # SAOLcuBoundary using non-deblocked pixels (0: OFF, 1: ON)
+
+#============ Slices ================
+SliceMode                : 0                # 0: Disable all slice options.
+                                            # 1: Enforce maximum number of LCU in an slice,
+                                            # 2: Enforce maximum number of bytes in an 'slice'
+                                            # 3: Enforce maximum number of tiles in a slice
+SliceArgument            : 1500             # Argument for 'SliceMode'.
+                                            # If SliceMode==1 it represents max. SliceGranularity-sized blocks per slice.
+                                            # If SliceMode==2 it represents max. bytes per slice.
+                                            # If SliceMode==3 it represents max. tiles per slice.
+
+LFCrossSliceBoundaryFlag : 1                # In-loop filtering, including ALF and DB, is across or not across slice boundary.
+                                            # 0:not across, 1: across
+
+#============ PCM ================
+PCMEnabledFlag                      : 0                # 0: No PCM mode
+PCMLog2MaxSize                      : 5                # Log2 of maximum PCM block size.
+PCMLog2MinSize                      : 3                # Log2 of minimum PCM block size.
+PCMInputBitDepthFlag                : 1                # 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
+PCMFilterDisableFlag                : 0                # 0: Enable loop filtering on I_PCM samples. 1: Disable loop filtering on I_PCM samples.
+
+#============ Tiles ================
+TileUniformSpacing                  : 0                # 0: the column boundaries are indicated by TileColumnWidth array, the row boundaries are indicated by TileRowHeight array
+                                                       # 1: the column and row boundaries are distributed uniformly
+NumTileColumnsMinus1                : 0                # Number of tile columns in a picture minus 1
+TileColumnWidthArray                : 2 3              # Array containing tile column width values in units of CTU (from left to right in picture)   
+NumTileRowsMinus1                   : 0                # Number of tile rows in a picture minus 1
+TileRowHeightArray                  : 2                # Array containing tile row height values in units of CTU (from top to bottom in picture)
+
+LFCrossTileBoundaryFlag           : 1                  # In-loop filtering is across or not across tile boundary.
+                                                       # 0:not across, 1: across                                                       
+
+#============ WaveFront ================
+WaveFrontSynchro                    : 0                # 0:  No WaveFront synchronisation (WaveFrontSubstreams must be 1 in this case).
+                                                       # >0: WaveFront synchronises with the LCU above and to the right by this many LCUs.
+
+#=========== Quantization Matrix =================
+ScalingList                   : 0                      # ScalingList 0 : off, 1 : default, 2 : file read
+ScalingListFile               : scaling_list.txt       # Scaling List file name. If file is not exist, use Default Matrix.
+
+#============ Lossless ================
+TransquantBypassEnableFlag: 0  # Value of PPS flag.
+CUTransquantBypassFlagForce: 0 # Constant lossless-value signaling per CU, if TransquantBypassEnableFlag is 1.
+
+#============ Rate Control ======================
+RateControl                         : 0                # Rate control: enable rate control
+TargetBitrate                       : 1000000          # Rate control: target bitrate, in bps
+KeepHierarchicalBit                 : 2                # Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation
+LCULevelRateControl                 : 1                # Rate control: 1: LCU level RC; 0: picture level RC
+RCLCUSeparateModel                  : 1                # Rate control: use LCU level separate R-lambda model
+InitialQP                           : 0                # Rate control: initial QP
+RCForceIntraQP                      : 0                # Rate control: force intra QP to be equal to initial QP
+
+### DO NOT ADD ANYTHING BELOW THIS LINE ###
+### DO NOT DELETE THE EMPTY LINE BELOW ###
+
Index: /branches/SHM-dev/cfg/misc/example_colour_remapping_sei_encoder_0.txt
===================================================================
--- /branches/SHM-dev/cfg/misc/example_colour_remapping_sei_encoder_0.txt	(revision 1460)
+++ /branches/SHM-dev/cfg/misc/example_colour_remapping_sei_encoder_0.txt	(revision 1460)
@@ -0,0 +1,54 @@
+# Example colour remapping information SEI configuration file
+# One of these is required per POC, with the POC number used in the filename suffix.
+
+colour_remap_id: 1
+colour_remap_cancel_flag: 0
+colour_remap_persistence_flag: 1
+colour_remap_video_signal_info_present_flag: 1
+colour_remap_full_range_flag: 0
+colour_remap_primaries: 1
+colour_remap_transfer_function: 1
+colour_remap_matrix_coefficients: 1
+
+colour_remap_input_bit_depth: 10
+colour_remap_bit_depth: 10
+
+pre_lut_num_val_minus1[c]: 1
+pre_lut_coded_value[c][i]: 0     pre_lut_target_value[c][i]: 0
+pre_lut_coded_value[c][i]: 1023  pre_lut_target_value[c][i]: 1023
+
+pre_lut_num_val_minus1[c]: 1
+pre_lut_coded_value[c][i]: 0     pre_lut_target_value[c][i]: 0
+pre_lut_coded_value[c][i]: 1023  pre_lut_target_value[c][i]: 1023
+
+pre_lut_num_val_minus1[c]: 1
+pre_lut_coded_value[c][i]: 0     pre_lut_target_value[c][i]: 0
+pre_lut_coded_value[c][i]: 1023  pre_lut_target_value[c][i]: 1023
+
+colour_remap_matrix_present_flag: 1
+log2_matrix_denom: 10
+colour_remap_coeffs[c][i]: 1024
+colour_remap_coeffs[c][i]: 0
+colour_remap_coeffs[c][i]: 0
+
+colour_remap_coeffs[c][i]: 0
+colour_remap_coeffs[c][i]: 1024
+colour_remap_coeffs[c][i]: 0
+
+colour_remap_coeffs[c][i]: 0
+colour_remap_coeffs[c][i]: 0
+colour_remap_coeffs[c][i]: 1024
+
+post_lut_num_val_minus1[c]: 3
+post_lut_coded_value[c][i]: 0    post_lut_target_value[c][i]: 0
+post_lut_coded_value[c][i]: 200  post_lut_target_value[c][i]: 100
+post_lut_coded_value[c][i]: 800  post_lut_target_value[c][i]: 900
+post_lut_coded_value[c][i]: 1023 post_lut_target_value[c][i]: 1023
+
+post_lut_num_val_minus1[c]: 1
+post_lut_coded_value[c][i]:    0 post_lut_target_value[c][i]:    0
+post_lut_coded_value[c][i]: 1023 post_lut_target_value[c][i]: 1023
+
+post_lut_num_val_minus1[c]: 1
+post_lut_coded_value[c][i]:    0 post_lut_target_value[c][i]:    0
+post_lut_coded_value[c][i]: 1023 post_lut_target_value[c][i]: 1023
Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 1460)
@@ -113,4 +113,7 @@
   ("TarDecLayerIdSetFile,l",    cfg_TargetDecLayerIdSetFile,           string(""), "targetDecLayerIdSet file name. The file should include white space separated LayerId values to be decoded. Omitting the option or a value of -1 in the file decodes all layers.")
   ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
+#if Q0074_COLOUR_REMAPPING_SEI
+  ("SEIColourRemappingInfoFilename",  m_colourRemapSEIFileName,        string(""), "Colour Remapping YUV output file name. If empty, no remapping is applied (ignore SEI message)\n")
+#endif
 #if O0043_BEST_EFFORT_DECODING
   ("ForceDecodeBitDepth",       m_forceDecodeBitDepth,                 0U,         "Force the decoder to operate at a particular bit-depth (best effort decoding)")
@@ -118,9 +121,4 @@
   ("OutputDecodedSEIMessagesFilename",  m_outputDecodedSEIMessagesFilename,    string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
   ("ClipOutputVideoToRec709Range",      m_bClipOutputVideoToRec709Range,  false, "If true then clip output video to the Rec. 709 Range on saving")
-#if Q0074_COLOUR_REMAPPING_SEI
-  ("SEIColourRemappingInfo,-cri", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"
-                                              "\t1: apply colour remapping on decoded pictures if available in the bitstream\n"
-                                              "\t0: ignore SEI message")
-#endif
   ;
 
Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h	(revision 1460)
@@ -71,7 +71,6 @@
   Bool          m_decodedNoDisplaySEIEnabled;         ///< Enable(true)/disable(false) writing only pictures that get displayed based on the no display SEI message
 #if Q0074_COLOUR_REMAPPING_SEI
-  Bool          m_colourRemapSEIEnabled;              ///< Enable the Colour Remapping Information SEI message if available (remapping decoded pictures)
+  std::string   m_colourRemapSEIFileName;             ///< output Colour Remapping file name
 #endif
-
   std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
   Int           m_respectDefDispWindow;               ///< Only output content inside the default display window
@@ -110,5 +109,5 @@
   , m_decodedNoDisplaySEIEnabled(false)
 #if Q0074_COLOUR_REMAPPING_SEI
-  , m_colourRemapSEIEnabled(false)
+  , m_colourRemapSEIFileName()
 #endif
   , m_targetDecLayerIdSet()
Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1460)
@@ -63,5 +63,6 @@
 TAppDecTop::TAppDecTop()
 #if Q0074_COLOUR_REMAPPING_SEI
-: seiColourRemappingInfoPrevious(NULL)
+: m_pcSeiColourRemappingInfoPrevious(NULL)
+, m_pcPicYuvColourRemapped(NULL)
 #endif
 {
@@ -78,5 +79,6 @@
 : m_iPOCLastDisplay(-MAX_INT)
 #if Q0074_COLOUR_REMAPPING_SEI
-, seiColourRemappingInfoPrevious(NULL)
+ ,m_pcSeiColourRemappingInfoPrevious(NULL)
+ ,m_pcPicYuvColourRemapped(NULL)
 #endif
 {
@@ -117,10 +119,4 @@
 #else
   m_reconFileName.clear();
-#endif
-#if Q0074_COLOUR_REMAPPING_SEI
-  if (seiColourRemappingInfoPrevious != NULL)
-  {
-    delete seiColourRemappingInfoPrevious;
-  }
 #endif
 }
@@ -688,4 +684,17 @@
   }
 #endif
+#if Q0074_COLOUR_REMAPPING_SEI
+  if (m_pcSeiColourRemappingInfoPrevious != NULL)
+  {
+    delete m_pcSeiColourRemappingInfoPrevious;
+    m_pcSeiColourRemappingInfoPrevious = NULL;
+  }
+  if (m_pcPicYuvColourRemapped != NULL)
+  {
+    m_pcPicYuvColourRemapped->destroy();
+    delete m_pcPicYuvColourRemapped;
+    m_pcPicYuvColourRemapped  = NULL;
+  }
+#endif
 }
 
@@ -919,38 +928,7 @@
 
 #if Q0074_COLOUR_REMAPPING_SEI
-        if (m_colourRemapSEIEnabled)
-        {
-          SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
-          const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
-          const TComSPS *sps = pcPic->getSlice(0)->getSPS();
-
-          if (colourRemappingInfo.size() > 1)
-          {
-            printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
-          }
-          if (seiColourRemappingInfo)
-          {
-            xApplyColourRemapping(sps, *pcPic->getPicYuvRec(), seiColourRemappingInfo);
-          }
-          else  // using the last CRI SEI received
-          {
-            const SEIColourRemappingInfo *seiColourRemappingInfoCopy;
-            seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious;
-            xApplyColourRemapping(sps, *pcPic->getPicYuvRec(), seiColourRemappingInfoCopy);
-          }
-
-          // save the last CRI SEI received
-          if( seiColourRemappingInfo != NULL){
-            if (seiColourRemappingInfoPrevious != NULL)
-            {
-              delete seiColourRemappingInfoPrevious;
-              seiColourRemappingInfoPrevious = NULL;
-            }
-            if (seiColourRemappingInfo->m_colourRemapPersistenceFlag)
-            {
-              seiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
-              seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo);
-            }
-          }
+        if (!m_colourRemapSEIFileName.empty())
+        {
+          xOutputColourRemapPic(pcPic, activeSPS);
         }
 #endif
@@ -1122,38 +1100,7 @@
 
 #if Q0074_COLOUR_REMAPPING_SEI
-        if (m_colourRemapSEIEnabled)
-        {
-          SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
-          const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
-          const TComSPS *sps = pcPic->getSlice(0)->getSPS();
-
-          if (colourRemappingInfo.size() > 1)
-          {
-            printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
-          }
-          if (seiColourRemappingInfo)
-          {
-            xApplyColourRemapping( sps, *pcPic->getPicYuvRec(), seiColourRemappingInfo );
-          }
-          else  // using the last CRI SEI received
-          {
-            const SEIColourRemappingInfo *seiColourRemappingInfoCopy;
-            seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious;
-            xApplyColourRemapping( sps, *pcPic->getPicYuvRec(), seiColourRemappingInfoCopy );
-          }
-
-          // save the last CRI SEI received
-          if( seiColourRemappingInfo != NULL){
-            if (seiColourRemappingInfoPrevious != NULL)
-            {
-              delete seiColourRemappingInfoPrevious;
-              seiColourRemappingInfoPrevious = NULL;
-            }
-            if (seiColourRemappingInfo->m_colourRemapPersistenceFlag)
-            {
-              seiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
-              seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo);
-            }
-          }
+        if (!m_colourRemapSEIFileName.empty())
+        {
+          xOutputColourRemapPic(pcPic, &(pcPic->getPicSym()->getSPS()));
         }
 #endif
@@ -1215,4 +1162,339 @@
   return false;
 }
+
+#if Q0074_COLOUR_REMAPPING_SEI
+
+Void TAppDecTop::xOutputColourRemapPic(TComPic* pcPic, const TComSPS* activeSPS)
+{
+  SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
+  SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
+
+  if (colourRemappingInfo.size() > 1)
+  {
+    printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
+  }
+  if (seiColourRemappingInfo)
+  {
+    applyColourRemapping(*pcPic->getPicYuvRec(), *seiColourRemappingInfo, *activeSPS);
+  }
+  else  // using the last CRI SEI received
+  {
+    if (m_pcSeiColourRemappingInfoPrevious != NULL)
+    {
+      if (m_pcSeiColourRemappingInfoPrevious->m_colourRemapPersistenceFlag == false)
+      {
+        printf("Warning No SEI-CRI message is present for the current picture, persistence of the CRI is not managed\n");
+      }
+      SEIColourRemappingInfo *seiColourRemappingInfoCopy;
+      seiColourRemappingInfoCopy = m_pcSeiColourRemappingInfoPrevious;
+      applyColourRemapping(*pcPic->getPicYuvRec(), *seiColourRemappingInfoCopy, *activeSPS);
+    }
+  }
+
+  // save the last CRI SEI received
+  if( seiColourRemappingInfo != NULL)
+  {
+    if (m_pcSeiColourRemappingInfoPrevious != NULL)
+    {
+      delete m_pcSeiColourRemappingInfoPrevious;
+      m_pcSeiColourRemappingInfoPrevious = NULL;
+    }
+    m_pcSeiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
+    m_pcSeiColourRemappingInfoPrevious->copyFrom(*seiColourRemappingInfo);
+  }
+}
+
+// compute lut from SEI
+// use at lutPoints points aligned on a power of 2 value
+// SEI Lut must be in ascending values of coded Values
+static std::vector<Int>
+initColourRemappingInfoLut(const Int                                          bitDepth_in,     // bit-depth of the input values of the LUT
+                           const Int                                          nbDecimalValues, // Position of the fixed point
+                           const std::vector<SEIColourRemappingInfo::CRIlut> &lut,
+                           const Int                                          maxValue, // maximum output value
+                           const Int                                          lutOffset)
+{
+  const Int lutPoints = (1 << bitDepth_in) + 1 ;
+  std::vector<Int> retLut(lutPoints);
+
+  // missing values: need to define default values before first definition (check codedValue[0] == 0)
+  Int iTargetPrev = (lut.size() && lut[0].codedValue == 0) ? lut[0].targetValue: 0;
+  Int startPivot = (lut.size())? ((lut[0].codedValue == 0)? 1: 0): 1;
+  Int iCodedPrev  = 0;
+  // set max value with the coded bit-depth
+  // + ((1 << nbDecimalValues) - 1) is for the added bits
+  const Int maxValueFixedPoint = (maxValue << nbDecimalValues) + ((1 << nbDecimalValues) - 1);
+
+  Int iValue = 0;
+
+  for ( Int iPivot=startPivot ; iPivot < (Int)lut.size(); iPivot++ )
+  {
+    Int iCodedNext  = lut[iPivot].codedValue;
+    Int iTargetNext = lut[iPivot].targetValue;
+
+    // ensure correct bit depth and avoid overflow in lut address
+    Int iCodedNext_bitDepth = std::min(iCodedNext, (1 << bitDepth_in));
+
+    const Int divValue =  (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1;
+    const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues;
+    const Int roundValue = divValue / 2;
+    for ( ; iValue<iCodedNext_bitDepth; iValue++ )
+    {
+      Int value = iValue;
+      Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue;               
+      retLut[iValue]  = std::min(lutValInit + interpol , maxValueFixedPoint);
+    }
+    iCodedPrev  = iCodedNext;
+    iTargetPrev = iTargetNext;
+  }
+  // fill missing values if necessary
+  if(iCodedPrev < (1 << bitDepth_in)+1)
+  {
+    Int iCodedNext  = (1 << bitDepth_in);
+    Int iTargetNext = (1 << bitDepth_in) - 1;
+
+    const Int divValue =  (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1;
+    const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues;
+    const Int roundValue = divValue / 2;
+
+    for ( ; iValue<=iCodedNext; iValue++ )
+    {
+      Int value = iValue;
+      Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue; 
+      retLut[iValue]  = std::min(lutValInit + interpol , maxValueFixedPoint);
+    }
+  }
+  return retLut;
+}
+
+static Void
+initColourRemappingInfoLuts(std::vector<Int>      (&preLut)[3],
+                            std::vector<Int>      (&postLut)[3],
+                            SEIColourRemappingInfo &pCriSEI,
+                            const Int               maxBitDepth)
+{
+  Int internalBitDepth = pCriSEI.m_colourRemapBitDepth;
+  for ( Int c=0 ; c<3 ; c++ )
+  {
+    std::sort(pCriSEI.m_preLut[c].begin(), pCriSEI.m_preLut[c].end()); // ensure preLut is ordered in ascending values of codedValues   
+    preLut[c] = initColourRemappingInfoLut(pCriSEI.m_colourRemapInputBitDepth, maxBitDepth - pCriSEI.m_colourRemapInputBitDepth, pCriSEI.m_preLut[c], ((1 << internalBitDepth) - 1), 0); //Fill preLut
+
+    std::sort(pCriSEI.m_postLut[c].begin(), pCriSEI.m_postLut[c].end()); // ensure postLut is ordered in ascending values of codedValues       
+    postLut[c] = initColourRemappingInfoLut(pCriSEI.m_colourRemapBitDepth, maxBitDepth - pCriSEI.m_colourRemapBitDepth, pCriSEI.m_postLut[c], (1 << internalBitDepth) - 1, 0); //Fill postLut
+  }
+}
+
+// apply lut.
+// Input lut values are aligned on power of 2 boundaries
+static Int
+applyColourRemappingInfoLut1D(Int inVal, const std::vector<Int> &lut, const Int inValPrecisionBits)
+{
+  const Int roundValue = (inValPrecisionBits)? 1 << (inValPrecisionBits - 1): 0;
+  inVal = std::min(std::max(0, inVal), (Int)(((lut.size()-1) << inValPrecisionBits)));
+  Int index  = (Int) std::min((inVal >> inValPrecisionBits), (Int)(lut.size()-2));
+  Int outVal = (( inVal - (index<<inValPrecisionBits) ) * (lut[index+1] - lut[index]) + roundValue) >> inValPrecisionBits;
+  outVal +=  lut[index] ;
+
+  return outVal;
+}  
+
+static Int
+applyColourRemappingInfoMatrix(const Int (&colourRemapCoeffs)[3], const Int postOffsetShift, const Int p0, const Int p1, const Int p2, const Int offset)
+{
+  Int YUVMat = (colourRemapCoeffs[0]* p0 + colourRemapCoeffs[1]* p1 + colourRemapCoeffs[2]* p2  + offset) >> postOffsetShift;
+  return YUVMat;
+}
+
+static Void
+setColourRemappingInfoMatrixOffset(Int (&matrixOffset)[3], Int offset0, Int offset1, Int offset2)
+{
+  matrixOffset[0] = offset0;
+  matrixOffset[1] = offset1;
+  matrixOffset[2] = offset2;
+}
+
+static Void
+setColourRemappingInfoMatrixOffsets(      Int  (&matrixInputOffset)[3],
+                                          Int  (&matrixOutputOffset)[3],
+                                    const Int  bitDepth,
+                                    const Bool crInputFullRangeFlag,
+                                    const Int  crInputMatrixCoefficients,
+                                    const Bool crFullRangeFlag,
+                                    const Int  crMatrixCoefficients)
+{
+  // set static matrix offsets
+  Int crInputOffsetLuma = (crInputFullRangeFlag)? 0:-(16 << (bitDepth-8));
+  Int crOffsetLuma = (crFullRangeFlag)? 0:(16 << (bitDepth-8));
+  Int crInputOffsetChroma = 0;
+  Int crOffsetChroma = 0;
+
+  switch(crInputMatrixCoefficients)
+  {
+    case MATRIX_COEFFICIENTS_RGB:
+      crInputOffsetChroma = 0;
+      if(!crInputFullRangeFlag)
+      {
+        fprintf(stderr, "WARNING: crInputMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n");
+        crInputOffsetLuma = 0;
+      }
+      break;
+    case MATRIX_COEFFICIENTS_UNSPECIFIED:
+    case MATRIX_COEFFICIENTS_BT709:
+    case MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE:
+      crInputOffsetChroma = -(1 << (bitDepth-1));
+      break;
+    default:
+      fprintf(stderr, "WARNING: crInputMatrixCoefficients set to undefined value: %d\n", crInputMatrixCoefficients);
+  }
+
+  switch(crMatrixCoefficients)
+  {
+    case MATRIX_COEFFICIENTS_RGB:
+      crOffsetChroma = 0;
+      if(!crFullRangeFlag)
+      {
+        fprintf(stderr, "WARNING: crMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n");
+        crOffsetLuma = 0;
+      }
+      break;
+    case MATRIX_COEFFICIENTS_UNSPECIFIED:
+    case MATRIX_COEFFICIENTS_BT709:
+    case MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE:
+      crOffsetChroma = (1 << (bitDepth-1));
+      break;
+    default:
+      fprintf(stderr, "WARNING: crMatrixCoefficients set to undefined value: %d\n", crMatrixCoefficients);
+  }
+
+  setColourRemappingInfoMatrixOffset(matrixInputOffset, crInputOffsetLuma, crInputOffsetChroma, crInputOffsetChroma);
+  setColourRemappingInfoMatrixOffset(matrixOutputOffset, crOffsetLuma, crOffsetChroma, crOffsetChroma);
+}
+
+Void TAppDecTop::applyColourRemapping(const TComPicYuv& pic, SEIColourRemappingInfo& criSEI, const TComSPS &activeSPS)
+{  
+  const Int maxBitDepth = 16;
+  Bool firstPicture = true;
+
+  // create colour remapped picture
+  if ( m_pcPicYuvColourRemapped == NULL )
+  {
+    const ChromaFormat chromaFormatIDC = activeSPS.getChromaFormatIdc();
+    const Int          iWidth          = activeSPS.getPicWidthInLumaSamples();
+    const Int          iHeight         = activeSPS.getPicHeightInLumaSamples();
+    const UInt         uiMaxCuWidth    = activeSPS.getMaxCUWidth();
+    const UInt         uiMaxCuHeight   = activeSPS.getMaxCUHeight();
+    const UInt         uiMaxDepth      = activeSPS.getMaxTotalCUDepth();
+    m_pcPicYuvColourRemapped  = new TComPicYuv;
+    m_pcPicYuvColourRemapped->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
+  }
+  else
+  {
+    firstPicture = false;
+  }
+
+  if( !criSEI.m_colourRemapCancelFlag )
+  {
+    const Int  iHeight  = pic.getHeight(COMPONENT_Y);
+    const Int  iWidth   = pic.getWidth(COMPONENT_Y);
+    const Int  iStride  = pic.getStride(COMPONENT_Y);
+    const Int  iCStride = pic.getStride(COMPONENT_Cb);
+    const Bool b444     = ( pic.getChromaFormat() == CHROMA_444 );
+    const Bool b422     = ( pic.getChromaFormat() == CHROMA_422 );
+    const Bool b420     = ( pic.getChromaFormat() == CHROMA_420 );
+
+    std::vector<Int> preLut[3];
+    std::vector<Int> postLut[3];
+    Int matrixInputOffset[3];
+    Int matrixOutputOffset[3];
+    const Pel *YUVIn[MAX_NUM_COMPONENT];
+    Pel *YUVOut[MAX_NUM_COMPONENT];
+    YUVIn[COMPONENT_Y]  = pic.getAddr(COMPONENT_Y);
+    YUVIn[COMPONENT_Cb] = pic.getAddr(COMPONENT_Cb);
+    YUVIn[COMPONENT_Cr] = pic.getAddr(COMPONENT_Cr);
+    YUVOut[COMPONENT_Y]  = m_pcPicYuvColourRemapped->getAddr(COMPONENT_Y);
+    YUVOut[COMPONENT_Cb] = m_pcPicYuvColourRemapped->getAddr(COMPONENT_Cb);
+    YUVOut[COMPONENT_Cr] = m_pcPicYuvColourRemapped->getAddr(COMPONENT_Cr);
+
+    Int bitDepthY = activeSPS.getBitDepth(CHANNEL_TYPE_LUMA);
+    assert(bitDepthY == activeSPS.getBitDepth(CHANNEL_TYPE_CHROMA)); // Different bitdepth is not implemented
+
+    const Int postOffsetShift = criSEI.m_log2MatrixDenom;
+    const Int matrixRound = 1 << (postOffsetShift - 1);
+    const Int postLutInputPrecision = (maxBitDepth - criSEI.m_colourRemapBitDepth);
+
+    if ( ! criSEI.m_colourRemapVideoSignalInfoPresentFlag ) // setting default
+    {
+      setColourRemappingInfoMatrixOffsets(matrixInputOffset, matrixOutputOffset, maxBitDepth,
+          activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients(),
+          activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients());
+    }
+    else
+    {
+      setColourRemappingInfoMatrixOffsets(matrixInputOffset, matrixOutputOffset, maxBitDepth,
+          activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients(),
+          criSEI.m_colourRemapFullRangeFlag, criSEI.m_colourRemapMatrixCoefficients);
+    }
+
+    // add matrix rounding to output matrix offsets
+    matrixOutputOffset[0] = (matrixOutputOffset[0] << postOffsetShift) + matrixRound;
+    matrixOutputOffset[1] = (matrixOutputOffset[1] << postOffsetShift) + matrixRound;
+    matrixOutputOffset[2] = (matrixOutputOffset[2] << postOffsetShift) + matrixRound;
+
+    // Merge   matrixInputOffset and matrixOutputOffset to matrixOutputOffset
+    matrixOutputOffset[0] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[0], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
+    matrixOutputOffset[1] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[1], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
+    matrixOutputOffset[2] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[2], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0);
+
+    // rescaling output: include CRI/output frame difference
+    const Int scaleShiftOut_neg = abs(bitDepthY - maxBitDepth);
+    const Int scaleOut_round = 1 << (scaleShiftOut_neg-1);
+
+    initColourRemappingInfoLuts(preLut, postLut, criSEI, maxBitDepth);
+
+    assert(pic.getChromaFormat() != CHROMA_400);
+    const Int hs = pic.getComponentScaleX(ComponentID(COMPONENT_Cb));
+
+    for( Int y = 0; y < iHeight; y++ )
+    {
+      for( Int x = 0; x < iWidth; x++ )
+      {
+        const Int xc = (x>>hs);
+        Bool computeChroma = b444 || ((b422 || !(y&1)) && !(x&1));
+
+        Int YUVPre_0 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Y][x], preLut[0], 0);
+        Int YUVPre_1 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Cb][xc], preLut[1], 0);
+        Int YUVPre_2 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Cr][xc], preLut[2], 0);
+
+        Int YUVMat_0 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[0], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[0]);
+        Int YUVLutB_0 = applyColourRemappingInfoLut1D(YUVMat_0, postLut[0], postLutInputPrecision);
+        YUVOut[COMPONENT_Y][x] = (YUVLutB_0 + scaleOut_round) >> scaleShiftOut_neg; // scaling output
+
+        if( computeChroma )
+        {
+          Int YUVMat_1 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[1], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[1]);
+          Int YUVLutB_1 = applyColourRemappingInfoLut1D(YUVMat_1, postLut[1], postLutInputPrecision);
+          YUVOut[COMPONENT_Cb][xc] = (YUVLutB_1 + scaleOut_round) >> scaleShiftOut_neg; // scaling output
+
+          Int YUVMat_2 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[2], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[2]);
+          Int YUVLutB_2 = applyColourRemappingInfoLut1D(YUVMat_2, postLut[2], postLutInputPrecision);
+          YUVOut[COMPONENT_Cr][xc] = (YUVLutB_2 + scaleOut_round) >> scaleShiftOut_neg; // scaling output
+        }
+      }
+
+      YUVIn[COMPONENT_Y]  += iStride;
+      YUVOut[COMPONENT_Y] += iStride;
+      if( !(b420 && !(y&1)) )
+      {
+         YUVIn[COMPONENT_Cb]  += iCStride;
+         YUVIn[COMPONENT_Cr]  += iCStride;
+         YUVOut[COMPONENT_Cb] += iCStride;
+         YUVOut[COMPONENT_Cr] += iCStride;
+      }
+    }
+    //Write remapped picture in display order
+    m_pcPicYuvColourRemapped->dump( m_colourRemapSEIFileName, activeSPS.getBitDepths(), !firstPicture );
+  }
+}
+#endif
 
 #if ALIGNED_BUMPING
@@ -1238,42 +1520,8 @@
 
 #if Q0074_COLOUR_REMAPPING_SEI
-    if( m_colourRemapSEIEnabled )
-    {
-      const TComSPS *sps = pic->getSlice(0)->getSPS();
-      SEIMessages colourRemappingInfo = getSeisByType(pic->getSEIs(), SEI::COLOUR_REMAPPING_INFO );
-      const SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL;
-
-      if (colourRemappingInfo.size() > 1)
-      {
-        printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first.");
-      }
-
-      if (seiColourRemappingInfo)
-      {
-        //printf ("\n\nColour Remapping is applied to POC : %d and LayerId : %d ",pic->getPOC(), pic->getLayerId());
-        xApplyColourRemapping( sps, *pic->getPicYuvRec(), seiColourRemappingInfo, pic->getLayerId() );
-      }
-      else  // using the last CRI SEI received
-      {
-        const SEIColourRemappingInfo *seiColourRemappingInfoCopy;
-        seiColourRemappingInfoCopy = seiColourRemappingInfoPrevious;
-        xApplyColourRemapping( sps, *pic->getPicYuvRec(), seiColourRemappingInfoCopy, pic->getLayerId() );
-      }
-
-      // save the last CRI SEI received
-      if( seiColourRemappingInfo != NULL){
-        if (seiColourRemappingInfoPrevious != NULL)
-        {
-          delete seiColourRemappingInfoPrevious;
-          seiColourRemappingInfoPrevious = NULL;
-        }
-        if (seiColourRemappingInfo->m_colourRemapPersistenceFlag)
-        {
-          seiColourRemappingInfoPrevious = new SEIColourRemappingInfo();
-          seiColourRemappingInfoPrevious->copyFrom(seiColourRemappingInfo);
-        }
-      }
-    }
-
+    if (!m_colourRemapSEIFileName.empty())
+    {
+      xOutputColourRemapPic(pic, pic->getSlice(0)->getSPS());
+    }
 #endif
   }
@@ -1795,173 +2043,3 @@
 #endif //ALIGNED_BUMPING
 
-#if Q0074_COLOUR_REMAPPING_SEI
-Void TAppDecTop::xInitColourRemappingLut( const BitDepths &bitDepths, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI )
-{
-  for ( Int c=0 ; c<3 ; c++ )
-  {  
-    Int bitDepth = bitDepths.recon[toChannelType(ComponentID(c))];
-    preLut[c].resize(1 << bitDepth);
-    postLut[c].resize(1 << pCriSEI->m_colourRemapBitDepth);
-    
-    Int bitDepthDiff = pCriSEI->m_colourRemapBitDepth - bitDepth;
-    Int iShift1 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from bitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= bitdepth)
-    if( bitDepthDiff<0 )
-      printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <bitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, bitDepth);
-    bitDepthDiff = pCriSEI->m_colourRemapBitDepth - pCriSEI->m_colourRemapInputBitDepth;
-    Int iShift2 = (bitDepthDiff>0) ? bitDepthDiff : 0; //bit scale from ColourRemapInputBitdepth to ColourRemapBitdepth (manage only case colourRemapBitDepth>= colourRemapInputBitDepth)
-    if( bitDepthDiff<0 )
-      printf ("Warning: CRI SEI - colourRemapBitDepth (%d) <colourRemapInputBitDepth (%d) - case not handled\n", pCriSEI->m_colourRemapBitDepth, pCriSEI->m_colourRemapInputBitDepth);
-
-    //Fill preLut
-    for ( Int k=0 ; k<(1<<bitDepth) ; k++ )
-    {
-      Int iSample = k << iShift1 ;
-      for ( Int iPivot=0 ; iPivot<=pCriSEI->m_preLutNumValMinus1[c] ; iPivot++ )
-      {
-        Int iCodedPrev  = pCriSEI->m_preLutCodedValue[c][iPivot]    << iShift2; //Coded in CRInputBitdepth
-        Int iCodedNext  = pCriSEI->m_preLutCodedValue[c][iPivot+1]  << iShift2; //Coded in CRInputBitdepth
-        Int iTargetPrev = pCriSEI->m_preLutTargetValue[c][iPivot];              //Coded in CRBitdepth
-        Int iTargetNext = pCriSEI->m_preLutTargetValue[c][iPivot+1];            //Coded in CRBitdepth
-        if ( iCodedPrev <= iSample && iSample <= iCodedNext )
-        {
-          Float fInterpol = (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev);
-          preLut[c][k]  = (Int)( 0.5f + fInterpol );
-          iPivot = pCriSEI->m_preLutNumValMinus1[c] + 1;
-        }
-      }
-    }
-    
-    //Fill postLut
-    for ( Int k=0 ; k<(1<<pCriSEI->m_colourRemapBitDepth) ; k++ )
-    {
-      Int iSample = k;
-      for ( Int iPivot=0 ; iPivot<=pCriSEI->m_postLutNumValMinus1[c] ; iPivot++ )
-      {
-        Int iCodedPrev  = pCriSEI->m_postLutCodedValue[c][iPivot];    //Coded in CRBitdepth
-        Int iCodedNext  = pCriSEI->m_postLutCodedValue[c][iPivot+1];  //Coded in CRBitdepth
-        Int iTargetPrev = pCriSEI->m_postLutTargetValue[c][iPivot];   //Coded in CRBitdepth
-        Int iTargetNext = pCriSEI->m_postLutTargetValue[c][iPivot+1]; //Coded in CRBitdepth
-        if ( iCodedPrev <= iSample && iSample <= iCodedNext )
-        {
-          Float fInterpol =  (Float)( (iCodedNext - iSample)*iTargetPrev + (iSample - iCodedPrev)*iTargetNext ) * 1.f / (Float)(iCodedNext - iCodedPrev) ;
-          postLut[c][k]  = (Int)( 0.5f + fInterpol );
-          iPivot = pCriSEI->m_postLutNumValMinus1[c] + 1;
-        }
-      }
-    }
-  }
-}
-
-Void TAppDecTop::xApplyColourRemapping( const TComSPS *sps, TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId )
-{
-  const BitDepths& bitDpeths = sps->getBitDepths();
-
-  if( !storeCriSEI.size() )
-  {
-#if SVC_EXTENSION
-    storeCriSEI.resize(MAX_LAYERS);
-#else
-    storeCriSEI.resize(1);
-#endif
-  }
-
-  if ( pCriSEI ) //if a CRI SEI has just been retrieved, keep it in memory (persistence management)
-  {
-    storeCriSEI[layerId] = *pCriSEI;
-  }
-
-  if( !storeCriSEI[layerId].m_colourRemapCancelFlag && pCriSEI) 
-  {
-    Int iHeight  = pic.getHeight(COMPONENT_Y);
-    Int iWidth   = pic.getWidth(COMPONENT_Y);
-    Int iStride  = pic.getStride(COMPONENT_Y);
-    Int iCStride = pic.getStride(COMPONENT_Cb);
-
-    Pel *YUVIn[3], *YUVOut[3];
-    YUVIn[0] = pic.getAddr(COMPONENT_Y);
-    YUVIn[1] = pic.getAddr(COMPONENT_Cb);
-    YUVIn[2] = pic.getAddr(COMPONENT_Cr);
-    
-    TComPicYuv picColourRemapped;
-
-#if SVC_EXTENSION
-#if AUXILIARY_PICTURES
-    picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), true, NULL );
-#else
-    picColourRemapped.create( pic.getWidth(), pic.getHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), true, NULL );
-#endif
-#else
-    picColourRemapped.create( pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), pic.getChromaFormat(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), true );
-#endif 
-    YUVOut[0] = picColourRemapped.getAddr(COMPONENT_Y);
-    YUVOut[1] = picColourRemapped.getAddr(COMPONENT_Cb);
-    YUVOut[2] = picColourRemapped.getAddr(COMPONENT_Cr);
-
-    std::vector<Int> preLut[3];
-    std::vector<Int> postLut[3];
-    xInitColourRemappingLut( bitDpeths, preLut, postLut, &storeCriSEI[layerId] );
-    
-    Int roundingOffset = (storeCriSEI[layerId].m_log2MatrixDenom==0) ? 0 : (1 << (storeCriSEI[layerId].m_log2MatrixDenom - 1));
-
-    for( Int y = 0; y < iHeight ; y++ )
-    {
-      for( Int x = 0; x < iWidth ; x++ )
-      {
-        Int YUVPre[3], YUVMat[3];
-        YUVPre[0] = preLut[0][ YUVIn[0][x]   ];
-        YUVPre[1] = preLut[1][ YUVIn[1][x>>1] ];
-        YUVPre[2] = preLut[2][ YUVIn[2][x>>1] ];
-
-        YUVMat[0] = ( storeCriSEI[layerId].m_colourRemapCoeffs[0][0]*YUVPre[0]
-                    + storeCriSEI[layerId].m_colourRemapCoeffs[0][1]*YUVPre[1] 
-                    + storeCriSEI[layerId].m_colourRemapCoeffs[0][2]*YUVPre[2] 
-                    + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
-        YUVMat[0] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[0] );
-        YUVOut[0][x] = postLut[0][ YUVMat[0] ];
-
-        if( (y&1) && (x&1) )
-        {
-          for(Int c=1 ; c<3 ; c++)
-          {
-            YUVMat[c] = ( storeCriSEI[layerId].m_colourRemapCoeffs[c][0]*YUVPre[0] 
-                        + storeCriSEI[layerId].m_colourRemapCoeffs[c][1]*YUVPre[1] 
-                        + storeCriSEI[layerId].m_colourRemapCoeffs[c][2]*YUVPre[2] 
-                        + roundingOffset ) >> ( storeCriSEI[layerId].m_log2MatrixDenom );
-            YUVMat[c] = Clip3( 0, (1<<storeCriSEI[layerId].m_colourRemapBitDepth)-1, YUVMat[c] );
-            YUVOut[c][x>>1] = postLut[c][ YUVMat[c] ];   
-          }
-        }
-      }
-      YUVIn[0]  += iStride;
-      YUVOut[0] += iStride;
-      if( y&1 )
-      {
-        YUVIn[1]  += iCStride;
-        YUVIn[2]  += iCStride;
-        YUVOut[1] += iCStride;
-        YUVOut[2] += iCStride;
-      }
-    }
-
-    //Write remapped picture in decoding order
-    TChar  cTemp[255];
-    sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, iWidth, iHeight, storeCriSEI[layerId].m_colourRemapBitDepth );
-    picColourRemapped.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );
-
-    picColourRemapped.destroy();
-
-    storeCriSEI[layerId].m_colourRemapCancelFlag = !storeCriSEI[layerId].m_colourRemapPersistenceFlag; //Handling persistence
-  }
-  else
-  {
-    //Write no remapped picture in decoding order
-    if (storeCriSEI[layerId].m_colourRemapBitDepth == 8 || storeCriSEI[layerId].m_colourRemapBitDepth == 10)
-    {
-      TChar  cTemp[255];
-      sprintf(cTemp, "seiColourRemappedPic_L%d_%dx%d_%dbits.yuv", layerId, pic.getWidth(COMPONENT_Y), pic.getHeight(COMPONENT_Y), storeCriSEI[layerId].m_colourRemapBitDepth );
-      pic.dump( cTemp, true, storeCriSEI[layerId].m_colourRemapBitDepth );
-    }
-  }
-}
-#endif
 //! \}
Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 1460)
@@ -66,23 +66,22 @@
   TDecTop*                        m_apcTDecTop[MAX_NUM_LAYER_IDS];                     ///< decoder point class 
   TVideoIOYuv*                    m_apcTVideoIOYuvReconFile[MAX_NUM_LAYER_IDS];        ///< reconstruction YUV class
+#if CONFORMANCE_BITSTREAM_MODE
+  TVideoIOYuv                     m_confReconFile[63];        ///< decode YUV files
+#endif 
+  // for output control
+  Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
 #else
   TDecTop                         m_cTDecTop;                     ///< decoder class
   TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
+
+  // for output control
+  Int                             m_iPOCLastDisplay;              ///< last POC in display order
 #endif
-  
-  // for output control  
+
   std::ofstream                   m_seiMessageFileStream;         ///< Used for outputing SEI messages.
 
-#if SVC_EXTENSION
-#if CONFORMANCE_BITSTREAM_MODE
-  TVideoIOYuv                     m_confReconFile[63];        ///< decode YUV files
-#endif 
-  Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
-#else
-  Int                             m_iPOCLastDisplay;              ///< last POC in display order
-#endif
 #if Q0074_COLOUR_REMAPPING_SEI
-  std::vector<SEIColourRemappingInfo> storeCriSEI; //Persistent Colour Remapping Information SEI
-  SEIColourRemappingInfo *seiColourRemappingInfoPrevious;
+  SEIColourRemappingInfo*         m_pcSeiColourRemappingInfoPrevious;
+  TComPicYuv*                     m_pcPicYuvColourRemapped;       ///< Colour Remapped picture
 #endif
 
@@ -117,9 +116,5 @@
   Void  xDestroyDecLib    (); ///< destroy internal classes
   Void  xInitDecLib       (); ///< initialize decoder class
-  
-#if Q0074_COLOUR_REMAPPING_SEI
-  Void  xInitColourRemappingLut( const BitDepths &bitDepths, std::vector<Int>(&preLut)[3], std::vector<Int>(&postLut)[3], const SEIColourRemappingInfo* const pCriSEI );
-  Void  xApplyColourRemapping( const TComSPS *sps, TComPicYuv& pic, const SEIColourRemappingInfo* pCriSEI, UInt layerId = 0 );
-#endif
+
 #if SVC_EXTENSION
   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId ); ///< write YUV to file
@@ -130,4 +125,10 @@
 #endif
   Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
+
+#if Q0074_COLOUR_REMAPPING_SEI
+private:
+  Void applyColourRemapping(const TComPicYuv& pic, SEIColourRemappingInfo& pCriSEI, const TComSPS &activeSPS);
+  Void xOutputColourRemapPic(TComPic* pcPic, const TComSPS* activeSPS);
+#endif
 #if ALIGNED_BUMPING
   Void checkOutputBeforeDecoding(Int layerIdx);
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1460)
@@ -774,5 +774,5 @@
   Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
 #if Q0074_COLOUR_REMAPPING_SEI
-  string* cfg_colourRemapSEIFileName[MAX_LAYERS];
+  string* cfg_colourRemapSEIFileRoot[MAX_LAYERS];
 #endif
   Bool*   cfg_entropyCodingSyncEnabledFlag[MAX_LAYERS];
@@ -793,5 +793,5 @@
     cfg_fQP[layer]          = &m_apcLayerCfg[layer]->m_fQP;
 #if Q0074_COLOUR_REMAPPING_SEI
-    cfg_colourRemapSEIFileName[layer] = &m_apcLayerCfg[layer]->m_colourRemapSEIFileName;
+    cfg_colourRemapSEIFileRoot[layer] = &m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot;
 #endif
     cfg_repFormatIdx[layer]         = &m_apcLayerCfg[layer]->m_repFormatIdx;
@@ -1073,5 +1073,5 @@
   ("PhaseVerChroma%d",                              cfg_phaseVerChromaPtr,            string(""), m_numLayers, "chroma shift in the vertical   direction used in resampling proces")
 #if Q0074_COLOUR_REMAPPING_SEI
-  ("SEIColourRemappingInfoFileRoot%d",              cfg_colourRemapSEIFileName,       string(""), m_numLayers, "Colour Remapping Information SEI parameters file name for layer %d")
+  ("SEIColourRemappingInfoFileRoot%d,-cri",         cfg_colourRemapSEIFileRoot,       string(""), m_numLayers, "Colour Remapping Information SEI parameters root file name (wo num ext)")
 #endif
   ("InputBitDepth%d",                                cfg_InputBitDepth[CHANNEL_TYPE_LUMA],     8, m_numLayers, "Bit-depth of input file for layer %d")
@@ -1141,8 +1141,5 @@
 #if !SVC_EXTENSION
   ("FrameRate,-fr",                                   m_iFrameRate,                                         0, "Frame rate")
-#if Q0074_COLOUR_REMAPPING_SEI
-  ("SEIColourRemappingInfoFileRoot",                  m_colourRemapSEIFileName,                    string(""), "Colour Remapping Information SEI parameters file name")
-#endif
-#endif //SVC_EXTENSION
+#endif
   ("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)")
@@ -1462,4 +1459,9 @@
   ("Log2MaxMvLengthHorizontal",                       m_log2MaxMvLengthHorizontal,                         15, "Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units")
   ("Log2MaxMvLengthVertical",                         m_log2MaxMvLengthVertical,                           15, "Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units")
+#if !SVC_EXTENSION
+#if Q0074_COLOUR_REMAPPING_SEI
+  ("SEIColourRemappingInfoFileRoot,-cri",             m_colourRemapSEIFileRoot,                    string(""), "Colour Remapping Information SEI parameters root file name (wo num ext)")
+#endif
+#endif
   ("SEIRecoveryPoint",                                m_recoveryPointSEIEnabled,                        false, "Control generation of recovery point SEI messages")
   ("SEIBufferingPeriod",                              m_bufferingPeriodSEIEnabled,                      false, "Control generation of buffering period SEI messages")
@@ -1566,5 +1568,5 @@
   ("SEIMasteringDisplayPrimaries",                    cfg_DisplayPrimariesCode,       cfg_DisplayPrimariesCode, "Mastering display primaries for all three colour planes in CIE xy coordinates in increments of 1/50000 (results in the ranges 0 to 50000 inclusive)")
   ("SEIMasteringDisplayWhitePoint",                   cfg_DisplayWhitePointCode,     cfg_DisplayWhitePointCode, "Mastering display white point CIE xy coordinates in normalised increments of 1/50000 (e.g. 0.333 = 16667)")
- 
+
 #if LAYERS_NOT_PRESENT_SEI
   ("SEILayersNotPresent",                             m_layersNotPresentSEIEnabled,             0, "Control generation of layers not present SEI message")
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1460)
@@ -457,4 +457,9 @@
   Int       m_log2MaxMvLengthHorizontal;                      ///< Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units
   Int       m_log2MaxMvLengthVertical;                        ///< Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units
+#if !SVC_EXTENSION
+#if Q0074_COLOUR_REMAPPING_SEI
+  std::string m_colourRemapSEIFileRoot;
+#endif
+#endif
 
   std::string m_summaryOutFilename;                           ///< filename to use for producing summary output file.
@@ -486,9 +491,5 @@
   Bool      m_elRapSliceBEnabled;
 #endif
-#if Q0074_COLOUR_REMAPPING_SEI
-#if !SVC_EXTENSION
-  string    m_colourRemapSEIFileName;
-#endif
-#endif
+
   // internal member functions
 #if SVC_EXTENSION
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 1460)
@@ -31,10 +31,4 @@
 , m_repFormatIdx(-1)
 {
-#if Q0074_COLOUR_REMAPPING_SEI
-  memset( m_colourRemapSEIPreLutCodedValue,   0, sizeof(m_colourRemapSEIPreLutCodedValue) );
-  memset( m_colourRemapSEIPreLutTargetValue,  0, sizeof(m_colourRemapSEIPreLutTargetValue) );
-  memset( m_colourRemapSEIPostLutCodedValue,  0, sizeof(m_colourRemapSEIPostLutCodedValue) );
-  memset( m_colourRemapSEIPostLutTargetValue, 0, sizeof(m_colourRemapSEIPostLutTargetValue) );
-#endif
   m_confWinLeft = m_confWinRight = m_confWinTop = m_confWinBottom = 0;
   m_aiPad[1] = m_aiPad[0] = 0;
@@ -64,25 +58,4 @@
     delete[] m_aidQP;
   }
-#if Q0074_COLOUR_REMAPPING_SEI
-  for( Int c=0 ; c<3 ; c++)
-  {
-    if ( m_colourRemapSEIPreLutCodedValue[c] )
-    {
-      delete[] m_colourRemapSEIPreLutCodedValue[c];
-    }
-    if ( m_colourRemapSEIPreLutTargetValue[c] )
-    {
-      delete[] m_colourRemapSEIPreLutTargetValue[c];
-    }
-    if ( m_colourRemapSEIPostLutCodedValue[c] )
-    {
-      delete[] m_colourRemapSEIPostLutCodedValue[c];
-    }
-    if ( m_colourRemapSEIPostLutTargetValue[c] )
-    {
-      delete[] m_colourRemapSEIPostLutTargetValue[c];
-    }
-  }
-#endif
 }
 
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 1460)
@@ -135,24 +135,5 @@
   Int       m_repFormatIdx;
 #if Q0074_COLOUR_REMAPPING_SEI
-  string    m_colourRemapSEIFileName;                         ///< Colour Remapping Information SEI message parameters file
-  Int       m_colourRemapSEIId;
-  Bool      m_colourRemapSEICancelFlag;
-  Bool      m_colourRemapSEIPersistenceFlag;
-  Bool      m_colourRemapSEIVideoSignalInfoPresentFlag;
-  Bool      m_colourRemapSEIFullRangeFlag;
-  Int       m_colourRemapSEIPrimaries;
-  Int       m_colourRemapSEITransferFunction;
-  Int       m_colourRemapSEIMatrixCoefficients;
-  Int       m_colourRemapSEIInputBitDepth;
-  Int       m_colourRemapSEIBitDepth;
-  Int       m_colourRemapSEIPreLutNumValMinus1[3];
-  Int*      m_colourRemapSEIPreLutCodedValue[3];
-  Int*      m_colourRemapSEIPreLutTargetValue[3];
-  Bool      m_colourRemapSEIMatrixPresentFlag;
-  Int       m_colourRemapSEILog2MatrixDenom;
-  Int       m_colourRemapSEICoeffs[3][3];
-  Int       m_colourRemapSEIPostLutNumValMinus1[3];
-  Int*      m_colourRemapSEIPostLutCodedValue[3];
-  Int*      m_colourRemapSEIPostLutTargetValue[3];
+  string    m_colourRemapSEIFileRoot;
 #endif
 
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1459)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1460)
@@ -505,9 +505,11 @@
     Bool&          m_bUseSAO                                    = m_apcLayerCfg[layer]->m_bUseSAO;
 
-    string&        m_colourRemapSEIFileName                     = m_apcLayerCfg[layer]->m_colourRemapSEIFileName;
-
     GOPEntry*      m_GOPList                                    = m_apcLayerCfg[layer]->m_GOPList;
     Int&           m_extraRPSs                                  = m_apcLayerCfg[layer]->m_extraRPSs;
     Int&           m_maxTempLayer                               = m_apcLayerCfg[layer]->m_maxTempLayer;
+
+#if Q0074_COLOUR_REMAPPING_SEI
+    string&        m_colourRemapSEIFileRoot                     = m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot;
+#endif
 #endif
 
@@ -542,5 +544,4 @@
   m_cTEncTop.setGopList                                           ( m_GOPList );
   m_cTEncTop.setExtraRPSs                                         ( m_extraRPSs );
-
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -765,4 +766,7 @@
   m_cTEncTop.setKneeSEIInputKneePoint                             ( m_kneeSEIInputKneePoint );
   m_cTEncTop.setKneeSEIOutputKneePoint                            ( m_kneeSEIOutputKneePoint );
+#if Q0074_COLOUR_REMAPPING_SEI
+  m_cTEncTop.setColourRemapInfoSEIFileRoot                        ( m_colourRemapSEIFileRoot );
+#endif
   m_cTEncTop.setMasteringDisplaySEI                               ( m_masteringDisplay );
 
@@ -842,7 +846,4 @@
   m_cTEncTop.setSummaryVerboseness                                ( m_summaryVerboseness );
 
-#if Q0074_COLOUR_REMAPPING_SEI
-  m_cTEncTop.xSetCRISEIFileRoot                                   ( m_colourRemapSEIFileName );
-#endif
 #if LAYERS_NOT_PRESENT_SEI
   m_cTEncTop.setLayersNotPresentSEIEnabled                        ( m_layersNotPresentSEIEnabled );
Index: /branches/SHM-dev/source/Lib/TLibCommon/SEI.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/SEI.cpp	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibCommon/SEI.cpp	(revision 1460)
@@ -150,5 +150,5 @@
     case SEI::CHROMA_RESAMPLING_FILTER_HINT:        return "Chroma sampling filter hint";
 #if Q0074_COLOUR_REMAPPING_SEI
-    case SEI::COLOUR_REMAPPING_INFO:                return "Colour Remapping Information";
+    case SEI::COLOUR_REMAPPING_INFO:                return "Colour remapping info";
 #endif
 #if SVC_EXTENSION
@@ -196,49 +196,2 @@
 }
 #endif
-
-#if Q0074_COLOUR_REMAPPING_SEI
-Void  SEIColourRemappingInfo::copyFrom( SEIColourRemappingInfo const * SeiCriInput)
-{
-  m_colourRemapId                         = SeiCriInput->m_colourRemapId;
-  m_colourRemapCancelFlag                 = SeiCriInput->m_colourRemapCancelFlag;
-  m_colourRemapPersistenceFlag            = SeiCriInput->m_colourRemapPersistenceFlag;
-  m_colourRemapVideoSignalInfoPresentFlag = SeiCriInput->m_colourRemapVideoSignalInfoPresentFlag;
-  m_colourRemapFullRangeFlag              = SeiCriInput->m_colourRemapFullRangeFlag;
-  m_colourRemapPrimaries                  = SeiCriInput->m_colourRemapPrimaries;
-  m_colourRemapTransferFunction           = SeiCriInput->m_colourRemapTransferFunction;
-  m_colourRemapMatrixCoefficients         = SeiCriInput->m_colourRemapMatrixCoefficients;
-  m_colourRemapInputBitDepth              = SeiCriInput->m_colourRemapInputBitDepth;
-  m_colourRemapBitDepth                   = SeiCriInput->m_colourRemapBitDepth;
-
-  for( Int c=0 ; c<3 ; c++ )
-  {
-    m_preLutNumValMinus1[c] = SeiCriInput->m_preLutNumValMinus1[c];
-    m_preLutCodedValue[c].resize(m_preLutNumValMinus1[c]+1);
-    m_preLutTargetValue[c].resize(m_preLutNumValMinus1[c]+1);
-    for ( Int i=0 ; i <= SeiCriInput->m_preLutNumValMinus1[c] ; i++ )
-    {
-        m_preLutCodedValue[c][i]   = SeiCriInput->m_preLutCodedValue[c][i];
-        m_preLutTargetValue[c][i]  = SeiCriInput->m_preLutTargetValue[c][i];
-    } 
-  }
-    
-  m_colourRemapMatrixPresentFlag  = SeiCriInput->m_colourRemapMatrixPresentFlag;
-  m_log2MatrixDenom               = SeiCriInput->m_log2MatrixDenom;
-
-  for ( Int c=0 ; c<3 ; c++ )
-    for ( Int i=0 ; i<3 ; i++ )
-      m_colourRemapCoeffs[c][i] = SeiCriInput->m_colourRemapCoeffs[c][i];
-
-  for( Int c=0 ; c<3 ; c++ )
-  {
-    m_postLutNumValMinus1[c] = SeiCriInput->m_postLutNumValMinus1[c];
-    m_postLutCodedValue[c].resize(m_postLutNumValMinus1[c]+1);
-    m_postLutTargetValue[c].resize(m_postLutNumValMinus1[c]+1);
-    for ( Int i=0 ; i <= m_postLutNumValMinus1[c] ; i++ )
-    {
-        m_postLutCodedValue[c][i]  = SeiCriInput->m_postLutCodedValue[c][i];
-        m_postLutTargetValue[c][i] = SeiCriInput->m_postLutTargetValue[c][i];
-    } 
-  }
-}
-#endif
Index: /branches/SHM-dev/source/Lib/TLibCommon/SEI.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/SEI.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibCommon/SEI.h	(revision 1460)
@@ -459,4 +459,48 @@
 };
 
+#if Q0074_COLOUR_REMAPPING_SEI
+class SEIColourRemappingInfo : public SEI
+{
+public:
+
+  struct CRIlut
+  {
+    Int codedValue;
+    Int targetValue;
+    bool operator < (const CRIlut& a) const
+    {
+      return codedValue < a.codedValue;
+    }
+  };
+
+  PayloadType payloadType() const { return COLOUR_REMAPPING_INFO; }
+  SEIColourRemappingInfo() {}
+  ~SEIColourRemappingInfo() {}
+
+  Void copyFrom( const SEIColourRemappingInfo &seiCriInput)
+  {
+    (*this) = seiCriInput;
+  }
+
+  UInt                m_colourRemapId;
+  Bool                m_colourRemapCancelFlag;
+  Bool                m_colourRemapPersistenceFlag;
+  Bool                m_colourRemapVideoSignalInfoPresentFlag;
+  Bool                m_colourRemapFullRangeFlag;
+  Int                 m_colourRemapPrimaries;
+  Int                 m_colourRemapTransferFunction;
+  Int                 m_colourRemapMatrixCoefficients;
+  Int                 m_colourRemapInputBitDepth;
+  Int                 m_colourRemapBitDepth;
+  Int                 m_preLutNumValMinus1[3];
+  std::vector<CRIlut> m_preLut[3];
+  Bool                m_colourRemapMatrixPresentFlag;
+  Int                 m_log2MatrixDenom;
+  Int                 m_colourRemapCoeffs[3][3];
+  Int                 m_postLutNumValMinus1[3];
+  std::vector<CRIlut> m_postLut[3];
+};
+#endif
+
 class SEIChromaResamplingFilterHint : public SEI
 {
@@ -673,60 +717,4 @@
 #endif
 
-#if Q0074_COLOUR_REMAPPING_SEI
-struct TComSEIColourRemappingInfo
-{
-  std::string             m_colourRemapSEIFile;
-  Int                     m_colourRemapSEIId;
-  Bool                    m_colourRemapSEICancelFlag;
-  Bool                    m_colourRemapSEIPersistenceFlag;
-  Bool                    m_colourRemapSEIVideoSignalInfoPresentFlag;
-  Bool                    m_colourRemapSEIFullRangeFlag;
-  Int                     m_colourRemapSEIPrimaries;
-  Int                     m_colourRemapSEITransferFunction;
-  Int                     m_colourRemapSEIMatrixCoefficients;
-  Int                     m_colourRemapSEIInputBitDepth;
-  Int                     m_colourRemapSEIBitDepth;
-  Int                     m_colourRemapSEIPreLutNumValMinus1[3];
-  Int*                    m_colourRemapSEIPreLutCodedValue[3];
-  Int*                    m_colourRemapSEIPreLutTargetValue[3];
-  Bool                    m_colourRemapSEIMatrixPresentFlag;
-  Int                     m_colourRemapSEILog2MatrixDenom;
-  Int                     m_colourRemapSEICoeffs[3][3];
-  Int                     m_colourRemapSEIPostLutNumValMinus1[3];
-  Int*                    m_colourRemapSEIPostLutCodedValue[3];
-  Int*                    m_colourRemapSEIPostLutTargetValue[3];
-};
-
-class SEIColourRemappingInfo : public SEI
-{
-public:
-  PayloadType payloadType() const { return COLOUR_REMAPPING_INFO; }
-  SEIColourRemappingInfo() {}
-  ~SEIColourRemappingInfo() {}
-
-  Void  copyFrom( SEIColourRemappingInfo const * SeiCriInput);
- 
-  Int   m_colourRemapId;
-  Bool  m_colourRemapCancelFlag;
-  Bool  m_colourRemapPersistenceFlag;
-  Bool  m_colourRemapVideoSignalInfoPresentFlag;
-  Bool  m_colourRemapFullRangeFlag;
-  Int   m_colourRemapPrimaries;
-  Int   m_colourRemapTransferFunction;
-  Int   m_colourRemapMatrixCoefficients;
-  Int   m_colourRemapInputBitDepth;
-  Int   m_colourRemapBitDepth;
-  Int   m_preLutNumValMinus1[3];
-  std::vector<Int> m_preLutCodedValue[3];
-  std::vector<Int> m_preLutTargetValue[3];
-  Bool  m_colourRemapMatrixPresentFlag;
-  Int   m_log2MatrixDenom;
-  Int   m_colourRemapCoeffs[3][3];
-  Int   m_postLutNumValMinus1[3];
-  std::vector<Int> m_postLutCodedValue[3];
-  std::vector<Int> m_postLutTargetValue[3];
-};
-#endif
-
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
 class SEIInterLayerConstrainedTileSets : public SEI
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 1460)
@@ -296,13 +296,20 @@
 
 // NOTE: This function is never called, but may be useful for developers.
-Void TComPicYuv::dump (const std::string &fileName, const BitDepths &bitDepths, Bool bAdd) const
-{
-  FILE* pFile = fopen (fileName.c_str(), bAdd?"ab":"wb");
+Void TComPicYuv::dump (const std::string &fileName, const BitDepths &bitDepths, const Bool bAppend, const Bool bForceTo8Bit) const
+{
+  FILE *pFile = fopen (fileName.c_str(), bAppend?"ab":"wb");
+
+  Bool is16bit=false;
+  for(Int comp = 0; comp < getNumberValidComponents() && !bForceTo8Bit; comp++)
+  {
+    if (bitDepths.recon[toChannelType(ComponentID(comp))]>8)
+    {
+      is16bit=true;
+    }
+  }
 
   for(Int comp = 0; comp < getNumberValidComponents(); comp++)
   {
     const ComponentID  compId = ComponentID(comp);
-    const Int          shift  = bitDepths.recon[toChannelType(compId)] - 8;
-    const Int          offset = (shift>0)?(1<<(shift-1)):0;
     const Pel         *pi     = getAddr(compId);
     const Int          stride = getStride(compId);
@@ -310,51 +317,34 @@
     const Int          width  = getWidth(compId);
 
-    for (Int y = 0; y < height; y++ )
-    {
-      for (Int x = 0; x < width; x++ )
-      {
-        UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift);
-        fwrite( &uc, sizeof(UChar), 1, pFile );
-      }
-      pi += stride;
-    }
-  }
-
-  fclose(pFile);
-}
-
-Void TComPicYuv::dump( const std::string &fileName, const Bool bAdd, const Int bitDepth )
-{
-  FILE* pFile = fopen (fileName.c_str(), bAdd?"ab":"wb");
-
-  if( bitDepth == 8 )
-  {
-    dump( fileName, bitDepth, bAdd );
-    return;
-  }
-
-  for(Int chan = 0; chan < getNumberValidComponents(); chan++)
-  {
-    const ComponentID  ch     = ComponentID(chan);
-    const Pel         *pi     = getAddr(ch);
-    const Int          stride = getStride(ch);
-    const Int          height = getHeight(ch);
-    const Int          width  = getWidth(ch);
-
-    for (Int y = 0; y < height; y++ )
-    {
-      for (Int x = 0; x < width; x++ )
-      {
-        Pel pix = pi[x];
-
-        UChar uc = pix & 0xff;      
-        fwrite( &uc, sizeof(UChar), 1, pFile );
-        uc = (pix >> 8) & 0xff;      
-        fwrite( &uc, sizeof(UChar), 1, pFile );
-      }
-      pi += stride;
-    }
-  }
-  
+    if (is16bit)
+    {
+      for (Int y = 0; y < height; y++ )
+      {
+        for (Int x = 0; x < width; x++ )
+        {
+          UChar uc = (UChar)((pi[x]>>0) & 0xff);
+          fwrite( &uc, sizeof(UChar), 1, pFile );
+          uc = (UChar)((pi[x]>>8) & 0xff);
+          fwrite( &uc, sizeof(UChar), 1, pFile );
+        }
+        pi += stride;
+      }
+    }
+    else
+    {
+      const Int shift  = bitDepths.recon[toChannelType(compId)] - 8;
+      const Int offset = (shift>0)?(1<<(shift-1)):0;
+      for (Int y = 0; y < height; y++ )
+      {
+        for (Int x = 0; x < width; x++ )
+        {
+          UChar uc = (UChar)Clip3<Pel>(0, 255, (pi[x]+offset)>>shift);
+          fwrite( &uc, sizeof(UChar), 1, pFile );
+        }
+        pi += stride;
+      }
+    }
+  }
+
   fclose(pFile);
 }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.h	(revision 1460)
@@ -180,5 +180,5 @@
 
   //  Dump picture
-  Void          dump              (const std::string &fileName, const BitDepths &bitDepths, Bool bAdd = false) const ;
+  Void          dump              (const std::string &fileName, const BitDepths &bitDepths, const Bool bAppend=false, const Bool bForceTo8Bit=false) const ;
 
   // Set border extension flag
@@ -196,6 +196,4 @@
 #endif
 
-  Void          dump( const std::string &fileName, const Bool bAdd, const Int bitDepth );
-
 };// END CLASS DEFINITION TComPicYuv
 
Index: /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h	(revision 1460)
@@ -127,5 +127,4 @@
 
 #endif // SVC_EXTENSION
-#define Q0074_COLOUR_REMAPPING_SEI       1      ///< JCTVC-Q0074, JCTVC-R0344: SEI Colour Remapping Information
 
 //! \ingroup TLibCommon
@@ -166,4 +165,5 @@
 #define T0196_SELECTIVE_RDOQ                              1 ///< selective RDOQ
 #define U0040_MODIFIED_WEIGHTEDPREDICTION_WITH_BIPRED_AND_CLIPPING 1
+#define Q0074_COLOUR_REMAPPING_SEI                        1      ///< JCTVC-Q0074, JCTVC-R0344: SEI Colour Remapping Information
 
 // ====================================================================================================================
@@ -377,4 +377,21 @@
   NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS = 4
 };
+
+#if Q0074_COLOUR_REMAPPING_SEI
+enum MATRIX_COEFFICIENTS // Table E.5 (Matrix coefficients)
+{
+  MATRIX_COEFFICIENTS_RGB                           = 0,
+  MATRIX_COEFFICIENTS_BT709                         = 1,
+  MATRIX_COEFFICIENTS_UNSPECIFIED                   = 2,
+  MATRIX_COEFFICIENTS_RESERVED_BY_ITUISOIEC         = 3,
+  MATRIX_COEFFICIENTS_USFCCT47                      = 4,
+  MATRIX_COEFFICIENTS_BT601_625                     = 5,
+  MATRIX_COEFFICIENTS_BT601_525                     = 6,
+  MATRIX_COEFFICIENTS_SMPTE240                      = 7,
+  MATRIX_COEFFICIENTS_YCGCO                         = 8,
+  MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE = 9,
+  MATRIX_COEFFICIENTS_BT2020_CONSTANT_LUMINANCE     = 10,
+};
+#endif
 
 enum DeblockEdgeDir
Index: /branches/SHM-dev/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/SEIread.cpp	(revision 1460)
@@ -308,8 +308,4 @@
       xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize, pDecodedMessageOutputStream);
       break;
-    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
-      sei = new SEIMasteringDisplayColourVolume;
-      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
-      break;
 #if Q0074_COLOUR_REMAPPING_SEI
     case SEI::COLOUR_REMAPPING_INFO:
@@ -318,4 +314,8 @@
       break;
 #endif
+    case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
+      sei = new SEIMasteringDisplayColourVolume;
+      xParseSEIMasteringDisplayColourVolume((SEIMasteringDisplayColourVolume&) *sei, payloadSize, pDecodedMessageOutputStream);
+      break;
 #if SVC_EXTENSION
 #if LAYERS_NOT_PRESENT_SEI
@@ -1335,31 +1335,10 @@
 }
 
-Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
-{
-  UInt code;
-  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
-
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
-
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
-
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
-
-
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
-  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
-
-  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
-  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
-}
-
 #if Q0074_COLOUR_REMAPPING_SEI
-Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/, std::ostream *pDecodedMessageOutputStream)
+Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
 {
   UInt  uiVal;
   Int   iVal;
+  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
 
   sei_read_uvlc( pDecodedMessageOutputStream, uiVal, "colour_remap_id" );          sei.m_colourRemapId = uiVal;
@@ -1371,29 +1350,30 @@
     if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
     {
-      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );           sei.m_colourRemapFullRangeFlag = uiVal;
-      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                 sei.m_colourRemapPrimaries = uiVal;
-      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );         sei.m_colourRemapTransferFunction = uiVal;
-      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );       sei.m_colourRemapMatrixCoefficients = uiVal;
-    }
-    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" ); sei.m_colourRemapInputBitDepth = uiVal;
-    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" ); sei.m_colourRemapBitDepth = uiVal;
+      sei_read_flag( pDecodedMessageOutputStream, uiVal,    "colour_remap_full_range_flag" );            sei.m_colourRemapFullRangeFlag = uiVal;
+      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_primaries" );                  sei.m_colourRemapPrimaries = uiVal;
+      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_transfer_function" );          sei.m_colourRemapTransferFunction = uiVal;
+      sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_matrix_coefficients" );        sei.m_colourRemapMatrixCoefficients = uiVal;
+    }
+    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_input_bit_depth" );              sei.m_colourRemapInputBitDepth = uiVal;
+    sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "colour_remap_bit_depth" );                    sei.m_colourRemapBitDepth = uiVal;
   
     for( Int c=0 ; c<3 ; c++ )
     {
       sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
-      sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
-      sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1);
+      sei.m_preLut[c].resize(sei.m_preLutNumValMinus1[c]+1);
       if( uiVal> 0 )
+      {
         for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
         {
-          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLutCodedValue[c][i]  = uiVal;
-          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal;
-        }
+          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapInputBitDepth   + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" );  sei.m_preLut[c][i].codedValue  = uiVal;
+          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLut[c][i].targetValue = uiVal;
+        }
+      }
       else // pre_lut_num_val_minus1[c] == 0
       {
-        sei.m_preLutCodedValue[c][0]  = 0;
-        sei.m_preLutTargetValue[c][0] = 0;
-        sei.m_preLutCodedValue[c][1]  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
-        sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1 ;
+        sei.m_preLut[c][0].codedValue  = 0;
+        sei.m_preLut[c][0].targetValue = 0;
+        sei.m_preLut[c][1].codedValue  = (1 << sei.m_colourRemapInputBitDepth) - 1 ;
+        sei.m_preLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1 ;
       }
     }
@@ -1404,39 +1384,67 @@
       sei_read_code( pDecodedMessageOutputStream, 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal;
       for ( Int c=0 ; c<3 ; c++ )
+      {
         for ( Int i=0 ; i<3 ; i++ )
         {
           sei_read_svlc( pDecodedMessageOutputStream, iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal;
         }
+      }
     }
     else // setting default matrix (I3)
     {
-      sei.m_log2MatrixDenom = 0;
+      sei.m_log2MatrixDenom = 10;
       for ( Int c=0 ; c<3 ; c++ )
+      {
         for ( Int i=0 ; i<3 ; i++ )
-          sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0;
+        {
+          sei.m_colourRemapCoeffs[c][i] = (c==i) << sei.m_log2MatrixDenom;
+        }
+      }
     }
     for( Int c=0 ; c<3 ; c++ )
     {
       sei_read_code( pDecodedMessageOutputStream, 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal;
-      sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
-      sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1);
+      sei.m_postLut[c].resize(sei.m_postLutNumValMinus1[c]+1);
       if( uiVal > 0 )
+      {
         for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
         {
-          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLutCodedValue[c][i] = uiVal;
-          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal;
-        }
+          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" );  sei.m_postLut[c][i].codedValue = uiVal;
+          sei_read_code( pDecodedMessageOutputStream, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLut[c][i].targetValue = uiVal;
+        }
+      }
       else
       {
-        sei.m_postLutCodedValue[c][0]  = 0;
-        sei.m_postLutTargetValue[c][0] = 0;
-        sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapBitDepth) - 1;
-        sei.m_postLutCodedValue[c][1]  = (1 << sei.m_colourRemapBitDepth) - 1;
-      }
-    }
-  }
-}
-#endif
-
+        sei.m_postLut[c][0].codedValue  = 0;
+        sei.m_postLut[c][0].targetValue = 0;
+        sei.m_postLut[c][1].targetValue = (1 << sei.m_colourRemapBitDepth) - 1;
+        sei.m_postLut[c][1].codedValue  = (1 << sei.m_colourRemapBitDepth) - 1;
+      }
+    }
+  }
+}
+#endif
+
+Void SEIReader::xParseSEIMasteringDisplayColourVolume(SEIMasteringDisplayColourVolume& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
+{
+  UInt code;
+  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
+
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[0]" ); sei.values.primaries[0][0] = code;
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[0]" ); sei.values.primaries[0][1] = code;
+
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[1]" ); sei.values.primaries[1][0] = code;
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[1]" ); sei.values.primaries[1][1] = code;
+
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_x[2]" ); sei.values.primaries[2][0] = code;
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "display_primaries_y[2]" ); sei.values.primaries[2][1] = code;
+
+
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_x" ); sei.values.whitePoint[0] = code;
+  sei_read_code( pDecodedMessageOutputStream, 16, code, "white_point_y" ); sei.values.whitePoint[1] = code;
+
+  sei_read_code( pDecodedMessageOutputStream, 32, code, "max_display_mastering_luminance" ); sei.values.maxLuminance = code;
+  sei_read_code( pDecodedMessageOutputStream, 32, code, "min_display_mastering_luminance" ); sei.values.minLuminance = code;
+}
 
 #if SVC_EXTENSION
Index: /branches/SHM-dev/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/SEIread.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/SEIread.h	(revision 1460)
@@ -108,4 +108,7 @@
   Void xParseSEIKneeFunctionInfo              (SEIKneeFunctionInfo& sei,              UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
   Void xParseSEIMasteringDisplayColourVolume  (SEIMasteringDisplayColourVolume& sei,  UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
+#if Q0074_COLOUR_REMAPPING_SEI
+  Void xParseSEIColourRemappingInfo           (SEIColourRemappingInfo& sei,           UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
+#endif
 
   Void sei_read_code(std::ostream *pOS, UInt uiLength, UInt& ruiCode, const TChar *pSymbolName);
@@ -114,7 +117,4 @@
   Void sei_read_flag(std::ostream *pOS,                UInt& ruiCode, const TChar *pSymbolName);
 
-#if Q0074_COLOUR_REMAPPING_SEI
-  Void xParseSEIColourRemappingInfo           (SEIColourRemappingInfo& sei,           UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
-#endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   Void xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
Index: /branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.cpp	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.cpp	(revision 1460)
@@ -421,4 +421,178 @@
 }
 
+#if Q0074_COLOUR_REMAPPING_SEI
+template <typename T>
+static Void readTokenValue(T            &returnedValue, /// value returned
+                           Bool         &failed,        /// used and updated
+                           std::istream &is,            /// stream to read token from
+                           const TChar  *pToken)        /// token string
+{
+  returnedValue=T();
+  if (failed)
+  {
+    return;
+  }
+
+  Int c;
+  // Ignore any whitespace
+  while ((c=is.get())!=EOF && isspace(c));
+  // test for comment mark
+  while (c=='#')
+  {
+    // Ignore to the end of the line
+    while ((c=is.get())!=EOF && (c!=10 && c!=13));
+    // Ignore any white space at the start of the next line
+    while ((c=is.get())!=EOF && isspace(c));
+  }
+  // test first character of token
+  failed=(c!=pToken[0]);
+  // test remaining characters of token
+  Int pos;
+  for(pos=1;!failed && pToken[pos]!=0 && is.get()==pToken[pos]; pos++);
+  failed|=(pToken[pos]!=0);
+  // Ignore any whitespace before the ':'
+  while (!failed && (c=is.get())!=EOF && isspace(c));
+  failed|=(c!=':');
+  // Now read the value associated with the token:
+  if (!failed)
+  {
+    is >> returnedValue;
+    failed=!is.good();
+    if (!failed)
+    {
+      c=is.get();
+      failed=(c!=EOF && !isspace(c));
+    }
+  }
+  if (failed)
+  {
+    std::cerr << "Unable to read token '" << pToken << "'\n";
+  }
+}
+
+template <typename T>
+static Void readTokenValueAndValidate(T            &returnedValue, /// value returned
+                                      Bool         &failed,        /// used and updated
+                                      std::istream &is,            /// stream to read token from
+                                      const TChar  *pToken,        /// token string
+                                      const T      &minInclusive,  /// minimum value allowed, inclusive
+                                      const T      &maxInclusive)  /// maximum value allowed, inclusive
+{
+  readTokenValue(returnedValue, failed, is, pToken);
+  if (!failed)
+  {
+    if (returnedValue<minInclusive || returnedValue>maxInclusive)
+    {
+      failed=true;
+      std::cerr << "Value for token " << pToken << " must be in the range " << minInclusive << " to " << maxInclusive << " (inclusive); value read: " << returnedValue << std::endl;
+    }
+  }
+}
+
+// Bool version does not have maximum and minimum values.
+static Void readTokenValueAndValidate(Bool         &returnedValue, /// value returned
+                                      Bool         &failed,        /// used and updated
+                                      std::istream &is,            /// stream to read token from
+                                      const TChar  *pToken)        /// token string
+{
+  readTokenValue(returnedValue, failed, is, pToken);
+}
+
+Bool SEIEncoder::initSEIColourRemappingInfo(SEIColourRemappingInfo* seiColourRemappingInfo, Int currPOC) // returns true on success, false on failure.
+{
+  assert (m_isInitialized);
+  assert (seiColourRemappingInfo!=NULL);
+
+  // reading external Colour Remapping Information SEI message parameters from file
+  if( !m_pcCfg->getColourRemapInfoSEIFileRoot().empty())
+  {
+    Bool failed=false;
+
+    // building the CRI file name with poc num in prefix "_poc.txt"
+    std::string colourRemapSEIFileWithPoc(m_pcCfg->getColourRemapInfoSEIFileRoot());
+    {
+      std::stringstream suffix;
+      suffix << "_" << currPOC << ".txt";
+      colourRemapSEIFileWithPoc+=suffix.str();
+    }
+
+    std::ifstream fic(colourRemapSEIFileWithPoc.c_str());
+    if (!fic.good() || !fic.is_open())
+    {
+      std::cerr <<  "No Colour Remapping Information SEI parameters file " << colourRemapSEIFileWithPoc << " for POC " << currPOC << std::endl;
+      return false;
+    }
+
+    // TODO: identify and remove duplication with decoder parsing through abstraction.
+
+    readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapId,         failed, fic, "colour_remap_id",        UInt(0), UInt(0x7fffffff) );
+    readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapCancelFlag, failed, fic, "colour_remap_cancel_flag" );
+    if( !seiColourRemappingInfo->m_colourRemapCancelFlag )
+    {
+      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapPersistenceFlag,            failed, fic, "colour_remap_persistence_flag" );
+      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag, failed, fic, "colour_remap_video_signal_info_present_flag");
+      if( seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag )
+      {
+        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapFullRangeFlag,      failed, fic, "colour_remap_full_range_flag" );
+        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapPrimaries,          failed, fic, "colour_remap_primaries",           Int(0), Int(255) );
+        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapTransferFunction,   failed, fic, "colour_remap_transfer_function",   Int(0), Int(255) );
+        readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapMatrixCoefficients, failed, fic, "colour_remap_matrix_coefficients", Int(0), Int(255) );
+      }
+      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapInputBitDepth, failed, fic, "colour_remap_input_bit_depth",            Int(8), Int(16) );
+      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapBitDepth,      failed, fic, "colour_remap_bit_depth",                  Int(8), Int(16) );
+
+      const Int maximumInputValue    = (1<<seiColourRemappingInfo->m_colourRemapInputBitDepth)-1;
+      const Int maximumRemappedValue = (1<<seiColourRemappingInfo->m_colourRemapBitDepth)-1;
+
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        readTokenValueAndValidate(seiColourRemappingInfo->m_preLutNumValMinus1[c],         failed, fic, "pre_lut_num_val_minus1[c]",        Int(0), Int(32) );
+        if( seiColourRemappingInfo->m_preLutNumValMinus1[c]>0 )
+        {
+          seiColourRemappingInfo->m_preLut[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
+          for( Int i=0 ; i<=seiColourRemappingInfo->m_preLutNumValMinus1[c] ; i++ )
+          {
+            readTokenValueAndValidate(seiColourRemappingInfo->m_preLut[c][i].codedValue,   failed, fic, "pre_lut_coded_value[c][i]",  Int(0), maximumInputValue    );
+            readTokenValueAndValidate(seiColourRemappingInfo->m_preLut[c][i].targetValue,  failed, fic, "pre_lut_target_value[c][i]", Int(0), maximumRemappedValue );
+          }
+        }
+      }
+      readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapMatrixPresentFlag, failed, fic, "colour_remap_matrix_present_flag" );
+      if( seiColourRemappingInfo->m_colourRemapMatrixPresentFlag )
+      {
+        readTokenValueAndValidate(seiColourRemappingInfo->m_log2MatrixDenom, failed, fic, "log2_matrix_denom", Int(0), Int(15) );
+        for( Int c=0 ; c<3 ; c++ )
+        {
+          for( Int i=0 ; i<3 ; i++ )
+          {
+            readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapCoeffs[c][i], failed, fic, "colour_remap_coeffs[c][i]", -32768, 32767 );
+          }
+        }
+      }
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        readTokenValueAndValidate(seiColourRemappingInfo->m_postLutNumValMinus1[c], failed, fic, "post_lut_num_val_minus1[c]", Int(0), Int(32) );
+        if( seiColourRemappingInfo->m_postLutNumValMinus1[c]>0 )
+        {
+          seiColourRemappingInfo->m_postLut[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
+          for( Int i=0 ; i<=seiColourRemappingInfo->m_postLutNumValMinus1[c] ; i++ )
+          {
+            readTokenValueAndValidate(seiColourRemappingInfo->m_postLut[c][i].codedValue,  failed, fic, "post_lut_coded_value[c][i]",  Int(0), maximumRemappedValue );
+            readTokenValueAndValidate(seiColourRemappingInfo->m_postLut[c][i].targetValue, failed, fic, "post_lut_target_value[c][i]", Int(0), maximumRemappedValue );
+          }
+        }
+      }
+    }
+
+    if( failed )
+    {
+      std::cerr << "Error while reading Colour Remapping Information SEI parameters file '" << colourRemapSEIFileWithPoc << "'" << std::endl;
+      exit(EXIT_FAILURE);
+    }
+  }
+  return true;
+}
+#endif
+
 Void SEIEncoder::initSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint *seiChromaResamplingFilterHint, Int iHorFilterIndex, Int iVerFilterIndex)
 {
@@ -646,65 +820,4 @@
 #endif
 
-#if Q0074_COLOUR_REMAPPING_SEI
-Void SEIEncoder::initSEIColourRemappingInfo(SEIColourRemappingInfo *seiColourRemappingInfo, TComSEIColourRemappingInfo* cfgSeiColourRemappingInfo)
-{
-  seiColourRemappingInfo->m_colourRemapId         = cfgSeiColourRemappingInfo->m_colourRemapSEIId;
-  seiColourRemappingInfo->m_colourRemapCancelFlag = cfgSeiColourRemappingInfo->m_colourRemapSEICancelFlag;
-  printf("xCreateSEIColourRemappingInfo - m_colourRemapId = %d m_colourRemapCancelFlag = %d \n",seiColourRemappingInfo->m_colourRemapId, seiColourRemappingInfo->m_colourRemapCancelFlag); 
-
-  if( !seiColourRemappingInfo->m_colourRemapCancelFlag )
-  {
-    seiColourRemappingInfo->m_colourRemapPersistenceFlag            = cfgSeiColourRemappingInfo->m_colourRemapSEIPersistenceFlag;
-    seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag = cfgSeiColourRemappingInfo->m_colourRemapSEIVideoSignalInfoPresentFlag;
-    if( seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag )
-    {
-      seiColourRemappingInfo->m_colourRemapFullRangeFlag           = cfgSeiColourRemappingInfo->m_colourRemapSEIFullRangeFlag;
-      seiColourRemappingInfo->m_colourRemapPrimaries               = cfgSeiColourRemappingInfo->m_colourRemapSEIPrimaries;
-      seiColourRemappingInfo->m_colourRemapTransferFunction        = cfgSeiColourRemappingInfo->m_colourRemapSEITransferFunction;
-      seiColourRemappingInfo->m_colourRemapMatrixCoefficients      = cfgSeiColourRemappingInfo->m_colourRemapSEIMatrixCoefficients;
-    }
-    seiColourRemappingInfo->m_colourRemapInputBitDepth             = cfgSeiColourRemappingInfo->m_colourRemapSEIInputBitDepth;
-    seiColourRemappingInfo->m_colourRemapBitDepth                  = cfgSeiColourRemappingInfo->m_colourRemapSEIBitDepth;
-    for( Int c=0 ; c<3 ; c++ )
-    {
-      seiColourRemappingInfo->m_preLutNumValMinus1[c] = cfgSeiColourRemappingInfo->m_colourRemapSEIPreLutNumValMinus1[c];
-      if( seiColourRemappingInfo->m_preLutNumValMinus1[c]>0 )
-      {
-        seiColourRemappingInfo->m_preLutCodedValue[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
-        seiColourRemappingInfo->m_preLutTargetValue[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1);
-        for( Int i=0 ; i<=seiColourRemappingInfo->m_preLutNumValMinus1[c] ; i++)
-        {
-          seiColourRemappingInfo->m_preLutCodedValue[c][i]  = cfgSeiColourRemappingInfo->m_colourRemapSEIPreLutCodedValue[c][i];
-          seiColourRemappingInfo->m_preLutTargetValue[c][i] = cfgSeiColourRemappingInfo->m_colourRemapSEIPreLutTargetValue[c][i];
-        }
-      }
-    }
-    seiColourRemappingInfo->m_colourRemapMatrixPresentFlag = cfgSeiColourRemappingInfo->m_colourRemapSEIMatrixPresentFlag;
-    if( seiColourRemappingInfo->m_colourRemapMatrixPresentFlag )
-    {
-      seiColourRemappingInfo->m_log2MatrixDenom = cfgSeiColourRemappingInfo->m_colourRemapSEILog2MatrixDenom;
-      for( Int c=0 ; c<3 ; c++ )
-        for( Int i=0 ; i<3 ; i++ )
-          seiColourRemappingInfo->m_colourRemapCoeffs[c][i] = cfgSeiColourRemappingInfo->m_colourRemapSEICoeffs[c][i];
-    }
-    for( Int c=0 ; c<3 ; c++ )
-    {
-      seiColourRemappingInfo->m_postLutNumValMinus1[c] = cfgSeiColourRemappingInfo->m_colourRemapSEIPostLutNumValMinus1[c];
-      if( seiColourRemappingInfo->m_postLutNumValMinus1[c]>0 )
-      {
-        seiColourRemappingInfo->m_postLutCodedValue[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
-        seiColourRemappingInfo->m_postLutTargetValue[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1);
-        for( Int i=0 ; i<=seiColourRemappingInfo->m_postLutNumValMinus1[c] ; i++)
-        {
-          seiColourRemappingInfo->m_postLutCodedValue[c][i]  = cfgSeiColourRemappingInfo->m_colourRemapSEIPostLutCodedValue[c][i];
-          seiColourRemappingInfo->m_postLutTargetValue[c][i] = cfgSeiColourRemappingInfo->m_colourRemapSEIPostLutTargetValue[c][i];
-        }
-      }
-    }
-  }
-}
-#endif
-
-
 #if O0164_MULTI_LAYER_HRD
 Void SEIEncoder::initBspNestingSEI(SEIScalableNesting *seiScalableNesting, const TComVPS *vps, const TComSPS *sps, Int olsIdx, Int partitioningSchemeIdx, Int bspIdx)
Index: /branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/SEIEncoder.h	(revision 1460)
@@ -81,4 +81,7 @@
   Void initSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint *sei, Int iHorFilterIndex, Int iVerFilterIndex);
   Void initSEITimeCode(SEITimeCode *sei);
+#if Q0074_COLOUR_REMAPPING_SEI
+  Bool initSEIColourRemappingInfo(SEIColourRemappingInfo *sei, Int currPOC); // returns true on success, false on failure.
+#endif
 
 #if LAYERS_NOT_PRESENT_SEI
@@ -93,7 +96,4 @@
 #if Q0096_OVERLAY_SEI
   Void initSEIOverlayInfo(SEIOverlayInfo *seiOverlayInfo);
-#endif
-#if Q0074_COLOUR_REMAPPING_SEI
-  Void initSEIColourRemappingInfo(SEIColourRemappingInfo *seiColourRemappingInfo, TComSEIColourRemappingInfo* cfgSeiColourRemappingInfo);
 #endif
 #if O0164_MULTI_LAYER_HRD
Index: /branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 1460)
@@ -152,7 +152,4 @@
     xWriteSEIKneeFunctionInfo(*static_cast<const SEIKneeFunctionInfo*>(&sei));
     break;
-  case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
-    xWriteSEIMasteringDisplayColourVolume(*static_cast<const SEIMasteringDisplayColourVolume*>(&sei));
-    break;
 #if Q0074_COLOUR_REMAPPING_SEI
   case SEI::COLOUR_REMAPPING_INFO:
@@ -160,4 +157,7 @@
     break;
 #endif
+  case SEI::MASTERING_DISPLAY_COLOUR_VOLUME:
+    xWriteSEIMasteringDisplayColourVolume(*static_cast<const SEIMasteringDisplayColourVolume*>(&sei));
+    break;
 #if SVC_EXTENSION
 #if LAYERS_NOT_PRESENT_SEI
@@ -987,4 +987,62 @@
 }
 
+#if Q0074_COLOUR_REMAPPING_SEI
+Void SEIWriter::xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei)
+{
+  WRITE_UVLC( sei.m_colourRemapId,                             "colour_remap_id" );
+  WRITE_FLAG( sei.m_colourRemapCancelFlag,                     "colour_remap_cancel_flag" );
+  if( !sei.m_colourRemapCancelFlag ) 
+  {
+    WRITE_FLAG( sei.m_colourRemapPersistenceFlag,              "colour_remap_persistence_flag" );
+    WRITE_FLAG( sei.m_colourRemapVideoSignalInfoPresentFlag,   "colour_remap_video_signal_info_present_flag" );
+    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
+    {
+      WRITE_FLAG( sei.m_colourRemapFullRangeFlag,              "colour_remap_full_range_flag" );
+      WRITE_CODE( sei.m_colourRemapPrimaries,               8, "colour_remap_primaries" );
+      WRITE_CODE( sei.m_colourRemapTransferFunction,        8, "colour_remap_transfer_function" );
+      WRITE_CODE( sei.m_colourRemapMatrixCoefficients,      8, "colour_remap_matrix_coefficients" );
+    }
+    WRITE_CODE( sei.m_colourRemapInputBitDepth,             8, "colour_remap_input_bit_depth" );
+    WRITE_CODE( sei.m_colourRemapBitDepth,                  8, "colour_remap_bit_depth" );
+    for( Int c=0 ; c<3 ; c++ )
+    {
+      WRITE_CODE( sei.m_preLutNumValMinus1[c],              8, "pre_lut_num_val_minus1[c]" );
+      if( sei.m_preLutNumValMinus1[c]>0 )
+      {
+        for( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
+        {
+          WRITE_CODE( sei.m_preLut[c][i].codedValue,  (( sei.m_colourRemapInputBitDepth + 7 ) >> 3 ) << 3, "pre_lut_coded_value[c][i]" );
+          WRITE_CODE( sei.m_preLut[c][i].targetValue, (( sei.m_colourRemapBitDepth      + 7 ) >> 3 ) << 3, "pre_lut_target_value[c][i]" );
+        }
+      }
+    }
+    WRITE_FLAG( sei.m_colourRemapMatrixPresentFlag,            "colour_remap_matrix_present_flag" );
+    if( sei.m_colourRemapMatrixPresentFlag )
+    {
+      WRITE_CODE( sei.m_log2MatrixDenom,                    4, "log2_matrix_denom" );
+      for( Int c=0 ; c<3 ; c++ )
+      {
+        for( Int i=0 ; i<3 ; i++ )
+        {
+          WRITE_SVLC( sei.m_colourRemapCoeffs[c][i],           "colour_remap_coeffs[c][i]" );
+        }
+      }
+    }
+
+    for( Int c=0 ; c<3 ; c++ )
+    {
+      WRITE_CODE( sei.m_postLutNumValMinus1[c],             8, "m_postLutNumValMinus1[c]" );
+      if( sei.m_postLutNumValMinus1[c]>0 )
+      {
+        for( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
+        {
+          WRITE_CODE( sei.m_postLut[c][i].codedValue, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_coded_value[c][i]" );
+          WRITE_CODE( sei.m_postLut[c][i].targetValue, (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_target_value[c][i]" );
+        }
+      }
+    }
+  }
+}
+#endif
 
 Void SEIWriter::xWriteSEIMasteringDisplayColourVolume(const SEIMasteringDisplayColourVolume& sei)
@@ -1326,54 +1384,3 @@
 #endif //SVC_EXTENSION
 
-#if Q0074_COLOUR_REMAPPING_SEI
-Void SEIWriter::xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei)
-{
-  WRITE_UVLC( sei.m_colourRemapId,                             "colour_remap_id" );
-  WRITE_FLAG( sei.m_colourRemapCancelFlag,                     "colour_remap_cancel_flag" );
-  if( !sei.m_colourRemapCancelFlag ) 
-  {
-    WRITE_FLAG( sei.m_colourRemapPersistenceFlag,              "colour_remap_persistence_flag" );
-    WRITE_FLAG( sei.m_colourRemapVideoSignalInfoPresentFlag,   "colour_remap_video_signal_info_present_flag" );
-    if ( sei.m_colourRemapVideoSignalInfoPresentFlag )
-    {
-      WRITE_FLAG( sei.m_colourRemapFullRangeFlag,              "colour_remap_full_range_flag" );
-      WRITE_CODE( sei.m_colourRemapPrimaries,               8, "colour_remap_primaries" );
-      WRITE_CODE( sei.m_colourRemapTransferFunction,        8, "colour_remap_transfer_function" );
-      WRITE_CODE( sei.m_colourRemapMatrixCoefficients,      8, "colour_remap_matrix_coefficients" );
-    }
-    WRITE_CODE( sei.m_colourRemapInputBitDepth,             8, "colour_remap_input_bit_depth" );
-    WRITE_CODE( sei.m_colourRemapBitDepth,                  8, "colour_remap_bit_depth" );
-    for( Int c=0 ; c<3 ; c++ )
-    {
-      WRITE_CODE( sei.m_preLutNumValMinus1[c],              8, "pre_lut_num_val_minus1[c]" );
-      if( sei.m_preLutNumValMinus1[c]>0 )
-        for( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ )
-        {
-          WRITE_CODE( sei.m_preLutCodedValue[c][i], (( sei.m_colourRemapInputBitDepth + 7 ) >> 3 ) << 3, "pre_lut_coded_value[c][i]" );
-          WRITE_CODE( sei.m_preLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "pre_lut_target_value[c][i]" );
-        }
-    }
-    WRITE_FLAG( sei.m_colourRemapMatrixPresentFlag,            "colour_remap_matrix_present_flag" );
-    if( sei.m_colourRemapMatrixPresentFlag )
-    {
-      WRITE_CODE( sei.m_log2MatrixDenom,                    4, "log2_matrix_denom" );
-      for( Int c=0 ; c<3 ; c++ )
-        for( Int i=0 ; i<3 ; i++ )
-          WRITE_SVLC( sei.m_colourRemapCoeffs[c][i],           "colour_remap_coeffs[c][i]" );
-    }
-
-    for( Int c=0 ; c<3 ; c++ )
-    {
-      WRITE_CODE( sei.m_postLutNumValMinus1[c],             8, "m_postLutNumValMinus1[c]" );
-      if( sei.m_postLutNumValMinus1[c]>0 )
-        for( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ )
-        {
-          WRITE_CODE( sei.m_postLutCodedValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_coded_value[c][i]" );       
-          WRITE_CODE( sei.m_postLutTargetValue[c][i], (( sei.m_colourRemapBitDepth + 7 ) >> 3 ) << 3, "post_lut_target_value[c][i]" );
-        }
-    }
-  }
-}
-#endif
-
 //! \}
Index: /branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/SEIwrite.h	(revision 1460)
@@ -89,4 +89,7 @@
   Void xWriteSEIChromaResamplingFilterHint(const SEIChromaResamplingFilterHint& sei);
   Void xWriteSEIKneeFunctionInfo(const SEIKneeFunctionInfo &sei);
+#if Q0074_COLOUR_REMAPPING_SEI
+  Void xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei);
+#endif
   Void xWriteSEIMasteringDisplayColourVolume( const SEIMasteringDisplayColourVolume& sei);
 
@@ -97,7 +100,5 @@
 #endif
   Void xWriteByteAlign();
-#if Q0074_COLOUR_REMAPPING_SEI
-  Void xWriteSEIColourRemappingInfo(const SEIColourRemappingInfo& sei);
-#endif
+
 #if SVC_EXTENSION
 #if LAYERS_NOT_PRESENT_SEI
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 1460)
@@ -321,4 +321,7 @@
   Int*      m_kneeSEIInputKneePoint;
   Int*      m_kneeSEIOutputKneePoint;
+#if Q0074_COLOUR_REMAPPING_SEI
+  std::string m_colourRemapSEIFileRoot;          ///< SEI Colour Remapping File (initialized from external file)
+#endif
   TComSEIMasteringDisplay m_masteringDisplay;
   //====== Weighted Prediction ========
@@ -907,4 +910,8 @@
   Void  setKneeSEIOutputKneePoint(Int *p)                            { m_kneeSEIOutputKneePoint = p; }
   Int*  getKneeSEIOutputKneePoint()                                  { return m_kneeSEIOutputKneePoint; }
+#if Q0074_COLOUR_REMAPPING_SEI
+  Void  setColourRemapInfoSEIFileRoot( const std::string &s )        { m_colourRemapSEIFileRoot = s; }
+  const std::string &getColourRemapInfoSEIFileRoot() const           { return m_colourRemapSEIFileRoot; }
+#endif
   Void  setMasteringDisplaySEI(const TComSEIMasteringDisplay &src)   { m_masteringDisplay = src; }
   const TComSEIMasteringDisplay &getMasteringDisplaySEI() const      { return m_masteringDisplay; }
@@ -1099,8 +1106,4 @@
   Bool  getAlphaClipTypeFlag()                               { return m_alphaClipTypeFlag; }
 #endif
-#if Q0074_COLOUR_REMAPPING_SEI
-  Void  xSetCRISEIFileRoot( std::string pch )                { m_colourRemapSEIFileName = pch; }
-  std::string& getCRISEIFileRoot()                           { return m_colourRemapSEIFileName; }
-#endif
 #if SVC_EXTENSION
   UInt      getLayerId()                                     { return m_layerId;    }
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1460)
@@ -117,11 +117,4 @@
   m_prevPicHasEos    = false;
 #endif //SVC_EXTENSION
-
-#if Q0074_COLOUR_REMAPPING_SEI
-  memset( m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue,   0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue));
-  memset( m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue,  0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue));
-  memset( m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue,  0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue));
-  memset( m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue, 0, sizeof(m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue));
-#endif
   return;
 }
@@ -702,159 +695,4 @@
 }
 
-#if Q0074_COLOUR_REMAPPING_SEI
-Void TEncGOP::xFreeColourCRI()
-{
-  for( Int c=0 ; c<3 ; c++)
-  {
-    if ( m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c] != NULL)
-    {
-      delete[] m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c];
-      m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c] = NULL;
-    }
-    if ( m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c] != NULL)
-    {
-      delete[] m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c];
-      m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c] = NULL;
-    }
-    if ( m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c] != NULL)
-    {
-      delete[] m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c];
-      m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c] = NULL;
-    }
-    if ( m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c] != NULL)
-    {
-      delete[] m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c];
-      m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c] = NULL;
-    }
-  }
-}
-
-Int TEncGOP::xReadingCRIparameters(){
-
-  // reading external Colour Remapping Information SEI message parameters from file
-  if( m_seiColourRemappingInfo.m_colourRemapSEIFile.c_str() )
-  {
-    FILE* fic;
-    Int retval;
-    if((fic = fopen(m_seiColourRemappingInfo.m_colourRemapSEIFile.c_str(),"r")) == (FILE*)NULL)
-    {
-      //fprintf(stderr, "Can't open Colour Remapping Information SEI parameters file %s\n", m_colourRemapSEIFile.c_str());
-      //exit(EXIT_FAILURE);
-      return (-1);
-    }
-    Int tempCode;
-    retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIId );
-    retval = fscanf( fic, "%d", &tempCode ); m_seiColourRemappingInfo.m_colourRemapSEICancelFlag = tempCode ? 1 : 0;
-    if( !m_seiColourRemappingInfo.m_colourRemapSEICancelFlag )
-    {
-      retval = fscanf( fic, "%d", &tempCode ); m_seiColourRemappingInfo.m_colourRemapSEIPersistenceFlag= tempCode ? 1 : 0;
-      retval = fscanf( fic, "%d", &tempCode); m_seiColourRemappingInfo.m_colourRemapSEIVideoSignalInfoPresentFlag = tempCode ? 1 : 0;
-      if( m_seiColourRemappingInfo.m_colourRemapSEIVideoSignalInfoPresentFlag )
-      {
-        retval = fscanf( fic, "%d", &tempCode  ); m_seiColourRemappingInfo.m_colourRemapSEIFullRangeFlag = tempCode ? 1 : 0;
-        retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPrimaries );
-        retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEITransferFunction );
-        retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIMatrixCoefficients );
-      }
-
-      retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth );
-      retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIBitDepth );
-  
-      for( Int c=0 ; c<3 ; c++ )
-      {
-        retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] );
-        if( m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]>0 )
-        {
-          m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c]  = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]+1];
-          m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c] = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]+1];
-          for( Int i=0 ; i<=m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] ; i++ )
-          {
-            retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c][i] );
-            retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c][i] );
-          }
-        }
-      }
-
-      retval = fscanf( fic, "%d", &tempCode ); m_seiColourRemappingInfo.m_colourRemapSEIMatrixPresentFlag = tempCode ? 1 : 0;
-      if( m_seiColourRemappingInfo.m_colourRemapSEIMatrixPresentFlag )
-      {
-        retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEILog2MatrixDenom );
-        for( Int c=0 ; c<3 ; c++ )
-        {
-          for( Int i=0 ; i<3 ; i++ )
-          {
-            retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEICoeffs[c][i] );
-          }
-        }
-      }
-
-      for( Int c=0 ; c<3 ; c++ )
-      {
-        retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] );
-        if( m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]>0 )
-        {
-          m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c]  = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]+1];
-          m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c] = new Int[m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]+1];
-          for( Int i=0 ; i<= m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] ; i++ )
-          {
-            retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c][i] );
-            retval = fscanf( fic, "%d", &m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c][i] );
-          }
-        }
-      }
-    }
-
-    fclose( fic );
-    if( retval != 1 )
-    {
-      fprintf(stderr, "Error while reading Colour Remapping Information SEI parameters file\n");
-      exit(EXIT_FAILURE);
-    }
-  }
-  return 1;
-}
-
-Bool confirmParameter(Bool bflag, const TChar* message);
-// ====================================================================================================================
-// Private member functions
-// ====================================================================================================================
-
-Void TEncGOP::xCheckParameter()
-{
-  Bool check_failed = false; /* abort if there is a fatal configuration problem */
-#define xConfirmParameter(a,b) check_failed |= confirmParameter(a,b)
-
-  if ( m_seiColourRemappingInfo.m_colourRemapSEIFile.c_str() && !m_seiColourRemappingInfo.m_colourRemapSEICancelFlag )
-  {
-    xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth < 8 || m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth > 16 , "colour_remap_coded_data_bit_depth shall be in the range of 8 to 16, inclusive");
-    xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIBitDepth < 8 || (m_seiColourRemappingInfo.m_colourRemapSEIBitDepth > 16 && m_seiColourRemappingInfo.m_colourRemapSEIBitDepth < 255) , "colour_remap_target_bit_depth shall be in the range of 8 to 16, inclusive");
-    for( Int c=0 ; c<3 ; c++)
-    {
-      xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] > 32, "pre_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
-      if( m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c]>0 )
-        for( Int i=0 ; i<= m_seiColourRemappingInfo.m_colourRemapSEIPreLutNumValMinus1[c] ; i++)
-        {
-          xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPreLutCodedValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIInputBitDepth)-1), "pre_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_coded_data_bit_depth)-1, inclusive");
-          xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPreLutTargetValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIBitDepth)-1), "pre_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive");
-        }
-      xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] > 32, "post_lut_num_val_minus1[c] shall be in the range of 0 to 32, inclusive");
-      if( m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c]>0 )
-        for( Int i=0 ; i<= m_seiColourRemappingInfo.m_colourRemapSEIPostLutNumValMinus1[c] ; i++)
-        {
-          xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPostLutCodedValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIBitDepth)-1), "post_lut_coded_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive");
-          xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c][i] < 0 || m_seiColourRemappingInfo.m_colourRemapSEIPostLutTargetValue[c][i] > ((1<<m_seiColourRemappingInfo.m_colourRemapSEIBitDepth)-1), "post_lut_target_value[c][i] shall be in the range of 0 to (1<<colour_remap_target_bit_depth)-1, inclusive");
-        }
-    }
-    if ( m_seiColourRemappingInfo.m_colourRemapSEIMatrixPresentFlag )
-    {
-      xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEILog2MatrixDenom < 0 || m_seiColourRemappingInfo.m_colourRemapSEILog2MatrixDenom > 15, "log2_matrix_denom shall be in the range of 0 to 15, inclusive");
-      for( Int c=0 ; c<3 ; c++)
-        for( Int i=0 ; i<3 ; i++)
-          xConfirmParameter( m_seiColourRemappingInfo.m_colourRemapSEICoeffs[c][i] < -32768 || m_seiColourRemappingInfo.m_colourRemapSEICoeffs[c][i] > 32767, "colour_remap_coeffs[c][i] shall be in the range of -32768 and 32767, inclusive");
-    }
-  }
-}
-#endif
-
 Void TEncGOP::xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice)
 {
@@ -912,4 +750,22 @@
   }
 
+#if Q0074_COLOUR_REMAPPING_SEI
+  // insert one Colour Remapping Info SEI for the picture (if the file exists)
+  if (!m_pcCfg->getColourRemapInfoSEIFileRoot().empty())
+  {
+    SEIColourRemappingInfo *seiColourRemappingInfo = new SEIColourRemappingInfo();
+    const Bool success = m_seiEncoder.initSEIColourRemappingInfo(seiColourRemappingInfo, slice->getPOC() );
+
+    if(success)
+    {
+      seiMessages.push_back(seiColourRemappingInfo);
+    }
+    else
+    {
+      delete seiColourRemappingInfo;
+    }
+  }
+#endif
+
 #if Q0189_TMVP_CONSTRAINTS
   if( m_pcEncTop->getTMVPConstraintsSEIEnabled() == 1 && (m_pcEncTop->getTMVPModeId() == 1 || m_pcEncTop->getTMVPModeId() == 2) &&
@@ -930,27 +786,4 @@
     seiMessages.push_back(seiFFInfo);
   }
-#endif
-#if Q0074_COLOUR_REMAPPING_SEI
-    // insert one CRI by picture (if the file exist)   
-    xFreeColourCRI();
-
-    // building the CRI file name with poc num in suffix "_poc.txt"
-    char suffix[10];
-    sprintf(suffix, "_%d.txt",  slice->getPOC());
-    string  colourRemapSEIFileWithPoc(m_pcCfg->getCRISEIFileRoot());
-    colourRemapSEIFileWithPoc.append(suffix);
-    xSetCRISEIFile( colourRemapSEIFileWithPoc );
-  
-    Int ret = xReadingCRIparameters();
-
-    if(ret != -1 && !m_pcCfg->getCRISEIFileRoot().empty())
-    {
-      // check validity of input parameters
-      xCheckParameter();
-
-      SEIColourRemappingInfo *seiColourRemappingInfo = new SEIColourRemappingInfo;
-      m_seiEncoder.initSEIColourRemappingInfo(seiColourRemappingInfo, &m_seiColourRemappingInfo);
-      seiMessages.push_back(seiColourRemappingInfo);
-    }
 #endif
 }
@@ -4590,14 +4423,3 @@
 #endif //SVC_EXTENSION
 
-#if Q0074_COLOUR_REMAPPING_SEI
-Bool confirmParameter(Bool bflag, const TChar* message)
-{
-  if (!bflag)
-    return false;
-
-  printf("Error: %s\n",message);
-  return true;
-}
-#endif
-
 //! \}
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 1459)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 1460)
@@ -138,7 +138,4 @@
   SEIEncoder              m_seiEncoder;
 
-#if Q0074_COLOUR_REMAPPING_SEI
-  TComSEIColourRemappingInfo m_seiColourRemappingInfo;  
-#endif
 #if SVC_EXTENSION
   Int                     m_pocCraWithoutReset;
@@ -274,12 +271,4 @@
   Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices );
 
-#if Q0074_COLOUR_REMAPPING_SEI
-  TComSEIColourRemappingInfo* xGetSEIColourRemappingInfo()  { return &m_seiColourRemappingInfo; }
-  Void xSetCRISEIFile( std::string pch )                    { m_seiColourRemappingInfo.m_colourRemapSEIFile = pch; }
-
-  Void xFreeColourCRI();
-  Int  xReadingCRIparameters();
-  Void xCheckParameter();
-#endif
 #if SVC_EXTENSION
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
