Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for commas in active views list #26

Merged
merged 9 commits into from
Dec 13, 2024
4 changes: 4 additions & 0 deletions include/OpenColorIO/OpenColorAppHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,13 @@ class OCIOEXPORT ConfigMergingParameters

void setActiveDisplays(const char * displays);
const char * getActiveDisplays() const;
int getNumActiveDisplays() const;
const char * getActiveDisplay(int index) const;

void setActiveViews(const char * views);
const char * getActiveViews() const;
int getNumActiveViews() const;
const char * getActiveView(int index) const;

void setInactiveColorspaces(const char * colorspaces);
const char * getInactiveColorSpaces() const;
Expand Down
10 changes: 10 additions & 0 deletions include/OpenColorIO/OpenColorIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,11 @@ class OCIOEXPORT Config
*/
void setActiveDisplays(const char * displays);
const char * getActiveDisplays() const;
void addActiveDisplay(const char * view);
void removeActiveDisplay(const char * view);
void clearActiveDisplays();
const char * getActiveDisplay(int index) const;
int getNumActiveDisplays() const;

/**
* \brief
Expand All @@ -1104,6 +1109,11 @@ class OCIOEXPORT Config
*/
void setActiveViews(const char * views);
const char * getActiveViews() const;
void addActiveView(const char * view);
void removeActiveView(const char * view);
void clearActiveViews();
const char * getActiveView(int index) const;
int getNumActiveViews() const;

/// Get all displays in the config, ignoring the active_displays list.
int getNumDisplaysAll() const noexcept;
Expand Down
176 changes: 175 additions & 1 deletion src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@ void Config::removeSharedView(const char * view)
{
std::ostringstream os;
os << "Shared view could not be removed from config. A shared view named '"
<< view << "' could be be found.";
<< view << "' could not be found.";
throw Exception(os.str().c_str());
}
}
Expand Down Expand Up @@ -4005,6 +4005,94 @@ const char * Config::getActiveDisplays() const
return getImpl()->m_activeDisplaysStr.c_str();
}

void Config::addActiveDisplay(const char * display)
{
if( !display || !display[0] )
{
throw Exception("Active display could not be added to config, display name has to be a "
"non-empty name.");
}

auto it = std::find(getImpl()->m_activeDisplays.begin(),
getImpl()->m_activeDisplays.end(), display);

if( it != getImpl()->m_activeDisplays.end() )
{
std::ostringstream os;
os << "Active display could not be added to config. An active display named '"
<< display << "' already exists.";
throw Exception(os.str().c_str());
}
doug-walker marked this conversation as resolved.
Show resolved Hide resolved
doug-walker marked this conversation as resolved.
Show resolved Hide resolved

getImpl()->m_activeDisplays.push_back(display);

getImpl()->m_displayCache.clear();

AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

void Config::removeActiveDisplay(const char * display)
{
if( !display || !display[0] )
{
throw Exception("Active display could not be removed from config, display name has to be a "
"non-empty name.");
}

auto it = std::find( getImpl()->m_activeDisplays.begin(),
getImpl()->m_activeDisplays.end(), display );

if( it != getImpl()->m_activeDisplays.end() )
{
getImpl()->m_activeDisplays.erase(it);
}
else
{
std::ostringstream os;
os << "Active display could not be removed from config. An active display named '"
<< display << "' could not be found.";
throw Exception(os.str().c_str());
}

getImpl()->m_displayCache.clear();
AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

void Config::clearActiveDisplays()
{
getImpl()->m_activeDisplays.clear();

getImpl()->m_displayCache.clear();

AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

const char * Config::getActiveDisplay( int index ) const
{
if( index<0 ||
index >= static_cast<int>(getImpl()->m_activeDisplays.size()))
{
return nullptr;
}
doug-walker marked this conversation as resolved.
Show resolved Hide resolved

return getImpl()->m_activeDisplays[index].c_str();
}

int Config::getNumActiveDisplays() const
{
const int numActiveDisplays = static_cast<int>(getImpl()->m_activeDisplays.size());
if( numActiveDisplays == 1 &&
getImpl()->m_activeDisplays[0].empty() )
{
return 0;
}

return static_cast<int>(getImpl()->m_activeDisplays.size());
}

void Config::setActiveViews(const char * views)
{
getImpl()->m_activeViews.clear();
Expand All @@ -4022,6 +4110,92 @@ const char * Config::getActiveViews() const
return getImpl()->m_activeViewsStr.c_str();
}

void Config::addActiveView(const char * view)
{
if( !view || !view[0] )
{
throw Exception("Active view could not be added to config, view name has to be a "
"non-empty name.");
}

auto it = std::find(getImpl()->m_activeViews.begin(),
getImpl()->m_activeViews.end(), view);

if( it != getImpl()->m_activeViews.end() )
{
std::ostringstream os;
os << "Active view could not be added to config. An active view named '"
<< view << "' already exists.";
throw Exception(os.str().c_str());
}

getImpl()->m_activeViews.push_back(view);

getImpl()->m_displayCache.clear();
AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

void Config::removeActiveView(const char * view)
{
if( !view || !view[0] )
{
throw Exception("Active view could not be removed from config, view name has to be a "
"non-empty name.");
}

auto it = std::find( getImpl()->m_activeViews.begin(),
getImpl()->m_activeViews.end(), view );

if(it!=getImpl()->m_activeViews.end())
{
getImpl()->m_activeViews.erase(it);
}
else
{
std::ostringstream os;
os << "Active view could not be removed from config. An active view named '"
<< view << "' could not be found.";
throw Exception(os.str().c_str());
}

getImpl()->m_displayCache.clear();
AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

void Config::clearActiveViews()
{
getImpl()->m_activeViews.clear();

getImpl()->m_displayCache.clear();
AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

const char * Config::getActiveView( int index ) const
{
if( index<0 ||
index >= static_cast<int>(getImpl()->m_activeViews.size()))
{
return nullptr;
}

return getImpl()->m_activeViews[index].c_str();
}

int Config::getNumActiveViews() const
{
const int numActiveViews = static_cast<int>(getImpl()->m_activeViews.size());
if( numActiveViews == 1 &&
getImpl()->m_activeViews[0].empty() )
{
return 0;
}

return static_cast<int>(getImpl()->m_activeViews.size());
}

int Config::getNumDisplaysAll() const noexcept
{
return static_cast<int>(getImpl()->m_displays.size());
Expand Down
21 changes: 17 additions & 4 deletions src/OpenColorIO/OCIOYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4992,13 +4992,26 @@ inline void save(YAML::Emitter & out, const Config & config)
out << YAML::Newline;
out << YAML::Key << "active_displays";
StringUtils::StringVec active_displays;
if(config.getActiveDisplays() != NULL && strlen(config.getActiveDisplays()) > 0)
active_displays = SplitStringEnvStyle(config.getActiveDisplays());
int nDisplays = config.getNumActiveDisplays();
active_displays.reserve( nDisplays );
for (int i = 0; i < nDisplays; i++)
{
active_displays.push_back(config.getActiveDisplay(i));
}

// The YAML library will wrap names that use a comma in quotes.
out << YAML::Value << YAML::Flow << active_displays;

out << YAML::Key << "active_views";
StringUtils::StringVec active_views;
if(config.getActiveViews() != NULL && strlen(config.getActiveViews()) > 0)
active_views = SplitStringEnvStyle(config.getActiveViews());
int nViews = config.getNumActiveViews();
active_views.reserve( nViews );
for (int i = 0; i < nViews; i++)
{
active_views.push_back(config.getActiveView(i));
}

// The YAML library will wrap names that use a comma in quotes.
out << YAML::Value << YAML::Flow << active_views;
doug-walker marked this conversation as resolved.
Show resolved Hide resolved

const std::string inactiveCSs = config.getInactiveColorSpaces();
Expand Down
Loading
Loading