diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index d97a37636..53ffa8315 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -1136,6 +1136,11 @@ class OCIOEXPORT Config * intended to be temporary (i.e. for the current session) and are not saved to a config file. */ bool isDisplayTemporary(int index) const noexcept; + /** + * Allows setting the flag that controls whether a display is temporary. This may be helpful, + * for example, to share a config with a temporary instantiated display with an OFX plug-in. + */ + void setDisplayTemporary(int index, bool isTemporary) noexcept; /** * Get either the shared or display-defined views for a display. The diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 727d434e9..ad19b39c7 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4170,6 +4170,18 @@ bool Config::isDisplayTemporary(int index) const noexcept return false; } +void Config::setDisplayTemporary(int index, bool isTemporary) noexcept +{ + if (index >= 0 || index < static_cast(getImpl()->m_displays.size())) + { + getImpl()->m_displays[index].second.m_temporary = isTemporary; + + getImpl()->m_displayCache.clear(); + AutoMutex lock(getImpl()->m_cacheidMutex); + getImpl()->resetCacheIDs(); + } +} + int Config::getNumViews(ViewType type, const char * display) const { if (!display || !*display) diff --git a/src/bindings/python/PyConfig.cpp b/src/bindings/python/PyConfig.cpp index 104d017f8..58f3f52fc 100644 --- a/src/bindings/python/PyConfig.cpp +++ b/src/bindings/python/PyConfig.cpp @@ -552,6 +552,18 @@ void bindPyConfig(py::module & m) return false; }, "display"_a) + .def("setDisplayTemporary", [](ConfigRcPtr & self, const std::string & display, bool isTemporary) + { + for (int i = 0; i < self->getNumDisplaysAll(); i++) + { + std::string other(self->getDisplayAll(i)); + if (StringUtils::Compare(display, other)) + { + self->setDisplayTemporary(i, isTemporary); + } + } + }, + "display"_a, "isTemporary"_a) .def_static("AreVirtualViewsEqual", [](const ConstConfigRcPtr & first, const ConstConfigRcPtr & second, const char * viewName) diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index 6a310aae0..b2a272f0e 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -8657,6 +8657,10 @@ active_views: [] OCIO_CHECK_EQUAL(2, cfg->getNumViews(OCIO::VIEW_DISPLAY_DEFINED, displayName.c_str())); OCIO_CHECK_EQUAL(1, cfg->getNumViews(OCIO::VIEW_SHARED, displayName.c_str())); + // The new display is marked as temporary. + OCIO_CHECK_ASSERT(!cfg->isDisplayTemporary(config->getNumDisplays() - 1)); + OCIO_CHECK_ASSERT(cfg->isDisplayTemporary(config->getNumDisplays())); + // Check the created display color space. OCIO::ConstColorSpaceRcPtr cs = cfg->getColorSpace(displayName.c_str()); @@ -8707,6 +8711,33 @@ active_views: [] OCIO_CHECK_EQUAL(cfg->getNumColorSpaces() - 1, config2->getNumColorSpaces()); } + // Check that the display may be marked as non-temporary and therefore serialized in a config. + + { + OCIO_CHECK_ASSERT(cfg->isDisplayTemporary(config->getNumDisplays())); + cfg->setDisplayTemporary(config->getNumDisplays(), false); + OCIO_CHECK_ASSERT(!cfg->isDisplayTemporary(config->getNumDisplays())); + + std::ostringstream oss2; + OCIO_CHECK_NO_THROW(oss2 << *cfg.get()); + + std::istringstream iss2; + iss2.str(oss2.str()); + + OCIO::ConstConfigRcPtr config2; + OCIO_CHECK_NO_THROW(config2 = OCIO::Config::CreateFromStream(iss2)); + + // Check that (display, view) pair created by the virtual display instantiation is present. + + OCIO_CHECK_EQUAL(config->getNumDisplays() + 1, config2->getNumDisplays()); + OCIO_CHECK_EQUAL(cfg->getNumDisplays(), config2->getNumDisplays()); + + // And the display color space is also present. + + OCIO_CHECK_EQUAL(config->getNumColorSpaces() + 1, config2->getNumColorSpaces()); + OCIO_CHECK_EQUAL(cfg->getNumColorSpaces(), config2->getNumColorSpaces()); + } + // Step 4 - 2 - Create a (display, view) using a custom ICC profile. cfg = config->createEditableCopy(); // Reset the instance to the original content. diff --git a/tests/python/ConfigTest.py b/tests/python/ConfigTest.py index 6d65573a6..78327a582 100644 --- a/tests/python/ConfigTest.py +++ b/tests/python/ConfigTest.py @@ -1590,3 +1590,12 @@ def test_virtual_display_exceptions(self): "Display 'virtual_display' has a view 'Raw1' that " + "refers to a color space or a named transform, " + "'raw1', which is not defined.") + + def test_temporary_display(self): + """ + Test the ability to get and set the temporary display status. + """ + + self.assertFalse(self.cfg.isDisplayTemporary('sRGB')) + self.cfg.setDisplayTemporary('sRGB', True) + self.assertTrue(self.cfg.isDisplayTemporary('sRGB'))