Skip to content

Commit 6ae111a

Browse files
authored
Generalize CLF generation interface (#48)
* Generalize CLF generation interface Signed-off-by: Michael Dolan <michdolan@gmail.com> * Fix linting errors Signed-off-by: Michael Dolan <michdolan@gmail.com> * Update pre-commit to fix CI failure Signed-off-by: Michael Dolan <michdolan@gmail.com> * Revert pre-commit to python 3.8 Signed-off-by: Michael Dolan <michdolan@gmail.com> * Fix test failures Signed-off-by: Michael Dolan <michdolan@gmail.com> * Update doctests for new data Signed-off-by: Michael Dolan <michdolan@gmail.com> * Update argument naming Signed-off-by: Michael Dolan <michdolan@gmail.com>
1 parent 5216c2a commit 6ae111a

File tree

11 files changed

+393
-328
lines changed

11 files changed

+393
-328
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
hooks:
1010
- id: flynt
1111
- repo: https://github.com/psf/black
12-
rev: 22.1.0
12+
rev: 22.3.0
1313
hooks:
1414
- id: black
1515
language_version: python3.8

opencolorio_config_aces/clf/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
filter_clf_transforms,
99
print_clf_taxonomy,
1010
)
11-
12-
from .transforms import generate_clf
11+
from .transforms import (
12+
create_matrix,
13+
create_conversion_matrix,
14+
create_gamma,
15+
generate_clf,
16+
)
1317

1418
__all__ = [
1519
"discover_clf_transforms",
@@ -18,4 +22,9 @@
1822
"filter_clf_transforms",
1923
"print_clf_taxonomy",
2024
]
21-
__all__ += ["generate_clf"]
25+
__all__ += [
26+
"create_matrix",
27+
"create_conversion_matrix",
28+
"create_gamma",
29+
"generate_clf",
30+
]

