Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/OpenColorIO/OpenColorIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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)
Expand Down
12 changes: 12 additions & 0 deletions src/bindings/python/PyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions tests/cpu/Config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions tests/python/ConfigTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))