Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
relight.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2011 Bruce Guenter.
4 Copyright (C) 2010-2012 Henrik Andersson.
5 Copyright (C) 2010-2013, 2016 johannes hanika.
6 Copyright (C) 2010 Milan Knížek.
7 Copyright (C) 2010, 2012 Pascal de Bruijn.
8 Copyright (C) 2011 Antony Dovgal.
9 Copyright (C) 2011 Brian Teague.
10 Copyright (C) 2011 Jérémy Rosen.
11 Copyright (C) 2011 Olivier Tribout.
12 Copyright (C) 2011 Robert Bieber.
13 Copyright (C) 2011-2014, 2016, 2018-2019 Tobias Ellinghaus.
14 Copyright (C) 2012 Richard Wonka.
15 Copyright (C) 2012-2014 Ulrich Pegelow.
16 Copyright (C) 2013 Dennis Gnad.
17 Copyright (C) 2013 Simon Spannagel.
18 Copyright (C) 2014-2016, 2019 Roman Lebedev.
19 Copyright (C) 2015 Pedro Côrte-Real.
20 Copyright (C) 2017 Heiko Bauke.
21 Copyright (C) 2018-2020, 2022-2023, 2025-2026 Aurélien PIERRE.
22 Copyright (C) 2018-2019 Edgardo Hoszowski.
23 Copyright (C) 2018 Maurizio Paglia.
24 Copyright (C) 2018-2022 Pascal Obry.
25 Copyright (C) 2018 rawfiner.
26 Copyright (C) 2019 Andreas Schneider.
27 Copyright (C) 2019-2020, 2022 Diederik Ter Rahe.
28 Copyright (C) 2020 Aldric Renaudin.
29 Copyright (C) 2020 Marco.
30 Copyright (C) 2020 Ralf Brown.
31 Copyright (C) 2021 Chris Elston.
32 Copyright (C) 2022 Hanno Schwalm.
33 Copyright (C) 2022 Martin Bařinka.
34 Copyright (C) 2022 Philipp Lutz.
35
36 darktable is free software: you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation, either version 3 of the License, or
39 (at your option) any later version.
40
41 darktable is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
45
46 You should have received a copy of the GNU General Public License
47 along with darktable. If not, see <http://www.gnu.org/licenses/>.
48*/
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#endif
52#include <assert.h>
53#include <stdlib.h>
54#include <string.h>
55
56#include "bauhaus/bauhaus.h"
57#include "common/debug.h"
58#include "common/math.h"
59#include "common/opencl.h"
60#include "control/control.h"
61#include "develop/develop.h"
62#include "develop/imageop.h"
63#include "develop/imageop_gui.h"
65#include "dtgtk/togglebutton.h"
67
68#include "gui/gtk.h"
69#include "gui/presets.h"
70#include "iop/iop_api.h"
71
73
75{
76 float ev; // $MIN: -2.0 $MAX: 2.0 $DEFAULT: 0.33 $DESCRIPTION: "exposure"
77 float center; // $DEFAULT: 0.0
78 float width; // $MIN: 2.0 $MAX: 10.0 $DEFAULT: 4.0
80
82{
84
85 dt_gui_presets_add_generic(_("fill-light 0.25EV with 4 zones"), self->op, self->version(),
86 &(dt_iop_relight_params_t){ 0.25, 0.25, 4.0 }, sizeof(dt_iop_relight_params_t),
88
89 dt_gui_presets_add_generic(_("fill-shadow -0.25EV with 4 zones"), self->op, self->version(),
90 &(dt_iop_relight_params_t){ -0.25, 0.25, 4.0 }, sizeof(dt_iop_relight_params_t),
92
94}
95
102
104{
105 float ev; // The ev of relight -4 - +4 EV
106 float center; // the center light value for relight
107 float width; // the width expressed in zones
109
110const char *name()
111{
112 return _("fill light");
113}
114
119
120const char *deprecated_msg()
121{
122 return _("this module is deprecated. please use the tone equalizer module instead.");
123}
124
126{
127 return IOP_GROUP_EFFECTS;
128}
129
131{
132 return IOP_CS_LAB;
133}
134
135#define GAUSS(a, b, c, x) (a * powf(2.718281828f, (-powf((x - b), 2) / (powf(c, 2)))))
136
138int process(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid,
139 void *const ovoid)
140{
141 const dt_iop_roi_t *const roi_out = &piece->roi_out;
143 const int ch = piece->dsc_in.channels;
144
145 // Precalculate parameters for gauss function
146 const float a = 1.0; // Height of top
147 const float b = -1.0 + (data->center * 2); // Center of top
148 const float c = (data->width / 10.0) / 2.0; // Width
150 for(int k = 0; k < roi_out->height; k++)
151 {
152 float *in = ((float *)ivoid) + (size_t)ch * k * roi_out->width;
153 float *out = ((float *)ovoid) + (size_t)ch * k * roi_out->width;
154 for(int j = 0; j < roi_out->width; j++, in += ch, out += ch)
155 {
156 const float lightness = in[0] / 100.0;
157 const float x = -1.0 + (lightness * 2.0);
158 float gauss = GAUSS(a, b, c, x);
159
160 if(isnan(gauss) || !isfinite(gauss)) gauss = 0.0;
161
162 float relight = 1.0 / exp2f(-data->ev * CLIP(gauss));
163
164 if(isnan(relight) || !isfinite(relight)) relight = 1.0;
165
166 out[0] = 100.0 * CLIP(lightness * relight);
167 out[1] = in[1];
168 out[2] = in[2];
169 out[3] = in[3];
170 }
171 }
172 return 0;
173}
174
175static void center_callback(GtkDarktableGradientSlider *slider, gpointer user_data)
176{
177 dt_iop_module_t *self = (dt_iop_module_t *)user_data;
178 if(darktable.gui->reset) return;
181 p->center = dtgtk_gradient_slider_get_value(slider);
183}
184
187{
190
191 d->ev = p->ev;
192 d->width = p->width;
193 d->center = p->center;
194}
195
197{
199 piece->data_size = sizeof(dt_iop_relight_data_t);
200}
201
203{
204 dt_free_align(piece->data);
205 piece->data = NULL;
206}
207
214
216{
218 float mean, min, max;
219
220 if(self->picked_color_max[0] >= 0.0f)
221 {
222 mean = fmin(fmax(self->picked_color[0] / 100.0f, 0.0f), 1.0f);
223 min = fmin(fmax(self->picked_color_min[0] / 100.0f, 0.0f), 1.0f);
224 max = fmin(fmax(self->picked_color_max[0] / 100.0f, 0.0f), 1.0f);
225 }
226 else
227 {
228 mean = min = max = NAN;
229 }
230
232}
233
234void gui_init(struct dt_iop_module_t *self)
235{
237
238 g->exposure = dt_bauhaus_slider_from_params(self, "ev");
239 dt_bauhaus_slider_set_format(g->exposure, _(" EV"));
240 gtk_widget_set_tooltip_text(g->exposure, _("the fill-light in EV"));
241
242 /* lightnessslider */
243 GtkBox *sliderbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, DT_GUI_BOX_SPACING));
244#define NEUTRAL_GRAY 0.5
245 static const GdkRGBA _gradient_L[]
246 = { { 0, 0, 0, 1.0 }, { NEUTRAL_GRAY, NEUTRAL_GRAY, NEUTRAL_GRAY, 1.0 } };
247
249 gtk_widget_set_tooltip_text(GTK_WIDGET(g->center), _("select the center of fill-light\nctrl+click to select an area"));
250 g_signal_connect(G_OBJECT(g->center), "value-changed", G_CALLBACK(center_callback), self);
251 gtk_box_pack_start(sliderbox, GTK_WIDGET(g->center), TRUE, TRUE, 0);
252 g->colorpicker = dt_color_picker_new(self, DT_COLOR_PICKER_POINT_AREA, GTK_WIDGET(sliderbox));
253 gtk_widget_set_tooltip_text(GTK_WIDGET(g->colorpicker), _("toggle tool for picking median lightness in image"));
254 gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(sliderbox), TRUE, FALSE, 0);
255
256 g->width = dt_bauhaus_slider_from_params(self, N_("width"));
257 gtk_widget_set_tooltip_text(g->width, _("width of fill-light area defined in zones"));
258}
259
260// clang-format off
261// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
262// vim: shiftwidth=2 expandtab tabstop=2 cindent
263// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
264// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
void dt_bauhaus_slider_set_format(GtkWidget *widget, const char *format)
Definition bauhaus.c:3598
@ DEVELOP_BLEND_CS_RGB_DISPLAY
Definition blend.h:59
const dt_iop_gui_blendif_colorstop_t _gradient_L[]
Definition blend_gui.c:165
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
@ IOP_CS_LAB
void dt_iop_color_picker_reset(dt_iop_module_t *module, gboolean keep)
GtkWidget * dt_color_picker_new(dt_iop_module_t *module, dt_iop_color_picker_kind_t kind, GtkWidget *w)
@ DT_COLOR_PICKER_POINT_AREA
static const float const float const float min
const float max
const dt_colormatrix_t dt_aligned_pixel_t out
darktable_t darktable
Definition darktable.c:181
#define dt_free_align(ptr)
Definition darktable.h:481
static void * dt_calloc_align(size_t size)
Definition darktable.h:488
#define DT_MODULE_INTROSPECTION(MODVER, PARAMSTYPE)
Definition darktable.h:151
#define __DT_CLONE_TARGETS__
Definition darktable.h:367
#define __OMP_PARALLEL_FOR__(...)
Definition darktable.h:258
#define dt_database_start_transaction(db)
Definition database.h:77
#define dt_database_release_transaction(db)
Definition database.h:78
#define dt_dev_add_history_item(dev, module, enable, redraw)
void dt_iop_params_t
Definition dev_history.h:41
GtkWidget * dtgtk_gradient_slider_new_with_color_and_name(GdkRGBA start, GdkRGBA end, gchar *name)
void dtgtk_gradient_slider_set_value(GtkDarktableGradientSlider *gslider, gdouble value)
gdouble dtgtk_gradient_slider_get_value(GtkDarktableGradientSlider *gslider)
void dtgtk_gradient_slider_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, gdouble min, gdouble max)
#define DTGTK_GRADIENT_SLIDER(obj)
#define DT_GUI_BOX_SPACING
Definition gtk.h:109
void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const int32_t version, const void *params, const int32_t params_size, const int32_t enabled, const dt_develop_blend_colorspace_t blend_cst)
@ IOP_FLAGS_INCLUDE_IN_STYLES
Definition imageop.h:166
@ IOP_FLAGS_DEPRECATED
Definition imageop.h:168
@ IOP_FLAGS_SUPPORTS_BLENDING
Definition imageop.h:167
@ IOP_FLAGS_ALLOW_TILING
Definition imageop.h:169
@ IOP_GROUP_EFFECTS
Definition imageop.h:142
#define IOP_GUI_ALLOC(module)
Definition imageop.h:599
GtkWidget * dt_bauhaus_slider_from_params(dt_iop_module_t *self, const char *param)
Definition imageop_gui.c:77
void *const ovoid
static const float x
float *const restrict const size_t k
float *const restrict const size_t const size_t ch
#define CLIP(x)
Definition math.h:81
static void center_callback(GtkDarktableGradientSlider *slider, gpointer user_data)
Definition relight.c:175
void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition relight.c:185
int default_group()
Definition relight.c:125
__DT_CLONE_TARGETS__ int process(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid)
Definition relight.c:138
void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition relight.c:196
const char * name()
Definition relight.c:110
void gui_update(struct dt_iop_module_t *self)
Refresh GUI controls from current params and configuration.
Definition relight.c:208
void gui_init(struct dt_iop_module_t *self)
Definition relight.c:234
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
Definition relight.c:130
int flags()
Definition relight.c:115
void init_presets(dt_iop_module_so_t *self)
Definition relight.c:81
#define GAUSS(a, b, c, x)
Definition relight.c:135
void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition relight.c:202
const char * deprecated_msg()
Definition relight.c:120
void color_picker_apply(dt_iop_module_t *self, GtkWidget *picker, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition relight.c:215
#define NEUTRAL_GRAY
struct _GtkWidget GtkWidget
Definition splash.h:29
struct dt_gui_gtk_t * gui
Definition darktable.h:775
const struct dt_database_t * db
Definition darktable.h:779
struct dt_develop_t * develop
Definition darktable.h:770
dt_iop_buffer_dsc_t dsc_in
struct dt_iop_module_t *void * data
int32_t reset
Definition gtk.h:172
unsigned int channels
Definition format.h:54
GModule *dt_dev_operation_t op
Definition imageop.h:230
GtkWidget * widget
Definition imageop.h:337
dt_iop_gui_data_t * gui_data
Definition imageop.h:311
dt_aligned_pixel_t picked_color_min
Definition imageop.h:272
dt_aligned_pixel_t picked_color_max
Definition imageop.h:272
dt_aligned_pixel_t picked_color
Definition imageop.h:272
dt_iop_params_t * params
Definition imageop.h:307
GtkWidget * colorpicker
Definition relight.c:100
GtkDarktableGradientSlider * center
Definition relight.c:99
Region of interest passed through the pixelpipe.
Definition imageop.h:72