Roles now have some assignments
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / create_general_colorspaces.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 Implements support for general colorspaces conversions and transfer functions.
6 """
7
8 from __future__ import division
9
10 import PyOpenColorIO as ocio
11
12 import aces_ocio.create_aces_colorspaces as aces
13 from aces_ocio.utilities import ColorSpace, mat44_from_mat33
14
15
16 __author__ = 'ACES Developers'
17 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
18 __license__ = ''
19 __maintainer__ = 'ACES Developers'
20 __email__ = 'aces@oscars.org'
21 __status__ = 'Production'
22
23 __all__ = ['create_generic_matrix',
24            'create_colorspaces']
25
26 # -------------------------------------------------------------------------
27 # *Simple Matrix Transform*
28 # -------------------------------------------------------------------------
29 def create_generic_matrix(name='matrix',
30                           from_reference_values=None,
31                           to_reference_values=None,
32                           aliases=[]):
33     """
34     Object description.
35
36     Parameters
37     ----------
38     parameter : type
39         Parameter description.
40
41     Returns
42     -------
43     type
44          Return value description.
45     """
46
47     if from_reference_values is None:
48         from_reference_values = []
49
50     if to_reference_values is None:
51         to_reference_values = []
52
53     cs = ColorSpace(name)
54     cs.description = 'The %s color space' % name
55     cs.aliases = aliases
56     cs.equality_group = name
57     cs.family = 'Utility'
58     cs.is_data = False
59
60     # A linear space needs allocation variables
61     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
62     cs.allocation_vars = [-8, 5, 0.00390625]
63
64     cs.to_reference_transforms = []
65     if to_reference_values:
66         for matrix in to_reference_values:
67             cs.to_reference_transforms.append({
68                 'type': 'matrix',
69                 'matrix': mat44_from_mat33(matrix),
70                 'direction': 'forward'})
71
72     cs.from_reference_transforms = []
73     if from_reference_values:
74         for matrix in from_reference_values:
75             cs.from_reference_transforms.append({
76                 'type': 'matrix',
77                 'matrix': mat44_from_mat33(matrix),
78                 'direction': 'forward'})
79
80     return cs
81
82 def create_colorspaces(lut_directory,
83                        lut_resolution_1d,
84                        lut_resolution_3d):
85     """
86     Generates the colorspace conversions.
87
88     Parameters
89     ----------
90     parameter : type
91         Parameter description.
92
93     Returns
94     -------
95     type
96          Return value description.
97     """
98
99     colorspaces = []
100
101     cs = create_generic_matrix('XYZ',
102                                to_reference_values=[aces.ACES_XYZ_TO_AP0],
103                                from_reference_values=[aces.ACES_AP0_TO_XYZ],
104                                aliases=["lin_xyz"])
105     colorspaces.append(cs)
106
107     cs = create_generic_matrix(
108         'Linear - AP1',
109         to_reference_values=[aces.ACES_AP1_TO_AP0],
110         from_reference_values=[aces.ACES_AP0_TO_AP1],
111         aliases=["lin_ap1"])
112     colorspaces.append(cs)
113
114     # *ACES* to *Linear*, *P3D60* primaries.
115     XYZ_to_P3D60 = [2.4027414142, -0.8974841639, -0.3880533700,
116                     -0.8325796487, 1.7692317536, 0.0237127115,
117                     0.0388233815, -0.0824996856, 1.0363685997]
118
119     cs = create_generic_matrix(
120         'Linear - P3-D60',
121         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_P3D60],
122         aliases=["lin_p3d60"])
123     colorspaces.append(cs)
124
125     # *ACES* to *Linear*, *P3DCI* primaries.
126     XYZ_to_P3DCI = [2.7253940305, -1.0180030062, -0.4401631952,
127                     -0.7951680258, 1.6897320548, 0.0226471906,
128                     0.0412418914, -0.0876390192, 1.1009293786]
129
130     cs = create_generic_matrix(
131         'Linear - P3-DCI',
132         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_P3DCI],
133         aliases=["lin_p3dci"])
134     colorspaces.append(cs)
135
136     # *ACES* to *Linear*, *Rec. 709* primaries.
137     XYZ_to_Rec709 = [3.2409699419, -1.5373831776, -0.4986107603,
138                      -0.9692436363, 1.8759675015, 0.0415550574,
139                      0.0556300797, -0.2039769589, 1.0569715142]
140
141     cs = create_generic_matrix(
142         'Linear - Rec.709',
143         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
144         aliases=["lin_rec709"])
145     colorspaces.append(cs)
146
147     # *ACES* to *Linear*, *Rec. 2020* primaries.
148     XYZ_to_Rec2020 = [1.7166511880, -0.3556707838, -0.2533662814,
149                       -0.6666843518, 1.6164812366, 0.0157685458,
150                       0.0176398574, -0.0427706133, 0.9421031212]
151
152     cs = create_generic_matrix(
153         'Linear - Rec.2020',
154         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec2020],
155         aliases=["lin_rec2020"])
156     colorspaces.append(cs)
157
158     # *ACES* to *Linear*, *Pro Photo* primaries.
159     AP0_to_RIMM = [1.2412367771, -0.1685692287, -0.0726675484,
160                    0.0061203066, 1.083151174, -0.0892714806,
161                    -0.0032853314, 0.0099796402, 0.9933056912]
162
163     cs = create_generic_matrix(
164         'Linear - RIMM ROMM (ProPhoto)',
165         from_reference_values=[AP0_to_RIMM],
166         aliases=["lin_prophoto", "lin_rimm"])
167     colorspaces.append(cs)
168
169     # *ACES* to *Linear*, *Adobe RGB* primaries.
170     AP0_to_ADOBERGB = [1.7245603168, -0.4199935942, -0.3045667227,
171                        -0.2764799142, 1.3727190877, -0.0962391734,
172                        -0.0261255258, -0.0901747807, 1.1163003065]
173
174     cs = create_generic_matrix(
175         'Linear - Adobe RGB',
176         from_reference_values=[AP0_to_ADOBERGB],
177         aliases=["lin_adobergb"])
178     colorspaces.append(cs)
179
180
181     # *ACES* to *Linear*, *Adobe Wide Gamut RGB* primaries.
182     AP0_to_ADOBERGB = [1.3809814778, -0.1158594573, -0.2651220205,
183                        0.0057015535, 1.0402949043, -0.0459964578,
184                        -0.0038908746, -0.0597091815, 1.0636000561]
185
186     cs = create_generic_matrix(
187         'Linear - Adobe Wide Gamut RGB',
188         from_reference_values=[AP0_to_ADOBERGB],
189         aliases=["lin_adobewidegamutrgb"])
190     colorspaces.append(cs)
191
192     return colorspaces
193
194 def create_raw():
195     # *Raw* utility space
196     name = "Raw"
197     raw = ColorSpace(name)
198     raw.description = 'The %s color space' % name
199     raw.aliases = []
200     raw.equality_group = name
201     raw.family = 'Utility'
202     raw.is_data = True
203
204     return raw
205
206