6fd7377e794ca2c847b57890268b6048d691aff4
[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 def create_generic_matrix(name='matrix',
28                           from_reference_values=None,
29                           to_reference_values=None,
30                           aliases=[]):
31     """
32     Object description.
33
34     Parameters
35     ----------
36     parameter : type
37         Parameter description.
38
39     Returns
40     -------
41     type
42          Return value description.
43     """
44
45     if from_reference_values is None:
46         from_reference_values = []
47
48     if to_reference_values is None:
49         to_reference_values = []
50
51     cs = ColorSpace(name)
52     cs.description = 'The %s color space' % name
53     cs.aliases = aliases
54     cs.equality_group = name
55     cs.family = 'Utility'
56     cs.is_data = False
57
58     # A linear space needs allocation variables
59     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
60     cs.allocation_vars = [-8, 5, 0.00390625]
61
62     cs.to_reference_transforms = []
63     if to_reference_values:
64         for matrix in to_reference_values:
65             cs.to_reference_transforms.append({
66                 'type': 'matrix',
67                 'matrix': mat44_from_mat33(matrix),
68                 'direction': 'forward'})
69
70     cs.from_reference_transforms = []
71     if from_reference_values:
72         for matrix in from_reference_values:
73             cs.from_reference_transforms.append({
74                 'type': 'matrix',
75                 'matrix': mat44_from_mat33(matrix),
76                 'direction': 'forward'})
77
78     return cs
79
80
81 def create_colorspaces(lut_directory,
82                        lut_resolution_1d,
83                        lut_resolution_3d):
84     """
85     Generates the colorspace conversions.
86
87     Parameters
88     ----------
89     parameter : type
90         Parameter description.
91
92     Returns
93     -------
94     type
95          Return value description.
96     """
97
98     colorspaces = []
99
100     cs = create_generic_matrix('XYZ',
101                                to_reference_values=[aces.ACES_XYZ_TO_AP0],
102                                from_reference_values=[aces.ACES_AP0_TO_XYZ],
103                                aliases=["lin_xyz"])
104     colorspaces.append(cs)
105
106     cs = create_generic_matrix(
107         'Linear - AP1',
108         to_reference_values=[aces.ACES_AP1_TO_AP0],
109         from_reference_values=[aces.ACES_AP0_TO_AP1],
110         aliases=["lin_ap1"])
111     colorspaces.append(cs)
112
113     # *ACES* to *Linear*, *P3D60* primaries.
114     XYZ_to_P3D60 = [2.4027414142, -0.8974841639, -0.3880533700,
115                     -0.8325796487, 1.7692317536, 0.0237127115,
116                     0.0388233815, -0.0824996856, 1.0363685997]
117
118     cs = create_generic_matrix(
119         'Linear - P3-D60',
120         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_P3D60],
121         aliases=["lin_p3d60"])
122     colorspaces.append(cs)
123
124     # *ACES* to *Linear*, *P3DCI* primaries.
125     XYZ_to_P3DCI = [2.7253940305, -1.0180030062, -0.4401631952,
126                     -0.7951680258, 1.6897320548, 0.0226471906,
127                     0.0412418914, -0.0876390192, 1.1009293786]
128
129     cs = create_generic_matrix(
130         'Linear - P3-DCI',
131         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_P3DCI],
132         aliases=["lin_p3dci"])
133     colorspaces.append(cs)
134
135     # *ACES* to *Linear*, *Rec. 709* primaries.
136     XYZ_to_Rec709 = [3.2409699419, -1.5373831776, -0.4986107603,
137                      -0.9692436363, 1.8759675015, 0.0415550574,
138                      0.0556300797, -0.2039769589, 1.0569715142]
139
140     cs = create_generic_matrix(
141         'Linear - Rec.709',
142         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709],
143         aliases=["lin_rec709"])
144     colorspaces.append(cs)
145
146     # *ACES* to *Linear*, *Rec. 2020* primaries.
147     XYZ_to_Rec2020 = [1.7166511880, -0.3556707838, -0.2533662814,
148                       -0.6666843518, 1.6164812366, 0.0157685458,
149                       0.0176398574, -0.0427706133, 0.9421031212]
150
151     cs = create_generic_matrix(
152         'Linear - Rec.2020',
153         from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec2020],
154         aliases=["lin_rec2020"])
155     colorspaces.append(cs)
156
157     # *ACES* to *Linear*, *Pro Photo* primaries.
158     AP0_to_RIMM = [1.2412367771, -0.1685692287, -0.0726675484,
159                    0.0061203066, 1.083151174, -0.0892714806,
160                    -0.0032853314, 0.0099796402, 0.9933056912]
161
162     cs = create_generic_matrix(
163         'Linear - RIMM ROMM (ProPhoto)',
164         from_reference_values=[AP0_to_RIMM],
165         aliases=["lin_prophoto", "lin_rimm"])
166     colorspaces.append(cs)
167
168     # *ACES* to *Linear*, *Adobe RGB* primaries.
169     AP0_to_ADOBERGB = [1.7245603168, -0.4199935942, -0.3045667227,
170                        -0.2764799142, 1.3727190877, -0.0962391734,
171                        -0.0261255258, -0.0901747807, 1.1163003065]
172
173     cs = create_generic_matrix(
174         'Linear - Adobe RGB',
175         from_reference_values=[AP0_to_ADOBERGB],
176         aliases=["lin_adobergb"])
177     colorspaces.append(cs)
178
179     # *ACES* to *Linear*, *Adobe Wide Gamut RGB* primaries.
180     AP0_to_ADOBERGB = [1.3809814778, -0.1158594573, -0.2651220205,
181                        0.0057015535, 1.0402949043, -0.0459964578,
182                        -0.0038908746, -0.0597091815, 1.0636000561]
183
184     cs = create_generic_matrix(
185         'Linear - Adobe Wide Gamut RGB',
186         from_reference_values=[AP0_to_ADOBERGB],
187         aliases=["lin_adobewidegamutrgb"])
188     colorspaces.append(cs)
189
190     return colorspaces