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 # 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,
785 Parameter description.
790 Return value description.
795 # -------------------------------------------------------------------------
797 # -------------------------------------------------------------------------
798 lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
799 lmt_lut_resolution_3d = max(65, lut_resolution_3d)
801 # Defining the *Log 2* shaper.
802 lmt_shaper_name = 'LMT Shaper'
803 lmt_shaper_name_aliases = ['crv_lmtshaper']
809 lmt_shaper = create_generic_log(aces_ctl_directory,
811 lmt_lut_resolution_1d,
813 name=lmt_shaper_name,
814 middle_grey=lmt_params['middleGrey'],
815 min_exposure=lmt_params['minExposure'],
816 max_exposure=lmt_params['maxExposure'],
817 aliases=lmt_shaper_name_aliases)
818 colorspaces.append(lmt_shaper)
820 shaper_input_scale_generic_log2 = 1
822 # *Log 2* shaper name and *CTL* transforms bundled up.
827 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
830 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
831 shaper_input_scale_generic_log2,
834 sorted_lmts = sorted(lmt_info.iteritems(), key=lambda x: x[1])
836 for lmt in sorted_lmts:
837 lmt_name, lmt_values = lmt
838 lmt_aliases = ['look_%s' % compact(lmt_values['transformUserName'])]
839 cs = create_ACES_LMT(
840 lmt_values['transformUserName'],
845 lmt_lut_resolution_3d,
848 colorspaces.append(cs)
853 # -------------------------------------------------------------------------
854 # *ACES RRT* with supplied *ODT*.
855 # -------------------------------------------------------------------------
856 def create_ACES_RRT_plus_ODT(odt_name,
861 lut_resolution_3d=64,
870 Parameter description.
875 Return value description.
881 cs = ColorSpace('%s' % odt_name)
882 cs.description = '%s - %s Output Transform' % (
883 odt_values['transformUserNamePrefix'], odt_name)
885 cs.equality_group = ''
889 cs.aces_transform_id = odt_values['transformID']
891 pprint.pprint(odt_values)
893 # Generating the *shaper* transform.
896 shaper_from_aces_ctl,
898 shaper_params) = shaper_info
900 if 'legalRange' in odt_values:
901 shaper_params['legalRange'] = odt_values['legalRange']
903 shaper_params['legalRange'] = 0
905 shaper_lut = '%s_to_linear.spi1d' % shaper_name
906 shaper_lut = sanitize(shaper_lut)
908 shaper_ocio_transform = {
911 'interpolation': 'linear',
912 'direction': 'inverse'}
914 # Generating the *forward* transform.
915 cs.from_reference_transforms = []
917 if 'transformLUT' in odt_values:
918 transform_lut_file_name = os.path.basename(
919 odt_values['transformLUT'])
920 lut = os.path.join(lut_directory, transform_lut_file_name)
921 shutil.copy(odt_values['transformLUT'], lut)
923 cs.from_reference_transforms.append(shaper_ocio_transform)
924 cs.from_reference_transforms.append({
926 'path': transform_lut_file_name,
927 'interpolation': 'tetrahedral',
928 'direction': 'forward'})
929 elif 'transformCTL' in odt_values:
931 shaper_to_aces_ctl % aces_ctl_directory,
932 os.path.join(aces_ctl_directory,
935 os.path.join(aces_ctl_directory,
937 odt_values['transformCTL'])]
938 lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
942 generate_3d_LUT_from_CTL(
943 os.path.join(lut_directory, lut),
947 1 / shaper_input_scale,
953 cs.from_reference_transforms.append(shaper_ocio_transform)
954 cs.from_reference_transforms.append({
957 'interpolation': 'tetrahedral',
958 'direction': 'forward'})
960 # Generating the *inverse* transform.
961 cs.to_reference_transforms = []
963 if 'transformLUTInverse' in odt_values:
964 transform_lut_inverse_file_name = os.path.basename(
965 odt_values['transformLUTInverse'])
966 lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
967 shutil.copy(odt_values['transformLUTInverse'], lut)
969 cs.to_reference_transforms.append({
971 'path': transform_lut_inverse_file_name,
972 'interpolation': 'tetrahedral',
973 'direction': 'forward'})
975 shaper_inverse = shaper_ocio_transform.copy()
976 shaper_inverse['direction'] = 'forward'
977 cs.to_reference_transforms.append(shaper_inverse)
978 elif 'transformCTLInverse' in odt_values:
979 ctls = [os.path.join(aces_ctl_directory,
981 odt_values['transformCTLInverse']),
982 os.path.join(aces_ctl_directory,
984 'InvRRT.a1.0.0.ctl'),
985 shaper_from_aces_ctl % aces_ctl_directory]
986 lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
990 generate_3d_LUT_from_CTL(
991 os.path.join(lut_directory, lut),
1001 cs.to_reference_transforms.append({
1004 'interpolation': 'tetrahedral',
1005 'direction': 'forward'})
1007 shaper_inverse = shaper_ocio_transform.copy()
1008 shaper_inverse['direction'] = 'forward'
1009 cs.to_reference_transforms.append(shaper_inverse)
1014 # -------------------------------------------------------------------------
1016 # -------------------------------------------------------------------------
1017 def create_ODTs(aces_ctl_directory,
1024 linear_display_space,
1032 Parameter description.
1037 Return value description.
1043 # -------------------------------------------------------------------------
1044 # *RRT / ODT* Shaper Options
1045 # -------------------------------------------------------------------------
1048 # Defining the *Log 2* shaper.
1049 log2_shaper_name = shaper_name
1050 log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1056 log2_shaper_colorspace = create_generic_log(
1061 name=log2_shaper_name,
1062 middle_grey=log2_params['middleGrey'],
1063 min_exposure=log2_params['minExposure'],
1064 max_exposure=log2_params['maxExposure'],
1065 aliases=log2_shaper_name_aliases)
1066 colorspaces.append(log2_shaper_colorspace)
1068 shaper_input_scale_generic_log2 = 1
1070 # *Log 2* shaper name and *CTL* transforms bundled up.
1071 log2_shaper_data = [
1075 'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1078 'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1079 shaper_input_scale_generic_log2,
1082 shaper_data[log2_shaper_name] = log2_shaper_data
1084 # Space with a more user-friendly name. Direct copy otherwise.
1085 log2_shaper_copy_name = 'Log2 Shaper'
1086 log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1087 log2_shaper_copy_colorspace.description = (
1088 'The %s color space' % log2_shaper_copy_name)
1089 log2_shaper_copy_colorspace.aliases = [
1090 'crv_%s' % compact(log2_shaper_copy_name)]
1091 log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1092 log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1093 log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1094 log2_shaper_copy_colorspace.to_reference_transforms = list(
1095 log2_shaper_colorspace.to_reference_transforms)
1096 log2_shaper_copy_colorspace.from_reference_transforms = list(
1097 log2_shaper_colorspace.from_reference_transforms)
1098 colorspaces.append(log2_shaper_copy_colorspace)
1100 # Defining the *Log2 shaper that includes the AP1* primaries.
1101 log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1102 log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1103 log2_shaper_api1_colorspace.description = (
1104 'The %s color space' % log2_shaper_api1_name)
1105 log2_shaper_api1_colorspace.aliases = [
1106 '%s_ap1' % compact(log2_shaper_copy_name)]
1107 log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1108 log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1109 log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1110 log2_shaper_api1_colorspace.to_reference_transforms = list(
1111 log2_shaper_colorspace.to_reference_transforms)
1112 log2_shaper_api1_colorspace.from_reference_transforms = list(
1113 log2_shaper_colorspace.from_reference_transforms)
1115 # *AP1* primaries to *AP0* primaries
1116 log2_shaper_api1_colorspace.to_reference_transforms.append({
1118 'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1119 'direction': 'forward'
1121 colorspaces.append(log2_shaper_api1_colorspace)
1123 # Defining the *Log2* shaper that includes the *AP1* primaries.
1124 # Named with `shaper_name` variable and needed for some *LUT* baking steps.
1125 shaper_api1_name = '%s - AP1' % shaper_name
1126 shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1127 shaper_api1_colorspace.description = (
1128 'The %s color space' % shaper_api1_name)
1129 shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1130 shaper_api1_colorspace.equality_group = shaper_api1_name
1131 shaper_api1_colorspace.family = log2_shaper_colorspace.family
1132 shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1133 shaper_api1_colorspace.to_reference_transforms = list(
1134 log2_shaper_api1_colorspace.to_reference_transforms)
1135 shaper_api1_colorspace.from_reference_transforms = list(
1136 log2_shaper_api1_colorspace.from_reference_transforms)
1137 colorspaces.append(shaper_api1_colorspace)
1139 # Define the base *Dolby PQ Shaper*
1141 dolby_pq_shaper_name = 'Dolby PQ 10000'
1142 dolbypq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1144 dolbypq_shaper_colorspace = create_Dolby_PQ(
1149 name=dolby_pq_shaper_name,
1150 aliases=dolbypq_shaper_name_aliases)
1151 colorspaces.append(dolbypq_shaper_colorspace)
1153 # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1154 dolbypq_shaper_data = [
1155 dolby_pq_shaper_name,
1158 'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1161 'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1165 shaper_data[dolby_pq_shaper_name] = dolbypq_shaper_data
1167 # Define the *Dolby PQ Shaper that considers a fixed linear range*
1168 dolby_pq_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=dolby_pq_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 dolby_pq_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[dolby_pq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1194 rrt_shaper = log2_shaper_data
1195 # rrt_shaper = dolbypq_scaled_shaper_data
1197 # *RRT + ODT* combinations.
1198 sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1200 for odt in sorted_odts:
1201 (odt_name, odt_values) = odt
1203 # Defining full range transform for *ODTs* that can only generate
1204 # either *legal* or *full* output.
1206 # Uncomment these lines and the lower section and
1207 # flip the `legalRange` value to 1 to restore the old behavior,
1208 # where both *legal* or *full* range *LUTs* were generated.
1209 if odt_values['transformHasFullLegalSwitch']:
1210 # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1211 odt_legal['legalRange'] = 0
1213 # odt_name_legal = odt_values['transformUserName']
1215 odt_name_legal = odt_values['transformUserName']
1217 odt_legal = odt_values.copy()
1219 odt_aliases = ['out_%s' % compact(odt_name_legal)]
1221 cs = create_ACES_RRT_plus_ODT(
1230 colorspaces.append(cs)
1232 displays[odt_name_legal] = {
1233 'Raw': linear_display_space,
1234 'Log': log_display_space,
1235 'Output Transform': cs}
1238 # Generating full range transform for *ODTs* that can generate
1239 # either *legal* or *full* output.
1240 if odt_values['transformHasFullLegalSwitch']:
1241 print('Generating full range ODT for %s' % odt_name)
1243 odt_name_full = '%s - Full' % odt_values['transformUserName']
1244 odt_full = odt_values.copy()
1245 odt_full['legalRange'] = 0
1247 odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1249 cs_full = create_ACES_RRT_plus_ODT(
1259 colorspaces.append(cs_full)
1261 displays[odt_name_full] = {
1262 'Raw': linear_display_space,
1263 'Log': log_display_space,
1264 'Output Transform': cs_full}
1267 return colorspaces, displays
1270 def get_transform_info(ctl_transform):
1277 Parameter description.
1282 Return value description.
1285 with open(ctl_transform, 'rb') as fp:
1286 lines = fp.readlines()
1288 # Retrieving the *transform ID* and *User Name*.
1289 transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1290 transform_user_name = '-'.join(
1291 lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1292 transform_user_name_prefix = (
1293 lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1295 # Figuring out if this transform has options for processing *full* and
1297 transform_full_legal_switch = False
1299 if line.strip() == 'input varying int legalRange = 0':
1300 # print( '%s has legal range flag' % transform_user_name)
1301 transform_full_legal_switch = True
1304 return (transform_id, transform_user_name, transform_user_name_prefix,
1305 transform_full_legal_switch)
1308 def get_ODTs_info(aces_ctl_directory):
1312 For versions after WGR9.
1317 Parameter description.
1322 Return value description.
1325 # TODO: Investigate usage of *files_walker* definition here.
1326 # Credit to *Alex Fry* for the original approach here.
1327 odt_dir = os.path.join(aces_ctl_directory, 'odt')
1329 for dir_name, subdir_list, file_list in os.walk(odt_dir):
1330 for fname in file_list:
1331 all_odt.append((os.path.join(dir_name, fname)))
1333 odt_ctls = [x for x in all_odt if
1334 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1338 for odt_ctl in odt_ctls:
1339 odt_tokens = os.path.split(odt_ctl)
1341 # Handling nested directories.
1342 odt_path_tokens = os.path.split(odt_tokens[-2])
1343 odt_dir = odt_path_tokens[-1]
1344 while odt_path_tokens[-2][-3:] != 'odt':
1345 odt_path_tokens = os.path.split(odt_path_tokens[-2])
1346 odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1348 # Building full name.
1349 transform_ctl = odt_tokens[-1]
1350 odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1352 # Finding id, user name and user name prefix.
1354 transform_user_name,
1355 transform_user_name_prefix,
1356 transform_full_legal_switch) = get_transform_info(
1357 os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1360 transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1361 if not os.path.exists(
1362 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1363 transform_ctl_inverse = None
1365 # Adding to list of *ODTs*.
1367 odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1368 if transform_ctl_inverse is not None:
1369 odts[odt_name]['transformCTLInverse'] = os.path.join(
1370 odt_dir, transform_ctl_inverse)
1372 odts[odt_name]['transformID'] = transform_id
1373 odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1374 odts[odt_name]['transformUserName'] = transform_user_name
1376 'transformHasFullLegalSwitch'] = transform_full_legal_switch
1378 forward_ctl = odts[odt_name]['transformCTL']
1380 print('ODT : %s' % odt_name)
1381 print('\tTransform ID : %s' % transform_id)
1382 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1383 print('\tTransform User Name : %s' % transform_user_name)
1385 '\tHas Full / Legal Switch : %s' % transform_full_legal_switch)
1386 print('\tForward ctl : %s' % forward_ctl)
1387 if 'transformCTLInverse' in odts[odt_name]:
1388 inverse_ctl = odts[odt_name]['transformCTLInverse']
1389 print('\tInverse ctl : %s' % inverse_ctl)
1391 print('\tInverse ctl : %s' % 'None')
1398 def get_LMTs_info(aces_ctl_directory):
1402 For versions after WGR9.
1407 Parameter description.
1412 Return value description.
1415 # TODO: Investigate refactoring with previous definition.
1417 # Credit to Alex Fry for the original approach here
1418 lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1420 for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1421 for fname in file_list:
1422 all_lmt.append((os.path.join(dir_name, fname)))
1424 lmt_ctls = [x for x in all_lmt if
1425 ('InvLMT' not in x) and ('README' not in x) and (
1426 os.path.split(x)[-1][0] != '.')]
1430 for lmt_ctl in lmt_ctls:
1431 lmt_tokens = os.path.split(lmt_ctl)
1433 # Handlimg nested directories.
1434 lmt_path_tokens = os.path.split(lmt_tokens[-2])
1435 lmt_dir = lmt_path_tokens[-1]
1436 while lmt_path_tokens[-2][-3:] != 'ctl':
1437 lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1438 lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1440 # Building full name.
1441 transform_CTL = lmt_tokens[-1]
1442 lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1444 # Finding id, user name and user name prefix.
1446 transform_user_name,
1447 transform_user_name_prefix,
1448 transform_full_legal_switch) = get_transform_info(
1449 os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1452 transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1453 if not os.path.exists(
1454 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1455 transform_ctl_inverse = None
1458 lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1459 if transform_ctl_inverse is not None:
1460 lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1461 lmt_dir, transform_ctl_inverse)
1463 lmts[lmt_name]['transformID'] = transform_id
1464 lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1465 lmts[lmt_name]['transformUserName'] = transform_user_name
1467 forward_ctl = lmts[lmt_name]['transformCTL']
1469 print('LMT : %s' % lmt_name)
1470 print('\tTransform ID : %s' % transform_id)
1471 print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1472 print('\tTransform User Name : %s' % transform_user_name)
1473 print('\t Forward ctl : %s' % forward_ctl)
1474 if 'transformCTLInverse' in lmts[lmt_name]:
1475 inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1476 print('\t Inverse ctl : %s' % inverse_ctl)
1478 print('\t Inverse ctl : %s' % 'None')
1485 def create_colorspaces(aces_ctl_directory,
1494 Generates the colorspace conversions.
1499 Parameter description.
1504 Return value description.
1509 ACES = create_ACES()
1511 ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1512 lut_resolution_1d, cleanup,
1513 min_value=-0.35840, max_value=1.468)
1514 colorspaces.append(ACEScc)
1516 ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1517 lut_resolution_1d, cleanup)
1518 colorspaces.append(ACESproxy)
1520 ACEScg = create_ACEScg()
1521 colorspaces.append(ACEScg)
1523 ADX10 = create_ADX(lut_directory, bit_depth=10)
1524 colorspaces.append(ADX10)
1526 ADX16 = create_ADX(lut_directory, bit_depth=16)
1527 colorspaces.append(ADX16)
1529 lmts = create_LMTs(aces_ctl_directory,
1535 colorspaces.extend(lmts)
1537 odts, displays = create_ODTs(aces_ctl_directory,
1546 colorspaces.extend(odts)
1548 # TODO: Investigate if there is a way to retrieve the value from *CTL*.
1549 default_display = 'sRGB (D60 sim.)'
1551 roles = {'color_picking': ACEScg.name,
1552 'color_timing': ACEScc.name,
1553 'compositing_log': ACEScc.name,
1555 'default': ACES.name,
1556 'matte_paint': ACEScc.name,
1558 'scene_linear': ACEScg.name,
1559 'texture_paint': ''}
1561 return ACES, colorspaces, displays, ACEScc, roles, default_display