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

Use non-native opencl pow function #17386

Closed
Closed
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
2 changes: 1 addition & 1 deletion data/kernels/colorequal.cl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static inline float4 gamut_map_HSB(float4 HSB, global float *gamut_LUT, const fl
{
float4 JCH = dt_UCS_HSB_to_JCH(HSB);
const float max_colorfulness = lookup_gamut(gamut_LUT, JCH.z);
const float max_chroma = 15.932993652962535f * native_powr(JCH.x * L_white, 0.6523997524738018f) * native_powr(max_colorfulness, 0.6007557017508491f) / L_white;
const float max_chroma = 15.932993652962535f * dtcl_pow(JCH.x * L_white, 0.6523997524738018f) * dtcl_pow(max_colorfulness, 0.6007557017508491f) / L_white;
const float4 JCH_gamut_boundary = { JCH.x, max_chroma, JCH.z, 0.0f };
const float4 HSB_gamut_boundary = dt_UCS_JCH_to_HSB(JCH_gamut_boundary);

Expand Down
18 changes: 9 additions & 9 deletions data/kernels/colorspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,14 @@ static inline float4 gamut_check_Yrg(float4 Ych)
static inline float Y_to_dt_UCS_L_star(const float Y)
{
// WARNING: L_star needs to be < 2.098883786377, meaning Y needs to be < 3.875766378407574e+19
const float Y_hat = native_powr(Y, 0.631651345306265f);
const float Y_hat = dtcl_pow(Y, 0.631651345306265f);
return 2.098883786377f * Y_hat / (Y_hat + 1.12426773749357f);
}

static inline float dt_UCS_L_star_to_Y(const float L_star)
{
// WARNING: L_star needs to be < 2.098883786377, meaning Y needs to be < 3.875766378407574e+19
return native_powr((1.12426773749357f * L_star / (2.098883786377f - L_star)), 1.5831518565279648f);
return dtcl_pow((1.12426773749357f * L_star / (2.098883786377f - L_star)), 1.5831518565279648f);
}

static inline void xyY_to_dt_UCS_UV(const float4 xyY, float UV_star_prime[2])
Expand Down Expand Up @@ -849,7 +849,7 @@ static inline float4 xyY_to_dt_UCS_JCH(const float4 xyY, const float L_white)
// should be JCH[0] = powf(L_star / L_white), cz) but we treat only the case where cz = 1
float4 JCH;
JCH.x = L_star / L_white;
JCH.y = 15.932993652962535f * native_powr(L_star, 0.6523997524738018f) * native_powr(M2, 0.6007557017508491f) / L_white;
JCH.y = 15.932993652962535f * dtcl_pow(L_star, 0.6523997524738018f) * dtcl_pow(M2, 0.6007557017508491f) / L_white;
JCH.z = atan2(UV_star_prime[1], UV_star_prime[0]);
return JCH;

Expand All @@ -875,7 +875,7 @@ static inline float4 dt_UCS_JCH_to_xyY(const float4 JCH, const float L_white)
const float DT_UCS_L_STAR_UPPER_LIMIT = 2.09885f;
const float L_star = clamp(JCH.x * L_white, 0.f, DT_UCS_L_STAR_UPPER_LIMIT);
const float M = L_star != 0.f
? native_powr(JCH.y * L_white / (15.932993652962535f * native_powr(L_star, 0.6523997524738018f)), 0.8322850678616855f)
? dtcl_pow(JCH.y * L_white / (15.932993652962535f * dtcl_pow(L_star, 0.6523997524738018f)), 0.8322850678616855f)
: 0.f;

const float U_star_prime = M * native_cos(JCH.z);
Expand Down Expand Up @@ -909,7 +909,7 @@ static inline float4 dt_UCS_JCH_to_xyY(const float4 JCH, const float L_white)
static inline float4 dt_UCS_JCH_to_HSB(const float4 JCH)
{
float4 HSB;
HSB.z = JCH.x * (native_powr(JCH.y, 1.33654221029386f) + 1.f);
HSB.z = JCH.x * (dtcl_pow(JCH.y, 1.33654221029386f) + 1.f);
HSB.y = (HSB.z > 0.f) ? JCH.y / HSB.z : 0.f;
HSB.x = JCH.z;
return HSB;
Expand All @@ -921,15 +921,15 @@ static inline float4 dt_UCS_HSB_to_JCH(const float4 HSB)
float4 JCH;
JCH.z = HSB.x;
JCH.y = HSB.y * HSB.z;
JCH.x = HSB.z / (native_powr(JCH.y, 1.33654221029386f) + 1.f);
JCH.x = HSB.z / (dtcl_pow(JCH.y, 1.33654221029386f) + 1.f);
return JCH;
}


static inline float4 dt_UCS_JCH_to_HCB(const float4 JCH)
{
float4 HCB;
HCB.z = JCH.x * (native_powr(JCH.y, 1.33654221029386f) + 1.f);
HCB.z = JCH.x * (dtcl_pow(JCH.y, 1.33654221029386f) + 1.f);
HCB.y = JCH.y;
HCB.x = JCH.z;
return HCB;
Expand All @@ -941,7 +941,7 @@ static inline float4 dt_UCS_HCB_to_JCH(const float4 HCB)
float4 JCH;
JCH.z = HCB.x;
JCH.y = HCB.y;
JCH.x = HCB.z / (native_powr(HCB.y, 1.33654221029386f) + 1.f);
JCH.x = HCB.z / (dtcl_pow(HCB.y, 1.33654221029386f) + 1.f);
return JCH;
}

Expand All @@ -956,7 +956,7 @@ static inline float4 dt_UCS_LUV_to_JCH(const float L_star, const float L_white,
{
const float M2 = UV_star_prime.x * UV_star_prime.x + UV_star_prime.y * UV_star_prime.y; // square of colorfulness M
const float4 JCH = { L_star / L_white,
15.932993652962535f * native_powr(L_star, 0.6523997524738018f) * native_powr(M2, 0.6007557017508491f) / L_white,
15.932993652962535f * dtcl_pow(L_star, 0.6523997524738018f) * dtcl_pow(M2, 0.6007557017508491f) / L_white,
atan2(UV_star_prime.y, UV_star_prime.x),
0.0f };
return JCH;
Expand Down
1 change: 1 addition & 0 deletions data/kernels/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ constant sampler_t samplerc = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP
// sampler for when the bound checks are already done manually
constant sampler_t samplerA = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST;

#define dtcl_pow(a,b) (pow(a,b))

#ifndef M_PI_F
#define M_PI_F 3.14159265358979323846 // should be defined by the OpenCL compiler acc. to standard
Expand Down
Loading