Skip to content

Commit

Permalink
Adsk contrib - Fix issue with is colorspace linear (#1734)
Browse files Browse the repository at this point in the history
* Throw when the colorspace is undefined for isColorSpaceLinear method. (+ unit test)

Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com>

* Typo

Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com>

Signed-off-by: Cédrik Fuoco <cedrik.fuoco@autodesk.com>
Co-authored-by: Doug Walker <doug.walker@autodesk.com>
(cherry picked from commit 6d7c479)
  • Loading branch information
cedrik-fuoco-adsk committed Jan 5, 2023
1 parent 739d5cf commit 2cb6b5a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions tests/cpu/ColorSpace_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
6 changes: 6 additions & 0 deletions tests/python/ColorSpaceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2cb6b5a

Please sign in to comment.