Skip to content

Commit 1dfa6aa

Browse files
authored
Add setDisplayTemporary method (#2181)
(cherry picked from commit f25cb6a) Signed-off-by: Doug Walker <[email protected]>
1 parent b3252c7 commit 1dfa6aa

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,11 @@ class OCIOEXPORT Config
11361136
* intended to be temporary (i.e. for the current session) and are not saved to a config file.
11371137
*/
11381138
bool isDisplayTemporary(int index) const noexcept;
1139+
/**
1140+
* Allows setting the flag that controls whether a display is temporary. This may be helpful,
1141+
* for example, to share a config with a temporary instantiated display with an OFX plug-in.
1142+
*/
1143+
void setDisplayTemporary(int index, bool isTemporary) noexcept;
11391144

11401145
/**
11411146
* Get either the shared or display-defined views for a display. The

src/OpenColorIO/Config.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,6 +4170,18 @@ bool Config::isDisplayTemporary(int index) const noexcept
41704170
return false;
41714171
}
41724172

4173+
void Config::setDisplayTemporary(int index, bool isTemporary) noexcept
4174+
{
4175+
if (index >= 0 || index < static_cast<int>(getImpl()->m_displays.size()))
4176+
{
4177+
getImpl()->m_displays[index].second.m_temporary = isTemporary;
4178+
4179+
getImpl()->m_displayCache.clear();
4180+
AutoMutex lock(getImpl()->m_cacheidMutex);
4181+
getImpl()->resetCacheIDs();
4182+
}
4183+
}
4184+
41734185
int Config::getNumViews(ViewType type, const char * display) const
41744186
{
41754187
if (!display || !*display)

src/bindings/python/PyConfig.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,18 @@ void bindPyConfig(py::module & m)
552552
return false;
553553
},
554554
"display"_a)
555+
.def("setDisplayTemporary", [](ConfigRcPtr & self, const std::string & display, bool isTemporary)
556+
{
557+
for (int i = 0; i < self->getNumDisplaysAll(); i++)
558+
{
559+
std::string other(self->getDisplayAll(i));
560+
if (StringUtils::Compare(display, other))
561+
{
562+
self->setDisplayTemporary(i, isTemporary);
563+
}
564+
}
565+
},
566+
"display"_a, "isTemporary"_a)
555567
.def_static("AreVirtualViewsEqual", [](const ConstConfigRcPtr & first,
556568
const ConstConfigRcPtr & second,
557569
const char * viewName)

tests/cpu/Config_tests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8657,6 +8657,10 @@ active_views: []
86578657
OCIO_CHECK_EQUAL(2, cfg->getNumViews(OCIO::VIEW_DISPLAY_DEFINED, displayName.c_str()));
86588658
OCIO_CHECK_EQUAL(1, cfg->getNumViews(OCIO::VIEW_SHARED, displayName.c_str()));
86598659

8660+
// The new display is marked as temporary.
8661+
OCIO_CHECK_ASSERT(!cfg->isDisplayTemporary(config->getNumDisplays() - 1));
8662+
OCIO_CHECK_ASSERT(cfg->isDisplayTemporary(config->getNumDisplays()));
8663+
86608664
// Check the created display color space.
86618665

86628666
OCIO::ConstColorSpaceRcPtr cs = cfg->getColorSpace(displayName.c_str());
@@ -8707,6 +8711,33 @@ active_views: []
87078711
OCIO_CHECK_EQUAL(cfg->getNumColorSpaces() - 1, config2->getNumColorSpaces());
87088712
}
87098713

8714+
// Check that the display may be marked as non-temporary and therefore serialized in a config.
8715+
8716+
{
8717+
OCIO_CHECK_ASSERT(cfg->isDisplayTemporary(config->getNumDisplays()));
8718+
cfg->setDisplayTemporary(config->getNumDisplays(), false);
8719+
OCIO_CHECK_ASSERT(!cfg->isDisplayTemporary(config->getNumDisplays()));
8720+
8721+
std::ostringstream oss2;
8722+
OCIO_CHECK_NO_THROW(oss2 << *cfg.get());
8723+
8724+
std::istringstream iss2;
8725+
iss2.str(oss2.str());
8726+
8727+
OCIO::ConstConfigRcPtr config2;
8728+
OCIO_CHECK_NO_THROW(config2 = OCIO::Config::CreateFromStream(iss2));
8729+
8730+
// Check that (display, view) pair created by the virtual display instantiation is present.
8731+
8732+
OCIO_CHECK_EQUAL(config->getNumDisplays() + 1, config2->getNumDisplays());
8733+
OCIO_CHECK_EQUAL(cfg->getNumDisplays(), config2->getNumDisplays());
8734+
8735+
// And the display color space is also present.
8736+
8737+
OCIO_CHECK_EQUAL(config->getNumColorSpaces() + 1, config2->getNumColorSpaces());
8738+
OCIO_CHECK_EQUAL(cfg->getNumColorSpaces(), config2->getNumColorSpaces());
8739+
}
8740+
87108741
// Step 4 - 2 - Create a (display, view) using a custom ICC profile.
87118742

87128743
cfg = config->createEditableCopy(); // Reset the instance to the original content.

tests/python/ConfigTest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,3 +1590,12 @@ def test_virtual_display_exceptions(self):
15901590
"Display 'virtual_display' has a view 'Raw1' that " +
15911591
"refers to a color space or a named transform, " +
15921592
"'raw1', which is not defined.")
1593+
1594+
def test_temporary_display(self):
1595+
"""
1596+
Test the ability to get and set the temporary display status.
1597+
"""
1598+
1599+
self.assertFalse(self.cfg.isDisplayTemporary('sRGB'))
1600+
self.cfg.setDisplayTemporary('sRGB', True)
1601+
self.assertTrue(self.cfg.isDisplayTemporary('sRGB'))

0 commit comments

Comments
 (0)