From 3767e1032d818fc0b2846c2e149a5aaee6397f0d Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Thu, 14 Mar 2024 04:04:53 +0000 Subject: [PATCH] libgimpwidgets: Port GimpCellRendererColor... ...to use GeglColor rather than GimpRGB. Also update the ColorHexEntry, DynamicsOutputEditor, and the colormap-remap plug-in which uses this widget. --- app/widgets/gimpdynamicsoutputeditor.c | 9 ++++-- libgimpwidgets/gimpcellrenderercolor.c | 44 ++++++++++++++++++-------- libgimpwidgets/gimpcolorhexentry.c | 9 ++++-- plug-ins/common/colormap-remap.c | 12 ++----- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/app/widgets/gimpdynamicsoutputeditor.c b/app/widgets/gimpdynamicsoutputeditor.c index 2e4cbb4045..a7131f523a 100644 --- a/app/widgets/gimpdynamicsoutputeditor.c +++ b/app/widgets/gimpdynamicsoutputeditor.c @@ -215,23 +215,26 @@ gimp_dynamics_output_editor_constructed (GObject *object) G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_STRING, - GIMP_TYPE_RGB); + GEGL_TYPE_COLOR); 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, inputs[i].use_property, &use_input, 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, &private->input_iters[i], -1, INPUT_COLUMN_INDEX, i, INPUT_COLUMN_USE_INPUT, use_input, INPUT_COLUMN_NAME, gettext (inputs[i].label), - INPUT_COLUMN_COLOR, &inputs[i].color, + INPUT_COLUMN_COLOR, color, -1); + g_object_unref (color); } view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (private->input_list)); diff --git a/libgimpwidgets/gimpcellrenderercolor.c b/libgimpwidgets/gimpcellrenderercolor.c index b98e9f74af..6d679664fa 100644 --- a/libgimpwidgets/gimpcellrenderercolor.c +++ b/libgimpwidgets/gimpcellrenderercolor.c @@ -56,7 +56,7 @@ enum struct _GimpCellRendererColorPrivate { - GimpRGB color; + GeglColor *color; gboolean opaque; GtkIconSize size; gint border; @@ -65,6 +65,7 @@ struct _GimpCellRendererColorPrivate #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, guint param_id, GValue *value, @@ -101,6 +102,7 @@ gimp_cell_renderer_color_class_init (GimpCellRendererColorClass *klass) GObjectClass *object_class = G_OBJECT_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->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; g_object_class_install_property (object_class, PROP_COLOR, - g_param_spec_boxed ("color", - "Color", - "The displayed color", - GIMP_TYPE_RGB, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("color", + "Color", + "The displayed color", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, PROP_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); - 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 @@ -151,7 +164,8 @@ gimp_cell_renderer_color_get_property (GObject *object, switch (param_id) { 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; case PROP_OPAQUE: g_value_set_boolean (value, private->opaque); @@ -172,13 +186,11 @@ gimp_cell_renderer_color_set_property (GObject *object, GParamSpec *pspec) { GimpCellRendererColorPrivate *private = GET_PRIVATE (object); - GimpRGB *color; switch (param_id) { case PROP_COLOR: - color = g_value_get_boxed (value); - private->color = *color; + g_set_object (&private->color, g_value_get_object (value)); break; case PROP_OPAQUE: 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); GtkStateFlags state; GdkRGBA color; + gdouble rgba[4]; cairo_rectangle (cr, rect.x + 1, rect.y + 1, 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); - 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; @@ -298,7 +313,8 @@ gimp_cell_renderer_color_render (GtkCellRenderer *cell, 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); } diff --git a/libgimpwidgets/gimpcolorhexentry.c b/libgimpwidgets/gimpcolorhexentry.c index f8f410fa40..3abf30650d 100644 --- a/libgimpwidgets/gimpcolorhexentry.c +++ b/libgimpwidgets/gimpcolorhexentry.c @@ -137,19 +137,24 @@ gimp_color_hex_entry_init (GimpColorHexEntry *entry) 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); for (i = 0; i < num_colors; i++) { 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_set (store, &iter, COLUMN_NAME, names[i], - COLUMN_COLOR, colors + i, + COLUMN_COLOR, named_color, -1); + g_object_unref (named_color); } g_free (colors); diff --git a/plug-ins/common/colormap-remap.c b/plug-ins/common/colormap-remap.c index 6c63d1bc6d..4751812625 100644 --- a/plug-ins/common/colormap-remap.c +++ b/plug-ins/common/colormap-remap.c @@ -415,26 +415,18 @@ read_image_palette (GimpImage *image, for (index = 0; index < ncolors; ++index) { GeglColor *c = colors[index]; - gdouble r, g, b; - GimpRGB rgb; gdouble hsv[3]; 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); - gimp_rgb_set_uchar (&rgb, - ROUND (r * 255), - ROUND (g * 255), - ROUND (b * 255)); - reverse_order[index] = ncolors - index - 1; gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COLOR_INDEX, index, COLOR_INDEX_TEXT, text, - COLOR_RGB, &rgb, + COLOR_RGB, c, COLOR_H, hsv[0], COLOR_S, hsv[1], COLOR_V, hsv[2], @@ -616,7 +608,7 @@ remap_dialog (GimpProcedure *procedure, gimp_window_set_transient (GTK_WINDOW (dialog)); 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); if (! read_image_palette (image, &ncolors))