Commit 945e57af authored by Michael Natterer's avatar Michael Natterer 😴

app: GimpHistogramBox: map the range to 0..1 for != 8 bit histograms

parent 9ba866dc
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment