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:

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, dt_dev_pixelpipe_iop_t *piece)
 
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)
 
void process (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_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_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:75
#define N
Definition noiseprofile.c:139

◆ 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; \
\
if(darktable.gui->reset) return; \
\
\
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); \
}
#define TRUE
Definition ashift_lsd.c:151
float dt_bauhaus_slider_get(GtkWidget *widget)
Definition bauhaus.c:2708
void dt_iop_color_picker_reset(dt_iop_module_t *module, gboolean keep)
Definition color_picker_proxy.c:120
darktable_t darktable
Definition darktable.c:111
struct dt_gui_gtk_t * gui
Definition darktable.h:541
struct dt_develop_t * develop
Definition darktable.h:536
int32_t reset
Definition gtk.h:98
Definition colorbalance.c:107
Definition colorbalance.c:97
Definition imageop.h:182
dt_iop_params_t * params
Definition imageop.h:238

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 

◆ _colorbalance_levels_t

Enumerator
LIFT 
GAMMA 
GAIN 
LEVELS 

◆ _colorbalance_patch_t

Enumerator
INVALID 
USER_SELECTED 
AUTO_SELECTED 

◆ _controls_t

Enumerator
HSL 
RGBL 
BOTH 

◆ dt_iop_colorbalance_mode_t

Enumerator
LIFT_GAMMA_GAIN 
SLOPE_OFFSET_POWER 
LEGACY 

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

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 ( )

◆ 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.

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(), GAIN, GAMMA, darktable_t::gui, dt_iop_module_t::gui_data, INVALID, LIFT, MAX, dt_iop_module_t::params, dt_iop_module_t::picked_color, dt_gui_gtk_t::reset, set_HSL_sliders(), and TRUE.

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 
)

◆ 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,
dt_dev_pixelpipe_iop_t piece 
)

References IOP_CS_LAB.

◆ default_group()

int default_group ( )

References IOP_GROUP_COLOR.

◆ description()

const char ** description ( struct dt_iop_module_t self)

◆ flags()

◆ gain_callback()

static void gain_callback ( GtkWidget *  slider,
gpointer  user_data 
)
static

◆ gamma_callback()

static void gamma_callback ( GtkWidget *  slider,
gpointer  user_data 
)
static

◆ gui_changed()

◆ gui_cleanup()

◆ gui_init()

◆ gui_reset()

◆ gui_update()

◆ init_global()

◆ init_pipe()

◆ init_presets()

void init_presets ( dt_iop_module_so_t self)

References add_preset().

◆ legacy_params()

◆ lift_callback()

static void lift_callback ( GtkWidget *  slider,
gpointer  user_data 
)
static

◆ name()

const char * name ( )

Referenced by add_preset().

◆ process()

◆ 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.

References CHANNEL_BLUE, CHANNEL_GREEN, CHANNEL_RED, dt_bauhaus_slider_set(), 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

References dt_bauhaus_slider_set_stop(), and hsl2rgb().

Referenced by set_HSL_sliders().