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 (
29 __author__ = 'ACES Developers'
30 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
32 __maintainer__ = 'ACES Developers'
33 __email__ = 'aces@oscars.org'
34 __status__ = 'Production'
36 __all__ = ['ACES_AP1_TO_AP0',
44 'create_ACES_RRT_plus_ODT',
53 # Matrix converting *ACES AP1* primaries to *ACES AP0*.
54 ACES_AP1_TO_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
55 0.0447945634, 0.8596711185, 0.0955343182,
56 -0.0055258826, 0.0040252103, 1.0015006723]
58 # Matrix converting *ACES AP0* primaries to *ACES AP1*.
59 ACES_AP0_TO_AP1 = [1.4514393161, -0.2365107469, -0.2149285693,
60 -0.0765537734, 1.1762296998, -0.0996759264,
61 0.0083161484, -0.0060324498, 0.9977163014]
63 # Matrix converting *ACES AP0* primaries to *XYZ*.
64 ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
65 0.3439664498, 0.7281660966, -0.0721325464,
66 0.0000000000, 0.0000000000, 1.0088251844]
68 # Matrix converting *ACES AP0* primaries to *XYZ*.
69 ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845,
70 -0.4959030231, 1.3733130458, 0.0982400361,
71 0.0000000000, 0.0000000000, 0.9912520182]
81 Parameter description.
86 Return value description.
89 # Defining the reference colorspace.
90 aces2065_1 = ColorSpace('ACES2065-1')
91 aces2065_1.description = (
92 'The Academy Color Encoding System reference color space')
93 aces2065_1.equality_group = ''
94 aces2065_1.aliases = ['lin_ap0', 'aces']
95 aces2065_1.family = 'ACES'
96 aces2065_1.is_data = False
97 aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2
98 aces2065_1.allocation_vars = [-8, 5, 0.00390625]
103 def create_ACEScc(aces_ctl_directory,
112 Creates the *ACEScc* colorspace.
117 Parameter description.
125 cs = ColorSpace(name)
126 cs.description = 'The %s color space' % name
127 cs.aliases = ['acescc', 'acescc_ap1']
128 cs.equality_group = ''
131 cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
132 cs.allocation_vars = [min_value, max_value]
133 cs.aces_transform_id = 'ACEScsc.ACEScc_to_ACES.a1.0.0'
135 ctls = [os.path.join(aces_ctl_directory,
137 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
138 # This transform gets back to the *AP1* primaries.
139 # Useful as the 1d LUT is only covering the transfer function.
140 # The primaries switch is covered by the matrix below:
141 os.path.join(aces_ctl_directory,
143 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
144 lut = '%s_to_linear.spi1d' % name
148 generate_1d_LUT_from_CTL(
149 os.path.join(lut_directory, lut),
162 cs.to_reference_transforms = []
163 cs.to_reference_transforms.append({
166 'interpolation': 'linear',
167 'direction': 'forward'})
169 # *AP1* primaries to *AP0* primaries
170 cs.to_reference_transforms.append({
172 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
173 'direction': 'forward'})
175 cs.from_reference_transforms = []
179 def create_ACESproxy(aces_ctl_directory,
185 Creates the *ACESproxy* colorspace.
190 Parameter description.
195 *ACESproxy* colorspace.
198 cs = ColorSpace(name)
199 cs.description = 'The %s color space' % name
200 cs.aliases = ['acesproxy', 'acesproxy_ap1']
201 cs.equality_group = ''
205 cs.aces_transform_id = 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0'
207 ctls = [os.path.join(aces_ctl_directory,
209 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
210 # This transform gets back to the *AP1* primaries.
211 # Useful as the 1d LUT is only covering the transfer function.
212 # The primaries switch is covered by the matrix below:
213 os.path.join(aces_ctl_directory,
215 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
216 lut = '%s_to_linear.spi1d' % name
220 generate_1d_LUT_from_CTL(
221 os.path.join(lut_directory, lut),
234 cs.to_reference_transforms = []
235 cs.to_reference_transforms.append({
238 'interpolation': 'linear',
239 'direction': 'forward'})
241 # *AP1* primaries to *AP0* primaries
242 cs.to_reference_transforms.append({
244 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
245 'direction': 'forward'})
247 cs.from_reference_transforms = []
251 # -------------------------------------------------------------------------
253 # -------------------------------------------------------------------------
256 Creates the *ACEScg* colorspace.
261 Parameter description.
271 cs = ColorSpace(name)
272 cs.description = 'The %s color space' % name
273 cs.aliases = ['acescg', 'lin_ap1']
274 cs.equality_group = ''
277 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
278 cs.allocation_vars = [-8, 5, 0.00390625]
280 cs.aces_transform_id = 'ACEScsc.ACEScg_to_ACES.a1.0.0'
282 cs.to_reference_transforms = []
284 # *AP1* primaries to *AP0* primaries
285 cs.to_reference_transforms.append({
287 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
288 'direction': 'forward'})
290 cs.from_reference_transforms = []
292 # *AP1* primaries to *AP0* primaries
293 cs.from_reference_transforms.append({
295 'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
296 'direction': 'forward'})
301 # -------------------------------------------------------------------------
303 # -------------------------------------------------------------------------
304 def create_ADX(lut_directory,
308 Creates the *ADX* colorspace.
313 Parameter description.
321 name = '%s%s' % (name, bit_depth)
322 cs = ColorSpace(name)
323 cs.description = '%s color space - used for film scans' % name
324 cs.aliases = ['adx%s' % str(bit_depth)]
325 cs.equality_group = ''
330 cs.aces_transform_id = 'ACEScsc.ADX10_to_ACES.a1.0.0'
332 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
333 ADX_to_CDD = [1023 / 500, 0, 0, 0,
337 offset = [-95 / 500, -95 / 500, -95 / 500, 0]
338 elif bit_depth == 16:
339 cs.aces_transform_id = 'ACEScsc.ADX16_to_ACES.a1.0.0'
341 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
342 ADX_to_CDD = [65535 / 8000, 0, 0, 0,
343 0, 65535 / 8000, 0, 0,
344 0, 0, 65535 / 8000, 0,
346 offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
348 cs.to_reference_transforms = []
350 # Converting from *ADX* to *Channel-Dependent Density*.
351 cs.to_reference_transforms.append({
353 'matrix': ADX_to_CDD,
355 'direction': 'forward'})
357 # Converting from *Channel-Dependent Density* to
358 # *Channel-Independent Density*.
359 cs.to_reference_transforms.append({
361 'matrix': [0.75573, 0.22197, 0.02230, 0,
362 0.05901, 0.96928, -0.02829, 0,
363 0.16134, 0.07406, 0.76460, 0,
365 'direction': 'forward'})
367 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
368 def create_CID_to_RLE_LUT():
370 def interpolate_1d(x, xp, fp):
371 return numpy.interp(x, xp, fp)
373 LUT_1D_XP = [-0.190000000000000,
385 LUT_1D_FP = [-6.000000000000000,
397 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
402 return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP)
403 return (100 / 55) * x - REF_PT
405 def fit(value, from_min, from_max, to_min, to_max):
406 if from_min == from_max:
407 raise ValueError('from_min == from_max')
408 return (value - from_min) / (from_max - from_min) * (
409 to_max - to_min) + to_min
411 num_samples = 2 ** 12
414 for i in xrange(num_samples):
415 x = i / (num_samples - 1)
416 x = fit(x, 0, 1, domain[0], domain[1])
417 data.append(cid_to_rle(x))
419 lut = 'ADX_CID_to_RLE.spi1d'
420 write_SPI_1d(os.path.join(lut_directory, lut),
428 # Converting *Channel Independent Density* values to
429 # *Relative Log Exposure* values.
430 lut = create_CID_to_RLE_LUT()
431 cs.to_reference_transforms.append({
434 'interpolation': 'linear',
435 'direction': 'forward'})
437 # Converting *Relative Log Exposure* values to
438 # *Relative Exposure* values.
439 cs.to_reference_transforms.append({
442 'direction': 'inverse'})
444 # Convert *Relative Exposure* values to *ACES* values.
445 cs.to_reference_transforms.append({
447 'matrix': [0.72286, 0.12630, 0.15084, 0,
448 0.11923, 0.76418, 0.11659, 0,
449 0.01427, 0.08213, 0.90359, 0,
451 'direction': 'forward'})
453 cs.from_reference_transforms = []
457 # -------------------------------------------------------------------------
458 # Generic *Log* Transform
459 # -------------------------------------------------------------------------
460 def create_generic_log(aces_ctl_directory,
473 Creates the *Generic Log* colorspace.
478 Parameter description.
483 *Generic Log* colorspace.
489 cs = ColorSpace(name)
490 cs.description = 'The %s color space' % name
492 cs.equality_group = name
493 cs.family = 'Utility'
496 ctls = [os.path.join(
499 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
500 lut = '%s_to_linear.spi1d' % name
504 generate_1d_LUT_from_CTL(
505 os.path.join(lut_directory, lut),
511 {'middleGrey': middle_grey,
512 'minExposure': min_exposure,
513 'maxExposure': max_exposure},
520 cs.to_reference_transforms = []
521 cs.to_reference_transforms.append({
524 'interpolation': 'linear',
525 'direction': 'forward'})
527 cs.from_reference_transforms = []
531 # -------------------------------------------------------------------------
532 # Base *Dolby PQ* Transform
533 # -------------------------------------------------------------------------
534 def create_Dolby_PQ(aces_ctl_directory,
546 cs = ColorSpace(name)
547 cs.description = 'The %s color space' % name
549 cs.equality_group = name
550 cs.family = 'Utility'
553 ctls = [os.path.join(
556 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
557 lut = '%s_to_linear.spi1d' % name
561 generate_1d_LUT_from_CTL(
562 os.path.join(lut_directory, lut),
574 cs.to_reference_transforms = []
575 cs.to_reference_transforms.append({
578 'interpolation': 'linear',
579 'direction': 'forward'})
581 cs.from_reference_transforms = []
585 # -------------------------------------------------------------------------
586 # *Dolby PQ* Transform - Fixed Linear Range
587 # -------------------------------------------------------------------------
588 def create_Dolby_PQ_scaled(aces_ctl_directory,
603 cs = ColorSpace(name)
604 cs.description = 'The %s color space' % name
606 cs.equality_group = name
607 cs.family = 'Utility'
610 ctls = [os.path.join(
613 'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
614 lut = '%s_to_linear.spi1d' % name
618 generate_1d_LUT_from_CTL(
619 os.path.join(lut_directory, lut),
625 {'middleGrey': middle_grey,
626 'minExposure': min_exposure,
627 'maxExposure': max_exposure},
633 cs.to_reference_transforms = []
634 cs.to_reference_transforms.append({
637 'interpolation': 'linear',
638 'direction': 'forward'})
640 cs.from_reference_transforms = []
644 # -------------------------------------------------------------------------
646 # -------------------------------------------------------------------------
647 def create_ACES_LMT(lmt_name,
652 lut_resolution_3d=64,
656 Creates the *ACES LMT* colorspace.
661 Parameter description.
666 *ACES LMT* colorspace.
672 cs = ColorSpace('%s' % lmt_name)
673 cs.description = 'The ACES Look Transform: %s' % lmt_name
675 cs.equality_group = ''
678 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
679 cs.allocation_vars = [-8, 5, 0.00390625]
680 cs.aces_transform_id = lmt_values['transformID']
682 pprint.pprint(lmt_values)
684 # Generating the *shaper* transform.
687 shaper_from_aces_ctl,
689 shaper_params) = shaper_info
691 shaper_lut = '%s_to_linear.spi1d' % shaper_name
692 shaper_lut = sanitize(shaper_lut)
694 shaper_ocio_transform = {
697 'interpolation': 'linear',
698 'direction': 'inverse'}
700 # Generating the forward transform.
701 cs.from_reference_transforms = []
703 if 'transformCTL' in lmt_values:
704 ctls = [shaper_to_aces_ctl % aces_ctl_directory,
705 os.path.join(aces_ctl_directory,
706 lmt_values['transformCTL'])]
707 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
711 generate_3d_LUT_from_CTL(
712 os.path.join(lut_directory, lut),
716 1 / shaper_input_scale,
722 cs.from_reference_transforms.append(shaper_ocio_transform)
723 cs.from_reference_transforms.append({
726 'interpolation': 'tetrahedral',
727 'direction': 'forward'})
729 # Generating the inverse transform.
730 cs.to_reference_transforms = []
732 if 'transformCTLInverse' in lmt_values:
733 ctls = [os.path.join(aces_ctl_directory,
734 lmt_values['transformCTLInverse']),
735 shaper_from_aces_ctl % aces_ctl_directory]
736 # TODO: Investigate unresolved `odt_name` reference.
737 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
741 generate_3d_LUT_from_CTL(
742 os.path.join(lut_directory, lut),
753 cs.to_reference_transforms.append({
756 'interpolation': 'tetrahedral',
757 'direction': 'forward'})
759 shaper_inverse = shaper_ocio_transform.copy()
760 shaper_inverse['direction'] = 'forward'
761 cs.to_reference_transforms.append(shaper_inverse)
766 # -------------------------------------------------------------------------
768 # -------------------------------------------------------------------------
769 def create_LMTs(aces_ctl_directory,
781 Parameter description.
786 Return value description.
791 # -------------------------------------------------------------------------
793 # -------------------------------------------------------------------------
794 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
795 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
797 # Defining the *Log 2* shaper.
798 lmt_shaper_name = 'LMT Shaper'
799 lmt_shaper_name_aliases = ['crv_lmtshaper']
805 lmt_shaper = create_generic_log(aces_ctl_directory,
807 lmt_lut_resolution_1d,
809 name=lmt_shaper_name,
810 middle_grey=lmt_params['middleGrey'],
811 min_exposure=lmt_params['minExposure'],
812 max_exposure=lmt_params['maxExposure'],
813 aliases=lmt_shaper_name_aliases)
814 colorspaces.append(lmt_shaper)
816 shaper_input_scale_generic_log2 = 1
818 # *Log 2* shaper name and *CTL* transforms bundled up.
823 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
826 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
827 shaper_input_scale_generic_log2,
830 sorted_lmts = sorted(lmt_info.iteritems(), key=lambda x: x[1])
832 for lmt in sorted_lmts:
833 lmt_name, lmt_values = lmt
834 lmt_aliases = ['look_%s' % compact(lmt_values['transformUserName'])]
835 cs = create_ACES_LMT(
836 lmt_values['transformUserName'],
841 lmt_lut_resolution_3d,
844 colorspaces.append(cs)
849 # -------------------------------------------------------------------------
850 # *ACES RRT* with supplied *ODT*.
851 # -------------------------------------------------------------------------
852 def create_ACES_RRT_plus_ODT(odt_name,
857 lut_resolution_3d=64,
866 Parameter description.
871 Return value description.
877 cs = ColorSpace('%s' % odt_name)
878 cs.description = '%s - %s Output Transform' % (
879 odt_values['transformUserNamePrefix'], odt_name)
881 cs.equality_group = ''
885 cs.aces_transform_id = odt_values['transformID']
887 pprint.pprint(odt_values)
889 # Generating the *shaper* transform.
892 shaper_from_aces_ctl,
894 shaper_params) = shaper_info
896 if 'legalRange' in odt_values:
897 shaper_params['legalRange'] = odt_values['legalRange']
899 shaper_params['legalRange'] = 0
901 shaper_lut = '%s_to_linear.spi1d' % shaper_name
902 shaper_lut = sanitize(shaper_lut)
904 shaper_ocio_transform = {
907 'interpolation': 'linear',
908 'direction': 'inverse'}
910 # Generating the *forward* transform.
911 cs.from_reference_transforms = []
913 if 'transformLUT' in odt_values:
914 transform_lut_file_name = os.path.basename(
915 odt_values['transformLUT'])
916 lut = os.path.join(lut_directory, transform_lut_file_name)
917 shutil.copy(odt_values['transformLUT'], lut)
919 cs.from_reference_transforms.append(shaper_ocio_transform)
920 cs.from_reference_transforms.append({
922 'path': transform_lut_file_name,
923 'interpolation': 'tetrahedral',
924 'direction': 'forward'})
925 elif 'transformCTL' in odt_values:
927 shaper_to_aces_ctl % aces_ctl_directory,
928 os.path.join(aces_ctl_directory,
931 os.path.join(aces_ctl_directory,
933 odt_values['transformCTL'])]
934 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
938 generate_3d_LUT_from_CTL(
939 os.path.join(lut_directory, lut),
943 1 / shaper_input_scale,
949 cs.from_reference_transforms.append(shaper_ocio_transform)
950 cs.from_reference_transforms.append({
953 'interpolation': 'tetrahedral',
954 'direction': 'forward'})
956 # Generating the *inverse* transform.
957 cs.to_reference_transforms = []
959 if 'transformLUTInverse' in odt_values:
960 transform_lut_inverse_file_name = os.path.basename(
961 odt_values['transformLUTInverse'])
962 lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
963 shutil.copy(odt_values['transformLUTInverse'], lut)
965 cs.to_reference_transforms.append({
967 'path': transform_lut_inverse_file_name,
968 'interpolation': 'tetrahedral',
969 'direction': 'forward'})
971 shaper_inverse = shaper_ocio_transform.copy()
972 shaper_inverse['direction'] = 'forward'
973 cs.to_reference_transforms.append(shaper_inverse)
974 elif 'transformCTLInverse' in odt_values:
975 ctls = [os.path.join(aces_ctl_directory,
977 odt_values['transformCTLInverse']),
978 os.path.join(aces_ctl_directory,
980 'InvRRT.a1.0.0.ctl'),
981 shaper_from_aces_ctl % aces_ctl_directory]
982 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
986 generate_3d_LUT_from_CTL(
987 os.path.join(lut_directory, lut),
997 cs.to_reference_transforms.append({
1000 'interpolation': 'tetrahedral',
1001 'direction': 'forward'})
1003 shaper_inverse = shaper_ocio_transform.copy()
1004 shaper_inverse['direction'] = 'forward'
1005 cs.to_reference_transforms.append(shaper_inverse)
1010 # -------------------------------------------------------------------------
1012 # -------------------------------------------------------------------------
1013 def create_ODTs(aces_ctl_directory,
1020 linear_display_space,
1028 Parameter description.
1033 Return value description.
1039 # -------------------------------------------------------------------------
1040 # *RRT / ODT* Shaper Options
1041 # -------------------------------------------------------------------------
1044 # Defining the *Log 2* shaper.
1045 log2_shaper_name = shaper_name
1046 log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1052 log2_shaper_colorspace = create_generic_log(
1057 name=log2_shaper_name,
1058 middle_grey=log2_params['middleGrey'],
1059 min_exposure=log2_params['minExposure'],
1060 max_exposure=log2_params['maxExposure'],
1061 aliases=log2_shaper_name_aliases)
1062 colorspaces.append(log2_shaper_colorspace)
1064 shaper_input_scale_generic_log2 = 1
1066 # *Log 2* shaper name and *CTL* transforms bundled up.
1067 log2_shaper_data = [
1071 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1074 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1075 shaper_input_scale_generic_log2,
1078 shaper_data[log2_shaper_name] = log2_shaper_data
1080 # Space with a more user-friendly name. Direct copy otherwise.
1081 log2_shaper_copy_name = 'Log2 Shaper'
1082 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1083 log2_shaper_copy_colorspace.description = (
1084 'The %s color space' % log2_shaper_copy_name)
1085 log2_shaper_copy_colorspace.aliases = [
1086 'crv_%s' % compact(log2_shaper_copy_name)]
1087 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1088 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1089 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1090 log2_shaper_copy_colorspace.to_reference_transforms = list(
1091 log2_shaper_colorspace.to_reference_transforms)
1092 log2_shaper_copy_colorspace.from_reference_transforms = list(
1093 log2_shaper_colorspace.from_reference_transforms)
1094 colorspaces.append(log2_shaper_copy_colorspace)
1096 # Defining the *Log2 shaper that includes the AP1* primaries.
1097 log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1098 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1099 log2_shaper_api1_colorspace.description = (
1100 'The %s color space' % log2_shaper_api1_name)
1101 log2_shaper_api1_colorspace.aliases = [
1102 '%s_ap1' % compact(log2_shaper_copy_name)]
1103 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1104 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1105 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1106 log2_shaper_api1_colorspace.to_reference_transforms = list(
1107 log2_shaper_colorspace.to_reference_transforms)
1108 log2_shaper_api1_colorspace.from_reference_transforms = list(
1109 log2_shaper_colorspace.from_reference_transforms)
1111 # *AP1* primaries to *AP0* primaries
1112 log2_shaper_api1_colorspace.to_reference_transforms.append({
1114 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1115 'direction': 'forward'
1117 colorspaces.append(log2_shaper_api1_colorspace)
1119 # Defining the *Log2* shaper that includes the *AP1* primaries.
1120 # Named with `shaper_name` variable and needed for some *LUT* baking steps.
1121 shaper_api1_name = '%s - AP1' % shaper_name
1122 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1123 shaper_api1_colorspace.description = (
1124 'The %s color space' % shaper_api1_name)
1125 shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1126 shaper_api1_colorspace.equality_group = shaper_api1_name
1127 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1128 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1129 shaper_api1_colorspace.to_reference_transforms = list(
1130 log2_shaper_api1_colorspace.to_reference_transforms)
1131 shaper_api1_colorspace.from_reference_transforms = list(
1132 log2_shaper_api1_colorspace.from_reference_transforms)
1133 colorspaces.append(shaper_api1_colorspace)
1135 # Define the base *Dolby PQ Shaper*
1137 dolby_pq_shaper_name = 'Dolby PQ 10000'
1138 dolbypq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1140 dolbypq_shaper_colorspace = create_Dolby_PQ(
1145 name=dolby_pq_shaper_name,
1146 aliases=dolbypq_shaper_name_aliases)
1147 colorspaces.append(dolbypq_shaper_colorspace)
1149 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1150 dolbypq_shaper_data = [
1151 dolby_pq_shaper_name,
1154 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1157 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1161 shaper_data[dolby_pq_shaper_name] = dolbypq_shaper_data
1163 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1164 dolby_pq_scaled_shaper_name = 'Dolby PQ Scaled'
1165 dolbypq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1167 dolbypq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1172 name=dolby_pq_scaled_shaper_name,
1173 aliases=dolbypq_scaled_shaper_name_aliases)
1174 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1176 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1177 dolbypq_scaled_shaper_data = [
1178 dolby_pq_scaled_shaper_name,
1181 'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1184 'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1188 shaper_data[dolby_pq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1190 rrt_shaper = log2_shaper_data
1191 # rrt_shaper = dolbypq_scaled_shaper_data
1193 # *RRT + ODT* combinations.
1194 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1196 for odt in sorted_odts:
1197 (odt_name, odt_values) = odt
1199 # Defining full range transform for *ODTs* that can only generate
1200 # either *legal* or *full* output.
1202 # Uncomment these lines and the lower section and
1203 # flip the `legalRange` value to 1 to restore the old behavior,
1204 # where both *legal* or *full* range *LUTs* were generated.
1205 if odt_values['transformHasFullLegalSwitch']:
1206 # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1207 odt_legal['legalRange'] = 0
1209 # odt_name_legal = odt_values['transformUserName']
1211 odt_name_legal = odt_values['transformUserName']
1213 odt_legal = odt_values.copy()
1215 odt_aliases = ['out_%s' % compact(odt_name_legal)]
1217 cs = create_ACES_RRT_plus_ODT(
1226 colorspaces.append(cs)
1228 displays[odt_name_legal] = {
1229 'Raw': linear_display_space,
1230 'Log': log_display_space,
1231 'Output Transform': cs}
1234 # Generating full range transform for *ODTs* that can generate
1235 # either *legal* or *full* output.
1236 if odt_values['transformHasFullLegalSwitch']:
1237 print('Generating full range ODT for %s' % odt_name)
1239 odt_name_full = '%s - Full' % odt_values['transformUserName']
1240 odt_full = odt_values.copy()
1241 odt_full['legalRange'] = 0
1243 odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1245 cs_full = create_ACES_RRT_plus_ODT(
1255 colorspaces.append(cs_full)
1257 displays[odt_name_full] = {
1258 'Raw': linear_display_space,
1259 'Log': log_display_space,
1260 'Output Transform': cs_full}
1263 return colorspaces, displays
1266 def get_transform_info(ctl_transform):
1273 Parameter description.
1278 Return value description.
1281 with open(ctl_transform, 'rb') as fp:
1282 lines = fp.readlines()
1284 # Retrieving the *transform ID* and *User Name*.
1285 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1286 transform_user_name = '-'.join(
1287 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1288 transform_user_name_prefix = (
1289 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1291 # Figuring out if this transform has options for processing *full* and
1293 transform_full_legal_switch = False
1295 if line.strip() == 'input varying int legalRange = 0':
1296 # print( '%s has legal range flag' % transform_user_name)
1297 transform_full_legal_switch = True
1300 return (transform_id, transform_user_name, transform_user_name_prefix,
1301 transform_full_legal_switch)
1304 def get_ODTs_info(aces_ctl_directory):
1308 For versions after WGR9.
1313 Parameter description.
1318 Return value description.
1321 # TODO: Investigate usage of *files_walker* definition here.
1322 # Credit to *Alex Fry* for the original approach here.
1323 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1325 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1326 for fname in file_list:
1327 all_odt.append((os.path.join(dir_name, fname)))
1329 odt_ctls = [x for x in all_odt if
1330 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1334 for odt_ctl in odt_ctls:
1335 odt_tokens = os.path.split(odt_ctl)
1337 # Handling nested directories.
1338 odt_path_tokens = os.path.split(odt_tokens[-2])
1339 odt_dir = odt_path_tokens[-1]
1340 while odt_path_tokens[-2][-3:] != 'odt':
1341 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1342 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1344 # Building full name.
1345 transform_ctl = odt_tokens[-1]
1346 odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1348 # Finding id, user name and user name prefix.
1350 transform_user_name,
1351 transform_user_name_prefix,
1352 transform_full_legal_switch) = get_transform_info(
1353 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1356 transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1357 if not os.path.exists(
1358 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1359 transform_ctl_inverse = None
1361 # Adding to list of *ODTs*.
1363 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1364 if transform_ctl_inverse is not None:
1365 odts[odt_name]['transformCTLInverse'] = os.path.join(
1366 odt_dir, transform_ctl_inverse)
1368 odts[odt_name]['transformID'] = transform_id
1369 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1370 odts[odt_name]['transformUserName'] = transform_user_name
1372 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1374 forward_ctl = odts[odt_name]['transformCTL']
1376 print('ODT : %s' % odt_name)
1377 print('\tTransform ID : %s' % transform_id)
1378 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1379 print('\tTransform User Name : %s' % transform_user_name)
1381 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1382 print('\tForward ctl : %s' % forward_ctl)
1383 if 'transformCTLInverse' in odts[odt_name]:
1384 inverse_ctl = odts[odt_name]['transformCTLInverse']
1385 print('\tInverse ctl : %s' % inverse_ctl)
1387 print('\tInverse ctl : %s' % 'None')
1394 def get_LMTs_info(aces_ctl_directory):
1398 For versions after WGR9.
1403 Parameter description.
1408 Return value description.
1411 # TODO: Investigate refactoring with previous definition.
1413 # Credit to Alex Fry for the original approach here
1414 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1416 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1417 for fname in file_list:
1418 all_lmt.append((os.path.join(dir_name, fname)))
1420 lmt_ctls = [x for x in all_lmt if
1421 ('InvLMT' not in x) and ('README' not in x) and (
1422 os.path.split(x)[-1][0] != '.')]
1426 for lmt_ctl in lmt_ctls:
1427 lmt_tokens = os.path.split(lmt_ctl)
1429 # Handlimg nested directories.
1430 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1431 lmt_dir = lmt_path_tokens[-1]
1432 while lmt_path_tokens[-2][-3:] != 'ctl':
1433 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1434 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1436 # Building full name.
1437 transform_CTL = lmt_tokens[-1]
1438 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1440 # Finding id, user name and user name prefix.
1442 transform_user_name,
1443 transform_user_name_prefix,
1444 transform_full_legal_switch) = get_transform_info(
1445 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1448 transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1449 if not os.path.exists(
1450 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1451 transform_ctl_inverse = None
1454 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1455 if transform_ctl_inverse is not None:
1456 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1457 lmt_dir, transform_ctl_inverse)
1459 lmts[lmt_name]['transformID'] = transform_id
1460 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1461 lmts[lmt_name]['transformUserName'] = transform_user_name
1463 forward_ctl = lmts[lmt_name]['transformCTL']
1465 print('LMT : %s' % lmt_name)
1466 print('\tTransform ID : %s' % transform_id)
1467 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1468 print('\tTransform User Name : %s' % transform_user_name)
1469 print('\t Forward ctl : %s' % forward_ctl)
1470 if 'transformCTLInverse' in lmts[lmt_name]:
1471 inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1472 print('\t Inverse ctl : %s' % inverse_ctl)
1474 print('\t Inverse ctl : %s' % 'None')
1481 def create_colorspaces(aces_ctl_directory,
1490 Generates the colorspace conversions.
1495 Parameter description.
1500 Return value description.
1505 ACES = create_ACES()
1507 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1508 lut_resolution_1d, cleanup,
1509 min_value=-0.35840, max_value=1.468)
1510 colorspaces.append(ACEScc)
1512 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1513 lut_resolution_1d, cleanup)
1514 colorspaces.append(ACESproxy)
1516 ACEScg = create_ACEScg()
1517 colorspaces.append(ACEScg)
1519 ADX10 = create_ADX(lut_directory, bit_depth=10)
1520 colorspaces.append(ADX10)
1522 ADX16 = create_ADX(lut_directory, bit_depth=16)
1523 colorspaces.append(ADX16)
1525 lmts = create_LMTs(aces_ctl_directory,
1531 colorspaces.extend(lmts)
1533 odts, displays = create_ODTs(aces_ctl_directory,
1542 colorspaces.extend(odts)
1544 # TODO: Investigate if there is a way to retrieve the value from *CTL*.
1545 default_display = 'sRGB (D60 sim.)'
1547 roles = {'color_picking': ACEScg.name,
1548 'color_timing': ACEScc.name,
1549 'compositing_log': ACEScc.name,
1551 'default': ACES.name,
1552 'matte_paint': ACEScc.name,
1554 'scene_linear': ACEScg.name,
1555 'texture_paint': ''}
1557 return ACES, colorspaces, displays, ACEScc, roles, default_display