1997-11-25 06:05:25 +08:00
|
|
|
/*
|
|
|
|
* This is a plug-in for the 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 2 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, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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).
|
2003-11-06 23:27:05 +08:00
|
|
|
*
|
1997-11-25 06:05:25 +08:00
|
|
|
* Author: robert@experimental.net
|
2000-12-19 20:54:34 +08:00
|
|
|
*
|
|
|
|
* 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
|
1999-03-18 04:52:50 +08:00
|
|
|
*/
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-08-01 00:06:20 +08:00
|
|
|
#include <string.h>
|
2002-01-30 22:54:27 +08:00
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-07 06:26:10 +08:00
|
|
|
|
1999-12-24 09:17:52 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
#define SCALE_WIDTH 128
|
2000-01-18 01:02:26 +08:00
|
|
|
#define PREVIEW_SIZE 128
|
1998-07-03 02:06:30 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* datastructure to store parameters in */
|
|
|
|
typedef struct
|
|
|
|
{
|
2001-01-12 07:36:59 +08:00
|
|
|
GimpRGB from;
|
|
|
|
GimpRGB to;
|
|
|
|
GimpRGB threshold;
|
2000-01-18 01:02:26 +08:00
|
|
|
gint32 image;
|
|
|
|
gint32 drawable;
|
|
|
|
} myParams;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* lets prototype */
|
2004-08-01 00:06:20 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
static void exchange (void);
|
|
|
|
static void real_exchange (gint, gint, gint, gint, gboolean);
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
static gboolean exchange_dialog (void);
|
2004-08-01 00:06:20 +08:00
|
|
|
static void update_preview (void);
|
|
|
|
static void color_button_callback (GtkWidget *, gpointer);
|
|
|
|
static void scale_callback (GtkAdjustment *, gpointer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* some global variables */
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpDrawable *drw;
|
2000-02-08 04:35:13 +08:00
|
|
|
static gboolean has_alpha;
|
2003-11-06 23:27:05 +08:00
|
|
|
static myParams xargs = { { 0.0, 0.0, 0.0, 1.0 },
|
2004-08-01 00:06:20 +08:00
|
|
|
{ 0.0, 0.0, 0.0, 1.0 },
|
|
|
|
{ 0.0, 0.0, 0.0, 1.0 },
|
|
|
|
0, 0 };
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpPixelRgn origregion;
|
2001-01-12 07:36:59 +08:00
|
|
|
static GtkWidget *preview;
|
|
|
|
static GtkWidget *from_colorbutton;
|
|
|
|
static gint sel_x1, sel_y1, sel_x2, sel_y2;
|
|
|
|
static gint prev_width, prev_height, sel_width, sel_height;
|
|
|
|
static gboolean lock_threshold = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* lets declare what we want to do */
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* run program */
|
2000-05-01 05:03:44 +08:00
|
|
|
MAIN ()
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* tell GIMP who we are */
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
2000-01-18 01:02:26 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
|
|
|
{ GIMP_PDB_INT8, "fromred", "Red value (from)" },
|
|
|
|
{ GIMP_PDB_INT8, "fromgreen", "Green value (from)" },
|
|
|
|
{ GIMP_PDB_INT8, "fromblue", "Blue value (from)" },
|
|
|
|
{ GIMP_PDB_INT8, "tored", "Red value (to)" },
|
|
|
|
{ GIMP_PDB_INT8, "togreen", "Green value (to)" },
|
|
|
|
{ GIMP_PDB_INT8, "toblue", "Blue value (to)" },
|
|
|
|
{ GIMP_PDB_INT8, "red_threshold", "Red threshold" },
|
|
|
|
{ GIMP_PDB_INT8, "green_threshold", "Green threshold" },
|
|
|
|
{ GIMP_PDB_INT8, "blue_threshold", "Blue threshold" }
|
2000-01-18 01:02:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
gimp_install_procedure ("plug_in_exchange",
|
2004-08-01 00:06:20 +08:00
|
|
|
"Color Exchange",
|
|
|
|
"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);
|
2004-05-07 08:30:24 +08:00
|
|
|
|
|
|
|
gimp_plugin_menu_register ("plug_in_exchange",
|
|
|
|
N_("<Image>/Filters/Colors/Map"));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* main function */
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
2003-07-02 19:07:41 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-07-02 19:07:41 +08:00
|
|
|
static GimpParam values[1];
|
2004-08-01 00:06:20 +08:00
|
|
|
GimpRunMode runmode;
|
2003-07-02 19:07:41 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
2000-01-18 01:02:26 +08:00
|
|
|
values[0].data.d_status = status;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
runmode = param[0].data.d_int32;
|
|
|
|
xargs.image = param[1].data.d_image;
|
|
|
|
xargs.drawable = param[2].data.d_drawable;
|
|
|
|
drw = gimp_drawable_get (xargs.drawable);
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-10-04 00:15:53 +08:00
|
|
|
/* initialize misc. things */
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drw->drawable_id,
|
2004-08-01 00:06:20 +08:00
|
|
|
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
|
2000-10-04 00:15:53 +08:00
|
|
|
sel_width = sel_x2 - sel_x1;
|
|
|
|
sel_height = sel_y2 - sel_y1;
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2000-10-04 00:15:53 +08:00
|
|
|
if (sel_width > PREVIEW_SIZE)
|
|
|
|
prev_width = PREVIEW_SIZE;
|
|
|
|
else
|
|
|
|
prev_width = sel_width;
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2000-10-04 00:15:53 +08:00
|
|
|
if (sel_height > PREVIEW_SIZE)
|
|
|
|
prev_height = PREVIEW_SIZE;
|
|
|
|
else
|
|
|
|
prev_height = sel_height;
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
has_alpha = gimp_drawable_has_alpha (drw->drawable_id);
|
2000-10-04 00:15:53 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
switch (runmode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2000-01-18 01:02:26 +08:00
|
|
|
/* retrieve stored arguments (if any) */
|
|
|
|
gimp_get_data ("plug_in_exchange", &xargs);
|
|
|
|
/* initialize using foreground color */
|
2004-09-23 02:43:09 +08:00
|
|
|
gimp_context_get_foreground (&xargs.from);
|
2001-01-12 07:36:59 +08:00
|
|
|
|
2000-12-19 20:54:34 +08:00
|
|
|
if (! exchange_dialog ())
|
2004-08-01 00:06:20 +08:00
|
|
|
return;
|
2000-01-18 01:02:26 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-01-18 01:02:26 +08:00
|
|
|
gimp_get_data ("plug_in_exchange", &xargs);
|
2003-11-06 23:27:05 +08:00
|
|
|
/*
|
2000-01-18 01:02:26 +08:00
|
|
|
* instead of recalling the last-set values,
|
|
|
|
* run with the current foreground as 'from'
|
|
|
|
* color, making ALT-F somewhat more useful.
|
|
|
|
*/
|
2004-09-23 02:43:09 +08:00
|
|
|
gimp_context_get_foreground (&xargs.from);
|
2000-01-18 01:02:26 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2000-10-04 00:15:53 +08:00
|
|
|
if (nparams != 12)
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
2000-02-08 04:35:13 +08:00
|
|
|
else
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
break;
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
default:
|
2000-01-18 01:02:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2000-01-18 01:02:26 +08:00
|
|
|
{
|
2001-06-15 04:07:38 +08:00
|
|
|
if (gimp_drawable_is_rgb (drw->drawable_id))
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
gimp_progress_init (_("Color Exchange..."));
|
|
|
|
gimp_tile_cache_ntiles (2 * (drw->width / gimp_tile_width () + 1));
|
|
|
|
exchange ();
|
|
|
|
gimp_drawable_detach( drw);
|
|
|
|
|
|
|
|
/* store our settings */
|
|
|
|
if (runmode == GIMP_RUN_INTERACTIVE)
|
|
|
|
gimp_set_data ("plug_in_exchange", &xargs, sizeof (myParams));
|
|
|
|
|
|
|
|
/* and flush */
|
|
|
|
if (runmode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
else
|
2004-08-01 00:06:20 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2000-01-18 01:02:26 +08:00
|
|
|
}
|
|
|
|
values[0].data.d_status = status;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do the exchanging */
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
|
|
|
exchange (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
/* do the real exchange */
|
|
|
|
real_exchange (-1, -1, -1, -1, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-12-19 20:54:34 +08:00
|
|
|
static gboolean
|
2003-11-06 23:27:05 +08:00
|
|
|
preview_event_handler (GtkWidget *widget,
|
2004-08-01 00:06:20 +08:00
|
|
|
GdkEvent *event)
|
2000-12-19 20:54:34 +08:00
|
|
|
{
|
2001-01-12 07:36:59 +08:00
|
|
|
gint pos;
|
|
|
|
guchar *buf;
|
2003-11-06 23:27:05 +08:00
|
|
|
GimpRGB color;
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
buf = GIMP_PREVIEW_AREA (widget)->buf;
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
switch(event->type)
|
2000-12-19 20:54:34 +08:00
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
2004-08-01 00:06:20 +08:00
|
|
|
pos = event->button.x * gimp_drawable_bpp(drw->drawable_id) +
|
|
|
|
event->button.y * GIMP_PREVIEW_AREA(widget)->rowstride;
|
2001-01-12 07:36:59 +08:00
|
|
|
|
|
|
|
gimp_rgb_set_uchar (&color, buf[pos], buf[pos + 1], buf[pos + 2]);
|
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (from_colorbutton), &color);
|
|
|
|
|
2000-12-19 20:54:34 +08:00
|
|
|
break;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-12-19 20:54:34 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* show our dialog */
|
2004-05-19 07:07:29 +08:00
|
|
|
static gboolean
|
2000-12-19 20:54:34 +08:00
|
|
|
exchange_dialog (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *mainbox;
|
|
|
|
GtkWidget *frame;
|
2000-01-26 01:46:56 +08:00
|
|
|
GtkWidget *abox;
|
|
|
|
GtkWidget *pframe;
|
2000-01-18 01:02:26 +08:00
|
|
|
GtkWidget *table;
|
2001-01-12 07:36:59 +08:00
|
|
|
GtkWidget *threshold;
|
2000-01-18 01:02:26 +08:00
|
|
|
GtkWidget *colorbutton;
|
2000-12-19 20:54:34 +08:00
|
|
|
GtkWidget *scale;
|
2004-05-19 07:07:29 +08:00
|
|
|
GtkSizeGroup *group;
|
2001-01-12 07:36:59 +08:00
|
|
|
GtkObject *adj;
|
2000-12-19 20:54:34 +08:00
|
|
|
gint framenumber;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
2000-05-01 05:03:44 +08:00
|
|
|
|
|
|
|
gimp_ui_init ("exchange", TRUE);
|
2000-01-07 06:26:10 +08:00
|
|
|
|
|
|
|
/* load pixelregion */
|
|
|
|
gimp_pixel_rgn_init (&origregion, drw,
|
2004-08-01 00:06:20 +08:00
|
|
|
0, 0, PREVIEW_SIZE, PREVIEW_SIZE, FALSE, FALSE);
|
2000-01-07 06:26:10 +08:00
|
|
|
|
|
|
|
/* set up the dialog */
|
|
|
|
dialog = gimp_dialog_new (_("Color Exchange"), "exchange",
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
2004-08-01 00:06:20 +08:00
|
|
|
gimp_standard_help_func, "plug-in-exchange",
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
NULL);
|
2000-01-07 06:26:10 +08:00
|
|
|
|
|
|
|
/* do some boxes here */
|
2004-05-19 07:07:29 +08:00
|
|
|
mainbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (mainbox), 12);
|
2000-01-07 06:26:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), mainbox,
|
2004-08-01 00:06:20 +08:00
|
|
|
TRUE, TRUE, 0);
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
frame = gimp_frame_new (_("Click inside preview to pick \"From Color\""));
|
2000-01-18 01:02:26 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (mainbox), frame, FALSE, FALSE, 0);
|
2000-01-07 06:26:10 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
abox = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), abox);
|
|
|
|
gtk_widget_show (abox);
|
|
|
|
|
|
|
|
pframe = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (pframe), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), pframe);
|
|
|
|
gtk_widget_show (pframe);
|
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
preview = gimp_preview_area_new ();
|
|
|
|
gtk_widget_set_size_request (preview, prev_width, prev_height);
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (pframe), preview);
|
2000-12-19 20:54:34 +08:00
|
|
|
gtk_widget_set_events (GTK_WIDGET(preview),
|
2004-08-01 00:06:20 +08:00
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON1_MOTION_MASK);
|
2000-12-19 20:54:34 +08:00
|
|
|
gtk_widget_show (preview);
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (preview, "event",
|
|
|
|
G_CALLBACK (preview_event_handler),
|
2001-12-29 21:26:29 +08:00
|
|
|
NULL);
|
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
/* a hidden color_button to handle the threshold more easily */
|
2003-11-06 23:27:05 +08:00
|
|
|
threshold = gimp_color_button_new (NULL, 1, 1,
|
2004-08-01 00:06:20 +08:00
|
|
|
&xargs.threshold,
|
|
|
|
GIMP_COLOR_AREA_FLAT);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (threshold, "color_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_color_button_get_color),
|
|
|
|
&xargs.threshold);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (threshold, "color_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (color_button_callback),
|
|
|
|
&xargs.threshold);
|
2001-01-12 07:36:59 +08:00
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
/* and our scales */
|
2004-05-19 07:07:29 +08:00
|
|
|
group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
for (framenumber = 0; framenumber < 2; framenumber++)
|
|
|
|
{
|
2004-05-19 07:07:29 +08:00
|
|
|
GtkWidget *image;
|
2004-05-19 21:15:11 +08:00
|
|
|
gint row = 0;
|
2004-05-19 07:07:29 +08:00
|
|
|
|
|
|
|
frame = gimp_frame_new (framenumber ? _("To Color") : _("From Color"));
|
2000-01-18 01:02:26 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (mainbox), frame, FALSE, FALSE, 0);
|
2000-01-07 06:26:10 +08:00
|
|
|
gtk_widget_show (frame);
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2004-05-19 21:15:11 +08:00
|
|
|
table = gtk_table_new (framenumber ? 4 : 8, 4, FALSE);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
2004-05-19 21:15:11 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 12);
|
|
|
|
if (!framenumber)
|
|
|
|
{
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 2, 6);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 4, 6);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 6, 6);
|
|
|
|
}
|
2000-01-07 06:26:10 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
2000-01-18 01:02:26 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
colorbutton = gimp_color_button_new (framenumber ?
|
2004-08-01 00:06:20 +08:00
|
|
|
_("Color Exchange: To Color") :
|
|
|
|
_("Color Exchange: From Color"),
|
|
|
|
SCALE_WIDTH / 2, 16,
|
|
|
|
(framenumber ?
|
2004-05-19 21:15:11 +08:00
|
|
|
&xargs.to : &xargs.from),
|
2004-08-01 00:06:20 +08:00
|
|
|
GIMP_COLOR_AREA_FLAT);
|
2004-05-19 21:15:11 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
|
2004-05-19 07:07:29 +08:00
|
|
|
NULL, 0.0, 0.0,
|
|
|
|
colorbutton, 1, FALSE);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (colorbutton, "color_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_color_button_get_color),
|
|
|
|
framenumber ? &xargs.to : &xargs.from);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (colorbutton, "color_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (color_button_callback),
|
|
|
|
framenumber ? &xargs.to : &xargs.from);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
if (!framenumber)
|
2004-08-01 00:06:20 +08:00
|
|
|
from_colorbutton = colorbutton;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
/* Red */
|
2004-05-19 07:07:29 +08:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_RED,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
2004-05-19 21:15:11 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_table_attach (GTK_TABLE (table), image,
|
2004-05-19 21:15:11 +08:00
|
|
|
0, 1, row, row + 1 + (framenumber ? 0 : 1),
|
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2004-05-19 21:15:11 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++,
|
2004-08-01 00:06:20 +08:00
|
|
|
_("_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);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton);
|
|
|
|
g_object_set_data (G_OBJECT (colorbutton), "red", adj);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
framenumber ? &xargs.to.r : &xargs.from.r);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (scale_callback),
|
|
|
|
framenumber ? &xargs.to : &xargs.from);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
|
|
|
scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
if (! framenumber)
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
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",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&xargs.threshold.r);
|
2004-08-01 00:06:20 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (scale_callback),
|
|
|
|
&xargs.threshold);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
|
2004-08-01 00:06:20 +08:00
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
/* Green */
|
2004-05-19 07:07:29 +08:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_GREEN,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
2004-05-19 21:15:11 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_table_attach (GTK_TABLE (table), image,
|
2004-05-19 21:15:11 +08:00
|
|
|
0, 1, row, row + 1 + (framenumber ? 0 : 1),
|
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2004-05-19 21:15:11 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++,
|
2004-08-01 00:06:20 +08:00
|
|
|
_("_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);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton);
|
|
|
|
g_object_set_data (G_OBJECT (colorbutton), "green", adj);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
framenumber ? &xargs.to.g : &xargs.from.g);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (scale_callback),
|
|
|
|
framenumber ? &xargs.to : &xargs.from);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
|
|
|
scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2003-08-06 23:12:58 +08:00
|
|
|
if (!framenumber)
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
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",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&xargs.threshold.g);
|
2004-08-01 00:06:20 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (scale_callback),
|
|
|
|
&xargs.threshold);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
|
2004-08-01 00:06:20 +08:00
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
/* Blue */
|
2004-05-19 07:07:29 +08:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_BLUE,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
2004-05-19 21:15:11 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_table_attach (GTK_TABLE (table), image,
|
2004-05-19 21:15:11 +08:00
|
|
|
0, 1, row, row + 1 + (framenumber ? 0 : 1),
|
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2004-05-19 21:15:11 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 1, row++,
|
2004-08-01 00:06:20 +08:00
|
|
|
_("_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);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton);
|
|
|
|
g_object_set_data (G_OBJECT (colorbutton), "blue", adj);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
framenumber ? &xargs.to.b : &xargs.from.b);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (scale_callback),
|
|
|
|
framenumber ? &xargs.to : &xargs.from);
|
2000-12-19 20:54:34 +08:00
|
|
|
|
|
|
|
scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
if (! framenumber)
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
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",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&xargs.threshold.b);
|
2004-08-01 00:06:20 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (scale_callback),
|
|
|
|
&xargs.threshold);
|
2000-02-26 21:56:55 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
2004-05-19 07:07:29 +08:00
|
|
|
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
|
2004-08-01 00:06:20 +08:00
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2003-08-06 23:12:58 +08:00
|
|
|
if (!framenumber)
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
GtkWidget *button;
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
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);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&lock_threshold);
|
2004-08-01 00:06:20 +08:00
|
|
|
}
|
2000-01-07 06:26:10 +08:00
|
|
|
}
|
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
g_object_unref (group);
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
/* show everything */
|
|
|
|
gtk_widget_show (mainbox);
|
|
|
|
gtk_widget_show (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
update_preview ();
|
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
|
|
|
color_button_callback (GtkWidget *widget,
|
2004-08-01 00:06:20 +08:00
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
GtkObject *red_adj;
|
|
|
|
GtkObject *green_adj;
|
|
|
|
GtkObject *blue_adj;
|
2001-01-12 07:36:59 +08:00
|
|
|
GimpRGB *color;
|
2001-01-11 06:49:45 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
color = (GimpRGB *) data;
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
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");
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
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);
|
2000-01-18 01:02:26 +08:00
|
|
|
|
|
|
|
update_preview ();
|
1998-07-03 02:06:30 +08:00
|
|
|
}
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
|
|
|
scale_callback (GtkAdjustment *adj,
|
2004-08-01 00:06:20 +08:00
|
|
|
gpointer data)
|
1998-07-03 02:06:30 +08:00
|
|
|
{
|
2000-02-26 21:56:55 +08:00
|
|
|
GtkObject *object;
|
2001-01-12 07:36:59 +08:00
|
|
|
GimpRGB *color;
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
color = (GimpRGB *) data;
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
object = g_object_get_data (G_OBJECT (adj), "colorbutton");
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
if (GIMP_IS_COLOR_BUTTON (object))
|
2000-02-26 21:56:55 +08:00
|
|
|
{
|
2001-01-12 07:36:59 +08:00
|
|
|
if (color == &xargs.threshold && lock_threshold == TRUE)
|
2004-08-01 00:06:20 +08:00
|
|
|
gimp_rgb_set (color, adj->value, adj->value, adj->value);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (object), color);
|
2000-02-26 21:56:55 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
update_preview ();
|
2000-02-26 21:56:55 +08:00
|
|
|
}
|
1998-07-03 02:06:30 +08:00
|
|
|
}
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
|
|
|
update_preview (void)
|
1998-07-03 02:06:30 +08:00
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
real_exchange (sel_x1, sel_y1,
|
2004-08-01 00:06:20 +08:00
|
|
|
sel_x1 + prev_width, sel_y1 + prev_height,
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
2000-05-01 05:03:44 +08:00
|
|
|
real_exchange (gint x1,
|
2004-08-01 00:06:20 +08:00
|
|
|
gint y1,
|
|
|
|
gint x2,
|
|
|
|
gint y2,
|
|
|
|
gboolean do_preview)
|
2000-01-18 01:02:26 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn srcPR, destPR;
|
2001-01-12 07:36:59 +08:00
|
|
|
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;
|
2004-08-01 00:06:20 +08:00
|
|
|
guchar *src_row, *dest_row, *dest = NULL;
|
2001-01-12 07:36:59 +08:00
|
|
|
guint x, y, bpp = drw->bpp;
|
|
|
|
guint width, height;
|
|
|
|
GimpRGB min;
|
|
|
|
GimpRGB max;
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
/* fill if necessary */
|
|
|
|
if (x1 == -1 || y1 == -1 || x2 == -1 || y2 == -1)
|
|
|
|
{
|
|
|
|
x1 = sel_x1;
|
|
|
|
y1 = sel_y1;
|
|
|
|
x2 = sel_x2;
|
|
|
|
y2 = sel_y2;
|
|
|
|
}
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
/* check for valid coordinates */
|
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
/* allocate memory */
|
2001-01-12 07:36:59 +08:00
|
|
|
src_row = g_new (guchar, drw->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);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
max = xargs.from;
|
|
|
|
gimp_rgb_add (&max, &xargs.threshold);
|
|
|
|
gimp_rgb_clamp (&max);
|
|
|
|
gimp_rgb_get_uchar (&max, &max_red, &max_green, &max_blue);
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2004-08-01 00:06:20 +08:00
|
|
|
dest_row = g_new (guchar, drw->width * bpp);
|
|
|
|
if (do_preview)
|
|
|
|
dest = g_new (guchar, PREVIEW_SIZE * PREVIEW_SIZE * drw->bpp);
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2001-01-12 07:36:59 +08:00
|
|
|
gimp_pixel_rgn_init (&srcPR, drw, x1, y1, width, height, FALSE, FALSE);
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-02-26 21:56:55 +08:00
|
|
|
if (! do_preview)
|
2001-01-12 07:36:59 +08:00
|
|
|
gimp_pixel_rgn_init (&destPR, drw, x1, y1, width, height, TRUE, TRUE);
|
1999-03-18 04:52:50 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
for (y = y1; y < y2; y++)
|
|
|
|
{
|
2001-01-12 07:36:59 +08:00
|
|
|
gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y, width);
|
|
|
|
for (x = 0; x < width; x++)
|
2004-08-01 00:06:20 +08:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
/* store the dest */
|
2003-11-06 23:27:05 +08:00
|
|
|
if (do_preview)
|
2004-08-01 00:06:20 +08:00
|
|
|
memcpy (dest+(y-y1)*PREVIEW_SIZE*bpp, dest_row, width * bpp);
|
2000-01-18 01:02:26 +08:00
|
|
|
else
|
2004-08-01 00:06:20 +08:00
|
|
|
gimp_pixel_rgn_set_row (&destPR, dest_row, x1, y, width);
|
2001-01-12 07:36:59 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
/* and tell the user what we're doing */
|
2000-02-26 21:56:55 +08:00
|
|
|
if (! do_preview && (y % 10) == 0)
|
2004-08-01 00:06:20 +08:00
|
|
|
gimp_progress_update ((gdouble) y / (gdouble) height);
|
2000-01-18 01:02:26 +08:00
|
|
|
}
|
|
|
|
g_free(src_row);
|
|
|
|
g_free(dest_row);
|
2000-02-26 21:56:55 +08:00
|
|
|
if (! do_preview)
|
2000-01-18 01:02:26 +08:00
|
|
|
{
|
|
|
|
/* update the processed region */
|
|
|
|
gimp_drawable_flush (drw);
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_merge_shadow (drw->drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drw->drawable_id, x1, y1, width, height);
|
2000-01-18 01:02:26 +08:00
|
|
|
}
|
2004-08-01 00:06:20 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
|
|
|
|
0, 0, PREVIEW_SIZE, PREVIEW_SIZE,
|
|
|
|
gimp_drawable_type (drw->drawable_id),
|
|
|
|
dest,
|
|
|
|
PREVIEW_SIZE * bpp);
|
|
|
|
g_free (dest);
|
|
|
|
}
|
2000-01-18 01:02:26 +08:00
|
|
|
}
|