Skip to content

Commit

Permalink
Adsk contrib - Add Built-in Transforms for ARRI LogC4 and Canon curves (
Browse files Browse the repository at this point in the history
#1704)

* Add LogC4 and Canon curves

Signed-off-by: Doug Walker <doug.walker@autodesk.com>

* Refactor Canon curves

Signed-off-by: Doug Walker <doug.walker@autodesk.com>

* Add checkVersionConsistency test

Signed-off-by: Doug Walker <doug.walker@autodesk.com>

* Update comment

Signed-off-by: Doug Walker <doug.walker@autodesk.com>

Signed-off-by: Doug Walker <doug.walker@autodesk.com>
  • Loading branch information
doug-walker committed Oct 27, 2022
1 parent 34284f5 commit 5dc32f9
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 42 deletions.
13 changes: 11 additions & 2 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4736,6 +4736,17 @@ void Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform) cons
throw Exception("Only config version 2.1 (or higher) can have "
"BuiltinTransform style 'ACES-LMT - ACES 1.3 Reference Gamut Compression'.");
}
if (m_majorVersion == 2 && m_minorVersion < 2
&& ( 0 == Platform::Strcasecmp(blt->getStyle(), "ARRI_LOGC4_to_ACES2065-1")
|| 0 == Platform::Strcasecmp(blt->getStyle(), "CURVE - CANON_CLOG2_to_LINEAR")
|| 0 == Platform::Strcasecmp(blt->getStyle(), "CURVE - CANON_CLOG3_to_LINEAR") )
)
{
std::ostringstream os;
os << "Only config version 2.2 (or higher) can have BuiltinTransform style '"
<< blt->getStyle() << "'.";
throw Exception(os.str().c_str());
}
}
else if (ConstCDLTransformRcPtr cdl = DynamicPtrCast<const CDLTransform>(transform))
{
Expand Down Expand Up @@ -4785,13 +4796,11 @@ void Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform) cons
{
throw Exception("Only config version 2 (or higher) can use 'cubic' "
"interpolation with FileTransform.");

}
if (ft->getCDLStyle() != CDL_TRANSFORM_DEFAULT)
{
throw Exception("Only config version 2 (or higher) can use CDL style' "
"for FileTransform.");

}
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/OpenColorIO/transforms/builtins/ArriCameras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ static const Chromaticities wht_xy(0.31270, 0.32900);
const Primaries primaries(red_xy, grn_xy, blu_xy, wht_xy);
}

namespace ARRI_WIDE_GAMUT_4
{
static const Chromaticities red_xy(0.73470, 0.26530);
static const Chromaticities grn_xy(0.14240, 0.85760);
static const Chromaticities blu_xy(0.09910, -0.03080);
static const Chromaticities wht_xy(0.31270, 0.32900);

const Primaries primaries(red_xy, grn_xy, blu_xy, wht_xy);
}

namespace ARRI_ALEXA_LOGC_EI800_to_LINEAR
{
static constexpr double linSideSlope = 1. / (0.18 * 0.005 * (800. / 400.) / 0.01);
Expand All @@ -40,6 +50,21 @@ static const LogOpData::Params
static const LogOpData log(base, params, params, params, TRANSFORM_DIR_INVERSE);
}

namespace ARRI_LOGC4_to_LINEAR
{
static constexpr double linSideSlope = 2231.82630906769;
static constexpr double linSideOffset = 64.0;
static constexpr double logSideSlope = 0.0647954196341293;
static constexpr double logSideOffset = -0.295908392682586;
static constexpr double linSideBreak = -0.0180569961199113;
static constexpr double base = 2.;

static const LogOpData::Params
params { logSideSlope, logSideOffset, linSideSlope, linSideOffset, linSideBreak };

static const LogOpData log(base, params, params, params, TRANSFORM_DIR_INVERSE);
}


namespace CAMERA
{
Expand All @@ -64,6 +89,22 @@ void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
"Convert ARRI ALEXA LogC (EI800) ALEXA Wide Gamut to ACES2065-1",
ARRI_ALEXA_LOGC_EI800_AWG_to_ACES2065_1_Functor);
}

