Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
5c784aa
Extend ocioperf to take config file parameter on CLI
KevinJW Dec 23, 2024
da0ab98
Extend ocioconvert to take config on command line
KevinJW Dec 24, 2024
b5ef4f2
Extract tonescale_fwd function
KevinJW Dec 24, 2024
14244a8
Extract inverse tonescale function
KevinJW Dec 24, 2024
3733698
Combine c and Z variables in J calculation exponent
KevinJW Jan 6, 2025
2286c57
Split RGB<->JMh function into two parts to expose opponent intermedia…
KevinJW Jan 6, 2025
a399575
Use function to compute matrix multiply for LMS calculations
KevinJW Jan 6, 2025
dab7c7a
Remove unused member variable from JMhParams structure
KevinJW Jan 2, 2025
bb80581
Combine chromatic adaptation weights into LMS matrix (and inverse) - …
KevinJW Jan 6, 2025
2fb497b
Use matrix form for transforming cone responses to Aab
KevinJW Jan 2, 2025
9e70f69
Normalise the F_L parameter
KevinJW Jan 6, 2025
26a0881
Remove ra and ba related variables to avoid them being out of sync wi…
KevinJW Jan 6, 2025
1f3b100
Make A<->J conversion function generic
KevinJW Jan 3, 2025
b621391
Deduplicate Y<->J conversions
KevinJW Jan 3, 2025
593e2ca
Factor JMh scaling parameters into Aab matrices
KevinJW Jan 3, 2025
db07f82
factor our references to PI, 360 and 180 constants
KevinJW Jan 3, 2025
c7415c7
Add functions to explain some of the calculations
KevinJW Jan 6, 2025
3651734
Further clarify when 100 means reference luminance
KevinJW Jan 7, 2025
590b3eb
migrate init steps performed within other init functions to the top l…
KevinJW Jan 7, 2025
ae7ddaa
extract some of the fixed values that only depend on the hue to reduc…
KevinJW Jan 7, 2025
f466d84
Avoid double lookup for reachMaxM value by resolving once the hue is …
KevinJW Jan 9, 2025
34794cd
Push wrapping of hues to the boundary,
KevinJW Jan 9, 2025
07cab5d
Store gamma values as reciprocals
KevinJW Jan 9, 2025
a6c7800
Add some missing includes to headers
KevinJW Jan 13, 2025
e567701
minor cleanup to use std::array instead of plain array for test samples
KevinJW Jan 13, 2025
4a9e1f7
Inline reach boundary finding
KevinJW Jan 10, 2025
b0f3962
Extract gamut mapper compression function
KevinJW Jan 10, 2025
05da229
Rework gamut mapper to compress absolute M then only recalculate calc…
KevinJW Jan 10, 2025
f8498c6
Precalculate maximum search range for cusp lookup
KevinJW Jan 13, 2025
90c6765
Experiment with reusing slope calculations in gamut mapper
KevinJW Jan 15, 2025
4a83479
Add a collection of TODO's
KevinJW Jan 15, 2025
a9a5c9a
Restore function mapping table index to hue
KevinJW Jan 15, 2025
a2ba534
Minor tweaks to tonescale inverse clamp
KevinJW Jan 16, 2025
9720a15
Remove duplicate table whilst calculating upper hull gamma
KevinJW Jan 16, 2025
f9b8087
Add some additional sample points for the upper hull gamma finder
KevinJW Jan 17, 2025
d661f07
Slight tidy up of gamma fitting code
KevinJW Jan 17, 2025
16f9d20
Experiment with alternate smin implementation
KevinJW Jan 17, 2025
d8a2536
Remove unused function and tidy up comments
KevinJW Jan 20, 2025
c4e05c1
Extract hue search into separate function
KevinJW Jan 20, 2025
ff6ca09
Extract hues into separate table, merge gamma values into their place…
KevinJW Jan 27, 2025
11856b9
Simplify upper hull gamma hue lookup to avoid unneeded lerping as we …
KevinJW Jan 21, 2025
bec1240
Split out tonescale function, minor tweaks to Aab->JMh
KevinJW Jan 21, 2025
3233ade
Build tables more uniformly, needs some clean up and lots of testing
KevinJW Jan 22, 2025
04a867a
Speed up reach corner finding by switching to testing against the Ach…
KevinJW Jan 23, 2025
426e3e7
Speed up hull gamma finding by computing values which depend only on …
KevinJW Jan 23, 2025
f1937a1
Adjust GPU hue lookup to take advantage of more uniform distribution
KevinJW Jan 27, 2025
debd979
Fix GLSL compatibility with hue lookup
KevinJW Jan 27, 2025
0fca9e6
Attempt to simplify table generation code
KevinJW Jan 27, 2025
2c69445
Explicilty allow GCC to perform additional optimisations - Needs some…
KevinJW Jan 27, 2025
fdde652
Add extra entries to reach table to avoid needing to clamp to range d…
KevinJW Jan 27, 2025
a40be0c
GPU move reach Max M sampling to avoid looking it up multiple times p…
KevinJW Jan 28, 2025
a77c9f2
Remove smoothing from GPU path, it is baked into the csup
KevinJW Jan 28, 2025
f4d0641
Fix bug with reach lookup
KevinJW Jan 29, 2025
caf7b6c
Try only wrap hues on input to the shaders
KevinJW Jan 29, 2025
a4f4596
rework GPU camut compressor to follow the same algorithm as CPU. Not …
KevinJW Jan 31, 2025
fd981f8
Rework solve_J_intersect to have fewer div instructions
KevinJW Jan 31, 2025
903a98d
Adjust GPU code to better align with CPU code's structure, some addit…
KevinJW Jan 31, 2025
8213ba3
Precompute more scaling factors into matrices and nonlinear functions
KevinJW Feb 3, 2025
4a13c36
Experiment with unsigned integers for array access
KevinJW Feb 4, 2025
6d609bc
Bypass one J-> A conversion by saving the Aab computed earlier
KevinJW Feb 5, 2025
da17d7c
Test intrinsics for compression Norm calculation
KevinJW Feb 5, 2025
7e96bdf
Attempt to calculate sin/cos only once per pixel.
KevinJW Feb 19, 2025
36db212
Remove unused parameters
KevinJW Feb 19, 2025
e3aa39f
Try tree vectoriser for gcc
KevinJW Feb 19, 2025
07abe0a
Add Vectorise option for MSVC
KevinJW Feb 19, 2025
abe5658
Remove unused function
KevinJW Feb 20, 2025
bb59154
Constexpr std::max is only available in C++ 14 for now avoid the call…
KevinJW Feb 20, 2025
e7c0dac
Try to fir intrinsic based errors on osome build configurations
KevinJW Feb 20, 2025
430043b
Another C++ 14 usage fix
KevinJW Feb 20, 2025
eab4a65
Remove check for CLANG left over from testing
KevinJW Feb 20, 2025
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
10 changes: 10 additions & 0 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ if(OCIO_USE_SIMD AND (OCIO_ARCH_X86 OR OCIO_USE_SSE2NEON))
set_property(SOURCE ops/lut3d/Lut3DOpCPU_AVX.cpp APPEND PROPERTY COMPILE_OPTIONS ${OCIO_AVX_ARGS})
set_property(SOURCE ops/lut3d/Lut3DOpCPU_AVX2.cpp APPEND PROPERTY COMPILE_OPTIONS ${OCIO_AVX2_ARGS})
set_property(SOURCE ops/lut3d/Lut3DOpCPU_AVX512.cpp APPEND PROPERTY COMPILE_OPTIONS ${OCIO_AVX512_ARGS})
set_property(SOURCE ops/fixedfunction/ACES2/Transform.cpp APPEND PROPERTY COMPILE_OPTIONS ${OCIO_SSE2_ARGS} ${OCIO_AVX_ARGS})
endif()

