[gimp] app: GimpHistogramBox: map the range to 0..1 for != 8 bit histograms
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: GimpHistogramBox: map the range to 0..1 for != 8 bit histograms
- Date: Wed, 12 Jun 2013 09:19:44 +0000 (UTC)
commit 945e57af1d6bbde502aceb1b34b0ab6b98f67272
Author: Michael Natterer <mitch gimp org>
Date: Wed Jun 12 11:18:07 2013 +0200
app: GimpHistogramBox: map the range to 0..1 for != 8 bit histograms
app/widgets/gimphistogrambox.c | 88 +++++++++++++++++++++++++++-------------
app/widgets/gimphistogrambox.h | 5 ++
2 files changed, 65 insertions(+), 28 deletions(-)
---
diff --git a/app/widgets/gimphistogrambox.c b/app/widgets/gimphistogrambox.c
index 5519560..1346e88 100644
--- a/app/widgets/gimphistogrambox.c
+++ b/app/widgets/gimphistogrambox.c
@@ -75,12 +75,13 @@ gimp_histogram_box_init (GimpHistogramBox *box)
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *vbox2;
- GtkWidget *spinbutton;
GtkObject *adjustment;
GtkWidget *frame;
GtkWidget *view;
GtkWidget *bar;
+ box->n_bins = 256;
+
gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
GTK_ORIENTATION_VERTICAL);
@@ -150,12 +151,12 @@ gimp_histogram_box_init (GimpHistogramBox *box)
gtk_widget_show (hbox);
/* low spinbutton */
- spinbutton = gimp_spin_button_new (&adjustment,
- 0.0, 0.0, 255.0, 1.0, 16.0, 0.0,
- 1.0, 0);
+ box->low_spinbutton = gimp_spin_button_new (&adjustment,
+ 0.0, 0.0, 255.0, 1.0, 16.0, 0.0,
+ 1.0, 0);
box->low_adj = GTK_ADJUSTMENT (adjustment);
- gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
- gtk_widget_show (spinbutton);
+ gtk_box_pack_start (GTK_BOX (hbox), box->low_spinbutton, FALSE, FALSE, 0);
+ gtk_widget_show (box->low_spinbutton);
g_signal_connect (adjustment, "value-changed",
G_CALLBACK (gimp_histogram_box_low_adj_update),
@@ -165,12 +166,12 @@ gimp_histogram_box_init (GimpHistogramBox *box)
GTK_ADJUSTMENT (adjustment));
/* high spinbutton */
- spinbutton = gimp_spin_button_new (&adjustment,
- 255.0, 0.0, 255.0, 1.0, 16.0, 0.0,
- 1.0, 0);
+ box->high_spinbutton = gimp_spin_button_new (&adjustment,
+ 255.0, 0.0, 255.0, 1.0, 16.0, 0.0,
+ 1.0, 0);
box->high_adj = GTK_ADJUSTMENT (adjustment);
- gtk_box_pack_end (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
- gtk_widget_show (spinbutton);
+ gtk_box_pack_end (GTK_BOX (hbox), box->high_spinbutton, FALSE, FALSE, 0);
+ gtk_widget_show (box->high_spinbutton);
g_signal_connect (adjustment, "value-changed",
G_CALLBACK (gimp_histogram_box_high_adj_update),
@@ -196,28 +197,34 @@ static void
gimp_histogram_box_low_adj_update (GtkAdjustment *adjustment,
GimpHistogramBox *box)
{
- gint value = ROUND (gtk_adjustment_get_value (adjustment));
+ gdouble value = gtk_adjustment_get_value (adjustment);
- if (box->view->start != value)
- {
- gtk_adjustment_set_lower (box->high_adj, value);
+ gtk_adjustment_set_lower (box->high_adj, value);
- gimp_histogram_view_set_range (box->view, value, box->view->end);
- }
+ 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);
}
static void
gimp_histogram_box_high_adj_update (GtkAdjustment *adjustment,
GimpHistogramBox *box)
{
- gint value = ROUND (gtk_adjustment_get_value (adjustment));
+ gdouble value = gtk_adjustment_get_value (adjustment);
- if (box->view->end != value)
- {
- gtk_adjustment_set_upper (box->low_adj, value);
+ gtk_adjustment_set_upper (box->low_adj, value);
- gimp_histogram_view_set_range (box->view, box->view->start, value);
- }
+ 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);
}
static void
@@ -226,13 +233,38 @@ gimp_histogram_box_histogram_range (GimpHistogramView *view,
gint end,
GimpHistogramBox *box)
{
- gtk_adjustment_set_lower (box->high_adj, start);
- gtk_adjustment_set_upper (box->high_adj, view->n_bins - 1);
+ gdouble s = start;
+ gdouble e = end;
+
+ if (box->n_bins != view->n_bins)
+ {
+ box->n_bins = view->n_bins;
+
+ if (box->n_bins == 256)
+ {
+ gtk_adjustment_set_upper (box->high_adj, 255);
+ gtk_spin_button_set_digits (GTK_SPIN_BUTTON (box->low_spinbutton), 0);
+ gtk_spin_button_set_digits (GTK_SPIN_BUTTON (box->high_spinbutton), 0);
+ }
+ else
+ {
+ gtk_adjustment_set_upper (box->high_adj, 1.0);
+ gtk_spin_button_set_digits (GTK_SPIN_BUTTON (box->low_spinbutton), 3);
+ gtk_spin_button_set_digits (GTK_SPIN_BUTTON (box->high_spinbutton), 3);
+ }
+ }
+
+ if (box->n_bins != 256)
+ {
+ s /= box->n_bins - 1;
+ e /= box->n_bins - 1;
+ }
- gtk_adjustment_set_upper (box->low_adj, end);
+ gtk_adjustment_set_lower (box->high_adj, s);
+ gtk_adjustment_set_upper (box->low_adj, e);
- gtk_adjustment_set_value (box->low_adj, start);
- gtk_adjustment_set_value (box->high_adj, end);
+ gtk_adjustment_set_value (box->low_adj, s);
+ gtk_adjustment_set_value (box->high_adj, e);
}
static void
diff --git a/app/widgets/gimphistogrambox.h b/app/widgets/gimphistogrambox.h
index f84383e..a6a8b2b 100644
--- a/app/widgets/gimphistogrambox.h
+++ b/app/widgets/gimphistogrambox.h
@@ -37,8 +37,13 @@ struct _GimpHistogramBox
GtkWidget *color_bar;
GtkWidget *slider_bar;
+ gint n_bins;
+
GtkAdjustment *low_adj;
GtkAdjustment *high_adj;
+
+ GtkWidget *low_spinbutton;
+ GtkWidget *high_spinbutton;
};
struct _GimpHistogramBoxClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]