mirror of https://github.com/GNOME/gimp.git
libgimpwidgets: don't unnecessarily redraw color previews.
When changing the selected color, we have no reason to redraw the Z preview. This preview should only be redrawn if the allocation size changed, or if we change the previewed model or the Z component. As for the XY preview, it should only be redrawn if the Z value is changed (and of course, similarly, if the allocation changed or if model or Z component changed).
This commit is contained in:
parent
3a787e8892
commit
89b80b5b63
|
@ -149,6 +149,7 @@ struct _GimpColorSelect
|
||||||
gboolean z_needs_render;
|
gboolean z_needs_render;
|
||||||
|
|
||||||
gdouble pos[3];
|
gdouble pos[3];
|
||||||
|
gfloat z_value;
|
||||||
|
|
||||||
ColorSelectDragMode drag_mode;
|
ColorSelectDragMode drag_mode;
|
||||||
|
|
||||||
|
@ -192,8 +193,7 @@ static void gimp_color_select_set_color (GimpColorSelector *selec
|
||||||
GeglColor *color);
|
GeglColor *color);
|
||||||
static void gimp_color_select_set_channel (GimpColorSelector *selector,
|
static void gimp_color_select_set_channel (GimpColorSelector *selector,
|
||||||
GimpColorSelectorChannel channel);
|
GimpColorSelectorChannel channel);
|
||||||
static void gimp_color_select_set_model_visible
|
static void gimp_color_select_set_model_visible (GimpColorSelector *selector,
|
||||||
(GimpColorSelector *selector,
|
|
||||||
GimpColorSelectorModel model,
|
GimpColorSelectorModel model,
|
||||||
gboolean visible);
|
gboolean visible);
|
||||||
static void gimp_color_select_set_format (GimpColorSelector *selector,
|
static void gimp_color_select_set_format (GimpColorSelector *selector,
|
||||||
|
@ -279,6 +279,9 @@ static void gimp_color_select_notify_config (GimpColorConfig *config,
|
||||||
const GParamSpec *pspec,
|
const GParamSpec *pspec,
|
||||||
GimpColorSelect *select);
|
GimpColorSelect *select);
|
||||||
|
|
||||||
|
static gfloat gimp_color_select_get_z_value (GimpColorSelect *select,
|
||||||
|
GeglColor *color);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpColorSelect, gimp_color_select, GIMP_TYPE_COLOR_SELECTOR)
|
G_DEFINE_TYPE (GimpColorSelect, gimp_color_select, GIMP_TYPE_COLOR_SELECTOR)
|
||||||
|
|
||||||
|
@ -367,6 +370,7 @@ gimp_color_select_init (GimpColorSelect *select)
|
||||||
GSList *group = NULL;
|
GSList *group = NULL;
|
||||||
|
|
||||||
/* Default values. */
|
/* Default values. */
|
||||||
|
select->z_value = G_MINFLOAT;
|
||||||
select->z_color_fill = COLOR_SELECT_HUE;
|
select->z_color_fill = COLOR_SELECT_HUE;
|
||||||
select->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
|
select->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
|
||||||
select->drag_mode = DRAG_NONE;
|
select->drag_mode = DRAG_NONE;
|
||||||
|
@ -575,9 +579,22 @@ gimp_color_select_set_color (GimpColorSelector *selector,
|
||||||
GeglColor *color)
|
GeglColor *color)
|
||||||
{
|
{
|
||||||
GimpColorSelect *select = GIMP_COLOR_SELECT (selector);
|
GimpColorSelect *select = GIMP_COLOR_SELECT (selector);
|
||||||
|
ColorSelectUpdateType update_flags = UPDATE_POS;
|
||||||
|
gfloat z_value;
|
||||||
|
|
||||||
gimp_color_select_update (select,
|
z_value = gimp_color_select_get_z_value (select, color);
|
||||||
UPDATE_POS | UPDATE_XY_COLOR | UPDATE_Z_COLOR);
|
|
||||||
|
/* Note: we are not comparing full colors, hence not using
|
||||||
|
* gimp_color_is_perceptually_identical(). It's more of a quick comparison on
|
||||||
|
* whether the Z channel is different enough that we'd want to redraw the XY
|
||||||
|
* preview too.
|
||||||
|
*/
|
||||||
|
#define GIMP_RGBA_EPSILON 1e-4
|
||||||
|
if (fabs (z_value - select->z_value) > GIMP_RGBA_EPSILON)
|
||||||
|
update_flags |= UPDATE_XY_COLOR;
|
||||||
|
#undef GIMP_RGBA_EPSILON
|
||||||
|
|
||||||
|
gimp_color_select_update (select, update_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1084,6 +1101,7 @@ gimp_color_select_xy_draw (GtkWidget *widget,
|
||||||
select->xy_color_fill,
|
select->xy_color_fill,
|
||||||
color,
|
color,
|
||||||
select->oog_color);
|
select->oog_color);
|
||||||
|
select->z_value = gimp_color_select_get_z_value (select, color);
|
||||||
select->xy_needs_render = FALSE;
|
select->xy_needs_render = FALSE;
|
||||||
|
|
||||||
g_object_unref (color);
|
g_object_unref (color);
|
||||||
|
@ -1991,3 +2009,43 @@ gimp_color_select_notify_config (GimpColorConfig *config,
|
||||||
|
|
||||||
g_object_unref (color);
|
g_object_unref (color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gfloat
|
||||||
|
gimp_color_select_get_z_value (GimpColorSelect *select,
|
||||||
|
GeglColor *color)
|
||||||
|
{
|
||||||
|
gint z_channel = -1;
|
||||||
|
gfloat channels[3];
|
||||||
|
|
||||||
|
switch (select->z_color_fill)
|
||||||
|
{
|
||||||
|
case COLOR_SELECT_RED:
|
||||||
|
z_channel = 0;
|
||||||
|
case COLOR_SELECT_GREEN:
|
||||||
|
z_channel = (z_channel > -1) ? z_channel : 1;
|
||||||
|
case COLOR_SELECT_BLUE:
|
||||||
|
z_channel = (z_channel > -1) ? z_channel : 2;
|
||||||
|
gegl_color_get_pixel (color, rgbf_format, channels);
|
||||||
|
break;
|
||||||
|
case COLOR_SELECT_HUE:
|
||||||
|
z_channel = 0;
|
||||||
|
case COLOR_SELECT_SATURATION:
|
||||||
|
z_channel = (z_channel > -1) ? z_channel : 1;
|
||||||
|
case COLOR_SELECT_VALUE:
|
||||||
|
z_channel = (z_channel > -1) ? z_channel : 2;
|
||||||
|
gegl_color_get_pixel (color, hsvf_format, channels);
|
||||||
|
break;
|
||||||
|
case COLOR_SELECT_LCH_LIGHTNESS:
|
||||||
|
z_channel = 0;
|
||||||
|
case COLOR_SELECT_LCH_CHROMA:
|
||||||
|
z_channel = (z_channel > -1) ? z_channel : 1;
|
||||||
|
case COLOR_SELECT_LCH_HUE:
|
||||||
|
z_channel = (z_channel > -1) ? z_channel : 2;
|
||||||
|
gegl_color_get_pixel (color, babl_format ("CIE LCH(ab) float"), channels);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_return_val_if_reached (G_MINFLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return channels[z_channel];
|
||||||
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@
|
||||||
#ifndef __GIMP_WIDGETS_PRIVATE_H__
|
#ifndef __GIMP_WIDGETS_PRIVATE_H__
|
||||||
#define __GIMP_WIDGETS_PRIVATE_H__
|
#define __GIMP_WIDGETS_PRIVATE_H__
|
||||||
|
|
||||||
/* Used to compare similar colors across several widgets. */
|
|
||||||
#define GIMP_RGBA_EPSILON 1e-6
|
|
||||||
|
|
||||||
|
|
||||||
typedef GeglColor * (* GimpGetColorFunc) (void);
|
typedef GeglColor * (* GimpGetColorFunc) (void);
|
||||||
typedef void (* GimpEnsureModulesFunc) (void);
|
typedef void (* GimpEnsureModulesFunc) (void);
|
||||||
|
|
Loading…
Reference in New Issue