Skip to content

Commit 8671060

Browse files
Adsk Contrib - Remove dynamic properties from configs (#1205)
* Remove dynamic properties from configs Signed-off-by: Bernard Lefebvre <bernard.lefebvre@autodesk.com> (cherry picked from commit 58a2796713869c2803f0b921a279899807ae4318) * Adjust dynamic property access Signed-off-by: Bernard Lefebvre <bernard.lefebvre@autodesk.com> * Forgot one case Signed-off-by: Bernard Lefebvre <bernard.lefebvre@autodesk.com> * Change also required for grading test Signed-off-by: Bernard Lefebvre <bernard.lefebvre@autodesk.com> Co-authored-by: Patrick Hodoul <patrick.hodoul@autodesk.com>
1 parent e5f7e9f commit 8671060

27 files changed

Lines changed: 497 additions & 669 deletions

include/OpenColorIO/OpenColorIO.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,8 +1934,8 @@ class OCIOEXPORT Processor
19341934
/**
19351935
* The returned pointer may be used to set the default value of any dynamic
19361936
* properties of the requested type. Throws if the requested property is not found. Note
1937-
* that if the processor contains several ops that support the requested property, only ones
1938-
* for which dynamic has been enabled will be controlled.
1937+
* that if the processor contains several ops that support the requested property, only one
1938+
* can be dynamic and only this one will be controlled.
19391939
*
19401940
* \note The dynamic properties are a convenient way to change on-the-fly values without
19411941
* generating again and again a CPU or GPU processor instance. Color transformations can
@@ -1945,7 +1945,8 @@ class OCIOEXPORT Processor
19451945
* are decoupled between the types of processor instances so that the same
19461946
* :cpp:class:`Processor` can generate several independent CPU and/or GPU processor
19471947
* instances i.e. changing the value of the exposure dynamic property from a CPU processor
1948-
* instance does not affect the corresponding GPU processor instance.
1948+
* instance does not affect the corresponding GPU processor instance. Processor creation will
1949+
* throw if there are more than one property of a given type.
19491950
*/
19501951
DynamicPropertyRcPtr getDynamicProperty(DynamicPropertyType type) const;
19511952
/// True if at least one dynamic property of that type exists.
@@ -2064,12 +2065,11 @@ class OCIOEXPORT CPUProcessor
20642065

20652066
/* The returned pointer may be used to set the value of any dynamic properties
20662067
* of the requested type. Throws if the requested property is not found. Note that if the
2067-
* processor contains several ops that support the requested property, only ones for which
2068-
* dynamic has been enabled will be controlled.
2068+
* processor contains several ops that support the requested property, only one can be dynamic.
20692069
*
20702070
* \note The dynamic properties in this object are decoupled from the ones in the
20712071
* \ref Processor it was generated from. For each dynamic property in the Processor,
2072-
* there is one ine the CPU processor.
2072+
* there is one in the CPU processor.
20732073
*/
20742074
DynamicPropertyRcPtr getDynamicProperty(DynamicPropertyType type) const;
20752075

include/OpenColorIO/OpenColorTransforms.h

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -893,39 +893,45 @@ class OCIOEXPORT ExposureContrastTransform : public Transform
893893
virtual bool equals(const ExposureContrastTransform & other) const noexcept = 0;
894894

895895
virtual ExposureContrastStyle getStyle() const = 0;
896-
/**
897-
* Select the algorithm for linear, video
898-
* or log color spaces.
899-
*/
896+
/// Select the algorithm for linear, video or log color spaces.
900897
virtual void setStyle(ExposureContrastStyle style) = 0;
901898

902899
virtual double getExposure() const = 0;
903900
/**
904-
* Applies an exposure adjustment. The value is in
905-
* units of stops (regardless of style), for example, a value of -1
906-
* would be equivalent to reducing the lighting by one half.
901+
* Applies an exposure adjustment. The value is in units of stops (regardless of style), for
902+
* example, a value of -1 would be equivalent to reducing the lighting by one half.
907903
*/
908904
virtual void setExposure(double exposure) = 0;
905+
/**
906+
* Exposure can be made dynamic so the value can be changed through the CPU or GPU processor,
907+
* but if there are several ExposureContrastTransform only one can have a dynamic exposure.
908+
*/
909909
virtual bool isExposureDynamic() const = 0;
910910
virtual void makeExposureDynamic() = 0;
911911
virtual void makeExposureNonDynamic() = 0;
912912

913913
virtual double getContrast() const = 0;
914914
/**
915-
* Applies a contrast/gamma adjustment around a pivot
916-
* point. The contrast and gamma are mathematically the same, but two
917-
* controls are provided to enable the use of separate dynamic
918-
* parameters. Contrast is usually a scene-referred adjustment that
919-
* pivots around gray whereas gamma is usually a display-referred
920-
* adjustment that pivots around white.
915+
* Applies a contrast/gamma adjustment around a pivot point. The contrast and gamma are
916+
* mathematically the same, but two controls are provided to enable the use of separate
917+
* dynamic parameters. Contrast is usually a scene-referred adjustment that pivots around
918+
* gray whereas gamma is usually a display-referred adjustment that pivots around white.
921919
*/
922920
virtual void setContrast(double contrast) = 0;
921+
/**
922+
* Contrast can be made dynamic so the value can be changed through the CPU or GPU processor,
923+
* but if there are several ExposureContrastTransform only one can have a dynamic contrast.
924+
*/
923925
virtual bool isContrastDynamic() const = 0;
924926
virtual void makeContrastDynamic() = 0;
925927
virtual void makeContrastNonDynamic() = 0;
926928

927929
virtual double getGamma() const = 0;
928930
virtual void setGamma(double gamma) = 0;
931+
/**
932+
* Gamma can be made dynamic so the value can be changed through the CPU or GPU processor,
933+
* but if there are several ExposureContrastTransform only one can have a dynamic gamma.
934+
*/
929935
virtual bool isGammaDynamic() const = 0;
930936
virtual void makeGammaDynamic() = 0;
931937
virtual void makeGammaNonDynamic() = 0;
@@ -1116,6 +1122,10 @@ class OCIOEXPORT GradingPrimaryTransform : public Transform
11161122
/// Throws if value is not valid.
11171123
virtual void setValue(const GradingPrimary & values) = 0;
11181124

1125+
/**
1126+
* Parameters can be made dynamic so the values can be changed through the CPU or GPU processor,
1127+
* but if there are several GradingPrimaryTransform only one can have dynamic parameters.
1128+
*/
11191129
virtual bool isDynamic() const noexcept = 0;
11201130
virtual void makeDynamic() noexcept = 0;
11211131
virtual void makeNonDynamic() noexcept = 0;
@@ -1176,6 +1186,10 @@ class OCIOEXPORT GradingRGBCurveTransform : public Transform
11761186
virtual bool getBypassLinToLog() const = 0;
11771187
virtual void setBypassLinToLog(bool bypass) = 0;
11781188

1189+
/**
1190+
* Parameters can be made dynamic so the values can be changed through the CPU or GPU processor,
1191+
* but if there are several GradingRGBCurveTransform only one can have dynamic parameters.
1192+
*/
11791193
virtual bool isDynamic() const noexcept = 0;
11801194
virtual void makeDynamic() noexcept = 0;
11811195
virtual void makeNonDynamic() noexcept = 0;
@@ -1236,6 +1250,10 @@ class OCIOEXPORT GradingToneTransform : public Transform
12361250
virtual const GradingTone & getValue() const = 0;
12371251
virtual void setValue(const GradingTone & values) = 0;
12381252

1253+
/**
1254+
* Parameters can be made dynamic so the values can be changed through the CPU or GPU processor,
1255+
* but if there are several GradingToneTransform only one can have dynamic parameters.
1256+
*/
12391257
virtual bool isDynamic() const noexcept = 0;
12401258
virtual void makeDynamic() noexcept = 0;
12411259
virtual void makeNonDynamic() noexcept = 0;

src/OpenColorIO/CPUProcessor.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,10 @@ void FinalizeOpsForCPU(OpRcPtrVec & ops, const OpRcPtrVec & rawOps,
297297

298298
if (!((oFlags & OPTIMIZATION_NO_DYNAMIC_PROPERTIES) == OPTIMIZATION_NO_DYNAMIC_PROPERTIES))
299299
{
300-
ops.unifyDynamicProperties();
300+
ops.validateDynamicProperties();
301301
}
302302
}
303303

304-
namespace
305-
{
306-
template<typename T>
307-
void UnifyDynamicProperty(ConstOpCPURcPtr & op, std::shared_ptr<T> & prop, DynamicPropertyType type)
308-
{
309-
if (op->hasDynamicProperty(type))
310-
{
311-
op->unifyDynamicProperty(type, prop);
312-
}
313-
}
314-
}
315-
316304
void CPUProcessor::Impl::finalize(const OpRcPtrVec & rawOps,
317305
BitDepth in, BitDepth out,
318306
OptimizationFlags oFlags)
@@ -338,30 +326,6 @@ void CPUProcessor::Impl::finalize(const OpRcPtrVec & rawOps,
338326
m_outBitDepthOp = nullptr;
339327
CreateCPUEngine(ops, in, out, oFlags, m_inBitDepthOp, m_cpuOps, m_outBitDepthOp);
340328

341-
// This ensures that dynamic properties are decoupled from processor and that when a dynamic
342-
// property on a CPU processor is modified, all ops that respond to that property (and which
343-
// are enabled) are synchronized.
344-
DynamicPropertyDoubleImplRcPtr dpExposure;
345-
DynamicPropertyDoubleImplRcPtr dpContrast;
346-
DynamicPropertyDoubleImplRcPtr dpGamma;
347-
DynamicPropertyGradingPrimaryImplRcPtr dpGradingPrimary;
348-
DynamicPropertyGradingRGBCurveImplRcPtr dpGradingRGBCurve;
349-
DynamicPropertyGradingToneImplRcPtr dpGradingTone;
350-
351-
ConstOpCPURcPtrVec allCpuOps = m_cpuOps;
352-
allCpuOps.push_back(m_inBitDepthOp);
353-
allCpuOps.push_back(m_outBitDepthOp);
354-
for (auto op : allCpuOps)
355-
{
356-
// Duplicate & initialize or share property.
357-
UnifyDynamicProperty(op, dpExposure, DYNAMIC_PROPERTY_EXPOSURE);
358-
UnifyDynamicProperty(op, dpContrast, DYNAMIC_PROPERTY_CONTRAST);
359-
UnifyDynamicProperty(op, dpGamma, DYNAMIC_PROPERTY_GAMMA);
360-
UnifyDynamicProperty(op, dpGradingPrimary, DYNAMIC_PROPERTY_GRADING_PRIMARY);
361-
UnifyDynamicProperty(op, dpGradingRGBCurve, DYNAMIC_PROPERTY_GRADING_RGBCURVE);
362-
UnifyDynamicProperty(op, dpGradingTone, DYNAMIC_PROPERTY_GRADING_TONE);
363-
}
364-
365329
// Compute the cache id.
366330

367331
std::stringstream ss;

src/OpenColorIO/Config.cpp

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,32 +4055,101 @@ void Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform) cons
40554055
{
40564056
if (transform)
40574057
{
4058-
if (ConstExponentTransformRcPtr ex = DynamicPtrCast<const ExponentTransform>(transform))
4058+
if (ConstBuiltinTransformRcPtr ex = DynamicPtrCast<const BuiltinTransform>(transform))
4059+
{
4060+
if (m_majorVersion < 2)
4061+
{
4062+
throw Exception("Only config version 2 (or higher) can have BuiltinInTransform.");
4063+
}
4064+
}
4065+
else if (ConstCDLTransformRcPtr cdl = DynamicPtrCast<const CDLTransform>(transform))
4066+
{
4067+
if (m_majorVersion < 2 && cdl->getStyle() != CDL_TRANSFORM_DEFAULT)
4068+
{
4069+
throw Exception("Only config version 2 (or higher) can have style for "
4070+
"CDLTransform.");
4071+
}
4072+
}
4073+
else if (DynamicPtrCast<const DisplayViewTransform>(transform))
4074+
{
4075+
if (m_majorVersion < 2)
4076+
{
4077+
throw Exception("Only config version 2 (or higher) can have DisplayViewTransform.");
4078+
}
4079+
}
4080+
else if (ConstExponentTransformRcPtr ex =
4081+
DynamicPtrCast<const ExponentTransform>(transform))
40594082
{
40604083
if (m_majorVersion < 2 && ex->getNegativeStyle() != NEGATIVE_CLAMP)
40614084
{
4062-
throw Exception("Config version 1 only supports ExponentTransform clamping negative values.");
4085+
throw Exception("Config version 1 only supports ExponentTransform clamping "
4086+
"negative values.");
40634087
}
40644088
}
40654089
else if (DynamicPtrCast<const ExponentWithLinearTransform>(transform))
40664090
{
40674091
if (m_majorVersion < 2)
40684092
{
4069-
throw Exception("Only config version 2 (or higher) can have ExponentWithLinearTransform.");
4093+
throw Exception("Only config version 2 (or higher) can have "
4094+
"ExponentWithLinearTransform.");
40704095
}
40714096
}
40724097
else if (DynamicPtrCast<const ExposureContrastTransform>(transform))
40734098
{
40744099
if (m_majorVersion < 2)
40754100
{
4076-
throw Exception("Only config version 2 (or higher) can have ExposureContrastTransform.");
4101+
throw Exception("Only config version 2 (or higher) can have "
4102+
"ExposureContrastTransform.");
4103+
}
4104+
}
4105+
else if (ConstFileTransformRcPtr ft = DynamicPtrCast<const FileTransform>(transform))
4106+
{
4107+
if (m_majorVersion < 2)
4108+
{
4109+
if (ft->getInterpolation() == INTERP_CUBIC)
4110+
{
4111+
throw Exception("Only config version 2 (or higher) can use 'cubic' "
4112+
"interpolation with FileTransform.");
4113+
4114+
}
4115+
if (ft->getCDLStyle() != CDL_TRANSFORM_DEFAULT)
4116+
{
4117+
throw Exception("Only config version 2 (or higher) can use CDL style' "
4118+
"for FileTransform.");
4119+
4120+
}
40774121
}
40784122
}
40794123
else if (DynamicPtrCast<const FixedFunctionTransform>(transform))
40804124
{
40814125
if (m_majorVersion < 2)
40824126
{
4083-
throw Exception("Only config version 2 (or higher) can have FixedFunctionTransform.");
4127+
throw Exception("Only config version 2 (or higher) can have "
4128+
"FixedFunctionTransform.");
4129+
}
4130+
}
4131+
else if (DynamicPtrCast<const GradingPrimaryTransform>(transform))
4132+
{
4133+
if (m_majorVersion < 2)
4134+
{
4135+
throw Exception("Only config version 2 (or higher) can have "
4136+
"GradingPrimaryTransform.");
4137+
}
4138+
}
4139+
else if (DynamicPtrCast<const GradingRGBCurveTransform>(transform))
4140+
{
4141+
if (m_majorVersion < 2)
4142+
{
4143+
throw Exception("Only config version 2 (or higher) can have "
4144+
"GradingRGBCurveTransform.");
4145+
}
4146+
}
4147+
else if (DynamicPtrCast<const GradingToneTransform>(transform))
4148+
{
4149+
if (m_majorVersion < 2)
4150+
{
4151+
throw Exception("Only config version 2 (or higher) can have "
4152+
"GradingToneTransform.");
40844153
}
40854154
}
40864155
else if (DynamicPtrCast<const LogAffineTransform>(transform))

src/OpenColorIO/GPUProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void GPUProcessor::Impl::finalize(const OpRcPtrVec & rawOps,
104104
m_ops = rawOps;
105105

106106
m_ops.finalize(oFlags);
107-
m_ops.unifyDynamicProperties();
107+
m_ops.validateDynamicProperties();
108108

109109
// Is NoOp ?
110110
m_isNoOp = m_ops.isNoOp();

0 commit comments

Comments
 (0)