Global: refactory colormanaged exctractor into plugin mixin

This commit is contained in:
Jakub Jezek 2023-02-28 14:53:49 +01:00
parent 0765602ce3
commit ee3e346c8d
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
4 changed files with 28 additions and 22 deletions

View file

@ -9,7 +9,8 @@ from openpype.pipeline import publish
from openpype.lib import collect_frames
class NukeRenderLocal(publish.ExtractorColormanaged):
class NukeRenderLocal(publish.Extractor,
publish.ColormanagedPyblishPluginMixin):
"""Render the current Nuke composition locally.
Extract the result of savers by starting a comp render

View file

@ -19,7 +19,7 @@ from .publish_plugins import (
RepairContextAction,
Extractor,
ExtractorColormanaged,
ColormanagedPyblishPluginMixin
)
from .lib import (
@ -64,7 +64,7 @@ __all__ = (
"RepairContextAction",
"Extractor",
"ExtractorColormanaged",
"ColormanagedPyblishPluginMixin",
"get_publish_template_name",

View file

@ -3,7 +3,7 @@ from abc import ABCMeta
from pprint import pformat
import pyblish.api
from pyblish.plugin import MetaPlugin, ExplicitMetaPlugin
from openpype.lib.transcoding import VIDEO_EXTENSIONS, IMAGE_EXTENSIONS
from openpype.lib import BoolDef
from .lib import (
@ -288,24 +288,25 @@ class Extractor(pyblish.api.InstancePlugin):
return get_instance_staging_dir(instance)
class ExtractorColormanaged(Extractor):
"""Extractor base for color managed image data.
Each Extractor intended to export pixel data representation
should inherit from this class to allow color managed data.
Class implements "get_colorspace_settings" and
"set_representation_colorspace" functions used
for injecting colorspace data to representation data for farther
integration into db document.
class ColormanagedPyblishPluginMixin(object):
"""Mixin for colormanaged plugins.
This class is used to set colorspace data to a publishing
representation. It contains a static method,
get_colorspace_settings, which returns config and
file rules data for the host context.
It also contains a method, set_representation_colorspace,
which sets colorspace data to the representation.
The allowed file extensions are listed in the allowed_ext variable.
he method first checks if the file extension is in
the list of allowed extensions. If it is, it then gets the
colorspace settings from the host context and gets a
matching colorspace from rules. Finally, it infuses this
data into the representation.
"""
allowed_ext = [
"cin", "dpx", "avi", "dv", "gif", "flv", "mkv", "mov", "mpg", "mpeg",
"mp4", "m4v", "mxf", "iff", "z", "ifl", "jpeg", "jpg", "jfif", "lut",
"1dl", "exr", "pic", "png", "ppm", "pnm", "pgm", "pbm", "rla", "rpf",
"sgi", "rgba", "rgb", "bw", "tga", "tiff", "tif", "img"
]
allowed_ext = set(
ext.lstrip(".") for ext in IMAGE_EXTENSIONS.union(VIDEO_EXTENSIONS)
)
@staticmethod
def get_colorspace_settings(context):
@ -375,7 +376,10 @@ class ExtractorColormanaged(Extractor):
ext = representation["ext"]
# check extension
self.log.debug("__ ext: `{}`".format(ext))
if ext.lower() not in self.allowed_ext:
# check if ext in lower case is in self.allowed_ext
if ext.lstrip(".").lower() not in self.allowed_ext:
self.log.debug("Extension is not in allowed extensions.")
return
if colorspace_settings is None:

View file

@ -2,7 +2,8 @@ import pyblish.api
from openpype.pipeline import publish
class ExtractColorspaceData(publish.ExtractorColormanaged):
class ExtractColorspaceData(publish.Extractor,
publish.ColormanagedPyblishPluginMixin):
""" Inject Colorspace data to available representations.
Input data: