diff --git a/src/OpenColorIO/Op.cpp b/src/OpenColorIO/Op.cpp index 7e95baecfc..ce45b3f5d6 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(); diff --git a/src/OpenColorIO/Op.h b/src/OpenColorIO/Op.h index 895c426d80..d323534561 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/OpOptimizers.cpp b/src/OpenColorIO/OpOptimizers.cpp index 164123f413..5d925d66c1 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()); } } diff --git a/src/OpenColorIO/ops/log/LogUtils.cpp b/src/OpenColorIO/ops/log/LogUtils.cpp index 77548acfe6..e023337774 100644 --- a/src/OpenColorIO/ops/log/LogUtils.cpp +++ b/src/OpenColorIO/ops/log/LogUtils.cpp @@ -3,6 +3,7 @@ #include #include +#include #include diff --git a/tests/cpu/Op_tests.cpp b/tests/cpu/Op_tests.cpp index d6c1fb3c00..0db960d3ef 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"