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 lut = '%s_to_linear.spi1d' % name
143 generate_1d_LUT_from_CTL(
144 os.path.join(lut_directory, lut),
150 {'transferFunctionOnly': 1},
157 cs.to_reference_transforms = []
158 cs.to_reference_transforms.append({
161 'interpolation': 'linear',
162 'direction': 'forward'})
164 # *AP1* primaries to *AP0* primaries.
165 cs.to_reference_transforms.append({
167 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
168 'direction': 'forward'})
170 cs.from_reference_transforms = []
174 def create_ACESproxy(aces_ctl_directory,
180 Creates the *ACESproxy* colorspace.
185 Parameter description.
190 *ACESproxy* colorspace.
193 cs = ColorSpace(name)
194 cs.description = 'The %s color space' % name
195 cs.aliases = ["acesproxy", "acesproxy_ap1"]
196 cs.equality_group = ''
200 cs.aces_transform_id = "ACEScsc.ACESproxy10i_to_ACES.a1.0.0"
202 ctls = [os.path.join(aces_ctl_directory,
204 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
205 # This transform gets back to the *AP1* primaries.
206 # Useful as the 1d LUT is only covering the transfer function.
207 # The primaries switch is covered by the matrix below:
208 os.path.join(aces_ctl_directory,
210 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
211 lut = '%s_to_linear.spi1d' % name
215 generate_1d_LUT_from_CTL(
216 os.path.join(lut_directory, lut),
229 cs.to_reference_transforms = []
230 cs.to_reference_transforms.append({
233 'interpolation': 'linear',
234 'direction': 'forward'})
236 # *AP1* primaries to *AP0* primaries.
237 cs.to_reference_transforms.append({
239 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
240 'direction': 'forward'})
242 cs.from_reference_transforms = []
246 # -------------------------------------------------------------------------
248 # -------------------------------------------------------------------------
249 def create_ACEScg(aces_ctl_directory,
255 Creates the *ACEScg* colorspace.
260 Parameter description.
268 cs = ColorSpace(name)
269 cs.description = 'The %s color space' % name
270 cs.aliases = ["acescg", "lin_ap1"]
271 cs.equality_group = ''
274 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
275 cs.allocation_vars = [-8, 5, 0.00390625]
277 cs.aces_transform_id = "ACEScsc.ACEScg_to_ACES.a1.0.0"
279 cs.to_reference_transforms = []
281 # *AP1* primaries to *AP0* primaries.
282 cs.to_reference_transforms.append({
284 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
285 'direction': 'forward'})
287 cs.from_reference_transforms = []
289 # *AP1* primaries to *AP0* primaries.
290 cs.from_reference_transforms.append({
292 'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
293 'direction': 'forward'})
298 # -------------------------------------------------------------------------
300 # -------------------------------------------------------------------------
301 def create_ADX(lut_directory,
306 Creates the *ADX* colorspace.
311 Parameter description.
319 name = '%s%s' % (name, bit_depth)
320 cs = ColorSpace(name)
321 cs.description = '%s color space - used for film scans' % name
322 cs.aliases = ["adx%s" % str(bit_depth)]
323 cs.equality_group = ''
328 cs.aces_transform_id = "ACEScsc.ADX10_to_ACES.a1.0.0"
330 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
331 ADX_to_CDD = [1023 / 500, 0, 0, 0,
335 offset = [-95 / 500, -95 / 500, -95 / 500, 0]
336 elif bit_depth == 16:
337 cs.aces_transform_id = "ACEScsc.ADX16_to_ACES.a1.0.0"
339 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
340 ADX_to_CDD = [65535 / 8000, 0, 0, 0,
341 0, 65535 / 8000, 0, 0,
342 0, 0, 65535 / 8000, 0,
344 offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
346 cs.to_reference_transforms = []
348 # Converting from *ADX* to *Channel-Dependent Density*.
349 cs.to_reference_transforms.append({
351 'matrix': ADX_to_CDD,
353 'direction': 'forward'})
355 # Convert from Channel-Dependent Density to Channel-Independent Density
356 cs.to_reference_transforms.append({
358 'matrix': [0.75573, 0.22197, 0.02230, 0,
359 0.05901, 0.96928, -0.02829, 0,
360 0.16134, 0.07406, 0.76460, 0,
362 'direction': 'forward'})
364 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
365 def create_CID_to_RLE_LUT():
367 def interpolate_1D(x, xp, fp):
368 return numpy.interp(x, xp, fp)
370 LUT_1D_xp = [-0.190000000000000,
382 LUT_1D_fp = [-6.000000000000000,
394 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
399 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
400 return (100 / 55) * x - REF_PT
402 def fit(value, from_min, from_max, to_min, to_max):
403 if from_min == from_max:
404 raise ValueError('from_min == from_max')
405 return (value - from_min) / (from_max - from_min) * (
406 to_max - to_min) + to_min
408 num_samples = 2 ** 12
411 for i in xrange(num_samples):
412 x = i / (num_samples - 1)
413 x = fit(x, 0, 1, domain[0], domain[1])
414 data.append(cid_to_rle(x))
416 lut = 'ADX_CID_to_RLE.spi1d'
417 write_SPI_1d(os.path.join(lut_directory, lut),
425 # Converting *Channel Independent Density* values to
426 # *Relative Log Exposure* values.
427 lut = create_CID_to_RLE_LUT()
428 cs.to_reference_transforms.append({
431 'interpolation': 'linear',
432 'direction': 'forward'})
434 # Converting *Relative Log Exposure* values to
435 # *Relative Exposure* values.
436 cs.to_reference_transforms.append({
439 'direction': 'inverse'})
441 # Convert *Relative Exposure* values to *ACES* values.
442 cs.to_reference_transforms.append({
444 'matrix': [0.72286, 0.12630, 0.15084, 0,
445 0.11923, 0.76418, 0.11659, 0,
446 0.01427, 0.08213, 0.90359, 0,
448 'direction': 'forward'})
450 cs.from_reference_transforms = []
454 # -------------------------------------------------------------------------
455 # *Generic Log Transform*
456 # -------------------------------------------------------------------------
457 def create_generic_log(aces_ctl_directory,
470 Creates the *Generic Log* colorspace.
475 Parameter description.
480 *Generic Log* colorspace.
483 cs = ColorSpace(name)
484 cs.description = 'The %s color space' % name
486 cs.equality_group = name
487 cs.family = 'Utility'
490 ctls = [os.path.join(
493 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl')]
494 lut = '%s_to_linear.spi1d' % name
498 generate_1d_LUT_from_CTL(
499 os.path.join(lut_directory, lut),
505 {'middleGrey': middle_grey,
506 'minExposure': min_exposure,
507 'maxExposure': max_exposure},
514 cs.to_reference_transforms = []
515 cs.to_reference_transforms.append({
518 'interpolation': 'linear',
519 'direction': 'forward'})
521 cs.from_reference_transforms = []
525 # -------------------------------------------------------------------------
526 # *base Dolby PQ Transform*
527 # -------------------------------------------------------------------------
528 def create_dolbypq(aces_CTL_directory,
537 cs = ColorSpace(name)
538 cs.description = 'The %s color space' % name
540 cs.equality_group = name
541 cs.family = 'Utility'
544 ctls = [os.path.join(
547 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl')]
548 lut = '%s_to_linear.spi1d' % name
552 generate_1d_LUT_from_CTL(
553 os.path.join(lut_directory, lut),
565 cs.to_reference_transforms = []
566 cs.to_reference_transforms.append({
569 'interpolation': 'linear',
570 'direction': 'forward'})
572 cs.from_reference_transforms = []
576 # -------------------------------------------------------------------------
577 # *Dolby PQ Transform that considers a fixed linear range*
578 # -------------------------------------------------------------------------
579 def create_dolbypq_scaled(aces_CTL_directory,
591 cs = ColorSpace(name)
592 cs.description = 'The %s color space' % name
594 cs.equality_group = name
595 cs.family = 'Utility'
598 ctls = [os.path.join(
601 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl')]
602 lut = '%s_to_linear.spi1d' % name
606 generate_1d_LUT_from_CTL(
607 os.path.join(lut_directory, lut),
613 {'middleGrey': middle_grey,
614 'minExposure': min_exposure,
615 'maxExposure': max_exposure},
621 cs.to_reference_transforms = []
622 cs.to_reference_transforms.append({
625 'interpolation': 'linear',
626 'direction': 'forward'})
628 cs.from_reference_transforms = []
632 # -------------------------------------------------------------------------
634 # -------------------------------------------------------------------------
635 def create_ACES_LMT(lmt_name,
640 lut_resolution_1d=1024,
641 lut_resolution_3d=64,
645 Creates the *ACES LMT* colorspace.
650 Parameter description.
655 *ACES LMT* colorspace.
661 cs = ColorSpace('%s' % lmt_name)
662 cs.description = 'The ACES Look Transform: %s' % lmt_name
664 cs.equality_group = ''
667 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
668 cs.allocation_vars = [-8, 5, 0.00390625]
670 pprint.pprint(lmt_values)
672 # Generating the *shaper* transform.
675 shaper_from_ACES_CTL,
677 shaper_params) = shaper_info
679 # Add the shaper transform
680 shaper_lut = '%s_to_linear.spi1d' % shaper_name
681 shaper_lut = sanitize(shaper_lut)
683 shaper_OCIO_transform = {
686 'interpolation': 'linear',
687 'direction': 'inverse'}
689 # Generating the forward transform.
690 cs.from_reference_transforms = []
692 if 'transformCTL' in lmt_values:
693 ctls = [shaper_to_ACES_CTL % aces_ctl_directory,
694 os.path.join(aces_ctl_directory,
695 lmt_values['transformCTL'])]
696 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
700 generate_3d_LUT_from_CTL(
701 os.path.join(lut_directory, lut),
705 1 / shaper_input_scale,
711 cs.from_reference_transforms.append(shaper_OCIO_transform)
712 cs.from_reference_transforms.append({
715 'interpolation': 'tetrahedral',
716 'direction': 'forward'})
718 # Generating the inverse transform.
719 cs.to_reference_transforms = []
721 if 'transformCTLInverse' in lmt_values:
722 ctls = [os.path.join(aces_ctl_directory,
723 lmt_values['transformCTLInverse']),
724 shaper_from_ACES_CTL % aces_ctl_directory]
725 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
729 generate_3d_LUT_from_CTL(
730 os.path.join(lut_directory, lut),
743 cs.to_reference_transforms.append({
746 'interpolation': 'tetrahedral',
747 'direction': 'forward'})
749 shaper_inverse = shaper_OCIO_transform.copy()
750 shaper_inverse['direction'] = 'forward'
751 cs.to_reference_transforms.append(shaper_inverse)
756 # -------------------------------------------------------------------------
758 # -------------------------------------------------------------------------
759 def create_LMTs(aces_ctl_directory,
772 Parameter description.
777 Return value description.
782 # -------------------------------------------------------------------------
784 # -------------------------------------------------------------------------
785 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
786 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
788 # Defining the *Log 2* shaper.
789 lmt_shaper_name = 'LMT Shaper'
790 lmt_shaper_name_aliases = ['crv_lmtshaper']
796 lmt_shaper = create_generic_log(aces_ctl_directory,
798 lmt_lut_resolution_1d,
800 name=lmt_shaper_name,
801 middle_grey=lmt_params['middleGrey'],
802 min_exposure=lmt_params['minExposure'],
803 max_exposure=lmt_params['maxExposure'],
804 aliases=lmt_shaper_name_aliases)
805 colorspaces.append(lmt_shaper)
807 shaper_input_scale_generic_log2 = 1
809 # *Log 2* shaper name and *CTL* transforms bundled up.
814 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
817 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
818 shaper_input_scale_generic_log2,
821 sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
823 for lmt in sorted_LMTs:
824 lmt_name, lmt_values = lmt
825 lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])]
826 cs = create_ACES_LMT(
827 lmt_values['transformUserName'],
832 lmt_lut_resolution_1d,
833 lmt_lut_resolution_3d,
836 colorspaces.append(cs)
841 # -------------------------------------------------------------------------
842 # *ACES RRT* with supplied *ODT*.
843 # -------------------------------------------------------------------------
844 def create_ACES_RRT_plus_ODT(odt_name,
849 lut_resolution_1d=1024,
850 lut_resolution_3d=64,
859 Parameter description.
864 Return value description.
870 cs = ColorSpace('%s' % odt_name)
871 cs.description = '%s - %s Output Transform' % (
872 odt_values['transformUserNamePrefix'], odt_name)
874 cs.equality_group = ''
878 cs.aces_transform_id = odt_values['transformID']
880 pprint.pprint(odt_values)
882 # Generating the *shaper* transform.
885 shaper_from_ACES_CTL,
887 shaper_params) = shaper_info
889 if 'legalRange' in odt_values:
890 shaper_params['legalRange'] = odt_values['legalRange']
892 shaper_params['legalRange'] = 0
894 # Add the shaper transform
895 shaper_lut = '%s_to_linear.spi1d' % shaper_name
896 shaper_lut = sanitize(shaper_lut)
898 shaper_OCIO_transform = {
901 'interpolation': 'linear',
902 'direction': 'inverse'}
904 # Generating the *forward* transform.
905 cs.from_reference_transforms = []
907 if 'transformLUT' in odt_values:
908 transform_LUT_file_name = os.path.basename(
909 odt_values['transformLUT'])
910 lut = os.path.join(lut_directory, transform_LUT_file_name)
911 shutil.copy(odt_values['transformLUT'], lut)
913 cs.from_reference_transforms.append(shaper_OCIO_transform)
914 cs.from_reference_transforms.append({
916 'path': transform_LUT_file_name,
917 'interpolation': 'tetrahedral',
918 'direction': 'forward'})
919 elif 'transformCTL' in odt_values:
921 shaper_to_ACES_CTL % aces_ctl_directory,
922 os.path.join(aces_ctl_directory,
925 os.path.join(aces_ctl_directory,
927 odt_values['transformCTL'])]
928 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
932 generate_3d_LUT_from_CTL(
933 os.path.join(lut_directory, lut),
938 1 / shaper_input_scale,
944 cs.from_reference_transforms.append(shaper_OCIO_transform)
945 cs.from_reference_transforms.append({
948 'interpolation': 'tetrahedral',
949 'direction': 'forward'})
951 # Generating the *inverse* transform.
952 cs.to_reference_transforms = []
954 if 'transformLUTInverse' in odt_values:
955 transform_LUT_inverse_file_name = os.path.basename(
956 odt_values['transformLUTInverse'])
957 lut = os.path.join(lut_directory, transform_LUT_inverse_file_name)
958 shutil.copy(odt_values['transformLUTInverse'], lut)
960 cs.to_reference_transforms.append({
962 'path': transform_LUT_inverse_file_name,
963 'interpolation': 'tetrahedral',
964 'direction': 'forward'})
966 shaper_inverse = shaper_OCIO_transform.copy()
967 shaper_inverse['direction'] = 'forward'
968 cs.to_reference_transforms.append(shaper_inverse)
969 elif 'transformCTLInverse' in odt_values:
970 ctls = [os.path.join(aces_ctl_directory,
972 odt_values['transformCTLInverse']),
973 os.path.join(aces_ctl_directory,
975 'InvRRT.a1.0.0.ctl'),
976 shaper_from_ACES_CTL % aces_ctl_directory]
977 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
981 generate_3d_LUT_from_CTL(
982 os.path.join(lut_directory, lut),
993 cs.to_reference_transforms.append({
996 'interpolation': 'tetrahedral',
997 'direction': 'forward'})
999 shaper_inverse = shaper_OCIO_transform.copy()
1000 shaper_inverse['direction'] = 'forward'
1001 cs.to_reference_transforms.append(shaper_inverse)
1006 # -------------------------------------------------------------------------
1008 # -------------------------------------------------------------------------
1009 def create_ODTs(aces_ctl_directory,
1016 linear_display_space,
1024 Parameter description.
1029 Return value description.
1035 # -------------------------------------------------------------------------
1036 # *RRT / ODT* Shaper Options
1037 # -------------------------------------------------------------------------
1040 # Defining the *Log 2* shaper.
1041 log2_shaper_name = shaper_name
1042 log2_shaper_name_aliases = ["crv_%s" % compact(log2_shaper_name)]
1048 log2_shaper_colorspace = create_generic_log(
1053 name=log2_shaper_name,
1054 middle_grey=log2_params['middleGrey'],
1055 min_exposure=log2_params['minExposure'],
1056 max_exposure=log2_params['maxExposure'],
1057 aliases=log2_shaper_name_aliases)
1058 colorspaces.append(log2_shaper_colorspace)
1060 shaper_input_scale_generic_log2 = 1
1062 # *Log 2* shaper name and *CTL* transforms bundled up.
1063 log2_shaper_data = [
1067 'ACESlib.OCIO_shaper_log2_to_lin_param.a1.0.0.ctl'),
1070 'ACESlib.OCIO_shaper_lin_to_log2_param.a1.0.0.ctl'),
1071 shaper_input_scale_generic_log2,
1074 shaper_data[log2_shaper_name] = log2_shaper_data
1076 # Space with a more user-friendly name. Direct copy otherwise.
1077 log2_shaper_copy_name = "Log2 Shaper"
1078 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1079 log2_shaper_copy_colorspace.description = 'The %s color space' % log2_shaper_copy_name
1080 log2_shaper_copy_colorspace.aliases = ["crv_%s" % compact(log2_shaper_copy_name)]
1081 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1082 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1083 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1084 log2_shaper_copy_colorspace.to_reference_transforms = list(
1085 log2_shaper_colorspace.to_reference_transforms)
1086 log2_shaper_copy_colorspace.from_reference_transforms = list(
1087 log2_shaper_colorspace.from_reference_transforms)
1088 colorspaces.append(log2_shaper_copy_colorspace)
1090 # Defining the *Log2 shaper that includes the AP1* primaries.
1091 log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper"
1092 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1093 log2_shaper_api1_colorspace.description = 'The %s color space' % log2_shaper_api1_name
1094 log2_shaper_api1_colorspace.aliases = [
1095 "%s_ap1" % compact(log2_shaper_copy_name)]
1096 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1097 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1098 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1099 log2_shaper_api1_colorspace.to_reference_transforms = list(
1100 log2_shaper_colorspace.to_reference_transforms)
1101 log2_shaper_api1_colorspace.from_reference_transforms = list(
1102 log2_shaper_colorspace.from_reference_transforms)
1104 # *AP1* primaries to *AP0* primaries.
1105 log2_shaper_api1_colorspace.to_reference_transforms.append({
1107 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1108 'direction': 'forward'
1110 colorspaces.append(log2_shaper_api1_colorspace)
1112 # Defining the *Log2 shaper that includes the AP1* primaries.
1113 # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1114 shaper_api1_name = "%s - AP1" % shaper_name
1115 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1116 shaper_api1_colorspace.description = 'The %s color space' % shaper_api1_name
1117 shaper_api1_colorspace.aliases = ["%s_ap1" % compact(shaper_name)]
1118 shaper_api1_colorspace.equality_group = shaper_api1_name
1119 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1120 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1121 shaper_api1_colorspace.to_reference_transforms = list(
1122 log2_shaper_api1_colorspace.to_reference_transforms)
1123 shaper_api1_colorspace.from_reference_transforms = list(
1124 log2_shaper_api1_colorspace.from_reference_transforms)
1125 colorspaces.append(shaper_api1_colorspace)
1127 # Define the base *Dolby PQ Shaper*
1129 dolbypq_shaper_name = "Dolby PQ 10000"
1130 dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"]
1132 dolbypq_shaper_colorspace = create_dolbypq(
1137 name=dolbypq_shaper_name,
1138 aliases=dolbypq_shaper_name_aliases)
1139 colorspaces.append(dolbypq_shaper_colorspace)
1141 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1142 dolbypq_shaper_data = [
1143 dolbypq_shaper_name,
1146 'ACESlib.OCIO_shaper_dolbypq_to_lin.a1.0.0.ctl'),
1149 'ACESlib.OCIO_shaper_lin_to_dolbypq.a1.0.0.ctl'),
1153 shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1155 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1157 dolbypq_scaled_shaper_name = "Dolby PQ Scaled"
1158 dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"]
1160 dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled(
1165 name=dolbypq_scaled_shaper_name,
1166 aliases=dolbypq_scaled_shaper_name_aliases)
1167 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1169 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1170 dolbypq_scaled_shaper_data = [
1171 dolbypq_scaled_shaper_name,
1174 'ACESlib.OCIO_shaper_dolbypq_to_lin_param.a1.0.0.ctl'),
1177 'ACESlib.OCIO_shaper_lin_to_dolbypq_param.a1.0.0.ctl'),
1181 shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1184 # Pick a specific shaper
1186 rrt_shaper = log2_shaper_data
1187 # rrt_shaper = dolbypq_scaled_shaper_data
1189 # *RRT + ODT* combinations.
1190 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1192 for odt in sorted_odts:
1193 (odt_name, odt_values) = odt
1195 # Generating legal range transform for *ODTs* that can generate
1196 # either *legal* or *full* output.
1197 if odt_values['transformHasFullLegalSwitch']:
1198 odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1200 odt_name_legal = odt_values['transformUserName']
1202 odt_legal = odt_values.copy()
1203 odt_legal['legalRange'] = 1
1205 odt_aliases = ["out_%s" % compact(odt_name_legal)]
1207 cs = create_ACES_RRT_plus_ODT(
1217 colorspaces.append(cs)
1219 displays[odt_name_legal] = {
1220 'Raw': linear_display_space,
1221 'Log': log_display_space,
1222 'Output Transform': cs}
1225 # Generating full range transform for *ODTs* that can generate
1226 # either *legal* or *full* output.
1227 if odt_values['transformHasFullLegalSwitch']:
1228 print('Generating full range ODT for %s' % odt_name)
1230 odt_name_full = '%s - Full' % odt_values['transformUserName']
1231 odt_full = odt_values.copy()
1232 odt_full['legalRange'] = 0
1234 odt_full_aliases = ["out_%s" % compact(odt_name_full)]
1236 cs_full = create_ACES_RRT_plus_ODT(
1246 colorspaces.append(cs_full)
1248 displays[odt_name_full] = {
1249 'Raw': linear_display_space,
1250 'Log': log_display_space,
1251 'Output Transform': cs_full}
1253 return (colorspaces, displays)
1256 def get_transform_info(ctl_transform):
1263 Parameter description.
1268 Return value description.
1271 with open(ctl_transform, 'rb') as fp:
1272 lines = fp.readlines()
1274 # Retrieving the *transform ID* and *User Name*.
1275 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1276 transform_user_name = '-'.join(
1277 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1278 transform_user_name_prefix = (
1279 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1281 # Figuring out if this transform has options for processing full and legal range
1282 transform_full_legal_switch = False
1284 if line.strip() == "input varying int legalRange = 0":
1285 # print( "%s has legal range flag" % transform_user_name)
1286 transform_full_legal_switch = True
1289 return (transform_id, transform_user_name, transform_user_name_prefix,
1290 transform_full_legal_switch)
1293 def get_ODTs_info(aces_ctl_directory):
1297 For versions after WGR9.
1302 Parameter description.
1307 Return value description.
1310 # TODO: Investigate usage of *files_walker* definition here.
1311 # Credit to *Alex Fry* for the original approach here.
1312 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1314 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1315 for fname in file_list:
1316 all_odt.append((os.path.join(dir_name, fname)))
1318 odt_CTLs = [x for x in all_odt if
1319 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1323 for odt_CTL in odt_CTLs:
1324 odt_tokens = os.path.split(odt_CTL)
1326 # Handling nested directories.
1327 odt_path_tokens = os.path.split(odt_tokens[-2])
1328 odt_dir = odt_path_tokens[-1]
1329 while odt_path_tokens[-2][-3:] != 'odt':
1330 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1331 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1333 # Building full name,
1334 transform_CTL = odt_tokens[-1]
1335 odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1337 # Finding id, user name and user name prefix.
1339 transform_user_name,
1340 transform_user_name_prefix,
1341 transform_full_legal_switch) = get_transform_info(
1342 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL))
1345 transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1346 if not os.path.exists(
1347 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1348 transform_CTL_inverse = None
1350 # Add to list of ODTs
1352 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1353 if transform_CTL_inverse is not None:
1354 odts[odt_name]['transformCTLInverse'] = os.path.join(
1355 odt_dir, transform_CTL_inverse)
1357 odts[odt_name]['transformID'] = transform_ID
1358 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1359 odts[odt_name]['transformUserName'] = transform_user_name
1361 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1363 forward_CTL = odts[odt_name]['transformCTL']
1365 print('ODT : %s' % odt_name)
1366 print('\tTransform ID : %s' % transform_ID)
1367 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1368 print('\tTransform User Name : %s' % transform_user_name)
1370 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1371 print('\tForward ctl : %s' % forward_CTL)
1372 if 'transformCTLInverse' in odts[odt_name]:
1373 inverse_CTL = odts[odt_name]['transformCTLInverse']
1374 print('\tInverse ctl : %s' % inverse_CTL)
1376 print('\tInverse ctl : %s' % 'None')
1383 def get_LMTs_info(aces_ctl_directory):
1387 For versions after WGR9.
1392 Parameter description.
1397 Return value description.
1400 # TODO: Investigate refactoring with previous definition.
1402 # Credit to Alex Fry for the original approach here
1403 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1405 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1406 for fname in file_list:
1407 all_lmt.append((os.path.join(dir_name, fname)))
1409 lmt_CTLs = [x for x in all_lmt if
1410 ('InvLMT' not in x) and ('README' not in x) and (
1411 os.path.split(x)[-1][0] != '.')]
1415 for lmt_CTL in lmt_CTLs:
1416 lmt_tokens = os.path.split(lmt_CTL)
1418 # Handlimg nested directories.
1419 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1420 lmt_dir = lmt_path_tokens[-1]
1421 while lmt_path_tokens[-2][-3:] != 'ctl':
1422 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1423 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1425 # Building full name.
1426 transform_CTL = lmt_tokens[-1]
1427 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1429 # Finding id, user name and user name prefix.
1431 transform_user_name,
1432 transform_user_name_prefix,
1433 transform_full_legal_switch) = get_transform_info(
1434 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1437 transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1438 if not os.path.exists(
1439 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1440 transform_CTL_inverse = None
1443 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1444 if transform_CTL_inverse is not None:
1445 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1446 lmt_dir, transform_CTL_inverse)
1448 lmts[lmt_name]['transformID'] = transform_ID
1449 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1450 lmts[lmt_name]['transformUserName'] = transform_user_name
1452 forward_CTL = lmts[lmt_name]['transformCTL']
1454 print('LMT : %s' % lmt_name)
1455 print('\tTransform ID : %s' % transform_ID)
1456 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1457 print('\tTransform User Name : %s' % transform_user_name)
1458 print('\t Forward ctl : %s' % forward_CTL)
1459 if 'transformCTLInverse' in lmts[lmt_name]:
1460 inverse_CTL = lmts[lmt_name]['transformCTLInverse']
1461 print('\t Inverse ctl : %s' % inverse_CTL)
1463 print('\t Inverse ctl : %s' % 'None')
1470 def create_colorspaces(aces_ctl_directory,
1479 Generates the colorspace conversions.
1484 Parameter description.
1489 Return value description.
1494 ACES = create_ACES()
1496 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1497 lut_resolution_1d, cleanup,
1498 min_value=-0.35840, max_value=1.468)
1499 colorspaces.append(ACEScc)
1501 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1502 lut_resolution_1d, cleanup)
1503 colorspaces.append(ACESproxy)
1505 ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1506 lut_resolution_1d, cleanup)
1507 colorspaces.append(ACEScg)
1509 ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1510 colorspaces.append(ADX10)
1512 ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1513 colorspaces.append(ADX16)
1515 lmts = create_LMTs(aces_ctl_directory,
1522 colorspaces.extend(lmts)
1524 odts, displays = create_ODTs(aces_ctl_directory,
1533 colorspaces.extend(odts)
1535 # Wish there was an automatic way to get this from the CTL
1536 defaultDisplay = "sRGB (D60 sim.)"
1538 roles = {'color_picking': ACEScg.name,
1539 'color_timing': ACEScc.name,
1540 'compositing_log': ACEScc.name,
1542 'default': ACES.name,
1543 'matte_paint': ACEScc.name,
1545 'scene_linear': ACEScg.name,
1546 'texture_paint': ''}
1548 return ACES, colorspaces, displays, ACEScc, roles, defaultDisplay