Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adsk Contrib - Enhance CLF tests #1011

Merged
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
10 changes: 6 additions & 4 deletions include/OpenColorIO/OpenColorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ enum TransformDirection
enum Interpolation
{
INTERP_UNKNOWN = 0,
INTERP_NEAREST = 1, //! nearest neighbor in all dimensions
INTERP_LINEAR = 2, //! linear interpolation in all dimensions
INTERP_TETRAHEDRAL = 3, //! tetrahedral interpolation in all directions
INTERP_CUBIC = 4, //! cubic interpolation in all dimensions
INTERP_NEAREST = 1, //! nearest neighbor
INTERP_LINEAR = 2, //! linear interpolation (trilinear for Lut3D)
INTERP_TETRAHEDRAL = 3, //! tetrahedral interpolation (Lut3D only)
INTERP_CUBIC = 4, //! cubic interpolation (not supported)

INTERP_DEFAULT = 254, //! the default interpolation type
INTERP_BEST = 255 //! the 'best' suitable interpolation type
Expand Down Expand Up @@ -466,6 +466,8 @@ enum CDLStyle
CDL_ASC = 0, //! ASC CDL specification v1.2
CDL_NO_CLAMP, //! CDL that does not clamp

// Note: The default for reading .cc/.ccc/.cdl files, config file YAML, and CDLTransform is no-clamp,
// since that is what is primarily desired in VFX. However, the CLF format default is ASC.
CDL_TRANSFORM_DEFAULT = CDL_NO_CLAMP
};

Expand Down
183 changes: 96 additions & 87 deletions src/OpenColorIO/fileformats/ctf/CTFReaderHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,9 +1324,11 @@ void CTFReaderCDLElt::start(const char ** atts)
}
}

// Although the OCIO default for CDL style is no-clamp, the default specified in
// the CLF v3 spec is ASC.
if (!isStyleFound)
{
throwMessage("CTF/CLF CDL parsing. Required attribute 'style' is missing.");
m_cdl->setStyle(CDLOpData::CDL_V1_2_FWD);
}
}

Expand Down Expand Up @@ -1837,6 +1839,10 @@ void CTFReaderGammaElt::start(const char ** atts)
}
m_gamma->setStyle(style);
isStyleFound = true;

// Set default parameters for all channels.
const GammaOpData::Params params = GammaOpData::getIdentityParameters(m_gamma->getStyle());
m_gamma->setParams(params);
}

