|
| 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 |
0 commit comments