libgimpwidgets: Port GimpCellRendererColor...

...to use GeglColor rather than GimpRGB.
Also update the ColorHexEntry,
DynamicsOutputEditor, and the
colormap-remap plug-in which uses this
widget.
This commit is contained in:
Alx Sa 2024-03-14 04:04:53 +00:00 committed by Idriss Fekir
parent 917506d16e
commit 3767e1032d
4 changed files with 45 additions and 29 deletions

View File

@ -215,23 +215,26 @@ gimp_dynamics_output_editor_constructed (GObject *object)
G_TYPE_INT, G_TYPE_INT,
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
G_TYPE_STRING, G_TYPE_STRING,
GIMP_TYPE_RGB); GEGL_TYPE_COLOR);
for (i = 0; i < G_N_ELEMENTS (inputs); i++) for (i = 0; i < G_N_ELEMENTS (inputs); i++)
{ {
gboolean use_input; gboolean use_input;
GeglColor *color = gegl_color_new ("black");
g_object_get (private->output, g_object_get (private->output,
inputs[i].use_property, &use_input, inputs[i].use_property, &use_input,
NULL); NULL);
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), inputs[i].color);
gtk_list_store_insert_with_values (private->input_list, gtk_list_store_insert_with_values (private->input_list,
&private->input_iters[i], -1, &private->input_iters[i], -1,
INPUT_COLUMN_INDEX, i, INPUT_COLUMN_INDEX, i,
INPUT_COLUMN_USE_INPUT, use_input, INPUT_COLUMN_USE_INPUT, use_input,
INPUT_COLUMN_NAME, gettext (inputs[i].label), INPUT_COLUMN_NAME, gettext (inputs[i].label),
INPUT_COLUMN_COLOR, &inputs[i].color, INPUT_COLUMN_COLOR, color,
-1); -1);
g_object_unref (color);
} }
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (private->input_list)); view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (private->input_list));

View File