# TODO: What to do for other compilers?
if(USE_GCC)
set_property(SOURCE ops/fixedfunction/ACES2/Transform.cpp APPEND PROPERTY COMPILE_OPTIONS
-fno-math-errno -fno-signed-zeros -fno-trapping-math -fno-signaling-nans -ffinite-math-only -freciprocal-math -ftree-vectorize)
endif()
if(MSVC)
set_property(SOURCE ops/fixedfunction/ACES2/Transform.cpp APPEND PROPERTY COMPILE_OPTIONS /Qvec)
endif()

configure_file(CPUInfoConfig.h.in CPUInfoConfig.h)
Expand Down
1 change: 1 addition & 0 deletions src/OpenColorIO/ops/fixedfunction/ACES2/ColorLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "transforms/builtins/ColorMatrixHelpers.h"
#include "MatrixLib.h"

#include <cmath>

namespace OCIO_NAMESPACE
{
Expand Down
149 changes: 115 additions & 34 deletions src/OpenColorIO/ops/fixedfunction/ACES2/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,98 @@
#include "MatrixLib.h"
#include "ColorLib.h"

#include <cmath>

namespace OCIO_NAMESPACE
{

namespace ACES2
{
constexpr float PI = 3.14159265358979f;

constexpr int TABLE_SIZE = 360;
constexpr int TABLE_ADDITION_ENTRIES = 2;
constexpr int TABLE_TOTAL_SIZE = TABLE_SIZE + TABLE_ADDITION_ENTRIES;
constexpr int GAMUT_TABLE_BASE_INDEX = 1;
constexpr float hue_limit = 360.0f;
//constexpr float hue_limit = 2.0f * PI;
inline float _wrap_to_hue_limit(float y)
{
if ( y < 0.f)
{
y = y + hue_limit;
}
return y;
}

inline float wrap_to_hue_limit(float hue)
{
float y = std::fmod(hue, hue_limit);
return _wrap_to_hue_limit(y);
}
inline constexpr float to_degrees(const float v) { return v; }
inline float from_degrees(const float v) { return wrap_to_hue_limit(v); }
inline constexpr float to_radians(const float v) { return PI * v / 180.0f; };
inline float _from_radians(const float v) { return _wrap_to_hue_limit(180.0f * v / PI); }; // v needs to be wrapped already
inline float from_radians(const float v) { return wrap_to_hue_limit(180.0f * v / PI); };
/*
inline constexpr float to_degrees(const float v) { return 180.0f * v / PI; }
inline float from_degrees(const float v) { return wrap_to_hue_limit(PI * v / 180.0f); }
inline constexpr float to_radians(const float v) { return v; }
inline float _from_radians(const float v) { return _wrap_to_hue_limit(v); };
inline float from_radians(const float v) { return wrap_to_hue_limit(v); };
*/

struct TableBase
{
static constexpr unsigned int _TABLE_ADDITION_ENTRIES = 2;
static constexpr unsigned int base_index = 1;
static constexpr unsigned int nominal_size = 360;
static constexpr unsigned int total_size = nominal_size + _TABLE_ADDITION_ENTRIES;

static constexpr unsigned int lower_wrap_index = 0;
static constexpr unsigned int upper_wrap_index = base_index + nominal_size;
static constexpr unsigned int first_nominal_index = base_index;
static constexpr unsigned int last_nominal_index = upper_wrap_index - 1;

inline float base_hue_for_position(unsigned int i_lo) const
{
if (hue_limit == float(nominal_size)) // TODO C++ 17 if constexpr
return float(i_lo);

const float result = i_lo * hue_limit / nominal_size;
return result;
}

inline unsigned int hue_position_in_uniform_table(float wrapped_hue) const
{
if (hue_limit == float(nominal_size)) // TODO C++ 17 if constexpr
return static_cast<unsigned int>(wrapped_hue);
else
return static_cast<unsigned int>(wrapped_hue / hue_limit * float(nominal_size)); // TODO: can we use the 'lost' fraction for the lerps?
}

inline unsigned int nominal_hue_position_in_uniform_table(float wrapped_hue) const
{
return first_nominal_index + hue_position_in_uniform_table(wrapped_hue);
}
};

struct Table3D
struct Table3D : public TableBase, std::array<float[3], TableBase::total_size>
{
static constexpr int base_index = GAMUT_TABLE_BASE_INDEX;
static constexpr int size = TABLE_SIZE;
static constexpr int total_size = TABLE_TOTAL_SIZE;
float table[TABLE_TOTAL_SIZE][3];
};

struct Table1D
struct Table1D : public TableBase, std::array<float, TableBase::total_size>
{
static constexpr int base_index = GAMUT_TABLE_BASE_INDEX;
static constexpr int size = TABLE_SIZE;
static constexpr int total_size = TABLE_TOTAL_SIZE;
float table[TABLE_TOTAL_SIZE];
};

struct JMhParams
{
float F_L;
float z;
float A_w;
m33f MATRIX_RGB_to_CAM16_c;
m33f MATRIX_CAM16_c_to_RGB;
m33f MATRIX_cone_response_to_Aab;
m33f MATRIX_Aab_to_cone_response;
float F_L_n; // F_L normalised
float cz;
float inv_cz; // 1/cz
float A_w_J;
f3 XYZ_w;
f3 D_RGB;
m33f MATRIX_RGB_to_CAM16;
m33f MATRIX_CAM16_to_RGB;
float inv_A_w_J; // 1/A_w_J
};

struct ToneScaleParams
Expand All @@ -57,41 +111,63 @@ struct ToneScaleParams
float s_2;
float u_2;
float m_2;
float forward_limit;
float inverse_limit;
float log_peak;
};

struct ChromaCompressParams
struct SharedCompressionParameters
{
float limit_J_max;
float model_gamma;
float model_gamma_inv;
Table1D reach_m_table;
};

struct ResolvedSharedCompressionParameters
{
float limit_J_max;
float model_gamma_inv;
float reachMaxM;
};

struct ChromaCompressParams
{
float sat;
float sat_thr;
float compr;
Table1D reach_m_table;
float chroma_compress_scale;
static constexpr float cusp_mid_blend = 1.3f;
};

struct HueDependantGamutParams
{
float gamma_bottom_inv;
f2 JMcusp;
float gamma_top_inv;
float focusJ;
float analytical_threshold;
};
struct GamutCompressParams
{
float limit_J_max;
float mid_J;
float model_gamma;
float focus_dist;
float lower_hull_gamma;
Table1D reach_m_table;
float lower_hull_gamma_inv;
std::array<int, 2> hue_linearity_search_range;
Table1D hue_table;;
Table3D gamut_cusp_table;
Table1D upper_hull_gamma_table;
};

// CAM
constexpr float reference_luminance = 100.f;
constexpr float L_A = 100.f;
constexpr float Y_b = 20.f;
constexpr float ac_resp = 1.f;
constexpr float ra = 2.f * ac_resp;
constexpr float ba = 0.05f + (2.f - ra);
constexpr f3 surround = {0.9f, 0.59f, 0.9f}; // Dim surround

constexpr float J_scale = 100.0f;
constexpr float cam_nl_Y_reference = 100.0f;
constexpr float cam_nl_offset = 0.2713f * cam_nl_Y_reference;
constexpr float cam_nl_scale = 4.0f * cam_nl_Y_reference;

// Chroma compression
constexpr float chroma_compress = 2.4f;
constexpr float chroma_compress_fact = 3.3f;
Expand All @@ -100,11 +176,11 @@ constexpr float chroma_expand_fact = 0.69f;
constexpr float chroma_expand_thr = 0.5f;

// Gamut compression
constexpr float smooth_cusps = 0.12f;
constexpr float smooth_cusps = 0.12f; // C++ 14 required for constexpr std::max(0.000001f, 0.12f);
constexpr float smooth_m = 0.27f;
constexpr float cusp_mid_blend = 1.3f;
constexpr float focus_gain_blend = 0.3f;
constexpr float focus_adjust_gain = 0.55f;
constexpr float focus_adjust_gain_inv = 1.0f / 0.55f;
constexpr float focus_distance = 1.35f;
constexpr float focus_distance_scaling = 1.75f;
constexpr float compression_threshold = 0.75f;
Expand All @@ -125,6 +201,11 @@ constexpr float gammaMaximum = 5.0f;
constexpr float gammaSearchStep = 0.4f;
constexpr float gammaAccuracy = 1e-5f;

constexpr int cuspCornerCount = 6;
constexpr int totalCornerCount = cuspCornerCount + 2;
constexpr int max_sorted_corners = 2 * cuspCornerCount;
constexpr float reach_cusp_tolerance = 1e-3f;
constexpr float display_cusp_tolerance = 1e-7f;

} // namespace ACES2

Expand Down
1 change: 1 addition & 0 deletions src/OpenColorIO/ops/fixedfunction/ACES2/MatrixLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ops/matrix/MatrixOpData.h"

#include <array>

namespace OCIO_NAMESPACE
{
Expand Down
Loading