Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
colorbalance.c File Reference
#include "bauhaus/bauhaus.h"
#include "common/exif.h"
#include "common/colorspaces_inline_conversions.h"
#include "common/opencl.h"
#include "develop/blend.h"
#include "develop/imageop.h"
#include "develop/imageop_math.h"
#include "develop/imageop_gui.h"
#include "dtgtk/gradientslider.h"
#include "gui/gtk.h"
#include "gui/presets.h"
#include "gui/color_picker_proxy.h"
#include "iop/iop_api.h"
#include <stdlib.h>
+ Include dependency graph for colorbalance.c:

Go to the source code of this file.

Data Structures

struct  dt_iop_colorbalance_params_t
 
struct  dt_iop_colorbalance_gui_data_t
 
struct  dt_iop_colorbalance_data_t
 
struct  dt_iop_colorbalance_global_data_t
 

Macros

#define HSL_CALLBACK(which)
 
#define ADD_CHANNEL(which, section, c, n, N, text, span)
 
#define ADD_BLOCK(blk, which, section, text, span, satspan)
 

Typedefs

typedef enum dt_iop_colorbalance_mode_t dt_iop_colorbalance_mode_t
 
typedef enum _colorbalance_channel_t _colorbalance_channel_t
 
typedef enum _colorbalance_levels_t _colorbalance_levels_t
 
typedef enum _controls_t _controls_t
 
typedef enum _colorbalance_patch_t _colorbalance_patch_t
 
typedef struct dt_iop_colorbalance_params_t dt_iop_colorbalance_params_t
 
typedef struct dt_iop_colorbalance_gui_data_t dt_iop_colorbalance_gui_data_t
 
typedef struct dt_iop_colorbalance_data_t dt_iop_colorbalance_data_t
 
typedef struct dt_iop_colorbalance_global_data_t dt_iop_colorbalance_global_data_t
 

Enumerations

enum  dt_iop_colorbalance_mode_t {
  LIFT_GAMMA_GAIN = 0 ,
  SLOPE_OFFSET_POWER = 1 ,
  LEGACY = 2
}
 
enum  _colorbalance_channel_t {
  CHANNEL_FACTOR = 0 ,
  CHANNEL_RED ,
  CHANNEL_GREEN ,
  CHANNEL_BLUE ,
  CHANNEL_SIZE
}
 
enum  _colorbalance_levels_t {
  LIFT = 0 ,
  GAMMA ,
  GAIN ,
  LEVELS
}
 
enum  _controls_t {
  HSL ,
  RGBL ,
  BOTH
}
 
enum  _colorbalance_patch_t {
  INVALID ,
  USER_SELECTED ,
  AUTO_SELECTED
}
 

Functions

const char * name ()
 
const char * aliases ()
 
const char ** description (struct dt_iop_module_t *self)
 
int flags ()
 
int default_group ()
 
