Skip to content
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
12 changes: 6 additions & 6 deletions data/kernels/basic.cl
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ colorin_clipping (read_only image2d_t in, write_only image2d_t out, const int wi
}

// clamp at this stage
for(int i=0; i<3; i++) RGB[i] = clamp(RGB[i], 0.0f, 1.0f);
for(int i=0; i<3; i++) RGB[i] = clipf(RGB[i]);

// convert clipped RGB to XYZ
for(int j=0;j<3;j++)
Expand Down Expand Up @@ -3128,7 +3128,7 @@ flip(read_only image2d_t in,
float
envelope(const float L)
{
const float x = clamp(L/100.0f, 0.0f, 1.0f);
const float x = clipf(L/100.0f);
// const float alpha = 2.0f;
const float beta = 0.6f;
if(x < beta)
Expand Down Expand Up @@ -3163,7 +3163,7 @@ monochrome_filter(read_only image2d_t in,

float4 pixel = read_imagef (in, sampleri, (int2)(x, y));
// TODO: this could be a native_expf, or exp2f, need to evaluate comparisons with cpu though:
pixel.x = 100.0f*dt_fast_expf(-clamp(((pixel.y - a)*(pixel.y - a) + (pixel.z - b)*(pixel.z - b))/(2.0f * size), 0.0f, 1.0f));
pixel.x = 100.0f*dt_fast_expf(-clipf((pixel.y - a)*(pixel.y - a) + (pixel.z - b)*(pixel.z - b))/(2.0f * size));
write_imagef (out, (int2)(x, y), pixel);
}

Expand All @@ -3185,7 +3185,7 @@ monochrome(read_only image2d_t in,

float4 pixel = read_imagef (in, sampleri, (int2)(x, y));
float4 basep = read_imagef (base, sampleri, (int2)(x, y));
float filter = dt_fast_expf(-clamp(((pixel.y - a)*(pixel.y - a) + (pixel.z - b)*(pixel.z - b))/(2.0f * size), 0.0f, 1.0f));
float filter = dt_fast_expf(-clipf(((pixel.y - a)*(pixel.y - a) + (pixel.z - b)*(pixel.z - b))/(2.0f * size)));
float tt = envelope(pixel.x);
float t = tt + (1.0f-tt)*(1.0f-highlights);
pixel.x = mix(pixel.x, pixel.x*basep.x/100.0f, t);
Expand Down Expand Up @@ -3378,7 +3378,7 @@ colorzones (read_only image2d_t in,
select = LCh.z;
break;
}
select = clamp(select, 0.f, 1.f);
select = clipf(select);

LCh.x *= dtcl_pow(2.0f, 4.0f * (lookup(table_L, select) - .5f));
LCh.y *= 2.f * lookup(table_C, select);
Expand Down Expand Up @@ -3705,7 +3705,7 @@ lowlight (read_only image2d_t in,
}

// scale using empiric coefficient and fit inside limits
V = clamp(c*V, 0.0f, 1.0f);
V = clipf(c*V);

// blending coefficient from curve
w = lookup(lut, pixel.x/100.0f);
Expand Down
75 changes: 37 additions & 38 deletions data/kernels/blendop.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
copyright (c) 2011--2013 ulrich pegelow.
Copyright (C) 2011-2025 darktable developers.

darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -279,13 +279,13 @@ blendif_factor_rgb_hsl(const float4 input, const float4 output,
float4 HSL_input = RGB_2_HSL(input);
float4 HSL_output = RGB_2_HSL(output);

scaled[DEVELOP_BLENDIF_H_in] = clamp(HSL_input.x, 0.0f, 1.0f); // H scaled to 0..1
scaled[DEVELOP_BLENDIF_S_in] = clamp(HSL_input.y, 0.0f, 1.0f); // S scaled to 0..1
scaled[DEVELOP_BLENDIF_l_in] = clamp(HSL_input.z, 0.0f, 1.0f); // L scaled to 0..1
scaled[DEVELOP_BLENDIF_H_in] = clipf(HSL_input.x); // H scaled to 0..1
scaled[DEVELOP_BLENDIF_S_in] = clipf(HSL_input.y); // S scaled to 0..1
scaled[DEVELOP_BLENDIF_l_in] = clipf(HSL_input.z); // L scaled to 0..1

scaled[DEVELOP_BLENDIF_H_out] = clamp(HSL_output.x, 0.0f, 1.0f); // H scaled to 0..1
scaled[DEVELOP_BLENDIF_S_out] = clamp(HSL_output.y, 0.0f, 1.0f); // S scaled to 0..1
scaled[DEVELOP_BLENDIF_l_out] = clamp(HSL_output.z, 0.0f, 1.0f); // L scaled to 0..1
scaled[DEVELOP_BLENDIF_H_out] = clipf(HSL_output.x); // H scaled to 0..1
scaled[DEVELOP_BLENDIF_S_out] = clipf(HSL_output.y); // S scaled to 0..1
scaled[DEVELOP_BLENDIF_l_out] = clipf(HSL_output.z); // L scaled to 0..1
}

const unsigned int invert_mask = (blendif >> 16) ^ ((mask_combine & DEVELOP_COMBINE_INCL) ? DEVELOP_BLENDIF_RGB_MASK : 0);
Expand Down Expand Up @@ -1449,8 +1449,7 @@ blendop_mask_tone_curve(__read_only image2d_t mask_in, __write_only image2d_t ma
scaled_opacity = (scaled_opacity + brightness) / (1.f + brightness);
scaled_opacity = fmax(scaled_opacity, -1.f);
}
opacity = clamp(
((scaled_opacity * e / (1.f + (e - 1.f) * fabs(scaled_opacity))) / 2.f + 0.5f) * gopacity, 0.f, 1.f);
opacity = clipf(((scaled_opacity * e / (1.f + (e - 1.f) * fabs(scaled_opacity))) / 2.f + 0.5f) * gopacity);
write_imagef(mask_out, (int2)(x, y), opacity);
}

Expand Down Expand Up @@ -1496,102 +1495,102 @@ blendop_display_channel(__read_only image2d_t in_a, __read_only image2d_t in_b,
switch(channel & DT_DEV_PIXELPIPE_DISPLAY_ANY)
{
case DT_DEV_PIXELPIPE_DISPLAY_L:
c = clamp(a.x / 100.0f / exp2(boost_factors[DEVELOP_BLENDIF_L_in]), 0.0f, 1.0f);
c = clipf(a.x / 100.0f / exp2(boost_factors[DEVELOP_BLENDIF_L_in]));
is_lab = 1;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_L | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
c = clamp(b.x / 100.0f / exp2(boost_factors[DEVELOP_BLENDIF_L_out]), 0.0f, 1.0f);
c = clipf(b.x / 100.0f / exp2(boost_factors[DEVELOP_BLENDIF_L_out]));
is_lab = 1;
break;
case DT_DEV_PIXELPIPE_DISPLAY_a:
c = clamp(a.y / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_A_in]) + 0.5f, 0.0f, 1.0f);
c = clipf(a.y / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_A_in]) + 0.5f);
is_lab = 1;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_a | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
c = clamp(b.y / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_A_out]) + 0.5f, 0.0f, 1.0f);
c = clipf(b.y / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_A_out]) + 0.5f);
is_lab = 1;
break;
case DT_DEV_PIXELPIPE_DISPLAY_b:
c = clamp(a.z / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_B_in]) + 0.5f, 0.0f, 1.0f);
c = clipf(a.z / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_B_in]) + 0.5f);
is_lab = 1;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_b | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
c = clamp(b.z / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_A_in]) + 0.5f, 0.0f, 1.0f);
c = clipf(b.z / 256.0f / exp2(boost_factors[DEVELOP_BLENDIF_A_in]) + 0.5f);
is_lab = 1;
break;
case DT_DEV_PIXELPIPE_DISPLAY_R:
c = clamp(a.x / exp2(boost_factors[DEVELOP_BLENDIF_RED_in]), 0.0f, 1.0f);
c = clipf(a.x / exp2(boost_factors[DEVELOP_BLENDIF_RED_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_R | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
c = clamp(b.x / exp2(boost_factors[DEVELOP_BLENDIF_RED_out]), 0.0f, 1.0f);
c = clipf(b.x / exp2(boost_factors[DEVELOP_BLENDIF_RED_out]));
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_G:
c = clamp(a.y / exp2(boost_factors[DEVELOP_BLENDIF_GREEN_in]), 0.0f, 1.0f);
c = clipf(a.y / exp2(boost_factors[DEVELOP_BLENDIF_GREEN_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_G | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
c = clamp(b.y / exp2(boost_factors[DEVELOP_BLENDIF_GREEN_out]), 0.0f, 1.0f);
c = clipf(b.y / exp2(boost_factors[DEVELOP_BLENDIF_GREEN_out]));
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_B:
c = clamp(a.z / exp2(boost_factors[DEVELOP_BLENDIF_BLUE_in]), 0.0f, 1.0f);
c = clipf(a.z / exp2(boost_factors[DEVELOP_BLENDIF_BLUE_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_B | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
c = clamp(b.z / exp2(boost_factors[DEVELOP_BLENDIF_BLUE_out]), 0.0f, 1.0f);
c = clipf(b.z / exp2(boost_factors[DEVELOP_BLENDIF_BLUE_out]));
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_GRAY:
if(use_profile == 0)
c = 0.3f * a.x + 0.59f * a.y + 0.11f * a.z;
else
c = get_rgb_matrix_luminance(a, profile_info, profile_info->matrix_in, profile_lut);
c = clamp(c / exp2(boost_factors[DEVELOP_BLENDIF_GRAY_in]), 0.0f, 1.0f);
c = clipf(c / exp2(boost_factors[DEVELOP_BLENDIF_GRAY_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_GRAY | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
if(use_profile == 0)
c = 0.3f * b.x + 0.59f * b.y + 0.11f * b.z;
else
c = get_rgb_matrix_luminance(b, profile_info, profile_info->matrix_in, profile_lut);
c = clamp(c / exp2(boost_factors[DEVELOP_BLENDIF_GRAY_out]), 0.0f, 1.0f);
c = clipf(c / exp2(boost_factors[DEVELOP_BLENDIF_GRAY_out]));
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_LCH_C:
LCH = Lab_2_LCH(a);
c = clamp(LCH.y / (128.0f * sqrt(2.0f) / exp2(boost_factors[DEVELOP_BLENDIF_C_in])), 0.0f, 1.0f);
c = clipf(LCH.y / (128.0f * sqrt(2.0f) / exp2(boost_factors[DEVELOP_BLENDIF_C_in])));
is_lab = 1;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_LCH_C | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
LCH = Lab_2_LCH(b);
c = clamp(LCH.y / (128.0f * sqrt(2.0f)) / exp2(boost_factors[DEVELOP_BLENDIF_C_out]), 0.0f, 1.0f);
c = clipf(LCH.y / (128.0f * sqrt(2.0f)) / exp2(boost_factors[DEVELOP_BLENDIF_C_out]));
is_lab = 1;
break;
case DT_DEV_PIXELPIPE_DISPLAY_LCH_h:
LCH = Lab_2_LCH(a);
c = clamp(LCH.z, 0.0f, 1.0f); // no boost for hues
c = clipf(LCH.z); // no boost for hues
is_lab = 1;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_LCH_h | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
LCH = Lab_2_LCH(b);
c = clamp(LCH.z, 0.0f, 1.0f); // no boost for hues
c = clipf(LCH.z); // no boost for hues
is_lab = 1;
break;
case DT_DEV_PIXELPIPE_DISPLAY_HSL_H:
HSL = RGB_2_HSL(a);
c = clamp(HSL.x, 0.0f, 1.0f); // no boost for hues
c = clipf(HSL.x); // no boost for hues
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_HSL_H | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
HSL = RGB_2_HSL(b);
c = clamp(HSL.x, 0.0f, 1.0f); // no boost for hues
c = clipf(HSL.x); // no boost for hues
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_HSL_S:
HSL = RGB_2_HSL(a);
c = clamp(HSL.y, 0.0f, 1.0f); // no boost for HSL
c = clipf(HSL.y); // no boost for HSL
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_HSL_S | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
Expand All @@ -1601,42 +1600,42 @@ blendop_display_channel(__read_only image2d_t in_a, __read_only image2d_t in_b,
break;
case DT_DEV_PIXELPIPE_DISPLAY_HSL_l:
HSL = RGB_2_HSL(a);
c = clamp(HSL.z, 0.0f, 1.0f); // no boost for HSL
c = clipf(HSL.z); // no boost for HSL
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_HSL_l | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
HSL = RGB_2_HSL(b);
c = clamp(HSL.z, 0.0f, 1.0f); // no boost for HSL
c = clipf(HSL.z); // no boost for HSL
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_JzCzhz_Jz:
JzCzhz = rgb_to_JzCzhz(a, profile_info, profile_lut, use_profile);
c = clamp(JzCzhz.x / exp2(boost_factors[DEVELOP_BLENDIF_Jz_in]), 0.0f, 1.0f);
c = clipf(JzCzhz.x / exp2(boost_factors[DEVELOP_BLENDIF_Jz_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_JzCzhz_Jz | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
JzCzhz = rgb_to_JzCzhz(b, profile_info, profile_lut, use_profile);
c = clamp(JzCzhz.x / exp2(boost_factors[DEVELOP_BLENDIF_Jz_out]), 0.0f, 1.0f);
c = clipf(JzCzhz.x / exp2(boost_factors[DEVELOP_BLENDIF_Jz_out]));
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_JzCzhz_Cz:
JzCzhz = rgb_to_JzCzhz(a, profile_info, profile_lut, use_profile);
c = clamp(JzCzhz.y / exp2(boost_factors[DEVELOP_BLENDIF_Cz_in]), 0.0f, 1.0f);
c = clipf(JzCzhz.y / exp2(boost_factors[DEVELOP_BLENDIF_Cz_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_JzCzhz_Cz | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
JzCzhz = rgb_to_JzCzhz(b, profile_info, profile_lut, use_profile);
c = clamp(JzCzhz.y / exp2(boost_factors[DEVELOP_BLENDIF_Cz_out]), 0.0f, 1.0f);
c = clipf(JzCzhz.y / exp2(boost_factors[DEVELOP_BLENDIF_Cz_out]));
is_lab = 0;
break;
case DT_DEV_PIXELPIPE_DISPLAY_JzCzhz_hz:
JzCzhz = rgb_to_JzCzhz(a, profile_info, profile_lut, use_profile);
c = clamp(JzCzhz.z / exp2(boost_factors[DEVELOP_BLENDIF_hz_in]), 0.0f, 1.0f);
c = clipf(JzCzhz.z / exp2(boost_factors[DEVELOP_BLENDIF_hz_in]));
is_lab = 0;
break;
case (DT_DEV_PIXELPIPE_DISPLAY_JzCzhz_hz | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT):
JzCzhz = rgb_to_JzCzhz(b, profile_info, profile_lut, use_profile);
c = clamp(JzCzhz.z / exp2(boost_factors[DEVELOP_BLENDIF_hz_out]), 0.0f, 1.0f);
c = clipf(JzCzhz.z / exp2(boost_factors[DEVELOP_BLENDIF_hz_out]));
is_lab = 0;
break;
default:
Expand Down
Loading
Loading