Skip to content

Commit 34284f5

Browse files
Merging adsk_contrib/make-interchange-roles-required-for-future-config-version into this new branch as one commit in order to clean up the commits. (#1711)
Signed-off-by: Cedrik Fuoco <[email protected]> Signed-off-by: Cedrik Fuoco <[email protected]>
1 parent f767cad commit 34284f5

File tree

8 files changed

+782
-133
lines changed

8 files changed

+782
-133
lines changed

src/OpenColorIO/Config.cpp

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static constexpr unsigned LastSupportedMajorVersion = OCIO_VERSION_MAJOR;
243243

244244
// For each major version keep the most recent minor.
245245
static const unsigned int LastSupportedMinorVersion[] = {0, // Version 1
246-
1 // Version 2
246+
2 // Version 2
247247
};
248248

249249
} // namespace
@@ -1368,7 +1368,8 @@ void Config::validate() const
13681368

13691369
StringSet existingColorSpaces;
13701370

1371-
bool hasDisplayReferredColorspace = false;
1371+
bool hasDisplayReferredColorspace = false;
1372+
bool hasSceneReferredColorspace = false;
13721373

13731374
// Confirm all ColorSpaces are valid.
13741375
for(int i=0; i<getImpl()->m_allColorSpaces->getNumColorSpaces(); ++i)
@@ -1415,13 +1416,18 @@ void Config::validate() const
14151416

14161417
const std::string namelower = StringUtils::Lower(name);
14171418
existingColorSpaces.insert(namelower);
1419+
14181420
if (cs->getReferenceSpaceType() == REFERENCE_SPACE_DISPLAY)
14191421
{
14201422
hasDisplayReferredColorspace = true;
14211423
}
1424+
else if (cs->getReferenceSpaceType() == REFERENCE_SPACE_SCENE)
1425+
{
1426+
hasSceneReferredColorspace = true;
1427+
}
14221428
}
14231429