i += 2;
Expand All @@ -1857,10 +1863,6 @@ void CTFReaderGammaElt::end()
{
CTFReaderOpElt::end();

// Set default alpha parameters.
const GammaOpData::Params paramsA = GammaOpData::getIdentityParameters(m_gamma->getStyle());
m_gamma->setAlphaParams(paramsA);

// Validate the end result.
try
{
Expand Down Expand Up @@ -1906,21 +1908,6 @@ bool CTFReaderGammaElt::isValid(const GammaOpData::Style style) const noexcept
return false;
}

void CTFReaderGammaElt_1_5::end()
{
CTFReaderOpElt::end();

// Validate the end result.
try
{
getGamma()->validateParameters();
}
catch (Exception & ce)
{
ThrowM(*this, "Invalid parameters: ", ce.what(), ".");
}
}

CTFReaderGammaParamsEltRcPtr CTFReaderGammaElt_1_5::createGammaParamsElt(
const std::string & name,
ContainerEltRcPtr pParent,
Expand Down Expand Up @@ -2669,59 +2656,10 @@ bool CTFReaderLogParamsElt::parseCineon(const char ** atts, unsigned i,
return false;
}

void CTFReaderLogParamsElt::start(const char ** atts)
void CTFReaderLogParamsElt::setCineon(LogUtil::CTFParams & legacyParams, int chan,
double gamma, double refWhite,
double refBlack, double highlight, double shadow)
{
CTFReaderLogElt * pLogElt = dynamic_cast<CTFReaderLogElt*>(getParent().get());

LogUtil::CTFParams & legacyParams = pLogElt->getCTFParams();

// Attributes we want to extract.

int chan = -1;

// Legacy Log/Lin parameters:
double gamma = std::numeric_limits<double>::quiet_NaN();
double refWhite = std::numeric_limits<double>::quiet_NaN();
double refBlack = std::numeric_limits<double>::quiet_NaN();
double highlight = std::numeric_limits<double>::quiet_NaN();
double shadow = std::numeric_limits<double>::quiet_NaN();

// Try extracting the attributes.
unsigned i = 0;
while (atts[i])
{
if (0 == Platform::Strcasecmp(ATTR_CHAN, atts[i]))
{
if (0 == Platform::Strcasecmp("R", atts[i + 1]))
{
chan = 0;
}
else if (0 == Platform::Strcasecmp("G", atts[i + 1]))
{
chan = 1;
}
else if (0 == Platform::Strcasecmp("B", atts[i + 1]))
{
chan = 2;
}
// Chan is optional but, if present, must be legal.
else
{
std::ostringstream arg;
arg << "Illegal channel attribute value '";
arg << atts[i + 1] << "'.";

throwMessage(arg.str());
}
}
else if (!parseCineon(atts, i, gamma, refWhite, refBlack, highlight, shadow))
{
logParameterWarning(atts[i]);
}

i += 2;
}

// Validate the attributes are appropriate for the log style and set
// the parameters (numeric validation is done by LogOpData::validate).

Expand Down Expand Up @@ -2761,8 +2699,6 @@ void CTFReaderLogParamsElt::start(const char ** atts)

// Assign the parameters to the object.

auto logOp = OCIO_DYNAMIC_POINTER_CAST<LogOpData>(pLogElt->getOp());

switch (chan)
{
case -1:
Expand All @@ -2782,6 +2718,62 @@ void CTFReaderLogParamsElt::start(const char ** atts)
}
}

void CTFReaderLogParamsElt::start(const char ** atts)
{
CTFReaderLogElt * pLogElt = dynamic_cast<CTFReaderLogElt*>(getParent().get());

LogUtil::CTFParams & legacyParams = pLogElt->getCTFParams();

// Attributes we want to extract.

int chan = -1;

// Legacy Log/Lin parameters:
double gamma = std::numeric_limits<double>::quiet_NaN();
double refWhite = std::numeric_limits<double>::quiet_NaN();
double refBlack = std::numeric_limits<double>::quiet_NaN();
double highlight = std::numeric_limits<double>::quiet_NaN();
double shadow = std::numeric_limits<double>::quiet_NaN();

// Try extracting the attributes.
unsigned i = 0;
while (atts[i])
{
if (0 == Platform::Strcasecmp(ATTR_CHAN, atts[i]))
{
if (0 == Platform::Strcasecmp("R", atts[i + 1]))
{
chan = 0;
}
else if (0 == Platform::Strcasecmp("G", atts[i + 1]))
{
chan = 1;
}
else if (0 == Platform::Strcasecmp("B", atts[i + 1]))
{
chan = 2;
}
// Chan is optional but, if present, must be legal.
else
{
std::ostringstream arg;
arg << "Illegal channel attribute value '";
arg << atts[i + 1] << "'.";

throwMessage(arg.str());
}
}
else if (!parseCineon(atts, i, gamma, refWhite, refBlack, highlight, shadow))
{
logParameterWarning(atts[i]);
}

i += 2;
}

setCineon(legacyParams, chan, gamma, refWhite, refBlack, highlight, shadow);
}

void CTFReaderLogParamsElt::end()
{
}
Expand Down Expand Up @@ -2815,11 +2807,11 @@ void CTFReaderLogParamsElt_2_0::start(const char ** atts)
double linearSlope = std::numeric_limits<double>::quiet_NaN();

// Legacy Log/Lin parameters (if allowed for CTF v2 onward:
double gamma = std::numeric_limits<double>::quiet_NaN();
double refWhite = std::numeric_limits<double>::quiet_NaN();
double refBlack = std::numeric_limits<double>::quiet_NaN();
double gamma = std::numeric_limits<double>::quiet_NaN();
double refWhite = std::numeric_limits<double>::quiet_NaN();
double refBlack = std::numeric_limits<double>::quiet_NaN();
double highlight = std::numeric_limits<double>::quiet_NaN();
double shadow = std::numeric_limits<double>::quiet_NaN();
double shadow = std::numeric_limits<double>::quiet_NaN();

// Try extracting the attributes.
unsigned i = 0;
Expand Down Expand Up @@ -2902,6 +2894,12 @@ void CTFReaderLogParamsElt_2_0::start(const char ** atts)
i += 2;
}

if (legacyParams.getType() == LogUtil::CTFParams::CINEON)
{
setCineon(legacyParams, chan, gamma, refWhite, refBlack, highlight, shadow);
return;
}

// Validate the attributes are appropriate for the log style and set
// the parameters (numeric validation is done by LogOpData::validate).

Expand All @@ -2918,23 +2916,34 @@ void CTFReaderLogParamsElt_2_0::start(const char ** atts)
pLogElt->setBase(base);
}

