2 # -*- coding: utf-8 -*-
5 Implements support for *ACES* colorspaces conversions and transfer functions.
8 from __future__ import division
17 import PyOpenColorIO as ocio
19 from aces_ocio.generate_lut import (
20 generate_1d_LUT_from_CTL,
21 generate_3d_LUT_from_CTL,
23 from aces_ocio.utilities import (
30 __author__ = 'ACES Developers'
31 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
33 __maintainer__ = 'ACES Developers'
34 __email__ = 'aces@oscars.org'
35 __status__ = 'Production'
37 __all__ = ['ACES_AP1_TO_AP0',
45 'create_ACES_RRT_plus_ODT',
54 # Matrix converting *ACES AP1* primaries to *ACES AP0*.
55 ACES_AP1_TO_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
56 0.0447945634, 0.8596711185, 0.0955343182,
57 -0.0055258826, 0.0040252103, 1.0015006723]
59 # Matrix converting *ACES AP0* primaries to *ACES AP1*.
60 ACES_AP0_TO_AP1 = [1.4514393161, -0.2365107469, -0.2149285693,
61 -0.0765537734, 1.1762296998, -0.0996759264,
62 0.0083161484, -0.0060324498, 0.9977163014]
64 # Matrix converting *ACES AP0* primaries to *XYZ*.
65 ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
66 0.3439664498, 0.7281660966, -0.0721325464,
67 0.0000000000, 0.0000000000, 1.0088251844]
69 # Matrix converting *ACES AP0* primaries to *XYZ*.
70 ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845,
71 -0.4959030231, 1.3733130458, 0.0982400361,
72 0.0000000000, 0.0000000000, 0.9912520182]
82 Parameter description.
87 Return value description.
90 # Defining the reference colorspace.
91 aces2065_1 = ColorSpace('ACES2065-1')
92 aces2065_1.description = (
93 'The Academy Color Encoding System reference color space')
94 aces2065_1.equality_group = ''
95 aces2065_1.aliases = ["lin_ap0", "aces"]
96 aces2065_1.family = 'ACES'
97 aces2065_1.is_data = False
98 aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2
99 aces2065_1.allocation_vars = [-8, 5, 0.00390625]
104 def create_ACEScc(aces_ctl_directory,
113 Creates the *ACEScc* colorspace.
118 Parameter description.
126 cs = ColorSpace(name)
127 cs.description = 'The %s color space' % name
128 cs.aliases = ["acescc", "acescc_ap1"]
129 cs.equality_group = ''
132 cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
133 cs.allocation_vars = [min_value, max_value]
134 cs.aces_transform_id = "ACEScsc.ACEScc_to_ACES.a1.0.0"
136 ctls = [os.path.join(aces_ctl_directory,
138 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
139 # This transform gets back to the *AP1* primaries.
140 # Useful as the 1d LUT is only covering the transfer function.
141 # The primaries switch is covered by the matrix below:
142 os.path.join(aces_ctl_directory,
144 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
145 lut = '%s_to_linear.spi1d' % name
149 generate_1d_LUT_from_CTL(
150 os.path.join(lut_directory, lut),
163 cs.to_reference_transforms = []
164 cs.to_reference_transforms.append({
167 'interpolation': 'linear',
168 'direction': 'forward'})
170 # *AP1* primaries to *AP0* primaries.
171 cs.to_reference_transforms.append({
173 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
174 'direction': 'forward'})
176 cs.from_reference_transforms = []
180 def create_ACESproxy(aces_ctl_directory,
186 Creates the *ACESproxy* colorspace.
191 Parameter description.
196 *ACESproxy* colorspace.
199 cs = ColorSpace(name)
200 cs.description = 'The %s color space' % name
201 cs.aliases = ["acesproxy", "acesproxy_ap1"]
202 cs.equality_group = ''
206 cs.aces_transform_id = "ACEScsc.ACESproxy10i_to_ACES.a1.0.0"
208 ctls = [os.path.join(aces_ctl_directory,
210 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
211 # This transform gets back to the *AP1* primaries.
212 # Useful as the 1d LUT is only covering the transfer function.
213 # The primaries switch is covered by the matrix below:
214 os.path.join(aces_ctl_directory,
216 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
217 lut = '%s_to_linear.spi1d' % name
221 generate_1d_LUT_from_CTL(
222 os.path.join(lut_directory, lut),
235 cs.to_reference_transforms = []
236 cs.to_reference_transforms.append({
239 'interpolation': 'linear',
240 'direction': 'forward'})
242 # *AP1* primaries to *AP0* primaries.
243 cs.to_reference_transforms.append({
245 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
246 'direction': 'forward'})
248 cs.from_reference_transforms = []
252 # -------------------------------------------------------------------------
254 # -------------------------------------------------------------------------
255 def create_ACEScg(aces_ctl_directory,
261 Creates the *ACEScg* colorspace.
266 Parameter description.
274 cs = ColorSpace(name)
275 cs.description = 'The %s color space' % name
276 cs.aliases = ["acescg", "lin_ap1"]
277 cs.equality_group = ''
280 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
281 cs.allocation_vars = [-8, 5, 0.00390625]
283 cs.aces_transform_id = "ACEScsc.ACEScg_to_ACES.a1.0.0"
285 cs.to_reference_transforms = []
287 # *AP1* primaries to *AP0* primaries.
288 cs.to_reference_transforms.append({
290 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
291 'direction': 'forward'})
293 cs.from_reference_transforms = []
295 # *AP1* primaries to *AP0* primaries.
296 cs.from_reference_transforms.append({
298 'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
299 'direction': 'forward'})
304 # -------------------------------------------------------------------------
306 # -------------------------------------------------------------------------
307 def create_ADX(lut_directory,
312 Creates the *ADX* colorspace.
317 Parameter description.
325 name = '%s%s' % (name, bit_depth)
326 cs = ColorSpace(name)
327 cs.description = '%s color space - used for film scans' % name
328 cs.aliases = ["adx%s" % str(bit_depth)]
329 cs.equality_group = ''
334 cs.aces_transform_id = "ACEScsc.ADX10_to_ACES.a1.0.0"
336 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
337 ADX_to_CDD = [1023 / 500, 0, 0, 0,
341 offset = [-95 / 500, -95 / 500, -95 / 500, 0]
342 elif bit_depth == 16:
343 cs.aces_transform_id = "ACEScsc.ADX16_to_ACES.a1.0.0"
345 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
346 ADX_to_CDD = [65535 / 8000, 0, 0, 0,
347 0, 65535 / 8000, 0, 0,
348 0, 0, 65535 / 8000, 0,
350 offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
352 cs.to_reference_transforms = []
354 # Converting from *ADX* to *Channel-Dependent Density*.
355 cs.to_reference_transforms.append({
357 'matrix': ADX_to_CDD,
359 'direction': 'forward'})
361 # Convert from Channel-Dependent Density to Channel-Independent Density
362 cs.to_reference_transforms.append({
364 'matrix': [0.75573, 0.22197, 0.02230, 0,
365 0.05901, 0.96928, -0.02829, 0,
366 0.16134, 0.07406, 0.76460, 0,
368 'direction': 'forward'})
370 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
371 def create_CID_to_RLE_LUT():
373 def interpolate_1D(x, xp, fp):
374 return numpy.interp(x, xp, fp)
376 LUT_1D_xp = [-0.190000000000000,
388 LUT_1D_fp = [-6.000000000000000,
400 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
405 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
406 return (100 / 55) * x - REF_PT
408 def fit(value, from_min, from_max, to_min, to_max):
409 if from_min == from_max:
410 raise ValueError('from_min == from_max')
411 return (value - from_min) / (from_max - from_min) * (
412 to_max - to_min) + to_min
414 num_samples = 2 ** 12
417 for i in xrange(num_samples):
418 x = i / (num_samples - 1)
419 x = fit(x, 0, 1, domain[0], domain[1])
420 data.append(cid_to_rle(x))
422 lut = 'ADX_CID_to_RLE.spi1d'
423 write_SPI_1d(os.path.join(lut_directory, lut),
431 # Converting *Channel Independent Density* values to
432 # *Relative Log Exposure* values.
433 lut = create_CID_to_RLE_LUT()
434 cs.to_reference_transforms.append({
437 'interpolation': 'linear',
438 'direction': 'forward'})
440 # Converting *Relative Log Exposure* values to
441 # *Relative Exposure* values.
442 cs.to_reference_transforms.append({
445 'direction': 'inverse'})
447 # Convert *Relative Exposure* values to *ACES* values.
448 cs.to_reference_transforms.append({
450 'matrix': [0.72286, 0.12630, 0.15084, 0,
451 0.11923, 0.76418, 0.11659, 0,
452 0.01427, 0.08213, 0.90359, 0,
454 'direction': 'forward'})
456 cs.from_reference_transforms = []
460 # -------------------------------------------------------------------------
461 # *Generic Log Transform*
462 # -------------------------------------------------------------------------
463 def create_generic_log(aces_ctl_directory,
476 Creates the *Generic Log* colorspace.
481 Parameter description.
486 *Generic Log* colorspace.
489 cs = ColorSpace(name)
490 cs.description = 'The %s color space' % name
492 cs.equality_group = name
493 cs.family = 'Utility'
496 ctls = [os.path.join(
499 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
500 lut = '%s_to_linear.spi1d' % name
504 generate_1d_LUT_from_CTL(
505 os.path.join(lut_directory, lut),
511 {'middleGrey': middle_grey,
512 'minExposure': min_exposure,
513 'maxExposure': max_exposure},
520 cs.to_reference_transforms = []
521 cs.to_reference_transforms.append({
524 'interpolation': 'linear',
525 'direction': 'forward'})
527 cs.from_reference_transforms = []
531 # -------------------------------------------------------------------------
532 # *base Dolby PQ Transform*
533 # -------------------------------------------------------------------------
534 def create_dolbypq(aces_CTL_directory,
543 cs = ColorSpace(name)
544 cs.description = 'The %s color space' % name
546 cs.equality_group = name
547 cs.family = 'Utility'
550 ctls = [os.path.join(
553 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
554 lut = '%s_to_linear.spi1d' % name
558 generate_1d_LUT_from_CTL(
559 os.path.join(lut_directory, lut),
571 cs.to_reference_transforms = []
572 cs.to_reference_transforms.append({
575 'interpolation': 'linear',
576 'direction': 'forward'})
578 cs.from_reference_transforms = []
582 # -------------------------------------------------------------------------
583 # *Dolby PQ Transform that considers a fixed linear range*
584 # -------------------------------------------------------------------------
585 def create_dolbypq_scaled(aces_CTL_directory,
597 cs = ColorSpace(name)
598 cs.description = 'The %s color space' % name
600 cs.equality_group = name
601 cs.family = 'Utility'
604 ctls = [os.path.join(
607 'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
608 lut = '%s_to_linear.spi1d' % name
612 generate_1d_LUT_from_CTL(
613 os.path.join(lut_directory, lut),
619 {'middleGrey': middle_grey,
620 'minExposure': min_exposure,
621 'maxExposure': max_exposure},
627 cs.to_reference_transforms = []
628 cs.to_reference_transforms.append({
631 'interpolation': 'linear',
632 'direction': 'forward'})
634 cs.from_reference_transforms = []
638 # -------------------------------------------------------------------------
640 # -------------------------------------------------------------------------
641 def create_ACES_LMT(lmt_name,
646 lut_resolution_1d=1024,
647 lut_resolution_3d=64,
651 Creates the *ACES LMT* colorspace.
656 Parameter description.
661 *ACES LMT* colorspace.
667 cs = ColorSpace('%s' % lmt_name)
668 cs.description = 'The ACES Look Transform: %s' % lmt_name
670 cs.equality_group = ''
673 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
674 cs.allocation_vars = [-8, 5, 0.00390625]
675 cs.aces_transform_id = lmt_values['transformID']
677 pprint.pprint(lmt_values)
679 # Generating the *shaper* transform.
682 shaper_from_ACES_CTL,
684 shaper_params) = shaper_info
686 # Add the shaper transform
687 shaper_lut = '%s_to_linear.spi1d' % shaper_name
688 shaper_lut = sanitize(shaper_lut)
690 shaper_OCIO_transform = {
693 'interpolation': 'linear',
694 'direction': 'inverse'}
696 # Generating the forward transform.
697 cs.from_reference_transforms = []
699 if 'transformCTL' in lmt_values:
700 ctls = [shaper_to_ACES_CTL % aces_ctl_directory,
701 os.path.join(aces_ctl_directory,
702 lmt_values['transformCTL'])]
703 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
707 generate_3d_LUT_from_CTL(
708 os.path.join(lut_directory, lut),
712 1 / shaper_input_scale,
718 cs.from_reference_transforms.append(shaper_OCIO_transform)
719 cs.from_reference_transforms.append({
722 'interpolation': 'tetrahedral',
723 'direction': 'forward'})
725 # Generating the inverse transform.
726 cs.to_reference_transforms = []
728 if 'transformCTLInverse' in lmt_values:
729 ctls = [os.path.join(aces_ctl_directory,
730 lmt_values['transformCTLInverse']),
731 shaper_from_ACES_CTL % aces_ctl_directory]
732 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
736 generate_3d_LUT_from_CTL(
737 os.path.join(lut_directory, lut),
750 cs.to_reference_transforms.append({
753 'interpolation': 'tetrahedral',
754 'direction': 'forward'})
756 shaper_inverse = shaper_OCIO_transform.copy()
757 shaper_inverse['direction'] = 'forward'
758 cs.to_reference_transforms.append(shaper_inverse)
763 # -------------------------------------------------------------------------
765 # -------------------------------------------------------------------------
766 def create_LMTs(aces_ctl_directory,
779 Parameter description.
784 Return value description.
789 # -------------------------------------------------------------------------
791 # -------------------------------------------------------------------------
792 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
793 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
795 # Defining the *Log 2* shaper.
796 lmt_shaper_name = 'LMT Shaper'
797 lmt_shaper_name_aliases = ['crv_lmtshaper']
803 lmt_shaper = create_generic_log(aces_ctl_directory,
805 lmt_lut_resolution_1d,
807 name=lmt_shaper_name,
808 middle_grey=lmt_params['middleGrey'],
809 min_exposure=lmt_params['minExposure'],
810 max_exposure=lmt_params['maxExposure'],
811 aliases=lmt_shaper_name_aliases)
812 colorspaces.append(lmt_shaper)
814 shaper_input_scale_generic_log2 = 1
816 # *Log 2* shaper name and *CTL* transforms bundled up.
821 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
824 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
825 shaper_input_scale_generic_log2,
828 sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
830 for lmt in sorted_LMTs:
831 lmt_name, lmt_values = lmt
832 lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])]
833 cs = create_ACES_LMT(
834 lmt_values['transformUserName'],
839 lmt_lut_resolution_1d,
840 lmt_lut_resolution_3d,
843 colorspaces.append(cs)
848 # -------------------------------------------------------------------------
849 # *ACES RRT* with supplied *ODT*.
850 # -------------------------------------------------------------------------
851 def create_ACES_RRT_plus_ODT(odt_name,
856 lut_resolution_1d=1024,
857 lut_resolution_3d=64,
866 Parameter description.
871 Return value description.
877 cs = ColorSpace('%s' % odt_name)
878 cs.description = '%s - %s Output Transform' % (
879 odt_values['transformUserNamePrefix'], odt_name)
881 cs.equality_group = ''
885 cs.aces_transform_id = odt_values['transformID']
887 pprint.pprint(odt_values)
889 # Generating the *shaper* transform.
892 shaper_from_ACES_CTL,
894 shaper_params) = shaper_info
896 if 'legalRange' in odt_values:
897 shaper_params['legalRange'] = odt_values['legalRange']
899 shaper_params['legalRange'] = 0
901 # Add the shaper transform
902 shaper_lut = '%s_to_linear.spi1d' % shaper_name
903 shaper_lut = sanitize(shaper_lut)
905 shaper_OCIO_transform = {
908 'interpolation': 'linear',
909 'direction': 'inverse'}
911 # Generating the *forward* transform.
912 cs.from_reference_transforms = []
914 if 'transformLUT' in odt_values:
915 transform_LUT_file_name = os.path.basename(
916 odt_values['transformLUT'])
917 lut = os.path.join(lut_directory, transform_LUT_file_name)
918 shutil.copy(odt_values['transformLUT'], lut)
920 cs.from_reference_transforms.append(shaper_OCIO_transform)
921 cs.from_reference_transforms.append({
923 'path': transform_LUT_file_name,
924 'interpolation': 'tetrahedral',
925 'direction': 'forward'})
926 elif 'transformCTL' in odt_values:
928 shaper_to_ACES_CTL % aces_ctl_directory,
929 os.path.join(aces_ctl_directory,
932 os.path.join(aces_ctl_directory,
934 odt_values['transformCTL'])]
935 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
939 generate_3d_LUT_from_CTL(
940 os.path.join(lut_directory, lut),
945 1 / shaper_input_scale,
951 cs.from_reference_transforms.append(shaper_OCIO_transform)
952 cs.from_reference_transforms.append({
955 'interpolation': 'tetrahedral',
956 'direction': 'forward'})
958 # Generating the *inverse* transform.
959 cs.to_reference_transforms = []
961 if 'transformLUTInverse' in odt_values:
962 transform_LUT_inverse_file_name = os.path.basename(
963 odt_values['transformLUTInverse'])
964 lut = os.path.join(lut_directory, transform_LUT_inverse_file_name)
965 shutil.copy(odt_values['transformLUTInverse'], lut)
967 cs.to_reference_transforms.append({
969 'path': transform_LUT_inverse_file_name,
970 'interpolation': 'tetrahedral',
971 'direction': 'forward'})
973 shaper_inverse = shaper_OCIO_transform.copy()
974 shaper_inverse['direction'] = 'forward'
975 cs.to_reference_transforms.append(shaper_inverse)
976 elif 'transformCTLInverse' in odt_values:
977 ctls = [os.path.join(aces_ctl_directory,
979 odt_values['transformCTLInverse']),
980 os.path.join(aces_ctl_directory,
982 'InvRRT.a1.0.0.ctl'),
983 shaper_from_ACES_CTL % aces_ctl_directory]
984 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
988 generate_3d_LUT_from_CTL(
989 os.path.join(lut_directory, lut),
1000 cs.to_reference_transforms.append({
1003 'interpolation': 'tetrahedral',
1004 'direction': 'forward'})
1006 shaper_inverse = shaper_OCIO_transform.copy()
1007 shaper_inverse['direction'] = 'forward'
1008 cs.to_reference_transforms.append(shaper_inverse)
1013 # -------------------------------------------------------------------------
1015 # -------------------------------------------------------------------------
1016 def create_ODTs(aces_ctl_directory,
1023 linear_display_space,
1031 Parameter description.
1036 Return value description.
1042 # -------------------------------------------------------------------------
1043 # *RRT / ODT* Shaper Options
1044 # -------------------------------------------------------------------------
1047 # Defining the *Log 2* shaper.
1048 log2_shaper_name = shaper_name
1049 log2_shaper_name_aliases = ["crv_%s" % compact(log2_shaper_name)]
1055 log2_shaper_colorspace = create_generic_log(
1060 name=log2_shaper_name,
1061 middle_grey=log2_params['middleGrey'],
1062 min_exposure=log2_params['minExposure'],
1063 max_exposure=log2_params['maxExposure'],
1064 aliases=log2_shaper_name_aliases)
1065 colorspaces.append(log2_shaper_colorspace)
1067 shaper_input_scale_generic_log2 = 1
1069 # *Log 2* shaper name and *CTL* transforms bundled up.
1070 log2_shaper_data = [
1074 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1077 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1078 shaper_input_scale_generic_log2,
1081 shaper_data[log2_shaper_name] = log2_shaper_data
1083 # Space with a more user-friendly name. Direct copy otherwise.
1084 log2_shaper_copy_name = "Log2 Shaper"
1085 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1086 log2_shaper_copy_colorspace.description = 'The %s color space' % log2_shaper_copy_name
1087 log2_shaper_copy_colorspace.aliases = ["crv_%s" % compact(log2_shaper_copy_name)]
1088 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1089 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1090 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1091 log2_shaper_copy_colorspace.to_reference_transforms = list(
1092 log2_shaper_colorspace.to_reference_transforms)
1093 log2_shaper_copy_colorspace.from_reference_transforms = list(
1094 log2_shaper_colorspace.from_reference_transforms)
1095 colorspaces.append(log2_shaper_copy_colorspace)
1097 # Defining the *Log2 shaper that includes the AP1* primaries.
1098 log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper"
1099 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1100 log2_shaper_api1_colorspace.description = 'The %s color space' % log2_shaper_api1_name
1101 log2_shaper_api1_colorspace.aliases = [
1102 "%s_ap1" % compact(log2_shaper_copy_name)]
1103 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1104 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1105 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1106 log2_shaper_api1_colorspace.to_reference_transforms = list(
1107 log2_shaper_colorspace.to_reference_transforms)
1108 log2_shaper_api1_colorspace.from_reference_transforms = list(
1109 log2_shaper_colorspace.from_reference_transforms)
1111 # *AP1* primaries to *AP0* primaries.
1112 log2_shaper_api1_colorspace.to_reference_transforms.append({
1114 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1115 'direction': 'forward'
1117 colorspaces.append(log2_shaper_api1_colorspace)
1119 # Defining the *Log2 shaper that includes the AP1* primaries.
1120 # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1121 shaper_api1_name = "%s - AP1" % shaper_name
1122 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1123 shaper_api1_colorspace.description = 'The %s color space' % shaper_api1_name
1124 shaper_api1_colorspace.aliases = ["%s_ap1" % compact(shaper_name)]
1125 shaper_api1_colorspace.equality_group = shaper_api1_name
1126 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1127 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1128 shaper_api1_colorspace.to_reference_transforms = list(
1129 log2_shaper_api1_colorspace.to_reference_transforms)
1130 shaper_api1_colorspace.from_reference_transforms = list(
1131 log2_shaper_api1_colorspace.from_reference_transforms)
1132 colorspaces.append(shaper_api1_colorspace)
1134 # Define the base *Dolby PQ Shaper*
1136 dolbypq_shaper_name = "Dolby PQ 10000"
1137 dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"]
1139 dolbypq_shaper_colorspace = create_dolbypq(
1144 name=dolbypq_shaper_name,
1145 aliases=dolbypq_shaper_name_aliases)
1146 colorspaces.append(dolbypq_shaper_colorspace)
1148 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1149 dolbypq_shaper_data = [
1150 dolbypq_shaper_name,
1153 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1156 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1160 shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1162 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1164 dolbypq_scaled_shaper_name = "Dolby PQ Scaled"
1165 dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"]
1167 dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled(
1172 name=dolbypq_scaled_shaper_name,
1173 aliases=dolbypq_scaled_shaper_name_aliases)
1174 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1176 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1177 dolbypq_scaled_shaper_data = [
1178 dolbypq_scaled_shaper_name,
1181 'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1184 'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1188 shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1191 # Pick a specific shaper
1193 rrt_shaper = log2_shaper_data
1194 # rrt_shaper = dolbypq_scaled_shaper_data
1196 # *RRT + ODT* combinations.
1197 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1199 for odt in sorted_odts:
1200 (odt_name, odt_values) = odt
1202 # Generating only full range transform for *ODTs* that can generate
1203 # either *legal* or *full* output.
1205 # Uncomment these lines and the lower section and flip the 'legalRange' value to 1
1206 # to recover the old behavior, where both legal and full range LUTs were generated
1207 if odt_values['transformHasFullLegalSwitch']:
1208 #odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1209 odt_legal['legalRange'] = 0
1211 # odt_name_legal = odt_values['transformUserName']
1213 odt_name_legal = odt_values['transformUserName']
1215 odt_legal = odt_values.copy()
1217 odt_aliases = ["out_%s" % compact(odt_name_legal)]
1219 cs = create_ACES_RRT_plus_ODT(
1229 colorspaces.append(cs)
1231 displays[odt_name_legal] = {
1232 'Raw': linear_display_space,
1233 'Log': log_display_space,
1234 'Output Transform': cs}
1237 # Generating full range transform for *ODTs* that can generate
1238 # either *legal* or *full* output.
1239 if odt_values['transformHasFullLegalSwitch']:
1240 print('Generating full range ODT for %s' % odt_name)
1242 odt_name_full = '%s - Full' % odt_values['transformUserName']
1243 odt_full = odt_values.copy()
1244 odt_full['legalRange'] = 0
1246 odt_full_aliases = ["out_%s" % compact(odt_name_full)]
1248 cs_full = create_ACES_RRT_plus_ODT(
1258 colorspaces.append(cs_full)
1260 displays[odt_name_full] = {
1261 'Raw': linear_display_space,
1262 'Log': log_display_space,
1263 'Output Transform': cs_full}
1266 return (colorspaces, displays)
1269 def get_transform_info(ctl_transform):
1276 Parameter description.
1281 Return value description.
1284 with open(ctl_transform, 'rb') as fp:
1285 lines = fp.readlines()
1287 # Retrieving the *transform ID* and *User Name*.
1288 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1289 transform_user_name = '-'.join(
1290 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1291 transform_user_name_prefix = (
1292 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1294 # Figuring out if this transform has options for processing full and legal range
1295 transform_full_legal_switch = False
1297 if line.strip() == "input varying int legalRange = 0":
1298 # print( "%s has legal range flag" % transform_user_name)
1299 transform_full_legal_switch = True
1302 return (transform_id, transform_user_name, transform_user_name_prefix,
1303 transform_full_legal_switch)
1306 def get_ODTs_info(aces_ctl_directory):
1310 For versions after WGR9.
1315 Parameter description.
1320 Return value description.
1323 # TODO: Investigate usage of *files_walker* definition here.
1324 # Credit to *Alex Fry* for the original approach here.
1325 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1327 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1328 for fname in file_list:
1329 all_odt.append((os.path.join(dir_name, fname)))
1331 odt_CTLs = [x for x in all_odt if
1332 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1336 for odt_CTL in odt_CTLs:
1337 odt_tokens = os.path.split(odt_CTL)
1339 # Handling nested directories.
1340 odt_path_tokens = os.path.split(odt_tokens[-2])
1341 odt_dir = odt_path_tokens[-1]
1342 while odt_path_tokens[-2][-3:] != 'odt':
1343 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1344 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1346 # Building full name,
1347 transform_CTL = odt_tokens[-1]
1348 odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1350 # Finding id, user name and user name prefix.
1352 transform_user_name,
1353 transform_user_name_prefix,
1354 transform_full_legal_switch) = get_transform_info(
1355 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL))
1358 transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1359 if not os.path.exists(
1360 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1361 transform_CTL_inverse = None
1363 # Add to list of ODTs
1365 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1366 if transform_CTL_inverse is not None:
1367 odts[odt_name]['transformCTLInverse'] = os.path.join(
1368 odt_dir, transform_CTL_inverse)
1370 odts[odt_name]['transformID'] = transform_ID
1371 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1372 odts[odt_name]['transformUserName'] = transform_user_name
1374 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1376 forward_CTL = odts[odt_name]['transformCTL']
1378 print('ODT : %s' % odt_name)
1379 print('\tTransform ID : %s' % transform_ID)
1380 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1381 print('\tTransform User Name : %s' % transform_user_name)
1383 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1384 print('\tForward ctl : %s' % forward_CTL)
1385 if 'transformCTLInverse' in odts[odt_name]:
1386 inverse_CTL = odts[odt_name]['transformCTLInverse']
1387 print('\tInverse ctl : %s' % inverse_CTL)
1389 print('\tInverse ctl : %s' % 'None')
1396 def get_LMTs_info(aces_ctl_directory):
1400 For versions after WGR9.
1405 Parameter description.
1410 Return value description.
1413 # TODO: Investigate refactoring with previous definition.
1415 # Credit to Alex Fry for the original approach here
1416 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1418 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1419 for fname in file_list:
1420 all_lmt.append((os.path.join(dir_name, fname)))
1422 lmt_CTLs = [x for x in all_lmt if
1423 ('InvLMT' not in x) and ('README' not in x) and (
1424 os.path.split(x)[-1][0] != '.')]
1428 for lmt_CTL in lmt_CTLs:
1429 lmt_tokens = os.path.split(lmt_CTL)
1431 # Handlimg nested directories.
1432 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1433 lmt_dir = lmt_path_tokens[-1]
1434 while lmt_path_tokens[-2][-3:] != 'ctl':
1435 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1436 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1438 # Building full name.
1439 transform_CTL = lmt_tokens[-1]
1440 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1442 # Finding id, user name and user name prefix.
1444 transform_user_name,
1445 transform_user_name_prefix,
1446 transform_full_legal_switch) = get_transform_info(
1447 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1450 transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1451 if not os.path.exists(
1452 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1453 transform_CTL_inverse = None
1456 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1457 if transform_CTL_inverse is not None:
1458 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1459 lmt_dir, transform_CTL_inverse)
1461 lmts[lmt_name]['transformID'] = transform_ID
1462 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1463 lmts[lmt_name]['transformUserName'] = transform_user_name
1465 forward_CTL = lmts[lmt_name]['transformCTL']
1467 print('LMT : %s' % lmt_name)
1468 print('\tTransform ID : %s' % transform_ID)
1469 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1470 print('\tTransform User Name : %s' % transform_user_name)
1471 print('\t Forward ctl : %s' % forward_CTL)
1472 if 'transformCTLInverse' in lmts[lmt_name]:
1473 inverse_CTL = lmts[lmt_name]['transformCTLInverse']
1474 print('\t Inverse ctl : %s' % inverse_CTL)
1476 print('\t Inverse ctl : %s' % 'None')
1483 def create_colorspaces(aces_ctl_directory,
1492 Generates the colorspace conversions.
1497 Parameter description.
1502 Return value description.
1507 ACES = create_ACES()
1509 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1510 lut_resolution_1d, cleanup,
1511 min_value=-0.35840, max_value=1.468)
1512 colorspaces.append(ACEScc)
1514 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1515 lut_resolution_1d, cleanup)
1516 colorspaces.append(ACESproxy)
1518 ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1519 lut_resolution_1d, cleanup)
1520 colorspaces.append(ACEScg)
1522 ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1523 colorspaces.append(ADX10)
1525 ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1526 colorspaces.append(ADX16)
1528 lmts = create_LMTs(aces_ctl_directory,
1535 colorspaces.extend(lmts)
1537 odts, displays = create_ODTs(aces_ctl_directory,
1546 colorspaces.extend(odts)
1548 # Wish there was an automatic way to get this from the CTL
1549 defaultDisplay = "sRGB (D60 sim.)"
1551 roles = {'color_picking': ACEScg.name,
1552 'color_timing': ACEScc.name,
1553 'compositing_log': ACEScc.name,
1555 'default': ACES.name,
1556 'matte_paint': ACEScc.name,
1558 'scene_linear': ACEScg.name,
1559 'texture_paint': ''}
1561 return ACES, colorspaces, displays, ACEScc, roles, defaultDisplay