1424-
// Confirm all roles are valid.
1430+
// Confirm all roles used by the config are valid and that essential roles are present.
14251431
{
14261432
for(StringMap::const_iterator iter = getImpl()->m_roles.begin(),
14271433
end = getImpl()->m_roles.end(); iter!=end; ++iter)
@@ -1451,6 +1457,107 @@ void Config::validate() const
14511457

14521458
// AddColorSpace, addNamedTransform & setRole already check there is no name conflict.
14531459
}
1460+
1461+
1462+
// Check for interchange roles requirements - scene-referred and display-referred.
1463+
if (getMajorVersion() >= 2 && getMinorVersion() >= 2)
1464+
{
1465+
bool hasRoleSceneLinear = false;
1466+
bool hasRoleCompositingLog = false;
1467+
bool hasRoleColorTiming = false;
1468+
1469+
bool hasRoleAcesInterchange = false;
1470+
bool acesInterHasSceneRefColorspace = false;
1471+
bool hasRoleCieXyzD65Interchange = false;
1472+
bool cieInterHasDisplayRefColorspace = false;
1473+
1474+
for (auto const& role : getImpl()->m_roles)
1475+
{
1476+
if (Platform::Strcasecmp(role.first.c_str(), ROLE_SCENE_LINEAR) == 0)
1477+
{
1478+
hasRoleSceneLinear = true;
1479+
}
1480+
else if (Platform::Strcasecmp(role.first.c_str(), ROLE_COMPOSITING_LOG ) == 0)
1481+
{
1482+
hasRoleCompositingLog = true;
1483+
}
1484+
else if (Platform::Strcasecmp(role.first.c_str(), ROLE_COLOR_TIMING) == 0)
1485+
{
1486+
hasRoleColorTiming = true;
1487+
}
1488+
else if (Platform::Strcasecmp(role.first.c_str(), ROLE_INTERCHANGE_SCENE) == 0)
1489+
{
1490+
hasRoleAcesInterchange = true;
1491+
1492+
ConstColorSpaceRcPtr cs = getColorSpace(role.second.c_str());
1493+
acesInterHasSceneRefColorspace =
1494+
cs->getReferenceSpaceType() == REFERENCE_SPACE_SCENE;
1495+
}
1496+
else if (Platform::Strcasecmp(role.first.c_str(), ROLE_INTERCHANGE_DISPLAY) == 0)
1497+
{
1498+
hasRoleCieXyzD65Interchange = true;
1499+
1500+
ConstColorSpaceRcPtr cs = getColorSpace(role.second.c_str());
1501+
cieInterHasDisplayRefColorspace =
1502+
cs->getReferenceSpaceType() == REFERENCE_SPACE_DISPLAY;
1503+
}
1504+
}
1505+
1506+
// All LogError below are technically a validation failure, but only logging a message
1507+
// rather than throwing (for now). This is to make it possible for upgradeToLatestVersion
1508+
// to always result in a config that does not fail validation.
1509+
1510+
if (!hasRoleSceneLinear)
1511+
{
1512+
std::ostringstream os;
1513+
os << "The scene_linear role is required for a config version 2.2 or higher.";
1514+
LogError(os.str());
1515+
}
1516+
1517+
if (!hasRoleCompositingLog)
1518+
{
1519+
std::ostringstream os;
1520+
os << "The compositing_log role is required for a config version 2.2 or higher.";
1521+
LogError(os.str());
1522+
}
1523+
1524+
if (!hasRoleColorTiming)
1525+
{
1526+
std::ostringstream os;
1527+
os << "The color_timing role is required for a config version 2.2 or higher.";
1528+
LogError(os.str());
1529+
}
1530+
1531+
if (hasSceneReferredColorspace && !hasRoleAcesInterchange)
1532+
{
1533+
std::ostringstream os;
1534+
os << "The aces_interchange role is required when there are scene-referred";
1535+
os << " color spaces and the config version is 2.2 or higher.";
1536+
LogError(os.str());
1537+
}
1538+
else if (hasRoleAcesInterchange &&
1539+
!acesInterHasSceneRefColorspace)
1540+
{
1541+
std::ostringstream os;
1542+
os << "The aces_interchange role must be a scene-referred color space.";
1543+
LogError(os.str());
1544+
}
1545+
1546+
if (hasDisplayReferredColorspace && !hasRoleCieXyzD65Interchange)
1547+
{
1548+
std::ostringstream os;
1549+
os << "The cie_xyz_d65_interchange role is required when there are";
1550+
os << " display-referred color spaces and the config version is 2.2 or higher.";
1551+
LogError(os.str());
1552+
}
1553+
else if (hasRoleCieXyzD65Interchange &&
1554+
!cieInterHasDisplayRefColorspace)
1555+
{
1556+
std::ostringstream os;
1557+
os << "The cie_xyz_d65_interchange role must be a display-referred color space.";
1558+
LogError(os.str());
1559+
}
1560+
}
14541561
}
14551562

14561563
// Confirm all inactive color spaces or named transforms exist.
@@ -4858,7 +4965,6 @@ void Config::Impl::checkVersionConsistency() const
48584965
{
48594966
throw Exception("Only version 2 (or higher) can have NamedTransforms.");
48604967
}
4861-
48624968
}
48634969

48644970
void Config::setConfigIOProxy(ConfigIOProxyRcPtr ciop)

src/OpenColorIO/Logging.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ void LogMessage(LoggingLevel level, const char * message)
153153
}
154154
}
155155

156+
void LogError(const std::string & text)
157+
{
158+
AutoMutex lock(g_logmutex);
159+
InitLogging();
160+
161+
// Did not add a LOGGING_LEVEL_ERROR since the enum values are part of the user-facing
162+
// documentation and it is therefore difficult to insert an ERROR value since it would
163+
// naturally need to fall between 0 and 1. But there is no need since presumably users
164+
// that want to see warnings would also want to see errors.
165+
if(g_logginglevel<LOGGING_LEVEL_WARNING) return;
166+
167+
LogMessage("[OpenColorIO Error]: ", text);
168+
}
169+
156170
void LogWarning(const std::string & text)
157171
{
158172
AutoMutex lock(g_logmutex);

src/OpenColorIO/Logging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace OCIO_NAMESPACE
1313
{
14+
void LogError(const std::string & text);
1415
void LogWarning(const std::string & text);
1516
void LogInfo(const std::string & text);
1617
void LogDebug(const std::string & text);

0 commit comments

Comments
 (0)