int default_colorspace (dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
 
void input_format (dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
 
int legacy_params (dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, const int new_version)
 
static void add_preset (dt_iop_module_so_t *self, const char *name, const char *pi, const int version, const char *bpi, const int blendop_version)
 
void init_presets (dt_iop_module_so_t *self)
 
static float CDL (float x, float slope, float offset, float power)
 
__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)
 
int process_cl (struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
 
static void update_saturation_slider_color (GtkWidget *slider, float hue)
 
static void set_RGB_sliders (GtkWidget *R, GtkWidget *G, GtkWidget *B, float hsl[3], float *p, int mode)
 
static void set_HSL_sliders (GtkWidget *hue, GtkWidget *sat, float RGB[4])
 
static void _check_tuner_picker_labels (dt_iop_module_t *self)
 
static void apply_autogrey (dt_iop_module_t *self)
 
static void apply_lift_neutralize (dt_iop_module_t *self)
 
static void apply_gamma_neutralize (dt_iop_module_t *self)
 
static void apply_gain_neutralize (dt_iop_module_t *self)
 
static void apply_lift_auto (dt_iop_module_t *self)
 
static void apply_gamma_auto (dt_iop_module_t *self)
 
static void apply_gain_auto (dt_iop_module_t *self)
 
static void apply_autocolor (dt_iop_module_t *self)
 
static void apply_autoluma (dt_iop_module_t *self)
 
void color_picker_apply (dt_iop_module_t *self, GtkWidget *picker, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
 
void init_global (dt_iop_module_so_t *module)
 
void cleanup_global (dt_iop_module_so_t *module)
 
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)
 
void init_pipe (dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
 
void cleanup_pipe (dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
 
void set_visible_widgets (dt_iop_colorbalance_gui_data_t *g)
 
void gui_update (dt_iop_module_t *self)
 
void gui_reset (dt_iop_module_t *self)
 
static void _configure_slider_blocks (gpointer instance, dt_iop_module_t *self)
 
void gui_changed (dt_iop_module_t *self, GtkWidget *w, void *previous)
 
static void controls_callback (GtkWidget *combo, dt_iop_module_t *self)
 
static void _cycle_layout_callback (GtkWidget *label, GdkEventButton *event, dt_iop_module_t *self)
 
static void lift_callback (GtkWidget *slider, gpointer user_data)
 
static void gamma_callback (GtkWidget *slider, gpointer user_data)
 
static void gain_callback (GtkWidget *slider, gpointer user_data)
 
void gui_init (dt_iop_module_t *self)
 
void gui_cleanup (struct dt_iop_module_t *self)
 

Macro Definition Documentation

◆ ADD_BLOCK

#define ADD_BLOCK (   blk,
  which,
  section,
  text,
  span,
  satspan 
)

◆ ADD_CHANNEL

#define ADD_CHANNEL (   which,
  section,
  c,
  n,
  N,
  text,
  span 
)
Value:
sprintf(field_name, "%s[%d]", #which, CHANNEL_##N); \
g->which##_##c = dt_bauhaus_slider_from_params(self, field_name); \
dt_bauhaus_slider_set_soft_range(g->which##_##c, -span+1.0, span+1.0); \
dt_bauhaus_slider_set_digits(g->which##_##c, 5); \
dt_bauhaus_slider_set_offset(g->which##_##c, -1.0); \
dt_bauhaus_slider_set_feedback(g->which##_##c, 0); \
gtk_widget_set_tooltip_text(g->which##_##c, _(text[CHANNEL_##N])); \
dt_bauhaus_widget_set_label(g->which##_##c, #n); \
GtkWidget * dt_bauhaus_slider_from_params(dt_iop_module_t *self, const char *param)
Definition imageop_gui.c:77
#define N

◆ HSL_CALLBACK

#define HSL_CALLBACK (   which)
Value:
static void which##_callback(GtkWidget *slider, gpointer user_data) \
{ \
dt_iop_module_t *self = (dt_iop_module_t *)user_data; \
\
\
\
float hsl[3] = {dt_bauhaus_slider_get(g->hue_##which) / 360.0f, \
dt_bauhaus_slider_get(g->sat_##which) / 100.0f, \
0.5f}; \
\
if(slider == g->hue_##which) \
update_saturation_slider_color(g->sat_##which, hsl[0]); \
set_RGB_sliders(g->which##_r, g->which##_g, g->which##_b, hsl, p->which, p->mode); \
dt_dev_add_history_item(darktable.develop, self, TRUE, TRUE); \
}
#define TRUE
Definition ashift_lsd.c:162
float dt_bauhaus_slider_get(GtkWidget *widget)
Definition bauhaus.c:3483
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
void dt_iop_color_picker_reset(dt_iop_module_t *module, gboolean keep)
darktable_t darktable
Definition darktable.c:181
struct _GtkWidget GtkWidget
Definition splash.h:29
return(r *r - sigma *sigma)/4.f - 3.f/8.f
struct dt_gui_gtk_t * gui
Definition darktable.h:775
struct dt_develop_t * develop
Definition darktable.h:770
int32_t reset
Definition gtk.h:172
dt_iop_params_t * params
Definition imageop.h:307

Definition at line 1552 of file colorbalance.c.

Typedef Documentation

◆ _colorbalance_channel_t

◆ _colorbalance_levels_t

◆ _colorbalance_patch_t

◆ _controls_t

typedef enum _controls_t _controls_t

◆ dt_iop_colorbalance_data_t

◆ dt_iop_colorbalance_global_data_t

◆ dt_iop_colorbalance_gui_data_t

◆ dt_iop_colorbalance_mode_t

◆ dt_iop_colorbalance_params_t

Enumeration Type Documentation

◆ _colorbalance_channel_t

Enumerator
CHANNEL_FACTOR 
CHANNEL_RED 
CHANNEL_GREEN 
CHANNEL_BLUE 
CHANNEL_SIZE 

Definition at line 95 of file colorbalance.c.

◆ _colorbalance_levels_t

Enumerator
LIFT 
GAMMA 
GAIN 
LEVELS 

Definition at line 104 of file colorbalance.c.

◆ _colorbalance_patch_t

Enumerator
INVALID 
USER_SELECTED 
AUTO_SELECTED 

Definition at line 119 of file colorbalance.c.

◆ _controls_t

Enumerator
HSL 
RGBL 
BOTH 

Definition at line 112 of file colorbalance.c.

◆ dt_iop_colorbalance_mode_t

Enumerator
LIFT_GAMMA_GAIN 
SLOPE_OFFSET_POWER 
LEGACY 

Definition at line 88 of file colorbalance.c.

Function Documentation

◆ _check_tuner_picker_labels()

static void _check_tuner_picker_labels ( dt_iop_module_t self)
inlinestatic

◆ _configure_slider_blocks()

static void _configure_slider_blocks ( gpointer  instance,
dt_iop_module_t self 
)
static

◆ _cycle_layout_callback()

static void _cycle_layout_callback ( GtkWidget label,
GdkEventButton *  event,
dt_iop_module_t self 
)
static

Definition at line 1547 of file colorbalance.c.

References _configure_slider_blocks().

Referenced by gui_init().

◆ add_preset()

static void add_preset ( dt_iop_module_so_t self,
const char *  name,
const char *  pi,
const int  version,
const char *  bpi,
const int  blendop_version 
)
static

◆ aliases()

const char * aliases ( )

Definition at line 181 of file colorbalance.c.

◆ apply_autocolor()

static void apply_autocolor ( dt_iop_module_t self)
static

Optimization loop : We try to find the CDL curves that neutralize the 3 input color patches, while not affecting the overall lightness. But this is a non-linear overconstrained problem with tainted inputs, so the best we can do is a numerical optimization. To do so, we compute each parameter of each RGB curve from the input color and the 2 other parameters. Then, we loop over the previous optimization until the difference between 2 updates is insignificant. This would need a proper stopping criterion based on convergence analysis, but it would be overkill here since it should converge usually in 20 iterations, and maximum in 100. Also, the convergence has not been proven formally. For better color accuracy, we compute on luminance corrected RGB values (after the main factors corrections). To avoid divergence, we constrain the parameters between +- 0.25 around the neutral value. Experimentally, nothing good happens out of these bounds.

Definition at line 971 of file colorbalance.c.

References AUTO_SELECTED, CDL(), CHANNEL_BLUE, CHANNEL_FACTOR, CHANNEL_GREEN, CHANNEL_RED, darktable, darktable_t::develop, dt_bauhaus_slider_set(), dt_dev_add_history_item, dt_iop_color_picker_reset(), dt_Lab_to_XYZ(), dt_prophotorgb_to_XYZ(), dt_XYZ_to_prophotorgb(), g, GAIN, GAMMA, darktable_t::gui, dt_iop_module_t::gui_data, INVALID, LIFT, MAX, p, dt_iop_module_t::params, dt_iop_module_t::picked_color, dt_gui_gtk_t::reset, RGB, set_HSL_sliders(), TRUE, and XYZ.

Referenced by color_picker_apply().

◆ apply_autogrey()

◆ apply_autoluma()

◆ apply_gain_auto()

◆ apply_gain_neutralize()

◆ apply_gamma_auto()

◆ apply_gamma_neutralize()

◆ apply_lift_auto()

◆ apply_lift_neutralize()

◆ CDL()

static float CDL ( float  x,
float  slope,
float  offset,
float  power 
)
inlinestatic

◆ cleanup_global()

◆ cleanup_pipe()

void cleanup_pipe ( dt_iop_module_t self,
dt_dev_pixelpipe_t pipe,
dt_dev_pixelpipe_iop_t piece 
)

Definition at line 1280 of file colorbalance.c.

References dt_dev_pixelpipe_iop_t::data, and dt_free_align.

◆ color_picker_apply()

◆ commit_params()

◆ controls_callback()

static void controls_callback ( GtkWidget combo,
dt_iop_module_t self 
)
static

◆ default_colorspace()

int default_colorspace ( dt_iop_module_t self,
dt_dev_pixelpipe_t pipe,
const dt_dev_pixelpipe_iop_t piece 
)

Definition at line 205 of file colorbalance.c.

References IOP_CS_LAB.

◆ default_group()

int default_group ( )

Definition at line 200 of file colorbalance.c.

References IOP_GROUP_COLOR.

◆ description()

const char ** description ( struct dt_iop_module_t self)

Definition at line 186 of file colorbalance.c.

References dt_iop_set_description().

◆ flags()

int flags ( )

◆ gain_callback()

static void gain_callback ( GtkWidget slider,
gpointer  user_data 
)
static

Definition at line 1575 of file colorbalance.c.

◆ gamma_callback()

static void gamma_callback ( GtkWidget slider,
gpointer  user_data 
)
static

Definition at line 1574 of file colorbalance.c.

◆ gui_changed()

◆ gui_cleanup()

◆ gui_init()

◆ gui_reset()

◆ gui_update()

void gui_update ( dt_iop_module_t self)
Todo:
check why needed
Todo:
by hand

Definition at line 1319 of file colorbalance.c.

References _check_tuner_picker_labels(), dt_iop_color_picker_reset(), gui_changed(), and TRUE.

◆ init_global()

◆ init_pipe()

◆ init_presets()

void init_presets ( dt_iop_module_so_t self)

Definition at line 308 of file colorbalance.c.

References add_preset().

◆ input_format()

◆ legacy_params()

int legacy_params ( dt_iop_module_t self,
const void *const  old_params,
const int  old_version,
void new_params,
const int  new_version 
)

Definition at line 218 of file colorbalance.c.

References CHANNEL_SIZE, d, dt_iop_module_t::default_params, i, LEGACY, and n.

◆ lift_callback()

static void lift_callback ( GtkWidget slider,
gpointer  user_data 
)
static

Definition at line 1573 of file colorbalance.c.

◆ name()

const char * name ( )

Definition at line 176 of file colorbalance.c.

Referenced by add_preset().

◆ process()

◆ process_cl()

◆ set_HSL_sliders()

static void set_HSL_sliders ( GtkWidget hue,
GtkWidget sat,
float  RGB[4] 
)
inlinestatic

HSL sliders are set from the RGB values at any time. Only the RGB values are saved and used in the computations. The HSL sliders are merely an interface.

Definition at line 698 of file colorbalance.c.

References CHANNEL_BLUE, CHANNEL_GREEN, CHANNEL_RED, dt_bauhaus_slider_set(), RGB, rgb2hsl(), and update_saturation_slider_color().

Referenced by apply_autocolor(), apply_gain_neutralize(), apply_gamma_neutralize(), apply_lift_neutralize(), and gui_changed().

◆ set_RGB_sliders()

static void set_RGB_sliders ( GtkWidget R,
GtkWidget G,
GtkWidget B,
float  hsl[3],
float *  p,
int  mode 
)
inlinestatic

◆ set_visible_widgets()

◆ update_saturation_slider_color()

static void update_saturation_slider_color ( GtkWidget slider,
float  hue 
)
inlinestatic

Definition at line 665 of file colorbalance.c.

References dt_bauhaus_slider_set_stop(), hsl2rgb(), and rgb.

Referenced by set_HSL_sliders().