From effeefb84a1a299c8b08b4fe4e89fb3ff632c2e2 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 10 Nov 2014 22:40:58 +0100 Subject: [PATCH] plug-ins, pdb: remove the color-exchange plug-in and add a PDB compat procedure. --- app/pdb/internal-procs.c | 2 +- app/pdb/plug-in-compat-cmds.c | 164 ++++++ plug-ins/common/.gitignore | 2 - plug-ins/common/Makefile.am | 18 - plug-ins/common/color-exchange.c | 783 ---------------------------- plug-ins/common/gimprc.common | 1 - plug-ins/common/plugin-defs.pl | 1 - po-plug-ins/POTFILES.in | 1 - tools/pdbgen/pdb/plug_in_compat.pdb | 83 +++ 9 files changed, 248 insertions(+), 807 deletions(-) delete mode 100644 plug-ins/common/color-exchange.c diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index bcc4e4f615..872acabbf9 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -28,7 +28,7 @@ #include "internal-procs.h" -/* 733 procedures registered total */ +/* 734 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c index cf16508f60..9da823271b 100644 --- a/app/pdb/plug-in-compat-cmds.c +++ b/app/pdb/plug-in-compat-cmds.c @@ -940,6 +940,80 @@ plug_in_deinterlace_invoker (GimpProcedure *procedure, error ? *error : NULL); } +static GimpValueArray * +plug_in_exchange_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpDrawable *drawable; + guint8 from_red; + guint8 from_green; + guint8 from_blue; + guint8 to_red; + guint8 to_green; + guint8 to_blue; + guint8 red_threshold; + guint8 green_threshold; + guint8 blue_threshold; + + drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp); + from_red = g_value_get_uint (gimp_value_array_index (args, 3)); + from_green = g_value_get_uint (gimp_value_array_index (args, 4)); + from_blue = g_value_get_uint (gimp_value_array_index (args, 5)); + to_red = g_value_get_uint (gimp_value_array_index (args, 6)); + to_green = g_value_get_uint (gimp_value_array_index (args, 7)); + to_blue = g_value_get_uint (gimp_value_array_index (args, 8)); + red_threshold = g_value_get_uint (gimp_value_array_index (args, 9)); + green_threshold = g_value_get_uint (gimp_value_array_index (args, 10)); + blue_threshold = g_value_get_uint (gimp_value_array_index (args, 11)); + + if (success) + { + if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, + 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; + 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); + gegl_to = gimp_gegl_color_new (&to); + + node = gegl_node_new_child (NULL, + "operation", "gegl:color-exchange", + "from-color", gegl_from, + "to-color", gegl_to, + "red-threshold", red_threshold / 255.0, + "green-threshold", green_threshold / 255.0, + "blue-threshold", blue_threshold / 255.0, + NULL); + + g_object_unref (gegl_from); + g_object_unref (gegl_to); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Color Exchange"), + node); + g_object_unref (node); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * plug_in_gauss_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -3258,6 +3332,96 @@ register_plug_in_compat_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-plug-in-exchange + */ + procedure = gimp_procedure_new (plug_in_exchange_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "plug-in-exchange"); + gimp_procedure_set_static_strings (procedure, + "plug-in-exchange", + "Swap one color with another", + "Exchange one color with another, optionally setting a threshold to convert from one shade to another.", + "Compatibility procedure. Please see 'gegl:color-exchange' for credits.", + "Compatibility procedure. Please see 'gegl:color-exchange' for credits.", + "2014", + NULL); + gimp_procedure_add_argument (procedure, + g_param_spec_enum ("run-mode", + "run mode", + "The run mode", + GIMP_TYPE_RUN_MODE, + GIMP_RUN_INTERACTIVE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_image_id ("image", + "image", + "Input image (unused)", + pdb->gimp, FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_drawable_id ("drawable", + "drawable", + "Input drawable", + pdb->gimp, FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("from-red", + "from red", + "Red value (from)", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("from-green", + "from green", + "Green value (from)", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("from-blue", + "from blue", + "Blue value (from)", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("to-red", + "to red", + "Red value (to)", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("to-green", + "to green", + "Green value (to)", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("to-blue", + "to blue", + "Blue value (to)", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("red-threshold", + "red threshold", + "Red threshold", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("green-threshold", + "green threshold", + "Green threshold", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("blue-threshold", + "blue threshold", + "Blue threshold", + 0, G_MAXUINT8, 0, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-plug-in-gauss */ diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore index 70bc36fb72..a95bb81a22 100644 --- a/plug-ins/common/.gitignore +++ b/plug-ins/common/.gitignore @@ -28,8 +28,6 @@ /color-cube-analyze.exe /color-enhance /color-enhance.exe -/color-exchange -/color-exchange.exe /colorify /colorify.exe /colormap-remap diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am index 9d6a5eb89a..51b8a7a0e4 100644 --- a/plug-ins/common/Makefile.am +++ b/plug-ins/common/Makefile.am @@ -57,7 +57,6 @@ libexec_PROGRAMS = \ cml-explorer \ color-cube-analyze \ color-enhance \ - color-exchange \ colorify \ colormap-remap \ compose \ @@ -408,23 +407,6 @@ color_enhance_LDADD = \ $(INTLLIBS) \ $(color_enhance_RC) -color_exchange_SOURCES = \ - color-exchange.c - -color_exchange_LDADD = \ - $(libgimpui) \ - $(libgimpwidgets) \ - $(libgimpmodule) \ - $(libgimp) \ - $(libgimpmath) \ - $(libgimpconfig) \ - $(libgimpcolor) \ - $(libgimpbase) \ - $(GTK_LIBS) \ - $(RT_LIBS) \ - $(INTLLIBS) \ - $(color_exchange_RC) - colorify_SOURCES = \ colorify.c diff --git a/plug-ins/common/color-exchange.c b/plug-ins/common/color-exchange.c deleted file mode 100644 index 0a70630fed..0000000000 --- a/plug-ins/common/color-exchange.c +++ /dev/null @@ -1,783 +0,0 @@ -/* - * This is a plug-in for GIMP. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * - */ - -/* - * Exchange one color with the other (settable threshold to convert from - * one color-shade to another...might do wonders on certain images, or be - * totally useless on others). - * - * Author: robert@experimental.net - * - * Added ability to select "from" color by clicking on the preview image. - * As a side effect, clicking twice on the same spot reverses the action, - * i.e. you can click once, see the result, and click again to revert. - * - * Also changed update policies for all sliders to delayed. On a slow machine - * the algorithm really chewes up CPU time. - * - * - timecop@japan.co.jp - */ - -#include "config.h" - -#include -#include - -#include "libgimp/stdplugins-intl.h" - - -#define PLUG_IN_PROC "plug-in-exchange" -#define PLUG_IN_BINARY "color-exchange" -#define PLUG_IN_ROLE "gimp-color-exchange" - -#define SCALE_WIDTH 128 - - -/* datastructure to store parameters in */ -typedef struct -{ - GimpRGB from; - GimpRGB to; - GimpRGB threshold; -} myParams; - -/* lets prototype */ -static void query (void); -static void run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals); - -static void exchange (GimpDrawable *drawable, - GimpPreview *preview); - -static gboolean exchange_dialog (GimpDrawable *preview); -static void color_button_callback (GtkWidget *widget, - gpointer data); -static void scale_callback (GtkAdjustment *adj, - gpointer data); - - -/* some global variables */ -static myParams xargs = -{ - { 0.0, 0.0, 0.0, 1.0 }, /* from */ - { 0.0, 0.0, 0.0, 1.0 }, /* to */ - { 0.0, 0.0, 0.0, 1.0 } /* threshold */ -}; - -static GtkWidget *from_colorbutton; -static gboolean lock_threshold = FALSE; - -/* lets declare what we want to do */ -const GimpPlugInInfo PLUG_IN_INFO = -{ - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run, /* run_proc */ -}; - -/* run program */ -MAIN () - -/* tell GIMP who we are */ -static void -query (void) -{ - static const GimpParamDef args[] = - { - { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" }, - { GIMP_PDB_IMAGE, "image", "Input image" }, - { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }, - { GIMP_PDB_INT8, "from-red", "Red value (from)" }, - { GIMP_PDB_INT8, "from-green", "Green value (from)" }, - { GIMP_PDB_INT8, "from-blue", "Blue value (from)" }, - { GIMP_PDB_INT8, "to-red", "Red value (to)" }, - { GIMP_PDB_INT8, "to-green", "Green value (to)" }, - { GIMP_PDB_INT8, "to-blue", "Blue value (to)" }, - { GIMP_PDB_INT8, "red-threshold", "Red threshold" }, - { GIMP_PDB_INT8, "green-threshold", "Green threshold" }, - { GIMP_PDB_INT8, "blue-threshold", "Blue threshold" } - }; - - gimp_install_procedure (PLUG_IN_PROC, - N_("Swap one color with another"), - "Exchange one color with another, optionally setting a threshold " - "to convert from one shade to another", - "robert@experimental.net", - "robert@experimental.net", - "June 17th, 1997", - N_("_Color Exchange..."), - "RGB*", - GIMP_PLUGIN, - G_N_ELEMENTS (args), 0, - args, NULL); - - gimp_plugin_menu_register (PLUG_IN_PROC, "/Colors/Map"); -} - -/* main function */ -static void -run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals) -{ - static GimpParam values[1]; - GimpRunMode runmode; - GimpPDBStatusType status = GIMP_PDB_SUCCESS; - GimpDrawable *drawable; - - *nreturn_vals = 1; - *return_vals = values; - - INIT_I18N (); - - values[0].type = GIMP_PDB_STATUS; - values[0].data.d_status = status; - - runmode = param[0].data.d_int32; - drawable = gimp_drawable_get (param[2].data.d_drawable); - - switch (runmode) - { - case GIMP_RUN_INTERACTIVE: - /* retrieve stored arguments (if any) */ - gimp_get_data (PLUG_IN_PROC, &xargs); - /* initialize using foreground color */ - gimp_context_get_foreground (&xargs.from); - - if (! exchange_dialog (drawable)) - return; - break; - - case GIMP_RUN_WITH_LAST_VALS: - gimp_get_data (PLUG_IN_PROC, &xargs); - /* - * instead of recalling the last-set values, - * run with the current foreground as 'from' - * color, making ALT-F somewhat more useful. - */ - gimp_context_get_foreground (&xargs.from); - break; - - case GIMP_RUN_NONINTERACTIVE: - if (nparams != 12) - { - status = GIMP_PDB_EXECUTION_ERROR; - } - else - { - gimp_rgb_set_uchar (&xargs.from, - param[3].data.d_int8, - param[4].data.d_int8, - param[5].data.d_int8); - gimp_rgb_set_uchar (&xargs.to, - param[6].data.d_int8, - param[7].data.d_int8, - param[8].data.d_int8); - gimp_rgb_set_uchar (&xargs.threshold, - param[9].data.d_int8, - param[10].data.d_int8, - param[11].data.d_int8); - } - break; - - default: - break; - } - - if (status == GIMP_PDB_SUCCESS) - { - if (gimp_drawable_is_rgb (drawable->drawable_id)) - { - gimp_progress_init (_("Color Exchange")); - gimp_tile_cache_ntiles (2 * (drawable->width / - gimp_tile_width () + 1)); - exchange (drawable, NULL); - gimp_drawable_detach (drawable); - - /* store our settings */ - if (runmode == GIMP_RUN_INTERACTIVE) - gimp_set_data (PLUG_IN_PROC, &xargs, sizeof (myParams)); - - /* and flush */ - if (runmode != GIMP_RUN_NONINTERACTIVE) - gimp_displays_flush (); - } - else - status = GIMP_PDB_EXECUTION_ERROR; - } - values[0].data.d_status = status; -} - -static gboolean -preview_event_handler (GtkWidget *area, - GdkEvent *event, - GtkWidget *preview) -{ - gint pos; - guchar *buf; - guint32 drawable_id; - GimpRGB color; - GdkEventButton *button_event = (GdkEventButton *)event; - - buf = GIMP_PREVIEW_AREA (area)->buf; - drawable_id = GIMP_DRAWABLE_PREVIEW (preview)->drawable->drawable_id; - - switch (event->type) - { - case GDK_BUTTON_PRESS: - if (button_event->button == 2) - { - pos = event->button.x * gimp_drawable_bpp (drawable_id) + - event->button.y * GIMP_PREVIEW_AREA (area)->rowstride; - - gimp_rgb_set_uchar (&color, buf[pos], buf[pos + 1], buf[pos + 2]); - gimp_color_button_set_color (GIMP_COLOR_BUTTON (from_colorbutton), - &color); - } - break; - - default: - break; - } - - return FALSE; -} - -/* show our dialog */ -static gboolean -exchange_dialog (GimpDrawable *drawable) -{ - GtkWidget *dialog; - GtkWidget *main_vbox; - GtkWidget *hbox; - GtkWidget *frame; - GtkWidget *preview; - GtkWidget *table; - GtkWidget *threshold; - GtkWidget *colorbutton; - GtkObject *adj; - GtkSizeGroup *group; - gint framenumber; - gboolean run; - - gimp_ui_init (PLUG_IN_BINARY, TRUE); - - dialog = gimp_dialog_new (_("Color Exchange"), PLUG_IN_ROLE, - NULL, 0, - gimp_standard_help_func, PLUG_IN_PROC, - - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - - NULL); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); - - gimp_window_set_transient (GTK_WINDOW (dialog)); - - /* do some boxes here */ - main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); - gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - main_vbox, TRUE, TRUE, 0); - gtk_widget_show (main_vbox); - - frame = gimp_frame_new (_("Middle-Click Inside Preview to " - "Pick \"From Color\"")); - gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0); - gtk_widget_show (frame); - - preview = gimp_drawable_preview_new (drawable, NULL); - gtk_container_add (GTK_CONTAINER (frame), preview); - gtk_widget_show (preview); - - g_signal_connect_swapped (preview, "invalidated", - G_CALLBACK (exchange), - drawable); - g_signal_connect (GIMP_PREVIEW (preview)->area, "event", - G_CALLBACK (preview_event_handler), - preview); - - /* a hidden color_button to handle the threshold more easily */ - threshold = gimp_color_button_new (NULL, 1, 1, - &xargs.threshold, - GIMP_COLOR_AREA_FLAT); - - g_signal_connect (threshold, "color-changed", - G_CALLBACK (gimp_color_button_get_color), - &xargs.threshold); - g_signal_connect (threshold, "color-changed", - G_CALLBACK (color_button_callback), - &xargs.threshold); - g_signal_connect_swapped (threshold, "color-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - /* and our scales */ - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - for (framenumber = 0; framenumber < 2; framenumber++) - { - GtkWidget *vbox; - GtkWidget *image; - gint row = 0; - - frame = gimp_frame_new (framenumber ? _("To Color") : _("From Color")); - gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0); - gtk_widget_show (frame); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show (vbox); - - table = gtk_table_new (framenumber ? 4 : 8, 4, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (table), 6); - gtk_table_set_row_spacings (GTK_TABLE (table), 6); - gtk_table_set_row_spacing (GTK_TABLE (table), 0, 12); - - if (! framenumber) - { - gtk_table_set_row_spacing (GTK_TABLE (table), 1, 2); - gtk_table_set_row_spacing (GTK_TABLE (table), 3, 2); - gtk_table_set_row_spacing (GTK_TABLE (table), 5, 2); - } - - gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); - gtk_widget_show (table); - - colorbutton = gimp_color_button_new (framenumber ? - _("Color Exchange: To Color") : - _("Color Exchange: From Color"), - SCALE_WIDTH / 2, 16, - (framenumber ? - &xargs.to : &xargs.from), - GIMP_COLOR_AREA_FLAT); - gimp_table_attach_aligned (GTK_TABLE (table), 0, row++, - NULL, 0.0, 0.0, - colorbutton, 1, FALSE); - - g_signal_connect (colorbutton, "color-changed", - G_CALLBACK (gimp_color_button_get_color), - framenumber ? &xargs.to : &xargs.from); - g_signal_connect (colorbutton, "color-changed", - G_CALLBACK (color_button_callback), - framenumber ? &xargs.to : &xargs.from); - g_signal_connect_swapped (colorbutton, "color-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - if (! framenumber) - from_colorbutton = colorbutton; - - /* Red */ - image = gtk_image_new_from_icon_name (GIMP_STOCK_CHANNEL_RED, - GTK_ICON_SIZE_BUTTON); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5); - gtk_table_attach (GTK_TABLE (table), image, - 0, 1, row, row + 1 + (framenumber ? 0 : 1), - GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show (image); - - adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++, - _("_Red:"), SCALE_WIDTH, 0, - framenumber ? xargs.to.r : xargs.from.r, - 0.0, 1.0, 0.01, 0.1, 3, - TRUE, 0, 0, - NULL, NULL); - - g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton); - g_object_set_data (G_OBJECT (colorbutton), "red", adj); - - g_signal_connect (adj, "value-changed", - G_CALLBACK (gimp_double_adjustment_update), - framenumber ? &xargs.to.r : &xargs.from.r); - g_signal_connect (adj, "value-changed", - G_CALLBACK (scale_callback), - framenumber ? &xargs.to : &xargs.from); - g_signal_connect_swapped (adj, "value-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj)); - - if (! framenumber) - { - adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++, - _("R_ed threshold:"), SCALE_WIDTH, 0, - xargs.threshold.r, - 0.0, 1.0, 0.01, 0.1, 3, - TRUE, 0, 0, - NULL, NULL); - - g_object_set_data (G_OBJECT (adj), "colorbutton", threshold); - g_object_set_data (G_OBJECT (threshold), "red", adj); - - g_signal_connect (adj, "value-changed", - G_CALLBACK (gimp_double_adjustment_update), - &xargs.threshold.r); - g_signal_connect (adj, "value-changed", - G_CALLBACK (scale_callback), - &xargs.threshold); - g_signal_connect_swapped (adj, "value-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj)); - } - - /* Green */ - image = gtk_image_new_from_icon_name (GIMP_STOCK_CHANNEL_GREEN, - GTK_ICON_SIZE_BUTTON); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5); - gtk_table_attach (GTK_TABLE (table), image, - 0, 1, row, row + 1 + (framenumber ? 0 : 1), - GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show (image); - - adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++, - _("_Green:"), SCALE_WIDTH, 0, - framenumber ? xargs.to.g : xargs.from.g, - 0.0, 1.0, 0.01, 0.1, 3, - TRUE, 0, 0, - NULL, NULL); - - g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton); - g_object_set_data (G_OBJECT (colorbutton), "green", adj); - - g_signal_connect (adj, "value-changed", - G_CALLBACK (gimp_double_adjustment_update), - framenumber ? &xargs.to.g : &xargs.from.g); - g_signal_connect (adj, "value-changed", - G_CALLBACK (scale_callback), - framenumber ? &xargs.to : &xargs.from); - g_signal_connect_swapped (adj, "value-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj)); - - if (! framenumber) - { - adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++, - _("G_reen threshold:"), SCALE_WIDTH, 0, - xargs.threshold.g, - 0.0, 1.0, 0.01, 0.1, 3, - TRUE, 0, 0, - NULL, NULL); - - g_object_set_data (G_OBJECT (adj), "colorbutton", threshold); - g_object_set_data (G_OBJECT (threshold), "green", adj); - - g_signal_connect (adj, "value-changed", - G_CALLBACK (gimp_double_adjustment_update), - &xargs.threshold.g); - g_signal_connect (adj, "value-changed", - G_CALLBACK (scale_callback), - &xargs.threshold); - g_signal_connect_swapped (adj, "value-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj)); - } - - /* Blue */ - image = gtk_image_new_from_icon_name (GIMP_STOCK_CHANNEL_BLUE, - GTK_ICON_SIZE_BUTTON); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5); - gtk_table_attach (GTK_TABLE (table), image, - 0, 1, row, row + 1 + (framenumber ? 0 : 1), - GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show (image); - - adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++, - _("_Blue:"), SCALE_WIDTH, 0, - framenumber ? xargs.to.b : xargs.from.b, - 0.0, 1.0, 0.01, 0.1, 3, - TRUE, 0, 0, - NULL, NULL); - - g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton); - g_object_set_data (G_OBJECT (colorbutton), "blue", adj); - - g_signal_connect (adj, "value-changed", - G_CALLBACK (gimp_double_adjustment_update), - framenumber ? &xargs.to.b : &xargs.from.b); - g_signal_connect (adj, "value-changed", - G_CALLBACK (scale_callback), - framenumber ? &xargs.to : &xargs.from); - g_signal_connect_swapped (adj, "value-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj)); - - if (! framenumber) - { - adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++, - _("B_lue threshold:"), SCALE_WIDTH, 0, - xargs.threshold.b, - 0.0, 1.0, 0.01, 0.1, 3, - TRUE, 0, 0, - NULL, NULL); - - g_object_set_data (G_OBJECT (adj), "colorbutton", threshold); - g_object_set_data (G_OBJECT (threshold), "blue", adj); - - g_signal_connect (adj, "value-changed", - G_CALLBACK (gimp_double_adjustment_update), - &xargs.threshold.b); - g_signal_connect (adj, "value-changed", - G_CALLBACK (scale_callback), - &xargs.threshold); - g_signal_connect_swapped (adj, "value-changed", - G_CALLBACK (gimp_preview_invalidate), - preview); - - gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj)); - } - - if (! framenumber) - { - GtkWidget *button; - - button = gtk_check_button_new_with_mnemonic (_("Lock _thresholds")); - gtk_table_attach (GTK_TABLE (table), button, 2, 4, row, row + 1, - GTK_FILL, 0, 0, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), - lock_threshold); - gtk_widget_show (button); - - g_signal_connect (button, "clicked", - G_CALLBACK (gimp_toggle_button_update), - &lock_threshold); - g_signal_connect_swapped (button, "clicked", - G_CALLBACK (gimp_preview_invalidate), - preview); - } - } - - g_object_unref (group); - - /* show everything */ - gtk_widget_show (dialog); - - run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); - - gtk_widget_destroy (dialog); - - return run; -} - -static void -color_button_callback (GtkWidget *widget, - gpointer data) -{ - GtkObject *red_adj; - GtkObject *green_adj; - GtkObject *blue_adj; - GimpRGB *color; - - color = (GimpRGB *) data; - - red_adj = (GtkObject *) g_object_get_data (G_OBJECT (widget), "red"); - green_adj = (GtkObject *) g_object_get_data (G_OBJECT (widget), "green"); - blue_adj = (GtkObject *) g_object_get_data (G_OBJECT (widget), "blue"); - - if (red_adj) - gtk_adjustment_set_value (GTK_ADJUSTMENT (red_adj), color->r); - if (green_adj) - gtk_adjustment_set_value (GTK_ADJUSTMENT (green_adj), color->g); - if (blue_adj) - gtk_adjustment_set_value (GTK_ADJUSTMENT (blue_adj), color->b); -} - -static void -scale_callback (GtkAdjustment *adj, - gpointer data) -{ - GtkObject *object; - GimpRGB *color; - - color = (GimpRGB *) data; - - object = g_object_get_data (G_OBJECT (adj), "colorbutton"); - - if (GIMP_IS_COLOR_BUTTON (object)) - { - if (color == &xargs.threshold && lock_threshold == TRUE) - { - gdouble value = gtk_adjustment_get_value (adj); - - gimp_rgb_set (color, value, value, value); - } - - gimp_color_button_set_color (GIMP_COLOR_BUTTON (object), color); - } -} - -/* do the exchanging */ -static void -exchange (GimpDrawable *drawable, - GimpPreview *preview) -{ - GimpPixelRgn srcPR, destPR; - guchar min_red, min_green, min_blue; - guchar max_red, max_green, max_blue; - guchar from_red, from_green, from_blue; - guchar to_red, to_green, to_blue; - guchar *src_row, *dest_row; - gint x, y, bpp = drawable->bpp; - gboolean has_alpha; - gint x1, y1, y2; - gint width, height; - GimpRGB min; - GimpRGB max; - - if (preview) - { - gimp_preview_get_position (preview, &x1, &y1); - gimp_preview_get_size (preview, &width, &height); - } - else if (! gimp_drawable_mask_intersect (drawable->drawable_id, - &x1, &y1, &width, &height)) - { - return; - } - - y2 = y1 + height; - - has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); - /* allocate memory */ - src_row = g_new (guchar, drawable->width * bpp); - - gimp_rgb_get_uchar (&xargs.from, &from_red, &from_green, &from_blue); - gimp_rgb_get_uchar (&xargs.to, &to_red, &to_green, &to_blue); - - /* get boundary values */ - min = xargs.from; - gimp_rgb_subtract (&min, &xargs.threshold); - gimp_rgb_clamp (&min); - gimp_rgb_get_uchar (&min, &min_red, &min_green, &min_blue); - - max = xargs.from; - gimp_rgb_add (&max, &xargs.threshold); - gimp_rgb_clamp (&max); - gimp_rgb_get_uchar (&max, &max_red, &max_green, &max_blue); - - dest_row = g_new (guchar, drawable->width * bpp); - - gimp_pixel_rgn_init (&srcPR, drawable, - x1, y1, width, height, FALSE, FALSE); - gimp_pixel_rgn_init (&destPR, drawable, - x1, y1, width, height, (preview == NULL), TRUE); - - for (y = y1; y < y2; y++) - { - gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y, width); - - for (x = 0; x < width; x++) - { - guchar pixel_red, pixel_green, pixel_blue; - guchar new_red, new_green, new_blue; - guint idx; - - /* get current pixel-values */ - pixel_red = src_row[x * bpp]; - pixel_green = src_row[x * bpp + 1]; - pixel_blue = src_row[x * bpp + 2]; - - idx = x * bpp; - - /* want this pixel? */ - if (pixel_red >= min_red && - pixel_red <= max_red && - pixel_green >= min_green && - pixel_green <= max_green && - pixel_blue >= min_blue && - pixel_blue <= max_blue) - { - guchar red_delta, green_delta, blue_delta; - - red_delta = pixel_red > from_red ? - pixel_red - from_red : from_red - pixel_red; - green_delta = pixel_green > from_green ? - pixel_green - from_green : from_green - pixel_green; - blue_delta = pixel_blue > from_blue ? - pixel_blue - from_blue : from_blue - pixel_blue; - - new_red = CLAMP (to_red + red_delta, 0, 255); - new_green = CLAMP (to_green + green_delta, 0, 255); - new_blue = CLAMP (to_blue + blue_delta, 0, 255); - } - else - { - new_red = pixel_red; - new_green = pixel_green; - new_blue = pixel_blue; - } - - /* fill buffer */ - dest_row[idx + 0] = new_red; - dest_row[idx + 1] = new_green; - dest_row[idx + 2] = new_blue; - - /* copy alpha-channel */ - if (has_alpha) - dest_row[idx + 3] = src_row[x * bpp + 3]; - } - /* store the dest */ - gimp_pixel_rgn_set_row (&destPR, dest_row, x1, y, width); - - /* and tell the user what we're doing */ - if (!preview && (y % 10) == 0) - gimp_progress_update ((gdouble) y / (gdouble) height); - } - - g_free (src_row); - g_free (dest_row); - - if (preview) - { - gimp_drawable_preview_draw_region (GIMP_DRAWABLE_PREVIEW (preview), - &destPR); - } - else - { - gimp_progress_update (1.0); - /* update the processed region */ - gimp_drawable_flush (drawable); - gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); - gimp_drawable_update (drawable->drawable_id, x1, y1, width, height); - } -} diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common index e41ed6ea5e..3962c96163 100644 --- a/plug-ins/common/gimprc.common +++ b/plug-ins/common/gimprc.common @@ -11,7 +11,6 @@ checkerboard_RC = checkerboard.rc.o cml_explorer_RC = cml-explorer.rc.o color_cube_analyze_RC = color-cube-analyze.rc.o color_enhance_RC = color-enhance.rc.o -color_exchange_RC = color-exchange.rc.o colorify_RC = colorify.rc.o colormap_remap_RC = colormap-remap.rc.o compose_RC = compose.rc.o diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl index 610e024ea1..05857aa556 100644 --- a/plug-ins/common/plugin-defs.pl +++ b/plug-ins/common/plugin-defs.pl @@ -12,7 +12,6 @@ 'cml-explorer' => { ui => 1 }, 'color-cube-analyze' => { ui => 1 }, 'color-enhance' => { ui => 1 }, - 'color-exchange' => { ui => 1 }, 'colorify' => { ui => 1 }, 'colormap-remap' => { ui => 1, gegl => 1 }, 'compose' => { ui => 1, gegl => 1 }, diff --git a/po-plug-ins/POTFILES.in b/po-plug-ins/POTFILES.in index c72e97c5f7..e16a168933 100644 --- a/po-plug-ins/POTFILES.in +++ b/po-plug-ins/POTFILES.in @@ -16,7 +16,6 @@ plug-ins/common/checkerboard.c plug-ins/common/cml-explorer.c plug-ins/common/color-cube-analyze.c plug-ins/common/color-enhance.c -plug-ins/common/color-exchange.c plug-ins/common/colorify.c plug-ins/common/colormap-remap.c plug-ins/common/compose.c diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb index 01064fcb06..910cfb1340 100644 --- a/tools/pdbgen/pdb/plug_in_compat.pdb +++ b/tools/pdbgen/pdb/plug_in_compat.pdb @@ -844,6 +844,88 @@ CODE ); } +sub plug_in_exchange { + $blurb = 'Swap one color with another'; + + $help = <<'HELP'; +Exchange one color with another, optionally setting a threshold to +convert from one shade to another. +HELP + + &std_pdb_compat('gegl:color-exchange'); + $date = '2014'; + + @inargs = ( + { name => 'run_mode', type => 'enum GimpRunMode', dead => 1, + desc => 'The run mode' }, + { name => 'image', type => 'image', dead => 1, + desc => 'Input image (unused)' }, + { name => 'drawable', type => 'drawable', + desc => 'Input drawable' }, + + { name => 'from_red', type => 'int8', + desc => 'Red value (from)' }, + { name => 'from_green', type => 'int8', + desc => 'Green value (from)' }, + { name => 'from_blue', type => 'int8', + desc => 'Blue value (from)' }, + { name => 'to_red', type => 'int8', + desc => 'Red value (to)' }, + { name => 'to_green', type => 'int8', + desc => 'Green value (to)' }, + { name => 'to_blue', type => 'int8', + desc => 'Blue value (to)' }, + { name => 'red_threshold', type => 'int8', + desc => 'Red threshold' }, + { name => 'green_threshold', type => 'int8', + desc => 'Green threshold' }, + { name => 'blue_threshold', type => 'int8', + desc => 'Blue threshold' } + ); + + %invoke = ( + code => <<'CODE' +{ + if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, + 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; + 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); + gegl_to = gimp_gegl_color_new (&to); + + node = gegl_node_new_child (NULL, + "operation", "gegl:color-exchange", + "from-color", gegl_from, + "to-color", gegl_to, + "red-threshold", red_threshold / 255.0, + "green-threshold", green_threshold / 255.0, + "blue-threshold", blue_threshold / 255.0, + NULL); + + g_object_unref (gegl_from); + g_object_unref (gegl_to); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Color Exchange"), + node); + g_object_unref (node); + } + else + success = FALSE; +} +CODE + ); +} + sub plug_in_gauss { $blurb = 'Simplest, most commonly used way of blurring'; @@ -2890,6 +2972,7 @@ CODE plug_in_convmatrix plug_in_cubism plug_in_deinterlace + plug_in_exchange plug_in_gauss plug_in_gauss_iir plug_in_gauss_iir2