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 "widgets/bauhaus.h"
50#include "develop/develop.h"
51#include "develop/imageop.h"
52#include "develop/imageop_gui.h"
53
54#include "iop/iop_api.h"
55#include <gtk/gtk.h>
56#include <inttypes.h>
57
59
61{
62 float amount; // $MIN: 0.0 $MAX: 100.0 $DEFAULT: 25.0 $DESCRIPTION: "vibrance"
64
69
74
75const char *deprecated_msg()
76{
77 return _("this module is deprecated. please use the vibrance slider in the color balance rgb module instead.");
78}
79
80const char *name()
81{
82 return _("vibrance");
83}
84
85const char *aliases()
86{
87 return _("saturation");
88}
89
95
97{
98 return IOP_GROUP_COLOR;
99}
100
102{
103 return IOP_CS_LAB;
104}
105
106const char **description(struct dt_iop_module_t *self)
107{
108 return dt_iop_set_description(self, _("saturate and reduce the lightness of the most saturated pixels\n"
109 "to make the colors more vivid."),
110 _("creative"),
111 _("linear or non-linear, Lab, display-referred"),
112 _("non-linear, Lab"),
113 _("non-linear, Lab, display-referred"));
114}
115
117int process(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid,
118 void *const ovoid)
119{
120 const dt_iop_roi_t *const roi_out = &piece->roi_out;
121
122 const dt_iop_vibrance_data_t *const d = (dt_iop_vibrance_data_t *)piece->data;
123 const float *const restrict in = (float *)ivoid;
124 float *const restrict out = (float *)ovoid;
125
126 const float amount = (d->amount * 0.01);
127 const int npixels = roi_out->height * roi_out->width;
129 for(int k = 0; k < 4 * npixels; k += 4)
130 {
131 /* saturation weight 0 - 1 */
132 const float sw = sqrtf((in[k + 1] * in[k + 1]) + (in[k + 2] * in[k + 2])) / 256.0f;
133 const float ls = 1.0f - ((amount * sw) * .25f);
134 const float ss = 1.0f + (amount * sw);
135 const dt_aligned_pixel_t weights = { ls, ss, ss, 1.0f };
136 __OMP_SIMD__(aligned(in, out : 16))
137 for (int c = 0; c < 4; c++)
138 {
139 out[k + c] = in[k + c] * weights[c];
140 }
141 }
142 return 0;
143}
144
152
154{
156 piece->data_size = sizeof(dt_iop_vibrance_data_t);
157}
158
160{
161 dt_free_align(piece->data);
162 piece->data = NULL;
163}
164
171
172void gui_init(struct dt_iop_module_t *self)
173{
175
176 g->amount_scale = dt_bauhaus_slider_from_params(self, "amount");
177 dt_bauhaus_slider_set_format(g->amount_scale, "%");
178 gtk_widget_set_tooltip_text(g->amount_scale, _("the amount of vibrance"));
179}
180// clang-format off
181// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
182// vim: shiftwidth=2 expandtab tabstop=2 cindent
183// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
184// clang-format on
void dt_bauhaus_slider_set(GtkWidget *widget, float pos)
Definition bauhaus.c:3331
void dt_bauhaus_slider_set_format(GtkWidget *widget, const char *format)
Definition bauhaus.c:3407
@ IOP_CS_LAB
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
const dt_colormatrix_t dt_aligned_pixel_t out
void dt_iop_params_t
Definition dev_history.h:43
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:1893
@ IOP_FLAGS_INCLUDE_IN_STYLES
Definition imageop.h:185
@ IOP_FLAGS_DEPRECATED
Definition imageop.h:187
@ IOP_FLAGS_SUPPORTS_BLENDING
Definition imageop.h:186
@ IOP_FLAGS_ALLOW_TILING
Definition imageop.h:188
@ IOP_GROUP_COLOR
Definition imageop.h:158
GtkWidget * dt_bauhaus_slider_from_params(dt_iop_module_t *self, const char *param)
static dt_iop_gui_data_t * dt_iop_gui_data(const struct dt_iop_module_t *m)
The module's GUI data blob, NULL-safe for headless callers: IOP process() implementations read it for...
Definition imageop_gui.h:81
#define IOP_GUI_ALLOC(module)
Definition imageop_gui.h:93
void *const ovoid
float *const restrict const size_t k
#define dt_free_align(ptr)
Release memory from dt_alloc_align() and set ptr to NULL.
Definition mem_alloc.h:214
static void * dt_calloc_align(size_t size)
dt_alloc_align() followed by a zero fill.
Definition mem_alloc.h:225
#define DT_MODULE_INTROSPECTION(MODVER, PARAMSTYPE)
DT_MODULE() for a module whose params struct is introspected.
#define __OMP_SIMD__(...)
Definition openmp.h:99
#define __OMP_PARALLEL_FOR__(...)
Definition openmp.h:95
DT_ALIGNED_PIXEL float dt_aligned_pixel_t[4]
Definition simd.h:53
struct dt_iop_module_t *void * data
dt_iop_params_t * params
Definition imageop.h:333
Region of interest passed through the pixelpipe.
Definition format.h:49
int width
Definition format.h:50
int height
Definition format.h:50
#define __DT_CLONE_TARGETS__
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:145
const char ** description(struct dt_iop_module_t *self)
Definition vibrance.c:106
int default_group()
Definition vibrance.c:96
__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:117
const char * aliases()
Definition vibrance.c:85
void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition vibrance.c:153
const char * name()
Definition vibrance.c:80
void gui_update(struct dt_iop_module_t *self)
Refresh GUI controls from current params and configuration.
Definition vibrance.c:165
void gui_init(struct dt_iop_module_t *self)
Definition vibrance.c:172
int default_colorspace(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
Definition vibrance.c:101
int flags()
Definition vibrance.c:90
void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
Definition vibrance.c:159
const char * deprecated_msg()
Definition vibrance.c:75