Skip to content

Commit

Permalink
Adsk Contrib - Fix some bugs found by Maya and SonarCloud (#1403)
Browse files Browse the repository at this point in the history
* Adsk Contrib - Fix some bugs found by Maya and SonarCloud

Signed-off-by: Patrick Hodoul <Patrick.Hodoul@autodesk.com>

* Fix a Windows warning

Signed-off-by: Patrick Hodoul <Patrick.Hodoul@autodesk.com>
  • Loading branch information
hodoulp authored May 28, 2021
1 parent dd59baf commit 3abbe5b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ class Config::Impl
// Note that it adds it or updates the existing one.
m_allColorSpaces->addColorSpace(cs);
}
catch(const Exception & ex)
catch(const Exception & /* ex */)
{
DisplayMap::iterator iter = FindDisplay(m_displays, colorSpaceName);
if (iter!=m_displays.end())
Expand All @@ -1075,7 +1075,7 @@ class Config::Impl

m_allColorSpaces->removeColorSpace(colorSpaceName.c_str());

throw ex;
throw;
}

// The display must be active.
Expand Down
8 changes: 4 additions & 4 deletions src/OpenColorIO/DynamicProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ bool DynamicPropertyImpl::equals(const DynamicPropertyImpl & rhs) const
{
auto lhst = dynamic_cast<const DynamicPropertyDouble *>(this);
auto rhst = dynamic_cast<const DynamicPropertyDouble *>(&rhs);
return (lhst->getValue() == rhst->getValue());
return lhst && rhst && (lhst->getValue() == rhst->getValue());
}
case DYNAMIC_PROPERTY_GRADING_PRIMARY:
{
auto lhst = dynamic_cast<const DynamicPropertyGradingPrimary *>(this);
auto rhst = dynamic_cast<const DynamicPropertyGradingPrimary *>(&rhs);
return (lhst->getValue() == rhst->getValue());
return lhst && rhst && (lhst->getValue() == rhst->getValue());
}
case DYNAMIC_PROPERTY_GRADING_RGBCURVE:
{
auto lhst = dynamic_cast<const DynamicPropertyGradingRGBCurve *>(this);
auto rhst = dynamic_cast<const DynamicPropertyGradingRGBCurve *>(&rhs);
return (*lhst->getValue() == *rhst->getValue());
return lhst && rhst && (*lhst->getValue() == *rhst->getValue());
}
case DYNAMIC_PROPERTY_GRADING_TONE:
{
auto lhst = dynamic_cast<const DynamicPropertyGradingTone *>(this);
auto rhst = dynamic_cast<const DynamicPropertyGradingTone *>(&rhs);
return (lhst->getValue() == rhst->getValue());
return lhst && rhst && (lhst->getValue() == rhst->getValue());
}
}
// Different values.
Expand Down
2 changes: 1 addition & 1 deletion src/OpenColorIO/DynamicProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class DynamicPropertyGradingPrimaryImpl : public DynamicPropertyImpl,
const Float3 & getSlope() const { return m_preRenderValues.getSlope(); }

// Do not apply the op if all params are identity.
bool getLocalBypass() const { return m_preRenderValues.m_localBypass; }
bool getLocalBypass() const { return m_preRenderValues.getLocalBypass(); }

DynamicPropertyGradingPrimaryImplRcPtr createEditableCopy() const;

Expand Down
4 changes: 2 additions & 2 deletions src/OpenColorIO/OpOptimizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int RemoveInverseOps(OpRcPtrVec & opVec, OptimizationFlags oFlags)
int count = 0;
int firstindex = 0; // this must be a signed int

