Skip to content

Commit

Permalink
Added GetProcessorFromConfigs variants for displays and views. (Acade…
Browse files Browse the repository at this point in the history
…mySoftwareFoundation#1808)

* Added GetProcessorFromConfigs variants for displays and views.

Signed-off-by: Eric Renaud-Houde <eric.renaud.houde@gmail.com>

* Added display-view processor from two configs tests, moved direction argument last.

Signed-off-by: Eric Renaud-Houde <eric.renaud.houde@gmail.com>

---------

Signed-off-by: Eric Renaud-Houde <eric.renaud.houde@gmail.com>
Co-authored-by: Michael Dolan <michdolan@gmail.com>
Signed-off-by: Brooke <beg9562@rit.edu>
  • Loading branch information
2 people authored and brkglvn01 committed Oct 23, 2023
1 parent f2ac1f0 commit ac5250f
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 4 deletions.
44 changes: 44 additions & 0 deletions include/OpenColorIO/OpenColorIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,50 @@ class OCIOEXPORT Config
const char * dstColorSpaceName,
const char * dstInterchangeName);

/**
* \brief Get a processor to convert from a color space to a display and view in
* two separate configs.
*/
static ConstProcessorRcPtr GetProcessorFromConfigs(const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
TransformDirection direction);

static ConstProcessorRcPtr GetProcessorFromConfigs(const ConstContextRcPtr & srcContext,
const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const ConstContextRcPtr & dstContext,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
TransformDirection direction);

/**
* The srcInterchangeName and dstInterchangeName must refer to a pair of
* color spaces in the two configs that are the same. A role name may also be used.
*/
static ConstProcessorRcPtr GetProcessorFromConfigs(const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const char * srcInterchangeName,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
const char * dstInterchangeName,
TransformDirection direction);

static ConstProcessorRcPtr GetProcessorFromConfigs(const ConstContextRcPtr & srcContext,
const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const char * srcInterchangeName,
const ConstContextRcPtr & dstContext,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
const char * dstInterchangeName,
TransformDirection direction);

/// Get the Processor Cache flags.
ProcessorCacheFlags getProcessorCacheFlags() const noexcept;

Expand Down
143 changes: 142 additions & 1 deletion src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4572,7 +4572,7 @@ ConstProcessorRcPtr Config::GetProcessorFromConfigs(const ConstContextRcPtr & sr
}

