|
3 | 3 | ====== |
4 | 4 | """ |
5 | 5 |
|
| 6 | +from io import StringIO |
6 | 7 | from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS |
7 | 8 | from colour.colorimetry import CCS_ILLUMINANTS |
| 9 | +from colour.io import LUTOperatorMatrix, write_LUT_SonySPImtx |
8 | 10 | from colour.models import RGB_COLOURSPACES |
9 | 11 | from colour.utilities import as_float_array |
10 | 12 |
|
|
18 | 20 | __status__ = "Production" |
19 | 21 |
|
20 | 22 | __all__ = [ |
21 | | - "RGB_COLOURSPACE_OPTIONS", |
22 | | - "CHROMATIC_ADAPTATION_TRANSFORM_OPTIONS", |
23 | | - "ILLUMINANTS_OPTIONS", |
24 | | - "NUKE_COLORMATRIX_NODE_TEMPLATE", |
| 23 | + "OPTIONS_RGB_COLOURSPACE", |
| 24 | + "OPTIONS_CHROMATIC_ADAPTATION_TRANSFORM", |
| 25 | + "OPTIONS_ILLUMINANTS", |
| 26 | + "TEMPLATE_NUKE_NODE_COLORMATRIX", |
25 | 27 | "nuke_format_matrix", |
| 28 | + "spimtx_format_matrix", |
| 29 | + "TEMPLATE_OCIO_COLORSPACE", |
| 30 | + "matrix_3x3_to_4x4", |
26 | 31 | ] |
27 | 32 |
|
28 | | -RGB_COLOURSPACE_OPTIONS: List[Dict] = [ |
| 33 | +OPTIONS_RGB_COLOURSPACE: List[Dict] = [ |
29 | 34 | {"label": key, "value": key} |
30 | 35 | for key in sorted(RGB_COLOURSPACES.keys()) |
31 | 36 | if key not in ("aces", "adobe1998", "prophoto") |
|
34 | 39 | *RGB* colourspace options for a :class:`Dropdown` class instance. |
35 | 40 | """ |
36 | 41 |
|
37 | | -CHROMATIC_ADAPTATION_TRANSFORM_OPTIONS: List[Dict] = [ |
| 42 | +OPTIONS_CHROMATIC_ADAPTATION_TRANSFORM: List[Dict] = [ |
38 | 43 | {"label": key, "value": key} |
39 | 44 | for key in sorted(CHROMATIC_ADAPTATION_TRANSFORMS.keys()) |
40 | 45 | ] |
|
43 | 48 | instance. |
44 | 49 | """ |
45 | 50 |
|
46 | | -ILLUMINANTS_OPTIONS: List[Dict] = [ |
| 51 | +OPTIONS_ILLUMINANTS: List[Dict] = [ |
47 | 52 | {"label": key, "value": key} |
48 | 53 | for key in sorted( |
49 | 54 | CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"].keys() |
|
54 | 59 | :class:`Dropdown`class instance. |
55 | 60 | """ |
56 | 61 |
|
57 | | -NUKE_COLORMATRIX_NODE_TEMPLATE: str = """ |
| 62 | +TEMPLATE_NUKE_NODE_COLORMATRIX: str = """ |
58 | 63 | ColorMatrix {{ |
59 | 64 | inputs 0 |
60 | 65 | matrix {{ |
61 | | - {0} |
| 66 | + {matrix} |
62 | 67 | }} |
63 | | - name "{1}" |
| 68 | + name "{name}" |
64 | 69 | selected true |
65 | 70 | xpos 0 |
66 | 71 | ypos 0 |
@@ -102,3 +107,74 @@ def pretty(x: Iterable) -> str: |
102 | 107 | tcl += f" {{{pretty(M[2])}}}" |
103 | 108 |
|
104 | 109 | return tcl |
| 110 | + |
| 111 | + |
| 112 | +def spimtx_format_matrix(M: ArrayLike, decimals: int = 10) -> str: |
| 113 | + """ |
| 114 | + Format given matrix as a *Sony* *.spimtx* *LUT* formatted matrix. |
| 115 | +
|
| 116 | + Parameters |
| 117 | + ---------- |
| 118 | + M |
| 119 | + Matrix to format. |
| 120 | + decimals |
| 121 | + Decimals to use when formatting the matrix. |
| 122 | +
|
| 123 | + Returns |
| 124 | + ------- |
| 125 | + :class:`str` |
| 126 | + *Sony* *.spimtx* *LUT* formatted matrix. |
| 127 | + """ |
| 128 | + |
| 129 | + string = StringIO() |
| 130 | + |
| 131 | + write_LUT_SonySPImtx(LUTOperatorMatrix(M), string, decimals) |
| 132 | + |
| 133 | + return string.getvalue() |
| 134 | + |
| 135 | + |
| 136 | +TEMPLATE_OCIO_COLORSPACE = """ |
| 137 | + - !<ColorSpace> |
| 138 | + name: Linear {name} |
| 139 | + aliases: [] |
| 140 | + family: Utility |
| 141 | + equalitygroup: "" |
| 142 | + bitdepth: 32f |
| 143 | + description: | |
| 144 | + Convert from {input_colourspace} to Linear {output_colourspace} |
| 145 | + isdata: false |
| 146 | + encoding: scene-linear |
| 147 | + allocation: uniform |
| 148 | + from_scene_reference: !<GroupTransform> |
| 149 | + name: {input_colourspace} to Linear {output_colourspace} |
| 150 | + children: |
| 151 | + - !<MatrixTransform> {{matrix: {matrix}}} |
| 152 | +"""[ |
| 153 | + 1: |
| 154 | +] |
| 155 | +""" |
| 156 | +*OpenColorIO* *ColorSpace* template. |
| 157 | +""" |
| 158 | + |
| 159 | + |
| 160 | +def matrix_3x3_to_4x4(M): |
| 161 | + """ |
| 162 | + Convert given 3x3 matrix :math:`M` to a raveled 4x4 matrix. |
| 163 | +
|
| 164 | + Parameters |
| 165 | + ---------- |
| 166 | + M : array_like |
| 167 | + 3x3 matrix :math:`M` to convert. |
| 168 | +
|
| 169 | + Returns |
| 170 | + ------- |
| 171 | + list |
| 172 | + Raveled 4x4 matrix. |
| 173 | + """ |
| 174 | + |
| 175 | + import numpy as np |
| 176 | + |
| 177 | + M_I = np.identity(4) |
| 178 | + M_I[:3, :3] = M |
| 179 | + |
| 180 | + return np.ravel(M_I) |
0 commit comments