Skip to content

Commit 184566e

Browse files
authored
Built-In Transform support for Apple Log (#1941)
* Built-In Transform support for Apple Log Signed-off-by: Joseph Goldstone <jgoldstone@arri.com> * Add Apple Log to Linear curve Signed-off-by: Joseph Goldstone <jgoldstone@arri.com> * Don't allow use of Apple Log in pre-2.4 configs; create half LUT to avoid clipping input Signed-off-by: Joseph Goldstone <jgoldstone@arri.com> * Insert std:: in front of that square root Signed-off-by: Joseph Goldstone <jgoldstone@arri.com> * Bump minor version number to 4 in testing config (stored as string literal); bump LastSupportedMinorVersion to 4 Signed-off-by: Joseph Goldstone <jgoldstone@arri.com> * Adjust string literal against which maximum minor version is tested to be 4, not 3 Signed-off-by: Joseph Goldstone <jgoldstone@arri.com> --------- Signed-off-by: Joseph Goldstone <jgoldstone@arri.com>
1 parent 0c90ded commit 184566e

9 files changed

Lines changed: 146 additions & 5 deletions

File tree

src/OpenColorIO/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ set(SOURCES
150150
transforms/builtins/BuiltinTransformRegistry.cpp
151151
transforms/builtins/ColorMatrixHelpers.cpp
152152
transforms/builtins/OpHelpers.cpp
153+
transforms/builtins/AppleCameras.cpp
153154
transforms/builtins/ArriCameras.cpp
154155
transforms/builtins/CanonCameras.cpp
155156
transforms/builtins/Displays.cpp

src/OpenColorIO/Config.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static constexpr unsigned LastSupportedMajorVersion = OCIO_VERSION_MAJOR;
247247

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

253253
} // namespace
@@ -5231,6 +5231,16 @@ void Config::Impl::checkVersionConsistency(ConstTransformRcPtr & transform) cons
52315231
throw Exception("Only config version 2.3 (or higher) can have "
52325232
"BuiltinTransform style 'DISPLAY - CIE-XYZ-D65_to_DisplayP3'.");
52335233
}
5234+
if (m_majorVersion == 2 && m_minorVersion < 4
5235+
&& ( 0 == Platform::Strcasecmp(blt->getStyle(), "APPLE_LOG_to_ACES2065-1")
5236+
|| 0 == Platform::Strcasecmp(blt->getStyle(), "CURVE - APPLE_LOG_to_LINEAR") )
5237+
)
5238+
{
5239+
std::ostringstream os;
5240+
os << "Only config version 2.4 (or higher) can have BuiltinTransform style '"
5241+
<< blt->getStyle() << "'.";
5242+
throw Exception(os.str().c_str());
5243+
}
52345244
}
52355245
else if (ConstCDLTransformRcPtr cdl = DynamicPtrCast<const CDLTransform>(transform))
52365246
{
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright Contributors to the OpenColorIO Project.
3+
4+
5+
#include <cmath>
6+
7+
#include <OpenColorIO/OpenColorIO.h>
8+
9+
#include "ops/matrix/MatrixOp.h"
10+
#include "transforms/builtins/AppleCameras.h"
11+
#include "transforms/builtins/BuiltinTransformRegistry.h"
12+
#include "transforms/builtins/ColorMatrixHelpers.h"
13+
#include "transforms/builtins/OpHelpers.h"
14+
15+
16+
namespace OCIO_NAMESPACE
17+
{
18+
19+
namespace APPLE_LOG
20+
{
21+
22+
void GenerateAppleLogToLinearOps(OpRcPtrVec & ops)
23+
{
24+
auto GenerateLutValues = [](double in) -> float
25+
{
26+
constexpr double R_0 = -0.05641088;
27+
constexpr double R_t = 0.01;
28+
constexpr double c = 47.28711236;
29+
constexpr double beta = 0.00964052;
30+
constexpr double gamma = 0.08550479;
31+
constexpr double delta = 0.69336945;
32+
const double P_t = c * std::pow((R_t - R_0), 2.0);
33+
34+
if (in >= P_t)
35+
{
36+
return float(std::pow(2.0, (in - delta) / gamma) - beta);
37+
}
38+
else if (in < P_t && in >= 0.0)
39+
{
40+
return float(std::sqrt(in / c) + R_0);
41+
}
42+
else
43+
{
44+
return float(R_0);
45+
}
46+
};
47+
48+
CreateHalfLut(ops, GenerateLutValues);
49+
50+
}
51+
52+
} // namespace APPLE_LOG
53+
54+
namespace CAMERA
55+
{
56+
57+
namespace APPLE
58+
{
59+
60+
void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept
61+
{
62+
{
63+
auto APPLE_LOG_to_ACES2065_1_Functor = [](OpRcPtrVec & ops)
64+
{
65+
APPLE_LOG::GenerateAppleLogToLinearOps(ops);
66+
67+
MatrixOpData::MatrixArrayPtr matrix
68+
= build_conversion_matrix(REC2020::primaries, ACES_AP0::primaries, ADAPTATION_BRADFORD);
69+
CreateMatrixOp(ops, matrix, TRANSFORM_DIR_FORWARD);
70+
};
71+
72+
registry.addBuiltin("APPLE_LOG_to_ACES2065-1",
73+
"Convert Apple Log to ACES2065-1",
74+
APPLE_LOG_to_ACES2065_1_Functor);
75+
}
76+
{
77+
auto APPLE_LOG_to_Linear_Functor = [](OpRcPtrVec & ops)
78+
{
79+
APPLE_LOG::GenerateAppleLogToLinearOps(ops);
80+
};
81+
82+
registry.addBuiltin("CURVE - APPLE_LOG_to_LINEAR",
83+
"Convert Apple Log to linear",
84+
APPLE_LOG_to_Linear_Functor);
85+
}
86+
}
87+
88+
} // namespace APPLE
89+
90+
} // namespace CAMERA
91+
92+
} // namespace OCIO_NAMESPACE
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright Contributors to the OpenColorIO Project.
3+
4+
5+
#ifndef INCLUDED_OCIO_APPLE_CAMERAS_H
6+
#define INCLUDED_OCIO_APPLE_CAMERAS_H
7+
8+
9+
#include <OpenColorIO/OpenColorIO.h>
10+
11+
12+
namespace OCIO_NAMESPACE
13+
{
14+
15+
class BuiltinTransformRegistryImpl;
16+
17+
namespace CAMERA
18+
{
19+
20+
namespace APPLE
21+
{
22+
23+
void RegisterAll(BuiltinTransformRegistryImpl & registry) noexcept;
24+
25+
} // namespace APPLE
26+
27+
} // namespace CAMERA
28+
29+
} // namespace OCIO_NAMESPACE
30+
31+
#endif // INCLUDED_OCIO_APPLE_CAMERAS_H

src/OpenColorIO/transforms/builtins/BuiltinTransformRegistry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "OpBuilders.h"
1212
#include "Platform.h"
1313
#include "transforms/builtins/ACES.h"
14+
#include "transforms/builtins/AppleCameras.h"
1415
#include "transforms/builtins/ArriCameras.h"
1516
#include "transforms/builtins/BuiltinTransformRegistry.h"
1617
#include "transforms/builtins/CanonCameras.h"
@@ -109,6 +110,7 @@ void BuiltinTransformRegistryImpl::registerAll() noexcept
109110
ACES::RegisterAll(*this);
110111

111112
// Camera support.
113+
CAMERA::APPLE::RegisterAll(*this);
112114
CAMERA::ARRI::RegisterAll(*this);
113115
CAMERA::CANON::RegisterAll(*this);
114116
CAMERA::PANASONIC::RegisterAll(*this);

tests/cpu/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ set(SOURCES
161161
ScanlineHelper.cpp
162162
Transform.cpp
163163
transforms/builtins/ACES.cpp
164+
transforms/builtins/AppleCameras.cpp
164165
transforms/builtins/ArriCameras.cpp
165166
transforms/builtins/CanonCameras.cpp
166167
transforms/builtins/ColorMatrixHelpers.cpp

tests/cpu/Config_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,12 +2103,12 @@ OCIO_ADD_TEST(Config, version)
21032103
{
21042104
OCIO_CHECK_THROW_WHAT(config->setVersion(2, 9), OCIO::Exception,
21052105
"The minor version 9 is not supported for major version 2. "
2106-
"Maximum minor version is 3");
2106+
"Maximum minor version is 4");
21072107

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

21142114
{
@@ -9471,4 +9471,4 @@ OCIO_ADD_TEST(Config, create_from_config_io_proxy)
94719471
OCIO_REQUIRE_ASSERT(proc);
94729472
OCIO_CHECK_NO_THROW(proc->getDefaultCPUProcessor());
94739473
}
9474-
}
9474+
}

tests/cpu/transforms/BuiltinTransform_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ AllValues UnitTestValues
429429
{ "ACES-OUTPUT - ACES2065-1_to_CIE-XYZ-D65 - HDR-CINEMA-108nit-7.2nit-P3lim_1.1",
430430
{ { 0.5f, 0.4f, 0.3f }, { 0.22214814f, 0.21179835f, 0.15639816f } } },
431431

432+
{ "APPLE_LOG_to_ACES2065-1",
433+
{ { 0.5f, 0.4f, 0.3f }, { 0.153334766f, 0.083515430f, 0.032948254f } } },
434+
{ "CURVE - APPLE_LOG_to_LINEAR",
435+
{ { 0.5f, 0.4f, 0.3f }, { 0.198913991f, 0.083076466024f, 0.0315782763f } } },
432436
{ "ARRI_ALEXA-LOGC-EI800-AWG_to_ACES2065-1",
433437
{ { 0.5f, 0.4f, 0.3f }, { 0.401621427766f, 0.236455447604f, 0.064830001192f } } },
434438
{ "ARRI_LOGC4_to_ACES2065-1",

tests/cpu/transforms/builtins/BuiltinTransformRegistry_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ OCIO_ADD_TEST(Builtins, read_write)
9696
// builtin transforms.
9797

9898
static constexpr char CONFIG_BUILTIN_TRANSFORMS[] {
99-
R"(ocio_profile_version: 2.3
99+
R"(ocio_profile_version: 2.4
100100
101101
environment:
102102
{}

0 commit comments

Comments
 (0)