auto p2 = dstConfig->getProcessor(dstContext, dstExCs, dstColorSpace);
if (!p1)
if (!p2)
{
throw Exception("Can't create the processor for the destination config "
"and the destination color space.");
Expand All @@ -4591,6 +4591,147 @@ ConstProcessorRcPtr Config::GetProcessorFromConfigs(const ConstContextRcPtr & sr
return processor;
}

ConstProcessorRcPtr Config::GetProcessorFromConfigs(const ConstConfigRcPtr & srcConfig,
const char * srcName,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
TransformDirection direction)
{
return GetProcessorFromConfigs(srcConfig->getCurrentContext(), srcConfig, srcName,
dstConfig->getCurrentContext(), dstConfig, dstDisplay, dstView, direction);
}

ConstProcessorRcPtr Config::GetProcessorFromConfigs(const ConstContextRcPtr & srcContext,
const ConstConfigRcPtr & srcConfig,
const char * srcName,
const ConstContextRcPtr & dstContext,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
TransformDirection direction)
{
ConstColorSpaceRcPtr srcColorSpace = srcConfig->getColorSpace(srcName);
if (!srcColorSpace)
{
std::ostringstream os;
os << "Could not find source color space '" << srcName << "'.";
throw Exception(os.str().c_str());
}

const bool sceneReferred = (srcColorSpace->getReferenceSpaceType() == REFERENCE_SPACE_SCENE);
const char* exchangeRoleName = sceneReferred ? ROLE_INTERCHANGE_SCENE : ROLE_INTERCHANGE_DISPLAY;
const char* srcExName = LookupRole(srcConfig->getImpl()->m_roles, exchangeRoleName);
if (!srcExName || !*srcExName)
{
std::ostringstream os;
os << "The role '" << exchangeRoleName << "' is missing in the source config.";
throw Exception(os.str().c_str());
}
ConstColorSpaceRcPtr srcExCs = srcConfig->getColorSpace(srcExName);
if (!srcExCs)
{
std::ostringstream os;
os << "The role '" << exchangeRoleName << "' refers to color space '" << srcExName;
os << "' that is missing in the source config.";
throw Exception(os.str().c_str());
}

const char* dstExName = LookupRole(dstConfig->getImpl()->m_roles, exchangeRoleName);
if (!dstExName || !*dstExName)
{
std::ostringstream os;
os << "The role '" << exchangeRoleName << "' is missing in the destination config.";
throw Exception(os.str().c_str());
}
ConstColorSpaceRcPtr dstExCs = dstConfig->getColorSpace(dstExName);
if (!dstExCs)
{
std::ostringstream os;
os << "The role '" << exchangeRoleName << "' refers to color space '" << dstExName;
os << "' that is missing in the destination config.";
throw Exception(os.str().c_str());
}

return GetProcessorFromConfigs(srcContext, srcConfig, srcName, srcExName,
dstContext, dstConfig, dstDisplay, dstView, dstExName, direction);
}

ConstProcessorRcPtr Config::GetProcessorFromConfigs(const ConstConfigRcPtr& srcConfig,
const char * srcName,
const char * srcInterchangeName,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
const char* dstInterchangeName,
TransformDirection direction)
{
return GetProcessorFromConfigs(srcConfig->getCurrentContext(), srcConfig, srcName, srcInterchangeName,
dstConfig->getCurrentContext(), dstConfig, dstDisplay, dstView, dstInterchangeName, direction);
}

ConstProcessorRcPtr Config::GetProcessorFromConfigs(const ConstContextRcPtr & srcContext,
const ConstConfigRcPtr & srcConfig,
const char * srcName,
const char * srcInterchangeName,
const ConstContextRcPtr & dstContext,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
const char * dstInterchangeName,
TransformDirection direction)
{
ConstColorSpaceRcPtr srcColorSpace = srcConfig->getColorSpace(srcName);
if (!srcColorSpace)
{
std::ostringstream os;
os << "Could not find source color space '" << srcName << "'.";
throw Exception(os.str().c_str());
}

ConstColorSpaceRcPtr srcExCs = srcConfig->getColorSpace(srcInterchangeName);
if (!srcExCs)
{
std::ostringstream os;
os << "Could not find source interchange color space '" << srcInterchangeName << "'.";
throw Exception(os.str().c_str());
}

if (direction == TRANSFORM_DIR_INVERSE)
{
std::swap(srcColorSpace, srcExCs);
}
auto p1 = srcConfig->getProcessor(srcContext, srcColorSpace, srcExCs);
if (!p1)
{
throw Exception("Can't create the processor for the source config and "
"the source color space.");
}

auto p2 = dstConfig->getProcessor(dstContext, dstInterchangeName, dstDisplay, dstView, direction);
if (!p2)
{
throw Exception("Can't create the processor for the destination config "
"and the destination color space.");
}

ProcessorRcPtr processor = Processor::Create();
processor->getImpl()->setProcessorCacheFlags(srcConfig->getImpl()->m_cacheFlags);

// If the source color spaces is a data space, its corresponding processor
// will be empty, but need to make sure the entire result is also empty to
// better match the semantics of how data spaces are handled.
if (!srcColorSpace->isData())
{
if (direction == TRANSFORM_DIR_INVERSE)
{
std::swap(p1, p2);
}
processor->getImpl()->concatenate(p1, p2);
}
return processor;
}

static ConstProcessorRcPtr GetProcessorToBuiltinCS(ConstConfigRcPtr srcConfig,
const char * srcColorSpaceName,
const char * builtinColorSpaceName,
Expand Down
73 changes: 73 additions & 0 deletions src/bindings/python/PyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,79 @@ void bindPyConfig(py::module & m)
"srcContext"_a, "srcConfig"_a, "srcColorSpaceName"_a, "srcInterchangeName"_a,
"dstContext"_a, "dstConfig"_a, "dstColorSpaceName"_a, "dstInterchangeName"_a,
DOC(Config, GetProcessorFromConfigs, 4))
.def_static("GetProcessorFromConfigs", [](const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
TransformDirection direction)
{
return Config::GetProcessorFromConfigs(srcConfig, srcColorSpaceName,
dstConfig, dstDisplay, dstView, direction);
},
"srcConfig"_a, "srcColorSpaceName"_a, "dstConfig"_a, "dstDisplay"_a, "dstView"_a, "direction"_a,
DOC(Config, GetProcessorFromConfigs, 5))
.def_static("GetProcessorFromConfigs", [](const ConstContextRcPtr & srcContext,
const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const ConstContextRcPtr & dstContext,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
TransformDirection direction)
{
return Config::GetProcessorFromConfigs(srcContext, srcConfig, srcColorSpaceName,
dstContext, dstConfig, dstDisplay, dstView, direction);
},
"srcContext"_a, "srcConfig"_a, "srcColorSpaceName"_a,
"dstContext"_a, "dstConfig"_a, "dstView"_a, "dstDisplay"_a, "direction"_a,
DOC(Config, GetProcessorFromConfigs, 6))
.def_static("GetProcessorFromConfigs", [](const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const char * srcInterchangeName,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
const char * dstInterchangeName,
TransformDirection direction)
{
return Config::GetProcessorFromConfigs(srcConfig,
srcColorSpaceName,
srcInterchangeName,
dstConfig,
dstDisplay,
dstView,
dstInterchangeName,
direction);
},
"srcConfig"_a, "srcColorSpaceName"_a, "srcInterchangeName"_a,
"dstConfig"_a, "dstDisplay"_a, "dstView"_a, "dstInterchangeName"_a, "direction"_a,
DOC(Config, GetProcessorFromConfigs, 7))
.def_static("GetProcessorFromConfigs", [](const ConstContextRcPtr & srcContext,
const ConstConfigRcPtr & srcConfig,
const char * srcColorSpaceName,
const char * srcInterchangeName,
const ConstContextRcPtr & dstContext,
const ConstConfigRcPtr & dstConfig,
const char * dstDisplay,
const char * dstView,
const char * dstInterchangeName,
TransformDirection direction)
{
return Config::GetProcessorFromConfigs(srcContext,
srcConfig,
srcColorSpaceName,
srcInterchangeName,
dstContext,
dstConfig,
dstDisplay,
dstView,
dstInterchangeName,
direction);
},
"srcContext"_a, "srcConfig"_a, "srcColorSpaceName"_a, "srcInterchangeName"_a,
"dstContext"_a, "dstConfig"_a, "dstDisplay"_a, "dstView"_a, "dstInterchangeName"_a, "direction"_a,
DOC(Config, GetProcessorFromConfigs, 8))
.def("setProcessorCacheFlags", &Config::setProcessorCacheFlags, "flags"_a,
DOC(Config, setProcessorCacheFlags))
.def("clearProcessorCache", &Config::clearProcessorCache,
Expand Down
Loading

0 comments on commit ac5250f

Please sign in to comment.