Skip to content

Commit f9ff0b9

Browse files
committed
agx: Mitigate input NaNs, restrict input RGB components to reasonable values (-1e6, 1e6)
1 parent e4e8ec9 commit f9ff0b9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

data/kernels/agx.cl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ __kernel void kernel_agx(
233233
const int2 pos = (int2)(i, j);
234234
float4 in_pixel = read_imagef(input, sampleri, pos);
235235

236+
// sanitize input range and get rid of NaNs
237+
in_pixel = select(clamp(in_pixel, -1e6f, 1e6f), (float4)(0.0f), isnan(in_pixel));
238+
236239
float4 base_rgb;
237240
if(base_working_same_profile)
238241
{

src/iop/agx.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,17 +1581,24 @@ void process(dt_iop_module_t *self,
15811581
for(size_t k = 0; k < 4 * n_pixels; k += 4)
15821582
{
15831583
const float *const restrict pix_in = in + k;
1584+
dt_aligned_pixel_t sanitised_in = { 0.f };
1585+
for_each_channel(c)
1586+
{
1587+
const float component = pix_in[c];
1588+
// allow about 22.5 EV above mid-grey, including out-of-gamut pixels, getting rid of NaNs
1589+
sanitised_in[c] = isnan(component) ? 0.f : CLAMPF(component, -1e6f, 1e6f);
1590+
}
15841591
float *const restrict pix_out = out + k;
15851592

15861593
// Convert from pipe working space to base space
15871594
dt_aligned_pixel_t base_rgb = { 0.f };
15881595
if(base_working_same_profile)
15891596
{
1590-
copy_pixel(base_rgb, pix_in);
1597+
copy_pixel(base_rgb, sanitised_in);
15911598
}
15921599
else
15931600
{
1594-
dt_apply_transposed_color_matrix(pix_in, pipe_to_base_transposed, base_rgb);
1601+
dt_apply_transposed_color_matrix(sanitised_in, pipe_to_base_transposed, base_rgb);
15951602
}
15961603

15971604
_compress_into_gamut(base_rgb);
@@ -1607,7 +1614,7 @@ void process(dt_iop_module_t *self,
16071614
dt_apply_transposed_color_matrix(rendering_rgb, rendering_to_pipe_transposed, pix_out);
16081615

16091616
// Copy over the alpha channel
1610-
pix_out[3] = pix_in[3];
1617+
pix_out[3] = sanitised_in[3];
16111618
}
16121619
}
16131620

0 commit comments

Comments
 (0)