2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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"
|
|
|
|
|
2007-12-31 01:54:51 +08:00
|
|
|
#include <gegl.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2008-01-28 01:39:01 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpdrawable-histogram.h"
|
2012-03-25 05:29:53 +08:00
|
|
|
#include "core/gimphistogram.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2002-09-08 01:27:32 +08:00
|
|
|
#include "widgets/gimphistogrambox.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "widgets/gimphistogramview.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2003-10-24 16:12:21 +08:00
|
|
|
#include "gimphistogramoptions.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "gimpthresholdtool.h"
|
2016-05-14 04:00:25 +08:00
|
|
|
#include "gimptooloptions-gui.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
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
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* local function prototypes */
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2008-01-04 03:23:35 +08:00
|
|
|
static void gimp_threshold_tool_finalize (GObject *object);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-01-04 03:23:35 +08:00
|
|
|
static gboolean gimp_threshold_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2016-05-10 06:08:36 +08:00
|
|
|
static gchar * gimp_threshold_tool_get_operation (GimpFilterTool *filter_tool,
|
2017-07-10 00:58:00 +08:00
|
|
|
gchar **description);
|
2016-05-10 06:08:36 +08:00
|
|
|
static void gimp_threshold_tool_dialog (GimpFilterTool *filter_tool);
|
2017-07-03 06:15:09 +08:00
|
|
|
static void gimp_threshold_tool_config_notify (GimpFilterTool *filter_tool,
|
|
|
|
GimpConfig *config,
|
|
|
|
const GParamSpec *pspec);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
static gboolean gimp_threshold_tool_channel_sensitive
|
|
|
|
(gint value,
|
|
|
|
gpointer data);
|
2008-01-04 03:23:35 +08:00
|
|
|
static void gimp_threshold_tool_histogram_range (GimpHistogramView *view,
|
|
|
|
gint start,
|
|
|
|
gint end,
|
|
|
|
GimpThresholdTool *t_tool);
|
|
|
|
static void gimp_threshold_tool_auto_clicked (GtkWidget *button,
|
|
|
|
GimpThresholdTool *t_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
G_DEFINE_TYPE (GimpThresholdTool, gimp_threshold_tool,
|
2016-05-10 06:08:36 +08:00
|
|
|
GIMP_TYPE_FILTER_TOOL)
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_threshold_tool_parent_class
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_threshold_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_THRESHOLD_TOOL,
|
2003-10-24 16:12:21 +08:00
|
|
|
GIMP_TYPE_HISTOGRAM_OPTIONS,
|
2016-05-14 04:00:25 +08:00
|
|
|
NULL,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-threshold-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Threshold"),
|
2018-01-14 22:42:29 +08:00
|
|
|
_("Reduce image to two colors using a threshold"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Threshold..."), NULL,
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_THRESHOLD,
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_TOOL_THRESHOLD,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_threshold_tool_class_init (GimpThresholdToolClass *klass)
|
|
|
|
{
|
2016-05-10 06:08:36 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2017-03-25 18:32:17 +08:00
|
|
|
object_class->finalize = gimp_threshold_tool_finalize;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2017-03-25 18:32:17 +08:00
|
|
|
tool_class->initialize = gimp_threshold_tool_initialize;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2017-03-25 18:32:17 +08:00
|
|
|
filter_tool_class->get_operation = gimp_threshold_tool_get_operation;
|
|
|
|
filter_tool_class->dialog = gimp_threshold_tool_dialog;
|
2017-07-03 06:15:09 +08:00
|
|
|
filter_tool_class->config_notify = gimp_threshold_tool_config_notify;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_threshold_tool_init (GimpThresholdTool *t_tool)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2016-12-27 00:32:17 +08:00
|
|
|
t_tool->histogram = gimp_histogram_new (FALSE);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_threshold_tool_finalize (GObject *object)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2003-10-24 16:12:21 +08:00
|
|
|
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (object);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2008-02-05 05:41:57 +08:00
|
|
|
if (t_tool->histogram)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2013-06-12 03:23:32 +08:00
|
|
|
g_object_unref (t_tool->histogram);
|
2008-02-05 05:41:57 +08:00
|
|
|
t_tool->histogram = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2004-01-22 00:07:48 +08:00
|
|
|
static gboolean
|
2006-09-27 04:55:40 +08:00
|
|
|
gimp_threshold_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2007-07-19 22:59:51 +08:00
|
|
|
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (tool);
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2003-02-04 07:54:19 +08:00
|
|
|
|
2009-08-20 23:05:23 +08:00
|
|
|
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2017-08-05 23:15:31 +08:00
|
|
|
gimp_drawable_calculate_histogram (drawable, t_tool->histogram, FALSE);
|
2003-11-01 10:39:34 +08:00
|
|
|
gimp_histogram_view_set_histogram (t_tool->histogram_box->view,
|
2008-02-05 05:41:57 +08:00
|
|
|
t_tool->histogram);
|
1999-06-23 23:24:46 +08:00
|
|
|
|
2004-01-22 00:07:48 +08:00
|
|
|
return TRUE;
|
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
|
|
|
}
|
|
|
|
|
2016-01-23 04:22:36 +08:00
|
|
|
static gchar *
|
2016-05-10 06:08:36 +08:00
|
|
|
gimp_threshold_tool_get_operation (GimpFilterTool *filter_tool,
|
2017-07-10 00:58:00 +08:00
|
|
|
gchar **description)
|
2008-01-04 03:23:35 +08:00
|
|
|
{
|
2017-07-10 00:58:00 +08:00
|
|
|
*description = g_strdup (_("Apply Threshold"));
|
2008-01-25 19:42:07 +08:00
|
|
|
|
2016-01-23 04:22:36 +08:00
|
|
|
return g_strdup ("gimp:threshold");
|
2008-01-04 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
|
1999-06-23 23:24:46 +08:00
|
|
|
/**********************/
|
|
|
|
/* Threshold dialog */
|
|
|
|
/**********************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void
|
2016-05-10 06:08:36 +08:00
|
|
|
gimp_threshold_tool_dialog (GimpFilterTool *filter_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-11-02 05:41:56 +08:00
|
|
|
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (filter_tool);
|
|
|
|
GimpToolOptions *tool_options = GIMP_TOOL_GET_OPTIONS (filter_tool);
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *main_frame;
|
|
|
|
GtkWidget *frame_vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *hbox2;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *button;
|
|
|
|
GimpHistogramChannel channel;
|
|
|
|
gdouble low;
|
|
|
|
gdouble high;
|
|
|
|
gint n_bins;
|
2016-01-23 04:22:36 +08:00
|
|
|
|
2016-05-10 06:08:36 +08:00
|
|
|
main_vbox = gimp_filter_tool_dialog_get_vbox (filter_tool);
|
2004-03-05 09:31:33 +08:00
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
main_frame = gimp_frame_new (NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), main_frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (main_frame);
|
|
|
|
|
2011-09-30 17:29:11 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2016-11-02 05:41:56 +08:00
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (main_frame), hbox);
|
2004-03-05 09:31:33 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("Cha_nnel:"));
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
|
|
|
|
-1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
t_tool->channel_menu = gimp_prop_enum_combo_box_new (filter_tool->config,
|
|
|
|
"channel", -1, -1);
|
|
|
|
gimp_enum_combo_box_set_icon_prefix (GIMP_ENUM_COMBO_BOX (t_tool->channel_menu),
|
|
|
|
"gimp-channel");
|
2017-01-29 21:07:06 +08:00
|
|
|
|
|
|
|
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (t_tool->channel_menu),
|
|
|
|
gimp_threshold_tool_channel_sensitive,
|
|
|
|
filter_tool, NULL);
|
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), t_tool->channel_menu, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (t_tool->channel_menu);
|
|
|
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), t_tool->channel_menu);
|
|
|
|
|
|
|
|
hbox2 = gimp_prop_enum_icon_box_new (G_OBJECT (tool_options),
|
|
|
|
"histogram-scale", "gimp-histogram",
|
|
|
|
0, 0);
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), hbox2, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox2);
|
|
|
|
|
|
|
|
frame_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (main_frame), frame_vbox);
|
|
|
|
gtk_widget_show (frame_vbox);
|
2004-03-05 09:31:33 +08:00
|
|
|
|
2004-06-21 06:04:10 +08:00
|
|
|
box = gimp_histogram_box_new ();
|
2016-11-02 05:41:56 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (frame_vbox), box, TRUE, TRUE, 0);
|
2002-10-15 09:15:43 +08:00
|
|
|
gtk_widget_show (box);
|
2002-08-29 03:47:07 +08:00
|
|
|
|
2002-10-15 09:15:43 +08:00
|
|
|
t_tool->histogram_box = GIMP_HISTOGRAM_BOX (box);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2016-05-10 06:08:36 +08:00
|
|
|
g_object_get (filter_tool->config,
|
2016-11-02 05:41:56 +08:00
|
|
|
"channel", &channel,
|
|
|
|
"low", &low,
|
|
|
|
"high", &high,
|
2016-01-23 04:22:36 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-12 22:35:15 +08:00
|
|
|
n_bins = gimp_histogram_n_bins (t_tool->histogram);
|
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
gimp_histogram_view_set_channel (t_tool->histogram_box->view, channel);
|
2008-02-05 05:41:57 +08:00
|
|
|
gimp_histogram_view_set_range (t_tool->histogram_box->view,
|
2016-01-23 04:22:36 +08:00
|
|
|
low * (n_bins - 0.0001),
|
|
|
|
high * (n_bins - 0.0001));
|
2008-02-05 05:41:57 +08:00
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (t_tool->histogram_box->view, "range-changed",
|
2002-09-08 01:27:32 +08:00
|
|
|
G_CALLBACK (gimp_threshold_tool_histogram_range),
|
2002-08-26 19:35:56 +08:00
|
|
|
t_tool);
|
2003-10-24 16:12:21 +08:00
|
|
|
|
2016-05-14 04:00:25 +08:00
|
|
|
g_object_bind_property (G_OBJECT (tool_options), "histogram-scale",
|
|
|
|
G_OBJECT (t_tool->histogram_box->view), "histogram-scale",
|
|
|
|
G_BINDING_SYNC_CREATE |
|
|
|
|
G_BINDING_BIDIRECTIONAL);
|
2006-04-26 02:02:30 +08:00
|
|
|
|
2011-09-30 17:29:11 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2016-11-02 05:41:56 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (frame_vbox), hbox, FALSE, FALSE, 0);
|
2006-04-26 02:02:30 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_mnemonic (_("_Auto"));
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
|
|
|
gimp_help_set_help_data (button, _("Automatically adjust to optimal "
|
|
|
|
"binarization threshold"), NULL);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (gimp_threshold_tool_auto_clicked),
|
|
|
|
t_tool);
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2017-07-03 06:15:09 +08:00
|
|
|
gimp_threshold_tool_config_notify (GimpFilterTool *filter_tool,
|
|
|
|
GimpConfig *config,
|
|
|
|
const GParamSpec *pspec)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2017-07-03 06:15:09 +08:00
|
|
|
GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (filter_tool);
|
|
|
|
|
|
|
|
GIMP_FILTER_TOOL_CLASS (parent_class)->config_notify (filter_tool,
|
|
|
|
config, pspec);
|
|
|
|
|
2008-02-05 05:41:57 +08:00
|
|
|
if (! t_tool->histogram_box)
|
|
|
|
return;
|
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
if (! strcmp (pspec->name, "channel"))
|
|
|
|
{
|
|
|
|
GimpHistogramChannel channel;
|
2016-01-23 04:22:36 +08:00
|
|
|
|
2017-07-03 06:15:09 +08:00
|
|
|
g_object_get (config,
|
2016-11-02 05:41:56 +08:00
|
|
|
"channel", &channel,
|
|
|
|
NULL);
|
2013-06-12 22:35:15 +08:00
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
gimp_histogram_view_set_channel (t_tool->histogram_box->view,
|
|
|
|
channel);
|
|
|
|
}
|
|
|
|
else if (! strcmp (pspec->name, "low") ||
|
|
|
|
! strcmp (pspec->name, "high"))
|
|
|
|
{
|
|
|
|
gdouble low;
|
|
|
|
gdouble high;
|
|
|
|
gint n_bins;
|
|
|
|
|
2017-07-03 06:15:09 +08:00
|
|
|
g_object_get (config,
|
2016-11-02 05:41:56 +08:00
|
|
|
"low", &low,
|
|
|
|
"high", &high,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
n_bins = gimp_histogram_n_bins (t_tool->histogram);
|
|
|
|
|
|
|
|
gimp_histogram_view_set_range (t_tool->histogram_box->view,
|
|
|
|
low * (n_bins - 0.0001),
|
|
|
|
high * (n_bins - 0.0001));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_threshold_tool_channel_sensitive (gint value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2017-07-11 05:28:49 +08:00
|
|
|
GimpDrawable *drawable = GIMP_TOOL (data)->drawable;
|
2016-11-02 05:41:56 +08:00
|
|
|
GimpHistogramChannel channel = value;
|
|
|
|
|
2017-01-29 21:07:06 +08:00
|
|
|
if (!drawable)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-02 05:41:56 +08:00
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
|
|
|
return gimp_drawable_is_rgb (drawable);
|
|
|
|
|
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
|
|
|
return gimp_drawable_has_alpha (drawable);
|
|
|
|
|
|
|
|
case GIMP_HISTOGRAM_RGB:
|
|
|
|
return gimp_drawable_is_rgb (drawable);
|
|
|
|
|
|
|
|
case GIMP_HISTOGRAM_LUMINANCE:
|
|
|
|
return gimp_drawable_is_rgb (drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-09-08 01:27:32 +08:00
|
|
|
gimp_threshold_tool_histogram_range (GimpHistogramView *widget,
|
|
|
|
gint start,
|
|
|
|
gint end,
|
|
|
|
GimpThresholdTool *t_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-05-10 06:08:36 +08:00
|
|
|
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (t_tool);
|
|
|
|
gint n_bins = gimp_histogram_n_bins (t_tool->histogram);
|
|
|
|
gdouble low = (gdouble) start / (n_bins - 1);
|
|
|
|
gdouble high = (gdouble) end / (n_bins - 1);
|
|
|
|
gdouble config_low;
|
|
|
|
gdouble config_high;
|
|
|
|
|
|
|
|
g_object_get (filter_tool->config,
|
2016-01-23 04:22:36 +08:00
|
|
|
"low", &config_low,
|
|
|
|
"high", &config_high,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (low != config_low ||
|
|
|
|
high != config_high)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-05-10 06:08:36 +08:00
|
|
|
g_object_set (filter_tool->config,
|
2008-01-25 19:42:07 +08:00
|
|
|
"low", low,
|
|
|
|
"high", high,
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
2006-04-26 02:02:30 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_threshold_tool_auto_clicked (GtkWidget *button,
|
|
|
|
GimpThresholdTool *t_tool)
|
|
|
|
{
|
2016-11-02 05:41:56 +08:00
|
|
|
GimpHistogramChannel channel;
|
|
|
|
gint n_bins;
|
|
|
|
gdouble low;
|
|
|
|
|
|
|
|
g_object_get (GIMP_FILTER_TOOL (t_tool)->config,
|
|
|
|
"channel", &channel,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
n_bins = gimp_histogram_n_bins (t_tool->histogram);
|
2008-02-04 07:50:55 +08:00
|
|
|
|
2008-02-05 05:41:57 +08:00
|
|
|
low = gimp_histogram_get_threshold (t_tool->histogram,
|
2016-11-02 05:41:56 +08:00
|
|
|
channel,
|
2013-06-12 22:35:15 +08:00
|
|
|
0, n_bins - 1);
|
2006-04-26 02:02:30 +08:00
|
|
|
|
|
|
|
gimp_histogram_view_set_range (t_tool->histogram_box->view,
|
2013-06-12 22:35:15 +08:00
|
|
|
low, n_bins - 1);
|
2006-04-26 02:02:30 +08:00
|
|
|
}
|