From 0ffd2b257d382cc295c9e281e49ead9e8f8eb42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Fri, 14 Apr 2023 15:35:48 -0400 Subject: [PATCH 1/7] Implements isInactiveColorSpace and getRoleColorSpace. Implements basic unit tests for those two methods. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 3 +++ src/OpenColorIO/Config.cpp | 39 ++++++++++++++++++++++++++++ tests/cpu/ColorSpace_tests.cpp | 42 +++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index a7d073f788..5a69b47273 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -652,6 +652,8 @@ class OCIOEXPORT Config */ void setInactiveColorSpaces(const char * inactiveColorSpaces); const char * getInactiveColorSpaces() const; + + bool isInactiveColorSpace(const char * colorspace) const; /** * \brief Return true if the specified color space is linear. @@ -720,6 +722,7 @@ class OCIOEXPORT Config * Return empty string if index is out of range. */ const char * getRoleColorSpace(int index) const; + const char * getRoleColorSpace(const char * roleName) const; /** * \defgroup Methods related to displays and views. diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 665d522390..d75ebea506 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -2918,6 +2918,22 @@ const char * Config::getInactiveColorSpaces() const return getImpl()->m_inactiveColorSpaceNamesConf.c_str(); } +bool Config::isInactiveColorSpace(const char * colorspace) const +{ + StringUtils::StringVec svec; + pystring::split(getImpl()->m_inactiveColorSpaceNamesConf.c_str(), svec, ", "); + + for (int i = 0; i < svec.size(); i++) + { + if (StringUtils::Compare(colorspace, svec.at(i))) + { + // Colorspace is inactive. + return true; + } + } + return false; +} + void Config::addColorSpace(const ConstColorSpaceRcPtr & original) { const std::string name(original->getName()); @@ -3357,6 +3373,29 @@ const char * Config::getRoleColorSpace(int index) const return LookupRole(getImpl()->m_roles, getRoleName(index)); } +const char * Config::getRoleColorSpace(const char * roleName) const +{ + if (roleName && !roleName[0]) + { + std::ostringstream os; + os << "Could not find an empty role. Empty name for a role is invalid."; + throw Exception(os.str().c_str()); + } + + for (int i = 0; i < getImpl()->m_roles.size(); i++) + { + if (StringUtils::Compare(roleName, getRoleName(i))) + { + // Found the specified role. + return LookupRole(getImpl()->m_roles, getRoleName(i)); + } + } + + std::ostringstream os; + os << "Could not find a color space assigned to role '" << roleName << "'."; + throw Exception(os.str().c_str()); +} + /////////////////////////////////////////////////////////////////////////// // // Named Transforms diff --git a/tests/cpu/ColorSpace_tests.cpp b/tests/cpu/ColorSpace_tests.cpp index db959703c7..e53057e38e 100644 --- a/tests/cpu/ColorSpace_tests.cpp +++ b/tests/cpu/ColorSpace_tests.cpp @@ -1188,4 +1188,46 @@ ocio_profile_version: 2 srcColorSpaceName.c_str()); checkProcessorInverse(proc); } +} + +OCIO_ADD_TEST(Config, inactive_colorspaces) +{ + // Using Built-in config to test the getInactiveColorSpace method. + const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + OCIO::ConstConfigRcPtr config; + + OCIO_CHECK_NO_THROW( + config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) + ); + OCIO_REQUIRE_ASSERT(config); + + OCIO_CHECK_NO_THROW(config->validate()); + + { + OCIO_CHECK_EQUAL(config->isInactiveColorSpace(""), false); + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("joe"), false); + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Linear P3-D65"), false); + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Rec.1886 Rec.2020 - Display"), true); + + + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("data")), std::string("Raw")); + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("cie_xyz_d65_interchange")), std::string("CIE-XYZ-D65")); + + OCIO_CHECK_THROW_WHAT( + config->getRoleColorSpace("wrong_role"), + OCIO::Exception, + "Could not find a color space assigned to role 'wrong_role'." + ); + + OCIO_CHECK_THROW_WHAT( + config->getRoleColorSpace(""), + OCIO::Exception, + "Could not find an empty role. Empty name for a role is invalid." + ); + } +} + +OCIO_ADD_TEST(Config, role_resolutions) +{ + } \ No newline at end of file From aede084cea340b4b4f037c689c1fc630f204ba9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Mon, 17 Apr 2023 12:29:54 -0400 Subject: [PATCH 2/7] Added header for the two new methods. Added the python bindings equivalents. Tweak C++ unit tests and added python unit tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 11 +++++++++ src/bindings/python/PyConfig.cpp | 6 +++++ tests/cpu/ColorSpace_tests.cpp | 38 ++++++++++++++++++++++++------- tests/python/ColorSpaceTest.py | 36 ++++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 9 deletions(-) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index 5a69b47273..df423de455 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -653,6 +653,11 @@ class OCIOEXPORT Config void setInactiveColorSpaces(const char * inactiveColorSpaces); const char * getInactiveColorSpaces() const; + /** + * \brief Return true if the specified color space is inactive. + * + * \param colorspace Color space name + */ bool isInactiveColorSpace(const char * colorspace) const; /** @@ -722,6 +727,12 @@ class OCIOEXPORT Config * Return empty string if index is out of range. */ const char * getRoleColorSpace(int index) const; + /** + * \brief Get the role color space based on the specified role name. + * + * \param roleName Role name to resolve + * \return Color space name + */ const char * getRoleColorSpace(const char * roleName) const; /** diff --git a/src/bindings/python/PyConfig.cpp b/src/bindings/python/PyConfig.cpp index 48270f2eca..e9b533efb0 100644 --- a/src/bindings/python/PyConfig.cpp +++ b/src/bindings/python/PyConfig.cpp @@ -334,6 +334,12 @@ void bindPyConfig(py::module & m) DOC(Config, setInactiveColorSpaces)) .def("getInactiveColorSpaces", &Config::getInactiveColorSpaces, DOC(Config, getInactiveColorSpaces)) + .def("isInactiveColorSpace", &Config::isInactiveColorSpace, "colorspace"_a, + DOC(Config, isInactiveColorSpace)) + .def("getRoleColorSpace", + (const char * (Config::*)(const char *) const) &Config::getRoleColorSpace, + "roleName"_a, + DOC(Config, getRoleColorSpace)) // Roles .def("setRole", &Config::setRole, "role"_a, "colorSpaceName"_a, diff --git a/tests/cpu/ColorSpace_tests.cpp b/tests/cpu/ColorSpace_tests.cpp index e53057e38e..fc6ad02b95 100644 --- a/tests/cpu/ColorSpace_tests.cpp +++ b/tests/cpu/ColorSpace_tests.cpp @@ -1204,30 +1204,52 @@ OCIO_ADD_TEST(Config, inactive_colorspaces) OCIO_CHECK_NO_THROW(config->validate()); { + // Test various combinations of input. + OCIO_CHECK_EQUAL(config->isInactiveColorSpace(""), false); - OCIO_CHECK_EQUAL(config->isInactiveColorSpace("joe"), false); + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("fake-colorspace-name"), false); + + // Test existing colorspaces from cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + + // Colorspace exists and is inactive. OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Linear P3-D65"), false); + + // Colorspace exists and is active. OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Rec.1886 Rec.2020 - Display"), true); + } +} +OCIO_ADD_TEST(Config, role_resolutions) +{ + // Using Built-in config to test the getInactiveColorSpace method. + const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + OCIO::ConstConfigRcPtr config; + OCIO_CHECK_NO_THROW( + config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) + ); + OCIO_REQUIRE_ASSERT(config); + + OCIO_CHECK_NO_THROW(config->validate()); + + { + // Test existing roles in cg-config-v1.0.0_aces-v1.3_ocio-v2.1. OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("data")), std::string("Raw")); - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("cie_xyz_d65_interchange")), std::string("CIE-XYZ-D65")); + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("cie_xyz_d65_interchange")), + std::string("CIE-XYZ-D65")); + // Test a unknown role. OCIO_CHECK_THROW_WHAT( config->getRoleColorSpace("wrong_role"), OCIO::Exception, "Could not find a color space assigned to role 'wrong_role'." ); + // Test an empty input. OCIO_CHECK_THROW_WHAT( config->getRoleColorSpace(""), OCIO::Exception, "Could not find an empty role. Empty name for a role is invalid." ); - } -} - -OCIO_ADD_TEST(Config, role_resolutions) -{ - + } } \ No newline at end of file diff --git a/tests/python/ColorSpaceTest.py b/tests/python/ColorSpaceTest.py index 465539886c..588c761d18 100644 --- a/tests/python/ColorSpaceTest.py +++ b/tests/python/ColorSpaceTest.py @@ -754,4 +754,38 @@ def check_processor_inv(self, p): # Test linear color space to_ref direction. cfg.setInactiveColorSpaces("Linear ITU-R BT.709, Texture -- sRGB") p = OCIO.Config.GetProcessorFromBuiltinColorSpace(builtin_csname, cfg, src_csname) - check_processor_inv(self, p) \ No newline at end of file + check_processor_inv(self, p) + + def test_inactive_colorspaces(self): + config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + config.validate() + + # Test various combinations of input. + + self.assertFalse(config.isInactiveColorSpace("")) + self.assertFalse(config.isInactiveColorSpace("fake-colorspace-name")) + + # Test existing colorspaces from cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + + # Colorspace exists and is inactive. + self.assertFalse(config.isInactiveColorSpace("Linear P3-D65")) + + # Colorspace exists and is active. + self.assertTrue(config.isInactiveColorSpace("Rec.1886 Rec.2020 - Display")) + + def test_role_resolutions(self): + config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + config.validate() + + self.assertEqual(config.getRoleColorSpace("data"), "Raw") + self.assertEqual(config.getRoleColorSpace("cie_xyz_d65_interchange"), "CIE-XYZ-D65") + + with self.assertRaises(OCIO.Exception) as cm: + config.getRoleColorSpace("wrong_role") + self.assertEqual(str(cm.exception), + "Could not find a color space assigned to role 'wrong_role'.") + + with self.assertRaises(OCIO.Exception) as cm: + config.getRoleColorSpace("") + self.assertEqual(str(cm.exception), + "Could not find an empty role. Empty name for a role is invalid.") \ No newline at end of file From 85e2f68918dbaf6e91f0b566d6e1bb317baf869f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 18 Apr 2023 10:23:25 -0400 Subject: [PATCH 3/7] Minimize usage for getRoleName MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/Config.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index d75ebea506..2bd06bfb92 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -3384,10 +3384,11 @@ const char * Config::getRoleColorSpace(const char * roleName) const for (int i = 0; i < getImpl()->m_roles.size(); i++) { - if (StringUtils::Compare(roleName, getRoleName(i))) + const char * name = getRoleName(i); + if (StringUtils::Compare(roleName, name)) { // Found the specified role. - return LookupRole(getImpl()->m_roles, getRoleName(i)); + return LookupRole(getImpl()->m_roles, name); } } From c3abe8055a949315d5a54079124bcd436f5d6ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 19 Apr 2023 11:00:48 -0400 Subject: [PATCH 4/7] Documentations Moving the new unit tests Adding extra tests for un-tested methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 13 ++-- src/OpenColorIO/Config.cpp | 24 +------- src/bindings/python/PyColorSpaceSet.cpp | 2 + src/bindings/python/PyConfig.cpp | 10 +-- tests/cpu/ColorSpace_tests.cpp | 64 ------------------- tests/cpu/Config_tests.cpp | 56 +++++++++++++++++ tests/python/ColorSpaceTest.py | 36 +---------- tests/python/ConfigTest.py | 81 +++++++++++++++++++++++++ 8 files changed, 152 insertions(+), 134 deletions(-) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index df423de455..24a73f46b3 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -653,11 +653,7 @@ class OCIOEXPORT Config void setInactiveColorSpaces(const char * inactiveColorSpaces); const char * getInactiveColorSpaces() const; - /** - * \brief Return true if the specified color space is inactive. - * - * \param colorspace Color space name - */ + /// Return true if the color space name is present in the inactive_colorspaces list. bool isInactiveColorSpace(const char * colorspace) const; /** @@ -728,12 +724,11 @@ class OCIOEXPORT Config */ const char * getRoleColorSpace(int index) const; /** - * \brief Get the role color space based on the specified role name. + * \brief Get the color space name used for the specified role. * - * \param roleName Role name to resolve - * \return Color space name + * Return an empty string if the role is not present */ - const char * getRoleColorSpace(const char * roleName) const; + const char * getRoleColorSpace(const char * roleName) const noexcept; /** * \defgroup Methods related to displays and views. diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 2bd06bfb92..3c3a607683 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -3373,28 +3373,10 @@ const char * Config::getRoleColorSpace(int index) const return LookupRole(getImpl()->m_roles, getRoleName(index)); } -const char * Config::getRoleColorSpace(const char * roleName) const +const char * Config::getRoleColorSpace(const char * roleName) const noexcept { - if (roleName && !roleName[0]) - { - std::ostringstream os; - os << "Could not find an empty role. Empty name for a role is invalid."; - throw Exception(os.str().c_str()); - } - - for (int i = 0; i < getImpl()->m_roles.size(); i++) - { - const char * name = getRoleName(i); - if (StringUtils::Compare(roleName, name)) - { - // Found the specified role. - return LookupRole(getImpl()->m_roles, name); - } - } - - std::ostringstream os; - os << "Could not find a color space assigned to role '" << roleName << "'."; - throw Exception(os.str().c_str()); + if (!roleName || !roleName[0]) return ""; + return LookupRole(getImpl()->m_roles, roleName); } /////////////////////////////////////////////////////////////////////////// diff --git a/src/bindings/python/PyColorSpaceSet.cpp b/src/bindings/python/PyColorSpaceSet.cpp index adab62a1ff..d6c4831e23 100644 --- a/src/bindings/python/PyColorSpaceSet.cpp +++ b/src/bindings/python/PyColorSpaceSet.cpp @@ -80,6 +80,8 @@ void bindPyColorSpaceSet(py::module & m) }) .def("getColorSpace", &ColorSpaceSet::getColorSpace, "name"_a, DOC(ColorSpaceSet, getColorSpace)) + .def("hasColorSpace", &ColorSpaceSet::hasColorSpace, "name"_a, + DOC(ColorSpaceSet, hasColorSpace)) .def("addColorSpace", &ColorSpaceSet::addColorSpace, "colorSpace"_a, DOC(ColorSpaceSet, addColorSpace)) .def("addColorSpaces", &ColorSpaceSet::addColorSpaces, "colorSpaces"_a, diff --git a/src/bindings/python/PyConfig.cpp b/src/bindings/python/PyConfig.cpp index e9b533efb0..6b4bafe34d 100644 --- a/src/bindings/python/PyConfig.cpp +++ b/src/bindings/python/PyConfig.cpp @@ -335,11 +335,7 @@ void bindPyConfig(py::module & m) .def("getInactiveColorSpaces", &Config::getInactiveColorSpaces, DOC(Config, getInactiveColorSpaces)) .def("isInactiveColorSpace", &Config::isInactiveColorSpace, "colorspace"_a, - DOC(Config, isInactiveColorSpace)) - .def("getRoleColorSpace", - (const char * (Config::*)(const char *) const) &Config::getRoleColorSpace, - "roleName"_a, - DOC(Config, getRoleColorSpace)) + DOC(Config, isInactiveColorSpace)) // Roles .def("setRole", &Config::setRole, "role"_a, "colorSpaceName"_a, @@ -354,6 +350,10 @@ void bindPyConfig(py::module & m) { return RoleColorSpaceIterator(self); }) + .def("getRoleColorSpace", + (const char * (Config::*)(const char *) const) &Config::getRoleColorSpace, + "roleName"_a, + DOC(Config, getRoleColorSpace)) // Display/View Registration .def("addSharedView", diff --git a/tests/cpu/ColorSpace_tests.cpp b/tests/cpu/ColorSpace_tests.cpp index fc6ad02b95..db959703c7 100644 --- a/tests/cpu/ColorSpace_tests.cpp +++ b/tests/cpu/ColorSpace_tests.cpp @@ -1188,68 +1188,4 @@ ocio_profile_version: 2 srcColorSpaceName.c_str()); checkProcessorInverse(proc); } -} - -OCIO_ADD_TEST(Config, inactive_colorspaces) -{ - // Using Built-in config to test the getInactiveColorSpace method. - const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; - OCIO::ConstConfigRcPtr config; - - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - - OCIO_CHECK_NO_THROW(config->validate()); - - { - // Test various combinations of input. - - OCIO_CHECK_EQUAL(config->isInactiveColorSpace(""), false); - OCIO_CHECK_EQUAL(config->isInactiveColorSpace("fake-colorspace-name"), false); - - // Test existing colorspaces from cg-config-v1.0.0_aces-v1.3_ocio-v2.1. - - // Colorspace exists and is inactive. - OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Linear P3-D65"), false); - - // Colorspace exists and is active. - OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Rec.1886 Rec.2020 - Display"), true); - } -} - -OCIO_ADD_TEST(Config, role_resolutions) -{ - // Using Built-in config to test the getInactiveColorSpace method. - const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; - OCIO::ConstConfigRcPtr config; - - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - - OCIO_CHECK_NO_THROW(config->validate()); - - { - // Test existing roles in cg-config-v1.0.0_aces-v1.3_ocio-v2.1. - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("data")), std::string("Raw")); - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("cie_xyz_d65_interchange")), - std::string("CIE-XYZ-D65")); - - // Test a unknown role. - OCIO_CHECK_THROW_WHAT( - config->getRoleColorSpace("wrong_role"), - OCIO::Exception, - "Could not find a color space assigned to role 'wrong_role'." - ); - - // Test an empty input. - OCIO_CHECK_THROW_WHAT( - config->getRoleColorSpace(""), - OCIO::Exception, - "Could not find an empty role. Empty name for a role is invalid." - ); - } } \ No newline at end of file diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index 76b668fc8e..fc4cf5292c 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -314,6 +314,33 @@ OCIO_ADD_TEST(Config, roles) OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(-4)), ""); } +OCIO_ADD_TEST(Config, role_resolutions) +{ + // Using Built-in config to test the getInactiveColorSpace method. + const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + OCIO::ConstConfigRcPtr config; + + OCIO_CHECK_NO_THROW( + config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) + ); + OCIO_REQUIRE_ASSERT(config); + + OCIO_CHECK_NO_THROW(config->validate()); + + { + // Test existing roles in cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("data")), std::string("Raw")); + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("cie_xyz_d65_interchange")), + std::string("CIE-XYZ-D65")); + + // Test a unknown role. + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("wrong_role")), std::string("")); + + // Test an empty input. + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("")), std::string("")); + } +} + OCIO_ADD_TEST(Config, required_roles_for_version_2_2) { // Test Setup @@ -5710,6 +5737,35 @@ OCIO_ADD_TEST(Config, inactive_color_space) OCIO::COLORSPACE_ALL, 1)); } +OCIO_ADD_TEST(Config, inactive_colorspaces) +{ + // Using Built-in config to test the getInactiveColorSpace method. + const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + OCIO::ConstConfigRcPtr config; + + OCIO_CHECK_NO_THROW( + config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) + ); + OCIO_REQUIRE_ASSERT(config); + + OCIO_CHECK_NO_THROW(config->validate()); + + { + // Test various combinations of input. + + OCIO_CHECK_EQUAL(config->isInactiveColorSpace(""), false); + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("fake-colorspace-name"), false); + + // Test existing colorspaces from cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + + // Colorspace exists and is active. + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Linear P3-D65"), false); + + // Colorspace exists and is inactive. + OCIO_CHECK_EQUAL(config->isInactiveColorSpace("Rec.1886 Rec.2020 - Display"), true); + } +} + OCIO_ADD_TEST(Config, inactive_color_space_precedence) { // The test demonstrates that an API request supersedes the env. variable and the diff --git a/tests/python/ColorSpaceTest.py b/tests/python/ColorSpaceTest.py index 588c761d18..465539886c 100644 --- a/tests/python/ColorSpaceTest.py +++ b/tests/python/ColorSpaceTest.py @@ -754,38 +754,4 @@ def check_processor_inv(self, p): # Test linear color space to_ref direction. cfg.setInactiveColorSpaces("Linear ITU-R BT.709, Texture -- sRGB") p = OCIO.Config.GetProcessorFromBuiltinColorSpace(builtin_csname, cfg, src_csname) - check_processor_inv(self, p) - - def test_inactive_colorspaces(self): - config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - config.validate() - - # Test various combinations of input. - - self.assertFalse(config.isInactiveColorSpace("")) - self.assertFalse(config.isInactiveColorSpace("fake-colorspace-name")) - - # Test existing colorspaces from cg-config-v1.0.0_aces-v1.3_ocio-v2.1. - - # Colorspace exists and is inactive. - self.assertFalse(config.isInactiveColorSpace("Linear P3-D65")) - - # Colorspace exists and is active. - self.assertTrue(config.isInactiveColorSpace("Rec.1886 Rec.2020 - Display")) - - def test_role_resolutions(self): - config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - config.validate() - - self.assertEqual(config.getRoleColorSpace("data"), "Raw") - self.assertEqual(config.getRoleColorSpace("cie_xyz_d65_interchange"), "CIE-XYZ-D65") - - with self.assertRaises(OCIO.Exception) as cm: - config.getRoleColorSpace("wrong_role") - self.assertEqual(str(cm.exception), - "Could not find a color space assigned to role 'wrong_role'.") - - with self.assertRaises(OCIO.Exception) as cm: - config.getRoleColorSpace("") - self.assertEqual(str(cm.exception), - "Could not find an empty role. Empty name for a role is invalid.") \ No newline at end of file + check_processor_inv(self, p) \ No newline at end of file diff --git a/tests/python/ConfigTest.py b/tests/python/ConfigTest.py index 1ea0e2d928..86ed140ef2 100644 --- a/tests/python/ConfigTest.py +++ b/tests/python/ConfigTest.py @@ -1186,6 +1186,87 @@ def lutExists(filepath): processor = config.getProcessor("c1", "c2") processor.getDefaultCPUProcessor() + + def test_inactive_colorspaces(self): + config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + config.validate() + + # Test various combinations of input. + + self.assertFalse(config.isInactiveColorSpace("")) + self.assertFalse(config.isInactiveColorSpace("fake-colorspace-name")) + + # Test existing colorspaces from cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + + # Colorspace exists and is active. + self.assertFalse(config.isInactiveColorSpace("Linear P3-D65")) + + # Colorspace exists and is inactive. + self.assertTrue(config.isInactiveColorSpace("Rec.1886 Rec.2020 - Display")) + + def test_roles(self): + config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + config.validate() + + # ***************************** + # Test getRoleNames interface. + # ***************************** + + rolesNames = config.getRoleNames() + + # Test the numbers of elements. + self.assertEqual(len(rolesNames), 9) + + # Test that the first element is an actual role. + self.assertTrue(config.hasRole(rolesNames[0])) + + # ************************* + # Test getRoles interface. + # ************************* + rolesAndColorspaces = config.getRoles() + + # Test the numbers of elements + self.assertEqual(len(rolesAndColorspaces), 9) + + # Test the first element. + colorspaces = config.getColorSpaces(None) + + # Test that the first element has an existing role and an existing colorspace. + self.assertTrue(config.hasRole(rolesAndColorspaces[0][0])) + self.assertTrue(colorspaces.hasColorSpace(rolesAndColorspaces[0][1])) + + def test_role_resolutions(self): + config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + config.validate() + + self.assertEqual(config.getRoleColorSpace("data"), "Raw") + self.assertEqual(config.getRoleColorSpace("cie_xyz_d65_interchange"), "CIE-XYZ-D65") + + # Test a unknown role. + self.assertEqual(config.getRoleColorSpace("wrong_role"), "") + + # Test an empty input. + self.assertEqual(config.getRoleColorSpace(""), "") + + def test_role_assignation(self): + config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + config.validate() + + # Test that empty role name returns false. + self.assertFalse(config.hasRole("")) + + # Test if color_picking role is present. + self.assertTrue(config.hasRole("color_picking")) + + # Test the original value of the role color_picking. + self.assertEqual(config.getRoleColorSpace("color_picking"), "sRGB - Texture") + + # Change the color space assigned to the role color_picking. + config.setRole(OCIO.ROLE_COLOR_PICKING, "ACEScct") + + # Test the new value of the role color_picking. + self.assertEqual(config.getRoleColorSpace("color_picking"), "ACEScct") + class ConfigVirtualWithActiveDisplayTest(unittest.TestCase): def setUp(self): self.cfg_active_display = OCIO.Config.CreateFromStream( From 897595a8ec650986821b25831503fad784299bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 20 Apr 2023 11:10:17 -0400 Subject: [PATCH 5/7] Tweaking unit tests and documentions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 2 +- src/OpenColorIO/Config.cpp | 2 +- tests/cpu/Config_tests.cpp | 31 +++++++------------------------ tests/python/ConfigTest.py | 12 ++++++------ 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index 24a73f46b3..6acae077c9 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -654,7 +654,7 @@ class OCIOEXPORT Config const char * getInactiveColorSpaces() const; /// Return true if the color space name is present in the inactive_colorspaces list. - bool isInactiveColorSpace(const char * colorspace) const; + bool isInactiveColorSpace(const char * colorspace) const noexcept; /** * \brief Return true if the specified color space is linear. diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 3c3a607683..2be99849b2 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -2918,7 +2918,7 @@ const char * Config::getInactiveColorSpaces() const return getImpl()->m_inactiveColorSpaceNamesConf.c_str(); } -bool Config::isInactiveColorSpace(const char * colorspace) const +bool Config::isInactiveColorSpace(const char * colorspace) const noexcept { StringUtils::StringVec svec; pystring::split(getImpl()->m_inactiveColorSpaceNamesConf.c_str(), svec, ", "); diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index fc4cf5292c..4d8c3c81be 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -312,33 +312,16 @@ OCIO_ADD_TEST(Config, roles) OCIO_CHECK_EQUAL(std::string(config->getRoleName(-4)), ""); OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(-4)), ""); -} - -OCIO_ADD_TEST(Config, role_resolutions) -{ - // Using Built-in config to test the getInactiveColorSpace method. - const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; - OCIO::ConstConfigRcPtr config; - - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - OCIO_CHECK_NO_THROW(config->validate()); - - { - // Test existing roles in cg-config-v1.0.0_aces-v1.3_ocio-v2.1. - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("data")), std::string("Raw")); - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("cie_xyz_d65_interchange")), - std::string("CIE-XYZ-D65")); + // Test existing roles in cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("scene_linear")), std::string("lnh")); + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("compositing_log")), std::string("lgh")); - // Test a unknown role. - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("wrong_role")), std::string("")); + // Test a unknown role. + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("wrong_role")), std::string("")); - // Test an empty input. - OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("")), std::string("")); - } + // Test an empty input. + OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("")), std::string("")); } OCIO_ADD_TEST(Config, required_roles_for_version_2_2) diff --git a/tests/python/ConfigTest.py b/tests/python/ConfigTest.py index 86ed140ef2..50481cbd26 100644 --- a/tests/python/ConfigTest.py +++ b/tests/python/ConfigTest.py @@ -1235,9 +1235,9 @@ def test_roles(self): self.assertTrue(config.hasRole(rolesAndColorspaces[0][0])) self.assertTrue(colorspaces.hasColorSpace(rolesAndColorspaces[0][1])) - def test_role_resolutions(self): - config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - config.validate() + # ********************** + # Test role resolutions + # ********************** self.assertEqual(config.getRoleColorSpace("data"), "Raw") self.assertEqual(config.getRoleColorSpace("cie_xyz_d65_interchange"), "CIE-XYZ-D65") @@ -1248,9 +1248,9 @@ def test_role_resolutions(self): # Test an empty input. self.assertEqual(config.getRoleColorSpace(""), "") - def test_role_assignation(self): - config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - config.validate() + # ********************** + # Test role assignation + # ********************** # Test that empty role name returns false. self.assertFalse(config.hasRole("")) From d8e59c38b56bd5f423502f7ae9198bf4b8bdb592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Fri, 21 Apr 2023 11:03:20 -0400 Subject: [PATCH 6/7] Fix build failure on Linux and Mac. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 2be99849b2..a5eef33b96 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -2923,7 +2923,7 @@ bool Config::isInactiveColorSpace(const char * colorspace) const noexcept StringUtils::StringVec svec; pystring::split(getImpl()->m_inactiveColorSpaceNamesConf.c_str(), svec, ", "); - for (int i = 0; i < svec.size(); i++) + for (size_t i = 0; i < svec.size(); i++) { if (StringUtils::Compare(colorspace, svec.at(i))) { From f1d52812d2244ebc7fdb14f43f4b4d6eed9747cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 3 May 2023 08:39:02 -0400 Subject: [PATCH 7/7] Fix comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- tests/cpu/Config_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index 4d8c3c81be..cb0977de42 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -313,7 +313,7 @@ OCIO_ADD_TEST(Config, roles) OCIO_CHECK_EQUAL(std::string(config->getRoleName(-4)), ""); OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace(-4)), ""); - // Test existing roles in cg-config-v1.0.0_aces-v1.3_ocio-v2.1. + // Test existing roles. OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("scene_linear")), std::string("lnh")); OCIO_CHECK_EQUAL(std::string(config->getRoleColorSpace("compositing_log")), std::string("lgh"));