From dbbcfb16d56c147ace1a8abeaaa8520dcb888e26 Mon Sep 17 00:00:00 2001 From: Jehan Date: Tue, 14 Nov 2023 20:04:14 +0100 Subject: [PATCH] app, libgimp*, pdb, plug-ins: GimpContext is now using only GeglColor. - app: gimp_context_get_(foreground|background)() are now returning a GeglColor. - libgimp: PDB functions named similarly in libgimp are returning a newly allocated GeglColor too. - A few other PDB functions (the ones using these functions) were updated and their signature changed to use GeglColor too, when relevant. Plug-ins which use any of the changed libgimp functions were fixed. - GimpContext: signals "(foreground|background)-changed" are now passing a GeglColor. - libgimpconfig: new macro GIMP_CONFIG_PROP_COLOR using gegl_param_spec_color(). - GimpContext: properties "foreground" and "background" are now GeglParamColor properties. - app: All code interacting with GimpContext objects were updated to receive a GeglColor (that they may still convert, or no, to GimpRGB for now). - app: gimp_prop_gegl_color_button_new() was added as an alternative to gimp_prop_color_button_new() when the property is a GeglParamColor. Eventually the former should replace completely the latter. - libgimpwidgets: gimp_prop_color_area_new() now works on GeglParamColor properties only. - libgimp: gimp_procedure_dialog_get_widget() will generate a GimpColorArea for GeglTypeParamColor arguments. --- app/actions/colormap-actions.c | 8 +- app/actions/colormap-commands.c | 11 +- app/actions/context-commands.c | 191 ++++++++++++++--------- app/actions/edit-actions.c | 28 ++-- app/actions/gradient-editor-actions.c | 8 +- app/actions/gradient-editor-commands.c | 36 +++-- app/actions/palette-editor-actions.c | 8 +- app/actions/palette-editor-commands.c | 10 +- app/core/gimp-utils.c | 21 ++- app/core/gimpcontext.c | 105 +++++-------- app/core/gimpcontext.h | 10 +- app/core/gimpdrawable-bucket-fill.c | 8 +- app/core/gimpdrawable-transform.c | 30 ++-- app/core/gimpfilloptions.c | 56 +++---- app/core/gimpgradient.c | 19 ++- app/core/gimpimage-merge.c | 6 +- app/core/gimplayer.c | 4 +- app/display/gimpcanvaspen.c | 14 +- app/display/gimpdisplayshell-dnd.c | 11 +- app/gui/gui.c | 90 +++++------ app/operations/gimpoperationoffset.c | 10 +- app/paint/gimperaser.c | 10 +- app/paint/gimpink.c | 17 +- app/paint/gimpmybrushcore.c | 11 +- app/paint/gimppaintbrush.c | 11 +- app/paint/gimpsmudge.c | 13 +- app/pdb/context-cmds.c | 38 +++-- app/pdb/plug-in-compat-cmds.c | 189 ++++++++++------------ app/pdb/text-layer-cmds.c | 11 +- app/text/gimptext-compat.c | 8 +- app/tools/gimpoperationtool.c | 19 ++- app/tools/gimptextoptions.c | 20 ++- app/widgets/gimpcolordialog.c | 8 +- app/widgets/gimpcoloreditor.c | 42 ++--- app/widgets/gimpcolorpanel.c | 22 +-- app/widgets/gimpdevicestatus.c | 19 +-- app/widgets/gimpfgbgeditor.c | 24 ++- app/widgets/gimpfgbgview.c | 21 +-- app/widgets/gimpfilleditor.c | 30 ++-- app/widgets/gimppropwidgets.c | 139 ++++++++++++++++- app/widgets/gimppropwidgets.h | 9 ++ app/widgets/gimptoolbox-color-area.c | 37 +++-- app/widgets/gimpviewrenderergradient.c | 2 +- libgimp/gimpcontext_pdb.c | 34 ++-- libgimp/gimpcontext_pdb.h | 4 +- libgimp/gimpproceduredialog.c | 6 +- libgimpconfig/gimpconfig-params.h | 8 + libgimpwidgets/gimpcolorbutton.c | 31 ++-- libgimpwidgets/gimppropwidgets.c | 29 ++-- libgimpwidgets/gimpwidgets-private.c | 1 + libgimpwidgets/gimpwidgets-private.h | 4 +- pdb/groups/context.pdb | 16 +- pdb/groups/plug_in_compat.pdb | 150 ++++++++---------- pdb/groups/text_layer.pdb | 11 +- plug-ins/common/blinds.c | 17 +- plug-ins/common/checkerboard.c | 9 +- plug-ins/common/decompose.c | 16 +- plug-ins/common/file-gif-save.c | 44 ++++-- plug-ins/common/file-pdf-save.c | 13 +- plug-ins/common/file-png.c | 19 ++- plug-ins/common/sparkle.c | 14 +- plug-ins/common/warp.c | 10 +- plug-ins/file-fli/fli-gimp.c | 17 +- plug-ins/gfig/gfig-style.c | 11 +- plug-ins/ifs-compose/ifs-compose.c | 68 ++++---- plug-ins/map-object/map-object-image.c | 9 +- plug-ins/map-object/map-object-preview.c | 9 +- plug-ins/pagecurl/pagecurl.c | 9 +- 68 files changed, 1107 insertions(+), 836 deletions(-) diff --git a/app/actions/colormap-actions.c b/app/actions/colormap-actions.c index a73c57a623..289d2d2b13 100644 --- a/app/actions/colormap-actions.c +++ b/app/actions/colormap-actions.c @@ -147,8 +147,12 @@ colormap_actions_update (GimpActionGroup *group, if (context) { - gimp_context_get_foreground (context, &fg); - gimp_context_get_background (context, &bg); + GeglColor *color; + + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &fg.r, &fg.g, &fg.b, &fg.a, NULL); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &bg.r, &bg.g, &bg.b, &bg.a, NULL); } #define SET_SENSITIVE(action,condition) \ diff --git a/app/actions/colormap-commands.c b/app/actions/colormap-commands.c index bf62aacdd6..aa677e82e5 100644 --- a/app/actions/colormap-commands.c +++ b/app/actions/colormap-commands.c @@ -71,14 +71,17 @@ colormap_add_color_cmd_callback (GimpAction *action, if (gimp_image_get_colormap_size (image) < 256) { - GimpRGB color; + GimpRGB rgb; + GeglColor *color; if (background) - gimp_context_get_background (context, &color); + color = gimp_context_get_background (context); else - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); - gimp_image_add_colormap_entry (image, &color); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + + gimp_image_add_colormap_entry (image, &rgb); gimp_image_flush (image); } } diff --git a/app/actions/context-commands.c b/app/actions/context-commands.c index c1294ed753..34b235f058 100644 --- a/app/actions/context-commands.c +++ b/app/actions/context-commands.c @@ -61,7 +61,7 @@ static gint context_paint_mode_index (GimpLayerMode paint_mode, gint n_modes); static void context_select_color (GimpActionSelectType select_type, - GimpRGB *color, + GeglColor *color, gboolean use_colormap, gboolean use_palette); @@ -73,7 +73,7 @@ static gint context_max_color_index (gboolean use_colormap, static gboolean context_set_color_index (gint index, gboolean use_colormap, gboolean use_palette, - GimpRGB *color); + GeglColor *color); static GimpPaletteEditor * context_get_palette_editor (void); static GimpColormapEditor * context_get_colormap_editor (void); @@ -110,17 +110,15 @@ context_##name##_##fgbg##ground_cmd_callback (GimpAction *action, \ gpointer data) \ { \ GimpContext *context; \ - GimpRGB rgb; \ - GeglColor *color = gegl_color_new ("black"); \ + GeglColor *color; \ GimpActionSelectType select_type; \ return_if_no_context (context, data); \ \ select_type = (GimpActionSelectType) g_variant_get_int32 (value); \ \ - gimp_context_get_##fgbg##ground (context, &rgb); \ - context_select_color (select_type, &rgb, \ + color = gegl_color_duplicate (gimp_context_get_##fgbg##ground (context)); \ + context_select_color (select_type, color, \ use_colormap, use_palette); \ - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); \ gimp_context_set_##fgbg##ground (context, color); \ g_object_unref (color); \ } @@ -138,19 +136,23 @@ context_foreground_red_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); - GimpRGB rgb; + GeglColor *color; + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; GimpActionSelectType select_type; return_if_no_context (context, data); select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_foreground (context, &rgb); - rgb.r = action_select_value (select_type, - rgb.r, - 0.0, 1.0, 1.0, - 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color_get_rgba_with_space (color, &red, &green, &blue, &alpha, NULL); + red = action_select_value (select_type, + red, + 0.0, 1.0, 1.0, + 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); + gegl_color_set_rgba_with_space (color, red, green, blue, alpha, NULL); gimp_context_set_foreground (context, color); g_object_unref (color); } @@ -161,19 +163,23 @@ context_foreground_green_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); - GimpRGB rgb; + GeglColor *color; + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; GimpActionSelectType select_type; return_if_no_context (context, data); select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_foreground (context, &rgb); - rgb.g = action_select_value (select_type, - rgb.g, + color = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color_get_rgba_with_space (color, &red, &green, &blue, &alpha, NULL); + green = action_select_value (select_type, + green, 0.0, 1.0, 1.0, 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + gegl_color_set_rgba_with_space (color, red, green, blue, alpha, NULL); gimp_context_set_foreground (context, color); g_object_unref (color); } @@ -184,19 +190,23 @@ context_foreground_blue_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); - GimpRGB rgb; + GeglColor *color; + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; GimpActionSelectType select_type; return_if_no_context (context, data); select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_foreground (context, &rgb); - rgb.b = action_select_value (select_type, - rgb.b, - 0.0, 1.0, 1.0, - 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color_get_rgba_with_space (color, &red, &green, &blue, &alpha, NULL); + blue = action_select_value (select_type, + blue, + 0.0, 1.0, 1.0, + 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); + gegl_color_set_rgba_with_space (color, red, green, blue, alpha, NULL); gimp_context_set_foreground (context, color); g_object_unref (color); } @@ -207,19 +217,24 @@ context_background_red_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); - GimpRGB rgb; + GeglColor *color; + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; GimpActionSelectType select_type; return_if_no_context (context, data); select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_background (context, &rgb); - rgb.r = action_select_value (select_type, - rgb.r, - 0.0, 1.0, 1.0, - 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + color = gegl_color_duplicate (gimp_context_get_background (context)); + /* TODO: what space to use for this action to work as expected? */ + gegl_color_get_rgba_with_space (color, &red, &green, &blue, &alpha, NULL); + red = action_select_value (select_type, + red, + 0.0, 1.0, 1.0, + 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); + gegl_color_set_rgba_with_space (color, red, green, blue, alpha, NULL); gimp_context_set_background (context, color); g_object_unref (color); } @@ -230,19 +245,23 @@ context_background_green_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); - GimpRGB rgb; + GeglColor *color; + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; GimpActionSelectType select_type; return_if_no_context (context, data); select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_background (context, &rgb); - rgb.g = action_select_value (select_type, - rgb.g, + color = gegl_color_duplicate (gimp_context_get_background (context)); + gegl_color_get_rgba_with_space (color, &red, &green, &blue, &alpha, NULL); + green = action_select_value (select_type, + green, 0.0, 1.0, 1.0, 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + gegl_color_set_rgba_with_space (color, red, green, blue, alpha, NULL); gimp_context_set_background (context, color); g_object_unref (color); } @@ -253,19 +272,23 @@ context_background_blue_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); - GimpRGB rgb; + GeglColor *color; + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; GimpActionSelectType select_type; return_if_no_context (context, data); select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_background (context, &rgb); - rgb.b = action_select_value (select_type, - rgb.b, - 0.0, 1.0, 1.0, - 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + color = gegl_color_duplicate (gimp_context_get_background (context)); + gegl_color_get_rgba_with_space (color, &red, &green, &blue, &alpha, NULL); + blue = action_select_value (select_type, + blue, + 0.0, 1.0, 1.0, + 1.0 / 255.0, 0.01, 0.1, 0.0, FALSE); + gegl_color_set_rgba_with_space (color, red, green, blue, alpha, NULL); gimp_context_set_background (context, color); g_object_unref (color); } @@ -276,7 +299,7 @@ context_foreground_hue_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); + GeglColor *color; GimpRGB rgb; GimpHSV hsv; GimpActionSelectType select_type; @@ -284,7 +307,8 @@ context_foreground_hue_cmd_callback (GimpAction *action, select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_foreground (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); gimp_rgb_to_hsv (&rgb, &hsv); hsv.h = action_select_value (select_type, hsv.h, @@ -302,7 +326,7 @@ context_foreground_saturation_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); + GeglColor *color; GimpRGB rgb; GimpHSV hsv; GimpActionSelectType select_type; @@ -310,7 +334,8 @@ context_foreground_saturation_cmd_callback (GimpAction *action, select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_foreground (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); gimp_rgb_to_hsv (&rgb, &hsv); hsv.s = action_select_value (select_type, hsv.s, @@ -328,7 +353,7 @@ context_foreground_value_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); + GeglColor *color; GimpRGB rgb; GimpHSV hsv; GimpActionSelectType select_type; @@ -336,7 +361,8 @@ context_foreground_value_cmd_callback (GimpAction *action, select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_foreground (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); gimp_rgb_to_hsv (&rgb, &hsv); hsv.v = action_select_value (select_type, hsv.v, @@ -354,7 +380,7 @@ context_background_hue_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); + GeglColor *color; GimpRGB rgb; GimpHSV hsv; GimpActionSelectType select_type; @@ -362,7 +388,8 @@ context_background_hue_cmd_callback (GimpAction *action, select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_background (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_background (context)); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); gimp_rgb_to_hsv (&rgb, &hsv); hsv.h = action_select_value (select_type, hsv.h, @@ -380,7 +407,7 @@ context_background_saturation_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); + GeglColor *color; GimpRGB rgb; GimpHSV hsv; GimpActionSelectType select_type; @@ -388,7 +415,8 @@ context_background_saturation_cmd_callback (GimpAction *action, select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_background (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_background (context)); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); gimp_rgb_to_hsv (&rgb, &hsv); hsv.s = action_select_value (select_type, hsv.s, @@ -406,7 +434,7 @@ context_background_value_cmd_callback (GimpAction *action, gpointer data) { GimpContext *context; - GeglColor *color = gegl_color_new ("black"); + GeglColor *color; GimpRGB rgb; GimpHSV hsv; GimpActionSelectType select_type; @@ -414,7 +442,8 @@ context_background_value_cmd_callback (GimpAction *action, select_type = (GimpActionSelectType) g_variant_get_int32 (value); - gimp_context_get_background (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_background (context)); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); gimp_rgb_to_hsv (&rgb, &hsv); hsv.v = action_select_value (select_type, hsv.v, @@ -907,16 +936,13 @@ context_paint_mode_index (GimpLayerMode paint_mode, static void context_select_color (GimpActionSelectType select_type, - GimpRGB *rgb, + GeglColor *color, gboolean use_colormap, gboolean use_palette) { - GeglColor *color; - gint index; - gint max; + gint index; + gint max; - color = gegl_color_new ("black"); - gegl_color_set_rgba_with_space (color, rgb->r, rgb->g, rgb->b, rgb->a, NULL); index = context_get_color_index (use_colormap, use_palette, color); max = context_max_color_index (use_colormap, use_palette); @@ -925,7 +951,7 @@ context_select_color (GimpActionSelectType select_type, 0, max, 0, 0, 1, 4, 0, FALSE); - context_set_color_index (index, use_colormap, use_palette, rgb); + context_set_color_index (index, use_colormap, use_palette, color); g_object_unref (color); } @@ -998,25 +1024,34 @@ context_max_color_index (gboolean use_colormap, } static gboolean -context_set_color_index (gint index, - gboolean use_colormap, - gboolean use_palette, - GimpRGB *color) +context_set_color_index (gint index, + gboolean use_colormap, + gboolean use_palette, + GeglColor *color) { + GimpRGB rgb; + + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); if (use_colormap) { GimpColormapEditor *editor = context_get_colormap_editor (); - if (editor && gimp_colormap_editor_set_index (editor, index, color)) - return TRUE; + if (editor && gimp_colormap_editor_set_index (editor, index, &rgb)) + { + gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + return TRUE; + } } if (use_palette) { GimpPaletteEditor *editor = context_get_palette_editor (); - if (editor && gimp_palette_editor_set_index (editor, index, color)) - return TRUE; + if (editor && gimp_palette_editor_set_index (editor, index, &rgb)) + { + gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); + return TRUE; + } } return FALSE; diff --git a/app/actions/edit-actions.c b/app/actions/edit-actions.c index 6dd27ba8f7..9ff08b2fd5 100644 --- a/app/actions/edit-actions.c +++ b/app/actions/edit-actions.c @@ -50,10 +50,10 @@ /* local function prototypes */ static void edit_actions_foreground_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpActionGroup *group); static void edit_actions_background_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpActionGroup *group); static void edit_actions_pattern_changed (GimpContext *context, GimpPattern *pattern, @@ -233,7 +233,7 @@ void edit_actions_setup (GimpActionGroup *group) { GimpContext *context = gimp_get_user_context (group->gimp); - GimpRGB color; + GeglColor *color; GimpPattern *pattern; gimp_action_group_add_actions (group, "edit-action", @@ -260,11 +260,11 @@ edit_actions_setup (GimpActionGroup *group) G_CALLBACK (edit_actions_pattern_changed), group, 0); - gimp_context_get_foreground (context, &color); - edit_actions_foreground_changed (context, &color, group); + color = gimp_context_get_foreground (context); + edit_actions_foreground_changed (context, color, group); - gimp_context_get_background (context, &color); - edit_actions_background_changed (context, &color, group); + color = gimp_context_get_background (context); + edit_actions_background_changed (context, color, group); pattern = gimp_context_get_pattern (context); edit_actions_pattern_changed (context, pattern, group); @@ -380,18 +380,24 @@ edit_actions_update (GimpActionGroup *group, static void edit_actions_foreground_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpActionGroup *group) { - gimp_action_group_set_action_color (group, "edit-fill-fg", color, FALSE); + GimpRGB rgb; + + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); + gimp_action_group_set_action_color (group, "edit-fill-fg", &rgb, FALSE); } static void edit_actions_background_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpActionGroup *group) { - gimp_action_group_set_action_color (group, "edit-fill-bg", color, FALSE); + GimpRGB rgb; + + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); + gimp_action_group_set_action_color (group, "edit-fill-bg", &rgb, FALSE); } static void diff --git a/app/actions/gradient-editor-actions.c b/app/actions/gradient-editor-actions.c index f0ed05fb1e..228cd00c98 100644 --- a/app/actions/gradient-editor-actions.c +++ b/app/actions/gradient-editor-actions.c @@ -548,8 +548,12 @@ gradient_editor_actions_update (GimpActionGroup *group, if (data_editor->context) { - gimp_context_get_foreground (data_editor->context, &fg); - gimp_context_get_background (data_editor->context, &bg); + GeglColor *color; + + color = gimp_context_get_foreground (data_editor->context); + gegl_color_get_rgba_with_space (color, &fg.r, &fg.g, &fg.b, &fg.a, NULL); + color = gimp_context_get_background (data_editor->context); + gegl_color_get_rgba_with_space (color, &bg.r, &bg.g, &bg.b, &bg.a, NULL); } /* pretend the gradient not being editable while the dialog is diff --git a/app/actions/gradient-editor-commands.c b/app/actions/gradient-editor-commands.c index cb30c8cda8..cf794af698 100644 --- a/app/actions/gradient-editor-commands.c +++ b/app/actions/gradient-editor-commands.c @@ -108,7 +108,8 @@ gradient_editor_load_left_cmd_callback (GimpAction *action, GimpGradientSegment *left; GimpGradientSegment *right; GimpGradientSegment *seg; - GimpRGB color; + GeglColor *color = NULL; + GimpRGB rgb; GimpGradientColor color_type = GIMP_GRADIENT_COLOR_FIXED; gint index = g_variant_get_int32 (value); @@ -122,32 +123,35 @@ gradient_editor_load_left_cmd_callback (GimpAction *action, else seg = gimp_gradient_segment_get_last (left); - color = seg->right_color; + rgb = seg->right_color; color_type = seg->right_color_type; break; case GRADIENT_EDITOR_COLOR_OTHER_ENDPOINT: - color = right->right_color; + rgb = right->right_color; color_type = right->right_color_type; break; case GRADIENT_EDITOR_COLOR_FOREGROUND: - gimp_context_get_foreground (data_editor->context, &color); + color = gimp_context_get_foreground (data_editor->context); break; case GRADIENT_EDITOR_COLOR_BACKGROUND: - gimp_context_get_background (data_editor->context, &color); + color = gimp_context_get_background (data_editor->context); break; default: /* Load a color */ - color = editor->saved_colors[index - GRADIENT_EDITOR_COLOR_FIRST_CUSTOM]; + rgb = editor->saved_colors[index - GRADIENT_EDITOR_COLOR_FIRST_CUSTOM]; break; } + if (color != NULL) + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + gimp_data_freeze (GIMP_DATA (gradient)); gimp_gradient_segment_range_blend (gradient, left, right, - &color, + &rgb, &right->right_color, TRUE, TRUE); gimp_gradient_segment_set_left_color_type (gradient, left, color_type); @@ -228,7 +232,8 @@ gradient_editor_load_right_cmd_callback (GimpAction *action, GimpGradientSegment *left; GimpGradientSegment *right; GimpGradientSegment *seg; - GimpRGB color; + GeglColor *color = NULL; + GimpRGB rgb; GimpGradientColor color_type = GIMP_GRADIENT_COLOR_FIXED; gint index = g_variant_get_int32 (value); @@ -242,33 +247,36 @@ gradient_editor_load_right_cmd_callback (GimpAction *action, else seg = gimp_gradient_segment_get_first (right); - color = seg->left_color; + rgb = seg->left_color; color_type = seg->left_color_type; break; case GRADIENT_EDITOR_COLOR_OTHER_ENDPOINT: - color = left->left_color; + rgb = left->left_color; color_type = left->left_color_type; break; case GRADIENT_EDITOR_COLOR_FOREGROUND: - gimp_context_get_foreground (data_editor->context, &color); + color = gimp_context_get_foreground (data_editor->context); break; case GRADIENT_EDITOR_COLOR_BACKGROUND: - gimp_context_get_background (data_editor->context, &color); + color = gimp_context_get_background (data_editor->context); break; default: /* Load a color */ - color = editor->saved_colors[index - GRADIENT_EDITOR_COLOR_FIRST_CUSTOM]; + rgb = editor->saved_colors[index - GRADIENT_EDITOR_COLOR_FIRST_CUSTOM]; break; } + if (color != NULL) + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + gimp_data_freeze (GIMP_DATA (gradient)); gimp_gradient_segment_range_blend (gradient, left, right, &left->left_color, - &color, + &rgb, TRUE, TRUE); gimp_gradient_segment_set_right_color_type (gradient, left, color_type); diff --git a/app/actions/palette-editor-actions.c b/app/actions/palette-editor-actions.c index ef92f83ce2..904d32f694 100644 --- a/app/actions/palette-editor-actions.c +++ b/app/actions/palette-editor-actions.c @@ -145,8 +145,12 @@ palette_editor_actions_update (GimpActionGroup *group, if (data_editor->context) { - gimp_context_get_foreground (data_editor->context, &fg); - gimp_context_get_background (data_editor->context, &bg); + GeglColor *color; + + color = gimp_context_get_foreground (data_editor->context); + gegl_color_get_rgba_with_space (color, &fg.r, &fg.g, &fg.b, &fg.a, NULL); + color = gimp_context_get_background (data_editor->context); + gegl_color_get_rgba_with_space (color, &bg.r, &bg.g, &bg.b, &bg.a, NULL); } edit_active = gimp_data_editor_get_edit_active (data_editor); diff --git a/app/actions/palette-editor-commands.c b/app/actions/palette-editor-commands.c index 55a8c0ee17..04801f4b34 100644 --- a/app/actions/palette-editor-commands.c +++ b/app/actions/palette-editor-commands.c @@ -56,14 +56,16 @@ palette_editor_new_color_cmd_callback (GimpAction *action, { GimpPalette *palette = GIMP_PALETTE (data_editor->data); GimpPaletteEntry *entry; - GimpRGB color; + GimpRGB rgb; + GeglColor *color; if (background) - gimp_context_get_background (data_editor->context, &color); + color = gimp_context_get_background (data_editor->context); else - gimp_context_get_foreground (data_editor->context, &color); + color = gimp_context_get_foreground (data_editor->context); - entry = gimp_palette_add_entry (palette, -1, NULL, &color); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + entry = gimp_palette_add_entry (palette, -1, NULL, &rgb); gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view), entry); } } diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c index 7ac01babd5..7626bb994e 100644 --- a/app/core/gimp-utils.c +++ b/app/core/gimp-utils.c @@ -527,13 +527,15 @@ gimp_enum_get_value_name (GType enum_type, gboolean gimp_get_fill_params (GimpContext *context, GimpFillType fill_type, - GimpRGB *color, + GimpRGB *rgb, GimpPattern **pattern, GError **error) { + GeglColor *color; + g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE); - g_return_val_if_fail (color != NULL, FALSE); + g_return_val_if_fail (rgb != NULL, FALSE); g_return_val_if_fail (pattern != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -542,11 +544,13 @@ gimp_get_fill_params (GimpContext *context, switch (fill_type) { case GIMP_FILL_FOREGROUND: - gimp_context_get_foreground (context, color); + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); break; case GIMP_FILL_BACKGROUND: - gimp_context_get_background (context, color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); break; case GIMP_FILL_CIELAB_MIDDLE_GRAY: @@ -568,16 +572,16 @@ gimp_get_fill_params (GimpContext *context, babl_process (babl_fish (babl_format ("CIE Lab float"), format), cielab_pixel, pixel, 1); - gimp_rgba_set (color, pixel[0], pixel[1], pixel[2], GIMP_OPACITY_OPAQUE); + gimp_rgba_set (rgb, pixel[0], pixel[1], pixel[2], GIMP_OPACITY_OPAQUE); } break; case GIMP_FILL_WHITE: - gimp_rgba_set (color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); + gimp_rgba_set (rgb, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); break; case GIMP_FILL_TRANSPARENT: - gimp_rgba_set (color, 0.0, 0.0, 0.0, GIMP_OPACITY_TRANSPARENT); + gimp_rgba_set (rgb, 0.0, 0.0, 0.0, GIMP_OPACITY_TRANSPARENT); break; case GIMP_FILL_PATTERN: @@ -589,7 +593,8 @@ gimp_get_fill_params (GimpContext *context, _("No patterns available for this operation.")); /* fall back to BG fill */ - gimp_context_get_background (context, color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); return FALSE; } diff --git a/app/core/gimpcontext.c b/app/core/gimpcontext.c index d98eaa9abb..aeef7e1ad2 100644 --- a/app/core/gimpcontext.c +++ b/app/core/gimpcontext.c @@ -58,8 +58,6 @@ #include "gimp-intl.h" -#define RGBA_EPSILON 1e-10 - typedef void (* GimpContextCopyPropFunc) (GimpContext *src, GimpContext *dest); @@ -405,11 +403,8 @@ gimp_context_class_init (GimpContextClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass); - GimpRGB black; - GimpRGB white; - - gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); - gimp_rgba_set (&white, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); + GeglColor *black = gegl_color_new ("black"); + GeglColor *white = gegl_color_new ("white"); gimp_context_signals[IMAGE_CHANGED] = g_signal_new ("image-changed", @@ -454,7 +449,7 @@ gimp_context_class_init (GimpContextClass *klass) G_STRUCT_OFFSET (GimpContextClass, foreground_changed), NULL, NULL, NULL, G_TYPE_NONE, 1, - GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE); + GEGL_TYPE_COLOR); gimp_context_signals[BACKGROUND_CHANGED] = g_signal_new ("background-changed", @@ -463,7 +458,7 @@ gimp_context_class_init (GimpContextClass *klass) G_STRUCT_OFFSET (GimpContextClass, background_changed), NULL, NULL, NULL, G_TYPE_NONE, 1, - GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE); + GEGL_TYPE_COLOR); gimp_context_signals[OPACITY_CHANGED] = g_signal_new ("opacity-changed", @@ -666,19 +661,19 @@ gimp_context_class_init (GimpContextClass *klass) GIMP_TYPE_PAINT_INFO, GIMP_PARAM_STATIC_STRINGS); - GIMP_CONFIG_PROP_RGB (object_class, GIMP_CONTEXT_PROP_FOREGROUND, - gimp_context_prop_names[GIMP_CONTEXT_PROP_FOREGROUND], - _("Foreground"), - _("Foreground color"), - FALSE, &black, - GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_PROP_COLOR (object_class, GIMP_CONTEXT_PROP_FOREGROUND, + gimp_context_prop_names[GIMP_CONTEXT_PROP_FOREGROUND], + _("Foreground"), + _("Foreground color"), + black, + GIMP_PARAM_STATIC_STRINGS); - GIMP_CONFIG_PROP_RGB (object_class, GIMP_CONTEXT_PROP_BACKGROUND, - gimp_context_prop_names[GIMP_CONTEXT_PROP_BACKGROUND], - _("Background"), - _("Background color"), - FALSE, &white, - GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_PROP_COLOR (object_class, GIMP_CONTEXT_PROP_BACKGROUND, + gimp_context_prop_names[GIMP_CONTEXT_PROP_BACKGROUND], + _("Background"), + _("Background color"), + white, + GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_DOUBLE (object_class, GIMP_CONTEXT_PROP_OPACITY, gimp_context_prop_names[GIMP_CONTEXT_PROP_OPACITY], @@ -770,6 +765,9 @@ gimp_context_class_init (GimpContextClass *klass) NULL, NULL, GIMP_TYPE_TEMPLATE, GIMP_PARAM_READWRITE)); + + g_object_unref (black); + g_object_unref (white); } static void @@ -827,8 +825,8 @@ gimp_context_init (GimpContext *context) context->line_art = NULL; context->line_art_timeout_id = 0; - context->foreground = NULL; - context->background = NULL; + context->foreground = gegl_color_new ("black"); + context->background = gegl_color_new ("white"); } static void @@ -1058,24 +1056,10 @@ gimp_context_set_property (GObject *object, gimp_context_set_paint_info (context, g_value_get_object (value)); break; case GIMP_CONTEXT_PROP_FOREGROUND: - { - GeglColor *color = gegl_color_new ("black"); - GimpRGB *rgb = g_value_get_boxed (value); - - gegl_color_set_rgba_with_space (color, rgb->r, rgb->g, rgb->b, rgb->a, NULL); - gimp_context_set_foreground (context, color); - g_object_unref (color); - } + gimp_context_set_foreground (context, g_value_get_object (value)); break; case GIMP_CONTEXT_PROP_BACKGROUND: - { - GeglColor *color = gegl_color_new ("black"); - GimpRGB *rgb = g_value_get_boxed (value); - - gegl_color_set_rgba_with_space (color, rgb->r, rgb->g, rgb->b, rgb->a, NULL); - gimp_context_set_background (context, color); - g_object_unref (color); - } + gimp_context_set_background (context, g_value_get_object (value)); break; case GIMP_CONTEXT_PROP_OPACITY: gimp_context_set_opacity (context, g_value_get_double (value)); @@ -1148,20 +1132,10 @@ gimp_context_get_property (GObject *object, g_value_set_object (value, gimp_context_get_paint_info (context)); break; case GIMP_CONTEXT_PROP_FOREGROUND: - { - GimpRGB color; - - gimp_context_get_foreground (context, &color); - g_value_set_boxed (value, &color); - } + g_value_take_object (value, gegl_color_duplicate (gimp_context_get_foreground (context))); break; case GIMP_CONTEXT_PROP_BACKGROUND: - { - GimpRGB color; - - gimp_context_get_background (context, &color); - g_value_set_boxed (value, &color); - } + g_value_take_object (value, gegl_color_duplicate (gimp_context_get_background (context))); break; case GIMP_CONTEXT_PROP_OPACITY: g_value_set_double (value, gimp_context_get_opacity (context)); @@ -2307,14 +2281,12 @@ gimp_context_real_set_paint_info (GimpContext *context, /*****************************************************************************/ /* foreground color ********************************************************/ -void -gimp_context_get_foreground (GimpContext *context, - GimpRGB *rgb) +GeglColor * +gimp_context_get_foreground (GimpContext *context) { - g_return_if_fail (GIMP_IS_CONTEXT (context)); - g_return_if_fail (rgb != NULL); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); - gegl_color_get_rgba_with_space (context->foreground, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); + return context->foreground; } void @@ -2322,7 +2294,7 @@ gimp_context_set_foreground (GimpContext *context, GeglColor *color) { g_return_if_fail (GIMP_IS_CONTEXT (context)); - g_return_if_fail (color != NULL); + g_return_if_fail (GEGL_IS_COLOR (color)); context_find_defined (context, GIMP_CONTEXT_PROP_FOREGROUND); @@ -2336,7 +2308,7 @@ gimp_context_foreground_changed (GimpContext *context) g_signal_emit (context, gimp_context_signals[FOREGROUND_CHANGED], 0, - &context->foreground); + context->foreground); } static void @@ -2359,15 +2331,12 @@ gimp_context_real_set_foreground (GimpContext *context, /*****************************************************************************/ /* background color ********************************************************/ -void -gimp_context_get_background (GimpContext *context, - GimpRGB *rgb) +GeglColor * +gimp_context_get_background (GimpContext *context) { - g_return_if_fail (GIMP_IS_CONTEXT (context)); + g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); - g_return_if_fail (rgb != NULL); - - gegl_color_get_rgba_with_space (context->background, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); + return context->background; } void @@ -2375,7 +2344,7 @@ gimp_context_set_background (GimpContext *context, GeglColor *color) { g_return_if_fail (GIMP_IS_CONTEXT (context)); - g_return_if_fail (color != NULL); + g_return_if_fail (GEGL_IS_COLOR (color)); context_find_defined (context, GIMP_CONTEXT_PROP_BACKGROUND); @@ -2389,7 +2358,7 @@ gimp_context_background_changed (GimpContext *context) g_signal_emit (context, gimp_context_signals[BACKGROUND_CHANGED], 0, - &context->background); + context->background); } static void diff --git a/app/core/gimpcontext.h b/app/core/gimpcontext.h index 3651b29d99..ad3dcfc567 100644 --- a/app/core/gimpcontext.h +++ b/app/core/gimpcontext.h @@ -122,9 +122,9 @@ struct _GimpContextClass GimpPaintInfo *paint_info); void (* foreground_changed) (GimpContext *context, - GimpRGB *color); + GeglColor *color); void (* background_changed) (GimpContext *context, - GimpRGB *color); + GeglColor *color); void (* opacity_changed) (GimpContext *context, gdouble opacity); void (* paint_mode_changed) (GimpContext *context, @@ -246,16 +246,14 @@ void gimp_context_paint_info_changed (GimpContext *context); /* foreground color */ -void gimp_context_get_foreground (GimpContext *context, - GimpRGB *color); +GeglColor * gimp_context_get_foreground (GimpContext *context); void gimp_context_set_foreground (GimpContext *context, GeglColor *color); void gimp_context_foreground_changed (GimpContext *context); /* background color */ -void gimp_context_get_background (GimpContext *context, - GimpRGB *color); +GeglColor * gimp_context_get_background (GimpContext *context); void gimp_context_set_background (GimpContext *context, GeglColor *color); void gimp_context_background_changed (GimpContext *context); diff --git a/app/core/gimpdrawable-bucket-fill.c b/app/core/gimpdrawable-bucket-fill.c index 10b6aa4021..268ce5c2e5 100644 --- a/app/core/gimpdrawable-bucket-fill.c +++ b/app/core/gimpdrawable-bucket-fill.c @@ -410,6 +410,7 @@ gimp_drawable_get_line_art_fill_buffer (GimpDrawable *drawable, if (fill_color_as_line_art) { GimpPickable *pickable = gimp_line_art_get_input (line_art); + GeglColor *color = NULL; /* This cannot be a pattern fill. */ g_return_val_if_fail (gimp_fill_options_get_style (options) != GIMP_FILL_STYLE_PATTERN, @@ -418,9 +419,12 @@ gimp_drawable_get_line_art_fill_buffer (GimpDrawable *drawable, g_return_val_if_fail (GIMP_IS_DRAWABLE (pickable), NULL); if (gimp_fill_options_get_style (options) == GIMP_FILL_STYLE_FG_COLOR) - gimp_context_get_foreground (GIMP_CONTEXT (options), &fill_color); + color = gimp_context_get_foreground (GIMP_CONTEXT (options)); else if (gimp_fill_options_get_style (options) == GIMP_FILL_STYLE_BG_COLOR) - gimp_context_get_background (GIMP_CONTEXT (options), &fill_color); + color = gimp_context_get_background (GIMP_CONTEXT (options)); + + g_return_val_if_fail (color != NULL, NULL); + gegl_color_get_rgba_with_space (color, &fill_color.r, &fill_color.g, &fill_color.b, &fill_color.a, NULL); fill_buffer = gimp_drawable_get_buffer (drawable); fill_offset_x = gimp_item_get_offset_x (GIMP_ITEM (drawable)) - diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c index 5ad2c99102..b6014784a2 100644 --- a/app/core/gimpdrawable-transform.c +++ b/app/core/gimpdrawable-transform.c @@ -198,7 +198,7 @@ gimp_drawable_transform_buffer_flip (GimpDrawable *drawable, if (clip_result && (new_x != orig_x || new_y != orig_y)) { GimpRGB bg; - GeglColor *color; + GeglColor *color = NULL; gint clip_x, clip_y; gint clip_width, clip_height; @@ -209,17 +209,12 @@ gimp_drawable_transform_buffer_flip (GimpDrawable *drawable, * channels, and drawables with an alpha channel. */ if (GIMP_IS_CHANNEL (drawable) || babl_format_has_alpha (format)) - { - gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); - } + gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); else - { - gimp_context_get_background (context, &bg); - gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), - &bg, &bg); - } + color = gegl_color_duplicate (gimp_context_get_background (context)); - color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable)); + if (color == NULL) + color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable)); gegl_buffer_set_color (new_buffer, NULL, color); g_object_unref (color); @@ -459,7 +454,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, { GimpRGB bg; - GeglColor *color; + GeglColor *color = NULL; gint clip_x, clip_y; gint clip_width, clip_height; @@ -474,17 +469,12 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, * channels, and drawables with an alpha channel. */ if (GIMP_IS_CHANNEL (drawable) || babl_format_has_alpha (format)) - { - gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); - } + gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); else - { - gimp_context_get_background (context, &bg); - gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), - &bg, &bg); - } + color = gegl_color_duplicate (gimp_context_get_background (context)); - color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable)); + if (color == NULL) + color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable)); gegl_buffer_set_color (new_buffer, NULL, color); g_object_unref (color); diff --git a/app/core/gimpfilloptions.c b/app/core/gimpfilloptions.c index 1418cf0485..0ae67ea452 100644 --- a/app/core/gimpfilloptions.c +++ b/app/core/gimpfilloptions.c @@ -375,8 +375,7 @@ gimp_fill_options_set_by_fill_type (GimpFillOptions *options, GError **error) { GimpFillOptionsPrivate *private; - GeglColor *color; - GimpRGB rgb; + GeglColor *color = NULL; const gchar *undo_desc; g_return_val_if_fail (GIMP_IS_FILL_OPTIONS (options), FALSE); @@ -390,46 +389,33 @@ gimp_fill_options_set_by_fill_type (GimpFillOptions *options, switch (fill_type) { case GIMP_FILL_FOREGROUND: - gimp_context_get_foreground (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); undo_desc = C_("undo-type", "Fill with Foreground Color"); break; case GIMP_FILL_BACKGROUND: - gimp_context_get_background (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_background (context)); undo_desc = C_("undo-type", "Fill with Background Color"); break; case GIMP_FILL_CIELAB_MIDDLE_GRAY: { - const float cielab_pixel[3] = {50, 0, 0}; - float pixel[3] = {0, 0, 0}; - GimpImage *image = gimp_context_get_image (context); - GimpImageBaseType base_type; - const Babl *format; + const float cielab_pixel[3] = {50, 0, 0}; - base_type = gimp_image_get_base_type (image); - if (base_type == GIMP_INDEXED) - base_type = GIMP_RGB; + color = gegl_color_new (NULL); + gegl_color_set_pixel (color, babl_format ("CIE Lab float"), cielab_pixel); - format = gimp_image_get_format (image, base_type, - GIMP_PRECISION_FLOAT_NON_LINEAR, FALSE, - gimp_image_get_layer_space (image)); - - babl_process (babl_fish (babl_format ("CIE Lab float"), format), - cielab_pixel, pixel, 1); - - gimp_rgba_set (&rgb, pixel[0], pixel[1], pixel[2], GIMP_OPACITY_OPAQUE); undo_desc = C_("undo-type", "Fill with Middle Gray (CIELAB) Color"); } break; case GIMP_FILL_WHITE: - gimp_rgba_set (&rgb, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); + color = gegl_color_new ("white"); undo_desc = C_("undo-type", "Fill with White"); break; case GIMP_FILL_TRANSPARENT: - gimp_context_get_background (context, &rgb); + color = gegl_color_duplicate (gimp_context_get_background (context)); gimp_context_set_paint_mode (GIMP_CONTEXT (options), GIMP_LAYER_MODE_ERASE); undo_desc = C_("undo-type", "Fill with Transparency"); @@ -459,9 +445,9 @@ gimp_fill_options_set_by_fill_type (GimpFillOptions *options, return FALSE; } + g_return_val_if_fail (color != NULL, FALSE); + gimp_fill_options_set_style (options, GIMP_FILL_STYLE_FG_COLOR); - color = gegl_color_new ("black"); - gegl_color_set_rgba_with_space (color, rgb.r, rgb.g, rgb.b, rgb.a, NULL); gimp_context_set_foreground (GIMP_CONTEXT (options), color); private->undo_desc = undo_desc; @@ -592,25 +578,27 @@ gimp_fill_options_fill_buffer (GimpFillOptions *options, { case GIMP_FILL_STYLE_FG_COLOR: { - GimpRGB color; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_foreground (GIMP_CONTEXT (options), &color); - gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, &color); + color = gimp_context_get_foreground (GIMP_CONTEXT (options)); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, &rgb); - gimp_drawable_fill_buffer (drawable, buffer, - &color, NULL, 0, 0); + gimp_drawable_fill_buffer (drawable, buffer, &rgb, NULL, 0, 0); } break; case GIMP_FILL_STYLE_BG_COLOR: { - GimpRGB color; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_background (GIMP_CONTEXT (options), &color); - gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, &color); + color = gimp_context_get_background (GIMP_CONTEXT (options)); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + gimp_palettes_add_color_history (GIMP_CONTEXT (options)->gimp, &rgb); - gimp_drawable_fill_buffer (drawable, buffer, - &color, NULL, 0, 0); + gimp_drawable_fill_buffer (drawable, buffer, &rgb, NULL, 0, 0); } break; diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c index 1bdfcc46d8..a7851dd6d1 100644 --- a/app/core/gimpgradient.c +++ b/app/core/gimpgradient.c @@ -2195,32 +2195,39 @@ gimp_gradient_get_segment_at_internal (GimpGradient *gradient, static void gimp_gradient_get_flat_color (GimpContext *context, - const GimpRGB *color, + const GimpRGB *rgb, GimpGradientColor color_type, GimpRGB *flat_color) { + GeglColor *color = NULL; + switch (color_type) { case GIMP_GRADIENT_COLOR_FIXED: - *flat_color = *color; + *flat_color = *rgb; break; case GIMP_GRADIENT_COLOR_FOREGROUND: case GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT: - gimp_context_get_foreground (context, flat_color); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); if (color_type == GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT) - gimp_rgb_set_alpha (flat_color, 0.0); + gimp_color_set_alpha (color, 0.0); break; case GIMP_GRADIENT_COLOR_BACKGROUND: case GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT: - gimp_context_get_background (context, flat_color); + color = gegl_color_duplicate (gimp_context_get_background (context)); if (color_type == GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT) - gimp_rgb_set_alpha (flat_color, 0.0); + gimp_color_set_alpha (color, 0.0); break; } + + if (color != NULL) + gegl_color_get_rgba_with_space (color, &flat_color->r, &flat_color->g, &flat_color->b, &flat_color->a, NULL); + + g_clear_object (&color); } static inline gdouble diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 8e332cd215..93313a98a9 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -673,7 +673,8 @@ gimp_image_merge_layers (GimpImage *image, (gimp_drawable_is_indexed (GIMP_DRAWABLE (layer)) && ! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))) { - GimpRGB bg; + GeglColor *color; + GimpRGB bg; merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1), gimp_image_get_layer_format (image, FALSE), @@ -689,7 +690,8 @@ gimp_image_merge_layers (GimpImage *image, } /* get the background for compositing */ - gimp_context_get_background (context, &bg); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &bg.r, &bg.g, &bg.b, &bg.a, NULL); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (layer), &bg, &bg); diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index 825b631ad8..353b236a6e 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -2517,6 +2517,7 @@ gimp_layer_remove_alpha (GimpLayer *layer, GimpContext *context) { GeglBuffer *new_buffer; + GeglColor *color; GimpRGB background; g_return_if_fail (GIMP_IS_LAYER (layer)); @@ -2531,7 +2532,8 @@ gimp_layer_remove_alpha (GimpLayer *layer, gimp_item_get_height (GIMP_ITEM (layer))), gimp_drawable_get_format_without_alpha (GIMP_DRAWABLE (layer))); - gimp_context_get_background (context, &background); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &background.r, &background.g, &background.b, &background.a, NULL); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (layer), &background, &background); diff --git a/app/display/gimpcanvaspen.c b/app/display/gimpcanvaspen.c index d0d01f914d..905c629c53 100644 --- a/app/display/gimpcanvaspen.c +++ b/app/display/gimpcanvaspen.c @@ -193,11 +193,12 @@ gimp_canvas_pen_new (GimpDisplayShell *shell, const GimpVector2 *points, gint n_points, GimpContext *context, - GimpActiveColor color, + GimpActiveColor active_color, gint width) { GimpCanvasItem *item; GimpArray *array; + GeglColor *color = NULL; GimpRGB rgb; g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL); @@ -207,17 +208,22 @@ gimp_canvas_pen_new (GimpDisplayShell *shell, array = gimp_array_new ((const guint8 *) points, n_points * sizeof (GimpVector2), TRUE); - switch (color) + switch (active_color) { case GIMP_ACTIVE_COLOR_FOREGROUND: - gimp_context_get_foreground (context, &rgb); + color = gimp_context_get_foreground (context); break; case GIMP_ACTIVE_COLOR_BACKGROUND: - gimp_context_get_background (context, &rgb); + color = gimp_context_get_background (context); break; + + default: + g_return_val_if_reached (NULL); } + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + item = g_object_new (GIMP_TYPE_CANVAS_PEN, "shell", shell, "points", array, diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c index ff214cc96f..89663fa717 100644 --- a/app/display/gimpdisplayshell-dnd.c +++ b/app/display/gimpdisplayshell-dnd.c @@ -388,15 +388,18 @@ gimp_display_shell_dnd_fill (GimpDisplayShell *shell, (gimp_fill_options_get_style (options) == GIMP_FILL_STYLE_FG_COLOR || gimp_fill_options_get_style (options) == GIMP_FILL_STYLE_BG_COLOR)) { - GimpRGB color; + GeglColor *color; + GimpRGB rgb; if (gimp_fill_options_get_style (options) == GIMP_FILL_STYLE_FG_COLOR) - gimp_context_get_foreground (GIMP_CONTEXT (options), &color); + color = gimp_context_get_foreground (GIMP_CONTEXT (options)); else - gimp_context_get_background (GIMP_CONTEXT (options), &color); + color = gimp_context_get_background (GIMP_CONTEXT (options)); + + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); gimp_text_layer_set (iter->data, NULL, - "color", &color, + "color", &rgb, NULL); } else diff --git a/app/gui/gui.c b/app/gui/gui.c index 54c086254e..988fda46a7 100644 --- a/app/gui/gui.c +++ b/app/gui/gui.c @@ -112,48 +112,48 @@ /* local function prototypes */ -static gchar * gui_sanity_check (void); -static void gui_help_func (const gchar *help_id, - gpointer help_data); -static gboolean gui_get_background_func (GimpRGB *color); -static gboolean gui_get_foreground_func (GimpRGB *color); +static gchar * gui_sanity_check (void); +static void gui_help_func (const gchar *help_id, + gpointer help_data); +static GeglColor * gui_get_background_func (void); +static GeglColor * gui_get_foreground_func (void); -static void gui_initialize_after_callback (Gimp *gimp, - GimpInitStatusFunc callback); +static void gui_initialize_after_callback (Gimp *gimp, + GimpInitStatusFunc callback); -static void gui_restore_callback (Gimp *gimp, - GimpInitStatusFunc callback); -static void gui_restore_after_callback (Gimp *gimp, - GimpInitStatusFunc callback); +static void gui_restore_callback (Gimp *gimp, + GimpInitStatusFunc callback); +static void gui_restore_after_callback (Gimp *gimp, + GimpInitStatusFunc callback); -static gboolean gui_exit_callback (Gimp *gimp, - gboolean force); -static gboolean gui_exit_after_callback (Gimp *gimp, - gboolean force); +static gboolean gui_exit_callback (Gimp *gimp, + gboolean force); +static gboolean gui_exit_after_callback (Gimp *gimp, + gboolean force); -static void gui_show_help_button_notify (GimpGuiConfig *gui_config, - GParamSpec *pspec, - Gimp *gimp); -static void gui_user_manual_notify (GimpGuiConfig *gui_config, - GParamSpec *pspec, - Gimp *gimp); -static void gui_single_window_mode_notify (GimpGuiConfig *gui_config, - GParamSpec *pspec, - GimpUIConfigurer *ui_configurer); +static void gui_show_help_button_notify (GimpGuiConfig *gui_config, + GParamSpec *pspec, + Gimp *gimp); +static void gui_user_manual_notify (GimpGuiConfig *gui_config, + GParamSpec *pspec, + Gimp *gimp); +static void gui_single_window_mode_notify (GimpGuiConfig *gui_config, + GParamSpec *pspec, + GimpUIConfigurer *ui_configurer); -static void gui_clipboard_changed (Gimp *gimp); +static void gui_clipboard_changed (Gimp *gimp); -static void gui_menu_show_tooltip (GimpUIManager *manager, - const gchar *tooltip, - Gimp *gimp); -static void gui_menu_hide_tooltip (GimpUIManager *manager, - Gimp *gimp); +static void gui_menu_show_tooltip (GimpUIManager *manager, + const gchar *tooltip, + Gimp *gimp); +static void gui_menu_hide_tooltip (GimpUIManager *manager, + Gimp *gimp); -static void gui_display_changed (GimpContext *context, - GimpDisplay *display, - Gimp *gimp); +static void gui_display_changed (GimpContext *context, + GimpDisplay *display, + Gimp *gimp); -static void gui_check_unique_accelerators (Gimp *gimp); +static void gui_check_unique_accelerators (Gimp *gimp); /* private variables */ @@ -411,26 +411,28 @@ gui_help_func (const gchar *help_id, gimp_help (the_gui_gimp, NULL, NULL, help_id); } -static gboolean -gui_get_foreground_func (GimpRGB *color) +static GeglColor * +gui_get_foreground_func (void) { - g_return_val_if_fail (color != NULL, FALSE); + GeglColor *color; + g_return_val_if_fail (GIMP_IS_GIMP (the_gui_gimp), FALSE); - gimp_context_get_foreground (gimp_get_user_context (the_gui_gimp), color); + color = gimp_context_get_foreground (gimp_get_user_context (the_gui_gimp)); - return TRUE; + return gegl_color_duplicate (color); } -static gboolean -gui_get_background_func (GimpRGB *color) +static GeglColor * +gui_get_background_func (void) { - g_return_val_if_fail (color != NULL, FALSE); + GeglColor *color; + g_return_val_if_fail (GIMP_IS_GIMP (the_gui_gimp), FALSE); - gimp_context_get_background (gimp_get_user_context (the_gui_gimp), color); + color = gimp_context_get_background (gimp_get_user_context (the_gui_gimp)); - return TRUE; + return gegl_color_duplicate (color); } static void diff --git a/app/operations/gimpoperationoffset.c b/app/operations/gimpoperationoffset.c index 69c644c3e6..788fa268ad 100644 --- a/app/operations/gimpoperationoffset.c +++ b/app/operations/gimpoperationoffset.c @@ -357,13 +357,7 @@ gimp_operation_offset_process (GeglOperation *operation, gimp_operation_offset_get_offset (offset, FALSE, &x, &y); if (offset->type == GIMP_OFFSET_BACKGROUND && offset->context) - { - GimpRGB bg; - - gimp_context_get_background (offset->context, &bg); - - color = gimp_gegl_color_new (&bg, NULL); - } + color = gimp_context_get_background (offset->context); for (i = 0; i < 4; i++) { @@ -398,8 +392,6 @@ gimp_operation_offset_process (GeglOperation *operation, } } - g_clear_object (&color); - return TRUE; } diff --git a/app/paint/gimperaser.c b/app/paint/gimperaser.c index 68a535e50f..3148c3ed19 100644 --- a/app/paint/gimperaser.c +++ b/app/paint/gimperaser.c @@ -86,7 +86,7 @@ static gboolean gimp_eraser_get_color_history_color (GimpPaintbrush *paintbrush, GimpDrawable *drawable, GimpPaintOptions *paint_options, - GimpRGB *color) + GimpRGB *rgb) { /* Erasing on a drawable without alpha is equivalent to * drawing with background color. So let's save history. @@ -94,8 +94,10 @@ gimp_eraser_get_color_history_color (GimpPaintbrush *paintbrush, if (! gimp_drawable_has_alpha (drawable)) { GimpContext *context = GIMP_CONTEXT (paint_options); + GeglColor *color; - gimp_context_get_background (context, color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); return TRUE; } @@ -116,8 +118,10 @@ gimp_eraser_get_paint_params (GimpPaintbrush *paintbrush, { GimpEraserOptions *options = GIMP_ERASER_OPTIONS (paint_options); GimpContext *context = GIMP_CONTEXT (paint_options); + GeglColor *color; - gimp_context_get_background (context, paint_color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &paint_color->r, &paint_color->g, &paint_color->b, &paint_color->a, NULL); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), paint_color, paint_color); diff --git a/app/paint/gimpink.c b/app/paint/gimpink.c index f0b442e167..58de474d6e 100644 --- a/app/paint/gimpink.c +++ b/app/paint/gimpink.c @@ -169,12 +169,13 @@ gimp_ink_paint (GimpPaintCore *paint_core, case GIMP_PAINT_STATE_INIT: { GimpContext *context = GIMP_CONTEXT (paint_options); - GimpRGB foreground; + GeglColor *foreground; + GimpRGB rgb; gimp_symmetry_set_stateful (sym, TRUE); - gimp_context_get_foreground (context, &foreground); - gimp_palettes_add_color_history (context->gimp, - &foreground); + foreground = gimp_context_get_foreground (context); + gegl_color_get_pixel (foreground, babl_format_with_space ("R'G'B'A double", NULL), &rgb); + gimp_palettes_add_color_history (context->gimp, &rgb); if (cur_coords->x == last_coords.x && cur_coords->y == last_coords.y) @@ -352,7 +353,6 @@ gimp_ink_motion (GimpPaintCore *paint_core, gint paint_buffer_x; gint paint_buffer_y; GimpLayerMode paint_mode; - GimpRGB foreground; GeglColor *color; GimpBlob *last_blob; GimpCoords coords; @@ -445,11 +445,8 @@ gimp_ink_motion (GimpPaintCore *paint_core, } paint_mode = gimp_context_get_paint_mode (context); + color = gimp_context_get_foreground (context); - gimp_context_get_foreground (context, &foreground); - gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), - &foreground, &foreground); - color = gimp_gegl_color_new (&foreground, gimp_drawable_get_space (drawable)); ink->blobs_to_render = blobs_to_render; for (i = 0; i < n_strokes; i++) @@ -494,8 +491,6 @@ gimp_ink_motion (GimpPaintCore *paint_core, } - g_object_unref (color); - g_list_free_full (blobs_to_render, g_free); } diff --git a/app/paint/gimpmybrushcore.c b/app/paint/gimpmybrushcore.c index 6c06733299..d359ddeb93 100644 --- a/app/paint/gimpmybrushcore.c +++ b/app/paint/gimpmybrushcore.c @@ -204,6 +204,7 @@ gimp_mybrush_core_paint (GimpPaintCore *paint_core, GimpContext *context = GIMP_CONTEXT (paint_options); gint offset_x; gint offset_y; + GeglColor *color; GimpRGB fg; g_return_if_fail (g_list_length (drawables) == 1); @@ -211,7 +212,8 @@ gimp_mybrush_core_paint (GimpPaintCore *paint_core, switch (paint_state) { case GIMP_PAINT_STATE_INIT: - gimp_context_get_foreground (context, &fg); + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &fg.r, &fg.g, &fg.b, &fg.a, NULL); gimp_palettes_add_color_history (context->gimp, &fg); gimp_symmetry_set_stateful (sym, TRUE); @@ -392,6 +394,7 @@ gimp_mybrush_core_create_brushes (GimpMybrushCore *mybrush, { GimpMybrushOptions *options = GIMP_MYBRUSH_OPTIONS (paint_options); GimpContext *context = GIMP_CONTEXT (paint_options); + GeglColor *color; GimpRGB fg; GimpHSV hsv; gint n_strokes; @@ -405,9 +408,11 @@ gimp_mybrush_core_create_brushes (GimpMybrushCore *mybrush, } if (options->eraser) - gimp_context_get_background (context, &fg); + color = gimp_context_get_background (context); else - gimp_context_get_foreground (context, &fg); + color = gimp_context_get_foreground (context); + + gegl_color_get_rgba_with_space (color, &fg.r, &fg.g, &fg.b, &fg.a, NULL); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), &fg, &fg); diff --git a/app/paint/gimppaintbrush.c b/app/paint/gimppaintbrush.c index 16abbd6215..510186fec7 100644 --- a/app/paint/gimppaintbrush.c +++ b/app/paint/gimppaintbrush.c @@ -151,11 +151,12 @@ static gboolean gimp_paintbrush_real_get_color_history_color (GimpPaintbrush *paintbrush, GimpDrawable *drawable, GimpPaintOptions *paint_options, - GimpRGB *color) + GimpRGB *rgb) { GimpContext *context = GIMP_CONTEXT (paint_options); GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paintbrush); GimpDynamics *dynamics = gimp_context_get_dynamics (context); + GeglColor *color; /* We don't save gradient color history and pixmap brushes * have no color to save. @@ -166,7 +167,8 @@ gimp_paintbrush_real_get_color_history_color (GimpPaintbrush *paintbrush, return FALSE; } - gimp_context_get_foreground (context, color); + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); return TRUE; } @@ -213,7 +215,10 @@ gimp_paintbrush_real_get_paint_params (GimpPaintbrush *paintbrush, else { /* otherwise fill the area with the foreground color */ - gimp_context_get_foreground (context, paint_color); + GeglColor *color; + + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &paint_color->r, &paint_color->g, &paint_color->b, &paint_color->a, NULL); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), paint_color, paint_color); diff --git a/app/paint/gimpsmudge.c b/app/paint/gimpsmudge.c index c7f867ba2d..b8da702b94 100644 --- a/app/paint/gimpsmudge.c +++ b/app/paint/gimpsmudge.c @@ -160,10 +160,12 @@ gimp_smudge_paint (GimpPaintCore *paint_core, ! gimp_dynamics_is_output_enabled (dynamics, GIMP_DYNAMICS_OUTPUT_COLOR) && ! (brush_core->brush && gimp_brush_get_pixmap (brush_core->brush))) { - GimpRGB foreground; + GeglColor *foreground; + GimpRGB rgb; - gimp_context_get_foreground (context, &foreground); - gimp_palettes_add_color_history (context->gimp, &foreground); + foreground = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (foreground, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + gimp_palettes_add_color_history (context->gimp, &rgb); } } break; @@ -453,7 +455,10 @@ gimp_smudge_motion (GimpPaintCore *paint_core, } else { - gimp_context_get_foreground (context, &brush_color); + GeglColor *color; + + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &brush_color.r, &brush_color.g, &brush_color.b, &brush_color.a, NULL); } /* Convert to linear RGBA */ diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c index c9a39416a5..8b2df8af27 100644 --- a/app/pdb/context-cmds.c +++ b/app/pdb/context-cmds.c @@ -249,13 +249,13 @@ context_get_foreground_invoker (GimpProcedure *procedure, GError **error) { GimpValueArray *return_vals; - GimpRGB foreground = { 0.0, 0.0, 0.0, 1.0 }; + GeglColor *foreground = NULL; - gimp_context_get_foreground (context, &foreground); - gimp_rgb_set_alpha (&foreground, 1.0); + foreground = gegl_color_duplicate (gimp_context_get_foreground (context)); + gimp_color_set_alpha (foreground, 1.0); return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - gimp_value_set_rgb (gimp_value_array_index (return_vals, 1), &foreground); + g_value_take_object (gimp_value_array_index (return_vals, 1), foreground); return return_vals; } @@ -292,13 +292,13 @@ context_get_background_invoker (GimpProcedure *procedure, GError **error) { GimpValueArray *return_vals; - GimpRGB background = { 0.0, 0.0, 0.0, 1.0 }; + GeglColor *background = NULL; - gimp_context_get_background (context, &background); - gimp_rgb_set_alpha (&background, 1.0); + background = gegl_color_duplicate (gimp_context_get_background (context)); + gimp_color_set_alpha (background, 1.0); return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - gimp_value_set_rgb (gimp_value_array_index (return_vals, 1), &background); + g_value_take_object (gimp_value_array_index (return_vals, 1), background); return return_vals; } @@ -3258,12 +3258,11 @@ register_context_procs (GimpPDB *pdb) "Michael Natterer & Sven Neumann", "2004"); gimp_procedure_add_return_value (procedure, - gimp_param_spec_rgb ("foreground", - "foreground", - "The foreground color", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("foreground", + "foreground", + "The foreground color", + NULL, + GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); @@ -3305,12 +3304,11 @@ register_context_procs (GimpPDB *pdb) "Michael Natterer & Sven Neumann", "2004"); gimp_procedure_add_return_value (procedure, - gimp_param_spec_rgb ("background", - "background", - "The background color", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("background", + "background", + "The background color", + NULL, + GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c index 8b97133d0d..20721d7169 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -598,25 +598,27 @@ plug_in_applylens_invoker (GimpProcedure *procedure, GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; GeglNode *node; if (set_background) - gimp_context_get_background (context, &color); + { + color = gegl_color_duplicate (gimp_context_get_background (context)); + } else - gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0); - - gegl_color = gimp_gegl_color_new (&color, NULL); + { + color = gegl_color_new ("black"); + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 0.0, 0.0, NULL); + } node = gegl_node_new_child (NULL, "operation", "gegl:apply-lens", "refraction-index", refraction, "keep-surroundings", keep_surroundings, - "background-color", gegl_color, + "background-color", color, NULL); - g_object_unref (gegl_color); + g_object_unref (color); node = wrap_in_selection_bounds (node, drawable); @@ -1265,29 +1267,27 @@ plug_in_cubism_invoker (GimpProcedure *procedure, GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; GeglNode *node; if (bg_color) { - gimp_context_get_background (context, &color); - gimp_rgb_set_alpha (&color, 0.0); + color = gegl_color_duplicate (gimp_context_get_background (context)); + gimp_color_set_alpha (color, 0.0); } else { - gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0); + color = gegl_color_new ("black"); + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 0.0, 0.0, NULL); } - gegl_color = gimp_gegl_color_new (&color, NULL); - node = gegl_node_new_child (NULL, "operation", "gegl:cubism", "tile-size", tile_size, "tile-saturation", tile_saturation, - "bg-color", gegl_color, + "bg-color", color, NULL); - g_object_unref (gegl_color); + g_object_unref (color); gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Cubism"), @@ -2294,21 +2294,14 @@ plug_in_lens_distortion_invoker (GimpProcedure *procedure, gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node = NULL; - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; - gimp_context_get_background (context, &color); + color = gegl_color_duplicate (gimp_context_get_background (context)); if (gimp_drawable_has_alpha (drawable)) - { - gimp_rgb_set_alpha (&color, 0.0); - } + gimp_color_set_alpha (color, 0.0); else - { - gimp_rgb_set_alpha (&color, 1.0); - } - - gegl_color = gimp_gegl_color_new (&color, NULL); + gimp_color_set_alpha (color, 1.0); node = gegl_node_new_child (NULL, "operation", "gegl:lens-distortion", @@ -2318,10 +2311,10 @@ plug_in_lens_distortion_invoker (GimpProcedure *procedure, "x-shift", (gdouble) offset_x, "y-shift", (gdouble) offset_y, "brighten", (gdouble) brighten, - "background", gegl_color, + "background", color, NULL); - g_object_unref (gegl_color); + g_object_unref (color); node = wrap_in_selection_bounds (node, drawable); @@ -2410,13 +2403,9 @@ plug_in_maze_invoker (GimpProcedure *procedure, GeglNode *node; GeglColor *fg_color; GeglColor *bg_color; - GimpRGB color; - gimp_context_get_foreground (context, &color); - fg_color = gimp_gegl_color_new (&color, NULL); - - gimp_context_get_background (context, &color); - bg_color = gimp_gegl_color_new (&color, NULL); + fg_color = gimp_context_get_foreground (context); + bg_color = gimp_context_get_background (context); node = gegl_node_new_child (NULL, "operation", "gegl:maze", @@ -2429,9 +2418,6 @@ plug_in_maze_invoker (GimpProcedure *procedure, "bg-color", bg_color, NULL); - g_object_unref (fg_color); - g_object_unref (bg_color); - gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Maze"), node); @@ -2708,13 +2694,8 @@ plug_in_mosaic_invoker (GimpProcedure *procedure, if (grout_color) { - GimpRGB fgcolor, bgcolor; - - gimp_context_get_background (context, &bgcolor); - bg_color = gimp_gegl_color_new (&bgcolor, NULL); - - gimp_context_get_foreground (context, &fgcolor); - fg_color = gimp_gegl_color_new (&fgcolor, NULL); + bg_color = gegl_color_duplicate (gimp_context_get_background (context)); + fg_color = gegl_color_duplicate (gimp_context_get_foreground (context)); } else { @@ -3118,7 +3099,7 @@ plug_in_papertile_invoker (GimpProcedure *procedure, gboolean wrap_around; gboolean centering; gint background_type; - GimpRGB background_color; + GeglColor *background_color; drawable = g_value_get_object (gimp_value_array_index (args, 2)); tile_size = g_value_get_int (gimp_value_array_index (args, 3)); @@ -3127,7 +3108,7 @@ plug_in_papertile_invoker (GimpProcedure *procedure, wrap_around = g_value_get_boolean (gimp_value_array_index (args, 6)); centering = g_value_get_boolean (gimp_value_array_index (args, 7)); background_type = g_value_get_int (gimp_value_array_index (args, 8)); - gimp_value_get_rgb (gimp_value_array_index (args, 9), &background_color); + background_color = g_value_get_object (gimp_value_array_index (args, 9)); if (success) { @@ -3136,48 +3117,49 @@ plug_in_papertile_invoker (GimpProcedure *procedure, gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node; - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; gint bg_type; switch (background_type) { default: bg_type = background_type; - gimp_rgba_set (&color, 0.0, 0.0, 1.0, 1.0); + color = gegl_color_new (NULL); + /* XXX: I guess what we want is to set this color (why blue?) in the + * drawable's space, though I haven't looked too much into it. + */ + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 1.0, 1.0, gimp_drawable_get_space (drawable)); break; case 3: bg_type = 3; - gimp_context_get_foreground (context, &color); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); break; case 4: bg_type = 3; - gimp_context_get_background (context, &color); + color = gegl_color_duplicate (gimp_context_get_background (context)); break; case 5: bg_type = 3; - color = background_color; + color = gegl_color_duplicate (background_color); break; } - gegl_color = gimp_gegl_color_new (&color, NULL); - node = gegl_node_new_child (NULL, "operation", "gegl:tile-paper", "tile-width", tile_size, "tile-height", tile_size, "move-rate", move_max, - "bg-color", gegl_color, + "bg-color", color, "centering", centering, "wrap-around", wrap_around, "background-type", bg_type, "fractional-type", fractional_type, NULL); - g_object_unref (gegl_color); + g_object_unref (color); gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Paper Tile"), @@ -3963,15 +3945,17 @@ plug_in_semiflatten_invoker (GimpProcedure *procedure, gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) && gimp_drawable_has_alpha (drawable)) { - GeglNode *node; - GimpRGB color; + GeglNode *node; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_background (context, &color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); node = gegl_node_new_child (NULL, "operation", "gimp:semi-flatten", - "color", &color, + "color", &rgb, NULL); gimp_drawable_apply_operation (drawable, progress, @@ -4047,8 +4031,8 @@ plug_in_sinus_invoker (GimpProcedure *procedure, gboolean tiling; gboolean perturb; gint colors; - GimpRGB col1; - GimpRGB col2; + GeglColor *col1; + GeglColor *col2; gdouble alpha1; gdouble alpha2; gint blend; @@ -4062,8 +4046,8 @@ plug_in_sinus_invoker (GimpProcedure *procedure, tiling = g_value_get_boolean (gimp_value_array_index (args, 7)); perturb = g_value_get_boolean (gimp_value_array_index (args, 8)); colors = g_value_get_int (gimp_value_array_index (args, 9)); - gimp_value_get_rgb (gimp_value_array_index (args, 10), &col1); - gimp_value_get_rgb (gimp_value_array_index (args, 11), &col2); + col1 = g_value_get_object (gimp_value_array_index (args, 10)); + col2 = g_value_get_object (gimp_value_array_index (args, 11)); alpha1 = g_value_get_double (gimp_value_array_index (args, 12)); alpha2 = g_value_get_double (gimp_value_array_index (args, 13)); blend = g_value_get_int (gimp_value_array_index (args, 14)); @@ -4076,28 +4060,30 @@ plug_in_sinus_invoker (GimpProcedure *procedure, gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node; - GeglColor *gegl_color1; - GeglColor *gegl_color2; - gint x, y, width, height; + GeglColor *gegl_color1 = NULL; + GeglColor *gegl_color2 = NULL; + gint x, y, width, height; switch (colors) { case 0: - gimp_rgb_set (&col1, 0.0, 0.0, 0.0); - gimp_rgb_set (&col2, 1.0, 1.0, 1.0); + gegl_color1 = gegl_color_new ("black"); + gegl_color2 = gegl_color_new ("white"); break; case 1: - gimp_context_get_foreground (context, &col1); - gimp_context_get_background (context, &col2); + gegl_color1 = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color2 = gegl_color_duplicate (gimp_context_get_background (context)); break; } - gimp_rgb_set_alpha (&col1, alpha1); - gimp_rgb_set_alpha (&col2, alpha2); - - gegl_color1 = gimp_gegl_color_new (&col1, NULL); - gegl_color2 = gimp_gegl_color_new (&col2, NULL); + if (gegl_color1 == NULL) + { + gegl_color1 = gegl_color_duplicate (col1); + gegl_color2 = gegl_color_duplicate (col2); + } + gimp_color_set_alpha (gegl_color1, alpha1); + gimp_color_set_alpha (gegl_color2, alpha2); gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); @@ -4536,8 +4522,7 @@ plug_in_vpropagate_invoker (GimpProcedure *procedure, gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node; - GimpRGB color; - GeglColor *gegl_color = NULL; + GeglColor *color = NULL; gint gegl_mode = 0; gboolean to_left = (direction_mask & (0x1 << 0)) != 0; gboolean to_top = (direction_mask & (0x1 << 1)) != 0; @@ -4561,16 +4546,14 @@ plug_in_vpropagate_invoker (GimpProcedure *procedure, { gegl_mode = propagate_mode; - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); } else { gegl_mode = 4; - gimp_context_get_background (context, &color); + color = gimp_context_get_background (context); } - - gegl_color = gimp_gegl_color_new (&color, NULL); break; case 6: @@ -4586,7 +4569,7 @@ plug_in_vpropagate_invoker (GimpProcedure *procedure, "lower-threshold", (gdouble) lower_limit / 255.0, "upper-threshold", (gdouble) upper_limit / 255.0, "rate", propagating_rate, - "color", gegl_color, + "color", color, "top", to_top, "left", to_left, "right", to_right, @@ -4595,9 +4578,6 @@ plug_in_vpropagate_invoker (GimpProcedure *procedure, "alpha", alpha, NULL); - if (gegl_color) - g_object_unref (gegl_color); - gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Value Propagate"), node); @@ -7896,12 +7876,11 @@ register_plug_in_compat_procs (GimpPDB *pdb) 0, 5, 0, GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, - gimp_param_spec_rgb ("background-color", - "background color", - "Background color (for background-type == 5)", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("background-color", + "background color", + "Background color (for background-type == 5)", + NULL, + GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, g_param_spec_int ("background-alpha", "background alpha", @@ -8870,19 +8849,17 @@ register_plug_in_compat_procs (GimpPDB *pdb) 0, 2, 0, GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, - gimp_param_spec_rgb ("col1", - "col1", - "fist color (sometimes unused)", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("col1", + "col1", + "fist color (sometimes unused)", + NULL, + GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, - gimp_param_spec_rgb ("col2", - "col2", - "second color (sometimes unused)", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("col2", + "col2", + "second color (sometimes unused)", + NULL, + GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, g_param_spec_double ("alpha1", "alpha1", diff --git a/app/pdb/text-layer-cmds.c b/app/pdb/text-layer-cmds.c index 21c87f36ec..fef0f974c1 100644 --- a/app/pdb/text-layer-cmds.c +++ b/app/pdb/text-layer-cmds.c @@ -76,20 +76,23 @@ text_layer_new_invoker (GimpProcedure *procedure, if (success) { - GimpText *gimp_text; - GimpRGB color; + GimpText *gimp_text; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); gimp_text = g_object_new (GIMP_TYPE_TEXT, "text", text, "font", font, "font-size", size, "font-size-unit", unit, - "color", &color, + "color", &rgb, NULL); layer = GIMP_TEXT_LAYER (gimp_text_layer_new (image, gimp_text)); + g_object_unref (color); g_object_unref (gimp_text); if (! layer) diff --git a/app/text/gimptext-compat.c b/app/text/gimptext-compat.c index b9a35d3a37..a72008bab0 100644 --- a/app/text/gimptext-compat.c +++ b/app/text/gimptext-compat.c @@ -60,7 +60,8 @@ text_render (GimpImage *image, { GimpText *gtext; GimpLayer *layer; - GimpRGB color; + GeglColor *color; + GimpRGB rgb; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL); @@ -76,7 +77,8 @@ text_render (GimpImage *image, if (border < 0) border = 0; - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); gtext = g_object_new (GIMP_TYPE_TEXT, "text", text, @@ -84,7 +86,7 @@ text_render (GimpImage *image, "font-size", font_size, "antialias", antialias, "border", border, - "color", &color, + "color", &rgb, NULL); layer = gimp_text_layer_new (image, gtext); diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c index 144c61a475..f34c5c4127 100644 --- a/app/tools/gimpoperationtool.c +++ b/app/tools/gimpoperationtool.c @@ -494,19 +494,18 @@ gimp_operation_tool_sync_op (GimpOperationTool *op_tool, } else if (sync_colors) { + GeglColor *color = NULL; + GimpRGB rgb; + if (HAS_KEY (pspec, "role", "color-primary")) - { - GimpRGB color; - - gimp_context_get_foreground (GIMP_CONTEXT (options), &color); - g_object_set (filter_tool->config, pspec->name, &color, NULL); - } + color = gimp_context_get_foreground (GIMP_CONTEXT (options)); else if (sync_colors && HAS_KEY (pspec, "role", "color-secondary")) - { - GimpRGB color; + color = gimp_context_get_background (GIMP_CONTEXT (options)); - gimp_context_get_background (GIMP_CONTEXT (options), &color); - g_object_set (filter_tool->config, pspec->name, &color, NULL); + if (color != NULL) + { + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + g_object_set (filter_tool->config, pspec->name, &rgb, NULL); } } } diff --git a/app/tools/gimptextoptions.c b/app/tools/gimptextoptions.c index b1d712c927..15879b7f92 100644 --- a/app/tools/gimptextoptions.c +++ b/app/tools/gimptextoptions.c @@ -683,15 +683,17 @@ gimp_text_options_notify_color (GimpContext *context, GParamSpec *pspec, GimpText *text) { - GimpRGB color; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); g_signal_handlers_block_by_func (text, gimp_text_options_notify_text_color, context); - g_object_set (text, "color", &color, NULL); + g_object_set (text, "color", &rgb, NULL); g_signal_handlers_unblock_by_func (text, gimp_text_options_notify_text_color, @@ -725,19 +727,21 @@ gimp_text_options_connect_text (GimpTextOptions *options, GimpText *text) { GimpContext *context; - GimpRGB color; + GeglColor *color; + GimpRGB rgb; g_return_if_fail (GIMP_IS_TEXT_OPTIONS (options)); g_return_if_fail (GIMP_IS_TEXT (text)); context = GIMP_CONTEXT (options); - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); gimp_config_sync (G_OBJECT (options), G_OBJECT (text), 0); g_object_set (text, - "color", &color, + "color", &rgb, "font", gimp_context_get_font (context), NULL); @@ -851,8 +855,8 @@ gimp_text_options_gui (GimpToolOptions *tool_options) button, 1); gtk_size_group_add_widget (size_group, button); - button = gimp_prop_color_button_new (config, "foreground", _("Text Color"), - 40, 24, GIMP_COLOR_AREA_FLAT); + button = gimp_prop_gegl_color_button_new (config, "foreground", _("Text Color"), + 40, 24, GIMP_COLOR_AREA_FLAT); gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE); gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), GIMP_CONTEXT (options)); diff --git a/app/widgets/gimpcolordialog.c b/app/widgets/gimpcolordialog.c index 9a024a6d33..ee9e8be076 100644 --- a/app/widgets/gimpcolordialog.c +++ b/app/widgets/gimpcolordialog.c @@ -609,11 +609,13 @@ gimp_color_dialog_colormap_add_activate (GimpColorDialog *dialog) viewable_dialog->context) { GimpContext *user_context = viewable_dialog->context->gimp->user_context; - GimpRGB color; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_foreground (user_context, &color); + color = gimp_context_get_foreground (user_context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); - gimp_image_add_colormap_entry (dialog->active_image, &color); + gimp_image_add_colormap_entry (dialog->active_image, &rgb); gimp_image_flush (dialog->active_image); } } diff --git a/app/widgets/gimpcoloreditor.c b/app/widgets/gimpcoloreditor.c index 091c0f1fad..3cb688a6de 100644 --- a/app/widgets/gimpcoloreditor.c +++ b/app/widgets/gimpcoloreditor.c @@ -78,10 +78,10 @@ static void gimp_color_editor_set_context (GimpDocked *docked, GimpContext *context); static void gimp_color_editor_fg_changed (GimpContext *context, - const GimpRGB *rgb, + GeglColor *color, GimpColorEditor *editor); static void gimp_color_editor_bg_changed (GimpContext *context, - const GimpRGB *rgb, + GeglColor *color, GimpColorEditor *editor); static void gimp_color_editor_color_changed (GimpColorSelector *selector, const GimpRGB *rgb, @@ -455,7 +455,7 @@ gimp_color_editor_set_context (GimpDocked *docked, if (editor->context) { - GimpRGB rgb; + GeglColor *color; g_object_ref (editor->context); @@ -481,13 +481,13 @@ gimp_color_editor_set_context (GimpDocked *docked, if (editor->edit_bg) { - gimp_context_get_background (editor->context, &rgb); - gimp_color_editor_bg_changed (editor->context, &rgb, editor); + color = gimp_context_get_background (editor->context); + gimp_color_editor_bg_changed (editor->context, color, editor); } else { - gimp_context_get_foreground (editor->context, &rgb); - gimp_color_editor_fg_changed (editor->context, &rgb, editor); + color = gimp_context_get_foreground (editor->context); + gimp_color_editor_fg_changed (editor->context, color, editor); } g_object_set_data (G_OBJECT (context->gimp->config->color_management), @@ -536,18 +536,20 @@ gimp_color_editor_style_updated (GtkWidget *widget) static void gimp_color_editor_set_color (GimpColorEditor *editor, - const GimpRGB *rgb) + GeglColor *color) { + GimpRGB rgb; GimpHSV hsv; - gimp_rgb_to_hsv (rgb, &hsv); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); + gimp_rgb_to_hsv (&rgb, &hsv); g_signal_handlers_block_by_func (editor->notebook, gimp_color_editor_color_changed, editor); gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (editor->notebook), - rgb, &hsv); + &rgb, &hsv); g_signal_handlers_unblock_by_func (editor->notebook, gimp_color_editor_color_changed, @@ -558,7 +560,7 @@ gimp_color_editor_set_color (GimpColorEditor *editor, editor); gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (editor->hex_entry), - rgb); + &rgb); g_signal_handlers_unblock_by_func (editor->hex_entry, gimp_color_editor_entry_changed, @@ -567,20 +569,20 @@ gimp_color_editor_set_color (GimpColorEditor *editor, static void gimp_color_editor_fg_changed (GimpContext *context, - const GimpRGB *rgb, + GeglColor *color, GimpColorEditor *editor) { if (! editor->edit_bg) - gimp_color_editor_set_color (editor, rgb); + gimp_color_editor_set_color (editor, color); } static void gimp_color_editor_bg_changed (GimpContext *context, - const GimpRGB *rgb, + GeglColor *color, GimpColorEditor *editor) { if (editor->edit_bg) - gimp_color_editor_set_color (editor, rgb); + gimp_color_editor_set_color (editor, color); } static void @@ -675,17 +677,17 @@ gimp_color_editor_fg_bg_notify (GtkWidget *widget, if (editor->context) { - GimpRGB rgb; + GeglColor *color; if (edit_bg) { - gimp_context_get_background (editor->context, &rgb); - gimp_color_editor_bg_changed (editor->context, &rgb, editor); + color = gimp_context_get_background (editor->context); + gimp_color_editor_bg_changed (editor->context, color, editor); } else { - gimp_context_get_foreground (editor->context, &rgb); - gimp_color_editor_fg_changed (editor->context, &rgb, editor); + color = gimp_context_get_foreground (editor->context); + gimp_color_editor_fg_changed (editor->context, color, editor); } } } diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c index c03df05074..a9b00dcc87 100644 --- a/app/widgets/gimpcolorpanel.c +++ b/app/widgets/gimpcolorpanel.c @@ -129,7 +129,7 @@ gimp_color_panel_button_press (GtkWidget *widget, GimpColorPanel *color_panel; GSimpleActionGroup *group; GimpAction *action; - GimpRGB color; + GimpRGB rgb; color_button = GIMP_COLOR_BUTTON (widget); color_panel = GIMP_COLOR_PANEL (widget); @@ -144,22 +144,26 @@ gimp_color_panel_button_press (GtkWidget *widget, if (color_panel->context) { + GeglColor *color; + action = GIMP_ACTION (g_action_map_lookup_action (G_ACTION_MAP (group), "use-foreground")); - gimp_context_get_foreground (color_panel->context, &color); - g_object_set (action, "color", &color, NULL); + color = gimp_context_get_foreground (color_panel->context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + g_object_set (action, "color", &rgb, NULL); action = GIMP_ACTION (g_action_map_lookup_action (G_ACTION_MAP (group), "use-background")); - gimp_context_get_background (color_panel->context, &color); - g_object_set (action, "color", &color, NULL); + color = gegl_color_duplicate (gimp_context_get_background (color_panel->context)); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); + g_object_set (action, "color", &rgb, NULL); } action = GIMP_ACTION (g_action_map_lookup_action (G_ACTION_MAP (group), "use-black")); - gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); - g_object_set (action, "color", &color, NULL); + gimp_rgba_set (&rgb, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); + g_object_set (action, "color", &rgb, NULL); action = GIMP_ACTION (g_action_map_lookup_action (G_ACTION_MAP (group), "use-white")); - gimp_rgba_set (&color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); - g_object_set (action, "color", &color, NULL); + gimp_rgba_set (&rgb, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); + g_object_set (action, "color", &rgb, NULL); } if (GTK_WIDGET_CLASS (parent_class)->button_press_event) diff --git a/app/widgets/gimpdevicestatus.c b/app/widgets/gimpdevicestatus.c index c873dc1dae..cba7d4d9fe 100644 --- a/app/widgets/gimpdevicestatus.c +++ b/app/widgets/gimpdevicestatus.c @@ -551,18 +551,19 @@ gimp_device_status_notify_info (GimpDeviceInfo *device_info, if (! strcmp (pspec->name, "tool-options")) { - GimpRGB color; - guchar r, g, b; - gchar buf[64]; + GeglColor *color; + guchar rgb[3]; + gchar buf[64]; - gimp_context_get_foreground (entry->context, &color); - gimp_rgb_get_uchar (&color, &r, &g, &b); - g_snprintf (buf, sizeof (buf), _("Foreground: %d, %d, %d"), r, g, b); + color = gimp_context_get_foreground (entry->context); + /* TODO: which space to use exactly to provide more useful info? */ + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B' u8", NULL), rgb); + g_snprintf (buf, sizeof (buf), _("Foreground: %d, %d, %d"), rgb[0], rgb[1], rgb[2]); gimp_help_set_help_data (entry->foreground, buf, NULL); - gimp_context_get_background (entry->context, &color); - gimp_rgb_get_uchar (&color, &r, &g, &b); - g_snprintf (buf, sizeof (buf), _("Background: %d, %d, %d"), r, g, b); + color = gimp_context_get_background (entry->context); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B' u8", NULL), rgb); + g_snprintf (buf, sizeof (buf), _("Background: %d, %d, %d"), rgb[0], rgb[1], rgb[2]); gimp_help_set_help_data (entry->background, buf, NULL); } } diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c index ee6ae531b0..adacaa89e8 100644 --- a/app/widgets/gimpfgbgeditor.c +++ b/app/widgets/gimpfgbgeditor.c @@ -347,7 +347,6 @@ gimp_fg_bg_editor_draw (GtkWidget *widget, gint width, height; gint default_w, default_h; gint swap_w, swap_h; - GimpRGB color; gtk_style_context_save (style); @@ -435,20 +434,25 @@ gimp_fg_bg_editor_draw (GtkWidget *widget, if (editor->context) { + GeglColor *color; + GimpRGB rgb; + /* draw the background frame */ - gimp_context_get_background (editor->context, &color); + color = gimp_context_get_background (editor->context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); rect.x = width - rect.width - border.right; rect.y = height - rect.height - border.bottom; - gimp_fg_bg_editor_draw_color_frame (editor, cr, &color, + gimp_fg_bg_editor_draw_color_frame (editor, cr, &rgb, rect.x, rect.y, rect.width, rect.height, -1, -1); /* draw the foreground frame */ - gimp_context_get_foreground (editor->context, &color); + color = gimp_context_get_foreground (editor->context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); rect.x = border.left; rect.y = border.top; - gimp_fg_bg_editor_draw_color_frame (editor, cr, &color, + gimp_fg_bg_editor_draw_color_frame (editor, cr, &rgb, rect.x, rect.y, rect.width, rect.height, +1, +1); @@ -742,24 +746,28 @@ gimp_fg_bg_editor_set_active (GimpFgBgEditor *editor, static void gimp_fg_bg_editor_drag_color (GtkWidget *widget, - GimpRGB *color, + GimpRGB *rgb, gpointer data) { GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget); + GeglColor *color = NULL; if (editor->context) { switch (editor->active_color) { case GIMP_ACTIVE_COLOR_FOREGROUND: - gimp_context_get_foreground (editor->context, color); + color = gimp_context_get_foreground (editor->context); break; case GIMP_ACTIVE_COLOR_BACKGROUND: - gimp_context_get_background (editor->context, color); + color = gimp_context_get_background (editor->context); break; } } + + if (color != NULL) + gegl_color_get_rgba_with_space (color, &rgb->r, &rgb->g, &rgb->b, &rgb->a, NULL); } static void diff --git a/app/widgets/gimpfgbgview.c b/app/widgets/gimpfgbgview.c index e1ca7d568b..43e25c005a 100644 --- a/app/widgets/gimpfgbgview.c +++ b/app/widgets/gimpfgbgview.c @@ -161,7 +161,8 @@ gimp_fg_bg_view_draw (GtkWidget *widget, GtkBorder border; GtkBorder padding; GdkRectangle rect; - GimpRGB color; + GeglColor *color; + GimpRGB rgb; gtk_widget_get_allocation (widget, &allocation); @@ -190,17 +191,18 @@ gimp_fg_bg_view_draw (GtkWidget *widget, if (view->context) { - gimp_context_get_background (view->context, &color); + color = gimp_context_get_background (view->context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); if (view->transform) gimp_color_transform_process_pixels (view->transform, babl_format ("R'G'B'A double"), - &color, + &rgb, babl_format ("R'G'B'A double"), - &color, + &rgb, 1); - gimp_cairo_set_source_rgb (cr, &color); + gimp_cairo_set_source_rgb (cr, &rgb); cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height); cairo_fill (cr); @@ -217,17 +219,18 @@ gimp_fg_bg_view_draw (GtkWidget *widget, if (view->context) { - gimp_context_get_foreground (view->context, &color); + color = gimp_context_get_foreground (view->context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); if (view->transform) gimp_color_transform_process_pixels (view->transform, babl_format ("R'G'B'A double"), - &color, + &rgb, babl_format ("R'G'B'A double"), - &color, + &rgb, 1); - gimp_cairo_set_source_rgb (cr, &color); + gimp_cairo_set_source_rgb (cr, &rgb); cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height); cairo_fill (cr); diff --git a/app/widgets/gimpfilleditor.c b/app/widgets/gimpfilleditor.c index 6601003fe6..6d55ee8544 100644 --- a/app/widgets/gimpfilleditor.c +++ b/app/widgets/gimpfilleditor.c @@ -137,11 +137,11 @@ gimp_fill_editor_constructed (GObject *object) if (editor->use_custom_style) { - color_button = gimp_prop_color_button_new (G_OBJECT (editor->options), - "foreground", - _("Fill Color"), - 1, 24, - GIMP_COLOR_AREA_SMALL_CHECKS); + color_button = gimp_prop_gegl_color_button_new (G_OBJECT (editor->options), + "foreground", + _("Fill Color"), + 1, 24, + GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button), GIMP_CONTEXT (editor->options)); gimp_enum_radio_box_add (GTK_BOX (box), color_button, @@ -149,21 +149,21 @@ gimp_fill_editor_constructed (GObject *object) } else { - color_button = gimp_prop_color_button_new (G_OBJECT (editor->options), - "foreground", - _("Fill Color"), - 1, 24, - GIMP_COLOR_AREA_SMALL_CHECKS); + color_button = gimp_prop_gegl_color_button_new (G_OBJECT (editor->options), + "foreground", + _("Fill Color"), + 1, 24, + GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button), GIMP_CONTEXT (editor->options)); gimp_enum_radio_box_add (GTK_BOX (box), color_button, GIMP_FILL_STYLE_FG_COLOR, FALSE); - color_button = gimp_prop_color_button_new (G_OBJECT (editor->options), - "background", - _("Fill BG Color"), - 1, 24, - GIMP_COLOR_AREA_SMALL_CHECKS); + color_button = gimp_prop_gegl_color_button_new (G_OBJECT (editor->options), + "background", + _("Fill BG Color"), + 1, 24, + GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button), GIMP_CONTEXT (editor->options)); gimp_enum_radio_box_add (GTK_BOX (box), color_button, diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c index 6975b660f0..295deba2af 100644 --- a/app/widgets/gimppropwidgets.c +++ b/app/widgets/gimppropwidgets.c @@ -337,11 +337,16 @@ gimp_prop_layer_mode_box_new (GObject *config, /* color button */ /******************/ -static void gimp_prop_color_button_callback (GtkWidget *widget, - GObject *config); -static void gimp_prop_color_button_notify (GObject *config, - GParamSpec *param_spec, - GtkWidget *button); +static void gimp_prop_color_button_callback (GtkWidget *widget, + GObject *config); +static void gimp_prop_color_button_notify (GObject *config, + GParamSpec *param_spec, + GtkWidget *button); +static void gimp_prop_gegl_color_button_callback (GtkWidget *widget, + GObject *config); +static void gimp_prop_gegl_color_button_notify (GObject *config, + GParamSpec *param_spec, + GtkWidget *button); /** * gimp_prop_color_button_new: @@ -404,6 +409,73 @@ gimp_prop_color_button_new (GObject *config, return button; } +/** + * gimp_prop_gegl_color_button_new: + * @config: #GimpConfig object to which property is attached. + * @property_name: Name of #GeglColor property. + * @title: Title of the #GimpColorPanel that is to be created + * @width: Width of color button. + * @height: Height of color button. + * @type: How transparency is represented. + * + * Creates a #GimpColorPanel to set and display the value of a #GimpRGB + * property. Pressing the button brings up a color selector dialog. + * If @title is %NULL, the @property_name's nick will be used as label + * of the returned widget. + * + * TODO: this is meant to replace completely gimp_prop_color_button_new(). + * + * Returns: A new #GimpColorPanel widget. + * + * Since GIMP 2.4 + */ +GtkWidget * +gimp_prop_gegl_color_button_new (GObject *config, + const gchar *property_name, + const gchar *title, + gint width, + gint height, + GimpColorAreaType type) +{ + GParamSpec *param_spec; + GtkWidget *button; + GeglColor *color = NULL; + GimpRGB value; + + param_spec = check_param_spec_w (config, property_name, + GEGL_TYPE_PARAM_COLOR, G_STRFUNC); + if (! param_spec) + return NULL; + + if (! title) + title = g_param_spec_get_nick (param_spec); + + g_object_get (config, + property_name, &color, + NULL); + + if (color != NULL) + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &value); + + button = gimp_color_panel_new (title, &value, type, width, height); + g_clear_object (&color); + + set_param_spec (G_OBJECT (button), button, param_spec); + + g_signal_connect (button, "color-changed", + G_CALLBACK (gimp_prop_gegl_color_button_callback), + config); + + connect_notify (config, property_name, + G_CALLBACK (gimp_prop_gegl_color_button_notify), + button); + + gimp_widget_set_bound_property (button, config, property_name); + gtk_widget_show (button); + + return button; +} + static void gimp_prop_color_button_callback (GtkWidget *button, GObject *config) @@ -454,6 +526,63 @@ gimp_prop_color_button_notify (GObject *config, config); } +static void +gimp_prop_gegl_color_button_callback (GtkWidget *button, + GObject *config) +{ + GParamSpec *param_spec; + GeglColor *color; + GimpRGB value; + + param_spec = get_param_spec (G_OBJECT (button)); + if (! param_spec) + return; + + gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &value); + + color = gegl_color_new (NULL); + gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), &value); + g_signal_handlers_block_by_func (config, + gimp_prop_color_button_notify, + button); + + g_object_set (config, + param_spec->name, color, + NULL); + + g_signal_handlers_unblock_by_func (config, + gimp_prop_color_button_notify, + button); + + g_object_unref (color); +} + +static void +gimp_prop_gegl_color_button_notify (GObject *config, + GParamSpec *param_spec, + GtkWidget *button) +{ + GeglColor *color; + GimpRGB value; + + g_object_get (config, + param_spec->name, &color, + NULL); + + g_signal_handlers_block_by_func (button, + gimp_prop_color_button_callback, + config); + + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &value); + gimp_color_button_set_color (GIMP_COLOR_BUTTON (button), &value); + + g_clear_object (&color); + + g_signal_handlers_unblock_by_func (button, + gimp_prop_color_button_callback, + config); +} + /************/ /* angles */ diff --git a/app/widgets/gimppropwidgets.h b/app/widgets/gimppropwidgets.h index 20c8cc6e3a..643c57b8b3 100644 --- a/app/widgets/gimppropwidgets.h +++ b/app/widgets/gimppropwidgets.h @@ -54,6 +54,15 @@ GtkWidget * gimp_prop_color_button_new (GObject *config, gint height, GimpColorAreaType type); +/* GeglParamColor */ + +GtkWidget * gimp_prop_gegl_color_button_new (GObject *config, + const gchar *property_name, + const gchar *title, + gint width, + gint height, + GimpColorAreaType type); + /* GParamDouble */ diff --git a/app/widgets/gimptoolbox-color-area.c b/app/widgets/gimptoolbox-color-area.c index 9d107ca8e1..f06aed91f0 100644 --- a/app/widgets/gimptoolbox-color-area.c +++ b/app/widgets/gimptoolbox-color-area.c @@ -46,10 +46,10 @@ /* local function prototypes */ static void color_area_foreground_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpColorDialog *dialog); static void color_area_background_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpColorDialog *dialog); static void color_area_dialog_update (GimpColorDialog *dialog, @@ -122,18 +122,21 @@ gimp_toolbox_color_area_create (GimpToolbox *toolbox, static void color_area_foreground_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpColorDialog *dialog) { if (edit_color == GIMP_ACTIVE_COLOR_FOREGROUND) { + GimpRGB rgb; + + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); g_signal_handlers_block_by_func (dialog, color_area_dialog_update, context); /* FIXME this should use GimpColorDialog API */ gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection), - color); + &rgb); g_signal_handlers_unblock_by_func (dialog, color_area_dialog_update, @@ -143,18 +146,21 @@ color_area_foreground_changed (GimpContext *context, static void color_area_background_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpColorDialog *dialog) { if (edit_color == GIMP_ACTIVE_COLOR_BACKGROUND) { + GimpRGB rgb; + + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); g_signal_handlers_block_by_func (dialog, color_area_dialog_update, context); /* FIXME this should use GimpColorDialog API */ gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection), - color); + &rgb); g_signal_handlers_unblock_by_func (dialog, color_area_dialog_update, @@ -227,23 +233,28 @@ color_area_color_clicked (GimpFgBgEditor *editor, GimpActiveColor active_color, GimpContext *context) { - GimpRGB color; + GeglColor *color; + GimpRGB rgb; const gchar *title; if (! color_dialog_active) { - gimp_context_get_foreground (context, &revert_fg); - gimp_context_get_background (context, &revert_bg); + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &revert_fg.r, &revert_fg.g, &revert_fg.b, &revert_fg.a, NULL); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &revert_bg.r, &revert_bg.g, &revert_bg.b, &revert_bg.a, NULL); } if (active_color == GIMP_ACTIVE_COLOR_FOREGROUND) { - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); title = _("Change Foreground Color"); } else { - gimp_context_get_background (context, &color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); title = _("Change Background Color"); } @@ -256,7 +267,7 @@ color_area_color_clicked (GimpFgBgEditor *editor, GTK_WIDGET (editor), gimp_dialog_factory_get_singleton (), "gimp-toolbox-color-dialog", - &color, + &rgb, TRUE, FALSE); g_signal_connect_object (color_dialog, "update", @@ -279,7 +290,7 @@ color_area_color_clicked (GimpFgBgEditor *editor, } gtk_window_set_title (GTK_WINDOW (color_dialog), title); - gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (color_dialog), &color); + gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (color_dialog), &rgb); gtk_window_present (GTK_WINDOW (color_dialog)); color_dialog_active = TRUE; diff --git a/app/widgets/gimpviewrenderergradient.c b/app/widgets/gimpviewrenderergradient.c index a2820fcbd3..6baaf3ec6b 100644 --- a/app/widgets/gimpviewrenderergradient.c +++ b/app/widgets/gimpviewrenderergradient.c @@ -69,7 +69,7 @@ gimp_view_renderer_gradient_init (GimpViewRendererGradient *renderer) static void gimp_view_renderer_gradient_fg_bg_changed (GimpContext *context, - const GimpRGB *color, + GeglColor *color, GimpViewRenderer *renderer) { #if 0 diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c index f59a64476d..851e040c56 100644 --- a/libgimp/gimpcontext_pdb.c +++ b/libgimp/gimpcontext_pdb.c @@ -328,7 +328,6 @@ gimp_context_set_stroke_method (GimpStrokeMethod stroke_method) /** * gimp_context_get_foreground: - * @foreground: (out caller-allocates): The foreground color. * * Get the current GIMP foreground color. * @@ -336,16 +335,16 @@ gimp_context_set_stroke_method (GimpStrokeMethod stroke_method) * used in a variety of tools such as paint tools, blending, and bucket * fill. * - * Returns: TRUE on success. + * Returns: (transfer full): The foreground color. * * Since: 2.2 **/ -gboolean -gimp_context_get_foreground (GimpRGB *foreground) +GeglColor * +gimp_context_get_foreground (void) { GimpValueArray *args; GimpValueArray *return_vals; - gboolean success = TRUE; + GeglColor *foreground = NULL; args = gimp_value_array_new_from_types (NULL, G_TYPE_NONE); @@ -355,14 +354,12 @@ gimp_context_get_foreground (GimpRGB *foreground) args); gimp_value_array_unref (args); - success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; - - if (success) - GIMP_VALUES_GET_RGB (return_vals, 1, &*foreground); + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + foreground = g_value_dup_object (gimp_value_array_index (return_vals, 1)); gimp_value_array_unref (return_vals); - return success; + return foreground; } /** @@ -404,7 +401,6 @@ gimp_context_set_foreground (GeglColor *foreground) /** * gimp_context_get_background: - * @background: (out caller-allocates): The background color. * * Get the current GIMP background color. * @@ -412,16 +408,16 @@ gimp_context_set_foreground (GeglColor *foreground) * used in a variety of tools such as blending, erasing (with non-alpha * images), and image filling. * - * Returns: TRUE on success. + * Returns: (transfer full): The background color. * * Since: 2.2 **/ -gboolean -gimp_context_get_background (GimpRGB *background) +GeglColor * +gimp_context_get_background (void) { GimpValueArray *args; GimpValueArray *return_vals; - gboolean success = TRUE; + GeglColor *background = NULL; args = gimp_value_array_new_from_types (NULL, G_TYPE_NONE); @@ -431,14 +427,12 @@ gimp_context_get_background (GimpRGB *background) args); gimp_value_array_unref (args); - success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; - - if (success) - GIMP_VALUES_GET_RGB (return_vals, 1, &*background); + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + background = g_value_dup_object (gimp_value_array_index (return_vals, 1)); gimp_value_array_unref (return_vals); - return success; + return background; } /** diff --git a/libgimp/gimpcontext_pdb.h b/libgimp/gimpcontext_pdb.h index b5a7e7c51a..83c57571b7 100644 --- a/libgimp/gimpcontext_pdb.h +++ b/libgimp/gimpcontext_pdb.h @@ -40,9 +40,9 @@ gchar* gimp_context_get_paint_method (void) gboolean gimp_context_set_paint_method (const gchar *name); GimpStrokeMethod gimp_context_get_stroke_method (void); gboolean gimp_context_set_stroke_method (GimpStrokeMethod stroke_method); -gboolean gimp_context_get_foreground (GimpRGB *foreground); +GeglColor* gimp_context_get_foreground (void); gboolean gimp_context_set_foreground (GeglColor *foreground); -gboolean gimp_context_get_background (GimpRGB *background); +GeglColor* gimp_context_get_background (void); gboolean gimp_context_set_background (GeglColor *background); gboolean gimp_context_set_default_colors (void); gboolean gimp_context_swap_colors (void); diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c index 1cbb1fa73b..4433791966 100644 --- a/libgimp/gimpproceduredialog.c +++ b/libgimp/gimpproceduredialog.c @@ -606,6 +606,7 @@ gimp_procedure_dialog_set_ok_label (GimpProcedureDialog *dialog, * Please use gimp_procedure_dialog_get_color_widget() for a * non-editable color area with a label. * * %GIMP_TYPE_COLOR_BUTTON: a color button with no label. + * - %GEGL_TYPE_COLOR: * * %GIMP_TYPE_COLOR_AREA: a color area with no label. * - %G_TYPE_PARAM_FILE: * * %GTK_FILE_CHOOSER_BUTTON (default): generic file chooser button @@ -755,7 +756,10 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog, gtk_widget_set_vexpand (widget, FALSE); gtk_widget_set_hexpand (widget, FALSE); } - else if (widget_type == GIMP_TYPE_COLOR_AREA) + } + else if (G_PARAM_SPEC_TYPE (pspec) == GEGL_TYPE_PARAM_COLOR) + { + if (widget_type == G_TYPE_NONE || widget_type == GIMP_TYPE_COLOR_AREA) { widget = gimp_prop_color_area_new (G_OBJECT (dialog->priv->config), property, 20, 20, diff --git a/libgimpconfig/gimpconfig-params.h b/libgimpconfig/gimpconfig-params.h index 87e2d98b93..afb2a441ef 100644 --- a/libgimpconfig/gimpconfig-params.h +++ b/libgimpconfig/gimpconfig-params.h @@ -198,6 +198,14 @@ G_BEGIN_DECLS G_PARAM_READWRITE |\ GIMP_CONFIG_PARAM_SERIALIZE)) +#define GIMP_CONFIG_PROP_COLOR(class, id, name, nick, blurb, default, flags) \ + g_object_class_install_property (class, id,\ + gegl_param_spec_color (name, nick, blurb,\ + default,\ + flags |\ + G_PARAM_READWRITE |\ + GIMP_CONFIG_PARAM_SERIALIZE)) + #define GIMP_CONFIG_PROP_BOXED(class, id, name, nick, blurb, boxed_type, flags) \ g_object_class_install_property (class, id,\ g_param_spec_boxed (name, nick, blurb,\ diff --git a/libgimpwidgets/gimpcolorbutton.c b/libgimpwidgets/gimpcolorbutton.c index 00ba0db0aa..a6feb921c8 100644 --- a/libgimpwidgets/gimpcolorbutton.c +++ b/libgimpwidgets/gimpcolorbutton.c @@ -955,35 +955,48 @@ gimp_color_button_use_color (GAction *action, GimpColorButton *button) { const gchar *name; - GimpRGB color; + GeglColor *color = NULL; + GimpRGB rgb; name = g_action_get_name (action); - gimp_color_button_get_color (button, &color); + gimp_color_button_get_color (button, &rgb); if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_FG)) { if (_gimp_get_foreground_func) - _gimp_get_foreground_func (&color); + { + color = _gimp_get_foreground_func (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); + } else - gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); + { + gimp_rgba_set (&rgb, 0.0, 0.0, 0.0, 1.0); + } } else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BG)) { if (_gimp_get_background_func) - _gimp_get_background_func (&color); + { + color = _gimp_get_background_func (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); + } else - gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0); + { + gimp_rgba_set (&rgb, 1.0, 1.0, 1.0, 1.0); + } } else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BLACK)) { - gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); + gimp_rgba_set (&rgb, 0.0, 0.0, 0.0, 1.0); } else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_WHITE)) { - gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0); + gimp_rgba_set (&rgb, 1.0, 1.0, 1.0, 1.0); } - gimp_color_button_set_color (button, &color); + gimp_color_button_set_color (button, &rgb); + + g_clear_object (&color); } static void diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c index 00a1c06979..d9e97dcd14 100644 --- a/libgimpwidgets/gimppropwidgets.c +++ b/libgimpwidgets/gimppropwidgets.c @@ -4069,7 +4069,7 @@ static void gimp_prop_color_area_notify (GObject *config, /** * gimp_prop_color_area_new: * @config: Object to which property is attached. - * @property_name: Name of RGB property. + * @property_name: Name of %GeglColor property. * @width: Width of color area. * @height: Height of color area. * @type: How transparency is represented. @@ -4090,10 +4090,11 @@ gimp_prop_color_area_new (GObject *config, { GParamSpec *param_spec; GtkWidget *area; - GimpRGB *value; + GeglColor *value = NULL; + GimpRGB rgb = { 0 }; param_spec = check_param_spec_w (config, property_name, - GIMP_TYPE_PARAM_RGB, G_STRFUNC); + GEGL_TYPE_PARAM_COLOR, G_STRFUNC); if (! param_spec) return NULL; @@ -4101,11 +4102,13 @@ gimp_prop_color_area_new (GObject *config, property_name, &value, NULL); - area = gimp_color_area_new (value, type, + if (value != NULL) + gegl_color_get_pixel (value, babl_format ("R'G'B'A double"), &rgb); + area = gimp_color_area_new (&rgb, type, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK); gtk_widget_set_size_request (area, width, height); - g_free (value); + g_clear_object (&value); set_param_spec (G_OBJECT (area), area, param_spec); @@ -4129,25 +4132,29 @@ gimp_prop_color_area_callback (GtkWidget *area, GObject *config) { GParamSpec *param_spec; + GeglColor *color; GimpRGB value; param_spec = get_param_spec (G_OBJECT (area)); if (! param_spec) return; + color = gegl_color_new (NULL); gimp_color_area_get_color (GIMP_COLOR_AREA (area), &value); + gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), &value); g_signal_handlers_block_by_func (config, gimp_prop_color_area_notify, area); g_object_set (config, - param_spec->name, &value, + param_spec->name, color, NULL); g_signal_handlers_unblock_by_func (config, gimp_prop_color_area_notify, area); + g_object_unref (color); } static void @@ -4155,19 +4162,21 @@ gimp_prop_color_area_notify (GObject *config, GParamSpec *param_spec, GtkWidget *area) { - GimpRGB *value; + GeglColor *color = NULL; + GimpRGB value; g_object_get (config, - param_spec->name, &value, + param_spec->name, &color, NULL); g_signal_handlers_block_by_func (area, gimp_prop_color_area_callback, config); - gimp_color_area_set_color (GIMP_COLOR_AREA (area), value); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &value); + gimp_color_area_set_color (GIMP_COLOR_AREA (area), &value); - g_free (value); + g_clear_object (&color); g_signal_handlers_unblock_by_func (area, gimp_prop_color_area_callback, diff --git a/libgimpwidgets/gimpwidgets-private.c b/libgimpwidgets/gimpwidgets-private.c index 96dbf07b5f..0ebe7fa7e0 100644 --- a/libgimpwidgets/gimpwidgets-private.c +++ b/libgimpwidgets/gimpwidgets-private.c @@ -22,6 +22,7 @@ #include "config.h" #include +#include #include #include "libgimpbase/gimpbase.h" diff --git a/libgimpwidgets/gimpwidgets-private.h b/libgimpwidgets/gimpwidgets-private.h index dea6e8ccab..cea4c16b1c 100644 --- a/libgimpwidgets/gimpwidgets-private.h +++ b/libgimpwidgets/gimpwidgets-private.h @@ -26,8 +26,8 @@ #define GIMP_RGBA_EPSILON 1e-6 -typedef gboolean (* GimpGetColorFunc) (GimpRGB *color); -typedef void (* GimpEnsureModulesFunc) (void); +typedef GeglColor * (* GimpGetColorFunc) (void); +typedef void (* GimpEnsureModulesFunc) (void); extern GimpHelpFunc _gimp_standard_help_func; diff --git a/pdb/groups/context.pdb b/pdb/groups/context.pdb index a8d9c2125d..bca357f003 100644 --- a/pdb/groups/context.pdb +++ b/pdb/groups/context.pdb @@ -249,15 +249,15 @@ HELP &pdb_misc; @outargs = ( - { name => 'foreground', type => 'color', void_ret => 1, + { name => 'foreground', type => 'geglcolor', desc => 'The foreground color' } ); %invoke = ( code => <<'CODE' { - gimp_context_get_foreground (context, &foreground); - gimp_rgb_set_alpha (&foreground, 1.0); + foreground = gegl_color_duplicate (gimp_context_get_foreground (context)); + gimp_color_set_alpha (foreground, 1.0); } CODE ); @@ -301,15 +301,15 @@ HELP &pdb_misc; @outargs = ( - { name => 'background', type => 'color', void_ret => 1, + { name => 'background', type => 'geglcolor', desc => 'The background color' } ); %invoke = ( code => <<'CODE' { - gimp_context_get_background (context, &background); - gimp_rgb_set_alpha (&background, 1.0); + background = gegl_color_duplicate (gimp_context_get_background (context)); + gimp_color_set_alpha (background, 1.0); } CODE ); @@ -3409,7 +3409,8 @@ CODE ); } -@headers = qw("core/gimp.h" +@headers = qw( + "core/gimp.h" "core/gimp-gradients.h" "core/gimpcontainer.h" "core/gimpdashpattern.h" @@ -3419,6 +3420,7 @@ CODE "core/gimpmybrush.h" "core/gimpstrokeoptions.h" "paint/gimppaintoptions.h" + "libgimpcolor/gimpcolor.h" "libgimpconfig/gimpconfig.h" "plug-in/gimpplugin.h" "plug-in/gimpplugin-context.h" diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb index a340a72c7d..368f319ca1 100644 --- a/pdb/groups/plug_in_compat.pdb +++ b/pdb/groups/plug_in_compat.pdb @@ -215,25 +215,27 @@ HELP GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; GeglNode *node; if (set_background) - gimp_context_get_background (context, &color); + { + color = gegl_color_duplicate (gimp_context_get_background (context)); + } else - gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0); - - gegl_color = gimp_gegl_color_new (&color, NULL); + { + color = gegl_color_new ("black"); + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 0.0, 0.0, NULL); + } node = gegl_node_new_child (NULL, "operation", "gegl:apply-lens", "refraction-index", refraction, "keep-surroundings", keep_surroundings, - "background-color", gegl_color, + "background-color", color, NULL); - g_object_unref (gegl_color); + g_object_unref (color); node = wrap_in_selection_bounds (node, drawable); @@ -980,29 +982,27 @@ HELP GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; GeglNode *node; if (bg_color) { - gimp_context_get_background (context, &color); - gimp_rgb_set_alpha (&color, 0.0); + color = gegl_color_duplicate (gimp_context_get_background (context)); + gimp_color_set_alpha (color, 0.0); } else { - gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0); + color = gegl_color_new ("black"); + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 0.0, 0.0, NULL); } - gegl_color = gimp_gegl_color_new (&color, NULL); - node = gegl_node_new_child (NULL, "operation", "gegl:cubism", "tile-size", tile_size, "tile-saturation", tile_saturation, - "bg-color", gegl_color, + "bg-color", color, NULL); - g_object_unref (gegl_color); + g_object_unref (color); gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Cubism"), @@ -2172,21 +2172,14 @@ HELP gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node = NULL; - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; - gimp_context_get_background (context, &color); + color = gegl_color_duplicate (gimp_context_get_background (context)); if (gimp_drawable_has_alpha (drawable)) - { - gimp_rgb_set_alpha (&color, 0.0); - } + gimp_color_set_alpha (color, 0.0); else - { - gimp_rgb_set_alpha (&color, 1.0); - } - - gegl_color = gimp_gegl_color_new (&color, NULL); + gimp_color_set_alpha (color, 1.0); node = gegl_node_new_child (NULL, "operation", "gegl:lens-distortion", @@ -2196,10 +2189,10 @@ HELP "x-shift", (gdouble) offset_x, "y-shift", (gdouble) offset_y, "brighten", (gdouble) brighten, - "background", gegl_color, + "background", color, NULL); - g_object_unref (gegl_color); + g_object_unref (color); node = wrap_in_selection_bounds (node, drawable); @@ -2305,13 +2298,9 @@ HELP GeglNode *node; GeglColor *fg_color; GeglColor *bg_color; - GimpRGB color; - gimp_context_get_foreground (context, &color); - fg_color = gimp_gegl_color_new (&color, NULL); - - gimp_context_get_background (context, &color); - bg_color = gimp_gegl_color_new (&color, NULL); + fg_color = gimp_context_get_foreground (context); + bg_color = gimp_context_get_background (context); node = gegl_node_new_child (NULL, "operation", "gegl:maze", @@ -2324,9 +2313,6 @@ HELP "bg-color", bg_color, NULL); - g_object_unref (fg_color); - g_object_unref (bg_color); - gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Maze"), node); @@ -2633,13 +2619,8 @@ HELP if (grout_color) { - GimpRGB fgcolor, bgcolor; - - gimp_context_get_background (context, &bgcolor); - bg_color = gimp_gegl_color_new (&bgcolor, NULL); - - gimp_context_get_foreground (context, &fgcolor); - fg_color = gimp_gegl_color_new (&fgcolor, NULL); + bg_color = gegl_color_duplicate (gimp_context_get_background (context)); + fg_color = gegl_color_duplicate (gimp_context_get_foreground (context)); } else { @@ -3102,7 +3083,7 @@ HELP desc => 'Centering' }, { name => 'background_type', type => '0 <= int32 <= 5', desc => 'Background type { TRANSPARENT (0), INVERTED (1), IMAGE (2), FG (3), BG (4), COLOR (5) }' }, - { name => 'background_color', type => 'color', + { name => 'background_color', type => 'geglcolor', desc => 'Background color (for background-type == 5)' }, { name => 'background_alpha', type => 'int32', dead => 1, desc => 'Background alpha (unused)' } @@ -3116,48 +3097,49 @@ HELP gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node; - GimpRGB color; - GeglColor *gegl_color; + GeglColor *color; gint bg_type; switch (background_type) { default: bg_type = background_type; - gimp_rgba_set (&color, 0.0, 0.0, 1.0, 1.0); + color = gegl_color_new (NULL); + /* XXX: I guess what we want is to set this color (why blue?) in the + * drawable's space, though I haven't looked too much into it. + */ + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 1.0, 1.0, gimp_drawable_get_space (drawable)); break; case 3: bg_type = 3; - gimp_context_get_foreground (context, &color); + color = gegl_color_duplicate (gimp_context_get_foreground (context)); break; case 4: bg_type = 3; - gimp_context_get_background (context, &color); + color = gegl_color_duplicate (gimp_context_get_background (context)); break; case 5: bg_type = 3; - color = background_color; + color = gegl_color_duplicate (background_color); break; } - gegl_color = gimp_gegl_color_new (&color, NULL); - node = gegl_node_new_child (NULL, "operation", "gegl:tile-paper", "tile-width", tile_size, "tile-height", tile_size, "move-rate", move_max, - "bg-color", gegl_color, + "bg-color", color, "centering", centering, "wrap-around", wrap_around, "background-type", bg_type, "fractional-type", fractional_type, NULL); - g_object_unref (gegl_color); + g_object_unref (color); gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Paper Tile"), @@ -4074,15 +4056,17 @@ HELP gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) && gimp_drawable_has_alpha (drawable)) { - GeglNode *node; - GimpRGB color; + GeglNode *node; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_background (context, &color); + color = gimp_context_get_background (context); + gegl_color_get_rgba_with_space (color, &rgb.r, &rgb.g, &rgb.b, &rgb.a, NULL); node = gegl_node_new_child (NULL, "operation", "gimp:semi-flatten", - "color", &color, + "color", &rgb, NULL); gimp_drawable_apply_operation (drawable, progress, @@ -4175,9 +4159,9 @@ sub plug_in_sinus { desc => 'If set, the pattern is a little more distorted...' }, { name => 'colors', type => '0 <= int32 <=2', desc => 'where to take the colors (0=B&W, 1=fg/bg, 2=col1/col2)' }, - { name => 'col1', type => 'color', + { name => 'col1', type => 'geglcolor', desc => 'fist color (sometimes unused)' }, - { name => 'col2', type => 'color', + { name => 'col2', type => 'geglcolor', desc => 'second color (sometimes unused)' }, { name => 'alpha1', type => '0 <= float <= 1', desc => 'alpha for the first color (used if the drawable has an alpha channel)' }, @@ -4197,28 +4181,30 @@ sub plug_in_sinus { gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node; - GeglColor *gegl_color1; - GeglColor *gegl_color2; - gint x, y, width, height; + GeglColor *gegl_color1 = NULL; + GeglColor *gegl_color2 = NULL; + gint x, y, width, height; switch (colors) { case 0: - gimp_rgb_set (&col1, 0.0, 0.0, 0.0); - gimp_rgb_set (&col2, 1.0, 1.0, 1.0); + gegl_color1 = gegl_color_new ("black"); + gegl_color2 = gegl_color_new ("white"); break; case 1: - gimp_context_get_foreground (context, &col1); - gimp_context_get_background (context, &col2); + gegl_color1 = gegl_color_duplicate (gimp_context_get_foreground (context)); + gegl_color2 = gegl_color_duplicate (gimp_context_get_background (context)); break; } - gimp_rgb_set_alpha (&col1, alpha1); - gimp_rgb_set_alpha (&col2, alpha2); - - gegl_color1 = gimp_gegl_color_new (&col1, NULL); - gegl_color2 = gimp_gegl_color_new (&col2, NULL); + if (gegl_color1 == NULL) + { + gegl_color1 = gegl_color_duplicate (col1); + gegl_color2 = gegl_color_duplicate (col2); + } + gimp_color_set_alpha (gegl_color1, alpha1); + gimp_color_set_alpha (gegl_color2, alpha2); gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height); @@ -4736,8 +4722,7 @@ HELP gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { GeglNode *node; - GimpRGB color; - GeglColor *gegl_color = NULL; + GeglColor *color = NULL; gint gegl_mode = 0; gboolean to_left = (direction_mask & (0x1 << 0)) != 0; gboolean to_top = (direction_mask & (0x1 << 1)) != 0; @@ -4761,16 +4746,14 @@ HELP { gegl_mode = propagate_mode; - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); } else { gegl_mode = 4; - gimp_context_get_background (context, &color); + color = gimp_context_get_background (context); } - - gegl_color = gimp_gegl_color_new (&color, NULL); break; case 6: @@ -4786,7 +4769,7 @@ HELP "lower-threshold", (gdouble) lower_limit / 255.0, "upper-threshold", (gdouble) upper_limit / 255.0, "rate", propagating_rate, - "color", gegl_color, + "color", color, "top", to_top, "left", to_left, "right", to_right, @@ -4795,9 +4778,6 @@ HELP "alpha", alpha, NULL); - if (gegl_color) - g_object_unref (gegl_color); - gimp_drawable_apply_operation (drawable, progress, C_("undo-type", "Value Propagate"), node); diff --git a/pdb/groups/text_layer.pdb b/pdb/groups/text_layer.pdb index 33b1e8489b..7ce06bb692 100644 --- a/pdb/groups/text_layer.pdb +++ b/pdb/groups/text_layer.pdb @@ -54,20 +54,23 @@ HELP %invoke = ( code => <<'CODE' { - GimpText *gimp_text; - GimpRGB color; + GimpText *gimp_text; + GeglColor *color; + GimpRGB rgb; - gimp_context_get_foreground (context, &color); + color = gimp_context_get_foreground (context); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); gimp_text = g_object_new (GIMP_TYPE_TEXT, "text", text, "font", font, "font-size", size, "font-size-unit", unit, - "color", &color, + "color", &rgb, NULL); layer = GIMP_TEXT_LAYER (gimp_text_layer_new (image, gimp_text)); + g_object_unref (color); g_object_unref (gimp_text); if (! layer) diff --git a/plug-ins/common/blinds.c b/plug-ins/common/blinds.c index 1a77c39bca..b66998de4f 100644 --- a/plug-ins/common/blinds.c +++ b/plug-ins/common/blinds.c @@ -452,6 +452,7 @@ dialog_update_preview (GtkWidget *widget, guchar *buffer; GBytes *cache; const guchar *cache_start; + GeglColor *color; GimpRGB background; guchar bg[4]; gint width; @@ -471,10 +472,13 @@ dialog_update_preview (GtkWidget *widget, &width, &height, &bpp); p = cache_start = g_bytes_get_data (cache, NULL); - gimp_context_get_background (&background); + color = gimp_context_get_background (); if (bg_trans) - gimp_rgb_set_alpha (&background, 0.0); + gimp_color_set_alpha (color, 0.0); + + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &background); + g_object_unref (color); if (gimp_drawable_is_gray (drawable)) { @@ -580,7 +584,7 @@ apply_blinds (GObject *config, guchar *src_rows, *des_rows; gint bytes; gint x, y; - GimpRGB background; + GeglColor *background; guchar bg[4]; gint sel_x1, sel_y1; gint sel_width, sel_height; @@ -592,12 +596,13 @@ apply_blinds (GObject *config, "orientation", &orientation, NULL); - gimp_context_get_background (&background); + background = gimp_context_get_background (); if (bg_trans) - gimp_rgb_set_alpha (&background, 0.0); + gimp_color_set_alpha (background, 0.0); - gimp_rgba_get_uchar (&background, bg, bg + 1, bg + 2, bg + 3); + gegl_color_get_pixel (background, babl_format_with_space ("R'G'B'A u8", NULL), bg); + g_object_unref (background); if (! gimp_drawable_mask_intersect (drawable, &sel_x1, &sel_y1, diff --git a/plug-ins/common/checkerboard.c b/plug-ins/common/checkerboard.c index 102da1bbf8..9995433f56 100644 --- a/plug-ins/common/checkerboard.c +++ b/plug-ins/common/checkerboard.c @@ -257,6 +257,7 @@ do_checkerboard_pattern (GObject *config, GimpPreview *preview) { CheckerboardParam_t param; + GeglColor *color; GimpRGB fg, bg; const Babl *format; gint bpp; @@ -269,8 +270,12 @@ do_checkerboard_pattern (GObject *config, "psychobily", &mode, NULL); - gimp_context_get_background (&bg); - gimp_context_get_foreground (&fg); + color = gimp_context_get_background (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &bg); + g_object_unref (color); + color = gimp_context_get_foreground (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &fg); + g_object_unref (color); if (gimp_drawable_is_gray (drawable)) { diff --git a/plug-ins/common/decompose.c b/plug-ins/common/decompose.c index 1ebb2ce99e..5680b12db6 100644 --- a/plug-ins/common/decompose.c +++ b/plug-ins/common/decompose.c @@ -660,7 +660,7 @@ transfer_registration_color (GeglBuffer *src, GeglBuffer **dst, gint count) { - GimpRGB color, test; + GeglColor *color; GeglBufferIterator *gi; const Babl *src_format; const Babl *dst_format; @@ -669,7 +669,7 @@ transfer_registration_color (GeglBuffer *src, gint i; gdouble white; - gimp_context_get_foreground (&color); + color = gimp_context_get_foreground (); white = 1.0; src_format = gegl_buffer_get_format (src); @@ -699,11 +699,13 @@ transfer_registration_color (GeglBuffer *src, for (k = 0; k < gi->length; k++) { - gulong pos = k * src_bpp; + GeglColor *test; + gulong pos = k * src_bpp; - gimp_rgba_set_pixel (&test, src_format, ((guchar *)src_data) + pos); + test = gegl_color_new (NULL); + gegl_color_set_pixel (test, src_format, ((guchar *)src_data) + pos); - if (gimp_rgb_distance (&test, &color) < 1e-6) + if (gimp_color_is_perceptually_identical (test, color)) { for (j = 0; j < count; j++) { @@ -713,8 +715,12 @@ transfer_registration_color (GeglBuffer *src, &white, (guchar *)data + (k * dst_bpp), 1); } } + + g_object_unref (test); } } + + g_object_unref (color); } static void diff --git a/plug-ins/common/file-gif-save.c b/plug-ins/common/file-gif-save.c index fd64fe4318..2568683943 100644 --- a/plug-ins/common/file-gif-save.c +++ b/plug-ins/common/file-gif-save.c @@ -785,8 +785,9 @@ save_image (GFile *file, gint Disposal; gchar *layer_name; - GimpRGB background; - guchar bgred, bggreen, bgblue; + guchar bgred = 255; + guchar bggreen = 255; + guchar bgblue = 255; guchar bgindex = 0; guint best_error = 0xFFFFFFFF; @@ -882,22 +883,31 @@ save_image (GFile *file, case GIMP_INDEXEDA_IMAGE: is_gif89 = TRUE; case GIMP_INDEXED_IMAGE: - cmap = gimp_image_get_colormap (image, NULL, &colors); - - gimp_context_get_background (&background); - gimp_rgb_get_uchar (&background, &bgred, &bggreen, &bgblue); - - for (i = 0; i < colors; i++) { - Red[i] = *cmap++; - Green[i] = *cmap++; - Blue[i] = *cmap++; - } - for ( ; i < 256; i++) - { - Red[i] = bgred; - Green[i] = bggreen; - Blue[i] = bgblue; + GeglColor *background; + guchar bg[3]; + + cmap = gimp_image_get_colormap (image, NULL, &colors); + + background = gimp_context_get_background (); + gegl_color_get_pixel (background, babl_format_with_space ("R'G'B' u8", NULL), bg); + g_object_unref (background); + bgred = bg[0]; + bggreen = bg[1]; + bgblue = bg[2]; + + for (i = 0; i < colors; i++) + { + Red[i] = *cmap++; + Green[i] = *cmap++; + Blue[i] = *cmap++; + } + for ( ; i < 256; i++) + { + Red[i] = bgred; + Green[i] = bggreen; + Blue[i] = bgblue; + } } break; case GIMP_GRAYA_IMAGE: diff --git a/plug-ins/common/file-pdf-save.c b/plug-ins/common/file-pdf-save.c index 483336e25f..ffa72aacd0 100644 --- a/plug-ins/common/file-pdf-save.c +++ b/plug-ins/common/file-pdf-save.c @@ -768,17 +768,18 @@ pdf_save_image (GimpProcedure *procedure, if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layers[n_layers - 1])) && fill_background_color) { - GimpRGB color; + GeglColor *color; + double rgb[3]; cairo_rectangle (cr, 0.0, 0.0, gimp_image_get_width (image), gimp_image_get_height (image)); - gimp_context_get_background (&color); - cairo_set_source_rgb (cr, - color.r, - color.g, - color.b); + color = gimp_context_get_background (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), rgb); + cairo_set_source_rgb (cr, rgb[0], rgb[1], rgb[2]); cairo_fill (cr); + + g_object_unref (color); } /* Now, we should loop over the layers of each image */ diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c index daf6687b93..24b4d992b3 100644 --- a/plug-ins/common/file-png.c +++ b/plug-ins/common/file-png.c @@ -1743,17 +1743,20 @@ save_image (GFile *file, if (save_bkgd) { - GimpRGB color; - guchar red, green, blue; + GeglColor *color; + GimpRGB rgb; + guchar c[3]; - gimp_context_get_background (&color); - gimp_rgb_get_uchar (&color, &red, &green, &blue); + color = gimp_context_get_background (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B' u8", NULL), c); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &rgb); + g_object_unref (color); background.index = 0; - background.red = red; - background.green = green; - background.blue = blue; - background.gray = gimp_rgb_luminance_uchar (&color); + background.red = c[0]; + background.green = c[1]; + background.blue = c[2]; + background.gray = gimp_rgb_luminance_uchar (&rgb); png_set_bKGD (pp, info, &background); } diff --git a/plug-ins/common/sparkle.c b/plug-ins/common/sparkle.c index 5f43b3a7d8..a2779d2bc4 100644 --- a/plug-ins/common/sparkle.c +++ b/plug-ins/common/sparkle.c @@ -992,7 +992,7 @@ fspike (GObject *config, gdouble sfac; gint i; gboolean ok; - GimpRGB gimp_color; + GeglColor *gegl_color; guchar pixel[MAX_CHANNELS]; guchar chosen_color[MAX_CHANNELS]; guchar color[MAX_CHANNELS]; @@ -1018,15 +1018,15 @@ fspike (GObject *config, break; case FOREGROUND: - gimp_context_get_foreground (&gimp_color); - gimp_rgb_get_uchar (&gimp_color, &chosen_color[0], &chosen_color[1], - &chosen_color[2]); + gegl_color = gimp_context_get_foreground (); + gegl_color_get_pixel (gegl_color, babl_format_with_space ("R'G'B' u8", NULL), chosen_color); + g_clear_object (&gegl_color); break; case BACKGROUND: - gimp_context_get_background (&gimp_color); - gimp_rgb_get_uchar (&gimp_color, &chosen_color[0], &chosen_color[1], - &chosen_color[2]); + gegl_color = gimp_context_get_background (); + gegl_color_get_pixel (gegl_color, babl_format_with_space ("R'G'B' u8", NULL), chosen_color); + g_clear_object (&gegl_color); break; } diff --git a/plug-ins/common/warp.c b/plug-ins/common/warp.c index f545d6208d..b7e33433cd 100644 --- a/plug-ins/common/warp.c +++ b/plug-ins/common/warp.c @@ -332,7 +332,7 @@ warp_run (GimpProcedure *procedure, gpointer run_data) { GimpDrawable *drawable; - GimpRGB color; + GeglColor *color; gegl_init (NULL, NULL); @@ -354,11 +354,9 @@ warp_run (GimpProcedure *procedure, } /* get currently selected foreground pixel color */ - gimp_context_get_foreground (&color); - gimp_rgb_get_uchar (&color, - &color_pixel[0], - &color_pixel[1], - &color_pixel[2]); + color = gimp_context_get_foreground (); + gegl_color_get_pixel (color, babl_format ("R'G'B' u8"), color_pixel); + g_object_unref (color); run_mode = _run_mode; diff --git a/plug-ins/file-fli/fli-gimp.c b/plug-ins/file-fli/fli-gimp.c index ca52b24130..201850146f 100644 --- a/plug-ins/file-fli/fli-gimp.c +++ b/plug-ins/file-fli/fli-gimp.c @@ -669,14 +669,14 @@ save_image (GFile *file, gint colors, i; guchar *cmap; guchar bg; - guchar red, green, blue; + guchar rgb[3]; gint diff, sum, max; gint offset_x, offset_y, xc, yc, xx, yy; guint rows, cols, bytes; guchar *src_row; guchar *fb, *ofb; guchar cm[768]; - GimpRGB background; + GeglColor *background; s_fli_header fli_header; gint cnt; gint from_frame; @@ -721,8 +721,9 @@ save_image (GFile *file, to_frame = n_frames; } - gimp_context_get_background (&background); - gimp_rgb_get_uchar (&background, &red, &green, &blue); + background = gimp_context_get_background (); + gegl_color_get_pixel (background, babl_format_with_space ("R'G'B' u8", NULL), rgb); + g_object_unref (background); switch (gimp_image_get_base_type (image)) { @@ -732,7 +733,7 @@ save_image (GFile *file, { cm[i*3+0] = cm[i*3+1] = cm[i*3+2] = i; } - bg = GIMP_RGB_LUMINANCE (red, green, blue) + 0.5; + bg = GIMP_RGB_LUMINANCE (rgb[0], rgb[1], rgb[2]) + 0.5; break; case GIMP_INDEXED: @@ -745,11 +746,11 @@ save_image (GFile *file, cm[i*3+1] = cmap[i*3+1]; cm[i*3+2] = cmap[i*3+2]; - diff = red - cm[i*3+0]; + diff = rgb[0] - cm[i*3+0]; sum = SQR (diff); - diff = green - cm[i*3+1]; + diff = rgb[1] - cm[i*3+1]; sum += SQR (diff); - diff = blue - cm[i*3+2]; + diff = rgb[1] - cm[i*3+2]; sum += SQR (diff); if (sum < max) diff --git a/plug-ins/gfig/gfig-style.c b/plug-ins/gfig/gfig-style.c index a79d033b5b..a77fe67bd8 100644 --- a/plug-ins/gfig/gfig-style.c +++ b/plug-ins/gfig/gfig-style.c @@ -648,7 +648,8 @@ void gfig_read_gimp_style (Style *style, const gchar *name) { - gint dummy; + GeglColor *color; + gint dummy; if (!name) g_message ("Error: name is NULL in gfig_read_gimp_style."); @@ -657,8 +658,12 @@ gfig_read_gimp_style (Style *style, g_printerr ("Reading Gimp settings as style %s\n", name); style->name = g_strdup (name); - gimp_context_get_foreground (&style->foreground); - gimp_context_get_background (&style->background); + color = gimp_context_get_foreground (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &style->foreground); + g_object_unref (color); + color = gimp_context_get_background (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A double", NULL), &style->background); + g_object_unref (color); style->brush = gimp_context_get_brush (); style->gradient = gimp_context_get_gradient (); diff --git a/plug-ins/ifs-compose/ifs-compose.c b/plug-ins/ifs-compose/ifs-compose.c index 80d05d883a..593e5a4444 100644 --- a/plug-ins/ifs-compose/ifs-compose.c +++ b/plug-ins/ifs-compose/ifs-compose.c @@ -1317,8 +1317,8 @@ ifs_compose (GimpDrawable *drawable) guchar *data; guchar *mask = NULL; guchar *nhits; - guchar rc, gc, bc; - GimpRGB color; + guchar c[3]; + GeglColor *color; if (alpha) format = babl_format ("R'G'B'A u8"); @@ -1336,8 +1336,9 @@ ifs_compose (GimpDrawable *drawable) data = g_new (guchar, width * band_height * SQR (ifsvals.subdivide) * 3); nhits = g_new (guchar, width * band_height * SQR (ifsvals.subdivide)); - gimp_context_get_background (&color); - gimp_rgb_get_uchar (&color, &rc, &gc, &bc); + color = gimp_context_get_background (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B' u8", NULL), c); + g_object_unref (color); for (band_no = 0, band_y = 0; band_no < num_bands; band_no++) { @@ -1429,9 +1430,9 @@ ifs_compose (GimpDrawable *drawable) } else { - *dest++ = (mtot * rtot + (255 - mtot) * rc) / 255; - *dest++ = (mtot * gtot + (255 - mtot) * gc) / 255; - *dest++ = (mtot * btot + (255 - mtot) * bc) / 255; + *dest++ = (mtot * rtot + (255 - mtot) * c[0]) / 255; + *dest++ = (mtot * gtot + (255 - mtot) * c[1]) / 255; + *dest++ = (mtot * btot + (255 - mtot) * c[2]) / 255; } } @@ -2324,10 +2325,13 @@ flip_check_button_callback (GtkWidget *widget, static void ifs_compose_set_defaults (void) { - gint i; - GimpRGB color; + GeglColor *color; + GimpRGB rgb; + gint i; - gimp_context_get_foreground (&color); + color = gimp_context_get_foreground (); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); + g_object_unref (color); ifsvals.aspect_ratio = (gdouble)ifsD->drawable_height / ifsD->drawable_width; @@ -2341,13 +2345,13 @@ ifs_compose_set_defaults (void) element_selected = g_realloc (element_selected, ifsvals.num_elements * sizeof(gboolean)); - elements[0] = aff_element_new (0.3, 0.37 * ifsvals.aspect_ratio, &color, + elements[0] = aff_element_new (0.3, 0.37 * ifsvals.aspect_ratio, &rgb, ++count_for_naming); element_selected[0] = FALSE; - elements[1] = aff_element_new (0.7, 0.37 * ifsvals.aspect_ratio, &color, + elements[1] = aff_element_new (0.7, 0.37 * ifsvals.aspect_ratio, &rgb, ++count_for_naming); element_selected[1] = FALSE; - elements[2] = aff_element_new (0.5, 0.7 * ifsvals.aspect_ratio, &color, + elements[2] = aff_element_new (0.5, 0.7 * ifsvals.aspect_ratio, &rgb, ++count_for_naming); element_selected[2] = FALSE; @@ -2622,19 +2626,22 @@ ifs_compose_new_action (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - GtkAllocation allocation; - GimpRGB color; - gint i; - AffElement *elem; + GtkAllocation allocation; + GeglColor *color; + GimpRGB rgb; + gint i; + AffElement *elem; gtk_widget_get_allocation (ifsDesign->area, &allocation); undo_begin (); - gimp_context_get_foreground (&color); + color = gimp_context_get_foreground (); + gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), &rgb); + g_object_unref (color); elem = aff_element_new (0.5, 0.5 * allocation.height / allocation.width, - &color, + &rgb, ++count_for_naming); ifsvals.num_elements++; @@ -2777,25 +2784,26 @@ static void ifs_compose_preview (void) { /* Expansion isn't really supported for previews */ - gint i; - gint width = ifsD->preview_width; - gint height = ifsD->preview_height; - guchar rc, gc, bc; - guchar *ptr; - GimpRGB color; + gint i; + gint width = ifsD->preview_width; + gint height = ifsD->preview_height; + guchar *ptr; + GeglColor *color; + guchar c[3]; if (!ifsD->preview_data) ifsD->preview_data = g_new (guchar, 3 * width * height); - gimp_context_get_background (&color); - gimp_rgb_get_uchar (&color, &rc, &gc, &bc); + color = gimp_context_get_background (); + gegl_color_get_pixel (color, babl_format_with_space ("R'G'B' u8", NULL), c); + g_object_unref (color); ptr = ifsD->preview_data; for (i = 0; i < width * height; i++) { - *ptr++ = rc; - *ptr++ = gc; - *ptr++ = bc; + *ptr++ = c[0]; + *ptr++ = c[1]; + *ptr++ = c[2]; } if (ifsD->preview_iterations == 0) diff --git a/plug-ins/map-object/map-object-image.c b/plug-ins/map-object/map-object-image.c index 6a90864969..89e00b134d 100644 --- a/plug-ins/map-object/map-object-image.c +++ b/plug-ins/map-object/map-object-image.c @@ -341,8 +341,13 @@ image_setup (GimpDrawable *drawable, } else { - gimp_context_get_background (&background); - gimp_rgb_set_alpha (&background, 1.0); + GeglColor *gegl_color; + + gegl_color = gimp_context_get_background (); + gimp_color_set_alpha (gegl_color, 1.0); + gegl_color_get_rgba_with_space (gegl_color, &background.r, &background.g, &background.b, &background.a, NULL); + + g_object_unref (gegl_color); } if (interactive == TRUE) diff --git a/plug-ins/map-object/map-object-preview.c b/plug-ins/map-object/map-object-preview.c index cbe909435c..d572b084e7 100644 --- a/plug-ins/map-object/map-object-preview.c +++ b/plug-ins/map-object/map-object-preview.c @@ -123,8 +123,13 @@ compute_preview (gint x, } else { - gimp_context_get_background (&background); - gimp_rgb_set_alpha (&background, 1.0); + GeglColor *gegl_color; + + gegl_color = gimp_context_get_background (); + gimp_color_set_alpha (gegl_color, 1.0); + gegl_color_get_rgba_with_space (gegl_color, &background.r, &background.g, &background.b, &background.a, NULL); + + g_object_unref (gegl_color); } gimp_rgba_set (&lightcheck, diff --git a/plug-ins/pagecurl/pagecurl.c b/plug-ins/pagecurl/pagecurl.c index acd305563b..0f940d9975 100644 --- a/plug-ins/pagecurl/pagecurl.c +++ b/plug-ins/pagecurl/pagecurl.c @@ -481,6 +481,7 @@ static void init_calculation (GimpDrawable *drawable, GimpProcedureConfig *config) { + GeglColor *color; gdouble k; gdouble alpha, beta; gdouble angle; @@ -547,8 +548,12 @@ init_calculation (GimpDrawable *drawable, /* Colors */ - gimp_context_get_foreground (&fg_color); - gimp_context_get_background (&bg_color); + color = gimp_context_get_foreground (); + gegl_color_get_rgba_with_space (color, &fg_color.r, &fg_color.g, &fg_color.b, &fg_color.a, NULL); + g_object_unref (color); + color = gimp_context_get_background (); + gegl_color_get_rgba_with_space (color, &bg_color.r, &bg_color.g, &bg_color.b, &bg_color.a, NULL); + g_object_unref (color); } static GimpLayer *