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

Commit

Permalink
Merge pull request #6033 from ynput/bugfix/traypublisher-explicit-col…
Browse files Browse the repository at this point in the history
…orspace

Refactor colorspace handling in CollectColorspace plugin
  • Loading branch information
jakubjezek001 authored Dec 19, 2023
2 parents 4db853e + 302b92d commit 0c28abc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)
from openpype.lib import EnumDef
from openpype.pipeline import colorspace
from openpype.pipeline.publish import KnownPublishError


class CollectColorspace(pyblish.api.InstancePlugin,
Expand All @@ -26,18 +27,44 @@ class CollectColorspace(pyblish.api.InstancePlugin,

def process(self, instance):
values = self.get_attr_values_from_data(instance.data)
colorspace = values.get("colorspace", None)
if colorspace is None:
colorspace_value = values.get("colorspace", None)
if colorspace_value is None:
return

self.log.debug("Explicit colorspace set to: {}".format(colorspace))
color_data = colorspace.convert_colorspace_enumerator_item(
colorspace_value, self.config_items)

colorspace_name = self._colorspace_name_by_type(color_data)
self.log.debug("Explicit colorspace name: {}".format(colorspace_name))

context = instance.context
for repre in instance.data.get("representations", {}):
self.set_representation_colorspace(
representation=repre,
context=context,
colorspace=colorspace
colorspace=colorspace_name
)

def _colorspace_name_by_type(self, colorspace_data):
"""
Returns colorspace name by type
Arguments:
colorspace_data (dict): colorspace data
Returns:
str: colorspace name
"""
if colorspace_data["type"] == "colorspaces":
return colorspace_data["name"]
elif colorspace_data["type"] == "roles":
return colorspace_data["colorspace"]
else:
raise KnownPublishError(
(
"Collecting of colorspace failed. used config is missing "
"colorspace type: '{}' . Please contact your pipeline TD."
).format(colorspace_data['type'])
)

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ def process(self, instance):
config_path = colorspace_data["config"]["path"]
if config_path not in config_colorspaces:
colorspaces = get_ocio_config_colorspaces(config_path)
config_colorspaces[config_path] = set(colorspaces)
if not colorspaces.get("colorspaces"):
message = (
f"OCIO config '{config_path}' does not contain any "
"colorspaces. This is an error in the OCIO config. "
"Contact your pipeline TD.",
)
raise PublishValidationError(
title="Colorspace validation",
message=message,
description=message
)
config_colorspaces[config_path] = set(
colorspaces["colorspaces"])

colorspace = colorspace_data["colorspace"]
self.log.debug(
Expand Down

0 comments on commit 0c28abc

Please sign in to comment.