Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/OpenColorIO/Op.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.

#include <cstring>
#include <string>
#include <sstream>

#include <pystring.h>

#include <OpenColorIO/OpenColorIO.h>

#include "Logging.h"
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/OpenColorIO/Op.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef INCLUDED_OCIO_OP_H
#define INCLUDED_OCIO_OP_H

#include <sstream>
#include <vector>

#include <OpenColorIO/OpenColorIO.h>
Expand Down
71 changes: 41 additions & 30 deletions src/OpenColorIO/OpOptimizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/OpenColorIO/ops/log/LogUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <algorithm>
#include <cmath>
#include <sstream>

#include <OpenColorIO/OpenColorIO.h>

Expand Down
1 change: 1 addition & 0 deletions tests/cpu/Op_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.

#include <cstring>

#include "Op.cpp"

Expand Down