Skip to content

Commit

Permalink
test: improve color management test in imagebufalgo_test (#4063)
Browse files Browse the repository at this point in the history
Add a few more assertion checks and error messages in imagebufalgo_test.

I observe that if somebody runs the testsuite with `$OCIO` set to a
config that doesn't contain the required color space names for this
test, it will fail. As a backstop, use the default built-in config if
the initial request fails. That will always give a working processor
between these spaces if OCIO >= 2.2 is being used.

Also one more tiny SPI-specific enhancement to hacky identification of
nonconforming color space names in our old configs.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Nov 27, 2023
1 parent 5f1e5c6 commit 169de93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/libOpenImageIO/color_ocio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ ColorConfig::Impl::classify_by_name(CSInfo& cs)
} else if (cs.name == "srgbf" || cs.name == "srgbh" || cs.name == "srgb16"
|| cs.name == "srgb8") {
cs.setflag(CSInfo::is_srgb, srgb_alias);
} else if (cs.name == "srgblnf" || cs.name == "srgblnh"
|| cs.name == "srgbln16" || cs.name == "srgbln8") {
cs.setflag(CSInfo::is_lin_srgb, lin_srgb_alias);
}
#endif

Expand Down
26 changes: 19 additions & 7 deletions src/libOpenImageIO/imagebufalgo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,19 +1140,31 @@ void
test_color_management()
{
ColorConfig config;
auto processor = config.createColorProcessor("lin_srgb", "srgb");
// These color spaces might not be found if the site running this test
// has a weirdo OCIO config that doesn't contain those names. If we fail,
// try again using the built-in config (OCIO 2.2+) and hope for the best.
if (!processor)
processor = ColorConfig("ocio://default")
.createColorProcessor("lin_srgb", "srgb");
OIIO_CHECK_ASSERT(processor);

// Test the IBA::colorconvert version that works on a color at a time
{
auto processor = config.createColorProcessor("lin_srgb", "srgb");
float rgb[3] = { 0.5f, 0.5f, 0.5f };
ImageBufAlgo::colorconvert(rgb, processor.get(), false);
float rgb[3] = { 0.5f, 0.5f, 0.5f };
bool r = ImageBufAlgo::colorconvert(rgb, processor.get(), false);
OIIO_CHECK_ASSERT(r);
if (!r)
OIIO::print("colorconvert error: {}\n", OIIO::geterror());
OIIO_CHECK_EQUAL_THRESH(rgb[1], 0.735356983052449f, 1.0e-5);
}
{
auto processor = config.createColorProcessor("lin_srgb", "srgb");
float rgb[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
ImageBufAlgo::colorconvert(rgb, processor.get(), true);
OIIO_CHECK_EQUAL_THRESH(rgb[1], 0.735356983052449f, 1.0e-5);
float rgba[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
bool r = ImageBufAlgo::colorconvert(rgba, processor.get(), true);
OIIO_CHECK_ASSERT(r);
if (!r)
OIIO::print("colorconvert error: {}\n", OIIO::geterror());
OIIO_CHECK_EQUAL_THRESH(rgba[1], 0.735356983052449f, 1.0e-5);
}
}

Expand Down

0 comments on commit 169de93

Please sign in to comment.