Commit ebc1bf8c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added GimpHistogramChannel index fiddling hacks for GRAYA images to all

2004-01-13  Michael Natterer  <mitch@gimp.org>

	* app/base/gimphistogram.c: added GimpHistogramChannel index
	fiddling hacks for GRAYA images to all gimp_histogram_get_*()
	functions. The public API now does what their enum values pretend
	to do.

	(gimp_histogram_calculate): restructured to reduce indentation depth.

	* app/widgets/gimphistogrameditor.c
	* app/widgets/gimphistogramview.c
	* tools/pdbgen/pdb/color.pdb: removed hacks here and always use
	the unchanged enum values.

	* app/pdb/color_cmds.c: regenerated.
parent 9eaace41
2004-01-13 Michael Natterer <mitch@gimp.org>
* app/base/gimphistogram.c: added GimpHistogramChannel index
fiddling hacks for GRAYA images to all gimp_histogram_get_*()
functions. The public API now does what their enum values pretend
to do.
(gimp_histogram_calculate): restructured to reduce indentation depth.
* app/widgets/gimphistogrameditor.c
* app/widgets/gimphistogramview.c
* tools/pdbgen/pdb/color.pdb: removed hacks here and always use
the unchanged enum values.
* app/pdb/color_cmds.c: regenerated.
2004-01-13 Michael Natterer <mitch@gimp.org>
* app/base/gimphistogram.[ch]: renamed gimp_histogram_nchannels()
......@@ -113,57 +113,56 @@ gimp_histogram_calculate (GimpHistogram *histogram,
g_return_if_fail (histogram != NULL);
if (region)
if (! region)
{
gimp_histogram_alloc_values (histogram, region->bytes);
gimp_histogram_free_values (histogram);
return;
}
gimp_histogram_alloc_values (histogram, region->bytes);
#ifdef ENABLE_MP
for (i = 0; i < histogram->num_slots; i++)
{
histogram->tmp_values[i] = g_new0 (gdouble *, histogram->n_channels);
histogram->tmp_slots[i] = 0;
for (i = 0; i < histogram->num_slots; i++)
{
histogram->tmp_values[i] = g_new0 (gdouble *, histogram->n_channels);
histogram->tmp_slots[i] = 0;
for (j = 0; j < histogram->n_channels; j++)
{
gint k;
for (j = 0; j < histogram->n_channels; j++)
{
gint k;
histogram->tmp_values[i][j] = g_new0 (gdouble, 256);
histogram->tmp_values[i][j] = g_new0 (gdouble, 256);
for (k = 0; k < 256; k++)
histogram->tmp_values[i][j][k] = 0.0;
}
for (k = 0; k < 256; k++)
histogram->tmp_values[i][j][k] = 0.0;
}
}
#endif
for (i = 0; i < histogram->n_channels; i++)
for (j = 0; j < 256; j++)
histogram->values[i][j] = 0.0;
for (i = 0; i < histogram->n_channels; i++)
for (j = 0; j < 256; j++)
histogram->values[i][j] = 0.0;
pixel_regions_process_parallel ((p_func) gimp_histogram_calculate_sub_region,
histogram, 2, region, mask);
pixel_regions_process_parallel ((p_func) gimp_histogram_calculate_sub_region,
histogram, 2, region, mask);
#ifdef ENABLE_MP
/* add up all the tmp buffers and free their memmory */
for (i = 0; i < histogram->num_slots; i++)
/* add up all the tmp buffers and free their memmory */
for (i = 0; i < histogram->num_slots; i++)
{
for (j = 0; j < histogram->n_channels; j++)
{
for (j = 0; j < histogram->n_channels; j++)
{
gint k;
gint k;
for (k = 0; k < 256; k++)
histogram->values[j][k] += histogram->tmp_values[i][j][k];
for (k = 0; k < 256; k++)
histogram->values[j][k] += histogram->tmp_values[i][j][k];
g_free (histogram->tmp_values[i][j]);
}
g_free (histogram->tmp_values[i]);
g_free (histogram->tmp_values[i][j]);
}
#endif
}
else
{
gimp_histogram_free_values (histogram);
g_free (histogram->tmp_values[i]);
}
#endif
}
gdouble
......@@ -175,6 +174,10 @@ gimp_histogram_get_maximum (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, 0.0);
/* the gray alpha channel is in slot 1 */
if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (! histogram->values || channel >= histogram->n_channels)
return 0.0;
......@@ -192,6 +195,10 @@ gimp_histogram_get_value (GimpHistogram *histogram,
{
g_return_val_if_fail (histogram != NULL, 0.0);
/* the gray alpha channel is in slot 1 */
if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (histogram->values &&
channel < histogram->n_channels &&
bin >= 0 && bin < 256)
......@@ -232,6 +239,10 @@ gimp_histogram_get_count (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, 0.0);
/* the gray alpha channel is in slot 1 */
if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (! histogram->values || channel >= histogram->n_channels)
return 0.0;
......@@ -253,6 +264,10 @@ gimp_histogram_get_mean (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, 0.0);
/* the gray alpha channel is in slot 1 */
if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (! histogram->values || channel >= histogram->n_channels)
return 0.0;
......@@ -279,6 +294,10 @@ gimp_histogram_get_median (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, -1);
/* the gray alpha channel is in slot 1 */
if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (! histogram->values || channel >= histogram->n_channels)
return 0;
......@@ -308,6 +327,10 @@ gimp_histogram_get_std_dev (GimpHistogram *histogram,
g_return_val_if_fail (histogram != NULL, 0.0);
/* the gray alpha channel is in slot 1 */
if (histogram->n_channels == 3 && channel == GIMP_HISTOGRAM_ALPHA)
channel = 1;
if (! histogram->values || channel >= histogram->n_channels)
return 0.0;
......
......@@ -1054,9 +1054,6 @@ histogram_invoker (Gimp *gimp,
{
GimpHistogram *histogram;
if (gimp_drawable_is_gray (drawable))
channel = (channel > 0) ? 1 : 0;
histogram = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config));
gimp_drawable_calculate_histogram (drawable, histogram);
......
......@@ -419,30 +419,26 @@ gimp_histogram_editor_info_update (GimpHistogramEditor *editor)
if (hist)
{
GimpHistogramChannel channel = gimp_histogram_view_get_channel (view);
gdouble pixels;
gdouble count;
gchar text[12];
gdouble pixels;
gdouble count;
gchar text[12];
/* FIXME: hack */
if (gimp_histogram_n_channels (hist) == 2)
channel = (channel > 0) ? 1 : 0;
pixels = gimp_histogram_get_count (hist, channel, 0, 255);
count = gimp_histogram_get_count (hist, channel, view->start, view->end);
pixels = gimp_histogram_get_count (hist, view->channel, 0, 255);
count = gimp_histogram_get_count (hist, view->channel,
view->start, view->end);
g_snprintf (text, sizeof (text), "%3.1f",
gimp_histogram_get_mean (hist, channel,
gimp_histogram_get_mean (hist, view->channel,
view->start, view->end));
gtk_label_set_text (GTK_LABEL (editor->labels[0]), text);
g_snprintf (text, sizeof (text), "%3.1f",
gimp_histogram_get_std_dev (hist, channel,
gimp_histogram_get_std_dev (hist, view->channel,
view->start, view->end));
gtk_label_set_text (GTK_LABEL (editor->labels[1]), text);
g_snprintf (text, sizeof (text), "%3.1f",
(gdouble) gimp_histogram_get_median (hist, channel,
(gdouble) gimp_histogram_get_median (hist, view->channel,
view->start,
view->end));
gtk_label_set_text (GTK_LABEL (editor->labels[2]), text);
......
......@@ -249,14 +249,13 @@ static gboolean
gimp_histogram_view_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
GimpHistogramChannel channel;
gint x, y;
gint x1, x2;
gint border;
gint width, height;
gdouble max;
gint xstop;
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
gint x, y;
gint x1, x2;
gint border;
gint width, height;
gdouble max;
gint xstop;
if (! view->histogram)
return FALSE;
......@@ -265,14 +264,8 @@ gimp_histogram_view_expose (GtkWidget *widget,
width = widget->allocation.width - 2 * border;
height = widget->allocation.height - 2 * border;
channel = view->channel;
/* FIXME: hack */
if (gimp_histogram_n_channels (view->histogram) == 2)
channel = (channel > 0) ? 1 : 0;
/* find the maximum value */
max = gimp_histogram_get_maximum (view->histogram, channel);
max = gimp_histogram_get_maximum (view->histogram, view->channel);
switch (view->scale)
{
......@@ -322,7 +315,7 @@ gimp_histogram_view_expose (GtkWidget *widget,
if (! in_selection)
in_selection = ((x1 != 0 || x2 != 255) && x1 <= i && i <= x2);
v = gimp_histogram_get_value (view->histogram, channel, i++);
v = gimp_histogram_get_value (view->histogram, view->channel, i++);
if (v > value)
value = v;
......
......@@ -679,9 +679,6 @@ HELP
{
GimpHistogram *histogram;
if (gimp_drawable_is_gray (drawable))
channel = (channel > 0) ? 1 : 0;
histogram = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config));
gimp_drawable_calculate_histogram (drawable, histogram);
......
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