if (cameraStyle)
// The LogOpData does not have a style member, so some validation needs to happen here.

if (!IsNan(linSideBreak))
{
if (!IsNan(linSideBreak))
if (!cameraStyle)
{
newParams.push_back(linSideBreak);
}
else
{
ThrowM(*this, "Parameters '", ATTR_LINSIDEBREAK, "' should be defined for style '",
ThrowM(*this, "Parameter '", ATTR_LINSIDEBREAK, "' is only allowed for style '",
LogUtil::ConvertStyleToString(LogUtil::CAMERA_LOG_TO_LIN), "' or '",
LogUtil::ConvertStyleToString(LogUtil::CAMERA_LIN_TO_LOG), "'.");
}
newParams.push_back(linSideBreak);
}
else if (cameraStyle)
{
ThrowM(*this, "Parameter '", ATTR_LINSIDEBREAK, "' should be defined for style '",
LogUtil::ConvertStyleToString(LogUtil::CAMERA_LOG_TO_LIN), "' or '",
LogUtil::ConvertStyleToString(LogUtil::CAMERA_LIN_TO_LOG), "'. ");
}

if (!IsNan(linearSlope))
if (!IsNan(linearSlope))
{
if (!cameraStyle)
{
newParams.push_back(linearSlope);
ThrowM(*this, "Parameter '", ATTR_LINEARSLOPE, "' is only allowed for style '",
LogUtil::ConvertStyleToString(LogUtil::CAMERA_LOG_TO_LIN), "' or '",
LogUtil::ConvertStyleToString(LogUtil::CAMERA_LIN_TO_LOG), "'. ");
}
newParams.push_back(linearSlope);
}

auto logOp = OCIO_DYNAMIC_POINTER_CAST<LogOpData>(pLogElt->getOp());
Expand Down
4 changes: 2 additions & 2 deletions src/OpenColorIO/fileformats/ctf/CTFReaderHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,6 @@ class CTFReaderGammaElt_1_5 : public CTFReaderGammaElt
CTFReaderGammaElt_1_5() : CTFReaderGammaElt() {}
~CTFReaderGammaElt_1_5() {}

void end() override;

CTFReaderGammaParamsEltRcPtr createGammaParamsElt(
const std::string & name,
ContainerEltRcPtr pParent,
Expand Down Expand Up @@ -730,6 +728,8 @@ class CTFReaderLogParamsElt : public XmlReaderPlainElt
bool parseCineon(const char ** atts, unsigned i, double & gamma, double & refWhite,
double & refBlack, double & highlight, double & shadow);

void setCineon(LogUtil::CTFParams & legacyParams, int chan, double gamma,
double refWhite, double refBlack, double highlight, double shadow);
};

class CTFReaderLogParamsElt_2_0 : public CTFReaderLogParamsElt
Expand Down
Loading