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_ap1"]
129 cs.equality_group = ''
132 cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
133 cs.allocation_vars = [min_value, max_value]
135 ctls = [os.path.join(aces_ctl_directory,
137 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl')]
138 lut = '%s_to_linear.spi1d' % name
142 generate_1d_LUT_from_CTL(
143 os.path.join(lut_directory, lut),
149 {'transferFunctionOnly':1},
156 cs.to_reference_transforms = []
157 cs.to_reference_transforms.append({
160 'interpolation': 'linear',
161 'direction': 'forward'})
163 # *AP1* primaries to *AP0* primaries.
164 cs.to_reference_transforms.append({
166 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
167 'direction': 'forward'})
169 cs.from_reference_transforms = []
173 def create_ACESproxy(aces_ctl_directory,
179 Creates the *ACESproxy* colorspace.
184 Parameter description.
189 *ACESproxy* colorspace.
192 cs = ColorSpace(name)
193 cs.description = 'The %s color space' % name
194 cs.aliases = ["acesproxy_ap1"]
195 cs.equality_group = ''
199 ctls = [os.path.join(aces_ctl_directory,
201 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
202 # This transform gets back to the *AP1* primaries.
203 # Useful as the 1d LUT is only covering the transfer function.
204 # The primaries switch is covered by the matrix below:
205 os.path.join(aces_ctl_directory,
207 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
208 lut = '%s_to_linear.spi1d' % name
212 generate_1d_LUT_from_CTL(
213 os.path.join(lut_directory, lut),
226 cs.to_reference_transforms = []
227 cs.to_reference_transforms.append({
230 'interpolation': 'linear',
231 'direction': 'forward'})
233 # *AP1* primaries to *AP0* primaries.
234 cs.to_reference_transforms.append({
236 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
237 'direction': 'forward'})
239 cs.from_reference_transforms = []
243 # -------------------------------------------------------------------------
245 # -------------------------------------------------------------------------
246 def create_ACEScg(aces_ctl_directory,
252 Creates the *ACEScg* colorspace.
257 Parameter description.
265 cs = ColorSpace(name)
266 cs.description = 'The %s color space' % name
267 cs.aliases = ["lin_ap1"]
268 cs.equality_group = ''
271 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
272 cs.allocation_vars = [-8, 5, 0.00390625]
274 cs.to_reference_transforms = []
276 # *AP1* primaries to *AP0* primaries.
277 cs.to_reference_transforms.append({
279 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
280 'direction': 'forward'})
282 cs.from_reference_transforms = []
286 # -------------------------------------------------------------------------
288 # -------------------------------------------------------------------------
289 def create_ADX(lut_directory,
294 Creates the *ADX* colorspace.
299 Parameter description.
307 name = '%s%s' % (name, bit_depth)
308 cs = ColorSpace(name)
309 cs.description = '%s color space - used for film scans' % name
310 cs.aliases = ["adx%s" % str(bit_depth)]
311 cs.equality_group = ''
316 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
317 ADX_to_CDD = [1023 / 500, 0, 0, 0,
321 offset = [-95 / 500, -95 / 500, -95 / 500, 0]
322 elif bit_depth == 16:
323 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
324 ADX_to_CDD = [65535 / 8000, 0, 0, 0,
325 0, 65535 / 8000, 0, 0,
326 0, 0, 65535 / 8000, 0,
328 offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
330 cs.to_reference_transforms = []
332 # Converting from *ADX* to *Channel-Dependent Density*.
333 cs.to_reference_transforms.append({
335 'matrix': ADX_to_CDD,
337 'direction': 'forward'})
339 # Convert from Channel-Dependent Density to Channel-Independent Density
340 cs.to_reference_transforms.append({
342 'matrix': [0.75573, 0.22197, 0.02230, 0,
343 0.05901, 0.96928, -0.02829, 0,
344 0.16134, 0.07406, 0.76460, 0,
346 'direction': 'forward'})
348 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
349 def create_CID_to_RLE_LUT():
351 def interpolate_1D(x, xp, fp):
352 return numpy.interp(x, xp, fp)
354 LUT_1D_xp = [-0.190000000000000,
366 LUT_1D_fp = [-6.000000000000000,
378 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
383 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
384 return (100 / 55) * x - REF_PT
386 def fit(value, from_min, from_max, to_min, to_max):
387 if from_min == from_max:
388 raise ValueError('from_min == from_max')
389 return (value - from_min) / (from_max - from_min) * (
390 to_max - to_min) + to_min
392 num_samples = 2 ** 12
395 for i in xrange(num_samples):
396 x = i / (num_samples - 1)
397 x = fit(x, 0, 1, domain[0], domain[1])
398 data.append(cid_to_rle(x))
400 lut = 'ADX_CID_to_RLE.spi1d'
401 write_SPI_1d(os.path.join(lut_directory, lut),
409 # Converting *Channel Independent Density* values to
410 # *Relative Log Exposure* values.
411 lut = create_CID_to_RLE_LUT()
412 cs.to_reference_transforms.append({
415 'interpolation': 'linear',
416 'direction': 'forward'})
418 # Converting *Relative Log Exposure* values to
419 # *Relative Exposure* values.
420 cs.to_reference_transforms.append({
423 'direction': 'inverse'})
425 # Convert *Relative Exposure* values to *ACES* values.
426 cs.to_reference_transforms.append({
428 'matrix': [0.72286, 0.12630, 0.15084, 0,
429 0.11923, 0.76418, 0.11659, 0,
430 0.01427, 0.08213, 0.90359, 0,
432 'direction': 'forward'})
434 cs.from_reference_transforms = []
437 # -------------------------------------------------------------------------
438 # *Generic Log Transform*
439 # -------------------------------------------------------------------------
440 def create_generic_log(aces_ctl_directory,
453 Creates the *Generic Log* colorspace.
458 Parameter description.
463 *Generic Log* colorspace.
466 cs = ColorSpace(name)
467 cs.description = 'The %s color space' % name
469 cs.equality_group = name
470 cs.family = 'Utility'
473 ctls = [os.path.join(
476 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')]
477 lut = '%s_to_linear.spi1d' % name
481 generate_1d_LUT_from_CTL(
482 os.path.join(lut_directory, lut),
488 {'middleGrey': middle_grey,
489 'minExposure': min_exposure,
490 'maxExposure': max_exposure},
497 cs.to_reference_transforms = []
498 cs.to_reference_transforms.append({
501 'interpolation': 'linear',
502 'direction': 'forward'})
504 cs.from_reference_transforms = []
507 # -------------------------------------------------------------------------
508 # *base Dolby PQ Transform*
509 # -------------------------------------------------------------------------
510 def create_dolbypq(aces_CTL_directory,
519 cs = ColorSpace(name)
520 cs.description = 'The %s color space' % name
522 cs.equality_group = name
523 cs.family = 'Utility'
526 ctls = [os.path.join(
529 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl')]
530 lut = '%s_to_linear.spi1d' % name
534 generate_1d_LUT_from_CTL(
535 os.path.join(lut_directory, lut),
547 cs.to_reference_transforms = []
548 cs.to_reference_transforms.append({
551 'interpolation': 'linear',
552 'direction': 'forward'})
554 cs.from_reference_transforms = []
557 # -------------------------------------------------------------------------
558 # *Dolby PQ Transform that considers a fixed linear range*
559 # -------------------------------------------------------------------------
560 def create_dolbypq_scaled(aces_CTL_directory,
572 cs = ColorSpace(name)
573 cs.description = 'The %s color space' % name
575 cs.equality_group = name
576 cs.family = 'Utility'
579 ctls = [os.path.join(
582 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl')]
583 lut = '%s_to_linear.spi1d' % name
587 generate_1d_LUT_from_CTL(
588 os.path.join(lut_directory, lut),
594 {'middleGrey': middle_grey,
595 'minExposure': min_exposure,
596 'maxExposure': max_exposure},
602 cs.to_reference_transforms = []
603 cs.to_reference_transforms.append({
606 'interpolation': 'linear',
607 'direction': 'forward'})
609 cs.from_reference_transforms = []
612 # -------------------------------------------------------------------------
614 # -------------------------------------------------------------------------
615 def create_ACES_LMT(lmt_name,
620 lut_resolution_1d=1024,
621 lut_resolution_3d=64,
625 Creates the *ACES LMT* colorspace.
630 Parameter description.
635 *ACES LMT* colorspace.
641 cs = ColorSpace('%s' % lmt_name)
642 cs.description = 'The ACES Look Transform: %s' % lmt_name
644 cs.equality_group = ''
647 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
648 cs.allocation_vars = [-8, 5, 0.00390625]
650 pprint.pprint(lmt_values)
652 # Generating the *shaper* transform.
655 shaper_from_ACES_CTL,
657 shaper_params) = shaper_info
659 # Add the shaper transform
660 shaper_lut = '%s_to_linear.spi1d' % shaper_name
661 shaper_lut = sanitize(shaper_lut)
663 shaper_OCIO_transform = {
666 'interpolation': 'linear',
667 'direction': 'inverse'}
669 # Generating the forward transform.
670 cs.from_reference_transforms = []
672 if 'transformCTL' in lmt_values:
673 ctls = [shaper_to_ACES_CTL % aces_ctl_directory,
674 os.path.join(aces_ctl_directory,
675 lmt_values['transformCTL'])]
676 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
680 generate_3d_LUT_from_CTL(
681 os.path.join(lut_directory, lut),
685 1 / shaper_input_scale,
691 cs.from_reference_transforms.append(shaper_OCIO_transform)
692 cs.from_reference_transforms.append({
695 'interpolation': 'tetrahedral',
696 'direction': 'forward'})
698 # Generating the inverse transform.
699 cs.to_reference_transforms = []
701 if 'transformCTLInverse' in lmt_values:
702 ctls = [os.path.join(aces_ctl_directory,
703 lmt_values['transformCTLInverse']),
704 shaper_from_ACES_CTL % aces_ctl_directory]
705 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
709 generate_3d_LUT_from_CTL(
710 os.path.join(lut_directory, lut),
723 cs.to_reference_transforms.append({
726 'interpolation': 'tetrahedral',
727 'direction': 'forward'})
729 shaper_inverse = shaper_OCIO_transform.copy()
730 shaper_inverse['direction'] = 'forward'
731 cs.to_reference_transforms.append(shaper_inverse)
735 # -------------------------------------------------------------------------
737 # -------------------------------------------------------------------------
738 def create_LMTs(aces_ctl_directory,
751 Parameter description.
756 Return value description.
761 # -------------------------------------------------------------------------
763 # -------------------------------------------------------------------------
764 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
765 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
767 # Defining the *Log 2* shaper.
768 lmt_shaper_name = 'LMT Shaper'
769 lmt_shaper_name_aliases = ['crv_lmtshaper']
775 lmt_shaper = create_generic_log(aces_ctl_directory,
777 lmt_lut_resolution_1d,
779 name=lmt_shaper_name,
780 middle_grey=lmt_params['middleGrey'],
781 min_exposure=lmt_params['minExposure'],
782 max_exposure=lmt_params['maxExposure'],
783 aliases=lmt_shaper_name_aliases)
784 colorspaces.append(lmt_shaper)
786 shaper_input_scale_generic_log2 = 1
788 # *Log 2* shaper name and *CTL* transforms bundled up.
793 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
796 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
797 shaper_input_scale_generic_log2,
800 sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
802 for lmt in sorted_LMTs:
803 lmt_name, lmt_values = lmt
804 lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])]
805 cs = create_ACES_LMT(
806 lmt_values['transformUserName'],
811 lmt_lut_resolution_1d,
812 lmt_lut_resolution_3d,
815 colorspaces.append(cs)
819 # -------------------------------------------------------------------------
820 # *ACES RRT* with supplied *ODT*.
821 # -------------------------------------------------------------------------
822 def create_ACES_RRT_plus_ODT(odt_name,
827 lut_resolution_1d=1024,
828 lut_resolution_3d=64,
837 Parameter description.
842 Return value description.
848 cs = ColorSpace('%s' % odt_name)
849 cs.description = '%s - %s Output Transform' % (
850 odt_values['transformUserNamePrefix'], odt_name)
852 cs.equality_group = ''
856 pprint.pprint(odt_values)
858 # Generating the *shaper* transform.
861 shaper_from_ACES_CTL,
863 shaper_params) = shaper_info
865 if 'legalRange' in odt_values:
866 shaper_params['legalRange'] = odt_values['legalRange']
868 shaper_params['legalRange'] = 0
870 # Add the shaper transform
871 shaper_lut = '%s_to_linear.spi1d' % shaper_name
872 shaper_lut = sanitize(shaper_lut)
874 shaper_OCIO_transform = {
877 'interpolation': 'linear',
878 'direction': 'inverse'}
880 # Generating the *forward* transform.
881 cs.from_reference_transforms = []
883 if 'transformLUT' in odt_values:
884 transform_LUT_file_name = os.path.basename(
885 odt_values['transformLUT'])
886 lut = os.path.join(lut_directory, transform_LUT_file_name)
887 shutil.copy(odt_values['transformLUT'], lut)
889 cs.from_reference_transforms.append(shaper_OCIO_transform)
890 cs.from_reference_transforms.append({
892 'path': transform_LUT_file_name,
893 'interpolation': 'tetrahedral',
894 'direction': 'forward'})
895 elif 'transformCTL' in odt_values:
897 shaper_to_ACES_CTL % aces_ctl_directory,
898 os.path.join(aces_ctl_directory,
901 os.path.join(aces_ctl_directory,
903 odt_values['transformCTL'])]
904 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
908 generate_3d_LUT_from_CTL(
909 os.path.join(lut_directory, lut),
914 1 / shaper_input_scale,
920 cs.from_reference_transforms.append(shaper_OCIO_transform)
921 cs.from_reference_transforms.append({
924 'interpolation': 'tetrahedral',
925 'direction': 'forward'})
927 # Generating the *inverse* transform.
928 cs.to_reference_transforms = []
930 if 'transformLUTInverse' in odt_values:
931 transform_LUT_inverse_file_name = os.path.basename(
932 odt_values['transformLUTInverse'])
933 lut = os.path.join(lut_directory, transform_LUT_inverse_file_name)
934 shutil.copy(odt_values['transformLUTInverse'], lut)
936 cs.to_reference_transforms.append({
938 'path': transform_LUT_inverse_file_name,
939 'interpolation': 'tetrahedral',
940 'direction': 'forward'})
942 shaper_inverse = shaper_OCIO_transform.copy()
943 shaper_inverse['direction'] = 'forward'
944 cs.to_reference_transforms.append(shaper_inverse)
945 elif 'transformCTLInverse' in odt_values:
946 ctls = [os.path.join(aces_ctl_directory,
948 odt_values['transformCTLInverse']),
949 os.path.join(aces_ctl_directory,
951 'InvRRT.a1.0.0.ctl'),
952 shaper_from_ACES_CTL % aces_ctl_directory]
953 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
957 generate_3d_LUT_from_CTL(
958 os.path.join(lut_directory, lut),
969 cs.to_reference_transforms.append({
972 'interpolation': 'tetrahedral',
973 'direction': 'forward'})
975 shaper_inverse = shaper_OCIO_transform.copy()
976 shaper_inverse['direction'] = 'forward'
977 cs.to_reference_transforms.append(shaper_inverse)
981 # -------------------------------------------------------------------------
983 # -------------------------------------------------------------------------
984 def create_ODTs(aces_ctl_directory,
991 linear_display_space,
999 Parameter description.
1004 Return value description.
1010 # -------------------------------------------------------------------------
1011 # *RRT / ODT* Shaper Options
1012 # -------------------------------------------------------------------------
1015 # Defining the *Log 2* shaper.
1016 log2_shaper_name = shaper_name
1017 log2_shaper_name_aliases = ["crv_%s" % compact(log2_shaper_name)]
1023 log2_shaper_colorspace = create_generic_log(
1028 name=log2_shaper_name,
1029 middle_grey=log2_params['middleGrey'],
1030 min_exposure=log2_params['minExposure'],
1031 max_exposure=log2_params['maxExposure'],
1032 aliases=log2_shaper_name_aliases)
1033 colorspaces.append(log2_shaper_colorspace)
1035 shaper_input_scale_generic_log2 = 1
1037 # *Log 2* shaper name and *CTL* transforms bundled up.
1038 log2_shaper_data = [
1042 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
1045 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
1046 shaper_input_scale_generic_log2,
1049 shaper_data[log2_shaper_name] = log2_shaper_data
1051 # Space with a more user-friendly name. Direct copy otherwise.
1052 log2_shaper_copy_name = "Log2 Shaper"
1053 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1054 log2_shaper_copy_colorspace.description = 'The %s color space' % log2_shaper_copy_name
1055 log2_shaper_copy_colorspace.aliases = [compact(log2_shaper_copy_name)]
1056 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1057 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1058 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1059 log2_shaper_copy_colorspace.to_reference_transforms = list(log2_shaper_colorspace.to_reference_transforms)
1060 log2_shaper_copy_colorspace.from_reference_transforms = list(log2_shaper_colorspace.from_reference_transforms)
1061 colorspaces.append(log2_shaper_copy_colorspace)
1063 # Defining the *Log2 shaper that includes the AP1* primaries.
1064 # Needed for some LUT baking steps.
1065 log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper"
1066 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1067 log2_shaper_api1_colorspace.description = 'The %s color space' % log2_shaper_api1_name
1068 log2_shaper_api1_colorspace.aliases = ["%s_ap1" % compact(log2_shaper_copy_name)]
1069 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1070 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1071 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1072 log2_shaper_api1_colorspace.to_reference_transforms = list(log2_shaper_colorspace.to_reference_transforms)
1073 log2_shaper_api1_colorspace.from_reference_transforms = list(log2_shaper_colorspace.from_reference_transforms)
1075 # *AP1* primaries to *AP0* primaries.
1076 log2_shaper_api1_colorspace.to_reference_transforms.append({
1078 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1079 'direction': 'forward'
1081 colorspaces.append(log2_shaper_api1_colorspace)
1083 # Define the base *Dolby PQ Shaper*
1085 dolbypq_shaper_name = "Dolby PQ 10000"
1086 dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"]
1088 dolbypq_shaper_colorspace = create_dolbypq(
1093 name=dolbypq_shaper_name,
1094 aliases=dolbypq_shaper_name_aliases)
1095 colorspaces.append(dolbypq_shaper_colorspace)
1097 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1098 dolbypq_shaper_data = [
1099 dolbypq_shaper_name,
1102 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl'),
1105 'ACESlib.OCIO_shaper_lin_to_dolbypq.a1.0.0.ctl'),
1109 shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1111 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1113 dolbypq_scaled_shaper_name = "Dolby PQ Scaled"
1114 dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"]
1116 dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled(
1121 name=dolbypq_scaled_shaper_name,
1122 aliases=dolbypq_scaled_shaper_name_aliases)
1123 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1125 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1126 dolbypq_scaled_shaper_data = [
1127 dolbypq_scaled_shaper_name,
1130 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl'),
1133 'ACESlib.OCIO_shaper_lin_to_dolbypq_param.a1.0.0.ctl'),
1137 shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1140 # Pick a specific shaper
1142 rrt_shaper = log2_shaper_data
1143 #rrt_shaper = dolbypq_scaled_shaper_data
1145 # *RRT + ODT* combinations.
1146 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1148 for odt in sorted_odts:
1149 (odt_name, odt_values) = odt
1151 # Generating legal range transform for *ODTs* that can generate
1152 # either *legal* or *full* output.
1153 if odt_values['transformHasFullLegalSwitch']:
1154 odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1156 odt_name_legal = odt_values['transformUserName']
1158 odt_legal = odt_values.copy()
1159 odt_legal['legalRange'] = 1
1161 odt_aliases = ["out_%s" % compact(odt_name_legal)]
1163 cs = create_ACES_RRT_plus_ODT(
1173 colorspaces.append(cs)
1175 displays[odt_name_legal] = {
1176 'Linear': linear_display_space,
1177 'Log': log_display_space,
1178 'Output Transform': cs}
1181 # Generating full range transform for *ODTs* that can generate
1182 # either *legal* or *full* output.
1183 if odt_values['transformHasFullLegalSwitch']:
1184 print('Generating full range ODT for %s' % odt_name)
1186 odt_name_full = '%s - Full' % odt_values['transformUserName']
1187 odt_full = odt_values.copy()
1188 odt_full['legalRange'] = 0
1190 odt_full_aliases = ["out_%s" % compact(odt_name_full)]
1192 cs_full = create_ACES_RRT_plus_ODT(
1202 colorspaces.append(cs_full)
1204 displays[odt_name_full] = {
1205 'Linear': linear_display_space,
1206 'Log': log_display_space,
1207 'Output Transform': cs_full}
1209 return (colorspaces, displays)
1212 def get_transform_info(ctl_transform):
1219 Parameter description.
1224 Return value description.
1227 with open(ctl_transform, 'rb') as fp:
1228 lines = fp.readlines()
1230 # Retrieving the *transform ID* and *User Name*.
1231 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1232 transform_user_name = '-'.join(
1233 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1234 transform_user_name_prefix = (
1235 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1237 # Figuring out if this transform has options for processing full and legal range
1238 transform_full_legal_switch = False
1240 if line.strip() == "input varying int legalRange = 0":
1241 # print( "%s has legal range flag" % transform_user_name)
1242 transform_full_legal_switch = True
1245 return (transform_id, transform_user_name, transform_user_name_prefix,
1246 transform_full_legal_switch)
1249 def get_ODTs_info(aces_ctl_directory):
1253 For versions after WGR9.
1258 Parameter description.
1263 Return value description.
1266 # TODO: Investigate usage of *files_walker* definition here.
1267 # Credit to *Alex Fry* for the original approach here.
1268 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1270 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1271 for fname in file_list:
1272 all_odt.append((os.path.join(dir_name, fname)))
1274 odt_CTLs = [x for x in all_odt if
1275 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1279 for odt_CTL in odt_CTLs:
1280 odt_tokens = os.path.split(odt_CTL)
1282 # Handling nested directories.
1283 odt_path_tokens = os.path.split(odt_tokens[-2])
1284 odt_dir = odt_path_tokens[-1]
1285 while odt_path_tokens[-2][-3:] != 'odt':
1286 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1287 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1289 # Building full name,
1290 transform_CTL = odt_tokens[-1]
1291 odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1293 # Finding id, user name and user name prefix.
1295 transform_user_name,
1296 transform_user_name_prefix,
1297 transform_full_legal_switch) = get_transform_info(
1298 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL))
1301 transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1302 if not os.path.exists(
1303 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1304 transform_CTL_inverse = None
1306 # Add to list of ODTs
1308 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1309 if transform_CTL_inverse is not None:
1310 odts[odt_name]['transformCTLInverse'] = os.path.join(
1311 odt_dir, transform_CTL_inverse)
1313 odts[odt_name]['transformID'] = transform_ID
1314 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1315 odts[odt_name]['transformUserName'] = transform_user_name
1317 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1319 forward_CTL = odts[odt_name]['transformCTL']
1321 print('ODT : %s' % odt_name)
1322 print('\tTransform ID : %s' % transform_ID)
1323 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1324 print('\tTransform User Name : %s' % transform_user_name)
1326 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1327 print('\tForward ctl : %s' % forward_CTL)
1328 if 'transformCTLInverse' in odts[odt_name]:
1329 inverse_CTL = odts[odt_name]['transformCTLInverse']
1330 print('\tInverse ctl : %s' % inverse_CTL)
1332 print('\tInverse ctl : %s' % 'None')
1339 def get_LMTs_info(aces_ctl_directory):
1343 For versions after WGR9.
1348 Parameter description.
1353 Return value description.
1356 # TODO: Investigate refactoring with previous definition.
1358 # Credit to Alex Fry for the original approach here
1359 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1361 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1362 for fname in file_list:
1363 all_lmt.append((os.path.join(dir_name, fname)))
1365 lmt_CTLs = [x for x in all_lmt if
1366 ('InvLMT' not in x) and ('README' not in x) and (
1367 os.path.split(x)[-1][0] != '.')]
1371 for lmt_CTL in lmt_CTLs:
1372 lmt_tokens = os.path.split(lmt_CTL)
1374 # Handlimg nested directories.
1375 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1376 lmt_dir = lmt_path_tokens[-1]
1377 while lmt_path_tokens[-2][-3:] != 'ctl':
1378 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1379 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1381 # Building full name.
1382 transform_CTL = lmt_tokens[-1]
1383 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1385 # Finding id, user name and user name prefix.
1387 transform_user_name,
1388 transform_user_name_prefix,
1389 transform_full_legal_switch) = get_transform_info(
1390 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1393 transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1394 if not os.path.exists(
1395 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1396 transform_CTL_inverse = None
1399 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1400 if transform_CTL_inverse is not None:
1401 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1402 lmt_dir, transform_CTL_inverse)
1404 lmts[lmt_name]['transformID'] = transform_ID
1405 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1406 lmts[lmt_name]['transformUserName'] = transform_user_name
1408 forward_CTL = lmts[lmt_name]['transformCTL']
1410 print('LMT : %s' % lmt_name)
1411 print('\tTransform ID : %s' % transform_ID)
1412 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1413 print('\tTransform User Name : %s' % transform_user_name)
1414 print('\t Forward ctl : %s' % forward_CTL)
1415 if 'transformCTLInverse' in lmts[lmt_name]:
1416 inverse_CTL = lmts[lmt_name]['transformCTLInverse']
1417 print('\t Inverse ctl : %s' % inverse_CTL)
1419 print('\t Inverse ctl : %s' % 'None')
1426 def create_colorspaces(aces_ctl_directory,
1435 Generates the colorspace conversions.
1440 Parameter description.
1445 Return value description.
1450 ACES = create_ACES()
1452 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1453 lut_resolution_1d, cleanup,
1454 min_value=-0.35840, max_value=1.468)
1455 colorspaces.append(ACEScc)
1457 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1458 lut_resolution_1d, cleanup)
1459 colorspaces.append(ACESproxy)
1461 ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1462 lut_resolution_1d, cleanup)
1463 colorspaces.append(ACEScg)
1465 ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1466 colorspaces.append(ADX10)
1468 ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1469 colorspaces.append(ADX16)
1471 lmts = create_LMTs(aces_ctl_directory,
1478 colorspaces.extend(lmts)
1480 odts, displays = create_ODTs(aces_ctl_directory,
1489 colorspaces.extend(odts)
1491 roles = {'color_picking' : ACEScg.name,
1492 'color_timing' : ACEScc.name,
1493 'compositing_log' : ACEScc.name,
1495 'default' : ACES.name,
1496 'matte_paint' : ACEScc.name,
1498 'scene_linear' : ACEScg.name,
1499 'texture_paint' : ''}
1502 return ACES, colorspaces, displays, ACEScc, roles