public version 0.2 master
authorMartin Schitter <ms+git@mur.at>
Sat, 24 Oct 2015 03:33:19 +0000 (05:33 +0200)
committerMartin Schitter <ms+git@mur.at>
Sat, 24 Oct 2015 03:33:19 +0000 (05:33 +0200)
adding legal range variants
removing XYZ output
rearrange the display hierachy

aces_1.0.1/python/aces_ocio/colorspaces/panasonic_gh4.py

index 11611fa..bf7ef1d 100644 (file)
@@ -170,22 +170,18 @@ styles = {
     254.96413793103449, 255.0, 255.0, 255.0, 255.0, 255.0, 255.0]
 }
 
-def prepare_photostyle_to_linear(style, corr=None, debug_plot=False):
+def prepare_photostyle_to_linear(style, legal_range=False, debug_plot=False):
 
-    # 18% gray card correction
+    # 18% gray card exposure offset
     corr = 16.5
-    
-    #if not corr:
-    #    if style == 'V-Log':
-    #        corr = 16.5
-    #    else:
-    #        #corr = 17.3
-    #        corr = 16.5
 
     exp = np.linspace( (corr-39)/3.0, corr/3.0, 40)
     l = np.power(2, exp) * 0.18
     vals = np.array(styles[style])
-    vals = vals/255
+    if legal_range:
+        vals = vals/255.0 * (235-16)/255.0 + 16/255.0
+    else:
+        vals = vals/255.0
 
     # remove visible edges at some exposure values
     print 'DIR:', dir()
@@ -220,7 +216,8 @@ def create_gh4_style(gamut,
                      lut_directory,
                      lut_resolution_1d,
                      aliases,
-                     style=None,
+                     legal_range,
+                     style,
                      variant=''):
     """
     Creates colorspace covering the conversion from GH4 picture styles 
@@ -238,6 +235,8 @@ def create_gh4_style(gamut,
         The resolution of generated 1D LUTs
     aliases : list of str
         Aliases for this colorspace
+    legal_range: bool
+        Add legal range shaper
     style : str
         Associated Photo Style
     variant : str
@@ -249,18 +248,24 @@ def create_gh4_style(gamut,
     A ColorSpace container class referencing the LUTs, matrices 
     and identifying information for the requested colorspace.
     """
-
-    name = ('GH4-%s - GH4-%s-Gamut %s' % (transfer_function, gamut, variant)).strip()
+    
+    if legal_range:
+        legal_str = 'Legal range '
+    else:
+        legal_str = ''
+        
+    name = ('%sGH4-%s - GH4-%s-Gamut %s' % ( legal_str, transfer_function,
+                                            gamut, variant)).strip()
     if transfer_function == '':
         name = ('Linear - GH4-%s-Gamut %s' % (gamut, variant)).strip()
     if gamut == '':
-        name = 'Curve - GH4-%s' % transfer_function
+        name = 'Curve - %sGH4-%s' % (legal_str, transfer_function)
 
     cs = ColorSpace(name)
     cs.description = name
     cs.aliases = aliases
     cs.equality_group = ''
-    cs.family = 'Input/Panasonic/GH4'
+    cs.family = 'Input/Panasonic/GH4 %s' %style
     cs.is_data = False
 
     # A linear space needs allocation variables
