|
| 1 | +# SPDX-License-Identifier: BSD-3-Clause |
| 2 | +# Copyright Contributors to the OpenColorIO Project. |
| 3 | +""" |
| 4 | +*Canon* CLF Transforms Generation |
| 5 | +=============================== |
| 6 | +
|
| 7 | +Defines procedures for generating Canon *Common LUT Format* (CLF) |
| 8 | +transforms: |
| 9 | +
|
| 10 | +- :func:`opencolorio_config_aces.clf.generate_clf_transforms_canon` |
| 11 | +""" |
| 12 | + |
| 13 | +import PyOpenColorIO as ocio |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | +from opencolorio_config_aces.clf.transforms import ( |
| 17 | + clf_basename, |
| 18 | + format_clf_transform_id, |
| 19 | + generate_clf_transform, |
| 20 | + matrix_RGB_to_RGB_transform, |
| 21 | +) |
| 22 | +from opencolorio_config_aces.config import transform_factory |
| 23 | + |
| 24 | +__author__ = "OpenColorIO Contributors" |
| 25 | +__copyright__ = "Copyright Contributors to the OpenColorIO Project." |
| 26 | +__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause" |
| 27 | +__maintainer__ = "OpenColorIO Contributors" |
| 28 | + |
| 29 | +__status__ = "Production" |
| 30 | + |
| 31 | +__all__ = [ |
| 32 | + "FAMILY", |
| 33 | + "GENUS", |
| 34 | + "VERSION", |
| 35 | + "generate_clf_transforms_canon", |
| 36 | +] |
| 37 | + |
| 38 | +FAMILY = "Canon" |
| 39 | +""" |
| 40 | +*CLF* transforms family. |
| 41 | +""" |
| 42 | + |
| 43 | +GENUS = "Input" |
| 44 | +""" |
| 45 | +*CLF* transforms genus. |
| 46 | +""" |
| 47 | + |
| 48 | +VERSION = "1.0" |
| 49 | +""" |
| 50 | +*CLF* transforms version. |
| 51 | +""" |
| 52 | + |
| 53 | + |
| 54 | +def generate_clf_transforms_canon(output_directory): |
| 55 | + """ |
| 56 | + Make the CLF file for Canon C-Log3 Cinema Gamut plus matrix/curve CLFs. |
| 57 | +
|
| 58 | + Returns |
| 59 | + ------- |
| 60 | + dict |
| 61 | + Dictionary of *CLF* transforms and *OpenColorIO* `GroupTransform` |
| 62 | + instances. |
| 63 | +
|
| 64 | + References |
| 65 | + ---------- |
| 66 | + - Canon. (2018). White Paper on Canon Log. |
| 67 | + Retrieved September 22, 2022, from http://downloads.canon.com/nw/learn/\ |
| 68 | +white-papers/cinema-eos/white-paper-canon-log-gamma-curves.pdf |
| 69 | +
|
| 70 | + Notes |
| 71 | + ----- |
| 72 | + - The resulting *CLF* transforms were reviewed by *Canon*. |
| 73 | + """ |
| 74 | + |
| 75 | + output_directory.mkdir(parents=True, exist_ok=True) |
| 76 | + |
| 77 | + clf_transforms = {} |
| 78 | + |
| 79 | + bt = ocio.BuiltinTransform(style="CANON_CLOG3-CGAMUT_to_ACES2065-1") |
| 80 | + |
| 81 | + mtx = matrix_RGB_to_RGB_transform( |
| 82 | + "Cinema Gamut", "ACES2065-1", "CAT02" |
| 83 | + ) |
| 84 | + |
| 85 | + aces_transform_id = ( |
| 86 | + "urn:ampas:aces:transformId:v1.5:" |
| 87 | + "ACEScsc.Academy.CLog3_CGamut_to_ACES.a1.1.0" |
| 88 | + ) |
| 89 | + |
| 90 | + # Generate full transform. |
| 91 | + # NB: This is being saved in CTF format to allow us of a Built-in Transform |
| 92 | + # and thus avoid the need for an external LUT file. |
| 93 | + |
| 94 | + name = "CanonLog3_CinemaGamut-D55_to_ACES2065-1" |
| 95 | + input_descriptor = "Canon Log 3 Cinema Gamut (Daylight)" |
| 96 | + output_descriptor = "ACES2065-1" |
| 97 | + clf_transform_id = format_clf_transform_id(FAMILY, GENUS, name, VERSION) |
| 98 | + filename = output_directory / clf_basename(clf_transform_id) |
| 99 | + clf_transforms[filename] = generate_clf_transform( |
| 100 | + filename, |
| 101 | + [bt], |
| 102 | + clf_transform_id, |
| 103 | + f"{input_descriptor} to {output_descriptor}", |
| 104 | + input_descriptor, |
| 105 | + output_descriptor, |
| 106 | + aces_transform_id, |
| 107 | + ) |
| 108 | + |
| 109 | + # Generate transform for primaries only. |
| 110 | + |
| 111 | + name = "Linear-CinemaGamut-D55_to_ACES2065-1" |
| 112 | + input_descriptor = "Linear Canon Cinema Gamut (Daylight)" |
| 113 | + output_descriptor = "ACES2065-1" |
| 114 | + clf_transform_id = format_clf_transform_id(FAMILY, GENUS, name, VERSION) |
| 115 | + filename = output_directory / clf_basename(clf_transform_id) |
| 116 | + clf_transforms[filename] = generate_clf_transform( |
| 117 | + filename, |
| 118 | + [mtx], |
| 119 | + clf_transform_id, |
| 120 | + f"{input_descriptor} to {output_descriptor}", |
| 121 | + input_descriptor, |
| 122 | + output_descriptor, |
| 123 | + ) |
| 124 | + |
| 125 | + # Generate `NamedTransform` for log curve only. |
| 126 | + |
| 127 | + # TODO: This will have to wait for OCIO 2.2 in order to do this without |
| 128 | + # requiring an external LUT file. |
| 129 | + |
| 130 | + return clf_transforms |
| 131 | + |
| 132 | + |
| 133 | +if __name__ == "__main__": |
| 134 | + import logging |
| 135 | + |
| 136 | + logging.basicConfig() |
| 137 | + logging.getLogger().setLevel(logging.INFO) |
| 138 | + |
| 139 | + output_directory = Path(__file__).parent.resolve() / "input" |
| 140 | + |
| 141 | + generate_clf_transforms_canon(output_directory) |
0 commit comments