Skip to content

Commit c824a39

Browse files
committed
Update ProPhotoRGB conversion matrix and cleanup
Replace the old ROMM RGB D50 matrix and whitepoint offsets with a consolidated RGB_to_XYZ_D65 matrix and simplify the conversion path to CIE XYZ D65. Tidy up GenerateEncodedToLinearOps (lambda formatting and const handling), adjust small signature/spacing changes, and reformat registry functors and comments for clarity. This consolidates the D50->D65 adaptation into the published matrix and removes redundant constructs. Signed-off-by: Vlad <shaamaan@gmail.com>
1 parent f975dce commit c824a39

1 file changed

Lines changed: 47 additions & 67 deletions

File tree

src/OpenColorIO/transforms/builtins/ProPhotoRGB.cpp

Lines changed: 47 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright Contributors to the OpenColorIO Project.
33

4-
54
#include <cmath>
65

76
#include <OpenColorIO/OpenColorIO.h>
@@ -14,7 +13,6 @@
1413
#include "transforms/builtins/OpHelpers.h"
1514
#include "transforms/builtins/ProPhotoRGB.h"
1615

17-
1816
namespace OCIO_NAMESPACE
1917
{
2018

@@ -28,27 +26,18 @@ namespace OCIO_NAMESPACE
2826
static const Chromaticities red_xy(0.7347, 0.2653);
2927
static const Chromaticities grn_xy(0.1596, 0.8404);
3028
static const Chromaticities blu_xy(0.0366, 0.0001);
31-
static const Chromaticities wht_xy(0.3457, 0.3585); // D50
29+
static const Chromaticities wht_xy(0.3457, 0.3585); // D50
3230

3331
const Primaries primaries(red_xy, grn_xy, blu_xy, wht_xy);
3432

35-
static constexpr double RGB_to_XYZ_D50[4 * 4]
36-
{
37-
0.7977, 0.1352, 0.0313, 0.,
38-
0.2880, 0.7119, 0.0001, 0.,
39-
0.0000, 0.0000, 0.8249, 0.,
40-
0., 0., 0., 1.
41-
};
42-
43-
static const MatrixOpData::Offsets white_D50_XYZ(
44-
0.3457 / 0.3585,
45-
1.,
46-
(1.0 - 0.3457 - 0.3585) / 0.3585,
47-
0.);
33+
static constexpr double RGB_to_XYZ_D65[4 * 4]{
34+
0.7555287932957933, 0.11273621650716224, 0.0820865579632326, 0.,
35+
0.26824815751179243, 0.7151801391921419, 0.016570112476870784, 0.,
36+
0.003916686659314376, -0.012934540726208194, 1.0978022304574562, 0.,
37+
0., 0., 0., 1.};
4838

4939
} // namespace ROMM_RGB
5040

51-
5241
// ROMM RGB uses a piecewise gamma function with gamma 1.8.
5342
//
5443
// Encoded to Linear (decoding):
@@ -67,82 +56,73 @@ namespace OCIO_NAMESPACE
6756
{
6857

6958
static constexpr double gamma = 1.8;
70-
static constexpr double slope = 16.0; // Slope of linear segment.
71-
static constexpr double breakEnc = 1.0 / 32.0; // Encoded breakpoint
59+
static constexpr double slope = 16.0; // Slope of linear segment.
60+
static constexpr double breakEnc = 1.0 / 32.0; // Encoded breakpoint
7261

73-
void GenerateEncodedToLinearOps(OpRcPtrVec& ops)
62+
void GenerateEncodedToLinearOps(OpRcPtrVec &ops)
7463
{
7564
// Encoded gamma 1.8 to linear curve using LUT for accuracy.
7665
auto GenerateLutValues = [](double in) -> float
66+
{
67+
const double absIn = std::abs(in);
68+
double out = 0.0;
69+
70+
if (absIn < breakEnc)
7771
{
78-
const double absIn = std::abs(in);
79-
double out = 0.0;
80-
81-
if (absIn < breakEnc)
82-
{
83-
out = absIn / slope;
84-
}
85-
else
86-
{
87-
out = std::pow(absIn, gamma);
88-
}
89-
90-
return float(std::copysign(out, in));
91-
};
72+
out = absIn / slope;
73+
}
74+
else
75+
{
76+
out = std::pow(absIn, gamma);
77+
}
78+
79+
return float(std::copysign(out, in));
80+
};
9281

9382
CreateHalfLut(ops, GenerateLutValues);
9483
}
9584

