|
| 1 | +# SPDX-License-Identifier: BSD-3-Clause |
| 2 | +# Copyright Contributors to the OpenColorIO Project. |
| 3 | +""" |
| 4 | +*Sony* CLF Transforms Generation |
| 5 | +================================ |
| 6 | +
|
| 7 | +Defines procedures for generating Sony *Common LUT Format* (CLF) |
| 8 | +transforms for 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 | + generate_clf, |
| 17 | +) |
| 18 | + |
| 19 | +__author__ = "OpenColorIO Contributors" |
| 20 | +__copyright__ = "Copyright Contributors to the OpenColorIO Project." |
| 21 | +__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause" |
| 22 | +__maintainer__ = "OpenColorIO Contributors" |
| 23 | +__email__ = "ocio-dev@lists.aswf.io" |
| 24 | +__status__ = "Production" |
| 25 | + |
| 26 | +__all__ = [ |
| 27 | + "generate_sony", |
| 28 | +] |
| 29 | + |
| 30 | +DEST_DIR = Path(__file__).parent.resolve() / "input" |
| 31 | + |
| 32 | +TF_ID_PREFIX = "urn:aswf:ocio:transformId:1.0:" |
| 33 | +TF_ID_SUFFIX = ":1.0" |
| 34 | + |
| 35 | +CLF_SUFFIX = ".clf" |
| 36 | + |
| 37 | + |
| 38 | +def _build_slog3_curve(): |
| 39 | + """Build the Log transform for the S-Log3 curve.""" |
| 40 | + linSideSlope = 1.0 / (0.18 + 0.01) |
| 41 | + linSideOffset = 0.01 / (0.18 + 0.01) |
| 42 | + logSideSlope = 261.5 / 1023.0 |
| 43 | + logSideOffset = 420.0 / 1023.0 |
| 44 | + linSideBreak = 0.01125000 |
| 45 | + linearSlope = ((171.2102946929 - 95.0) / 0.01125000) / 1023.0 |
| 46 | + base = 10.0 |
| 47 | + |
| 48 | + lct = ocio.LogCameraTransform( |
| 49 | + base=base, |
| 50 | + linSideBreak=[linSideBreak] * 3, |
| 51 | + logSideSlope=[logSideSlope] * 3, |
| 52 | + logSideOffset=[logSideOffset] * 3, |
| 53 | + linSideSlope=[linSideSlope] * 3, |
| 54 | + linSideOffset=[linSideOffset] * 3, |
| 55 | + linearSlope=[linearSlope] * 3, |
| 56 | + direction=ocio.TRANSFORM_DIR_INVERSE, |
| 57 | + ) |
| 58 | + return lct |
| 59 | + |
| 60 | + |
| 61 | +def _build_sgamut3_mtx(): |
| 62 | + """Build the Matrix transform for the S-Gamut3 primaries.""" |
| 63 | + mtx = create_conversion_matrix("S-Gamut3", "ACES2065-1", "CAT02") |
| 64 | + return mtx |
| 65 | + |
| 66 | + |
| 67 | +def _build_sgamut3_cine_mtx(): |
| 68 | + """Build the Matrix transform for the S-Gamut3.Cine primaries.""" |
| 69 | + mtx = create_conversion_matrix("S-Gamut3.Cine", "ACES2065-1", "CAT02") |
| 70 | + return mtx |
| 71 | + |
| 72 | + |
| 73 | +def _build_venice_sgamut3_mtx(): |
| 74 | + """Build the Matrix transform for the Venice S-Gamut3 primaries.""" |
| 75 | + mtx = create_conversion_matrix("Venice S-Gamut3", "ACES2065-1", "CAT02") |
| 76 | + return mtx |
| 77 | + |
| 78 | + |
| 79 | +def _build_venice_sgamut3_cine_mtx(): |
| 80 | + """Build the Matrix transform for the Venice S-Gamut3.Cine primaries.""" |
| 81 | + mtx = create_conversion_matrix( |
| 82 | + "Venice S-Gamut3.Cine", "ACES2065-1", "CAT02" |
| 83 | + ) |
| 84 | + return mtx |
| 85 | + |
| 86 | + |
| 87 | +def generate_sony(): |
| 88 | + """Make all the Sony CLFs.""" |
| 89 | + |
| 90 | + if not DEST_DIR.exists(): |
| 91 | + DEST_DIR.mkdir() |
| 92 | + |
| 93 | + # The full transforms generated here were developed in collaboration with Sony. |
| 94 | + |
| 95 | + # Generate full S-Log3 - S-Gamut3 transform. |
| 96 | + |
| 97 | + generate_clf( |
| 98 | + ocio.GroupTransform( |
| 99 | + transforms=[ |
| 100 | + _build_slog3_curve(), |
| 101 | + _build_sgamut3_mtx(), |
| 102 | + ] |
| 103 | + ), |
| 104 | + TF_ID_PREFIX + "Sony:Input:SLog3_SGamut3_to_ACES2065-1" + TF_ID_SUFFIX, |
| 105 | + "Sony S-Log3 S-Gamut3 to ACES2065-1", |
| 106 | + DEST_DIR / ("SLog3-SGamut3_to_ACES2065-1" + CLF_SUFFIX), |
| 107 | + "Sony S-Log3 S-Gamut3", |
| 108 | + "ACES2065-1", |
| 109 | + "urn:ampas:aces:transformId:v1.5:IDT.Sony.SLog3_SGamut3.a1.v1", |
| 110 | + ) |
| 111 | + |
| 112 | + # Generate the Linear S-Gamut3 transform. |
| 113 | + |
| 114 | + generate_clf( |
| 115 | + ocio.GroupTransform([_build_sgamut3_mtx()]), |
| 116 | + TF_ID_PREFIX |
| 117 | + + "Sony:Input:Linear_SGamut3_to_ACES2065-1" |
| 118 | + + TF_ID_SUFFIX, |
| 119 | + "Linear S-Gamut3 to ACES2065-1", |
| 120 | + DEST_DIR / ("Linear-SGamut3_to_ACES2065-1" + CLF_SUFFIX), |
| 121 | + "Linear S-Gamut3", |
| 122 | + "ACES2065-1", |
| 123 | + None, |
| 124 | + ) |
| 125 | + |
| 126 | + # Generate full S-Log3 - S-Gamut3.Cine transform. |
| 127 | + |
| 128 | + generate_clf( |
| 129 | + ocio.GroupTransform( |
| 130 | + transforms=[ |
| 131 | + _build_slog3_curve(), |
| 132 | + _build_sgamut3_cine_mtx(), |
| 133 | + ] |
| 134 | + ), |
| 135 | + TF_ID_PREFIX |
| 136 | + + "Sony:Input:SLog3_SGamut3Cine_to_ACES2065-1" |
| 137 | + + TF_ID_SUFFIX, |
| 138 | + "Sony S-Log3 S-Gamut3.Cine to ACES2065-1", |
| 139 | + DEST_DIR / ("SLog3-SGamut3Cine_to_ACES2065-1" + CLF_SUFFIX), |
| 140 | + "Sony S-Log3 S-Gamut3.Cine", |
| 141 | + "ACES2065-1", |
| 142 | + "urn:ampas:aces:transformId:v1.5:IDT.Sony.SLog3_SGamut3Cine.a1.v1", |
| 143 | + ) |
| 144 | + |
| 145 | + # Generate the Linear S-Gamut3.Cine transform. |
| 146 | + |
| 147 | + generate_clf( |
| 148 | + ocio.GroupTransform([_build_sgamut3_cine_mtx()]), |
| 149 | + TF_ID_PREFIX |
| 150 | + + "Sony:Input:Linear_SGamut3Cine_to_ACES2065-1" |
| 151 | + + TF_ID_SUFFIX, |
| 152 | + "Linear S-Gamut3.Cine to ACES2065-1", |
| 153 | + DEST_DIR / ("Linear-SGamut3Cine_to_ACES2065-1" + CLF_SUFFIX), |
| 154 | + "Linear S-Gamut3.Cine", |
| 155 | + "ACES2065-1", |
| 156 | + None, |
| 157 | + ) |
| 158 | + |
| 159 | + # Generate full Venice S-Log3 - S-Gamut3 transform. |
| 160 | + |
| 161 | + generate_clf( |
| 162 | + ocio.GroupTransform( |
| 163 | + transforms=[ |
| 164 | + _build_slog3_curve(), |
| 165 | + _build_venice_sgamut3_mtx(), |
| 166 | + ] |
| 167 | + ), |
| 168 | + TF_ID_PREFIX |
| 169 | + + "Sony:Input:Venice_SLog3_SGamut3_to_ACES2065-1" |
| 170 | + + TF_ID_SUFFIX, |
| 171 | + "Sony Venice S-Log3 S-Gamut3 to ACES2065-1", |
| 172 | + DEST_DIR / ("Venice-SLog3-SGamut3_to_ACES2065-1" + CLF_SUFFIX), |
| 173 | + "Sony Venice S-Log3 S-Gamut3", |
| 174 | + "ACES2065-1", |
| 175 | + "urn:ampas:aces:transformId:v1.5:IDT.Sony.Venice_SLog3_SGamut3.a1.v1", |
| 176 | + ) |
| 177 | + |
| 178 | + # Generate the Linear Venice S-Gamut3 transform. |
| 179 | + |
| 180 | + generate_clf( |
| 181 | + ocio.GroupTransform([_build_venice_sgamut3_cine_mtx()]), |
| 182 | + TF_ID_PREFIX |
| 183 | + + "Sony:Input:Linear_Venice_SGamut3_to_ACES2065-1" |
| 184 | + + TF_ID_SUFFIX, |
| 185 | + "Linear Venice S-Gamut3 to ACES2065-1", |
| 186 | + DEST_DIR / ("Linear-Venice-SGamut3_to_ACES2065-1" + CLF_SUFFIX), |
| 187 | + "Linear Venice S-Gamut3", |
| 188 | + "ACES2065-1", |
| 189 | + None, |
| 190 | + ) |
| 191 | + |
| 192 | + # Generate full Venice S-Log3 - S-Gamut3.Cine transform. |
| 193 | + |
| 194 | + generate_clf( |
| 195 | + ocio.GroupTransform( |
| 196 | + transforms=[ |
| 197 | + _build_slog3_curve(), |
| 198 | + _build_venice_sgamut3_cine_mtx(), |
| 199 | + ] |
| 200 | + ), |
| 201 | + TF_ID_PREFIX |
| 202 | + + "Sony:Input:Venice_SLog3_SGamut3Cine_to_ACES2065-1" |
| 203 | + + TF_ID_SUFFIX, |
| 204 | + "Sony Venice S-Log3 S-Gamut3.Cine to ACES2065-1", |
| 205 | + DEST_DIR / ("Venice-SLog3-SGamut3Cine_to_ACES2065-1" + CLF_SUFFIX), |
| 206 | + "Sony Venice S-Log3 S-Gamut3.Cine", |
| 207 | + "ACES2065-1", |
| 208 | + "urn:ampas:aces:transformId:v1.5:IDT.Sony.Venice_SLog3_SGamut3Cine.a1.v1", |
| 209 | + ) |
| 210 | + |
| 211 | + # Generate the Linear Venice S-Gamut3.Cine transform. |
| 212 | + |
| 213 | + generate_clf( |
| 214 | + ocio.GroupTransform([_build_venice_sgamut3_cine_mtx()]), |
| 215 | + TF_ID_PREFIX |
| 216 | + + "Sony:Input:Linear_Venice_SGamut3Cine_to_ACES2065-1" |
| 217 | + + TF_ID_SUFFIX, |
| 218 | + "Linear Venice S-Gamut3.Cine to ACES2065-1", |
| 219 | + DEST_DIR / ("Linear-Venice-SGamut3Cine_to_ACES2065-1" + CLF_SUFFIX), |
| 220 | + "Linear Venice S-Gamut3.Cine", |
| 221 | + "ACES2065-1", |
| 222 | + None, |
| 223 | + ) |
| 224 | + |
| 225 | + # Generate named transform for S-Log3 curve only. |
| 226 | + |
| 227 | + generate_clf( |
| 228 | + ocio.GroupTransform([_build_slog3_curve()]), |
| 229 | + TF_ID_PREFIX + "Sony:Input:SLog3_Log_to_Linear" + TF_ID_SUFFIX, |
| 230 | + "S-Log3 Log to Linear Curve", |
| 231 | + DEST_DIR / ("SLog3-Curve" + CLF_SUFFIX), |
| 232 | + "S-Log3 Log (arbitrary primaries)", |
| 233 | + "S-Log3 Linear (arbitrary primaries)", |
| 234 | + None, |
| 235 | + ) |
| 236 | + |
| 237 | + return 0 |
| 238 | + |
| 239 | + |
| 240 | +if __name__ == "__main__": |
| 241 | + import sys |
| 242 | + |
| 243 | + sys.exit(generate_sony()) |
0 commit comments