{
auto ARRI_LOGC4_AWG4_to_ACES2065_1_Functor = [](OpRcPtrVec & ops)
{
LogOpDataRcPtr log = ARRI_LOGC4_to_LINEAR::log.clone();
CreateLogOp(ops, log, TRANSFORM_DIR_FORWARD);

MatrixOpData::MatrixArrayPtr matrix
= build_conversion_matrix(ARRI_WIDE_GAMUT_4::primaries, ACES_AP0::primaries, ADAPTATION_CAT02);
CreateMatrixOp(ops, matrix, TRANSFORM_DIR_FORWARD);
};

registry.addBuiltin("ARRI_LOGC4_to_ACES2065-1",
"Convert ARRI LogC4 to ACES2065-1",
ARRI_LOGC4_AWG4_to_ACES2065_1_Functor);
}
}

} // namespace ARRI
Expand Down
103 changes: 65 additions & 38 deletions src/OpenColorIO/transforms/builtins/CanonCameras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,48 @@ static const Chromaticities wht_xy(0.3127, 0.3290);
const Primaries primaries(red_xy, grn_xy, blu_xy, wht_xy);
}

namespace CANON_CLOG2
{
auto GenerateLutValues = [](double in) -> float
{
double out = 0.;

if (in < 0.092864125)
{
out = -(std::pow(10, (0.092864125 - in) / 0.24136077) - 1) / 87.099375;
}
else
{
out = (std::pow(10, (in - 0.092864125) / 0.24136077) - 1) / 87.099375;
}

return float(out * 0.9);
};
}

namespace CANON_CLOG3
{
auto GenerateLutValues = [](double in) -> float
{
double out = 0.;

if (in < 0.097465473)
{
out = -(std::pow(10, (0.12783901 - in) / 0.36726845) - 1) / 14.98325;
}
else if (in <= 0.15277891)
{
out = (in - 0.12512219) / 1.9754798;
}
else
{
out = (std::pow(10, (in - 0.12240537) / 0.36726845) - 1) / 14.98325;
}

return float(out * 0.9);
};
}


namespace CAMERA
{
Expand All @@ -39,23 +81,7 @@ void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
{
auto CANON_CLOG2_CGAMUT_to_ACES2065_1_Functor = [](OpRcPtrVec & ops)
{
auto GenerateLutValues = [](double in) -> float
{
double out = 0.;

if (in < 0.092864125)
{
out = -(std::pow(10, (0.092864125 - in) / 0.24136077) - 1) / 87.099375;
}
else
{
out = (std::pow(10, (in - 0.092864125) / 0.24136077) - 1) / 87.099375;
}

return float(out * 0.9);
};

CreateLut(ops, 4096, GenerateLutValues);
CreateLut(ops, 4096, CANON_CLOG2::GenerateLutValues);

MatrixOpData::MatrixArrayPtr matrix
= build_conversion_matrix(CANON_CGAMUT::primaries, ACES_AP0::primaries, ADAPTATION_CAT02);
Expand All @@ -66,30 +92,21 @@ void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
"Convert Canon Log 2 Cinema Gamut to ACES2065-1",
CANON_CLOG2_CGAMUT_to_ACES2065_1_Functor);
}
{
auto CANON_CLOG2_to_Linear_Functor = [](OpRcPtrVec & ops)
{
CreateLut(ops, 4096, CANON_CLOG2::GenerateLutValues);
};

registry.addBuiltin("CURVE - CANON_CLOG2_to_LINEAR",
"Convert Canon Log 2 to linear",
CANON_CLOG2_to_Linear_Functor);
}

{
auto CANON_CLOG3_CGAMUT_to_ACES2065_1_Functor = [](OpRcPtrVec & ops)
{
auto GenerateLutValues = [](double in) -> float
{
double out = 0.;

if (in < 0.097465473)
{
out = -(std::pow(10, (0.12783901 - in) / 0.36726845) - 1) / 14.98325;
}
else if (in <= 0.15277891)
{
out = (in - 0.12512219) / 1.9754798;
}
else
{
out = (std::pow(10, (in - 0.12240537) / 0.36726845) - 1) / 14.98325;
}

return float(out * 0.9);
};

CreateLut(ops, 4096, GenerateLutValues);
CreateLut(ops, 4096, CANON_CLOG3::GenerateLutValues);

MatrixOpData::MatrixArrayPtr matrix
= build_conversion_matrix(CANON_CGAMUT::primaries, ACES_AP0::primaries, ADAPTATION_CAT02);
Expand All @@ -100,6 +117,16 @@ void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
"Convert Canon Log 3 Cinema Gamut to ACES2065-1",
CANON_CLOG3_CGAMUT_to_ACES2065_1_Functor);
}
{
auto CANON_CLOG3_to_Linear_Functor = [](OpRcPtrVec & ops)
{
CreateLut(ops, 4096, CANON_CLOG3::GenerateLutValues);
};

registry.addBuiltin("CURVE - CANON_CLOG3_to_LINEAR",
"Convert Canon Log 3 to linear",
CANON_CLOG3_to_Linear_Functor);
}
}

} // namespace CANON
Expand Down
3 changes: 3 additions & 0 deletions tests/cpu/Config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6995,6 +6995,9 @@ ocio_profile_version: 1
OCIO_CHECK_THROW_WHAT(cfg = OCIO::Config::CreateFromStream(is),
OCIO::Exception,
"Only config version 2 (or higher) can have RangeTransform.");

