Skip to content

Commit 5f0131d

Browse files
committed
Minor code reformatting & add some consts.
1 parent e0feb42 commit 5f0131d

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

src/iop/clahe.c

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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 "bauhaus/bauhaus.h"
1920
#include "common/colorspaces.h"
2021
#include "common/darktable.h"
@@ -84,8 +85,12 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
8485
return IOP_CS_RGB;
8586
}
8687

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)
8994
{
9095
dt_iop_rlce_data_t *data = piece->data;
9196
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
100105
float *lm = luminance + (size_t)j * roi_out->width;
101106
for(int i = 0; i < roi_out->width; i++)
102107
{
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
105110
*lm = (pmax + pmin) / 2.f; // Pixel luminosity
106111
in += ch;
107112
lm++;
@@ -123,12 +128,12 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
123128
DT_OMP_FOR()
124129
for(int j = 0; j < roi_out->height; j++)
125130
{
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;
129134

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);
132137

133138
int hist[BINS + 1];
134139
int clippedhist[BINS + 1];
@@ -150,27 +155,29 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
150155

151156
int v = ROUND_POSISTIVE(luminance[(size_t)j * roi_in->width + i] * (float)BINS);
152157

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;
157162

158-
int limit = (int)(slope * n / BINS + 0.5f);
163+
const int limit = (int)(slope * n / BINS + 0.5f);
159164

160165
/* remove left behind values from histogram */
161166
if(xMin > 0)
162167
{
163-
int xMin1 = xMin - 1;
168+
const int xMin1 = xMin - 1;
164169
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)];
166172
}
167173

168174
/* add newly included values to histogram */
169175
if(xMax <= roi_in->width)
170176
{
171-
int xMax1 = xMax - 1;
177+
const int xMax1 = xMax - 1;
172178
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)];
174181
}
175182

176183
/* 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
182189
ce = 0;
183190
for(int b = 0; b <= BINS; b++)
184191
{
185-
int d = clippedhist[b] - limit;
192+
const int d = clippedhist[b] - limit;
186193
if(d > 0)
187194
{
188195
ce += d;
189196
clippedhist[b] = limit;
190197
}
191198
}
192199

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);
195202
for(int b = 0; b <= BINS; b++) clippedhist[b] += d;
196203

197204
if(m != 0)
198205
{
199-
int s = BINS / (float)m;
206+
const int s = BINS / (float)m;
200207
for(int b = 0; b <= BINS; b += s) ++clippedhist[b];
201208
}
202209
} while(ce != ceb);
@@ -207,12 +214,14 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
207214
if(clippedhist[b] != 0) hMin = b;
208215

209216
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];
211219

212220
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];
214223

215-
int cdfMin = clippedhist[hMin];
224+
const int cdfMin = clippedhist[hMin];
216225

217226
*ld = (cdf - cdfMin) / (float)(cdfMax - cdfMin);
218227

@@ -242,15 +251,17 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c
242251
#undef BINS
243252
}
244253

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)
246256
{
247257
if(darktable.gui->reset) return;
248258
dt_iop_rlce_params_t *p = self->params;
249259
p->radius = dt_bauhaus_slider_get(slider);
250260
dt_dev_add_history_item(darktable.develop, self, TRUE);
251261
}
252262

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)
254265
{
255266
if(darktable.gui->reset) return;
256267
dt_iop_rlce_params_t *p = self->params;
@@ -260,7 +271,9 @@ static void slope_callback(GtkWidget *slider, dt_iop_module_t *self)
260271

261272

262273

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,
264277
dt_dev_pixelpipe_iop_t *piece)
265278
{
266279
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_
270283
d->slope = p->slope;
271284
}
272285

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)
274289
{
275290
piece->data = calloc(1, sizeof(dt_iop_rlce_data_t));
276291
}
277292

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)
279296
{
280297
free(piece->data);
281298
piece->data = NULL;
@@ -306,8 +323,10 @@ void gui_init(dt_iop_module_t *self)
306323

307324
self->widget = GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
308325

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));
311330
gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->vbox1), FALSE, FALSE, 0);
312331
gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->vbox2), TRUE, TRUE, 0);
313332

@@ -325,13 +344,14 @@ void gui_init(dt_iop_module_t *self)
325344
gtk_widget_set_tooltip_text(GTK_WIDGET(g->scale1), _("size of features to preserve"));
326345
gtk_widget_set_tooltip_text(GTK_WIDGET(g->scale2), _("strength of the effect"));
327346

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);
330351
}
331352

332353
// clang-format off
333354
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
334355
// vim: shiftwidth=2 expandtab tabstop=2 cindent
335356
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
336357
// clang-format on
337-

0 commit comments

Comments
 (0)