Skip to content

Commit

Permalink
Fix for LookParser, getNum returning 1 on empty string and added conf…
Browse files Browse the repository at this point in the history
…ig tests
  • Loading branch information
larochj committed Dec 13, 2024
1 parent 8b0a0b9 commit 3dcda46
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,13 @@ const char * Config::getActiveDisplay( int index ) const

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());
}

Expand Down Expand Up @@ -4179,6 +4186,13 @@ const char * Config::getActiveView( int index ) const

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());
}

Expand Down
6 changes: 0 additions & 6 deletions src/OpenColorIO/LookParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ const LookParseResult::Options & LookParseResult::parse(const std::string & look
tokens.push_back(t);
}

if( vec.size() == 0 )
{
LookParseResult::Token t;
tokens.push_back(t);
}

m_options.push_back(tokens);
}

Expand Down
15 changes: 10 additions & 5 deletions src/OpenColorIO/OCIOYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4993,27 +4993,32 @@ inline void save(YAML::Emitter & out, const Config & config)
out << YAML::Key << "active_displays";
StringUtils::StringVec active_displays;
int nDisplays = config.getNumActiveDisplays();
active_displays.reserve( nDisplays );
//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;

//if( nDisplays > 0 )
//{
out << YAML::Value << YAML::Flow << active_displays;
//}

out << YAML::Key << "active_views";
StringUtils::StringVec active_views;
int nViews = config.getNumActiveViews();
active_views.reserve( nViews );
//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;
//if( nViews > 0 )
//{
out << YAML::Value << YAML::Flow << active_views;
//}

const std::string inactiveCSs = config.getInactiveColorSpaces();
if (!inactiveCSs.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/OpenColorIO/ParseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ StringUtils::StringVec SplitStringEnvStyle(const std::string & str)
const std::string s = StringUtils::Trim(str);
if( s.size() == 0 )
{
return {};
return { "" };
}

StringUtils::StringVec outputvec;
Expand Down
15 changes: 11 additions & 4 deletions src/OpenColorIO/apphelpers/mergeconfigs/OCIOMYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,27 +549,34 @@ inline void save(YAML::Emitter & out, const ConfigMerger & merger)
out << YAML::Key << "active_displays";
StringUtils::StringVec active_displays;
int nDisplays = p->getNumActiveDisplays();
active_displays.reserve( nDisplays );
//active_displays.reserve( nDisplays );
for (int i = 0; i < nDisplays; i++)
{
active_displays.push_back(p->getActiveDisplay(i));
}

// The YAML library will wrap names that use a comma in quotes.
out << YAML::Value << YAML::Flow << active_displays;
//if( nDisplays > 0)
//{
out << YAML::Value << YAML::Flow << active_displays;
//}
out << YAML::Newline;

out << YAML::Key << "active_views";
StringUtils::StringVec active_views;
int nViews = p->getNumActiveViews();
active_views.reserve( nViews );
//active_views.reserve( nViews );
for (int i = 0; i < nViews; i++)
{
active_views.push_back(p->getActiveView(i));
}

// The YAML library will wrap names that use a comma in quotes.
out << YAML::Value << YAML::Flow << active_views;
//out << YAML::Value << YAML::Flow << active_views;
//if( nViews > 0)
//{
out << YAML::Value << YAML::Flow << active_views;
//}

out << YAML::Key << "inactive_colorspaces";
StringUtils::StringVec inactive_colorspaces;
Expand Down
2 changes: 1 addition & 1 deletion tests/cpu/ParseUtils_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ OCIO_ADD_TEST(ParseUtils, split_string_env_style)
{
StringUtils::StringVec outputvec;
outputvec = OCIO::SplitStringEnvStyle("");
OCIO_CHECK_EQUAL(0, outputvec.size());
OCIO_CHECK_EQUAL(1, outputvec.size());
outputvec.clear();

outputvec = OCIO::SplitStringEnvStyle("This:is:a:test");
Expand Down
1 change: 1 addition & 0 deletions tests/cpu/ViewingRules_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ active_views: []

std::stringstream os;
os << *config.get();
OCIO_CHECK_EQUAL(0, config->getNumActiveDisplays());
OCIO_CHECK_EQUAL(os.str(), SIMPLE_CONFIG);

// Copy to set active views.
Expand Down

0 comments on commit 3dcda46

Please sign in to comment.