// NOTE: For more tests of Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform)
// for Builtin Transform styles, please see BuiltinTransformRegistry_tests.cpp.
}

OCIO_ADD_TEST(Config, dynamic_properties)
Expand Down
6 changes: 6 additions & 0 deletions tests/cpu/transforms/BuiltinTransform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,16 @@ AllValues UnitTestValues

{ "ARRI_ALEXA-LOGC-EI800-AWG_to_ACES2065-1",
{ { 0.5f, 0.4f, 0.3f }, { 0.401621427766f, 0.236455447604f, 0.064830001192f } } },
{ "ARRI_LOGC4_to_ACES2065-1",
{ { 0.5f, 0.4f, 0.3f }, { 1.786878082249f, 0.743018593362f, 0.232840037656f } } },
{ "CANON_CLOG2-CGAMUT_to_ACES2065-1",
{ { 0.5f, 0.4f, 0.3f }, { 0.408435767126f, 0.197486903378f, 0.034204558318f } } },
{ "CURVE - CANON_CLOG2_to_LINEAR",
{ { 0.5f, 0.4f, 0.3f }, { 0.492082215086f, 0.183195624930f, 0.064213555991f } } },
{ "CANON_CLOG3-CGAMUT_to_ACES2065-1",
{ { 0.5f, 0.4f, 0.3f }, { 0.496034919950f, 0.301015360499f, 0.083691829261f } } },
{ "CURVE - CANON_CLOG3_to_LINEAR",
{ { 0.5f, 0.4f, 0.3f }, { 0.580777404788f, 0.282284436009f, 0.122823721131f } } },
{ "PANASONIC_VLOG-VGAMUT_to_ACES2065-1",
{ { 0.5f, 0.4f, 0.3f }, { 0.306918773245f, 0.148128050597f, 0.046334439047f } } },
{ "RED_REDLOGFILM-RWG_to_ACES2065-1",
Expand Down
47 changes: 45 additions & 2 deletions tests/cpu/transforms/builtins/BuiltinTransformRegistry_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ OCIO_ADD_TEST(Builtins, read_write)
// builtin transforms.

static constexpr char CONFIG_BUILTIN_TRANSFORMS[] {
R"(ocio_profile_version: 2.1
R"(ocio_profile_version: 2.2
environment:
{}
Expand Down Expand Up @@ -144,7 +144,7 @@ active_views: []
std::string configStr;
configStr += CONFIG_BUILTIN_TRANSFORMS;

// Add all the existing builtin transforms.
// Add all the existing builtin transforms to one big GroupTransform.

const size_t numBuiltins = reg->getNumBuiltins();
for (size_t idx = 0; idx < numBuiltins; ++idx)
Expand Down Expand Up @@ -261,3 +261,46 @@ active_views: []
"'ACES-LMT - ACES 1.3 Reference Gamut Compression'.");
}

OCIO_ADD_TEST(Builtins, version_2_1_validation)
{
// The unit test validates that the config reader checkVersionConsistency check throws for
// version 2.1 configs containing a Builtin Transform with the 2.2 style for ARRI LogC4.

static constexpr char CONFIG[] {
R"(ocio_profile_version: 2.1
environment:
{}
search_path: ""
strictparsing: true
luma: [0.2126, 0.7152, 0.0722]
roles:
default: ref
file_rules:
- !<Rule> {name: Default, colorspace: default}
displays:
Disp1:
- !<View> {name: View1, colorspace: test}
active_displays: []
active_views: []
colorspaces:
- !<ColorSpace>
name: ref
- !<ColorSpace>
name: test
from_scene_reference: !<BuiltinTransform> {style: ARRI_LOGC4_to_ACES2065-1})" };

std::istringstream iss;
iss.str(CONFIG);

OCIO_CHECK_THROW_WHAT(OCIO::Config::CreateFromStream(iss),
OCIO::Exception,
"Only config version 2.2 (or higher) can have BuiltinTransform style "\
"'ARRI_LOGC4_to_ACES2065-1'.");
}

0 comments on commit 5dc32f9

Please sign in to comment.