Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
nuke12 is having its own PyOpenColorIO 1.1.1
Browse files Browse the repository at this point in the history
which is missing some functionalinty
  • Loading branch information
jakubjezek001 committed Mar 13, 2024
1 parent 69c3196 commit d434589
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 40 deletions.
4 changes: 4 additions & 0 deletions openpype/pipeline/colorspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,13 @@ def compatibility_check():

try:
import PyOpenColorIO # noqa: F401
config = PyOpenColorIO.GetCurrentConfig()
config.getDisplayViewColorSpaceName("sRGB", "sRGB")
CachedData.has_compatible_ocio_package = True
except ImportError:
CachedData.has_compatible_ocio_package = False
except AttributeError:
CachedData.has_compatible_ocio_package = False

# compatible
return CachedData.has_compatible_ocio_package
Expand Down
60 changes: 20 additions & 40 deletions openpype/scripts/ocio_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
- returning all available viewers
found in input config path.
"""

import os
import click
import json
from pathlib import Path
import PyOpenColorIO as ocio


Expand Down Expand Up @@ -76,14 +75,12 @@ def get_colorspace(in_path, out_path):
> pyton.exe ./ocio_wrapper.py config get_colorspace
--in_path=<path> --out_path=<path>
"""
json_path = Path(out_path)

out_data = _get_colorspace_data(in_path)

with open(json_path, "w") as f_:
with open(out_path, "w") as f_:
json.dump(out_data, f_)

print("Colorspace data are saved to '{}'".format(json_path))
print("Colorspace data are saved to '{}'".format(out_path))


def _get_colorspace_data(config_path):
Expand All @@ -98,13 +95,11 @@ def _get_colorspace_data(config_path):
Returns:
dict: aggregated available colorspaces
"""
config_path = Path(config_path)

if not config_path.is_file():
if not os.path.isfile(config_path):
raise IOError(
"Input path `{}` should be `config.ocio` file".format(config_path))

config = ocio.Config().CreateFromFile(str(config_path))
config = ocio.Config().CreateFromFile(config_path)

colorspace_data = {
"roles": {},
Expand Down Expand Up @@ -173,14 +168,12 @@ def get_views(in_path, out_path):
> pyton.exe ./ocio_wrapper.py config get_views \
--in_path=<path> --out_path=<path>
"""
json_path = Path(out_path)

out_data = _get_views_data(in_path)

with open(json_path, "w") as f_:
with open(out_path, "w") as f_:
json.dump(out_data, f_)

print("Viewer data are saved to '{}'".format(json_path))
print("Viewer data are saved to '{}'".format(out_path))


def _get_views_data(config_path):
Expand All @@ -195,12 +188,10 @@ def _get_views_data(config_path):
Returns:
dict: aggregated available viewers
"""
config_path = Path(config_path)

if not config_path.is_file():
if not os.path.isfile(config_path):
raise IOError("Input path should be `config.ocio` file")

config = ocio.Config().CreateFromFile(str(config_path))
config = ocio.Config().CreateFromFile(config_path)

data_ = {}
for display in config.getDisplays():
Expand Down Expand Up @@ -247,14 +238,12 @@ def get_version(config_path, out_path):
> pyton.exe ./ocio_wrapper.py config get_version \
--config_path=<path> --out_path=<path>
"""
json_path = Path(out_path)

out_data = _get_version_data(config_path)

with open(json_path, "w") as f_:
with open(out_path, "w") as f_:
json.dump(out_data, f_)

print("Config version data are saved to '{}'".format(json_path))
print("Config version data are saved to '{}'".format(out_path))


def _get_version_data(config_path):
Expand All @@ -269,12 +258,10 @@ def _get_version_data(config_path):
Returns:
dict: minor and major keys with values
"""
config_path = Path(config_path)

if not config_path.is_file():
if not os.path.isfile(config_path):
raise IOError("Input path should be `config.ocio` file")

config = ocio.Config().CreateFromFile(str(config_path))
config = ocio.Config().CreateFromFile(config_path)

return {
"major": config.getMajorVersion(),
Expand Down Expand Up @@ -317,15 +304,13 @@ def get_config_file_rules_colorspace_from_filepath(
colorspace get_config_file_rules_colorspace_from_filepath \
--config_path=<path> --filepath=<path> --out_path=<path>
"""
json_path = Path(out_path)

colorspace = _get_config_file_rules_colorspace_from_filepath(
config_path, filepath)

with open(json_path, "w") as f_:
with open(out_path, "w") as f_:
json.dump(colorspace, f_)

print("Colorspace name is saved to '{}'".format(json_path))
print("Colorspace name is saved to '{}'".format(out_path))


def _get_config_file_rules_colorspace_from_filepath(config_path, filepath):
Expand All @@ -341,16 +326,14 @@ def _get_config_file_rules_colorspace_from_filepath(config_path, filepath):
Returns:
dict: aggregated available colorspaces
"""
config_path = Path(config_path)

if not config_path.is_file():
if not os.path.isfile(config_path):
raise IOError(
"Input path `{}` should be `config.ocio` file".format(config_path))

config = ocio.Config().CreateFromFile(str(config_path))
config = ocio.Config().CreateFromFile(config_path)

# TODO: use `parseColorSpaceFromString` instead if ocio v1
colorspace = config.getColorSpaceFromFilepath(str(filepath))
colorspace = config.getColorSpaceFromFilepath(filepath)

return colorspace

Expand All @@ -370,13 +353,10 @@ def _get_display_view_colorspace_name(config_path, display, view):
Returns:
view color space name (str) e.g. "Output - sRGB"
"""

config_path = Path(config_path)

if not config_path.is_file():
if not os.path.isfile(config_path):
raise IOError("Input path should be `config.ocio` file")

config = ocio.Config.CreateFromFile(str(config_path))
config = ocio.Config.CreateFromFile(config_path)
colorspace = config.getDisplayViewColorSpaceName(display, view)

return colorspace
Expand Down

0 comments on commit d434589

Please sign in to comment.