mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
improving colorspace categorization
also adding new abstract function for returning all settings options nicely labelled
This commit is contained in:
parent
c30fc498ee
commit
1d0e55aa83
4 changed files with 101 additions and 51 deletions
|
|
@ -148,13 +148,12 @@ This creator publishes color space look file (LUT).
|
||||||
|
|
||||||
if config_data:
|
if config_data:
|
||||||
filepath = config_data["path"]
|
filepath = config_data["path"]
|
||||||
config_items = colorspace.get_ocio_config_colorspaces(filepath)
|
labeled_colorspaces = colorspace.get_labeled_colorspaces(
|
||||||
|
filepath,
|
||||||
self.colorspace_items.extend((
|
include_aliases=True,
|
||||||
(name, f"{name} [{data_['type']}]")
|
include_roles=True
|
||||||
for name, data_ in config_items.items()
|
)
|
||||||
if data_.get("type") == "colorspace"
|
self.colorspace_items.extend(labeled_colorspaces)
|
||||||
))
|
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
|
|
||||||
def _get_subset(self, asset_doc, variant, project_name, task_name=None):
|
def _get_subset(self, asset_doc, variant, project_name, task_name=None):
|
||||||
|
|
|
||||||
|
|
@ -50,30 +50,13 @@ class CollectColorspace(pyblish.api.InstancePlugin,
|
||||||
)
|
)
|
||||||
|
|
||||||
if config_data:
|
if config_data:
|
||||||
|
|
||||||
filepath = config_data["path"]
|
filepath = config_data["path"]
|
||||||
config_items = colorspace.get_ocio_config_colorspaces(filepath)
|
labeled_colorspaces = colorspace.get_labeled_colorspaces(
|
||||||
aliases = set()
|
filepath,
|
||||||
for _, value_ in config_items.items():
|
include_aliases=True,
|
||||||
if value_.get("type") != "colorspace":
|
include_roles=True
|
||||||
continue
|
)
|
||||||
if not value_.get("aliases"):
|
cls.colorspace_items.extend(labeled_colorspaces)
|
||||||
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
|
|
||||||
))
|
|
||||||
cls.enabled = True
|
cls.enabled = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,10 @@ def parse_colorspace_from_filepath(
|
||||||
"Must provide `config_path` if `colorspaces` is not provided."
|
"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 = {
|
underscored_colorspaces = {
|
||||||
key.replace(" ", "_"): key for key in colorspaces
|
key.replace(" ", "_"): key for key in colorspaces
|
||||||
if " " in key
|
if " " in key
|
||||||
|
|
@ -393,7 +396,7 @@ def validate_imageio_colorspace_in_config(config_path, colorspace_name):
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if exists
|
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:
|
if colorspace_name not in colorspaces:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
"Missing colorspace '{}' in config file '{}'".format(
|
"Missing colorspace '{}' in config file '{}'".format(
|
||||||
|
|
@ -530,6 +533,76 @@ def get_ocio_config_colorspaces(config_path):
|
||||||
return CachedData.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
|
# TODO: remove this in future - backward compatibility
|
||||||
@deprecated("_get_wrapped_with_subprocess")
|
@deprecated("_get_wrapped_with_subprocess")
|
||||||
def get_colorspace_data_subprocess(config_path):
|
def get_colorspace_data_subprocess(config_path):
|
||||||
|
|
|
||||||
|
|
@ -107,37 +107,32 @@ def _get_colorspace_data(config_path):
|
||||||
config = ocio.Config().CreateFromFile(str(config_path))
|
config = ocio.Config().CreateFromFile(str(config_path))
|
||||||
|
|
||||||
colorspace_data = {
|
colorspace_data = {
|
||||||
color.getName(): {
|
"colorspace": {
|
||||||
"type": "colorspace",
|
color.getName(): {
|
||||||
"family": color.getFamily(),
|
"family": color.getFamily(),
|
||||||
"categories": list(color.getCategories()),
|
"categories": list(color.getCategories()),
|
||||||
"aliases": list(color.getAliases()),
|
"aliases": list(color.getAliases()),
|
||||||
"equalitygroup": color.getEqualityGroup(),
|
"equalitygroup": color.getEqualityGroup(),
|
||||||
|
}
|
||||||
|
for color in config.getColorSpaces()
|
||||||
}
|
}
|
||||||
for color in config.getColorSpaces()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# add looks
|
# add looks
|
||||||
looks = config.getLooks()
|
looks = config.getLooks()
|
||||||
if looks:
|
if looks:
|
||||||
colorspace_data.update({
|
colorspace_data["look"] = {
|
||||||
look.getName(): {
|
look.getName(): {"process_space": look.getProcessSpace()}
|
||||||
"type": "look",
|
|
||||||
"process_space": look.getProcessSpace()
|
|
||||||
}
|
|
||||||
for look in looks
|
for look in looks
|
||||||
})
|
}
|
||||||
|
|
||||||
# add roles
|
# add roles
|
||||||
roles = config.getRoles()
|
roles = config.getRoles()
|
||||||
if roles:
|
if roles:
|
||||||
colorspace_data.update({
|
colorspace_data["role"] = {
|
||||||
role: {
|
role: {"colorspace": colorspace}
|
||||||
"type": "role",
|
|
||||||
"colorspace": colorspace
|
|
||||||
}
|
|
||||||
for (role, colorspace) in roles
|
for (role, colorspace) in roles
|
||||||
})
|
}
|
||||||
|
|
||||||
return colorspace_data
|
return colorspace_data
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue