From 6e349414d856b4789b9f29a5e4657d797e8a88e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 22 Nov 2022 09:44:43 -0500 Subject: [PATCH 1/2] Throw when the colorspace is undefined for isColorSpaceLinear method. (+ unit test) 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 | 7 +++++++ tests/cpu/ColorSpace_tests.cpp | 13 +++++++++++++ tests/python/ColorSpaceTest.py | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index bdf9994756..a96db363eb 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -3127,6 +3127,13 @@ bool Config::isColorSpaceLinear(const char * colorSpace, ReferenceSpaceType refe { auto cs = getColorSpace(colorSpace); + if (cs == nullptr) + { + std::ostringstream os; + os << "Could not test colorspace linearity. Colorspace " << colorSpace << " does not exist"; + throw Exception(os.str().c_str()); + } + if (cs->isData()) { return false; diff --git a/tests/cpu/ColorSpace_tests.cpp b/tests/cpu/ColorSpace_tests.cpp index fc3a6581a6..db959703c7 100644 --- a/tests/cpu/ColorSpace_tests.cpp +++ b/tests/cpu/ColorSpace_tests.cpp @@ -898,6 +898,19 @@ inactive_colorspaces: [display_linear-trans, scene_linear-trans] OCIO_CHECK_EQUAL_FROM(isLinearToDisplayReference, bDisplayExpected, line); }; + // Test undefined color spaces. + { + OCIO_CHECK_THROW_WHAT( + config->isColorSpaceLinear("colorspace_abc", OCIO::REFERENCE_SPACE_SCENE), OCIO::Exception, + "Could not test colorspace linearity. Colorspace colorspace_abc does not exist" + ); + + OCIO_CHECK_THROW_WHAT( + config->isColorSpaceLinear("colorspace_abc", OCIO::REFERENCE_SPACE_DISPLAY), OCIO::Exception, + "Could not test colorspace linearity. Colorspace colorspace_abc does not exist" + ); + } + { testSceneReferred("display_data", false, __LINE__); testSceneReferred("display_linear-enc", false, __LINE__); diff --git a/tests/python/ColorSpaceTest.py b/tests/python/ColorSpaceTest.py index 792bcf5fec..465539886c 100644 --- a/tests/python/ColorSpaceTest.py +++ b/tests/python/ColorSpaceTest.py @@ -579,6 +579,12 @@ def test_display_referred(self, cfg, cs_name, expected_value): ) self.assertEqual(is_linear_to_display_reference, expected_value) + # Test undefined color spaces. + with self.assertRaises(OCIO.Exception): + cfg.isColorSpaceLinear('colorspace_abc', OCIO.REFERENCE_SPACE_SCENE) + with self.assertRaises(OCIO.Exception): + cfg.isColorSpaceLinear('colorspace_abc', OCIO.REFERENCE_SPACE_DISPLAY) + # Test the scene referred color spaces. test_scene_referred(self, cfg, "display_data", False) test_scene_referred(self, cfg, "display_linear-enc", False) From a8f6a773effaccf844f72634ad47a3e39f6d1ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 30 Nov 2022 11:09:33 -0500 Subject: [PATCH 2/2] Typo 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 a96db363eb..665d522390 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -3130,7 +3130,7 @@ bool Config::isColorSpaceLinear(const char * colorSpace, ReferenceSpaceType refe if (cs == nullptr) { std::ostringstream os; - os << "Could not test colorspace linearity. Colorspace " << colorSpace << " does not exist"; + os << "Could not test colorspace linearity. Colorspace " << colorSpace << " does not exist."; throw Exception(os.str().c_str()); }