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 # -------------------------------------------------------------------------
254 def create_ACEScg(aces_ctl_directory,
260 Creates the *ACEScg* colorspace.
265 Parameter description.
273 cs = ColorSpace(name)
274 cs.description = 'The %s color space' % name
275 cs.aliases = ['acescg', 'lin_ap1']
276 cs.equality_group = ''
279 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
280 cs.allocation_vars = [-8, 5, 0.00390625]
282 cs.aces_transform_id = 'ACEScsc.ACEScg_to_ACES.a1.0.0'
284 cs.to_reference_transforms = []
286 # *AP1* primaries to *AP0* primaries.
287 cs.to_reference_transforms.append({
289 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
290 'direction': 'forward'})
292 cs.from_reference_transforms = []
294 # *AP1* primaries to *AP0* primaries.
295 cs.from_reference_transforms.append({
297 'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
298 'direction': 'forward'})
303 # -------------------------------------------------------------------------
305 # -------------------------------------------------------------------------
306 def create_ADX(lut_directory,
311 Creates the *ADX* colorspace.
316 Parameter description.
324 name = '%s%s' % (name, bit_depth)
325 cs = ColorSpace(name)
326 cs.description = '%s color space - used for film scans' % name
327 cs.aliases = ['adx%s' % str(bit_depth)]
328 cs.equality_group = ''
333 cs.aces_transform_id = 'ACEScsc.ADX10_to_ACES.a1.0.0'
335 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
336 ADX_to_CDD = [1023 / 500, 0, 0, 0,
340 offset = [-95 / 500, -95 / 500, -95 / 500, 0]
341 elif bit_depth == 16:
342 cs.aces_transform_id = 'ACEScsc.ADX16_to_ACES.a1.0.0'
344 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
345 ADX_to_CDD = [65535 / 8000, 0, 0, 0,
346 0, 65535 / 8000, 0, 0,
347 0, 0, 65535 / 8000, 0,
349 offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
351 cs.to_reference_transforms = []
353 # Converting from *ADX* to *Channel-Dependent Density*.
354 cs.to_reference_transforms.append({
356 'matrix': ADX_to_CDD,
358 'direction': 'forward'})
360 # Convert from Channel-Dependent Density to Channel-Independent Density
361 cs.to_reference_transforms.append({
363 'matrix': [0.75573, 0.22197, 0.02230, 0,
364 0.05901, 0.96928, -0.02829, 0,
365 0.16134, 0.07406, 0.76460, 0,
367 'direction': 'forward'})
369 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
370 def create_CID_to_RLE_LUT():
372 def interpolate_1d(x, xp, fp):
373 return numpy.interp(x, xp, fp)
375 LUT_1D_XP = [-0.190000000000000,
387 LUT_1D_FP = [-6.000000000000000,
399 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
404 return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP)
405 return (100 / 55) * x - REF_PT
407 def fit(value, from_min, from_max, to_min, to_max):
408 if from_min == from_max:
409 raise ValueError('from_min == from_max')
410 return (value - from_min) / (from_max - from_min) * (
411 to_max - to_min) + to_min
413 num_samples = 2 ** 12
416 for i in xrange(num_samples):
417 x = i / (num_samples - 1)
418 x = fit(x, 0, 1, domain[0], domain[1])
419 data.append(cid_to_rle(x))
421 lut = 'ADX_CID_to_RLE.spi1d'
422 write_SPI_1d(os.path.join(lut_directory, lut),
430 # Converting *Channel Independent Density* values to
431 # *Relative Log Exposure* values.
432 lut = create_CID_to_RLE_LUT()
433 cs.to_reference_transforms.append({
436 'interpolation': 'linear',
437 'direction': 'forward'})
439 # Converting *Relative Log Exposure* values to
440 # *Relative Exposure* values.
441 cs.to_reference_transforms.append({
444 'direction': 'inverse'})
446 # Convert *Relative Exposure* values to *ACES* values.
447 cs.to_reference_transforms.append({
449 'matrix': [0.72286, 0.12630, 0.15084, 0,
450 0.11923, 0.76418, 0.11659, 0,
451 0.01427, 0.08213, 0.90359, 0,
453 'direction': 'forward'})
455 cs.from_reference_transforms = []
459 # -------------------------------------------------------------------------
460 # *Generic Log Transform*
461 # -------------------------------------------------------------------------
462 def create_generic_log(aces_ctl_directory,
475 Creates the *Generic Log* colorspace.
480 Parameter description.
485 *Generic Log* colorspace.
491 cs = ColorSpace(name)
492 cs.description = 'The %s color space' % name
494 cs.equality_group = name
495 cs.family = 'Utility'
498 ctls = [os.path.join(
501 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
502 lut = '%s_to_linear.spi1d' % name
506 generate_1d_LUT_from_CTL(
507 os.path.join(lut_directory, lut),
513 {'middleGrey': middle_grey,
514 'minExposure': min_exposure,
515 'maxExposure': max_exposure},
522 cs.to_reference_transforms = []
523 cs.to_reference_transforms.append({
526 'interpolation': 'linear',
527 'direction': 'forward'})
529 cs.from_reference_transforms = []
533 # -------------------------------------------------------------------------
534 # *base Dolby PQ Transform*
535 # -------------------------------------------------------------------------
536 def create_Dolby_PQ(aces_ctl_directory,
548 cs = ColorSpace(name)
549 cs.description = 'The %s color space' % name
551 cs.equality_group = name
552 cs.family = 'Utility'
555 ctls = [os.path.join(
558 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
559 lut = '%s_to_linear.spi1d' % name
563 generate_1d_LUT_from_CTL(
564 os.path.join(lut_directory, lut),
576 cs.to_reference_transforms = []
577 cs.to_reference_transforms.append({
580 'interpolation': 'linear',
581 'direction': 'forward'})
583 cs.from_reference_transforms = []
587 # -------------------------------------------------------------------------
588 # *Dolby PQ Transform that considers a fixed linear range*
589 # -------------------------------------------------------------------------
590 def create_Dolby_PQ_scaled(aces_ctl_directory,
605 cs = ColorSpace(name)
606 cs.description = 'The %s color space' % name
608 cs.equality_group = name
609 cs.family = 'Utility'
612 ctls = [os.path.join(
615 'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
616 lut = '%s_to_linear.spi1d' % name
620 generate_1d_LUT_from_CTL(
621 os.path.join(lut_directory, lut),
627 {'middleGrey': middle_grey,
628 'minExposure': min_exposure,
629 'maxExposure': max_exposure},
635 cs.to_reference_transforms = []
636 cs.to_reference_transforms.append({
639 'interpolation': 'linear',
640 'direction': 'forward'})
642 cs.from_reference_transforms = []
646 # -------------------------------------------------------------------------
648 # -------------------------------------------------------------------------
649 def create_ACES_LMT(lmt_name,
654 lut_resolution_1d=1024,
655 lut_resolution_3d=64,
659 Creates the *ACES LMT* colorspace.
664 Parameter description.
669 *ACES LMT* colorspace.
675 cs = ColorSpace('%s' % lmt_name)
676 cs.description = 'The ACES Look Transform: %s' % lmt_name
678 cs.equality_group = ''
681 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
682 cs.allocation_vars = [-8, 5, 0.00390625]
683 cs.aces_transform_id = lmt_values['transformID']
685 pprint.pprint(lmt_values)
687 # Generating the *shaper* transform.
690 shaper_from_aces_ctl,
692 shaper_params) = shaper_info
694 # Add the shaper transform
695 shaper_lut = '%s_to_linear.spi1d' % shaper_name
696 shaper_lut = sanitize(shaper_lut)
698 shaper_ocio_transform = {
701 'interpolation': 'linear',
702 'direction': 'inverse'}
704 # Generating the forward transform.
705 cs.from_reference_transforms = []
707 if 'transformCTL' in lmt_values:
708 ctls = [shaper_to_aces_ctl % aces_ctl_directory,
709 os.path.join(aces_ctl_directory,
710 lmt_values['transformCTL'])]
711 lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
715 generate_3d_LUT_from_CTL(
716 os.path.join(lut_directory, lut),
720 1 / shaper_input_scale,
726 cs.from_reference_transforms.append(shaper_ocio_transform)
727 cs.from_reference_transforms.append({
730 'interpolation': 'tetrahedral',
731 'direction': 'forward'})
733 # Generating the inverse transform.
734 cs.to_reference_transforms = []
736 if 'transformCTLInverse' in lmt_values:
737 ctls = [os.path.join(aces_ctl_directory,
738 lmt_values['transformCTLInverse']),
739 shaper_from_aces_ctl % aces_ctl_directory]
740 # TODO: Investigate unresolved `odt_name` reference.
741 lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
745 generate_3d_LUT_from_CTL(
746 os.path.join(lut_directory, lut),
757 cs.to_reference_transforms.append({
760 'interpolation': 'tetrahedral',
761 'direction': 'forward'})
763 shaper_inverse = shaper_ocio_transform.copy()
764 shaper_inverse['direction'] = 'forward'
765 cs.to_reference_transforms.append(shaper_inverse)
770 # -------------------------------------------------------------------------
772 # -------------------------------------------------------------------------
773 def create_LMTs(aces_ctl_directory,
786 Parameter description.
791 Return value description.
796 # -------------------------------------------------------------------------
798 # -------------------------------------------------------------------------
799 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
800 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
802 # Defining the *Log 2* shaper.
803 lmt_shaper_name = 'LMT Shaper'
804 lmt_shaper_name_aliases = ['crv_lmtshaper']
810 lmt_shaper = create_generic_log(aces_ctl_directory,
812 lmt_lut_resolution_1d,
814 name=lmt_shaper_name,
815 middle_grey=lmt_params['middleGrey'],
816 min_exposure=lmt_params['minExposure'],
817 max_exposure=lmt_params['maxExposure'],
818 aliases=lmt_shaper_name_aliases)
819 colorspaces.append(lmt_shaper)
821 shaper_input_scale_generic_log2 = 1
823 # *Log 2* shaper name and *CTL* transforms bundled up.
828 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
831 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
832 shaper_input_scale_generic_log2,
835 sorted_lmts = sorted(lmt_info.iteritems(), key=lambda x: x[1])
837 for lmt in sorted_lmts:
838 lmt_name, lmt_values = lmt
839 lmt_aliases = ['look_%s' % compact(lmt_values['transformUserName'])]
840 cs = create_ACES_LMT(
841 lmt_values['transformUserName'],
846 lmt_lut_resolution_1d,
847 lmt_lut_resolution_3d,
850 colorspaces.append(cs)
855 # -------------------------------------------------------------------------
856 # *ACES RRT* with supplied *ODT*.
857 # -------------------------------------------------------------------------
858 def create_ACES_RRT_plus_ODT(odt_name,
863 lut_resolution_1d=1024,
864 lut_resolution_3d=64,
873 Parameter description.
878 Return value description.
884 cs = ColorSpace('%s' % odt_name)
885 cs.description = '%s - %s Output Transform' % (
886 odt_values['transformUserNamePrefix'], odt_name)
888 cs.equality_group = ''
892 cs.aces_transform_id = odt_values['transformID']
894 pprint.pprint(odt_values)
896 # Generating the *shaper* transform.
899 shaper_from_aces_ctl,
901 shaper_params) = shaper_info
903 if 'legalRange' in odt_values:
904 shaper_params['legalRange'] = odt_values['legalRange']
906 shaper_params['legalRange'] = 0
908 # Add the shaper transform
909 shaper_lut = '%s_to_linear.spi1d' % shaper_name
910 shaper_lut = sanitize(shaper_lut)
912 shaper_ocio_transform = {
915 'interpolation': 'linear',
916 'direction': 'inverse'}
918 # Generating the *forward* transform.
919 cs.from_reference_transforms = []
921 if 'transformLUT' in odt_values:
922 transform_lut_file_name = os.path.basename(
923 odt_values['transformLUT'])
924 lut = os.path.join(lut_directory, transform_lut_file_name)
925 shutil.copy(odt_values['transformLUT'], lut)
927 cs.from_reference_transforms.append(shaper_ocio_transform)
928 cs.from_reference_transforms.append({
930 'path': transform_lut_file_name,
931 'interpolation': 'tetrahedral',
932 'direction': 'forward'})
933 elif 'transformCTL' in odt_values:
935 shaper_to_aces_ctl % aces_ctl_directory,
936 os.path.join(aces_ctl_directory,
939 os.path.join(aces_ctl_directory,
941 odt_values['transformCTL'])]
942 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
946 generate_3d_LUT_from_CTL(
947 os.path.join(lut_directory, lut),
952 1 / shaper_input_scale,
958 cs.from_reference_transforms.append(shaper_ocio_transform)
959 cs.from_reference_transforms.append({
962 'interpolation': 'tetrahedral',
963 'direction': 'forward'})
965 # Generating the *inverse* transform.
966 cs.to_reference_transforms = []
968 if 'transformLUTInverse' in odt_values:
969 transform_lut_inverse_file_name = os.path.basename(
970 odt_values['transformLUTInverse'])
971 lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
972 shutil.copy(odt_values['transformLUTInverse'], lut)
974 cs.to_reference_transforms.append({
976 'path': transform_lut_inverse_file_name,
977 'interpolation': 'tetrahedral',
978 'direction': 'forward'})
980 shaper_inverse = shaper_ocio_transform.copy()
981 shaper_inverse['direction'] = 'forward'
982 cs.to_reference_transforms.append(shaper_inverse)
983 elif 'transformCTLInverse' in odt_values:
984 ctls = [os.path.join(aces_ctl_directory,
986 odt_values['transformCTLInverse']),
987 os.path.join(aces_ctl_directory,
989 'InvRRT.a1.0.0.ctl'),
990 shaper_from_aces_ctl % aces_ctl_directory]
991 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
995 generate_3d_LUT_from_CTL(
996 os.path.join(lut_directory, lut),
1007 cs.to_reference_transforms.append({
1010 'interpolation': 'tetrahedral',
1011 'direction': 'forward'})
1013 shaper_inverse = shaper_ocio_transform.copy()
1014 shaper_inverse['direction'] = 'forward'
1015 cs.to_reference_transforms.append(shaper_inverse)
1020 # -------------------------------------------------------------------------
1022 # -------------------------------------------------------------------------
1023 def create_ODTs(aces_ctl_directory,
1030 linear_display_space,
1038 Parameter description.
1043 Return value description.
1049 # -------------------------------------------------------------------------
1050 # *RRT / ODT* Shaper Options
1051 # -------------------------------------------------------------------------
1054 # Defining the *Log 2* shaper.
1055 log2_shaper_name = shaper_name
1056 log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1062 log2_shaper_colorspace = create_generic_log(
1067 name=log2_shaper_name,
1068 middle_grey=log2_params['middleGrey'],
1069 min_exposure=log2_params['minExposure'],
1070 max_exposure=log2_params['maxExposure'],
1071 aliases=log2_shaper_name_aliases)
1072 colorspaces.append(log2_shaper_colorspace)
1074 shaper_input_scale_generic_log2 = 1
1076 # *Log 2* shaper name and *CTL* transforms bundled up.
1077 log2_shaper_data = [
1081 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1084 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1085 shaper_input_scale_generic_log2,
1088 shaper_data[log2_shaper_name] = log2_shaper_data
1090 # Space with a more user-friendly name. Direct copy otherwise.
1091 log2_shaper_copy_name = 'Log2 Shaper'
1092 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1093 log2_shaper_copy_colorspace.description = (
1094 'The %s color space' % log2_shaper_copy_name)
1095 log2_shaper_copy_colorspace.aliases = [
1096 'crv_%s' % compact(log2_shaper_copy_name)]
1097 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1098 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1099 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1100 log2_shaper_copy_colorspace.to_reference_transforms = list(
1101 log2_shaper_colorspace.to_reference_transforms)
1102 log2_shaper_copy_colorspace.from_reference_transforms = list(
1103 log2_shaper_colorspace.from_reference_transforms)
1104 colorspaces.append(log2_shaper_copy_colorspace)
1106 # Defining the *Log2 shaper that includes the AP1* primaries.
1107 log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1108 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1109 log2_shaper_api1_colorspace.description = (
1110 'The %s color space' % log2_shaper_api1_name)
1111 log2_shaper_api1_colorspace.aliases = [
1112 '%s_ap1' % compact(log2_shaper_copy_name)]
1113 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1114 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1115 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1116 log2_shaper_api1_colorspace.to_reference_transforms = list(
1117 log2_shaper_colorspace.to_reference_transforms)
1118 log2_shaper_api1_colorspace.from_reference_transforms = list(
1119 log2_shaper_colorspace.from_reference_transforms)
1121 # *AP1* primaries to *AP0* primaries.
1122 log2_shaper_api1_colorspace.to_reference_transforms.append({
1124 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1125 'direction': 'forward'
1127 colorspaces.append(log2_shaper_api1_colorspace)
1129 # Defining the *Log2 shaper that includes the AP1* primaries.
1130 # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1131 shaper_api1_name = '%s - AP1' % shaper_name
1132 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1133 shaper_api1_colorspace.description = (
1134 'The %s color space' % shaper_api1_name)
1135 shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1136 shaper_api1_colorspace.equality_group = shaper_api1_name
1137 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1138 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1139 shaper_api1_colorspace.to_reference_transforms = list(
1140 log2_shaper_api1_colorspace.to_reference_transforms)
1141 shaper_api1_colorspace.from_reference_transforms = list(
1142 log2_shaper_api1_colorspace.from_reference_transforms)
1143 colorspaces.append(shaper_api1_colorspace)
1145 # Define the base *Dolby PQ Shaper*
1147 dolbypq_shaper_name = 'Dolby PQ 10000'
1148 dolbypq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1150 dolbypq_shaper_colorspace = create_Dolby_PQ(
1155 name=dolbypq_shaper_name,
1156 aliases=dolbypq_shaper_name_aliases)
1157 colorspaces.append(dolbypq_shaper_colorspace)
1159 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1160 dolbypq_shaper_data = [
1161 dolbypq_shaper_name,
1164 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1167 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1171 shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1173 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1175 dolbypq_scaled_shaper_name = 'Dolby PQ Scaled'
1176 dolbypq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1178 dolbypq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1183 name=dolbypq_scaled_shaper_name,
1184 aliases=dolbypq_scaled_shaper_name_aliases)
1185 colorspaces.append(dolbypq_scaled_shaper_colorspace)
1187 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1188 dolbypq_scaled_shaper_data = [
1189 dolbypq_scaled_shaper_name,
1192 'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1195 'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1199 shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1202 # Pick a specific shaper
1204 rrt_shaper = log2_shaper_data
1205 # rrt_shaper = dolbypq_scaled_shaper_data
1207 # *RRT + ODT* combinations.
1208 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1210 for odt in sorted_odts:
1211 (odt_name, odt_values) = odt
1213 # Generating only full range transform for *ODTs* that can generate
1214 # either *legal* or *full* output.
1216 # Uncomment these lines and the lower section and
1217 # flip the 'legalRange' value to 1 to recover the old behavior,
1218 # where both legal and full range LUTs were generated.
1219 if odt_values['transformHasFullLegalSwitch']:
1220 # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1221 odt_legal['legalRange'] = 0
1223 # odt_name_legal = odt_values['transformUserName']
1225 odt_name_legal = odt_values['transformUserName']
1227 odt_legal = odt_values.copy()
1229 odt_aliases = ['out_%s' % compact(odt_name_legal)]
1231 cs = create_ACES_RRT_plus_ODT(
1241 colorspaces.append(cs)
1243 displays[odt_name_legal] = {
1244 'Raw': linear_display_space,
1245 'Log': log_display_space,
1246 'Output Transform': cs}
1249 # Generating full range transform for *ODTs* that can generate
1250 # either *legal* or *full* output.
1251 if odt_values['transformHasFullLegalSwitch']:
1252 print('Generating full range ODT for %s' % odt_name)
1254 odt_name_full = '%s - Full' % odt_values['transformUserName']
1255 odt_full = odt_values.copy()
1256 odt_full['legalRange'] = 0
1258 odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1260 cs_full = create_ACES_RRT_plus_ODT(
1270 colorspaces.append(cs_full)
1272 displays[odt_name_full] = {
1273 'Raw': linear_display_space,
1274 'Log': log_display_space,
1275 'Output Transform': cs_full}
1278 return colorspaces, displays
1281 def get_transform_info(ctl_transform):
1288 Parameter description.
1293 Return value description.
1296 with open(ctl_transform, 'rb') as fp:
1297 lines = fp.readlines()
1299 # Retrieving the *transform ID* and *User Name*.
1300 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1301 transform_user_name = '-'.join(
1302 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1303 transform_user_name_prefix = (
1304 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1306 # Figuring out if this transform has options
1307 # for processing full and legal range.
1308 transform_full_legal_switch = False
1310 if line.strip() == 'input varying int legalRange = 0':
1311 # print( '%s has legal range flag' % transform_user_name)
1312 transform_full_legal_switch = True
1315 return (transform_id, transform_user_name, transform_user_name_prefix,
1316 transform_full_legal_switch)
1319 def get_ODTs_info(aces_ctl_directory):
1323 For versions after WGR9.
1328 Parameter description.
1333 Return value description.
1336 # TODO: Investigate usage of *files_walker* definition here.
1337 # Credit to *Alex Fry* for the original approach here.
1338 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1340 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1341 for fname in file_list:
1342 all_odt.append((os.path.join(dir_name, fname)))
1344 odt_ctls = [x for x in all_odt if
1345 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1349 for odt_ctl in odt_ctls:
1350 odt_tokens = os.path.split(odt_ctl)
1352 # Handling nested directories.
1353 odt_path_tokens = os.path.split(odt_tokens[-2])
1354 odt_dir = odt_path_tokens[-1]
1355 while odt_path_tokens[-2][-3:] != 'odt':
1356 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1357 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1359 # Building full name,
1360 transform_ctl = odt_tokens[-1]
1361 odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1363 # Finding id, user name and user name prefix.
1365 transform_user_name,
1366 transform_user_name_prefix,
1367 transform_full_legal_switch) = get_transform_info(
1368 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1371 transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1372 if not os.path.exists(
1373 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1374 transform_ctl_inverse = None
1376 # Add to list of ODTs
1378 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1379 if transform_ctl_inverse is not None:
1380 odts[odt_name]['transformCTLInverse'] = os.path.join(
1381 odt_dir, transform_ctl_inverse)
1383 odts[odt_name]['transformID'] = transform_id
1384 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1385 odts[odt_name]['transformUserName'] = transform_user_name
1387 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1389 forward_ctl = odts[odt_name]['transformCTL']
1391 print('ODT : %s' % odt_name)
1392 print('\tTransform ID : %s' % transform_id)
1393 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1394 print('\tTransform User Name : %s' % transform_user_name)
1396 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1397 print('\tForward ctl : %s' % forward_ctl)
1398 if 'transformCTLInverse' in odts[odt_name]:
1399 inverse_ctl = odts[odt_name]['transformCTLInverse']
1400 print('\tInverse ctl : %s' % inverse_ctl)
1402 print('\tInverse ctl : %s' % 'None')
1409 def get_LMTs_info(aces_ctl_directory):
1413 For versions after WGR9.
1418 Parameter description.
1423 Return value description.
1426 # TODO: Investigate refactoring with previous definition.
1428 # Credit to Alex Fry for the original approach here
1429 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1431 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1432 for fname in file_list:
1433 all_lmt.append((os.path.join(dir_name, fname)))
1435 lmt_ctls = [x for x in all_lmt if
1436 ('InvLMT' not in x) and ('README' not in x) and (
1437 os.path.split(x)[-1][0] != '.')]
1441 for lmt_ctl in lmt_ctls:
1442 lmt_tokens = os.path.split(lmt_ctl)
1444 # Handlimg nested directories.
1445 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1446 lmt_dir = lmt_path_tokens[-1]
1447 while lmt_path_tokens[-2][-3:] != 'ctl':
1448 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1449 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1451 # Building full name.
1452 transform_CTL = lmt_tokens[-1]
1453 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1455 # Finding id, user name and user name prefix.
1457 transform_user_name,
1458 transform_user_name_prefix,
1459 transform_full_legal_switch) = get_transform_info(
1460 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1463 transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1464 if not os.path.exists(
1465 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1466 transform_ctl_inverse = None
1469 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1470 if transform_ctl_inverse is not None:
1471 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1472 lmt_dir, transform_ctl_inverse)
1474 lmts[lmt_name]['transformID'] = transform_id
1475 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1476 lmts[lmt_name]['transformUserName'] = transform_user_name
1478 forward_ctl = lmts[lmt_name]['transformCTL']
1480 print('LMT : %s' % lmt_name)
1481 print('\tTransform ID : %s' % transform_id)
1482 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1483 print('\tTransform User Name : %s' % transform_user_name)
1484 print('\t Forward ctl : %s' % forward_ctl)
1485 if 'transformCTLInverse' in lmts[lmt_name]:
1486 inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1487 print('\t Inverse ctl : %s' % inverse_ctl)
1489 print('\t Inverse ctl : %s' % 'None')
1496 def create_colorspaces(aces_ctl_directory,
1505 Generates the colorspace conversions.
1510 Parameter description.
1515 Return value description.
1520 ACES = create_ACES()
1522 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1523 lut_resolution_1d, cleanup,
1524 min_value=-0.35840, max_value=1.468)
1525 colorspaces.append(ACEScc)
1527 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1528 lut_resolution_1d, cleanup)
1529 colorspaces.append(ACESproxy)
1531 ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1532 lut_resolution_1d, cleanup)
1533 colorspaces.append(ACEScg)
1535 ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1536 colorspaces.append(ADX10)
1538 ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1539 colorspaces.append(ADX16)
1541 lmts = create_LMTs(aces_ctl_directory,
1548 colorspaces.extend(lmts)
1550 odts, displays = create_ODTs(aces_ctl_directory,
1559 colorspaces.extend(odts)
1561 # Wish there was an automatic way to get this from the CTL
1562 default_display = 'sRGB (D60 sim.)'
1564 roles = {'color_picking': ACEScg.name,
1565 'color_timing': ACEScc.name,
1566 'compositing_log': ACEScc.name,
1568 'default': ACES.name,
1569 'matte_paint': ACEScc.name,
1571 'scene_linear': ACEScg.name,
1572 'texture_paint': ''}
1574 return ACES, colorspaces, displays, ACEScc, roles, default_display