|
25 | 25 |
|
26 | 26 | __all__ = [ |
27 | 27 | 'create_matrix_colorspace', 'create_transfer_colorspace', |
28 | | - 'create_matrix_plus_transfer_colorspace', 'linear_to_sRGB', |
29 | | - 'sRGB_to_linear', 'linear_to_Rec709', 'Rec709_to_linear', |
30 | | - 'linear_to_Rec2020_10bit', 'Rec2020_10bit_to_linear', |
31 | | - 'linear_to_Rec2020_12bit', 'Rec2020_12bit_to_linear', 'linear_to_Rec1886', |
32 | | - 'Rec1886_to_linear', 'create_colorspaces', 'create_raw' |
| 28 | + 'create_matrix_plus_transfer_colorspace', 'create_gamma_colorspace', |
| 29 | + 'create_matrix_plus_gamma_colorspace', 'linear_to_sRGB', 'sRGB_to_linear', |
| 30 | + 'linear_to_Rec709', 'Rec709_to_linear', 'linear_to_Rec2020_10bit', |
| 31 | + 'Rec2020_10bit_to_linear', 'linear_to_Rec2020_12bit', |
| 32 | + 'Rec2020_12bit_to_linear', 'linear_to_Rec1886', 'Rec1886_to_linear', |
| 33 | + 'create_colorspaces', 'create_raw' |
33 | 34 | ] |
34 | 35 |
|
35 | 36 |
|
@@ -297,6 +298,151 @@ def create_matrix_plus_transfer_colorspace( |
297 | 298 | return cs |
298 | 299 |
|
299 | 300 |
|
| 301 | +# ------------------------------------------------------------------------- |
| 302 | +# *Gamma Function Transform* |
| 303 | +# ------------------------------------------------------------------------- |
| 304 | +def create_gamma_colorspace(name='gamma', gamma_value=1.0, aliases=None): |
| 305 | + """ |
| 306 | + Creates a colorspace expressed as an *ExponentTransform* transformation. |
| 307 | +
|
| 308 | + Parameters |
| 309 | + ---------- |
| 310 | + name : str, optional |
| 311 | + Aliases for this colorspace. |
| 312 | + gamma_value : function, optional |
| 313 | + The gamma value. |
| 314 | + aliases : list of str |
| 315 | + Aliases for this colorspace. |
| 316 | +
|
| 317 | + Returns |
| 318 | + ------- |
| 319 | + ColorSpace |
| 320 | + A colorspace expressed as an *ExponentTransform* transformation. |
| 321 | + """ |
| 322 | + |
| 323 | + if aliases is None: |
| 324 | + aliases = [] |
| 325 | + |
| 326 | + cs = ColorSpace(name) |
| 327 | + cs.description = 'The {0} color space'.format(name) |
| 328 | + cs.aliases = aliases |
| 329 | + cs.equality_group = name |
| 330 | + cs.family = 'Utility' |
| 331 | + cs.is_data = False |
| 332 | + |
| 333 | + # A linear space needs allocation variables. |
| 334 | + cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM |
| 335 | + cs.allocation_vars = [0, 1] |
| 336 | + |
| 337 | + # Creating the *to_reference* transforms. |
| 338 | + cs.to_reference_transforms = [] |
| 339 | + cs.to_reference_transforms.append({ |
| 340 | + 'type': |
| 341 | + 'exponent', |
| 342 | + 'value': [gamma_value, gamma_value, gamma_value, 1] |
| 343 | + }) |
| 344 | + |
| 345 | + # Creating the *from_reference* transforms. |
| 346 | + cs.from_reference_transforms = [] |
| 347 | + |
| 348 | + return cs |
| 349 | + |
| 350 | + |
| 351 | +# ------------------------------------------------------------------------- |
| 352 | +# *Gamma Function + Matrix Transform* |
| 353 | +# ------------------------------------------------------------------------- |
| 354 | +def create_matrix_plus_gamma_colorspace(name='matrix_plus_gamma', |
| 355 | + gamma_value=1.0, |
| 356 | + from_reference_values=None, |
| 357 | + to_reference_values=None, |
| 358 | + aliases=None): |
| 359 | + """ |
| 360 | + Creates a colorspace expressed as a single or multiple *MatrixTransform* |
| 361 | + and an *ExponentTransform* transformations. |
| 362 | +
|
| 363 | + Parameters |
| 364 | + ---------- |
| 365 | + name : str, optional |
| 366 | + Aliases for this colorspace. |
| 367 | + gamma_value : function, optional |
| 368 | + The gamma value. |
| 369 | + from_reference_values : list of matrices |
| 370 | + List of matrices to convert from the reference colorspace to this |
| 371 | + colorspace. |
| 372 | + to_reference_values : list of matrices |
| 373 | + List of matrices to convert to the reference colorspace from this |
| 374 | + colorspace. |
| 375 | + aliases : list of str |
| 376 | + Aliases for this colorspace. |
| 377 | +
|
| 378 | + Returns |
| 379 | + ------- |
| 380 | + ColorSpace |
| 381 | + A colorspace expressed as a single or multiple *MatrixTransform* and an |
| 382 | + *ExponentTransform* transformations. |
| 383 | + """ |
| 384 | + |
| 385 | + if from_reference_values is None: |
| 386 | + from_reference_values = [] |
| 387 | + |
| 388 | + if to_reference_values is None: |
| 389 | + to_reference_values = [] |
| 390 | + |
| 391 | + if aliases is None: |
| 392 | + aliases = [] |
| 393 | + |
| 394 | + cs = ColorSpace(name) |
| 395 | + cs.description = 'The {0} color space'.format(name) |
| 396 | + cs.aliases = aliases |
| 397 | + cs.equality_group = name |
| 398 | + cs.family = 'Utility' |
| 399 | + cs.is_data = False |
| 400 | + |
| 401 | + cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM |
| 402 | + cs.allocation_vars = [0, 1] |
| 403 | + |
| 404 | + # Creating the *to_reference* transforms. |
| 405 | + cs.to_reference_transforms = [] |
| 406 | + if to_reference_values: |
| 407 | + cs.to_reference_transforms.append({ |
| 408 | + 'type': |
| 409 | + 'exponent', |
| 410 | + 'value': [gamma_value, gamma_value, gamma_value, 1] |
| 411 | + }) |
| 412 | + |
| 413 | + for matrix in to_reference_values: |
| 414 | + cs.to_reference_transforms.append({ |
| 415 | + 'type': |
| 416 | + 'matrix', |
| 417 | + 'matrix': |
| 418 | + mat44_from_mat33(matrix), |
| 419 | + 'direction': |
| 420 | + 'forward' |
| 421 | + }) |
| 422 | + |
| 423 | + # Creating the *from_reference* transforms. |
| 424 | + cs.from_reference_transforms = [] |
| 425 | + if from_reference_values: |
| 426 | + for matrix in from_reference_values: |
| 427 | + cs.from_reference_transforms.append({ |
| 428 | + 'type': |
| 429 | + 'matrix', |
| 430 | + 'matrix': |
| 431 | + mat44_from_mat33(matrix), |
| 432 | + 'direction': |
| 433 | + 'forward' |
| 434 | + }) |
| 435 | + |
| 436 | + cs.from_reference_transforms.append({ |
| 437 | + 'type': |
| 438 | + 'exponent', |
| 439 | + 'value': |
| 440 | + [1.0 / gamma_value, 1.0 / gamma_value, 1.0 / gamma_value, 1] |
| 441 | + }) |
| 442 | + |
| 443 | + return cs |
| 444 | + |
| 445 | + |
300 | 446 | # Transfer functions for standard colorspaces. |
301 | 447 | def linear_to_sRGB(L): |
302 | 448 | """ |
@@ -686,6 +832,26 @@ def create_colorspaces(lut_directory, lut_resolution_1D=1024): |
686 | 832 | aliases=['rec709_camera']) |
687 | 833 | colorspaces.append(cs) |
688 | 834 |
|
| 835 | + # *ACES* to *Rec.709* Primaries + Gamma 2.2* |
| 836 | + cs = create_matrix_plus_gamma_colorspace( |
| 837 | + 'Gamma 2.2 - Rec.709 - Texture', |
| 838 | + 2.2, |
| 839 | + from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709], |
| 840 | + aliases=['g22_rec709']) |
| 841 | + cs.description = ( |
| 842 | + 'The Gamma 2.2 - Rec.709 color space for importing certain textures.') |
| 843 | + colorspaces.append(cs) |
| 844 | + |
| 845 | + # *ACES* to *Rec.709* Primaries + Gamma 1.8* |
| 846 | + cs = create_matrix_plus_gamma_colorspace( |
| 847 | + 'Gamma 1.8 - Rec.709 - Texture', |
| 848 | + 1.8, |
| 849 | + from_reference_values=[aces.ACES_AP0_TO_XYZ, XYZ_to_Rec709], |
| 850 | + aliases=['g18_rec709']) |
| 851 | + cs.description = ( |
| 852 | + 'The Gamma 1.8 - Rec.709 color space for importing certain textures.') |
| 853 | + colorspaces.append(cs) |
| 854 | + |
689 | 855 | # ------------------------------------------------------------------------- |
690 | 856 | # Rec 2020 |
691 | 857 | # ------------------------------------------------------------------------- |
|
0 commit comments