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

Built-In Transform support for Apple Log #1941

Merged
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
1 change: 1 addition & 0 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ set(SOURCES
transforms/builtins/BuiltinTransformRegistry.cpp
transforms/builtins/ColorMatrixHelpers.cpp
transforms/builtins/OpHelpers.cpp
transforms/builtins/AppleCameras.cpp
transforms/builtins/ArriCameras.cpp
transforms/builtins/CanonCameras.cpp
transforms/builtins/Displays.cpp
Expand Down
12 changes: 11 additions & 1 deletion src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static constexpr unsigned LastSupportedMajorVersion = OCIO_VERSION_MAJOR;

// For each major version keep the most recent minor.
static const unsigned int LastSupportedMinorVersion[] = {0, // Version 1
3 // Version 2
4 // Version 2
};

} // namespace
Expand Down Expand Up @@ -5231,6 +5231,16 @@ void Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform) cons
throw Exception("Only config version 2.3 (or higher) can have "
"BuiltinTransform style 'DISPLAY - CIE-XYZ-D65_to_DisplayP3'.");
}
if (m_majorVersion == 2 && m_minorVersion < 4
&& ( 0 == Platform::Strcasecmp(blt->getStyle(), "APPLE_LOG_to_ACES2065-1")
|| 0 == Platform::Strcasecmp(blt->getStyle(), "CURVE - APPLE_LOG_to_LINEAR") )
)
{
std::ostringstream os;
os << "Only config version 2.4 (or higher) can have BuiltinTransform style '"
<< blt->getStyle() << "'.";
throw Exception(os.str().c_str());
}
}
else if (ConstCDLTransformRcPtr cdl = DynamicPtrCast<const CDLTransform>(transform))
{
Expand Down
92 changes: 92 additions & 0 deletions src/OpenColorIO/transforms/builtins/AppleCameras.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.


#include <cmath>

#include <OpenColorIO/OpenColorIO.h>

#include "ops/matrix/MatrixOp.h"
#include "transforms/builtins/AppleCameras.h"
#include "transforms/builtins/BuiltinTransformRegistry.h"
#include "transforms/builtins/ColorMatrixHelpers.h"
#include "transforms/builtins/OpHelpers.h"


namespace OCIO_NAMESPACE
{

namespace APPLE_LOG
{

void GenerateAppleLogToLinearOps(OpRcPtrVec & ops)
{
auto GenerateLutValues = [](double in) -> float
{
constexpr double R_0 = -0.05641088;
constexpr double R_t = 0.01;
constexpr double c = 47.28711236;
constexpr double beta = 0.00964052;
constexpr double gamma = 0.08550479;
constexpr double delta = 0.69336945;
const double P_t = c * std::pow((R_t - R_0), 2.0);

if (in >= P_t)
{
return float(std::pow(2.0, (in - delta) / gamma) - beta);
}
else if (in < P_t && in >= 0.0)
{
return float(std::sqrt(in / c) + R_0);
}
else
{
return float(R_0);
}
};

CreateHalfLut(ops, GenerateLutValues);

}

} // namespace APPLE_LOG

namespace CAMERA
{

namespace APPLE
{

void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
{
{
auto APPLE_LOG_to_ACES2065_1_Functor = [](OpRcPtrVec & ops)
{
APPLE_LOG::GenerateAppleLogToLinearOps(ops);

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

registry.addBuiltin("APPLE_LOG_to_ACES2065-1",
"Convert Apple Log to ACES2065-1",
APPLE_LOG_to_ACES2065_1_Functor);
}
{
auto APPLE_LOG_to_Linear_Functor = [](OpRcPtrVec & ops)
{
APPLE_LOG::GenerateAppleLogToLinearOps(ops);
};

registry.addBuiltin("CURVE - APPLE_LOG_to_LINEAR",
"Convert Apple Log to linear",
APPLE_LOG_to_Linear_Functor);
}
}

} // namespace APPLE

} // namespace CAMERA

} // namespace OCIO_NAMESPACE
31 changes: 31 additions & 0 deletions src/OpenColorIO/transforms/builtins/AppleCameras.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenColorIO Project.


#ifndef INCLUDED_OCIO_APPLE_CAMERAS_H
#define INCLUDED_OCIO_APPLE_CAMERAS_H


#include <OpenColorIO/OpenColorIO.h>


namespace OCIO_NAMESPACE
{

class BuiltinTransformRegistryImpl;

namespace CAMERA
{

namespace APPLE
{

void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept;

} // namespace APPLE

} // namespace CAMERA

} // namespace OCIO_NAMESPACE

#endif // INCLUDED_OCIO_APPLE_CAMERAS_H
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "OpBuilders.h"
#include "Platform.h"
#include "transforms/builtins/ACES.h"
#include "transforms/builtins/AppleCameras.h"
#include "transforms/builtins/ArriCameras.h"
#include "transforms/builtins/BuiltinTransformRegistry.h"
#include "transforms/builtins/CanonCameras.h"
Expand Down Expand Up @@ -109,6 +110,7 @@ void BuiltinTransformRegistryImpl::registerAll() noexcept
ACES::RegisterAll(*this);

// Camera support.
CAMERA::APPLE::RegisterAll(*this);
CAMERA::ARRI::RegisterAll(*this);
CAMERA::CANON::RegisterAll(*this);
CAMERA::PANASONIC::RegisterAll(*this);
Expand Down
1 change: 1 addition & 0 deletions tests/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ set(SOURCES
ScanlineHelper.cpp
Transform.cpp
transforms/builtins/ACES.cpp
transforms/builtins/AppleCameras.cpp
transforms/builtins/ArriCameras.cpp
transforms/builtins/CanonCameras.cpp
transforms/builtins/ColorMatrixHelpers.cpp
Expand Down
6 changes: 3 additions & 3 deletions tests/cpu/Config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2103,12 +2103,12 @@ OCIO_ADD_TEST(Config, version)
{
OCIO_CHECK_THROW_WHAT(config->setVersion(2, 9), OCIO::Exception,
"The minor version 9 is not supported for major version 2. "
"Maximum minor version is 3");
"Maximum minor version is 4");

OCIO_CHECK_NO_THROW(config->setMajorVersion(2));
OCIO_CHECK_THROW_WHAT(config->setMinorVersion(9), OCIO::Exception,
"The minor version 9 is not supported for major version 2. "
"Maximum minor version is 3");
"Maximum minor version is 4");
}

{
Expand Down Expand Up @@ -9471,4 +9471,4 @@ OCIO_ADD_TEST(Config, create_from_config_io_proxy)
OCIO_REQUIRE_ASSERT(proc);
OCIO_CHECK_NO_THROW(proc->getDefaultCPUProcessor());
}
}
}
4 changes: 4 additions & 0 deletions tests/cpu/transforms/BuiltinTransform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ AllValues UnitTestValues
{ "ACES-OUTPUT - ACES2065-1_to_CIE-XYZ-D65 - HDR-CINEMA-108nit-7.2nit-P3lim_1.1",
{ { 0.5f, 0.4f, 0.3f }, { 0.22214814f, 0.21179835f, 0.15639816f } } },

{ "APPLE_LOG_to_ACES2065-1",
{ { 0.5f, 0.4f, 0.3f }, { 0.153334766f, 0.083515430f, 0.032948254f } } },
{ "CURVE - APPLE_LOG_to_LINEAR",
{ { 0.5f, 0.4f, 0.3f }, { 0.198913991f, 0.083076466024f, 0.0315782763f } } },
{ "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",
Expand Down
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.3
R"(ocio_profile_version: 2.4

environment:
{}
Expand Down
Loading