move get function to colorspace.py

This commit is contained in:
Mustafa-Zarkash 2023-07-20 13:38:09 +03:00
parent 00d4afd117
commit d90d45c56d
3 changed files with 91 additions and 7 deletions

View file

@ -71,19 +71,24 @@ class ValidateReviewColorspace(pyblish.api.InstancePlugin):
"""
import hou
import PyOpenColorIO as OCIO
from openpype.pipeline.colorspace import get_display_view_colorspace_name
from openpype.hosts.houdini.api.lib import get_color_management_preferences #noqa
rop_node = hou.node(instance.data["instance_node"])
config = OCIO.GetCurrentConfig()
display = hou.Color.ocio_defaultDisplay()
view = hou.Color.ocio_defaultView()
data = get_color_management_preferences()
config_path = data.get("config")
display = data.get("display")
view = data.get("view")
default_view_space = config.getDisplayViewColorSpaceName(
display, view) # works with PyOpenColorIO 2.2.1
cls.log.debug("Get default view colorspace name..")
default_view_space = get_display_view_colorspace_name(config_path,
display, view)
rop_node.setParms({"ociocolorspace": default_view_space})
cls.log.debug(
"'OCIO Colorspace' parm on '%s' has been set to '%s'",
"'OCIO Colorspace' parm on '%s' has been set to "
"the default view color space '%s'",
default_view_space, rop_node
)

View file

@ -589,3 +589,39 @@ def _get_imageio_settings(project_settings, host_name):
imageio_host = project_settings.get(host_name, {}).get("imageio", {})
return imageio_global, imageio_host
def get_display_view_colorspace_name(config_path, display, view):
if not compatibility_check():
# python environment is not compatible with PyOpenColorIO
# needs to be run in subprocess
return get_display_view_colorspace_subprocess(config_path,
display, view)
from openpype.scripts.ocio_wrapper import _get_display_view_colorspace_name #noqa
return _get_display_view_colorspace_name(config_path, display, view)
def get_display_view_colorspace_subprocess(config_path, display, view):
with _make_temp_json_file() as tmp_json_path:
# Prepare subprocess arguments
args = [
"run", get_ocio_config_script_path(),
"config", "get_display_view_colorspace_name",
"--in_path", config_path,
"--out_path", tmp_json_path,
"--display", display,
"--view", view
]
log.info("Executing: {}".format(" ".join(args)))
process_kwargs = {
"logger": log
}
run_openpype_process(*args, **process_kwargs)
# return all colorspaces
return_json_data = open(tmp_json_path).read()
return json.loads(return_json_data)

View file

@ -173,6 +173,49 @@ def _get_views_data(config_path):
return data
def _get_display_view_colorspace_name(config_path, display, view):
config_path = Path(config_path)
if not config_path.is_file():
raise IOError("Input path should be `config.ocio` file")
config = ocio.Config().CreateFromFile(str(config_path))
colorspace = config.getDisplayViewColorSpaceName(display, view)
return colorspace
@config.command(
name="get_display_view_colorspace_name",
help=(
"return default view colorspace name "
"for the given display and view "
"--path input arg is required"
)
)
@click.option("--in_path", required=True,
help="path where to read ocio config file",
type=click.Path(exists=True))
@click.option("--out_path", required=True,
help="path where to write output json file",
type=click.Path())
@click.option("--display", required=True,
help="display",
type=click.STRING)
@click.option("--view", required=True,
help="view",
type=click.STRING)
def get_display_view_colorspace_name(in_path, out_path,
display, view):
json_path = Path(out_path)
out_data = _get_display_view_colorspace_name(in_path,
display, view)
with open(json_path, "w") as f:
json.dump(out_data, f)
print(f"Viewer data are saved to '{json_path}'")
if __name__ == '__main__':
main()