while (firstindex < static_cast<int>(opVec.size() - 1))
while (firstindex < (static_cast<int>(opVec.size()) - 1))
{
ConstOpRcPtr op1 = opVec[firstindex];
ConstOpRcPtr op2 = opVec[firstindex + 1];
Expand Down Expand Up @@ -273,7 +273,7 @@ int CombineOps(OpRcPtrVec & opVec, OptimizationFlags oFlags)

OpRcPtrVec tmpops;

while (firstindex < static_cast<int>(opVec.size() - 1))
while (firstindex < (static_cast<int>(opVec.size()) - 1))
{
ConstOpRcPtr op1 = opVec[firstindex];
ConstOpRcPtr op2 = opVec[firstindex + 1];
Expand Down
1 change: 0 additions & 1 deletion src/OpenColorIO/ops/allocation/AllocationOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ void CreateAllocationOps(OpRcPtrVec & ops,
}
case ALLOCATION_UNKNOWN:
throw Exception("Unsupported Allocation Type.");
break;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/OpenColorIO/ops/gradingprimary/GradingPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ void GradingPrimaryPreRender::update(GradingStyle style,
m_isPowerIdentity = m_gamma[0] == 1.0f && m_gamma[1] == 1.0f && m_gamma[2] == 1.0f;
m_pivot = 0.5 + v.m_pivot * 0.5;
m_localBypass = m_localBypass && m_isPowerIdentity &&
m_brightness[0] == 0.f && m_brightness[2] == 0.f && m_brightness[2] == 0.f &&
m_contrast[0] == 1.f && m_contrast[2] == 1.f && m_contrast[2] == 1.f;
m_brightness[0] == 0.f && m_brightness[1] == 0.f && m_brightness[2] == 0.f &&
m_contrast[0] == 1.f && m_contrast[1] == 1.f && m_contrast[2] == 1.f;
break;
}
case GRADING_LIN:
Expand Down Expand Up @@ -193,8 +193,8 @@ void GradingPrimaryPreRender::update(GradingStyle style,
m_contrast[2] == 1.0f;
m_pivot = 0.18 * std::pow(2., v.m_pivot);
m_localBypass = m_localBypass && m_isPowerIdentity &&
m_exposure[0] == 1.f && m_exposure[2] == 1.f && m_exposure[2] == 1.f &&
m_offset[0] == 0.f && m_offset[2] == 0.f && m_offset[2] == 0.f;
m_exposure[0] == 1.f && m_exposure[1] == 1.f && m_exposure[2] == 1.f &&
m_offset[0] == 0.f && m_offset[1] == 0.f && m_offset[2] == 0.f;
break;
}
case GRADING_VIDEO:
Expand Down Expand Up @@ -251,8 +251,8 @@ void GradingPrimaryPreRender::update(GradingStyle style,
}
m_isPowerIdentity = m_gamma[0] == 1.0f || m_gamma[1] == 1.0f || m_gamma[2] == 1.0f;
m_localBypass = m_localBypass && m_isPowerIdentity &&
m_slope[0] == 1.f && m_slope[2] == 1.f && m_slope[2] == 1.f &&
m_offset[0] == 0.f && m_offset[2] == 0.f && m_offset[2] == 0.f;
m_slope[0] == 1.f && m_slope[1] == 1.f && m_slope[2] == 1.f &&
m_offset[0] == 0.f && m_offset[1] == 0.f && m_offset[2] == 0.f;
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/OpenColorIO/ops/gradingprimary/GradingPrimary.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct GradingPrimaryPreRender
void update(GradingStyle style, TransformDirection dir, const GradingPrimary & v) noexcept;

// Do not apply the op if all params are identity.
bool m_localBypass{ false };
bool getLocalBypass() const { return m_localBypass; }

// Access to the precomputed values. Note that values are already inversed based on the
// direction so that no computation is required before using them.
Expand Down Expand Up @@ -58,6 +58,8 @@ struct GradingPrimaryPreRender
double m_pivot{ 0. };

bool m_isPowerIdentity{ false };

bool m_localBypass{ false };
};

bool operator==(const GradingRGBM & lhs, const GradingRGBM & rhs);
Expand Down
7 changes: 7 additions & 0 deletions tests/cpu/ops/gradingprimary/GradingPrimary_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ OCIO_ADD_TEST(GradingPrimary, precompute)
OCIO_CHECK_CLOSE(comp.getPivot(), 0.4f, 1.e-6f);
OCIO_CHECK_ASSERT(comp.isGammaIdentity());

gp.m_brightness.m_green = 0.1 * 1023. / 6.25;
comp.update(OCIO::GRADING_LOG, OCIO::TRANSFORM_DIR_FORWARD, gp);
OCIO_CHECK_ASSERT(comp.getBrightness() == OCIO::Float3({ 0.f, 0.1f, 0.f }));
OCIO_CHECK_ASSERT(!comp.getLocalBypass());
OCIO_CHECK_ASSERT(comp.isGammaIdentity());

gp.m_brightness.m_red = 0.1 * 1023. / 6.25;
gp.m_brightness.m_green = 0.;
gp.m_contrast.m_red = 0.; // Inverse will be 1.
gp.m_contrast.m_green = 1.25;
gp.m_gamma.m_blue = 0.8;
Expand Down

0 comments on commit 3abbe5b

Please sign in to comment.