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

Filmic v6 #10976

Merged
merged 14 commits into from
Apr 2, 2022
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
31 changes: 31 additions & 0 deletions data/kernels/colorspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,34 @@ static inline void XYZ_adapt_D50(float4 *lms_in,
const float4 D50 = { 0.9642119944211994f, 1.0f, 0.8251882845188288f, 0.f };
*lms_in *= D50 / origin_illuminant;
}

static inline float4 gamut_check_Yrg(float4 Ych)
{
// Do a test conversion to Yrg
float4 Yrg = Ych_to_Yrg(Ych);

// Gamut-clip in Yrg at constant hue and luminance
// e.g. find the max chroma value that fits in gamut at the current hue
const float D65[4] = { 0.21962576f, 0.54487092f, 0.23550333f, 0.f };
float max_c = Ych.y;
const float cos_h = native_cos(Ych.z);
const float sin_h = native_sin(Ych.z);

if(Yrg.y < 0.f)
{
max_c = fmin(-D65[0] / cos_h, max_c);
}
if(Yrg.z < 0.f)
{
max_c = fmin(-D65[1] / sin_h, max_c);
}
if(Yrg.y + Yrg.z > 1.f)
{
max_c = fmin((1.f - D65[0] - D65[1]) / (cos_h + sin_h), max_c);
}

// Overwrite chroma with the sanitized value and
Ych.y = max_c;

return Ych;
}
27 changes: 3 additions & 24 deletions data/kernels/extended.cl
Original file line number Diff line number Diff line change
Expand Up @@ -854,31 +854,10 @@ colorbalancergb (read_only image2d_t in, write_only image2d_t out,
const float chroma_factor = fmax(1.f + chroma_boost + vib, 0.f);
Ych.y *= chroma_factor;

// Do a test conversion to Yrg
Yrg = Ych_to_Yrg(Ych);

// Gamut-clip in Yrg at constant hue and luminance
// e.g. find the max chroma value that fits in gamut at the current hue
const float D65[4] = { 0.21962576f, 0.54487092f, 0.23550333f, 0.f };
float max_c = Ych.y;
const float cos_h = native_cos(Ych.z);
const float sin_h = native_sin(Ych.z);

if(Yrg.y < 0.f)
{
max_c = fmin(-D65[0] / cos_h, max_c);
}
if(Yrg.z < 0.f)
{
max_c = fmin(-D65[1] / sin_h, max_c);
}
if(Yrg.y + Yrg.z > 1.f)
{
max_c = fmin((1.f - D65[0] - D65[1]) / (cos_h + sin_h), max_c);
}
// clip chroma at constant Y and hue
Ych = gamut_check_Yrg(Ych);

// Overwrite chroma with the sanitized value and go to Yrg for real
Ych.y = max_c;
// go to Yrg for real
Yrg = Ych_to_Yrg(Ych);

// Go to LMS
Expand Down
Loading