@@ -271,11 +276,13 @@ def create_gh4_style(gamut,
     cs.to_reference_transforms = []
 
     if transfer_function != '':
-        f = prepare_photostyle_to_linear(transfer_function)
+
+        if legal_range:
+            lut = 'gh4_%s_legal_to_linear.spi1d' % transfer_function.lower()
+        else:
+            lut = 'gh4_%s_to_linear.spi1d' % transfer_function.lower()
+        f = prepare_photostyle_to_linear(transfer_function, legal_range)
         
-        #data = array.array('f', '\0' * lut_resolution_1d * 4)
-        #for c in range(lut_resolution_1d):
-        #    data[c] = v_log_to_linear(float(c) / (lut_resolution_1d - 1))
         dom = np.linspace(0.0, 1.0, lut_resolution_1d)
         data = f(dom)
 
@@ -290,7 +297,6 @@ def create_gh4_style(gamut,
             else:
                 data[i] = data_max
         
-        lut = 'gh4_%s_to_linear.spi1d' % transfer_function
         genlut.write_SPI_1d(
             os.path.join(lut_directory, lut),
             0.0,
@@ -449,69 +455,89 @@ def create_colorspaces(lut_directory, lut_resolution_1d):
     
     styles_sort = styles.keys()
     styles_sort.sort()
-    
-    for style in styles_sort: 
 
-        # Full conversion
-        style_1 = create_gh4_style(
-            style,
-            style, 
-            lut_directory,
-            lut_resolution_1d,
-            ['gh4_%s_gh4_gamut' % style.lower().replace('-','_')])
-        colorspaces.append(style_1)
-
-        # Linearization Only
-        style_2 = create_gh4_style(
-            '',
-            style,
-            lut_directory,
-            lut_resolution_1d,
-            ['crv_gh4_%s' % style.lower().replace('-','_')])
-        colorspaces.append(style_2)
-
-        # Linearization and XYZ conversion
-        style_3 = create_gh4_style(
-            '%s' % style,
-            style,
-            lut_directory,
-            lut_resolution_1d,
-            ['gh4_%s_xyz' % style.lower().replace('-','_')],
-            variant='XYZ')
-        colorspaces.append(style_3)
-
-        # Primaries Only
-        style_4 = create_gh4_style(
-            style,
-            '',
-            lut_directory,
-            lut_resolution_1d,
-            ['lin_gh4_%s_gamut' % style.lower().replace('-','_')])
-        colorspaces.append(style_4)
+    for legal_range in [True, False]:
+        
+        for style in styles_sort: 
 
-        if style != 'BW':
-            
-            # Full conversion calibrated
-            style_5 = create_gh4_style(
-                '%s' % style,
+            if legal_range:
+                lower_style='%s_legal' % style.lower().replace('-','_')
+            else:
+                lower_style='%s' % style.lower().replace('-','_')
+
+            # Full conversion
+            style_1 = create_gh4_style(
+                style,
                 style, 
                 lut_directory,
                 lut_resolution_1d,
-                ['gh4_%s_gh4_calibrated_gamut'% style.lower().replace('-','_')],
-                style,
-                variant='Calibrated')
-            colorspaces.append(style_5)
+                ['gh4_%s_gh4_gamut' % lower_style],
+                legal_range=legal_range,
+                style=style)
+            colorspaces.append(style_1)
 
-            # Primaries Only calibrated
-            style_6 = create_gh4_style(
-                '%s-Calibrated' % style,
+            # Linearization Only
+            style_2 = create_gh4_style(
                 '',
+                style,
                 lut_directory,
                 lut_resolution_1d,
-                ['lin_gh4_%s_calibrated_gamut'%style.lower().replace('-','_')],
+                ['crv_gh4_%s' % lower_style],
+                legal_range=legal_range,
+                style=style)
+            colorspaces.append(style_2)
+
+            # # Linearization and XYZ conversion
+            # # only necessary for matrix calculation
+            #
+            # style_3 = create_gh4_style(
+            #     style,
+            #     style,
+            #     lut_directory,
+            #     lut_resolution_1d,
+            #     ['gh4_%s_xyz' % lower_style],
+            #     legal_range=legal_range,
+            #     style=style,
+            #     variant='XYZ')
+            # colorspaces.append(style_3)
+
+            # Primaries Only
+            style_4 = create_gh4_style(
                 style,
-                variant='Calibrated')
-            colorspaces.append(style_6)
+                '',
+                lut_directory,
+                lut_resolution_1d,
+                ['lin_gh4_%s_gamut' % lower_style],
+                legal_range=legal_range,
+                style=style
+            )
+            colorspaces.append(style_4)
+
+            if style != 'BW':
+
+                # Full conversion calibrated
+                style_5 = create_gh4_style(
+                    style,
+                    style, 
+                    lut_directory,
+                    lut_resolution_1d,
+                    ['gh4_%s_gh4_calibrated_gamut'% lower_style],
+                    legal_range=legal_range,
+                    style=style,
+                    variant='Calibrated')
+                colorspaces.append(style_5)
+
+                # Primaries Only calibrated
+                style_6 = create_gh4_style(
+                    style,
+                    '',
+                    lut_directory,
+                    lut_resolution_1d,
+                    ['lin_gh4_%s_calibrated_gamut'%lower_style],
+                    legal_range=legal_range,
+                    style=style,
+                    variant='Calibrated')
+                colorspaces.append(style_6)
 
             
     return colorspaces