9685
} // namespace ROMM_RGB_GAMMA_18
9786

98-
99-
10087
namespace PROPHOTO
10188
{
10289

103-
void RegisterAll(BuiltinTransformRegistryImpl& registry) noexcept
90+
void RegisterAll(BuiltinTransformRegistryImpl &registry) noexcept
10491
{
10592
// Linear ProPhoto RGB to ACES2065-1.
10693
{
107-
auto LINEAR_RIMM_to_ACES2065_1_BFD_Functor = [](OpRcPtrVec& ops)
108-
{
109-
// Convert from ROMM RGB (D50) to ACES AP0 (D60).
110-
// Uses Bradford chromatic adaptation.
111-
MatrixOpData::MatrixArrayPtr matrix
112-
= build_conversion_matrix(ROMM_RGB::primaries,
113-
ACES_AP0::primaries,
114-
ADAPTATION_BRADFORD);
115-
CreateMatrixOp(ops, matrix, TRANSFORM_DIR_FORWARD);
116-
};
94+
auto LINEAR_RIMM_to_ACES2065_1_BFD_Functor = [](OpRcPtrVec &ops)
95+
{
96+
// Convert from ROMM RGB (D50) to ACES AP0 (D60).
97+
// Uses Bradford chromatic adaptation.
98+
MatrixOpData::MatrixArrayPtr matrix = build_conversion_matrix(ROMM_RGB::primaries,
99+
ACES_AP0::primaries,
100+
ADAPTATION_BRADFORD);
101+
CreateMatrixOp(ops, matrix, TRANSFORM_DIR_FORWARD);
102+
};
117103

118104
registry.addBuiltin("LINEAR-RIMM_to_ACES2065-1_BFD",
119-
"Convert ProPhoto RGB (linear) to ACES2065-1",
120-
LINEAR_RIMM_to_ACES2065_1_BFD_Functor);
105+
"Convert ProPhoto RGB (linear) to ACES2065-1",
106+
LINEAR_RIMM_to_ACES2065_1_BFD_Functor);
121107
}
122108

123109
// Encoded ProPhoto RGB (gamma 1.8) to CIE XYZ D65.
124110
{
125-
auto ROMM_to_CIE_XYZ_D65_BFD_Functor = [](OpRcPtrVec& ops)
126-
{
127-
// 1. Decode gamma 1.8 to linear.
128-
ROMM_RGB_GAMMA_18::GenerateEncodedToLinearOps(ops);
129-
130-
// 2. Convert from the published ROMM RGB to XYZ(D50) matrix.
131-
CreateMatrixOp(ops, &ROMM_RGB::RGB_to_XYZ_D50[0], TRANSFORM_DIR_FORWARD);
132-
133-
// 3. Adapt XYZ from D50 to D65 using Bradford.
134-
MatrixOpData::MatrixArrayPtr matrix
135-
= build_vonkries_adapt(ROMM_RGB::white_D50_XYZ,
136-
WHITEPOINT::D65_XYZ,
137-
ADAPTATION_BRADFORD);
138-
CreateMatrixOp(ops, matrix, TRANSFORM_DIR_FORWARD);
139-
};
111+
auto ROMM_to_CIE_XYZ_D65_BFD_Functor = [](OpRcPtrVec &ops)
112+
{
113+
// 1. Decode gamma 1.8 to linear.
114+
ROMM_RGB_GAMMA_18::GenerateEncodedToLinearOps(ops);
115+
116+
// 2. Convert from ROMM RGB to CIE XYZ D65 using the
117+
// published ROMM RGB to XYZ(D50) matrix combined with
118+
// Bradford adaptation from D50 to D65.
119+
CreateMatrixOp(ops, &ROMM_RGB::RGB_to_XYZ_D65[0], TRANSFORM_DIR_FORWARD);
120+
};
140121

141122
registry.addBuiltin("ROMM_to_CIE-XYZ-D65_BFD",
142-
"Convert ProPhoto RGB (gamma 1.8 encoded) to CIE XYZ D65",
143-
ROMM_to_CIE_XYZ_D65_BFD_Functor);
123+
"Convert ProPhoto RGB (gamma 1.8 encoded) to CIE XYZ D65",
124+
ROMM_to_CIE_XYZ_D65_BFD_Functor);
144125
}
145-
146126
}
147127

148128
} // namespace PROPHOTO

0 commit comments

Comments
 (0)