1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "tools-types.h"
|
|
|
|
|
|
|
|
#include "base/gimphistogram.h"
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
|
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpdrawable-histogram.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphistogramview.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "gimpthresholdtool.h"
|
|
|
|
#include "tool_manager.h"
|
|
|
|
#include "tool_options.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
#include "app_procs.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "image_map.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
#define HISTOGRAM_WIDTH 256
|
1997-11-25 06:05:25 +08:00
|
|
|
#define HISTOGRAM_HEIGHT 150
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
#define LOW 0x1
|
|
|
|
#define HIGH 0x2
|
2001-05-25 07:57:08 +08:00
|
|
|
#define HISTOGRAM 0x4
|
1999-11-22 19:14:29 +08:00
|
|
|
#define ALL (LOW | HIGH | HISTOGRAM)
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* local function prototypes */
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void gimp_threshold_tool_class_init (GimpThresholdToolClass *klass);
|
|
|
|
static void gimp_threshold_tool_init (GimpThresholdTool *threshold_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
static void gimp_threshold_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_threshold_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GimpDisplay *gdisp);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
static ThresholdDialog * threshold_dialog_new (void);
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
static void threshold_dialog_hide (void);
|
2000-12-31 12:07:42 +08:00
|
|
|
static void threshold_update (ThresholdDialog *td,
|
|
|
|
gint update);
|
|
|
|
static void threshold_preview (ThresholdDialog *td);
|
|
|
|
static void threshold_reset_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void threshold_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void threshold_cancel_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void threshold_preview_update (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void threshold_low_threshold_adjustment_update (GtkAdjustment *adj,
|
|
|
|
gpointer data);
|
|
|
|
static void threshold_high_threshold_adjustment_update (GtkAdjustment *adj,
|
|
|
|
gpointer data);
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
static void threshold (PixelRegion *,
|
|
|
|
PixelRegion *,
|
|
|
|
gpointer );
|
|
|
|
static void threshold_histogram_range (GimpHistogramView *,
|
|
|
|
gint ,
|
|
|
|
gint ,
|
|
|
|
gpointer );
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the threshold tool options */
|
2001-07-18 04:50:01 +08:00
|
|
|
static GimpToolOptions *threshold_options = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* the threshold tool dialog */
|
|
|
|
static ThresholdDialog *threshold_dialog = NULL;
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static GimpImageMapToolClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* functions */
|
|
|
|
|
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_threshold_tool_register (Gimp *gimp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_THRESHOLD_TOOL,
|
2001-05-25 07:57:08 +08:00
|
|
|
FALSE,
|
|
|
|
"gimp:threshold_tool",
|
|
|
|
_("Threshold"),
|
|
|
|
_("Reduce image to two colors using a threshold"),
|
|
|
|
N_("/Image/Colors/Threshold..."), NULL,
|
|
|
|
NULL, "tools/threshold.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_THRESHOLD);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-05-25 07:57:08 +08:00
|
|
|
gimp_threshold_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpThresholdToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_threshold_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpThresholdTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_threshold_tool_init,
|
2001-05-25 07:57:08 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
|
|
|
|
"GimpThresholdTool",
|
|
|
|
&tool_info, 0);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_threshold_tool_class_init (GimpThresholdToolClass *klass)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
GimpToolClass *tool_class;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
tool_class->initialize = gimp_threshold_tool_initialize;
|
|
|
|
tool_class->control = gimp_threshold_tool_control;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_threshold_tool_init (GimpThresholdTool *bc_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (bc_tool);
|
|
|
|
|
|
|
|
if (! threshold_options)
|
|
|
|
{
|
|
|
|
threshold_options = tool_options_new ();
|
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_THRESHOLD_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) threshold_options);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_threshold_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
|
|
|
if (! gdisp)
|
|
|
|
{
|
|
|
|
threshold_dialog_hide ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp_drawable_is_indexed (gimp_image_active_drawable (gdisp->gimage)))
|
|
|
|
{
|
|
|
|
g_message (_("Threshold does not operate on indexed drawables."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The threshold dialog */
|
|
|
|
if (!threshold_dialog)
|
|
|
|
threshold_dialog = threshold_dialog_new ();
|
|
|
|
else
|
|
|
|
if (!GTK_WIDGET_VISIBLE (threshold_dialog->shell))
|
|
|
|
gtk_widget_show (threshold_dialog->shell);
|
|
|
|
|
|
|
|
threshold_dialog->low_threshold = 127;
|
|
|
|
threshold_dialog->high_threshold = 255;
|
|
|
|
|
|
|
|
threshold_dialog->drawable = gimp_image_active_drawable (gdisp->gimage);
|
|
|
|
threshold_dialog->color = gimp_drawable_is_rgb (threshold_dialog->drawable);
|
|
|
|
threshold_dialog->image_map =
|
|
|
|
image_map_create (gdisp, threshold_dialog->drawable);
|
|
|
|
|
|
|
|
gimp_drawable_calculate_histogram (threshold_dialog->drawable,
|
|
|
|
threshold_dialog->hist);
|
|
|
|
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_handlers_block_by_func (G_OBJECT (threshold_dialog->histogram),
|
|
|
|
threshold_histogram_range,
|
|
|
|
threshold_dialog);
|
2001-10-17 19:33:43 +08:00
|
|
|
gimp_histogram_view_update (threshold_dialog->histogram,
|
|
|
|
threshold_dialog->hist);
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_handlers_unblock_by_func (G_OBJECT (threshold_dialog->histogram),
|
|
|
|
threshold_histogram_range,
|
|
|
|
threshold_dialog);
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
threshold_update (threshold_dialog, ALL);
|
|
|
|
|
|
|
|
if (threshold_dialog->preview)
|
|
|
|
threshold_preview (threshold_dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_threshold_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
|
|
|
threshold_dialog_hide ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GIMP_TOOL_CLASS (parent_class)->control)
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
|
|
|
}
|
|
|
|
|
1999-06-23 23:24:46 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* threshold machinery */
|
|
|
|
|
moved a bunch of PDB stuff here
* app/color_cmds.c: moved a bunch of PDB stuff here
* app/color_balance.[ch]: removed PDB proc, exported TransferMode
enum, ColorBalanceDialog, color_balance_create_lookup_tables, and
color_balance
* app/curves.[ch]: removed PDB procs, exported SMOOTH and GFREE
#defines, CurvesDialog, curves_lut_func and curves_calculate_curve
* app/desaturate.[ch]: removed PDB proc, exported desaturate
* app/equalize.[ch]: removed PDB proc, exported equalize
* app/histogram_tool.[ch]: removed PDB proc, exported HISTOGRAM_WIDTH
and HISTOGRAM_HEIGHT #defines, HistogramToolDialog,
histogram_tool_histogram_range
* app/hue_saturation.[ch]: removed PDB proc, exported HueRange enum,
HueSaturationDialog, hue_saturation_calculate_transfers,
hue_saturation
* app/invert.[ch]: remove PDB proc, export invert
* app/threshold.[ch]: remove PDB proc, export ThresholdDialog and
threshold_2
* internal_procs.c: changes for pdbgen
* app/gimprc.c: removed leftover declaration
* app/image_map.h: add #include "gimpdrawableF.h"
* app/lut_funcs.h: add ALPHA_LUT to ChannelLutType
-Yosh
1999-04-21 13:39:57 +08:00
|
|
|
void
|
2000-12-31 12:07:42 +08:00
|
|
|
threshold_2 (gpointer data,
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR)
|
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
/* this function just re-orders the arguments so we can use
|
|
|
|
* pixel_regions_process_paralell
|
|
|
|
*/
|
|
|
|
threshold (srcPR, destPR, data);
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
|
|
|
threshold (PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR,
|
1999-11-22 19:14:29 +08:00
|
|
|
void *data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
|
|
|
unsigned char *src, *s;
|
|
|
|
unsigned char *dest, *d;
|
|
|
|
int has_alpha, alpha;
|
|
|
|
int w, h, b;
|
|
|
|
int value;
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
td = (ThresholdDialog *) data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
h = srcPR->h;
|
|
|
|
src = srcPR->data;
|
|
|
|
dest = destPR->data;
|
|
|
|
has_alpha = (srcPR->bytes == 2 || srcPR->bytes == 4);
|
|
|
|
alpha = has_alpha ? srcPR->bytes - 1 : srcPR->bytes;
|
|
|
|
|
|
|
|
while (h--)
|
|
|
|
{
|
|
|
|
w = srcPR->w;
|
|
|
|
s = src;
|
|
|
|
d = dest;
|
|
|
|
while (w--)
|
|
|
|
{
|
|
|
|
if (td->color)
|
|
|
|
{
|
|
|
|
value = MAX (s[RED_PIX], s[GREEN_PIX]);
|
|
|
|
value = MAX (value, s[BLUE_PIX]);
|
|
|
|
|
|
|
|
value = (value >= td->low_threshold && value <= td->high_threshold ) ? 255 : 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = (s[GRAY_PIX] >= td->low_threshold && s[GRAY_PIX] <= td->high_threshold) ? 255 : 0;
|
|
|
|
|
|
|
|
for (b = 0; b < alpha; b++)
|
|
|
|
d[b] = value;
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
d[alpha] = s[alpha];
|
|
|
|
|
|
|
|
s += srcPR->bytes;
|
|
|
|
d += destPR->bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
src += srcPR->rowstride;
|
|
|
|
dest += destPR->rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-23 23:24:46 +08:00
|
|
|
/**********************/
|
|
|
|
/* Threshold dialog */
|
|
|
|
/**********************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static ThresholdDialog *
|
1999-11-22 19:14:29 +08:00
|
|
|
threshold_dialog_new (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
1999-11-22 19:14:29 +08:00
|
|
|
GtkWidget *spinbutton;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *toggle;
|
1999-11-22 19:14:29 +08:00
|
|
|
GtkObject *data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
td = g_new (ThresholdDialog, 1);
|
|
|
|
td->preview = TRUE;
|
|
|
|
td->low_threshold = 127;
|
1997-11-25 06:05:25 +08:00
|
|
|
td->high_threshold = 255;
|
1999-09-28 01:58:10 +08:00
|
|
|
td->hist = gimp_histogram_new ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* The shell and main vbox */
|
1999-09-28 01:58:10 +08:00
|
|
|
td->shell =
|
|
|
|
gimp_dialog_new (_("Threshold"), "threshold",
|
2001-05-25 07:57:08 +08:00
|
|
|
tool_manager_help_func, NULL,
|
1999-09-28 01:58:10 +08:00
|
|
|
GTK_WIN_POS_NONE,
|
|
|
|
FALSE, TRUE, FALSE,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-04 03:43:19 +08:00
|
|
|
GTK_STOCK_OK, threshold_ok_callback,
|
2000-01-07 00:40:17 +08:00
|
|
|
td, NULL, NULL, TRUE, FALSE,
|
1999-12-02 21:00:18 +08:00
|
|
|
_("Reset"), threshold_reset_callback,
|
2000-01-07 00:40:17 +08:00
|
|
|
td, NULL, NULL, TRUE, FALSE,
|
2001-08-04 03:43:19 +08:00
|
|
|
GTK_STOCK_CANCEL, threshold_cancel_callback,
|
2000-01-07 00:40:17 +08:00
|
|
|
td, NULL, NULL, FALSE, TRUE,
|
1999-09-28 01:58:10 +08:00
|
|
|
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
|
1999-09-28 01:58:10 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (td->shell)->vbox), vbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Horizontal box for threshold text widget */
|
1999-11-22 19:14:29 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
label = gtk_label_new (_("Threshold Range:"));
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
/* low threshold spinbutton */
|
|
|
|
data = gtk_adjustment_new (td->low_threshold, 0.0, 255.0, 1.0, 10.0, 0.0);
|
|
|
|
td->low_threshold_data = GTK_ADJUSTMENT (data);
|
|
|
|
|
|
|
|
spinbutton = gtk_spin_button_new (td->low_threshold_data, 1.0, 0);
|
|
|
|
gtk_widget_set_usize (spinbutton, 75, -1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_connect (G_OBJECT (td->low_threshold_data), "value_changed",
|
2001-08-15 00:33:28 +08:00
|
|
|
G_CALLBACK (threshold_low_threshold_adjustment_update),
|
2001-08-01 10:57:58 +08:00
|
|
|
td);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
|
|
|
/* high threshold spinbutton */
|
|
|
|
data = gtk_adjustment_new (td->high_threshold, 0.0, 255.0, 1.0, 10.0, 0.0);
|
|
|
|
td->high_threshold_data = GTK_ADJUSTMENT (data);
|
|
|
|
|
|
|
|
spinbutton = gtk_spin_button_new (td->high_threshold_data, 1.0, 0);
|
|
|
|
gtk_widget_set_usize (spinbutton, 75, -1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_connect (G_OBJECT (td->high_threshold_data), "value_changed",
|
2001-08-15 00:33:28 +08:00
|
|
|
G_CALLBACK (threshold_high_threshold_adjustment_update),
|
2001-08-01 10:57:58 +08:00
|
|
|
td);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
/* The threshold histogram */
|
1999-11-22 19:14:29 +08:00
|
|
|
hbox = gtk_hbox_new (TRUE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (hbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, FALSE, 0);
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (frame);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
td->histogram = gimp_histogram_view_new (HISTOGRAM_WIDTH, HISTOGRAM_HEIGHT);
|
1999-11-22 19:14:29 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (td->histogram));
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (GTK_WIDGET (td->histogram));
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_connect (G_OBJECT (td->histogram), "range_changed",
|
2001-08-15 00:33:28 +08:00
|
|
|
G_CALLBACK (threshold_histogram_range),
|
2001-08-01 10:57:58 +08:00
|
|
|
td);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Horizontal box for preview */
|
1999-11-22 19:14:29 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (hbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* The preview toggle */
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
toggle = gtk_check_button_new_with_label (_("Preview"));
|
1999-01-16 01:35:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), td->preview);
|
1999-11-22 19:14:29 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
|
2001-08-15 00:33:28 +08:00
|
|
|
gtk_widget_show (toggle);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_connect (G_OBJECT (toggle), "toggled",
|
2001-08-15 00:33:28 +08:00
|
|
|
G_CALLBACK (threshold_preview_update),
|
2001-08-01 10:57:58 +08:00
|
|
|
td);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_widget_show (td->shell);
|
|
|
|
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
static void
|
|
|
|
threshold_dialog_hide (void)
|
|
|
|
{
|
|
|
|
if (threshold_dialog)
|
|
|
|
threshold_cancel_callback (NULL, (gpointer) threshold_dialog);
|
|
|
|
}
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
static void
|
|
|
|
threshold_update (ThresholdDialog *td,
|
|
|
|
gint update)
|
|
|
|
{
|
|
|
|
if (update & LOW)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (td->low_threshold_data, td->low_threshold);
|
|
|
|
}
|
|
|
|
if (update & HIGH)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (td->high_threshold_data, td->high_threshold);
|
|
|
|
}
|
|
|
|
if (update & HISTOGRAM)
|
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
gimp_histogram_view_range (td->histogram,
|
|
|
|
td->low_threshold,
|
|
|
|
td->high_threshold);
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
|
|
|
threshold_preview (ThresholdDialog *td)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpTool *active_tool;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!td->image_map)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
|
|
|
g_warning ("threshold_preview(): No image map");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
active_tool = tool_manager_get_active (the_gimp);
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
active_tool->preserve = TRUE;
|
|
|
|
image_map_apply (td->image_map, threshold, td);
|
|
|
|
active_tool->preserve = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
threshold_reset_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
|
|
|
|
|
|
|
td = (ThresholdDialog *) data;
|
|
|
|
|
|
|
|
td->low_threshold = 127.0;
|
|
|
|
td->high_threshold = 255.0;
|
|
|
|
|
|
|
|
threshold_update (td, ALL);
|
|
|
|
|
|
|
|
if (td->preview)
|
|
|
|
threshold_preview (td);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
threshold_ok_callback (GtkWidget *widget,
|
1999-11-22 19:14:29 +08:00
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpTool *active_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
td = (ThresholdDialog *) data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
gtk_widget_hide (td->shell);
|
2001-07-08 01:36:00 +08:00
|
|
|
|
|
|
|
active_tool = tool_manager_get_active (the_gimp);
|
|
|
|
|
1998-04-02 12:51:44 +08:00
|
|
|
active_tool->preserve = TRUE;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!td->preview)
|
2001-10-17 19:33:43 +08:00
|
|
|
image_map_apply (td->image_map, threshold, (gpointer) td);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (td->image_map)
|
|
|
|
image_map_commit (td->image_map);
|
|
|
|
|
1998-04-02 12:51:44 +08:00
|
|
|
active_tool->preserve = FALSE;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
td->image_map = NULL;
|
1999-06-26 19:16:47 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
active_tool->gdisp = NULL;
|
1999-06-26 19:16:47 +08:00
|
|
|
active_tool->drawable = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
threshold_cancel_callback (GtkWidget *widget,
|
1999-11-22 19:14:29 +08:00
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpTool *active_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
td = (ThresholdDialog *) data;
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
gtk_widget_hide (td->shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
active_tool = tool_manager_get_active (the_gimp);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (td->image_map)
|
|
|
|
{
|
1998-04-02 12:51:44 +08:00
|
|
|
active_tool->preserve = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
image_map_abort (td->image_map);
|
1998-04-02 12:51:44 +08:00
|
|
|
active_tool->preserve = FALSE;
|
1999-06-23 23:24:46 +08:00
|
|
|
|
|
|
|
td->image_map = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplays_flush ();
|
|
|
|
}
|
1999-06-26 19:16:47 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
active_tool->gdisp = NULL;
|
1999-06-26 19:16:47 +08:00
|
|
|
active_tool->drawable = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-11-22 19:14:29 +08:00
|
|
|
threshold_preview_update (GtkWidget *widget,
|
1997-11-25 06:05:25 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpTool *active_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
td = (ThresholdDialog *) data;
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
if (GTK_TOGGLE_BUTTON (widget)->active)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
td->preview = TRUE;
|
|
|
|
threshold_preview (td);
|
|
|
|
}
|
|
|
|
else
|
2000-06-13 17:13:16 +08:00
|
|
|
{
|
|
|
|
td->preview = FALSE;
|
|
|
|
if (td->image_map)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
active_tool = tool_manager_get_active (the_gimp);
|
|
|
|
|
2000-06-13 17:13:16 +08:00
|
|
|
active_tool->preserve = TRUE;
|
|
|
|
image_map_clear (td->image_map);
|
|
|
|
active_tool->preserve = FALSE;
|
|
|
|
gdisplays_flush ();
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-11-22 19:14:29 +08:00
|
|
|
threshold_low_threshold_adjustment_update (GtkAdjustment *adjustment,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
|
|
|
|
|
|
|
td = (ThresholdDialog *) data;
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
if (td->low_threshold != adjustment->value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
td->low_threshold = adjustment->value;
|
|
|
|
|
|
|
|
threshold_update (td, HISTOGRAM);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (td->preview)
|
|
|
|
threshold_preview (td);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-11-22 19:14:29 +08:00
|
|
|
threshold_high_threshold_adjustment_update (GtkAdjustment *adjustment,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
|
|
|
|
|
|
|
td = (ThresholdDialog *) data;
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
if (td->high_threshold != adjustment->value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
td->high_threshold = adjustment->value;
|
|
|
|
|
|
|
|
threshold_update (td, HISTOGRAM);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (td->preview)
|
|
|
|
threshold_preview (td);
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:14:29 +08:00
|
|
|
|
|
|
|
static void
|
2001-10-17 19:33:43 +08:00
|
|
|
threshold_histogram_range (GimpHistogramView *widget,
|
|
|
|
gint start,
|
|
|
|
gint end,
|
|
|
|
gpointer data)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
|
|
|
ThresholdDialog *td;
|
|
|
|
|
|
|
|
td = (ThresholdDialog *) data;
|
|
|
|
|
|
|
|
td->low_threshold = start;
|
|
|
|
td->high_threshold = end;
|
|
|
|
|
|
|
|
threshold_update (td, LOW | HIGH);
|
|
|
|
|
|
|
|
if (td->preview)
|
|
|
|
threshold_preview (td);
|
|
|
|
}
|