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 #4079 from pypeclub/feature/OP-4364_Flame-load-cli…
Browse files Browse the repository at this point in the history
…p-with-colorspace-remapping

Flame: Loading clip with native colorspace resolved from mapping
  • Loading branch information
jakubjezek001 authored Nov 18, 2022
2 parents 728347c + 0f392dd commit a375af6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
52 changes: 50 additions & 2 deletions openpype/hosts/flame/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from copy import deepcopy
from xml.etree import ElementTree as ET

import qargparse
from Qt import QtCore, QtWidgets

import qargparse
from openpype import style
from openpype.settings import get_current_project_settings
from openpype.lib import Logger
from openpype.pipeline import LegacyCreator, LoaderPlugin
from openpype.settings import get_current_project_settings

from . import constants
from . import lib as flib
Expand Down Expand Up @@ -690,6 +690,54 @@ class ClipLoader(LoaderPlugin):
)
]

_mapping = None

def get_colorspace(self, context):
"""Get colorspace name
Look either to version data or representation data.
Args:
context (dict): version context data
Returns:
str: colorspace name or None
"""
version = context['version']
version_data = version.get("data", {})
colorspace = version_data.get(
"colorspace", None
)

if (
not colorspace
or colorspace == "Unknown"
):
colorspace = context["representation"]["data"].get(
"colorspace", None)

return colorspace

@classmethod
def get_native_colorspace(cls, input_colorspace):
"""Return native colorspace name.
Args:
input_colorspace (str | None): colorspace name
Returns:
str: native colorspace name defined in mapping or None
"""
if not cls._mapping:
settings = get_current_project_settings()["flame"]
mapping = settings["imageio"]["profilesMapping"]["inputs"]
cls._mapping = {
input["ocioName"]: input["flameName"]
for input in mapping
}

return cls._mapping.get(input_colorspace)


class OpenClipSolver(flib.MediaInfoFile):
create_new_clip = False
Expand Down
7 changes: 4 additions & 3 deletions openpype/hosts/flame/plugins/load/load_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def load(self, context, name, namespace, options):
version = context['version']
version_data = version.get("data", {})
version_name = version.get("name", None)
colorspace = version_data.get("colorspace", None)
colorspace = self.get_colorspace(context)

clip_name = StringTemplate(self.clip_name_template).format(
context["representation"]["context"])

# TODO: settings in imageio
# convert colorspace with ocio to flame mapping
# in imageio flame section
colorspace = colorspace
colorspace = self.get_native_colorspace(colorspace)
self.log.info("Loading with colorspace: `{}`".format(colorspace))

# create workfile path
workfile_dir = os.environ["AVALON_WORKDIR"]
Expand Down
6 changes: 3 additions & 3 deletions openpype/hosts/flame/plugins/load/load_clip_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def load(self, context, name, namespace, options):
version = context['version']
version_data = version.get("data", {})
version_name = version.get("name", None)
colorspace = version_data.get("colorspace", None)
colorspace = self.get_colorspace(context)

# in case output is not in context replace key to representation
if not context["representation"]["context"].get("output"):
Expand All @@ -47,10 +47,10 @@ def load(self, context, name, namespace, options):
clip_name = StringTemplate(self.clip_name_template).format(
formating_data)

# TODO: settings in imageio
# convert colorspace with ocio to flame mapping
# in imageio flame section
colorspace = colorspace
colorspace = self.get_native_colorspace(colorspace)
self.log.info("Loading with colorspace: `{}`".format(colorspace))

# create workfile path
workfile_dir = options.get("workdir") or os.environ["AVALON_WORKDIR"]
Expand Down

0 comments on commit a375af6

Please sign in to comment.