From 3dcda4605356341339cc94b0f79d30d67fa2418c Mon Sep 17 00:00:00 2001 From: Jonathan Laroche Date: Thu, 12 Dec 2024 23:52:51 -0500 Subject: [PATCH] Fix for LookParser, getNum returning 1 on empty string and added config tests --- src/OpenColorIO/Config.cpp | 14 ++++++++++++++ src/OpenColorIO/LookParse.cpp | 6 ------ src/OpenColorIO/OCIOYaml.cpp | 15 ++++++++++----- src/OpenColorIO/ParseUtils.cpp | 2 +- .../apphelpers/mergeconfigs/OCIOMYaml.cpp | 15 +++++++++++---- tests/cpu/ParseUtils_tests.cpp | 2 +- tests/cpu/ViewingRules_tests.cpp | 1 + 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index d270953e6e..b01532e508 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4083,6 +4083,13 @@ const char * Config::getActiveDisplay( int index ) const int Config::getNumActiveDisplays() const { + const int numActiveDisplays = static_cast(getImpl()->m_activeDisplays.size()); + if( numActiveDisplays == 1 && + getImpl()->m_activeDisplays[0].empty() ) + { + return 0; + } + return static_cast(getImpl()->m_activeDisplays.size()); } @@ -4179,6 +4186,13 @@ const char * Config::getActiveView( int index ) const int Config::getNumActiveViews() const { + const int numActiveViews = static_cast(getImpl()->m_activeViews.size()); + if( numActiveViews == 1 && + getImpl()->m_activeViews[0].empty() ) + { + return 0; + } + return static_cast(getImpl()->m_activeViews.size()); } diff --git a/src/OpenColorIO/LookParse.cpp b/src/OpenColorIO/LookParse.cpp index 0102d17db1..2b83270e0d 100644 --- a/src/OpenColorIO/LookParse.cpp +++ b/src/OpenColorIO/LookParse.cpp @@ -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); } diff --git a/src/OpenColorIO/OCIOYaml.cpp b/src/OpenColorIO/OCIOYaml.cpp index 9678b7b379..34fe6f6260 100644 --- a/src/OpenColorIO/OCIOYaml.cpp +++ b/src/OpenColorIO/OCIOYaml.cpp @@ -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()) diff --git a/src/OpenColorIO/ParseUtils.cpp b/src/OpenColorIO/ParseUtils.cpp index b25288403c..dbff0f9e5f 100644 --- a/src/OpenColorIO/ParseUtils.cpp +++ b/src/OpenColorIO/ParseUtils.cpp @@ -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; diff --git a/src/OpenColorIO/apphelpers/mergeconfigs/OCIOMYaml.cpp b/src/OpenColorIO/apphelpers/mergeconfigs/OCIOMYaml.cpp index 25f6dcd086..822d6b284b 100644 --- a/src/OpenColorIO/apphelpers/mergeconfigs/OCIOMYaml.cpp +++ b/src/OpenColorIO/apphelpers/mergeconfigs/OCIOMYaml.cpp @@ -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; diff --git a/tests/cpu/ParseUtils_tests.cpp b/tests/cpu/ParseUtils_tests.cpp index 3b10450023..aefe1d38fb 100644 --- a/tests/cpu/ParseUtils_tests.cpp +++ b/tests/cpu/ParseUtils_tests.cpp @@ -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"); diff --git a/tests/cpu/ViewingRules_tests.cpp b/tests/cpu/ViewingRules_tests.cpp index a58ffaf63f..62e94f2fd9 100644 --- a/tests/cpu/ViewingRules_tests.cpp +++ b/tests/cpu/ViewingRules_tests.cpp @@ -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.