From 2e0d31b17e9e542531304f14b1bd3cead7bed517 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Sat, 23 Mar 2024 04:10:26 +0000 Subject: [PATCH] modules, core, pdb, plug-ins: GeglColor ports More minor ports from GimpRGB to GeglColor. Note that file-mng's GimpRGB code was already dummied out. --- app/core/gimpdrawable-transform.c | 26 ++++++++++------ app/pdb/drawable-cmds.c | 4 +++ app/pdb/gradient-cmds.c | 3 ++ app/pdb/image-cmds.c | 3 ++ app/pdb/image-grid-cmds.c | 3 ++ app/pdb/image-select-cmds.c | 3 ++ app/pdb/palette-cmds.c | 3 ++ app/pdb/plug-in-compat-cmds.c | 51 +++++++++++++++---------------- app/pdb/text-layer-cmds.c | 2 ++ modules/gimpcolorwheel.c | 20 ++++++++++-- pdb/groups/plug_in_compat.pdb | 27 ++++++++-------- pdb/pdb.pl | 3 +- plug-ins/common/blinds.c | 14 ++++----- plug-ins/common/file-mng.c | 17 ++++++----- 14 files changed, 111 insertions(+), 68 deletions(-) diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c index b6014784a2..5d0295e2dc 100644 --- a/app/core/gimpdrawable-transform.c +++ b/app/core/gimpdrawable-transform.c @@ -197,7 +197,6 @@ gimp_drawable_transform_buffer_flip (GimpDrawable *drawable, if (clip_result && (new_x != orig_x || new_y != orig_y)) { - GimpRGB bg; GeglColor *color = NULL; gint clip_x, clip_y; gint clip_width, clip_height; @@ -209,12 +208,16 @@ 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); + { + color = gegl_color_new ("black"); + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 0.0, 0.0, + gimp_drawable_get_space (drawable)); + } else - color = gegl_color_duplicate (gimp_context_get_background (context)); + { + color = gegl_color_duplicate (gimp_context_get_background (context)); + } - 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); @@ -453,7 +456,6 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, new_width != orig_width || new_height != orig_height)) { - GimpRGB bg; GeglColor *color = NULL; gint clip_x, clip_y; gint clip_width, clip_height; @@ -469,12 +471,16 @@ 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); + { + color = gegl_color_new ("black"); + gegl_color_set_rgba_with_space (color, 0.0, 0.0, 0.0, 0.0, + gimp_drawable_get_space (drawable)); + } else - color = gegl_color_duplicate (gimp_context_get_background (context)); + { + color = gegl_color_duplicate (gimp_context_get_background (context)); + } - 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/pdb/drawable-cmds.c b/app/pdb/drawable-cmds.c index d1dd7599c3..3b540b715e 100644 --- a/app/pdb/drawable-cmds.c +++ b/app/pdb/drawable-cmds.c @@ -21,10 +21,14 @@ #include "stamp-pdbgen.h" +#include + #include #include +#include "libgimpcolor/gimpcolor.h" + #include "libgimpbase/gimpbase.h" #include "pdb-types.h" diff --git a/app/pdb/gradient-cmds.c b/app/pdb/gradient-cmds.c index 109af20e84..7c83ef6206 100644 --- a/app/pdb/gradient-cmds.c +++ b/app/pdb/gradient-cmds.c @@ -21,12 +21,15 @@ #include "stamp-pdbgen.h" +#include #include #include #include +#include "libgimpcolor/gimpcolor.h" + #include "libgimpbase/gimpbase.h" #include "pdb-types.h" diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index 4506c31cdf..cd8691350e 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -21,11 +21,14 @@ #include "stamp-pdbgen.h" +#include + #include #include #include "libgimpbase/gimpbase.h" +#include "libgimpcolor/gimpcolor.h" #include "libgimpmath/gimpmath.h" #include "libgimpbase/gimpbase.h" diff --git a/app/pdb/image-grid-cmds.c b/app/pdb/image-grid-cmds.c index 96ea38811e..214c6389c1 100644 --- a/app/pdb/image-grid-cmds.c +++ b/app/pdb/image-grid-cmds.c @@ -21,11 +21,14 @@ #include "stamp-pdbgen.h" +#include + #include #include #include "libgimpbase/gimpbaseenums.h" +#include "libgimpcolor/gimpcolor.h" #include "libgimpbase/gimpbase.h" diff --git a/app/pdb/image-select-cmds.c b/app/pdb/image-select-cmds.c index 6acdbe71a5..8453f3e97d 100644 --- a/app/pdb/image-select-cmds.c +++ b/app/pdb/image-select-cmds.c @@ -21,11 +21,14 @@ #include "stamp-pdbgen.h" +#include + #include #include #include "libgimpbase/gimpbase.h" +#include "libgimpcolor/gimpcolor.h" #include "libgimpbase/gimpbase.h" diff --git a/app/pdb/palette-cmds.c b/app/pdb/palette-cmds.c index b0247ca90b..fd78a594f1 100644 --- a/app/pdb/palette-cmds.c +++ b/app/pdb/palette-cmds.c @@ -21,12 +21,15 @@ #include "stamp-pdbgen.h" +#include #include #include #include +#include "libgimpcolor/gimpcolor.h" + #include "libgimpbase/gimpbase.h" #include "pdb-types.h" diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c index b12044c8dd..3c5eee24c3 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -1084,10 +1084,10 @@ plug_in_colortoalpha_invoker (GimpProcedure *procedure, { gboolean success = TRUE; GimpDrawable *drawable; - GimpRGB color; + GeglColor *color; drawable = g_value_get_object (gimp_value_array_index (args, 2)); - gimp_value_get_rgb (gimp_value_array_index (args, 3), &color); + color = g_value_get_object (gimp_value_array_index (args, 3)); if (success) { @@ -1095,7 +1095,7 @@ plug_in_colortoalpha_invoker (GimpProcedure *procedure, GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL); + GeglColor *gegl_color = gegl_color_duplicate (color); GeglNode *node = gegl_node_new_child (NULL, "operation", "gegl:color-to-alpha", @@ -1795,17 +1795,14 @@ plug_in_exchange_invoker (GimpProcedure *procedure, GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GimpRGB from; - GimpRGB to; - GeglColor *gegl_from; - GeglColor *gegl_to; + GeglColor *gegl_from = gegl_color_new (NULL); + GeglColor *gegl_to = gegl_color_new (NULL); GeglNode *node; - gimp_rgb_set_uchar (&from, from_red, from_green, from_blue); - gimp_rgb_set_uchar (&to, to_red, to_green, to_blue); - - gegl_from = gimp_gegl_color_new (&from, NULL); - gegl_to = gimp_gegl_color_new (&to, NULL); + gegl_color_set_rgba (gegl_from, from_red / 255.0, from_green / 255.0, + from_blue / 255.0, 1.0); + gegl_color_set_rgba (gegl_to, to_red / 255.0, to_green / 255.0, + to_blue / 255.0, 1.0); node = gegl_node_new_child (NULL, "operation", "gegl:color-exchange", @@ -2921,7 +2918,7 @@ plug_in_nova_invoker (GimpProcedure *procedure, GimpDrawable *drawable; gint xcenter; gint ycenter; - GimpRGB color; + GeglColor *color; gint radius; gint nspoke; gint randomhue; @@ -2929,7 +2926,7 @@ plug_in_nova_invoker (GimpProcedure *procedure, drawable = g_value_get_object (gimp_value_array_index (args, 2)); xcenter = g_value_get_int (gimp_value_array_index (args, 3)); ycenter = g_value_get_int (gimp_value_array_index (args, 4)); - gimp_value_get_rgb (gimp_value_array_index (args, 5), &color); + color = g_value_get_object (gimp_value_array_index (args, 5)); radius = g_value_get_int (gimp_value_array_index (args, 6)); nspoke = g_value_get_int (gimp_value_array_index (args, 7)); randomhue = g_value_get_int (gimp_value_array_index (args, 8)); @@ -2940,11 +2937,13 @@ plug_in_nova_invoker (GimpProcedure *procedure, GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { + GeglColor *gegl_color; GeglNode *node; - GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL); gdouble center_x = (gdouble) xcenter / (gdouble) gimp_item_get_width (GIMP_ITEM (drawable)); gdouble center_y = (gdouble) ycenter / (gdouble) gimp_item_get_height (GIMP_ITEM (drawable)); + gegl_color = gegl_color_duplicate (color); + node = gegl_node_new_child (NULL, "operation", "gegl:supernova", "center-x", center_x, @@ -5618,12 +5617,11 @@ register_plug_in_compat_procs (GimpPDB *pdb) FALSE, GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, - gimp_param_spec_rgb ("color", - "color", - "Color to remove", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("color", + "color", + "Color to remove", + NULL, + GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); @@ -7663,12 +7661,11 @@ register_plug_in_compat_procs (GimpPDB *pdb) G_MININT32, G_MAXINT32, 0, GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, - gimp_param_spec_rgb ("color", - "color", - "Color of supernova", - FALSE, - NULL, - GIMP_PARAM_READWRITE)); + gegl_param_spec_color ("color", + "color", + "Color of supernova", + NULL, + GIMP_PARAM_READWRITE)); gimp_procedure_add_argument (procedure, g_param_spec_int ("radius", "radius", diff --git a/app/pdb/text-layer-cmds.c b/app/pdb/text-layer-cmds.c index 8ae9af92a8..8ff6fddf9a 100644 --- a/app/pdb/text-layer-cmds.c +++ b/app/pdb/text-layer-cmds.c @@ -21,6 +21,7 @@ #include "stamp-pdbgen.h" +#include #include #include @@ -28,6 +29,7 @@ #include #include "libgimpbase/gimpbase.h" +#include "libgimpcolor/gimpcolor.h" #include "libgimpbase/gimpbase.h" diff --git a/modules/gimpcolorwheel.c b/modules/gimpcolorwheel.c index c230948a7b..c54113fbbe 100644 --- a/modules/gimpcolorwheel.c +++ b/modules/gimpcolorwheel.c @@ -808,6 +808,9 @@ paint_ring (GimpColorWheel *wheel, { GtkWidget *widget = GTK_WIDGET (wheel); GimpColorWheelPrivate *priv = gimp_color_wheel_get_instance_private (wheel); + GeglColor *color = gegl_color_new (NULL); + const Babl *render_space; + gdouble luminance[1]; gint width, height; gint xx, yy; gdouble dx, dy, dist; @@ -825,6 +828,8 @@ paint_ring (GimpColorWheel *wheel, width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); + render_space = gimp_widget_get_render_space (widget, priv->config); + center_x = width / 2.0; center_y = height / 2.0; @@ -891,7 +896,9 @@ paint_ring (GimpColorWheel *wheel, b = 1.0; hsv_to_rgb (&r, &g, &b); - if (GIMP_RGB_LUMINANCE (r, g, b) > 0.5) + gegl_color_set_rgba_with_space (color, r, g, b, 1.0, render_space); + gegl_color_get_pixel (color, babl_format ("Y' double"), luminance); + if (luminance[0] > 0.5) cairo_set_source_rgb (source_cr, 0.0, 0.0, 0.0); else cairo_set_source_rgb (source_cr, 1.0, 1.0, 1.0); @@ -920,6 +927,7 @@ paint_ring (GimpColorWheel *wheel, cairo_restore (cr); + g_object_unref (color); g_free (buf); } @@ -958,6 +966,9 @@ paint_triangle (GimpColorWheel *wheel, { GtkWidget *widget = GTK_WIDGET (wheel); GimpColorWheelPrivate *priv = gimp_color_wheel_get_instance_private (wheel); + GeglColor *color = gegl_color_new (NULL); + const Babl *render_space; + gdouble luminance[1]; gint hx, hy, sx, sy, vx, vy; /* HSV vertices */ gint x1, y1, r1, g1, b1; /* First vertex in scanline order */ gint x2, y2, r2, g2, b2; /* Second vertex */ @@ -977,6 +988,8 @@ paint_triangle (GimpColorWheel *wheel, width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); + render_space = gimp_widget_get_render_space (widget, priv->config); + /* Compute triangle's vertices */ compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy); @@ -1127,7 +1140,9 @@ paint_triangle (GimpColorWheel *wheel, gtk_style_context_save (context); - if (GIMP_RGB_LUMINANCE (r, g, b) > 0.5) + gegl_color_set_rgba_with_space (color, r, g, b, 1.0, render_space); + gegl_color_get_pixel (color, babl_format ("Y' double"), luminance); + if (luminance[0] > 0.5) { gtk_style_context_add_class (context, "light-area-focus"); cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); @@ -1137,6 +1152,7 @@ paint_triangle (GimpColorWheel *wheel, gtk_style_context_add_class (context, "dark-area-focus"); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); } + g_object_unref (color); #define RADIUS 4 #define FOCUS_RADIUS 6 diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb index 50219eaab1..f8af903d79 100644 --- a/pdb/groups/plug_in_compat.pdb +++ b/pdb/groups/plug_in_compat.pdb @@ -787,7 +787,7 @@ HELP desc => 'Input image (unused)' }, { name => 'drawable', type => 'drawable', desc => 'Input drawable' }, - { name => 'color', type => 'color', + { name => 'color', type => 'geglcolor', desc => 'Color to remove' } ); @@ -798,7 +798,7 @@ HELP GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL); + GeglColor *gegl_color = gegl_color_duplicate (color); GeglNode *node = gegl_node_new_child (NULL, "operation", "gegl:color-to-alpha", @@ -1575,17 +1575,14 @@ HELP GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { - GimpRGB from; - GimpRGB to; - GeglColor *gegl_from; - GeglColor *gegl_to; + GeglColor *gegl_from = gegl_color_new (NULL); + GeglColor *gegl_to = gegl_color_new (NULL); GeglNode *node; - gimp_rgb_set_uchar (&from, from_red, from_green, from_blue); - gimp_rgb_set_uchar (&to, to_red, to_green, to_blue); - - gegl_from = gimp_gegl_color_new (&from, NULL); - gegl_to = gimp_gegl_color_new (&to, NULL); + gegl_color_set_rgba (gegl_from, from_red / 255.0, from_green / 255.0, + from_blue / 255.0, 1.0); + gegl_color_set_rgba (gegl_to, to_red / 255.0, to_green / 255.0, + to_blue / 255.0, 1.0); node = gegl_node_new_child (NULL, "operation", "gegl:color-exchange", @@ -2881,8 +2878,8 @@ HELP desc => 'X coordinates of the center of supernova' }, { name => 'ycenter', type => 'int32', desc => 'Y coordinates of the center of supernova' }, - { name => 'color', type => 'color', - desc => 'Color of supernova' }, + { name => 'color', type => 'geglcolor', + desc => 'Color of supernova' }, { name => 'radius', type => '1 <= int32 <= 3000', desc => 'Radius of supernova' }, { name => 'nspoke', type => '1 <= int32 <= 1024', @@ -2898,11 +2895,13 @@ HELP GIMP_PDB_ITEM_CONTENT, error) && gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error)) { + GeglColor *gegl_color; GeglNode *node; - GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL); gdouble center_x = (gdouble) xcenter / (gdouble) gimp_item_get_width (GIMP_ITEM (drawable)); gdouble center_y = (gdouble) ycenter / (gdouble) gimp_item_get_height (GIMP_ITEM (drawable)); + gegl_color = gegl_color_duplicate (color); + node = gegl_node_new_child (NULL, "operation", "gegl:supernova", "center-x", center_x, diff --git a/pdb/pdb.pl b/pdb/pdb.pl index dfe7ac9089..0128ebd606 100644 --- a/pdb/pdb.pl +++ b/pdb/pdb.pl @@ -283,7 +283,8 @@ package Gimp::CodeGen::pdb; get_value_func => '$var = g_value_get_object ($value)', dup_value_func => '$var = g_value_dup_object (gimp_value_array_index ($value))', set_value_func => 'g_value_set_object ($value, $var)', - take_value_func => 'g_value_take_object ($value, $var)' }, + take_value_func => 'g_value_take_object ($value, $var)', + headers => [ qw( "libgimpcolor/gimpcolor.h") ] }, display => { name => 'DISPLAY', gtype => 'GIMP_TYPE_DISPLAY', diff --git a/plug-ins/common/blinds.c b/plug-ins/common/blinds.c index b66998de4f..794f1c345d 100644 --- a/plug-ins/common/blinds.c +++ b/plug-ins/common/blinds.c @@ -453,7 +453,6 @@ dialog_update_preview (GtkWidget *widget, GBytes *cache; const guchar *cache_start; GeglColor *color; - GimpRGB background; guchar bg[4]; gint width; gint height; @@ -477,18 +476,19 @@ dialog_update_preview (GtkWidget *widget, if (bg_trans) 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)) { - bg[0] = gimp_rgb_luminance_uchar (&background); - gimp_rgba_get_uchar (&background, NULL, NULL, NULL, bg + 3); + guchar luminance[2]; + + gegl_color_get_pixel (color, babl_format ("Y'A u8"), luminance); + bg[0] = luminance[0]; + bg[3] = luminance[1]; } else { - gimp_rgba_get_uchar (&background, bg, bg + 1, bg + 2, bg + 3); + gegl_color_get_pixel (color, babl_format ("R'G'B'A u8"), bg); } + g_object_unref (color); buffer = g_new (guchar, width * height * bpp); diff --git a/plug-ins/common/file-mng.c b/plug-ins/common/file-mng.c index e3bb20cb0e..3406bdfc72 100644 --- a/plug-ins/common/file-mng.c +++ b/plug-ins/common/file-mng.c @@ -947,13 +947,16 @@ mng_save_image (GFile *file, /* how do we get this to work? */ if (config_bkgd) { - GimpRGB bgcolor; - guchar red, green, blue; + GeglColor *background; + guchar rgb[3]; + guchar luminance[1]; - gimp_context_get_background (&bgcolor); - gimp_rgb_get_uchar (&bgcolor, &red, &green, &blue); + background = gimp_context_get_background (); + gegl_color_get_pixel (background, babl_format ("R'G'B' u8"), rgb); + gegl_color_get_pixel (background, babl_format ("Y' u8"), luminance); + g_object_unref (background); - if (mng_putchunk_back (handle, red, green, blue, + if (mng_putchunk_back (handle, rgb[0], rgb[1], rgb[2], MNG_BACKGROUNDCOLOR_MANDATORY, 0, MNG_BACKGROUNDIMAGE_NOTILE) != MNG_NOERROR) { @@ -962,8 +965,8 @@ mng_save_image (GFile *file, } if (mng_putchunk_bkgd (handle, MNG_FALSE, 2, 0, - gimp_rgb_luminance_uchar (&bgcolor), - red, green, blue) != MNG_NOERROR) + luminance, + rgb[0], rgb[1], rgb[2])) != MNG_NOERROR) { g_warning ("Unable to mng_putchunk_bkgd() in mng_save_image()"); goto err3;