From f484d1f161943f854a5265f4df037c607d21ba04 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 12 Jan 2026 17:08:02 +0000 Subject: [PATCH 1/4] Op.cpp: remove dependency on pystring Signed-off-by: Kevin Wheatley --- src/OpenColorIO/Op.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/OpenColorIO/Op.cpp b/src/OpenColorIO/Op.cpp index 7e95baecf..ce45b3f5d 100755 --- a/src/OpenColorIO/Op.cpp +++ b/src/OpenColorIO/Op.cpp @@ -1,11 +1,9 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenColorIO Project. -#include +#include #include -#include - #include #include "Logging.h" @@ -473,16 +471,14 @@ std::ostream& operator<< (std::ostream & os, const Op & op) std::string SerializeOpVec(const OpRcPtrVec & ops, int indent) { std::ostringstream oss; + const std::string indentStr(indent, ' '); - for (OpRcPtrVec::size_type idx = 0, size = ops.size(); idx < size; ++idx) + OpRcPtrVec::size_type idx = 0; + for (const auto & op : ops) { - const OpRcPtr & op = ops[idx]; - - oss << pystring::mul(" ", indent); - oss << "Op " << idx << ": " << *op << " "; - oss << op->getCacheID(); - - oss << "\n"; + oss << indentStr << "Op " << idx << ": " << *op << " " + << op->getCacheID() << "\n"; + ++idx; } return oss.str(); From 0a5cfaab72ac0ecafbe75f6230374bd17db320d0 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 12 Jan 2026 17:12:48 +0000 Subject: [PATCH 2/4] Op.h: Remove unused sstream include Add sstream to LogUtils.cpp which was previously being included by transitive dependency in Op.h Signed-off-by: Kevin Wheatley --- src/OpenColorIO/Op.h | 1 - src/OpenColorIO/ops/log/LogUtils.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenColorIO/Op.h b/src/OpenColorIO/Op.h index 895c426d8..d32353456 100644 --- a/src/OpenColorIO/Op.h +++ b/src/OpenColorIO/Op.h @@ -5,7 +5,6 @@ #ifndef INCLUDED_OCIO_OP_H #define INCLUDED_OCIO_OP_H -#include #include #include diff --git a/src/OpenColorIO/ops/log/LogUtils.cpp b/src/OpenColorIO/ops/log/LogUtils.cpp index 77548acfe..e02333777 100644 --- a/src/OpenColorIO/ops/log/LogUtils.cpp +++ b/src/OpenColorIO/ops/log/LogUtils.cpp @@ -3,6 +3,7 @@ #include #include +#include #include From 2d3a2ec6cf774d9fc3a906fc9e574f883d5fa1b6 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 12 Jan 2026 18:06:42 +0000 Subject: [PATCH 3/4] Add additional output during optimisation to show the results of ach stage Store the result of IsDebugLoggingEnabled() to avoid taking the internal mutex and to ensure either none or all the debugging will be output for the duration optimisation call. Avoid calling operator<< between character string literals which can be combined by the preprocessor Replace use of std::endl with "\n" Signed-off-by: Kevin Wheatley --- src/OpenColorIO/OpOptimizers.cpp | 71 ++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/OpenColorIO/OpOptimizers.cpp b/src/OpenColorIO/OpOptimizers.cpp index 164123f41..5d925d66c 100755 --- a/src/OpenColorIO/OpOptimizers.cpp +++ b/src/OpenColorIO/OpOptimizers.cpp @@ -615,13 +615,12 @@ void OpRcPtrVec::optimize(OptimizationFlags oFlags) return; } - if (IsDebugLoggingEnabled()) + const bool debugLoggingEnabled = IsDebugLoggingEnabled(); + if (debugLoggingEnabled) { std::ostringstream oss; - oss << std::endl - << "**" << std::endl - << "Optimizing Op Vec..." << std::endl - << SerializeOpVec(*this, 4) << std::endl; + oss << "\n**\nOptimizing Op Vec...\n" + << SerializeOpVec(*this, 4) << "\n"; LogDebug(oss.str()); } @@ -633,16 +632,15 @@ void OpRcPtrVec::optimize(OptimizationFlags oFlags) if (oFlags == OPTIMIZATION_NONE) { - if (IsDebugLoggingEnabled()) + if (debugLoggingEnabled) { OpRcPtrVec::size_type finalSize = size(); std::ostringstream os; - os << "**" << std::endl; - os << "Optimized "; - os << originalSize << "->" << finalSize << ", 1 pass, "; - os << total_nooptype << " no-op types removed\n"; - os << SerializeOpVec(*this, 4); + os << "**\nOptimized " + << originalSize << "->" << finalSize << ", 1 pass, " + << total_nooptype << " no-op types removed\n" + << SerializeOpVec(*this, 4); LogDebug(os.str()); } @@ -678,20 +676,30 @@ void OpRcPtrVec::optimize(OptimizationFlags oFlags) { // Remove all ops for which isNoOp is true, including identity matrices. int noops = optimizeIdentity ? RemoveNoOps(*this) : 0; + if (debugLoggingEnabled) + LogDebug(std::string("RemoveNoOps\n") + SerializeOpVec(*this, 4)); // Replace all complex ops with simpler ops (e.g., a CDL which only scales with a matrix). // Note this might increase the number of ops. int replacedOps = replaceOps ? ReplaceOps(*this) : 0; + if (debugLoggingEnabled) + LogDebug(std::string("ReplaceOps\n") + SerializeOpVec(*this, 4)); // Replace all complex identities with simpler ops (e.g., an identity Lut1D with a range). int identityops = ReplaceIdentityOps(*this, oFlags); + if (debugLoggingEnabled) + LogDebug(std::string("ReplaceIdentityOps\n") + SerializeOpVec(*this, 4)); // Remove all adjacent pairs of ops that are inverses of each other. int inverseops = RemoveInverseOps(*this, oFlags); + if (debugLoggingEnabled) + LogDebug(std::string("RemoveInverseOps\n") + SerializeOpVec(*this, 4)); // Combine a pair of ops, for example multiply two adjacent Matrix ops. // (Combines at most one pair on each iteration.) int combines = CombineOps(*this, oFlags); + if (debugLoggingEnabled) + LogDebug(std::string("CombineOps\n") + SerializeOpVec(*this, 4)); if (noops + identityops + inverseops + combines == 0) { @@ -701,6 +709,10 @@ void OpRcPtrVec::optimize(OptimizationFlags oFlags) if (fastLut) { const int inverses = ReplaceInverseLuts(*this); + if (debugLoggingEnabled) + LogDebug(std::string("ReplaceInverseLuts\n") + + SerializeOpVec(*this, 4)); + if (inverses == 0) { break; @@ -723,34 +735,33 @@ void OpRcPtrVec::optimize(OptimizationFlags oFlags) ++passes; } - if (passes == MAX_OPTIMIZATION_PASSES) + if (debugLoggingEnabled && (passes == MAX_OPTIMIZATION_PASSES)) { std::ostringstream os; - os << "The max number of passes, " << passes << ", "; - os << "was reached during optimization. This is likely a sign "; - os << "that either the complexity of the color transform is "; - os << "very high, or that some internal optimizers are in conflict "; - os << "(undo-ing / redo-ing the other's results)."; + os << "The max number of passes, " << passes << ", " + "was reached during optimization. This is likely a sign " + "that either the complexity of the color transform is " + "very high, or that some internal optimizers are in conflict " + "(undo-ing / redo-ing the other's results)."; LogDebug(os.str()); } - if (IsDebugLoggingEnabled()) + if (debugLoggingEnabled) { OpRcPtrVec::size_type finalSize = size(); std::ostringstream os; - os << "**" << std::endl; - os << "Optimized "; - os << originalSize << "->" << finalSize << ", "; - os << passes << " passes, "; - os << total_nooptype << " no-op types removed, "; - os << total_noops << " no-ops removed, "; - os << total_replacedops << " ops replaced, "; - os << total_identityops << " identity ops replaced, "; - os << total_inverseops << " inverse op pairs removed, "; - os << total_combines << " ops combined, "; - os << total_inverses << " ops inverted\n"; - os << SerializeOpVec(*this, 4); + os << "**\nOptimized " + << originalSize << "->" << finalSize << ", " + << passes << " passes, " + << total_nooptype << " no-op types removed, " + << total_noops << " no-ops removed, " + << total_replacedops << " ops replaced, " + << total_identityops << " identity ops replaced, " + << total_inverseops << " inverse op pairs removed, " + << total_combines << " ops combined, " + << total_inverses << " ops inverted\n" + << SerializeOpVec(*this, 4); LogDebug(os.str()); } } From f9b3524ecb0eec27d2b4986cd3e00f4ae2519879 Mon Sep 17 00:00:00 2001 From: Kevin Wheatley Date: Mon, 12 Jan 2026 20:36:34 +0000 Subject: [PATCH 4/4] Add for memcpy to test code Signed-off-by: Kevin Wheatley --- tests/cpu/Op_tests.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cpu/Op_tests.cpp b/tests/cpu/Op_tests.cpp index d6c1fb3c0..0db960d3e 100644 --- a/tests/cpu/Op_tests.cpp +++ b/tests/cpu/Op_tests.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenColorIO Project. +#include #include "Op.cpp"