Commit 1ebb2b36 authored by Roman Lebedev's avatar Roman Lebedev

DTGTK Gradient Slider: cleanup: GdkColor -> GdkRGBA

NOTE: this results in slightly different color of blendifs and in relight iop.

This is because before max value was 32768 when it should have been 65535,
see https://developer.gnome.org/gdk3/stable/gdk3-Colors.html#GdkColor
parent 88438064
......@@ -290,7 +290,7 @@ typedef struct dt_blendop_t
typedef struct dt_iop_gui_blendif_colorstop_t
{
float stoppoint;
GdkColor color;
GdkRGBA color;
} dt_iop_gui_blendif_colorstop_t;
......
......@@ -43,7 +43,7 @@
#define CLAMP_RANGE(x, y, z) (CLAMP(x, y, z))
#define LIGHTNESS 32767.0f
#define LIGHTNESS 1.0
typedef enum _iop_gui_blendif_channel_t
{
......@@ -60,55 +60,58 @@ typedef enum _iop_gui_blendif_channel_t
static const dt_iop_gui_blendif_colorstop_t _gradient_L[]
= { { 0.0f, { 0, 0, 0, 0 } },
{ 0.5f, { 0, LIGHTNESS / 2, LIGHTNESS / 2, LIGHTNESS / 2 } },
{ 1.0f, { 0, LIGHTNESS, LIGHTNESS, LIGHTNESS } } };
= { { 0.0f, { 0, 0, 0, 1.0 } },
{ 0.5f, { LIGHTNESS / 2, LIGHTNESS / 2, LIGHTNESS / 2, 1.0 } },
{ 1.0f, { LIGHTNESS, LIGHTNESS, LIGHTNESS, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_a[]
= { { 0.0f, { 0, 0, 0.34 * LIGHTNESS * 2, 0.27 * LIGHTNESS * 2 } },
{ 0.5f, { 0, LIGHTNESS, LIGHTNESS, LIGHTNESS } },
{ 1.0f, { 0, 0.53 * LIGHTNESS * 2, 0.08 * LIGHTNESS * 2, 0.28 * LIGHTNESS * 2 } } };
= { { 0.0f, { 0, 0.34 * LIGHTNESS * 2, 0.27 * LIGHTNESS * 2, 1.0 } },
{ 0.5f, { LIGHTNESS, LIGHTNESS, LIGHTNESS, 1.0 } },
{ 1.0f, { 0.53 * LIGHTNESS * 2, 0.08 * LIGHTNESS * 2, 0.28 * LIGHTNESS * 2, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_b[]
= { { 0.0f, { 0, 0, 0.27 * LIGHTNESS * 2, 0.58 * LIGHTNESS * 2 } },
{ 0.5f, { 0, LIGHTNESS, LIGHTNESS, LIGHTNESS } },
{ 1.0f, { 0, 0.81 * LIGHTNESS * 2, 0.66 * LIGHTNESS * 2, 0 } } };
= { { 0.0f, { 0, 0.27 * LIGHTNESS * 2, 0.58 * LIGHTNESS * 2, 1.0 } },
{ 0.5f, { LIGHTNESS, LIGHTNESS, LIGHTNESS, 1.0 } },
{ 1.0f, { 0.81 * LIGHTNESS * 2, 0.66 * LIGHTNESS * 2, 0, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_gray[]
= { { 0.0f, { 0, 0, 0, 0 } },
{ 0.5f, { 0, LIGHTNESS / 2, LIGHTNESS / 2, LIGHTNESS / 2 } },
{ 1.0f, { 0, LIGHTNESS, LIGHTNESS, LIGHTNESS } } };
= { { 0.0f, { 0, 0, 0, 1.0 } },
{ 0.5f, { LIGHTNESS / 2, LIGHTNESS / 2, LIGHTNESS / 2, 1.0 } },
{ 1.0f, { LIGHTNESS, LIGHTNESS, LIGHTNESS, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_red[]
= { { 0.0f, { 0, 0, 0, 0 } }, { 0.5f, { 0, LIGHTNESS / 2, 0, 0 } }, { 1.0f, { 0, LIGHTNESS, 0, 0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_red[] = { { 0.0f, { 0, 0, 0, 1.0 } },
{ 0.5f, { LIGHTNESS / 2, 0, 0, 1.0 } },
{ 1.0f, { LIGHTNESS, 0, 0, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_green[]
= { { 0.0f, { 0, 0, 0, 0 } }, { 0.5f, { 0, 0, LIGHTNESS / 2, 0 } }, { 1.0f, { 0, 0, LIGHTNESS, 0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_green[] = { { 0.0f, { 0, 0, 0, 1.0 } },
{ 0.5f, { 0, LIGHTNESS / 2, 0, 1.0 } },
{ 1.0f, { 0, LIGHTNESS, 0, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_blue[]
= { { 0.0f, { 0, 0, 0, 0 } }, { 0.5f, { 0, 0, 0, LIGHTNESS / 2 } }, { 1.0f, { 0, 0, 0, LIGHTNESS } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_blue[] = { { 0.0f, { 0, 0, 0, 1.0 } },
{ 0.5f, { 0, 0, LIGHTNESS / 2, 1.0 } },
{ 1.0f, { 0, 0, LIGHTNESS, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_chroma[]
= { { 0.0f, { 0, LIGHTNESS, LIGHTNESS, LIGHTNESS } },
{ 0.5f, { 0, LIGHTNESS, LIGHTNESS / 2, LIGHTNESS } },
{ 1.0f, { 0, LIGHTNESS, 0, LIGHTNESS } } };
= { { 0.0f, { LIGHTNESS, LIGHTNESS, LIGHTNESS, 1.0 } },
{ 0.5f, { LIGHTNESS, LIGHTNESS / 2, LIGHTNESS, 1.0 } },
{ 1.0f, { LIGHTNESS, 0, LIGHTNESS, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_hue[]
= { { 0.0f, { 0, 1.00f * 1.5f * LIGHTNESS, 0.68f * 1.5f * LIGHTNESS, 0.78f * 1.5f * LIGHTNESS } },
{ 0.166f, { 0, 0.95f * 1.5f * LIGHTNESS, 0.73f * 1.5f * LIGHTNESS, 0.56f * 1.5f * LIGHTNESS } },
{ 0.333f, { 0, 0.71f * 1.5f * LIGHTNESS, 0.81f * 1.5f * LIGHTNESS, 0.55f * 1.5f * LIGHTNESS } },
{ 0.500f, { 0, 0.45f * 1.5f * LIGHTNESS, 0.85f * 1.5f * LIGHTNESS, 0.77f * 1.5f * LIGHTNESS } },
{ 0.666f, { 0, 0.49f * 1.5f * LIGHTNESS, 0.82f * 1.5f * LIGHTNESS, 1.00f * 1.5f * LIGHTNESS } },
{ 0.833f, { 0, 0.82f * 1.5f * LIGHTNESS, 0.74f * 1.5f * LIGHTNESS, 1.00f * 1.5f * LIGHTNESS } },
{ 1.0f, { 0, 1.00f * 1.5f * LIGHTNESS, 0.68f * 1.5f * LIGHTNESS, 0.78f * 1.5f * LIGHTNESS } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_HUE[] = { { 0.0f, { 0, LIGHTNESS, 0, 0 } },
{ 0.166f, { 0, LIGHTNESS, LIGHTNESS, 0 } },
{ 0.332f, { 0, 0, LIGHTNESS, 0 } },
{ 0.498f, { 0, 0, LIGHTNESS, LIGHTNESS } },
{ 0.664f, { 0, 0, 0, LIGHTNESS } },
{ 0.830f, { 0, LIGHTNESS, 0, LIGHTNESS } },
{ 1.0f, { 0, LIGHTNESS, 0, 0 } } };
= { { 0.0f, { 1.00f * 1.5f * LIGHTNESS, 0.68f * 1.5f * LIGHTNESS, 0.78f * 1.5f * LIGHTNESS, 1.0 } },
{ 0.166f, { 0.95f * 1.5f * LIGHTNESS, 0.73f * 1.5f * LIGHTNESS, 0.56f * 1.5f * LIGHTNESS, 1.0 } },
{ 0.333f, { 0.71f * 1.5f * LIGHTNESS, 0.81f * 1.5f * LIGHTNESS, 0.55f * 1.5f * LIGHTNESS, 1.0 } },
{ 0.500f, { 0.45f * 1.5f * LIGHTNESS, 0.85f * 1.5f * LIGHTNESS, 0.77f * 1.5f * LIGHTNESS, 1.0 } },
{ 0.666f, { 0.49f * 1.5f * LIGHTNESS, 0.82f * 1.5f * LIGHTNESS, 1.00f * 1.5f * LIGHTNESS, 1.0 } },
{ 0.833f, { 0.82f * 1.5f * LIGHTNESS, 0.74f * 1.5f * LIGHTNESS, 1.00f * 1.5f * LIGHTNESS, 1.0 } },
{ 1.0f, { 1.00f * 1.5f * LIGHTNESS, 0.68f * 1.5f * LIGHTNESS, 0.78f * 1.5f * LIGHTNESS, 1.0 } } };
static const dt_iop_gui_blendif_colorstop_t _gradient_HUE[] = { { 0.0f, { LIGHTNESS, 0, 0, 1.0 } },
{ 0.166f, { LIGHTNESS, LIGHTNESS, 0, 1.0 } },
{ 0.332f, { 0, LIGHTNESS, 0, 1.0 } },
{ 0.498f, { 0, LIGHTNESS, LIGHTNESS, 1.0 } },
{ 0.664f, { 0, 0, LIGHTNESS, 1.0 } },
{ 0.830f, { LIGHTNESS, 0, LIGHTNESS, 1.0 } },
{ 1.0f, { LIGHTNESS, 0, 0, 1.0 } } };
static inline void _RGB_2_HSL(const float *RGB, float *HSL)
......
......@@ -428,8 +428,8 @@ static gboolean _gradient_slider_draw(GtkWidget *widget, cairo_t *cr)
do
{
_gradient_slider_stop_t *stop = (_gradient_slider_stop_t *)current->data;
cairo_pattern_add_color_stop_rgb(gradient, stop->position, stop->color.red / 65535.0,
stop->color.green / 65535.0, stop->color.blue / 65535.0);
cairo_pattern_add_color_stop_rgb(gradient, stop->position, stop->color.red, stop->color.green,
stop->color.blue);
} while((current = g_list_next(current)) != NULL);
}
......@@ -545,7 +545,7 @@ GtkWidget *dtgtk_gradient_slider_multivalue_new(gint positions)
}
GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkColor start, GdkColor end, gint positions)
GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkRGBA start, GdkRGBA end, gint positions)
{
assert(positions <= GRADIENT_SLIDER_MAX_POSITIONS);
......@@ -567,13 +567,13 @@ GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkColor start, GdkCo
// Construct gradient start color
_gradient_slider_stop_t *gc = (_gradient_slider_stop_t *)g_malloc(sizeof(_gradient_slider_stop_t));
gc->position = 0.0;
memcpy(&gc->color, &start, sizeof(GdkColor));
memcpy(&gc->color, &start, sizeof(GdkRGBA));
gslider->colors = g_list_append(gslider->colors, gc);
// Construct gradient stop color
gc = (_gradient_slider_stop_t *)g_malloc(sizeof(_gradient_slider_stop_t));
gc->position = 1.0;
memcpy(&gc->color, &end, sizeof(GdkColor));
memcpy(&gc->color, &end, sizeof(GdkRGBA));
gslider->colors = g_list_append(gslider->colors, gc);
......@@ -589,20 +589,20 @@ gint _list_find_by_position(gconstpointer a, gconstpointer b)
}
void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position,
GdkColor color)
GdkRGBA color)
{
// First find color at position, if exists update color, otherwise create a new stop at position.
GList *current = g_list_find_custom(gslider->colors, (gpointer)&position, _list_find_by_position);
if(current != NULL)
{
memcpy(&((_gradient_slider_stop_t *)current->data)->color, &color, sizeof(GdkColor));
memcpy(&((_gradient_slider_stop_t *)current->data)->color, &color, sizeof(GdkRGBA));
}
else
{
// stop didn't exist lets add it
_gradient_slider_stop_t *gc = (_gradient_slider_stop_t *)g_malloc(sizeof(_gradient_slider_stop_t));
gc->position = position;
memcpy(&gc->color, &color, sizeof(GdkColor));
memcpy(&gc->color, &color, sizeof(GdkRGBA));
gslider->colors = g_list_append(gslider->colors, gc);
}
}
......@@ -720,12 +720,12 @@ GtkWidget *dtgtk_gradient_slider_new()
return dtgtk_gradient_slider_multivalue_new(1);
}
GtkWidget *dtgtk_gradient_slider_new_with_color(GdkColor start, GdkColor end)
GtkWidget *dtgtk_gradient_slider_new_with_color(GdkRGBA start, GdkRGBA end)
{
return dtgtk_gradient_slider_multivalue_new_with_color(start, end, 1);
}
void dtgtk_gradient_slider_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkColor color)
void dtgtk_gradient_slider_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkRGBA color)
{
dtgtk_gradient_slider_multivalue_set_stop(gslider, position, color);
}
......
......@@ -109,7 +109,7 @@ typedef struct _GtkDarktableGradientSliderClass
typedef struct _gradient_slider_stop_t
{
gdouble position;
GdkColor color;
GdkRGBA color;
} _gradient_slider_stop_t;
......@@ -118,10 +118,10 @@ GType dtgtk_gradient_slider_multivalue_get_type(void);
/** Instansiate a new darktable gradient slider control */
GtkWidget *dtgtk_gradient_slider_new();
GtkWidget *dtgtk_gradient_slider_new_with_color(GdkColor start, GdkColor end);
GtkWidget *dtgtk_gradient_slider_new_with_color(GdkRGBA start, GdkRGBA end);
/** Set a color at specified stop */
void dtgtk_gradient_slider_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkColor color);
void dtgtk_gradient_slider_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkRGBA color);
/** Clear all stops */
void dtgtk_gradient_slider_multivalue_clear_stops(GtkDarktableGradientSlider *gslider);
......@@ -151,11 +151,11 @@ void dtgtk_gradient_slider_set_increment(GtkDarktableGradientSlider *gslider, gd
/** Instansiate a new darktable gradient slider multivalue control */
GtkWidget *dtgtk_gradient_slider_multivalue_new(gint positions);
GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkColor start, GdkColor end, gint positions);
GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkRGBA start, GdkRGBA end, gint positions);
/** Set a color at specified stop for multivalue control */
void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position,
GdkColor color);
GdkRGBA color);
/** Get the slider value 0 - 1.0 for multivalue control */
gdouble dtgtk_gradient_slider_multivalue_get_value(GtkDarktableGradientSlider *gslider, gint position);
......
......@@ -286,7 +286,7 @@ colorpick_callback (GtkDarktableButton *button, gpointer user_data)
G_CALLBACK (colorpick_button_callback), csd);
GtkColorSelection *cs = GTK_COLOR_SELECTION(gtk_color_selection_dialog_get_color_selection(csd));
GdkColor c;
GdkRGBA c;
float color[3],h,s,l;
h = p->hue;
......@@ -294,18 +294,18 @@ colorpick_callback (GtkDarktableButton *button, gpointer user_data)
l=0.5;
hsl2rgb(color,h,s,l);
c.red= 65535 * color[0];
c.green= 65535 * color[1];
c.blue= 65535 * color[2];
c.red = color[0];
c.green = color[1];
c.blue = color[2];
gtk_color_selection_set_current_color(cs,&c);
if(gtk_dialog_run(GTK_DIALOG(csd))==GTK_RESPONSE_ACCEPT)
{
gtk_color_selection_get_current_color(cs,&c);
color[0]=c.red/65535.0;
color[1]=c.green/65535.0;
color[2]=c.blue/65535.0;
color[0] = c.red;
color[1] = c.green;
color[2] = c.blue;
rgb2hsl(color,&h,&s,&l);
l=0.5;
hsl2rgb(color,h,s,l);
......@@ -399,10 +399,10 @@ void gui_update(struct dt_iop_module_t *self)
float color[3];
hsl2rgb(color,p->hue,p->saturation,0.5);
GdkColor c;
c.red=color[0]*65535.0;
c.green=color[1]*65535.0;
c.blue=color[2]*65535.0;
GdkRGBA c;
c.red = color[0];
c.green = color[1];
c.blue = color[2];
gtk_widget_modify_fg(GTK_WIDGET(g->colorpick1),GTK_STATE_NORMAL,&c);
#endif
......
......@@ -383,9 +383,9 @@ void gui_init(struct dt_iop_module_t *self)
/* lightnessslider */
GtkBox *hbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2));
int lightness = 32768;
gdouble lightness = 1.0;
g->gslider1 = DTGTK_GRADIENT_SLIDER(dtgtk_gradient_slider_new_with_color(
(GdkColor){ 0, 0, 0, 0 }, (GdkColor){ 0, lightness, lightness, lightness }));
(GdkRGBA){ 0.0, 0.0, 0.0, 1.0 }, (GdkRGBA){ lightness, lightness, lightness, 1.0 }));
g_object_set(G_OBJECT(g->gslider1), "tooltip-text", _("select the center of fill-light"), (char *)NULL);
g_signal_connect(G_OBJECT(g->gslider1), "value-changed", G_CALLBACK(center_callback), self);
g->tbutton1 = DTGTK_TOGGLEBUTTON(dtgtk_togglebutton_new(dtgtk_cairo_paint_colorpicker, CPF_STYLE_FLAT));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment