Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
vibrance.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2011-2012 Henrik Andersson.
4 Copyright (C) 2012 Richard Wonka.
5 Copyright (C) 2012-2014, 2016, 2019 Tobias Ellinghaus.
6 Copyright (C) 2012, 2014 Ulrich Pegelow.
7 Copyright (C) 2013 Simon Spannagel.
8 Copyright (C) 2014-2016 Roman Lebedev.
9 Copyright (C) 2015 Pedro Côrte-Real.
10 Copyright (C) 2017 Heiko Bauke.
11 Copyright (C) 2018, 2020, 2023, 2025-2026 Aurélien PIERRE.
12 Copyright (C) 2018 Edgardo Hoszowski.
13 Copyright (C) 2018 Maurizio Paglia.
14 Copyright (C) 2018, 2020-2022 Pascal Obry.
15 Copyright (C) 2018 rawfiner.
16 Copyright (C) 2019 Andreas Schneider.
17 Copyright (C) 2019 Diederik ter Rahe.
18 Copyright (C) 2020 Aldric Renaudin.
19 Copyright (C) 2020, 2022 Diederik Ter Rahe.
20 Copyright (C) 2020-2021 Ralf Brown.
21 Copyright (C) 2021 Chris Elston.
22 Copyright (C) 2022 Hanno Schwalm.
23 Copyright (C) 2022 Martin Bařinka.
24 Copyright (C) 2022 Philipp Lutz.
25
26 darktable is free software: you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by
28 the Free Software Foundation, either version 3 of the License, or
29 (at your option) any later version.
30
31 darktable is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details.
35
36 You should have received a copy of the GNU General Public License
37 along with darktable. If not, see <http://www.gnu.org/licenses/>.
38*/
39#ifdef HAVE_CONFIG_H
40#include "config.h"
41#endif
42#include <assert.h>
43#include <math.h>
44#include <stdlib.h>
45#include <string.h>
46
47#include "bauhaus/bauhaus.h"
48#include "common/opencl.h"
49#include "control/control.h"
50#include "develop/develop.h"
51#include "develop/imageop.h"
52#include "develop/imageop_gui.h"
53
54#include "gui/gtk.h"
55#include "iop/iop_api.h"
56#include <gtk/gtk.h>
57#include <inttypes.h>
58
60
62{
63 float amount; // $MIN: 0.0 $MAX: 100.0 $DEFAULT: 25.0 $DESCRIPTION: "vibrance"
65
70
75
76const char *deprecated_msg()
77{
78 return _("this module is deprecated. please use the vibrance slider in the color balance rgb module instead.");
79}
80
81const char *name()
82{
83 return _("vibrance");
84}
85
86const char *aliases()
87{
88 return _("saturation");
89}
90
96
98{
99 return IOP_GROUP_COLOR;
100}
101
103{
104 return IOP_CS_LAB;
105}
106
107const char **description(struct dt_iop_module_t *self)
108{
109 return dt_iop_set_description(self, _("saturate and reduce the lightness of the most saturated pixels\n"
110 "to make the colors more vivid."),
111 _("creative"),
112 _("linear or non-linear, Lab, display-referred"),
113 _("non-linear, Lab"),
114 _("non-linear, Lab, display-referred"));
115}
116
118int process(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid,
119 void *const ovoid)
120{
121 const dt_iop_roi_t *const roi_out = &piece->roi_out;
122
123 const dt_iop_vibrance_data_t *const d = (dt_iop_vibrance_data_t *)piece->data;
124 const float *const restrict in = (float *)ivoid;
125 float *const restrict out = (float *)ovoid;
126
127 const float amount = (d->amount * 0.01);
128 const int npixels = roi_out->height * roi_out->width;
130 for(int k = 0; k < 4 * npixels; k += 4)
131 {
132 /* saturation weight 0 - 1 */
133 const float sw = sqrtf((in[k + 1] * in[k + 1]) + (in[k + 2] * in[k + 2])) / 256.0f;
134 const float ls = 1.0f - ((amount * sw) * .25f);
135 const float ss = 1.0f + (amount * sw);
136 const dt_aligned_pixel_t weights = { ls, ss, ss, 1.0f };
137 __OMP_SIMD__(aligned(in, out : 16))
138 for (int c = 0; c < 4; c++)
139 {
140 out[k + c] = in[k + c] * weights[c];
141 }
142 }
143 return 0;
144}
145
153
155{
157 piece->data_size = sizeof(dt_iop_vibrance_data_t);
158}
159
161{
162 dt_free_align(piece->data);
163 piece->data = NULL;
164}
165
172
173void gui_init(struct dt_iop_module_t *self)
174{
176
177 g->amount_scale = dt_bauhaus_slider_from_params(self, "amount");
178 dt_bauhaus_slider_set_format(g->amount_scale, "%");
179 gtk_widget_set_tooltip_text(g->amount_scale, _("the amount of vibrance"));
180}
181// clang-format off
182// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
183// vim: shiftwidth=2 expandtab tabstop=2 cindent
184// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
185// clang-format on
void dt_bauhaus_slider_set(GtkWidget *widget, float pos)
Definition bauhaus.c:3506
void dt_bauhaus_slider_set_format(GtkWidget *widget, const char *format)
Definition bauhaus.c:3598
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
@ IOP_CS_LAB
const dt_colormatrix_t dt_aligned_pixel_t out
#define dt_free_align(ptr)
Definition darktable.h:481
static void * dt_calloc_align(size_t size)
Definition darktable.h:488
#define __OMP_SIMD__(...)
Definition darktable.h:262
#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
void dt_iop_params_t
Definition dev_history.h:41
const char ** dt_iop_set_description(dt_iop_module_t *module, const char *main_text, const char *purpose, const char *input, const char *process, const char *output)
Definition imageop.c:3141
@ 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_COLOR
Definition imageop.h:139
#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
float *const restrict const size_t k
float dt_aligned_pixel_t[4]
struct _GtkWidget GtkWidget
Definition splash.h:29
struct dt_iop_module_t *void * data
dt_iop_gui_data_t * gui_data
Definition imageop.h:311
dt_iop_params_t * params
Definition imageop.h:307
Region of interest passed through the pixelpipe.
Definition imageop.h:72
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 vibrance.c:146
const char ** description(struct dt_iop_module_t *self)
Definition vibrance.c:107
int default_group()
Definition vibrance.c:97
__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 vibrance.c:118
const char * aliases()
Definition vibrance.c:86
void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition vibrance.c:154
const char * name()
Definition vibrance.c:81
void gui_update(struct dt_iop_module_t *self)
Refresh GUI controls from current params and configuration.
Definition vibrance.c:166
void gui_init(struct dt_iop_module_t *self)
Definition vibrance.c:173
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
Definition vibrance.c:102
int flags()
Definition vibrance.c:91
void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition vibrance.c:160
const char * deprecated_msg()
Definition vibrance.c:76