Issue #4205 - The histogram dock scale is incorrect when an image is opened

In gimp_histogram_view_update_bins(), don't update the view's
range if there's no histogram or the histogram is empty, to avoid
discarding the existing range.  Additionally, improve the range
readjustment when the number of bins changes.

(cherry picked from commit 0c899394b4)
This commit is contained in:
Ell
2019-11-11 18:11:39 +02:00
parent 7072b77224
commit 9f8e244ec1

View File

@ -799,21 +799,21 @@ gimp_histogram_view_notify (GimpHistogram *histogram,
static void
gimp_histogram_view_update_bins (GimpHistogramView *view)
{
gint new_bins = 256;
gint new_bins = 0;
if (view->histogram)
new_bins = gimp_histogram_n_bins (view->histogram);
else if (view->bg_histogram)
new_bins = gimp_histogram_n_bins (view->bg_histogram);
if (new_bins != view->n_bins)
if (new_bins > 0 && new_bins != view->n_bins)
{
view->start = ROUND (((gdouble) view->start *
(new_bins - 1) /
(view->n_bins - 1)));
view->end = ROUND (((gdouble) view->end *
(new_bins - 1) /
(view->n_bins - 1)));
view->start = MIN (ROUND ((gdouble) view->start *
new_bins / view->n_bins),
new_bins - 1);
view->end = MAX (ROUND ((gdouble) (view->end + 1) *
new_bins / view->n_bins) - 1,
0);
view->n_bins = new_bins;