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',
47 'create_Dolby_PQ_scaled',
50 'create_ACES_RRT_plus_ODT',
57 # Matrix converting *ACES AP1* primaries to *ACES AP0*.
58 ACES_AP1_TO_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
59 0.0447945634, 0.8596711185, 0.0955343182,
60 -0.0055258826, 0.0040252103, 1.0015006723]
62 # Matrix converting *ACES AP0* primaries to *ACES AP1*.
63 ACES_AP0_TO_AP1 = [1.4514393161, -0.2365107469, -0.2149285693,
64 -0.0765537734, 1.1762296998, -0.0996759264,
65 0.0083161484, -0.0060324498, 0.9977163014]
67 # Matrix converting *ACES AP0* primaries to *XYZ*.
68 ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
69 0.3439664498, 0.7281660966, -0.0721325464,
70 0.0000000000, 0.0000000000, 1.0088251844]
72 # Matrix converting *ACES AP0* primaries to *XYZ*.
73 ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845,
74 -0.4959030231, 1.3733130458, 0.0982400361,
75 0.0000000000, 0.0000000000, 0.9912520182]
85 Parameter description.
90 Return value description.
93 # Defining the reference colorspace.
94 aces2065_1 = ColorSpace('ACES2065-1')
95 aces2065_1.description = (
96 'The Academy Color Encoding System reference color space')
97 aces2065_1.equality_group = ''
98 aces2065_1.aliases = ['lin_ap0', 'aces']
99 aces2065_1.family = 'ACES'
100 aces2065_1.is_data = False
101 aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2
102 aces2065_1.allocation_vars = [-8, 5, 0.00390625]
107 def create_ACEScc(aces_ctl_directory,
116 Creates the *ACEScc* colorspace.
121 Parameter description.
129 cs = ColorSpace(name)
130 cs.description = 'The %s color space' % name
131 cs.aliases = ['acescc', 'acescc_ap1']
132 cs.equality_group = ''
135 cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
136 cs.allocation_vars = [min_value, max_value]
137 cs.aces_transform_id = 'ACEScsc.ACEScc_to_ACES.a1.0.0'
139 ctls = [os.path.join(aces_ctl_directory,
141 'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
142 # This transform gets back to the *AP1* primaries.
143 # Useful as the 1d LUT is only covering the transfer function.
144 # The primaries switch is covered by the matrix below:
145 os.path.join(aces_ctl_directory,
147 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
148 lut = '%s_to_linear.spi1d' % name
152 generate_1d_LUT_from_CTL(
153 os.path.join(lut_directory, lut),
166 cs.to_reference_transforms = []
167 cs.to_reference_transforms.append({
170 'interpolation': 'linear',
171 'direction': 'forward'})
173 # *AP1* primaries to *AP0* primaries
174 cs.to_reference_transforms.append({
176 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
177 'direction': 'forward'})
179 cs.from_reference_transforms = []
183 def create_ACESproxy(aces_ctl_directory,
189 Creates the *ACESproxy* colorspace.
194 Parameter description.
199 *ACESproxy* colorspace.
202 cs = ColorSpace(name)
203 cs.description = 'The %s color space' % name
204 cs.aliases = ['acesproxy', 'acesproxy_ap1']
205 cs.equality_group = ''
209 cs.aces_transform_id = 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0'
211 ctls = [os.path.join(aces_ctl_directory,
213 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
214 # This transform gets back to the *AP1* primaries.
215 # Useful as the 1d LUT is only covering the transfer function.
216 # The primaries switch is covered by the matrix below:
217 os.path.join(aces_ctl_directory,
219 'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
220 lut = '%s_to_linear.spi1d' % name
224 generate_1d_LUT_from_CTL(
225 os.path.join(lut_directory, lut),
238 cs.to_reference_transforms = []
239 cs.to_reference_transforms.append({
242 'interpolation': 'linear',
243 'direction': 'forward'})
245 # *AP1* primaries to *AP0* primaries
246 cs.to_reference_transforms.append({
248 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
249 'direction': 'forward'})
251 cs.from_reference_transforms = []
255 # -------------------------------------------------------------------------
257 # -------------------------------------------------------------------------
260 Creates the *ACEScg* colorspace.
265 Parameter description.
275 cs = ColorSpace(name)
276 cs.description = 'The %s color space' % name
277 cs.aliases = ['acescg', 'lin_ap1']
278 cs.equality_group = ''
281 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
282 cs.allocation_vars = [-8, 5, 0.00390625]
284 cs.aces_transform_id = 'ACEScsc.ACEScg_to_ACES.a1.0.0'
286 cs.to_reference_transforms = []
288 # *AP1* primaries to *AP0* primaries
289 cs.to_reference_transforms.append({
291 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
292 'direction': 'forward'})
294 cs.from_reference_transforms = []
296 # *AP1* primaries to *AP0* primaries
297 cs.from_reference_transforms.append({
299 'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
300 'direction': 'forward'})
305 # -------------------------------------------------------------------------
307 # -------------------------------------------------------------------------
308 def create_ADX(lut_directory,
312 Creates the *ADX* colorspace.
317 Parameter description.
325 name = '%s%s' % (name, bit_depth)
326 cs = ColorSpace(name)
327 cs.description = '%s color space - used for film scans' % name
328 cs.aliases = ['adx%s' % str(bit_depth)]
329 cs.equality_group = ''
334 cs.aces_transform_id = 'ACEScsc.ADX10_to_ACES.a1.0.0'
336 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
337 ADX_to_CDD = [1023 / 500, 0, 0, 0,
341 offset = [-95 / 500, -95 / 500, -95 / 500, 0]
342 elif bit_depth == 16:
343 cs.aces_transform_id = 'ACEScsc.ADX16_to_ACES.a1.0.0'
345 cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
346 ADX_to_CDD = [65535 / 8000, 0, 0, 0,
347 0, 65535 / 8000, 0, 0,
348 0, 0, 65535 / 8000, 0,
350 offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
352 cs.to_reference_transforms = []
354 # Converting from *ADX* to *Channel-Dependent Density*.
355 cs.to_reference_transforms.append({
357 'matrix': ADX_to_CDD,
359 'direction': 'forward'})
361 # Converting from *Channel-Dependent Density* to
362 # *Channel-Independent Density*.
363 cs.to_reference_transforms.append({
365 'matrix': [0.75573, 0.22197, 0.02230, 0,
366 0.05901, 0.96928, -0.02829, 0,
367 0.16134, 0.07406, 0.76460, 0,
369 'direction': 'forward'})
371 # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
372 def create_CID_to_RLE_LUT():
374 def interpolate_1d(x, xp, fp):
375 return numpy.interp(x, xp, fp)
377 LUT_1D_XP = [-0.190000000000000,
389 LUT_1D_FP = [-6.000000000000000,
401 REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
406 return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP)
407 return (100 / 55) * x - REF_PT
409 def fit(value, from_min, from_max, to_min, to_max):
410 if from_min == from_max:
411 raise ValueError('from_min == from_max')
412 return (value - from_min) / (from_max - from_min) * (
413 to_max - to_min) + to_min
415 num_samples = 2 ** 12
418 for i in xrange(num_samples):
419 x = i / (num_samples - 1)
420 x = fit(x, 0, 1, domain[0], domain[1])
421 data.append(cid_to_rle(x))
423 lut = 'ADX_CID_to_RLE.spi1d'
424 write_SPI_1d(os.path.join(lut_directory, lut),
432 # Converting *Channel Independent Density* values to
433 # *Relative Log Exposure* values.
434 lut = create_CID_to_RLE_LUT()
435 cs.to_reference_transforms.append({
438 'interpolation': 'linear',
439 'direction': 'forward'})
441 # Converting *Relative Log Exposure* values to
442 # *Relative Exposure* values.
443 cs.to_reference_transforms.append({
446 'direction': 'inverse'})
448 # Convert *Relative Exposure* values to *ACES* values.
449 cs.to_reference_transforms.append({
451 'matrix': [0.72286, 0.12630, 0.15084, 0,
452 0.11923, 0.76418, 0.11659, 0,
453 0.01427, 0.08213, 0.90359, 0,
455 'direction': 'forward'})
457 cs.from_reference_transforms = []
461 # -------------------------------------------------------------------------
462 # Generic *Log* Transform
463 # -------------------------------------------------------------------------
464 def create_generic_log(aces_ctl_directory,
477 Creates the *Generic Log* colorspace.
482 Parameter description.
487 *Generic Log* colorspace.
493 cs = ColorSpace(name)
494 cs.description = 'The %s color space' % name
496 cs.equality_group = name
497 cs.family = 'Utility'
500 ctls = [os.path.join(
503 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
504 lut = '%s_to_linear.spi1d' % name
508 generate_1d_LUT_from_CTL(
509 os.path.join(lut_directory, lut),
515 {'middleGrey': middle_grey,
516 'minExposure': min_exposure,
517 'maxExposure': max_exposure},
524 cs.to_reference_transforms = []
525 cs.to_reference_transforms.append({
528 'interpolation': 'linear',
529 'direction': 'forward'})
531 cs.from_reference_transforms = []
535 # -------------------------------------------------------------------------
536 # Base *Dolby PQ* Transform
537 # -------------------------------------------------------------------------
538 def create_Dolby_PQ(aces_ctl_directory,
550 cs = ColorSpace(name)
551 cs.description = 'The %s color space' % name
553 cs.equality_group = name
554 cs.family = 'Utility'
557 ctls = [os.path.join(
560 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
561 lut = '%s_to_linear.spi1d' % name
565 generate_1d_LUT_from_CTL(
566 os.path.join(lut_directory, lut),
578 cs.to_reference_transforms = []
579 cs.to_reference_transforms.append({
582 'interpolation': 'linear',
583 'direction': 'forward'})
585 cs.from_reference_transforms = []
589 # -------------------------------------------------------------------------
590 # *Dolby PQ* Transform - Fixed Linear Range
591 # -------------------------------------------------------------------------
592 def create_Dolby_PQ_scaled(aces_ctl_directory,
607 cs = ColorSpace(name)
608 cs.description = 'The %s color space' % name
610 cs.equality_group = name
611 cs.family = 'Utility'
614 ctls = [os.path.join(
617 'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
618 lut = '%s_to_linear.spi1d' % name
622 generate_1d_LUT_from_CTL(
623 os.path.join(lut_directory, lut),
629 {'middleGrey': middle_grey,
630 'minExposure': min_exposure,
631 'maxExposure': max_exposure},
637 cs.to_reference_transforms = []
638 cs.to_reference_transforms.append({
641 'interpolation': 'linear',
642 'direction': 'forward'})
644 cs.from_reference_transforms = []
648 # -------------------------------------------------------------------------
650 # -------------------------------------------------------------------------
651 def create_ACES_LMT(lmt_name,
656 lut_resolution_3d=64,
660 Creates the *ACES LMT* colorspace.
665 Parameter description.
670 *ACES LMT* colorspace.
676 cs = ColorSpace('%s' % lmt_name)
677 cs.description = 'The ACES Look Transform: %s' % lmt_name
679 cs.equality_group = ''
682 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
683 cs.allocation_vars = [-8, 5, 0.00390625]
684 cs.aces_transform_id = lmt_values['transformID']
686 pprint.pprint(lmt_values)
688 # Generating the *shaper* transform.
691 shaper_from_aces_ctl,
693 shaper_params) = shaper_info
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 lut = 'Inverse.%s.%s.spi3d' % (lmt_name, shaper_name)
744 generate_3d_LUT_from_CTL(
745 os.path.join(lut_directory, lut),
756 cs.to_reference_transforms.append({
759 'interpolation': 'tetrahedral',
760 'direction': 'forward'})
762 shaper_inverse = shaper_ocio_transform.copy()
763 shaper_inverse['direction'] = 'forward'
764 cs.to_reference_transforms.append(shaper_inverse)
769 # -------------------------------------------------------------------------
771 # -------------------------------------------------------------------------
772 def create_LMTs(aces_ctl_directory,
784 Parameter description.
789 Return value description.
794 # -------------------------------------------------------------------------
796 # -------------------------------------------------------------------------
797 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
798 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
800 # Defining the *Log 2* shaper.
801 lmt_shaper_name = 'LMT Shaper'
802 lmt_shaper_name_aliases = ['crv_lmtshaper']
808 lmt_shaper = create_generic_log(aces_ctl_directory,
810 lmt_lut_resolution_1d,
812 name=lmt_shaper_name,
813 middle_grey=lmt_params['middleGrey'],
814 min_exposure=lmt_params['minExposure'],
815 max_exposure=lmt_params['maxExposure'],
816 aliases=lmt_shaper_name_aliases)
817 colorspaces.append(lmt_shaper)
819 shaper_input_scale_generic_log2 = 1
821 # *Log 2* shaper name and *CTL* transforms bundled up.
826 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
829 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
830 shaper_input_scale_generic_log2,
833 sorted_lmts = sorted(lmt_info.iteritems(), key=lambda x: x[1])
835 for lmt in sorted_lmts:
836 lmt_name, lmt_values = lmt
837 lmt_aliases = ['look_%s' % compact(lmt_values['transformUserName'])]
838 cs = create_ACES_LMT(
839 lmt_values['transformUserName'],
844 lmt_lut_resolution_3d,
847 colorspaces.append(cs)
852 # -------------------------------------------------------------------------
853 # *ACES RRT* with supplied *ODT*.
854 # -------------------------------------------------------------------------
855 def create_ACES_RRT_plus_ODT(odt_name,
860 lut_resolution_3d=64,
869 Parameter description.
874 Return value description.
880 cs = ColorSpace('%s' % odt_name)
881 cs.description = '%s - %s Output Transform' % (
882 odt_values['transformUserNamePrefix'], odt_name)
884 cs.equality_group = ''
888 cs.aces_transform_id = odt_values['transformID']
890 pprint.pprint(odt_values)
892 # Generating the *shaper* transform.
895 shaper_from_aces_ctl,
897 shaper_params) = shaper_info
899 if 'legalRange' in odt_values:
900 shaper_params['legalRange'] = odt_values['legalRange']
902 shaper_params['legalRange'] = 0
904 shaper_lut = '%s_to_linear.spi1d' % shaper_name
905 shaper_lut = sanitize(shaper_lut)
907 shaper_ocio_transform = {
910 'interpolation': 'linear',
911 'direction': 'inverse'}
913 # Generating the *forward* transform.
914 cs.from_reference_transforms = []
916 if 'transformLUT' in odt_values:
917 transform_lut_file_name = os.path.basename(
918 odt_values['transformLUT'])
919 lut = os.path.join(lut_directory, transform_lut_file_name)
920 shutil.copy(odt_values['transformLUT'], lut)
922 cs.from_reference_transforms.append(shaper_ocio_transform)
923 cs.from_reference_transforms.append({
925 'path': transform_lut_file_name,
926 'interpolation': 'tetrahedral',
927 'direction': 'forward'})
928 elif 'transformCTL' in odt_values:
930 shaper_to_aces_ctl % aces_ctl_directory,
931 os.path.join(aces_ctl_directory,
934 os.path.join(aces_ctl_directory,
936 odt_values['transformCTL'])]
937 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
941 generate_3d_LUT_from_CTL(
942 os.path.join(lut_directory, lut),
946 1 / shaper_input_scale,
952 cs.from_reference_transforms.append(shaper_ocio_transform)
953 cs.from_reference_transforms.append({
956 'interpolation': 'tetrahedral',
957 'direction': 'forward'})
959 # Generating the *inverse* transform.
960 cs.to_reference_transforms = []
962 if 'transformLUTInverse' in odt_values:
963 transform_lut_inverse_file_name = os.path.basename(
964 odt_values['transformLUTInverse'])
965 lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
966 shutil.copy(odt_values['transformLUTInverse'], lut)
968 cs.to_reference_transforms.append({
970 'path': transform_lut_inverse_file_name,
971 'interpolation': 'tetrahedral',
972 'direction': 'forward'})
974 shaper_inverse = shaper_ocio_transform.copy()
975 shaper_inverse['direction'] = 'forward'
976 cs.to_reference_transforms.append(shaper_inverse)
977 elif 'transformCTLInverse' in odt_values:
978 ctls = [os.path.join(aces_ctl_directory,
980 odt_values['transformCTLInverse']),
981 os.path.join(aces_ctl_directory,
983 'InvRRT.a1.0.0.ctl'),
984 shaper_from_aces_ctl % aces_ctl_directory]
985 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
989 generate_3d_LUT_from_CTL(
990 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 and 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 dolby_pq_shaper_name = 'Dolby PQ 10000'
1141 dolby_pq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1143 dolby_pq_shaper_colorspace = create_Dolby_PQ(
1148 name=dolby_pq_shaper_name,
1149 aliases=dolby_pq_shaper_name_aliases)
1150 colorspaces.append(dolby_pq_shaper_colorspace)
1152 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1153 dolby_pq_shaper_data = [
1154 dolby_pq_shaper_name,
1157 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1160 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1164 shaper_data[dolby_pq_shaper_name] = dolby_pq_shaper_data
1166 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1167 dolby_pq_scaled_shaper_name = 'Dolby PQ Scaled'
1168 dolby_pq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1170 dolby_pq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1175 name=dolby_pq_scaled_shaper_name,
1176 aliases=dolby_pq_scaled_shaper_name_aliases)
1177 colorspaces.append(dolby_pq_scaled_shaper_colorspace)
1179 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1180 dolby_pq_scaled_shaper_data = [
1181 dolby_pq_scaled_shaper_name,
1184 'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1187 'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1191 shaper_data[dolby_pq_scaled_shaper_name] = dolby_pq_scaled_shaper_data
1193 rrt_shaper = log2_shaper_data
1194 # rrt_shaper = dolby_pq_scaled_shaper_data
1196 # *RRT + ODT* combinations.
1197 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1199 for odt in sorted_odts:
1200 (odt_name, odt_values) = odt
1202 # Defining full range transform for *ODTs* that can generate either
1203 # *legal* or *full* output.
1205 # Uncomment these lines and the lower section and
1206 # flip the `legalRange` value to 1 to restore the old behavior,
1207 # where both *legal* or *full* range *LUTs* were generated.
1208 if odt_values['transformHasFullLegalSwitch']:
1209 # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1210 odt_legal['legalRange'] = 0
1212 # odt_name_legal = odt_values['transformUserName']
1214 odt_name_legal = odt_values['transformUserName']
1216 odt_legal = odt_values.copy()
1218 odt_aliases = ['out_%s' % compact(odt_name_legal)]
1220 cs = create_ACES_RRT_plus_ODT(
1229 colorspaces.append(cs)
1231 displays[odt_name_legal] = {
1232 'Raw': linear_display_space,
1233 'Log': log_display_space,
1234 'Output Transform': cs}
1237 # Generating full range transform for *ODTs* that can generate
1238 # either *legal* or *full* output.
1239 if odt_values['transformHasFullLegalSwitch']:
1240 print('Generating full range ODT for %s' % odt_name)
1242 odt_name_full = '%s - Full' % odt_values['transformUserName']
1243 odt_full = odt_values.copy()
1244 odt_full['legalRange'] = 0
1246 odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1248 cs_full = create_ACES_RRT_plus_ODT(
1258 colorspaces.append(cs_full)
1260 displays[odt_name_full] = {
1261 'Raw': linear_display_space,
1262 'Log': log_display_space,
1263 'Output Transform': cs_full}
1266 return colorspaces, displays
1269 def get_transform_info(ctl_transform):
1276 Parameter description.
1281 Return value description.
1284 with open(ctl_transform, 'rb') as fp:
1285 lines = fp.readlines()
1287 # Retrieving the *transform ID* and *User Name*.
1288 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1289 transform_user_name = '-'.join(
1290 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1291 transform_user_name_prefix = (
1292 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1294 # Figuring out if this transform has options for processing *full* and
1296 transform_full_legal_switch = False
1298 if line.strip() == 'input varying int legalRange = 0':
1299 # print( '%s has legal range flag' % transform_user_name)
1300 transform_full_legal_switch = True
1303 return (transform_id,
1304 transform_user_name,
1305 transform_user_name_prefix,
1306 transform_full_legal_switch)
1309 def get_ODTs_info(aces_ctl_directory):
1313 For versions after WGR9.
1318 Parameter description.
1323 Return value description.
1326 # TODO: Investigate usage of *files_walker* definition here.
1327 # Credit to *Alex Fry* for the original approach here.
1328 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1330 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1331 for fname in file_list:
1332 all_odt.append((os.path.join(dir_name, fname)))
1334 odt_ctls = [x for x in all_odt if
1335 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1339 for odt_ctl in odt_ctls:
1340 odt_tokens = os.path.split(odt_ctl)
1342 # Handling nested directories.
1343 odt_path_tokens = os.path.split(odt_tokens[-2])
1344 odt_dir = odt_path_tokens[-1]
1345 while odt_path_tokens[-2][-3:] != 'odt':
1346 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1347 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1349 # Building full name.
1350 transform_ctl = odt_tokens[-1]
1351 odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1353 # Finding id, user name and user name prefix.
1355 transform_user_name,
1356 transform_user_name_prefix,
1357 transform_full_legal_switch) = get_transform_info(
1358 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1361 transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1362 if not os.path.exists(
1363 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1364 transform_ctl_inverse = None
1366 # Adding to list of *ODTs*.
1368 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1369 if transform_ctl_inverse is not None:
1370 odts[odt_name]['transformCTLInverse'] = os.path.join(
1371 odt_dir, transform_ctl_inverse)
1373 odts[odt_name]['transformID'] = transform_id
1374 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1375 odts[odt_name]['transformUserName'] = transform_user_name
1377 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1379 forward_ctl = odts[odt_name]['transformCTL']
1381 print('ODT : %s' % odt_name)
1382 print('\tTransform ID : %s' % transform_id)
1383 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1384 print('\tTransform User Name : %s' % transform_user_name)
1386 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1387 print('\tForward ctl : %s' % forward_ctl)
1388 if 'transformCTLInverse' in odts[odt_name]:
1389 inverse_ctl = odts[odt_name]['transformCTLInverse']
1390 print('\tInverse ctl : %s' % inverse_ctl)
1392 print('\tInverse ctl : %s' % 'None')
1399 def get_LMTs_info(aces_ctl_directory):
1403 For versions after WGR9.
1408 Parameter description.
1413 Return value description.
1416 # TODO: Investigate refactoring with previous definition.
1418 # Credit to Alex Fry for the original approach here
1419 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1421 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1422 for fname in file_list:
1423 all_lmt.append((os.path.join(dir_name, fname)))
1425 lmt_ctls = [x for x in all_lmt if
1426 ('InvLMT' not in x) and ('README' not in x) and (
1427 os.path.split(x)[-1][0] != '.')]
1431 for lmt_ctl in lmt_ctls:
1432 lmt_tokens = os.path.split(lmt_ctl)
1434 # Handlimg nested directories.
1435 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1436 lmt_dir = lmt_path_tokens[-1]
1437 while lmt_path_tokens[-2][-3:] != 'ctl':
1438 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1439 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1441 # Building full name.
1442 transform_ctl = lmt_tokens[-1]
1443 lmt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1445 # Finding id, user name and user name prefix.
1447 transform_user_name,
1448 transform_user_name_prefix,
1449 transform_full_legal_switch) = get_transform_info(
1450 os.path.join(aces_ctl_directory, lmt_dir, transform_ctl))
1453 transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1454 if not os.path.exists(
1455 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1456 transform_ctl_inverse = None
1459 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_ctl)
1460 if transform_ctl_inverse is not None:
1461 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1462 lmt_dir, transform_ctl_inverse)
1464 lmts[lmt_name]['transformID'] = transform_id
1465 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1466 lmts[lmt_name]['transformUserName'] = transform_user_name
1468 forward_ctl = lmts[lmt_name]['transformCTL']
1470 print('LMT : %s' % lmt_name)
1471 print('\tTransform ID : %s' % transform_id)
1472 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1473 print('\tTransform User Name : %s' % transform_user_name)
1474 print('\t Forward ctl : %s' % forward_ctl)
1475 if 'transformCTLInverse' in lmts[lmt_name]:
1476 inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1477 print('\t Inverse ctl : %s' % inverse_ctl)
1479 print('\t Inverse ctl : %s' % 'None')
1486 def create_colorspaces(aces_ctl_directory,
1495 Generates the colorspace conversions.
1500 Parameter description.
1505 Return value description.
1510 ACES = create_ACES()
1512 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1513 lut_resolution_1d, cleanup,
1514 min_value=-0.35840, max_value=1.468)
1515 colorspaces.append(ACEScc)
1517 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1518 lut_resolution_1d, cleanup)
1519 colorspaces.append(ACESproxy)
1521 ACEScg = create_ACEScg()
1522 colorspaces.append(ACEScg)
1524 ADX10 = create_ADX(lut_directory, bit_depth=10)
1525 colorspaces.append(ADX10)
1527 ADX16 = create_ADX(lut_directory, bit_depth=16)
1528 colorspaces.append(ADX16)
1530 lmts = create_LMTs(aces_ctl_directory,
1536 colorspaces.extend(lmts)
1538 odts, displays = create_ODTs(aces_ctl_directory,
1547 colorspaces.extend(odts)
1549 # TODO: Investigate if there is a way to retrieve the value from *CTL*.
1550 default_display = 'sRGB (D60 sim.)'
1552 roles = {'color_picking': ACEScg.name,
1553 'color_timing': ACEScc.name,
1554 'compositing_log': ACEScc.name,
1556 'default': ACES.name,
1557 'matte_paint': ACEScc.name,
1559 'scene_linear': ACEScg.name,
1560 'texture_paint': ''}
1562 return ACES, colorspaces, displays, ACEScc, roles, default_display