2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2002-09-08 01:27:32 +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
|
2002-09-08 01:27:32 +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
|
2002-09-08 01:27:32 +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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-09-08 01:27:32 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2004-06-21 06:04:10 +08:00
|
|
|
|
2002-12-01 22:53:17 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-04-17 02:51:55 +08:00
|
|
|
#include <gegl.h>
|
2002-09-08 01:27:32 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2002-09-08 01:27:32 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2012-03-25 05:29:53 +08:00
|
|
|
#include "core/gimphistogram.h"
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
#include "gimpcolorbar.h"
|
2007-11-20 17:10:39 +08:00
|
|
|
#include "gimphandlebar.h"
|
2002-09-08 01:27:32 +08:00
|
|
|
#include "gimphistogrambox.h"
|
|
|
|
#include "gimphistogramview.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
/* #define DEBUG_VIEW */
|
2003-12-12 01:24:18 +08:00
|
|
|
|
2004-06-21 06:04:10 +08:00
|
|
|
#define GRADIENT_HEIGHT 12
|
2007-11-20 17:10:39 +08:00
|
|
|
#define CONTROL_HEIGHT 10
|
2002-10-15 09:15:43 +08:00
|
|
|
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2002-10-15 21:36:28 +08:00
|
|
|
static void gimp_histogram_box_low_adj_update (GtkAdjustment *adj,
|
|
|
|
GimpHistogramBox *box);
|
|
|
|
static void gimp_histogram_box_high_adj_update (GtkAdjustment *adj,
|
|
|
|
GimpHistogramBox *box);
|
|
|
|
static void gimp_histogram_box_histogram_range (GimpHistogramView *view,
|
|
|
|
gint start,
|
|
|
|
gint end,
|
|
|
|
GimpHistogramBox *box);
|
2004-02-20 03:56:04 +08:00
|
|
|
static void gimp_histogram_box_channel_notify (GimpHistogramView *view,
|
|
|
|
GParamSpec *pspec,
|
2007-11-20 17:10:39 +08:00
|
|
|
GimpHistogramBox *box);
|
2004-02-20 03:56:04 +08:00
|
|
|
static void gimp_histogram_box_border_notify (GimpHistogramView *view,
|
|
|
|
GParamSpec *pspec,
|
2004-06-21 06:04:10 +08:00
|
|
|
GimpHistogramBox *box);
|
2006-09-20 18:19:49 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
|
2010-10-30 21:44:46 +08:00
|
|
|
G_DEFINE_TYPE (GimpHistogramBox, gimp_histogram_box, GTK_TYPE_BOX)
|
2005-12-20 06:37:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_box_class_init (GimpHistogramBoxClass *klass)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_box_init (GimpHistogramBox *box)
|
|
|
|
{
|
|
|
|
GtkWidget *hbox;
|
2004-06-21 04:51:23 +08:00
|
|
|
GtkWidget *vbox;
|
2007-11-20 17:10:39 +08:00
|
|
|
GtkWidget *vbox2;
|
2002-09-08 01:27:32 +08:00
|
|
|
GtkWidget *frame;
|
2002-10-15 09:15:43 +08:00
|
|
|
GtkWidget *view;
|
2004-02-20 03:56:04 +08:00
|
|
|
GtkWidget *bar;
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
box->n_bins = 256;
|
|
|
|
|
2010-10-30 21:44:46 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
2003-11-02 01:39:09 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (box), 2);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2002-10-15 09:15:43 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 0);
|
2002-09-08 01:27:32 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2011-09-30 17:29:11 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2007-11-20 17:10:39 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
/* The histogram */
|
2003-11-02 01:39:09 +08:00
|
|
|
view = gimp_histogram_view_new (TRUE);
|
2007-11-20 17:10:39 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), view, TRUE, TRUE, 0);
|
2002-10-15 09:15:43 +08:00
|
|
|
gtk_widget_show (view);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (view, "range-changed",
|
2002-09-08 01:27:32 +08:00
|
|
|
G_CALLBACK (gimp_histogram_box_histogram_range),
|
|
|
|
box);
|
2002-10-15 09:15:43 +08:00
|
|
|
|
2003-11-01 10:39:34 +08:00
|
|
|
box->view = GIMP_HISTOGRAM_VIEW (view);
|
2002-10-15 09:15:43 +08:00
|
|
|
|
|
|
|
/* The gradient below the histogram */
|
2011-09-30 17:29:11 +08:00
|
|
|
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2007-11-20 17:10:39 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox2),
|
|
|
|
GIMP_HISTOGRAM_VIEW (view)->border_width);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox2);
|
|
|
|
|
|
|
|
box->color_bar = bar = g_object_new (GIMP_TYPE_COLOR_BAR,
|
|
|
|
"histogram-channel", box->view->channel,
|
|
|
|
NULL);
|
|
|
|
gtk_widget_set_size_request (bar, -1, GRADIENT_HEIGHT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), bar, FALSE, FALSE, 0);
|
2004-02-20 03:56:04 +08:00
|
|
|
gtk_widget_show (bar);
|
2003-01-26 02:58:45 +08:00
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
g_signal_connect (view, "notify::histogram-channel",
|
|
|
|
G_CALLBACK (gimp_histogram_box_channel_notify),
|
2007-11-20 17:10:39 +08:00
|
|
|
box);
|
2004-02-20 03:56:04 +08:00
|
|
|
g_signal_connect (view, "notify::border-width",
|
|
|
|
G_CALLBACK (gimp_histogram_box_border_notify),
|
2007-11-20 17:10:39 +08:00
|
|
|
box);
|
|
|
|
|
|
|
|
box->slider_bar = bar = g_object_new (GIMP_TYPE_HANDLE_BAR, NULL);
|
|
|
|
gtk_widget_set_size_request (bar, -1, CONTROL_HEIGHT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), bar, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (bar);
|
|
|
|
|
2013-06-18 04:13:48 +08:00
|
|
|
gimp_handle_bar_connect_events (GIMP_HANDLE_BAR (box->slider_bar),
|
|
|
|
box->color_bar);
|
2003-10-24 14:22:53 +08:00
|
|
|
|
|
|
|
/* The range selection */
|
2011-09-30 17:29:11 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2003-10-24 14:22:53 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
/* low spinbutton */
|
2010-10-15 20:28:56 +08:00
|
|
|
box->low_adj = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 16.0, 0.0);
|
2014-06-22 04:39:37 +08:00
|
|
|
box->low_spinbutton = gtk_spin_button_new (box->low_adj, 1.0, 0);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (box->low_spinbutton), TRUE);
|
2013-06-12 17:18:07 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), box->low_spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (box->low_spinbutton);
|
2003-10-24 14:22:53 +08:00
|
|
|
|
2014-06-22 04:39:37 +08:00
|
|
|
g_signal_connect (box->low_adj, "value-changed",
|
2003-10-24 14:22:53 +08:00
|
|
|
G_CALLBACK (gimp_histogram_box_low_adj_update),
|
|
|
|
box);
|
|
|
|
|
2010-10-15 20:28:56 +08:00
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (bar), 0, box->low_adj);
|
2007-11-20 17:10:39 +08:00
|
|
|
|
2003-10-24 14:22:53 +08:00
|
|
|
/* high spinbutton */
|
2010-10-15 20:28:56 +08:00
|
|
|
box->high_adj = gtk_adjustment_new (255.0, 0.0, 255.0, 1.0, 16.0, 0.0);
|
2014-06-22 04:39:37 +08:00
|
|
|
box->high_spinbutton = gtk_spin_button_new (box->high_adj, 1.0, 0);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (box->high_spinbutton), TRUE);
|
2013-06-12 17:18:07 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), box->high_spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (box->high_spinbutton);
|
2003-10-24 14:22:53 +08:00
|
|
|
|
2014-06-22 04:39:37 +08:00
|
|
|
g_signal_connect (box->high_adj, "value-changed",
|
2003-10-24 14:22:53 +08:00
|
|
|
G_CALLBACK (gimp_histogram_box_high_adj_update),
|
|
|
|
box);
|
2003-12-12 01:24:18 +08:00
|
|
|
|
2010-10-15 20:28:56 +08:00
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (bar), 2, box->high_adj);
|
2007-11-20 17:10:39 +08:00
|
|
|
|
2003-12-12 01:24:18 +08:00
|
|
|
#ifdef DEBUG_VIEW
|
|
|
|
spinbutton = gimp_prop_spin_button_new (G_OBJECT (box->view), "border-width",
|
|
|
|
1, 5, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
|
|
|
|
spinbutton = gimp_prop_spin_button_new (G_OBJECT (box->view), "subdivisions",
|
|
|
|
1, 5, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
#endif
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_box_low_adj_update (GtkAdjustment *adjustment,
|
|
|
|
GimpHistogramBox *box)
|
|
|
|
{
|
2013-06-12 17:18:07 +08:00
|
|
|
gdouble value = gtk_adjustment_get_value (adjustment);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
gtk_adjustment_set_lower (box->high_adj, value);
|
2003-10-24 14:22:53 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
if (box->n_bins != 256)
|
|
|
|
value *= box->n_bins - 1;
|
|
|
|
|
|
|
|
value = ROUND (value);
|
|
|
|
|
|
|
|
if (box->view->start != value)
|
|
|
|
gimp_histogram_view_set_range (box->view, value, box->view->end);
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_histogram_box_high_adj_update (GtkAdjustment *adjustment,
|
|
|
|
GimpHistogramBox *box)
|
|
|
|
{
|
2013-06-12 17:18:07 +08:00
|
|
|
gdouble value = gtk_adjustment_get_value (adjustment);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
gtk_adjustment_set_upper (box->low_adj, value);
|
2003-10-24 14:22:53 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
if (box->n_bins != 256)
|
|
|
|
value *= box->n_bins - 1;
|
|
|
|
|
|
|
|
value = ROUND (value);
|
|
|
|
|
|
|
|
if (box->view->end != value)
|
|
|
|
gimp_histogram_view_set_range (box->view, box->view->start, value);
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-02-20 03:56:04 +08:00
|
|
|
gimp_histogram_box_histogram_range (GimpHistogramView *view,
|
2002-09-08 01:27:32 +08:00
|
|
|
gint start,
|
|
|
|
gint end,
|
|
|
|
GimpHistogramBox *box)
|
|
|
|
{
|
2013-06-12 17:18:07 +08:00
|
|
|
gdouble s = start;
|
|
|
|
gdouble e = end;
|
|
|
|
|
|
|
|
if (box->n_bins != view->n_bins)
|
|
|
|
{
|
2016-12-31 16:25:46 +08:00
|
|
|
gdouble upper;
|
|
|
|
gdouble page_increment;
|
|
|
|
gdouble step_increment;
|
|
|
|
guint digits;
|
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
box->n_bins = view->n_bins;
|
|
|
|
|
|
|
|
if (box->n_bins == 256)
|
|
|
|
{
|
2016-12-31 16:25:46 +08:00
|
|
|
digits = 0;
|
|
|
|
upper = 255.0;
|
|
|
|
step_increment = 1.0;
|
|
|
|
page_increment = 16.0;
|
2013-06-12 17:18:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-31 16:25:46 +08:00
|
|
|
digits = 3;
|
|
|
|
upper = 1.0;
|
|
|
|
step_increment = 0.01;
|
|
|
|
page_increment = 0.1;
|
2013-06-12 17:18:07 +08:00
|
|
|
}
|
2016-12-31 16:25:46 +08:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (box->high_adj),
|
|
|
|
"upper", upper,
|
|
|
|
"step-increment", step_increment,
|
|
|
|
"page-increment", page_increment,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (box->high_spinbutton), digits);
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (box->low_adj),
|
|
|
|
"step-increment", step_increment,
|
|
|
|
"page-increment", page_increment,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (box->low_spinbutton), digits);
|
2013-06-12 17:18:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (box->n_bins != 256)
|
|
|
|
{
|
|
|
|
s /= box->n_bins - 1;
|
|
|
|
e /= box->n_bins - 1;
|
|
|
|
}
|
2013-06-12 04:36:33 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
gtk_adjustment_set_lower (box->high_adj, s);
|
|
|
|
gtk_adjustment_set_upper (box->low_adj, e);
|
2002-09-08 01:27:32 +08:00
|
|
|
|
2013-06-12 17:18:07 +08:00
|
|
|
gtk_adjustment_set_value (box->low_adj, s);
|
|
|
|
gtk_adjustment_set_value (box->high_adj, e);
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
|
|
|
|
2002-10-15 21:36:28 +08:00
|
|
|
static void
|
2004-02-20 03:56:04 +08:00
|
|
|
gimp_histogram_box_channel_notify (GimpHistogramView *view,
|
|
|
|
GParamSpec *pspec,
|
2007-11-20 17:10:39 +08:00
|
|
|
GimpHistogramBox *box)
|
2002-10-15 21:36:28 +08:00
|
|
|
{
|
2007-11-20 17:10:39 +08:00
|
|
|
gimp_color_bar_set_channel (GIMP_COLOR_BAR (box->color_bar), view->channel);
|
2002-10-15 21:36:28 +08:00
|
|
|
}
|
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
static void
|
|
|
|
gimp_histogram_box_border_notify (GimpHistogramView *view,
|
|
|
|
GParamSpec *pspec,
|
2007-11-20 17:10:39 +08:00
|
|
|
GimpHistogramBox *box)
|
2002-10-15 09:15:43 +08:00
|
|
|
{
|
2008-06-28 23:50:27 +08:00
|
|
|
GtkWidget *vbox = gtk_widget_get_parent (box->color_bar);
|
|
|
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), view->border_width);
|
2002-10-15 09:15:43 +08:00
|
|
|
}
|
|
|
|
|
2007-11-20 17:10:39 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2002-09-08 01:27:32 +08:00
|
|
|
GtkWidget *
|
2004-06-21 06:04:10 +08:00
|
|
|
gimp_histogram_box_new (void)
|
2002-09-08 01:27:32 +08:00
|
|
|
{
|
2004-08-19 08:21:55 +08:00
|
|
|
return g_object_new (GIMP_TYPE_HISTOGRAM_BOX, NULL);
|
2002-09-08 01:27:32 +08:00
|
|
|
}
|
2002-10-15 09:15:43 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_histogram_box_set_channel (GimpHistogramBox *box,
|
|
|
|
GimpHistogramChannel channel)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_HISTOGRAM_BOX (box));
|
|
|
|
|
2003-12-12 01:24:18 +08:00
|
|
|
if (box->view)
|
|
|
|
gimp_histogram_view_set_channel (box->view, channel);
|
2002-10-15 09:15:43 +08:00
|
|
|
}
|