11/*
22 This file is part of darktable,
3- Copyright (C) 2011-2024 darktable developers.
3+ Copyright (C) 2011-2025 darktable developers.
44
55 darktable is free software: you can redistribute it and/or modify
66 it under the terms of the GNU General Public License as published by
1515 You should have received a copy of the GNU General Public License
1616 along with darktable. If not, see <http://www.gnu.org/licenses/>.
1717*/
18+
1819#include <assert.h>
1920#include <math.h>
2021#include <stdlib.h>
@@ -103,14 +104,20 @@ const char **description(dt_iop_module_t *self)
103104 _ ("linear, RGB, display-referred" ));
104105}
105106
106- void process (dt_iop_module_t * self , dt_dev_pixelpipe_iop_t * piece , const void * const ivoid ,
107- void * const ovoid , const dt_iop_roi_t * const roi_in , const dt_iop_roi_t * const roi_out )
107+ void process (dt_iop_module_t * self ,
108+ dt_dev_pixelpipe_iop_t * piece ,
109+ const void * const ivoid ,
110+ void * const ovoid ,
111+ const dt_iop_roi_t * const roi_in ,
112+ const dt_iop_roi_t * const roi_out )
108113{
109114 const dt_iop_soften_data_t * const d = (const dt_iop_soften_data_t * const )piece -> data ;
110115
111- if (!dt_iop_have_required_input_format (4 /*we need full-color pixels*/ , self , piece -> colors ,
116+ if (!dt_iop_have_required_input_format (4 /*we need full-color pixels*/ ,
117+ self , piece -> colors ,
112118 ivoid , ovoid , roi_in , roi_out ))
113- return ; // image has been copied through to output and module's trouble flag has been updated
119+ return ; // image has been copied through to output and module's
120+ // trouble flag has been updated
114121
115122 const float brightness = 1.0 / exp2f (- d -> brightness );
116123 const float saturation = d -> saturation / 100.0 ;
@@ -119,7 +126,7 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
119126 float * const restrict out = (float * const )ovoid ;
120127
121128 const size_t npixels = (size_t )roi_out -> width * roi_out -> height ;
122- /* create overexpose image and then blur */
129+ /* create overexpose image and then blur */
123130 DT_OMP_FOR ()
124131 for (size_t k = 0 ; k < 4 * npixels ; k += 4 )
125132 {
@@ -172,7 +179,8 @@ int process_cl(dt_iop_module_t *self,
172179 const int rad = mrad * (fmin (100.0f , d -> size + 1.0f ) / 100.0f );
173180 const int radius = MIN (mrad , ceilf (rad * roi_in -> scale / piece -> iscale ));
174181
175- /* sigma-radius correlation to match opencl vs. non-opencl. identified by numerical experiments but
182+ /* sigma-radius correlation to match opencl
183+ * vs. non-opencl. identified by numerical experiments but
176184 * unproven. ask me if you need details. ulrich */
177185 const float sigma = sqrtf ((radius * (radius + 1 ) * BOX_ITERATIONS + 2 ) / 3.0f );
178186 const int wdh = ceilf (3.0f * sigma );
@@ -183,17 +191,24 @@ int process_cl(dt_iop_module_t *self,
183191 float weight = 0.0f ;
184192
185193 // init gaussian kernel
186- for (int l = - wdh ; l <= wdh ; l ++ ) weight += m [l ] = expf (- (l * l ) / (2.f * sigma * sigma ));
187- for (int l = - wdh ; l <= wdh ; l ++ ) m [l ] /= weight ;
194+ for (int l = - wdh ; l <= wdh ; l ++ )
195+ weight += m [l ] = expf (- (l * l ) / (2.f * sigma * sigma ));
196+ for (int l = - wdh ; l <= wdh ; l ++ )
197+ m [l ] /= weight ;
188198
189199 // for(int l=-wdh; l<=wdh; l++) printf("%.6f ", (double)m[l]);
190200 // printf("\n");
191201
192202 int hblocksize ;
193203 dt_opencl_local_buffer_t hlocopt
194- = (dt_opencl_local_buffer_t ){ .xoffset = 2 * wdh , .xfactor = 1 , .yoffset = 0 , .yfactor = 1 ,
195- .cellsize = 4 * sizeof (float ), .overhead = 0 ,
196- .sizex = 1 << 16 , .sizey = 1 };
204+ = (dt_opencl_local_buffer_t ){ .xoffset = 2 * wdh ,
205+ .xfactor = 1 ,
206+ .yoffset = 0 ,
207+ .yfactor = 1 ,
208+ .cellsize = 4 * sizeof (float ),
209+ .overhead = 0 ,
210+ .sizex = 1 << 16 ,
211+ .sizey = 1 };
197212
198213 if (dt_opencl_local_buffer_opt (devid , gd -> kernel_soften_hblur , & hlocopt ))
199214 hblocksize = hlocopt .sizex ;
@@ -202,9 +217,14 @@ int process_cl(dt_iop_module_t *self,
202217
203218 int vblocksize ;
204219 dt_opencl_local_buffer_t vlocopt
205- = (dt_opencl_local_buffer_t ){ .xoffset = 1 , .xfactor = 1 , .yoffset = 2 * wdh , .yfactor = 1 ,
206- .cellsize = 4 * sizeof (float ), .overhead = 0 ,
207- .sizex = 1 , .sizey = 1 << 16 };
220+ = (dt_opencl_local_buffer_t ){ .xoffset = 1 ,
221+ .xfactor = 1 ,
222+ .yoffset = 2 * wdh ,
223+ .yfactor = 1 ,
224+ .cellsize = 4 * sizeof (float ),
225+ .overhead = 0 ,
226+ .sizex = 1 ,
227+ .sizey = 1 << 16 };
208228
209229 if (dt_opencl_local_buffer_opt (devid , gd -> kernel_soften_vblur , & vlocopt ))
210230 vblocksize = vlocopt .sizey ;
@@ -225,7 +245,8 @@ int process_cl(dt_iop_module_t *self,
225245 dev_m = dt_opencl_copy_host_to_device_constant (devid , mat_size , mat );
226246 if (dev_m == NULL ) goto error ;
227247
228- err = dt_opencl_enqueue_kernel_2d_args (devid , gd -> kernel_soften_overexposed , width , height ,
248+ err = dt_opencl_enqueue_kernel_2d_args (devid , gd -> kernel_soften_overexposed ,
249+ width , height ,
229250 CLARG (dev_in ), CLARG (dev_tmp ),
230251 CLARG (width ), CLARG (height ), CLARG (saturation ), CLARG (brightness ));
231252 if (err != CL_SUCCESS ) goto error ;
@@ -239,9 +260,12 @@ int process_cl(dt_iop_module_t *self,
239260 local [0 ] = hblocksize ;
240261 local [1 ] = 1 ;
241262 local [2 ] = 1 ;
242- dt_opencl_set_kernel_args (devid , gd -> kernel_soften_hblur , 0 , CLARG (dev_tmp ), CLARG (dev_out ), CLARG (dev_m ),
243- CLARG (wdh ), CLARG (width ), CLARG (height ), CLARG (hblocksize ), CLLOCAL ((hblocksize + 2 * wdh ) * 4 * sizeof (float )));
244- err = dt_opencl_enqueue_kernel_2d_with_local (devid , gd -> kernel_soften_hblur , sizes , local );
263+ dt_opencl_set_kernel_args (devid , gd -> kernel_soften_hblur , 0 ,
264+ CLARG (dev_tmp ), CLARG (dev_out ), CLARG (dev_m ),
265+ CLARG (wdh ), CLARG (width ), CLARG (height ), CLARG (hblocksize ),
266+ CLLOCAL ((hblocksize + 2 * wdh ) * 4 * sizeof (float )));
267+ err = dt_opencl_enqueue_kernel_2d_with_local (devid , gd -> kernel_soften_hblur ,
268+ sizes , local );
245269 if (err != CL_SUCCESS ) goto error ;
246270
247271
@@ -285,7 +309,8 @@ void tiling_callback(dt_iop_module_t *self,
285309 const int rad = mrad * (fmin (100.0f , d -> size + 1.0f ) / 100.0f );
286310 const int radius = MIN (mrad , ceilf (rad * roi_in -> scale / piece -> iscale ));
287311
288- /* sigma-radius correlation to match opencl vs. non-opencl. identified by numerical experiments but
312+ /* sigma-radius correlation to match opencl
313+ * vs. non-opencl. identified by numerical experiments but
289314 * unproven. ask me if you need details. ulrich */
290315 const float sigma = sqrtf ((radius * (radius + 1 ) * BOX_ITERATIONS + 2 ) / 3.0f );
291316 const int wdh = ceilf (3.0f * sigma );
@@ -322,7 +347,9 @@ void cleanup_global(dt_iop_module_so_t *self)
322347 self -> data = NULL ;
323348}
324349
325- void commit_params (dt_iop_module_t * self , dt_iop_params_t * p1 , dt_dev_pixelpipe_t * pipe ,
350+ void commit_params (dt_iop_module_t * self ,
351+ dt_iop_params_t * p1 ,
352+ dt_dev_pixelpipe_t * pipe ,
326353 dt_dev_pixelpipe_iop_t * piece )
327354{
328355 dt_iop_soften_params_t * p = (dt_iop_soften_params_t * )p1 ;
@@ -334,12 +361,16 @@ void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_
334361 d -> amount = p -> amount ;
335362}
336363
337- void init_pipe (dt_iop_module_t * self , dt_dev_pixelpipe_t * pipe , dt_dev_pixelpipe_iop_t * piece )
364+ void init_pipe (dt_iop_module_t * self ,
365+ dt_dev_pixelpipe_t * pipe ,
366+ dt_dev_pixelpipe_iop_t * piece )
338367{
339368 piece -> data = calloc (1 , sizeof (dt_iop_soften_data_t ));
340369}
341370
342- void cleanup_pipe (dt_iop_module_t * self , dt_dev_pixelpipe_t * pipe , dt_dev_pixelpipe_iop_t * piece )
371+ void cleanup_pipe (dt_iop_module_t * self ,
372+ dt_dev_pixelpipe_t * pipe ,
373+ dt_dev_pixelpipe_iop_t * piece )
343374{
344375 free (piece -> data );
345376 piece -> data = NULL ;
0 commit comments