improving colorspace categorization

also adding new abstract function for returning all settings options nicely labelled
This commit is contained in:
Jakub Jezek 2023-10-04 13:00:42 +02:00
parent c30fc498ee
commit 1d0e55aa83
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
4 changed files with 101 additions and 51 deletions

View file

@ -148,13 +148,12 @@ This creator publishes color space look file (LUT).
if config_data:
filepath = config_data["path"]
config_items = colorspace.get_ocio_config_colorspaces(filepath)
self.colorspace_items.extend((
(name, f"{name} [{data_['type']}]")
for name, data_ in config_items.items()
if data_.get("type") == "colorspace"
))
labeled_colorspaces = colorspace.get_labeled_colorspaces(
filepath,
include_aliases=True,
include_roles=True
)
self.colorspace_items.extend(labeled_colorspaces)
self.enabled = True
def _get_subset(self, asset_doc, variant, project_name, task_name=None):

View file

@ -50,30 +50,13 @@ class CollectColorspace(pyblish.api.InstancePlugin,
)
if config_data:
filepath = config_data["path"]
config_items = colorspace.get_ocio_config_colorspaces(filepath)
aliases = set()
for _, value_ in config_items.items():
if value_.get("type") != "colorspace":
continue
if not value_.get("aliases"):
continue
for alias in value_.get("aliases"):
aliases.add(alias)
colorspaces = {
name for name, data_ in config_items.items()
if data_.get("type") == "colorspace"
}
cls.colorspace_items.extend((
(name, f"{name} [colorspace]") for name in colorspaces
))
if aliases:
cls.colorspace_items.extend((
(name, f"{name} [alias]") for name in aliases
))
labeled_colorspaces = colorspace.get_labeled_colorspaces(
filepath,
include_aliases=True,
include_roles=True
)
cls.colorspace_items.extend(labeled_colorspaces)
cls.enabled = True
@classmethod

View file

@ -356,7 +356,10 @@ def parse_colorspace_from_filepath(
"Must provide `config_path` if `colorspaces` is not provided."
)
colorspaces = colorspaces or get_ocio_config_colorspaces(config_path)
colorspaces = (
colorspaces
or get_ocio_config_colorspaces(config_path)["colorspace"]
)
underscored_colorspaces = {
key.replace(" ", "_"): key for key in colorspaces
if " " in key
@ -393,7 +396,7 @@ def validate_imageio_colorspace_in_config(config_path, colorspace_name):
Returns:
bool: True if exists
"""
colorspaces = get_ocio_config_colorspaces(config_path)
colorspaces = get_ocio_config_colorspaces(config_path)["colorspace"]
if colorspace_name not in colorspaces:
raise KeyError(
"Missing colorspace '{}' in config file '{}'".format(
@ -530,6 +533,76 @@ def get_ocio_config_colorspaces(config_path):
return CachedData.ocio_config_colorspaces[config_path]
def get_labeled_colorspaces(
config_path,
include_aliases=False,
include_looks=False,
include_roles=False,
):
"""Get all colorspace data with labels
Wrapper function for aggregating all names and its families.
Families can be used for building menu and submenus in gui.
Args:
config_path (str): path leading to config.ocio file
include_aliases (bool): include aliases in result
include_looks (bool): include looks in result
include_roles (bool): include roles in result
Returns:
list[tuple[str,str]]: colorspace and family in couple
"""
config_items = get_ocio_config_colorspaces(config_path)
labeled_colorspaces = []
aliases = set()
colorspaces = set()
looks = set()
roles = set()
for items_type, colorspace_items in config_items.items():
if items_type == "colorspace":
for color_name, color_data in colorspace_items.items():
if color_data.get("aliases"):
aliases.update([
"{} ({})".format(alias_name, color_name)
for alias_name in color_data["aliases"]
])
colorspaces.add(color_name)
elif items_type == "look":
looks.update([
"{} ({})".format(name, role_data["process_space"])
for name, role_data in colorspace_items.items()
])
elif items_type == "role":
roles.update([
"{} ({})".format(name, role_data["colorspace"])
for name, role_data in colorspace_items.items()
])
if roles and include_roles:
labeled_colorspaces.extend((
(name, f"[role] {name}") for name in roles
))
labeled_colorspaces.extend((
(name, f"[colorspace] {name}") for name in colorspaces
))
if aliases and include_aliases:
labeled_colorspaces.extend((
(name, f"[alias] {name}") for name in aliases
))
if looks and include_looks:
labeled_colorspaces.extend((
(name, f"[look] {name}") for name in looks
))
return labeled_colorspaces
# TODO: remove this in future - backward compatibility
@deprecated("_get_wrapped_with_subprocess")
def get_colorspace_data_subprocess(config_path):

View file

@ -107,37 +107,32 @@ def _get_colorspace_data(config_path):
config = ocio.Config().CreateFromFile(str(config_path))
colorspace_data = {
color.getName(): {
"type": "colorspace",
"family": color.getFamily(),
"categories": list(color.getCategories()),
"aliases": list(color.getAliases()),
"equalitygroup": color.getEqualityGroup(),
"colorspace": {
color.getName(): {
"family": color.getFamily(),
"categories": list(color.getCategories()),
"aliases": list(color.getAliases()),
"equalitygroup": color.getEqualityGroup(),
}
for color in config.getColorSpaces()
}
for color in config.getColorSpaces()
}
# add looks
looks = config.getLooks()
if looks:
colorspace_data.update({
look.getName(): {
"type": "look",
"process_space": look.getProcessSpace()
}
colorspace_data["look"] = {
look.getName(): {"process_space": look.getProcessSpace()}
for look in looks
})
}
# add roles
roles = config.getRoles()
if roles:
colorspace_data.update({
role: {
"type": "role",
"colorspace": colorspace
}
colorspace_data["role"] = {
role: {"colorspace": colorspace}
for (role, colorspace) in roles
})
}
return colorspace_data