Skip to content

Commit

Permalink
Add built-in transform for Display P3 and bump config version (#1814)
Browse files Browse the repository at this point in the history
* Add built-in display transform for Display P3

Signed-off-by: Doug Walker <[email protected]>

* Add URLs with DisplayP3 info

Signed-off-by: Doug Walker <[email protected]>

---------

Signed-off-by: Doug Walker <[email protected]>
  • Loading branch information
doug-walker committed Jul 27, 2023
1 parent 6dec6b2 commit 93ee2cc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static constexpr unsigned LastSupportedMajorVersion = OCIO_VERSION_MAJOR;

// For each major version keep the most recent minor.
static const unsigned int LastSupportedMinorVersion[] = {0, // Version 1
2 // Version 2
3 // Version 2
};

} // namespace
Expand Down Expand Up @@ -5030,6 +5030,12 @@ void Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform) cons
<< blt->getStyle() << "'.";
throw Exception(os.str().c_str());
}
if (m_majorVersion == 2 && m_minorVersion < 3
&& 0 == Platform::Strcasecmp(blt->getStyle(), "DISPLAY - CIE-XYZ-D65_to_DisplayP3"))
{
throw Exception("Only config version 2.3 (or higher) can have "
"BuiltinTransform style 'DISPLAY - CIE-XYZ-D65_to_DisplayP3'.");
}
}
else if (ConstCDLTransformRcPtr cdl = DynamicPtrCast<const CDLTransform>(transform))
{
Expand Down
32 changes: 32 additions & 0 deletions src/OpenColorIO/transforms/builtins/Displays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,38 @@ void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
CIE_XYZ_D65_to_P3_D60_BFD_Functor);
}

{
auto CIE_XYZ_D65_to_DisplayP3_Functor = [](OpRcPtrVec & ops)
{
MatrixOpData::MatrixArrayPtr matrix
= build_conversion_matrix_from_XYZ_D65(P3_D65::primaries, ADAPTATION_NONE);
CreateMatrixOp(ops, matrix, TRANSFORM_DIR_FORWARD);

// This color space is intended to be useful for macOS color spaces
// kCGColorSpaceDisplayP3 and kCGColorSpaceExtendedDisplayP3.
// The developer documentation does not seem to detail how the
// transfer function is extended below 0 for the "extended" version.
// However it does say that it uses the sRGB transfer function and
// the kCGColorSpaceExtendedSRGB color space extends by reflecting
// the curve around 0. Hence the use here of MONCURVE_MIRROR_REV.
// As with the other displays here, this built-in should be used
// with a RangeTransform to limit the results to [0,1], if necessary.
//
// https://developer.apple.com/documentation/coregraphics/kcgcolorspacedisplayp3
// https://developer.apple.com/documentation/appkit/nscolorspace/1644175-extendedsrgbcolorspace

const GammaOpData::Params rgbParams = { 2.4, 0.055 };
const GammaOpData::Params alphaParams = { 1.0, 0.0 };
auto gammaData = std::make_shared<GammaOpData>(GammaOpData::MONCURVE_MIRROR_REV,
rgbParams, rgbParams, rgbParams, alphaParams);
CreateGammaOp(ops, gammaData, TRANSFORM_DIR_FORWARD);
};

registry.addBuiltin("DISPLAY - CIE-XYZ-D65_to_DisplayP3",
"Convert CIE XYZ (D65 white) to Apple Display P3",
CIE_XYZ_D65_to_DisplayP3_Functor);
}

{
auto ST2084_to_Linear_Functor = [](OpRcPtrVec & ops)
{
Expand Down
18 changes: 10 additions & 8 deletions tests/cpu/Config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ OCIO_ADD_TEST(Config, serialize_group_transform)
config->setRole( OCIO::ROLE_COMPOSITING_LOG, cs->getName() );
}

config->setVersion(2, 2);
std::ostringstream os;
config->serialize(os);

Expand Down Expand Up @@ -643,6 +644,7 @@ OCIO_ADD_TEST(Config, serialize_searchpath)
cs->setName("default");
cs->setIsData(true);
config->addColorSpace(cs);
config->setVersion(2, 2);
}

std::ostringstream os;
Expand Down Expand Up @@ -2018,14 +2020,14 @@ OCIO_ADD_TEST(Config, version)
}

{
OCIO_CHECK_THROW_WHAT(config->setVersion(2, 3), OCIO::Exception,
"The minor version 3 is not supported for major version 2. "
"Maximum minor version is 2");
OCIO_CHECK_THROW_WHAT(config->setVersion(2, 9), OCIO::Exception,
"The minor version 9 is not supported for major version 2. "
"Maximum minor version is 3");

OCIO_CHECK_NO_THROW(config->setMajorVersion(2));
OCIO_CHECK_THROW_WHAT(config->setMinorVersion(3), OCIO::Exception,
"The minor version 3 is not supported for major version 2. "
"Maximum minor version is 2");
OCIO_CHECK_THROW_WHAT(config->setMinorVersion(9), OCIO::Exception,
"The minor version 9 is not supported for major version 2. "
"Maximum minor version is 3");
}

{
Expand Down Expand Up @@ -2057,9 +2059,9 @@ OCIO_ADD_TEST(Config, version_validation)

{
std::istringstream is;
is.str("ocio_profile_version: 2.3\n" + SIMPLE_PROFILE_END);
is.str("ocio_profile_version: 2.9\n" + SIMPLE_PROFILE_END);
OCIO_CHECK_THROW_WHAT(OCIO::Config::CreateFromStream(is), OCIO::Exception,
"The minor version 3 is not supported for major version 2");
"The minor version 9 is not supported for major version 2");
}

{
Expand Down
2 changes: 2 additions & 0 deletions tests/cpu/transforms/BuiltinTransform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ AllValues UnitTestValues
{ { 0.5f, 0.4f, 0.3f }, { 0.896805202281f, 0.627254277624f, 0.608228132100f } } },
{ "DISPLAY - CIE-XYZ-D65_to_G2.6-P3-D60-BFD",
{ { 0.5f, 0.4f, 0.3f }, { 0.892433142142f, 0.627011653770f, 0.608093643982f } } },
{ "DISPLAY - CIE-XYZ-D65_to_DisplayP3",
{ { 0.5f, 0.4f, 0.3f }, { 0.882580907776f, 0.581526360743f, 0.5606367050000f } } },

{ "CURVE - ST-2084_to_LINEAR",
{ { 0.5f, 0.4f, 0.3f }, { 0.922457089941f, 0.324479178538f, 0.100382263105f } } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ OCIO_ADD_TEST(Builtins, read_write)
// builtin transforms.

static constexpr char CONFIG_BUILTIN_TRANSFORMS[] {
R"(ocio_profile_version: 2.2
R"(ocio_profile_version: 2.3
environment:
{}
Expand Down

0 comments on commit 93ee2cc

Please sign in to comment.