@ -56,7 +56,7 @@ enum
struct _GimpCellRendererColorPrivate struct _GimpCellRendererColorPrivate
{ {
GimpRGB color; GeglColor *color;
gboolean opaque; gboolean opaque;
GtkIconSize size; GtkIconSize size;
gint border; gint border;
@ -65,6 +65,7 @@ struct _GimpCellRendererColorPrivate
#define GET_PRIVATE(obj) (((GimpCellRendererColor *) (obj))->priv) #define GET_PRIVATE(obj) (((GimpCellRendererColor *) (obj))->priv)
static void gimp_cell_renderer_color_finalize (GObject *object);
static void gimp_cell_renderer_color_get_property (GObject *object, static void gimp_cell_renderer_color_get_property (GObject *object,
guint param_id, guint param_id,
GValue *value, GValue *value,
@ -101,6 +102,7 @@ gimp_cell_renderer_color_class_init (GimpCellRendererColorClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
object_class->finalize = gimp_cell_renderer_color_finalize;
object_class->get_property = gimp_cell_renderer_color_get_property; object_class->get_property = gimp_cell_renderer_color_get_property;
object_class->set_property = gimp_cell_renderer_color_set_property; object_class->set_property = gimp_cell_renderer_color_set_property;
@ -108,11 +110,12 @@ gimp_cell_renderer_color_class_init (GimpCellRendererColorClass *klass)
cell_class->render = gimp_cell_renderer_color_render; cell_class->render = gimp_cell_renderer_color_render;
g_object_class_install_property (object_class, PROP_COLOR, g_object_class_install_property (object_class, PROP_COLOR,
g_param_spec_boxed ("color", gegl_param_spec_color ("color",
"Color", "Color",
"The displayed color", "The displayed color",
GIMP_TYPE_RGB, NULL,
GIMP_PARAM_READWRITE)); G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_OPAQUE, g_object_class_install_property (object_class, PROP_OPAQUE,
g_param_spec_boolean ("opaque", g_param_spec_boolean ("opaque",
@ -137,7 +140,17 @@ gimp_cell_renderer_color_init (GimpCellRendererColor *cell)
{ {
cell->priv = gimp_cell_renderer_color_get_instance_private (cell); cell->priv = gimp_cell_renderer_color_get_instance_private (cell);
gimp_rgba_set (&cell->priv->color, 0.0, 0.0, 0.0, 1.0); cell->priv->color = gegl_color_new ("black");
}
static void
gimp_cell_renderer_color_finalize (GObject *object)
{
GimpCellRendererColorPrivate *private = GET_PRIVATE (object);
g_clear_object (&private->color);
G_OBJECT_CLASS (parent_class)->finalize (object);
} }
static void static void
@ -151,7 +164,8 @@ gimp_cell_renderer_color_get_property (GObject *object,
switch (param_id) switch (param_id)
{ {
case PROP_COLOR: case PROP_COLOR:
g_value_set_boxed (value, &private->color); g_clear_object (&private->color);
private->color = gegl_color_duplicate (g_value_get_object (value));
break; break;
case PROP_OPAQUE: case PROP_OPAQUE:
g_value_set_boolean (value, private->opaque); g_value_set_boolean (value, private->opaque);
@ -172,13 +186,11 @@ gimp_cell_renderer_color_set_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpCellRendererColorPrivate *private = GET_PRIVATE (object); GimpCellRendererColorPrivate *private = GET_PRIVATE (object);
GimpRGB *color;
switch (param_id) switch (param_id)
{ {
case PROP_COLOR: case PROP_COLOR:
color = g_value_get_boxed (value); g_set_object (&private->color, g_value_get_object (value));
private->color = *color;
break; break;
case PROP_OPAQUE: case PROP_OPAQUE:
private->opaque = g_value_get_boolean (value); private->opaque = g_value_get_boolean (value);
@ -273,15 +285,18 @@ gimp_cell_renderer_color_render (GtkCellRenderer *cell,
GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStyleContext *context = gtk_widget_get_style_context (widget);
GtkStateFlags state; GtkStateFlags state;
GdkRGBA color; GdkRGBA color;
gdouble rgba[4];
cairo_rectangle (cr, cairo_rectangle (cr,
rect.x + 1, rect.y + 1, rect.x + 1, rect.y + 1,
rect.width - 2, rect.height - 2); rect.width - 2, rect.height - 2);
gimp_cairo_set_source_rgb (cr, &private->color); gimp_cairo_set_source_color (cr, private->color, NULL, FALSE,
widget);
cairo_fill (cr); cairo_fill (cr);
if (! private->opaque && private->color.a < 1.0) gegl_color_get_pixel (private->color, babl_format ("R'G'B'A double"), rgba);
if (! private->opaque && rgba[3] < 1.0)
{ {
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
@ -298,7 +313,8 @@ gimp_cell_renderer_color_render (GtkCellRenderer *cell,
cairo_fill_preserve (cr); cairo_fill_preserve (cr);
gimp_cairo_set_source_rgba (cr, &private->color); gimp_cairo_set_source_color (cr, private->color, NULL, FALSE,
widget);
cairo_fill (cr); cairo_fill (cr);
} }

View File

@ -137,19 +137,24 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry)
private->color = gegl_color_new ("black"); private->color = gegl_color_new ("black");
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GIMP_TYPE_RGB); store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, GEGL_TYPE_COLOR);
gimp_rgb_list_names (&names, &colors, &num_colors); gimp_rgb_list_names (&names, &colors, &num_colors);
for (i = 0; i < num_colors; i++) for (i = 0; i < num_colors; i++)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GeglColor *named_color = gegl_color_new ("black");
gegl_color_set_rgba_with_space (named_color, colors[i].r, colors[i].g,
colors[i].b, colors[i].a, NULL);
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
COLUMN_NAME, names[i], COLUMN_NAME, names[i],
COLUMN_COLOR, colors + i, COLUMN_COLOR, named_color,
-1); -1);
g_object_unref (named_color);
} }
g_free (colors); g_free (colors);

View File

@ -415,26 +415,18 @@ read_image_palette (GimpImage *image,
for (index = 0; index < ncolors; ++index) for (index = 0; index < ncolors; ++index)
{ {
GeglColor *c = colors[index]; GeglColor *c = colors[index];
gdouble r, g, b;
GimpRGB rgb;
gdouble hsv[3]; gdouble hsv[3];
gchar *text = g_strdup_printf ("%d", index); gchar *text = g_strdup_printf ("%d", index);
gegl_color_get_rgba (c, &r, &g, &b, NULL);
gegl_color_get_pixel (c, babl_format ("HSV double"), hsv); gegl_color_get_pixel (c, babl_format ("HSV double"), hsv);
gimp_rgb_set_uchar (&rgb,
ROUND (r * 255),
ROUND (g * 255),
ROUND (b * 255));
reverse_order[index] = ncolors - index - 1; reverse_order[index] = ncolors - index - 1;
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
COLOR_INDEX, index, COLOR_INDEX, index,
COLOR_INDEX_TEXT, text, COLOR_INDEX_TEXT, text,
COLOR_RGB, &rgb, COLOR_RGB, c,
COLOR_H, hsv[0], COLOR_H, hsv[0],
COLOR_S, hsv[1], COLOR_S, hsv[1],
COLOR_V, hsv[2], COLOR_V, hsv[2],
@ -616,7 +608,7 @@ remap_dialog (GimpProcedure *procedure,
gimp_window_set_transient (GTK_WINDOW (dialog)); gimp_window_set_transient (GTK_WINDOW (dialog));
store = gtk_list_store_new (NUM_COLS, store = gtk_list_store_new (NUM_COLS,
G_TYPE_INT, G_TYPE_STRING, GIMP_TYPE_RGB, G_TYPE_INT, G_TYPE_STRING, GEGL_TYPE_COLOR,
G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE); G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
if (! read_image_palette (image, &ncolors)) if (! read_image_palette (image, &ncolors))