app: add gimp_histogram_clear_values() and use it

instead of abusing gimp_histogram_calculate() with a NULL region for
that purpose; calculate() is about to go away.
This commit is contained in:
Michael Natterer
2012-04-15 19:09:35 +02:00
parent cadd54823b
commit df5ab0f551
3 changed files with 23 additions and 25 deletions

View File

@ -57,7 +57,6 @@ struct _GimpHistogram
static void gimp_histogram_alloc_values (GimpHistogram *histogram, static void gimp_histogram_alloc_values (GimpHistogram *histogram,
gint bytes); gint bytes);
static void gimp_histogram_free_values (GimpHistogram *histogram);
static void gimp_histogram_calculate_sub_region (GimpHistogram *histogram, static void gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
PixelRegion *region, PixelRegion *region,
PixelRegion *mask); PixelRegion *mask);
@ -98,7 +97,7 @@ gimp_histogram_unref (GimpHistogram *histogram)
if (histogram->ref_count == 0) if (histogram->ref_count == 0)
{ {
gimp_histogram_free_values (histogram); gimp_histogram_clear_values (histogram);
g_slice_free (GimpHistogram, histogram); g_slice_free (GimpHistogram, histogram);
} }
} }
@ -144,12 +143,7 @@ gimp_histogram_calculate (GimpHistogram *histogram,
gint i; gint i;
g_return_if_fail (histogram != NULL); g_return_if_fail (histogram != NULL);
g_return_if_fail (region != NULL);
if (! region)
{
gimp_histogram_free_values (histogram);
return;
}
gimp_histogram_alloc_values (histogram, region->bytes); gimp_histogram_alloc_values (histogram, region->bytes);
@ -175,6 +169,23 @@ gimp_histogram_calculate (GimpHistogram *histogram,
#endif #endif
} }
void
gimp_histogram_clear_values (GimpHistogram *histogram)
{
gint i;
g_return_if_fail (histogram != NULL);
for (i = 0; i < NUM_SLOTS; i++)
if (histogram->values[i])
{
g_free (histogram->values[i]);
histogram->values[i] = NULL;
}
histogram->n_channels = 0;
}
#define HISTOGRAM_VALUE(c,i) (histogram->values[0][(c) * 256 + (i)]) #define HISTOGRAM_VALUE(c,i) (histogram->values[0][(c) * 256 + (i)])
@ -550,7 +561,7 @@ gimp_histogram_alloc_values (GimpHistogram *histogram,
{ {
if (bytes + 1 != histogram->n_channels) if (bytes + 1 != histogram->n_channels)
{ {
gimp_histogram_free_values (histogram); gimp_histogram_clear_values (histogram);
histogram->n_channels = bytes + 1; histogram->n_channels = bytes + 1;
@ -558,21 +569,6 @@ gimp_histogram_alloc_values (GimpHistogram *histogram,
} }
} }
static void
gimp_histogram_free_values (GimpHistogram *histogram)
{
gint i;
for (i = 0; i < NUM_SLOTS; i++)
if (histogram->values[i])
{
g_free (histogram->values[i]);
histogram->values[i] = NULL;
}
histogram->n_channels = 0;
}
static void static void
gimp_histogram_calculate_sub_region (GimpHistogram *histogram, gimp_histogram_calculate_sub_region (GimpHistogram *histogram,
PixelRegion *region, PixelRegion *region,

View File

@ -32,6 +32,8 @@ void gimp_histogram_calculate (GimpHistogram *histogram,
PixelRegion *region, PixelRegion *region,
PixelRegion *mask); PixelRegion *mask);
void gimp_histogram_clear_values (GimpHistogram *histogram);
gdouble gimp_histogram_get_maximum (GimpHistogram *histogram, gdouble gimp_histogram_get_maximum (GimpHistogram *histogram,
GimpHistogramChannel channel); GimpHistogramChannel channel);
gdouble gimp_histogram_get_count (GimpHistogram *histogram, gdouble gimp_histogram_get_count (GimpHistogram *histogram,

View File

@ -372,7 +372,7 @@ gimp_histogram_editor_validate (GimpHistogramEditor *editor)
if (editor->drawable) if (editor->drawable)
gimp_drawable_calculate_histogram (editor->drawable, editor->histogram); gimp_drawable_calculate_histogram (editor->drawable, editor->histogram);
else else
gimp_histogram_calculate (editor->histogram, NULL, NULL); gimp_histogram_clear_values (editor->histogram);
gimp_histogram_editor_info_update (editor); gimp_histogram_editor_info_update (editor);