Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions src/bauhaus/bauhaus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2139,10 +2139,9 @@ static gboolean _popup_draw(GtkWidget *widget,
dt_bauhaus_widget_t *w = bh->current;

// dimensions of the popup
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
const int width = gtk_widget_get_allocated_width(widget);
const GtkBorder *padding = &pop->padding;
const int w2 = allocation.width - padding->left - padding->right;
const int w2 = width - padding->left - padding->right;
const int h2 = pop->position.height - padding->top - padding->bottom;

GtkStyleContext *context = gtk_widget_get_style_context(widget);
Expand All @@ -2162,8 +2161,8 @@ static gboolean _popup_draw(GtkWidget *widget,
gtk_style_context_get_color(context, state, fg_color);

// draw background
gtk_render_background(context, cr, 0, - pop->offcut, allocation.width, pop->position.height);
gtk_render_frame(context, cr, 0, - pop->offcut, allocation.width, pop->position.height);
gtk_render_background(context, cr, 0, - pop->offcut, width, pop->position.height);
gtk_render_frame(context, cr, 0, - pop->offcut, width, pop->position.height);

// translate to account for the widget spacing
cairo_translate(cr, padding->left, padding->top - pop->offcut);
Expand Down Expand Up @@ -2208,7 +2207,7 @@ static gboolean _popup_draw(GtkWidget *widget,
? _slider_get_line_offset(d->oldpos, scale,
bh->mouse_x / w2,
bh->mouse_y / h2,
ht / (float)h2, allocation.width, w)
ht / (float)h2, width, w)
: 0.0f;
_slider_draw_line(cr, d->oldpos, mouse_off, scale, w2, h2, ht, w);
cairo_stroke(cr);
Expand Down Expand Up @@ -2920,7 +2919,8 @@ static gboolean _widget_scroll(GtkWidget *widget,

if(w->type == DT_BAUHAUS_SLIDER)
{
gboolean force = darktable.control->element == DT_ACTION_ELEMENT_FORCE;
gboolean force = darktable.control->element == DT_ACTION_ELEMENT_FORCE
&& event->window == gtk_widget_get_window(widget);
if(force && dt_modifier_is(event->state, GDK_SHIFT_MASK | GDK_CONTROL_MASK))
{
_slider_zoom_range(w, delta_y);
Expand Down Expand Up @@ -3375,16 +3375,15 @@ static gboolean _widget_button_press(GtkWidget *widget,
_request_focus(w);
gtk_widget_grab_focus(widget);

GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
const int w3 = allocation.width - w->margin.left - w->padding.left
- w->margin.right - w->padding.right;
const int width = gtk_widget_get_allocated_width(widget);
const int w3 = width - w->margin.left - w->padding.left
- w->margin.right - w->padding.right;
const double ex = event->x - w->margin.left - w->padding.left;
const double ey = event->y - w->margin.top - w->padding.top;

if(w->quad_paint
&& event->x > allocation.width - _widget_get_quad_width(w)
- w->margin.right - w->padding.right)
if(w->quad_paint && event->window == gtk_widget_get_window(widget)
&& event->x > width - _widget_get_quad_width(w)
- w->margin.right - w->padding.right)
{
dt_bauhaus_widget_press_quad(widget);
}
Expand Down Expand Up @@ -3414,7 +3413,7 @@ static gboolean _widget_button_press(GtkWidget *widget,
{
dt_bauhaus_slider_data_t *d = &w->data.slider;
d->is_dragging = -1;
if(!dt_modifier_is(event->state, 0))
if(!dt_modifier_is(event->state, 0) || event->window != gtk_widget_get_window(widget))
darktable.bauhaus->mouse_x = ex;
else if(ey > darktable.bauhaus->line_height / 2.0f)
{
Expand Down Expand Up @@ -3457,16 +3456,15 @@ static gboolean _widget_motion_notify(GtkWidget *widget,
dt_bauhaus_widget_t *w = (dt_bauhaus_widget_t *)widget;
dt_bauhaus_slider_data_t *d = &w->data.slider;

GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
const int w3 = allocation.width - w->margin.left - w->padding.left
- w->margin.right - w->padding.right;
const int width = gdk_window_get_width(event->window);
const int w3 = width - w->margin.left - w->padding.left
- w->margin.right - w->padding.right;
const double ex = event->x - w->margin.left - w->padding.left;

if(w->type == DT_BAUHAUS_COMBOBOX)
{
darktable.control->element =
event->x <= allocation.width - _widget_get_quad_width(w) || !w->quad_paint
event->x <= width - _widget_get_quad_width(w) || !w->quad_paint
? DT_ACTION_ELEMENT_SELECTION : DT_ACTION_ELEMENT_BUTTON;
}
else if(d->is_dragging && event->state & GDK_BUTTON1_MASK)
Expand Down
68 changes: 7 additions & 61 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2866,78 +2866,24 @@ gboolean dt_dev_is_current_image(const dt_develop_t *dev,
return (dev->image_storage.id == imgid) ? TRUE : FALSE;
}

static dt_dev_proxy_exposure_t *find_last_exposure_instance(dt_develop_t *dev)
static dt_dev_proxy_exposure_t *_dev_exposure_proxy_available(dt_develop_t *dev)
{
if(!dev->proxy.exposure.module) return NULL;
if(!dev->proxy.exposure.module || dt_view_get_current() != DT_VIEW_DARKROOM) return NULL;

dt_dev_proxy_exposure_t *instance = &dev->proxy.exposure;

return instance;
};

gboolean dt_dev_exposure_hooks_available(dt_develop_t *dev)
{
dt_dev_proxy_exposure_t *instance = find_last_exposure_instance(dev);

/* check if exposure iop module has registered its hooks */
if(instance
&& instance->module
&& instance->set_black
&& instance->get_black && instance->set_exposure
&& instance->get_exposure)
return TRUE;

return FALSE;
}

void dt_dev_exposure_reset_defaults(dt_develop_t *dev)
{
dt_dev_proxy_exposure_t *instance = find_last_exposure_instance(dev);

if(!(instance && instance->module)) return;

dt_iop_module_t *exposure = instance->module;
memcpy(exposure->params, exposure->default_params, exposure->params_size);
dt_iop_gui_update(exposure);
dt_dev_add_history_item(exposure->dev, exposure, TRUE);
}

void dt_dev_exposure_set_exposure(dt_develop_t *dev,
const float exposure)
{
dt_dev_proxy_exposure_t *instance = find_last_exposure_instance(dev);

if(instance && instance->module && instance->set_exposure)
instance->set_exposure(instance->module, exposure);
return instance && instance->module ? instance : NULL;
}

float dt_dev_exposure_get_exposure(dt_develop_t *dev)
{
dt_dev_proxy_exposure_t *instance = find_last_exposure_instance(dev);

if(instance && instance->module && instance->get_exposure)
return instance->get_exposure(instance->module);

return 0.0;
}

void dt_dev_exposure_set_black(dt_develop_t *dev,
const float black)
{
dt_dev_proxy_exposure_t *instance = find_last_exposure_instance(dev);

if(instance && instance->module && instance->set_black)
instance->set_black(instance->module, black);
const dt_dev_proxy_exposure_t *instance = _dev_exposure_proxy_available(dev);
return instance && instance->get_exposure && instance->module->enabled ? instance->get_exposure(instance->module) : 0.0f;
}

float dt_dev_exposure_get_black(dt_develop_t *dev)
{
dt_dev_proxy_exposure_t *instance = find_last_exposure_instance(dev);

if(instance && instance->module && instance->get_black)
return instance->get_black(instance->module);

return 0.0;
const dt_dev_proxy_exposure_t *instance = _dev_exposure_proxy_available(dev);
return instance && instance->get_black && instance->module->enabled ? instance->get_black(instance->module) : 0.0f;
}

void dt_dev_modulegroups_set(dt_develop_t *dev,
Expand Down
25 changes: 8 additions & 17 deletions src/develop/develop.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ typedef enum dt_clipping_preview_mode_t
typedef struct dt_dev_proxy_exposure_t
{
struct dt_iop_module_t *module;
void (*set_exposure)(struct dt_iop_module_t *exp, const float exposure);
float (*get_exposure)(struct dt_iop_module_t *exp);
void (*set_black)(struct dt_iop_module_t *exp, const float black);
float (*get_black)(struct dt_iop_module_t *exp);
void (*handle_event)(GdkEvent *event, gboolean blackwhite);
} dt_dev_proxy_exposure_t;

struct dt_dev_pixelpipe_t;
Expand Down Expand Up @@ -457,25 +456,17 @@ void dt_dev_get_viewport_params(dt_dev_viewport_t *port,

void dt_dev_configure(dt_dev_viewport_t *port);

/*
* exposure plugin hook, set the exposure and the black level
*/

/** check if exposure iop hooks are available */
gboolean dt_dev_exposure_hooks_available(dt_develop_t *dev);
/** reset exposure to defaults */
void dt_dev_exposure_reset_defaults(dt_develop_t *dev);
/** set exposure */
void dt_dev_exposure_set_exposure(dt_develop_t *dev,
const float exposure);
/** get exposure */
/** get exposure level */
float dt_dev_exposure_get_exposure(dt_develop_t *dev);
/** set exposure black level */
void dt_dev_exposure_set_black(dt_develop_t *dev,
const float black);
/** get exposure black level */
float dt_dev_exposure_get_black(dt_develop_t *dev);

inline void dt_dev_exposure_handle_event(GdkEvent *event, gboolean blackwhite)
{
if(darktable.develop->proxy.exposure.handle_event)
darktable.develop->proxy.exposure.handle_event(event, blackwhite);
}

/*
* modulegroups plugin hooks
*/
Expand Down
96 changes: 39 additions & 57 deletions src/iop/exposure.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2009-2023 darktable developers.
Copyright (C) 2009-2024 darktable developers.

darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -69,12 +69,12 @@ typedef enum dt_spot_mode_t

typedef struct dt_iop_exposure_params_t
{
dt_iop_exposure_mode_t mode; // $DEFAULT: EXPOSURE_MODE_MANUAL
float black; // $MIN: -1.0 $MAX: 1.0 $DEFAULT: 0.0 $DESCRIPTION: "black level correction"
float exposure; // $MIN: -18.0 $MAX: 18.0 $DEFAULT: 0.0
float deflicker_percentile; // $MIN: 0.0 $MAX: 100.0 $DEFAULT: 50.0 $DESCRIPTION: "percentile"
float deflicker_target_level; // $MIN: -18.0 $MAX: 18.0 $DEFAULT: -4.0 $DESCRIPTION: "target level"
gboolean compensate_exposure_bias; // $DEFAULT: FALSE $DESCRIPTION: "compensate exposure bias"
dt_iop_exposure_mode_t mode; // $DEFAULT: EXPOSURE_MODE_MANUAL
float black; // $MIN: -1.0 $MAX: 1.0 $DEFAULT: 0.0 $DESCRIPTION: "black level correction"
float exposure; // $MIN: -18.0 $MAX: 18.0 $DEFAULT: 0.0
float deflicker_percentile; // $MIN: 0.0 $MAX: 100.0 $DEFAULT: 50.0 $DESCRIPTION: "percentile"
float deflicker_target_level; // $MIN: -18.0 $MAX: 18.0 $DEFAULT: -4.0 $DESCRIPTION: "target level"
gboolean compensate_exposure_bias;// $DEFAULT: FALSE $DESCRIPTION: "compensate exposure bias"
} dt_iop_exposure_params_t;

typedef struct dt_iop_exposure_gui_data_t
Expand Down Expand Up @@ -151,19 +151,9 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
return IOP_CS_RGB;
}

static void _exposure_proxy_set_exposure(dt_iop_module_t *self,
const float exposure);

static float _exposure_proxy_get_exposure(dt_iop_module_t *self);

static void _exposure_proxy_set_black(dt_iop_module_t *self,
const float black);

static float _exposure_proxy_get_black(dt_iop_module_t *self);
static void _paint_hue(dt_iop_module_t *self);

static void _exposure_set_black(dt_iop_module_t *self,
const float black);
static void _exposure_set_black(dt_iop_module_t *self, const float black);

int legacy_params(dt_iop_module_t *self,
const void *const old_params,
Expand Down Expand Up @@ -409,14 +399,12 @@ static double _raw_to_ev(const uint32_t raw,
}

static void _compute_correction(dt_iop_module_t *self,
dt_iop_params_t *p1,
dt_iop_exposure_params_t *p,
dt_dev_pixelpipe_t *pipe,
const uint32_t *const histogram,
const dt_dev_histogram_stats_t *const histogram_stats,
float *correction)
{
const dt_iop_exposure_params_t *const p = (const dt_iop_exposure_params_t *const)p1;

*correction = EXPOSURE_CORRECTION_UNDEFINED;

if(histogram == NULL) return;
Expand Down Expand Up @@ -451,7 +439,7 @@ static gboolean _show_computed(gpointer user_data);
static void _process_common_setup(dt_iop_module_t *self,
dt_dev_pixelpipe_iop_t *piece)
{
dt_iop_exposure_gui_data_t *g = (dt_iop_exposure_gui_data_t*)self->gui_data;
dt_iop_exposure_gui_data_t *g = self->gui_data;
dt_iop_exposure_data_t *d = piece->data;

d->black = d->params.black;
Expand Down Expand Up @@ -720,31 +708,6 @@ static void _exposure_set_white(dt_iop_module_t *self,
dt_dev_add_history_item(darktable.develop, self, TRUE);
}

static void _exposure_proxy_set_exposure(dt_iop_module_t *self,
const float exposure)
{
dt_iop_exposure_params_t *p = self->params;

if(p->mode == EXPOSURE_MODE_DEFLICKER)
{
dt_iop_exposure_gui_data_t *g = self->gui_data;

p->deflicker_target_level = exposure;

++darktable.gui->reset;
dt_bauhaus_slider_set(g->deflicker_target_level, p->deflicker_target_level);
--darktable.gui->reset;

dt_dev_add_history_item(darktable.develop, self, TRUE);
}
else
{
const float white = exposure2white(exposure);
_exposure_set_white(self, white);
_autoexp_disable(self);
}
}

static float _exposure_proxy_get_exposure(dt_iop_module_t *self)
{
dt_iop_exposure_params_t *p = self->params;
Expand Down Expand Up @@ -779,19 +742,39 @@ static void _exposure_set_black(dt_iop_module_t *self,
dt_dev_add_history_item(darktable.develop, self, TRUE);
}

static void _exposure_proxy_set_black(dt_iop_module_t *self,
const float black)
{
_autoexp_disable(self);
_exposure_set_black(self, black);
}

static float _exposure_proxy_get_black(dt_iop_module_t *self)
{
dt_iop_exposure_params_t *p = self->params;
return p->black;
}


static void _exposure_proxy_handle_event(GdkEvent *event, const gboolean blackwhite)
{
dt_iop_module_t *self = darktable.develop->proxy.exposure.module;
if(self && self->gui_data)
{
static gboolean black = FALSE;
if(event->type == GDK_BUTTON_PRESS || event->type == GDK_SCROLL)
black = blackwhite;

if(black)
event->button.x *= -1;

const dt_iop_exposure_params_t *p = self->params;
dt_iop_exposure_gui_data_t *g = self->gui_data;
GtkWidget *widget = black ? g->black :
p->mode == EXPOSURE_MODE_DEFLICKER
? g->deflicker_target_level : g->exposure;
gtk_widget_realize(widget);
gtk_widget_event(widget, event);

gchar *text = dt_bauhaus_slider_get_text(widget, dt_bauhaus_slider_get(widget));
dt_action_widget_toast(DT_ACTION(self), widget, "%s", text);
g_free(text);
}
}

static void _auto_set_exposure(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe)
{
dt_iop_exposure_gui_data_t *g = self->gui_data;
Expand Down Expand Up @@ -965,7 +948,7 @@ static gboolean _show_computed(gpointer user_data)

static gboolean _target_color_draw(GtkWidget *widget,
cairo_t *crf,
dt_iop_module_t *self)
const dt_iop_module_t *self)
{
dt_iop_exposure_gui_data_t *g = self->gui_data;

Expand Down Expand Up @@ -1259,10 +1242,9 @@ void gui_init(dt_iop_module_t *self)
*/
dt_dev_proxy_exposure_t *instance = &darktable.develop->proxy.exposure;
instance->module = self;
instance->set_exposure = _exposure_proxy_set_exposure;
instance->get_exposure = _exposure_proxy_get_exposure;
instance->set_black = _exposure_proxy_set_black;
instance->get_black = _exposure_proxy_get_black;
instance->handle_event = _exposure_proxy_handle_event;
}

void gui_cleanup(dt_iop_module_t *self)
Expand Down
Loading
Loading