diff --git a/ChangeLog b/ChangeLog index a8d512c80d..1913ad7b50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,17 @@ +2008-07-22 Sven Neumann + + * app/base/gimphistogram.[ch]: added new method + gimp_histogram_duplicate(). + + * app/widgets/gimphistogrameditor.c + (gimp_histogram_editor_frozen_update): instead of recalculating + the histogram, use a duplicate for the background histogram. + 2008-07-22 Sven Neumann * app/widgets/gimphistogrameditor.c (gimp_histogram_editor_set_image): reverted last change, it did not plug the leak. - + 2008-07-22 Sven Neumann * app/gui/session.c (session_init): plugged a small memory leak. diff --git a/app/base/gimphistogram.c b/app/base/gimphistogram.c index 02bc251fd7..ca65c00e74 100644 --- a/app/base/gimphistogram.c +++ b/app/base/gimphistogram.c @@ -102,6 +102,39 @@ gimp_histogram_unref (GimpHistogram *histogram) } } +/** + * gimp_histogram_duplicate: + * @histogram: a %GimpHistogram + * + * Creates a duplicate of @histogram. The duplicate has a reference + * count of 1 and contains the values from @histogram. + * + * Return value: a newly allocated %GimpHistogram + **/ +GimpHistogram * +gimp_histogram_duplicate (GimpHistogram *histogram) +{ + GimpHistogram *dup; + + g_return_val_if_fail (histogram != NULL, NULL); + + dup = gimp_histogram_new (); + +#ifdef ENABLE_MP + g_static_mutex_lock (&histogram->mutex); +#endif + + dup->n_channels = histogram->n_channels; + dup->values[0] = g_memdup (histogram->values[0], + sizeof (gdouble) * dup->n_channels * 256); + +#ifdef ENABLE_MP + g_static_mutex_unlock (&histogram->mutex); +#endif + + return dup; +} + void gimp_histogram_calculate (GimpHistogram *histogram, PixelRegion *region, diff --git a/app/base/gimphistogram.h b/app/base/gimphistogram.h index 5e812defd4..2f847ab647 100644 --- a/app/base/gimphistogram.h +++ b/app/base/gimphistogram.h @@ -23,9 +23,12 @@ GimpHistogram * gimp_histogram_new (void); + GimpHistogram * gimp_histogram_ref (GimpHistogram *histogram); void gimp_histogram_unref (GimpHistogram *histogram); +GimpHistogram * gimp_histogram_duplicate (GimpHistogram *histogram); + void gimp_histogram_calculate (GimpHistogram *histogram, PixelRegion *region, PixelRegion *mask); diff --git a/app/widgets/gimphistogrameditor.c b/app/widgets/gimphistogrameditor.c index ff580b1efe..20b2a81343 100644 --- a/app/widgets/gimphistogrameditor.c +++ b/app/widgets/gimphistogrameditor.c @@ -365,6 +365,24 @@ gimp_histogram_editor_layer_changed (GimpImage *image, gimp_histogram_editor_name_update (editor); } +static gboolean +gimp_histogram_editor_validate (GimpHistogramEditor *editor) +{ + if (! editor->valid && editor->histogram) + { + if (editor->drawable) + gimp_drawable_calculate_histogram (editor->drawable, editor->histogram); + else + gimp_histogram_calculate (editor->histogram, NULL, NULL); + + gimp_histogram_editor_info_update (editor); + + editor->valid = TRUE; + } + + return editor->valid; +} + static void gimp_histogram_editor_frozen_update (GimpHistogramEditor *editor, const GParamSpec *pspec) @@ -375,10 +393,8 @@ gimp_histogram_editor_frozen_update (GimpHistogramEditor *editor, { if (! editor->bg_histogram) { - editor->bg_histogram = gimp_histogram_new (); - - gimp_drawable_calculate_histogram (editor->drawable, - editor->bg_histogram); + if (gimp_histogram_editor_validate (editor)) + editor->bg_histogram = gimp_histogram_duplicate (editor->histogram); gimp_histogram_view_set_background (view, editor->bg_histogram); } @@ -538,17 +554,7 @@ gimp_histogram_editor_info_update (GimpHistogramEditor *editor) static gboolean gimp_histogram_view_expose (GimpHistogramEditor *editor) { - if (! editor->valid && editor->histogram) - { - if (editor->drawable) - gimp_drawable_calculate_histogram (editor->drawable, editor->histogram); - else - gimp_histogram_calculate (editor->histogram, NULL, NULL); - - editor->valid = TRUE; - - gimp_histogram_editor_info_update (editor); - } + gimp_histogram_editor_validate (editor); return FALSE; }