15
15
You should have received a copy of the GNU General Public License
16
16
along with darktable. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
+
18
19
#include "bauhaus/bauhaus.h"
19
20
#include "common/colorspaces.h"
20
21
#include "common/darktable.h"
@@ -84,8 +85,12 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
84
85
return IOP_CS_RGB ;
85
86
}
86
87
87
- void process (dt_iop_module_t * self , dt_dev_pixelpipe_iop_t * piece , const void * const ivoid ,
88
- void * const ovoid , const dt_iop_roi_t * const roi_in , const dt_iop_roi_t * const roi_out )
88
+ void process (dt_iop_module_t * self ,
89
+ dt_dev_pixelpipe_iop_t * piece ,
90
+ const void * const ivoid ,
91
+ void * const ovoid ,
92
+ const dt_iop_roi_t * const roi_in ,
93
+ const dt_iop_roi_t * const roi_out )
89
94
{
90
95
dt_iop_rlce_data_t * data = piece -> data ;
91
96
const int ch = piece -> colors ;
@@ -100,8 +105,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
100
105
float * lm = luminance + (size_t )j * roi_out -> width ;
101
106
for (int i = 0 ; i < roi_out -> width ; i ++ )
102
107
{
103
- float pmax = CLIP (max3f (in )); // Max value in RGB set
104
- float pmin = CLIP (min3f (in )); // Min value in RGB set
108
+ const float pmax = CLIP (max3f (in )); // Max value in RGB set
109
+ const float pmin = CLIP (min3f (in )); // Min value in RGB set
105
110
* lm = (pmax + pmin ) / 2.f ; // Pixel luminosity
106
111
in += ch ;
107
112
lm ++ ;
@@ -123,12 +128,12 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
123
128
DT_OMP_FOR ()
124
129
for (int j = 0 ; j < roi_out -> height ; j ++ )
125
130
{
126
- int yMin = fmax (0 , j - rad );
127
- int yMax = fmin (roi_in -> height , j + rad + 1 );
128
- int h = yMax - yMin ;
131
+ const int yMin = fmax (0 , j - rad );
132
+ const int yMax = fmin (roi_in -> height , j + rad + 1 );
133
+ const int h = yMax - yMin ;
129
134
130
- int xMin0 = fmax (0 , 0 - rad );
131
- int xMax0 = fmin (roi_in -> width - 1 , rad );
135
+ const int xMin0 = fmax (0 , 0 - rad );
136
+ const int xMax0 = fmin (roi_in -> width - 1 , rad );
132
137
133
138
int hist [BINS + 1 ];
134
139
int clippedhist [BINS + 1 ];
@@ -150,27 +155,29 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
150
155
151
156
int v = ROUND_POSISTIVE (luminance [(size_t )j * roi_in -> width + i ] * (float )BINS );
152
157
153
- int xMin = fmax (0 , i - rad );
154
- int xMax = i + rad + 1 ;
155
- int w = fmin (roi_in -> width , xMax ) - xMin ;
156
- int n = h * w ;
158
+ const int xMin = fmax (0 , i - rad );
159
+ const int xMax = i + rad + 1 ;
160
+ const int w = fmin (roi_in -> width , xMax ) - xMin ;
161
+ const int n = h * w ;
157
162
158
- int limit = (int )(slope * n / BINS + 0.5f );
163
+ const int limit = (int )(slope * n / BINS + 0.5f );
159
164
160
165
/* remove left behind values from histogram */
161
166
if (xMin > 0 )
162
167
{
163
- int xMin1 = xMin - 1 ;
168
+ const int xMin1 = xMin - 1 ;
164
169
for (int yi = yMin ; yi < yMax ; ++ yi )
165
- -- hist [ROUND_POSISTIVE (luminance [(size_t )yi * roi_in -> width + xMin1 ] * (float )BINS )];
170
+ -- hist [ROUND_POSISTIVE
171
+ (luminance [(size_t )yi * roi_in -> width + xMin1 ] * (float )BINS )];
166
172
}
167
173
168
174
/* add newly included values to histogram */
169
175
if (xMax <= roi_in -> width )
170
176
{
171
- int xMax1 = xMax - 1 ;
177
+ const int xMax1 = xMax - 1 ;
172
178
for (int yi = yMin ; yi < yMax ; ++ yi )
173
- ++ hist [ROUND_POSISTIVE (luminance [(size_t )yi * roi_in -> width + xMax1 ] * (float )BINS )];
179
+ ++ hist [ROUND_POSISTIVE
180
+ (luminance [(size_t )yi * roi_in -> width + xMax1 ] * (float )BINS )];
174
181
}
175
182
176
183
/* clip histogram and redistribute clipped entries */
@@ -182,21 +189,21 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
182
189
ce = 0 ;
183
190
for (int b = 0 ; b <= BINS ; b ++ )
184
191
{
185
- int d = clippedhist [b ] - limit ;
192
+ const int d = clippedhist [b ] - limit ;
186
193
if (d > 0 )
187
194
{
188
195
ce += d ;
189
196
clippedhist [b ] = limit ;
190
197
}
191
198
}
192
199
193
- int d = (ce / (float )(BINS + 1 ));
194
- int m = ce % (BINS + 1 );
200
+ const int d = (ce / (float )(BINS + 1 ));
201
+ const int m = ce % (BINS + 1 );
195
202
for (int b = 0 ; b <= BINS ; b ++ ) clippedhist [b ] += d ;
196
203
197
204
if (m != 0 )
198
205
{
199
- int s = BINS / (float )m ;
206
+ const int s = BINS / (float )m ;
200
207
for (int b = 0 ; b <= BINS ; b += s ) ++ clippedhist [b ];
201
208
}
202
209
} while (ce != ceb );
@@ -207,12 +214,14 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
207
214
if (clippedhist [b ] != 0 ) hMin = b ;
208
215
209
216
int cdf = 0 ;
210
- for (int b = hMin ; b <= v ; b ++ ) cdf += clippedhist [b ];
217
+ for (int b = hMin ; b <= v ; b ++ )
218
+ cdf += clippedhist [b ];
211
219
212
220
int cdfMax = cdf ;
213
- for (int b = v + 1 ; b <= BINS ; b ++ ) cdfMax += clippedhist [b ];
221
+ for (int b = v + 1 ; b <= BINS ; b ++ )
222
+ cdfMax += clippedhist [b ];
214
223
215
- int cdfMin = clippedhist [hMin ];
224
+ const int cdfMin = clippedhist [hMin ];
216
225
217
226
* ld = (cdf - cdfMin ) / (float )(cdfMax - cdfMin );
218
227
@@ -242,15 +251,17 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
242
251
#undef BINS
243
252
}
244
253
245
- static void radius_callback (GtkWidget * slider , dt_iop_module_t * self )
254
+ static void radius_callback (GtkWidget * slider ,
255
+ dt_iop_module_t * self )
246
256
{
247
257
if (darktable .gui -> reset ) return ;
248
258
dt_iop_rlce_params_t * p = self -> params ;
249
259
p -> radius = dt_bauhaus_slider_get (slider );
250
260
dt_dev_add_history_item (darktable .develop , self , TRUE);
251
261
}
252
262
253
- static void slope_callback (GtkWidget * slider , dt_iop_module_t * self )
263
+ static void slope_callback (GtkWidget * slider ,
264
+ dt_iop_module_t * self )
254
265
{
255
266
if (darktable .gui -> reset ) return ;
256
267
dt_iop_rlce_params_t * p = self -> params ;
@@ -260,7 +271,9 @@ static void slope_callback(GtkWidget *slider, dt_iop_module_t *self)
260
271
261
272
262
273
263
- void commit_params (dt_iop_module_t * self , dt_iop_params_t * p1 , dt_dev_pixelpipe_t * pipe ,
274
+ void commit_params (dt_iop_module_t * self ,
275
+ dt_iop_params_t * p1 ,
276
+ dt_dev_pixelpipe_t * pipe ,
264
277
dt_dev_pixelpipe_iop_t * piece )
265
278
{
266
279
dt_iop_rlce_params_t * p = (dt_iop_rlce_params_t * )p1 ;
@@ -270,12 +283,16 @@ void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_
270
283
d -> slope = p -> slope ;
271
284
}
272
285
273
- void init_pipe (dt_iop_module_t * self , dt_dev_pixelpipe_t * pipe , dt_dev_pixelpipe_iop_t * piece )
286
+ void init_pipe (dt_iop_module_t * self ,
287
+ dt_dev_pixelpipe_t * pipe ,
288
+ dt_dev_pixelpipe_iop_t * piece )
274
289
{
275
290
piece -> data = calloc (1 , sizeof (dt_iop_rlce_data_t ));
276
291
}
277
292
278
- void cleanup_pipe (dt_iop_module_t * self , dt_dev_pixelpipe_t * pipe , dt_dev_pixelpipe_iop_t * piece )
293
+ void cleanup_pipe (dt_iop_module_t * self ,
294
+ dt_dev_pixelpipe_t * pipe ,
295
+ dt_dev_pixelpipe_iop_t * piece )
279
296
{
280
297
free (piece -> data );
281
298
piece -> data = NULL ;
@@ -306,8 +323,10 @@ void gui_init(dt_iop_module_t *self)
306
323
307
324
self -> widget = GTK_WIDGET (gtk_box_new (GTK_ORIENTATION_HORIZONTAL , 0 ));
308
325
309
- g -> vbox1 = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL , DT_GUI_IOP_MODULE_CONTROL_SPACING ));
310
- g -> vbox2 = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL , DT_GUI_IOP_MODULE_CONTROL_SPACING ));
326
+ g -> vbox1 = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL ,
327
+ DT_GUI_IOP_MODULE_CONTROL_SPACING ));
328
+ g -> vbox2 = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL ,
329
+ DT_GUI_IOP_MODULE_CONTROL_SPACING ));
311
330
gtk_box_pack_start (GTK_BOX (self -> widget ), GTK_WIDGET (g -> vbox1 ), FALSE, FALSE, 0 );
312
331
gtk_box_pack_start (GTK_BOX (self -> widget ), GTK_WIDGET (g -> vbox2 ), TRUE, TRUE, 0 );
313
332
@@ -325,13 +344,14 @@ void gui_init(dt_iop_module_t *self)
325
344
gtk_widget_set_tooltip_text (GTK_WIDGET (g -> scale1 ), _ ("size of features to preserve" ));
326
345
gtk_widget_set_tooltip_text (GTK_WIDGET (g -> scale2 ), _ ("strength of the effect" ));
327
346
328
- g_signal_connect (G_OBJECT (g -> scale1 ), "value-changed" , G_CALLBACK (radius_callback ), self );
329
- g_signal_connect (G_OBJECT (g -> scale2 ), "value-changed" , G_CALLBACK (slope_callback ), self );
347
+ g_signal_connect (G_OBJECT (g -> scale1 ), "value-changed" ,
348
+ G_CALLBACK (radius_callback ), self );
349
+ g_signal_connect (G_OBJECT (g -> scale2 ), "value-changed" ,
350
+ G_CALLBACK (slope_callback ), self );
330
351
}
331
352
332
353
// clang-format off
333
354
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
334
355
// vim: shiftwidth=2 expandtab tabstop=2 cindent
335
356
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
336
357
// clang-format on
337
-
0 commit comments