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 = []
438 # -------------------------------------------------------------------------
439 # *Generic Log Transform*
440 # -------------------------------------------------------------------------
441 def create_generic_log(aces_ctl_directory,
454 Creates the *Generic Log* colorspace.
459 Parameter description.
464 *Generic Log* colorspace.
467 cs = ColorSpace(name)
468 cs.description = 'The %s color space' % name
470 cs.equality_group = name
471 cs.family = 'Utility'
474 ctls = [os.path.join(
477 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')]
478 lut = '%s_to_linear.spi1d' % name
482 generate_1d_LUT_from_CTL(
483 os.path.join(lut_directory, lut),
489 {'middleGrey': middle_grey,
490 'minExposure': min_exposure,
491 'maxExposure': max_exposure},
498 cs.to_reference_transforms = []
499 cs.to_reference_transforms.append({
502 'interpolation': 'linear',
503 'direction': 'forward'})
505 cs.from_reference_transforms = []
509 # -------------------------------------------------------------------------
510 # *base Dolby PQ Transform*
511 # -------------------------------------------------------------------------
512 def create_dolbypq(aces_CTL_directory,
521 cs = ColorSpace(name)
522 cs.description = 'The %s color space' % name
524 cs.equality_group = name
525 cs.family = 'Utility'
528 ctls = [os.path.join(
531 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl')]
532 lut = '%s_to_linear.spi1d' % name
536 generate_1d_LUT_from_CTL(
537 os.path.join(lut_directory, lut),
549 cs.to_reference_transforms = []
550 cs.to_reference_transforms.append({
553 'interpolation': 'linear',
554 'direction': 'forward'})
556 cs.from_reference_transforms = []
560 # -------------------------------------------------------------------------
561 # *Dolby PQ Transform that considers a fixed linear range*
562 # -------------------------------------------------------------------------
563 def create_dolbypq_scaled(aces_CTL_directory,
575 cs = ColorSpace(name)
576 cs.description = 'The %s color space' % name
578 cs.equality_group = name
579 cs.family = 'Utility'
582 ctls = [os.path.join(
585 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl')]
586 lut = '%s_to_linear.spi1d' % name
590 generate_1d_LUT_from_CTL(
591 os.path.join(lut_directory, lut),
597 {'middleGrey': middle_grey,
598 'minExposure': min_exposure,
599 'maxExposure': max_exposure},
605 cs.to_reference_transforms = []
606 cs.to_reference_transforms.append({
609 'interpolation': 'linear',
610 'direction': 'forward'})
612 cs.from_reference_transforms = []
616 # -------------------------------------------------------------------------
618 # -------------------------------------------------------------------------
619 def create_ACES_LMT(lmt_name,
624 lut_resolution_1d=1024,
625 lut_resolution_3d=64,
629 Creates the *ACES LMT* colorspace.
634 Parameter description.
639 *ACES LMT* colorspace.
645 cs = ColorSpace('%s' % lmt_name)
646 cs.description = 'The ACES Look Transform: %s' % lmt_name
648 cs.equality_group = ''
651 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
652 cs.allocation_vars = [-8, 5, 0.00390625]
654 pprint.pprint(lmt_values)
656 # Generating the *shaper* transform.
659 shaper_from_ACES_CTL,
661 shaper_params) = shaper_info
663 # Add the shaper transform
664 shaper_lut = '%s_to_linear.spi1d' % shaper_name
665 shaper_lut = sanitize(shaper_lut)
667 shaper_OCIO_transform = {
670 'interpolation': 'linear',
671 'direction': 'inverse'}
673 # Generating the forward transform.
674 cs.from_reference_transforms = []
676 if 'transformCTL' in lmt_values:
677 ctls = [shaper_to_ACES_CTL % aces_ctl_directory,
678 os.path.join(aces_ctl_directory,
679 lmt_values['transformCTL'])]
680 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
684 generate_3d_LUT_from_CTL(
685 os.path.join(lut_directory, lut),
689 1 / shaper_input_scale,
695 cs.from_reference_transforms.append(shaper_OCIO_transform)
696 cs.from_reference_transforms.append({
699 'interpolation': 'tetrahedral',
700 'direction': 'forward'})
702 # Generating the inverse transform.
703 cs.to_reference_transforms = []
705 if 'transformCTLInverse' in lmt_values:
706 ctls = [os.path.join(aces_ctl_directory,
707 lmt_values['transformCTLInverse']),
708 shaper_from_ACES_CTL % aces_ctl_directory]
709 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
713 generate_3d_LUT_from_CTL(
714 os.path.join(lut_directory, lut),
727 cs.to_reference_transforms.append({
730 'interpolation': 'tetrahedral',
731 'direction': 'forward'})
733 shaper_inverse = shaper_OCIO_transform.copy()
734 shaper_inverse['direction'] = 'forward'
735 cs.to_reference_transforms.append(shaper_inverse)
740 # -------------------------------------------------------------------------
742 # -------------------------------------------------------------------------
743 def create_LMTs(aces_ctl_directory,
756 Parameter description.
761 Return value description.
766 # -------------------------------------------------------------------------
768 # -------------------------------------------------------------------------
769 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
770 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
772 # Defining the *Log 2* shaper.
773 lmt_shaper_name = 'LMT Shaper'
774 lmt_shaper_name_aliases = ['crv_lmtshaper']
780 lmt_shaper = create_generic_log(aces_ctl_directory,
782 lmt_lut_resolution_1d,
784 name=lmt_shaper_name,
785 middle_grey=lmt_params['middleGrey'],
786 min_exposure=lmt_params['minExposure'],
787 max_exposure=lmt_params['maxExposure'],
788 aliases=lmt_shaper_name_aliases)
789 colorspaces.append(lmt_shaper)
791 shaper_input_scale_generic_log2 = 1
793 # *Log 2* shaper name and *CTL* transforms bundled up.
798 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
801 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
802 shaper_input_scale_generic_log2,
805 sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
807 for lmt in sorted_LMTs:
808 lmt_name, lmt_values = lmt
809 lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])]
810 cs = create_ACES_LMT(
811 lmt_values['transformUserName'],
816 lmt_lut_resolution_1d,
817 lmt_lut_resolution_3d,
820 colorspaces.append(cs)
825 # -------------------------------------------------------------------------
826 # *ACES RRT* with supplied *ODT*.
827 # -------------------------------------------------------------------------
828 def create_ACES_RRT_plus_ODT(odt_name,
833 lut_resolution_1d=1024,
834 lut_resolution_3d=64,
843 Parameter description.
848 Return value description.
854 cs = ColorSpace('%s' % odt_name)
855 cs.description = '%s - %s Output Transform' % (
856 odt_values['transformUserNamePrefix'], odt_name)
858 cs.equality_group = ''
862 pprint.pprint(odt_values)
864 # Generating the *shaper* transform.
867 shaper_from_ACES_CTL,
869 shaper_params) = shaper_info
871 if 'legalRange' in odt_values:
872 shaper_params['legalRange'] = odt_values['legalRange']
874 shaper_params['legalRange'] = 0
876 # Add the shaper transform
877 shaper_lut = '%s_to_linear.spi1d' % shaper_name
878 shaper_lut = sanitize(shaper_lut)
880 shaper_OCIO_transform = {
883 'interpolation': 'linear',
884 'direction': 'inverse'}
886 # Generating the *forward* transform.
887 cs.from_reference_transforms = []
889 if 'transformLUT' in odt_values:
890 transform_LUT_file_name = os.path.basename(
891 odt_values['transformLUT'])
892 lut = os.path.join(lut_directory, transform_LUT_file_name)
893 shutil.copy(odt_values['transformLUT'], lut)
895 cs.from_reference_transforms.append(shaper_OCIO_transform)
896 cs.from_reference_transforms.append({
898 'path': transform_LUT_file_name,
899 'interpolation': 'tetrahedral',
900 'direction': 'forward'})
901 elif 'transformCTL' in odt_values:
903 shaper_to_ACES_CTL % aces_ctl_directory,
904 os.path.join(aces_ctl_directory,
907 os.path.join(aces_ctl_directory,
909 odt_values['transformCTL'])]
910 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
914 generate_3d_LUT_from_CTL(
915 os.path.join(lut_directory, lut),
920 1 / shaper_input_scale,
926 cs.from_reference_transforms.append(shaper_OCIO_transform)
927 cs.from_reference_transforms.append({
930 'interpolation': 'tetrahedral',
931 'direction': 'forward'})
933 # Generating the *inverse* transform.
934 cs.to_reference_transforms = []
936 if 'transformLUTInverse' in odt_values:
937 transform_LUT_inverse_file_name = os.path.basename(
938 odt_values['transformLUTInverse'])
939 lut = os.path.join(lut_directory, transform_LUT_inverse_file_name)
940 shutil.copy(odt_values['transformLUTInverse'], lut)
942 cs.to_reference_transforms.append({
944 'path': transform_LUT_inverse_file_name,
945 'interpolation': 'tetrahedral',
946 'direction': 'forward'})
948 shaper_inverse = shaper_OCIO_transform.copy()
949 shaper_inverse['direction'] = 'forward'
950 cs.to_reference_transforms.append(shaper_inverse)
951 elif 'transformCTLInverse' in odt_values:
952 ctls = [os.path.join(aces_ctl_directory,
954 odt_values['transformCTLInverse']),
955 os.path.join(aces_ctl_directory,
957 'InvRRT.a1.0.0.ctl'),
958 shaper_from_ACES_CTL % aces_ctl_directory]
959 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
963 generate_3d_LUT_from_CTL(
964 os.path.join(lut_directory, lut),
975 cs.to_reference_transforms.append({
978 'interpolation': 'tetrahedral',
979 'direction': 'forward'})
981 shaper_inverse = shaper_OCIO_transform.copy()
982 shaper_inverse['direction'] = 'forward'
983 cs.to_reference_transforms.append(shaper_inverse)
988 # -------------------------------------------------------------------------
990 # -------------------------------------------------------------------------
991 def create_ODTs(aces_ctl_directory,
998 linear_display_space,
1006 Parameter description.
1011 Return value description.
1017 # -------------------------------------------------------------------------
1018 # *RRT / ODT* Shaper Options
1019 # -------------------------------------------------------------------------
1022 # Defining the *Log 2* shaper.
1023 log2_shaper_name = shaper_name
1024 log2_shaper_name_aliases = ["crv_%s" % compact(log2_shaper_name)]
1030 log2_shaper_colorspace = create_generic_log(
1035 name=log2_shaper_name,
1036 middle_grey=log2_params['middleGrey'],
1037 min_exposure=log2_params['minExposure'],
1038 max_exposure=log2_params['maxExposure'],
1039 aliases=log2_shaper_name_aliases)
1040 colorspaces.append(log2_shaper_colorspace)
1042 shaper_input_scale_generic_log2 = 1
1044 # *Log 2* shaper name and *CTL* transforms bundled up.
1045 log2_shaper_data = [
1049 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
1052 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
1053 shaper_input_scale_generic_log2,
1056 shaper_data[log2_shaper_name] = log2_shaper_data
1058 # Space with a more user-friendly name. Direct copy otherwise.
1059 log2_shaper_copy_name = "Log2 Shaper"
1060 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1061 log2_shaper_copy_colorspace.description = 'The %s color space' % log2_shaper_copy_name
1062 log2_shaper_copy_colorspace.aliases = [compact(log2_shaper_copy_name)]
1063 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1064 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1065 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1066 log2_shaper_copy_colorspace.to_reference_transforms = list(
1067 log2_shaper_colorspace.to_reference_transforms)
1068 log2_shaper_copy_colorspace.from_reference_transforms = list(
1069 log2_shaper_colorspace.from_reference_transforms)
1070 colorspaces.append(log2_shaper_copy_colorspace)
1072 # Defining the *Log2 shaper that includes the AP1* primaries.
1073 log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper"
1074 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1075 log2_shaper_api1_colorspace.description = 'The %s color space' % log2_shaper_api1_name
1076 log2_shaper_api1_colorspace.aliases = [
1077 "%s_ap1" % compact(log2_shaper_copy_name)]
1078 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1079 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1080 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1081 log2_shaper_api1_colorspace.to_reference_transforms = list(
1082 log2_shaper_colorspace.to_reference_transforms)
1083 log2_shaper_api1_colorspace.from_reference_transforms = list(
1084 log2_shaper_colorspace.from_reference_transforms)
1086 # *AP1* primaries to *AP0* primaries.
1087 log2_shaper_api1_colorspace.to_reference_transforms.append({
1089 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1090 'direction': 'forward'
1092 colorspaces.append(log2_shaper_api1_colorspace)
1094 # Defining the *Log2 shaper that includes the AP1* primaries.
1095 # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1096 shaper_api1_name = "%s - AP1" % shaper_name
1097 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1098 shaper_api1_colorspace.description = 'The %s color space' % shaper_api1_name
1099 shaper_api1_colorspace.aliases = ["%s_ap1" % compact(shaper_api1_name)]
1100 shaper_api1_colorspace.equality_group = shaper_api1_name
1101 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1102 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1103 shaper_api1_colorspace.to_reference_transforms = list(
1104 log2_shaper_api1_colorspace.to_reference_transforms)
1105 shaper_api1_colorspace.from_reference_transforms = list(
1106 log2_shaper_api1_colorspace.from_reference_transforms)
1107 colorspaces.append(shaper_api1_colorspace)
1109 # Define the base *Dolby PQ Shaper*
1111 dolbypq_shaper_name = "Dolby PQ 10000"
1112 dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"]
1114 dolbypq_shaper_colorspace = create_dolbypq(
1119 name=dolbypq_shaper_name,
1120 aliases=dolbypq_shaper_name_aliases)
1121 colorspaces.append(dolbypq_shaper_colorspace)
1123 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1124 dolbypq_shaper_data = [
1125 dolbypq_shaper_name,
1128 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl'),
1131 'ACESlib.OCIO_shaper_lin_to_dolbypq.a1.0.0.ctl'),
1135 shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1137 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1139 dolbypq_scaled_shaper_name = "Dolby PQ Scaled"
1140 dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"]
1142 dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled(
1147 name=dolbypq_scaled_shaper_name,
1148 aliases=dolbypq_scaled_shaper_name_aliases)
1149 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1151 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1152 dolbypq_scaled_shaper_data = [
1153 dolbypq_scaled_shaper_name,
1156 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl'),
1159 'ACESlib.OCIO_shaper_lin_to_dolbypq_param.a1.0.0.ctl'),
1163 shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1166 # Pick a specific shaper
1168 rrt_shaper = log2_shaper_data
1169 # rrt_shaper = dolbypq_scaled_shaper_data
1171 # *RRT + ODT* combinations.
1172 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1174 for odt in sorted_odts:
1175 (odt_name, odt_values) = odt
1177 # Generating legal range transform for *ODTs* that can generate
1178 # either *legal* or *full* output.
1179 if odt_values['transformHasFullLegalSwitch']:
1180 odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1182 odt_name_legal = odt_values['transformUserName']
1184 odt_legal = odt_values.copy()
1185 odt_legal['legalRange'] = 1
1187 odt_aliases = ["out_%s" % compact(odt_name_legal)]
1189 cs = create_ACES_RRT_plus_ODT(
1199 colorspaces.append(cs)
1201 displays[odt_name_legal] = {
1202 'Linear': linear_display_space,
1203 'Log': log_display_space,
1204 'Output Transform': cs}
1207 # Generating full range transform for *ODTs* that can generate
1208 # either *legal* or *full* output.
1209 if odt_values['transformHasFullLegalSwitch']:
1210 print('Generating full range ODT for %s' % odt_name)
1212 odt_name_full = '%s - Full' % odt_values['transformUserName']
1213 odt_full = odt_values.copy()
1214 odt_full['legalRange'] = 0
1216 odt_full_aliases = ["out_%s" % compact(odt_name_full)]
1218 cs_full = create_ACES_RRT_plus_ODT(
1228 colorspaces.append(cs_full)
1230 displays[odt_name_full] = {
1231 'Linear': linear_display_space,
1232 'Log': log_display_space,
1233 'Output Transform': cs_full}
1235 return (colorspaces, displays)
1238 def get_transform_info(ctl_transform):
1245 Parameter description.
1250 Return value description.
1253 with open(ctl_transform, 'rb') as fp:
1254 lines = fp.readlines()
1256 # Retrieving the *transform ID* and *User Name*.
1257 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1258 transform_user_name = '-'.join(
1259 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1260 transform_user_name_prefix = (
1261 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1263 # Figuring out if this transform has options for processing full and legal range
1264 transform_full_legal_switch = False
1266 if line.strip() == "input varying int legalRange = 0":
1267 # print( "%s has legal range flag" % transform_user_name)
1268 transform_full_legal_switch = True
1271 return (transform_id, transform_user_name, transform_user_name_prefix,
1272 transform_full_legal_switch)
1275 def get_ODTs_info(aces_ctl_directory):
1279 For versions after WGR9.
1284 Parameter description.
1289 Return value description.
1292 # TODO: Investigate usage of *files_walker* definition here.
1293 # Credit to *Alex Fry* for the original approach here.
1294 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1296 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1297 for fname in file_list:
1298 all_odt.append((os.path.join(dir_name, fname)))
1300 odt_CTLs = [x for x in all_odt if
1301 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1305 for odt_CTL in odt_CTLs:
1306 odt_tokens = os.path.split(odt_CTL)
1308 # Handling nested directories.
1309 odt_path_tokens = os.path.split(odt_tokens[-2])
1310 odt_dir = odt_path_tokens[-1]
1311 while odt_path_tokens[-2][-3:] != 'odt':
1312 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1313 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1315 # Building full name,
1316 transform_CTL = odt_tokens[-1]
1317 odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1319 # Finding id, user name and user name prefix.
1321 transform_user_name,
1322 transform_user_name_prefix,
1323 transform_full_legal_switch) = get_transform_info(
1324 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL))
1327 transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1328 if not os.path.exists(
1329 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1330 transform_CTL_inverse = None
1332 # Add to list of ODTs
1334 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1335 if transform_CTL_inverse is not None:
1336 odts[odt_name]['transformCTLInverse'] = os.path.join(
1337 odt_dir, transform_CTL_inverse)
1339 odts[odt_name]['transformID'] = transform_ID
1340 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1341 odts[odt_name]['transformUserName'] = transform_user_name
1343 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1345 forward_CTL = odts[odt_name]['transformCTL']
1347 print('ODT : %s' % odt_name)
1348 print('\tTransform ID : %s' % transform_ID)
1349 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1350 print('\tTransform User Name : %s' % transform_user_name)
1352 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1353 print('\tForward ctl : %s' % forward_CTL)
1354 if 'transformCTLInverse' in odts[odt_name]:
1355 inverse_CTL = odts[odt_name]['transformCTLInverse']
1356 print('\tInverse ctl : %s' % inverse_CTL)
1358 print('\tInverse ctl : %s' % 'None')
1365 def get_LMTs_info(aces_ctl_directory):
1369 For versions after WGR9.
1374 Parameter description.
1379 Return value description.
1382 # TODO: Investigate refactoring with previous definition.
1384 # Credit to Alex Fry for the original approach here
1385 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1387 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1388 for fname in file_list:
1389 all_lmt.append((os.path.join(dir_name, fname)))
1391 lmt_CTLs = [x for x in all_lmt if
1392 ('InvLMT' not in x) and ('README' not in x) and (
1393 os.path.split(x)[-1][0] != '.')]
1397 for lmt_CTL in lmt_CTLs:
1398 lmt_tokens = os.path.split(lmt_CTL)
1400 # Handlimg nested directories.
1401 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1402 lmt_dir = lmt_path_tokens[-1]
1403 while lmt_path_tokens[-2][-3:] != 'ctl':
1404 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1405 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1407 # Building full name.
1408 transform_CTL = lmt_tokens[-1]
1409 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1411 # Finding id, user name and user name prefix.
1413 transform_user_name,
1414 transform_user_name_prefix,
1415 transform_full_legal_switch) = get_transform_info(
1416 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1419 transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1420 if not os.path.exists(
1421 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1422 transform_CTL_inverse = None
1425 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1426 if transform_CTL_inverse is not None:
1427 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1428 lmt_dir, transform_CTL_inverse)
1430 lmts[lmt_name]['transformID'] = transform_ID
1431 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1432 lmts[lmt_name]['transformUserName'] = transform_user_name
1434 forward_CTL = lmts[lmt_name]['transformCTL']
1436 print('LMT : %s' % lmt_name)
1437 print('\tTransform ID : %s' % transform_ID)
1438 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1439 print('\tTransform User Name : %s' % transform_user_name)
1440 print('\t Forward ctl : %s' % forward_CTL)
1441 if 'transformCTLInverse' in lmts[lmt_name]:
1442 inverse_CTL = lmts[lmt_name]['transformCTLInverse']
1443 print('\t Inverse ctl : %s' % inverse_CTL)
1445 print('\t Inverse ctl : %s' % 'None')
1452 def create_colorspaces(aces_ctl_directory,
1461 Generates the colorspace conversions.
1466 Parameter description.
1471 Return value description.
1476 ACES = create_ACES()
1478 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1479 lut_resolution_1d, cleanup,
1480 min_value=-0.35840, max_value=1.468)
1481 colorspaces.append(ACEScc)
1483 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1484 lut_resolution_1d, cleanup)
1485 colorspaces.append(ACESproxy)
1487 ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1488 lut_resolution_1d, cleanup)
1489 colorspaces.append(ACEScg)
1491 ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1492 colorspaces.append(ADX10)
1494 ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1495 colorspaces.append(ADX16)
1497 lmts = create_LMTs(aces_ctl_directory,
1504 colorspaces.extend(lmts)
1506 odts, displays = create_ODTs(aces_ctl_directory,
1515 colorspaces.extend(odts)
1517 roles = {'color_picking': ACEScg.name,
1518 'color_timing': ACEScc.name,
1519 'compositing_log': ACEScc.name,
1521 'default': ACES.name,
1522 'matte_paint': ACEScc.name,
1524 'scene_linear': ACES.name,
1525 'texture_paint': ''}
1527 return ACES, colorspaces, displays, ACEScc, roles