Skip to content

Commit e4e8ec9

Browse files
committed
agx: fixing NaNs; CL: clamp -> clipf, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, CL_INVALID_CONTEXT -> DT_OPENCL_PROCESS_CL
1 parent e4ccc62 commit e4e8ec9

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

data/kernels/agx.cl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ static inline void _agx_compress_into_gamut(float4 *pixel)
8080
float y_new = rgb_offset.x * luminance_coeffs[0] + rgb_offset.y * luminance_coeffs[1] + rgb_offset.z * luminance_coeffs[2];
8181
y_new = max_inverse_rgb_offset - y_inverse_rgb_offset + y_new;
8282

83-
const float luminance_ratio = (y_new > y_compensate_negative) ? y_compensate_negative / y_new : 1.0f;
83+
const float luminance_ratio =
84+
(y_new > y_compensate_negative && y_new > _epsilon)
85+
? y_compensate_negative / y_new
86+
: 1.f;
8487
*pixel = luminance_ratio * rgb_offset;
8588
}
8689

8790
static inline float _agx_apply_log_encoding(const float x, const float range_in_ev, const float min_ev)
8891
{
8992
const float x_relative = fmax(_epsilon, x / 0.18f);
9093
const float mapped = (log2(fmax(x_relative, 0.0f)) - min_ev) / range_in_ev;
91-
return clamp(mapped, 0.0f, 1.0f);
94+
return clipf(mapped);
9295
}
9396

9497
static inline float _agx_sigmoid(const float x, const float power)

src/iop/agx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,9 @@ static inline void _compress_into_gamut(dt_aligned_pixel_t pixel_in_out)
990990
+ rgb_offset[2] * luminance_coeffs[2];
991991
y_new = max_inverse_rgb_offset - y_inverse_rgb_offset + y_new;
992992

993-
// Compensate the intensity to match the original luminance
993+
// Compensate the intensity to match the original luminance; avoid div by 0 or tiny number
994994
const float luminance_ratio =
995-
y_new > y_compensate_negative
995+
(y_new > y_compensate_negative && y_new > _epsilon)
996996
? y_compensate_negative / y_new
997997
: 1.f;
998998

@@ -1119,7 +1119,7 @@ static tone_mapping_params_t _calculate_tone_mapping_params(const dt_iop_agx_par
11191119
// toe
11201120
tone_mapping_params.target_black =
11211121
powf(p->curve_target_display_black_ratio, 1.f / tone_mapping_params.curve_gamma);
1122-
tone_mapping_params.toe_power = p->curve_toe_power;
1122+
tone_mapping_params.toe_power = fmaxf(0.01f, p->curve_toe_power);
11231123

11241124
const float remaining_y_below_pivot = tone_mapping_params.pivot_y - tone_mapping_params.target_black;
11251125
const float toe_length_y = remaining_y_below_pivot * p->curve_linear_ratio_below_pivot;
@@ -1181,7 +1181,7 @@ static tone_mapping_params_t _calculate_tone_mapping_params(const dt_iop_agx_par
11811181

11821182
const float shoulder_dy_above_pivot = tone_mapping_params.slope * dx_linear_above_pivot;
11831183
tone_mapping_params.shoulder_transition_y = tone_mapping_params.pivot_y + shoulder_dy_above_pivot;
1184-
tone_mapping_params.shoulder_power = p->curve_shoulder_power;
1184+
tone_mapping_params.shoulder_power = fmaxf(0.01f, p->curve_shoulder_power);
11851185

11861186
const float shoulder_limit_x = 1.f;
11871187
tone_mapping_params.shoulder_scale = _scale(shoulder_limit_x,
@@ -2885,7 +2885,7 @@ int process_cl(dt_iop_module_t *self,
28852885
{
28862886
if(!dt_iop_have_required_input_format(4, self, piece->colors, (void*)dev_in, (void*)dev_out, roi_in, roi_out))
28872887
{
2888-
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
2888+
return DT_OPENCL_PROCESS_CL;
28892889
}
28902890

28912891
const dt_iop_agx_global_data_t *gd = self->global_data;
@@ -2906,7 +2906,7 @@ int process_cl(dt_iop_module_t *self,
29062906
{
29072907
dt_print(DT_DEBUG_ALWAYS,
29082908
"[agx process_cl] Failed to obtain a valid base profile. Module will not run correctly.");
2909-
return CL_INVALID_CONTEXT;
2909+
return DT_OPENCL_PROCESS_CL;
29102910
}
29112911

29122912
dt_colormatrix_t pipe_to_base;

0 commit comments

Comments
 (0)