opencolorio_config_aces/clf/discover/classify.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,14 @@
9595
NAMESPACE_CLF : unicode
9696
"""
9797

98-
TRANSFORM_TYPES_CLF = [
99-
"Utility",
100-
]
98+
TRANSFORM_TYPES_CLF = ["Input", "Utility"]
10199
"""
102100
*CLF* transform types.
103101
104102
TRANSFORM_TYPES_CLF : list
105103
"""
106104

107-
TRANSFORM_FAMILIES_CLF = {"utility": "Utility"}
105+
TRANSFORM_FAMILIES_CLF = {"input": "Input", "utility": "Utility"}
108106
"""
109107
*CLF* transform families mapping the *CLF* transform directories to family
110108
names.
@@ -1097,7 +1095,7 @@ def discover_clf_transforms(root_directory=ROOT_TRANSFORMS_CLF):
10971095
Examples
10981096
--------
10991097
>>> clf_transforms = discover_clf_transforms()
1100-
>>> key = sorted(clf_transforms.keys())[0]
1098+
>>> key = sorted(clf_transforms.keys())[1]
11011099
>>> os.path.basename(key)
11021100
'utility'
11031101
>>> sorted([os.path.basename(path) for path in clf_transforms[key]])[:2]
@@ -1159,7 +1157,7 @@ def classify_clf_transforms(unclassified_clf_transforms):
11591157
--------
11601158
>>> clf_transforms = classify_clf_transforms(
11611159
... discover_clf_transforms())
1162-
>>> family = sorted(clf_transforms.keys())[0]
1160+
>>> family = sorted(clf_transforms.keys())[1]
11631161
>>> str(family)
11641162
'Utility'
11651163
>>> genera = sorted(clf_transforms[family])
@@ -1249,7 +1247,7 @@ def unclassify_clf_transforms(classified_clf_transforms):
12491247
... discover_clf_transforms())
12501248
>>> sorted( # doctest: +ELLIPSIS
12511249
... unclassify_clf_transforms(clf_transforms), key=lambda x: x.path)[0]
1252-
CLFTransform('utility...OCIO.Utility.AP0_to_AP1-Gamma2.2.clf')
1250+
CLFTransform('input...OCIO.Input.AP0_to_Rec709-sRGB.clf')
12531251
"""
12541252

12551253
unclassified_clf_transforms = []
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright Contributors to the OpenColorIO Project.
33

4-
from .utility import generate_clf
4+
from .utilities import (
5+
create_matrix,
6+
create_conversion_matrix,
7+
create_gamma,
8+
generate_clf,
9+
)
510

6-
__all__ = ["generate_clf"]
11+
__all__ = [
12+
"create_matrix",
13+
"create_conversion_matrix",
14+
"create_gamma",
15+
"generate_clf",
16+
]
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright Contributors to the OpenColorIO Project.
3+
"""
4+
*OpenColorIO* CLF Transforms Generation
5+
=======================================
6+
7+
Defines procedures for generating specific *Common LUT Format* (CLF)
8+
transforms from the OpenColorIO project.
9+
"""
10+
11+
import PyOpenColorIO as ocio
12+
from pathlib import Path
13+
14+
from opencolorio_config_aces.clf import (
15+
create_conversion_matrix,
16+
create_gamma,
17+
generate_clf,
18+
)
19+
20+
__author__ = "OpenColorIO Contributors"
21+
__copyright__ = "Copyright Contributors to the OpenColorIO Project."
22+
__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause"
23+
__maintainer__ = "OpenColorIO Contributors"
24+
__email__ = "ocio-dev@lists.aswf.io"
25+
__status__ = "Production"
26+
27+
__all__ = ["generate_clf_input", "generate_clf_utility"]
28+
29+
THIS_DIR = Path(__file__).parent.resolve()
30+
31+
TF_ID_PREFIX = "urn:aswf:ocio:transformId:1.0:OCIO:"
32+
TF_ID_SUFFIX = ":1.0"
33+
34+
CLF_PREFIX = "OCIO."
35+
CLF_SUFFIX = ".clf"
36+
37+
38+
def generate_clf_input():
39+
"""Generate OCIO Input CLF transforms."""
40+
41+
dest_dir = THIS_DIR / "input"
42+
if not dest_dir.exists():
43+
dest_dir.mkdir()
44+
45+
generate_clf(
46+
ocio.GroupTransform(
47+
transforms=[
48+
create_conversion_matrix("ACES2065-1", "sRGB"),
49+
create_gamma("sRGB"),
50+
]
51+
),
52+
TF_ID_PREFIX + "Input:AP0_to_Rec709-sRGB" + TF_ID_SUFFIX,
53+
"AP0 to Rec.709 - sRGB",
54+
dest_dir / (CLF_PREFIX + "Input.AP0_to_Rec709-sRGB" + CLF_SUFFIX),
55+
"ACES2065-1",
56+
"sRGB",
57+
)
58+
59+
60+
def generate_clf_utility():
61+
"""Generate OCIO Utility CLF transforms."""
62+
63+
dest_dir = THIS_DIR / "utility"
64+
if not dest_dir.exists():
65+
dest_dir.mkdir()
66+
67+
generate_clf(
68+
ocio.GroupTransform(transforms=[create_gamma(2.4)]),
69+
TF_ID_PREFIX + "Utility:Linear_to_Rec1886" + TF_ID_SUFFIX,
70+
"Linear to Rec.1886",
71+
dest_dir / (CLF_PREFIX + "Utility.Linear_to_Rec1886" + CLF_SUFFIX),
72+
"generic linear RGB",
73+
"generic gamma-corrected RGB",
74+
)
75+
76+
generate_clf(
77+
ocio.GroupTransform(transforms=[create_gamma("sRGB")]),
78+
TF_ID_PREFIX + "Utility:Linear_to_sRGB" + TF_ID_SUFFIX,
79+
"Linear to sRGB",
80+
dest_dir / (CLF_PREFIX + "Utility.Linear_to_sRGB" + CLF_SUFFIX),
81+
"generic linear RGB",
82+
"generic gamma-corrected RGB",
83+
)
84+
85+
generate_clf(
86+
ocio.GroupTransform(
87+
transforms=[create_conversion_matrix("ACES2065-1", "P3-D65")]
88+
),
89+
TF_ID_PREFIX + "Utility:AP0_to_P3-D65-Linear" + TF_ID_SUFFIX,
90+
"AP0 to P3-D65 - Linear",
91+
dest_dir / (CLF_PREFIX + "Utility.AP0_to_P3-D65-Linear" + CLF_SUFFIX),
92+
"ACES2065-1",
93+
"linear P3 primaries, D65 white point",
94+
)
95+
96+
generate_clf(
97+
ocio.GroupTransform(
98+
transforms=[
99+
create_conversion_matrix("ACES2065-1", "ITU-R BT.2020")
100+
]
101+
),
102+
TF_ID_PREFIX + "Utility:AP0_to_Rec2020-Linear" + TF_ID_SUFFIX,
103+
"AP0 to Rec.2020 - Linear",
104+
dest_dir / (CLF_PREFIX + "Utility.AP0_to_Rec2020-Linear" + CLF_SUFFIX),
105+
"ACES2065-1",
106+
"linear Rec.2020 primaries, D65 white point",
107+
)
108+
109+
generate_clf(
110+
ocio.GroupTransform(
111+
transforms=[create_conversion_matrix("ACES2065-1", "ITU-R BT.709")]
112+
),
113+
TF_ID_PREFIX + "Utility:AP0_to_Rec709-Linear" + TF_ID_SUFFIX,
114+
"AP0 to Rec.709 - Linear",
115+
dest_dir / (CLF_PREFIX + "Utility.AP0_to_Rec709-Linear" + CLF_SUFFIX),
116+
"ACES2065-1",
117+
"linear Rec.709 primaries, D65 white point",
118+
)
119+
120+
generate_clf(
121+
ocio.GroupTransform(
122+
transforms=[
123+
create_conversion_matrix("ACES2065-1", "ITU-R BT.709"),
124+
create_gamma(1.8),
125+
]
126+
),
127+
TF_ID_PREFIX + "Utility:AP0_to_Rec709-Gamma1.8" + TF_ID_SUFFIX,
128+
"AP0 to Rec.709 - Gamma 1.8",
129+
dest_dir
130+
/ (CLF_PREFIX + "Utility.AP0_to_Rec709-Gamma1.8" + CLF_SUFFIX),
131+
"ACES2065-1",
132+
"1.8 gamma-corrected Rec.709 primaries, D65 white point",
133+
)
134+
135+
generate_clf(
136+
ocio.GroupTransform(
137+
transforms=[
138+
create_conversion_matrix("ACES2065-1", "ITU-R BT.709"),
139+
create_gamma(2.2),
140+
]
141+
),
142+
TF_ID_PREFIX + "Utility:AP0_to_Rec709-Gamma2.2" + TF_ID_SUFFIX,
143+
"AP0 to Rec.709 - Gamma 2.2",
144+
dest_dir
145+
/ (CLF_PREFIX + "Utility.AP0_to_Rec709-Gamma2.2" + CLF_SUFFIX),
146+
"ACES2065-1",
147+
"2.2 gamma-corrected Rec.709 primaries, D65 white point",
148+
)
149+
150+
generate_clf(
151+
ocio.GroupTransform(
152+
transforms=[
153+
create_conversion_matrix("ACES2065-1", "ITU-R BT.709"),
154+
create_gamma(2.4),
155+
]
156+
),
157+
TF_ID_PREFIX + "Utility:AP0_to_Rec709-Gamma2.4" + TF_ID_SUFFIX,
158+
"AP0 to Rec.709 - Gamma 2.4",
159+
dest_dir
160+
/ (CLF_PREFIX + "Utility.AP0_to_Rec709-Gamma2.4" + CLF_SUFFIX),
161+
"ACES2065-1",
162+
"2.4 gamma-corrected Rec.709 primaries, D65 white point",
163+
)
164+
165+
generate_clf(
166+
ocio.GroupTransform(
167+
transforms=[
168+
create_conversion_matrix("ACES2065-1", "ACEScg"),
169+
create_gamma(2.2),
170+
]
171+
),
172+
TF_ID_PREFIX + "Utility:AP0_to_AP1-Gamma2.2" + TF_ID_SUFFIX,
173+
"AP0 to AP1 - Gamma 2.2",
174+
dest_dir / (CLF_PREFIX + "Utility.AP0_to_AP1-Gamma2.2" + CLF_SUFFIX),
175+
"ACES2065-1",
176+
"2.2 gamma-corrected AP1 primaries, D60 white point",
177+
)
178+
179+
180+
if __name__ == "__main__":
181+
generate_clf_input()
182+
generate_clf_utility()

opencolorio_config_aces/clf/transforms/ocio/utility/OCIO.Utility.AP0_to_Rec709-sRGB.clf renamed to opencolorio_config_aces/clf/transforms/ocio/input/OCIO.Input.AP0_to_Rec709-sRGB.clf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<ProcessList compCLFversion="3" id="urn:aswf:ocio:transformId:1.0:OCIO:Utility:AP0_to_Rec709-sRGB:1.0" name="AP0 to Rec.709 - sRGB">
2+
<ProcessList compCLFversion="3" id="urn:aswf:ocio:transformId:1.0:OCIO:Input:AP0_to_Rec709-sRGB:1.0" name="AP0 to Rec.709 - sRGB">
33
<InputDescriptor>ACES2065-1</InputDescriptor>
44
<OutputDescriptor>sRGB</OutputDescriptor>
55
<Matrix inBitDepth="32f" outBitDepth="32f">

0 commit comments

Comments
 (0)