@@ -243,7 +243,7 @@ static constexpr unsigned LastSupportedMajorVersion = OCIO_VERSION_MAJOR;
243243
244244// For each major version keep the most recent minor.
245245static 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
48644970void Config::setConfigIOProxy (ConfigIOProxyRcPtr ciop)
0 commit comments