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 # Convert from Channel-Dependent Density to Channel-Independent Density
358 cs.to_reference_transforms.append({
360 'matrix': [0.75573, 0.22197, 0.02230, 0,
361 0.05901, 0.96928, -0.02829, 0,
362 0.16134, 0.07406, 0.76460, 0,
364 'direction': 'forward'})
366 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
367 def create_CID_to_RLE_LUT():
369 def interpolate_1d(x, xp, fp):
370 return numpy.interp(x, xp, fp)
372 LUT_1D_XP = [-0.190000000000000,
384 LUT_1D_FP = [-6.000000000000000,
396 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
401 return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP)
402 return (100 / 55) * x - REF_PT
404 def fit(value, from_min, from_max, to_min, to_max):
405 if from_min == from_max:
406 raise ValueError('from_min == from_max')
407 return (value - from_min) / (from_max - from_min) * (
408 to_max - to_min) + to_min
410 num_samples = 2 ** 12
413 for i in xrange(num_samples):
414 x = i / (num_samples - 1)
415 x = fit(x, 0, 1, domain[0], domain[1])
416 data.append(cid_to_rle(x))
418 lut = 'ADX_CID_to_RLE.spi1d'
419 write_SPI_1d(os.path.join(lut_directory, lut),
427 # Converting *Channel Independent Density* values to
428 # *Relative Log Exposure* values.
429 lut = create_CID_to_RLE_LUT()
430 cs.to_reference_transforms.append({
433 'interpolation': 'linear',
434 'direction': 'forward'})
436 # Converting *Relative Log Exposure* values to
437 # *Relative Exposure* values.
438 cs.to_reference_transforms.append({
441 'direction': 'inverse'})
443 # Convert *Relative Exposure* values to *ACES* values.
444 cs.to_reference_transforms.append({
446 'matrix': [0.72286, 0.12630, 0.15084, 0,
447 0.11923, 0.76418, 0.11659, 0,
448 0.01427, 0.08213, 0.90359, 0,
450 'direction': 'forward'})
452 cs.from_reference_transforms = []
456 # -------------------------------------------------------------------------
457 # *Generic Log Transform*
458 # -------------------------------------------------------------------------
459 def create_generic_log(aces_ctl_directory,
472 Creates the *Generic Log* colorspace.
477 Parameter description.
482 *Generic Log* colorspace.
488 cs = ColorSpace(name)
489 cs.description = 'The %s color space' % name
491 cs.equality_group = name
492 cs.family = 'Utility'
495 ctls = [os.path.join(
498 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
499 lut = '%s_to_linear.spi1d' % name
503 generate_1d_LUT_from_CTL(
504 os.path.join(lut_directory, lut),
510 {'middleGrey': middle_grey,
511 'minExposure': min_exposure,
512 'maxExposure': max_exposure},
519 cs.to_reference_transforms = []
520 cs.to_reference_transforms.append({
523 'interpolation': 'linear',
524 'direction': 'forward'})
526 cs.from_reference_transforms = []
530 # -------------------------------------------------------------------------
531 # *base Dolby PQ Transform*
532 # -------------------------------------------------------------------------
533 def create_Dolby_PQ(aces_ctl_directory,
545 cs = ColorSpace(name)
546 cs.description = 'The %s color space' % name
548 cs.equality_group = name
549 cs.family = 'Utility'
552 ctls = [os.path.join(
555 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
556 lut = '%s_to_linear.spi1d' % name
560 generate_1d_LUT_from_CTL(
561 os.path.join(lut_directory, lut),
573 cs.to_reference_transforms = []
574 cs.to_reference_transforms.append({
577 'interpolation': 'linear',
578 'direction': 'forward'})
580 cs.from_reference_transforms = []
584 # -------------------------------------------------------------------------
585 # *Dolby PQ Transform that considers a fixed linear range*
586 # -------------------------------------------------------------------------
587 def create_Dolby_PQ_scaled(aces_ctl_directory,
602 cs = ColorSpace(name)
603 cs.description = 'The %s color space' % name
605 cs.equality_group = name
606 cs.family = 'Utility'
609 ctls = [os.path.join(
612 'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
613 lut = '%s_to_linear.spi1d' % name
617 generate_1d_LUT_from_CTL(
618 os.path.join(lut_directory, lut),
624 {'middleGrey': middle_grey,
625 'minExposure': min_exposure,
626 'maxExposure': max_exposure},
632 cs.to_reference_transforms = []
633 cs.to_reference_transforms.append({
636 'interpolation': 'linear',
637 'direction': 'forward'})
639 cs.from_reference_transforms = []
643 # -------------------------------------------------------------------------
645 # -------------------------------------------------------------------------
646 def create_ACES_LMT(lmt_name,
651 lut_resolution_3d=64,
655 Creates the *ACES LMT* colorspace.
660 Parameter description.
665 *ACES LMT* colorspace.
671 cs = ColorSpace('%s' % lmt_name)
672 cs.description = 'The ACES Look Transform: %s' % lmt_name
674 cs.equality_group = ''
677 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
678 cs.allocation_vars = [-8, 5, 0.00390625]
679 cs.aces_transform_id = lmt_values['transformID']
681 pprint.pprint(lmt_values)
683 # Generating the *shaper* transform.
686 shaper_from_aces_ctl,
688 shaper_params) = shaper_info
690 # Add the shaper transform
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 # Add the shaper transform
902 shaper_lut = '%s_to_linear.spi1d' % shaper_name
903 shaper_lut = sanitize(shaper_lut)
905 shaper_ocio_transform = {
908 'interpolation': 'linear',
909 'direction': 'inverse'}
911 # Generating the *forward* transform.
912 cs.from_reference_transforms = []
914 if 'transformLUT' in odt_values:
915 transform_lut_file_name = os.path.basename(
916 odt_values['transformLUT'])
917 lut = os.path.join(lut_directory, transform_lut_file_name)
918 shutil.copy(odt_values['transformLUT'], lut)
920 cs.from_reference_transforms.append(shaper_ocio_transform)
921 cs.from_reference_transforms.append({
923 'path': transform_lut_file_name,
924 'interpolation': 'tetrahedral',
925 'direction': 'forward'})
926 elif 'transformCTL' in odt_values:
928 shaper_to_aces_ctl % aces_ctl_directory,
929 os.path.join(aces_ctl_directory,
932 os.path.join(aces_ctl_directory,
934 odt_values['transformCTL'])]
935 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
939 generate_3d_LUT_from_CTL(
940 os.path.join(lut_directory, lut),
945 1 / shaper_input_scale,
951 cs.from_reference_transforms.append(shaper_ocio_transform)
952 cs.from_reference_transforms.append({
955 'interpolation': 'tetrahedral',
956 'direction': 'forward'})
958 # Generating the *inverse* transform.
959 cs.to_reference_transforms = []
961 if 'transformLUTInverse' in odt_values:
962 transform_lut_inverse_file_name = os.path.basename(
963 odt_values['transformLUTInverse'])
964 lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
965 shutil.copy(odt_values['transformLUTInverse'], lut)
967 cs.to_reference_transforms.append({
969 'path': transform_lut_inverse_file_name,
970 'interpolation': 'tetrahedral',
971 'direction': 'forward'})
973 shaper_inverse = shaper_ocio_transform.copy()
974 shaper_inverse['direction'] = 'forward'
975 cs.to_reference_transforms.append(shaper_inverse)
976 elif 'transformCTLInverse' in odt_values:
977 ctls = [os.path.join(aces_ctl_directory,
979 odt_values['transformCTLInverse']),
980 os.path.join(aces_ctl_directory,
982 'InvRRT.a1.0.0.ctl'),
983 shaper_from_aces_ctl % aces_ctl_directory]
984 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
988 generate_3d_LUT_from_CTL(
989 os.path.join(lut_directory, lut),
1000 cs.to_reference_transforms.append({
1003 'interpolation': 'tetrahedral',
1004 'direction': 'forward'})
1006 shaper_inverse = shaper_ocio_transform.copy()
1007 shaper_inverse['direction'] = 'forward'
1008 cs.to_reference_transforms.append(shaper_inverse)
1013 # -------------------------------------------------------------------------
1015 # -------------------------------------------------------------------------
1016 def create_ODTs(aces_ctl_directory,
1023 linear_display_space,
1031 Parameter description.
1036 Return value description.
1042 # -------------------------------------------------------------------------
1043 # *RRT / ODT* Shaper Options
1044 # -------------------------------------------------------------------------
1047 # Defining the *Log 2* shaper.
1048 log2_shaper_name = shaper_name
1049 log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1055 log2_shaper_colorspace = create_generic_log(
1060 name=log2_shaper_name,
1061 middle_grey=log2_params['middleGrey'],
1062 min_exposure=log2_params['minExposure'],
1063 max_exposure=log2_params['maxExposure'],
1064 aliases=log2_shaper_name_aliases)
1065 colorspaces.append(log2_shaper_colorspace)
1067 shaper_input_scale_generic_log2 = 1
1069 # *Log 2* shaper name and *CTL* transforms bundled up.
1070 log2_shaper_data = [
1074 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1077 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1078 shaper_input_scale_generic_log2,
1081 shaper_data[log2_shaper_name] = log2_shaper_data
1083 # Space with a more user-friendly name. Direct copy otherwise.
1084 log2_shaper_copy_name = 'Log2 Shaper'
1085 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1086 log2_shaper_copy_colorspace.description = (
1087 'The %s color space' % log2_shaper_copy_name)
1088 log2_shaper_copy_colorspace.aliases = [
1089 'crv_%s' % compact(log2_shaper_copy_name)]
1090 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1091 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1092 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1093 log2_shaper_copy_colorspace.to_reference_transforms = list(
1094 log2_shaper_colorspace.to_reference_transforms)
1095 log2_shaper_copy_colorspace.from_reference_transforms = list(
1096 log2_shaper_colorspace.from_reference_transforms)
1097 colorspaces.append(log2_shaper_copy_colorspace)
1099 # Defining the *Log2 shaper that includes the AP1* primaries.
1100 log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1101 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1102 log2_shaper_api1_colorspace.description = (
1103 'The %s color space' % log2_shaper_api1_name)
1104 log2_shaper_api1_colorspace.aliases = [
1105 '%s_ap1' % compact(log2_shaper_copy_name)]
1106 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1107 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1108 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1109 log2_shaper_api1_colorspace.to_reference_transforms = list(
1110 log2_shaper_colorspace.to_reference_transforms)
1111 log2_shaper_api1_colorspace.from_reference_transforms = list(
1112 log2_shaper_colorspace.from_reference_transforms)
1114 # *AP1* primaries to *AP0* primaries.
1115 log2_shaper_api1_colorspace.to_reference_transforms.append({
1117 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1118 'direction': 'forward'
1120 colorspaces.append(log2_shaper_api1_colorspace)
1122 # Defining the *Log2 shaper that includes the AP1* primaries.
1123 # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1124 shaper_api1_name = '%s - AP1' % shaper_name
1125 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1126 shaper_api1_colorspace.description = (
1127 'The %s color space' % shaper_api1_name)
1128 shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1129 shaper_api1_colorspace.equality_group = shaper_api1_name
1130 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1131 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1132 shaper_api1_colorspace.to_reference_transforms = list(
1133 log2_shaper_api1_colorspace.to_reference_transforms)
1134 shaper_api1_colorspace.from_reference_transforms = list(
1135 log2_shaper_api1_colorspace.from_reference_transforms)
1136 colorspaces.append(shaper_api1_colorspace)
1138 # Define the base *Dolby PQ Shaper*
1140 dolbypq_shaper_name = 'Dolby PQ 10000'
1141 dolbypq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1143 dolbypq_shaper_colorspace = create_Dolby_PQ(
1148 name=dolbypq_shaper_name,
1149 aliases=dolbypq_shaper_name_aliases)
1150 colorspaces.append(dolbypq_shaper_colorspace)
1152 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1153 dolbypq_shaper_data = [
1154 dolbypq_shaper_name,
1157 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1160 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1164 shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1166 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1168 dolbypq_scaled_shaper_name = 'Dolby PQ Scaled'
1169 dolbypq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1171 dolbypq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1176 name=dolbypq_scaled_shaper_name,
1177 aliases=dolbypq_scaled_shaper_name_aliases)
1178 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1180 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1181 dolbypq_scaled_shaper_data = [
1182 dolbypq_scaled_shaper_name,
1185 'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1188 'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1192 shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1195 # Pick a specific shaper
1197 rrt_shaper = log2_shaper_data
1198 # rrt_shaper = dolbypq_scaled_shaper_data
1200 # *RRT + ODT* combinations.
1201 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1203 for odt in sorted_odts:
1204 (odt_name, odt_values) = odt
1206 # Generating only full range transform for *ODTs* that can generate
1207 # either *legal* or *full* output.
1209 # Uncomment these lines and the lower section and
1210 # flip the 'legalRange' value to 1 to recover the old behavior,
1211 # where both legal and full range LUTs were generated.
1212 if odt_values['transformHasFullLegalSwitch']:
1213 # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1214 odt_legal['legalRange'] = 0
1216 # odt_name_legal = odt_values['transformUserName']
1218 odt_name_legal = odt_values['transformUserName']
1220 odt_legal = odt_values.copy()
1222 odt_aliases = ['out_%s' % compact(odt_name_legal)]
1224 cs = create_ACES_RRT_plus_ODT(
1233 colorspaces.append(cs)
1235 displays[odt_name_legal] = {
1236 'Raw': linear_display_space,
1237 'Log': log_display_space,
1238 'Output Transform': cs}
1241 # Generating full range transform for *ODTs* that can generate
1242 # either *legal* or *full* output.
1243 if odt_values['transformHasFullLegalSwitch']:
1244 print('Generating full range ODT for %s' % odt_name)
1246 odt_name_full = '%s - Full' % odt_values['transformUserName']
1247 odt_full = odt_values.copy()
1248 odt_full['legalRange'] = 0
1250 odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1252 cs_full = create_ACES_RRT_plus_ODT(
1262 colorspaces.append(cs_full)
1264 displays[odt_name_full] = {
1265 'Raw': linear_display_space,
1266 'Log': log_display_space,
1267 'Output Transform': cs_full}
1270 return colorspaces, displays
1273 def get_transform_info(ctl_transform):
1280 Parameter description.
1285 Return value description.
1288 with open(ctl_transform, 'rb') as fp:
1289 lines = fp.readlines()
1291 # Retrieving the *transform ID* and *User Name*.
1292 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1293 transform_user_name = '-'.join(
1294 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1295 transform_user_name_prefix = (
1296 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1298 # Figuring out if this transform has options
1299 # for processing full and legal range.
1300 transform_full_legal_switch = False
1302 if line.strip() == 'input varying int legalRange = 0':
1303 # print( '%s has legal range flag' % transform_user_name)
1304 transform_full_legal_switch = True
1307 return (transform_id, transform_user_name, transform_user_name_prefix,
1308 transform_full_legal_switch)
1311 def get_ODTs_info(aces_ctl_directory):
1315 For versions after WGR9.
1320 Parameter description.
1325 Return value description.
1328 # TODO: Investigate usage of *files_walker* definition here.
1329 # Credit to *Alex Fry* for the original approach here.
1330 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1332 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1333 for fname in file_list:
1334 all_odt.append((os.path.join(dir_name, fname)))
1336 odt_ctls = [x for x in all_odt if
1337 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1341 for odt_ctl in odt_ctls:
1342 odt_tokens = os.path.split(odt_ctl)
1344 # Handling nested directories.
1345 odt_path_tokens = os.path.split(odt_tokens[-2])
1346 odt_dir = odt_path_tokens[-1]
1347 while odt_path_tokens[-2][-3:] != 'odt':
1348 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1349 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1351 # Building full name,
1352 transform_ctl = odt_tokens[-1]
1353 odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1355 # Finding id, user name and user name prefix.
1357 transform_user_name,
1358 transform_user_name_prefix,
1359 transform_full_legal_switch) = get_transform_info(
1360 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1363 transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1364 if not os.path.exists(
1365 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1366 transform_ctl_inverse = None
1368 # Add to list of ODTs
1370 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1371 if transform_ctl_inverse is not None:
1372 odts[odt_name]['transformCTLInverse'] = os.path.join(
1373 odt_dir, transform_ctl_inverse)
1375 odts[odt_name]['transformID'] = transform_id
1376 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1377 odts[odt_name]['transformUserName'] = transform_user_name
1379 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1381 forward_ctl = odts[odt_name]['transformCTL']
1383 print('ODT : %s' % odt_name)
1384 print('\tTransform ID : %s' % transform_id)
1385 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1386 print('\tTransform User Name : %s' % transform_user_name)
1388 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1389 print('\tForward ctl : %s' % forward_ctl)
1390 if 'transformCTLInverse' in odts[odt_name]:
1391 inverse_ctl = odts[odt_name]['transformCTLInverse']
1392 print('\tInverse ctl : %s' % inverse_ctl)
1394 print('\tInverse ctl : %s' % 'None')
1401 def get_LMTs_info(aces_ctl_directory):
1405 For versions after WGR9.
1410 Parameter description.
1415 Return value description.
1418 # TODO: Investigate refactoring with previous definition.
1420 # Credit to Alex Fry for the original approach here
1421 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1423 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1424 for fname in file_list:
1425 all_lmt.append((os.path.join(dir_name, fname)))
1427 lmt_ctls = [x for x in all_lmt if
1428 ('InvLMT' not in x) and ('README' not in x) and (
1429 os.path.split(x)[-1][0] != '.')]
1433 for lmt_ctl in lmt_ctls:
1434 lmt_tokens = os.path.split(lmt_ctl)
1436 # Handlimg nested directories.
1437 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1438 lmt_dir = lmt_path_tokens[-1]
1439 while lmt_path_tokens[-2][-3:] != 'ctl':
1440 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1441 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1443 # Building full name.
1444 transform_CTL = lmt_tokens[-1]
1445 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1447 # Finding id, user name and user name prefix.
1449 transform_user_name,
1450 transform_user_name_prefix,
1451 transform_full_legal_switch) = get_transform_info(
1452 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1455 transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1456 if not os.path.exists(
1457 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1458 transform_ctl_inverse = None
1461 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1462 if transform_ctl_inverse is not None:
1463 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1464 lmt_dir, transform_ctl_inverse)
1466 lmts[lmt_name]['transformID'] = transform_id
1467 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1468 lmts[lmt_name]['transformUserName'] = transform_user_name
1470 forward_ctl = lmts[lmt_name]['transformCTL']
1472 print('LMT : %s' % lmt_name)
1473 print('\tTransform ID : %s' % transform_id)
1474 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1475 print('\tTransform User Name : %s' % transform_user_name)
1476 print('\t Forward ctl : %s' % forward_ctl)
1477 if 'transformCTLInverse' in lmts[lmt_name]:
1478 inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1479 print('\t Inverse ctl : %s' % inverse_ctl)
1481 print('\t Inverse ctl : %s' % 'None')
1488 def create_colorspaces(aces_ctl_directory,
1497 Generates the colorspace conversions.
1502 Parameter description.
1507 Return value description.
1512 ACES = create_ACES()
1514 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1515 lut_resolution_1d, cleanup,
1516 min_value=-0.35840, max_value=1.468)
1517 colorspaces.append(ACEScc)
1519 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1520 lut_resolution_1d, cleanup)
1521 colorspaces.append(ACESproxy)
1523 ACEScg = create_ACEScg()
1524 colorspaces.append(ACEScg)
1526 ADX10 = create_ADX(lut_directory, bit_depth=10)
1527 colorspaces.append(ADX10)
1529 ADX16 = create_ADX(lut_directory, bit_depth=16)
1530 colorspaces.append(ADX16)
1532 lmts = create_LMTs(aces_ctl_directory,
1538 colorspaces.extend(lmts)
1540 odts, displays = create_ODTs(aces_ctl_directory,
1549 colorspaces.extend(odts)
1551 # Wish there was an automatic way to get this from the CTL
1552 default_display = 'sRGB (D60 sim.)'
1554 roles = {'color_picking': ACEScg.name,
1555 'color_timing': ACEScc.name,
1556 'compositing_log': ACEScc.name,
1558 'default': ACES.name,
1559 'matte_paint': ACEScc.name,
1561 'scene_linear': ACEScg.name,
1562 'texture_paint': ''}
1564 return ACES, colorspaces, displays, ACEScc, roles, default_display